diff --git a/packages/bcp/package.json b/packages/bcp/package.json index 4721a2d6..193fb5d9 100644 --- a/packages/bcp/package.json +++ b/packages/bcp/package.json @@ -44,6 +44,8 @@ "@iov/encoding": "^2.0.0-alpha.7", "@iov/stream": "^2.0.0-alpha.7", "@iov/utils": "^2.0.0-alpha.7", + "@types/bn.js": "^4.11.6", + "bn.js": "^5.1.1", "fast-deep-equal": "^3.1.1", "readonly-date": "^1.0.0", "xstream": "^11.11.0" diff --git a/packages/bcp/src/cosmwasmconnection.spec.ts b/packages/bcp/src/cosmwasmconnection.spec.ts index 6c14f0d1..dee2d922 100644 --- a/packages/bcp/src/cosmwasmconnection.spec.ts +++ b/packages/bcp/src/cosmwasmconnection.spec.ts @@ -84,6 +84,12 @@ describe("CosmWasmConnection", () => { ticker: "BASH", name: "Bash Token", }, + { + contractAddress: "cosmos18r5szma8hm93pvx6lwpjwyxruw27e0k5uw835c", + fractionalDigits: 18, + ticker: "CASH", + name: "Cash Token", + }, ], }; @@ -154,6 +160,11 @@ describe("CosmWasmConnection", () => { tokenName: "Bash Token", tokenTicker: "BASH" as TokenTicker, }, + { + fractionalDigits: 18, + tokenName: "Cash Token", + tokenTicker: "CASH" as TokenTicker, + }, { fractionalDigits: 6, tokenName: "Fee Token", diff --git a/packages/bcp/src/cosmwasmconnection.ts b/packages/bcp/src/cosmwasmconnection.ts index d8e8dbb5..7a3e50e2 100644 --- a/packages/bcp/src/cosmwasmconnection.ts +++ b/packages/bcp/src/cosmwasmconnection.ts @@ -31,6 +31,7 @@ import { import { Sha256 } from "@iov/crypto"; import { Encoding, Uint53 } from "@iov/encoding"; import { DefaultValueProducer, ValueAndUpdates } from "@iov/stream"; +import BN from "bn.js"; import equal from "fast-deep-equal"; import { ReadonlyDate } from "readonly-date"; import { Stream } from "xstream"; @@ -172,18 +173,20 @@ export class CosmWasmConnection implements BlockchainConnection { const response = JSON.parse( await this.restClient.queryContractSmart(erc20.contractAddress, queryMsg), ); + const normalizedBalance = new BN(response.balance).toString(); return { fractionalDigits: erc20.fractionalDigits, - quantity: response.balance, + quantity: normalizedBalance, tokenTicker: erc20.ticker as TokenTicker, }; }, ), ); + const nonZeroErc20Amounts = erc20Amounts.filter(amount => amount.quantity !== "0"); const balance = [ ...supportedBankCoins.map(coin => decodeAmount(this.bankTokens, coin)), - ...erc20Amounts, + ...nonZeroErc20Amounts, ].sort((a, b) => a.tokenTicker.localeCompare(b.tokenTicker)); const pubkey = !account.public_key ? undefined : decodeCosmosPubkey(account.public_key); diff --git a/scripts/cosm/deploy_erc20.js b/scripts/cosm/deploy_erc20.js index 953f433b..78901bf1 100755 --- a/scripts/cosm/deploy_erc20.js +++ b/scripts/cosm/deploy_erc20.js @@ -118,7 +118,18 @@ async function main() { }, ], }; - for (const initMsg of [initMsgAsh, initMsgBash]) { + const initMsgCash = { + decimals: 18, + name: "Cash Token", + symbol: "CASH", + initial_balances: [ + { + address: faucetAddress, + amount: "189189189000000000000000000", // 189189189 CASH + }, + ], + }; + for (const initMsg of [initMsgAsh, initMsgBash, initMsgCash]) { const initResult = await instantiateContract(client, pen, codeId, initMsg); if (initResult.code) { throw new Error(`Instantiation failed with code: ${initResult.code}; log: '${initResult.raw_log}'`); diff --git a/yarn.lock b/yarn.lock index 634f4e2f..2f12d9fe 100644 --- a/yarn.lock +++ b/yarn.lock @@ -966,6 +966,13 @@ dependencies: "@types/babel-types" "*" +"@types/bn.js@^4.11.6": + version "4.11.6" + resolved "https://registry.yarnpkg.com/@types/bn.js/-/bn.js-4.11.6.tgz#c306c70d9358aaea33cd4eda092a742b9505967c" + integrity sha512-pqr857jrp2kPuO9uRjZ3PwnJTjoQy+fcdxvBTvHm6dkmEL9q+hDD/2j/0ELOBPtPnS8LjCX0gI9nbl8lVkadpg== + dependencies: + "@types/node" "*" + "@types/body-parser@*": version "1.17.1" resolved "https://registry.yarnpkg.com/@types/body-parser/-/body-parser-1.17.1.tgz#18fcf61768fb5c30ccc508c21d6fd2e8b3bf7897" @@ -1826,6 +1833,11 @@ bn.js@^4.0.0, bn.js@^4.1.0, bn.js@^4.1.1, bn.js@^4.11.8, bn.js@^4.4.0: resolved "https://registry.yarnpkg.com/bn.js/-/bn.js-4.11.8.tgz#2cde09eb5ee341f484746bb0309b3253b1b1442f" integrity sha512-ItfYfPLkWHUjckQCk8xC+LwxgK8NYcXywGigJgSwOP8Y2iyWT4f2vsZnoOXTTbo+o5yXmIUJ4gn5538SO5S3gA== +bn.js@^5.1.1: + version "5.1.1" + resolved "https://registry.yarnpkg.com/bn.js/-/bn.js-5.1.1.tgz#48efc4031a9c4041b9c99c6941d903463ab62eb5" + integrity sha512-IUTD/REb78Z2eodka1QZyyEk66pciRcP6Sroka0aI3tG/iwIdYLrBD62RsubR7vqdt3WyX8p4jxeatzmRSphtA== + body-parser@^1.16.1: version "1.19.0" resolved "https://registry.yarnpkg.com/body-parser/-/body-parser-1.19.0.tgz#96b2709e57c9c4e09a6fd66a8fd979844f69f08a"