Skip to content

Commit

Permalink
Merge pull request #857 from johngrantuk/fix-erc4626-rates
Browse files Browse the repository at this point in the history
Fix erc4626 rates
  • Loading branch information
KanievskyiDanylo authored Dec 16, 2024
2 parents c1d7c84 + 8962e8e commit cdf8b62
Show file tree
Hide file tree
Showing 8 changed files with 405 additions and 29 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@paraswap/dex-lib",
"version": "4.0.4",
"version": "4.0.5",
"main": "build/index.js",
"types": "build/index.d.ts",
"repository": "https://github.com/paraswap/paraswap-dex-lib",
Expand Down
36 changes: 30 additions & 6 deletions src/dex/balancer-v3/balancer-v3-e2e.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -216,8 +216,8 @@ describe('BalancerV3 E2E', () => {
const tokenASymbol: string = 'WXDAI';
const tokenBSymbol: string = 'COW';

const tokenAAmount: string = '1000000000000000000';
const tokenBAmount: string = '1000000000000000000';
const tokenAAmount: string = '100000000000000000';
const tokenBAmount: string = '100000000000000000';
const nativeTokenAmount = '100000000000000';

testForNetwork(
Expand All @@ -233,12 +233,12 @@ describe('BalancerV3 E2E', () => {
});

describe('Weighed Path', () => {
const tokenASymbol: string = 'USDCe';
const tokenBSymbol: string = 'sDAI';
const tokenASymbol: string = 'sDAI';
const tokenBSymbol: string = 'XDAI';

const tokenAAmount: string = '1000000';
const tokenAAmount: string = '100000000000000000';
const tokenBAmount: string = '100000000000000000';
const nativeTokenAmount = '0';
const nativeTokenAmount = '100000000000000000';

testForNetwork(
network,
Expand Down Expand Up @@ -272,4 +272,28 @@ describe('BalancerV3 E2E', () => {
);
});
});

describe('Mainnet', () => {
const network = Network.MAINNET;

describe('Stable Path', () => {
const tokenASymbol: string = 'wUSDL';
const tokenBSymbol: string = 'USDC';

const tokenAAmount: string = '1000000000000000000';
const tokenBAmount: string = '10000000';
const nativeTokenAmount = '0';

testForNetwork(
network,
dexKey,
tokenASymbol,
tokenBSymbol,
tokenAAmount,
tokenBAmount,
nativeTokenAmount,
false,
);
});
});
});
230 changes: 229 additions & 1 deletion src/dex/balancer-v3/balancer-v3-integration.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -187,7 +187,7 @@ async function checkOnChainPricingNonMulti(
// test match for each returned price
for (const price of prices) {
let expectedPrices: bigint[] = [];
if (price.data.steps.length === 1)
if (price.data.steps.length === 1 && !price.data.steps[0].isBuffer)
expectedPrices = await querySinglePathPrices(
network,
side,
Expand Down Expand Up @@ -831,6 +831,234 @@ describe('BalancerV3', function () {
}
});
});

describe('Buffer, Nested Rate', () => {
/*
The Gnosis pool, 0x272d6be442e30d7c87390edeb9b96f1e84cecd8d uses a rate provider that is nested.
So unwrap rate does not equal rate between aave wsteth and eth.
This particular case the rate provider accounts for growth of wsteth in terms of weth and the additional aave yield.
This highlighted that rateProvider can not be used for buffer wrap/unwrap which instead should use erc4626 rate.
*/
const dexHelper = new DummyDexHelper(network);

const tokens = Tokens[network];
const srcTokenSymbol = 'wstETH';
const destTokenSymbol = 'waGnowstETH';

const amountsForSell = [
0n,
1n * BI_POWS[tokens[srcTokenSymbol].decimals],
100n * BI_POWS[tokens[srcTokenSymbol].decimals],
];

const amountsForBuy = [
0n,
1n * BI_POWS[tokens[destTokenSymbol].decimals],
100n * BI_POWS[tokens[destTokenSymbol].decimals],
];

beforeAll(async () => {
blockNumber = await dexHelper.web3Provider.eth.getBlockNumber();
balancerV3 = new BalancerV3(network, dexKey, dexHelper);
if (balancerV3.initializePricing) {
await balancerV3.initializePricing(blockNumber);
}
});

it('getPoolIdentifiers and getPricesVolume SELL', async function () {
await testPricingOnNetwork(
balancerV3,
network,
dexKey,
blockNumber,
srcTokenSymbol,
destTokenSymbol,
SwapSide.SELL,
amountsForSell,
);
});

it('getPoolIdentifiers and getPricesVolume BUY', async function () {
await testPricingOnNetwork(
balancerV3,
network,
dexKey,
blockNumber,
srcTokenSymbol,
destTokenSymbol,
SwapSide.BUY,
amountsForBuy,
);
});
});
});

