feat: add avalanche chain support

This commit is contained in:
c4605
2025-05-16 21:56:28 +08:00
parent f8a7eff326
commit bda6b787e2
5 changed files with 26 additions and 2 deletions

View File

@@ -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 = (

View File

@@ -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]
}

View File

@@ -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 {

View File

@@ -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:

View File

@@ -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,