@defisaver/sdk 1.3.36 → 1.3.37-semi-continuous-dev

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 (167) hide show
  1. package/README.md +55 -9
  2. package/docs/DEV.md +63 -0
  3. package/esm/src/Action.js +21 -13
  4. package/esm/src/ActionWithL2.js +4 -0
  5. package/esm/src/Recipe.js +5 -1
  6. package/package.json +2 -6
  7. package/src/Action.ts +18 -9
  8. package/src/ActionWithL2.ts +2 -0
  9. package/src/Recipe.ts +4 -1
  10. package/test/Action.js +83 -3
  11. package/test/ActionWithL2.js +65 -19
  12. package/test/Recipe.js +97 -0
  13. package/tsconfig.json +1 -5
  14. package/umd/index.js +24 -13
  15. package/ACTIONS.md +0 -1765
  16. package/DEV.md +0 -43
  17. package/docs/md/.nojekyll +0 -1
  18. package/docs/md/README.md +0 -12
  19. package/docs/md/classes/AaveBorrowAction.md +0 -458
  20. package/docs/md/classes/AaveClaimStkAaveAction.md +0 -455
  21. package/docs/md/classes/AaveCollateralSwitchAction.md +0 -455
  22. package/docs/md/classes/AavePaybackAction.md +0 -458
  23. package/docs/md/classes/AaveSupplyAction.md +0 -458
  24. package/docs/md/classes/AaveV2FlashLoanAction.md +0 -458
  25. package/docs/md/classes/AaveV2FlashLoanPaybackAction.md +0 -454
  26. package/docs/md/classes/AaveV3ATokenPaybackAction.md +0 -644
  27. package/docs/md/classes/AaveV3BorrowAction.md +0 -606
  28. package/docs/md/classes/AaveV3ClaimRewardsAction.md +0 -603
  29. package/docs/md/classes/AaveV3CollateralSwitchAction.md +0 -603
  30. package/docs/md/classes/AaveV3FlashLoanAction.md +0 -604
  31. package/docs/md/classes/AaveV3FlashLoanPaybackAction.md +0 -454
  32. package/docs/md/classes/AaveV3PaybackAction.md +0 -618
  33. package/docs/md/classes/AaveV3RatioCheckAction.md +0 -454
  34. package/docs/md/classes/AaveV3RatioTrigger.md +0 -454
  35. package/docs/md/classes/AaveV3SetEModeAction.md +0 -601
  36. package/docs/md/classes/AaveV3SupplyAction.md +0 -618
  37. package/docs/md/classes/AaveV3SwapBorrowRateModeAction.md +0 -602
  38. package/docs/md/classes/AaveV3WithdrawAction.md +0 -603
  39. package/docs/md/classes/AaveWithdrawAction.md +0 -456
  40. package/docs/md/classes/Action.md +0 -604
  41. package/docs/md/classes/ActionWithL2.md +0 -612
  42. package/docs/md/classes/AutomationV2Unsub.md +0 -452
  43. package/docs/md/classes/BalancerFlashLoanAction.md +0 -456
  44. package/docs/md/classes/BalancerFlashLoanPaybackAction.md +0 -454
  45. package/docs/md/classes/BalancerV2ClaimAction.md +0 -457
  46. package/docs/md/classes/BalancerV2SupplyAction.md +0 -458
  47. package/docs/md/classes/BalancerV2WithdrawAction.md +0 -470
  48. package/docs/md/classes/CBChickenInAction.md +0 -454
  49. package/docs/md/classes/CBChickenOutAction.md +0 -455
  50. package/docs/md/classes/CBCreateAction.md +0 -454
  51. package/docs/md/classes/CBRedeemAction.md +0 -456
  52. package/docs/md/classes/ChainLinkPriceTrigger.md +0 -453
  53. package/docs/md/classes/ChangeProxyOwnerAction.md +0 -453
  54. package/docs/md/classes/CompV3RatioTrigger.md +0 -454
  55. package/docs/md/classes/CompoundBorrowAction.md +0 -455
  56. package/docs/md/classes/CompoundClaimAction.md +0 -456
  57. package/docs/md/classes/CompoundCollateralSwitchAction.md +0 -454
  58. package/docs/md/classes/CompoundGetDebtAction.md +0 -452
  59. package/docs/md/classes/CompoundPaybackAction.md +0 -456
  60. package/docs/md/classes/CompoundRatioTrigger.md +0 -453
  61. package/docs/md/classes/CompoundSupplyAction.md +0 -456
  62. package/docs/md/classes/CompoundV3AllowAction.md +0 -455
  63. package/docs/md/classes/CompoundV3BorrowAction.md +0 -456
  64. package/docs/md/classes/CompoundV3ClaimAction.md +0 -456
  65. package/docs/md/classes/CompoundV3PaybackAction.md +0 -468
  66. package/docs/md/classes/CompoundV3RatioCheckAction.md +0 -456
  67. package/docs/md/classes/CompoundV3SupplyAction.md +0 -468
  68. package/docs/md/classes/CompoundV3TransferAction.md +0 -457
  69. package/docs/md/classes/CompoundV3WithdrawAction.md +0 -457
  70. package/docs/md/classes/CompoundWithdrawAction.md +0 -455
  71. package/docs/md/classes/ConvexClaimAction.md +0 -466
  72. package/docs/md/classes/ConvexDepositAction.md +0 -468
  73. package/docs/md/classes/ConvexWithdrawAction.md +0 -468
  74. package/docs/md/classes/CurveClaimFeesAction.md +0 -452
  75. package/docs/md/classes/CurveDepositAction.md +0 -467
  76. package/docs/md/classes/CurveGaugeDepositAction.md +0 -455
  77. package/docs/md/classes/CurveGaugeWithdrawAction.md +0 -454
  78. package/docs/md/classes/CurveMintCrvAction.md +0 -452
  79. package/docs/md/classes/CurveStethPoolDepositAction.md +0 -456
  80. package/docs/md/classes/CurveStethPoolWithdrawAction.md +0 -457
  81. package/docs/md/classes/CurveSwapAction.md +0 -457
  82. package/docs/md/classes/CurveWithdrawAction.md +0 -468
  83. package/docs/md/classes/DfsWeb3.md +0 -212
  84. package/docs/md/classes/DyDxFlashLoanAction.md +0 -456
  85. package/docs/md/classes/DyDxFlashLoanPaybackAction.md +0 -454
  86. package/docs/md/classes/DyDxWithdrawAction.md +0 -455
  87. package/docs/md/classes/EulerFlashLoanAction.md +0 -456
  88. package/docs/md/classes/EulerFlashLoanPaybackAction.md +0 -454
  89. package/docs/md/classes/GUniDeposit.md +0 -461
  90. package/docs/md/classes/GUniWithdraw.md +0 -458
  91. package/docs/md/classes/GasFeeAction.md +0 -454
  92. package/docs/md/classes/GasFeeActionL2.md +0 -455
  93. package/docs/md/classes/GasPriceTrigger.md +0 -35
  94. package/docs/md/classes/InstPullTokensAction.md +0 -454
  95. package/docs/md/classes/LidoStakeAction.md +0 -455
  96. package/docs/md/classes/LidoUnwrapAction.md +0 -455
  97. package/docs/md/classes/LidoWrapAction.md +0 -456
  98. package/docs/md/classes/LiquityBorrowAction.md +0 -457
  99. package/docs/md/classes/LiquityClaimAction.md +0 -453
  100. package/docs/md/classes/LiquityClaimSPRewardsAction.md +0 -454
  101. package/docs/md/classes/LiquityClaimStakingRewardsAction.md +0 -454
  102. package/docs/md/classes/LiquityCloseAction.md +0 -454
  103. package/docs/md/classes/LiquityEthGainToTroveAction.md +0 -455
  104. package/docs/md/classes/LiquityOpenAction.md +0 -459
  105. package/docs/md/classes/LiquityPaybackAction.md +0 -456
  106. package/docs/md/classes/LiquityRatioTrigger.md +0 -453
  107. package/docs/md/classes/LiquityRedeemAction.md +0 -461
  108. package/docs/md/classes/LiquitySPDepositAction.md +0 -456
  109. package/docs/md/classes/LiquitySPWithdrawAction.md +0 -458
  110. package/docs/md/classes/LiquityStakeAction.md +0 -456
  111. package/docs/md/classes/LiquitySupplyAction.md +0 -456
  112. package/docs/md/classes/LiquityUnstakeAction.md +0 -458
  113. package/docs/md/classes/LiquityWithdrawAction.md +0 -456
  114. package/docs/md/classes/MStableClaimAction.md +0 -456
  115. package/docs/md/classes/MStableDepositAction.md +0 -461
  116. package/docs/md/classes/MStableWithdrawAction.md +0 -461
  117. package/docs/md/classes/MakerClaimAction.md +0 -455
  118. package/docs/md/classes/MakerFlashLoanAction.md +0 -455
  119. package/docs/md/classes/MakerFlashLoanPaybackAction.md +0 -454
  120. package/docs/md/classes/MakerGenerateAction.md +0 -456
  121. package/docs/md/classes/MakerGiveAction.md +0 -456
  122. package/docs/md/classes/MakerMergeAction.md +0 -455
  123. package/docs/md/classes/MakerOpenVaultAction.md +0 -454
  124. package/docs/md/classes/MakerPaybackAction.md +0 -456
  125. package/docs/md/classes/MakerRatioAction.md +0 -453
  126. package/docs/md/classes/MakerRatioCheckAction.md +0 -457
  127. package/docs/md/classes/MakerRatioTrigger.md +0 -453
  128. package/docs/md/classes/MakerSupplyAction.md +0 -457
  129. package/docs/md/classes/MakerWithdrawAction.md +0 -457
  130. package/docs/md/classes/PullTokenAction.md +0 -455
  131. package/docs/md/classes/RariDepositAction.md +0 -458
  132. package/docs/md/classes/RariWithdrawAction.md +0 -459
  133. package/docs/md/classes/Recipe.md +0 -195
  134. package/docs/md/classes/ReflexerGenerateAction.md +0 -455
  135. package/docs/md/classes/ReflexerNativeUniV2SaviourDepositAction.md +0 -455
  136. package/docs/md/classes/ReflexerNativeUniV2SaviourGetReservesAction.md +0 -454
  137. package/docs/md/classes/ReflexerNativeUniV2SaviourWithdrawAction.md +0 -455
  138. package/docs/md/classes/ReflexerOpenSafeAction.md +0 -453
  139. package/docs/md/classes/ReflexerPaybackAction.md +0 -455
  140. package/docs/md/classes/ReflexerRatioTrigger.md +0 -453
  141. package/docs/md/classes/ReflexerSupplyAction.md +0 -456
  142. package/docs/md/classes/ReflexerWithdrawAction.md +0 -456
  143. package/docs/md/classes/SellAction.md +0 -613
  144. package/docs/md/classes/SendTokenAction.md +0 -467
  145. package/docs/md/classes/SendTokenAndUnwrapAction.md +0 -455
  146. package/docs/md/classes/Strategy.md +0 -195
  147. package/docs/md/classes/SubInputsAction.md +0 -454
  148. package/docs/md/classes/SumInputsAction.md +0 -454
  149. package/docs/md/classes/TimestampTrigger.md +0 -451
  150. package/docs/md/classes/ToggleSubAction.md +0 -454
  151. package/docs/md/classes/TokenBalanceAction.md +0 -452
  152. package/docs/md/classes/TrailingStopTrigger.md +0 -453
  153. package/docs/md/classes/TransferNFTAction.md +0 -454
  154. package/docs/md/classes/UniV3CurrentTickTrigger.md +0 -452
  155. package/docs/md/classes/UniswapSupplyAction.md +0 -461
  156. package/docs/md/classes/UniswapV3CollectAction.md +0 -614
  157. package/docs/md/classes/UniswapV3CreatePoolAction.md +0 -611
  158. package/docs/md/classes/UniswapV3MintAction.md +0 -610
  159. package/docs/md/classes/UniswapV3SupplyAction.md +0 -63
  160. package/docs/md/classes/UniswapV3WithdrawAction.md +0 -618
  161. package/docs/md/classes/UniswapWithdrawAction.md +0 -460
  162. package/docs/md/classes/UnwrapEthAction.md +0 -600
  163. package/docs/md/classes/UpdateSubAction.md +0 -454
  164. package/docs/md/classes/WrapEthAction.md +0 -599
  165. package/docs/md/classes/YearnSupplyAction.md +0 -456
  166. package/docs/md/classes/YearnWithdrawAction.md +0 -456
  167. package/docs/md/modules.md +0 -814
