@paraswap/dex-lib 2.16.1 → 2.16.2-balancer-v2-buy.2

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 (91) hide show
  1. package/build/abi/uniswap-v3/UniswapV3Pool.abi.json +363 -67
  2. package/build/abi/uniswap-v3/UniswapV3Quoter.abi.json +119 -23
  3. package/build/abi/uniswap-v3/pancakeswap-v3/PancakeswapV3QuoterV2.abi.json +285 -0
  4. package/build/abi/uniswap-v3/pancakeswap-v3/PancakeswapV3Router.abi.json +583 -0
  5. package/build/config.js +6 -6
  6. package/build/dex/balancer-v2/balancer-v2.d.ts +9 -14
  7. package/build/dex/balancer-v2/balancer-v2.js +19 -16
  8. package/build/dex/balancer-v2/balancer-v2.js.map +1 -1
  9. package/build/dex/balancer-v2/config.d.ts +2 -7
  10. package/build/dex/balancer-v2/config.js +20 -30
  11. package/build/dex/balancer-v2/config.js.map +1 -1
  12. package/build/dex/balancer-v2/pools/balancer-v2-pool.d.ts +24 -0
  13. package/build/dex/balancer-v2/pools/balancer-v2-pool.js +102 -0
  14. package/build/dex/balancer-v2/pools/balancer-v2-pool.js.map +1 -0
  15. package/build/dex/balancer-v2/pools/linear/LinearMath.d.ts +19 -0
  16. package/build/dex/balancer-v2/pools/linear/LinearMath.js +179 -0
  17. package/build/dex/balancer-v2/pools/linear/LinearMath.js.map +1 -0
  18. package/build/dex/balancer-v2/pools/linear/LinearPool.d.ts +50 -0
  19. package/build/dex/balancer-v2/pools/linear/LinearPool.js +458 -0
  20. package/build/dex/balancer-v2/pools/linear/LinearPool.js.map +1 -0
  21. package/build/dex/balancer-v2/pools/phantom-stable/PhantomStableMath.d.ts +10 -0
  22. package/build/dex/balancer-v2/pools/phantom-stable/PhantomStableMath.js +314 -0
  23. package/build/dex/balancer-v2/pools/phantom-stable/PhantomStableMath.js.map +1 -0
  24. package/build/dex/balancer-v2/pools/phantom-stable/PhantomStablePool.d.ts +50 -0
  25. package/build/dex/balancer-v2/pools/phantom-stable/PhantomStablePool.js +367 -0
  26. package/build/dex/balancer-v2/pools/phantom-stable/PhantomStablePool.js.map +1 -0
  27. package/build/dex/balancer-v2/pools/stable/StableMath.d.ts +7 -0
  28. package/build/dex/balancer-v2/pools/stable/StableMath.js +111 -0
  29. package/build/dex/balancer-v2/pools/stable/StableMath.js.map +1 -0
  30. package/build/dex/balancer-v2/pools/stable/StablePool.d.ts +30 -0
  31. package/build/dex/balancer-v2/pools/stable/StablePool.js +129 -0
  32. package/build/dex/balancer-v2/pools/stable/StablePool.js.map +1 -0
  33. package/build/dex/balancer-v2/pools/weighted/WeightedMath.d.ts +6 -0
  34. package/build/dex/balancer-v2/pools/weighted/WeightedMath.js +61 -0
  35. package/build/dex/balancer-v2/pools/weighted/WeightedMath.js.map +1 -0
  36. package/build/dex/balancer-v2/pools/weighted/WeightedPool.d.ts +30 -0
  37. package/build/dex/balancer-v2/pools/weighted/WeightedPool.js +112 -0
  38. package/build/dex/balancer-v2/pools/weighted/WeightedPool.js.map +1 -0
  39. package/build/dex/index.js +4 -0
  40. package/build/dex/index.js.map +1 -1
  41. package/build/dex/maverick-v1/config.js +1 -1
  42. package/build/dex/maverick-v1/config.js.map +1 -1
  43. package/build/dex/quickswap/config.js +8 -0
  44. package/build/dex/quickswap/config.js.map +1 -1
  45. package/build/dex/quickswap/spiritswap-v3.d.ts +6 -0
  46. package/build/dex/quickswap/spiritswap-v3.js +19 -0
  47. package/build/dex/quickswap/spiritswap-v3.js.map +1 -0
  48. package/build/dex/uniswap-v3/config.js +42 -0
  49. package/build/dex/uniswap-v3/config.js.map +1 -1
  50. package/build/dex/uniswap-v3/forks/pancakeswap-v3/pancakeswap-v3.d.ts +12 -0
  51. package/build/dex/uniswap-v3/forks/pancakeswap-v3/pancakeswap-v3.js +23 -0
  52. package/build/dex/uniswap-v3/forks/pancakeswap-v3/pancakeswap-v3.js.map +1 -0
  53. package/build/dex/uniswap-v3/types.d.ts +3 -0
  54. package/build/dex/uniswap-v3/types.js.map +1 -1
  55. package/build/dex/uniswap-v3/uniswap-v3-pool.d.ts +2 -1
  56. package/build/dex/uniswap-v3/uniswap-v3-pool.js +3 -2
  57. package/build/dex/uniswap-v3/uniswap-v3-pool.js.map +1 -1
  58. package/build/dex/uniswap-v3/uniswap-v3.js +6 -3
  59. package/build/dex/uniswap-v3/uniswap-v3.js.map +1 -1
  60. package/package.json +1 -1
  61. package/src/abi/uniswap-v3/UniswapV3Pool.abi.json +363 -67
  62. package/src/abi/uniswap-v3/UniswapV3Quoter.abi.json +119 -23
  63. package/src/abi/uniswap-v3/pancakeswap-v3/PancakeswapV3QuoterV2.abi.json +285 -0
  64. package/src/abi/uniswap-v3/pancakeswap-v3/PancakeswapV3Router.abi.json +583 -0
  65. package/src/config.ts +6 -6
  66. package/src/dex/balancer-v2/balancer-v2-e2e.test.ts +99 -160
  67. package/src/dex/balancer-v2/balancer-v2.ts +41 -29
  68. package/src/dex/balancer-v2/config.ts +23 -35
  69. package/src/dex/balancer-v2/pools/balancer-v2-pool.ts +273 -0
  70. package/src/dex/balancer-v2/{LinearMath.ts → pools/linear/LinearMath.ts} +1 -1
  71. package/src/dex/balancer-v2/{LinearPool.ts → pools/linear/LinearPool.ts} +210 -5
  72. package/src/dex/balancer-v2/{StableMath.ts → pools/phantom-stable/PhantomStableMath.ts} +101 -21
  73. package/src/dex/balancer-v2/{PhantomStablePool.ts → pools/phantom-stable/PhantomStablePool.ts} +165 -11
  74. package/src/dex/balancer-v2/pools/stable/StableMath.ts +204 -0
  75. package/src/dex/balancer-v2/pools/stable/StablePool.ts +221 -0
  76. package/src/dex/balancer-v2/pools/weighted/WeightedMath.ts +84 -0
  77. package/src/dex/balancer-v2/pools/weighted/WeightedPool.ts +189 -0
  78. package/src/dex/index.ts +4 -0
  79. package/src/dex/maverick-v1/config.ts +1 -1
  80. package/src/dex/quickswap/config.ts +9 -0
  81. package/src/dex/quickswap/quickswap-e2e.test.ts +94 -0
  82. package/src/dex/quickswap/spiritswap-v3.ts +19 -0
  83. package/src/dex/uniswap-v3/config.ts +50 -0
  84. package/src/dex/uniswap-v3/forks/pancakeswap-v3/pancakeswap-v3.ts +28 -0
  85. package/src/dex/uniswap-v3/types.ts +3 -0
  86. package/src/dex/uniswap-v3/uniswap-v3-e2e.test.ts +156 -0
  87. package/src/dex/uniswap-v3/uniswap-v3-pool.ts +3 -2
  88. package/src/dex/uniswap-v3/uniswap-v3.ts +7 -3
  89. package/tests/constants-e2e.ts +11 -6
  90. package/.idea/runConfigurations.xml +0 -10
  91. package/src/dex/balancer-v2/balancer-v2-pool.ts +0 -744
