@curvefi/api 2.62.0 → 2.63.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.
- package/lib/boosting.js +247 -645
- package/lib/constants/L2Networks.js +1 -1
- package/lib/constants/aliases.js +31 -31
- package/lib/constants/coins/arbitrum.js +5 -5
- package/lib/constants/coins/aurora.js +5 -5
- package/lib/constants/coins/avalanche.js +6 -6
- package/lib/constants/coins/base.js +5 -5
- package/lib/constants/coins/bsc.js +5 -5
- package/lib/constants/coins/celo.js +5 -5
- package/lib/constants/coins/ethereum.js +9 -9
- package/lib/constants/coins/fantom.js +7 -7
- package/lib/constants/coins/fraxtal.js +5 -5
- package/lib/constants/coins/kava.js +5 -5
- package/lib/constants/coins/mantle.js +5 -5
- package/lib/constants/coins/moonbeam.js +5 -5
- package/lib/constants/coins/optimism.js +5 -5
- package/lib/constants/coins/polygon.js +6 -6
- package/lib/constants/coins/xdai.js +5 -5
- package/lib/constants/coins/xlayer.js +5 -5
- package/lib/constants/coins/zksync.js +5 -5
- package/lib/constants/pools/arbitrum.js +1 -1
- package/lib/constants/pools/aurora.js +1 -1
- package/lib/constants/pools/avalanche.js +1 -1
- package/lib/constants/pools/base.js +1 -1
- package/lib/constants/pools/bsc.js +1 -1
- package/lib/constants/pools/celo.js +1 -1
- package/lib/constants/pools/ethereum.js +2 -2
- package/lib/constants/pools/fantom.js +1 -1
- package/lib/constants/pools/fraxtal.js +1 -1
- package/lib/constants/pools/kava.js +1 -1
- package/lib/constants/pools/mantle.js +1 -1
- package/lib/constants/pools/moonbeam.js +1 -1
- package/lib/constants/pools/optimism.js +1 -1
- package/lib/constants/pools/polygon.js +1 -1
- package/lib/constants/pools/xdai.js +1 -1
- package/lib/constants/pools/xlayer.js +1 -1
- package/lib/constants/pools/zksync.js +1 -1
- package/lib/constants/tricryptoDeployImplementations.js +3 -3
- package/lib/constants/utils.js +18 -19
- package/lib/constants/volumeNetworks.js +1 -1
- package/lib/curve.d.ts +3 -1
- package/lib/curve.js +534 -909
- package/lib/dao.js +351 -705
- package/lib/external-api.js +127 -256
- package/lib/factory/common.js +4 -4
- package/lib/factory/constants-crypto.js +33 -33
- package/lib/factory/constants.js +36 -46
- package/lib/factory/deploy.js +542 -907
- package/lib/factory/factory-api.js +205 -269
- package/lib/factory/factory-crypto.js +202 -342
- package/lib/factory/factory-tricrypto.js +164 -286
- package/lib/factory/factory-twocrypto.js +151 -269
- package/lib/factory/factory.js +245 -385
- package/lib/index.js +109 -198
- package/lib/interfaces.d.ts +1 -6
- package/lib/pools/PoolTemplate.js +1773 -3025
- package/lib/pools/gaugePool.js +112 -251
- package/lib/pools/mixins/common.js +22 -93
- package/lib/pools/mixins/depositBalancedAmountsMixins.js +52 -118
- package/lib/pools/mixins/depositMixins.js +160 -386
- package/lib/pools/mixins/depositWrappedMixins.js +79 -205
- package/lib/pools/mixins/poolBalancesMixin.js +24 -87
- package/lib/pools/mixins/swapMixins.js +139 -324
- package/lib/pools/mixins/swapWrappedMixins.js +111 -265
- package/lib/pools/mixins/withdrawExpectedMixins.js +27 -91
- package/lib/pools/mixins/withdrawImbalanceMixins.js +111 -293
- package/lib/pools/mixins/withdrawImbalanceWrappedMixins.js +58 -169
- package/lib/pools/mixins/withdrawMixins.js +139 -359
- package/lib/pools/mixins/withdrawOneCoinExpectedMixins.js +20 -75
- package/lib/pools/mixins/withdrawOneCoinMixins.js +140 -360
- package/lib/pools/mixins/withdrawOneCoinWrappedExpectedMixins.js +10 -51
- package/lib/pools/mixins/withdrawOneCoinWrappedMixins.js +60 -167
- package/lib/pools/mixins/withdrawWrappedMixins.js +57 -167
- package/lib/pools/poolConstructor.js +5 -25
- package/lib/pools/utils.js +301 -469
- package/lib/route-finder.worker.d.ts +9 -0
- package/lib/route-finder.worker.js +112 -0
- package/lib/route-graph.worker.d.ts +11 -0
- package/lib/route-graph.worker.js +334 -0
- package/lib/router.js +323 -912
- package/lib/utils.d.ts +5 -4
- package/lib/utils.js +539 -906
- package/package.json +1 -1
|
@@ -7,325 +7,207 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
|
|
|
7
7
|
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
8
8
|
});
|
|
9
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
10
|
import { curve } from "../curve.js";
|
|
47
11
|
import ERC20ABI from "../constants/abis/ERC20.json" assert { type: 'json' };
|
|
48
12
|
import twocryptoFactorySwapABI from "../constants/abis/factory-twocrypto/factory-twocrypto-pool.json" assert { type: 'json' };
|
|
49
13
|
import factoryGaugeABI from "../constants/abis/gauge_factory.json" assert { type: 'json' };
|
|
50
14
|
import gaugeChildABI from "../constants/abis/gauge_child.json" assert { type: 'json' };
|
|
51
|
-
|
|
15
|
+
const deepFlatten = (arr) => [].concat(...arr.map((v) => (Array.isArray(v) ? deepFlatten(v) : v)));
|
|
52
16
|
function getRecentlyCreatedCryptoPoolId(swapAddress) {
|
|
53
|
-
return __awaiter(this, void 0, void 0, function () {
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
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-twocrypto-".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
|
-
});
|
|
17
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
18
|
+
const factoryContract = this.contracts[this.constants.ALIASES.twocrypto_factory].contract;
|
|
19
|
+
const poolCount = Number(curve.formatUnits(yield factoryContract.pool_count(this.constantOptions), 0));
|
|
20
|
+
for (let i = 1; i <= poolCount; i++) {
|
|
21
|
+
const address = yield factoryContract.pool_list(poolCount - i);
|
|
22
|
+
if (address.toLowerCase() === swapAddress.toLowerCase())
|
|
23
|
+
return `factory-twocrypto-${poolCount - i}`;
|
|
24
|
+
}
|
|
25
|
+
throw Error("Unknown pool");
|
|
80
26
|
});
|
|
81
27
|
}
|
|
82
|
-
function getTwocryptoFactoryIdsAndSwapAddresses(fromIdx) {
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
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-twocrypto-".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
|
-
});
|
|
28
|
+
function getTwocryptoFactoryIdsAndSwapAddresses(fromIdx = 0) {
|
|
29
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
30
|
+
const factoryContract = this.contracts[this.constants.ALIASES.twocrypto_factory].contract;
|
|
31
|
+
const factoryMulticallContract = this.contracts[this.constants.ALIASES.twocrypto_factory].multicallContract;
|
|
32
|
+
const poolCount = Number(curve.formatUnits(yield factoryContract.pool_count(this.constantOptions), 0));
|
|
33
|
+
const calls = [];
|
|
34
|
+
for (let i = fromIdx; i < poolCount; i++) {
|
|
35
|
+
calls.push(factoryMulticallContract.pool_list(i));
|
|
36
|
+
}
|
|
37
|
+
if (calls.length === 0)
|
|
38
|
+
return [[], []];
|
|
39
|
+
let factories = (yield this.multicallProvider.all(calls)).map((addr, i) => ({ id: `factory-twocrypto-${fromIdx + i}`, address: addr.toLowerCase() }));
|
|
40
|
+
const swapAddresses = Object.values(this.constants.POOLS_DATA).map((pool) => pool.swap_address.toLowerCase());
|
|
41
|
+
factories = factories.filter((f) => !swapAddresses.includes(f.address));
|
|
42
|
+
return [factories.map((f) => f.id), factories.map((f) => f.address)];
|
|
110
43
|
});
|
|
111
44
|
}
|
|
112
45
|
function _handleCoinAddresses(coinAddresses) {
|
|
113
|
-
|
|
114
|
-
return coinAddresses.map(function (addresses) { return addresses.map(function (addr) { return _this.chainId === 137 && addr === "0x0000000000000000000000000000000000001010" ? _this.constants.NATIVE_TOKEN.wrappedAddress : addr.toLowerCase(); }); });
|
|
46
|
+
return coinAddresses.map((addresses) => addresses.map((addr) => this.chainId === 137 && addr === "0x0000000000000000000000000000000000001010" ? this.constants.NATIVE_TOKEN.wrappedAddress : addr.toLowerCase()));
|
|
115
47
|
}
|
|
116
48
|
function getPoolsData(factorySwapAddresses) {
|
|
117
|
-
return __awaiter(this, void 0, void 0, function () {
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
calls = [];
|
|
125
|
-
for (_i = 0, factorySwapAddresses_1 = factorySwapAddresses; _i < factorySwapAddresses_1.length; _i++) {
|
|
126
|
-
addr = factorySwapAddresses_1[_i];
|
|
127
|
-
calls.push(factoryMulticallContract.get_gauge(addr));
|
|
128
|
-
calls.push(factoryMulticallContract.get_coins(addr));
|
|
129
|
-
}
|
|
130
|
-
return [4 /*yield*/, this.multicallProvider.all(calls)];
|
|
131
|
-
case 1:
|
|
132
|
-
res = _b.sent();
|
|
133
|
-
gaugeAddresses = res.filter(function (a, i) { return i % 2 == 0; }).map(function (a) { return a.toLowerCase(); });
|
|
134
|
-
coinAddresses = _handleCoinAddresses.call(this, res.filter(function (a, i) { return i % 2 == 1; }));
|
|
135
|
-
return [2 /*return*/, [gaugeAddresses, coinAddresses]];
|
|
136
|
-
case 2:
|
|
137
|
-
factoryMulticallContract = this.contracts[this.constants.ALIASES.twocrypto_factory].multicallContract;
|
|
138
|
-
isFactoryGaugeNull = this.constants.ALIASES.gauge_factory === '0x0000000000000000000000000000000000000000';
|
|
139
|
-
factoryMulticallGaugeContract = this.contracts[this.constants.ALIASES.gauge_factory].multicallContract;
|
|
140
|
-
calls = [];
|
|
141
|
-
for (_a = 0, factorySwapAddresses_2 = factorySwapAddresses; _a < factorySwapAddresses_2.length; _a++) {
|
|
142
|
-
addr = factorySwapAddresses_2[_a];
|
|
143
|
-
if (!isFactoryGaugeNull) {
|
|
144
|
-
calls.push(factoryMulticallGaugeContract.get_gauge_from_lp_token(addr));
|
|
145
|
-
}
|
|
146
|
-
calls.push(factoryMulticallContract.get_coins(addr));
|
|
147
|
-
}
|
|
148
|
-
return [4 /*yield*/, this.multicallProvider.all(calls)];
|
|
149
|
-
case 3:
|
|
150
|
-
res = _b.sent();
|
|
151
|
-
if (!isFactoryGaugeNull) {
|
|
152
|
-
gaugeAddresses = res.filter(function (a, i) { return i % 2 == 0; }).map(function (a) { return a.toLowerCase(); });
|
|
153
|
-
coinAddresses = _handleCoinAddresses.call(this, res.filter(function (a, i) { return i % 2 == 1; }));
|
|
154
|
-
return [2 /*return*/, [gaugeAddresses, coinAddresses]];
|
|
155
|
-
}
|
|
156
|
-
else {
|
|
157
|
-
coinAddresses = _handleCoinAddresses.call(this, res.filter(function (a, i) { return i % 2 == 0; }));
|
|
158
|
-
gaugeAddresses = Array.from(Array(factorySwapAddresses.length)).map(function () { return '0x0000000000000000000000000000000000000000'; });
|
|
159
|
-
return [2 /*return*/, [gaugeAddresses, coinAddresses]];
|
|
160
|
-
}
|
|
161
|
-
_b.label = 4;
|
|
162
|
-
case 4: return [2 /*return*/];
|
|
49
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
50
|
+
if (this.chainId === 1) {
|
|
51
|
+
const factoryMulticallContract = this.contracts[this.constants.ALIASES.twocrypto_factory].multicallContract;
|
|
52
|
+
const calls = [];
|
|
53
|
+
for (const addr of factorySwapAddresses) {
|
|
54
|
+
calls.push(factoryMulticallContract.get_gauge(addr));
|
|
55
|
+
calls.push(factoryMulticallContract.get_coins(addr));
|
|
163
56
|
}
|
|
164
|
-
|
|
57
|
+
const res = yield this.multicallProvider.all(calls);
|
|
58
|
+
const gaugeAddresses = res.filter((a, i) => i % 2 == 0).map((a) => a.toLowerCase());
|
|
59
|
+
const coinAddresses = _handleCoinAddresses.call(this, res.filter((a, i) => i % 2 == 1));
|
|
60
|
+
return [gaugeAddresses, coinAddresses];
|
|
61
|
+
}
|
|
62
|
+
else {
|
|
63
|
+
const factoryMulticallContract = this.contracts[this.constants.ALIASES.twocrypto_factory].multicallContract;
|
|
64
|
+
const isFactoryGaugeNull = this.constants.ALIASES.gauge_factory === '0x0000000000000000000000000000000000000000';
|
|
65
|
+
const factoryMulticallGaugeContract = this.contracts[this.constants.ALIASES.gauge_factory].multicallContract;
|
|
66
|
+
const calls = [];
|
|
67
|
+
for (const addr of factorySwapAddresses) {
|
|
68
|
+
if (!isFactoryGaugeNull) {
|
|
69
|
+
calls.push(factoryMulticallGaugeContract.get_gauge_from_lp_token(addr));
|
|
70
|
+
}
|
|
71
|
+
calls.push(factoryMulticallContract.get_coins(addr));
|
|
72
|
+
}
|
|
73
|
+
const res = yield this.multicallProvider.all(calls);
|
|
74
|
+
if (!isFactoryGaugeNull) {
|
|
75
|
+
const gaugeAddresses = res.filter((a, i) => i % 2 == 0).map((a) => a.toLowerCase());
|
|
76
|
+
const coinAddresses = _handleCoinAddresses.call(this, res.filter((a, i) => i % 2 == 1));
|
|
77
|
+
return [gaugeAddresses, coinAddresses];
|
|
78
|
+
}
|
|
79
|
+
else {
|
|
80
|
+
const coinAddresses = _handleCoinAddresses.call(this, res.filter((a, i) => i % 2 == 0));
|
|
81
|
+
const gaugeAddresses = Array.from(Array(factorySwapAddresses.length)).map(() => '0x0000000000000000000000000000000000000000');
|
|
82
|
+
return [gaugeAddresses, coinAddresses];
|
|
83
|
+
}
|
|
84
|
+
}
|
|
165
85
|
});
|
|
166
86
|
}
|
|
167
87
|
function setTwocryptoFactorySwapContracts(factorySwapAddresses) {
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
_this.setContract(addr, twocryptoFactorySwapABI);
|
|
88
|
+
factorySwapAddresses.forEach((addr) => {
|
|
89
|
+
this.setContract(addr, twocryptoFactorySwapABI);
|
|
171
90
|
});
|
|
172
91
|
}
|
|
173
92
|
function setTwocryptoFactoryTokenContracts(factoryTokenAddresses) {
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
_this.setContract(addr, ERC20ABI);
|
|
93
|
+
factoryTokenAddresses.forEach((addr) => {
|
|
94
|
+
this.setContract(addr, ERC20ABI);
|
|
177
95
|
});
|
|
178
96
|
}
|
|
179
97
|
function setTwocryptoFactoryGaugeContracts(factoryGaugeAddresses) {
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
_this.setContract(addr, _this.chainId === 1 ? factoryGaugeABI : gaugeChildABI);
|
|
98
|
+
factoryGaugeAddresses.filter((addr) => addr !== curve.constants.ZERO_ADDRESS).forEach((addr, i) => {
|
|
99
|
+
this.setContract(addr, this.chainId === 1 ? factoryGaugeABI : gaugeChildABI);
|
|
183
100
|
});
|
|
184
101
|
}
|
|
185
102
|
function setTwocryptoFactoryCoinsContracts(coinAddresses) {
|
|
186
|
-
|
|
187
|
-
for (
|
|
188
|
-
var addr = flattenedCoinAddresses_1[_i];
|
|
103
|
+
const flattenedCoinAddresses = Array.from(new Set(deepFlatten(coinAddresses)));
|
|
104
|
+
for (const addr of flattenedCoinAddresses) {
|
|
189
105
|
if (addr in this.contracts)
|
|
190
106
|
continue;
|
|
191
107
|
this.setContract(addr, ERC20ABI);
|
|
192
108
|
}
|
|
193
109
|
}
|
|
194
110
|
function getTwocryptoFactoryUnderlyingCoinAddresses(coinAddresses) {
|
|
195
|
-
return
|
|
111
|
+
return [...coinAddresses.map((coins) => coins.map((c) => c))];
|
|
196
112
|
}
|
|
197
113
|
function getExistingCoinAddressNameDict() {
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
poolData.wrapped_coin_addresses.forEach(
|
|
114
|
+
const dict = {};
|
|
115
|
+
for (const poolData of Object.values(this.constants.POOLS_DATA)) {
|
|
116
|
+
poolData.wrapped_coin_addresses.forEach((addr, i) => {
|
|
201
117
|
if (!(addr.toLowerCase() in dict)) {
|
|
202
118
|
dict[addr.toLowerCase()] = poolData.wrapped_coins[i];
|
|
203
119
|
}
|
|
204
120
|
});
|
|
205
|
-
poolData.underlying_coin_addresses.forEach(
|
|
121
|
+
poolData.underlying_coin_addresses.forEach((addr, i) => {
|
|
206
122
|
if (!(addr.toLowerCase() in dict)) {
|
|
207
123
|
dict[addr.toLowerCase()] = poolData.underlying_coins[i];
|
|
208
124
|
}
|
|
209
125
|
});
|
|
210
|
-
};
|
|
211
|
-
for (var _i = 0, _a = Object.values(this.constants.POOLS_DATA); _i < _a.length; _i++) {
|
|
212
|
-
var poolData = _a[_i];
|
|
213
|
-
_loop_1(poolData);
|
|
214
126
|
}
|
|
215
127
|
dict[this.constants.NATIVE_TOKEN.address] = this.constants.NATIVE_TOKEN.symbol;
|
|
216
128
|
return dict;
|
|
217
129
|
}
|
|
218
130
|
function getCoinsData(tokenAddresses, coinAddresses, existingCoinAddrNameDict, existingCoinAddrDecimalsDict) {
|
|
219
|
-
return __awaiter(this, void 0, void 0, function () {
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
else if (addr === "0x9f8f72aa9304c8b593d555f12ef6589cc3a579a2") {
|
|
235
|
-
coinAddrNamesDict[addr] = "MKR";
|
|
236
|
-
}
|
|
237
|
-
else {
|
|
238
|
-
newCoinAddresses.push(addr);
|
|
239
|
-
}
|
|
240
|
-
}
|
|
241
|
-
calls = [];
|
|
242
|
-
for (_a = 0, tokenAddresses_1 = tokenAddresses; _a < tokenAddresses_1.length; _a++) {
|
|
243
|
-
addr = tokenAddresses_1[_a];
|
|
244
|
-
calls.push(this.contracts[addr].multicallContract.symbol());
|
|
245
|
-
calls.push(this.contracts[addr].multicallContract.name());
|
|
246
|
-
}
|
|
247
|
-
for (_b = 0, newCoinAddresses_1 = newCoinAddresses; _b < newCoinAddresses_1.length; _b++) {
|
|
248
|
-
addr = newCoinAddresses_1[_b];
|
|
249
|
-
calls.push(this.contracts[addr].multicallContract.symbol());
|
|
250
|
-
calls.push(this.contracts[addr].multicallContract.decimals());
|
|
251
|
-
}
|
|
252
|
-
return [4 /*yield*/, this.multicallProvider.all(calls)];
|
|
253
|
-
case 1:
|
|
254
|
-
res = _c.sent();
|
|
255
|
-
res1 = res.slice(0, tokenAddresses.length * 2);
|
|
256
|
-
tokenSymbols = res1.filter(function (a, i) { return i % 2 == 0; });
|
|
257
|
-
tokenNames = res1.filter(function (a, i) { return i % 2 == 1; });
|
|
258
|
-
res2 = res.slice(tokenAddresses.length * 2);
|
|
259
|
-
symbols = res2.filter(function (a, i) { return i % 2 == 0; });
|
|
260
|
-
decimals = res2.filter(function (a, i) { return i % 2 == 1; }).map(function (_d) { return Number(curve.formatUnits(_d, 0)); });
|
|
261
|
-
newCoinAddresses.forEach(function (addr, i) {
|
|
262
|
-
coinAddrNamesDict[addr] = symbols[i];
|
|
263
|
-
coinAddrDecimalsDict[addr] = decimals[i];
|
|
264
|
-
});
|
|
265
|
-
coinAddrNamesDict[this.constants.NATIVE_TOKEN.address] = this.constants.NATIVE_TOKEN.symbol;
|
|
266
|
-
coinAddrDecimalsDict[this.constants.NATIVE_TOKEN.address] = 18;
|
|
267
|
-
return [2 /*return*/, [tokenSymbols, tokenNames, coinAddrNamesDict, coinAddrDecimalsDict]];
|
|
131
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
132
|
+
const flattenedCoinAddresses = Array.from(new Set(deepFlatten(coinAddresses)));
|
|
133
|
+
const newCoinAddresses = [];
|
|
134
|
+
const coinAddrNamesDict = {};
|
|
135
|
+
const coinAddrDecimalsDict = {};
|
|
136
|
+
for (const addr of flattenedCoinAddresses) {
|
|
137
|
+
if (addr in existingCoinAddrNameDict) {
|
|
138
|
+
coinAddrNamesDict[addr] = existingCoinAddrNameDict[addr];
|
|
139
|
+
coinAddrDecimalsDict[addr] = existingCoinAddrDecimalsDict[addr];
|
|
140
|
+
}
|
|
141
|
+
else if (addr === "0x9f8f72aa9304c8b593d555f12ef6589cc3a579a2") {
|
|
142
|
+
coinAddrNamesDict[addr] = "MKR";
|
|
143
|
+
}
|
|
144
|
+
else {
|
|
145
|
+
newCoinAddresses.push(addr);
|
|
268
146
|
}
|
|
147
|
+
}
|
|
148
|
+
const calls = [];
|
|
149
|
+
for (const addr of tokenAddresses) {
|
|
150
|
+
calls.push(this.contracts[addr].multicallContract.symbol());
|
|
151
|
+
calls.push(this.contracts[addr].multicallContract.name());
|
|
152
|
+
}
|
|
153
|
+
for (const addr of newCoinAddresses) {
|
|
154
|
+
calls.push(this.contracts[addr].multicallContract.symbol());
|
|
155
|
+
calls.push(this.contracts[addr].multicallContract.decimals());
|
|
156
|
+
}
|
|
157
|
+
const res = yield this.multicallProvider.all(calls);
|
|
158
|
+
const res1 = res.slice(0, tokenAddresses.length * 2);
|
|
159
|
+
const tokenSymbols = res1.filter((a, i) => i % 2 == 0);
|
|
160
|
+
const tokenNames = res1.filter((a, i) => i % 2 == 1);
|
|
161
|
+
const res2 = res.slice(tokenAddresses.length * 2);
|
|
162
|
+
const symbols = res2.filter((a, i) => i % 2 == 0);
|
|
163
|
+
const decimals = res2.filter((a, i) => i % 2 == 1).map((_d) => Number(curve.formatUnits(_d, 0)));
|
|
164
|
+
newCoinAddresses.forEach((addr, i) => {
|
|
165
|
+
coinAddrNamesDict[addr] = symbols[i];
|
|
166
|
+
coinAddrDecimalsDict[addr] = decimals[i];
|
|
269
167
|
});
|
|
168
|
+
coinAddrNamesDict[this.constants.NATIVE_TOKEN.address] = this.constants.NATIVE_TOKEN.symbol;
|
|
169
|
+
coinAddrDecimalsDict[this.constants.NATIVE_TOKEN.address] = 18;
|
|
170
|
+
return [tokenSymbols, tokenNames, coinAddrNamesDict, coinAddrDecimalsDict];
|
|
270
171
|
});
|
|
271
172
|
}
|
|
272
|
-
export function getTwocryptoFactoryPoolData(fromIdx, swapAddress) {
|
|
273
|
-
|
|
274
|
-
|
|
275
|
-
|
|
276
|
-
|
|
277
|
-
|
|
278
|
-
|
|
279
|
-
|
|
280
|
-
|
|
281
|
-
|
|
282
|
-
|
|
283
|
-
|
|
284
|
-
|
|
285
|
-
|
|
286
|
-
|
|
287
|
-
|
|
288
|
-
|
|
289
|
-
|
|
290
|
-
|
|
291
|
-
|
|
292
|
-
|
|
293
|
-
|
|
294
|
-
|
|
295
|
-
|
|
296
|
-
|
|
297
|
-
|
|
298
|
-
|
|
299
|
-
|
|
300
|
-
|
|
301
|
-
|
|
302
|
-
|
|
303
|
-
|
|
304
|
-
|
|
305
|
-
|
|
306
|
-
|
|
307
|
-
|
|
308
|
-
|
|
309
|
-
|
|
310
|
-
|
|
311
|
-
token_address: swapAddresses[i],
|
|
312
|
-
gauge_address: gaugeAddresses[i],
|
|
313
|
-
is_crypto: true,
|
|
314
|
-
is_plain: underlyingCoinAddresses[i].toString() === coinAddresses[i].toString(),
|
|
315
|
-
is_factory: true,
|
|
316
|
-
underlying_coins: __spreadArray([], underlyingCoinAddresses[i].map(function (addr) { return coinAddressNameDict[addr]; }), true),
|
|
317
|
-
wrapped_coins: __spreadArray([], coinAddresses[i].map(function (addr) { return coinAddressNameDict[addr]; }), true),
|
|
318
|
-
underlying_coin_addresses: underlyingCoinAddresses[i],
|
|
319
|
-
wrapped_coin_addresses: coinAddresses[i],
|
|
320
|
-
underlying_decimals: __spreadArray([], underlyingCoinAddresses[i].map(function (addr) { return coinAddressDecimalsDict[addr]; }), true),
|
|
321
|
-
wrapped_decimals: __spreadArray([], coinAddresses[i].map(function (addr) { return coinAddressDecimalsDict[addr]; }), true),
|
|
322
|
-
swap_abi: twocryptoFactorySwapABI,
|
|
323
|
-
gauge_abi: this.chainId === 1 ? factoryGaugeABI : gaugeChildABI,
|
|
324
|
-
is_ng: true,
|
|
325
|
-
};
|
|
326
|
-
}
|
|
327
|
-
return [2 /*return*/, TWOCRYPTO_FACTORY_POOLS_DATA];
|
|
328
|
-
}
|
|
329
|
-
});
|
|
173
|
+
export function getTwocryptoFactoryPoolData(fromIdx = 0, swapAddress) {
|
|
174
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
175
|
+
const [poolIds, swapAddresses] = swapAddress ?
|
|
176
|
+
[[yield getRecentlyCreatedCryptoPoolId.call(this, swapAddress)], [swapAddress.toLowerCase()]]
|
|
177
|
+
: yield getTwocryptoFactoryIdsAndSwapAddresses.call(this, fromIdx);
|
|
178
|
+
if (poolIds.length === 0)
|
|
179
|
+
return {};
|
|
180
|
+
const [gaugeAddresses, coinAddresses] = yield getPoolsData.call(this, swapAddresses);
|
|
181
|
+
setTwocryptoFactorySwapContracts.call(this, swapAddresses);
|
|
182
|
+
setTwocryptoFactoryGaugeContracts.call(this, gaugeAddresses);
|
|
183
|
+
setTwocryptoFactoryCoinsContracts.call(this, coinAddresses);
|
|
184
|
+
const underlyingCoinAddresses = getTwocryptoFactoryUnderlyingCoinAddresses.call(this, coinAddresses);
|
|
185
|
+
const existingCoinAddressNameDict = getExistingCoinAddressNameDict.call(this);
|
|
186
|
+
const [poolSymbols, poolNames, coinAddressNameDict, coinAddressDecimalsDict] = yield getCoinsData.call(this, swapAddresses, coinAddresses, existingCoinAddressNameDict, this.constants.DECIMALS);
|
|
187
|
+
const TWOCRYPTO_FACTORY_POOLS_DATA = {};
|
|
188
|
+
for (let i = 0; i < poolIds.length; i++) {
|
|
189
|
+
TWOCRYPTO_FACTORY_POOLS_DATA[poolIds[i]] = {
|
|
190
|
+
name: poolNames[i],
|
|
191
|
+
full_name: poolNames[i],
|
|
192
|
+
symbol: poolSymbols[i],
|
|
193
|
+
reference_asset: "CRYPTO",
|
|
194
|
+
swap_address: swapAddresses[i],
|
|
195
|
+
token_address: swapAddresses[i],
|
|
196
|
+
gauge_address: gaugeAddresses[i],
|
|
197
|
+
is_crypto: true,
|
|
198
|
+
is_plain: underlyingCoinAddresses[i].toString() === coinAddresses[i].toString(),
|
|
199
|
+
is_factory: true,
|
|
200
|
+
underlying_coins: [...underlyingCoinAddresses[i].map((addr) => coinAddressNameDict[addr])],
|
|
201
|
+
wrapped_coins: [...coinAddresses[i].map((addr) => coinAddressNameDict[addr])],
|
|
202
|
+
underlying_coin_addresses: underlyingCoinAddresses[i],
|
|
203
|
+
wrapped_coin_addresses: coinAddresses[i],
|
|
204
|
+
underlying_decimals: [...underlyingCoinAddresses[i].map((addr) => coinAddressDecimalsDict[addr])],
|
|
205
|
+
wrapped_decimals: [...coinAddresses[i].map((addr) => coinAddressDecimalsDict[addr])],
|
|
206
|
+
swap_abi: twocryptoFactorySwapABI,
|
|
207
|
+
gauge_abi: this.chainId === 1 ? factoryGaugeABI : gaugeChildABI,
|
|
208
|
+
is_ng: true,
|
|
209
|
+
};
|
|
210
|
+
}
|
|
211
|
+
return TWOCRYPTO_FACTORY_POOLS_DATA;
|
|
330
212
|
});
|
|
331
213
|
}
|