From 556689e322d4b79f0bb567fc5d9d8cd4ecd6ce26 Mon Sep 17 00:00:00 2001 From: Paul Kim Date: Wed, 29 Sep 2021 13:34:40 +0900 Subject: [PATCH] Remove Denom.LUNA, Denom.USD, ... for sustainablity (#143) * fix(Denom): remove Denom.LUNA, Denom.USD, ... for sustainablity * build: version 2.0.11 --- README.md | 4 +- integration-tests/estimateFee.ts | 2 +- integration-tests/executeContract.ts | 2 +- integration-tests/submitProposal.ts | 2 +- .../validatorsWithVotingPower.ts | 2 +- package-lock.json | 4 +- package.json | 2 +- src/client/lcd/LCDUtils.spec.ts | 2 +- src/client/lcd/api/StakingAPI.ts | 4 +- src/client/lcd/api/TreasuryAPI.ts | 2 +- src/core/Coin.spec.ts | 38 +++++++++---------- src/core/Coins.spec.ts | 11 +++--- src/core/Denom.ts | 24 ------------ src/core/TxInfo.data.json | 22 +++++------ 14 files changed, 48 insertions(+), 73 deletions(-) diff --git a/README.md b/README.md index d36dea1c9..f3282890c 100644 --- a/README.md +++ b/README.md @@ -67,7 +67,7 @@ import { LCDClient, Coin } from '@terra-money/terra.js'; // connect to bombay testnet const terra = new LCDClient({ URL: 'https://bombay-lcd.terra.dev', - chainID: 'bombay-10', + chainID: 'bombay-12', }); // To use LocalTerra @@ -99,7 +99,7 @@ const mk = new MnemonicKey({ // connect to bombay testnet const terra = new LCDClient({ URL: 'https://bombay-lcd.terra.dev', - chainID: 'bombay-10', + chainID: 'bombay-12', }); // To use LocalTerra diff --git a/integration-tests/estimateFee.ts b/integration-tests/estimateFee.ts index ef1ca6ba9..3c1c3705a 100644 --- a/integration-tests/estimateFee.ts +++ b/integration-tests/estimateFee.ts @@ -11,7 +11,7 @@ async function main() { ); const tequila = new LCDClient({ - chainID: 'bombay-9', + chainID: 'bombay-12', URL: 'https://bombay-lcd.terra.dev', gasPrices, }); diff --git a/integration-tests/executeContract.ts b/integration-tests/executeContract.ts index cc513e95f..a52af622b 100644 --- a/integration-tests/executeContract.ts +++ b/integration-tests/executeContract.ts @@ -1,7 +1,7 @@ import { LCDClient, MnemonicKey, MsgExecuteContract, Wallet } from '../src'; const client = new LCDClient({ - chainID: 'bombay-9', + chainID: 'bombay-12', URL: 'https://bombay-lcd.terra.dev', }); diff --git a/integration-tests/submitProposal.ts b/integration-tests/submitProposal.ts index 88cc08128..95abbacc5 100644 --- a/integration-tests/submitProposal.ts +++ b/integration-tests/submitProposal.ts @@ -8,7 +8,7 @@ import { } from '../src'; const client = new LCDClient({ - chainID: 'bombay-11', + chainID: 'bombay-12', URL: 'https://bombay-lcd.terra.dev', }); diff --git a/integration-tests/validatorsWithVotingPower.ts b/integration-tests/validatorsWithVotingPower.ts index 69d320dff..8c7cc8e06 100644 --- a/integration-tests/validatorsWithVotingPower.ts +++ b/integration-tests/validatorsWithVotingPower.ts @@ -1,7 +1,7 @@ import { LCDClient } from '../src'; const terra = new LCDClient({ - chainID: 'bombay-9', + chainID: 'bombay-12', URL: 'https://bombay-lcd.terra.dev', }); diff --git a/package-lock.json b/package-lock.json index a7ce67246..09841723a 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1,12 +1,12 @@ { "name": "@terra-money/terra.js", - "version": "2.0.10", + "version": "2.0.11", "lockfileVersion": 2, "requires": true, "packages": { "": { "name": "@terra-money/terra.js", - "version": "2.0.10", + "version": "2.0.11", "license": "MIT", "dependencies": { "axios": "^0.21.1", diff --git a/package.json b/package.json index 739db8f45..6723946c6 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "@terra-money/terra.js", - "version": "2.0.10", + "version": "2.0.11", "description": "The JavaScript SDK for Terra", "license": "MIT", "author": "Terraform Labs, PTE.", diff --git a/src/client/lcd/LCDUtils.spec.ts b/src/client/lcd/LCDUtils.spec.ts index c131a8688..82a50e7c9 100644 --- a/src/client/lcd/LCDUtils.spec.ts +++ b/src/client/lcd/LCDUtils.spec.ts @@ -4,7 +4,7 @@ import { Coin, Validator } from '../../core'; const lcdUtils = new LCDUtils( new LCDClient({ - chainID: 'bombay-9', + chainID: 'bombay-12', URL: 'https://bombay-lcd.terra.dev', }) ); diff --git a/src/client/lcd/api/StakingAPI.ts b/src/client/lcd/api/StakingAPI.ts index 0a89cb76f..cfbb6546f 100644 --- a/src/client/lcd/api/StakingAPI.ts +++ b/src/client/lcd/api/StakingAPI.ts @@ -231,8 +231,8 @@ export class StakingAPI extends BaseAPI { return this.c .get(`/staking/pool`, params) .then(({ result: d }) => ({ - bonded_tokens: new Coin(Denom.LUNA, d.bonded_tokens), - not_bonded_tokens: new Coin(Denom.LUNA, d.not_bonded_tokens), + bonded_tokens: new Coin('uluna', d.bonded_tokens), + not_bonded_tokens: new Coin('uluna', d.not_bonded_tokens), })); } diff --git a/src/client/lcd/api/TreasuryAPI.ts b/src/client/lcd/api/TreasuryAPI.ts index 7af2a8fd7..d6b66f206 100644 --- a/src/client/lcd/api/TreasuryAPI.ts +++ b/src/client/lcd/api/TreasuryAPI.ts @@ -100,7 +100,7 @@ export class TreasuryAPI extends BaseAPI { public async seigniorageProceeds(params: APIParams = {}): Promise { return this.c .get(`/treasury/seigniorage_proceeds`, params) - .then(d => new Coin(Denom.LUNA, d.result)); + .then(d => new Coin('uluna', d.result)); } /** diff --git a/src/core/Coin.spec.ts b/src/core/Coin.spec.ts index cee192877..561c26d01 100644 --- a/src/core/Coin.spec.ts +++ b/src/core/Coin.spec.ts @@ -4,24 +4,24 @@ import { Dec, Int } from './numeric'; describe('Coin', () => { it('different types for amount', () => { - const ref = new Coin(Denom.LUNA, 1000); - const coins = [new Coin(Denom.LUNA, 1000.0), new Coin(Denom.LUNA, '1000')]; + const ref = new Coin('uluna', 1000); + const coins = [new Coin('uluna', 1000.0), new Coin('uluna', '1000')]; coins.forEach(coin => expect(coin).toEqual(ref)); }); it('deserializes Coin value', () => { const coin = Coin.fromData({ - denom: Denom.LUNA, + denom: 'uluna', amount: '1000', }); - expect(coin.denom).toEqual(Denom.LUNA); + expect(coin.denom).toEqual('uluna'); expect(coin.amount.toNumber()).toEqual(1000); }); it('serializes', () => { const coinData: Coin.Data = { - denom: Denom.LUNA, + denom: 'uluna', amount: '1000', }; @@ -30,7 +30,7 @@ describe('Coin', () => { expect(coin.toData()).toEqual(coinData); const decCoinData = { - denom: Denom.LUNA, + denom: 'uluna', amount: '1000.000000000000000000', }; const decCoin = Coin.fromData(decCoinData); @@ -39,18 +39,18 @@ describe('Coin', () => { }); it('arithmetic', () => { - const zero = new Coin(Denom.LUNA, 0); - const coin = new Coin(Denom.LUNA, 1000); - const coin2 = new Coin(Denom.LUNA, 2000); - const coin3 = new Coin(Denom.KRW, 2000); + const zero = new Coin('uluna', 0); + const coin = new Coin('uluna', 1000); + const coin2 = new Coin('uluna', 2000); + const coin3 = new Coin('ukrw', 2000); // addition const sum = coin.add(coin2); const decSum = coin.add(0.1); expect(coin.add(zero).amount).toEqual(coin.amount); expect(sum.amount.toNumber()).toEqual(3000); - expect(sum.denom).toEqual(Denom.LUNA); - expect(coin.add(1500)).toEqual(new Coin(Denom.LUNA, 2500)); + expect(sum.denom).toEqual('uluna'); + expect(coin.add(1500)).toEqual(new Coin('uluna', 2500)); expect(decSum.isDecCoin()).toBe(true); expect(decSum.isIntCoin()).toBe(false); expect(decSum.amount.toNumber()).toEqual(1000.1); @@ -58,30 +58,30 @@ describe('Coin', () => { // subtraction const diff = coin2.sub(coin); - expect(diff.denom).toEqual(Denom.LUNA); + expect(diff.denom).toEqual('uluna'); expect(diff.amount.toNumber()).toEqual(1000); expect(() => coin2.sub(coin3)).toThrow(Coin.ArithmeticError); // multiplication const product = coin.mul(3.1233); - expect(product.denom).toEqual(Denom.LUNA); + expect(product.denom).toEqual('uluna'); expect(product.amount.toNumber()).toEqual(3123.3); // division const quotient = coin.div(5); - expect(quotient.denom).toEqual(Denom.LUNA); + expect(quotient.denom).toEqual('uluna'); expect(quotient.amount.toNumber()).toEqual(200); // modulo const rem = coin.mod(43); - expect(rem.denom).toEqual(Denom.LUNA); + expect(rem.denom).toEqual('uluna'); expect(rem.amount.toNumber()).toEqual(coin.amount.toNumber() % 43); }); it('equality', () => { - const coin1 = new Coin(Denom.LUNA, 1000); - const coin2 = new Coin(Denom.LUNA, 1000); - const coin3 = new Coin(Denom.LUNA, 1001); + const coin1 = new Coin('uluna', 1000); + const coin2 = new Coin('uluna', 1000); + const coin3 = new Coin('uluna', 1001); expect(coin1).toEqual(coin2); expect(coin1).not.toEqual(coin3); }); diff --git a/src/core/Coins.spec.ts b/src/core/Coins.spec.ts index 7f0debf8d..0a8b6671e 100644 --- a/src/core/Coins.spec.ts +++ b/src/core/Coins.spec.ts @@ -1,17 +1,16 @@ import { Coins } from './Coins'; import { Coin } from './Coin'; -import { Denom } from './Denom'; describe('Coins', () => { it('clobbers coins of similar denom', () => { const coins1 = new Coins([ - new Coin(Denom.KRW, 1000), - new Coin(Denom.LUNA, 1000), - new Coin(Denom.LUNA, 1000), + new Coin('ukrw', 1000), + new Coin('uluna', 1000), + new Coin('uluna', 1000), ]); - const coinKRW = coins1.get(Denom.KRW); - const coinLUNA = coins1.get(Denom.LUNA); + const coinKRW = coins1.get('ukrw'); + const coinLUNA = coins1.get('uluna'); expect(coinKRW).toBeDefined(); expect(coinLUNA).toBeDefined(); diff --git a/src/core/Denom.ts b/src/core/Denom.ts index e5f7d06ea..54451d729 100644 --- a/src/core/Denom.ts +++ b/src/core/Denom.ts @@ -1,25 +1 @@ export type Denom = string; - -export namespace Denom { - export const LUNA = 'uluna'; - export const AUD = 'uaud'; - export const CAD = 'ucad'; - export const CHF = 'uchf'; - export const CNY = 'ucny'; - export const DKK = 'udkk'; - export const EUR = 'ueur'; - export const GBP = 'ugbp'; - export const HKD = 'uhkd'; - export const IDR = 'uidr'; - export const INR = 'uinr'; - export const JPY = 'ujpy'; - export const KRW = 'ukrw'; - export const MNT = 'umnt'; - export const NOK = 'unok'; - export const PHP = 'uphp'; - export const SDR = 'usdr'; - export const SEK = 'usek'; - export const SGD = 'usgd'; - export const THB = 'uthb'; - export const USD = 'uusd'; -} diff --git a/src/core/TxInfo.data.json b/src/core/TxInfo.data.json index 8d487f7b5..ecf4eab5f 100644 --- a/src/core/TxInfo.data.json +++ b/src/core/TxInfo.data.json @@ -124,7 +124,7 @@ }, { "id": 20854160, - "chainId": "bombay-9", + "chainId": "bombay-12", "tx": { "type": "core/StdTx", "value": { @@ -245,7 +245,7 @@ }, { "id": 20849375, - "chainId": "bombay-9", + "chainId": "bombay-12", "tx": { "type": "core/StdTx", "value": { @@ -417,7 +417,7 @@ }, { "id": 20849322, - "chainId": "bombay-9", + "chainId": "bombay-12", "tx": { "type": "core/StdTx", "value": { @@ -594,7 +594,7 @@ }, { "id": 20539231, - "chainId": "bombay-9", + "chainId": "bombay-12", "tx": { "type": "core/StdTx", "value": { @@ -726,7 +726,7 @@ }, { "id": 20529213, - "chainId": "bombay-9", + "chainId": "bombay-12", "tx": { "type": "core/StdTx", "value": { @@ -871,7 +871,7 @@ }, { "id": 20529159, - "chainId": "bombay-9", + "chainId": "bombay-12", "tx": { "type": "core/StdTx", "value": { @@ -1048,7 +1048,7 @@ }, { "id": 20524335, - "chainId": "bombay-9", + "chainId": "bombay-12", "tx": { "type": "core/StdTx", "value": { @@ -1225,7 +1225,7 @@ }, { "id": 20523910, - "chainId": "bombay-9", + "chainId": "bombay-12", "tx": { "type": "core/StdTx", "value": { @@ -1370,7 +1370,7 @@ }, { "id": 20512034, - "chainId": "bombay-9", + "chainId": "bombay-12", "tx": { "type": "core/StdTx", "value": { @@ -1489,7 +1489,7 @@ }, { "id": 20510761, - "chainId": "bombay-9", + "chainId": "bombay-12", "tx": { "type": "core/StdTx", "value": { @@ -1661,7 +1661,7 @@ }, { "id": 18557171, - "chainId": "bombay-9", + "chainId": "bombay-12", "tx": { "type": "core/StdTx", "value": {