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