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