Skip to content

Commit

Permalink
feat: base bridge
Browse files Browse the repository at this point in the history
  • Loading branch information
Primata committed Feb 10, 2024
1 parent 9f540df commit d465bd7
Show file tree
Hide file tree
Showing 7 changed files with 64 additions and 16 deletions.
8 changes: 8 additions & 0 deletions components/blockchain/bridge.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -123,6 +123,14 @@ export function Bridge() {
>
Mantle
</option>
<option
value={"base"}
selected={targetChain === "base"}
disabled={chain?.network === "base"}
onSelect={handleChangeTargetChain}
>
Base
</option>
</Form.Select>
</div>
</Form.Group>
Expand Down
4 changes: 2 additions & 2 deletions components/blockchain/wallet-connect-custom.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,7 @@ export const WalletConnectCustom = ({
{chain.iconUrl && (
<img
alt={chain.name ?? "Chain icon"}
src={chain.iconUrl ?? "/mantle-template.png"}
src={chain.iconUrl}
style={{ width: 24, height: 24 }}
/>
)}
Expand All @@ -116,7 +116,7 @@ export const WalletConnectCustom = ({
{
<img
alt={chain.name ?? "Chain icon"}
src={"/mantle-template.png"}
src={chain.iconUrl}
style={{ width: 24, height: 24 }}
/>
}
Expand Down
9 changes: 6 additions & 3 deletions config/networks.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand All @@ -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"
Expand Down
2 changes: 2 additions & 0 deletions integrations/defi-llama/utils/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@ export const chainIdToName: Record<number, string> = {
10: "optimism",
137: "matic-network",
42161: "arbitrum",
8453: "base"

}

export const nameToChainId: Record<string, number> = {
Expand Down
2 changes: 1 addition & 1 deletion lib/generated/blockchain.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// Generated by @wagmi/[email protected] on 12/29/2023 at 5:17:10 PM
// Generated by @wagmi/[email protected] on 2/9/2024 at 10:03:56 PM
import {
useContractEvent,
UseContractEventConfig,
Expand Down
1 change: 1 addition & 0 deletions lib/utils/get-network-color.ts
Original file line number Diff line number Diff line change
@@ -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"
Expand Down
54 changes: 44 additions & 10 deletions lib/utils/layerZero.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 = {
Expand Down Expand Up @@ -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/8APv/6/P/W3//j6v/v8/+Jo/+BnP9miP8wZ/+pu/8iX//D0P/d5P9ZgP+htf+FoP9eg/8UWv86bP/P2v+1xP+7yf93lf9Pef+ar/9xkf9Gc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eCFlEt0qyNvvJy0xCUiXo3DaPPC6gg6A5k4alEggyIvRvRkQ2C5g3oFl/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];

Expand All @@ -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.");
Expand All @@ -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
Expand All @@ -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;
}

Expand All @@ -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 = {
Expand Down

0 comments on commit d465bd7

Please sign in to comment.