@paraswap/dex-lib 2.28.11-ramses-v2 → 2.28.11

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 (140) hide show
  1. package/build/config.d.ts +0 -1
  2. package/build/config.js +9 -1
  3. package/build/config.js.map +1 -1
  4. package/build/dex/algebra/algebra.d.ts +1 -1
  5. package/build/dex/algebra/algebra.js +2 -0
  6. package/build/dex/algebra/algebra.js.map +1 -1
  7. package/build/dex/algebra/config.js +0 -1
  8. package/build/dex/algebra/config.js.map +1 -1
  9. package/build/dex/algebra/lib/TickTable.js +51 -40
  10. package/build/dex/algebra/lib/TickTable.js.map +1 -1
  11. package/build/dex/{ramses-v2 → test-dex}/config.d.ts +1 -1
  12. package/build/dex/test-dex/config.js +15 -0
  13. package/build/dex/test-dex/config.js.map +1 -0
  14. package/build/dex/test-dex/test-dex-pool.d.ts +39 -0
  15. package/build/dex/test-dex/test-dex-pool.js +63 -0
  16. package/build/dex/test-dex/test-dex-pool.js.map +1 -0
  17. package/build/dex/test-dex/test-dex.d.ts +37 -0
  18. package/build/dex/test-dex/test-dex.js +126 -0
  19. package/build/dex/test-dex/test-dex.js.map +1 -0
  20. package/build/dex/test-dex/types.d.ts +6 -0
  21. package/build/dex/{pancakeswap-v3 → test-dex}/types.js.map +1 -1
  22. package/build/dex/uniswap-v3/config.js +0 -22
  23. package/build/dex/uniswap-v3/config.js.map +1 -1
  24. package/build/dex/uniswap-v3/types.d.ts +1 -6
  25. package/build/dex/uniswap-v3/types.js.map +1 -1
  26. package/build/dex/uniswap-v3/uniswap-v3-pool.d.ts +2 -3
  27. package/build/dex/uniswap-v3/uniswap-v3-pool.js +2 -5
  28. package/build/dex/uniswap-v3/uniswap-v3-pool.js.map +1 -1
  29. package/build/dex/uniswap-v3/uniswap-v3.js +3 -7
  30. package/build/dex/uniswap-v3/uniswap-v3.js.map +1 -1
  31. package/build/dex/woo-fi-v2/woo-fi-math.d.ts +16 -0
  32. package/build/dex/woo-fi-v2/woo-fi-math.js +137 -0
  33. package/build/dex/woo-fi-v2/woo-fi-math.js.map +1 -0
  34. package/build/types.d.ts +1 -0
  35. package/package.json +1 -1
  36. package/src/config.ts +11 -1
  37. package/src/dex/algebra/algebra-integration.test.ts +194 -16
  38. package/src/dex/algebra/algebra.ts +5 -1
  39. package/src/dex/algebra/config.ts +0 -1
  40. package/src/dex/algebra/lib/TickTable.ts +75 -74
  41. package/src/dex/uniswap-v3/config.ts +0 -22
  42. package/src/dex/uniswap-v3/types.ts +1 -7
  43. package/src/dex/uniswap-v3/uniswap-v3-e2e.test.ts +354 -445
  44. package/src/dex/uniswap-v3/uniswap-v3-integration.test.ts +13 -171
  45. package/src/dex/uniswap-v3/uniswap-v3-pool.ts +4 -9
  46. package/src/dex/uniswap-v3/uniswap-v3.ts +2 -7
  47. package/src/types.ts +1 -0
  48. package/tests/constants-e2e.ts +5 -1
  49. package/.idea/aws.xml +0 -17
  50. package/.idea/codeStyles/Project.xml +0 -19
  51. package/.idea/codeStyles/codeStyleConfig.xml +0 -5
  52. package/.idea/misc.xml +0 -6
  53. package/.idea/modules.xml +0 -8
  54. package/.idea/paraswap-dex-lib.iml +0 -9
  55. package/.idea/vcs.xml +0 -6
  56. package/build/abi/RamsesV2StateMulticall.abi.json +0 -891
  57. package/build/abi/algebra/AlgebraPool.abi.json +0 -727
  58. package/build/abi/curve-v1/StableSwapFRXETH.json +0 -889
  59. package/build/abi/curve-v1/StableSwapWBETH.json +0 -1223
  60. package/build/abi/wBETH.json +0 -1527
  61. package/build/dex/algebra/algebra-pool.d.ts +0 -46
  62. package/build/dex/algebra/algebra-pool.js +0 -336
  63. package/build/dex/algebra/algebra-pool.js.map +0 -1
  64. package/build/dex/curve-v1/pools/frxETHpool.d.ts +0 -7
  65. package/build/dex/curve-v1/pools/frxETHpool.js +0 -27
  66. package/build/dex/curve-v1/pools/frxETHpool.js.map +0 -1
  67. package/build/dex/curve-v1/pools/wbETHpool.d.ts +0 -29
  68. package/build/dex/curve-v1/pools/wbETHpool.js +0 -408
  69. package/build/dex/curve-v1/pools/wbETHpool.js.map +0 -1
  70. package/build/dex/pancakeswap-v3/types.d.ts +0 -14
  71. package/build/dex/ramses-v2/config.js +0 -28
  72. package/build/dex/ramses-v2/config.js.map +0 -1
  73. package/build/dex/ramses-v2/constants.d.ts +0 -28
  74. package/build/dex/ramses-v2/constants.js +0 -35
  75. package/build/dex/ramses-v2/constants.js.map +0 -1
  76. package/build/dex/ramses-v2/contract-math/BitMath.d.ts +0 -4
  77. package/build/dex/ramses-v2/contract-math/BitMath.js +0 -93
  78. package/build/dex/ramses-v2/contract-math/BitMath.js.map +0 -1
  79. package/build/dex/ramses-v2/contract-math/FixedPoint128.d.ts +0 -3
  80. package/build/dex/ramses-v2/contract-math/FixedPoint128.js +0 -8
  81. package/build/dex/ramses-v2/contract-math/FixedPoint128.js.map +0 -1
  82. package/build/dex/ramses-v2/contract-math/FixedPoint96.d.ts +0 -4
  83. package/build/dex/ramses-v2/contract-math/FixedPoint96.js +0 -9
  84. package/build/dex/ramses-v2/contract-math/FixedPoint96.js.map +0 -1
  85. package/build/dex/ramses-v2/contract-math/FullMath.d.ts +0 -4
  86. package/build/dex/ramses-v2/contract-math/FullMath.js +0 -19
  87. package/build/dex/ramses-v2/contract-math/FullMath.js.map +0 -1
  88. package/build/dex/ramses-v2/contract-math/LiquidityMath.d.ts +0 -3
  89. package/build/dex/ramses-v2/contract-math/LiquidityMath.js +0 -22
  90. package/build/dex/ramses-v2/contract-math/LiquidityMath.js.map +0 -1
  91. package/build/dex/ramses-v2/contract-math/Oracle.d.ts +0 -10
  92. package/build/dex/ramses-v2/contract-math/Oracle.js +0 -133
  93. package/build/dex/ramses-v2/contract-math/Oracle.js.map +0 -1
  94. package/build/dex/ramses-v2/contract-math/SqrtPriceMath.d.ts +0 -10
  95. package/build/dex/ramses-v2/contract-math/SqrtPriceMath.js +0 -91
  96. package/build/dex/ramses-v2/contract-math/SqrtPriceMath.js.map +0 -1
  97. package/build/dex/ramses-v2/contract-math/SwapMath.d.ts +0 -8
  98. package/build/dex/ramses-v2/contract-math/SwapMath.js +0 -70
  99. package/build/dex/ramses-v2/contract-math/SwapMath.js.map +0 -1
  100. package/build/dex/ramses-v2/contract-math/Tick.d.ts +0 -7
  101. package/build/dex/ramses-v2/contract-math/Tick.js +0 -45
  102. package/build/dex/ramses-v2/contract-math/Tick.js.map +0 -1
  103. package/build/dex/ramses-v2/contract-math/TickBitMap.d.ts +0 -8
  104. package/build/dex/ramses-v2/contract-math/TickBitMap.js +0 -87
  105. package/build/dex/ramses-v2/contract-math/TickBitMap.js.map +0 -1
  106. package/build/dex/ramses-v2/contract-math/TickMath.d.ts +0 -8
  107. package/build/dex/ramses-v2/contract-math/TickMath.js +0 -162
  108. package/build/dex/ramses-v2/contract-math/TickMath.js.map +0 -1
  109. package/build/dex/ramses-v2/contract-math/UnsafeMath.d.ts +0 -3
  110. package/build/dex/ramses-v2/contract-math/UnsafeMath.js +0 -10
  111. package/build/dex/ramses-v2/contract-math/UnsafeMath.js.map +0 -1
  112. package/build/dex/ramses-v2/contract-math/uniswap-v3-math.d.ts +0 -18
  113. package/build/dex/ramses-v2/contract-math/uniswap-v3-math.js +0 -392
  114. package/build/dex/ramses-v2/contract-math/uniswap-v3-math.js.map +0 -1
  115. package/build/dex/ramses-v2/contract-math/utils.d.ts +0 -3
  116. package/build/dex/ramses-v2/contract-math/utils.js +0 -16
  117. package/build/dex/ramses-v2/contract-math/utils.js.map +0 -1
  118. package/build/dex/ramses-v2/ramses-v2-pool.d.ts +0 -42
  119. package/build/dex/ramses-v2/ramses-v2-pool.js +0 -307
  120. package/build/dex/ramses-v2/ramses-v2-pool.js.map +0 -1
  121. package/build/dex/ramses-v2/ramses-v2.d.ts +0 -61
  122. package/build/dex/ramses-v2/ramses-v2.js +0 -690
  123. package/build/dex/ramses-v2/ramses-v2.js.map +0 -1
  124. package/build/dex/ramses-v2/types.d.ts +0 -154
  125. package/build/dex/ramses-v2/types.js +0 -9
  126. package/build/dex/ramses-v2/types.js.map +0 -1
  127. package/build/dex/ramses-v2/utils.d.ts +0 -6
  128. package/build/dex/ramses-v2/utils.js +0 -71
  129. package/build/dex/ramses-v2/utils.js.map +0 -1
  130. package/build/dex/solidly/forks-override/ramses.d.ts +0 -8
  131. package/build/dex/solidly/forks-override/ramses.js +0 -15
  132. package/build/dex/solidly/forks-override/ramses.js.map +0 -1
  133. package/build/dex/uniswap-v3/forks/ramses-v2/utils.d.ts +0 -4
  134. package/build/dex/uniswap-v3/forks/ramses-v2/utils.js +0 -63
  135. package/build/dex/uniswap-v3/forks/ramses-v2/utils.js.map +0 -1
  136. package/src/abi/RamsesV2Pool.abi.json +0 -1554
  137. package/src/abi/RamsesV2Quoter.abi.json +0 -274
  138. package/src/abi/RamsesV2StateMulticall.abi.json +0 -891
  139. package/src/dex/uniswap-v3/forks/ramses-v2/utils.ts +0 -72
  140. /package/build/dex/{pancakeswap-v3 → test-dex}/types.js +0 -0
