@curvefi/api 2.63.0 → 2.63.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (83) hide show
  1. package/lib/boosting.js +247 -645
  2. package/lib/constants/L2Networks.js +1 -1
  3. package/lib/constants/aliases.js +19 -19
  4. package/lib/constants/coins/arbitrum.js +5 -5
  5. package/lib/constants/coins/aurora.js +5 -5
  6. package/lib/constants/coins/avalanche.js +6 -6
  7. package/lib/constants/coins/base.js +5 -5
  8. package/lib/constants/coins/bsc.js +5 -5
  9. package/lib/constants/coins/celo.js +5 -5
  10. package/lib/constants/coins/ethereum.js +9 -9
  11. package/lib/constants/coins/fantom.js +7 -7
  12. package/lib/constants/coins/fraxtal.js +5 -5
  13. package/lib/constants/coins/kava.js +5 -5
  14. package/lib/constants/coins/mantle.js +5 -5
  15. package/lib/constants/coins/moonbeam.js +5 -5
  16. package/lib/constants/coins/optimism.js +5 -5
  17. package/lib/constants/coins/polygon.js +6 -6
  18. package/lib/constants/coins/xdai.js +5 -5
  19. package/lib/constants/coins/xlayer.js +5 -5
  20. package/lib/constants/coins/zksync.js +5 -5
  21. package/lib/constants/pools/arbitrum.js +1 -1
  22. package/lib/constants/pools/aurora.js +1 -1
  23. package/lib/constants/pools/avalanche.js +1 -1
  24. package/lib/constants/pools/base.js +1 -1
  25. package/lib/constants/pools/bsc.js +1 -1
  26. package/lib/constants/pools/celo.js +1 -1
  27. package/lib/constants/pools/ethereum.js +2 -2
  28. package/lib/constants/pools/fantom.js +1 -1
  29. package/lib/constants/pools/fraxtal.js +1 -1
  30. package/lib/constants/pools/kava.js +1 -1
  31. package/lib/constants/pools/mantle.js +1 -1
  32. package/lib/constants/pools/moonbeam.js +1 -1
  33. package/lib/constants/pools/optimism.js +1 -1
  34. package/lib/constants/pools/polygon.js +1 -1
  35. package/lib/constants/pools/xdai.js +1 -1
  36. package/lib/constants/pools/xlayer.js +1 -1
  37. package/lib/constants/pools/zksync.js +1 -1
  38. package/lib/constants/tricryptoDeployImplementations.js +1 -1
  39. package/lib/constants/utils.js +18 -19
  40. package/lib/constants/volumeNetworks.js +1 -1
  41. package/lib/curve.d.ts +10 -6
  42. package/lib/curve.js +534 -909
  43. package/lib/dao.js +351 -705
  44. package/lib/external-api.js +127 -256
  45. package/lib/factory/common.js +4 -4
  46. package/lib/factory/constants-crypto.js +33 -33
  47. package/lib/factory/constants.js +34 -34
  48. package/lib/factory/deploy.js +542 -907
  49. package/lib/factory/factory-api.js +205 -269
  50. package/lib/factory/factory-crypto.js +202 -342
  51. package/lib/factory/factory-tricrypto.js +164 -286
  52. package/lib/factory/factory-twocrypto.js +151 -269
  53. package/lib/factory/factory.js +245 -385
  54. package/lib/index.js +109 -198
  55. package/lib/interfaces.d.ts +46 -6
  56. package/lib/pools/PoolTemplate.js +1774 -3027
  57. package/lib/pools/gaugePool.js +112 -251
  58. package/lib/pools/mixins/common.js +22 -93
  59. package/lib/pools/mixins/depositBalancedAmountsMixins.js +52 -118
  60. package/lib/pools/mixins/depositMixins.js +160 -386
  61. package/lib/pools/mixins/depositWrappedMixins.js +79 -205
  62. package/lib/pools/mixins/poolBalancesMixin.js +24 -87
  63. package/lib/pools/mixins/swapMixins.js +139 -324
  64. package/lib/pools/mixins/swapWrappedMixins.js +111 -265
  65. package/lib/pools/mixins/withdrawExpectedMixins.js +27 -91
  66. package/lib/pools/mixins/withdrawImbalanceMixins.js +111 -293
  67. package/lib/pools/mixins/withdrawImbalanceWrappedMixins.js +58 -169
  68. package/lib/pools/mixins/withdrawMixins.js +139 -359
  69. package/lib/pools/mixins/withdrawOneCoinExpectedMixins.js +20 -75
  70. package/lib/pools/mixins/withdrawOneCoinMixins.js +140 -360
  71. package/lib/pools/mixins/withdrawOneCoinWrappedExpectedMixins.js +10 -51
  72. package/lib/pools/mixins/withdrawOneCoinWrappedMixins.js +60 -167
  73. package/lib/pools/mixins/withdrawWrappedMixins.js +57 -167
  74. package/lib/pools/poolConstructor.js +11 -31
  75. package/lib/pools/utils.js +301 -469
  76. package/lib/route-finder.worker.d.ts +9 -0
  77. package/lib/route-finder.worker.js +112 -0
  78. package/lib/route-graph.worker.d.ts +11 -0
  79. package/lib/route-graph.worker.js +334 -0
  80. package/lib/router.js +323 -912
  81. package/lib/utils.d.ts +8 -7
  82. package/lib/utils.js +540 -927
  83. package/package.json +3 -2