package/test/Recipe.js CHANGED
@@ -93,3 +93,100 @@ describe('Recipe', () => {
93
93
  it('encodeForDsProxyCall', () => encodeForDsProxyCall(recipe));
94
94
  })
95
95
  })
96
+
97
+
98
+ describe('Recipe composition', () => {
99
+ const AbiCoder = require('web3-eth-abi');
100
+ const owner = '0x0000000000000000000000000000000000000001';
101
+ const otherOwner = '0x0000000000000000000000000000000000000002';
102
+
103
+ it('encodes ordered action data, IDs and mappings in the recipe tuple', () => {
104
+ const first = new dfs.Action('MockDeposit', owner, ['uint256'], ['7']);
105
+ const second = new dfs.Action('MockSwap', owner, ['uint256', 'address'], ['$1', otherOwner]);
106
+ const recipe = new dfs.Recipe('Mapped recipe', [first]);
107
+ assert.strictEqual(recipe.addAction(second), recipe);
108
+ const zeroWord = '0'.repeat(64);
109
+ // Expected values are independent of the actions' encoding methods.
110
+ const expected = [
111
+ 'Mapped recipe',
112
+ [`0x${'7'.padStart(64, '0')}`, `0x${zeroWord}${'2'.padStart(64, '0')}`],
113
+ [`0x${zeroWord}`, `0x${zeroWord}`],
114
+ ['0xf7012350', '0xe45f86c0'],
115
+ [[0], [1, 0]],
116
+ ];
117
+ const signature = 'executeRecipe((string,bytes[],bytes32[],bytes4[],uint8[][]))';
118
+ const data = AbiCoder.encodeParameter('(string,bytes[],bytes32[],bytes4[],uint8[][])', expected);
119
+ assert.deepEqual(recipe.encodeForDsProxyCall(), [
120
+ dfs.getAddr('RecipeExecutor'),
121
+ AbiCoder.encodeFunctionSignature(signature) + data.slice(2),
122
+ ]);
123
+ });
124
+
125
+ it('sums ETH values exactly above JavaScript safe integer precision', async () => {
126
+ const recipe = new dfs.Recipe('ETH value', [
127
+ new dfs.actions.basic.WrapEthAction('1000000000000000000'),
128
+ new dfs.actions.basic.WrapEthAction('1'),
129
+ new dfs.actions.basic.WrapEthAction('99', false),
130
+ ]);
131
+ assert.equal(await recipe.getEthValue(), '1000000000000000001');
132
+ assert.equal(await new dfs.Recipe('Empty').getEthValue(), '0');
133
+ });
134
+
135
+ it('deduplicates ERC-20 approvals by asset and owner and excludes native ETH', async () => {
136
+ const weth = getAssetInfo('WETH').address;
137
+ const dai = getAssetInfo('DAI').address;
138
+ const recipe = new dfs.Recipe('Approvals', [
139
+ new dfs.actions.basic.PullTokenAction(weth, owner, '1'),
140
+ new dfs.actions.basic.PullTokenAction(weth, owner, '2'),
141
+ new dfs.actions.basic.PullTokenAction(weth, otherOwner, '3'),
142
+ new dfs.actions.basic.PullTokenAction(dai, owner, '4'),
143
+ ]);
144
+ const nativeAction = new dfs.Action('Native', owner, [], []);
145
+ nativeAction.getAssetsToApprove = async () => [{ asset: getAssetInfo('ETH').address, owner }];
146
+ recipe.addAction(nativeAction);
147
+ assert.deepEqual(await recipe.getAssetsToApprove(), [
148
+ { asset: weth, owner, specialApproveLabel: undefined },
149
+ { asset: weth, owner: otherOwner, specialApproveLabel: undefined },
150
+ { asset: dai, owner, specialApproveLabel: undefined },
151
+ ]);
152
+ assert.deepEqual(await new dfs.Recipe('Empty').getAssetsToApprove(), []);
153
+ });
154
+
155
+ it('rejects non-action entries both at construction and when adding an action', () => {
156
+ assert.throws(() => new dfs.Recipe('Invalid', [{}]), TypeError, 'Supplied action does not inherit Action');
157
+ const recipe = new dfs.Recipe('Empty');
158
+ assert.throws(() => recipe.addAction({}), TypeError, 'Supplied action does not inherit Action');
159
+ assert.lengthOf(recipe.actions, 0);
160
+ });
161
+ });
162
+
163
+
164
+ describe('Recipe validation and NFT approvals', () => {
165
+ const owner = '0x0000000000000000000000000000000000000001';
166
+ const collectionA = '0x0000000000000000000000000000000000000002';
167
+ const collectionB = '0x0000000000000000000000000000000000000003';
168
+
169
+ it('keeps different NFT contracts, token IDs and owners while removing exact duplicates', async () => {
170
+ const approvals = [
171
+ { owner, nft: collectionA, tokenId: '1' },
172
+ { owner, nft: collectionA, tokenId: '1' },
173
+ { owner, nft: collectionB, tokenId: '1' },
174
+ { owner, nft: collectionA, tokenId: '2' },
175
+ { owner: collectionB, nft: collectionA, tokenId: '1' },
176
+ ];
177
+ const actions = approvals.map(approval => {
178
+ const action = new dfs.Action('NFT', owner, [], []);
179
+ action.getAssetsToApprove = async () => [approval];
180
+ return action;
181
+ });
182
+ assert.deepEqual(await new dfs.Recipe('NFT approvals', actions).getAssetsToApprove(),
183
+ [approvals[0], ...approvals.slice(2)].map(approval => ({ ...approval, specialApproveLabel: undefined })));
184
+ });
185
+
186
+ it('reports empty recipes clearly for both regular and TxSaver encoding', () => {
187
+ const recipe = new dfs.Recipe('Empty');
188
+ assert.throws(() => recipe.encodeForDsProxyCall(), 'Cannot encode an empty recipe');
189
+ assert.throws(() => recipe.encodeForTxSaverCall({ shouldTakeFeeFromPosition: false }),
190
+ 'Cannot encode an empty recipe');
191
+ });
192
+ });
package/tsconfig.json CHANGED
@@ -71,9 +71,5 @@
71
71
  },
