@defisaver/sdk 1.3.36 → 1.3.37
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/README.md +55 -9
- package/docs/DEV.md +63 -0
- package/esm/src/Action.js +21 -13
- package/esm/src/ActionWithL2.js +4 -0
- package/esm/src/Recipe.js +5 -1
- package/esm/src/addresses.js +12 -12
- package/package.json +2 -6
- package/src/Action.ts +18 -9
- package/src/ActionWithL2.ts +2 -0
- package/src/Recipe.ts +4 -1
- package/src/addresses.ts +12 -12
- package/test/Action.js +83 -3
- package/test/ActionWithL2.js +65 -19
- package/test/Recipe.js +97 -0
- package/tsconfig.json +1 -5
- package/umd/index.js +36 -25
- package/ACTIONS.md +0 -1765
- package/DEV.md +0 -43
- package/docs/md/.nojekyll +0 -1
- package/docs/md/README.md +0 -12
- package/docs/md/classes/AaveBorrowAction.md +0 -458
- package/docs/md/classes/AaveClaimStkAaveAction.md +0 -455
- package/docs/md/classes/AaveCollateralSwitchAction.md +0 -455
- package/docs/md/classes/AavePaybackAction.md +0 -458
- package/docs/md/classes/AaveSupplyAction.md +0 -458
- package/docs/md/classes/AaveV2FlashLoanAction.md +0 -458
- package/docs/md/classes/AaveV2FlashLoanPaybackAction.md +0 -454
- package/docs/md/classes/AaveV3ATokenPaybackAction.md +0 -644
- package/docs/md/classes/AaveV3BorrowAction.md +0 -606
- package/docs/md/classes/AaveV3ClaimRewardsAction.md +0 -603
- package/docs/md/classes/AaveV3CollateralSwitchAction.md +0 -603
- package/docs/md/classes/AaveV3FlashLoanAction.md +0 -604
- package/docs/md/classes/AaveV3FlashLoanPaybackAction.md +0 -454
- package/docs/md/classes/AaveV3PaybackAction.md +0 -618
- package/docs/md/classes/AaveV3RatioCheckAction.md +0 -454
- package/docs/md/classes/AaveV3RatioTrigger.md +0 -454
- package/docs/md/classes/AaveV3SetEModeAction.md +0 -601
- package/docs/md/classes/AaveV3SupplyAction.md +0 -618
- package/docs/md/classes/AaveV3SwapBorrowRateModeAction.md +0 -602
- package/docs/md/classes/AaveV3WithdrawAction.md +0 -603
- package/docs/md/classes/AaveWithdrawAction.md +0 -456
- package/docs/md/classes/Action.md +0 -604
- package/docs/md/classes/ActionWithL2.md +0 -612
- package/docs/md/classes/AutomationV2Unsub.md +0 -452
- package/docs/md/classes/BalancerFlashLoanAction.md +0 -456
- package/docs/md/classes/BalancerFlashLoanPaybackAction.md +0 -454
- package/docs/md/classes/BalancerV2ClaimAction.md +0 -457
- package/docs/md/classes/BalancerV2SupplyAction.md +0 -458
- package/docs/md/classes/BalancerV2WithdrawAction.md +0 -470
- package/docs/md/classes/CBChickenInAction.md +0 -454
- package/docs/md/classes/CBChickenOutAction.md +0 -455
- package/docs/md/classes/CBCreateAction.md +0 -454
- package/docs/md/classes/CBRedeemAction.md +0 -456
- package/docs/md/classes/ChainLinkPriceTrigger.md +0 -453
- package/docs/md/classes/ChangeProxyOwnerAction.md +0 -453
- package/docs/md/classes/CompV3RatioTrigger.md +0 -454
- package/docs/md/classes/CompoundBorrowAction.md +0 -455
- package/docs/md/classes/CompoundClaimAction.md +0 -456
- package/docs/md/classes/CompoundCollateralSwitchAction.md +0 -454
- package/docs/md/classes/CompoundGetDebtAction.md +0 -452
- package/docs/md/classes/CompoundPaybackAction.md +0 -456
- package/docs/md/classes/CompoundRatioTrigger.md +0 -453
- package/docs/md/classes/CompoundSupplyAction.md +0 -456
- package/docs/md/classes/CompoundV3AllowAction.md +0 -455
- package/docs/md/classes/CompoundV3BorrowAction.md +0 -456
- package/docs/md/classes/CompoundV3ClaimAction.md +0 -456
- package/docs/md/classes/CompoundV3PaybackAction.md +0 -468
- package/docs/md/classes/CompoundV3RatioCheckAction.md +0 -456
- package/docs/md/classes/CompoundV3SupplyAction.md +0 -468
- package/docs/md/classes/CompoundV3TransferAction.md +0 -457
- package/docs/md/classes/CompoundV3WithdrawAction.md +0 -457
- package/docs/md/classes/CompoundWithdrawAction.md +0 -455
- package/docs/md/classes/ConvexClaimAction.md +0 -466
- package/docs/md/classes/ConvexDepositAction.md +0 -468
- package/docs/md/classes/ConvexWithdrawAction.md +0 -468
- package/docs/md/classes/CurveClaimFeesAction.md +0 -452
- package/docs/md/classes/CurveDepositAction.md +0 -467
- package/docs/md/classes/CurveGaugeDepositAction.md +0 -455
- package/docs/md/classes/CurveGaugeWithdrawAction.md +0 -454
- package/docs/md/classes/CurveMintCrvAction.md +0 -452
- package/docs/md/classes/CurveStethPoolDepositAction.md +0 -456
- package/docs/md/classes/CurveStethPoolWithdrawAction.md +0 -457
- package/docs/md/classes/CurveSwapAction.md +0 -457
- package/docs/md/classes/CurveWithdrawAction.md +0 -468
- package/docs/md/classes/DfsWeb3.md +0 -212
- package/docs/md/classes/DyDxFlashLoanAction.md +0 -456
- package/docs/md/classes/DyDxFlashLoanPaybackAction.md +0 -454
- package/docs/md/classes/DyDxWithdrawAction.md +0 -455
- package/docs/md/classes/EulerFlashLoanAction.md +0 -456
- package/docs/md/classes/EulerFlashLoanPaybackAction.md +0 -454
- package/docs/md/classes/GUniDeposit.md +0 -461
- package/docs/md/classes/GUniWithdraw.md +0 -458
- package/docs/md/classes/GasFeeAction.md +0 -454
- package/docs/md/classes/GasFeeActionL2.md +0 -455
- package/docs/md/classes/GasPriceTrigger.md +0 -35
- package/docs/md/classes/InstPullTokensAction.md +0 -454
- package/docs/md/classes/LidoStakeAction.md +0 -455
- package/docs/md/classes/LidoUnwrapAction.md +0 -455
- package/docs/md/classes/LidoWrapAction.md +0 -456
- package/docs/md/classes/LiquityBorrowAction.md +0 -457
- package/docs/md/classes/LiquityClaimAction.md +0 -453
- package/docs/md/classes/LiquityClaimSPRewardsAction.md +0 -454
- package/docs/md/classes/LiquityClaimStakingRewardsAction.md +0 -454
- package/docs/md/classes/LiquityCloseAction.md +0 -454
- package/docs/md/classes/LiquityEthGainToTroveAction.md +0 -455
- package/docs/md/classes/LiquityOpenAction.md +0 -459
- package/docs/md/classes/LiquityPaybackAction.md +0 -456
- package/docs/md/classes/LiquityRatioTrigger.md +0 -453
- package/docs/md/classes/LiquityRedeemAction.md +0 -461
- package/docs/md/classes/LiquitySPDepositAction.md +0 -456
- package/docs/md/classes/LiquitySPWithdrawAction.md +0 -458
- package/docs/md/classes/LiquityStakeAction.md +0 -456
- package/docs/md/classes/LiquitySupplyAction.md +0 -456
- package/docs/md/classes/LiquityUnstakeAction.md +0 -458
- package/docs/md/classes/LiquityWithdrawAction.md +0 -456
- package/docs/md/classes/MStableClaimAction.md +0 -456
- package/docs/md/classes/MStableDepositAction.md +0 -461
- package/docs/md/classes/MStableWithdrawAction.md +0 -461
- package/docs/md/classes/MakerClaimAction.md +0 -455
- package/docs/md/classes/MakerFlashLoanAction.md +0 -455
- package/docs/md/classes/MakerFlashLoanPaybackAction.md +0 -454
- package/docs/md/classes/MakerGenerateAction.md +0 -456
- package/docs/md/classes/MakerGiveAction.md +0 -456
- package/docs/md/classes/MakerMergeAction.md +0 -455
- package/docs/md/classes/MakerOpenVaultAction.md +0 -454
- package/docs/md/classes/MakerPaybackAction.md +0 -456
- package/docs/md/classes/MakerRatioAction.md +0 -453
- package/docs/md/classes/MakerRatioCheckAction.md +0 -457
- package/docs/md/classes/MakerRatioTrigger.md +0 -453
- package/docs/md/classes/MakerSupplyAction.md +0 -457
- package/docs/md/classes/MakerWithdrawAction.md +0 -457
- package/docs/md/classes/PullTokenAction.md +0 -455
- package/docs/md/classes/RariDepositAction.md +0 -458
- package/docs/md/classes/RariWithdrawAction.md +0 -459
- package/docs/md/classes/Recipe.md +0 -195
- package/docs/md/classes/ReflexerGenerateAction.md +0 -455
- package/docs/md/classes/ReflexerNativeUniV2SaviourDepositAction.md +0 -455
- package/docs/md/classes/ReflexerNativeUniV2SaviourGetReservesAction.md +0 -454
- package/docs/md/classes/ReflexerNativeUniV2SaviourWithdrawAction.md +0 -455
- package/docs/md/classes/ReflexerOpenSafeAction.md +0 -453
- package/docs/md/classes/ReflexerPaybackAction.md +0 -455
- package/docs/md/classes/ReflexerRatioTrigger.md +0 -453
- package/docs/md/classes/ReflexerSupplyAction.md +0 -456
- package/docs/md/classes/ReflexerWithdrawAction.md +0 -456
- package/docs/md/classes/SellAction.md +0 -613
- package/docs/md/classes/SendTokenAction.md +0 -467
- package/docs/md/classes/SendTokenAndUnwrapAction.md +0 -455
- package/docs/md/classes/Strategy.md +0 -195
- package/docs/md/classes/SubInputsAction.md +0 -454
- package/docs/md/classes/SumInputsAction.md +0 -454
- package/docs/md/classes/TimestampTrigger.md +0 -451
- package/docs/md/classes/ToggleSubAction.md +0 -454
- package/docs/md/classes/TokenBalanceAction.md +0 -452
- package/docs/md/classes/TrailingStopTrigger.md +0 -453
- package/docs/md/classes/TransferNFTAction.md +0 -454
- package/docs/md/classes/UniV3CurrentTickTrigger.md +0 -452
- package/docs/md/classes/UniswapSupplyAction.md +0 -461
- package/docs/md/classes/UniswapV3CollectAction.md +0 -614
- package/docs/md/classes/UniswapV3CreatePoolAction.md +0 -611
- package/docs/md/classes/UniswapV3MintAction.md +0 -610
- package/docs/md/classes/UniswapV3SupplyAction.md +0 -63
- package/docs/md/classes/UniswapV3WithdrawAction.md +0 -618
- package/docs/md/classes/UniswapWithdrawAction.md +0 -460
- package/docs/md/classes/UnwrapEthAction.md +0 -600
- package/docs/md/classes/UpdateSubAction.md +0 -454
- package/docs/md/classes/WrapEthAction.md +0 -599
- package/docs/md/classes/YearnSupplyAction.md +0 -456
- package/docs/md/classes/YearnWithdrawAction.md +0 -456
- package/docs/md/modules.md +0 -814
package/test/ActionWithL2.js
CHANGED
|
@@ -1,27 +1,73 @@
|
|
|
1
1
|
const dfs = require('../src');
|
|
2
|
-
const
|
|
3
|
-
const {assert} = require('chai');
|
|
2
|
+
const AbiCoder = require('web3-eth-abi');
|
|
3
|
+
const { assert } = require('chai');
|
|
4
4
|
|
|
5
5
|
const MAXUINT = '115792089237316195423570985008687907853269984665640564039457584007913129639935';
|
|
6
|
-
const
|
|
6
|
+
const target = '0x0000000000000000000000000000000000000001';
|
|
7
|
+
const recipient = '0x0000000000000000000000000000000000000002';
|
|
8
|
+
|
|
7
9
|
describe('ActionWithL2', () => {
|
|
10
|
+
it('packs integer boundaries, addresses and booleans to their specified widths', () => {
|
|
11
|
+
const action = new dfs.ActionWithL2('MockSwap', target, [], []);
|
|
12
|
+
for (const [value, expected] of [[0, '00'], [1, '01'], [255, 'ff']]) {
|
|
13
|
+
assert.equal(action.numberToBytes1(value), expected);
|
|
14
|
+
}
|
|
15
|
+
for (const [value, expected] of [[0, '0000'], [1, '0001'], [65535, 'ffff']]) {
|
|
16
|
+
assert.equal(action.numberToBytes2(value), expected);
|
|
17
|
+
}
|
|
18
|
+
assert.equal(action.numberToBytes32('0'), '0'.repeat(64));
|
|
19
|
+
assert.equal(action.numberToBytes32('1'), '1'.padStart(64, '0'));
|
|
20
|
+
assert.equal(action.numberToBytes32(MAXUINT), 'f'.repeat(64));
|
|
21
|
+
assert.equal(action.addressToBytes20(recipient), '2'.padStart(40, '0'));
|
|
22
|
+
assert.equal(action.boolToBytes1(false), '00');
|
|
23
|
+
assert.equal(action.boolToBytes1(true), '01');
|
|
24
|
+
});
|
|
8
25
|
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
})
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
});
|
|
26
|
+
it('falls back to standard ABI encoding when packed encoding is not overridden', () => {
|
|
27
|
+
const action = new dfs.ActionWithL2('MockSwap', target, ['uint256'], ['5']);
|
|
28
|
+
const data = action.encodeForL2DsProxyCall();
|
|
29
|
+
assert.equal(data.slice(0, 10), '0x389f87ff');
|
|
30
|
+
assert.equal(AbiCoder.decodeParameter('bytes', `0x${data.slice(10)}`),
|
|
31
|
+
`0x${'5'.padStart(64, '0')}`);
|
|
32
|
+
assert.equal(action.encodeForL2Recipe(), `0x${data.slice(10)}`);
|
|
17
33
|
});
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
it('
|
|
21
|
-
action = new dfs.actions.aaveV3.AaveV3WithdrawAction(
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
34
|
+
|
|
35
|
+
for (const useDefaultMarket of [true, false]) {
|
|
36
|
+
it(`encodes Aave withdrawal with ${useDefaultMarket ? 'default' : 'explicit'} market`, () => {
|
|
37
|
+
const action = new dfs.actions.aaveV3.AaveV3WithdrawAction(
|
|
38
|
+
useDefaultMarket, target, MAXUINT, recipient, 9,
|
|
39
|
+
);
|
|
40
|
+
// uint16 asset ID, bool default market, uint256 amount, address recipient,
|
|
41
|
+
// followed by the market address only when not using the default.
|
|
42
|
+
const payload = `0009${useDefaultMarket ? '01' : '00'}${'f'.repeat(64)}${recipient.slice(2)}${useDefaultMarket ? '' : target.slice(2)}`;
|
|
43
|
+
assert.equal(action.encodeForL2DsProxyCall(), `0x2895f3aa${payload}`);
|
|
44
|
+
assert.equal(action.encodeForL2Recipe(), `0x${payload}`);
|
|
45
|
+
|
|
46
|
+
const previous = { ...dfs.CONFIG };
|
|
47
|
+
try {
|
|
48
|
+
dfs.configure({ chainId: 10, testingMode: false });
|
|
49
|
+
assert.deepEqual(action.encodeForDsProxyCall(), [action.contractAddress, `0x2895f3aa${payload}`]);
|
|
50
|
+
} finally {
|
|
51
|
+
dfs.configure(previous);
|
|
52
|
+
}
|
|
25
53
|
});
|
|
54
|
+
}
|
|
55
|
+
});
|
|
56
|
+
|
|
57
|
+
|
|
58
|
+
describe('ActionWithL2 integer validation', () => {
|
|
59
|
+
const action = new dfs.ActionWithL2('MockSwap', target, [], []);
|
|
60
|
+
|
|
61
|
+
for (const [method, overflow] of [['numberToBytes1', 256], ['numberToBytes2', 65536]]) {
|
|
62
|
+
it(`${method} rejects overflow, negative, fractional and non-finite values`, () => {
|
|
63
|
+
for (const value of [overflow, -1, 1.5, NaN, Infinity]) {
|
|
64
|
+
assert.throws(() => action[method](value), RangeError, 'Value must fit');
|
|
65
|
+
}
|
|
66
|
+
});
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
it('preserves hex text accepted by existing JavaScript callers', () => {
|
|
70
|
+
assert.equal(action.numberToBytes1('10'), '10');
|
|
71
|
+
assert.equal(action.numberToBytes2('10'), '0010');
|
|
26
72
|
});
|
|
27
|
-
})
|
|
73
|
+
});
|
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
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 (
|
|
93
|
-
|
|
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 (
|
|
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 (
|
|
249
|
-
|
|
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];
|
|
@@ -1327,8 +1338,8 @@ var actionAddresses = {
|
|
|
1327
1338
|
TokenBalance: '0xa92B177950F1460119940436515FD857C24494BC',
|
|
1328
1339
|
AutomationV2Unsub: '0xe35Fb12fE9796847751076aCf5ee7d124108612C',
|
|
1329
1340
|
SendTokenAndUnwrap: '0x4155537e6933E59a62deb68f6ad93d237d07242a',
|
|
1330
|
-
ToggleSub: '
|
|
1331
|
-
UpdateSub: '
|
|
1341
|
+
ToggleSub: '0xf247a8525E7486884E7227EB9a161507F0FF46A6',
|
|
1342
|
+
UpdateSub: '0x919c472bFA4B50FcACF9849501344aFDde2E4675',
|
|
1332
1343
|
TransferNFT: '0x861e893E1796F81248e75F06C0b09Abdc8fe2f6F',
|
|
1333
1344
|
CreateSub: '0xEB13C96257667cF0A037305A46092bf7C70A61e1',
|
|
1334
1345
|
ApproveToken: '0xA4161cED7A29F0a3424e464a4a2dBf75888c5BF9',
|
|
@@ -1670,8 +1681,8 @@ var actionAddresses = {
|
|
|
1670
1681
|
SubInputs: '0x60d00020f12dd202eAfDba84e8F69E165a84c64D',
|
|
1671
1682
|
ApproveToken: '0x842a81d2cfe26d401CD63Cc14e9DEf275c197C1a',
|
|
1672
1683
|
SendTokenAndUnwrap: '0xd4f69250cb4d1f083Dd372FEace391A16ABbfBDc',
|
|
1673
|
-
ToggleSub: '
|
|
1674
|
-
UpdateSub: '
|
|
1684
|
+
ToggleSub: '0xA4Eaad8Fe80d1E47f2b95CED2bcFb648d5929735',
|
|
1685
|
+
UpdateSub: '0xe2c7D66b40e00Dd14844Db8d02142f23D4Da7071',
|
|
1675
1686
|
CreateSub: '0x2daED8030BFC87B3d27c02E2f044B9CF4841Ff3e',
|
|
1676
1687
|
TokenBalance: '0xC6FF5b01f7c7b35b6e093fF70D2332B361C5Be5A',
|
|
1677
1688
|
TokenizedVaultAdapter: '0xdf31669FEd440f5BfF658ca0bBF0D22B8abdeb73',
|
|
@@ -1733,14 +1744,14 @@ var actionAddresses = {
|
|
|
1733
1744
|
SubInputs: '0x8ec14f9568e1d7cf73b68df899808abd7fe6fc8d',
|
|
1734
1745
|
SendTokenAndUnwrap: '0x009C5B1c7C844Bd662Da3991295b1B3Bd71a430c',
|
|
1735
1746
|
ApproveToken: '0x01058999F5Ac434EF48DFB5Cd942c57A7661787B',
|
|
1736
|
-
ToggleSub: '
|
|
1747
|
+
ToggleSub: '0x75469d8f96368F87718162e528104B59550CD71E',
|
|
1737
1748
|
CreateSub: '0xbFD17a0a844b75976585a382a5BcCaFC9EAd731f',
|
|
1738
1749
|
TokenBalance: '0x483B903E702F60698Dd8124558C6199922737f1F',
|
|
1739
1750
|
TokenizedVaultAdapter: '0xD05C512bDFf6D3eAc5328807B3bC075F35271167',
|
|
1740
1751
|
ChangeProxyOwner: '0xacf5bAD9543A98EcAcC620cF6CB989Ec88f1650D',
|
|
1741
1752
|
PermitToken: '0x2E5E7a691092C158bb8341b936eF24FCcA6c0e00',
|
|
1742
1753
|
HandleAuth: '0xbfcab1339e1a56a0a836cbca6457eaf71f148fcb',
|
|
1743
|
-
UpdateSub: '
|
|
1754
|
+
UpdateSub: '0x404c3EE602fb4b2D3E36E371bEA36a27B2177107',
|
|
1744
1755
|
TransferNFT: '0xf73b14cf4bc10509446fc4111407a721f8a81f7d',
|
|
1745
1756
|
MerklClaim: '0xdab7b1865efa8d1f8fe1602dea9285b4a599c45c',
|
|
1746
1757
|
// aave v3
|
|
@@ -1839,9 +1850,9 @@ var actionAddresses = {
|
|
|
1839
1850
|
ChangeProxyOwner: '0x7b55d25BfF49Fd62563823570f47E9a35AA39541',
|
|
1840
1851
|
PermitToken: '0x57c8ae94a5A11dA33e0518054102488b604628D0',
|
|
1841
1852
|
HandleAuth: '0x18a90e6db79199ace00140631ef931e0bd97837c',
|
|
1842
|
-
ToggleSub: '
|
|
1853
|
+
ToggleSub: '0x8879fF7E7B08cdE2e634F7Cd90219e66FB64F01D',
|
|
1843
1854
|
CreateSub: '0xeE739937085A716477BCB5b01b0f74e1BE046645',
|
|
1844
|
-
UpdateSub: '
|
|
1855
|
+
UpdateSub: '0xB3598798599d3A22EA667e5557C53c139653c673',
|
|
1845
1856
|
MerklClaim: '0xa2c6cd875c52bf5c27516fae3b6ba9241790908a',
|
|
1846
1857
|
TransferNFT: '0xe49c70c673c3ef9019fe9c875ed5ed3dc02f5613',
|
|
1847
1858
|
GasFeeTakerL2: '0xAEe02caf404332c40Fd7FF8d5c25F91f7c1641d0',
|
|
@@ -2002,7 +2013,7 @@ var actionAddresses = {
|
|
|
2002
2013
|
};
|
|
2003
2014
|
var otherAddresses = {
|
|
2004
2015
|
[_config__WEBPACK_IMPORTED_MODULE_0__.NETWORKS.ethereum.chainId]: {
|
|
2005
|
-
RecipeExecutor: '
|
|
2016
|
+
RecipeExecutor: '0x6e7dEde13E011Eee74E0c731A06c158377fc1Cae',
|
|
2006
2017
|
DFSRegistry: '0x287778F121F134C66212FB16c9b53eC991D32f5b',
|
|
2007
2018
|
DFSProxyRegistry: '0x0cCB1F91beb8590949880D2a61C26C11d6280319',
|
|
2008
2019
|
ProxyRegistry: '0x4678f0a6958e4D2Bc4F1BAF7Bc52E8F3564f3fE4',
|
|
@@ -2022,7 +2033,7 @@ var otherAddresses = {
|
|
|
2022
2033
|
Empty: '0x0000000000000000000000000000000000000000'
|
|
2023
2034
|
},
|
|
2024
2035
|
[_config__WEBPACK_IMPORTED_MODULE_0__.NETWORKS.optimism.chainId]: {
|
|
2025
|
-
RecipeExecutor: '
|
|
2036
|
+
RecipeExecutor: '0x3296C0f3Ff67B00306e5Ce251CDfA1E0160F5742',
|
|
2026
2037
|
DFSRegistry: '0xAf707Ee480204Ed6e2640B53cE86F680D28Afcbd',
|
|
2027
2038
|
ProxyRegistry: '0x283Cc5C26e53D66ed2Ea252D986F094B37E6e895',
|
|
2028
2039
|
SFProxyEntryPoint: '0x06299D4A07E8C6D7C1aEc14Ab2F46DF05Dd9588E',
|
|
@@ -2033,7 +2044,7 @@ var otherAddresses = {
|
|
|
2033
2044
|
UniswapV3PositionManager: '0xC36442b4a4522E871399CD717aBDD847Ab11FE88'
|
|
2034
2045
|
},
|
|
2035
2046
|
[_config__WEBPACK_IMPORTED_MODULE_0__.NETWORKS.arbitrum.chainId]: {
|
|
2036
|
-
RecipeExecutor: '
|
|
2047
|
+
RecipeExecutor: '0x1674Df46e92A393d6B29139BF8C2d2885F40F7B2',
|
|
2037
2048
|
DFSRegistry: '0xBF1CaC12DB60819Bfa71A328282ecbc1D40443aA',
|
|
2038
2049
|
ProxyRegistry: '0x283Cc5C26e53D66ed2Ea252D986F094B37E6e895',
|
|
2039
2050
|
SFProxyEntryPoint: '0x15D776C062bF292f8F70A81533E49adC7C06Cb69',
|
|
@@ -2044,7 +2055,7 @@ var otherAddresses = {
|
|
|
2044
2055
|
UniswapV3PositionManager: '0xC36442b4a4522E871399CD717aBDD847Ab11FE88'
|
|
2045
2056
|
},
|
|
2046
2057
|
[_config__WEBPACK_IMPORTED_MODULE_0__.NETWORKS.base.chainId]: {
|
|
2047
|
-
RecipeExecutor: '
|
|
2058
|
+
RecipeExecutor: '0xB81865b724eF6DAc41DFf125E5445701924ea19D',
|
|
2048
2059
|
DFSRegistry: '0x347FB634271F666353F23A3362f3935D96F97476',
|
|
2049
2060
|
ProxyRegistry: '0x425fA97285965E01Cc5F951B62A51F6CDEA5cc0d',
|
|
2050
2061
|
SFProxyEntryPoint: '0xab6e5cde983fF98Cdb0F61f5F99cb58D40D0c837',
|