@paraswap/dex-lib 2.28.12-ramses.2 → 2.29.0

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 (35) hide show
  1. package/build/dex/index.js +0 -2
  2. package/build/dex/index.js.map +1 -1
  3. package/build/dex/solidly/config.js +1 -11
  4. package/build/dex/solidly/config.js.map +1 -1
  5. package/build/dex/solidly/forks-override/ramses.js +2 -2
  6. package/build/dex/solidly/forks-override/ramses.js.map +1 -1
  7. package/build/dex/solidly/solidly.js +0 -1
  8. package/build/dex/solidly/solidly.js.map +1 -1
  9. package/build/dex/uniswap-v3/config.js +22 -0
  10. package/build/dex/uniswap-v3/config.js.map +1 -1
  11. package/build/dex/uniswap-v3/types.d.ts +6 -1
  12. package/build/dex/uniswap-v3/types.js.map +1 -1
  13. package/build/dex/uniswap-v3/uniswap-v3-pool.d.ts +3 -2
  14. package/build/dex/uniswap-v3/uniswap-v3-pool.js +5 -2
  15. package/build/dex/uniswap-v3/uniswap-v3-pool.js.map +1 -1
  16. package/build/dex/uniswap-v3/uniswap-v3.js +7 -3
  17. package/build/dex/uniswap-v3/uniswap-v3.js.map +1 -1
  18. package/package.json +1 -1
  19. package/src/abi/RamsesV2Pool.abi.json +1554 -0
  20. package/src/abi/RamsesV2Quoter.abi.json +274 -0
  21. package/src/abi/RamsesV2StateMulticall.abi.json +891 -0
  22. package/src/dex/index.ts +0 -2
  23. package/src/dex/solidly/config.ts +1 -13
  24. package/src/dex/solidly/solidly-e2e.test.ts +0 -95
  25. package/src/dex/solidly/solidly-integration.test.ts +1 -141
  26. package/src/dex/solidly/solidly.ts +0 -2
  27. package/src/dex/uniswap-v3/config.ts +22 -0
  28. package/src/dex/uniswap-v3/forks/ramses-v2/utils.ts +72 -0
  29. package/src/dex/uniswap-v3/types.ts +7 -1
  30. package/src/dex/uniswap-v3/uniswap-v3-e2e.test.ts +445 -354
  31. package/src/dex/uniswap-v3/uniswap-v3-integration.test.ts +171 -13
  32. package/src/dex/uniswap-v3/uniswap-v3-pool.ts +7 -2
  33. package/src/dex/uniswap-v3/uniswap-v3.ts +7 -2
  34. package/tests/constants-e2e.ts +1 -1
  35. package/src/dex/solidly/forks-override/ramses.ts +0 -224
package/src/dex/index.ts CHANGED
@@ -42,7 +42,6 @@ import { WooFiV2 } from './woo-fi-v2/woo-fi-v2';
42
42
  import { ParaSwapLimitOrders } from './paraswap-limit-orders/paraswap-limit-orders';
43
43
  import { AugustusRFQOrder } from './augustus-rfq';
44
44
  import { Solidly } from './solidly/solidly';
45
- import { Ramses } from './solidly/forks-override/ramses';
46
45
  import { Thena } from './solidly/forks-override/thena';
47
46
  import { Chronos } from './solidly/forks-override/chronos';
48
47
  import { Velodrome } from './solidly/forks-override/velodrome';
@@ -125,7 +124,6 @@ const Dexes = [
125
124
  Solidly,
126
125
  SolidlyEthereum,
127
126
  SpiritSwapV2,
128
- Ramses,
129
127
  Thena,
130
128
  Chronos,
131
129
  Velodrome,
@@ -125,18 +125,6 @@ export const SolidlyConfig: DexConfigMap<DexParams> = {
125
125
  feeCode: 0,
126
126
  },
127
127
  },
128
- Ramses: {
129
- [Network.ARBITRUM]: {
130
- subgraphURL:
131
- 'https://api.thegraph.com/subgraphs/name/ramsesexchange/api-subgraph',
132
- factoryAddress: '0xAAA20D08e59F6561f242b08513D36266C5A29415',
133
- router: '0xb2634B3CBc1E401AB3C2743DB44d459C5c9aA662',
134
- initCode:
135
- '0x1565b129f2d1790f12d45301b9b084335626f0c92410bc43130763b69971135d',
136
- poolGasCost: 180 * 1000,
137
- feeCode: 0,
138
- },
139
- },
140
128
  };
