@paraswap/dex-lib 3.8.14 → 3.8.16

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 (211) hide show
  1. package/build/abi/concentrator/arUSD.json +568 -0
  2. package/build/abi/concentrator/arUSD5115.json +1746 -0
  3. package/build/abi/fx-protocol/FxMarket.json +1284 -0
  4. package/build/abi/{wombat/pool.json → fx-protocol/FxUSD.json} +541 -603
  5. package/build/abi/fx-protocol/weETHOralce.json +676 -0
  6. package/build/abi/inception/inception-ineth-pool.json +1062 -0
  7. package/build/abi/inception/inception-ineth.json +609 -0
  8. package/build/abi/inception/inception-ratio-feed.json +93 -0
  9. package/build/abi/inception/inception-vault.json +991 -0
  10. package/build/abi/infusion/InfusionFactory.json +147 -0
  11. package/build/abi/infusion/InfusionPair.json +658 -0
  12. package/build/abi/infusion/InfusionRouter.json +442 -0
  13. package/build/abi/oswap/oswap.abi.json +452 -0
  14. package/build/dex/aave-v1/aave-v1.js +0 -1
  15. package/build/dex/aave-v1/aave-v1.js.map +1 -1
  16. package/build/dex/angle-transmuter/angle-transmuter.js +1 -1
  17. package/build/dex/angle-transmuter/angle-transmuter.js.map +1 -1
  18. package/build/dex/concentrator-arusd/concentrator-arusd-event.d.ts +17 -0
  19. package/build/dex/concentrator-arusd/concentrator-arusd-event.js +66 -0
  20. package/build/dex/concentrator-arusd/concentrator-arusd-event.js.map +1 -0
  21. package/build/dex/concentrator-arusd/concentrator-arusd.d.ts +41 -0
  22. package/build/dex/concentrator-arusd/concentrator-arusd.js +188 -0
  23. package/build/dex/concentrator-arusd/concentrator-arusd.js.map +1 -0
  24. package/build/dex/concentrator-arusd/config.d.ts +3 -0
  25. package/build/dex/concentrator-arusd/config.js +14 -0
  26. package/build/dex/concentrator-arusd/config.js.map +1 -0
  27. package/build/dex/concentrator-arusd/types.d.ts +14 -0
  28. package/build/dex/concentrator-arusd/types.js +3 -0
  29. package/build/dex/concentrator-arusd/types.js.map +1 -0
  30. package/build/dex/concentrator-arusd/utils.d.ts +4 -0
  31. package/build/dex/concentrator-arusd/utils.js +27 -0
  32. package/build/dex/concentrator-arusd/utils.js.map +1 -0
  33. package/build/dex/fx-protocol-rusd/config.d.ts +3 -0
  34. package/build/dex/fx-protocol-rusd/config.js +15 -0
  35. package/build/dex/fx-protocol-rusd/config.js.map +1 -0
  36. package/build/dex/fx-protocol-rusd/fx-protocol-rusd-event.d.ts +18 -0
  37. package/build/dex/fx-protocol-rusd/fx-protocol-rusd-event.js +71 -0
  38. package/build/dex/fx-protocol-rusd/fx-protocol-rusd-event.js.map +1 -0
  39. package/build/dex/fx-protocol-rusd/fx-protocol-rusd.d.ts +39 -0
  40. package/build/dex/fx-protocol-rusd/fx-protocol-rusd.js +201 -0
  41. package/build/dex/fx-protocol-rusd/fx-protocol-rusd.js.map +1 -0
  42. package/build/dex/fx-protocol-rusd/types.d.ts +13 -0
  43. package/build/dex/fx-protocol-rusd/types.js +3 -0
  44. package/build/dex/fx-protocol-rusd/types.js.map +1 -0
  45. package/build/dex/fx-protocol-rusd/utils.d.ts +4 -0
  46. package/build/dex/fx-protocol-rusd/utils.js +26 -0
  47. package/build/dex/fx-protocol-rusd/utils.js.map +1 -0
  48. package/build/dex/idex.d.ts +11 -7
  49. package/build/dex/idle-dao/idle-dao-pool.d.ts +56 -0
  50. package/build/dex/idle-dao/idle-dao-pool.js +176 -0
  51. package/build/dex/idle-dao/idle-dao-pool.js.map +1 -0
  52. package/build/dex/idle-dao/idle-dao-pooling-pool.d.ts +16 -0
  53. package/build/dex/idle-dao/idle-dao-pooling-pool.js +57 -0
  54. package/build/dex/idle-dao/idle-dao-pooling-pool.js.map +1 -0
  55. package/build/dex/idle-dao/scripts.d.ts +9 -0
  56. package/build/dex/idle-dao/scripts.js +552 -0
  57. package/build/dex/idle-dao/scripts.js.map +1 -0
  58. package/build/dex/inception/config.d.ts +5 -0
  59. package/build/dex/inception/config.js +112 -0
  60. package/build/dex/inception/config.js.map +1 -0
  61. package/build/dex/inception/inception-event-pool.d.ts +23 -0
  62. package/build/dex/inception/inception-event-pool.js +34 -0
  63. package/build/dex/inception/inception-event-pool.js.map +1 -0
  64. package/build/dex/inception/inception-native.d.ts +43 -0
  65. package/build/dex/inception/inception-native.js +131 -0
  66. package/build/dex/inception/inception-native.js.map +1 -0
  67. package/build/dex/inception/inception-pool.d.ts +18 -0
  68. package/build/dex/inception/inception-pool.js +32 -0
  69. package/build/dex/inception/inception-pool.js.map +1 -0
  70. package/build/dex/inception/inception-price-feed.d.ts +19 -0
  71. package/build/dex/inception/inception-price-feed.js +51 -0
  72. package/build/dex/inception/inception-price-feed.js.map +1 -0
  73. package/build/dex/inception/inception.d.ts +44 -0
  74. package/build/dex/inception/inception.js +162 -0
  75. package/build/dex/inception/inception.js.map +1 -0
  76. package/build/dex/inception/tokens.d.ts +9 -0
  77. package/build/dex/inception/tokens.js +28 -0
  78. package/build/dex/inception/tokens.js.map +1 -0
  79. package/build/dex/inception/types.d.ts +22 -0
  80. package/build/dex/inception/types.js +3 -0
  81. package/build/dex/inception/types.js.map +1 -0
  82. package/build/dex/inception/utils.d.ts +7 -0
  83. package/build/dex/inception/utils.js +58 -0
  84. package/build/dex/inception/utils.js.map +1 -0
  85. package/build/dex/index.js +4 -0
  86. package/build/dex/index.js.map +1 -1
  87. package/build/dex/infusion/config.d.ts +4 -0
  88. package/build/dex/infusion/config.js +25 -0
  89. package/build/dex/infusion/config.js.map +1 -0
  90. package/build/dex/infusion/infusion-stable-pool.d.ts +4 -0
  91. package/build/dex/infusion/infusion-stable-pool.js +74 -0
  92. package/build/dex/infusion/infusion-stable-pool.js.map +1 -0
  93. package/build/dex/infusion/infusion.d.ts +54 -0
  94. package/build/dex/infusion/infusion.js +510 -0
  95. package/build/dex/infusion/infusion.js.map +1 -0
  96. package/build/dex/infusion/types.d.ts +47 -0
  97. package/build/dex/infusion/types.js +3 -0
  98. package/build/dex/infusion/types.js.map +1 -0
  99. package/build/dex/infusion/utils/isStablePair.d.ts +2 -0
  100. package/build/dex/infusion/utils/isStablePair.js +18 -0
  101. package/build/dex/infusion/utils/isStablePair.js.map +1 -0
  102. package/build/dex/oswap/config.d.ts +5 -0
  103. package/build/dex/oswap/config.js +31 -0
  104. package/build/dex/oswap/config.js.map +1 -0
  105. package/build/dex/oswap/oswap-pool.d.ts +51 -0
  106. package/build/dex/oswap/oswap-pool.js +150 -0
  107. package/build/dex/oswap/oswap-pool.js.map +1 -0
  108. package/build/dex/oswap/oswap.d.ts +46 -0
  109. package/build/dex/oswap/oswap.js +263 -0
  110. package/build/dex/oswap/oswap.js.map +1 -0
  111. package/build/dex/oswap/types.d.ts +20 -0
  112. package/build/dex/oswap/types.js +3 -0
  113. package/build/dex/oswap/types.js.map +1 -0
  114. package/build/dex/platypus/platypus.js +3 -17
  115. package/build/dex/platypus/platypus.js.map +1 -1
  116. package/build/dex/swaap-v1/swaap-v1.js +0 -4
  117. package/build/dex/swaap-v1/swaap-v1.js.map +1 -1
  118. package/build/dex/weth/config.js +3 -0
  119. package/build/dex/weth/config.js.map +1 -1
  120. package/package.json +1 -1
  121. package/src/abi/concentrator/arUSD.json +568 -0
  122. package/src/abi/concentrator/arUSD5115.json +1746 -0
  123. package/src/abi/fx-protocol/FxMarket.json +1284 -0
  124. package/src/abi/fx-protocol/FxUSD.json +1227 -0
  125. package/src/abi/fx-protocol/weETHOralce.json +676 -0
  126. package/src/dex/angle-transmuter/angle-transmuter.ts +1 -1
  127. package/src/dex/concentrator-arusd/concentrator-arusd-e2e.test.ts +92 -0
  128. package/src/dex/concentrator-arusd/concentrator-arusd-event.ts +100 -0
  129. package/src/dex/concentrator-arusd/concentrator-arusd-integration.test.ts +104 -0
  130. package/src/dex/concentrator-arusd/concentrator-arusd.ts +269 -0
  131. package/src/dex/concentrator-arusd/concetrator-arusd-events.test.ts +97 -0
  132. package/src/dex/concentrator-arusd/config.ts +13 -0
  133. package/src/dex/concentrator-arusd/types.ts +16 -0
  134. package/src/dex/concentrator-arusd/utils.ts +36 -0
  135. package/src/dex/fx-protocol-rusd/config.ts +14 -0
  136. package/src/dex/fx-protocol-rusd/fx-protocol-e2e.test.ts +96 -0
  137. package/src/dex/fx-protocol-rusd/fx-protocol-events.test.ts +101 -0
  138. package/src/dex/fx-protocol-rusd/fx-protocol-integration.test.ts +104 -0
  139. package/src/dex/fx-protocol-rusd/fx-protocol-rusd-event.ts +112 -0
  140. package/src/dex/fx-protocol-rusd/fx-protocol-rusd.ts +282 -0
  141. package/src/dex/fx-protocol-rusd/types.ts +16 -0
  142. package/src/dex/fx-protocol-rusd/utils.ts +47 -0
  143. package/src/dex/idex.ts +48 -41
  144. package/src/dex/index.ts +4 -0
  145. package/src/dex/weth/config.ts +3 -0
  146. package/src/dex/weth/weth-e2e.test.ts +156 -0
  147. package/src/dex/wsteth/wsteth-integration.test.ts +0 -1
  148. package/tests/constants-e2e.ts +10 -0
  149. package/.vscode/launch.json +0 -53
  150. package/.vscode/settings.json +0 -2
  151. package/.vscode/tasks.json +0 -15
  152. package/build/abi/maverick-v2/MaverickV2Router.json +0 -778
  153. package/build/abi/uniswap-v3/AlienBaseV3Router.abi.json +0 -52
  154. package/build/dex/aave-v2/tokens-avalanche.json +0 -44
  155. package/build/dex/aave-v2/tokens-mainnet.json +0 -188
  156. package/build/dex/aave-v2/tokens-polygon.json +0 -44
  157. package/build/dex/bProtocol.d.ts +0 -18
  158. package/build/dex/bProtocol.js +0 -39
  159. package/build/dex/bProtocol.js.map +0 -1
  160. package/build/dex/bancor.d.ts +0 -26
  161. package/build/dex/bancor.js +0 -58
  162. package/build/dex/bancor.js.map +0 -1
  163. package/build/dex/compound.d.ts +0 -18
  164. package/build/dex/compound.js +0 -46
  165. package/build/dex/compound.js.map +0 -1
  166. package/build/dex/curve-v2.d.ts +0 -58
  167. package/build/dex/curve-v2.js +0 -180
  168. package/build/dex/curve-v2.js.map +0 -1
  169. package/build/dex/dodo-v1.d.ts +0 -33
  170. package/build/dex/dodo-v1.js +0 -63
  171. package/build/dex/dodo-v1.js.map +0 -1
  172. package/build/dex/lido.d.ts +0 -19
  173. package/build/dex/lido.js +0 -42
  174. package/build/dex/lido.js.map +0 -1
  175. package/build/dex/maker-psm/scripts/gem.abi.json +0 -136
  176. package/build/dex/maker-psm/scripts/validate-state.d.ts +0 -0
  177. package/build/dex/maker-psm/scripts/validate-state.js +0 -185
  178. package/build/dex/maker-psm/scripts/validate-state.js.map +0 -1
  179. package/build/dex/maker-psm/scripts/vat.abi.json +0 -243
  180. package/build/dex/onebit.d.ts +0 -25
  181. package/build/dex/onebit.js +0 -42
  182. package/build/dex/onebit.js.map +0 -1
  183. package/build/dex/smoothy.d.ts +0 -26
  184. package/build/dex/smoothy.js +0 -48
  185. package/build/dex/smoothy.js.map +0 -1
  186. package/build/dex/solidly-v3/scripts/check-event-pool-event.d.ts +0 -1
  187. package/build/dex/solidly-v3/scripts/check-event-pool-event.js +0 -53
  188. package/build/dex/solidly-v3/scripts/check-event-pool-event.js.map +0 -1
  189. package/build/dex/stable-pool.d.ts +0 -28
  190. package/build/dex/stable-pool.js +0 -55
  191. package/build/dex/stable-pool.js.map +0 -1
  192. package/build/dex/trader-joe-v2.1/base.d.ts +0 -18
  193. package/build/dex/trader-joe-v2.1/base.js +0 -99
  194. package/build/dex/trader-joe-v2.1/base.js.map +0 -1
  195. package/build/dex/trader-joe-v2.1/trader-joe-v2.1-new.d.ts +0 -7
  196. package/build/dex/trader-joe-v2.1/trader-joe-v2.1-new.js +0 -20
  197. package/build/dex/trader-joe-v2.1/trader-joe-v2.1-new.js.map +0 -1
  198. package/build/dex/trader-joe-v2.1/trader-joe-v2.2.d.ts +0 -7
  199. package/build/dex/trader-joe-v2.1/trader-joe-v2.2.js +0 -20
  200. package/build/dex/trader-joe-v2.1/trader-joe-v2.2.js.map +0 -1
  201. package/build/dex/trader-joe-v2.1.d.ts +0 -43
  202. package/build/dex/trader-joe-v2.1.js +0 -79
  203. package/build/dex/trader-joe-v2.1.js.map +0 -1
  204. package/build/dex/uniswap-v3/forks/alien-base-v3/alien-base-v3.d.ts +0 -17
  205. package/build/dex/uniswap-v3/forks/alien-base-v3/alien-base-v3.js +0 -64
  206. package/build/dex/uniswap-v3/forks/alien-base-v3/alien-base-v3.js.map +0 -1
  207. package/build/dex/uniswap-v3/forks/alien-v3/alien-v3.d.ts +0 -17
  208. package/build/dex/uniswap-v3/forks/alien-v3/alien-v3.js +0 -79
  209. package/build/dex/uniswap-v3/forks/alien-v3/alien-v3.js.map +0 -1
  210. package/config.ts +0 -1946
  211. package/src/dex/dexs.txt +0 -58