describe('Mainnet', () => {
const network = Network.MAINNET;
describe('Token/Underlying With Different Decimals', () => {
/*
Mainnet Pool, 0x5dd88b3aa3143173eb26552923922bdf33f50949 has an ERC4626 token with 18 decimals that uses a 6 decimal underlying.
Note for maths: Instead of manually adding support for each ERC4626 implementation (e.g. stata with Ray maths) we always use an
18 decimal scaled rate and do 18 decimal maths to convert. We may end up loosing 100% accuracy but thats deemed acceptable.
*/
describe.only('Buffer wrap 6decimal>18decimal', () => {
const dexHelper = new DummyDexHelper(network);

const tokens = Tokens[network];
const srcTokenSymbol = 'USDC';
const destTokenSymbol = 'steakUSDC';

const amountsForSell = [
0n,
1n * BI_POWS[tokens[srcTokenSymbol].decimals],
10n * BI_POWS[tokens[srcTokenSymbol].decimals],
];

const amountsForBuy = [
0n,
1n * BI_POWS[tokens[destTokenSymbol].decimals],
10n * BI_POWS[tokens[destTokenSymbol].decimals],
];

beforeAll(async () => {
blockNumber = await dexHelper.web3Provider.eth.getBlockNumber();
balancerV3 = new BalancerV3(network, dexKey, dexHelper);
if (balancerV3.initializePricing) {
await balancerV3.initializePricing(blockNumber);
}
});

it('getPoolIdentifiers and getPricesVolume SELL', async function () {
await testPricingOnNetwork(
balancerV3,
network,
dexKey,
blockNumber,
srcTokenSymbol,
destTokenSymbol,
SwapSide.SELL,
amountsForSell,
);
});

it('getPoolIdentifiers and getPricesVolume BUY', async function () {
await testPricingOnNetwork(
balancerV3,
network,
dexKey,
blockNumber,
srcTokenSymbol,
destTokenSymbol,
SwapSide.BUY,
amountsForBuy,
);
});
});
describe('Buffer unwrap 18decimal>6decimal', () => {
const dexHelper = new DummyDexHelper(network);

const tokens = Tokens[network];
const srcTokenSymbol = 'steakUSDC';
const destTokenSymbol = 'USDC';

const amountsForSell = [
0n,
1n * BI_POWS[tokens[srcTokenSymbol].decimals],
10n * BI_POWS[tokens[srcTokenSymbol].decimals],
];

const amountsForBuy = [
0n,
1n * BI_POWS[tokens[destTokenSymbol].decimals],
10n * BI_POWS[tokens[destTokenSymbol].decimals],
];

beforeAll(async () => {
blockNumber = await dexHelper.web3Provider.eth.getBlockNumber();
balancerV3 = new BalancerV3(network, dexKey, dexHelper);
if (balancerV3.initializePricing) {
await balancerV3.initializePricing(blockNumber);
}
});

it('getPoolIdentifiers and getPricesVolume SELL', async function () {
await testPricingOnNetwork(
balancerV3,
network,
dexKey,
blockNumber,
srcTokenSymbol,
destTokenSymbol,
SwapSide.SELL,
amountsForSell,
);
});

it('getPoolIdentifiers and getPricesVolume BUY', async function () {
await testPricingOnNetwork(
balancerV3,
network,
dexKey,
blockNumber,
srcTokenSymbol,
destTokenSymbol,
SwapSide.BUY,
amountsForBuy,
);
});
});
describe('Full boosted path', () => {
const dexHelper = new DummyDexHelper(network);

const tokens = Tokens[network];
const srcTokenSymbol = 'wUSDL';
const destTokenSymbol = 'USDC';

const amountsForSell = [
0n,
1n * BI_POWS[tokens[srcTokenSymbol].decimals],
];

const amountsForBuy = [
0n,
1n * BI_POWS[tokens[destTokenSymbol].decimals],
];

beforeAll(async () => {
blockNumber = await dexHelper.web3Provider.eth.getBlockNumber();
balancerV3 = new BalancerV3(network, dexKey, dexHelper);
if (balancerV3.initializePricing) {
await balancerV3.initializePricing(blockNumber);
}
});

it('getPoolIdentifiers and getPricesVolume SELL', async function () {
await testPricingOnNetwork(
balancerV3,
network,
dexKey,
blockNumber,
srcTokenSymbol,
destTokenSymbol,
SwapSide.SELL,
amountsForSell,
);
});

it('getPoolIdentifiers and getPricesVolume BUY', async function () {
await testPricingOnNetwork(
balancerV3,
network,
dexKey,
blockNumber,
srcTokenSymbol,
destTokenSymbol,
SwapSide.BUY,
amountsForBuy,
);
});
});
});
});
});

Expand Down
Loading

0 comments on commit cdf8b62

Please sign in to comment.