141
129
 
142
130
  export const Adapters: Record<number, AdapterMappings> = {
@@ -159,6 +147,6 @@ export const Adapters: Record<number, AdapterMappings> = {
159
147
  [SwapSide.SELL]: [{ name: 'AvalancheAdapter02', index: 3 }], // solisnek
160
148
  },
161
149
  [Network.ARBITRUM]: {
162
- [SwapSide.SELL]: [{ name: 'ArbitrumAdapter02', index: 1 }], // chronos, ramses
150
+ [SwapSide.SELL]: [{ name: 'ArbitrumAdapter02', index: 1 }], // chronos
163
151
  },
164
152
  };
@@ -1179,100 +1179,5 @@ describe('Solidly E2E', () => {
1179
1179
  }),
1180
1180
  );
1181
1181
  });
1182
-
1183
- describe('Ramses', () => {
1184
- const dexKey = 'Ramses';
1185
-
1186
- const sideToContractMethods = new Map([
1187
- [
1188
- SwapSide.SELL,
1189
- [
1190
- ContractMethod.simpleSwap,
1191
- ContractMethod.multiSwap,
1192
- ContractMethod.megaSwap,
1193
- ],
1194
- ],
1195
- ]);
1196
-
1197
- const pairs: { name: string; sellAmount: string }[][] = [
1198
- [
1199
- {
1200
- name: 'ETH',
1201
- sellAmount: '1000000000000000000',
1202
- },
1203
- {
1204
- name: 'USDCe',
1205
- sellAmount: '100000000',
1206
- },
1207
- ],
1208
- [
1209
- {
1210
- name: 'WETH',
1211
- sellAmount: '1000000000000000000',
1212
- },
1213
- {
1214
- name: 'USDCe',
1215
- sellAmount: '100000000',
1216
- },
1217
- ],
1218
- [
1219
- {
1220
- name: 'USDT',
1221
- sellAmount: '100000000',
1222
- },
1223
- {
1224
- name: 'USDCe',
1225
- sellAmount: '100000000',
1226
- },
1227
- ],
1228
- [
1229
- {
1230
- name: 'USDCe',
1231
- sellAmount: '100000000',
1232
- },
1233
- {
1234
- name: 'DAI',
1235
- sellAmount: '100000000000000000000',
1236
- },
1237
- ],
1238
- ];
1239
-
1240
- sideToContractMethods.forEach((contractMethods, side) =>
1241
- describe(`${side}`, () => {
1242
- contractMethods.forEach((contractMethod: ContractMethod) => {
1243
- pairs.forEach(pair => {
1244
- describe(`${contractMethod}`, () => {
1245
- it(`${pair[0].name} -> ${pair[1].name}`, async () => {
1246
- await testE2E(
1247
- tokens[pair[0].name],
1248
- tokens[pair[1].name],
1249
- holders[pair[0].name],
1250
- pair[0].sellAmount,
1251
- side,
1252
- dexKey,
1253
- contractMethod,
1254
- network,
1255
- provider,
1256
- );
1257
- });
1258
- it(`${pair[1].name} -> ${pair[0].name}`, async () => {
1259
- await testE2E(
1260
- tokens[pair[1].name],
1261
- tokens[pair[0].name],
1262
- holders[pair[1].name],
1263
- pair[1].sellAmount,
1264
- side,
1265
- dexKey,
1266
- contractMethod,
1267
- network,
1268
- provider,
1269
- );
1270
- });
1271
- });
1272
- });
1273
- });
1274
- }),
1275
- );
1276
- });
1277
1182
  });
1278
1183
  });
@@ -12,8 +12,6 @@ import solidlyPairABI from '../../abi/solidly/SolidlyPair.json';
12
12
  import { SpiritSwapV2 } from './forks-override/spiritSwapV2';
13
13
  import { Cone } from './forks-override/cone';
14
14
  import { Chronos } from './forks-override/chronos';
15
- import { Ramses } from './forks-override/ramses';
16
- import * as util from 'util';
17
15
 
18
16
  const amounts18 = [0n, BI_POWS[18], 2000000000000000000n];
19
17
  const amounts6 = [0n, BI_POWS[6], 2000000n];
@@ -62,7 +60,7 @@ const constructCheckOnChainPricing =
62
60
  funcName,
