From 499a71ab718d6ae0af9b397072cffdd318958f2e Mon Sep 17 00:00:00 2001 From: Yun Yeo Date: Thu, 30 Sep 2021 21:48:21 +0900 Subject: [PATCH] fix vesting account --- package-lock.json | 4 +- package.json | 2 +- src/client/lcd/api/AuthAPI.spec.ts | 4 - src/client/lcd/api/AuthAPI.ts | 8 - src/core/auth/Account.data.json | 36 +---- src/core/auth/Account.spec.ts | 24 --- src/core/auth/Account.ts | 9 +- .../auth/LazyGradedVestingAccount.data.json | 148 +++++++++++------- .../auth/LazyGradedVestingAccount.spec.ts | 59 +++---- src/core/auth/LazyGradedVestingAccount.ts | 55 +++---- 10 files changed, 143 insertions(+), 206 deletions(-) diff --git a/package-lock.json b/package-lock.json index f54623af7..262eeb2a2 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1,12 +1,12 @@ { "name": "@terra-money/terra.js", - "version": "2.0.12", + "version": "2.0.13", "lockfileVersion": 2, "requires": true, "packages": { "": { "name": "@terra-money/terra.js", - "version": "2.0.12", + "version": "2.0.13", "license": "MIT", "dependencies": { "axios": "^0.21.1", diff --git a/package.json b/package.json index 7feec20f7..dfbc2690e 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "@terra-money/terra.js", - "version": "2.0.12", + "version": "2.0.13", "description": "The JavaScript SDK for Terra", "license": "MIT", "author": "Terraform Labs, PTE.", diff --git a/src/client/lcd/api/AuthAPI.spec.ts b/src/client/lcd/api/AuthAPI.spec.ts index 4b7fe9fe3..0d436aff6 100644 --- a/src/client/lcd/api/AuthAPI.spec.ts +++ b/src/client/lcd/api/AuthAPI.spec.ts @@ -15,10 +15,6 @@ describe('AuthAPI', () => { ); expect(acct instanceof Account).toBe(true); - expect(acct.coins.toData()).toContainEqual({ - denom: expect.any(String), - amount: expect.any(String), - }); }); // TODO: - after merging CosmosSDK@v0.43.x restore vesting account test diff --git a/src/client/lcd/api/AuthAPI.ts b/src/client/lcd/api/AuthAPI.ts index 1b5d7a33e..1841934ba 100644 --- a/src/client/lcd/api/AuthAPI.ts +++ b/src/client/lcd/api/AuthAPI.ts @@ -21,14 +21,6 @@ export class AuthAPI extends BaseAPI { const { result } = await this.c.get< Account.Data | LazyGradedVestingAccount.Data >(`/auth/accounts/${address}`, params); - - // Until columbus-4 it used to return coins from /auth/accounts - if (!result.value.coins) { - result.value.coins = ( - await this.c.get(`/bank/balances/${address}`, params) - ).result; - } - if (result.type === 'core/Account') { return Account.fromData(result); } else { diff --git a/src/core/auth/Account.data.json b/src/core/auth/Account.data.json index 2d2310597..69e43c433 100644 --- a/src/core/auth/Account.data.json +++ b/src/core/auth/Account.data.json @@ -1,20 +1,8 @@ -[{ +[ + { "type": "core/Account", "value": { "address": "terra1h0d5kq5p64jcyqysvja3h2gysxnfudk9h73fnn", - "coins": [{ - "denom": "ukrw", - "amount": "3981685437" - }, - { - "denom": "uluna", - "amount": "2041" - }, - { - "denom": "umnt", - "amount": "363613" - } - ], "public_key": { "type": "tendermint/PubKeySecp256k1", "value": "Av0uQ9R72aq0dgu1H+F1+1p2daQLl0JsWhwkA07ftTq/" @@ -27,10 +15,6 @@ "type": "core/Account", "value": { "address": "terra1fex9f78reuwhfsnc8sun6mz8rl9zwqh03fhwf3", - "coins": [{ - "denom": "ukrw", - "amount": "15464712273121303" - }], "public_key": { "type": "tendermint/PubKeySecp256k1", "value": "AxYEJ7m2BMIzrugTG5Rl8Pz2RNU6eGfnsn2TfMXWEruf" @@ -43,10 +27,6 @@ "type": "core/Account", "value": { "address": "terra12fm3tql2uu0gheuj3st9cwz7ml97tq9mla88c2", - "coins": [{ - "denom": "ukrw", - "amount": "1077000000" - }], "public_key": { "type": "tendermint/PubKeySecp256k1", "value": "AvBeqhogW0wd7OtF8M8hJ/P1A/IBY1+uNvBO/tbVlfq2" @@ -59,11 +39,6 @@ "type": "core/Account", "value": { "address": "terra1kcc65k0ru6qq946ztqljxd67d5wltqstln5d5k", - "coins": [], - "public_key": { - "type": "tendermint/PubKeySecp256k1", - "value": "AsPdLO1QwuajkAP/MlVe17WwTimT7gUAE2iXDjaScrxH" - }, "account_number": "987828", "sequence": "28" } @@ -72,10 +47,7 @@ "type": "core/Account", "value": { "address": "terra1ax7xtll5v6u6vdnymxa4k4648w80zhkggl0u24", - "coins": [{ - "denom": "ukrw", - "amount": "31999000000" - }], + "public_key": { "type": "tendermint/PubKeySecp256k1", "value": "A/vzuSK9wCAvmFXorv/KTbUFsF9Av5r9XuplqF+4OLfR" @@ -84,4 +56,4 @@ "sequence": "65" } } -] \ No newline at end of file +] diff --git a/src/core/auth/Account.spec.ts b/src/core/auth/Account.spec.ts index 14e15ef71..f97171bdb 100644 --- a/src/core/auth/Account.spec.ts +++ b/src/core/auth/Account.spec.ts @@ -10,16 +10,6 @@ describe('Account', () => { type: 'core/Account', value: { address: 'terra12fm3tql2uu0gheuj3st9cwz7ml97tq9mla88c2', - coins: [ - { - denom: 'ukrw', - amount: '1077000000', - }, - { - denom: 'uluna', - amount: '10203920', - }, - ], public_key: { type: 'tendermint/PubKeySecp256k1', value: 'AvBeqhogW0wd7OtF8M8hJ/P1A/IBY1+uNvBO/tbVlfq2', @@ -31,10 +21,6 @@ describe('Account', () => { const acct = Account.fromData(data); expect(acct).toMatchObject({ address: 'terra12fm3tql2uu0gheuj3st9cwz7ml97tq9mla88c2', - coins: new Coins({ - ukrw: '1077000000', - uluna: '10203920', - }), public_key: { value: 'AvBeqhogW0wd7OtF8M8hJ/P1A/IBY1+uNvBO/tbVlfq2', }, @@ -50,7 +36,6 @@ describe('Account', () => { type: 'core/Account', value: { address: '', - coins: [], public_key: null, account_number: '0', sequence: '0', @@ -63,9 +48,6 @@ describe('Account', () => { it('serializes accounts correctly', () => { const acct = new Account( 'terra12fm3tql2uu0gheuj3st9cwz7ml97tq9mla88c2', - new Coins({ - uluna: 10203920, - }), new PublicKey('tendermint/PubKeySecp256k1', 'abc'), 251248, 58 @@ -75,12 +57,6 @@ describe('Account', () => { type: 'core/Account', value: { address: 'terra12fm3tql2uu0gheuj3st9cwz7ml97tq9mla88c2', - coins: [ - { - denom: 'uluna', - amount: '10203920', - }, - ], public_key: { type: 'tendermint/PubKeySecp256k1', value: 'abc', diff --git a/src/core/auth/Account.ts b/src/core/auth/Account.ts index 0a8893bfd..9efb638ef 100644 --- a/src/core/auth/Account.ts +++ b/src/core/auth/Account.ts @@ -11,14 +11,12 @@ export class Account extends JSONSerializable { * Creates a new Account object, holding information about a basic account. * * @param address account address - * @param coins account's balance * @param public_key account's public key information * @param account_number account number on the blockchain * @param sequence sequence number, or number of transactions that have been posted */ constructor( public address: AccAddress, - public coins: Coins, public public_key: PublicKey | null, public account_number: number, public sequence: number @@ -27,12 +25,11 @@ export class Account extends JSONSerializable { } public toData(): Account.Data { - const { address, coins, public_key, account_number, sequence } = this; + const { address, public_key, account_number, sequence } = this; return { type: 'core/Account', value: { address, - coins: coins.toData(), public_key: public_key ? public_key.toData() : null, account_number: account_number.toFixed(), sequence: sequence.toFixed(), @@ -42,12 +39,11 @@ export class Account extends JSONSerializable { public static fromData(data: Account.Data): Account { const { - value: { address, coins, public_key, account_number, sequence }, + value: { address, public_key, account_number, sequence }, } = data; return new Account( address || '', - Coins.fromData(coins), public_key ? PublicKey.fromData(public_key) : null, Number.parseInt(account_number) || 0, Number.parseInt(sequence) || 0 @@ -58,7 +54,6 @@ export class Account extends JSONSerializable { export namespace Account { export interface Value { address: AccAddress; - coins: Coins.Data; public_key: PublicKey.Data | null; account_number: string; sequence: string; diff --git a/src/core/auth/LazyGradedVestingAccount.data.json b/src/core/auth/LazyGradedVestingAccount.data.json index 7e67aee56..c6136a25f 100644 --- a/src/core/auth/LazyGradedVestingAccount.data.json +++ b/src/core/auth/LazyGradedVestingAccount.data.json @@ -1,64 +1,94 @@ -[{ - "type": "core/LazyGradedVestingAccount", - "value": { - "address": "terra1upg95nlwkfkrq4hhjrn3k9s6ud0aqx36gwnlsn", - "coins": [{ - "denom": "ukrw", - "amount": "3952727625434" - }, - { - "denom": "uluna", - "amount": "48919046" - }, - { - "denom": "umnt", - "amount": "35243811596" - }, - { - "denom": "usdr", - "amount": "1212381" - }, - { - "denom": "uusd", - "amount": "474532" - } - ], - "public_key": null, - "account_number": "684082", - "sequence": "0", - "original_vesting": [{ - "denom": "uluna", - "amount": "5000000000000" - }], - "delegated_free": [], - "delegated_vesting": [{ - "denom": "uluna", - "amount": "1338029091449" - }], - "end_time": "0", - "vesting_schedules": [{ - "denom": "uluna", - "schedules": [{ - "start_time": "1558677600", - "end_time": "1561356000", - "ratio": "0.100000000000000000" - }, - { - "start_time": "1561356000", - "end_time": "1587708000", - "ratio": "0.270000000000000000" - }, - { - "start_time": "1587708000", - "end_time": "1600927200", - "ratio": "0.480000000000000000" +[ + { + "type": "core/LazyGradedVestingAccount", + "value": { + "base_vesting_account": { + "base_account": { + "address": "terra1dp0taj85ruc299rkdvzp4z5pfg6z6swaed74e6", + "public_key": { + "type": "tendermint/PubKeyMultisigThreshold", + "value": { + "threshold": "2", + "pubkeys": [ + { + "type": "tendermint/PubKeySecp256k1", + "value": "AyETa9Y9ihObzeRPWMP0MBAa0Mqune3I+5KonOCPTtkv" + }, + { + "type": "tendermint/PubKeySecp256k1", + "value": "AzzLltyI4MzxLpcmS1vfpXJeAk/sgS1eVYmvXgFpGRtg" + }, + { + "type": "tendermint/PubKeySecp256k1", + "value": "AnZjvWmye3JPEL95xRcGeFRf4o8pHDK0dkZjf6B9D4FA" + } + ] + } + }, + "account_number": "317776", + "sequence": "61" }, + "original_vesting": [{ "denom": "usdr", "amount": "1000000000000000" }], + "delegated_free": [{ "denom": "uluna", "amount": "57620630000008" }], + "delegated_vesting": [] + }, + "vesting_schedules": [ { - "start_time": "1600927200", - "end_time": "1603519200", - "ratio": "0.150000000000000000" + "denom": "usdr", + "schedules": [ + { + "start_time": "1556085600", + "end_time": "1558677600", + "ratio": "0.100000000000000000" + }, + { + "start_time": "1587708000", + "end_time": "1590300000", + "ratio": "0.100000000000000000" + }, + { + "start_time": "1619244000", + "end_time": "1621836000", + "ratio": "0.100000000000000000" + }, + { + "start_time": "1650780000", + "end_time": "1653372000", + "ratio": "0.100000000000000000" + }, + { + "start_time": "1682316000", + "end_time": "1684908000", + "ratio": "0.100000000000000000" + }, + { + "start_time": "1713938400", + "end_time": "1716530400", + "ratio": "0.100000000000000000" + }, + { + "start_time": "1745474400", + "end_time": "1748066400", + "ratio": "0.100000000000000000" + }, + { + "start_time": "1777010400", + "end_time": "1779602400", + "ratio": "0.100000000000000000" + }, + { + "start_time": "1808546400", + "end_time": "1811138400", + "ratio": "0.100000000000000000" + }, + { + "start_time": "1840168800", + "end_time": "1842760800", + "ratio": "0.100000000000000000" + } + ] } ] - }] + } } -}] \ No newline at end of file +] diff --git a/src/core/auth/LazyGradedVestingAccount.spec.ts b/src/core/auth/LazyGradedVestingAccount.spec.ts index ca37ee4fc..33dab8cb5 100644 --- a/src/core/auth/LazyGradedVestingAccount.spec.ts +++ b/src/core/auth/LazyGradedVestingAccount.spec.ts @@ -8,46 +8,27 @@ describe('LazyGradedVestingAccount', () => { const acct = LazyGradedVestingAccount.fromData({ type: 'core/LazyGradedVestingAccount', value: { - address: 'terra1upg95nlwkfkrq4hhjrn3k9s6ud0aqx36gwnlsn', - coins: [ - { - denom: 'ukrw', - amount: '3952727625434', - }, - { - denom: 'uluna', - amount: '48919046', - }, - { - denom: 'umnt', - amount: '35243811596', - }, - { - denom: 'usdr', - amount: '1212381', - }, - { - denom: 'uusd', - amount: '474532', + base_vesting_account: { + base_account: { + address: 'terra1upg95nlwkfkrq4hhjrn3k9s6ud0aqx36gwnlsn', + public_key: null, + account_number: '684082', + sequence: '0', }, - ], - public_key: null, - account_number: '684082', - sequence: '0', - original_vesting: [ - { - denom: 'uluna', - amount: '5000000000000', - }, - ], - delegated_free: [], - delegated_vesting: [ - { - denom: 'uluna', - amount: '1338029091449', - }, - ], - end_time: '0', + original_vesting: [ + { + denom: 'uluna', + amount: '5000000000000', + }, + ], + delegated_free: [], + delegated_vesting: [ + { + denom: 'uluna', + amount: '1338029091449', + }, + ], + }, vesting_schedules: [ { denom: 'uluna', diff --git a/src/core/auth/LazyGradedVestingAccount.ts b/src/core/auth/LazyGradedVestingAccount.ts index 1bd36917a..cf5ea1768 100644 --- a/src/core/auth/LazyGradedVestingAccount.ts +++ b/src/core/auth/LazyGradedVestingAccount.ts @@ -16,19 +16,16 @@ export class LazyGradedVestingAccount extends JSONSerializable vs.toData()), }, }; @@ -69,28 +67,23 @@ export class LazyGradedVestingAccount extends JSONSerializable LazyGradedVestingAccount.VestingSchedule.fromData(vs) ) @@ -101,11 +94,13 @@ export class LazyGradedVestingAccount extends JSONSerializable