mirror of
https://github.com/Brotocol-xyz/bro-sdk.git
synced 2026-01-12 14:54:21 +08:00
feat: add uBTC token support
This commit is contained in:
@@ -1,7 +1,10 @@
|
||||
import { XLinkSDK } from "../src"
|
||||
import { KnownRoute } from "../src/utils/buildSupportedRoutes"
|
||||
|
||||
async function main(): Promise<void> {
|
||||
async function print(matchers: {
|
||||
chain: string[]
|
||||
token: string[]
|
||||
}): Promise<void> {
|
||||
const sdk = new XLinkSDK()
|
||||
const supportedRoutes = await sdk.getSupportedRoutes()
|
||||
|
||||
@@ -14,11 +17,44 @@ async function main(): Promise<void> {
|
||||
|
||||
const groupEntries = Object.entries(group)
|
||||
for (const [group, routes] of groupEntries) {
|
||||
const matchedRoutes = routes.filter(r => runMatchers(r))
|
||||
if (matchedRoutes.length === 0) continue
|
||||
|
||||
console.log(group)
|
||||
for (const route of routes) {
|
||||
for (const route of matchedRoutes) {
|
||||
console.log(` ${route.fromToken} -> ${route.toToken}`)
|
||||
}
|
||||
}
|
||||
|
||||
function runMatchers(route: KnownRoute): boolean {
|
||||
if (matchers.chain.length === 0 && matchers.token.length === 0) return true
|
||||
|
||||
return (
|
||||
matchers.chain.some(c => route.fromChain.includes(c)) ||
|
||||
matchers.token.some(t => route.fromToken.includes(t))
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
main().catch(console.error)
|
||||
async function main(command: string[], args: string[]): Promise<void> {
|
||||
if (args.some(a => a === "-h" || a === "--help")) {
|
||||
console.log(`Usage: ${command.join(" ")} [chain:<chain>] [token:<token>]`)
|
||||
process.exit(0)
|
||||
}
|
||||
|
||||
const matchers = {
|
||||
chain: [] as string[],
|
||||
token: [] as string[],
|
||||
}
|
||||
args.forEach(arg => {
|
||||
if (arg.startsWith("chain:")) {
|
||||
matchers.chain.push(arg.split(":")[1])
|
||||
} else if (arg.startsWith("token:")) {
|
||||
matchers.token.push(arg.split(":")[1])
|
||||
}
|
||||
})
|
||||
|
||||
await print(matchers).catch(console.error)
|
||||
}
|
||||
|
||||
main(process.argv.slice(0, 2), process.argv.slice(2)).catch(console.error)
|
||||
|
||||
@@ -78,6 +78,8 @@ export const evmContractAddresses: Record<EVMChain, EVMOnChainAddresses> = {
|
||||
[EVMToken.vLiSTX]: "0x70727228DB8C7491bF0aD42C180dbf8D95B257e2",
|
||||
// https://github.com/xlink-network/xlink/blob/87aaca8ef74dea59a322eb31c92311d2aa25d6bb/packages/libs/commons/src/lib/utils/config.ts#L216
|
||||
[EVMToken.vLiALEX]: "0xcd5ED0B0b1e107D331833715932B4a596bFbA378",
|
||||
// https://t.me/c/1599543687/59542
|
||||
[EVMToken.uBTC]: "0x796e4D53067FF374B89b2Ac101ce0c1f72ccaAc2",
|
||||
},
|
||||
// https://t.me/c/1599543687/54380
|
||||
[EVMChain.BOB]: {
|
||||
@@ -133,6 +135,8 @@ export const evmContractAddresses: Record<EVMChain, EVMOnChainAddresses> = {
|
||||
[EVMToken.ALEX]: "0x1c5aC43f0b30462C5dDEB1A2152E639BbDFe38eA",
|
||||
[EVMToken.vLiSTX]: "0x4CeFE0F8FcEa50c982AAbF766e67F2B0e7845542",
|
||||
[EVMToken.vLiALEX]: "0x822278fb6ece06667AE5207D0af12a7F60CDf13A",
|
||||
// https://t.me/c/1599543687/59542
|
||||
[EVMToken.wuBTC]: "0xd0d1b59CA62cE194E882455Fd36632d6277b192a",
|
||||
},
|
||||
// https://t.me/c/1599543687/57439
|
||||
[EVMChain.AILayer]: {
|
||||
|
||||
@@ -323,6 +323,36 @@ export async function fromCorrespondingStacksCurrency(
|
||||
assertExclude(restEVMTokenPossibilities, EVMToken.WBTC)
|
||||
assertExclude(restEVMTokenPossibilities, EVMToken.BTCB)
|
||||
|
||||
if (stacksToken === StacksToken.uBTC) {
|
||||
switch (toChain) {
|
||||
case EVMChain.Bsquared:
|
||||
return EVMToken.uBTC
|
||||
case EVMChain.Ethereum:
|
||||
case EVMChain.Sepolia:
|
||||
case EVMChain.BSC:
|
||||
case EVMChain.BSCTestnet:
|
||||
case EVMChain.CoreDAO:
|
||||
case EVMChain.CoreDAOTestnet:
|
||||
case EVMChain.BOB:
|
||||
case EVMChain.Bitlayer:
|
||||
case EVMChain.Lorenzo:
|
||||
case EVMChain.Merlin:
|
||||
case EVMChain.AILayer:
|
||||
case EVMChain.Mode:
|
||||
case EVMChain.XLayer:
|
||||
case EVMChain.Arbitrum:
|
||||
case EVMChain.Aurora:
|
||||
case EVMChain.BisonTestnet:
|
||||
case EVMChain.BitboyTestnet:
|
||||
return EVMToken.wuBTC
|
||||
default:
|
||||
checkNever(toChain)
|
||||
}
|
||||
}
|
||||
assertExclude(restEVMTokenPossibilities, EVMToken.uBTC)
|
||||
assertExclude(restEVMTokenPossibilities, EVMToken.wuBTC)
|
||||
|
||||
checkNever(restEVMTokenPossibilities)
|
||||
checkNever(restEVMTokenPossibilities)
|
||||
return undefined
|
||||
}
|
||||
@@ -350,6 +380,9 @@ export async function toCorrespondingStacksCurrency(
|
||||
case EVMToken.WBTC:
|
||||
case EVMToken.aBTC:
|
||||
return StacksToken.aBTC
|
||||
case EVMToken.uBTC:
|
||||
case EVMToken.wuBTC:
|
||||
return StacksToken.uBTC
|
||||
default:
|
||||
checkNever(evmToken)
|
||||
return
|
||||
|
||||
@@ -198,6 +198,8 @@ const _getOnChainConfigsImpl = async (
|
||||
ONCHAIN_CONFIG_KEY.TOKEN_LUNR,
|
||||
ONCHAIN_CONFIG_KEY.TOKEN_SKO,
|
||||
ONCHAIN_CONFIG_KEY.TOKEN_SUSDT,
|
||||
ONCHAIN_CONFIG_KEY.TOKEN_UBTC,
|
||||
ONCHAIN_CONFIG_KEY.TOKEN_WUBTC,
|
||||
],
|
||||
],
|
||||
}).catch(err => {
|
||||
@@ -228,6 +230,8 @@ const _getOnChainConfigsImpl = async (
|
||||
[EVMToken.LUNR]: maybeAddress(configs[9]),
|
||||
[EVMToken.SKO]: maybeAddress(configs[10]),
|
||||
[EVMToken.sUSDT]: maybeAddress(configs[11]),
|
||||
[EVMToken.uBTC]: maybeAddress(configs[12]),
|
||||
[EVMToken.wuBTC]: maybeAddress(configs[13]),
|
||||
}
|
||||
}
|
||||
function maybeAddress(value: string | null): Address | undefined {
|
||||
@@ -237,10 +241,11 @@ function maybeAddress(value: string | null): Address | undefined {
|
||||
if (value === zeroAddress) return undefined
|
||||
return value
|
||||
}
|
||||
/**
|
||||
* https://t.me/c/1599543687/57298
|
||||
*/
|
||||
|
||||
enum ONCHAIN_CONFIG_KEY {
|
||||
/**
|
||||
* https://t.me/c/1599543687/57298
|
||||
*/
|
||||
ENDPOINT = "ENDPOINT",
|
||||
REGISTRY = "REGISTRY",
|
||||
TOKEN_ABTC = "TOKEN_ABTC",
|
||||
@@ -258,4 +263,8 @@ enum ONCHAIN_CONFIG_KEY {
|
||||
MIGRATE_BOB = "MIGRATE_BOB",
|
||||
MIGRATE_BOB_L2 = "MIGRATE_BOB_L2",
|
||||
MIGRATE_BOB_L2_S = "MIGRATE_BOB_L2_S",
|
||||
|
||||
// https://github.com/xlink-network/xlink/pull/299/commits/22b23c9ff3ea65eeb7c632db4255afe803f97fef#diff-8302902f9863ee3c7928a0fa6eb6ca22edd10f5553708459cdd072c1ea3ef696
|
||||
TOKEN_UBTC = "TOKEN_UBTC",
|
||||
TOKEN_WUBTC = "TOKEN_WUBTC",
|
||||
}
|
||||
|
||||
@@ -90,4 +90,14 @@ export const stxTokenContractAddresses: Record<
|
||||
contractName: "token-wvlialex",
|
||||
},
|
||||
},
|
||||
[KnownTokenId.Stacks.uBTC]: {
|
||||
[KnownChainId.Stacks.Mainnet]: {
|
||||
deployerAddress: "SP673Z4BPB4R73359K9HE55F2X91V5BJTN5SXZ5T",
|
||||
contractName: "token-ubtc",
|
||||
},
|
||||
[KnownChainId.Stacks.Testnet]: {
|
||||
deployerAddress: xlinkContractsDeployerTestnet,
|
||||
contractName: "token-ubtc",
|
||||
},
|
||||
},
|
||||
}
|
||||
|
||||
@@ -50,6 +50,8 @@ export namespace KnownTokenId {
|
||||
export const vLiSTX = tokenId("evm-vlistx")
|
||||
/** Represents the vLiALEX token ID on EVM-compatible blockchains. */
|
||||
export const vLiALEX = tokenId("evm-vlialex")
|
||||
export const uBTC = tokenId("evm-ubtc")
|
||||
export const wuBTC = tokenId("evm-wubtc")
|
||||
}
|
||||
/** This type includes all known tokens on EVM-compatible blockchains. */
|
||||
export type EVMToken = (typeof _allKnownEVMTokens)[number]
|
||||
@@ -73,6 +75,7 @@ export namespace KnownTokenId {
|
||||
export const vLiSTX = tokenId("stx-vlistx")
|
||||
/** Represents the vLiALEX token ID on the Stacks blockchain. */
|
||||
export const vLiALEX = tokenId("stx-vlialex")
|
||||
export const uBTC = tokenId("stx-ubtc")
|
||||
}
|
||||
/** This type includes all known tokens on the Stacks blockchain. */
|
||||
export type StacksToken = (typeof _allKnownStacksTokens)[number]
|
||||
|
||||
@@ -64,6 +64,8 @@ export const supportedRoutes = buildSupportedRoutes(
|
||||
[KnownTokenId.EVM.ALEX, KnownTokenId.Stacks.ALEX],
|
||||
[KnownTokenId.EVM.vLiSTX, KnownTokenId.Stacks.vLiSTX],
|
||||
[KnownTokenId.EVM.vLiALEX, KnownTokenId.Stacks.vLiALEX],
|
||||
[KnownTokenId.EVM.uBTC, KnownTokenId.Stacks.uBTC],
|
||||
[KnownTokenId.EVM.wuBTC, KnownTokenId.Stacks.uBTC],
|
||||
],
|
||||
),
|
||||
...defineRoute(
|
||||
@@ -96,6 +98,11 @@ export const supportedRoutes = buildSupportedRoutes(
|
||||
[KnownTokenId.EVM.ALEX, KnownTokenId.EVM.ALEX],
|
||||
[KnownTokenId.EVM.vLiSTX, KnownTokenId.EVM.vLiSTX],
|
||||
[KnownTokenId.EVM.vLiALEX, KnownTokenId.EVM.vLiALEX],
|
||||
|
||||
[KnownTokenId.EVM.uBTC, KnownTokenId.EVM.uBTC],
|
||||
[KnownTokenId.EVM.wuBTC, KnownTokenId.EVM.wuBTC],
|
||||
[KnownTokenId.EVM.uBTC, KnownTokenId.EVM.wuBTC],
|
||||
[KnownTokenId.EVM.wuBTC, KnownTokenId.EVM.uBTC],
|
||||
],
|
||||
),
|
||||
|
||||
|
||||
@@ -48,6 +48,8 @@ export const supportedRoutes = buildSupportedRoutes(
|
||||
[KnownTokenId.Stacks.ALEX, KnownTokenId.EVM.ALEX],
|
||||
[KnownTokenId.Stacks.vLiSTX, KnownTokenId.EVM.vLiSTX],
|
||||
[KnownTokenId.Stacks.vLiALEX, KnownTokenId.EVM.vLiALEX],
|
||||
[KnownTokenId.Stacks.uBTC, KnownTokenId.EVM.uBTC],
|
||||
[KnownTokenId.Stacks.uBTC, KnownTokenId.EVM.wuBTC],
|
||||
],
|
||||
),
|
||||
|
||||
|
||||
Reference in New Issue
Block a user