63
61
  tokenIn,
64
62
  );
65
-
63
+ console.log('readerCallData', readerCallData);
66
64
  const readerResult = (
67
65
  await dexHelper.multiContract.methods
68
66
  .aggregate(readerCallData)
@@ -72,8 +70,6 @@ const constructCheckOnChainPricing =
72
70
  decodeReaderResult(readerResult, readerIface, funcName),
73
71
  );
74
72
 
75
- console.log('ON-CHAIN PRICES: ', expectedPrices);
76
-
77
73
  expect(prices.map(p => p.toString())).toEqual(
78
74
  expectedPrices.map(p => p.toString()),
79
75
  );
@@ -772,141 +768,5 @@ describe('Solidly integration tests', () => {
772
768
  });
773
769
  });
774
770
  });
775
-
776
- describe('Ramses', function () {
777
- const dexKey = 'Ramses';
778
- const ramses = new Ramses(network, dexKey, dexHelper);
779
-
780
- describe('UniswapV2 like pool', function () {
781
- const TokenASymbol = 'USDCe';
782
- const tokenA = Tokens[network][TokenASymbol];
783
- const TokenBSymbol = 'WETH';
784
- const tokenB = Tokens[network][TokenBSymbol];
785
-
786
- const amounts = amounts18;
787
-
788
- it('getPoolIdentifiers and getPricesVolume', async function () {
789
- const blocknumber = await dexHelper.web3Provider.eth.getBlockNumber();
790
- const pools = await ramses.getPoolIdentifiers(
791
- tokenA,
792
- tokenB,
793
- SwapSide.SELL,
794
- blocknumber,
795
- );
796
- console.log(
797
- `${TokenASymbol} <> ${TokenBSymbol} Pool Identifiers: `,
798
- pools,
799
- );
800
-
801
- expect(pools.length).toBeGreaterThan(0);
802
-
803
- console.log('AMOUNTS: ', amounts);
804
-
805
- const poolPrices = await ramses.getPricesVolume(
806
- tokenA,
807
- tokenB,
808
- amounts,
809
- SwapSide.SELL,
810
- blocknumber,
811
- pools,
812
- );
813
- console.log(
814
- `${TokenASymbol} <> ${TokenBSymbol} Pool Prices: `,
815
- util.inspect(poolPrices, false, null, true),
816
- );
817
-
818
- expect(poolPrices).not.toBeNull();
819
- // checkPoolPrices(poolPrices!, amounts, SwapSide.SELL, dexKey);
820
-
821
- // Check if onchain pricing equals to calculated ones
822
-
823
- for (const i in poolPrices || []) {
824
- await checkOnChainPricing(
825
- ramses,
826
- 'getAmountOut',
827
- blocknumber,
828
- poolPrices![i].prices,
829
- poolPrices![i].poolAddresses![0],
830
- tokenA.address,
831
- amounts,
832
- );
833
- }
834
- });
835
-
836
- it('getTopPoolsForToken', async function () {
837
- const poolLiquidity = await ramses.getTopPoolsForToken(
838
- tokenA.address,
839
- 10,
840
- );
841
- console.log(`${TokenASymbol} Top Pools:`, poolLiquidity);
842
-
843
- checkPoolsLiquidity(poolLiquidity, tokenA.address, dexKey);
844
- });
845
- });
846
-
847
- describe('Curve like stable pool', function () {
848
- const TokenASymbol = 'USDT';
849
- const tokenA = Tokens[network][TokenASymbol];
850
- const TokenBSymbol = 'USDCe';
851
- const tokenB = Tokens[network][TokenBSymbol];
852
-
853
- const amounts = amounts6;
854
-
855
- it('getPoolIdentifiers and getPricesVolume', async function () {
856
- const blocknumber = await dexHelper.web3Provider.eth.getBlockNumber();
857
- const pools = await ramses.getPoolIdentifiers(
858
- tokenA,
859
- tokenB,
860
- SwapSide.SELL,
861
- blocknumber,
862
- );
863
- console.log(
864
- `${TokenASymbol} <> ${TokenBSymbol} Pool Identifiers: `,
865
- pools,
866
- );
867
-
868
- expect(pools.length).toBeGreaterThan(0);
869
-
870
- const poolPrices = await ramses.getPricesVolume(
871
- tokenA,
872
- tokenB,
873
- amounts,
874
- SwapSide.SELL,
875
- blocknumber,
876
- pools,
877
- );
878
- console.log(
879
- `${TokenASymbol} <> ${TokenBSymbol} Pool Prices: `,
880
- poolPrices,
881
- );
882
-
883
- expect(poolPrices).not.toBeNull();
884
- checkPoolPrices(poolPrices!, amounts, SwapSide.SELL, dexKey);
885
-
886
- // Check if onchain pricing equals to calculated ones
887
- for (const i in poolPrices || []) {
888
- await checkOnChainPricing(
889
- ramses,
890
- 'getAmountOut',
891
- blocknumber,
892
- poolPrices![i].prices,
893
- poolPrices![i].poolAddresses![0],
894
- tokenA.address,
895
- amounts,
896
- );
897
- }
898
- });
899
-
900
- it('getTopPoolsForToken', async function () {
901
- const poolLiquidity = await ramses.getTopPoolsForToken(
902
- tokenA.address,
903
- 10,
904
- );
905
- console.log(`${TokenASymbol} Top Pools:`, poolLiquidity);
906
-
907
- checkPoolsLiquidity(poolLiquidity, tokenA.address, dexKey);
908
- });
909
- });
910
- });
911
771
  });