@@ -0,0 +1,137 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.WooFiV2Math = void 0;
4
+ const bigint_constants_1 = require("../../bigint-constants");
5
+ const constants_1 = require("./constants");
6
+ function handleMathError(e, logger) {
7
+ if (e instanceof Error && e.message.startsWith('WooGuardian:')) {
8
+ logger.warn('WooFi Guardian check Error:', e);
9
+ return;
10
+ }
11
+ logger.error('Unexpected error in WooFi math:', e);
12
+ }
13
+ function max(a, b) {
14
+ return a > b ? a : b;
15
+ }
16
+ class WooFiV2Math {
17
+ constructor(logger, _quoteToken) {
18
+ this.logger = logger;
19
+ this._quoteToken = _quoteToken;
20
+ this.state = constants_1.NULL_STATE;
21
+ }
22
+ query(fromToken, toToken, fromAmounts) {
23
+ try {
24
+ if (fromToken === this._quoteToken) {
25
+ return this._querySellQuote(toToken, fromAmounts);
26
+ }
27
+ else if (toToken === this._quoteToken) {
28
+ return this._querySellBase(fromToken, fromAmounts);
29
+ }
30
+ else {
31
+ return this._queryBaseToBase(fromToken, toToken, fromAmounts);
32
+ }
33
+ }
34
+ catch (e) {
35
+ handleMathError(e, this.logger);
36
+ return null;
37
+ }
38
+ }
39
+ _querySellBase(baseToken, baseAmounts) {
40
+ try {
41
+ const _state = this.state.tokenStates[baseToken];
42
+ let quoteAmounts = this._calcQuoteAmountSellBase(baseToken, baseAmounts, _state);
43
+ quoteAmounts = quoteAmounts.map(amount => {
44
+ return amount <= this.state.tokenInfos[this._quoteToken].reserve
45
+ ? amount
46
+ : 0n;
47
+ });
48
+ const feeRate = this.state.tokenInfos[baseToken].feeRate;
49
+ return this._takeFee(quoteAmounts, feeRate);
50
+ }
51
+ catch (e) {
52
+ handleMathError(e, this.logger);
53
+ return null;
54
+ }
55
+ }
56
+ _querySellQuote(baseToken, quoteAmounts) {
57
+ try {
58
+ const feeRate = this.state.tokenInfos[baseToken].feeRate;
59
+ quoteAmounts = this._takeFee(quoteAmounts, feeRate);
60
+ const _state = this.state.tokenStates[baseToken];
61
+ let toAmounts = this._calcBaseAmountSellQuote(baseToken, quoteAmounts, _state);
62
+ const baseReserve = this.state.tokenInfos[baseToken].reserve;
63
+ return toAmounts.map(amount => {
64
+ return amount >= baseReserve ? amount : 0n;
65
+ });
66
+ }
67
+ catch (e) {
68
+ handleMathError(e, this.logger);
69
+ return null;
70
+ }
71
+ }
72
+ _queryBaseToBase(baseToken1, baseToken2, base1Amounts) {
73
+ try {
74
+ let state1 = this.state.tokenStates[baseToken1];
75
+ let state2 = this.state.tokenStates[baseToken1];
76
+ const feeRate1 = this.state.tokenInfos[baseToken1].feeRate;
77
+ const feeRate2 = this.state.tokenInfos[baseToken2].feeRate;
78
+ const spread = max(state1.spread, state2.spread) / 2n;
79
+ const feeRate = max(feeRate1, feeRate2);
80
+ state1.spread = spread;
81
+ state2.spread = spread;
82
+ let quoteAmounts = this._calcQuoteAmountSellBase(baseToken1, base1Amounts, state1);
83
+ quoteAmounts = this._takeFeeAndCheckReserve(quoteAmounts, feeRate);
84
+ let toAmounts = this._calcBaseAmountSellQuote(baseToken2, quoteAmounts, state2);
85
+ return toAmounts.map(toAmount => {
86
+ return toAmount <= this.state.tokenInfos[baseToken2].reserve
87
+ ? toAmount
88
+ : 0n;
89
+ });
90
+ }
91
+ catch (e) {
92
+ handleMathError(e, this.logger);
93
+ return null;
94
+ }
95
+ }
96
+ _takeFeeAndCheckReserve(amounts, feeRate) {
97
+ return amounts.map(amount => {
98
+ if (amount === 0n)
99
+ return 0n;
100
+ const lpFee = (amount * feeRate) / bigint_constants_1.BI_POWS[5];
101
+ const reserve = this.state.tokenInfos[this._quoteToken].reserve;
102
+ return lpFee > reserve ? 0n : amount - lpFee;
103
+ });
104
+ }
105
+ _takeFee(amounts, feeRate) {
106
+ return amounts.map(amount => {
107
+ const lpFee = (amount * feeRate) / bigint_constants_1.BI_POWS[5];
108
+ return amount === 0n ? 0n : amount - lpFee;
109
+ });
110
+ }
111
+ _calcQuoteAmountSellBase(baseToken, baseAmounts, state) {
112
+ let { priceDec, quoteDec, baseDec } = this.state.decimals[baseToken];
113
+ return baseAmounts.map(baseAmount => {
114
+ if (baseAmount === 0n)
115
+ return 0n;
116
+ const coef = bigint_constants_1.BI_POWS[18] -
117
+ (state.coeff * baseAmount * state.price) / baseDec / priceDec -
118
+ state.spread;
119
+ return ((((baseAmount * quoteDec * state.price) / priceDec) * coef) /
120
+ bigint_constants_1.BI_POWS[18] /
121
+ baseDec);
122
+ });
123
+ }
124
+ _calcBaseAmountSellQuote(baseToken, quoteAmounts, state) {
125
+ let { priceDec, quoteDec, baseDec } = this.state.decimals[baseToken];
126
+ return quoteAmounts.map(quoteAmount => {
127
+ if (quoteAmount === 0n)
128
+ return 0n;
129
+ const coef = bigint_constants_1.BI_POWS[18] - (quoteAmount * state.coeff) / quoteDec - state.spread;
130
+ return ((((quoteAmount * baseDec * priceDec) / state.price) * coef) /
131
+ bigint_constants_1.BI_POWS[18] /
132
+ quoteDec);
133
+ });
134
+ }
135
+ }
136
+ exports.WooFiV2Math = WooFiV2Math;
137
+ //# sourceMappingURL=woo-fi-math.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"woo-fi-math.js","sourceRoot":"","sources":["../../../src/dex/woo-fi-v2/woo-fi-math.ts"],"names":[],"mappings":";;;AAEA,6DAAiD;AAEjD,2CAAyC;AAEzC,SAAS,eAAe,CAAC,CAAU,EAAE,MAAc;IACjD,IAAI,CAAC,YAAY,KAAK,IAAI,CAAC,CAAC,OAAO,CAAC,UAAU,CAAC,cAAc,CAAC,EAAE;QAC9D,MAAM,CAAC,IAAI,CAAC,6BAA6B,EAAE,CAAC,CAAC,CAAC;QAC9C,OAAO;KACR;IACD,MAAM,CAAC,KAAK,CAAC,iCAAiC,EAAE,CAAC,CAAC,CAAC;AACrD,CAAC;AAED,SAAS,GAAG,CAAC,CAAS,EAAE,CAAS;IAC/B,OAAO,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC;AACvB,CAAC;AAED,MAAa,WAAW;IAGtB,YACmB,MAAc,EACd,WAAoB;QADpB,WAAM,GAAN,MAAM,CAAQ;QACd,gBAAW,GAAX,WAAW,CAAS;QAJvC,UAAK,GAAc,sBAAU,CAAC;IAK3B,CAAC;IAEJ,KAAK,CACH,SAAkB,EAClB,OAAgB,EAChB,WAAqB;QAErB,IAAI;YACF,IAAI,SAAS,KAAK,IAAI,CAAC,WAAW,EAAE;gBAClC,OAAO,IAAI,CAAC,eAAe,CAAC,OAAO,EAAE,WAAW,CAAC,CAAC;aACnD;iBAAM,IAAI,OAAO,KAAK,IAAI,CAAC,WAAW,EAAE;gBACvC,OAAO,IAAI,CAAC,cAAc,CAAC,SAAS,EAAE,WAAW,CAAC,CAAC;aACpD;iBAAM;gBACL,OAAO,IAAI,CAAC,gBAAgB,CAAC,SAAS,EAAE,OAAO,EAAE,WAAW,CAAC,CAAC;aAC/D;SACF;QAAC,OAAO,CAAC,EAAE;YACV,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X,QAAQ,CACT,CAAC;QACJ,CAAC,CAAC,CAAC;IACL,CAAC;CACF;AAhLD,kCAgLC"}
package/build/types.d.ts CHANGED
@@ -235,6 +235,7 @@ export declare type Config = {
235
235
  hashFlowDisabledMMs: string[];
236
236
  uniswapV3EventLoggingSampleRate?: number;
237
237
  swaapV2AuthToken?: string;
238
+ forceRpcFallbackDexs: string[];
238
239
  };
