@defisaver/sdk 0.2.11 → 0.3.0

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 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
- DfsWeb3,
23
+
24
+ configure,
25
+ getNetworkData,
26
+ networks: NETWORKS,
27
+ actionAddressesAllChains: actionAddresses,
28
+ actionAddresses: () => actionAddresses[CONFIG.chainId],
20
29
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@defisaver/sdk",
3
- "version": "0.2.11",
3
+ "version": "0.3.0",
4
4
  "description": "",
5
5
  "main": "index.js",
6
6
  "scripts": {
@@ -13,7 +13,7 @@
13
13
  "repository": "https://github.com/DecenterApps/defisaver-sdk",
14
14
  "license": "ISC",
15
15
  "dependencies": {
16
- "@defisaver/tokens": "^1.4.12",
16
+ "@defisaver/tokens": "^1.4.18",
17
17
  "@ethersproject/address": "^5.0.10",
18
18
  "@ethersproject/solidity": "^5.0.9",
19
19
  "axios": "^0.21.1",
@@ -23,9 +23,9 @@
23
23
  },
24
24
  "devDependencies": {
25
25
  "chai": "^4.2.0",
26
- "dotenv": "^10.0.0",
27
26
  "jsdoc-to-markdown": "^6.0.1",
28
27
  "mocha": "^8.2.1",
29
- "web3": "^1.3.4"
28
+ "web3": "^1.3.4",
29
+ "dotenv": "^10.0.0"
30
30
  }
31
31
  }
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
 
@@ -112,16 +113,24 @@ class Action {
112
113
  return [AbiCoder.encodeParameter(_paramType, _arg)];
113
114
  }
114
115
 
116
+ encodeForL2DsProxyCall() {
117
+ throw new Error('Not L2'); // TODO improve this
118
+ }
119
+
115
120
  /**
116
121
  * Encode arguments for calling the action via DsProxy
117
122
  * @returns {Array<string>} `address` & `data` to be passed on to DSProxy's `execute(address _target, bytes memory _data)`
118
123
  */
119
124
  encodeForDsProxyCall() {
120
- const executeActionDirectAbi = ActionAbi.find(({ name }) => name === 'executeActionDirect');
121
- return [
122
- this.contractAddress,
123
- AbiCoder.encodeFunctionCall(executeActionDirectAbi, this._encodeForCall()),
124
- ];
125
+ if (CONFIG.chainId === 1) {
126
+ const executeActionDirectAbi = ActionAbi.find(({ name }) => name === 'executeActionDirect');
127
+ return [
128
+ this.contractAddress,
129
+ AbiCoder.encodeFunctionCall(executeActionDirectAbi, this._encodeForCall()),
130
+ ];
131
+ } else {
132
+ return [this.contractAddress, this.encodeForL2DsProxyCall()];
133
+ }
125
134
  }
126
135
 
