@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
package/lib/curve.js CHANGED
@@ -1,123 +1,52 @@
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());
1
+ import { ethers, Contract } from "ethers";
2
+ import { Provider as MulticallProvider, Contract as MulticallContract } from 'ethcall';
3
+ import { getFactoryPoolData } from "./factory/factory.js";
4
+ import { getFactoryPoolsDataFromApi } from "./factory/factory-api.js";
5
+ import { getCryptoFactoryPoolData } from "./factory/factory-crypto.js";
6
+ import ERC20Abi from './constants/abis/ERC20.json' assert { type: 'json' };
7
+ import cERC20Abi from './constants/abis/cERC20.json' assert { type: 'json' };
8
+ import yERC20Abi from './constants/abis/yERC20.json' assert { type: 'json' };
9
+ import minterABI from './constants/abis/minter.json' assert { type: 'json' };
10
+ import minterChildABI from './constants/abis/minter_child.json' assert { type: 'json' };
11
+ import votingEscrowABI from './constants/abis/votingescrow.json' assert { type: 'json' };
12
+ import feeDistributorABI from './constants/abis/fee_distributor.json' assert { type: 'json' };
13
+ import addressProviderABI from './constants/abis/address_provider.json' assert { type: 'json' };
14
+ import gaugeControllerABI from './constants/abis/gaugecontroller.json' assert { type: 'json' };
15
+ import routerABI from './constants/abis/router.json' assert { type: 'json' };
16
+ import depositAndStakeABI from './constants/abis/deposit_and_stake.json' assert { type: 'json' };
17
+ import depositAndStake6CoinsABI from './constants/abis/deposit_and_stake_6coins.json' assert { type: 'json' };
18
+ import registryExchangeABI from './constants/abis/registry_exchange.json' assert { type: 'json' };
19
+ import streamerABI from './constants/abis/streamer.json' assert { type: 'json' };
20
+ import factoryABI from './constants/abis/factory.json' assert { type: 'json' };
21
+ import cryptoFactoryABI from './constants/abis/factory-crypto.json' assert { type: 'json' };
22
+ import { POOLS_DATA_ETHEREUM, POOLS_DATA_POLYGON, POOLS_DATA_FANTOM, POOLS_DATA_AVALANCHE, POOLS_DATA_ARBITRUM, POOLS_DATA_OPTIMISM, POOLS_DATA_XDAI, POOLS_DATA_MOONBEAM, POOLS_DATA_AURORA, POOLS_DATA_KAVA, POOLS_DATA_CELO, } from './constants/pools/index.js';
23
+ import { ALIASES_ETHEREUM, ALIASES_OPTIMISM, ALIASES_POLYGON, ALIASES_FANTOM, ALIASES_AVALANCHE, ALIASES_ARBITRUM, ALIASES_XDAI, ALIASES_MOONBEAM, ALIASES_AURORA, ALIASES_KAVA, ALIASES_CELO, } from "./constants/aliases.js";
24
+ import { COINS_ETHEREUM, cTokensEthereum, yTokensEthereum, ycTokensEthereum, aTokensEthereum } from "./constants/coins/ethereum.js";
25
+ import { COINS_OPTIMISM, cTokensOptimism, yTokensOptimism, ycTokensOptimism, aTokensOptimism } from "./constants/coins/optimism.js";
26
+ import { COINS_POLYGON, cTokensPolygon, yTokensPolygon, ycTokensPolygon, aTokensPolygon } from "./constants/coins/polygon.js";
27
+ import { COINS_FANTOM, cTokensFantom, yTokensFantom, ycTokensFantom, aTokensFantom } from "./constants/coins/fantom.js";
28
+ import { COINS_AVALANCHE, cTokensAvalanche, yTokensAvalanche, ycTokensAvalanche, aTokensAvalanche } from "./constants/coins/avalanche.js";
29
+ import { COINS_ARBITRUM, cTokensArbitrum, yTokensArbitrum, ycTokensArbitrum, aTokensArbitrum } from "./constants/coins/arbitrum.js";
30
+ import { COINS_XDAI, cTokensXDai, yTokensXDai, ycTokensXDai, aTokensXDai } from "./constants/coins/xdai.js";
31
+ import { COINS_MOONBEAM, cTokensMoonbeam, yTokensMoonbeam, ycTokensMoonbeam, aTokensMoonbeam } from "./constants/coins/moonbeam.js";
32
+ import { COINS_AURORA, cTokensAurora, yTokensAurora, ycTokensAurora, aTokensAurora } from "./constants/coins/aurora.js";
33
+ import { COINS_KAVA, cTokensKava, yTokensKava, ycTokensKava, aTokensKava } from "./constants/coins/kava.js";
34
+ import { COINS_CELO, cTokensCelo, yTokensCelo, ycTokensCelo, aTokensCelo } from "./constants/coins/celo.js";
35
+ import { lowerCasePoolDataAddresses, extractDecimals, extractGauges } from "./constants/utils.js";
36
+ import { _getAllGauges, _getHiddenPools } from "./external-api.js";
37
+ const _killGauges = async (poolsData) => {
38
+ const gaugeData = await _getAllGauges();
39
+ const isKilled = {};
40
+ Object.values(gaugeData).forEach((d) => {
41
+ isKilled[d.gauge.toLowerCase()] = d.is_killed ?? false;
20
42
  });
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];
43
+ for (const poolId in poolsData) {
44
+ if (isKilled[poolsData[poolId].gauge_address]) {
45
+ poolsData[poolId].gauge_address = ethers.ZeroAddress;
54
46
  }
55
47
  }
