Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

refactor erc721 abi, remove id field #53

Merged
merged 1 commit into from
Sep 22, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 1 addition & 3 deletions packages/core/src/erc721/index.ts
Original file line number Diff line number Diff line change
@@ -1,18 +1,16 @@
export type {
ERC721,
ERC721IDData,
ERC721Data,
} from "./types.js";

export { createERC721, createERC721Data, createERC721IDData } from "./utils.js";
export { createERC721, createERC721Data } from "./utils.js";

export { solmateErc721ABI as solmateERC721ABI } from "../generated.js";

export { getERC721 } from "./publicActions/getERC721.js";
export { getERC721Approved } from "./publicActions/getERC721Approved.js";
export { getERC721BalanceOf } from "./publicActions/getERC721BalanceOf.js";
export { getERC721Data } from "./publicActions/getERC721Data.js";
export { getERC721IDData } from "./publicActions/getERC721IDData.js";
export { getERC721IsApprovedForAll } from "./publicActions/getERC721IsApprovedForAll.js";
export { getERC721Name } from "./publicActions/getERC721Name.js";
export { getERC721Symbol } from "./publicActions/getERC721Symbol.js";
Expand Down
9 changes: 1 addition & 8 deletions packages/core/src/erc721/publicActions/getERC721.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,14 +27,7 @@ beforeAll(async () => {
hash: deployHash,
});
invariant(contractAddress);
erc721 = createERC721(
contractAddress,
"name",
"symbol",
0n,
"mitch.com",
foundry.id,
);
erc721 = createERC721(contractAddress, "name", "symbol", foundry.id);
} else {
await testClient.revert({ id });
}
Expand Down
17 changes: 5 additions & 12 deletions packages/core/src/erc721/publicActions/getERC721.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,12 @@ import type { ERC721 } from "../types.js";
import { createERC721 } from "../utils.js";
import { getERC721Name } from "./getERC721Name.js";
import { getERC721Symbol } from "./getERC721Symbol.js";
import { getERC721TokenURI } from "./getERC721TokenURI.js";

export type GetERC721Parameters = Omit<
ReadContractParameters<typeof solmateERC721ABI, "name">,
"address" | "abi" | "functionName" | "args"
> & {
erc721: Pick<ERC721, "address" | "id" | "chainID"> &
erc721: Pick<ERC721, "address" | "chainID"> &
Partial<Pick<ERC721, "blockCreated">>;
};

Expand All @@ -24,19 +23,16 @@ export const getERC721 = <
client: Client<Transport, TChain>,
args: GetERC721Parameters,
type?: T,
): ReverseMirage<[string, string, string], GetERC721ReturnType, T> =>
): ReverseMirage<[string, string], GetERC721ReturnType, T> =>
(type === undefined
? Promise.all([
getERC721Name(client, args),
getERC721Symbol(client, args),
getERC721TokenURI(client, args),
]).then(([name, symbol, tokenURI]) =>
]).then(([name, symbol]) =>
createERC721(
args.erc721.address,
name,
symbol,
args.erc721.id,
tokenURI,
args.erc721.chainID,
args.blockNumber,
),
Expand All @@ -46,16 +42,13 @@ export const getERC721 = <
Promise.all([
getERC721Name(client, args, "select").read(),
getERC721Symbol(client, args, "select").read(),
getERC721TokenURI(client, args, "select").read(),
]),
parse: ([name, symbol, tokenURI]) =>
parse: ([name, symbol]) =>
createERC721(
args.erc721.address,
name,
symbol,
args.erc721.id,
tokenURI,
args.erc721.chainID,
args.blockNumber,
),
}) as ReverseMirage<[string, string, string], GetERC721ReturnType, T>;
}) as ReverseMirage<[string, string], GetERC721ReturnType, T>;
11 changes: 3 additions & 8 deletions packages/core/src/erc721/publicActions/getERC721Approved.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,14 +27,7 @@ beforeAll(async () => {
hash: deployHash,
});
invariant(contractAddress);
erc721 = createERC721(
contractAddress,
"name",
"symbol",
0n,
"mitch.com",
foundry.id,
);
erc721 = createERC721(contractAddress, "name", "symbol", foundry.id);

