@curvefi/api 2.30.1 → 2.31.1

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 (100) hide show
  1. package/lib/boosting.js +137 -402
  2. package/lib/constants/abis/avaxcrypto/swap.json +1195 -0
  3. package/lib/constants/abis/avaxcrypto/zap.json +250 -0
  4. package/lib/constants/aliases.d.ts +11 -11
  5. package/lib/constants/aliases.js +12 -15
  6. package/lib/constants/coins/arbitrum.js +6 -9
  7. package/lib/constants/coins/aurora.js +6 -9
  8. package/lib/constants/coins/avalanche.js +12 -10
  9. package/lib/constants/coins/celo.js +6 -9
  10. package/lib/constants/coins/ethereum.js +10 -13
  11. package/lib/constants/coins/fantom.js +8 -11
  12. package/lib/constants/coins/kava.js +6 -9
  13. package/lib/constants/coins/moonbeam.js +6 -9
  14. package/lib/constants/coins/optimism.js +6 -9
  15. package/lib/constants/coins/polygon.js +7 -10
  16. package/lib/constants/coins/xdai.js +6 -9
  17. package/lib/constants/pools/arbitrum.d.ts +2 -4
  18. package/lib/constants/pools/arbitrum.js +22 -28
  19. package/lib/constants/pools/aurora.d.ts +2 -4
  20. package/lib/constants/pools/aurora.js +6 -12
  21. package/lib/constants/pools/avalanche.d.ts +2 -4
  22. package/lib/constants/pools/avalanche.js +51 -22
  23. package/lib/constants/pools/celo.d.ts +2 -4
  24. package/lib/constants/pools/celo.js +2 -5
  25. package/lib/constants/pools/ethereum.js +247 -253
  26. package/lib/constants/pools/fantom.d.ts +2 -4
  27. package/lib/constants/pools/fantom.js +28 -34
  28. package/lib/constants/pools/index.d.ts +11 -11
  29. package/lib/constants/pools/index.js +12 -25
  30. package/lib/constants/pools/kava.d.ts +2 -4
  31. package/lib/constants/pools/kava.js +2 -5
  32. package/lib/constants/pools/moonbeam.d.ts +2 -4
  33. package/lib/constants/pools/moonbeam.js +6 -12
  34. package/lib/constants/pools/optimism.d.ts +2 -4
  35. package/lib/constants/pools/optimism.js +9 -15
  36. package/lib/constants/pools/polygon.d.ts +2 -4
  37. package/lib/constants/pools/polygon.js +23 -28
  38. package/lib/constants/pools/xdai.d.ts +2 -4
  39. package/lib/constants/pools/xdai.js +25 -30
  40. package/lib/constants/utils.js +20 -29
  41. package/lib/curve.d.ts +9 -7
  42. package/lib/curve.js +397 -615
  43. package/lib/external-api.d.ts +1 -1
  44. package/lib/external-api.js +47 -140
  45. package/lib/factory/common.js +6 -10
  46. package/lib/factory/constants-crypto.js +48 -54
  47. package/lib/factory/constants.js +274 -280
  48. package/lib/factory/deploy.d.ts +8 -8
  49. package/lib/factory/deploy.js +177 -347
  50. package/lib/factory/factory-api.js +195 -278
  51. package/lib/factory/factory-crypto.js +170 -323
  52. package/lib/factory/factory.js +195 -350
  53. package/lib/index.d.ts +24 -25
  54. package/lib/index.js +87 -143
  55. package/lib/interfaces.d.ts +6 -5
  56. package/lib/interfaces.js +1 -2
  57. package/lib/pools/PoolTemplate.d.ts +1 -0
  58. package/lib/pools/PoolTemplate.js +1516 -2928
  59. package/lib/pools/index.d.ts +2 -2
  60. package/lib/pools/index.js +3 -7
  61. package/lib/pools/mixins/common.d.ts +3 -4
  62. package/lib/pools/mixins/common.js +23 -102
  63. package/lib/pools/mixins/depositBalancedAmountsMixins.d.ts +1 -1
  64. package/lib/pools/mixins/depositBalancedAmountsMixins.js +50 -139
  65. package/lib/pools/mixins/depositMixins.d.ts +1 -1
  66. package/lib/pools/mixins/depositMixins.js +145 -405
  67. package/lib/pools/mixins/depositWrappedMixins.d.ts +1 -1
  68. package/lib/pools/mixins/depositWrappedMixins.js +72 -227
  69. package/lib/pools/mixins/poolBalancesMixin.d.ts +1 -2
  70. package/lib/pools/mixins/poolBalancesMixin.js +25 -131
  71. package/lib/pools/mixins/swapMixins.d.ts +1 -1
  72. package/lib/pools/mixins/swapMixins.js +127 -353
  73. package/lib/pools/mixins/swapWrappedMixins.d.ts +1 -1
  74. package/lib/pools/mixins/swapWrappedMixins.js +90 -276
  75. package/lib/pools/mixins/withdrawExpectedMixins.d.ts +1 -2
  76. package/lib/pools/mixins/withdrawExpectedMixins.js +26 -154
  77. package/lib/pools/mixins/withdrawImbalanceMixins.d.ts +1 -1
  78. package/lib/pools/mixins/withdrawImbalanceMixins.js +99 -321
  79. package/lib/pools/mixins/withdrawImbalanceWrappedMixins.d.ts +1 -1
  80. package/lib/pools/mixins/withdrawImbalanceWrappedMixins.js +53 -192
  81. package/lib/pools/mixins/withdrawMixins.d.ts +1 -1
  82. package/lib/pools/mixins/withdrawMixins.js +124 -378
  83. package/lib/pools/mixins/withdrawOneCoinExpectedMixins.d.ts +1 -1
  84. package/lib/pools/mixins/withdrawOneCoinExpectedMixins.js +17 -92
  85. package/lib/pools/mixins/withdrawOneCoinMixins.d.ts +1 -1
  86. package/lib/pools/mixins/withdrawOneCoinMixins.js +125 -378
  87. package/lib/pools/mixins/withdrawOneCoinWrappedExpectedMixins.d.ts +1 -1
  88. package/lib/pools/mixins/withdrawOneCoinWrappedExpectedMixins.js +9 -66
  89. package/lib/pools/mixins/withdrawOneCoinWrappedMixins.d.ts +1 -1
  90. package/lib/pools/mixins/withdrawOneCoinWrappedMixins.js +55 -190
  91. package/lib/pools/mixins/withdrawWrappedMixins.d.ts +1 -1
  92. package/lib/pools/mixins/withdrawWrappedMixins.js +52 -191
  93. package/lib/pools/poolConstructor.d.ts +1 -1
  94. package/lib/pools/poolConstructor.js +79 -109
  95. package/lib/pools/utils.js +298 -500
  96. package/lib/router.d.ts +2 -2
  97. package/lib/router.js +406 -650
  98. package/lib/utils.d.ts +9 -9
  99. package/lib/utils.js +377 -731
  100. package/package.json +8 -8
