Skip to content

Commit

Permalink
fix: USD config
Browse files Browse the repository at this point in the history
  • Loading branch information
GuillaumeNervoXS committed Jun 3, 2024
1 parent 9c9c9e9 commit d174a4f
Show file tree
Hide file tree
Showing 4 changed files with 58 additions and 66 deletions.
86 changes: 31 additions & 55 deletions src/dex/angle-transmuter/angle-transmuter-events.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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);

Expand All @@ -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

Expand Down Expand Up @@ -80,35 +81,21 @@ describe('AngleTransmuter EventPool Mainnet', () => {
const eventsToTestUSD: Record<Address, EventMappings> = {
//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': {
Expand All @@ -129,37 +116,19 @@ 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,
19708213, 19708713, 19708727, 19712712, 19713229, 19714392, 19720091,
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,
Expand All @@ -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(
Expand All @@ -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,
),
Expand All @@ -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,
),
Expand Down
18 changes: 11 additions & 7 deletions src/dex/angle-transmuter/angle-transmuter-pool.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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<PoolState> {
readonly config: PoolConfig;
Expand Down Expand Up @@ -135,12 +136,15 @@ export class AngleTransmuterEventPool extends ComposedEventSubscriber<PoolState>
{},
);

const pythListener = new PythSubscriber<PoolState>(
config.oracles.pyth.proxy,
config.oracles.pyth.ids,
lens<DeepReadonly<PoolState>>().oracles.pyth,
dexHelper.getLogger(`Pyth for ${parentName}-${network}`),
);
let pythListener: PythSubscriber<PoolState>[] = [];
if (!_.isEmpty(config.oracles.pyth)) {
pythListener[0] = new PythSubscriber<PoolState>(
config.oracles.pyth.proxy,
config.oracles.pyth.ids,
lens<DeepReadonly<PoolState>>().oracles.pyth,
dexHelper.getLogger(`Pyth for ${parentName}-${network}`),
);
}

const transmuterListener = new TransmuterSubscriber(
config.stablecoin.address,
Expand All @@ -161,7 +165,7 @@ export class AngleTransmuterEventPool extends ComposedEventSubscriber<PoolState>
...Object.values(redstoneMap),
...Object.values(morphoMap),
transmuterListener,
pythListener,
...pythListener,
],
{
stablecoin: config.stablecoin,
Expand Down
10 changes: 6 additions & 4 deletions src/dex/angle-transmuter/constants.ts
Original file line number Diff line number Diff line change
@@ -1,13 +1,14 @@
import { ethers } from 'ethers';
import { bigIntify } from '../../utils';
import { ChainlinkConfig, PoolConfig, PythConfig } from './types';

export const CBETH = '0xBe9895146f7AF43049ca1c1AE358B0541Ea49704';
export const RETH = '0xae78736Cd615f374D3085123A210448E74Fc6393';
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,
Expand Down Expand Up @@ -50,7 +51,7 @@ export const configEUR = {
},
};

export const configUSD = {
export const configUSD: PoolConfig = {
stablecoin: {
address: '0x0000206329b97DB379d5E1Bf586BbDB969C63274',
decimals: 18,
Expand All @@ -62,6 +63,7 @@ export const configUSD = {
'0xBEEF01735c132Ada46AA9aA4c54623cAA92A64CB',
],
oracles: {
backed: {} as ChainlinkConfig,
chainlink: {
'0x8fFfFfd4AfB6115b954Bd326cbe7B4BA576818f6': {
proxy: '0x8fFfFfd4AfB6115b954Bd326cbe7B4BA576818f6',
Expand All @@ -74,7 +76,7 @@ export const configUSD = {
decimals: 8,
},
},
redstone: {},
redstone: {} as ChainlinkConfig,
morpho: {
'0x025106374196586E8BC91eE8818dD7B0Efd2B78B': {
baseVault: '0xBEEF01735c132Ada46AA9aA4c54623cAA92A64CB',
Expand All @@ -88,6 +90,6 @@ export const configUSD = {
scaleFactor: bigIntify('1000000000000000000'),
},
},
pyth: {},
pyth: {} as PythConfig,
},
};
10 changes: 10 additions & 0 deletions src/dex/angle-transmuter/morphoVault.ts
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,8 @@ export class MorphoVaultSubscriber<State> 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':
Expand Down Expand Up @@ -104,6 +106,14 @@ export class MorphoVaultSubscriber<State> extends PartialEventSubscriber<
return state;
}

handleAccrueFee(
event: ethers.utils.LogDescription,
state: MorphoVaultState,
): DeepReadonly<MorphoVaultState> | null {
state.totalSupply += bigIntify(event.args.feeShares);
return state;
}

handleDeposit(
event: ethers.utils.LogDescription,
state: MorphoVaultState,
Expand Down

0 comments on commit d174a4f

Please sign in to comment.