@boostxyz/sdk 0.0.0-alpha.10
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/LICENSE +674 -0
- package/README.md +7 -0
- package/dist/Actions/Action.cjs +2 -0
- package/dist/Actions/Action.cjs.map +1 -0
- package/dist/Actions/Action.d.ts +31 -0
- package/dist/Actions/Action.d.ts.map +1 -0
- package/dist/Actions/Action.js +29 -0
- package/dist/Actions/Action.js.map +1 -0
- package/dist/Actions/ContractAction.d.ts +370 -0
- package/dist/Actions/ContractAction.d.ts.map +1 -0
- package/dist/Actions/ERC721MintAction.d.ts +513 -0
- package/dist/Actions/ERC721MintAction.d.ts.map +1 -0
- package/dist/Actions/EventAction.cjs +2 -0
- package/dist/Actions/EventAction.cjs.map +1 -0
- package/dist/Actions/EventAction.d.ts +694 -0
- package/dist/Actions/EventAction.d.ts.map +1 -0
- package/dist/Actions/EventAction.js +491 -0
- package/dist/Actions/EventAction.js.map +1 -0
- package/dist/AllowLists/AllowList.cjs +2 -0
- package/dist/AllowLists/AllowList.cjs.map +1 -0
- package/dist/AllowLists/AllowList.d.ts +32 -0
- package/dist/AllowLists/AllowList.d.ts.map +1 -0
- package/dist/AllowLists/AllowList.js +30 -0
- package/dist/AllowLists/AllowList.js.map +1 -0
- package/dist/AllowLists/SimpleAllowList.cjs +2 -0
- package/dist/AllowLists/SimpleAllowList.cjs.map +1 -0
- package/dist/AllowLists/SimpleAllowList.d.ts +481 -0
- package/dist/AllowLists/SimpleAllowList.d.ts.map +1 -0
- package/dist/AllowLists/SimpleAllowList.js +154 -0
- package/dist/AllowLists/SimpleAllowList.js.map +1 -0
- package/dist/AllowLists/SimpleDenyList.cjs +2 -0
- package/dist/AllowLists/SimpleDenyList.cjs.map +1 -0
- package/dist/AllowLists/SimpleDenyList.d.ts +335 -0
- package/dist/AllowLists/SimpleDenyList.d.ts.map +1 -0
- package/dist/AllowLists/SimpleDenyList.js +115 -0
- package/dist/AllowLists/SimpleDenyList.js.map +1 -0
- package/dist/Auth/Auth.cjs +2 -0
- package/dist/Auth/Auth.cjs.map +1 -0
- package/dist/Auth/Auth.d.ts +10 -0
- package/dist/Auth/Auth.d.ts.map +1 -0
- package/dist/Auth/Auth.js +5 -0
- package/dist/Auth/Auth.js.map +1 -0
- package/dist/Auth/PassthroughAuth.cjs +2 -0
- package/dist/Auth/PassthroughAuth.cjs.map +1 -0
- package/dist/Auth/PassthroughAuth.d.ts +51 -0
- package/dist/Auth/PassthroughAuth.d.ts.map +1 -0
- package/dist/Auth/PassthroughAuth.js +39 -0
- package/dist/Auth/PassthroughAuth.js.map +1 -0
- package/dist/Boost.cjs +2 -0
- package/dist/Boost.cjs.map +1 -0
- package/dist/Boost.d.ts +234 -0
- package/dist/Boost.d.ts.map +1 -0
- package/dist/Boost.js +162 -0
- package/dist/Boost.js.map +1 -0
- package/dist/BoostCore.cjs +3 -0
- package/dist/BoostCore.cjs.map +1 -0
- package/dist/BoostCore.d.ts +498 -0
- package/dist/BoostCore.d.ts.map +1 -0
- package/dist/BoostCore.js +1153 -0
- package/dist/BoostCore.js.map +1 -0
- package/dist/BoostRegistry.cjs +2 -0
- package/dist/BoostRegistry.cjs.map +1 -0
- package/dist/BoostRegistry.d.ts +243 -0
- package/dist/BoostRegistry.d.ts.map +1 -0
- package/dist/BoostRegistry.js +262 -0
- package/dist/BoostRegistry.js.map +1 -0
- package/dist/Budgets/Budget.cjs +2 -0
- package/dist/Budgets/Budget.cjs.map +1 -0
- package/dist/Budgets/Budget.d.ts +31 -0
- package/dist/Budgets/Budget.d.ts.map +1 -0
- package/dist/Budgets/Budget.js +29 -0
- package/dist/Budgets/Budget.js.map +1 -0
- package/dist/Budgets/ManagedBudget.cjs +2 -0
- package/dist/Budgets/ManagedBudget.cjs.map +1 -0
- package/dist/Budgets/ManagedBudget.d.ts +1103 -0
- package/dist/Budgets/ManagedBudget.d.ts.map +1 -0
- package/dist/Budgets/ManagedBudget.js +516 -0
- package/dist/Budgets/ManagedBudget.js.map +1 -0
- package/dist/Budgets/SimpleBudget.d.ts +824 -0
- package/dist/Budgets/SimpleBudget.d.ts.map +1 -0
- package/dist/Budgets/VestingBudget.d.ts +778 -0
- package/dist/Budgets/VestingBudget.d.ts.map +1 -0
- package/dist/Deployable/Contract.cjs +2 -0
- package/dist/Deployable/Contract.cjs.map +1 -0
- package/dist/Deployable/Contract.d.ts +125 -0
- package/dist/Deployable/Contract.d.ts.map +1 -0
- package/dist/Deployable/Contract.js +150 -0
- package/dist/Deployable/Contract.js.map +1 -0
- package/dist/Deployable/Deployable.cjs +2 -0
- package/dist/Deployable/Deployable.cjs.map +1 -0
- package/dist/Deployable/Deployable.d.ts +161 -0
- package/dist/Deployable/Deployable.d.ts.map +1 -0
- package/dist/Deployable/Deployable.js +131 -0
- package/dist/Deployable/Deployable.js.map +1 -0
- package/dist/Deployable/DeployableTarget.cjs +2 -0
- package/dist/Deployable/DeployableTarget.cjs.map +1 -0
- package/dist/Deployable/DeployableTarget.d.ts +116 -0
- package/dist/Deployable/DeployableTarget.d.ts.map +1 -0
- package/dist/Deployable/DeployableTarget.js +132 -0
- package/dist/Deployable/DeployableTarget.js.map +1 -0
- package/dist/Incentives/AllowListIncentive.cjs +2 -0
- package/dist/Incentives/AllowListIncentive.cjs.map +1 -0
- package/dist/Incentives/AllowListIncentive.d.ts +513 -0
- package/dist/Incentives/AllowListIncentive.d.ts.map +1 -0
- package/dist/Incentives/AllowListIncentive.js +201 -0
- package/dist/Incentives/AllowListIncentive.js.map +1 -0
- package/dist/Incentives/CGDAIncentive.cjs +2 -0
- package/dist/Incentives/CGDAIncentive.cjs.map +1 -0
- package/dist/Incentives/CGDAIncentive.d.ts +644 -0
- package/dist/Incentives/CGDAIncentive.d.ts.map +1 -0
- package/dist/Incentives/CGDAIncentive.js +271 -0
- package/dist/Incentives/CGDAIncentive.js.map +1 -0
- package/dist/Incentives/ERC1155Incentive.d.ts +713 -0
- package/dist/Incentives/ERC1155Incentive.d.ts.map +1 -0
- package/dist/Incentives/ERC20Incentive.cjs +2 -0
- package/dist/Incentives/ERC20Incentive.cjs.map +1 -0
- package/dist/Incentives/ERC20Incentive.d.ts +666 -0
- package/dist/Incentives/ERC20Incentive.d.ts.map +1 -0
- package/dist/Incentives/ERC20Incentive.js +312 -0
- package/dist/Incentives/ERC20Incentive.js.map +1 -0
- package/dist/Incentives/ERC20VariableIncentive.d.ts +582 -0
- package/dist/Incentives/ERC20VariableIncentive.d.ts.map +1 -0
- package/dist/Incentives/Incentive.cjs +2 -0
- package/dist/Incentives/Incentive.cjs.map +1 -0
- package/dist/Incentives/Incentive.d.ts +36 -0
- package/dist/Incentives/Incentive.d.ts.map +1 -0
- package/dist/Incentives/Incentive.js +299 -0
- package/dist/Incentives/Incentive.js.map +1 -0
- package/dist/Incentives/PointsIncentive.cjs +2 -0
- package/dist/Incentives/PointsIncentive.cjs.map +1 -0
- package/dist/Incentives/PointsIncentive.d.ts +659 -0
- package/dist/Incentives/PointsIncentive.d.ts.map +1 -0
- package/dist/Incentives/PointsIncentive.js +215 -0
- package/dist/Incentives/PointsIncentive.js.map +1 -0
- package/dist/Validators/SignerValidator.cjs +2 -0
- package/dist/Validators/SignerValidator.cjs.map +1 -0
- package/dist/Validators/SignerValidator.d.ts +745 -0
- package/dist/Validators/SignerValidator.d.ts.map +1 -0
- package/dist/Validators/SignerValidator.js +293 -0
- package/dist/Validators/SignerValidator.js.map +1 -0
- package/dist/Validators/Validator.cjs +2 -0
- package/dist/Validators/Validator.cjs.map +1 -0
- package/dist/Validators/Validator.d.ts +31 -0
- package/dist/Validators/Validator.d.ts.map +1 -0
- package/dist/Validators/Validator.js +27 -0
- package/dist/Validators/Validator.js.map +1 -0
- package/dist/claiming.cjs +2 -0
- package/dist/claiming.cjs.map +1 -0
- package/dist/claiming.d.ts +43 -0
- package/dist/claiming.d.ts.map +1 -0
- package/dist/claiming.js +17 -0
- package/dist/claiming.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 +2 -0
- package/dist/errors.cjs.map +1 -0
- package/dist/errors.d.ts +441 -0
- package/dist/errors.d.ts.map +1 -0
- package/dist/errors.js +262 -0
- package/dist/errors.js.map +1 -0
- package/dist/generated-BDeDiaCK.js +4625 -0
- package/dist/generated-BDeDiaCK.js.map +1 -0
- package/dist/generated-wKBNvm48.cjs +3 -0
- package/dist/generated-wKBNvm48.cjs.map +1 -0
- package/dist/index.cjs +2 -0
- package/dist/index.cjs.map +1 -0
- package/dist/index.d.ts +25 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +113 -0
- package/dist/index.js.map +1 -0
- package/dist/transfers.cjs +2 -0
- package/dist/transfers.cjs.map +1 -0
- package/dist/transfers.d.ts +198 -0
- package/dist/transfers.d.ts.map +1 -0
- package/dist/transfers.js +84 -0
- package/dist/transfers.js.map +1 -0
- package/dist/utils.cjs +2 -0
- package/dist/utils.cjs.map +1 -0
- package/dist/utils.d.ts +116 -0
- package/dist/utils.d.ts.map +1 -0
- package/dist/utils.js +30 -0
- package/dist/utils.js.map +1 -0
- package/package.json +211 -0
- package/src/Actions/Action.test.ts +75 -0
- package/src/Actions/Action.ts +61 -0
- package/src/Actions/ContractAction.test.ts +197 -0
- package/src/Actions/ContractAction.ts +301 -0
- package/src/Actions/ERC721MintAction.test.ts +112 -0
- package/src/Actions/ERC721MintAction.ts +292 -0
- package/src/Actions/EventAction.test.ts +205 -0
- package/src/Actions/EventAction.ts +811 -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 +284 -0
- package/src/AllowLists/SimpleDenyList.test.ts +52 -0
- package/src/AllowLists/SimpleDenyList.ts +227 -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 +290 -0
- package/src/BoostCore.test.ts +773 -0
- package/src/BoostCore.ts +1261 -0
- package/src/BoostRegistry.ts +467 -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 +796 -0
- package/src/Budgets/SimpleBudget.test.ts +152 -0
- package/src/Budgets/SimpleBudget.ts +564 -0
- package/src/Budgets/VestingBudget.test.ts +123 -0
- package/src/Budgets/VestingBudget.ts +602 -0
- package/src/Deployable/Contract.ts +229 -0
- package/src/Deployable/Deployable.ts +250 -0
- package/src/Deployable/DeployableTarget.ts +223 -0
- package/src/Incentives/AllowListIncentive.test.ts +143 -0
- package/src/Incentives/AllowListIncentive.ts +334 -0
- package/src/Incentives/CGDAIncentive.test.ts +132 -0
- package/src/Incentives/CGDAIncentive.ts +468 -0
- package/src/Incentives/ERC1155Incentive.test.ts +87 -0
- package/src/Incentives/ERC1155Incentive.ts +466 -0
- package/src/Incentives/ERC20Incentive.test.ts +130 -0
- package/src/Incentives/ERC20Incentive.ts +482 -0
- package/src/Incentives/ERC20VariableIncentive.test.ts +136 -0
- package/src/Incentives/ERC20VariableIncentive.ts +420 -0
- package/src/Incentives/Incentive.test.ts +92 -0
- package/src/Incentives/Incentive.ts +85 -0
- package/src/Incentives/PointsIncentive.test.ts +139 -0
- package/src/Incentives/PointsIncentive.ts +365 -0
- package/src/Validators/SignerValidator.test.ts +159 -0
- package/src/Validators/SignerValidator.ts +681 -0
- package/src/Validators/Validator.test.ts +21 -0
- package/src/Validators/Validator.ts +55 -0
- package/src/claiming.ts +56 -0
- package/src/errors.ts +542 -0
- package/src/index.test.ts +40 -0
- package/src/index.ts +53 -0
- package/src/transfers.ts +284 -0
- package/src/utils.test.ts +44 -0
- package/src/utils.ts +198 -0
package/src/index.ts
ADDED
|
@@ -0,0 +1,53 @@
|
|
|
1
|
+
export * from './BoostRegistry';
|
|
2
|
+
export * from './BoostCore';
|
|
3
|
+
export * from './Boost';
|
|
4
|
+
|
|
5
|
+
// Actions
|
|
6
|
+
|
|
7
|
+
export * from './Actions/Action';
|
|
8
|
+
// export * from './Actions/ContractAction';
|
|
9
|
+
// export * from './Actions/ERC721MintAction';
|
|
10
|
+
export * from './Actions/EventAction';
|
|
11
|
+
|
|
12
|
+
// AllowLists
|
|
13
|
+
|
|
14
|
+
export * from './AllowLists/AllowList';
|
|
15
|
+
export * from './AllowLists/SimpleAllowList';
|
|
16
|
+
export * from './AllowLists/SimpleDenyList';
|
|
17
|
+
|
|
18
|
+
// Budgets
|
|
19
|
+
|
|
20
|
+
export * from './Budgets/Budget';
|
|
21
|
+
// export * from './Budgets/SimpleBudget';
|
|
22
|
+
// export * from './Budgets/VestingBudget';
|
|
23
|
+
export * from './Budgets/ManagedBudget';
|
|
24
|
+
|
|
25
|
+
// Deployable
|
|
26
|
+
|
|
27
|
+
export * from './Deployable/Deployable';
|
|
28
|
+
export * from './Deployable/Contract';
|
|
29
|
+
export * from './Deployable/DeployableTarget';
|
|
30
|
+
|
|
31
|
+
// Incentives
|
|
32
|
+
|
|
33
|
+
export * from './Incentives/AllowListIncentive';
|
|
34
|
+
export * from './Incentives/CGDAIncentive';
|
|
35
|
+
export * from './Incentives/ERC20Incentive';
|
|
36
|
+
// export * from './Incentives/ERC1155Incentive';
|
|
37
|
+
export * from './Incentives/Incentive';
|
|
38
|
+
export * from './Incentives/PointsIncentive';
|
|
39
|
+
|
|
40
|
+
// Validators
|
|
41
|
+
|
|
42
|
+
export * from './Validators/SignerValidator';
|
|
43
|
+
export * from './Validators/Validator';
|
|
44
|
+
|
|
45
|
+
// Extra
|
|
46
|
+
|
|
47
|
+
export * from './errors';
|
|
48
|
+
export * from './utils';
|
|
49
|
+
|
|
50
|
+
// Auth
|
|
51
|
+
|
|
52
|
+
export * from './Auth/Auth';
|
|
53
|
+
export * from './Auth/PassthroughAuth';
|
package/src/transfers.ts
ADDED
|
@@ -0,0 +1,284 @@
|
|
|
1
|
+
import {
|
|
2
|
+
type Address,
|
|
3
|
+
type Hex,
|
|
4
|
+
encodeAbiParameters,
|
|
5
|
+
parseAbiParameters,
|
|
6
|
+
zeroAddress,
|
|
7
|
+
} from 'viem';
|
|
8
|
+
|
|
9
|
+
/**
|
|
10
|
+
* The various types of assets supported in Budgets and Incentives.
|
|
11
|
+
*
|
|
12
|
+
* @export
|
|
13
|
+
* @enum {number}
|
|
14
|
+
*/
|
|
15
|
+
export enum AssetType {
|
|
16
|
+
ETH,
|
|
17
|
+
ERC20,
|
|
18
|
+
ERC1155,
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
/**
|
|
22
|
+
* Object representation of a generic `Transfer` struct.
|
|
23
|
+
*
|
|
24
|
+
* @export
|
|
25
|
+
* @interface TransferPayload
|
|
26
|
+
* @typedef {TransferPayload}
|
|
27
|
+
*/
|
|
28
|
+
export interface TransferPayload {
|
|
29
|
+
/**
|
|
30
|
+
* The type of the asset being transferred.
|
|
31
|
+
*
|
|
32
|
+
* @type {AssetType}
|
|
33
|
+
*/
|
|
34
|
+
assetType: AssetType;
|
|
35
|
+
/**
|
|
36
|
+
* The address of the asset to transfer, zero address for ETH.
|
|
37
|
+
*
|
|
38
|
+
* @type {Address}
|
|
39
|
+
*/
|
|
40
|
+
address: Address;
|
|
41
|
+
/**
|
|
42
|
+
* The account from which to transfer the assets.
|
|
43
|
+
*
|
|
44
|
+
* @type {Address}
|
|
45
|
+
*/
|
|
46
|
+
target: Address;
|
|
47
|
+
/**
|
|
48
|
+
* An encoded {@link FungiblePayload}, use {@link prepareFungiblePayload} to construct.
|
|
49
|
+
*
|
|
50
|
+
* @type {Hex}
|
|
51
|
+
*/
|
|
52
|
+
data: Hex;
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
/**
|
|
56
|
+
* Encodes parameters for transferring the transfer of Fungible and ERC1155 assets, used for {@link Budget} operations.
|
|
57
|
+
* Typically you'd use {@link prepareFungibleTransfer} or {@link prepareERC1155Transfer}
|
|
58
|
+
*
|
|
59
|
+
* @param {TransferPayload} param0
|
|
60
|
+
* @param {AssetType} param0.assetType - The asset type being transferred.
|
|
61
|
+
* @param {Address} param0.address - The address of the asset, use zero address for ETH transfers.
|
|
62
|
+
* @param {Address} param0.target - The address of the account being transferred from
|
|
63
|
+
* @param {Hex} param0.data - Use {@link prepareFungiblePayload} to properly encode an amount to transfer
|
|
64
|
+
* @returns {Hex}
|
|
65
|
+
*/
|
|
66
|
+
export const prepareTransferPayload = ({
|
|
67
|
+
assetType,
|
|
68
|
+
address,
|
|
69
|
+
target,
|
|
70
|
+
data,
|
|
71
|
+
}: TransferPayload) => {
|
|
72
|
+
return encodeAbiParameters(
|
|
73
|
+
[
|
|
74
|
+
{ type: 'uint8', name: 'assetType' },
|
|
75
|
+
{ type: 'address', name: 'asset' },
|
|
76
|
+
{ type: 'address', name: 'target' },
|
|
77
|
+
{ type: 'bytes', name: 'data' },
|
|
78
|
+
],
|
|
79
|
+
[assetType, address, target, data],
|
|
80
|
+
);
|
|
81
|
+
};
|
|
82
|
+
|
|
83
|
+
/**
|
|
84
|
+
* Object representation of
|
|
85
|
+
*
|
|
86
|
+
* @export
|
|
87
|
+
* @interface ERC1155Payload
|
|
88
|
+
* @typedef {ERC1155Payload}
|
|
89
|
+
*/
|
|
90
|
+
export interface ERC1155Payload {
|
|
91
|
+
/**
|
|
92
|
+
* The ERC1155 token ID for the incentive
|
|
93
|
+
*
|
|
94
|
+
* @type {bigint}
|
|
95
|
+
*/
|
|
96
|
+
tokenId: bigint;
|
|
97
|
+
/**
|
|
98
|
+
* The amount to transfer
|
|
99
|
+
*
|
|
100
|
+
* @type {bigint}
|
|
101
|
+
*/
|
|
102
|
+
amount: bigint;
|
|
103
|
+
}
|
|
104
|
+
|
|
105
|
+
/**
|
|
106
|
+
* Given a token ID and amount, properly encode a `ERC1155Incentive.ERC1155Payload` for use with {@link ERC1155Incentive} initialization.
|
|
107
|
+
*
|
|
108
|
+
* @export
|
|
109
|
+
* @param {ERC1155Payload} param0
|
|
110
|
+
* @param {bigint} param0.tokenId - The ERC1155 token ID for the incentive
|
|
111
|
+
* @param {bigint} param0.amount - The amount to transfer
|
|
112
|
+
* @returns {Hex}
|
|
113
|
+
*/
|
|
114
|
+
export function prepareERC1155Payload({ tokenId, amount }: ERC1155Payload) {
|
|
115
|
+
return encodeAbiParameters(
|
|
116
|
+
parseAbiParameters([
|
|
117
|
+
'ERC1155Payload payload',
|
|
118
|
+
'struct ERC1155Payload { uint256 tokenId; uint256 amount; bytes data; }',
|
|
119
|
+
]),
|
|
120
|
+
[{ tokenId, amount, data: '0x' }],
|
|
121
|
+
);
|
|
122
|
+
}
|
|
123
|
+
|
|
124
|
+
/**
|
|
125
|
+
* An object representation of the `Budget.Transfer` contract struct for transfers of ERC1155 assets.
|
|
126
|
+
*
|
|
127
|
+
* @export
|
|
128
|
+
* @interface ERC1155TransferPayload
|
|
129
|
+
* @typedef {ERC1155TransferPayload}
|
|
130
|
+
*/
|
|
131
|
+
export interface ERC1155TransferPayload {
|
|
132
|
+
/**
|
|
133
|
+
* The token ID to transfer
|
|
134
|
+
*
|
|
135
|
+
* @type {bigint}
|
|
136
|
+
*/
|
|
137
|
+
tokenId: bigint;
|
|
138
|
+
/**
|
|
139
|
+
* The amount to transfer
|
|
140
|
+
*
|
|
141
|
+
* @type {bigint}
|
|
142
|
+
*/
|
|
143
|
+
amount: bigint;
|
|
144
|
+
/**
|
|
145
|
+
* The address of the asset to target
|
|
146
|
+
*
|
|
147
|
+
* @type {Address}
|
|
148
|
+
*/
|
|
149
|
+
asset: Address;
|
|
150
|
+
/**
|
|
151
|
+
* The account to transfer from
|
|
152
|
+
*
|
|
153
|
+
* @type {Address}
|
|
154
|
+
*/
|
|
155
|
+
target: Address;
|
|
156
|
+
}
|
|
157
|
+
|
|
158
|
+
/**
|
|
159
|
+
* Encodes parameters for transferring the transfer of ERC1155 assets, used for {@link Budget} operations.
|
|
160
|
+
* The caller must have already approved the contract to transfer the asset.
|
|
161
|
+
*
|
|
162
|
+
* @export
|
|
163
|
+
* @param {ERC1155TransferPayload} param0
|
|
164
|
+
* @param {bigint} param0.tokenId - The token ID to transfer
|
|
165
|
+
* @param {bigint} param0.amount - The amount to transfer
|
|
166
|
+
* @param {Address} param0.asset - The address of the asset to target
|
|
167
|
+
* @param {Address} param0.target - The account to transfer from
|
|
168
|
+
* @returns {Hex}
|
|
169
|
+
*/
|
|
170
|
+
export function prepareERC1155Transfer({
|
|
171
|
+
tokenId,
|
|
172
|
+
amount,
|
|
173
|
+
asset,
|
|
174
|
+
target,
|
|
175
|
+
}: ERC1155TransferPayload) {
|
|
176
|
+
return encodeAbiParameters(
|
|
177
|
+
parseAbiParameters([
|
|
178
|
+
'Transfer request',
|
|
179
|
+
'struct Transfer { uint8 assetType; address asset; address target; bytes data; }',
|
|
180
|
+
]),
|
|
181
|
+
[
|
|
182
|
+
{
|
|
183
|
+
assetType: AssetType.ERC1155,
|
|
184
|
+
asset,
|
|
185
|
+
data: prepareERC1155Payload({ tokenId, amount }),
|
|
186
|
+
target,
|
|
187
|
+
},
|
|
188
|
+
],
|
|
189
|
+
);
|
|
190
|
+
}
|
|
191
|
+
|
|
192
|
+
/**
|
|
193
|
+
* An object representation of the `FungiblePayload` struct
|
|
194
|
+
*
|
|
195
|
+
* @export
|
|
196
|
+
* @interface FungiblePayload
|
|
197
|
+
* @typedef {FungiblePayload}
|
|
198
|
+
*/
|
|
199
|
+
export interface FungiblePayload {
|
|
200
|
+
/**
|
|
201
|
+
* The amount being transferred
|
|
202
|
+
*
|
|
203
|
+
* @type {bigint}
|
|
204
|
+
*/
|
|
205
|
+
amount: bigint;
|
|
206
|
+
}
|
|
207
|
+
|
|
208
|
+
/**
|
|
209
|
+
* Encodes an amount for the `FungiblePayload` struct
|
|
210
|
+
*
|
|
211
|
+
* @export
|
|
212
|
+
* @param {FungiblePayload} param0
|
|
213
|
+
* @param {bigint} param0.amount - The amount being transferred
|
|
214
|
+
* @returns {*}
|
|
215
|
+
*/
|
|
216
|
+
export function prepareFungiblePayload({ amount }: FungiblePayload) {
|
|
217
|
+
return encodeAbiParameters(
|
|
218
|
+
parseAbiParameters([
|
|
219
|
+
'FungiblePayload payload',
|
|
220
|
+
'struct FungiblePayload { uint256 amount; }',
|
|
221
|
+
]),
|
|
222
|
+
[{ amount }],
|
|
223
|
+
);
|
|
224
|
+
}
|
|
225
|
+
|
|
226
|
+
/**
|
|
227
|
+
* An object representation of the `Budget.Transfer` contract struct for transfers of fungible assets.
|
|
228
|
+
*
|
|
229
|
+
* @export
|
|
230
|
+
* @interface FungibleTransferPayload
|
|
231
|
+
* @typedef {FungibleTransferPayload}
|
|
232
|
+
*/
|
|
233
|
+
export interface FungibleTransferPayload {
|
|
234
|
+
/**
|
|
235
|
+
* The amount to transfer
|
|
236
|
+
*
|
|
237
|
+
* @type {bigint}
|
|
238
|
+
*/
|
|
239
|
+
amount: bigint;
|
|
240
|
+
/**
|
|
241
|
+
* The address of the asset. Use zero address for ETH transfers.
|
|
242
|
+
*
|
|
243
|
+
* @type {Address}
|
|
244
|
+
*/
|
|
245
|
+
asset: Address;
|
|
246
|
+
/**
|
|
247
|
+
* The account to transfer from
|
|
248
|
+
*
|
|
249
|
+
* @type {Address}
|
|
250
|
+
*/
|
|
251
|
+
target: Address;
|
|
252
|
+
}
|
|
253
|
+
|
|
254
|
+
/**
|
|
255
|
+
* Encodes parameters for a Fungible transfer, used for Budget allocations.
|
|
256
|
+
* The caller must have already approved the contract to transfer the asset.
|
|
257
|
+
*
|
|
258
|
+
* @export
|
|
259
|
+
* @param {FungibleTransferPayload} param0
|
|
260
|
+
* @param {bigint} param0.amount - The amount to transfer
|
|
261
|
+
* @param {Address} param0.asset - The address of the asset. Use zero address for ETH transfers.
|
|
262
|
+
* @param {Address} param0.target - The account to transfer from
|
|
263
|
+
* @returns {Hex}
|
|
264
|
+
*/
|
|
265
|
+
export function prepareFungibleTransfer({
|
|
266
|
+
amount,
|
|
267
|
+
asset,
|
|
268
|
+
target,
|
|
269
|
+
}: FungibleTransferPayload) {
|
|
270
|
+
return encodeAbiParameters(
|
|
271
|
+
parseAbiParameters([
|
|
272
|
+
'Transfer request',
|
|
273
|
+
'struct Transfer { uint8 assetType; address asset; address target; bytes data; }',
|
|
274
|
+
]),
|
|
275
|
+
[
|
|
276
|
+
{
|
|
277
|
+
assetType: asset == zeroAddress ? AssetType.ETH : AssetType.ERC20,
|
|
278
|
+
asset,
|
|
279
|
+
data: prepareFungiblePayload({ amount }),
|
|
280
|
+
target,
|
|
281
|
+
},
|
|
282
|
+
],
|
|
283
|
+
);
|
|
284
|
+
}
|
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
import { simulateMockErc20Mint, writeMockErc20Mint } from '@boostxyz/evm';
|
|
2
|
+
import { isAddress } from 'viem';
|
|
3
|
+
import { describe, expect, test } from 'vitest';
|
|
4
|
+
import { MockERC20 } from '../test/MockERC20';
|
|
5
|
+
import { defaultOptions } from '../test/helpers';
|
|
6
|
+
import { awaitResult, bytes4, getDeployedContractAddress } from './utils';
|
|
7
|
+
|
|
8
|
+
describe('bytes4', () => {
|
|
9
|
+
test('should return the bytes4 representation of a string', () => {
|
|
10
|
+
expect(bytes4('0xdeadbeef')).toBe('0xd4fd4e18');
|
|
11
|
+
expect(bytes4('deadbeef')).toBe('0x9f24c52e');
|
|
12
|
+
});
|
|
13
|
+
});
|
|
14
|
+
|
|
15
|
+
describe('getDeployedContractAddress', () => {
|
|
16
|
+
test('should return the address of a contract given a tx hash promise', async () => {
|
|
17
|
+
const hash = new MockERC20(defaultOptions, {}).deployRaw();
|
|
18
|
+
expect(
|
|
19
|
+
isAddress(await getDeployedContractAddress(defaultOptions.config, hash)),
|
|
20
|
+
).toBe(true);
|
|
21
|
+
});
|
|
22
|
+
});
|
|
23
|
+
|
|
24
|
+
describe('awaitResult', () => {
|
|
25
|
+
test('should wait for a transaction receipt and return the simulated result', async () => {
|
|
26
|
+
const erc20 = new MockERC20(defaultOptions, {});
|
|
27
|
+
await erc20.deploy();
|
|
28
|
+
const { request, result } = await simulateMockErc20Mint(
|
|
29
|
+
defaultOptions.config,
|
|
30
|
+
{
|
|
31
|
+
address: erc20.assertValidAddress(),
|
|
32
|
+
args: [defaultOptions.account.address, 100n],
|
|
33
|
+
account: defaultOptions.account,
|
|
34
|
+
},
|
|
35
|
+
);
|
|
36
|
+
const hash = await writeMockErc20Mint(defaultOptions.config, request);
|
|
37
|
+
expect(
|
|
38
|
+
await awaitResult(
|
|
39
|
+
defaultOptions.config,
|
|
40
|
+
Promise.resolve({ hash, result }),
|
|
41
|
+
),
|
|
42
|
+
).toBe(undefined);
|
|
43
|
+
});
|
|
44
|
+
});
|
package/src/utils.ts
ADDED
|
@@ -0,0 +1,198 @@
|
|
|
1
|
+
import {
|
|
2
|
+
type Config,
|
|
3
|
+
type ReadContractParameters,
|
|
4
|
+
type WatchContractEventParameters,
|
|
5
|
+
type WriteContractParameters,
|
|
6
|
+
waitForTransactionReceipt,
|
|
7
|
+
} from '@wagmi/core';
|
|
8
|
+
import type { ExtractAbiEvent } from 'abitype';
|
|
9
|
+
import type {
|
|
10
|
+
Abi,
|
|
11
|
+
AbiEvent,
|
|
12
|
+
ContractEventName,
|
|
13
|
+
ContractFunctionName,
|
|
14
|
+
GetLogsParameters,
|
|
15
|
+
Hash,
|
|
16
|
+
Hex,
|
|
17
|
+
Log,
|
|
18
|
+
WaitForTransactionReceiptParameters,
|
|
19
|
+
} from 'viem';
|
|
20
|
+
import { isHex, keccak256, slice, toHex } from 'viem';
|
|
21
|
+
import { NoContractAddressUponReceiptError } from './errors';
|
|
22
|
+
|
|
23
|
+
export type Overwrite<T, U> = Pick<T, Exclude<keyof T, keyof U>> & U;
|
|
24
|
+
|
|
25
|
+
/**
|
|
26
|
+
* Helper type that encapsulates common writeContract parameters without fields like `abi`, `args`, `functionName`, `address` that are expected to be provided the SDK.
|
|
27
|
+
* See (writeContract)[https://viem.sh/docs/contract/writeContract]
|
|
28
|
+
*
|
|
29
|
+
* @export
|
|
30
|
+
* @typedef {WriteParams}
|
|
31
|
+
* @template {Abi} abi
|
|
32
|
+
* @template {ContractFunctionName<abi>} functionName
|
|
33
|
+
*/
|
|
34
|
+
export type WriteParams<
|
|
35
|
+
abi extends Abi,
|
|
36
|
+
functionName extends ContractFunctionName<abi>,
|
|
37
|
+
> = Partial<
|
|
38
|
+
Omit<
|
|
39
|
+
WriteContractParameters<abi, functionName>,
|
|
40
|
+
'address' | 'args' | 'functionName' | 'abi'
|
|
41
|
+
>
|
|
42
|
+
>;
|
|
43
|
+
|
|
44
|
+
/**
|
|
45
|
+
* Helper type that encapsulates common readContract parameters without fields like `abi`, `args`, `functionName`, `address` that are expected to be provided the SDK.
|
|
46
|
+
* See (readContract)[https://viem.sh/docs/contract/readContract]
|
|
47
|
+
*
|
|
48
|
+
* @export
|
|
49
|
+
* @typedef {ReadParams}
|
|
50
|
+
* @template {Abi} abi
|
|
51
|
+
* @template {ContractFunctionName<abi>} functionName
|
|
52
|
+
*/
|
|
53
|
+
export type ReadParams<
|
|
54
|
+
abi extends Abi,
|
|
55
|
+
functionName extends ContractFunctionName<abi>,
|
|
56
|
+
> = Partial<
|
|
57
|
+
Omit<
|
|
58
|
+
ReadContractParameters<abi, functionName>,
|
|
59
|
+
'address' | 'args' | 'functionName' | 'abi'
|
|
60
|
+
>
|
|
61
|
+
>;
|
|
62
|
+
|
|
63
|
+
/**
|
|
64
|
+
* Helper type that encapsulates common `watchContractEvent` parameters without fields like `address`, and `abi` that are expected to be provided the SDK.
|
|
65
|
+
* See (watchContractEvent)[https://wagmi.sh/core/api/actions/watchContractEvent]
|
|
66
|
+
*
|
|
67
|
+
* @export
|
|
68
|
+
* @typedef {WatchParams}
|
|
69
|
+
* @template {Abi} abi
|
|
70
|
+
* @template {ContractEventName<abi> | undefined} [eventName=undefined]
|
|
71
|
+
*/
|
|
72
|
+
export type WatchParams<
|
|
73
|
+
abi extends Abi,
|
|
74
|
+
eventName extends ContractEventName<abi> | undefined = undefined,
|
|
75
|
+
> = Partial<
|
|
76
|
+
Omit<WatchContractEventParameters<abi, eventName>, 'address' | 'abi'>
|
|
77
|
+
>;
|
|
78
|
+
|
|
79
|
+
/**
|
|
80
|
+
* Helper type that encapsulates common `getLogs` parameters without fields like `address` that are expected to be provided the SDK.
|
|
81
|
+
* See (getLogs)[https://viem.sh/docs/actions/public/getLogs#getlogs]
|
|
82
|
+
*
|
|
83
|
+
* @export
|
|
84
|
+
* @typedef {GetLogsParams}
|
|
85
|
+
* @template {Abi} abi
|
|
86
|
+
* @template {ContractEventName<abi>} event
|
|
87
|
+
* @template {ExtractAbiEvent<abi, event>} [abiEvent=ExtractAbiEvent<abi, event>]
|
|
88
|
+
* @template {| readonly AbiEvent[]
|
|
89
|
+
* | readonly unknown[]
|
|
90
|
+
* | undefined} [abiEvents=abiEvent extends AbiEvent ? [abiEvent] : undefined]
|
|
91
|
+
*/
|
|
92
|
+
export type GetLogsParams<
|
|
93
|
+
abi extends Abi,
|
|
94
|
+
event extends ContractEventName<abi>,
|
|
95
|
+
abiEvent extends ExtractAbiEvent<abi, event> = ExtractAbiEvent<abi, event>,
|
|
96
|
+
abiEvents extends
|
|
97
|
+
| readonly AbiEvent[]
|
|
98
|
+
| readonly unknown[]
|
|
99
|
+
| undefined = abiEvent extends AbiEvent ? [abiEvent] : undefined,
|
|
100
|
+
> = Partial<Omit<GetLogsParameters<abiEvent, abiEvents>, 'address'>> & {
|
|
101
|
+
chainId?: number | undefined;
|
|
102
|
+
};
|
|
103
|
+
|
|
104
|
+
/**
|
|
105
|
+
* A generic `viem.Log` event with typed `args` support via a given `Abi` and `ContractEventName`
|
|
106
|
+
*
|
|
107
|
+
* @export
|
|
108
|
+
* @typedef {GenericLog}
|
|
109
|
+
* @template {Abi} abi
|
|
110
|
+
* @template {ContractEventName<abi>} [event=ContractEventName<abi>]
|
|
111
|
+
*/
|
|
112
|
+
export type GenericLog<
|
|
113
|
+
abi extends Abi,
|
|
114
|
+
event extends ContractEventName<abi> = ContractEventName<abi>,
|
|
115
|
+
> = Log<bigint, number, false, ExtractAbiEvent<abi, event>, false>;
|
|
116
|
+
|
|
117
|
+
/**
|
|
118
|
+
* Helper utility to convert a string to a `bytes4` type
|
|
119
|
+
*
|
|
120
|
+
* @export
|
|
121
|
+
* @param {string} input
|
|
122
|
+
* @returns {Hex}
|
|
123
|
+
*/
|
|
124
|
+
export function bytes4(input: string) {
|
|
125
|
+
return slice(isHex(input) ? keccak256(input) : keccak256(toHex(input)), 0, 4);
|
|
126
|
+
}
|
|
127
|
+
|
|
128
|
+
/**
|
|
129
|
+
* Utility function to wait for a transaction receipt, and extract the contractAddress
|
|
130
|
+
*
|
|
131
|
+
* @export
|
|
132
|
+
* @async
|
|
133
|
+
* @param {WagmiConfig} config - [Wagmi Configuration](https://wagmi.sh/core/api/createConfig)
|
|
134
|
+
* @param {Promise<Hash>} hash - A transaction hash promise
|
|
135
|
+
* @param {?Omit<WaitForTransactionReceiptParameters, 'hash'>} [waitParams] - @see {@link WaitForTransactionReceiptParameters}
|
|
136
|
+
* @returns {unknown}
|
|
137
|
+
* @throws {@link NoContractAddressUponReceiptError} if no `contractAddress` exists after the transaction has been received
|
|
138
|
+
*/
|
|
139
|
+
export async function getDeployedContractAddress(
|
|
140
|
+
config: Config,
|
|
141
|
+
hash: Promise<Hash>,
|
|
142
|
+
waitParams?: Omit<WaitForTransactionReceiptParameters, 'hash'>,
|
|
143
|
+
) {
|
|
144
|
+
const receipt = await waitForTransactionReceipt(config, {
|
|
145
|
+
...waitParams,
|
|
146
|
+
hash: await hash,
|
|
147
|
+
});
|
|
148
|
+
if (!receipt.contractAddress)
|
|
149
|
+
throw new NoContractAddressUponReceiptError(receipt);
|
|
150
|
+
return receipt.contractAddress;
|
|
151
|
+
}
|
|
152
|
+
|
|
153
|
+
/**
|
|
154
|
+
* Utility type to encapsulate a transaction hash, and the simulated result prior to submitting the transaction.
|
|
155
|
+
*
|
|
156
|
+
* @export
|
|
157
|
+
* @typedef {HashAndSimulatedResult}
|
|
158
|
+
* @template [T=unknown]
|
|
159
|
+
*/
|
|
160
|
+
export type HashAndSimulatedResult<T = unknown> = { hash: Hash; result: T };
|
|
161
|
+
|
|
162
|
+
/**
|
|
163
|
+
* Helper function to wait for a transaction receipt given a hash promise.
|
|
164
|
+
*
|
|
165
|
+
* @export
|
|
166
|
+
* @async
|
|
167
|
+
* @template [Result=unknown]
|
|
168
|
+
* @param {WagmiConfig} config
|
|
169
|
+
* @param {Promise<HashAndSimulatedResult<Result>>} hashPromise
|
|
170
|
+
* @param {?Omit<WaitForTransactionReceiptParameters, 'hash'>} [waitParams]
|
|
171
|
+
* @returns {Promise<Result>}
|
|
172
|
+
*/
|
|
173
|
+
export async function awaitResult<Result = unknown>(
|
|
174
|
+
config: Config,
|
|
175
|
+
hashPromise: Promise<HashAndSimulatedResult<Result>>,
|
|
176
|
+
waitParams?: Omit<WaitForTransactionReceiptParameters, 'hash'>,
|
|
177
|
+
): Promise<Result> {
|
|
178
|
+
const { hash, result } = await hashPromise;
|
|
179
|
+
await waitForTransactionReceipt(config, {
|
|
180
|
+
...waitParams,
|
|
181
|
+
hash,
|
|
182
|
+
});
|
|
183
|
+
return result;
|
|
184
|
+
}
|
|
185
|
+
|
|
186
|
+
/**
|
|
187
|
+
* Enum encapsulating all the different types of targets used in the Boost V2 Protocol.
|
|
188
|
+
*
|
|
189
|
+
* @export
|
|
190
|
+
* @enum {number}
|
|
191
|
+
*/
|
|
192
|
+
export enum RegistryType {
|
|
193
|
+
ACTION = 0,
|
|
194
|
+
ALLOW_LIST = 1,
|
|
195
|
+
BUDGET = 2,
|
|
196
|
+
INCENTIVE = 3,
|
|
197
|
+
VALIDATOR = 4,
|
|
198
|
+
}
|