Skip to content

Commit

Permalink
Remove Denom.LUNA, Denom.USD, ... for sustainablity (#143)
Browse files Browse the repository at this point in the history
* fix(Denom): remove Denom.LUNA, Denom.USD, ... for sustainablity
* build: version 2.0.11
  • Loading branch information
hanjukim authored Sep 29, 2021
1 parent 711242a commit 556689e
Show file tree
Hide file tree
Showing 14 changed files with 48 additions and 73 deletions.
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion integration-tests/estimateFee.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ async function main() {
);

const tequila = new LCDClient({
chainID: 'bombay-9',
chainID: 'bombay-12',
URL: 'https://bombay-lcd.terra.dev',
gasPrices,
});
Expand Down
2 changes: 1 addition & 1 deletion integration-tests/executeContract.ts
Original file line number Diff line number Diff line change
@@ -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',
});

Expand Down
2 changes: 1 addition & 1 deletion integration-tests/submitProposal.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import {
} from '../src';

const client = new LCDClient({
chainID: 'bombay-11',
chainID: 'bombay-12',
URL: 'https://bombay-lcd.terra.dev',
});

Expand Down
2 changes: 1 addition & 1 deletion integration-tests/validatorsWithVotingPower.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { LCDClient } from '../src';

const terra = new LCDClient({
chainID: 'bombay-9',
chainID: 'bombay-12',
URL: 'https://bombay-lcd.terra.dev',
});

Expand Down
4 changes: 2 additions & 2 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -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.",
Expand Down
2 changes: 1 addition & 1 deletion src/client/lcd/LCDUtils.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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',
})
);
Expand Down
4 changes: 2 additions & 2 deletions src/client/lcd/api/StakingAPI.ts
Original file line number Diff line number Diff line change
Expand Up @@ -231,8 +231,8 @@ export class StakingAPI extends BaseAPI {
return this.c
.get<StakingPool.Data>(`/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),
}));
}

Expand Down
2 changes: 1 addition & 1 deletion src/client/lcd/api/TreasuryAPI.ts
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,7 @@ export class TreasuryAPI extends BaseAPI {
public async seigniorageProceeds(params: APIParams = {}): Promise<Coin> {
return this.c
.get<string>(`/treasury/seigniorage_proceeds`, params)
.then(d => new Coin(Denom.LUNA, d.result));
.then(d => new Coin('uluna', d.result));
}

/**
Expand Down
38 changes: 19 additions & 19 deletions src/core/Coin.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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',
};

Expand All @@ -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);
Expand All @@ -39,49 +39,49 @@ 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);
expect(() => coin.add(coin3)).toThrowError(Coin.ArithmeticError);

// 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);
});
Expand Down
11 changes: 5 additions & 6 deletions src/core/Coins.spec.ts
Original file line number Diff line number Diff line change
@@ -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();
Expand Down
24 changes: 0 additions & 24 deletions src/core/Denom.ts
Original file line number Diff line number Diff line change
@@ -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';
}
22 changes: 11 additions & 11 deletions src/core/TxInfo.data.json
Original file line number Diff line number Diff line change
Expand Up @@ -124,7 +124,7 @@
},
{
"id": 20854160,
"chainId": "bombay-9",
"chainId": "bombay-12",
"tx": {
"type": "core/StdTx",
"value": {
Expand Down Expand Up @@ -245,7 +245,7 @@
},
{
"id": 20849375,
"chainId": "bombay-9",
"chainId": "bombay-12",
"tx": {
"type": "core/StdTx",
"value": {
Expand Down Expand Up @@ -417,7 +417,7 @@
},
{
"id": 20849322,
"chainId": "bombay-9",
"chainId": "bombay-12",
"tx": {
"type": "core/StdTx",
"value": {
Expand Down Expand Up @@ -594,7 +594,7 @@
},
{
"id": 20539231,
"chainId": "bombay-9",
"chainId": "bombay-12",
"tx": {
"type": "core/StdTx",
"value": {
Expand Down Expand Up @@ -726,7 +726,7 @@
},
{
"id": 20529213,
"chainId": "bombay-9",
"chainId": "bombay-12",
"tx": {
"type": "core/StdTx",
"value": {
Expand Down Expand Up @@ -871,7 +871,7 @@
},
{
"id": 20529159,
"chainId": "bombay-9",
"chainId": "bombay-12",
"tx": {
"type": "core/StdTx",
"value": {
Expand Down Expand Up @@ -1048,7 +1048,7 @@
},
{
"id": 20524335,
"chainId": "bombay-9",
"chainId": "bombay-12",
"tx": {
"type": "core/StdTx",
"value": {
Expand Down Expand Up @@ -1225,7 +1225,7 @@
},
{
"id": 20523910,
"chainId": "bombay-9",
"chainId": "bombay-12",
"tx": {
"type": "core/StdTx",
"value": {
Expand Down Expand Up @@ -1370,7 +1370,7 @@
},
{
"id": 20512034,
"chainId": "bombay-9",
"chainId": "bombay-12",
"tx": {
"type": "core/StdTx",
"value": {
Expand Down Expand Up @@ -1489,7 +1489,7 @@
},
{
"id": 20510761,
"chainId": "bombay-9",
"chainId": "bombay-12",
"tx": {
"type": "core/StdTx",
"value": {
Expand Down Expand Up @@ -1661,7 +1661,7 @@
},
{
"id": 18557171,
"chainId": "bombay-9",
"chainId": "bombay-12",
"tx": {
"type": "core/StdTx",
"value": {
Expand Down

0 comments on commit 556689e

Please sign in to comment.