Skip to content

Commit 69a666a

Browse files
author
Joe Andrews
authored
Ja/fix typo (#66)
* Fix typo * use types from npm barrentenberg * fix element yield * add missing provider
1 parent d4ba24f commit 69a666a

File tree

4 files changed

+13
-10
lines changed

4 files changed

+13
-10
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.38",
33+
"version": "0.1.39",
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",
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
11
import { Web3Provider } from '@ethersproject/providers';
2-
import { EthereumProvider } from './ethereum_provider';
2+
import { EthereumProvider } from '@aztec/barretenberg/blockchain';
33

44
export const createWeb3Provider = (ethereumProvider: EthereumProvider) => new Web3Provider(ethereumProvider);

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

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -221,13 +221,13 @@ describe('element bridge data', () => {
221221
expect(expiration).toBe(BigInt(endDate));
222222
});
223223

224-
it('should return the correct yearly output of the tranche', async () => {
224+
it('should return the correct yield of the tranche', async () => {
225225
const now = Math.floor(Date.now() / 1000);
226226
const expiry = BigInt(now + 86400 * 30);
227227
const trancheAddress = '0x90ca5cef5b29342b229fb8ae2db5d8f4f894d652';
228228
const poolId = '0x90ca5cef5b29342b229fb8ae2db5d8f4f894d6520002000000000000000000b5';
229-
const interest = 100000n;
230-
const inputValue = 10e18,
229+
const interest = BigInt(1e16);
230+
const inputValue = BigInt(10e18),
231231
elementBridge = {
232232
hashAssetAndExpiry: jest.fn().mockResolvedValue('0xa'),
233233
pools: jest.fn().mockResolvedValue([trancheAddress, '', poolId]),
@@ -240,9 +240,7 @@ describe('element bridge data', () => {
240240
balancerContract = {
241241
...balancerContract,
242242
queryBatchSwap: jest.fn().mockImplementation((...args) => {
243-
const amount = args[1][0].amount;
244-
245-
return Promise.resolve([BigNumber.from(BigInt(amount)), BigNumber.from(-BigInt(BigInt(amount) + interest))]);
243+
return Promise.resolve([BigNumber.from(inputValue), BigNumber.from(-BigInt(inputValue + interest))]);
246244
}),
247245
};
248246

@@ -279,8 +277,11 @@ describe('element bridge data', () => {
279277
const timeToExpiration = expiry - BigInt(now);
280278
const scaledOut = (BigInt(interest) * elementBridgeData.scalingFactor) / timeToExpiration;
281279
const yearlyOut = (scaledOut * BigInt(YEAR)) / elementBridgeData.scalingFactor;
280+
const scaledPercentage = (yearlyOut * elementBridgeData.scalingFactor) / inputValue;
281+
const percentage2sf = scaledPercentage / (elementBridgeData.scalingFactor / 10000n);
282+
const percent = Number(percentage2sf) / 100;
282283

283-
expect(output[0]).toBe(Number((BigInt(inputValue) / (yearlyOut + BigInt(inputValue))) * 100n));
284+
expect(output[0]).toBe(percent);
284285
});
285286

286287
it('should return the correct market size for a given tranche', async () => {

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

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -318,8 +318,10 @@ export class ElementBridgeData implements BridgeDataFieldGetters {
318318
const interest = -outputAssetAValue.toBigInt() - precision;
319319
const scaledOutput = divide(interest, timeToExpiration, this.scalingFactor);
320320
const yearlyOutput = (scaledOutput * YEAR) / this.scalingFactor;
321+
const percentageScaled = divide(yearlyOutput, precision, this.scalingFactor);
322+
const percentage2sf = (percentageScaled * 10000n) / this.scalingFactor;
321323

322-
return [Number((precision * this.scalingFactor) / (yearlyOutput + precision) / this.scalingFactor / 10000n) / 100];
324+
return [Number(percentage2sf) / 100];
323325
}
324326

325327
async getMarketSize(

0 commit comments

Comments
 (0)