Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: alliance delegation model does not need to be coins #88

Open
wants to merge 4 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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/feather.js",
"version": "3.0.0-beta.1",
"version": "3.0.0-beta.3",
"description": "The JavaScript SDK for Terra and Feather chains",
"license": "MIT",
"author": "Terraform Labs, PTE.",
Expand Down
8 changes: 2 additions & 6 deletions src/client/lcd/api/AllianceAPI.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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';

Expand Down Expand Up @@ -108,7 +108,6 @@ export class AllianceAPI extends BaseAPI {
params: Partial<PaginationOptions & APIParams> = {}
): Promise<{
delegations: AllianceDelegation[];
balance: Coins;
pagination: Pagination;
}> {
let url = `/terra/alliances/delegations`;
Expand Down Expand Up @@ -138,7 +137,6 @@ export class AllianceAPI extends BaseAPI {
if (delAddr && valAddr && denom) {
const res = await this.getReqFromChainID(chainID).get<{
delegation: AllianceDelegation.Data;
balance: Coins.Data;
}>(url, params);

return {
Expand All @@ -147,19 +145,17 @@ export class AllianceAPI extends BaseAPI {
total: 1,
},
delegations: [AllianceDelegation.fromData(res.delegation)],
balance: Coins.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),
};
}
}
Expand Down
2 changes: 1 addition & 1 deletion src/client/lcd/api/ICAv1API.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down
62 changes: 37 additions & 25 deletions src/core/alliance/models/AllianceDelegation.ts
Original file line number Diff line number Diff line change
@@ -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';
Expand All @@ -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(
Expand All @@ -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(
Expand All @@ -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)
);
}

Expand All @@ -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;
}
}
2 changes: 1 addition & 1 deletion src/core/alliance/models/AllianceRedelegation.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { AccAddress, ValAddress } from 'core/bech32';
import { AccAddress, ValAddress } from '../../../core/bech32';
import { Coin } from '../../../core/Coin';

export class AllianceRedelegation {
Expand Down
2 changes: 1 addition & 1 deletion src/core/alliance/models/AllianceUnbondings.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { ValAddress } from 'core/bech32';
import { ValAddress } from '../../../core/bech32';

export class AllianceUnbonding {
constructor(
Expand Down
3 changes: 1 addition & 2 deletions src/core/alliance/models/AllianceValidator.ts
Original file line number Diff line number Diff line change
@@ -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 {
Expand Down
2 changes: 1 addition & 1 deletion src/core/feemarket/v1/models/FeemarketDenomParams.ts
Original file line number Diff line number Diff line change
@@ -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';

Expand Down
2 changes: 1 addition & 1 deletion src/core/gov/v1/Proposal.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Loading