From d465bd7073e93e3cf53ee59fa5abefcc490c2e8a Mon Sep 17 00:00:00 2001 From: 0xPrimata Date: Fri, 9 Feb 2024 22:21:49 -0300 Subject: [PATCH] feat: base bridge --- components/blockchain/bridge.tsx | 8 +++ .../blockchain/wallet-connect-custom.tsx | 4 +- config/networks.ts | 9 ++-- integrations/defi-llama/utils/index.ts | 2 + lib/generated/blockchain.ts | 2 +- lib/utils/get-network-color.ts | 1 + lib/utils/layerZero.ts | 54 +++++++++++++++---- 7 files changed, 64 insertions(+), 16 deletions(-) diff --git a/components/blockchain/bridge.tsx b/components/blockchain/bridge.tsx index e293ac9..76243d0 100644 --- a/components/blockchain/bridge.tsx +++ b/components/blockchain/bridge.tsx @@ -123,6 +123,14 @@ export function Bridge() { > Mantle + diff --git a/components/blockchain/wallet-connect-custom.tsx b/components/blockchain/wallet-connect-custom.tsx index b839731..99f561e 100644 --- a/components/blockchain/wallet-connect-custom.tsx +++ b/components/blockchain/wallet-connect-custom.tsx @@ -96,7 +96,7 @@ export const WalletConnectCustom = ({ {chain.iconUrl && ( {chain.name )} @@ -116,7 +116,7 @@ export const WalletConnectCustom = ({ { {chain.name } diff --git a/config/networks.ts b/config/networks.ts index cd48c57..1acaca6 100644 --- a/config/networks.ts +++ b/config/networks.ts @@ -6,7 +6,8 @@ import { Chain, ChainProviderFn, configureChains } from "wagmi" import { avalanche, mantle, - arbitrum + arbitrum, + base } from "wagmi/chains" import { alchemyProvider } from "wagmi/providers/alchemy" import { infuraProvider } from "wagmi/providers/infura" @@ -16,12 +17,14 @@ import { publicProvider } from "wagmi/providers/public" export const ETH_CHAINS_TEST = [ avalanche, mantle, - arbitrum + arbitrum, + base ] export const ETH_CHAINS_PROD = [ avalanche, mantle, - arbitrum + arbitrum, + base ] export const ETH_CHAINS_DEV = env.NEXT_PUBLIC_PROD_NETWORKS_DEV === "true" diff --git a/integrations/defi-llama/utils/index.ts b/integrations/defi-llama/utils/index.ts index eb60c48..a6cbefc 100644 --- a/integrations/defi-llama/utils/index.ts +++ b/integrations/defi-llama/utils/index.ts @@ -5,6 +5,8 @@ export const chainIdToName: Record = { 10: "optimism", 137: "matic-network", 42161: "arbitrum", + 8453: "base" + } export const nameToChainId: Record = { diff --git a/lib/generated/blockchain.ts b/lib/generated/blockchain.ts index 1300cb2..2d016bc 100644 --- a/lib/generated/blockchain.ts +++ b/lib/generated/blockchain.ts @@ -1,4 +1,4 @@ -// Generated by @wagmi/cli@1.1.0 on 12/29/2023 at 5:17:10 PM +// Generated by @wagmi/cli@1.1.0 on 2/9/2024 at 10:03:56 PM import { useContractEvent, UseContractEventConfig, diff --git a/lib/utils/get-network-color.ts b/lib/utils/get-network-color.ts index 768df8d..baec94a 100644 --- a/lib/utils/get-network-color.ts +++ b/lib/utils/get-network-color.ts @@ -1,6 +1,7 @@ export function GetNetworkColor(chain?: string) { if (chain === "homestead") return "green" if (chain === "arbitrum") return "blue" + if (chain === "base") return "blue" if (chain === "optimism") return "red" if (chain === "matic") return "purple" if (chain === "goerli") return "yellow" diff --git a/lib/utils/layerZero.ts b/lib/utils/layerZero.ts index d5d7906..fce45bf 100644 --- a/lib/utils/layerZero.ts +++ b/lib/utils/layerZero.ts @@ -1486,6 +1486,17 @@ export const networkConfig = { rpcUrl: "https://rpc.mantle.xyz ", blockExplorerUrl: "https://explorer.mantle.xyz", }, + base: { + name: "Base", + chainId: 8453, + lzChainId: 184, + bridgeLink: null, + nativeTokenName: "Ether", + nativeToken: "ETH", + rpcUrl: "https://base.llamarpc.com", + blockExplorerUrl: "https://basescan.io", + + } }; export const arbitrum = { @@ -1557,7 +1568,30 @@ export const mantle = { testnet: false, }; -export const supportedChains = ["arbitrum", "avalanche", "mantle"]; +export const base = { + id: networkConfig.base.chainId, + name: "Base", + network: "base", + iconUrl: + "data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAOEAAADhCAMAAAAJbSJIAAAAkFBMVEX///8AUv8ARv8AQP/o7v8AT/8ASv8ARP8ATP8ATv8ASf8AQf8APf8AQ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ytJjjEM657/v7v8RhlrS2vYU8CO43qvJZLBwi8xY9Yq0oUQuHl1t8QVVpFIxsauIckVQ0oRzQfIt7Wk4ugiFH2E7OUT6JuHMpYB/5B05Wki5xoeCFlEt0qyNvvJy0xCUiXo3DaPPC6gg6A5k4alEggyIvRvRkQ2C5g3oFl/PsLL0yldmFd+YK+jrNVNEvo8A1YbqWkTkllSoFGy1GHBWb8iqU52H56p+H5RZivUnH3bOBwXUyeSNYiqwRCDwssdRRQt+ORTk2juVNdJVet95L4GiJlc4rZfOVWhz+WfilGPW94mQOE/3yyzyv0ez5igmHx6DEH1fm3uowNPNeSGYOdF9eOUdrSZRTK9ewOFFN0RWJJPYyJFhO6BEvrmZDnL0VsIg5z5RnoYzzeKH/gtwDBNHSUM2VWUQYy6jS9L7QHvaZKZczo4yYrD+s2gD3R2gvejOSZs/A1jeWw10y6y2eid0P2sm2P3CEe8ym0V+ylNoWcwh3hTP43CZPSe4EnVG0WI83k9UsPI4pmIaz1WTTXS+iUQntRP4DZWfa5fy8JfMAAAAASUVORK5CYII=", + iconBackground: "#fff", + nativeCurrency: { + decimals: 18, + name: "Base", + symbol: "ETH", + }, + rpcUrls: { + public: { http: [networkConfig.base.rpcUrl] }, + default: { http: [networkConfig.base.rpcUrl] }, + }, + blockExplorers: { + default: { name: "Base", url: networkConfig.base.blockExplorerUrl }, + etherscan: { name: "Base", url: networkConfig.base.blockExplorerUrl }, + }, + testnet: false, +}; + +export const supportedChains = ["arbitrum", "avalanche", "mantle", "base"]; export const supportedChainIds = [43114, 42161, 5000]; @@ -1573,7 +1607,7 @@ export const getProvider = (chain: any) => { return provider; }; -export const getWeb3Signer = async () => { +export const getWeb3Signer = () => { // @ts-ignore if (!window.ethereum) { throw new Error("No web3 provider found."); @@ -1600,13 +1634,13 @@ export const getMeatBalance = async (chain: any, address: any) => { return ethers.utils.formatUnits(balanceRaw.toString(), 6); }; export function addressToBytes32(address: string) { - let newAddress = '0x' + address.substring(2).padStart(64, '0'); + const newAddress = '0x' + address.substring(2).padStart(64, '0'); return newAddress; } export const getLayerZeroFee = async (srcChain: any, dstChain: any, address: any, amount: any) => { try { - let encodedPackedHex = encodePackedUint16Uint256(1, 2000000); + const encodedPackedHex = encodePackedUint16Uint256(1, 2000000); const lsContract = await getMeatContract(srcChain); const lzFees = await lsContract.estimateSendFee( // @ts-ignore @@ -1626,15 +1660,15 @@ export const getLayerZeroFee = async (srcChain: any, dstChain: any, address: any }; function convertToHex(num: number, bytesLength: number) { - let hexNum = num.toString(16); - let hexLength = bytesLength * 2; // 2 hex digits per byte + const hexNum = num.toString(16); + const hexLength = bytesLength * 2; // 2 hex digits per byte return hexNum.padStart(hexLength, '0'); } export function encodePackedUint16Uint256(uint16Val: any, uint256Val: any) { - let hexUint16 = convertToHex(uint16Val, 2); // 2 bytes for uint16 - let hexUint256 = convertToHex(uint256Val, 32); // 32 bytes for uint256 - let value = "0x" + hexUint16 + hexUint256; + const hexUint16 = convertToHex(uint16Val, 2); // 2 bytes for uint16 + const hexUint256 = convertToHex(uint256Val, 32); // 32 bytes for uint256 + const value = "0x" + hexUint16 + hexUint256; return value; } @@ -1654,7 +1688,7 @@ export const bridgeTokens = async (address: any, srcChain: any, dstChain: any, a if (nativeFee === undefined) { throw new Error(`Error getting fee.`); } - let encodedPackedHex = encodePackedUint16Uint256(1, 2000000); + const encodedPackedHex = encodePackedUint16Uint256(1, 2000000); const value = ethers.utils.parseEther((nativeFee).toString()); const callParams = {