@paraswap/dex-lib 2.41.3 → 2.41.5-polygon-migrator

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (57) hide show
  1. package/build/abi/polygon-migration/PolygonMigration.abi.json +364 -0
  2. package/build/config.js +2 -2
  3. package/build/dex/dexalot/constants.js.map +1 -1
  4. package/build/dex/dexalot/dexalot.js +18 -10
  5. package/build/dex/dexalot/dexalot.js.map +1 -1
  6. package/build/dex/dexalot/rate-fetcher.js +1 -1
  7. package/build/dex/dexalot/rate-fetcher.js.map +1 -1
  8. package/build/dex/index.js +4 -0
  9. package/build/dex/index.js.map +1 -1
  10. package/build/dex/polygon-migrator/config.d.ts +11 -0
  11. package/build/dex/polygon-migrator/config.js +21 -0
  12. package/build/dex/polygon-migrator/config.js.map +1 -0
  13. package/build/dex/polygon-migrator/constants.d.ts +1 -0
  14. package/build/dex/polygon-migrator/constants.js +5 -0
  15. package/build/dex/polygon-migrator/constants.js.map +1 -0
  16. package/build/dex/polygon-migrator/polygon-migrator.d.ts +48 -0
  17. package/build/dex/polygon-migrator/polygon-migrator.js +109 -0
  18. package/build/dex/polygon-migrator/polygon-migrator.js.map +1 -0
  19. package/build/dex/polygon-migrator/types.d.ts +11 -0
  20. package/build/dex/polygon-migrator/types.js +9 -0
  21. package/build/dex/polygon-migrator/types.js.map +1 -0
  22. package/build/dex/solidly/config.js +11 -1
  23. package/build/dex/solidly/config.js.map +1 -1
  24. package/build/dex/solidly/forks-override/chronos.js +10 -3
  25. package/build/dex/solidly/forks-override/chronos.js.map +1 -1
  26. package/build/dex/solidly/forks-override/usdfi.d.ts +8 -0
  27. package/build/dex/solidly/forks-override/usdfi.js +15 -0
  28. package/build/dex/solidly/forks-override/usdfi.js.map +1 -0
  29. package/build/dex/solidly/forks-override/velocimeter.js +6 -2
  30. package/build/dex/solidly/forks-override/velocimeter.js.map +1 -1
  31. package/build/dex/solidly/solidly.js +1 -0
  32. package/build/dex/solidly/solidly.js.map +1 -1
  33. package/build/dex/swaap-v2/swaap-v2.js.map +1 -1
  34. package/package.json +1 -1
  35. package/src/abi/polygon-migration/PolygonMigration.abi.json +364 -0
  36. package/src/config.ts +2 -2
  37. package/src/dex/algebra/algebra-e2e.test.ts +1 -1
  38. package/src/dex/dexalot/constants.ts +2 -1
  39. package/src/dex/dexalot/dexalot-e2e.test.ts +9 -9
  40. package/src/dex/dexalot/dexalot.ts +59 -34
  41. package/src/dex/dexalot/rate-fetcher.ts +1 -1
  42. package/src/dex/index.ts +4 -0
  43. package/src/dex/polygon-migrator/config.ts +25 -0
  44. package/src/dex/polygon-migrator/constants.ts +2 -0
  45. package/src/dex/polygon-migrator/polygon-migrator-e2e.test.ts +102 -0
  46. package/src/dex/polygon-migrator/polygon-migrator-integration.test.ts +140 -0
  47. package/src/dex/polygon-migrator/polygon-migrator.ts +151 -0
  48. package/src/dex/polygon-migrator/types.ts +14 -0
  49. package/src/dex/solidly/config.ts +13 -1
  50. package/src/dex/solidly/forks-override/chronos.ts +93 -68
  51. package/src/dex/solidly/forks-override/usdfi.ts +10 -0
  52. package/src/dex/solidly/forks-override/velocimeter.ts +6 -2
  53. package/src/dex/solidly/solidly-e2e.test.ts +20 -0
  54. package/src/dex/solidly/solidly-integration.test.ts +189 -1
  55. package/src/dex/solidly/solidly.ts +1 -0
  56. package/src/dex/swaap-v2/swaap-v2.ts +5 -2
  57. package/tests/constants-e2e.ts +25 -0
