Update open edition minter contract helpers
This commit is contained in:
parent
97fa8a875b
commit
2def96407f
@ -1,3 +1,6 @@
|
|||||||
|
/* eslint-disable eslint-comments/disable-enable-pair */
|
||||||
|
/* eslint-disable @typescript-eslint/no-explicit-any */
|
||||||
|
/* eslint-disable @typescript-eslint/no-unsafe-assignment */
|
||||||
import type { MsgExecuteContractEncodeObject, SigningCosmWasmClient } from '@cosmjs/cosmwasm-stargate'
|
import type { MsgExecuteContractEncodeObject, SigningCosmWasmClient } from '@cosmjs/cosmwasm-stargate'
|
||||||
import { toUtf8 } from '@cosmjs/encoding'
|
import { toUtf8 } from '@cosmjs/encoding'
|
||||||
import type { Coin } from '@cosmjs/proto-signing'
|
import type { Coin } from '@cosmjs/proto-signing'
|
||||||
@ -5,6 +8,7 @@ import { coin } from '@cosmjs/proto-signing'
|
|||||||
import type { logs } from '@cosmjs/stargate'
|
import type { logs } from '@cosmjs/stargate'
|
||||||
import type { Timestamp } from '@stargazezone/types/contracts/minter/shared-types'
|
import type { Timestamp } from '@stargazezone/types/contracts/minter/shared-types'
|
||||||
import { MsgExecuteContract } from 'cosmjs-types/cosmwasm/wasm/v1/tx'
|
import { MsgExecuteContract } from 'cosmjs-types/cosmwasm/wasm/v1/tx'
|
||||||
|
import toast from 'react-hot-toast'
|
||||||
|
|
||||||
export interface InstantiateResponse {
|
export interface InstantiateResponse {
|
||||||
readonly contractAddress: string
|
readonly contractAddress: string
|
||||||
@ -185,6 +189,11 @@ export interface OpenEditionMinterContract {
|
|||||||
export const openEditionMinter = (client: SigningCosmWasmClient, txSigner: string): OpenEditionMinterContract => {
|
export const openEditionMinter = (client: SigningCosmWasmClient, txSigner: string): OpenEditionMinterContract => {
|
||||||
const use = (contractAddress: string): OpenEditionMinterInstance => {
|
const use = (contractAddress: string): OpenEditionMinterInstance => {
|
||||||
//Query
|
//Query
|
||||||
|
const getFactoryParameters = async (factoryAddress: string): Promise<any> => {
|
||||||
|
const res = await client.queryContractSmart(factoryAddress, { params: {} })
|
||||||
|
return res
|
||||||
|
}
|
||||||
|
|
||||||
const getConfig = async (): Promise<any> => {
|
const getConfig = async (): Promise<any> => {
|
||||||
const res = await client.queryContractSmart(contractAddress, {
|
const res = await client.queryContractSmart(contractAddress, {
|
||||||
config: {},
|
config: {},
|
||||||
@ -338,6 +347,21 @@ export const openEditionMinter = (client: SigningCosmWasmClient, txSigner: strin
|
|||||||
}
|
}
|
||||||
|
|
||||||
const mintTo = async (senderAddress: string, recipient: string): Promise<string> => {
|
const mintTo = async (senderAddress: string, recipient: string): Promise<string> => {
|
||||||
|
const txHash = await getConfig().then(async (response) => {
|
||||||
|
const factoryParameters = await toast.promise(getFactoryParameters(response.factory), {
|
||||||
|
loading: 'Querying Factory Parameters...',
|
||||||
|
error: 'Querying Factory Parameters failed!',
|
||||||
|
success: 'Query successful! Minting...',
|
||||||
|
})
|
||||||
|
console.log(factoryParameters?.params?.extension?.airdrop_mint_fee_bps)
|
||||||
|
|
||||||
|
const price = factoryParameters?.params?.extension?.airdrop_mint_price.amount
|
||||||
|
if (!price) {
|
||||||
|
throw new Error(
|
||||||
|
'Unable to retrieve a valid airdrop mint price. It may be that the given contract address does not belong to a Open Edition Factory.',
|
||||||
|
)
|
||||||
|
}
|
||||||
|
console.log((Number(price) * Number(factoryParameters.params.extension?.airdrop_mint_fee_bps)) / 100)
|
||||||
const res = await client.execute(
|
const res = await client.execute(
|
||||||
senderAddress,
|
senderAddress,
|
||||||
contractAddress,
|
contractAddress,
|
||||||
@ -346,12 +370,33 @@ export const openEditionMinter = (client: SigningCosmWasmClient, txSigner: strin
|
|||||||
},
|
},
|
||||||
'auto',
|
'auto',
|
||||||
'',
|
'',
|
||||||
|
[
|
||||||
|
coin(
|
||||||
|
(Number(price) * Number(factoryParameters.params.extension?.airdrop_mint_fee_bps)) / 100 / 100,
|
||||||
|
'ustars',
|
||||||
|
),
|
||||||
|
],
|
||||||
)
|
)
|
||||||
|
|
||||||
return res.transactionHash
|
return res.transactionHash
|
||||||
|
})
|
||||||
|
return txHash
|
||||||
}
|
}
|
||||||
|
|
||||||
const batchMint = async (senderAddress: string, recipient: string, batchNumber: number): Promise<string> => {
|
const batchMint = async (senderAddress: string, recipient: string, batchNumber: number): Promise<string> => {
|
||||||
|
const txHash = await getConfig().then(async (response) => {
|
||||||
|
const factoryParameters = await toast.promise(getFactoryParameters(response?.factory), {
|
||||||
|
loading: 'Querying Factory Parameters...',
|
||||||
|
error: 'Querying Factory Parameters failed!',
|
||||||
|
success: 'Query successful! Minting...',
|
||||||
|
})
|
||||||
|
|
||||||
|
const price = factoryParameters?.params?.extension?.airdrop_mint_price.amount
|
||||||
|
if (!price) {
|
||||||
|
throw new Error(
|
||||||
|
'Unable to retrieve a valid airdrop mint price. It may be that the given contract address does not belong to a Open Edition Factory.',
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
const executeContractMsgs: MsgExecuteContractEncodeObject[] = []
|
const executeContractMsgs: MsgExecuteContractEncodeObject[] = []
|
||||||
for (let i = 0; i < batchNumber; i++) {
|
for (let i = 0; i < batchNumber; i++) {
|
||||||
const msg = {
|
const msg = {
|
||||||
@ -363,6 +408,12 @@ export const openEditionMinter = (client: SigningCosmWasmClient, txSigner: strin
|
|||||||
sender: senderAddress,
|
sender: senderAddress,
|
||||||
contract: contractAddress,
|
contract: contractAddress,
|
||||||
msg: toUtf8(JSON.stringify(msg)),
|
msg: toUtf8(JSON.stringify(msg)),
|
||||||
|
funds: [
|
||||||
|
coin(
|
||||||
|
(Number(price) * Number(factoryParameters.params.extension?.airdrop_mint_fee_bps)) / 100 / 100,
|
||||||
|
'ustars',
|
||||||
|
),
|
||||||
|
],
|
||||||
}),
|
}),
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -372,9 +423,25 @@ export const openEditionMinter = (client: SigningCosmWasmClient, txSigner: strin
|
|||||||
const res = await client.signAndBroadcast(senderAddress, executeContractMsgs, 'auto', 'batch mint')
|
const res = await client.signAndBroadcast(senderAddress, executeContractMsgs, 'auto', 'batch mint')
|
||||||
|
|
||||||
return res.transactionHash
|
return res.transactionHash
|
||||||
|
})
|
||||||
|
return txHash
|
||||||
}
|
}
|
||||||
|
|
||||||
const airdrop = async (senderAddress: string, recipients: string[]): Promise<string> => {
|
const airdrop = async (senderAddress: string, recipients: string[]): Promise<string> => {
|
||||||
|
const txHash = await getConfig().then(async (response) => {
|
||||||
|
const factoryParameters = await toast.promise(getFactoryParameters(response?.factory), {
|
||||||
|
loading: 'Querying Factory Parameters...',
|
||||||
|
error: 'Querying Factory Parameters failed!',
|
||||||
|
success: 'Query successful! Minting...',
|
||||||
|
})
|
||||||
|
|
||||||
|
const price = factoryParameters?.params?.extension?.airdrop_mint_price.amount
|
||||||
|
if (!price) {
|
||||||
|
throw new Error(
|
||||||
|
'Unable to retrieve a valid airdrop mint price. It may be that the given contract address does not belong to a Open Edition Factory.',
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
const executeContractMsgs: MsgExecuteContractEncodeObject[] = []
|
const executeContractMsgs: MsgExecuteContractEncodeObject[] = []
|
||||||
for (let i = 0; i < recipients.length; i++) {
|
for (let i = 0; i < recipients.length; i++) {
|
||||||
const msg = {
|
const msg = {
|
||||||
@ -386,6 +453,12 @@ export const openEditionMinter = (client: SigningCosmWasmClient, txSigner: strin
|
|||||||
sender: senderAddress,
|
sender: senderAddress,
|
||||||
contract: contractAddress,
|
contract: contractAddress,
|
||||||
msg: toUtf8(JSON.stringify(msg)),
|
msg: toUtf8(JSON.stringify(msg)),
|
||||||
|
funds: [
|
||||||
|
coin(
|
||||||
|
(Number(price) * Number(factoryParameters.params.extension?.airdrop_mint_fee_bps)) / 100 / 100,
|
||||||
|
'ustars',
|
||||||
|
),
|
||||||
|
],
|
||||||
}),
|
}),
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -395,6 +468,8 @@ export const openEditionMinter = (client: SigningCosmWasmClient, txSigner: strin
|
|||||||
const res = await client.signAndBroadcast(senderAddress, executeContractMsgs, 'auto', 'airdrop')
|
const res = await client.signAndBroadcast(senderAddress, executeContractMsgs, 'auto', 'airdrop')
|
||||||
|
|
||||||
return res.transactionHash
|
return res.transactionHash
|
||||||
|
})
|
||||||
|
return txHash
|
||||||
}
|
}
|
||||||
|
|
||||||
return {
|
return {
|
||||||
|
Loading…
Reference in New Issue
Block a user