@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
|
@@ -1,297 +1,111 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
__assign = Object.assign || function(t) {
|
|
4
|
-
for (var s, i = 1, n = arguments.length; i < n; i++) {
|
|
5
|
-
s = arguments[i];
|
|
6
|
-
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p))
|
|
7
|
-
t[p] = s[p];
|
|
8
|
-
}
|
|
9
|
-
return t;
|
|
10
|
-
};
|
|
11
|
-
return __assign.apply(this, arguments);
|
|
12
|
-
};
|
|
13
|
-
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
14
|
-
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
15
|
-
return new (P || (P = Promise))(function (resolve, reject) {
|
|
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
|
-
});
|
|
21
|
-
};
|
|
22
|
-
var __generator = (this && this.__generator) || function (thisArg, body) {
|
|
23
|
-
var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g;
|
|
24
|
-
return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
|
|
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
|
-
}
|
|
48
|
-
};
|
|
49
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
50
|
-
exports.swapWrappedExpectedAndApproveMixin = exports.swapWrappedMixin = exports.swapWrappedTricrypto2Mixin = void 0;
|
|
51
|
-
var utils_1 = require("../../utils");
|
|
52
|
-
var curve_1 = require("../../curve");
|
|
53
|
-
var ethers_1 = require("ethers");
|
|
1
|
+
import { curve } from "../../curve.js";
|
|
2
|
+
import { _ensureAllowance, _getCoinDecimals, ensureAllowance, ensureAllowanceEstimateGas, fromBN, hasAllowance, isEth, toBN, parseUnits, mulBy1_3, } from "../../utils.js";
|
|
54
3
|
// @ts-ignore
|
|
55
|
-
function _swapWrappedCheck(inputCoin, outputCoin, amount, estimateGas) {
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
_c = estimateGas;
|
|
72
|
-
if (!_c) return [3 /*break*/, 3];
|
|
73
|
-
return [4 /*yield*/, (0, utils_1.hasAllowance)([this.wrappedCoinAddresses[i]], [amount], curve_1.curve.signerAddress, this.address)];
|
|
74
|
-
case 2:
|
|
75
|
-
_c = !(_d.sent());
|
|
76
|
-
_d.label = 3;
|
|
77
|
-
case 3:
|
|
78
|
-
if (_c) {
|
|
79
|
-
throw Error("Token allowance is needed to estimate gas");
|
|
80
|
-
}
|
|
81
|
-
if (!!estimateGas) return [3 /*break*/, 5];
|
|
82
|
-
return [4 /*yield*/, curve_1.curve.updateFeeData()];
|
|
83
|
-
case 4:
|
|
84
|
-
_d.sent();
|
|
85
|
-
_d.label = 5;
|
|
86
|
-
case 5:
|
|
87
|
-
_amount = (0, utils_1.parseUnits)(amount, this.wrappedDecimals[i]);
|
|
88
|
-
return [2 /*return*/, [i, j, _amount]];
|
|
89
|
-
}
|
|
90
|
-
});
|
|
91
|
-
});
|
|
4
|
+
async function _swapWrappedCheck(inputCoin, outputCoin, amount, estimateGas = false) {
|
|
5
|
+
// @ts-ignore
|
|
6
|
+
const i = this._getCoinIdx(inputCoin, false);
|
|
7
|
+
// @ts-ignore
|
|
8
|
+
const j = this._getCoinIdx(outputCoin, false);
|
|
9
|
+
const inputCoinBalance = Object.values(await this.wallet.wrappedCoinBalances())[i];
|
|
10
|
+
if (Number(inputCoinBalance) < Number(amount)) {
|
|
11
|
+
throw Error(`Not enough ${this.wrappedCoins[i]}. Actual: ${inputCoinBalance}, required: ${amount}`);
|
|
12
|
+
}
|
|
13
|
+
if (estimateGas && !(await hasAllowance([this.wrappedCoinAddresses[i]], [amount], curve.signerAddress, this.address))) {
|
|
14
|
+
throw Error("Token allowance is needed to estimate gas");
|
|
15
|
+
}
|
|
16
|
+
if (!estimateGas)
|
|
17
|
+
await curve.updateFeeData();
|
|
18
|
+
const _amount = parseUnits(amount, this.wrappedDecimals[i]);
|
|
19
|
+
return [i, j, _amount];
|
|
92
20
|
}
|
|
93
|
-
function _swapWrappedMinAmount(i, j, _amount, slippage) {
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
case 0: return [4 /*yield*/, this._swapWrappedExpected(i, j, _amount)];
|
|
100
|
-
case 1:
|
|
101
|
-
_expected = _a.sent();
|
|
102
|
-
outputCoinDecimals = (0, utils_1._getCoinDecimals)(this.wrappedCoinAddresses[j])[0];
|
|
103
|
-
minAmountBN = (0, utils_1.toBN)(_expected, outputCoinDecimals).times(100 - slippage).div(100);
|
|
104
|
-
return [2 /*return*/, (0, utils_1.fromBN)(minAmountBN, outputCoinDecimals)];
|
|
105
|
-
}
|
|
106
|
-
});
|
|
107
|
-
});
|
|
21
|
+
async function _swapWrappedMinAmount(i, j, _amount, slippage = 0.5) {
|
|
22
|
+
// @ts-ignore
|
|
23
|
+
const _expected = await this._swapWrappedExpected(i, j, _amount);
|
|
24
|
+
const [outputCoinDecimals] = _getCoinDecimals(this.wrappedCoinAddresses[j]);
|
|
25
|
+
const minAmountBN = toBN(_expected, outputCoinDecimals).times(100 - slippage).div(100);
|
|
26
|
+
return fromBN(minAmountBN, outputCoinDecimals);
|
|
108
27
|
}
|
|
109
28
|
// @ts-ignore
|
|
110
|
-
|
|
29
|
+
export const swapWrappedTricrypto2Mixin = {
|
|
111
30
|
// @ts-ignore
|
|
112
|
-
_swapWrapped
|
|
113
|
-
if (estimateGas
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
_a.label = 2;
|
|
124
|
-
case 2: return [4 /*yield*/, _swapWrappedMinAmount.call(this, i, j, _amount, slippage)];
|
|
125
|
-
case 3:
|
|
126
|
-
_minRecvAmount = _a.sent();
|
|
127
|
-
contract = curve_1.curve.contracts[this.address].contract;
|
|
128
|
-
value = (0, utils_1.isEth)(this.wrappedCoinAddresses[i]) ? _amount : ethers_1.ethers.BigNumber.from(0);
|
|
129
|
-
return [4 /*yield*/, contract.estimateGas.exchange(i, j, _amount, _minRecvAmount, false, __assign(__assign({}, curve_1.curve.constantOptions), { value: value }))];
|
|
130
|
-
case 4:
|
|
131
|
-
gas = _a.sent();
|
|
132
|
-
if (estimateGas)
|
|
133
|
-
return [2 /*return*/, gas.toNumber()];
|
|
134
|
-
gasLimit = gas.mul(130).div(100);
|
|
135
|
-
return [4 /*yield*/, contract.exchange(i, j, _amount, _minRecvAmount, false, __assign(__assign({}, curve_1.curve.options), { value: value, gasLimit: gasLimit }))];
|
|
136
|
-
case 5: return [2 /*return*/, (_a.sent()).hash];
|
|
137
|
-
}
|
|
138
|
-
});
|
|
139
|
-
});
|
|
31
|
+
async _swapWrapped(i, j, _amount, slippage, estimateGas = false) {
|
|
32
|
+
if (!estimateGas)
|
|
33
|
+
await _ensureAllowance([this.wrappedCoinAddresses[i]], [_amount], this.address);
|
|
34
|
+
const _minRecvAmount = await _swapWrappedMinAmount.call(this, i, j, _amount, slippage);
|
|
35
|
+
const contract = curve.contracts[this.address].contract;
|
|
36
|
+
const value = isEth(this.wrappedCoinAddresses[i]) ? _amount : 0n;
|
|
37
|
+
const gas = await contract.exchange.estimateGas(i, j, _amount, _minRecvAmount, false, { ...curve.constantOptions, value });
|
|
38
|
+
if (estimateGas)
|
|
39
|
+
return Number(gas);
|
|
40
|
+
const gasLimit = mulBy1_3(gas);
|
|
41
|
+
return (await contract.exchange(i, j, _amount, _minRecvAmount, false, { ...curve.options, value, gasLimit })).hash;
|
|
140
42
|
},
|
|
141
|
-
swapWrappedEstimateGas
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
case 0: return [4 /*yield*/, _swapWrappedCheck.call(this, inputCoin, outputCoin, amount, true)];
|
|
147
|
-
case 1:
|
|
148
|
-
_a = _b.sent(), i = _a[0], j = _a[1], _amount = _a[2];
|
|
149
|
-
return [4 /*yield*/, this._swapWrapped(i, j, _amount, 0.1, true)];
|
|
150
|
-
case 2:
|
|
151
|
-
// @ts-ignore
|
|
152
|
-
return [2 /*return*/, _b.sent()];
|
|
153
|
-
}
|
|
154
|
-
});
|
|
155
|
-
});
|
|
43
|
+
async swapWrappedEstimateGas(inputCoin, outputCoin, amount) {
|
|
44
|
+
// @ts-ignore
|
|
45
|
+
const [i, j, _amount] = await _swapWrappedCheck.call(this, inputCoin, outputCoin, amount, true);
|
|
46
|
+
// @ts-ignore
|
|
47
|
+
return await this._swapWrapped(i, j, _amount, 0.1, true);
|
|
156
48
|
},
|
|
157
|
-
swapWrapped
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
case 0: return [4 /*yield*/, _swapWrappedCheck.call(this, inputCoin, outputCoin, amount)];
|
|
163
|
-
case 1:
|
|
164
|
-
_a = _b.sent(), i = _a[0], j = _a[1], _amount = _a[2];
|
|
165
|
-
return [4 /*yield*/, this._swapWrapped(i, j, _amount, slippage)];
|
|
166
|
-
case 2:
|
|
167
|
-
// @ts-ignore
|
|
168
|
-
return [2 /*return*/, _b.sent()];
|
|
169
|
-
}
|
|
170
|
-
});
|
|
171
|
-
});
|
|
49
|
+
async swapWrapped(inputCoin, outputCoin, amount, slippage) {
|
|
50
|
+
// @ts-ignore
|
|
51
|
+
const [i, j, _amount] = await _swapWrappedCheck.call(this, inputCoin, outputCoin, amount);
|
|
52
|
+
// @ts-ignore
|
|
53
|
+
return await this._swapWrapped(i, j, _amount, slippage);
|
|
172
54
|
},
|
|
173
55
|
};
|
|
174
56
|
// @ts-ignore
|
|
175
|
-
|
|
57
|
+
export const swapWrappedMixin = {
|
|
176
58
|
// @ts-ignore
|
|
177
|
-
_swapWrapped
|
|
178
|
-
if (estimateGas
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
_a.label = 2;
|
|
189
|
-
case 2: return [4 /*yield*/, _swapWrappedMinAmount.call(this, i, j, _amount, slippage)];
|
|
190
|
-
case 3:
|
|
191
|
-
_minRecvAmount = _a.sent();
|
|
192
|
-
contract = curve_1.curve.contracts[this.address].contract;
|
|
193
|
-
value = (0, utils_1.isEth)(this.wrappedCoinAddresses[i]) ? _amount : ethers_1.ethers.BigNumber.from(0);
|
|
194
|
-
return [4 /*yield*/, contract.estimateGas.exchange(i, j, _amount, _minRecvAmount, __assign(__assign({}, curve_1.curve.constantOptions), { value: value }))];
|
|
195
|
-
case 4:
|
|
196
|
-
gas = _a.sent();
|
|
197
|
-
if (estimateGas)
|
|
198
|
-
return [2 /*return*/, gas.toNumber()];
|
|
199
|
-
gasLimit = curve_1.curve.chainId === 137 && this.id === 'ren' ? gas.mul(140).div(100) : gas.mul(130).div(100);
|
|
200
|
-
return [4 /*yield*/, contract.exchange(i, j, _amount, _minRecvAmount, __assign(__assign({}, curve_1.curve.options), { value: value, gasLimit: gasLimit }))];
|
|
201
|
-
case 5: return [2 /*return*/, (_a.sent()).hash];
|
|
202
|
-
}
|
|
203
|
-
});
|
|
204
|
-
});
|
|
59
|
+
async _swapWrapped(i, j, _amount, slippage, estimateGas = false) {
|
|
60
|
+
if (!estimateGas)
|
|
61
|
+
await _ensureAllowance([this.wrappedCoinAddresses[i]], [_amount], this.address);
|
|
62
|
+
const _minRecvAmount = await _swapWrappedMinAmount.call(this, i, j, _amount, slippage);
|
|
63
|
+
const contract = curve.contracts[this.address].contract;
|
|
64
|
+
const value = isEth(this.wrappedCoinAddresses[i]) ? _amount : 0n;
|
|
65
|
+
const gas = await contract.exchange.estimateGas(i, j, _amount, _minRecvAmount, { ...curve.constantOptions, value });
|
|
66
|
+
if (estimateGas)
|
|
67
|
+
return Number(gas);
|
|
68
|
+
const gasLimit = curve.chainId === 137 && this.id === 'ren' ? gas * 140n / 100n : mulBy1_3(gas);
|
|
69
|
+
return (await contract.exchange(i, j, _amount, _minRecvAmount, { ...curve.options, value, gasLimit })).hash;
|
|
205
70
|
},
|
|
206
|
-
swapWrappedEstimateGas
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
case 0: return [4 /*yield*/, _swapWrappedCheck.call(this, inputCoin, outputCoin, amount, true)];
|
|
212
|
-
case 1:
|
|
213
|
-
_a = _b.sent(), i = _a[0], j = _a[1], _amount = _a[2];
|
|
214
|
-
return [4 /*yield*/, this._swapWrapped(i, j, _amount, 0.1, true)];
|
|
215
|
-
case 2:
|
|
216
|
-
// @ts-ignore
|
|
217
|
-
return [2 /*return*/, _b.sent()];
|
|
218
|
-
}
|
|
219
|
-
});
|
|
220
|
-
});
|
|
71
|
+
async swapWrappedEstimateGas(inputCoin, outputCoin, amount) {
|
|
72
|
+
// @ts-ignore
|
|
73
|
+
const [i, j, _amount] = await _swapWrappedCheck.call(this, inputCoin, outputCoin, amount, true);
|
|
74
|
+
// @ts-ignore
|
|
75
|
+
return await this._swapWrapped(i, j, _amount, 0.1, true);
|
|
221
76
|
},
|
|
222
|
-
swapWrapped
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
case 0: return [4 /*yield*/, _swapWrappedCheck.call(this, inputCoin, outputCoin, amount)];
|
|
228
|
-
case 1:
|
|
229
|
-
_a = _b.sent(), i = _a[0], j = _a[1], _amount = _a[2];
|
|
230
|
-
return [4 /*yield*/, this._swapWrapped(i, j, _amount, slippage)];
|
|
231
|
-
case 2:
|
|
232
|
-
// @ts-ignore
|
|
233
|
-
return [2 /*return*/, _b.sent()];
|
|
234
|
-
}
|
|
235
|
-
});
|
|
236
|
-
});
|
|
77
|
+
async swapWrapped(inputCoin, outputCoin, amount, slippage) {
|
|
78
|
+
// @ts-ignore
|
|
79
|
+
const [i, j, _amount] = await _swapWrappedCheck.call(this, inputCoin, outputCoin, amount);
|
|
80
|
+
// @ts-ignore
|
|
81
|
+
return await this._swapWrapped(i, j, _amount, slippage);
|
|
237
82
|
},
|
|
238
83
|
};
|
|
239
84
|
// @ts-ignore
|
|
240
|
-
|
|
241
|
-
swapWrappedExpected
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
return [4 /*yield*/, this._swapWrappedExpected(i, j, _amount)];
|
|
251
|
-
case 1:
|
|
252
|
-
_expected = _a.sent();
|
|
253
|
-
return [2 /*return*/, ethers_1.ethers.utils.formatUnits(_expected, this.wrappedDecimals[j])];
|
|
254
|
-
}
|
|
255
|
-
});
|
|
256
|
-
});
|
|
85
|
+
export const swapWrappedExpectedAndApproveMixin = {
|
|
86
|
+
async swapWrappedExpected(inputCoin, outputCoin, amount) {
|
|
87
|
+
// @ts-ignore
|
|
88
|
+
const i = this._getCoinIdx(inputCoin, false);
|
|
89
|
+
// @ts-ignore
|
|
90
|
+
const j = this._getCoinIdx(outputCoin, false);
|
|
91
|
+
const _amount = parseUnits(amount, this.wrappedDecimals[i]);
|
|
92
|
+
// @ts-ignore
|
|
93
|
+
const _expected = await this._swapWrappedExpected(i, j, _amount);
|
|
94
|
+
return curve.formatUnits(_expected, this.wrappedDecimals[j]);
|
|
257
95
|
},
|
|
258
|
-
swapWrappedIsApproved
|
|
259
|
-
|
|
260
|
-
|
|
261
|
-
|
|
262
|
-
switch (_a.label) {
|
|
263
|
-
case 0:
|
|
264
|
-
i = this._getCoinIdx(inputCoin, false);
|
|
265
|
-
return [4 /*yield*/, (0, utils_1.hasAllowance)([this.wrappedCoinAddresses[i]], [amount], curve_1.curve.signerAddress, this.address)];
|
|
266
|
-
case 1: return [2 /*return*/, _a.sent()];
|
|
267
|
-
}
|
|
268
|
-
});
|
|
269
|
-
});
|
|
96
|
+
async swapWrappedIsApproved(inputCoin, amount) {
|
|
97
|
+
// @ts-ignore
|
|
98
|
+
const i = this._getCoinIdx(inputCoin, false);
|
|
99
|
+
return await hasAllowance([this.wrappedCoinAddresses[i]], [amount], curve.signerAddress, this.address);
|
|
270
100
|
},
|
|
271
|
-
swapWrappedApproveEstimateGas
|
|
272
|
-
|
|
273
|
-
|
|
274
|
-
|
|
275
|
-
switch (_a.label) {
|
|
276
|
-
case 0:
|
|
277
|
-
i = this._getCoinIdx(inputCoin, false);
|
|
278
|
-
return [4 /*yield*/, (0, utils_1.ensureAllowanceEstimateGas)([this.wrappedCoinAddresses[i]], [amount], this.address)];
|
|
279
|
-
case 1: return [2 /*return*/, _a.sent()];
|
|
280
|
-
}
|
|
281
|
-
});
|
|
282
|
-
});
|
|
101
|
+
async swapWrappedApproveEstimateGas(inputCoin, amount) {
|
|
102
|
+
// @ts-ignore
|
|
103
|
+
const i = this._getCoinIdx(inputCoin, false);
|
|
104
|
+
return await ensureAllowanceEstimateGas([this.wrappedCoinAddresses[i]], [amount], this.address);
|
|
283
105
|
},
|
|
284
|
-
swapWrappedApprove
|
|
285
|
-
|
|
286
|
-
|
|
287
|
-
|
|
288
|
-
switch (_a.label) {
|
|
289
|
-
case 0:
|
|
290
|
-
i = this._getCoinIdx(inputCoin, false);
|
|
291
|
-
return [4 /*yield*/, (0, utils_1.ensureAllowance)([this.wrappedCoinAddresses[i]], [amount], this.address)];
|
|
292
|
-
case 1: return [2 /*return*/, _a.sent()];
|
|
293
|
-
}
|
|
294
|
-
});
|
|
295
|
-
});
|
|
106
|
+
async swapWrappedApprove(inputCoin, amount) {
|
|
107
|
+
// @ts-ignore
|
|
108
|
+
const i = this._getCoinIdx(inputCoin, false);
|
|
109
|
+
return await ensureAllowance([this.wrappedCoinAddresses[i]], [amount], this.address);
|
|
296
110
|
},
|
|
297
111
|
};
|
|
@@ -1,6 +1,5 @@
|
|
|
1
|
-
import { PoolTemplate } from "../PoolTemplate";
|
|
1
|
+
import { PoolTemplate } from "../PoolTemplate.js";
|
|
2
2
|
export declare const withdrawExpectedMixin: PoolTemplate;
|
|
3
3
|
export declare const withdrawExpectedLendingOrCryptoMixin: PoolTemplate;
|
|
4
4
|
export declare const withdrawExpectedMetaMixin: PoolTemplate;
|
|
5
|
-
export declare const withdrawExpectedAtricrypto3Mixin: PoolTemplate;
|
|
6
5
|
export declare const withdrawWrappedExpectedMixin: PoolTemplate;
|
|
@@ -1,166 +1,38 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
return new (P || (P = Promise))(function (resolve, reject) {
|
|
5
|
-
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
6
|
-
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
7
|
-
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
8
|
-
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
9
|
-
});
|
|
10
|
-
};
|
|
11
|
-
var __generator = (this && this.__generator) || function (thisArg, body) {
|
|
12
|
-
var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g;
|
|
13
|
-
return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
|
|
14
|
-
function verb(n) { return function (v) { return step([n, v]); }; }
|
|
15
|
-
function step(op) {
|
|
16
|
-
if (f) throw new TypeError("Generator is already executing.");
|
|
17
|
-
while (g && (g = 0, op[0] && (_ = 0)), _) try {
|
|
18
|
-
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;
|
|
19
|
-
if (y = 0, t) op = [op[0] & 2, t.value];
|
|
20
|
-
switch (op[0]) {
|
|
21
|
-
case 0: case 1: t = op; break;
|
|
22
|
-
case 4: _.label++; return { value: op[1], done: false };
|
|
23
|
-
case 5: _.label++; y = op[1]; op = [0]; continue;
|
|
24
|
-
case 7: op = _.ops.pop(); _.trys.pop(); continue;
|
|
25
|
-
default:
|
|
26
|
-
if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }
|
|
27
|
-
if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }
|
|
28
|
-
if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }
|
|
29
|
-
if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }
|
|
30
|
-
if (t[2]) _.ops.pop();
|
|
31
|
-
_.trys.pop(); continue;
|
|
32
|
-
}
|
|
33
|
-
op = body.call(thisArg, _);
|
|
34
|
-
} catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }
|
|
35
|
-
if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
|
|
36
|
-
}
|
|
37
|
-
};
|
|
38
|
-
var __spreadArray = (this && this.__spreadArray) || function (to, from, pack) {
|
|
39
|
-
if (pack || arguments.length === 2) for (var i = 0, l = from.length, ar; i < l; i++) {
|
|
40
|
-
if (ar || !(i in from)) {
|
|
41
|
-
if (!ar) ar = Array.prototype.slice.call(from, 0, i);
|
|
42
|
-
ar[i] = from[i];
|
|
43
|
-
}
|
|
44
|
-
}
|
|
45
|
-
return to.concat(ar || Array.prototype.slice.call(from));
|
|
46
|
-
};
|
|
47
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
48
|
-
exports.withdrawWrappedExpectedMixin = exports.withdrawExpectedAtricrypto3Mixin = exports.withdrawExpectedMetaMixin = exports.withdrawExpectedLendingOrCryptoMixin = exports.withdrawExpectedMixin = void 0;
|
|
49
|
-
var ethers_1 = require("ethers");
|
|
50
|
-
var common_1 = require("./common");
|
|
51
|
-
var PoolTemplate_1 = require("../PoolTemplate");
|
|
52
|
-
var utils_1 = require("../../utils");
|
|
53
|
-
// @ts-ignore
|
|
54
|
-
exports.withdrawExpectedMixin = {
|
|
55
|
-
withdrawExpected: function (lpTokenAmount) {
|
|
56
|
-
return __awaiter(this, void 0, void 0, function () {
|
|
57
|
-
var _lpTokenAmount, _expected;
|
|
58
|
-
var _this = this;
|
|
59
|
-
return __generator(this, function (_a) {
|
|
60
|
-
switch (_a.label) {
|
|
61
|
-
case 0:
|
|
62
|
-
_lpTokenAmount = (0, utils_1.parseUnits)(lpTokenAmount);
|
|
63
|
-
return [4 /*yield*/, common_1._calcExpectedAmounts.call(this, _lpTokenAmount)];
|
|
64
|
-
case 1:
|
|
65
|
-
_expected = _a.sent();
|
|
66
|
-
return [2 /*return*/, _expected.map(function (amount, i) { return ethers_1.ethers.utils.formatUnits(amount, _this.underlyingDecimals[i]); })];
|
|
67
|
-
}
|
|
68
|
-
});
|
|
69
|
-
});
|
|
70
|
-
},
|
|
71
|
-
};
|
|
1
|
+
import { curve } from "../../curve.js";
|
|
2
|
+
import { parseUnits } from "../../utils.js";
|
|
3
|
+
import { _calcExpectedAmounts, _calcExpectedUnderlyingAmountsMeta } from "./common.js";
|
|
72
4
|
// @ts-ignore
|
|
73
|
-
|
|
74
|
-
withdrawExpected
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
return __generator(this, function (_a) {
|
|
79
|
-
switch (_a.label) {
|
|
80
|
-
case 0:
|
|
81
|
-
_lpTokenAmount = (0, utils_1.parseUnits)(lpTokenAmount);
|
|
82
|
-
return [4 /*yield*/, common_1._calcExpectedAmounts.call(this, _lpTokenAmount)];
|
|
83
|
-
case 1:
|
|
84
|
-
_expectedAmounts = _a.sent();
|
|
85
|
-
return [4 /*yield*/, this._getRates()];
|
|
86
|
-
case 2:
|
|
87
|
-
_rates = _a.sent();
|
|
88
|
-
_expected = _expectedAmounts.map(function (_amount, i) { return _amount.mul(_rates[i]).div(ethers_1.ethers.BigNumber.from(10).pow(18)); });
|
|
89
|
-
return [2 /*return*/, _expected.map(function (amount, i) { return ethers_1.ethers.utils.formatUnits(amount, _this.underlyingDecimals[i]); })];
|
|
90
|
-
}
|
|
91
|
-
});
|
|
92
|
-
});
|
|
5
|
+
export const withdrawExpectedMixin = {
|
|
6
|
+
async withdrawExpected(lpTokenAmount) {
|
|
7
|
+
const _lpTokenAmount = parseUnits(lpTokenAmount);
|
|
8
|
+
const _expected = await _calcExpectedAmounts.call(this, _lpTokenAmount);
|
|
9
|
+
return _expected.map((amount, i) => curve.formatUnits(amount, this.underlyingDecimals[i]));
|
|
93
10
|
},
|
|
94
11
|
};
|
|
95
12
|
// @ts-ignore
|
|
96
|
-
|
|
97
|
-
withdrawExpected
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
_lpTokenAmount = (0, utils_1.parseUnits)(lpTokenAmount);
|
|
105
|
-
return [4 /*yield*/, common_1._calcExpectedAmounts.call(this, _lpTokenAmount)];
|
|
106
|
-
case 1:
|
|
107
|
-
_expectedWrappedAmounts = _b.sent();
|
|
108
|
-
_expectedWrappedAmounts.unshift(_expectedWrappedAmounts.pop());
|
|
109
|
-
_expectedMetaCoinAmount = _expectedWrappedAmounts[0], _expectedUnderlyingAmounts = _expectedWrappedAmounts.slice(1);
|
|
110
|
-
basePool = new PoolTemplate_1.PoolTemplate(this.basePool);
|
|
111
|
-
if (!(this.basePool === "atricrypto3")) return [3 /*break*/, 3];
|
|
112
|
-
return [4 /*yield*/, common_1._atricrypto3CalcExpectedAmounts.call(basePool, _expectedMetaCoinAmount)];
|
|
113
|
-
case 2:
|
|
114
|
-
_a = _b.sent();
|
|
115
|
-
return [3 /*break*/, 5];
|
|
116
|
-
case 3: return [4 /*yield*/, common_1._calcExpectedAmounts.call(basePool, _expectedMetaCoinAmount)];
|
|
117
|
-
case 4:
|
|
118
|
-
_a = _b.sent();
|
|
119
|
-
_b.label = 5;
|
|
120
|
-
case 5:
|
|
121
|
-
_basePoolExpectedAmounts = _a;
|
|
122
|
-
_expected = __spreadArray(__spreadArray([], _expectedUnderlyingAmounts, true), _basePoolExpectedAmounts, true);
|
|
123
|
-
return [2 /*return*/, _expected.map(function (amount, i) { return ethers_1.ethers.utils.formatUnits(amount, _this.underlyingDecimals[i]); })];
|
|
124
|
-
}
|
|
125
|
-
});
|
|
126
|
-
});
|
|
13
|
+
export const withdrawExpectedLendingOrCryptoMixin = {
|
|
14
|
+
async withdrawExpected(lpTokenAmount) {
|
|
15
|
+
const _lpTokenAmount = parseUnits(lpTokenAmount);
|
|
16
|
+
const _expectedAmounts = await _calcExpectedAmounts.call(this, _lpTokenAmount);
|
|
17
|
+
// @ts-ignore
|
|
18
|
+
const _rates = await this._getRates();
|
|
19
|
+
const _expected = _expectedAmounts.map((_amount, i) => _amount * _rates[i] / (10n ** 18n));
|
|
20
|
+
return _expected.map((amount, i) => curve.formatUnits(amount, this.underlyingDecimals[i]));
|
|
127
21
|
},
|
|
128
22
|
};
|
|
129
23
|
// @ts-ignore
|
|
130
|
-
|
|
131
|
-
withdrawExpected
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
return __generator(this, function (_a) {
|
|
136
|
-
switch (_a.label) {
|
|
137
|
-
case 0:
|
|
138
|
-
_lpTokenAmount = (0, utils_1.parseUnits)(lpTokenAmount);
|
|
139
|
-
return [4 /*yield*/, common_1._atricrypto3CalcExpectedAmounts.call(this, _lpTokenAmount)];
|
|
140
|
-
case 1:
|
|
141
|
-
_expected = _a.sent();
|
|
142
|
-
return [2 /*return*/, _expected.map(function (amount, i) { return ethers_1.ethers.utils.formatUnits(amount, _this.underlyingDecimals[i]); })];
|
|
143
|
-
}
|
|
144
|
-
});
|
|
145
|
-
});
|
|
24
|
+
export const withdrawExpectedMetaMixin = {
|
|
25
|
+
async withdrawExpected(lpTokenAmount) {
|
|
26
|
+
const _lpTokenAmount = parseUnits(lpTokenAmount);
|
|
27
|
+
const _expected = await _calcExpectedUnderlyingAmountsMeta.call(this, _lpTokenAmount);
|
|
28
|
+
return _expected.map((amount, i) => curve.formatUnits(amount, this.underlyingDecimals[i]));
|
|
146
29
|
},
|
|
147
30
|
};
|
|
148
31
|
// @ts-ignore
|
|
149
|
-
|
|
150
|
-
withdrawWrappedExpected
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
return __generator(this, function (_a) {
|
|
155
|
-
switch (_a.label) {
|
|
156
|
-
case 0:
|
|
157
|
-
_lpTokenAmount = (0, utils_1.parseUnits)(lpTokenAmount);
|
|
158
|
-
return [4 /*yield*/, common_1._calcExpectedAmounts.call(this, _lpTokenAmount)];
|
|
159
|
-
case 1:
|
|
160
|
-
_expected = _a.sent();
|
|
161
|
-
return [2 /*return*/, _expected.map(function (amount, i) { return ethers_1.ethers.utils.formatUnits(amount, _this.wrappedDecimals[i]); })];
|
|
162
|
-
}
|
|
163
|
-
});
|
|
164
|
-
});
|
|
32
|
+
export const withdrawWrappedExpectedMixin = {
|
|
33
|
+
async withdrawWrappedExpected(lpTokenAmount) {
|
|
34
|
+
const _lpTokenAmount = parseUnits(lpTokenAmount);
|
|
35
|
+
const _expected = await _calcExpectedAmounts.call(this, _lpTokenAmount);
|
|
36
|
+
return _expected.map((amount, i) => curve.formatUnits(amount, this.wrappedDecimals[i]));
|
|
165
37
|
},
|
|
166
38
|
};
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { PoolTemplate } from "../PoolTemplate";
|
|
1
|
+
import { PoolTemplate } from "../PoolTemplate.js";
|
|
2
2
|
export declare const withdrawImbalanceMetaFactoryMixin: PoolTemplate;
|
|
3
3
|
export declare const withdrawImbalanceZapMixin: PoolTemplate;
|
|
4
4
|
export declare const withdrawImbalanceLendingMixin: PoolTemplate;
|