@curvefi/api 2.32.0 → 2.33.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (59) hide show
  1. package/lib/boosting.js +385 -135
  2. package/lib/constants/aliases.js +22 -11
  3. package/lib/constants/coins/arbitrum.js +5 -5
  4. package/lib/constants/coins/aurora.js +5 -5
  5. package/lib/constants/coins/avalanche.js +6 -6
  6. package/lib/constants/coins/celo.js +5 -5
  7. package/lib/constants/coins/ethereum.js +10 -9
  8. package/lib/constants/coins/fantom.js +7 -7
  9. package/lib/constants/coins/kava.js +5 -5
  10. package/lib/constants/coins/moonbeam.js +5 -5
  11. package/lib/constants/coins/optimism.js +5 -5
  12. package/lib/constants/coins/polygon.js +6 -6
  13. package/lib/constants/coins/xdai.js +5 -5
  14. package/lib/constants/pools/arbitrum.js +1 -1
  15. package/lib/constants/pools/aurora.js +1 -1
  16. package/lib/constants/pools/avalanche.js +1 -1
  17. package/lib/constants/pools/celo.js +1 -1
  18. package/lib/constants/pools/ethereum.js +1 -1
  19. package/lib/constants/pools/fantom.js +1 -1
  20. package/lib/constants/pools/kava.js +1 -1
  21. package/lib/constants/pools/moonbeam.js +1 -1
  22. package/lib/constants/pools/optimism.js +1 -1
  23. package/lib/constants/pools/polygon.js +1 -1
  24. package/lib/constants/pools/xdai.js +1 -1
  25. package/lib/constants/utils.js +19 -18
  26. package/lib/curve.js +506 -282
  27. package/lib/external-api.js +132 -45
  28. package/lib/factory/common.js +3 -3
  29. package/lib/factory/constants-crypto.js +21 -21
  30. package/lib/factory/constants.js +32 -31
  31. package/lib/factory/deploy.js +336 -176
  32. package/lib/factory/factory-api.js +256 -180
  33. package/lib/factory/factory-crypto.js +309 -163
  34. package/lib/factory/factory.d.ts +1 -1
  35. package/lib/factory/factory.js +336 -186
  36. package/lib/index.js +98 -44
  37. package/lib/interfaces.d.ts +5 -0
  38. package/lib/pools/PoolTemplate.js +2879 -1468
  39. package/lib/pools/mixins/common.js +106 -22
  40. package/lib/pools/mixins/depositBalancedAmountsMixins.js +131 -48
  41. package/lib/pools/mixins/depositMixins.js +413 -144
  42. package/lib/pools/mixins/depositWrappedMixins.js +223 -72
  43. package/lib/pools/mixins/poolBalancesMixin.js +98 -22
  44. package/lib/pools/mixins/swapMixins.js +347 -125
  45. package/lib/pools/mixins/swapWrappedMixins.js +270 -88
  46. package/lib/pools/mixins/withdrawExpectedMixins.js +104 -23
  47. package/lib/pools/mixins/withdrawImbalanceMixins.js +316 -97
  48. package/lib/pools/mixins/withdrawImbalanceWrappedMixins.js +187 -51
  49. package/lib/pools/mixins/withdrawMixins.js +385 -122
  50. package/lib/pools/mixins/withdrawOneCoinExpectedMixins.js +88 -16
  51. package/lib/pools/mixins/withdrawOneCoinMixins.js +386 -123
  52. package/lib/pools/mixins/withdrawOneCoinWrappedExpectedMixins.js +62 -8
  53. package/lib/pools/mixins/withdrawOneCoinWrappedMixins.js +185 -53
  54. package/lib/pools/mixins/withdrawWrappedMixins.js +185 -50
  55. package/lib/pools/poolConstructor.js +25 -5
  56. package/lib/pools/utils.js +488 -299
  57. package/lib/router.js +675 -212
  58. package/lib/utils.js +675 -354
  59. package/package.json +1 -2
