@curvefi/api 2.37.0 → 2.39.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 +46 -0
- package/lib/boosting.d.ts +10 -1
- package/lib/boosting.js +189 -0
- package/lib/constants/abis/anycall.json +552 -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/abis/voting_escrow_oracle.json +450 -0
- package/lib/constants/abis/voting_escrow_oracle_eth.json +76 -0
- package/lib/constants/aliases.js +11 -0
- package/lib/curve.d.ts +6 -0
- package/lib/curve.js +89 -2
- package/lib/external-api.d.ts +8 -1
- package/lib/external-api.js +16 -0
- 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 +19 -1
- package/lib/index.js +28 -2
- package/lib/interfaces.d.ts +3 -0
- package/lib/pools/PoolTemplate.js +5 -5
- 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
|
@@ -83,7 +83,6 @@ declare const curve: {
|
|
|
83
83
|
getPoolList: () => string[];
|
|
84
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: string | 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>;
|
|
@@ -92,6 +91,12 @@ declare const curve: {
|
|
|
92
91
|
deployGauge: (poolAddress: string) => Promise<number>;
|
|
93
92
|
};
|
|
94
93
|
};
|
|
94
|
+
tricryptoFactory: {
|
|
95
|
+
fetchPools: (useApi?: boolean) => Promise<void>;
|
|
96
|
+
fetchNewPools: () => Promise<string[]>;
|
|
97
|
+
getPoolList: () => string[];
|
|
98
|
+
fetchRecentlyDeployedPool: (poolAddress: string) => Promise<string>;
|
|
99
|
+
};
|
|
95
100
|
estimateGas: {
|
|
96
101
|
ensureAllowance: (coins: string[], amounts: (string | number)[], spender: string, isMax?: boolean) => Promise<number>;
|
|
97
102
|
};
|
|
@@ -123,6 +128,19 @@ declare const curve: {
|
|
|
123
128
|
withdrawLockedCrv: () => Promise<number>;
|
|
124
129
|
claimFees: (address?: string) => Promise<number>;
|
|
125
130
|
};
|
|
131
|
+
sidechain: {
|
|
132
|
+
lastBlockhash: () => Promise<number>;
|
|
133
|
+
checkBlockhash: (block: number) => Promise<boolean>;
|
|
134
|
+
getAnycallBalance: () => Promise<string>;
|
|
135
|
+
topUpAnycall: (amount?: string | number) => Promise<string>;
|
|
136
|
+
sendBlockhash: (block: number, chainId: import("./interfaces.js").IChainId) => Promise<string>;
|
|
137
|
+
submitProof: (block: number, address?: string) => Promise<string>;
|
|
138
|
+
estimateGas: {
|
|
139
|
+
topUpAnycall: (amount?: string | number) => Promise<number>;
|
|
140
|
+
sendBlockhash: (block: number, chainId: import("./interfaces.js").IChainId) => Promise<number>;
|
|
141
|
+
submitProof: (block: number, address?: string) => Promise<number>;
|
|
142
|
+
};
|
|
143
|
+
};
|
|
126
144
|
};
|
|
127
145
|
router: {
|
|
128
146
|
getBestRouteAndOutput: (inputCoin: string, outputCoin: string, amount: string | number) => Promise<{
|
package/lib/index.js
CHANGED
|
@@ -38,7 +38,7 @@ import { PoolTemplate, getPool } from "./pools/index.js";
|
|
|
38
38
|
import { getUserPoolListByLiquidity, getUserPoolListByClaimable, getUserPoolList, getUserLiquidityUSD, getUserClaimable, } from "./pools/utils.js";
|
|
39
39
|
import { getBestRouteAndOutput, swapExpected, swapPriceImpact, swapIsApproved, swapApproveEstimateGas, swapApprove, swapEstimateGas, swap, getSwappedAmount, } from "./router.js";
|
|
40
40
|
import { curve as _curve } from "./curve.js";
|
|
41
|
-
import { getCrv, getLockedAmountAndUnlockTime, getVeCrv, getVeCrvPct, calcUnlockTime, createLockEstimateGas, createLock, isApproved, approveEstimateGas, approve, increaseAmountEstimateGas, increaseAmount, increaseUnlockTimeEstimateGas, increaseUnlockTime, withdrawLockedCrvEstimateGas, withdrawLockedCrv, claimableFees, claimFeesEstimateGas, claimFees, } from "./boosting.js";
|
|
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
43
|
import { deployStablePlainPool, deployStablePlainPoolEstimateGas, setOracle, setOracleEstimateGas, deployStableMetaPool, deployStableMetaPoolEstimateGas, deployCryptoPool, deployCryptoPoolEstimateGas, deployGauge, deployGaugeEstimateGas, getDeployedStablePlainPoolAddress, getDeployedStableMetaPoolAddress, getDeployedCryptoPoolAddress, getDeployedGaugeAddress, } from './factory/deploy.js';
|
|
44
44
|
function init(providerType, providerSettings, options) {
|
|
@@ -118,7 +118,6 @@ var curve = {
|
|
|
118
118
|
deployGauge: function (poolAddress) { return __awaiter(void 0, void 0, void 0, function () { return __generator(this, function (_a) {
|
|
119
119
|
return [2 /*return*/, deployGauge(poolAddress, true)];
|
|
120
120
|
}); }); },
|
|
121
|
-
getDeployed: getDeployedStablePlainPoolAddress,
|
|
122
121
|
getDeployedPoolAddress: getDeployedCryptoPoolAddress,
|
|
123
122
|
getDeployedGaugeAddress: getDeployedGaugeAddress,
|
|
124
123
|
fetchRecentlyDeployedPool: _curve.fetchRecentlyDeployedCryptoFactoryPool,
|
|
@@ -129,6 +128,20 @@ var curve = {
|
|
|
129
128
|
}); }); },
|
|
130
129
|
},
|
|
131
130
|
},
|
|
131
|
+
tricryptoFactory: {
|
|
132
|
+
fetchPools: _curve.fetchTricryptoFactoryPools,
|
|
133
|
+
fetchNewPools: _curve.fetchNewTricryptoFactoryPools,
|
|
134
|
+
getPoolList: _curve.getTricryptoFactoryPoolList,
|
|
135
|
+
// deployPool: deployCryptoPool,
|
|
136
|
+
// deployGauge: async (poolAddress: string): Promise<ethers.ContractTransactionResponse> => deployGauge(poolAddress, true),
|
|
137
|
+
// getDeployedPoolAddress: getDeployedCryptoPoolAddress,
|
|
138
|
+
// getDeployedGaugeAddress: getDeployedGaugeAddress,
|
|
139
|
+
fetchRecentlyDeployedPool: _curve.fetchRecentlyDeployedTricryptoFactoryPool,
|
|
140
|
+
// estimateGas: {
|
|
141
|
+
// deployPool: deployCryptoPoolEstimateGas,
|
|
142
|
+
// deployGauge: async (poolAddress: string): Promise<number> => deployGaugeEstimateGas(poolAddress, true),
|
|
143
|
+
// },
|
|
144
|
+
},
|
|
132
145
|
estimateGas: {
|
|
133
146
|
ensureAllowance: ensureAllowanceEstimateGas,
|
|
134
147
|
},
|
|
@@ -154,6 +167,19 @@ var curve = {
|
|
|
154
167
|
withdrawLockedCrv: withdrawLockedCrvEstimateGas,
|
|
155
168
|
claimFees: claimFeesEstimateGas,
|
|
156
169
|
},
|
|
170
|
+
sidechain: {
|
|
171
|
+
lastBlockhash: lastBlockhash,
|
|
172
|
+
checkBlockhash: checkBlockhash,
|
|
173
|
+
getAnycallBalance: getAnycallBalance,
|
|
174
|
+
topUpAnycall: topUpAnycall,
|
|
175
|
+
sendBlockhash: sendBlockhash,
|
|
176
|
+
submitProof: submitProof,
|
|
177
|
+
estimateGas: {
|
|
178
|
+
topUpAnycall: topUpAnycallEstimateGas,
|
|
179
|
+
sendBlockhash: sendBlockhashEstimateGas,
|
|
180
|
+
submitProof: submitProofEstimateGas,
|
|
181
|
+
},
|
|
182
|
+
},
|
|
157
183
|
},
|
|
158
184
|
router: {
|
|
159
185
|
getBestRouteAndOutput: getBestRouteAndOutput,
|
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[];
|
|
@@ -597,8 +597,6 @@ var PoolTemplate = /** @class */ (function () {
|
|
|
597
597
|
return __generator(this, function (_d) {
|
|
598
598
|
switch (_d.label) {
|
|
599
599
|
case 0:
|
|
600
|
-
if (curve.chainId !== 1)
|
|
601
|
-
throw Error("Boosting is available only on Ethereum network");
|
|
602
600
|
if (this.gauge === curve.constants.ZERO_ADDRESS)
|
|
603
601
|
throw Error("".concat(this.name, " doesn't have gauge"));
|
|
604
602
|
address = address || curve.signerAddress;
|
|
@@ -612,6 +610,10 @@ var PoolTemplate = /** @class */ (function () {
|
|
|
612
610
|
case 1:
|
|
613
611
|
_c = (_d.sent()).map(function (value) { return toBN(value); }), workingBalanceBN = _c[0], balanceBN = _c[1];
|
|
614
612
|
boostBN = workingBalanceBN.div(0.4).div(balanceBN);
|
|
613
|
+
if (boostBN.lt(1))
|
|
614
|
+
return [2 /*return*/, '1.0'];
|
|
615
|
+
if (boostBN.gt(2.5))
|
|
616
|
+
return [2 /*return*/, '2.5'];
|
|
615
617
|
return [2 /*return*/, boostBN.toFixed(4).replace(/([0-9])0+$/, '$1')];
|
|
616
618
|
}
|
|
617
619
|
});
|
|
@@ -654,8 +656,6 @@ var PoolTemplate = /** @class */ (function () {
|
|
|
654
656
|
return __generator(this, function (_f) {
|
|
655
657
|
switch (_f.label) {
|
|
656
658
|
case 0:
|
|
657
|
-
if (curve.chainId !== 1)
|
|
658
|
-
throw Error("Boosting is available only on Ethereum network");
|
|
659
659
|
if (this.gauge === curve.constants.ZERO_ADDRESS)
|
|
660
660
|
throw Error("".concat(this.name, " doesn't have gauge"));
|
|
661
661
|
if (addresses.length == 1 && Array.isArray(addresses[0]))
|
|
@@ -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;
|
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();
|