@@ -0,0 +1,282 @@
1
+ import {
2
+ Token,
3
+ Address,
4
+ ExchangePrices,
5
+ PoolPrices,
6
+ AdapterExchangeParam,
7
+ Logger,
8
+ NumberAsString,
9
+ DexExchangeParam,
10
+ PoolLiquidity,
11
+ } from '../../types';
12
+ import { SwapSide, Network } from '../../constants';
13
+ import * as CALLDATA_GAS_COST from '../../calldata-gas-cost';
14
+ import { getDexKeysWithNetwork } from '../../utils';
15
+ import { IDex } from '../idex';
16
+ import { IDexHelper } from '../../dex-helper/idex-helper';
17
+ import { DexParams, FxProtocolData } from './types';
18
+ import { SimpleExchange } from '../simple-exchange';
19
+ import { FxProtocolConfig } from './config';
20
+ import { Interface, JsonFragment } from '@ethersproject/abi';
21
+ import FxUSD_ABI from '../../abi/fx-protocol/FxUSD.json';
22
+ import FxMarket_ABI from '../../abi/fx-protocol/FxMarket.json';
23
+ import EthWeETHOralce_ABI from '../../abi/fx-protocol/weETHOralce.json';
24
+
25
+ import { extractReturnAmountPosition } from '../../executor/utils';
26
+ import { FxProtocolRusdEvent } from './fx-protocol-rusd-event';
27
+ import { BI_POWS } from '../../bigint-constants';
28
+ import { getOnChainState } from './utils';
29
+
30
+ export class FxProtocolRusd
31
+ extends SimpleExchange
32
+ implements IDex<FxProtocolData>
33
+ {
34
+ protected config: DexParams;
35
+
36
+ readonly hasConstantPriceLargeAmounts = true;
37
+
38
+ readonly needWrapNative = false;
39
+
40
+ readonly isFeeOnTransferSupported = false;
41
+
42
+ public static dexKeysWithNetwork: { key: string; networks: Network[] }[] =
43
+ getDexKeysWithNetwork(FxProtocolConfig);
44
+
45
+ fxUSDIface: Interface;
46
+ rUSDMarketIface: Interface;
47
+ weETHOracleIface: Interface;
48
+ fxProtocolRusdPool: FxProtocolRusdEvent;
49
+ logger: Logger;
50
+
51
+ constructor(
52
+ readonly network: Network,
53
+ readonly dexKey: string,
54
+ readonly dexHelper: IDexHelper,
55
+ ) {
56
+ super(dexHelper, dexKey);
57
+ const config = FxProtocolConfig[dexKey][network];
58
+ this.fxUSDIface = new Interface(FxUSD_ABI as JsonFragment[]);
59
+ this.rUSDMarketIface = new Interface(FxMarket_ABI as JsonFragment[]);
60
+ this.weETHOracleIface = new Interface(EthWeETHOralce_ABI as JsonFragment[]);
61
+ this.config = {
62
+ rUSDAddress: config.rUSDAddress.toLowerCase(),
63
+ weETHAddress: config.weETHAddress.toLowerCase(),
64
+ rUSDWeETHMarketAddress: config.rUSDWeETHMarketAddress.toLowerCase(),
65
+ weETHOracleAddress: config.weETHOracleAddress.toLowerCase(),
66
+ };
67
+ this.logger = dexHelper.getLogger(dexKey);
68
+ this.fxProtocolRusdPool = new FxProtocolRusdEvent(
69
+ this.dexKey,
70
+ dexHelper,
71
+ this.config.rUSDWeETHMarketAddress,
72
+ this.rUSDMarketIface,
73
+ this.config.weETHOracleAddress,
74
+ this.weETHOracleIface,
75
+ this.logger,
76
+ );
77
+ }
78
+
79
+ async initializePricing(blockNumber: number) {
80
+ const poolState = await getOnChainState(
81
+ this.dexHelper.multiContract,
82
+ this.config.rUSDWeETHMarketAddress,
83
+ this.rUSDMarketIface,
84
+ this.config.weETHOracleAddress,
85
+ this.weETHOracleIface,
86
+ blockNumber,
87
+ );
88
+
89
+ await this.fxProtocolRusdPool.initialize(blockNumber, {
90
+ state: poolState,
91
+ });
92
+ }
93
+
94
+ getConfig() {
95
+ return this.config;
96
+ }
97
+
98
+ is_weETH(token: string) {
99
+ return token.toLowerCase() === this.config.weETHAddress.toLowerCase();
100
+ }
101
+
102
+ is_rUSD(token: string) {
103
+ return token.toLowerCase() === this.config.rUSDAddress.toLowerCase();
104
+ }
105
+
106
+ is_rUSD_swap_token(srcToken: string, destToken: string) {
107
+ return (
108
+ (this.is_weETH(srcToken) && this.is_rUSD(destToken)) ||
109
+ (this.is_rUSD(srcToken) && this.is_weETH(destToken))
110
+ );
111
+ }
112
+ // Returns the list of contract adapters (name and index)
113
+ // for a buy/sell. Return null if there are no adapters.
114
+ getAdapters() {
115
+ return null;
116
+ }
117
+
118
+ async getPoolIdentifiers(
119
+ srcToken: Token,
120
+ destToken: Token,
121
+ side: SwapSide,
122
+ blockNumber: number,
123
+ ): Promise<string[]> {
124
+ if (!this.is_rUSD_swap_token(srcToken.address, destToken.address)) {
125
+ return [];
126
+ }
127
+ return [`${this.dexKey}_${this.config.rUSDAddress}`];
128
+ }
129
+
130
+ async getPricesVolume(
131
+ srcToken: Token,
132
+ destToken: Token,
133
+ amounts: bigint[],
134
+ side: SwapSide,
135
+ blockNumber: number,
136
+ limitPools?: string[],
137
+ ): Promise<null | ExchangePrices<FxProtocolData>> {
138
+ // note: BUY is not supported
139
+ if (side === SwapSide.BUY) return null;
140
+
141
+ const isRUSDSwapToken = this.is_rUSD_swap_token(
142
+ srcToken.address,
143
+ destToken.address,
144
+ );
145
+ if (!isRUSDSwapToken) {
146
+ return null;
147
+ }
148
+ const pool = this.fxProtocolRusdPool;
149
+ const is_redeem = this.is_weETH(destToken.address);
150
+ const unitIn = BI_POWS[18];
151
+ const unitOut = await pool.getPrice(blockNumber, unitIn, is_redeem);
152
+ const amountsOut = await Promise.all(
153
+ amounts.map(_amountIn =>
154
+ pool.getPrice(blockNumber, _amountIn, is_redeem),
155
+ ),
156
+ );
157
+
158
+ return [
159
+ {
160
+ unit: unitOut,
161
+ prices: amountsOut,
162
+ data: {},
163
+ poolAddresses: [this.config.rUSDAddress],
164
+ exchange: this.dexKey,
165
+ gasCost: 1000000,
166
+ },
167
+ ];
168
+ }
169
+
170
+ // Returns estimated gas cost of calldata for this DEX in multiSwap
171
+ getCalldataGasCost(
172
+ poolPrices: PoolPrices<FxProtocolData>,
173
+ ): number | number[] {
174
+ return CALLDATA_GAS_COST.DEX_NO_PAYLOAD;
175
+ }
176
+
177
+ // Encode params required by the exchange adapter
178
+ // V5: Used for multiSwap, buy & megaSwap
179
+ // V6: Not used, can be left blank
180
+ // Hint: abiCoder.encodeParameter() could be useful
181
+ getAdapterParam(
182
+ srcToken: string,
183
+ destToken: string,
184
+ srcAmount: string,
185
+ destAmount: string,
186
+ data: FxProtocolData,
187
+ side: SwapSide,
188
+ ): AdapterExchangeParam {
189
+ const payload = '0x';
190
+
191
+ return {
192
+ targetExchange: this.config.rUSDAddress,
193
+ payload,
194
+ networkFee: '0',
195
+ };
196
+ }
197
+
198
+ async getDexParam(
199
+ srcToken: Address,
200
+ destToken: Address,
201
+ srcAmount: NumberAsString,
202
+ destAmount: NumberAsString,
203
+ recipient: Address,
204
+ data: FxProtocolData,
205
+ side: SwapSide,
206
+ ): Promise<DexExchangeParam> {
207
+ const is_rUSD_src = this.is_rUSD(srcToken);
208
+ const is_weETH_src = this.is_weETH(srcToken);
209
+ const is_rUSD_dest = this.is_rUSD(destToken);
210
+ const is_weETH_dest = this.is_weETH(destToken);
211
+
212
+ if (is_weETH_src && is_rUSD_dest) {
213
+ const exchangeData = this.fxUSDIface.encodeFunctionData('mint', [
214
+ this.config.weETHAddress,
215
+ srcAmount,
216
+ recipient,
217
+ '0',
218
+ ]);
219
+ return {
220
+ needWrapNative: false,
221
+ dexFuncHasRecipient: true,
222
+ exchangeData,
223
+ targetExchange: this.config.rUSDAddress,
224
+ returnAmountPos: extractReturnAmountPosition(
225
+ this.fxUSDIface,
226
+ 'mint',
227
+ '_amountOut',
228
+ ),
229
+ };
230
+ }
231
+ if (is_rUSD_src && is_weETH_dest) {
232
+ const exchangeData = this.fxUSDIface.encodeFunctionData('redeem', [
233
+ this.config.weETHAddress,
234
+ srcAmount,
235
+ recipient,
236
+ '0',
237
+ ]);
238
+ return {
239
+ needWrapNative: false,
240
+ dexFuncHasRecipient: true,
241
+ exchangeData,
242
+ targetExchange: this.config.rUSDAddress,
243
+ returnAmountPos: extractReturnAmountPosition(
244
+ this.fxUSDIface,
245
+ 'redeem',
246
+ '_amountOut',
247
+ ),
248
+ };
249
+ }
250
+ throw new Error('LOGIC ERROR');
251
+ }
252
+
253
+ // Returns list of top pools based on liquidity. Max
254
+ // limit number pools should be returned.
255
+ async getTopPoolsForToken(
256
+ tokenAddress: Address,
257
+ limit: number,
258
+ ): Promise<PoolLiquidity[]> {
259
+ if (!this.is_rUSD(tokenAddress) && !this.is_weETH(tokenAddress)) return [];
260
+
261
+ return [
262
+ {
263
+ exchange: this.dexKey,
264
+ address: this.config.rUSDAddress,
265
+ connectorTokens: this.is_weETH(tokenAddress)
266
+ ? [
267
+ {
268
+ decimals: 18,
269
+ address: this.config.rUSDAddress,
270
+ },
271
+ ]
272
+ : [
273
+ {
274
+ decimals: 18,
275
+ address: this.config.weETHAddress,
276
+ },
277
+ ],
278
+ liquidityUSD: 1000000000, // Just returning a big number so this DEX will be preferred
279
+ },
280
+ ];
281
+ }
282
+ }
@@ -0,0 +1,16 @@
1
+ import { Address } from '../../types';
2
+
3
+ export type FxProtocolPoolState = {
4
+ nav: string;
5
+ redeemFee: string;
6
+ weETHPrice: string;
7
+ };
8
+
9
+ export type FxProtocolData = {};
10
+
11
+ export type DexParams = {
12
+ rUSDAddress: Address;
13
+ weETHAddress: Address;
14
+ rUSDWeETHMarketAddress: Address;
15
+ weETHOracleAddress: Address;
16
+ };
@@ -0,0 +1,47 @@
1
+ import { Contract } from 'web3-eth-contract';
2
+ import { FxProtocolPoolState } from './types';
3
+ import { Interface } from '@ethersproject/abi';
4
+
5
+ export async function getOnChainState(
6
+ multiContract: Contract,
7
+ marketAddress: string,
8
+ marketInterface: Interface,
9
+ ethWeETHOracleAddress: string,
10
+ ethWeETHOracleIface: Interface,
11
+ blockNumber: number | 'latest',
12
+ ): Promise<FxProtocolPoolState> {
13
+ const data: { returnData: any[] } = await multiContract.methods
14
+ .aggregate([
15
+ {
16
+ target: marketAddress,
17
+ callData: marketInterface.encodeFunctionData(
18
+ 'fTokenRedeemFeeRatio',
19
+ [],
20
+ ),
21
+ },
22
+ {
23
+ target: ethWeETHOracleAddress,
24
+ callData: ethWeETHOracleIface.encodeFunctionData('latestAnswer', []),
25
+ },
26
+ ])
27
+ .call({}, blockNumber);
28
+
29
+ const redeemFee = BigInt(
30
+ marketInterface.decodeFunctionResult(
31
+ 'fTokenRedeemFeeRatio',
32
+ data.returnData[0],
33
+ )[0],
34
+ ).toString();
35
+ const weETHPrice = BigInt(
36
+ ethWeETHOracleIface.decodeFunctionResult(
37
+ 'latestAnswer',
38
+ data.returnData[1],
39
+ )[0],
40
+ ).toString();
41
+
42
+ return {
43
+ nav: '1000000000000000000',
44
+ redeemFee,
45
+ weETHPrice,
46
+ };
47
+ }
package/src/dex/idex.ts CHANGED
@@ -24,34 +24,7 @@ export type Context = {
24
24
  isGlobalDestToken: boolean;
25
25
  };
