@curvefi/llamalend-api 2.2.6 → 2.3.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/.yarn/install-state.gz +0 -0
- package/README.md +23 -26
- package/lib/constants/aliases.js +6 -6
- package/lib/lendMarkets/interfaces/leverageZapV2.d.ts +31 -63
- package/lib/lendMarkets/modules/common/leverageZapV2Base.d.ts +34 -65
- package/lib/lendMarkets/modules/common/leverageZapV2Base.js +107 -127
- package/lib/lendMarkets/modules/v1/leverageV1ZapV2.d.ts +3 -3
- package/lib/lendMarkets/modules/v1/leverageV1ZapV2.js +12 -12
- package/lib/lendMarkets/modules/v2/leverageV2ZapV2.d.ts +3 -3
- package/lib/lendMarkets/modules/v2/leverageV2ZapV2.js +10 -17
- package/lib/utils.d.ts +3 -11
- package/lib/utils.js +2 -10
- package/package.json +2 -2
- package/src/constants/aliases.ts +6 -6
- package/src/lendMarkets/interfaces/leverageZapV2.ts +30 -72
- package/src/lendMarkets/modules/common/leverageZapV2Base.ts +112 -175
- package/src/lendMarkets/modules/v1/leverageV1ZapV2.ts +9 -12
- package/src/lendMarkets/modules/v2/leverageV2ZapV2.ts +7 -17
- package/src/utils.ts +5 -27
|
@@ -60,7 +60,6 @@ export class LeverageV1ZapV2Module extends LeverageZapV2BaseModule {
|
|
|
60
60
|
|
|
61
61
|
protected override async _createLoanContractCall(
|
|
62
62
|
_userCollateral: bigint,
|
|
63
|
-
_userBorrowed: bigint,
|
|
64
63
|
_debt: bigint,
|
|
65
64
|
_minRecv: bigint,
|
|
66
65
|
range: number,
|
|
@@ -68,14 +67,14 @@ export class LeverageV1ZapV2Module extends LeverageZapV2BaseModule {
|
|
|
68
67
|
exchangeCalldata: string,
|
|
69
68
|
estimateGas: boolean
|
|
70
69
|
): Promise<string | TGas> {
|
|
71
|
-
const zapCalldata = buildCalldataForLeverageZapV2(router, exchangeCalldata);
|
|
70
|
+
const zapCalldata = buildCalldataForLeverageZapV2({controllerId: parseUnits(this._getMarketId(), 0), _minRecv ,router, exchangeCalldata});
|
|
72
71
|
const contract = this.llamalend.contracts[this.market.addresses.controller].contract;
|
|
73
72
|
const gas = await contract.create_loan_extended.estimateGas(
|
|
74
73
|
_userCollateral,
|
|
75
74
|
_debt,
|
|
76
75
|
range,
|
|
77
76
|
this._getLeverageZapAddress(),
|
|
78
|
-
[
|
|
77
|
+
[],
|
|
79
78
|
zapCalldata,
|
|
80
79
|
{ ...this.llamalend.constantOptions }
|
|
81
80
|
);
|
|
@@ -88,7 +87,7 @@ export class LeverageV1ZapV2Module extends LeverageZapV2BaseModule {
|
|
|
88
87
|
_debt,
|
|
89
88
|
range,
|
|
90
89
|
this._getLeverageZapAddress(),
|
|
91
|
-
[
|
|
90
|
+
[],
|
|
92
91
|
zapCalldata,
|
|
93
92
|
{ ...this.llamalend.options, gasLimit }
|
|
94
93
|
)).hash;
|
|
@@ -96,20 +95,19 @@ export class LeverageV1ZapV2Module extends LeverageZapV2BaseModule {
|
|
|
96
95
|
|
|
97
96
|
protected override async _borrowMoreContractCall(
|
|
98
97
|
_userCollateral: bigint,
|
|
99
|
-
_userBorrowed: bigint,
|
|
100
98
|
_debt: bigint,
|
|
101
99
|
_minRecv: bigint,
|
|
102
100
|
router: string,
|
|
103
101
|
exchangeCalldata: string,
|
|
104
102
|
estimateGas: boolean
|
|
105
103
|
): Promise<string | TGas> {
|
|
106
|
-
const zapCalldata = buildCalldataForLeverageZapV2(router, exchangeCalldata);
|
|
104
|
+
const zapCalldata = buildCalldataForLeverageZapV2({controllerId: parseUnits(this._getMarketId(), 0), _minRecv,router, exchangeCalldata});
|
|
107
105
|
const contract = this.llamalend.contracts[this.market.addresses.controller].contract;
|
|
108
106
|
const gas = await contract.borrow_more_extended.estimateGas(
|
|
109
107
|
_userCollateral,
|
|
110
108
|
_debt,
|
|
111
109
|
this._getLeverageZapAddress(),
|
|
112
|
-
[
|
|
110
|
+
[],
|
|
113
111
|
zapCalldata,
|
|
114
112
|
{ ...this.llamalend.constantOptions }
|
|
115
113
|
);
|
|
@@ -121,7 +119,7 @@ export class LeverageV1ZapV2Module extends LeverageZapV2BaseModule {
|
|
|
121
119
|
_userCollateral,
|
|
122
120
|
_debt,
|
|
123
121
|
this._getLeverageZapAddress(),
|
|
124
|
-
[
|
|
122
|
+
[],
|
|
125
123
|
zapCalldata,
|
|
126
124
|
{ ...this.llamalend.options, gasLimit }
|
|
127
125
|
)).hash;
|
|
@@ -129,17 +127,16 @@ export class LeverageV1ZapV2Module extends LeverageZapV2BaseModule {
|
|
|
129
127
|
|
|
130
128
|
protected override async _repayContractCall(
|
|
131
129
|
_userCollateral: bigint,
|
|
132
|
-
_userBorrowed: bigint,
|
|
133
130
|
_minRecv: bigint,
|
|
134
131
|
router: string,
|
|
135
132
|
exchangeCalldata: string,
|
|
136
133
|
estimateGas: boolean
|
|
137
134
|
): Promise<string | TGas> {
|
|
138
|
-
const zapCalldata = buildCalldataForLeverageZapV2(router, exchangeCalldata);
|
|
135
|
+
const zapCalldata = buildCalldataForLeverageZapV2({controllerId: parseUnits(this._getMarketId(), 0), _minRecv ,router, exchangeCalldata});
|
|
139
136
|
const contract = this.llamalend.contracts[this.market.addresses.controller].contract;
|
|
140
137
|
const gas = await contract.repay_extended.estimateGas(
|
|
141
138
|
this._getLeverageZapAddress(),
|
|
142
|
-
[
|
|
139
|
+
[],
|
|
143
140
|
zapCalldata
|
|
144
141
|
);
|
|
145
142
|
if (estimateGas) return smartNumber(gas);
|
|
@@ -148,7 +145,7 @@ export class LeverageV1ZapV2Module extends LeverageZapV2BaseModule {
|
|
|
148
145
|
const gasLimit = _mulBy1_3(DIGas(gas));
|
|
149
146
|
return (await contract.repay_extended(
|
|
150
147
|
this._getLeverageZapAddress(),
|
|
151
|
-
[
|
|
148
|
+
[],
|
|
152
149
|
zapCalldata,
|
|
153
150
|
{ ...this.llamalend.options, gasLimit }
|
|
154
151
|
)).hash;
|
|
@@ -6,7 +6,7 @@ import {
|
|
|
6
6
|
_mulBy1_3,
|
|
7
7
|
DIGas,
|
|
8
8
|
MAX_ACTIVE_BAND,
|
|
9
|
-
|
|
9
|
+
buildCalldataForLeverageZapV2,
|
|
10
10
|
} from "../../../utils";
|
|
11
11
|
|
|
12
12
|
export class LeverageV2ZapV2Module extends LeverageZapV2BaseModule {
|
|
@@ -66,7 +66,6 @@ export class LeverageV2ZapV2Module extends LeverageZapV2BaseModule {
|
|
|
66
66
|
|
|
67
67
|
protected override async _createLoanContractCall(
|
|
68
68
|
_userCollateral: bigint,
|
|
69
|
-
_userBorrowed: bigint,
|
|
70
69
|
_debt: bigint,
|
|
71
70
|
_minRecv: bigint,
|
|
72
71
|
range: number,
|
|
@@ -77,11 +76,9 @@ export class LeverageV2ZapV2Module extends LeverageZapV2BaseModule {
|
|
|
77
76
|
const contract = this.llamalend.contracts[this.market.addresses.controller].contract;
|
|
78
77
|
const _for = _getAddress.call(this.llamalend, '');
|
|
79
78
|
const _callbacker = this._getLeverageZapAddress();
|
|
80
|
-
const zapCalldata =
|
|
81
|
-
op: 'create_loan',
|
|
79
|
+
const zapCalldata = buildCalldataForLeverageZapV2({
|
|
82
80
|
controllerId: this._getMarketId(),
|
|
83
|
-
|
|
84
|
-
minRecv: _minRecv,
|
|
81
|
+
_minRecv,
|
|
85
82
|
router,
|
|
86
83
|
exchangeCalldata,
|
|
87
84
|
});
|
|
@@ -112,7 +109,6 @@ export class LeverageV2ZapV2Module extends LeverageZapV2BaseModule {
|
|
|
112
109
|
|
|
113
110
|
protected override async _borrowMoreContractCall(
|
|
114
111
|
_userCollateral: bigint,
|
|
115
|
-
_userBorrowed: bigint,
|
|
116
112
|
_debt: bigint,
|
|
117
113
|
_minRecv: bigint,
|
|
118
114
|
router: string,
|
|
@@ -122,11 +118,9 @@ export class LeverageV2ZapV2Module extends LeverageZapV2BaseModule {
|
|
|
122
118
|
const contract = this.llamalend.contracts[this.market.addresses.controller].contract;
|
|
123
119
|
const _for = _getAddress.call(this.llamalend, '');
|
|
124
120
|
const _callbacker = this._getLeverageZapAddress();
|
|
125
|
-
const zapCalldata =
|
|
126
|
-
op: 'borrow_more',
|
|
121
|
+
const zapCalldata = buildCalldataForLeverageZapV2({
|
|
127
122
|
controllerId: this._getMarketId(),
|
|
128
|
-
|
|
129
|
-
minRecv: _minRecv,
|
|
123
|
+
_minRecv,
|
|
130
124
|
router,
|
|
131
125
|
exchangeCalldata,
|
|
132
126
|
});
|
|
@@ -155,7 +149,6 @@ export class LeverageV2ZapV2Module extends LeverageZapV2BaseModule {
|
|
|
155
149
|
|
|
156
150
|
protected override async _repayContractCall(
|
|
157
151
|
_userCollateral: bigint,
|
|
158
|
-
_userBorrowed: bigint,
|
|
159
152
|
_minRecv: bigint,
|
|
160
153
|
router: string,
|
|
161
154
|
exchangeCalldata: string,
|
|
@@ -164,12 +157,9 @@ export class LeverageV2ZapV2Module extends LeverageZapV2BaseModule {
|
|
|
164
157
|
const contract = this.llamalend.contracts[this.market.addresses.controller].contract;
|
|
165
158
|
const _for = _getAddress.call(this.llamalend, '');
|
|
166
159
|
const _callbacker = this._getLeverageZapAddress();
|
|
167
|
-
const zapCalldata =
|
|
168
|
-
op: 'repay',
|
|
160
|
+
const zapCalldata = buildCalldataForLeverageZapV2({
|
|
169
161
|
controllerId: this._getMarketId(),
|
|
170
|
-
|
|
171
|
-
userBorrowed: _userBorrowed,
|
|
172
|
-
minRecv: _minRecv,
|
|
162
|
+
_minRecv,
|
|
173
163
|
router,
|
|
174
164
|
exchangeCalldata,
|
|
175
165
|
});
|
package/src/utils.ts
CHANGED
|
@@ -484,43 +484,21 @@ export const calculateFutureLeverage = (
|
|
|
484
484
|
}
|
|
485
485
|
};
|
|
486
486
|
|
|
487
|
-
export const buildCalldataForLeverageZapV2 = (routerAddress: string, exchangeCalldata: string): string => {
|
|
488
|
-
const cleanCalldata = exchangeCalldata.startsWith('0x') ? exchangeCalldata.slice(2) : exchangeCalldata;
|
|
489
|
-
|
|
490
|
-
const abiCoder = ethers.AbiCoder.defaultAbiCoder();
|
|
491
|
-
return abiCoder.encode(
|
|
492
|
-
['address', 'bytes'],
|
|
493
|
-
[routerAddress, '0x' + cleanCalldata]
|
|
494
|
-
);
|
|
495
|
-
};
|
|
496
|
-
|
|
497
|
-
// - create_loan / borrow_more: (uint256 controllerId, uint256 userBorrowed, uint256 minRecv, address router, bytes exchangeCalldata)
|
|
498
|
-
// - repay: (uint256 controllerId, uint256 userCollateral, uint256 userBorrowed, uint256 minRecv, address router, bytes exchangeCalldata)
|
|
499
487
|
export type LeverageZapV2LLv2CalldataParams = {
|
|
500
488
|
controllerId: number | string | bigint;
|
|
501
|
-
|
|
489
|
+
_minRecv: bigint;
|
|
502
490
|
router: string;
|
|
503
491
|
exchangeCalldata: string;
|
|
504
|
-
}
|
|
505
|
-
{ op: 'create_loan' | 'borrow_more'; userBorrowed: bigint }
|
|
506
|
-
| {op: 'repay'; userCollateral: bigint; userBorrowed: bigint }
|
|
507
|
-
);
|
|
492
|
+
}
|
|
508
493
|
|
|
509
|
-
export const
|
|
494
|
+
export const buildCalldataForLeverageZapV2 = (params: LeverageZapV2LLv2CalldataParams): string => {
|
|
510
495
|
const cleanCalldata = params.exchangeCalldata.startsWith('0x') ? params.exchangeCalldata.slice(2) : params.exchangeCalldata;
|
|
511
496
|
const exchangeBytes = '0x' + cleanCalldata;
|
|
512
497
|
const abiCoder = ethers.AbiCoder.defaultAbiCoder();
|
|
513
498
|
|
|
514
|
-
if (params.op === 'repay') {
|
|
515
|
-
return abiCoder.encode(
|
|
516
|
-
['uint256', 'uint256', 'uint256', 'uint256', 'address', 'bytes'],
|
|
517
|
-
[BigInt(params.controllerId), params.userCollateral, params.userBorrowed, params.minRecv, params.router, exchangeBytes]
|
|
518
|
-
);
|
|
519
|
-
}
|
|
520
|
-
|
|
521
499
|
return abiCoder.encode(
|
|
522
|
-
['uint256', 'uint256', '
|
|
523
|
-
[BigInt(params.controllerId), params.
|
|
500
|
+
['uint256', 'uint256', 'address', 'bytes'],
|
|
501
|
+
[BigInt(params.controllerId), params._minRecv, params.router, exchangeBytes]
|
|
524
502
|
);
|
|
525
503
|
};
|
|
526
504
|
|