Skip to content

Commit

Permalink
Merge branch 'sam/boost-3883-protocol-v2-sdk-creation-flow' into art/…
Browse files Browse the repository at this point in the history
…tweak-create-return
  • Loading branch information
sammccord authored Jul 2, 2024
2 parents 4725be9 + 12daea3 commit d6f3cb2
Show file tree
Hide file tree
Showing 20 changed files with 601 additions and 297 deletions.
22 changes: 18 additions & 4 deletions packages/sdk/src/Actions/ContractAction.ts
Original file line number Diff line number Diff line change
@@ -1,15 +1,18 @@
import {
type ContractActionPayload,
contractActionAbi,
prepareContractActionPayload,
readContractActionChainId,
readContractActionPrepare,
readContractActionSelector,
readContractActionTarget,
readContractActionValue,
simulateContractActionExecute,
writeContractActionExecute,
} from '@boostxyz/evm';
import ContractActionArtifact from '@boostxyz/evm/artifacts/contracts/actions/ContractAction.sol/ContractAction.json';
import type { Hex } from 'viem';
import { bytecode } from '@boostxyz/evm/artifacts/contracts/actions/ContractAction.sol/ContractAction.json';
import { getTransaction, waitForTransactionReceipt } from '@wagmi/core';
import { type Hex, decodeFunctionData } from 'viem';
import type {
DeployableOptions,
GenericDeployableParams,
Expand Down Expand Up @@ -61,6 +64,17 @@ export class ContractAction extends DeployableTarget<ContractActionPayload> {
public async execute(
data: Hex,
params: CallParams<typeof writeContractActionExecute> = {},
) {
return this.awaitResult(
this.executeRaw(data, params),
contractActionAbi,
simulateContractActionExecute,
);
}

public async executeRaw(
data: Hex,
params: CallParams<typeof writeContractActionExecute> = {},
) {
return writeContractActionExecute(this._config, {
address: this.assertValidAddress(),
Expand Down Expand Up @@ -91,8 +105,8 @@ export class ContractAction extends DeployableTarget<ContractActionPayload> {
_options,
);
return {
abi: ContractActionArtifact.abi,
bytecode: ContractActionArtifact.bytecode as Hex,
abi: contractActionAbi,
bytecode: bytecode as Hex,
args: [prepareContractActionPayload(payload)],
...this.optionallyAttachAccount(options.account),
};
Expand Down
39 changes: 31 additions & 8 deletions packages/sdk/src/Actions/ERC721MintAction.ts
Original file line number Diff line number Diff line change
@@ -1,17 +1,18 @@
import {
type ERC721MintActionPayload,
erc721MintActionAbi,
prepareERC721MintActionPayload,
readErc721MintActionPrepare,
simulateErc721MintActionExecute,
simulateErc721MintActionValidate,
writeErc721MintActionExecute,
writeErc721MintActionValidate,
} from '@boostxyz/evm';
import ERC721MintActionArtifact from '@boostxyz/evm/artifacts/contracts/actions/ERC721MintAction.sol/ERC721MintAction.json';
import type { Config } from '@wagmi/core';
import { bytecode } from '@boostxyz/evm/artifacts/contracts/actions/ERC721MintAction.sol/ERC721MintAction.json';
import type { Hex } from 'viem';
import {
Deployable,
type DeployableOptions,
type GenericDeployableParams,
import type {
DeployableOptions,
GenericDeployableParams,
} from '../Deployable/Deployable';
import type { CallParams } from '../utils';
import { ContractAction } from './ContractAction';
Expand All @@ -22,6 +23,17 @@ export class ERC721MintAction extends ContractAction {
public override async execute(
data: Hex,
params: CallParams<typeof writeErc721MintActionExecute> = {},
) {
return this.awaitResult(
this.executeRaw(data, params),
erc721MintActionAbi,
simulateErc721MintActionExecute,
);
}

public override async executeRaw(
data: Hex,
params: CallParams<typeof writeErc721MintActionExecute> = {},
) {
return writeErc721MintActionExecute(this._config, {
address: this.assertValidAddress(),
Expand All @@ -46,6 +58,17 @@ export class ERC721MintAction extends ContractAction {
public async validate(
data: Hex,
params: CallParams<typeof writeErc721MintActionValidate> = {},
) {
return this.awaitResult(
this.validateRaw(data, params),
erc721MintActionAbi,
simulateErc721MintActionValidate,
);
}

public async validateRaw(
data: Hex,
params: CallParams<typeof writeErc721MintActionValidate> = {},
) {
return writeErc721MintActionValidate(this._config, {
address: this.assertValidAddress(),
Expand All @@ -64,8 +87,8 @@ export class ERC721MintAction extends ContractAction {
_options,
);
return {
abi: ERC721MintActionArtifact.abi,
bytecode: ERC721MintActionArtifact.bytecode as Hex,
abi: erc721MintActionAbi,
bytecode: bytecode as Hex,
args: [prepareERC721MintActionPayload(payload)],
...this.optionallyAttachAccount(options.account),
};
Expand Down
23 changes: 19 additions & 4 deletions packages/sdk/src/AllowLists/SimpleAllowList.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,11 @@ import {
type SimpleAllowListPayload,
prepareSimpleAllowListPayload,
readSimpleAllowListIsAllowed,
simpleAllowListAbi,
simulateSimpleAllowListSetAllowed,
writeSimpleAllowListSetAllowed,
} from '@boostxyz/evm';
import SimpleAllowListArtifact from '@boostxyz/evm/artifacts/contracts/allowlists/SimpleAllowList.sol/SimpleAllowList.json';
import { bytecode } from '@boostxyz/evm/artifacts/contracts/allowlists/SimpleAllowList.sol/SimpleAllowList.json';
import { getAccount } from '@wagmi/core';
import { type Address, type Hex, zeroAddress, zeroHash } from 'viem';
import type {
Expand Down Expand Up @@ -33,14 +35,27 @@ export class SimpleAllowList extends DeployableTarget<SimpleAllowListPayload> {
public async setAllowed(
addresses: Address[],
allowed: boolean[],
params: CallParams<typeof readSimpleAllowListIsAllowed> = {},
params: CallParams<typeof writeSimpleAllowListSetAllowed> = {},
) {
return this.awaitResult(
this.setAllowedRaw(addresses, allowed, params),
simpleAllowListAbi,
simulateSimpleAllowListSetAllowed,
);
}

public async setAllowedRaw(
addresses: Address[],
allowed: boolean[],
params: CallParams<typeof writeSimpleAllowListSetAllowed> = {},
) {
return await writeSimpleAllowListSetAllowed(this._config, {
address: this.assertValidAddress(),
args: [addresses, allowed],
...params,
});
}

public override buildParameters(
_payload?: SimpleAllowListPayload,
_options?: DeployableOptions,
Expand All @@ -62,8 +77,8 @@ export class SimpleAllowList extends DeployableTarget<SimpleAllowListPayload> {
}
}
return {
abi: SimpleAllowListArtifact.abi,
bytecode: SimpleAllowListArtifact.bytecode as Hex,
abi: simpleAllowListAbi,
bytecode: bytecode as Hex,
args: [prepareSimpleAllowListPayload(payload)],
...this.optionallyAttachAccount(options.account),
};
Expand Down
20 changes: 17 additions & 3 deletions packages/sdk/src/AllowLists/SimpleDenyList.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,11 @@ import {
type SimpleDenyListPayload,
prepareSimpleDenyListPayload,
readSimpleDenyListIsAllowed,
simpleDenyListAbi,
simulateSimpleDenyListSetDenied,
writeSimpleDenyListSetDenied,
} from '@boostxyz/evm';
import SimpleDenyListArtifact from '@boostxyz/evm/artifacts/contracts/allowlists/SimpleDenyList.sol/SimpleDenyList.json';
import { bytecode } from '@boostxyz/evm/artifacts/contracts/allowlists/SimpleDenyList.sol/SimpleDenyList.json';
import { getAccount } from '@wagmi/core';
import { type Address, type Hex, zeroAddress, zeroHash } from 'viem';
import type {
Expand Down Expand Up @@ -33,6 +35,18 @@ export class SimpleDenyList extends DeployableTarget<SimpleDenyListPayload> {
addresses: Address[],
allowed: boolean[],
params: CallParams<typeof writeSimpleDenyListSetDenied> = {},
) {
return this.awaitResult(
this.setAllowedRaw(addresses, allowed, params),
simpleDenyListAbi,
simulateSimpleDenyListSetDenied,
);
}

public async setAllowedRaw(
addresses: Address[],
allowed: boolean[],
params: CallParams<typeof writeSimpleDenyListSetDenied> = {},
) {
return await writeSimpleDenyListSetDenied(this._config, {
address: this.assertValidAddress(),
Expand Down Expand Up @@ -62,8 +76,8 @@ export class SimpleDenyList extends DeployableTarget<SimpleDenyListPayload> {
}
}
return {
abi: SimpleDenyListArtifact.abi,
bytecode: SimpleDenyListArtifact.bytecode as Hex,
abi: simpleDenyListAbi,
bytecode: bytecode as Hex,
args: [prepareSimpleDenyListPayload(payload)],
...this.optionallyAttachAccount(options.account),
};
Expand Down
9 changes: 4 additions & 5 deletions packages/sdk/src/Boost.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,7 @@ import type { Budget } from './Budgets/Budget';
import type { Incentive } from './Incentives/Incentive';
import type { Validator } from './Validators/Validator';

export type BoostPayload = {
address?: Address;
export interface BoostPayload {
budget: Budget;
action: Action;
validator: Validator;
Expand All @@ -16,24 +15,24 @@ export type BoostPayload = {
referralFee?: bigint;
maxParticipants?: bigint;
owner?: Address;
};
}

export class Boost {
readonly budget: Budget;
readonly action: Action;
readonly validator: Validator;
readonly allowList: AllowList;
readonly budget: Budget;
readonly incentives: Array<Incentive>;
readonly protocolFee: bigint;
readonly referralFee: bigint;
readonly maxParticipants: bigint;
readonly owner: Address;

constructor(payload: BoostPayload) {
this.budget = payload.budget;
this.action = payload.action;
this.validator = payload.validator;
this.allowList = payload.allowList;
this.budget = payload.budget;
this.incentives = payload.incentives;
this.protocolFee = payload.protocolFee || 0n;
this.referralFee = payload.referralFee || 0n;
Expand Down
63 changes: 0 additions & 63 deletions packages/sdk/src/BoostClient.test.ts

This file was deleted.

59 changes: 59 additions & 0 deletions packages/sdk/src/BoostCore.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
import { beforeAll, describe, test } from 'vitest';
import { type Fixtures, deployFixtures } from '../test/helpers';
import { setupConfig, testAccount } from '../test/viem';
import { BoostCore } from './BoostCore';

let fixtures: Fixtures;

beforeAll(async () => {
fixtures = await deployFixtures();
});

describe('BoostCore', () => {
test('can successfully create a boost', async () => {
const config = setupConfig();
const { core, bases } = fixtures;
const client = new BoostCore({
config: config,
address: core,
account: testAccount,
});
await client.createBoost({
budget: client
.SimpleBudget({
owner: testAccount.address,
authorized: [],
})
.at(bases.SimpleBudget.base),
action: client
.ContractAction(
{
chainId: BigInt(31_337),
target: core,
selector: '0xdeadbeef',
value: 0n,
},
true,
)
.at(bases.ContractAction.base),
validator: client
.SignerValidator(
{
signers: [testAccount.address],
},
true,
)
.at(bases.SignerValidator.base),
allowList: client
.SimpleAllowList(
{
owner: testAccount.address,
allowed: [],
},
true,
)
.at(bases.SimpleAllowList.base),
incentives: [],
});
});
});
Loading

0 comments on commit d6f3cb2

Please sign in to comment.