Skip to content

Commit

Permalink
Merge remote-tracking branch 'origin/develop' into gyro2-v2
Browse files Browse the repository at this point in the history
  • Loading branch information
brunoguerios committed Feb 19, 2024
2 parents 963deee + d5669b0 commit 79a5993
Show file tree
Hide file tree
Showing 6 changed files with 67 additions and 31 deletions.
1 change: 1 addition & 0 deletions .nvmrc
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
lts/gallium
19 changes: 9 additions & 10 deletions test/gyroEV2.integration.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,10 @@ import { setUp } from './testScripts/utils';
dotenv.config();

const networkId = Network.POLYGON;
const jsonRpcUrl = '';
const jsonRpcUrl = process.env.RPC_URL_POLYGON ?? '';
const rpcUrl = 'http://127.0.0.1:8137';
const provider = new JsonRpcProvider(rpcUrl, networkId);
const blocknumber = 42173266;
const blocknumber = 47427007;

const vault = Vault__factory.connect(vaultAddr, provider);

Expand Down Expand Up @@ -64,7 +64,7 @@ const gyroEV2PoolWMATIC_stMATIC_POLYGON: SubgraphPoolBase = {
dSq: '0.9999999999999999988662409334210612',
};

describe.skip('gyroEV2: WMATIC-stMATIC integration tests', () => {
describe('gyroEV2: WMATIC-stMATIC integration tests', () => {
let sor: SOR;
const funds = {
sender: AddressZero,
Expand All @@ -91,21 +91,20 @@ describe.skip('gyroEV2: WMATIC-stMATIC integration tests', () => {
it('should return no swaps when above limit', async () => {
const tokenIn = ADDRESSES[Network.POLYGON].WMATIC.address;
const tokenOut = ADDRESSES[Network.POLYGON].stMATIC.address;
const swapAmount = parseFixed('33.33333333333333', 18);
const swapAmount = parseFixed('100000000', 18);
const swapInfo = await sor.getSwaps(
tokenIn,
tokenOut,
swapType,
swapAmount
);

expect(swapInfo.swaps.length).to.eq(0);
expect(swapInfo.returnAmount.toString()).to.eq('0');
});
it('token > LSD, getSwaps result should match queryBatchSwap', async () => {
const tokenIn = ADDRESSES[Network.POLYGON].WMATIC.address;
const tokenOut = ADDRESSES[Network.POLYGON].stMATIC.address;
const swapAmount = parseFixed('1.12345678', 18);
const swapAmount = parseFixed('1603426', 18);
const swapInfo = await sor.getSwaps(
tokenIn,
tokenOut,
Expand All @@ -130,7 +129,7 @@ describe.skip('gyroEV2: WMATIC-stMATIC integration tests', () => {
it('LSD > token, getSwaps result should match queryBatchSwap', async () => {
const tokenIn = ADDRESSES[Network.POLYGON].stMATIC.address;
const tokenOut = ADDRESSES[Network.POLYGON].WMATIC.address;
const swapAmount = parseFixed('0.999', 18);
const swapAmount = parseFixed('160342', 18);
const swapInfo = await sor.getSwaps(
tokenIn,
tokenOut,
Expand Down Expand Up @@ -160,7 +159,7 @@ describe.skip('gyroEV2: WMATIC-stMATIC integration tests', () => {
it('should return no swaps when above limit', async () => {
const tokenIn = ADDRESSES[Network.POLYGON].WMATIC.address;
const tokenOut = ADDRESSES[Network.POLYGON].stMATIC.address;
const swapAmount = parseFixed('100', 18);
const swapAmount = parseFixed('100000000', 18);
const swapInfo = await sor.getSwaps(
tokenIn,
tokenOut,
Expand All @@ -174,7 +173,7 @@ describe.skip('gyroEV2: WMATIC-stMATIC integration tests', () => {
it('token > LSD, getSwaps result should match queryBatchSwap', async () => {
const tokenIn = ADDRESSES[Network.POLYGON].WMATIC.address;
const tokenOut = ADDRESSES[Network.POLYGON].stMATIC.address;
const swapAmount = parseFixed('1.987654321', 18);
const swapAmount = parseFixed('1603426', 18);
const swapInfo = await sor.getSwaps(
tokenIn,
tokenOut,
Expand All @@ -198,7 +197,7 @@ describe.skip('gyroEV2: WMATIC-stMATIC integration tests', () => {
it('LSD > token, getSwaps result should match queryBatchSwap', async () => {
const tokenIn = ADDRESSES[Network.POLYGON].stMATIC.address;
const tokenOut = ADDRESSES[Network.POLYGON].WMATIC.address;
const swapAmount = parseFixed('0.999', 18);
const swapAmount = parseFixed('1603420', 18);
const swapInfo = await sor.getSwaps(
tokenIn,
tokenOut,
Expand Down
38 changes: 23 additions & 15 deletions test/lib/onchainData.ts
Original file line number Diff line number Diff line change
Expand Up @@ -140,11 +140,14 @@ export async function getOnChainBalances(
);

multiPool.call(`${pool.id}.targets`, pool.address, 'getTargets');
multiPool.call(
`${pool.id}.rate`,
pool.address,
'getWrappedTokenRate'
);
// AaveLinear pools with version === 1 rates will still work
if (pool.poolType === 'AaveLinear' && pool.poolTypeVersion === 1) {
multiPool.call(
`${pool.id}.rate`,
pool.address,
'getWrappedTokenRate'
);
}
} else if (pool.poolType.toString().includes('Gyro')) {
multiPool.call(
`${pool.id}.swapFee`,
Expand Down Expand Up @@ -263,19 +266,24 @@ export async function getOnChainBalances(
);
}

const wrappedIndex = subgraphPools[index].wrappedIndex;
if (
wrappedIndex === undefined ||
onchainData.rate === undefined
subgraphPools[index].poolType === 'AaveLinear' &&
subgraphPools[index].poolTypeVersion === 1
) {
console.error(
`Linear Pool Missing WrappedIndex or PriceRate: ${poolId}`
);
return;
const wrappedIndex = subgraphPools[index].wrappedIndex;
if (
wrappedIndex === undefined ||
onchainData.rate === undefined
) {
console.error(
`Linear Pool Missing WrappedIndex or PriceRate: ${poolId}`
);
return;
}
// Update priceRate of wrappedToken
subgraphPools[index].tokens[wrappedIndex].priceRate =
formatFixed(onchainData.rate, 18);
}
// Update priceRate of wrappedToken
subgraphPools[index].tokens[wrappedIndex].priceRate =
formatFixed(onchainData.rate, 18);
}

subgraphPools[index].swapFee = formatFixed(swapFee, 18);
Expand Down
30 changes: 29 additions & 1 deletion test/testScripts/constants.ts
Original file line number Diff line number Diff line change
Expand Up @@ -114,6 +114,14 @@ export const SOR_CONFIG: Record<Network, SorConfig> = {
symbol: 'weth',
address: '0x6A023CCd1ff6F2045C3309768eAd9E68F978f6e1',
},
{
symbol: 'wsteth',
address: '0x6C76971f98945AE98dD7d4DFcA8711ebea946eA6',
},
],
triPathMidPoolIds: [
'0xeb30c85cc528537f5350cf5684ce6a4538e13394000200000000000000000059', // 3POOL_BPT/wstETH
'0x7644fa5d0ea14fcf3e813fdf93ca9544f8567655000000000000000000000066', // sBAL3
],
},
[Network.ZKEVM]: {
Expand Down Expand Up @@ -515,13 +523,33 @@ export const ADDRESSES = {
WXDAI: {
address: '0xe91d153e0b41518a2ce8dd3d7944fa863463a97d',
decimals: 18,
symbol: 'DAI',
symbol: 'WXDAI',
},
USDT: {
address: '0x4ECaBa5870353805a9F068101A40E0f32ed605C6',
decimals: 6,
symbol: 'USDT',
},
wstETH: {
address: '0x6C76971f98945AE98dD7d4DFcA8711ebea946eA6',
decimals: 18,
symbol: 'wstETH',
},
STETH: {
address: 'todo',
decimals: 18,
symbol: 'STETH',
},
crvUSD: {
address: '0xaBEf652195F98A91E490f047A5006B71c85f058d',
decimals: 18,
symbol: 'crvUSD',
},
sDAI: {
address: '0xaf204776c7245bf4147c2612bf6e5972ee483701',
decimals: 18,
symbol: 'sDAI',
},
},
[Network.GOERLI]: {
DAI: {
Expand Down
8 changes: 4 additions & 4 deletions test/testScripts/swapExample.ts
Original file line number Diff line number Diff line change
Expand Up @@ -58,17 +58,17 @@ function setUp(networkId: Network, provider: JsonRpcProvider): SOR {
}

export async function swap(): Promise<void> {
const networkId = Network.BASE;
const networkId = Network.GNOSIS;
const provider = new JsonRpcProvider(PROVIDER_URLS[networkId]);
// gasPrice is used by SOR as a factor to determine how many pools to swap against.
// i.e. higher cost means more costly to trade against lots of different pools.
const gasPrice = BigNumber.from('14000000000');
// This determines the max no of pools the SOR will use to swap.
const maxPools = 4;
const tokenIn = ADDRESSES[networkId].DAI;
const tokenOut = ADDRESSES[networkId].BALD;
const tokenIn = ADDRESSES[networkId].WXDAI;
const tokenOut = ADDRESSES[networkId].crvUSD;
const swapType: SwapTypes = SwapTypes.SwapExactIn;
const swapAmount = parseFixed('900', 18);
const swapAmount = parseFixed('200', 18);

const sor = setUp(networkId, provider);

Expand Down
2 changes: 1 addition & 1 deletion test/xaveFxPool.polygon.integration.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ const xaveFxPoolXSGD_USDC_POLYGON: SubgraphPoolBase = {
epsilon: '0.0005',
};

describe.skip('xaveFxPool: DAI-USDC integration (Polygon) tests', () => {
describe('xaveFxPool: DAI-USDC integration (Polygon) tests', () => {
context('test swaps vs queryBatchSwap', () => {
// Setup chain
before(async function () {
Expand Down

0 comments on commit 79a5993

Please sign in to comment.