@boostxyz/sdk 0.0.0-alpha.2 → 0.0.0-alpha.20
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 +14 -12
- package/dist/Actions/Action.js.map +1 -0
- package/dist/Actions/ContractAction.d.ts +57 -14
- package/dist/Actions/ContractAction.d.ts.map +1 -1
- package/dist/Actions/ERC721MintAction.d.ts +50 -23
- package/dist/Actions/ERC721MintAction.d.ts.map +1 -1
- package/dist/Actions/EventAction.cjs +2 -1
- package/dist/Actions/EventAction.cjs.map +1 -0
- package/dist/Actions/EventAction.d.ts +405 -36
- package/dist/Actions/EventAction.d.ts.map +1 -1
- package/dist/Actions/EventAction.js +15 -209
- 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 +6 -5
- package/dist/AllowLists/AllowList.d.ts.map +1 -1
- package/dist/AllowLists/AllowList.js +46 -22
- package/dist/AllowLists/AllowList.js.map +1 -0
- package/dist/AllowLists/OpenAllowList.d.ts +423 -0
- package/dist/AllowLists/OpenAllowList.d.ts.map +1 -0
- package/dist/AllowLists/SimpleAllowList.cjs +2 -1
- package/dist/AllowLists/SimpleAllowList.cjs.map +1 -0
- package/dist/AllowLists/SimpleAllowList.d.ts +124 -40
- package/dist/AllowLists/SimpleAllowList.d.ts.map +1 -1
- package/dist/AllowLists/SimpleAllowList.js +77 -77
- package/dist/AllowLists/SimpleAllowList.js.map +1 -0
- package/dist/AllowLists/SimpleDenyList.cjs +2 -1
- package/dist/AllowLists/SimpleDenyList.cjs.map +1 -0
- package/dist/AllowLists/SimpleDenyList.d.ts +234 -13
- package/dist/AllowLists/SimpleDenyList.d.ts.map +1 -1
- package/dist/AllowLists/SimpleDenyList.js +12 -200
- 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 +2 -1
- package/dist/Auth/PassthroughAuth.cjs.map +1 -0
- package/dist/Auth/PassthroughAuth.js +5 -4
- package/dist/Auth/PassthroughAuth.js.map +1 -0
- package/dist/Boost.cjs +2 -1
- package/dist/Boost.cjs.map +1 -0
- package/dist/Boost.d.ts +111 -1
- package/dist/Boost.d.ts.map +1 -1
- package/dist/Boost.js +140 -5
- package/dist/Boost.js.map +1 -0
- package/dist/BoostCore-3-U1xTQN.cjs +3 -0
- package/dist/BoostCore-3-U1xTQN.cjs.map +1 -0
- package/dist/BoostCore-DVGBUr2y.js +1477 -0
- package/dist/BoostCore-DVGBUr2y.js.map +1 -0
- package/dist/BoostCore.cjs +2 -2
- package/dist/BoostCore.cjs.map +1 -0
- package/dist/BoostCore.d.ts +166 -43
- package/dist/BoostCore.d.ts.map +1 -1
- package/dist/BoostCore.js +30 -1103
- package/dist/BoostCore.js.map +1 -0
- package/dist/BoostRegistry.cjs +2 -1
- package/dist/BoostRegistry.cjs.map +1 -0
- package/dist/BoostRegistry.d.ts +64 -23
- package/dist/BoostRegistry.d.ts.map +1 -1
- package/dist/BoostRegistry.js +162 -88
- 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 +15 -13
- package/dist/Budgets/Budget.js.map +1 -0
- package/dist/Budgets/ManagedBudget.cjs +2 -1
- package/dist/Budgets/ManagedBudget.cjs.map +1 -0
- package/dist/Budgets/ManagedBudget.d.ts +78 -188
- package/dist/Budgets/ManagedBudget.d.ts.map +1 -1
- package/dist/Budgets/ManagedBudget.js +86 -286
- package/dist/Budgets/ManagedBudget.js.map +1 -0
- package/dist/Budgets/VestingBudget.d.ts +243 -87
- package/dist/Budgets/VestingBudget.d.ts.map +1 -1
- package/dist/Deployable/Contract.cjs +2 -1
- package/dist/Deployable/Contract.cjs.map +1 -0
- package/dist/Deployable/Contract.d.ts +4 -5
- package/dist/Deployable/Contract.d.ts.map +1 -1
- package/dist/Deployable/Contract.js +7 -8
- 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.d.ts +9 -3
- package/dist/Deployable/Deployable.d.ts.map +1 -1
- package/dist/Deployable/Deployable.js +10 -5
- package/dist/Deployable/Deployable.js.map +1 -0
- package/dist/Deployable/DeployableTarget.cjs +2 -1
- package/dist/Deployable/DeployableTarget.cjs.map +1 -0
- package/dist/Deployable/DeployableTarget.d.ts +16 -15
- package/dist/Deployable/DeployableTarget.d.ts.map +1 -1
- package/dist/Deployable/DeployableTarget.js +49 -42
- package/dist/Deployable/DeployableTarget.js.map +1 -0
- package/dist/Deployable/DeployableTargetWithRBAC.cjs +2 -0
- package/dist/Deployable/DeployableTargetWithRBAC.cjs.map +1 -0
- package/dist/Deployable/DeployableTargetWithRBAC.d.ts +179 -0
- package/dist/Deployable/DeployableTargetWithRBAC.d.ts.map +1 -0
- package/dist/Deployable/DeployableTargetWithRBAC.js +222 -0
- package/dist/Deployable/DeployableTargetWithRBAC.js.map +1 -0
- package/dist/EventAction-CIPqmAoP.js +1450 -0
- package/dist/EventAction-CIPqmAoP.js.map +1 -0
- package/dist/EventAction-d-oeqZQs.cjs +2 -0
- package/dist/EventAction-d-oeqZQs.cjs.map +1 -0
- package/dist/Incentive-Bp8Sez7M.js +298 -0
- package/dist/Incentive-Bp8Sez7M.js.map +1 -0
- package/dist/Incentive-Djnzseoj.cjs +2 -0
- package/dist/Incentive-Djnzseoj.cjs.map +1 -0
- package/dist/Incentives/AllowListIncentive.cjs +2 -1
- package/dist/Incentives/AllowListIncentive.cjs.map +1 -0
- package/dist/Incentives/AllowListIncentive.d.ts +49 -19
- package/dist/Incentives/AllowListIncentive.d.ts.map +1 -1
- package/dist/Incentives/AllowListIncentive.js +50 -34
- package/dist/Incentives/AllowListIncentive.js.map +1 -0
- package/dist/Incentives/CGDAIncentive.cjs +2 -1
- package/dist/Incentives/CGDAIncentive.cjs.map +1 -0
- package/dist/Incentives/CGDAIncentive.d.ts +118 -22
- package/dist/Incentives/CGDAIncentive.d.ts.map +1 -1
- package/dist/Incentives/CGDAIncentive.js +67 -42
- package/dist/Incentives/CGDAIncentive.js.map +1 -0
- package/dist/Incentives/ERC1155Incentive.d.ts +99 -38
- package/dist/Incentives/ERC1155Incentive.d.ts.map +1 -1
- package/dist/Incentives/ERC20Incentive.cjs +2 -1
- package/dist/Incentives/ERC20Incentive.cjs.map +1 -0
- package/dist/Incentives/ERC20Incentive.d.ts +73 -29
- package/dist/Incentives/ERC20Incentive.d.ts.map +1 -1
- package/dist/Incentives/ERC20Incentive.js +71 -48
- package/dist/Incentives/ERC20Incentive.js.map +1 -0
- package/dist/Incentives/ERC20VariableCriteriaIncentive.d.ts +523 -0
- package/dist/Incentives/ERC20VariableCriteriaIncentive.d.ts.map +1 -0
- package/dist/Incentives/ERC20VariableIncentive.d.ts +65 -28
- package/dist/Incentives/ERC20VariableIncentive.d.ts.map +1 -1
- package/dist/Incentives/Incentive.cjs +2 -1
- package/dist/Incentives/Incentive.cjs.map +1 -0
- package/dist/Incentives/Incentive.d.ts +4 -7
- package/dist/Incentives/Incentive.d.ts.map +1 -1
- package/dist/Incentives/Incentive.js +17 -278
- package/dist/Incentives/Incentive.js.map +1 -0
- package/dist/Incentives/PointsIncentive.cjs +2 -1
- package/dist/Incentives/PointsIncentive.cjs.map +1 -0
- package/dist/Incentives/PointsIncentive.d.ts +65 -21
- package/dist/Incentives/PointsIncentive.d.ts.map +1 -1
- package/dist/Incentives/PointsIncentive.js +57 -36
- package/dist/Incentives/PointsIncentive.js.map +1 -0
- package/dist/SimpleDenyList-BwfNjRsg.cjs +2 -0
- package/dist/SimpleDenyList-BwfNjRsg.cjs.map +1 -0
- package/dist/SimpleDenyList-Cn5WpNn0.js +132 -0
- package/dist/SimpleDenyList-Cn5WpNn0.js.map +1 -0
- package/dist/Validators/SignerValidator.cjs +2 -1
- package/dist/Validators/SignerValidator.cjs.map +1 -0
- package/dist/Validators/SignerValidator.d.ts +310 -17
- package/dist/Validators/SignerValidator.d.ts.map +1 -1
- package/dist/Validators/SignerValidator.js +165 -36
- 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 +2 -2
- package/dist/Validators/Validator.d.ts.map +1 -1
- package/dist/Validators/Validator.js +12 -10
- 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-D09mhzxO.cjs +2 -0
- package/dist/componentInterfaces-D09mhzxO.cjs.map +1 -0
- package/dist/componentInterfaces-RXBMI5yH.js +14 -0
- package/dist/componentInterfaces-RXBMI5yH.js.map +1 -0
- package/dist/deployments-BM42vImE.js +43 -0
- package/dist/deployments-BM42vImE.js.map +1 -0
- package/dist/deployments-CMdF5uEC.cjs +2 -0
- package/dist/deployments-CMdF5uEC.cjs.map +1 -0
- package/dist/deployments.json +41 -0
- package/dist/errors.cjs +2 -1
- package/dist/errors.cjs.map +1 -0
- package/dist/errors.d.ts +403 -1
- package/dist/errors.d.ts.map +1 -1
- package/dist/errors.js +285 -39
- package/dist/errors.js.map +1 -0
- package/dist/generated-B0tk-c9b.cjs +3 -0
- package/dist/generated-B0tk-c9b.cjs.map +1 -0
- package/dist/{generated-x_abr3Yv.js → generated-B7VaSah4.js} +2058 -2541
- package/dist/generated-B7VaSah4.js.map +1 -0
- package/dist/index.cjs +2 -1
- package/dist/index.cjs.map +1 -0
- package/dist/index.d.ts +10 -9
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +143 -1353
- 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 -1
- package/dist/utils.cjs.map +1 -0
- package/dist/utils.d.ts +26 -1350
- package/dist/utils.d.ts.map +1 -1
- package/dist/utils.js +38 -636
- package/dist/utils.js.map +1 -0
- package/package.json +37 -11
- package/src/Actions/Action.test.ts +79 -0
- package/src/Actions/Action.ts +61 -0
- package/src/Actions/ContractAction.test.ts +197 -0
- package/src/Actions/ContractAction.ts +300 -0
- package/src/Actions/ERC721MintAction.test.ts +112 -0
- package/src/Actions/ERC721MintAction.ts +291 -0
- package/src/Actions/EventAction.test.ts +787 -0
- package/src/Actions/EventAction.ts +1214 -0
- package/src/AllowLists/AllowList.test.ts +64 -0
- package/src/AllowLists/AllowList.ts +62 -0
- package/src/AllowLists/OpenAllowList.test.ts +40 -0
- package/src/AllowLists/OpenAllowList.ts +45 -0
- package/src/AllowLists/SimpleAllowList.test.ts +52 -0
- package/src/AllowLists/SimpleAllowList.ts +262 -0
- package/src/AllowLists/SimpleDenyList.test.ts +52 -0
- package/src/AllowLists/SimpleDenyList.ts +250 -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 +309 -0
- package/src/BoostCore.test.ts +827 -0
- package/src/BoostCore.ts +1447 -0
- package/src/BoostRegistry.ts +543 -0
- package/src/Budgets/Budget.test.ts +27 -0
- package/src/Budgets/Budget.ts +60 -0
- package/src/Budgets/ManagedBudget.test.ts +217 -0
- package/src/Budgets/ManagedBudget.ts +534 -0
- package/src/Budgets/VestingBudget.test.ts +123 -0
- package/src/Budgets/VestingBudget.ts +530 -0
- package/src/Deployable/Contract.ts +228 -0
- package/src/Deployable/Deployable.ts +250 -0
- package/src/Deployable/DeployableTarget.ts +234 -0
- package/src/Deployable/DeployableTargetWithRBAC.ts +323 -0
- package/src/Incentives/AllowListIncentive.test.ts +143 -0
- package/src/Incentives/AllowListIncentive.ts +336 -0
- package/src/Incentives/CGDAIncentive.test.ts +132 -0
- package/src/Incentives/CGDAIncentive.ts +470 -0
- package/src/Incentives/ERC1155Incentive.test.ts +87 -0
- package/src/Incentives/ERC1155Incentive.ts +465 -0
- package/src/Incentives/ERC20Incentive.test.ts +130 -0
- package/src/Incentives/ERC20Incentive.ts +484 -0
- package/src/Incentives/ERC20VariableCriteriaIncentive.test.ts +184 -0
- package/src/Incentives/ERC20VariableCriteriaIncentive.ts +309 -0
- package/src/Incentives/ERC20VariableIncentive.test.ts +136 -0
- package/src/Incentives/ERC20VariableIncentive.ts +422 -0
- package/src/Incentives/Incentive.test.ts +92 -0
- package/src/Incentives/Incentive.ts +86 -0
- package/src/Incentives/PointsIncentive.test.ts +139 -0
- package/src/Incentives/PointsIncentive.ts +367 -0
- package/src/Validators/SignerValidator.test.ts +159 -0
- package/src/Validators/SignerValidator.ts +683 -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 +844 -0
- package/src/index.test.ts +122 -0
- package/src/index.ts +58 -0
- package/src/transfers.ts +284 -0
- package/src/utils.test.ts +44 -0
- package/src/utils.ts +247 -0
- package/dist/Budgets/SimpleBudget.d.ts +0 -793
- package/dist/Budgets/SimpleBudget.d.ts.map +0 -1
- package/dist/generated-BaaleHW-.cjs +0 -2
package/src/utils.ts
ADDED
|
@@ -0,0 +1,247 @@
|
|
|
1
|
+
import {
|
|
2
|
+
type Config,
|
|
3
|
+
type ReadContractParameters,
|
|
4
|
+
type WatchContractEventParameters,
|
|
5
|
+
type WriteContractParameters,
|
|
6
|
+
getAccount,
|
|
7
|
+
getClient,
|
|
8
|
+
waitForTransactionReceipt,
|
|
9
|
+
} from '@wagmi/core';
|
|
10
|
+
import type { ExtractAbiEvent } from 'abitype';
|
|
11
|
+
import type {
|
|
12
|
+
Abi,
|
|
13
|
+
AbiEvent,
|
|
14
|
+
Address,
|
|
15
|
+
ContractEventName,
|
|
16
|
+
ContractFunctionName,
|
|
17
|
+
GetLogsParameters,
|
|
18
|
+
Hash,
|
|
19
|
+
Hex,
|
|
20
|
+
Log,
|
|
21
|
+
WaitForTransactionReceiptParameters,
|
|
22
|
+
} from 'viem';
|
|
23
|
+
import { isHex, keccak256, slice, toHex } from 'viem';
|
|
24
|
+
import {
|
|
25
|
+
InvalidProtocolChainIdError,
|
|
26
|
+
NoConnectedChainIdError,
|
|
27
|
+
NoContractAddressUponReceiptError,
|
|
28
|
+
} from './errors';
|
|
29
|
+
|
|
30
|
+
export type Overwrite<T, U> = Pick<T, Exclude<keyof T, keyof U>> & U;
|
|
31
|
+
|
|
32
|
+
/**
|
|
33
|
+
* Enum encapsulating all the different types of targets used in the Boost V2 Protocol.
|
|
34
|
+
*
|
|
35
|
+
* @export
|
|
36
|
+
* @enum {number}
|
|
37
|
+
*/
|
|
38
|
+
export enum RegistryType {
|
|
39
|
+
ACTION = 0,
|
|
40
|
+
ALLOW_LIST = 1,
|
|
41
|
+
BUDGET = 2,
|
|
42
|
+
INCENTIVE = 3,
|
|
43
|
+
VALIDATOR = 4,
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
/**
|
|
47
|
+
* Helper type that encapsulates common writeContract parameters without fields like `abi`, `args`, `functionName`, `address` that are expected to be provided the SDK.
|
|
48
|
+
* See (writeContract)[https://viem.sh/docs/contract/writeContract]
|
|
49
|
+
*
|
|
50
|
+
* @export
|
|
51
|
+
* @typedef {WriteParams}
|
|
52
|
+
* @template {Abi} abi
|
|
53
|
+
* @template {ContractFunctionName<abi>} functionName
|
|
54
|
+
*/
|
|
55
|
+
export type WriteParams<
|
|
56
|
+
abi extends Abi = Abi,
|
|
57
|
+
functionName extends ContractFunctionName<abi> = ContractFunctionName<abi>,
|
|
58
|
+
> = Partial<
|
|
59
|
+
Omit<
|
|
60
|
+
WriteContractParameters<abi, functionName>,
|
|
61
|
+
'address' | 'args' | 'functionName' | 'abi'
|
|
62
|
+
>
|
|
63
|
+
>;
|
|
64
|
+
|
|
65
|
+
/**
|
|
66
|
+
* Helper type that encapsulates common readContract parameters without fields like `abi`, `args`, `functionName`, `address` that are expected to be provided the SDK.
|
|
67
|
+
* See (readContract)[https://viem.sh/docs/contract/readContract]
|
|
68
|
+
*
|
|
69
|
+
* @export
|
|
70
|
+
* @typedef {ReadParams}
|
|
71
|
+
* @template {Abi} abi
|
|
72
|
+
* @template {ContractFunctionName<abi>} functionName
|
|
73
|
+
*/
|
|
74
|
+
export type ReadParams<
|
|
75
|
+
abi extends Abi,
|
|
76
|
+
functionName extends ContractFunctionName<abi>,
|
|
77
|
+
> = Partial<
|
|
78
|
+
Omit<
|
|
79
|
+
ReadContractParameters<abi, functionName>,
|
|
80
|
+
'address' | 'args' | 'functionName' | 'abi'
|
|
81
|
+
>
|
|
82
|
+
>;
|
|
83
|
+
|
|
84
|
+
/**
|
|
85
|
+
* Helper type that encapsulates common `watchContractEvent` parameters without fields like `address`, and `abi` that are expected to be provided the SDK.
|
|
86
|
+
* See (watchContractEvent)[https://wagmi.sh/core/api/actions/watchContractEvent]
|
|
87
|
+
*
|
|
88
|
+
* @export
|
|
89
|
+
* @typedef {WatchParams}
|
|
90
|
+
* @template {Abi} abi
|
|
91
|
+
* @template {ContractEventName<abi> | undefined} [eventName=undefined]
|
|
92
|
+
*/
|
|
93
|
+
export type WatchParams<
|
|
94
|
+
abi extends Abi,
|
|
95
|
+
eventName extends ContractEventName<abi> | undefined = undefined,
|
|
96
|
+
> = Partial<
|
|
97
|
+
Omit<WatchContractEventParameters<abi, eventName>, 'address' | 'abi'>
|
|
98
|
+
>;
|
|
99
|
+
|
|
100
|
+
/**
|
|
101
|
+
* Helper type that encapsulates common `getLogs` parameters without fields like `address` that are expected to be provided the SDK.
|
|
102
|
+
* See (getLogs)[https://viem.sh/docs/actions/public/getLogs#getlogs]
|
|
103
|
+
*
|
|
104
|
+
* @export
|
|
105
|
+
* @typedef {GetLogsParams}
|
|
106
|
+
* @template {Abi} abi
|
|
107
|
+
* @template {ContractEventName<abi>} event
|
|
108
|
+
* @template {ExtractAbiEvent<abi, event>} [abiEvent=ExtractAbiEvent<abi, event>]
|
|
109
|
+
* @template {| readonly AbiEvent[]
|
|
110
|
+
* | readonly unknown[]
|
|
111
|
+
* | undefined} [abiEvents=abiEvent extends AbiEvent ? [abiEvent] : undefined]
|
|
112
|
+
*/
|
|
113
|
+
export type GetLogsParams<
|
|
114
|
+
abi extends Abi,
|
|
115
|
+
event extends ContractEventName<abi>,
|
|
116
|
+
abiEvent extends ExtractAbiEvent<abi, event> = ExtractAbiEvent<abi, event>,
|
|
117
|
+
abiEvents extends
|
|
118
|
+
| readonly AbiEvent[]
|
|
119
|
+
| readonly unknown[]
|
|
120
|
+
| undefined = abiEvent extends AbiEvent ? [abiEvent] : undefined,
|
|
121
|
+
> = Partial<Omit<GetLogsParameters<abiEvent, abiEvents>, 'address'>> & {
|
|
122
|
+
chainId?: number | undefined;
|
|
123
|
+
};
|
|
124
|
+
|
|
125
|
+
/**
|
|
126
|
+
* A generic `viem.Log` event with typed `args` support via a given `Abi` and `ContractEventName`
|
|
127
|
+
*
|
|
128
|
+
* @export
|
|
129
|
+
* @typedef {GenericLog}
|
|
130
|
+
* @template {Abi} abi
|
|
131
|
+
* @template {ContractEventName<abi>} [event=ContractEventName<abi>]
|
|
132
|
+
*/
|
|
133
|
+
export type GenericLog<
|
|
134
|
+
abi extends Abi,
|
|
135
|
+
event extends ContractEventName<abi> = ContractEventName<abi>,
|
|
136
|
+
> = Log<bigint, number, false, ExtractAbiEvent<abi, event>, false>;
|
|
137
|
+
|
|
138
|
+
/**
|
|
139
|
+
* Helper utility to convert a string to a `bytes4` type
|
|
140
|
+
*
|
|
141
|
+
* @export
|
|
142
|
+
* @param {string} input
|
|
143
|
+
* @returns {Hex}
|
|
144
|
+
*/
|
|
145
|
+
export function bytes4(input: string) {
|
|
146
|
+
return slice(isHex(input) ? keccak256(input) : keccak256(toHex(input)), 0, 4);
|
|
147
|
+
}
|
|
148
|
+
|
|
149
|
+
/**
|
|
150
|
+
* Utility function to wait for a transaction receipt, and extract the contractAddress
|
|
151
|
+
*
|
|
152
|
+
* @export
|
|
153
|
+
* @async
|
|
154
|
+
* @param {WagmiConfig} config - [Wagmi Configuration](https://wagmi.sh/core/api/createConfig)
|
|
155
|
+
* @param {Promise<Hash>} hash - A transaction hash promise
|
|
156
|
+
* @param {?Omit<WaitForTransactionReceiptParameters, 'hash'>} [waitParams] - @see {@link WaitForTransactionReceiptParameters}
|
|
157
|
+
* @returns {Promise<Address>}
|
|
158
|
+
* @throws {@link NoContractAddressUponReceiptError} if no `contractAddress` exists after the transaction has been received
|
|
159
|
+
*/
|
|
160
|
+
export async function getDeployedContractAddress(
|
|
161
|
+
config: Config,
|
|
162
|
+
hash: Promise<Hash>,
|
|
163
|
+
waitParams?: Omit<WaitForTransactionReceiptParameters, 'hash'>,
|
|
164
|
+
) {
|
|
165
|
+
const receipt = await waitForTransactionReceipt(config, {
|
|
166
|
+
...waitParams,
|
|
167
|
+
hash: await hash,
|
|
168
|
+
});
|
|
169
|
+
if (!receipt.contractAddress)
|
|
170
|
+
throw new NoContractAddressUponReceiptError(receipt);
|
|
171
|
+
return receipt.contractAddress;
|
|
172
|
+
}
|
|
173
|
+
|
|
174
|
+
/**
|
|
175
|
+
* Utility type to encapsulate a transaction hash, and the simulated result prior to submitting the transaction.
|
|
176
|
+
*
|
|
177
|
+
* @export
|
|
178
|
+
* @typedef {HashAndSimulatedResult}
|
|
179
|
+
* @template [T=unknown]
|
|
180
|
+
*/
|
|
181
|
+
export type HashAndSimulatedResult<T = unknown> = { hash: Hash; result: T };
|
|
182
|
+
|
|
183
|
+
/**
|
|
184
|
+
* Helper function to wait for a transaction receipt given a hash promise.
|
|
185
|
+
*
|
|
186
|
+
* @export
|
|
187
|
+
* @async
|
|
188
|
+
* @template [Result=unknown]
|
|
189
|
+
* @param {WagmiConfig} config
|
|
190
|
+
* @param {Promise<HashAndSimulatedResult<Result>>} hashPromise
|
|
191
|
+
* @param {?Omit<WaitForTransactionReceiptParameters, 'hash'>} [waitParams]
|
|
192
|
+
* @returns {Promise<Result>}
|
|
193
|
+
*/
|
|
194
|
+
export async function awaitResult<Result = unknown>(
|
|
195
|
+
config: Config,
|
|
196
|
+
hashPromise: Promise<HashAndSimulatedResult<Result>>,
|
|
197
|
+
waitParams?: Omit<WaitForTransactionReceiptParameters, 'hash'>,
|
|
198
|
+
): Promise<Result> {
|
|
199
|
+
const { hash, result } = await hashPromise;
|
|
200
|
+
await waitForTransactionReceipt(config, {
|
|
201
|
+
...waitParams,
|
|
202
|
+
hash,
|
|
203
|
+
});
|
|
204
|
+
return result;
|
|
205
|
+
}
|
|
206
|
+
|
|
207
|
+
/**
|
|
208
|
+
* Given a wagmi config and a map of chain id's to addresses, determine an address/chainId combo that maps to the currently connected chain id, or throw a typed error.
|
|
209
|
+
*
|
|
210
|
+
* @export
|
|
211
|
+
* @param {Config} config
|
|
212
|
+
* @param {Record<string, Address>} addressByChainId
|
|
213
|
+
* @param {number} desiredChainId
|
|
214
|
+
* @returns {{ chainId: number, address: Address }}
|
|
215
|
+
* @throws {@link InvalidProtocolChainIdError}
|
|
216
|
+
*/
|
|
217
|
+
export function assertValidAddressByChainId(
|
|
218
|
+
config: Config,
|
|
219
|
+
addressByChainId: Record<number, Address>,
|
|
220
|
+
desiredChainId?: number,
|
|
221
|
+
): { chainId: number; address: Address } {
|
|
222
|
+
let chainId: number | undefined = undefined;
|
|
223
|
+
const wagmiAccount = getAccount(config);
|
|
224
|
+
// if manually providing a chain id for some contract operation, try to use it
|
|
225
|
+
if (desiredChainId !== undefined) {
|
|
226
|
+
if (addressByChainId[desiredChainId]) chainId = desiredChainId;
|
|
227
|
+
} else if (wagmiAccount.chainId !== undefined) {
|
|
228
|
+
// otherwise if we can get the current chain id off the connected account and it matches one of ours, use it
|
|
229
|
+
if (addressByChainId[wagmiAccount.chainId]) chainId = wagmiAccount.chainId;
|
|
230
|
+
}
|
|
231
|
+
// chainId is still undefined, try to get chain id off viem client
|
|
232
|
+
if (chainId === undefined) {
|
|
233
|
+
const client = getClient(config);
|
|
234
|
+
if (client?.chain.id && addressByChainId[client?.chain.id])
|
|
235
|
+
chainId = client.chain.id;
|
|
236
|
+
}
|
|
237
|
+
// if chainId is STILL undefined, use our default addresses
|
|
238
|
+
// TODO: update this when on prod network
|
|
239
|
+
if (chainId === undefined) chainId = Number(__DEFAULT_CHAIN_ID__);
|
|
240
|
+
if (!addressByChainId[chainId])
|
|
241
|
+
throw new InvalidProtocolChainIdError(
|
|
242
|
+
chainId,
|
|
243
|
+
Object.keys(addressByChainId).map(Number),
|
|
244
|
+
);
|
|
245
|
+
// biome-ignore lint/style/noNonNullAssertion: this type should be narrowed by the above statement but isn't?
|
|
246
|
+
return { chainId, address: addressByChainId[chainId]! };
|
|
247
|
+
}
|