From 0b4f8e7437dc7e199fd2ec1be7dae4f015ee075d Mon Sep 17 00:00:00 2001 From: emidev98 Date: Sat, 16 Mar 2024 10:53:06 +0200 Subject: [PATCH 1/4] fix: alliance delegation model does not need to be coins --- src/client/lcd/api/AllianceAPI.ts | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/src/client/lcd/api/AllianceAPI.ts b/src/client/lcd/api/AllianceAPI.ts index ea42f32..976a09c 100644 --- a/src/client/lcd/api/AllianceAPI.ts +++ b/src/client/lcd/api/AllianceAPI.ts @@ -7,7 +7,7 @@ import { AllianceUnbonding, AllianceValidator, } from '../../../core/alliance'; -import { AccAddress, Coins, ValAddress } from '../../../core'; +import { AccAddress, Coins, Coin, ValAddress } from '../../../core'; import { APIParams, Pagination, PaginationOptions } from '../APIRequester'; import { LCDClient } from '../LCDClient'; @@ -108,7 +108,7 @@ export class AllianceAPI extends BaseAPI { params: Partial = {} ): Promise<{ delegations: AllianceDelegation[]; - balance: Coins; + balance: Coin; pagination: Pagination; }> { let url = `/terra/alliances/delegations`; @@ -138,7 +138,7 @@ export class AllianceAPI extends BaseAPI { if (delAddr && valAddr && denom) { const res = await this.getReqFromChainID(chainID).get<{ delegation: AllianceDelegation.Data; - balance: Coins.Data; + balance: Coin.Data; }>(url, params); return { @@ -147,19 +147,19 @@ export class AllianceAPI extends BaseAPI { total: 1, }, delegations: [AllianceDelegation.fromData(res.delegation)], - balance: Coins.fromData(res.balance), + balance: Coin.fromData(res.balance), }; } else { const res = await this.getReqFromChainID(chainID).get<{ delegations: AllianceDelegation.Data[]; - balance: Coins.Data; + balance: Coin.Data; pagination: Pagination; }>(url, params); return { pagination: res.pagination, delegations: res.delegations.map(d => AllianceDelegation.fromData(d)), - balance: Coins.fromData(res.balance), + balance: Coin.fromData(res.balance), }; } } From 5bd63ab09f84d828516b1362a6f754f0abcbf383 Mon Sep 17 00:00:00 2001 From: emidev98 Date: Sat, 16 Mar 2024 10:59:28 +0200 Subject: [PATCH 2/4] chore: increase tag version --- package-lock.json | 4 ++-- package.json | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/package-lock.json b/package-lock.json index cee82ca..fe0b577 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1,12 +1,12 @@ { "name": "@terra-money/feather.js", - "version": "3.0.0-beta.1", + "version": "3.0.0-beta.2", "lockfileVersion": 3, "requires": true, "packages": { "": { "name": "@terra-money/feather.js", - "version": "3.0.0-beta.1", + "version": "3.0.0-beta.2", "license": "MIT", "dependencies": { "@terra-money/legacy.proto": "npm:@terra-money/terra.proto@^0.1.7", diff --git a/package.json b/package.json index b8c71a9..edc1fbd 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "@terra-money/feather.js", - "version": "3.0.0-beta.1", + "version": "3.0.0-beta.2", "description": "The JavaScript SDK for Terra and Feather chains", "license": "MIT", "author": "Terraform Labs, PTE.", From 2bc3995670fb27e6efae282f554d21d83502995c Mon Sep 17 00:00:00 2001 From: emidev98 Date: Sun, 17 Mar 2024 09:26:03 +0200 Subject: [PATCH 3/4] fix: alliance delegation model to return delegated balance --- package-lock.json | 4 +- package.json | 2 +- src/client/lcd/api/AllianceAPI.ts | 4 -- .../alliance/models/AllianceDelegation.ts | 60 +++++++++++-------- 4 files changed, 39 insertions(+), 31 deletions(-) diff --git a/package-lock.json b/package-lock.json index fe0b577..79a2f6e 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1,12 +1,12 @@ { "name": "@terra-money/feather.js", - "version": "3.0.0-beta.2", + "version": "3.0.0-beta.3", "lockfileVersion": 3, "requires": true, "packages": { "": { "name": "@terra-money/feather.js", - "version": "3.0.0-beta.2", + "version": "3.0.0-beta.3", "license": "MIT", "dependencies": { "@terra-money/legacy.proto": "npm:@terra-money/terra.proto@^0.1.7", diff --git a/package.json b/package.json index edc1fbd..c1f1d19 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "@terra-money/feather.js", - "version": "3.0.0-beta.2", + "version": "3.0.0-beta.3", "description": "The JavaScript SDK for Terra and Feather chains", "license": "MIT", "author": "Terraform Labs, PTE.", diff --git a/src/client/lcd/api/AllianceAPI.ts b/src/client/lcd/api/AllianceAPI.ts index 976a09c..6b8b1fe 100644 --- a/src/client/lcd/api/AllianceAPI.ts +++ b/src/client/lcd/api/AllianceAPI.ts @@ -108,7 +108,6 @@ export class AllianceAPI extends BaseAPI { params: Partial = {} ): Promise<{ delegations: AllianceDelegation[]; - balance: Coin; pagination: Pagination; }> { let url = `/terra/alliances/delegations`; @@ -138,7 +137,6 @@ export class AllianceAPI extends BaseAPI { if (delAddr && valAddr && denom) { const res = await this.getReqFromChainID(chainID).get<{ delegation: AllianceDelegation.Data; - balance: Coin.Data; }>(url, params); return { @@ -147,7 +145,6 @@ export class AllianceAPI extends BaseAPI { total: 1, }, delegations: [AllianceDelegation.fromData(res.delegation)], - balance: Coin.fromData(res.balance), }; } else { const res = await this.getReqFromChainID(chainID).get<{ @@ -159,7 +156,6 @@ export class AllianceAPI extends BaseAPI { return { pagination: res.pagination, delegations: res.delegations.map(d => AllianceDelegation.fromData(d)), - balance: Coin.fromData(res.balance), }; } } diff --git a/src/core/alliance/models/AllianceDelegation.ts b/src/core/alliance/models/AllianceDelegation.ts index 5d460fc..7d4d533 100644 --- a/src/core/alliance/models/AllianceDelegation.ts +++ b/src/core/alliance/models/AllianceDelegation.ts @@ -15,7 +15,8 @@ export class AllianceDelegation { /** shares define the Alliancedelegation shares received. */ public shares: Dec, public rewardHistory: RewardHistory[], - public lastRewardClaimHeight: Long + public lastRewardClaimHeight: Long, + public balance: Coin ) {} public static fromData( @@ -24,12 +25,15 @@ export class AllianceDelegation { ): AllianceDelegation { _; const { - delegator_address, - validator_address, - denom, - shares, - reward_history, - last_reward_claim_height, + delegation: { + delegator_address, + validator_address, + denom, + shares, + reward_history, + last_reward_claim_height, + }, + balance, } = data; return new AllianceDelegation( @@ -38,7 +42,8 @@ export class AllianceDelegation { denom, new Dec(shares), reward_history?.map(r => RewardHistory.fromData(r)), - last_reward_claim_height + last_reward_claim_height, + Coin.fromData(balance) ); } @@ -51,30 +56,37 @@ export class AllianceDelegation { shares, rewardHistory, lastRewardClaimHeight, + balance, } = this; return { - delegator_address: delegatorAddress, - validator_address: validatorAddress, - denom: denom, - shares: shares.toString(), - reward_history: rewardHistory, - last_reward_claim_height: lastRewardClaimHeight, + delegation: { + delegator_address: delegatorAddress, + validator_address: validatorAddress, + denom: denom, + shares: shares.toString(), + reward_history: rewardHistory, + last_reward_claim_height: lastRewardClaimHeight, + }, + balance: balance.toData(), }; } } export namespace AllianceDelegation { export interface Data { - /** delegator_address is the bech32-encoded address of the delegator. */ - delegator_address: AccAddress; - /** validator_address is the bech32-encoded address of the validator. */ - validator_address: ValAddress; - /** denom of token staked */ - denom: string; - /** shares define the Alliancedelegation shares received. */ - shares: string; - reward_history: RewardHistory.Data[]; - last_reward_claim_height: Long; + delegation: { + /** delegator_address is the bech32-encoded address of the delegator. */ + delegator_address: AccAddress; + /** validator_address is the bech32-encoded address of the validator. */ + validator_address: ValAddress; + /** denom of token staked */ + denom: string; + /** shares define the Alliancedelegation shares received. */ + shares: string; + reward_history: RewardHistory.Data[]; + last_reward_claim_height: Long; + }; + balance: Coin.Data; } } From 2575a9d8081cf70f082f75f48444c2cc31de5b96 Mon Sep 17 00:00:00 2001 From: emidev98 Date: Mon, 18 Mar 2024 18:30:22 +0200 Subject: [PATCH 4/4] fix: imports --- src/client/lcd/api/ICAv1API.ts | 2 +- src/core/alliance/models/AllianceDelegation.ts | 2 +- src/core/alliance/models/AllianceRedelegation.ts | 2 +- src/core/alliance/models/AllianceUnbondings.ts | 2 +- src/core/alliance/models/AllianceValidator.ts | 3 +-- src/core/feemarket/v1/models/FeemarketDenomParams.ts | 2 +- src/core/gov/v1/Proposal.ts | 2 +- 7 files changed, 7 insertions(+), 8 deletions(-) diff --git a/src/client/lcd/api/ICAv1API.ts b/src/client/lcd/api/ICAv1API.ts index 8c2a418..d84014d 100644 --- a/src/client/lcd/api/ICAv1API.ts +++ b/src/client/lcd/api/ICAv1API.ts @@ -4,7 +4,7 @@ import { QueryInterchainAccountResponse } from '@terra-money/terra.proto/ibc/app import { APIParams } from '../APIRequester'; import { LCDClient } from '../LCDClient'; import { BaseAPI } from './BaseAPI'; -import { AccAddress } from 'core'; +import { AccAddress } from '../../../core'; export class ICAv1API extends BaseAPI { constructor(public lcd: LCDClient) { diff --git a/src/core/alliance/models/AllianceDelegation.ts b/src/core/alliance/models/AllianceDelegation.ts index 7d4d533..3055d9d 100644 --- a/src/core/alliance/models/AllianceDelegation.ts +++ b/src/core/alliance/models/AllianceDelegation.ts @@ -1,5 +1,5 @@ import { Dec } from '../../../core/numeric'; -import { AccAddress, ValAddress } from 'core/bech32'; +import { AccAddress, ValAddress } from '../../../core/bech32'; import { RewardHistory } from './RewardHistory'; import Long from 'long'; import { Coin } from '../../../core/Coin'; diff --git a/src/core/alliance/models/AllianceRedelegation.ts b/src/core/alliance/models/AllianceRedelegation.ts index 38d422f..ceab676 100644 --- a/src/core/alliance/models/AllianceRedelegation.ts +++ b/src/core/alliance/models/AllianceRedelegation.ts @@ -1,4 +1,4 @@ -import { AccAddress, ValAddress } from 'core/bech32'; +import { AccAddress, ValAddress } from '../../../core/bech32'; import { Coin } from '../../../core/Coin'; export class AllianceRedelegation { diff --git a/src/core/alliance/models/AllianceUnbondings.ts b/src/core/alliance/models/AllianceUnbondings.ts index 491a52a..ea208d4 100644 --- a/src/core/alliance/models/AllianceUnbondings.ts +++ b/src/core/alliance/models/AllianceUnbondings.ts @@ -1,4 +1,4 @@ -import { ValAddress } from 'core/bech32'; +import { ValAddress } from '../../../core/bech32'; export class AllianceUnbonding { constructor( diff --git a/src/core/alliance/models/AllianceValidator.ts b/src/core/alliance/models/AllianceValidator.ts index e067133..340d308 100644 --- a/src/core/alliance/models/AllianceValidator.ts +++ b/src/core/alliance/models/AllianceValidator.ts @@ -1,5 +1,4 @@ -import { ValAddress } from 'core/bech32'; -import { Coin } from '../../../core/Coin'; +import { ValAddress } from '../../../core/bech32'; import { AllianceValidatorAmount } from './AllianceValidatorAmount'; export class AllianceValidator { diff --git a/src/core/feemarket/v1/models/FeemarketDenomParams.ts b/src/core/feemarket/v1/models/FeemarketDenomParams.ts index 3ac2078..e0476d0 100644 --- a/src/core/feemarket/v1/models/FeemarketDenomParams.ts +++ b/src/core/feemarket/v1/models/FeemarketDenomParams.ts @@ -1,5 +1,5 @@ import { FeeDenomParam as FeeDenomParam_pb } from '@terra-money/terra.proto/feemarket/feemarket/v1/genesis'; -import { Denom } from 'core/Denom'; +import { Denom } from '../../../../core/Denom'; import Decimal from 'decimal.js'; import { JSONSerializable } from '../../../../util/json'; diff --git a/src/core/gov/v1/Proposal.ts b/src/core/gov/v1/Proposal.ts index b8dc763..9e9d05c 100644 --- a/src/core/gov/v1/Proposal.ts +++ b/src/core/gov/v1/Proposal.ts @@ -43,7 +43,7 @@ import { MsgFeeDenomParam, MsgRemoveFeeDenomParam, } from '../../../core/feemarket'; -import { AccAddress } from 'core/bech32'; +import { AccAddress } from '../../../core/bech32'; /** * Stores information pertaining to a submitted proposal, such as its status and time of