@defisaver/sdk 1.0.1 → 1.0.2

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.
Files changed (170) hide show
  1. package/.babelrc +3 -0
  2. package/.eslintrc.js +100 -0
  3. package/package.json +8 -3
  4. package/src/Action.ts +47 -42
  5. package/src/ActionWithL2.ts +6 -6
  6. package/src/DfsWeb3.ts +20 -25
  7. package/src/Recipe.ts +18 -16
  8. package/src/Strategy.ts +10 -8
  9. package/src/actions/aave/AaveBorrowAction.ts +4 -4
  10. package/src/actions/aave/AaveClaimStkAaveAction.ts +5 -5
  11. package/src/actions/aave/AaveCollateralSwitchAction.ts +7 -7
  12. package/src/actions/aave/AavePaybackAction.ts +6 -6
  13. package/src/actions/aave/AaveSupplyAction.ts +7 -7
  14. package/src/actions/aave/AaveWithdrawAction.ts +6 -6
  15. package/src/actions/aaveV3/AaveV3ATokenPaybackAction.ts +13 -11
  16. package/src/actions/aaveV3/AaveV3BorrowAction.ts +11 -9
  17. package/src/actions/aaveV3/AaveV3ClaimRewardsAction.ts +7 -6
  18. package/src/actions/aaveV3/AaveV3CollateralSwitchAction.ts +8 -7
  19. package/src/actions/aaveV3/AaveV3PaybackAction.ts +20 -19
  20. package/src/actions/aaveV3/AaveV3SetEModeAction.ts +6 -6
  21. package/src/actions/aaveV3/AaveV3SupplyAction.ts +17 -18
  22. package/src/actions/aaveV3/AaveV3SwapBorrowRateModeAction.ts +10 -9
  23. package/src/actions/aaveV3/AaveV3WithdrawAction.ts +14 -13
  24. package/src/actions/balancer/BalancerV2ClaimAction.ts +14 -15
  25. package/src/actions/balancer/BalancerV2SupplyAction.ts +16 -14
  26. package/src/actions/balancer/BalancerV2WithdrawAction.ts +16 -14
  27. package/src/actions/balancer/index.ts +3 -3
  28. package/src/actions/basic/AutomationV2Unsub.ts +6 -6
  29. package/src/actions/basic/ChangeProxyOwnerAction.ts +5 -5
  30. package/src/actions/basic/GasFeeAction.ts +6 -7
  31. package/src/actions/basic/GasFeeActionL2.ts +6 -6
  32. package/src/actions/basic/PullTokenAction.ts +11 -11
  33. package/src/actions/basic/SellAction.ts +11 -12
  34. package/src/actions/basic/SendTokenAction.ts +8 -8
  35. package/src/actions/basic/SendTokenAndUnwrapAction.ts +8 -8
  36. package/src/actions/basic/SubInputsAction.ts +6 -6
  37. package/src/actions/basic/SumInputsAction.ts +6 -6
  38. package/src/actions/basic/ToggleSubAction.ts +5 -7
  39. package/src/actions/basic/TokenBalanceAction.ts +5 -5
  40. package/src/actions/basic/TransferNFTAction.ts +8 -8
  41. package/src/actions/basic/UnwrapEthAction.ts +11 -10
  42. package/src/actions/basic/UpdateSubAction.ts +8 -8
  43. package/src/actions/basic/WrapEthAction.ts +6 -6
  44. package/src/actions/checkers/AaveV3RatioCheckAction.ts +5 -5
  45. package/src/actions/checkers/CompoundV3RatioCheckAction.ts +6 -6
  46. package/src/actions/checkers/MakerRatioCheckAction.ts +5 -5
  47. package/src/actions/chickenBonds/CBChickenInAction.ts +6 -6
  48. package/src/actions/chickenBonds/CBChickenOutAction.ts +7 -7
  49. package/src/actions/chickenBonds/CBCreateAction.ts +6 -6
  50. package/src/actions/chickenBonds/CBRedeemAction.ts +6 -7
  51. package/src/actions/compound/CompoundBorrowAction.ts +5 -5
  52. package/src/actions/compound/CompoundClaimAction.ts +6 -6
  53. package/src/actions/compound/CompoundCollateralSwitchAction.ts +4 -4
  54. package/src/actions/compound/CompoundGetDebtAction.ts +5 -5
  55. package/src/actions/compound/CompoundPaybackAction.ts +8 -9
  56. package/src/actions/compound/CompoundSupplyAction.ts +8 -9
  57. package/src/actions/compound/CompoundWithdrawAction.ts +5 -5
  58. package/src/actions/compoundV3/CompoundV3AllowAction.ts +16 -16
  59. package/src/actions/compoundV3/CompoundV3BorrowAction.ts +17 -17
  60. package/src/actions/compoundV3/CompoundV3ClaimAction.ts +9 -9
  61. package/src/actions/compoundV3/CompoundV3PaybackAction.ts +32 -33
  62. package/src/actions/compoundV3/CompoundV3SupplyAction.ts +24 -25
  63. package/src/actions/compoundV3/CompoundV3TransferAction.ts +25 -25
  64. package/src/actions/compoundV3/CompoundV3WithdrawAction.ts +9 -9
  65. package/src/actions/compoundV3/index.ts +1 -1
  66. package/src/actions/convex/ConvexClaimAction.ts +51 -52
  67. package/src/actions/convex/ConvexDepositAction.ts +58 -59
  68. package/src/actions/convex/ConvexWithdrawAction.ts +55 -56
  69. package/src/actions/curve/CurveClaimFeesAction.ts +18 -19
  70. package/src/actions/curve/CurveDepositAction.ts +61 -62
  71. package/src/actions/curve/CurveGaugeDepositAction.ts +20 -21
  72. package/src/actions/curve/CurveGaugeWithdrawAction.ts +15 -16
  73. package/src/actions/curve/CurveMintCrvAction.ts +14 -15
  74. package/src/actions/curve/CurveStethPoolDepositAction.ts +27 -27
  75. package/src/actions/curve/CurveStethPoolWithdrawAction.ts +26 -26
  76. package/src/actions/curve/CurveSwapAction.ts +20 -21
  77. package/src/actions/curve/CurveWithdrawAction.ts +56 -57
  78. package/src/actions/dydx/DyDxWithdrawAction.ts +6 -6
  79. package/src/actions/flashloan/AaveV2FlashLoanAction.ts +6 -6
  80. package/src/actions/flashloan/AaveV2FlashLoanPaybackAction.ts +5 -5
  81. package/src/actions/flashloan/AaveV3FlashLoanAction.ts +6 -6
  82. package/src/actions/flashloan/AaveV3FlashLoanPaybackAction.ts +5 -5
  83. package/src/actions/flashloan/BalancerFlashLoanAction.ts +6 -6
  84. package/src/actions/flashloan/BalancerFlashLoanPaybackAction.ts +8 -8
  85. package/src/actions/flashloan/DyDxFlashLoanAction.ts +7 -7
  86. package/src/actions/flashloan/DyDxFlashLoanPaybackAction.ts +5 -5
  87. package/src/actions/flashloan/EulerFlashLoanAction.ts +6 -6
  88. package/src/actions/flashloan/EulerFlashLoanPaybackAction.ts +6 -5
  89. package/src/actions/flashloan/FLAction.ts +51 -0
  90. package/src/actions/flashloan/MakerFlashLoanAction.ts +6 -6
  91. package/src/actions/flashloan/MakerFlashLoanPaybackAction.ts +4 -4
  92. package/src/actions/flashloan/index.ts +3 -2
  93. package/src/actions/guni/GUniDeposit.ts +15 -15
  94. package/src/actions/guni/GUniWithdraw.ts +11 -11
  95. package/src/actions/index.ts +24 -24
  96. package/src/actions/insta/InstPullTokensAction.ts +9 -9
  97. package/src/actions/lido/LidoStakeAction.ts +7 -7
  98. package/src/actions/lido/LidoUnwrapAction.ts +6 -6
  99. package/src/actions/lido/LidoWrapAction.ts +9 -10
  100. package/src/actions/liquity/LiquityBorrowAction.ts +19 -17
  101. package/src/actions/liquity/LiquityClaimAction.ts +14 -14
  102. package/src/actions/liquity/LiquityClaimSPRewardsAction.ts +9 -9
  103. package/src/actions/liquity/LiquityClaimStakingRewardsAction.ts +9 -9
  104. package/src/actions/liquity/LiquityCloseAction.ts +19 -19
  105. package/src/actions/liquity/LiquityEthGainToTroveAction.ts +19 -17
  106. package/src/actions/liquity/LiquityOpenAction.ts +25 -23
  107. package/src/actions/liquity/LiquityPaybackAction.ts +21 -19
  108. package/src/actions/liquity/LiquityRedeemAction.ts +42 -37
  109. package/src/actions/liquity/LiquitySPDepositAction.ts +22 -22
  110. package/src/actions/liquity/LiquitySPWithdrawAction.ts +19 -19
  111. package/src/actions/liquity/LiquityStakeAction.ts +22 -22
  112. package/src/actions/liquity/LiquitySupplyAction.ts +21 -19
  113. package/src/actions/liquity/LiquityUnstakeAction.ts +19 -19
  114. package/src/actions/liquity/LiquityWithdrawAction.ts +18 -16
  115. package/src/actions/maker/MakerClaimAction.ts +8 -8
  116. package/src/actions/maker/MakerGenerateAction.ts +5 -5
  117. package/src/actions/maker/MakerGiveAction.ts +6 -6
  118. package/src/actions/maker/MakerMergeAction.ts +4 -4
  119. package/src/actions/maker/MakerOpenVaultAction.ts +4 -4
  120. package/src/actions/maker/MakerPaybackAction.ts +6 -6
  121. package/src/actions/maker/MakerRatioAction.ts +3 -3
  122. package/src/actions/maker/MakerSupplyAction.ts +6 -6
  123. package/src/actions/maker/MakerWithdrawAction.ts +5 -5
  124. package/src/actions/mstable/MStableClaimAction.ts +23 -23
  125. package/src/actions/mstable/MStableDepositAction.ts +60 -60
  126. package/src/actions/mstable/MStableWithdrawAction.ts +59 -59
  127. package/src/actions/rari/RariDepositAction.ts +4 -4
  128. package/src/actions/rari/RariWithdrawAction.ts +4 -4
  129. package/src/actions/reflexer/ReflexerGenerateAction.ts +6 -6
  130. package/src/actions/reflexer/ReflexerNativeUniV2SaviourDepositAction.ts +10 -11
  131. package/src/actions/reflexer/ReflexerNativeUniV2SaviourGetReservesAction.ts +7 -7
  132. package/src/actions/reflexer/ReflexerNativeUniV2SaviourWithdrawAction.ts +8 -8
  133. package/src/actions/reflexer/ReflexerOpenSafeAction.ts +3 -3
  134. package/src/actions/reflexer/ReflexerPaybackAction.ts +6 -6
  135. package/src/actions/reflexer/ReflexerSupplyAction.ts +6 -6
  136. package/src/actions/reflexer/ReflexerWithdrawAction.ts +5 -5
  137. package/src/actions/uniswap/UniswapSupplyAction.ts +18 -18
  138. package/src/actions/uniswap/UniswapWithdrawAction.ts +16 -16
  139. package/src/actions/uniswapV3/UniswapV3CollectAction.ts +9 -10
  140. package/src/actions/uniswapV3/UniswapV3CreatePoolAction.ts +22 -20
  141. package/src/actions/uniswapV3/UniswapV3MintAction.ts +21 -19
  142. package/src/actions/uniswapV3/UniswapV3SupplyAction.ts +15 -15
  143. package/src/actions/uniswapV3/UniswapV3WithdrawAction.ts +14 -15
  144. package/src/actions/yearn/YearnSupplyAction.ts +7 -7
  145. package/src/actions/yearn/YearnWithdrawAction.ts +7 -7
  146. package/src/addresses.ts +10 -7
  147. package/src/config.ts +6 -6
  148. package/src/index.ts +30 -15
  149. package/src/triggers/AaveV3RatioTrigger.ts +6 -7
  150. package/src/triggers/ChainLinkPriceTrigger.ts +6 -8
  151. package/src/triggers/CompV3RatioTrigger.ts +6 -7
  152. package/src/triggers/CompoundRatioTrigger.ts +6 -7
  153. package/src/triggers/GasPriceTrigger.ts +6 -7
  154. package/src/triggers/LiquityRatioTrigger.ts +9 -10
  155. package/src/triggers/MakerRatioTrigger.ts +6 -7
  156. package/src/triggers/ReflexerRatioTrigger.ts +6 -7
  157. package/src/triggers/TimestampTrigger.ts +6 -7
  158. package/src/triggers/TrailingStopTrigger.ts +6 -7
  159. package/src/triggers/UniV3CurrentTickTrigger.ts +6 -6
  160. package/src/types.ts +9 -7
  161. package/src/utils/convex-utils.ts +9 -9
  162. package/src/utils/curve-utils.ts +11 -8
  163. package/src/utils/general.ts +4 -5
  164. package/src/utils/index.ts +7 -5
  165. package/src/utils/mstableAssetPairs.ts +6 -6
  166. package/src/utils/uniswapLP.ts +14 -16
  167. package/src/utils/uniswapV3LP.ts +5 -4
  168. package/src/utils/zeroExExchange.ts +9 -8
  169. package/.eslintrc +0 -14
  170. package/src/triggers/CompV3Trigger.ts +0 -15