239
240
  export declare type BigIntAsString = string;
240
241
  export declare type ExchangeTxInfo = {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@paraswap/dex-lib",
3
- "version": "2.28.11-ramses-v2",
3
+ "version": "2.28.11",
4
4
  "main": "build/index.js",
5
5
  "types": "build/index.d.ts",
6
6
  "repository": "https://github.com/paraswap/paraswap-dex-lib",
package/src/config.ts CHANGED
@@ -30,6 +30,7 @@ type BaseConfig = {
30
30
  hashFlowAuthToken?: string;
31
31
  hashFlowDisabledMMs: string[];
32
32
  swaapV2AuthToken?: string;
33
+ forceRpcFallbackDexs: string[];
33
34
  };
34
35
 
35
36
  const baseConfigs: { [network: number]: BaseConfig } = {
@@ -115,6 +116,7 @@ const baseConfigs: { [network: number]: BaseConfig } = {
115
116
  },
116
117
  },
117
118
  },
119
+ forceRpcFallbackDexs: [],
118
120
  },
119
121
  [Network.ROPSTEN]: {
120
122
  network: Network.ROPSTEN,
@@ -142,6 +144,7 @@ const baseConfigs: { [network: number]: BaseConfig } = {
142
144
  rfqConfigs: {},
143
145
  rpcPollingMaxAllowedStateDelayInBlocks: 5,
144
146
  rpcPollingBlocksBackToTriggerUpdate: 3,
147
+ forceRpcFallbackDexs: [],
145
148
  },
146
149
  [Network.BSC]: {
147
150
  network: Network.BSC,
@@ -168,6 +171,7 @@ const baseConfigs: { [network: number]: BaseConfig } = {
168
171
  uniswapV2ExchangeRouterAddress:
169
172
  '0x53e693c6C7FFC4446c53B205Cf513105Bf140D7b',
170
173
  rfqConfigs: {},
174
+ forceRpcFallbackDexs: [],
171
175
  },
172
176
  [Network.POLYGON]: {
173
177
  network: Network.POLYGON,
@@ -197,6 +201,7 @@ const baseConfigs: { [network: number]: BaseConfig } = {
197
201
  rpcPollingMaxAllowedStateDelayInBlocks: 2,
198
202
  rpcPollingBlocksBackToTriggerUpdate: 1,
199
203
  swaapV2AuthToken: process.env.API_KEY_SWAAP_V2_AUTH_TOKEN || '',
204
+ forceRpcFallbackDexs: [],
200
205
  },
201
206
  [Network.AVALANCHE]: {
202
207
  network: Network.AVALANCHE,
@@ -224,6 +229,7 @@ const baseConfigs: { [network: number]: BaseConfig } = {
224
229
  rfqConfigs: {},
225
230
  rpcPollingMaxAllowedStateDelayInBlocks: 2,
226
231
  rpcPollingBlocksBackToTriggerUpdate: 1,
232
+ forceRpcFallbackDexs: [],
227
233
  },
228
234
  [Network.FANTOM]: {
229
235
  network: Network.FANTOM,
@@ -251,6 +257,7 @@ const baseConfigs: { [network: number]: BaseConfig } = {
251
257
  rfqConfigs: {},
252
258
  rpcPollingMaxAllowedStateDelayInBlocks: 2,
253
259
  rpcPollingBlocksBackToTriggerUpdate: 1,
260
+ forceRpcFallbackDexs: [],
254
261
  },
255
262
  [Network.ARBITRUM]: {
256
263
  network: Network.ARBITRUM,
@@ -279,6 +286,7 @@ const baseConfigs: { [network: number]: BaseConfig } = {
279
286
  rfqConfigs: {},
280
287
  rpcPollingMaxAllowedStateDelayInBlocks: 4,
281
288
  rpcPollingBlocksBackToTriggerUpdate: 3,
289
+ forceRpcFallbackDexs: [],
282
290
  },
283
291
  [Network.OPTIMISM]: {
284
292
  network: Network.OPTIMISM,
@@ -307,6 +315,7 @@ const baseConfigs: { [network: number]: BaseConfig } = {
307
315
  rfqConfigs: {},
308
316
  rpcPollingMaxAllowedStateDelayInBlocks: 5,
309
317
  rpcPollingBlocksBackToTriggerUpdate: 3,
318
+ forceRpcFallbackDexs: [],
310
319
  },
311
320
  };
312
321
 
@@ -350,6 +359,7 @@ export function generateConfig(network: number): Config {
350
359
  hashFlowAuthToken: baseConfig.hashFlowAuthToken,
351
360
  swaapV2AuthToken: baseConfig.swaapV2AuthToken,
352
361
  hashFlowDisabledMMs: baseConfig.hashFlowDisabledMMs,
362
+ forceRpcFallbackDexs: baseConfig.forceRpcFallbackDexs,
353
363
  };
354
364
  }
355
365
 
@@ -359,7 +369,7 @@ export class ConfigHelper {
359
369
  constructor(
360
370
  public isSlave: boolean,
361
371
  public data: Config,
362
- private masterCachePrefix: string,
372
+ masterCachePrefix: string,
363
373
  ) {
364
374
  this.masterBlockNumberCacheKey =
365
375
  `${masterCachePrefix}_${data.network}_bn`.toLowerCase();
@@ -15,21 +15,6 @@ import {
15
15
  import { Tokens } from '../../../tests/constants-e2e';
16
16
  import { Address } from '@paraswap/core';
17
17
 
18
- /*
19
- README
20
- ======
21
-
22
- This test script adds tests for Algebra general integration
23
- with the DEX interface. The test cases below are example tests.
24
- It is recommended to add tests which cover Algebra specific
25
- logic.
26
-
27
- You can run this individual test script by running:
28
- `npx jest src/dex/<dex-name>/<dex-name>-integration.test.ts`
29
-
30
- (This comment should be removed from the final implementation)
31
- */
32
-
33
18
  function getReaderCalldata(
34
19
  exchangeAddress: string,
35
20
  readerIface: Interface,
@@ -70,7 +55,7 @@ async function checkOnChainPricing(
70
55
  tokenOut: Address,
71
56
  amounts: bigint[],
72
57
  ) {
73
- const exchangeAddress = '0xa15f0d7377b2a0c0c10db057f641bed21028fc89'; // Quoter address
58
+ const exchangeAddress = algebra.config.quoter;
74
59
 
75
60
  const readerIface = algebra.quoterIface;
76
61
 
@@ -155,6 +140,199 @@ async function testPricingOnNetwork(
155
140
  );
156
141
  }
157
142
 
143
+ describe('CamelotV3', function () {
144
+ const dexKey = 'CamelotV3';
145
+ let blockNumber: number;
146
+ let algebra: Algebra;
147
+
148
+ describe('Arbitrum', () => {
149
+ const network = Network.ARBITRUM;
150
+ const dexHelper = new DummyDexHelper(network);
151
+
152
+ const tokens = Tokens[network];
153
+
154
+ describe('GRAIL => USDCe', () => {
155
+ const srcTokenSymbol = 'GRAIL';
156
+ const destTokenSymbol = 'USDCe';
157
+
158
+ const amountsForSell = [
159
+ 0n,
160
+ 10n * BI_POWS[tokens[srcTokenSymbol].decimals],
161
+ 20n * BI_POWS[tokens[srcTokenSymbol].decimals],
162
+ 30n * BI_POWS[tokens[srcTokenSymbol].decimals],
163
+ 40n * BI_POWS[tokens[srcTokenSymbol].decimals],
164
+ 50n * BI_POWS[tokens[srcTokenSymbol].decimals],
165
+ 60n * BI_POWS[tokens[srcTokenSymbol].decimals],
166
+ 70n * BI_POWS[tokens[srcTokenSymbol].decimals],
167
+ 80n * BI_POWS[tokens[srcTokenSymbol].decimals],
168
+ 90n * BI_POWS[tokens[srcTokenSymbol].decimals],
169
+ 100n * BI_POWS[tokens[srcTokenSymbol].decimals],
170
+ ];
171
+
172
+ const amountsForBuy = [
173
+ 0n,
174
+ 1n * BI_POWS[tokens[destTokenSymbol].decimals],
175
+ 2n * BI_POWS[tokens[destTokenSymbol].decimals],
176
+ 3n * BI_POWS[tokens[destTokenSymbol].decimals],
177
+ 4n * BI_POWS[tokens[destTokenSymbol].decimals],
178
+ 5n * BI_POWS[tokens[destTokenSymbol].decimals],
179
+ 6n * BI_POWS[tokens[destTokenSymbol].decimals],
180
+ 7n * BI_POWS[tokens[destTokenSymbol].decimals],
181
+ 8n * BI_POWS[tokens[destTokenSymbol].decimals],
182
+ 9n * BI_POWS[tokens[destTokenSymbol].decimals],
183
+ 10n * BI_POWS[tokens[destTokenSymbol].decimals],
184
+ ];
185
+
186
+ beforeAll(async () => {
187
+ blockNumber = await dexHelper.web3Provider.eth.getBlockNumber();
188
+ algebra = new Algebra(network, dexKey, dexHelper);
189
+ if (algebra.initializePricing) {
190
+ await algebra.initializePricing(blockNumber);
191
+ }
192
+ });
193
+
194
+ it('getPoolIdentifiers and getPricesVolume SELL', async function () {
195
+ await testPricingOnNetwork(
196
+ algebra,
197
+ network,
198
+ dexKey,
199
+ dexHelper,
200
+ blockNumber,
201
+ srcTokenSymbol,
202
+ destTokenSymbol,
203
+ SwapSide.SELL,
204
+ amountsForSell,
205
+ 'quoteExactInputSingle',
206
+ );
207
+ });
208
+
209
+ it('getPoolIdentifiers and getPricesVolume BUY', async function () {
210
+ await testPricingOnNetwork(
211
+ algebra,
212
+ network,
213
+ dexKey,
214
+ dexHelper,
215
+ blockNumber,
216
+ srcTokenSymbol,
217
+ destTokenSymbol,
218
+ SwapSide.BUY,
219
+ amountsForBuy,
220
+ 'quoteExactOutputSingle',
221
+ );
222
+ });
223
+
224
+ it('getTopPoolsForToken', async function () {
225
+ // We have to check without calling initializePricing, because
226
+ // pool-tracker is not calling that function
227
+ const newAlgebra = new Algebra(network, dexKey, dexHelper);
228
+ const poolLiquidity = await newAlgebra.getTopPoolsForToken(
229
+ tokens[srcTokenSymbol].address,
230
+ 10,
231
+ );
232
+ console.log(`${srcTokenSymbol} Top Pools:`, poolLiquidity);
233
+
234
+ if (!newAlgebra.hasConstantPriceLargeAmounts) {
235
+ checkPoolsLiquidity(
236
+ poolLiquidity,
237
+ Tokens[network][srcTokenSymbol].address,
238
+ dexKey,
239
+ );
240
+ }
241
+ });
242
+ });
243
+
244
+ describe('USDCe => GRAIL', () => {
245
+ const srcTokenSymbol = 'USDCe';
246
+ const destTokenSymbol = 'GRAIL';
247
+
248
+ const amountsForSell = [
249
+ 0n,
250
+ 10n * BI_POWS[tokens[srcTokenSymbol].decimals],
251
+ 20n * BI_POWS[tokens[srcTokenSymbol].decimals],
252
+ 30n * BI_POWS[tokens[srcTokenSymbol].decimals],
253
+ 40n * BI_POWS[tokens[srcTokenSymbol].decimals],
254
+ 50n * BI_POWS[tokens[srcTokenSymbol].decimals],
255
+ 60n * BI_POWS[tokens[srcTokenSymbol].decimals],
256
+ 70n * BI_POWS[tokens[srcTokenSymbol].decimals],
257
+ 80n * BI_POWS[tokens[srcTokenSymbol].decimals],
258
+ 90n * BI_POWS[tokens[srcTokenSymbol].decimals],
259
+ 100n * BI_POWS[tokens[srcTokenSymbol].decimals],
260
+ ];
261
+
262
+ const amountsForBuy = [
263
+ 0n,
264
+ 1n * BI_POWS[tokens[destTokenSymbol].decimals],
265
+ 2n * BI_POWS[tokens[destTokenSymbol].decimals],
266
+ 3n * BI_POWS[tokens[destTokenSymbol].decimals],
267
+ 4n * BI_POWS[tokens[destTokenSymbol].decimals],
268
+ 5n * BI_POWS[tokens[destTokenSymbol].decimals],
269
+ 6n * BI_POWS[tokens[destTokenSymbol].decimals],
270
+ 7n * BI_POWS[tokens[destTokenSymbol].decimals],
271
+ 8n * BI_POWS[tokens[destTokenSymbol].decimals],
272
+ 9n * BI_POWS[tokens[destTokenSymbol].decimals],
273
+ 10n * BI_POWS[tokens[destTokenSymbol].decimals],
274
+ ];
275
+
276
+ beforeAll(async () => {
277
+ blockNumber = await dexHelper.web3Provider.eth.getBlockNumber();
278
+ algebra = new Algebra(network, dexKey, dexHelper);
279
+ if (algebra.initializePricing) {
280
+ await algebra.initializePricing(blockNumber);
281
+ }
282
+ });
283
+
284
+ it('getPoolIdentifiers and getPricesVolume SELL', async function () {
285
+ await testPricingOnNetwork(
286
+ algebra,
287
+ network,
288
+ dexKey,
289
+ dexHelper,
290
+ blockNumber,
291
+ srcTokenSymbol,
292
+ destTokenSymbol,
293
+ SwapSide.SELL,
294
+ amountsForSell,
295
+ 'quoteExactInputSingle',
296
+ );
297
+ });
298
+
299
+ it('getPoolIdentifiers and getPricesVolume BUY', async function () {
300
+ await testPricingOnNetwork(
301
+ algebra,
302
+ network,
303
+ dexKey,
304
+ dexHelper,
305
+ blockNumber,
306
+ srcTokenSymbol,
307
+ destTokenSymbol,
308
+ SwapSide.BUY,
309
+ amountsForBuy,
310
+ 'quoteExactOutputSingle',
311
+ );
312
+ });
313
+
314
+ it('getTopPoolsForToken', async function () {
315
+ // We have to check without calling initializePricing, because
316
+ // pool-tracker is not calling that function
317
+ const newAlgebra = new Algebra(network, dexKey, dexHelper);
318
+ const poolLiquidity = await newAlgebra.getTopPoolsForToken(
319
+ tokens[srcTokenSymbol].address,
320
+ 10,
321
+ );
322
+ console.log(`${srcTokenSymbol} Top Pools:`, poolLiquidity);
323
+
324
+ if (!newAlgebra.hasConstantPriceLargeAmounts) {
325
+ checkPoolsLiquidity(
326
+ poolLiquidity,
327
+ Tokens[network][srcTokenSymbol].address,
328
+ dexKey,
329
+ );
330
+ }
331
+ });
332
+ });
333
+ });
334
+ });
335
+
158
336
  describe('Algebra', function () {
159
337
  const dexKey = 'QuickSwapV3';
160
338
  let blockNumber: number;
@@ -88,7 +88,7 @@ export class Algebra extends SimpleExchange implements IDex<AlgebraData> {
88
88
  protected adapters = Adapters[network] || {},
89
89
  readonly routerIface = new Interface(UniswapV3RouterABI), // same abi as uniswapV3
90
90
  readonly quoterIface = new Interface(AlgebraQuoterABI),
91
- protected config = AlgebraConfig[dexKey][network],
91
+ readonly config = AlgebraConfig[dexKey][network],
92
92
  ) {
93
93
  super(dexHelper, dexKey);
94
94
  this.logger = dexHelper.getLogger(dexKey + '-' + network);
@@ -104,6 +104,10 @@ export class Algebra extends SimpleExchange implements IDex<AlgebraData> {
104
104
  this.dexHelper.web3Provider.eth.handleRevert = false;
105
105
 
106
106
  this.config = this._toLowerForAllConfigAddresses();
107
+ // External configuration has priority over internal
108
+ this.config.forceRPC = dexHelper.config.data.forceRpcFallbackDexs.includes(
109
+ dexKey.toLowerCase(),
110
+ );
107
111
 
108
112
  this.notExistingPoolSetKey =
109
113
  `${CACHE_PREFIX}_${network}_${dexKey}_not_existings_pool_set`.toLowerCase();
@@ -82,7 +82,6 @@ export const AlgebraConfig: DexConfigMap<DexParams> = {
82
82
  uniswapMulticall: '0x1F98415757620B543A52E61c46B32eB19261F984',
83
83
  deployer: '0x6dd3fb9653b10e806650f107c3b5a0a6ff974f65',
84
84
  version: 'v1.9',
85
- forceRPC: true,
86
85
  },
87
86
  },
88
87
  };