@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,188 @@
1
+ "use strict";
2
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
+ if (k2 === undefined) k2 = k;
4
+ var desc = Object.getOwnPropertyDescriptor(m, k);
5
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
+ desc = { enumerable: true, get: function() { return m[k]; } };
7
+ }
8
+ Object.defineProperty(o, k2, desc);
9
+ }) : (function(o, m, k, k2) {
10
+ if (k2 === undefined) k2 = k;
11
+ o[k2] = m[k];
12
+ }));
13
+ var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
14
+ Object.defineProperty(o, "default", { enumerable: true, value: v });
15
+ }) : function(o, v) {
16
+ o["default"] = v;
17
+ });
18
+ var __importStar = (this && this.__importStar) || function (mod) {
19
+ if (mod && mod.__esModule) return mod;
20
+ var result = {};
21
+ if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
22
+ __setModuleDefault(result, mod);
23
+ return result;
24
+ };
25
+ var __importDefault = (this && this.__importDefault) || function (mod) {
26
+ return (mod && mod.__esModule) ? mod : { "default": mod };
27
+ };
28
+ Object.defineProperty(exports, "__esModule", { value: true });
29
+ exports.ConcentratorArusd = void 0;
30
+ const constants_1 = require("../../constants");
31
+ const CALLDATA_GAS_COST = __importStar(require("../../calldata-gas-cost"));
32
+ const utils_1 = require("../../utils");
33
+ const simple_exchange_1 = require("../simple-exchange");
34
+ const config_1 = require("./config");
35
+ const abi_1 = require("@ethersproject/abi");
36
+ const arUSD_json_1 = __importDefault(require("../../abi/concentrator/arUSD.json"));
37
+ const arUSD5115_json_1 = __importDefault(require("../../abi/concentrator/arUSD5115.json"));
38
+ const utils_2 = require("../../executor/utils");
39
+ const bigint_constants_1 = require("../../bigint-constants");
40
+ const concentrator_arusd_event_1 = require("./concentrator-arusd-event");
41
+ const utils_3 = require("./utils");
42
+ class ConcentratorArusd extends simple_exchange_1.SimpleExchange {
43
+ constructor(network, dexKey, dexHelper, adapters = {}) {
44
+ super(dexHelper, dexKey);
45
+ this.network = network;
46
+ this.dexKey = dexKey;
47
+ this.dexHelper = dexHelper;
48
+ this.adapters = adapters;
49
+ this.hasConstantPriceLargeAmounts = true;
50
+ this.needWrapNative = true;
51
+ this.isFeeOnTransferSupported = false;
52
+ const config = config_1.ConcentratorArusdConfig[dexKey][network];
53
+ this.config = {
54
+ rUSDAddress: config.rUSDAddress.toLowerCase(),
55
+ arUSDAddress: config.arUSDAddress.toLowerCase(),
56
+ arUSD5115Address: config.arUSD5115Address.toLowerCase(),
57
+ };
58
+ this.arUSD5115Iface = new abi_1.Interface(arUSD5115_json_1.default);
59
+ this.logger = dexHelper.getLogger(dexKey);
60
+ this.concentratorArusdEvent = new concentrator_arusd_event_1.ConcentratorArusdEvent(this.dexKey, dexHelper, this.config.arUSD5115Address, this.arUSD5115Iface, this.logger);
61
+ }
62
+ async initializePricing(blockNumber) {
63
+ const poolState = await (0, utils_3.getOnChainState)(this.dexHelper.multiContract, this.config.arUSD5115Address, this.arUSD5115Iface, blockNumber);
64
+ await this.concentratorArusdEvent.initialize(blockNumber, {
65
+ state: poolState,
66
+ });
67
+ }
68
+ is_arUSD(token) {
69
+ return token.toLowerCase() === this.config.arUSDAddress;
70
+ }
71
+ is_rUSD(token) {
72
+ return token.toLowerCase() === this.config.rUSDAddress;
73
+ }
74
+ is_arUSD_swap_token(srcToken, destToken) {
75
+ if (this.is_rUSD(srcToken) && this.is_arUSD(destToken)) {
76
+ return true;
77
+ }
78
+ if (this.is_arUSD(srcToken) && this.is_rUSD(destToken)) {
79
+ return true;
80
+ }
81
+ return false;
82
+ }
83
+ getAdapters(side) {
84
+ return null;
85
+ }
86
+ async getPoolIdentifiers(srcToken, destToken, side, blockNumber) {
87
+ if (!this.is_arUSD_swap_token(srcToken.address, destToken.address)) {
88
+ return [];
89
+ }
90
+ return [`${this.dexKey}_${this.config.arUSDAddress}`];
91
+ }
92
+ async getPricesVolume(srcToken, destToken, amounts, side, blockNumber, limitPools) {
93
+ // note: BUY is not supported
94
+ if (side === constants_1.SwapSide.BUY)
95
+ return null;
96
+ const isArUSDSwapToken = this.is_arUSD_swap_token(srcToken.address, destToken.address);
97
+ if (!isArUSDSwapToken) {
98
+ return null;
99
+ }
100
+ const is_deposit = !!this.is_rUSD(srcToken.address);
101
+ const pool = this.concentratorArusdEvent;
102
+ const unitIn = bigint_constants_1.BI_POWS[18];
103
+ const unitOut = await pool.getPrice(blockNumber, unitIn, is_deposit);
104
+ const amountsOut = await Promise.all(amounts.map(async (amountIn) => {
105
+ const _newPrice = await pool.getPrice(blockNumber, amountIn, is_deposit);
106
+ return _newPrice;
107
+ }));
108
+ return [
109
+ {
110
+ unit: unitOut,
111
+ prices: amountsOut,
112
+ data: {},
113
+ poolAddresses: [this.config.arUSDAddress],
114
+ exchange: this.dexKey,
115
+ gasCost: 1000000,
116
+ },
117
+ ];
118
+ }
119
+ // Returns estimated gas cost of calldata for this DEX in multiSwap
120
+ getCalldataGasCost(poolPrices) {
121
+ return CALLDATA_GAS_COST.DEX_NO_PAYLOAD;
122
+ }
123
+ getAdapterParam(srcToken, destToken, srcAmount, destAmount, data, side) {
124
+ const payload = '0x';
125
+ return {
126
+ targetExchange: this.config.rUSDAddress,
127
+ payload,
128
+ networkFee: '0',
129
+ };
130
+ }
131
+ async getDexParam(srcToken, destToken, srcAmount, destAmount, recipient, data, side, context, executorAddress) {
132
+ const is_rUSD_src = this.is_rUSD(srcToken);
133
+ const is_arUSD_src = this.is_arUSD(srcToken);
134
+ const is_rUSD_dest = this.is_rUSD(destToken);
135
+ const is_arUSD_dest = this.is_arUSD(destToken);
136
+ if (is_rUSD_src && is_arUSD_dest) {
137
+ const exchangeData = ConcentratorArusd.arUSDIface.encodeFunctionData('deposit', [srcAmount, recipient]);
138
+ return {
139
+ needWrapNative: false,
140
+ dexFuncHasRecipient: true,
141
+ exchangeData,
142
+ targetExchange: this.config.arUSDAddress,
143
+ returnAmountPos: (0, utils_2.extractReturnAmountPosition)(ConcentratorArusd.arUSDIface, 'deposit', 'shares'),
144
+ };
145
+ }
146
+ if (is_arUSD_src && is_rUSD_dest) {
147
+ const exchangeData = ConcentratorArusd.arUSDIface.encodeFunctionData('redeem', [srcAmount, recipient, executorAddress]);
148
+ return {
149
+ needWrapNative: false,
150
+ dexFuncHasRecipient: true,
151
+ exchangeData,
152
+ targetExchange: this.config.arUSDAddress,
153
+ returnAmountPos: (0, utils_2.extractReturnAmountPosition)(ConcentratorArusd.arUSDIface, 'redeem', 'assets'),
154
+ };
155
+ }
156
+ throw new Error('LOGIC ERROR');
157
+ }
158
+ // Returns list of top pools based on liquidity. Max
159
+ // limit number pools should be returned.
160
+ async getTopPoolsForToken(tokenAddress, limit) {
161
+ if (!this.is_rUSD(tokenAddress) && !this.is_arUSD(tokenAddress))
162
+ return [];
163
+ return [
164
+ {
165
+ exchange: this.dexKey,
166
+ address: this.config.arUSDAddress,
167
+ connectorTokens: this.is_rUSD(tokenAddress)
168
+ ? [
169
+ {
170
+ decimals: 18,
171
+ address: this.config.arUSDAddress,
172
+ },
173
+ ]
174
+ : [
175
+ {
176
+ decimals: 18,
177
+ address: this.config.rUSDAddress,
178
+ },
179
+ ],
180
+ liquidityUSD: 1000000000, // Just returning a big number so this DEX will be preferred
181
+ },
182
+ ];
183
+ }
184
+ }
185
+ exports.ConcentratorArusd = ConcentratorArusd;
186
+ ConcentratorArusd.arUSDIface = new abi_1.Interface(arUSD_json_1.default);
187
+ ConcentratorArusd.dexKeysWithNetwork = (0, utils_1.getDexKeysWithNetwork)(config_1.ConcentratorArusdConfig);
188
+ //# sourceMappingURL=concentrator-arusd.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"concentrator-arusd.js","sourceRoot":"","sources":["../../../src/dex/concentrator-arusd/concentrator-arusd.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAWA,+CAAoD;AACpD,2EAA6D;AAC7D,uCAAoD;AAIpD,wDAAoD;AACpD,qCAAmD;AACnD,4CAA+C;AAC/C,mFAA0D;AAC1D,2FAAkE;AAClE,gDAAmE;AACnE,6DAAiD;AACjD,yEAAoE;AACpE,mCAA0C;AAE1C,MAAa,iBACX,SAAQ,gCAAc;IAmBtB,YACW,OAAgB,EAChB,MAAc,EACd,SAAqB,EACpB,WAAW,EAAE;QAEvB,KAAK,CAAC,SAAS,EAAE,MAAM,CAAC,CAAC;QALhB,YAAO,GAAP,OAAO,CAAS;QAChB,WAAM,GAAN,MAAM,CAAQ;QACd,cAAS,GAAT,SAAS,CAAY;QACpB,aAAQ,GAAR,QAAQ,CAAK;QAhBhB,iCAA4B,GAAG,IAAI,CAAC;QACpC,mBAAc,GAAG,IAAI,CAAC;QAEtB,6BAAwB,GAAG,KAAK,CAAC;QAgBxC,MAAM,MAAM,GAAG,gCAAuB,CAAC,MAAM,CAAC,CAAC,OAAO,CAAC,CAAC;QACxD,IAAI,CAAC,MAAM,GAAG;YACZ,WAAW,EAAE,MAAM,CAAC,WAAW,CAAC,WAAW,EAAE;YAC7C,YAAY,EAAE,MAAM,CAAC,YAAY,CAAC,WAAW,EAAE;YAC/C,gBAAgB,EAAE,MAAM,CAAC,gBAAgB,CAAC,WAAW,EAAE;SACxD,CAAC;QACF,IAAI,CAAC,cAAc,GAAG,IAAI,eAAS,CAAC,wBAAa,CAAC,CAAC;QACnD,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7OiB,4BAAU,GAAG,IAAI,eAAS,CAAC,oBAAS,CAAC,CAAC;AASxC,oCAAkB,GAC9B,IAAA,6BAAqB,EAAC,gCAAuB,CAAC,CAAC"}
@@ -0,0 +1,3 @@
1
+ import { DexParams } from './types';
2
+ import { DexConfigMap } from '../../types';
3
+ export declare const ConcentratorArusdConfig: DexConfigMap<DexParams>;
@@ -0,0 +1,14 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.ConcentratorArusdConfig = void 0;
4
+ const constants_1 = require("../../constants");
5
+ exports.ConcentratorArusdConfig = {
6
+ ConcentratorArusd: {
7
+ [constants_1.Network.MAINNET]: {
8
+ rUSDAddress: '0x65D72AA8DA931F047169112fcf34f52DbaAE7D18',
9
+ arUSDAddress: '0x07D1718fF05a8C53C8F05aDAEd57C0d672945f9a',
10
+ arUSD5115Address: '0x549716F858aefF9CB845d4C78c67A7599B0Df240',
11
+ },
12
+ },
13
+ };
14
+ //# sourceMappingURL=config.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"config.js","sourceRoot":"","sources":["../../../src/dex/concentrator-arusd/config.ts"],"names":[],"mappings":";;;AAEA,+CAAoD;AAEvC,QAAA,uBAAuB,GAA4B;IAC9D,iBAAiB,EAAE;QACjB,CAAC,mBAAO,CAAC,OAAO,CAAC,EAAE;YACjB,WAAW,EAAE,4CAA4C;YACzD,YAAY,EAAE,4CAA4C;YAC1D,gBAAgB,EAAE,4CAA4C;SAC/D;KACF;CACF,CAAC"}
@@ -0,0 +1,14 @@
1
+ import { Address } from '../../types';
2
+ export declare type ConcentratorArusdState = {
3
+ totalSupply: string;
4
+ totalAssets: string;
5
+ };
6
+ export declare type ConcentratorArusdNavState = {
7
+ nav: string;
8
+ };
9
+ export declare type ConcentratorArusdData = {};
10
+ export declare type DexParams = {
11
+ arUSDAddress: Address;
12
+ rUSDAddress: Address;
13
+ arUSD5115Address: Address;
14
+ };
@@ -0,0 +1,3 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ //# sourceMappingURL=types.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"types.js","sourceRoot":"","sources":["../../../src/dex/concentrator-arusd/types.ts"],"names":[],"mappings":""}
@@ -0,0 +1,4 @@
1
+ import { Contract } from 'web3-eth-contract';
2
+ import { ConcentratorArusdState } from './types';
3
+ import { Interface } from '@ethersproject/abi';
4
+ export declare function getOnChainState(multiContract: Contract, poolAddress: string, poolInterface: Interface, blockNumber: number | 'latest'): Promise<ConcentratorArusdState>;
@@ -0,0 +1,27 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.getOnChainState = void 0;
4
+ const abi_1 = require("@ethersproject/abi");
5
+ const coder = new abi_1.AbiCoder();
6
+ async function getOnChainState(multiContract, poolAddress, poolInterface, blockNumber) {
7
+ const data = await multiContract.methods
8
+ .aggregate([
9
+ {
10
+ target: poolAddress,
11
+ callData: poolInterface.encodeFunctionData('totalSupply', []),
12
+ },
13
+ {
14
+ target: poolAddress,
15
+ callData: poolInterface.encodeFunctionData('getTotalAssets', []),
16
+ },
17
+ ])
18
+ .call({}, blockNumber);
19
+ const totalSupply = BigInt(poolInterface.decodeFunctionResult('totalSupply', data.returnData[0])[0]).toString();
20
+ const totalAssets = BigInt(poolInterface.decodeFunctionResult('getTotalAssets', data.returnData[1])[0]).toString();
21
+ return {
22
+ totalSupply,
23
+ totalAssets,
24
+ };
25
+ }
26
+ exports.getOnChainState = getOnChainState;
27
+ //# sourceMappingURL=utils.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"utils.js","sourceRoot":"","sources":["../../../src/dex/concentrator-arusd/utils.ts"],"names":[],"mappings":";;;AAEA,4CAAyD;AAEzD,MAAM,KAAK,GAAG,IAAI,cAAQ,EAAE,CAAC;AAEtB,KAAK,UAAU,eAAe,CACnC,aAAuB,EACvB,WAAmB,EACnB,aAAwB,EACxB,WAA8B;IAE9B,MAAM,IAAI,GAA0B,MAAM,aAAa,CAAC,OAAO;SAC5D,SAAS,CAAC;QACT;YACE,MAAM,EAAE,WAAW;YACnB,QAAQ,EAAE,aAAa,CAAC,kBAAkB,CAAC,aAAa,EAAE,EAAE,CAAC;SAC9D;QACD;YACE,MAAM,EAAE,WAAW;YACnB,QAAQ,EAAE,aAAa,CAAC,kBAAkB,CAAC,gBAAgB,EAAE,EAAE,CAAC;SACjE;KACF,CAAC;SACD,IAAI,CAAC,EAAE,EAAE,WAAW,CAAC,CAAC;IAEzB,MAAM,WAAW,GAAG,MAAM,CACxB,aAAa,CAAC,oBAAoB,CAAC,aAAa,EAAE,IAAI,CAAC,UAAU,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CACzE,CAAC,QAAQ,EAAE,CAAC;IACb,MAAM,WAAW,GAAG,MAAM,CACxB,aAAa,CAAC,oBAAoB,CAAC,gBAAgB,EAAE,IAAI,CAAC,UAAU,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAC5E,CAAC,QAAQ,EAAE,CAAC;IACb,OAAO;QACL,WAAW;QACX,WAAW;KACZ,CAAC;AACJ,CAAC;AA7BD,0CA6BC"}
@@ -0,0 +1,3 @@
1
+ import { DexParams } from './types';
2
+ import { DexConfigMap } from '../../types';
3
+ export declare const FxProtocolConfig: DexConfigMap<DexParams>;
@@ -0,0 +1,15 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.FxProtocolConfig = void 0;
4
+ const constants_1 = require("../../constants");
5
+ exports.FxProtocolConfig = {
6
+ FxProtocolRusd: {
7
+ [constants_1.Network.MAINNET]: {
8
+ rUSDAddress: '0x65D72AA8DA931F047169112fcf34f52DbaAE7D18',
9
+ weETHAddress: '0xCd5fE23C85820F7B72D0926FC9b05b43E359b7ee',
10
+ rUSDWeETHMarketAddress: '0x267c6a96db7422faa60aa7198ffeeec4169cd65f',
11
+ weETHOracleAddress: '0xddb6f90ffb4d3257dd666b69178e5b3c5bf41136',
12
+ },
13
+ },
14
+ };
15
+ //# sourceMappingURL=config.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"config.js","sourceRoot":"","sources":["../../../src/dex/fx-protocol-rusd/config.ts"],"names":[],"mappings":";;;AAEA,+CAAoD;AAEvC,QAAA,gBAAgB,GAA4B;IACvD,cAAc,EAAE;QACd,CAAC,mBAAO,CAAC,OAAO,CAAC,EAAE;YACjB,WAAW,EAAE,4CAA4C;YACzD,YAAY,EAAE,4CAA4C;YAC1D,sBAAsB,EAAE,4CAA4C;YACpE,kBAAkB,EAAE,4CAA4C;SACjE;KACF;CACF,CAAC"}
@@ -0,0 +1,18 @@
1
+ import { Interface } from '@ethersproject/abi';
2
+ import { IDexHelper } from '../../dex-helper';
3
+ import { StatefulEventSubscriber } from '../../stateful-event-subscriber';
4
+ import { Address, Log, Logger } from '../../types';
5
+ import { AsyncOrSync, DeepReadonly } from 'ts-essentials';
6
+ import { FxProtocolPoolState } from './types';
7
+ export declare class FxProtocolRusdEvent extends StatefulEventSubscriber<FxProtocolPoolState> {
8
+ protected dexHelper: IDexHelper;
9
+ private marketAddress;
10
+ private marketInterface;
11
+ private weETHOracleAddress;
12
+ private weETHOracleIface;
13
+ constructor(parentName: string, dexHelper: IDexHelper, marketAddress: Address, marketInterface: Interface, weETHOracleAddress: Address, weETHOracleIface: Interface, logger: Logger);
14
+ protected processLog(state: DeepReadonly<FxProtocolPoolState>, log: Readonly<Log>): AsyncOrSync<DeepReadonly<FxProtocolPoolState> | null>;
15
+ generateState(blockNumber?: number | 'latest'): Promise<DeepReadonly<FxProtocolPoolState>>;
16
+ getPrice(blockNumber: number, amount: bigint, isRedeem: boolean): Promise<bigint>;
17
+ getOrGenerateState(blockNumber: number): Promise<DeepReadonly<FxProtocolPoolState> | null>;
18
+ }
@@ -0,0 +1,71 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.FxProtocolRusdEvent = void 0;
4
+ const abi_1 = require("@ethersproject/abi");
5
+ const stateful_event_subscriber_1 = require("../../stateful-event-subscriber");
6
+ const bigint_constants_1 = require("../../bigint-constants");
7
+ const utils_1 = require("./utils");
8
+ const ANSWER_UPDATED_TOPICHASH = `0x0559884fd3a460db3073b7fc896cc77986f16e378210ded43186175bf646fc5f`;
9
+ const UPDATE_REDEEM_FEE_TOPICHASH = `0xb3d49e95905d108ea668ffe62a85ee16bdc4ff9f122a7137964327ea8e0585ff`;
10
+ class FxProtocolRusdEvent extends stateful_event_subscriber_1.StatefulEventSubscriber {
11
+ constructor(parentName, dexHelper, marketAddress, marketInterface, weETHOracleAddress, weETHOracleIface, logger) {
12
+ super(parentName, 'fxProtocolRusd', dexHelper, logger);
13
+ this.dexHelper = dexHelper;
14
+ this.marketAddress = marketAddress;
15
+ this.marketInterface = marketInterface;
16
+ this.weETHOracleAddress = weETHOracleAddress;
17
+ this.weETHOracleIface = weETHOracleIface;
18
+ this.addressesSubscribed = [marketAddress, weETHOracleAddress];
19
+ }
20
+ processLog(state, log) {
21
+ if (log.topics[0] === UPDATE_REDEEM_FEE_TOPICHASH) {
22
+ const [defaultFeeRatio] = abi_1.defaultAbiCoder.decode(['uint256', 'int256'], log.data);
23
+ return {
24
+ ...state,
25
+ redeemFee: BigInt(defaultFeeRatio).toString(),
26
+ };
27
+ }
28
+ if (log.topics[0] === ANSWER_UPDATED_TOPICHASH) {
29
+ return {
30
+ ...state,
31
+ weETHPrice: BigInt(log.topics[1]).toString(),
32
+ };
33
+ }
34
+ return null;
35
+ }
36
+ async generateState(blockNumber = 'latest') {
37
+ const state = await (0, utils_1.getOnChainState)(this.dexHelper.multiContract, this.marketAddress, this.marketInterface, this.weETHOracleAddress, this.weETHOracleIface, blockNumber);
38
+ return state;
39
+ }
40
+ async getPrice(blockNumber, amount, isRedeem) {
41
+ const state = await this.getOrGenerateState(blockNumber);
42
+ if (!state)
43
+ throw new Error('Cannot compute price');
44
+ const { nav, redeemFee, weETHPrice } = state;
45
+ const baseTokenPrice = BigInt(weETHPrice) * bigint_constants_1.BI_POWS[10];
46
+ if (isRedeem) {
47
+ return BigInt((amount * BigInt(nav) * (bigint_constants_1.BI_POWS[18] - BigInt(redeemFee))) /
48
+ bigint_constants_1.BI_POWS[18] /
49
+ baseTokenPrice);
50
+ }
51
+ else {
52
+ return BigInt((baseTokenPrice * amount) / BigInt(nav));
53
+ }
54
+ }
55
+ async getOrGenerateState(blockNumber) {
56
+ const state = this.getState(blockNumber);
57
+ if (state) {
58
+ return state;
59
+ }
60
+ this.logger.debug(`No state found for ${this.addressesSubscribed[0]}, generating new one`);
61
+ const newState = await this.generateState(blockNumber);
62
+ if (!newState) {
63
+ this.logger.debug(`Could not regenerate state for ${this.addressesSubscribed[0]}`);
64
+ return null;
65
+ }
66
+ this.setState(newState, blockNumber);
67
+ return newState;
68
+ }
69
+ }
70
+ exports.FxProtocolRusdEvent = FxProtocolRusdEvent;
71
+ //# sourceMappingURL=fx-protocol-rusd-event.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"fx-protocol-rusd-event.js","sourceRoot":"","sources":["../../../src/dex/fx-protocol-rusd/fx-protocol-rusd-event.ts"],"names":[],"mappings":";;;AACA,4CAAgE;AAEhE,+EAA0E;AAI1E,6DAAiD;AACjD,mCAA0C;AAE1C,MAAM,wBAAwB,GAAG,oEAAoE,CAAC;AACtG,MAAM,2BAA2B,GAAG,oEAAoE,CAAC;AAEzG,MAAa,mBAAoB,SAAQ,mDAA4C;IACnF,YACE,UAAkB,EACR,SAAqB,EACvB,aAAsB,EACtB,eAA0B,EAC1B,kBAA2B,EAC3B,gBAA2B,EACnC,MAAc;QAEd,KAAK,CAAC,UAAU,EAAE,gBAAgB,EAAE,SAAS,EAAE,MAAM,CAAC,CAAC;QAP7C,cAAS,GAAT,SAAS,CAAY;QACvB,kBAAa,GAAb,aAAa,CAAS;QACtB,oBAAe,GAAf,eAAe,CAAW;QAC1B,uBAAkB,GAAlB,kBAAkB,CAAS;QAC3B,qBAAgB,GAAhB,gBA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AAG,KAAK,CAAC;QAC7C,MAAM,cAAc,GAAG,MAAM,CAAC,UAAU,CAAC,GAAG,0BAAO,CAAC,EAAE,CAAC,CAAC;QAExD,IAAI,QAAQ,EAAE;YACZ,OAAO,MAAM,CACX,CAAC,MAAM,GAAG,MAAM,CAAC,GAAG,CAAC,GAAG,CAAC,0BAAO,CAAC,EAAE,CAAC,GAAG,MAAM,CAAC,SAAS,CAAC,CAAC,CAAC;gBACxD,0BAAO,CAAC,EAAE,CAAC;gBACX,cAAc,CACjB,CAAC;SACH;aAAM;YACL,OAAO,MAAM,CAAC,CAAC,cAAc,GAAG,MAAM,CAAC,GAAG,MAAM,CAAC,GAAG,CAAC,CAAC,CAAC;SACxD;IACH,CAAC;IAED,KAAK,CAAC,kBAAkB,CACtB,WAAmB;QAEnB,MAAM,KAAK,GAAG,IAAI,CAAC,QAAQ,CAAC,WAAW,CAAC,CAAC;QACzC,IAAI,KAAK,EAAE;YACT,OAAO,KAAK,CAAC;SACd;QAED,IAAI,CAAC,MAAM,CAAC,KAAK,CACf,sBAAsB,IAAI,CAAC,mBAAmB,CAAC,CAAC,CAAC,sBAAsB,CACxE,CAAC;QACF,MAAM,QAAQ,GAAG,MAAM,IAAI,CAAC,aAAa,CAAC,WAAW,CAAC,CAAC;QAEvD,IAAI,CAAC,QAAQ,EAAE;YACb,IAAI,CAAC,MAAM,CAAC,KAAK,CACf,kCAAkC,IAAI,CAAC,mBAAmB,CAAC,CAAC,CAAC,EAAE,CAChE,CAAC;YACF,OAAO,IAAI,CAAC;SACb;QACD,IAAI,CAAC,QAAQ,CAAC,QAAQ,EAAE,WAAW,CAAC,CAAC;QACrC,OAAO,QAAQ,CAAC;IAClB,CAAC;CACF;AAlGD,kDAkGC"}
@@ -0,0 +1,39 @@
1
+ import { Token, Address, ExchangePrices, PoolPrices, AdapterExchangeParam, Logger, NumberAsString, DexExchangeParam, PoolLiquidity } from '../../types';
2
+ import { SwapSide, Network } from '../../constants';
3
+ import { IDex } from '../idex';
4
+ import { IDexHelper } from '../../dex-helper/idex-helper';
5
+ import { DexParams, FxProtocolData } from './types';
6
+ import { SimpleExchange } from '../simple-exchange';
7
+ import { Interface } from '@ethersproject/abi';
8
+ import { FxProtocolRusdEvent } from './fx-protocol-rusd-event';
9
+ export declare class FxProtocolRusd extends SimpleExchange implements IDex<FxProtocolData> {
10
+ readonly network: Network;
11
+ readonly dexKey: string;
12
+ readonly dexHelper: IDexHelper;
13
+ protected config: DexParams;
14
+ readonly hasConstantPriceLargeAmounts = true;
15
+ readonly needWrapNative = false;
16
+ readonly isFeeOnTransferSupported = false;
17
+ static dexKeysWithNetwork: {
18
+ key: string;
19
+ networks: Network[];
20
+ }[];
21
+ fxUSDIface: Interface;
22
+ rUSDMarketIface: Interface;
23
+ weETHOracleIface: Interface;
24
+ fxProtocolRusdPool: FxProtocolRusdEvent;
25
+ logger: Logger;
26
+ constructor(network: Network, dexKey: string, dexHelper: IDexHelper);
27
+ initializePricing(blockNumber: number): Promise<void>;
28
+ getConfig(): DexParams;
29
+ is_weETH(token: string): boolean;
30
+ is_rUSD(token: string): boolean;
31
+ is_rUSD_swap_token(srcToken: string, destToken: string): boolean;
32
+ getAdapters(): null;
33
+ getPoolIdentifiers(srcToken: Token, destToken: Token, side: SwapSide, blockNumber: number): Promise<string[]>;
34
+ getPricesVolume(srcToken: Token, destToken: Token, amounts: bigint[], side: SwapSide, blockNumber: number, limitPools?: string[]): Promise<null | ExchangePrices<FxProtocolData>>;
35
+ getCalldataGasCost(poolPrices: PoolPrices<FxProtocolData>): number | number[];
36
+ getAdapterParam(srcToken: string, destToken: string, srcAmount: string, destAmount: string, data: FxProtocolData, side: SwapSide): AdapterExchangeParam;
37
+ getDexParam(srcToken: Address, destToken: Address, srcAmount: NumberAsString, destAmount: NumberAsString, recipient: Address, data: FxProtocolData, side: SwapSide): Promise<DexExchangeParam>;
38
+ getTopPoolsForToken(tokenAddress: Address, limit: number): Promise<PoolLiquidity[]>;
39
+ }
@@ -0,0 +1,201 @@
1
+ "use strict";
2
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
+ if (k2 === undefined) k2 = k;
4
+ var desc = Object.getOwnPropertyDescriptor(m, k);
5
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
+ desc = { enumerable: true, get: function() { return m[k]; } };
7
+ }
8
+ Object.defineProperty(o, k2, desc);
9
+ }) : (function(o, m, k, k2) {
10
+ if (k2 === undefined) k2 = k;
11
+ o[k2] = m[k];
12
+ }));
13
+ var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
14
+ Object.defineProperty(o, "default", { enumerable: true, value: v });
15
+ }) : function(o, v) {
16
+ o["default"] = v;
17
+ });
18
+ var __importStar = (this && this.__importStar) || function (mod) {
19
+ if (mod && mod.__esModule) return mod;
20
+ var result = {};
21
+ if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
22
+ __setModuleDefault(result, mod);
23
+ return result;
24
+ };
25
+ var __importDefault = (this && this.__importDefault) || function (mod) {
26
+ return (mod && mod.__esModule) ? mod : { "default": mod };
27
+ };
28
+ Object.defineProperty(exports, "__esModule", { value: true });
29
+ exports.FxProtocolRusd = void 0;
30
+ const constants_1 = require("../../constants");
31
+ const CALLDATA_GAS_COST = __importStar(require("../../calldata-gas-cost"));
32
+ const utils_1 = require("../../utils");
33
+ const simple_exchange_1 = require("../simple-exchange");
34
+ const config_1 = require("./config");
35
+ const abi_1 = require("@ethersproject/abi");
36
+ const FxUSD_json_1 = __importDefault(require("../../abi/fx-protocol/FxUSD.json"));
37
+ const FxMarket_json_1 = __importDefault(require("../../abi/fx-protocol/FxMarket.json"));
38
+ const weETHOralce_json_1 = __importDefault(require("../../abi/fx-protocol/weETHOralce.json"));
39
+ const utils_2 = require("../../executor/utils");
40
+ const fx_protocol_rusd_event_1 = require("./fx-protocol-rusd-event");
41
+ const bigint_constants_1 = require("../../bigint-constants");
42
+ const utils_3 = require("./utils");
43
+ class FxProtocolRusd extends simple_exchange_1.SimpleExchange {
44
+ constructor(network, dexKey, dexHelper) {
45
+ super(dexHelper, dexKey);
46
+ this.network = network;
47
+ this.dexKey = dexKey;
48
+ this.dexHelper = dexHelper;
49
+ this.hasConstantPriceLargeAmounts = true;
50
+ this.needWrapNative = false;
51
+ this.isFeeOnTransferSupported = false;
52
+ const config = config_1.FxProtocolConfig[dexKey][network];
53
+ this.fxUSDIface = new abi_1.Interface(FxUSD_json_1.default);
54
+ this.rUSDMarketIface = new abi_1.Interface(FxMarket_json_1.default);
55
+ this.weETHOracleIface = new abi_1.Interface(weETHOralce_json_1.default);
56
+ this.config = {
57
+ rUSDAddress: config.rUSDAddress.toLowerCase(),
58
+ weETHAddress: config.weETHAddress.toLowerCase(),
59
+ rUSDWeETHMarketAddress: config.rUSDWeETHMarketAddress.toLowerCase(),
60
+ weETHOracleAddress: config.weETHOracleAddress.toLowerCase(),
61
+ };
62
+ this.logger = dexHelper.getLogger(dexKey);
63
+ this.fxProtocolRusdPool = new fx_protocol_rusd_event_1.FxProtocolRusdEvent(this.dexKey, dexHelper, this.config.rUSDWeETHMarketAddress, this.rUSDMarketIface, this.config.weETHOracleAddress, this.weETHOracleIface, this.logger);
64
+ }
65
+ async initializePricing(blockNumber) {
66
+ const poolState = await (0, utils_3.getOnChainState)(this.dexHelper.multiContract, this.config.rUSDWeETHMarketAddress, this.rUSDMarketIface, this.config.weETHOracleAddress, this.weETHOracleIface, blockNumber);
67
+ await this.fxProtocolRusdPool.initialize(blockNumber, {
68
+ state: poolState,
69
+ });
70
+ }
71
+ getConfig() {
72
+ return this.config;
73
+ }
74
+ is_weETH(token) {
75
+ return token.toLowerCase() === this.config.weETHAddress.toLowerCase();
76
+ }
77
+ is_rUSD(token) {
78
+ return token.toLowerCase() === this.config.rUSDAddress.toLowerCase();
79
+ }
80
+ is_rUSD_swap_token(srcToken, destToken) {
81
+ return ((this.is_weETH(srcToken) && this.is_rUSD(destToken)) ||
82
+ (this.is_rUSD(srcToken) && this.is_weETH(destToken)));
83
+ }
84
+ // Returns the list of contract adapters (name and index)
85
+ // for a buy/sell. Return null if there are no adapters.
86
+ getAdapters() {
87
+ return null;
88
+ }
89
+ async getPoolIdentifiers(srcToken, destToken, side, blockNumber) {
90
+ if (!this.is_rUSD_swap_token(srcToken.address, destToken.address)) {
91
+ return [];
92
+ }
93
+ return [`${this.dexKey}_${this.config.rUSDAddress}`];
94
+ }
95
+ async getPricesVolume(srcToken, destToken, amounts, side, blockNumber, limitPools) {
96
+ // note: BUY is not supported
97
+ if (side === constants_1.SwapSide.BUY)
98
+ return null;
99
+ const isRUSDSwapToken = this.is_rUSD_swap_token(srcToken.address, destToken.address);
100
+ if (!isRUSDSwapToken) {
101
+ return null;
102
+ }
103
+ const pool = this.fxProtocolRusdPool;
104
+ const is_redeem = this.is_weETH(destToken.address);
105
+ const unitIn = bigint_constants_1.BI_POWS[18];
106
+ const unitOut = await pool.getPrice(blockNumber, unitIn, is_redeem);
107
+ const amountsOut = await Promise.all(amounts.map(_amountIn => pool.getPrice(blockNumber, _amountIn, is_redeem)));
108
+ return [
109
+ {
110
+ unit: unitOut,
111
+ prices: amountsOut,
112
+ data: {},
113
+ poolAddresses: [this.config.rUSDAddress],
114
+ exchange: this.dexKey,
115
+ gasCost: 1000000,
116
+ },
117
+ ];
118
+ }
119
+ // Returns estimated gas cost of calldata for this DEX in multiSwap
120
+ getCalldataGasCost(poolPrices) {
121
+ return CALLDATA_GAS_COST.DEX_NO_PAYLOAD;
122
+ }
123
+ // Encode params required by the exchange adapter
124
+ // V5: Used for multiSwap, buy & megaSwap
125
+ // V6: Not used, can be left blank
126
+ // Hint: abiCoder.encodeParameter() could be useful
127
+ getAdapterParam(srcToken, destToken, srcAmount, destAmount, data, side) {
128
+ const payload = '0x';
129
+ return {
130
+ targetExchange: this.config.rUSDAddress,
131
+ payload,
132
+ networkFee: '0',
133
+ };
134
+ }
135
+ async getDexParam(srcToken, destToken, srcAmount, destAmount, recipient, data, side) {
136
+ const is_rUSD_src = this.is_rUSD(srcToken);
137
+ const is_weETH_src = this.is_weETH(srcToken);
138
+ const is_rUSD_dest = this.is_rUSD(destToken);
139
+ const is_weETH_dest = this.is_weETH(destToken);
140
+ if (is_weETH_src && is_rUSD_dest) {
141
+ const exchangeData = this.fxUSDIface.encodeFunctionData('mint', [
142
+ this.config.weETHAddress,
143
+ srcAmount,
144
+ recipient,
145
+ '0',
146
+ ]);
147
+ return {
148
+ needWrapNative: false,
149
+ dexFuncHasRecipient: true,
150
+ exchangeData,
151
+ targetExchange: this.config.rUSDAddress,
152
+ returnAmountPos: (0, utils_2.extractReturnAmountPosition)(this.fxUSDIface, 'mint', '_amountOut'),
153
+ };
154
+ }
155
+ if (is_rUSD_src && is_weETH_dest) {
156
+ const exchangeData = this.fxUSDIface.encodeFunctionData('redeem', [
157
+ this.config.weETHAddress,
158
+ srcAmount,
159
+ recipient,
160
+ '0',
161
+ ]);
162
+ return {
163
+ needWrapNative: false,
164
+ dexFuncHasRecipient: true,
165
+ exchangeData,
166
+ targetExchange: this.config.rUSDAddress,
167
+ returnAmountPos: (0, utils_2.extractReturnAmountPosition)(this.fxUSDIface, 'redeem', '_amountOut'),
168
+ };
169
+ }
170
+ throw new Error('LOGIC ERROR');
171
+ }
172
+ // Returns list of top pools based on liquidity. Max
173
+ // limit number pools should be returned.
174
+ async getTopPoolsForToken(tokenAddress, limit) {
175
+ if (!this.is_rUSD(tokenAddress) && !this.is_weETH(tokenAddress))
176
+ return [];
177
+ return [
178
+ {
179
+ exchange: this.dexKey,
180
+ address: this.config.rUSDAddress,
181
+ connectorTokens: this.is_weETH(tokenAddress)
182
+ ? [
183
+ {
184
+ decimals: 18,
185
+ address: this.config.rUSDAddress,
186
+ },
187
+ ]
188
+ : [
189
+ {
190
+ decimals: 18,
191
+ address: this.config.weETHAddress,
192
+ },
193
+ ],
194
+ liquidityUSD: 1000000000, // Just returning a big number so this DEX will be preferred
195
+ },
196
+ ];
197
+ }
198
+ }
199
+ exports.FxProtocolRusd = FxProtocolRusd;
200
+ FxProtocolRusd.dexKeysWithNetwork = (0, utils_1.getDexKeysWithNetwork)(config_1.FxProtocolConfig);
201
+ //# sourceMappingURL=fx-protocol-rusd.js.map