package/.babelrc ADDED
@@ -0,0 +1,3 @@
1
+ {
2
+ "presets": []
3
+ }
package/.eslintrc.js ADDED
@@ -0,0 +1,100 @@
1
+
2
+ module.exports = {
3
+ extends: ['airbnb'],
4
+ plugins: ['import'],
5
+ parser: '@babel/eslint-parser',
6
+ env: {
7
+ es6: true,
8
+ browser: true,
9
+ },
10
+ overrides: [{
11
+ // these are overrides for .ts files, meaning these are only applied to .ts files
12
+ files: ['*.ts', '*.tsx'],
13
+ extends: ['airbnb-typescript'],
14
+ plugins: ['@typescript-eslint'],
15
+ parser: '@typescript-eslint/parser',
16
+ parserOptions: { project: ['./tsconfig.json'] },
17
+ // typescript rules must be added here to work
18
+ rules: {
19
+ '@typescript-eslint/no-unused-vars': 0,
20
+ '@typescript-eslint/naming-convention': 0,
21
+ '@typescript-eslint/default-param-last': 0,
22
+ },
23
+ }],
24
+ parserOptions: {
25
+ ecmaVersion: 2018,
26
+ sourceType: 'module',
27
+ },
28
+ rules: {
29
+ 'no-restricted-syntax': 0,
30
+ 'no-continue': 0,
31
+ 'jsx-a11y/control-has-associated-label': 0,
32
+ 'arrow-parens': 0,
33
+ 'no-async-promise-executor': 0,
34
+ 'no-multiple-empty-lines': [2, { max: 2 }],
35
+ camelcase: [2, { allow: ['^UNSAFE_'] }],
36
+ 'no-mixed-operators': [2, { allowSamePrecedence: true }],
37
+ 'no-plusplus': 0,
38
+ 'no-minusminus': 0,
39
+ 'prefer-destructuring': 0,
40
+ 'max-len': 0,
41
+ 'class-methods-use-this': 0,
42
+ 'jsx-a11y/href-no-hash': 'off',
43
+ 'jsx-a11y/no-autofocus': 0,
44
+ 'no-unused-vars': 0,
45
+ 'no-underscore-dangle': 0,
46
+ 'global-require': 0,
47
+ 'no-console': 0,
48
+ 'new-cap': 0,
49
+ 'eol-last': 0,
50
+ 'jsx-a11y/label-has-for': 0,
51
+ 'linebreak-style': 0,
52
+ 'consistent-return': 0,
53
+ 'import/prefer-default-export': 0,
54
+ 'no-unescaped-entities': 0,
55
+ 'jsx-a11y/no-static-element-interactions': 0,
56
+ 'jsx-a11y/click-events-have-key-events': 0,
57
+ 'jsx-a11y/anchor-is-valid': 0,
58
+ 'no-shadow': 0,
59
+ 'prefer-promise-reject-errors': 0,
60
+ 'function-paren-newline': 0,
61
+ 'operator-linebreak': 0,
62
+ 'jsx-a11y/no-noninteractive-element-interactions': 0,
63
+ 'jsx-a11y/label-has-associated-control': 0,
64
+ 'no-nested-ternary': 0,
65
+ 'import/no-cycle': 0,
66
+ 'import/no-unresolved': 0,
67
+ 'function-call-argument-newline': 0,
68
+ 'import/extensions': [
69
+ 'error',
70
+ 'always',
71
+ {
72
+ pattern: {
73
+ js: 'never',
74
+ ts: 'never',
75
+ },
76
+ },
77
+ ],
78
+ },
79
+ globals: {
80
+ web3: true,
81
+ ethereum: true,
82
+ $: true,
83
+ window: true,
84
+ document: true,
85
+ fetch: true,
86
+ location: true,
87
+ localStorage: true,
88
+ },
89
+ settings: {
90
+ 'import/resolver': {
91
+ typescript: {
92
+ alwaysTryTypes: true,
93
+ project: ['./tsconfig.json'],
94
+ },
95
+ node: {
96
+ extensions: ['.js', '.ts'],
97
+ },
98
+ },
99
+ },
100
+ };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@defisaver/sdk",
3
- "version": "1.0.1",
3
+ "version": "1.0.2",
4
4
  "description": "",
