Handle non-STARS creation fees for vending & base minter

This commit is contained in:
Serkan Reis 2024-05-22 20:25:41 +03:00
parent d1b5041312
commit fa1475f109

View File

@ -7,6 +7,7 @@
/* eslint-disable @typescript-eslint/no-unsafe-member-access */ /* eslint-disable @typescript-eslint/no-unsafe-member-access */
import { toUtf8 } from '@cosmjs/encoding' import { toUtf8 } from '@cosmjs/encoding'
import type { Coin } from '@cosmjs/proto-signing'
import { coin } from '@cosmjs/proto-signing' import { coin } from '@cosmjs/proto-signing'
import { Sidetab } from '@typeform/embed-react' import { Sidetab } from '@typeform/embed-react'
import axios from 'axios' import axios from 'axios'
@ -126,12 +127,12 @@ const CollectionCreationPage: NextPage = () => {
const [royaltyDetails, setRoyaltyDetails] = useState<RoyaltyDetailsDataProps | null>(null) const [royaltyDetails, setRoyaltyDetails] = useState<RoyaltyDetailsDataProps | null>(null)
const [minterType, setMinterType] = useState<MinterType>('vending') const [minterType, setMinterType] = useState<MinterType>('vending')
const [vendingMinterCreationFee, setVendingMinterCreationFee] = useState<string | null>(null) const [vendingMinterCreationFee, setVendingMinterCreationFee] = useState<Coin | null>(null)
const [baseMinterCreationFee, setBaseMinterCreationFee] = useState<string | null>(null) const [baseMinterCreationFee, setBaseMinterCreationFee] = useState<Coin | null>(null)
const [vendingMinterUpdatableCreationFee, setVendingMinterUpdatableCreationFee] = useState<string | null>(null) const [vendingMinterUpdatableCreationFee, setVendingMinterUpdatableCreationFee] = useState<Coin | null>(null)
const [openEditionMinterCreationFee, setOpenEditionMinterCreationFee] = useState<string | null>(null) const [openEditionMinterCreationFee, setOpenEditionMinterCreationFee] = useState<Coin | null>(null)
const [vendingMinterFlexCreationFee, setVendingMinterFlexCreationFee] = useState<string | null>(null) const [vendingMinterFlexCreationFee, setVendingMinterFlexCreationFee] = useState<Coin | null>(null)
const [baseMinterUpdatableCreationFee, setBaseMinterUpdatableCreationFee] = useState<string | null>(null) const [baseMinterUpdatableCreationFee, setBaseMinterUpdatableCreationFee] = useState<Coin | null>(null)
const [minimumMintPrice, setMinimumMintPrice] = useState<string | null>('0') const [minimumMintPrice, setMinimumMintPrice] = useState<string | null>('0')
const [minimumUpdatableMintPrice, setMinimumUpdatableMintPrice] = useState<string | null>('0') const [minimumUpdatableMintPrice, setMinimumUpdatableMintPrice] = useState<string | null>('0')
const [minimumOpenEditionMintPrice, setMinimumOpenEditionMintPrice] = useState<string | null>('0') const [minimumOpenEditionMintPrice, setMinimumOpenEditionMintPrice] = useState<string | null>('0')
@ -675,14 +676,11 @@ const CollectionCreationPage: NextPage = () => {
txSigner: wallet.address || '', txSigner: wallet.address || '',
msg, msg,
funds: [ funds: [
coin( whitelistDetails?.whitelistState !== 'none' && whitelistDetails?.whitelistType === 'flex'
whitelistDetails?.whitelistState !== 'none' && whitelistDetails?.whitelistType === 'flex' ? (vendingMinterFlexCreationFee as Coin)
? (vendingMinterFlexCreationFee as string) : collectionDetails?.updatable
: collectionDetails?.updatable ? (vendingMinterUpdatableCreationFee as Coin)
? (vendingMinterUpdatableCreationFee as string) : (vendingMinterCreationFee as Coin),
: (vendingMinterCreationFee as string),
'ustars',
),
], ],
updatable: collectionDetails?.updatable, updatable: collectionDetails?.updatable,
flex: whitelistDetails?.whitelistState !== 'none' && whitelistDetails?.whitelistType === 'flex', flex: whitelistDetails?.whitelistState !== 'none' && whitelistDetails?.whitelistType === 'flex',
@ -736,10 +734,7 @@ const CollectionCreationPage: NextPage = () => {
txSigner: wallet.address || '', txSigner: wallet.address || '',
msg, msg,
funds: [ funds: [
coin( collectionDetails?.updatable ? (baseMinterUpdatableCreationFee as Coin) : (baseMinterCreationFee as Coin),
collectionDetails?.updatable ? (baseMinterUpdatableCreationFee as string) : (baseMinterCreationFee as string),
'ustars',
),
], ],
updatable: collectionDetails?.updatable, updatable: collectionDetails?.updatable,
} }
@ -1216,7 +1211,7 @@ const CollectionCreationPage: NextPage = () => {
toast.error(`${error.message}`, { style: { maxWidth: 'none' } }) toast.error(`${error.message}`, { style: { maxWidth: 'none' } })
addLogItem({ id: uid(), message: error.message, type: 'Error', timestamp: new Date() }) addLogItem({ id: uid(), message: error.message, type: 'Error', timestamp: new Date() })
}) })
setBaseMinterCreationFee(baseFactoryParameters?.params?.creation_fee?.amount) setBaseMinterCreationFee(baseFactoryParameters?.params?.creation_fee)
} }
if (BASE_FACTORY_UPDATABLE_ADDRESS) { if (BASE_FACTORY_UPDATABLE_ADDRESS) {
const baseFactoryUpdatableParameters = await client const baseFactoryUpdatableParameters = await client
@ -1227,7 +1222,7 @@ const CollectionCreationPage: NextPage = () => {
toast.error(`${error.message}`, { style: { maxWidth: 'none' } }) toast.error(`${error.message}`, { style: { maxWidth: 'none' } })
addLogItem({ id: uid(), message: error.message, type: 'Error', timestamp: new Date() }) addLogItem({ id: uid(), message: error.message, type: 'Error', timestamp: new Date() })
}) })
setBaseMinterUpdatableCreationFee(baseFactoryUpdatableParameters?.params?.creation_fee?.amount) setBaseMinterUpdatableCreationFee(baseFactoryUpdatableParameters?.params?.creation_fee)
} }
if (VENDING_FACTORY_ADDRESS) { if (VENDING_FACTORY_ADDRESS) {
const vendingFactoryParameters = await client const vendingFactoryParameters = await client
@ -1236,7 +1231,7 @@ const CollectionCreationPage: NextPage = () => {
toast.error(`${error.message}`, { style: { maxWidth: 'none' } }) toast.error(`${error.message}`, { style: { maxWidth: 'none' } })
addLogItem({ id: uid(), message: error.message, type: 'Error', timestamp: new Date() }) addLogItem({ id: uid(), message: error.message, type: 'Error', timestamp: new Date() })
}) })
setVendingMinterCreationFee(vendingFactoryParameters?.params?.creation_fee?.amount) setVendingMinterCreationFee(vendingFactoryParameters?.params?.creation_fee)
setMinimumMintPrice(vendingFactoryParameters?.params?.min_mint_price?.amount) setMinimumMintPrice(vendingFactoryParameters?.params?.min_mint_price?.amount)
} }
if (VENDING_FACTORY_UPDATABLE_ADDRESS) { if (VENDING_FACTORY_UPDATABLE_ADDRESS) {
@ -1248,7 +1243,7 @@ const CollectionCreationPage: NextPage = () => {
toast.error(`${error.message}`, { style: { maxWidth: 'none' } }) toast.error(`${error.message}`, { style: { maxWidth: 'none' } })
addLogItem({ id: uid(), message: error.message, type: 'Error', timestamp: new Date() }) addLogItem({ id: uid(), message: error.message, type: 'Error', timestamp: new Date() })
}) })
setVendingMinterUpdatableCreationFee(vendingFactoryUpdatableParameters?.params?.creation_fee?.amount) setVendingMinterUpdatableCreationFee(vendingFactoryUpdatableParameters?.params?.creation_fee)
setMinimumUpdatableMintPrice(vendingFactoryUpdatableParameters?.params?.min_mint_price?.amount) setMinimumUpdatableMintPrice(vendingFactoryUpdatableParameters?.params?.min_mint_price?.amount)
} }
if (VENDING_FACTORY_FLEX_ADDRESS) { if (VENDING_FACTORY_FLEX_ADDRESS) {
@ -1260,7 +1255,7 @@ const CollectionCreationPage: NextPage = () => {
toast.error(`${error.message}`, { style: { maxWidth: 'none' } }) toast.error(`${error.message}`, { style: { maxWidth: 'none' } })
addLogItem({ id: uid(), message: error.message, type: 'Error', timestamp: new Date() }) addLogItem({ id: uid(), message: error.message, type: 'Error', timestamp: new Date() })
}) })
setVendingMinterFlexCreationFee(vendingFactoryFlexParameters?.params?.creation_fee?.amount) setVendingMinterFlexCreationFee(vendingFactoryFlexParameters?.params?.creation_fee)
setMinimumFlexMintPrice(vendingFactoryFlexParameters?.params?.min_mint_price?.amount) setMinimumFlexMintPrice(vendingFactoryFlexParameters?.params?.min_mint_price?.amount)
} }
if (OPEN_EDITION_FACTORY_ADDRESS) { if (OPEN_EDITION_FACTORY_ADDRESS) {
@ -1270,7 +1265,7 @@ const CollectionCreationPage: NextPage = () => {
toast.error(`${error.message}`, { style: { maxWidth: 'none' } }) toast.error(`${error.message}`, { style: { maxWidth: 'none' } })
addLogItem({ id: uid(), message: error.message, type: 'Error', timestamp: new Date() }) addLogItem({ id: uid(), message: error.message, type: 'Error', timestamp: new Date() })
}) })
setOpenEditionMinterCreationFee(openEditionFactoryParameters?.params?.creation_fee?.amount) setOpenEditionMinterCreationFee(openEditionFactoryParameters?.params?.creation_fee)
setMinimumOpenEditionMintPrice(openEditionFactoryParameters?.params?.min_mint_price?.amount) setMinimumOpenEditionMintPrice(openEditionFactoryParameters?.params?.min_mint_price?.amount)
} }
setInitialParametersFetched(true) setInitialParametersFetched(true)
@ -1300,7 +1295,7 @@ const CollectionCreationPage: NextPage = () => {
toast.error(`${error.message}`, { style: { maxWidth: 'none' } }) toast.error(`${error.message}`, { style: { maxWidth: 'none' } })
addLogItem({ id: uid(), message: error.message, type: 'Error', timestamp: new Date() }) addLogItem({ id: uid(), message: error.message, type: 'Error', timestamp: new Date() })
}) })
setOpenEditionMinterCreationFee(openEditionFactoryParameters?.params?.creation_fee?.amount) setOpenEditionMinterCreationFee(openEditionFactoryParameters?.params?.creation_fee)
setMinimumOpenEditionMintPrice(openEditionFactoryParameters?.params?.min_mint_price?.amount) setMinimumOpenEditionMintPrice(openEditionFactoryParameters?.params?.min_mint_price?.amount)
setMintTokenFromOpenEditionFactory( setMintTokenFromOpenEditionFactory(
tokensList.find((token) => token.denom === openEditionFactoryParameters?.params?.min_mint_price?.denom), tokensList.find((token) => token.denom === openEditionFactoryParameters?.params?.min_mint_price?.denom),
@ -1347,13 +1342,13 @@ const CollectionCreationPage: NextPage = () => {
}) })
if (whitelistDetails?.whitelistState !== 'none' && whitelistDetails?.whitelistType === 'flex') { if (whitelistDetails?.whitelistState !== 'none' && whitelistDetails?.whitelistType === 'flex') {
setVendingMinterFlexCreationFee(vendingFactoryParameters?.params?.creation_fee?.amount) setVendingMinterFlexCreationFee(vendingFactoryParameters?.params?.creation_fee)
setMinimumFlexMintPrice(vendingFactoryParameters?.params?.min_mint_price?.amount) setMinimumFlexMintPrice(vendingFactoryParameters?.params?.min_mint_price?.amount)
} else if (collectionDetails?.updatable) { } else if (collectionDetails?.updatable) {
setVendingMinterUpdatableCreationFee(vendingFactoryParameters?.params?.creation_fee?.amount) setVendingMinterUpdatableCreationFee(vendingFactoryParameters?.params?.creation_fee)
setMinimumUpdatableMintPrice(vendingFactoryParameters?.params?.min_mint_price?.amount) setMinimumUpdatableMintPrice(vendingFactoryParameters?.params?.min_mint_price?.amount)
} else { } else {
setVendingMinterCreationFee(vendingFactoryParameters?.params?.creation_fee?.amount) setVendingMinterCreationFee(vendingFactoryParameters?.params?.creation_fee)
setMinimumMintPrice(vendingFactoryParameters?.params?.min_mint_price?.amount) setMinimumMintPrice(vendingFactoryParameters?.params?.min_mint_price?.amount)
} }
setMintTokenFromVendingFactory( setMintTokenFromVendingFactory(
@ -1372,53 +1367,82 @@ const CollectionCreationPage: NextPage = () => {
]) ])
const checkwalletBalance = async () => { const checkwalletBalance = async () => {
await (await wallet.getCosmWasmClient()).getBalance(wallet.address || '', 'ustars').then((balance) => { const queryClient = await wallet.getCosmWasmClient()
if (minterType === 'vending' && whitelistDetails?.whitelistState === 'new') {
if (whitelistDetails.whitelistType !== 'merkletree' && whitelistDetails.memberLimit) { const creationFee: Coin | null =
const amountNeeded = minterType === 'vending'
Math.ceil(Number(whitelistDetails.memberLimit) / 1000) * 100000000 + ? whitelistDetails?.whitelistType === 'flex'
(whitelistDetails.whitelistType === 'flex' ? vendingMinterFlexCreationFee
? Number(vendingMinterFlexCreationFee) : collectionDetails?.updatable
: collectionDetails?.updatable ? vendingMinterUpdatableCreationFee
? Number(vendingMinterUpdatableCreationFee) : vendingMinterCreationFee
: Number(vendingMinterCreationFee)) : collectionDetails?.updatable
if (amountNeeded >= Number(balance.amount)) ? baseMinterUpdatableCreationFee
: baseMinterCreationFee
const creationFeeDenom = tokensList.find((token) => token.denom === creationFee?.denom)
await queryClient.getBalance(wallet.address || '', 'ustars').then(async (starsBalance) => {
await queryClient
.getBalance(wallet.address || '', creationFee?.denom as string)
.then((creationFeeDenomBalance) => {
if (minterType === 'vending' && whitelistDetails?.whitelistState === 'new') {
if (whitelistDetails.whitelistType !== 'merkletree' && whitelistDetails.memberLimit) {
const whitelistCreationFee = Math.ceil(Number(whitelistDetails.memberLimit) / 1000) * 100000000
if (creationFee?.denom === 'ustars') {
const amountNeeded = whitelistCreationFee + Number(creationFee.amount)
if (amountNeeded >= Number(starsBalance.amount))
throw new Error(
`Insufficient wallet balance to instantiate the required contracts. Needed amount: ${(
amountNeeded / 1000000
).toString()} STARS`,
)
} else {
if (whitelistCreationFee >= Number(starsBalance.amount))
throw new Error(
`Insufficient wallet balance to instantiate the whitelist. Needed amount: ${(
whitelistCreationFee / 1000000
).toString()} STARS`,
)
if (Number(creationFee?.amount) > Number(creationFeeDenomBalance.amount))
throw new Error(
`Insufficient wallet balance to instantiate the required contracts. Needed amount: ${(
Number(creationFee?.amount) / 1000000
).toString()} ${creationFeeDenom ? creationFeeDenom.displayName : creationFee?.denom}`,
)
}
} else if (whitelistDetails.whitelistType === 'merkletree') {
const merkleWhitelistCreationFee = 1000000000
if (creationFee?.denom === 'ustars') {
const amountNeeded = merkleWhitelistCreationFee + Number(creationFee.amount)
if (amountNeeded >= Number(starsBalance.amount))
throw new Error(
`Insufficient wallet balance to instantiate the required contracts. Needed amount: ${(
amountNeeded / 1000000
).toString()} STARS`,
)
} else {
if (merkleWhitelistCreationFee >= Number(starsBalance.amount))
throw new Error(
`Insufficient wallet balance to instantiate the whitelist. Needed amount: ${(
merkleWhitelistCreationFee / 1000000
).toString()} STARS`,
)
if (Number(creationFee?.amount) > Number(creationFeeDenomBalance.amount))
throw new Error(
`Insufficient wallet balance to instantiate the required contracts. Needed amount: ${(
Number(creationFee?.amount) / 1000000
).toString()} ${creationFeeDenom ? creationFeeDenom.displayName : creationFee?.denom}`,
)
}
}
} else if (Number(creationFee?.amount) > Number(creationFeeDenomBalance.amount))
throw new Error( throw new Error(
`Insufficient wallet balance to instantiate the required contracts. Needed amount: ${( `Insufficient wallet balance to instantiate the required contracts. Needed amount: ${(
amountNeeded / 1000000 Number(creationFee?.amount) / 1000000
).toString()} STARS`, ).toString()} ${creationFeeDenom ? creationFeeDenom.displayName : creationFee?.denom}`,
) )
} else if (whitelistDetails.whitelistType === 'merkletree') { })
const amountNeeded =
1000000000 +
(collectionDetails?.updatable
? Number(vendingMinterUpdatableCreationFee)
: Number(vendingMinterCreationFee))
if (amountNeeded >= Number(balance.amount))
throw new Error(
`Insufficient wallet balance to instantiate the required contracts. Needed amount: ${(
amountNeeded / 1000000
).toString()} STARS`,
)
}
} else {
const amountNeeded =
minterType === 'vending'
? whitelistDetails?.whitelistState === 'existing' && whitelistDetails.whitelistType === 'flex'
? Number(vendingMinterFlexCreationFee)
: collectionDetails?.updatable
? Number(vendingMinterUpdatableCreationFee)
: Number(vendingMinterCreationFee)
: collectionDetails?.updatable
? Number(baseMinterUpdatableCreationFee)
: Number(baseMinterCreationFee)
if (amountNeeded >= Number(balance.amount))
throw new Error(
`Insufficient wallet balance to instantiate the required contracts. Needed amount: ${(
amountNeeded / 1000000
).toString()} STARS`,
)
}
}) })
} }
@ -1934,7 +1958,7 @@ const CollectionCreationPage: NextPage = () => {
onChange={setOpenEditionMinterCreatorData} onChange={setOpenEditionMinterCreatorData}
onDetailsChange={setOpenEditionMinterDetails} onDetailsChange={setOpenEditionMinterDetails}
openEditionFactoryAddress={openEditionFactoryAddress} openEditionFactoryAddress={openEditionFactoryAddress}
openEditionMinterCreationFee={openEditionMinterCreationFee as string} openEditionMinterCreationFee={openEditionMinterCreationFee?.amount as string}
/> />
</Conditional> </Conditional>
<div className="mx-10"> <div className="mx-10">