Skip to content

Commit

Permalink
chore: stabilize create, boost core tests
Browse files Browse the repository at this point in the history
  • Loading branch information
sammccord committed Jun 27, 2024
1 parent b478220 commit a1b9444
Show file tree
Hide file tree
Showing 26 changed files with 896 additions and 578 deletions.
4 changes: 1 addition & 3 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,7 @@
"type": "module",
"repository": "https://github.com/rabbitholegg/boost-protocol",
"author": "Boost Team<[email protected]>",
"workspaces": [
"packages/*"
],
"workspaces": ["packages/*"],
"packageManager": "[email protected]",
"engines": {
"pnpm": "8.15.8"
Expand Down
6 changes: 1 addition & 5 deletions packages/evm/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,7 @@
"version": "0.0.0-alpha.0",
"description": "",
"private": true,
"files": [
"dist",
"artifacts",
"contracts"
],
"files": ["dist", "artifacts", "contracts"],
"type": "module",
"repository": "https://github.com/rabbitholegg/boost-protocol",
"author": "Boost Team<[email protected]>",
Expand Down
19 changes: 13 additions & 6 deletions packages/sdk/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,9 @@
".": "./src/index.ts",
"./errors": "./src/errors.ts",
"./Boost": "./src/Boost.ts",
"./BoostClient": "./src/BoostClient.ts",
"./BoostCore": "./src/BoostCore.ts",
"./Deployable/Deployable": "./src/Deployable/Deployable.ts",
"./Deployable/DeployableTarget": "./src/Deployable/DeployableTarget.ts",
"./Deployable/Contract": "./src/Deployable/Contract.ts",
"./Actions/Action": "./src/Actions/Action.ts",
"./Actions/ContractAction": "./src/Actions/ContractAction.ts",
Expand Down Expand Up @@ -51,18 +52,24 @@
"node": "./dist/Boost.js",
"types": "./dist/Boost.d.ts"
},
"./BoostClient": {
"require": "./dist/BoostClient.cjs",
"import": "./dist/BoostClient.js",
"node": "./dist/BoostClient.js",
"types": "./dist/BoostClient.d.ts"
"./BoostCore": {
"require": "./dist/BoostCore.cjs",
"import": "./dist/BoostCore.js",
"node": "./dist/BoostCore.js",
"types": "./dist/BoostCore.d.ts"
},
"./Deployable/Deployable": {
"require": "./dist/Deployable/Deployable.cjs",
"import": "./dist/Deployable/Deployable.js",
"node": "./dist/Deployable/Deployable.js",
"types": "./dist/Deployable/Deployable.d.ts"
},
"./Deployable/DeployableTarget": {
"require": "./dist/Deployable/DeployableTarget.cjs",
"import": "./dist/Deployable/DeployableTarget.js",
"node": "./dist/Deployable/DeployableTarget.js",
"types": "./dist/Deployable/DeployableTarget.d.ts"
},
"./Deployable/Contract": {
"require": "./dist/Deployable/Contract.cjs",
"import": "./dist/Deployable/Contract.js",
Expand Down
30 changes: 20 additions & 10 deletions packages/sdk/src/Actions/ContractAction.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
import type { Config } from '@wagmi/core';
import type { Hex } from 'viem';
import {
type ContractActionPayload,
prepareContractActionPayload,
Expand All @@ -9,22 +7,25 @@ import {
readContractActionTarget,
readContractActionValue,
writeContractActionExecute,
} from '../../../evm/artifacts';
import ContractActionArtifact from '../../../evm/artifacts/contracts/actions/ContractAction.sol/ContractAction.json';
import {
Deployable,
type GenericDeployableParams,
} from '@boostxyz/evm';
import ContractActionArtifact from '@boostxyz/evm/artifacts/contracts/actions/ContractAction.sol/ContractAction.json';
import type { Hex } from 'viem';
import type {
DeployableOptions,
GenericDeployableParams,
} from '../Deployable/Deployable';
import { DeployableTarget } from '../Deployable/DeployableTarget';
import type { CallParams } from '../utils';

export type { ContractActionPayload };

export class ContractAction extends Deployable<ContractActionPayload> {
export class ContractAction extends DeployableTarget<ContractActionPayload> {
public async chainId(
params: CallParams<typeof readContractActionChainId> = {},
) {
return readContractActionChainId(this._config, {
address: this.assertValidAddress(),
...this.optionallyAttachAccount(),
...params,
});
}
Expand All @@ -34,6 +35,7 @@ export class ContractAction extends Deployable<ContractActionPayload> {
) {
return readContractActionTarget(this._config, {
address: this.assertValidAddress(),
...this.optionallyAttachAccount(),
...params,
});
}
Expand All @@ -43,13 +45,15 @@ export class ContractAction extends Deployable<ContractActionPayload> {
) {
return readContractActionSelector(this._config, {
address: this.assertValidAddress(),
...this.optionallyAttachAccount(),
...params,
});
}

public async value(params: CallParams<typeof readContractActionValue> = {}) {
return readContractActionValue(this._config, {
address: this.assertValidAddress(),
...this.optionallyAttachAccount(),
...params,
});
}
Expand All @@ -61,6 +65,7 @@ export class ContractAction extends Deployable<ContractActionPayload> {
return writeContractActionExecute(this._config, {
address: this.assertValidAddress(),
args: [data],
...this.optionallyAttachAccount(),
...params,
});
}
Expand All @@ -72,19 +77,24 @@ export class ContractAction extends Deployable<ContractActionPayload> {
return readContractActionPrepare(this._config, {
address: this.assertValidAddress(),
args: [data],
...this.optionallyAttachAccount(),
...params,
});
}

public override buildParameters(
_payload?: ContractActionPayload,
_config?: Config,
_options?: DeployableOptions,
): GenericDeployableParams {
const [payload] = this.validateDeploymentConfig(_payload, _config);
const [payload, options] = this.validateDeploymentConfig(
_payload,
_options,
);
return {
abi: ContractActionArtifact.abi,
bytecode: ContractActionArtifact.bytecode as Hex,
args: [prepareContractActionPayload(payload)],
...this.optionallyAttachAccount(options.account),
};
}
}
20 changes: 14 additions & 6 deletions packages/sdk/src/Actions/ERC721MintAction.ts
Original file line number Diff line number Diff line change
@@ -1,15 +1,16 @@
import type { Config } from '@wagmi/core';
import type { Hex } from 'viem';
import {
type ERC721MintActionPayload,
prepareERC721MintActionPayload,
readErc721MintActionPrepare,
writeErc721MintActionExecute,
writeErc721MintActionValidate,
} from '../../../evm/artifacts';
import ERC721MintActionArtifact from '../../../evm/artifacts/contracts/actions/ERC721MintAction.sol/ERC721MintAction.json';
} from '@boostxyz/evm';
import ERC721MintActionArtifact from '@boostxyz/evm/artifacts/contracts/actions/ERC721MintAction.sol/ERC721MintAction.json';
import type { Config } from '@wagmi/core';
import type { Hex } from 'viem';
import {
Deployable,
type DeployableOptions,
type GenericDeployableParams,
} from '../Deployable/Deployable';
import type { CallParams } from '../utils';
Expand All @@ -25,6 +26,7 @@ export class ERC721MintAction extends ContractAction {
return writeErc721MintActionExecute(this._config, {
address: this.assertValidAddress(),
args: [data],
...this.optionallyAttachAccount(),
...params,
});
}
Expand All @@ -36,6 +38,7 @@ export class ERC721MintAction extends ContractAction {
return readErc721MintActionPrepare(this._config, {
address: this.assertValidAddress(),
args: [data],
...this.optionallyAttachAccount(),
...params,
});
}
Expand All @@ -47,19 +50,24 @@ export class ERC721MintAction extends ContractAction {
return writeErc721MintActionValidate(this._config, {
address: this.assertValidAddress(),
args: [data],
...this.optionallyAttachAccount(),
...params,
});
}

public override buildParameters(
_payload?: ERC721MintActionPayload,
_config?: Config,
_options?: DeployableOptions,
): GenericDeployableParams {
const [payload] = this.validateDeploymentConfig(_payload, _config);
const [payload, options] = this.validateDeploymentConfig(
_payload,
_options,
);
return {
abi: ERC721MintActionArtifact.abi,
bytecode: ERC721MintActionArtifact.bytecode as Hex,
args: [prepareERC721MintActionPayload(payload)],
...this.optionallyAttachAccount(options.account),
};
}
}
32 changes: 21 additions & 11 deletions packages/sdk/src/AllowLists/SimpleAllowList.ts
Original file line number Diff line number Diff line change
@@ -1,29 +1,31 @@
import { type Config, getAccount } from '@wagmi/core';
import { type Address, type Hex, zeroAddress, zeroHash } from 'viem';
import {
type SimpleAllowListPayload,
prepareSimpleAllowListPayload,
readSimpleAllowListIsAllowed,
writeSimpleAllowListSetAllowed,
} from '../../../evm/artifacts';
import SimpleAllowListArtifact from '../../../evm/artifacts/contracts/allowlists/SimpleAllowList.sol/SimpleAllowList.json';
import {
Deployable,
type GenericDeployableParams,
} from '@boostxyz/evm';
import SimpleAllowListArtifact 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 {
DeployableOptions,
GenericDeployableParams,
} from '../Deployable/Deployable';
import { DeployableTarget } from '../Deployable/DeployableTarget';
import { DeployableUnknownOwnerProvidedError } from '../errors';
import type { CallParams } from '../utils';

export type { SimpleAllowListPayload };

export class SimpleAllowList extends Deployable<SimpleAllowListPayload> {
export class SimpleAllowList extends DeployableTarget<SimpleAllowListPayload> {
public async isAllowed(
address: Address,
params: CallParams<typeof readSimpleAllowListIsAllowed> = {},
): Promise<boolean> {
return await readSimpleAllowListIsAllowed(this._config, {
address: this.assertValidAddress(),
args: [address, zeroHash],
...this.optionallyAttachAccount(),
...params,
});
}
Expand All @@ -41,11 +43,18 @@ export class SimpleAllowList extends Deployable<SimpleAllowListPayload> {
}
public override buildParameters(
_payload?: SimpleAllowListPayload,
_config?: Config,
_options?: DeployableOptions,
): GenericDeployableParams {
const [payload, config] = this.validateDeploymentConfig(_payload, _config);
const [payload, options] = this.validateDeploymentConfig(
_payload,
_options,
);
if (!payload.owner || payload.owner === zeroAddress) {
const owner = getAccount(config).address;
const owner = options.account
? options.account.address
: options.config
? getAccount(options.config).address
: this._account?.address;
if (owner) {
payload.owner = owner;
} else {
Expand All @@ -56,6 +65,7 @@ export class SimpleAllowList extends Deployable<SimpleAllowListPayload> {
abi: SimpleAllowListArtifact.abi,
bytecode: SimpleAllowListArtifact.bytecode as Hex,
args: [prepareSimpleAllowListPayload(payload)],
...this.optionallyAttachAccount(options.account),
};
}
}
31 changes: 20 additions & 11 deletions packages/sdk/src/AllowLists/SimpleDenyList.ts
Original file line number Diff line number Diff line change
@@ -1,22 +1,23 @@
import { type Config, getAccount } from '@wagmi/core';
import { type Address, type Hex, zeroAddress, zeroHash } from 'viem';
import {
type SimpleDenyListPayload,
prepareSimpleDenyListPayload,
readSimpleDenyListIsAllowed,
writeSimpleDenyListSetDenied,
} from '../../../evm/artifacts';
import SimpleDenyListArtifact from '../../../evm/artifacts/contracts/allowlists/SimpleDenyList.sol/SimpleDenyList.json';
import {
Deployable,
type GenericDeployableParams,
} from '@boostxyz/evm';
import SimpleDenyListArtifact 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 {
DeployableOptions,
GenericDeployableParams,
} from '../Deployable/Deployable';
import { DeployableTarget } from '../Deployable/DeployableTarget';
import { DeployableUnknownOwnerProvidedError } from '../errors';
import type { CallParams } from '../utils';

export type { SimpleDenyListPayload };

export class SimpleDenyList extends Deployable<SimpleDenyListPayload> {
export class SimpleDenyList extends DeployableTarget<SimpleDenyListPayload> {
public async isAllowed(
address: Address,
params: CallParams<typeof readSimpleDenyListIsAllowed> = {},
Expand All @@ -42,11 +43,18 @@ export class SimpleDenyList extends Deployable<SimpleDenyListPayload> {

public override buildParameters(
_payload?: SimpleDenyListPayload,
_config?: Config,
_options?: DeployableOptions,
): GenericDeployableParams {
const [payload, config] = this.validateDeploymentConfig(_payload, _config);
const [payload, options] = this.validateDeploymentConfig(
_payload,
_options,
);
if (!payload.owner || payload.owner === zeroAddress) {
const owner = getAccount(config).address;
const owner = options.account
? options.account.address
: options.config
? getAccount(options.config).address
: this._account?.address;
if (owner) {
payload.owner = owner;
} else {
Expand All @@ -57,6 +65,7 @@ export class SimpleDenyList extends Deployable<SimpleDenyListPayload> {
abi: SimpleDenyListArtifact.abi,
bytecode: SimpleDenyListArtifact.bytecode as Hex,
args: [prepareSimpleDenyListPayload(payload)],
...this.optionallyAttachAccount(options.account),
};
}
}
15 changes: 10 additions & 5 deletions packages/sdk/src/Boost.ts
Original file line number Diff line number Diff line change
@@ -1,13 +1,11 @@
import type { Config } from '@wagmi/core';
import { type Address, zeroAddress } from 'viem';
import { type Address, type Hex, zeroAddress } from 'viem';
import type { Action } from './Actions/Action';
import type { AllowList } from './AllowLists/AllowList';
import type { Budget } from './Budgets/Budget';
import { Contract } from './Deployable/Contract';
import type { Incentive } from './Incentives/Incentive';
import type { Validator } from './Validators/Validator';

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

export class Boost {
readonly action: Action;
Expand All @@ -42,4 +40,11 @@ export class Boost {
this.maxParticipants = payload.maxParticipants || 0n;
this.owner = payload.owner || zeroAddress;
}

// public encode() {}

public static decode(_data: Hex) {
// TODO decode hash, initialize class
// return new Boost({});
}
}
Loading

0 comments on commit a1b9444

Please sign in to comment.