Skip to content

Commit

Permalink
[BOOST-4772] Refactor Budget Methods (#126)
Browse files Browse the repository at this point in the history
  • Loading branch information
sammccord authored Sep 26, 2024
2 parents 0208120 + 4b65cfe commit 65e3762
Show file tree
Hide file tree
Showing 7 changed files with 38 additions and 33 deletions.
5 changes: 5 additions & 0 deletions .changeset/silver-bobcats-switch.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@boostxyz/sdk": patch
---

refactor budget methods to make assets have zero address as the default value
18 changes: 9 additions & 9 deletions packages/sdk/src/Budgets/ManagedBudget.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -42,8 +42,8 @@ describe('ManagedBudget', () => {
const budget = await loadFixture(
freshManagedBudget(defaultOptions, fixtures),
);
const one = accounts.at(1)!.account;
const two = accounts.at(2)!.account;
const one = accounts[1].account;
const two = accounts[2].account;
await budget.setAuthorized([one, two], [true, true]);
expect(await budget.hasAllRoles(one, ManagedBudgetRoles.ADMIN)).toBe(false);
expect(await budget.hasAllRoles(one, ManagedBudgetRoles.MANAGER)).toBe(
Expand All @@ -58,8 +58,8 @@ describe('ManagedBudget', () => {
const budget = await loadFixture(
freshManagedBudget(defaultOptions, fixtures),
);
const admin = accounts.at(1)!.account;
const manager = accounts.at(2)!.account;
const admin = accounts[1].account;
const manager = accounts[2].account;
await budget.grantRoles(
[admin, manager],
[ManagedBudgetRoles.ADMIN, ManagedBudgetRoles.MANAGER],
Expand All @@ -76,8 +76,8 @@ describe('ManagedBudget', () => {
const budget = await loadFixture(
freshManagedBudget(defaultOptions, fixtures),
);
const admin = accounts.at(1)!.account;
const manager = accounts.at(2)!.account;
const admin = accounts[1].account;
const manager = accounts[2].account;
await budget.grantRoles(
[admin, manager],
[ManagedBudgetRoles.ADMIN, ManagedBudgetRoles.MANAGER],
Expand Down Expand Up @@ -115,7 +115,7 @@ describe('ManagedBudget', () => {
const budget = await loadFixture(
freshManagedBudget(defaultOptions, fixtures),
);
expect(await budget.available(zeroAddress)).toBe(0n);
expect(await budget.available()).toBe(0n);
});

describe('can allocate', () => {
Expand All @@ -136,7 +136,7 @@ describe('ManagedBudget', () => {
value: parseEther('1.0'),
},
);
expect(await budget.available(zeroAddress)).toBe(parseEther('1.0'));
expect(await budget.available()).toBe(parseEther('1.0'));
});

test('erc20', async () => {
Expand Down Expand Up @@ -186,7 +186,7 @@ describe('ManagedBudget', () => {
target: defaultOptions.account.address,
});

expect(await budget.available(zeroAddress)).toBe(0n);
expect(await budget.available()).toBe(0n);
});

test('erc20 assets', async () => {
Expand Down
12 changes: 6 additions & 6 deletions packages/sdk/src/Budgets/ManagedBudget.ts
Original file line number Diff line number Diff line change
Expand Up @@ -682,13 +682,13 @@ export class ManagedBudget extends DeployableTarget<
* If a tokenId is provided, get the total amount of ERC1155 assets allocated to the budget, including any that have been distributed
*
* @public
* @param {Address} asset - The address of the asset
* @param {Address} [asset="0x0000000000000000000000000000000000000000"] - The address of the asset
* @param {?(bigint | undefined)} [tokenId] - The ID of the token
* @param {?ReadParams<typeof managedBudgetAbi, 'total'>} [params]
* @returns {Promise<bigint>} - The total amount of assets
*/
public total(
asset: Address,
asset: Address = zeroAddress,
tokenId?: bigint | undefined,
params?: ReadParams<typeof managedBudgetAbi, 'total'>,
) {
Expand All @@ -705,13 +705,13 @@ export class ManagedBudget extends DeployableTarget<
* If a tokenId is provided, get the amount of ERC1155 assets available for distribution from the budget
*
* @public
* @param {Address} asset
* @param {Address} [asset="0x0000000000000000000000000000000000000000"]
* @param {?(bigint | undefined)} [tokenId]
* @param {?ReadParams<typeof managedBudgetAbi, 'available'>} [params]
* @returns {Promise<bigint>} - The amount of assets available
*/
public available(
asset: Address,
asset: Address = zeroAddress,
tokenId?: bigint | undefined,
params?: ReadParams<typeof managedBudgetAbi, 'available'>,
) {
Expand All @@ -728,13 +728,13 @@ export class ManagedBudget extends DeployableTarget<
* If a tokenId is provided, get the amount of ERC1155 assets that have been distributed from the budget
*
* @public
* @param {Address} asset
* @param {Address} [asset="0x0000000000000000000000000000000000000000"]
* @param {?(bigint | undefined)} [tokenId]
* @param {?ReadParams<typeof managedBudgetAbi, 'distributed'>} [params]
* @returns {Promise<bigint>} - The amount of assets distributed
*/
public distributed(
asset: Address,
asset: Address = zeroAddress,
tokenId?: bigint | undefined,
params?: ReadParams<typeof managedBudgetAbi, 'distributed'>,
) {
Expand Down
6 changes: 3 additions & 3 deletions packages/sdk/src/Budgets/SimpleBudget.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ describe.skip('SimpleBudget', () => {

test('can have no initial balance', async () => {
const budget = await loadFixture(freshBudget(defaultOptions, fixtures));
expect(await budget.available(zeroAddress)).toBe(0n);
expect(await budget.available()).toBe(0n);
});

describe('can allocate', () => {
Expand All @@ -71,7 +71,7 @@ describe.skip('SimpleBudget', () => {
value: parseEther('1.0'),
},
);
expect(await budget.available(zeroAddress)).toBe(parseEther('1.0'));
expect(await budget.available()).toBe(parseEther('1.0'));
});

test('erc20', async () => {
Expand Down Expand Up @@ -121,7 +121,7 @@ describe.skip('SimpleBudget', () => {
target: defaultOptions.account.address,
});

expect(await budget.available(zeroAddress)).toBe(0n);
expect(await budget.available()).toBe(0n);
});

test('erc20 assets', async () => {
Expand Down
12 changes: 6 additions & 6 deletions packages/sdk/src/Budgets/SimpleBudget.ts
Original file line number Diff line number Diff line change
Expand Up @@ -441,13 +441,13 @@ export class SimpleBudget extends DeployableTarget<
* If a tokenId is provided, get the total amount of ERC1155 assets allocated to the budget, including any that have been distributed
*
* @public
* @param {Address} asset - The address of the asset
* @param {Address} [asset="0x0000000000000000000000000000000000000000"] - The address of the asset
* @param {?(bigint | undefined)} [tokenId] - The ID of the token
* @param {?ReadParams<typeof simpleBudgetAbi, 'total'>} [params]
* @returns {Promise<bigint>} - The total amount of assets
*/
public total(
asset: Address,
asset: Address = zeroAddress,
tokenId?: bigint | undefined,
params?: ReadParams<typeof simpleBudgetAbi, 'total'>,
) {
Expand All @@ -464,13 +464,13 @@ export class SimpleBudget extends DeployableTarget<
* If a tokenId is provided, get the amount of ERC1155 assets available for distribution from the budget
*
* @public
* @param {Address} asset
* @param {Address} [asset="0x0000000000000000000000000000000000000000"]
* @param {?(bigint | undefined)} [tokenId]
* @param {?ReadParams<typeof simpleBudgetAbi, 'available'>} [params]
* @returns {Promise<bigint>} - The amount of assets available
*/
public available(
asset: Address,
asset: Address = zeroAddress,
tokenId?: bigint | undefined,
params?: ReadParams<typeof simpleBudgetAbi, 'available'>,
) {
Expand All @@ -487,13 +487,13 @@ export class SimpleBudget extends DeployableTarget<
* If a tokenId is provided, get the amount of ERC1155 assets that have been distributed from the budget
*
* @public
* @param {Address} asset
* @param {Address} [asset="0x0000000000000000000000000000000000000000"]
* @param {?(bigint | undefined)} [tokenId]
* @param {?ReadParams<typeof simpleBudgetAbi, 'distributed'>} [params]
* @returns {Promise<bigint>} - The amount of assets distributed
*/
public distributed(
asset: Address,
asset: Address = zeroAddress,
tokenId?: bigint | undefined,
params?: ReadParams<typeof simpleBudgetAbi, 'distributed'>,
) {
Expand Down
6 changes: 3 additions & 3 deletions packages/sdk/src/Budgets/VestingBudget.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ describe.skip('VestingBudget', () => {
const budget = await loadFixture(
freshVestingBudget(defaultOptions, fixtures),
);
expect(await budget.available(zeroAddress)).toBe(0n);
expect(await budget.available()).toBe(0n);
});

describe('can allocate', () => {
Expand All @@ -73,7 +73,7 @@ describe.skip('VestingBudget', () => {
value: parseEther('1.0'),
},
);
expect(await budget.available(zeroAddress)).toBe(parseEther('1.0'));
expect(await budget.available()).toBe(parseEther('1.0'));
});

test('erc20', async () => {
Expand Down Expand Up @@ -105,7 +105,7 @@ describe.skip('VestingBudget', () => {
target: defaultOptions.account.address,
});

expect(await budget.available(zeroAddress)).toBe(0n);
expect(await budget.available()).toBe(0n);
});

test('erc20 assets', async () => {
Expand Down
12 changes: 6 additions & 6 deletions packages/sdk/src/Budgets/VestingBudget.ts
Original file line number Diff line number Diff line change
Expand Up @@ -480,12 +480,12 @@ export class VestingBudget extends DeployableTarget<
* This is equal to the sum of the total current balance and the total distributed amount
*
* @public
* @param {Address} asset - The address of the asset (or the zero address for native assets)
* @param {Address} [asset="0x0000000000000000000000000000000000000000"] - The address of the asset (or the zero address for native assets)
* @param {?ReadParams<typeof vestingBudgetAbi, 'total'>} [params]
* @returns {Promise<bigint>}
*/
public total(
asset: Address,
asset: Address = zeroAddress,
params?: ReadParams<typeof vestingBudgetAbi, 'total'>,
) {
return readVestingBudgetTotal(this._config, {
Expand All @@ -501,12 +501,12 @@ export class VestingBudget extends DeployableTarget<
* This is equal to the total vested amount minus any already distributed
*
* @public
* @param {Address} asset - The address of the asset (or the zero address for native assets)
* @param {Address} [asset="0x0000000000000000000000000000000000000000"] - The address of the asset (or the zero address for native assets)
* @param {?ReadParams<typeof vestingBudgetAbi, 'available'>} [params]
* @returns {Promise<bigint>} - The amount of assets currently available for distribution
*/
public available(
asset: Address,
asset: Address = zeroAddress,
params?: ReadParams<typeof vestingBudgetAbi, 'available'>,
) {
return readVestingBudgetAvailable(this._config, {
Expand All @@ -521,12 +521,12 @@ export class VestingBudget extends DeployableTarget<
* Get the amount of assets that have been distributed from the budget
*
* @public
* @param {Address} asset
* @param {Address} [asset="0x0000000000000000000000000000000000000000"]
* @param {?ReadParams<typeof vestingBudgetAbi, 'distributed'>} [params]
* @returns {Promise<bigint>} - The amount of assets distributed
*/
public distributed(
asset: Address,
asset: Address = zeroAddress,
params?: ReadParams<typeof vestingBudgetAbi, 'distributed'>,
) {
return readVestingBudgetDistributed(this._config, {
Expand Down

0 comments on commit 65e3762

Please sign in to comment.