@curvefi/api 2.32.0 → 2.33.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/lib/boosting.js +385 -135
- package/lib/constants/aliases.js +22 -11
- 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/celo.js +5 -5
- package/lib/constants/coins/ethereum.js +10 -9
- package/lib/constants/coins/fantom.js +7 -7
- package/lib/constants/coins/kava.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/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/celo.js +1 -1
- package/lib/constants/pools/ethereum.js +1 -1
- package/lib/constants/pools/fantom.js +1 -1
- package/lib/constants/pools/kava.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/utils.js +19 -18
- package/lib/curve.js +506 -282
- package/lib/external-api.js +132 -45
- package/lib/factory/common.js +3 -3
- package/lib/factory/constants-crypto.js +21 -21
- package/lib/factory/constants.js +32 -31
- package/lib/factory/deploy.js +336 -176
- package/lib/factory/factory-api.js +256 -180
- package/lib/factory/factory-crypto.js +309 -163
- package/lib/factory/factory.d.ts +1 -1
- package/lib/factory/factory.js +336 -186
- package/lib/index.js +98 -44
- package/lib/interfaces.d.ts +5 -0
- package/lib/pools/PoolTemplate.js +2879 -1468
- package/lib/pools/mixins/common.js +106 -22
- package/lib/pools/mixins/depositBalancedAmountsMixins.js +131 -48
- package/lib/pools/mixins/depositMixins.js +413 -144
- package/lib/pools/mixins/depositWrappedMixins.js +223 -72
- package/lib/pools/mixins/poolBalancesMixin.js +98 -22
- package/lib/pools/mixins/swapMixins.js +347 -125
- package/lib/pools/mixins/swapWrappedMixins.js +270 -88
- package/lib/pools/mixins/withdrawExpectedMixins.js +104 -23
- package/lib/pools/mixins/withdrawImbalanceMixins.js +316 -97
- package/lib/pools/mixins/withdrawImbalanceWrappedMixins.js +187 -51
- package/lib/pools/mixins/withdrawMixins.js +385 -122
- package/lib/pools/mixins/withdrawOneCoinExpectedMixins.js +88 -16
- package/lib/pools/mixins/withdrawOneCoinMixins.js +386 -123
- package/lib/pools/mixins/withdrawOneCoinWrappedExpectedMixins.js +62 -8
- package/lib/pools/mixins/withdrawOneCoinWrappedMixins.js +185 -53
- package/lib/pools/mixins/withdrawWrappedMixins.js +185 -50
- package/lib/pools/poolConstructor.js +25 -5
- package/lib/pools/utils.js +488 -299
- package/lib/router.js +675 -212
- package/lib/utils.js +675 -354
- package/package.json +1 -2
package/lib/factory/deploy.js
CHANGED
|
@@ -1,190 +1,350 @@
|
|
|
1
|
+
var __assign = (this && this.__assign) || function () {
|
|
2
|
+
__assign = Object.assign || function(t) {
|
|
3
|
+
for (var s, i = 1, n = arguments.length; i < n; i++) {
|
|
4
|
+
s = arguments[i];
|
|
5
|
+
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p))
|
|
6
|
+
t[p] = s[p];
|
|
7
|
+
}
|
|
8
|
+
return t;
|
|
9
|
+
};
|
|
10
|
+
return __assign.apply(this, arguments);
|
|
11
|
+
};
|
|
12
|
+
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
13
|
+
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
14
|
+
return new (P || (P = Promise))(function (resolve, reject) {
|
|
15
|
+
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
16
|
+
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
17
|
+
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
18
|
+
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
19
|
+
});
|
|
20
|
+
};
|
|
21
|
+
var __generator = (this && this.__generator) || function (thisArg, body) {
|
|
22
|
+
var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g;
|
|
23
|
+
return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
|
|
24
|
+
function verb(n) { return function (v) { return step([n, v]); }; }
|
|
25
|
+
function step(op) {
|
|
26
|
+
if (f) throw new TypeError("Generator is already executing.");
|
|
27
|
+
while (g && (g = 0, op[0] && (_ = 0)), _) try {
|
|
28
|
+
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;
|
|
29
|
+
if (y = 0, t) op = [op[0] & 2, t.value];
|
|
30
|
+
switch (op[0]) {
|
|
31
|
+
case 0: case 1: t = op; break;
|
|
32
|
+
case 4: _.label++; return { value: op[1], done: false };
|
|
33
|
+
case 5: _.label++; y = op[1]; op = [0]; continue;
|
|
34
|
+
case 7: op = _.ops.pop(); _.trys.pop(); continue;
|
|
35
|
+
default:
|
|
36
|
+
if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }
|
|
37
|
+
if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }
|
|
38
|
+
if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }
|
|
39
|
+
if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }
|
|
40
|
+
if (t[2]) _.ops.pop();
|
|
41
|
+
_.trys.pop(); continue;
|
|
42
|
+
}
|
|
43
|
+
op = body.call(thisArg, _);
|
|
44
|
+
} catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }
|
|
45
|
+
if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
|
|
46
|
+
}
|
|
47
|
+
};
|
|
1
48
|
import { Contract } from "ethers";
|
|
2
49
|
import { curve } from "../curve.js";
|
|
3
50
|
import { parseUnits, BN, mulBy1_3 } from "../utils.js";
|
|
4
51
|
import CurveLpTokenV5ABI from "../constants/abis/curve_lp_token_v5.json" assert { type: 'json' };
|
|
5
52
|
// ------- STABLE PLAIN POOLS -------
|
|
6
|
-
|
|
7
|
-
assetType, implementationIdx, estimateGas)
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
53
|
+
var _deployStablePlainPool = function (name, symbol, coins, A, fee, // %
|
|
54
|
+
assetType, implementationIdx, estimateGas) { return __awaiter(void 0, void 0, void 0, function () {
|
|
55
|
+
var _A, _fee, _coins, contract, gas, gasLimit;
|
|
56
|
+
return __generator(this, function (_a) {
|
|
57
|
+
switch (_a.label) {
|
|
58
|
+
case 0:
|
|
59
|
+
if (name.length > 32)
|
|
60
|
+
throw Error("Max name length = 32");
|
|
61
|
+
if (symbol.length > 10)
|
|
62
|
+
throw Error("Max symbol length = 10");
|
|
63
|
+
if (![2, 3, 4].includes(coins.length))
|
|
64
|
+
throw Error("Invalid number of coins. Must be 2, 3 or 4");
|
|
65
|
+
if (BN(fee).lt(0.04))
|
|
66
|
+
throw Error("fee must be >= 0.04%. Passed fee = ".concat(fee));
|
|
67
|
+
if (BN(fee).gt(1))
|
|
68
|
+
throw Error("fee must be <= 1%. Passed fee = ".concat(fee));
|
|
69
|
+
if (![0, 1, 2, 3].includes(assetType))
|
|
70
|
+
throw Error("Invalid assetType. Must be one of: 0 = USD, 1 = ETH, 2 = BTC, 3 = Other");
|
|
71
|
+
if (![0, 1, 2, 3].includes(implementationIdx))
|
|
72
|
+
throw Error("Invalid implementationIdx. Must be one 0, 1, 2 or 3");
|
|
73
|
+
_A = parseUnits(A, 0);
|
|
74
|
+
_fee = parseUnits(fee, 8);
|
|
75
|
+
_coins = coins.concat(Array(4 - coins.length).fill(curve.constants.ZERO_ADDRESS));
|
|
76
|
+
contract = curve.contracts[curve.constants.ALIASES.factory].contract;
|
|
77
|
+
return [4 /*yield*/, contract.deploy_plain_pool.estimateGas(name, symbol, _coins, _A, _fee, assetType, implementationIdx, curve.constantOptions)];
|
|
78
|
+
case 1:
|
|
79
|
+
gas = _a.sent();
|
|
80
|
+
if (estimateGas)
|
|
81
|
+
return [2 /*return*/, Number(gas)];
|
|
82
|
+
gasLimit = mulBy1_3(gas);
|
|
83
|
+
return [4 /*yield*/, curve.updateFeeData()];
|
|
84
|
+
case 2:
|
|
85
|
+
_a.sent();
|
|
86
|
+
return [4 /*yield*/, contract.deploy_plain_pool(name, symbol, _coins, _A, _fee, assetType, implementationIdx, __assign(__assign({}, curve.options), { gasLimit: gasLimit }))];
|
|
87
|
+
case 3: return [2 /*return*/, _a.sent()];
|
|
88
|
+
}
|
|
89
|
+
});
|
|
90
|
+
}); };
|
|
91
|
+
export var deployStablePlainPoolEstimateGas = function (name, symbol, coins, A, fee, // %
|
|
92
|
+
assetType, implementationIdx) { return __awaiter(void 0, void 0, void 0, function () {
|
|
93
|
+
return __generator(this, function (_a) {
|
|
94
|
+
switch (_a.label) {
|
|
95
|
+
case 0: return [4 /*yield*/, _deployStablePlainPool(name, symbol, coins, A, fee, assetType, implementationIdx, true)];
|
|
96
|
+
case 1: return [2 /*return*/, _a.sent()];
|
|
97
|
+
}
|
|
98
|
+
});
|
|
99
|
+
}); };
|
|
100
|
+
export var deployStablePlainPool = function (name, symbol, coins, A, fee, // %
|
|
101
|
+
assetType, implementationIdx) { return __awaiter(void 0, void 0, void 0, function () {
|
|
102
|
+
return __generator(this, function (_a) {
|
|
103
|
+
switch (_a.label) {
|
|
104
|
+
case 0: return [4 /*yield*/, _deployStablePlainPool(name, symbol, coins, A, fee, assetType, implementationIdx, false)];
|
|
105
|
+
case 1: return [2 /*return*/, _a.sent()];
|
|
106
|
+
}
|
|
107
|
+
});
|
|
108
|
+
}); };
|
|
109
|
+
export var getDeployedStablePlainPoolAddress = function (tx) { return __awaiter(void 0, void 0, void 0, function () {
|
|
110
|
+
var txInfo;
|
|
111
|
+
return __generator(this, function (_a) {
|
|
112
|
+
switch (_a.label) {
|
|
113
|
+
case 0: return [4 /*yield*/, tx.wait()];
|
|
114
|
+
case 1:
|
|
115
|
+
txInfo = _a.sent();
|
|
116
|
+
if (!txInfo)
|
|
117
|
+
throw Error("Can't get tx info");
|
|
118
|
+
return [2 /*return*/, txInfo.logs[0].address.toLowerCase()];
|
|
119
|
+
}
|
|
120
|
+
});
|
|
121
|
+
}); };
|
|
47
122
|
// ------- STABLE META POOLS -------
|
|
48
|
-
|
|
49
|
-
implementationIdx, estimateGas)
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
123
|
+
var _deployStableMetaPool = function (basePool, name, symbol, coin, A, fee, // %
|
|
124
|
+
implementationIdx, estimateGas) { return __awaiter(void 0, void 0, void 0, function () {
|
|
125
|
+
var _A, _fee, contract, gas, gasLimit;
|
|
126
|
+
return __generator(this, function (_a) {
|
|
127
|
+
switch (_a.label) {
|
|
128
|
+
case 0:
|
|
129
|
+
if (name.length > 32)
|
|
130
|
+
throw Error("Max name length = 32");
|
|
131
|
+
if (symbol.length > 10)
|
|
132
|
+
throw Error("Max symbol length = 10");
|
|
133
|
+
if (BN(fee).lt(0.04))
|
|
134
|
+
throw Error("fee must be >= 0.04%. Passed fee = ".concat(fee));
|
|
135
|
+
if (BN(fee).gt(1))
|
|
136
|
+
throw Error("fee must be <= 1%. Passed fee = ".concat(fee));
|
|
137
|
+
if (![0, 1].includes(implementationIdx))
|
|
138
|
+
throw Error("Invalid implementationIdx. Must be one 0 or 1");
|
|
139
|
+
_A = parseUnits(A, 0);
|
|
140
|
+
_fee = parseUnits(fee, 8);
|
|
141
|
+
contract = curve.contracts[curve.constants.ALIASES.factory].contract;
|
|
142
|
+
return [4 /*yield*/, contract.deploy_metapool.estimateGas(basePool, name, symbol, coin, _A, _fee, implementationIdx, curve.constantOptions)];
|
|
143
|
+
case 1:
|
|
144
|
+
gas = _a.sent();
|
|
145
|
+
if (estimateGas)
|
|
146
|
+
return [2 /*return*/, Number(gas)];
|
|
147
|
+
gasLimit = mulBy1_3(gas);
|
|
148
|
+
return [4 /*yield*/, curve.updateFeeData()];
|
|
149
|
+
case 2:
|
|
150
|
+
_a.sent();
|
|
151
|
+
return [4 /*yield*/, contract.deploy_metapool(basePool, name, symbol, coin, _A, _fee, implementationIdx, __assign(__assign({}, curve.options), { gasLimit: gasLimit }))];
|
|
152
|
+
case 3: return [2 /*return*/, _a.sent()];
|
|
153
|
+
}
|
|
154
|
+
});
|
|
155
|
+
}); };
|
|
156
|
+
export var deployStableMetaPoolEstimateGas = function (basePool, name, symbol, coin, A, fee, // %
|
|
157
|
+
implementationIdx) { return __awaiter(void 0, void 0, void 0, function () {
|
|
158
|
+
return __generator(this, function (_a) {
|
|
159
|
+
switch (_a.label) {
|
|
160
|
+
case 0: return [4 /*yield*/, _deployStableMetaPool(basePool, name, symbol, coin, A, fee, implementationIdx, true)];
|
|
161
|
+
case 1: return [2 /*return*/, _a.sent()];
|
|
162
|
+
}
|
|
163
|
+
});
|
|
164
|
+
}); };
|
|
165
|
+
export var deployStableMetaPool = function (basePool, name, symbol, coin, A, fee, // %
|
|
166
|
+
implementationIdx) { return __awaiter(void 0, void 0, void 0, function () {
|
|
167
|
+
return __generator(this, function (_a) {
|
|
168
|
+
switch (_a.label) {
|
|
169
|
+
case 0: return [4 /*yield*/, _deployStableMetaPool(basePool, name, symbol, coin, A, fee, implementationIdx, false)];
|
|
170
|
+
case 1: return [2 /*return*/, _a.sent()];
|
|
171
|
+
}
|
|
172
|
+
});
|
|
173
|
+
}); };
|
|
174
|
+
export var getDeployedStableMetaPoolAddress = function (tx) { return __awaiter(void 0, void 0, void 0, function () {
|
|
175
|
+
var txInfo;
|
|
176
|
+
return __generator(this, function (_a) {
|
|
177
|
+
switch (_a.label) {
|
|
178
|
+
case 0: return [4 /*yield*/, tx.wait()];
|
|
179
|
+
case 1:
|
|
180
|
+
txInfo = _a.sent();
|
|
181
|
+
if (!txInfo)
|
|
182
|
+
throw Error("Can't get tx info");
|
|
183
|
+
return [2 /*return*/, txInfo.logs[3].address.toLowerCase()];
|
|
184
|
+
}
|
|
185
|
+
});
|
|
186
|
+
}); };
|
|
84
187
|
// ------- CRYPTO POOLS -------
|
|
85
|
-
|
|
188
|
+
var _deployCryptoPool = function (name, symbol, coins, A, gamma, midFee, // %
|
|
86
189
|
outFee, // %
|
|
87
190
|
allowedExtraProfit, feeGamma, adjustmentStep, maHalfTime, // Seconds
|
|
88
|
-
initialPrice, estimateGas)
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
191
|
+
initialPrice, estimateGas) { return __awaiter(void 0, void 0, void 0, function () {
|
|
192
|
+
var _A, _gamma, _midFee, _outFee, _allowedExtraProfit, _feeGamma, _adjustmentStep, _maHalfTime, _initialPrice, contract, gas, gasLimit;
|
|
193
|
+
return __generator(this, function (_a) {
|
|
194
|
+
switch (_a.label) {
|
|
195
|
+
case 0:
|
|
196
|
+
if (name.length > 32)
|
|
197
|
+
throw Error("Max name length = 32");
|
|
198
|
+
if (symbol.length > 10)
|
|
199
|
+
throw Error("Max symbol length = 10");
|
|
200
|
+
if (coins.length !== 2)
|
|
201
|
+
throw Error("Invalid number of coins. Must be 2");
|
|
202
|
+
if (coins[1] === coins[2])
|
|
203
|
+
throw Error("Coins must be different");
|
|
204
|
+
if (BN(A).lt(4000))
|
|
205
|
+
throw Error("A must be >= 4000. Passed A = ".concat(A));
|
|
206
|
+
if (BN(A).gt(4 * (Math.pow(10, 9))))
|
|
207
|
+
throw Error("A must be <= 4 * 10 ** 9. Passed A = ".concat(A));
|
|
208
|
+
if (BN(gamma).lt(1e-8))
|
|
209
|
+
throw Error("gamma must be >= 1e-8. Passed gamma = ".concat(gamma));
|
|
210
|
+
if (BN(gamma).gt(0.02))
|
|
211
|
+
throw Error("gamma must be <= 0.02. Passed gamma = ".concat(gamma));
|
|
212
|
+
if (BN(midFee).lt(0.005))
|
|
213
|
+
throw Error("midFee must be >= 0.005. Passed midFee = ".concat(midFee));
|
|
214
|
+
if (BN(midFee).gt(100))
|
|
215
|
+
throw Error("midFee must be <= 100. Passed midFee = ".concat(midFee));
|
|
216
|
+
if (BN(outFee).lt(BN(midFee)))
|
|
217
|
+
throw Error("outFee must be >= midFee. Passed outFee = ".concat(outFee, " < midFee = ").concat(midFee));
|
|
218
|
+
if (BN(outFee).gt(100))
|
|
219
|
+
throw Error("outFee must be <= 100. Passed outFee = ".concat(outFee));
|
|
220
|
+
if (BN(allowedExtraProfit).lt(0))
|
|
221
|
+
throw Error("allowedExtraProfit must be >= 0. Passed allowedExtraProfit = ".concat(allowedExtraProfit));
|
|
222
|
+
if (BN(allowedExtraProfit).gt(0.01))
|
|
223
|
+
throw Error("allowedExtraProfit must be <= 0.01. Passed allowedExtraProfit = ".concat(allowedExtraProfit));
|
|
224
|
+
if (BN(feeGamma).lt(0))
|
|
225
|
+
throw Error("feeGamma must be >= 0. Passed feeGamma = ".concat(feeGamma));
|
|
226
|
+
if (BN(feeGamma).gt(1))
|
|
227
|
+
throw Error("feeGamma must be <= 1. Passed feeGamma = ".concat(feeGamma));
|
|
228
|
+
if (BN(adjustmentStep).lt(0))
|
|
229
|
+
throw Error("adjustmentStep must be >= 0. Passed adjustmentStep=".concat(adjustmentStep));
|
|
230
|
+
if (BN(adjustmentStep).gt(1))
|
|
231
|
+
throw Error("adjustmentStep must be <= 1. Passed adjustmentStep=".concat(adjustmentStep));
|
|
232
|
+
if (BN(maHalfTime).lt(0))
|
|
233
|
+
throw Error("maHalfTime must be >= 0. Passed maHalfTime=".concat(maHalfTime));
|
|
234
|
+
if (BN(maHalfTime).gt(604800))
|
|
235
|
+
throw Error("maHalfTime must be <= 604800. Passed maHalfTime=".concat(maHalfTime));
|
|
236
|
+
if (BN(initialPrice).lt(1e-12))
|
|
237
|
+
throw Error("initialPrice must be >= 1e-12. Passed initialPrice=".concat(initialPrice));
|
|
238
|
+
if (BN(initialPrice).gt(1e12))
|
|
239
|
+
throw Error("initialPrice must be <= 1e12. Passed initialPrice=".concat(initialPrice));
|
|
240
|
+
_A = parseUnits(A, 0);
|
|
241
|
+
_gamma = parseUnits(gamma);
|
|
242
|
+
_midFee = parseUnits(midFee, 8);
|
|
243
|
+
_outFee = parseUnits(outFee, 8);
|
|
244
|
+
_allowedExtraProfit = parseUnits(allowedExtraProfit);
|
|
245
|
+
_feeGamma = parseUnits(feeGamma);
|
|
246
|
+
_adjustmentStep = parseUnits(adjustmentStep);
|
|
247
|
+
_maHalfTime = parseUnits(maHalfTime, 0);
|
|
248
|
+
_initialPrice = parseUnits(initialPrice);
|
|
249
|
+
contract = curve.contracts[curve.constants.ALIASES.crypto_factory].contract;
|
|
250
|
+
return [4 /*yield*/, contract.deploy_pool.estimateGas(name, symbol, coins, _A, _gamma, _midFee, _outFee, _allowedExtraProfit, _feeGamma, _adjustmentStep, 5000000000, _maHalfTime, _initialPrice, curve.constantOptions)];
|
|
251
|
+
case 1:
|
|
252
|
+
gas = _a.sent();
|
|
253
|
+
if (estimateGas)
|
|
254
|
+
return [2 /*return*/, Number(gas)];
|
|
255
|
+
gasLimit = mulBy1_3(gas);
|
|
256
|
+
return [4 /*yield*/, curve.updateFeeData()];
|
|
257
|
+
case 2:
|
|
258
|
+
_a.sent();
|
|
259
|
+
return [4 /*yield*/, contract.deploy_pool(name, symbol, coins, _A, _gamma, _midFee, _outFee, _allowedExtraProfit, _feeGamma, _adjustmentStep, 5000000000, // 50%
|
|
260
|
+
_maHalfTime, _initialPrice, __assign(__assign({}, curve.options), { gasLimit: gasLimit }))];
|
|
261
|
+
case 3: return [2 /*return*/, _a.sent()];
|
|
262
|
+
}
|
|
263
|
+
});
|
|
264
|
+
}); };
|
|
265
|
+
export var deployCryptoPoolEstimateGas = function (name, symbol, coins, A, gamma, midFee, // %
|
|
152
266
|
outFee, // %
|
|
153
267
|
allowedExtraProfit, feeGamma, adjustmentStep, maHalfTime, // Seconds
|
|
154
|
-
initialPrice)
|
|
155
|
-
return
|
|
156
|
-
|
|
157
|
-
|
|
268
|
+
initialPrice) { return __awaiter(void 0, void 0, void 0, function () {
|
|
269
|
+
return __generator(this, function (_a) {
|
|
270
|
+
switch (_a.label) {
|
|
271
|
+
case 0: return [4 /*yield*/, _deployCryptoPool(name, symbol, coins, A, gamma, midFee, outFee, allowedExtraProfit, feeGamma, adjustmentStep, maHalfTime, initialPrice, true)];
|
|
272
|
+
case 1: return [2 /*return*/, _a.sent()];
|
|
273
|
+
}
|
|
274
|
+
});
|
|
275
|
+
}); };
|
|
276
|
+
export var deployCryptoPool = function (name, symbol, coins, A, gamma, midFee, // %
|
|
158
277
|
outFee, // %
|
|
159
278
|
allowedExtraProfit, feeGamma, adjustmentStep, maHalfTime, // Seconds
|
|
160
|
-
initialPrice)
|
|
161
|
-
return
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
279
|
+
initialPrice) { return __awaiter(void 0, void 0, void 0, function () {
|
|
280
|
+
return __generator(this, function (_a) {
|
|
281
|
+
switch (_a.label) {
|
|
282
|
+
case 0: return [4 /*yield*/, _deployCryptoPool(name, symbol, coins, A, gamma, midFee, outFee, allowedExtraProfit, feeGamma, adjustmentStep, maHalfTime, initialPrice, false)];
|
|
283
|
+
case 1: return [2 /*return*/, _a.sent()];
|
|
284
|
+
}
|
|
285
|
+
});
|
|
286
|
+
}); };
|
|
287
|
+
export var getDeployedCryptoPoolAddress = function (tx) { return __awaiter(void 0, void 0, void 0, function () {
|
|
288
|
+
var txInfo, lpTokenAddress, contract;
|
|
289
|
+
return __generator(this, function (_a) {
|
|
290
|
+
switch (_a.label) {
|
|
291
|
+
case 0: return [4 /*yield*/, tx.wait()];
|
|
292
|
+
case 1:
|
|
293
|
+
txInfo = _a.sent();
|
|
294
|
+
if (!txInfo)
|
|
295
|
+
throw Error("Can't get tx info");
|
|
296
|
+
lpTokenAddress = txInfo.logs[0].address;
|
|
297
|
+
contract = new Contract(lpTokenAddress, CurveLpTokenV5ABI, curve.provider);
|
|
298
|
+
return [4 /*yield*/, contract.minter(curve.constantOptions)];
|
|
299
|
+
case 2: return [2 /*return*/, (_a.sent()).toLowerCase()];
|
|
300
|
+
}
|
|
301
|
+
});
|
|
302
|
+
}); };
|
|
171
303
|
// ------- GAUGE -------
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
}
|
|
304
|
+
var _deployGauge = function (pool, isCrypto, estimateGas) { return __awaiter(void 0, void 0, void 0, function () {
|
|
305
|
+
var contractAddress, contract, gas, gasLimit;
|
|
306
|
+
return __generator(this, function (_a) {
|
|
307
|
+
switch (_a.label) {
|
|
308
|
+
case 0:
|
|
309
|
+
contractAddress = isCrypto ? curve.constants.ALIASES.crypto_factory : curve.constants.ALIASES.factory;
|
|
310
|
+
contract = curve.contracts[contractAddress].contract;
|
|
311
|
+
return [4 /*yield*/, contract.deploy_gauge.estimateGas(pool, curve.constantOptions)];
|
|
312
|
+
case 1:
|
|
313
|
+
gas = _a.sent();
|
|
314
|
+
if (estimateGas)
|
|
315
|
+
return [2 /*return*/, Number(gas)];
|
|
316
|
+
gasLimit = mulBy1_3(gas);
|
|
317
|
+
return [4 /*yield*/, curve.updateFeeData()];
|
|
318
|
+
case 2:
|
|
319
|
+
_a.sent();
|
|
320
|
+
return [4 /*yield*/, contract.deploy_gauge(pool, __assign(__assign({}, curve.options), { gasLimit: gasLimit }))];
|
|
321
|
+
case 3: return [2 /*return*/, _a.sent()];
|
|
322
|
+
}
|
|
323
|
+
});
|
|
324
|
+
}); };
|
|
325
|
+
export var deployGaugeEstimateGas = function (pool, isCrypto) { return __awaiter(void 0, void 0, void 0, function () { return __generator(this, function (_a) {
|
|
326
|
+
switch (_a.label) {
|
|
327
|
+
case 0: return [4 /*yield*/, _deployGauge(pool, isCrypto, true)];
|
|
328
|
+
case 1: return [2 /*return*/, _a.sent()];
|
|
329
|
+
}
|
|
330
|
+
}); }); };
|
|
331
|
+
export var deployGauge = function (pool, isCrypto) { return __awaiter(void 0, void 0, void 0, function () { return __generator(this, function (_a) {
|
|
332
|
+
switch (_a.label) {
|
|
333
|
+
case 0: return [4 /*yield*/, _deployGauge(pool, isCrypto, false)];
|
|
334
|
+
case 1: return [2 /*return*/, _a.sent()];
|
|
335
|
+
}
|
|
336
|
+
}); }); };
|
|
337
|
+
export var getDeployedGaugeAddress = function (tx) { return __awaiter(void 0, void 0, void 0, function () {
|
|
338
|
+
var txInfo;
|
|
339
|
+
return __generator(this, function (_a) {
|
|
340
|
+
switch (_a.label) {
|
|
341
|
+
case 0: return [4 /*yield*/, tx.wait()];
|
|
342
|
+
case 1:
|
|
343
|
+
txInfo = _a.sent();
|
|
344
|
+
if (!txInfo)
|
|
345
|
+
throw Error("Can't get tx info");
|
|
346
|
+
// @ts-ignore
|
|
347
|
+
return [2 /*return*/, txInfo.events[0].args[txInfo.events[0].args.length - 1].toLowerCase()];
|
|
348
|
+
}
|
|
349
|
+
});
|
|
350
|
+
}); };
|