2022-07-19 07:53:03 +00:00
|
|
|
import type { SigningCosmWasmClient } from '@cosmjs/cosmwasm-stargate'
|
|
|
|
import type { Coin } from '@cosmjs/proto-signing'
|
|
|
|
import { coin } from '@cosmjs/proto-signing'
|
2022-07-14 10:16:50 +00:00
|
|
|
|
|
|
|
export interface InstantiateResponse {
|
|
|
|
readonly contractAddress: string
|
|
|
|
readonly transactionHash: string
|
|
|
|
}
|
|
|
|
|
|
|
|
export interface ConfigResponse {
|
|
|
|
readonly num_members: number
|
2022-12-21 06:24:54 +00:00
|
|
|
readonly per_address_limit: number
|
2022-07-14 10:16:50 +00:00
|
|
|
readonly member_limit: number
|
|
|
|
readonly start_time: string
|
|
|
|
readonly end_time: string
|
2022-10-21 01:02:52 +00:00
|
|
|
readonly mint_price: Coin
|
2022-07-14 10:16:50 +00:00
|
|
|
readonly is_active: boolean
|
|
|
|
}
|
|
|
|
export interface WhiteListInstance {
|
|
|
|
readonly contractAddress: string
|
|
|
|
//Query
|
|
|
|
hasStarted: () => Promise<boolean>
|
|
|
|
hasEnded: () => Promise<boolean>
|
|
|
|
isActive: () => Promise<boolean>
|
2022-07-19 07:53:03 +00:00
|
|
|
members: (startAfter?: string, limit?: number) => Promise<string[]>
|
2022-07-14 10:16:50 +00:00
|
|
|
hasMember: (member: string) => Promise<boolean>
|
2023-03-18 08:34:23 +00:00
|
|
|
adminList: () => Promise<string[]>
|
2022-07-14 10:16:50 +00:00
|
|
|
config: () => Promise<ConfigResponse>
|
|
|
|
|
|
|
|
//Execute
|
|
|
|
updateStartTime: (startTime: string) => Promise<string>
|
|
|
|
updateEndTime: (endTime: string) => Promise<string>
|
2022-07-19 07:53:03 +00:00
|
|
|
addMembers: (memberList: string[]) => Promise<string>
|
|
|
|
removeMembers: (memberList: string[]) => Promise<string>
|
2022-07-14 10:16:50 +00:00
|
|
|
updatePerAddressLimit: (limit: number) => Promise<string>
|
|
|
|
increaseMemberLimit: (limit: number) => Promise<string>
|
2023-03-08 21:24:15 +00:00
|
|
|
updateAdmins: (admins: string[]) => Promise<string>
|
2022-07-14 10:16:50 +00:00
|
|
|
}
|
|
|
|
|
2022-07-19 07:53:03 +00:00
|
|
|
export interface WhitelistMessages {
|
|
|
|
updateStartTime: (startTime: string) => UpdateStartTimeMessage
|
|
|
|
updateEndTime: (endTime: string) => UpdateEndTimeMessage
|
|
|
|
addMembers: (memberList: string[]) => AddMembersMessage
|
|
|
|
removeMembers: (memberList: string[]) => RemoveMembersMessage
|
|
|
|
updatePerAddressLimit: (limit: number) => UpdatePerAddressLimitMessage
|
|
|
|
increaseMemberLimit: (limit: number) => IncreaseMemberLimitMessage
|
2023-03-08 21:24:15 +00:00
|
|
|
updateAdmins: (admins: string[]) => UpdateAdminsMessage
|
2022-07-19 07:53:03 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
export interface UpdateStartTimeMessage {
|
|
|
|
sender: string
|
|
|
|
contract: string
|
|
|
|
msg: {
|
|
|
|
update_start_time: string
|
|
|
|
}
|
|
|
|
funds: Coin[]
|
|
|
|
}
|
|
|
|
|
|
|
|
export interface UpdateEndTimeMessage {
|
|
|
|
sender: string
|
|
|
|
contract: string
|
|
|
|
msg: {
|
|
|
|
update_end_time: string
|
|
|
|
}
|
|
|
|
funds: Coin[]
|
|
|
|
}
|
|
|
|
|
2023-03-08 21:24:15 +00:00
|
|
|
export interface UpdateAdminsMessage {
|
|
|
|
sender: string
|
|
|
|
contract: string
|
|
|
|
msg: {
|
|
|
|
update_admins: { admins: string[] }
|
|
|
|
}
|
|
|
|
funds: Coin[]
|
|
|
|
}
|
2022-07-19 07:53:03 +00:00
|
|
|
export interface AddMembersMessage {
|
|
|
|
sender: string
|
|
|
|
contract: string
|
|
|
|
msg: {
|
|
|
|
add_members: { to_add: string[] }
|
|
|
|
}
|
|
|
|
funds: Coin[]
|
|
|
|
}
|
|
|
|
|
|
|
|
export interface RemoveMembersMessage {
|
|
|
|
sender: string
|
|
|
|
contract: string
|
|
|
|
msg: {
|
|
|
|
remove_members: { to_remove: string[] }
|
|
|
|
}
|
|
|
|
funds: Coin[]
|
|
|
|
}
|
|
|
|
|
|
|
|
export interface UpdatePerAddressLimitMessage {
|
|
|
|
sender: string
|
|
|
|
|
|
|
|
contract: string
|
|
|
|
msg: {
|
|
|
|
update_per_address_limit: number
|
|
|
|
}
|
|
|
|
funds: Coin[]
|
|
|
|
}
|
|
|
|
|
|
|
|
export interface IncreaseMemberLimitMessage {
|
|
|
|
sender: string
|
|
|
|
contract: string
|
|
|
|
msg: {
|
|
|
|
increase_member_limit: number
|
|
|
|
}
|
|
|
|
funds: Coin[]
|
|
|
|
}
|
|
|
|
|
2022-07-14 10:16:50 +00:00
|
|
|
export interface WhiteListContract {
|
|
|
|
instantiate: (
|
|
|
|
codeId: number,
|
|
|
|
initMsg: Record<string, unknown>,
|
|
|
|
label: string,
|
|
|
|
admin?: string,
|
|
|
|
) => Promise<InstantiateResponse>
|
|
|
|
|
|
|
|
use: (contractAddress: string) => WhiteListInstance
|
2022-07-19 07:53:03 +00:00
|
|
|
|
|
|
|
messages: (contractAddress: string) => WhitelistMessages
|
2022-07-14 10:16:50 +00:00
|
|
|
}
|
|
|
|
|
2022-07-19 07:53:03 +00:00
|
|
|
export const WhiteList = (client: SigningCosmWasmClient, txSigner: string): WhiteListContract => {
|
2022-07-14 10:16:50 +00:00
|
|
|
const use = (contractAddress: string): WhiteListInstance => {
|
|
|
|
///QUERY START
|
|
|
|
const hasStarted = async (): Promise<boolean> => {
|
|
|
|
return client.queryContractSmart(contractAddress, { has_started: {} })
|
|
|
|
}
|
|
|
|
|
|
|
|
const hasEnded = async (): Promise<boolean> => {
|
|
|
|
return client.queryContractSmart(contractAddress, { has_ended: {} })
|
|
|
|
}
|
|
|
|
|
|
|
|
const isActive = async (): Promise<boolean> => {
|
|
|
|
return client.queryContractSmart(contractAddress, { is_active: {} })
|
|
|
|
}
|
|
|
|
|
2022-07-19 07:53:03 +00:00
|
|
|
const members = async (startAfter?: string, limit?: number): Promise<string[]> => {
|
2022-07-14 10:16:50 +00:00
|
|
|
return client.queryContractSmart(contractAddress, {
|
|
|
|
members: { limit, start_after: startAfter },
|
|
|
|
})
|
|
|
|
}
|
|
|
|
|
|
|
|
const hasMember = async (member: string): Promise<boolean> => {
|
|
|
|
return client.queryContractSmart(contractAddress, {
|
|
|
|
has_member: { member },
|
|
|
|
})
|
|
|
|
}
|
|
|
|
|
2023-03-18 08:34:23 +00:00
|
|
|
const adminList = async (): Promise<string[]> => {
|
|
|
|
return client.queryContractSmart(contractAddress, {
|
|
|
|
admin_list: {},
|
|
|
|
})
|
|
|
|
}
|
|
|
|
|
2022-07-14 10:16:50 +00:00
|
|
|
const config = async (): Promise<ConfigResponse> => {
|
|
|
|
return client.queryContractSmart(contractAddress, {
|
|
|
|
config: {},
|
|
|
|
})
|
|
|
|
}
|
|
|
|
/// QUERY END
|
|
|
|
/// EXECUTE START
|
|
|
|
const updateStartTime = async (startTime: string): Promise<string> => {
|
2022-07-19 07:53:03 +00:00
|
|
|
const res = await client.execute(txSigner, contractAddress, { update_start_time: startTime }, 'auto')
|
2022-07-14 10:16:50 +00:00
|
|
|
return res.transactionHash
|
|
|
|
}
|
|
|
|
|
|
|
|
const updateEndTime = async (endTime: string): Promise<string> => {
|
2022-07-19 07:53:03 +00:00
|
|
|
const res = await client.execute(txSigner, contractAddress, { update_end_time: endTime }, 'auto')
|
2022-07-14 10:16:50 +00:00
|
|
|
return res.transactionHash
|
|
|
|
}
|
|
|
|
|
2022-07-19 07:53:03 +00:00
|
|
|
const addMembers = async (memberList: string[]): Promise<string> => {
|
2022-07-14 10:16:50 +00:00
|
|
|
const res = await client.execute(
|
2022-07-19 07:53:03 +00:00
|
|
|
txSigner,
|
2022-07-14 10:16:50 +00:00
|
|
|
contractAddress,
|
2022-07-19 07:53:03 +00:00
|
|
|
{
|
|
|
|
add_members: {
|
|
|
|
to_add: memberList,
|
|
|
|
},
|
|
|
|
},
|
|
|
|
'auto',
|
2022-07-14 10:16:50 +00:00
|
|
|
)
|
|
|
|
return res.transactionHash
|
|
|
|
}
|
|
|
|
|
2023-03-08 21:24:15 +00:00
|
|
|
const updateAdmins = async (admins: string[]): Promise<string> => {
|
|
|
|
const res = await client.execute(
|
|
|
|
txSigner,
|
|
|
|
contractAddress,
|
|
|
|
{
|
|
|
|
update_admins: {
|
|
|
|
admins,
|
|
|
|
},
|
|
|
|
},
|
|
|
|
'auto',
|
|
|
|
)
|
|
|
|
return res.transactionHash
|
|
|
|
}
|
|
|
|
|
2022-07-19 07:53:03 +00:00
|
|
|
const removeMembers = async (memberList: string[]): Promise<string> => {
|
2022-07-14 10:16:50 +00:00
|
|
|
const res = await client.execute(
|
2022-07-19 07:53:03 +00:00
|
|
|
txSigner,
|
2022-07-14 10:16:50 +00:00
|
|
|
contractAddress,
|
2022-07-19 07:53:03 +00:00
|
|
|
{
|
|
|
|
remove_members: {
|
|
|
|
to_remove: memberList,
|
|
|
|
},
|
|
|
|
},
|
|
|
|
'auto',
|
2022-07-14 10:16:50 +00:00
|
|
|
)
|
|
|
|
return res.transactionHash
|
|
|
|
}
|
|
|
|
|
|
|
|
const updatePerAddressLimit = async (limit: number): Promise<string> => {
|
2022-07-19 07:53:03 +00:00
|
|
|
const res = await client.execute(txSigner, contractAddress, { update_per_address_limit: limit }, 'auto')
|
2022-07-14 10:16:50 +00:00
|
|
|
return res.transactionHash
|
|
|
|
}
|
|
|
|
|
|
|
|
const increaseMemberLimit = async (limit: number): Promise<string> => {
|
2022-07-19 07:53:03 +00:00
|
|
|
const res = await client.execute(txSigner, contractAddress, { increase_member_limit: limit }, 'auto')
|
2022-07-14 10:16:50 +00:00
|
|
|
return res.transactionHash
|
|
|
|
}
|
|
|
|
/// EXECUTE END
|
|
|
|
|
|
|
|
return {
|
|
|
|
contractAddress,
|
|
|
|
updateStartTime,
|
|
|
|
updateEndTime,
|
2023-03-08 21:24:15 +00:00
|
|
|
updateAdmins,
|
2022-07-14 10:16:50 +00:00
|
|
|
addMembers,
|
|
|
|
removeMembers,
|
|
|
|
updatePerAddressLimit,
|
|
|
|
increaseMemberLimit,
|
|
|
|
hasStarted,
|
|
|
|
hasEnded,
|
|
|
|
isActive,
|
|
|
|
members,
|
|
|
|
hasMember,
|
2023-03-18 08:34:23 +00:00
|
|
|
adminList,
|
2022-07-14 10:16:50 +00:00
|
|
|
config,
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
const instantiate = async (
|
|
|
|
codeId: number,
|
|
|
|
initMsg: Record<string, unknown>,
|
|
|
|
label: string,
|
|
|
|
admin?: string,
|
|
|
|
): Promise<InstantiateResponse> => {
|
2022-07-19 07:53:03 +00:00
|
|
|
const result = await client.instantiate(txSigner, codeId, initMsg, label, 'auto', {
|
2022-10-21 01:02:52 +00:00
|
|
|
funds: [coin((Math.ceil(Number(initMsg.member_limit) / 1000) * 100000000).toString(), 'ustars')],
|
2022-07-19 07:53:03 +00:00
|
|
|
admin,
|
|
|
|
})
|
2022-07-14 10:16:50 +00:00
|
|
|
|
|
|
|
return {
|
|
|
|
contractAddress: result.contractAddress,
|
|
|
|
transactionHash: result.transactionHash,
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-07-19 07:53:03 +00:00
|
|
|
const messages = (contractAddress: string) => {
|
|
|
|
const updateStartTime = (startTime: string) => {
|
|
|
|
return {
|
|
|
|
sender: txSigner,
|
|
|
|
contract: contractAddress,
|
|
|
|
msg: {
|
|
|
|
update_start_time: startTime,
|
|
|
|
},
|
|
|
|
funds: [],
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
const updateEndTime = (endTime: string) => {
|
|
|
|
return {
|
|
|
|
sender: txSigner,
|
|
|
|
contract: contractAddress,
|
|
|
|
msg: {
|
|
|
|
update_end_time: endTime,
|
|
|
|
},
|
|
|
|
funds: [],
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
const addMembers = (memberList: string[]) => {
|
|
|
|
return {
|
|
|
|
sender: txSigner,
|
|
|
|
contract: contractAddress,
|
|
|
|
msg: {
|
|
|
|
add_members: { to_add: memberList },
|
|
|
|
},
|
|
|
|
funds: [],
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2023-03-08 21:24:15 +00:00
|
|
|
const updateAdmins = (admins: string[]) => {
|
|
|
|
return {
|
|
|
|
sender: txSigner,
|
|
|
|
contract: contractAddress,
|
|
|
|
msg: {
|
|
|
|
update_admins: { admins },
|
|
|
|
},
|
|
|
|
funds: [],
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-07-19 07:53:03 +00:00
|
|
|
const removeMembers = (memberList: string[]) => {
|
|
|
|
return {
|
|
|
|
sender: txSigner,
|
|
|
|
contract: contractAddress,
|
|
|
|
msg: {
|
|
|
|
remove_members: { to_remove: memberList },
|
|
|
|
},
|
|
|
|
funds: [],
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
const updatePerAddressLimit = (limit: number) => {
|
|
|
|
return {
|
|
|
|
sender: txSigner,
|
|
|
|
contract: contractAddress,
|
|
|
|
msg: {
|
|
|
|
update_per_address_limit: limit,
|
|
|
|
},
|
|
|
|
funds: [],
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
const increaseMemberLimit = (limit: number) => {
|
|
|
|
return {
|
|
|
|
sender: txSigner,
|
|
|
|
contract: contractAddress,
|
|
|
|
msg: {
|
|
|
|
increase_member_limit: limit,
|
|
|
|
},
|
|
|
|
funds: [],
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return {
|
|
|
|
updateStartTime,
|
|
|
|
updateEndTime,
|
2023-03-08 21:24:15 +00:00
|
|
|
updateAdmins,
|
2022-07-19 07:53:03 +00:00
|
|
|
addMembers,
|
|
|
|
removeMembers,
|
|
|
|
updatePerAddressLimit,
|
|
|
|
increaseMemberLimit,
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return { use, instantiate, messages }
|
2022-07-14 10:16:50 +00:00
|
|
|
}
|