Skip to content

Commit

Permalink
feat: expose raw/awaited api for all write methods
Browse files Browse the repository at this point in the history
  • Loading branch information
sammccord committed Jul 1, 2024
1 parent 37a3316 commit 12daea3
Show file tree
Hide file tree
Showing 14 changed files with 381 additions and 93 deletions.
30 changes: 9 additions & 21 deletions packages/sdk/src/Actions/ContractAction.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import {
type ContractActionPayload,
contractActionAbi,
prepareContractActionPayload,
readContractActionChainId,
readContractActionPrepare,
Expand All @@ -9,7 +10,7 @@ import {
simulateContractActionExecute,
writeContractActionExecute,
} from '@boostxyz/evm';
import ContractActionArtifact from '@boostxyz/evm/artifacts/contracts/actions/ContractAction.sol/ContractAction.json';
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 {
Expand Down Expand Up @@ -64,24 +65,11 @@ export class ContractAction extends DeployableTarget<ContractActionPayload> {
data: Hex,
params: CallParams<typeof writeContractActionExecute> = {},
) {
const hash = await this.executeRaw(data, params);
const receipt = await waitForTransactionReceipt(this._config, {
hash,
});
const tx = await getTransaction(this._config, { hash });
const { args } = decodeFunctionData({
abi: ContractActionArtifact.abi,
data: tx.input,
});
const { result } = await simulateContractActionExecute(this._config, {
account: tx.from,
address: tx.to!,
args: args as [Hex],
// value: tx.value, // TS doesn't like me to including this
blockNumber: receipt.blockNumber,
// do we need to include nonce, gas price, etc. to properly simulate?
});
return result;
return this.awaitResult(
this.executeRaw(data, params),
contractActionAbi,
simulateContractActionExecute,
);
}

public async executeRaw(
Expand Down Expand Up @@ -117,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
33 changes: 20 additions & 13 deletions packages/sdk/src/Actions/ERC721MintAction.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,19 +4,15 @@ import {
prepareERC721MintActionPayload,
readErc721MintActionPrepare,
simulateErc721MintActionExecute,
simulateErc721MintActionValidate,
writeErc721MintActionExecute,
writeErc721MintActionValidate,
} from '@boostxyz/evm';
import {
type Config,
getTransaction,
waitForTransactionReceipt,
} from '@wagmi/core';
import { type Hex, decodeFunctionData } from 'viem';
import {
Deployable,
type DeployableOptions,
type GenericDeployableParams,
import { bytecode } from '@boostxyz/evm/artifacts/contracts/actions/ERC721MintAction.sol/ERC721MintAction.json';
import type { Hex } from 'viem';
import type {
DeployableOptions,
GenericDeployableParams,
} from '../Deployable/Deployable';
import type { CallParams } from '../utils';
import { ContractAction } from './ContractAction';
Expand All @@ -28,7 +24,7 @@ export class ERC721MintAction extends ContractAction {
data: Hex,
params: CallParams<typeof writeErc721MintActionExecute> = {},
) {
return this.awaitResult<typeof erc721MintActionAbi, 'execute'>(
return this.awaitResult(
this.executeRaw(data, params),
erc721MintActionAbi,
simulateErc721MintActionExecute,
Expand Down Expand Up @@ -62,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 @@ -80,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
76 changes: 69 additions & 7 deletions packages/sdk/src/Budgets/SimpleBudget.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,13 +8,19 @@ import {
readSimpleBudgetIsAuthorized,
readSimpleBudgetTotal,
readVestingBudgetStart,
simpleAllowListAbi,
simulateSimpleBudgetAllocate,
simulateSimpleBudgetDisburse,
simulateSimpleBudgetDisburseBatch,
simulateSimpleBudgetReclaim,
simulateSimpleBudgetSetAuthorized,
writeSimpleBudgetAllocate,
writeSimpleBudgetDisburse,
writeSimpleBudgetDisburseBatch,
writeSimpleBudgetReclaim,
writeSimpleBudgetSetAuthorized,
} from '@boostxyz/evm';
import SimpleBudgetArtifact from '@boostxyz/evm/artifacts/contracts/budgets/SimpleBudget.sol/SimpleBudget.json';
import { bytecode } from '@boostxyz/evm/artifacts/contracts/budgets/SimpleBudget.sol/SimpleBudget.json';
import { getAccount } from '@wagmi/core';
import { type Address, type Hex, zeroAddress } from 'viem';
import {
Expand All @@ -35,7 +41,18 @@ export class SimpleBudget extends Deployable<SimpleBudgetPayload> {
});
}

public allocate(
public async allocate(
transfer: TransferPayload,
params: CallParams<typeof writeSimpleBudgetAllocate> = {},
) {
return this.awaitResult(
this.allocateRaw(transfer, params),
simpleAllowListAbi,
simulateSimpleBudgetAllocate,
);
}

public allocateRaw(
transfer: TransferPayload,
params: CallParams<typeof writeSimpleBudgetAllocate> = {},
) {
Expand All @@ -46,7 +63,18 @@ export class SimpleBudget extends Deployable<SimpleBudgetPayload> {
});
}

public reclaim(
public async reclaim(
transfer: TransferPayload,
params: CallParams<typeof writeSimpleBudgetReclaim> = {},
) {
return this.awaitResult(
this.reclaimRaw(transfer, params),
simpleAllowListAbi,
simulateSimpleBudgetReclaim,
);
}

public reclaimRaw(
transfer: TransferPayload,
params: CallParams<typeof writeSimpleBudgetReclaim> = {},
) {
Expand All @@ -57,7 +85,18 @@ export class SimpleBudget extends Deployable<SimpleBudgetPayload> {
});
}

public disburse(
public async disburse(
transfer: TransferPayload,
params: CallParams<typeof writeSimpleBudgetDisburse> = {},
) {
return this.awaitResult(
this.disburseRaw(transfer, params),
simpleAllowListAbi,
simulateSimpleBudgetDisburse,
);
}

public disburseRaw(
transfer: TransferPayload,
params: CallParams<typeof writeSimpleBudgetDisburse> = {},
) {
Expand All @@ -68,9 +107,20 @@ export class SimpleBudget extends Deployable<SimpleBudgetPayload> {
});
}

public async disburseBatch(
transfers: TransferPayload[],
params: CallParams<typeof writeSimpleBudgetDisburseBatch> = {},
) {
return this.awaitResult(
this.disburseBatchRaw(transfers, params),
simpleAllowListAbi,
simulateSimpleBudgetDisburseBatch,
);
}

// use prepareFungibleTransfer or prepareERC1155Transfer
// TODO use data structure
public disburseBatch(
public disburseBatchRaw(
transfers: TransferPayload[],
params: CallParams<typeof writeSimpleBudgetDisburseBatch> = {},
) {
Expand All @@ -85,6 +135,18 @@ export class SimpleBudget extends Deployable<SimpleBudgetPayload> {
addresses: Address[],
allowed: boolean[],
params: CallParams<typeof writeSimpleBudgetSetAuthorized> = {},
) {
return this.awaitResult(
this.setAuthorizedRaw(addresses, allowed, params),
simpleAllowListAbi,
simulateSimpleBudgetSetAuthorized,
);
}

public async setAuthorizedRaw(
addresses: Address[],
allowed: boolean[],
params: CallParams<typeof writeSimpleBudgetSetAuthorized> = {},
) {
return await writeSimpleBudgetSetAuthorized(this._config, {
address: this.assertValidAddress(),
Expand Down Expand Up @@ -161,8 +223,8 @@ export class SimpleBudget extends Deployable<SimpleBudgetPayload> {
}
}
return {
abi: SimpleBudgetArtifact.abi,
bytecode: SimpleBudgetArtifact.bytecode as Hex,
abi: simpleAllowListAbi,
bytecode: bytecode as Hex,
args: [prepareSimpleBudgetPayload(payload)],
...this.optionallyAttachAccount(options.account),
};
Expand Down
Loading

0 comments on commit 12daea3

Please sign in to comment.