Skip to content

Commit 64146b8

Browse files
author
Joe Andrews
authored
fix currentYield on element-bridge-data getter (#72)
1 parent ffab86d commit 64146b8

File tree

2 files changed

+7
-8
lines changed

2 files changed

+7
-8
lines changed

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@
3030
"rootDir": "./src"
3131
},
3232
"name": "@aztec/bridge-clients",
33-
"version": "0.1.39",
33+
"version": "0.1.40",
3434
"description": "This repo contains the solidity files and typescript helper class for all of the Aztec Connect Bridge Contracts",
3535
"repository": "[email protected]:AztecProtocol/aztec-connect-bridges.git",
3636
"license": "MIT",

src/client/element/element-bridge-data.ts

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -226,17 +226,16 @@ export class ElementBridgeData implements BridgeDataFieldGetters {
226226
return [];
227227
}
228228

229-
const latestBlock = await this.getCurrentBlock();
229+
const YEAR = 60n * 60n * 24n * 365n;
230230

231-
const now = latestBlock.timestamp;
232231
const totalInterest = endValue.toBigInt() - defiEvent.totalInputValue;
233-
const elapsedTime = BigInt(now - defiEvent.timestamp);
234232
const totalTime = exitTimestamp.toBigInt() - BigInt(defiEvent.timestamp);
235-
const timeRatio = divide(elapsedTime, totalTime, this.scalingFactor);
236-
const accruedInterst = (totalInterest * timeRatio) / this.scalingFactor;
233+
const interestPerSecondScaled = divide(totalInterest, totalTime, this.scalingFactor);
234+
const yearlyInterest = (interestPerSecondScaled * YEAR) / this.scalingFactor;
237235

238-
const currentYield = (defiEvent.totalInputValue / (defiEvent.totalInputValue + accruedInterst)) * 100n;
239-
return [Number(currentYield)];
236+
const percentageScaled = divide(yearlyInterest, defiEvent.totalInputValue, this.scalingFactor);
237+
const percentage2sf = (percentageScaled * 10000n) / this.scalingFactor;
238+
return [Number(percentage2sf) / 100];
240239
}
241240

242241
async getAuxData(

0 commit comments

Comments
 (0)