@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
|
@@ -0,0 +1,796 @@
|
|
|
1
|
+
import {
|
|
2
|
+
managedBudgetAbi,
|
|
3
|
+
readManagedBudgetAvailable,
|
|
4
|
+
readManagedBudgetDistributed,
|
|
5
|
+
readManagedBudgetHasAllRoles,
|
|
6
|
+
readManagedBudgetHasAnyRole,
|
|
7
|
+
readManagedBudgetIsAuthorized,
|
|
8
|
+
readManagedBudgetOwner,
|
|
9
|
+
readManagedBudgetRolesOf,
|
|
10
|
+
readManagedBudgetTotal,
|
|
11
|
+
simulateManagedBudgetAllocate,
|
|
12
|
+
simulateManagedBudgetClawback,
|
|
13
|
+
simulateManagedBudgetDisburse,
|
|
14
|
+
simulateManagedBudgetDisburseBatch,
|
|
15
|
+
simulateManagedBudgetGrantRoles,
|
|
16
|
+
simulateManagedBudgetRevokeRoles,
|
|
17
|
+
simulateManagedBudgetSetAuthorized,
|
|
18
|
+
writeManagedBudgetAllocate,
|
|
19
|
+
writeManagedBudgetClawback,
|
|
20
|
+
writeManagedBudgetDisburse,
|
|
21
|
+
writeManagedBudgetDisburseBatch,
|
|
22
|
+
writeManagedBudgetGrantRoles,
|
|
23
|
+
writeManagedBudgetRevokeRoles,
|
|
24
|
+
writeManagedBudgetSetAuthorized,
|
|
25
|
+
} from '@boostxyz/evm';
|
|
26
|
+
import { bytecode } from '@boostxyz/evm/artifacts/contracts/budgets/ManagedBudget.sol/ManagedBudget.json';
|
|
27
|
+
import { getAccount } from '@wagmi/core';
|
|
28
|
+
import {
|
|
29
|
+
type Address,
|
|
30
|
+
type ContractEventName,
|
|
31
|
+
type Hex,
|
|
32
|
+
encodeAbiParameters,
|
|
33
|
+
parseAbiParameters,
|
|
34
|
+
zeroAddress,
|
|
35
|
+
} from 'viem';
|
|
36
|
+
import type {
|
|
37
|
+
DeployableOptions,
|
|
38
|
+
GenericDeployableParams,
|
|
39
|
+
} from '../Deployable/Deployable';
|
|
40
|
+
import { DeployableTarget } from '../Deployable/DeployableTarget';
|
|
41
|
+
import {
|
|
42
|
+
DeployableUnknownOwnerProvidedError,
|
|
43
|
+
UnknownTransferPayloadSupplied,
|
|
44
|
+
} from '../errors';
|
|
45
|
+
import {
|
|
46
|
+
type ERC1155TransferPayload,
|
|
47
|
+
type FungibleTransferPayload,
|
|
48
|
+
prepareERC1155Transfer,
|
|
49
|
+
prepareFungibleTransfer,
|
|
50
|
+
} from '../transfers';
|
|
51
|
+
import {
|
|
52
|
+
type GenericLog,
|
|
53
|
+
type ReadParams,
|
|
54
|
+
RegistryType,
|
|
55
|
+
type WriteParams,
|
|
56
|
+
} from '../utils';
|
|
57
|
+
|
|
58
|
+
export { managedBudgetAbi };
|
|
59
|
+
export type { ERC1155TransferPayload, FungibleTransferPayload };
|
|
60
|
+
|
|
61
|
+
/**
|
|
62
|
+
* The object representation of a `ManagedBudgetPayload.InitPayload`
|
|
63
|
+
*
|
|
64
|
+
* @export
|
|
65
|
+
* @interface ManagedBudgetPayload
|
|
66
|
+
* @typedef {ManagedBudgetPayload}
|
|
67
|
+
*/
|
|
68
|
+
export interface ManagedBudgetPayload {
|
|
69
|
+
/**
|
|
70
|
+
* The budget's owner
|
|
71
|
+
*
|
|
72
|
+
* @type {Address}
|
|
73
|
+
*/
|
|
74
|
+
owner: Address;
|
|
75
|
+
/**
|
|
76
|
+
* List of accounts authorized to use the budget. This list should include a Boost core address to interact with the protocol.
|
|
77
|
+
*
|
|
78
|
+
* @type {Address[]}
|
|
79
|
+
*/
|
|
80
|
+
authorized: Address[];
|
|
81
|
+
/**
|
|
82
|
+
* List of roles to assign to the corresponding account by index.
|
|
83
|
+
*
|
|
84
|
+
* @type {bigint[]}
|
|
85
|
+
*/
|
|
86
|
+
roles: bigint[];
|
|
87
|
+
}
|
|
88
|
+
|
|
89
|
+
/**
|
|
90
|
+
* Enum representing available roles for use in the `ManagedBudget`.
|
|
91
|
+
* `MANAGER` can disburse funds.
|
|
92
|
+
* `ADMIN` can additionally manage authorized users on the budget.
|
|
93
|
+
*
|
|
94
|
+
* @type {{ readonly MANAGER: 1n; readonly ADMIN_ROLE: 2n; }}
|
|
95
|
+
*/
|
|
96
|
+
export const ManagedBudgetRoles = {
|
|
97
|
+
MANAGER: 1n,
|
|
98
|
+
ADMIN: 2n,
|
|
99
|
+
} as const;
|
|
100
|
+
|
|
101
|
+
/**
|
|
102
|
+
* A generic `viem.Log` event with support for `ManagedBudget` event types.
|
|
103
|
+
*
|
|
104
|
+
* @export
|
|
105
|
+
* @typedef {ManagedBudgetLog}
|
|
106
|
+
* @template {ContractEventName<typeof managedBudgetAbi>} [event=ContractEventName<
|
|
107
|
+
* typeof managedBudgetAbi
|
|
108
|
+
* >]
|
|
109
|
+
*/
|
|
110
|
+
export type ManagedBudgetLog<
|
|
111
|
+
event extends ContractEventName<typeof managedBudgetAbi> = ContractEventName<
|
|
112
|
+
typeof managedBudgetAbi
|
|
113
|
+
>,
|
|
114
|
+
> = GenericLog<typeof managedBudgetAbi, event>;
|
|
115
|
+
|
|
116
|
+
/**
|
|
117
|
+
* Typeguard to determine if a transfer payload is a Fungible Transfer
|
|
118
|
+
*
|
|
119
|
+
* @export
|
|
120
|
+
* @param {(FungibleTransferPayload | ERC1155TransferPayload)} transfer
|
|
121
|
+
* @returns {transfer is FungibleTransferPayload}
|
|
122
|
+
*/
|
|
123
|
+
export function isFungibleTransfer(
|
|
124
|
+
transfer: FungibleTransferPayload | ERC1155TransferPayload,
|
|
125
|
+
): transfer is FungibleTransferPayload {
|
|
126
|
+
return (transfer as ERC1155TransferPayload).tokenId === undefined;
|
|
127
|
+
}
|
|
128
|
+
|
|
129
|
+
/**
|
|
130
|
+
* Typeguard to determine if a transfer payload is an ERC1155 Transfer
|
|
131
|
+
*
|
|
132
|
+
* @export
|
|
133
|
+
* @param {(FungibleTransferPayload | ERC1155TransferPayload)} transfer
|
|
134
|
+
* @returns {transfer is ERC1155TransferPayload}
|
|
135
|
+
*/
|
|
136
|
+
export function isERC1155TransferPayload(
|
|
137
|
+
transfer: FungibleTransferPayload | ERC1155TransferPayload,
|
|
138
|
+
): transfer is ERC1155TransferPayload {
|
|
139
|
+
return (transfer as ERC1155TransferPayload).tokenId !== undefined;
|
|
140
|
+
}
|
|
141
|
+
|
|
142
|
+
/**
|
|
143
|
+
* Given either a Fungible transfer, or ERC1155 transfer, will properly encode parameters for transfers, claims, disbursements, allocations, etc.
|
|
144
|
+
*
|
|
145
|
+
* @export
|
|
146
|
+
* @param {(FungibleTransferPayload | ERC1155TransferPayload)} transfer
|
|
147
|
+
* @returns {*}
|
|
148
|
+
* @throws {@link UnknownTransferPayloadSupplied}
|
|
149
|
+
*/
|
|
150
|
+
export function prepareTransfer(
|
|
151
|
+
transfer: FungibleTransferPayload | ERC1155TransferPayload,
|
|
152
|
+
) {
|
|
153
|
+
if (isFungibleTransfer(transfer)) {
|
|
154
|
+
return prepareFungibleTransfer(transfer);
|
|
155
|
+
} else if (isERC1155TransferPayload(transfer)) {
|
|
156
|
+
return prepareERC1155Transfer(transfer);
|
|
157
|
+
} else throw new UnknownTransferPayloadSupplied(transfer);
|
|
158
|
+
}
|
|
159
|
+
|
|
160
|
+
/**
|
|
161
|
+
* A minimal budget implementation that simply holds and distributes tokens (ERC20-like and native)
|
|
162
|
+
* This type of budget supports ETH, ERC20, and ERC1155 assets only
|
|
163
|
+
*
|
|
164
|
+
* @export
|
|
165
|
+
* @class ManagedBudget
|
|
166
|
+
* @typedef {ManagedBudget}
|
|
167
|
+
* @extends {DeployableTarget<ManagedBudgetPayload>}
|
|
168
|
+
*/
|
|
169
|
+
export class ManagedBudget extends DeployableTarget<
|
|
170
|
+
ManagedBudgetPayload,
|
|
171
|
+
typeof managedBudgetAbi
|
|
172
|
+
> {
|
|
173
|
+
/**
|
|
174
|
+
* @inheritdoc
|
|
175
|
+
*
|
|
176
|
+
* @public
|
|
177
|
+
* @readonly
|
|
178
|
+
* @type {*}
|
|
179
|
+
*/
|
|
180
|
+
public override readonly abi = managedBudgetAbi;
|
|
181
|
+
/**
|
|
182
|
+
* @inheritdoc
|
|
183
|
+
*
|
|
184
|
+
* @public
|
|
185
|
+
* @static
|
|
186
|
+
* @type {Address}
|
|
187
|
+
*/
|
|
188
|
+
public static override base: Address = import.meta.env
|
|
189
|
+
.VITE_MANAGED_BUDGET_BASE;
|
|
190
|
+
/**
|
|
191
|
+
* @inheritdoc
|
|
192
|
+
*
|
|
193
|
+
* @public
|
|
194
|
+
* @static
|
|
195
|
+
* @type {RegistryType}
|
|
196
|
+
*/
|
|
197
|
+
public static override registryType: RegistryType = RegistryType.BUDGET;
|
|
198
|
+
|
|
199
|
+
/**
|
|
200
|
+
* Allocates assets to the budget.
|
|
201
|
+
* The caller must have already approved the contract to transfer the asset
|
|
202
|
+
* If the asset transfer fails, the allocation will revert
|
|
203
|
+
*
|
|
204
|
+
* @public
|
|
205
|
+
* @async
|
|
206
|
+
* @param {(FungibleTransferPayload | ERC1155TransferPayload)} transfer
|
|
207
|
+
* @param {?WriteParams<typeof managedBudgetAbi, 'allocate'>} [params]
|
|
208
|
+
* @returns {Promise<boolean>} - True if the allocation was successful
|
|
209
|
+
*/
|
|
210
|
+
public async allocate(
|
|
211
|
+
transfer: FungibleTransferPayload | ERC1155TransferPayload,
|
|
212
|
+
params?: WriteParams<typeof managedBudgetAbi, 'allocate'>,
|
|
213
|
+
) {
|
|
214
|
+
return await this.awaitResult(this.allocateRaw(transfer, params));
|
|
215
|
+
}
|
|
216
|
+
|
|
217
|
+
/**
|
|
218
|
+
* Allocates assets to the budget.
|
|
219
|
+
* The caller must have already approved the contract to transfer the asset
|
|
220
|
+
* If the asset transfer fails, the allocation will revert
|
|
221
|
+
*
|
|
222
|
+
* @public
|
|
223
|
+
* @async
|
|
224
|
+
* @param {(FungibleTransferPayload | ERC1155TransferPayload)} transfer
|
|
225
|
+
* @param {?WriteParams<typeof managedBudgetAbi, 'allocate'>} [params]
|
|
226
|
+
* @returns {Promise<boolean>} - True if the allocation was successful
|
|
227
|
+
*/
|
|
228
|
+
public async allocateRaw(
|
|
229
|
+
transfer: FungibleTransferPayload | ERC1155TransferPayload,
|
|
230
|
+
params?: WriteParams<typeof managedBudgetAbi, 'allocate'>,
|
|
231
|
+
) {
|
|
232
|
+
const { request, result } = await simulateManagedBudgetAllocate(
|
|
233
|
+
this._config,
|
|
234
|
+
{
|
|
235
|
+
address: this.assertValidAddress(),
|
|
236
|
+
args: [prepareTransfer(transfer)],
|
|
237
|
+
...this.optionallyAttachAccount(),
|
|
238
|
+
// biome-ignore lint/suspicious/noExplicitAny: Accept any shape of valid wagmi/viem parameters, wagmi does the same thing internally
|
|
239
|
+
...(params as any),
|
|
240
|
+
},
|
|
241
|
+
);
|
|
242
|
+
const hash = await writeManagedBudgetAllocate(this._config, request);
|
|
243
|
+
return { hash, result };
|
|
244
|
+
}
|
|
245
|
+
|
|
246
|
+
/**
|
|
247
|
+
* Clawbacks assets from the budget.
|
|
248
|
+
* Only the owner can directly clawback assets from the budget
|
|
249
|
+
* If the amount is zero, the entire balance of the asset will be transferred to the receiver
|
|
250
|
+
* If the asset transfer fails, the reclamation will revert
|
|
251
|
+
*
|
|
252
|
+
* @public
|
|
253
|
+
* @async
|
|
254
|
+
* @param {(FungibleTransferPayload | ERC1155TransferPayload)} transfer
|
|
255
|
+
* @param {?WriteParams<typeof managedBudgetAbi, 'clawback'>} [params]
|
|
256
|
+
* @returns {Promise<boolean>} - True if the request was successful
|
|
257
|
+
*/
|
|
258
|
+
public async clawback(
|
|
259
|
+
transfer: FungibleTransferPayload | ERC1155TransferPayload,
|
|
260
|
+
params?: WriteParams<typeof managedBudgetAbi, 'clawback'>,
|
|
261
|
+
) {
|
|
262
|
+
return await this.awaitResult(this.clawbackRaw(transfer, params));
|
|
263
|
+
}
|
|
264
|
+
|
|
265
|
+
/**
|
|
266
|
+
* Clawbacks assets from the budget.
|
|
267
|
+
* Only the owner can directly clawback assets from the budget
|
|
268
|
+
* If the amount is zero, the entire balance of the asset will be transferred to the receiver
|
|
269
|
+
* If the asset transfer fails, the reclamation will revert
|
|
270
|
+
*
|
|
271
|
+
* @public
|
|
272
|
+
* @async
|
|
273
|
+
* @param {(FungibleTransferPayload | ERC1155TransferPayload)} transfer
|
|
274
|
+
* @param {?WriteParams<typeof managedBudgetAbi, 'clawback'>} [params]
|
|
275
|
+
* @returns {Promise<boolean>} - True if the request was successful
|
|
276
|
+
*/
|
|
277
|
+
public async clawbackRaw(
|
|
278
|
+
transfer: FungibleTransferPayload | ERC1155TransferPayload,
|
|
279
|
+
params?: WriteParams<typeof managedBudgetAbi, 'clawback'>,
|
|
280
|
+
) {
|
|
281
|
+
const { request, result } = await simulateManagedBudgetClawback(
|
|
282
|
+
this._config,
|
|
283
|
+
{
|
|
284
|
+
address: this.assertValidAddress(),
|
|
285
|
+
args: [prepareTransfer(transfer)],
|
|
286
|
+
...this.optionallyAttachAccount(),
|
|
287
|
+
// biome-ignore lint/suspicious/noExplicitAny: Accept any shape of valid wagmi/viem parameters, wagmi does the same thing internally
|
|
288
|
+
...(params as any),
|
|
289
|
+
},
|
|
290
|
+
);
|
|
291
|
+
const hash = await writeManagedBudgetClawback(this._config, request);
|
|
292
|
+
return { hash, result };
|
|
293
|
+
}
|
|
294
|
+
|
|
295
|
+
/**
|
|
296
|
+
* Disburses assets from the budget to a single recipient
|
|
297
|
+
* If the asset transfer fails, the disbursement will revert
|
|
298
|
+
*
|
|
299
|
+
* @public
|
|
300
|
+
* @async
|
|
301
|
+
* @param {(FungibleTransferPayload | ERC1155TransferPayload)} transfer
|
|
302
|
+
* @param {?WriteParams<typeof managedBudgetAbi, 'disburse'>} [params]
|
|
303
|
+
* @returns {Promise<boolean>} - True if the disbursement was successful
|
|
304
|
+
*/
|
|
305
|
+
public async disburse(
|
|
306
|
+
transfer: FungibleTransferPayload | ERC1155TransferPayload,
|
|
307
|
+
params?: WriteParams<typeof managedBudgetAbi, 'disburse'>,
|
|
308
|
+
) {
|
|
309
|
+
return await this.awaitResult(this.disburseRaw(transfer, params));
|
|
310
|
+
}
|
|
311
|
+
|
|
312
|
+
/**
|
|
313
|
+
* Disburses assets from the budget to a single recipient
|
|
314
|
+
* If the asset transfer fails, the disbursement will revert
|
|
315
|
+
*
|
|
316
|
+
* @public
|
|
317
|
+
* @async
|
|
318
|
+
* @param {(FungibleTransferPayload | ERC1155TransferPayload)} transfer
|
|
319
|
+
* @param {?WriteParams<typeof managedBudgetAbi, 'disburse'>} [params]
|
|
320
|
+
* @returns {Promise<boolean>} - True if the disbursement was successful
|
|
321
|
+
*/
|
|
322
|
+
public async disburseRaw(
|
|
323
|
+
transfer: FungibleTransferPayload | ERC1155TransferPayload,
|
|
324
|
+
params?: WriteParams<typeof managedBudgetAbi, 'disburse'>,
|
|
325
|
+
) {
|
|
326
|
+
const { request, result } = await simulateManagedBudgetDisburse(
|
|
327
|
+
this._config,
|
|
328
|
+
{
|
|
329
|
+
address: this.assertValidAddress(),
|
|
330
|
+
args: [prepareTransfer(transfer)],
|
|
331
|
+
...this.optionallyAttachAccount(),
|
|
332
|
+
// biome-ignore lint/suspicious/noExplicitAny: Accept any shape of valid wagmi/viem parameters, wagmi does the same thing internally
|
|
333
|
+
...(params as any),
|
|
334
|
+
},
|
|
335
|
+
);
|
|
336
|
+
const hash = await writeManagedBudgetDisburse(this._config, request);
|
|
337
|
+
return { hash, result };
|
|
338
|
+
}
|
|
339
|
+
|
|
340
|
+
/**
|
|
341
|
+
* Disburses assets from the budget to multiple recipients
|
|
342
|
+
*
|
|
343
|
+
* @public
|
|
344
|
+
* @async
|
|
345
|
+
* @param {Array<FungibleTransferPayload | ERC1155TransferPayload>} transfers
|
|
346
|
+
* @param {?WriteParams<typeof managedBudgetAbi, 'disburseBatch'>} [params]
|
|
347
|
+
* @returns {Promise<boolean>} - True if all disbursements were successful
|
|
348
|
+
*/
|
|
349
|
+
public async disburseBatch(
|
|
350
|
+
transfers: Array<FungibleTransferPayload | ERC1155TransferPayload>,
|
|
351
|
+
params?: WriteParams<typeof managedBudgetAbi, 'disburseBatch'>,
|
|
352
|
+
) {
|
|
353
|
+
return await this.awaitResult(this.disburseBatchRaw(transfers, params));
|
|
354
|
+
}
|
|
355
|
+
|
|
356
|
+
/**
|
|
357
|
+
* Disburses assets from the budget to multiple recipients
|
|
358
|
+
*
|
|
359
|
+
* @public
|
|
360
|
+
* @async
|
|
361
|
+
* @param {Array<FungibleTransferPayload | ERC1155TransferPayload>} transfers
|
|
362
|
+
* @param {?WriteParams<typeof managedBudgetAbi, 'disburseBatch'>} [params]
|
|
363
|
+
* @returns {Promise<boolean>} - True if all disbursements were successful
|
|
364
|
+
*/
|
|
365
|
+
public async disburseBatchRaw(
|
|
366
|
+
transfers: Array<FungibleTransferPayload | ERC1155TransferPayload>,
|
|
367
|
+
params?: WriteParams<typeof managedBudgetAbi, 'disburseBatch'>,
|
|
368
|
+
) {
|
|
369
|
+
const { request, result } = await simulateManagedBudgetDisburseBatch(
|
|
370
|
+
this._config,
|
|
371
|
+
{
|
|
372
|
+
address: this.assertValidAddress(),
|
|
373
|
+
args: [transfers.map(prepareTransfer)],
|
|
374
|
+
...this.optionallyAttachAccount(),
|
|
375
|
+
// biome-ignore lint/suspicious/noExplicitAny: Accept any shape of valid wagmi/viem parameters, wagmi does the same thing internally
|
|
376
|
+
...(params as any),
|
|
377
|
+
},
|
|
378
|
+
);
|
|
379
|
+
const hash = await writeManagedBudgetDisburseBatch(this._config, request);
|
|
380
|
+
return { hash, result };
|
|
381
|
+
}
|
|
382
|
+
|
|
383
|
+
/**
|
|
384
|
+
* Set the authorized status of the given accounts
|
|
385
|
+
* The mechanism for managing authorization is left to the implementing contract
|
|
386
|
+
*
|
|
387
|
+
* @public
|
|
388
|
+
* @async
|
|
389
|
+
* @param {Address[]} addresses - The accounts to authorize or deauthorize
|
|
390
|
+
* @param {boolean[]} allowed - The authorization status for the given accounts
|
|
391
|
+
* @param {?WriteParams<typeof managedBudgetAbi, 'setAuthorized'>} [params]
|
|
392
|
+
* @returns {Promise<void>}
|
|
393
|
+
*/
|
|
394
|
+
public async setAuthorized(
|
|
395
|
+
addresses: Address[],
|
|
396
|
+
allowed: boolean[],
|
|
397
|
+
params?: WriteParams<typeof managedBudgetAbi, 'setAuthorized'>,
|
|
398
|
+
) {
|
|
399
|
+
return await this.awaitResult(
|
|
400
|
+
this.setAuthorizedRaw(addresses, allowed, params),
|
|
401
|
+
);
|
|
402
|
+
}
|
|
403
|
+
|
|
404
|
+
/**
|
|
405
|
+
* Set the authorized status of the given accounts
|
|
406
|
+
* The mechanism for managing authorization is left to the implementing contract
|
|
407
|
+
*
|
|
408
|
+
* @public
|
|
409
|
+
* @async
|
|
410
|
+
* @param {Address[]} addresses - The accounts to authorize or deauthorize
|
|
411
|
+
* @param {boolean[]} allowed - The authorization status for the given accounts
|
|
412
|
+
* @param {?WriteParams<typeof managedBudgetAbi, 'setAuthorized'>} [params]
|
|
413
|
+
* @returns {Promise<void>}
|
|
414
|
+
*/
|
|
415
|
+
public async setAuthorizedRaw(
|
|
416
|
+
addresses: Address[],
|
|
417
|
+
allowed: boolean[],
|
|
418
|
+
params?: WriteParams<typeof managedBudgetAbi, 'setAuthorized'>,
|
|
419
|
+
) {
|
|
420
|
+
const { request, result } = await simulateManagedBudgetSetAuthorized(
|
|
421
|
+
this._config,
|
|
422
|
+
{
|
|
423
|
+
address: this.assertValidAddress(),
|
|
424
|
+
args: [addresses, allowed],
|
|
425
|
+
...this.optionallyAttachAccount(),
|
|
426
|
+
// biome-ignore lint/suspicious/noExplicitAny: Accept any shape of valid wagmi/viem parameters, wagmi does the same thing internally
|
|
427
|
+
...(params as any),
|
|
428
|
+
},
|
|
429
|
+
);
|
|
430
|
+
const hash = await writeManagedBudgetSetAuthorized(this._config, request);
|
|
431
|
+
return { hash, result };
|
|
432
|
+
}
|
|
433
|
+
|
|
434
|
+
/**
|
|
435
|
+
* Grant many accounts permissions on the budget.
|
|
436
|
+
*
|
|
437
|
+
* @example
|
|
438
|
+
* ```ts
|
|
439
|
+
* await budget.grantRoles(['0xfoo', '0xbar], [ManagedBudgetRoles.MANAGER, ManagedBudgetRoles.ADMIN])
|
|
440
|
+
* ```
|
|
441
|
+
* @public
|
|
442
|
+
* @async
|
|
443
|
+
* @param {Address[]} addresses
|
|
444
|
+
* @param {bigint[]} roles
|
|
445
|
+
* @param {?WriteParams<typeof managedBudgetAbi, 'grantRoles'>} [params]
|
|
446
|
+
* @returns {unknown}
|
|
447
|
+
*/
|
|
448
|
+
public async grantRoles(
|
|
449
|
+
addresses: Address[],
|
|
450
|
+
roles: bigint[],
|
|
451
|
+
params?: WriteParams<typeof managedBudgetAbi, 'grantRoles'>,
|
|
452
|
+
) {
|
|
453
|
+
return await this.awaitResult(this.grantRolesRaw(addresses, roles, params));
|
|
454
|
+
}
|
|
455
|
+
|
|
456
|
+
/**
|
|
457
|
+
* Grant many accounts permissions on the budget.
|
|
458
|
+
*
|
|
459
|
+
* @example
|
|
460
|
+
* ```ts
|
|
461
|
+
* await budget.grantRoles(['0xfoo', '0xbar], [ManagedBudgetRoles.MANAGER, ManagedBudgetRoles.ADMIN])
|
|
462
|
+
*
|
|
463
|
+
* @public
|
|
464
|
+
* @async
|
|
465
|
+
* @param {Address[]} addresses
|
|
466
|
+
* @param {bigint[]} roles
|
|
467
|
+
* @param {?WriteParams<typeof managedBudgetAbi, 'grantRoles'>} [params]
|
|
468
|
+
* @returns {unknown}
|
|
469
|
+
*/
|
|
470
|
+
public async grantRolesRaw(
|
|
471
|
+
addresses: Address[],
|
|
472
|
+
roles: bigint[],
|
|
473
|
+
params?: WriteParams<typeof managedBudgetAbi, 'grantRoles'>,
|
|
474
|
+
) {
|
|
475
|
+
const { request, result } = await simulateManagedBudgetGrantRoles(
|
|
476
|
+
this._config,
|
|
477
|
+
{
|
|
478
|
+
address: this.assertValidAddress(),
|
|
479
|
+
args: [addresses, roles],
|
|
480
|
+
...this.optionallyAttachAccount(),
|
|
481
|
+
// biome-ignore lint/suspicious/noExplicitAny: Accept any shape of valid wagmi/viem parameters, wagmi does the same thing internally
|
|
482
|
+
...(params as any),
|
|
483
|
+
},
|
|
484
|
+
);
|
|
485
|
+
const hash = await writeManagedBudgetGrantRoles(
|
|
486
|
+
this._config,
|
|
487
|
+
// biome-ignore lint/suspicious/noExplicitAny: negligible low level lack of type intersection
|
|
488
|
+
request as any,
|
|
489
|
+
);
|
|
490
|
+
return { hash, result };
|
|
491
|
+
}
|
|
492
|
+
|
|
493
|
+
/**
|
|
494
|
+
* Revoke many accounts' permissions on the budget.
|
|
495
|
+
*
|
|
496
|
+
* @example
|
|
497
|
+
* ```ts
|
|
498
|
+
* await budget.revokeRoles(['0xfoo', '0xbar], [ManagedBudgetRoles.MANAGER, ManagedBudgetRoles.ADMIN])
|
|
499
|
+
*
|
|
500
|
+
* @public
|
|
501
|
+
* @async
|
|
502
|
+
* @param {Address[]} addresses
|
|
503
|
+
* @param {bigint[]} roles
|
|
504
|
+
* @param {?WriteParams<typeof managedBudgetAbi, 'revokeRoles'>} [params]
|
|
505
|
+
* @returns {unknown}
|
|
506
|
+
*/
|
|
507
|
+
public async revokeRoles(
|
|
508
|
+
addresses: Address[],
|
|
509
|
+
roles: bigint[],
|
|
510
|
+
params?: WriteParams<typeof managedBudgetAbi, 'revokeRoles'>,
|
|
511
|
+
) {
|
|
512
|
+
return await this.awaitResult(
|
|
513
|
+
this.revokeRolesRaw(addresses, roles, params),
|
|
514
|
+
);
|
|
515
|
+
}
|
|
516
|
+
|
|
517
|
+
/**
|
|
518
|
+
* Revoke many accounts' permissions on the budget.
|
|
519
|
+
*
|
|
520
|
+
* @example
|
|
521
|
+
* ```ts
|
|
522
|
+
* await budget.revokeRoles(['0xfoo', '0xbar], [ManagedBudgetRoles.MANAGER, ManagedBudgetRoles.ADMIN])
|
|
523
|
+
* @public
|
|
524
|
+
* @async
|
|
525
|
+
* @param {Address[]} addresses
|
|
526
|
+
* @param {bigint[]} roles
|
|
527
|
+
* @param {?WriteParams<typeof managedBudgetAbi, 'revokeRoles'>} [params]
|
|
528
|
+
* @returns {unknown}
|
|
529
|
+
*/
|
|
530
|
+
public async revokeRolesRaw(
|
|
531
|
+
addresses: Address[],
|
|
532
|
+
roles: bigint[],
|
|
533
|
+
params?: WriteParams<typeof managedBudgetAbi, 'revokeRoles'>,
|
|
534
|
+
) {
|
|
535
|
+
const { request, result } = await simulateManagedBudgetRevokeRoles(
|
|
536
|
+
this._config,
|
|
537
|
+
{
|
|
538
|
+
address: this.assertValidAddress(),
|
|
539
|
+
args: [addresses, roles],
|
|
540
|
+
...this.optionallyAttachAccount(),
|
|
541
|
+
// biome-ignore lint/suspicious/noExplicitAny: Accept any shape of valid wagmi/viem parameters, wagmi does the same thing internally
|
|
542
|
+
...(params as any),
|
|
543
|
+
},
|
|
544
|
+
);
|
|
545
|
+
const hash = await writeManagedBudgetRevokeRoles(
|
|
546
|
+
this._config,
|
|
547
|
+
// biome-ignore lint/suspicious/noExplicitAny: negligible low level lack of type intersection
|
|
548
|
+
request as any,
|
|
549
|
+
);
|
|
550
|
+
return { hash, result };
|
|
551
|
+
}
|
|
552
|
+
|
|
553
|
+
/**
|
|
554
|
+
* Return an array of the roles assigned to the given account.
|
|
555
|
+
* @example
|
|
556
|
+
* ```ts
|
|
557
|
+
* (await budget.rolesOf(0xfoo)).includes(ManagedBudgetRoles.ADMIN)
|
|
558
|
+
* @public
|
|
559
|
+
* @param {Address} account
|
|
560
|
+
* @param {?ReadParams<typeof managedBudgetAbi, 'rolesOf'>} [params]
|
|
561
|
+
* @returns {Promise<Array<bigint>>}
|
|
562
|
+
*/
|
|
563
|
+
public async rolesOf(
|
|
564
|
+
account: Address,
|
|
565
|
+
params?: ReadParams<typeof managedBudgetAbi, 'rolesOf'>,
|
|
566
|
+
) {
|
|
567
|
+
const roles = await readManagedBudgetRolesOf(this._config, {
|
|
568
|
+
address: this.assertValidAddress(),
|
|
569
|
+
args: [account],
|
|
570
|
+
...this.optionallyAttachAccount(),
|
|
571
|
+
// biome-ignore lint/suspicious/noExplicitAny: Accept any shape of valid wagmi/viem parameters, wagmi does the same thing internally
|
|
572
|
+
...(params as any),
|
|
573
|
+
});
|
|
574
|
+
return [ManagedBudgetRoles.MANAGER, ManagedBudgetRoles.ADMIN].filter(
|
|
575
|
+
(role) => (roles & role) === role,
|
|
576
|
+
);
|
|
577
|
+
}
|
|
578
|
+
|
|
579
|
+
/**
|
|
580
|
+
* Returns whether given account has any of the provided roles bitmap.
|
|
581
|
+
*
|
|
582
|
+
* @example
|
|
583
|
+
* ```ts
|
|
584
|
+
* await budget.hasAnyRole(0xfoo, ManagedBudgetRoles.ADMIN | ManagedBudgetRoles.MANAGER)
|
|
585
|
+
* @public
|
|
586
|
+
* @param {Address} account
|
|
587
|
+
* @param {bigint} roles
|
|
588
|
+
* @param {?ReadParams<typeof managedBudgetAbi, 'hasAnyRole'>} [params]
|
|
589
|
+
* @returns {Promise<boolean>}
|
|
590
|
+
*/
|
|
591
|
+
public hasAnyRole(
|
|
592
|
+
account: Address,
|
|
593
|
+
roles: bigint,
|
|
594
|
+
params?: ReadParams<typeof managedBudgetAbi, 'hasAnyRole'>,
|
|
595
|
+
) {
|
|
596
|
+
return readManagedBudgetHasAnyRole(this._config, {
|
|
597
|
+
address: this.assertValidAddress(),
|
|
598
|
+
args: [account, roles],
|
|
599
|
+
...this.optionallyAttachAccount(),
|
|
600
|
+
// biome-ignore lint/suspicious/noExplicitAny: Accept any shape of valid wagmi/viem parameters, wagmi does the same thing internally
|
|
601
|
+
...(params as any),
|
|
602
|
+
});
|
|
603
|
+
}
|
|
604
|
+
|
|
605
|
+
/**
|
|
606
|
+
* Returns whether given account has all of the provided roles bitmap.
|
|
607
|
+
*
|
|
608
|
+
* @example
|
|
609
|
+
* ```ts
|
|
610
|
+
* await budget.hasAllRoles(0xfoo, ManagedBudgetRoles.ADMIN & ManagedBudgetRoles.MANAGER)
|
|
611
|
+
*
|
|
612
|
+
* @public
|
|
613
|
+
* @param {Address} account
|
|
614
|
+
* @param {bigint} roles
|
|
615
|
+
* @param {?ReadParams<typeof managedBudgetAbi, 'hasAllRoles'>} [params]
|
|
616
|
+
* @returns {*}
|
|
617
|
+
*/
|
|
618
|
+
public hasAllRoles(
|
|
619
|
+
account: Address,
|
|
620
|
+
roles: bigint,
|
|
621
|
+
params?: ReadParams<typeof managedBudgetAbi, 'hasAllRoles'>,
|
|
622
|
+
) {
|
|
623
|
+
return readManagedBudgetHasAllRoles(this._config, {
|
|
624
|
+
address: this.assertValidAddress(),
|
|
625
|
+
args: [account, roles],
|
|
626
|
+
...this.optionallyAttachAccount(),
|
|
627
|
+
// biome-ignore lint/suspicious/noExplicitAny: Accept any shape of valid wagmi/viem parameters, wagmi does the same thing internally
|
|
628
|
+
...(params as any),
|
|
629
|
+
});
|
|
630
|
+
}
|
|
631
|
+
|
|
632
|
+
/**
|
|
633
|
+
* Check if the given account is authorized to use the budget
|
|
634
|
+
*
|
|
635
|
+
* @public
|
|
636
|
+
* @param {Address} account
|
|
637
|
+
* @param {?ReadParams<typeof managedBudgetAbi, 'isAuthorized'>} [params]
|
|
638
|
+
* @returns {Promise<boolean>} - True if the account is authorized
|
|
639
|
+
*/
|
|
640
|
+
public isAuthorized(
|
|
641
|
+
account: Address,
|
|
642
|
+
params?: ReadParams<typeof managedBudgetAbi, 'isAuthorized'>,
|
|
643
|
+
) {
|
|
644
|
+
return readManagedBudgetIsAuthorized(this._config, {
|
|
645
|
+
address: this.assertValidAddress(),
|
|
646
|
+
args: [account],
|
|
647
|
+
...this.optionallyAttachAccount(),
|
|
648
|
+
// biome-ignore lint/suspicious/noExplicitAny: Accept any shape of valid wagmi/viem parameters, wagmi does the same thing internally
|
|
649
|
+
...(params as any),
|
|
650
|
+
});
|
|
651
|
+
}
|
|
652
|
+
|
|
653
|
+
/**
|
|
654
|
+
* Get the owner of the budget
|
|
655
|
+
*
|
|
656
|
+
* @public
|
|
657
|
+
* @param {?ReadParams<typeof managedBudgetAbi, 'owner'>} [params]
|
|
658
|
+
* @returns {Promise<Address>}
|
|
659
|
+
*/
|
|
660
|
+
public owner(params?: ReadParams<typeof managedBudgetAbi, 'owner'>) {
|
|
661
|
+
return readManagedBudgetOwner(this._config, {
|
|
662
|
+
address: this.assertValidAddress(),
|
|
663
|
+
args: [],
|
|
664
|
+
// biome-ignore lint/suspicious/noExplicitAny: Accept any shape of valid wagmi/viem parameters, wagmi does the same thing internally
|
|
665
|
+
...(params as any),
|
|
666
|
+
});
|
|
667
|
+
}
|
|
668
|
+
|
|
669
|
+
/**
|
|
670
|
+
* Get the total amount of assets allocated to the budget, including any that have been distributed
|
|
671
|
+
* If a tokenId is provided, get the total amount of ERC1155 assets allocated to the budget, including any that have been distributed
|
|
672
|
+
*
|
|
673
|
+
* @public
|
|
674
|
+
* @param {Address} asset - The address of the asset
|
|
675
|
+
* @param {?(bigint | undefined)} [tokenId] - The ID of the token
|
|
676
|
+
* @param {?ReadParams<typeof managedBudgetAbi, 'total'>} [params]
|
|
677
|
+
* @returns {Promise<bigint>} - The total amount of assets
|
|
678
|
+
*/
|
|
679
|
+
public total(
|
|
680
|
+
asset: Address,
|
|
681
|
+
tokenId?: bigint | undefined,
|
|
682
|
+
params?: ReadParams<typeof managedBudgetAbi, 'total'>,
|
|
683
|
+
) {
|
|
684
|
+
return readManagedBudgetTotal(this._config, {
|
|
685
|
+
address: this.assertValidAddress(),
|
|
686
|
+
args: tokenId ? [asset, tokenId] : [asset],
|
|
687
|
+
// biome-ignore lint/suspicious/noExplicitAny: Accept any shape of valid wagmi/viem parameters, wagmi does the same thing internally
|
|
688
|
+
...(params as any),
|
|
689
|
+
});
|
|
690
|
+
}
|
|
691
|
+
|
|
692
|
+
/**
|
|
693
|
+
* Get the amount of assets available for distribution from the budget.
|
|
694
|
+
* If a tokenId is provided, get the amount of ERC1155 assets available for distribution from the budget
|
|
695
|
+
*
|
|
696
|
+
* @public
|
|
697
|
+
* @param {Address} asset
|
|
698
|
+
* @param {?(bigint | undefined)} [tokenId]
|
|
699
|
+
* @param {?ReadParams<typeof managedBudgetAbi, 'available'>} [params]
|
|
700
|
+
* @returns {Promise<bigint>} - The amount of assets available
|
|
701
|
+
*/
|
|
702
|
+
public available(
|
|
703
|
+
asset: Address,
|
|
704
|
+
tokenId?: bigint | undefined,
|
|
705
|
+
params?: ReadParams<typeof managedBudgetAbi, 'available'>,
|
|
706
|
+
) {
|
|
707
|
+
return readManagedBudgetAvailable(this._config, {
|
|
708
|
+
address: this.assertValidAddress(),
|
|
709
|
+
args: tokenId ? [asset, tokenId] : [asset],
|
|
710
|
+
// biome-ignore lint/suspicious/noExplicitAny: Accept any shape of valid wagmi/viem parameters, wagmi does the same thing internally
|
|
711
|
+
...(params as any),
|
|
712
|
+
});
|
|
713
|
+
}
|
|
714
|
+
|
|
715
|
+
/**
|
|
716
|
+
* Get the amount of assets that have been distributed from the budget.
|
|
717
|
+
* If a tokenId is provided, get the amount of ERC1155 assets that have been distributed from the budget
|
|
718
|
+
*
|
|
719
|
+
* @public
|
|
720
|
+
* @param {Address} asset
|
|
721
|
+
* @param {?(bigint | undefined)} [tokenId]
|
|
722
|
+
* @param {?ReadParams<typeof managedBudgetAbi, 'distributed'>} [params]
|
|
723
|
+
* @returns {Promise<bigint>} - The amount of assets distributed
|
|
724
|
+
*/
|
|
725
|
+
public distributed(
|
|
726
|
+
asset: Address,
|
|
727
|
+
tokenId?: bigint | undefined,
|
|
728
|
+
params?: ReadParams<typeof managedBudgetAbi, 'distributed'>,
|
|
729
|
+
) {
|
|
730
|
+
return readManagedBudgetDistributed(this._config, {
|
|
731
|
+
address: this.assertValidAddress(),
|
|
732
|
+
args: tokenId ? [asset, tokenId] : [asset],
|
|
733
|
+
// biome-ignore lint/suspicious/noExplicitAny: Accept any shape of valid wagmi/viem parameters, wagmi does the same thing internally
|
|
734
|
+
...(params as any),
|
|
735
|
+
});
|
|
736
|
+
}
|
|
737
|
+
|
|
738
|
+
/**
|
|
739
|
+
* @inheritdoc
|
|
740
|
+
*
|
|
741
|
+
* @public
|
|
742
|
+
* @param {?ManagedBudgetPayload} [_payload]
|
|
743
|
+
* @param {?DeployableOptions} [_options]
|
|
744
|
+
* @returns {GenericDeployableParams}
|
|
745
|
+
*/
|
|
746
|
+
public override buildParameters(
|
|
747
|
+
_payload?: ManagedBudgetPayload,
|
|
748
|
+
_options?: DeployableOptions,
|
|
749
|
+
): GenericDeployableParams {
|
|
750
|
+
const [payload, options] = this.validateDeploymentConfig(
|
|
751
|
+
_payload,
|
|
752
|
+
_options,
|
|
753
|
+
);
|
|
754
|
+
if (!payload.owner || payload.owner === zeroAddress) {
|
|
755
|
+
const owner = options.account
|
|
756
|
+
? options.account.address
|
|
757
|
+
: options.config
|
|
758
|
+
? getAccount(options.config).address
|
|
759
|
+
: this._account?.address;
|
|
760
|
+
if (owner) {
|
|
761
|
+
payload.owner = owner;
|
|
762
|
+
} else {
|
|
763
|
+
throw new DeployableUnknownOwnerProvidedError();
|
|
764
|
+
}
|
|
765
|
+
}
|
|
766
|
+
return {
|
|
767
|
+
abi: managedBudgetAbi,
|
|
768
|
+
bytecode: bytecode as Hex,
|
|
769
|
+
args: [prepareManagedBudgetPayload(payload)],
|
|
770
|
+
...this.optionallyAttachAccount(options.account),
|
|
771
|
+
};
|
|
772
|
+
}
|
|
773
|
+
}
|
|
774
|
+
|
|
775
|
+
/**
|
|
776
|
+
* Given a {@link ManagedBudgetPayload}, properly encode a `ManagedBudget.InitPayload` for use with {@link ManagedBudget} initialization.
|
|
777
|
+
*
|
|
778
|
+
* @param {ManagedBudgetPayload} param0
|
|
779
|
+
* @param {Address} param0.owner - The budget's owner
|
|
780
|
+
* @param {{}} param0.authorized - List of accounts authorized to use the budget. This list should include a Boost core address to interact with the protocol.
|
|
781
|
+
* @param {{}} param0.roles - List of roles to assign to the corresponding account by index.
|
|
782
|
+
* @returns {*}
|
|
783
|
+
*/
|
|
784
|
+
export const prepareManagedBudgetPayload = ({
|
|
785
|
+
owner,
|
|
786
|
+
authorized,
|
|
787
|
+
roles,
|
|
788
|
+
}: ManagedBudgetPayload) => {
|
|
789
|
+
return encodeAbiParameters(
|
|
790
|
+
parseAbiParameters([
|
|
791
|
+
'ManagedBudgetPayload payload',
|
|
792
|
+
'struct ManagedBudgetPayload { address owner; address[] authorized; uint256[] roles; }',
|
|
793
|
+
]),
|
|
794
|
+
[{ owner, authorized, roles }],
|
|
795
|
+
);
|
|
796
|
+
};
|