56
- return to.concat(ar || Array.prototype.slice.call(from));
57
48
  };
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.curve = exports.NETWORK_CONSTANTS = exports.NATIVE_TOKENS = void 0;
63
- var ethers_1 = require("ethers");
64
- var ethcall_1 = require("ethcall");
65
- var factory_1 = require("./factory/factory");
66
- var factory_api_1 = require("./factory/factory-api");
67
- var factory_crypto_1 = require("./factory/factory-crypto");
68
- var ERC20_json_1 = __importDefault(require("./constants/abis/ERC20.json"));
69
- var cERC20_json_1 = __importDefault(require("./constants/abis/cERC20.json"));
70
- var yERC20_json_1 = __importDefault(require("./constants/abis/yERC20.json"));
71
- var minter_json_1 = __importDefault(require("./constants/abis/minter.json"));
72
- var minter_child_json_1 = __importDefault(require("./constants/abis/minter_child.json"));
73
- var votingescrow_json_1 = __importDefault(require("./constants/abis/votingescrow.json"));
74
- var fee_distributor_json_1 = __importDefault(require("./constants/abis/fee_distributor.json"));
75
- var address_provider_json_1 = __importDefault(require("./constants/abis/address_provider.json"));
76
- var gaugecontroller_json_1 = __importDefault(require("./constants/abis/gaugecontroller.json"));
77
- var router_json_1 = __importDefault(require("./constants/abis/router.json"));
78
- var deposit_and_stake_json_1 = __importDefault(require("./constants/abis/deposit_and_stake.json"));
79
- var deposit_and_stake_6coins_json_1 = __importDefault(require("./constants/abis/deposit_and_stake_6coins.json"));
80
- var registry_exchange_json_1 = __importDefault(require("./constants/abis/registry_exchange.json"));
81
- var streamer_json_1 = __importDefault(require("./constants/abis/streamer.json"));
82
- var factory_json_1 = __importDefault(require("./constants/abis/factory.json"));
83
- var factory_crypto_json_1 = __importDefault(require("./constants/abis/factory-crypto.json"));
84
- var pools_1 = require("./constants/pools");
85
- var aliases_1 = require("./constants/aliases");
86
- var ethereum_1 = require("./constants/coins/ethereum");
87
- var optimism_1 = require("./constants/coins/optimism");
88
- var polygon_1 = require("./constants/coins/polygon");
89
- var fantom_1 = require("./constants/coins/fantom");
90
- var avalanche_1 = require("./constants/coins/avalanche");
91
- var arbitrum_1 = require("./constants/coins/arbitrum");
92
- var xdai_1 = require("./constants/coins/xdai");
93
- var moonbeam_1 = require("./constants/coins/moonbeam");
94
- var aurora_1 = require("./constants/coins/aurora");
95
- var kava_1 = require("./constants/coins/kava");
96
- var celo_1 = require("./constants/coins/celo");
97
- var utils_1 = require("./constants/utils");
98
- var external_api_1 = require("./external-api");
99
- var _killGauges = function (poolsData) { return __awaiter(void 0, void 0, void 0, function () {
100
- var gaugeData, isKilled, poolId;
101
- return __generator(this, function (_a) {
102
- switch (_a.label) {
103
- case 0: return [4 /*yield*/, (0, external_api_1._getAllGauges)()];
104
- case 1:
105
- gaugeData = _a.sent();
106
- isKilled = {};
107
- Object.values(gaugeData).forEach(function (d) {
108
- var _a;
109
- isKilled[d.gauge.toLowerCase()] = (_a = d.is_killed) !== null && _a !== void 0 ? _a : false;
110
- });
111
- for (poolId in poolsData) {
112
- if (isKilled[poolsData[poolId].gauge_address]) {
113
- poolsData[poolId].gauge_address = ethers_1.ethers.constants.AddressZero;
114
- }
115
- }
116
- return [2 /*return*/];
117
- }
118
- });
119
- }); };
120
- exports.NATIVE_TOKENS = {
49
+ export const NATIVE_TOKENS = {
121
50
  1: {
122
51
  symbol: 'ETH',
123
52
  wrappedSymbol: 'WETH',
@@ -185,270 +114,185 @@ exports.NATIVE_TOKENS = {
185
114
  wrappedAddress: '0xC9BdeEd33CD01541e1eeD10f90519d2C06Fe3feB'.toLowerCase(),
186
115
  },
187
116
  };
188
- exports.NETWORK_CONSTANTS = {
117
+ export const NETWORK_CONSTANTS = {
189
118
  1: {
190
119
  NAME: 'ethereum',
191
- ALIASES: aliases_1.ALIASES_ETHEREUM,
192
- POOLS_DATA: pools_1.POOLS_DATA_ETHEREUM,
193
- COINS: ethereum_1.COINS_ETHEREUM,
194
- cTokens: ethereum_1.cTokensEthereum,
195
- yTokens: ethereum_1.yTokensEthereum,
196
- ycTokens: ethereum_1.ycTokensEthereum,
197
- aTokens: ethereum_1.aTokensEthereum,
120
+ ALIASES: ALIASES_ETHEREUM,
121
+ POOLS_DATA: POOLS_DATA_ETHEREUM,
122
+ COINS: COINS_ETHEREUM,
123
+ cTokens: cTokensEthereum,
124
+ yTokens: yTokensEthereum,
125
+ ycTokens: ycTokensEthereum,
126
+ aTokens: aTokensEthereum,
198
127
  },
199
128
  10: {
200
129
  NAME: 'optimism',
201
- ALIASES: aliases_1.ALIASES_OPTIMISM,
202
- POOLS_DATA: pools_1.POOLS_DATA_OPTIMISM,
203
- COINS: optimism_1.COINS_OPTIMISM,
204
- cTokens: optimism_1.cTokensOptimism,
205
- yTokens: optimism_1.yTokensOptimism,
206
- ycTokens: optimism_1.ycTokensOptimism,
207
- aTokens: optimism_1.aTokensOptimism,
130
+ ALIASES: ALIASES_OPTIMISM,
131
+ POOLS_DATA: POOLS_DATA_OPTIMISM,
132
+ COINS: COINS_OPTIMISM,
133
+ cTokens: cTokensOptimism,
134
+ yTokens: yTokensOptimism,
135
+ ycTokens: ycTokensOptimism,
136
+ aTokens: aTokensOptimism,
208
137
  },
209
138
  100: {
210
139
  NAME: 'xdai',
211
- ALIASES: aliases_1.ALIASES_XDAI,
212
- POOLS_DATA: pools_1.POOLS_DATA_XDAI,
213
- COINS: xdai_1.COINS_XDAI,
214
- cTokens: xdai_1.cTokensXDai,
215
- yTokens: xdai_1.yTokensXDai,
216
- ycTokens: xdai_1.ycTokensXDai,
217
- aTokens: xdai_1.aTokensXDai,
140
+ ALIASES: ALIASES_XDAI,
141
+ POOLS_DATA: POOLS_DATA_XDAI,
142
+ COINS: COINS_XDAI,
143
+ cTokens: cTokensXDai,
144
+ yTokens: yTokensXDai,
145
+ ycTokens: ycTokensXDai,
146
+ aTokens: aTokensXDai,
218
147
  },
219
148
  137: {
220
149
  NAME: 'polygon',
221
- ALIASES: aliases_1.ALIASES_POLYGON,
222
- POOLS_DATA: pools_1.POOLS_DATA_POLYGON,
223
- COINS: polygon_1.COINS_POLYGON,
224
- cTokens: polygon_1.cTokensPolygon,
225
- yTokens: polygon_1.yTokensPolygon,
226
- ycTokens: polygon_1.ycTokensPolygon,
227
- aTokens: polygon_1.aTokensPolygon,
150
+ ALIASES: ALIASES_POLYGON,
151
+ POOLS_DATA: POOLS_DATA_POLYGON,
152
+ COINS: COINS_POLYGON,
153
+ cTokens: cTokensPolygon,
154
+ yTokens: yTokensPolygon,
155
+ ycTokens: ycTokensPolygon,
156
+ aTokens: aTokensPolygon,
228
157
  },
229
158
  250: {
230
159
  NAME: 'fantom',
231
- ALIASES: aliases_1.ALIASES_FANTOM,
232
- POOLS_DATA: pools_1.POOLS_DATA_FANTOM,
233
- COINS: fantom_1.COINS_FANTOM,
234
- cTokens: fantom_1.cTokensFantom,
235
- yTokens: fantom_1.yTokensFantom,
236
- ycTokens: fantom_1.ycTokensFantom,
237
- aTokens: fantom_1.aTokensFantom,
160
+ ALIASES: ALIASES_FANTOM,
161
+ POOLS_DATA: POOLS_DATA_FANTOM,
162
+ COINS: COINS_FANTOM,
163
+ cTokens: cTokensFantom,
164
+ yTokens: yTokensFantom,
165
+ ycTokens: ycTokensFantom,
166
+ aTokens: aTokensFantom,
238
167
  },
239
168
  1284: {
240
169
  NAME: 'moonbeam',
241
- ALIASES: aliases_1.ALIASES_MOONBEAM,
242
- POOLS_DATA: pools_1.POOLS_DATA_MOONBEAM,
243
- COINS: moonbeam_1.COINS_MOONBEAM,
244
- cTokens: moonbeam_1.cTokensMoonbeam,
245
- yTokens: moonbeam_1.yTokensMoonbeam,
246
- ycTokens: moonbeam_1.ycTokensMoonbeam,
247
- aTokens: moonbeam_1.aTokensMoonbeam,
170
+ ALIASES: ALIASES_MOONBEAM,
171
+ POOLS_DATA: POOLS_DATA_MOONBEAM,
172
+ COINS: COINS_MOONBEAM,
173
+ cTokens: cTokensMoonbeam,
174
+ yTokens: yTokensMoonbeam,
175
+ ycTokens: ycTokensMoonbeam,
176
+ aTokens: aTokensMoonbeam,
248
177
  },
249
178
  2222: {
250
179
  NAME: 'kava',
251
- ALIASES: aliases_1.ALIASES_KAVA,
252
- POOLS_DATA: pools_1.POOLS_DATA_KAVA,
253
- COINS: kava_1.COINS_KAVA,
254
- cTokens: kava_1.cTokensKava,
255
- yTokens: kava_1.yTokensKava,
256
- ycTokens: kava_1.ycTokensKava,
257
- aTokens: kava_1.aTokensKava,
180
+ ALIASES: ALIASES_KAVA,
181
+ POOLS_DATA: POOLS_DATA_KAVA,
182
+ COINS: COINS_KAVA,
183
+ cTokens: cTokensKava,
184
+ yTokens: yTokensKava,
185
+ ycTokens: ycTokensKava,
186
+ aTokens: aTokensKava,
258
187
  },
259
188
  42161: {
260
189
  NAME: 'arbitrum',
261
- ALIASES: aliases_1.ALIASES_ARBITRUM,
262
- POOLS_DATA: pools_1.POOLS_DATA_ARBITRUM,
263
- COINS: arbitrum_1.COINS_ARBITRUM,
264
- cTokens: arbitrum_1.cTokensArbitrum,
265
- yTokens: arbitrum_1.yTokensArbitrum,
266
- ycTokens: arbitrum_1.ycTokensArbitrum,
267
- aTokens: arbitrum_1.aTokensArbitrum,
190
+ ALIASES: ALIASES_ARBITRUM,
191
+ POOLS_DATA: POOLS_DATA_ARBITRUM,
192
+ COINS: COINS_ARBITRUM,
193
+ cTokens: cTokensArbitrum,
194
+ yTokens: yTokensArbitrum,
195
+ ycTokens: ycTokensArbitrum,
196
+ aTokens: aTokensArbitrum,
268
197
  },
269
198
  42220: {
270
199
  NAME: 'celo',
271
- ALIASES: aliases_1.ALIASES_CELO,
272
- POOLS_DATA: pools_1.POOLS_DATA_CELO,
273
- COINS: celo_1.COINS_CELO,
274
- cTokens: celo_1.cTokensCelo,
275
- yTokens: celo_1.yTokensCelo,
276
- ycTokens: celo_1.ycTokensCelo,
277
- aTokens: celo_1.aTokensCelo,
200
+ ALIASES: ALIASES_CELO,
201
+ POOLS_DATA: POOLS_DATA_CELO,
202
+ COINS: COINS_CELO,
203
+ cTokens: cTokensCelo,
204
+ yTokens: yTokensCelo,
205
+ ycTokens: ycTokensCelo,
206
+ aTokens: aTokensCelo,
278
207
  },
279
208
  43114: {
280
209
  NAME: 'avalanche',
281
- ALIASES: aliases_1.ALIASES_AVALANCHE,
282
- POOLS_DATA: pools_1.POOLS_DATA_AVALANCHE,
283
- COINS: avalanche_1.COINS_AVALANCHE,
284
- cTokens: avalanche_1.cTokensAvalanche,
285
- yTokens: avalanche_1.yTokensAvalanche,
286
- ycTokens: avalanche_1.ycTokensAvalanche,
287
- aTokens: avalanche_1.aTokensAvalanche,
210
+ ALIASES: ALIASES_AVALANCHE,
211
+ POOLS_DATA: POOLS_DATA_AVALANCHE,
212
+ COINS: COINS_AVALANCHE,
213
+ cTokens: cTokensAvalanche,
214
+ yTokens: yTokensAvalanche,
215
+ ycTokens: ycTokensAvalanche,
216
+ aTokens: aTokensAvalanche,
288
217
  },
289
218
  1313161554: {
290
219
  NAME: 'aurora',
291
- ALIASES: aliases_1.ALIASES_AURORA,
292
- POOLS_DATA: pools_1.POOLS_DATA_AURORA,
293
- COINS: aurora_1.COINS_AURORA,
294
- cTokens: aurora_1.cTokensAurora,
295
- yTokens: aurora_1.yTokensAurora,
296
- ycTokens: aurora_1.ycTokensAurora,
297
- aTokens: aurora_1.aTokensAurora,
220
+ ALIASES: ALIASES_AURORA,
221
+ POOLS_DATA: POOLS_DATA_AURORA,
222
+ COINS: COINS_AURORA,
223
+ cTokens: cTokensAurora,
224
+ yTokens: yTokensAurora,
225
+ ycTokens: ycTokensAurora,
226
+ aTokens: aTokensAurora,
298
227
  },
299
228
  };
300
- var Curve = /** @class */ (function () {
301
- function Curve() {
302
- var _this = this;
303
- this.fetchFactoryPools = function (useApi) {
304
- if (useApi === void 0) { useApi = true; }
305
- return __awaiter(_this, void 0, void 0, function () {
306
- var _a, _b, _c, _d, _e;
307
- return __generator(this, function (_f) {
308
- switch (_f.label) {
309
- case 0:
310
- if (this.chainId === 1313161554)
311
- return [2 /*return*/];
312
- if (!useApi) return [3 /*break*/, 2];
313
- _a = this.constants;
314
- _b = utils_1.lowerCasePoolDataAddresses;
315
- return [4 /*yield*/, factory_api_1.getFactoryPoolsDataFromApi.call(this, false)];
316
- case 1:
317
- _a.FACTORY_POOLS_DATA = _b.apply(void 0, [_f.sent()]);
318
- return [3 /*break*/, 4];
319
- case 2:
320
- _c = this.constants;
321
- _d = utils_1.lowerCasePoolDataAddresses;
322
- return [4 /*yield*/, factory_1.getFactoryPoolData.call(this)];
323
- case 3:
324
- _c.FACTORY_POOLS_DATA = _d.apply(void 0, [_f.sent()]);
325
- _f.label = 4;
326
- case 4:
327
- _e = this.constants;
328
- return [4 /*yield*/, this._filterHiddenPools(this.constants.FACTORY_POOLS_DATA)];
329
- case 5:
330
- _e.FACTORY_POOLS_DATA = _f.sent();
331
- this._updateDecimalsAndGauges(this.constants.FACTORY_POOLS_DATA);
332
- return [4 /*yield*/, _killGauges(this.constants.FACTORY_POOLS_DATA)];
333
- case 6:
334
- _f.sent();
335
- return [2 /*return*/];
336
- }
337
- });
338
- });
229
+ class Curve {
230
+ constructor() {
231
+ this.fetchFactoryPools = async (useApi = true) => {
232
+ if (this.chainId === 1313161554)
233
+ return;
234
+ if (useApi) {
235
+ this.constants.FACTORY_POOLS_DATA = lowerCasePoolDataAddresses(await getFactoryPoolsDataFromApi.call(this, false));
236
+ }
237
+ else {
238
+ this.constants.FACTORY_POOLS_DATA = lowerCasePoolDataAddresses(await getFactoryPoolData.call(this));
239
+ }
240
+ this.constants.FACTORY_POOLS_DATA = await this._filterHiddenPools(this.constants.FACTORY_POOLS_DATA);
241
+ this._updateDecimalsAndGauges(this.constants.FACTORY_POOLS_DATA);
242
+ await _killGauges(this.constants.FACTORY_POOLS_DATA);
339
243
  };
340
- this.fetchCryptoFactoryPools = function (useApi) {
341
- if (useApi === void 0) { useApi = true; }
342
- return __awaiter(_this, void 0, void 0, function () {
343
- var _a, _b, _c, _d, _e;
344
- return __generator(this, function (_f) {
345
- switch (_f.label) {
346
- case 0:
347
- if (![1, 137, 250].includes(this.chainId))
348
- return [2 /*return*/];
349
- if (!useApi) return [3 /*break*/, 2];
350
- _a = this.constants;
351
- _b = utils_1.lowerCasePoolDataAddresses;
352
- return [4 /*yield*/, factory_api_1.getFactoryPoolsDataFromApi.call(this, true)];
353
- case 1:
354
- _a.CRYPTO_FACTORY_POOLS_DATA = _b.apply(void 0, [_f.sent()]);
355
- return [3 /*break*/, 4];
356
- case 2:
357
- _c = this.constants;
358
- _d = utils_1.lowerCasePoolDataAddresses;
359
- return [4 /*yield*/, factory_crypto_1.getCryptoFactoryPoolData.call(this)];
360
- case 3:
361
- _c.CRYPTO_FACTORY_POOLS_DATA = _d.apply(void 0, [_f.sent()]);
362
- _f.label = 4;
363
- case 4:
364
- _e = this.constants;
365
- return [4 /*yield*/, this._filterHiddenPools(this.constants.CRYPTO_FACTORY_POOLS_DATA)];
366
- case 5:
367
- _e.CRYPTO_FACTORY_POOLS_DATA = _f.sent();
368
- this._updateDecimalsAndGauges(this.constants.CRYPTO_FACTORY_POOLS_DATA);
369
- return [4 /*yield*/, _killGauges(this.constants.CRYPTO_FACTORY_POOLS_DATA)];
370
- case 6:
371
- _f.sent();
372
- return [2 /*return*/];
373
- }
374
- });
375
- });
244
+ this.fetchCryptoFactoryPools = async (useApi = true) => {
245
+ if (![1, 137, 250].includes(this.chainId))
246
+ return;
247
+ if (useApi) {
248
+ this.constants.CRYPTO_FACTORY_POOLS_DATA = lowerCasePoolDataAddresses(await getFactoryPoolsDataFromApi.call(this, true));
249
+ }
250
+ else {
251
+ this.constants.CRYPTO_FACTORY_POOLS_DATA = lowerCasePoolDataAddresses(await getCryptoFactoryPoolData.call(this));
252
+ }
253
+ this.constants.CRYPTO_FACTORY_POOLS_DATA = await this._filterHiddenPools(this.constants.CRYPTO_FACTORY_POOLS_DATA);
254
+ this._updateDecimalsAndGauges(this.constants.CRYPTO_FACTORY_POOLS_DATA);
255
+ await _killGauges(this.constants.CRYPTO_FACTORY_POOLS_DATA);
376
256
  };
377
- this.fetchNewFactoryPools = function () { return __awaiter(_this, void 0, void 0, function () {
378
- var currentPoolIds, lastPoolIdx, poolData, _a;
379
- return __generator(this, function (_b) {
380
- switch (_b.label) {
381
- case 0:
382
- if (this.chainId === 1313161554)
383
- return [2 /*return*/, []];
384
- currentPoolIds = Object.keys(this.constants.FACTORY_POOLS_DATA);
385
- lastPoolIdx = Number(currentPoolIds[currentPoolIds.length - 1].split("-")[2]);
386
- _a = utils_1.lowerCasePoolDataAddresses;
387
- return [4 /*yield*/, factory_1.getFactoryPoolData.call(this, lastPoolIdx + 1)];
388
- case 1:
389
- poolData = _a.apply(void 0, [_b.sent()]);
390
- this.constants.FACTORY_POOLS_DATA = __assign(__assign({}, this.constants.FACTORY_POOLS_DATA), poolData);
391
- this._updateDecimalsAndGauges(this.constants.FACTORY_POOLS_DATA);
392
- return [2 /*return*/, Object.keys(poolData)];
393
- }
394
- });
395
- }); };
396
- this.fetchNewCryptoFactoryPools = function () { return __awaiter(_this, void 0, void 0, function () {
397
- var currentPoolIds, lastPoolIdx, poolData, _a;
398
- return __generator(this, function (_b) {
399
- switch (_b.label) {
400
- case 0:
401
- if (![1, 137, 250].includes(this.chainId))
402
- return [2 /*return*/, []];
403
- currentPoolIds = Object.keys(this.constants.CRYPTO_FACTORY_POOLS_DATA);
404
- lastPoolIdx = Number(currentPoolIds[currentPoolIds.length - 1].split("-")[2]);
405
- _a = utils_1.lowerCasePoolDataAddresses;
406
- return [4 /*yield*/, factory_crypto_1.getCryptoFactoryPoolData.call(this, lastPoolIdx + 1)];
407
- case 1:
408
- poolData = _a.apply(void 0, [_b.sent()]);
409
- this.constants.CRYPTO_FACTORY_POOLS_DATA = __assign(__assign({}, this.constants.CRYPTO_FACTORY_POOLS_DATA), poolData);
410
- this._updateDecimalsAndGauges(this.constants.CRYPTO_FACTORY_POOLS_DATA);
411
- return [2 /*return*/, Object.keys(poolData)];
412
- }
413
- });
414
- }); };
415
- this.fetchRecentlyDeployedFactoryPool = function (poolAddress) { return __awaiter(_this, void 0, void 0, function () {
416
- var poolData, _a;
417
- return __generator(this, function (_b) {
418
- switch (_b.label) {
419
- case 0:
420
- if (this.chainId === 1313161554)
421
- return [2 /*return*/, ''];
422
- _a = utils_1.lowerCasePoolDataAddresses;
423
- return [4 /*yield*/, factory_1.getFactoryPoolData.call(this, 0, poolAddress)];
424
- case 1:
425
- poolData = _a.apply(void 0, [_b.sent()]);
426
- this.constants.FACTORY_POOLS_DATA = __assign(__assign({}, this.constants.FACTORY_POOLS_DATA), poolData);
427
- this._updateDecimalsAndGauges(this.constants.FACTORY_POOLS_DATA);
428
- return [2 /*return*/, Object.keys(poolData)[0]]; // id
429
- }
430
- });
431
- }); };
432
- this.fetchRecentlyDeployedCryptoFactoryPool = function (poolAddress) { return __awaiter(_this, void 0, void 0, function () {
433
- var poolData, _a;
434
- return __generator(this, function (_b) {
435
- switch (_b.label) {
436
- case 0:
437
- if (![1, 137, 250].includes(this.chainId))
438
- return [2 /*return*/, ''];
439
- _a = utils_1.lowerCasePoolDataAddresses;
440
- return [4 /*yield*/, factory_crypto_1.getCryptoFactoryPoolData.call(this, 0, poolAddress)];
441
- case 1:
442
- poolData = _a.apply(void 0, [_b.sent()]);
443
- this.constants.CRYPTO_FACTORY_POOLS_DATA = __assign(__assign({}, this.constants.CRYPTO_FACTORY_POOLS_DATA), poolData);
444
- this._updateDecimalsAndGauges(this.constants.CRYPTO_FACTORY_POOLS_DATA);
445
- return [2 /*return*/, Object.keys(poolData)[0]]; // id
446
- }
447
- });
448
- }); };
449
- this.getPoolList = function () { return Object.keys(_this.constants.POOLS_DATA); };
450
- this.getFactoryPoolList = function () { return Object.keys(_this.constants.FACTORY_POOLS_DATA); };
451
- this.getCryptoFactoryPoolList = function () { return Object.keys(_this.constants.CRYPTO_FACTORY_POOLS_DATA); };
257
+ this.fetchNewFactoryPools = async () => {
258
+ if (this.chainId === 1313161554)
259
+ return [];
260
+ const currentPoolIds = Object.keys(this.constants.FACTORY_POOLS_DATA);
261
+ const lastPoolIdx = Number(currentPoolIds[currentPoolIds.length - 1].split("-")[2]);
262
+ const poolData = lowerCasePoolDataAddresses(await getFactoryPoolData.call(this, lastPoolIdx + 1));
263
+ this.constants.FACTORY_POOLS_DATA = { ...this.constants.FACTORY_POOLS_DATA, ...poolData };
264
+ this._updateDecimalsAndGauges(this.constants.FACTORY_POOLS_DATA);
265
+ return Object.keys(poolData);
266
+ };
267
+ this.fetchNewCryptoFactoryPools = async () => {
268
+ if (![1, 137, 250].includes(this.chainId))
269
+ return [];
270
+ const currentPoolIds = Object.keys(this.constants.CRYPTO_FACTORY_POOLS_DATA);
271
+ const lastPoolIdx = Number(currentPoolIds[currentPoolIds.length - 1].split("-")[2]);
272
+ const poolData = lowerCasePoolDataAddresses(await getCryptoFactoryPoolData.call(this, lastPoolIdx + 1));
273
+ this.constants.CRYPTO_FACTORY_POOLS_DATA = { ...this.constants.CRYPTO_FACTORY_POOLS_DATA, ...poolData };
274
+ this._updateDecimalsAndGauges(this.constants.CRYPTO_FACTORY_POOLS_DATA);
275
+ return Object.keys(poolData);
276
+ };
277
+ this.fetchRecentlyDeployedFactoryPool = async (poolAddress) => {
278
+ if (this.chainId === 1313161554)
279
+ return '';
280
+ const poolData = lowerCasePoolDataAddresses(await getFactoryPoolData.call(this, 0, poolAddress));
281
+ this.constants.FACTORY_POOLS_DATA = { ...this.constants.FACTORY_POOLS_DATA, ...poolData };
282
+ this._updateDecimalsAndGauges(this.constants.FACTORY_POOLS_DATA);
283
+ return Object.keys(poolData)[0]; // id
284
+ };
285
+ this.fetchRecentlyDeployedCryptoFactoryPool = async (poolAddress) => {
286
+ if (![1, 137, 250].includes(this.chainId))
287
+ return '';
288
+ const poolData = lowerCasePoolDataAddresses(await getCryptoFactoryPoolData.call(this, 0, poolAddress));
289
+ this.constants.CRYPTO_FACTORY_POOLS_DATA = { ...this.constants.CRYPTO_FACTORY_POOLS_DATA, ...poolData };
290
+ this._updateDecimalsAndGauges(this.constants.CRYPTO_FACTORY_POOLS_DATA);
291
+ return Object.keys(poolData)[0]; // id
292
+ };
293
+ this.getPoolList = () => Object.keys(this.constants.POOLS_DATA);
294
+ this.getFactoryPoolList = () => Object.keys(this.constants.FACTORY_POOLS_DATA);
295
+ this.getCryptoFactoryPoolList = () => Object.keys(this.constants.CRYPTO_FACTORY_POOLS_DATA);
452
296
  // @ts-ignore
453
297
  this.provider = null;
454
298
  // @ts-ignore
@@ -462,7 +306,7 @@ var Curve = /** @class */ (function () {
462
306
  this.constantOptions = { gasLimit: 12000000 };
463
307
  this.options = {};
464
308
  this.constants = {
465
- NATIVE_TOKEN: exports.NATIVE_TOKENS[1],
309
+ NATIVE_TOKEN: NATIVE_TOKENS[1],
466
310
  NETWORK_NAME: 'ethereum',
467
311
  ALIASES: {},
468
312
  POOLS_DATA: {},
@@ -471,279 +315,217 @@ var Curve = /** @class */ (function () {
471
315
  COINS: {},
472
316
  DECIMALS: {},
473
317
  GAUGES: [],
318
+ ZERO_ADDRESS: ethers.ZeroAddress,
474
319
  };
475
320
  }
476
- Curve.prototype.init = function (providerType, providerSettings, options // gasPrice in Gwei
321
+ async init(providerType, providerSettings, options = {} // gasPrice in Gwei
477
322
  ) {
478
- var _a;
479
- if (options === void 0) { options = {}; }
480
- return __awaiter(this, void 0, void 0, function () {
481
- var network, _b, poolId, _c, cTokens, yTokens, ycTokens, aTokens, customAbiTokens, _d, err_1, _i, _e, pool, _f, _g, coinAddr, _h, _j, coinAddr, _k, _l, coinAddr, _minterABI, addressProviderContract, _m;
482
- return __generator(this, function (_o) {
483
- switch (_o.label) {
484
- case 0:
485
- // @ts-ignore
486
- this.provider = null;
487
- // @ts-ignore
488
- this.signer = null;
489
- this.signerAddress = '';
490
- this.chainId = 1;
491
- // @ts-ignore
492
- this.multicallProvider = null;
493
- this.contracts = {};
494
- this.feeData = {};
495
- this.constantOptions = { gasLimit: 12000000 };
496
- this.options = {};
497
- this.constants = {
498
- NATIVE_TOKEN: exports.NATIVE_TOKENS[1],
499
- NETWORK_NAME: 'ethereum',
500
- ALIASES: {},
501
- POOLS_DATA: {},
502
- FACTORY_POOLS_DATA: {},
503
- CRYPTO_FACTORY_POOLS_DATA: {},
504
- COINS: {},
505
- DECIMALS: {},
506
- GAUGES: [],
507
- };
508
- // JsonRpc provider
509
- if (providerType.toLowerCase() === 'JsonRpc'.toLowerCase()) {
510
- providerSettings = providerSettings;
511
- if (providerSettings.url) {
512
- this.provider = this.provider = new ethers_1.ethers.providers.JsonRpcProvider(providerSettings.url);
513
- }
514
- else {
515
- this.provider = new ethers_1.ethers.providers.JsonRpcProvider('http://localhost:8545/');
516
- }
517
- if (providerSettings.privateKey) {
518
- this.signer = new ethers_1.ethers.Wallet(providerSettings.privateKey, this.provider);
519
- }
520
- else if (!((_a = providerSettings.url) === null || _a === void 0 ? void 0 : _a.startsWith("https://rpc.gnosischain.com"))) {
521
- this.signer = this.provider.getSigner();
522
- }
523
- // Web3 provider
524
- }
525
- else if (providerType.toLowerCase() === 'Web3'.toLowerCase()) {
526
- providerSettings = providerSettings;
527
- this.provider = new ethers_1.ethers.providers.Web3Provider(providerSettings.externalProvider);
528
- this.signer = this.provider.getSigner();
529
- // Infura provider
530
- }
531
- else if (providerType.toLowerCase() === 'Infura'.toLowerCase()) {
532
- providerSettings = providerSettings;
533
- this.provider = new ethers_1.ethers.providers.InfuraProvider(providerSettings.network, providerSettings.apiKey);
534
- this.signer = null;
535
- // Alchemy provider
536
- }
537
- else if (providerType.toLowerCase() === 'Alchemy'.toLowerCase()) {
538
- providerSettings = providerSettings;
539
- this.provider = new ethers_1.ethers.providers.AlchemyProvider(providerSettings.network, providerSettings.apiKey);
540
- this.signer = null;
541
- }
542
- else {
543
- throw Error('Wrong providerType');
544
- }
545
- _b = this.provider.network;
546
- if (_b) return [3 /*break*/, 2];
547
- return [4 /*yield*/, this.provider._networkPromise];
548
- case 1:
549
- _b = (_o.sent());
550
- _o.label = 2;
551
- case 2:
552
- network = _b;
553
- console.log("CURVE-JS IS CONNECTED TO NETWORK:", network);
554
- this.chainId = network.chainId === 1337 ? 1 : network.chainId;
555
- this.constants.NATIVE_TOKEN = exports.NATIVE_TOKENS[this.chainId];
556
- this.constants.NETWORK_NAME = exports.NETWORK_CONSTANTS[this.chainId].NAME;
557
- this.constants.ALIASES = exports.NETWORK_CONSTANTS[this.chainId].ALIASES;
558
- this.constants.POOLS_DATA = exports.NETWORK_CONSTANTS[this.chainId].POOLS_DATA;
559
- for (poolId in this.constants.POOLS_DATA)
560
- this.constants.POOLS_DATA[poolId].in_api = true;
561
- this.constants.COINS = exports.NETWORK_CONSTANTS[this.chainId].COINS;
562
- this.constants.DECIMALS = (0, utils_1.extractDecimals)(this.constants.POOLS_DATA);
563
- this.constants.DECIMALS[this.constants.NATIVE_TOKEN.address] = 18;
564
- this.constants.DECIMALS[this.constants.NATIVE_TOKEN.wrappedAddress] = 18;
565
- this.constants.GAUGES = (0, utils_1.extractGauges)(this.constants.POOLS_DATA);
566
- _c = [
567
- exports.NETWORK_CONSTANTS[this.chainId].cTokens,
568
- exports.NETWORK_CONSTANTS[this.chainId].yTokens,
569
- exports.NETWORK_CONSTANTS[this.chainId].ycTokens,
570
- exports.NETWORK_CONSTANTS[this.chainId].aTokens,
571
- ], cTokens = _c[0], yTokens = _c[1], ycTokens = _c[2], aTokens = _c[3];
572
- customAbiTokens = __spreadArray(__spreadArray(__spreadArray(__spreadArray([], cTokens, true), yTokens, true), ycTokens, true), aTokens, true);
573
- return [4 /*yield*/, _killGauges(this.constants.POOLS_DATA)];
574
- case 3:
575
- _o.sent();
576
- this.multicallProvider = new ethcall_1.Provider();
577
- return [4 /*yield*/, this.multicallProvider.init(this.provider)];
578
- case 4:
579
- _o.sent();
580
- if (!this.signer) return [3 /*break*/, 9];
581
- _o.label = 5;
582
- case 5:
583
- _o.trys.push([5, 7, , 8]);
584
- _d = this;
585
- return [4 /*yield*/, this.signer.getAddress()];
586
- case 6:
587
- _d.signerAddress = _o.sent();
588
- return [3 /*break*/, 8];
589
- case 7:
590
- err_1 = _o.sent();
591
- this.signer = null;
592
- return [3 /*break*/, 8];
593
- case 8: return [3 /*break*/, 10];
594
- case 9:
595
- this.signerAddress = '';
596
- _o.label = 10;
597
- case 10:
598
- this.feeData = { gasPrice: options.gasPrice, maxFeePerGas: options.maxFeePerGas, maxPriorityFeePerGas: options.maxPriorityFeePerGas };
599
- return [4 /*yield*/, this.updateFeeData()];
600
- case 11:
601
- _o.sent();
602
- for (_i = 0, _e = Object.values(this.constants.POOLS_DATA); _i < _e.length; _i++) {
603
- pool = _e[_i];
604
- this.setContract(pool.swap_address, pool.swap_abi);
605
- if (pool.token_address !== pool.swap_address) {
606
- this.setContract(pool.token_address, ERC20_json_1.default);
607
- }
608
- if (pool.gauge_address !== ethers_1.ethers.constants.AddressZero) {
609
- this.setContract(pool.gauge_address, pool.gauge_abi);
610
- }
611
- if (pool.deposit_address && !this.contracts[pool.deposit_address]) {
612
- this.setContract(pool.deposit_address, pool.deposit_abi);
613
- }
614
- for (_f = 0, _g = pool.underlying_coin_addresses; _f < _g.length; _f++) {
615
- coinAddr = _g[_f];
616
- this.setContract(coinAddr, ERC20_json_1.default);
617
- }
618
- for (_h = 0, _j = pool.wrapped_coin_addresses; _h < _j.length; _h++) {
619
- coinAddr = _j[_h];
620
- if (customAbiTokens.includes(coinAddr))
621
- continue;
622
- if (coinAddr in this.contracts)
623
- continue;
624
- this.setContract(coinAddr, ERC20_json_1.default);
625
- }
626
- // TODO add all coins
627
- for (_k = 0, _l = pool.wrapped_coin_addresses; _k < _l.length; _k++) {
628
- coinAddr = _l[_k];
629
- if (cTokens.includes(coinAddr)) {
630
- this.setContract(coinAddr, cERC20_json_1.default);
631
- }
632
- if (aTokens.includes(coinAddr)) {
633
- this.setContract(coinAddr, ERC20_json_1.default);
634
- }
635
- if (yTokens.includes(coinAddr) || ycTokens.includes(coinAddr)) {
636
- this.setContract(coinAddr, yERC20_json_1.default);
637
- }
638
- }
639
- if (pool.reward_contract) {
640
- this.setContract(pool.reward_contract, streamer_json_1.default);
641
- }
642
- if (pool.sCurveRewards_address) {
643
- this.setContract(pool.sCurveRewards_address, pool.sCurveRewards_abi);
644
- }
645
- }
646
- this.setContract(this.constants.NATIVE_TOKEN.wrappedAddress, ERC20_json_1.default);
647
- this.setContract(this.constants.ALIASES.crv, ERC20_json_1.default);
648
- this.constants.DECIMALS[this.constants.ALIASES.crv] = 18;
649
- _minterABI = this.chainId === 1 ? minter_json_1.default : minter_child_json_1.default;
650
- this.setContract(this.constants.ALIASES.minter, _minterABI);
651
- this.setContract(this.constants.ALIASES.voting_escrow, votingescrow_json_1.default);
652
- this.setContract(this.constants.ALIASES.fee_distributor, fee_distributor_json_1.default);
653
- this.setContract(this.constants.ALIASES.address_provider, address_provider_json_1.default);
654
- addressProviderContract = this.contracts[this.constants.ALIASES.address_provider].contract;
655
- _m = this.constants.ALIASES;
656
- return [4 /*yield*/, addressProviderContract.get_address(2, this.constantOptions)];
657
- case 12:
658
- _m.registry_exchange = (_o.sent()).toLowerCase();
659
- this.setContract(this.constants.ALIASES.registry_exchange, registry_exchange_json_1.default);
660
- this.setContract(this.constants.ALIASES.gauge_controller, gaugecontroller_json_1.default);
661
- this.setContract(this.constants.ALIASES.router, router_json_1.default);
662
- if (this.chainId === 137) {
663
- this.setContract(this.constants.ALIASES.deposit_and_stake, deposit_and_stake_6coins_json_1.default);
664
- }
665
- else {
666
- this.setContract(this.constants.ALIASES.deposit_and_stake, deposit_and_stake_json_1.default);
667
- }
668
- this.setContract(this.constants.ALIASES.factory, factory_json_1.default);
669
- this.setContract(this.constants.ALIASES.crypto_factory, factory_crypto_json_1.default);
670
- return [2 /*return*/];
671
- }
672
- });
673
- });
674
- };
675
- Curve.prototype.setContract = function (address, abi) {
676
- this.contracts[address] = {
677
- contract: new ethers_1.Contract(address, abi, this.signer || this.provider),
678
- multicallContract: new ethcall_1.Contract(address, abi),
323
+ // @ts-ignore
324
+ this.provider = null;
325
+ // @ts-ignore
326
+ this.signer = null;
327
+ this.signerAddress = '';
328
+ this.chainId = 1;
329
+ // @ts-ignore
330
+ this.multicallProvider = null;
331
+ this.contracts = {};
332
+ this.feeData = {};
333
+ this.constantOptions = { gasLimit: 12000000 };
334
+ this.options = {};
335
+ this.constants = {
336
+ NATIVE_TOKEN: NATIVE_TOKENS[1],
337
+ NETWORK_NAME: 'ethereum',
338
+ ALIASES: {},
339
+ POOLS_DATA: {},
340
+ FACTORY_POOLS_DATA: {},
341
+ CRYPTO_FACTORY_POOLS_DATA: {},
342
+ COINS: {},
343
+ DECIMALS: {},
344
+ GAUGES: [],
345
+ ZERO_ADDRESS: ethers.ZeroAddress,
679
346
  };
680
- };
681
- Curve.prototype._filterHiddenPools = function (pools) {
682
- return __awaiter(this, void 0, void 0, function () {
683
- var hiddenPools;
684
- return __generator(this, function (_a) {
685
- switch (_a.label) {
686
- case 0: return [4 /*yield*/, (0, external_api_1._getHiddenPools)()];
687
- case 1:
688
- hiddenPools = (_a.sent())[this.constants.NETWORK_NAME] || [];
689
- // @ts-ignore
690
- return [2 /*return*/, Object.fromEntries(Object.entries(pools).filter(function (_a) {
691
- var id = _a[0];
692
- return !hiddenPools.includes(id);
693
- }))];
347
+ // JsonRpc provider
348
+ if (providerType.toLowerCase() === 'JsonRpc'.toLowerCase()) {
349
+ providerSettings = providerSettings;
350
+ if (providerSettings.url) {
351
+ this.provider = new ethers.JsonRpcProvider(providerSettings.url);
352
+ }
353
+ else {
354
+ this.provider = new ethers.JsonRpcProvider('http://localhost:8545/');
355
+ }
356
+ if (providerSettings.privateKey) {
357
+ this.signer = new ethers.Wallet(providerSettings.privateKey, this.provider);
358
+ }
359
+ else if (!providerSettings.url?.startsWith("https://rpc.gnosischain.com")) {
360
+ try {
361
+ this.signer = await this.provider.getSigner();
362
+ }
363
+ catch (e) {
364
+ this.signer = null;
365
+ }
366
+ }
367
+ // Web3 provider
368
+ }
369
+ else if (providerType.toLowerCase() === 'Web3'.toLowerCase()) {
370
+ providerSettings = providerSettings;
371
+ this.provider = new ethers.BrowserProvider(providerSettings.externalProvider);
372
+ this.signer = await this.provider.getSigner();
373
+ // Infura provider
374
+ }
375
+ else if (providerType.toLowerCase() === 'Infura'.toLowerCase()) {
376
+ providerSettings = providerSettings;
377
+ this.provider = new ethers.InfuraProvider(providerSettings.network, providerSettings.apiKey);
378
+ this.signer = null;
379
+ // Alchemy provider
380
+ }
381
+ else if (providerType.toLowerCase() === 'Alchemy'.toLowerCase()) {
382
+ providerSettings = providerSettings;
383
+ this.provider = new ethers.AlchemyProvider(providerSettings.network, providerSettings.apiKey);
384
+ this.signer = null;
385
+ }
386
+ else {
387
+ throw Error('Wrong providerType');
388
+ }
389
+ const network = await this.provider.getNetwork();
390
+ console.log("CURVE-JS IS CONNECTED TO NETWORK:", { name: network.name.toUpperCase(), chainId: Number(network.chainId) });
391
+ this.chainId = Number(network.chainId) === 1337 ? 1 : Number(network.chainId);
392
+ this.constants.NATIVE_TOKEN = NATIVE_TOKENS[this.chainId];
393
+ this.constants.NETWORK_NAME = NETWORK_CONSTANTS[this.chainId].NAME;
394
+ this.constants.ALIASES = NETWORK_CONSTANTS[this.chainId].ALIASES;
395
+ this.constants.POOLS_DATA = NETWORK_CONSTANTS[this.chainId].POOLS_DATA;
396
+ for (const poolId in this.constants.POOLS_DATA)
397
+ this.constants.POOLS_DATA[poolId].in_api = true;
398
+ this.constants.COINS = NETWORK_CONSTANTS[this.chainId].COINS;
399
+ this.constants.DECIMALS = extractDecimals(this.constants.POOLS_DATA);
400
+ this.constants.DECIMALS[this.constants.NATIVE_TOKEN.address] = 18;
401
+ this.constants.DECIMALS[this.constants.NATIVE_TOKEN.wrappedAddress] = 18;
402
+ this.constants.GAUGES = extractGauges(this.constants.POOLS_DATA);
403
+ const [cTokens, yTokens, ycTokens, aTokens] = [
404
+ NETWORK_CONSTANTS[this.chainId].cTokens,
405
+ NETWORK_CONSTANTS[this.chainId].yTokens,
406
+ NETWORK_CONSTANTS[this.chainId].ycTokens,
407
+ NETWORK_CONSTANTS[this.chainId].aTokens,
408
+ ];
409
+ const customAbiTokens = [...cTokens, ...yTokens, ...ycTokens, ...aTokens];
410
+ await _killGauges(this.constants.POOLS_DATA);
411
+ this.multicallProvider = new MulticallProvider(this.chainId, this.provider);
412
+ if (this.signer) {
413
+ try {
414
+ this.signerAddress = await this.signer.getAddress();
415
+ }
416
+ catch (err) {
417
+ this.signer = null;
418
+ }
419
+ }
420
+ else {
421
+ this.signerAddress = '';
422
+ }
423
+ this.feeData = { gasPrice: options.gasPrice, maxFeePerGas: options.maxFeePerGas, maxPriorityFeePerGas: options.maxPriorityFeePerGas };
424
+ await this.updateFeeData();
425
+ for (const pool of Object.values(this.constants.POOLS_DATA)) {
426
+ this.setContract(pool.swap_address, pool.swap_abi);
427
+ if (pool.token_address !== pool.swap_address) {
428
+ this.setContract(pool.token_address, ERC20Abi);
429
+ }
430
+ if (pool.gauge_address !== this.constants.ZERO_ADDRESS) {
431
+ this.setContract(pool.gauge_address, pool.gauge_abi);
432
+ }
433
+ if (pool.deposit_address && !this.contracts[pool.deposit_address]) {
434
+ this.setContract(pool.deposit_address, pool.deposit_abi);
435
+ }
436
+ for (const coinAddr of pool.underlying_coin_addresses) {
437
+ this.setContract(coinAddr, ERC20Abi);
438
+ }
439
+ for (const coinAddr of pool.wrapped_coin_addresses) {
440
+ if (customAbiTokens.includes(coinAddr))
441
+ continue;
442
+ if (coinAddr in this.contracts)
443
+ continue;
444
+ this.setContract(coinAddr, ERC20Abi);
445
+ }
446
+ // TODO add all coins
447
+ for (const coinAddr of pool.wrapped_coin_addresses) {
448
+ if (cTokens.includes(coinAddr)) {
449
+ this.setContract(coinAddr, cERC20Abi);
450
+ }
451
+ if (aTokens.includes(coinAddr)) {
452
+ this.setContract(coinAddr, ERC20Abi);
694
453
  }
695
- });
696
- });
697
- };
698
- Curve.prototype._updateDecimalsAndGauges = function (pools) {
699
- this.constants.DECIMALS = __assign(__assign({}, this.constants.DECIMALS), (0, utils_1.extractDecimals)(pools));
700
- this.constants.GAUGES = __spreadArray(__spreadArray([], this.constants.GAUGES, true), (0, utils_1.extractGauges)(pools), true);
701
- };
702
- Curve.prototype.setCustomFeeData = function (customFeeData) {
703
- this.feeData = __assign(__assign({}, this.feeData), customFeeData);
704
- };
705
- Curve.prototype.updateFeeData = function () {
706
- return __awaiter(this, void 0, void 0, function () {
707
- var feeData, _a, _b, _c;
708
- return __generator(this, function (_d) {
709
- switch (_d.label) {
710
- case 0: return [4 /*yield*/, this.provider.getFeeData()];
711
- case 1:
712
- feeData = _d.sent();
713
- if (!(feeData.maxFeePerGas === null || feeData.maxPriorityFeePerGas === null)) return [3 /*break*/, 6];
714
- delete this.options.maxFeePerGas;
715
- delete this.options.maxPriorityFeePerGas;
716
- _a = this.options;
717
- if (!(this.feeData.gasPrice !== undefined)) return [3 /*break*/, 2];
718
- _b = ethers_1.ethers.utils.parseUnits(this.feeData.gasPrice.toString(), "gwei");
719
- return [3 /*break*/, 5];
720
- case 2:
721
- _c = feeData.gasPrice;
722
- if (_c) return [3 /*break*/, 4];
723
- return [4 /*yield*/, this.provider.getGasPrice()];
724
- case 3:
725
- _c = (_d.sent());
726
- _d.label = 4;
727
- case 4:
728
- _b = (_c);
729
- _d.label = 5;
730
- case 5:
731
- _a.gasPrice = _b;
732
- return [3 /*break*/, 7];
733
- case 6:
734
- delete this.options.gasPrice;
735
- this.options.maxFeePerGas = this.feeData.maxFeePerGas !== undefined ?
736
- ethers_1.ethers.utils.parseUnits(this.feeData.maxFeePerGas.toString(), "gwei") :
737
- feeData.maxFeePerGas;
738
- this.options.maxPriorityFeePerGas = this.feeData.maxPriorityFeePerGas !== undefined ?
739
- ethers_1.ethers.utils.parseUnits(this.feeData.maxPriorityFeePerGas.toString(), "gwei") :
740
- feeData.maxPriorityFeePerGas;
741
- _d.label = 7;
742
- case 7: return [2 /*return*/];
454
+ if (yTokens.includes(coinAddr) || ycTokens.includes(coinAddr)) {
455
+ this.setContract(coinAddr, yERC20Abi);
743
456
  }
744
- });
745
- });
746
- };
747
- return Curve;
748
- }());
749
- exports.curve = new Curve();
457
+ }
458
+ if (pool.reward_contract) {
459
+ this.setContract(pool.reward_contract, streamerABI);
460
+ }
461
+ if (pool.sCurveRewards_address) {
462
+ this.setContract(pool.sCurveRewards_address, pool.sCurveRewards_abi);
463
+ }
464
+ }
465
+ this.setContract(this.constants.NATIVE_TOKEN.wrappedAddress, ERC20Abi);
466
+ this.setContract(this.constants.ALIASES.crv, ERC20Abi);
467
+ this.constants.DECIMALS[this.constants.ALIASES.crv] = 18;
468
+ const _minterABI = this.chainId === 1 ? minterABI : minterChildABI;
469
+ this.setContract(this.constants.ALIASES.minter, _minterABI);
470
+ this.setContract(this.constants.ALIASES.voting_escrow, votingEscrowABI);
471
+ this.setContract(this.constants.ALIASES.fee_distributor, feeDistributorABI);
472
+ this.setContract(this.constants.ALIASES.address_provider, addressProviderABI);
473
+ const addressProviderContract = this.contracts[this.constants.ALIASES.address_provider].contract;
474
+ this.constants.ALIASES.registry_exchange = (await addressProviderContract.get_address(2, this.constantOptions)).toLowerCase();
475
+ this.setContract(this.constants.ALIASES.registry_exchange, registryExchangeABI);
476
+ this.setContract(this.constants.ALIASES.gauge_controller, gaugeControllerABI);
477
+ this.setContract(this.constants.ALIASES.router, routerABI);
478
+ if (this.chainId === 137) {
479
+ this.setContract(this.constants.ALIASES.deposit_and_stake, depositAndStake6CoinsABI);
480
+ }
481
+ else {
482
+ this.setContract(this.constants.ALIASES.deposit_and_stake, depositAndStakeABI);
483
+ }
484
+ this.setContract(this.constants.ALIASES.factory, factoryABI);
485
+ this.setContract(this.constants.ALIASES.crypto_factory, cryptoFactoryABI);
486
+ }
487
+ setContract(address, abi) {
488
+ this.contracts[address] = {
489
+ contract: new Contract(address, abi, this.signer || this.provider),
490
+ multicallContract: new MulticallContract(address, abi),
491
+ };
492
+ }
493
+ async _filterHiddenPools(pools) {
494
+ const hiddenPools = (await _getHiddenPools())[this.constants.NETWORK_NAME] || [];
495
+ // @ts-ignore
496
+ return Object.fromEntries(Object.entries(pools).filter(([id]) => !hiddenPools.includes(id)));
497
+ }
498
+ _updateDecimalsAndGauges(pools) {
499
+ this.constants.DECIMALS = { ...this.constants.DECIMALS, ...extractDecimals(pools) };
500
+ this.constants.GAUGES = [...this.constants.GAUGES, ...extractGauges(pools)];
501
+ }
502
+ setCustomFeeData(customFeeData) {
503
+ this.feeData = { ...this.feeData, ...customFeeData };
504
+ }
505
+ formatUnits(value, unit) {
506
+ return ethers.formatUnits(value, unit);
507
+ }
508
+ parseUnits(value, unit) {
509
+ return ethers.parseUnits(value, unit);
510
+ }
511
+ async updateFeeData() {
512
+ const feeData = await this.provider.getFeeData();
513
+ if (feeData.maxFeePerGas === null || feeData.maxPriorityFeePerGas === null) {
514
+ delete this.options.maxFeePerGas;
515
+ delete this.options.maxPriorityFeePerGas;
516
+ this.options.gasPrice = this.feeData.gasPrice !== undefined ?
517
+ this.parseUnits(this.feeData.gasPrice.toString(), "gwei") :
518
+ (feeData.gasPrice || this.parseUnits("20", "gwei"));
519
+ }
520
+ else {
521
+ delete this.options.gasPrice;
522
+ this.options.maxFeePerGas = this.feeData.maxFeePerGas !== undefined ?
523
+ this.parseUnits(this.feeData.maxFeePerGas.toString(), "gwei") :
524
+ feeData.maxFeePerGas;
525
+ this.options.maxPriorityFeePerGas = this.feeData.maxPriorityFeePerGas !== undefined ?
526
+ this.parseUnits(this.feeData.maxPriorityFeePerGas.toString(), "gwei") :
527
+ feeData.maxPriorityFeePerGas;
528
+ }
529
+ }
530
+ }
531
+ export const curve = new Curve();