Skip to content

Commit

Permalink
chore: createBoost and retrieve payload in tests
Browse files Browse the repository at this point in the history
  • Loading branch information
sammccord committed Jun 28, 2024
1 parent a1b9444 commit a4c3306
Show file tree
Hide file tree
Showing 5 changed files with 110 additions and 72 deletions.
1 change: 1 addition & 0 deletions packages/sdk/src/Actions/ContractAction.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import {
} from '@boostxyz/evm';
import ContractActionArtifact from '@boostxyz/evm/artifacts/contracts/actions/ContractAction.sol/ContractAction.json';
import type { Hex } from 'viem';
import { simulateContract } from 'viem/actions';
import type {
DeployableOptions,
GenericDeployableParams,
Expand Down
16 changes: 14 additions & 2 deletions packages/sdk/src/Boost.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import type { Budget } from './Budgets/Budget';
import type { Incentive } from './Incentives/Incentive';
import type { Validator } from './Validators/Validator';

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

export interface LibBoost {
action: Address;
validator: Address;
allowList: Address;
budget: Address;
incentives: Array<Address>;
protocolFee: bigint;
referralFee: bigint;
maxParticipants: bigint;
owner: Address;
}

export class Boost {
readonly action: Action;
Expand Down
File renamed without changes.
163 changes: 94 additions & 69 deletions packages/sdk/src/BoostCore.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,19 @@
import BoostCoreArtifact from '@boostxyz/evm/artifacts/contracts/BoostCore.sol/BoostCore.json';
import { getAccount, waitForTransactionReceipt } from '@wagmi/core';
import {
getAccount,
getTransaction,
getTransactionReceipt,
simulateContract,
waitForTransactionReceipt,
} from '@wagmi/core';
import { createWriteContract } from '@wagmi/core/codegen';
import {
type Address,
type Hash,
type Hex,
decodeAbiParameters,
decodeFunctionData,
decodeFunctionResult,
zeroAddress,
zeroHash,
} from 'viem';
Expand All @@ -14,6 +22,9 @@ import {
type Target,
boostCoreAbi,
prepareBoostPayload,
readBoostCoreGetBoost,
readBoostCoreGetBoostCount,
simulateBoostCoreCreateBoost,
} from '../../evm/artifacts';

import type { Action } from './Actions/Action';
Expand All @@ -34,6 +45,7 @@ import {
SimpleDenyList,
type SimpleDenyListPayload,
} from './AllowLists/SimpleDenyList';
import { Boost } from './Boost';
import type { Budget } from './Budgets/Budget';
import { SimpleBudget, type SimpleBudgetPayload } from './Budgets/SimpleBudget';
import {
Expand Down Expand Up @@ -100,7 +112,7 @@ export type BoostClientConfig =
| BoostCoreDeployedOptions
| BoostCoreOptionsWithPayload;

export type CreatBoostPayload = {
export type CreateBoostPayload = {
budget: Budget | Address;
action: Action | Target;
validator: Validator | Target;
Expand Down Expand Up @@ -137,16 +149,17 @@ export class BoostCore extends Deployable<[Address, Address]> {

// TODO make this transactional? if any deployment fails what do we do with the previously deployed deployables?
public async createBoost(
_boostPayload: CreatBoostPayload,
_boostPayload: CreateBoostPayload,
_options: DeployableOptions = {
config: this._config,
account: this._account,
},
) {
const [payload, options] = this.validateDeploymentConfig<CreatBoostPayload>(
_boostPayload,
_options,
);
const [payload, options] =
this.validateDeploymentConfig<CreateBoostPayload>(
_boostPayload,
_options,
);

let {
budget,
Expand All @@ -157,7 +170,7 @@ export class BoostCore extends Deployable<[Address, Address]> {
protocolFee = 0n,
referralFee = 0n,
maxParticipants = 0n,
owner = zeroAddress,
owner,
} = payload;

const boostFactory = createWriteContract({
Expand Down Expand Up @@ -345,71 +358,83 @@ export class BoostCore extends Deployable<[Address, Address]> {
owner,
};

const encodedBoost = await boostFactory(options.config, {
const boostHash = await boostFactory(options.config, {
args: [prepareBoostPayload(onChainPayload)],
...this.optionallyAttachAccount(options.account),
});
await waitForTransactionReceipt(options.config, {
hash: boostHash,
});
const tx = await getTransaction(options.config, {
hash: boostHash,
});
const { args } = decodeFunctionData({
abi: boostCoreAbi,
data: tx.input,
});
const boostCreation = await simulateBoostCoreCreateBoost(options.config, {
address: this.address!,
args: args as [Hex],
...this.optionallyAttachAccount(),
});

console.log(encodedBoost);
const values = decodeAbiParameters(
[
{
components: [
{
internalType: 'contract Action',
name: 'action',
type: 'address',
},
{
internalType: 'contract Validator',
name: 'validator',
type: 'address',
},
{
internalType: 'contract AllowList',
name: 'allowList',
type: 'address',
},
{
internalType: 'contract Budget',
name: 'budget',
type: 'address',
},
{
internalType: 'contract Incentive[]',
name: 'incentives',
type: 'address[]',
},
{
internalType: 'uint64',
name: 'protocolFee',
type: 'uint64',
},
{
internalType: 'uint64',
name: 'referralFee',
type: 'uint64',
},
{
internalType: 'uint256',
name: 'maxParticipants',
type: 'uint256',
},
{
internalType: 'address',
name: 'owner',
type: 'address',
},
],
internalType: 'struct BoostLib.Boost',
name: '',
type: 'tuple',
},
],
encodedBoost,
);

console.log(values);
// const values = decodeAbiParameters(
// [
// {
// components: [
// {
// internalType: 'contract Action',
// name: 'action',
// type: 'address',
// },
// {
// internalType: 'contract Validator',
// name: 'validator',
// type: 'address',
// },
// {
// internalType: 'contract AllowList',
// name: 'allowList',
// type: 'address',
// },
// {
// internalType: 'contract Budget',
// name: 'budget',
// type: 'address',
// },
// {
// internalType: 'contract Incentive[]',
// name: 'incentives',
// type: 'address[]',
// },
// {
// internalType: 'uint64',
// name: 'protocolFee',
// type: 'uint64',
// },
// {
// internalType: 'uint64',
// name: 'referralFee',
// type: 'uint64',
// },
// {
// internalType: 'uint256',
// name: 'maxParticipants',
// type: 'uint256',
// },
// {
// internalType: 'address',
// name: 'owner',
// type: 'address',
// },
// ],
// internalType: 'struct BoostLib.Boost',
// name: '',
// type: 'tuple',
// },
// ],
// encodedBoost,
// );
}

ContractAction(
Expand Down
2 changes: 1 addition & 1 deletion packages/sdk/test/viem.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ export const mockWalletClient = createTestClient({
transport: http(),
chain: hardhat,
mode: 'hardhat',
account,
account: testAccount,
key,
})
.extend(publicActions)
Expand Down

0 comments on commit a4c3306

Please sign in to comment.