From d174a4f6c12f403af1ba14299060001966a18756 Mon Sep 17 00:00:00 2001 From: gs8nrv <55771972+GuillaumeNervoXS@users.noreply.github.com> Date: Mon, 3 Jun 2024 19:45:30 +0200 Subject: [PATCH] fix: USD config --- .../angle-transmuter-events.test.ts | 86 +++++++------------ .../angle-transmuter/angle-transmuter-pool.ts | 18 ++-- src/dex/angle-transmuter/constants.ts | 10 ++- src/dex/angle-transmuter/morphoVault.ts | 10 +++ 4 files changed, 58 insertions(+), 66 deletions(-) diff --git a/src/dex/angle-transmuter/angle-transmuter-events.test.ts b/src/dex/angle-transmuter/angle-transmuter-events.test.ts index 7d2836aaf..40514b49f 100644 --- a/src/dex/angle-transmuter/angle-transmuter-events.test.ts +++ b/src/dex/angle-transmuter/angle-transmuter-events.test.ts @@ -9,7 +9,7 @@ import { DummyDexHelper } from '../../dex-helper/index'; import { testEventSubscriber } from '../../../tests/utils-events'; import { PoolState } from './types'; import { DeepReadonly } from 'ts-essentials'; -import { configEUR } from './constants'; +import { configEUR, configUSD } from './constants'; jest.setTimeout(50 * 1000); @@ -29,7 +29,8 @@ describe('AngleTransmuter EventPool Mainnet', () => { const network = Network.MAINNET; const dexHelper = new DummyDexHelper(network); const logger = dexHelper.getLogger(dexKey); - let angleTransmuterPool: AngleTransmuterEventPool; + let angleTransmuterPoolEUR: AngleTransmuterEventPool; + let angleTransmuterPoolUSD: AngleTransmuterEventPool; // poolAddress -> EventMappings @@ -80,35 +81,21 @@ describe('AngleTransmuter EventPool Mainnet', () => { const eventsToTestUSD: Record = { //Transmuter Events '0x222222fD79264BBE280b4986F6FEfBC3524d0137': { - // FeesSet: [ - // 19539192, - // 19539193, 19539198, 19539199 - // ], - // RedemptionCurveParamsSet: [], - // OracleSet: [19539189, 19539191, 19539197], + FeesSet: [19539198, 19539199], + RedemptionCurveParamsSet: [], + OracleSet: [], Swap: [ - 19609442, 19609442, 19612088, 19612720, 19612970, 19613233, 19613417, - 19613466, 19614093, 19615163, 19615653, 19616187, 19616247, 19616257, - 19616459, 19616597, 19616723, 19616850, 19616966, 19616990, 19617295, - 19617327, 19617327, 19617335, 19617394, 19617406, 19617508, 19617521, - 19617543, 19618077, 19618185, 19618395, 19619660, 19619853, 19620424, - 19620631, 19620917, 19620950, 19621140, 19621187, 19621308, 19622224, - 19622628, 19622951, 19622974, 19623084, 19623835, 19624153, 19624153, - 19624236, 19624376, 19624955, 19625166, 19625524, 19625679, 19627173, - 19627831, 19628073, 19628437, 19629497, 19630262, 19630452, 19630453, - 19630569, 19630846, 19630998, 19631045, 19631072, 19631089, 19631277, - 19631526, 19631561, 19631603, 19631653, 19631772, 19631838, 19632250, - 19633153, 19633215, 19633259, 19633531, 19633556, 19633605, 19634664, - 19634767, 19635043, 19635866, 19636522, 19636596, 19637181, 19637803, - 19637913, 19638541, 19639245, 19639420, 19639420, 19639995, 19640181, - 19640895, + 19628073, 19628437, 19629497, 19630262, 19630452, 19630569, 19630846, + 19630998, 19631045, 19631072, 19631526, 19631561, 19631603, 19631653, + 19632250, 19633153, 19633531, 19633556, 19633605, 19634664, 19635866, + 19636522, 19636596, 19637181, 19637803, 19637913, 19638541, 19640895, ], - // Redeemed: [], - // ReservesAdjusted: [], - // CollateralAdded: [19539190, 19539196], - // CollateralRevoked: [], - // CollateralWhitelistStatusUpdated: [19539202], - // WhitelistStatusToggled: [], + Redeemed: [], + ReservesAdjusted: [], + CollateralAdded: [], + CollateralRevoked: [], + CollateralWhitelistStatusUpdated: [], + WhitelistStatusToggled: [], }, // Chainlink '0x8fFfFfd4AfB6115b954Bd326cbe7B4BA576818f6': { @@ -129,16 +116,6 @@ describe('AngleTransmuter EventPool Mainnet', () => { // Morpho '0xBEEF01735c132Ada46AA9aA4c54623cAA92A64CB': { UpdateLastTotalAssets: [ - 19581667, 19582915, 19585628, 19587407, 19588157, 19588208, 19590069, - 19590733, 19590797, 19592697, 19593362, 19593473, 19594011, 19595306, - 19596519, 19597364, 19599063, 19599206, 19602087, 19602936, 19603096, - 19603429, 19608399, 19608426, 19610964, 19612913, 19617893, 19618624, - 19619754, 19620051, 19621535, 19623267, 19624153, 19624164, 19629126, - 19630421, 19630643, 19630671, 19631025, 19633145, 19637639, 19638537, - 19638655, 19639050, 19639147, 19639164, 19639420, 19641771, 19642216, - 19643013, 19644465, 19646888, 19648977, 19649555, 19649742, 19651107, - 19651169, 19651577, 19652313, 19652647, 19657982, 19660275, 19662862, - 19667407, 19669210, 19669302, 19670406, 19674048, 19676127, 19677576, 19680251, 19680544, 19681017, 19682815, 19689659, 19689880, 19692533, 19697311, 19697903, 19698704, 19698867, 19701099, 19701428, 19702068, 19703302, 19703569, 19704999, 19705931, 19705954, 19706402, 19706567, @@ -146,20 +123,12 @@ describe('AngleTransmuter EventPool Mainnet', () => { 19720560, 19722127, ], Deposit: [ - 19582915, 19587407, 19588157, 19588208, 19590797, 19592697, 19593362, - 19594011, 19599063, 19602087, 19603096, 19610964, 19612913, 19618624, - 19620051, 19624153, 19629126, 19630421, 19630643, 19630671, 19633145, - 19638537, 19638655, 19639050, 19639147, 19639420, 19652647, 19657982, - 19660275, 19670406, 19674048, 19677576, 19689880, 19692533, 19697311, 19697903, 19698704, 19698867, 19701099, 19701428, 19702068, 19703302, 19703569, 19705931, 19705954, 19706402, 19706567, 19708213, 19708713, 19708727, 19713229, 19714392, 19720091, 19720560, 19722127, 19723842, 19724873, 19724886, 19727258, 19727832, 19727836, 19727900, ], Withdraw: [ - 19581667, 19585628, 19590069, 19590733, 19593473, 19595306, 19596519, - 19597364, 19599206, 19602936, 19603429, 19608399, 19608426, 19617893, - 19619754, 19621535, 19623267, 19624164, 19631025, 19637639, 19639164, 19641771, 19642216, 19643013, 19644465, 19646888, 19648977, 19649555, 19649742, 19651107, 19651169, 19651577, 19652313, 19662862, 19667407, 19669210, 19669302, 19676127, 19680251, 19680544, 19681017, 19682815, @@ -169,13 +138,20 @@ describe('AngleTransmuter EventPool Mainnet', () => { }; beforeEach(async () => { - angleTransmuterPool = new AngleTransmuterEventPool( - dexKey, + angleTransmuterPoolEUR = new AngleTransmuterEventPool( + `${dexKey}_EUR`, network, dexHelper, logger, configEUR, ); + angleTransmuterPoolUSD = new AngleTransmuterEventPool( + `${dexKey}_EUR`, + network, + dexHelper, + logger, + configUSD, + ); }); Object.entries(eventsToTestEUR).forEach( @@ -187,11 +163,11 @@ describe('AngleTransmuter EventPool Mainnet', () => { blockNumbers.forEach((blockNumber: number) => { it(`State after ${blockNumber}`, async () => { await testEventSubscriber( - angleTransmuterPool, - angleTransmuterPool.addressesSubscribed, + angleTransmuterPoolEUR, + angleTransmuterPoolEUR.addressesSubscribed, (_blockNumber: number) => fetchPoolState( - angleTransmuterPool, + angleTransmuterPoolEUR, _blockNumber, poolAddress, ), @@ -217,11 +193,11 @@ describe('AngleTransmuter EventPool Mainnet', () => { blockNumbers.forEach((blockNumber: number) => { it(`State after ${blockNumber}`, async () => { await testEventSubscriber( - angleTransmuterPool, - angleTransmuterPool.addressesSubscribed, + angleTransmuterPoolUSD, + angleTransmuterPoolUSD.addressesSubscribed, (_blockNumber: number) => fetchPoolState( - angleTransmuterPool, + angleTransmuterPoolUSD, _blockNumber, poolAddress, ), diff --git a/src/dex/angle-transmuter/angle-transmuter-pool.ts b/src/dex/angle-transmuter/angle-transmuter-pool.ts index 7609064c0..6d376e002 100644 --- a/src/dex/angle-transmuter/angle-transmuter-pool.ts +++ b/src/dex/angle-transmuter/angle-transmuter-pool.ts @@ -44,6 +44,7 @@ import { BLOCK_UPGRADE_ORACLE } from './constants'; import { MorphoOracleEventPool } from './morphoOracle'; import { bigIntify } from '../../utils'; import { MorphoVaultSubscriber } from './morphoVault'; +import _ from 'lodash'; export class AngleTransmuterEventPool extends ComposedEventSubscriber { readonly config: PoolConfig; @@ -135,12 +136,15 @@ export class AngleTransmuterEventPool extends ComposedEventSubscriber {}, ); - const pythListener = new PythSubscriber( - config.oracles.pyth.proxy, - config.oracles.pyth.ids, - lens>().oracles.pyth, - dexHelper.getLogger(`Pyth for ${parentName}-${network}`), - ); + let pythListener: PythSubscriber[] = []; + if (!_.isEmpty(config.oracles.pyth)) { + pythListener[0] = new PythSubscriber( + config.oracles.pyth.proxy, + config.oracles.pyth.ids, + lens>().oracles.pyth, + dexHelper.getLogger(`Pyth for ${parentName}-${network}`), + ); + } const transmuterListener = new TransmuterSubscriber( config.stablecoin.address, @@ -161,7 +165,7 @@ export class AngleTransmuterEventPool extends ComposedEventSubscriber ...Object.values(redstoneMap), ...Object.values(morphoMap), transmuterListener, - pythListener, + ...pythListener, ], { stablecoin: config.stablecoin, diff --git a/src/dex/angle-transmuter/constants.ts b/src/dex/angle-transmuter/constants.ts index 94fde78be..5feab5fa4 100644 --- a/src/dex/angle-transmuter/constants.ts +++ b/src/dex/angle-transmuter/constants.ts @@ -1,5 +1,6 @@ import { ethers } from 'ethers'; import { bigIntify } from '../../utils'; +import { ChainlinkConfig, PoolConfig, PythConfig } from './types'; export const CBETH = '0xBe9895146f7AF43049ca1c1AE358B0541Ea49704'; export const RETH = '0xae78736Cd615f374D3085123A210448E74Fc6393'; @@ -7,7 +8,7 @@ export const STETH = '0xae7ab96520DE3A18E5e111B5EaAb095312D7fE84'; export const SFRXETH = '0xac3E018457B222d93114458476f3E3416Abbe38F'; export const BLOCK_UPGRADE_ORACLE = 19567142; -export const configEUR = { +export const configEUR: PoolConfig = { stablecoin: { address: '0x1a7e4e63778B4f12a199C062f3eFdD288afCBce8', decimals: 18, @@ -50,7 +51,7 @@ export const configEUR = { }, }; -export const configUSD = { +export const configUSD: PoolConfig = { stablecoin: { address: '0x0000206329b97DB379d5E1Bf586BbDB969C63274', decimals: 18, @@ -62,6 +63,7 @@ export const configUSD = { '0xBEEF01735c132Ada46AA9aA4c54623cAA92A64CB', ], oracles: { + backed: {} as ChainlinkConfig, chainlink: { '0x8fFfFfd4AfB6115b954Bd326cbe7B4BA576818f6': { proxy: '0x8fFfFfd4AfB6115b954Bd326cbe7B4BA576818f6', @@ -74,7 +76,7 @@ export const configUSD = { decimals: 8, }, }, - redstone: {}, + redstone: {} as ChainlinkConfig, morpho: { '0x025106374196586E8BC91eE8818dD7B0Efd2B78B': { baseVault: '0xBEEF01735c132Ada46AA9aA4c54623cAA92A64CB', @@ -88,6 +90,6 @@ export const configUSD = { scaleFactor: bigIntify('1000000000000000000'), }, }, - pyth: {}, + pyth: {} as PythConfig, }, }; diff --git a/src/dex/angle-transmuter/morphoVault.ts b/src/dex/angle-transmuter/morphoVault.ts index f77a63522..4f90209d6 100644 --- a/src/dex/angle-transmuter/morphoVault.ts +++ b/src/dex/angle-transmuter/morphoVault.ts @@ -40,6 +40,8 @@ export class MorphoVaultSubscriber extends PartialEventSubscriber< switch (parsed.name) { case 'UpdateLastTotalAssets': return this.handleUpdateLastTotalAssets(parsed, _state); + case 'AccrueInterest': + return this.handleAccrueFee(parsed, _state); case 'Deposit': return this.handleDeposit(parsed, _state); case 'Withdraw': @@ -104,6 +106,14 @@ export class MorphoVaultSubscriber extends PartialEventSubscriber< return state; } + handleAccrueFee( + event: ethers.utils.LogDescription, + state: MorphoVaultState, + ): DeepReadonly | null { + state.totalSupply += bigIntify(event.args.feeShares); + return state; + } + handleDeposit( event: ethers.utils.LogDescription, state: MorphoVaultState,