Skip to content

Commit

Permalink
chore(sdk): boostregistry.initialize, better target .isBase inference…
Browse files Browse the repository at this point in the history
…, comments
  • Loading branch information
sammccord committed Sep 20, 2024
1 parent 88c0b99 commit 15f71e8
Show file tree
Hide file tree
Showing 7 changed files with 67 additions and 10 deletions.
5 changes: 5 additions & 0 deletions .changeset/swift-rivers-deny.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@boostxyz/sdk": minor
---

add `BoostRegistry.initialize` as more obvious alternative name for `.clone`, make `.deploy` protected for Boost targets, await valid action steps, better `isBase` defaults, update comments
10 changes: 9 additions & 1 deletion packages/sdk/src/Actions/EventAction.ts
Original file line number Diff line number Diff line change
Expand Up @@ -46,8 +46,16 @@ import {
isEventActionPayloadSimple,
prepareEventActionPayload,
} from '../utils';
import type { SignatureType } from './../utils';

export type { EventActionPayload };
export type {
EventActionPayload,
ActionStep,
ActionClaimant,
SignatureType,
FilterType,
PrimitiveType,
};

/**
* A generic event action
Expand Down
5 changes: 3 additions & 2 deletions packages/sdk/src/AllowLists/SimpleAllowList.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ import {
type ReadParams,
RegistryType,
type SimpleAllowListPayload,
type WriteParams,
prepareSimpleAllowListPayload,
} from '../utils';

Expand Down Expand Up @@ -120,7 +121,7 @@ export class SimpleAllowList extends DeployableTarget<
public async setAllowed(
addresses: Address[],
allowed: boolean[],
params?: ReadParams<typeof simpleAllowListAbi, 'setAllowed'>,
params?: WriteParams<typeof simpleAllowListAbi, 'setAllowed'>,
) {
return this.awaitResult(this.setAllowedRaw(addresses, allowed, params));
}
Expand Down Expand Up @@ -168,7 +169,7 @@ export class SimpleAllowList extends DeployableTarget<
public async grantRoles(
address: Address,
role: bigint,
params?: ReadParams<typeof simpleAllowListAbi, 'grantRoles'>,
params?: WriteParams<typeof simpleAllowListAbi, 'grantRoles'>,
) {
return this.awaitResult(this.grantRolesRaw(address, role, params));
}
Expand Down
5 changes: 4 additions & 1 deletion packages/sdk/src/BoostCore.ts
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,7 @@ import {
BoostCoreNoIdentifierEmitted,
BudgetMustAuthorizeBoostCore,
DeployableUnknownOwnerProvidedError,
IncentiveNotCloneableError,
NoContractAddressUponReceiptError,
} from './errors';
import {
Expand Down Expand Up @@ -247,7 +248,8 @@ export class BoostCore extends Deployable<
}
//@ts-expect-error I can't set this property on the class because for some reason it takes super out of constructor scope?
this.abi = boostCoreAbi;
} /**
}
/**
* Create a new Boost.
*
* @public
Expand Down Expand Up @@ -404,6 +406,7 @@ export class BoostCore extends Deployable<
const incentive = incentives.at(i)!;
if (incentive.address) {
const isBase = incentive.address === incentive.base || incentive.isBase;
if (!isBase) throw new IncentiveNotCloneableError(incentive);
incentivesPayloads[i] = {
isBase: isBase,
instance: incentive.address,
Expand Down
21 changes: 21 additions & 0 deletions packages/sdk/src/BoostRegistry.ts
Original file line number Diff line number Diff line change
Expand Up @@ -227,6 +227,27 @@ export class BoostRegistry extends Deployable<
return { hash, result };
}

/**
* Initialize a new instance of a registered base implementation, returning the provided target with a new address set on it.
* This method is the same as `clone`, but serves to make its function more obvious as to why you'd need to use it.
*
* @public
* @async
* @template {DeployableTarget} Target
* @param {string} displayName - The display name for the clone
* @param {Target} target - An instance of a target contract to clone and initialize
* @param {?WriteParams<typeof boostRegistryAbi, 'deployClone'>} [params]
* @returns {Target} - The provided instance, but with a new address attached.
* biome-ignore lint/suspicious/noExplicitAny: any deployable target will suffice
*/
public async initialize<Target extends DeployableTarget<any, any>>(
displayName: string,
target: Target,
params?: WriteParams<typeof boostRegistryAbi, 'deployClone'>,
): Promise<Target> {
return this.clone(displayName, target, params);
}

