Skip to content

Commit

Permalink
Merge pull request #55 from kyscott18/base
Browse files Browse the repository at this point in the history
Base types for erc721 and erc1155
  • Loading branch information
kyscott18 authored Sep 22, 2023
2 parents be2f35f + 0f4896b commit a8d3004
Show file tree
Hide file tree
Showing 29 changed files with 67 additions and 67 deletions.
8 changes: 0 additions & 8 deletions docs/.vitepress/config.mts
Original file line number Diff line number Diff line change
Expand Up @@ -196,10 +196,6 @@ export default defineConfig({
text: "createERC721Data",
link: "",
},
{
text: "createERC721DataID",
link: "",
},
],
},
{
Expand Down Expand Up @@ -245,10 +241,6 @@ export default defineConfig({
text: "getERC721Data",
link: "",
},
{
text: "getERC721DataID",
link: "",
},
],
},
{
Expand Down
1 change: 1 addition & 0 deletions packages/core/src/erc1155/index.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
export type {
BaseERC1155,
ERC1155,
ERC1155Data,
} from "./types.js";
Expand Down
8 changes: 4 additions & 4 deletions packages/core/src/erc1155/publicActions/getERC1155.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,18 +2,18 @@ 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 type { BaseERC1155 } 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">>;
erc1155: Pick<BaseERC1155, "address" | "id" | "chainID"> &
Partial<Pick<BaseERC1155, "blockCreated">>;
};

export type GetERC1155ReturnType = ERC1155;
export type GetERC1155ReturnType = BaseERC1155;

