From ea541cb6fad47230b6771da916669f9719d1a855 Mon Sep 17 00:00:00 2001 From: Ninjatosba Date: Wed, 23 Aug 2023 15:17:30 +0300 Subject: [PATCH 1/7] feat : add support for IBC minters instantiation --- src/create-collection/minter.ts | 61 +++++++++++++++++++++------------ 1 file changed, 40 insertions(+), 21 deletions(-) diff --git a/src/create-collection/minter.ts b/src/create-collection/minter.ts index 01e58197..8903a65e 100644 --- a/src/create-collection/minter.ts +++ b/src/create-collection/minter.ts @@ -12,6 +12,7 @@ import { formatRoyaltyInfo, } from '../helpers/utils'; import { toUtf8 } from '@cosmjs/encoding'; +import Prompt from 'inquirer/lib/prompts/base'; const config = require('../../config'); @@ -25,17 +26,17 @@ export type MinterParams = | { sg721CodeId: number; vendingMinterCodeId: number; - vendingFactory: string; + vendingFactoryAddresses: string; [k: string]: unknown; } | undefined; export async function create_minter(params: MinterParams) { if (params !== undefined) { - const { sg721CodeId, vendingMinterCodeId, vendingFactory } = params; + const { sg721CodeId, vendingMinterCodeId, vendingFactoryAddresses } = params; config.sg721BaseCodeId = sg721CodeId; config.vendingMinterCodeId = vendingMinterCodeId; - config.vendingFactory = vendingFactory; + config.vendingFactoryAddresses = vendingFactoryAddresses; } console.log('Collection name:', config.name); console.log('Account:', config.account, '\n'); @@ -104,6 +105,36 @@ export async function create_minter(params: MinterParams) { ); } + const factories = await Promise.all( + config.vendingFactoryAddresses.map(async (address: string) => { + const factory = await client.queryContractSmart(address, { + params: {}, + }); + return { + address: address, + denom: factory.params.min_mint_price.denom, + fee: factory.params.creation_fee.amount, + } + }) + ); + await new Promise((r) => setTimeout(r, 1000)); + + const pickedFactory = await inquirer.prompt([ + { + message: 'Pick a denom', + name: 'params', + type: 'list', + // Choises should be 1 to paramsResponses.length+1. FE [1,2,3,4,5] + choices: factories.map((factory: any, index: number) => { + return { + name: factory.denom, + value: factory, + }; + } + ), + }, + ]); + const initMsg: CreateMinterMsgForVendingMinterInitMsgExtension = { init_msg: { base_token_uri: config.baseTokenUri, @@ -111,7 +142,7 @@ export async function create_minter(params: MinterParams) { num_tokens: config.numTokens, mint_price: { amount: (config.mintPrice * 1000000).toString(), - denom: 'ustars', + denom: pickedFactory.params.denom, }, per_address_limit: config.perAddressLimit, payment_address: paymentAddress, @@ -131,19 +162,7 @@ export async function create_minter(params: MinterParams) { }, }, }; - - // should be stars1nelx34qg6xtm5u748jzjsahthddsktrrg5dw2rx8vzpc8hwwgk5q32mj2h - console.log('vending factory addr: ', config.vendingFactory); - - const paramsResponse = await client.queryContractSmart( - config.vendingFactory, - { - params: {}, - } - ); - console.log('params response', paramsResponse); - - const creationFee = paramsResponse.params.creation_fee.amount; + const creationFee = pickedFactory.params.fee const tempMsg = { create_minter: initMsg }; @@ -163,7 +182,7 @@ export async function create_minter(params: MinterParams) { typeUrl: '/cosmwasm.wasm.v1.MsgExecuteContract', value: { sender: account, - contract: config.vendingFactory, + contract: pickedFactory.params.address, msg: toUtf8( JSON.stringify(obj) ), @@ -198,7 +217,7 @@ export async function create_minter(params: MinterParams) { const result = await client.execute( account, - config.vendingFactory, + pickedFactory.params.address, msg, 'auto', config.name, @@ -223,7 +242,7 @@ async function create_updatable_vending_minter() { let params = { sg721CodeId: config.sg721UpdatableCodeId, vendingMinterCodeId: config.vendingMinterCodeId, - vendingFactory: config.updatableVendingFactory, + vendingFactoryAddresses: config.updatableVendingFactoryAddresses, }; create_minter(params); } @@ -233,7 +252,7 @@ async function create_flex_vending_minter() { let params = { sg721CodeId: config.sg721BaseCodeId, vendingMinterCodeId: config.flexibleVendingMinterCodeId, - vendingFactory: config.flexibleVendingFactory, + vendingFactoryAddresses: config.flexibleVendingFactoryAddresses, }; create_minter(params); } From e20f56d26c431c96f4e0f99c0b159eb05143703a Mon Sep 17 00:00:00 2001 From: Ninjatosba Date: Wed, 23 Aug 2023 15:19:56 +0300 Subject: [PATCH 2/7] feat : add support for IBC open edition minters --- src/create-collection/open-edition-minter.ts | 55 ++++++++++++++------ 1 file changed, 38 insertions(+), 17 deletions(-) diff --git a/src/create-collection/open-edition-minter.ts b/src/create-collection/open-edition-minter.ts index b787cc5a..96895e3c 100644 --- a/src/create-collection/open-edition-minter.ts +++ b/src/create-collection/open-edition-minter.ts @@ -20,17 +20,17 @@ export type OpenEditionMinterParams = | { sg721CodeId: number; openEditionMinterCodeId: number; - openEditionFactory: string; + openEditionFactoryAddresses: string; [k: string]: unknown; } | undefined; export async function create_minter(params: OpenEditionMinterParams) { if (params !== undefined) { - const { sg721CodeId, openEditionMinterCodeId, openEditionFactory } = params; + const { sg721CodeId, openEditionMinterCodeId, openEditionFactoryAddresses } = params; config.sg721OpenEditionCodeId = sg721CodeId; config.openEditionMinterCodeId = openEditionMinterCodeId; - config.openEditionFactory = openEditionFactory; + config.openEditionFactoryAddresses = openEditionFactoryAddresses; } console.log('Collection name:', config.name); console.log('Account:', config.account, '\n'); @@ -97,6 +97,35 @@ export async function create_minter(params: OpenEditionMinterParams) { const startTradingTime: Timestamp | null = config.openEditionMinterConfig.startTradingTime ? (new Date(config.openEditionMinterConfig.startTradingTime).getTime() * 1_000_000).toString() : null; + + const factories = await Promise.all( + config.openEditionFactoryAddresses.map(async (address: string) => { + const factory = await client.queryContractSmart(address, { + params: {}, + }); + return { + address: address, + denom: factory.params.min_mint_price.denom, + fee: factory.params.creation_fee.amount, + } + }) + ); + + const pickedFactory = await inquirer.prompt([ + { + message: 'Pick a denom', + name: 'params', + type: 'list', + // Choises should be 1 to paramsResponses.length+1. FE [1,2,3,4,5] + choices: factories.map((factory: any, index: number) => { + return { + name: factory.denom, + value: factory, + }; + } + ), + }, + ]); const initMsg = { init_msg: { @@ -117,7 +146,7 @@ export async function create_minter(params: OpenEditionMinterParams) { end_time: endTime, mint_price: { amount: (config.openEditionMinterConfig.mintPrice * 1000000).toString(), - denom: 'ustars', + denom: pickedFactory.params.denom, }, per_address_limit: config.openEditionMinterConfig.perAddressLimit, payment_address: paymentAddress, @@ -137,19 +166,11 @@ export async function create_minter(params: OpenEditionMinterParams) { }, }; - console.log('Open Edition Factory address: ', config.openEditionFactory); - - const paramsResponse = await client.queryContractSmart( - config.openEditionFactory, - { - params: {}, - } - ); - console.log('Open Edition Factory parameters: ', paramsResponse); + console.log('Open Edition Factory address: ', pickedFactory.params.address); const tempMsg = { create_minter: initMsg }; - const creationFee = paramsResponse.params.creation_fee.amount; + const creationFee = pickedFactory.params.fee; // TODO use recursive cleanup of undefined and null values if ( @@ -167,7 +188,7 @@ export async function create_minter(params: OpenEditionMinterParams) { typeUrl: '/cosmwasm.wasm.v1.MsgExecuteContract', value: { sender: account, - contract: config.openEditionFactory, + contract: pickedFactory.params.address, msg: toUtf8( JSON.stringify(obj) ), @@ -202,7 +223,7 @@ export async function create_minter(params: OpenEditionMinterParams) { const result = await client.execute( account, - config.openEditionFactory, + pickedFactory.params.address, msg, 'auto', config.name, @@ -227,7 +248,7 @@ async function create_updatable_open_edition_minter() { let params = { sg721CodeId: config.sg721OpenEditionUpdatableCodeId, openEditionMinterCodeId: config.openEditionMinterCodeId, - openEditionFactory: config.openEditionUpdatableFactory, + openEditionFactoryAddresses: config.openEditionUpdatableFactoryAddresses, }; create_minter(params); } From a8f3ef6541e9954cd7313ce39f6c58a4120d2eb1 Mon Sep 17 00:00:00 2001 From: Ninjatosba Date: Wed, 23 Aug 2023 15:21:05 +0300 Subject: [PATCH 3/7] feat : allow user to pick denom upon creating whitelist contract --- src/whitelist/whitelist-flex.ts | 20 +++++++++++++++++++- src/whitelist/whitelist.ts | 21 ++++++++++++++++++++- 2 files changed, 39 insertions(+), 2 deletions(-) diff --git a/src/whitelist/whitelist-flex.ts b/src/whitelist/whitelist-flex.ts index e2e7e68e..3244b3bb 100644 --- a/src/whitelist/whitelist-flex.ts +++ b/src/whitelist/whitelist-flex.ts @@ -50,6 +50,24 @@ async function init() { new Date(config.whitelistEndTime).getTime() * 1_000_000 ).toString(); + const flexibleVendingDenoms = await Promise.all( + config.flexibleVendingFactoryAddresses.map(async (factoryAddress: string) => { + const res = await client.queryContractSmart(factoryAddress, { + params: {}, + }); + return res.params.min_mint_price.denom; + }) + ); + // Ask user to select a denom for whitelist mint price + const denom = await inquirer.prompt([ + { + message: 'Select a denom for whitelist mint price', + name: 'denom', + type: 'list', + choices: flexibleVendingDenoms, + }, + ]); + // @ts-ignore const msg: InstantiateMsg = { members: whitelist, @@ -57,7 +75,7 @@ async function init() { end_time: whitelistEndTime, mint_price: { amount: (config.whitelistPrice * 1000000).toString(), - denom: 'ustars', + denom: denom, }, member_limit: config.whitelistMemberLimit, admins: [config.account], diff --git a/src/whitelist/whitelist.ts b/src/whitelist/whitelist.ts index b548d856..91fd3f0d 100644 --- a/src/whitelist/whitelist.ts +++ b/src/whitelist/whitelist.ts @@ -58,6 +58,25 @@ async function init() { const admins = config.admins || [config.account]; + const vendingMinterMintingDenoms = await Promise.all( + config.vendingFactoryAddresses.map(async (address: string) => { + let params = await client.queryContractSmart(address, { + params: {}, + }); + return params.params.min_mint_price.denom; + }) + ); + + // Ask user to pick denom for whitelist + const denom = await inquirer.prompt([ + { + message: 'Select a denom for whitelist mint price', + name: 'denom', + type: 'list', + choices: await vendingMinterMintingDenoms, + }, + ]); + // @ts-ignore const msg: InstantiateMsg = { admins: admins, @@ -67,7 +86,7 @@ async function init() { end_time: whitelistEndTime, mint_price: { amount: (config.whitelistPrice * 1000000).toString(), - denom: 'ustars', + denom: denom, }, per_address_limit: config.whitelistPerAddressLimit, member_limit: config.whitelistMemberLimit, From 665e6fbc62361cf8d093a3995c99b666ff7b728b Mon Sep 17 00:00:00 2001 From: Ninjatosba Date: Wed, 23 Aug 2023 16:56:14 +0300 Subject: [PATCH 4/7] fix : fix bug while whitelist instantiation related to denom --- src/whitelist/whitelist-flex.ts | 4 ++-- src/whitelist/whitelist.ts | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/src/whitelist/whitelist-flex.ts b/src/whitelist/whitelist-flex.ts index 3244b3bb..247ce43f 100644 --- a/src/whitelist/whitelist-flex.ts +++ b/src/whitelist/whitelist-flex.ts @@ -67,7 +67,7 @@ async function init() { choices: flexibleVendingDenoms, }, ]); - + // @ts-ignore const msg: InstantiateMsg = { members: whitelist, @@ -75,7 +75,7 @@ async function init() { end_time: whitelistEndTime, mint_price: { amount: (config.whitelistPrice * 1000000).toString(), - denom: denom, + denom: denom.denom, }, member_limit: config.whitelistMemberLimit, admins: [config.account], diff --git a/src/whitelist/whitelist.ts b/src/whitelist/whitelist.ts index 91fd3f0d..7e1239f8 100644 --- a/src/whitelist/whitelist.ts +++ b/src/whitelist/whitelist.ts @@ -86,7 +86,7 @@ async function init() { end_time: whitelistEndTime, mint_price: { amount: (config.whitelistPrice * 1000000).toString(), - denom: denom, + denom: denom.denom, }, per_address_limit: config.whitelistPerAddressLimit, member_limit: config.whitelistMemberLimit, From d03a2a43151337f150df7d12dadd3cf62e10e7fa Mon Sep 17 00:00:00 2001 From: Ninjatosba Date: Wed, 23 Aug 2023 16:58:28 +0300 Subject: [PATCH 5/7] feat : change config.example.js related to ibc minters --- config.example.js | 20 ++++++++++---------- 1 file changed, 10 insertions(+), 10 deletions(-) diff --git a/config.example.js b/config.example.js index 849fa13d..9c3db8b6 100644 --- a/config.example.js +++ b/config.example.js @@ -156,20 +156,20 @@ module.exports = { // The code ID for vending flexible minter for use with whitelist flexible flexibleVendingMinterCodeId: 2601, // Addr for vending factory contract - vendingFactory: - 'stars18h7ugh8eaug7wr0w4yjw0ls5s937z35pnkg935ucsek2y9xl3gaqqk4jtx', + vendingFactoryAddresses: + ['stars18h7ugh8eaug7wr0w4yjw0ls5s937z35pnkg935ucsek2y9xl3gaqqk4jtx'], // Addr for updatable vending factory contract - updatableVendingFactory: - 'stars1h65nms9gwg4vdktyqj84tu50gwlm34e0eczl5w2ezllxuzfxy9esa9qlt0', + updatableVendingFactoryAddresses: + ['stars1h65nms9gwg4vdktyqj84tu50gwlm34e0eczl5w2ezllxuzfxy9esa9qlt0'], // Addr for flexible vending factory contract - flexibleVendingFactory: - 'stars1hvu2ghqkcnvhtj2fc6wuazxt4dqcftslp2rwkkkcxy269a35a9pq60ug2q', + flexibleVendingFactoryAddresses: + ['stars1hvu2ghqkcnvhtj2fc6wuazxt4dqcftslp2rwkkkcxy269a35a9pq60ug2q'], // Addr for open edition factory contract - openEditionFactory: - 'stars13r06dn4jc6mudvvkl9rclxjctywm4nhl045jn9f8mk6vc53eylusy4zxzj', + openEditionFactoryAddresses: + ['stars13r06dn4jc6mudvvkl9rclxjctywm4nhl045jn9f8mk6vc53eylusy4zxzj'], // Addr for open edition updatable factory contract - openEditionUpdatableFactory: - 'stars1n7np7wdmm4ea8tapkz00j3jtxupne0g8v9jj02j96wfn9w9ukxgs6hcsv0', + openEditionUpdatableFactoryAddresses: + ['stars1n7np7wdmm4ea8tapkz00j3jtxupne0g8v9jj02j96wfn9w9ukxgs6hcsv0'], // The code ID for open edition minter openEditionMinterCodeId: 2579, // The code ID for the whitelist contract From c14264cb45f761592d27ea02ee692f3c52db0237 Mon Sep 17 00:00:00 2001 From: Ninjatosba Date: Wed, 23 Aug 2023 17:12:21 +0300 Subject: [PATCH 6/7] chore : clean up unnecessary comments --- src/create-collection/minter.ts | 1 - src/create-collection/open-edition-minter.ts | 1 - 2 files changed, 2 deletions(-) diff --git a/src/create-collection/minter.ts b/src/create-collection/minter.ts index 8903a65e..84f34868 100644 --- a/src/create-collection/minter.ts +++ b/src/create-collection/minter.ts @@ -124,7 +124,6 @@ export async function create_minter(params: MinterParams) { message: 'Pick a denom', name: 'params', type: 'list', - // Choises should be 1 to paramsResponses.length+1. FE [1,2,3,4,5] choices: factories.map((factory: any, index: number) => { return { name: factory.denom, diff --git a/src/create-collection/open-edition-minter.ts b/src/create-collection/open-edition-minter.ts index 96895e3c..566880b5 100644 --- a/src/create-collection/open-edition-minter.ts +++ b/src/create-collection/open-edition-minter.ts @@ -116,7 +116,6 @@ export async function create_minter(params: OpenEditionMinterParams) { message: 'Pick a denom', name: 'params', type: 'list', - // Choises should be 1 to paramsResponses.length+1. FE [1,2,3,4,5] choices: factories.map((factory: any, index: number) => { return { name: factory.denom, From dec683a71ddbbd0d06a82a8691e008f2b1fcec40 Mon Sep 17 00:00:00 2001 From: Ninjatosba Date: Thu, 24 Aug 2023 13:02:52 +0300 Subject: [PATCH 7/7] refactor : remove unnecessary code --- src/create-collection/minter.ts | 1 - 1 file changed, 1 deletion(-) diff --git a/src/create-collection/minter.ts b/src/create-collection/minter.ts index 84f34868..4d4d91cb 100644 --- a/src/create-collection/minter.ts +++ b/src/create-collection/minter.ts @@ -117,7 +117,6 @@ export async function create_minter(params: MinterParams) { } }) ); - await new Promise((r) => setTimeout(r, 1000)); const pickedFactory = await inquirer.prompt([ {