26
26
 
27
- export interface IDexTxBuilder<ExchangeData, DirectParam = null> {
28
- needWrapNative: boolean;
29
- needsSequentialPreprocessing?: boolean;
30
-
31
- // Returns the ETH fee required to swap
32
- // It is optional for a DEX to implement this
33
- // This is a legacy function and will be removed soon
34
- getNetworkFee?(
35
- srcToken: Address,
36
- destToken: Address,
37
- srcAmount: NumberAsString,
38
- destAmount: NumberAsString,
39
- data: ExchangeData,
40
- side: SwapSide,
41
- ): NumberAsString;
42
-
43
- // If exists, called before getAdapterParam to use async calls and receive data if needed
44
- preProcessTransaction?(
45
- optimalSwapExchange: OptimalSwapExchange<ExchangeData>,
46
- srcToken: Token,
47
- destToken: Token,
48
- side: SwapSide,
49
- options: PreprocessTransactionOptions,
50
- ): AsyncOrSync<[OptimalSwapExchange<ExchangeData>, ExchangeTxInfo]>;
51
-
52
- // This is helper a function to support testing if preProcessTransaction is implemented
53
- getTokenFromAddress?(address: Address): Token;
54
-
27
+ export interface IDexTxBuilderV5<ExchangeData, DirectParam = null> {
55
28
  // Encode params required by the exchange adapter
56
29
  // V5: Used for multiSwap, buy & megaSwap
57
30
  // V6: NOT used, pass a placeholder
@@ -76,18 +49,6 @@ export interface IDexTxBuilder<ExchangeData, DirectParam = null> {
76
49
  side: SwapSide,
77
50
  ): AsyncOrSync<SimpleExchangeParam>;
78
51
 
79
- getDexParam?(
80
- srcToken: Address,
81
- destToken: Address,
82
- srcAmount: NumberAsString,
83
- destAmount: NumberAsString,
84
- recipient: Address,
85
- data: ExchangeData,
86
- side: SwapSide,
87
- context: Context,
88
- executorAddress: Address,
89
- ): AsyncOrSync<DexExchangeParam>;
90
-
91
52
  // Returns params required by direct swap method.
92
53
  // Only Dexes which have a direct method should implement this
93
54
  // Used if there is a possibility for direct swap (Eg. UniswapV2,
@@ -108,8 +69,23 @@ export interface IDexTxBuilder<ExchangeData, DirectParam = null> {
108
69
  beneficiary: string,
109
70
  contractMethod: string,
110
71
  ): TxInfo<DirectParam>;
72
+ }
111
73
 
112
- // Same as above but for V6
74
+ export interface IDexTxBuilderV6<ExchangeData, DirectParam = null> {
75
+ // Returns params required by generic method
76
+ getDexParam?(
77
+ srcToken: Address,
78
+ destToken: Address,
79
+ srcAmount: NumberAsString,
80
+ destAmount: NumberAsString,
81
+ recipient: Address,
82
+ data: ExchangeData,
83
+ side: SwapSide,
84
+ context: Context,
85
+ executorAddress: Address,
86
+ ): AsyncOrSync<DexExchangeParam>;
87
+
88
+ // Returns params for direct method
113
89
  getDirectParamV6?(
114
90
  srcToken: Address,
115
91
  destToken: Address,
@@ -127,6 +103,37 @@ export interface IDexTxBuilder<ExchangeData, DirectParam = null> {
127
103
  ): TxInfo<DirectParam>;
128
104
  }
129
105
 
106
+ export interface IDexTxBuilder<ExchangeData, DirectParam = null>
107
+ extends IDexTxBuilderV5<ExchangeData, DirectParam>,
108
+ IDexTxBuilderV6<ExchangeData, DirectParam> {
109
+ needWrapNative: boolean;
110
+ needsSequentialPreprocessing?: boolean;
111
+
112
+ // Returns the ETH fee required to swap
113
+ // It is optional for a DEX to implement this
114
+ // This is a legacy function and will be removed soon
115
+ getNetworkFee?(
116
+ srcToken: Address,
117
+ destToken: Address,
118
+ srcAmount: NumberAsString,
119
+ destAmount: NumberAsString,
120
+ data: ExchangeData,
121
+ side: SwapSide,
122
+ ): NumberAsString;
123
+
124
+ // If exists, called before getAdapterParam to use async calls and receive data if needed
125
+ preProcessTransaction?(
126
+ optimalSwapExchange: OptimalSwapExchange<ExchangeData>,
127
+ srcToken: Token,
128
+ destToken: Token,
129
+ side: SwapSide,
130
+ options: PreprocessTransactionOptions,
131
+ ): AsyncOrSync<[OptimalSwapExchange<ExchangeData>, ExchangeTxInfo]>;
132
+
133
+ // This is helper a function to support testing if preProcessTransaction is implemented
134
+ getTokenFromAddress?(address: Address): Token;
135
+ }
136
+
130
137
  export interface IDexPricing<ExchangeData> {
131
138
  readonly dexKey: string;
132
139
  // This is true if the the DEX is simply
package/src/dex/index.ts CHANGED
@@ -81,6 +81,8 @@ import { EtherFi } from './etherfi';
81
81
  import { Spark } from './spark/spark';
82
82
  import { VelodromeSlipstream } from './uniswap-v3/forks/velodrome-slipstream/velodrome-slipstream';
83
83
  import { AaveV3Stata } from './aave-v3-stata/aave-v3-stata';
84
+ import { ConcentratorArusd } from './concentrator-arusd/concentrator-arusd';
85
+ import { FxProtocolRusd } from './fx-protocol-rusd/fx-protocol-rusd';
84
86
 
85
87
  const LegacyDexes = [
86
88
  CurveV2,
@@ -157,6 +159,8 @@ const Dexes = [
157
159
  PharaohV1,
158
160
  Spark,
159
161
  AaveV3Stata,
162
+ ConcentratorArusd,
163
+ FxProtocolRusd,
160
164
  ];
161
165
 
162
166
  export type LegacyDexConstructor = new (dexHelper: IDexHelper) => IDexTxBuilder<
@@ -73,4 +73,7 @@ export const Adapters: {
73
73
  [Network.BASE]: {
74
74
  [SwapSide.SELL]: [{ name: 'BaseAdapter02', index: 2 }],
75
75
  },
76
+ [Network.ZKEVM]: {
77
+ [SwapSide.SELL]: [{ name: 'PolygonZkEvmAdapter01', index: 3 }],
78
+ },
76
79
  };
@@ -873,4 +873,160 @@ describe('Weth E2E', () => {
873
873
  });
874
874
  });
875
875
  });