@@ -0,0 +1,84 @@
1
+ import { MathSol } from '../../balancer-v2-math';
2
+
3
+ const _require = (b: boolean, message: string) => {
4
+ if (!b) throw new Error(message);
5
+ };
6
+
7
+ export class WeightedMath {
8
+ static _MAX_IN_RATIO = 300000000000000000n;
9
+ static _MAX_OUT_RATIO = 300000000000000000n;
10
+
11
+ static _calcInGivenOut(
12
+ balanceIn: bigint,
13
+ weightIn: bigint,
14
+ balanceOut: bigint,
15
+ weightOut: bigint,
16
+ amountsOut: bigint[],
17
+ ): bigint[] {
18
+ /* https://docs.balancer.fi/reference/math/weighted-math.html#ingivenout */
19
+ /**********************************************************************************************
20
+ // outGivenOut //
21
+ // aI = amountIn //
22
+ // bI = balanceIn //
23
+ // bO = balanceOut / / bO \ (wO / wI) \ //
24
+ // aO = amountOut aI = bI * | | -------------------------- | ^ - 1 | //
25
+ // wI = weightIn \ \ ( bO - aO ) / / //
26
+ // wO = weightOut //
27
+ *********************************************************************************************/
28
+ const exponent = MathSol.divUpFixed(weightOut, weightIn);
29
+ return amountsOut.map((amountOut) => {
30
+ _require(
31
+ amountOut <= MathSol.mulDownFixed(balanceOut, this._MAX_OUT_RATIO),
32
+ 'Errors.MAX_OUT_RATIO',
33
+ );
34
+
35
+ const denominator = balanceOut - amountOut;
36
+ const base = MathSol.divUpFixed(balanceOut, denominator);
37
+ const power = MathSol.powUpFixed(base, exponent);
38
+ const ratio = MathSol.sub(power, MathSol.ONE);
39
+
40
+ return MathSol.mulUpFixed(balanceIn, ratio);
41
+ });
42
+ }
43
+
44
+ // Computes how many tokens can be taken out of a pool if `amountIn` are sent, given the
45
+ // current balances and weights.
46
+ static _calcOutGivenIn(
47
+ balanceIn: bigint,
48
+ weightIn: bigint,
49
+ balanceOut: bigint,
50
+ weightOut: bigint,
51
+ amountsIn: bigint[],
52
+ ): bigint[] {
53
+ /* https://docs.balancer.fi/reference/math/weighted-math.html#outgivenin */
54
+ /**********************************************************************************************
55
+ // outGivenIn //
56
+ // aO = amountOut //
57
+ // bO = balanceOut //
58
+ // bI = balanceIn / / bI \ (wI / wO) \ //
59
+ // aI = amountIn aO = bO * | 1 - | -------------------------- | ^ | //
60
+ // wI = weightIn \ \ ( bI + aI ) / / //
61
+ // wO = weightOut //
62
+ **********************************************************************************************/
63
+
64
+ // Amount out, so we round down overall.
65
+
66
+ // The multiplication rounds down, and the subtrahend (power) rounds up (so the base rounds up too).
67
+ // Because bI / (bI + aI) <= 1, the exponent rounds down.
68
+
69
+ // Cannot exceed maximum in ratio
70
+
71
+ const exponent = MathSol.divDownFixed(weightIn, weightOut);
72
+ return amountsIn.map(amountIn => {
73
+ _require(
74
+ amountIn <= MathSol.mulDownFixed(balanceIn, this._MAX_IN_RATIO),
75
+ 'Errors.MAX_IN_RATIO',
76
+ );
77
+ const denominator = balanceIn + amountIn;
78
+ const base = MathSol.divUpFixed(balanceIn, denominator);
79
+ const power = MathSol.powUpFixed(base, exponent);
80
+
81
+ return MathSol.mulDownFixed(balanceOut, MathSol.complementFixed(power));
82
+ });
83
+ }
84
+ }
@@ -0,0 +1,189 @@
1
+ import { Interface } from '@ethersproject/abi';
2
+ import WeightedPoolABI from '../../../../abi/balancer-v2/weighted-pool.json';
3
+ import { callData, PoolState, SubgraphPoolBase, TokenState } from '../../types';
4
+ import { decodeThrowError, getTokenScalingFactor } from '../../utils';
5
+ import { SwapSide } from '../../../../constants';
6
+ import { BaseMinimalSwapInfoPool } from '../balancer-v2-pool';
7
+ import { WeightedMath } from './WeightedMath';
8
+
9
+ export type WeightedPoolPairData = {
10
+ tokenInBalance: bigint;
11
+ tokenOutBalance: bigint;
12
+ tokenInScalingFactor: bigint;
13
+ tokenOutScalingFactor: bigint;
14
+ tokenInWeight: bigint;
15
+ tokenOutWeight: bigint;
16
+ swapFee: bigint;
17
+ };
18
+
19
+
20
+ export class WeightedPool extends BaseMinimalSwapInfoPool {
21
+ vaultAddress: string;
22
+ vaultInterface: Interface;
23
+ poolInterface: Interface;
24
+
25
+ constructor(vaultAddress: string, vaultInterface: Interface) {
26
+ super();
27
+ this.vaultAddress = vaultAddress;
28
+ this.vaultInterface = vaultInterface;
29
+ this.poolInterface = new Interface(WeightedPoolABI);
30
+ }
31
+
32
+ _onSwapGivenOut(
33
+ tokenAmountsOut: bigint[],
34
+ currentBalanceTokenIn: bigint,
35
+ currentBalanceTokenOut: bigint,
36
+ _weightIn: bigint,
37
+ _weightOut: bigint,
38
+ ): bigint[] {
39
+ return WeightedMath._calcInGivenOut(
40
+ currentBalanceTokenIn,
41
+ _weightIn,
42
+ currentBalanceTokenOut,
43
+ _weightOut,
44
+ tokenAmountsOut,
45
+ );
46
+ }
47
+
48
+ _onSwapGivenIn(
49
+ tokenAmountsIn: bigint[],
50
+ currentBalanceTokenIn: bigint,
51
+ currentBalanceTokenOut: bigint,
52
+ _weightIn: bigint,
53
+ _weightOut: bigint,
54
+ ): bigint[] {
55
+ return WeightedMath._calcOutGivenIn(
56
+ currentBalanceTokenIn,
57
+ _weightIn,
58
+ currentBalanceTokenOut,
59
+ _weightOut,
60
+ tokenAmountsIn,
61
+ );
62
+ }
63
+
64
+ /*
65
+ Helper function to parse pool data into params for onSell function.
66
+ */
67
+ parsePoolPairData(
68
+ pool: SubgraphPoolBase,
69
+ poolState: PoolState,
70
+ tokenIn: string,
71
+ tokenOut: string,
72
+ ): WeightedPoolPairData {
73
+ const inAddress = tokenIn.toLowerCase();
74
+ const outAddress = tokenOut.toLowerCase();
75
+
76
+ const tIn = pool.tokens.find(t => t.address.toLowerCase() === inAddress);
77
+ const tOut = pool.tokens.find(t => t.address.toLowerCase() === outAddress);
78
+
79
+ if (!tIn || !tOut) return {} as WeightedPoolPairData;
80
+
81
+ const tokenInBalance = poolState.tokens[inAddress].balance;
82
+ const tokenOutBalance = poolState.tokens[outAddress].balance;
83
+ const tokenInWeight = poolState.tokens[inAddress].weight || 0n;
84
+ const tokenOutWeight = poolState.tokens[outAddress].weight || 0n;
85
+ const tokenInScalingFactor = getTokenScalingFactor(tIn.decimals);
86
+ const tokenOutScalingFactor = getTokenScalingFactor(tOut.decimals);
87
+
88
+ const poolPairData: WeightedPoolPairData = {
89
+ tokenInBalance,
90
+ tokenOutBalance,
91
+ tokenInScalingFactor,
92
+ tokenOutScalingFactor,
93
+ tokenInWeight,
94
+ tokenOutWeight,
95
+ swapFee: poolState.swapFee,
96
+ };
97
+ return poolPairData;
98
+ }
99
+
100
+ /*
101
+ Helper function to construct onchain multicall data for WeightedPool (also 'LiquidityBootstrapping' and 'Investment' pool types).
102
+ */
103
+ getOnChainCalls(pool: SubgraphPoolBase): callData[] {
104
+ return [
105
+ {
106
+ target: this.vaultAddress,
107
+ callData: this.vaultInterface.encodeFunctionData('getPoolTokens', [
108
+ pool.id,
109
+ ]),
110
+ },
111
+ {
112
+ target: pool.address,
113
+ callData: this.poolInterface.encodeFunctionData('getSwapFeePercentage'),
114
+ },
115
+ {
116
+ target: pool.address,
117
+ callData: this.poolInterface.encodeFunctionData('getNormalizedWeights'),
118
+ },
119
+ ];
120
+ }
121
+
122
+ /*
123
+ Helper function to decodes multicall data for a Weighted Pool.
124
+ data must contain returnData
125
+ startIndex is where to start in returnData. Allows this decode function to be called along with other pool types.
126
+ */
127
+ decodeOnChainCalls(
128
+ pool: SubgraphPoolBase,
129
+ data: { success: boolean; returnData: any }[],
130
+ startIndex: number,
131
+ ): [{ [address: string]: PoolState }, number] {
132
+ const pools = {} as { [address: string]: PoolState };
133
+
134
+ const poolTokens = decodeThrowError(
135
+ this.vaultInterface,
136
+ 'getPoolTokens',
137
+ data[startIndex++],
138
+ pool.address,
139
+ );
140
+ const swapFee = decodeThrowError(
141
+ this.poolInterface,
142
+ 'getSwapFeePercentage',
143
+ data[startIndex++],
144
+ pool.address,
145
+ )[0];
146
+ const normalisedWeights = decodeThrowError(
147
+ this.poolInterface,
148
+ 'getNormalizedWeights',
149
+ data[startIndex++],
150
+ pool.address,
151
+ )[0];
152
+
153
+ const poolState: PoolState = {
154
+ swapFee: BigInt(swapFee.toString()),
155
+ tokens: poolTokens.tokens.reduce(
156
+ (ptAcc: { [address: string]: TokenState }, pt: string, j: number) => {
157
+ const tokenState: TokenState = {
158
+ balance: BigInt(poolTokens.balances[j].toString()),
159
+ };
160
+
161
+ if (normalisedWeights)
162
+ tokenState.weight = BigInt(normalisedWeights[j].toString());
163
+
164
+ ptAcc[pt.toLowerCase()] = tokenState;
165
+ return ptAcc;
166
+ },
167
+ {},
168
+ ),
169
+ orderedTokens: poolTokens.tokens,
170
+ };
171
+
172
+ pools[pool.address] = poolState;
173
+
174
+ return [pools, startIndex];
175
+ }
176
+
177
+ /*
178
+ For weighted pools there is a Swap limit of 30%: amounts swapped may not be larger than this percentage of total balance.
179
+ */
180
+ getSwapMaxAmount(poolPairData: WeightedPoolPairData, side: SwapSide): bigint {
181
+ return (
182
+ ((side === SwapSide.SELL
183
+ ? poolPairData.tokenInBalance
184
+ : poolPairData.tokenOutBalance) *
185
+ 3n) /
186
+ 10n
187
+ );
188
+ }
189
+ }
package/src/dex/index.ts CHANGED
@@ -63,6 +63,8 @@ import { MaverickV1 } from './maverick-v1/maverick-v1';
63
63
  import { QuickSwapV3 } from './quickswap/quickswap-v3';
