Merge pull request #147 from public-awesome/mint-price-related-updates

Dynamic minimum mint price checks during collection creation & mint price updates
This commit is contained in:
Serkan Reis 2023-04-07 12:45:42 +03:00 committed by GitHub
commit f9db6a301d
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
7 changed files with 56 additions and 15 deletions

View File

@ -1,4 +1,4 @@
APP_VERSION=0.5.7
APP_VERSION=0.5.8
NEXT_PUBLIC_PINATA_ENDPOINT_URL=https://api.pinata.cloud/pinning/pinFileToIPFS
NEXT_PUBLIC_SG721_CODE_ID=1911

View File

@ -297,9 +297,6 @@ export const CollectionActions = ({
if (minterContractAddress === '' && sg721ContractAddress === '') {
throw new Error('Please enter minter and sg721 contract addresses!')
}
if (type === 'update_mint_price' && priceState.value < 50) {
throw new Error('Mint price must be at least 50 STARS')
}
if (wallet.client && type === 'update_mint_price') {
const contractConfig = wallet.client.queryContractSmart(minterContractAddress, {
@ -337,6 +334,22 @@ export const CollectionActions = ({
.catch((error) => {
throw new Error(String(error).substring(String(error).lastIndexOf('Error:') + 7))
})
} else {
await contractConfig.then(async (config) => {
const factoryParameters = await wallet.client?.queryContractSmart(config.factory, {
params: {},
})
if (
factoryParameters.params.min_mint_price.amount &&
priceState.value < Number(factoryParameters.params.min_mint_price.amount) / 1000000
) {
throw new Error(
`Updated mint price cannot be lower than the minimum mint price of ${
Number(factoryParameters.params.min_mint_price.amount) / 1000000
} STARS`,
)
}
})
}
})
}

View File

@ -13,6 +13,7 @@ interface MintingDetailsProps {
onChange: (data: MintingDetailsDataProps) => void
numberOfTokens: number | undefined
uploadMethod: UploadMethod
minimumMintPrice: number
}
export interface MintingDetailsDataProps {
@ -23,7 +24,7 @@ export interface MintingDetailsDataProps {
paymentAddress?: string
}
export const MintingDetails = ({ onChange, numberOfTokens, uploadMethod }: MintingDetailsProps) => {
export const MintingDetails = ({ onChange, numberOfTokens, uploadMethod, minimumMintPrice }: MintingDetailsProps) => {
const wallet = useWallet()
const [timestamp, setTimestamp] = useState<Date | undefined>()
@ -40,7 +41,7 @@ export const MintingDetails = ({ onChange, numberOfTokens, uploadMethod }: Minti
id: 'unitPrice',
name: 'unitPrice',
title: 'Unit Price',
subtitle: 'Price of each token (min. 50 STARS)',
subtitle: `Price of each token (min. ${minimumMintPrice} STARS)`,
placeholder: '50',
})

View File

@ -49,7 +49,7 @@ export const WhitelistDetails = ({ onChange }: WhitelistDetailsProps) => {
id: 'unit-price',
name: 'unitPrice',
title: 'Unit Price',
subtitle: 'Token price for whitelisted addresses \n (min. 25 STARS)',
subtitle: 'Token price for whitelisted addresses \n (min. 0 STARS)',
placeholder: '25',
})

View File

@ -1,6 +1,6 @@
{
"name": "stargaze-studio",
"version": "0.5.7",
"version": "0.5.8",
"workspaces": [
"packages/*"
],

View File

@ -94,6 +94,8 @@ const CollectionCreationPage: NextPage = () => {
const [baseMinterCreationFee, setBaseMinterCreationFee] = useState<string | null>(null)
const [vendingMinterUpdatableCreationFee, setVendingMinterUpdatableCreationFee] = useState<string | null>(null)
const [baseMinterUpdatableCreationFee, setBaseMinterUpdatableCreationFee] = useState<string | null>(null)
const [minimumMintPrice, setMinimumMintPrice] = useState<string | null>('0')
const [minimumUpdatableMintPrice, setMinimumUpdatableMintPrice] = useState<string | null>('0')
const [uploading, setUploading] = useState(false)
const [isMintingComplete, setIsMintingComplete] = useState(false)
@ -784,8 +786,13 @@ const CollectionCreationPage: NextPage = () => {
const checkMintingDetails = () => {
if (!mintingDetails) throw new Error('Please fill out the minting details')
if (mintingDetails.numTokens < 1 || mintingDetails.numTokens > 10000) throw new Error('Invalid number of tokens')
if (Number(mintingDetails.unitPrice) < 50000000)
throw new Error('Invalid unit price: The minimum unit price is 50 STARS')
if (collectionDetails?.updatable) {
if (Number(mintingDetails.unitPrice) < Number(minimumUpdatableMintPrice))
throw new Error(
`Invalid unit price: The minimum unit price is ${Number(minimumUpdatableMintPrice) / 1000000} STARS`,
)
} else if (Number(mintingDetails.unitPrice) < Number(minimumMintPrice))
throw new Error(`Invalid unit price: The minimum unit price is ${Number(minimumMintPrice) / 1000000} STARS`)
if (
!mintingDetails.perAddressLimit ||
mintingDetails.perAddressLimit < 1 ||
@ -848,8 +855,8 @@ const CollectionCreationPage: NextPage = () => {
} else if (whitelistDetails.whitelistType === 'new') {
if (whitelistDetails.members?.length === 0) throw new Error('Whitelist member list cannot be empty')
if (whitelistDetails.unitPrice === '') throw new Error('Whitelist unit price is required')
if (Number(whitelistDetails.unitPrice) < 25000000)
throw new Error('Invalid unit price: The minimum unit price for whitelisted addresses is 25 STARS')
if (Number(whitelistDetails.unitPrice) < 0)
throw new Error('Invalid unit price: The unit price cannot be negative')
if (whitelistDetails.startTime === '') throw new Error('Start time is required')
if (whitelistDetails.endTime === '') throw new Error('End time is required')
if (!whitelistDetails.perAddressLimit || whitelistDetails.perAddressLimit === 0)
@ -929,12 +936,14 @@ const CollectionCreationPage: NextPage = () => {
if (VENDING_FACTORY_ADDRESS) {
const vendingFactoryParameters = await client.queryContractSmart(VENDING_FACTORY_ADDRESS, { params: {} })
setVendingMinterCreationFee(vendingFactoryParameters?.params?.creation_fee?.amount)
setMinimumMintPrice(vendingFactoryParameters?.params?.min_mint_price?.amount)
}
if (VENDING_FACTORY_UPDATABLE_ADDRESS) {
const vendingFactoryUpdatableParameters = await client.queryContractSmart(VENDING_FACTORY_UPDATABLE_ADDRESS, {
params: {},
})
setVendingMinterUpdatableCreationFee(vendingFactoryUpdatableParameters?.params?.creation_fee?.amount)
setMinimumUpdatableMintPrice(vendingFactoryUpdatableParameters?.params?.min_mint_price?.amount)
}
}
@ -1285,6 +1294,11 @@ const CollectionCreationPage: NextPage = () => {
</Conditional>
<Conditional test={minterType === 'vending'}>
<MintingDetails
minimumMintPrice={
collectionDetails?.updatable
? Number(minimumUpdatableMintPrice) / 1000000
: Number(minimumMintPrice) / 1000000
}
numberOfTokens={uploadDetails?.assetFiles.length}
onChange={setMintingDetails}
uploadMethod={uploadDetails?.uploadMethod as UploadMethod}

View File

@ -113,9 +113,6 @@ const VendingMinterExecutePage: NextPage = () => {
if (contractState.value === '') {
throw new Error('Please enter the contract address.')
}
if (type === 'update_mint_price' && priceState.value < 50) {
throw new Error('Mint price must be at least 50 STARS')
}
if (wallet.client && type === 'update_mint_price') {
const contractConfig = wallet.client.queryContractSmart(contractState.value, {
@ -153,6 +150,22 @@ const VendingMinterExecutePage: NextPage = () => {
.catch((error) => {
throw new Error(String(error).substring(String(error).lastIndexOf('Error:') + 7))
})
} else {
await contractConfig.then(async (config) => {
const factoryParameters = await wallet.client?.queryContractSmart(config.factory, {
params: {},
})
if (
factoryParameters.params.min_mint_price.amount &&
priceState.value < Number(factoryParameters.params.min_mint_price.amount) / 1000000
) {
throw new Error(
`Updated mint price cannot be lower than the minimum mint price of ${
Number(factoryParameters.params.min_mint_price.amount) / 1000000
} STARS`,
)
}
})
}
})
}