@@ -0,0 +1,102 @@
1
+ import dotenv from 'dotenv';
2
+ dotenv.config();
3
+
4
+ import { ContractMethod, Network, SwapSide } from '../../constants';
5
+ import { StaticJsonRpcProvider } from '@ethersproject/providers';
6
+ import { generateConfig } from '../../config';
7
+ import { Holders, Tokens } from '../../../tests/constants-e2e';
8
+ import { testE2E } from '../../../tests/utils-e2e';
9
+
10
+ function testForNetwork(
11
+ network: Network,
12
+ dexKey: string,
13
+ tokenASymbol: string,
14
+ tokenBSymbol: string,
15
+ tokenAAmount: string,
16
+ tokenBAmount: string,
17
+ ) {
18
+ const provider = new StaticJsonRpcProvider(
19
+ generateConfig(network).privateHttpProvider,
20
+ network,
21
+ );
22
+ const tokens = Tokens[network];
23
+ const holders = Holders[network];
24
+
25
+ const sideToContractMethods = new Map([
26
+ [
27
+ SwapSide.SELL,
28
+ [
29
+ ContractMethod.simpleSwap,
30
+ ContractMethod.multiSwap,
31
+ ContractMethod.megaSwap,
32
+ ],
33
+ ],
34
+ [
35
+ SwapSide.BUY,
36
+ [
37
+ ContractMethod.simpleBuy,
38
+ ContractMethod.buy,
39
+ ],
40
+ ],
41
+ ]);
42
+
43
+ describe(`${network}`, () => {
44
+ sideToContractMethods.forEach((contractMethods, side) =>
45
+ describe(`${side}`, () => {
46
+ contractMethods.forEach((contractMethod: ContractMethod) => {
47
+ describe(`${contractMethod}`, () => {
48
+ it(`${tokenASymbol} -> ${tokenBSymbol}`, async () => {
49
+ await testE2E(
50
+ tokens[tokenASymbol],
51
+ tokens[tokenBSymbol],
52
+ holders[tokenASymbol],
53
+ side === SwapSide.SELL ? tokenAAmount : tokenBAmount,
54
+ side,
55
+ dexKey,
56
+ contractMethod,
57
+ network,
58
+ provider,
59
+ );
60
+ });
61
+ it(`${tokenBSymbol} -> ${tokenASymbol}`, async () => {
62
+ await testE2E(
63
+ tokens[tokenBSymbol],
64
+ tokens[tokenASymbol],
65
+ holders[tokenBSymbol],
66
+ side === SwapSide.SELL ? tokenBAmount : tokenAAmount,
67
+ side,
68
+ dexKey,
69
+ contractMethod,
70
+ network,
71
+ provider,
72
+ );
73
+ });
74
+ });
75
+ });
76
+ }),
77
+ );
78
+ });
79
+ }
80
+
81
+ describe('PolygonMigrator E2E', () => {
82
+ const dexKey = 'PolygonMigrator';
83
+
84
+ describe('Mainnet', () => {
85
+ const network = Network.MAINNET;
86
+
87
+ const tokenASymbol: string = 'POL';
88
+ const tokenBSymbol: string = 'MATIC';
89
+
90
+ const tokenAAmount: string = '10000000000000000000';
91
+ const tokenBAmount: string = '20000000000000000000000';
92
+
93
+ testForNetwork(
94
+ network,
95
+ dexKey,
96
+ tokenASymbol,
97
+ tokenBSymbol,
98
+ tokenAAmount,
99
+ tokenBAmount,
100
+ );
101
+ });
102
+ });
@@ -0,0 +1,140 @@
1
+ import dotenv from 'dotenv';
2
+ dotenv.config();
3
+
4
+ import { DummyDexHelper } from '../../dex-helper/index';
5
+ import { Network, SwapSide } from '../../constants';
6
+ import { checkConstantPoolPrices } from '../../../tests/utils';
7
+ import { Tokens } from '../../../tests/constants-e2e';
8
+ import { BI_POWS } from '../../bigint-constants';
9
+ import { PolygonMigrator } from './polygon-migrator';
10
+
11
+ const network = Network.MAINNET;
12
+
13
+ const MaticSymbol = 'MATIC';
14
+ const MaticToken = Tokens[network][MaticSymbol];
15
+
16
+ const PolSymbol = 'POL';
17
+ const PolToken = Tokens[network][PolSymbol];
18
+
19
+ const amounts = [0n, BI_POWS[18], 2000000000000000000n];
20
+
21
+ const dexKey = 'PolygonMigrator';
22
+
23
+ describe('PolygonMigrator', function () {
24
+ it('getPoolIdentifiers and getPricesVolume MATIC -> POL SELL', async function () {
25
+ const dexHelper = new DummyDexHelper(network);
26
+ const blocknumber = await dexHelper.web3Provider.eth.getBlockNumber();
27
+ const polygonMigrator = new PolygonMigrator(network, dexKey, dexHelper);
28
+
29
+ const pools = await polygonMigrator.getPoolIdentifiers(
30
+ MaticToken,
31
+ PolToken,
32
+ SwapSide.SELL,
33
+ blocknumber,
34
+ );
35
+ console.log(`${MaticSymbol} <> ${PolSymbol} Pool Identifiers: `, pools);
36
+
37
+ expect(pools.length).toBeGreaterThan(0);
38
+
39
+ const poolPrices = await polygonMigrator.getPricesVolume(
40
+ MaticToken,
41
+ PolToken,
42
+ amounts,
43
+ SwapSide.SELL,
44
+ blocknumber,
45
+ pools,
46
+ );
47
+ console.log(`${MaticSymbol} <> ${PolSymbol} Pool Prices: `, poolPrices);
48
+
49
+ expect(poolPrices).not.toBeNull();
50
+ checkConstantPoolPrices(poolPrices!, amounts, dexKey);
51
+ });
52
+
53
+ it('getPoolIdentifiers and getPricesVolume POL -> MATIC SELL', async function () {
54
+ const dexHelper = new DummyDexHelper(network);
55
+ const blocknumber = await dexHelper.web3Provider.eth.getBlockNumber();
56
+ const polygonMigrator = new PolygonMigrator(network, dexKey, dexHelper);
57
+
58
+ const pools = await polygonMigrator.getPoolIdentifiers(
59
+ PolToken,
60
+ MaticToken,
61
+ SwapSide.SELL,
62
+ blocknumber,
63
+ );
64
+ console.log(`${PolSymbol} <> ${MaticSymbol} Pool Identifiers: `, pools);
65
+
66
+ expect(pools.length).toBeGreaterThan(0);
67
+
68
+ const poolPrices = await polygonMigrator.getPricesVolume(
69
+ PolToken,
70
+ MaticToken,
71
+ amounts,
72
+ SwapSide.SELL,
73
+ blocknumber,
74
+ pools,
75
+ );
76
+ console.log(`${PolSymbol} <> ${MaticSymbol} Pool Prices: `, poolPrices);
77
+
78
+ expect(poolPrices).not.toBeNull();
79
+ checkConstantPoolPrices(poolPrices!, amounts, dexKey);
80
+ });
81
+
82
+ it('getPoolIdentifiers and getPricesVolume MATIC -> POL BUY', async function () {
83
+ const dexHelper = new DummyDexHelper(network);
84
+ const blocknumber = await dexHelper.web3Provider.eth.getBlockNumber();
85
+ const polygonMigrator = new PolygonMigrator(network, dexKey, dexHelper);
86
+
87
+ const pools = await polygonMigrator.getPoolIdentifiers(
88
+ MaticToken,
89
+ PolToken,
90
+ SwapSide.BUY,
91
+ blocknumber,
92
+ );
93
+ console.log(`${MaticSymbol} <> ${PolSymbol} Pool Identifiers: `, pools);
94
+
95
+ expect(pools.length).toBeGreaterThan(0);
96
+
97
+ const poolPrices = await polygonMigrator.getPricesVolume(
98
+ MaticToken,
99
+ PolToken,
100
+ amounts,
101
+ SwapSide.BUY,
102
+ blocknumber,
103
+ pools,
104
+ );
105
+ console.log(`${MaticSymbol} <> ${PolSymbol} Pool Prices: `, poolPrices);
106
+
107
+ expect(poolPrices).not.toBeNull();
108
+ checkConstantPoolPrices(poolPrices!, amounts, dexKey);
109
+ });
110
+
111
+ it('getPoolIdentifiers and getPricesVolume POL -> MATIC BUY', async function () {
112
+ const dexHelper = new DummyDexHelper(network);
113
+ const blocknumber = await dexHelper.web3Provider.eth.getBlockNumber();
114
+ const polygonMigrator = new PolygonMigrator(network, dexKey, dexHelper);
115
+
116
+ const pools = await polygonMigrator.getPoolIdentifiers(
117
+ PolToken,
118
+ MaticToken,
119
+ SwapSide.BUY,
120
+ blocknumber,
121
+ );
122
+ console.log(`${PolSymbol} <> ${MaticSymbol} Pool Identifiers: `, pools);
123
+
124
+ expect(pools.length).toBeGreaterThan(0);
125
+
126
+ const poolPrices = await polygonMigrator.getPricesVolume(
127
+ PolToken,
128
+ MaticToken,
129
+ amounts,
130
+ SwapSide.BUY,
131
+ blocknumber,
132
+ pools,
133
+ );
134
+ console.log(`${PolSymbol} <> ${MaticSymbol} Pool Prices: `, poolPrices);
135
+
136
+ expect(poolPrices).not.toBeNull();
137
+ checkConstantPoolPrices(poolPrices!, amounts, dexKey);
138
+ });
139
+
140
+ });
@@ -0,0 +1,151 @@
1
+ import { SimpleExchange } from '../simple-exchange';
2
+ import { IDex } from '../idex';
3
+ import { DexParams, PolygonMigrationData, PolygonMigratorFunctions } from './types';
4
+ import { Network, SwapSide } from '../../constants';
5
+ import { getDexKeysWithNetwork } from '../../utils';
6
+ import { Adapters, PolygonMigratorConfig } from './config';
7
+ import {
8
+ AdapterExchangeParam,
9
+ Address,
10
+ ExchangePrices,
11
+ Logger,
12
+ PoolLiquidity,
13
+ PoolPrices,
14
+ SimpleExchangeParam,
15
+ Token
16
+ } from '../../types';
17
+ import { IDexHelper } from '../../dex-helper';
18
+ import * as CALLDATA_GAS_COST from '../../calldata-gas-cost';
19
+ import { BI_POWS } from '../../bigint-constants';
20
+ import { POLYGON_MIGRATION_GAS_COST } from './constants';
21
+ import PolygonMigrationAbi from '../../abi/polygon-migration/PolygonMigration.abi.json';
22
+ import { Interface } from 'ethers/lib/utils';
23
+
24
+ export class PolygonMigrator extends SimpleExchange implements IDex<PolygonMigrationData, DexParams> {
25
+ readonly hasConstantPriceLargeAmounts = true;
26
+ readonly isFeeOnTransferSupported = false;
27
+
28
+ public static dexKeysWithNetwork: { key: string; networks: Network[] }[] =
29
+ getDexKeysWithNetwork(PolygonMigratorConfig);
30
+
31
+ logger: Logger;
32
+
33
+ constructor(
34
+ protected network: Network,
35
+ dexKey: string,
36
+ protected dexHelper: IDexHelper,
37
+ readonly migratorAddress: string = PolygonMigratorConfig[dexKey][network].migratorAddress,
38
+ readonly polTokenAddress: string = PolygonMigratorConfig[dexKey][network].polTokenAddress,
39
+ readonly maticTokenAddress: string = PolygonMigratorConfig[dexKey][network].maticTokenAddress,
40
+ protected unitPrice = BI_POWS[18],
41
+ protected adapters = Adapters[network] || {},
42
+ protected migratorInterface = new Interface(PolygonMigrationAbi),
43
+ ) {
44
+ super(dexHelper, dexKey);
45
+ this.logger = dexHelper.getLogger(dexKey);
46
+ }
47
+
48
+ getAdapters(side: SwapSide): { name: string; index: number }[] | null {
49
+ return this.adapters[side] || null;
50
+ }
51
+
52
+ isMatic(tokenAddress: Address) {
53
+ return this.maticTokenAddress.toLowerCase() === tokenAddress.toLowerCase();
54
+ }
55
+
56
+ isPol(tokenAddress: Address) {
57
+ return this.polTokenAddress.toLowerCase() === tokenAddress.toLowerCase();
58
+ }
59
+
60
+ isAppropriatePair(srcToken: Token, destToken: Token) {
61
+ return (this.isMatic(srcToken.address) && this.isPol(destToken.address))
62
+ || (this.isMatic(destToken.address) && this.isPol(srcToken.address));
63
+ }
64
+
65
+ async getPoolIdentifiers(
66
+ srcToken: Token,
67
+ destToken: Token,
68
+ side: SwapSide,
69
+ blockNumber: number,
70
+ ): Promise<string[]> {
71
+ if(this.isAppropriatePair(srcToken, destToken)) {
72
+ return [`${this.dexKey}_${srcToken.address}_${destToken.address}`];
73
+ }
74
+
75
+ return [];
76
+ }
77
+
78
+ async getPricesVolume(
79
+ srcToken: Token,
80
+ destToken: Token,
81
+ amounts: bigint[],
82
+ side: SwapSide,
83
+ blockNumber: number,
84
+ limitPools?: string[],
85
+ ): Promise<null | ExchangePrices<PolygonMigrationData>> {
86
+ if(!this.isAppropriatePair(srcToken, destToken)) {
87
+ return null;
88
+ }
89
+
90
+ return [
91
+ {
92
+ prices: amounts,
93
+ unit: this.unitPrice,
94
+ gasCost: POLYGON_MIGRATION_GAS_COST,
95
+ exchange: this.dexKey,
96
+ poolAddresses: [this.migratorAddress],
97
+ data: null,
98
+ },
99
+ ];
100
+ }
101
+
102
+ // Returns estimated gas cost of calldata for this DEX in multiSwap
103
+ getCalldataGasCost(poolPrices: PoolPrices<PolygonMigrationData>): number | number[] {
104
+ return CALLDATA_GAS_COST.DEX_NO_PAYLOAD;
105
+ }
106
+
107
+ getAdapterParam(
108
+ srcToken: string,
109
+ destToken: string,
110
+ srcAmount: string,
111
+ destAmount: string,
112
+ data: PolygonMigrationData,
113
+ side: SwapSide,
114
+ ): AdapterExchangeParam {
115
+ return {
116
+ targetExchange: this.migratorAddress,
117
+ payload: '0x',
118
+ networkFee: '0',
119
+ };
120
+ }
121
+
122
+ async getSimpleParam(
123
+ srcToken: string,
124
+ destToken: string,
125
+ srcAmount: string,
126
+ destAmount: string,
127
+ data: PolygonMigrationData,
128
+ side: SwapSide,
129
+ ): Promise<SimpleExchangeParam> {
130
+ const swapData = this.migratorInterface.encodeFunctionData(
131
+ this.isMatic(srcToken) ? PolygonMigratorFunctions.migrate : PolygonMigratorFunctions.unmigrate,
132
+ [ srcAmount ],
133
+ );
134
+
135
+ return this.buildSimpleParamWithoutWETHConversion(
136
+ srcToken,
137
+ srcAmount,
138
+ destToken,
139
+ destAmount,
140
+ swapData,
141
+ this.migratorAddress,
142
+ );
143
+ }
144
+
145
+ async getTopPoolsForToken(
146
+ tokenAddress: Address,
147
+ limit: number,
148
+ ): Promise<PoolLiquidity[]> {
149
+ return [];
150
+ }
151
+ }
@@ -0,0 +1,14 @@
1
+ import { Address } from '../../types';
2
+
3
+ export type PolygonMigrationData = null;
4
+
5
+ export type DexParams = {
6
+ migratorAddress: Address;
7
+ polTokenAddress: Address;
8
+ maticTokenAddress: Address;
9
+ };
10
+
11
+ export enum PolygonMigratorFunctions {
12
+ migrate = 'migrate',
13
+ unmigrate = 'unmigrate',
14
+ }
@@ -198,6 +198,18 @@ export const SolidlyConfig: DexConfigMap<DexParams> = {
198
198
  // no subgraph
199
199
  },
