From 0365aa5a7b04c4090ef5d96ba5a701b850daee70 Mon Sep 17 00:00:00 2001 From: Serkan Reis Date: Tue, 10 Oct 2023 13:43:14 +0300 Subject: [PATCH] Add Infinity Swap related actions to Collection Actions > Actions --- components/collections/actions/Action.tsx | 39 +++++++++- components/collections/actions/actions.ts | 94 ++++++++++++++++++++++- pages/collections/actions.tsx | 8 ++ 3 files changed, 135 insertions(+), 6 deletions(-) diff --git a/components/collections/actions/Action.tsx b/components/collections/actions/Action.tsx index a8b1b2e..6799d3c 100644 --- a/components/collections/actions/Action.tsx +++ b/components/collections/actions/Action.tsx @@ -1,6 +1,7 @@ /* eslint-disable eslint-comments/disable-enable-pair */ /* eslint-disable no-nested-ternary */ import { toUtf8 } from '@cosmjs/encoding' +import clsx from 'clsx' import { AirdropUpload } from 'components/AirdropUpload' import { Button } from 'components/Button' import type { DispatchExecuteArgs } from 'components/collections/actions/actions' @@ -20,6 +21,7 @@ import { useGlobalSettings } from 'contexts/globalSettings' import { useWallet } from 'contexts/wallet' import type { BaseMinterInstance } from 'contracts/baseMinter' import type { OpenEditionMinterInstance } from 'contracts/openEditionMinter' +import type { RoyaltyRegistryInstance } from 'contracts/royaltyRegistry' import type { SG721Instance } from 'contracts/sg721' import type { VendingMinterInstance } from 'contracts/vendingMinter' import type { FormEvent } from 'react' @@ -27,6 +29,7 @@ import { useEffect, useState } from 'react' import { toast } from 'react-hot-toast' import { FaArrowRight } from 'react-icons/fa' import { useMutation } from 'react-query' +import { ROYALTY_REGISTRY_ADDRESS } from 'utils/constants' import type { AirdropAllocation } from 'utils/isValidAccountsFile' import { resolveAddress } from 'utils/resolveAddress' @@ -41,6 +44,7 @@ interface CollectionActionsProps { vendingMinterMessages: VendingMinterInstance | undefined baseMinterMessages: BaseMinterInstance | undefined openEditionMinterMessages: OpenEditionMinterInstance | undefined + royaltyRegistryMessages: RoyaltyRegistryInstance | undefined minterType: MinterType sg721Type: Sg721Type } @@ -54,6 +58,7 @@ export const CollectionActions = ({ vendingMinterMessages, baseMinterMessages, openEditionMinterMessages, + royaltyRegistryMessages, minterType, sg721Type, }: CollectionActionsProps) => { @@ -69,6 +74,7 @@ export const CollectionActions = ({ const [explicitContent, setExplicitContent] = useState(undefined) const [resolvedRecipientAddress, setResolvedRecipientAddress] = useState('') const [jsonExtensions, setJsonExtensions] = useState(false) + const [decrement, setDecrement] = useState(false) const actionComboboxState = useActionsComboboxState() const type = actionComboboxState.value?.id @@ -170,8 +176,11 @@ export const CollectionActions = ({ const royaltyShareState = useInputState({ id: 'royalty-share', name: 'royaltyShare', - title: 'Share Percentage', - subtitle: 'Percentage of royalties to be paid', + title: type !== 'update_royalties_for_infinity_swap' ? 'Share Percentage' : 'Share Delta', + subtitle: + type !== 'update_royalties_for_infinity_swap' + ? 'Percentage of royalties to be paid' + : 'Change in share percentage', placeholder: '5%', }) @@ -208,7 +217,10 @@ export const CollectionActions = ({ const showDescriptionField = type === 'update_collection_info' const showImageField = type === 'update_collection_info' const showExternalLinkField = type === 'update_collection_info' - const showRoyaltyRelatedFields = type === 'update_collection_info' + const showRoyaltyRelatedFields = + type === 'update_collection_info' || + type === 'set_royalties_for_infinity_swap' || + type === 'update_royalties_for_infinity_swap' const showExplicitContentField = type === 'update_collection_info' const showBaseUriField = type === 'batch_update_token_metadata' @@ -219,6 +231,7 @@ export const CollectionActions = ({ limit: limitState.value, minterContract: minterContractAddress, sg721Contract: sg721ContractAddress, + royaltyRegistryContract: ROYALTY_REGISTRY_ADDRESS, tokenId: tokenIdState.value, tokenIds: tokenIdListState.value, tokenUri: tokenURIState.value.trim().endsWith('/') @@ -229,6 +242,7 @@ export const CollectionActions = ({ baseMinterMessages, openEditionMinterMessages, sg721Messages, + royaltyRegistryMessages, recipient: resolvedRecipientAddress, recipients: airdropArray, tokenRecipients: airdropAllocationArray, @@ -240,6 +254,7 @@ export const CollectionActions = ({ : baseURIState.value.trim(), collectionInfo, jsonExtensions, + decrement, } const resolveRecipientAddress = async () => { await resolveAddress(recipientState.value.trim(), wallet).then((resolvedAddress) => { @@ -448,6 +463,24 @@ export const CollectionActions = ({
+ +
+
+ +
+ Decrement +
+
)} {showExplicitContentField && ( diff --git a/components/collections/actions/actions.ts b/components/collections/actions/actions.ts index d3e69d6..cab26a2 100644 --- a/components/collections/actions/actions.ts +++ b/components/collections/actions/actions.ts @@ -1,10 +1,13 @@ /* eslint-disable eslint-comments/disable-enable-pair */ import { useBaseMinterContract } from 'contracts/baseMinter' import { useOpenEditionMinterContract } from 'contracts/openEditionMinter' +import type { RoyaltyRegistryInstance } from 'contracts/royaltyRegistry' +import { useRoyaltyRegistryContract } from 'contracts/royaltyRegistry' import type { CollectionInfo, SG721Instance } from 'contracts/sg721' import { useSG721Contract } from 'contracts/sg721' import type { VendingMinterInstance } from 'contracts/vendingMinter' import { useVendingMinterContract } from 'contracts/vendingMinter' +import { INFINITY_SWAP_PROTOCOL_ADDRESS } from 'utils/constants' import type { AirdropAllocation } from 'utils/isValidAccountsFile' import type { BaseMinterInstance } from '../../../contracts/baseMinter/contract' @@ -29,6 +32,8 @@ export const ACTION_TYPES = [ 'update_per_address_limit', 'update_collection_info', 'freeze_collection_info', + 'set_royalties_for_infinity_swap', + 'update_royalties_for_infinity_swap', 'transfer', 'batch_transfer', 'batch_transfer_multi_address', @@ -73,6 +78,16 @@ export const BASE_ACTION_LIST: ActionListItem[] = [ name: 'Freeze Collection Info', description: `Freeze collection info to prevent further updates`, }, + { + id: 'set_royalties_for_infinity_swap', + name: 'Set Royalty Details for Infinity Swap', + description: `Set royalty details for Infinity Swap`, + }, + { + id: 'update_royalties_for_infinity_swap', + name: 'Update Royalty Details for Infinity Swap', + description: `Update royalty details for Infinity Swap`, + }, { id: 'transfer', name: 'Transfer Tokens', @@ -166,6 +181,16 @@ export const VENDING_ACTION_LIST: ActionListItem[] = [ name: 'Freeze Collection Info', description: `Freeze collection info to prevent further updates`, }, + { + id: 'set_royalties_for_infinity_swap', + name: 'Set Royalty Details for Infinity Swap', + description: `Set royalty details for Infinity Swap`, + }, + { + id: 'update_royalties_for_infinity_swap', + name: 'Update Royalty Details for Infinity Swap', + description: `Update royalty details for Infinity Swap`, + }, { id: 'transfer', name: 'Transfer Tokens', @@ -259,6 +284,16 @@ export const OPEN_EDITION_ACTION_LIST: ActionListItem[] = [ name: 'Freeze Collection Info', description: `Freeze collection info to prevent further updates`, }, + { + id: 'set_royalties_for_infinity_swap', + name: 'Set Royalty Details for Infinity Swap', + description: `Set royalty details for Infinity Swap`, + }, + { + id: 'update_royalties_for_infinity_swap', + name: 'Update Royalty Details for Infinity Swap', + description: `Update royalty details for Infinity Swap`, + }, { id: 'transfer', name: 'Transfer Tokens', @@ -323,10 +358,12 @@ export interface DispatchExecuteProps { export interface DispatchExecuteArgs { minterContract: string sg721Contract: string + royaltyRegistryContract: string vendingMinterMessages?: VendingMinterInstance baseMinterMessages?: BaseMinterInstance openEditionMinterMessages?: OpenEditionMinterInstance sg721Messages?: SG721Instance + royaltyRegistryMessages?: RoyaltyRegistryInstance txSigner: string type: string | undefined tokenUri: string @@ -344,11 +381,25 @@ export interface DispatchExecuteArgs { collectionInfo: CollectionInfo | undefined baseUri: string jsonExtensions: boolean + decrement: boolean } export const dispatchExecute = async (args: DispatchExecuteArgs) => { - const { vendingMinterMessages, baseMinterMessages, openEditionMinterMessages, sg721Messages, txSigner } = args - if (!vendingMinterMessages || !baseMinterMessages || !openEditionMinterMessages || !sg721Messages) { + const { + vendingMinterMessages, + baseMinterMessages, + openEditionMinterMessages, + sg721Messages, + royaltyRegistryMessages, + txSigner, + } = args + if ( + !vendingMinterMessages || + !baseMinterMessages || + !openEditionMinterMessages || + !sg721Messages || + !royaltyRegistryMessages + ) { throw new Error('Cannot execute actions') } switch (args.type) { @@ -415,6 +466,23 @@ export const dispatchExecute = async (args: DispatchExecuteArgs) => { case 'shuffle': { return vendingMinterMessages.shuffle(txSigner) } + case 'set_royalties_for_infinity_swap': { + return royaltyRegistryMessages.setCollectionRoyaltyProtocol( + args.sg721Contract, + INFINITY_SWAP_PROTOCOL_ADDRESS, + args.collectionInfo?.royalty_info?.payment_address as string, + Number(args.collectionInfo?.royalty_info?.share) * 100, + ) + } + case 'update_royalties_for_infinity_swap': { + return royaltyRegistryMessages.updateCollectionRoyaltyProtocol( + args.sg721Contract, + INFINITY_SWAP_PROTOCOL_ADDRESS, + args.collectionInfo?.royalty_info?.payment_address as string, + Number(args.collectionInfo?.royalty_info?.share) * 100, + args.decrement, + ) + } case 'transfer': { return sg721Messages.transferNft(args.recipient, args.tokenId.toString()) } @@ -460,7 +528,10 @@ export const previewExecutePayload = (args: DispatchExecuteArgs) => { const { messages: baseMinterMessages } = useBaseMinterContract() // eslint-disable-next-line react-hooks/rules-of-hooks const { messages: openEditionMinterMessages } = useOpenEditionMinterContract() - const { minterContract, sg721Contract } = args + // eslint-disable-next-line react-hooks/rules-of-hooks + const { messages: royaltyRegistryMessages } = useRoyaltyRegistryContract() + + const { minterContract, sg721Contract, royaltyRegistryContract } = args switch (args.type) { case 'mint_token_uri': { return baseMinterMessages(minterContract)?.mint(args.tokenUri) @@ -525,6 +596,23 @@ export const previewExecutePayload = (args: DispatchExecuteArgs) => { case 'shuffle': { return vendingMinterMessages(minterContract)?.shuffle() } + case 'set_royalties_for_infinity_swap': { + return royaltyRegistryMessages(royaltyRegistryContract)?.setCollectionRoyaltyProtocol( + args.sg721Contract, + INFINITY_SWAP_PROTOCOL_ADDRESS, + args.collectionInfo?.royalty_info?.payment_address as string, + Number(args.collectionInfo?.royalty_info?.share) * 100, + ) + } + case 'update_royalties_for_infinity_swap': { + return royaltyRegistryMessages(royaltyRegistryContract)?.updateCollectionRoyaltyProtocol( + args.sg721Contract, + INFINITY_SWAP_PROTOCOL_ADDRESS, + args.collectionInfo?.royalty_info?.payment_address as string, + Number(args.collectionInfo?.royalty_info?.share) * 100, + args.decrement, + ) + } case 'transfer': { return sg721Messages(sg721Contract)?.transferNft(args.recipient, args.tokenId.toString()) } diff --git a/pages/collections/actions.tsx b/pages/collections/actions.tsx index 74e1e10..e07d732 100644 --- a/pages/collections/actions.tsx +++ b/pages/collections/actions.tsx @@ -12,6 +12,7 @@ import { useRouter } from 'next/router' import { NextSeo } from 'next-seo' import { useEffect, useMemo, useState } from 'react' import toast from 'react-hot-toast' +import { ROYALTY_REGISTRY_ADDRESS } from 'utils/constants' import { useDebounce } from 'utils/debounce' import { withMetadata } from 'utils/layout' import { links } from 'utils/links' @@ -24,6 +25,7 @@ const CollectionActionsPage: NextPage = () => { vendingMinter: vendingMinterContract, openEditionMinter: openEditionMinterContract, sg721: sg721Contract, + royaltyRegistry: royaltyRegistryContract, } = useContracts() const wallet = useWallet() @@ -66,6 +68,11 @@ const CollectionActionsPage: NextPage = () => { [sg721Contract, sg721ContractState.value], ) + const royaltyRegistryMessages = useMemo( + () => royaltyRegistryContract?.use(ROYALTY_REGISTRY_ADDRESS), + [royaltyRegistryContract], + ) + const sg721ContractAddress = sg721ContractState.value const minterContractAddress = minterContractState.value @@ -227,6 +234,7 @@ const CollectionActionsPage: NextPage = () => { minterContractAddress={minterContractState.value} minterType={minterType} openEditionMinterMessages={openEditionMinterMessages} + royaltyRegistryMessages={royaltyRegistryMessages} sg721ContractAddress={sg721ContractState.value} sg721Messages={sg721Messages} sg721Type={sg721Type}