Skip to content

Commit

Permalink
Merge pull request #85 from allbridge-io/alpha
Browse files Browse the repository at this point in the history
fix(apr): aprs type number -> string
  • Loading branch information
Kozer4 authored Jun 24, 2024
2 parents 377c9bb + 831adf5 commit b185dfa
Show file tree
Hide file tree
Showing 7 changed files with 21 additions and 21 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@
"decimals": 18,
"symbol": "YARO",
"feeShare": "0.003",
"apr": 0,
"lpRate": 1.00000007,
"apr": "0",
"lpRate": "1.00000007",
"chainSymbol": "TRX",
"chainType": "TRX",
"allbridgeChainId": 4,
Expand Down
14 changes: 7 additions & 7 deletions src/__tests__/utils/calculation/index.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -90,10 +90,10 @@ describe("Calculation", () => {
name: "name",
poolAddress: "poolAddress",
tokenAddress: "tokenAddress",
apr: 0,
apr7d: 0,
apr30d: 0,
lpRate: 0,
apr: "0",
apr7d: "0",
apr30d: "0",
lpRate: "0",
};

describe("Given token with a balanced poolInfo", () => {
Expand Down Expand Up @@ -241,11 +241,11 @@ describe("Calculation", () => {

describe("aprInPercents", () => {
test("convert apr to percent view", () => {
expect(aprInPercents(0.1256)).toEqual("12.56%");
expect(aprInPercents("0.1256")).toEqual("12.56%");
});
test("invalid apr to percent view", () => {
expect(aprInPercents(0)).toEqual("N/A");
expect(aprInPercents(-1)).toEqual("N/A");
expect(aprInPercents("0")).toEqual("N/A");
expect(aprInPercents("-1")).toEqual("N/A");
});
});
});
8 changes: 4 additions & 4 deletions src/client/core-api/core-api.model.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,10 +29,10 @@ export interface TokenDTO {
tokenAddress: string;
poolInfo: PoolInfoDTO;
feeShare: string;
apr: number;
apr7d: number;
apr30d: number;
lpRate: number;
apr: string;
apr7d: string;
apr30d: string;
lpRate: string;
}

export interface PoolInfoDTO {
Expand Down
2 changes: 1 addition & 1 deletion src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -492,7 +492,7 @@ export class AllbridgeCoreSdk {
* @param apr
* @returns aprPercentageView
*/
aprInPercents(apr: number): string {
aprInPercents(apr: string): string {
return this.service.aprInPercents(apr);
}

Expand Down
2 changes: 1 addition & 1 deletion src/services/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -466,7 +466,7 @@ export class AllbridgeCoreSdkService {
return this.api.refreshPoolInfo();
}

aprInPercents(apr: number): string {
aprInPercents(apr: string): string {
return aprInPercents(apr);
}

Expand Down
8 changes: 4 additions & 4 deletions src/tokens-info/tokens-info.model.ts
Original file line number Diff line number Diff line change
Expand Up @@ -88,19 +88,19 @@ export interface Token {
* @Deprecated use {@link apr7d}</br>
* Token APR
*/
apr: number;
apr: string;
/**
* Token APR based on last 7 days
*/
apr7d: number;
apr7d: string;
/**
* Token APR based on last 30 days
*/
apr30d: number;
apr30d: string;
/**
* Token LP rate
*/
lpRate: number;
lpRate: string;
}

/**
Expand Down
4 changes: 2 additions & 2 deletions src/utils/calculation/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -174,8 +174,8 @@ export function getEarned(userLpAmount: string, userRewardDebt: string, accRewar
return rewards.sub(userRewardDebtBN).toString();
}

export function aprInPercents(apr: number): string {
return apr * 100 > 0 ? `${Number(Big(apr).times(100).toFixed(2)).toLocaleString()}%` : "N/A";
export function aprInPercents(apr: string): string {
return Big(apr).gt(0) ? `${Number(Big(apr).times(100).toFixed(2)).toLocaleString()}%` : "N/A";
}

// a = 8Axy(x+y)
Expand Down

0 comments on commit b185dfa

Please sign in to comment.