@@ -1,323 +1,240 @@
1
- "use strict";
2
- var __assign = (this && this.__assign) || function () {
3
- __assign = Object.assign || function(t) {
4
- for (var s, i = 1, n = arguments.length; i < n; i++) {
5
- s = arguments[i];
6
- for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p))
7
- t[p] = s[p];
8
- }
9
- return t;
10
- };
11
- return __assign.apply(this, arguments);
12
- };
13
- var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
14
- function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
15
- return new (P || (P = Promise))(function (resolve, reject) {
16
- function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
17
- function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
18
- function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
19
- step((generator = generator.apply(thisArg, _arguments || [])).next());
20
- });
21
- };
22
- var __generator = (this && this.__generator) || function (thisArg, body) {
23
- var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g;
24
- return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
25
- function verb(n) { return function (v) { return step([n, v]); }; }
26
- function step(op) {
27
- if (f) throw new TypeError("Generator is already executing.");
28
- while (g && (g = 0, op[0] && (_ = 0)), _) try {
29
- 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;
30
- if (y = 0, t) op = [op[0] & 2, t.value];
31
- switch (op[0]) {
32
- case 0: case 1: t = op; break;
33
- case 4: _.label++; return { value: op[1], done: false };
34
- case 5: _.label++; y = op[1]; op = [0]; continue;
35
- case 7: op = _.ops.pop(); _.trys.pop(); continue;
36
- default:
37
- if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }
38
- if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }
39
- if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }
40
- if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }
41
- if (t[2]) _.ops.pop();
42
- _.trys.pop(); continue;
43
- }
44
- op = body.call(thisArg, _);
45
- } catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }
46
- if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
47
- }
48
- };
49
- var __spreadArray = (this && this.__spreadArray) || function (to, from, pack) {
50
- if (pack || arguments.length === 2) for (var i = 0, l = from.length, ar; i < l; i++) {
51
- if (ar || !(i in from)) {
52
- if (!ar) ar = Array.prototype.slice.call(from, 0, i);
53
- ar[i] = from[i];
54
- }
55
- }
56
- return to.concat(ar || Array.prototype.slice.call(from));
57
- };
58
- var __importDefault = (this && this.__importDefault) || function (mod) {
59
- return (mod && mod.__esModule) ? mod : { "default": mod };
60
- };
61
- Object.defineProperty(exports, "__esModule", { value: true });
62
- exports.getFactoryPoolsDataFromApi = exports.lowerCasePoolDataAddresses = void 0;
63
- var ethers_1 = require("ethers");
64
- var ethcall_1 = require("ethcall");
65
- var gauge_factory_json_1 = __importDefault(require("../constants/abis/gauge_factory.json"));
66
- var gauge_child_json_1 = __importDefault(require("../constants/abis/gauge_child.json"));
67
- var ERC20_json_1 = __importDefault(require("../constants/abis/ERC20.json"));
68
- var factory_crypto_pool_2_json_1 = __importDefault(require("../constants/abis/factory-crypto/factory-crypto-pool-2.json"));
69
- var constants_1 = require("./constants");
70
- var constants_crypto_1 = require("./constants-crypto");
71
- var common_1 = require("./common");
72
- var external_api_1 = require("../external-api");
73
- var lowerCasePoolDataAddresses = function (poolsData) {
74
- var _a;
75
- for (var _i = 0, poolsData_1 = poolsData; _i < poolsData_1.length; _i++) {
76
- var poolData = poolsData_1[_i];
1
+ import { Contract } from "ethers";
2
+ import { Contract as MulticallContract } from "ethcall";
3
+ import { curve } from "../curve.js";
4
+ import factoryGaugeABI from "../constants/abis/gauge_factory.json" assert { type: 'json' };
5
+ import gaugeChildABI from "../constants/abis/gauge_child.json" assert { type: 'json' };
6
+ import ERC20ABI from "../constants/abis/ERC20.json" assert { type: 'json' };
7
+ import cryptoFactorySwapABI from "../constants/abis/factory-crypto/factory-crypto-pool-2.json" assert { type: 'json' };
8
+ import { FACTORY_CONSTANTS } from "./constants.js";
9
+ import { CRYPTO_FACTORY_CONSTANTS } from "./constants-crypto.js";
10
+ import { setFactoryZapContracts } from "./common.js";
11
+ import { _getPoolsFromApi } from "../external-api.js";
12
+ export const lowerCasePoolDataAddresses = (poolsData) => {
13
+ for (const poolData of poolsData) {
77
14
  poolData.address = poolData.address.toLowerCase();
78
15
  if (poolData.lpTokenAddress)
79
16
  poolData.lpTokenAddress = poolData.lpTokenAddress.toLowerCase();
80
17
  if (poolData.gaugeAddress)
81
18
  poolData.gaugeAddress = poolData.gaugeAddress.toLowerCase();
82
19
  poolData.implementationAddress = poolData.implementationAddress.toLowerCase();
83
- for (var _b = 0, _c = poolData.coins; _b < _c.length; _b++) {
84
- var coin = _c[_b];
20
+ for (const coin of poolData.coins) {
85
21
  coin.address = coin.address.toLowerCase();
86
22
  }
87
- for (var _d = 0, _e = (_a = poolData.gaugeRewards) !== null && _a !== void 0 ? _a : []; _d < _e.length; _d++) {
88
- var reward = _e[_d];
23
+ for (const reward of poolData.gaugeRewards ?? []) {
89
24
  reward.gaugeAddress = reward.gaugeAddress.toLowerCase();
90
25
  reward.tokenAddress = reward.tokenAddress.toLowerCase();
91
26
  }
92
27
  }
93
28
  return poolsData;
94
29
  };
95
- exports.lowerCasePoolDataAddresses = lowerCasePoolDataAddresses;
96
30
  function setFactorySwapContracts(rawPoolList, isCrypto) {
97
- var _this = this;
98
31
  if (isCrypto) {
99
- rawPoolList.forEach(function (pool) {
100
- var addr = pool.address;
101
- _this.contracts[addr] = {
102
- contract: new ethers_1.Contract(addr, factory_crypto_pool_2_json_1.default, _this.signer || _this.provider),
103
- multicallContract: new ethcall_1.Contract(addr, factory_crypto_pool_2_json_1.default),
32
+ rawPoolList.forEach((pool) => {
33
+ const addr = pool.address;
34
+ this.contracts[addr] = {
35
+ contract: new Contract(addr, cryptoFactorySwapABI, this.signer || this.provider),
36
+ multicallContract: new MulticallContract(addr, cryptoFactorySwapABI),
104
37
  };
105
38
  });
106
39
  }
107
40
  else {
108
- var implementationABIDict_1 = constants_1.FACTORY_CONSTANTS[this.chainId].implementationABIDict;
109
- rawPoolList.forEach(function (pool) {
110
- var addr = pool.address;
111
- _this.contracts[addr] = {
112
- contract: new ethers_1.Contract(addr, implementationABIDict_1[pool.implementationAddress], _this.signer || _this.provider),
113
- multicallContract: new ethcall_1.Contract(addr, implementationABIDict_1[pool.implementationAddress]),
41
+ const implementationABIDict = FACTORY_CONSTANTS[this.chainId].implementationABIDict;
42
+ rawPoolList.forEach((pool) => {
43
+ const addr = pool.address;
44
+ this.contracts[addr] = {
45
+ contract: new Contract(addr, implementationABIDict[pool.implementationAddress], this.signer || this.provider),
46
+ multicallContract: new MulticallContract(addr, implementationABIDict[pool.implementationAddress]),
114
47
  };
115
48
  });
116
49
  }
117
50
  }
118
51
  function setCryptoFactoryTokenContracts(rawPoolList) {
119
- var _this = this;
120
- rawPoolList.forEach(function (pool) {
121
- var addr = pool.lpTokenAddress;
122
- _this.contracts[addr] = {
123
- contract: new ethers_1.Contract(addr, ERC20_json_1.default, _this.signer || _this.provider),
124
- multicallContract: new ethcall_1.Contract(addr, ERC20_json_1.default),
52
+ rawPoolList.forEach((pool) => {
53
+ const addr = pool.lpTokenAddress;
54
+ this.contracts[addr] = {
55
+ contract: new Contract(addr, ERC20ABI, this.signer || this.provider),
56
+ multicallContract: new MulticallContract(addr, ERC20ABI),
125
57
  };
126
58
  });
127
59
  }
128
60
  function setFactoryGaugeContracts(rawPoolList) {
129
- var _this = this;
130
- rawPoolList.forEach(function (pool) {
61
+ rawPoolList.forEach((pool) => {
131
62
  if (pool.gaugeAddress) {
132
- var addr = pool.gaugeAddress;
133
- _this.contracts[addr] = {
134
- contract: new ethers_1.Contract(addr, _this.chainId === 1 ? gauge_factory_json_1.default : gauge_child_json_1.default, _this.signer || _this.provider),
135
- multicallContract: new ethcall_1.Contract(addr, _this.chainId === 1 ? gauge_factory_json_1.default : gauge_child_json_1.default),
63
+ const addr = pool.gaugeAddress;
64
+ this.contracts[addr] = {
65
+ contract: new Contract(addr, this.chainId === 1 ? factoryGaugeABI : gaugeChildABI, this.signer || this.provider),
66
+ multicallContract: new MulticallContract(addr, this.chainId === 1 ? factoryGaugeABI : gaugeChildABI),
136
67
  };
137
68
  }
138
69
  });
139
70
  }
140
71
  function setFactoryCoinsContracts(rawPoolList) {
141
- for (var _i = 0, rawPoolList_1 = rawPoolList; _i < rawPoolList_1.length; _i++) {
142
- var pool = rawPoolList_1[_i];
143
- for (var _a = 0, _b = pool.coins; _a < _b.length; _a++) {
144
- var coin = _b[_a];
145
- var addr = coin.address;
72
+ for (const pool of rawPoolList) {
73
+ for (const coin of pool.coins) {
74
+ const addr = coin.address;
146
75
  if (addr in this.contracts)
147
76
  continue;
148
77
  this.contracts[addr] = {
149
- contract: new ethers_1.Contract(addr, ERC20_json_1.default, this.signer || this.provider),
150
- multicallContract: new ethcall_1.Contract(addr, ERC20_json_1.default),
78
+ contract: new Contract(addr, ERC20ABI, this.signer || this.provider),
79
+ multicallContract: new MulticallContract(addr, ERC20ABI),
151
80
  };
152
81
  }
153
82
  }
154
83
  }
155
- function getFactoryPoolsDataFromApi(isCrypto) {
156
- return __awaiter(this, void 0, void 0, function () {
157
- var network, factoryType, rawPoolList, _a, mainAddresses, FACTORY_POOLS_DATA;
158
- var _this = this;
159
- return __generator(this, function (_b) {
160
- switch (_b.label) {
161
- case 0:
162
- network = this.constants.NETWORK_NAME;
163
- factoryType = isCrypto ? "factory-crypto" : "factory";
164
- _a = exports.lowerCasePoolDataAddresses;
165
- return [4 /*yield*/, (0, external_api_1._getPoolsFromApi)(network, factoryType)];
166
- case 1:
167
- rawPoolList = _a.apply(void 0, [(_b.sent()).poolData]);
168
- if (!isCrypto) {
169
- rawPoolList = rawPoolList.filter(function (p) { return p.implementationAddress in constants_1.FACTORY_CONSTANTS[_this.chainId].implementationABIDict; });
170
- }
171
- mainAddresses = Object.values(this.constants.POOLS_DATA).map(function (pool) { return pool.swap_address; });
172
- rawPoolList = rawPoolList.filter(function (p) { return !mainAddresses.includes(p.address); });
173
- setFactorySwapContracts.call(this, rawPoolList, isCrypto);
174
- if (isCrypto)
175
- setCryptoFactoryTokenContracts.call(this, rawPoolList);
176
- setFactoryGaugeContracts.call(this, rawPoolList);
177
- setFactoryCoinsContracts.call(this, rawPoolList);
178
- common_1.setFactoryZapContracts.call(this, isCrypto);
179
- FACTORY_POOLS_DATA = {};
180
- rawPoolList.forEach(function (pool) {
181
- var nativeToken = _this.constants.NATIVE_TOKEN;
182
- var coinAddresses = pool.coins.map(function (c) { return c.address; });
183
- if (_this.chainId === 137) {
184
- coinAddresses = coinAddresses.map(function (a) { return a === "0x0000000000000000000000000000000000001010" ? nativeToken.wrappedAddress : a; });
185
- }
186
- var coinNames = pool.coins.map(function (c) { return c.symbol; });
187
- var coinDecimals = pool.coins.map(function (c) { return Number(c.decimals); });
188
- if (isCrypto) {
189
- var wrappedCoinNames = pool.coins.map(function (c) { return c.symbol === nativeToken.symbol ? nativeToken.wrappedSymbol : c.symbol; });
190
- var underlyingCoinNames = pool.coins.map(function (c) { return c.symbol === nativeToken.wrappedSymbol ? nativeToken.symbol : c.symbol; });
191
- var underlyingCoinAddresses = coinAddresses.map(function (addr) { return addr === nativeToken.wrappedAddress ? nativeToken.address : addr; });
192
- var isPlain = !coinAddresses.includes(nativeToken.wrappedAddress);
193
- var lpTokenBasePoolIdDict = constants_crypto_1.CRYPTO_FACTORY_CONSTANTS[_this.chainId].lpTokenBasePoolIdDict;
194
- var basePoolIdZapDict = constants_crypto_1.CRYPTO_FACTORY_CONSTANTS[_this.chainId].basePoolIdZapDict;
195
- var basePoolId = lpTokenBasePoolIdDict[coinAddresses[1]];
196
- if (basePoolId) { // isMeta
197
- var allPoolsData = __assign(__assign({}, _this.constants.POOLS_DATA), FACTORY_POOLS_DATA);
198
- var basePoolCoinNames = __spreadArray([], allPoolsData[basePoolId].underlying_coins, true);
199
- var basePoolCoinAddresses = __spreadArray([], allPoolsData[basePoolId].underlying_coin_addresses, true);
200
- var basePoolDecimals = __spreadArray([], allPoolsData[basePoolId].underlying_decimals, true);
201
- var basePoolZap = basePoolIdZapDict[basePoolId];
202
- FACTORY_POOLS_DATA[pool.id] = {
203
- name: pool.name.split(": ")[1].trim(),
204
- full_name: pool.name,
205
- symbol: pool.symbol,
206
- reference_asset: "CRYPTO",
207
- swap_address: pool.address,
208
- token_address: pool.lpTokenAddress,
209
- gauge_address: pool.gaugeAddress ? pool.gaugeAddress : ethers_1.ethers.constants.AddressZero,
210
- deposit_address: basePoolZap.address,
211
- is_meta: true,
212
- is_crypto: true,
213
- is_factory: true,
214
- base_pool: basePoolId,
215
- underlying_coins: __spreadArray([underlyingCoinNames[0]], basePoolCoinNames, true),
216
- wrapped_coins: wrappedCoinNames,
217
- underlying_coin_addresses: __spreadArray([underlyingCoinAddresses[0]], basePoolCoinAddresses, true),
218
- wrapped_coin_addresses: coinAddresses,
219
- underlying_decimals: __spreadArray([coinDecimals[0]], basePoolDecimals, true),
220
- wrapped_decimals: coinDecimals,
221
- swap_abi: factory_crypto_pool_2_json_1.default,
222
- gauge_abi: _this.chainId === 1 ? gauge_factory_json_1.default : gauge_child_json_1.default,
223
- deposit_abi: basePoolZap.ABI,
224
- in_api: true,
225
- };
226
- }
227
- else {
228
- FACTORY_POOLS_DATA[pool.id] = {
229
- name: pool.name.split(": ")[1].trim(),
230
- full_name: pool.name,
231
- symbol: pool.symbol,
232
- reference_asset: "CRYPTO",
233
- swap_address: pool.address,
234
- token_address: pool.lpTokenAddress,
235
- gauge_address: pool.gaugeAddress ? pool.gaugeAddress : ethers_1.ethers.constants.AddressZero,
236
- is_crypto: true,
237
- is_plain: isPlain,
238
- is_factory: true,
239
- underlying_coins: underlyingCoinNames,
240
- wrapped_coins: wrappedCoinNames,
241
- underlying_coin_addresses: underlyingCoinAddresses,
242
- wrapped_coin_addresses: coinAddresses,
243
- underlying_decimals: coinDecimals,
244
- wrapped_decimals: coinDecimals,
245
- swap_abi: factory_crypto_pool_2_json_1.default,
246
- gauge_abi: _this.chainId === 1 ? gauge_factory_json_1.default : gauge_child_json_1.default,
247
- in_api: true,
248
- };
249
- }
250
- }
251
- else if (pool.implementation.includes("meta")) {
252
- var implementationABIDict = constants_1.FACTORY_CONSTANTS[_this.chainId].implementationABIDict;
253
- var implementationBasePoolIdDict = constants_1.FACTORY_CONSTANTS[_this.chainId].implementationBasePoolIdDict;
254
- var basePoolIds = Object.values(implementationBasePoolIdDict).filter(function (poolId, i, arr) { return arr.indexOf(poolId) === i; });
255
- var allPoolsData_1 = __assign(__assign({}, _this.constants.POOLS_DATA), FACTORY_POOLS_DATA);
256
- // @ts-ignore
257
- 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]; }));
258
- // @ts-ignore
259
- 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]; }));
260
- // @ts-ignore
261
- 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]; }));
262
- var basePoolIdZapDict = constants_1.FACTORY_CONSTANTS[_this.chainId].basePoolIdZapDict;
263
- var basePoolId = implementationBasePoolIdDict[pool.implementationAddress];
264
- var basePoolCoinNames = basePoolIdCoinsDict[basePoolId];
265
- var basePoolCoinAddresses = basePoolIdCoinAddressesDict[basePoolId];
266
- var basePoolDecimals = basePoolIdDecimalsDict[basePoolId];
267
- var basePoolZap = basePoolIdZapDict[basePoolId];
268
- FACTORY_POOLS_DATA[pool.id] = {
269
- name: pool.name.split(": ")[1].trim(),
270
- full_name: pool.name,
271
- symbol: pool.symbol,
272
- reference_asset: pool.assetTypeName.toUpperCase(),
273
- swap_address: pool.address,
274
- token_address: pool.address,
275
- gauge_address: pool.gaugeAddress ? pool.gaugeAddress : ethers_1.ethers.constants.AddressZero,
276
- deposit_address: basePoolZap.address,
277
- implementation_address: pool.implementationAddress,
278
- is_meta: true,
279
- is_factory: true,
280
- base_pool: basePoolId,
281
- underlying_coins: __spreadArray([coinNames[0]], basePoolCoinNames, true),
282
- wrapped_coins: coinNames,
283
- underlying_coin_addresses: __spreadArray([coinAddresses[0]], basePoolCoinAddresses, true),
284
- wrapped_coin_addresses: coinAddresses,
285
- underlying_decimals: __spreadArray([coinDecimals[0]], basePoolDecimals, true),
286
- wrapped_decimals: coinDecimals,
287
- swap_abi: implementationABIDict[pool.implementationAddress],
288
- gauge_abi: _this.chainId === 1 ? gauge_factory_json_1.default : gauge_child_json_1.default,
289
- deposit_abi: basePoolZap.ABI,
290
- in_api: true,
291
- };
292
- }
293
- else {
294
- var implementationABIDict = constants_1.FACTORY_CONSTANTS[_this.chainId].implementationABIDict;
295
- FACTORY_POOLS_DATA[pool.id] = {
296
- name: pool.name.split(": ")[1].trim(),
297
- full_name: pool.name,
298
- symbol: pool.symbol,
299
- reference_asset: pool.assetTypeName.toUpperCase(),
300
- swap_address: pool.address,
301
- token_address: pool.address,
302
- gauge_address: pool.gaugeAddress ? pool.gaugeAddress : ethers_1.ethers.constants.AddressZero,
303
- implementation_address: pool.implementationAddress,
304
- is_plain: true,
305
- is_factory: true,
306
- underlying_coins: coinNames,
307
- wrapped_coins: coinNames,
308
- underlying_coin_addresses: coinAddresses,
309
- wrapped_coin_addresses: coinAddresses,
310
- underlying_decimals: coinDecimals,
311
- wrapped_decimals: coinDecimals,
312
- swap_abi: implementationABIDict[pool.implementationAddress],
313
- gauge_abi: _this.chainId === 1 ? gauge_factory_json_1.default : gauge_child_json_1.default,
314
- in_api: true,
315
- };
316
- }
317
- });
318
- return [2 /*return*/, FACTORY_POOLS_DATA];
84
+ export async function getFactoryPoolsDataFromApi(isCrypto) {
85
+ const network = this.constants.NETWORK_NAME;
86
+ const factoryType = isCrypto ? "factory-crypto" : "factory";
87
+ let rawPoolList = lowerCasePoolDataAddresses((await _getPoolsFromApi(network, factoryType)).poolData);
88
+ if (!isCrypto) {
89
+ rawPoolList = rawPoolList.filter((p) => p.implementationAddress in FACTORY_CONSTANTS[this.chainId].implementationABIDict);
90
+ }
91
+ // Filter duplications
92
+ const mainAddresses = Object.values(this.constants.POOLS_DATA).map((pool) => pool.swap_address);
93
+ rawPoolList = rawPoolList.filter((p) => !mainAddresses.includes(p.address));
94
+ setFactorySwapContracts.call(this, rawPoolList, isCrypto);
95
+ if (isCrypto)
96
+ setCryptoFactoryTokenContracts.call(this, rawPoolList);
97
+ setFactoryGaugeContracts.call(this, rawPoolList);
98
+ setFactoryCoinsContracts.call(this, rawPoolList);
99
+ setFactoryZapContracts.call(this, isCrypto);
100
+ const FACTORY_POOLS_DATA = {};
101
+ rawPoolList.forEach((pool) => {
102
+ const nativeToken = this.constants.NATIVE_TOKEN;
103
+ let coinAddresses = pool.coins.map((c) => c.address);
104
+ if (this.chainId === 137) {
105
+ coinAddresses = coinAddresses.map((a) => a === "0x0000000000000000000000000000000000001010" ? nativeToken.wrappedAddress : a);
106
+ }
107
+ const coinNames = pool.coins.map((c) => c.symbol);
108
+ const coinDecimals = pool.coins.map((c) => Number(c.decimals));
109
+ if (isCrypto) {
110
+ const wrappedCoinNames = pool.coins.map((c) => c.symbol === nativeToken.symbol ? nativeToken.wrappedSymbol : c.symbol);
111
+ const underlyingCoinNames = pool.coins.map((c) => c.symbol === nativeToken.wrappedSymbol ? nativeToken.symbol : c.symbol);
112
+ const underlyingCoinAddresses = coinAddresses.map((addr) => addr === nativeToken.wrappedAddress ? nativeToken.address : addr);
113
+ const isPlain = !coinAddresses.includes(nativeToken.wrappedAddress);
114
+ const lpTokenBasePoolIdDict = CRYPTO_FACTORY_CONSTANTS[this.chainId].lpTokenBasePoolIdDict;
115
+ const basePoolIdZapDict = CRYPTO_FACTORY_CONSTANTS[this.chainId].basePoolIdZapDict;
116
+ const basePoolId = lpTokenBasePoolIdDict[coinAddresses[1]];
117
+ if (basePoolId) { // isMeta
118
+ const allPoolsData = { ...this.constants.POOLS_DATA, ...FACTORY_POOLS_DATA };
119
+ const basePoolCoinNames = [...allPoolsData[basePoolId].underlying_coins];
120
+ const basePoolCoinAddresses = [...allPoolsData[basePoolId].underlying_coin_addresses];
121
+ const basePoolDecimals = [...allPoolsData[basePoolId].underlying_decimals];
122
+ const basePoolZap = basePoolIdZapDict[basePoolId];
123
+ FACTORY_POOLS_DATA[pool.id] = {
124
+ name: pool.name.split(": ")[1].trim(),
125
+ full_name: pool.name,
126
+ symbol: pool.symbol,
127
+ reference_asset: "CRYPTO",
128
+ swap_address: pool.address,
129
+ token_address: pool.lpTokenAddress,
130
+ gauge_address: pool.gaugeAddress ? pool.gaugeAddress : curve.constants.ZERO_ADDRESS,
131
+ deposit_address: basePoolZap.address,
132
+ is_meta: true,
133
+ is_crypto: true,
134
+ is_factory: true,
135
+ base_pool: basePoolId,
136
+ underlying_coins: [underlyingCoinNames[0], ...basePoolCoinNames],
137
+ wrapped_coins: wrappedCoinNames,
138
+ underlying_coin_addresses: [underlyingCoinAddresses[0], ...basePoolCoinAddresses],
139
+ wrapped_coin_addresses: coinAddresses,
140
+ underlying_decimals: [coinDecimals[0], ...basePoolDecimals],
141
+ wrapped_decimals: coinDecimals,
142
+ swap_abi: cryptoFactorySwapABI,
143
+ gauge_abi: this.chainId === 1 ? factoryGaugeABI : gaugeChildABI,
144
+ deposit_abi: basePoolZap.ABI,
145
+ in_api: true,
146
+ };
319
147
  }
320
- });
148
+ else {
149
+ FACTORY_POOLS_DATA[pool.id] = {
150
+ name: pool.name.split(": ")[1].trim(),
151
+ full_name: pool.name,
152
+ symbol: pool.symbol,
153
+ reference_asset: "CRYPTO",
154
+ swap_address: pool.address,
155
+ token_address: pool.lpTokenAddress,
156
+ gauge_address: pool.gaugeAddress ? pool.gaugeAddress : curve.constants.ZERO_ADDRESS,
157
+ is_crypto: true,
158
+ is_plain: isPlain,
159
+ is_factory: true,
160
+ underlying_coins: underlyingCoinNames,
161
+ wrapped_coins: wrappedCoinNames,
162
+ underlying_coin_addresses: underlyingCoinAddresses,
163
+ wrapped_coin_addresses: coinAddresses,
164
+ underlying_decimals: coinDecimals,
165
+ wrapped_decimals: coinDecimals,
166
+ swap_abi: cryptoFactorySwapABI,
167
+ gauge_abi: this.chainId === 1 ? factoryGaugeABI : gaugeChildABI,
168
+ in_api: true,
169
+ };
170
+ }
171
+ }
172
+ else if (pool.implementation.includes("meta")) {
173
+ const implementationABIDict = FACTORY_CONSTANTS[this.chainId].implementationABIDict;
174
+ const implementationBasePoolIdDict = FACTORY_CONSTANTS[this.chainId].implementationBasePoolIdDict;
175
+ const basePoolIds = Object.values(implementationBasePoolIdDict).filter((poolId, i, arr) => arr.indexOf(poolId) === i);
176
+ const allPoolsData = { ...this.constants.POOLS_DATA, ...FACTORY_POOLS_DATA };
177
+ // @ts-ignore
178
+ const basePoolIdCoinsDict = Object.fromEntries(basePoolIds.map((poolId) => [poolId, allPoolsData[poolId]?.underlying_coins]));
179
+ // @ts-ignore
180
+ const basePoolIdCoinAddressesDict = Object.fromEntries(basePoolIds.map((poolId) => [poolId, allPoolsData[poolId]?.underlying_coin_addresses]));
181
+ // @ts-ignore
182
+ const basePoolIdDecimalsDict = Object.fromEntries(basePoolIds.map((poolId) => [poolId, allPoolsData[poolId]?.underlying_decimals]));
183
+ const basePoolIdZapDict = FACTORY_CONSTANTS[this.chainId].basePoolIdZapDict;
184
+ const basePoolId = implementationBasePoolIdDict[pool.implementationAddress];
185
+ const basePoolCoinNames = basePoolIdCoinsDict[basePoolId];
186
+ const basePoolCoinAddresses = basePoolIdCoinAddressesDict[basePoolId];
187
+ const basePoolDecimals = basePoolIdDecimalsDict[basePoolId];
188
+ const basePoolZap = basePoolIdZapDict[basePoolId];
189
+ FACTORY_POOLS_DATA[pool.id] = {
190
+ name: pool.name.split(": ")[1].trim(),
191
+ full_name: pool.name,
192
+ symbol: pool.symbol,
193
+ reference_asset: pool.assetTypeName.toUpperCase(),
194
+ swap_address: pool.address,
195
+ token_address: pool.address,
196
+ gauge_address: pool.gaugeAddress ? pool.gaugeAddress : curve.constants.ZERO_ADDRESS,
197
+ deposit_address: basePoolZap.address,
198
+ implementation_address: pool.implementationAddress,
199
+ is_meta: true,
200
+ is_factory: true,
201
+ base_pool: basePoolId,
202
+ underlying_coins: [coinNames[0], ...basePoolCoinNames],
203
+ wrapped_coins: coinNames,
204
+ underlying_coin_addresses: [coinAddresses[0], ...basePoolCoinAddresses],
205
+ wrapped_coin_addresses: coinAddresses,
206
+ underlying_decimals: [coinDecimals[0], ...basePoolDecimals],
207
+ wrapped_decimals: coinDecimals,
208
+ swap_abi: implementationABIDict[pool.implementationAddress],
209
+ gauge_abi: this.chainId === 1 ? factoryGaugeABI : gaugeChildABI,
210
+ deposit_abi: basePoolZap.ABI,
211
+ in_api: true,
212
+ };
213
+ }
214
+ else {
215
+ const implementationABIDict = FACTORY_CONSTANTS[this.chainId].implementationABIDict;
216
+ FACTORY_POOLS_DATA[pool.id] = {
217
+ name: pool.name.split(": ")[1].trim(),
218
+ full_name: pool.name,
219
+ symbol: pool.symbol,
220
+ reference_asset: pool.assetTypeName.toUpperCase(),
221
+ swap_address: pool.address,
222
+ token_address: pool.address,
223
+ gauge_address: pool.gaugeAddress ? pool.gaugeAddress : curve.constants.ZERO_ADDRESS,
224
+ implementation_address: pool.implementationAddress,
225
+ is_plain: true,
226
+ is_factory: true,
227
+ underlying_coins: coinNames,
228
+ wrapped_coins: coinNames,
229
+ underlying_coin_addresses: coinAddresses,
230
+ wrapped_coin_addresses: coinAddresses,
231
+ underlying_decimals: coinDecimals,
232
+ wrapped_decimals: coinDecimals,
233
+ swap_abi: implementationABIDict[pool.implementationAddress],
234
+ gauge_abi: this.chainId === 1 ? factoryGaugeABI : gaugeChildABI,
235
+ in_api: true,
236
+ };
237
+ }
321
238
  });
239
+ return FACTORY_POOLS_DATA;
322
240
  }
323
- exports.getFactoryPoolsDataFromApi = getFactoryPoolsDataFromApi;