Skip to content

Commit

Permalink
Migration to viem
Browse files Browse the repository at this point in the history
  • Loading branch information
busimus committed Apr 9, 2024
1 parent a1118f0 commit cda6c91
Show file tree
Hide file tree
Showing 29 changed files with 2,410 additions and 2,761 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -32,5 +32,5 @@ parse a transaction receipt from ethers.js and web3.js
# yarn ts-node ./examples/01-retrieve-spot-price.ts

# project dependencies
ethers
viem
```
4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@crocswap-libs/sdk",
"version": "0.3.9-2",
"version": "1.0.0",
"description": "🛠🐊🛠 An SDK for building applications on top of CrocSwap",
"author": "Ben Wolski <[email protected]>",
"repository": "https://github.com/CrocSwap/sdk.git",
Expand Down Expand Up @@ -40,6 +40,6 @@
"typescript": "^5.3.3"
},
"dependencies": {
"ethers": "^5.5.3"
"viem": "^2.9.13"
}
}
144 changes: 0 additions & 144 deletions src/abis/erc20.read.ts

This file was deleted.

31 changes: 20 additions & 11 deletions src/constants.ts
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
import { BigNumber } from "ethers";
import { mainnet, goerli, sepolia, scroll, blast, blastSepolia, arbitrumGoerli, localhost, Chain, scrollSepolia } from "viem/chains";

type ChainAddress = string;
type ChainId = string;
type ChainId = `0x${string}`;

export const MIN_TICK = -665454;
export const MAX_TICK = 831818;
export const MAX_SQRT_PRICE: BigNumber = BigNumber.from(
"21267430153580247136652501917186561138").sub(1);
export const MIN_SQRT_PRICE: BigNumber = BigNumber.from("65538").sub(1);
export const MAX_LIQ = BigNumber.from(2).pow(128).sub(1);
export const MAX_SQRT_PRICE: bigint = BigInt(
"21267430153580247136652501917186561138") - BigInt(1);
export const MIN_SQRT_PRICE: bigint = BigInt("65538") - BigInt(1);
export const MAX_LIQ = BigInt(2) ** BigInt(128) - BigInt(1);

export interface ChainSpec {
nodeUrl: string;
Expand All @@ -33,20 +33,21 @@ export interface ChainSpec {
blockExplorer?: string;
displayName: string;
logoUrl?: string;
viemChain: Chain;
}

const ETHEREUM_LOGO =
"https://d33wubrfki0l68.cloudfront.net/fcd4ecd90386aeb50a235ddc4f0063cfbb8a7b66/4295e/static/bfc04ac72981166c740b189463e1f74c/40129/eth-diamond-black-white.jpg";
const SCROLL_LOGO =
"https://develop--ambient-finance.netlify.app/scroll_logo.png";
const BLAST_LOGO =
const BLAST_LOGO =
"https://assets-global.website-files.com/65a6baa1a3f8ed336f415cb4/65a6cc95aae1066cf96d497d_Logo%20Black%20on%20Yellow%20Background%402x-p-500.png"

const DFLT_SDK_INFURA_KEY = '4741d1713bff4013bc3075ed6e7ce091'

const GOERLI_CHAIN: ChainSpec = {
nodeUrl: "https://goerli.infura.io/v3/" + DFLT_SDK_INFURA_KEY,
wsUrl: "wss://goerli.infura.io/ws/v3/" + DFLT_SDK_INFURA_KEY,
nodeUrl: "https://goerli.infura.io/v3/" + DFLT_SDK_INFURA_KEY,
wsUrl: "wss://goerli.infura.io/ws/v3/" + DFLT_SDK_INFURA_KEY,
addrs: {
dex: "0xfafcd1f5530827e7398b6d3c509f450b1b24a209",
query: "0xc9900777baa5EE94Cd2C6509fb09278A1A46b7e8",
Expand All @@ -64,9 +65,9 @@ const GOERLI_CHAIN: ChainSpec = {
blockExplorer: "https://goerli.etherscan.io/",
displayName: "Görli",
logoUrl: ETHEREUM_LOGO,
viemChain: goerli,
};


const ARB_GOERLI_CHAIN: ChainSpec = {
nodeUrl: "https://goerli-rollup.arbitrum.io/rpc",
addrs: {
Expand All @@ -86,6 +87,7 @@ const ARB_GOERLI_CHAIN: ChainSpec = {
blockExplorer: "https://goerli.arbiscan.io/",
displayName: "Arbitrum Görli",
logoUrl: ETHEREUM_LOGO,
viemChain: arbitrumGoerli,
};

const MAINNET_CHAIN: ChainSpec = {
Expand All @@ -111,6 +113,7 @@ const MAINNET_CHAIN: ChainSpec = {
blockExplorer: "https://etherscan.io/",
displayName: "Ethereum",
logoUrl: ETHEREUM_LOGO,
viemChain: mainnet,
};

const SEPOLIA_CHAIN: ChainSpec = {
Expand All @@ -135,6 +138,7 @@ const SEPOLIA_CHAIN: ChainSpec = {
blockExplorer: "https://sepolia.etherscan.io/",
displayName: "Sepolia",
logoUrl: ETHEREUM_LOGO,
viemChain: sepolia,
};

const BLAST_CHAIN: ChainSpec = {
Expand All @@ -159,6 +163,7 @@ const BLAST_CHAIN: ChainSpec = {
blockExplorer: "https://blastscan.io/",
displayName: "Blast",
logoUrl: BLAST_LOGO,
viemChain: blast,
};

const BLAST_SEPOLIA_CHAIN: ChainSpec = {
Expand All @@ -183,6 +188,7 @@ const BLAST_SEPOLIA_CHAIN: ChainSpec = {
blockExplorer: "https://testnet.blastscan.io/",
displayName: "Blast Sepolia",
logoUrl: BLAST_LOGO,
viemChain: blastSepolia,
};

const SCROLL_SEPOLIA_CHAIN: ChainSpec = {
Expand All @@ -206,6 +212,7 @@ const SCROLL_SEPOLIA_CHAIN: ChainSpec = {
blockExplorer: "https://sepolia.scrollscan.dev/",
displayName: "Scroll Sepolia",
logoUrl: SCROLL_LOGO,
viemChain: scrollSepolia,
};

const SCROLL_CHAIN: ChainSpec = {
Expand All @@ -230,12 +237,14 @@ const SCROLL_CHAIN: ChainSpec = {
blockExplorer: "https://scrollscan.com/",
displayName: "Scroll",
logoUrl: SCROLL_LOGO,
viemChain: scroll,
};

const LOCAL_FORK_CHAIN: ChainSpec = Object.assign({}, GOERLI_CHAIN, {
nodeUrl: "http://127.0.0.1:8545",
chainId: "0x7a69",
displayName: "Local Fork"
displayName: "Local Fork",
viemChain: localhost,
});

export const CHAIN_SPECS: { [chainId: string]: ChainSpec } = {
Expand Down
4 changes: 2 additions & 2 deletions src/constants/mainnetTokens.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { ethers } from "ethers";
import { AddressZero } from "../utils"

export const ETH = ethers.constants.AddressZero
export const ETH = AddressZero

export const USDC = "0xa0b86991c6218b36c1d19d4a2e9eb0ce3606eb48"
export const DAI = "0x6b175474e89094c44da98b954eedeac495271d0f"
Loading

0 comments on commit cda6c91

Please sign in to comment.