/**
* Deploy a new instance of a registered base implementation, returning the provided target with a new address set on it.
*
Expand Down
10 changes: 8 additions & 2 deletions packages/sdk/src/Deployable/Deployable.ts
Original file line number Diff line number Diff line change
Expand Up @@ -140,6 +140,9 @@ export class Deployable<

/**
* High level deployment function to deploy and await the contract address.
* This is mainly a convenience method to easily deploy a contract, but will not initialize a `Cloneable`,
* which makes it useless for Boost components.
* Obviously you can ignore the TS warnings and use this, but you shouldn't in most all cases.
*
* @public
* @async
Expand All @@ -148,7 +151,7 @@ export class Deployable<
* @param {?Omit<WaitForTransactionReceiptParameters, 'hash'>} [waitParams] - See [viem.WaitForTransactionReceipt](https://v1.viem.sh/docs/actions/public/waitForTransactionReceipt.html#waitfortransactionreceipt)
* @returns {unknown}
*/
public async deploy(
protected async deploy(
_payload?: Payload,
_options?: DeployableOptions,
waitParams?: Omit<WaitForTransactionReceiptParameters, 'hash'>,
Expand All @@ -165,6 +168,9 @@ export class Deployable<

/**
* The lower level contract deployment function that does not await for the transaction receipt.
* This is mainly a convenience method to easily deploy a contract, but will not initialize a `Cloneable`,
* which makes it useless for Boost components.
* Obviously you can ignore the TS warnings and use this, but you shouldn't in most all cases.
*
* @public
* @async
Expand All @@ -175,7 +181,7 @@ export class Deployable<
* @throws {@link DeployableWagmiConfigurationRequiredError}
* @throws {@link DeployableMissingPayloadError}
*/
public async deployRaw(
protected async deployRaw(
_payload?: Payload,
_options?: DeployableOptions,
): Promise<Hash> {
Expand Down
21 changes: 17 additions & 4 deletions packages/sdk/src/Deployable/DeployableTarget.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import {
type Hash,
type Hex,
type WaitForTransactionReceiptParameters,
isAddress,
zeroAddress,
} from 'viem';
import {
Expand Down Expand Up @@ -58,7 +59,11 @@ export class DeployableTarget<
* @readonly
* @type {boolean}
*/
readonly isBase: boolean = true;
protected _isBase = true;
get isBase() {
if (!!this.address && this.address !== this.base) return false;
return this._isBase;
}

/**
* Creates an instance of DeployableTarget.
Expand All @@ -74,7 +79,15 @@ export class DeployableTarget<
isBase?: boolean,
) {
super(options, payload);
if (isBase !== undefined) this.isBase = isBase;
// if supplying a custom address, safe enough to assume it is not a base address which makes reusing contracts like budgets easier
if (
typeof payload === 'string' &&
isAddress(payload) &&
payload !== this.base &&
payload !== zeroAddress
)
isBase = false;
if (isBase !== undefined) this._isBase = isBase;
}

/**
Expand Down Expand Up @@ -109,7 +122,7 @@ export class DeployableTarget<
* @param {?Omit<WaitForTransactionReceiptParameters, 'hash'>} [waitParams]
* @returns {unknown}
*/
public override async deploy(
protected override async deploy(
payload?: Payload,
options?: DeployableOptions,
waitParams?: Omit<WaitForTransactionReceiptParameters, 'hash'>,
Expand All @@ -128,7 +141,7 @@ export class DeployableTarget<
* @param {?DeployableOptions} [_options]
* @returns {Promise<Hash>}
*/
public override async deployRaw(
protected override async deployRaw(
_payload?: Payload,
_options?: DeployableOptions,
): Promise<Hash> {
Expand Down

0 comments on commit 15f71e8

Please sign in to comment.