@@ -1,3 +1,59 @@
1
+ var __assign = (this && this.__assign) || function () {
2
+ __assign = Object.assign || function(t) {
3
+ for (var s, i = 1, n = arguments.length; i < n; i++) {
4
+ s = arguments[i];
5
+ for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p))
6
+ t[p] = s[p];
7
+ }
8
+ return t;
9
+ };
10
+ return __assign.apply(this, arguments);
11
+ };
12
+ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
13
+ function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
14
+ return new (P || (P = Promise))(function (resolve, reject) {
15
+ function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
16
+ function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
17
+ function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
18
+ step((generator = generator.apply(thisArg, _arguments || [])).next());
19
+ });
20
+ };
21
+ var __generator = (this && this.__generator) || function (thisArg, body) {
22
+ var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g;
23
+ return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
24
+ function verb(n) { return function (v) { return step([n, v]); }; }
25
+ function step(op) {
26
+ if (f) throw new TypeError("Generator is already executing.");
27
+ while (g && (g = 0, op[0] && (_ = 0)), _) try {
28
+ 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;
29
+ if (y = 0, t) op = [op[0] & 2, t.value];
30
+ switch (op[0]) {
31
+ case 0: case 1: t = op; break;
32
+ case 4: _.label++; return { value: op[1], done: false };
33
+ case 5: _.label++; y = op[1]; op = [0]; continue;
34
+ case 7: op = _.ops.pop(); _.trys.pop(); continue;
35
+ default:
36
+ if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }
37
+ if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }
38
+ if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }
39
+ if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }
40
+ if (t[2]) _.ops.pop();
41
+ _.trys.pop(); continue;
42
+ }
43
+ op = body.call(thisArg, _);
44
+ } catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }
45
+ if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
46
+ }
47
+ };
48
+ var __spreadArray = (this && this.__spreadArray) || function (to, from, pack) {
49
+ if (pack || arguments.length === 2) for (var i = 0, l = from.length, ar; i < l; i++) {
50
+ if (ar || !(i in from)) {
51
+ if (!ar) ar = Array.prototype.slice.call(from, 0, i);
52
+ ar[i] = from[i];
53
+ }
54
+ }
55
+ return to.concat(ar || Array.prototype.slice.call(from));
56
+ };
1
57
  import { Contract as MulticallContract } from "ethcall";
2
58
  import { curve } from "../curve.js";
3
59
  import ERC20ABI from "../constants/abis/ERC20.json" assert { type: 'json' };