876
+
877
+ describe('Weth ZKEvm', () => {
878
+ const dexKey = 'Weth';
879
+ const network = Network.ZKEVM;
880
+
881
+ const nativeTokenSymbol = 'ETH';
882
+ const wrappedTokenSymbol = 'WETH';
883
+
884
+ const nativeAmount = '1000000000000000000';
885
+ const wrappedAmount = '1000000000000000000';
886
+
887
+ const tokens = Tokens[network];
888
+ const holders = Holders[network];
889
+ const provider = new StaticJsonRpcProvider(
890
+ generateConfig(network).privateHttpProvider,
891
+ network,
892
+ );
893
+
894
+ const nativeToken = tokens[nativeTokenSymbol];
895
+ const wrappedToken = tokens[wrappedTokenSymbol];
896
+
897
+ const nativeHolder = holders[nativeTokenSymbol];
898
+ const wrappedHolder = holders[wrappedTokenSymbol];
899
+
900
+ describe('SimpleSwap SELL', () => {
901
+ const contractMethod = ContractMethod.simpleSwap;
902
+ const side = SwapSide.SELL;
903
+
904
+ it('native -> wrapped', async () => {
905
+ await testE2E(
906
+ nativeToken,
907
+ wrappedToken,
908
+ nativeHolder,
909
+ nativeAmount,
910
+ side,
911
+ dexKey,
912
+ contractMethod,
913
+ network,
914
+ provider,
915
+ undefined,
916
+ undefined,
917
+ undefined,
918
+ undefined,
919
+ undefined,
920
+ true,
921
+ );
922
+ });
923
+ it('wrapped -> native', async () => {
924
+ await testE2E(
925
+ wrappedToken,
926
+ nativeToken,
927
+ wrappedHolder,
928
+ wrappedAmount,
929
+ side,
930
+ dexKey,
931
+ contractMethod,
932
+ network,
933
+ provider,
934
+ undefined,
935
+ undefined,
936
+ undefined,
937
+ undefined,
938
+ undefined,
939
+ true,
940
+ );
941
+ });
942
+ });
943
+
944
+ describe('MultiSwap SELL', () => {
945
+ const contractMethod = ContractMethod.multiSwap;
946
+ const side = SwapSide.SELL;
947
+
948
+ it('native -> wrapped', async () => {
949
+ await testE2E(
950
+ nativeToken,
951
+ wrappedToken,
952
+ nativeHolder,
953
+ nativeAmount,
954
+ side,
955
+ dexKey,
956
+ contractMethod,
957
+ network,
958
+ provider,
959
+ undefined,
960
+ undefined,
961
+ undefined,
962
+ undefined,
963
+ undefined,
964
+ true,
965
+ );
966
+ });
967
+ it('wrapped -> native', async () => {
968
+ await testE2E(
969
+ wrappedToken,
970
+ nativeToken,
971
+ wrappedHolder,
972
+ wrappedAmount,
973
+ side,
974
+ dexKey,
975
+ contractMethod,
976
+ network,
977
+ provider,
978
+ undefined,
979
+ undefined,
980
+ undefined,
981
+ undefined,
982
+ undefined,
983
+ true,
984
+ );
985
+ });
986
+ });
987
+
988
+ describe('MegaSwap SELL', () => {
989
+ const contractMethod = ContractMethod.megaSwap;
990
+ const side = SwapSide.SELL;
991
+
992
+ it('native -> wrapped', async () => {
993
+ await testE2E(
994
+ nativeToken,
995
+ wrappedToken,
996
+ nativeHolder,
997
+ nativeAmount,
998
+ side,
999
+ dexKey,
1000
+ contractMethod,
1001
+ network,
1002
+ provider,
1003
+ undefined,
1004
+ undefined,
1005
+ undefined,
1006
+ undefined,
1007
+ undefined,
1008
+ true,
1009
+ );
1010
+ });
1011
+ it('wrapped -> native', async () => {
1012
+ await testE2E(
1013
+ wrappedToken,
1014
+ nativeToken,
1015
+ wrappedHolder,
1016
+ wrappedAmount,
1017
+ side,
1018
+ dexKey,
1019
+ contractMethod,
1020
+ network,
1021
+ provider,
1022
+ undefined,
1023
+ undefined,
1024
+ undefined,
1025
+ undefined,
1026
+ undefined,
1027
+ true,
1028
+ );
1029
+ });
1030
+ });
1031
+ });
876
1032
  });
