@boostxyz/sdk 0.0.0-alpha.2 → 0.0.0-alpha.21
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 +76 -76
- 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 +105 -14
- package/dist/Boost.d.ts.map +1 -1
- package/dist/Boost.js +138 -5
- package/dist/Boost.js.map +1 -0
- package/dist/BoostCore-DolmDuXW.cjs +3 -0
- package/dist/BoostCore-DolmDuXW.cjs.map +1 -0
- package/dist/BoostCore-Z97KVu4V.js +1448 -0
- package/dist/BoostCore-Z97KVu4V.js.map +1 -0
- package/dist/BoostCore.cjs +2 -2
- package/dist/BoostCore.cjs.map +1 -0
- package/dist/BoostCore.d.ts +788 -79
- 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 +95 -26
- package/dist/BoostRegistry.d.ts.map +1 -1
- package/dist/BoostRegistry.js +183 -89
- 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 +112 -192
- package/dist/Budgets/ManagedBudget.d.ts.map +1 -1
- package/dist/Budgets/ManagedBudget.js +91 -291
- package/dist/Budgets/ManagedBudget.js.map +1 -0
- package/dist/Budgets/VestingBudget.d.ts +277 -91
- 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-CBKzuNoN.cjs +2 -0
- package/dist/EventAction-CBKzuNoN.cjs.map +1 -0
- package/dist/EventAction-DWuuc_Qy.js +1528 -0
- package/dist/EventAction-DWuuc_Qy.js.map +1 -0
- package/dist/Incentive-BxzEtN26.js +298 -0
- package/dist/Incentive-BxzEtN26.js.map +1 -0
- package/dist/Incentive-CrF3-ayL.cjs +2 -0
- package/dist/Incentive-CrF3-ayL.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 +65 -21
- package/dist/Incentives/AllowListIncentive.d.ts.map +1 -1
- package/dist/Incentives/AllowListIncentive.js +52 -36
- 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 +315 -26
- package/dist/Incentives/CGDAIncentive.d.ts.map +1 -1
- package/dist/Incentives/CGDAIncentive.js +64 -39
- package/dist/Incentives/CGDAIncentive.js.map +1 -0
- package/dist/Incentives/ERC1155Incentive.d.ts +291 -43
- 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 +270 -33
- package/dist/Incentives/ERC20Incentive.d.ts.map +1 -1
- package/dist/Incentives/ERC20Incentive.js +69 -46
- package/dist/Incentives/ERC20Incentive.js.map +1 -0
- package/dist/{Budgets/SimpleBudget.d.ts → Incentives/ERC20VariableCriteriaIncentive.d.ts} +338 -421
- package/dist/Incentives/ERC20VariableCriteriaIncentive.d.ts.map +1 -0
- package/dist/Incentives/ERC20VariableIncentive.d.ts +262 -32
- 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 +5 -8
- 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 +81 -23
- 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-BUR17Tt1.cjs +2 -0
- package/dist/SimpleDenyList-BUR17Tt1.cjs.map +1 -0
- package/dist/SimpleDenyList-CGaWjuld.js +132 -0
- package/dist/SimpleDenyList-CGaWjuld.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 +10 -8
- 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-BBCFkrZv.js +14 -0
- package/dist/componentInterfaces-BBCFkrZv.js.map +1 -0
- package/dist/componentInterfaces-DRI_dQ-P.cjs +2 -0
- package/dist/componentInterfaces-DRI_dQ-P.cjs.map +1 -0
- package/dist/deployments-DVXioW2i.cjs +2 -0
- package/dist/deployments-DVXioW2i.cjs.map +1 -0
- package/dist/deployments-oykLv3_Z.js +43 -0
- package/dist/deployments-oykLv3_Z.js.map +1 -0
- package/dist/deployments.json +44 -0
- package/dist/errors.cjs +2 -1
- package/dist/errors.cjs.map +1 -0
- package/dist/errors.d.ts +421 -1
- package/dist/errors.d.ts.map +1 -1
- package/dist/errors.js +297 -39
- package/dist/errors.js.map +1 -0
- package/dist/{generated-x_abr3Yv.js → generated-CKt2yCQd.js} +3143 -3002
- package/dist/generated-CKt2yCQd.js.map +1 -0
- package/dist/generated-CyTNlOwM.cjs +3 -0
- package/dist/generated-CyTNlOwM.cjs.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 +144 -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 +1218 -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 +287 -0
- package/src/BoostCore.test.ts +894 -0
- package/src/BoostCore.ts +1438 -0
- package/src/BoostRegistry.test.ts +53 -0
- package/src/BoostRegistry.ts +588 -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 +135 -0
- package/src/Incentives/CGDAIncentive.ts +476 -0
- package/src/Incentives/ERC1155Incentive.test.ts +87 -0
- package/src/Incentives/ERC1155Incentive.ts +465 -0
- package/src/Incentives/ERC20Incentive.test.ts +133 -0
- package/src/Incentives/ERC20Incentive.ts +490 -0
- package/src/Incentives/ERC20VariableCriteriaIncentive.test.ts +184 -0
- package/src/Incentives/ERC20VariableCriteriaIncentive.ts +309 -0
- package/src/Incentives/ERC20VariableIncentive.test.ts +139 -0
- package/src/Incentives/ERC20VariableIncentive.ts +428 -0
- package/src/Incentives/Incentive.test.ts +95 -0
- package/src/Incentives/Incentive.ts +86 -0
- package/src/Incentives/PointsIncentive.test.ts +138 -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 +866 -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.map +0 -1
- package/dist/generated-BaaleHW-.cjs +0 -2
|
@@ -0,0 +1,534 @@
|
|
|
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 { ManagedBudget as ManagedBudgetBases } from '../../dist/deployments.json';
|
|
37
|
+
import type {
|
|
38
|
+
DeployableOptions,
|
|
39
|
+
GenericDeployableParams,
|
|
40
|
+
} from '../Deployable/Deployable';
|
|
41
|
+
import { DeployableTarget } from '../Deployable/DeployableTarget';
|
|
42
|
+
import { DeployableTargetWithRBAC } from '../Deployable/DeployableTargetWithRBAC';
|
|
43
|
+
import {
|
|
44
|
+
DeployableUnknownOwnerProvidedError,
|
|
45
|
+
UnknownTransferPayloadSupplied,
|
|
46
|
+
} from '../errors';
|
|
47
|
+
import {
|
|
48
|
+
type ERC1155TransferPayload,
|
|
49
|
+
type FungibleTransferPayload,
|
|
50
|
+
prepareERC1155Transfer,
|
|
51
|
+
prepareFungibleTransfer,
|
|
52
|
+
} from '../transfers';
|
|
53
|
+
import {
|
|
54
|
+
type GenericLog,
|
|
55
|
+
type ReadParams,
|
|
56
|
+
RegistryType,
|
|
57
|
+
type WriteParams,
|
|
58
|
+
} from '../utils';
|
|
59
|
+
export { managedBudgetAbi };
|
|
60
|
+
export type { ERC1155TransferPayload, FungibleTransferPayload };
|
|
61
|
+
|
|
62
|
+
/**
|
|
63
|
+
* The object representation of a `ManagedBudgetPayload.InitPayload`
|
|
64
|
+
*
|
|
65
|
+
* @export
|
|
66
|
+
* @interface ManagedBudgetPayload
|
|
67
|
+
* @typedef {ManagedBudgetPayload}
|
|
68
|
+
*/
|
|
69
|
+
export interface ManagedBudgetPayload {
|
|
70
|
+
/**
|
|
71
|
+
* The budget's owner
|
|
72
|
+
*
|
|
73
|
+
* @type {Address}
|
|
74
|
+
*/
|
|
75
|
+
owner: Address;
|
|
76
|
+
/**
|
|
77
|
+
* List of accounts authorized to use the budget. This list should include a Boost core address to interact with the protocol.
|
|
78
|
+
*
|
|
79
|
+
* @type {Address[]}
|
|
80
|
+
*/
|
|
81
|
+
authorized: Address[];
|
|
82
|
+
/**
|
|
83
|
+
* List of roles to assign to the corresponding account by index.
|
|
84
|
+
*
|
|
85
|
+
* @type {ManagedBudgetRoles[]}
|
|
86
|
+
*/
|
|
87
|
+
roles: ManagedBudgetRoles[];
|
|
88
|
+
}
|
|
89
|
+
|
|
90
|
+
/**
|
|
91
|
+
* Enum representing available roles for use in the `ManagedBudget`.
|
|
92
|
+
* `MANAGER` can disburse funds.
|
|
93
|
+
* `ADMIN` can additionally manage authorized users on the budget.
|
|
94
|
+
*
|
|
95
|
+
* @export
|
|
96
|
+
* @type {{ readonly MANAGER: 1n; readonly ADMIN_ROLE: 2n; }}
|
|
97
|
+
* @enum {bigint}
|
|
98
|
+
*/
|
|
99
|
+
export enum ManagedBudgetRoles {
|
|
100
|
+
//@ts-expect-error ts doesn't like bigint enum values
|
|
101
|
+
MANAGER = 1n,
|
|
102
|
+
//@ts-expect-error ts doesn't like bigint enum values
|
|
103
|
+
ADMIN = 2n,
|
|
104
|
+
}
|
|
105
|
+
|
|
106
|
+
/**
|
|
107
|
+
* A generic `viem.Log` event with support for `ManagedBudget` event types.
|
|
108
|
+
*
|
|
109
|
+
* @export
|
|
110
|
+
* @typedef {ManagedBudgetLog}
|
|
111
|
+
* @template {ContractEventName<typeof managedBudgetAbi>} [event=ContractEventName<
|
|
112
|
+
* typeof managedBudgetAbi
|
|
113
|
+
* >]
|
|
114
|
+
*/
|
|
115
|
+
export type ManagedBudgetLog<
|
|
116
|
+
event extends ContractEventName<typeof managedBudgetAbi> = ContractEventName<
|
|
117
|
+
typeof managedBudgetAbi
|
|
118
|
+
>,
|
|
119
|
+
> = GenericLog<typeof managedBudgetAbi, event>;
|
|
120
|
+
|
|
121
|
+
/**
|
|
122
|
+
* Typeguard to determine if a transfer payload is a Fungible Transfer
|
|
123
|
+
*
|
|
124
|
+
* @export
|
|
125
|
+
* @param {(FungibleTransferPayload | ERC1155TransferPayload)} transfer
|
|
126
|
+
* @returns {transfer is FungibleTransferPayload}
|
|
127
|
+
*/
|
|
128
|
+
export function isFungibleTransfer(
|
|
129
|
+
transfer: FungibleTransferPayload | ERC1155TransferPayload,
|
|
130
|
+
): transfer is FungibleTransferPayload {
|
|
131
|
+
return (transfer as ERC1155TransferPayload).tokenId === undefined;
|
|
132
|
+
}
|
|
133
|
+
|
|
134
|
+
/**
|
|
135
|
+
* Typeguard to determine if a transfer payload is an ERC1155 Transfer
|
|
136
|
+
*
|
|
137
|
+
* @export
|
|
138
|
+
* @param {(FungibleTransferPayload | ERC1155TransferPayload)} transfer
|
|
139
|
+
* @returns {transfer is ERC1155TransferPayload}
|
|
140
|
+
*/
|
|
141
|
+
export function isERC1155TransferPayload(
|
|
142
|
+
transfer: FungibleTransferPayload | ERC1155TransferPayload,
|
|
143
|
+
): transfer is ERC1155TransferPayload {
|
|
144
|
+
return (transfer as ERC1155TransferPayload).tokenId !== undefined;
|
|
145
|
+
}
|
|
146
|
+
|
|
147
|
+
/**
|
|
148
|
+
* Given either a Fungible transfer, or ERC1155 transfer, will properly encode parameters for transfers, claims, disbursements, allocations, etc.
|
|
149
|
+
*
|
|
150
|
+
* @export
|
|
151
|
+
* @param {(FungibleTransferPayload | ERC1155TransferPayload)} transfer
|
|
152
|
+
* @returns {Hex}
|
|
153
|
+
* @throws {@link UnknownTransferPayloadSupplied}
|
|
154
|
+
*/
|
|
155
|
+
export function prepareTransfer(
|
|
156
|
+
transfer: FungibleTransferPayload | ERC1155TransferPayload,
|
|
157
|
+
) {
|
|
158
|
+
if (isFungibleTransfer(transfer)) {
|
|
159
|
+
return prepareFungibleTransfer(transfer);
|
|
160
|
+
}
|
|
161
|
+
if (isERC1155TransferPayload(transfer)) {
|
|
162
|
+
return prepareERC1155Transfer(transfer);
|
|
163
|
+
}
|
|
164
|
+
throw new UnknownTransferPayloadSupplied(transfer);
|
|
165
|
+
}
|
|
166
|
+
|
|
167
|
+
/**
|
|
168
|
+
* A minimal budget implementation that simply holds and distributes tokens (ERC20-like and native)
|
|
169
|
+
* This type of budget supports ETH, ERC20, and ERC1155 assets only
|
|
170
|
+
*
|
|
171
|
+
* @export
|
|
172
|
+
* @class ManagedBudget
|
|
173
|
+
* @typedef {ManagedBudget}
|
|
174
|
+
* @extends {DeployableTargetWithRBAC<ManagedBudgetPayload>}
|
|
175
|
+
*/
|
|
176
|
+
export class ManagedBudget extends DeployableTargetWithRBAC<
|
|
177
|
+
ManagedBudgetPayload,
|
|
178
|
+
typeof managedBudgetAbi
|
|
179
|
+
> {
|
|
180
|
+
/**
|
|
181
|
+
* @inheritdoc
|
|
182
|
+
*
|
|
183
|
+
* @public
|
|
184
|
+
* @readonly
|
|
185
|
+
* @type {*}
|
|
186
|
+
*/
|
|
187
|
+
public override readonly abi = managedBudgetAbi;
|
|
188
|
+
/**
|
|
189
|
+
* @inheritdoc
|
|
190
|
+
*
|
|
191
|
+
* @public
|
|
192
|
+
* @static
|
|
193
|
+
* @type {Record<number, Address>}
|
|
194
|
+
*/
|
|
195
|
+
public static override bases: Record<number, Address> = {
|
|
196
|
+
...(ManagedBudgetBases as Record<number, Address>),
|
|
197
|
+
};
|
|
198
|
+
/**
|
|
199
|
+
* @inheritdoc
|
|
200
|
+
*
|
|
201
|
+
* @public
|
|
202
|
+
* @static
|
|
203
|
+
* @type {RegistryType}
|
|
204
|
+
*/
|
|
205
|
+
public static override registryType: RegistryType = RegistryType.BUDGET;
|
|
206
|
+
|
|
207
|
+
/**
|
|
208
|
+
* Allocates assets to the budget.
|
|
209
|
+
* The caller must have already approved the contract to transfer the asset
|
|
210
|
+
* If the asset transfer fails, the allocation will revert
|
|
211
|
+
*
|
|
212
|
+
* @public
|
|
213
|
+
* @async
|
|
214
|
+
* @param {(FungibleTransferPayload | ERC1155TransferPayload)} transfer
|
|
215
|
+
* @param {?WriteParams} [params]
|
|
216
|
+
* @returns {Promise<boolean>} - True if the allocation was successful
|
|
217
|
+
*/
|
|
218
|
+
public async allocate(
|
|
219
|
+
transfer: FungibleTransferPayload | ERC1155TransferPayload,
|
|
220
|
+
params?: WriteParams<typeof managedBudgetAbi, 'allocate'>,
|
|
221
|
+
) {
|
|
222
|
+
return await this.awaitResult(this.allocateRaw(transfer, params));
|
|
223
|
+
}
|
|
224
|
+
|
|
225
|
+
/**
|
|
226
|
+
* Allocates assets to the budget.
|
|
227
|
+
* The caller must have already approved the contract to transfer the asset
|
|
228
|
+
* If the asset transfer fails, the allocation will revert
|
|
229
|
+
*
|
|
230
|
+
* @public
|
|
231
|
+
* @async
|
|
232
|
+
* @param {(FungibleTransferPayload | ERC1155TransferPayload)} transfer
|
|
233
|
+
* @param {?WriteParams} [params]
|
|
234
|
+
* @returns {Promise<{ hash: `0x${string}`; result: boolean; }>} - True if the allocation was successful
|
|
235
|
+
*/
|
|
236
|
+
public async allocateRaw(
|
|
237
|
+
transfer: FungibleTransferPayload | ERC1155TransferPayload,
|
|
238
|
+
params?: WriteParams<typeof managedBudgetAbi, 'allocate'>,
|
|
239
|
+
) {
|
|
240
|
+
const { request, result } = await simulateManagedBudgetAllocate(
|
|
241
|
+
this._config,
|
|
242
|
+
{
|
|
243
|
+
address: this.assertValidAddress(),
|
|
244
|
+
args: [prepareTransfer(transfer)],
|
|
245
|
+
...this.optionallyAttachAccount(),
|
|
246
|
+
// biome-ignore lint/suspicious/noExplicitAny: Accept any shape of valid wagmi/viem parameters, wagmi does the same thing internally
|
|
247
|
+
...(params as any),
|
|
248
|
+
},
|
|
249
|
+
);
|
|
250
|
+
const hash = await writeManagedBudgetAllocate(this._config, request);
|
|
251
|
+
return { hash, result };
|
|
252
|
+
}
|
|
253
|
+
|
|
254
|
+
/**
|
|
255
|
+
* Clawbacks assets from the budget.
|
|
256
|
+
* Only the owner can directly clawback assets from the budget
|
|
257
|
+
* If the amount is zero, the entire balance of the asset will be transferred to the receiver
|
|
258
|
+
* If the asset transfer fails, the reclamation will revert
|
|
259
|
+
*
|
|
260
|
+
* @public
|
|
261
|
+
* @async
|
|
262
|
+
* @param {(FungibleTransferPayload | ERC1155TransferPayload)} transfer
|
|
263
|
+
* @param {?WriteParams} [params]
|
|
264
|
+
* @returns {Promise<boolean>} - True if the request was successful
|
|
265
|
+
*/
|
|
266
|
+
public async clawback(
|
|
267
|
+
transfer: FungibleTransferPayload | ERC1155TransferPayload,
|
|
268
|
+
params?: WriteParams<typeof managedBudgetAbi, 'clawback'>,
|
|
269
|
+
) {
|
|
270
|
+
return await this.awaitResult(this.clawbackRaw(transfer, params));
|
|
271
|
+
}
|
|
272
|
+
|
|
273
|
+
/**
|
|
274
|
+
* Clawbacks assets from the budget.
|
|
275
|
+
* Only the owner can directly clawback assets from the budget
|
|
276
|
+
* If the amount is zero, the entire balance of the asset will be transferred to the receiver
|
|
277
|
+
* If the asset transfer fails, the reclamation will revert
|
|
278
|
+
*
|
|
279
|
+
* @public
|
|
280
|
+
* @async
|
|
281
|
+
* @param {(FungibleTransferPayload | ERC1155TransferPayload)} transfer
|
|
282
|
+
* @param {?WriteParams} [params]
|
|
283
|
+
* @returns {Promise<{ hash: `0x${string}`; result: boolean; }>} - True if the request was successful
|
|
284
|
+
*/
|
|
285
|
+
public async clawbackRaw(
|
|
286
|
+
transfer: FungibleTransferPayload | ERC1155TransferPayload,
|
|
287
|
+
params?: WriteParams<typeof managedBudgetAbi, 'clawback'>,
|
|
288
|
+
) {
|
|
289
|
+
const { request, result } = await simulateManagedBudgetClawback(
|
|
290
|
+
this._config,
|
|
291
|
+
{
|
|
292
|
+
address: this.assertValidAddress(),
|
|
293
|
+
args: [prepareTransfer(transfer)],
|
|
294
|
+
...this.optionallyAttachAccount(),
|
|
295
|
+
// biome-ignore lint/suspicious/noExplicitAny: Accept any shape of valid wagmi/viem parameters, wagmi does the same thing internally
|
|
296
|
+
...(params as any),
|
|
297
|
+
},
|
|
298
|
+
);
|
|
299
|
+
const hash = await writeManagedBudgetClawback(this._config, request);
|
|
300
|
+
return { hash, result };
|
|
301
|
+
}
|
|
302
|
+
|
|
303
|
+
/**
|
|
304
|
+
* Disburses assets from the budget to a single recipient
|
|
305
|
+
* If the asset transfer fails, the disbursement will revert
|
|
306
|
+
*
|
|
307
|
+
* @public
|
|
308
|
+
* @async
|
|
309
|
+
* @param {(FungibleTransferPayload | ERC1155TransferPayload)} transfer
|
|
310
|
+
* @param {?WriteParams} [params]
|
|
311
|
+
* @returns {Promise<boolean>} - True if the disbursement was successful
|
|
312
|
+
*/
|
|
313
|
+
public async disburse(
|
|
314
|
+
transfer: FungibleTransferPayload | ERC1155TransferPayload,
|
|
315
|
+
params?: WriteParams<typeof managedBudgetAbi, 'disburse'>,
|
|
316
|
+
) {
|
|
317
|
+
return await this.awaitResult(this.disburseRaw(transfer, params));
|
|
318
|
+
}
|
|
319
|
+
|
|
320
|
+
/**
|
|
321
|
+
* Disburses assets from the budget to a single recipient
|
|
322
|
+
* If the asset transfer fails, the disbursement will revert
|
|
323
|
+
*
|
|
324
|
+
* @public
|
|
325
|
+
* @async
|
|
326
|
+
* @param {(FungibleTransferPayload | ERC1155TransferPayload)} transfer
|
|
327
|
+
* @param {?WriteParams} [params]
|
|
328
|
+
* @returns {Promise<{ hash: `0x${string}`; result: boolean; }>} - True if the disbursement was successful
|
|
329
|
+
*/
|
|
330
|
+
public async disburseRaw(
|
|
331
|
+
transfer: FungibleTransferPayload | ERC1155TransferPayload,
|
|
332
|
+
params?: WriteParams<typeof managedBudgetAbi, 'disburse'>,
|
|
333
|
+
) {
|
|
334
|
+
const { request, result } = await simulateManagedBudgetDisburse(
|
|
335
|
+
this._config,
|
|
336
|
+
{
|
|
337
|
+
address: this.assertValidAddress(),
|
|
338
|
+
args: [prepareTransfer(transfer)],
|
|
339
|
+
...this.optionallyAttachAccount(),
|
|
340
|
+
// biome-ignore lint/suspicious/noExplicitAny: Accept any shape of valid wagmi/viem parameters, wagmi does the same thing internally
|
|
341
|
+
...(params as any),
|
|
342
|
+
},
|
|
343
|
+
);
|
|
344
|
+
const hash = await writeManagedBudgetDisburse(this._config, request);
|
|
345
|
+
return { hash, result };
|
|
346
|
+
}
|
|
347
|
+
|
|
348
|
+
/**
|
|
349
|
+
* Disburses assets from the budget to multiple recipients
|
|
350
|
+
*
|
|
351
|
+
* @public
|
|
352
|
+
* @async
|
|
353
|
+
* @param {Array<FungibleTransferPayload | ERC1155TransferPayload>} transfers
|
|
354
|
+
* @param {?WriteParams} [params]
|
|
355
|
+
* @returns {Promise<boolean>} - True if all disbursements were successful
|
|
356
|
+
*/
|
|
357
|
+
public async disburseBatch(
|
|
358
|
+
transfers: Array<FungibleTransferPayload | ERC1155TransferPayload>,
|
|
359
|
+
params?: WriteParams<typeof managedBudgetAbi, 'disburseBatch'>,
|
|
360
|
+
) {
|
|
361
|
+
return await this.awaitResult(this.disburseBatchRaw(transfers, params));
|
|
362
|
+
}
|
|
363
|
+
|
|
364
|
+
/**
|
|
365
|
+
* Disburses assets from the budget to multiple recipients
|
|
366
|
+
*
|
|
367
|
+
* @public
|
|
368
|
+
* @async
|
|
369
|
+
* @param {Array<FungibleTransferPayload | ERC1155TransferPayload>} transfers
|
|
370
|
+
* @param {?WriteParams} [params]
|
|
371
|
+
* @returns {Promise<{ hash: `0x${string}`; result: boolean; }>} - True if all disbursements were successful
|
|
372
|
+
*/
|
|
373
|
+
public async disburseBatchRaw(
|
|
374
|
+
transfers: Array<FungibleTransferPayload | ERC1155TransferPayload>,
|
|
375
|
+
params?: WriteParams<typeof managedBudgetAbi, 'disburseBatch'>,
|
|
376
|
+
) {
|
|
377
|
+
const { request, result } = await simulateManagedBudgetDisburseBatch(
|
|
378
|
+
this._config,
|
|
379
|
+
{
|
|
380
|
+
address: this.assertValidAddress(),
|
|
381
|
+
args: [transfers.map(prepareTransfer)],
|
|
382
|
+
...this.optionallyAttachAccount(),
|
|
383
|
+
// biome-ignore lint/suspicious/noExplicitAny: Accept any shape of valid wagmi/viem parameters, wagmi does the same thing internally
|
|
384
|
+
...(params as any),
|
|
385
|
+
},
|
|
386
|
+
);
|
|
387
|
+
const hash = await writeManagedBudgetDisburseBatch(this._config, request);
|
|
388
|
+
return { hash, result };
|
|
389
|
+
}
|
|
390
|
+
|
|
391
|
+
/**
|
|
392
|
+
* Get the owner of the budget
|
|
393
|
+
*
|
|
394
|
+
* @public
|
|
395
|
+
* @param {?ReadParams} [params]
|
|
396
|
+
* @returns {Promise<Address>}
|
|
397
|
+
*/
|
|
398
|
+
public owner(params?: ReadParams<typeof managedBudgetAbi, 'owner'>) {
|
|
399
|
+
return readManagedBudgetOwner(this._config, {
|
|
400
|
+
address: this.assertValidAddress(),
|
|
401
|
+
args: [],
|
|
402
|
+
// biome-ignore lint/suspicious/noExplicitAny: Accept any shape of valid wagmi/viem parameters, wagmi does the same thing internally
|
|
403
|
+
...(params as any),
|
|
404
|
+
});
|
|
405
|
+
}
|
|
406
|
+
|
|
407
|
+
/**
|
|
408
|
+
* Get the total amount of assets allocated to the budget, including any that have been distributed
|
|
409
|
+
* If a tokenId is provided, get the total amount of ERC1155 assets allocated to the budget, including any that have been distributed
|
|
410
|
+
*
|
|
411
|
+
* @public
|
|
412
|
+
* @param {Address} [asset="0x0000000000000000000000000000000000000000"] - The address of the asset
|
|
413
|
+
* @param {?(bigint | undefined)} [tokenId] - The ID of the token
|
|
414
|
+
* @param {?ReadParams} [params]
|
|
415
|
+
* @returns {Promise<bigint>} - The total amount of assets
|
|
416
|
+
*/
|
|
417
|
+
public total(
|
|
418
|
+
asset: Address = zeroAddress,
|
|
419
|
+
tokenId?: bigint | undefined,
|
|
420
|
+
params?: ReadParams<typeof managedBudgetAbi, 'total'>,
|
|
421
|
+
) {
|
|
422
|
+
return readManagedBudgetTotal(this._config, {
|
|
423
|
+
address: this.assertValidAddress(),
|
|
424
|
+
args: tokenId ? [asset, tokenId] : [asset],
|
|
425
|
+
// biome-ignore lint/suspicious/noExplicitAny: Accept any shape of valid wagmi/viem parameters, wagmi does the same thing internally
|
|
426
|
+
...(params as any),
|
|
427
|
+
});
|
|
428
|
+
}
|
|
429
|
+
|
|
430
|
+
/**
|
|
431
|
+
* Get the amount of assets available for distribution from the budget.
|
|
432
|
+
* If a tokenId is provided, get the amount of ERC1155 assets available for distribution from the budget
|
|
433
|
+
*
|
|
434
|
+
* @public
|
|
435
|
+
* @param {Address} [asset="0x0000000000000000000000000000000000000000"]
|
|
436
|
+
* @param {?(bigint | undefined)} [tokenId]
|
|
437
|
+
* @param {?ReadParams} [params]
|
|
438
|
+
* @returns {Promise<bigint>} - The amount of assets available
|
|
439
|
+
*/
|
|
440
|
+
public available(
|
|
441
|
+
asset: Address = zeroAddress,
|
|
442
|
+
tokenId?: bigint | undefined,
|
|
443
|
+
params?: ReadParams<typeof managedBudgetAbi, 'available'>,
|
|
444
|
+
) {
|
|
445
|
+
return readManagedBudgetAvailable(this._config, {
|
|
446
|
+
address: this.assertValidAddress(),
|
|
447
|
+
args: tokenId ? [asset, tokenId] : [asset],
|
|
448
|
+
// biome-ignore lint/suspicious/noExplicitAny: Accept any shape of valid wagmi/viem parameters, wagmi does the same thing internally
|
|
449
|
+
...(params as any),
|
|
450
|
+
});
|
|
451
|
+
}
|
|
452
|
+
|
|
453
|
+
/**
|
|
454
|
+
* Get the amount of assets that have been distributed from the budget.
|
|
455
|
+
* If a tokenId is provided, get the amount of ERC1155 assets that have been distributed from the budget
|
|
456
|
+
*
|
|
457
|
+
* @public
|
|
458
|
+
* @param {Address} [asset="0x0000000000000000000000000000000000000000"]
|
|
459
|
+
* @param {?(bigint | undefined)} [tokenId]
|
|
460
|
+
* @param {?ReadParams} [params]
|
|
461
|
+
* @returns {Promise<bigint>} - The amount of assets distributed
|
|
462
|
+
*/
|
|
463
|
+
public distributed(
|
|
464
|
+
asset: Address = zeroAddress,
|
|
465
|
+
tokenId?: bigint | undefined,
|
|
466
|
+
params?: ReadParams<typeof managedBudgetAbi, 'distributed'>,
|
|
467
|
+
) {
|
|
468
|
+
return readManagedBudgetDistributed(this._config, {
|
|
469
|
+
address: this.assertValidAddress(),
|
|
470
|
+
args: tokenId ? [asset, tokenId] : [asset],
|
|
471
|
+
// biome-ignore lint/suspicious/noExplicitAny: Accept any shape of valid wagmi/viem parameters, wagmi does the same thing internally
|
|
472
|
+
...(params as any),
|
|
473
|
+
});
|
|
474
|
+
}
|
|
475
|
+
|
|
476
|
+
/**
|
|
477
|
+
* @inheritdoc
|
|
478
|
+
*
|
|
479
|
+
* @public
|
|
480
|
+
* @param {?ManagedBudgetPayload} [_payload]
|
|
481
|
+
* @param {?DeployableOptions} [_options]
|
|
482
|
+
* @returns {GenericDeployableParams}
|
|
483
|
+
*/
|
|
484
|
+
public override buildParameters(
|
|
485
|
+
_payload?: ManagedBudgetPayload,
|
|
486
|
+
_options?: DeployableOptions,
|
|
487
|
+
): GenericDeployableParams {
|
|
488
|
+
const [payload, options] = this.validateDeploymentConfig(
|
|
489
|
+
_payload,
|
|
490
|
+
_options,
|
|
491
|
+
);
|
|
492
|
+
if (!payload.owner || payload.owner === zeroAddress) {
|
|
493
|
+
const owner = options.account
|
|
494
|
+
? options.account.address
|
|
495
|
+
: options.config
|
|
496
|
+
? getAccount(options.config).address
|
|
497
|
+
: this._account?.address;
|
|
498
|
+
if (owner) {
|
|
499
|
+
payload.owner = owner;
|
|
500
|
+
} else {
|
|
501
|
+
throw new DeployableUnknownOwnerProvidedError();
|
|
502
|
+
}
|
|
503
|
+
}
|
|
504
|
+
return {
|
|
505
|
+
abi: managedBudgetAbi,
|
|
506
|
+
bytecode: bytecode as Hex,
|
|
507
|
+
args: [prepareManagedBudgetPayload(payload)],
|
|
508
|
+
...this.optionallyAttachAccount(options.account),
|
|
509
|
+
};
|
|
510
|
+
}
|
|
511
|
+
}
|
|
512
|
+
|
|
513
|
+
/**
|
|
514
|
+
* Given a {@link ManagedBudgetPayload}, properly encode a `ManagedBudget.InitPayload` for use with {@link ManagedBudget} initialization.
|
|
515
|
+
*
|
|
516
|
+
* @param {ManagedBudgetPayload} param0
|
|
517
|
+
* @param {Address} param0.owner - The budget's owner
|
|
518
|
+
* @param {{}} param0.authorized - List of accounts authorized to use the budget. This list should include a Boost core address to interact with the protocol.
|
|
519
|
+
* @param {{}} param0.roles - List of roles to assign to the corresponding account by index.
|
|
520
|
+
* @returns {Hex}
|
|
521
|
+
*/
|
|
522
|
+
export const prepareManagedBudgetPayload = ({
|
|
523
|
+
owner,
|
|
524
|
+
authorized,
|
|
525
|
+
roles,
|
|
526
|
+
}: ManagedBudgetPayload) => {
|
|
527
|
+
return encodeAbiParameters(
|
|
528
|
+
parseAbiParameters([
|
|
529
|
+
'ManagedBudgetPayload payload',
|
|
530
|
+
'struct ManagedBudgetPayload { address owner; address[] authorized; uint256[] roles; }',
|
|
531
|
+
]),
|
|
532
|
+
[{ owner, authorized, roles: roles as unknown as Array<bigint> }],
|
|
533
|
+
);
|
|
534
|
+
};
|
|
@@ -0,0 +1,123 @@
|
|
|
1
|
+
import { loadFixture } from '@nomicfoundation/hardhat-network-helpers';
|
|
2
|
+
import { isAddress, parseEther, zeroAddress } from 'viem';
|
|
3
|
+
import { beforeAll, beforeEach, describe, expect, test } from 'vitest';
|
|
4
|
+
import type { MockERC20 } from '@boostxyz/test/MockERC20';
|
|
5
|
+
import {
|
|
6
|
+
type Fixtures,
|
|
7
|
+
defaultOptions,
|
|
8
|
+
deployFixtures,
|
|
9
|
+
freshVestingBudget,
|
|
10
|
+
fundErc20,
|
|
11
|
+
fundVestingBudget,
|
|
12
|
+
} from '@boostxyz/test/helpers';
|
|
13
|
+
import { testAccount } from '@boostxyz/test/viem';
|
|
14
|
+
import { VestingBudget } from './VestingBudget';
|
|
15
|
+
|
|
16
|
+
let fixtures: Fixtures, budget: VestingBudget, erc20: MockERC20;
|
|
17
|
+
|
|
18
|
+
beforeAll(async () => {
|
|
19
|
+
fixtures = await loadFixture(deployFixtures(defaultOptions));
|
|
20
|
+
});
|
|
21
|
+
|
|
22
|
+
describe.skip('VestingBudget', () => {
|
|
23
|
+
test('can successfully be deployed', async () => {
|
|
24
|
+
const budget = new VestingBudget(defaultOptions, {
|
|
25
|
+
owner: testAccount.address,
|
|
26
|
+
authorized: [],
|
|
27
|
+
start: 0n,
|
|
28
|
+
duration: 100n,
|
|
29
|
+
cliff: 5n,
|
|
30
|
+
});
|
|
31
|
+
await budget.deploy();
|
|
32
|
+
expect(isAddress(budget.assertValidAddress())).toBe(true);
|
|
33
|
+
});
|
|
34
|
+
|
|
35
|
+
test('can be owned', async () => {
|
|
36
|
+
const budget = await loadFixture(
|
|
37
|
+
freshVestingBudget(defaultOptions, fixtures),
|
|
38
|
+
);
|
|
39
|
+
expect(await budget.owner()).toBe(defaultOptions.account.address);
|
|
40
|
+
});
|
|
41
|
+
|
|
42
|
+
test('can have authorized users', async () => {
|
|
43
|
+
const budget = await loadFixture(
|
|
44
|
+
freshVestingBudget(defaultOptions, fixtures),
|
|
45
|
+
);
|
|
46
|
+
expect(await budget.isAuthorized(defaultOptions.account.address)).toBe(
|
|
47
|
+
true,
|
|
48
|
+
);
|
|
49
|
+
expect(await budget.isAuthorized(zeroAddress)).toBe(false);
|
|
50
|
+
});
|
|
51
|
+
|
|
52
|
+
test('can have no initial balance', async () => {
|
|
53
|
+
const budget = await loadFixture(
|
|
54
|
+
freshVestingBudget(defaultOptions, fixtures),
|
|
55
|
+
);
|
|
56
|
+
expect(await budget.available()).toBe(0n);
|
|
57
|
+
});
|
|
58
|
+
|
|
59
|
+
describe('can allocate', () => {
|
|
60
|
+
beforeEach(async () => {
|
|
61
|
+
budget = await loadFixture(freshVestingBudget(defaultOptions, fixtures));
|
|
62
|
+
erc20 = await loadFixture(fundErc20(defaultOptions));
|
|
63
|
+
});
|
|
64
|
+
|
|
65
|
+
test('native assets', async () => {
|
|
66
|
+
await budget.allocate(
|
|
67
|
+
{
|
|
68
|
+
amount: parseEther('1.0'),
|
|
69
|
+
asset: zeroAddress,
|
|
70
|
+
target: defaultOptions.account.address,
|
|
71
|
+
},
|
|
72
|
+
{
|
|
73
|
+
value: parseEther('1.0'),
|
|
74
|
+
},
|
|
75
|
+
);
|
|
76
|
+
expect(await budget.available()).toBe(parseEther('1.0'));
|
|
77
|
+
});
|
|
78
|
+
|
|
79
|
+
test('erc20', async () => {
|
|
80
|
+
await erc20.approve(budget.assertValidAddress(), parseEther('100'));
|
|
81
|
+
await budget.allocate({
|
|
82
|
+
amount: parseEther('100'),
|
|
83
|
+
asset: erc20.assertValidAddress(),
|
|
84
|
+
target: defaultOptions.account.address,
|
|
85
|
+
});
|
|
86
|
+
expect(await budget.available(erc20.assertValidAddress())).toBe(
|
|
87
|
+
parseEther('100'),
|
|
88
|
+
);
|
|
89
|
+
});
|
|
90
|
+
});
|
|
91
|
+
|
|
92
|
+
describe('can disburse', () => {
|
|
93
|
+
beforeEach(async () => {
|
|
94
|
+
const budgetFixtures = await loadFixture(
|
|
95
|
+
fundVestingBudget(defaultOptions, fixtures),
|
|
96
|
+
);
|
|
97
|
+
budget = budgetFixtures.budget;
|
|
98
|
+
erc20 = budgetFixtures.erc20;
|
|
99
|
+
});
|
|
100
|
+
|
|
101
|
+
test('native assets', async () => {
|
|
102
|
+
await budget.disburse({
|
|
103
|
+
amount: parseEther('1.0'),
|
|
104
|
+
asset: zeroAddress,
|
|
105
|
+
target: defaultOptions.account.address,
|
|
106
|
+
});
|
|
107
|
+
|
|
108
|
+
expect(await budget.available()).toBe(0n);
|
|
109
|
+
});
|
|
110
|
+
|
|
111
|
+
test('erc20 assets', async () => {
|
|
112
|
+
await budget.disburse({
|
|
113
|
+
amount: parseEther('10'),
|
|
114
|
+
asset: erc20.assertValidAddress(),
|
|
115
|
+
target: defaultOptions.account.address,
|
|
116
|
+
});
|
|
117
|
+
|
|
118
|
+
expect(await budget.available(erc20.assertValidAddress())).toBe(
|
|
119
|
+
parseEther('90'),
|
|
120
|
+
);
|
|
121
|
+
});
|
|
122
|
+
});
|
|
123
|
+
});
|