Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Yieldnest #806

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1,027 changes: 1,027 additions & 0 deletions src/abi/ynETH.json

Large diffs are not rendered by default.

2 changes: 2 additions & 0 deletions src/dex/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,7 @@ import { LitePsm } from './lite-psm/lite-psm';
import { UsualBond } from './usual-bond/usual-bond';
import { StkGHO } from './stkgho/stkgho';
import { SkyConverter } from './sky-converter/sky-converter';
import { Yieldnest } from './yieldnest/yieldnest';

const LegacyDexes = [
CurveV2,
Expand Down Expand Up @@ -177,6 +178,7 @@ const Dexes = [
UsualBond,
StkGHO,
SkyConverter,
Yieldnest,
];

export type LegacyDexConstructor = new (dexHelper: IDexHelper) => IDexTxBuilder<
Expand Down
28 changes: 28 additions & 0 deletions src/dex/yieldnest/config.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
import { Network, SwapSide } from '../../constants';
import { DexConfigMap } from '../../types';
import { Yieldnest } from './yieldnest';

type DexParams = {
ynETH: `0x${string}`;
};

export const YieldnestConfig: DexConfigMap<DexParams> = {
Yieldnest: {
[Network.MAINNET]: {
ynETH: '0x14dc3d915107dca9ed39e29e14fbdfe4358a1346',
},
},
};

export const Adapters: {
[chainId: number]: { [side: string]: { name: string; index: number }[] };
} = {
[Network.MAINNET]: {
[SwapSide.SELL]: [
{
name: '',
index: 0,
},
],
},
};
3 changes: 3 additions & 0 deletions src/dex/yieldnest/type.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
export type YNETHPoolState = {
ynETHToETHRateFixed: bigint;
};
33 changes: 33 additions & 0 deletions src/dex/yieldnest/utils.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
import { Contract } from 'web3-eth-contract';
import { YNETHPoolState } from './type';
import { Interface, AbiCoder } from '@ethersproject/abi';
import { BigNumber } from 'ethers';

const coder = new AbiCoder();

export async function getOnChainStateYnETH(
multiContract: Contract,
poolAddress: string,
poolInterface: Interface,
blockNumber: number | 'latest',
): Promise<YNETHPoolState> {
const data: { returnData: any[] } = await multiContract.methods
.aggregate([
{
target: poolAddress,
callData: poolInterface.encodeFunctionData('previewDeposit', [
BigNumber.from(10).pow(18),
]),
},
])
.call({}, blockNumber);

const decodedData = coder.decode(['uint256'], data.returnData[0]);

const ETHToynETHRateFixed = BigInt(decodedData[0].toString());
const ynETHToETHRateFixed = 1n / ETHToynETHRateFixed;

return {
ynETHToETHRateFixed,
};
}
49 changes: 49 additions & 0 deletions src/dex/yieldnest/yieldnest-e2e.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
import dotenv from 'dotenv';
dotenv.config();

import { testE2E } from '../../../tests/utils-e2e';
import { Tokens, Holders } from '../../../tests/constants-e2e';
import { Network, ContractMethod, SwapSide } from '../../constants';
import { StaticJsonRpcProvider } from '@ethersproject/providers';
import { generateConfig } from '../../config';

describe('Yieldnest', () => {
const network = Network.MAINNET;
const tokens = Tokens[network];
const holders = Holders[network];
const provider = new StaticJsonRpcProvider(
generateConfig(network).privateHttpProvider,
network,
);
const dexKey = 'Yieldnest';

[ContractMethod.swapExactAmountIn].forEach(contractMethod => {
it(`${contractMethod} - ETH -> ynETH`, async () => {
await testE2E(
tokens.ETH,
tokens.ynETH,
holders.ETH,
'1000000000000000000',
SwapSide.SELL,
dexKey,
contractMethod,
network,
provider,
);
});

it(`${contractMethod} - WETH -> ynETH`, async () => {
await testE2E(
tokens.WETH,
tokens.ynETH,
holders.WETH,
'1000000000000000000',
SwapSide.SELL,
dexKey,
contractMethod,
network,
provider,
);
});
});
});
Loading