@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,341 +7,219 @@ 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 tricryptoFactorySwapABI from "../constants/abis/factory-tricrypto/factory-tricrypto-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
|
import { tricryptoDeployImplementations } from "../constants/tricryptoDeployImplementations.js";
|
|
52
|
-
|
|
16
|
+
const deepFlatten = (arr) => [].concat(...arr.map((v) => (Array.isArray(v) ? deepFlatten(v) : v)));
|
|
53
17
|
function getRecentlyCreatedCryptoPoolId(swapAddress) {
|
|
54
|
-
return __awaiter(this, void 0, void 0, function () {
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
case 1:
|
|
64
|
-
poolCount = _a.apply(void 0, [_c.apply(_b, [_e.sent(), 0])]);
|
|
65
|
-
i = 1;
|
|
66
|
-
_e.label = 2;
|
|
67
|
-
case 2:
|
|
68
|
-
if (!(i <= poolCount)) return [3 /*break*/, 5];
|
|
69
|
-
return [4 /*yield*/, factoryContract.pool_list(poolCount - i)];
|
|
70
|
-
case 3:
|
|
71
|
-
address = _e.sent();
|
|
72
|
-
if (address.toLowerCase() === swapAddress.toLowerCase())
|
|
73
|
-
return [2 /*return*/, "factory-tricrypto-".concat(poolCount - i)];
|
|
74
|
-
_e.label = 4;
|
|
75
|
-
case 4:
|
|
76
|
-
i++;
|
|
77
|
-
return [3 /*break*/, 2];
|
|
78
|
-
case 5: throw Error("Unknown pool");
|
|
79
|
-
}
|
|
80
|
-
});
|
|
18
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
19
|
+
const factoryContract = this.contracts[this.constants.ALIASES.tricrypto_factory].contract;
|
|
20
|
+
const poolCount = Number(curve.formatUnits(yield factoryContract.pool_count(this.constantOptions), 0));
|
|
21
|
+
for (let i = 1; i <= poolCount; i++) {
|
|
22
|
+
const address = yield factoryContract.pool_list(poolCount - i);
|
|
23
|
+
if (address.toLowerCase() === swapAddress.toLowerCase())
|
|
24
|
+
return `factory-tricrypto-${poolCount - i}`;
|
|
25
|
+
}
|
|
26
|
+
throw Error("Unknown pool");
|
|
81
27
|
});
|
|
82
28
|
}
|
|
83
|
-
function getCryptoFactoryIdsAndSwapAddresses(fromIdx) {
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
for (i = fromIdx; i < poolCount; i++) {
|
|
99
|
-
calls.push(factoryMulticallContract.pool_list(i));
|
|
100
|
-
}
|
|
101
|
-
if (calls.length === 0)
|
|
102
|
-
return [2 /*return*/, [[], []]];
|
|
103
|
-
return [4 /*yield*/, this.multicallProvider.all(calls)];
|
|
104
|
-
case 2:
|
|
105
|
-
factories = (_e.sent()).map(function (addr, i) { return ({ id: "factory-tricrypto-".concat(fromIdx + i), address: addr.toLowerCase() }); });
|
|
106
|
-
swapAddresses = Object.values(this.constants.POOLS_DATA).map(function (pool) { return pool.swap_address.toLowerCase(); });
|
|
107
|
-
factories = factories.filter(function (f) { return !swapAddresses.includes(f.address); });
|
|
108
|
-
return [2 /*return*/, [factories.map(function (f) { return f.id; }), factories.map(function (f) { return f.address; })]];
|
|
109
|
-
}
|
|
110
|
-
});
|
|
29
|
+
function getCryptoFactoryIdsAndSwapAddresses(fromIdx = 0) {
|
|
30
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
31
|
+
const factoryContract = this.contracts[this.constants.ALIASES.tricrypto_factory].contract;
|
|
32
|
+
const factoryMulticallContract = this.contracts[this.constants.ALIASES.tricrypto_factory].multicallContract;
|
|
33
|
+
const poolCount = Number(curve.formatUnits(yield factoryContract.pool_count(this.constantOptions), 0));
|
|
34
|
+
const calls = [];
|
|
35
|
+
for (let i = fromIdx; i < poolCount; i++) {
|
|
36
|
+
calls.push(factoryMulticallContract.pool_list(i));
|
|
37
|
+
}
|
|
38
|
+
if (calls.length === 0)
|
|
39
|
+
return [[], []];
|
|
40
|
+
let factories = (yield this.multicallProvider.all(calls)).map((addr, i) => ({ id: `factory-tricrypto-${fromIdx + i}`, address: addr.toLowerCase() }));
|
|
41
|
+
const swapAddresses = Object.values(this.constants.POOLS_DATA).map((pool) => pool.swap_address.toLowerCase());
|
|
42
|
+
factories = factories.filter((f) => !swapAddresses.includes(f.address));
|
|
43
|
+
return [factories.map((f) => f.id), factories.map((f) => f.address)];
|
|
111
44
|
});
|
|
112
45
|
}
|
|
113
46
|
function _handleCoinAddresses(coinAddresses) {
|
|
114
|
-
|
|
115
|
-
return coinAddresses.map(function (addresses) { return addresses.map(function (addr) { return _this.chainId === 137 && addr === "0x0000000000000000000000000000000000001010" ? _this.constants.NATIVE_TOKEN.wrappedAddress : addr.toLowerCase(); }); });
|
|
47
|
+
return coinAddresses.map((addresses) => addresses.map((addr) => this.chainId === 137 && addr === "0x0000000000000000000000000000000000001010" ? this.constants.NATIVE_TOKEN.wrappedAddress : addr.toLowerCase()));
|
|
116
48
|
}
|
|
117
49
|
function getPoolsData(factorySwapAddresses) {
|
|
118
|
-
return __awaiter(this, void 0, void 0, function () {
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
for (_i = 0, factorySwapAddresses_1 = factorySwapAddresses; _i < factorySwapAddresses_1.length; _i++) {
|
|
127
|
-
addr = factorySwapAddresses_1[_i];
|
|
128
|
-
calls.push(factoryMulticallContract.get_gauge(addr));
|
|
129
|
-
calls.push(factoryMulticallContract.get_coins(addr));
|
|
130
|
-
calls.push(factoryMulticallContract.get_implementation_address(addr));
|
|
131
|
-
}
|
|
132
|
-
return [4 /*yield*/, this.multicallProvider.all(calls)];
|
|
133
|
-
case 1:
|
|
134
|
-
res = _b.sent();
|
|
135
|
-
gaugeAddresses = res.filter(function (a, i) { return i % 3 == 0; }).map(function (a) { return a.toLowerCase(); });
|
|
136
|
-
coinAddresses = _handleCoinAddresses.call(this, res.filter(function (a, i) { return i % 3 == 1; }));
|
|
137
|
-
implementationAddresses = res.filter(function (a, i) { return i % 3 == 2; }).map(function (a) { return a.toLowerCase(); });
|
|
138
|
-
return [2 /*return*/, [gaugeAddresses, coinAddresses, implementationAddresses]];
|
|
139
|
-
case 2:
|
|
140
|
-
factoryMulticallContract = this.contracts[this.constants.ALIASES.tricrypto_factory].multicallContract;
|
|
141
|
-
isFactoryGaugeNull = this.constants.ALIASES.gauge_factory === '0x0000000000000000000000000000000000000000';
|
|
142
|
-
factoryMulticallGaugeContract = this.contracts[this.constants.ALIASES.gauge_factory].multicallContract;
|
|
143
|
-
calls = [];
|
|
144
|
-
for (_a = 0, factorySwapAddresses_2 = factorySwapAddresses; _a < factorySwapAddresses_2.length; _a++) {
|
|
145
|
-
addr = factorySwapAddresses_2[_a];
|
|
146
|
-
if (!isFactoryGaugeNull) {
|
|
147
|
-
calls.push(factoryMulticallGaugeContract.get_gauge_from_lp_token(addr));
|
|
148
|
-
}
|
|
149
|
-
calls.push(factoryMulticallContract.get_coins(addr));
|
|
150
|
-
calls.push(factoryMulticallContract.get_implementation_address(addr));
|
|
151
|
-
}
|
|
152
|
-
return [4 /*yield*/, this.multicallProvider.all(calls)];
|
|
153
|
-
case 3:
|
|
154
|
-
res = _b.sent();
|
|
155
|
-
if (!isFactoryGaugeNull) {
|
|
156
|
-
gaugeAddresses = res.filter(function (a, i) { return i % 3 == 0; }).map(function (a) { return a.toLowerCase(); });
|
|
157
|
-
coinAddresses = _handleCoinAddresses.call(this, res.filter(function (a, i) { return i % 3 == 1; }));
|
|
158
|
-
implementationAddresses = res.filter(function (a, i) { return i % 3 == 2; }).map(function (a) { return a.toLowerCase(); });
|
|
159
|
-
return [2 /*return*/, [gaugeAddresses, coinAddresses, implementationAddresses]];
|
|
160
|
-
}
|
|
161
|
-
else {
|
|
162
|
-
coinAddresses = _handleCoinAddresses.call(this, res.filter(function (a, i) { return i % 2 == 0; }));
|
|
163
|
-
gaugeAddresses = Array.from(Array(factorySwapAddresses.length)).map(function () { return '0x0000000000000000000000000000000000000000'; });
|
|
164
|
-
implementationAddresses = res.filter(function (a, i) { return i % 2 == 1; }).map(function (a) { return a.toLowerCase(); });
|
|
165
|
-
return [2 /*return*/, [gaugeAddresses, coinAddresses, implementationAddresses]];
|
|
166
|
-
}
|
|
167
|
-
_b.label = 4;
|
|
168
|
-
case 4: return [2 /*return*/];
|
|
50
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
51
|
+
if (this.chainId === 1) {
|
|
52
|
+
const factoryMulticallContract = this.contracts[this.constants.ALIASES.tricrypto_factory].multicallContract;
|
|
53
|
+
const calls = [];
|
|
54
|
+
for (const addr of factorySwapAddresses) {
|
|
55
|
+
calls.push(factoryMulticallContract.get_gauge(addr));
|
|
56
|
+
calls.push(factoryMulticallContract.get_coins(addr));
|
|
57
|
+
calls.push(factoryMulticallContract.get_implementation_address(addr));
|
|
169
58
|
}
|
|
170
|
-
|
|
59
|
+
const res = yield this.multicallProvider.all(calls);
|
|
60
|
+
const gaugeAddresses = res.filter((a, i) => i % 3 == 0).map((a) => a.toLowerCase());
|
|
61
|
+
const coinAddresses = _handleCoinAddresses.call(this, res.filter((a, i) => i % 3 == 1));
|
|
62
|
+
const implementationAddresses = res.filter((a, i) => i % 3 == 2).map((a) => a.toLowerCase());
|
|
63
|
+
return [gaugeAddresses, coinAddresses, implementationAddresses];
|
|
64
|
+
}
|
|
65
|
+
else {
|
|
66
|
+
const factoryMulticallContract = this.contracts[this.constants.ALIASES.tricrypto_factory].multicallContract;
|
|
67
|
+
const isFactoryGaugeNull = this.constants.ALIASES.gauge_factory === '0x0000000000000000000000000000000000000000';
|
|
68
|
+
const factoryMulticallGaugeContract = this.contracts[this.constants.ALIASES.gauge_factory].multicallContract;
|
|
69
|
+
const calls = [];
|
|
70
|
+
for (const addr of factorySwapAddresses) {
|
|
71
|
+
if (!isFactoryGaugeNull) {
|
|
72
|
+
calls.push(factoryMulticallGaugeContract.get_gauge_from_lp_token(addr));
|
|
73
|
+
}
|
|
74
|
+
calls.push(factoryMulticallContract.get_coins(addr));
|
|
75
|
+
calls.push(factoryMulticallContract.get_implementation_address(addr));
|
|
76
|
+
}
|
|
77
|
+
const res = yield this.multicallProvider.all(calls);
|
|
78
|
+
if (!isFactoryGaugeNull) {
|
|
79
|
+
const gaugeAddresses = res.filter((a, i) => i % 3 == 0).map((a) => a.toLowerCase());
|
|
80
|
+
const coinAddresses = _handleCoinAddresses.call(this, res.filter((a, i) => i % 3 == 1));
|
|
81
|
+
const implementationAddresses = res.filter((a, i) => i % 3 == 2).map((a) => a.toLowerCase());
|
|
82
|
+
return [gaugeAddresses, coinAddresses, implementationAddresses];
|
|
83
|
+
}
|
|
84
|
+
else {
|
|
85
|
+
const coinAddresses = _handleCoinAddresses.call(this, res.filter((a, i) => i % 2 == 0));
|
|
86
|
+
const gaugeAddresses = Array.from(Array(factorySwapAddresses.length)).map(() => '0x0000000000000000000000000000000000000000');
|
|
87
|
+
const implementationAddresses = res.filter((a, i) => i % 2 == 1).map((a) => a.toLowerCase());
|
|
88
|
+
return [gaugeAddresses, coinAddresses, implementationAddresses];
|
|
89
|
+
}
|
|
90
|
+
}
|
|
171
91
|
});
|
|
172
92
|
}
|
|
173
93
|
function setCryptoFactorySwapContracts(factorySwapAddresses) {
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
_this.setContract(addr, tricryptoFactorySwapABI);
|
|
94
|
+
factorySwapAddresses.forEach((addr) => {
|
|
95
|
+
this.setContract(addr, tricryptoFactorySwapABI);
|
|
177
96
|
});
|
|
178
97
|
}
|
|
179
98
|
function setCryptoFactoryTokenContracts(factoryTokenAddresses) {
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
_this.setContract(addr, ERC20ABI);
|
|
99
|
+
factoryTokenAddresses.forEach((addr) => {
|
|
100
|
+
this.setContract(addr, ERC20ABI);
|
|
183
101
|
});
|
|
184
102
|
}
|
|
185
103
|
function setCryptoFactoryGaugeContracts(factoryGaugeAddresses) {
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
_this.setContract(addr, _this.chainId === 1 ? factoryGaugeABI : gaugeChildABI);
|
|
104
|
+
factoryGaugeAddresses.filter((addr) => addr !== curve.constants.ZERO_ADDRESS).forEach((addr, i) => {
|
|
105
|
+
this.setContract(addr, this.chainId === 1 ? factoryGaugeABI : gaugeChildABI);
|
|
189
106
|
});
|
|
190
107
|
}
|
|
191
108
|
function setCryptoFactoryCoinsContracts(coinAddresses) {
|
|
192
|
-
|
|
193
|
-
for (
|
|
194
|
-
var addr = flattenedCoinAddresses_1[_i];
|
|
109
|
+
const flattenedCoinAddresses = Array.from(new Set(deepFlatten(coinAddresses)));
|
|
110
|
+
for (const addr of flattenedCoinAddresses) {
|
|
195
111
|
if (addr in this.contracts)
|
|
196
112
|
continue;
|
|
197
113
|
this.setContract(addr, ERC20ABI);
|
|
198
114
|
}
|
|
199
115
|
}
|
|
200
116
|
function getExistingCoinAddressNameDict() {
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
poolData.wrapped_coin_addresses.forEach(
|
|
117
|
+
const dict = {};
|
|
118
|
+
for (const poolData of Object.values(this.constants.POOLS_DATA)) {
|
|
119
|
+
poolData.wrapped_coin_addresses.forEach((addr, i) => {
|
|
204
120
|
if (!(addr.toLowerCase() in dict)) {
|
|
205
121
|
dict[addr.toLowerCase()] = poolData.wrapped_coins[i];
|
|
206
122
|
}
|
|
207
123
|
});
|
|
208
|
-
poolData.underlying_coin_addresses.forEach(
|
|
124
|
+
poolData.underlying_coin_addresses.forEach((addr, i) => {
|
|
209
125
|
if (!(addr.toLowerCase() in dict)) {
|
|
210
126
|
dict[addr.toLowerCase()] = poolData.underlying_coins[i];
|
|
211
127
|
}
|
|
212
128
|
});
|
|
213
|
-
};
|
|
214
|
-
for (var _i = 0, _a = Object.values(this.constants.POOLS_DATA); _i < _a.length; _i++) {
|
|
215
|
-
var poolData = _a[_i];
|
|
216
|
-
_loop_1(poolData);
|
|
217
129
|
}
|
|
218
130
|
dict[this.constants.NATIVE_TOKEN.address] = this.constants.NATIVE_TOKEN.symbol;
|
|
219
131
|
return dict;
|
|
220
132
|
}
|
|
221
133
|
function getCoinsData(tokenAddresses, coinAddresses, existingCoinAddrNameDict, existingCoinAddrDecimalsDict) {
|
|
222
|
-
return __awaiter(this, void 0, void 0, function () {
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
else if (addr === "0x9f8f72aa9304c8b593d555f12ef6589cc3a579a2") {
|
|
238
|
-
coinAddrNamesDict[addr] = "MKR";
|
|
239
|
-
}
|
|
240
|
-
else {
|
|
241
|
-
newCoinAddresses.push(addr);
|
|
242
|
-
}
|
|
243
|
-
}
|
|
244
|
-
calls = [];
|
|
245
|
-
for (_a = 0, tokenAddresses_1 = tokenAddresses; _a < tokenAddresses_1.length; _a++) {
|
|
246
|
-
addr = tokenAddresses_1[_a];
|
|
247
|
-
calls.push(this.contracts[addr].multicallContract.symbol());
|
|
248
|
-
calls.push(this.contracts[addr].multicallContract.name());
|
|
249
|
-
}
|
|
250
|
-
for (_b = 0, newCoinAddresses_1 = newCoinAddresses; _b < newCoinAddresses_1.length; _b++) {
|
|
251
|
-
addr = newCoinAddresses_1[_b];
|
|
252
|
-
calls.push(this.contracts[addr].multicallContract.symbol());
|
|
253
|
-
calls.push(this.contracts[addr].multicallContract.decimals());
|
|
254
|
-
}
|
|
255
|
-
return [4 /*yield*/, this.multicallProvider.all(calls)];
|
|
256
|
-
case 1:
|
|
257
|
-
res = _c.sent();
|
|
258
|
-
res1 = res.slice(0, tokenAddresses.length * 2);
|
|
259
|
-
tokenSymbols = res1.filter(function (a, i) { return i % 2 == 0; });
|
|
260
|
-
tokenNames = res1.filter(function (a, i) { return i % 2 == 1; });
|
|
261
|
-
res2 = res.slice(tokenAddresses.length * 2);
|
|
262
|
-
symbols = res2.filter(function (a, i) { return i % 2 == 0; });
|
|
263
|
-
decimals = res2.filter(function (a, i) { return i % 2 == 1; }).map(function (_d) { return Number(curve.formatUnits(_d, 0)); });
|
|
264
|
-
newCoinAddresses.forEach(function (addr, i) {
|
|
265
|
-
coinAddrNamesDict[addr] = symbols[i];
|
|
266
|
-
coinAddrDecimalsDict[addr] = decimals[i];
|
|
267
|
-
});
|
|
268
|
-
coinAddrNamesDict[this.constants.NATIVE_TOKEN.address] = this.constants.NATIVE_TOKEN.symbol;
|
|
269
|
-
coinAddrDecimalsDict[this.constants.NATIVE_TOKEN.address] = 18;
|
|
270
|
-
return [2 /*return*/, [tokenSymbols, tokenNames, coinAddrNamesDict, coinAddrDecimalsDict]];
|
|
134
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
135
|
+
const flattenedCoinAddresses = Array.from(new Set(deepFlatten(coinAddresses)));
|
|
136
|
+
const newCoinAddresses = [];
|
|
137
|
+
const coinAddrNamesDict = {};
|
|
138
|
+
const coinAddrDecimalsDict = {};
|
|
139
|
+
for (const addr of flattenedCoinAddresses) {
|
|
140
|
+
if (addr in existingCoinAddrNameDict) {
|
|
141
|
+
coinAddrNamesDict[addr] = existingCoinAddrNameDict[addr];
|
|
142
|
+
coinAddrDecimalsDict[addr] = existingCoinAddrDecimalsDict[addr];
|
|
143
|
+
}
|
|
144
|
+
else if (addr === "0x9f8f72aa9304c8b593d555f12ef6589cc3a579a2") {
|
|
145
|
+
coinAddrNamesDict[addr] = "MKR";
|
|
146
|
+
}
|
|
147
|
+
else {
|
|
148
|
+
newCoinAddresses.push(addr);
|
|
271
149
|
}
|
|
150
|
+
}
|
|
151
|
+
const calls = [];
|
|
152
|
+
for (const addr of tokenAddresses) {
|
|
153
|
+
calls.push(this.contracts[addr].multicallContract.symbol());
|
|
154
|
+
calls.push(this.contracts[addr].multicallContract.name());
|
|
155
|
+
}
|
|
156
|
+
for (const addr of newCoinAddresses) {
|
|
157
|
+
calls.push(this.contracts[addr].multicallContract.symbol());
|
|
158
|
+
calls.push(this.contracts[addr].multicallContract.decimals());
|
|
159
|
+
}
|
|
160
|
+
const res = yield this.multicallProvider.all(calls);
|
|
161
|
+
const res1 = res.slice(0, tokenAddresses.length * 2);
|
|
162
|
+
const tokenSymbols = res1.filter((a, i) => i % 2 == 0);
|
|
163
|
+
const tokenNames = res1.filter((a, i) => i % 2 == 1);
|
|
164
|
+
const res2 = res.slice(tokenAddresses.length * 2);
|
|
165
|
+
const symbols = res2.filter((a, i) => i % 2 == 0);
|
|
166
|
+
const decimals = res2.filter((a, i) => i % 2 == 1).map((_d) => Number(curve.formatUnits(_d, 0)));
|
|
167
|
+
newCoinAddresses.forEach((addr, i) => {
|
|
168
|
+
coinAddrNamesDict[addr] = symbols[i];
|
|
169
|
+
coinAddrDecimalsDict[addr] = decimals[i];
|
|
272
170
|
});
|
|
171
|
+
coinAddrNamesDict[this.constants.NATIVE_TOKEN.address] = this.constants.NATIVE_TOKEN.symbol;
|
|
172
|
+
coinAddrDecimalsDict[this.constants.NATIVE_TOKEN.address] = 18;
|
|
173
|
+
return [tokenSymbols, tokenNames, coinAddrNamesDict, coinAddrDecimalsDict];
|
|
273
174
|
});
|
|
274
175
|
}
|
|
275
|
-
export function getTricryptoFactoryPoolData(fromIdx, swapAddress) {
|
|
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
|
-
|
|
312
|
-
|
|
313
|
-
|
|
314
|
-
|
|
315
|
-
|
|
316
|
-
|
|
317
|
-
|
|
318
|
-
|
|
319
|
-
|
|
320
|
-
|
|
321
|
-
|
|
322
|
-
|
|
323
|
-
token_address: swapAddresses[i],
|
|
324
|
-
gauge_address: gaugeAddresses[i],
|
|
325
|
-
is_crypto: true,
|
|
326
|
-
is_plain: underlyingCoinAddresses.toString() === coinAddresses[i].toString(),
|
|
327
|
-
is_factory: true,
|
|
328
|
-
underlying_coins: __spreadArray([], underlyingCoinAddresses.map(function (addr) { return coinAddressNameDict[addr]; }), true),
|
|
329
|
-
wrapped_coins: __spreadArray([], coinAddresses[i].map(function (addr) { return coinAddressNameDict[addr]; }), true),
|
|
330
|
-
underlying_coin_addresses: underlyingCoinAddresses,
|
|
331
|
-
wrapped_coin_addresses: coinAddresses[i],
|
|
332
|
-
underlying_decimals: __spreadArray([], underlyingCoinAddresses.map(function (addr) { return coinAddressDecimalsDict[addr]; }), true),
|
|
333
|
-
wrapped_decimals: __spreadArray([], coinAddresses[i].map(function (addr) { return coinAddressDecimalsDict[addr]; }), true),
|
|
334
|
-
swap_abi: tricryptoFactorySwapABI,
|
|
335
|
-
gauge_abi: this_1.chainId === 1 ? factoryGaugeABI : gaugeChildABI,
|
|
336
|
-
is_ng: true,
|
|
337
|
-
};
|
|
338
|
-
};
|
|
339
|
-
this_1 = this;
|
|
340
|
-
for (i = 0; i < poolIds.length; i++) {
|
|
341
|
-
_loop_2(i);
|
|
342
|
-
}
|
|
343
|
-
return [2 /*return*/, TRICRYPTO_FACTORY_POOLS_DATA];
|
|
344
|
-
}
|
|
345
|
-
});
|
|
176
|
+
export function getTricryptoFactoryPoolData(fromIdx = 0, swapAddress) {
|
|
177
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
178
|
+
const [poolIds, swapAddresses] = swapAddress ?
|
|
179
|
+
[[yield getRecentlyCreatedCryptoPoolId.call(this, swapAddress)], [swapAddress.toLowerCase()]]
|
|
180
|
+
: yield getCryptoFactoryIdsAndSwapAddresses.call(this, fromIdx);
|
|
181
|
+
if (poolIds.length === 0)
|
|
182
|
+
return {};
|
|
183
|
+
const [gaugeAddresses, coinAddresses, implementationAddresses] = yield getPoolsData.call(this, swapAddresses);
|
|
184
|
+
setCryptoFactorySwapContracts.call(this, swapAddresses);
|
|
185
|
+
setCryptoFactoryGaugeContracts.call(this, gaugeAddresses);
|
|
186
|
+
setCryptoFactoryCoinsContracts.call(this, coinAddresses);
|
|
187
|
+
const existingCoinAddressNameDict = getExistingCoinAddressNameDict.call(this);
|
|
188
|
+
const [poolSymbols, poolNames, coinAddressNameDict, coinAddressDecimalsDict] = yield getCoinsData.call(this, swapAddresses, coinAddresses, existingCoinAddressNameDict, this.constants.DECIMALS);
|
|
189
|
+
const TRICRYPTO_FACTORY_POOLS_DATA = {};
|
|
190
|
+
const nativeToken = this.constants.NATIVE_TOKEN;
|
|
191
|
+
for (let i = 0; i < poolIds.length; i++) {
|
|
192
|
+
const underlyingCoinAddresses = coinAddresses[i].map((addr) => {
|
|
193
|
+
const isETHEnabled = implementationAddresses[i] === tricryptoDeployImplementations[curve.chainId].amm_native_transfers_enabled;
|
|
194
|
+
if (isETHEnabled) {
|
|
195
|
+
return addr === nativeToken.wrappedAddress ? nativeToken.address : addr;
|
|
196
|
+
}
|
|
197
|
+
else {
|
|
198
|
+
return addr;
|
|
199
|
+
}
|
|
200
|
+
});
|
|
201
|
+
TRICRYPTO_FACTORY_POOLS_DATA[poolIds[i]] = {
|
|
202
|
+
name: poolNames[i],
|
|
203
|
+
full_name: poolNames[i],
|
|
204
|
+
symbol: poolSymbols[i],
|
|
205
|
+
reference_asset: "CRYPTO",
|
|
206
|
+
swap_address: swapAddresses[i],
|
|
207
|
+
token_address: swapAddresses[i],
|
|
208
|
+
gauge_address: gaugeAddresses[i],
|
|
209
|
+
is_crypto: true,
|
|
210
|
+
is_plain: underlyingCoinAddresses.toString() === coinAddresses[i].toString(),
|
|
211
|
+
is_factory: true,
|
|
212
|
+
underlying_coins: [...underlyingCoinAddresses.map((addr) => coinAddressNameDict[addr])],
|
|
213
|
+
wrapped_coins: [...coinAddresses[i].map((addr) => coinAddressNameDict[addr])],
|
|
214
|
+
underlying_coin_addresses: underlyingCoinAddresses,
|
|
215
|
+
wrapped_coin_addresses: coinAddresses[i],
|
|
216
|
+
underlying_decimals: [...underlyingCoinAddresses.map((addr) => coinAddressDecimalsDict[addr])],
|
|
217
|
+
wrapped_decimals: [...coinAddresses[i].map((addr) => coinAddressDecimalsDict[addr])],
|
|
218
|
+
swap_abi: tricryptoFactorySwapABI,
|
|
219
|
+
gauge_abi: this.chainId === 1 ? factoryGaugeABI : gaugeChildABI,
|
|
220
|
+
is_ng: true,
|
|
221
|
+
};
|
|
222
|
+
}
|
|
223
|
+
return TRICRYPTO_FACTORY_POOLS_DATA;
|
|
346
224
|
});
|
|
347
225
|
}
|