@defisaver/sdk 0.2.2 → 0.2.5
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/index.js +11 -2
- package/package.json +1 -1
- package/src/Action.js +21 -9
- package/src/ActionWithL2.js +36 -0
- package/src/actions/aave/AaveBorrowAction.js +11 -2
- package/src/actions/aave/AaveClaimStkAaveAction.js +5 -5
- package/src/actions/aave/AaveCollateralSwitchAction.js +5 -4
- package/src/actions/aave/AavePaybackAction.js +11 -2
- package/src/actions/aave/AaveSupplyAction.js +6 -6
- package/src/actions/aave/AaveWithdrawAction.js +8 -1
- package/src/actions/aaveV3/AaveV3ATokenPaybackAction.js +58 -0
- package/src/actions/aaveV3/AaveV3BorrowAction.js +59 -0
- package/src/actions/aaveV3/AaveV3ClaimRewardsAction.js +45 -0
- package/src/actions/aaveV3/AaveV3CollateralSwitchAction.js +45 -0
- package/src/actions/aaveV3/AaveV3PaybackAction.js +68 -0
- package/src/actions/aaveV3/AaveV3SetEModeAction.js +40 -0
- package/src/actions/aaveV3/AaveV3SupplyAction.js +69 -0
- package/src/actions/aaveV3/AaveV3SwapBorrowRateModeAction.js +43 -0
- package/src/actions/aaveV3/AaveV3WithdrawAction.js +46 -0
- package/src/actions/aaveV3/index.js +21 -0
- package/src/actions/balancer/BalancerV2ClaimAction.js +12 -10
- package/src/actions/balancer/BalancerV2SupplyAction.js +16 -14
- package/src/actions/balancer/BalancerV2WithdrawAction.js +17 -15
- package/src/actions/basic/AutomationV2Unsub.js +3 -3
- package/src/actions/basic/ChangeProxyOwnerAction.js +4 -2
- package/src/actions/basic/GasFeeAction.js +6 -6
- package/src/actions/basic/PullTokenAction.js +9 -3
- package/src/actions/basic/SellAction.js +6 -5
- package/src/actions/basic/SendTokenAction.js +9 -4
- package/src/actions/basic/SubInputsAction.js +8 -3
- package/src/actions/basic/SumInputsAction.js +8 -3
- package/src/actions/basic/TokenBalanceAction.js +3 -3
- package/src/actions/basic/UnwrapEthAction.js +18 -5
- package/src/actions/basic/WrapEthAction.js +15 -5
- package/src/actions/basic/index.js +0 -4
- package/src/actions/checkers/MakerRatioCheckAction.js +5 -5
- package/src/actions/compound/CompoundBorrowAction.js +7 -1
- package/src/actions/compound/CompoundClaimAction.js +3 -3
- package/src/actions/compound/CompoundCollateralSwitchAction.js +4 -2
- package/src/actions/compound/CompoundGetDebtAction.js +3 -3
- package/src/actions/compound/CompoundPaybackAction.js +7 -1
- package/src/actions/compound/CompoundSupplyAction.js +4 -4
- package/src/actions/compound/CompoundWithdrawAction.js +7 -1
- package/src/actions/curve/CurveClaimFeesAction.js +4 -4
- package/src/actions/curve/CurveDepositAction.js +7 -7
- package/src/actions/curve/CurveGaugeDepositAction.js +6 -6
- package/src/actions/curve/CurveGaugeWithdrawAction.js +4 -4
- package/src/actions/curve/CurveMintCrvAction.js +3 -3
- package/src/actions/curve/CurveStethPoolDepositAction.js +7 -7
- package/src/actions/curve/CurveStethPoolWithdrawAction.js +7 -7
- package/src/actions/curve/CurveSwapAction.js +15 -15
- package/src/actions/curve/CurveWithdrawAction.js +7 -7
- package/src/actions/dydx/DyDxWithdrawAction.js +7 -1
- package/src/actions/flashloan/AaveV2FlashLoanAction.js +2 -2
- package/src/actions/flashloan/AaveV3FlashLoanAction.js +26 -0
- package/src/actions/flashloan/AaveV3FlashLoanPaybackAction.js +17 -0
- package/src/actions/flashloan/BalancerFlashLoanAction.js +2 -2
- package/src/actions/flashloan/DyDxFlashLoanAction.js +1 -5
- package/src/actions/flashloan/MakerFlashLoanAction.js +2 -2
- package/src/actions/flashloan/index.js +4 -0
- package/src/actions/guni/GUniDeposit.js +9 -9
- package/src/actions/guni/GUniWithdraw.js +5 -5
- package/src/actions/index.js +2 -0
- package/src/actions/insta/InstPullTokensAction.js +4 -4
- package/src/actions/lido/LidoStakeAction.js +7 -2
- package/src/actions/lido/LidoUnwrapAction.js +7 -2
- package/src/actions/lido/LidoWrapAction.js +7 -7
- package/src/actions/liquity/LiquityBorrowAction.js +5 -5
- package/src/actions/liquity/LiquityClaimAction.js +3 -3
- package/src/actions/liquity/LiquityCloseAction.js +4 -4
- package/src/actions/liquity/LiquityEthGainToTroveAction.js +3 -3
- package/src/actions/liquity/LiquityOpenAction.js +8 -8
- package/src/actions/liquity/LiquityPaybackAction.js +5 -5
- package/src/actions/liquity/LiquityRedeemAction.js +7 -7
- package/src/actions/liquity/LiquitySPDepositAction.js +7 -7
- package/src/actions/liquity/LiquitySPWithdrawAction.js +6 -6
- package/src/actions/liquity/LiquityStakeAction.js +7 -7
- package/src/actions/liquity/LiquitySupplyAction.js +5 -5
- package/src/actions/liquity/LiquityUnstakeAction.js +6 -6
- package/src/actions/liquity/LiquityWithdrawAction.js +4 -4
- package/src/actions/maker/MakerClaimAction.js +4 -4
- package/src/actions/maker/MakerGenerateAction.js +8 -1
- package/src/actions/maker/MakerGiveAction.js +4 -4
- package/src/actions/maker/MakerMergeAction.js +7 -1
- package/src/actions/maker/MakerOpenVaultAction.js +6 -1
- package/src/actions/maker/MakerPaybackAction.js +9 -2
- package/src/actions/maker/MakerRatioAction.js +5 -1
- package/src/actions/maker/MakerSupplyAction.js +9 -1
- package/src/actions/maker/MakerWithdrawAction.js +9 -1
- package/src/actions/mstable/MStableClaimAction.js +4 -4
- package/src/actions/mstable/MStableDepositAction.js +16 -16
- package/src/actions/mstable/MStableWithdrawAction.js +15 -15
- package/src/actions/rari/RariDepositAction.js +5 -5
- package/src/actions/rari/RariWithdrawAction.js +6 -6
- package/src/actions/reflexer/ReflexerGenerateAction.js +7 -1
- package/src/actions/reflexer/ReflexerNativeUniV2SaviourDepositAction.js +5 -5
- package/src/actions/reflexer/ReflexerNativeUniV2SaviourGetReservesAction.js +8 -3
- package/src/actions/reflexer/ReflexerNativeUniV2SaviourWithdrawAction.js +9 -4
- package/src/actions/reflexer/ReflexerOpenSafeAction.js +5 -1
- package/src/actions/reflexer/ReflexerPaybackAction.js +7 -1
- package/src/actions/reflexer/ReflexerSupplyAction.js +8 -1
- package/src/actions/reflexer/ReflexerWithdrawAction.js +8 -1
- package/src/actions/uniswap/UniswapSupplyAction.js +22 -20
- package/src/actions/uniswap/UniswapWithdrawAction.js +18 -16
- package/src/actions/uniswapV3/UniswapV3CollectAction.js +9 -7
- package/src/actions/uniswapV3/UniswapV3CreatePoolAction.js +22 -20
- package/src/actions/uniswapV3/UniswapV3MintAction.js +21 -19
- package/src/actions/uniswapV3/UniswapV3SupplyAction.js +19 -17
- package/src/actions/uniswapV3/UniswapV3WithdrawAction.js +14 -12
- package/src/actions/yearn/YearnSupplyAction.js +6 -6
- package/src/actions/yearn/YearnWithdrawAction.js +6 -6
- package/src/addresses.js +187 -143
- package/src/config.js +83 -0
- package/src/triggers/ChainLinkPriceTrigger.js +2 -2
- package/src/triggers/CompoundRatioTrigger.js +1 -1
- package/src/triggers/GasPriceTrigger.js +1 -1
- package/src/triggers/LiquityRatioTrigger.js +2 -2
- package/src/triggers/MakerRatioTrigger.js +5 -1
- package/src/triggers/ReflexerRatioTrigger.js +1 -1
- package/src/triggers/TimestampTrigger.js +1 -1
- package/src/triggers/UniV3CurrentTickTrigger.js +1 -1
- package/src/types.js +33 -0
- package/test/Action.js +1 -2
- package/test/accessLists/access-lists.js +2 -1
- package/test/actions/maker/MakerPaybackAction.js +2 -2
- package/test/index.js +4 -1
- package/src/actions/basic/SendTokenAndUnwrapAction.js +0 -30
- package/src/actions/basic/UpdateSubAction.js +0 -19
package/index.js
CHANGED
|
@@ -2,6 +2,9 @@ const Action = require('./src/Action');
|
|
|
2
2
|
const Recipe = require('./src/Recipe');
|
|
3
3
|
const Strategy = require('./src/Strategy');
|
|
4
4
|
const DfsWeb3 = require('./src/DfsWeb3');
|
|
5
|
+
const {
|
|
6
|
+
configure, getNetworkData, CONFIG, NETWORKS,
|
|
7
|
+
} = require('./src/config');
|
|
5
8
|
|
|
6
9
|
const actions = require('./src/actions/');
|
|
7
10
|
const triggers = require('./src/triggers/');
|
|
@@ -12,9 +15,15 @@ module.exports = {
|
|
|
12
15
|
Action,
|
|
13
16
|
Recipe,
|
|
14
17
|
Strategy,
|
|
18
|
+
DfsWeb3,
|
|
19
|
+
|
|
15
20
|
actions,
|
|
16
21
|
triggers,
|
|
17
|
-
actionAddresses,
|
|
18
22
|
utils,
|
|
19
|
-
|
|
23
|
+
|
|
24
|
+
configure,
|
|
25
|
+
getNetworkData,
|
|
26
|
+
networks: NETWORKS,
|
|
27
|
+
actionAddressesAllChains: actionAddresses,
|
|
28
|
+
actionAddresses: () => actionAddresses[CONFIG.chainId],
|
|
20
29
|
}
|
package/package.json
CHANGED
package/src/Action.js
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
const AbiCoder = require('web3-eth-abi');
|
|
2
2
|
const { keccak256, padLeft, toHex } = require('web3-utils');
|
|
3
|
+
const { CONFIG } = require('./config');
|
|
3
4
|
|
|
4
5
|
const ActionAbi = require('./abis/Action.json');
|
|
5
6
|
|
|
@@ -107,9 +108,16 @@ class Action {
|
|
|
107
108
|
* @private
|
|
108
109
|
*/
|
|
109
110
|
_encodeForCall() {
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
111
|
+
return this.args.map((arg, i) => {
|
|
112
|
+
let paramType = this.paramTypes[i];
|
|
113
|
+
let _arg = this._replaceWithPlaceholders(arg, paramType);
|
|
114
|
+
let _paramType = this._formatType(paramType);
|
|
115
|
+
return AbiCoder.encodeParameter(_paramType, _arg);
|
|
116
|
+
});
|
|
117
|
+
}
|
|
118
|
+
|
|
119
|
+
encodeForL2DsProxyCall() {
|
|
120
|
+
throw new Error('Not L2'); // TODO improve this
|
|
113
121
|
}
|
|
114
122
|
|
|
115
123
|
/**
|
|
@@ -117,11 +125,15 @@ class Action {
|
|
|
117
125
|
* @returns {Array<string>} `address` & `data` to be passed on to DSProxy's `execute(address _target, bytes memory _data)`
|
|
118
126
|
*/
|
|
119
127
|
encodeForDsProxyCall() {
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
128
|
+
if (CONFIG.chainId === 1) {
|
|
129
|
+
const executeActionDirectAbi = ActionAbi.find(({ name }) => name === 'executeActionDirect');
|
|
130
|
+
return [
|
|
131
|
+
this.contractAddress,
|
|
132
|
+
AbiCoder.encodeFunctionCall(executeActionDirectAbi, this._encodeForCall()),
|
|
133
|
+
];
|
|
134
|
+
} else {
|
|
135
|
+
return [this.contractAddress, this.encodeForL2DsProxyCall()];
|
|
136
|
+
}
|
|
125
137
|
}
|
|
126
138
|
|
|
127
139
|
/**
|
|
@@ -140,7 +152,7 @@ class Action {
|
|
|
140
152
|
encodeForStrategy(subSlots) {
|
|
141
153
|
return [
|
|
142
154
|
this.getId(),
|
|
143
|
-
|
|
155
|
+
this._getArgumentMappingWithSlots(subSlots), // paramMappings
|
|
144
156
|
]
|
|
145
157
|
}
|
|
146
158
|
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
const Action = require('./Action');
|
|
2
|
+
const Dec = require('decimal.js');
|
|
3
|
+
|
|
4
|
+
class ActionWithL2 extends Action {
|
|
5
|
+
/**
|
|
6
|
+
* Encode arguments for calling the action via DsProxy
|
|
7
|
+
* @returns {string}
|
|
8
|
+
*/
|
|
9
|
+
encodeForL2DsProxyCall() { return this.encodeInputs(); }
|
|
10
|
+
|
|
11
|
+
encodeInputs() { throw new Error('Use implementation from specific ActionWithL2'); }
|
|
12
|
+
|
|
13
|
+
addressToBytes20(address) { return address.slice(2); }
|
|
14
|
+
|
|
15
|
+
boolToBytes1(bool) { return bool ? '01' : '00' }
|
|
16
|
+
|
|
17
|
+
async getEthValue() { return '0'; }
|
|
18
|
+
|
|
19
|
+
numberToBytes2(number){
|
|
20
|
+
const hexNumber = number.toString(16);
|
|
21
|
+
return hexNumber.padStart(4, '0');
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
numberToBytes1(number){
|
|
25
|
+
const hexNumber = number.toString(16);
|
|
26
|
+
return hexNumber.padStart(2, '0');
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
numberToBytes32(number){
|
|
30
|
+
let hexNumber = new Dec(number).toHex();
|
|
31
|
+
hexNumber = hexNumber.slice(2);
|
|
32
|
+
|
|
33
|
+
return hexNumber.padStart(64, '0');
|
|
34
|
+
}
|
|
35
|
+
}
|
|
36
|
+
module.exports = ActionWithL2;
|
|
@@ -19,9 +19,18 @@ class AaveBorrowAction extends Action {
|
|
|
19
19
|
super(
|
|
20
20
|
'AaveBorrow',
|
|
21
21
|
getAddr('AaveBorrow'),
|
|
22
|
-
['address', 'address', 'uint256', 'uint256', 'address', 'address'],
|
|
23
|
-
[market, tokenAddr, amount, rateMode, to, onBehalf],
|
|
22
|
+
[['address', 'address', 'uint256', 'uint256', 'address', 'address']],
|
|
23
|
+
[[market, tokenAddr, amount, rateMode, to, onBehalf]],
|
|
24
24
|
);
|
|
25
|
+
|
|
26
|
+
this.mappableArgs = [
|
|
27
|
+
this.args[0][0],
|
|
28
|
+
this.args[0][1],
|
|
29
|
+
this.args[0][2],
|
|
30
|
+
this.args[0][3],
|
|
31
|
+
this.args[0][4],
|
|
32
|
+
this.args[0][5],
|
|
33
|
+
];
|
|
25
34
|
}
|
|
26
35
|
}
|
|
27
36
|
|
|
@@ -11,13 +11,13 @@ class AaveClaimStkAaveAction extends Action {
|
|
|
11
11
|
super(
|
|
12
12
|
'AaveClaimStkAave',
|
|
13
13
|
getAddr('AaveClaimStkAave'),
|
|
14
|
-
['address[]', 'uint256', 'address'],
|
|
15
|
-
[...arguments],
|
|
14
|
+
[['address[]', 'uint256', 'address']],
|
|
15
|
+
[[...arguments]],
|
|
16
16
|
);
|
|
17
17
|
this.mappableArgs = [
|
|
18
|
-
this.args[1],
|
|
19
|
-
this.args[2],
|
|
20
|
-
|
|
18
|
+
this.args[0][1],
|
|
19
|
+
this.args[0][2],
|
|
20
|
+
];
|
|
21
21
|
}
|
|
22
22
|
}
|
|
23
23
|
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
const Action = require("../../Action");
|
|
2
2
|
const {requireAddress} = require("../../utils/general.js");
|
|
3
|
-
const {getAddr} = require('../../addresses.js');
|
|
3
|
+
const { getAddr } = require('../../addresses.js');
|
|
4
4
|
|
|
5
5
|
/**
|
|
6
6
|
* AaveCollateralSwitchAction - Aave enable/disable token usage as collateral
|
|
@@ -10,10 +10,11 @@ class AaveCollateralSwitchAction extends Action {
|
|
|
10
10
|
super(
|
|
11
11
|
'AaveCollateralSwitch',
|
|
12
12
|
getAddr('AaveCollateralSwitch'),
|
|
13
|
-
['address', 'address[]', 'bool[]'],
|
|
14
|
-
[...arguments],
|
|
13
|
+
[['address', 'address[]', 'bool[]']],
|
|
14
|
+
[[...arguments]],
|
|
15
15
|
);
|
|
16
|
-
this.mappableArgs = [
|
|
16
|
+
this.mappableArgs = [
|
|
17
|
+
];
|
|
17
18
|
}
|
|
18
19
|
}
|
|
19
20
|
|
|
@@ -17,9 +17,18 @@ class AavePaybackAction extends Action {
|
|
|
17
17
|
constructor(market, tokenAddr, amount, rateMode, from, onBehalf = getAddr('Empty')) {
|
|
18
18
|
super('AavePayback',
|
|
19
19
|
getAddr('AavePayback'),
|
|
20
|
-
['address', 'address', 'uint256', 'uint256', 'address', 'address'],
|
|
21
|
-
[market, tokenAddr, amount, rateMode, from, onBehalf],
|
|
20
|
+
[['address', 'address', 'uint256', 'uint256', 'address', 'address']],
|
|
21
|
+
[[market, tokenAddr, amount, rateMode, from, onBehalf]],
|
|
22
22
|
);
|
|
23
|
+
|
|
24
|
+
this.mappableArgs = [
|
|
25
|
+
this.args[0][0],
|
|
26
|
+
this.args[0][1],
|
|
27
|
+
this.args[0][2],
|
|
28
|
+
this.args[0][3],
|
|
29
|
+
this.args[0][4],
|
|
30
|
+
this.args[0][5],
|
|
31
|
+
];
|
|
23
32
|
}
|
|
24
33
|
|
|
25
34
|
async getAssetsToApprove() {
|
|
@@ -15,14 +15,14 @@ class AaveSupplyAction extends Action {
|
|
|
15
15
|
* @param enableAsColl {boolean} If we need to enable asset as collateral
|
|
16
16
|
*/
|
|
17
17
|
constructor(market, tokenAddr, amount, from, onBehalf = getAddr('Empty'), enableAsColl) {
|
|
18
|
-
super('AaveSupply', getAddr('AaveSupply'), ['address','address','uint256','address','address','bool'], [market, tokenAddr, amount, from, onBehalf, enableAsColl]);
|
|
18
|
+
super('AaveSupply', getAddr('AaveSupply'), [['address','address','uint256','address','address','bool']], [[market, tokenAddr, amount, from, onBehalf, enableAsColl]]);
|
|
19
19
|
|
|
20
20
|
this.mappableArgs = [
|
|
21
|
-
this.args[0],
|
|
22
|
-
this.args[1],
|
|
23
|
-
this.args[2],
|
|
24
|
-
this.args[3],
|
|
25
|
-
this.args[4],
|
|
21
|
+
this.args[0][0],
|
|
22
|
+
this.args[0][1],
|
|
23
|
+
this.args[0][2],
|
|
24
|
+
this.args[0][3],
|
|
25
|
+
this.args[0][4],
|
|
26
26
|
];
|
|
27
27
|
}
|
|
28
28
|
|
|
@@ -14,7 +14,14 @@ class AaveWithdrawAction extends Action {
|
|
|
14
14
|
*/
|
|
15
15
|
constructor(market, tokenAddr, amount, to) {
|
|
16
16
|
requireAddress(to);
|
|
17
|
-
super('AaveWithdraw', getAddr('AaveWithdraw'), ['address','address','uint256','address'], [...arguments]);
|
|
17
|
+
super('AaveWithdraw', getAddr('AaveWithdraw'), [['address','address','uint256','address']], [[...arguments]]);
|
|
18
|
+
|
|
19
|
+
this.mappableArgs = [
|
|
20
|
+
this.args[0][0],
|
|
21
|
+
this.args[0][1],
|
|
22
|
+
this.args[0][2],
|
|
23
|
+
this.args[0][3],
|
|
24
|
+
];
|
|
18
25
|
}
|
|
19
26
|
}
|
|
20
27
|
|
|
@@ -0,0 +1,58 @@
|
|
|
1
|
+
const ActionWithL2 = require("../../ActionWithL2");
|
|
2
|
+
const { getAssetInfoByAddress } = require("@defisaver/tokens");
|
|
3
|
+
const { getAddr } = require('../../addresses.js');
|
|
4
|
+
|
|
5
|
+
/**
|
|
6
|
+
* AaveV3ATokenPaybackAction - Repay Aave V3 debt using aTokens
|
|
7
|
+
*/
|
|
8
|
+
class AaveV3ATokenPaybackAction extends ActionWithL2 {
|
|
9
|
+
/**
|
|
10
|
+
* @param useDefaultMarket {boolean} If this is true it defaults to the hardcoded market in contract
|
|
11
|
+
* @param market {EthAddress} Address provider for specific market
|
|
12
|
+
* @param amount {string} Amount of tokens to be payed back (uint.max for full debt)
|
|
13
|
+
* @param from {EthAddress} Where are we pulling the payback aTokens from
|
|
14
|
+
* @param rateMode {number} Type of borrow debt [Stable: 1, Variable: 2]
|
|
15
|
+
* @param aTokenAddr {EthAddress} address of the aToken to be pulled
|
|
16
|
+
* @param assetId {number} The id of the underlying asset to be repaid
|
|
17
|
+
*/
|
|
18
|
+
constructor(useDefaultMarket, market, amount, from, rateMode, aTokenAddr, assetId) {
|
|
19
|
+
super('AaveV3ATokenPayback', getAddr('AaveV3ATokenPayback'),
|
|
20
|
+
[['uint256','address','uint8','uint16', 'bool', 'address']],
|
|
21
|
+
[[amount, from, rateMode, assetId, useDefaultMarket, market]]
|
|
22
|
+
);
|
|
23
|
+
|
|
24
|
+
this.mappableArgs = [
|
|
25
|
+
this.args[0][0],
|
|
26
|
+
this.args[0][1],
|
|
27
|
+
this.args[0][5],
|
|
28
|
+
];
|
|
29
|
+
this.addressForApproval = aTokenAddr;
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
async getAssetsToApprove() {
|
|
33
|
+
const asset = getAssetInfoByAddress(this.addressForApproval);
|
|
34
|
+
if (asset.symbol !== 'ETH') return [{asset: this.addressForApproval, owner: this.args[0][2]}];
|
|
35
|
+
return [];
|
|
36
|
+
}
|
|
37
|
+
encodeInputs() {
|
|
38
|
+
// executeActionDirectL2
|
|
39
|
+
let encodedInput = "0x2895f3aa";
|
|
40
|
+
// amount
|
|
41
|
+
encodedInput = encodedInput.concat(this.numberToBytes32(this.args[0][0]));
|
|
42
|
+
// from
|
|
43
|
+
encodedInput = encodedInput.concat(this.addressToBytes20(this.args[0][1]));
|
|
44
|
+
// rateMode
|
|
45
|
+
encodedInput = encodedInput.concat(this.numberToBytes1(this.args[0][2]));
|
|
46
|
+
// assetId
|
|
47
|
+
encodedInput = encodedInput.concat(this.numberToBytes2(this.args[0][3]));
|
|
48
|
+
// useDefaultMarket
|
|
49
|
+
encodedInput = encodedInput.concat(this.boolToBytes1(this.args[0][4]))
|
|
50
|
+
if (!this.args[0][4]){
|
|
51
|
+
// market
|
|
52
|
+
encodedInput = encodedInput.concat(this.addressToBytes20(this.args[0][5]));
|
|
53
|
+
}
|
|
54
|
+
return encodedInput;
|
|
55
|
+
}
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
module.exports = AaveV3ATokenPaybackAction;
|
|
@@ -0,0 +1,59 @@
|
|
|
1
|
+
const ActionWithL2 = require("../../ActionWithL2");
|
|
2
|
+
const { getAddr } = require('../../addresses.js');
|
|
3
|
+
|
|
4
|
+
/**
|
|
5
|
+
* AaveV3BorrowAction - Borrow a token from AaveV3
|
|
6
|
+
*/
|
|
7
|
+
class AaveV3BorrowAction extends ActionWithL2 {
|
|
8
|
+
/**
|
|
9
|
+
* @param useDefaultMarket {boolean} If this is true it defaults to the hardcoded market in contract
|
|
10
|
+
* @param market {EthAddress} Address provider for specific market
|
|
11
|
+
* @param amount {string} Amount of tokens to be borrowed
|
|
12
|
+
* @param to {EthAddress} The address we are sending the borrowed tokens to
|
|
13
|
+
* @param rateMode {number} Type of borrow debt [Stable: 1, Variable: 2]
|
|
14
|
+
* @param assetId {number} The id of the token to be borrowed
|
|
15
|
+
* @param useOnBehalf {boolean} use on behalf or default to proxy
|
|
16
|
+
* @param [onBehalf] {EthAddress} On whose behalf we borrow the tokens, defaults to proxy
|
|
17
|
+
*/
|
|
18
|
+
constructor(useDefaultMarket, market, amount, to, rateMode, assetId, useOnBehalf , onBehalf = getAddr('Empty')) {
|
|
19
|
+
super('AaveV3Borrow', getAddr('AaveV3Borrow'),
|
|
20
|
+
[['uint256','address','uint8','uint16','bool','bool','address','address']],
|
|
21
|
+
[[amount, to, rateMode, assetId, useDefaultMarket, useOnBehalf, market, onBehalf]]
|
|
22
|
+
);
|
|
23
|
+
|
|
24
|
+
this.mappableArgs = [
|
|
25
|
+
this.args[0][0],
|
|
26
|
+
this.args[0][1],
|
|
27
|
+
this.args[0][6],
|
|
28
|
+
this.args[0][7],
|
|
29
|
+
];
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
encodeInputs() {
|
|
33
|
+
// executeActionDirectL2
|
|
34
|
+
let encodedInput = "0x2895f3aa";
|
|
35
|
+
// amount
|
|
36
|
+
encodedInput = encodedInput.concat(this.numberToBytes32(this.args[0][0]));
|
|
37
|
+
// to
|
|
38
|
+
encodedInput = encodedInput.concat(this.addressToBytes20(this.args[0][1]));
|
|
39
|
+
// rateMode
|
|
40
|
+
encodedInput = encodedInput.concat(this.numberToBytes1(this.args[0][2]));
|
|
41
|
+
// assetId
|
|
42
|
+
encodedInput = encodedInput.concat(this.numberToBytes2(this.args[0][3]));
|
|
43
|
+
// useDefaultMarket
|
|
44
|
+
encodedInput = encodedInput.concat(this.boolToBytes1(this.args[0][4]))
|
|
45
|
+
// useOnBehalf
|
|
46
|
+
encodedInput = encodedInput.concat(this.boolToBytes1(this.args[0][5]));
|
|
47
|
+
if (!this.args[0][4]) {
|
|
48
|
+
// market
|
|
49
|
+
encodedInput = encodedInput.concat(this.addressToBytes20(this.args[0][6]));
|
|
50
|
+
}
|
|
51
|
+
if (this.args[0][5]) {
|
|
52
|
+
// onBehalf
|
|
53
|
+
encodedInput = encodedInput.concat(this.addressToBytes20(this.args[0][7]));
|
|
54
|
+
}
|
|
55
|
+
return encodedInput;
|
|
56
|
+
}
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
module.exports = AaveV3BorrowAction;
|
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
const ActionWithL2 = require("../../ActionWithL2");
|
|
2
|
+
const { getAddr } = require('../../addresses.js');
|
|
3
|
+
|
|
4
|
+
/**
|
|
5
|
+
* AaveV3ClaimRewardsAction
|
|
6
|
+
*/
|
|
7
|
+
class AaveV3ClaimRewardsAction extends ActionWithL2 {
|
|
8
|
+
/**
|
|
9
|
+
* @param assetsLength {number} Address provider for specific market
|
|
10
|
+
* @param amount {string} length of two arrays
|
|
11
|
+
* @param to {EthAddress}
|
|
12
|
+
* @param reward {EthAddress}
|
|
13
|
+
* @param assets {Array<EthAddress>}
|
|
14
|
+
*/
|
|
15
|
+
constructor(assetsLength, amount, to, reward, assets) {
|
|
16
|
+
super(
|
|
17
|
+
'AaveV3ClaimRewards',
|
|
18
|
+
getAddr('AaveV3ClaimRewards'),
|
|
19
|
+
[['uint8', 'uint256', 'address', 'address', 'address[]']],
|
|
20
|
+
[[assetsLength, amount, to, reward, assets]],
|
|
21
|
+
);
|
|
22
|
+
}
|
|
23
|
+
encodeInputs() {
|
|
24
|
+
// executeActionDirectL2
|
|
25
|
+
let encodedInput = "0x2895f3aa";
|
|
26
|
+
// assetsLength
|
|
27
|
+
encodedInput = encodedInput.concat(this.numberToBytes1(this.args[0][0]));
|
|
28
|
+
// amount
|
|
29
|
+
encodedInput = encodedInput.concat(this.numberToBytes32(this.args[0][1]));
|
|
30
|
+
// to
|
|
31
|
+
encodedInput = encodedInput.concat(this.addressToBytes20(this.args[0][2]));
|
|
32
|
+
// reward
|
|
33
|
+
encodedInput = encodedInput.concat(this.addressToBytes20(this.args[0][3]));
|
|
34
|
+
// assets
|
|
35
|
+
const arrayLength = this.args[0][0];
|
|
36
|
+
for (let i = 0; i < arrayLength; i++){
|
|
37
|
+
// assets[i]
|
|
38
|
+
encodedInput = encodedInput.concat(this.addressToBytes20(this.args[0][4][i]))
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
return encodedInput;
|
|
42
|
+
}
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
module.exports = AaveV3ClaimRewardsAction;
|
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
const ActionWithL2 = require("../../ActionWithL2");
|
|
2
|
+
const { getAddr } = require('../../addresses.js');
|
|
3
|
+
|
|
4
|
+
/**
|
|
5
|
+
* AaveV3CollateralSwitchAction - Aave enable/disable token usage as collateral for AaveV3 position
|
|
6
|
+
*/
|
|
7
|
+
class AaveV3CollateralSwitchAction extends ActionWithL2 {
|
|
8
|
+
/**
|
|
9
|
+
* @param useDefaultMarket {boolean} If this is true it defaults to the hardcoded market in contract
|
|
10
|
+
* @param market {EthAddress} Address provider for specific market
|
|
11
|
+
* @param arrayLength {number} length of two arrays
|
|
12
|
+
* @param assetIds {Array<number>}
|
|
13
|
+
* @param useAsCollateral {Array<boolean>}
|
|
14
|
+
*/
|
|
15
|
+
constructor(useDefaultMarket, market, arrayLength, assetIds, useAsCollateral) {
|
|
16
|
+
super(
|
|
17
|
+
'AaveV3CollateralSwitch',
|
|
18
|
+
getAddr('AaveV3CollateralSwitch'),
|
|
19
|
+
[['uint8','bool', 'uint16[]', 'bool[]','address']],
|
|
20
|
+
[[arrayLength, useDefaultMarket, assetIds, useAsCollateral, market]],
|
|
21
|
+
);
|
|
22
|
+
}
|
|
23
|
+
encodeInputs() {
|
|
24
|
+
// executeActionDirectL2
|
|
25
|
+
let encodedInput = "0x2895f3aa";
|
|
26
|
+
// arrayLength
|
|
27
|
+
encodedInput = encodedInput.concat(this.numberToBytes1(this.args[0][0]));
|
|
28
|
+
// useDefaultMarket
|
|
29
|
+
encodedInput = encodedInput.concat(this.boolToBytes1(this.args[0][1]));
|
|
30
|
+
const arrayLength = this.args[0][0];
|
|
31
|
+
for (let i = 0; i < arrayLength; i++){
|
|
32
|
+
// assetIds[i]
|
|
33
|
+
encodedInput = encodedInput.concat(this.numberToBytes2(this.args[0][2][i]));
|
|
34
|
+
// useAsCollateral[i]
|
|
35
|
+
encodedInput = encodedInput.concat(this.boolToBytes1(this.args[0][3][i]));
|
|
36
|
+
}
|
|
37
|
+
if (!this.args[0][1]){
|
|
38
|
+
// market
|
|
39
|
+
encodedInput = encodedInput.concat(this.addressToBytes20(this.args[0][4]));
|
|
40
|
+
}
|
|
41
|
+
return encodedInput;
|
|
42
|
+
}
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
module.exports = AaveV3CollateralSwitchAction;
|
|
@@ -0,0 +1,68 @@
|
|
|
1
|
+
const ActionWithL2 = require("../../ActionWithL2");
|
|
2
|
+
const { getAssetInfoByAddress } = require("@defisaver/tokens");
|
|
3
|
+
const { getAddr } = require('../../addresses.js');
|
|
4
|
+
|
|
5
|
+
/**
|
|
6
|
+
* AaveV3PaybackAction - Payback debt on Aave using underlying token
|
|
7
|
+
*/
|
|
8
|
+
class AaveV3PaybackAction extends ActionWithL2 {
|
|
9
|
+
/**
|
|
10
|
+
* @param useOnDefaultMarket {boolean} If this is true it defaults to the hardcoded market in contract
|
|
11
|
+
* @param market {EthAddress} Address provider for specific market
|
|
12
|
+
* @param amount {string} Amount of tokens to be payed back
|
|
13
|
+
* @param from {EthAddress} Tokens will be supplied from this address
|
|
14
|
+
* @param rateMode {number} Type of borrow debt [Stable: 1, Variable: 2]
|
|
15
|
+
* @param tokenAddr {EthAddress}
|
|
16
|
+
* @param assetId {number} The id of the underlying asset to be repaid
|
|
17
|
+
* @param useOnBehalf {boolean} use on behalf param or default to proxy
|
|
18
|
+
* @param onBehalf {EthAddress} For what user we are paying back the debt, defaults to proxy
|
|
19
|
+
*/
|
|
20
|
+
constructor(useOnDefaultMarket, market, amount, from, rateMode, tokenAddr, assetId, useOnBehalf , onBehalf = getAddr('Empty')) {
|
|
21
|
+
super('AaveV3Payback', getAddr('AaveV3Payback'),
|
|
22
|
+
[['uint256','address','uint8','uint16', 'bool', 'bool','address','address']],
|
|
23
|
+
[[amount, from, rateMode, assetId, useOnDefaultMarket, useOnBehalf, market, onBehalf]]
|
|
24
|
+
);
|
|
25
|
+
|
|
26
|
+
this.mappableArgs = [
|
|
27
|
+
this.args[0][0],
|
|
28
|
+
this.args[0][1],
|
|
29
|
+
this.args[0][6],
|
|
30
|
+
this.args[0][7],
|
|
31
|
+
];
|
|
32
|
+
this.tokenForApproval = tokenAddr;
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
async getAssetsToApprove() {
|
|
36
|
+
const asset = getAssetInfoByAddress(this.tokenForApproval);
|
|
37
|
+
if (asset.symbol !== 'ETH') return [{asset: this.tokenForApproval, owner: this.args[3]}];
|
|
38
|
+
return [];
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
encodeInputs() {
|
|
42
|
+
// executeActionDirectL2
|
|
43
|
+
let encodedInput = "0x2895f3aa";
|
|
44
|
+
// amount
|
|
45
|
+
encodedInput = encodedInput.concat(this.numberToBytes32(this.args[0][0]));
|
|
46
|
+
// from
|
|
47
|
+
encodedInput = encodedInput.concat(this.addressToBytes20(this.args[0][1]));
|
|
48
|
+
// rateMode
|
|
49
|
+
encodedInput = encodedInput.concat(this.numberToBytes1(this.args[0][2]));
|
|
50
|
+
// assetId
|
|
51
|
+
encodedInput = encodedInput.concat(this.numberToBytes2(this.args[0][3]));
|
|
52
|
+
// useDefaultMarket
|
|
53
|
+
encodedInput = encodedInput.concat(this.boolToBytes1(this.args[0][4]));
|
|
54
|
+
// useOnBehalf
|
|
55
|
+
encodedInput = encodedInput.concat(this.boolToBytes1(this.args[0][5]));
|
|
56
|
+
if (!this.args[0][4]) {
|
|
57
|
+
// market
|
|
58
|
+
encodedInput = encodedInput.concat(this.addressToBytes20(this.args[0][6]));
|
|
59
|
+
}
|
|
60
|
+
if (this.args[0][5]) {
|
|
61
|
+
// onBehalf
|
|
62
|
+
encodedInput = encodedInput.concat(this.addressToBytes20(this.args[0][7]));
|
|
63
|
+
}
|
|
64
|
+
return encodedInput;
|
|
65
|
+
}
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
module.exports = AaveV3PaybackAction;
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
const ActionWithL2 = require("../../ActionWithL2");
|
|
2
|
+
const { getAddr } = require('../../addresses.js');
|
|
3
|
+
|
|
4
|
+
/**
|
|
5
|
+
* AaveV3SetEModeAction - Set EMode for the proxy AaveV3 position
|
|
6
|
+
*/
|
|
7
|
+
class AaveV3SetEModeAction extends ActionWithL2 {
|
|
8
|
+
/**
|
|
9
|
+
* @param categoryId {EthAddress} ID of the category emode
|
|
10
|
+
* @param useOnDefaultMarket {boolean} If this is true it defaults to the hardcoded market in contract
|
|
11
|
+
* @param market {EthAddress} Address provider for specific market
|
|
12
|
+
*/
|
|
13
|
+
constructor(categoryId, useOnDefaultMarket, market) {
|
|
14
|
+
super('AaveV3SetEMode', getAddr('AaveV3SetEMode'),
|
|
15
|
+
[['uint8', 'bool', 'address']],
|
|
16
|
+
[[categoryId, useOnDefaultMarket, market]]
|
|
17
|
+
);
|
|
18
|
+
|
|
19
|
+
this.mappableArgs = [
|
|
20
|
+
this.args[0][2],
|
|
21
|
+
];
|
|
22
|
+
}
|
|
23
|
+
encodeInputs() {
|
|
24
|
+
// executeActionDirectL2
|
|
25
|
+
let encodedInput = "0x2895f3aa";
|
|
26
|
+
// categoryId
|
|
27
|
+
encodedInput = encodedInput.concat(this.numberToBytes1(this.args[0][0]));
|
|
28
|
+
// useOnDefaultMarket
|
|
29
|
+
encodedInput = encodedInput.concat(this.boolToBytes1(this.args[0][1]));
|
|
30
|
+
if (!this.args[0][1]){
|
|
31
|
+
// market
|
|
32
|
+
encodedInput = encodedInput.concat(this.addressToBytes20(this.args[0][2]));
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
return encodedInput;
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
module.exports = AaveV3SetEModeAction;
|
|
@@ -0,0 +1,69 @@
|
|
|
1
|
+
const ActionWithL2 = require("../../ActionWithL2");
|
|
2
|
+
const { getAssetInfoByAddress } = require("@defisaver/tokens");
|
|
3
|
+
const { getAddr } = require('../../addresses.js');
|
|
4
|
+
|
|
5
|
+
/**
|
|
6
|
+
* AaveV3SupplyAction - Supply token to an aave position on Aave V3
|
|
7
|
+
*/
|
|
8
|
+
class AaveV3SupplyAction extends ActionWithL2 {
|
|
9
|
+
|
|
10
|
+
/**
|
|
11
|
+
* @param amount {string} Amount of tokens to be deposited
|
|
12
|
+
* @param from {EthAddress} Tokens will be supplied from this address
|
|
13
|
+
* @param tokenAddress {EthAddress} Address of the token
|
|
14
|
+
* @param assetId {number} The id of the token to be deposited
|
|
15
|
+
* @param enableAsColl {boolean} If we need to enable asset as collateral
|
|
16
|
+
* @param useDefaultMarket {boolean} If this is true it defaults to the hardcoded market in contract
|
|
17
|
+
* @param useOnBehalf {boolean} use on behalf param or default to proxy
|
|
18
|
+
* @param market {EthAddress} Address provider for specific market
|
|
19
|
+
* @param [onBehalf] {EthAddress} For what user we are supplying the tokens, defaults to proxy
|
|
20
|
+
*/
|
|
21
|
+
constructor(amount, from, tokenAddress, assetId, enableAsColl, useDefaultMarket, useOnBehalf ,market, onBehalf = getAddr('Empty')) {
|
|
22
|
+
super('AaveV3Supply', getAddr('AaveV3Supply'),
|
|
23
|
+
[['uint256','address','uint16','bool','bool','bool','address','address']],
|
|
24
|
+
[[amount, from, assetId, enableAsColl, useDefaultMarket, useOnBehalf, market, onBehalf]]
|
|
25
|
+
);
|
|
26
|
+
|
|
27
|
+
this.mappableArgs = [
|
|
28
|
+
this.args[0][0],
|
|
29
|
+
this.args[0][1],
|
|
30
|
+
this.args[0][6],
|
|
31
|
+
this.args[0][7],
|
|
32
|
+
];
|
|
33
|
+
this.tokenForApproval = tokenAddress;
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
async getAssetsToApprove() {
|
|
37
|
+
const asset = getAssetInfoByAddress(this.tokenForApproval);
|
|
38
|
+
if (asset.symbol !== 'ETH') return [{asset: this.tokenForApproval, owner: this.args[0][2]}];
|
|
39
|
+
return [];
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
encodeInputs() {
|
|
43
|
+
// executeActionDirectL2
|
|
44
|
+
let encodedInput = "0x2895f3aa";
|
|
45
|
+
// amount
|
|
46
|
+
encodedInput = encodedInput.concat(this.numberToBytes32(this.args[0][0]));
|
|
47
|
+
// from
|
|
48
|
+
encodedInput = encodedInput.concat(this.addressToBytes20(this.args[0][1]));
|
|
49
|
+
// assetId
|
|
50
|
+
encodedInput = encodedInput.concat(this.numberToBytes2(this.args[0][2]));
|
|
51
|
+
// enableAsColl
|
|
52
|
+
encodedInput = encodedInput.concat(this.boolToBytes1(this.args[0][3]));
|
|
53
|
+
// useDefaultMarket
|
|
54
|
+
encodedInput = encodedInput.concat(this.boolToBytes1(this.args[0][4]));
|
|
55
|
+
// useOnBehalf
|
|
56
|
+
encodedInput = encodedInput.concat(this.boolToBytes1(this.args[0][5]));
|
|
57
|
+
if (!this.args[0][4]) {
|
|
58
|
+
// market
|
|
59
|
+
encodedInput = encodedInput.concat(this.addressToBytes20(this.args[0][6]));
|
|
60
|
+
}
|
|
61
|
+
if (this.args[0][5]) {
|
|
62
|
+
// onBehalf
|
|
63
|
+
encodedInput = encodedInput.concat(this.addressToBytes20(this.args[0][7]));
|
|
64
|
+
}
|
|
65
|
+
return encodedInput;
|
|
66
|
+
}
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
module.exports = AaveV3SupplyAction;
|