From bd88d06734abded8a57e80daf3b13dcaa87b5b2d Mon Sep 17 00:00:00 2001 From: revantark Date: Mon, 24 Jun 2024 14:26:34 +0530 Subject: [PATCH] support evm localnet --- packages/orderbook/package.json | 2 +- packages/orderbook/src/lib/asset.ts | 48 ++++++++++++++++++- packages/orderbook/src/lib/contractAddress.ts | 27 +++++++---- packages/orderbook/src/lib/orderpair.ts | 8 ++-- 4 files changed, 70 insertions(+), 15 deletions(-) diff --git a/packages/orderbook/package.json b/packages/orderbook/package.json index 179b484..33ce6f3 100644 --- a/packages/orderbook/package.json +++ b/packages/orderbook/package.json @@ -1,6 +1,6 @@ { "name": "@gardenfi/orderbook", - "version": "0.1.5", + "version": "0.1.6", "type": "module", "dependencies": { "@catalogfi/utils": "^0.1.6", diff --git a/packages/orderbook/src/lib/asset.ts b/packages/orderbook/src/lib/asset.ts index 5cff846..36d1b9d 100644 --- a/packages/orderbook/src/lib/asset.ts +++ b/packages/orderbook/src/lib/asset.ts @@ -5,6 +5,8 @@ export const Chains = { bitcoin_testnet: "bitcoin_testnet", bitcoin_regtest: "bitcoin_regtest", ethereum_arbitrum: "ethereum_arbitrum", + ethereum_arbitrumlocalnet: "ethereum_arbitrumlocalnet", + ethereum_localnet: "ethereum_localnet", } as const; export type Chain = keyof typeof Chains; @@ -55,6 +57,28 @@ export const Assets = { address: "0x3D1e56247033FE191DC789b5838E366dC04b1b73", }, }, + ethereum_arb_localnet: { + WBTC: { + name: "Wrapped Bitcoin", + symbol: "WBTC", + decimals: 8, + chain: Chains.ethereum_arbitrum, + isToken: true, + thumbnail: "https://cryptologos.cc/logos/wrapped-bitcoin-wbtc-logo.svg", + address: "0xe7f1725E7734CE288F8367e1Bb143E90bb3F0512", + }, + }, + ethereum_localnet: { + WBTC: { + name: "Wrapped Bitcoin", + symbol: "WBTC", + decimals: 8, + chain: Chains.ethereum_localnet, + isToken: true, + thumbnail: "https://cryptologos.cc/logos/wrapped-bitcoin-wbtc-logo.svg", + address: "0x5FbDB2315678afecb367f032d93F642f64180aa3", + }, + }, bitcoin: { BTC: { name: "Bitcoin", @@ -149,12 +173,34 @@ export const ChainsData: Record = { thumbnail: "https://cryptologos.cc/logos/arbitrum-arb-logo.svg", }, }, + ethereum_arbitrumlocalnet: { + nativeAsset: { + name: "Ethereum", + symbol: "ETH", + decimals: 18, + chain: Chains.ethereum_arbitrumlocalnet, + isToken: false, + thumbnail: "https://cryptologos.cc/logos/arbitrum-arb-logo.svg", + }, + }, + ethereum_localnet: { + nativeAsset: { + name: "Ethereum", + symbol: "ETH", + decimals: 18, + chain: Chains.ethereum_localnet, + isToken: false, + thumbnail: "https://cryptologos.cc/logos/ethereum-eth-logo.svg", + }, + }, }; export const isMainnet = (chain: Chain) => { return !( chain === Chains.ethereum_sepolia || chain === Chains.bitcoin_testnet || - chain === Chains.bitcoin_regtest + chain === Chains.bitcoin_regtest || + chain === Chains.ethereum_arbitrumlocalnet || + chain === Chains.ethereum_localnet ); }; diff --git a/packages/orderbook/src/lib/contractAddress.ts b/packages/orderbook/src/lib/contractAddress.ts index 4aca970..65c0cbd 100644 --- a/packages/orderbook/src/lib/contractAddress.ts +++ b/packages/orderbook/src/lib/contractAddress.ts @@ -1,15 +1,22 @@ export type ContractAddress = { - AtomicSwap: string; + // TODO: Make this lowercase + AtomicSwap: string; }; export const CONTRACT_ADDRESS: Record = { - 1: { - AtomicSwap: "0xA5E38d098b54C00F10e32E51647086232a9A0afD", - }, - 11155111: { - AtomicSwap: "0x9ceD08aeE17Fbc333BB7741Ec5eB2907b0CA4241", - }, - 42161: { - AtomicSwap: "0x203DAC25763aE783Ad532A035FfF33d8df9437eE", - }, + 1: { + AtomicSwap: "0xA5E38d098b54C00F10e32E51647086232a9A0afD", + }, + 11155111: { + AtomicSwap: "0x9ceD08aeE17Fbc333BB7741Ec5eB2907b0CA4241", + }, + 42161: { + AtomicSwap: "0x203DAC25763aE783Ad532A035FfF33d8df9437eE", + }, + 31337: { + AtomicSwap: "0xe7f1725E7734CE288F8367e1Bb143E90bb3F0512", + }, + 31338: { + AtomicSwap: "0xDc64a140Aa3E981100a9becA4E685f962f0cF6C9", + }, }; diff --git a/packages/orderbook/src/lib/orderpair.ts b/packages/orderbook/src/lib/orderpair.ts index 917bfc7..8f616f2 100644 --- a/packages/orderbook/src/lib/orderpair.ts +++ b/packages/orderbook/src/lib/orderpair.ts @@ -1,6 +1,6 @@ -import { Asset, Chains, EvmChain } from './asset'; -import { CONTRACT_ADDRESS } from './contractAddress'; -import { OrderpairErrors } from './errors'; +import { Asset, Chains, EvmChain } from "./asset"; +import { CONTRACT_ADDRESS } from "./contractAddress"; +import { OrderpairErrors } from "./errors"; export const orderPairGenerator = (from: Asset, to: Asset) => { if (from.chain === to.chain) { @@ -28,6 +28,8 @@ export const chainToId: Record = { ethereum: 1, ethereum_sepolia: 11155111, ethereum_arbitrum: 42161, + ethereum_arbitrumlocalnet: 31338, + ethereum_localnet: 31337, }; export const idToChain: Record = Object.entries(