2022-12-09 08:27:50 +00:00
|
|
|
import type { SigningCosmWasmClient } from '@cosmjs/cosmwasm-stargate'
|
|
|
|
import type { Coin } from '@cosmjs/proto-signing'
|
|
|
|
import { coin } from '@cosmjs/proto-signing'
|
|
|
|
import type { logs } from '@cosmjs/stargate'
|
|
|
|
import { BASE_FACTORY_ADDRESS } from 'utils/constants'
|
|
|
|
|
2023-02-26 10:08:03 +00:00
|
|
|
import { BASE_FACTORY_UPDATABLE_ADDRESS } from '../../utils/constants'
|
|
|
|
|
2022-12-09 08:27:50 +00:00
|
|
|
export interface CreateBaseMinterResponse {
|
|
|
|
readonly baseMinterAddress: string
|
|
|
|
readonly sg721Address: string
|
|
|
|
readonly transactionHash: string
|
|
|
|
readonly logs: readonly logs.Log[]
|
|
|
|
}
|
|
|
|
|
|
|
|
export interface BaseFactoryInstance {
|
|
|
|
readonly contractAddress: string
|
|
|
|
|
|
|
|
//Query
|
|
|
|
getParams: () => Promise<any>
|
|
|
|
//Execute
|
|
|
|
createBaseMinter: (
|
|
|
|
senderAddress: string,
|
|
|
|
msg: Record<string, unknown>,
|
|
|
|
funds: Coin[],
|
2023-02-26 10:08:03 +00:00
|
|
|
updatable?: boolean,
|
2022-12-09 08:27:50 +00:00
|
|
|
) => Promise<CreateBaseMinterResponse>
|
|
|
|
}
|
|
|
|
|
|
|
|
export interface BaseFactoryMessages {
|
2023-02-26 10:08:03 +00:00
|
|
|
createBaseMinter: (msg: Record<string, unknown>, updatable?: boolean) => CreateBaseMinterMessage
|
2022-12-09 08:27:50 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
export interface CreateBaseMinterMessage {
|
|
|
|
sender: string
|
|
|
|
contract: string
|
|
|
|
msg: Record<string, unknown>
|
|
|
|
funds: Coin[]
|
|
|
|
}
|
|
|
|
|
|
|
|
export interface BaseFactoryContract {
|
|
|
|
use: (contractAddress: string) => BaseFactoryInstance
|
|
|
|
|
|
|
|
messages: (contractAddress: string) => BaseFactoryMessages
|
|
|
|
}
|
|
|
|
|
|
|
|
export const baseFactory = (client: SigningCosmWasmClient, txSigner: string): BaseFactoryContract => {
|
|
|
|
const use = (contractAddress: string): BaseFactoryInstance => {
|
|
|
|
//Query
|
|
|
|
const getParams = async (): Promise<any> => {
|
|
|
|
const res = await client.queryContractSmart(contractAddress, {
|
|
|
|
params: {},
|
|
|
|
})
|
|
|
|
return res
|
|
|
|
}
|
|
|
|
|
|
|
|
//Execute
|
|
|
|
const createBaseMinter = async (
|
|
|
|
senderAddress: string,
|
|
|
|
msg: Record<string, unknown>,
|
|
|
|
funds: Coin[],
|
2023-02-26 10:08:03 +00:00
|
|
|
updatable?: boolean,
|
2022-12-09 08:27:50 +00:00
|
|
|
): Promise<CreateBaseMinterResponse> => {
|
2023-02-26 10:08:03 +00:00
|
|
|
const result = await client.execute(
|
|
|
|
senderAddress,
|
|
|
|
updatable ? BASE_FACTORY_UPDATABLE_ADDRESS : BASE_FACTORY_ADDRESS,
|
|
|
|
msg,
|
|
|
|
'auto',
|
|
|
|
'',
|
|
|
|
funds,
|
|
|
|
)
|
2022-12-09 08:27:50 +00:00
|
|
|
|
|
|
|
return {
|
|
|
|
baseMinterAddress: result.logs[0].events[5].attributes[0].value,
|
|
|
|
sg721Address: result.logs[0].events[5].attributes[2].value,
|
|
|
|
transactionHash: result.transactionHash,
|
|
|
|
logs: result.logs,
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return {
|
|
|
|
contractAddress,
|
|
|
|
getParams,
|
|
|
|
createBaseMinter,
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
const messages = (contractAddress: string) => {
|
2023-02-26 10:08:03 +00:00
|
|
|
const createBaseMinter = (msg: Record<string, unknown>, updatable?: boolean): CreateBaseMinterMessage => {
|
2022-12-09 08:27:50 +00:00
|
|
|
return {
|
|
|
|
sender: txSigner,
|
|
|
|
contract: contractAddress,
|
|
|
|
msg,
|
2023-03-31 16:38:26 +00:00
|
|
|
funds: [coin(updatable ? '3000000000' : '250000000', 'ustars')],
|
2022-12-09 08:27:50 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return {
|
|
|
|
createBaseMinter,
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return { use, messages }
|
|
|
|
}
|