Skip to content

Commit

Permalink
Merge pull request paraswap#472 from paraswap/feat/1236-add-new-factory
Browse files Browse the repository at this point in the history
BACK-1236: Integrate CurveV1Factory new factory CRV_USD
  • Loading branch information
Verisana authored Aug 22, 2023
2 parents a1a4270 + 3e43854 commit c88ff6f
Show file tree
Hide file tree
Showing 31 changed files with 863 additions and 569 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": "2.30.1",
"version": "2.30.2",
"main": "build/index.js",
"types": "build/index.d.ts",
"repository": "https://github.com/paraswap/paraswap-dex-lib",
Expand Down
26 changes: 17 additions & 9 deletions src/dex/curve-v1-factory/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,10 @@ import { normalizeAddress } from '../../utils';
const CurveV1FactoryConfig: DexConfigMap<DexParams> = {
CurveV1Factory: {
[Network.MAINNET]: {
factoryAddress: '0xB9fC157394Af804a3578134A6585C0dc9cc990d4',
factoryAddresses: [
'0xB9fC157394Af804a3578134A6585C0dc9cc990d4',
'0x4f8846ae9380b90d2e71d5e3d042dff3e7ebb40d',
],
stateUpdatePeriodMs: 5 * 1000,
disabledPools: new Set([
'0x28B0Cf1baFB707F2c6826d10caf6DD901a6540C5', // It is rug pool token
Expand Down Expand Up @@ -150,6 +153,11 @@ const CurveV1FactoryConfig: DexConfigMap<DexParams> = {
name: ImplementationNames.FACTORY_PLAIN_4_OPTIMIZED,
address: '0xad4753d045d3aed5c1a6606dfb6a7d7ad67c1ad7',
},
'0x67fe41A94e779CcFa22cff02cc2957DC9C0e4286': {
name: ImplementationNames.FACTORY_PLAIN_2_CRV_EMA,
address: '0x67fe41A94e779CcFa22cff02cc2957DC9C0e4286',
liquidityApiSlug: '/factory-crvusd',
},
},
customPools: {
'0xDcEF968d416a41Cdac0ED8702fAC8128A64241A2': {
Expand Down Expand Up @@ -200,7 +208,7 @@ const CurveV1FactoryConfig: DexConfigMap<DexParams> = {
},
},
[Network.POLYGON]: {
factoryAddress: '0x722272D36ef0Da72FF51c5A65Db7b870E2e8D4ee',
factoryAddresses: ['0x722272D36ef0Da72FF51c5A65Db7b870E2e8D4ee'],
stateUpdatePeriodMs: 2 * 1000,
disabledPools: new Set([
'0x666Dc3b4baBfd063FaF965BD020024AF0dC51B64',
Expand Down Expand Up @@ -306,7 +314,7 @@ const CurveV1FactoryConfig: DexConfigMap<DexParams> = {
},
},
[Network.FANTOM]: {
factoryAddress: '0x686d67265703D1f124c45E33d47d794c566889Ba',
factoryAddresses: ['0x686d67265703D1f124c45E33d47d794c566889Ba'],
stateUpdatePeriodMs: 2 * 1000,
disabledPools: new Set([]),
disabledImplementations: new Set([]),
Expand Down Expand Up @@ -421,7 +429,7 @@ const CurveV1FactoryConfig: DexConfigMap<DexParams> = {
},
},
[Network.AVALANCHE]: {
factoryAddress: '0xb17b674D9c5CB2e441F8e196a2f048A81355d031',
factoryAddresses: ['0xb17b674D9c5CB2e441F8e196a2f048A81355d031'],
stateUpdatePeriodMs: 2 * 1000,
// FIX: This must be removed when we go for full CurveV1 event based support
disabledPools: new Set(['0x16a7da911a4dd1d83f3ff066fe28f3c792c50d90']),
Expand Down Expand Up @@ -519,7 +527,7 @@ const CurveV1FactoryConfig: DexConfigMap<DexParams> = {
},
},
[Network.ARBITRUM]: {
factoryAddress: '0xb17b674D9c5CB2e441F8e196a2f048A81355d031',
factoryAddresses: ['0xb17b674D9c5CB2e441F8e196a2f048A81355d031'],
stateUpdatePeriodMs: 2 * 1000,
disabledPools: new Set([]),
disabledImplementations: new Set([]),
Expand Down Expand Up @@ -645,7 +653,7 @@ const CurveV1FactoryConfig: DexConfigMap<DexParams> = {
},
},
[Network.OPTIMISM]: {
factoryAddress: '0x2db0E83599a91b508Ac268a6197b8B14F5e72840',
factoryAddresses: ['0x2db0E83599a91b508Ac268a6197b8B14F5e72840'],
stateUpdatePeriodMs: 2 * 1000,
disabledPools: new Set([]),
disabledImplementations: new Set([]),
Expand Down Expand Up @@ -869,9 +877,9 @@ const configAddressesNormalizer = (

// Unite everything into top level config
const normalizedConfig: DexParams = {
factoryAddress: _config.factoryAddress
? _config.factoryAddress.toLowerCase()
: _config.factoryAddress,
factoryAddresses: _config.factoryAddresses
? _config.factoryAddresses.map(e => e.toLowerCase())
: _config.factoryAddresses,
stateUpdatePeriodMs: _config.stateUpdatePeriodMs,
factoryPoolImplementations,
customPools,
Expand Down
19 changes: 19 additions & 0 deletions src/dex/curve-v1-factory/curve-v1-factory-e2e.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -111,6 +111,25 @@ describe('CurveV1Factory E2E', () => {
tokenBAmount,
);
});

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

const tokenASymbol: string = 'crvUSD';
const tokenBSymbol: string = 'USDT';

const tokenAAmount: string = '10000000000000000000';
const tokenBAmount: string = '10000000';

testForNetwork(
network,
dexKey,
tokenASymbol,
tokenBSymbol,
tokenAAmount,
tokenBAmount,
);
});
describe('Mainnet ng pool', () => {
const network = Network.MAINNET;

Expand Down
153 changes: 108 additions & 45 deletions src/dex/curve-v1-factory/curve-v1-factory-integration.test.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
/* eslint-disable no-console */
import dotenv from 'dotenv';
dotenv.config();

Expand Down Expand Up @@ -143,23 +144,6 @@ describe('CurveV1Factory', function () {

const tokens = Tokens[network];

const srcTokenSymbol = 'USDD';
const destTokenSymbol = 'USDT';

const amountsForSell = [
0n,
1n * BI_POWS[tokens[srcTokenSymbol].decimals],
2n * BI_POWS[tokens[srcTokenSymbol].decimals],
3n * BI_POWS[tokens[srcTokenSymbol].decimals],
4n * BI_POWS[tokens[srcTokenSymbol].decimals],
5n * BI_POWS[tokens[srcTokenSymbol].decimals],
6n * BI_POWS[tokens[srcTokenSymbol].decimals],
7n * BI_POWS[tokens[srcTokenSymbol].decimals],
8n * BI_POWS[tokens[srcTokenSymbol].decimals],
9n * BI_POWS[tokens[srcTokenSymbol].decimals],
10n * BI_POWS[tokens[srcTokenSymbol].decimals],
];

beforeAll(async () => {
blockNumber = await dexHelper.web3Provider.eth.getBlockNumber();
// @ts-expect-error for testing there is dummy blocknumber, but it is not
Expand All @@ -178,39 +162,118 @@ describe('CurveV1Factory', function () {
if (curveV1Factory) curveV1Factory.releaseResources();
});

it('getPoolIdentifiers and getPricesVolume SELL', async function () {
await testPricingOnNetwork(
curveV1Factory,
network,
dexKey,
blockNumber,
srcTokenSymbol,
destTokenSymbol,
SwapSide.SELL,
amountsForSell,
);
describe(`USDD-USDT`, () => {
const srcTokenSymbol = 'USDD';
const destTokenSymbol = 'USDT';
const amountsForSell = [
0n,
1n * BI_POWS[tokens[srcTokenSymbol].decimals],
2n * BI_POWS[tokens[srcTokenSymbol].decimals],
3n * BI_POWS[tokens[srcTokenSymbol].decimals],
4n * BI_POWS[tokens[srcTokenSymbol].decimals],
5n * BI_POWS[tokens[srcTokenSymbol].decimals],
6n * BI_POWS[tokens[srcTokenSymbol].decimals],
7n * BI_POWS[tokens[srcTokenSymbol].decimals],
8n * BI_POWS[tokens[srcTokenSymbol].decimals],
9n * BI_POWS[tokens[srcTokenSymbol].decimals],
10n * BI_POWS[tokens[srcTokenSymbol].decimals],
];

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

it('getTopPoolsForToken', async function () {
// We have to check without calling initializePricing, because
// pool-tracker is not calling that function
const newCurveV1Factory = new CurveV1Factory(
network,
dexKey,
dexHelper,
);
if (newCurveV1Factory.updatePoolState) {
await newCurveV1Factory.updatePoolState();
}
const poolLiquidity = await newCurveV1Factory.getTopPoolsForToken(
tokens[srcTokenSymbol].address,
10,
);
console.log(`${srcTokenSymbol} Top Pools:`, poolLiquidity);

if (!newCurveV1Factory.hasConstantPriceLargeAmounts) {
checkPoolsLiquidity(
poolLiquidity,
Tokens[network][srcTokenSymbol].address,
dexKey,
);
}
});
});

it('getTopPoolsForToken', async function () {
// We have to check without calling initializePricing, because
// pool-tracker is not calling that function
const newCurveV1Factory = new CurveV1Factory(network, dexKey, dexHelper);
if (newCurveV1Factory.updatePoolState) {
await newCurveV1Factory.updatePoolState();
}
const poolLiquidity = await newCurveV1Factory.getTopPoolsForToken(
tokens[srcTokenSymbol].address,
10,
);
console.log(`${srcTokenSymbol} Top Pools:`, poolLiquidity);
describe(`crvUSD-GHO`, () => {
const srcTokenSymbol = 'crvUSD';
const destTokenSymbol = 'GHO';
const amountsForSell = [
0n,
1n * BI_POWS[tokens[srcTokenSymbol].decimals],
2n * BI_POWS[tokens[srcTokenSymbol].decimals],
3n * BI_POWS[tokens[srcTokenSymbol].decimals],
4n * BI_POWS[tokens[srcTokenSymbol].decimals],
5n * BI_POWS[tokens[srcTokenSymbol].decimals],
6n * BI_POWS[tokens[srcTokenSymbol].decimals],
7n * BI_POWS[tokens[srcTokenSymbol].decimals],
8n * BI_POWS[tokens[srcTokenSymbol].decimals],
9n * BI_POWS[tokens[srcTokenSymbol].decimals],
10n * BI_POWS[tokens[srcTokenSymbol].decimals],
];

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

if (!newCurveV1Factory.hasConstantPriceLargeAmounts) {
checkPoolsLiquidity(
poolLiquidity,
Tokens[network][srcTokenSymbol].address,
it('getTopPoolsForToken', async function () {
// We have to check without calling initializePricing, because
// pool-tracker is not calling that function
const newCurveV1Factory = new CurveV1Factory(
network,
dexKey,
dexHelper,
);
}
if (newCurveV1Factory.updatePoolState) {
await newCurveV1Factory.updatePoolState();
}
const poolLiquidity = await newCurveV1Factory.getTopPoolsForToken(
tokens[srcTokenSymbol].address,
10,
);
console.log(`${srcTokenSymbol} Top Pools:`, poolLiquidity);

if (!newCurveV1Factory.hasConstantPriceLargeAmounts) {
checkPoolsLiquidity(
poolLiquidity,
Tokens[network][srcTokenSymbol].address,
dexKey,
);
}
});
});
});
describe('Polygon', () => {
Expand Down
Loading

0 comments on commit c88ff6f

Please sign in to comment.