-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
33 changed files
with
1,322 additions
and
818 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1,2 @@ | ||
node_modules | ||
node_modules | ||
.vitepress/.* |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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"; |
43 changes: 43 additions & 0 deletions
43
packages/core/src/erc1155/publicActions/getERC1155.test.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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<typeof solmateERC1155ABI, "uri">, | ||
"address" | "abi" | "functionName" | "args" | ||
> & { | ||
erc1155: Pick<ERC1155, "address" | "id" | "chainID"> & | ||
Partial<Pick<ERC1155, "blockCreated">>; | ||
}; | ||
|
||
export type GetERC1155ReturnType = ERC1155; | ||
|
||
export const getERC1155 = < | ||
TChain extends Chain | undefined, | ||
T extends "select" | undefined, | ||
>( | ||
client: Client<Transport, TChain>, | ||
args: GetERC1155Parameters, | ||
type?: T, | ||
): ReverseMirage<string, GetERC1155ReturnType, T> => | ||
(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<string, GetERC1155ReturnType, T>; |
Oops, something went wrong.