200
200
  },
201
+ Usdfi: {
202
+ [Network.BSC]: {
203
+ subgraphURL:
204
+ 'https://api.thegraph.com/subgraphs/name/tbotteam/usdfi-dexv2',
205
+ factoryAddress: '0xB3863573d9f25e6a84895d4685a408db7a488416',
206
+ router: '0xc2b5a8082D2E1867A9CBBF41b625E3ae9dF81f8b',
207
+ initCode:
208
+ '0x1d770cc32abcf060a45b0de3f0afbd8594effe9f6d836f93d19c05d76b4b4dfa',
209
+ poolGasCost: 180 * 1000,
210
+ feeCode: 0, // dynamic fees
211
+ },
212
+ },
201
213
  };
202
214
 
203
215
  export const Adapters: Record<number, AdapterMappings> = {
@@ -211,7 +223,7 @@ export const Adapters: Record<number, AdapterMappings> = {
211
223
  [SwapSide.SELL]: [{ name: 'OptimismAdapter01', index: 8 }], // velodrome
212
224
  },
213
225
  [Network.BSC]: {
214
- [SwapSide.SELL]: [{ name: 'BscAdapter02', index: 1 }], // thena + cone
226
+ [SwapSide.SELL]: [{ name: 'BscAdapter02', index: 1 }], // thena + cone, usdFi
215
227
  },
216
228
  [Network.MAINNET]: {
217
229
  [SwapSide.SELL]: [{ name: 'Adapter04', index: 1 }], // solidly
@@ -27,7 +27,7 @@ type ChronosSubgraphPool = {
27
27
  token0: { id: string; decimals: string };
28
28
  reserve0: string;
29
29
  reserve1: string;
30
- token1: { id: string; decimals: string; };
30
+ token1: { id: string; decimals: string };
31
31
  };
32
32
 
33
33
  export class Chronos extends Solidly {
@@ -114,35 +114,43 @@ export class Chronos extends Solidly {
114
114
  if (!(data && data.pools0 && data.pools1))
115
115
  throw new Error("Couldn't fetch the pools from the subgraph");
116
116
 
117
- const pools0 = await this.prepareSubgraphPools(data.pools0, (pool,{
118
- address1, decimals1, liquidityUSDToken0, liquidityUSDToken1,
119
- }) => ({
120
- exchange: this.dexKey,
121
- stable: pool.isStable,
122
- address: pool.id.toLowerCase(),
123
- connectorTokens: [
124
- {
125
- address: address1,
126
- decimals: decimals1,
127
- },
128
- ],
129
- liquidityUSD: liquidityUSDToken0 + liquidityUSDToken1,
130
- }));
131
-
132
- const pools1 = await this.prepareSubgraphPools(data.pools1, (pool,{
133
- address0, decimals0, liquidityUSDToken0, liquidityUSDToken1,
134
- }) => ({
135
- exchange: this.dexKey,
136
- stable: pool.isStable,
137
- address: pool.id.toLowerCase(),
138
- connectorTokens: [
139
- {
140
- address: address0,
141
- decimals: decimals0,
142
- },
143
- ],
144
- liquidityUSD: liquidityUSDToken0 + liquidityUSDToken1,
145
- }));
117
+ const pools0 = await this.prepareSubgraphPools(
118
+ data.pools0,
119
+ (
120
+ pool,
121
+ { address1, decimals1, liquidityUSDToken0, liquidityUSDToken1 },
122
+ ) => ({
123
+ exchange: this.dexKey,
124
+ stable: pool.isStable,
125
+ address: pool.id.toLowerCase(),
126
+ connectorTokens: [
127
+ {
128
+ address: address1,
129
+ decimals: decimals1,
130
+ },
131
+ ],
132
+ liquidityUSD: liquidityUSDToken0 + liquidityUSDToken1,
133
+ }),
134
+ );
135
+
136
+ const pools1 = await this.prepareSubgraphPools(
137
+ data.pools1,
138
+ (
139
+ pool,
140
+ { address0, decimals0, liquidityUSDToken0, liquidityUSDToken1 },
141
+ ) => ({
142
+ exchange: this.dexKey,
143
+ stable: pool.isStable,
144
+ address: pool.id.toLowerCase(),
145
+ connectorTokens: [
146
+ {
147
+ address: address0,
148
+ decimals: decimals0,
149
+ },
150
+ ],
151
+ liquidityUSD: liquidityUSDToken0 + liquidityUSDToken1,
152
+ }),
153
+ );
146
154
 
147
155
  return _.slice(
148
156
  _.sortBy(_.concat(pools0, pools1), [pool => -1 * pool.liquidityUSD]),
@@ -154,7 +162,8 @@ export class Chronos extends Solidly {
154
162
  private async prepareSubgraphPools(
155
163
  pools: ChronosSubgraphPool[],
156
164
  iterator: (
157
- pool: ChronosSubgraphPool, {
165
+ pool: ChronosSubgraphPool,
166
+ {
158
167
  address0,
159
168
  address1,
160
169
  decimals0,
@@ -164,43 +173,59 @@ export class Chronos extends Solidly {
164
173
  liquidityUSDToken0,
165
174
  liquidityUSDToken1,
166
175
  }: {
167
- address0: string,
168
- address1: string,
169
- decimals0: number,
170
- decimals1: number,
171
- reserve0: bigint,
172
- reserve1: bigint,
173
- liquidityUSDToken0: number,
174
- liquidityUSDToken1: number,
175
- }) => PoolLiquidity
176
+ address0: string;
177
+ address1: string;
178
+ decimals0: number;
179
+ decimals1: number;
180
+ reserve0: bigint;
181
+ reserve1: bigint;
182
+ liquidityUSDToken0: number;
183
+ liquidityUSDToken1: number;
184
+ },
185
+ ) => PoolLiquidity,
176
186
  ): Promise<PoolLiquidity[]> {
177
- return Promise.all(pools.map(async (
178
- pool: ChronosSubgraphPool,
179
- ) => {
180
- const address0 = pool.token0.id.toLowerCase();
181
- const address1 = pool.token1.id.toLowerCase();
182
-
183
- const decimals0 = parseInt(pool.token0.decimals);
184
- const decimals1 = parseInt(pool.token1.decimals);
185
-
186
- const reserve0 = BigInt(new BigNumber(pool.reserve0).multipliedBy(10 ** decimals0).toFixed());
187
- const reserve1 = BigInt(new BigNumber(pool.reserve1).multipliedBy(10 ** decimals1).toFixed());
188
-
189
- const liquidityUSDToken0 = await this.dexHelper.getTokenUSDPrice({
190
- address: address0,
191
- decimals: decimals0,
192
- }, reserve0);
193
-
194
- const liquidityUSDToken1 = await this.dexHelper.getTokenUSDPrice({
195
- address: address1,
196
- decimals: decimals1,
197
- }, reserve1);
198
-
199
- return iterator(
200
- pool, {
201
- address0, address1, decimals0, decimals1, reserve0, reserve1, liquidityUSDToken0, liquidityUSDToken1,
202
- },
203
- );
204
- }));
187
+ return Promise.all(
188
+ pools.map(async (pool: ChronosSubgraphPool) => {
189
+ const address0 = pool.token0.id.toLowerCase();
190
+ const address1 = pool.token1.id.toLowerCase();
191
+
192
+ const decimals0 = parseInt(pool.token0.decimals);
193
+ const decimals1 = parseInt(pool.token1.decimals);
194
+
195
+ const reserve0 = BigInt(
196
+ new BigNumber(pool.reserve0).multipliedBy(10 ** decimals0).toFixed(),
197
+ );
198
+ const reserve1 = BigInt(
199
+ new BigNumber(pool.reserve1).multipliedBy(10 ** decimals1).toFixed(),
200
+ );
201
+
202
+ const liquidityUSDToken0 = await this.dexHelper.getTokenUSDPrice(
203
+ {
204
+ address: address0,
205
+ decimals: decimals0,
206
+ },
207
+ reserve0,
208
+ );
209
+
210
+ const liquidityUSDToken1 = await this.dexHelper.getTokenUSDPrice(
211
+ {
212
+ address: address1,
213
+ decimals: decimals1,
214
+ },
215
+ reserve1,
216
+ );
217
+
218
+ return iterator(pool, {
219
+ address0,
220
+ address1,
221
+ decimals0,
222
+ decimals1,
223
+ reserve0,
224
+ reserve1,
225
+ liquidityUSDToken0,
226
+ liquidityUSDToken1,
227
+ });
228
+ }),
229
+ );
205
230
  }
206
231
  }
@@ -0,0 +1,10 @@
1
+ import { Network } from '../../../constants';
2
+ import { getDexKeysWithNetwork } from '../../../utils';
3
+ import { SolidlyConfig } from '../config';
4
+ import _ from 'lodash';
5
+ import { SpiritSwapV2 } from './spiritSwapV2';
6
+
7
+ export class Usdfi extends SpiritSwapV2 {
8
+ public static dexKeysWithNetwork: { key: string; networks: Network[] }[] =
9
+ getDexKeysWithNetwork(_.pick(SolidlyConfig, ['Usdfi']));
10
+ }
@@ -39,11 +39,15 @@ export class Velocimeter extends Solidly {
39
39
  protected getFeesMultiCallData(pair: SolidlyPair) {
40
40
  const callEntry = {
41
41
  target: this.factoryAddress,
42
- callData: velocimeterFactoryIface.encodeFunctionData('getFee', [pair.exchange]),
42
+ callData: velocimeterFactoryIface.encodeFunctionData('getFee', [
43
+ pair.exchange,
44
+ ]),
43
45
  };
44
46
  const callDecoder = (values: any[]) =>
45
47
  parseInt(
46
- velocimeterFactoryIface.decodeFunctionResult('getFee', values)[0].toString(),
48
+ velocimeterFactoryIface
49
+ .decodeFunctionResult('getFee', values)[0]
50
+ .toString(),
47
51
  );
48
52
 
49
53
  return {
@@ -1126,6 +1126,26 @@ describe('Solidly E2E', () => {
1126
1126
  }),
1127
1127
  );
1128
1128
  });
1129
+
1130
+ describe('Usdfi', () => {
1131
+ const dexKey = 'Usdfi';
1132
+ const tokenASymbol: string = 'FRAX';
1133
+ const tokenBSymbol: string = 'frxETH';
1134
+
1135
+ const tokenAAmount: string = '100000000000000000';
1136
+ const tokenBAmount: string = '1111100000';
1137
+ const nativeTokenAmount = '100000000000000000';
1138
+
1139
+ testForNetwork(
1140
+ network,
1141
+ dexKey,
1142
+ tokenASymbol,
1143
+ tokenBSymbol,
1144
+ tokenAAmount,
1145
+ tokenBAmount,
1146
+ nativeTokenAmount,
1147
+ );
1148
+ });
1129
1149
  });
1130
1150
 
1131
1151
  describe('Avalanche', () => {