912
772
  });
@@ -72,7 +72,6 @@ export class Solidly extends UniswapV2 {
72
72
  'Thena',
73
73
  'SoliSnek',
74
74
  'Chronos',
75
- 'Ramses'
76
75
  ]),
77
76
  );
78
77
 
@@ -521,7 +520,6 @@ export class Solidly extends UniswapV2 {
521
520
  const pair = await this.findSolidlyPair(from, to, stable);
522
521
  if (!(pair && pair.pool && pair.exchange)) return null;
523
522
  const pairState = pair.pool.getState(blockNumber);
524
-
525
523
  if (!pairState) {
526
524
  this.logger.error(
527
525
  `Error_orderPairParams expected reserves, got none (maybe the pool doesn't exist) ${
@@ -2,6 +2,9 @@ import { DexParams } from './types';
2
2
  import { DexConfigMap, AdapterMappings } from '../../types';
3
3
  import { Network, SwapSide } from '../../constants';
4
4
  import { Address } from '../../types';
5
+ import RamsesV2StateMulticallABI from '../../abi/RamsesV2StateMulticall.abi.json';
6
+ import { AbiItem } from 'web3-utils';
7
+ import { decodeStateMultiCallResultWithRelativeBitmaps } from './forks/ramses-v2/utils';
5
8
 
6
9
  const SUPPORTED_FEES = [10000n, 3000n, 500n, 100n];
7
10
 
@@ -104,6 +107,25 @@ export const UniswapV3Config: DexConfigMap<DexParams> = {
104
107
  'https://api.thegraph.com/subgraphs/name/lynnshaoyu/uniswap-v3-avax',
105
108
  },
106
109
  },
110
+ RamsesV2: {
111
+ [Network.ARBITRUM]: {
112
+ factory: '0xAA2cd7477c451E703f3B9Ba5663334914763edF8',
113
+ deployer: '0xb3e423ab9cE6C03D98326A3A2a0D7D96b0829f22',
114
+ quoter: '0xAA20EFF7ad2F523590dE6c04918DaAE0904E3b20',
115
+ router: '0xAA23611badAFB62D37E7295A682D21960ac85A90',
116
+ supportedFees: SUPPORTED_FEES,
117
+ stateMulticall: '0x50EE4112Cab9c79812F23bE079aB3911395ACc8e',
118
+ stateMultiCallAbi: RamsesV2StateMulticallABI as AbiItem[],
119
+ uniswapMulticall: '0x1F98415757620B543A52E61c46B32eB19261F984',
120
+ chunksCount: 10,
121
+ initRetryFrequency: 10,
122
+ decodeStateMultiCallResultWithRelativeBitmaps,
123
+ initHash:
124
+ '0x1565b129f2d1790f12d45301b9b084335626f0c92410bc43130763b69971135d',
125
+ subgraphURL:
126
+ 'https://api.thegraph.com/subgraphs/name/ramsesexchange/concentrated-liquidity-graph',
127
+ },
128
+ },
107
129
  'QuickSwapV3.1': {
108
130
  [Network.ZKEVM]: {
109
131
  factory: '0xD9a2AD9E927Bd7014116CC5c7328f028D4318178',
@@ -0,0 +1,72 @@
1
+ import { MultiResult } from '../../../../lib/multi-wrapper';
2
+ import { BytesLike, ethers } from 'ethers';
3
+ import { DecodedStateMultiCallResultWithRelativeBitmaps } from '../../types';
4
+ import { extractSuccessAndValue } from '../../../../lib/decoders';
5
+ import { assert } from 'ts-essentials';
6
+
7
+ export function decodeStateMultiCallResultWithRelativeBitmaps(
8
+ result: MultiResult<BytesLike> | BytesLike,
9
+ ): DecodedStateMultiCallResultWithRelativeBitmaps {
10
+ const [isSuccess, toDecode] = extractSuccessAndValue(result);
11
+
12
+ assert(
13
+ isSuccess && toDecode !== '0x',
14
+ `decodeStateMultiCallResultWithRelativeBitmaps failed to get decodable result: ${result}`,
15
+ );
16
+
17
+ const decoded = ethers.utils.defaultAbiCoder.decode(
18
+ [
19
+ // I don't want to pass here any interface, so I just use it in ethers format
20
+ `
21
+ tuple(
22
+ address pool,
23
+ uint256 blockTimestamp,
24
+ tuple(
25
+ uint160 sqrtPriceX96,
26
+ int24 tick,
27
+ uint16 observationIndex,
28
+ uint16 observationCardinality,
29
+ uint16 observationCardinalityNext,
30
+ uint8 feeProtocol,
31
+ bool unlocked,
32
+ ) slot0,
33
+ uint128 liquidity,
34
+ int24 tickSpacing,
35
+ uint128 maxLiquidityPerTick,
36
+ tuple(
37
+ uint32 blockTimestamp,
38
+ int56 tickCumulative,
39
+ uint160 secondsPerLiquidityCumulativeX128,
40
+ bool initialized,
41
+ uint160 secondsPerBoostedLiquidityPeriodX128,
42
+ uint32 boostedInRange,
43
+ ) observation,
44
+ tuple(
45
+ int16 index,
46
+ uint256 value
47
+ )[] tickBitmap,
48
+ tuple(
49
+ int24 index,
50
+ tuple(
51
+ uint128 liquidityGross,
52
+ int128 liquidityNet,
53
+ uint128 cleanUnusedSlot,
54
+ uint128 cleanUnusedSlot2,
55
+ uint256 feeGrowthOutside0X128,
56
+ uint256 feeGrowthOutside1X128,
57
+ int56 tickCumulativeOutside,
58
+ uint160 secondsPerLiquidityOutsideX128,
59
+ uint32 secondsOutside,
60
+ bool initialized,
61
+ ) value,
62
+ )[] ticks
63
+ )
64
+ `,
65
+ ],
66
+ toDecode,
67
+ )[0];
68
+
69
+ // This conversion is not precise, because when we decode, we have more values
70
+ // But I typed only the ones that are used later
71
+ return decoded as DecodedStateMultiCallResultWithRelativeBitmaps;
72
+ }
@@ -1,6 +1,8 @@
1
- import { BigNumber } from 'ethers';
1
+ import { BigNumber, BytesLike } from 'ethers';
2
2
  import { NumberAsString } from '../../types';
3
3
  import { Address } from '../../types';
4
+ import { AbiItem } from 'web3-utils';
5
+ import { MultiResult } from '../../lib/multi-wrapper';
4
6
 
5
7
  export type OracleObservation = {
6
8
  blockTimestamp: bigint;
@@ -60,6 +62,8 @@ export type UniswapV3Data = {
60
62
  isApproved?: boolean;
61
63
  };
62
64
 
65
+ export type DecodeStateMultiCallFunc = (result: MultiResult<BytesLike> | BytesLike) => DecodedStateMultiCallResultWithRelativeBitmaps;
66
+
63
67
  export type DexParams = {
64
68
  router: Address;
65
69
  quoter: Address;
@@ -72,6 +76,8 @@ export type DexParams = {
72
76
  deployer?: Address;
73
77
  subgraphURL: string;
74
78
  initHash: string;
79
+ stateMultiCallAbi?: AbiItem[];
80
+ decodeStateMultiCallResultWithRelativeBitmaps? : DecodeStateMultiCallFunc,
75
81
  };
76
82
 
77
83
  export type UniswapV3SimpleSwapSellParam = {