From a864d650d2d49d977602b3cdd2e55b6189cec043 Mon Sep 17 00:00:00 2001 From: Kyle Scott Date: Wed, 20 Sep 2023 16:57:45 -0400 Subject: [PATCH] format erc1155 and fix actions --- docs/.gitignore | 3 +- docs/.vitepress/config.mts | 142 ++++++- examples/next-interface/hooks/useBalance.ts | 20 +- examples/next-interface/hooks/useTransfer.ts | 11 +- packages/core/src/_test/constants.ts | 2 +- packages/core/src/erc1155/index.ts | 17 + .../erc1155/publicActions/getERC1155.test.ts | 43 ++ .../src/erc1155/publicActions/getERC1155.ts | 57 +++ .../publicActions/getERC1155BalanceOf.test.ts | 58 +++ .../publicActions/getERC1155BalanceOf.ts | 47 +++ .../getERC1155IsApprovedForAll.test.ts | 58 +++ .../getERC1155IsApprovedForAll.ts | 44 ++ .../publicActions/getERC1155URI.test.ts | 38 ++ .../erc1155/publicActions/getERC1155URI.ts | 38 ++ packages/core/src/erc1155/reads.test.ts | 100 ----- packages/core/src/erc1155/reads.ts | 115 ------ packages/core/src/erc1155/types.ts | 4 +- .../simulateERC1155SetApprovalForAll.test.ts | 71 ++++ .../simulateERC1155SetApprovalForAll.ts | 65 +++ .../simulateERC1155Transfer.test.ts | 70 ++++ .../walletActions/simulateERC1155Transfer.ts | 75 ++++ .../simulateERC1155TransferBatch.test.ts | 92 +++++ .../simulateERC1155TransferBatch.ts | 86 ++++ packages/core/src/erc1155/writes.test.ts | 136 ------- packages/core/src/erc1155/writes.ts | 111 ----- packages/core/src/erc721/index.ts | 2 +- packages/core/src/fraction/types.ts | 2 +- packages/core/src/fraction/utils.test.ts | 228 +++++------ packages/core/src/fraction/utils.ts | 2 +- packages/core/src/index.ts | 382 ++++++++---------- packages/core/src/price/utils.test.ts | 8 +- packages/core/src/price/utils.ts | 4 +- packages/core/src/utils/getQueryKey.ts | 9 +- 33 files changed, 1322 insertions(+), 818 deletions(-) create mode 100644 packages/core/src/erc1155/index.ts create mode 100644 packages/core/src/erc1155/publicActions/getERC1155.test.ts create mode 100644 packages/core/src/erc1155/publicActions/getERC1155.ts create mode 100644 packages/core/src/erc1155/publicActions/getERC1155BalanceOf.test.ts create mode 100644 packages/core/src/erc1155/publicActions/getERC1155BalanceOf.ts create mode 100644 packages/core/src/erc1155/publicActions/getERC1155IsApprovedForAll.test.ts create mode 100644 packages/core/src/erc1155/publicActions/getERC1155IsApprovedForAll.ts create mode 100644 packages/core/src/erc1155/publicActions/getERC1155URI.test.ts create mode 100644 packages/core/src/erc1155/publicActions/getERC1155URI.ts delete mode 100644 packages/core/src/erc1155/reads.test.ts delete mode 100644 packages/core/src/erc1155/reads.ts create mode 100644 packages/core/src/erc1155/walletActions/simulateERC1155SetApprovalForAll.test.ts create mode 100644 packages/core/src/erc1155/walletActions/simulateERC1155SetApprovalForAll.ts create mode 100644 packages/core/src/erc1155/walletActions/simulateERC1155Transfer.test.ts create mode 100644 packages/core/src/erc1155/walletActions/simulateERC1155Transfer.ts create mode 100644 packages/core/src/erc1155/walletActions/simulateERC1155TransferBatch.test.ts create mode 100644 packages/core/src/erc1155/walletActions/simulateERC1155TransferBatch.ts delete mode 100644 packages/core/src/erc1155/writes.test.ts delete mode 100644 packages/core/src/erc1155/writes.ts diff --git a/docs/.gitignore b/docs/.gitignore index b512c09..d2af4da 100644 --- a/docs/.gitignore +++ b/docs/.gitignore @@ -1 +1,2 @@ -node_modules \ No newline at end of file +node_modules +.vitepress/.* \ No newline at end of file diff --git a/docs/.vitepress/config.mts b/docs/.vitepress/config.mts index 682287a..0c87fe8 100644 --- a/docs/.vitepress/config.mts +++ b/docs/.vitepress/config.mts @@ -182,12 +182,150 @@ export default defineConfig({ { text: "ERC721", collapsed: true, - items: [{ text: "Introduction", link: "" }], + items: [ + { text: "Introduction", link: "" }, + { + text: "Utilities", + items: [ + { + text: "createERC721", + link: "", + }, + { + text: "createERC721Data", + link: "", + }, + { + text: "createERC721DataID", + link: "", + }, + ], + }, + { + text: "Public Actions", + items: [ + { + text: "getERC721", + link: "", + }, + { + text: "getERC721Approved", + link: "", + }, + { + text: "getERC721IsApprovedForAll", + link: "", + }, + { + text: "getERC721BalanceOf", + link: "", + }, + { + text: "getERC721Name", + link: "", + }, + { + text: "getERC721Symbol", + link: "", + }, + { + text: "getERC721OwnerOf", + link: "", + }, + { + text: "getERC721SupportsInterface", + link: "", + }, + { + text: "getERC721TokenURI", + link: "", + }, + { + text: "getERC721Data", + link: "", + }, + { + text: "getERC721DataID", + link: "", + }, + ], + }, + { + text: "Wallet Actions", + items: [ + { + text: "simulateERC721Transfer", + link: "", + }, + { + text: "simulateERC721Approve", + link: "", + }, + { + text: "simulateERC721SetApprovalForAll", + link: "", + }, + ], + }, + ], }, { text: "ERC1155", collapsed: true, - items: [{ text: "Introduction", link: "" }], + items: [ + { text: "Introduction", link: "" }, + { + text: "Utilities", + items: [ + { + text: "createERC1155", + link: "", + }, + { + text: "createERC1155Data", + link: "", + }, + ], + }, + { + text: "Public Actions", + items: [ + { + text: "getERC1155", + link: "", + }, + { + text: "getERC1155IsApprovedForAll", + link: "", + }, + { + text: "getERC1155BalanceOf", + link: "", + }, + { + text: "getERC1155URI", + link: "", + }, + ], + }, + { + text: "Wallet Actions", + items: [ + { + text: "simulateERC1155Transfer", + link: "", + }, + { + text: "simulateERC1155TransferBatch", + link: "", + }, + { + text: "simulateERC1155SetApprovalForAll", + link: "", + }, + ], + }, + ], }, { text: "Amount", diff --git a/examples/next-interface/hooks/useBalance.ts b/examples/next-interface/hooks/useBalance.ts index 98e2ab0..7134236 100644 --- a/examples/next-interface/hooks/useBalance.ts +++ b/examples/next-interface/hooks/useBalance.ts @@ -1,5 +1,5 @@ import { useQuery } from "@tanstack/react-query"; -import { type ERC20, erc20BalanceOf, getQueryKey } from "reverse-mirage"; +import { type ERC20, getERC20BalanceOf, getQueryKey } from "reverse-mirage"; import { type Address, usePublicClient } from "wagmi"; import type { HookArg } from "./internal/types"; import { userRefectchInterval } from "./internal/utils"; @@ -14,19 +14,23 @@ export const useBalance = ( return useQuery({ queryKey: getQueryKey( - erc20BalanceOf, + getERC20BalanceOf, { erc20: erc20!, address: address! }, chainID, ), enabled: [erc20, address].some((a) => a === undefined) ? false : true, queryFn: () => - erc20BalanceOf({ - args: { erc20: erc20!, address: address! }, - }).read(publicClient), + getERC20BalanceOf( + publicClient, + { erc20: erc20!, address: address! }, + "select", + ).read(), select: (data) => - erc20BalanceOf({ - args: { erc20: erc20!, address: address! }, - }).parse(data), + getERC20BalanceOf( + publicClient, + { erc20: erc20!, address: address! }, + "select", + ).parse(data), staleTime: Infinity, refetchInterval: userRefectchInterval, }); diff --git a/examples/next-interface/hooks/useTransfer.ts b/examples/next-interface/hooks/useTransfer.ts index 53d09b0..20b643b 100644 --- a/examples/next-interface/hooks/useTransfer.ts +++ b/examples/next-interface/hooks/useTransfer.ts @@ -4,9 +4,9 @@ import { useMemo } from "react"; import { type BaseERC20, type ERC20Amount, - erc20BalanceOf, - erc20Transfer, + getERC20BalanceOf, getQueryKey, + simulateERC20Transfer, } from "reverse-mirage"; import { getAddress } from "viem"; import { type Address, useWalletClient } from "wagmi"; @@ -36,9 +36,8 @@ export const useTransfer = ( } & { toast: TxToast; }) => { - const { request } = await erc20Transfer(client, { - to, - amount, + const { request } = await simulateERC20Transfer(client, { + args: { to, amount }, }); const hash = await walletClient.data!.writeContract(request); @@ -59,7 +58,7 @@ export const useTransfer = ( await Promise.all([ queryClient.invalidateQueries({ queryKey: getQueryKey( - erc20BalanceOf, + getERC20BalanceOf, { erc20: input.amount.token, address: getAddress(data.from), diff --git a/packages/core/src/_test/constants.ts b/packages/core/src/_test/constants.ts index a33dde5..0c02956 100644 --- a/packages/core/src/_test/constants.ts +++ b/packages/core/src/_test/constants.ts @@ -1,6 +1,6 @@ import { foundry } from "viem/chains"; import type { NativeCurrency } from "../native/types.js"; -import type { Token } from "../types.js"; +import type { Token } from "../types/token.js"; // Test accounts export const ACCOUNTS = [ diff --git a/packages/core/src/erc1155/index.ts b/packages/core/src/erc1155/index.ts new file mode 100644 index 0000000..899fbf7 --- /dev/null +++ b/packages/core/src/erc1155/index.ts @@ -0,0 +1,17 @@ +export type { + ERC1155, + ERC1155Data, +} from "./types.js"; + +export { createERC1155, createERC1155Data } from "./utils.js"; + +export { solmateErc1155ABI as solmateERC1155ABI } from "../generated.js"; + +export { getERC1155 } from "./publicActions/getERC1155.js"; +export { getERC1155BalanceOf } from "./publicActions/getERC1155BalanceOf.js"; +export { getERC1155IsApprovedForAll } from "./publicActions/getERC1155IsApprovedForAll.js"; +export { getERC1155URI } from "./publicActions/getERC1155URI.js"; + +export { simulateERC1155Transfer } from "./walletActions/simulateERC1155Transfer.js"; +export { simulateERC1155TransferBatch } from "./walletActions/simulateERC1155TransferBatch.js"; +export { simulateERC1155SetApprovalForAll } from "./walletActions/simulateERC1155SetApprovalForAll.js"; diff --git a/packages/core/src/erc1155/publicActions/getERC1155.test.ts b/packages/core/src/erc1155/publicActions/getERC1155.test.ts new file mode 100644 index 0000000..dd77bf7 --- /dev/null +++ b/packages/core/src/erc1155/publicActions/getERC1155.test.ts @@ -0,0 +1,43 @@ +import invariant from "tiny-invariant"; +import { type Hex } from "viem"; +import { foundry } from "viem/chains"; +import { beforeEach, expect, test } from "vitest"; +import ERC1155Bytecode from "../../../../../contracts/out/ERC1155.sol/ERC1155.json"; +import { publicClient, testClient, walletClient } from "../../_test/utils.js"; +import { erc1155ABI } from "../../generated.js"; +import type { ERC1155 } from "../types.js"; +import { createERC1155 } from "../utils.js"; +import { getERC1155 } from "./getERC1155.js"; + +let id: Hex | undefined = undefined; + +let erc1155: ERC1155; + +beforeEach(async () => { + if (id === undefined) { + const deployHash = await walletClient.deployContract({ + abi: erc1155ABI, + bytecode: ERC1155Bytecode.bytecode.object as Hex, + args: ["https://mitch.com"], + }); + + const { contractAddress } = await publicClient.waitForTransactionReceipt({ + hash: deployHash, + }); + invariant(contractAddress); + erc1155 = createERC1155( + contractAddress, + 0n, + "https://mitch.com", + foundry.id, + ); + } else { + await testClient.revert({ id }); + } + + id = await testClient.snapshot(); +}); + +test("getERC1155", async () => { + expect(await getERC1155(publicClient, { erc1155 })).toStrictEqual(erc1155); +}); diff --git a/packages/core/src/erc1155/publicActions/getERC1155.ts b/packages/core/src/erc1155/publicActions/getERC1155.ts new file mode 100644 index 0000000..2ff4b85 --- /dev/null +++ b/packages/core/src/erc1155/publicActions/getERC1155.ts @@ -0,0 +1,57 @@ +import type { Chain, Client, ReadContractParameters, Transport } from "viem"; +import { readContract } from "viem/contract"; +import { solmateErc1155ABI as solmateERC1155ABI } from "../../generated.js"; +import type { ReverseMirage } from "../../types/rm.js"; +import type { ERC1155 } from "../types.js"; +import { createERC1155 } from "../utils.js"; + +export type GetERC1155Parameters = Omit< + ReadContractParameters, + "address" | "abi" | "functionName" | "args" +> & { + erc1155: Pick & + Partial>; +}; + +export type GetERC1155ReturnType = ERC1155; + +export const getERC1155 = < + TChain extends Chain | undefined, + T extends "select" | undefined, +>( + client: Client, + args: GetERC1155Parameters, + type?: T, +): ReverseMirage => + (type === undefined + ? readContract(client, { + abi: solmateERC1155ABI, + address: args.erc1155.address, + functionName: "uri", + args: [args.erc1155.id], + }).then((data) => + createERC1155( + args.erc1155.address, + args.erc1155.id, + data, + args.erc1155.chainID, + args.blockNumber, + ), + ) + : { + read: () => + readContract(client, { + abi: solmateERC1155ABI, + address: args.erc1155.address, + functionName: "uri", + args: [args.erc1155.id], + }), + parse: (data) => + createERC1155( + args.erc1155.address, + args.erc1155.id, + data, + args.erc1155.chainID, + args.blockNumber, + ), + }) as ReverseMirage; diff --git a/packages/core/src/erc1155/publicActions/getERC1155BalanceOf.test.ts b/packages/core/src/erc1155/publicActions/getERC1155BalanceOf.test.ts new file mode 100644 index 0000000..5603f5c --- /dev/null +++ b/packages/core/src/erc1155/publicActions/getERC1155BalanceOf.test.ts @@ -0,0 +1,58 @@ +import invariant from "tiny-invariant"; +import { type Hex, getAddress } from "viem"; +import { foundry } from "viem/chains"; +import { beforeEach, expect, test } from "vitest"; +import ERC1155Bytecode from "../../../../../contracts/out/ERC1155.sol/ERC1155.json"; +import { ALICE } from "../../_test/constants.js"; +import { publicClient, testClient, walletClient } from "../../_test/utils.js"; +import { erc1155ABI } from "../../generated.js"; +import type { ERC1155 } from "../types.js"; +import { createERC1155 } from "../utils.js"; +import { getERC1155BalanceOf } from "./getERC1155BalanceOf.js"; + +let id: Hex | undefined = undefined; + +let erc1155: ERC1155; + +beforeEach(async () => { + if (id === undefined) { + const deployHash = await walletClient.deployContract({ + abi: erc1155ABI, + bytecode: ERC1155Bytecode.bytecode.object as Hex, + args: ["https://mitch.com"], + }); + + const { contractAddress } = await publicClient.waitForTransactionReceipt({ + hash: deployHash, + }); + invariant(contractAddress); + erc1155 = createERC1155( + contractAddress, + 0n, + "https://mitch.com", + foundry.id, + ); + + const mintHash = await walletClient.writeContract({ + abi: erc1155ABI, + functionName: "mint", + address: getAddress(contractAddress!), + args: [ALICE, 0n, 10n, "0x"], + }); + await publicClient.waitForTransactionReceipt({ hash: mintHash }); + } else { + await testClient.revert({ id }); + } + + id = await testClient.snapshot(); +}); + +test("balanceOf", async () => { + const balance = await getERC1155BalanceOf(publicClient, { + erc1155, + address: ALICE, + }); + + expect(balance.amount).toBe(10n); + expect(balance.token).toStrictEqual(erc1155); +}); diff --git a/packages/core/src/erc1155/publicActions/getERC1155BalanceOf.ts b/packages/core/src/erc1155/publicActions/getERC1155BalanceOf.ts new file mode 100644 index 0000000..c5a91ca --- /dev/null +++ b/packages/core/src/erc1155/publicActions/getERC1155BalanceOf.ts @@ -0,0 +1,47 @@ +import type { + Address, + Chain, + Client, + ReadContractParameters, + Transport, +} from "viem"; +import { readContract } from "viem/contract"; +import { solmateErc1155ABI as solmateERC1155ABI } from "../../generated.js"; +import type { ReverseMirage } from "../../types/rm.js"; +import type { ERC1155, ERC1155Data } from "../types.js"; +import { createERC1155Data } from "../utils.js"; + +export type GetERC1155BalanceOfParameters = Omit< + ReadContractParameters, + "address" | "abi" | "functionName" | "args" +> & { erc1155: TERC1155; address: Address }; + +export type GetERC1155BalanceOfReturnType = + ERC1155Data; + +export const getERC1155BalanceOf = < + TChain extends Chain | undefined, + TERC1155 extends ERC1155, + T extends "select" | undefined, +>( + client: Client, + args: GetERC1155BalanceOfParameters, + type?: T, +): ReverseMirage, T> => + (type === undefined + ? readContract(client, { + abi: solmateERC1155ABI, + address: args.erc1155.address, + functionName: "balanceOf", + args: [args.address, args.erc1155.id], + }).then((data) => createERC1155Data(args.erc1155, data)) + : { + read: () => + readContract(client, { + abi: solmateERC1155ABI, + address: args.erc1155.address, + functionName: "balanceOf", + args: [args.address, args.erc1155.id], + }), + parse: (data) => createERC1155Data(args.erc1155, data), + }) as ReverseMirage, T>; diff --git a/packages/core/src/erc1155/publicActions/getERC1155IsApprovedForAll.test.ts b/packages/core/src/erc1155/publicActions/getERC1155IsApprovedForAll.test.ts new file mode 100644 index 0000000..b6117b0 --- /dev/null +++ b/packages/core/src/erc1155/publicActions/getERC1155IsApprovedForAll.test.ts @@ -0,0 +1,58 @@ +import invariant from "tiny-invariant"; +import { type Hex, getAddress } from "viem"; +import { foundry } from "viem/chains"; +import { beforeEach, expect, test } from "vitest"; +import ERC1155Bytecode from "../../../../../contracts/out/ERC1155.sol/ERC1155.json"; +import { ALICE, BOB } from "../../_test/constants.js"; +import { publicClient, testClient, walletClient } from "../../_test/utils.js"; +import { erc1155ABI } from "../../generated.js"; +import type { ERC1155 } from "../types.js"; +import { createERC1155 } from "../utils.js"; +import { getERC1155IsApprovedForAll } from "./getERC1155IsApprovedForAll.js"; + +let id: Hex | undefined = undefined; + +let erc1155: ERC1155; + +beforeEach(async () => { + if (id === undefined) { + const deployHash = await walletClient.deployContract({ + abi: erc1155ABI, + bytecode: ERC1155Bytecode.bytecode.object as Hex, + args: ["https://mitch.com"], + }); + + const { contractAddress } = await publicClient.waitForTransactionReceipt({ + hash: deployHash, + }); + invariant(contractAddress); + erc1155 = createERC1155( + contractAddress, + 0n, + "https://mitch.com", + foundry.id, + ); + + const hash = await walletClient.writeContract({ + abi: erc1155ABI, + functionName: "setApprovalForAll", + address: getAddress(contractAddress!), + args: [BOB, true], + }); + await publicClient.waitForTransactionReceipt({ hash }); + } else { + await testClient.revert({ id }); + } + + id = await testClient.snapshot(); +}); + +test("isApprovedForAll", async () => { + const isApprovedForAll = await getERC1155IsApprovedForAll(publicClient, { + erc1155, + owner: ALICE, + spender: BOB, + }); + + expect(isApprovedForAll).toBe(true); +}); diff --git a/packages/core/src/erc1155/publicActions/getERC1155IsApprovedForAll.ts b/packages/core/src/erc1155/publicActions/getERC1155IsApprovedForAll.ts new file mode 100644 index 0000000..05b885c --- /dev/null +++ b/packages/core/src/erc1155/publicActions/getERC1155IsApprovedForAll.ts @@ -0,0 +1,44 @@ +import type { + Address, + Chain, + Client, + ReadContractParameters, + Transport, +} from "viem"; +import { readContract } from "viem/contract"; +import { solmateErc1155ABI as solmateERC1155ABI } from "../../generated.js"; +import type { ReverseMirage } from "../../types/rm.js"; +import type { ERC1155 } from "../types.js"; + +export type GetERC1155IsApprovedForAllParameters = Omit< + ReadContractParameters, + "address" | "abi" | "functionName" | "args" +> & { erc1155: Pick; owner: Address; spender: Address }; + +export type GetERC1155IsApprovedForAllReturnType = boolean; + +export const getERC1155IsApprovedForAll = < + TChain extends Chain | undefined, + T extends "select" | undefined, +>( + client: Client, + args: GetERC1155IsApprovedForAllParameters, + type?: T, +): ReverseMirage => + (type === undefined + ? readContract(client, { + abi: solmateERC1155ABI, + address: args.erc1155.address, + functionName: "isApprovedForAll", + args: [args.owner, args.spender], + }) + : { + read: () => + readContract(client, { + abi: solmateERC1155ABI, + address: args.erc1155.address, + functionName: "isApprovedForAll", + args: [args.owner, args.spender], + }), + parse: (data) => data, + }) as ReverseMirage; diff --git a/packages/core/src/erc1155/publicActions/getERC1155URI.test.ts b/packages/core/src/erc1155/publicActions/getERC1155URI.test.ts new file mode 100644 index 0000000..0716c4a --- /dev/null +++ b/packages/core/src/erc1155/publicActions/getERC1155URI.test.ts @@ -0,0 +1,38 @@ +import invariant from "tiny-invariant"; +import { type Hex } from "viem"; +import { foundry } from "viem/chains"; +import { beforeEach, expect, test } from "vitest"; +import ERC1155Bytecode from "../../../../../contracts/out/ERC1155.sol/ERC1155.json"; +import { publicClient, testClient, walletClient } from "../../_test/utils.js"; +import { erc1155ABI } from "../../generated.js"; +import type { ERC1155 } from "../types.js"; +import { createERC1155 } from "../utils.js"; +import { getERC1155URI } from "./getERC1155URI.js"; + +let id: Hex | undefined = undefined; + +let erc1155: ERC1155; + +beforeEach(async () => { + if (id === undefined) { + const deployHash = await walletClient.deployContract({ + abi: erc1155ABI, + bytecode: ERC1155Bytecode.bytecode.object as Hex, + args: ["mitch.com"], + }); + + const { contractAddress } = await publicClient.waitForTransactionReceipt({ + hash: deployHash, + }); + invariant(contractAddress); + erc1155 = createERC1155(contractAddress, 0n, "mitch.com", foundry.id); + } else { + await testClient.revert({ id }); + } + + id = await testClient.snapshot(); +}); + +test("getERC1155", async () => { + expect(await getERC1155URI(publicClient, { erc1155 })).toBe("mitch.com"); +}); diff --git a/packages/core/src/erc1155/publicActions/getERC1155URI.ts b/packages/core/src/erc1155/publicActions/getERC1155URI.ts new file mode 100644 index 0000000..6eb0eaa --- /dev/null +++ b/packages/core/src/erc1155/publicActions/getERC1155URI.ts @@ -0,0 +1,38 @@ +import type { Chain, Client, ReadContractParameters, Transport } from "viem"; +import { readContract } from "viem/contract"; +import { solmateErc1155ABI as solmateERC1155ABI } from "../../generated.js"; +import type { ReverseMirage } from "../../types/rm.js"; +import type { ERC1155 } from "../types.js"; + +export type GetERC1155URIParameters = Omit< + ReadContractParameters, + "address" | "abi" | "functionName" | "args" +> & { erc1155: Pick }; + +export type GetERC1155URIReturnType = string; + +export const getERC1155URI = < + TChain extends Chain | undefined, + T extends "select" | undefined, +>( + client: Client, + args: GetERC1155URIParameters, + type?: T, +): ReverseMirage => + (type === undefined + ? readContract(client, { + abi: solmateERC1155ABI, + address: args.erc1155.address, + functionName: "uri", + args: [args.erc1155.id], + }) + : { + read: () => + readContract(client, { + abi: solmateERC1155ABI, + address: args.erc1155.address, + functionName: "uri", + args: [args.erc1155.id], + }), + parse: (data) => data, + }) as ReverseMirage; diff --git a/packages/core/src/erc1155/reads.test.ts b/packages/core/src/erc1155/reads.test.ts deleted file mode 100644 index 3838545..0000000 --- a/packages/core/src/erc1155/reads.test.ts +++ /dev/null @@ -1,100 +0,0 @@ -import invariant from "tiny-invariant"; -import { type Hex, getAddress } from "viem"; -import { foundry } from "viem/chains"; -import { beforeEach, describe, expect, test } from "vitest"; -import ERC1155Bytecode from "../../../../contracts/out/ERC1155.sol/ERC1155.json"; -import { ALICE, BOB } from "../_test/constants.js"; -import { publicClient, testClient, walletClient } from "../_test/utils.js"; -import { erc1155ABI } from "../generated.js"; -import { - erc1155BalanceOf, - erc1155IsApprovedForAll, - erc1155URI, - getERC1155, -} from "./reads.js"; -import type { ERC1155 } from "./types.js"; -import { createERC1155 } from "./utils.js"; -import { erc1155SetApprovalForAll } from "./writes.js"; - -let id: Hex | undefined = undefined; - -let erc1155: ERC1155; - -beforeEach(async () => { - if (id === undefined) { - const deployHash = await walletClient.deployContract({ - abi: erc1155ABI, - bytecode: ERC1155Bytecode.bytecode.object as Hex, - args: ["https://mitch.com"], - }); - - const { contractAddress } = await publicClient.waitForTransactionReceipt({ - hash: deployHash, - }); - invariant(contractAddress); - erc1155 = createERC1155( - contractAddress, - 0n, - "https://mitch.com", - foundry.id, - ); - - const mintHash = await walletClient.writeContract({ - abi: erc1155ABI, - functionName: "mint", - address: getAddress(contractAddress!), - args: [ALICE, 0n, 10n, "0x"], - }); - await publicClient.waitForTransactionReceipt({ hash: mintHash }); - - const { request } = await erc1155SetApprovalForAll(publicClient, { - erc1155, - spender: BOB, - approved: true, - account: ALICE, - }); - const hash = await walletClient.writeContract(request); - await publicClient.waitForTransactionReceipt({ hash }); - } else { - await testClient.revert({ id }); - } - - id = await testClient.snapshot(); -}); - -describe("erc1155 reads", async () => { - test("isApprovedForAll", async () => { - const isApprovedForAll = await erc1155IsApprovedForAll({ - publicClient, - args: { - erc1155, - owner: ALICE, - spender: BOB, - }, - }); - - expect(isApprovedForAll).toBe(true); - }); - - test("uri", async () => { - const uri = await erc1155URI({ publicClient, args: { erc1155 } }); - - expect(uri).toBe("https://mitch.com"); - }); - - test("balanceOf", async () => { - const balance = await erc1155BalanceOf({ - publicClient, - args: { erc1155, address: ALICE }, - }); - - expect(balance.amount).toBe(10n); - expect(balance.token).toBe(erc1155); - }); - - test("getERC1155", async () => { - expect(await getERC1155({ publicClient, args: { erc1155 } })).toStrictEqual( - erc1155, - ); - }); -}); diff --git a/packages/core/src/erc1155/reads.ts b/packages/core/src/erc1155/reads.ts deleted file mode 100644 index 70fba79..0000000 --- a/packages/core/src/erc1155/reads.ts +++ /dev/null @@ -1,115 +0,0 @@ -import type { Address, PublicClient } from "viem"; -import { solmateErc1155ABI } from "../generated.js"; -import { createReverseMirage } from "../readUtils.js"; -import type { ReverseMirage, ReverseMirageRead } from "../types.js"; -import type { ERC1155, ERC1155Data } from "./types.js"; -import { createERC1155, createERC1155Data } from "./utils.js"; - -export const erc1155IsApprovedForAll: ReverseMirage< - boolean, - boolean, - { - erc1155: Pick; - owner: Address; - spender: Address; - } -> = createReverseMirage( - (args: { - erc1155: Pick; - owner: Address; - spender: Address; - }) => ({ - read: (publicClient: PublicClient) => - publicClient.readContract({ - abi: solmateErc1155ABI, - address: args.erc1155.address, - functionName: "isApprovedForAll", - args: [args.owner, args.spender], - }), - parse: (data) => data, - }), -); - -export const erc1155URI: ReverseMirage< - string, - string, - { - erc1155: Pick; - } -> = createReverseMirage( - (args: { - erc1155: Pick; - }) => ({ - read: (publicClient: PublicClient) => - publicClient.readContract({ - abi: solmateErc1155ABI, - address: args.erc1155.address, - functionName: "uri", - args: [args.erc1155.id], - }), - parse: (data) => data, - }), -); - -export const erc1155BalanceOf = < - TA extends { - args: { - erc1155: ERC1155; - address: Address; - }; - publicClient?: PublicClient; - }, ->( - a: TA, -) => - ("publicClient" in a - ? a.publicClient - .readContract({ - abi: solmateErc1155ABI, - address: a.args.erc1155.address, - functionName: "balanceOf", - args: [a.args.address, a.args.erc1155.id], - }) - .then((data) => createERC1155Data(a.args.erc1155, data)) - : { - read: (publicClient: PublicClient) => - publicClient.readContract({ - abi: solmateErc1155ABI, - address: a.args.erc1155.address, - functionName: "balanceOf", - args: [a.args.address, a.args.erc1155.id], - }), - parse: (data) => createERC1155Data(a.args.erc1155, data), - }) as TA extends { publicClient: PublicClient } - ? Promise> - : ReverseMirageRead>; - -export const getERC1155: ReverseMirage< - string, - ERC1155, - { - erc1155: Pick & - Partial>; - } -> = createReverseMirage( - (args: { - erc1155: Pick & - Partial>; - }) => ({ - read: (publicClient: PublicClient) => - publicClient.readContract({ - abi: solmateErc1155ABI, - address: args.erc1155.address, - functionName: "uri", - args: [args.erc1155.id], - }), - parse: (data): ERC1155 => - createERC1155( - args.erc1155.address, - args.erc1155.id, - data, - args.erc1155.chainID, - args.erc1155.blockCreated, - ), - }), -); diff --git a/packages/core/src/erc1155/types.ts b/packages/core/src/erc1155/types.ts index 8fa5967..4480e08 100644 --- a/packages/core/src/erc1155/types.ts +++ b/packages/core/src/erc1155/types.ts @@ -1,6 +1,6 @@ import type { Address } from "viem"; -import type { Amount } from "../amount.js"; -import type { Token } from "../types.js"; +import type { Amount } from "../amount/types.js"; +import type { Token } from "../types/token.js"; export type ERC1155 = Token<"erc1155"> & { address: Address; diff --git a/packages/core/src/erc1155/walletActions/simulateERC1155SetApprovalForAll.test.ts b/packages/core/src/erc1155/walletActions/simulateERC1155SetApprovalForAll.test.ts new file mode 100644 index 0000000..528c23e --- /dev/null +++ b/packages/core/src/erc1155/walletActions/simulateERC1155SetApprovalForAll.test.ts @@ -0,0 +1,71 @@ +import invariant from "tiny-invariant"; +import { type Hex, getAddress, parseEther } from "viem"; +import { foundry } from "viem/chains"; +import { beforeEach, expect, test } from "vitest"; +import ERC1155Bytecode from "../../../../../contracts/out/ERC1155.sol/ERC1155.json"; +import { ALICE, BOB } from "../../_test/constants.js"; +import { publicClient, testClient, walletClient } from "../../_test/utils.js"; +import { erc1155ABI } from "../../generated.js"; +import { getERC1155IsApprovedForAll } from "../publicActions/getERC1155IsApprovedForAll.js"; +import type { ERC1155 } from "../types.js"; +import { createERC1155 } from "../utils.js"; +import { simulateERC1155SetApprovalForAll } from "./simulateERC1155SetApprovalForAll.js"; + +let id: Hex | undefined = undefined; + +let erc1155: ERC1155; + +beforeEach(async () => { + if (id === undefined) { + const deployHash = await walletClient.deployContract({ + abi: erc1155ABI, + bytecode: ERC1155Bytecode.bytecode.object as Hex, + args: ["https://mitch.com"], + }); + + const { contractAddress } = await publicClient.waitForTransactionReceipt({ + hash: deployHash, + }); + invariant(contractAddress); + erc1155 = createERC1155( + contractAddress, + 0n, + "https://mitch.com", + foundry.id, + ); + + const mintHash = await walletClient.writeContract({ + abi: erc1155ABI, + functionName: "mint", + address: getAddress(contractAddress!), + args: [ALICE, 0n, parseEther("1"), "0x"], + }); + await publicClient.waitForTransactionReceipt({ hash: mintHash }); + } else { + await testClient.revert({ id }); + } + + id = await testClient.snapshot(); +}); + +test("set approval for all", async () => { + const { request } = await simulateERC1155SetApprovalForAll(publicClient, { + args: { + erc1155, + spender: BOB, + approved: true, + }, + account: ALICE, + }); + const hash = await walletClient.writeContract(request); + + await publicClient.waitForTransactionReceipt({ hash }); + + expect( + await getERC1155IsApprovedForAll(publicClient, { + erc1155, + spender: BOB, + owner: ALICE, + }), + ).toBe(true); +}); diff --git a/packages/core/src/erc1155/walletActions/simulateERC1155SetApprovalForAll.ts b/packages/core/src/erc1155/walletActions/simulateERC1155SetApprovalForAll.ts new file mode 100644 index 0000000..e61f602 --- /dev/null +++ b/packages/core/src/erc1155/walletActions/simulateERC1155SetApprovalForAll.ts @@ -0,0 +1,65 @@ +import type { + Address, + Chain, + Client, + SimulateContractParameters, + SimulateContractReturnType, + Transport, +} from "viem"; +import { simulateContract } from "viem/contract"; +import { solmateErc1155ABI as solmateERC1155 } from "../../generated.js"; +import type { ERC1155 } from "../types.js"; + +export type ERC1155SetApprovalForAllParameters = { + erc1155: Pick; + spender: Address; + approved: boolean; +}; + +export type SimulateERC1155SetApprovalForAllParameters< + TChain extends Chain | undefined = Chain, + TChainOverride extends Chain | undefined = Chain | undefined, +> = Omit< + SimulateContractParameters< + typeof solmateERC1155, + "setApprovalForAll", + TChain, + TChainOverride + >, + "args" | "address" | "abi" | "functionName" +> & { args: ERC1155SetApprovalForAllParameters }; + +export type SimulateERC1155SetApprovalForAllReturnType< + TChain extends Chain | undefined, + TChainOverride extends Chain | undefined = undefined, +> = SimulateContractReturnType< + typeof solmateERC1155, + "setApprovalForAll", + TChain, + TChainOverride +>; + +export const simulateERC1155SetApprovalForAll = < + TChain extends Chain | undefined, + TChainOverride extends Chain | undefined, +>( + client: Client, + { + args: { erc1155, spender, approved }, + ...request + }: SimulateERC1155SetApprovalForAllParameters, +): Promise< + SimulateERC1155SetApprovalForAllReturnType +> => + simulateContract(client, { + address: erc1155.address, + abi: solmateERC1155, + functionName: "setApprovalForAll", + args: [spender, approved], + ...request, + } as unknown as SimulateContractParameters< + typeof solmateERC1155, + "setApprovalForAll", + TChain, + TChainOverride + >); diff --git a/packages/core/src/erc1155/walletActions/simulateERC1155Transfer.test.ts b/packages/core/src/erc1155/walletActions/simulateERC1155Transfer.test.ts new file mode 100644 index 0000000..8031a8f --- /dev/null +++ b/packages/core/src/erc1155/walletActions/simulateERC1155Transfer.test.ts @@ -0,0 +1,70 @@ +import invariant from "tiny-invariant"; +import { type Hex, getAddress } from "viem"; +import { foundry } from "viem/chains"; +import { beforeEach, expect, test } from "vitest"; +import ERC1155Bytecode from "../../../../../contracts/out/ERC1155.sol/ERC1155.json"; +import { ALICE, BOB } from "../../_test/constants.js"; +import { publicClient, testClient, walletClient } from "../../_test/utils.js"; +import { erc1155ABI } from "../../generated.js"; +import { getERC1155BalanceOf } from "../publicActions/getERC1155BalanceOf.js"; +import type { ERC1155 } from "../types.js"; +import { createERC1155, createERC1155Data } from "../utils.js"; +import { simulateERC1155Transfer } from "./simulateERC1155Transfer.js"; + +let id: Hex | undefined = undefined; + +let erc1155: ERC1155; + +beforeEach(async () => { + if (id === undefined) { + const deployHash = await walletClient.deployContract({ + abi: erc1155ABI, + bytecode: ERC1155Bytecode.bytecode.object as Hex, + args: ["https://mitch.com"], + }); + + const { contractAddress } = await publicClient.waitForTransactionReceipt({ + hash: deployHash, + }); + invariant(contractAddress); + erc1155 = createERC1155( + contractAddress, + 0n, + "https://mitch.com", + foundry.id, + ); + + const mintHash = await walletClient.writeContract({ + abi: erc1155ABI, + functionName: "mint", + address: getAddress(contractAddress!), + args: [ALICE, 0n, 10n, "0x"], + }); + await publicClient.waitForTransactionReceipt({ hash: mintHash }); + } else { + await testClient.revert({ id }); + } + + id = await testClient.snapshot(); +}); + +test("can transfer", async () => { + const { request } = await simulateERC1155Transfer(publicClient, { + args: { to: BOB, erc1155Data: createERC1155Data(erc1155, 5n) }, + account: ALICE, + }); + const hash = await walletClient.writeContract(request); + await publicClient.waitForTransactionReceipt({ hash }); + + const balanceALICE = await getERC1155BalanceOf(publicClient, { + erc1155, + address: ALICE, + }); + expect(balanceALICE.amount).toBe(5n); + + const balanceBOB = await getERC1155BalanceOf(publicClient, { + erc1155, + address: BOB, + }); + expect(balanceBOB.amount).toBe(5n); +}); diff --git a/packages/core/src/erc1155/walletActions/simulateERC1155Transfer.ts b/packages/core/src/erc1155/walletActions/simulateERC1155Transfer.ts new file mode 100644 index 0000000..49824d2 --- /dev/null +++ b/packages/core/src/erc1155/walletActions/simulateERC1155Transfer.ts @@ -0,0 +1,75 @@ +import type { + Address, + Chain, + Client, + Hex, + SimulateContractParameters, + SimulateContractReturnType, + Transport, +} from "viem"; +import { simulateContract } from "viem/contract"; +import { solmateErc1155ABI as solmateERC1155 } from "../../generated.js"; +import type { ERC1155, ERC1155Data } from "../types.js"; + +export type ERC1155TransferParameters = { + erc1155Data: ERC1155Data; + from?: Address; + to: Address; + data?: Hex; +}; + +export type SimulateERC1155TransferParameters< + TChain extends Chain | undefined = Chain, + TChainOverride extends Chain | undefined = Chain | undefined, +> = Omit< + SimulateContractParameters< + typeof solmateERC1155, + "safeTransferFrom", + TChain, + TChainOverride + >, + "args" | "address" | "abi" | "functionName" +> & { args: ERC1155TransferParameters }; + +export type SimulateERC1155TransferReturnType< + TChain extends Chain | undefined, + TChainOverride extends Chain | undefined = undefined, +> = SimulateContractReturnType< + typeof solmateERC1155, + "safeTransferFrom", + TChain, + TChainOverride +>; + +export const simulateERC1155Transfer = < + TChain extends Chain | undefined, + TChainOverride extends Chain | undefined, +>( + client: Client, + { + args: { erc1155Data, to, from, data }, + ...request + }: SimulateERC1155TransferParameters, +): Promise> => + simulateContract(client, { + address: erc1155Data.token.address, + abi: solmateERC1155, + functionName: "safeTransferFrom", + args: [ + (from ?? + client.account?.address ?? + (typeof request.account === "object" + ? request.account.address + : request.account))!, + to, + erc1155Data.token.id, + erc1155Data.amount, + data ?? "0x", + ], + ...request, + } as unknown as SimulateContractParameters< + typeof solmateERC1155, + "safeTransferFrom", + TChain, + TChainOverride + >); diff --git a/packages/core/src/erc1155/walletActions/simulateERC1155TransferBatch.test.ts b/packages/core/src/erc1155/walletActions/simulateERC1155TransferBatch.test.ts new file mode 100644 index 0000000..dfb942a --- /dev/null +++ b/packages/core/src/erc1155/walletActions/simulateERC1155TransferBatch.test.ts @@ -0,0 +1,92 @@ +import invariant from "tiny-invariant"; +import { type Hex, getAddress, zeroAddress } from "viem"; +import { foundry } from "viem/chains"; +import { beforeEach, expect, test } from "vitest"; +import ERC1155Bytecode from "../../../../../contracts/out/ERC1155.sol/ERC1155.json"; +import { ALICE, BOB } from "../../_test/constants.js"; +import { publicClient, testClient, walletClient } from "../../_test/utils.js"; +import { erc1155ABI } from "../../generated.js"; +import { getERC1155BalanceOf } from "../publicActions/getERC1155BalanceOf.js"; +import type { ERC1155 } from "../types.js"; +import { createERC1155, createERC1155Data } from "../utils.js"; +import { simulateERC1155TransferBatch } from "./simulateERC1155TransferBatch.js"; + +let id: Hex | undefined = undefined; + +let erc1155: ERC1155; + +beforeEach(async () => { + if (id === undefined) { + const deployHash = await walletClient.deployContract({ + abi: erc1155ABI, + bytecode: ERC1155Bytecode.bytecode.object as Hex, + args: ["https://mitch.com"], + }); + + const { contractAddress } = await publicClient.waitForTransactionReceipt({ + hash: deployHash, + }); + invariant(contractAddress); + erc1155 = createERC1155( + contractAddress, + 0n, + "https://mitch.com", + foundry.id, + ); + + const mintHash = await walletClient.writeContract({ + abi: erc1155ABI, + functionName: "mint", + address: getAddress(contractAddress!), + args: [ALICE, 0n, 10n, "0x"], + }); + await publicClient.waitForTransactionReceipt({ hash: mintHash }); + } else { + await testClient.revert({ id }); + } + + id = await testClient.snapshot(); +}); + +test("can transfer batch", async () => { + await expect( + async () => + await simulateERC1155TransferBatch(publicClient, { + args: { to: BOB, erc1155Data: [] }, + account: ALICE, + }), + ).rejects.toThrowError(); + + await expect( + async () => + await simulateERC1155TransferBatch(publicClient, { + account: ALICE, + args: { + to: BOB, + erc1155Data: [ + createERC1155Data(erc1155, 5n), + createERC1155Data({ ...erc1155, address: zeroAddress }, 5n), + ], + }, + }), + ).rejects.toThrowError(); + + const { request } = await simulateERC1155TransferBatch(publicClient, { + account: ALICE, + args: { + to: BOB, + erc1155Data: [ + createERC1155Data(erc1155, 5n), + createERC1155Data(erc1155, 5n), + ], + }, + }); + const hash = await walletClient.writeContract(request); + await publicClient.waitForTransactionReceipt({ hash }); + + const balanceBOB = await getERC1155BalanceOf(publicClient, { + erc1155, + address: BOB, + }); + expect(balanceBOB.amount).toBe(10n); +}); diff --git a/packages/core/src/erc1155/walletActions/simulateERC1155TransferBatch.ts b/packages/core/src/erc1155/walletActions/simulateERC1155TransferBatch.ts new file mode 100644 index 0000000..ce442a8 --- /dev/null +++ b/packages/core/src/erc1155/walletActions/simulateERC1155TransferBatch.ts @@ -0,0 +1,86 @@ +import { + type Address, + type Chain, + type Client, + type Hex, + type SimulateContractParameters, + type SimulateContractReturnType, + type Transport, + getAddress, +} from "viem"; +import { simulateContract } from "viem/contract"; +import { solmateErc1155ABI as solmateERC1155 } from "../../generated.js"; +import type { ERC1155, ERC1155Data } from "../types.js"; + +export type ERC1155TransferBatchParameters = { + erc1155Data: ERC1155Data[]; + from?: Address; + to: Address; + data?: Hex; +}; + +export type SimulateERC1155TransferBatchParameters< + TChain extends Chain | undefined = Chain, + TChainOverride extends Chain | undefined = Chain | undefined, +> = Omit< + SimulateContractParameters< + typeof solmateERC1155, + "safeBatchTransferFrom", + TChain, + TChainOverride + >, + "args" | "address" | "abi" | "functionName" +> & { args: ERC1155TransferBatchParameters }; + +export type SimulateERC1155TransferBatchReturnType< + TChain extends Chain | undefined, + TChainOverride extends Chain | undefined = undefined, +> = SimulateContractReturnType< + typeof solmateERC1155, + "safeBatchTransferFrom", + TChain, + TChainOverride +>; + +export const simulateERC1155TransferBatch = < + TChain extends Chain | undefined, + TChainOverride extends Chain | undefined, +>( + client: Client, + { + args: { erc1155Data, to, from, data }, + ...request + }: SimulateERC1155TransferBatchParameters, +): Promise> => { + const address = erc1155Data.reduce((addr: Address | undefined, cur) => { + if (addr === undefined) return getAddress(cur.token.address); + else if (addr !== getAddress(cur.token.address)) + throw Error("Tokens refering to different addresses"); + else return addr; + }, undefined); + + if (address === undefined) throw Error("No tokens passed to transfer"); + + return simulateContract(client, { + address, + abi: solmateERC1155, + functionName: "safeBatchTransferFrom", + args: [ + (from ?? + client.account?.address ?? + (typeof request.account === "object" + ? request.account.address + : request.account))!, + to, + erc1155Data.map((t) => t.token.id), + erc1155Data.map((t) => t.amount), + data ?? "0x", + ], + ...request, + } as unknown as SimulateContractParameters< + typeof solmateERC1155, + "safeBatchTransferFrom", + TChain, + TChainOverride + >); +}; diff --git a/packages/core/src/erc1155/writes.test.ts b/packages/core/src/erc1155/writes.test.ts deleted file mode 100644 index 9909d65..0000000 --- a/packages/core/src/erc1155/writes.test.ts +++ /dev/null @@ -1,136 +0,0 @@ -import invariant from "tiny-invariant"; -import { type Hex, getAddress, zeroAddress } from "viem"; -import { foundry } from "viem/chains"; -import { beforeEach, describe, expect, test } from "vitest"; -import ERC1155Bytecode from "../../../../contracts/out/ERC1155.sol/ERC1155.json"; -import { ALICE, BOB } from "../_test/constants.js"; -import { publicClient, testClient, walletClient } from "../_test/utils.js"; -import { erc1155ABI } from "../generated.js"; -import { erc1155BalanceOf, erc1155IsApprovedForAll } from "./reads.js"; -import type { ERC1155 } from "./types.js"; -import { createERC1155, createERC1155Data } from "./utils.js"; -import { - erc1155SetApprovalForAll, - erc1155Transfer, - erc1155TransferBatch, -} from "./writes.js"; - -let id: Hex | undefined = undefined; - -let erc1155: ERC1155; - -beforeEach(async () => { - if (id === undefined) { - const deployHash = await walletClient.deployContract({ - abi: erc1155ABI, - bytecode: ERC1155Bytecode.bytecode.object as Hex, - args: ["https://mitch.com"], - }); - - const { contractAddress } = await publicClient.waitForTransactionReceipt({ - hash: deployHash, - }); - invariant(contractAddress); - erc1155 = createERC1155( - contractAddress, - 0n, - "https://mitch.com", - foundry.id, - ); - - const mintHash = await walletClient.writeContract({ - abi: erc1155ABI, - functionName: "mint", - address: getAddress(contractAddress!), - args: [ALICE, 0n, 10n, "0x"], - }); - await publicClient.waitForTransactionReceipt({ hash: mintHash }); - } else { - await testClient.revert({ id }); - } - - id = await testClient.snapshot(); -}); - -describe("erc1155 writes", async () => { - test("can transfer", async () => { - const { request } = await erc1155Transfer(publicClient, { - to: BOB, - erc1155: createERC1155Data(erc1155, 5n), - account: ALICE, - }); - const hash = await walletClient.writeContract(request); - await publicClient.waitForTransactionReceipt({ hash }); - - const balanceALICE = await erc1155BalanceOf({ - publicClient, - args: { erc1155, address: ALICE }, - }); - expect(balanceALICE.amount).toBe(5n); - - const balanceBOB = await erc1155BalanceOf({ - publicClient, - args: { erc1155, address: BOB }, - }); - expect(balanceBOB.amount).toBe(5n); - }); - - test("can transfer batch", async () => { - await expect( - async () => - await erc1155TransferBatch(publicClient, { - to: BOB, - erc1155: [], - account: ALICE, - }), - ).rejects.toThrowError(); - - await expect( - async () => - await erc1155TransferBatch(publicClient, { - account: ALICE, - to: BOB, - erc1155: [ - createERC1155Data(erc1155, 5n), - createERC1155Data({ ...erc1155, address: zeroAddress }, 5n), - ], - }), - ).rejects.toThrowError(); - - const { request } = await erc1155TransferBatch(publicClient, { - account: ALICE, - to: BOB, - erc1155: [createERC1155Data(erc1155, 5n), createERC1155Data(erc1155, 5n)], - }); - const hash = await walletClient.writeContract(request); - await publicClient.waitForTransactionReceipt({ hash }); - - const balanceBOB = await erc1155BalanceOf({ - publicClient, - args: { erc1155, address: BOB }, - }); - expect(balanceBOB.amount).toBe(10n); - }); - - test("can approve for all", async () => { - const { request } = await erc1155SetApprovalForAll( - publicClient, - - { - account: ALICE, - erc1155, - spender: BOB, - approved: true, - }, - ); - const hash = await walletClient.writeContract(request); - await publicClient.waitForTransactionReceipt({ hash }); - - expect( - await erc1155IsApprovedForAll({ - publicClient, - args: { erc1155, owner: ALICE, spender: BOB }, - }), - ).toBe(true); - }); -}); diff --git a/packages/core/src/erc1155/writes.ts b/packages/core/src/erc1155/writes.ts deleted file mode 100644 index c40982a..0000000 --- a/packages/core/src/erc1155/writes.ts +++ /dev/null @@ -1,111 +0,0 @@ -import { - type Account, - type Address, - type Client, - type Hex, - getAddress, -} from "viem"; -import { simulateContract } from "viem/contract"; -import { solmateErc1155ABI } from "../generated.js"; -import type { ERC1155, ERC1155Data } from "./types.js"; - -export const erc1155SetApprovalForAll = ( - client: Client, - { - erc1155, - spender, - approved, - ...request - }: { - erc1155: Pick; - spender: Address; - approved: boolean; - account?: Account | Address; - }, -) => - simulateContract(client, { - address: erc1155.address, - abi: solmateErc1155ABI, - functionName: "setApprovalForAll", - args: [spender, approved], - ...request, - }); - -export const erc1155Transfer = ( - client: Client, - - { - erc1155, - from, - to, - data, - ...request - }: { - erc1155: ERC1155Data; - from?: Address; - to: Address; - data?: Hex; - account?: Account | Address; - }, -) => - simulateContract(client, { - address: erc1155.token.address, - abi: solmateErc1155ABI, - functionName: "safeTransferFrom", - args: [ - (from ?? - client.account?.address ?? - (typeof request.account === "object" - ? request.account.address - : request.account))!, - to, - erc1155.token.id, - erc1155.amount, - data ?? "0x", - ], - ...request, - }); - -export const erc1155TransferBatch = ( - client: Client, - { - erc1155, - from, - to, - data, - ...request - }: { - erc1155: ERC1155Data[]; - from?: Address; - to: Address; - data?: Hex; - account?: Account | Address; - }, -) => { - const address = erc1155.reduce((addr: Address | undefined, cur) => { - if (addr === undefined) return getAddress(cur.token.address); - else if (addr !== getAddress(cur.token.address)) - throw Error("Tokens refering to different addresses"); - else return addr; - }, undefined); - - if (address === undefined) throw Error("No tokens passed to transfer"); - - return simulateContract(client, { - address, - abi: solmateErc1155ABI, - functionName: "safeBatchTransferFrom", - args: [ - (from ?? - client.account?.address ?? - (typeof request.account === "object" - ? request.account.address - : request.account))!, - to, - erc1155.map((t) => t.token.id), - erc1155.map((t) => t.amount), - data ?? "0x", - ], - ...request, - }); -}; diff --git a/packages/core/src/erc721/index.ts b/packages/core/src/erc721/index.ts index 9056845..551c543 100644 --- a/packages/core/src/erc721/index.ts +++ b/packages/core/src/erc721/index.ts @@ -6,7 +6,7 @@ export type { export { createERC721, createERC721Data, createERC721IDData } from "./utils.js"; -export { solmateErc721ABI as solmateERC721 } from "../generated.js"; +export { solmateErc721ABI as solmateERC721ABI } from "../generated.js"; export { getERC721 } from "./publicActions/getERC721.js"; export { getERC721Approved } from "./publicActions/getERC721Approved.js"; diff --git a/packages/core/src/fraction/types.ts b/packages/core/src/fraction/types.ts index a24d522..ec25154 100644 --- a/packages/core/src/fraction/types.ts +++ b/packages/core/src/fraction/types.ts @@ -2,4 +2,4 @@ export type Fraction = { type: "fraction"; numerator: bigint; denominator: bigint; -}; \ No newline at end of file +}; diff --git a/packages/core/src/fraction/utils.test.ts b/packages/core/src/fraction/utils.test.ts index 3dafd75..355591e 100644 --- a/packages/core/src/fraction/utils.test.ts +++ b/packages/core/src/fraction/utils.test.ts @@ -1,4 +1,5 @@ import { expect, test } from "vitest"; +import type { Fraction } from "./types.js"; import { createFraction, fractionAdd, @@ -12,121 +13,120 @@ import { fractionRemainder, fractionSubtract, } from "./utils.js"; -import type { Fraction } from "./types.js"; const one: Fraction = { type: "fraction", numerator: 1n, denominator: 1n }; const two: Fraction = { type: "fraction", numerator: 2n, denominator: 1n }; - test("create fraction", async () => { - expect(fractionEqualTo(createFraction(2n, 1n), two)).toBe(true); - expect(fractionEqualTo(createFraction(2n), two)).toBe(true); - expect(fractionEqualTo(createFraction("2"), two)).toBe(true); - expect(fractionEqualTo(createFraction(2), two)).toBe(true); - }); - - test("create fraction error", () => { - expect(() => createFraction(1.1)).toThrowError(); - expect(() => createFraction("a")).toThrowError(); - }); - - test("can quotient", () => { - expect(fractionQuotient(two)).toBe(2n); - expect(fractionQuotient(createFraction(5, 3))).toBe(1n); - expect(fractionQuotient(createFraction(1, 2))).toBe(0n); - }); - - test("can remainder", () => { - expect(fractionRemainder(two)).toBe(0n); - expect(fractionRemainder(createFraction(5, 3))).toBe(2n); - expect(fractionRemainder(createFraction(1, 2))).toBe(1n); - }); - - test("can invert", () => { - expect(fractionEqualTo(fractionInvert(one), one)).toBe(true); - expect( - fractionEqualTo(fractionInvert(two), { - type: "fraction", - numerator: 1n, - denominator: 2n, - }), - ).toBe(true); - }); - - test("can add", () => { - expect(fractionEqualTo(fractionAdd(one, one), two)).toBe(true); - expect(fractionEqualTo(fractionAdd(one, createFraction(4n, 4n)), two)).toBe( - true, - ); - expect(fractionEqualTo(fractionAdd(one, 1), two)).toBe(true); - }); - - test("can subtract", () => { - expect(fractionEqualTo(fractionSubtract(two, one), one)).toBe(true); - expect( - fractionEqualTo(fractionSubtract(two, createFraction(4n, 4n)), one), - ).toBe(true); - expect(fractionEqualTo(fractionSubtract(two, 1), one)).toBe(true); - }); - - test("can multiply", () => { - expect(fractionEqualTo(fractionMultiply(one, one), one)).toBe(true); - expect( - fractionEqualTo(fractionMultiply(one, createFraction(4n, 4n)), one), - ).toBe(true); - - expect(fractionEqualTo(fractionMultiply(one, two), two)).toBe(true); - expect(fractionEqualTo(fractionMultiply(two, two), createFraction(4))).toBe( - true, - ); - - expect(fractionEqualTo(fractionMultiply(one, 1), one)).toBe(true); - expect(fractionEqualTo(fractionMultiply(one, 2), two)).toBe(true); - }); - - test("can divide", () => { - expect(fractionEqualTo(fractionDivide(one, one), one)).toBe(true); - expect( - fractionEqualTo(fractionDivide(one, createFraction(4n, 4n)), one), - ).toBe(true); - - expect(fractionEqualTo(fractionDivide(two, one), two)).toBe(true); - expect(fractionEqualTo(fractionDivide(createFraction(4), two), two)).toBe( - true, - ); - - expect(fractionEqualTo(fractionDivide(one, 1), one)).toBe(true); - expect(fractionEqualTo(fractionDivide(two, 1), two)).toBe(true); - }); - - test("can less than", () => { - expect(fractionLessThan(one, two)).toBe(true); - expect(fractionLessThan(createFraction(4n, 4n), two)).toBe(true); - - expect(fractionLessThan(two, one)).toBe(false); - expect(fractionLessThan(two, createFraction(4n, 4n))).toBe(false); - - expect(fractionLessThan(one, 2)).toBe(true); - expect(fractionLessThan(two, 1)).toBe(false); - }); - - test("can equal to", () => { - expect(fractionEqualTo(two, two)).toBe(true); - expect(fractionEqualTo(createFraction(4n, 2n), two)).toBe(true); - - expect(fractionEqualTo(one, 1)).toBe(true); - }); - - test("can greater than", () => { - expect(fractionGreaterThan(two, one)).toBe(true); - expect(fractionGreaterThan(two, createFraction(4n, 4n))).toBe(true); - - expect(fractionGreaterThan(one, two)).toBe(false); - expect(fractionGreaterThan(createFraction(4n, 4n), two)).toBe(false); - - expect(fractionGreaterThan(two, 1)).toBe(true); - expect(fractionGreaterThan(one, 2)).toBe(false); - }); - - test.todo("can print fixed"); - - test.todo("can print significant"); +test("create fraction", async () => { + expect(fractionEqualTo(createFraction(2n, 1n), two)).toBe(true); + expect(fractionEqualTo(createFraction(2n), two)).toBe(true); + expect(fractionEqualTo(createFraction("2"), two)).toBe(true); + expect(fractionEqualTo(createFraction(2), two)).toBe(true); +}); + +test("create fraction error", () => { + expect(() => createFraction(1.1)).toThrowError(); + expect(() => createFraction("a")).toThrowError(); +}); + +test("can quotient", () => { + expect(fractionQuotient(two)).toBe(2n); + expect(fractionQuotient(createFraction(5, 3))).toBe(1n); + expect(fractionQuotient(createFraction(1, 2))).toBe(0n); +}); + +test("can remainder", () => { + expect(fractionRemainder(two)).toBe(0n); + expect(fractionRemainder(createFraction(5, 3))).toBe(2n); + expect(fractionRemainder(createFraction(1, 2))).toBe(1n); +}); + +test("can invert", () => { + expect(fractionEqualTo(fractionInvert(one), one)).toBe(true); + expect( + fractionEqualTo(fractionInvert(two), { + type: "fraction", + numerator: 1n, + denominator: 2n, + }), + ).toBe(true); +}); + +test("can add", () => { + expect(fractionEqualTo(fractionAdd(one, one), two)).toBe(true); + expect(fractionEqualTo(fractionAdd(one, createFraction(4n, 4n)), two)).toBe( + true, + ); + expect(fractionEqualTo(fractionAdd(one, 1), two)).toBe(true); +}); + +test("can subtract", () => { + expect(fractionEqualTo(fractionSubtract(two, one), one)).toBe(true); + expect( + fractionEqualTo(fractionSubtract(two, createFraction(4n, 4n)), one), + ).toBe(true); + expect(fractionEqualTo(fractionSubtract(two, 1), one)).toBe(true); +}); + +test("can multiply", () => { + expect(fractionEqualTo(fractionMultiply(one, one), one)).toBe(true); + expect( + fractionEqualTo(fractionMultiply(one, createFraction(4n, 4n)), one), + ).toBe(true); + + expect(fractionEqualTo(fractionMultiply(one, two), two)).toBe(true); + expect(fractionEqualTo(fractionMultiply(two, two), createFraction(4))).toBe( + true, + ); + + expect(fractionEqualTo(fractionMultiply(one, 1), one)).toBe(true); + expect(fractionEqualTo(fractionMultiply(one, 2), two)).toBe(true); +}); + +test("can divide", () => { + expect(fractionEqualTo(fractionDivide(one, one), one)).toBe(true); + expect( + fractionEqualTo(fractionDivide(one, createFraction(4n, 4n)), one), + ).toBe(true); + + expect(fractionEqualTo(fractionDivide(two, one), two)).toBe(true); + expect(fractionEqualTo(fractionDivide(createFraction(4), two), two)).toBe( + true, + ); + + expect(fractionEqualTo(fractionDivide(one, 1), one)).toBe(true); + expect(fractionEqualTo(fractionDivide(two, 1), two)).toBe(true); +}); + +test("can less than", () => { + expect(fractionLessThan(one, two)).toBe(true); + expect(fractionLessThan(createFraction(4n, 4n), two)).toBe(true); + + expect(fractionLessThan(two, one)).toBe(false); + expect(fractionLessThan(two, createFraction(4n, 4n))).toBe(false); + + expect(fractionLessThan(one, 2)).toBe(true); + expect(fractionLessThan(two, 1)).toBe(false); +}); + +test("can equal to", () => { + expect(fractionEqualTo(two, two)).toBe(true); + expect(fractionEqualTo(createFraction(4n, 2n), two)).toBe(true); + + expect(fractionEqualTo(one, 1)).toBe(true); +}); + +test("can greater than", () => { + expect(fractionGreaterThan(two, one)).toBe(true); + expect(fractionGreaterThan(two, createFraction(4n, 4n))).toBe(true); + + expect(fractionGreaterThan(one, two)).toBe(false); + expect(fractionGreaterThan(createFraction(4n, 4n), two)).toBe(false); + + expect(fractionGreaterThan(two, 1)).toBe(true); + expect(fractionGreaterThan(one, 2)).toBe(false); +}); + +test.todo("can print fixed"); + +test.todo("can print significant"); diff --git a/packages/core/src/fraction/utils.ts b/packages/core/src/fraction/utils.ts index 91fad95..828d87a 100644 --- a/packages/core/src/fraction/utils.ts +++ b/packages/core/src/fraction/utils.ts @@ -1,6 +1,6 @@ import invariant from "tiny-invariant"; -import type { Fraction } from "./types.js"; import type { BigIntIsh } from "../types/bigintish.js"; +import type { Fraction } from "./types.js"; /** * Returns true if {@link x } is of type {@link Fraction} diff --git a/packages/core/src/index.ts b/packages/core/src/index.ts index 7d14d44..a5e5407 100644 --- a/packages/core/src/index.ts +++ b/packages/core/src/index.ts @@ -1,213 +1,169 @@ -// // ERC20 - -// export { -// erc20BalanceOf, -// erc20Allowance, -// erc20TotalSupply, -// erc20Name, -// erc20Symbol, -// erc20Decimals, -// erc20PermitNonce, -// erc20PermitData, -// erc20PermitDomainSeparator, -// getERC20, -// getERC20Permit, -// erc20IsPermit, -// } from "./erc20/reads.js"; - -// export { -// createERC20, -// createERC20Permit, -// createERC20PermitDataFromString, -// createERC20PermitDataFromRaw, -// createERC20PermitDataFromFraction, -// PermitType, -// erc20PermitTypedDataHash, -// } from "./erc20/utils.js"; - -// export { -// erc20Transfer, -// erc20Approve, -// erc20TransferFrom, -// erc20Permit, -// erc20SignPermit, -// } from "./erc20/writes.js"; - -// // ERC721 - -// export { -// erc721Name, -// erc721Symbol, -// erc721TokenURI, -// erc721GetApproved, -// erc721IsApprovedForAll, -// erc721OwnerOf, -// erc721BalanceOf, -// erc721SupportsInterface, -// getERC721, -// erc721Data, -// erc721IDData, -// } from "./erc721/reads.js"; - -// export { -// createERC721, -// createERC721Data, -// createERC721IDData, -// } from "./erc721/utils.js"; - -// export { -// erc721Transfer, -// erc721Approve, -// erc721SetApprovalForAll, -// } from "./erc721/writes.js"; - -// // ERC1155 - -// export { -// erc1155IsApprovedForAll, -// erc1155URI, -// erc1155BalanceOf, -// getERC1155, -// } from "./erc1155/reads.js"; - -// export { createERC1155, createERC1155Data } from "./erc1155/utils.js"; - -// export { -// erc1155SetApprovalForAll, -// erc1155Transfer, -// erc1155TransferBatch, -// } from "./erc1155/writes.js"; - -// // NATIVE - -// export { nativeBalance } from "./native/reads.js"; - -// export { createNativeCurrency } from "./native/utils.js"; - -// // WETH - -// export { createWETH } from "./weth/utils.js"; - -// export { wethDeposit, wethWithdraw } from "./weth/writes.js"; - -// // UTILS - -// export { createReverseMirage, getQueryKey } from "./readUtils.js"; - -// // AMOUNT - -// export { -// type Amount, -// isAmount, -// createAmountFromString, -// createAmountFromFraction, -// createAmountFromRaw, -// amountAdd, -// amountSubtract, -// amountMultiply, -// amountDivide, -// amountLessThan, -// amountEqualTo, -// amountGreaterThan, -// amountToNumber, -// } from "./amount.js"; - -// // FRACTION - -// export { -// isFraction, -// createFraction, -// fractionQuotient, -// fractionRemainder, -// fractionInvert, -// fractionAdd, -// fractionSubtract, -// fractionMultiply, -// fractionDivide, -// fractionLessThan, -// fractionEqualTo, -// fractionGreaterThan, -// fractionToNumber, -// } from "./fractionUtils.js"; - -// // PRICE - -// export { -// isPrice, -// createPriceFromFraction, -// createPriceFromAmounts, -// createPrice, -// priceInvert, -// priceAdd, -// priceSubtract, -// priceMultiply, -// priceDivide, -// priceLessThan, -// priceEqualTo, -// priceGreaterThan, -// priceQuote, -// rawPrice, -// adjustedPrice, -// priceToNumber, -// } from "./priceUtils.js"; - -// // ABI - -// export { -// solmateErc20ABI as erc20ABI, -// solmateErc721ABI as erc721ABI, -// solmateErc1155ABI as erc1155ABI, -// weth9ABI, -// } from "./generated.js"; - -// // TYPES - -// export type { -// BaseERC20, -// ERC20, -// ERC20Permit, -// ERC20Data, -// ERC20Amount, -// ERC20PermitData, -// } from "./erc20/types.js"; - -// export type { ERC721, ERC721IDData, ERC721Data } from "./erc721/types.js"; - -// export type { ERC1155, ERC1155Data } from "./erc1155/types.js"; - -// export type { -// NativeCurrency, -// NativeCurrencyAmount, -// NativeCurrencyData, -// } from "./native/types.js"; - -// export type { WETH } from "./weth/types.js"; - -// export type { -// BigIntIsh, -// Fraction, -// Token, -// TokenData, -// Price, -// ReverseMirage, -// ReverseMirageRead, -// Tuple, -// } from "./types.js"; - -// // CONSTANTS - -// export { -// type ChainTokens, -// mainnetTokens, -// sepoliaTokens, -// goerliTokens, -// optimismTokens, -// optimismGoerliTokens, -// arbitrumTokens, -// arbitrumGoerliTokens, -// baseTokens, -// baseGoerliTokens, -// celoTokens, -// celoAlfajoresTokens, -// foundryTokens, -// } from "./constants.js"; +export { + type Amount, + isAmount, + createAmountFromString, + createAmountFromFraction, + createAmountFromRaw, + amountAdd, + amountSubtract, + amountMultiply, + amountDivide, + amountLessThan, + amountEqualTo, + amountGreaterThan, + amountToNumber, +} from "./amount/index.js"; + +export { + type ChainTokens, + arbitrumTokens, + arbitrumGoerliTokens, + baseTokens, + baseGoerliTokens, + celoTokens, + celoAlfajoresTokens, + foundryTokens, + goerliTokens, + mainnetTokens, + optimismTokens, + optimismGoerliTokens, + sepoliaTokens, +} from "./chains/index.js"; + +export { + type BaseERC20, + type ERC20, + type ERC20Permit, + type ERC20Data, + type ERC20Amount, + type ERC20PermitData, + createERC20, + createERC20Permit, + createERC20PermitDataFromFraction, + createERC20PermitDataFromRaw, + createERC20PermitDataFromString, + PermitType, + solmateERC20ABI, + getERC20, + getERC20Allowance, + getERC20BalanceOf, + getERC20Decimals, + getERC20DomainSeparator, + getERC20Name, + getERC20Permit, + getERC20PermitData, + getERC20PermitNonce, + getERC20Symbol, + getERC20TotalSupply, + getIsERC20Permit, + signERC20Permit, + simulateERC20Approve, + simulateERC20Permit, + simulateERC20Transfer, + simulateERC20TransferFrom, +} from "./erc20/index.js"; + +export { + type ERC721, + type ERC721IDData, + type ERC721Data, + createERC721, + createERC721Data, + createERC721IDData, + solmateERC721ABI, + getERC721, + getERC721Approved, + getERC721BalanceOf, + getERC721Data, + getERC721IDData, + getERC721IsApprovedForAll, + getERC721Name, + getERC721Symbol, + getERC721OwnerOf, + getERC721SupportsInterface, + getERC721TokenURI, + simulateERC721Transfer, + simulateERC721Approve, + simulateERC721SetApprovalForAll, +} from "./erc721/index.js"; + +export { + type ERC1155, + type ERC1155Data, + createERC1155, + createERC1155Data, + solmateERC1155ABI, + getERC1155, + getERC1155BalanceOf, + getERC1155IsApprovedForAll, + getERC1155URI, + simulateERC1155Transfer, + simulateERC1155TransferBatch, + simulateERC1155SetApprovalForAll, +} from "./erc1155/index.js"; + +export { + type Fraction, + isFraction, + createFraction, + fractionQuotient, + fractionRemainder, + fractionInvert, + fractionAdd, + fractionSubtract, + fractionMultiply, + fractionDivide, + fractionLessThan, + fractionEqualTo, + fractionGreaterThan, + fractionToNumber, +} from "./fraction/index.js"; + +export { + type NativeCurrency, + type NativeCurrencyAmount, + type NativeCurrencyData, + createNativeCurrency, + getNativeBalance, + type GetNativeBalanceParameters, + type GetNativeBalanceReturnType, +} from "./native/index.js"; + +export { + type Price, + isPrice, + createPriceFromFraction, + createPriceFromAmounts, + createPrice, + priceInvert, + priceAdd, + priceSubtract, + priceMultiply, + priceDivide, + priceLessThan, + priceEqualTo, + priceGreaterThan, + priceQuote, + rawPrice, + adjustedPrice, + priceToNumber, +} from "./price/index.js"; + +export type { + BigIntIsh, + ReverseMirage, + ReverseMirageRead, + Token, + TokenData, + Tuple, +} from "./types/index.js"; + +export { getQueryKey } from "./utils/index.js"; + +export { + type WETH, + createWETH, + weth9ABI, + simulateWETHDeposit, + simulateWETHWithdraw, +} from "./weth/index.js"; diff --git a/packages/core/src/price/utils.test.ts b/packages/core/src/price/utils.test.ts index 253a709..bdc493b 100644 --- a/packages/core/src/price/utils.test.ts +++ b/packages/core/src/price/utils.test.ts @@ -1,5 +1,11 @@ import { describe, expect, test } from "vitest"; import { mockToken } from "../_test/constants.js"; +import { + amountEqualTo, + createAmountFromRaw, + createAmountFromString, +} from "../amount/utils.js"; +import { createFraction, fractionEqualTo } from "../fraction/utils.js"; import { adjustedPrice, createPrice, @@ -17,8 +23,6 @@ import { priceToNumber, rawPrice, } from "./utils.js"; -import { amountEqualTo, createAmountFromRaw, createAmountFromString } from "../amount/utils.js"; -import { createFraction, fractionEqualTo } from "../fraction/utils.js"; const one = { type: "price", diff --git a/packages/core/src/price/utils.ts b/packages/core/src/price/utils.ts index af28de9..a505732 100644 --- a/packages/core/src/price/utils.ts +++ b/packages/core/src/price/utils.ts @@ -1,5 +1,7 @@ import invariant from "tiny-invariant"; import type { Amount } from "../amount/types.js"; +import { createAmountFromRaw, scaleUp } from "../amount/utils.js"; +import type { Fraction } from "../fraction/types.js"; import { fractionAdd, fractionDivide, @@ -12,9 +14,7 @@ import { fractionToNumber, } from "../fraction/utils.js"; import type { BigIntIsh } from "../types/bigintish.js"; -import type { Fraction } from "../fraction/types.js"; import type { Price } from "./types.js"; -import { createAmountFromRaw, scaleUp } from "../amount/utils.js"; /** * Returns true if {@link x} is of type {@link Price} diff --git a/packages/core/src/utils/getQueryKey.ts b/packages/core/src/utils/getQueryKey.ts index de79dd8..4f610a0 100644 --- a/packages/core/src/utils/getQueryKey.ts +++ b/packages/core/src/utils/getQueryKey.ts @@ -6,8 +6,13 @@ import type { ReverseMirageRead } from "../types/rm.js"; * @see https://tanstack.com/query/v4/docs/react/guides/query-keys */ export const getQueryKey = ( - // biome-ignore lint/suspicious/noExplicitAny: dont need - get: (a: { args: TArgs }) => ReverseMirageRead, + get: ( + // biome-ignore lint/suspicious/noExplicitAny: dont need + client: any, + args: TArgs, + type?: "select" | undefined, + // biome-ignore lint/suspicious/noExplicitAny: dont need + ) => ReverseMirageRead, args: TArgs, chainID: number, ) => {