5
5
  "main": "./umd/index.js",
6
6
  "module": "./esm/src/index.js",
@@ -25,11 +25,13 @@
25
25
  "@types/web3-eth-abi": "^1.2.2",
26
26
  "axios": "^0.21.1",
27
27
  "decimal.js": "^10.2.1",
28
+ "web3": "^1.8.0",
28
29
  "web3-eth-abi": "^1.8.0",
29
30
  "web3-utils": "^1.8.0"
30
31
  },
31
32
  "devDependencies": {
32
33
  "@babel/core": "^7.12.10",
34
+ "@babel/eslint-parser": "^7.12.17",
33
35
  "@babel/preset-env": "^7.12.11",
34
36
  "@babel/preset-typescript": "^7.12.7",
35
37
  "@types/node": "^18.11.8",
@@ -38,7 +40,11 @@
38
40
  "babel-loader": "^8.2.2",
39
41
  "chai": "^4.2.0",
40
42
  "dotenv": "^10.0.0",
41
- "eslint": "^8.26.0",
43
+ "eslint": "8.22.0",
44
+ "eslint-config-airbnb": "^18.0.2",
45
+ "eslint-config-airbnb-typescript": "^17.0.0",
46
+ "eslint-import-resolver-typescript": "^3.5.1",
47
+ "eslint-plugin-import": "^2.22.0",
42
48
  "jsdoc-to-markdown": "^6.0.1",
43
49
  "mocha": "^8.2.1",
44
50
  "ts-node": "^10.9.1",
@@ -47,7 +53,6 @@
47
53
  "typescript": "^4.8.4",
48
54
  "webpack": "^5.13.0",
49
55
  "webpack-cli": "^4.10.0",
50
- "web3": "^1.8.0",
51
56
  "@types/web3": "^1.2.2"
52
57
  }