export const getERC1155 = <
TChain extends Chain | undefined,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,20 +8,20 @@ import type {
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 type { BaseERC1155, ERC1155Data } from "../types.js";
import { createERC1155Data } from "../utils.js";

export type GetERC1155BalanceOfParameters<TERC1155 extends ERC1155> = Omit<
export type GetERC1155BalanceOfParameters<TERC1155 extends BaseERC1155> = Omit<
ReadContractParameters<typeof solmateERC1155ABI, "balanceOf">,
"address" | "abi" | "functionName" | "args"
> & { erc1155: TERC1155; address: Address };

export type GetERC1155BalanceOfReturnType<TERC1155 extends ERC1155> =
export type GetERC1155BalanceOfReturnType<TERC1155 extends BaseERC1155> =
ERC1155Data<TERC1155>;

export const getERC1155BalanceOf = <
TChain extends Chain | undefined,
TERC1155 extends ERC1155,
TERC1155 extends BaseERC1155,
T extends "select" | undefined,
>(
client: Client<Transport, TChain>,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,12 +8,12 @@ import type {
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 type { BaseERC1155 } from "../types.js";

export type GetERC1155IsApprovedForAllParameters = Omit<
ReadContractParameters<typeof solmateERC1155ABI, "isApprovedForAll">,
"address" | "abi" | "functionName" | "args"
> & { erc1155: Pick<ERC1155, "address">; owner: Address; spender: Address };
> & { erc1155: Pick<BaseERC1155, "address">; owner: Address; spender: Address };

export type GetERC1155IsApprovedForAllReturnType = boolean;

Expand Down
4 changes: 2 additions & 2 deletions packages/core/src/erc1155/publicActions/getERC1155URI.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,12 @@ 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 type { BaseERC1155 } from "../types.js";

export type GetERC1155URIParameters = Omit<
ReadContractParameters<typeof solmateERC1155ABI, "uri">,
"address" | "abi" | "functionName" | "args"
> & { erc1155: Pick<ERC1155, "address" | "id"> };
> & { erc1155: Pick<BaseERC1155, "address" | "id"> };

export type GetERC1155URIReturnType = string;

Expand Down
6 changes: 4 additions & 2 deletions packages/core/src/erc1155/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,16 @@ import type { Address } from "viem";
import type { Amount } from "../amount/types.js";
import type { Token } from "../types/token.js";

export type ERC1155 = Token<"erc1155"> & {
export type BaseERC1155<TType extends string = string> = Token<TType> & {
address: Address;
id: bigint;
uri: string;
blockCreated: bigint;
};

export type ERC1155Data<TERC1155 extends ERC1155> = Amount<
export type ERC1155 = BaseERC1155<"erc1155">;

export type ERC1155Data<TERC1155 extends BaseERC1155> = Amount<
TERC1155,
`${TERC1155["type"]}Data`
>;
4 changes: 2 additions & 2 deletions packages/core/src/erc1155/utils.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { type Address, getAddress } from "viem";
import type { ERC1155, ERC1155Data } from "./types.js";
import type { BaseERC1155, ERC1155, ERC1155Data } from "./types.js";

/**
* Creates an {@link ERC1155}
Expand All @@ -22,7 +22,7 @@ export const createERC1155 = (
/**
* Creates an {@link ERC1155Data}
*/
export const createERC1155Data = <TERC1155 extends ERC1155>(
export const createERC1155Data = <TERC1155 extends BaseERC1155>(
erc1155: TERC1155,
amount: bigint,
): ERC1155Data<TERC1155> => ({
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,10 @@ import type {
} from "viem";
import { simulateContract } from "viem/contract";
import { solmateErc1155ABI as solmateERC1155 } from "../../generated.js";
import type { ERC1155 } from "../types.js";
import type { BaseERC1155 } from "../types.js";

export type ERC1155SetApprovalForAllParameters = {
erc1155: Pick<ERC1155, "address">;
erc1155: Pick<BaseERC1155, "address">;
spender: Address;
approved: boolean;
};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,10 @@ import type {
} from "viem";
import { simulateContract } from "viem/contract";
import { solmateErc1155ABI as solmateERC1155 } from "../../generated.js";
import type { ERC1155, ERC1155Data } from "../types.js";
import type { BaseERC1155, ERC1155Data } from "../types.js";

export type ERC1155TransferParameters = {
erc1155Data: ERC1155Data<ERC1155>;
erc1155Data: ERC1155Data<BaseERC1155>;
from?: Address;
to: Address;
data?: Hex;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,10 @@ import {
} from "viem";
import { simulateContract } from "viem/contract";
import { solmateErc1155ABI as solmateERC1155 } from "../../generated.js";
import type { ERC1155, ERC1155Data } from "../types.js";
import type { BaseERC1155, ERC1155Data } from "../types.js";

export type ERC1155TransferBatchParameters = {
erc1155Data: ERC1155Data<ERC1155>[];
erc1155Data: ERC1155Data<BaseERC1155>[];
from?: Address;
to: Address;
data?: Hex;
Expand Down
6 changes: 3 additions & 3 deletions packages/core/src/erc20/publicActions/getERC20.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import type { ReverseMirage } from "../../types/rm.js";
import type { BaseERC20, ERC20 } from "../types.js";
import { createERC20 } from "../utils.js";
import { getERC20Decimals } from "./getERC20Decimals.js";
import { type GetERC20NameReturnType, getERC20Name } from "./getERC20Name.js";
import { getERC20Name } from "./getERC20Name.js";
import { getERC20Symbol } from "./getERC20Symbol.js";

export type GetERC20Parameters = Omit<
Expand All @@ -24,7 +24,7 @@ export const getERC20 = <
client: Client<Transport, TChain>,
{ erc20, ...request }: GetERC20Parameters,
type?: T,
): ReverseMirage<[string, string, number], GetERC20NameReturnType, T> =>
): ReverseMirage<[string, string, number], GetERC20ReturnType, T> =>
(type === undefined
? Promise.all([
getERC20Name(client, { erc20, ...request }),
Expand Down Expand Up @@ -56,4 +56,4 @@ export const getERC20 = <
erc20.chainID,
erc20.blockCreated,
),
}) as ReverseMirage<[string, string, number], GetERC20NameReturnType, T>;
}) as ReverseMirage<[string, string, number], GetERC20ReturnType, T>;
1 change: 1 addition & 0 deletions packages/core/src/erc721/index.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
export type {
BaseERC721,
ERC721,
ERC721Data,
} from "./types.js";
Expand Down
8 changes: 4 additions & 4 deletions packages/core/src/erc721/publicActions/getERC721.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import type { Chain, Client, ReadContractParameters, Transport } from "viem";
import { solmateErc721ABI as solmateERC721ABI } from "../../generated.js";
import type { ReverseMirage } from "../../types/rm.js";
import type { ERC721 } from "../types.js";
import type { BaseERC721 } from "../types.js";
import { createERC721 } from "../utils.js";
import { getERC721Name } from "./getERC721Name.js";
import { getERC721Symbol } from "./getERC721Symbol.js";
Expand All @@ -10,11 +10,11 @@ export type GetERC721Parameters = Omit<
ReadContractParameters<typeof solmateERC721ABI, "name">,
"address" | "abi" | "functionName" | "args"
> & {
erc721: Pick<ERC721, "address" | "chainID"> &
Partial<Pick<ERC721, "blockCreated">>;
erc721: Pick<BaseERC721, "address" | "chainID"> &
Partial<Pick<BaseERC721, "blockCreated">>;
};

export type GetERC721ReturnType = ERC721;
export type GetERC721ReturnType = BaseERC721;

export const getERC721 = <
TChain extends Chain | undefined,
Expand Down
4 changes: 2 additions & 2 deletions packages/core/src/erc721/publicActions/getERC721Approved.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,12 +8,12 @@ import type {
import { readContract } from "viem/contract";
import { solmateErc721ABI as solmateERC721ABI } from "../../generated.js";
import type { ReverseMirage } from "../../types/rm.js";
import type { ERC721 } from "../types.js";
import type { BaseERC721 } from "../types.js";

export type GetERC721ApprovedParameters = Omit<
ReadContractParameters<typeof solmateERC721ABI, "getApproved">,
"address" | "abi" | "functionName" | "args"
> & { erc721: Pick<ERC721, "address">; id: bigint };
> & { erc721: Pick<BaseERC721, "address">; id: bigint };

export type GetERC721ApprovedReturnType = Address;

Expand Down
4 changes: 2 additions & 2 deletions packages/core/src/erc721/publicActions/getERC721BalanceOf.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,12 +8,12 @@ import type {
import { readContract } from "viem/contract";
import { solmateErc721ABI as solmateERC721ABI } from "../../generated.js";
import type { ReverseMirage } from "../../types/rm.js";
import type { ERC721 } from "../types.js";
import type { BaseERC721 } from "../types.js";

export type GetERC721BalanceOfParameters = Omit<
ReadContractParameters<typeof solmateERC721ABI, "balanceOf">,
"address" | "abi" | "functionName" | "args"
> & { erc721: Pick<ERC721, "address">; address: Address };
> & { erc721: Pick<BaseERC721, "address">; address: Address };

export type GetERC721BalanceOfReturnType = bigint;

Expand Down
8 changes: 4 additions & 4 deletions packages/core/src/erc721/publicActions/getERC721Data.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,21 +7,21 @@ import type {
} from "viem";
import { solmateErc721ABI as solmateERC721ABI } from "../../generated.js";
import type { ReverseMirage } from "../../types/rm.js";
import type { ERC721, ERC721Data } from "../types.js";
import type { BaseERC721, ERC721Data } from "../types.js";
import { createERC721Data } from "../utils.js";
import { getERC721BalanceOf } from "./getERC721BalanceOf.js";

export type GetERC721DataParameters<TERC721 extends ERC721> = Omit<
export type GetERC721DataParameters<TERC721 extends BaseERC721> = Omit<
ReadContractParameters<typeof solmateERC721ABI, "balanceOf">,
"address" | "abi" | "functionName" | "args"
> & { erc721: TERC721; address: Address };

export type GetERC721DataReturnType<TERC721 extends ERC721> =
export type GetERC721DataReturnType<TERC721 extends BaseERC721> =
ERC721Data<TERC721>;

export const getERC721Data = <
TChain extends Chain | undefined,
TERC721 extends ERC721,
TERC721 extends BaseERC721,
T extends "select" | undefined,
>(
client: Client<Transport, TChain>,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,12 +8,12 @@ import type {
import { readContract } from "viem/contract";
import { solmateErc721ABI as solmateERC721ABI } from "../../generated.js";
import type { ReverseMirage } from "../../types/rm.js";
import type { ERC721 } from "../types.js";
import type { BaseERC721 } from "../types.js";

export type GetERC721IsApprovedForAllParameters = Omit<
ReadContractParameters<typeof solmateERC721ABI, "isApprovedForAll">,
"address" | "abi" | "functionName" | "args"
> & { erc721: Pick<ERC721, "address">; owner: Address; spender: Address };
> & { erc721: Pick<BaseERC721, "address">; owner: Address; spender: Address };

export type GetERC721IsApprovedForAllReturnType = boolean;

Expand Down
4 changes: 2 additions & 2 deletions packages/core/src/erc721/publicActions/getERC721Name.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,12 @@ import type { Chain, Client, ReadContractParameters, Transport } from "viem";
import { readContract } from "viem/contract";
import { solmateErc721ABI as solmateERC721ABI } from "../../generated.js";
import type { ReverseMirage } from "../../types/rm.js";
import type { ERC721 } from "../types.js";
import type { BaseERC721 } from "../types.js";

export type GetERC721NameParameters = Omit<
ReadContractParameters<typeof solmateERC721ABI, "name">,
"address" | "abi" | "functionName" | "args"
> & { erc721: Pick<ERC721, "address"> };
> & { erc721: Pick<BaseERC721, "address"> };

export type GetERC721NameReturnType = string;

Expand Down
4 changes: 2 additions & 2 deletions packages/core/src/erc721/publicActions/getERC721OwnerOf.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,12 +8,12 @@ import type {
import { readContract } from "viem/contract";
import { solmateErc721ABI as solmateERC721ABI } from "../../generated.js";
import type { ReverseMirage } from "../../types/rm.js";
import type { ERC721 } from "../types.js";
import type { BaseERC721 } from "../types.js";

export type GetERC721OwnerOfParameters = Omit<
ReadContractParameters<typeof solmateERC721ABI, "ownerOf">,
"address" | "abi" | "functionName" | "args"
> & { erc721: Pick<ERC721, "address">; id: bigint };
> & { erc721: Pick<BaseERC721, "address">; id: bigint };

export type GetERC721OwnerOfReturnType = Address;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,12 +8,12 @@ import type {
import { readContract } from "viem/contract";
import { solmateErc721ABI as solmateERC721ABI } from "../../generated.js";
import type { ReverseMirage } from "../../types/rm.js";
import type { ERC721 } from "../types.js";
import type { BaseERC721 } from "../types.js";

export type GetERC721SupportsInterfaceParameters = Omit<
ReadContractParameters<typeof solmateERC721ABI, "supportsInterface">,
"address" | "abi" | "functionName" | "args"
> & { erc721: Pick<ERC721, "address">; interfaceID: Hex };
> & { erc721: Pick<BaseERC721, "address">; interfaceID: Hex };

export type GetERC721SupportsInterfaceReturnType = boolean;

Expand Down
4 changes: 2 additions & 2 deletions packages/core/src/erc721/publicActions/getERC721Symbol.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,12 @@ import type { Chain, Client, ReadContractParameters, Transport } from "viem";
import { readContract } from "viem/contract";
import { solmateErc721ABI as solmateERC721ABI } from "../../generated.js";
import type { ReverseMirage } from "../../types/rm.js";
import type { ERC721 } from "../types.js";
import type { BaseERC721 } from "../types.js";

export type GetERC721SymbolParameters = Omit<
ReadContractParameters<typeof solmateERC721ABI, "symbol">,
"address" | "abi" | "functionName" | "args"
> & { erc721: Pick<ERC721, "address"> };
> & { erc721: Pick<BaseERC721, "address"> };

export type GetERC721SymbolReturnType = string;

Expand Down
4 changes: 2 additions & 2 deletions packages/core/src/erc721/publicActions/getERC721TokenURI.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,12 @@ import type { Chain, Client, ReadContractParameters, Transport } from "viem";
import { readContract } from "viem/contract";
import { solmateErc721ABI as solmateERC721ABI } from "../../generated.js";
import type { ReverseMirage } from "../../types/rm.js";
import type { ERC721 } from "../types.js";
import type { BaseERC721 } from "../types.js";

export type GetERC721TokenURIParameters = Omit<
ReadContractParameters<typeof solmateERC721ABI, "tokenURI">,
"address" | "abi" | "functionName" | "args"
> & { erc721: Pick<ERC721, "address">; id: bigint };
> & { erc721: Pick<BaseERC721, "address">; id: bigint };

export type GetERC721TokenURIReturnType = string;

Expand Down
6 changes: 4 additions & 2 deletions packages/core/src/erc721/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,17 @@ import type { Address } from "viem";
import type { Token, TokenData } from "../types/token.js";
import type { Tuple } from "../types/tuple.js";

export type ERC721 = Token<"erc721"> & {
export type BaseERC721<TType extends string = string> = Token<TType> & {
address: Address;
name: string;
symbol: string;
blockCreated: bigint;
};

export type ERC721 = BaseERC721<"erc721">;

export type ERC721Data<
TERC721 extends ERC721,
TERC721 extends BaseERC721,
TBalance extends number = number,
> = TokenData<
TERC721,
Expand Down
Loading

0 comments on commit a8d3004

Please sign in to comment.