UNPKG

@xlink-network/xlink-sdk

Version:
180 lines (178 loc) 5.15 kB
import { fromCorrespondingStacksToken } from "./chunk-D2X23GOD.mjs"; import { props } from "./chunk-EEY7UWSA.mjs"; import { getEVMTokenContractInfo } from "./chunk-A6P6ZEKP.mjs"; import { executeReadonlyCallXLINK, getStacksContractCallInfo, numberFromStacksContractNumber } from "./chunk-BAWSEGXM.mjs"; import { stxTokenContractAddresses } from "./chunk-YFQCRPOW.mjs"; import { getBTCPegInAddress } from "./chunk-LZ7NVYPA.mjs"; import { KnownChainId, KnownTokenId, _allNoLongerSupportedEVMChains } from "./chunk-GZDQGY7B.mjs"; import { checkNever } from "./chunk-E5Y3FGR6.mjs"; import { BigNumber } from "./chunk-KHTJNOQE.mjs"; // src/bitcoinUtils/peggingHelpers.ts import { callReadOnlyFunction } from "@stacks/transactions"; var getBtc2StacksFeeInfo = async (route) => { const stacksContractCallInfo = getStacksContractCallInfo( route.toChain, "btc-peg-in-endpoint-v2-05" ); if (stacksContractCallInfo == null) return; const executeOptions = { deployerAddress: stacksContractCallInfo.deployerAddress, callReadOnlyFunction: (callOptions) => callReadOnlyFunction({ ...callOptions, network: stacksContractCallInfo.network }) }; const resp = await props({ isPaused: executeReadonlyCallXLINK( stacksContractCallInfo.contractName, "is-peg-in-paused", {}, executeOptions ), feeRate: executeReadonlyCallXLINK( stacksContractCallInfo.contractName, "get-peg-in-fee", {}, executeOptions ).then(numberFromStacksContractNumber), minFeeAmount: executeReadonlyCallXLINK( stacksContractCallInfo.contractName, "get-peg-in-min-fee", {}, executeOptions ).then(numberFromStacksContractNumber) }); return { isPaused: resp.isPaused, bridgeToken: route.fromToken, fees: [ { type: "rate", token: route.fromToken, rate: resp.feeRate, minimumAmount: resp.minFeeAmount } ], minBridgeAmount: BigNumber.isZero(resp.minFeeAmount) ? null : resp.minFeeAmount, maxBridgeAmount: null }; }; var getStacks2BtcFeeInfo = async (route) => { const stacksContractCallInfo = getStacksContractCallInfo( route.fromChain, "btc-peg-out-endpoint-v2-01" ); if (stacksContractCallInfo == null) return; const executeOptions = { deployerAddress: stacksContractCallInfo.deployerAddress, callReadOnlyFunction: (callOptions) => callReadOnlyFunction({ ...callOptions, network: stacksContractCallInfo.network }) }; const resp = await props({ isPaused: executeReadonlyCallXLINK( stacksContractCallInfo.contractName, "is-peg-out-paused", {}, executeOptions ), feeRate: executeReadonlyCallXLINK( stacksContractCallInfo.contractName, "get-peg-out-fee", {}, executeOptions ).then(numberFromStacksContractNumber), minFeeAmount: executeReadonlyCallXLINK( stacksContractCallInfo.contractName, "get-peg-out-min-fee", {}, executeOptions ).then(numberFromStacksContractNumber) }); return { isPaused: resp.isPaused, bridgeToken: route.fromToken, fees: [ { type: "rate", token: route.fromToken, rate: resp.feeRate, minimumAmount: resp.minFeeAmount } ], minBridgeAmount: BigNumber.isZero(resp.minFeeAmount) ? null : resp.minFeeAmount, maxBridgeAmount: null }; }; var isSupportedBitcoinRoute = async (ctx, route) => { const { fromChain, toChain, fromToken, toToken } = route; if (fromChain === toChain && fromToken === toToken) { return false; } if (KnownChainId.isEVMChain(fromChain) && _allNoLongerSupportedEVMChains.includes(fromChain)) { return false; } if (KnownChainId.isEVMChain(toChain) && _allNoLongerSupportedEVMChains.includes(toChain)) { return false; } if (!KnownChainId.isBitcoinChain(fromChain) || !KnownTokenId.isBitcoinToken(fromToken)) { return false; } if (!KnownChainId.isKnownChain(toChain)) return false; const pegInAddress = getBTCPegInAddress(fromChain, toChain); if (pegInAddress == null) return false; if (KnownChainId.isBitcoinChain(toChain)) { return false; } if (KnownChainId.isRunesChain(toChain)) { return false; } if (KnownChainId.isBRC20Chain(toChain)) { return false; } if (KnownChainId.isStacksChain(toChain)) { if (!KnownTokenId.isStacksToken(toToken)) return false; return fromToken === KnownTokenId.Bitcoin.BTC && toToken === KnownTokenId.Stacks.aBTC && stxTokenContractAddresses[toToken]?.[toChain] != null; } if (KnownChainId.isEVMChain(toChain)) { if (!KnownTokenId.isEVMToken(toToken)) return false; const info = await getEVMTokenContractInfo(ctx, toChain, toToken); if (info == null) return false; const toEVMTokens = await fromCorrespondingStacksToken( toChain, KnownTokenId.Stacks.aBTC ); return toEVMTokens.includes(toToken); } checkNever(toChain); return false; }; export { getBtc2StacksFeeInfo, getStacks2BtcFeeInfo, isSupportedBitcoinRoute }; //# sourceMappingURL=chunk-UDAD5DCH.mjs.map