@defisaver/sdk 0.1.21 → 0.1.24
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/ACTIONS.md +20 -254
- package/AccessLists/DyDxAccessLists.js +0 -4
- package/AccessLists/InstaAccessLists.js +0 -8
- package/AccessLists/UtilsAccessLists.js +0 -5
- package/DEV.md +0 -7
- package/index.js +15 -2
- package/package.json +1 -1
- package/src/Action.js +52 -12
- package/src/L2Action.js +44 -0
- package/src/Recipe.js +5 -4
- package/src/Strategy.js +63 -0
- package/src/abis/Action.json +157 -11
- package/src/abis/Recipe.json +92 -47
- package/src/actions/aave/AaveBorrowAction.js +11 -2
- package/src/actions/aave/AavePaybackAction.js +11 -2
- package/src/actions/aave/AaveSupplyAction.js +9 -1
- package/src/actions/aave/AaveWithdrawAction.js +8 -1
- package/src/actions/aaveV3/AaveV3ATokenPaybackAction.js +53 -0
- package/src/actions/aaveV3/AaveV3BorrowAction.js +54 -0
- package/src/actions/aaveV3/AaveV3CollateralSwitchAction.js +41 -0
- package/src/actions/aaveV3/AaveV3PaybackAction.js +63 -0
- package/src/actions/aaveV3/AaveV3SetEModeAction.js +35 -0
- package/src/actions/aaveV3/AaveV3SupplyAction.js +64 -0
- package/src/actions/aaveV3/AaveV3WithdrawAction.js +41 -0
- package/src/actions/aaveV3/index.js +17 -0
- package/src/actions/basic/GasFeeAction.js +27 -0
- package/src/actions/basic/PullTokenAction.js +9 -3
- package/src/actions/basic/SellAction.js +6 -5
- package/src/actions/basic/SendTokenAction.js +9 -3
- package/src/actions/basic/SumInputsAction.js +8 -3
- package/src/actions/basic/UnwrapEthAction.js +8 -3
- package/src/actions/basic/WrapEthAction.js +5 -1
- package/src/actions/basic/index.js +2 -2
- package/src/actions/checkers/MakerRatioCheckAction.js +29 -0
- package/src/actions/checkers/index.js +5 -0
- package/src/actions/compound/CompoundBorrowAction.js +7 -1
- package/src/actions/compound/CompoundClaimAction.js +6 -1
- package/src/actions/compound/CompoundPaybackAction.js +7 -1
- package/src/actions/compound/CompoundSupplyAction.js +7 -1
- package/src/actions/compound/CompoundWithdrawAction.js +7 -1
- package/src/actions/dydx/DyDxWithdrawAction.js +7 -1
- package/src/actions/dydx/index.js +0 -2
- package/src/actions/flashloan/AaveV2FlashLoanAction.js +2 -2
- package/src/actions/flashloan/BalancerFlashLoanAction.js +2 -2
- package/src/actions/flashloan/DyDxFlashLoanAction.js +1 -1
- package/src/actions/flashloan/MakerFlashLoanAction.js +2 -2
- package/src/actions/index.js +4 -0
- package/src/actions/insta/index.js +0 -2
- package/src/actions/liquity/LiquityClaimAction.js +6 -2
- package/src/actions/liquity/LiquityCloseAction.js +7 -2
- package/src/actions/maker/MakerGenerateAction.js +8 -1
- package/src/actions/maker/MakerGiveAction.js +7 -1
- package/src/actions/maker/MakerMergeAction.js +7 -1
- package/src/actions/maker/MakerOpenVaultAction.js +6 -1
- package/src/actions/maker/MakerPaybackAction.js +1 -0
- package/src/actions/maker/MakerRatioAction.js +20 -0
- package/src/actions/maker/MakerSupplyAction.js +9 -1
- package/src/actions/maker/MakerWithdrawAction.js +10 -2
- package/src/actions/maker/index.js +2 -0
- package/src/actions/mstable/MStableDepositAction.js +2 -2
- package/src/actions/mstable/MStableWithdrawAction.js +2 -2
- package/src/actions/reflexer/ReflexerGenerateAction.js +7 -1
- 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/addresses.js +179 -143
- package/src/config.js +74 -0
- package/src/triggers/ChainLinkPriceTrigger.js +12 -0
- package/src/triggers/CompoundRatioTrigger.js +11 -0
- package/src/triggers/GasPriceTrigger.js +11 -0
- package/src/triggers/LiquityRatioTrigger.js +16 -0
- package/src/triggers/MakerRatioTrigger.js +15 -0
- package/src/triggers/ReflexerRatioTrigger.js +11 -0
- package/src/triggers/TimestampTrigger.js +11 -0
- package/src/triggers/UniV3CurrentTickTrigger.js +12 -0
- package/src/triggers/index.js +19 -0
- package/src/types.js +33 -0
- package/src/utils/general.js +2 -0
- package/src/utils/zeroExExchange.js +2 -40
- package/test/accessLists/MockAccessLists.json +0 -72
- package/test/accessLists/Recipe.js +3 -3
- package/test/actions/insta/InstPullTokensAction.js +2 -2
- package/test/index.js +4 -1
- package/test/utils/zeroExExchange.js +0 -8
- package/src/actions/basic/BuyAction.js +0 -53
- package/src/actions/dydx/DyDxSupplyAction.js +0 -25
- package/src/actions/insta/ClaimInstMakerAction.js +0 -21
- package/test/actions/basic/BuyAction.js +0 -100
- package/test/actions/dydx/DyDxSupplyAction.js +0 -78
- package/test/actions/insta/ClaimInstMakerAction.js +0 -46
|
@@ -7,7 +7,6 @@ const axios = require('axios');
|
|
|
7
7
|
const {assetAmountInWei, getAssetInfo} = require('@defisaver/tokens');
|
|
8
8
|
|
|
9
9
|
const SellAction = require('../actions/basic/SellAction');
|
|
10
|
-
const BuyAction = require('../actions/basic/BuyAction');
|
|
11
10
|
const {parsePriceFromContract, formatPriceForContract} = require('./general');
|
|
12
11
|
const API_URL = 'https://api.0x.org/swap/v1/';
|
|
13
12
|
const ZEROX_WRAPPER = '0x0c4e16899f2059F4e41ddB164317414a5c0d2988';
|
|
@@ -124,7 +123,7 @@ module.exports.estimateBuyPrice = async (buyAmount, buyToken, sellToken) => esti
|
|
|
124
123
|
* @param shouldSell {Boolean} look for price to sell or to buy (if false sellToken becomes becomes buyToken and vice-versa)
|
|
125
124
|
* @param fromAccount {EthAddress} Withdraw funds from this addr
|
|
126
125
|
* @param toAccount {EthAddress} Send funds to this addr
|
|
127
|
-
* @return {Promise<(SellAction
|
|
126
|
+
* @return {Promise<(SellAction>} SellAction
|
|
128
127
|
*
|
|
129
128
|
* @private
|
|
130
129
|
*/
|
|
@@ -179,9 +178,7 @@ const createExchangeAction = async (
|
|
|
179
178
|
'0x', // wrapperData,
|
|
180
179
|
offchainDataArray,
|
|
181
180
|
];
|
|
182
|
-
return
|
|
183
|
-
? new SellAction(orderData, fromAccount, toAccount, protocolFee)
|
|
184
|
-
: new BuyAction(orderData, fromAccount, toAccount, protocolFee)
|
|
181
|
+
return new SellAction(orderData, fromAccount, toAccount, protocolFee)
|
|
185
182
|
};
|
|
186
183
|
|
|
187
184
|
/**
|
|
@@ -217,38 +214,3 @@ module.exports.createSellAction = async (
|
|
|
217
214
|
fromAccount,
|
|
218
215
|
toAccount,
|
|
219
216
|
);
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
/**
|
|
223
|
-
* Fetches prices and creates order ready to be passed to transaction.
|
|
224
|
-
* This should only be called when before sending tx, not to be used for just querying the price.
|
|
225
|
-
* For that purpose, the estimateBuyPrice method can be used.
|
|
226
|
-
*
|
|
227
|
-
* @param buyAmount {string} Amount of asset being bought ('1500.123')
|
|
228
|
-
* @param buyToken {string} Symbol for asset being bought ('DAI')
|
|
229
|
-
* @param sellToken {string} Symbol for asset being sold ('ETH')
|
|
230
|
-
* @param expectedPrice {string} Price received from estimatePrice (so minPrice can be calculated based on what user saw)
|
|
231
|
-
* @param acceptedSlippagePercent {string|Number} Slippage percentage tolerated [0-100]
|
|
232
|
-
* @param fromAccount {EthAddress} Withdraw funds from this addr
|
|
233
|
-
* @param toAccount {EthAddress} Send funds to this addr
|
|
234
|
-
* @return {Promise<BuyAction>}
|
|
235
|
-
*/
|
|
236
|
-
module.exports.createBuyAction = async (
|
|
237
|
-
buyAmount,
|
|
238
|
-
buyToken,
|
|
239
|
-
sellToken,
|
|
240
|
-
expectedPrice,
|
|
241
|
-
acceptedSlippagePercent,
|
|
242
|
-
fromAccount,
|
|
243
|
-
toAccount,
|
|
244
|
-
) => createExchangeAction(
|
|
245
|
-
sellToken,
|
|
246
|
-
buyToken,
|
|
247
|
-
'0',
|
|
248
|
-
buyAmount,
|
|
249
|
-
expectedPrice,
|
|
250
|
-
acceptedSlippagePercent,
|
|
251
|
-
false,
|
|
252
|
-
fromAccount,
|
|
253
|
-
toAccount,
|
|
254
|
-
);
|
|
@@ -626,23 +626,6 @@
|
|
|
626
626
|
]
|
|
627
627
|
]
|
|
628
628
|
],
|
|
629
|
-
"DyDxSupply": [
|
|
630
|
-
[
|
|
631
|
-
"0xA8D1C1eea86573cBcC919fbf28Db542bDfE7Ed5b",
|
|
632
|
-
[ 1, 0, 14, 5, 3, 12 ]
|
|
633
|
-
],
|
|
634
|
-
[
|
|
635
|
-
"0x1E0447b19BB6EcFdAe1e4AE1694b0C3659614e4e",
|
|
636
|
-
[ 13, 1, 12, 10, 9 ]
|
|
637
|
-
],
|
|
638
|
-
[
|
|
639
|
-
"0x5c55B921f590a89C1Ebe84dF170E655a82b62126",
|
|
640
|
-
[
|
|
641
|
-
10, 6, 1, 7,
|
|
642
|
-
0, 5, 13
|
|
643
|
-
]
|
|
644
|
-
]
|
|
645
|
-
],
|
|
646
629
|
"DyDxWithdraw": [
|
|
647
630
|
[
|
|
648
631
|
"0x55AA33F42D79DbD3f1885b410e4796d641549bC3",
|
|
@@ -893,41 +876,6 @@
|
|
|
893
876
|
[ 3, 5, 14, 7, 6, 11 ]
|
|
894
877
|
]
|
|
895
878
|
],
|
|
896
|
-
"ClaimInstMaker": [
|
|
897
|
-
[
|
|
898
|
-
"0x15E22A8160F0bDb619C6846C982F8D208A5670D2",
|
|
899
|
-
[
|
|
900
|
-
0, 12, 6, 1,
|
|
901
|
-
13, 5, 9
|
|
902
|
-
]
|
|
903
|
-
],
|
|
904
|
-
[
|
|
905
|
-
"0x2971AdFa57b20E5a416aE5a708A8655A9c74f723",
|
|
906
|
-
[ 7, 3, 9, 5, 15 ]
|
|
907
|
-
],
|
|
908
|
-
[
|
|
909
|
-
"0x5ef30b9986345249bc32d8928B7ee64DE9435E39",
|
|
910
|
-
[ 3, 8, 1, 9, 4, 7 ]
|
|
911
|
-
],
|
|
912
|
-
[
|
|
913
|
-
"0xAC838332afc2937FdED89c16a59b2ED8e8e2743c",
|
|
914
|
-
[ 10, 4, 3, 0, 1, 15 ]
|
|
915
|
-
],
|
|
916
|
-
[
|
|
917
|
-
"0x6f40d4A6237C257fff2dB00FA0510DeEECd303eb",
|
|
918
|
-
[
|
|
919
|
-
14, 11, 5, 10,
|
|
920
|
-
6, 9, 12, 13
|
|
921
|
-
]
|
|
922
|
-
],
|
|
923
|
-
[
|
|
924
|
-
"0x5c55B921f590a89C1Ebe84dF170E655a82b62126",
|
|
925
|
-
[
|
|
926
|
-
12, 4, 1, 9,
|
|
927
|
-
5, 10, 11, 0
|
|
928
|
-
]
|
|
929
|
-
]
|
|
930
|
-
],
|
|
931
879
|
"InstPullTokens": [
|
|
932
880
|
[
|
|
933
881
|
"0x37FC940Be30e11d578243dEBea4f9B950E22aC99",
|
|
@@ -1397,26 +1345,6 @@
|
|
|
1397
1345
|
[ 10, 3, 8, 13, 6, 9 ]
|
|
1398
1346
|
]
|
|
1399
1347
|
],
|
|
1400
|
-
"DFSBuy": [
|
|
1401
|
-
[
|
|
1402
|
-
"0x939dCad6A3D1fEACccB60Af90876D904468CbF66",
|
|
1403
|
-
[ 11, 5, 8, 0, 9, 12 ]
|
|
1404
|
-
],
|
|
1405
|
-
[
|
|
1406
|
-
"0x25dd3F51e0C3c3Ff164DDC02A8E4D65Bb9cBB12D",
|
|
1407
|
-
[
|
|
1408
|
-
1, 5, 3, 14,
|
|
1409
|
-
7, 11, 12, 4
|
|
1410
|
-
]
|
|
1411
|
-
],
|
|
1412
|
-
[
|
|
1413
|
-
"0x5c55B921f590a89C1Ebe84dF170E655a82b62126",
|
|
1414
|
-
[
|
|
1415
|
-
1, 3, 2, 9,
|
|
1416
|
-
0, 15, 6
|
|
1417
|
-
]
|
|
1418
|
-
]
|
|
1419
|
-
],
|
|
1420
1348
|
"SendToken": [
|
|
1421
1349
|
[
|
|
1422
1350
|
"0xBbe0D7f2AF01aE678f8A873CB2d2EB73871C9b5A",
|
|
@@ -21,7 +21,7 @@ class Recipe {
|
|
|
21
21
|
|
|
22
22
|
this.name = name;
|
|
23
23
|
this.actions = actions;
|
|
24
|
-
this.
|
|
24
|
+
this.recipeExecutorAddress = getAddr('RecipeExecutor');
|
|
25
25
|
}
|
|
26
26
|
|
|
27
27
|
/**
|
|
@@ -56,7 +56,7 @@ class Recipe {
|
|
|
56
56
|
encodeForDsProxyCall() {
|
|
57
57
|
const executeTaskAbi = RecipeAbi.find(({name}) => name === 'executeTask');
|
|
58
58
|
return [
|
|
59
|
-
this.
|
|
59
|
+
this.recipeExecutorAddress,
|
|
60
60
|
AbiCoder.encodeFunctionCall(executeTaskAbi, this._encodeForCall()),
|
|
61
61
|
];
|
|
62
62
|
}
|
|
@@ -107,7 +107,7 @@ class Recipe {
|
|
|
107
107
|
*/
|
|
108
108
|
getAccessList() {
|
|
109
109
|
const addressMapping = {
|
|
110
|
-
[getAddr('
|
|
110
|
+
[getAddr('RecipeExecutor')]: [],
|
|
111
111
|
[getAddr('DFSRegistry')]: [],
|
|
112
112
|
};
|
|
113
113
|
this.actions.forEach((action) => {
|
|
@@ -3,14 +3,14 @@ const {encodeForDsProxyCall, encodeForRecipe} = require('../../_actionUtils');
|
|
|
3
3
|
const {assert} = require('chai');
|
|
4
4
|
const { getAddr } = require('../../../src/addresses.js');
|
|
5
5
|
|
|
6
|
-
describe('Action:
|
|
6
|
+
describe('Action: InstPullTokensAction', () => {
|
|
7
7
|
let action;
|
|
8
8
|
|
|
9
9
|
const dsaAddress = '0x63bf1D484d7D799722b1BA9c91f5ffa6d416D60A';
|
|
10
10
|
const to = '0x0a80C3C540eEF99811f4579fa7b1A0617294e06f';
|
|
11
11
|
|
|
12
12
|
|
|
13
|
-
context('
|
|
13
|
+
context('InstPullTokensAction action test', () => {
|
|
14
14
|
it('constructor', () => {
|
|
15
15
|
action = new dfs.actions.insta.InstPullTokensAction(
|
|
16
16
|
dsaAddress,
|
package/test/index.js
CHANGED
|
@@ -3,6 +3,9 @@ const {assert} = require('chai');
|
|
|
3
3
|
|
|
4
4
|
describe('DFS', () => {
|
|
5
5
|
it('Exports constructors', () => {
|
|
6
|
-
assert.containsAllKeys(dfs, [
|
|
6
|
+
assert.containsAllKeys(dfs, [
|
|
7
|
+
'Action', 'Recipe', 'actions', 'actionAddresses', 'utils', 'DfsWeb3', 'configure', 'getNetworkData', 'networks',
|
|
8
|
+
'actionAddressesAllChains',
|
|
9
|
+
]);
|
|
7
10
|
})
|
|
8
11
|
})
|
|
@@ -83,12 +83,4 @@ describe('Exchange utils', () => {
|
|
|
83
83
|
}).timeout(10000);
|
|
84
84
|
})
|
|
85
85
|
|
|
86
|
-
context('Get BuyAction via 0x', function() {
|
|
87
|
-
it('Creates action', async () => {
|
|
88
|
-
const action = await exchangeUtils.createBuyAction('10000', 'DAI', 'ETH', '0', 0, myAddr, myAddr);
|
|
89
|
-
assert.instanceOf(action, dfs.actions.basic.BuyAction);
|
|
90
|
-
assert.equal(action.args[1], myAddr);
|
|
91
|
-
assert.equal(action.args[2], myAddr);
|
|
92
|
-
}).timeout(10000);
|
|
93
|
-
})
|
|
94
86
|
})
|
|
@@ -1,53 +0,0 @@
|
|
|
1
|
-
const Action = require("../../Action");
|
|
2
|
-
const {requireAddress} = require("../../utils/general");
|
|
3
|
-
const {getAssetInfoByAddress} = require("@defisaver/tokens");
|
|
4
|
-
const {getAddr} = require('../../addresses.js');
|
|
5
|
-
const Dec = require('decimal.js');
|
|
6
|
-
const {parsePriceFromContract} = require('../../utils/general');
|
|
7
|
-
|
|
8
|
-
/**
|
|
9
|
-
* Buys an exact amount of dest token on DeFi Saver exchange aggregator
|
|
10
|
-
*/
|
|
11
|
-
class BuyAction extends Action {
|
|
12
|
-
/**
|
|
13
|
-
* @param exchangeOrder {Array} Standard DFS Exchange data
|
|
14
|
-
* @param from {string} Order sender
|
|
15
|
-
* @param to {string} Order recipient
|
|
16
|
-
* @param protocolFee {string} 0x fee (amount of ETH in Wei)
|
|
17
|
-
*/
|
|
18
|
-
constructor(exchangeOrder, from, to, protocolFee) {
|
|
19
|
-
requireAddress(to);
|
|
20
|
-
super(
|
|
21
|
-
'DFSBuy',
|
|
22
|
-
getAddr('DFSBuy'),
|
|
23
|
-
[
|
|
24
|
-
["address","address","uint256","uint256","uint256","uint256","address","address","bytes",["address","address","address","uint256","uint256","bytes"]],
|
|
25
|
-
"address",
|
|
26
|
-
"address",
|
|
27
|
-
],
|
|
28
|
-
[exchangeOrder, from, to]
|
|
29
|
-
);
|
|
30
|
-
|
|
31
|
-
this.protocolFee = protocolFee;
|
|
32
|
-
|
|
33
|
-
this.mappableArgs = [
|
|
34
|
-
this.args[0][0],
|
|
35
|
-
this.args[0][1],
|
|
36
|
-
this.args[0][3],
|
|
37
|
-
this.args[1],
|
|
38
|
-
this.args[2],
|
|
39
|
-
];
|
|
40
|
-
}
|
|
41
|
-
|
|
42
|
-
async getAssetsToApprove() {
|
|
43
|
-
const asset = getAssetInfoByAddress(this.args[0][0]);
|
|
44
|
-
if (asset.symbol !== 'ETH') return [{asset: this.args[0][0], owner: this.args[1]}];
|
|
45
|
-
return [];
|
|
46
|
-
}
|
|
47
|
-
|
|
48
|
-
async getEthValue() {
|
|
49
|
-
return this.protocolFee || '0';
|
|
50
|
-
}
|
|
51
|
-
}
|
|
52
|
-
|
|
53
|
-
module.exports = BuyAction;
|
|
@@ -1,25 +0,0 @@
|
|
|
1
|
-
const Action = require("../../Action");
|
|
2
|
-
const {getAssetInfoByAddress} = require("@defisaver/tokens");
|
|
3
|
-
const { getAddr } = require('../../addresses.js');
|
|
4
|
-
|
|
5
|
-
/**
|
|
6
|
-
* DyDxSupplyAction - Supply token to an DyDx position
|
|
7
|
-
*/
|
|
8
|
-
class DyDxSupplyAction extends Action {
|
|
9
|
-
/**
|
|
10
|
-
* @param tokenAddr {EthAddress}
|
|
11
|
-
* @param amount {string}
|
|
12
|
-
* @param from {EthAddress} Tokens will be supplied from this address
|
|
13
|
-
*/
|
|
14
|
-
constructor(tokenAddr, amount, from) {
|
|
15
|
-
super('DyDxSupply', getAddr('DyDxSupply'), ['address','uint256','address'], [tokenAddr, amount, from]);
|
|
16
|
-
}
|
|
17
|
-
|
|
18
|
-
async getAssetsToApprove() {
|
|
19
|
-
const asset = getAssetInfoByAddress(this.args[0]);
|
|
20
|
-
if (asset.symbol !== 'ETH') return [{asset: this.args[0], owner: this.args[2], specialApproveLabel: 'dydx'}];
|
|
21
|
-
return [];
|
|
22
|
-
}
|
|
23
|
-
}
|
|
24
|
-
|
|
25
|
-
module.exports = DyDxSupplyAction;
|
|
@@ -1,21 +0,0 @@
|
|
|
1
|
-
const Action = require("../../Action");
|
|
2
|
-
const { getAssetInfoByAddress, getAssetInfo } = require("@defisaver/tokens");
|
|
3
|
-
const { getAddr } = require("../../addresses.js");
|
|
4
|
-
|
|
5
|
-
class ClaimInstMakerAction extends Action {
|
|
6
|
-
constructor(index, vaultId, rewardAmount, networthAmount, merkleProof, owner, to) {
|
|
7
|
-
super(
|
|
8
|
-
"ClaimInstMaker",
|
|
9
|
-
getAddr("ClaimInstMaker"),
|
|
10
|
-
[["uint256", "uint256", "uint256", "uint256", "bytes32[]", "address", "address"]],
|
|
11
|
-
[[index, vaultId, rewardAmount, networthAmount, merkleProof,owner, to]]
|
|
12
|
-
);
|
|
13
|
-
this.mappableArgs = [];
|
|
14
|
-
}
|
|
15
|
-
|
|
16
|
-
async getAssetsToApprove() {
|
|
17
|
-
return [];
|
|
18
|
-
}
|
|
19
|
-
}
|
|
20
|
-
|
|
21
|
-
module.exports = ClaimInstMakerAction;
|
|
@@ -1,100 +0,0 @@
|
|
|
1
|
-
const dfs = require('../../../index.js');
|
|
2
|
-
const {assetAmountInEth} = require("@defisaver/tokens");
|
|
3
|
-
const {assetAmountInWei} = require("@defisaver/tokens");
|
|
4
|
-
const {getAssetInfo} = require("@defisaver/tokens");
|
|
5
|
-
const {encodeForDsProxyCall, encodeForRecipe} = require('../../_actionUtils');
|
|
6
|
-
const {assert} = require('chai');
|
|
7
|
-
|
|
8
|
-
describe('Action: Buy', () => {
|
|
9
|
-
let action;
|
|
10
|
-
|
|
11
|
-
context('Without param mappings', () => {
|
|
12
|
-
it('constructor', () => {
|
|
13
|
-
action = new dfs.actions.basic.BuyAction(
|
|
14
|
-
[getAssetInfo('DAI').address, '0xc02aaa39b223fe8d0a0e5c4f27ead9083c756cc2', 0, 1000000000000, 0, 0, '0x0000000000000000000000000000000000000000', '0x6403BD92589F825FfeF6b62177FCe9149947cb9f', '0x000000000000000000000000000000000000000000000000000000000000002000000000000000000000000000000000000000000000000000000000000000020000000000000000000000006b175474e89094c44da98b954eedeac495271d0f000000000000000000000000c02aaa39b223fe8d0a0e5c4f27ead9083c756cc2', ['0x0000000000000000000000000000000000000000','0x0000000000000000000000000000000000000000', '0x0000000000000000000000000000000000000000', 0, 0, []]],
|
|
15
|
-
'0x0a80C3C540eEF99811f4579fa7b1A0617294e06f',
|
|
16
|
-
'0x0a80C3C540eEF99811f4579fa7b1A0617294e06f'
|
|
17
|
-
);
|
|
18
|
-
})
|
|
19
|
-
it('encodeForDsProxyCall', () => encodeForDsProxyCall(action));
|
|
20
|
-
it('encodeForRecipe', () => encodeForRecipe(action));
|
|
21
|
-
it('getAssetsToApprove', async () => {
|
|
22
|
-
const assetOwnerPairs = await action.getAssetsToApprove();
|
|
23
|
-
assert.lengthOf(assetOwnerPairs, 1);
|
|
24
|
-
assert.equal(assetOwnerPairs[0].asset, getAssetInfo('DAI').address);
|
|
25
|
-
assert.equal(assetOwnerPairs[0].owner, '0x0a80C3C540eEF99811f4579fa7b1A0617294e06f');
|
|
26
|
-
})
|
|
27
|
-
it('getEthValue', async () => {
|
|
28
|
-
const ethValue = await action.getEthValue();
|
|
29
|
-
assert.equal(ethValue, '0');
|
|
30
|
-
})
|
|
31
|
-
})
|
|
32
|
-
|
|
33
|
-
context('With param mappings inside tuple', () => {
|
|
34
|
-
it('constructor', () => {
|
|
35
|
-
action = new dfs.actions.basic.BuyAction(
|
|
36
|
-
['0xc02aaa39b223fe8d0a0e5c4f27ead9083c756cc2', '0xc02aaa39b223fe8d0a0e5c4f27ead9083c756cc2', 0, '$1', 0, 0, '0x0000000000000000000000000000000000000000', '0x6403BD92589F825FfeF6b62177FCe9149947cb9f', '0x000000000000000000000000000000000000000000000000000000000000002000000000000000000000000000000000000000000000000000000000000000020000000000000000000000006b175474e89094c44da98b954eedeac495271d0f000000000000000000000000c02aaa39b223fe8d0a0e5c4f27ead9083c756cc2', ['0x0000000000000000000000000000000000000000','0x0000000000000000000000000000000000000000', '0x0000000000000000000000000000000000000000', 0, 0, []]],
|
|
37
|
-
'0x0a80C3C540eEF99811f4579fa7b1A0617294e06f',
|
|
38
|
-
'0x0a80C3C540eEF99811f4579fa7b1A0617294e06f'
|
|
39
|
-
);
|
|
40
|
-
})
|
|
41
|
-
it('encodeForDsProxyCall', () => encodeForDsProxyCall(action));
|
|
42
|
-
it('encodeForRecipe', () => encodeForRecipe(action));
|
|
43
|
-
})
|
|
44
|
-
|
|
45
|
-
context('Buy DAI with ETH', () => {
|
|
46
|
-
it('constructor', () => {
|
|
47
|
-
action = new dfs.actions.basic.BuyAction(
|
|
48
|
-
[getAssetInfo('WETH').address, getAssetInfo('DAI').address, '0', assetAmountInWei('1000', 'DAI'), '1813717262792943307400', 0, '0x0000000000000000000000000000000000000000', '0x0000000000000000000000000000000000000000', '0x', ['0x0c4e16899f2059F4e41ddB164317414a5c0d2988','0xdef1c0ded9bec7f1a1670819833240f027b25eff', '0xdef1c0ded9bec7f1a1670819833240f027b25eff', '1813717262792943307400', '0', '0x415565b0000000000000000000000000c02aaa39b223fe8d0a0e5c4f27ead9083c756cc20000000000000000000000006b175474e89094c44da98b954eedeac495271d0fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff00000000000000000000000000000000000000000000021e19e0c9bab240000000000000000000000000000000000000000000000000000000000000000000a00000000000000000000000000000000000000000000000000000000000000002000000000000000000000000000000000000000000000000000000000000004000000000000000000000000000000000000000000000000000000000000003a0000000000000000000000000000000000000000000000000000000000000000e0000000000000000000000000000000000000000000000000000000000000040000000000000000000000000000000000000000000000000000000000000030000000000000000000000000000000000000000000000000000000000000000200000000000000000000000000000000000000000000000000000000000000001000000000000000000000000c02aaa39b223fe8d0a0e5c4f27ead9083c756cc20000000000000000000000006b175474e89094c44da98b954eedeac495271d0f000000000000000000000000000000000000000000000000000000000000012000000000000000000000000000000000000000000000000000000000000002c000000000000000000000000000000000000000000000000000000000000002c000000000000000000000000000000000000000000000000000000000000002a000000000000000000000000000000000000000000000021e19e0c9bab2400000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000010000000000000000000000000000000000000000000000000000000000000020000000000000000000000000000000000000000000000000000000000000000e0000000000000000000000000000000000000000000000004c84061358b7eca100000000000000000000000000000000000000000000021e19e0c9bab2400000000000000000000000000000000000000000000000000000000000000000008000000000000000000000000000000000000000000000000000000000000000a0000000000000000000000000d9e1ce17f2641f24ae83637ab66a2cca9c378b9f00000000000000000000000000000000000000000000000000000000000000400000000000000000000000000000000000000000000000000000000000000002000000000000000000000000c02aaa39b223fe8d0a0e5c4f27ead9083c756cc20000000000000000000000006b175474e89094c44da98b954eedeac495271d0f000000000000000000000000000000000000000000000000000000000000000100000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000007000000000000000000000000000000000000000000000000000000000000004000000000000000000000000000000000000000000000000000000000000001000000000000000000000000000000000000000000000000000000000000000020000000000000000000000000000000000000000000000000000000000000004000000000000000000000000000000000000000000000000000000000000000c00000000000000000000000000000000000000000000000000000000000000003000000000000000000000000c02aaa39b223fe8d0a0e5c4f27ead9083c756cc20000000000000000000000006b175474e89094c44da98b954eedeac495271d0f000000000000000000000000eeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeee0000000000000000000000000000000000000000000000000000000000000000869584cd000000000000000000000000322d58b9e75a6918f7e7849aee0ff09369977e0800000000000000000000000000000000000000000000007ef75d3d7d6048be6e']],
|
|
49
|
-
'0x0a80C3C540eEF99811f4579fa7b1A0617294e06f',
|
|
50
|
-
'0x0a80C3C540eEF99811f4579fa7b1A0617294e06f'
|
|
51
|
-
);
|
|
52
|
-
})
|
|
53
|
-
it('encodeForDsProxyCall', () => encodeForDsProxyCall(action));
|
|
54
|
-
it('encodeForRecipe', () => encodeForRecipe(action));
|
|
55
|
-
it('getAssetsToApprove', async () => {
|
|
56
|
-
const assetOwnerPairs = await action.getAssetsToApprove();
|
|
57
|
-
assert.lengthOf(assetOwnerPairs, 1);
|
|
58
|
-
assert.equal(assetOwnerPairs[0].asset, getAssetInfo('WETH').address);
|
|
59
|
-
assert.equal(assetOwnerPairs[0].owner, '0x0a80C3C540eEF99811f4579fa7b1A0617294e06f');
|
|
60
|
-
})
|
|
61
|
-
it('getEthValue', async () => {
|
|
62
|
-
const ethValue = await action.getEthValue();
|
|
63
|
-
assert.isAtLeast(+assetAmountInEth(ethValue, 'WETH'), 0);
|
|
64
|
-
})
|
|
65
|
-
})
|
|
66
|
-
|
|
67
|
-
context('Buy DAI with USDC', () => {
|
|
68
|
-
it('constructor', () => {
|
|
69
|
-
action = new dfs.actions.basic.BuyAction(
|
|
70
|
-
[getAssetInfo('USDC').address, getAssetInfo('DAI').address, 0, assetAmountInWei('1000', 'DAI'), 0, 0, '0x0000000000000000000000000000000000000000', '0x6403BD92589F825FfeF6b62177FCe9149947cb9f', '0x000000000000000000000000000000000000000000000000000000000000002000000000000000000000000000000000000000000000000000000000000000020000000000000000000000006b175474e89094c44da98b954eedeac495271d0f000000000000000000000000c02aaa39b223fe8d0a0e5c4f27ead9083c756cc2', ['0x0000000000000000000000000000000000000000','0x0000000000000000000000000000000000000000', '0x0000000000000000000000000000000000000000', 0, 0, []]],
|
|
71
|
-
'0x0a80C3C540eEF99811f4579fa7b1A0617294e06f',
|
|
72
|
-
'0x0a80C3C540eEF99811f4579fa7b1A0617294e06f'
|
|
73
|
-
);
|
|
74
|
-
})
|
|
75
|
-
it('encodeForDsProxyCall', () => encodeForDsProxyCall(action));
|
|
76
|
-
it('encodeForRecipe', () => encodeForRecipe(action));
|
|
77
|
-
it('getAssetsToApprove', async () => {
|
|
78
|
-
const assetOwnerPairs = await action.getAssetsToApprove();
|
|
79
|
-
assert.lengthOf(assetOwnerPairs, 1);
|
|
80
|
-
assert.equal(assetOwnerPairs[0].asset, getAssetInfo('USDC').address);
|
|
81
|
-
assert.equal(assetOwnerPairs[0].owner, '0x0a80C3C540eEF99811f4579fa7b1A0617294e06f');
|
|
82
|
-
})
|
|
83
|
-
it('getEthValue', async () => {
|
|
84
|
-
const ethValue = await action.getEthValue();
|
|
85
|
-
assert.isAtLeast(+assetAmountInEth(ethValue, 'WETH'), 0);
|
|
86
|
-
})
|
|
87
|
-
})
|
|
88
|
-
|
|
89
|
-
context('Buy and send to invalid address', () => {
|
|
90
|
-
it('constructor throws', () => {
|
|
91
|
-
assert.throws(() => {
|
|
92
|
-
action = new dfs.actions.basic.BuyAction(
|
|
93
|
-
[getAssetInfo('USDC').address, getAssetInfo('DAI').address, 0, assetAmountInWei('1000', 'DAI'), 0, 0, '0x0000000000000000000000000000000000000000', '0x6403BD92589F825FfeF6b62177FCe9149947cb9f', '0x000000000000000000000000000000000000000000000000000000000000002000000000000000000000000000000000000000000000000000000000000000020000000000000000000000006b175474e89094c44da98b954eedeac495271d0f000000000000000000000000c02aaa39b223fe8d0a0e5c4f27ead9083c756cc2', ['0x0000000000000000000000000000000000000000','0x0000000000000000000000000000000000000000', '0x0000000000000000000000000000000000000000', 0, 0, []]],
|
|
94
|
-
'0x0a80C3C540eEF99811f4579fa7b1A0617294e06f',
|
|
95
|
-
'0x0000000000000000000000000000000000000000'
|
|
96
|
-
);
|
|
97
|
-
});
|
|
98
|
-
});
|
|
99
|
-
})
|
|
100
|
-
})
|
|
@@ -1,78 +0,0 @@
|
|
|
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: DyDxSupplyAction', () => {
|
|
8
|
-
let action;
|
|
9
|
-
|
|
10
|
-
const testAcc = '0x0a80C3C540eEF99811f4579fa7b1A0617294e06f';
|
|
11
|
-
|
|
12
|
-
context('Supply 1 ETH', () => {
|
|
13
|
-
it('constructor', () => {
|
|
14
|
-
action = new dfs.actions.dydx.DyDxSupplyAction(
|
|
15
|
-
getAssetInfo('WETH').address,
|
|
16
|
-
assetAmountInWei(1, 'WETH'),
|
|
17
|
-
testAcc,
|
|
18
|
-
);
|
|
19
|
-
})
|
|
20
|
-
it('encodeForDsProxyCall', () => encodeForDsProxyCall(action));
|
|
21
|
-
it('encodeForRecipe', () => encodeForRecipe(action));
|
|
22
|
-
it('getAssetsToApprove', async () => {
|
|
23
|
-
const assetOwnerPairs = await action.getAssetsToApprove();
|
|
24
|
-
assert.lengthOf(assetOwnerPairs, 1);
|
|
25
|
-
assert.equal(assetOwnerPairs[0].asset, getAssetInfo('WETH').address);
|
|
26
|
-
assert.equal(assetOwnerPairs[0].owner, testAcc);
|
|
27
|
-
})
|
|
28
|
-
it('getEthValue', async () => {
|
|
29
|
-
const ethValue = await action.getEthValue();
|
|
30
|
-
assert.equal(assetAmountInEth(ethValue), '0');
|
|
31
|
-
})
|
|
32
|
-
})
|
|
33
|
-
|
|
34
|
-
context('Supply 1 ETH on behalf of', () => {
|
|
35
|
-
it('constructor', () => {
|
|
36
|
-
action = new dfs.actions.dydx.DyDxSupplyAction(
|
|
37
|
-
getAssetInfo('WETH').address,
|
|
38
|
-
assetAmountInWei(1, 'WETH'),
|
|
39
|
-
testAcc,
|
|
40
|
-
);
|
|
41
|
-
})
|
|
42
|
-
it('encodeForDsProxyCall', () => encodeForDsProxyCall(action));
|
|
43
|
-
it('encodeForRecipe', () => encodeForRecipe(action));
|
|
44
|
-
it('getAssetsToApprove', async () => {
|
|
45
|
-
const assetOwnerPairs = await action.getAssetsToApprove();
|
|
46
|
-
assert.lengthOf(assetOwnerPairs, 1);
|
|
47
|
-
assert.equal(assetOwnerPairs[0].asset, getAssetInfo('WETH').address);
|
|
48
|
-
assert.equal(assetOwnerPairs[0].owner, testAcc);
|
|
49
|
-
|
|
50
|
-
})
|
|
51
|
-
it('getEthValue', async () => {
|
|
52
|
-
const ethValue = await action.getEthValue();
|
|
53
|
-
assert.equal(assetAmountInEth(ethValue), '0');
|
|
54
|
-
})
|
|
55
|
-
})
|
|
56
|
-
|
|
57
|
-
context('Supply 1 WBTC', () => {
|
|
58
|
-
it('constructor', () => {
|
|
59
|
-
action = new dfs.actions.dydx.DyDxSupplyAction(
|
|
60
|
-
getAssetInfo('WBTC').address,
|
|
61
|
-
assetAmountInWei(1, 'WBTC'),
|
|
62
|
-
testAcc,
|
|
63
|
-
);
|
|
64
|
-
})
|
|
65
|
-
it('encodeForDsProxyCall', () => encodeForDsProxyCall(action));
|
|
66
|
-
it('encodeForRecipe', () => encodeForRecipe(action));
|
|
67
|
-
it('getAssetsToApprove', async () => {
|
|
68
|
-
const assetOwnerPairs = await action.getAssetsToApprove();
|
|
69
|
-
assert.lengthOf(assetOwnerPairs, 1);
|
|
70
|
-
assert.equal(assetOwnerPairs[0].asset, getAssetInfo('WBTC').address);
|
|
71
|
-
assert.equal(assetOwnerPairs[0].owner, testAcc);
|
|
72
|
-
})
|
|
73
|
-
it('getEthValue', async () => {
|
|
74
|
-
const ethValue = await action.getEthValue();
|
|
75
|
-
assert.equal(ethValue, '0');
|
|
76
|
-
})
|
|
77
|
-
})
|
|
78
|
-
})
|
|
@@ -1,46 +0,0 @@
|
|
|
1
|
-
const dfs = require('../../../index.js');
|
|
2
|
-
const {encodeForDsProxyCall, encodeForRecipe} = require('../../_actionUtils');
|
|
3
|
-
const {assert} = require('chai');
|
|
4
|
-
|
|
5
|
-
describe('Action: ClaimInstMakerAction', () => {
|
|
6
|
-
let action;
|
|
7
|
-
|
|
8
|
-
const testAcc = '0x0a80C3C540eEF99811f4579fa7b1A0617294e06f';
|
|
9
|
-
const merkleProof = [
|
|
10
|
-
'0xadf6648083080d45a44d25d400e399d3cc49189e7b6f497714d3dd0eabfa85f5',
|
|
11
|
-
'0x75498e5089efb5104ee04ebf124d0498ddc9103fbcf231f40c951315e85a8bc6',
|
|
12
|
-
'0x2b94d73cab41590303d19a99dae53ed96975cd945bea914861fa8d9e835ee092',
|
|
13
|
-
'0xce3aeed6316ab0db40b4d286050b8c154c68772a562cd46755f218f7e4ba273a',
|
|
14
|
-
'0x131f93fd7e53c15f7709fb6d1ceff03f9174b47b9567500073fe70c384eeffb1',
|
|
15
|
-
'0xbe8fcca3868516767e82e3ee7024f6d7db4142a3d61580d5c5c3ca83c2e879a4',
|
|
16
|
-
'0xdfdaad234615b6a3301d429cb65ac9355c1ace3d8eb11254ed2205741b713f19',
|
|
17
|
-
'0x3b38004520945b4299cc3767238c1fcbfc80311ffccfe807b8d6018e0a1689f3',
|
|
18
|
-
'0xdafb15b74e2ba8567c06a8f39929d395cb62f21397077d49abfdb9bbbc4503bc',
|
|
19
|
-
'0x01187ca02739e5b2be74b31bdec427cba63e0aed2ec18e76537834350efef60e',
|
|
20
|
-
'0xb603aea54f299c68b184e36174748b3b6dbb7205e4049a1e35a9391cea34f161',
|
|
21
|
-
'0xfa80a2920bb437f7db718d3bc0b1247687d5b2cae710f3dc2b315c6edf734305',
|
|
22
|
-
'0xbc145c0be2d3bf27857248519709740701a787a9c3f685534ac0cac578bfe90c',
|
|
23
|
-
];
|
|
24
|
-
|
|
25
|
-
context('Claim INST tokens for Maker vault', () => {
|
|
26
|
-
it('constructor', () => {
|
|
27
|
-
action = new dfs.actions.insta.ClaimInstMakerAction(
|
|
28
|
-
'3570',
|
|
29
|
-
'22178',
|
|
30
|
-
'35152894943847522649',
|
|
31
|
-
'5926144717204641000000',
|
|
32
|
-
merkleProof,
|
|
33
|
-
testAcc,
|
|
34
|
-
testAcc,
|
|
35
|
-
);
|
|
36
|
-
})
|
|
37
|
-
it('encodeForDsProxyCall', () => encodeForDsProxyCall(action));
|
|
38
|
-
it('encodeForRecipe', () => encodeForRecipe(action));
|
|
39
|
-
it('getAssetsToApprove', async () => {
|
|
40
|
-
const assetOwnerPairs = await action.getAssetsToApprove();
|
|
41
|
-
assert.lengthOf(assetOwnerPairs, 0);
|
|
42
|
-
})
|
|
43
|
-
})
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
})
|