@@ -7,341 +7,219 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
7
7
  step((generator = generator.apply(thisArg, _arguments || [])).next());
8
8
  });
9
9
  };
10
- var __generator = (this && this.__generator) || function (thisArg, body) {
11
- var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g;
12
- return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
13
- function verb(n) { return function (v) { return step([n, v]); }; }
14
- function step(op) {
15
- if (f) throw new TypeError("Generator is already executing.");
16
- while (g && (g = 0, op[0] && (_ = 0)), _) try {
17
- if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t;
18
- if (y = 0, t) op = [op[0] & 2, t.value];
19
- switch (op[0]) {
20
- case 0: case 1: t = op; break;
21
- case 4: _.label++; return { value: op[1], done: false };
22
- case 5: _.label++; y = op[1]; op = [0]; continue;
23
- case 7: op = _.ops.pop(); _.trys.pop(); continue;
24
- default:
25
- if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }
26
- if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }
27
- if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }
28
- if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }
29
- if (t[2]) _.ops.pop();
30
- _.trys.pop(); continue;
31
- }
32
- op = body.call(thisArg, _);
33
- } catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }
34
- if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
35
- }
36
- };
37
- var __spreadArray = (this && this.__spreadArray) || function (to, from, pack) {
38
- if (pack || arguments.length === 2) for (var i = 0, l = from.length, ar; i < l; i++) {
39
- if (ar || !(i in from)) {
40
- if (!ar) ar = Array.prototype.slice.call(from, 0, i);
41
- ar[i] = from[i];
42
- }
43
- }
44
- return to.concat(ar || Array.prototype.slice.call(from));
45
- };
46
10
  import { curve } from "../curve.js";
47
11
  import ERC20ABI from "../constants/abis/ERC20.json" assert { type: 'json' };
48
12
  import tricryptoFactorySwapABI from "../constants/abis/factory-tricrypto/factory-tricrypto-pool.json" assert { type: 'json' };
49
13
  import factoryGaugeABI from "../constants/abis/gauge_factory.json" assert { type: 'json' };
50
14
  import gaugeChildABI from "../constants/abis/gauge_child.json" assert { type: 'json' };
51
15
  import { tricryptoDeployImplementations } from "../constants/tricryptoDeployImplementations.js";
