Skip to content

Commit

Permalink
Merge pull request #67 from kyscott18/kjs/update
Browse files Browse the repository at this point in the history
`viem@2`
  • Loading branch information
kyscott18 authored Mar 18, 2024
2 parents 70369fc + 5b19e79 commit c52ffba
Show file tree
Hide file tree
Showing 189 changed files with 5,128 additions and 3,909 deletions.
2 changes: 1 addition & 1 deletion .changeset/config.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,5 +7,5 @@
"access": "public",
"baseBranch": "main",
"updateInternalDependencies": "patch",
"ignore": []
"ignore": ["reverse-mirage-next-example"]
}
5 changes: 5 additions & 0 deletions .changeset/fast-laws-battle.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"reverse-mirage": minor
---

Migrated to peer dependency viem to v2.
10 changes: 0 additions & 10 deletions .husky/pre-commit

This file was deleted.

4 changes: 4 additions & 0 deletions .npmrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
auto-install-peers=false
enable-pre-post-scripts=true
link-workspace-packages=deep
strict-peer-dependencies=false
14 changes: 7 additions & 7 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ Building blocks for Ethereum app development. Built using [Viem](https://viem.sh

## Features

- ✅ 10x-100x faster, 10.4x smaller than [`@uniswap/sdk-core`](https://github.com/uniswap/sdk-core)
- ✅ 10x-100x faster, 11.6x smaller than [`@uniswap/sdk-core`](https://github.com/uniswap/sdk-core)
- ✅ Abstactions for most commonly used token standards
- ✅ Supports `permit`
- ✅ Extensible to build apps and libraries
Expand Down Expand Up @@ -56,7 +56,7 @@ $ npm i reverse-mirage

## Benchmarks

Benchmarks are done with [mitata](https://github.com/evanwashere/mitata). To reproduce:
Benchmarks are done with [mitata](https://github.com/evanwashere/mitata). To reproduce:

```sh
$ cd packages/core/
Expand All @@ -65,13 +65,13 @@ $ bun run src/amount/utils.bench.ts

### Results

* amount add: `reverse mirage` **8.17x** faster than `@uniswap/sdk-core`
* amount equal to: `reverse-mirage` **10.63x** faster than `@uniswap/sdk-core`
* amount to number: `reverse-mirage` **136.14x** faster than `@uniswap/sdk-core`
* amount to significant: `reverse-mirage` **30.03x** faster than `@uniswap/sdk-core`
- amount add: `reverse mirage` **8.31x** faster than `@uniswap/sdk-core`
- amount equal to: `reverse-mirage` **18.9x** faster than `@uniswap/sdk-core`
- amount to number: `reverse-mirage` **313x** faster than `@uniswap/sdk-core`
- amount to significant: `reverse-mirage` **27.1x** faster than `@uniswap/sdk-core`

## Bundle Size

`reverse-mirage`: **5.12 kB**
`reverse-mirage`: **4.61 kB**

`@uniswap/sdk-core`: **53.4 kB**
14 changes: 8 additions & 6 deletions biome.json
Original file line number Diff line number Diff line change
@@ -1,12 +1,14 @@
{
"$schema": "https://biomejs.dev/schemas/1.0.0/schema.json",
"$schema": "https://biomejs.dev/schemas/1.6.1/schema.json",
"files": {
"ignore": [
"**/node_modules",
"CHANGELOG.md",
"node_modules",
".vitepress",
".next",
"coverage",
"dist",
"tsconfig.json",
"tsconfig.*.json",
"generated.ts",
"CHANGELOG.md",
"pnpm-lock.yaml"
]
},
Expand All @@ -17,7 +19,7 @@
"enabled": true,
"formatWithErrors": true,
"indentStyle": "space",
"indentSize": 2,
"indentWidth": 2,
"lineWidth": 80
},
"linter": {
Expand Down
10 changes: 5 additions & 5 deletions docs/benchmark.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,13 @@

## Results

* amount add: `reverse mirage` **8.17x** faster than `@uniswap/sdk-core`
* amount equal to: `reverse-mirage` **10.63x** faster than `@uniswap/sdk-core`
* amount to number: `reverse-mirage` **136.14x** faster than `@uniswap/sdk-core`
* amount to significant: `reverse-mirage` **30.03x** faster than `@uniswap/sdk-core`
* amount add: `reverse mirage` **8.31x** faster than `@uniswap/sdk-core`
* amount equal to: `reverse-mirage` **18.9x** faster than `@uniswap/sdk-core`
* amount to number: `reverse-mirage` **313x** faster than `@uniswap/sdk-core`
* amount to significant: `reverse-mirage` **27.1x** faster than `@uniswap/sdk-core`

## Bundle Size

`reverse-mirage`: **5.12 kB**
`reverse-mirage`: **4.61 kB**

`@uniswap/sdk-core`: **53.4 kB**
2 changes: 1 addition & 1 deletion docs/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ This documentation is still under active development.

## Features

- ✅ 10x-100x faster, 10.4x smaller than [`@uniswap/sdk-core`](https://github.com/uniswap/sdk-core)
- ✅ 10x-100x faster, 11.6x smaller than [`@uniswap/sdk-core`](https://github.com/uniswap/sdk-core)
- ✅ Abstactions for most commonly used token standards
- ✅ Extensible to build apps and libraries
- ✅ Seamless extension to [Viem](https://github.com/wagmi-dev/viem)
Expand Down
2 changes: 1 addition & 1 deletion docs/start.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@

### Tokens

Tokens represent an asset on Ethereum. Tokens by themselves don't hold any specific state, but can be used to read from Ethereum or send a transaction. Currently `reverse-mirage` has:
Tokens represent an asset on Ethereum. Currently `reverse-mirage` has:

- **ERC20**: Fungible tokens
- **ERC721**: Non-fungible tokens
Expand Down
33 changes: 0 additions & 33 deletions examples/next-interface/CHANGELOG.md

This file was deleted.

34 changes: 0 additions & 34 deletions examples/next-interface/biome.json

This file was deleted.

18 changes: 9 additions & 9 deletions examples/next-interface/components/beet.tsx
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
import { clsx } from "clsx";
import Link from "next/link";
import React from "react";
import type React from "react";
import { toast } from "react-hot-toast";
import type { TransactionReceipt } from "viem";
import type { Address } from "wagmi";
import { useNetwork } from "wagmi";
import type { Address } from "viem";
import { useChains } from "wagmi";

export type BeetTx = {
title: string;
Expand Down Expand Up @@ -68,7 +68,7 @@ export class DefaultToasterWrapper {
txSending(tx: Omit<TxSending, "status">) {
toast.loading(this._buildToastContainer({ ...tx, status: "sending" }), {
id: tx.id,
duration: Infinity,
duration: Number.POSITIVE_INFINITY,
position: "bottom-left",
});
}
Expand Down Expand Up @@ -106,15 +106,15 @@ export class DefaultToasterWrapper {
tx: TxSending | TxSuccess | TxError | TxPending,
) {
return (
<div className="flex w-full flex-col overflow-hidden font-mono">
<div className="flex items-center justify-between w-full">
<p className="flex items-center p2 gap-1 text-ellipsis ma">
<div className="flex flex-col w-full overflow-hidden font-mono">
<div className="flex items-center justify-between w-full">
<p className="flex items-center gap-1 p2 text-ellipsis ma">
{tx.title}
<span className="flex p5">{tx.humanCount}</span>
</p>
<button
type="button"
className="pointer text-xl text-secondary hover:text-black"
className="text-xl pointer text-secondary hover:text-black"
onClick={() => toast.dismiss(tx.id)}
>
×
Expand Down Expand Up @@ -149,7 +149,7 @@ export const AddressLink: React.FC<{
data: "tx" | "address";
className?: string;
}> = ({ address, className, data }) => {
const { chain } = useNetwork();
const [chain] = useChains();
return (
<Link
href={`${
Expand Down
1 change: 1 addition & 0 deletions examples/next-interface/components/tokenAmountDisplay.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ export default function TokenAmountDisplay({
// [newest, oldest]
const [from, setFrom] = useState<[number, number]>([0, 0]);

// biome-ignore lint/correctness/useExhaustiveDependencies: avoid circle
useEffect(() => {
from[0] !== num && setFrom([num, from[0]]);
}, [num]);
Expand Down
2 changes: 1 addition & 1 deletion examples/next-interface/components/tokenAmountRow.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import AsyncButton from "./asyncButton";
import { Beet } from "./beet";

import { useTransfer } from "@/hooks/useTransfer";
import { type UseQueryResult } from "@tanstack/react-query";
import type { UseQueryResult } from "@tanstack/react-query";
import {
type ERC20,
type ERC20Amount,
Expand Down
2 changes: 1 addition & 1 deletion examples/next-interface/contexts/environment.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { type ERC20 } from "@/lib/types";
import type { ERC20 } from "@/lib/types";
import { useState } from "react";
import { createContainer } from "unstated-next";
import type { Hex } from "viem";
Expand Down
9 changes: 0 additions & 9 deletions examples/next-interface/hooks/internal/useFastClient.ts

This file was deleted.

8 changes: 4 additions & 4 deletions examples/next-interface/hooks/useBalance.ts
Original file line number Diff line number Diff line change
@@ -1,16 +1,16 @@
import { useQuery } from "@tanstack/react-query";
import { type ERC20, getERC20BalanceOf } from "reverse-mirage";
import { type Address, usePublicClient } from "wagmi";
import type { Address } from "viem";
import { useChainId, usePublicClient } from "wagmi";
import type { HookArg } from "./internal/types";
import { getQueryKey, userRefectchInterval } from "./internal/utils";
import { useChainID } from "./useChain";

export const useBalance = <TERC20 extends ERC20>(
erc20: HookArg<TERC20>,
address: HookArg<Address>,
) => {
const publicClient = usePublicClient();
const chainID = useChainID();
const chainID = useChainId();

return useQuery({
queryKey: getQueryKey(
Expand All @@ -21,7 +21,7 @@ export const useBalance = <TERC20 extends ERC20>(
enabled: [erc20, address].some((a) => a === undefined) ? false : true,
queryFn: () =>
getERC20BalanceOf(publicClient, { erc20: erc20!, address: address! }),
staleTime: Infinity,
staleTime: Number.POSITIVE_INFINITY,
refetchInterval: userRefectchInterval,
});
};
9 changes: 0 additions & 9 deletions examples/next-interface/hooks/useChain.ts

This file was deleted.

8 changes: 4 additions & 4 deletions examples/next-interface/hooks/useSetup.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,11 @@ import { testClient, walletClient } from "@/pages/_app";
import { useMutation, useQueryClient } from "@tanstack/react-query";
import { createERC20 } from "reverse-mirage";
import invariant from "tiny-invariant";
import { type Hex } from "viem";
import type { Hex } from "viem";
import { parseEther } from "viem/utils";
import { useChainId, usePublicClient } from "wagmi";
import ERC20 from "../../../contracts/out/ERC20.sol/ERC20.json";
import { erc20ABI } from "../generated";
import { erc20Abi } from "../generated";

export const useSetup = () => {
const publicClient = usePublicClient();
Expand All @@ -21,7 +21,7 @@ export const useSetup = () => {
if (id === undefined) {
const deployHash = await walletClient.deployContract({
account: ALICE,
abi: erc20ABI,
abi: erc20Abi,
bytecode: ERC20.bytecode.object as Hex,
args: ["Marshall Rogan INU", "MRI", 18],
});
Expand All @@ -39,7 +39,7 @@ export const useSetup = () => {
});

const mintHash = await walletClient.writeContract({
abi: erc20ABI,
abi: erc20Abi,
functionName: "mint",
address: contractAddress,
args: [ALICE, parseEther("10")],
Expand Down
11 changes: 5 additions & 6 deletions examples/next-interface/hooks/useTransfer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,21 +7,20 @@ import {
getERC20BalanceOf,
simulateERC20Transfer,
} from "reverse-mirage";
import type { Address } from "viem";
import { getAddress } from "viem/utils";
import { type Address, useWalletClient } from "wagmi";
import { useChainId, usePublicClient, useWalletClient } from "wagmi";
import type { HookArg } from "./internal/types";
import { useFastClient } from "./internal/useFastClient";
import { getQueryKey } from "./internal/utils";
import { useChainID } from "./useChain";

export const useTransfer = <TERC20 extends BaseERC20>(
amount: HookArg<ERC20Amount<TERC20>>,
to: HookArg<Address>,
) => {
const queryClient = useQueryClient();
const client = useFastClient();
const client = usePublicClient();
const walletClient = useWalletClient();
const chainID = useChainID();
const chainID = useChainId();

const title = "Transfer";

Expand Down Expand Up @@ -94,5 +93,5 @@ export const useTransfer = <TERC20 extends BaseERC20>(
},
],
} as const satisfies { data: readonly BeetStage[]; status: "success" };
}, [to, amount, mutate]);
}, [to, amount, mutate, walletClient.data]);
};
Loading

1 comment on commit c52ffba

@vercel
Copy link

@vercel vercel bot commented on c52ffba Mar 18, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please sign in to comment.