72
72
  "include": [
73
73
  "./src/*",
74
- ],
75
- "typedocOptions": {
76
- "entryPoints": ["./src/index.ts"],
77
- "out": "docs",
78
- }
74
+ ]
79
75
  }
package/umd/index.js CHANGED
@@ -59,9 +59,6 @@ class Action {
59
59
  * @param args
60
60
  */
61
61
  constructor(name, contractAddress, paramTypes, args) {
62
- /**
63
- *
64
- */
65
62
  _classPrivateMethodInitSpec(this, _Action_brand);
66
63
  _defineProperty(this, "contractAddress", void 0);
67
64
  _defineProperty(this, "paramTypes", void 0);
@@ -89,11 +86,11 @@ class Action {
89
86
  */
90
87
  _getArgumentMapping() {
91
88
  return this.mappableArgs.map(arg => {
92
- if (new RegExp(/\$\d+/).test(arg)) {
93
- if (Array.isArray(arg)) throw TypeError('Input can\'t be mapped to arrays (tuples/structs). Specify `mappableArgs` array in constructor.');
94
- // eslint-disable-next-line
95
- return parseInt(arg.substr(1));
89
+ if (Array.isArray(arg) && /\$\d+/.test(arg.toString())) {
90
+ throw TypeError('Input can\'t be mapped to arrays (tuples/structs). Specify `mappableArgs` array in constructor.');
96
91
  }
92
+ var reference = _assertClassBrand(_Action_brand, this, _getReturnValueReference).call(this, arg);
93
+ if (reference !== undefined) return reference;
97
94
  return 0;
98
95
  });
99
96
  }
@@ -139,7 +136,7 @@ class Action {
139
136
  var paramTypeParsed = this._parseParamType(paramType, arg);
140
137
  if (Array.isArray(arg)) return arg.map((_arg, i) => this._replaceWithPlaceholders(_arg, paramTypeParsed[i]));
141
138
  if (typeof paramType === 'string') {
142
- if (new RegExp(/\$\d+/).test(arg)) return _assertClassBrand(_Action_brand, this, _getPlaceholderForType).call(this, paramType);
139
+ if (_assertClassBrand(_Action_brand, this, _getReturnValueReference).call(this, arg) !== undefined) return _assertClassBrand(_Action_brand, this, _getPlaceholderForType).call(this, paramType);
143
140
  if (new RegExp(/&\w+/).test(arg)) return _assertClassBrand(_Action_brand, this, _getPlaceholderForType).call(this, paramType);
144
141
  }
145
142
  return arg;
@@ -243,13 +240,24 @@ class Action {
243
240
  });
244
241
  }
245
242
  }
243
+ function _getReturnValueReference(arg) {
244
+ if (typeof arg !== 'string' || !/\$\d+/.test(arg)) return undefined;
245
+ var index = Number(arg.slice(1));
246
+ if (!/^\$\d+$/.test(arg) || !Number.isSafeInteger(index) || index < 1) {
247
+ throw new Error("Invalid action return reference: ".concat(arg));
248
+ }
249
+ return index;
250
+ }
251
+ /**
252
+ *
253
+ */
246
254
  function _getArgumentMappingWithSlots(subSlots) {
247
255
  return this.mappableArgs.map(arg => {
248
- if (new RegExp(/\$\d+/).test(arg)) {
249
- if (Array.isArray(arg)) throw TypeError('Input can\'t be mapped to arrays (tuples/structs). Specify `mappableArgs` array in constructor.');
250
- // eslint-disable-next-line
251
- return parseInt(arg.substr(1));
256
+ if (Array.isArray(arg) && /\$\d+/.test(arg.toString())) {
257
+ throw TypeError('Input can\'t be mapped to arrays (tuples/structs). Specify `mappableArgs` array in constructor.');
252
258
  }
259
+ var reference = _assertClassBrand(_Action_brand, this, _getReturnValueReference).call(this, arg);
260
+ if (reference !== undefined) return reference;
253
261
 
254
262
  // Handle SubSlots placeholder values in strategies
255
263
  if (new RegExp(/&\w+/).test(arg)) {
@@ -1043,10 +1051,12 @@ class ActionWithL2 extends _Action__WEBPACK_IMPORTED_MODULE_1__.Action {
1043
1051
  }
1044
1052
  numberToBytes2(number) {
1045
1053
  var hexNumber = number.toString(16);
1054
+ if (!/^[0-9a-f]{1,4}$/i.test(hexNumber)) throw new RangeError('Value must fit in an unsigned 2-byte integer');
1046
1055
  return hexNumber.padStart(4, '0');
1047
1056
  }
1048
1057
  numberToBytes1(number) {
1049
1058
  var hexNumber = number.toString(16);
1059
+ if (!/^[0-9a-f]{1,2}$/i.test(hexNumber)) throw new RangeError('Value must fit in an unsigned 1-byte integer');
1050
1060
  return hexNumber.padStart(2, '0');
1051
1061
  }
1052
1062
  numberToBytes32(number) {
@@ -1233,7 +1243,7 @@ class Recipe {
1233
1243
  for (var pairsPerAction of assetOwnerPairs) {
1234
1244
  var _loop = function* _loop(pair) {
1235
1245
  var isNft = !pair.asset;
1236
- if (!uniqueAssetOwnerPairs.find(_pair => _pair.owner === pair.owner && (isNft ? _pair.tokenId === pair.tokenId : _pair.asset === pair.asset))) {
1246
+ if (!uniqueAssetOwnerPairs.find(_pair => _pair.owner === pair.owner && (isNft ? 'nft' in _pair && _pair.nft === pair.nft && _pair.tokenId === pair.tokenId : _pair.asset === pair.asset))) {
1237
1247
  if (isNft) {
1238
1248
  uniqueAssetOwnerPairs.push({
1239
1249
  owner: pair.owner,
@@ -1295,6 +1305,7 @@ class Recipe {
1295
1305
  }
1296
1306
  }
1297
1307
  function _encodeForCall() {
1308
+ if (this.actions.length === 0) throw new Error('Cannot encode an empty recipe');
1298
1309
  var encoded = this.actions.map(action => action.encodeForRecipe());
1299
1310
  var transposed = encoded[0].map((_, colIndex) => encoded.map(row => row[colIndex]));
1300
1311
  var taskStruct = [this.name, ...transposed];