@curvefi/api 2.66.30 → 2.66.31
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.d.ts +33 -32
- package/lib/boosting.js +320 -252
- package/lib/cached.d.ts +4 -3
- package/lib/cached.js +63 -19
- package/lib/constants/utils.d.ts +14 -1
- package/lib/constants/utils.js +21 -6
- package/lib/curve.d.ts +5 -5
- package/lib/curve.js +21 -38
- package/lib/dao.d.ts +32 -31
- package/lib/dao.js +420 -350
- package/lib/external-api.d.ts +1 -1
- package/lib/external-api.js +2 -2
- package/lib/factory/common.d.ts +2 -1
- package/lib/factory/common.js +1 -1
- package/lib/factory/deploy.d.ts +46 -45
- package/lib/factory/deploy.js +630 -551
- package/lib/factory/factory-api.d.ts +3 -2
- package/lib/factory/factory-api.js +22 -23
- package/lib/factory/factory-crypto.d.ts +1 -1
- package/lib/factory/factory-crypto.js +12 -15
- package/lib/factory/factory-tricrypto.d.ts +1 -1
- package/lib/factory/factory-tricrypto.js +14 -15
- package/lib/factory/factory-twocrypto.d.ts +1 -1
- package/lib/factory/factory-twocrypto.js +12 -13
- package/lib/factory/factory.d.ts +4 -3
- package/lib/factory/factory.js +21 -24
- package/lib/index.d.ts +413 -104
- package/lib/index.js +253 -257
- package/lib/interfaces.d.ts +2 -0
- package/lib/pools/PoolTemplate.d.ts +13 -12
- package/lib/pools/PoolTemplate.js +279 -285
- package/lib/pools/mixins/common.js +2 -2
- package/lib/pools/mixins/depositBalancedAmountsMixins.d.ts +12 -4
- package/lib/pools/mixins/depositBalancedAmountsMixins.js +1 -15
- package/lib/pools/mixins/depositMixins.d.ts +25 -5
- package/lib/pools/mixins/depositMixins.js +38 -76
- package/lib/pools/mixins/depositWrappedMixins.d.ts +10 -2
- package/lib/pools/mixins/depositWrappedMixins.js +17 -33
- package/lib/pools/mixins/poolBalancesMixin.d.ts +6 -2
- package/lib/pools/mixins/poolBalancesMixin.js +3 -5
- package/lib/pools/mixins/swapMixins.d.ts +20 -4
- package/lib/pools/mixins/swapMixins.js +36 -70
- package/lib/pools/mixins/swapWrappedMixins.d.ts +19 -4
- package/lib/pools/mixins/swapWrappedMixins.js +32 -60
- package/lib/pools/mixins/withdrawExpectedMixins.d.ts +12 -4
- package/lib/pools/mixins/withdrawExpectedMixins.js +6 -11
- package/lib/pools/mixins/withdrawImbalanceMixins.d.ts +20 -4
- package/lib/pools/mixins/withdrawImbalanceMixins.js +26 -53
- package/lib/pools/mixins/withdrawImbalanceWrappedMixins.d.ts +10 -2
- package/lib/pools/mixins/withdrawImbalanceWrappedMixins.js +12 -27
- package/lib/pools/mixins/withdrawMixins.d.ts +25 -5
- package/lib/pools/mixins/withdrawMixins.js +33 -67
- package/lib/pools/mixins/withdrawOneCoinExpectedMixins.d.ts +12 -4
- package/lib/pools/mixins/withdrawOneCoinExpectedMixins.js +8 -13
- package/lib/pools/mixins/withdrawOneCoinMixins.d.ts +25 -5
- package/lib/pools/mixins/withdrawOneCoinMixins.js +32 -66
- package/lib/pools/mixins/withdrawOneCoinWrappedExpectedMixins.d.ts +6 -2
- package/lib/pools/mixins/withdrawOneCoinWrappedExpectedMixins.js +4 -7
- package/lib/pools/mixins/withdrawOneCoinWrappedMixins.d.ts +10 -2
- package/lib/pools/mixins/withdrawOneCoinWrappedMixins.js +13 -29
- package/lib/pools/mixins/withdrawWrappedMixins.d.ts +10 -2
- package/lib/pools/mixins/withdrawWrappedMixins.js +14 -28
- package/lib/pools/poolConstructor.d.ts +2 -1
- package/lib/pools/poolConstructor.js +27 -28
- package/lib/pools/subClasses/corePool.d.ts +4 -1
- package/lib/pools/subClasses/corePool.js +5 -7
- package/lib/pools/subClasses/gaugePool.d.ts +5 -3
- package/lib/pools/subClasses/gaugePool.js +19 -18
- package/lib/pools/subClasses/statsPool.d.ts +2 -0
- package/lib/pools/subClasses/statsPool.js +22 -10
- package/lib/pools/subClasses/walletPool.d.ts +2 -1
- package/lib/pools/subClasses/walletPool.js +6 -6
- package/lib/pools/utils.d.ts +7 -6
- package/lib/pools/utils.js +316 -297
- package/lib/route-graph.worker.d.ts +2 -2
- package/lib/route-graph.worker.js +4 -6
- package/lib/router.d.ts +12 -11
- package/lib/router.js +331 -295
- package/lib/utils.d.ts +34 -33
- package/lib/utils.js +481 -435
- package/package.json +1 -1
|
@@ -7,185 +7,151 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
|
|
|
7
7
|
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
8
8
|
});
|
|
9
9
|
};
|
|
10
|
-
import {
|
|
11
|
-
import { _ensureAllowance, _getCoinDecimals, fromBN, hasAllowance, isEth, toBN, parseUnits, mulBy1_3, DIGas, smartNumber } from '../../utils.js';
|
|
12
|
-
// @ts-ignore
|
|
10
|
+
import { _ensureAllowance, _getCoinDecimals, DIGas, fromBN, hasAllowance, isEth, mulBy1_3, parseUnits, smartNumber, toBN, } from '../../utils.js';
|
|
13
11
|
function _swapCheck(inputCoin_1, outputCoin_1, amount_1) {
|
|
14
12
|
return __awaiter(this, arguments, void 0, function* (inputCoin, outputCoin, amount, estimateGas = false) {
|
|
15
|
-
// @ts-ignore
|
|
16
13
|
const contractAddress = this._swapContractAddress();
|
|
17
|
-
// @ts-ignore
|
|
18
14
|
const i = this._getCoinIdx(inputCoin);
|
|
19
|
-
// @ts-ignore
|
|
20
15
|
const j = this._getCoinIdx(outputCoin);
|
|
21
16
|
const inputCoinBalance = Object.values(yield this.wallet.underlyingCoinBalances())[i];
|
|
22
17
|
if (Number(inputCoinBalance) < Number(amount)) {
|
|
23
18
|
throw Error(`Not enough ${this.underlyingCoins[i]}. Actual: ${inputCoinBalance}, required: ${amount}`);
|
|
24
19
|
}
|
|
25
|
-
if (estimateGas && !(yield hasAllowance([this.underlyingCoinAddresses[i]], [amount], curve.signerAddress, contractAddress))) {
|
|
20
|
+
if (estimateGas && !(yield hasAllowance.call(this.curve, [this.underlyingCoinAddresses[i]], [amount], this.curve.signerAddress, contractAddress))) {
|
|
26
21
|
throw Error("Token allowance is needed to estimate gas");
|
|
27
22
|
}
|
|
28
23
|
if (!estimateGas)
|
|
29
|
-
yield curve.updateFeeData();
|
|
24
|
+
yield this.curve.updateFeeData();
|
|
30
25
|
const _amount = parseUnits(amount, this.underlyingDecimals[i]);
|
|
31
26
|
return [i, j, _amount];
|
|
32
27
|
});
|
|
33
28
|
}
|
|
34
29
|
function _swapMinAmount(i_1, j_1, _amount_1) {
|
|
35
30
|
return __awaiter(this, arguments, void 0, function* (i, j, _amount, slippage = 0.5) {
|
|
36
|
-
// @ts-ignore
|
|
37
31
|
const _expected = yield this._swapExpected(i, j, _amount);
|
|
38
|
-
const [outputCoinDecimals] = _getCoinDecimals(this.underlyingCoinAddresses[j]);
|
|
32
|
+
const [outputCoinDecimals] = _getCoinDecimals.call(this.curve, this.underlyingCoinAddresses[j]);
|
|
39
33
|
const minAmountBN = toBN(_expected, outputCoinDecimals).times(100 - slippage).div(100);
|
|
40
34
|
return fromBN(minAmountBN, outputCoinDecimals);
|
|
41
35
|
});
|
|
42
36
|
}
|
|
43
|
-
// @ts-ignore
|
|
44
37
|
export const swapTricrypto2Mixin = {
|
|
45
|
-
// @ts-ignore
|
|
46
38
|
_swap(i_1, j_1, _amount_1, slippage_1) {
|
|
47
39
|
return __awaiter(this, arguments, void 0, function* (i, j, _amount, slippage, estimateGas = false) {
|
|
48
|
-
// @ts-ignore
|
|
49
40
|
const contractAddress = this._swapContractAddress();
|
|
50
41
|
if (!estimateGas)
|
|
51
|
-
yield _ensureAllowance([this.underlyingCoinAddresses[i]], [_amount], contractAddress);
|
|
42
|
+
yield _ensureAllowance.call(this.curve, [this.underlyingCoinAddresses[i]], [_amount], contractAddress);
|
|
52
43
|
const _minRecvAmount = yield _swapMinAmount.call(this, i, j, _amount, slippage);
|
|
53
|
-
const contract = curve.contracts[contractAddress].contract;
|
|
44
|
+
const contract = this.curve.contracts[contractAddress].contract;
|
|
54
45
|
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 }));
|
|
46
|
+
const value = isEth(this.underlyingCoinAddresses[i]) ? _amount : this.curve.parseUnits("0");
|
|
47
|
+
const gas = yield contract[exchangeMethod].estimateGas(i, j, _amount, _minRecvAmount, true, Object.assign(Object.assign({}, this.curve.constantOptions), { value }));
|
|
57
48
|
if (estimateGas)
|
|
58
49
|
return smartNumber(gas);
|
|
59
50
|
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;
|
|
51
|
+
return (yield contract[exchangeMethod](i, j, _amount, _minRecvAmount, true, Object.assign(Object.assign({}, this.curve.options), { value, gasLimit }))).hash;
|
|
61
52
|
});
|
|
62
53
|
},
|
|
63
54
|
swapEstimateGas(inputCoin, outputCoin, amount) {
|
|
64
55
|
return __awaiter(this, void 0, void 0, function* () {
|
|
65
|
-
// @ts-ignore
|
|
66
56
|
const [i, j, _amount] = yield _swapCheck.call(this, inputCoin, outputCoin, amount, true);
|
|
67
|
-
|
|
68
|
-
return yield this._swap(i, j, _amount, 0.1, true);
|
|
57
|
+
return yield swapTricrypto2Mixin._swap.call(this, i, j, _amount, 0.1, true);
|
|
69
58
|
});
|
|
70
59
|
},
|
|
71
60
|
swap(inputCoin, outputCoin, amount, slippage) {
|
|
72
61
|
return __awaiter(this, void 0, void 0, function* () {
|
|
73
|
-
// @ts-ignore
|
|
74
62
|
const [i, j, _amount] = yield _swapCheck.call(this, inputCoin, outputCoin, amount);
|
|
75
|
-
|
|
76
|
-
return yield this._swap(i, j, _amount, slippage);
|
|
63
|
+
return yield swapTricrypto2Mixin._swap.call(this, i, j, _amount, slippage);
|
|
77
64
|
});
|
|
78
65
|
},
|
|
79
66
|
};
|
|
80
|
-
// @ts-ignore
|
|
81
67
|
export const swapMetaFactoryMixin = {
|
|
82
|
-
// @ts-ignore
|
|
83
68
|
_swap(i_1, j_1, _amount_1, slippage_1) {
|
|
84
69
|
return __awaiter(this, arguments, void 0, function* (i, j, _amount, slippage, estimateGas = false) {
|
|
85
|
-
// @ts-ignore
|
|
86
70
|
const contractAddress = this._swapContractAddress();
|
|
87
71
|
if (!estimateGas)
|
|
88
|
-
yield _ensureAllowance([this.underlyingCoinAddresses[i]], [_amount], contractAddress);
|
|
72
|
+
yield _ensureAllowance.call(this.curve, [this.underlyingCoinAddresses[i]], [_amount], contractAddress);
|
|
89
73
|
const _minRecvAmount = yield _swapMinAmount.call(this, i, j, _amount, slippage);
|
|
90
|
-
const contract = curve.contracts[contractAddress].contract;
|
|
74
|
+
const contract = this.curve.contracts[contractAddress].contract;
|
|
91
75
|
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 }));
|
|
76
|
+
const value = isEth(this.underlyingCoinAddresses[i]) ? _amount : this.curve.parseUnits("0");
|
|
77
|
+
const gas = yield contract[exchangeMethod].estimateGas(this.address, i, j, _amount, _minRecvAmount, Object.assign(Object.assign({}, this.curve.constantOptions), { value }));
|
|
94
78
|
if (estimateGas)
|
|
95
79
|
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;
|
|
80
|
+
const gasLimit = DIGas(gas) * this.curve.parseUnits("140", 0) / this.curve.parseUnits("100", 0);
|
|
81
|
+
return (yield contract[exchangeMethod](this.address, i, j, _amount, _minRecvAmount, Object.assign(Object.assign({}, this.curve.options), { value, gasLimit }))).hash;
|
|
98
82
|
});
|
|
99
83
|
},
|
|
100
84
|
swapEstimateGas(inputCoin, outputCoin, amount) {
|
|
101
85
|
return __awaiter(this, void 0, void 0, function* () {
|
|
102
|
-
// @ts-ignore
|
|
103
86
|
const [i, j, _amount] = yield _swapCheck.call(this, inputCoin, outputCoin, amount, true);
|
|
104
|
-
|
|
105
|
-
return yield this._swap(i, j, _amount, 0.1, true);
|
|
87
|
+
return yield swapMetaFactoryMixin._swap.call(this, i, j, _amount, 0.1, true);
|
|
106
88
|
});
|
|
107
89
|
},
|
|
108
90
|
swap(inputCoin, outputCoin, amount, slippage) {
|
|
109
91
|
return __awaiter(this, void 0, void 0, function* () {
|
|
110
|
-
// @ts-ignore
|
|
111
92
|
const [i, j, _amount] = yield _swapCheck.call(this, inputCoin, outputCoin, amount);
|
|
112
|
-
|
|
113
|
-
return yield this._swap(i, j, _amount, slippage);
|
|
93
|
+
return yield swapMetaFactoryMixin._swap.call(this, i, j, _amount, slippage);
|
|
114
94
|
});
|
|
115
95
|
},
|
|
116
96
|
};
|
|
117
|
-
// @ts-ignore
|
|
118
97
|
export const swapCryptoMetaFactoryMixin = {
|
|
119
|
-
// @ts-ignore
|
|
120
98
|
_swap(i_1, j_1, _amount_1, slippage_1) {
|
|
121
99
|
return __awaiter(this, arguments, void 0, function* (i, j, _amount, slippage, estimateGas = false) {
|
|
122
|
-
// @ts-ignore
|
|
123
100
|
const contractAddress = this._swapContractAddress();
|
|
124
101
|
if (!estimateGas)
|
|
125
|
-
yield _ensureAllowance([this.underlyingCoinAddresses[i]], [_amount], contractAddress);
|
|
102
|
+
yield _ensureAllowance.call(this.curve, [this.underlyingCoinAddresses[i]], [_amount], contractAddress);
|
|
126
103
|
const _minRecvAmount = yield _swapMinAmount.call(this, i, j, _amount, slippage);
|
|
127
|
-
const contract = curve.contracts[contractAddress].contract;
|
|
104
|
+
const contract = this.curve.contracts[contractAddress].contract;
|
|
128
105
|
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 }));
|
|
106
|
+
const value = isEth(this.underlyingCoinAddresses[i]) ? _amount : this.curve.parseUnits("0");
|
|
107
|
+
const gas = yield contract[exchangeMethod].estimateGas(this.address, i, j, _amount, _minRecvAmount, true, Object.assign(Object.assign({}, this.curve.constantOptions), { value }));
|
|
131
108
|
if (estimateGas)
|
|
132
109
|
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;
|
|
110
|
+
const gasLimit = DIGas(gas) * this.curve.parseUnits("140", 0) / this.curve.parseUnits("100", 0);
|
|
111
|
+
return (yield contract[exchangeMethod](this.address, i, j, _amount, _minRecvAmount, true, Object.assign(Object.assign({}, this.curve.options), { value, gasLimit }))).hash;
|
|
135
112
|
});
|
|
136
113
|
},
|
|
137
114
|
swapEstimateGas(inputCoin, outputCoin, amount) {
|
|
138
115
|
return __awaiter(this, void 0, void 0, function* () {
|
|
139
|
-
// @ts-ignore
|
|
140
116
|
const [i, j, _amount] = yield _swapCheck.call(this, inputCoin, outputCoin, amount, true);
|
|
141
|
-
|
|
142
|
-
return yield this._swap(i, j, _amount, 0.1, true);
|
|
117
|
+
return yield swapCryptoMetaFactoryMixin._swap.call(this, i, j, _amount, 0.1, true);
|
|
143
118
|
});
|
|
144
119
|
},
|
|
145
120
|
swap(inputCoin, outputCoin, amount, slippage) {
|
|
146
121
|
return __awaiter(this, void 0, void 0, function* () {
|
|
147
|
-
// @ts-ignore
|
|
148
122
|
const [i, j, _amount] = yield _swapCheck.call(this, inputCoin, outputCoin, amount);
|
|
149
|
-
|
|
150
|
-
return yield this._swap(i, j, _amount, slippage);
|
|
123
|
+
return yield swapCryptoMetaFactoryMixin._swap.call(this, i, j, _amount, slippage);
|
|
151
124
|
});
|
|
152
125
|
},
|
|
153
126
|
};
|
|
154
|
-
// @ts-ignore
|
|
155
127
|
export const swapMixin = {
|
|
156
|
-
// @ts-ignore
|
|
157
128
|
_swap(i_1, j_1, _amount_1, slippage_1) {
|
|
158
129
|
return __awaiter(this, arguments, void 0, function* (i, j, _amount, slippage, estimateGas = false) {
|
|
159
|
-
// @ts-ignore
|
|
160
130
|
const contractAddress = this._swapContractAddress();
|
|
161
131
|
if (!estimateGas)
|
|
162
|
-
yield _ensureAllowance([this.underlyingCoinAddresses[i]], [_amount], contractAddress);
|
|
132
|
+
yield _ensureAllowance.call(this.curve, [this.underlyingCoinAddresses[i]], [_amount], contractAddress);
|
|
163
133
|
const _minRecvAmount = yield _swapMinAmount.call(this, i, j, _amount, slippage);
|
|
164
|
-
const contract = curve.contracts[contractAddress].contract;
|
|
134
|
+
const contract = this.curve.contracts[contractAddress].contract;
|
|
165
135
|
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 }));
|
|
136
|
+
const value = isEth(this.underlyingCoinAddresses[i]) ? _amount : this.curve.parseUnits("0");
|
|
137
|
+
const gas = yield contract[exchangeMethod].estimateGas(i, j, _amount, _minRecvAmount, Object.assign(Object.assign({}, this.curve.constantOptions), { value }));
|
|
168
138
|
if (estimateGas)
|
|
169
139
|
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;
|
|
140
|
+
yield this.curve.updateFeeData();
|
|
141
|
+
const gasLimit = this.curve.chainId === 137 && this.id === 'ren' ? DIGas(gas) * this.curve.parseUnits("160", 0) / this.curve.parseUnits("100", 0) : mulBy1_3(DIGas(gas));
|
|
142
|
+
return (yield contract[exchangeMethod](i, j, _amount, _minRecvAmount, Object.assign(Object.assign({}, this.curve.options), { value, gasLimit }))).hash;
|
|
173
143
|
});
|
|
174
144
|
},
|
|
175
145
|
swapEstimateGas(inputCoin, outputCoin, amount) {
|
|
176
146
|
return __awaiter(this, void 0, void 0, function* () {
|
|
177
|
-
// @ts-ignore
|
|
178
147
|
const [i, j, _amount] = yield _swapCheck.call(this, inputCoin, outputCoin, amount, true);
|
|
179
|
-
|
|
180
|
-
return yield this._swap(i, j, _amount, 0.1, true);
|
|
148
|
+
return yield swapMixin._swap.call(this, i, j, _amount, 0.1, true);
|
|
181
149
|
});
|
|
182
150
|
},
|
|
183
151
|
swap(inputCoin, outputCoin, amount, slippage) {
|
|
184
152
|
return __awaiter(this, void 0, void 0, function* () {
|
|
185
|
-
// @ts-ignore
|
|
186
153
|
const [i, j, _amount] = yield _swapCheck.call(this, inputCoin, outputCoin, amount);
|
|
187
|
-
|
|
188
|
-
return yield this._swap(i, j, _amount, slippage);
|
|
154
|
+
return yield swapMixin._swap.call(this, i, j, _amount, slippage);
|
|
189
155
|
});
|
|
190
156
|
},
|
|
191
157
|
};
|
|
@@ -1,5 +1,20 @@
|
|
|
1
1
|
import { PoolTemplate } from "../PoolTemplate.js";
|
|
2
|
-
export declare const swapWrappedTricrypto2Mixin:
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
2
|
+
export declare const swapWrappedTricrypto2Mixin: {
|
|
3
|
+
_swapWrapped(this: PoolTemplate, i: number, j: number, _amount: bigint, slippage?: number, estimateGas?: boolean): Promise<string | number | number[]>;
|
|
4
|
+
swapWrappedEstimateGas(this: PoolTemplate, inputCoin: string | number, outputCoin: string | number, amount: number | string): Promise<number>;
|
|
5
|
+
swapWrapped(this: PoolTemplate, inputCoin: string | number, outputCoin: string | number, amount: number | string, slippage?: number): Promise<string>;
|
|
6
|
+
};
|
|
7
|
+
export declare const swapWrappedMixin: {
|
|
8
|
+
_swapWrapped(this: PoolTemplate, i: number, j: number, _amount: bigint, slippage?: number, estimateGas?: boolean): Promise<string | number | number[]>;
|
|
9
|
+
swapWrappedEstimateGas(this: PoolTemplate, inputCoin: string | number, outputCoin: string | number, amount: number | string): Promise<number>;
|
|
10
|
+
swapWrapped(this: PoolTemplate, inputCoin: string | number, outputCoin: string | number, amount: number | string, slippage?: number): Promise<string>;
|
|
11
|
+
};
|
|
12
|
+
export declare const swapWrappedExpectedAndApproveMixin: {
|
|
13
|
+
swapWrappedExpected(this: PoolTemplate, inputCoin: string | number, outputCoin: string | number, amount: number | string): Promise<string>;
|
|
14
|
+
swapWrappedIsApproved(this: PoolTemplate, inputCoin: string | number, amount: number | string): Promise<boolean>;
|
|
15
|
+
swapWrappedApproveEstimateGas(this: PoolTemplate, inputCoin: string | number, amount: number | string): Promise<number | number[]>;
|
|
16
|
+
swapWrappedApprove(this: PoolTemplate, inputCoin: string | number, amount: number | string): Promise<string[]>;
|
|
17
|
+
};
|
|
18
|
+
export declare const swapWrappedRequiredMixin: {
|
|
19
|
+
swapWrappedRequired(this: PoolTemplate, inputCoin: string | number, outputCoin: string | number, amount: number | string): Promise<string>;
|
|
20
|
+
};
|
|
@@ -7,153 +7,125 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
|
|
|
7
7
|
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
8
8
|
});
|
|
9
9
|
};
|
|
10
|
-
import {
|
|
11
|
-
import { _ensureAllowance, _getCoinDecimals, ensureAllowance, ensureAllowanceEstimateGas, fromBN, hasAllowance, isEth, toBN, parseUnits, mulBy1_3, DIGas, smartNumber } from '../../utils.js';
|
|
12
|
-
// @ts-ignore
|
|
10
|
+
import { _ensureAllowance, _getCoinDecimals, DIGas, ensureAllowance, ensureAllowanceEstimateGas, fromBN, hasAllowance, isEth, mulBy1_3, parseUnits, smartNumber, toBN, } from '../../utils.js';
|
|
13
11
|
function _swapWrappedCheck(inputCoin_1, outputCoin_1, amount_1) {
|
|
14
12
|
return __awaiter(this, arguments, void 0, function* (inputCoin, outputCoin, amount, estimateGas = false) {
|
|
15
|
-
// @ts-ignore
|
|
16
13
|
const i = this._getCoinIdx(inputCoin, false);
|
|
17
|
-
// @ts-ignore
|
|
18
14
|
const j = this._getCoinIdx(outputCoin, false);
|
|
19
15
|
const inputCoinBalance = Object.values(yield this.wallet.wrappedCoinBalances())[i];
|
|
20
16
|
if (Number(inputCoinBalance) < Number(amount)) {
|
|
21
17
|
throw Error(`Not enough ${this.wrappedCoins[i]}. Actual: ${inputCoinBalance}, required: ${amount}`);
|
|
22
18
|
}
|
|
23
|
-
if (estimateGas && !(yield hasAllowance([this.wrappedCoinAddresses[i]], [amount], curve.signerAddress, this.address))) {
|
|
19
|
+
if (estimateGas && !(yield hasAllowance.call(this.curve, [this.wrappedCoinAddresses[i]], [amount], this.curve.signerAddress, this.address))) {
|
|
24
20
|
throw Error("Token allowance is needed to estimate gas");
|
|
25
21
|
}
|
|
26
22
|
if (!estimateGas)
|
|
27
|
-
yield curve.updateFeeData();
|
|
23
|
+
yield this.curve.updateFeeData();
|
|
28
24
|
const _amount = parseUnits(amount, this.wrappedDecimals[i]);
|
|
29
25
|
return [i, j, _amount];
|
|
30
26
|
});
|
|
31
27
|
}
|
|
32
28
|
function _swapWrappedMinAmount(i_1, j_1, _amount_1) {
|
|
33
29
|
return __awaiter(this, arguments, void 0, function* (i, j, _amount, slippage = 0.5) {
|
|
34
|
-
|
|
35
|
-
const
|
|
36
|
-
const [outputCoinDecimals] = _getCoinDecimals(this.wrappedCoinAddresses[j]);
|
|
30
|
+
const _expected = yield this._swapWrappedExpected.call(this, i, j, _amount);
|
|
31
|
+
const [outputCoinDecimals] = _getCoinDecimals.call(this.curve, this.wrappedCoinAddresses[j]);
|
|
37
32
|
const minAmountBN = toBN(_expected, outputCoinDecimals).times(100 - slippage).div(100);
|
|
38
33
|
return fromBN(minAmountBN, outputCoinDecimals);
|
|
39
34
|
});
|
|
40
35
|
}
|
|
41
|
-
// @ts-ignore
|
|
42
36
|
export const swapWrappedTricrypto2Mixin = {
|
|
43
|
-
// @ts-ignore
|
|
44
37
|
_swapWrapped(i_1, j_1, _amount_1, slippage_1) {
|
|
45
38
|
return __awaiter(this, arguments, void 0, function* (i, j, _amount, slippage, estimateGas = false) {
|
|
46
39
|
if (!estimateGas)
|
|
47
|
-
yield _ensureAllowance([this.wrappedCoinAddresses[i]], [_amount], this.address);
|
|
40
|
+
yield _ensureAllowance.call(this.curve, [this.wrappedCoinAddresses[i]], [_amount], this.address);
|
|
48
41
|
const _minRecvAmount = yield _swapWrappedMinAmount.call(this, i, j, _amount, slippage);
|
|
49
|
-
const contract = curve.contracts[this.address].contract;
|
|
50
|
-
const value = isEth(this.wrappedCoinAddresses[i]) ? _amount : curve.parseUnits("0");
|
|
51
|
-
const gas = yield contract.exchange.estimateGas(i, j, _amount, _minRecvAmount, false, Object.assign(Object.assign({}, curve.constantOptions), { value }));
|
|
42
|
+
const contract = this.curve.contracts[this.address].contract;
|
|
43
|
+
const value = isEth(this.wrappedCoinAddresses[i]) ? _amount : this.curve.parseUnits("0");
|
|
44
|
+
const gas = yield contract.exchange.estimateGas(i, j, _amount, _minRecvAmount, false, Object.assign(Object.assign({}, this.curve.constantOptions), { value }));
|
|
52
45
|
if (estimateGas)
|
|
53
46
|
return smartNumber(gas);
|
|
54
47
|
const gasLimit = mulBy1_3(DIGas(gas));
|
|
55
|
-
return (yield contract.exchange(i, j, _amount, _minRecvAmount, false, Object.assign(Object.assign({}, curve.options), { value, gasLimit }))).hash;
|
|
48
|
+
return (yield contract.exchange(i, j, _amount, _minRecvAmount, false, Object.assign(Object.assign({}, this.curve.options), { value, gasLimit }))).hash;
|
|
56
49
|
});
|
|
57
50
|
},
|
|
58
51
|
swapWrappedEstimateGas(inputCoin, outputCoin, amount) {
|
|
59
52
|
return __awaiter(this, void 0, void 0, function* () {
|
|
60
|
-
// @ts-ignore
|
|
61
53
|
const [i, j, _amount] = yield _swapWrappedCheck.call(this, inputCoin, outputCoin, amount, true);
|
|
62
|
-
|
|
63
|
-
return yield this._swapWrapped(i, j, _amount, 0.1, true);
|
|
54
|
+
return yield swapWrappedTricrypto2Mixin._swapWrapped.call(this, i, j, _amount, 0.1, true);
|
|
64
55
|
});
|
|
65
56
|
},
|
|
66
57
|
swapWrapped(inputCoin, outputCoin, amount, slippage) {
|
|
67
58
|
return __awaiter(this, void 0, void 0, function* () {
|
|
68
|
-
// @ts-ignore
|
|
69
59
|
const [i, j, _amount] = yield _swapWrappedCheck.call(this, inputCoin, outputCoin, amount);
|
|
70
|
-
|
|
71
|
-
return yield this._swapWrapped(i, j, _amount, slippage);
|
|
60
|
+
return yield swapWrappedTricrypto2Mixin._swapWrapped.call(this, i, j, _amount, slippage);
|
|
72
61
|
});
|
|
73
62
|
},
|
|
74
63
|
};
|
|
75
|
-
// @ts-ignore
|
|
76
64
|
export const swapWrappedMixin = {
|
|
77
|
-
// @ts-ignore
|
|
78
65
|
_swapWrapped(i_1, j_1, _amount_1, slippage_1) {
|
|
79
66
|
return __awaiter(this, arguments, void 0, function* (i, j, _amount, slippage, estimateGas = false) {
|
|
80
67
|
if (!estimateGas)
|
|
81
|
-
yield _ensureAllowance([this.wrappedCoinAddresses[i]], [_amount], this.address);
|
|
68
|
+
yield _ensureAllowance.call(this.curve, [this.wrappedCoinAddresses[i]], [_amount], this.address);
|
|
82
69
|
const _minRecvAmount = yield _swapWrappedMinAmount.call(this, i, j, _amount, slippage);
|
|
83
|
-
const contract = curve.contracts[this.address].contract;
|
|
84
|
-
const value = isEth(this.wrappedCoinAddresses[i]) ? _amount : curve.parseUnits("0");
|
|
85
|
-
const gas = yield contract.exchange.estimateGas(i, j, _amount, _minRecvAmount, Object.assign(Object.assign({}, curve.constantOptions), { value }));
|
|
70
|
+
const contract = this.curve.contracts[this.address].contract;
|
|
71
|
+
const value = isEth(this.wrappedCoinAddresses[i]) ? _amount : this.curve.parseUnits("0");
|
|
72
|
+
const gas = yield contract.exchange.estimateGas(i, j, _amount, _minRecvAmount, Object.assign(Object.assign({}, this.curve.constantOptions), { value }));
|
|
86
73
|
if (estimateGas)
|
|
87
74
|
return smartNumber(gas);
|
|
88
|
-
const gasLimit = curve.chainId === 137 && this.id === 'ren' ? DIGas(gas) * curve.parseUnits("140", 0) / curve.parseUnits("100", 0) : mulBy1_3(DIGas(gas));
|
|
89
|
-
return (yield contract.exchange(i, j, _amount, _minRecvAmount, Object.assign(Object.assign({}, curve.options), { value, gasLimit }))).hash;
|
|
75
|
+
const gasLimit = this.curve.chainId === 137 && this.id === 'ren' ? DIGas(gas) * this.curve.parseUnits("140", 0) / this.curve.parseUnits("100", 0) : mulBy1_3(DIGas(gas));
|
|
76
|
+
return (yield contract.exchange(i, j, _amount, _minRecvAmount, Object.assign(Object.assign({}, this.curve.options), { value, gasLimit }))).hash;
|
|
90
77
|
});
|
|
91
78
|
},
|
|
92
79
|
swapWrappedEstimateGas(inputCoin, outputCoin, amount) {
|
|
93
80
|
return __awaiter(this, void 0, void 0, function* () {
|
|
94
|
-
// @ts-ignore
|
|
95
81
|
const [i, j, _amount] = yield _swapWrappedCheck.call(this, inputCoin, outputCoin, amount, true);
|
|
96
|
-
|
|
97
|
-
return yield this._swapWrapped(i, j, _amount, 0.1, true);
|
|
82
|
+
return yield swapWrappedMixin._swapWrapped.call(this, i, j, _amount, 0.1, true);
|
|
98
83
|
});
|
|
99
84
|
},
|
|
100
85
|
swapWrapped(inputCoin, outputCoin, amount, slippage) {
|
|
101
86
|
return __awaiter(this, void 0, void 0, function* () {
|
|
102
|
-
// @ts-ignore
|
|
103
87
|
const [i, j, _amount] = yield _swapWrappedCheck.call(this, inputCoin, outputCoin, amount);
|
|
104
|
-
|
|
105
|
-
return yield this._swapWrapped(i, j, _amount, slippage);
|
|
88
|
+
return yield swapWrappedMixin._swapWrapped.call(this, i, j, _amount, slippage);
|
|
106
89
|
});
|
|
107
90
|
},
|
|
108
91
|
};
|
|
109
|
-
// @ts-ignore
|
|
110
92
|
export const swapWrappedExpectedAndApproveMixin = {
|
|
111
93
|
swapWrappedExpected(inputCoin, outputCoin, amount) {
|
|
112
94
|
return __awaiter(this, void 0, void 0, function* () {
|
|
113
|
-
// @ts-ignore
|
|
114
95
|
const i = this._getCoinIdx(inputCoin, false);
|
|
115
|
-
// @ts-ignore
|
|
116
96
|
const j = this._getCoinIdx(outputCoin, false);
|
|
117
97
|
const _amount = parseUnits(amount, this.wrappedDecimals[i]);
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
return curve.formatUnits(_expected, this.wrappedDecimals[j]);
|
|
98
|
+
const _expected = yield this._swapWrappedExpected.call(this, i, j, _amount);
|
|
99
|
+
return this.curve.formatUnits(_expected, this.wrappedDecimals[j]);
|
|
121
100
|
});
|
|
122
101
|
},
|
|
123
102
|
swapWrappedIsApproved(inputCoin, amount) {
|
|
124
103
|
return __awaiter(this, void 0, void 0, function* () {
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
return yield hasAllowance([this.wrappedCoinAddresses[i]], [amount], curve.signerAddress, this.address);
|
|
104
|
+
const i = this._getCoinIdx.call(this, inputCoin, false);
|
|
105
|
+
return yield hasAllowance.call(this.curve, [this.wrappedCoinAddresses[i]], [amount], this.curve.signerAddress, this.address);
|
|
128
106
|
});
|
|
129
107
|
},
|
|
130
108
|
swapWrappedApproveEstimateGas(inputCoin, amount) {
|
|
131
109
|
return __awaiter(this, void 0, void 0, function* () {
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
return yield ensureAllowanceEstimateGas([this.wrappedCoinAddresses[i]], [amount], this.address);
|
|
110
|
+
const i = this._getCoinIdx.call(this, inputCoin, false);
|
|
111
|
+
return yield ensureAllowanceEstimateGas.call(this.curve, [this.wrappedCoinAddresses[i]], [amount], this.address);
|
|
135
112
|
});
|
|
136
113
|
},
|
|
137
114
|
swapWrappedApprove(inputCoin, amount) {
|
|
138
115
|
return __awaiter(this, void 0, void 0, function* () {
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
return yield ensureAllowance([this.wrappedCoinAddresses[i]], [amount], this.address);
|
|
116
|
+
const i = this._getCoinIdx.call(this, inputCoin, false);
|
|
117
|
+
return yield ensureAllowance.call(this.curve, [this.wrappedCoinAddresses[i]], [amount], this.address);
|
|
142
118
|
});
|
|
143
119
|
},
|
|
144
120
|
};
|
|
145
|
-
// @ts-ignore
|
|
146
121
|
export const swapWrappedRequiredMixin = {
|
|
147
122
|
swapWrappedRequired(inputCoin, outputCoin, amount) {
|
|
148
123
|
return __awaiter(this, void 0, void 0, function* () {
|
|
149
|
-
|
|
150
|
-
const
|
|
151
|
-
// @ts-ignore
|
|
152
|
-
const j = this._getCoinIdx(outputCoin, false);
|
|
124
|
+
const i = this._getCoinIdx.call(this, inputCoin, false);
|
|
125
|
+
const j = this._getCoinIdx.call(this, outputCoin, false);
|
|
153
126
|
const _amount = parseUnits(amount, this.wrappedDecimals[j]);
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
return curve.formatUnits(_required, this.wrappedDecimals[i]);
|
|
127
|
+
const _required = yield this._swapRequired.call(this, i, j, _amount, false);
|
|
128
|
+
return this.curve.formatUnits(_required, this.wrappedDecimals[i]);
|
|
157
129
|
});
|
|
158
130
|
},
|
|
159
131
|
};
|
|
@@ -1,5 +1,13 @@
|
|
|
1
1
|
import { PoolTemplate } from "../PoolTemplate.js";
|
|
2
|
-
export declare const withdrawExpectedMixin:
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
export declare const
|
|
2
|
+
export declare const withdrawExpectedMixin: {
|
|
3
|
+
withdrawExpected(this: PoolTemplate, lpTokenAmount: number | string): Promise<string[]>;
|
|
4
|
+
};
|
|
5
|
+
export declare const withdrawExpectedLendingOrCryptoMixin: {
|
|
6
|
+
withdrawExpected(this: PoolTemplate, lpTokenAmount: number | string): Promise<string[]>;
|
|
7
|
+
};
|
|
8
|
+
export declare const withdrawExpectedMetaMixin: {
|
|
9
|
+
withdrawExpected(this: PoolTemplate, lpTokenAmount: number | string): Promise<string[]>;
|
|
10
|
+
};
|
|
11
|
+
export declare const withdrawWrappedExpectedMixin: {
|
|
12
|
+
withdrawWrappedExpected(this: PoolTemplate, lpTokenAmount: number | string): Promise<string[]>;
|
|
13
|
+
};
|
|
@@ -7,49 +7,44 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
|
|
|
7
7
|
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
8
8
|
});
|
|
9
9
|
};
|
|
10
|
-
import { curve } from "../../curve.js";
|
|
11
10
|
import { parseUnits } from "../../utils.js";
|
|
12
11
|
import { _calcExpectedAmounts, _calcExpectedUnderlyingAmountsMeta } from "./common.js";
|
|
13
|
-
|
|
12
|
+
import { formatUnits } from "../../constants/utils";
|
|
14
13
|
export const withdrawExpectedMixin = {
|
|
15
14
|
withdrawExpected(lpTokenAmount) {
|
|
16
15
|
return __awaiter(this, void 0, void 0, function* () {
|
|
17
16
|
const _lpTokenAmount = parseUnits(lpTokenAmount);
|
|
18
17
|
const _expected = yield _calcExpectedAmounts.call(this, _lpTokenAmount);
|
|
19
|
-
return _expected.map((amount, i) =>
|
|
18
|
+
return _expected.map((amount, i) => formatUnits(amount, this.underlyingDecimals[i]));
|
|
20
19
|
});
|
|
21
20
|
},
|
|
22
21
|
};
|
|
23
|
-
// @ts-ignore
|
|
24
22
|
export const withdrawExpectedLendingOrCryptoMixin = {
|
|
25
23
|
withdrawExpected(lpTokenAmount) {
|
|
26
24
|
return __awaiter(this, void 0, void 0, function* () {
|
|
27
25
|
const _lpTokenAmount = parseUnits(lpTokenAmount);
|
|
28
26
|
const _expectedAmounts = yield _calcExpectedAmounts.call(this, _lpTokenAmount);
|
|
29
|
-
// @ts-ignore
|
|
30
27
|
const _rates = yield this._getRates();
|
|
31
|
-
const _expected = _expectedAmounts.map((_amount, i) => _amount * _rates[i] /
|
|
32
|
-
return _expected.map((amount, i) =>
|
|
28
|
+
const _expected = _expectedAmounts.map((_amount, i) => _amount * _rates[i] / parseUnits(String(Math.pow(10, 18)), 0));
|
|
29
|
+
return _expected.map((amount, i) => formatUnits(amount, this.underlyingDecimals[i]));
|
|
33
30
|
});
|
|
34
31
|
},
|
|
35
32
|
};
|
|
36
|
-
// @ts-ignore
|
|
37
33
|
export const withdrawExpectedMetaMixin = {
|
|
38
34
|
withdrawExpected(lpTokenAmount) {
|
|
39
35
|
return __awaiter(this, void 0, void 0, function* () {
|
|
40
36
|
const _lpTokenAmount = parseUnits(lpTokenAmount);
|
|
41
37
|
const _expected = yield _calcExpectedUnderlyingAmountsMeta.call(this, _lpTokenAmount);
|
|
42
|
-
return _expected.map((amount, i) =>
|
|
38
|
+
return _expected.map((amount, i) => formatUnits(amount, this.underlyingDecimals[i]));
|
|
43
39
|
});
|
|
44
40
|
},
|
|
45
41
|
};
|
|
46
|
-
// @ts-ignore
|
|
47
42
|
export const withdrawWrappedExpectedMixin = {
|
|
48
43
|
withdrawWrappedExpected(lpTokenAmount) {
|
|
49
44
|
return __awaiter(this, void 0, void 0, function* () {
|
|
50
45
|
const _lpTokenAmount = parseUnits(lpTokenAmount);
|
|
51
46
|
const _expected = yield _calcExpectedAmounts.call(this, _lpTokenAmount);
|
|
52
|
-
return _expected.map((amount, i) =>
|
|
47
|
+
return _expected.map((amount, i) => formatUnits(amount, this.wrappedDecimals[i]));
|
|
53
48
|
});
|
|
54
49
|
},
|
|
55
50
|
};
|
|
@@ -1,5 +1,21 @@
|
|
|
1
1
|
import { PoolTemplate } from "../PoolTemplate.js";
|
|
2
|
-
export declare const withdrawImbalanceMetaFactoryMixin:
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
2
|
+
export declare const withdrawImbalanceMetaFactoryMixin: {
|
|
3
|
+
_withdrawImbalance(this: PoolTemplate, _amounts: bigint[], slippage?: number, estimateGas?: boolean): Promise<string | number | number[]>;
|
|
4
|
+
withdrawImbalanceEstimateGas(this: PoolTemplate, amounts: (number | string)[]): Promise<number>;
|
|
5
|
+
withdrawImbalance(this: PoolTemplate, amounts: (number | string)[], slippage?: number): Promise<string>;
|
|
6
|
+
};
|
|
7
|
+
export declare const withdrawImbalanceZapMixin: {
|
|
8
|
+
_withdrawImbalance(this: PoolTemplate, _amounts: bigint[], slippage?: number, estimateGas?: boolean): Promise<string | number | number[]>;
|
|
9
|
+
withdrawImbalanceEstimateGas(this: PoolTemplate, amounts: (number | string)[]): Promise<number>;
|
|
10
|
+
withdrawImbalance(this: PoolTemplate, amounts: (number | string)[], slippage?: number): Promise<string>;
|
|
11
|
+
};
|
|
12
|
+
export declare const withdrawImbalanceLendingMixin: {
|
|
13
|
+
_withdrawImbalance(this: PoolTemplate, _amounts: bigint[], slippage?: number, estimateGas?: boolean): Promise<string | number | number[]>;
|
|
14
|
+
withdrawImbalanceEstimateGas(this: PoolTemplate, amounts: (number | string)[]): Promise<number>;
|
|
15
|
+
withdrawImbalance(this: PoolTemplate, amounts: (number | string)[], slippage?: number): Promise<string>;
|
|
16
|
+
};
|
|
17
|
+
export declare const withdrawImbalancePlainMixin: {
|
|
18
|
+
_withdrawImbalance(this: PoolTemplate, _amounts: bigint[], slippage?: number, estimateGas?: boolean): Promise<string | number | number[]>;
|
|
19
|
+
withdrawImbalanceEstimateGas(this: PoolTemplate, amounts: (number | string)[]): Promise<number>;
|
|
20
|
+
withdrawImbalance(this: PoolTemplate, amounts: (number | string)[], slippage?: number): Promise<string>;
|
|
21
|
+
};
|