64
64
  import { ZyberSwapV3 } from './quickswap/zyberswap-v3';
65
65
  import { TraderJoeV2 } from './trader-joe-v2';
66
+ import { SpiritSwapV3 } from './quickswap/spiritswap-v3';
67
+ import { PancakeswapV3 } from './uniswap-v3/forks/pancakeswap-v3/pancakeswap-v3';
66
68
 
67
69
  const LegacyDexes = [
68
70
  CurveV2,
@@ -80,6 +82,7 @@ const LegacyDexes = [
80
82
  DodoV2,
81
83
  QuickSwapV3,
82
84
  ZyberSwapV3,
85
+ SpiritSwapV3,
83
86
  TraderJoeV2,
84
87
  Jarvis,
85
88
  Lido,
@@ -94,6 +97,7 @@ const Dexes = [
94
97
  BalancerV2,
95
98
  UniswapV2,
96
99
  UniswapV3,
100
+ PancakeswapV3,
97
101
  BiSwap,
98
102
  MDEX,
99
103
  Dfyn,
@@ -10,7 +10,7 @@ export const MaverickV1Config: DexConfigMap<DexParams> = {
10
10
  MaverickV1: {
11
11
  [Network.MAINNET]: {
12
12
  subgraphURL:
13
- 'https://gateway.thegraph.com/api/4b42aaaee3e81a3f29390e9df7010cbc/subgraphs/id/9n4uEbt1XV6DnYH7AGHJ84Gh2fpu68iwxwBKnWqVMX9G',
13
+ 'https://api.thegraph.com/subgraphs/name/maverickprotocol/maverick-mainnet',
14
14
  routerAddress: '0x4a585e0f7c18e2c414221d6402652d5e0990e5f8',
15
15
  poolInspectorAddress: '0xaA5BF61a664109e959D69C38734d4EA7dF74e456',
16
16
  },
@@ -21,4 +21,13 @@ export const QuickSwapConfig: DexConfigMap<DexParams> = {
21
21
  '0xfa2ad44b9e39d38a7d396bb44a41ea957ac7b622c5c6afdc285728c300b3382a',
22
22
  },
23
23
  },
24
+ SpiritSwapV3: {
25
+ [Network.FANTOM]: {
26
+ factoryAddress: '0xC58A98644fCeee73bc2B6d349B3102627e2Ec58e',
27
+ router: '0x03108EDEd4902e89781839c885496c6de9D21956',
28
+ quoteAddress: '0xc4D1310D60A36c7d849A332Be8Dcff29603fe907',
29
+ initCode:
30
+ '0xa360004fb86ddf4cd7fe9aa67d0c6a7f7812d9069142659003dc503e1d7d241f',
31
+ },
32
+ },
24
33
  };
@@ -354,4 +354,98 @@ describe('QuickSwap', () => {
354
354
  });
355
355
  });
356
356
  });