127
136
  /**
@@ -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;
@@ -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],
26
+ this.args[1],
27
+ this.args[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[2]}];
35
+ return [];
36
+ }
37
+ encodeInputs() {
38
+ // executeActionDirectL2
39
+ let encodedInput = "0x2895f3aa";
40
+ // amount
41
+ encodedInput = encodedInput.concat(this.numberToBytes32(this.args[0]));
42
+ // from
43
+ encodedInput = encodedInput.concat(this.addressToBytes20(this.args[1]));
44
+ // rateMode
45
+ encodedInput = encodedInput.concat(this.numberToBytes1(this.args[2]));
46
+ // assetId
47
+ encodedInput = encodedInput.concat(this.numberToBytes2(this.args[3]));
48
+ // useDefaultMarket
49
+ encodedInput = encodedInput.concat(this.boolToBytes1(this.args[4]))
50
+ if (!this.args[4]){
51
+ // market
52
+ encodedInput = encodedInput.concat(this.addressToBytes20(this.args[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],
26
+ this.args[1],
27
+ this.args[6],
28
+ this.args[7],
29
+ ];
30
+ }
31
+
32
+ encodeInputs() {
33
+ // executeActionDirectL2
34
+ let encodedInput = "0x2895f3aa";
35
+ // amount
36
+ encodedInput = encodedInput.concat(this.numberToBytes32(this.args[0]));
37
+ // to
38
+ encodedInput = encodedInput.concat(this.addressToBytes20(this.args[1]));
39
+ // rateMode
40
+ encodedInput = encodedInput.concat(this.numberToBytes1(this.args[2]));
41
+ // assetId
42
+ encodedInput = encodedInput.concat(this.numberToBytes2(this.args[3]));
43
+ // useDefaultMarket
44
+ encodedInput = encodedInput.concat(this.boolToBytes1(this.args[4]))
45
+ // useOnBehalf
46
+ encodedInput = encodedInput.concat(this.boolToBytes1(this.args[5]));
47
+ if (!this.args[4]) {
48
+ // market
49
+ encodedInput = encodedInput.concat(this.addressToBytes20(this.args[6]));
50
+ }
51
+ if (this.args[5]) {
52
+ // onBehalf
53
+ encodedInput = encodedInput.concat(this.addressToBytes20(this.args[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]));
28
+ // amount
29
+ encodedInput = encodedInput.concat(this.numberToBytes32(this.args[1]));
30
+ // to
31
+ encodedInput = encodedInput.concat(this.addressToBytes20(this.args[2]));
32
+ // reward
33
+ encodedInput = encodedInput.concat(this.addressToBytes20(this.args[3]));
34
+ // assets
35
+ const arrayLength = this.args[0];
36
+ for (let i = 0; i < arrayLength; i++){
37
+ // assets[i]
38
+ encodedInput = encodedInput.concat(this.addressToBytes20(this.args[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]));
28
+ // useDefaultMarket
29
+ encodedInput = encodedInput.concat(this.boolToBytes1(this.args[1]));
30
+ const arrayLength = this.args[0];
31
+ for (let i = 0; i < arrayLength; i++){
32
+ // assetIds[i]
33
+ encodedInput = encodedInput.concat(this.numberToBytes2(this.args[2][i]));
34
+ // useAsCollateral[i]
35
+ encodedInput = encodedInput.concat(this.boolToBytes1(this.args[3][i]));
36
+ }
37
+ if (!this.args[1]){
38
+ // market
39
+ encodedInput = encodedInput.concat(this.addressToBytes20(this.args[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],
28
+ this.args[1],
29
+ this.args[6],
30
+ this.args[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]));
46
+ // from
47
+ encodedInput = encodedInput.concat(this.addressToBytes20(this.args[1]));
48
+ // rateMode
49
+ encodedInput = encodedInput.concat(this.numberToBytes1(this.args[2]));
50
+ // assetId
51
+ encodedInput = encodedInput.concat(this.numberToBytes2(this.args[3]));
52
+ // useDefaultMarket
53
+ encodedInput = encodedInput.concat(this.boolToBytes1(this.args[4]));
54
+ // useOnBehalf
55
+ encodedInput = encodedInput.concat(this.boolToBytes1(this.args[5]));
56
+ if (!this.args[4]) {
57
+ // market
58
+ encodedInput = encodedInput.concat(this.addressToBytes20(this.args[6]));
59
+ }
60
+ if (this.args[5]) {
61
+ // onBehalf
62
+ encodedInput = encodedInput.concat(this.addressToBytes20(this.args[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[2],
21
+ ];
22
+ }
23
+ encodeInputs() {
24
+ // executeActionDirectL2
25
+ let encodedInput = "0x2895f3aa";
26
+ // categoryId
27
+ encodedInput = encodedInput.concat(this.numberToBytes1(this.args[0]));
28
+ // useOnDefaultMarket
29
+ encodedInput = encodedInput.concat(this.boolToBytes1(this.args[1]));
30
+ if (!this.args[1]){
31
+ // market
32
+ encodedInput = encodedInput.concat(this.addressToBytes20(this.args[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],
29
+ this.args[1],
30
+ this.args[6],
31
+ this.args[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[2]}];
39
+ return [];
40
+ }
41
+
42
+ encodeInputs() {
43
+ // executeActionDirectL2
44
+ let encodedInput = "0x2895f3aa";
45
+ // amount
46
+ encodedInput = encodedInput.concat(this.numberToBytes32(this.args[0]));
47
+ // from
48
+ encodedInput = encodedInput.concat(this.addressToBytes20(this.args[1]));
49
+ // assetId
50
+ encodedInput = encodedInput.concat(this.numberToBytes2(this.args[2]));
51
+ // enableAsColl
52
+ encodedInput = encodedInput.concat(this.boolToBytes1(this.args[3]));
53
+ // useDefaultMarket
54
+ encodedInput = encodedInput.concat(this.boolToBytes1(this.args[4]));
55
+ // useOnBehalf
56
+ encodedInput = encodedInput.concat(this.boolToBytes1(this.args[5]));
57
+ if (!this.args[4]) {
58
+ // market
59
+ encodedInput = encodedInput.concat(this.addressToBytes20(this.args[6]));
60
+ }
61
+ if (this.args[5]) {
62
+ // onBehalf
63
+ encodedInput = encodedInput.concat(this.addressToBytes20(this.args[7]));
64
+ }
65
+ return encodedInput;
66
+ }
67
+ }
68
+
69
+ module.exports = AaveV3SupplyAction;
@@ -0,0 +1,43 @@
1
+ const ActionWithL2 = require("../../ActionWithL2");
2
+ const { getAddr } = require('../../addresses.js');
3
+
4
+ /**
5
+ * AaveV3SwapBorrowRateModeAction - Swaps proxy positions borrow rate mode between stable and variable.
6
+ */
7
+ class AaveV3SwapBorrowRateModeAction extends ActionWithL2 {
8
+ /**
9
+ * @param rateMode {string} rate mode the user is swapping from.[Stable: 1, Variable: 2]
10
+ * @param assetId {number} id of the underlying asset in the market
11
+ * @param useDefaultMarket {boolean} If this is true it defaults to the hardcoded market in contract
12
+ * @param market {EthAddress} Address provider for specific market
13
+ *
14
+ */
15
+ constructor(rateMode, assetId, useDefaultMarket, market) {
16
+ super('AaveV3SwapBorrowRateMode', getAddr('AaveV3SwapBorrowRateMode'),
17
+ ['uint256','uint16','bool','address'],
18
+ [rateMode, assetId, useDefaultMarket, market]
19
+ );
20
+
21
+ this.mappableArgs = [
22
+ this.args[0][0],
23
+ this.args[3],
24
+ ];
25
+ }
26
+ encodeInputs() {
27
+ // executeActionDirectL2
28
+ let encodedInput = "0x2895f3aa";
29
+ // rateMode
30
+ encodedInput = encodedInput.concat(this.numberToBytes32(this.args[0]));
31
+ // assetId
32
+ encodedInput = encodedInput.concat(this.numberToBytes2(this.args[1]))
33
+ // useOnDefaultMarket
34
+ encodedInput = encodedInput.concat(this.boolToBytes1(this.args[2]))
35
+ if (!this.args[2]){
36
+ // market
37
+ encodedInput = encodedInput.concat(this.addressToBytes20(this.args[3]));
38
+ }
39
+ return encodedInput;
40
+ }
41
+ }
42
+
43
+ module.exports = AaveV3SwapBorrowRateModeAction;
@@ -0,0 +1,46 @@
1
+ const ActionWithL2 = require("../../ActionWithL2");
2
+ const { getAddr } = require('../../addresses.js');
3
+
4
+ /**
5
+ * AaveV3WithdrawAction - Withdraw a previously supplied token from a position in AaveV3
6
+ */
7
+ class AaveV3WithdrawAction extends ActionWithL2 {
8
+ /**
9
+ * @param assetId {number} The id of the token to be deposited
10
+ * @param useDefaultMarket {boolean} If this is true it defaults to the hardcoded market in contract
11
+ * @param amount {string} Amount of tokens to be withdrawn -> send type(uint).max for whole amount
12
+ * @param to {EthAddress} Where the withdrawn tokens will be sent
13
+ * @param market {EthAddress} Address provider for specific market
14
+ */
15
+ constructor(assetId, useDefaultMarket, amount, to, market) {
16
+ super('AaveV3Withdraw', getAddr('AaveV3Withdraw'),
17
+ ['uint16','bool','uint256','address','address'],
18
+ [assetId, useDefaultMarket, amount, to, market]
19
+ );
20
+
21
+ this.mappableArgs = [
22
+ this.args[2],
23
+ this.args[3],
24
+ this.args[4],
25
+ ];
26
+ }
27
+ encodeInputs() {
28
+ // executeActionDirectL2
29
+ let encodedInput = "0x2895f3aa";
30
+ // assetId
31
+ encodedInput = encodedInput.concat(this.numberToBytes2(this.args[0]));
32
+ // useOnDefaultMarket
33
+ encodedInput = encodedInput.concat(this.boolToBytes1(this.args[1]))
34
+ // amount
35
+ encodedInput = encodedInput.concat(this.numberToBytes32(this.args[2]));
36
+ // from
37
+ encodedInput = encodedInput.concat(this.addressToBytes20(this.args[3]));
38
+ if (!this.args[1]){
39
+ // market
40
+ encodedInput = encodedInput.concat(this.addressToBytes20(this.args[4]));
41
+ }
42
+ return encodedInput;
43
+ }
44
+ }
45
+
46
+ module.exports = AaveV3WithdrawAction;
@@ -0,0 +1,21 @@
1
+ const AaveV3SupplyAction = require('./AaveV3SupplyAction');
2
+ const AaveV3BorrowAction = require('./AaveV3BorrowAction');
3
+ const AaveV3PaybackAction = require('./AaveV3PaybackAction');
4
+ const AaveV3WithdrawAction = require('./AaveV3WithdrawAction');
5
+ const AaveV3SetEModeAction = require('./AaveV3SetEModeAction');
6
+ const AaveV3ATokenPaybackAction = require('./AaveV3ATokenPaybackAction');
7
+ const AaveV3CollateralSwitchAction = require('./AaveV3CollateralSwitchAction');
8
+ const AaveV3ClaimRewardsAction = require('./AaveV3ClaimRewardsAction');
9
+ const AaveV3SwapBorrowRateModeAction = require('./AaveV3SwapBorrowRateModeAction');
10
+
11
+ module.exports = {
12
+ AaveV3SupplyAction,
13
+ AaveV3BorrowAction,
14
+ AaveV3PaybackAction,
15
+ AaveV3WithdrawAction,
16
+ AaveV3SetEModeAction,
17
+ AaveV3ATokenPaybackAction,
18
+ AaveV3CollateralSwitchAction,
19
+ AaveV3ClaimRewardsAction,
20
+ AaveV3SwapBorrowRateModeAction,
21
+ }
@@ -1,13 +1,14 @@
1
- const Action = require("../../Action");
2
- const {requireAddress} = require("../../utils/general");
3
- const {getAssetInfoByAddress} = require("@defisaver/tokens");
1
+ const ActionAbi = require('../../abis/Action.json');
2
+ const AbiCoder = require('web3-eth-abi');
3
+ const ActionWithL2 = require("../../ActionWithL2");
4
+ const { requireAddress } = require("../../utils/general");
5
+ const { getAssetInfoByAddress } = require("@defisaver/tokens");
4
6
  const { getAddr } = require('../../addresses.js');