53
58
  }
package/src/Action.ts CHANGED
@@ -2,24 +2,26 @@ import AbiCoder from 'web3-eth-abi';
2
2
  import { keccak256, padLeft, toHex } from 'web3-utils';
3
3
  import { CONFIG } from './config';
4
4
  import ActionAbi from './abis/Action.json';
5
- import { AccessLists as _AccessLists,AccessListItem} from './types';
5
+ import { AccessLists as _AccessLists, AccessListItem, EthAddress } from './types';
6
6
  import { AccessLists } from '../AccessLists';
7
- import { EthAddress } from './types';
8
7
 
9
8
  type ParamTypes = Array<string | Array<any>>;
10
9
  type Args = Array<any>;
11
10
 
12
11
  /**
13
12
  * Single action that can be executed directly, or combined into a set (ie. supply a vault)
14
- *
13
+ *
15
14
  * @category Base Classes
16
15
  */
17
16
  export class Action {
18
-
19
17
  contractAddress : EthAddress;
18
+
20
19
  paramTypes: ParamTypes;
20
+
21
21
  name: string;
22
+
22
23
  args: Args;
24
+
23
25
  mappableArgs: Args;
24
26
 
25
27
  /**
@@ -31,7 +33,7 @@ export class Action {
31
33
  constructor(name: string, contractAddress: EthAddress, paramTypes : ParamTypes, args : Args) {
32
34
  // if (new.target === Action) throw new TypeError("Actions are instantiated using derived classes");
33
35
 
34
- if (paramTypes.length !== args.length) throw new Error('Parameters/arguments length mismatch')
36
+ if (paramTypes.length !== args.length) throw new Error('Parameters/arguments length mismatch');
35
37
 
36
38
  this.contractAddress = contractAddress;
37
39
  this.paramTypes = paramTypes;
@@ -41,26 +43,28 @@ export class Action {
41
43
  }
42
44
 
43
45
  /**
44
- *
46
+ *
45
47
  */
46
48
  getId() : string {
47
49
  return keccak256(this.name).substr(0, 10);
48
50
  }
49
51
 
50
52
  /**
51
- *
53
+ *
52
54
  */
53
- #_getArgumentMappingWithSlots(subSlots: Args) : Array<number>{
55
+ #_getArgumentMappingWithSlots(subSlots: Args) : Array<number> {
54
56
  return this.mappableArgs.map(arg => {
55
57
  if (new RegExp(/\$\d+/).test(arg)) {
56
58
  if (Array.isArray(arg)) throw TypeError('Input can\'t be mapped to arrays (tuples/structs). Specify `mappableArgs` array in constructor.');
57
- return parseInt(arg.substr(1))
59
+ // eslint-disable-next-line
60
+ return parseInt(arg.substr(1));
58
61
  }
59
62
 
60
63
  // Handle SubSlots placeholder values in strategies
61
64
  if (new RegExp(/&\w+/).test(arg)) {
62
65
  if (arg === '&proxy') return 254;
63
66
  if (arg === '&eoa') return 255;
67
+ // eslint-disable-next-line
64
68
  return parseInt(subSlots[arg].index);
65
69
  }
66
70
 
@@ -68,25 +72,27 @@ export class Action {
68
72
  });
69
73
  }
70
74
 
71
- /**
72
- *
75
+ /**
76
+ *
73
77
  */
74
- _getArgumentMapping() : Args {
75
- return this.mappableArgs.map(arg => {
76
- if (new RegExp(/\$\d+/).test(arg)) {
77
- if (Array.isArray(arg)) throw TypeError('Input can\'t be mapped to arrays (tuples/structs). Specify `mappableArgs` array in constructor.');
78
- return parseInt(arg.substr(1))
79
- }
80
- return 0;
81
- });
82
- }
78
+ _getArgumentMapping() : Args {
79
+ return this.mappableArgs.map(arg => {
80
+ if (new RegExp(/\$\d+/).test(arg)) {
81
+ if (Array.isArray(arg)) throw TypeError('Input can\'t be mapped to arrays (tuples/structs). Specify `mappableArgs` array in constructor.');
82
+ // eslint-disable-next-line
83
+ return parseInt(arg.substr(1));
84
+ }
85
+ return 0;
86
+ });
87
+ }
83
88
 
84
89
  /**
85
90
  * @param type
86
- *
91
+ *
87
92
  */
88
93
  #_getPlaceholderForType(type: string) : string {
89
94
  // TODO handle arrays?
95
+ // eslint-disable-next-line
90
96
  if (type.startsWith('bytes')) return `0x${'0'.repeat(parseInt(type.substr(5)))}`;
91
97
  if (type === 'address') return `0x${'0'.repeat(40)}`;
92
98
  if (type === 'string') return '';
@@ -94,19 +100,19 @@ export class Action {
94
100
  }
95
101
 
96
102
  /**
97
- *
103
+ *
98
104
  */
99
105
  _replaceWithPlaceholders(arg: Args, paramType: string | ParamTypes) : any {
100
106
  if (Array.isArray(arg)) return arg.map((_arg, i) => this._replaceWithPlaceholders(_arg, paramType[i]));
101
- if(typeof(paramType) === 'string'){
102
- if (new RegExp(/\$\d+/).test(arg)) return this.#_getPlaceholderForType(paramType);
103
- if (new RegExp(/&\w+/).test(arg)) return this.#_getPlaceholderForType(paramType);
107
+ if (typeof (paramType) === 'string') {
108
+ if (new RegExp(/\$\d+/).test(arg)) return this.#_getPlaceholderForType(paramType);
109
+ if (new RegExp(/&\w+/).test(arg)) return this.#_getPlaceholderForType(paramType);
104
110
  }
105
111
  return arg;
106
112
  }
107
113
 
108
114
  /**
109
- *
115
+ *
110
116
  */
111
117
  _formatType(paramType: string | ParamTypes) : string {
112
118
  if (Array.isArray(paramType)) return `(${paramType.map((_paramType) => this._formatType(_paramType))})`;
@@ -116,7 +122,7 @@ export class Action {
116
122
  /**
117
123
  * Encode arguments for calling the action directly
118
124
  * @returns bytes-encoded args
119
- *
125
+ *
120
126
  */
121
127
  _encodeForCall() : Array<string> {
122
128
  const _arg = this._replaceWithPlaceholders(this.args, this.paramTypes);
@@ -136,42 +142,41 @@ export class Action {
136
142
  * Encode arguments for calling the action via DsProxy
137
143
  * @returns `address` & `data` to be passed on to DSProxy's `execute(address _target, bytes memory _data)`
138
144
  */
139
- encodeForDsProxyCall() : Array<string | string[]>{
145
+ encodeForDsProxyCall() : Array<string | string[]> {
140
146
  if (CONFIG.chainId === 1) {
141
- const executeActionDirectAbi : any = (ActionAbi.find(({ name }:{name: string}) => name === 'executeActionDirect'))!;
147
+ const executeActionDirectAbi : any = (ActionAbi.find(({ name }:{ name: string }) => name === 'executeActionDirect'))!;
142
148
  return [
143
149
  this.contractAddress,
144
150
  AbiCoder.encodeFunctionCall(executeActionDirectAbi, this._encodeForCall()),
145
151
  ];
146
- } else {
147
- return [this.contractAddress, this.encodeForL2DsProxyCall()];
148
152
  }
153
+ return [this.contractAddress, this.encodeForL2DsProxyCall()];
149
154
  }
150
155
 
151
156
  /**
152
157
  * Encodes action for Recipe call
153
158
  */
154
159
  encodeForRecipe() : Array<string | string[] | number[]> {
155
- return [
156
- this._encodeForCall()[0], // actionCallData
157
- "0x0000000000000000000000000000000000000000000000000000000000000000", // subData
158
- this.getId(), // actionIds
159
- this._getArgumentMapping(), // paramMappings
160
- ]
160
+ return [
161
+ this._encodeForCall()[0], // actionCallData
162
+ '0x0000000000000000000000000000000000000000000000000000000000000000', // subData
163
+ this.getId(), // actionIds
164
+ this._getArgumentMapping(), // paramMappings
165
+ ];
161
166
  }
162
167
 
163
- encodeForStrategy(subSlots: any) : Array<(string | number[])>{
168
+ encodeForStrategy(subSlots: any) : Array<(string | number[])> {
164
169
  return [
165
170
  this.getId(),
166
171
  this.#_getArgumentMappingWithSlots(subSlots), // paramMappings
167
- ]
172
+ ];
168
173
  }
169
174
 
170
175
  /**
171
176
  * Assets requiring approval to be used by DsProxy
172
177
  * Approval is done from owner to DsProxy
173
178
  */
174
- async getAssetsToApprove(): Promise<Array<{owner?: string, asset?: string,[key: string]:any}>> {
179
+ async getAssetsToApprove(): Promise<Array<{ owner?: string, asset?: string, [key: string]:any }>> {
175
180
  return [];
176
181
  }
177
182
 
@@ -187,12 +192,12 @@ export class Action {
187
192
  * Access list for single action
188
193
  */
189
194
  getAccessList(chainId: number) : Array<AccessListItem> {
190
- if(chainId!=1) return [];
195
+ if (chainId !== 1) return [];
191
196
  return [
192
197
  [this.contractAddress, []],
193
198
  ...(AccessLists[this.name as keyof _AccessLists] || []),
194
199
  ].map(([address, storageKeys]) => ({
195
- address: address,
200
+ address,
196
201
  storageKeys: storageKeys.map((num: number) => padLeft(toHex(num), 64)),
197
202
  }));
198
203
  }
@@ -1,11 +1,11 @@
1
- import {Action} from './Action';
2
1
  import Dec from 'decimal.js';
3
2
  import AbiCoder from 'web3-eth-abi';
3
+ import { Action } from './Action';
4
4
  import ActionAbi from './abis/Action.json';
5
5
 
6
6
  /**
7
7
  * Single L2 action that can be executed directly, or combined into a set (ie. supply a vault)
8
- *
8
+ *
9
9
  * @category Base Classes
10
10
  */
11
11
  export class ActionWithL2 extends Action {
@@ -25,21 +25,21 @@ export class ActionWithL2 extends Action {
25
25
 
26
26
  addressToBytes20(address:string) { return address.slice(2); }
27
27
 
28
- boolToBytes1(bool:boolean) { return bool ? '01' : '00' }
28
+ boolToBytes1(bool:boolean) { return bool ? '01' : '00'; }
29
29
 
30
30
  async getEthValue() { return '0'; }
31
31
 
32
- numberToBytes2(number:number){
32
+ numberToBytes2(number:number) {
33
33
  const hexNumber = number.toString(16);
34
34
  return hexNumber.padStart(4, '0');
35
35
  }
36
36
 
37
- numberToBytes1(number:number){
37
+ numberToBytes1(number:number) {
38
38
  const hexNumber = number.toString(16);
39
39
  return hexNumber.padStart(2, '0');
40
40
  }
41
41
 
42
- numberToBytes32(number:number){
42
+ numberToBytes32(number:number) {
43
43
  let hexNumber = new Dec(number).toHex();
44
44
  hexNumber = hexNumber.slice(2);
45
45
 
package/src/DfsWeb3.ts CHANGED
@@ -1,25 +1,27 @@
1
+ import Web3 from 'web3';
2
+ import { AbiItem, StateMutabilityType, AbiType } from 'web3-utils';
1
3
  import DFSPRoxyRegistyAbi from './abis/DFSProxyRegistry.json';
2
4
  import ProxyRegistryAbi from './abis/ProxyRegistry.json';
3
5
  import DsProxyAbi from './abis/DsProxy.json';
4
6
  import Erc20Abi from './abis/Erc20.json';
5
7
  import { getAddr } from './addresses';
6
- import {Action} from "./Action";
7
- import {Recipe} from "./Recipe";
8
+ import { Action } from './Action';
9
+ import { Recipe } from './Recipe';
8
10
  import { CONFIG } from './config';
9
11
  import { EthAddress } from './types';
10
12
  // reports error but it works ?????
11
- import Web3 from 'web3';
12
- import { AbiItem, StateMutabilityType, AbiType } from 'web3-utils';
13
13
 
14
14
  /**
15
- *
15
+ *
16
16
  * @category Base Classes
17
17
  */
18
18
  export class DfsWeb3 {
19
-
20
19
  web3: Web3;
20
+
21
21
  accountReady: boolean;
22
+
22
23
  account?: EthAddress;
24
+
23
25
  proxy?: EthAddress;
24
26
 
25
27
  constructor(web3: Web3) {
@@ -42,10 +44,8 @@ export class DfsWeb3 {
42
44
  const accounts = await this.web3.eth.getAccounts();
43
45
  if (!accounts || !accounts.length) throw new Error('Supplied web3 has no account');
44
46
  this.account = accounts[0];
45
- const DFSPRoxyRegistyAbiItems : AbiItem[] = DFSPRoxyRegistyAbi.map(item=>{
46
- return {...item,stateMutability: item.stateMutability as StateMutabilityType,type: item.type as AbiType};
47
- });
48
- const dfsRegistry = new this.web3.eth.Contract(DFSPRoxyRegistyAbiItems, getAddr('DFSProxyRegistry',CONFIG.chainId));
47
+ const DFSPRoxyRegistyAbiItems : AbiItem[] = DFSPRoxyRegistyAbi.map(item => ({ ...item, stateMutability: item.stateMutability as StateMutabilityType, type: item.type as AbiType }));
48
+ const dfsRegistry = new this.web3.eth.Contract(DFSPRoxyRegistyAbiItems, getAddr('DFSProxyRegistry', CONFIG.chainId));
49
49
  const proxies = await dfsRegistry.methods.getAllProxies(this.account).call();
50
50
  if (proxies[0] !== '0x0000000000000000000000000000000000000000') {
51
51
  this.proxy = proxies[0];
@@ -57,10 +57,8 @@ export class DfsWeb3 {
57
57
  if (!this.accountReady) await this.prepareAccount();
58
58
  if (!this.account) throw new Error('DfsWeb3 has not been instantiated properly');
59
59
  if (this.proxy) throw new Error('Account already has DsProxy');
60
- const ProxyRegistryAbiItems : AbiItem[] = ProxyRegistryAbi.map(item=>{
61
- return {...item,stateMutability: item.stateMutability as StateMutabilityType,type: item.type as AbiType};
62
- });
63
- const makerRegistry = new this.web3.eth.Contract(ProxyRegistryAbiItems, getAddr('ProxyRegistry',CONFIG.chainId));
60
+ const ProxyRegistryAbiItems : AbiItem[] = ProxyRegistryAbi.map(item => ({ ...item, stateMutability: item.stateMutability as StateMutabilityType, type: item.type as AbiType }));
61
+ const makerRegistry = new this.web3.eth.Contract(ProxyRegistryAbiItems, getAddr('ProxyRegistry', CONFIG.chainId));
64
62
  return makerRegistry.methods.build();
65
63
  }
66
64
 
@@ -74,9 +72,7 @@ export class DfsWeb3 {
74
72
  const approvals = await action.getAssetsToApprove();
75
73
  await Promise.all(approvals.map(async (a) => {
76
74
  if (a.owner!.toLowerCase() === this.proxy!.toLowerCase()) {
77
- const Erc20AbiItems : AbiItem[] = Erc20Abi.map(item=>{
78
- return {...item,stateMutability: item.stateMutability as StateMutabilityType,type: item.type as AbiType};
79
- });
75
+ const Erc20AbiItems : AbiItem[] = Erc20Abi.map(item => ({ ...item, stateMutability: item.stateMutability as StateMutabilityType, type: item.type as AbiType }));
80
76
  const tokenContract = new this.web3.eth.Contract(Erc20AbiItems, a.asset);
81
77
  const allowance = await tokenContract.methods.allowance(this.account, this.proxy).call();
82
78
  if (parseFloat(allowance.toString()) === 0) {
@@ -90,9 +86,7 @@ export class DfsWeb3 {
90
86
  async execute(address: EthAddress, params: Array<any>) {
91
87
  if (!this.accountReady) await this.prepareAccount();
92
88
  if (!this.proxy) throw new Error('Account does not have a Smart Wallet. Run createSmartWallet first');
93
- const DsProxyAbiItems : AbiItem[] = DsProxyAbi.map(item=>{
94
- return {...item,stateMutability: item.stateMutability as StateMutabilityType,type: item.type as AbiType};
95
- });
89
+ const DsProxyAbiItems : AbiItem[] = DsProxyAbi.map(item => ({ ...item, stateMutability: item.stateMutability as StateMutabilityType, type: item.type as AbiType }));
96
90
  const proxyContract = new this.web3.eth.Contract(DsProxyAbiItems, this.proxy);
97
91
  return proxyContract.methods['execute(address,bytes)'](address, params);
98
92
  }
@@ -101,14 +95,15 @@ export class DfsWeb3 {
101
95
  * @param action
102
96
  */
103
97
  async executeAction(action: Action) : Promise<Action> {
104
- const encoded =action.encodeForDsProxyCall();
105
- return this.execute(encoded[0] as string,encoded[1] as string[]);
98
+ const encoded = action.encodeForDsProxyCall();
99
+ return this.execute(encoded[0] as string, encoded[1] as string[]);
106
100
  }
101
+
107
102
  /**
108
103
  * @param recipe
109
104
  */
110
105
  async executeRecipe(recipe: Recipe) : Promise<Recipe> {
111
- const encoded =recipe.encodeForDsProxyCall();
112
- return this.execute(encoded[0] as string,encoded[1] as unknown as string[]);
106
+ const encoded = recipe.encodeForDsProxyCall();
107
+ return this.execute(encoded[0] as string, encoded[1] as unknown as string[]);
113
108
  }
114
- }
109
+ }
package/src/Recipe.ts CHANGED
@@ -1,10 +1,10 @@
1
1
  import AbiCoder from 'web3-eth-abi';
2
- import {toBN} from 'web3-utils';
3
- import {getAssetInfo, utils} from "@defisaver/tokens";
4
- import {Action} from './Action';
2
+ import { toBN } from 'web3-utils';
3
+ import { getAssetInfo, utils } from '@defisaver/tokens';
4
+ import { Action } from './Action';
5
5
  import { getAddr } from './addresses';
6
6
  import RecipeAbi from './abis/Recipe.json';
7
- import {AccessListItem, EthAddress} from './types';
7
+ import { AccessListItem, EthAddress } from './types';
8
8
  import { CONFIG } from './config';
9
9
 
10
10
  /**
@@ -13,10 +13,12 @@ import { CONFIG } from './config';
13
13
  * @category Base Classes
14
14
  */
15
15
  export class Recipe {
16
-
17
16
  name: string;
17
+
18
18
  actions: Array<Action>;
19
+
19
20
  recipeExecutorAddress: string;
21
+
20
22
  extraGas: number;
21
23
 
22
24
  /**
@@ -32,7 +34,7 @@ export class Recipe {
32
34
  this.actions = actions;
33
35
 
34
36
  this.extraGas = 0;
35
- this.recipeExecutorAddress = getAddr('RecipeExecutor',CONFIG.chainId);
37
+ this.recipeExecutorAddress = getAddr('RecipeExecutor', CONFIG.chainId);
36
38
  }
37
39
 
38
40
  /**
@@ -48,7 +50,7 @@ export class Recipe {
48
50
  * Encode arguments for calling the action set directly
49
51
  *
50
52
  */
51
- #_encodeForCall(): Array<string|Array<any>> {
53
+ #_encodeForCall(): Array<string | Array<any>> {
52
54
  const encoded = this.actions.map(action => action.encodeForRecipe());
53
55
  const transposed = encoded[0].map((_, colIndex) => encoded.map(row => row[colIndex]));
54
56
  const taskStruct = [
@@ -63,7 +65,7 @@ export class Recipe {
63
65
  * @returns `address` & `data` to be passed on to DSProxy's `execute(address _target, bytes memory _data)`
64
66
  */
65
67
  encodeForDsProxyCall() : Array<string> {
66
- const executeTaskAbi : any = RecipeAbi.find(({name}:{name: string}) => name === 'executeRecipe');
68
+ const executeTaskAbi : any = RecipeAbi.find(({ name }:{ name: string }) => name === 'executeRecipe');
67
69
  const encoded = this.#_encodeForCall();
68
70
  return [
69
71
  this.recipeExecutorAddress,
@@ -79,7 +81,7 @@ export class Recipe {
79
81
  this.actions.forEach((action : Action, i : number) => {
80
82
  action._getArgumentMapping().forEach((source, j) => {
81
83
  if (source) console.log(`${this.actions[i].name} takes argument #${j + 1} from ${this.actions[source - 1].name} (action #${source})`);
82
- })
84
+ });
83
85
  });
84
86
  }
85
87
 
@@ -87,14 +89,14 @@ export class Recipe {
87
89
  * Assets requiring approval to be used by DsProxy
88
90
  * Approval is done from owner to DsProxy
89
91
  */
90
- async getAssetsToApprove() : Promise<Array<{owner: string, asset: string}>> {
91
- const uniqueAssetOwnerPairs : Array<{owner: string, asset: string,[key: string]:any}> = [];
92
+ async getAssetsToApprove() : Promise<Array<{ owner: string, asset: string }>> {
93
+ const uniqueAssetOwnerPairs : Array<{ owner: string, asset: string, [key: string]:any }> = [];
92
94
  const assetOwnerPairs = await Promise.all(this.actions.map(a => a.getAssetsToApprove()));
93
95
  for (const pairsPerAction of assetOwnerPairs) {
94
96
  for (const pair of pairsPerAction) {
95
97
  const isNft = !pair.asset;
96
98
  if (!uniqueAssetOwnerPairs.find(_pair => _pair.owner === pair.owner && (isNft ? _pair.tokenId === pair.tokenId : _pair.asset === pair.asset))) {
97
- uniqueAssetOwnerPairs.push({owner:pair.owner!,asset:pair.asset!});
99
+ uniqueAssetOwnerPairs.push({ owner: pair.owner!, asset: pair.asset! });
98
100
  }
99
101
  }
100
102
  }
@@ -116,14 +118,14 @@ export class Recipe {
116
118
  */
117
119
  getAccessList(): Array<AccessListItem> {
118
120
  const addressMapping : any = {
119
- [getAddr('RecipeExecutor',CONFIG.chainId)]: [],
120
- [getAddr('DFSRegistry',CONFIG.chainId)]: [],
121
+ [getAddr('RecipeExecutor', CONFIG.chainId)]: [],
122
+ [getAddr('DFSRegistry', CONFIG.chainId)]: [],
121
123
  };
122
124
  this.actions.forEach((action) => {
123
125
  const accessList = action.getAccessList(CONFIG.chainId);
124
- accessList.forEach(({ address, storageKeys }:{address: EthAddress,storageKeys: Array<string>}) => {
126
+ accessList.forEach(({ address, storageKeys }:{ address: EthAddress, storageKeys: Array<string> }) => {
125
127
  addressMapping[address] = new Set([...storageKeys, ...(addressMapping[address] || [])]);
126
- })
128
+ });
127
129
  });
128
130
  return Object.keys(addressMapping).map((address) => ({
129
131
  address,
package/src/Strategy.ts CHANGED
@@ -1,15 +1,18 @@
1
- import {Action} from './Action';
1
+ import { Action } from './Action';
2
2
 
3
3
  /**
4
- *
4
+ *
5
5
  * @category Base Classes
6
6
  */
7
7
  export class Strategy {
8
-
9
8
  name: string;
9
+
10
10
  subSlots: any;
11
+
11
12
  actions: Array<Action>;
13
+
12
14
  triggers: Array<Action>;
15
+
13
16
  numSubSlots: number;
14
17
 
15
18
  constructor(name: string) {
@@ -21,7 +24,7 @@ export class Strategy {
21
24
  }
22
25
 
23
26
  addSubSlot(name: string, type: string) {
24
- this.subSlots[name] = { type, index: this.numSubSlots + 128 };
27
+ this.subSlots[name] = { type, index: this.numSubSlots + 128 };
25
28
  this.numSubSlots++;
26
29
  }
27
30
 
@@ -34,8 +37,8 @@ export class Strategy {
34
37
  }
35
38
 
36
39
  print() {
37
- console.log(`Name: ${this.name }`);
38
- console.log(`Slots: ${this.subSlots }`);
40
+ console.log(`Name: ${this.name}`);
41
+ console.log(`Slots: ${this.subSlots}`);
39
42
  console.log(`Action: ${this.actions[0]}`);
40
43
  }
41
44
 
@@ -60,8 +63,7 @@ export class Strategy {
60
63
  this.name,
61
64
  triggerIds,
62
65
  actionIds,
63
- paramMappings
66
+ paramMappings,
64
67
  ];
65
68
  }
66
-
67
69
  }
@@ -1,11 +1,11 @@
1
- import {Action} from "../../Action";
2
- import { requireAddress } from "../../utils/general";
1
+ import { Action } from '../../Action';
2
+ import { requireAddress } from '../../utils/general';
3
3
  import { getAddr } from '../../addresses';
4
- import {EthAddress,uint256} from '../../types';
4
+ import { EthAddress, uint256 } from '../../types';
5
5
 
6
6
  /**
7
7
  * AaveBorrowAction - Borrow tokens from Aave
8
- *
8
+ *
9
9
  * @category Aave
10
10
  */
11
11
  export class AaveBorrowAction extends Action {