Skip to content

Commit

Permalink
Merge pull request #399 from CosmWasm/396-fee-table
Browse files Browse the repository at this point in the history
Update Fee tables
  • Loading branch information
webmaster128 authored Aug 19, 2020
2 parents 8b7bd1e + 47018d2 commit 0bd8d5e
Show file tree
Hide file tree
Showing 26 changed files with 596 additions and 98 deletions.
16 changes: 16 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,10 @@
## 0.23.0 (unreleased)

- @cosmjs/cosmwasm: Rename `CosmWasmClient.postTx` method to `.broadcastTx`.
- @cosmjs/cosmwasm: Rename `FeeTable` type to `CosmWasmFeeTable`.
- @cosmjs/cosmwasm: `SigningCosmWasmClient` constructor now takes optional
arguments `gasPrice` and `gasLimits` instead of `customFees` for easier
customization.
- @cosmjs/cosmwasm: Rename `SigningCosmWasmClient.signAndPost` method to
`.signAndBroadcast`.
- @cosmjs/cosmwasm: Use stricter type `Record<string, unknown>` for smart query,
Expand All @@ -13,7 +17,18 @@
- @cosmjs/encoding: Add `limit` parameter to `Bech32.encode` and `.decode`. The
new default limit for decoding is infinity (was 90 before). Set it to 90 to
create a strict decoder.
- @cosmjs/faucet: Environmental variable `FAUCET_FEE` renamed to
`FAUCET_GAS_PRICE` and now only accepts one token. Environmental variable
`FAUCET_GAS` renamed to `FAUCET_GAS_LIMIT`.
- @cosmjs/launchpad: Rename `FeeTable` type to `CosmosFeeTable` and export a new
more generic type `FeeTable`.
- @cosmjs/launchpad: Add new class `GasPrice`, new helper type `GasLimits` and
new helper function `buildFeeTable` for easier handling of gas prices and
fees.
- @cosmjs/launchpad: Rename `CosmosClient.postTx` method to `.broadcastTx`.
- @cosmjs/launchpad: `SigningCosmosClient` constructor now takes optional
arguments `gasPrice` and `gasLimits` instead of `customFees` for easier
customization.
- @cosmjs/launchpad: Rename `SigningCosmosClient.signAndPost` method to
`.signAndBroadcast`.
- @cosmjs/launchpad: Rename `PostTx`-related types to `BroadcastTxResult`,
Expand All @@ -24,6 +39,7 @@
`isSearchBySentFromOrToQuery` and `isSearchByTagsQuery`.
- @cosmjs/launchpad: Change type of `TxsResponse.logs` and
`BroadcastTxsResponse.logs` to `unknown[]`.
- @cosmjs/math: Add `.multiply` method to `Decimal` class.
- @cosmjs/tendermint-rpc: Make `BroadcastTxCommitResponse.height` non-optional.
- @cosmjs/tendermint-rpc: Change type of `GenesisResponse.appState` to
`Record<string, unknown> | undefined`.
Expand Down
20 changes: 10 additions & 10 deletions packages/cli/examples/helpers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,8 @@ const defaultOptions: Options = {

const defaultFaucetUrl = "https://faucet.demo-10.cosmwasm.com/credit";

const buildFeeTable = (feeToken: string, gasPrice: number): FeeTable => {
const stdFee = (gas: number, denom: string, price: number) => {
const buildFeeTable = (feeToken: string, gasPrice: number): CosmWasmFeeTable => {
const calculateFee = (gas: number, denom: string, price: number) => {
const amount = Math.floor(gas * price);
return {
amount: [{ amount: amount.toString(), denom: denom }],
Expand All @@ -26,12 +26,12 @@ const buildFeeTable = (feeToken: string, gasPrice: number): FeeTable => {
};

return {
upload: stdFee(1000000, feeToken, gasPrice),
init: stdFee(500000, feeToken, gasPrice),
migrate: stdFee(500000, feeToken, gasPrice),
exec: stdFee(200000, feeToken, gasPrice),
send: stdFee(80000, feeToken, gasPrice),
changeAdmin: stdFee(80000, feeToken, gasPrice),
upload: calculateFee(1000000, feeToken, gasPrice),
init: calculateFee(500000, feeToken, gasPrice),
migrate: calculateFee(500000, feeToken, gasPrice),
exec: calculateFee(200000, feeToken, gasPrice),
send: calculateFee(80000, feeToken, gasPrice),
changeAdmin: calculateFee(80000, feeToken, gasPrice),
};
};

Expand All @@ -51,11 +51,11 @@ const connect = async (
address: string;
}> => {
const options: Options = { ...defaultOptions, ...opts };
const feeTable = buildFeeTable(options.feeToken, options.gasPrice);
const gasPrice = GasPrice.fromString(`${options.gasPrice}${options.feeToken}`);
const wallet = await Secp256k1Wallet.fromMnemonic(mnemonic);
const [{ address }] = await wallet.getAccounts();

const client = new SigningCosmWasmClient(options.httpUrl, address, wallet, feeTable);
const client = new SigningCosmWasmClient(options.httpUrl, address, wallet, gasPrice);
return { client, address };
};

Expand Down
3 changes: 2 additions & 1 deletion packages/cli/src/cli.ts
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ export async function main(originalArgs: readonly string[]): Promise<void> {
"SearchTxFilter",
// signingcosmwasmclient
"ExecuteResult",
"FeeTable",
"CosmWasmFeeTable",
"InstantiateResult",
"SigningCosmWasmClient",
"UploadMeta",
Expand Down Expand Up @@ -102,6 +102,7 @@ export async function main(originalArgs: readonly string[]): Promise<void> {
"BroadcastTxResult",
"Coin",
"CosmosClient",
"GasPrice",
"Msg",
"MsgDelegate",
"MsgSend",
Expand Down
2 changes: 1 addition & 1 deletion packages/cosmwasm/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ export {
} from "./cosmwasmclient";
export {
ExecuteResult,
FeeTable,
CosmWasmFeeTable,
InstantiateOptions,
InstantiateResult,
MigrateResult,
Expand Down
197 changes: 196 additions & 1 deletion packages/cosmwasm/src/signingcosmwasmclient.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import {
AuthExtension,
coin,
coins,
GasPrice,
LcdClient,
MsgDelegate,
Secp256k1Wallet,
Expand All @@ -15,7 +16,7 @@ import { assert } from "@cosmjs/utils";

import { PrivateCosmWasmClient } from "./cosmwasmclient";
import { setupWasmExtension, WasmExtension } from "./lcdapi/wasm";
import { SigningCosmWasmClient, UploadMeta } from "./signingcosmwasmclient";
import { PrivateSigningCosmWasmClient, SigningCosmWasmClient, UploadMeta } from "./signingcosmwasmclient";
import {
alice,
getHackatom,
Expand All @@ -38,6 +39,200 @@ describe("SigningCosmWasmClient", () => {
const client = new SigningCosmWasmClient(httpUrl, alice.address0, wallet);
expect(client).toBeTruthy();
});

it("can be constructed with custom gas price", async () => {
const wallet = await Secp256k1Wallet.fromMnemonic(alice.mnemonic);
const gasPrice = GasPrice.fromString("3.14utest");
const client = new SigningCosmWasmClient(httpUrl, alice.address0, wallet, gasPrice);
const openedClient = (client as unknown) as PrivateSigningCosmWasmClient;
expect(openedClient.fees).toEqual({
upload: {
amount: [
{
amount: "3140000",
denom: "utest",
},
],
gas: "1000000",
},
init: {
amount: [
{
amount: "1570000",
denom: "utest",
},
],
gas: "500000",
},
migrate: {
amount: [
{
amount: "628000",
denom: "utest",
},
],
gas: "200000",
},
exec: {
amount: [
{
amount: "628000",
denom: "utest",
},
],
gas: "200000",
},
send: {
amount: [
{
amount: "251200",
denom: "utest",
},
],
gas: "80000",
},
changeAdmin: {
amount: [
{
amount: "251200",
denom: "utest",
},
],
gas: "80000",
},
});
});

it("can be constructed with custom gas limits", async () => {
const wallet = await Secp256k1Wallet.fromMnemonic(alice.mnemonic);
const gasLimits = {
send: 160000,
};
const client = new SigningCosmWasmClient(httpUrl, alice.address0, wallet, undefined, gasLimits);
const openedClient = (client as unknown) as PrivateSigningCosmWasmClient;
expect(openedClient.fees).toEqual({
upload: {
amount: [
{
amount: "25000",
denom: "ucosm",
},
],
gas: "1000000",
},
init: {
amount: [
{
amount: "12500",
denom: "ucosm",
},
],
gas: "500000",
},
migrate: {
amount: [
{
amount: "5000",
denom: "ucosm",
},
],
gas: "200000",
},
exec: {
amount: [
{
amount: "5000",
denom: "ucosm",
},
],
gas: "200000",
},
send: {
amount: [
{
amount: "4000",
denom: "ucosm",
},
],
gas: "160000",
},
changeAdmin: {
amount: [
{
amount: "2000",
denom: "ucosm",
},
],
gas: "80000",
},
});
});

it("can be constructed with custom gas price and gas limits", async () => {
const wallet = await Secp256k1Wallet.fromMnemonic(alice.mnemonic);
const gasPrice = GasPrice.fromString("3.14utest");
const gasLimits = {
send: 160000,
};
const client = new SigningCosmWasmClient(httpUrl, alice.address0, wallet, gasPrice, gasLimits);
const openedClient = (client as unknown) as PrivateSigningCosmWasmClient;
expect(openedClient.fees).toEqual({
upload: {
amount: [
{
amount: "3140000",
denom: "utest",
},
],
gas: "1000000",
},
init: {
amount: [
{
amount: "1570000",
denom: "utest",
},
],
gas: "500000",
},
migrate: {
amount: [
{
amount: "628000",
denom: "utest",
},
],
gas: "200000",
},
exec: {
amount: [
{
amount: "628000",
denom: "utest",
},
],
gas: "200000",
},
send: {
amount: [
{
amount: "502400",
denom: "utest",
},
],
gas: "160000",
},
changeAdmin: {
amount: [
{
amount: "251200",
denom: "utest",
},
],
gas: "80000",
},
});
});
});

describe("getHeight", () => {
Expand Down
Loading

0 comments on commit 0bd8d5e

Please sign in to comment.