357
+
358
+ describe('Fantom', () => {
359
+ const network = Network.FANTOM;
360
+ const tokens = Tokens[network];
361
+ const holders = Holders[network];
362
+ const provider = new StaticJsonRpcProvider(
363
+ generateConfig(network).privateHttpProvider,
364
+ network,
365
+ );
366
+ describe('SpiritSwapV3', () => {
367
+ const dexKey = 'SpiritSwapV3';
368
+
369
+ const sideToContractMethods = new Map([
370
+ [
371
+ SwapSide.SELL,
372
+ [
373
+ ContractMethod.simpleSwap,
374
+ ContractMethod.multiSwap,
375
+ ContractMethod.megaSwap,
376
+ ],
377
+ ],
378
+ [SwapSide.BUY, [ContractMethod.simpleBuy, ContractMethod.buy]],
379
+ ]);
380
+
381
+ const pairs: { name: string; sellAmount: string; buyAmount: string }[][] =
382
+ [
383
+ [
384
+ {
385
+ name: 'USDC',
386
+ sellAmount: '100',
387
+ buyAmount: '10000000000000000',
388
+ },
389
+ {
390
+ name: 'WFTM',
391
+ sellAmount: '10000000000000000',
392
+ buyAmount: '100',
393
+ },
394
+ ],
395
+ [
396
+ {
397
+ name: 'FTM',
398
+ sellAmount: '1000000000000000',
399
+ buyAmount: '100',
400
+ },
401
+ {
402
+ name: 'USDC',
403
+ sellAmount: '100',
404
+ buyAmount: '10000000000000000',
405
+ },
406
+ ],
407
+ ];
408
+
409
+ sideToContractMethods.forEach((contractMethods, side) =>
410
+ describe(`${side}`, () => {
411
+ contractMethods.forEach((contractMethod: ContractMethod) => {
412
+ pairs.forEach(pair => {
413
+ describe(`${contractMethod}`, () => {
414
+ it(`${pair[0].name} -> ${pair[1].name}`, async () => {
415
+ await testE2E(
416
+ tokens[pair[0].name],
417
+ tokens[pair[1].name],
418
+ holders[pair[0].name],
419
+ side === SwapSide.SELL
420
+ ? pair[0].sellAmount
421
+ : pair[0].buyAmount,
422
+ side,
423
+ dexKey,
424
+ contractMethod,
425
+ network,
426
+ provider,
427
+ );
428
+ });
429
+ it(`${pair[1].name} -> ${pair[0].name}`, async () => {
430
+ await testE2E(
431
+ tokens[pair[1].name],
432
+ tokens[pair[0].name],
433
+ holders[pair[1].name],
434
+ side === SwapSide.SELL
435
+ ? pair[1].sellAmount
436
+ : pair[1].buyAmount,
437
+ side,
438
+ dexKey,
439
+ contractMethod,
440
+ network,
441
+ provider,
442
+ );
443
+ });
444
+ });
445
+ });
446
+ });
447
+ }),
448
+ );
449
+ });
450
+ });
357
451
  });
