@boostxyz/sdk 0.0.0-alpha.3 → 0.0.0-alpha.6
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 +2 -1
- package/dist/Actions/Action.cjs.map +1 -0
- package/dist/Actions/Action.d.ts +1 -1
- package/dist/Actions/Action.d.ts.map +1 -1
- package/dist/Actions/Action.js +15 -13
- package/dist/Actions/Action.js.map +1 -0
- package/dist/Actions/EventAction.cjs +1 -0
- package/dist/Actions/EventAction.cjs.map +1 -0
- package/dist/Actions/EventAction.js +1 -0
- package/dist/Actions/EventAction.js.map +1 -0
- package/dist/AllowLists/AllowList.cjs +2 -1
- package/dist/AllowLists/AllowList.cjs.map +1 -0
- package/dist/AllowLists/AllowList.d.ts +1 -2
- package/dist/AllowLists/AllowList.d.ts.map +1 -1
- package/dist/AllowLists/AllowList.js +16 -14
- package/dist/AllowLists/AllowList.js.map +1 -0
- package/dist/AllowLists/SimpleAllowList.cjs +1 -0
- package/dist/AllowLists/SimpleAllowList.cjs.map +1 -0
- package/dist/AllowLists/SimpleAllowList.js +1 -0
- package/dist/AllowLists/SimpleAllowList.js.map +1 -0
- package/dist/AllowLists/SimpleDenyList.cjs +1 -0
- package/dist/AllowLists/SimpleDenyList.cjs.map +1 -0
- package/dist/AllowLists/SimpleDenyList.js +1 -0
- package/dist/AllowLists/SimpleDenyList.js.map +1 -0
- package/dist/Auth/Auth.cjs +1 -0
- package/dist/Auth/Auth.cjs.map +1 -0
- package/dist/Auth/Auth.js +1 -0
- package/dist/Auth/Auth.js.map +1 -0
- package/dist/Auth/PassthroughAuth.cjs +1 -0
- package/dist/Auth/PassthroughAuth.cjs.map +1 -0
- package/dist/Auth/PassthroughAuth.js +1 -0
- package/dist/Auth/PassthroughAuth.js.map +1 -0
- package/dist/Boost.cjs +1 -0
- package/dist/Boost.cjs.map +1 -0
- package/dist/Boost.js +1 -0
- package/dist/Boost.js.map +1 -0
- package/dist/BoostCore.cjs +1 -0
- package/dist/BoostCore.cjs.map +1 -0
- package/dist/BoostCore.js +1 -0
- package/dist/BoostCore.js.map +1 -0
- package/dist/BoostRegistry.cjs +1 -0
- package/dist/BoostRegistry.cjs.map +1 -0
- package/dist/BoostRegistry.js +1 -0
- package/dist/BoostRegistry.js.map +1 -0
- package/dist/Budgets/Budget.cjs +2 -1
- package/dist/Budgets/Budget.cjs.map +1 -0
- package/dist/Budgets/Budget.d.ts +1 -1
- package/dist/Budgets/Budget.d.ts.map +1 -1
- package/dist/Budgets/Budget.js +14 -12
- package/dist/Budgets/Budget.js.map +1 -0
- package/dist/Budgets/ManagedBudget.cjs +1 -0
- package/dist/Budgets/ManagedBudget.cjs.map +1 -0
- package/dist/Budgets/ManagedBudget.js +1 -0
- package/dist/Budgets/ManagedBudget.js.map +1 -0
- package/dist/Deployable/Contract.cjs +1 -0
- package/dist/Deployable/Contract.cjs.map +1 -0
- package/dist/Deployable/Contract.js +1 -0
- package/dist/Deployable/Contract.js.map +1 -0
- package/dist/Deployable/Deployable.cjs +1 -0
- package/dist/Deployable/Deployable.cjs.map +1 -0
- package/dist/Deployable/Deployable.js +1 -0
- package/dist/Deployable/Deployable.js.map +1 -0
- package/dist/Deployable/DeployableTarget.cjs +1 -0
- package/dist/Deployable/DeployableTarget.cjs.map +1 -0
- package/dist/Deployable/DeployableTarget.js +1 -0
- package/dist/Deployable/DeployableTarget.js.map +1 -0
- package/dist/Incentives/AllowListIncentive.cjs +1 -0
- package/dist/Incentives/AllowListIncentive.cjs.map +1 -0
- package/dist/Incentives/AllowListIncentive.js +1 -0
- package/dist/Incentives/AllowListIncentive.js.map +1 -0
- package/dist/Incentives/CGDAIncentive.cjs +1 -0
- package/dist/Incentives/CGDAIncentive.cjs.map +1 -0
- package/dist/Incentives/CGDAIncentive.js +1 -0
- package/dist/Incentives/CGDAIncentive.js.map +1 -0
- package/dist/Incentives/ERC20Incentive.cjs +1 -0
- package/dist/Incentives/ERC20Incentive.cjs.map +1 -0
- package/dist/Incentives/ERC20Incentive.js +1 -0
- package/dist/Incentives/ERC20Incentive.js.map +1 -0
- package/dist/Incentives/Incentive.cjs +2 -1
- package/dist/Incentives/Incentive.cjs.map +1 -0
- package/dist/Incentives/Incentive.d.ts +1 -4
- package/dist/Incentives/Incentive.d.ts.map +1 -1
- package/dist/Incentives/Incentive.js +39 -36
- package/dist/Incentives/Incentive.js.map +1 -0
- package/dist/Incentives/PointsIncentive.cjs +1 -0
- package/dist/Incentives/PointsIncentive.cjs.map +1 -0
- package/dist/Incentives/PointsIncentive.js +1 -0
- package/dist/Incentives/PointsIncentive.js.map +1 -0
- package/dist/Validators/SignerValidator.cjs +1 -0
- package/dist/Validators/SignerValidator.cjs.map +1 -0
- package/dist/Validators/SignerValidator.js +1 -0
- package/dist/Validators/SignerValidator.js.map +1 -0
- package/dist/Validators/Validator.cjs +2 -1
- package/dist/Validators/Validator.cjs.map +1 -0
- package/dist/Validators/Validator.d.ts +1 -1
- package/dist/Validators/Validator.d.ts.map +1 -1
- package/dist/Validators/Validator.js +9 -7
- package/dist/Validators/Validator.js.map +1 -0
- package/dist/componentInterfaces-CKCBwG16.cjs +2 -0
- package/dist/componentInterfaces-CKCBwG16.cjs.map +1 -0
- package/dist/componentInterfaces-DYkaxBda.js +13 -0
- package/dist/componentInterfaces-DYkaxBda.js.map +1 -0
- package/dist/errors.cjs +1 -0
- package/dist/errors.cjs.map +1 -0
- package/dist/errors.js +1 -0
- package/dist/errors.js.map +1 -0
- package/dist/generated-Cd-Fe7W7.cjs +1 -0
- package/dist/generated-Cd-Fe7W7.cjs.map +1 -0
- package/dist/generated-DGpIVcv5.js +1 -0
- package/dist/generated-DGpIVcv5.js.map +1 -0
- package/dist/index.cjs +1 -0
- package/dist/index.cjs.map +1 -0
- package/dist/index.js +1 -0
- package/dist/index.js.map +1 -0
- package/dist/utils.cjs +1 -0
- package/dist/utils.cjs.map +1 -0
- package/dist/utils.d.ts +1 -1
- package/dist/utils.d.ts.map +1 -1
- package/dist/utils.js +1 -0
- package/dist/utils.js.map +1 -0
- package/package.json +5 -3
- package/src/Actions/Action.test.ts +77 -0
- package/src/Actions/Action.ts +61 -0
- package/src/Actions/ContractAction.test.ts +199 -0
- package/src/Actions/ContractAction.ts +238 -0
- package/src/Actions/ERC721MintAction.test.ts +112 -0
- package/src/Actions/ERC721MintAction.ts +238 -0
- package/src/Actions/EventAction.test.ts +182 -0
- package/src/Actions/EventAction.ts +382 -0
- package/src/AllowLists/AllowList.test.ts +64 -0
- package/src/AllowLists/AllowList.ts +60 -0
- package/src/AllowLists/SimpleAllowList.test.ts +52 -0
- package/src/AllowLists/SimpleAllowList.ts +240 -0
- package/src/AllowLists/SimpleDenyList.test.ts +52 -0
- package/src/AllowLists/SimpleDenyList.ts +289 -0
- package/src/Auth/Auth.ts +11 -0
- package/src/Auth/PassthroughAuth.test.ts +12 -0
- package/src/Auth/PassthroughAuth.ts +80 -0
- package/src/Boost.ts +155 -0
- package/src/BoostCore.test.ts +846 -0
- package/src/BoostCore.ts +1192 -0
- package/src/BoostRegistry.ts +449 -0
- package/src/Budgets/Budget.test.ts +27 -0
- package/src/Budgets/Budget.ts +61 -0
- package/src/Budgets/ManagedBudget.test.ts +154 -0
- package/src/Budgets/ManagedBudget.ts +743 -0
- package/src/Budgets/SimpleBudget.test.ts +152 -0
- package/src/Budgets/SimpleBudget.ts +521 -0
- package/src/Budgets/VestingBudget.test.ts +123 -0
- package/src/Budgets/VestingBudget.ts +532 -0
- package/src/Deployable/Contract.ts +229 -0
- package/src/Deployable/Deployable.ts +244 -0
- package/src/Deployable/DeployableTarget.ts +210 -0
- package/src/Incentives/AllowListIncentive.test.ts +146 -0
- package/src/Incentives/AllowListIncentive.ts +290 -0
- package/src/Incentives/CGDAIncentive.test.ts +136 -0
- package/src/Incentives/CGDAIncentive.ts +364 -0
- package/src/Incentives/ERC1155Incentive.test.ts +98 -0
- package/src/Incentives/ERC1155Incentive.ts +384 -0
- package/src/Incentives/ERC20Incentive.test.ts +141 -0
- package/src/Incentives/ERC20Incentive.ts +417 -0
- package/src/Incentives/ERC20VariableIncentive.test.ts +156 -0
- package/src/Incentives/ERC20VariableIncentive.ts +368 -0
- package/src/Incentives/Incentive.test.ts +92 -0
- package/src/Incentives/Incentive.ts +85 -0
- package/src/Incentives/PointsIncentive.test.ts +142 -0
- package/src/Incentives/PointsIncentive.ts +303 -0
- package/src/Validators/SignerValidator.test.ts +163 -0
- package/src/Validators/SignerValidator.ts +272 -0
- package/src/Validators/Validator.test.ts +21 -0
- package/src/Validators/Validator.ts +55 -0
- package/src/errors.ts +524 -0
- package/src/index.test.ts +40 -0
- package/src/index.ts +50 -0
- package/src/utils.test.ts +44 -0
- package/src/utils.ts +2247 -0
|
@@ -0,0 +1,112 @@
|
|
|
1
|
+
import { mockErc721Abi } from '@boostxyz/evm';
|
|
2
|
+
import { loadFixture } from '@nomicfoundation/hardhat-network-helpers';
|
|
3
|
+
import {
|
|
4
|
+
encodeAbiParameters,
|
|
5
|
+
encodeFunctionData,
|
|
6
|
+
isAddress,
|
|
7
|
+
parseEther,
|
|
8
|
+
toFunctionSelector,
|
|
9
|
+
zeroAddress,
|
|
10
|
+
} from 'viem';
|
|
11
|
+
import { beforeAll, beforeEach, describe, expect, test } from 'vitest';
|
|
12
|
+
import type { MockERC721 } from '../../test/MockERC721';
|
|
13
|
+
import { accounts } from '../../test/accounts';
|
|
14
|
+
import {
|
|
15
|
+
type Fixtures,
|
|
16
|
+
defaultOptions,
|
|
17
|
+
deployFixtures,
|
|
18
|
+
fundErc721,
|
|
19
|
+
} from '../../test/helpers';
|
|
20
|
+
import { ERC721MintAction } from './ERC721MintAction';
|
|
21
|
+
|
|
22
|
+
let fixtures: Fixtures, erc721: MockERC721;
|
|
23
|
+
|
|
24
|
+
beforeAll(async () => {
|
|
25
|
+
fixtures = await loadFixture(deployFixtures);
|
|
26
|
+
});
|
|
27
|
+
|
|
28
|
+
const mintSelector = toFunctionSelector('function mint(address to)');
|
|
29
|
+
|
|
30
|
+
function nonPayableAction(fixtures: Fixtures, erc721: MockERC721) {
|
|
31
|
+
return function nonPayableAction() {
|
|
32
|
+
return fixtures.registry.clone(
|
|
33
|
+
crypto.randomUUID(),
|
|
34
|
+
new fixtures.bases.ERC721MintAction(defaultOptions, {
|
|
35
|
+
chainId: BigInt(31_337),
|
|
36
|
+
target: erc721.assertValidAddress(),
|
|
37
|
+
selector: mintSelector,
|
|
38
|
+
value: 0n,
|
|
39
|
+
}),
|
|
40
|
+
);
|
|
41
|
+
};
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
describe.skip('ERC721MintAction', () => {
|
|
45
|
+
beforeEach(async () => {
|
|
46
|
+
erc721 = await loadFixture(fundErc721(defaultOptions));
|
|
47
|
+
});
|
|
48
|
+
|
|
49
|
+
test('can successfully be deployed', async () => {
|
|
50
|
+
const action = new ERC721MintAction(defaultOptions, {
|
|
51
|
+
chainId: BigInt(31_337),
|
|
52
|
+
target: zeroAddress,
|
|
53
|
+
selector: '0xdeadbeef',
|
|
54
|
+
value: 2n,
|
|
55
|
+
});
|
|
56
|
+
await action.deploy();
|
|
57
|
+
expect(isAddress(action.assertValidAddress())).toBe(true);
|
|
58
|
+
});
|
|
59
|
+
|
|
60
|
+
test('can read chain id', async () => {
|
|
61
|
+
const action = await loadFixture(nonPayableAction(fixtures, erc721));
|
|
62
|
+
expect(await action.chainId()).toBe(BigInt(31_337));
|
|
63
|
+
});
|
|
64
|
+
|
|
65
|
+
test('can read target', async () => {
|
|
66
|
+
const action = await loadFixture(nonPayableAction(fixtures, erc721));
|
|
67
|
+
expect((await action.target()).toLowerCase()).toBe(
|
|
68
|
+
erc721.assertValidAddress().toLowerCase(),
|
|
69
|
+
);
|
|
70
|
+
});
|
|
71
|
+
|
|
72
|
+
test('can read selector', async () => {
|
|
73
|
+
const action = await loadFixture(nonPayableAction(fixtures, erc721));
|
|
74
|
+
expect(await action.selector()).toBe(mintSelector);
|
|
75
|
+
});
|
|
76
|
+
|
|
77
|
+
test('can read value', async () => {
|
|
78
|
+
const action = await loadFixture(nonPayableAction(fixtures, erc721));
|
|
79
|
+
expect(await action.value()).toBe(0n);
|
|
80
|
+
});
|
|
81
|
+
|
|
82
|
+
test('prepare will properly encode execution payload', async () => {
|
|
83
|
+
const action = await loadFixture(nonPayableAction(fixtures, erc721));
|
|
84
|
+
const { account } = accounts.at(1)!;
|
|
85
|
+
const payload = await action.prepare(
|
|
86
|
+
encodeAbiParameters([{ type: 'address', name: 'address' }], [account]),
|
|
87
|
+
);
|
|
88
|
+
expect(payload).toBe(
|
|
89
|
+
encodeFunctionData({
|
|
90
|
+
abi: mockErc721Abi,
|
|
91
|
+
functionName: 'mint',
|
|
92
|
+
args: [account],
|
|
93
|
+
}),
|
|
94
|
+
);
|
|
95
|
+
});
|
|
96
|
+
|
|
97
|
+
// TODO implement execute
|
|
98
|
+
test.skip('nonpayable execute', async () => {
|
|
99
|
+
const action = await loadFixture(nonPayableAction(fixtures, erc721));
|
|
100
|
+
const { account } = accounts.at(1)!;
|
|
101
|
+
const [success] = await action.execute(
|
|
102
|
+
encodeAbiParameters(
|
|
103
|
+
[
|
|
104
|
+
{ type: 'address', name: 'to' },
|
|
105
|
+
{ type: 'uint256', name: 'amount' },
|
|
106
|
+
],
|
|
107
|
+
[account, parseEther('100')],
|
|
108
|
+
),
|
|
109
|
+
);
|
|
110
|
+
expect(success).toBe(true);
|
|
111
|
+
});
|
|
112
|
+
});
|
|
@@ -0,0 +1,238 @@
|
|
|
1
|
+
import {
|
|
2
|
+
erc721MintActionAbi,
|
|
3
|
+
readErc721MintActionPrepare,
|
|
4
|
+
readErc721MintActionValidated,
|
|
5
|
+
simulateErc721MintActionExecute,
|
|
6
|
+
simulateErc721MintActionValidate,
|
|
7
|
+
writeErc721MintActionExecute,
|
|
8
|
+
writeErc721MintActionValidate,
|
|
9
|
+
} from '@boostxyz/evm';
|
|
10
|
+
import { bytecode } from '@boostxyz/evm/artifacts/contracts/actions/ERC721MintAction.sol/ERC721MintAction.json';
|
|
11
|
+
import type { Address, ContractEventName, Hex } from 'viem';
|
|
12
|
+
import type {
|
|
13
|
+
DeployableOptions,
|
|
14
|
+
GenericDeployableParams,
|
|
15
|
+
} from '../Deployable/Deployable';
|
|
16
|
+
import {
|
|
17
|
+
type ERC721MintActionPayload,
|
|
18
|
+
type GenericLog,
|
|
19
|
+
type ReadParams,
|
|
20
|
+
RegistryType,
|
|
21
|
+
type WriteParams,
|
|
22
|
+
prepareERC721MintActionPayload,
|
|
23
|
+
prepareERC721MintActionValidate,
|
|
24
|
+
} from '../utils';
|
|
25
|
+
import { ContractAction } from './ContractAction';
|
|
26
|
+
|
|
27
|
+
export { erc721MintActionAbi, prepareERC721MintActionPayload };
|
|
28
|
+
export type { ERC721MintActionPayload };
|
|
29
|
+
|
|
30
|
+
/**
|
|
31
|
+
* A generic `viem.Log` event with support for `ERC721MintAction` event types.
|
|
32
|
+
*
|
|
33
|
+
* @export
|
|
34
|
+
* @typedef {ERC721MintActionLog}
|
|
35
|
+
* @template {ContractEventName<
|
|
36
|
+
* typeof erc721MintActionAbi
|
|
37
|
+
* >} [event=ContractEventName<typeof erc721MintActionAbi>]
|
|
38
|
+
*/
|
|
39
|
+
export type ERC721MintActionLog<
|
|
40
|
+
event extends ContractEventName<
|
|
41
|
+
typeof erc721MintActionAbi
|
|
42
|
+
> = ContractEventName<typeof erc721MintActionAbi>,
|
|
43
|
+
> = GenericLog<typeof erc721MintActionAbi, event>;
|
|
44
|
+
|
|
45
|
+
/**
|
|
46
|
+
* A primitive action to mint and/or validate that an ERC721 token has been minted
|
|
47
|
+
* The action is expected to be prepared with the data payload for the minting of the token
|
|
48
|
+
* This a minimal generic implementation that should be extended if additional functionality or customizations are required
|
|
49
|
+
* It is expected that the target contract has an externally accessible mint function whose selector
|
|
50
|
+
*
|
|
51
|
+
* @export
|
|
52
|
+
* @class ERC721MintAction
|
|
53
|
+
* @typedef {ERC721MintAction}
|
|
54
|
+
* @extends {ContractAction}
|
|
55
|
+
*/
|
|
56
|
+
export class ERC721MintAction extends ContractAction<
|
|
57
|
+
typeof erc721MintActionAbi
|
|
58
|
+
> {
|
|
59
|
+
//@ts-expect-error should never be constructed with variant typ
|
|
60
|
+
public override readonly abi = erc721MintActionAbi;
|
|
61
|
+
|
|
62
|
+
/**
|
|
63
|
+
* @inheritdoc
|
|
64
|
+
*
|
|
65
|
+
* @public
|
|
66
|
+
* @static
|
|
67
|
+
* @type {Address}
|
|
68
|
+
*/
|
|
69
|
+
public static override base: Address = import.meta.env
|
|
70
|
+
.VITE_ERC721_MINT_ACTION_BASE;
|
|
71
|
+
/**
|
|
72
|
+
* @inheritdoc
|
|
73
|
+
*
|
|
74
|
+
* @public
|
|
75
|
+
* @static
|
|
76
|
+
* @type {RegistryType}
|
|
77
|
+
*/
|
|
78
|
+
public static override registryType: RegistryType = RegistryType.ACTION;
|
|
79
|
+
|
|
80
|
+
/**
|
|
81
|
+
* The set of validated tokens
|
|
82
|
+
* This is intended to prevent multiple validations against the same token ID
|
|
83
|
+
*
|
|
84
|
+
* @public
|
|
85
|
+
* @async
|
|
86
|
+
* @param {bigint} token
|
|
87
|
+
* @param {?ReadParams<typeof erc721MintActionAbi, 'validated'>} [params]
|
|
88
|
+
* @returns {unknown}
|
|
89
|
+
*/
|
|
90
|
+
public async validated(
|
|
91
|
+
token: bigint,
|
|
92
|
+
params?: ReadParams<typeof erc721MintActionAbi, 'validated'>,
|
|
93
|
+
) {
|
|
94
|
+
return readErc721MintActionValidated(this._config, {
|
|
95
|
+
address: this.assertValidAddress(),
|
|
96
|
+
...this.optionallyAttachAccount(),
|
|
97
|
+
// biome-ignore lint/suspicious/noExplicitAny: Accept any shape of valid wagmi/viem parameters, wagmi does the same thing internally
|
|
98
|
+
...(params as any),
|
|
99
|
+
args: [token],
|
|
100
|
+
});
|
|
101
|
+
}
|
|
102
|
+
|
|
103
|
+
/**
|
|
104
|
+
* @inheritdoc
|
|
105
|
+
*
|
|
106
|
+
* @public
|
|
107
|
+
* @async
|
|
108
|
+
* @param {Hex} data
|
|
109
|
+
* @param {?WriteParams<typeof erc721MintActionAbi, 'execute'>} [params]
|
|
110
|
+
* @returns {unknown}
|
|
111
|
+
*/
|
|
112
|
+
public override async execute(
|
|
113
|
+
data: Hex,
|
|
114
|
+
params?: WriteParams<typeof erc721MintActionAbi, 'execute'>,
|
|
115
|
+
) {
|
|
116
|
+
return this.awaitResult(this.executeRaw(data, params));
|
|
117
|
+
}
|
|
118
|
+
|
|
119
|
+
/**
|
|
120
|
+
* @inheritdoc
|
|
121
|
+
*
|
|
122
|
+
* @public
|
|
123
|
+
* @async
|
|
124
|
+
* @param {Hex} data
|
|
125
|
+
* @param {?WriteParams<typeof erc721MintActionAbi, 'execute'>} [params]
|
|
126
|
+
* @returns {unknown}
|
|
127
|
+
*/
|
|
128
|
+
public override async executeRaw(
|
|
129
|
+
data: Hex,
|
|
130
|
+
params?: WriteParams<typeof erc721MintActionAbi, 'execute'>,
|
|
131
|
+
) {
|
|
132
|
+
const { request, result } = await simulateErc721MintActionExecute(
|
|
133
|
+
this._config,
|
|
134
|
+
{
|
|
135
|
+
address: this.assertValidAddress(),
|
|
136
|
+
args: [data],
|
|
137
|
+
...this.optionallyAttachAccount(),
|
|
138
|
+
// biome-ignore lint/suspicious/noExplicitAny: Accept any shape of valid wagmi/viem parameters, wagmi does the same thing internally
|
|
139
|
+
...(params as any),
|
|
140
|
+
},
|
|
141
|
+
);
|
|
142
|
+
const hash = await writeErc721MintActionExecute(this._config, request);
|
|
143
|
+
return { hash, result };
|
|
144
|
+
}
|
|
145
|
+
|
|
146
|
+
/**
|
|
147
|
+
* @inheritdoc
|
|
148
|
+
*
|
|
149
|
+
* @public
|
|
150
|
+
* @async
|
|
151
|
+
* @param {Hex} data
|
|
152
|
+
* @param {?ReadParams<typeof erc721MintActionAbi, 'prepare'>} [params]
|
|
153
|
+
* @returns {unknown}
|
|
154
|
+
*/
|
|
155
|
+
public override async prepare(
|
|
156
|
+
data: Hex,
|
|
157
|
+
params?: ReadParams<typeof erc721MintActionAbi, 'prepare'>,
|
|
158
|
+
) {
|
|
159
|
+
return readErc721MintActionPrepare(this._config, {
|
|
160
|
+
address: this.assertValidAddress(),
|
|
161
|
+
args: [data],
|
|
162
|
+
...this.optionallyAttachAccount(),
|
|
163
|
+
// biome-ignore lint/suspicious/noExplicitAny: Accept any shape of valid wagmi/viem parameters, wagmi does the same thing internally
|
|
164
|
+
...(params as any),
|
|
165
|
+
});
|
|
166
|
+
}
|
|
167
|
+
|
|
168
|
+
/**
|
|
169
|
+
* Validate that the action has been completed successfully
|
|
170
|
+
*
|
|
171
|
+
* @public
|
|
172
|
+
* @async
|
|
173
|
+
* @param {Address} holder - The holder
|
|
174
|
+
* @param {BigInt} tokenId - The token ID
|
|
175
|
+
* @param {?WriteParams<typeof erc721MintActionAbi, 'validate'>} [params]
|
|
176
|
+
* @returns {Promise<{ hash: `0x${string}`; result: boolean; }>} - True if the action has been validated for the user
|
|
177
|
+
*/
|
|
178
|
+
public async validate(
|
|
179
|
+
holder: Address,
|
|
180
|
+
tokenId: bigint,
|
|
181
|
+
params?: WriteParams<typeof erc721MintActionAbi, 'validate'>,
|
|
182
|
+
) {
|
|
183
|
+
return this.awaitResult(this.validateRaw(holder, tokenId, params));
|
|
184
|
+
}
|
|
185
|
+
|
|
186
|
+
/**
|
|
187
|
+
* Validate that the action has been completed successfully
|
|
188
|
+
*
|
|
189
|
+
* @public
|
|
190
|
+
* @async
|
|
191
|
+
* @param {Address} holder - The holder
|
|
192
|
+
* @param {BigInt} tokenId - The token ID
|
|
193
|
+
* @param {?WriteParams<typeof erc721MintActionAbi, 'validate'>} [params]
|
|
194
|
+
* @returns {Promise<{ hash: `0x${string}`; result: boolean; }>} - True if the action has been validated for the user
|
|
195
|
+
*/
|
|
196
|
+
public async validateRaw(
|
|
197
|
+
holder: Address,
|
|
198
|
+
tokenId: bigint,
|
|
199
|
+
params?: WriteParams<typeof erc721MintActionAbi, 'validate'>,
|
|
200
|
+
) {
|
|
201
|
+
const { request, result } = await simulateErc721MintActionValidate(
|
|
202
|
+
this._config,
|
|
203
|
+
{
|
|
204
|
+
address: this.assertValidAddress(),
|
|
205
|
+
args: [prepareERC721MintActionValidate(holder, tokenId)],
|
|
206
|
+
...this.optionallyAttachAccount(),
|
|
207
|
+
// biome-ignore lint/suspicious/noExplicitAny: Accept any shape of valid wagmi/viem parameters, wagmi does the same thing internally
|
|
208
|
+
...(params as any),
|
|
209
|
+
},
|
|
210
|
+
);
|
|
211
|
+
const hash = await writeErc721MintActionValidate(this._config, request);
|
|
212
|
+
return { hash, result };
|
|
213
|
+
}
|
|
214
|
+
|
|
215
|
+
/**
|
|
216
|
+
* @inheritdoc
|
|
217
|
+
*
|
|
218
|
+
* @public
|
|
219
|
+
* @param {?ERC721MintActionPayload} [_payload]
|
|
220
|
+
* @param {?DeployableOptions} [_options]
|
|
221
|
+
* @returns {GenericDeployableParams}
|
|
222
|
+
*/
|
|
223
|
+
public override buildParameters(
|
|
224
|
+
_payload?: ERC721MintActionPayload,
|
|
225
|
+
_options?: DeployableOptions,
|
|
226
|
+
): GenericDeployableParams {
|
|
227
|
+
const [payload, options] = this.validateDeploymentConfig(
|
|
228
|
+
_payload,
|
|
229
|
+
_options,
|
|
230
|
+
);
|
|
231
|
+
return {
|
|
232
|
+
abi: erc721MintActionAbi,
|
|
233
|
+
bytecode: bytecode as Hex,
|
|
234
|
+
args: [prepareERC721MintActionPayload(payload)],
|
|
235
|
+
...this.optionallyAttachAccount(options.account),
|
|
236
|
+
};
|
|
237
|
+
}
|
|
238
|
+
}
|
|
@@ -0,0 +1,182 @@
|
|
|
1
|
+
import {
|
|
2
|
+
readAActionGetComponentInterface,
|
|
3
|
+
readEventActionGetComponentInterface,
|
|
4
|
+
} from '@boostxyz/evm';
|
|
5
|
+
import { selectors } from '@boostxyz/signatures/events';
|
|
6
|
+
import { loadFixture } from '@nomicfoundation/hardhat-network-helpers';
|
|
7
|
+
import { type Hex, type Log, isAddress } from 'viem';
|
|
8
|
+
import { beforeAll, beforeEach, describe, expect, test } from 'vitest';
|
|
9
|
+
import type { MockERC721 } from '../../test/MockERC721';
|
|
10
|
+
import { accounts } from '../../test/accounts';
|
|
11
|
+
import {
|
|
12
|
+
type Fixtures,
|
|
13
|
+
defaultOptions,
|
|
14
|
+
deployFixtures,
|
|
15
|
+
fundErc721,
|
|
16
|
+
} from '../../test/helpers';
|
|
17
|
+
import {
|
|
18
|
+
type EventActionPayloadSimple,
|
|
19
|
+
FilterType,
|
|
20
|
+
PrimitiveType,
|
|
21
|
+
SignatureType,
|
|
22
|
+
} from '../utils';
|
|
23
|
+
import { EventAction } from './EventAction';
|
|
24
|
+
|
|
25
|
+
let fixtures: Fixtures, erc721: MockERC721;
|
|
26
|
+
|
|
27
|
+
beforeAll(async () => {
|
|
28
|
+
fixtures = await loadFixture(deployFixtures);
|
|
29
|
+
});
|
|
30
|
+
|
|
31
|
+
function basicErc721TransferAction(
|
|
32
|
+
erc721: MockERC721,
|
|
33
|
+
): EventActionPayloadSimple {
|
|
34
|
+
return {
|
|
35
|
+
actionClaimant: {
|
|
36
|
+
signatureType: SignatureType.EVENT,
|
|
37
|
+
signature: selectors['Transfer(address,address,uint256)'] as Hex,
|
|
38
|
+
fieldIndex: 2,
|
|
39
|
+
targetContract: erc721.assertValidAddress(),
|
|
40
|
+
},
|
|
41
|
+
actionSteps: [
|
|
42
|
+
{
|
|
43
|
+
signature: selectors['Transfer(address,address,uint256)'] as Hex,
|
|
44
|
+
signatureType: SignatureType.EVENT,
|
|
45
|
+
actionType: 0,
|
|
46
|
+
targetContract: erc721.assertValidAddress(),
|
|
47
|
+
actionParameter: {
|
|
48
|
+
filterType: FilterType.EQUAL,
|
|
49
|
+
fieldType: PrimitiveType.ADDRESS,
|
|
50
|
+
fieldIndex: 2,
|
|
51
|
+
filterData: accounts.at(1)!.account,
|
|
52
|
+
},
|
|
53
|
+
},
|
|
54
|
+
],
|
|
55
|
+
};
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
function cloneEventAction(fixtures: Fixtures, erc721: MockERC721) {
|
|
59
|
+
return function cloneEventAction() {
|
|
60
|
+
return fixtures.registry.clone(
|
|
61
|
+
crypto.randomUUID(),
|
|
62
|
+
new fixtures.bases.EventAction(
|
|
63
|
+
defaultOptions,
|
|
64
|
+
basicErc721TransferAction(erc721),
|
|
65
|
+
),
|
|
66
|
+
);
|
|
67
|
+
};
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
describe('EventAction', () => {
|
|
71
|
+
beforeEach(async () => {
|
|
72
|
+
erc721 = await loadFixture(fundErc721(defaultOptions));
|
|
73
|
+
});
|
|
74
|
+
|
|
75
|
+
test('can successfully be deployed', async () => {
|
|
76
|
+
const action = new EventAction(
|
|
77
|
+
defaultOptions,
|
|
78
|
+
basicErc721TransferAction(erc721),
|
|
79
|
+
);
|
|
80
|
+
await action.deploy();
|
|
81
|
+
expect(isAddress(action.assertValidAddress())).toBe(true);
|
|
82
|
+
});
|
|
83
|
+
|
|
84
|
+
test('can get an action step', async () => {
|
|
85
|
+
const action = await loadFixture(cloneEventAction(fixtures, erc721));
|
|
86
|
+
const step = await action.getActionStep(0);
|
|
87
|
+
if (!step) throw new Error('there should be an action step at this index');
|
|
88
|
+
step.targetContract = step.targetContract.toUpperCase() as Hex;
|
|
89
|
+
step.actionParameter.filterData =
|
|
90
|
+
step.actionParameter.filterData.toUpperCase() as Hex;
|
|
91
|
+
expect(step).toMatchObject({
|
|
92
|
+
signature: selectors['Transfer(address,address,uint256)'] as Hex,
|
|
93
|
+
signatureType: SignatureType.EVENT,
|
|
94
|
+
actionType: 0,
|
|
95
|
+
targetContract: erc721.assertValidAddress().toUpperCase(),
|
|
96
|
+
actionParameter: {
|
|
97
|
+
filterType: FilterType.EQUAL,
|
|
98
|
+
fieldType: PrimitiveType.ADDRESS,
|
|
99
|
+
fieldIndex: 2,
|
|
100
|
+
filterData: accounts.at(1)!.account.toUpperCase(),
|
|
101
|
+
},
|
|
102
|
+
});
|
|
103
|
+
});
|
|
104
|
+
|
|
105
|
+
test('can get all action steps', async () => {
|
|
106
|
+
const action = await loadFixture(cloneEventAction(fixtures, erc721));
|
|
107
|
+
const steps = await action.getActionSteps();
|
|
108
|
+
expect(steps.length).toBe(1);
|
|
109
|
+
const step = steps.at(0)!;
|
|
110
|
+
step.targetContract = step.targetContract.toUpperCase() as Hex;
|
|
111
|
+
step.actionParameter.filterData =
|
|
112
|
+
step.actionParameter.filterData.toUpperCase() as Hex;
|
|
113
|
+
expect(step).toMatchObject({
|
|
114
|
+
signature: selectors['Transfer(address,address,uint256)'] as Hex,
|
|
115
|
+
signatureType: SignatureType.EVENT,
|
|
116
|
+
actionType: 0,
|
|
117
|
+
targetContract: erc721.assertValidAddress().toUpperCase(),
|
|
118
|
+
actionParameter: {
|
|
119
|
+
filterType: FilterType.EQUAL,
|
|
120
|
+
fieldType: PrimitiveType.ADDRESS,
|
|
121
|
+
fieldIndex: 2,
|
|
122
|
+
filterData: accounts.at(1)!.account.toUpperCase(),
|
|
123
|
+
},
|
|
124
|
+
});
|
|
125
|
+
});
|
|
126
|
+
|
|
127
|
+
test('can get the total number of action steps', async () => {
|
|
128
|
+
const action = await loadFixture(cloneEventAction(fixtures, erc721));
|
|
129
|
+
const count = await action.getActionStepsCount();
|
|
130
|
+
expect(count).toBe(1);
|
|
131
|
+
});
|
|
132
|
+
|
|
133
|
+
test('can get the action claimant', async () => {
|
|
134
|
+
const action = await loadFixture(cloneEventAction(fixtures, erc721));
|
|
135
|
+
const claimant = await action.getActionClaimant();
|
|
136
|
+
claimant.targetContract = claimant.targetContract.toUpperCase() as Hex;
|
|
137
|
+
expect(claimant).toMatchObject({
|
|
138
|
+
signatureType: SignatureType.EVENT,
|
|
139
|
+
signature: selectors['Transfer(address,address,uint256)'] as Hex,
|
|
140
|
+
fieldIndex: 2,
|
|
141
|
+
targetContract: erc721.assertValidAddress().toUpperCase(),
|
|
142
|
+
});
|
|
143
|
+
});
|
|
144
|
+
|
|
145
|
+
test('with no logs, does not validate', async () => {
|
|
146
|
+
const action = await loadFixture(cloneEventAction(fixtures, erc721));
|
|
147
|
+
expect(await action.validateActionSteps()).toBe(false);
|
|
148
|
+
});
|
|
149
|
+
|
|
150
|
+
test('with a correct log, validates', async () => {
|
|
151
|
+
const action = await loadFixture(cloneEventAction(fixtures, erc721));
|
|
152
|
+
const recipient = accounts.at(1)!.account;
|
|
153
|
+
await erc721.approve(recipient, 1n);
|
|
154
|
+
await erc721.transferFrom(defaultOptions.account.address, recipient, 1n);
|
|
155
|
+
expect(await action.validateActionSteps()).toBe(true);
|
|
156
|
+
});
|
|
157
|
+
|
|
158
|
+
test('can supply your own logs to validate against', async () => {
|
|
159
|
+
const log = {
|
|
160
|
+
eventName: 'Transfer',
|
|
161
|
+
args: undefined,
|
|
162
|
+
address: erc721.assertValidAddress(),
|
|
163
|
+
blockHash:
|
|
164
|
+
'0xbf602f988260519805d032be46d6ff97fbefbee6924b21097074d6d0bc34eced',
|
|
165
|
+
blockNumber: 1203n,
|
|
166
|
+
data: '0x',
|
|
167
|
+
logIndex: 0,
|
|
168
|
+
removed: false,
|
|
169
|
+
topics: [
|
|
170
|
+
'0xddf252ad1be2c89b69c2b068fc378daa952ba7f163c4a11628f55a4df523b3ef',
|
|
171
|
+
'0x000000000000000000000000f39fd6e51aad88f6f4ce6ab8827279cfffb92266',
|
|
172
|
+
'0x00000000000000000000000070997970c51812dc3a010c7d01b50e0d17dc79c8',
|
|
173
|
+
'0x0000000000000000000000000000000000000000000000000000000000000001',
|
|
174
|
+
],
|
|
175
|
+
transactionHash:
|
|
176
|
+
'0xff0e6ab0c4961ec14b7b40afec83ed7d7a77582683512a262e641d21f82efea5',
|
|
177
|
+
transactionIndex: 0,
|
|
178
|
+
} as Log;
|
|
179
|
+
const action = await loadFixture(cloneEventAction(fixtures, erc721));
|
|
180
|
+
expect(await action.validateActionSteps({ logs: [log] })).toBe(true);
|
|
181
|
+
});
|
|
182
|
+
});
|