@curvefi/api 2.63.0 → 2.63.2
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 +19 -19
- 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 +1 -1
- package/lib/constants/utils.js +18 -19
- package/lib/constants/volumeNetworks.js +1 -1
- package/lib/curve.d.ts +10 -6
- 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 +34 -34
- 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 +46 -6
- package/lib/pools/PoolTemplate.js +1774 -3027
- 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 +11 -31
- 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 +8 -7
- package/lib/utils.js +540 -927
- package/package.json +3 -2
|
@@ -1,14 +1,3 @@
|
|
|
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
1
|
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
13
2
|
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
14
3
|
return new (P || (P = Promise))(function (resolve, reject) {
|
|
@@ -18,359 +7,185 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
|
|
|
18
7
|
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
19
8
|
});
|
|
20
9
|
};
|
|
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
|
-
};
|
|
48
10
|
import { curve } from "../../curve.js";
|
|
49
11
|
import { _ensureAllowance, _getCoinDecimals, fromBN, hasAllowance, isEth, toBN, parseUnits, mulBy1_3, DIGas, smartNumber } from '../../utils.js';
|
|
50
12
|
// @ts-ignore
|
|
51
|
-
function _swapCheck(inputCoin, outputCoin, amount, estimateGas) {
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
return [4 /*yield*/, hasAllowance([this.underlyingCoinAddresses[i]], [amount], curve.signerAddress, contractAddress)];
|
|
71
|
-
case 2:
|
|
72
|
-
_c = !(_d.sent());
|
|
73
|
-
_d.label = 3;
|
|
74
|
-
case 3:
|
|
75
|
-
if (_c) {
|
|
76
|
-
throw Error("Token allowance is needed to estimate gas");
|
|
77
|
-
}
|
|
78
|
-
if (!!estimateGas) return [3 /*break*/, 5];
|
|
79
|
-
return [4 /*yield*/, curve.updateFeeData()];
|
|
80
|
-
case 4:
|
|
81
|
-
_d.sent();
|
|
82
|
-
_d.label = 5;
|
|
83
|
-
case 5:
|
|
84
|
-
_amount = parseUnits(amount, this.underlyingDecimals[i]);
|
|
85
|
-
return [2 /*return*/, [i, j, _amount]];
|
|
86
|
-
}
|
|
87
|
-
});
|
|
13
|
+
function _swapCheck(inputCoin, outputCoin, amount, estimateGas = false) {
|
|
14
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
15
|
+
// @ts-ignore
|
|
16
|
+
const contractAddress = this._swapContractAddress();
|
|
17
|
+
// @ts-ignore
|
|
18
|
+
const i = this._getCoinIdx(inputCoin);
|
|
19
|
+
// @ts-ignore
|
|
20
|
+
const j = this._getCoinIdx(outputCoin);
|
|
21
|
+
const inputCoinBalance = Object.values(yield this.wallet.underlyingCoinBalances())[i];
|
|
22
|
+
if (Number(inputCoinBalance) < Number(amount)) {
|
|
23
|
+
throw Error(`Not enough ${this.underlyingCoins[i]}. Actual: ${inputCoinBalance}, required: ${amount}`);
|
|
24
|
+
}
|
|
25
|
+
if (estimateGas && !(yield hasAllowance([this.underlyingCoinAddresses[i]], [amount], curve.signerAddress, contractAddress))) {
|
|
26
|
+
throw Error("Token allowance is needed to estimate gas");
|
|
27
|
+
}
|
|
28
|
+
if (!estimateGas)
|
|
29
|
+
yield curve.updateFeeData();
|
|
30
|
+
const _amount = parseUnits(amount, this.underlyingDecimals[i]);
|
|
31
|
+
return [i, j, _amount];
|
|
88
32
|
});
|
|
89
33
|
}
|
|
90
|
-
function _swapMinAmount(i, j, _amount, slippage) {
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
case 1:
|
|
98
|
-
_expected = _a.sent();
|
|
99
|
-
outputCoinDecimals = _getCoinDecimals(this.underlyingCoinAddresses[j])[0];
|
|
100
|
-
minAmountBN = toBN(_expected, outputCoinDecimals).times(100 - slippage).div(100);
|
|
101
|
-
return [2 /*return*/, fromBN(minAmountBN, outputCoinDecimals)];
|
|
102
|
-
}
|
|
103
|
-
});
|
|
34
|
+
function _swapMinAmount(i, j, _amount, slippage = 0.5) {
|
|
35
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
36
|
+
// @ts-ignore
|
|
37
|
+
const _expected = yield this._swapExpected(i, j, _amount);
|
|
38
|
+
const [outputCoinDecimals] = _getCoinDecimals(this.underlyingCoinAddresses[j]);
|
|
39
|
+
const minAmountBN = toBN(_expected, outputCoinDecimals).times(100 - slippage).div(100);
|
|
40
|
+
return fromBN(minAmountBN, outputCoinDecimals);
|
|
104
41
|
});
|
|
105
42
|
}
|
|
106
43
|
// @ts-ignore
|
|
107
|
-
export
|
|
44
|
+
export const swapTricrypto2Mixin = {
|
|
108
45
|
// @ts-ignore
|
|
109
|
-
_swap
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
_minRecvAmount = _a.sent();
|
|
125
|
-
contract = curve.contracts[contractAddress].contract;
|
|
126
|
-
exchangeMethod = 'exchange_underlying' in contract ? 'exchange_underlying' : 'exchange';
|
|
127
|
-
value = isEth(this.underlyingCoinAddresses[i]) ? _amount : curve.parseUnits("0");
|
|
128
|
-
return [4 /*yield*/, contract[exchangeMethod].estimateGas(i, j, _amount, _minRecvAmount, true, __assign(__assign({}, curve.constantOptions), { value: value }))];
|
|
129
|
-
case 4:
|
|
130
|
-
gas = _a.sent();
|
|
131
|
-
if (estimateGas)
|
|
132
|
-
return [2 /*return*/, smartNumber(gas)];
|
|
133
|
-
gasLimit = mulBy1_3(DIGas(gas));
|
|
134
|
-
return [4 /*yield*/, contract[exchangeMethod](i, j, _amount, _minRecvAmount, true, __assign(__assign({}, curve.options), { value: value, gasLimit: gasLimit }))];
|
|
135
|
-
case 5: return [2 /*return*/, (_a.sent()).hash];
|
|
136
|
-
}
|
|
137
|
-
});
|
|
46
|
+
_swap(i, j, _amount, slippage, estimateGas = false) {
|
|
47
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
48
|
+
// @ts-ignore
|
|
49
|
+
const contractAddress = this._swapContractAddress();
|
|
50
|
+
if (!estimateGas)
|
|
51
|
+
yield _ensureAllowance([this.underlyingCoinAddresses[i]], [_amount], contractAddress);
|
|
52
|
+
const _minRecvAmount = yield _swapMinAmount.call(this, i, j, _amount, slippage);
|
|
53
|
+
const contract = curve.contracts[contractAddress].contract;
|
|
54
|
+
const exchangeMethod = 'exchange_underlying' in contract ? 'exchange_underlying' : 'exchange';
|
|
55
|
+
const value = isEth(this.underlyingCoinAddresses[i]) ? _amount : curve.parseUnits("0");
|
|
56
|
+
const gas = yield contract[exchangeMethod].estimateGas(i, j, _amount, _minRecvAmount, true, Object.assign(Object.assign({}, curve.constantOptions), { value }));
|
|
57
|
+
if (estimateGas)
|
|
58
|
+
return smartNumber(gas);
|
|
59
|
+
const gasLimit = mulBy1_3(DIGas(gas));
|
|
60
|
+
return (yield contract[exchangeMethod](i, j, _amount, _minRecvAmount, true, Object.assign(Object.assign({}, curve.options), { value, gasLimit }))).hash;
|
|
138
61
|
});
|
|
139
62
|
},
|
|
140
|
-
swapEstimateGas
|
|
141
|
-
return __awaiter(this, void 0, void 0, function () {
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
case 1:
|
|
147
|
-
_a = _b.sent(), i = _a[0], j = _a[1], _amount = _a[2];
|
|
148
|
-
return [4 /*yield*/, this._swap(i, j, _amount, 0.1, true)];
|
|
149
|
-
case 2:
|
|
150
|
-
// @ts-ignore
|
|
151
|
-
return [2 /*return*/, _b.sent()];
|
|
152
|
-
}
|
|
153
|
-
});
|
|
63
|
+
swapEstimateGas(inputCoin, outputCoin, amount) {
|
|
64
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
65
|
+
// @ts-ignore
|
|
66
|
+
const [i, j, _amount] = yield _swapCheck.call(this, inputCoin, outputCoin, amount, true);
|
|
67
|
+
// @ts-ignore
|
|
68
|
+
return yield this._swap(i, j, _amount, 0.1, true);
|
|
154
69
|
});
|
|
155
70
|
},
|
|
156
|
-
swap
|
|
157
|
-
return __awaiter(this, void 0, void 0, function () {
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
case 1:
|
|
163
|
-
_a = _b.sent(), i = _a[0], j = _a[1], _amount = _a[2];
|
|
164
|
-
return [4 /*yield*/, this._swap(i, j, _amount, slippage)];
|
|
165
|
-
case 2:
|
|
166
|
-
// @ts-ignore
|
|
167
|
-
return [2 /*return*/, _b.sent()];
|
|
168
|
-
}
|
|
169
|
-
});
|
|
71
|
+
swap(inputCoin, outputCoin, amount, slippage) {
|
|
72
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
73
|
+
// @ts-ignore
|
|
74
|
+
const [i, j, _amount] = yield _swapCheck.call(this, inputCoin, outputCoin, amount);
|
|
75
|
+
// @ts-ignore
|
|
76
|
+
return yield this._swap(i, j, _amount, slippage);
|
|
170
77
|
});
|
|
171
78
|
},
|
|
172
79
|
};
|
|
173
80
|
// @ts-ignore
|
|
174
|
-
export
|
|
81
|
+
export const swapMetaFactoryMixin = {
|
|
175
82
|
// @ts-ignore
|
|
176
|
-
_swap
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
_minRecvAmount = _a.sent();
|
|
192
|
-
contract = curve.contracts[contractAddress].contract;
|
|
193
|
-
exchangeMethod = 'exchange_underlying' in contract ? 'exchange_underlying' : 'exchange';
|
|
194
|
-
value = isEth(this.underlyingCoinAddresses[i]) ? _amount : curve.parseUnits("0");
|
|
195
|
-
return [4 /*yield*/, contract[exchangeMethod].estimateGas(this.address, i, j, _amount, _minRecvAmount, __assign(__assign({}, curve.constantOptions), { value: value }))];
|
|
196
|
-
case 4:
|
|
197
|
-
gas = _a.sent();
|
|
198
|
-
if (estimateGas)
|
|
199
|
-
return [2 /*return*/, smartNumber(gas)];
|
|
200
|
-
gasLimit = DIGas(gas) * curve.parseUnits("140", 0) / curve.parseUnits("100", 0);
|
|
201
|
-
return [4 /*yield*/, contract[exchangeMethod](this.address, i, j, _amount, _minRecvAmount, __assign(__assign({}, curve.options), { value: value, gasLimit: gasLimit }))];
|
|
202
|
-
case 5: return [2 /*return*/, (_a.sent()).hash];
|
|
203
|
-
}
|
|
204
|
-
});
|
|
83
|
+
_swap(i, j, _amount, slippage, estimateGas = false) {
|
|
84
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
85
|
+
// @ts-ignore
|
|
86
|
+
const contractAddress = this._swapContractAddress();
|
|
87
|
+
if (!estimateGas)
|
|
88
|
+
yield _ensureAllowance([this.underlyingCoinAddresses[i]], [_amount], contractAddress);
|
|
89
|
+
const _minRecvAmount = yield _swapMinAmount.call(this, i, j, _amount, slippage);
|
|
90
|
+
const contract = curve.contracts[contractAddress].contract;
|
|
91
|
+
const exchangeMethod = 'exchange_underlying' in contract ? 'exchange_underlying' : 'exchange';
|
|
92
|
+
const value = isEth(this.underlyingCoinAddresses[i]) ? _amount : curve.parseUnits("0");
|
|
93
|
+
const gas = yield contract[exchangeMethod].estimateGas(this.address, i, j, _amount, _minRecvAmount, Object.assign(Object.assign({}, curve.constantOptions), { value }));
|
|
94
|
+
if (estimateGas)
|
|
95
|
+
return smartNumber(gas);
|
|
96
|
+
const gasLimit = DIGas(gas) * curve.parseUnits("140", 0) / curve.parseUnits("100", 0);
|
|
97
|
+
return (yield contract[exchangeMethod](this.address, i, j, _amount, _minRecvAmount, Object.assign(Object.assign({}, curve.options), { value, gasLimit }))).hash;
|
|
205
98
|
});
|
|
206
99
|
},
|
|
207
|
-
swapEstimateGas
|
|
208
|
-
return __awaiter(this, void 0, void 0, function () {
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
case 1:
|
|
214
|
-
_a = _b.sent(), i = _a[0], j = _a[1], _amount = _a[2];
|
|
215
|
-
return [4 /*yield*/, this._swap(i, j, _amount, 0.1, true)];
|
|
216
|
-
case 2:
|
|
217
|
-
// @ts-ignore
|
|
218
|
-
return [2 /*return*/, _b.sent()];
|
|
219
|
-
}
|
|
220
|
-
});
|
|
100
|
+
swapEstimateGas(inputCoin, outputCoin, amount) {
|
|
101
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
102
|
+
// @ts-ignore
|
|
103
|
+
const [i, j, _amount] = yield _swapCheck.call(this, inputCoin, outputCoin, amount, true);
|
|
104
|
+
// @ts-ignore
|
|
105
|
+
return yield this._swap(i, j, _amount, 0.1, true);
|
|
221
106
|
});
|
|
222
107
|
},
|
|
223
|
-
swap
|
|
224
|
-
return __awaiter(this, void 0, void 0, function () {
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
case 1:
|
|
230
|
-
_a = _b.sent(), i = _a[0], j = _a[1], _amount = _a[2];
|
|
231
|
-
return [4 /*yield*/, this._swap(i, j, _amount, slippage)];
|
|
232
|
-
case 2:
|
|
233
|
-
// @ts-ignore
|
|
234
|
-
return [2 /*return*/, _b.sent()];
|
|
235
|
-
}
|
|
236
|
-
});
|
|
108
|
+
swap(inputCoin, outputCoin, amount, slippage) {
|
|
109
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
110
|
+
// @ts-ignore
|
|
111
|
+
const [i, j, _amount] = yield _swapCheck.call(this, inputCoin, outputCoin, amount);
|
|
112
|
+
// @ts-ignore
|
|
113
|
+
return yield this._swap(i, j, _amount, slippage);
|
|
237
114
|
});
|
|
238
115
|
},
|
|
239
116
|
};
|
|
240
117
|
// @ts-ignore
|
|
241
|
-
export
|
|
118
|
+
export const swapCryptoMetaFactoryMixin = {
|
|
242
119
|
// @ts-ignore
|
|
243
|
-
_swap
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
_minRecvAmount = _a.sent();
|
|
259
|
-
contract = curve.contracts[contractAddress].contract;
|
|
260
|
-
exchangeMethod = 'exchange_underlying' in contract ? 'exchange_underlying' : 'exchange';
|
|
261
|
-
value = isEth(this.underlyingCoinAddresses[i]) ? _amount : curve.parseUnits("0");
|
|
262
|
-
return [4 /*yield*/, contract[exchangeMethod].estimateGas(this.address, i, j, _amount, _minRecvAmount, true, __assign(__assign({}, curve.constantOptions), { value: value }))];
|
|
263
|
-
case 4:
|
|
264
|
-
gas = _a.sent();
|
|
265
|
-
if (estimateGas)
|
|
266
|
-
return [2 /*return*/, smartNumber(gas)];
|
|
267
|
-
gasLimit = DIGas(gas) * curve.parseUnits("140", 0) / curve.parseUnits("100", 0);
|
|
268
|
-
return [4 /*yield*/, contract[exchangeMethod](this.address, i, j, _amount, _minRecvAmount, true, __assign(__assign({}, curve.options), { value: value, gasLimit: gasLimit }))];
|
|
269
|
-
case 5: return [2 /*return*/, (_a.sent()).hash];
|
|
270
|
-
}
|
|
271
|
-
});
|
|
120
|
+
_swap(i, j, _amount, slippage, estimateGas = false) {
|
|
121
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
122
|
+
// @ts-ignore
|
|
123
|
+
const contractAddress = this._swapContractAddress();
|
|
124
|
+
if (!estimateGas)
|
|
125
|
+
yield _ensureAllowance([this.underlyingCoinAddresses[i]], [_amount], contractAddress);
|
|
126
|
+
const _minRecvAmount = yield _swapMinAmount.call(this, i, j, _amount, slippage);
|
|
127
|
+
const contract = curve.contracts[contractAddress].contract;
|
|
128
|
+
const exchangeMethod = 'exchange_underlying' in contract ? 'exchange_underlying' : 'exchange';
|
|
129
|
+
const value = isEth(this.underlyingCoinAddresses[i]) ? _amount : curve.parseUnits("0");
|
|
130
|
+
const gas = yield contract[exchangeMethod].estimateGas(this.address, i, j, _amount, _minRecvAmount, true, Object.assign(Object.assign({}, curve.constantOptions), { value }));
|
|
131
|
+
if (estimateGas)
|
|
132
|
+
return smartNumber(gas);
|
|
133
|
+
const gasLimit = DIGas(gas) * curve.parseUnits("140", 0) / curve.parseUnits("100", 0);
|
|
134
|
+
return (yield contract[exchangeMethod](this.address, i, j, _amount, _minRecvAmount, true, Object.assign(Object.assign({}, curve.options), { value, gasLimit }))).hash;
|
|
272
135
|
});
|
|
273
136
|
},
|
|
274
|
-
swapEstimateGas
|
|
275
|
-
return __awaiter(this, void 0, void 0, function () {
|
|
276
|
-
|
|
277
|
-
|
|
278
|
-
|
|
279
|
-
|
|
280
|
-
case 1:
|
|
281
|
-
_a = _b.sent(), i = _a[0], j = _a[1], _amount = _a[2];
|
|
282
|
-
return [4 /*yield*/, this._swap(i, j, _amount, 0.1, true)];
|
|
283
|
-
case 2:
|
|
284
|
-
// @ts-ignore
|
|
285
|
-
return [2 /*return*/, _b.sent()];
|
|
286
|
-
}
|
|
287
|
-
});
|
|
137
|
+
swapEstimateGas(inputCoin, outputCoin, amount) {
|
|
138
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
139
|
+
// @ts-ignore
|
|
140
|
+
const [i, j, _amount] = yield _swapCheck.call(this, inputCoin, outputCoin, amount, true);
|
|
141
|
+
// @ts-ignore
|
|
142
|
+
return yield this._swap(i, j, _amount, 0.1, true);
|
|
288
143
|
});
|
|
289
144
|
},
|
|
290
|
-
swap
|
|
291
|
-
return __awaiter(this, void 0, void 0, function () {
|
|
292
|
-
|
|
293
|
-
|
|
294
|
-
|
|
295
|
-
|
|
296
|
-
case 1:
|
|
297
|
-
_a = _b.sent(), i = _a[0], j = _a[1], _amount = _a[2];
|
|
298
|
-
return [4 /*yield*/, this._swap(i, j, _amount, slippage)];
|
|
299
|
-
case 2:
|
|
300
|
-
// @ts-ignore
|
|
301
|
-
return [2 /*return*/, _b.sent()];
|
|
302
|
-
}
|
|
303
|
-
});
|
|
145
|
+
swap(inputCoin, outputCoin, amount, slippage) {
|
|
146
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
147
|
+
// @ts-ignore
|
|
148
|
+
const [i, j, _amount] = yield _swapCheck.call(this, inputCoin, outputCoin, amount);
|
|
149
|
+
// @ts-ignore
|
|
150
|
+
return yield this._swap(i, j, _amount, slippage);
|
|
304
151
|
});
|
|
305
152
|
},
|
|
306
153
|
};
|
|
307
154
|
// @ts-ignore
|
|
308
|
-
export
|
|
155
|
+
export const swapMixin = {
|
|
309
156
|
// @ts-ignore
|
|
310
|
-
_swap
|
|
311
|
-
|
|
312
|
-
|
|
313
|
-
|
|
314
|
-
|
|
315
|
-
|
|
316
|
-
|
|
317
|
-
|
|
318
|
-
|
|
319
|
-
|
|
320
|
-
|
|
321
|
-
|
|
322
|
-
|
|
323
|
-
|
|
324
|
-
|
|
325
|
-
|
|
326
|
-
contract = curve.contracts[contractAddress].contract;
|
|
327
|
-
exchangeMethod = 'exchange_underlying' in contract ? 'exchange_underlying' : 'exchange';
|
|
328
|
-
value = isEth(this.underlyingCoinAddresses[i]) ? _amount : curve.parseUnits("0");
|
|
329
|
-
return [4 /*yield*/, contract[exchangeMethod].estimateGas(i, j, _amount, _minRecvAmount, __assign(__assign({}, curve.constantOptions), { value: value }))];
|
|
330
|
-
case 4:
|
|
331
|
-
gas = _a.sent();
|
|
332
|
-
if (estimateGas)
|
|
333
|
-
return [2 /*return*/, smartNumber(gas)];
|
|
334
|
-
return [4 /*yield*/, curve.updateFeeData()];
|
|
335
|
-
case 5:
|
|
336
|
-
_a.sent();
|
|
337
|
-
gasLimit = curve.chainId === 137 && this.id === 'ren' ? DIGas(gas) * curve.parseUnits("160", 0) / curve.parseUnits("100", 0) : mulBy1_3(DIGas(gas));
|
|
338
|
-
return [4 /*yield*/, contract[exchangeMethod](i, j, _amount, _minRecvAmount, __assign(__assign({}, curve.options), { value: value, gasLimit: gasLimit }))];
|
|
339
|
-
case 6: return [2 /*return*/, (_a.sent()).hash];
|
|
340
|
-
}
|
|
341
|
-
});
|
|
157
|
+
_swap(i, j, _amount, slippage, estimateGas = false) {
|
|
158
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
159
|
+
// @ts-ignore
|
|
160
|
+
const contractAddress = this._swapContractAddress();
|
|
161
|
+
if (!estimateGas)
|
|
162
|
+
yield _ensureAllowance([this.underlyingCoinAddresses[i]], [_amount], contractAddress);
|
|
163
|
+
const _minRecvAmount = yield _swapMinAmount.call(this, i, j, _amount, slippage);
|
|
164
|
+
const contract = curve.contracts[contractAddress].contract;
|
|
165
|
+
const exchangeMethod = 'exchange_underlying' in contract ? 'exchange_underlying' : 'exchange';
|
|
166
|
+
const value = isEth(this.underlyingCoinAddresses[i]) ? _amount : curve.parseUnits("0");
|
|
167
|
+
const gas = yield contract[exchangeMethod].estimateGas(i, j, _amount, _minRecvAmount, Object.assign(Object.assign({}, curve.constantOptions), { value }));
|
|
168
|
+
if (estimateGas)
|
|
169
|
+
return smartNumber(gas);
|
|
170
|
+
yield curve.updateFeeData();
|
|
171
|
+
const gasLimit = curve.chainId === 137 && this.id === 'ren' ? DIGas(gas) * curve.parseUnits("160", 0) / curve.parseUnits("100", 0) : mulBy1_3(DIGas(gas));
|
|
172
|
+
return (yield contract[exchangeMethod](i, j, _amount, _minRecvAmount, Object.assign(Object.assign({}, curve.options), { value, gasLimit }))).hash;
|
|
342
173
|
});
|
|
343
174
|
},
|
|
344
|
-
swapEstimateGas
|
|
345
|
-
return __awaiter(this, void 0, void 0, function () {
|
|
346
|
-
|
|
347
|
-
|
|
348
|
-
|
|
349
|
-
|
|
350
|
-
case 1:
|
|
351
|
-
_a = _b.sent(), i = _a[0], j = _a[1], _amount = _a[2];
|
|
352
|
-
return [4 /*yield*/, this._swap(i, j, _amount, 0.1, true)];
|
|
353
|
-
case 2:
|
|
354
|
-
// @ts-ignore
|
|
355
|
-
return [2 /*return*/, _b.sent()];
|
|
356
|
-
}
|
|
357
|
-
});
|
|
175
|
+
swapEstimateGas(inputCoin, outputCoin, amount) {
|
|
176
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
177
|
+
// @ts-ignore
|
|
178
|
+
const [i, j, _amount] = yield _swapCheck.call(this, inputCoin, outputCoin, amount, true);
|
|
179
|
+
// @ts-ignore
|
|
180
|
+
return yield this._swap(i, j, _amount, 0.1, true);
|
|
358
181
|
});
|
|
359
182
|
},
|
|
360
|
-
swap
|
|
361
|
-
return __awaiter(this, void 0, void 0, function () {
|
|
362
|
-
|
|
363
|
-
|
|
364
|
-
|
|
365
|
-
|
|
366
|
-
case 1:
|
|
367
|
-
_a = _b.sent(), i = _a[0], j = _a[1], _amount = _a[2];
|
|
368
|
-
return [4 /*yield*/, this._swap(i, j, _amount, slippage)];
|
|
369
|
-
case 2:
|
|
370
|
-
// @ts-ignore
|
|
371
|
-
return [2 /*return*/, _b.sent()];
|
|
372
|
-
}
|
|
373
|
-
});
|
|
183
|
+
swap(inputCoin, outputCoin, amount, slippage) {
|
|
184
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
185
|
+
// @ts-ignore
|
|
186
|
+
const [i, j, _amount] = yield _swapCheck.call(this, inputCoin, outputCoin, amount);
|
|
187
|
+
// @ts-ignore
|
|
188
|
+
return yield this._swap(i, j, _amount, slippage);
|
|
374
189
|
});
|
|
375
190
|
},
|
|
376
191
|
};
|