const mintHash = await walletClient.writeContract({
abi: erc721ABI,
Expand All @@ -60,6 +53,7 @@ beforeAll(async () => {
test("read approved", async () => {
const owner = await getERC721Approved(publicClient, {
erc721,
id: 0n,
});
expect(owner).toBe(BOB);
});
Expand All @@ -69,6 +63,7 @@ test("read approved select", async () => {
publicClient,
{
erc721,
id: 0n,
},
"select",
);
Expand Down
6 changes: 3 additions & 3 deletions packages/core/src/erc721/publicActions/getERC721Approved.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ import type { ERC721 } from "../types.js";
export type GetERC721ApprovedParameters = Omit<
ReadContractParameters<typeof solmateERC721ABI, "getApproved">,
"address" | "abi" | "functionName" | "args"
> & { erc721: Pick<ERC721, "address" | "id"> };
> & { erc721: Pick<ERC721, "address">; id: bigint };

export type GetERC721ApprovedReturnType = Address;

Expand All @@ -30,15 +30,15 @@ export const getERC721Approved = <
abi: solmateERC721ABI,
address: args.erc721.address,
functionName: "getApproved",
args: [args.erc721.id],
args: [args.id],
})
: {
read: () =>
readContract(client, {
abi: solmateERC721ABI,
address: args.erc721.address,
functionName: "getApproved",
args: [args.erc721.id],
args: [args.id],
}),
parse: (data) => data,
}) as ReverseMirage<Address, GetERC721ApprovedReturnType, T>;
Original file line number Diff line number Diff line change
Expand Up @@ -27,14 +27,7 @@ beforeAll(async () => {
hash: deployHash,
});
invariant(contractAddress);
erc721 = createERC721(
contractAddress,
"name",
"symbol",
0n,
"mitch.com",
foundry.id,
);
erc721 = createERC721(contractAddress, "name", "symbol", foundry.id);

const mintHash = await walletClient.writeContract({
abi: erc721ABI,
Expand Down
9 changes: 1 addition & 8 deletions packages/core/src/erc721/publicActions/getERC721Data.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,14 +27,7 @@ beforeAll(async () => {
hash: deployHash,
});
invariant(contractAddress);
erc721 = createERC721(
contractAddress,
"name",
"symbol",
0n,
"mitch.com",
foundry.id,
);
erc721 = createERC721(contractAddress, "name", "symbol", foundry.id);

const mintHash = await walletClient.writeContract({
abi: erc721ABI,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,14 +20,7 @@ test("erc721 max balance", async () => {
hash: deployHash,
});
invariant(contractAddress);
const erc721 = createERC721(
contractAddress,
"name",
"symbol",
0n,
"https://mitch.com",
foundry.id,
);
const erc721 = createERC721(contractAddress, "name", "symbol", foundry.id);
await expect(() =>
getERC721Data(publicClient, { erc721, address: ALICE }),
).rejects.toThrowError();
Expand Down
71 changes: 0 additions & 71 deletions packages/core/src/erc721/publicActions/getERC721IDData.test.ts

This file was deleted.

46 changes: 0 additions & 46 deletions packages/core/src/erc721/publicActions/getERC721IDData.ts

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -27,14 +27,7 @@ beforeAll(async () => {
hash: deployHash,
});
invariant(contractAddress);
erc721 = createERC721(
contractAddress,
"name",
"symbol",
0n,
"mitch.com",
foundry.id,
);
erc721 = createERC721(contractAddress, "name", "symbol", foundry.id);

const approvedHash = await walletClient.writeContract({
abi: erc721ABI,
Expand Down
9 changes: 1 addition & 8 deletions packages/core/src/erc721/publicActions/getERC721Name.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,14 +27,7 @@ beforeAll(async () => {
hash: deployHash,
});
invariant(contractAddress);
erc721 = createERC721(
contractAddress,
"name",
"symbol",
0n,
"mitch.com",
foundry.id,
);
erc721 = createERC721(contractAddress, "name", "symbol", foundry.id);
} else {
await testClient.revert({ id });
}
Expand Down
11 changes: 3 additions & 8 deletions packages/core/src/erc721/publicActions/getERC721OwnerOf.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,14 +27,7 @@ beforeAll(async () => {
hash: deployHash,
});
invariant(contractAddress);
erc721 = createERC721(
contractAddress,
"name",
"symbol",
0n,
"mitch.com",
foundry.id,
);
erc721 = createERC721(contractAddress, "name", "symbol", foundry.id);

const mintHash = await walletClient.writeContract({
abi: erc721ABI,
Expand All @@ -52,6 +45,7 @@ beforeAll(async () => {
test("read owner", async () => {
const owner = await getERC721OwnerOf(publicClient, {
erc721,
id: 0n,
});
expect(owner).toBe(ALICE);
});
Expand All @@ -61,6 +55,7 @@ test("read owner select", async () => {
publicClient,
{
erc721,
id: 0n,
},
"select",
);
Expand Down
Loading