@@ -58,7 +58,6 @@ async function checkOnChainPricing(
58
58
  const expectedPrices = [0n].concat(
59
59
  decodeReaderResult(readerResult, readerIface, funcName),
60
60
  );
61
-
62
61
  expect(prices).toEqual(expectedPrices);
63
62
  }
64
63
 
@@ -499,6 +499,14 @@ export const Tokens: {
499
499
  address: '0x23878914efe38d27c4d67ab83ed1b93a74d4086a',
500
500
  decimals: 6,
501
501
  },
502
+ rUSD: {
503
+ address: '0x65D72AA8DA931F047169112fcf34f52DbaAE7D18',
504
+ decimals: 18,
505
+ },
506
+ arUSD: {
507
+ address: '0x07D1718fF05a8C53C8F05aDAEd57C0d672945f9a',
508
+ decimals: 18,
509
+ },
502
510
  },
503
511
  [Network.POLYGON]: {
504
512
  jGBP: {
@@ -1569,6 +1577,8 @@ export const Holders: {
1569
1577
  stataUSDT: '0x6803364AceD5181877abC11E865FB27cB654a426',
1570
1578
  aaveUSDT: '0x32c98a981Fe7C333Bd4e8E7630E8e0CF5ce20987',
1571
1579
  weETH: '0x267ed5f71EE47D3E45Bb1569Aa37889a2d10f91e',
1580
+ rUSD: '0xEC2eda1C4F981E468ABF62424a10B69B738b498E',
1581
+ arUSD: '0xeFc24206053a452e2299BF3b8f964512b041Db4C',
1572
1582
  },
1573
1583
  [Network.POLYGON]: {
1574
1584
  jGBP: '0x02aa0B826c7BA6386DdBE04C0a8715A1c0A16B24',