@boostxyz/sdk 0.0.0-alpha.11 → 0.0.0-alpha.13
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/dist/Actions/Action.cjs +1 -1
- package/dist/Actions/Action.js +1 -1
- package/dist/Actions/ContractAction.d.ts +2 -2
- package/dist/Actions/ContractAction.d.ts.map +1 -1
- package/dist/Actions/ERC721MintAction.d.ts +2 -2
- package/dist/Actions/ERC721MintAction.d.ts.map +1 -1
- package/dist/Actions/EventAction.cjs +1 -1
- package/dist/Actions/EventAction.cjs.map +1 -1
- package/dist/Actions/EventAction.d.ts +117 -33
- package/dist/Actions/EventAction.d.ts.map +1 -1
- package/dist/Actions/EventAction.js +309 -121
- package/dist/Actions/EventAction.js.map +1 -1
- package/dist/AllowLists/AllowList.cjs +1 -1
- package/dist/AllowLists/AllowList.js +2 -2
- package/dist/AllowLists/SimpleAllowList.cjs +1 -1
- package/dist/AllowLists/SimpleAllowList.cjs.map +1 -1
- package/dist/AllowLists/SimpleAllowList.d.ts +2 -2
- package/dist/AllowLists/SimpleAllowList.d.ts.map +1 -1
- package/dist/AllowLists/SimpleAllowList.js +23 -19
- package/dist/AllowLists/SimpleAllowList.js.map +1 -1
- package/dist/AllowLists/SimpleDenyList.cjs +1 -1
- package/dist/AllowLists/SimpleDenyList.d.ts +2 -2
- package/dist/AllowLists/SimpleDenyList.d.ts.map +1 -1
- package/dist/AllowLists/SimpleDenyList.js +6 -5
- package/dist/AllowLists/SimpleDenyList.js.map +1 -1
- package/dist/Auth/PassthroughAuth.cjs +1 -1
- package/dist/Auth/PassthroughAuth.js +1 -1
- package/dist/BoostCore.cjs +2 -2
- package/dist/BoostCore.cjs.map +1 -1
- package/dist/BoostCore.d.ts +27 -5
- package/dist/BoostCore.d.ts.map +1 -1
- package/dist/BoostCore.js +438 -347
- package/dist/BoostCore.js.map +1 -1
- package/dist/BoostRegistry.cjs +1 -1
- package/dist/BoostRegistry.cjs.map +1 -1
- package/dist/BoostRegistry.d.ts +26 -5
- package/dist/BoostRegistry.d.ts.map +1 -1
- package/dist/BoostRegistry.js +125 -64
- package/dist/BoostRegistry.js.map +1 -1
- package/dist/Budgets/Budget.cjs +1 -1
- package/dist/Budgets/Budget.js +1 -1
- package/dist/Budgets/ManagedBudget.cjs +1 -1
- package/dist/Budgets/ManagedBudget.cjs.map +1 -1
- package/dist/Budgets/ManagedBudget.d.ts +2 -2
- package/dist/Budgets/ManagedBudget.d.ts.map +1 -1
- package/dist/Budgets/ManagedBudget.js +41 -37
- package/dist/Budgets/ManagedBudget.js.map +1 -1
- package/dist/Budgets/SimpleBudget.d.ts +2 -2
- package/dist/Budgets/SimpleBudget.d.ts.map +1 -1
- package/dist/Budgets/VestingBudget.d.ts +2 -2
- package/dist/Budgets/VestingBudget.d.ts.map +1 -1
- package/dist/Deployable/DeployableTarget.cjs +1 -1
- package/dist/Deployable/DeployableTarget.cjs.map +1 -1
- package/dist/Deployable/DeployableTarget.d.ts +6 -6
- package/dist/Deployable/DeployableTarget.d.ts.map +1 -1
- package/dist/Deployable/DeployableTarget.js +22 -17
- package/dist/Deployable/DeployableTarget.js.map +1 -1
- package/dist/Incentives/AllowListIncentive.cjs +1 -1
- package/dist/Incentives/AllowListIncentive.cjs.map +1 -1
- package/dist/Incentives/AllowListIncentive.d.ts +2 -2
- package/dist/Incentives/AllowListIncentive.d.ts.map +1 -1
- package/dist/Incentives/AllowListIncentive.js +17 -13
- package/dist/Incentives/AllowListIncentive.js.map +1 -1
- package/dist/Incentives/CGDAIncentive.cjs +1 -1
- package/dist/Incentives/CGDAIncentive.cjs.map +1 -1
- package/dist/Incentives/CGDAIncentive.d.ts +14 -2
- package/dist/Incentives/CGDAIncentive.d.ts.map +1 -1
- package/dist/Incentives/CGDAIncentive.js +27 -23
- package/dist/Incentives/CGDAIncentive.js.map +1 -1
- package/dist/Incentives/ERC1155Incentive.d.ts +2 -2
- package/dist/Incentives/ERC1155Incentive.d.ts.map +1 -1
- package/dist/Incentives/ERC20Incentive.cjs +1 -1
- package/dist/Incentives/ERC20Incentive.cjs.map +1 -1
- package/dist/Incentives/ERC20Incentive.d.ts +2 -2
- package/dist/Incentives/ERC20Incentive.d.ts.map +1 -1
- package/dist/Incentives/ERC20Incentive.js +17 -13
- package/dist/Incentives/ERC20Incentive.js.map +1 -1
- package/dist/Incentives/ERC20VariableIncentive.d.ts +2 -2
- package/dist/Incentives/ERC20VariableIncentive.d.ts.map +1 -1
- package/dist/Incentives/Incentive.cjs +1 -1
- package/dist/Incentives/Incentive.cjs.map +1 -1
- package/dist/Incentives/Incentive.js +34 -30
- package/dist/Incentives/Incentive.js.map +1 -1
- package/dist/Incentives/PointsIncentive.cjs +1 -1
- package/dist/Incentives/PointsIncentive.cjs.map +1 -1
- package/dist/Incentives/PointsIncentive.d.ts +2 -2
- package/dist/Incentives/PointsIncentive.d.ts.map +1 -1
- package/dist/Incentives/PointsIncentive.js +13 -9
- package/dist/Incentives/PointsIncentive.js.map +1 -1
- package/dist/{SimpleDenyList-4PtOPXTc.js → SimpleDenyList-C21O9Yfi.js} +23 -19
- package/dist/SimpleDenyList-C21O9Yfi.js.map +1 -0
- package/dist/SimpleDenyList-DeJRKD2D.cjs +2 -0
- package/dist/{SimpleDenyList-4PtOPXTc.js.map → SimpleDenyList-DeJRKD2D.cjs.map} +1 -1
- package/dist/Validators/SignerValidator.cjs +1 -1
- package/dist/Validators/SignerValidator.cjs.map +1 -1
- package/dist/Validators/SignerValidator.d.ts +2 -2
- package/dist/Validators/SignerValidator.d.ts.map +1 -1
- package/dist/Validators/SignerValidator.js +18 -14
- package/dist/Validators/SignerValidator.js.map +1 -1
- package/dist/Validators/Validator.cjs +1 -1
- package/dist/Validators/Validator.js +1 -1
- package/dist/deployments-BvFcK_eR.js +40 -0
- package/dist/deployments-BvFcK_eR.js.map +1 -0
- package/dist/deployments-Ho4PnGCS.cjs +2 -0
- package/dist/deployments-Ho4PnGCS.cjs.map +1 -0
- package/dist/deployments.json +38 -0
- package/dist/errors.cjs +1 -1
- package/dist/errors.cjs.map +1 -1
- package/dist/errors.d.ts +122 -20
- package/dist/errors.d.ts.map +1 -1
- package/dist/errors.js +98 -28
- package/dist/errors.js.map +1 -1
- package/dist/{generated-BDeDiaCK.js → generated-LpgSHrH0.js} +150 -110
- package/dist/generated-LpgSHrH0.js.map +1 -0
- package/dist/generated-tq_HLZJ0.cjs +3 -0
- package/dist/generated-tq_HLZJ0.cjs.map +1 -0
- package/dist/index.cjs +1 -1
- package/dist/index.js +115 -108
- package/dist/utils.cjs +1 -1
- package/dist/utils.cjs.map +1 -1
- package/dist/utils.d.ts +25 -11
- package/dist/utils.d.ts.map +1 -1
- package/dist/utils.js +38 -23
- package/dist/utils.js.map +1 -1
- package/package.json +10 -6
- package/src/Actions/Action.test.ts +8 -4
- package/src/Actions/ContractAction.ts +5 -3
- package/src/Actions/ERC721MintAction.ts +5 -3
- package/src/Actions/EventAction.test.ts +528 -100
- package/src/Actions/EventAction.ts +302 -60
- package/src/AllowLists/AllowList.test.ts +1 -1
- package/src/AllowLists/SimpleAllowList.ts +6 -3
- package/src/AllowLists/SimpleDenyList.ts +6 -3
- package/src/BoostCore.test.ts +31 -91
- package/src/BoostCore.ts +137 -34
- package/src/BoostRegistry.ts +89 -21
- package/src/Budgets/ManagedBudget.ts +6 -4
- package/src/Budgets/SimpleBudget.ts +4 -3
- package/src/Budgets/VestingBudget.ts +4 -3
- package/src/Deployable/DeployableTarget.ts +22 -11
- package/src/Incentives/AllowListIncentive.ts +6 -3
- package/src/Incentives/CGDAIncentive.ts +6 -3
- package/src/Incentives/ERC1155Incentive.ts +4 -3
- package/src/Incentives/ERC20Incentive.ts +6 -3
- package/src/Incentives/ERC20VariableIncentive.ts +6 -3
- package/src/Incentives/PointsIncentive.ts +6 -3
- package/src/Validators/SignerValidator.ts +6 -3
- package/src/errors.ts +177 -21
- package/src/utils.ts +60 -11
- package/dist/SimpleDenyList-CqT0BMP7.cjs +0 -2
- package/dist/SimpleDenyList-CqT0BMP7.cjs.map +0 -1
- package/dist/generated-BDeDiaCK.js.map +0 -1
- package/dist/generated-wKBNvm48.cjs +0 -3
- package/dist/generated-wKBNvm48.cjs.map +0 -1
|
@@ -1,27 +1,47 @@
|
|
|
1
1
|
import { selectors as eventSelectors } from '@boostxyz/signatures/events';
|
|
2
|
+
import { selectors as funcSelectors } from '@boostxyz/signatures/functions';
|
|
2
3
|
import { loadFixture } from '@nomicfoundation/hardhat-network-helpers';
|
|
3
|
-
import {
|
|
4
|
+
import {
|
|
5
|
+
type AbiEvent,
|
|
6
|
+
type Address,
|
|
7
|
+
type GetLogsReturnType,
|
|
8
|
+
type Hex,
|
|
9
|
+
type Log,
|
|
10
|
+
isAddress,
|
|
11
|
+
pad,
|
|
12
|
+
parseEther,
|
|
13
|
+
toHex,
|
|
14
|
+
} from 'viem';
|
|
4
15
|
import { beforeAll, beforeEach, describe, expect, test } from 'vitest';
|
|
16
|
+
import type { MockERC20 } from '../../test/MockERC20';
|
|
5
17
|
import type { MockERC721 } from '../../test/MockERC721';
|
|
6
18
|
import { accounts } from '../../test/accounts';
|
|
7
19
|
import {
|
|
8
20
|
type Fixtures,
|
|
21
|
+
type StringEmitterFixtures,
|
|
9
22
|
defaultOptions,
|
|
10
23
|
deployFixtures,
|
|
24
|
+
fundErc20,
|
|
25
|
+
deployStringEmitterMock,
|
|
11
26
|
fundErc721,
|
|
12
27
|
} from '../../test/helpers';
|
|
13
28
|
import {
|
|
14
29
|
EventAction,
|
|
30
|
+
type EventLogs,
|
|
15
31
|
type EventActionPayloadSimple,
|
|
16
32
|
FilterType,
|
|
17
33
|
PrimitiveType,
|
|
18
34
|
SignatureType,
|
|
19
35
|
} from './EventAction';
|
|
20
36
|
|
|
21
|
-
let fixtures: Fixtures,
|
|
37
|
+
let fixtures: Fixtures,
|
|
38
|
+
erc721: MockERC721,
|
|
39
|
+
erc20: MockERC20,
|
|
40
|
+
stringEmitterFixtures: StringEmitterFixtures;
|
|
22
41
|
|
|
23
42
|
beforeAll(async () => {
|
|
24
43
|
fixtures = await loadFixture(deployFixtures);
|
|
44
|
+
stringEmitterFixtures = await loadFixture(deployStringEmitterMock);
|
|
25
45
|
});
|
|
26
46
|
|
|
27
47
|
function basicErc721TransferAction(
|
|
@@ -30,21 +50,25 @@ function basicErc721TransferAction(
|
|
|
30
50
|
return {
|
|
31
51
|
actionClaimant: {
|
|
32
52
|
signatureType: SignatureType.EVENT,
|
|
33
|
-
signature: eventSelectors[
|
|
34
|
-
|
|
53
|
+
signature: eventSelectors[
|
|
54
|
+
'Transfer(address indexed,address indexed,uint256 indexed)'
|
|
55
|
+
] as Hex,
|
|
56
|
+
fieldIndex: 1,
|
|
35
57
|
targetContract: erc721.assertValidAddress(),
|
|
36
58
|
chainid: defaultOptions.config.chains[0].id,
|
|
37
59
|
},
|
|
38
60
|
actionSteps: [
|
|
39
61
|
{
|
|
40
|
-
signature: eventSelectors[
|
|
62
|
+
signature: eventSelectors[
|
|
63
|
+
'Transfer(address indexed,address indexed,uint256 indexed)'
|
|
64
|
+
] as Hex,
|
|
41
65
|
signatureType: SignatureType.EVENT,
|
|
42
66
|
targetContract: erc721.assertValidAddress(),
|
|
43
67
|
chainid: defaultOptions.config.chains[0].id,
|
|
44
68
|
actionParameter: {
|
|
45
69
|
filterType: FilterType.EQUAL,
|
|
46
70
|
fieldType: PrimitiveType.ADDRESS,
|
|
47
|
-
fieldIndex:
|
|
71
|
+
fieldIndex: 1,
|
|
48
72
|
filterData: accounts[1].account,
|
|
49
73
|
},
|
|
50
74
|
},
|
|
@@ -52,154 +76,558 @@ function basicErc721TransferAction(
|
|
|
52
76
|
};
|
|
53
77
|
}
|
|
54
78
|
|
|
55
|
-
|
|
79
|
+
function cloneEventAction(fixtures: Fixtures, erc721: MockERC721) {
|
|
80
|
+
return function cloneEventAction() {
|
|
81
|
+
return fixtures.registry.initialize(
|
|
82
|
+
crypto.randomUUID(),
|
|
83
|
+
fixtures.core.EventAction(basicErc721TransferAction(erc721)),
|
|
84
|
+
);
|
|
85
|
+
};
|
|
86
|
+
}
|
|
87
|
+
|
|
56
88
|
function basicErc721MintFuncAction(
|
|
57
89
|
erc721: MockERC721,
|
|
58
90
|
): EventActionPayloadSimple {
|
|
59
91
|
return {
|
|
60
92
|
actionClaimant: {
|
|
61
93
|
signatureType: SignatureType.FUNC,
|
|
62
|
-
signature: funcSelectors['mint(address)'] as Hex,
|
|
94
|
+
signature: pad(funcSelectors['mint(address)'] as Hex),
|
|
63
95
|
fieldIndex: 0,
|
|
64
96
|
targetContract: erc721.assertValidAddress(),
|
|
97
|
+
chainid: defaultOptions.config.chains[0].id,
|
|
65
98
|
},
|
|
66
99
|
actionSteps: [
|
|
67
100
|
{
|
|
68
|
-
signature: funcSelectors['mint(address)'] as Hex,
|
|
101
|
+
signature: pad(funcSelectors['mint(address)'] as Hex),
|
|
69
102
|
signatureType: SignatureType.FUNC,
|
|
70
103
|
actionType: 0,
|
|
71
104
|
targetContract: erc721.assertValidAddress(),
|
|
105
|
+
chainid: defaultOptions.config.chains[0].id,
|
|
72
106
|
actionParameter: {
|
|
73
107
|
filterType: FilterType.EQUAL,
|
|
74
108
|
fieldType: PrimitiveType.ADDRESS,
|
|
75
|
-
fieldIndex:
|
|
109
|
+
fieldIndex: 0,
|
|
76
110
|
filterData: accounts[1].account,
|
|
77
111
|
},
|
|
78
112
|
},
|
|
79
113
|
],
|
|
80
114
|
};
|
|
81
115
|
}
|
|
82
|
-
*/
|
|
83
116
|
|
|
84
|
-
function
|
|
85
|
-
return
|
|
86
|
-
|
|
117
|
+
function basicErc20MintFuncAction(erc20: MockERC20): EventActionPayloadSimple {
|
|
118
|
+
return {
|
|
119
|
+
actionClaimant: {
|
|
120
|
+
signatureType: SignatureType.FUNC,
|
|
121
|
+
signature: pad(funcSelectors['mint(address to, uint256 amount)'] as Hex),
|
|
122
|
+
fieldIndex: 0,
|
|
123
|
+
targetContract: erc20.assertValidAddress(),
|
|
124
|
+
chainid: defaultOptions.config.chains[0].id,
|
|
125
|
+
},
|
|
126
|
+
actionSteps: [
|
|
127
|
+
{
|
|
128
|
+
signature: pad(
|
|
129
|
+
funcSelectors['mint(address to, uint256 amount)'] as Hex,
|
|
130
|
+
),
|
|
131
|
+
signatureType: SignatureType.FUNC,
|
|
132
|
+
actionType: 0,
|
|
133
|
+
targetContract: erc20.assertValidAddress(),
|
|
134
|
+
chainid: defaultOptions.config.chains[0].id,
|
|
135
|
+
actionParameter: {
|
|
136
|
+
filterType: FilterType.EQUAL,
|
|
137
|
+
fieldType: PrimitiveType.ADDRESS,
|
|
138
|
+
fieldIndex: 0,
|
|
139
|
+
filterData: accounts[1].account,
|
|
140
|
+
},
|
|
141
|
+
},
|
|
142
|
+
],
|
|
143
|
+
};
|
|
144
|
+
}
|
|
145
|
+
|
|
146
|
+
function indexedStringErc721TransferAction(
|
|
147
|
+
filterType: FilterType,
|
|
148
|
+
data: Hex,
|
|
149
|
+
stringEmitterAddress: Address,
|
|
150
|
+
erc721: MockERC721,
|
|
151
|
+
): EventActionPayloadSimple {
|
|
152
|
+
return {
|
|
153
|
+
actionClaimant: {
|
|
154
|
+
signatureType: SignatureType.EVENT,
|
|
155
|
+
signature: eventSelectors[
|
|
156
|
+
'Transfer(address indexed,address indexed,uint256 indexed)'
|
|
157
|
+
] as Hex,
|
|
158
|
+
fieldIndex: 1,
|
|
159
|
+
targetContract: erc721.assertValidAddress(),
|
|
160
|
+
chainid: defaultOptions.config.chains[0].id,
|
|
161
|
+
},
|
|
162
|
+
actionSteps: [
|
|
163
|
+
{
|
|
164
|
+
signature: eventSelectors[
|
|
165
|
+
'InfoIndexed(address indexed,string indexed)'
|
|
166
|
+
] as Hex,
|
|
167
|
+
signatureType: SignatureType.EVENT,
|
|
168
|
+
actionType: 0,
|
|
169
|
+
targetContract: stringEmitterAddress,
|
|
170
|
+
chainid: defaultOptions.config.chains[0].id,
|
|
171
|
+
actionParameter: {
|
|
172
|
+
filterType,
|
|
173
|
+
fieldType: PrimitiveType.STRING,
|
|
174
|
+
fieldIndex: 1,
|
|
175
|
+
filterData: data,
|
|
176
|
+
},
|
|
177
|
+
},
|
|
178
|
+
],
|
|
179
|
+
};
|
|
180
|
+
}
|
|
181
|
+
|
|
182
|
+
function stringErc721TransferAction(
|
|
183
|
+
filterType: FilterType,
|
|
184
|
+
data: Hex,
|
|
185
|
+
stringEmitterAddress: Address,
|
|
186
|
+
erc721: MockERC721,
|
|
187
|
+
): EventActionPayloadSimple {
|
|
188
|
+
return {
|
|
189
|
+
actionClaimant: {
|
|
190
|
+
signatureType: SignatureType.EVENT,
|
|
191
|
+
signature: eventSelectors[
|
|
192
|
+
'Transfer(address indexed,address indexed,uint256 indexed)'
|
|
193
|
+
] as Hex,
|
|
194
|
+
fieldIndex: 1,
|
|
195
|
+
targetContract: erc721.assertValidAddress(),
|
|
196
|
+
chainid: defaultOptions.config.chains[0].id,
|
|
197
|
+
},
|
|
198
|
+
actionSteps: [
|
|
199
|
+
{
|
|
200
|
+
signature: eventSelectors['Info(address,string)'] as Hex,
|
|
201
|
+
signatureType: SignatureType.EVENT,
|
|
202
|
+
actionType: 0,
|
|
203
|
+
targetContract: stringEmitterAddress,
|
|
204
|
+
chainid: defaultOptions.config.chains[0].id,
|
|
205
|
+
actionParameter: {
|
|
206
|
+
filterType,
|
|
207
|
+
fieldType: PrimitiveType.STRING,
|
|
208
|
+
fieldIndex: 1,
|
|
209
|
+
filterData: data,
|
|
210
|
+
},
|
|
211
|
+
},
|
|
212
|
+
],
|
|
213
|
+
};
|
|
214
|
+
}
|
|
215
|
+
|
|
216
|
+
function cloneFunctionAction20(fixtures: Fixtures, erc20: MockERC20) {
|
|
217
|
+
return function cloneFunctionAction20() {
|
|
218
|
+
return fixtures.registry.clone(
|
|
87
219
|
crypto.randomUUID(),
|
|
88
|
-
fixtures.
|
|
220
|
+
new fixtures.bases.EventAction(
|
|
221
|
+
defaultOptions,
|
|
222
|
+
basicErc20MintFuncAction(erc20),
|
|
223
|
+
),
|
|
224
|
+
);
|
|
225
|
+
};
|
|
226
|
+
}
|
|
227
|
+
|
|
228
|
+
function cloneFunctionAction(fixtures: Fixtures, erc721: MockERC721) {
|
|
229
|
+
return function cloneFunctionAction() {
|
|
230
|
+
return fixtures.registry.clone(
|
|
231
|
+
crypto.randomUUID(),
|
|
232
|
+
new fixtures.bases.EventAction(
|
|
233
|
+
defaultOptions,
|
|
234
|
+
basicErc721MintFuncAction(erc721),
|
|
235
|
+
),
|
|
236
|
+
);
|
|
237
|
+
};
|
|
238
|
+
}
|
|
239
|
+
|
|
240
|
+
function cloneStringEventAction(
|
|
241
|
+
fixtures: Fixtures,
|
|
242
|
+
actionParams: EventActionPayloadSimple,
|
|
243
|
+
) {
|
|
244
|
+
return function loadFixtureCallback() {
|
|
245
|
+
return fixtures.registry.clone(
|
|
246
|
+
crypto.randomUUID(),
|
|
247
|
+
new fixtures.bases.EventAction(defaultOptions, actionParams),
|
|
89
248
|
);
|
|
90
249
|
};
|
|
91
250
|
}
|
|
92
251
|
|
|
93
|
-
describe('EventAction', () => {
|
|
252
|
+
describe('EventAction Event Selector', () => {
|
|
94
253
|
beforeEach(async () => {
|
|
95
254
|
erc721 = await loadFixture(fundErc721(defaultOptions));
|
|
96
255
|
});
|
|
97
256
|
|
|
98
|
-
|
|
257
|
+
describe('basic transfer event', () => {
|
|
258
|
+
test('can successfully be deployed', async () => {
|
|
259
|
+
const action = new EventAction(
|
|
260
|
+
defaultOptions,
|
|
261
|
+
basicErc721TransferAction(erc721),
|
|
262
|
+
);
|
|
263
|
+
await action.deploy();
|
|
264
|
+
expect(isAddress(action.assertValidAddress())).toBe(true);
|
|
265
|
+
});
|
|
266
|
+
|
|
267
|
+
test('can get an action step', async () => {
|
|
268
|
+
const action = await loadFixture(cloneEventAction(fixtures, erc721));
|
|
269
|
+
const step = await action.getActionStep(0);
|
|
270
|
+
if (!step)
|
|
271
|
+
throw new Error('there should be an action step at this index');
|
|
272
|
+
step.targetContract = step.targetContract.toUpperCase() as Hex;
|
|
273
|
+
step.actionParameter.filterData =
|
|
274
|
+
step.actionParameter.filterData.toUpperCase() as Hex;
|
|
275
|
+
expect(step).toMatchObject({
|
|
276
|
+
signature: eventSelectors[
|
|
277
|
+
'Transfer(address indexed,address indexed,uint256 indexed)'
|
|
278
|
+
] as Hex,
|
|
279
|
+
signatureType: SignatureType.EVENT,
|
|
280
|
+
actionType: 0,
|
|
281
|
+
targetContract: erc721.assertValidAddress().toUpperCase(),
|
|
282
|
+
actionParameter: {
|
|
283
|
+
filterType: FilterType.EQUAL,
|
|
284
|
+
fieldType: PrimitiveType.ADDRESS,
|
|
285
|
+
fieldIndex: 1,
|
|
286
|
+
filterData: accounts[1].account.toUpperCase(),
|
|
287
|
+
},
|
|
288
|
+
});
|
|
289
|
+
});
|
|
290
|
+
|
|
291
|
+
test('can get all action steps', async () => {
|
|
292
|
+
const action = await loadFixture(cloneEventAction(fixtures, erc721));
|
|
293
|
+
const steps = await action.getActionSteps();
|
|
294
|
+
expect(steps.length).toBe(1);
|
|
295
|
+
const step = steps[0];
|
|
296
|
+
step.targetContract = step.targetContract.toUpperCase() as Hex;
|
|
297
|
+
step.actionParameter.filterData =
|
|
298
|
+
step.actionParameter.filterData.toUpperCase() as Hex;
|
|
299
|
+
expect(step).toMatchObject({
|
|
300
|
+
signature: eventSelectors[
|
|
301
|
+
'Transfer(address indexed,address indexed,uint256 indexed)'
|
|
302
|
+
] as Hex,
|
|
303
|
+
signatureType: SignatureType.EVENT,
|
|
304
|
+
actionType: 0,
|
|
305
|
+
targetContract: erc721.assertValidAddress().toUpperCase(),
|
|
306
|
+
actionParameter: {
|
|
307
|
+
filterType: FilterType.EQUAL,
|
|
308
|
+
fieldType: PrimitiveType.ADDRESS,
|
|
309
|
+
fieldIndex: 1,
|
|
310
|
+
filterData: accounts[1].account.toUpperCase(),
|
|
311
|
+
},
|
|
312
|
+
});
|
|
313
|
+
});
|
|
314
|
+
|
|
315
|
+
test('can get the total number of action steps', async () => {
|
|
316
|
+
const action = await loadFixture(cloneEventAction(fixtures, erc721));
|
|
317
|
+
const count = await action.getActionStepsCount();
|
|
318
|
+
expect(count).toBe(1);
|
|
319
|
+
});
|
|
320
|
+
|
|
321
|
+
test('can get the action claimant', async () => {
|
|
322
|
+
const action = await loadFixture(cloneEventAction(fixtures, erc721));
|
|
323
|
+
const claimant = await action.getActionClaimant();
|
|
324
|
+
claimant.targetContract = claimant.targetContract.toUpperCase() as Hex;
|
|
325
|
+
expect(claimant).toMatchObject({
|
|
326
|
+
signatureType: SignatureType.EVENT,
|
|
327
|
+
signature: eventSelectors[
|
|
328
|
+
'Transfer(address indexed,address indexed,uint256 indexed)'
|
|
329
|
+
] as Hex,
|
|
330
|
+
fieldIndex: 1,
|
|
331
|
+
});
|
|
332
|
+
});
|
|
333
|
+
|
|
334
|
+
test('can get all action steps', async () => {
|
|
335
|
+
const action = await loadFixture(cloneEventAction(fixtures, erc721));
|
|
336
|
+
const steps = await action.getActionSteps();
|
|
337
|
+
expect(steps.length).toBe(1);
|
|
338
|
+
const step = steps[0];
|
|
339
|
+
step.targetContract = step.targetContract.toUpperCase() as Hex;
|
|
340
|
+
step.actionParameter.filterData =
|
|
341
|
+
step.actionParameter.filterData.toUpperCase() as Hex;
|
|
342
|
+
expect(step).toMatchObject({
|
|
343
|
+
signature: eventSelectors[
|
|
344
|
+
'Transfer(address indexed,address indexed,uint256 indexed)'
|
|
345
|
+
] as Hex,
|
|
346
|
+
signatureType: SignatureType.EVENT,
|
|
347
|
+
actionType: 0,
|
|
348
|
+
targetContract: erc721.assertValidAddress().toUpperCase(),
|
|
349
|
+
actionParameter: {
|
|
350
|
+
filterType: FilterType.EQUAL,
|
|
351
|
+
fieldType: PrimitiveType.ADDRESS,
|
|
352
|
+
fieldIndex: 1,
|
|
353
|
+
filterData: accounts[1].account.toUpperCase(),
|
|
354
|
+
},
|
|
355
|
+
});
|
|
356
|
+
});
|
|
357
|
+
|
|
358
|
+
test('can get the total number of action steps', async () => {
|
|
359
|
+
const action = await loadFixture(cloneEventAction(fixtures, erc721));
|
|
360
|
+
const count = await action.getActionStepsCount();
|
|
361
|
+
expect(count).toBe(1);
|
|
362
|
+
});
|
|
363
|
+
|
|
364
|
+
test('can get the action claimant', async () => {
|
|
365
|
+
const action = await loadFixture(cloneEventAction(fixtures, erc721));
|
|
366
|
+
const claimant = await action.getActionClaimant();
|
|
367
|
+
claimant.targetContract = claimant.targetContract.toUpperCase() as Hex;
|
|
368
|
+
expect(claimant).toMatchObject({
|
|
369
|
+
signatureType: SignatureType.EVENT,
|
|
370
|
+
signature: eventSelectors[
|
|
371
|
+
'Transfer(address indexed,address indexed,uint256 indexed)'
|
|
372
|
+
] as Hex,
|
|
373
|
+
fieldIndex: 1,
|
|
374
|
+
targetContract: erc721.assertValidAddress().toUpperCase(),
|
|
375
|
+
});
|
|
376
|
+
});
|
|
377
|
+
|
|
378
|
+
test('with no logs, does not validate', async () => {
|
|
379
|
+
const action = await loadFixture(cloneEventAction(fixtures, erc721));
|
|
380
|
+
expect(await action.validateActionSteps()).toBe(false);
|
|
381
|
+
});
|
|
382
|
+
|
|
383
|
+
test('with a correct log, validates', async () => {
|
|
384
|
+
const action = await loadFixture(cloneEventAction(fixtures, erc721));
|
|
385
|
+
const recipient = accounts[1].account;
|
|
386
|
+
await erc721.approve(recipient, 1n);
|
|
387
|
+
await erc721.transferFrom(defaultOptions.account.address, recipient, 1n);
|
|
388
|
+
expect(await action.validateActionSteps()).toBe(true);
|
|
389
|
+
});
|
|
390
|
+
|
|
391
|
+
test('can supply your own logs to validate against', async () => {
|
|
392
|
+
const logs: EventLogs = [
|
|
393
|
+
{
|
|
394
|
+
eventName: 'Transfer',
|
|
395
|
+
args: [
|
|
396
|
+
'0xf39Fd6e51aad88F6F4ce6aB8827279cffFb92266',
|
|
397
|
+
'0x70997970C51812dc3A010C7d01b50e0d17dc79C8',
|
|
398
|
+
1n,
|
|
399
|
+
],
|
|
400
|
+
address: erc721.assertValidAddress(),
|
|
401
|
+
blockHash:
|
|
402
|
+
'0xbf602f988260519805d032be46d6ff97fbefbee6924b21097074d6d0bc34eced',
|
|
403
|
+
blockNumber: 1203n,
|
|
404
|
+
data: '0x',
|
|
405
|
+
logIndex: 0,
|
|
406
|
+
removed: false,
|
|
407
|
+
topics: [
|
|
408
|
+
'0xddf252ad1be2c89b69c2b068fc378daa952ba7f163c4a11628f55a4df523b3ef',
|
|
409
|
+
'0x000000000000000000000000f39fd6e51aad88f6f4ce6ab8827279cfffb92266',
|
|
410
|
+
'0x00000000000000000000000070997970c51812dc3a010c7d01b50e0d17dc79c8',
|
|
411
|
+
'0x0000000000000000000000000000000000000000000000000000000000000001',
|
|
412
|
+
],
|
|
413
|
+
transactionHash:
|
|
414
|
+
'0xff0e6ab0c4961ec14b7b40afec83ed7d7a77582683512a262e641d21f82efea5',
|
|
415
|
+
transactionIndex: 0,
|
|
416
|
+
},
|
|
417
|
+
];
|
|
418
|
+
const action = await loadFixture(cloneEventAction(fixtures, erc721));
|
|
419
|
+
expect(
|
|
420
|
+
await action.validateActionSteps({ logs }),
|
|
421
|
+
).toBe(true);
|
|
422
|
+
});
|
|
423
|
+
|
|
424
|
+
describe('string event actions', () => {
|
|
425
|
+
test('cannot parse and validate contains for an emitted string event with an indexed param', async () => {
|
|
426
|
+
const action = await loadFixture(
|
|
427
|
+
cloneStringEventAction(
|
|
428
|
+
fixtures,
|
|
429
|
+
indexedStringErc721TransferAction(
|
|
430
|
+
FilterType.CONTAINS,
|
|
431
|
+
toHex('ello'),
|
|
432
|
+
stringEmitterFixtures.address,
|
|
433
|
+
erc721,
|
|
434
|
+
),
|
|
435
|
+
),
|
|
436
|
+
);
|
|
437
|
+
|
|
438
|
+
await stringEmitterFixtures.emitIndexedString('Hello world');
|
|
439
|
+
await expect(() => action.validateActionSteps()).rejects.toThrowError(
|
|
440
|
+
/Parameter is not transparently stored onchain/,
|
|
441
|
+
);
|
|
442
|
+
});
|
|
443
|
+
test('can parse and validate contains for an emitted string event', async () => {
|
|
444
|
+
const action = await loadFixture(
|
|
445
|
+
cloneStringEventAction(
|
|
446
|
+
fixtures,
|
|
447
|
+
stringErc721TransferAction(
|
|
448
|
+
FilterType.CONTAINS,
|
|
449
|
+
toHex('ello'),
|
|
450
|
+
stringEmitterFixtures.address,
|
|
451
|
+
erc721,
|
|
452
|
+
),
|
|
453
|
+
),
|
|
454
|
+
);
|
|
455
|
+
await stringEmitterFixtures.emitString('Hello world');
|
|
456
|
+
expect(await action.validateActionSteps()).toBe(true);
|
|
457
|
+
});
|
|
458
|
+
test('can parse and validate regex for an emitted string event', async () => {
|
|
459
|
+
const action = await loadFixture(
|
|
460
|
+
cloneStringEventAction(
|
|
461
|
+
fixtures,
|
|
462
|
+
stringErc721TransferAction(
|
|
463
|
+
FilterType.REGEX,
|
|
464
|
+
toHex('[hH]ello'),
|
|
465
|
+
stringEmitterFixtures.address,
|
|
466
|
+
erc721,
|
|
467
|
+
),
|
|
468
|
+
),
|
|
469
|
+
);
|
|
470
|
+
|
|
471
|
+
await stringEmitterFixtures.emitString('Hello world');
|
|
472
|
+
expect(await action.validateActionSteps()).toBe(true);
|
|
473
|
+
});
|
|
474
|
+
});
|
|
475
|
+
});
|
|
476
|
+
});
|
|
477
|
+
|
|
478
|
+
describe('EventAction Func Selector', () => {
|
|
479
|
+
beforeEach(async () => {
|
|
480
|
+
erc721 = await loadFixture(fundErc721(defaultOptions));
|
|
481
|
+
erc20 = await loadFixture(fundErc20(defaultOptions));
|
|
482
|
+
});
|
|
483
|
+
|
|
484
|
+
test('can be deployed successfully', async () => {
|
|
99
485
|
const action = new EventAction(
|
|
100
486
|
defaultOptions,
|
|
101
|
-
|
|
487
|
+
basicErc721MintFuncAction(erc721),
|
|
102
488
|
);
|
|
103
489
|
await action.deploy();
|
|
104
490
|
expect(isAddress(action.assertValidAddress())).toBe(true);
|
|
105
491
|
});
|
|
106
492
|
|
|
107
|
-
test('
|
|
108
|
-
const action = await loadFixture(
|
|
109
|
-
const
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
step.actionParameter.filterData.toUpperCase() as Hex;
|
|
114
|
-
expect(step).toMatchObject({
|
|
115
|
-
signature: eventSelectors['Transfer(address,address,uint256)'] as Hex,
|
|
116
|
-
signatureType: SignatureType.EVENT,
|
|
117
|
-
actionType: 0,
|
|
118
|
-
targetContract: erc721.assertValidAddress().toUpperCase(),
|
|
119
|
-
actionParameter: {
|
|
120
|
-
filterType: FilterType.EQUAL,
|
|
121
|
-
fieldType: PrimitiveType.ADDRESS,
|
|
122
|
-
fieldIndex: 2,
|
|
123
|
-
filterData: accounts[1].account.toUpperCase(),
|
|
124
|
-
},
|
|
493
|
+
test('validates function action step with correct hash', async () => {
|
|
494
|
+
const action = await loadFixture(cloneFunctionAction(fixtures, erc721));
|
|
495
|
+
const actionSteps = await action.getActionSteps();
|
|
496
|
+
const recipient = accounts[1].account;
|
|
497
|
+
const { hash } = await erc721.mintRaw(recipient, {
|
|
498
|
+
value: parseEther('.1'),
|
|
125
499
|
});
|
|
500
|
+
|
|
501
|
+
expect(
|
|
502
|
+
await action.isActionFunctionValid(actionSteps[0], {
|
|
503
|
+
hash,
|
|
504
|
+
}),
|
|
505
|
+
).toBe(true);
|
|
126
506
|
});
|
|
127
507
|
|
|
128
|
-
test('
|
|
129
|
-
const action = await loadFixture(
|
|
130
|
-
const
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
508
|
+
test('throws an error when hash is missing', async () => {
|
|
509
|
+
const action = await loadFixture(cloneFunctionAction(fixtures, erc721));
|
|
510
|
+
const actionSteps = await action.getActionSteps();
|
|
511
|
+
try {
|
|
512
|
+
await action.isActionFunctionValid(actionSteps[0], {});
|
|
513
|
+
} catch (e) {
|
|
514
|
+
expect(e).toBeInstanceOf(Error);
|
|
515
|
+
expect((e as Error).message).toBe(
|
|
516
|
+
'Hash is required for function validation',
|
|
517
|
+
);
|
|
518
|
+
}
|
|
519
|
+
});
|
|
520
|
+
|
|
521
|
+
test('validates function step with EQUAL filter', async () => {
|
|
522
|
+
const action = await loadFixture(cloneFunctionAction(fixtures, erc721));
|
|
523
|
+
const actionSteps = await action.getActionSteps();
|
|
524
|
+
|
|
525
|
+
const recipient = accounts[1].account;
|
|
526
|
+
const { hash } = await erc721.mintRaw(recipient, {
|
|
527
|
+
value: parseEther('.1'),
|
|
528
|
+
});
|
|
529
|
+
|
|
530
|
+
const criteriaMatch = await action.isActionFunctionValid(actionSteps[0], {
|
|
531
|
+
hash,
|
|
147
532
|
});
|
|
533
|
+
|
|
534
|
+
expect(criteriaMatch).toBe(true);
|
|
148
535
|
});
|
|
149
536
|
|
|
150
|
-
test('
|
|
151
|
-
const action = await loadFixture(
|
|
152
|
-
const
|
|
153
|
-
|
|
537
|
+
test('fails validation with incorrect function signature', async () => {
|
|
538
|
+
const action = await loadFixture(cloneFunctionAction(fixtures, erc721));
|
|
539
|
+
const actionSteps = await action.getActionSteps();
|
|
540
|
+
const recipient = accounts[1].account;
|
|
541
|
+
|
|
542
|
+
const invalidStep = {
|
|
543
|
+
...actionSteps[0],
|
|
544
|
+
signature: pad(funcSelectors['mint(address to, uint256 amount)'] as Hex), // Intentional mismatch
|
|
545
|
+
};
|
|
546
|
+
|
|
547
|
+
const { hash } = await erc721.mintRaw(recipient, {
|
|
548
|
+
value: parseEther('.1'),
|
|
549
|
+
});
|
|
550
|
+
|
|
551
|
+
try {
|
|
552
|
+
await action.isActionFunctionValid(invalidStep, { hash });
|
|
553
|
+
} catch (e) {
|
|
554
|
+
expect(e).toBeInstanceOf(Error);
|
|
555
|
+
expect((e as Error).message).toContain(
|
|
556
|
+
'Failed to decode function data: Encoded function signature "0x6a627842"',
|
|
557
|
+
);
|
|
558
|
+
}
|
|
154
559
|
});
|
|
155
560
|
|
|
156
|
-
test('
|
|
157
|
-
const action = await loadFixture(
|
|
158
|
-
const
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
fieldIndex: 2,
|
|
164
|
-
targetContract: erc721.assertValidAddress().toUpperCase(),
|
|
561
|
+
test('validates against NOT_EQUAL filter criteria', async () => {
|
|
562
|
+
const action = await loadFixture(cloneFunctionAction(fixtures, erc721));
|
|
563
|
+
const actionSteps = await action.getActionSteps();
|
|
564
|
+
actionSteps[0].actionParameter.filterType = FilterType.NOT_EQUAL;
|
|
565
|
+
const recipient = accounts[2].account;
|
|
566
|
+
const { hash } = await erc721.mintRaw(recipient, {
|
|
567
|
+
value: parseEther('.1'),
|
|
165
568
|
});
|
|
569
|
+
|
|
570
|
+
expect(
|
|
571
|
+
await action.isActionFunctionValid(actionSteps[0], {
|
|
572
|
+
hash,
|
|
573
|
+
}),
|
|
574
|
+
).toBe(true);
|
|
166
575
|
});
|
|
167
576
|
|
|
168
|
-
test('
|
|
169
|
-
const action = await loadFixture(
|
|
170
|
-
|
|
577
|
+
test('validates GREATER_THAN criteria for numeric values', async () => {
|
|
578
|
+
const action = await loadFixture(cloneFunctionAction20(fixtures, erc20));
|
|
579
|
+
const actionSteps = await action.getActionSteps();
|
|
580
|
+
|
|
581
|
+
actionSteps[0].actionParameter = {
|
|
582
|
+
filterType: FilterType.GREATER_THAN,
|
|
583
|
+
fieldType: PrimitiveType.UINT,
|
|
584
|
+
fieldIndex: 1,
|
|
585
|
+
filterData: toHex('1'),
|
|
586
|
+
};
|
|
587
|
+
|
|
588
|
+
const address = accounts[1].account;
|
|
589
|
+
const value = 400n;
|
|
590
|
+
const { hash } = await erc20.mintRaw(address, value);
|
|
591
|
+
|
|
592
|
+
expect(
|
|
593
|
+
await action.isActionFunctionValid(actionSteps[0], {
|
|
594
|
+
hash,
|
|
595
|
+
}),
|
|
596
|
+
).toBe(true);
|
|
171
597
|
});
|
|
172
598
|
|
|
173
|
-
test('
|
|
174
|
-
const action = await loadFixture(
|
|
175
|
-
const
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
599
|
+
test('validates LESS_THAN criteria for numeric values', async () => {
|
|
600
|
+
const action = await loadFixture(cloneFunctionAction20(fixtures, erc20));
|
|
601
|
+
const actionSteps = await action.getActionSteps();
|
|
602
|
+
actionSteps[0].actionParameter = {
|
|
603
|
+
filterType: FilterType.LESS_THAN,
|
|
604
|
+
fieldType: PrimitiveType.UINT,
|
|
605
|
+
fieldIndex: 1,
|
|
606
|
+
filterData: toHex('5'),
|
|
607
|
+
};
|
|
608
|
+
|
|
609
|
+
const address = accounts[1].account;
|
|
610
|
+
const value = 4n;
|
|
611
|
+
const { hash } = await erc20.mintRaw(address, value);
|
|
612
|
+
|
|
613
|
+
expect(
|
|
614
|
+
await action.isActionFunctionValid(actionSteps[0], {
|
|
615
|
+
hash,
|
|
616
|
+
}),
|
|
617
|
+
).toBe(true);
|
|
179
618
|
});
|
|
180
619
|
|
|
181
|
-
test('
|
|
182
|
-
const
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
'0xddf252ad1be2c89b69c2b068fc378daa952ba7f163c4a11628f55a4df523b3ef',
|
|
194
|
-
'0x000000000000000000000000f39fd6e51aad88f6f4ce6ab8827279cfffb92266',
|
|
195
|
-
'0x00000000000000000000000070997970c51812dc3a010c7d01b50e0d17dc79c8',
|
|
196
|
-
'0x0000000000000000000000000000000000000000000000000000000000000001',
|
|
197
|
-
],
|
|
198
|
-
transactionHash:
|
|
199
|
-
'0xff0e6ab0c4961ec14b7b40afec83ed7d7a77582683512a262e641d21f82efea5',
|
|
200
|
-
transactionIndex: 0,
|
|
201
|
-
} as Log;
|
|
202
|
-
const action = await loadFixture(cloneEventAction(fixtures, erc721));
|
|
203
|
-
expect(await action.validateActionSteps({ logs: [log] })).toBe(true);
|
|
620
|
+
test('validates entire flow of function action', async () => {
|
|
621
|
+
const action = await loadFixture(cloneFunctionAction(fixtures, erc721));
|
|
622
|
+
const recipient = accounts[1].account;
|
|
623
|
+
const { hash } = await erc721.mintRaw(recipient, {
|
|
624
|
+
value: parseEther('.1'),
|
|
625
|
+
});
|
|
626
|
+
|
|
627
|
+
expect(
|
|
628
|
+
await action.validateActionSteps({
|
|
629
|
+
hash ,
|
|
630
|
+
}),
|
|
631
|
+
).toBe(true);
|
|
204
632
|
});
|
|
205
633
|
});
|