@@ -5,7 +61,7 @@ import factoryGaugeABI from "../constants/abis/gauge_factory.json" assert { type
5
61
  import gaugeChildABI from "../constants/abis/gauge_child.json" assert { type: 'json' };
6
62
  import { setFactoryZapContracts } from "./common.js";
7
63
  import { FACTORY_CONSTANTS } from "./constants.js";
8
- const BLACK_LIST = {
64
+ var BLACK_LIST = {
9
65
  1: [
10
66
  "0x066b6e1e93fa7dcd3f0eb7f8bac7d5a747ce0bf9",
11
67
  ],
@@ -15,35 +71,72 @@ const BLACK_LIST = {
15
71
  "0x88c4d6534165510b2e2caf0a130d4f70aa4b6d71",
16
72
  ],
17
73
  };
18
- const deepFlatten = (arr) => [].concat(...arr.map((v) => (Array.isArray(v) ? deepFlatten(v) : v)));
19
- async function getRecentlyCreatedPoolId(swapAddress) {
20
- const factoryContract = this.contracts[this.constants.ALIASES.factory].contract;
21
- const poolCount = Number(curve.formatUnits(await factoryContract.pool_count(this.constantOptions), 0));
22
- for (let i = 1; i <= poolCount; i++) {
23
- const address = await factoryContract.pool_list(poolCount - i);
24
- if (address.toLowerCase() === swapAddress.toLowerCase())
25
- return `factory-v2-${poolCount - i}`;
26
- }
27
- throw Error("Unknown pool");
74
+ var deepFlatten = function (arr) { return [].concat.apply([], arr.map(function (v) { return (Array.isArray(v) ? deepFlatten(v) : v); })); };
75
+ function getRecentlyCreatedPoolId(swapAddress) {
76
+ return __awaiter(this, void 0, void 0, function () {
77
+ var factoryContract, poolCount, _a, _b, _c, i, address;
78
+ return __generator(this, function (_e) {
79
+ switch (_e.label) {
80
+ case 0:
81
+ factoryContract = this.contracts[this.constants.ALIASES.factory].contract;
82
+ _a = Number;
83
+ _c = (_b = curve).formatUnits;
84
+ return [4 /*yield*/, factoryContract.pool_count(this.constantOptions)];
85
+ case 1:
86
+ poolCount = _a.apply(void 0, [_c.apply(_b, [_e.sent(), 0])]);
87
+ i = 1;
88
+ _e.label = 2;
89
+ case 2:
90
+ if (!(i <= poolCount)) return [3 /*break*/, 5];
91
+ return [4 /*yield*/, factoryContract.pool_list(poolCount - i)];
92
+ case 3:
93
+ address = _e.sent();
94
+ if (address.toLowerCase() === swapAddress.toLowerCase())
95
+ return [2 /*return*/, "factory-v2-".concat(poolCount - i)];
96
+ _e.label = 4;
97
+ case 4:
98
+ i++;
99
+ return [3 /*break*/, 2];
100
+ case 5: throw Error("Unknown pool");
101
+ }
102
+ });
103
+ });
28
104
  }
29
- async function getFactoryIdsAndSwapAddresses(fromIdx = 0) {
30
- const factoryContract = this.contracts[this.constants.ALIASES.factory].contract;
31
- const factoryMulticallContract = this.contracts[this.constants.ALIASES.factory].multicallContract;
32
- const poolCount = Number(curve.formatUnits(await factoryContract.pool_count(this.constantOptions), 0));
33
- const calls = [];
34
- for (let i = fromIdx; i < poolCount; i++) {
35
- calls.push(factoryMulticallContract.pool_list(i));
36
- }
37
- if (calls.length === 0)
38
- return [[], []];
39
- let factories = (await this.multicallProvider.all(calls)).map((addr, i) => ({ id: `factory-v2-${fromIdx + i}`, address: addr.toLowerCase() }));
40
- const swapAddresses = Object.values(this.constants.POOLS_DATA).map((pool) => pool.swap_address.toLowerCase());
41
- const blacklist = BLACK_LIST[this.chainId] ?? [];
42
- factories = factories.filter((f) => !swapAddresses.includes(f.address) && !blacklist.includes(f.address));
43
- return [factories.map((f) => f.id), factories.map((f) => f.address)];
105
+ function getFactoryIdsAndSwapAddresses(fromIdx, factoryAddress) {
106
+ var _a;
107
+ if (fromIdx === void 0) { fromIdx = 0; }
108
+ return __awaiter(this, void 0, void 0, function () {
109
+ var factoryContract, factoryMulticallContract, poolCount, _b, _c, _e, calls, i, prefix, factories, swapAddresses, blacklist;
110
+ return __generator(this, function (_f) {
111
+ switch (_f.label) {
112
+ case 0:
113
+ factoryContract = this.contracts[factoryAddress].contract;
114
+ factoryMulticallContract = this.contracts[factoryAddress].multicallContract;
115
+ _b = Number;
116
+ _e = (_c = curve).formatUnits;
117
+ return [4 /*yield*/, factoryContract.pool_count(this.constantOptions)];
118
+ case 1:
119
+ poolCount = _b.apply(void 0, [_e.apply(_c, [_f.sent(), 0])]);
120
+ calls = [];
121
+ for (i = fromIdx; i < poolCount; i++) {
122
+ calls.push(factoryMulticallContract.pool_list(i));
123
+ }
124
+ if (calls.length === 0)
125
+ return [2 /*return*/, [[], []]];
126
+ prefix = factoryAddress === this.constants.ALIASES.factory ? "factory-v2-" : "factory-crvusd-";
127
+ return [4 /*yield*/, this.multicallProvider.all(calls)];
128
+ case 2:
129
+ factories = (_f.sent()).map(function (addr, i) { return ({ id: prefix + (fromIdx + i), address: addr.toLowerCase() }); });
130
+ swapAddresses = Object.values(this.constants.POOLS_DATA).map(function (pool) { return pool.swap_address.toLowerCase(); });
131
+ blacklist = (_a = BLACK_LIST[this.chainId]) !== null && _a !== void 0 ? _a : [];
132
+ factories = factories.filter(function (f) { return !swapAddresses.includes(f.address) && !blacklist.includes(f.address); });
133
+ return [2 /*return*/, [factories.map(function (f) { return f.id; }), factories.map(function (f) { return f.address; })]];
134
+ }
135
+ });
136
+ });
44
137
  }
45
138
  function _handleReferenceAssets(referenceAssets) {
46
- return referenceAssets.map((t) => {
139
+ return referenceAssets.map(function (t) {
47
140
  return {
48
141
  0: "USD",
49
142
  1: "ETH",
@@ -52,192 +145,249 @@ function _handleReferenceAssets(referenceAssets) {
52
145
  });
53
146
  }
54
147
  function _handleCoinAddresses(coinAddresses) {
55
- return coinAddresses.map((addresses) => addresses
56
- .filter((addr) => addr !== curve.constants.ZERO_ADDRESS)
57
- .map((addr) => this.chainId === 137 && addr === "0x0000000000000000000000000000000000001010" ? this.constants.NATIVE_TOKEN.address : addr.toLowerCase()));
148
+ var _this = this;
149
+ return coinAddresses.map(function (addresses) { return addresses
150
+ .filter(function (addr) { return addr !== curve.constants.ZERO_ADDRESS; })
151
+ .map(function (addr) { return _this.chainId === 137 && addr === "0x0000000000000000000000000000000000001010" ? _this.constants.NATIVE_TOKEN.address : addr.toLowerCase(); }); });
58
152
  }
59
- async function getPoolsData(factorySwapAddresses) {
60
- const factoryMulticallContract = this.contracts[this.constants.ALIASES.factory].multicallContract;
61
- const calls = [];
62
- for (const addr of factorySwapAddresses) {
63
- const tempSwapContract = new MulticallContract(addr, ERC20ABI);
64
- calls.push(factoryMulticallContract.get_implementation_address(addr));
65
- calls.push(factoryMulticallContract.get_gauge(addr));
66
- calls.push(factoryMulticallContract.get_pool_asset_type(addr));
67
- calls.push(tempSwapContract.symbol());
68
- calls.push(tempSwapContract.name());
69
- calls.push(factoryMulticallContract.is_meta(addr));
70
- calls.push(factoryMulticallContract.get_coins(addr));
71
- }
72
- const res = await this.multicallProvider.all(calls);
73
- const implememntationAddresses = res.filter((a, i) => i % 7 == 0).map((a) => a.toLowerCase());
74
- const gaugeAddresses = res.filter((a, i) => i % 7 == 1).map((a) => a.toLowerCase());
75
- const referenceAssets = _handleReferenceAssets(res.filter((a, i) => i % 7 == 2));
76
- const symbols = res.filter((a, i) => i % 7 == 3);
77
- const names = res.filter((a, i) => i % 7 == 4);
78
- const isMeta = res.filter((a, i) => i % 7 == 5);
79
- const coinAddresses = _handleCoinAddresses.call(this, res.filter((a, i) => i % 7 == 6));
80
- return [implememntationAddresses, gaugeAddresses, referenceAssets, symbols, names, isMeta, coinAddresses];
153
+ function getPoolsData(factorySwapAddresses, factoryAddress) {
154
+ return __awaiter(this, void 0, void 0, function () {
155
+ var factoryMulticallContract, calls, _i, factorySwapAddresses_1, addr, tempSwapContract, res, implememntationAddresses, gaugeAddresses, referenceAssets, symbols, names, isMeta, coinAddresses;
156
+ return __generator(this, function (_a) {
157
+ switch (_a.label) {
158
+ case 0:
159
+ factoryMulticallContract = this.contracts[factoryAddress].multicallContract;
160
+ calls = [];
161
+ for (_i = 0, factorySwapAddresses_1 = factorySwapAddresses; _i < factorySwapAddresses_1.length; _i++) {
162
+ addr = factorySwapAddresses_1[_i];
163
+ tempSwapContract = new MulticallContract(addr, ERC20ABI);
164
+ calls.push(factoryMulticallContract.get_implementation_address(addr));
165
+ calls.push(factoryMulticallContract.get_gauge(addr));
166
+ calls.push(factoryMulticallContract.get_pool_asset_type(addr));
167
+ calls.push(tempSwapContract.symbol());
168
+ calls.push(tempSwapContract.name());
169
+ calls.push(factoryMulticallContract.is_meta(addr));
170
+ calls.push(factoryMulticallContract.get_coins(addr));
171
+ }
172
+ return [4 /*yield*/, this.multicallProvider.all(calls)];
173
+ case 1:
174
+ res = _a.sent();
175
+ implememntationAddresses = res.filter(function (a, i) { return i % 7 == 0; }).map(function (a) { return a.toLowerCase(); });
176
+ gaugeAddresses = res.filter(function (a, i) { return i % 7 == 1; }).map(function (a) { return a.toLowerCase(); });
177
+ referenceAssets = _handleReferenceAssets(res.filter(function (a, i) { return i % 7 == 2; }));
178
+ symbols = res.filter(function (a, i) { return i % 7 == 3; });
179
+ names = res.filter(function (a, i) { return i % 7 == 4; });
180
+ isMeta = res.filter(function (a, i) { return i % 7 == 5; });
181
+ coinAddresses = _handleCoinAddresses.call(this, res.filter(function (a, i) { return i % 7 == 6; }));
182
+ return [2 /*return*/, [implememntationAddresses, gaugeAddresses, referenceAssets, symbols, names, isMeta, coinAddresses]];
183
+ }
184
+ });
185
+ });
81
186
  }
82
187
  function setFactorySwapContracts(factorySwapAddresses, factorySwapABIs) {
83
- factorySwapAddresses.forEach((addr, i) => {
84
- this.setContract(addr, factorySwapABIs[i]);
188
+ var _this = this;
189
+ factorySwapAddresses.forEach(function (addr, i) {
190
+ _this.setContract(addr, factorySwapABIs[i]);
85
191
  });
86
192
  }
87
193
  function setFactoryGaugeContracts(factoryGaugeAddresses) {
88
- factoryGaugeAddresses.filter((addr) => addr !== curve.constants.ZERO_ADDRESS).forEach((addr, i) => {
89
- this.setContract(addr, this.chainId === 1 ? factoryGaugeABI : gaugeChildABI);
194
+ var _this = this;
195
+ factoryGaugeAddresses.filter(function (addr) { return addr !== curve.constants.ZERO_ADDRESS; }).forEach(function (addr, i) {
196
+ _this.setContract(addr, _this.chainId === 1 ? factoryGaugeABI : gaugeChildABI);
90
197
  });
91
198
  }
92
199
  function setFactoryCoinsContracts(coinAddresses) {
93
- const flattenedCoinAddresses = Array.from(new Set(deepFlatten(coinAddresses)));
94
- for (const addr of flattenedCoinAddresses) {
200
+ var flattenedCoinAddresses = Array.from(new Set(deepFlatten(coinAddresses)));
201
+ for (var _i = 0, flattenedCoinAddresses_1 = flattenedCoinAddresses; _i < flattenedCoinAddresses_1.length; _i++) {
202
+ var addr = flattenedCoinAddresses_1[_i];
95
203
  if (addr in this.contracts)
96
204
  continue;
97
205
  this.setContract(addr, ERC20ABI);
98
206
  }
99
207
  }
100
208
  function getExistingCoinAddressNameDict() {
101
- const dict = {};
102
- for (const poolData of Object.values(this.constants.POOLS_DATA)) {
103
- poolData.wrapped_coin_addresses.forEach((addr, i) => {
209
+ var dict = {};
210
+ var _loop_1 = function (poolData) {
211
+ poolData.wrapped_coin_addresses.forEach(function (addr, i) {
104
212
  if (!(addr.toLowerCase() in dict)) {
105
213
  dict[addr.toLowerCase()] = poolData.wrapped_coins[i];
106
214
  }
107
215
  });
108
- poolData.underlying_coin_addresses.forEach((addr, i) => {
216
+ poolData.underlying_coin_addresses.forEach(function (addr, i) {
109
217
  if (!(addr.toLowerCase() in dict)) {
110
218
  dict[addr.toLowerCase()] = poolData.underlying_coins[i];
111
219
  }
112
220
  });
221
+ };
222
+ for (var _i = 0, _a = Object.values(this.constants.POOLS_DATA); _i < _a.length; _i++) {
223
+ var poolData = _a[_i];
224
+ _loop_1(poolData);
113
225
  }
114
226
  dict[this.constants.NATIVE_TOKEN.address] = this.constants.NATIVE_TOKEN.symbol;
115
227
  return dict;
116
228
  }
117
- async function getCoinsData(coinAddresses, existingCoinAddrNameDict, existingCoinAddrDecimalsDict) {
118
- const flattenedCoinAddresses = Array.from(new Set(deepFlatten(coinAddresses)));
119
- const newCoinAddresses = [];
120
- const coinAddrNamesDict = {};
121
- const coinAddrDecimalsDict = {};
122
- for (const addr of flattenedCoinAddresses) {
123
- if (addr in existingCoinAddrNameDict) {
124
- coinAddrNamesDict[addr] = existingCoinAddrNameDict[addr];
125
- coinAddrDecimalsDict[addr] = existingCoinAddrDecimalsDict[addr];
126
- }
127
- else {
128
- newCoinAddresses.push(addr);
129
- }
130
- }
131
- const calls = [];
132
- for (const addr of newCoinAddresses) {
133
- calls.push(this.contracts[addr].multicallContract.symbol());
134
- calls.push(this.contracts[addr].multicallContract.decimals());
135
- }
136
- const res = await this.multicallProvider.all(calls);
137
- const symbols = res.filter((a, i) => i % 2 == 0);
138
- const decimals = res.filter((a, i) => i % 2 == 1).map((_d) => Number(curve.formatUnits(_d, 0)));
139
- newCoinAddresses.forEach((addr, i) => {
140
- coinAddrNamesDict[addr] = symbols[i];
141
- coinAddrDecimalsDict[addr] = decimals[i];
229
+ function getCoinsData(coinAddresses, existingCoinAddrNameDict, existingCoinAddrDecimalsDict) {
230
+ return __awaiter(this, void 0, void 0, function () {
231
+ var flattenedCoinAddresses, newCoinAddresses, coinAddrNamesDict, coinAddrDecimalsDict, _i, flattenedCoinAddresses_2, addr, calls, _a, newCoinAddresses_1, addr, res, symbols, decimals;
232
+ return __generator(this, function (_b) {
233
+ switch (_b.label) {
234
+ case 0:
235
+ flattenedCoinAddresses = Array.from(new Set(deepFlatten(coinAddresses)));
236
+ newCoinAddresses = [];
237
+ coinAddrNamesDict = {};
238
+ coinAddrDecimalsDict = {};
239
+ for (_i = 0, flattenedCoinAddresses_2 = flattenedCoinAddresses; _i < flattenedCoinAddresses_2.length; _i++) {
240
+ addr = flattenedCoinAddresses_2[_i];
241
+ if (addr in existingCoinAddrNameDict) {
242
+ coinAddrNamesDict[addr] = existingCoinAddrNameDict[addr];
243
+ coinAddrDecimalsDict[addr] = existingCoinAddrDecimalsDict[addr];
244
+ }
245
+ else {
246
+ newCoinAddresses.push(addr);
247
+ }
248
+ }
249
+ calls = [];
250
+ for (_a = 0, newCoinAddresses_1 = newCoinAddresses; _a < newCoinAddresses_1.length; _a++) {
251
+ addr = newCoinAddresses_1[_a];
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 = _b.sent();
258
+ symbols = res.filter(function (a, i) { return i % 2 == 0; });
259
+ decimals = res.filter(function (a, i) { return i % 2 == 1; }).map(function (_d) { return Number(curve.formatUnits(_d, 0)); });
260
+ newCoinAddresses.forEach(function (addr, i) {
261
+ coinAddrNamesDict[addr] = symbols[i];
262
+ coinAddrDecimalsDict[addr] = decimals[i];
263
+ });
264
+ return [2 /*return*/, [coinAddrNamesDict, coinAddrDecimalsDict]];
265
+ }
266
+ });
142
267
  });
143
- return [coinAddrNamesDict, coinAddrDecimalsDict];
144
268
  }
145
- export async function getFactoryPoolData(fromIdx = 0, swapAddress) {
146
- const [rawPoolIds, rawSwapAddresses] = swapAddress ?
147
- [[await getRecentlyCreatedPoolId.call(this, swapAddress)], [swapAddress.toLowerCase()]]
148
- : await getFactoryIdsAndSwapAddresses.call(this, fromIdx);
149
- if (rawPoolIds.length === 0)
150
- return {};
151
- const [rawImplementations, rawGauges, rawReferenceAssets, rawPoolSymbols, rawPoolNames, rawIsMeta, rawCoinAddresses] = await getPoolsData.call(this, rawSwapAddresses);
152
- const poolIds = [];
153
- const swapAddresses = [];
154
- const implementations = [];
155
- const gaugeAddresses = [];
156
- const referenceAssets = [];
157
- const poolSymbols = [];
158
- const poolNames = [];
159
- const isMeta = [];
160
- const coinAddresses = [];
161
- const implementationABIDict = FACTORY_CONSTANTS[this.chainId].implementationABIDict;
162
- for (let i = 0; i < rawPoolIds.length; i++) {
163
- if (rawImplementations[i] in implementationABIDict) {
164
- poolIds.push(rawPoolIds[i]);
165
- swapAddresses.push(rawSwapAddresses[i]);
166
- implementations.push(rawImplementations[i]);
167
- gaugeAddresses.push(rawGauges[i]);
168
- referenceAssets.push(rawReferenceAssets[i]);
169
- poolSymbols.push(rawPoolSymbols[i]);
170
- poolNames.push(rawPoolNames[i]);
171
- isMeta.push(rawIsMeta[i]);
172
- coinAddresses.push(rawCoinAddresses[i]);
173
- }
174
- }
175
- const swapABIs = implementations.map((addr) => implementationABIDict[addr]);
176
- setFactorySwapContracts.call(this, swapAddresses, swapABIs);
177
- setFactoryGaugeContracts.call(this, gaugeAddresses);
178
- setFactoryCoinsContracts.call(this, coinAddresses);
179
- setFactoryZapContracts.call(this, false);
180
- const [coinAddressNameDict, coinAddressDecimalsDict] = await getCoinsData.call(this, coinAddresses, getExistingCoinAddressNameDict.call(this), this.constants.DECIMALS);
181
- const implementationBasePoolIdDict = FACTORY_CONSTANTS[this.chainId].implementationBasePoolIdDict;
182
- const basePoolIds = implementations.map((addr) => implementationBasePoolIdDict[addr]);
183
- const FACTORY_POOLS_DATA = {};
184
- for (let i = 0; i < poolIds.length; i++) {
185
- if (!isMeta[i]) {
186
- FACTORY_POOLS_DATA[poolIds[i]] = {
187
- name: poolNames[i].split(": ")[1].trim(),
188
- full_name: poolNames[i],
189
- symbol: poolSymbols[i],
190
- reference_asset: referenceAssets[i],
191
- swap_address: swapAddresses[i],
192
- token_address: swapAddresses[i],
193
- gauge_address: gaugeAddresses[i],
194
- implementation_address: implementations[i],
195
- is_plain: true,
196
- is_factory: true,
197
- underlying_coins: coinAddresses[i].map((addr) => coinAddressNameDict[addr]),
198
- wrapped_coins: coinAddresses[i].map((addr) => coinAddressNameDict[addr]),
199
- underlying_coin_addresses: coinAddresses[i],
200
- wrapped_coin_addresses: coinAddresses[i],
201
- underlying_decimals: coinAddresses[i].map((addr) => coinAddressDecimalsDict[addr]),
202
- wrapped_decimals: coinAddresses[i].map((addr) => coinAddressDecimalsDict[addr]),
203
- swap_abi: swapABIs[i],
204
- gauge_abi: this.chainId === 1 ? factoryGaugeABI : gaugeChildABI,
205
- };
206
- }
207
- else {
208
- const allPoolsData = { ...this.constants.POOLS_DATA, ...FACTORY_POOLS_DATA };
209
- // @ts-ignore
210
- const basePoolIdCoinsDict = Object.fromEntries(basePoolIds.map((poolId) => [poolId, allPoolsData[poolId]?.underlying_coins]));
211
- // @ts-ignore
212
- const basePoolIdCoinAddressesDict = Object.fromEntries(basePoolIds.map((poolId) => [poolId, allPoolsData[poolId]?.underlying_coin_addresses]));
213
- // @ts-ignore
214
- const basePoolIdDecimalsDict = Object.fromEntries(basePoolIds.map((poolId) => [poolId, allPoolsData[poolId]?.underlying_decimals]));
215
- const basePoolIdZapDict = FACTORY_CONSTANTS[this.chainId].basePoolIdZapDict;
216
- const basePoolZap = basePoolIdZapDict[basePoolIds[i]];
217
- FACTORY_POOLS_DATA[poolIds[i]] = {
218
- name: poolNames[i].split(": ")[1].trim(),
219
- full_name: poolNames[i],
220
- symbol: poolSymbols[i],
221
- reference_asset: referenceAssets[i],
222
- swap_address: swapAddresses[i],
223
- token_address: swapAddresses[i],
224
- gauge_address: gaugeAddresses[i],
225
- deposit_address: basePoolIdZapDict[basePoolIds[i]].address,
226
- implementation_address: implementations[i],
227
- is_meta: true,
228
- is_factory: true,
229
- base_pool: basePoolIds[i],
230
- underlying_coins: [coinAddressNameDict[coinAddresses[i][0]], ...basePoolIdCoinsDict[basePoolIds[i]]],
231
- wrapped_coins: coinAddresses[i].map((addr) => coinAddressNameDict[addr]),
232
- underlying_coin_addresses: [coinAddresses[i][0], ...basePoolIdCoinAddressesDict[basePoolIds[i]]],
233
- wrapped_coin_addresses: coinAddresses[i],
234
- underlying_decimals: [coinAddressDecimalsDict[coinAddresses[i][0]], ...basePoolIdDecimalsDict[basePoolIds[i]]],
235
- wrapped_decimals: coinAddresses[i].map((addr) => coinAddressDecimalsDict[addr]),
236
- swap_abi: swapABIs[i],
237
- gauge_abi: this.chainId === 1 ? factoryGaugeABI : gaugeChildABI,
238
- deposit_abi: basePoolZap.ABI,
239
- };
240
- }
241
- }
242
- return FACTORY_POOLS_DATA;
269
+ export function getFactoryPoolData(fromIdx, swapAddress, factoryAddress) {
270
+ if (fromIdx === void 0) { fromIdx = 0; }
271
+ if (factoryAddress === void 0) { factoryAddress = curve.constants.ALIASES.factory; }
272
+ return __awaiter(this, void 0, void 0, function () {
273
+ var _a, rawPoolIds, rawSwapAddresses, _b, _c, rawImplementations, rawGauges, rawReferenceAssets, rawPoolSymbols, rawPoolNames, rawIsMeta, rawCoinAddresses, poolIds, swapAddresses, implementations, gaugeAddresses, referenceAssets, poolSymbols, poolNames, isMeta, coinAddresses, implementationABIDict, i, swapABIs, _e, coinAddressNameDict, coinAddressDecimalsDict, implementationBasePoolIdDict, basePoolIds, FACTORY_POOLS_DATA, _loop_2, this_1, i;
274
+ return __generator(this, function (_f) {
275
+ switch (_f.label) {
276
+ case 0:
277
+ if (!swapAddress) return [3 /*break*/, 2];
278
+ return [4 /*yield*/, getRecentlyCreatedPoolId.call(this, swapAddress)];
279
+ case 1:
280
+ _b = [[_f.sent()], [swapAddress.toLowerCase()]];
281
+ return [3 /*break*/, 4];
282
+ case 2: return [4 /*yield*/, getFactoryIdsAndSwapAddresses.call(this, fromIdx, factoryAddress)];
283
+ case 3:
284
+ _b = _f.sent();
285
+ _f.label = 4;
286
+ case 4:
287
+ _a = _b, rawPoolIds = _a[0], rawSwapAddresses = _a[1];
288
+ if (rawPoolIds.length === 0)
289
+ return [2 /*return*/, {}];
290
+ return [4 /*yield*/, getPoolsData.call(this, rawSwapAddresses, factoryAddress)];
291
+ case 5:
292
+ _c = _f.sent(), rawImplementations = _c[0], rawGauges = _c[1], rawReferenceAssets = _c[2], rawPoolSymbols = _c[3], rawPoolNames = _c[4], rawIsMeta = _c[5], rawCoinAddresses = _c[6];
293
+ poolIds = [];
294
+ swapAddresses = [];
295
+ implementations = [];
296
+ gaugeAddresses = [];
297
+ referenceAssets = [];
298
+ poolSymbols = [];
299
+ poolNames = [];
300
+ isMeta = [];
301
+ coinAddresses = [];
302
+ implementationABIDict = FACTORY_CONSTANTS[this.chainId].implementationABIDict;
303
+ for (i = 0; i < rawPoolIds.length; i++) {
304
+ if (rawImplementations[i] in implementationABIDict) {
305
+ poolIds.push(rawPoolIds[i]);
306
+ swapAddresses.push(rawSwapAddresses[i]);
307
+ implementations.push(rawImplementations[i]);
308
+ gaugeAddresses.push(rawGauges[i]);
309
+ referenceAssets.push(rawReferenceAssets[i]);
310
+ poolSymbols.push(rawPoolSymbols[i]);
311
+ poolNames.push(rawPoolNames[i]);
312
+ isMeta.push(rawIsMeta[i]);
313
+ coinAddresses.push(rawCoinAddresses[i]);
314
+ }
315
+ }
316
+ swapABIs = implementations.map(function (addr) { return implementationABIDict[addr]; });
317
+ setFactorySwapContracts.call(this, swapAddresses, swapABIs);
318
+ setFactoryGaugeContracts.call(this, gaugeAddresses);
319
+ setFactoryCoinsContracts.call(this, coinAddresses);
320
+ setFactoryZapContracts.call(this, false);
321
+ return [4 /*yield*/, getCoinsData.call(this, coinAddresses, getExistingCoinAddressNameDict.call(this), this.constants.DECIMALS)];
322
+ case 6:
323
+ _e = _f.sent(), coinAddressNameDict = _e[0], coinAddressDecimalsDict = _e[1];
324
+ implementationBasePoolIdDict = FACTORY_CONSTANTS[this.chainId].implementationBasePoolIdDict;
325
+ basePoolIds = implementations.map(function (addr) { return implementationBasePoolIdDict[addr]; });
326
+ FACTORY_POOLS_DATA = {};
327
+ _loop_2 = function (i) {
328
+ if (!isMeta[i]) {
329
+ FACTORY_POOLS_DATA[poolIds[i]] = {
330
+ name: poolNames[i].split(": ")[1].trim(),
331
+ full_name: poolNames[i],
332
+ symbol: poolSymbols[i],
333
+ reference_asset: referenceAssets[i],
334
+ swap_address: swapAddresses[i],
335
+ token_address: swapAddresses[i],
336
+ gauge_address: gaugeAddresses[i],
337
+ implementation_address: implementations[i],
338
+ is_plain: true,
339
+ is_factory: true,
340
+ underlying_coins: coinAddresses[i].map(function (addr) { return coinAddressNameDict[addr]; }),
341
+ wrapped_coins: coinAddresses[i].map(function (addr) { return coinAddressNameDict[addr]; }),
342
+ underlying_coin_addresses: coinAddresses[i],
343
+ wrapped_coin_addresses: coinAddresses[i],
344
+ underlying_decimals: coinAddresses[i].map(function (addr) { return coinAddressDecimalsDict[addr]; }),
345
+ wrapped_decimals: coinAddresses[i].map(function (addr) { return coinAddressDecimalsDict[addr]; }),
346
+ swap_abi: swapABIs[i],
347
+ gauge_abi: this_1.chainId === 1 ? factoryGaugeABI : gaugeChildABI,
348
+ };
349
+ }
350
+ else {
351
+ var allPoolsData_1 = __assign(__assign({}, this_1.constants.POOLS_DATA), FACTORY_POOLS_DATA);
352
+ // @ts-ignore
353
+ var basePoolIdCoinsDict = Object.fromEntries(basePoolIds.map(function (poolId) { var _a; return [poolId, (_a = allPoolsData_1[poolId]) === null || _a === void 0 ? void 0 : _a.underlying_coins]; }));
354
+ // @ts-ignore
355
+ var basePoolIdCoinAddressesDict = Object.fromEntries(basePoolIds.map(function (poolId) { var _a; return [poolId, (_a = allPoolsData_1[poolId]) === null || _a === void 0 ? void 0 : _a.underlying_coin_addresses]; }));
356
+ // @ts-ignore
357
+ var basePoolIdDecimalsDict = Object.fromEntries(basePoolIds.map(function (poolId) { var _a; return [poolId, (_a = allPoolsData_1[poolId]) === null || _a === void 0 ? void 0 : _a.underlying_decimals]; }));
358
+ var basePoolIdZapDict = FACTORY_CONSTANTS[this_1.chainId].basePoolIdZapDict;
359
+ var basePoolZap = basePoolIdZapDict[basePoolIds[i]];
360
+ FACTORY_POOLS_DATA[poolIds[i]] = {
361
+ name: poolNames[i].split(": ")[1].trim(),
362
+ full_name: poolNames[i],
363
+ symbol: poolSymbols[i],
364
+ reference_asset: referenceAssets[i],
365
+ swap_address: swapAddresses[i],
366
+ token_address: swapAddresses[i],
367
+ gauge_address: gaugeAddresses[i],
368
+ deposit_address: basePoolIdZapDict[basePoolIds[i]].address,
369
+ implementation_address: implementations[i],
370
+ is_meta: true,
371
+ is_factory: true,
372
+ base_pool: basePoolIds[i],
373
+ underlying_coins: __spreadArray([coinAddressNameDict[coinAddresses[i][0]]], basePoolIdCoinsDict[basePoolIds[i]], true),
374
+ wrapped_coins: coinAddresses[i].map(function (addr) { return coinAddressNameDict[addr]; }),
375
+ underlying_coin_addresses: __spreadArray([coinAddresses[i][0]], basePoolIdCoinAddressesDict[basePoolIds[i]], true),
376
+ wrapped_coin_addresses: coinAddresses[i],
377
+ underlying_decimals: __spreadArray([coinAddressDecimalsDict[coinAddresses[i][0]]], basePoolIdDecimalsDict[basePoolIds[i]], true),
378
+ wrapped_decimals: coinAddresses[i].map(function (addr) { return coinAddressDecimalsDict[addr]; }),
379
+ swap_abi: swapABIs[i],
380
+ gauge_abi: this_1.chainId === 1 ? factoryGaugeABI : gaugeChildABI,
381
+ deposit_abi: basePoolZap.ABI,
382
+ };
383
+ }
384
+ };
385
+ this_1 = this;
386
+ for (i = 0; i < poolIds.length; i++) {
387
+ _loop_2(i);
388
+ }
389
+ return [2 /*return*/, FACTORY_POOLS_DATA];
390
+ }
391
+ });
392
+ });
243
393
  }