diff --git a/packages/cosmwasm-stargate/src/cosmwasmclient.spec.ts b/packages/cosmwasm-stargate/src/cosmwasmclient.spec.ts index 7b0502e8..3092ded5 100644 --- a/packages/cosmwasm-stargate/src/cosmwasmclient.spec.ts +++ b/packages/cosmwasm-stargate/src/cosmwasmclient.spec.ts @@ -20,6 +20,8 @@ import { CosmWasmClient, PrivateCosmWasmClient } from "./cosmwasmclient"; import { SigningCosmWasmClient } from "./signingcosmwasmclient"; import { alice, + defaultInstantiateFee, + defaultUploadFee, deployedHackatom, getHackatom, makeRandomAddress, @@ -31,7 +33,7 @@ import { } from "./testutils.spec"; interface HackatomInstance { - readonly initMsg: { + readonly instantiateMsg: { readonly verifier: string; readonly beneficiary: string; }; @@ -318,15 +320,17 @@ describe("CosmWasmClient", () => { if (wasmdEnabled()) { const wallet = await DirectSecp256k1HdWallet.fromMnemonic(alice.mnemonic, { prefix: wasmd.prefix }); const client = await SigningCosmWasmClient.connectWithSigner(wasmd.endpoint, wallet); - const { codeId } = await client.upload(alice.address0, getHackatom().data); - const initMsg = { verifier: makeRandomAddress(), beneficiary: makeRandomAddress() }; + const { codeId } = await client.upload(alice.address0, getHackatom().data, defaultUploadFee); + const instantiateMsg = { verifier: makeRandomAddress(), beneficiary: makeRandomAddress() }; + const label = "random hackatom"; const { contractAddress } = await client.instantiate( alice.address0, codeId, - initMsg, - "random hackatom", + instantiateMsg, + label, + defaultInstantiateFee, ); - contract = { initMsg: initMsg, address: contractAddress }; + contract = { instantiateMsg: instantiateMsg, address: contractAddress }; } }); @@ -338,8 +342,8 @@ describe("CosmWasmClient", () => { const raw = await client.queryContractRaw(contract.address, configKey); assert(raw, "must get result"); expect(JSON.parse(fromAscii(raw))).toEqual({ - verifier: contract.initMsg.verifier, - beneficiary: contract.initMsg.beneficiary, + verifier: contract.instantiateMsg.verifier, + beneficiary: contract.instantiateMsg.beneficiary, funder: alice.address0, }); }); @@ -372,15 +376,17 @@ describe("CosmWasmClient", () => { if (wasmdEnabled()) { const wallet = await DirectSecp256k1HdWallet.fromMnemonic(alice.mnemonic, { prefix: wasmd.prefix }); const client = await SigningCosmWasmClient.connectWithSigner(wasmd.endpoint, wallet); - const { codeId } = await client.upload(alice.address0, getHackatom().data); - const initMsg = { verifier: makeRandomAddress(), beneficiary: makeRandomAddress() }; + const { codeId } = await client.upload(alice.address0, getHackatom().data, defaultUploadFee); + const instantiateMsg = { verifier: makeRandomAddress(), beneficiary: makeRandomAddress() }; + const label = "a different hackatom"; const { contractAddress } = await client.instantiate( alice.address0, codeId, - initMsg, - "a different hackatom", + instantiateMsg, + label, + defaultInstantiateFee, ); - contract = { initMsg: initMsg, address: contractAddress }; + contract = { instantiateMsg: instantiateMsg, address: contractAddress }; } }); @@ -390,7 +396,7 @@ describe("CosmWasmClient", () => { const client = await CosmWasmClient.connect(wasmd.endpoint); const result = await client.queryContractSmart(contract.address, { verifier: {} }); - expect(result).toEqual({ verifier: contract.initMsg.verifier }); + expect(result).toEqual({ verifier: contract.instantiateMsg.verifier }); }); it("errors for malformed query message", async () => { diff --git a/packages/cosmwasm-stargate/src/index.ts b/packages/cosmwasm-stargate/src/index.ts index c48f6a81..e90bbc57 100644 --- a/packages/cosmwasm-stargate/src/index.ts +++ b/packages/cosmwasm-stargate/src/index.ts @@ -22,9 +22,7 @@ export { MsgUpdateAdminEncodeObject, } from "./encodeobjects"; export { - defaultGasLimits, ChangeAdminResult, - CosmWasmFeeTable, // part of SigningCosmWasmClientOptions ExecuteResult, InstantiateOptions, InstantiateResult, diff --git a/packages/cosmwasm-stargate/src/signingcosmwasmclient.spec.ts b/packages/cosmwasm-stargate/src/signingcosmwasmclient.spec.ts index 65f264a0..f592b0a3 100644 --- a/packages/cosmwasm-stargate/src/signingcosmwasmclient.spec.ts +++ b/packages/cosmwasm-stargate/src/signingcosmwasmclient.spec.ts @@ -9,7 +9,6 @@ import { assertIsBroadcastTxSuccess, coin, coins, - GasPrice, MsgDelegateEncodeObject, MsgSendEncodeObject, } from "@cosmjs/stargate"; @@ -27,6 +26,13 @@ import { MsgStoreCodeEncodeObject } from "./encodeobjects"; import { SigningCosmWasmClient, UploadMeta } from "./signingcosmwasmclient"; import { alice, + defaultClearAdminFee, + defaultExecuteFee, + defaultInstantiateFee, + defaultMigrateFee, + defaultSendFee, + defaultUpdateAdminFee, + defaultUploadFee, getHackatom, makeRandomAddress, makeWasmClient, @@ -57,167 +63,6 @@ describe("SigningCosmWasmClient", () => { const client = await SigningCosmWasmClient.connectWithSigner(wasmd.endpoint, wallet, options); expect(client.registry.lookupType("/custom.MsgCustom")).toEqual(MsgSend); }); - - it("can be constructed with custom gas price", async () => { - pendingWithoutWasmd(); - const wallet = await DirectSecp256k1HdWallet.fromMnemonic(alice.mnemonic, { prefix: wasmd.prefix }); - const options = { - prefix: wasmd.prefix, - gasPrice: GasPrice.fromString("3.14utest"), - }; - const client = await SigningCosmWasmClient.connectWithSigner(wasmd.endpoint, wallet, options); - expect(client.fees).toEqual({ - upload: { - amount: coins(4710000, "utest"), - gas: "1500000", - }, - init: { - amount: coins(1570000, "utest"), - gas: "500000", - }, - migrate: { - amount: coins(628000, "utest"), - gas: "200000", - }, - exec: { - amount: coins(628000, "utest"), - gas: "200000", - }, - send: { - amount: coins(251200, "utest"), - gas: "80000", - }, - changeAdmin: { - amount: coins(251200, "utest"), - gas: "80000", - }, - delegate: { - amount: coins(502400, "utest"), - gas: "160000", - }, - transfer: { - amount: coins(502400, "utest"), - gas: "160000", - }, - undelegate: { - amount: coins(502400, "utest"), - gas: "160000", - }, - withdraw: { - amount: coins(502400, "utest"), - gas: "160000", - }, - }); - }); - - it("can be constructed with custom gas limits", async () => { - pendingWithoutWasmd(); - const wallet = await DirectSecp256k1HdWallet.fromMnemonic(alice.mnemonic, { prefix: wasmd.prefix }); - const options = { - prefix: wasmd.prefix, - gasLimits: { - send: 160000, - }, - }; - const client = await SigningCosmWasmClient.connectWithSigner(wasmd.endpoint, wallet, options); - expect(client.fees).toEqual({ - upload: { - amount: coins(37500, "ucosm"), - gas: "1500000", - }, - init: { - amount: coins(12500, "ucosm"), - gas: "500000", - }, - migrate: { - amount: coins(5000, "ucosm"), - gas: "200000", - }, - exec: { - amount: coins(5000, "ucosm"), - gas: "200000", - }, - send: { - amount: coins(4000, "ucosm"), - gas: "160000", - }, - changeAdmin: { - amount: coins(2000, "ucosm"), - gas: "80000", - }, - delegate: { - amount: coins(4000, "ucosm"), - gas: "160000", - }, - transfer: { - amount: coins(4000, "ucosm"), - gas: "160000", - }, - undelegate: { - amount: coins(4000, "ucosm"), - gas: "160000", - }, - withdraw: { - amount: coins(4000, "ucosm"), - gas: "160000", - }, - }); - }); - - it("can be constructed with custom gas price and gas limits", async () => { - pendingWithoutWasmd(); - const wallet = await DirectSecp256k1HdWallet.fromMnemonic(alice.mnemonic, { prefix: wasmd.prefix }); - const options = { - prefix: wasmd.prefix, - gasPrice: GasPrice.fromString("3.14utest"), - gasLimits: { - send: 160000, - }, - }; - const client = await SigningCosmWasmClient.connectWithSigner(wasmd.endpoint, wallet, options); - expect(client.fees).toEqual({ - upload: { - amount: coins(4710000, "utest"), - gas: "1500000", - }, - init: { - amount: coins(1570000, "utest"), - gas: "500000", - }, - migrate: { - amount: coins(628000, "utest"), - gas: "200000", - }, - exec: { - amount: coins(628000, "utest"), - gas: "200000", - }, - send: { - amount: coins(502400, "utest"), - gas: "160000", - }, - changeAdmin: { - amount: coins(251200, "utest"), - gas: "80000", - }, - delegate: { - amount: coins(502400, "utest"), - gas: "160000", - }, - transfer: { - amount: coins(502400, "utest"), - gas: "160000", - }, - undelegate: { - amount: coins(502400, "utest"), - gas: "160000", - }, - withdraw: { - amount: coins(502400, "utest"), - gas: "160000", - }, - }); - }); }); describe("upload", () => { @@ -228,7 +73,7 @@ describe("SigningCosmWasmClient", () => { const client = await SigningCosmWasmClient.connectWithSigner(wasmd.endpoint, wallet, options); const wasm = getHackatom().data; const { codeId, originalChecksum, originalSize, compressedChecksum, compressedSize } = - await client.upload(alice.address0, wasm); + await client.upload(alice.address0, wasm, defaultUploadFee); expect(originalChecksum).toEqual(toHex(sha256(wasm))); expect(originalSize).toEqual(wasm.length); expect(compressedChecksum).toMatch(/^[0-9a-f]{64}$/); @@ -246,7 +91,7 @@ describe("SigningCosmWasmClient", () => { source: "https://crates.io/api/v1/crates/cw-nameservice/0.1.0/download", builder: "confio/cosmwasm-opt:0.6.2", }; - const { codeId } = await client.upload(alice.address0, hackatom.data, meta); + const { codeId } = await client.upload(alice.address0, hackatom.data, defaultUploadFee, meta); const codeDetails = await client.getCodeDetails(codeId); expect(codeDetails.source).toEqual(meta.source); expect(codeDetails.builder).toEqual(meta.builder); @@ -259,7 +104,7 @@ describe("SigningCosmWasmClient", () => { const wallet = await DirectSecp256k1HdWallet.fromMnemonic(alice.mnemonic, { prefix: wasmd.prefix }); const options = { prefix: wasmd.prefix }; const client = await SigningCosmWasmClient.connectWithSigner(wasmd.endpoint, wallet, options); - const { codeId } = await client.upload(alice.address0, getHackatom().data); + const { codeId } = await client.upload(alice.address0, getHackatom().data, defaultUploadFee); const funds = [coin(1234, "ucosm"), coin(321, "ustake")]; const beneficiaryAddress = makeRandomAddress(); const { contractAddress } = await client.instantiate( @@ -270,6 +115,7 @@ describe("SigningCosmWasmClient", () => { beneficiary: beneficiaryAddress, }, "My cool label", + defaultInstantiateFee, { memo: "Let's see if the memo is used", funds: funds, @@ -287,7 +133,7 @@ describe("SigningCosmWasmClient", () => { const wallet = await DirectSecp256k1HdWallet.fromMnemonic(alice.mnemonic, { prefix: wasmd.prefix }); const options = { prefix: wasmd.prefix }; const client = await SigningCosmWasmClient.connectWithSigner(wasmd.endpoint, wallet, options); - const { codeId } = await client.upload(alice.address0, getHackatom().data); + const { codeId } = await client.upload(alice.address0, getHackatom().data, defaultUploadFee); const beneficiaryAddress = makeRandomAddress(); const { contractAddress } = await client.instantiate( alice.address0, @@ -297,6 +143,7 @@ describe("SigningCosmWasmClient", () => { beneficiary: beneficiaryAddress, }, "My cool label", + defaultInstantiateFee, { admin: unused.address }, ); const wasmClient = await makeWasmClient(wasmd.endpoint); @@ -310,7 +157,7 @@ describe("SigningCosmWasmClient", () => { const wallet = await DirectSecp256k1HdWallet.fromMnemonic(alice.mnemonic, { prefix: wasmd.prefix }); const options = { prefix: wasmd.prefix }; const client = await SigningCosmWasmClient.connectWithSigner(wasmd.endpoint, wallet, options); - const { codeId } = await client.upload(alice.address0, getHackatom().data); + const { codeId } = await client.upload(alice.address0, getHackatom().data, defaultUploadFee); const contractAddress1 = await client.instantiate( alice.address0, codeId, @@ -319,6 +166,7 @@ describe("SigningCosmWasmClient", () => { beneficiary: makeRandomAddress(), }, "contract 1", + defaultInstantiateFee, ); const contractAddress2 = await client.instantiate( alice.address0, @@ -328,6 +176,7 @@ describe("SigningCosmWasmClient", () => { beneficiary: makeRandomAddress(), }, "contract 2", + defaultInstantiateFee, ); expect(contractAddress1).not.toEqual(contractAddress2); }); @@ -339,7 +188,7 @@ describe("SigningCosmWasmClient", () => { const wallet = await DirectSecp256k1HdWallet.fromMnemonic(alice.mnemonic, { prefix: wasmd.prefix }); const options = { prefix: wasmd.prefix }; const client = await SigningCosmWasmClient.connectWithSigner(wasmd.endpoint, wallet, options); - const { codeId } = await client.upload(alice.address0, getHackatom().data); + const { codeId } = await client.upload(alice.address0, getHackatom().data, defaultUploadFee); const beneficiaryAddress = makeRandomAddress(); const { contractAddress } = await client.instantiate( alice.address0, @@ -349,6 +198,8 @@ describe("SigningCosmWasmClient", () => { beneficiary: beneficiaryAddress, }, "My cool label", + defaultInstantiateFee, + { admin: alice.address0, }, @@ -358,7 +209,7 @@ describe("SigningCosmWasmClient", () => { assert(contractInfo1); expect(contractInfo1.admin).toEqual(alice.address0); - await client.updateAdmin(alice.address0, contractAddress, unused.address); + await client.updateAdmin(alice.address0, contractAddress, unused.address, defaultUpdateAdminFee); const { contractInfo: contractInfo2 } = await wasmClient.wasm.getContractInfo(contractAddress); assert(contractInfo2); expect(contractInfo2.admin).toEqual(unused.address); @@ -371,7 +222,7 @@ describe("SigningCosmWasmClient", () => { const wallet = await DirectSecp256k1HdWallet.fromMnemonic(alice.mnemonic, { prefix: wasmd.prefix }); const options = { prefix: wasmd.prefix }; const client = await SigningCosmWasmClient.connectWithSigner(wasmd.endpoint, wallet, options); - const { codeId } = await client.upload(alice.address0, getHackatom().data); + const { codeId } = await client.upload(alice.address0, getHackatom().data, defaultUploadFee); const beneficiaryAddress = makeRandomAddress(); const { contractAddress } = await client.instantiate( alice.address0, @@ -381,6 +232,7 @@ describe("SigningCosmWasmClient", () => { beneficiary: beneficiaryAddress, }, "My cool label", + defaultInstantiateFee, { admin: alice.address0, }, @@ -390,7 +242,7 @@ describe("SigningCosmWasmClient", () => { assert(contractInfo1); expect(contractInfo1.admin).toEqual(alice.address0); - await client.clearAdmin(alice.address0, contractAddress); + await client.clearAdmin(alice.address0, contractAddress, defaultClearAdminFee); const { contractInfo: contractInfo2 } = await wasmClient.wasm.getContractInfo(contractAddress); assert(contractInfo2); expect(contractInfo2.admin).toEqual(""); @@ -403,8 +255,8 @@ describe("SigningCosmWasmClient", () => { const wallet = await DirectSecp256k1HdWallet.fromMnemonic(alice.mnemonic, { prefix: wasmd.prefix }); const options = { prefix: wasmd.prefix }; const client = await SigningCosmWasmClient.connectWithSigner(wasmd.endpoint, wallet, options); - const { codeId: codeId1 } = await client.upload(alice.address0, getHackatom().data); - const { codeId: codeId2 } = await client.upload(alice.address0, getHackatom().data); + const { codeId: codeId1 } = await client.upload(alice.address0, getHackatom().data, defaultUploadFee); + const { codeId: codeId2 } = await client.upload(alice.address0, getHackatom().data, defaultUploadFee); const beneficiaryAddress = makeRandomAddress(); const { contractAddress } = await client.instantiate( alice.address0, @@ -414,6 +266,7 @@ describe("SigningCosmWasmClient", () => { beneficiary: beneficiaryAddress, }, "My cool label", + defaultInstantiateFee, { admin: alice.address0, }, @@ -424,7 +277,13 @@ describe("SigningCosmWasmClient", () => { expect(contractInfo1.admin).toEqual(alice.address0); const newVerifier = makeRandomAddress(); - await client.migrate(alice.address0, contractAddress, codeId2, { verifier: newVerifier }); + await client.migrate( + alice.address0, + contractAddress, + codeId2, + { verifier: newVerifier }, + defaultMigrateFee, + ); const { contractInfo: contractInfo2 } = await wasmClient.wasm.getContractInfo(contractAddress); assert(contractInfo2); expect({ ...contractInfo2 }).toEqual({ @@ -440,7 +299,7 @@ describe("SigningCosmWasmClient", () => { const wallet = await DirectSecp256k1HdWallet.fromMnemonic(alice.mnemonic, { prefix: wasmd.prefix }); const options = { prefix: wasmd.prefix }; const client = await SigningCosmWasmClient.connectWithSigner(wasmd.endpoint, wallet, options); - const { codeId } = await client.upload(alice.address0, getHackatom().data); + const { codeId } = await client.upload(alice.address0, getHackatom().data, defaultUploadFee); // instantiate const funds = [coin(233444, "ucosm"), coin(5454, "ustake")]; const beneficiaryAddress = makeRandomAddress(); @@ -452,12 +311,18 @@ describe("SigningCosmWasmClient", () => { beneficiary: beneficiaryAddress, }, "amazing random contract", + defaultInstantiateFee, { funds: funds, }, ); // execute - const result = await client.execute(alice.address0, contractAddress, { release: {} }, undefined); + const result = await client.execute( + alice.address0, + contractAddress, + { release: {} }, + defaultExecuteFee, + ); const wasmEvent = result.logs[0].events.find((e) => e.type === "wasm"); assert(wasmEvent, "Event of type wasm expected"); expect(wasmEvent.attributes).toContain({ key: "action", value: "release" }); @@ -497,7 +362,13 @@ describe("SigningCosmWasmClient", () => { }); // send - const result = await client.sendTokens(alice.address0, beneficiaryAddress, amount, memo); + const result = await client.sendTokens( + alice.address0, + beneficiaryAddress, + amount, + defaultSendFee, + memo, + ); assertIsBroadcastTxSuccess(result); expect(result.rawLog).toBeTruthy(); @@ -525,7 +396,13 @@ describe("SigningCosmWasmClient", () => { }); // send - const result = await client.sendTokens(alice.address0, beneficiaryAddress, amount, memo); + const result = await client.sendTokens( + alice.address0, + beneficiaryAddress, + amount, + defaultSendFee, + memo, + ); assertIsBroadcastTxSuccess(result); expect(result.rawLog).toBeTruthy(); diff --git a/packages/cosmwasm-stargate/src/signingcosmwasmclient.ts b/packages/cosmwasm-stargate/src/signingcosmwasmclient.ts index 95c72e09..c95632b3 100644 --- a/packages/cosmwasm-stargate/src/signingcosmwasmclient.ts +++ b/packages/cosmwasm-stargate/src/signingcosmwasmclient.ts @@ -18,14 +18,8 @@ import { AminoTypes, BroadcastTxFailure, BroadcastTxResponse, - buildFeeTable, Coin, - CosmosFeeTable, - defaultGasLimits as defaultStargateGasLimits, - defaultGasPrice, defaultRegistryTypes, - GasLimits, - GasPrice, isBroadcastTxFailure, logs, MsgDelegateEncodeObject, @@ -63,18 +57,6 @@ import { MsgUpdateAdminEncodeObject, } from "./encodeobjects"; -/** - * These fees are used by the higher level methods of SigningCosmWasmClient - */ -export interface CosmWasmFeeTable extends CosmosFeeTable { - readonly upload: StdFee; - readonly init: StdFee; - readonly exec: StdFee; - readonly migrate: StdFee; - /** Paid when setting the contract admin to a new address or unsetting it */ - readonly changeAdmin: StdFee; -} - function prepareBuilder(builder: string | undefined): string { if (builder === undefined) { return ""; // normalization needed by backend @@ -84,15 +66,6 @@ function prepareBuilder(builder: string | undefined): string { } } -export const defaultGasLimits: GasLimits = { - ...defaultStargateGasLimits, - upload: 1_500_000, - init: 500_000, - migrate: 200_000, - exec: 200_000, - changeAdmin: 80_000, -}; - export interface UploadMeta { /** * An URL to a .tar.gz archive of the source code of the contract, which can be used to reproducibly build the Wasm bytecode. @@ -195,14 +168,11 @@ export interface SigningCosmWasmClientOptions { readonly registry?: Registry; readonly aminoTypes?: AminoTypes; readonly prefix?: string; - readonly gasPrice?: GasPrice; - readonly gasLimits?: Partial>; readonly broadcastTimeoutMs?: number; readonly broadcastPollIntervalMs?: number; } export class SigningCosmWasmClient extends CosmWasmClient { - public readonly fees: CosmWasmFeeTable; public readonly registry: Registry; public readonly broadcastTimeoutMs: number | undefined; public readonly broadcastPollIntervalMs: number | undefined; @@ -244,10 +214,7 @@ export class SigningCosmWasmClient extends CosmWasmClient { const { registry = createDefaultRegistry(), aminoTypes = new AminoTypes({ additions: cosmWasmTypes, prefix: options.prefix }), - gasPrice = defaultGasPrice, - gasLimits = {}, } = options; - this.fees = buildFeeTable(gasPrice, defaultGasLimits, gasLimits); this.registry = registry; this.aminoTypes = aminoTypes; this.signer = signer; @@ -259,6 +226,7 @@ export class SigningCosmWasmClient extends CosmWasmClient { public async upload( senderAddress: string, wasmCode: Uint8Array, + fee: StdFee, meta: UploadMeta = {}, memo = "", ): Promise { @@ -275,7 +243,7 @@ export class SigningCosmWasmClient extends CosmWasmClient { }), }; - const result = await this.signAndBroadcast(senderAddress, [storeCodeMsg], this.fees.upload, memo); + const result = await this.signAndBroadcast(senderAddress, [storeCodeMsg], fee, memo); if (isBroadcastTxFailure(result)) { throw new Error(createBroadcastTxErrorMessage(result)); } @@ -297,6 +265,7 @@ export class SigningCosmWasmClient extends CosmWasmClient { codeId: number, msg: Record, label: string, + fee: StdFee, options: InstantiateOptions = {}, ): Promise { const instantiateContractMsg: MsgInstantiateContractEncodeObject = { @@ -310,12 +279,7 @@ export class SigningCosmWasmClient extends CosmWasmClient { admin: options.admin, }), }; - const result = await this.signAndBroadcast( - senderAddress, - [instantiateContractMsg], - this.fees.init, - options.memo, - ); + const result = await this.signAndBroadcast(senderAddress, [instantiateContractMsg], fee, options.memo); if (isBroadcastTxFailure(result)) { throw new Error(createBroadcastTxErrorMessage(result)); } @@ -332,6 +296,7 @@ export class SigningCosmWasmClient extends CosmWasmClient { senderAddress: string, contractAddress: string, newAdmin: string, + fee: StdFee, memo = "", ): Promise { const updateAdminMsg: MsgUpdateAdminEncodeObject = { @@ -342,7 +307,7 @@ export class SigningCosmWasmClient extends CosmWasmClient { newAdmin: newAdmin, }), }; - const result = await this.signAndBroadcast(senderAddress, [updateAdminMsg], this.fees.changeAdmin, memo); + const result = await this.signAndBroadcast(senderAddress, [updateAdminMsg], fee, memo); if (isBroadcastTxFailure(result)) { throw new Error(createBroadcastTxErrorMessage(result)); } @@ -355,6 +320,7 @@ export class SigningCosmWasmClient extends CosmWasmClient { public async clearAdmin( senderAddress: string, contractAddress: string, + fee: StdFee, memo = "", ): Promise { const clearAdminMsg: MsgClearAdminEncodeObject = { @@ -364,7 +330,7 @@ export class SigningCosmWasmClient extends CosmWasmClient { contract: contractAddress, }), }; - const result = await this.signAndBroadcast(senderAddress, [clearAdminMsg], this.fees.changeAdmin, memo); + const result = await this.signAndBroadcast(senderAddress, [clearAdminMsg], fee, memo); if (isBroadcastTxFailure(result)) { throw new Error(createBroadcastTxErrorMessage(result)); } @@ -379,6 +345,7 @@ export class SigningCosmWasmClient extends CosmWasmClient { contractAddress: string, codeId: number, migrateMsg: Record, + fee: StdFee, memo = "", ): Promise { const migrateContractMsg: MsgMigrateContractEncodeObject = { @@ -390,7 +357,7 @@ export class SigningCosmWasmClient extends CosmWasmClient { migrateMsg: toUtf8(JSON.stringify(migrateMsg)), }), }; - const result = await this.signAndBroadcast(senderAddress, [migrateContractMsg], this.fees.migrate, memo); + const result = await this.signAndBroadcast(senderAddress, [migrateContractMsg], fee, memo); if (isBroadcastTxFailure(result)) { throw new Error(createBroadcastTxErrorMessage(result)); } @@ -404,6 +371,7 @@ export class SigningCosmWasmClient extends CosmWasmClient { senderAddress: string, contractAddress: string, msg: Record, + fee: StdFee, memo = "", funds?: readonly Coin[], ): Promise { @@ -416,7 +384,7 @@ export class SigningCosmWasmClient extends CosmWasmClient { funds: [...(funds || [])], }), }; - const result = await this.signAndBroadcast(senderAddress, [executeContractMsg], this.fees.exec, memo); + const result = await this.signAndBroadcast(senderAddress, [executeContractMsg], fee, memo); if (isBroadcastTxFailure(result)) { throw new Error(createBroadcastTxErrorMessage(result)); } @@ -430,6 +398,7 @@ export class SigningCosmWasmClient extends CosmWasmClient { senderAddress: string, recipientAddress: string, amount: readonly Coin[], + fee: StdFee, memo = "", ): Promise { const sendMsg: MsgSendEncodeObject = { @@ -440,45 +409,48 @@ export class SigningCosmWasmClient extends CosmWasmClient { amount: [...amount], }, }; - return this.signAndBroadcast(senderAddress, [sendMsg], this.fees.send, memo); + return this.signAndBroadcast(senderAddress, [sendMsg], fee, memo); } public async delegateTokens( delegatorAddress: string, validatorAddress: string, amount: Coin, + fee: StdFee, memo = "", ): Promise { const delegateMsg: MsgDelegateEncodeObject = { typeUrl: "/cosmos.staking.v1beta1.MsgDelegate", value: MsgDelegate.fromPartial({ delegatorAddress: delegatorAddress, validatorAddress, amount }), }; - return this.signAndBroadcast(delegatorAddress, [delegateMsg], this.fees.delegate, memo); + return this.signAndBroadcast(delegatorAddress, [delegateMsg], fee, memo); } public async undelegateTokens( delegatorAddress: string, validatorAddress: string, amount: Coin, + fee: StdFee, memo = "", ): Promise { const undelegateMsg: MsgUndelegateEncodeObject = { typeUrl: "/cosmos.staking.v1beta1.MsgUndelegate", value: MsgUndelegate.fromPartial({ delegatorAddress: delegatorAddress, validatorAddress, amount }), }; - return this.signAndBroadcast(delegatorAddress, [undelegateMsg], this.fees.undelegate, memo); + return this.signAndBroadcast(delegatorAddress, [undelegateMsg], fee, memo); } public async withdrawRewards( delegatorAddress: string, validatorAddress: string, + fee: StdFee, memo = "", ): Promise { const withdrawDelegatorRewardMsg: MsgWithdrawDelegatorRewardEncodeObject = { typeUrl: "/cosmos.distribution.v1beta1.MsgWithdrawDelegatorReward", value: MsgWithdrawDelegatorReward.fromPartial({ delegatorAddress: delegatorAddress, validatorAddress }), }; - return this.signAndBroadcast(delegatorAddress, [withdrawDelegatorRewardMsg], this.fees.withdraw, memo); + return this.signAndBroadcast(delegatorAddress, [withdrawDelegatorRewardMsg], fee, memo); } /** diff --git a/packages/cosmwasm-stargate/src/testutils.spec.ts b/packages/cosmwasm-stargate/src/testutils.spec.ts index 7f80d47d..a8f37eac 100644 --- a/packages/cosmwasm-stargate/src/testutils.spec.ts +++ b/packages/cosmwasm-stargate/src/testutils.spec.ts @@ -11,7 +11,9 @@ import { import { AuthExtension, BankExtension, + calculateFee, coins, + GasPrice, QueryClient, setupAuthExtension, setupBankExtension, @@ -23,6 +25,15 @@ import { AuthInfo, SignDoc, TxBody } from "cosmjs-types/cosmos/tx/v1beta1/tx"; import { setupWasmExtension, WasmExtension } from "./queries"; import hackatom from "./testdata/contract.json"; +export const defaultGasPrice = GasPrice.fromString("0.025ucosm"); +export const defaultSendFee = calculateFee(80_000, defaultGasPrice); +export const defaultUploadFee = calculateFee(1_500_000, defaultGasPrice); +export const defaultInstantiateFee = calculateFee(500_000, defaultGasPrice); +export const defaultExecuteFee = calculateFee(200_000, defaultGasPrice); +export const defaultMigrateFee = calculateFee(200_000, defaultGasPrice); +export const defaultUpdateAdminFee = calculateFee(80_000, defaultGasPrice); +export const defaultClearAdminFee = calculateFee(80_000, defaultGasPrice); + /** An internal testing type. SigningCosmWasmClient has a similar but different interface */ export interface ContractUploadInstructions { /** The wasm bytecode */