Skip to content

Commit

Permalink
chore(fee): Calculate APY using optional exchange rate param
Browse files Browse the repository at this point in the history
  • Loading branch information
daniel-savu committed Apr 7, 2021
1 parent d191679 commit 83ad194
Showing 1 changed file with 9 additions and 9 deletions.
18 changes: 9 additions & 9 deletions src/parachain/fee.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,10 +23,10 @@ export interface FeeAPI {
* @param feesPolkaBTC Satoshi value representing the BTC fees accrued
* @param feesDOT Planck value representing the DOT fees accrued
* @param lockedDOT Planck value representing the value locked to gain yield
* @param dotToBtcRate Conversion rate
* @param dotToBtcRate (Optional) Conversion rate of the large denominations (DOT/BTC as opposed to Planck/Satoshi)
* @returns The APY, given the parameters
*/
calculateAPY(feesPolkaBTC: Big, feesDOT: Big, lockedDOT: Big): Promise<string>;
calculateAPY(feesPolkaBTC: Big, feesDOT: Big, lockedDOT: Big, dotToBtcRate?: Big): Promise<string>;
/**
* @returns The griefing collateral rate for issuing PolkaBTC
*/
Expand Down Expand Up @@ -70,14 +70,14 @@ export class DefaultFeeAPI implements FeeAPI {
return new Big(decodeFixedPointType(griefingCollateralRate));
}

async calculateAPY(feesPolkaBTC: Big, feesDOT: Big, lockedDOT: Big): Promise<string> {
const dotToBtcRate = await this.oracleAPI.getExchangeRate();
const feesPolkaBTCBig = new Big(feesPolkaBTC);
const feesPolkaBTCInDot = feesPolkaBTCBig.mul(dotToBtcRate);
const totalFees = new Big(feesDOT).add(feesPolkaBTCInDot);
const lockedDotBig = new Big(lockedDOT);
async calculateAPY(feesPolkaBTC: Big, feesDOT: Big, lockedDOT: Big, dotToBtcRate?: Big): Promise<string> {
if(dotToBtcRate === undefined) {
dotToBtcRate = await this.oracleAPI.getExchangeRate();
}
const feesPolkaBTCInDot = feesPolkaBTC.mul(dotToBtcRate);
const totalFees = feesDOT.add(feesPolkaBTCInDot);

// convert to percent
return totalFees.div(lockedDotBig).mul(100).toString();
return totalFees.div(lockedDOT).mul(100).toString();
}
}

0 comments on commit 83ad194

Please sign in to comment.