5
- const Dec = require('decimal.js');
6
7
 
7
8
  /**
8
9
  * Sells token on DeFi Saver exchange aggregator
9
10
  */
10
- class SellAction extends Action {
11
+ class SellAction extends ActionWithL2 {
11
12
  /**
12
13
  * @param exchangeOrder {Array} Standard DFS Exchange data
13
14
  * @param from {string} Order sender
@@ -38,6 +39,11 @@ class SellAction extends Action {
38
39
  ];
39
40
  }
40
41
 
42
+ encodeInputs() {
43
+ const executeActionDirectAbi = ActionAbi.find(({ name }) => name === 'executeActionDirect');
44
+ return AbiCoder.encodeFunctionCall(executeActionDirectAbi, this._encodeForCall());
45
+ }
46
+
41
47
  async getAssetsToApprove() {
42
48
  const asset = getAssetInfoByAddress(this.args[0][0]);
43
49
  if (asset.symbol !== 'ETH') return [{asset: this.args[0][0], owner: this.args[1]}];
@@ -1,6 +1,5 @@
1
1
  const Action = require("../../Action");
2
2
  const {requireAddress} = require("../../utils/general");
3
- const {getAssetInfoByAddress} = require("@defisaver/tokens");
4
3
  const { getAddr } = require('../../addresses.js');
5
4
 
6
5
  /**