mirror of
https://github.com/Brotocol-xyz/bro-sdk.git
synced 2026-01-12 14:54:21 +08:00
feat: add API getStacksTokenFromTerminatingStacksTokenContractAddress
This commit is contained in:
@@ -31,7 +31,10 @@ import {
|
||||
StacksContractAddress,
|
||||
} from "../xlinkSdkUtils/types"
|
||||
import { SDKGlobalContext } from "../xlinkSdkUtils/types.internal"
|
||||
import { getEVMSupportedRoutes } from "./apiHelpers/getEVMSupportedRoutes"
|
||||
import {
|
||||
getEVMSupportedRoutes,
|
||||
getEVMSupportedRoutesByChainType,
|
||||
} from "./apiHelpers/getEVMSupportedRoutes"
|
||||
import { BridgeEndpointAbi } from "./contractAbi/bridgeEndpoint"
|
||||
import { BridgeRegistryAbi } from "./contractAbi/bridgeRegistry"
|
||||
import {
|
||||
@@ -463,34 +466,53 @@ export async function evmTokenToCorrespondingStacksToken(
|
||||
|
||||
export const getTerminatingStacksTokenContractAddress = async (
|
||||
sdkContext: SDKGlobalContext,
|
||||
route: {
|
||||
info: {
|
||||
evmChain: KnownChainId.EVMChain
|
||||
evmToken: KnownTokenId.EVMToken
|
||||
stacksChain: KnownChainId.StacksChain
|
||||
},
|
||||
): Promise<undefined | StacksContractAddress> => {
|
||||
const supportedRoutes = await getEVMSupportedRoutes(
|
||||
sdkContext,
|
||||
route.evmChain,
|
||||
)
|
||||
const supportedRoutes = await getEVMSupportedRoutes(sdkContext, info.evmChain)
|
||||
|
||||
return (
|
||||
supportedRoutes.find(r => r.evmToken === route.evmToken)
|
||||
supportedRoutes.find(r => r.evmToken === info.evmToken)
|
||||
?.proxyStacksTokenContractAddress ?? undefined
|
||||
)
|
||||
}
|
||||
export const getEVMTokenIdFromTerminatingStacksTokenContractAddress = async (
|
||||
|
||||
export const getStacksTokenFromTerminatingStacksTokenContractAddress = async (
|
||||
sdkContext: SDKGlobalContext,
|
||||
route: {
|
||||
info: {
|
||||
stacksChain: KnownChainId.StacksChain
|
||||
stacksTokenAddress: StacksContractAddress
|
||||
},
|
||||
): Promise<undefined | KnownTokenId.StacksToken> => {
|
||||
const routes = await getEVMSupportedRoutesByChainType(
|
||||
sdkContext,
|
||||
info.stacksChain === KnownChainId.Stacks.Mainnet ? "mainnet" : "testnet",
|
||||
)
|
||||
|
||||
return (
|
||||
routes.find(r =>
|
||||
r.proxyStacksTokenContractAddress == null
|
||||
? false
|
||||
: isStacksContractAddressEqual(
|
||||
r.proxyStacksTokenContractAddress,
|
||||
info.stacksTokenAddress,
|
||||
),
|
||||
)?.stacksToken ?? undefined
|
||||
)
|
||||
}
|
||||
|
||||
export const getEVMTokenFromTerminatingStacksTokenContractAddress = async (
|
||||
sdkContext: SDKGlobalContext,
|
||||
info: {
|
||||
evmChain: KnownChainId.EVMChain
|
||||
stacksChain: KnownChainId.StacksChain
|
||||
stacksTokenAddress: StacksContractAddress
|
||||
},
|
||||
): Promise<undefined | KnownTokenId.EVMToken> => {
|
||||
const supportedRoutes = await getEVMSupportedRoutes(
|
||||
sdkContext,
|
||||
route.evmChain,
|
||||
)
|
||||
const supportedRoutes = await getEVMSupportedRoutes(sdkContext, info.evmChain)
|
||||
|
||||
return (
|
||||
supportedRoutes.find(r =>
|
||||
@@ -498,7 +520,7 @@ export const getEVMTokenIdFromTerminatingStacksTokenContractAddress = async (
|
||||
? false
|
||||
: isStacksContractAddressEqual(
|
||||
r.proxyStacksTokenContractAddress,
|
||||
route.stacksTokenAddress,
|
||||
info.stacksTokenAddress,
|
||||
),
|
||||
)?.evmToken ?? undefined
|
||||
)
|
||||
|
||||
@@ -4,7 +4,8 @@
|
||||
*/
|
||||
|
||||
import {
|
||||
getEVMTokenIdFromTerminatingStacksTokenContractAddress as _getEVMTokenIdFromTerminatingStacksTokenContractAddress,
|
||||
getEVMTokenFromTerminatingStacksTokenContractAddress as _getEVMTokenFromTerminatingStacksTokenContractAddress,
|
||||
getStacksTokenFromTerminatingStacksTokenContractAddress as _getStacksTokenFromTerminatingStacksTokenContractAddress,
|
||||
getTerminatingStacksTokenContractAddress as _getTerminatingStacksTokenContractAddress,
|
||||
evmTokenFromCorrespondingStacksToken,
|
||||
evmTokenToCorrespondingStacksToken,
|
||||
@@ -102,7 +103,7 @@ export const getXLinkSDKContext = (
|
||||
|
||||
export const getTerminatingStacksTokenContractAddress = async (
|
||||
sdk: import("./XLinkSDK").XLinkSDK,
|
||||
route: {
|
||||
info: {
|
||||
evmChain: KnownChainId.EVMChain
|
||||
evmToken: KnownTokenId.EVMToken
|
||||
stacksChain: KnownChainId.StacksChain
|
||||
@@ -110,20 +111,32 @@ export const getTerminatingStacksTokenContractAddress = async (
|
||||
): Promise<undefined | StacksContractAddress> => {
|
||||
return _getTerminatingStacksTokenContractAddress(
|
||||
getXLinkSDKContext(sdk),
|
||||
route,
|
||||
info,
|
||||
)
|
||||
}
|
||||
export const getStacksTokenFromTerminatingStacksTokenContractAddress = async (
|
||||
sdk: import("./XLinkSDK").XLinkSDK,
|
||||
info: {
|
||||
stacksChain: KnownChainId.StacksChain
|
||||
stacksTokenAddress: StacksContractAddress
|
||||
},
|
||||
): Promise<undefined | KnownTokenId.StacksToken> => {
|
||||
return _getStacksTokenFromTerminatingStacksTokenContractAddress(
|
||||
getXLinkSDKContext(sdk),
|
||||
info,
|
||||
)
|
||||
}
|
||||
export const getEVMTokenIdFromTerminatingStacksTokenContractAddress = async (
|
||||
sdk: import("./XLinkSDK").XLinkSDK,
|
||||
route: {
|
||||
info: {
|
||||
evmChain: KnownChainId.EVMChain
|
||||
stacksChain: KnownChainId.StacksChain
|
||||
stacksTokenAddress: StacksContractAddress
|
||||
},
|
||||
): Promise<undefined | KnownTokenId.EVMToken> => {
|
||||
return _getEVMTokenIdFromTerminatingStacksTokenContractAddress(
|
||||
return _getEVMTokenFromTerminatingStacksTokenContractAddress(
|
||||
getXLinkSDKContext(sdk),
|
||||
route,
|
||||
info,
|
||||
)
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user