Skip to content

Commit

Permalink
chore(sdk): fix budget fixture helpers
Browse files Browse the repository at this point in the history
  • Loading branch information
sammccord committed Jul 10, 2024
1 parent e68df49 commit dedfa8d
Show file tree
Hide file tree
Showing 7 changed files with 43 additions and 35 deletions.
40 changes: 8 additions & 32 deletions packages/sdk/src/BoostCore.ts
Original file line number Diff line number Diff line change
Expand Up @@ -265,14 +265,10 @@ export class BoostCore extends Deployable<[Address, Address]> {
// biome-ignore lint/style/noNonNullAssertion: this will never be undefined
const incentive = incentives.at(i)!;
if (incentive.address) {
const isBase = allowList.address === allowList.base || allowList.isBase;
incentivesPayloads[i] = {
isBase: isBase,
instance: incentive.address,
parameters: isBase
? incentive.buildParameters(undefined, options).args.at(0) ||
zeroHash
: zeroHash,
isBase: true,
instance: incentive.base,
parameters: incentive.buildParameters(undefined, options).args.at(0)!,
};
} else {
// biome-ignore lint/style/noNonNullAssertion: this will never be undefined
Expand Down Expand Up @@ -547,54 +543,34 @@ export class BoostCore extends Deployable<[Address, Address]> {
options,
);
}
AllowListIncentive(
options: DeployablePayloadOrAddress<AllowListIncentivePayload>,
isBase?: boolean,
) {
AllowListIncentive(options: AllowListIncentivePayload) {
return new AllowListIncentive(
{ config: this._config, account: this._account },
options,
isBase,
);
}
CGDAIncentive(
options: DeployablePayloadOrAddress<CGDAIncentivePayload>,
isBase?: boolean,
) {
CGDAIncentive(options: CGDAIncentivePayload) {
return new CGDAIncentive(
{ config: this._config, account: this._account },
options,
isBase,
);
}
ERC20Incentive(
options: DeployablePayloadOrAddress<ERC20IncentivePayload>,
isBase?: boolean,
) {
ERC20Incentive(options: ERC20IncentivePayload) {
return new ERC20Incentive(
{ config: this._config, account: this._account },
options,
isBase,
);
}
ERC1155Incentive(
options: DeployablePayloadOrAddress<ERC1155IncentivePayload>,
isBase?: boolean,
) {
ERC1155Incentive(options: ERC1155IncentivePayload) {
return new ERC1155Incentive(
{ config: this._config, account: this._account },
options,
isBase,
);
}
PointsIncentive(
options: DeployablePayloadOrAddress<PointsIncentivePayload>,
isBase?: boolean,
) {
PointsIncentive(options: PointsIncentivePayload) {
return new PointsIncentive(
{ config: this._config, account: this._account },
options,
isBase,
);
}
SignerValidator(
Expand Down
5 changes: 5 additions & 0 deletions packages/sdk/src/Incentives/AllowListIncentive.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ import type { Address, Hex } from 'viem';
import { SimpleAllowList } from '../AllowLists/AllowList';
import type {
DeployableOptions,
DeployablePayloadOrAddress,
GenericDeployableParams,
} from '../Deployable/Deployable';
import { DeployableTarget } from '../Deployable/DeployableTarget';
Expand All @@ -31,6 +32,10 @@ export class AllowListIncentive extends DeployableTarget<AllowListIncentivePaylo
public static base = import.meta.env.VITE_ALLOWLIST_INCENTIVE_BASE;
public override readonly base = AllowListIncentive.base;

constructor(options: DeployableOptions, payload: AllowListIncentivePayload) {
super(options, payload, true);
}

public async claims(
params?: ReadParams<typeof allowListIncentiveAbi, 'claims'>,
) {
Expand Down
4 changes: 4 additions & 0 deletions packages/sdk/src/Incentives/CGDAIncentive.ts
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,10 @@ export class CGDAIncentive extends DeployableTarget<CGDAIncentivePayload> {
public static base = import.meta.env.VITE_CGDA_INCENTIVE_BASE;
public override readonly base = CGDAIncentive.base;

constructor(options: DeployableOptions, payload: CGDAIncentivePayload) {
super(options, payload, true);
}

public async claims(params?: ReadParams<typeof cgdaIncentiveAbi, 'claims'>) {
return readCgdaIncentiveClaims(this._config, {
address: this.assertValidAddress(),
Expand Down
4 changes: 4 additions & 0 deletions packages/sdk/src/Incentives/ERC1155Incentive.ts
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,10 @@ export class ERC1155Incentive extends DeployableTarget<ERC1155IncentivePayload>
public static base = import.meta.env.VITE_ERC1155_INCENTIVE_BASE;
public override readonly base = ERC1155Incentive.base;

constructor(options: DeployableOptions, payload: ERC1155IncentivePayload) {
super(options, payload, true);
}

public async claims(
params?: ReadParams<typeof erc1155IncentiveAbi, 'claims'>,
) {
Expand Down
4 changes: 4 additions & 0 deletions packages/sdk/src/Incentives/ERC20Incentive.ts
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,10 @@ export class ERC20Incentive extends DeployableTarget<ERC20IncentivePayload> {
public static base = import.meta.env.VITE_ERC20_INCENTIVE_BASE;
public override readonly base = ERC20Incentive.base;

constructor(options: DeployableOptions, payload: ERC20IncentivePayload) {
super(options, payload, true);
}

public async claims(params?: ReadParams<typeof erc20IncentiveAbi, 'claims'>) {
return readErc20IncentiveClaims(this._config, {
address: this.assertValidAddress(),
Expand Down
4 changes: 4 additions & 0 deletions packages/sdk/src/Incentives/PointsIncentive.ts
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,10 @@ export class PointsIncentive extends DeployableTarget<PointsIncentivePayload> {
public static base = import.meta.env.VITE_POINTS_INCENTIVE_BASE;
public override readonly base = PointsIncentive.base;

constructor(options: DeployableOptions, payload: PointsIncentivePayload) {
super(options, payload, true);
}

public async claims(
params?: ReadParams<typeof pointsIncentiveAbi, 'claims'>,
) {
Expand Down
17 changes: 14 additions & 3 deletions packages/sdk/test/helpers.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
import {
RegistryType,
mockErc20Abi,
readMockErc20BalanceOf,
readMockErc1155BalanceOf,
writeBoostRegistryRegister,
writeMockErc20Approve,
writeMockErc1155SetApprovalForAll,
} from '@boostxyz/evm';
import BoostCore from '@boostxyz/evm/artifacts/contracts/BoostCore.sol/BoostCore.json';
import BoostRegistry from '@boostxyz/evm/artifacts/contracts/BoostRegistry.sol/BoostRegistry.json';
Expand All @@ -22,7 +22,6 @@ import PointsIncentiveArtifact from '@boostxyz/evm/artifacts/contracts/incentive
import SignerValidatorArtifact from '@boostxyz/evm/artifacts/contracts/validators/SignerValidator.sol/SignerValidator.json';
import { deployContract } from '@wagmi/core';
import { type Address, type Hex, parseEther, zeroAddress } from 'viem';
import { writeContract } from 'viem/actions';
import {
AllowListIncentive,
type Budget,
Expand Down Expand Up @@ -396,16 +395,28 @@ export async function fundBudget(
{ value: parseEther('1.0') },
);

// approve and allocate erc20 to the account
await writeMockErc20Approve(options.config, {
args: [budget.address!, parseEther('100')],
address: erc20.address!,
account: options.account,
});
await budget.allocate({
amount: parseEther('100'),
asset: erc20.address!,
target: options.account.address,
});

await writeMockErc1155SetApprovalForAll(options.config, {
args: [budget.address!, true],
address: erc1155.address!,
account: options.account,
});
await budget.allocate({
tokenId: 1n,
amount: 100n,
asset: erc1155.address!,
target: testAccount.address,
target: options.account.address,
});

return { budget, erc20, erc1155 };
Expand Down

0 comments on commit dedfa8d

Please sign in to comment.