@@ -0,0 +1,19 @@
1
+ import { IDexHelper } from '../../dex-helper';
2
+ import _ from 'lodash';
3
+ import { QuickSwapConfig } from './config';
4
+ import { QuickSwapV3 } from './quickswap-v3';
5
+
6
+ const config = _.pick(QuickSwapConfig, ['SpiritSwapV3']).SpiritSwapV3;
7
+
8
+ export class SpiritSwapV3 extends QuickSwapV3 {
9
+ static dexKeys = ['spiritswapv3'];
10
+
11
+ // public static dexKeysWithNetwork
12
+ constructor(dexHelper: IDexHelper) {
13
+ super(
14
+ dexHelper,
15
+ 'spiritswapv3',
16
+ config[dexHelper.config.data.network].router,
17
+ );
18
+ }
19
+ }
@@ -4,6 +4,7 @@ import { Network, SwapSide } from '../../constants';
4
4
  import { Address } from '../../types';
5
5
 
6
6
  const SUPPORTED_FEES = [10000n, 3000n, 500n, 100n];
7
+ const PANCAKE_SUPPORTED_FEES = [10000n, 2500n, 500n, 100n];
7
8
 
8
9
  // Pools that will be initialized on app startup
9
10
  // They are added for testing
@@ -22,6 +23,7 @@ export const PoolsToPreload: DexConfigMap<
22
23
  },
