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