mirror of
https://github.com/Brotocol-xyz/bro-sdk.git
synced 2026-01-12 06:44:18 +08:00
feat: add avalanche chain support
This commit is contained in:
@@ -2,6 +2,7 @@ import { Client, createClient, fallback, http } from "viem"
|
||||
import {
|
||||
arbitrum,
|
||||
aurora,
|
||||
avalanche,
|
||||
base,
|
||||
bob,
|
||||
bsc,
|
||||
@@ -14,6 +15,8 @@ import {
|
||||
mode,
|
||||
sepolia,
|
||||
} from "viem/chains"
|
||||
import { entries } from "../utils/objectHelper"
|
||||
import { KnownChainId } from "../utils/types/knownIds"
|
||||
import {
|
||||
ailayer,
|
||||
berachainTestnet,
|
||||
@@ -24,8 +27,6 @@ import {
|
||||
lorenzo,
|
||||
xLayer,
|
||||
} from "./evmChainInfos"
|
||||
import { KnownChainId } from "../utils/types/knownIds"
|
||||
import { entries } from "../utils/objectHelper"
|
||||
|
||||
type EVMChain = KnownChainId.EVMChain
|
||||
const EVMChain = KnownChainId.EVM
|
||||
@@ -153,6 +154,12 @@ export const defaultEvmClients: Partial<Record<KnownChainId.EVMChain, Client>> =
|
||||
transport: http(),
|
||||
batch: { multicall: true },
|
||||
}),
|
||||
|
||||
[EVMChain.Avalanche]: createClient({
|
||||
chain: avalanche,
|
||||
transport: http(),
|
||||
batch: { multicall: true },
|
||||
}),
|
||||
} satisfies Record<Exclude<EVMChain, typeof EVMChain.BitboyTestnet>, Client>
|
||||
|
||||
export const evmChainIdFromKnownChainId = (
|
||||
|
||||
@@ -56,6 +56,8 @@ export function contractAssignedChainIdFromKnownChain(
|
||||
return 15n
|
||||
case KnownChainId.EVM.Base:
|
||||
return 16n
|
||||
case KnownChainId.EVM.Avalanche:
|
||||
return 17n
|
||||
case KnownChainId.BRC20.Mainnet:
|
||||
case KnownChainId.BRC20.Testnet:
|
||||
return 1001n
|
||||
@@ -166,6 +168,11 @@ export function contractAssignedChainIdToKnownChain(
|
||||
}
|
||||
assertExclude(resPossibilities, KnownChainId.EVM.Base)
|
||||
|
||||
if (chainId === 17n) {
|
||||
return [KnownChainId.EVM.Avalanche]
|
||||
}
|
||||
assertExclude(resPossibilities, KnownChainId.EVM.Avalanche)
|
||||
|
||||
if (chainId === 1001n) {
|
||||
return [KnownChainId.BRC20.Mainnet, KnownChainId.BRC20.Testnet]
|
||||
}
|
||||
|
||||
@@ -30,6 +30,7 @@ export const possibleSwapOnEVMChains = [
|
||||
KnownChainId.EVM.Arbitrum,
|
||||
KnownChainId.EVM.Linea,
|
||||
KnownChainId.EVM.BSC,
|
||||
KnownChainId.EVM.Avalanche,
|
||||
] satisfies KnownChainId.EVMChain[]
|
||||
|
||||
export interface EVMDexAggregatorSwapParameters {
|
||||
|
||||
@@ -183,6 +183,8 @@ function mapSDKChainIdToKyberChainId(
|
||||
return "base"
|
||||
case KnownChainId.EVM.Linea:
|
||||
return "linea"
|
||||
case KnownChainId.EVM.Avalanche:
|
||||
return "avalanche"
|
||||
case KnownChainId.EVM.Sepolia:
|
||||
case KnownChainId.EVM.BSCTestnet:
|
||||
case KnownChainId.EVM.CoreDAOTestnet:
|
||||
|
||||
@@ -348,6 +348,12 @@ export namespace KnownChainId {
|
||||
// export const Bera = chainId("evm-bera")
|
||||
/** Represents the Bera testnet chain ID. */
|
||||
export const BeraTestnet = chainId("evm-bera-testnet")
|
||||
|
||||
// Avalanche
|
||||
/** Represents the Avalanche mainnet chain ID. */
|
||||
export const Avalanche = chainId("evm-avalanche")
|
||||
/** Represents the Avalanche testnet chain ID. */
|
||||
// export const AvalancheTestnet = chainId("evm-avalanche-testnet")
|
||||
}
|
||||
/** Represents a mainnet EVM-compatible blockchain network. */
|
||||
export type EVMMainnetChain = (typeof _allKnownEVMMainnetChains)[number]
|
||||
@@ -422,6 +428,7 @@ export const _allKnownEVMMainnetChains = [
|
||||
KnownChainId.EVM.Manta,
|
||||
KnownChainId.EVM.Linea,
|
||||
KnownChainId.EVM.Base,
|
||||
KnownChainId.EVM.Avalanche,
|
||||
] as const
|
||||
export const _allKnownEVMTestnetChains = [
|
||||
KnownChainId.EVM.Sepolia,
|
||||
|
||||
Reference in New Issue
Block a user