Skip to content

Commit

Permalink
fix all tests
Browse files Browse the repository at this point in the history
  • Loading branch information
GuillaumeNervoXS committed Apr 23, 2024
1 parent 1b78773 commit dff0dcf
Show file tree
Hide file tree
Showing 4 changed files with 37 additions and 15 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -90,8 +90,9 @@ describe('AngleStakedStable EventPool Mainnet', () => {
dexKey,
network,
dexHelper,
AngleStakedStableConfig[dexKey][network].stEUR,
AngleStakedStableConfig[dexKey][network].EURA,
logger,
AngleStakedStableConfig[dexKey][network],
);
});

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -82,12 +82,14 @@ async function checkOnChainPricing(
);

// No exact computation because of the bigInt approx
// for (let i = 0; i < expectedPrices.length; ++i) {
// expect(prices[i]).toBeGreaterThanOrEqual(expectedPrices[i] - 1n);
// expect(prices[i]).toBeLessThanOrEqual(expectedPrices[i] + 1n);
// }

expect(prices).toEqual(expectedPrices);
for (let i = 0; i < expectedPrices.length; ++i) {
expect(prices[i]).toBeGreaterThanOrEqual(
(expectedPrices[i] * 99999n) / 100000n,
);
expect(prices[i]).toBeLessThanOrEqual(
(expectedPrices[i] * 100001n) / 100000n,
);
}
}

async function testPricingOnNetwork(
Expand Down
33 changes: 25 additions & 8 deletions src/dex/angle-staked-stable/angle-staked-stable-pool.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import { StatefulEventSubscriber } from '../../stateful-event-subscriber';
import type { IDexHelper } from '../../dex-helper/idex-helper';
import type { DexParams, PoolState } from './types';
import StakedStableABI from '../../abi/angle/stagToken.json';
import ERC20ABI from '../../abi/erc20.json';

export class AngleStakedStableEventPool extends StatefulEventSubscriber<PoolState> {
handlers: {
Expand All @@ -22,6 +23,7 @@ export class AngleStakedStableEventPool extends StatefulEventSubscriber<PoolStat
} = {};

static angleStakedStableIface = new Interface(StakedStableABI);
static erc20Iface = new Interface(ERC20ABI);

logDecoder: (log: Log) => any;

Expand All @@ -36,6 +38,7 @@ export class AngleStakedStableEventPool extends StatefulEventSubscriber<PoolStat
protected network: number,
protected dexHelper: IDexHelper,
public stakeToken: string,
public agToken: string,
logger: Logger,
) {
super(parentName, 'Staked_Stable', dexHelper, logger);
Expand Down Expand Up @@ -97,32 +100,39 @@ export class AngleStakedStableEventPool extends StatefulEventSubscriber<PoolStat
} as PoolState;

const multicall = [
{
target: this.agToken,
callData: AngleStakedStableEventPool.erc20Iface.encodeFunctionData(
'balanceOf',
[this.stakeToken],
),
},
{
target: this.stakeToken,
callData:
AngleStakedStableEventPool.angleStakedStableIface.encodeFunctionData(
'totalAssets',
'totalSupply',
),
},
{
target: this.stakeToken,
callData:
AngleStakedStableEventPool.angleStakedStableIface.encodeFunctionData(
'totalSupply',
'lastUpdate',
),
},
{
target: this.stakeToken,
callData:
AngleStakedStableEventPool.angleStakedStableIface.encodeFunctionData(
'lastUpdate',
'paused',
),
},
{
target: this.stakeToken,
callData:
AngleStakedStableEventPool.angleStakedStableIface.encodeFunctionData(
'paused',
'rate',
),
},
];
Expand All @@ -136,8 +146,8 @@ export class AngleStakedStableEventPool extends StatefulEventSubscriber<PoolStat

// Decode
poolState.totalAssets = bigIntify(
AngleStakedStableEventPool.angleStakedStableIface.decodeFunctionResult(
'totalAssets',
AngleStakedStableEventPool.erc20Iface.decodeFunctionResult(
'balanceOf',
returnData[0],
)[0],
);
Expand All @@ -159,6 +169,13 @@ export class AngleStakedStableEventPool extends StatefulEventSubscriber<PoolStat
returnData[3],
)[0] as boolean;

poolState.rate = bigIntify(
AngleStakedStableEventPool.angleStakedStableIface.decodeFunctionResult(
'rate',
returnData[4],
)[0],
);

return poolState;
}

Expand Down Expand Up @@ -204,7 +221,7 @@ export class AngleStakedStableEventPool extends StatefulEventSubscriber<PoolStat
}

_computeUpdatedAssets(amount: bigint, rate: bigint, exp: bigint): bigint {
if (exp === 0n || rate > 0) return amount;
if (exp === 0n || rate === 0n) return amount;
const expMinusOne = exp - 1n;
const expMinusTwo = exp > 2n ? exp - 2n : 0n;
const basePowerTwo = (rate * rate + this.HALF_BASE_27) / this.BASE_27;
Expand Down Expand Up @@ -236,7 +253,7 @@ export class AngleStakedStableEventPool extends StatefulEventSubscriber<PoolStat
log: Readonly<Log>,
blockHeader: BlockHeader,
): DeepReadonly<PoolState> | null {
state.lastUpdate = bigIntify(blockHeader.timestamp);
state.rate = bigIntify(event.args.newRate);
return state;
}

Expand Down
2 changes: 2 additions & 0 deletions src/dex/angle-staked-stable/angle-staked-stable.ts
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,7 @@ export class AngleStakedStable
this.network,
this.dexHelper,
this.config.stEUR,
this.config.EURA,
this.logger,
);
await this.eventPools[this.config.stEUR].initialize(blockNumber);
Expand All @@ -79,6 +80,7 @@ export class AngleStakedStable
this.network,
this.dexHelper,
this.config.stUSD,
this.config.USDA,
this.logger,
);
await this.eventPools[this.config.stUSD].initialize(blockNumber);
Expand Down

0 comments on commit dff0dcf

Please sign in to comment.