23
24
  ],
24
25
  },
26
+ PancakeswapV3: {},
25
27
  };
26
28
 
27
29
  export const UniswapV3Config: DexConfigMap<DexParams> = {
@@ -34,6 +36,8 @@ export const UniswapV3Config: DexConfigMap<DexParams> = {
34
36
  stateMulticall: '0x9c764D2e92dA68E4CDfD784B902283A095ff8b63',
35
37
  uniswapMulticall: '0x1F98415757620B543A52E61c46B32eB19261F984',
36
38
  chunksCount: 10,
39
+ initHash: `0xe34f199b19b2b4f47f68442619d555527d244f78a3297ea89325f843f87b8b54`,
40
+ subgraphURL: 'https://api.thegraph.com/subgraphs/name/uniswap/uniswap-v3',
37
41
  },
38
42
  [Network.BSC]: {
39
43
  factory: '0xdB1d10011AD0Ff90774D0C6Bb92e5C5c8b4461F7',
@@ -43,6 +47,9 @@ export const UniswapV3Config: DexConfigMap<DexParams> = {
43
47
  stateMulticall: '0x593F39A4Ba26A9c8ed2128ac95D109E8e403C485',
44
48
  uniswapMulticall: '0x963Df249eD09c358A4819E39d9Cd5736c3087184',
45
49
  chunksCount: 10,
50
+ initHash: `0xe34f199b19b2b4f47f68442619d555527d244f78a3297ea89325f843f87b8b54`,
51
+ subgraphURL:
52
+ 'https://api.thegraph.com/subgraphs/name/ianlapham/uniswap-v3-bsc',
46
53
  },
47
54
  [Network.POLYGON]: {
48
55
  factory: '0x1F98431c8aD98523631AE4a59f267346ea31F984',
@@ -52,6 +59,9 @@ export const UniswapV3Config: DexConfigMap<DexParams> = {
52
59
  stateMulticall: '0x6Dc993Fe1e945A640576B4Dca81281d8e998DF71',
53
60
  uniswapMulticall: '0x1F98415757620B543A52E61c46B32eB19261F984',
54
61
  chunksCount: 10,
62
+ initHash: `0xe34f199b19b2b4f47f68442619d555527d244f78a3297ea89325f843f87b8b54`,
63
+ subgraphURL:
64
+ 'https://api.thegraph.com/subgraphs/name/ianlapham/uniswap-v3-polygon',
55
65
  },
56
66
  [Network.ARBITRUM]: {
57
67
  factory: '0x1F98431c8aD98523631AE4a59f267346ea31F984',
@@ -61,6 +71,9 @@ export const UniswapV3Config: DexConfigMap<DexParams> = {
61
71
  stateMulticall: '0xaBB58098A7B5172A9b0B38a1925A522dbf0b4FC3',
62
72
  uniswapMulticall: '0x1F98415757620B543A52E61c46B32eB19261F984',
63
73
  chunksCount: 10,
74
+ initHash: `0xe34f199b19b2b4f47f68442619d555527d244f78a3297ea89325f843f87b8b54`,
75
+ subgraphURL:
76
+ 'https://api.thegraph.com/subgraphs/name/ianlapham/arbitrum-minimal',
64
77
  },
65
78
  [Network.OPTIMISM]: {
66
79
  factory: '0x1F98431c8aD98523631AE4a59f267346ea31F984',
@@ -70,6 +83,39 @@ export const UniswapV3Config: DexConfigMap<DexParams> = {
70
83
  stateMulticall: '0x4FF0dEC5f9a763Aa1E5C2a962aa6f4eDFeE4f9eA',
71
84
  uniswapMulticall: '0x1F98415757620B543A52E61c46B32eB19261F984',
72
85
  chunksCount: 10,
86
+ initHash: `0xe34f199b19b2b4f47f68442619d555527d244f78a3297ea89325f843f87b8b54`,
87
+ subgraphURL:
88
+ 'https://api.thegraph.com/subgraphs/name/ianlapham/optimism-post-regenesis',
89
+ },
90
+ },
91
+ PancakeswapV3: {
92
+ [Network.MAINNET]: {
93
+ factory: '0x0BFbCF9fa4f9C56B0F40a671Ad40E0805A091865',
94
+ deployer: '0x41ff9AA7e16B8B1a8a8dc4f0eFacd93D02d071c9',
95
+ quoter: '0xB048Bbc1Ee6b733FFfCFb9e9CeF7375518e25997',
96
+ router: '0x1b81D678ffb9C0263b24A97847620C99d213eB14',
97
+ supportedFees: PANCAKE_SUPPORTED_FEES,
98
+ stateMulticall: '0x80898f80cFA3Fa3AbF410d90e69aDc432AE5D4c2',
99
+ uniswapMulticall: '0xac1cE734566f390A94b00eb9bf561c2625BF44ea',
100
+ chunksCount: 10,
101
+ initHash:
102
+ '0x6ce8eb472fa82df5469c6ab6d485f17c3ad13c8cd7af59b3d4a8026c5ce0f7e2',
103
+ subgraphURL:
104
+ 'https://api.thegraph.com/subgraphs/name/pancakeswap/exchange-v3-eth',
105
+ },
106
+ [Network.BSC]: {
107
+ factory: '0x0BFbCF9fa4f9C56B0F40a671Ad40E0805A091865',
108
+ deployer: '0x41ff9AA7e16B8B1a8a8dc4f0eFacd93D02d071c9',
109
+ quoter: '0xB048Bbc1Ee6b733FFfCFb9e9CeF7375518e25997',
110
+ router: '0x1b81D678ffb9C0263b24A97847620C99d213eB14',
111
+ supportedFees: PANCAKE_SUPPORTED_FEES,
112
+ stateMulticall: '0x9DAd2ED7ADc6eaacf81589Cd043579c9684E5C81',
113
+ uniswapMulticall: '0xac1cE734566f390A94b00eb9bf561c2625BF44ea',
114
+ chunksCount: 10,
115
+ initHash:
116
+ '0x6ce8eb472fa82df5469c6ab6d485f17c3ad13c8cd7af59b3d4a8026c5ce0f7e2',
117
+ subgraphURL:
118
+ 'https://api.thegraph.com/subgraphs/name/pancakeswap/exchange-v3-bsc',
73
119
  },
74
120
  },
75
121
  };
@@ -95,4 +141,8 @@ export const Adapters: Record<number, AdapterMappings> = {
95
141
  [SwapSide.SELL]: [{ name: 'OptimismAdapter01', index: 3 }],
96
142
  [SwapSide.BUY]: [{ name: 'OptimismBuyAdapter', index: 2 }],
97
143
  },
144
+ [Network.FANTOM]: {
145
+ [SwapSide.SELL]: [{ name: 'FantomAdapter01', index: 11 }],
146
+ [SwapSide.BUY]: [{ name: 'FantomBuyAdapter', index: 3 }],
147
+ },
98
148
  };
@@ -0,0 +1,28 @@
1
+ import { UniswapV3 } from '../../uniswap-v3';
2
+ import { Network } from '../../../../constants';
3
+ import { IDexHelper } from '../../../../dex-helper';
4
+ import { Interface } from '@ethersproject/abi';
5
+ import PancakeswapV3RouterABI from '../../../../abi/uniswap-v3/pancakeswap-v3/PancakeswapV3Router.abi.json';
6
+ import PancakeswapV3QuoterV2ABI from '../../../../abi/uniswap-v3/pancakeswap-v3/PancakeswapV3QuoterV2.abi.json';
7
+ import { getDexKeysWithNetwork } from '../../../../utils';
8
+ import _ from 'lodash';
9
+ import { UniswapV3Config } from '../../config';
10
+
11
+ export class PancakeswapV3 extends UniswapV3 {
12
+ public static dexKeysWithNetwork: { key: string; networks: Network[] }[] =
13
+ getDexKeysWithNetwork(_.pick(UniswapV3Config, ['PancakeswapV3']));
14
+ constructor(
15
+ protected network: Network,
16
+ dexKey: string,
17
+ protected dexHelper: IDexHelper,
18
+ ) {
19
+ super(
20
+ network,
21
+ dexKey,
22
+ dexHelper,
23
+ undefined,
24
+ new Interface(PancakeswapV3RouterABI),
25
+ new Interface(PancakeswapV3QuoterV2ABI),
26
+ );
27
+ }
28
+ }
@@ -67,6 +67,9 @@ export type DexParams = {
67
67
  uniswapMulticall: Address;
68
68
  supportedFees: bigint[];
69
69
  chunksCount: number;
70
+ deployer?: Address;
71
+ subgraphURL: string;
72
+ initHash: string;
70
73
  };
71
74
 
72
75
  export type UniswapV3SellParam = {