2023-04-27 17:16:40 +00:00
|
|
|
/* eslint-disable eslint-comments/disable-enable-pair */
|
2023-08-06 15:44:22 +00:00
|
|
|
|
2022-10-21 01:02:52 +00:00
|
|
|
import type { SigningCosmWasmClient } from '@cosmjs/cosmwasm-stargate'
|
|
|
|
import type { Coin } from '@cosmjs/proto-signing'
|
|
|
|
import type { logs } from '@cosmjs/stargate'
|
2023-02-26 10:08:03 +00:00
|
|
|
|
2022-12-09 08:27:50 +00:00
|
|
|
export interface CreateVendingMinterResponse {
|
|
|
|
readonly vendingMinterAddress: string
|
2022-10-21 01:02:52 +00:00
|
|
|
readonly sg721Address: string
|
|
|
|
readonly transactionHash: string
|
|
|
|
readonly logs: readonly logs.Log[]
|
|
|
|
}
|
|
|
|
|
|
|
|
export interface VendingFactoryInstance {
|
|
|
|
readonly contractAddress: string
|
|
|
|
|
|
|
|
//Query
|
|
|
|
|
|
|
|
//Execute
|
2022-12-09 08:27:50 +00:00
|
|
|
createVendingMinter: (
|
|
|
|
senderAddress: string,
|
|
|
|
msg: Record<string, unknown>,
|
|
|
|
funds: Coin[],
|
2023-02-26 10:08:03 +00:00
|
|
|
updatable?: boolean,
|
2023-04-27 17:16:40 +00:00
|
|
|
flex?: boolean,
|
2022-12-09 08:27:50 +00:00
|
|
|
) => Promise<CreateVendingMinterResponse>
|
2022-10-21 01:02:52 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
export interface VendingFactoryMessages {
|
2023-04-27 17:16:40 +00:00
|
|
|
createVendingMinter: (
|
|
|
|
msg: Record<string, unknown>,
|
|
|
|
funds: Coin[],
|
|
|
|
updatable?: boolean,
|
|
|
|
flex?: boolean,
|
|
|
|
) => CreateVendingMinterMessage
|
2022-10-21 01:02:52 +00:00
|
|
|
}
|
|
|
|
|
2022-12-09 08:27:50 +00:00
|
|
|
export interface CreateVendingMinterMessage {
|
2022-10-21 01:02:52 +00:00
|
|
|
sender: string
|
|
|
|
contract: string
|
|
|
|
msg: Record<string, unknown>
|
|
|
|
funds: Coin[]
|
|
|
|
}
|
|
|
|
|
|
|
|
export interface VendingFactoryContract {
|
|
|
|
use: (contractAddress: string) => VendingFactoryInstance
|
|
|
|
|
|
|
|
messages: (contractAddress: string) => VendingFactoryMessages
|
|
|
|
}
|
|
|
|
|
|
|
|
export const vendingFactory = (client: SigningCosmWasmClient, txSigner: string): VendingFactoryContract => {
|
|
|
|
const use = (contractAddress: string): VendingFactoryInstance => {
|
|
|
|
//Query
|
|
|
|
|
|
|
|
//Execute
|
2022-12-09 08:27:50 +00:00
|
|
|
const createVendingMinter = async (
|
2022-10-21 01:02:52 +00:00
|
|
|
senderAddress: string,
|
|
|
|
msg: Record<string, unknown>,
|
|
|
|
funds: Coin[],
|
2023-02-26 10:08:03 +00:00
|
|
|
updatable?: boolean,
|
2023-04-27 17:16:40 +00:00
|
|
|
flex?: boolean,
|
2022-12-09 08:27:50 +00:00
|
|
|
): Promise<CreateVendingMinterResponse> => {
|
2023-08-06 15:44:22 +00:00
|
|
|
const result = await client.execute(senderAddress, contractAddress, msg, 'auto', '', funds)
|
2022-10-21 01:02:52 +00:00
|
|
|
|
|
|
|
return {
|
2022-12-09 08:27:50 +00:00
|
|
|
vendingMinterAddress: result.logs[0].events[5].attributes[0].value,
|
2022-10-21 01:02:52 +00:00
|
|
|
sg721Address: result.logs[0].events[5].attributes[2].value,
|
|
|
|
transactionHash: result.transactionHash,
|
|
|
|
logs: result.logs,
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return {
|
|
|
|
contractAddress,
|
2022-12-09 08:27:50 +00:00
|
|
|
createVendingMinter,
|
2022-10-21 01:02:52 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
const messages = (contractAddress: string) => {
|
2023-04-01 13:45:49 +00:00
|
|
|
const createVendingMinter = (
|
|
|
|
msg: Record<string, unknown>,
|
|
|
|
funds: Coin[],
|
|
|
|
updatable?: boolean,
|
2023-04-27 17:16:40 +00:00
|
|
|
flex?: boolean,
|
2023-04-01 13:45:49 +00:00
|
|
|
): CreateVendingMinterMessage => {
|
2022-10-21 01:02:52 +00:00
|
|
|
return {
|
|
|
|
sender: txSigner,
|
|
|
|
contract: contractAddress,
|
|
|
|
msg,
|
2023-04-01 13:45:49 +00:00
|
|
|
funds,
|
2022-10-21 01:02:52 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return {
|
2022-12-09 08:27:50 +00:00
|
|
|
createVendingMinter,
|
2022-10-21 01:02:52 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return { use, messages }
|
|
|
|
}
|