@curvefi/api 2.38.0 → 2.40.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.
- package/README.md +75 -0
- package/lib/constants/abis/factory-tricrypto/factory-tricrypto-pool.json +1502 -0
- package/lib/constants/abis/factory-tricrypto.json +664 -0
- package/lib/constants/aliases.js +11 -0
- package/lib/curve.d.ts +6 -0
- package/lib/curve.js +82 -2
- package/lib/external-api.d.ts +1 -1
- package/lib/factory/deploy.d.ts +7 -4
- package/lib/factory/deploy.js +133 -10
- package/lib/factory/factory-api.d.ts +1 -1
- package/lib/factory/factory-api.js +22 -37
- package/lib/factory/factory-crypto.js +1 -1
- package/lib/factory/factory-tricrypto.d.ts +2 -0
- package/lib/factory/factory-tricrypto.js +303 -0
- package/lib/index.d.ts +16 -3
- package/lib/index.js +23 -6
- package/lib/interfaces.d.ts +3 -0
- package/lib/pools/PoolTemplate.js +19 -6
- package/lib/router.js +1 -1
- package/lib/utils.js +2 -2
- package/package.json +1 -1
|
@@ -0,0 +1,303 @@
|
|
|
1
|
+
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
2
|
+
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
3
|
+
return new (P || (P = Promise))(function (resolve, reject) {
|
|
4
|
+
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
5
|
+
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
6
|
+
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
7
|
+
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
8
|
+
});
|
|
9
|
+
};
|
|
10
|
+
var __generator = (this && this.__generator) || function (thisArg, body) {
|
|
11
|
+
var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g;
|
|
12
|
+
return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
|
|
13
|
+
function verb(n) { return function (v) { return step([n, v]); }; }
|
|
14
|
+
function step(op) {
|
|
15
|
+
if (f) throw new TypeError("Generator is already executing.");
|
|
16
|
+
while (g && (g = 0, op[0] && (_ = 0)), _) try {
|
|
17
|
+
if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t;
|
|
18
|
+
if (y = 0, t) op = [op[0] & 2, t.value];
|
|
19
|
+
switch (op[0]) {
|
|
20
|
+
case 0: case 1: t = op; break;
|
|
21
|
+
case 4: _.label++; return { value: op[1], done: false };
|
|
22
|
+
case 5: _.label++; y = op[1]; op = [0]; continue;
|
|
23
|
+
case 7: op = _.ops.pop(); _.trys.pop(); continue;
|
|
24
|
+
default:
|
|
25
|
+
if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }
|
|
26
|
+
if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }
|
|
27
|
+
if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }
|
|
28
|
+
if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }
|
|
29
|
+
if (t[2]) _.ops.pop();
|
|
30
|
+
_.trys.pop(); continue;
|
|
31
|
+
}
|
|
32
|
+
op = body.call(thisArg, _);
|
|
33
|
+
} catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }
|
|
34
|
+
if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
|
|
35
|
+
}
|
|
36
|
+
};
|
|
37
|
+
var __spreadArray = (this && this.__spreadArray) || function (to, from, pack) {
|
|
38
|
+
if (pack || arguments.length === 2) for (var i = 0, l = from.length, ar; i < l; i++) {
|
|
39
|
+
if (ar || !(i in from)) {
|
|
40
|
+
if (!ar) ar = Array.prototype.slice.call(from, 0, i);
|
|
41
|
+
ar[i] = from[i];
|
|
42
|
+
}
|
|
43
|
+
}
|
|
44
|
+
return to.concat(ar || Array.prototype.slice.call(from));
|
|
45
|
+
};
|
|
46
|
+
import { curve } from "../curve.js";
|
|
47
|
+
import ERC20ABI from "../constants/abis/ERC20.json" assert { type: 'json' };
|
|
48
|
+
import tricryptoFactorySwapABI from "../constants/abis/factory-tricrypto/factory-tricrypto-pool.json" assert { type: 'json' };
|
|
49
|
+
import factoryGaugeABI from "../constants/abis/gauge_factory.json" assert { type: 'json' };
|
|
50
|
+
import gaugeChildABI from "../constants/abis/gauge_child.json" assert { type: 'json' };
|
|
51
|
+
var deepFlatten = function (arr) { return [].concat.apply([], arr.map(function (v) { return (Array.isArray(v) ? deepFlatten(v) : v); })); };
|
|
52
|
+
function getRecentlyCreatedCryptoPoolId(swapAddress) {
|
|
53
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
54
|
+
var factoryContract, poolCount, _a, _b, _c, i, address;
|
|
55
|
+
return __generator(this, function (_e) {
|
|
56
|
+
switch (_e.label) {
|
|
57
|
+
case 0:
|
|
58
|
+
factoryContract = this.contracts[this.constants.ALIASES.tricrypto_factory].contract;
|
|
59
|
+
_a = Number;
|
|
60
|
+
_c = (_b = curve).formatUnits;
|
|
61
|
+
return [4 /*yield*/, factoryContract.pool_count(this.constantOptions)];
|
|
62
|
+
case 1:
|
|
63
|
+
poolCount = _a.apply(void 0, [_c.apply(_b, [_e.sent(), 0])]);
|
|
64
|
+
i = 1;
|
|
65
|
+
_e.label = 2;
|
|
66
|
+
case 2:
|
|
67
|
+
if (!(i <= poolCount)) return [3 /*break*/, 5];
|
|
68
|
+
return [4 /*yield*/, factoryContract.pool_list(poolCount - i)];
|
|
69
|
+
case 3:
|
|
70
|
+
address = _e.sent();
|
|
71
|
+
if (address.toLowerCase() === swapAddress.toLowerCase())
|
|
72
|
+
return [2 /*return*/, "factory-tricrypto-".concat(poolCount - i)];
|
|
73
|
+
_e.label = 4;
|
|
74
|
+
case 4:
|
|
75
|
+
i++;
|
|
76
|
+
return [3 /*break*/, 2];
|
|
77
|
+
case 5: throw Error("Unknown pool");
|
|
78
|
+
}
|
|
79
|
+
});
|
|
80
|
+
});
|
|
81
|
+
}
|
|
82
|
+
function getCryptoFactoryIdsAndSwapAddresses(fromIdx) {
|
|
83
|
+
if (fromIdx === void 0) { fromIdx = 0; }
|
|
84
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
85
|
+
var factoryContract, factoryMulticallContract, poolCount, _a, _b, _c, calls, i, factories, swapAddresses;
|
|
86
|
+
return __generator(this, function (_e) {
|
|
87
|
+
switch (_e.label) {
|
|
88
|
+
case 0:
|
|
89
|
+
factoryContract = this.contracts[this.constants.ALIASES.tricrypto_factory].contract;
|
|
90
|
+
factoryMulticallContract = this.contracts[this.constants.ALIASES.tricrypto_factory].multicallContract;
|
|
91
|
+
_a = Number;
|
|
92
|
+
_c = (_b = curve).formatUnits;
|
|
93
|
+
return [4 /*yield*/, factoryContract.pool_count(this.constantOptions)];
|
|
94
|
+
case 1:
|
|
95
|
+
poolCount = _a.apply(void 0, [_c.apply(_b, [_e.sent(), 0])]);
|
|
96
|
+
calls = [];
|
|
97
|
+
for (i = fromIdx; i < poolCount; i++) {
|
|
98
|
+
calls.push(factoryMulticallContract.pool_list(i));
|
|
99
|
+
}
|
|
100
|
+
if (calls.length === 0)
|
|
101
|
+
return [2 /*return*/, [[], []]];
|
|
102
|
+
return [4 /*yield*/, this.multicallProvider.all(calls)];
|
|
103
|
+
case 2:
|
|
104
|
+
factories = (_e.sent()).map(function (addr, i) { return ({ id: "factory-tricrypto-".concat(fromIdx + i), address: addr.toLowerCase() }); });
|
|
105
|
+
swapAddresses = Object.values(this.constants.POOLS_DATA).map(function (pool) { return pool.swap_address.toLowerCase(); });
|
|
106
|
+
factories = factories.filter(function (f) { return !swapAddresses.includes(f.address); });
|
|
107
|
+
return [2 /*return*/, [factories.map(function (f) { return f.id; }), factories.map(function (f) { return f.address; })]];
|
|
108
|
+
}
|
|
109
|
+
});
|
|
110
|
+
});
|
|
111
|
+
}
|
|
112
|
+
function _handleCoinAddresses(coinAddresses) {
|
|
113
|
+
var _this = this;
|
|
114
|
+
return coinAddresses.map(function (addresses) { return addresses.map(function (addr) { return _this.chainId === 137 && addr === "0x0000000000000000000000000000000000001010" ? _this.constants.NATIVE_TOKEN.wrappedAddress : addr.toLowerCase(); }); });
|
|
115
|
+
}
|
|
116
|
+
function getPoolsData(factorySwapAddresses) {
|
|
117
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
118
|
+
var factoryMulticallContract, calls, _i, factorySwapAddresses_1, addr, res, gaugeAddresses, coinAddresses;
|
|
119
|
+
return __generator(this, function (_a) {
|
|
120
|
+
switch (_a.label) {
|
|
121
|
+
case 0:
|
|
122
|
+
factoryMulticallContract = this.contracts[this.constants.ALIASES.tricrypto_factory].multicallContract;
|
|
123
|
+
calls = [];
|
|
124
|
+
for (_i = 0, factorySwapAddresses_1 = factorySwapAddresses; _i < factorySwapAddresses_1.length; _i++) {
|
|
125
|
+
addr = factorySwapAddresses_1[_i];
|
|
126
|
+
calls.push(factoryMulticallContract.get_gauge(addr));
|
|
127
|
+
calls.push(factoryMulticallContract.get_coins(addr));
|
|
128
|
+
}
|
|
129
|
+
return [4 /*yield*/, this.multicallProvider.all(calls)];
|
|
130
|
+
case 1:
|
|
131
|
+
res = _a.sent();
|
|
132
|
+
gaugeAddresses = res.filter(function (a, i) { return i % 2 == 0; }).map(function (a) { return a.toLowerCase(); });
|
|
133
|
+
coinAddresses = _handleCoinAddresses.call(this, res.filter(function (a, i) { return i % 2 == 1; }));
|
|
134
|
+
return [2 /*return*/, [gaugeAddresses, coinAddresses]];
|
|
135
|
+
}
|
|
136
|
+
});
|
|
137
|
+
});
|
|
138
|
+
}
|
|
139
|
+
function setCryptoFactorySwapContracts(factorySwapAddresses) {
|
|
140
|
+
var _this = this;
|
|
141
|
+
factorySwapAddresses.forEach(function (addr) {
|
|
142
|
+
_this.setContract(addr, tricryptoFactorySwapABI);
|
|
143
|
+
});
|
|
144
|
+
}
|
|
145
|
+
function setCryptoFactoryTokenContracts(factoryTokenAddresses) {
|
|
146
|
+
var _this = this;
|
|
147
|
+
factoryTokenAddresses.forEach(function (addr) {
|
|
148
|
+
_this.setContract(addr, ERC20ABI);
|
|
149
|
+
});
|
|
150
|
+
}
|
|
151
|
+
function setCryptoFactoryGaugeContracts(factoryGaugeAddresses) {
|
|
152
|
+
var _this = this;
|
|
153
|
+
factoryGaugeAddresses.filter(function (addr) { return addr !== curve.constants.ZERO_ADDRESS; }).forEach(function (addr, i) {
|
|
154
|
+
_this.setContract(addr, _this.chainId === 1 ? factoryGaugeABI : gaugeChildABI);
|
|
155
|
+
});
|
|
156
|
+
}
|
|
157
|
+
function setCryptoFactoryCoinsContracts(coinAddresses) {
|
|
158
|
+
var flattenedCoinAddresses = Array.from(new Set(deepFlatten(coinAddresses)));
|
|
159
|
+
for (var _i = 0, flattenedCoinAddresses_1 = flattenedCoinAddresses; _i < flattenedCoinAddresses_1.length; _i++) {
|
|
160
|
+
var addr = flattenedCoinAddresses_1[_i];
|
|
161
|
+
if (addr in this.contracts)
|
|
162
|
+
continue;
|
|
163
|
+
this.setContract(addr, ERC20ABI);
|
|
164
|
+
}
|
|
165
|
+
}
|
|
166
|
+
function getCryptoFactoryUnderlyingCoinAddresses(coinAddresses) {
|
|
167
|
+
var _this = this;
|
|
168
|
+
return __spreadArray([], coinAddresses.map(function (coins) { return coins.map(function (c) { return c === _this.constants.NATIVE_TOKEN.wrappedAddress ? _this.constants.NATIVE_TOKEN.address : c; }); }), true);
|
|
169
|
+
}
|
|
170
|
+
function getExistingCoinAddressNameDict() {
|
|
171
|
+
var dict = {};
|
|
172
|
+
var _loop_1 = function (poolData) {
|
|
173
|
+
poolData.wrapped_coin_addresses.forEach(function (addr, i) {
|
|
174
|
+
if (!(addr.toLowerCase() in dict)) {
|
|
175
|
+
dict[addr.toLowerCase()] = poolData.wrapped_coins[i];
|
|
176
|
+
}
|
|
177
|
+
});
|
|
178
|
+
poolData.underlying_coin_addresses.forEach(function (addr, i) {
|
|
179
|
+
if (!(addr.toLowerCase() in dict)) {
|
|
180
|
+
dict[addr.toLowerCase()] = poolData.underlying_coins[i];
|
|
181
|
+
}
|
|
182
|
+
});
|
|
183
|
+
};
|
|
184
|
+
for (var _i = 0, _a = Object.values(this.constants.POOLS_DATA); _i < _a.length; _i++) {
|
|
185
|
+
var poolData = _a[_i];
|
|
186
|
+
_loop_1(poolData);
|
|
187
|
+
}
|
|
188
|
+
dict[this.constants.NATIVE_TOKEN.address] = this.constants.NATIVE_TOKEN.symbol;
|
|
189
|
+
return dict;
|
|
190
|
+
}
|
|
191
|
+
function getCoinsData(tokenAddresses, coinAddresses, existingCoinAddrNameDict, existingCoinAddrDecimalsDict) {
|
|
192
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
193
|
+
var flattenedCoinAddresses, newCoinAddresses, coinAddrNamesDict, coinAddrDecimalsDict, _i, flattenedCoinAddresses_2, addr, calls, _a, tokenAddresses_1, addr, _b, newCoinAddresses_1, addr, res, res1, tokenSymbols, tokenNames, res2, symbols, decimals;
|
|
194
|
+
return __generator(this, function (_c) {
|
|
195
|
+
switch (_c.label) {
|
|
196
|
+
case 0:
|
|
197
|
+
flattenedCoinAddresses = Array.from(new Set(deepFlatten(coinAddresses)));
|
|
198
|
+
newCoinAddresses = [];
|
|
199
|
+
coinAddrNamesDict = {};
|
|
200
|
+
coinAddrDecimalsDict = {};
|
|
201
|
+
for (_i = 0, flattenedCoinAddresses_2 = flattenedCoinAddresses; _i < flattenedCoinAddresses_2.length; _i++) {
|
|
202
|
+
addr = flattenedCoinAddresses_2[_i];
|
|
203
|
+
if (addr in existingCoinAddrNameDict) {
|
|
204
|
+
coinAddrNamesDict[addr] = existingCoinAddrNameDict[addr];
|
|
205
|
+
coinAddrDecimalsDict[addr] = existingCoinAddrDecimalsDict[addr];
|
|
206
|
+
}
|
|
207
|
+
else if (addr === "0x9f8f72aa9304c8b593d555f12ef6589cc3a579a2") {
|
|
208
|
+
coinAddrNamesDict[addr] = "MKR";
|
|
209
|
+
}
|
|
210
|
+
else {
|
|
211
|
+
newCoinAddresses.push(addr);
|
|
212
|
+
}
|
|
213
|
+
}
|
|
214
|
+
calls = [];
|
|
215
|
+
for (_a = 0, tokenAddresses_1 = tokenAddresses; _a < tokenAddresses_1.length; _a++) {
|
|
216
|
+
addr = tokenAddresses_1[_a];
|
|
217
|
+
calls.push(this.contracts[addr].multicallContract.symbol());
|
|
218
|
+
calls.push(this.contracts[addr].multicallContract.name());
|
|
219
|
+
}
|
|
220
|
+
for (_b = 0, newCoinAddresses_1 = newCoinAddresses; _b < newCoinAddresses_1.length; _b++) {
|
|
221
|
+
addr = newCoinAddresses_1[_b];
|
|
222
|
+
calls.push(this.contracts[addr].multicallContract.symbol());
|
|
223
|
+
calls.push(this.contracts[addr].multicallContract.decimals());
|
|
224
|
+
}
|
|
225
|
+
return [4 /*yield*/, this.multicallProvider.all(calls)];
|
|
226
|
+
case 1:
|
|
227
|
+
res = _c.sent();
|
|
228
|
+
res1 = res.slice(0, tokenAddresses.length * 2);
|
|
229
|
+
tokenSymbols = res1.filter(function (a, i) { return i % 2 == 0; });
|
|
230
|
+
tokenNames = res1.filter(function (a, i) { return i % 2 == 1; });
|
|
231
|
+
res2 = res.slice(tokenAddresses.length * 2);
|
|
232
|
+
symbols = res2.filter(function (a, i) { return i % 2 == 0; });
|
|
233
|
+
decimals = res2.filter(function (a, i) { return i % 2 == 1; }).map(function (_d) { return Number(curve.formatUnits(_d, 0)); });
|
|
234
|
+
newCoinAddresses.forEach(function (addr, i) {
|
|
235
|
+
coinAddrNamesDict[addr] = symbols[i];
|
|
236
|
+
coinAddrDecimalsDict[addr] = decimals[i];
|
|
237
|
+
});
|
|
238
|
+
coinAddrNamesDict[this.constants.NATIVE_TOKEN.address] = this.constants.NATIVE_TOKEN.symbol;
|
|
239
|
+
coinAddrDecimalsDict[this.constants.NATIVE_TOKEN.address] = 18;
|
|
240
|
+
return [2 /*return*/, [tokenSymbols, tokenNames, coinAddrNamesDict, coinAddrDecimalsDict]];
|
|
241
|
+
}
|
|
242
|
+
});
|
|
243
|
+
});
|
|
244
|
+
}
|
|
245
|
+
export function getTricryptoFactoryPoolData(fromIdx, swapAddress) {
|
|
246
|
+
if (fromIdx === void 0) { fromIdx = 0; }
|
|
247
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
248
|
+
var _a, poolIds, swapAddresses, _b, _c, gaugeAddresses, coinAddresses, underlyingCoinAddresses, existingCoinAddressNameDict, _e, poolSymbols, poolNames, coinAddressNameDict, coinAddressDecimalsDict, TRICRYPTO_FACTORY_POOLS_DATA, i;
|
|
249
|
+
return __generator(this, function (_f) {
|
|
250
|
+
switch (_f.label) {
|
|
251
|
+
case 0:
|
|
252
|
+
if (!swapAddress) return [3 /*break*/, 2];
|
|
253
|
+
return [4 /*yield*/, getRecentlyCreatedCryptoPoolId.call(this, swapAddress)];
|
|
254
|
+
case 1:
|
|
255
|
+
_b = [[_f.sent()], [swapAddress.toLowerCase()]];
|
|
256
|
+
return [3 /*break*/, 4];
|
|
257
|
+
case 2: return [4 /*yield*/, getCryptoFactoryIdsAndSwapAddresses.call(this, fromIdx)];
|
|
258
|
+
case 3:
|
|
259
|
+
_b = _f.sent();
|
|
260
|
+
_f.label = 4;
|
|
261
|
+
case 4:
|
|
262
|
+
_a = _b, poolIds = _a[0], swapAddresses = _a[1];
|
|
263
|
+
if (poolIds.length === 0)
|
|
264
|
+
return [2 /*return*/, {}];
|
|
265
|
+
return [4 /*yield*/, getPoolsData.call(this, swapAddresses)];
|
|
266
|
+
case 5:
|
|
267
|
+
_c = _f.sent(), gaugeAddresses = _c[0], coinAddresses = _c[1];
|
|
268
|
+
setCryptoFactorySwapContracts.call(this, swapAddresses);
|
|
269
|
+
setCryptoFactoryGaugeContracts.call(this, gaugeAddresses);
|
|
270
|
+
setCryptoFactoryCoinsContracts.call(this, coinAddresses);
|
|
271
|
+
underlyingCoinAddresses = getCryptoFactoryUnderlyingCoinAddresses.call(this, coinAddresses);
|
|
272
|
+
existingCoinAddressNameDict = getExistingCoinAddressNameDict.call(this);
|
|
273
|
+
return [4 /*yield*/, getCoinsData.call(this, swapAddresses, coinAddresses, existingCoinAddressNameDict, this.constants.DECIMALS)];
|
|
274
|
+
case 6:
|
|
275
|
+
_e = _f.sent(), poolSymbols = _e[0], poolNames = _e[1], coinAddressNameDict = _e[2], coinAddressDecimalsDict = _e[3];
|
|
276
|
+
TRICRYPTO_FACTORY_POOLS_DATA = {};
|
|
277
|
+
for (i = 0; i < poolIds.length; i++) {
|
|
278
|
+
TRICRYPTO_FACTORY_POOLS_DATA[poolIds[i]] = {
|
|
279
|
+
name: poolNames[i],
|
|
280
|
+
full_name: poolNames[i],
|
|
281
|
+
symbol: poolSymbols[i],
|
|
282
|
+
reference_asset: "CRYPTO",
|
|
283
|
+
swap_address: swapAddresses[i],
|
|
284
|
+
token_address: swapAddresses[i],
|
|
285
|
+
gauge_address: gaugeAddresses[i],
|
|
286
|
+
is_crypto: true,
|
|
287
|
+
is_plain: underlyingCoinAddresses[i].toString() === coinAddresses[i].toString(),
|
|
288
|
+
is_factory: true,
|
|
289
|
+
underlying_coins: __spreadArray([], underlyingCoinAddresses[i].map(function (addr) { return coinAddressNameDict[addr]; }), true),
|
|
290
|
+
wrapped_coins: __spreadArray([], coinAddresses[i].map(function (addr) { return coinAddressNameDict[addr]; }), true),
|
|
291
|
+
underlying_coin_addresses: underlyingCoinAddresses[i],
|
|
292
|
+
wrapped_coin_addresses: coinAddresses[i],
|
|
293
|
+
underlying_decimals: __spreadArray([], underlyingCoinAddresses[i].map(function (addr) { return coinAddressDecimalsDict[addr]; }), true),
|
|
294
|
+
wrapped_decimals: __spreadArray([], coinAddresses[i].map(function (addr) { return coinAddressDecimalsDict[addr]; }), true),
|
|
295
|
+
swap_abi: tricryptoFactorySwapABI,
|
|
296
|
+
gauge_abi: this.chainId === 1 ? factoryGaugeABI : gaugeChildABI,
|
|
297
|
+
};
|
|
298
|
+
}
|
|
299
|
+
return [2 /*return*/, TRICRYPTO_FACTORY_POOLS_DATA];
|
|
300
|
+
}
|
|
301
|
+
});
|
|
302
|
+
});
|
|
303
|
+
}
|
package/lib/index.d.ts
CHANGED
|
@@ -81,14 +81,27 @@ declare const curve: {
|
|
|
81
81
|
fetchPools: (useApi?: boolean) => Promise<void>;
|
|
82
82
|
fetchNewPools: () => Promise<string[]>;
|
|
83
83
|
getPoolList: () => string[];
|
|
84
|
-
deployPool: (name: string, symbol: string, coins: string[], A: string | number, gamma: string | number, midFee: string | number, outFee: string | number, allowedExtraProfit: string | number, feeGamma: string | number, adjustmentStep: string | number, maHalfTime:
|
|
84
|
+
deployPool: (name: string, symbol: string, coins: string[], A: string | number, gamma: string | number, midFee: string | number, outFee: string | number, allowedExtraProfit: string | number, feeGamma: string | number, adjustmentStep: string | number, maHalfTime: number, initialPrice: string | number) => Promise<ethers.ContractTransactionResponse>;
|
|
85
85
|
deployGauge: (poolAddress: string) => Promise<ethers.ContractTransactionResponse>;
|
|
86
|
-
getDeployed: (tx: ethers.ContractTransactionResponse) => Promise<string>;
|
|
87
86
|
getDeployedPoolAddress: (tx: ethers.ContractTransactionResponse) => Promise<string>;
|
|
88
87
|
getDeployedGaugeAddress: (tx: ethers.ContractTransactionResponse) => Promise<string>;
|
|
89
88
|
fetchRecentlyDeployedPool: (poolAddress: string) => Promise<string>;
|
|
90
89
|
estimateGas: {
|
|
91
|
-
deployPool: (name: string, symbol: string, coins: string[], A: string | number, gamma: string | number, midFee: string | number, outFee: string | number, allowedExtraProfit: string | number, feeGamma: string | number, adjustmentStep: string | number, maHalfTime:
|
|
90
|
+
deployPool: (name: string, symbol: string, coins: string[], A: string | number, gamma: string | number, midFee: string | number, outFee: string | number, allowedExtraProfit: string | number, feeGamma: string | number, adjustmentStep: string | number, maHalfTime: number, initialPrice: string | number) => Promise<number>;
|
|
91
|
+
deployGauge: (poolAddress: string) => Promise<number>;
|
|
92
|
+
};
|
|
93
|
+
};
|
|
94
|
+
tricryptoFactory: {
|
|
95
|
+
fetchPools: (useApi?: boolean) => Promise<void>;
|
|
96
|
+
fetchNewPools: () => Promise<string[]>;
|
|
97
|
+
getPoolList: () => string[];
|
|
98
|
+
deployPool: (name: string, symbol: string, coins: string[], A: string | number, gamma: string | number, midFee: string | number, outFee: string | number, allowedExtraProfit: string | number, feeGamma: string | number, adjustmentStep: string | number, emaTime: number, initialPrices: (string | number)[]) => Promise<ethers.ContractTransactionResponse>;
|
|
99
|
+
deployGauge: (poolAddress: string) => Promise<ethers.ContractTransactionResponse>;
|
|
100
|
+
getDeployedPoolAddress: (tx: ethers.ContractTransactionResponse) => Promise<string>;
|
|
101
|
+
getDeployedGaugeAddress: (tx: ethers.ContractTransactionResponse) => Promise<string>;
|
|
102
|
+
fetchRecentlyDeployedPool: (poolAddress: string) => Promise<string>;
|
|
103
|
+
estimateGas: {
|
|
104
|
+
deployPool: (name: string, symbol: string, coins: string[], A: string | number, gamma: string | number, midFee: string | number, outFee: string | number, allowedExtraProfit: string | number, feeGamma: string | number, adjustmentStep: string | number, emaTime: number, initialPrices: (string | number)[]) => Promise<number>;
|
|
92
105
|
deployGauge: (poolAddress: string) => Promise<number>;
|
|
93
106
|
};
|
|
94
107
|
};
|
package/lib/index.js
CHANGED
|
@@ -40,7 +40,7 @@ import { getBestRouteAndOutput, swapExpected, swapPriceImpact, swapIsApproved, s
|
|
|
40
40
|
import { curve as _curve } from "./curve.js";
|
|
41
41
|
import { getCrv, getLockedAmountAndUnlockTime, getVeCrv, getVeCrvPct, calcUnlockTime, createLockEstimateGas, createLock, isApproved, approveEstimateGas, approve, increaseAmountEstimateGas, increaseAmount, increaseUnlockTimeEstimateGas, increaseUnlockTime, withdrawLockedCrvEstimateGas, withdrawLockedCrv, claimableFees, claimFeesEstimateGas, claimFees, lastBlockhash, checkBlockhash, getAnycallBalance, topUpAnycall, topUpAnycallEstimateGas, sendBlockhash, sendBlockhashEstimateGas, submitProof, submitProofEstimateGas, } from "./boosting.js";
|
|
42
42
|
import { getBalances, getAllowance, hasAllowance, ensureAllowanceEstimateGas, ensureAllowance, getUsdRate, getTVL, getCoinsData, getVolume, } from "./utils.js";
|
|
43
|
-
import { deployStablePlainPool, deployStablePlainPoolEstimateGas, setOracle, setOracleEstimateGas, deployStableMetaPool, deployStableMetaPoolEstimateGas, deployCryptoPool, deployCryptoPoolEstimateGas,
|
|
43
|
+
import { deployStablePlainPool, deployStablePlainPoolEstimateGas, getDeployedStablePlainPoolAddress, setOracle, setOracleEstimateGas, deployStableMetaPool, deployStableMetaPoolEstimateGas, getDeployedStableMetaPoolAddress, deployCryptoPool, deployCryptoPoolEstimateGas, getDeployedCryptoPoolAddress, deployTricryptoPool, deployTricryptoPoolEstimateGas, getDeployedTricryptoPoolAddress, deployGauge, deployGaugeEstimateGas, getDeployedGaugeAddress, } from './factory/deploy.js';
|
|
44
44
|
function init(providerType, providerSettings, options) {
|
|
45
45
|
if (options === void 0) { options = {}; }
|
|
46
46
|
return __awaiter(this, void 0, void 0, function () {
|
|
@@ -91,7 +91,7 @@ var curve = {
|
|
|
91
91
|
setOracle: setOracle,
|
|
92
92
|
deployMetaPool: deployStableMetaPool,
|
|
93
93
|
deployGauge: function (poolAddress) { return __awaiter(void 0, void 0, void 0, function () { return __generator(this, function (_a) {
|
|
94
|
-
return [2 /*return*/, deployGauge(poolAddress,
|
|
94
|
+
return [2 /*return*/, deployGauge(poolAddress, _curve.constants.ALIASES.factory)];
|
|
95
95
|
}); }); },
|
|
96
96
|
getDeployedPlainPoolAddress: getDeployedStablePlainPoolAddress,
|
|
97
97
|
getDeployedMetaPoolAddress: getDeployedStableMetaPoolAddress,
|
|
@@ -102,7 +102,7 @@ var curve = {
|
|
|
102
102
|
setOracle: setOracleEstimateGas,
|
|
103
103
|
deployMetaPool: deployStableMetaPoolEstimateGas,
|
|
104
104
|
deployGauge: function (poolAddress) { return __awaiter(void 0, void 0, void 0, function () { return __generator(this, function (_a) {
|
|
105
|
-
return [2 /*return*/, deployGaugeEstimateGas(poolAddress,
|
|
105
|
+
return [2 /*return*/, deployGaugeEstimateGas(poolAddress, _curve.constants.ALIASES.factory)];
|
|
106
106
|
}); }); },
|
|
107
107
|
},
|
|
108
108
|
},
|
|
@@ -116,16 +116,33 @@ var curve = {
|
|
|
116
116
|
getPoolList: _curve.getCryptoFactoryPoolList,
|
|
117
117
|
deployPool: deployCryptoPool,
|
|
118
118
|
deployGauge: function (poolAddress) { return __awaiter(void 0, void 0, void 0, function () { return __generator(this, function (_a) {
|
|
119
|
-
return [2 /*return*/, deployGauge(poolAddress,
|
|
119
|
+
return [2 /*return*/, deployGauge(poolAddress, _curve.constants.ALIASES.crypto_factory)];
|
|
120
120
|
}); }); },
|
|
121
|
-
getDeployed: getDeployedStablePlainPoolAddress,
|
|
122
121
|
getDeployedPoolAddress: getDeployedCryptoPoolAddress,
|
|
123
122
|
getDeployedGaugeAddress: getDeployedGaugeAddress,
|
|
124
123
|
fetchRecentlyDeployedPool: _curve.fetchRecentlyDeployedCryptoFactoryPool,
|
|
125
124
|
estimateGas: {
|
|
126
125
|
deployPool: deployCryptoPoolEstimateGas,
|
|
127
126
|
deployGauge: function (poolAddress) { return __awaiter(void 0, void 0, void 0, function () { return __generator(this, function (_a) {
|
|
128
|
-
return [2 /*return*/, deployGaugeEstimateGas(poolAddress,
|
|
127
|
+
return [2 /*return*/, deployGaugeEstimateGas(poolAddress, _curve.constants.ALIASES.crypto_factory)];
|
|
128
|
+
}); }); },
|
|
129
|
+
},
|
|
130
|
+
},
|
|
131
|
+
tricryptoFactory: {
|
|
132
|
+
fetchPools: _curve.fetchTricryptoFactoryPools,
|
|
133
|
+
fetchNewPools: _curve.fetchNewTricryptoFactoryPools,
|
|
134
|
+
getPoolList: _curve.getTricryptoFactoryPoolList,
|
|
135
|
+
deployPool: deployTricryptoPool,
|
|
136
|
+
deployGauge: function (poolAddress) { return __awaiter(void 0, void 0, void 0, function () { return __generator(this, function (_a) {
|
|
137
|
+
return [2 /*return*/, deployGauge(poolAddress, _curve.constants.ALIASES.tricrypto_factory)];
|
|
138
|
+
}); }); },
|
|
139
|
+
getDeployedPoolAddress: getDeployedTricryptoPoolAddress,
|
|
140
|
+
getDeployedGaugeAddress: getDeployedGaugeAddress,
|
|
141
|
+
fetchRecentlyDeployedPool: _curve.fetchRecentlyDeployedTricryptoFactoryPool,
|
|
142
|
+
estimateGas: {
|
|
143
|
+
deployPool: deployTricryptoPoolEstimateGas,
|
|
144
|
+
deployGauge: function (poolAddress) { return __awaiter(void 0, void 0, void 0, function () { return __generator(this, function (_a) {
|
|
145
|
+
return [2 /*return*/, deployGaugeEstimateGas(poolAddress, _curve.constants.ALIASES.tricrypto_factory)];
|
|
129
146
|
}); }); },
|
|
130
147
|
},
|
|
131
148
|
},
|
package/lib/interfaces.d.ts
CHANGED
|
@@ -76,7 +76,10 @@ export interface ICurve {
|
|
|
76
76
|
ALIASES: IDict<string>;
|
|
77
77
|
POOLS_DATA: IDict<IPoolData>;
|
|
78
78
|
FACTORY_POOLS_DATA: IDict<IPoolData>;
|
|
79
|
+
CRVUSD_FACTORY_POOLS_DATA: IDict<IPoolData>;
|
|
79
80
|
CRYPTO_FACTORY_POOLS_DATA: IDict<IPoolData>;
|
|
81
|
+
TRICRYPTO_FACTORY_POOLS_DATA: IDict<IPoolData>;
|
|
82
|
+
LLAMMAS_DATA: IDict<IPoolData>;
|
|
80
83
|
COINS: IDict<string>;
|
|
81
84
|
DECIMALS: IDict<number>;
|
|
82
85
|
GAUGES: string[];
|
|
@@ -78,7 +78,7 @@ var PoolTemplate = /** @class */ (function () {
|
|
|
78
78
|
calls = [
|
|
79
79
|
multicallContract.get_virtual_price(),
|
|
80
80
|
multicallContract.fee(),
|
|
81
|
-
multicallContract.admin_fee(),
|
|
81
|
+
"admin_fee" in multicallContract ? multicallContract.admin_fee() : multicallContract.ADMIN_FEE(),
|
|
82
82
|
multicallContract.A(),
|
|
83
83
|
lpMulticallContract.totalSupply(),
|
|
84
84
|
];
|
|
@@ -464,7 +464,7 @@ var PoolTemplate = /** @class */ (function () {
|
|
|
464
464
|
if (!BN(a).eq(BN(seedAmounts_1[i])))
|
|
465
465
|
throw Error("Amounts must be = ".concat(seedAmounts_1));
|
|
466
466
|
});
|
|
467
|
-
return [2 /*return*/, parseUnits(Math.sqrt(Number(
|
|
467
|
+
return [2 /*return*/, parseUnits(Math.sqrt(amounts.map(Number).reduce(function (a, b) { return a * b; })))];
|
|
468
468
|
case 6:
|
|
469
469
|
_c.trys.push([6, 11, , 13]);
|
|
470
470
|
contract = curve.contracts[curve.constants.ALIASES.stable_calc].contract;
|
|
@@ -1082,7 +1082,7 @@ var PoolTemplate = /** @class */ (function () {
|
|
|
1082
1082
|
}
|
|
1083
1083
|
});
|
|
1084
1084
|
}); };
|
|
1085
|
-
var poolData =
|
|
1085
|
+
var poolData = curve.getPoolsData()[id];
|
|
1086
1086
|
this.id = id;
|
|
1087
1087
|
this.name = poolData.name;
|
|
1088
1088
|
this.fullName = poolData.full_name;
|
|
@@ -1283,23 +1283,36 @@ var PoolTemplate = /** @class */ (function () {
|
|
|
1283
1283
|
};
|
|
1284
1284
|
PoolTemplate.prototype.cryptoSeedAmounts = function (amount1) {
|
|
1285
1285
|
return __awaiter(this, void 0, void 0, function () {
|
|
1286
|
-
var decimals, amount1BN, priceScaleBN, _c;
|
|
1286
|
+
var decimals, amount1BN, priceScaleBN, _c, priceScaleBN;
|
|
1287
1287
|
return __generator(this, function (_d) {
|
|
1288
1288
|
switch (_d.label) {
|
|
1289
1289
|
case 0:
|
|
1290
1290
|
if (!this.isCrypto)
|
|
1291
1291
|
throw Error("cryptoSeedAmounts method doesn't exist for stable pools");
|
|
1292
1292
|
decimals = this.isMeta ? this.wrappedDecimals : this.underlyingDecimals;
|
|
1293
|
-
if (decimals.length > 2)
|
|
1294
|
-
throw Error("cryptoSeedAmounts method doesn't exist for pools with N coins > 2");
|
|
1295
1293
|
amount1BN = BN(amount1);
|
|
1296
1294
|
if (amount1BN.lte(0))
|
|
1297
1295
|
throw Error("Initial deposit amounts must be > 0");
|
|
1296
|
+
if (!(decimals.length === 2)) return [3 /*break*/, 2];
|
|
1298
1297
|
_c = toBN;
|
|
1299
1298
|
return [4 /*yield*/, curve.contracts[this.address].contract.price_scale(curve.constantOptions)];
|
|
1300
1299
|
case 1:
|
|
1301
1300
|
priceScaleBN = _c.apply(void 0, [_d.sent()]);
|
|
1302
1301
|
return [2 /*return*/, [_cutZeros(amount1BN.toFixed(decimals[0])), _cutZeros(amount1BN.div(priceScaleBN).toFixed(decimals[1]))]];
|
|
1302
|
+
case 2:
|
|
1303
|
+
if (!(decimals.length === 3)) return [3 /*break*/, 4];
|
|
1304
|
+
return [4 /*yield*/, curve.multicallProvider.all([
|
|
1305
|
+
curve.contracts[this.address].multicallContract.price_scale(0),
|
|
1306
|
+
curve.contracts[this.address].multicallContract.price_scale(1),
|
|
1307
|
+
])];
|
|
1308
|
+
case 3:
|
|
1309
|
+
priceScaleBN = (_d.sent()).map(function (_p) { return toBN(_p); });
|
|
1310
|
+
return [2 /*return*/, [
|
|
1311
|
+
_cutZeros(amount1BN.toFixed(decimals[0])),
|
|
1312
|
+
_cutZeros(amount1BN.div(priceScaleBN[0]).toFixed(decimals[1])),
|
|
1313
|
+
_cutZeros(amount1BN.div(priceScaleBN[1]).toFixed(decimals[2])),
|
|
1314
|
+
]];
|
|
1315
|
+
case 4: throw Error("cryptoSeedAmounts method doesn't exist for pools with N coins > 3");
|
|
1303
1316
|
}
|
|
1304
1317
|
});
|
|
1305
1318
|
});
|
package/lib/router.js
CHANGED
|
@@ -136,7 +136,7 @@ var _findAllRoutes = function (inputCoinAddress, outputCoinAddress) { return __a
|
|
|
136
136
|
case 0:
|
|
137
137
|
inputCoinAddress = inputCoinAddress.toLowerCase();
|
|
138
138
|
outputCoinAddress = outputCoinAddress.toLowerCase();
|
|
139
|
-
ALL_POOLS = Object.entries(
|
|
139
|
+
ALL_POOLS = Object.entries(curve.getPoolsData());
|
|
140
140
|
return [4 /*yield*/, _getAmplificationCoefficientsFromApi()];
|
|
141
141
|
case 1:
|
|
142
142
|
amplificationCoefficientDict = _s.sent();
|
package/lib/utils.js
CHANGED
|
@@ -391,14 +391,14 @@ export var ensureAllowance = function (coins, amounts, spender, isMax) {
|
|
|
391
391
|
});
|
|
392
392
|
};
|
|
393
393
|
export var getPoolIdBySwapAddress = function (swapAddress) {
|
|
394
|
-
var poolsData =
|
|
394
|
+
var poolsData = curve.getPoolsData();
|
|
395
395
|
return Object.entries(poolsData).filter(function (_a) {
|
|
396
396
|
var _ = _a[0], poolData = _a[1];
|
|
397
397
|
return poolData.swap_address.toLowerCase() === swapAddress.toLowerCase();
|
|
398
398
|
})[0][0];
|
|
399
399
|
};
|
|
400
400
|
var _getTokenAddressBySwapAddress = function (swapAddress) {
|
|
401
|
-
var poolsData =
|
|
401
|
+
var poolsData = curve.getPoolsData();
|
|
402
402
|
var res = Object.entries(poolsData).filter(function (_a) {
|
|
403
403
|
var _ = _a[0], poolData = _a[1];
|
|
404
404
|
return poolData.swap_address.toLowerCase() === swapAddress.toLowerCase();
|