52
- var deepFlatten = function (arr) { return [].concat.apply([], arr.map(function (v) { return (Array.isArray(v) ? deepFlatten(v) : v); })); };
16
+ const deepFlatten = (arr) => [].concat(...arr.map((v) => (Array.isArray(v) ? deepFlatten(v) : v)));
53
17
  function getRecentlyCreatedCryptoPoolId(swapAddress) {
54
- return __awaiter(this, void 0, void 0, function () {
55
- var factoryContract, poolCount, _a, _b, _c, i, address;
56
- return __generator(this, function (_e) {
57
- switch (_e.label) {
58
- case 0:
59
- factoryContract = this.contracts[this.constants.ALIASES.tricrypto_factory].contract;
60
- _a = Number;
61
- _c = (_b = curve).formatUnits;
62
- return [4 /*yield*/, factoryContract.pool_count(this.constantOptions)];
63
- case 1:
64
- poolCount = _a.apply(void 0, [_c.apply(_b, [_e.sent(), 0])]);
65
- i = 1;
66
- _e.label = 2;
67
- case 2:
68
- if (!(i <= poolCount)) return [3 /*break*/, 5];
69
- return [4 /*yield*/, factoryContract.pool_list(poolCount - i)];
70
- case 3:
71
- address = _e.sent();
72
- if (address.toLowerCase() === swapAddress.toLowerCase())
73
- return [2 /*return*/, "factory-tricrypto-".concat(poolCount - i)];
74
- _e.label = 4;
75
- case 4:
76
- i++;
77
- return [3 /*break*/, 2];
78
- case 5: throw Error("Unknown pool");
79
- }
80
- });
18
+ return __awaiter(this, void 0, void 0, function* () {
19
+ const factoryContract = this.contracts[this.constants.ALIASES.tricrypto_factory].contract;
20
+ const poolCount = Number(curve.formatUnits(yield factoryContract.pool_count(this.constantOptions), 0));
21
+ for (let i = 1; i <= poolCount; i++) {
22
+ const address = yield factoryContract.pool_list(poolCount - i);
23
+ if (address.toLowerCase() === swapAddress.toLowerCase())
24
+ return `factory-tricrypto-${poolCount - i}`;
25
+ }
26
+ throw Error("Unknown pool");
81
27
  });
82
28
  }
83
- function getCryptoFactoryIdsAndSwapAddresses(fromIdx) {
84
- if (fromIdx === void 0) { fromIdx = 0; }
85
- return __awaiter(this, void 0, void 0, function () {
86
- var factoryContract, factoryMulticallContract, poolCount, _a, _b, _c, calls, i, factories, swapAddresses;
87
- return __generator(this, function (_e) {
88
- switch (_e.label) {
89
- case 0:
90
- factoryContract = this.contracts[this.constants.ALIASES.tricrypto_factory].contract;
91
- factoryMulticallContract = this.contracts[this.constants.ALIASES.tricrypto_factory].multicallContract;
92
- _a = Number;
93
- _c = (_b = curve).formatUnits;
94
- return [4 /*yield*/, factoryContract.pool_count(this.constantOptions)];
95
- case 1:
96
- poolCount = _a.apply(void 0, [_c.apply(_b, [_e.sent(), 0])]);
97
- calls = [];
98
- for (i = fromIdx; i < poolCount; i++) {
99
- calls.push(factoryMulticallContract.pool_list(i));
100
- }
101
- if (calls.length === 0)
102
- return [2 /*return*/, [[], []]];
103
- return [4 /*yield*/, this.multicallProvider.all(calls)];
104
- case 2:
105
- factories = (_e.sent()).map(function (addr, i) { return ({ id: "factory-tricrypto-".concat(fromIdx + i), address: addr.toLowerCase() }); });
106
- swapAddresses = Object.values(this.constants.POOLS_DATA).map(function (pool) { return pool.swap_address.toLowerCase(); });
107
- factories = factories.filter(function (f) { return !swapAddresses.includes(f.address); });
108
- return [2 /*return*/, [factories.map(function (f) { return f.id; }), factories.map(function (f) { return f.address; })]];
109
- }
110
- });
29
+ function getCryptoFactoryIdsAndSwapAddresses(fromIdx = 0) {
30
+ return __awaiter(this, void 0, void 0, function* () {
31
+ const factoryContract = this.contracts[this.constants.ALIASES.tricrypto_factory].contract;
32
+ const factoryMulticallContract = this.contracts[this.constants.ALIASES.tricrypto_factory].multicallContract;
33
+ const poolCount = Number(curve.formatUnits(yield factoryContract.pool_count(this.constantOptions), 0));
34
+ const calls = [];
35
+ for (let i = fromIdx; i < poolCount; i++) {
36
+ calls.push(factoryMulticallContract.pool_list(i));
37
+ }
38
+ if (calls.length === 0)
39
+ return [[], []];
40
+ let factories = (yield this.multicallProvider.all(calls)).map((addr, i) => ({ id: `factory-tricrypto-${fromIdx + i}`, address: addr.toLowerCase() }));
41
+ const swapAddresses = Object.values(this.constants.POOLS_DATA).map((pool) => pool.swap_address.toLowerCase());
42
+ factories = factories.filter((f) => !swapAddresses.includes(f.address));
43
+ return [factories.map((f) => f.id), factories.map((f) => f.address)];
111
44
  });
112
45
  }
113
46
  function _handleCoinAddresses(coinAddresses) {
114
- var _this = this;
115
- return coinAddresses.map(function (addresses) { return addresses.map(function (addr) { return _this.chainId === 137 && addr === "0x0000000000000000000000000000000000001010" ? _this.constants.NATIVE_TOKEN.wrappedAddress : addr.toLowerCase(); }); });
47
+ return coinAddresses.map((addresses) => addresses.map((addr) => this.chainId === 137 && addr === "0x0000000000000000000000000000000000001010" ? this.constants.NATIVE_TOKEN.wrappedAddress : addr.toLowerCase()));
116
48
  }
117
49
  function getPoolsData(factorySwapAddresses) {
118
- return __awaiter(this, void 0, void 0, function () {
119
- var factoryMulticallContract, calls, _i, factorySwapAddresses_1, addr, res, gaugeAddresses, coinAddresses, implementationAddresses, factoryMulticallContract, isFactoryGaugeNull, factoryMulticallGaugeContract, calls, _a, factorySwapAddresses_2, addr, res, gaugeAddresses, coinAddresses, implementationAddresses, coinAddresses, gaugeAddresses, implementationAddresses;
120
- return __generator(this, function (_b) {
121
- switch (_b.label) {
122
- case 0:
123
- if (!(this.chainId === 1)) return [3 /*break*/, 2];
124
- factoryMulticallContract = this.contracts[this.constants.ALIASES.tricrypto_factory].multicallContract;
125
- calls = [];
126
- for (_i = 0, factorySwapAddresses_1 = factorySwapAddresses; _i < factorySwapAddresses_1.length; _i++) {
127
- addr = factorySwapAddresses_1[_i];
128
- calls.push(factoryMulticallContract.get_gauge(addr));
129
- calls.push(factoryMulticallContract.get_coins(addr));
130
- calls.push(factoryMulticallContract.get_implementation_address(addr));
131
- }
132
- return [4 /*yield*/, this.multicallProvider.all(calls)];
133
- case 1:
134
- res = _b.sent();
135
- gaugeAddresses = res.filter(function (a, i) { return i % 3 == 0; }).map(function (a) { return a.toLowerCase(); });
136
- coinAddresses = _handleCoinAddresses.call(this, res.filter(function (a, i) { return i % 3 == 1; }));
137
- implementationAddresses = res.filter(function (a, i) { return i % 3 == 2; }).map(function (a) { return a.toLowerCase(); });
138
- return [2 /*return*/, [gaugeAddresses, coinAddresses, implementationAddresses]];
139
- case 2:
140
- factoryMulticallContract = this.contracts[this.constants.ALIASES.tricrypto_factory].multicallContract;
141
- isFactoryGaugeNull = this.constants.ALIASES.gauge_factory === '0x0000000000000000000000000000000000000000';
142
- factoryMulticallGaugeContract = this.contracts[this.constants.ALIASES.gauge_factory].multicallContract;
143
- calls = [];
144
- for (_a = 0, factorySwapAddresses_2 = factorySwapAddresses; _a < factorySwapAddresses_2.length; _a++) {
145
- addr = factorySwapAddresses_2[_a];
146
- if (!isFactoryGaugeNull) {
147
- calls.push(factoryMulticallGaugeContract.get_gauge_from_lp_token(addr));
148
- }
149
- calls.push(factoryMulticallContract.get_coins(addr));
150
- calls.push(factoryMulticallContract.get_implementation_address(addr));
151
- }
152
- return [4 /*yield*/, this.multicallProvider.all(calls)];
153
- case 3:
154
- res = _b.sent();
155
- if (!isFactoryGaugeNull) {
156
- gaugeAddresses = res.filter(function (a, i) { return i % 3 == 0; }).map(function (a) { return a.toLowerCase(); });
157
- coinAddresses = _handleCoinAddresses.call(this, res.filter(function (a, i) { return i % 3 == 1; }));
158
- implementationAddresses = res.filter(function (a, i) { return i % 3 == 2; }).map(function (a) { return a.toLowerCase(); });
159
- return [2 /*return*/, [gaugeAddresses, coinAddresses, implementationAddresses]];
160
- }
161
- else {
162
- coinAddresses = _handleCoinAddresses.call(this, res.filter(function (a, i) { return i % 2 == 0; }));
163
- gaugeAddresses = Array.from(Array(factorySwapAddresses.length)).map(function () { return '0x0000000000000000000000000000000000000000'; });
164
- implementationAddresses = res.filter(function (a, i) { return i % 2 == 1; }).map(function (a) { return a.toLowerCase(); });
165
- return [2 /*return*/, [gaugeAddresses, coinAddresses, implementationAddresses]];
166
- }
167
- _b.label = 4;
168
- case 4: return [2 /*return*/];
50
+ return __awaiter(this, void 0, void 0, function* () {
51
+ if (this.chainId === 1) {
52
+ const factoryMulticallContract = this.contracts[this.constants.ALIASES.tricrypto_factory].multicallContract;
53
+ const calls = [];
54
+ for (const addr of factorySwapAddresses) {
55
+ calls.push(factoryMulticallContract.get_gauge(addr));
56
+ calls.push(factoryMulticallContract.get_coins(addr));
57
+ calls.push(factoryMulticallContract.get_implementation_address(addr));
169
58
  }
170
- });
59
+ const res = yield this.multicallProvider.all(calls);
60
+ const gaugeAddresses = res.filter((a, i) => i % 3 == 0).map((a) => a.toLowerCase());
61
+ const coinAddresses = _handleCoinAddresses.call(this, res.filter((a, i) => i % 3 == 1));
62
+ const implementationAddresses = res.filter((a, i) => i % 3 == 2).map((a) => a.toLowerCase());
63
+ return [gaugeAddresses, coinAddresses, implementationAddresses];
64
+ }
65
+ else {
66
+ const factoryMulticallContract = this.contracts[this.constants.ALIASES.tricrypto_factory].multicallContract;
67
+ const isFactoryGaugeNull = this.constants.ALIASES.gauge_factory === '0x0000000000000000000000000000000000000000';
68
+ const factoryMulticallGaugeContract = this.contracts[this.constants.ALIASES.gauge_factory].multicallContract;
69
+ const calls = [];
70
+ for (const addr of factorySwapAddresses) {
71
+ if (!isFactoryGaugeNull) {
72
+ calls.push(factoryMulticallGaugeContract.get_gauge_from_lp_token(addr));
73
+ }
74
+ calls.push(factoryMulticallContract.get_coins(addr));
75
+ calls.push(factoryMulticallContract.get_implementation_address(addr));
76
+ }
77
+ const res = yield this.multicallProvider.all(calls);
78
+ if (!isFactoryGaugeNull) {
79
+ const gaugeAddresses = res.filter((a, i) => i % 3 == 0).map((a) => a.toLowerCase());
80
+ const coinAddresses = _handleCoinAddresses.call(this, res.filter((a, i) => i % 3 == 1));
81
+ const implementationAddresses = res.filter((a, i) => i % 3 == 2).map((a) => a.toLowerCase());
82
+ return [gaugeAddresses, coinAddresses, implementationAddresses];
83
+ }
84
+ else {
85
+ const coinAddresses = _handleCoinAddresses.call(this, res.filter((a, i) => i % 2 == 0));
86
+ const gaugeAddresses = Array.from(Array(factorySwapAddresses.length)).map(() => '0x0000000000000000000000000000000000000000');
87
+ const implementationAddresses = res.filter((a, i) => i % 2 == 1).map((a) => a.toLowerCase());
88
+ return [gaugeAddresses, coinAddresses, implementationAddresses];
89
+ }
90
+ }
171
91
  });
172
92
  }
173
93
  function setCryptoFactorySwapContracts(factorySwapAddresses) {
174
- var _this = this;
175
- factorySwapAddresses.forEach(function (addr) {
176
- _this.setContract(addr, tricryptoFactorySwapABI);
94
+ factorySwapAddresses.forEach((addr) => {
95
+ this.setContract(addr, tricryptoFactorySwapABI);
177
96
  });
178
97
  }
179
98
  function setCryptoFactoryTokenContracts(factoryTokenAddresses) {
180
- var _this = this;
181
- factoryTokenAddresses.forEach(function (addr) {
182
- _this.setContract(addr, ERC20ABI);
99
+ factoryTokenAddresses.forEach((addr) => {
100
+ this.setContract(addr, ERC20ABI);
183
101
  });
184
102
  }
185
103
  function setCryptoFactoryGaugeContracts(factoryGaugeAddresses) {
186
- var _this = this;
187
- factoryGaugeAddresses.filter(function (addr) { return addr !== curve.constants.ZERO_ADDRESS; }).forEach(function (addr, i) {
188
- _this.setContract(addr, _this.chainId === 1 ? factoryGaugeABI : gaugeChildABI);
104
+ factoryGaugeAddresses.filter((addr) => addr !== curve.constants.ZERO_ADDRESS).forEach((addr, i) => {
105
+ this.setContract(addr, this.chainId === 1 ? factoryGaugeABI : gaugeChildABI);
189
106
  });
190
107
  }
191
108
  function setCryptoFactoryCoinsContracts(coinAddresses) {
192
- var flattenedCoinAddresses = Array.from(new Set(deepFlatten(coinAddresses)));
193
- for (var _i = 0, flattenedCoinAddresses_1 = flattenedCoinAddresses; _i < flattenedCoinAddresses_1.length; _i++) {
194
- var addr = flattenedCoinAddresses_1[_i];
109
+ const flattenedCoinAddresses = Array.from(new Set(deepFlatten(coinAddresses)));
110
+ for (const addr of flattenedCoinAddresses) {
195
111
  if (addr in this.contracts)
196
112
  continue;
197
113
  this.setContract(addr, ERC20ABI);
198
114
  }
199
115
  }
200
116
  function getExistingCoinAddressNameDict() {
201
- var dict = {};
202
- var _loop_1 = function (poolData) {
203
- poolData.wrapped_coin_addresses.forEach(function (addr, i) {
117
+ const dict = {};
118
+ for (const poolData of Object.values(this.constants.POOLS_DATA)) {
119
+ poolData.wrapped_coin_addresses.forEach((addr, i) => {
204
120
  if (!(addr.toLowerCase() in dict)) {
205
121
  dict[addr.toLowerCase()] = poolData.wrapped_coins[i];
206
122
  }
207
123
  });
208
- poolData.underlying_coin_addresses.forEach(function (addr, i) {
124
+ poolData.underlying_coin_addresses.forEach((addr, i) => {
209
125
  if (!(addr.toLowerCase() in dict)) {
210
126
  dict[addr.toLowerCase()] = poolData.underlying_coins[i];
211
127
  }
212
128
  });
213
- };
214
- for (var _i = 0, _a = Object.values(this.constants.POOLS_DATA); _i < _a.length; _i++) {
215
- var poolData = _a[_i];
216
- _loop_1(poolData);
217
129
  }
218
130
  dict[this.constants.NATIVE_TOKEN.address] = this.constants.NATIVE_TOKEN.symbol;
219
131
  return dict;
220
132
  }
221
133
  function getCoinsData(tokenAddresses, coinAddresses, existingCoinAddrNameDict, existingCoinAddrDecimalsDict) {
222
- return __awaiter(this, void 0, void 0, function () {
223
- var flattenedCoinAddresses, newCoinAddresses, coinAddrNamesDict, coinAddrDecimalsDict, _i, flattenedCoinAddresses_2, addr, calls, _a, tokenAddresses_1, addr, _b, newCoinAddresses_1, addr, res, res1, tokenSymbols, tokenNames, res2, symbols, decimals;
224
- return __generator(this, function (_c) {
225
- switch (_c.label) {
226
- case 0:
227
- flattenedCoinAddresses = Array.from(new Set(deepFlatten(coinAddresses)));
228
- newCoinAddresses = [];
229
- coinAddrNamesDict = {};
230
- coinAddrDecimalsDict = {};
231
- for (_i = 0, flattenedCoinAddresses_2 = flattenedCoinAddresses; _i < flattenedCoinAddresses_2.length; _i++) {
232
- addr = flattenedCoinAddresses_2[_i];
233
- if (addr in existingCoinAddrNameDict) {
234
- coinAddrNamesDict[addr] = existingCoinAddrNameDict[addr];
235
- coinAddrDecimalsDict[addr] = existingCoinAddrDecimalsDict[addr];
236
- }
237
- else if (addr === "0x9f8f72aa9304c8b593d555f12ef6589cc3a579a2") {
238
- coinAddrNamesDict[addr] = "MKR";
239
- }
240
- else {
241
- newCoinAddresses.push(addr);
242
- }
243
- }
244
- calls = [];
245
- for (_a = 0, tokenAddresses_1 = tokenAddresses; _a < tokenAddresses_1.length; _a++) {
246
- addr = tokenAddresses_1[_a];
247
- calls.push(this.contracts[addr].multicallContract.symbol());
248
- calls.push(this.contracts[addr].multicallContract.name());
249
- }
250
- for (_b = 0, newCoinAddresses_1 = newCoinAddresses; _b < newCoinAddresses_1.length; _b++) {
251
- addr = newCoinAddresses_1[_b];
252
- calls.push(this.contracts[addr].multicallContract.symbol());
253
- calls.push(this.contracts[addr].multicallContract.decimals());
254
- }
255
- return [4 /*yield*/, this.multicallProvider.all(calls)];
256
- case 1:
257
- res = _c.sent();
258
- res1 = res.slice(0, tokenAddresses.length * 2);
259
- tokenSymbols = res1.filter(function (a, i) { return i % 2 == 0; });
260
- tokenNames = res1.filter(function (a, i) { return i % 2 == 1; });
261
- res2 = res.slice(tokenAddresses.length * 2);
262
- symbols = res2.filter(function (a, i) { return i % 2 == 0; });
263
- decimals = res2.filter(function (a, i) { return i % 2 == 1; }).map(function (_d) { return Number(curve.formatUnits(_d, 0)); });
264
- newCoinAddresses.forEach(function (addr, i) {
265
- coinAddrNamesDict[addr] = symbols[i];
266
- coinAddrDecimalsDict[addr] = decimals[i];
267
- });
268
- coinAddrNamesDict[this.constants.NATIVE_TOKEN.address] = this.constants.NATIVE_TOKEN.symbol;
269
- coinAddrDecimalsDict[this.constants.NATIVE_TOKEN.address] = 18;
270
- return [2 /*return*/, [tokenSymbols, tokenNames, coinAddrNamesDict, coinAddrDecimalsDict]];
134
+ return __awaiter(this, void 0, void 0, function* () {
135
+ const flattenedCoinAddresses = Array.from(new Set(deepFlatten(coinAddresses)));
136
+ const newCoinAddresses = [];
137
+ const coinAddrNamesDict = {};
138
+ const coinAddrDecimalsDict = {};
139
+ for (const addr of flattenedCoinAddresses) {
140
+ if (addr in existingCoinAddrNameDict) {
141
+ coinAddrNamesDict[addr] = existingCoinAddrNameDict[addr];
142
+ coinAddrDecimalsDict[addr] = existingCoinAddrDecimalsDict[addr];
143
+ }
144
+ else if (addr === "0x9f8f72aa9304c8b593d555f12ef6589cc3a579a2") {
145
+ coinAddrNamesDict[addr] = "MKR";
146
+ }
147
+ else {
148
+ newCoinAddresses.push(addr);
271
149
  }
150
+ }
151
+ const calls = [];
152
+ for (const addr of tokenAddresses) {
153
+ calls.push(this.contracts[addr].multicallContract.symbol());
154
+ calls.push(this.contracts[addr].multicallContract.name());
155
+ }
156
+ for (const addr of newCoinAddresses) {
157
+ calls.push(this.contracts[addr].multicallContract.symbol());
158
+ calls.push(this.contracts[addr].multicallContract.decimals());
159
+ }
160
+ const res = yield this.multicallProvider.all(calls);
161
+ const res1 = res.slice(0, tokenAddresses.length * 2);
162
+ const tokenSymbols = res1.filter((a, i) => i % 2 == 0);
163
+ const tokenNames = res1.filter((a, i) => i % 2 == 1);
164
+ const res2 = res.slice(tokenAddresses.length * 2);
165
+ const symbols = res2.filter((a, i) => i % 2 == 0);
166
+ const decimals = res2.filter((a, i) => i % 2 == 1).map((_d) => Number(curve.formatUnits(_d, 0)));
167
+ newCoinAddresses.forEach((addr, i) => {
168
+ coinAddrNamesDict[addr] = symbols[i];
169
+ coinAddrDecimalsDict[addr] = decimals[i];
272
170
  });
171
+ coinAddrNamesDict[this.constants.NATIVE_TOKEN.address] = this.constants.NATIVE_TOKEN.symbol;
172
+ coinAddrDecimalsDict[this.constants.NATIVE_TOKEN.address] = 18;
173
+ return [tokenSymbols, tokenNames, coinAddrNamesDict, coinAddrDecimalsDict];
273
174
  });
274
175
  }
275
- export function getTricryptoFactoryPoolData(fromIdx, swapAddress) {
276
- if (fromIdx === void 0) { fromIdx = 0; }
277
- return __awaiter(this, void 0, void 0, function () {
278
- var _a, poolIds, swapAddresses, _b, _c, gaugeAddresses, coinAddresses, implementationAddresses, existingCoinAddressNameDict, _e, poolSymbols, poolNames, coinAddressNameDict, coinAddressDecimalsDict, TRICRYPTO_FACTORY_POOLS_DATA, nativeToken, _loop_2, this_1, i;
279
- return __generator(this, function (_f) {
280
- switch (_f.label) {
281
- case 0:
282
- if (!swapAddress) return [3 /*break*/, 2];
283
- return [4 /*yield*/, getRecentlyCreatedCryptoPoolId.call(this, swapAddress)];
284
- case 1:
285
- _b = [[_f.sent()], [swapAddress.toLowerCase()]];
286
- return [3 /*break*/, 4];
287
- case 2: return [4 /*yield*/, getCryptoFactoryIdsAndSwapAddresses.call(this, fromIdx)];
288
- case 3:
289
- _b = _f.sent();
290
- _f.label = 4;
291
- case 4:
292
- _a = _b, poolIds = _a[0], swapAddresses = _a[1];
293
- if (poolIds.length === 0)
294
- return [2 /*return*/, {}];
295
- return [4 /*yield*/, getPoolsData.call(this, swapAddresses)];
296
- case 5:
297
- _c = _f.sent(), gaugeAddresses = _c[0], coinAddresses = _c[1], implementationAddresses = _c[2];
298
- setCryptoFactorySwapContracts.call(this, swapAddresses);
299
- setCryptoFactoryGaugeContracts.call(this, gaugeAddresses);
300
- setCryptoFactoryCoinsContracts.call(this, coinAddresses);
301
- existingCoinAddressNameDict = getExistingCoinAddressNameDict.call(this);
302
- return [4 /*yield*/, getCoinsData.call(this, swapAddresses, coinAddresses, existingCoinAddressNameDict, this.constants.DECIMALS)];
303
- case 6:
304
- _e = _f.sent(), poolSymbols = _e[0], poolNames = _e[1], coinAddressNameDict = _e[2], coinAddressDecimalsDict = _e[3];
305
- TRICRYPTO_FACTORY_POOLS_DATA = {};
306
- nativeToken = this.constants.NATIVE_TOKEN;
307
- _loop_2 = function (i) {
308
- var underlyingCoinAddresses = coinAddresses[i].map(function (addr) {
309
- var isETHEnabled = implementationAddresses[i] === tricryptoDeployImplementations[curve.chainId].amm_native_transfers_enabled;
310
- if (isETHEnabled) {
311
- return addr === nativeToken.wrappedAddress ? nativeToken.address : addr;
312
- }
313
- else {
314
- return addr;
315
- }
316
- });
317
- TRICRYPTO_FACTORY_POOLS_DATA[poolIds[i]] = {
318
- name: poolNames[i],
319
- full_name: poolNames[i],
320
- symbol: poolSymbols[i],
321
- reference_asset: "CRYPTO",
322
- swap_address: swapAddresses[i],
323
- token_address: swapAddresses[i],
324
- gauge_address: gaugeAddresses[i],
325
- is_crypto: true,
326
- is_plain: underlyingCoinAddresses.toString() === coinAddresses[i].toString(),
327
- is_factory: true,
328
- underlying_coins: __spreadArray([], underlyingCoinAddresses.map(function (addr) { return coinAddressNameDict[addr]; }), true),
329
- wrapped_coins: __spreadArray([], coinAddresses[i].map(function (addr) { return coinAddressNameDict[addr]; }), true),
330
- underlying_coin_addresses: underlyingCoinAddresses,
331
- wrapped_coin_addresses: coinAddresses[i],
332
- underlying_decimals: __spreadArray([], underlyingCoinAddresses.map(function (addr) { return coinAddressDecimalsDict[addr]; }), true),
333
- wrapped_decimals: __spreadArray([], coinAddresses[i].map(function (addr) { return coinAddressDecimalsDict[addr]; }), true),
334
- swap_abi: tricryptoFactorySwapABI,
335
- gauge_abi: this_1.chainId === 1 ? factoryGaugeABI : gaugeChildABI,
336
- is_ng: true,
337
- };
338
- };
339
- this_1 = this;
340
- for (i = 0; i < poolIds.length; i++) {
341
- _loop_2(i);
342
- }
343
- return [2 /*return*/, TRICRYPTO_FACTORY_POOLS_DATA];
344
- }
345
- });
176
+ export function getTricryptoFactoryPoolData(fromIdx = 0, swapAddress) {
177
+ return __awaiter(this, void 0, void 0, function* () {
178
+ const [poolIds, swapAddresses] = swapAddress ?
179
+ [[yield getRecentlyCreatedCryptoPoolId.call(this, swapAddress)], [swapAddress.toLowerCase()]]
180
+ : yield getCryptoFactoryIdsAndSwapAddresses.call(this, fromIdx);
181
+ if (poolIds.length === 0)
182
+ return {};
183
+ const [gaugeAddresses, coinAddresses, implementationAddresses] = yield getPoolsData.call(this, swapAddresses);
184
+ setCryptoFactorySwapContracts.call(this, swapAddresses);
185
+ setCryptoFactoryGaugeContracts.call(this, gaugeAddresses);
186
+ setCryptoFactoryCoinsContracts.call(this, coinAddresses);
187
+ const existingCoinAddressNameDict = getExistingCoinAddressNameDict.call(this);
188
+ const [poolSymbols, poolNames, coinAddressNameDict, coinAddressDecimalsDict] = yield getCoinsData.call(this, swapAddresses, coinAddresses, existingCoinAddressNameDict, this.constants.DECIMALS);
189
+ const TRICRYPTO_FACTORY_POOLS_DATA = {};
190
+ const nativeToken = this.constants.NATIVE_TOKEN;
191
+ for (let i = 0; i < poolIds.length; i++) {
192
+ const underlyingCoinAddresses = coinAddresses[i].map((addr) => {
193
+ const isETHEnabled = implementationAddresses[i] === tricryptoDeployImplementations[curve.chainId].amm_native_transfers_enabled;
194
+ if (isETHEnabled) {
195
+ return addr === nativeToken.wrappedAddress ? nativeToken.address : addr;
196
+ }
197
+ else {
198
+ return addr;
199
+ }
200
+ });
201
+ TRICRYPTO_FACTORY_POOLS_DATA[poolIds[i]] = {
202
+ name: poolNames[i],
203
+ full_name: poolNames[i],
204
+ symbol: poolSymbols[i],
205
+ reference_asset: "CRYPTO",
206
+ swap_address: swapAddresses[i],
207
+ token_address: swapAddresses[i],
208
+ gauge_address: gaugeAddresses[i],
209
+ is_crypto: true,
210
+ is_plain: underlyingCoinAddresses.toString() === coinAddresses[i].toString(),
211
+ is_factory: true,
212
+ underlying_coins: [...underlyingCoinAddresses.map((addr) => coinAddressNameDict[addr])],
213
+ wrapped_coins: [...coinAddresses[i].map((addr) => coinAddressNameDict[addr])],
214
+ underlying_coin_addresses: underlyingCoinAddresses,
215
+ wrapped_coin_addresses: coinAddresses[i],
216
+ underlying_decimals: [...underlyingCoinAddresses.map((addr) => coinAddressDecimalsDict[addr])],
217
+ wrapped_decimals: [...coinAddresses[i].map((addr) => coinAddressDecimalsDict[addr])],
218
+ swap_abi: tricryptoFactorySwapABI,
219
+ gauge_abi: this.chainId === 1 ? factoryGaugeABI : gaugeChildABI,
220
+ is_ng: true,
221
+ };
222
+ }
223
+ return TRICRYPTO_FACTORY_POOLS_DATA;
346
224
  });
347
225
  }