diff --git a/packages/evm/artifacts/index.ts b/packages/evm/artifacts/index.ts index 640b0ba21..1d3a05101 100644 --- a/packages/evm/artifacts/index.ts +++ b/packages/evm/artifacts/index.ts @@ -253,74 +253,6 @@ export function prepareERC1155Payload({ ); } -export interface ERC1155TransferPayload { - tokenId: bigint; - amount: bigint; - asset: Address; - target: Address; -} - -export function prepareERC1155Transfer({ - tokenId, - amount, - asset, - target, -}: ERC1155TransferPayload) { - return encodeAbiParameters( - parseAbiParameters([ - 'Transfer request', - 'struct Transfer { uint8 assetType; address asset; address target; bytes data; }', - ]), - [ - { - assetType: 2, - asset, - data: prepareERC1155Payload({ tokenId, amount }), - target, - }, - ], - ); -} - -export interface FungiblePayload { amount: bigint } - -export function prepareFungiblePayload({ amount }: FungiblePayload) { - return encodeAbiParameters( - parseAbiParameters([ - 'FungiblePayload payload', - 'struct FungiblePayload { uint256 amount; }', - ]), - [{ amount }], - ); -} - -export interface FungibleTransferPayload { - amount: bigint; - asset: Address; - target: Address; -} - -export function prepareFungibleTransfer({ - amount, - asset, - target, -}: FungibleTransferPayload) { - return encodeAbiParameters( - parseAbiParameters([ - 'Transfer request', - 'struct Transfer { uint8 assetType; address asset; address target; bytes data; }', - ]), - [ - { - assetType: asset == zeroAddress ? 0 : 1, - asset, - data: prepareFungiblePayload({ amount }), - target, - }, - ], - ); -} - export interface PointsIncentivePayload { venue: Address; selector: Hex; @@ -548,6 +480,10 @@ export const prepareClaimPayload = ({ target, data = zeroHash }: ClaimPayload) = ) } +/* +* Transfer Payloads +*/ + export enum AssetType { ETH, ERC20, @@ -573,3 +509,70 @@ export const prepareTransferPayload =({ assetType, address, target, data }: Tran ) } +export interface ERC1155TransferPayload { + tokenId: bigint; + amount: bigint; + asset: Address; + target: Address; +} + +export function prepareERC1155Transfer({ + tokenId, + amount, + asset, + target, +}: ERC1155TransferPayload) { + return encodeAbiParameters( + parseAbiParameters([ + 'Transfer request', + 'struct Transfer { uint8 assetType; address asset; address target; bytes data; }', + ]), + [ + { + assetType: AssetType.ERC1155, + asset, + data: prepareERC1155Payload({ tokenId, amount }), + target, + }, + ], + ); +} + +export interface FungiblePayload { amount: bigint } + +export function prepareFungiblePayload({ amount }: FungiblePayload) { + return encodeAbiParameters( + parseAbiParameters([ + 'FungiblePayload payload', + 'struct FungiblePayload { uint256 amount; }', + ]), + [{ amount }], + ); +} + +export interface FungibleTransferPayload { + amount: bigint; + asset: Address; + target: Address; +} + +export function prepareFungibleTransfer({ + amount, + asset, + target, +}: FungibleTransferPayload) { + return encodeAbiParameters( + parseAbiParameters([ + 'Transfer request', + 'struct Transfer { uint8 assetType; address asset; address target; bytes data; }', + ]), + [ + { + assetType: asset == zeroAddress ? AssetType.ETH : AssetType.ERC20, + asset, + data: prepareFungiblePayload({ amount }), + target, + }, + ], + ); +} diff --git a/packages/sdk/src/Actions/ContractAction.ts b/packages/sdk/src/Actions/ContractAction.ts index 085f70c9c..4219db835 100644 --- a/packages/sdk/src/Actions/ContractAction.ts +++ b/packages/sdk/src/Actions/ContractAction.ts @@ -19,7 +19,7 @@ import type { GenericDeployableParams, } from '../Deployable/Deployable'; import { DeployableTarget } from '../Deployable/DeployableTarget'; -import type { CallParams } from '../utils'; +import type { ReadParams, WriteParams } from '../utils'; export type { ContractActionPayload }; @@ -28,46 +28,48 @@ export class ContractAction extends DeployableTarget { public override readonly base = ContractAction.base; public async chainId( - params: CallParams = {}, + params?: ReadParams, ) { return readContractActionChainId(this._config, { address: this.assertValidAddress(), ...this.optionallyAttachAccount(), - ...params, + // biome-ignore lint/suspicious/noExplicitAny: Accept any shape of valid wagmi/viem parameters, wagmi does the same thing internally + ...(params as any), }); } - public async target( - params: CallParams = {}, - ) { + public async target(params?: ReadParams) { return readContractActionTarget(this._config, { address: this.assertValidAddress(), ...this.optionallyAttachAccount(), - ...params, + // biome-ignore lint/suspicious/noExplicitAny: Accept any shape of valid wagmi/viem parameters, wagmi does the same thing internally + ...(params as any), }); } public async selector( - params: CallParams = {}, + params?: ReadParams, ) { return readContractActionSelector(this._config, { address: this.assertValidAddress(), ...this.optionallyAttachAccount(), - ...params, + // biome-ignore lint/suspicious/noExplicitAny: Accept any shape of valid wagmi/viem parameters, wagmi does the same thing internally + ...(params as any), }); } - public async value(params: CallParams = {}) { + public async value(params?: ReadParams) { return readContractActionValue(this._config, { address: this.assertValidAddress(), ...this.optionallyAttachAccount(), - ...params, + // biome-ignore lint/suspicious/noExplicitAny: Accept any shape of valid wagmi/viem parameters, wagmi does the same thing internally + ...(params as any), }); } public async execute( data: Hex, - params: CallParams = {}, + params?: WriteParams, ) { return this.awaitResult( this.executeRaw(data, params), @@ -78,47 +80,51 @@ export class ContractAction extends DeployableTarget { public async executeRaw( data: Hex, - params: CallParams = {}, + params?: WriteParams, ) { return writeContractActionExecute(this._config, { address: this.assertValidAddress(), ...this.optionallyAttachAccount(), - ...params, + // biome-ignore lint/suspicious/noExplicitAny: Accept any shape of valid wagmi/viem parameters, wagmi does the same thing internally + ...(params as any), args: [data], }); } public async prepare( data: Hex, - params: CallParams = {}, + params?: ReadParams, ) { return readContractActionPrepare(this._config, { address: this.assertValidAddress(), args: [data], ...this.optionallyAttachAccount(), - ...params, + // biome-ignore lint/suspicious/noExplicitAny: Accept any shape of valid wagmi/viem parameters, wagmi does the same thing internally + ...(params as any), }); } public async supportsInterface( interfaceId: Hex, - params: CallParams = {}, + params?: ReadParams, ) { return readContractActionSupportsInterface(this._config, { address: this.assertValidAddress(), ...this.optionallyAttachAccount(), - ...params, + // biome-ignore lint/suspicious/noExplicitAny: Accept any shape of valid wagmi/viem parameters, wagmi does the same thing internally + ...(params as any), args: [interfaceId], }); } public async getComponentInterface( - params: CallParams = {}, + params?: ReadParams, ) { return readContractActionGetComponentInterface(this._config, { address: this.assertValidAddress(), ...this.optionallyAttachAccount(), - ...params, + // biome-ignore lint/suspicious/noExplicitAny: Accept any shape of valid wagmi/viem parameters, wagmi does the same thing internally + ...(params as any), args: [], }); } diff --git a/packages/sdk/src/Actions/ERC721MintAction.ts b/packages/sdk/src/Actions/ERC721MintAction.ts index d67e0eaba..17d46ade6 100644 --- a/packages/sdk/src/Actions/ERC721MintAction.ts +++ b/packages/sdk/src/Actions/ERC721MintAction.ts @@ -16,7 +16,7 @@ import type { DeployableOptions, GenericDeployableParams, } from '../Deployable/Deployable'; -import type { CallParams } from '../utils'; +import type { ReadParams, WriteParams } from '../utils'; import { ContractAction } from './ContractAction'; export type { ERC721MintActionPayload }; @@ -27,7 +27,7 @@ export class ERC721MintAction extends ContractAction { public override async execute( data: Hex, - params: CallParams = {}, + params?: WriteParams, ) { return this.awaitResult( this.executeRaw(data, params), @@ -38,31 +38,33 @@ export class ERC721MintAction extends ContractAction { public override async executeRaw( data: Hex, - params: CallParams = {}, + params?: WriteParams, ) { return writeErc721MintActionExecute(this._config, { address: this.assertValidAddress(), args: [data], ...this.optionallyAttachAccount(), - ...params, + // biome-ignore lint/suspicious/noExplicitAny: Accept any shape of valid wagmi/viem parameters, wagmi does the same thing internally + ...(params as any), }); } public override async prepare( data: Hex, - params: CallParams = {}, + params?: ReadParams, ) { return readErc721MintActionPrepare(this._config, { address: this.assertValidAddress(), args: [data], ...this.optionallyAttachAccount(), - ...params, + // biome-ignore lint/suspicious/noExplicitAny: Accept any shape of valid wagmi/viem parameters, wagmi does the same thing internally + ...(params as any), }); } public async validate( data: Hex, - params: CallParams = {}, + params?: WriteParams, ) { return this.awaitResult( this.validateRaw(data, params), @@ -73,35 +75,38 @@ export class ERC721MintAction extends ContractAction { public async validateRaw( data: Hex, - params: CallParams = {}, + params?: WriteParams, ) { return writeErc721MintActionValidate(this._config, { address: this.assertValidAddress(), args: [data], ...this.optionallyAttachAccount(), - ...params, + // biome-ignore lint/suspicious/noExplicitAny: Accept any shape of valid wagmi/viem parameters, wagmi does the same thing internally + ...(params as any), }); } public override async supportsInterface( interfaceId: Hex, - params: CallParams = {}, + params?: ReadParams, ) { return readErc721MintActionSupportsInterface(this._config, { address: this.assertValidAddress(), ...this.optionallyAttachAccount(), - ...params, + // biome-ignore lint/suspicious/noExplicitAny: Accept any shape of valid wagmi/viem parameters, wagmi does the same thing internally + ...(params as any), args: [interfaceId], }); } public override async getComponentInterface( - params: CallParams = {}, + params?: ReadParams, ) { return readErc721MintActionGetComponentInterface(this._config, { address: this.assertValidAddress(), ...this.optionallyAttachAccount(), - ...params, + // biome-ignore lint/suspicious/noExplicitAny: Accept any shape of valid wagmi/viem parameters, wagmi does the same thing internally + ...(params as any), args: [], }); } diff --git a/packages/sdk/src/AllowLists/SimpleAllowList.ts b/packages/sdk/src/AllowLists/SimpleAllowList.ts index b7d4c6cf3..068f75798 100644 --- a/packages/sdk/src/AllowLists/SimpleAllowList.ts +++ b/packages/sdk/src/AllowLists/SimpleAllowList.ts @@ -17,7 +17,7 @@ import type { } from '../Deployable/Deployable'; import { DeployableTarget } from '../Deployable/DeployableTarget'; import { DeployableUnknownOwnerProvidedError } from '../errors'; -import type { CallParams } from '../utils'; +import type { ReadParams } from '../utils'; export type { SimpleAllowListPayload }; @@ -27,20 +27,21 @@ export class SimpleAllowList extends DeployableTarget { public async isAllowed( address: Address, - params: CallParams = {}, + params?: ReadParams, ): Promise { return await readSimpleAllowListIsAllowed(this._config, { address: this.assertValidAddress(), args: [address, zeroHash], ...this.optionallyAttachAccount(), - ...params, + // biome-ignore lint/suspicious/noExplicitAny: Accept any shape of valid wagmi/viem parameters, wagmi does the same thing internally + ...(params as any), }); } public async setAllowed( addresses: Address[], allowed: boolean[], - params: CallParams = {}, + params?: ReadParams, ) { return this.awaitResult( this.setAllowedRaw(addresses, allowed, params), @@ -52,34 +53,37 @@ export class SimpleAllowList extends DeployableTarget { public async setAllowedRaw( addresses: Address[], allowed: boolean[], - params: CallParams = {}, + params?: ReadParams, ) { return await writeSimpleAllowListSetAllowed(this._config, { address: this.assertValidAddress(), args: [addresses, allowed], - ...params, + // biome-ignore lint/suspicious/noExplicitAny: Accept any shape of valid wagmi/viem parameters, wagmi does the same thing internally + ...(params as any), }); } public async supportsInterface( interfaceId: Hex, - params: CallParams = {}, + params?: ReadParams, ) { return readSimpleAllowListSupportsInterface(this._config, { address: this.assertValidAddress(), ...this.optionallyAttachAccount(), - ...params, + // biome-ignore lint/suspicious/noExplicitAny: Accept any shape of valid wagmi/viem parameters, wagmi does the same thing internally + ...(params as any), args: [interfaceId], }); } public async getComponentInterface( - params: CallParams = {}, + params?: ReadParams, ) { return readSimpleAllowListGetComponentInterface(this._config, { address: this.assertValidAddress(), ...this.optionallyAttachAccount(), - ...params, + // biome-ignore lint/suspicious/noExplicitAny: Accept any shape of valid wagmi/viem parameters, wagmi does the same thing internally + ...(params as any), args: [], }); } diff --git a/packages/sdk/src/AllowLists/SimpleDenyList.ts b/packages/sdk/src/AllowLists/SimpleDenyList.ts index 3adcfd9c9..d7c4ed35d 100644 --- a/packages/sdk/src/AllowLists/SimpleDenyList.ts +++ b/packages/sdk/src/AllowLists/SimpleDenyList.ts @@ -17,7 +17,7 @@ import type { } from '../Deployable/Deployable'; import { DeployableTarget } from '../Deployable/DeployableTarget'; import { DeployableUnknownOwnerProvidedError } from '../errors'; -import type { CallParams } from '../utils'; +import type { ReadParams, WriteParams } from '../utils'; export type { SimpleDenyListPayload }; @@ -27,58 +27,62 @@ export class SimpleDenyList extends DeployableTarget { public async isAllowed( address: Address, - params: CallParams = {}, + params?: ReadParams, ): Promise { return await readSimpleDenyListIsAllowed(this._config, { address: this.assertValidAddress(), args: [address, zeroHash], - ...params, + // biome-ignore lint/suspicious/noExplicitAny: Accept any shape of valid wagmi/viem parameters, wagmi does the same thing internally + ...(params as any), }); } - public async setAllowed( + public async setDenied( addresses: Address[], allowed: boolean[], - params: CallParams = {}, + params?: WriteParams, ) { return this.awaitResult( - this.setAllowedRaw(addresses, allowed, params), + this.setDeniedRaw(addresses, allowed, params), simpleDenyListAbi, simulateSimpleDenyListSetDenied, ); } - public async setAllowedRaw( + public async setDeniedRaw( addresses: Address[], allowed: boolean[], - params: CallParams = {}, + params?: WriteParams, ) { return await writeSimpleDenyListSetDenied(this._config, { address: this.assertValidAddress(), args: [addresses, allowed], - ...params, + // biome-ignore lint/suspicious/noExplicitAny: Accept any shape of valid wagmi/viem parameters, wagmi does the same thing internally + ...(params as any), }); } public async supportsInterface( interfaceId: Hex, - params: CallParams = {}, + params?: ReadParams, ) { return readSimpleDenyListSupportsInterface(this._config, { address: this.assertValidAddress(), ...this.optionallyAttachAccount(), - ...params, + // biome-ignore lint/suspicious/noExplicitAny: Accept any shape of valid wagmi/viem parameters, wagmi does the same thing internally + ...(params as any), args: [interfaceId], }); } public async getComponentInterface( - params: CallParams = {}, + params?: ReadParams, ) { return readSimpleDenyListGetComponentInterface(this._config, { address: this.assertValidAddress(), ...this.optionallyAttachAccount(), - ...params, + // biome-ignore lint/suspicious/noExplicitAny: Accept any shape of valid wagmi/viem parameters, wagmi does the same thing internally + ...(params as any), args: [], }); } diff --git a/packages/sdk/src/BoostCore.ts b/packages/sdk/src/BoostCore.ts index 8d19a26d5..69b6af0c2 100644 --- a/packages/sdk/src/BoostCore.ts +++ b/packages/sdk/src/BoostCore.ts @@ -86,7 +86,7 @@ import { DeployableUnknownOwnerProvidedError, NoContractAddressUponReceiptError, } from './errors'; -import type { CallParams } from './utils'; +import type { ReadParams, WriteParams } from './utils'; export const BOOST_CORE_ADDRESS: Address = import.meta.env .VITE_BOOST_CORE_ADDRESS; @@ -340,7 +340,7 @@ export class BoostCore extends Deployable<[Address, Address]> { incentiveId: bigint, address: Address, data: Hex, - params: CallParams = {}, + params?: WriteParams, ) { return this.awaitResult( this.claimIncentiveRaw(boostId, incentiveId, address, data, params), @@ -354,31 +354,33 @@ export class BoostCore extends Deployable<[Address, Address]> { incentiveId: bigint, address: Address, data: Hex, - params: CallParams = {}, + params?: WriteParams, ) { return writeBoostCoreClaimIncentive(this._config, { address: this.assertValidAddress(), args: [boostId, incentiveId, address, data], ...this.optionallyAttachAccount(), - ...params, + // biome-ignore lint/suspicious/noExplicitAny: Accept any shape of valid wagmi/viem parameters, wagmi does the same thing internally + ...(params as any), }); } public async readBoost( id: bigint, - params: CallParams = {}, + params?: ReadParams, ) { return readBoostCoreGetBoost(this._config, { address: this.assertValidAddress(), args: [id], ...this.optionallyAttachAccount(), - ...params, + // biome-ignore lint/suspicious/noExplicitAny: Accept any shape of valid wagmi/viem parameters, wagmi does the same thing internally + ...(params as any), }); } public async getBoost( _id: string | bigint, - params: CallParams = {}, + params?: ReadParams, ) { let id: bigint; if (typeof _id === 'string') { @@ -422,19 +424,20 @@ export class BoostCore extends Deployable<[Address, Address]> { } public async getBoostCount( - params: CallParams = {}, + params?: ReadParams, ) { return readBoostCoreGetBoostCount(this._config, { address: this.assertValidAddress(), args: [], ...this.optionallyAttachAccount(), - ...params, + // biome-ignore lint/suspicious/noExplicitAny: Accept any shape of valid wagmi/viem parameters, wagmi does the same thing internally + ...(params as any), }); } public async setProcolFeeReceiver( address: Address, - params: CallParams = {}, + params?: WriteParams, ) { return this.awaitResult( this.setProcolFeeReceiverRaw(address, params), @@ -445,19 +448,20 @@ export class BoostCore extends Deployable<[Address, Address]> { public async setProcolFeeReceiverRaw( address: Address, - params: CallParams = {}, + params?: WriteParams, ) { return writeBoostCoreSetProtocolFeeReceiver(this._config, { address: this.assertValidAddress(), args: [address], ...this.optionallyAttachAccount(), - ...params, + // biome-ignore lint/suspicious/noExplicitAny: Accept any shape of valid wagmi/viem parameters, wagmi does the same thing internally + ...(params as any), }); } public async setClaimFee( claimFee: bigint, - params: CallParams = {}, + params?: WriteParams, ) { return this.awaitResult( this.setClaimFeeRaw(claimFee, params), @@ -468,13 +472,14 @@ export class BoostCore extends Deployable<[Address, Address]> { public async setClaimFeeRaw( claimFee: bigint, - params: CallParams = {}, + params?: WriteParams, ) { return writeBoostCoreSetClaimFee(this._config, { address: this.assertValidAddress(), args: [claimFee], ...this.optionallyAttachAccount(), - ...params, + // biome-ignore lint/suspicious/noExplicitAny: Accept any shape of valid wagmi/viem parameters, wagmi does the same thing internally + ...(params as any), }); } diff --git a/packages/sdk/src/Budgets/SimpleBudget.ts b/packages/sdk/src/Budgets/SimpleBudget.ts index 3f87b9ef0..a4a463ee8 100644 --- a/packages/sdk/src/Budgets/SimpleBudget.ts +++ b/packages/sdk/src/Budgets/SimpleBudget.ts @@ -1,6 +1,10 @@ import { + type ERC1155TransferPayload, + type FungibleTransferPayload, type SimpleBudgetPayload, type TransferPayload, + prepareERC1155Transfer, + prepareFungibleTransfer, prepareSimpleBudgetPayload, prepareTransferPayload, readSimpleBudgetAvailable, @@ -10,7 +14,7 @@ import { readSimpleBudgetSupportsInterface, readSimpleBudgetTotal, readVestingBudgetStart, - simpleAllowListAbi, + simpleBudgetAbi, simulateSimpleBudgetAllocate, simulateSimpleBudgetDisburse, simulateSimpleBudgetDisburseBatch, @@ -24,102 +28,124 @@ import { } from '@boostxyz/evm'; import { bytecode } from '@boostxyz/evm/artifacts/contracts/budgets/SimpleBudget.sol/SimpleBudget.json'; import { getAccount } from '@wagmi/core'; +import type { CreateWriteContractParameters } from '@wagmi/core/codegen'; import { type Address, type Hex, zeroAddress } from 'viem'; -import { - Deployable, - type DeployableOptions, - type GenericDeployableParams, +import { writeContract } from 'viem/actions'; +import type { + DeployableOptions, + GenericDeployableParams, } from '../Deployable/Deployable'; import { DeployableTarget } from '../Deployable/DeployableTarget'; -import { DeployableUnknownOwnerProvidedError } from '../errors'; -import type { CallParams } from '../utils'; +import { + DeployableUnknownOwnerProvidedError, + UnknownTransferPayloadSupplied, +} from '../errors'; +import type { ReadParams, WriteParams } from '../utils'; export type { SimpleBudgetPayload }; +export function isFungibleTransfer( + transfer: FungibleTransferPayload | ERC1155TransferPayload, +): transfer is FungibleTransferPayload { + return (transfer as ERC1155TransferPayload).tokenId === undefined; +} + +export function isERC1155TransferPayload( + transfer: FungibleTransferPayload | ERC1155TransferPayload, +): transfer is ERC1155TransferPayload { + return (transfer as ERC1155TransferPayload).tokenId !== undefined; +} + +export function prepareTransfer( + transfer: FungibleTransferPayload | ERC1155TransferPayload, +) { + if (isFungibleTransfer(transfer)) { + return prepareFungibleTransfer(transfer); + } else if (isERC1155TransferPayload(transfer)) { + return prepareERC1155Transfer(transfer); + } else throw new UnknownTransferPayloadSupplied(transfer); +} + export class SimpleBudget extends DeployableTarget { public static base = import.meta.env.VITE_SIMPLE_BUDGET_BASE; public override readonly base = SimpleBudget.base; - public start(params: CallParams = {}) { - return readVestingBudgetStart(this._config, { - address: this.assertValidAddress(), - ...params, - }); - } - public async allocate( - transfer: TransferPayload, - params: CallParams = {}, + transfer: FungibleTransferPayload | ERC1155TransferPayload, + params?: WriteParams, ) { return this.awaitResult( this.allocateRaw(transfer, params), - simpleAllowListAbi, + simpleBudgetAbi, simulateSimpleBudgetAllocate, ); } public allocateRaw( - transfer: TransferPayload, - params: CallParams = {}, + transfer: FungibleTransferPayload | ERC1155TransferPayload, + params?: WriteParams, ) { return writeSimpleBudgetAllocate(this._config, { address: this.assertValidAddress(), - args: [prepareTransferPayload(transfer)], - ...params, + args: [prepareTransfer(transfer)], + // biome-ignore lint/suspicious/noExplicitAny: Accept any shape of valid wagmi/viem parameters, wagmi does the same thing internally + ...(params as any), }); } public async reclaim( - transfer: TransferPayload, - params: CallParams = {}, + transfer: FungibleTransferPayload | ERC1155TransferPayload, + params?: WriteParams, ) { return this.awaitResult( this.reclaimRaw(transfer, params), - simpleAllowListAbi, + simpleBudgetAbi, simulateSimpleBudgetReclaim, ); } public reclaimRaw( - transfer: TransferPayload, - params: CallParams = {}, + transfer: FungibleTransferPayload | ERC1155TransferPayload, + params?: WriteParams, ) { return writeSimpleBudgetReclaim(this._config, { address: this.assertValidAddress(), - args: [prepareTransferPayload(transfer)], - ...params, + args: [prepareTransfer(transfer)], + // biome-ignore lint/suspicious/noExplicitAny: Accept any shape of valid wagmi/viem parameters, wagmi does the same thing internally + ...(params as any), }); } public async disburse( - transfer: TransferPayload, - params: CallParams = {}, + transfer: FungibleTransferPayload | ERC1155TransferPayload, + params?: WriteParams, ) { return this.awaitResult( this.disburseRaw(transfer, params), - simpleAllowListAbi, + simpleBudgetAbi, simulateSimpleBudgetDisburse, ); } public disburseRaw( - transfer: TransferPayload, - params: CallParams = {}, + transfer: FungibleTransferPayload | ERC1155TransferPayload, + params?: WriteParams, ) { return writeSimpleBudgetDisburse(this._config, { address: this.assertValidAddress(), - args: [prepareTransferPayload(transfer)], - ...params, + args: [prepareTransfer(transfer)], + // biome-ignore lint/suspicious/noExplicitAny: Accept any shape of valid wagmi/viem parameters, wagmi does the same thing internally + ...(params as any), }); } public async disburseBatch( - transfers: TransferPayload[], - params: CallParams = {}, + transfers: Array, + params?: WriteParams, ) { return this.awaitResult( this.disburseBatchRaw(transfers, params), - simpleAllowListAbi, + simpleBudgetAbi, simulateSimpleBudgetDisburseBatch, ); } @@ -127,24 +153,25 @@ export class SimpleBudget extends DeployableTarget { // use prepareFungibleTransfer or prepareERC1155Transfer // TODO use data structure public disburseBatchRaw( - transfers: TransferPayload[], - params: CallParams = {}, + transfers: Array, + params?: WriteParams, ) { return writeSimpleBudgetDisburseBatch(this._config, { address: this.assertValidAddress(), - args: [transfers.map(prepareTransferPayload)], - ...params, + args: [transfers.map(prepareTransfer)], + // biome-ignore lint/suspicious/noExplicitAny: Accept any shape of valid wagmi/viem parameters, wagmi does the same thing internally + ...(params as any), }); } public async setAuthorized( addresses: Address[], allowed: boolean[], - params: CallParams = {}, + params?: WriteParams, ) { return this.awaitResult( this.setAuthorizedRaw(addresses, allowed, params), - simpleAllowListAbi, + simpleBudgetAbi, simulateSimpleBudgetSetAuthorized, ); } @@ -152,81 +179,88 @@ export class SimpleBudget extends DeployableTarget { public async setAuthorizedRaw( addresses: Address[], allowed: boolean[], - params: CallParams = {}, + params?: WriteParams, ) { return await writeSimpleBudgetSetAuthorized(this._config, { address: this.assertValidAddress(), args: [addresses, allowed], - ...params, + // biome-ignore lint/suspicious/noExplicitAny: Accept any shape of valid wagmi/viem parameters, wagmi does the same thing internally + ...(params as any), }); } public isAuthorized( account: Address, - params: CallParams = {}, + params?: ReadParams, ) { return readSimpleBudgetIsAuthorized(this._config, { address: this.assertValidAddress(), args: [account], - ...params, + // biome-ignore lint/suspicious/noExplicitAny: Accept any shape of valid wagmi/viem parameters, wagmi does the same thing internally + ...(params as any), }); } public total( asset: Address, tokenId: bigint | undefined, - params: CallParams = {}, + params?: ReadParams, ) { return readSimpleBudgetTotal(this._config, { address: this.assertValidAddress(), args: tokenId ? [asset, tokenId] : [asset], - ...params, + // biome-ignore lint/suspicious/noExplicitAny: Accept any shape of valid wagmi/viem parameters, wagmi does the same thing internally + ...(params as any), }); } public available( asset: Address, tokenId: bigint | undefined, - params: CallParams = {}, + params?: ReadParams, ) { return readSimpleBudgetAvailable(this._config, { address: this.assertValidAddress(), args: tokenId ? [asset, tokenId] : [asset], - ...params, + // biome-ignore lint/suspicious/noExplicitAny: Accept any shape of valid wagmi/viem parameters, wagmi does the same thing internally + ...(params as any), }); } public distributed( asset: Address, tokenId: bigint | undefined, - params: CallParams = {}, + params?: ReadParams, ) { return readSimpleBudgetDistributed(this._config, { address: this.assertValidAddress(), args: tokenId ? [asset, tokenId] : [asset], - ...params, + // biome-ignore lint/suspicious/noExplicitAny: Accept any shape of valid wagmi/viem parameters, wagmi does the same thing internally + ...(params as any), }); } public async supportsInterface( interfaceId: Hex, - params: CallParams = {}, + params?: ReadParams, ) { return readSimpleBudgetSupportsInterface(this._config, { address: this.assertValidAddress(), ...this.optionallyAttachAccount(), - ...params, + // biome-ignore lint/suspicious/noExplicitAny: Accept any shape of valid wagmi/viem parameters, wagmi does the same thing internally + ...(params as any), args: [interfaceId], }); } public async getComponentInterface( - params: CallParams = {}, + params?: ReadParams, ) { return readSimpleBudgetGetComponentInterface(this._config, { address: this.assertValidAddress(), ...this.optionallyAttachAccount(), - ...params, + // biome-ignore lint/suspicious/noExplicitAny: Accept any shape of valid wagmi/viem parameters, wagmi does the same thing internally + ...(params as any), args: [], }); } @@ -252,7 +286,7 @@ export class SimpleBudget extends DeployableTarget { } } return { - abi: simpleAllowListAbi, + abi: simpleBudgetAbi, bytecode: bytecode as Hex, args: [prepareSimpleBudgetPayload(payload)], ...this.optionallyAttachAccount(options.account), diff --git a/packages/sdk/src/Budgets/VestingBudget.ts b/packages/sdk/src/Budgets/VestingBudget.ts index cbd651ce6..8f7afbeca 100644 --- a/packages/sdk/src/Budgets/VestingBudget.ts +++ b/packages/sdk/src/Budgets/VestingBudget.ts @@ -1,7 +1,7 @@ import { - type TransferPayload, + type FungibleTransferPayload, type VestingBudgetPayload, - prepareTransferPayload, + prepareFungibleTransfer, prepareVestingBudgetPayload, readVestingBudgetAvailable, readVestingBudgetCliff, @@ -34,7 +34,7 @@ import type { } from '../Deployable/Deployable'; import { DeployableTarget } from '../Deployable/DeployableTarget'; import { DeployableUnknownOwnerProvidedError } from '../errors'; -import type { CallParams } from '../utils'; +import type { ReadParams, WriteParams } from '../utils'; export type { VestingBudgetPayload }; @@ -42,33 +42,36 @@ export class VestingBudget extends DeployableTarget { public static base = import.meta.env.VITE_VESTING_BUDGET_BASE; public override readonly base = VestingBudget.base; - public start(params: CallParams = {}) { + public start(params?: ReadParams) { return readVestingBudgetStart(this._config, { address: this.assertValidAddress(), args: [], - ...params, + // biome-ignore lint/suspicious/noExplicitAny: Accept any shape of valid wagmi/viem parameters, wagmi does the same thing internally + ...(params as any), }); } - public duration(params: CallParams = {}) { + public duration(params?: ReadParams) { return readVestingBudgetDuration(this._config, { address: this.assertValidAddress(), args: [], - ...params, + // biome-ignore lint/suspicious/noExplicitAny: Accept any shape of valid wagmi/viem parameters, wagmi does the same thing internally + ...(params as any), }); } - public cliff(params: CallParams = {}) { + public cliff(params?: ReadParams) { return readVestingBudgetCliff(this._config, { address: this.assertValidAddress(), args: [], - ...params, + // biome-ignore lint/suspicious/noExplicitAny: Accept any shape of valid wagmi/viem parameters, wagmi does the same thing internally + ...(params as any), }); } public async allocate( - transfer: TransferPayload, - params: CallParams = {}, + transfer: FungibleTransferPayload, + params?: WriteParams, ) { return this.awaitResult( this.allocateRaw(transfer, params), @@ -78,19 +81,20 @@ export class VestingBudget extends DeployableTarget { } public allocateRaw( - transfer: TransferPayload, - params: CallParams = {}, + transfer: FungibleTransferPayload, + params?: WriteParams, ) { return writeVestingBudgetAllocate(this._config, { address: this.assertValidAddress(), - args: [prepareTransferPayload(transfer)], - ...params, + args: [prepareFungibleTransfer(transfer)], + // biome-ignore lint/suspicious/noExplicitAny: Accept any shape of valid wagmi/viem parameters, wagmi does the same thing internally + ...(params as any), }); } public async reclaim( - transfer: TransferPayload, - params: CallParams = {}, + transfer: FungibleTransferPayload, + params?: WriteParams, ) { return this.awaitResult( this.reclaimRaw(transfer, params), @@ -100,19 +104,20 @@ export class VestingBudget extends DeployableTarget { } public reclaimRaw( - transfer: TransferPayload, - params: CallParams = {}, + transfer: FungibleTransferPayload, + params?: WriteParams, ) { return writeVestingBudgetReclaim(this._config, { address: this.assertValidAddress(), - args: [prepareTransferPayload(transfer)], - ...params, + args: [prepareFungibleTransfer(transfer)], + // biome-ignore lint/suspicious/noExplicitAny: Accept any shape of valid wagmi/viem parameters, wagmi does the same thing internally + ...(params as any), }); } public async disburse( - transfer: TransferPayload, - params: CallParams = {}, + transfer: FungibleTransferPayload, + params?: WriteParams, ) { return this.awaitResult( this.disburseRaw(transfer, params), @@ -122,19 +127,20 @@ export class VestingBudget extends DeployableTarget { } public disburseRaw( - transfer: TransferPayload, - params: CallParams = {}, + transfer: FungibleTransferPayload, + params?: WriteParams, ) { return writeVestingBudgetDisburse(this._config, { address: this.assertValidAddress(), - args: [prepareTransferPayload(transfer)], - ...params, + args: [prepareFungibleTransfer(transfer)], + // biome-ignore lint/suspicious/noExplicitAny: Accept any shape of valid wagmi/viem parameters, wagmi does the same thing internally + ...(params as any), }); } public async disburseBatch( - transfers: TransferPayload[], - params: CallParams = {}, + transfers: FungibleTransferPayload[], + params?: WriteParams, ) { return this.awaitResult( this.disburseBatchRaw(transfers, params), @@ -144,20 +150,21 @@ export class VestingBudget extends DeployableTarget { } public disburseBatchRaw( - transfers: TransferPayload[], - params: CallParams = {}, + transfers: FungibleTransferPayload[], + params?: WriteParams, ) { return writeVestingBudgetDisburseBatch(this._config, { address: this.assertValidAddress(), - args: [transfers.map(prepareTransferPayload)], - ...params, + args: [transfers.map(prepareFungibleTransfer)], + // biome-ignore lint/suspicious/noExplicitAny: Accept any shape of valid wagmi/viem parameters, wagmi does the same thing internally + ...(params as any), }); } public async setAuthorized( addresses: Address[], allowed: boolean[], - params: CallParams = {}, + params?: WriteParams, ) { return this.awaitResult( this.setAuthorizedRaw(addresses, allowed, params), @@ -169,86 +176,94 @@ export class VestingBudget extends DeployableTarget { public async setAuthorizedRaw( addresses: Address[], allowed: boolean[], - params: CallParams = {}, + params?: WriteParams, ) { return await writeVestingBudgetSetAuthorized(this._config, { address: this.assertValidAddress(), args: [addresses, allowed], - ...params, + // biome-ignore lint/suspicious/noExplicitAny: Accept any shape of valid wagmi/viem parameters, wagmi does the same thing internally + ...(params as any), }); } public isAuthorized( account: Address, - params: CallParams = {}, + params?: ReadParams, ) { return readVestingBudgetIsAuthorized(this._config, { address: this.assertValidAddress(), args: [account], - ...params, + // biome-ignore lint/suspicious/noExplicitAny: Accept any shape of valid wagmi/viem parameters, wagmi does the same thing internally + ...(params as any), }); } - public end(params: CallParams = {}) { + public end(params?: ReadParams) { return readVestingBudgetEnd(this._config, { address: this.assertValidAddress(), args: [], - ...params, + // biome-ignore lint/suspicious/noExplicitAny: Accept any shape of valid wagmi/viem parameters, wagmi does the same thing internally + ...(params as any), }); } public total( asset: Address, - params: CallParams = {}, + params?: ReadParams, ) { return readVestingBudgetTotal(this._config, { address: this.assertValidAddress(), args: [asset], - ...params, + // biome-ignore lint/suspicious/noExplicitAny: Accept any shape of valid wagmi/viem parameters, wagmi does the same thing internally + ...(params as any), }); } public available( asset: Address, - params: CallParams = {}, + params?: ReadParams, ) { return readVestingBudgetAvailable(this._config, { address: this.assertValidAddress(), args: [asset], - ...params, + // biome-ignore lint/suspicious/noExplicitAny: Accept any shape of valid wagmi/viem parameters, wagmi does the same thing internally + ...(params as any), }); } public distributed( asset: Address, - params: CallParams = {}, + params?: ReadParams, ) { return readVestingBudgetDistributed(this._config, { address: this.assertValidAddress(), args: [asset], - ...params, + // biome-ignore lint/suspicious/noExplicitAny: Accept any shape of valid wagmi/viem parameters, wagmi does the same thing internally + ...(params as any), }); } public async supportsInterface( interfaceId: Hex, - params: CallParams = {}, + params?: ReadParams, ) { return readVestingBudgetSupportsInterface(this._config, { address: this.assertValidAddress(), ...this.optionallyAttachAccount(), - ...params, + // biome-ignore lint/suspicious/noExplicitAny: Accept any shape of valid wagmi/viem parameters, wagmi does the same thing internally + ...(params as any), args: [interfaceId], }); } public async getComponentInterface( - params: CallParams = {}, + params?: ReadParams, ) { return readVestingBudgetGetComponentInterface(this._config, { address: this.assertValidAddress(), ...this.optionallyAttachAccount(), - ...params, + // biome-ignore lint/suspicious/noExplicitAny: Accept any shape of valid wagmi/viem parameters, wagmi does the same thing internally + ...(params as any), args: [], }); } diff --git a/packages/sdk/src/Deployable/Contract.ts b/packages/sdk/src/Deployable/Contract.ts index b042614ca..b8706606b 100644 --- a/packages/sdk/src/Deployable/Contract.ts +++ b/packages/sdk/src/Deployable/Contract.ts @@ -46,7 +46,7 @@ export class Contract { hashPromise: Promise, abi: abi, fn: CreateSimulateContractReturnType, - waitParams: Omit = {}, + waitParams?: Omit, ) { return awaitResult(this._config, hashPromise, abi, fn, waitParams); } diff --git a/packages/sdk/src/Deployable/Deployable.ts b/packages/sdk/src/Deployable/Deployable.ts index 75eb7436a..722fff93f 100644 --- a/packages/sdk/src/Deployable/Deployable.ts +++ b/packages/sdk/src/Deployable/Deployable.ts @@ -57,7 +57,7 @@ export class Deployable extends Contract { public async deploy( _payload?: Payload, _options?: DeployableOptions, - waitParams: Omit = {}, + waitParams?: Omit, ): Promise
{ const config = _options?.config || this._config; const address = await getDeployedContractAddress( diff --git a/packages/sdk/src/Incentives/AllowListIncentive.ts b/packages/sdk/src/Incentives/AllowListIncentive.ts index aca075b10..8c689a9f0 100644 --- a/packages/sdk/src/Incentives/AllowListIncentive.ts +++ b/packages/sdk/src/Incentives/AllowListIncentive.ts @@ -23,7 +23,7 @@ import type { GenericDeployableParams, } from '../Deployable/Deployable'; import { DeployableTarget } from '../Deployable/DeployableTarget'; -import type { CallParams } from '../utils'; +import type { ReadParams, WriteParams } from '../utils'; export type { AllowListIncentivePayload }; @@ -32,42 +32,46 @@ export class AllowListIncentive extends DeployableTarget = {}, + params?: ReadParams, ) { return readAllowListIncentiveClaims(this._config, { address: this.assertValidAddress(), args: [], - ...params, + // biome-ignore lint/suspicious/noExplicitAny: Accept any shape of valid wagmi/viem parameters, wagmi does the same thing internally + ...(params as any), }); } public async reward( - params: CallParams = {}, + params?: ReadParams, ) { return readAllowListIncentiveReward(this._config, { address: this.assertValidAddress(), args: [], - ...params, + // biome-ignore lint/suspicious/noExplicitAny: Accept any shape of valid wagmi/viem parameters, wagmi does the same thing internally + ...(params as any), }); } public async claimed( address: Address, - params: CallParams = {}, + params?: ReadParams, ) { return readAllowListIncentiveClaimed(this._config, { address: this.assertValidAddress(), args: [address], - ...params, + // biome-ignore lint/suspicious/noExplicitAny: Accept any shape of valid wagmi/viem parameters, wagmi does the same thing internally + ...(params as any), }); } public async allowList( - params: CallParams = {}, + params?: ReadParams, ): Promise { const address = await readAllowListIncentiveAllowList(this._config, { address: this.assertValidAddress(), - ...params, + // biome-ignore lint/suspicious/noExplicitAny: Accept any shape of valid wagmi/viem parameters, wagmi does the same thing internally + ...(params as any), }); return new SimpleAllowList( { config: this._config, account: this._account }, @@ -76,17 +80,18 @@ export class AllowListIncentive extends DeployableTarget = {}, + params?: ReadParams, ) { return readAllowListIncentiveLimit(this._config, { address: this.assertValidAddress(), - ...params, + // biome-ignore lint/suspicious/noExplicitAny: Accept any shape of valid wagmi/viem parameters, wagmi does the same thing internally + ...(params as any), }); } public async claim( payload: ClaimPayload, - params: CallParams = {}, + params?: WriteParams, ) { return this.awaitResult( this.claimRaw(payload, params), @@ -97,46 +102,50 @@ export class AllowListIncentive extends DeployableTarget = {}, + params?: WriteParams, ) { return writeAllowListIncentiveClaim(this._config, { address: this.assertValidAddress(), args: [prepareClaimPayload(payload)], - ...params, + // biome-ignore lint/suspicious/noExplicitAny: Accept any shape of valid wagmi/viem parameters, wagmi does the same thing internally + ...(params as any), }); } // use prepareClaimPayload? public async isClaimable( payload: ClaimPayload, - params: CallParams = {}, + params?: ReadParams, ) { return readAllowListIncentiveIsClaimable(this._config, { address: this.assertValidAddress(), args: [prepareClaimPayload(payload)], - ...params, + // biome-ignore lint/suspicious/noExplicitAny: Accept any shape of valid wagmi/viem parameters, wagmi does the same thing internally + ...(params as any), }); } public async supportsInterface( interfaceId: Hex, - params: CallParams = {}, + params?: ReadParams, ) { return readAllowListIncentiveSupportsInterface(this._config, { address: this.assertValidAddress(), ...this.optionallyAttachAccount(), - ...params, + // biome-ignore lint/suspicious/noExplicitAny: Accept any shape of valid wagmi/viem parameters, wagmi does the same thing internally + ...(params as any), args: [interfaceId], }); } public async getComponentInterface( - params: CallParams = {}, + params?: ReadParams, ) { return readAllowListIncentiveGetComponentInterface(this._config, { address: this.assertValidAddress(), ...this.optionallyAttachAccount(), - ...params, + // biome-ignore lint/suspicious/noExplicitAny: Accept any shape of valid wagmi/viem parameters, wagmi does the same thing internally + ...(params as any), args: [], }); } diff --git a/packages/sdk/src/Incentives/CGDAIncentive.ts b/packages/sdk/src/Incentives/CGDAIncentive.ts index 53f411281..df5f8770c 100644 --- a/packages/sdk/src/Incentives/CGDAIncentive.ts +++ b/packages/sdk/src/Incentives/CGDAIncentive.ts @@ -27,7 +27,7 @@ import type { GenericDeployableParams, } from '../Deployable/Deployable'; import { DeployableTarget } from '../Deployable/DeployableTarget'; -import type { CallParams } from '../utils'; +import type { ReadParams, WriteParams } from '../utils'; export type { CGDAIncentivePayload }; @@ -35,47 +35,52 @@ export class CGDAIncentive extends DeployableTarget { public static base = import.meta.env.VITE_CGDA_INCENTIVE_BASE; public override readonly base = CGDAIncentive.base; - public async claims(params: CallParams = {}) { + public async claims(params?: ReadParams) { return readCgdaIncentiveClaims(this._config, { address: this.assertValidAddress(), args: [], - ...params, + // biome-ignore lint/suspicious/noExplicitAny: Accept any shape of valid wagmi/viem parameters, wagmi does the same thing internally + ...(params as any), }); } - public async reward(params: CallParams = {}) { + public async reward(params?: ReadParams) { return readCgdaIncentiveReward(this._config, { address: this.assertValidAddress(), args: [], - ...params, + // biome-ignore lint/suspicious/noExplicitAny: Accept any shape of valid wagmi/viem parameters, wagmi does the same thing internally + ...(params as any), }); } public async claimed( address: Address, - params: CallParams = {}, + params?: ReadParams, ) { return readCgdaIncentiveClaimed(this._config, { address: this.assertValidAddress(), args: [address], - ...params, + // biome-ignore lint/suspicious/noExplicitAny: Accept any shape of valid wagmi/viem parameters, wagmi does the same thing internally + ...(params as any), }); } - public async asset(params: CallParams = {}) { + public async asset(params?: ReadParams) { return readCgdaIncentiveAsset(this._config, { address: this.assertValidAddress(), - ...params, + // biome-ignore lint/suspicious/noExplicitAny: Accept any shape of valid wagmi/viem parameters, wagmi does the same thing internally + ...(params as any), }); } public async cgdaParams( - params: CallParams = {}, + params?: ReadParams, ): Promise { const [rewardDecay, rewardBoost, lastClaimTime, currentReward] = await readCgdaIncentiveCgdaParams(this._config, { address: this.assertValidAddress(), - ...params, + // biome-ignore lint/suspicious/noExplicitAny: Accept any shape of valid wagmi/viem parameters, wagmi does the same thing internally + ...(params as any), }); return { rewardDecay, @@ -86,17 +91,18 @@ export class CGDAIncentive extends DeployableTarget { } public async totalBudget( - params: CallParams = {}, + params?: ReadParams, ) { return readCgdaIncentiveTotalBudget(this._config, { address: this.assertValidAddress(), - ...params, + // biome-ignore lint/suspicious/noExplicitAny: Accept any shape of valid wagmi/viem parameters, wagmi does the same thing internally + ...(params as any), }); } public async claim( payload: ClaimPayload, - params: CallParams = {}, + params?: WriteParams, ) { return this.awaitResult( this.claimRaw(payload, params), @@ -107,18 +113,19 @@ export class CGDAIncentive extends DeployableTarget { public async claimRaw( payload: ClaimPayload, - params: CallParams = {}, + params?: WriteParams, ) { return writeCgdaIncentiveClaim(this._config, { address: this.assertValidAddress(), args: [prepareClaimPayload(payload)], - ...params, + // biome-ignore lint/suspicious/noExplicitAny: Accept any shape of valid wagmi/viem parameters, wagmi does the same thing internally + ...(params as any), }); } public async reclaim( payload: ClaimPayload, - params: CallParams = {}, + params?: WriteParams, ) { return this.awaitResult( this.reclaimRaw(payload, params), @@ -129,65 +136,71 @@ export class CGDAIncentive extends DeployableTarget { public async reclaimRaw( payload: ClaimPayload, - params: CallParams = {}, + params?: WriteParams, ) { return writeCgdaIncentiveReclaim(this._config, { address: this.assertValidAddress(), args: [prepareClaimPayload(payload)], - ...params, + // biome-ignore lint/suspicious/noExplicitAny: Accept any shape of valid wagmi/viem parameters, wagmi does the same thing internally + ...(params as any), }); } public async isClaimable( payload: ClaimPayload, - params: CallParams = {}, + params?: ReadParams, ) { return readCgdaIncentiveIsClaimable(this._config, { address: this.assertValidAddress(), args: [prepareClaimPayload(payload)], - ...params, + // biome-ignore lint/suspicious/noExplicitAny: Accept any shape of valid wagmi/viem parameters, wagmi does the same thing internally + ...(params as any), }); } public async preflight( data: CGDAIncentivePayload, - params: CallParams = {}, + params?: ReadParams, ) { return readCgdaIncentiveIsClaimable(this._config, { address: this.assertValidAddress(), args: [prepareCGDAIncentivePayload(data)], - ...params, + // biome-ignore lint/suspicious/noExplicitAny: Accept any shape of valid wagmi/viem parameters, wagmi does the same thing internally + ...(params as any), }); } public async currentReward( - params: CallParams = {}, + params?: ReadParams, ) { return readCgdaIncentiveCurrentReward(this._config, { address: this.assertValidAddress(), - ...params, + // biome-ignore lint/suspicious/noExplicitAny: Accept any shape of valid wagmi/viem parameters, wagmi does the same thing internally + ...(params as any), }); } public async supportsInterface( interfaceId: Hex, - params: CallParams = {}, + params?: ReadParams, ) { return readCgdaIncentiveSupportsInterface(this._config, { address: this.assertValidAddress(), ...this.optionallyAttachAccount(), - ...params, + // biome-ignore lint/suspicious/noExplicitAny: Accept any shape of valid wagmi/viem parameters, wagmi does the same thing internally + ...(params as any), args: [interfaceId], }); } public async getComponentInterface( - params: CallParams = {}, + params?: ReadParams, ) { return readCgdaIncentiveGetComponentInterface(this._config, { address: this.assertValidAddress(), ...this.optionallyAttachAccount(), - ...params, + // biome-ignore lint/suspicious/noExplicitAny: Accept any shape of valid wagmi/viem parameters, wagmi does the same thing internally + ...(params as any), args: [], }); } diff --git a/packages/sdk/src/Incentives/ERC1155Incentive.ts b/packages/sdk/src/Incentives/ERC1155Incentive.ts index 62e514398..5e9b41410 100644 --- a/packages/sdk/src/Incentives/ERC1155Incentive.ts +++ b/packages/sdk/src/Incentives/ERC1155Incentive.ts @@ -30,7 +30,7 @@ import type { GenericDeployableParams, } from '../Deployable/Deployable'; import { DeployableTarget } from '../Deployable/DeployableTarget'; -import type { CallParams } from '../utils'; +import type { ReadParams, WriteParams } from '../utils'; export type { ERC1155IncentivePayload, ERC1155StrategyType }; @@ -39,84 +39,88 @@ export class ERC1155Incentive extends DeployableTarget public override readonly base = ERC1155Incentive.base; public async claims( - params: CallParams = {}, + params?: ReadParams, ) { return readErc1155IncentiveClaims(this._config, { address: this.assertValidAddress(), args: [], - ...params, + // biome-ignore lint/suspicious/noExplicitAny: Accept any shape of valid wagmi/viem parameters, wagmi does the same thing internally + ...(params as any), }); } public async reward( - params: CallParams = {}, + params?: ReadParams, ) { return readErc1155IncentiveReward(this._config, { address: this.assertValidAddress(), args: [], - ...params, + // biome-ignore lint/suspicious/noExplicitAny: Accept any shape of valid wagmi/viem parameters, wagmi does the same thing internally + ...(params as any), }); } public async claimed( address: Address, - params: CallParams = {}, + params?: ReadParams, ) { return readErc1155IncentiveClaimed(this._config, { address: this.assertValidAddress(), args: [address], - ...params, + // biome-ignore lint/suspicious/noExplicitAny: Accept any shape of valid wagmi/viem parameters, wagmi does the same thing internally + ...(params as any), }); } - public async asset( - params: CallParams = {}, - ) { + public async asset(params?: ReadParams) { return readErc1155IncentiveAsset(this._config, { address: this.assertValidAddress(), - ...params, + // biome-ignore lint/suspicious/noExplicitAny: Accept any shape of valid wagmi/viem parameters, wagmi does the same thing internally + ...(params as any), }); } public async strategy( - params: CallParams = {}, + params?: ReadParams, ): Promise { return readErc1155IncentiveStrategy(this._config, { address: this.assertValidAddress(), - ...params, + // biome-ignore lint/suspicious/noExplicitAny: Accept any shape of valid wagmi/viem parameters, wagmi does the same thing internally + ...(params as any), }) as Promise; } - public async limit( - params: CallParams = {}, - ) { + public async limit(params?: ReadParams) { return readErc1155IncentiveLimit(this._config, { address: this.assertValidAddress(), - ...params, + // biome-ignore lint/suspicious/noExplicitAny: Accept any shape of valid wagmi/viem parameters, wagmi does the same thing internally + ...(params as any), }); } public async tokenId( - params: CallParams = {}, + params?: ReadParams, ) { return readErc1155IncentiveTokenId(this._config, { address: this.assertValidAddress(), - ...params, + // biome-ignore lint/suspicious/noExplicitAny: Accept any shape of valid wagmi/viem parameters, wagmi does the same thing internally + ...(params as any), }); } public async extraData( - params: CallParams = {}, + params?: ReadParams, ) { return readErc1155IncentiveExtraData(this._config, { address: this.assertValidAddress(), - ...params, + // biome-ignore lint/suspicious/noExplicitAny: Accept any shape of valid wagmi/viem parameters, wagmi does the same thing internally + ...(params as any), }); } public async claim( payload: ClaimPayload, - params: CallParams = {}, + params?: WriteParams, ) { return this.awaitResult( this.claimRaw(payload, params), @@ -127,18 +131,19 @@ export class ERC1155Incentive extends DeployableTarget public async claimRaw( payload: ClaimPayload, - params: CallParams = {}, + params?: WriteParams, ) { return writeErc1155IncentiveClaim(this._config, { address: this.assertValidAddress(), args: [prepareClaimPayload(payload)], - ...params, + // biome-ignore lint/suspicious/noExplicitAny: Accept any shape of valid wagmi/viem parameters, wagmi does the same thing internally + ...(params as any), }); } public async reclaim( payload: ClaimPayload, - params: CallParams = {}, + params?: WriteParams, ) { return this.awaitResult( this.reclaimRaw(payload, params), @@ -149,55 +154,60 @@ export class ERC1155Incentive extends DeployableTarget public async reclaimRaw( payload: ClaimPayload, - params: CallParams = {}, + params?: WriteParams, ) { return writeErc1155IncentiveReclaim(this._config, { address: this.assertValidAddress(), args: [prepareClaimPayload(payload)], - ...params, + // biome-ignore lint/suspicious/noExplicitAny: Accept any shape of valid wagmi/viem parameters, wagmi does the same thing internally + ...(params as any), }); } public async isClaimable( payload: ClaimPayload, - params: CallParams = {}, + params?: ReadParams, ) { return readErc1155IncentiveIsClaimable(this._config, { address: this.assertValidAddress(), args: [prepareClaimPayload(payload)], - ...params, + // biome-ignore lint/suspicious/noExplicitAny: Accept any shape of valid wagmi/viem parameters, wagmi does the same thing internally + ...(params as any), }); } public async preflight( data: ERC1155IncentivePayload, - params: CallParams = {}, + params?: ReadParams, ) { return readErc1155IncentivePreflight(this._config, { address: this.assertValidAddress(), args: [prepareERC1155IncentivePayload(data)], - ...params, + // biome-ignore lint/suspicious/noExplicitAny: Accept any shape of valid wagmi/viem parameters, wagmi does the same thing internally + ...(params as any), }); } public async supportsInterface( interfaceId: Hex, - params: CallParams = {}, + params?: ReadParams, ) { return readErc1155SupportsInterface(this._config, { address: this.assertValidAddress(), args: [interfaceId], - ...params, + // biome-ignore lint/suspicious/noExplicitAny: Accept any shape of valid wagmi/viem parameters, wagmi does the same thing internally + ...(params as any), }); } public async getComponentInterface( - params: CallParams = {}, + params?: ReadParams, ) { return readErc1155IncentiveGetComponentInterface(this._config, { address: this.assertValidAddress(), ...this.optionallyAttachAccount(), - ...params, + // biome-ignore lint/suspicious/noExplicitAny: Accept any shape of valid wagmi/viem parameters, wagmi does the same thing internally + ...(params as any), args: [], }); } diff --git a/packages/sdk/src/Incentives/ERC20Incentive.ts b/packages/sdk/src/Incentives/ERC20Incentive.ts index 1ef201f44..37795f8f0 100644 --- a/packages/sdk/src/Incentives/ERC20Incentive.ts +++ b/packages/sdk/src/Incentives/ERC20Incentive.ts @@ -30,7 +30,7 @@ import type { GenericDeployableParams, } from '../Deployable/Deployable'; import { DeployableTarget } from '../Deployable/DeployableTarget'; -import type { CallParams } from '../utils'; +import type { ReadParams, WriteParams } from '../utils'; export type { ERC20IncentivePayload }; @@ -38,73 +38,76 @@ export class ERC20Incentive extends DeployableTarget { public static base = import.meta.env.VITE_ERC20_INCENTIVE_BASE; public override readonly base = ERC20Incentive.base; - public async claims( - params: CallParams = {}, - ) { + public async claims(params?: ReadParams) { return readErc20IncentiveClaims(this._config, { address: this.assertValidAddress(), args: [], - ...params, + // biome-ignore lint/suspicious/noExplicitAny: Accept any shape of valid wagmi/viem parameters, wagmi does the same thing internally + ...(params as any), }); } public async claimed( address: Address, - params: CallParams = {}, + params?: ReadParams, ) { return readErc20IncentiveClaimed(this._config, { address: this.assertValidAddress(), args: [address], - ...params, + // biome-ignore lint/suspicious/noExplicitAny: Accept any shape of valid wagmi/viem parameters, wagmi does the same thing internally + ...(params as any), }); } - public async asset(params: CallParams = {}) { + public async asset(params?: ReadParams) { return readErc20IncentiveAsset(this._config, { address: this.assertValidAddress(), - ...params, + // biome-ignore lint/suspicious/noExplicitAny: Accept any shape of valid wagmi/viem parameters, wagmi does the same thing internally + ...(params as any), }); } public async strategy( - params: CallParams = {}, + params?: ReadParams, ): Promise { return readErc20IncentiveStrategy(this._config, { address: this.assertValidAddress(), - ...params, + // biome-ignore lint/suspicious/noExplicitAny: Accept any shape of valid wagmi/viem parameters, wagmi does the same thing internally + ...(params as any), }) as Promise; } - public async reward( - params: CallParams = {}, - ) { + public async reward(params?: ReadParams) { return readErc20IncentiveReward(this._config, { address: this.assertValidAddress(), - ...params, + // biome-ignore lint/suspicious/noExplicitAny: Accept any shape of valid wagmi/viem parameters, wagmi does the same thing internally + ...(params as any), }); } - public async limit(params: CallParams = {}) { + public async limit(params?: ReadParams) { return readErc20IncentiveLimit(this._config, { address: this.assertValidAddress(), - ...params, + // biome-ignore lint/suspicious/noExplicitAny: Accept any shape of valid wagmi/viem parameters, wagmi does the same thing internally + ...(params as any), }); } public async entries( i: bigint, - params: CallParams = {}, + params?: ReadParams, ) { return readErc20IncentiveEntries(this._config, { address: this.assertValidAddress(), args: [i], - ...params, + // biome-ignore lint/suspicious/noExplicitAny: Accept any shape of valid wagmi/viem parameters, wagmi does the same thing internally + ...(params as any), }); } public async claim( payload: ClaimPayload, - params: CallParams = {}, + params?: WriteParams, ) { return this.awaitResult( this.claimRaw(payload, params), @@ -115,18 +118,19 @@ export class ERC20Incentive extends DeployableTarget { public async claimRaw( payload: ClaimPayload, - params: CallParams = {}, + params?: WriteParams, ) { return writeErc20IncentiveClaim(this._config, { address: this.assertValidAddress(), args: [prepareClaimPayload(payload)], - ...params, + // biome-ignore lint/suspicious/noExplicitAny: Accept any shape of valid wagmi/viem parameters, wagmi does the same thing internally + ...(params as any), }); } public async reclaim( payload: ClaimPayload, - params: CallParams = {}, + params?: WriteParams, ) { return this.awaitResult( this.reclaimRaw(payload, params), @@ -137,39 +141,42 @@ export class ERC20Incentive extends DeployableTarget { public async reclaimRaw( payload: ClaimPayload, - params: CallParams = {}, + params?: WriteParams, ) { return writeErc20IncentiveReclaim(this._config, { address: this.assertValidAddress(), args: [prepareClaimPayload(payload)], - ...params, + // biome-ignore lint/suspicious/noExplicitAny: Accept any shape of valid wagmi/viem parameters, wagmi does the same thing internally + ...(params as any), }); } public async isClaimable( payload: ClaimPayload, - params: CallParams = {}, + params?: ReadParams, ) { return readErc20IncentiveIsClaimable(this._config, { address: this.assertValidAddress(), args: [prepareClaimPayload(payload)], - ...params, + // biome-ignore lint/suspicious/noExplicitAny: Accept any shape of valid wagmi/viem parameters, wagmi does the same thing internally + ...(params as any), }); } public async preflight( data: ERC20IncentivePayload, - params: CallParams = {}, + params?: ReadParams, ) { return readErc20IncentivePreflight(this._config, { address: this.assertValidAddress(), args: [prepareERC20IncentivePayload(data)], - ...params, + // biome-ignore lint/suspicious/noExplicitAny: Accept any shape of valid wagmi/viem parameters, wagmi does the same thing internally + ...(params as any), }); } public async drawRaffle( - params: CallParams = {}, + params?: WriteParams, ) { return this.awaitResult( this.drawRaffleRaw(params), @@ -179,33 +186,36 @@ export class ERC20Incentive extends DeployableTarget { } public async drawRaffleRaw( - params: CallParams = {}, + params?: WriteParams, ) { return writeErc20IncentiveDrawRaffle(this._config, { address: this.assertValidAddress(), - ...params, + // biome-ignore lint/suspicious/noExplicitAny: Accept any shape of valid wagmi/viem parameters, wagmi does the same thing internally + ...(params as any), }); } public async supportsInterface( interfaceId: Hex, - params: CallParams = {}, + params?: ReadParams, ) { return readErc20IncentiveSupportsInterface(this._config, { address: this.assertValidAddress(), ...this.optionallyAttachAccount(), - ...params, + // biome-ignore lint/suspicious/noExplicitAny: Accept any shape of valid wagmi/viem parameters, wagmi does the same thing internally + ...(params as any), args: [interfaceId], }); } public async getComponentInterface( - params: CallParams = {}, + params?: ReadParams, ) { return readErc20IncentiveGetComponentInterface(this._config, { address: this.assertValidAddress(), ...this.optionallyAttachAccount(), - ...params, + // biome-ignore lint/suspicious/noExplicitAny: Accept any shape of valid wagmi/viem parameters, wagmi does the same thing internally + ...(params as any), args: [], }); } diff --git a/packages/sdk/src/Incentives/PointsIncentive.ts b/packages/sdk/src/Incentives/PointsIncentive.ts index a26790187..06f78877c 100644 --- a/packages/sdk/src/Incentives/PointsIncentive.ts +++ b/packages/sdk/src/Incentives/PointsIncentive.ts @@ -24,7 +24,7 @@ import type { GenericDeployableParams, } from '../Deployable/Deployable'; import { DeployableTarget } from '../Deployable/DeployableTarget'; -import type { CallParams } from '../utils'; +import type { ReadParams, WriteParams } from '../utils'; export type { PointsIncentivePayload }; @@ -33,72 +33,79 @@ export class PointsIncentive extends DeployableTarget { public override readonly base = PointsIncentive.base; public async claims( - params: CallParams = {}, + params?: ReadParams, ) { return readPointsIncentiveClaims(this._config, { address: this.assertValidAddress(), args: [], - ...params, + // biome-ignore lint/suspicious/noExplicitAny: Accept any shape of valid wagmi/viem parameters, wagmi does the same thing internally + ...(params as any), }); } public async currentReward( - params: CallParams = {}, + params?: ReadParams, ) { return readPointsIncentiveCurrentReward(this._config, { address: this.assertValidAddress(), args: [], - ...params, + // biome-ignore lint/suspicious/noExplicitAny: Accept any shape of valid wagmi/viem parameters, wagmi does the same thing internally + ...(params as any), }); } public async reward( - params: CallParams = {}, + params?: ReadParams, ) { return readPointsIncentiveReward(this._config, { address: this.assertValidAddress(), args: [], - ...params, + // biome-ignore lint/suspicious/noExplicitAny: Accept any shape of valid wagmi/viem parameters, wagmi does the same thing internally + ...(params as any), }); } public async claimed( address: Address, - params: CallParams = {}, + params?: ReadParams, ) { return readPointsIncentiveClaimed(this._config, { address: this.assertValidAddress(), args: [address], - ...params, + // biome-ignore lint/suspicious/noExplicitAny: Accept any shape of valid wagmi/viem parameters, wagmi does the same thing internally + ...(params as any), }); } - public async venue(params: CallParams = {}) { + public async venue(params?: ReadParams) { return readPointsIncentiveVenue(this._config, { address: this.assertValidAddress(), - ...params, + // biome-ignore lint/suspicious/noExplicitAny: Accept any shape of valid wagmi/viem parameters, wagmi does the same thing internally + ...(params as any), }); } - public async limit(params: CallParams = {}) { + public async limit(params?: ReadParams) { return readPointsIncentiveLimit(this._config, { address: this.assertValidAddress(), - ...params, + // biome-ignore lint/suspicious/noExplicitAny: Accept any shape of valid wagmi/viem parameters, wagmi does the same thing internally + ...(params as any), }); } public async selector( - params: CallParams = {}, + params?: ReadParams, ) { return readPointsIncentiveSelector(this._config, { address: this.assertValidAddress(), - ...params, + // biome-ignore lint/suspicious/noExplicitAny: Accept any shape of valid wagmi/viem parameters, wagmi does the same thing internally + ...(params as any), }); } public async claim( payload: ClaimPayload, - params: CallParams = {}, + params?: WriteParams, ) { return this.awaitResult( this.claimRaw(payload, params), @@ -109,45 +116,48 @@ export class PointsIncentive extends DeployableTarget { public async claimRaw( payload: ClaimPayload, - params: CallParams = {}, + params?: WriteParams, ) { return writePointsIncentiveClaim(this._config, { address: this.assertValidAddress(), args: [prepareClaimPayload(payload)], - ...params, + // biome-ignore lint/suspicious/noExplicitAny: Accept any shape of valid wagmi/viem parameters, wagmi does the same thing internally + ...(params as any), }); } - //prepareClaimPayload public async isClaimable( payload: ClaimPayload, - params: CallParams = {}, + params?: ReadParams, ) { return readPointsIncentiveIsClaimable(this._config, { address: this.assertValidAddress(), args: [prepareClaimPayload(payload)], - ...params, + // biome-ignore lint/suspicious/noExplicitAny: Accept any shape of valid wagmi/viem parameters, wagmi does the same thing internally + ...(params as any), }); } public async supportsInterface( interfaceId: Hex, - params: CallParams = {}, + params?: ReadParams, ) { return readPointsIncentiveSupportsInterface(this._config, { address: this.assertValidAddress(), args: [interfaceId], - ...params, + // biome-ignore lint/suspicious/noExplicitAny: Accept any shape of valid wagmi/viem parameters, wagmi does the same thing internally + ...(params as any), }); } public async getComponentInterface( - params: CallParams = {}, + params?: ReadParams, ) { return readPointsIncentiveGetComponentInterface(this._config, { address: this.assertValidAddress(), ...this.optionallyAttachAccount(), - ...params, + // biome-ignore lint/suspicious/noExplicitAny: Accept any shape of valid wagmi/viem parameters, wagmi does the same thing internally + ...(params as any), args: [], }); } diff --git a/packages/sdk/src/Validators/SignerValidator.ts b/packages/sdk/src/Validators/SignerValidator.ts index 501d52633..93b21d00f 100644 --- a/packages/sdk/src/Validators/SignerValidator.ts +++ b/packages/sdk/src/Validators/SignerValidator.ts @@ -17,7 +17,7 @@ import type { GenericDeployableParams, } from '../Deployable/Deployable'; import { DeployableTarget } from '../Deployable/DeployableTarget'; -import type { CallParams } from '../utils'; +import type { ReadParams, WriteParams } from '../utils'; export type { SignerValidatorPayload }; @@ -27,18 +27,19 @@ export class SignerValidator extends DeployableTarget { public async signers( address: Address, - params: CallParams = {}, + params?: ReadParams, ) { return readSignerValidatorSigners(this._config, { address: this.assertValidAddress(), args: [address], - ...params, + // biome-ignore lint/suspicious/noExplicitAny: Accept any shape of valid wagmi/viem parameters, wagmi does the same thing internally + ...(params as any), }); } public async validate( payload: SignerValidatorValidatePayload, - params: CallParams = {}, + params?: WriteParams, ) { return this.awaitResult( this.validateRaw(payload, params), @@ -49,19 +50,20 @@ export class SignerValidator extends DeployableTarget { public async validateRaw( payload: SignerValidatorValidatePayload, - params: CallParams = {}, + params?: ReadParams, ) { return writeSignerValidatorValidate(this._config, { address: this.assertValidAddress(), args: [prepareSignerValidatorValidatePayload(payload)], - ...params, + // biome-ignore lint/suspicious/noExplicitAny: Accept any shape of valid wagmi/viem parameters, wagmi does the same thing internally + ...(params as any), }); } public async setAuthorized( addresses: Address[], allowed: boolean[], - params: CallParams = {}, + params?: WriteParams, ) { return this.awaitResult( this.setAuthorizedRaw(addresses, allowed, params), @@ -73,12 +75,13 @@ export class SignerValidator extends DeployableTarget { public async setAuthorizedRaw( addresses: Address[], allowed: boolean[], - params: CallParams = {}, + params?: WriteParams, ) { return await writeSignerValidatorSetAuthorized(this._config, { address: this.assertValidAddress(), args: [addresses, allowed], - ...params, + // biome-ignore lint/suspicious/noExplicitAny: Accept any shape of valid wagmi/viem parameters, wagmi does the same thing internally + ...(params as any), }); } diff --git a/packages/sdk/src/errors.ts b/packages/sdk/src/errors.ts index cb7999327..4a9070924 100644 --- a/packages/sdk/src/errors.ts +++ b/packages/sdk/src/errors.ts @@ -61,7 +61,9 @@ export class DeployableMissingPayloadError extends Error { export class NoContractAddressUponReceiptError extends Error { public readonly receipt: WaitForTransactionReceiptReturnType; constructor(receipt: WaitForTransactionReceiptReturnType) { - super(`Expected a contract address to exist on receipt.`); + super(`Expected a contract address to exist on receipt.`, { + cause: receipt, + }); this.receipt = receipt; } } @@ -71,8 +73,19 @@ export class InvalidComponentInterfaceError extends Error { public readonly received: Hex = zeroHash; constructor(expected: Hex[], received: Hex) { - super(`Address provided is not `); + super(`Address provided is not `, { cause: { expected, received } }); this.expected = expected; this.received = received; } } + +export class UnknownTransferPayloadSupplied extends Error { + received: unknown; + constructor(received: unknown) { + super( + `Did not provide a valid FungibleTransferPayload or ERC1155 transfer payload.`, + { cause: received }, + ); + this.received = received; + } +} diff --git a/packages/sdk/src/utils.ts b/packages/sdk/src/utils.ts index c450e31a1..5e22f3497 100644 --- a/packages/sdk/src/utils.ts +++ b/packages/sdk/src/utils.ts @@ -15,18 +15,33 @@ import { type ContractFunctionArgs, decodeFunctionData, } from 'viem'; +import type { WriteContractParameters } from 'viem/actions'; import { NoContractAddressUponReceiptError } from './errors'; -// biome-ignore lint/suspicious/noExplicitAny: -export type CallParams any> = Omit< - Parameters[1], - 'address' | 'args' +export type WriteParams< + abi extends Abi, + functionName extends ContractFunctionName, +> = Partial< + Omit< + WriteContractParameters, + 'address' | 'args' | 'functionName' | 'abi' + > +>; + +export type ReadParams< + abi extends Abi, + functionName extends ContractFunctionName, +> = Partial< + Omit< + WriteContractParameters, + 'address' | 'args' | 'functionName' | 'abi' + > >; export async function getDeployedContractAddress( config: Config, hash: Promise, - waitParams: Omit = {}, + waitParams?: Omit, ) { const receipt = await waitForTransactionReceipt(config, { ...waitParams, @@ -49,7 +64,7 @@ export async function awaitResult< undefined, functionName >, - waitParams: Omit = {}, + waitParams?: Omit, ) { const hash = await hashPromise; const receipt = await waitForTransactionReceipt(config, {