Skip to content

Commit

Permalink
Merge pull request #46 from kyscott18/block-created
Browse files Browse the repository at this point in the history
block created and constants
  • Loading branch information
kyscott18 authored Sep 11, 2023
2 parents 386b9be + a75ece2 commit dc0feaf
Show file tree
Hide file tree
Showing 17 changed files with 163 additions and 5 deletions.
5 changes: 5 additions & 0 deletions .changeset/lemon-singers-jog.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"reverse-mirage": patch
---

Add block created to several types and define constants for popular chains
107 changes: 107 additions & 0 deletions packages/core/src/constants.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,107 @@
import type { NativeCurrency } from "./native/types.js";
import { createNativeCurrency } from "./native/utils.js";
import type { WETH } from "./weth/types.js";
import { createWETH } from "./weth/utils.js";

export type ChainTokens = { native: NativeCurrency; weth?: WETH };

export const mainnetTokens = {
native: createNativeCurrency("Ether", "ETH", 18, 1),
weth: createWETH(
"0xC02aaA39b223FE8D0A0e5C4F27eAD9083C756Cc2",
"Wrapped Ether",
"WETH",
18,
1,
4719568n,
),
} as const satisfies ChainTokens;

export const sepoliaTokens = {
native: createNativeCurrency("Ether", "ETH", 18, 11155111),
} as const satisfies ChainTokens;

export const goerliTokens = {
native: createNativeCurrency("Ether", "ETH", 18, 5),
weth: createWETH(
"0xB4FBF271143F4FBf7B91A5ded31805e42b2208d6",
"Wrapped Ether",
"WETH",
18,
5,
1036651n,
),
} as const satisfies ChainTokens;

export const optimismTokens = {
native: createNativeCurrency("Ether", "ETH", 18, 10),
weth: createWETH(
"0x4200000000000000000000000000000000000006",
"Wrapped Ether",
"WETH",
18,
10,
),
} as const satisfies ChainTokens;

export const optimismGoerliTokens = {
native: createNativeCurrency("Ether", "ETH", 18, 420),
} as const satisfies ChainTokens;

export const arbitrumTokens = {
native: createNativeCurrency("Ether", "ETH", 18, 42161),
weth: createWETH(
"0x82aF49447D8a07e3bd95BD0d56f35241523fBab1",
"Wrapped Ether",
"WETH",
18,
42161,
55n,
),
} as const satisfies ChainTokens;

export const arbitrumGoerliTokens = {
native: createNativeCurrency("Ether", "ETH", 18, 421_613),
} as const satisfies ChainTokens;

export const baseTokens = {
native: createNativeCurrency("Ether", "ETH", 18, 8453),
weth: createWETH(
"0x4200000000000000000000000000000000000006",
"Wrapped Ether",
"WETH",
18,
8453,
),
} as const satisfies ChainTokens;

export const baseGoerliTokens = {
native: createNativeCurrency("Ether", "ETH", 18, 84531),
} as const satisfies ChainTokens;

export const celoTokens = {
native: createNativeCurrency("Celo Native Asset", "CELO", 18, 42_220),
weth: createWETH(
"0x471EcE3750Da237f93B8E339c536989b8978a438",
"Celo Native Asset",
"CELO",
18,
42_220,
2919n,
),
} as const satisfies ChainTokens;

export const celoAlfajoresTokens = {
native: createNativeCurrency("Celo Native Asset", "CELO", 18, 44_787),
weth: createWETH(
"0xF194afDf50B03e69Bd7D057c1Aa9e10c9954E4C9",
"Celo Native Asset",
"CELO",
18,
44_787,
),
} as const satisfies ChainTokens;

export const foundryTokens = {
native: createNativeCurrency("Ether", "ETH", 18, 31_337),
} as const satisfies ChainTokens;
4 changes: 3 additions & 1 deletion packages/core/src/erc1155/reads.ts
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,8 @@ export const erc1155BalanceOf = <TERC1155 extends ERC1155>(args: {
}) as const satisfies ReverseMirageRead<bigint>;

