Add batch mint_for() functionality to Collection Actions

This commit is contained in:
Serkan Reis 2022-10-28 13:05:02 +03:00
parent 60de59a5ad
commit f86be40cc3
4 changed files with 107 additions and 10 deletions

View File

@ -143,8 +143,15 @@ export const CollectionActions = ({
const showLimitField = type === 'update_per_address_limit' const showLimitField = type === 'update_per_address_limit'
const showTokenIdField = isEitherType(type, ['transfer', 'mint_for', 'burn']) const showTokenIdField = isEitherType(type, ['transfer', 'mint_for', 'burn'])
const showNumberOfTokensField = type === 'batch_mint' const showNumberOfTokensField = type === 'batch_mint'
const showTokenIdListField = isEitherType(type, ['batch_burn', 'batch_transfer']) const showTokenIdListField = isEitherType(type, ['batch_burn', 'batch_transfer', 'batch_mint_for'])
const showRecipientField = isEitherType(type, ['transfer', 'mint_to', 'mint_for', 'batch_mint', 'batch_transfer']) const showRecipientField = isEitherType(type, [
'transfer',
'mint_to',
'mint_for',
'batch_mint',
'batch_transfer',
'batch_mint_for',
])
const showAirdropFileField = type === 'airdrop' const showAirdropFileField = type === 'airdrop'
const showPriceField = type === 'update_mint_price' const showPriceField = type === 'update_mint_price'
const showDescriptionField = type === 'update_collection_info' const showDescriptionField = type === 'update_collection_info'
@ -259,7 +266,7 @@ export const CollectionActions = ({
{showWhitelistField && <AddressInput {...whitelistState} />} {showWhitelistField && <AddressInput {...whitelistState} />}
{showLimitField && <NumberInput {...limitState} />} {showLimitField && <NumberInput {...limitState} />}
{showTokenIdField && <NumberInput {...tokenIdState} />} {showTokenIdField && <NumberInput {...tokenIdState} />}
{showTokenIdListField && <TextInput {...tokenIdListState} />} {showTokenIdListField && <TextInput className="mt-2" {...tokenIdListState} />}
{showNumberOfTokensField && <NumberInput {...batchNumberState} />} {showNumberOfTokensField && <NumberInput {...batchNumberState} />}
{showPriceField && <NumberInput {...priceState} />} {showPriceField && <NumberInput {...priceState} />}
{showDescriptionField && <TextInput className="mb-2" {...descriptionState} />} {showDescriptionField && <TextInput className="mb-2" {...descriptionState} />}

View File

@ -23,6 +23,7 @@ export const ACTION_TYPES = [
'batch_transfer', 'batch_transfer',
'burn', 'burn',
'batch_burn', 'batch_burn',
'batch_mint_for',
'shuffle', 'shuffle',
'airdrop', 'airdrop',
'burn_remaining', 'burn_remaining',
@ -55,15 +56,20 @@ export const ACTION_LIST: ActionListItem[] = [
name: 'Mint To', name: 'Mint To',
description: `Mint a token to a user`, description: `Mint a token to a user`,
}, },
{
id: 'mint_for',
name: 'Mint For',
description: `Mint a token for a user with given token ID`,
},
{ {
id: 'batch_mint', id: 'batch_mint',
name: 'Batch Mint', name: 'Batch Mint',
description: `Mint multiple tokens to a user with given token amount`, description: `Mint multiple tokens to a user`,
},
{
id: 'mint_for',
name: 'Mint For',
description: `Mint a token for a user with the given token ID`,
},
{
id: 'batch_mint_for',
name: 'Batch Mint For',
description: `Mint a specific range of tokens from the collection to a specific address`,
}, },
{ {
id: 'set_whitelist', id: 'set_whitelist',
@ -169,6 +175,7 @@ export type DispatchExecuteArgs = {
| { type: Select<'batch_transfer'>; recipient: string; tokenIds: string } | { type: Select<'batch_transfer'>; recipient: string; tokenIds: string }
| { type: Select<'burn'>; tokenId: number } | { type: Select<'burn'>; tokenId: number }
| { type: Select<'batch_burn'>; tokenIds: string } | { type: Select<'batch_burn'>; tokenIds: string }
| { type: Select<'batch_mint_for'>; recipient: string; tokenIds: string }
| { type: Select<'airdrop'>; recipients: string[] } | { type: Select<'airdrop'>; recipients: string[] }
| { type: Select<'burn_remaining'> } | { type: Select<'burn_remaining'> }
| { type: Select<'update_collection_info'>; collectionInfo: CollectionInfo | undefined } | { type: Select<'update_collection_info'>; collectionInfo: CollectionInfo | undefined }
@ -235,6 +242,9 @@ export const dispatchExecute = async (args: DispatchExecuteArgs) => {
case 'batch_burn': { case 'batch_burn': {
return sg721Messages.batchBurn(args.tokenIds) return sg721Messages.batchBurn(args.tokenIds)
} }
case 'batch_mint_for': {
return minterMessages.batchMintFor(txSigner, args.recipient, args.tokenIds)
}
case 'airdrop': { case 'airdrop': {
return minterMessages.airdrop(txSigner, args.recipients) return minterMessages.airdrop(txSigner, args.recipients)
} }
@ -308,6 +318,9 @@ export const previewExecutePayload = (args: DispatchExecuteArgs) => {
case 'batch_burn': { case 'batch_burn': {
return sg721Messages(sg721Contract)?.batchBurn(args.tokenIds) return sg721Messages(sg721Contract)?.batchBurn(args.tokenIds)
} }
case 'batch_mint_for': {
return minterMessages(minterContract)?.batchMintFor(args.recipient, args.tokenIds)
}
case 'airdrop': { case 'airdrop': {
return minterMessages(minterContract)?.airdrop(args.recipients) return minterMessages(minterContract)?.airdrop(args.recipients)
} }

View File

@ -37,6 +37,7 @@ export interface MinterInstance {
updatePerAddressLimit: (senderAddress: string, perAddressLimit: number) => Promise<string> updatePerAddressLimit: (senderAddress: string, perAddressLimit: number) => Promise<string>
mintTo: (senderAddress: string, recipient: string) => Promise<string> mintTo: (senderAddress: string, recipient: string) => Promise<string>
mintFor: (senderAddress: string, recipient: string, tokenId: number) => Promise<string> mintFor: (senderAddress: string, recipient: string, tokenId: number) => Promise<string>
batchMintFor: (senderAddress: string, recipient: string, tokenIds: string) => Promise<string>
batchMint: (senderAddress: string, recipient: string, batchNumber: number) => Promise<string> batchMint: (senderAddress: string, recipient: string, batchNumber: number) => Promise<string>
shuffle: (senderAddress: string) => Promise<string> shuffle: (senderAddress: string) => Promise<string>
withdraw: (senderAddress: string) => Promise<string> withdraw: (senderAddress: string) => Promise<string>
@ -54,6 +55,7 @@ export interface MinterMessages {
updatePerAddressLimit: (perAddressLimit: number) => UpdatePerAddressLimitMessage updatePerAddressLimit: (perAddressLimit: number) => UpdatePerAddressLimitMessage
mintTo: (recipient: string) => MintToMessage mintTo: (recipient: string) => MintToMessage
mintFor: (recipient: string, tokenId: number) => MintForMessage mintFor: (recipient: string, tokenId: number) => MintForMessage
batchMintFor: (recipient: string, tokenIds: string) => BatchMintForMessage
batchMint: (recipient: string, batchNumber: number) => CustomMessage batchMint: (recipient: string, batchNumber: number) => CustomMessage
shuffle: () => ShuffleMessage shuffle: () => ShuffleMessage
withdraw: () => WithdrawMessage withdraw: () => WithdrawMessage
@ -152,6 +154,12 @@ export interface MintForMessage {
} }
funds: Coin[] funds: Coin[]
} }
export interface BatchMintForMessage {
sender: string
contract: string
msg: Record<string, unknown>[]
funds: Coin[]
}
export interface CustomMessage { export interface CustomMessage {
sender: string sender: string
@ -390,6 +398,49 @@ export const minter = (client: SigningCosmWasmClient, txSigner: string): MinterC
return res.transactionHash return res.transactionHash
} }
const batchMintFor = async (senderAddress: string, recipient: string, tokenIds: string): Promise<string> => {
const executeContractMsgs: MsgExecuteContractEncodeObject[] = []
if (tokenIds.includes(':')) {
const [start, end] = tokenIds.split(':').map(Number)
for (let i = start; i <= end; i++) {
const msg = {
mint_for: { token_id: i, recipient },
}
const executeContractMsg: MsgExecuteContractEncodeObject = {
typeUrl: '/cosmwasm.wasm.v1.MsgExecuteContract',
value: MsgExecuteContract.fromPartial({
sender: txSigner,
contract: contractAddress,
msg: toUtf8(JSON.stringify(msg)),
}),
}
executeContractMsgs.push(executeContractMsg)
}
} else {
const tokenNumbers = tokenIds.split(',').map(Number)
for (let i = 0; i < tokenNumbers.length; i++) {
const msg = {
mint_for: { token_id: tokenNumbers[i], recipient },
}
const executeContractMsg: MsgExecuteContractEncodeObject = {
typeUrl: '/cosmwasm.wasm.v1.MsgExecuteContract',
value: MsgExecuteContract.fromPartial({
sender: txSigner,
contract: contractAddress,
msg: toUtf8(JSON.stringify(msg)),
}),
}
executeContractMsgs.push(executeContractMsg)
}
}
const res = await client.signAndBroadcast(txSigner, executeContractMsgs, 'auto', 'batch mint for')
return res.transactionHash
}
const batchMint = async (senderAddress: string, recipient: string, batchNumber: number): Promise<string> => { const batchMint = async (senderAddress: string, recipient: string, batchNumber: number): Promise<string> => {
const executeContractMsgs: MsgExecuteContractEncodeObject[] = [] const executeContractMsgs: MsgExecuteContractEncodeObject[] = []
for (let i = 0; i < batchNumber; i++) { for (let i = 0; i < batchNumber; i++) {
@ -495,6 +546,7 @@ export const minter = (client: SigningCosmWasmClient, txSigner: string): MinterC
updatePerAddressLimit, updatePerAddressLimit,
mintTo, mintTo,
mintFor, mintFor,
batchMintFor,
batchMint, batchMint,
airdrop, airdrop,
shuffle, shuffle,
@ -631,6 +683,30 @@ export const minter = (client: SigningCosmWasmClient, txSigner: string): MinterC
} }
} }
const batchMintFor = (recipient: string, tokenIds: string): BatchMintForMessage => {
const msg: Record<string, unknown>[] = []
if (tokenIds.includes(':')) {
const [start, end] = tokenIds.split(':').map(Number)
for (let i = start; i <= end; i++) {
msg.push({
mint_for: { token_id: i.toString(), recipient },
})
}
} else {
const tokenNumbers = tokenIds.split(',').map(Number)
for (let i = 0; i < tokenNumbers.length; i++) {
msg.push({ mint_for: { token_id: tokenNumbers[i].toString(), recipient } })
}
}
return {
sender: txSigner,
contract: contractAddress,
msg,
funds: [],
}
}
const batchMint = (recipient: string, batchNumber: number): CustomMessage => { const batchMint = (recipient: string, batchNumber: number): CustomMessage => {
const msg: Record<string, unknown>[] = [] const msg: Record<string, unknown>[] = []
for (let i = 0; i < batchNumber; i++) { for (let i = 0; i < batchNumber; i++) {
@ -700,6 +776,7 @@ export const minter = (client: SigningCosmWasmClient, txSigner: string): MinterC
updatePerAddressLimit, updatePerAddressLimit,
mintTo, mintTo,
mintFor, mintFor,
batchMintFor,
batchMint, batchMint,
airdrop, airdrop,
shuffle, shuffle,

View File

@ -444,7 +444,7 @@ const CollectionCreationPage: NextPage = () => {
baseTokenUri.lastIndexOf('ipfs://') + 7, baseTokenUri.lastIndexOf('ipfs://') + 7,
)}/`} )}/`}
> >
ipfs://{baseTokenUri?.substring(baseTokenUri.lastIndexOf('ipfs://') + 7)}/ ipfs://{baseTokenUri?.substring(baseTokenUri.lastIndexOf('ipfs://') + 7)}
</Anchor> </Anchor>
)} )}
<br /> <br />