@defisaver/sdk 0.0.26 → 0.1.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/.env.example +1 -0
- package/ACTIONS.md +41 -2
- package/DEV.md +14 -0
- package/index.js +2 -0
- package/package.json +4 -3
- package/src/DfsWeb3.js +20 -7
- package/src/actions/aave/AaveCollateralSwitchAction.js +21 -0
- package/src/actions/aave/index.js +2 -0
- package/src/actions/balancer/BalancerV2ClaimAction.js +48 -0
- package/src/actions/balancer/BalancerV2SupplyAction.js +1 -3
- package/src/actions/balancer/BalancerV2WithdrawAction.js +3 -0
- package/src/actions/balancer/index.js +2 -0
- package/src/actions/basic/TokenBalanceAction.js +18 -0
- package/src/actions/basic/index.js +2 -0
- package/src/actions/compound/CompoundCollateralSwitchAction.js +21 -0
- package/src/actions/compound/CompoundGetDebtAction.js +18 -0
- package/src/actions/compound/CompoundPaybackAction.js +3 -2
- package/src/actions/compound/index.js +4 -0
- package/src/actions/insta/InstPullTokensAction.js +24 -0
- package/src/actions/insta/index.js +2 -0
- package/src/addresses.js +11 -4
- package/src/utils/zeroExExchange.js +0 -2
- package/test/DfsWeb3.js +7 -2
- package/test/Recipe.js +1 -1
- package/test/actions/aave/AaveClaimStkAaveAction.js +22 -0
- package/test/actions/aave/AaveCollateralSwitchAction.js +21 -0
- package/test/actions/balancer/BalancerV2ClaimAction.js +101 -0
- package/test/actions/basic/TokenBalanceAction.js +21 -0
- package/test/actions/compound/CompoundCollateralSwitchAction.js +20 -0
- package/test/actions/compound/CompoundGetDebtAction.js +21 -0
- package/test/actions/insta/ClaimInstMakerAction.js +1 -1
- package/test/actions/insta/InstPullTokensAction.js +31 -0
- package/test/actions/liquity/LiquityBorrowAction.js +28 -0
- package/test/actions/liquity/LiquityClaimAction.js +28 -0
- package/test/actions/liquity/LiquityClaimSPRewardsAction.js +28 -0
- package/test/actions/liquity/LiquityClaimStakingRewardsAction.js +28 -0
- package/test/actions/liquity/LiquityCloseAction.js +30 -0
- package/test/actions/liquity/LiquityEthGainToTroveAction.js +28 -0
- package/test/actions/liquity/LiquityOpenAction.js +30 -0
- package/test/actions/liquity/LiquityPaybackAction.js +30 -0
- package/test/actions/liquity/LiquityRedeemAction.js +38 -0
- package/test/actions/liquity/LiquitySPDepositAction.js +31 -0
- package/test/actions/liquity/LiquitySPWithdrawAction.js +29 -0
- package/test/actions/liquity/LiquityStakeAction.js +30 -0
- package/test/actions/liquity/LiquitySupplyAction.js +30 -0
- package/test/actions/liquity/LiquityUnstakeAction.js +28 -0
- package/test/actions/liquity/LiquityWithdrawAction.js +28 -0
- package/test/actions/maker/MakerSupplyAction.js +2 -2
- package/test/index.js +1 -1
- package/test/utils/zeroExExchange.js +0 -11
package/.env.example
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
RPC=
|
package/ACTIONS.md
CHANGED
|
@@ -7,6 +7,9 @@
|
|
|
7
7
|
<dt><a href="#AaveClaimStkAaveAction">AaveClaimStkAaveAction</a></dt>
|
|
8
8
|
<dd><p>AaveClaimStkAaveAction - Claims stkAave from incentives controller</p>
|
|
9
9
|
</dd>
|
|
10
|
+
<dt><a href="#AaveCollateralSwitchAction">AaveCollateralSwitchAction</a></dt>
|
|
11
|
+
<dd><p>AaveCollateralSwitchAction - Aave enable/disable token usage as collateral</p>
|
|
12
|
+
</dd>
|
|
10
13
|
<dt><a href="#AaveMigrateLendAction">AaveMigrateLendAction</a></dt>
|
|
11
14
|
<dd><p>AaveMigrateLendAction - Migrates Lend to Aave</p>
|
|
12
15
|
</dd>
|
|
@@ -19,10 +22,13 @@
|
|
|
19
22
|
<dt><a href="#AaveWithdrawAction">AaveWithdrawAction</a></dt>
|
|
20
23
|
<dd><p>AaveWithdrawAction - Withdraw token from an aave position</p>
|
|
21
24
|
</dd>
|
|
25
|
+
<dt><a href="#BalancerV2ClaimAction">BalancerV2ClaimAction</a></dt>
|
|
26
|
+
<dd></dd>
|
|
22
27
|
<dt><a href="#BalancerV2SupplyAction">BalancerV2SupplyAction</a></dt>
|
|
23
28
|
<dd></dd>
|
|
24
29
|
<dt><a href="#BalancerV2WithdrawAction">BalancerV2WithdrawAction</a></dt>
|
|
25
|
-
<dd
|
|
30
|
+
<dd><p>BalancerV2WithdrawAction - Withdraw tokens from Balancer pool</p>
|
|
31
|
+
</dd>
|
|
26
32
|
<dt><a href="#BuyAction">BuyAction</a></dt>
|
|
27
33
|
<dd><p>Buys an exact amount of dest token on DeFi Saver exchange aggregator</p>
|
|
28
34
|
</dd>
|
|
@@ -56,6 +62,9 @@
|
|
|
56
62
|
<dt><a href="#CompoundClaimAction">CompoundClaimAction</a></dt>
|
|
57
63
|
<dd><p>CompoundClaimAction - Claims Comp tokens for the specified address</p>
|
|
58
64
|
</dd>
|
|
65
|
+
<dt><a href="#CompoundCollateralSwitchAction">CompoundCollateralSwitchAction</a></dt>
|
|
66
|
+
<dd><p>CompoundCollateralSwitchAction - Compound enable/disable cToken usage as collateral</p>
|
|
67
|
+
</dd>
|
|
59
68
|
<dt><a href="#CompoundPaybackAction">CompoundPaybackAction</a></dt>
|
|
60
69
|
<dd><p>CompoundPaybackAction - Payback borrowed tokens from Compound</p>
|
|
61
70
|
</dd>
|
|
@@ -228,6 +237,12 @@ AaveBorrowAction - Borrow tokens from Aave
|
|
|
228
237
|
## AaveClaimStkAaveAction
|
|
229
238
|
AaveClaimStkAaveAction - Claims stkAave from incentives controller
|
|
230
239
|
|
|
240
|
+
**Kind**: global class
|
|
241
|
+
<a name="AaveCollateralSwitchAction"></a>
|
|
242
|
+
|
|
243
|
+
## AaveCollateralSwitchAction
|
|
244
|
+
AaveCollateralSwitchAction - Aave enable/disable token usage as collateral
|
|
245
|
+
|
|
231
246
|
**Kind**: global class
|
|
232
247
|
<a name="AaveMigrateLendAction"></a>
|
|
233
248
|
|
|
@@ -296,6 +311,21 @@ AaveWithdrawAction - Withdraw token from an aave position
|
|
|
296
311
|
- amount <code>string</code>
|
|
297
312
|
- to <code>EthAddress</code> - Tokens will be withdrawn to this address
|
|
298
313
|
|
|
314
|
+
<a name="BalancerV2ClaimAction"></a>
|
|
315
|
+
|
|
316
|
+
## BalancerV2ClaimAction
|
|
317
|
+
**Kind**: global class
|
|
318
|
+
<a name="new_BalancerV2ClaimAction_new"></a>
|
|
319
|
+
|
|
320
|
+
### new BalancerV2ClaimAction(liquidityProvider, to, weeks, balances, merkleProofs)
|
|
321
|
+
**Params**
|
|
322
|
+
|
|
323
|
+
- liquidityProvider <code>EthAddress</code>
|
|
324
|
+
- to <code>EthAddress</code>
|
|
325
|
+
- weeks <code>Array.<uint256></code>
|
|
326
|
+
- balances <code>uint256</code>
|
|
327
|
+
- merkleProofs <code>Array.<Array.<bytes32>></code>
|
|
328
|
+
|
|
299
329
|
<a name="BalancerV2SupplyAction"></a>
|
|
300
330
|
|
|
301
331
|
## BalancerV2SupplyAction
|
|
@@ -315,6 +345,8 @@ AaveWithdrawAction - Withdraw token from an aave position
|
|
|
315
345
|
<a name="BalancerV2WithdrawAction"></a>
|
|
316
346
|
|
|
317
347
|
## BalancerV2WithdrawAction
|
|
348
|
+
BalancerV2WithdrawAction - Withdraw tokens from Balancer pool
|
|
349
|
+
|
|
318
350
|
**Kind**: global class
|
|
319
351
|
<a name="new_BalancerV2WithdrawAction_new"></a>
|
|
320
352
|
|
|
@@ -474,6 +506,12 @@ CompoundClaimAction - Claims Comp tokens for the specified address
|
|
|
474
506
|
- from <code>EthAddress</code>
|
|
475
507
|
- to <code>EthAddress</code>
|
|
476
508
|
|
|
509
|
+
<a name="CompoundCollateralSwitchAction"></a>
|
|
510
|
+
|
|
511
|
+
## CompoundCollateralSwitchAction
|
|
512
|
+
CompoundCollateralSwitchAction - Compound enable/disable cToken usage as collateral
|
|
513
|
+
|
|
514
|
+
**Kind**: global class
|
|
477
515
|
<a name="CompoundPaybackAction"></a>
|
|
478
516
|
|
|
479
517
|
## CompoundPaybackAction
|
|
@@ -482,12 +520,13 @@ CompoundPaybackAction - Payback borrowed tokens from Compound
|
|
|
482
520
|
**Kind**: global class
|
|
483
521
|
<a name="new_CompoundPaybackAction_new"></a>
|
|
484
522
|
|
|
485
|
-
### new CompoundPaybackAction(cTokenAddr, amount, from)
|
|
523
|
+
### new CompoundPaybackAction(cTokenAddr, amount, from, onBehalf)
|
|
486
524
|
**Params**
|
|
487
525
|
|
|
488
526
|
- cTokenAddr <code>EthAddress</code>
|
|
489
527
|
- amount <code>string</code> - Wei amount in underlying asset decimals (not cAsset) - ie. 18 dec for cETH, not 8
|
|
490
528
|
- from <code>EthAddress</code>
|
|
529
|
+
- onBehalf <code>Array.<EthAddress></code>
|
|
491
530
|
|
|
492
531
|
<a name="CompoundSupplyAction"></a>
|
|
493
532
|
|
package/DEV.md
CHANGED
|
@@ -3,6 +3,8 @@
|
|
|
3
3
|
<dl>
|
|
4
4
|
<dt><a href="#utils.module_uniswapLP">uniswapLP</a></dt>
|
|
5
5
|
<dd></dd>
|
|
6
|
+
<dt><a href="#utils.module_uniV3">uniV3</a></dt>
|
|
7
|
+
<dd></dd>
|
|
6
8
|
<dt><a href="#utils.module_zeroExExchange">zeroExExchange</a></dt>
|
|
7
9
|
<dd></dd>
|
|
8
10
|
</dl>
|
|
@@ -58,6 +60,18 @@ Source: https://uniswap.org/docs/v2/javascript-SDK/getting-pair-addresses/#types
|
|
|
58
60
|
- symbolA <code>string</code>
|
|
59
61
|
- symbolB <code>string</code>
|
|
60
62
|
|
|
63
|
+
<a name="utils.module_uniV3"></a>
|
|
64
|
+
|
|
65
|
+
## uniV3
|
|
66
|
+
<a name="utils.module_uniV3.getAssetAddrByTokenId"></a>
|
|
67
|
+
|
|
68
|
+
### uniV3.getAssetAddrByTokenId(web3, tokenId) ⇒ <code>Promise.<Array.<string>></code>
|
|
69
|
+
**Kind**: static method of [<code>uniV3</code>](#utils.module_uniV3)
|
|
70
|
+
**Params**
|
|
71
|
+
|
|
72
|
+
- web3 <code>Object</code> - Web3 instance
|
|
73
|
+
- tokenId <code>string</code>
|
|
74
|
+
|
|
61
75
|
<a name="utils.module_zeroExExchange"></a>
|
|
62
76
|
|
|
63
77
|
## zeroExExchange
|
package/index.js
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
const Action = require('./src/Action');
|
|
2
2
|
const Recipe = require('./src/Recipe');
|
|
3
|
+
const DfsWeb3 = require('./src/DfsWeb3');
|
|
3
4
|
|
|
4
5
|
const actions = require('./src/actions/');
|
|
5
6
|
const utils = require('./src/utils/');
|
|
@@ -11,4 +12,5 @@ module.exports = {
|
|
|
11
12
|
actions,
|
|
12
13
|
actionAddresses,
|
|
13
14
|
utils,
|
|
15
|
+
DfsWeb3,
|
|
14
16
|
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@defisaver/sdk",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.1.1",
|
|
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.3.
|
|
16
|
+
"@defisaver/tokens": "^1.3.53",
|
|
17
17
|
"@ethersproject/address": "^5.0.10",
|
|
18
18
|
"@ethersproject/solidity": "^5.0.9",
|
|
19
19
|
"axios": "^0.21.1",
|
|
@@ -25,6 +25,7 @@
|
|
|
25
25
|
"chai": "^4.2.0",
|
|
26
26
|
"jsdoc-to-markdown": "^6.0.1",
|
|
27
27
|
"mocha": "^8.2.1",
|
|
28
|
-
"web3": "^1.3.4"
|
|
28
|
+
"web3": "^1.3.4",
|
|
29
|
+
"dotenv": "^10.0.0"
|
|
29
30
|
}
|
|
30
31
|
}
|
package/src/DfsWeb3.js
CHANGED
|
@@ -25,7 +25,9 @@ class DfsWeb3 {
|
|
|
25
25
|
this.account = accounts[0];
|
|
26
26
|
const dfsRegistry = new this.web3.eth.Contract(DFSPRoxyRegistyAbi, getAddr('DFSProxyRegistry'));
|
|
27
27
|
const proxies = await dfsRegistry.methods.getAllProxies(this.account).call();
|
|
28
|
-
|
|
28
|
+
if (proxies[0] !== '0x0000000000000000000000000000000000000000') {
|
|
29
|
+
this.proxy = proxies[0];
|
|
30
|
+
}
|
|
29
31
|
this.accountReady = true;
|
|
30
32
|
}
|
|
31
33
|
|
|
@@ -46,7 +48,7 @@ class DfsWeb3 {
|
|
|
46
48
|
const transactions = [];
|
|
47
49
|
const approvals = await action.getAssetsToApprove();
|
|
48
50
|
await Promise.all(approvals.map(async (a) => {
|
|
49
|
-
if (a.owner.
|
|
51
|
+
if (a.owner.toLowerCase() === this.proxy.toLowerCase()) {
|
|
50
52
|
const tokenContract = new this.web3.eth.Contract(Erc20Abi, a.asset);
|
|
51
53
|
const allowance = await tokenContract.methods.allowance(this.account, this.proxy).call();
|
|
52
54
|
if (parseFloat(allowance.toString()) === 0) {
|
|
@@ -56,14 +58,25 @@ class DfsWeb3 {
|
|
|
56
58
|
}));
|
|
57
59
|
return transactions;
|
|
58
60
|
}
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
*/
|
|
62
|
-
async executeViaProxy(action) {
|
|
61
|
+
|
|
62
|
+
async execute(address, params) {
|
|
63
63
|
if (!this.accountReady) await this.prepareAccount();
|
|
64
64
|
if (!this.proxy) throw new Error('Account does not have a Smart Wallet. Run createSmartWallet first');
|
|
65
65
|
const proxyContract = new this.web3.eth.Contract(DsProxyAbi, this.proxy);
|
|
66
|
-
return proxyContract.methods['execute(address,bytes)'](
|
|
66
|
+
return proxyContract.methods['execute(address,bytes)'](address, params);
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
/**
|
|
70
|
+
* @param action {(Action)}
|
|
71
|
+
*/
|
|
72
|
+
async executeAction(action) {
|
|
73
|
+
return this.execute(...action.encodeForDsProxyCall());
|
|
74
|
+
}
|
|
75
|
+
/**
|
|
76
|
+
* @param recipe {(Recipe)}
|
|
77
|
+
*/
|
|
78
|
+
async executeRecipe(recipe) {
|
|
79
|
+
return this.execute(...recipe.encodeForDsProxyCall());
|
|
67
80
|
}
|
|
68
81
|
}
|
|
69
82
|
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
const Action = require("../../Action");
|
|
2
|
+
const {requireAddress} = require("../../utils/general.js");
|
|
3
|
+
const { getAddr } = require('../../addresses.js');
|
|
4
|
+
|
|
5
|
+
/**
|
|
6
|
+
* AaveCollateralSwitchAction - Aave enable/disable token usage as collateral
|
|
7
|
+
*/
|
|
8
|
+
class AaveCollateralSwitchAction extends Action {
|
|
9
|
+
constructor(market, tokens, useAsCollateral) {
|
|
10
|
+
super(
|
|
11
|
+
'AaveCollateralSwitch',
|
|
12
|
+
getAddr('AaveCollateralSwitch'),
|
|
13
|
+
[['address', 'address[]', 'bool[]']],
|
|
14
|
+
[[...arguments]],
|
|
15
|
+
);
|
|
16
|
+
this.mappableArgs = [
|
|
17
|
+
];
|
|
18
|
+
}
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
module.exports = AaveCollateralSwitchAction;
|
|
@@ -4,6 +4,7 @@ const AavePaybackAction = require('./AavePaybackAction');
|
|
|
4
4
|
const AaveWithdrawAction = require('./AaveWithdrawAction');
|
|
5
5
|
const AaveMigrateLendAction = require('./AaveMigrateLendAction');
|
|
6
6
|
const AaveClaimStkAaveAction = require('./AaveClaimStkAaveAction');
|
|
7
|
+
const AaveCollateralSwitchAction = require('./AaveCollateralSwitchAction');
|
|
7
8
|
|
|
8
9
|
module.exports = {
|
|
9
10
|
AaveBorrowAction,
|
|
@@ -12,4 +13,5 @@ module.exports = {
|
|
|
12
13
|
AaveWithdrawAction,
|
|
13
14
|
AaveMigrateLendAction,
|
|
14
15
|
AaveClaimStkAaveAction,
|
|
16
|
+
AaveCollateralSwitchAction
|
|
15
17
|
};
|
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
const Action = require("../../Action");
|
|
2
|
+
const {getAddr} = require('../../addresses.js');
|
|
3
|
+
|
|
4
|
+
/*
|
|
5
|
+
* BalancerV2ClaimAction - Claim BAL governance tokens
|
|
6
|
+
*/
|
|
7
|
+
class BalancerV2ClaimAction extends Action {
|
|
8
|
+
/**
|
|
9
|
+
* @param {EthAddress} liquidityProvider
|
|
10
|
+
* @param {EthAddress} to
|
|
11
|
+
* @param {uint256[]} weeks
|
|
12
|
+
* @param {uint256} balances
|
|
13
|
+
* @param {bytes32[][]} merkleProofs
|
|
14
|
+
*/
|
|
15
|
+
constructor(liquidityProvider, to, weeks, balances, merkleProofs) {
|
|
16
|
+
super(
|
|
17
|
+
'BalancerV2Claim',
|
|
18
|
+
getAddr('BalancerV2Claim'),
|
|
19
|
+
[
|
|
20
|
+
[
|
|
21
|
+
"address",
|
|
22
|
+
"address",
|
|
23
|
+
"uint256[]",
|
|
24
|
+
"uint256[]",
|
|
25
|
+
"bytes32[][]",
|
|
26
|
+
],
|
|
27
|
+
],
|
|
28
|
+
[[liquidityProvider, to, weeks, balances, merkleProofs]]
|
|
29
|
+
);
|
|
30
|
+
|
|
31
|
+
this.mappableArgs = [
|
|
32
|
+
this.args[0][0],
|
|
33
|
+
this.args[0][1],
|
|
34
|
+
];
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
async getAssetsToApprove() {
|
|
38
|
+
|
|
39
|
+
const approveArr = [];
|
|
40
|
+
if (this.args[0][0] !== this.args[0][1]){
|
|
41
|
+
const tokenAddress = getAddr('BalancerToken');
|
|
42
|
+
approveArr.push({asset: tokenAddress, owner: this.args[0][0]});
|
|
43
|
+
}
|
|
44
|
+
return approveArr;
|
|
45
|
+
}
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
module.exports = BalancerV2ClaimAction;
|
|
@@ -2,7 +2,7 @@ const Action = require("../../Action");
|
|
|
2
2
|
const {getAddr} = require('../../addresses.js');
|
|
3
3
|
|
|
4
4
|
/*
|
|
5
|
-
*
|
|
5
|
+
* BalancerV2SupplyAction - Supply tokens to Balancer pool
|
|
6
6
|
*/
|
|
7
7
|
class BalancerV2SupplyAction extends Action {
|
|
8
8
|
/**
|
|
@@ -30,8 +30,6 @@ class BalancerV2SupplyAction extends Action {
|
|
|
30
30
|
[[poolId, from, to, tokens, maxAmountsIn, userData]]
|
|
31
31
|
);
|
|
32
32
|
|
|
33
|
-
this.from = from;
|
|
34
|
-
|
|
35
33
|
this.mappableArgs = [
|
|
36
34
|
this.args[0][1],
|
|
37
35
|
this.args[0][2],
|
|
@@ -1,7 +1,9 @@
|
|
|
1
1
|
const BalancerV2SupplyAction = require("./BalancerV2SupplyAction");
|
|
2
2
|
const BalancerV2WithdrawAction = require("./BalancerV2WithdrawAction");
|
|
3
|
+
const BalancerV2ClaimAction = require("./BalancerV2ClaimAction");
|
|
3
4
|
|
|
4
5
|
module.exports = {
|
|
5
6
|
BalancerV2SupplyAction,
|
|
6
7
|
BalancerV2WithdrawAction,
|
|
8
|
+
BalancerV2ClaimAction,
|
|
7
9
|
}
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
const Action = require("../../Action");
|
|
2
|
+
const { getAddr } = require('../../addresses.js');
|
|
3
|
+
|
|
4
|
+
class TokenBalanceAction extends Action {
|
|
5
|
+
constructor(tokenAddr, holderAddr) {
|
|
6
|
+
super(
|
|
7
|
+
'TokenBalance',
|
|
8
|
+
getAddr('TokenBalance'),
|
|
9
|
+
[[
|
|
10
|
+
"address",
|
|
11
|
+
"address",
|
|
12
|
+
]],
|
|
13
|
+
[[...arguments]]
|
|
14
|
+
);
|
|
15
|
+
}
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
module.exports = TokenBalanceAction;
|
|
@@ -7,6 +7,7 @@ const UnwrapEthAction = require('./UnwrapEthAction');
|
|
|
7
7
|
const SumInputsAction = require('./SumInputsAction');
|
|
8
8
|
const SubInputsAction = require('./SubInputsAction');
|
|
9
9
|
const ChangeProxyOwnerAction = require('./ChangeProxyOwnerAction');
|
|
10
|
+
const TokenBalanceAction = require('./TokenBalanceAction');
|
|
10
11
|
|
|
11
12
|
module.exports = {
|
|
12
13
|
SellAction,
|
|
@@ -18,4 +19,5 @@ module.exports = {
|
|
|
18
19
|
SumInputsAction,
|
|
19
20
|
SubInputsAction,
|
|
20
21
|
ChangeProxyOwnerAction,
|
|
22
|
+
TokenBalanceAction,
|
|
21
23
|
};
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
const Action = require("../../Action");
|
|
2
|
+
const {requireAddress} = require("../../utils/general.js");
|
|
3
|
+
const { getAddr } = require('../../addresses.js');
|
|
4
|
+
|
|
5
|
+
/**
|
|
6
|
+
* CompoundCollateralSwitchAction - Compound enable/disable cToken usage as collateral
|
|
7
|
+
*/
|
|
8
|
+
class CompoundCollateralSwitchAction extends Action {
|
|
9
|
+
constructor(cTokens, useAsCollateral) {
|
|
10
|
+
super(
|
|
11
|
+
'CompCollateralSwitch',
|
|
12
|
+
getAddr('CompCollateralSwitch'),
|
|
13
|
+
[['address[]', 'bool[]']],
|
|
14
|
+
[[...arguments]],
|
|
15
|
+
);
|
|
16
|
+
this.mappableArgs = [
|
|
17
|
+
];
|
|
18
|
+
}
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
module.exports = CompoundCollateralSwitchAction;
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
const Action = require("../../Action");
|
|
2
|
+
const { getAddr } = require('../../addresses.js');
|
|
3
|
+
|
|
4
|
+
class CompoundGetDebtAction extends Action {
|
|
5
|
+
constructor(cTokenAddr, holderAddr) {
|
|
6
|
+
super(
|
|
7
|
+
'CompGetDebt',
|
|
8
|
+
getAddr('CompGetDebt'),
|
|
9
|
+
[[
|
|
10
|
+
"address",
|
|
11
|
+
"address",
|
|
12
|
+
]],
|
|
13
|
+
[[...arguments]]
|
|
14
|
+
);
|
|
15
|
+
}
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
module.exports = CompoundGetDebtAction;
|
|
@@ -10,9 +10,10 @@ class CompoundPaybackAction extends Action {
|
|
|
10
10
|
* @param cTokenAddr {EthAddress}
|
|
11
11
|
* @param amount {string} Wei amount in underlying asset decimals (not cAsset) - ie. 18 dec for cETH, not 8
|
|
12
12
|
* @param from {EthAddress}
|
|
13
|
+
* @param onBehalf {EthAddress} Defaults to DsProxy address if 0x0
|
|
13
14
|
*/
|
|
14
|
-
constructor(cTokenAddr, amount, from) {
|
|
15
|
-
super('CompPayback', getAddr('CompPayback'), ['address', 'uint256', 'address'], [
|
|
15
|
+
constructor(cTokenAddr, amount, from, onBehalf = getAddr('Empty')) {
|
|
16
|
+
super('CompPayback', getAddr('CompPayback'), ['address', 'uint256', 'address', 'address'], [cTokenAddr, amount, from, onBehalf]);
|
|
16
17
|
}
|
|
17
18
|
|
|
18
19
|
async getAssetsToApprove() {
|
|
@@ -3,6 +3,8 @@ const CompoundSupplyAction = require('./CompoundSupplyAction');
|
|
|
3
3
|
const CompoundPaybackAction = require('./CompoundPaybackAction');
|
|
4
4
|
const CompoundWithdrawAction = require('./CompoundWithdrawAction');
|
|
5
5
|
const CompoundClaimAction = require('./CompoundClaimAction');
|
|
6
|
+
const CompoundCollateralSwitchAction = require('./CompoundCollateralSwitchAction');
|
|
7
|
+
const CompoundGetDebtAction = require('./CompoundGetDebtAction');
|
|
6
8
|
|
|
7
9
|
module.exports = {
|
|
8
10
|
CompoundBorrowAction,
|
|
@@ -10,4 +12,6 @@ module.exports = {
|
|
|
10
12
|
CompoundPaybackAction,
|
|
11
13
|
CompoundWithdrawAction,
|
|
12
14
|
CompoundClaimAction,
|
|
15
|
+
CompoundCollateralSwitchAction,
|
|
16
|
+
CompoundGetDebtAction,
|
|
13
17
|
};
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
const Action = require("../../Action");
|
|
2
|
+
const { getAssetInfoByAddress, getAssetInfo } = require("@defisaver/tokens");
|
|
3
|
+
const { getAddr } = require("../../addresses.js");
|
|
4
|
+
|
|
5
|
+
class InstPullTokensAction extends Action {
|
|
6
|
+
constructor(dsaAddress, tokens, amounts, to) {
|
|
7
|
+
super(
|
|
8
|
+
"InstPullTokens",
|
|
9
|
+
getAddr("InstPullTokens"),
|
|
10
|
+
[["address", "address[]", "uint256[]", "address"]],
|
|
11
|
+
[[dsaAddress, tokens, amounts, to]]
|
|
12
|
+
);
|
|
13
|
+
this.mappableArgs = [];
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
async getAssetsToApprove() {
|
|
17
|
+
return [{
|
|
18
|
+
dsaAddress: this.args[0][0],
|
|
19
|
+
specialApproveLabel: 'Instadapp'
|
|
20
|
+
}];
|
|
21
|
+
}
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
module.exports = InstPullTokensAction;
|
package/src/addresses.js
CHANGED
|
@@ -11,6 +11,7 @@ const actionAddresses = {
|
|
|
11
11
|
'SumInputs': '0xCdef35425579fc566B6Ee0499A79256ac88d25cf',
|
|
12
12
|
'SubInputs': '0x3f71c5b806c2aCFA88bd7Ae5F7f8A14121E0FcA6',
|
|
13
13
|
'ChangeProxyOwner': '0x32cEdFfF6e64f6cD1907Ae0b27b78c36320587E7',
|
|
14
|
+
'TokenBalance': '0xFEb82445aEaA675D59A43CD5833f5A6807f97ea2',
|
|
14
15
|
|
|
15
16
|
// exchange
|
|
16
17
|
'DFSSell': '0x9A765623F9De2D7dB26afb5f7Bb85592DF094CDB',
|
|
@@ -37,20 +38,23 @@ const actionAddresses = {
|
|
|
37
38
|
|
|
38
39
|
// aave
|
|
39
40
|
'AaveBorrow': '0xEdBbF97C505309e5174E164fbec3cAE774d310Ea',
|
|
40
|
-
'AavePayback': '
|
|
41
|
+
'AavePayback': '0xb583Bc7603E5E482F475Ec9Ea90129029D53fbc8',
|
|
41
42
|
'AaveSupply': '0xC71113E9122465e8bCd42123f840Df99abaF29F1',
|
|
42
43
|
'AaveWithdraw': '0xE06Fc1CBD78Eb0799d5B0ca62D51B065886e08FC',
|
|
44
|
+
'AaveCollateralSwitch': '0x27d77c80A88665342C98Ea31B687A5fc8ca9a445',
|
|
43
45
|
|
|
44
46
|
// compound
|
|
45
47
|
'CompBorrow': '0xde1b05266f2D05Bf9216B76500583c2b7785b7e9',
|
|
46
48
|
'CompClaim': '0xAA165C03fF61301b79f35649157f6738263739A3',
|
|
47
|
-
'CompPayback': '
|
|
49
|
+
'CompPayback': '0x67D2CC825730cCb70FD4579E55cDb3cf3152fcb6',
|
|
48
50
|
'CompSupply': '0x1F22890C166B30cE8769b7B55354064C254e063F',
|
|
49
51
|
'CompWithdraw': '0xD326a003bcfDbad0E9A4Ccc37a76Ce264345F38a',
|
|
52
|
+
'CompGetDebt': '0x009109AB7b8CAFf748cdA2F272F36043528Bef2C',
|
|
53
|
+
'CompCollateralSwitch': '0x1c0BD1E4da2c3108f6caA64609E89a37531B0f86',
|
|
50
54
|
|
|
51
55
|
// flashloan
|
|
52
|
-
'FLAaveV2': '
|
|
53
|
-
'FLDyDx': '
|
|
56
|
+
'FLAaveV2': '0x46aafdbc76a8b412909985d0a2c51073ff33c02e',
|
|
57
|
+
'FLDyDx': '0x973065599BACa33FC9CAD2823710f1332D2B7805',
|
|
54
58
|
|
|
55
59
|
// uniswap
|
|
56
60
|
'UniSupply': '0xcAE220B5398AfAad75bfeb946164f6C23CF65A98',
|
|
@@ -91,10 +95,12 @@ const actionAddresses = {
|
|
|
91
95
|
|
|
92
96
|
// insta
|
|
93
97
|
'ClaimInstMaker': '0x15E22A8160F0bDb619C6846C982F8D208A5670D2',
|
|
98
|
+
'InstPullTokens': '0x37FC940Be30e11d578243dEBea4f9B950E22aC99',
|
|
94
99
|
|
|
95
100
|
// balancer
|
|
96
101
|
'BalancerV2Supply': '0xD78E5D95A28a67F7851b0a94505790813A92E405',
|
|
97
102
|
'BalancerV2Withdraw': '0xCcf4b96407BEF25D7df1c95045CCF64950e73E97',
|
|
103
|
+
'BalancerV2Claim': '0x259Ae83567858B7960d2De0D00F3717a764aD73B',
|
|
98
104
|
};
|
|
99
105
|
|
|
100
106
|
const otherAddresses = {
|
|
@@ -106,6 +112,7 @@ const otherAddresses = {
|
|
|
106
112
|
DFSProxyRegistry: '0x29474FdaC7142f9aB7773B8e38264FA15E3805ed',
|
|
107
113
|
UniswapV3PositionManager : '0xC36442b4a4522E871399CD717aBDD847Ab11FE88',
|
|
108
114
|
RaiWethUniV2LPToken : '0x8aE720a71622e824F576b4A8C03031066548A3B1',
|
|
115
|
+
BalancerToken : '0xba100000625a3754423978a60c9317c58a424e3D',
|
|
109
116
|
}
|
|
110
117
|
|
|
111
118
|
|
|
@@ -54,7 +54,6 @@ const get0xPrice = async (_sellToken, _buyToken, _amount, convertAmountToWei = t
|
|
|
54
54
|
if (res.status !== 200) throw new Error(JSON.stringify(res.data));
|
|
55
55
|
|
|
56
56
|
const data = res.data;
|
|
57
|
-
console.log(data);
|
|
58
57
|
|
|
59
58
|
// convert price to be able to compare with other prices onchain
|
|
60
59
|
if (!shouldSell) {
|
|
@@ -180,7 +179,6 @@ const createExchangeAction = async (
|
|
|
180
179
|
'0x', // wrapperData,
|
|
181
180
|
offchainDataArray,
|
|
182
181
|
];
|
|
183
|
-
console.log(orderData);
|
|
184
182
|
return shouldSell
|
|
185
183
|
? new SellAction(orderData, fromAccount, toAccount, protocolFee)
|
|
186
184
|
: new BuyAction(orderData, fromAccount, toAccount, protocolFee)
|
package/test/DfsWeb3.js
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
require('dotenv').config();
|
|
1
2
|
const {assert} = require('chai');
|
|
2
3
|
const DfsWeb3 = require('../src/DfsWeb3');
|
|
3
4
|
const Web3 = require('web3');
|
|
@@ -8,7 +9,11 @@ describe('DfsWeb3', () => {
|
|
|
8
9
|
let dfsWeb3;
|
|
9
10
|
before(async () => {
|
|
10
11
|
const web3 = new Web3(process.env.RPC);
|
|
12
|
+
|
|
13
|
+
web3.eth.getAccounts = () => ['0x0a80C3C540eEF99811f4579fa7b1A0617294e06f'];
|
|
11
14
|
dfsWeb3 = new DfsWeb3(web3);
|
|
15
|
+
dfsWeb3.account = '0x0a80C3C540eEF99811f4579fa7b1A0617294e06f';
|
|
16
|
+
|
|
12
17
|
await dfsWeb3.prepareAccount();
|
|
13
18
|
assert.containsAllKeys(dfsWeb3, ['web3', 'account', 'proxy']);
|
|
14
19
|
})
|
|
@@ -24,7 +29,7 @@ describe('DfsWeb3', () => {
|
|
|
24
29
|
gas: '9000000',
|
|
25
30
|
})
|
|
26
31
|
}
|
|
27
|
-
const exec = await dfsWeb3.
|
|
32
|
+
const exec = await dfsWeb3.executeAction(a);
|
|
28
33
|
// await exec.send({
|
|
29
34
|
// from: dfsWeb3.account,
|
|
30
35
|
// value: await a.getEthValue(),
|
|
@@ -50,7 +55,7 @@ describe('DfsWeb3', () => {
|
|
|
50
55
|
gas: '9000000',
|
|
51
56
|
})
|
|
52
57
|
}
|
|
53
|
-
const exec = await dfsWeb3.
|
|
58
|
+
const exec = await dfsWeb3.executeRecipe(r);
|
|
54
59
|
// await exec.send({
|
|
55
60
|
// from: dfsWeb3.account,
|
|
56
61
|
// value: await r.getEthValue(),
|
package/test/Recipe.js
CHANGED
|
@@ -24,7 +24,7 @@ describe('Recipe', () => {
|
|
|
24
24
|
it('encodeForDsProxyCall', () => encodeForDsProxyCall(recipe));
|
|
25
25
|
it('getAssetsToApprove', async () => {
|
|
26
26
|
const assetsToApprove = await recipe.getAssetsToApprove();
|
|
27
|
-
assert.lengthOf(assetsToApprove,
|
|
27
|
+
assert.lengthOf(assetsToApprove, 1);
|
|
28
28
|
});
|
|
29
29
|
it('getEthValue', async () => {
|
|
30
30
|
const ethValue = await recipe.getEthValue();
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
const dfs = require('../../../index.js');
|
|
2
|
+
const {assetAmountInWei, getAssetInfo, assetAmountInEth} = require("@defisaver/tokens");
|
|
3
|
+
const {encodeForDsProxyCall, encodeForRecipe} = require('../../_actionUtils');
|
|
4
|
+
const {assert} = require('chai');
|
|
5
|
+
const { getAddr } = require('../../../src/addresses.js');
|
|
6
|
+
|
|
7
|
+
describe('Action: AaveClaimStkAaveAction', () => {
|
|
8
|
+
let action;
|
|
9
|
+
const to = '0x0a80C3C540eEF99811f4579fa7b1A0617294e06f';
|
|
10
|
+
|
|
11
|
+
context('Claims stkAave from incentives controller', () => {
|
|
12
|
+
it('constructor', () => {
|
|
13
|
+
action = new dfs.actions.aave.AaveClaimStkAaveAction(
|
|
14
|
+
[getAddr('Empty')],
|
|
15
|
+
'1000',
|
|
16
|
+
to,
|
|
17
|
+
)
|
|
18
|
+
})
|
|
19
|
+
it('encodeForDsProxyCall', () => encodeForDsProxyCall(action));
|
|
20
|
+
it('encodeForRecipe', () => encodeForRecipe(action));
|
|
21
|
+
})
|
|
22
|
+
})
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
const dfs = require('../../../index.js');
|
|
2
|
+
const {assetAmountInWei, getAssetInfo, assetAmountInEth} = require("@defisaver/tokens");
|
|
3
|
+
const {encodeForDsProxyCall, encodeForRecipe} = require('../../_actionUtils');
|
|
4
|
+
const {assert} = require('chai');
|
|
5
|
+
const { getAddr } = require('../../../src/addresses.js');
|
|
6
|
+
|
|
7
|
+
describe('Action: AaveCollateralSwitchAction', () => {
|
|
8
|
+
let action;
|
|
9
|
+
|
|
10
|
+
context('Enable one token, disable other token with AaveCollSwitch Action', () => {
|
|
11
|
+
it('constructor', () => {
|
|
12
|
+
action = new dfs.actions.aave.AaveCollateralSwitchAction(
|
|
13
|
+
getAddr('AaveDefaultMarket'),
|
|
14
|
+
[getAddr('RaiWethUniV2LPToken'), getAddr('BalancerToken')],
|
|
15
|
+
[true, false],
|
|
16
|
+
)
|
|
17
|
+
})
|
|
18
|
+
it('encodeForDsProxyCall', () => encodeForDsProxyCall(action));
|
|
19
|
+
it('encodeForRecipe', () => encodeForRecipe(action));
|
|
20
|
+
})
|
|
21
|
+
})
|