export const getERC1155 = (args: {
erc1155: Pick<ERC1155, "address" | "id" | "chainID">;
erc1155: Pick<ERC1155, "address" | "id" | "chainID"> &
Partial<Pick<ERC1155, "blockCreated">>;
}) =>
({
read: (publicClient: PublicClient) =>
Expand All @@ -67,5 +68,6 @@ export const getERC1155 = (args: {
args.erc1155.id,
data,
args.erc1155.chainID,
args.erc1155.blockCreated,
),
}) as const satisfies ReverseMirageRead<string>;
1 change: 1 addition & 0 deletions packages/core/src/erc1155/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ export type ERC1155 = Token<"erc1155"> & {
address: Address;
id: bigint;
uri: string;
blockCreated: bigint;
};

export type ERC1155Data<TERC1155 extends ERC1155> = Amount<
Expand Down
1 change: 1 addition & 0 deletions packages/core/src/erc1155/utils.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ const erc1155 = {
id: 0n,
uri: "https://mitch.com",
chainID: foundry.id,
blockCreated: 0n,
} as const;

describe("utils", () => {
Expand Down
2 changes: 2 additions & 0 deletions packages/core/src/erc1155/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,12 +9,14 @@ export const createERC1155 = (
id: bigint,
uri: string,
chainID: number,
blockCreated = 0n,
): ERC1155 => ({
type: "erc1155",
address: getAddress(address),
id,
uri,
chainID,
blockCreated,
});

/**
Expand Down
12 changes: 9 additions & 3 deletions packages/core/src/erc20/reads.ts
Original file line number Diff line number Diff line change
Expand Up @@ -151,7 +151,8 @@ export const erc20PermitDomainSeparator = (args: {
}) as const satisfies ReverseMirageRead<Hex>;

export const getERC20 = (args: {
erc20: Pick<ERC20, "address" | "chainID">;
erc20: Pick<BaseERC20, "address" | "chainID"> &
Partial<Pick<BaseERC20, "blockCreated">>;
}) =>
({
read: (publicClient: PublicClient) =>
Expand All @@ -167,12 +168,13 @@ export const getERC20 = (args: {
data[1],
data[2],
args.erc20.chainID,
args.erc20.blockCreated,
),
}) as const satisfies ReverseMirageRead<[string, string, number]>;

export const getERC20Permit = (args: {
erc20: Pick<ERC20Permit, "address" | "chainID"> &
Partial<Pick<ERC20Permit, "version">>;
Partial<Pick<ERC20Permit, "version" | "blockCreated">>;
}) =>
({
read: (publicClient: PublicClient) =>
Expand All @@ -189,6 +191,7 @@ export const getERC20Permit = (args: {
data[2],
args.erc20.version ?? "1",
args.erc20.chainID,
args.erc20.blockCreated,
),
}) as const satisfies ReverseMirageRead<[string, string, number]>;

Expand All @@ -198,7 +201,8 @@ export const getERC20Permit = (args: {
* Implementation is determined by checking if calling `DOMAIN_SEPARATOR()` reverts
*/
export const erc20IsPermit = (args: {
erc20: Pick<ERC20, "address" | "chainID"> &
erc20: Pick<BaseERC20, "address" | "chainID"> &
Partial<Pick<BaseERC20, "blockCreated">> &
Partial<Pick<ERC20Permit, "version">>;
}) =>
({
Expand All @@ -220,6 +224,7 @@ export const erc20IsPermit = (args: {
data[0][1],
data[0][2],
args.erc20.chainID,
args.erc20.blockCreated,
)
: createERC20Permit(
args.erc20.address,
Expand All @@ -228,6 +233,7 @@ export const erc20IsPermit = (args: {
data[0][2],
args.erc20.version ?? "1",
args.erc20.chainID,
args.erc20.blockCreated,
),
}) as const satisfies ReverseMirageRead<
[[string, string, number], Hex] | [[string, string, number]]
Expand Down
1 change: 1 addition & 0 deletions packages/core/src/erc20/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ export type BaseERC20<TType extends string = string> = Token<TType> & {
name: string;
symbol: string;
decimals: number;
blockCreated: bigint;
};

export type ERC20 = BaseERC20<"erc20">;
Expand Down
2 changes: 2 additions & 0 deletions packages/core/src/erc20/utils.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ const erc20Permit = {
decimals: 18,
version: "1",
chainID: foundry.id,
blockCreated: 0n,
} as const;

describe("utils", () => {
Expand All @@ -38,6 +39,7 @@ describe("utils", () => {
symbol: "symbol",
decimals: 18,
chainID: foundry.id,
blockCreated: 0n,
});
});

Expand Down
4 changes: 4 additions & 0 deletions packages/core/src/erc20/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,13 +16,15 @@ export const createERC20 = (
symbol: string,
decimals: number,
chainID: number,
blockCreated = 0n,
): ERC20 => ({
type: "erc20",
address: getAddress(address),
name,
symbol,
decimals,
chainID,
blockCreated,
});

/**
Expand All @@ -35,6 +37,7 @@ export const createERC20Permit = (
decimals: number,
version: string,
chainID: number,
blockCreated = 0n,
): ERC20Permit => ({
type: "erc20Permit",
address: getAddress(address),
Expand All @@ -43,6 +46,7 @@ export const createERC20Permit = (
decimals,
version,
chainID,
blockCreated,
});

/**
Expand Down
4 changes: 3 additions & 1 deletion packages/core/src/erc721/reads.ts
Original file line number Diff line number Diff line change
Expand Up @@ -119,7 +119,8 @@ export const erc721SupportsInterface = (args: {
}) as const satisfies ReverseMirageRead<boolean>;

export const getERC721 = (args: {
erc721: Pick<ERC721, "address" | "id" | "chainID">;
erc721: Pick<ERC721, "address" | "id" | "chainID"> &
Partial<Pick<ERC721, "blockCreated">>;
}) =>
({
read: (publicClient: PublicClient) =>
Expand All @@ -136,6 +137,7 @@ export const getERC721 = (args: {
args.erc721.id,
data[2],
args.erc721.chainID,
args.erc721.blockCreated,
),
}) as const satisfies ReverseMirageRead<[string, string, string]>;

Expand Down
1 change: 1 addition & 0 deletions packages/core/src/erc721/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ export type ERC721 = Token<"erc721"> & {
symbol: string;
id: bigint;
tokenURI: string;
blockCreated: bigint;
};

export type ERC721IDData<TERC721 extends ERC721> = TokenData<
Expand Down
1 change: 1 addition & 0 deletions packages/core/src/erc721/utils.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ const erc721 = {
id: 0n,
tokenURI: "https://mitch.com",
chainID: foundry.id,
blockCreated: 0n,
} as const;

describe("utils", () => {
Expand Down
2 changes: 2 additions & 0 deletions packages/core/src/erc721/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ export const createERC721 = (
id: bigint,
tokenURI: string,
chainID: number,
blockCreated = 0n,
): ERC721 => ({
type: "erc721",
address: getAddress(address),
Expand All @@ -20,6 +21,7 @@ export const createERC721 = (
id,
tokenURI,
chainID,
blockCreated,
});

/**
Expand Down
18 changes: 18 additions & 0 deletions packages/core/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -193,3 +193,21 @@ export type {
ReverseMirageWrite,
Tuple,
} from "./types.js";

// CONSTANTS

export {
type ChainTokens,
mainnetTokens,
sepoliaTokens,
goerliTokens,
optimismTokens,
optimismGoerliTokens,
arbitrumTokens,
arbitrumGoerliTokens,
baseTokens,
baseGoerliTokens,
celoTokens,
celoAlfajoresTokens,
foundryTokens,
} from "./constants.js";
1 change: 1 addition & 0 deletions packages/core/src/weth/utils.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ const weth = {
decimals: 18,
address: zeroAddress,
chainID: foundry.id,
blockCreated: 0n,
} as const;

describe("utils", () => {
Expand Down
2 changes: 2 additions & 0 deletions packages/core/src/weth/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,13 @@ export const createWETH = (
symbol: string,
decimals: number,
chainID: number,
blockCreated = 0n,
): WETH => ({
type: "weth",
address: getAddress(address),
name,
symbol,
decimals,
chainID,
blockCreated,
});

0 comments on commit dc0feaf

Please sign in to comment.