@lifi/sdk-provider-bitcoin 4.0.0-beta.7 → 4.0.0-beta.9
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/cjs/BitcoinProvider.js.map +1 -1
- package/dist/cjs/actions/getBitcoinBalance.js.map +1 -1
- package/dist/cjs/actions/resolveBitcoinAddress.js.map +1 -1
- package/dist/cjs/client/publicClient.js.map +1 -1
- package/dist/cjs/core/BitcoinStepExecutor.js.map +1 -1
- package/dist/cjs/core/tasks/BitcoinSignAndExecuteTask.js.map +1 -1
- package/dist/cjs/core/tasks/BitcoinWaitForTransactionTask.js.map +1 -1
- package/dist/cjs/errors/parseBitcoinErrors.js.map +1 -1
- package/dist/cjs/types.js.map +1 -1
- package/dist/cjs/utils/isPsbtFinalized.js.map +1 -1
- package/dist/cjs/utils/toBigmiChainId.js.map +1 -1
- package/dist/cjs/version.d.ts +1 -1
- package/dist/cjs/version.js +1 -1
- package/dist/cjs/version.js.map +1 -1
- package/dist/esm/BitcoinProvider.js.map +1 -1
- package/dist/esm/actions/getBitcoinBalance.js.map +1 -1
- package/dist/esm/actions/resolveBitcoinAddress.js.map +1 -1
- package/dist/esm/client/publicClient.js.map +1 -1
- package/dist/esm/core/BitcoinStepExecutor.js.map +1 -1
- package/dist/esm/core/tasks/BitcoinSignAndExecuteTask.js.map +1 -1
- package/dist/esm/core/tasks/BitcoinWaitForTransactionTask.js.map +1 -1
- package/dist/esm/errors/parseBitcoinErrors.js.map +1 -1
- package/dist/esm/types.js.map +1 -1
- package/dist/esm/utils/isPsbtFinalized.js.map +1 -1
- package/dist/esm/utils/toBigmiChainId.js.map +1 -1
- package/dist/esm/version.d.ts +1 -1
- package/dist/esm/version.js +1 -1
- package/dist/esm/version.js.map +1 -1
- package/package.json +2 -2
- package/src/version.ts +1 -1
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"BitcoinProvider.js","names":["ChainType","isUTXOAddress","resolveBitcoinAddress","getBitcoinBalance","BitcoinStepExecutor"],"sources":["../../src/BitcoinProvider.ts"],"sourcesContent":["import { isUTXOAddress } from '@bigmi/core'\nimport { ChainType, type StepExecutorOptions } from '@lifi/sdk'\nimport { getBitcoinBalance } from './actions/getBitcoinBalance.js'\nimport { resolveBitcoinAddress } from './actions/resolveBitcoinAddress.js'\nimport { BitcoinStepExecutor } from './core/BitcoinStepExecutor.js'\nimport type { BitcoinProviderOptions, BitcoinSDKProvider } from './types.js'\n\nexport function BitcoinProvider(\n options?: BitcoinProviderOptions\n): BitcoinSDKProvider {\n const _options: BitcoinProviderOptions = options ?? {}\n return {\n get type() {\n return ChainType.UTXO\n },\n isAddress: isUTXOAddress,\n resolveAddress: resolveBitcoinAddress,\n getBalance: getBitcoinBalance,\n async getStepExecutor(\n options: StepExecutorOptions\n ): Promise<BitcoinStepExecutor> {\n if (!_options.getWalletClient) {\n throw new Error('Client is not provided.')\n }\n\n const walletClient = await _options.getWalletClient()\n\n const executor = new BitcoinStepExecutor({\n client: walletClient,\n routeId: options.routeId,\n executionOptions: {\n ...options.executionOptions,\n },\n })\n\n return executor\n },\n setOptions(options: BitcoinProviderOptions) {\n Object.assign(_options, options)\n },\n }\n}\n"],"mappings":";;;;;;;;AAOA,SAAgB,gBACd,SACoB;CACpB,MAAM,WAAmC,WAAW,EAAE;
|
|
1
|
+
{"version":3,"file":"BitcoinProvider.js","names":["ChainType","isUTXOAddress","resolveBitcoinAddress","getBitcoinBalance","BitcoinStepExecutor"],"sources":["../../src/BitcoinProvider.ts"],"sourcesContent":["import { isUTXOAddress } from '@bigmi/core'\nimport { ChainType, type StepExecutorOptions } from '@lifi/sdk'\nimport { getBitcoinBalance } from './actions/getBitcoinBalance.js'\nimport { resolveBitcoinAddress } from './actions/resolveBitcoinAddress.js'\nimport { BitcoinStepExecutor } from './core/BitcoinStepExecutor.js'\nimport type { BitcoinProviderOptions, BitcoinSDKProvider } from './types.js'\n\nexport function BitcoinProvider(\n options?: BitcoinProviderOptions\n): BitcoinSDKProvider {\n const _options: BitcoinProviderOptions = options ?? {}\n return {\n get type() {\n return ChainType.UTXO\n },\n isAddress: isUTXOAddress,\n resolveAddress: resolveBitcoinAddress,\n getBalance: getBitcoinBalance,\n async getStepExecutor(\n options: StepExecutorOptions\n ): Promise<BitcoinStepExecutor> {\n if (!_options.getWalletClient) {\n throw new Error('Client is not provided.')\n }\n\n const walletClient = await _options.getWalletClient()\n\n const executor = new BitcoinStepExecutor({\n client: walletClient,\n routeId: options.routeId,\n executionOptions: {\n ...options.executionOptions,\n },\n })\n\n return executor\n },\n setOptions(options: BitcoinProviderOptions) {\n Object.assign(_options, options)\n },\n }\n}\n"],"mappings":";;;;;;;;AAOA,SAAgB,gBACd,SACoB;CACpB,MAAM,WAAmC,WAAW,EAAE;CACtD,OAAO;EACL,IAAI,OAAO;GACT,OAAOA,UAAAA,UAAU;;EAEnB,WAAWC,YAAAA;EACX,gBAAgBC,sCAAAA;EAChB,YAAYC,kCAAAA;EACZ,MAAM,gBACJ,SAC8B;GAC9B,IAAI,CAAC,SAAS,iBACZ,MAAM,IAAI,MAAM,0BAA0B;GAa5C,OAAO,IARcC,iCAAAA,oBAAoB;IACvC,QAAQ,MAHiB,SAAS,iBAAiB;IAInD,SAAS,QAAQ;IACjB,kBAAkB,EAChB,GAAG,QAAQ,kBACZ;IACF,CAEc;;EAEjB,WAAW,SAAiC;GAC1C,OAAO,OAAO,UAAU,QAAQ;;EAEnC"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"getBitcoinBalance.js","names":["getBitcoinPublicClient","ChainId"],"sources":["../../../src/actions/getBitcoinBalance.ts"],"sourcesContent":["import {\n ChainId,\n type SDKClient,\n type Token,\n type TokenAmount,\n} from '@lifi/sdk'\nimport { getBitcoinPublicClient } from '../client/publicClient.js'\n\nexport const getBitcoinBalance = async (\n client: SDKClient,\n walletAddress: string,\n tokens: Token[]\n): Promise<TokenAmount[]> => {\n if (tokens.length === 0) {\n return []\n }\n const { chainId } = tokens[0]\n for (const token of tokens) {\n if (token.chainId !== chainId) {\n console.warn('Requested tokens have to be on the same chain.')\n }\n }\n const bigmiClient = await getBitcoinPublicClient(client, ChainId.BTC)\n const [balance, blockCount] = await Promise.allSettled([\n bigmiClient.getBalance({ address: walletAddress }),\n bigmiClient.getBlockCount(),\n ])\n\n const blockNumber =\n blockCount.status === 'fulfilled' ? BigInt(blockCount.value) : 0n\n\n if (balance.status !== 'fulfilled') {\n // RPC failed — leave amount undefined so callers can distinguish\n // an unknown balance from a known zero.\n return tokens.map((token) => ({\n ...token,\n blockNumber,\n }))\n }\n\n return tokens.map((token) => ({\n ...token,\n amount: balance.value,\n blockNumber,\n }))\n}\n"],"mappings":";;;;;AAQA,MAAa,oBAAoB,OAC/B,QACA,eACA,WAC2B;
|
|
1
|
+
{"version":3,"file":"getBitcoinBalance.js","names":["getBitcoinPublicClient","ChainId"],"sources":["../../../src/actions/getBitcoinBalance.ts"],"sourcesContent":["import {\n ChainId,\n type SDKClient,\n type Token,\n type TokenAmount,\n} from '@lifi/sdk'\nimport { getBitcoinPublicClient } from '../client/publicClient.js'\n\nexport const getBitcoinBalance = async (\n client: SDKClient,\n walletAddress: string,\n tokens: Token[]\n): Promise<TokenAmount[]> => {\n if (tokens.length === 0) {\n return []\n }\n const { chainId } = tokens[0]\n for (const token of tokens) {\n if (token.chainId !== chainId) {\n console.warn('Requested tokens have to be on the same chain.')\n }\n }\n const bigmiClient = await getBitcoinPublicClient(client, ChainId.BTC)\n const [balance, blockCount] = await Promise.allSettled([\n bigmiClient.getBalance({ address: walletAddress }),\n bigmiClient.getBlockCount(),\n ])\n\n const blockNumber =\n blockCount.status === 'fulfilled' ? BigInt(blockCount.value) : 0n\n\n if (balance.status !== 'fulfilled') {\n // RPC failed — leave amount undefined so callers can distinguish\n // an unknown balance from a known zero.\n return tokens.map((token) => ({\n ...token,\n blockNumber,\n }))\n }\n\n return tokens.map((token) => ({\n ...token,\n amount: balance.value,\n blockNumber,\n }))\n}\n"],"mappings":";;;;;AAQA,MAAa,oBAAoB,OAC/B,QACA,eACA,WAC2B;CAC3B,IAAI,OAAO,WAAW,GACpB,OAAO,EAAE;CAEX,MAAM,EAAE,YAAY,OAAO;CAC3B,KAAK,MAAM,SAAS,QAClB,IAAI,MAAM,YAAY,SACpB,QAAQ,KAAK,iDAAiD;CAGlE,MAAM,cAAc,MAAMA,4BAAAA,uBAAuB,QAAQC,UAAAA,QAAQ,IAAI;CACrE,MAAM,CAAC,SAAS,cAAc,MAAM,QAAQ,WAAW,CACrD,YAAY,WAAW,EAAE,SAAS,eAAe,CAAC,EAClD,YAAY,eAAe,CAC5B,CAAC;CAEF,MAAM,cACJ,WAAW,WAAW,cAAc,OAAO,WAAW,MAAM,GAAG;CAEjE,IAAI,QAAQ,WAAW,aAGrB,OAAO,OAAO,KAAK,WAAW;EAC5B,GAAG;EACH;EACD,EAAE;CAGL,OAAO,OAAO,KAAK,WAAW;EAC5B,GAAG;EACH,QAAQ,QAAQ;EAChB;EACD,EAAE"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"resolveBitcoinAddress.js","names":[],"sources":["../../../src/actions/resolveBitcoinAddress.ts"],"sourcesContent":["export async function resolveBitcoinAddress(\n name: string\n): Promise<string | undefined> {\n // Not supported on UTXO yet\n return name\n}\n"],"mappings":";;AAAA,eAAsB,sBACpB,MAC6B;
|
|
1
|
+
{"version":3,"file":"resolveBitcoinAddress.js","names":[],"sources":["../../../src/actions/resolveBitcoinAddress.ts"],"sourcesContent":["export async function resolveBitcoinAddress(\n name: string\n): Promise<string | undefined> {\n // Not supported on UTXO yet\n return name\n}\n"],"mappings":";;AAAA,eAAsB,sBACpB,MAC6B;CAE7B,OAAO"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"publicClient.js","names":["toBigmiChainId","publicActions","walletActions"],"sources":["../../../src/client/publicClient.ts"],"sourcesContent":["import {\n type Account,\n blockchair,\n blockcypher,\n type Chain,\n type Client,\n createClient,\n type FallbackTransport,\n fallback,\n type HttpTransport,\n http,\n mempool,\n type PublicActions,\n publicActions,\n rpcSchema,\n type UTXOSchema,\n type WalletActions,\n walletActions,\n} from '@bigmi/core'\nimport type { SDKClient } from '@lifi/sdk'\nimport { toBigmiChainId } from '../utils/toBigmiChainId.js'\n\nexport type PublicClient = Client<\n FallbackTransport<readonly HttpTransport[]>,\n Chain,\n Account | undefined,\n UTXOSchema,\n PublicActions & WalletActions\n>\n\n// cached providers\nconst publicClients: Record<number, PublicClient> = {}\n\n/**\n * Get an instance of a provider for a specific chain\n * @param client - The SDK client\n * @param chainId - Id of the chain the provider is for\n * @returns The public client for the given chain\n */\nexport const getBitcoinPublicClient = async (\n client: SDKClient,\n chainId: number\n): Promise<PublicClient> => {\n if (!publicClients[chainId]) {\n const urls = await client.getRpcUrlsByChainId(chainId)\n const fallbackTransports = urls.map((url) =>\n http(url, {\n fetchOptions: {\n method: 'POST',\n },\n })\n )\n const _chain = await client.getChainById(chainId)\n const chain: Chain = {\n ..._chain,\n ..._chain.metamask,\n id: toBigmiChainId(_chain.id),\n name: _chain.metamask.chainName,\n rpcUrls: {\n default: { http: _chain.metamask.rpcUrls },\n public: { http: _chain.metamask.rpcUrls },\n },\n }\n const bigmiClient = createClient({\n chain,\n rpcSchema: rpcSchema<UTXOSchema>(),\n transport: fallback([\n blockchair(),\n blockcypher(),\n mempool(),\n ...fallbackTransports,\n ]),\n pollingInterval: 10_000,\n })\n .extend(publicActions)\n .extend(walletActions)\n publicClients[chainId] = bigmiClient\n }\n\n if (!publicClients[chainId]) {\n throw new Error(`Unable to configure provider for chain ${chainId}`)\n }\n\n return publicClients[chainId]\n}\n"],"mappings":";;;;;AA+BA,MAAM,gBAA8C,EAAE;;;;;;;AAQtD,MAAa,yBAAyB,OACpC,QACA,YAC0B;
|
|
1
|
+
{"version":3,"file":"publicClient.js","names":["toBigmiChainId","publicActions","walletActions"],"sources":["../../../src/client/publicClient.ts"],"sourcesContent":["import {\n type Account,\n blockchair,\n blockcypher,\n type Chain,\n type Client,\n createClient,\n type FallbackTransport,\n fallback,\n type HttpTransport,\n http,\n mempool,\n type PublicActions,\n publicActions,\n rpcSchema,\n type UTXOSchema,\n type WalletActions,\n walletActions,\n} from '@bigmi/core'\nimport type { SDKClient } from '@lifi/sdk'\nimport { toBigmiChainId } from '../utils/toBigmiChainId.js'\n\nexport type PublicClient = Client<\n FallbackTransport<readonly HttpTransport[]>,\n Chain,\n Account | undefined,\n UTXOSchema,\n PublicActions & WalletActions\n>\n\n// cached providers\nconst publicClients: Record<number, PublicClient> = {}\n\n/**\n * Get an instance of a provider for a specific chain\n * @param client - The SDK client\n * @param chainId - Id of the chain the provider is for\n * @returns The public client for the given chain\n */\nexport const getBitcoinPublicClient = async (\n client: SDKClient,\n chainId: number\n): Promise<PublicClient> => {\n if (!publicClients[chainId]) {\n const urls = await client.getRpcUrlsByChainId(chainId)\n const fallbackTransports = urls.map((url) =>\n http(url, {\n fetchOptions: {\n method: 'POST',\n },\n })\n )\n const _chain = await client.getChainById(chainId)\n const chain: Chain = {\n ..._chain,\n ..._chain.metamask,\n id: toBigmiChainId(_chain.id),\n name: _chain.metamask.chainName,\n rpcUrls: {\n default: { http: _chain.metamask.rpcUrls },\n public: { http: _chain.metamask.rpcUrls },\n },\n }\n const bigmiClient = createClient({\n chain,\n rpcSchema: rpcSchema<UTXOSchema>(),\n transport: fallback([\n blockchair(),\n blockcypher(),\n mempool(),\n ...fallbackTransports,\n ]),\n pollingInterval: 10_000,\n })\n .extend(publicActions)\n .extend(walletActions)\n publicClients[chainId] = bigmiClient\n }\n\n if (!publicClients[chainId]) {\n throw new Error(`Unable to configure provider for chain ${chainId}`)\n }\n\n return publicClients[chainId]\n}\n"],"mappings":";;;;;AA+BA,MAAM,gBAA8C,EAAE;;;;;;;AAQtD,MAAa,yBAAyB,OACpC,QACA,YAC0B;CAC1B,IAAI,CAAC,cAAc,UAAU;EAE3B,MAAM,sBAAqB,MADR,OAAO,oBAAoB,QAAQ,EACtB,KAAK,SAAA,GAAA,YAAA,MAC9B,KAAK,EACR,cAAc,EACZ,QAAQ,QACT,EACF,CAAC,CACH;EACD,MAAM,SAAS,MAAM,OAAO,aAAa,QAAQ;EAwBjD,cAAc,YAAA,GAAA,YAAA,cAbmB;GAC/B,OAAA;IAVA,GAAG;IACH,GAAG,OAAO;IACV,IAAIA,6BAAAA,eAAe,OAAO,GAAG;IAC7B,MAAM,OAAO,SAAS;IACtB,SAAS;KACP,SAAS,EAAE,MAAM,OAAO,SAAS,SAAS;KAC1C,QAAQ,EAAE,MAAM,OAAO,SAAS,SAAS;KAC1C;IAGI;GACL,YAAA,GAAA,YAAA,YAAkC;GAClC,YAAA,GAAA,YAAA,UAAoB;iCACN;kCACC;8BACJ;IACT,GAAG;IACJ,CAAC;GACF,iBAAiB;GAClB,CAAC,CACC,OAAOC,YAAAA,cAAc,CACrB,OAAOC,YAAAA,cAC0B;;CAGtC,IAAI,CAAC,cAAc,UACjB,MAAM,IAAI,MAAM,0CAA0C,UAAU;CAGtE,OAAO,cAAc"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"BitcoinStepExecutor.js","names":["BaseStepExecutor","TransactionError","LiFiErrorCode","CheckBalanceTask","PrepareTransactionTask","BitcoinSignAndExecuteTask","BitcoinWaitForTransactionTask","WaitForTransactionStatusTask","TaskPipeline","parseBitcoinErrors","getBitcoinPublicClient"],"sources":["../../../src/core/BitcoinStepExecutor.ts"],"sourcesContent":["import type { Client } from '@bigmi/core'\nimport {\n BaseStepExecutor,\n CheckBalanceTask,\n type ExecutionAction,\n LiFiErrorCode,\n type LiFiStepExtended,\n PrepareTransactionTask,\n type SDKError,\n type StepExecutorBaseContext,\n type StepExecutorOptions,\n TaskPipeline,\n TransactionError,\n WaitForTransactionStatusTask,\n} from '@lifi/sdk'\nimport { getBitcoinPublicClient } from '../client/publicClient.js'\nimport { parseBitcoinErrors } from '../errors/parseBitcoinErrors.js'\nimport type { BitcoinStepExecutorContext } from '../types.js'\nimport { BitcoinSignAndExecuteTask } from './tasks/BitcoinSignAndExecuteTask.js'\nimport { BitcoinWaitForTransactionTask } from './tasks/BitcoinWaitForTransactionTask.js'\n\ninterface BitcoinStepExecutorOptions extends StepExecutorOptions {\n client: Client\n}\n\nexport class BitcoinStepExecutor extends BaseStepExecutor {\n private client: Client\n\n constructor(options: BitcoinStepExecutorOptions) {\n super(options)\n this.client = options.client\n }\n\n checkClient = (step: LiFiStepExtended): void => {\n // TODO: check chain and possibly implement chain switch?\n // Prevent execution of the quote by wallet different from the one which requested the quote\n if (this.client.account?.address !== step.action.fromAddress) {\n throw new TransactionError(\n LiFiErrorCode.WalletChangedDuringExecution,\n 'The wallet address that requested the quote does not match the wallet address attempting to sign the transaction.'\n )\n }\n }\n\n override createPipeline = (\n context: BitcoinStepExecutorContext\n ): TaskPipeline => {\n const { step, isBridgeExecution } = context\n\n const tasks = [\n new CheckBalanceTask(),\n new PrepareTransactionTask(),\n new BitcoinSignAndExecuteTask(),\n new BitcoinWaitForTransactionTask(),\n new WaitForTransactionStatusTask(\n isBridgeExecution ? 'RECEIVING_CHAIN' : 'SWAP'\n ),\n ]\n const swapOrBridgeAction = this.statusManager.findAction(\n step,\n isBridgeExecution ? 'CROSS_CHAIN' : 'SWAP'\n )\n\n const taskName = swapOrBridgeAction?.txHash\n ? swapOrBridgeAction?.status === 'DONE'\n ? WaitForTransactionStatusTask.name\n : BitcoinWaitForTransactionTask.name\n : CheckBalanceTask.name\n\n const firstTaskIndex = tasks.findIndex(\n (task) => task.constructor.name === taskName\n )\n\n const tasksToRun = tasks.slice(firstTaskIndex)\n\n return new TaskPipeline(tasksToRun)\n }\n\n override parseErrors = (\n error: Error,\n step?: LiFiStepExtended,\n action?: ExecutionAction\n ): Promise<SDKError> => parseBitcoinErrors(error, step, action)\n\n override createContext = async (\n baseContext: StepExecutorBaseContext\n ): Promise<BitcoinStepExecutorContext> => {\n const { client, fromChain } = baseContext\n\n const publicClient = await getBitcoinPublicClient(client, fromChain.id)\n\n return {\n ...baseContext,\n pollingIntervalMs: 10_000,\n checkClient: this.checkClient,\n walletClient: this.client,\n publicClient,\n }\n }\n}\n"],"mappings":";;;;;;;;AAyBA,IAAa,sBAAb,cAAyCA,UAAAA,iBAAiB;CACxD;CAEA,YAAY,SAAqC;
|
|
1
|
+
{"version":3,"file":"BitcoinStepExecutor.js","names":["BaseStepExecutor","TransactionError","LiFiErrorCode","CheckBalanceTask","PrepareTransactionTask","BitcoinSignAndExecuteTask","BitcoinWaitForTransactionTask","WaitForTransactionStatusTask","TaskPipeline","parseBitcoinErrors","getBitcoinPublicClient"],"sources":["../../../src/core/BitcoinStepExecutor.ts"],"sourcesContent":["import type { Client } from '@bigmi/core'\nimport {\n BaseStepExecutor,\n CheckBalanceTask,\n type ExecutionAction,\n LiFiErrorCode,\n type LiFiStepExtended,\n PrepareTransactionTask,\n type SDKError,\n type StepExecutorBaseContext,\n type StepExecutorOptions,\n TaskPipeline,\n TransactionError,\n WaitForTransactionStatusTask,\n} from '@lifi/sdk'\nimport { getBitcoinPublicClient } from '../client/publicClient.js'\nimport { parseBitcoinErrors } from '../errors/parseBitcoinErrors.js'\nimport type { BitcoinStepExecutorContext } from '../types.js'\nimport { BitcoinSignAndExecuteTask } from './tasks/BitcoinSignAndExecuteTask.js'\nimport { BitcoinWaitForTransactionTask } from './tasks/BitcoinWaitForTransactionTask.js'\n\ninterface BitcoinStepExecutorOptions extends StepExecutorOptions {\n client: Client\n}\n\nexport class BitcoinStepExecutor extends BaseStepExecutor {\n private client: Client\n\n constructor(options: BitcoinStepExecutorOptions) {\n super(options)\n this.client = options.client\n }\n\n checkClient = (step: LiFiStepExtended): void => {\n // TODO: check chain and possibly implement chain switch?\n // Prevent execution of the quote by wallet different from the one which requested the quote\n if (this.client.account?.address !== step.action.fromAddress) {\n throw new TransactionError(\n LiFiErrorCode.WalletChangedDuringExecution,\n 'The wallet address that requested the quote does not match the wallet address attempting to sign the transaction.'\n )\n }\n }\n\n override createPipeline = (\n context: BitcoinStepExecutorContext\n ): TaskPipeline => {\n const { step, isBridgeExecution } = context\n\n const tasks = [\n new CheckBalanceTask(),\n new PrepareTransactionTask(),\n new BitcoinSignAndExecuteTask(),\n new BitcoinWaitForTransactionTask(),\n new WaitForTransactionStatusTask(\n isBridgeExecution ? 'RECEIVING_CHAIN' : 'SWAP'\n ),\n ]\n const swapOrBridgeAction = this.statusManager.findAction(\n step,\n isBridgeExecution ? 'CROSS_CHAIN' : 'SWAP'\n )\n\n const taskName = swapOrBridgeAction?.txHash\n ? swapOrBridgeAction?.status === 'DONE'\n ? WaitForTransactionStatusTask.name\n : BitcoinWaitForTransactionTask.name\n : CheckBalanceTask.name\n\n const firstTaskIndex = tasks.findIndex(\n (task) => task.constructor.name === taskName\n )\n\n const tasksToRun = tasks.slice(firstTaskIndex)\n\n return new TaskPipeline(tasksToRun)\n }\n\n override parseErrors = (\n error: Error,\n step?: LiFiStepExtended,\n action?: ExecutionAction\n ): Promise<SDKError> => parseBitcoinErrors(error, step, action)\n\n override createContext = async (\n baseContext: StepExecutorBaseContext\n ): Promise<BitcoinStepExecutorContext> => {\n const { client, fromChain } = baseContext\n\n const publicClient = await getBitcoinPublicClient(client, fromChain.id)\n\n return {\n ...baseContext,\n pollingIntervalMs: 10_000,\n checkClient: this.checkClient,\n walletClient: this.client,\n publicClient,\n }\n }\n}\n"],"mappings":";;;;;;;;AAyBA,IAAa,sBAAb,cAAyCA,UAAAA,iBAAiB;CACxD;CAEA,YAAY,SAAqC;EAC/C,MAAM,QAAQ;EACd,KAAK,SAAS,QAAQ;;CAGxB,eAAe,SAAiC;EAG9C,IAAI,KAAK,OAAO,SAAS,YAAY,KAAK,OAAO,aAC/C,MAAM,IAAIC,UAAAA,iBACRC,UAAAA,cAAc,8BACd,oHACD;;CAIL,kBACE,YACiB;EACjB,MAAM,EAAE,MAAM,sBAAsB;EAEpC,MAAM,QAAQ;GACZ,IAAIC,UAAAA,kBAAkB;GACtB,IAAIC,UAAAA,wBAAwB;GAC5B,IAAIC,6CAAAA,2BAA2B;GAC/B,IAAIC,iDAAAA,+BAA+B;GACnC,IAAIC,UAAAA,6BACF,oBAAoB,oBAAoB,OACzC;GACF;EACD,MAAM,qBAAqB,KAAK,cAAc,WAC5C,MACA,oBAAoB,gBAAgB,OACrC;EAED,MAAM,WAAW,oBAAoB,SACjC,oBAAoB,WAAW,SAC7BA,UAAAA,6BAA6B,OAC7BD,iDAAAA,8BAA8B,OAChCH,UAAAA,iBAAiB;EAErB,MAAM,iBAAiB,MAAM,WAC1B,SAAS,KAAK,YAAY,SAAS,SACrC;EAID,OAAO,IAAIK,UAAAA,aAFQ,MAAM,MAAM,eAEG,CAAC;;CAGrC,eACE,OACA,MACA,WACsBC,kCAAAA,mBAAmB,OAAO,MAAM,OAAO;CAE/D,gBAAyB,OACvB,gBACwC;EACxC,MAAM,EAAE,QAAQ,cAAc;EAE9B,MAAM,eAAe,MAAMC,4BAAAA,uBAAuB,QAAQ,UAAU,GAAG;EAEvE,OAAO;GACL,GAAG;GACH,mBAAmB;GACnB,aAAa,KAAK;GAClB,cAAc,KAAK;GACnB;GACD"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"BitcoinSignAndExecuteTask.js","names":["BaseStepExecutionTask","TransactionError","LiFiErrorCode","ecc","Psbt","networks","address","AddressType","toXOnly","generateRedeemScript","isPsbtFinalized"],"sources":["../../../../src/core/tasks/BitcoinSignAndExecuteTask.ts"],"sourcesContent":["import {\n AddressType,\n getAddressInfo,\n hexToUnit8Array,\n signPsbt,\n withTimeout,\n} from '@bigmi/core'\nimport * as ecc from '@bitcoinerlab/secp256k1'\nimport {\n BaseStepExecutionTask,\n getTransactionRequestData,\n LiFiErrorCode,\n type TaskResult,\n TransactionError,\n} from '@lifi/sdk'\nimport { address, initEccLib, networks, Psbt } from 'bitcoinjs-lib'\nimport type { BitcoinStepExecutorContext } from '../../types.js'\nimport { generateRedeemScript } from '../../utils/generateRedeemScript.js'\nimport { isPsbtFinalized } from '../../utils/isPsbtFinalized.js'\nimport { toXOnly } from '../../utils/toXOnly.js'\n\nexport class BitcoinSignAndExecuteTask extends BaseStepExecutionTask {\n async run(context: BitcoinStepExecutorContext): Promise<TaskResult> {\n const {\n step,\n walletClient,\n statusManager,\n executionOptions,\n fromChain,\n publicClient,\n checkClient,\n isBridgeExecution,\n } = context\n\n const action = statusManager.findAction(\n step,\n isBridgeExecution ? 'CROSS_CHAIN' : 'SWAP'\n )\n\n if (!action) {\n throw new TransactionError(\n LiFiErrorCode.TransactionUnprepared,\n 'Unable to prepare transaction. Action not found.'\n )\n }\n\n const transactionRequestData = await getTransactionRequestData(\n step,\n executionOptions\n )\n\n checkClient(step)\n\n const psbtHex = transactionRequestData\n\n // Initialize ECC library required for Taproot operations\n // https://github.com/bitcoinjs/bitcoinjs-lib?tab=readme-ov-file#using-taproot\n initEccLib(ecc)\n\n const psbt = Psbt.fromHex(psbtHex, { network: networks.bitcoin })\n\n psbt.data.inputs.forEach((input, index) => {\n const accountAddress = input.witnessUtxo\n ? address.fromOutputScript(input.witnessUtxo.script, networks.bitcoin)\n : (walletClient.account?.address as string)\n const addressInfo = getAddressInfo(accountAddress)\n if (addressInfo.type === AddressType.p2tr) {\n // Taproot (P2TR) addresses require specific PSBT fields for proper signing\n\n // tapInternalKey: Required for Taproot key-path spending\n // Most wallets / libraries usually handle this already\n if (!input.tapInternalKey) {\n const pubKey = walletClient.account?.publicKey\n if (pubKey) {\n const tapInternalKey = toXOnly(hexToUnit8Array(pubKey))\n psbt.updateInput(index, {\n tapInternalKey,\n })\n }\n }\n // sighashType: Required by bitcoinjs-lib even though the bitcoin protocol allows defaults\n // check if sighashType is default (0) or not set (undefined)\n if (!input.sighashType) {\n psbt.updateInput(index, {\n sighashType: 1, // Default to Transaction.SIGHASH_ALL - 1\n })\n }\n }\n // redeemScript: Required by Pay-to-Script-Hash (P2SH) addresses for proper spending\n if (addressInfo.type === AddressType.p2sh) {\n if (!input.redeemScript) {\n const pubKey = walletClient.account?.publicKey\n if (pubKey) {\n psbt.updateInput(index, {\n redeemScript: generateRedeemScript(hexToUnit8Array(pubKey)),\n })\n }\n }\n }\n })\n\n const inputsToSign = Array.from(\n psbt.data.inputs\n .reduce((map, input, index) => {\n const accountAddress = input.witnessUtxo\n ? address.fromOutputScript(\n input.witnessUtxo.script,\n networks.bitcoin\n )\n : (walletClient.account?.address as string)\n if (map.has(accountAddress)) {\n map.get(accountAddress)!.signingIndexes.push(index)\n } else {\n map.set(accountAddress, {\n address: accountAddress,\n sigHash: 1, // Default to Transaction.SIGHASH_ALL - 1\n signingIndexes: [index],\n })\n }\n return map\n }, new Map<\n string,\n { address: string; sigHash: number; signingIndexes: number[] }\n >())\n .values()\n )\n\n // We give users 10 minutes to sign the transaction or it should be considered expired\n const signedPsbtHex = await withTimeout(\n () =>\n signPsbt(walletClient, {\n psbt: psbt.toHex(),\n inputsToSign: inputsToSign,\n finalize: false,\n }),\n {\n timeout: 600_000,\n errorInstance: new TransactionError(\n LiFiErrorCode.TransactionExpired,\n 'Transaction has expired.'\n ),\n }\n )\n\n const signedPsbt = Psbt.fromHex(signedPsbtHex)\n\n if (!isPsbtFinalized(signedPsbt)) {\n signedPsbt.finalizeAllInputs()\n }\n\n const txHex = signedPsbt.extractTransaction().toHex()\n\n const txHash = await publicClient.sendUTXOTransaction({\n hex: txHex,\n })\n\n statusManager.updateAction(step, action.type, 'PENDING', {\n txHash: txHash,\n txLink: `${fromChain.metamask.blockExplorerUrls[0]}tx/${txHash}`,\n txHex,\n signedAt: Date.now(),\n })\n\n return {\n status: 'COMPLETED',\n }\n }\n}\n"],"mappings":";;;;;;;;;;;AAqBA,IAAa,4BAAb,cAA+CA,UAAAA,sBAAsB;CACnE,MAAM,IAAI,SAA0D;EAClE,MAAM,EACJ,MACA,cACA,eACA,kBACA,WACA,cACA,aACA,sBACE;EAEJ,MAAM,SAAS,cAAc,WAC3B,MACA,oBAAoB,gBAAgB,OACrC;
|
|
1
|
+
{"version":3,"file":"BitcoinSignAndExecuteTask.js","names":["BaseStepExecutionTask","TransactionError","LiFiErrorCode","ecc","Psbt","networks","address","AddressType","toXOnly","generateRedeemScript","isPsbtFinalized"],"sources":["../../../../src/core/tasks/BitcoinSignAndExecuteTask.ts"],"sourcesContent":["import {\n AddressType,\n getAddressInfo,\n hexToUnit8Array,\n signPsbt,\n withTimeout,\n} from '@bigmi/core'\nimport * as ecc from '@bitcoinerlab/secp256k1'\nimport {\n BaseStepExecutionTask,\n getTransactionRequestData,\n LiFiErrorCode,\n type TaskResult,\n TransactionError,\n} from '@lifi/sdk'\nimport { address, initEccLib, networks, Psbt } from 'bitcoinjs-lib'\nimport type { BitcoinStepExecutorContext } from '../../types.js'\nimport { generateRedeemScript } from '../../utils/generateRedeemScript.js'\nimport { isPsbtFinalized } from '../../utils/isPsbtFinalized.js'\nimport { toXOnly } from '../../utils/toXOnly.js'\n\nexport class BitcoinSignAndExecuteTask extends BaseStepExecutionTask {\n async run(context: BitcoinStepExecutorContext): Promise<TaskResult> {\n const {\n step,\n walletClient,\n statusManager,\n executionOptions,\n fromChain,\n publicClient,\n checkClient,\n isBridgeExecution,\n } = context\n\n const action = statusManager.findAction(\n step,\n isBridgeExecution ? 'CROSS_CHAIN' : 'SWAP'\n )\n\n if (!action) {\n throw new TransactionError(\n LiFiErrorCode.TransactionUnprepared,\n 'Unable to prepare transaction. Action not found.'\n )\n }\n\n const transactionRequestData = await getTransactionRequestData(\n step,\n executionOptions\n )\n\n checkClient(step)\n\n const psbtHex = transactionRequestData\n\n // Initialize ECC library required for Taproot operations\n // https://github.com/bitcoinjs/bitcoinjs-lib?tab=readme-ov-file#using-taproot\n initEccLib(ecc)\n\n const psbt = Psbt.fromHex(psbtHex, { network: networks.bitcoin })\n\n psbt.data.inputs.forEach((input, index) => {\n const accountAddress = input.witnessUtxo\n ? address.fromOutputScript(input.witnessUtxo.script, networks.bitcoin)\n : (walletClient.account?.address as string)\n const addressInfo = getAddressInfo(accountAddress)\n if (addressInfo.type === AddressType.p2tr) {\n // Taproot (P2TR) addresses require specific PSBT fields for proper signing\n\n // tapInternalKey: Required for Taproot key-path spending\n // Most wallets / libraries usually handle this already\n if (!input.tapInternalKey) {\n const pubKey = walletClient.account?.publicKey\n if (pubKey) {\n const tapInternalKey = toXOnly(hexToUnit8Array(pubKey))\n psbt.updateInput(index, {\n tapInternalKey,\n })\n }\n }\n // sighashType: Required by bitcoinjs-lib even though the bitcoin protocol allows defaults\n // check if sighashType is default (0) or not set (undefined)\n if (!input.sighashType) {\n psbt.updateInput(index, {\n sighashType: 1, // Default to Transaction.SIGHASH_ALL - 1\n })\n }\n }\n // redeemScript: Required by Pay-to-Script-Hash (P2SH) addresses for proper spending\n if (addressInfo.type === AddressType.p2sh) {\n if (!input.redeemScript) {\n const pubKey = walletClient.account?.publicKey\n if (pubKey) {\n psbt.updateInput(index, {\n redeemScript: generateRedeemScript(hexToUnit8Array(pubKey)),\n })\n }\n }\n }\n })\n\n const inputsToSign = Array.from(\n psbt.data.inputs\n .reduce((map, input, index) => {\n const accountAddress = input.witnessUtxo\n ? address.fromOutputScript(\n input.witnessUtxo.script,\n networks.bitcoin\n )\n : (walletClient.account?.address as string)\n if (map.has(accountAddress)) {\n map.get(accountAddress)!.signingIndexes.push(index)\n } else {\n map.set(accountAddress, {\n address: accountAddress,\n sigHash: 1, // Default to Transaction.SIGHASH_ALL - 1\n signingIndexes: [index],\n })\n }\n return map\n }, new Map<\n string,\n { address: string; sigHash: number; signingIndexes: number[] }\n >())\n .values()\n )\n\n // We give users 10 minutes to sign the transaction or it should be considered expired\n const signedPsbtHex = await withTimeout(\n () =>\n signPsbt(walletClient, {\n psbt: psbt.toHex(),\n inputsToSign: inputsToSign,\n finalize: false,\n }),\n {\n timeout: 600_000,\n errorInstance: new TransactionError(\n LiFiErrorCode.TransactionExpired,\n 'Transaction has expired.'\n ),\n }\n )\n\n const signedPsbt = Psbt.fromHex(signedPsbtHex)\n\n if (!isPsbtFinalized(signedPsbt)) {\n signedPsbt.finalizeAllInputs()\n }\n\n const txHex = signedPsbt.extractTransaction().toHex()\n\n const txHash = await publicClient.sendUTXOTransaction({\n hex: txHex,\n })\n\n statusManager.updateAction(step, action.type, 'PENDING', {\n txHash: txHash,\n txLink: `${fromChain.metamask.blockExplorerUrls[0]}tx/${txHash}`,\n txHex,\n signedAt: Date.now(),\n })\n\n return {\n status: 'COMPLETED',\n }\n }\n}\n"],"mappings":";;;;;;;;;;;AAqBA,IAAa,4BAAb,cAA+CA,UAAAA,sBAAsB;CACnE,MAAM,IAAI,SAA0D;EAClE,MAAM,EACJ,MACA,cACA,eACA,kBACA,WACA,cACA,aACA,sBACE;EAEJ,MAAM,SAAS,cAAc,WAC3B,MACA,oBAAoB,gBAAgB,OACrC;EAED,IAAI,CAAC,QACH,MAAM,IAAIC,UAAAA,iBACRC,UAAAA,cAAc,uBACd,mDACD;EAGH,MAAM,yBAAyB,OAAA,GAAA,UAAA,2BAC7B,MACA,iBACD;EAED,YAAY,KAAK;EAEjB,MAAM,UAAU;EAIhB,CAAA,GAAA,cAAA,YAAWC,wBAAI;EAEf,MAAM,OAAOC,cAAAA,KAAK,QAAQ,SAAS,EAAE,SAASC,cAAAA,SAAS,SAAS,CAAC;EAEjE,KAAK,KAAK,OAAO,SAAS,OAAO,UAAU;GAIzC,MAAM,eAAA,GAAA,YAAA,gBAHiB,MAAM,cACzBC,cAAAA,QAAQ,iBAAiB,MAAM,YAAY,QAAQD,cAAAA,SAAS,QAAQ,GACnE,aAAa,SAAS,QACuB;GAClD,IAAI,YAAY,SAASE,YAAAA,YAAY,MAAM;IAKzC,IAAI,CAAC,MAAM,gBAAgB;KACzB,MAAM,SAAS,aAAa,SAAS;KACrC,IAAI,QAAQ;MACV,MAAM,iBAAiBC,sBAAAA,SAAAA,GAAAA,YAAAA,iBAAwB,OAAO,CAAC;MACvD,KAAK,YAAY,OAAO,EACtB,gBACD,CAAC;;;IAKN,IAAI,CAAC,MAAM,aACT,KAAK,YAAY,OAAO,EACtB,aAAa,GACd,CAAC;;GAIN,IAAI,YAAY,SAASD,YAAAA,YAAY;QAC/B,CAAC,MAAM,cAAc;KACvB,MAAM,SAAS,aAAa,SAAS;KACrC,IAAI,QACF,KAAK,YAAY,OAAO,EACtB,cAAcE,mCAAAA,sBAAAA,GAAAA,YAAAA,iBAAqC,OAAO,CAAC,EAC5D,CAAC;;;IAIR;EAEF,MAAM,eAAe,MAAM,KACzB,KAAK,KAAK,OACP,QAAQ,KAAK,OAAO,UAAU;GAC7B,MAAM,iBAAiB,MAAM,cACzBH,cAAAA,QAAQ,iBACN,MAAM,YAAY,QAClBD,cAAAA,SAAS,QACV,GACA,aAAa,SAAS;GAC3B,IAAI,IAAI,IAAI,eAAe,EACzB,IAAI,IAAI,eAAe,CAAE,eAAe,KAAK,MAAM;QAEnD,IAAI,IAAI,gBAAgB;IACtB,SAAS;IACT,SAAS;IACT,gBAAgB,CAAC,MAAM;IACxB,CAAC;GAEJ,OAAO;qBACN,IAAI,KAGJ,CAAC,CACH,QAAQ,CACZ;EAGD,MAAM,gBAAgB,OAAA,GAAA,YAAA,oBAAA,GAAA,YAAA,UAET,cAAc;GACrB,MAAM,KAAK,OAAO;GACJ;GACd,UAAU;GACX,CAAC,EACJ;GACE,SAAS;GACT,eAAe,IAAIJ,UAAAA,iBACjBC,UAAAA,cAAc,oBACd,2BACD;GACF,CACF;EAED,MAAM,aAAaE,cAAAA,KAAK,QAAQ,cAAc;EAE9C,IAAI,CAACM,8BAAAA,gBAAgB,WAAW,EAC9B,WAAW,mBAAmB;EAGhC,MAAM,QAAQ,WAAW,oBAAoB,CAAC,OAAO;EAErD,MAAM,SAAS,MAAM,aAAa,oBAAoB,EACpD,KAAK,OACN,CAAC;EAEF,cAAc,aAAa,MAAM,OAAO,MAAM,WAAW;GAC/C;GACR,QAAQ,GAAG,UAAU,SAAS,kBAAkB,GAAG,KAAK;GACxD;GACA,UAAU,KAAK,KAAK;GACrB,CAAC;EAEF,OAAO,EACL,QAAQ,aACT"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"BitcoinWaitForTransactionTask.js","names":["BaseStepExecutionTask","TransactionError","LiFiErrorCode"],"sources":["../../../../src/core/tasks/BitcoinWaitForTransactionTask.ts"],"sourcesContent":["import type { ReplacementReason } from '@bigmi/core'\nimport { waitForTransaction } from '@bigmi/core'\nimport {\n BaseStepExecutionTask,\n LiFiErrorCode,\n type TaskResult,\n TransactionError,\n} from '@lifi/sdk'\nimport type { BitcoinStepExecutorContext } from '../../types.js'\n\nexport class BitcoinWaitForTransactionTask extends BaseStepExecutionTask {\n async run(context: BitcoinStepExecutorContext): Promise<TaskResult> {\n const {\n step,\n statusManager,\n fromChain,\n isBridgeExecution,\n walletClient,\n publicClient,\n checkClient,\n } = context\n\n const action = statusManager.findAction(\n step,\n isBridgeExecution ? 'CROSS_CHAIN' : 'SWAP'\n )\n\n const txHex = action?.txHex\n const txHash = action?.txHash\n\n if (!txHash || !txHex) {\n throw new TransactionError(\n LiFiErrorCode.TransactionUnprepared,\n 'Unable to prepare transaction. Transaction hash or hex is not set.'\n )\n }\n\n checkClient(step)\n\n let replacementReason: ReplacementReason | undefined\n const transaction = await waitForTransaction(publicClient, {\n txId: txHash,\n txHex,\n senderAddress: walletClient.account?.address,\n onReplaced: (response) => {\n replacementReason = response.reason\n statusManager.updateAction(step, action.type, 'PENDING', {\n txHash: response.transaction.txid,\n txLink: `${fromChain.metamask.blockExplorerUrls[0]}tx/${response.transaction.txid}`,\n })\n },\n })\n\n if (replacementReason === 'cancelled') {\n throw new TransactionError(\n LiFiErrorCode.TransactionCanceled,\n 'User canceled transaction.'\n )\n }\n\n if (transaction.txid !== txHash) {\n statusManager.updateAction(step, action.type, 'PENDING', {\n txHash: transaction.txid,\n txLink: `${fromChain.metamask.blockExplorerUrls[0]}tx/${transaction.txid}`,\n })\n }\n\n if (isBridgeExecution) {\n statusManager.updateAction(step, action.type, 'DONE')\n }\n\n return { status: 'COMPLETED' }\n }\n}\n"],"mappings":";;;;;AAUA,IAAa,gCAAb,cAAmDA,UAAAA,sBAAsB;CACvE,MAAM,IAAI,SAA0D;EAClE,MAAM,EACJ,MACA,eACA,WACA,mBACA,cACA,cACA,gBACE;EAEJ,MAAM,SAAS,cAAc,WAC3B,MACA,oBAAoB,gBAAgB,OACrC;EAED,MAAM,QAAQ,QAAQ;EACtB,MAAM,SAAS,QAAQ;
|
|
1
|
+
{"version":3,"file":"BitcoinWaitForTransactionTask.js","names":["BaseStepExecutionTask","TransactionError","LiFiErrorCode"],"sources":["../../../../src/core/tasks/BitcoinWaitForTransactionTask.ts"],"sourcesContent":["import type { ReplacementReason } from '@bigmi/core'\nimport { waitForTransaction } from '@bigmi/core'\nimport {\n BaseStepExecutionTask,\n LiFiErrorCode,\n type TaskResult,\n TransactionError,\n} from '@lifi/sdk'\nimport type { BitcoinStepExecutorContext } from '../../types.js'\n\nexport class BitcoinWaitForTransactionTask extends BaseStepExecutionTask {\n async run(context: BitcoinStepExecutorContext): Promise<TaskResult> {\n const {\n step,\n statusManager,\n fromChain,\n isBridgeExecution,\n walletClient,\n publicClient,\n checkClient,\n } = context\n\n const action = statusManager.findAction(\n step,\n isBridgeExecution ? 'CROSS_CHAIN' : 'SWAP'\n )\n\n const txHex = action?.txHex\n const txHash = action?.txHash\n\n if (!txHash || !txHex) {\n throw new TransactionError(\n LiFiErrorCode.TransactionUnprepared,\n 'Unable to prepare transaction. Transaction hash or hex is not set.'\n )\n }\n\n checkClient(step)\n\n let replacementReason: ReplacementReason | undefined\n const transaction = await waitForTransaction(publicClient, {\n txId: txHash,\n txHex,\n senderAddress: walletClient.account?.address,\n onReplaced: (response) => {\n replacementReason = response.reason\n statusManager.updateAction(step, action.type, 'PENDING', {\n txHash: response.transaction.txid,\n txLink: `${fromChain.metamask.blockExplorerUrls[0]}tx/${response.transaction.txid}`,\n })\n },\n })\n\n if (replacementReason === 'cancelled') {\n throw new TransactionError(\n LiFiErrorCode.TransactionCanceled,\n 'User canceled transaction.'\n )\n }\n\n if (transaction.txid !== txHash) {\n statusManager.updateAction(step, action.type, 'PENDING', {\n txHash: transaction.txid,\n txLink: `${fromChain.metamask.blockExplorerUrls[0]}tx/${transaction.txid}`,\n })\n }\n\n if (isBridgeExecution) {\n statusManager.updateAction(step, action.type, 'DONE')\n }\n\n return { status: 'COMPLETED' }\n }\n}\n"],"mappings":";;;;;AAUA,IAAa,gCAAb,cAAmDA,UAAAA,sBAAsB;CACvE,MAAM,IAAI,SAA0D;EAClE,MAAM,EACJ,MACA,eACA,WACA,mBACA,cACA,cACA,gBACE;EAEJ,MAAM,SAAS,cAAc,WAC3B,MACA,oBAAoB,gBAAgB,OACrC;EAED,MAAM,QAAQ,QAAQ;EACtB,MAAM,SAAS,QAAQ;EAEvB,IAAI,CAAC,UAAU,CAAC,OACd,MAAM,IAAIC,UAAAA,iBACRC,UAAAA,cAAc,uBACd,qEACD;EAGH,YAAY,KAAK;EAEjB,IAAI;EACJ,MAAM,cAAc,OAAA,GAAA,YAAA,oBAAyB,cAAc;GACzD,MAAM;GACN;GACA,eAAe,aAAa,SAAS;GACrC,aAAa,aAAa;IACxB,oBAAoB,SAAS;IAC7B,cAAc,aAAa,MAAM,OAAO,MAAM,WAAW;KACvD,QAAQ,SAAS,YAAY;KAC7B,QAAQ,GAAG,UAAU,SAAS,kBAAkB,GAAG,KAAK,SAAS,YAAY;KAC9E,CAAC;;GAEL,CAAC;EAEF,IAAI,sBAAsB,aACxB,MAAM,IAAID,UAAAA,iBACRC,UAAAA,cAAc,qBACd,6BACD;EAGH,IAAI,YAAY,SAAS,QACvB,cAAc,aAAa,MAAM,OAAO,MAAM,WAAW;GACvD,QAAQ,YAAY;GACpB,QAAQ,GAAG,UAAU,SAAS,kBAAkB,GAAG,KAAK,YAAY;GACrE,CAAC;EAGJ,IAAI,mBACF,cAAc,aAAa,MAAM,OAAO,MAAM,OAAO;EAGvD,OAAO,EAAE,QAAQ,aAAa"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"parseBitcoinErrors.js","names":["SDKError","TransactionError","LiFiErrorCode","BaseError","UnknownError","ErrorMessage"],"sources":["../../../src/errors/parseBitcoinErrors.ts"],"sourcesContent":["import {\n BaseError,\n ErrorMessage,\n type ExecutionAction,\n LiFiErrorCode,\n type LiFiStep,\n SDKError,\n TransactionError,\n UnknownError,\n} from '@lifi/sdk'\n\nexport const parseBitcoinErrors = async (\n e: Error,\n step?: LiFiStep,\n action?: ExecutionAction\n): Promise<SDKError> => {\n if (e instanceof SDKError) {\n e.step = e.step ?? step\n e.action = e.action ?? action\n return e\n }\n\n const baseError = handleSpecificErrors(e)\n\n return new SDKError(baseError, step, action)\n}\n\nconst handleSpecificErrors = (e: any) => {\n // txn-mempool-conflict\n if (\n e.details?.includes?.('conflict') ||\n e.cause?.message?.includes?.('conflict')\n ) {\n return new TransactionError(\n LiFiErrorCode.TransactionConflict,\n 'Your transaction conflicts with another transaction already in the mempool. One or more inputs have been spent by another transaction.',\n e\n )\n }\n if (e.code === 4001 || e.code === -32000 || e.cause?.includes?.('rejected')) {\n return new TransactionError(LiFiErrorCode.SignatureRejected, e.message, e)\n }\n if (e.code === -5 || e.code === -32700 || e.code === -32064) {\n return new TransactionError(LiFiErrorCode.NotFound, e.message, e)\n }\n\n if (e instanceof BaseError) {\n return e\n }\n\n return new UnknownError(e.message || ErrorMessage.UnknownError, e)\n}\n"],"mappings":";;;;AAWA,MAAa,qBAAqB,OAChC,GACA,MACA,WACsB;
|
|
1
|
+
{"version":3,"file":"parseBitcoinErrors.js","names":["SDKError","TransactionError","LiFiErrorCode","BaseError","UnknownError","ErrorMessage"],"sources":["../../../src/errors/parseBitcoinErrors.ts"],"sourcesContent":["import {\n BaseError,\n ErrorMessage,\n type ExecutionAction,\n LiFiErrorCode,\n type LiFiStep,\n SDKError,\n TransactionError,\n UnknownError,\n} from '@lifi/sdk'\n\nexport const parseBitcoinErrors = async (\n e: Error,\n step?: LiFiStep,\n action?: ExecutionAction\n): Promise<SDKError> => {\n if (e instanceof SDKError) {\n e.step = e.step ?? step\n e.action = e.action ?? action\n return e\n }\n\n const baseError = handleSpecificErrors(e)\n\n return new SDKError(baseError, step, action)\n}\n\nconst handleSpecificErrors = (e: any) => {\n // txn-mempool-conflict\n if (\n e.details?.includes?.('conflict') ||\n e.cause?.message?.includes?.('conflict')\n ) {\n return new TransactionError(\n LiFiErrorCode.TransactionConflict,\n 'Your transaction conflicts with another transaction already in the mempool. One or more inputs have been spent by another transaction.',\n e\n )\n }\n if (e.code === 4001 || e.code === -32000 || e.cause?.includes?.('rejected')) {\n return new TransactionError(LiFiErrorCode.SignatureRejected, e.message, e)\n }\n if (e.code === -5 || e.code === -32700 || e.code === -32064) {\n return new TransactionError(LiFiErrorCode.NotFound, e.message, e)\n }\n\n if (e instanceof BaseError) {\n return e\n }\n\n return new UnknownError(e.message || ErrorMessage.UnknownError, e)\n}\n"],"mappings":";;;;AAWA,MAAa,qBAAqB,OAChC,GACA,MACA,WACsB;CACtB,IAAI,aAAaA,UAAAA,UAAU;EACzB,EAAE,OAAO,EAAE,QAAQ;EACnB,EAAE,SAAS,EAAE,UAAU;EACvB,OAAO;;CAKT,OAAO,IAAIA,UAAAA,SAFO,qBAAqB,EAEV,EAAE,MAAM,OAAO;;AAG9C,MAAM,wBAAwB,MAAW;CAEvC,IACE,EAAE,SAAS,WAAW,WAAW,IACjC,EAAE,OAAO,SAAS,WAAW,WAAW,EAExC,OAAO,IAAIC,UAAAA,iBACTC,UAAAA,cAAc,qBACd,0IACA,EACD;CAEH,IAAI,EAAE,SAAS,QAAQ,EAAE,SAAS,SAAU,EAAE,OAAO,WAAW,WAAW,EACzE,OAAO,IAAID,UAAAA,iBAAiBC,UAAAA,cAAc,mBAAmB,EAAE,SAAS,EAAE;CAE5E,IAAI,EAAE,SAAS,MAAM,EAAE,SAAS,UAAU,EAAE,SAAS,QACnD,OAAO,IAAID,UAAAA,iBAAiBC,UAAAA,cAAc,UAAU,EAAE,SAAS,EAAE;CAGnE,IAAI,aAAaC,UAAAA,WACf,OAAO;CAGT,OAAO,IAAIC,UAAAA,aAAa,EAAE,WAAWC,UAAAA,aAAa,cAAc,EAAE"}
|
package/dist/cjs/types.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"types.js","names":["ChainType"],"sources":["../../src/types.ts"],"sourcesContent":["import type { Client } from '@bigmi/core'\nimport {\n ChainType,\n type LiFiStepExtended,\n type SDKProvider,\n type StepExecutorContext,\n} from '@lifi/sdk'\nimport type { PublicClient } from './client/publicClient.js'\n\nexport interface BitcoinProviderOptions {\n getWalletClient?: () => Promise<Client>\n}\n\nexport interface BitcoinStepExecutorContext extends StepExecutorContext {\n walletClient: Client\n publicClient: PublicClient\n checkClient: (step: LiFiStepExtended) => void\n}\n\nexport interface BitcoinSDKProvider extends SDKProvider {\n setOptions(options: BitcoinProviderOptions): void\n}\n\nexport function isBitcoinProvider(\n provider: SDKProvider\n): provider is BitcoinSDKProvider {\n return provider.type === ChainType.UTXO\n}\n"],"mappings":";;;;AAuBA,SAAgB,kBACd,UACgC;
|
|
1
|
+
{"version":3,"file":"types.js","names":["ChainType"],"sources":["../../src/types.ts"],"sourcesContent":["import type { Client } from '@bigmi/core'\nimport {\n ChainType,\n type LiFiStepExtended,\n type SDKProvider,\n type StepExecutorContext,\n} from '@lifi/sdk'\nimport type { PublicClient } from './client/publicClient.js'\n\nexport interface BitcoinProviderOptions {\n getWalletClient?: () => Promise<Client>\n}\n\nexport interface BitcoinStepExecutorContext extends StepExecutorContext {\n walletClient: Client\n publicClient: PublicClient\n checkClient: (step: LiFiStepExtended) => void\n}\n\nexport interface BitcoinSDKProvider extends SDKProvider {\n setOptions(options: BitcoinProviderOptions): void\n}\n\nexport function isBitcoinProvider(\n provider: SDKProvider\n): provider is BitcoinSDKProvider {\n return provider.type === ChainType.UTXO\n}\n"],"mappings":";;;;AAuBA,SAAgB,kBACd,UACgC;CAChC,OAAO,SAAS,SAASA,UAAAA,UAAU"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"isPsbtFinalized.js","names":[],"sources":["../../../src/utils/isPsbtFinalized.ts"],"sourcesContent":["import type { Psbt } from 'bitcoinjs-lib'\n\nexport function isPsbtFinalized(psbt: Psbt): boolean {\n try {\n psbt.extractTransaction()\n return true\n } catch (_) {\n return false\n }\n}\n"],"mappings":";;AAEA,SAAgB,gBAAgB,MAAqB;
|
|
1
|
+
{"version":3,"file":"isPsbtFinalized.js","names":[],"sources":["../../../src/utils/isPsbtFinalized.ts"],"sourcesContent":["import type { Psbt } from 'bitcoinjs-lib'\n\nexport function isPsbtFinalized(psbt: Psbt): boolean {\n try {\n psbt.extractTransaction()\n return true\n } catch (_) {\n return false\n }\n}\n"],"mappings":";;AAEA,SAAgB,gBAAgB,MAAqB;CACnD,IAAI;EACF,KAAK,oBAAoB;EACzB,OAAO;UACA,GAAG;EACV,OAAO"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"toBigmiChainId.js","names":["ChainId","BigmiChainId"],"sources":["../../../src/utils/toBigmiChainId.ts"],"sourcesContent":["import { ChainId as BigmiChainId } from '@bigmi/core'\nimport { ChainId } from '@lifi/sdk'\n\nexport const toBigmiChainId = (chainId: ChainId): BigmiChainId => {\n switch (chainId) {\n case ChainId.BTC:\n return BigmiChainId.BITCOIN_MAINNET\n default:\n throw new Error(`Unsupported chainId mapping: ${chainId}`)\n }\n}\n"],"mappings":";;;;;AAGA,MAAa,kBAAkB,YAAmC;
|
|
1
|
+
{"version":3,"file":"toBigmiChainId.js","names":["ChainId","BigmiChainId"],"sources":["../../../src/utils/toBigmiChainId.ts"],"sourcesContent":["import { ChainId as BigmiChainId } from '@bigmi/core'\nimport { ChainId } from '@lifi/sdk'\n\nexport const toBigmiChainId = (chainId: ChainId): BigmiChainId => {\n switch (chainId) {\n case ChainId.BTC:\n return BigmiChainId.BITCOIN_MAINNET\n default:\n throw new Error(`Unsupported chainId mapping: ${chainId}`)\n }\n}\n"],"mappings":";;;;;AAGA,MAAa,kBAAkB,YAAmC;CAChE,QAAQ,SAAR;EACE,KAAKA,UAAAA,QAAQ,KACX,OAAOC,YAAAA,QAAa;EACtB,SACE,MAAM,IAAI,MAAM,gCAAgC,UAAU"}
|
package/dist/cjs/version.d.ts
CHANGED
package/dist/cjs/version.js
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
|
|
2
2
|
//#region src/version.ts
|
|
3
3
|
const name = "@lifi/sdk-provider-bitcoin";
|
|
4
|
-
const version = "4.0.0-beta.
|
|
4
|
+
const version = "4.0.0-beta.9";
|
|
5
5
|
//#endregion
|
|
6
6
|
exports.name = name;
|
|
7
7
|
exports.version = version;
|
package/dist/cjs/version.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"version.js","names":[],"sources":["../../src/version.ts"],"sourcesContent":["export const name = '@lifi/sdk-provider-bitcoin'\nexport const version = '4.0.0-beta.
|
|
1
|
+
{"version":3,"file":"version.js","names":[],"sources":["../../src/version.ts"],"sourcesContent":["export const name = '@lifi/sdk-provider-bitcoin'\nexport const version = '4.0.0-beta.9'\n"],"mappings":";;AAAA,MAAa,OAAO;AACpB,MAAa,UAAU"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"BitcoinProvider.js","names":[],"sources":["../../src/BitcoinProvider.ts"],"sourcesContent":["import { isUTXOAddress } from '@bigmi/core'\nimport { ChainType, type StepExecutorOptions } from '@lifi/sdk'\nimport { getBitcoinBalance } from './actions/getBitcoinBalance.js'\nimport { resolveBitcoinAddress } from './actions/resolveBitcoinAddress.js'\nimport { BitcoinStepExecutor } from './core/BitcoinStepExecutor.js'\nimport type { BitcoinProviderOptions, BitcoinSDKProvider } from './types.js'\n\nexport function BitcoinProvider(\n options?: BitcoinProviderOptions\n): BitcoinSDKProvider {\n const _options: BitcoinProviderOptions = options ?? {}\n return {\n get type() {\n return ChainType.UTXO\n },\n isAddress: isUTXOAddress,\n resolveAddress: resolveBitcoinAddress,\n getBalance: getBitcoinBalance,\n async getStepExecutor(\n options: StepExecutorOptions\n ): Promise<BitcoinStepExecutor> {\n if (!_options.getWalletClient) {\n throw new Error('Client is not provided.')\n }\n\n const walletClient = await _options.getWalletClient()\n\n const executor = new BitcoinStepExecutor({\n client: walletClient,\n routeId: options.routeId,\n executionOptions: {\n ...options.executionOptions,\n },\n })\n\n return executor\n },\n setOptions(options: BitcoinProviderOptions) {\n Object.assign(_options, options)\n },\n }\n}\n"],"mappings":";;;;;;AAOA,SAAgB,gBACd,SACoB;CACpB,MAAM,WAAmC,WAAW,EAAE;
|
|
1
|
+
{"version":3,"file":"BitcoinProvider.js","names":[],"sources":["../../src/BitcoinProvider.ts"],"sourcesContent":["import { isUTXOAddress } from '@bigmi/core'\nimport { ChainType, type StepExecutorOptions } from '@lifi/sdk'\nimport { getBitcoinBalance } from './actions/getBitcoinBalance.js'\nimport { resolveBitcoinAddress } from './actions/resolveBitcoinAddress.js'\nimport { BitcoinStepExecutor } from './core/BitcoinStepExecutor.js'\nimport type { BitcoinProviderOptions, BitcoinSDKProvider } from './types.js'\n\nexport function BitcoinProvider(\n options?: BitcoinProviderOptions\n): BitcoinSDKProvider {\n const _options: BitcoinProviderOptions = options ?? {}\n return {\n get type() {\n return ChainType.UTXO\n },\n isAddress: isUTXOAddress,\n resolveAddress: resolveBitcoinAddress,\n getBalance: getBitcoinBalance,\n async getStepExecutor(\n options: StepExecutorOptions\n ): Promise<BitcoinStepExecutor> {\n if (!_options.getWalletClient) {\n throw new Error('Client is not provided.')\n }\n\n const walletClient = await _options.getWalletClient()\n\n const executor = new BitcoinStepExecutor({\n client: walletClient,\n routeId: options.routeId,\n executionOptions: {\n ...options.executionOptions,\n },\n })\n\n return executor\n },\n setOptions(options: BitcoinProviderOptions) {\n Object.assign(_options, options)\n },\n }\n}\n"],"mappings":";;;;;;AAOA,SAAgB,gBACd,SACoB;CACpB,MAAM,WAAmC,WAAW,EAAE;CACtD,OAAO;EACL,IAAI,OAAO;GACT,OAAO,UAAU;;EAEnB,WAAW;EACX,gBAAgB;EAChB,YAAY;EACZ,MAAM,gBACJ,SAC8B;GAC9B,IAAI,CAAC,SAAS,iBACZ,MAAM,IAAI,MAAM,0BAA0B;GAa5C,OAAO,IARc,oBAAoB;IACvC,QAAQ,MAHiB,SAAS,iBAAiB;IAInD,SAAS,QAAQ;IACjB,kBAAkB,EAChB,GAAG,QAAQ,kBACZ;IACF,CAEc;;EAEjB,WAAW,SAAiC;GAC1C,OAAO,OAAO,UAAU,QAAQ;;EAEnC"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"getBitcoinBalance.js","names":[],"sources":["../../../src/actions/getBitcoinBalance.ts"],"sourcesContent":["import {\n ChainId,\n type SDKClient,\n type Token,\n type TokenAmount,\n} from '@lifi/sdk'\nimport { getBitcoinPublicClient } from '../client/publicClient.js'\n\nexport const getBitcoinBalance = async (\n client: SDKClient,\n walletAddress: string,\n tokens: Token[]\n): Promise<TokenAmount[]> => {\n if (tokens.length === 0) {\n return []\n }\n const { chainId } = tokens[0]\n for (const token of tokens) {\n if (token.chainId !== chainId) {\n console.warn('Requested tokens have to be on the same chain.')\n }\n }\n const bigmiClient = await getBitcoinPublicClient(client, ChainId.BTC)\n const [balance, blockCount] = await Promise.allSettled([\n bigmiClient.getBalance({ address: walletAddress }),\n bigmiClient.getBlockCount(),\n ])\n\n const blockNumber =\n blockCount.status === 'fulfilled' ? BigInt(blockCount.value) : 0n\n\n if (balance.status !== 'fulfilled') {\n // RPC failed — leave amount undefined so callers can distinguish\n // an unknown balance from a known zero.\n return tokens.map((token) => ({\n ...token,\n blockNumber,\n }))\n }\n\n return tokens.map((token) => ({\n ...token,\n amount: balance.value,\n blockNumber,\n }))\n}\n"],"mappings":";;;AAQA,MAAa,oBAAoB,OAC/B,QACA,eACA,WAC2B;
|
|
1
|
+
{"version":3,"file":"getBitcoinBalance.js","names":[],"sources":["../../../src/actions/getBitcoinBalance.ts"],"sourcesContent":["import {\n ChainId,\n type SDKClient,\n type Token,\n type TokenAmount,\n} from '@lifi/sdk'\nimport { getBitcoinPublicClient } from '../client/publicClient.js'\n\nexport const getBitcoinBalance = async (\n client: SDKClient,\n walletAddress: string,\n tokens: Token[]\n): Promise<TokenAmount[]> => {\n if (tokens.length === 0) {\n return []\n }\n const { chainId } = tokens[0]\n for (const token of tokens) {\n if (token.chainId !== chainId) {\n console.warn('Requested tokens have to be on the same chain.')\n }\n }\n const bigmiClient = await getBitcoinPublicClient(client, ChainId.BTC)\n const [balance, blockCount] = await Promise.allSettled([\n bigmiClient.getBalance({ address: walletAddress }),\n bigmiClient.getBlockCount(),\n ])\n\n const blockNumber =\n blockCount.status === 'fulfilled' ? BigInt(blockCount.value) : 0n\n\n if (balance.status !== 'fulfilled') {\n // RPC failed — leave amount undefined so callers can distinguish\n // an unknown balance from a known zero.\n return tokens.map((token) => ({\n ...token,\n blockNumber,\n }))\n }\n\n return tokens.map((token) => ({\n ...token,\n amount: balance.value,\n blockNumber,\n }))\n}\n"],"mappings":";;;AAQA,MAAa,oBAAoB,OAC/B,QACA,eACA,WAC2B;CAC3B,IAAI,OAAO,WAAW,GACpB,OAAO,EAAE;CAEX,MAAM,EAAE,YAAY,OAAO;CAC3B,KAAK,MAAM,SAAS,QAClB,IAAI,MAAM,YAAY,SACpB,QAAQ,KAAK,iDAAiD;CAGlE,MAAM,cAAc,MAAM,uBAAuB,QAAQ,QAAQ,IAAI;CACrE,MAAM,CAAC,SAAS,cAAc,MAAM,QAAQ,WAAW,CACrD,YAAY,WAAW,EAAE,SAAS,eAAe,CAAC,EAClD,YAAY,eAAe,CAC5B,CAAC;CAEF,MAAM,cACJ,WAAW,WAAW,cAAc,OAAO,WAAW,MAAM,GAAG;CAEjE,IAAI,QAAQ,WAAW,aAGrB,OAAO,OAAO,KAAK,WAAW;EAC5B,GAAG;EACH;EACD,EAAE;CAGL,OAAO,OAAO,KAAK,WAAW;EAC5B,GAAG;EACH,QAAQ,QAAQ;EAChB;EACD,EAAE"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"resolveBitcoinAddress.js","names":[],"sources":["../../../src/actions/resolveBitcoinAddress.ts"],"sourcesContent":["export async function resolveBitcoinAddress(\n name: string\n): Promise<string | undefined> {\n // Not supported on UTXO yet\n return name\n}\n"],"mappings":";AAAA,eAAsB,sBACpB,MAC6B;
|
|
1
|
+
{"version":3,"file":"resolveBitcoinAddress.js","names":[],"sources":["../../../src/actions/resolveBitcoinAddress.ts"],"sourcesContent":["export async function resolveBitcoinAddress(\n name: string\n): Promise<string | undefined> {\n // Not supported on UTXO yet\n return name\n}\n"],"mappings":";AAAA,eAAsB,sBACpB,MAC6B;CAE7B,OAAO"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"publicClient.js","names":[],"sources":["../../../src/client/publicClient.ts"],"sourcesContent":["import {\n type Account,\n blockchair,\n blockcypher,\n type Chain,\n type Client,\n createClient,\n type FallbackTransport,\n fallback,\n type HttpTransport,\n http,\n mempool,\n type PublicActions,\n publicActions,\n rpcSchema,\n type UTXOSchema,\n type WalletActions,\n walletActions,\n} from '@bigmi/core'\nimport type { SDKClient } from '@lifi/sdk'\nimport { toBigmiChainId } from '../utils/toBigmiChainId.js'\n\nexport type PublicClient = Client<\n FallbackTransport<readonly HttpTransport[]>,\n Chain,\n Account | undefined,\n UTXOSchema,\n PublicActions & WalletActions\n>\n\n// cached providers\nconst publicClients: Record<number, PublicClient> = {}\n\n/**\n * Get an instance of a provider for a specific chain\n * @param client - The SDK client\n * @param chainId - Id of the chain the provider is for\n * @returns The public client for the given chain\n */\nexport const getBitcoinPublicClient = async (\n client: SDKClient,\n chainId: number\n): Promise<PublicClient> => {\n if (!publicClients[chainId]) {\n const urls = await client.getRpcUrlsByChainId(chainId)\n const fallbackTransports = urls.map((url) =>\n http(url, {\n fetchOptions: {\n method: 'POST',\n },\n })\n )\n const _chain = await client.getChainById(chainId)\n const chain: Chain = {\n ..._chain,\n ..._chain.metamask,\n id: toBigmiChainId(_chain.id),\n name: _chain.metamask.chainName,\n rpcUrls: {\n default: { http: _chain.metamask.rpcUrls },\n public: { http: _chain.metamask.rpcUrls },\n },\n }\n const bigmiClient = createClient({\n chain,\n rpcSchema: rpcSchema<UTXOSchema>(),\n transport: fallback([\n blockchair(),\n blockcypher(),\n mempool(),\n ...fallbackTransports,\n ]),\n pollingInterval: 10_000,\n })\n .extend(publicActions)\n .extend(walletActions)\n publicClients[chainId] = bigmiClient\n }\n\n if (!publicClients[chainId]) {\n throw new Error(`Unable to configure provider for chain ${chainId}`)\n }\n\n return publicClients[chainId]\n}\n"],"mappings":";;;AA+BA,MAAM,gBAA8C,EAAE;;;;;;;AAQtD,MAAa,yBAAyB,OACpC,QACA,YAC0B;
|
|
1
|
+
{"version":3,"file":"publicClient.js","names":[],"sources":["../../../src/client/publicClient.ts"],"sourcesContent":["import {\n type Account,\n blockchair,\n blockcypher,\n type Chain,\n type Client,\n createClient,\n type FallbackTransport,\n fallback,\n type HttpTransport,\n http,\n mempool,\n type PublicActions,\n publicActions,\n rpcSchema,\n type UTXOSchema,\n type WalletActions,\n walletActions,\n} from '@bigmi/core'\nimport type { SDKClient } from '@lifi/sdk'\nimport { toBigmiChainId } from '../utils/toBigmiChainId.js'\n\nexport type PublicClient = Client<\n FallbackTransport<readonly HttpTransport[]>,\n Chain,\n Account | undefined,\n UTXOSchema,\n PublicActions & WalletActions\n>\n\n// cached providers\nconst publicClients: Record<number, PublicClient> = {}\n\n/**\n * Get an instance of a provider for a specific chain\n * @param client - The SDK client\n * @param chainId - Id of the chain the provider is for\n * @returns The public client for the given chain\n */\nexport const getBitcoinPublicClient = async (\n client: SDKClient,\n chainId: number\n): Promise<PublicClient> => {\n if (!publicClients[chainId]) {\n const urls = await client.getRpcUrlsByChainId(chainId)\n const fallbackTransports = urls.map((url) =>\n http(url, {\n fetchOptions: {\n method: 'POST',\n },\n })\n )\n const _chain = await client.getChainById(chainId)\n const chain: Chain = {\n ..._chain,\n ..._chain.metamask,\n id: toBigmiChainId(_chain.id),\n name: _chain.metamask.chainName,\n rpcUrls: {\n default: { http: _chain.metamask.rpcUrls },\n public: { http: _chain.metamask.rpcUrls },\n },\n }\n const bigmiClient = createClient({\n chain,\n rpcSchema: rpcSchema<UTXOSchema>(),\n transport: fallback([\n blockchair(),\n blockcypher(),\n mempool(),\n ...fallbackTransports,\n ]),\n pollingInterval: 10_000,\n })\n .extend(publicActions)\n .extend(walletActions)\n publicClients[chainId] = bigmiClient\n }\n\n if (!publicClients[chainId]) {\n throw new Error(`Unable to configure provider for chain ${chainId}`)\n }\n\n return publicClients[chainId]\n}\n"],"mappings":";;;AA+BA,MAAM,gBAA8C,EAAE;;;;;;;AAQtD,MAAa,yBAAyB,OACpC,QACA,YAC0B;CAC1B,IAAI,CAAC,cAAc,UAAU;EAE3B,MAAM,sBAAqB,MADR,OAAO,oBAAoB,QAAQ,EACtB,KAAK,QACnC,KAAK,KAAK,EACR,cAAc,EACZ,QAAQ,QACT,EACF,CAAC,CACH;EACD,MAAM,SAAS,MAAM,OAAO,aAAa,QAAQ;EAwBjD,cAAc,WAbM,aAAa;GAC/B,OAAA;IAVA,GAAG;IACH,GAAG,OAAO;IACV,IAAI,eAAe,OAAO,GAAG;IAC7B,MAAM,OAAO,SAAS;IACtB,SAAS;KACP,SAAS,EAAE,MAAM,OAAO,SAAS,SAAS;KAC1C,QAAQ,EAAE,MAAM,OAAO,SAAS,SAAS;KAC1C;IAGI;GACL,WAAW,WAAuB;GAClC,WAAW,SAAS;IAClB,YAAY;IACZ,aAAa;IACb,SAAS;IACT,GAAG;IACJ,CAAC;GACF,iBAAiB;GAClB,CAAC,CACC,OAAO,cAAc,CACrB,OAAO,cAC0B;;CAGtC,IAAI,CAAC,cAAc,UACjB,MAAM,IAAI,MAAM,0CAA0C,UAAU;CAGtE,OAAO,cAAc"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"BitcoinStepExecutor.js","names":[],"sources":["../../../src/core/BitcoinStepExecutor.ts"],"sourcesContent":["import type { Client } from '@bigmi/core'\nimport {\n BaseStepExecutor,\n CheckBalanceTask,\n type ExecutionAction,\n LiFiErrorCode,\n type LiFiStepExtended,\n PrepareTransactionTask,\n type SDKError,\n type StepExecutorBaseContext,\n type StepExecutorOptions,\n TaskPipeline,\n TransactionError,\n WaitForTransactionStatusTask,\n} from '@lifi/sdk'\nimport { getBitcoinPublicClient } from '../client/publicClient.js'\nimport { parseBitcoinErrors } from '../errors/parseBitcoinErrors.js'\nimport type { BitcoinStepExecutorContext } from '../types.js'\nimport { BitcoinSignAndExecuteTask } from './tasks/BitcoinSignAndExecuteTask.js'\nimport { BitcoinWaitForTransactionTask } from './tasks/BitcoinWaitForTransactionTask.js'\n\ninterface BitcoinStepExecutorOptions extends StepExecutorOptions {\n client: Client\n}\n\nexport class BitcoinStepExecutor extends BaseStepExecutor {\n private client: Client\n\n constructor(options: BitcoinStepExecutorOptions) {\n super(options)\n this.client = options.client\n }\n\n checkClient = (step: LiFiStepExtended): void => {\n // TODO: check chain and possibly implement chain switch?\n // Prevent execution of the quote by wallet different from the one which requested the quote\n if (this.client.account?.address !== step.action.fromAddress) {\n throw new TransactionError(\n LiFiErrorCode.WalletChangedDuringExecution,\n 'The wallet address that requested the quote does not match the wallet address attempting to sign the transaction.'\n )\n }\n }\n\n override createPipeline = (\n context: BitcoinStepExecutorContext\n ): TaskPipeline => {\n const { step, isBridgeExecution } = context\n\n const tasks = [\n new CheckBalanceTask(),\n new PrepareTransactionTask(),\n new BitcoinSignAndExecuteTask(),\n new BitcoinWaitForTransactionTask(),\n new WaitForTransactionStatusTask(\n isBridgeExecution ? 'RECEIVING_CHAIN' : 'SWAP'\n ),\n ]\n const swapOrBridgeAction = this.statusManager.findAction(\n step,\n isBridgeExecution ? 'CROSS_CHAIN' : 'SWAP'\n )\n\n const taskName = swapOrBridgeAction?.txHash\n ? swapOrBridgeAction?.status === 'DONE'\n ? WaitForTransactionStatusTask.name\n : BitcoinWaitForTransactionTask.name\n : CheckBalanceTask.name\n\n const firstTaskIndex = tasks.findIndex(\n (task) => task.constructor.name === taskName\n )\n\n const tasksToRun = tasks.slice(firstTaskIndex)\n\n return new TaskPipeline(tasksToRun)\n }\n\n override parseErrors = (\n error: Error,\n step?: LiFiStepExtended,\n action?: ExecutionAction\n ): Promise<SDKError> => parseBitcoinErrors(error, step, action)\n\n override createContext = async (\n baseContext: StepExecutorBaseContext\n ): Promise<BitcoinStepExecutorContext> => {\n const { client, fromChain } = baseContext\n\n const publicClient = await getBitcoinPublicClient(client, fromChain.id)\n\n return {\n ...baseContext,\n pollingIntervalMs: 10_000,\n checkClient: this.checkClient,\n walletClient: this.client,\n publicClient,\n }\n }\n}\n"],"mappings":";;;;;;AAyBA,IAAa,sBAAb,cAAyC,iBAAiB;CACxD;CAEA,YAAY,SAAqC;
|
|
1
|
+
{"version":3,"file":"BitcoinStepExecutor.js","names":[],"sources":["../../../src/core/BitcoinStepExecutor.ts"],"sourcesContent":["import type { Client } from '@bigmi/core'\nimport {\n BaseStepExecutor,\n CheckBalanceTask,\n type ExecutionAction,\n LiFiErrorCode,\n type LiFiStepExtended,\n PrepareTransactionTask,\n type SDKError,\n type StepExecutorBaseContext,\n type StepExecutorOptions,\n TaskPipeline,\n TransactionError,\n WaitForTransactionStatusTask,\n} from '@lifi/sdk'\nimport { getBitcoinPublicClient } from '../client/publicClient.js'\nimport { parseBitcoinErrors } from '../errors/parseBitcoinErrors.js'\nimport type { BitcoinStepExecutorContext } from '../types.js'\nimport { BitcoinSignAndExecuteTask } from './tasks/BitcoinSignAndExecuteTask.js'\nimport { BitcoinWaitForTransactionTask } from './tasks/BitcoinWaitForTransactionTask.js'\n\ninterface BitcoinStepExecutorOptions extends StepExecutorOptions {\n client: Client\n}\n\nexport class BitcoinStepExecutor extends BaseStepExecutor {\n private client: Client\n\n constructor(options: BitcoinStepExecutorOptions) {\n super(options)\n this.client = options.client\n }\n\n checkClient = (step: LiFiStepExtended): void => {\n // TODO: check chain and possibly implement chain switch?\n // Prevent execution of the quote by wallet different from the one which requested the quote\n if (this.client.account?.address !== step.action.fromAddress) {\n throw new TransactionError(\n LiFiErrorCode.WalletChangedDuringExecution,\n 'The wallet address that requested the quote does not match the wallet address attempting to sign the transaction.'\n )\n }\n }\n\n override createPipeline = (\n context: BitcoinStepExecutorContext\n ): TaskPipeline => {\n const { step, isBridgeExecution } = context\n\n const tasks = [\n new CheckBalanceTask(),\n new PrepareTransactionTask(),\n new BitcoinSignAndExecuteTask(),\n new BitcoinWaitForTransactionTask(),\n new WaitForTransactionStatusTask(\n isBridgeExecution ? 'RECEIVING_CHAIN' : 'SWAP'\n ),\n ]\n const swapOrBridgeAction = this.statusManager.findAction(\n step,\n isBridgeExecution ? 'CROSS_CHAIN' : 'SWAP'\n )\n\n const taskName = swapOrBridgeAction?.txHash\n ? swapOrBridgeAction?.status === 'DONE'\n ? WaitForTransactionStatusTask.name\n : BitcoinWaitForTransactionTask.name\n : CheckBalanceTask.name\n\n const firstTaskIndex = tasks.findIndex(\n (task) => task.constructor.name === taskName\n )\n\n const tasksToRun = tasks.slice(firstTaskIndex)\n\n return new TaskPipeline(tasksToRun)\n }\n\n override parseErrors = (\n error: Error,\n step?: LiFiStepExtended,\n action?: ExecutionAction\n ): Promise<SDKError> => parseBitcoinErrors(error, step, action)\n\n override createContext = async (\n baseContext: StepExecutorBaseContext\n ): Promise<BitcoinStepExecutorContext> => {\n const { client, fromChain } = baseContext\n\n const publicClient = await getBitcoinPublicClient(client, fromChain.id)\n\n return {\n ...baseContext,\n pollingIntervalMs: 10_000,\n checkClient: this.checkClient,\n walletClient: this.client,\n publicClient,\n }\n }\n}\n"],"mappings":";;;;;;AAyBA,IAAa,sBAAb,cAAyC,iBAAiB;CACxD;CAEA,YAAY,SAAqC;EAC/C,MAAM,QAAQ;EACd,KAAK,SAAS,QAAQ;;CAGxB,eAAe,SAAiC;EAG9C,IAAI,KAAK,OAAO,SAAS,YAAY,KAAK,OAAO,aAC/C,MAAM,IAAI,iBACR,cAAc,8BACd,oHACD;;CAIL,kBACE,YACiB;EACjB,MAAM,EAAE,MAAM,sBAAsB;EAEpC,MAAM,QAAQ;GACZ,IAAI,kBAAkB;GACtB,IAAI,wBAAwB;GAC5B,IAAI,2BAA2B;GAC/B,IAAI,+BAA+B;GACnC,IAAI,6BACF,oBAAoB,oBAAoB,OACzC;GACF;EACD,MAAM,qBAAqB,KAAK,cAAc,WAC5C,MACA,oBAAoB,gBAAgB,OACrC;EAED,MAAM,WAAW,oBAAoB,SACjC,oBAAoB,WAAW,SAC7B,6BAA6B,OAC7B,8BAA8B,OAChC,iBAAiB;EAErB,MAAM,iBAAiB,MAAM,WAC1B,SAAS,KAAK,YAAY,SAAS,SACrC;EAID,OAAO,IAAI,aAFQ,MAAM,MAAM,eAEG,CAAC;;CAGrC,eACE,OACA,MACA,WACsB,mBAAmB,OAAO,MAAM,OAAO;CAE/D,gBAAyB,OACvB,gBACwC;EACxC,MAAM,EAAE,QAAQ,cAAc;EAE9B,MAAM,eAAe,MAAM,uBAAuB,QAAQ,UAAU,GAAG;EAEvE,OAAO;GACL,GAAG;GACH,mBAAmB;GACnB,aAAa,KAAK;GAClB,cAAc,KAAK;GACnB;GACD"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"BitcoinSignAndExecuteTask.js","names":[],"sources":["../../../../src/core/tasks/BitcoinSignAndExecuteTask.ts"],"sourcesContent":["import {\n AddressType,\n getAddressInfo,\n hexToUnit8Array,\n signPsbt,\n withTimeout,\n} from '@bigmi/core'\nimport * as ecc from '@bitcoinerlab/secp256k1'\nimport {\n BaseStepExecutionTask,\n getTransactionRequestData,\n LiFiErrorCode,\n type TaskResult,\n TransactionError,\n} from '@lifi/sdk'\nimport { address, initEccLib, networks, Psbt } from 'bitcoinjs-lib'\nimport type { BitcoinStepExecutorContext } from '../../types.js'\nimport { generateRedeemScript } from '../../utils/generateRedeemScript.js'\nimport { isPsbtFinalized } from '../../utils/isPsbtFinalized.js'\nimport { toXOnly } from '../../utils/toXOnly.js'\n\nexport class BitcoinSignAndExecuteTask extends BaseStepExecutionTask {\n async run(context: BitcoinStepExecutorContext): Promise<TaskResult> {\n const {\n step,\n walletClient,\n statusManager,\n executionOptions,\n fromChain,\n publicClient,\n checkClient,\n isBridgeExecution,\n } = context\n\n const action = statusManager.findAction(\n step,\n isBridgeExecution ? 'CROSS_CHAIN' : 'SWAP'\n )\n\n if (!action) {\n throw new TransactionError(\n LiFiErrorCode.TransactionUnprepared,\n 'Unable to prepare transaction. Action not found.'\n )\n }\n\n const transactionRequestData = await getTransactionRequestData(\n step,\n executionOptions\n )\n\n checkClient(step)\n\n const psbtHex = transactionRequestData\n\n // Initialize ECC library required for Taproot operations\n // https://github.com/bitcoinjs/bitcoinjs-lib?tab=readme-ov-file#using-taproot\n initEccLib(ecc)\n\n const psbt = Psbt.fromHex(psbtHex, { network: networks.bitcoin })\n\n psbt.data.inputs.forEach((input, index) => {\n const accountAddress = input.witnessUtxo\n ? address.fromOutputScript(input.witnessUtxo.script, networks.bitcoin)\n : (walletClient.account?.address as string)\n const addressInfo = getAddressInfo(accountAddress)\n if (addressInfo.type === AddressType.p2tr) {\n // Taproot (P2TR) addresses require specific PSBT fields for proper signing\n\n // tapInternalKey: Required for Taproot key-path spending\n // Most wallets / libraries usually handle this already\n if (!input.tapInternalKey) {\n const pubKey = walletClient.account?.publicKey\n if (pubKey) {\n const tapInternalKey = toXOnly(hexToUnit8Array(pubKey))\n psbt.updateInput(index, {\n tapInternalKey,\n })\n }\n }\n // sighashType: Required by bitcoinjs-lib even though the bitcoin protocol allows defaults\n // check if sighashType is default (0) or not set (undefined)\n if (!input.sighashType) {\n psbt.updateInput(index, {\n sighashType: 1, // Default to Transaction.SIGHASH_ALL - 1\n })\n }\n }\n // redeemScript: Required by Pay-to-Script-Hash (P2SH) addresses for proper spending\n if (addressInfo.type === AddressType.p2sh) {\n if (!input.redeemScript) {\n const pubKey = walletClient.account?.publicKey\n if (pubKey) {\n psbt.updateInput(index, {\n redeemScript: generateRedeemScript(hexToUnit8Array(pubKey)),\n })\n }\n }\n }\n })\n\n const inputsToSign = Array.from(\n psbt.data.inputs\n .reduce((map, input, index) => {\n const accountAddress = input.witnessUtxo\n ? address.fromOutputScript(\n input.witnessUtxo.script,\n networks.bitcoin\n )\n : (walletClient.account?.address as string)\n if (map.has(accountAddress)) {\n map.get(accountAddress)!.signingIndexes.push(index)\n } else {\n map.set(accountAddress, {\n address: accountAddress,\n sigHash: 1, // Default to Transaction.SIGHASH_ALL - 1\n signingIndexes: [index],\n })\n }\n return map\n }, new Map<\n string,\n { address: string; sigHash: number; signingIndexes: number[] }\n >())\n .values()\n )\n\n // We give users 10 minutes to sign the transaction or it should be considered expired\n const signedPsbtHex = await withTimeout(\n () =>\n signPsbt(walletClient, {\n psbt: psbt.toHex(),\n inputsToSign: inputsToSign,\n finalize: false,\n }),\n {\n timeout: 600_000,\n errorInstance: new TransactionError(\n LiFiErrorCode.TransactionExpired,\n 'Transaction has expired.'\n ),\n }\n )\n\n const signedPsbt = Psbt.fromHex(signedPsbtHex)\n\n if (!isPsbtFinalized(signedPsbt)) {\n signedPsbt.finalizeAllInputs()\n }\n\n const txHex = signedPsbt.extractTransaction().toHex()\n\n const txHash = await publicClient.sendUTXOTransaction({\n hex: txHex,\n })\n\n statusManager.updateAction(step, action.type, 'PENDING', {\n txHash: txHash,\n txLink: `${fromChain.metamask.blockExplorerUrls[0]}tx/${txHash}`,\n txHex,\n signedAt: Date.now(),\n })\n\n return {\n status: 'COMPLETED',\n }\n }\n}\n"],"mappings":";;;;;;;;AAqBA,IAAa,4BAAb,cAA+C,sBAAsB;CACnE,MAAM,IAAI,SAA0D;EAClE,MAAM,EACJ,MACA,cACA,eACA,kBACA,WACA,cACA,aACA,sBACE;EAEJ,MAAM,SAAS,cAAc,WAC3B,MACA,oBAAoB,gBAAgB,OACrC;
|
|
1
|
+
{"version":3,"file":"BitcoinSignAndExecuteTask.js","names":[],"sources":["../../../../src/core/tasks/BitcoinSignAndExecuteTask.ts"],"sourcesContent":["import {\n AddressType,\n getAddressInfo,\n hexToUnit8Array,\n signPsbt,\n withTimeout,\n} from '@bigmi/core'\nimport * as ecc from '@bitcoinerlab/secp256k1'\nimport {\n BaseStepExecutionTask,\n getTransactionRequestData,\n LiFiErrorCode,\n type TaskResult,\n TransactionError,\n} from '@lifi/sdk'\nimport { address, initEccLib, networks, Psbt } from 'bitcoinjs-lib'\nimport type { BitcoinStepExecutorContext } from '../../types.js'\nimport { generateRedeemScript } from '../../utils/generateRedeemScript.js'\nimport { isPsbtFinalized } from '../../utils/isPsbtFinalized.js'\nimport { toXOnly } from '../../utils/toXOnly.js'\n\nexport class BitcoinSignAndExecuteTask extends BaseStepExecutionTask {\n async run(context: BitcoinStepExecutorContext): Promise<TaskResult> {\n const {\n step,\n walletClient,\n statusManager,\n executionOptions,\n fromChain,\n publicClient,\n checkClient,\n isBridgeExecution,\n } = context\n\n const action = statusManager.findAction(\n step,\n isBridgeExecution ? 'CROSS_CHAIN' : 'SWAP'\n )\n\n if (!action) {\n throw new TransactionError(\n LiFiErrorCode.TransactionUnprepared,\n 'Unable to prepare transaction. Action not found.'\n )\n }\n\n const transactionRequestData = await getTransactionRequestData(\n step,\n executionOptions\n )\n\n checkClient(step)\n\n const psbtHex = transactionRequestData\n\n // Initialize ECC library required for Taproot operations\n // https://github.com/bitcoinjs/bitcoinjs-lib?tab=readme-ov-file#using-taproot\n initEccLib(ecc)\n\n const psbt = Psbt.fromHex(psbtHex, { network: networks.bitcoin })\n\n psbt.data.inputs.forEach((input, index) => {\n const accountAddress = input.witnessUtxo\n ? address.fromOutputScript(input.witnessUtxo.script, networks.bitcoin)\n : (walletClient.account?.address as string)\n const addressInfo = getAddressInfo(accountAddress)\n if (addressInfo.type === AddressType.p2tr) {\n // Taproot (P2TR) addresses require specific PSBT fields for proper signing\n\n // tapInternalKey: Required for Taproot key-path spending\n // Most wallets / libraries usually handle this already\n if (!input.tapInternalKey) {\n const pubKey = walletClient.account?.publicKey\n if (pubKey) {\n const tapInternalKey = toXOnly(hexToUnit8Array(pubKey))\n psbt.updateInput(index, {\n tapInternalKey,\n })\n }\n }\n // sighashType: Required by bitcoinjs-lib even though the bitcoin protocol allows defaults\n // check if sighashType is default (0) or not set (undefined)\n if (!input.sighashType) {\n psbt.updateInput(index, {\n sighashType: 1, // Default to Transaction.SIGHASH_ALL - 1\n })\n }\n }\n // redeemScript: Required by Pay-to-Script-Hash (P2SH) addresses for proper spending\n if (addressInfo.type === AddressType.p2sh) {\n if (!input.redeemScript) {\n const pubKey = walletClient.account?.publicKey\n if (pubKey) {\n psbt.updateInput(index, {\n redeemScript: generateRedeemScript(hexToUnit8Array(pubKey)),\n })\n }\n }\n }\n })\n\n const inputsToSign = Array.from(\n psbt.data.inputs\n .reduce((map, input, index) => {\n const accountAddress = input.witnessUtxo\n ? address.fromOutputScript(\n input.witnessUtxo.script,\n networks.bitcoin\n )\n : (walletClient.account?.address as string)\n if (map.has(accountAddress)) {\n map.get(accountAddress)!.signingIndexes.push(index)\n } else {\n map.set(accountAddress, {\n address: accountAddress,\n sigHash: 1, // Default to Transaction.SIGHASH_ALL - 1\n signingIndexes: [index],\n })\n }\n return map\n }, new Map<\n string,\n { address: string; sigHash: number; signingIndexes: number[] }\n >())\n .values()\n )\n\n // We give users 10 minutes to sign the transaction or it should be considered expired\n const signedPsbtHex = await withTimeout(\n () =>\n signPsbt(walletClient, {\n psbt: psbt.toHex(),\n inputsToSign: inputsToSign,\n finalize: false,\n }),\n {\n timeout: 600_000,\n errorInstance: new TransactionError(\n LiFiErrorCode.TransactionExpired,\n 'Transaction has expired.'\n ),\n }\n )\n\n const signedPsbt = Psbt.fromHex(signedPsbtHex)\n\n if (!isPsbtFinalized(signedPsbt)) {\n signedPsbt.finalizeAllInputs()\n }\n\n const txHex = signedPsbt.extractTransaction().toHex()\n\n const txHash = await publicClient.sendUTXOTransaction({\n hex: txHex,\n })\n\n statusManager.updateAction(step, action.type, 'PENDING', {\n txHash: txHash,\n txLink: `${fromChain.metamask.blockExplorerUrls[0]}tx/${txHash}`,\n txHex,\n signedAt: Date.now(),\n })\n\n return {\n status: 'COMPLETED',\n }\n }\n}\n"],"mappings":";;;;;;;;AAqBA,IAAa,4BAAb,cAA+C,sBAAsB;CACnE,MAAM,IAAI,SAA0D;EAClE,MAAM,EACJ,MACA,cACA,eACA,kBACA,WACA,cACA,aACA,sBACE;EAEJ,MAAM,SAAS,cAAc,WAC3B,MACA,oBAAoB,gBAAgB,OACrC;EAED,IAAI,CAAC,QACH,MAAM,IAAI,iBACR,cAAc,uBACd,mDACD;EAGH,MAAM,yBAAyB,MAAM,0BACnC,MACA,iBACD;EAED,YAAY,KAAK;EAEjB,MAAM,UAAU;EAIhB,WAAW,IAAI;EAEf,MAAM,OAAO,KAAK,QAAQ,SAAS,EAAE,SAAS,SAAS,SAAS,CAAC;EAEjE,KAAK,KAAK,OAAO,SAAS,OAAO,UAAU;GAIzC,MAAM,cAAc,eAHG,MAAM,cACzB,QAAQ,iBAAiB,MAAM,YAAY,QAAQ,SAAS,QAAQ,GACnE,aAAa,SAAS,QACuB;GAClD,IAAI,YAAY,SAAS,YAAY,MAAM;IAKzC,IAAI,CAAC,MAAM,gBAAgB;KACzB,MAAM,SAAS,aAAa,SAAS;KACrC,IAAI,QAAQ;MACV,MAAM,iBAAiB,QAAQ,gBAAgB,OAAO,CAAC;MACvD,KAAK,YAAY,OAAO,EACtB,gBACD,CAAC;;;IAKN,IAAI,CAAC,MAAM,aACT,KAAK,YAAY,OAAO,EACtB,aAAa,GACd,CAAC;;GAIN,IAAI,YAAY,SAAS,YAAY;QAC/B,CAAC,MAAM,cAAc;KACvB,MAAM,SAAS,aAAa,SAAS;KACrC,IAAI,QACF,KAAK,YAAY,OAAO,EACtB,cAAc,qBAAqB,gBAAgB,OAAO,CAAC,EAC5D,CAAC;;;IAIR;EAEF,MAAM,eAAe,MAAM,KACzB,KAAK,KAAK,OACP,QAAQ,KAAK,OAAO,UAAU;GAC7B,MAAM,iBAAiB,MAAM,cACzB,QAAQ,iBACN,MAAM,YAAY,QAClB,SAAS,QACV,GACA,aAAa,SAAS;GAC3B,IAAI,IAAI,IAAI,eAAe,EACzB,IAAI,IAAI,eAAe,CAAE,eAAe,KAAK,MAAM;QAEnD,IAAI,IAAI,gBAAgB;IACtB,SAAS;IACT,SAAS;IACT,gBAAgB,CAAC,MAAM;IACxB,CAAC;GAEJ,OAAO;qBACN,IAAI,KAGJ,CAAC,CACH,QAAQ,CACZ;EAGD,MAAM,gBAAgB,MAAM,kBAExB,SAAS,cAAc;GACrB,MAAM,KAAK,OAAO;GACJ;GACd,UAAU;GACX,CAAC,EACJ;GACE,SAAS;GACT,eAAe,IAAI,iBACjB,cAAc,oBACd,2BACD;GACF,CACF;EAED,MAAM,aAAa,KAAK,QAAQ,cAAc;EAE9C,IAAI,CAAC,gBAAgB,WAAW,EAC9B,WAAW,mBAAmB;EAGhC,MAAM,QAAQ,WAAW,oBAAoB,CAAC,OAAO;EAErD,MAAM,SAAS,MAAM,aAAa,oBAAoB,EACpD,KAAK,OACN,CAAC;EAEF,cAAc,aAAa,MAAM,OAAO,MAAM,WAAW;GAC/C;GACR,QAAQ,GAAG,UAAU,SAAS,kBAAkB,GAAG,KAAK;GACxD;GACA,UAAU,KAAK,KAAK;GACrB,CAAC;EAEF,OAAO,EACL,QAAQ,aACT"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"BitcoinWaitForTransactionTask.js","names":[],"sources":["../../../../src/core/tasks/BitcoinWaitForTransactionTask.ts"],"sourcesContent":["import type { ReplacementReason } from '@bigmi/core'\nimport { waitForTransaction } from '@bigmi/core'\nimport {\n BaseStepExecutionTask,\n LiFiErrorCode,\n type TaskResult,\n TransactionError,\n} from '@lifi/sdk'\nimport type { BitcoinStepExecutorContext } from '../../types.js'\n\nexport class BitcoinWaitForTransactionTask extends BaseStepExecutionTask {\n async run(context: BitcoinStepExecutorContext): Promise<TaskResult> {\n const {\n step,\n statusManager,\n fromChain,\n isBridgeExecution,\n walletClient,\n publicClient,\n checkClient,\n } = context\n\n const action = statusManager.findAction(\n step,\n isBridgeExecution ? 'CROSS_CHAIN' : 'SWAP'\n )\n\n const txHex = action?.txHex\n const txHash = action?.txHash\n\n if (!txHash || !txHex) {\n throw new TransactionError(\n LiFiErrorCode.TransactionUnprepared,\n 'Unable to prepare transaction. Transaction hash or hex is not set.'\n )\n }\n\n checkClient(step)\n\n let replacementReason: ReplacementReason | undefined\n const transaction = await waitForTransaction(publicClient, {\n txId: txHash,\n txHex,\n senderAddress: walletClient.account?.address,\n onReplaced: (response) => {\n replacementReason = response.reason\n statusManager.updateAction(step, action.type, 'PENDING', {\n txHash: response.transaction.txid,\n txLink: `${fromChain.metamask.blockExplorerUrls[0]}tx/${response.transaction.txid}`,\n })\n },\n })\n\n if (replacementReason === 'cancelled') {\n throw new TransactionError(\n LiFiErrorCode.TransactionCanceled,\n 'User canceled transaction.'\n )\n }\n\n if (transaction.txid !== txHash) {\n statusManager.updateAction(step, action.type, 'PENDING', {\n txHash: transaction.txid,\n txLink: `${fromChain.metamask.blockExplorerUrls[0]}tx/${transaction.txid}`,\n })\n }\n\n if (isBridgeExecution) {\n statusManager.updateAction(step, action.type, 'DONE')\n }\n\n return { status: 'COMPLETED' }\n }\n}\n"],"mappings":";;;AAUA,IAAa,gCAAb,cAAmD,sBAAsB;CACvE,MAAM,IAAI,SAA0D;EAClE,MAAM,EACJ,MACA,eACA,WACA,mBACA,cACA,cACA,gBACE;EAEJ,MAAM,SAAS,cAAc,WAC3B,MACA,oBAAoB,gBAAgB,OACrC;EAED,MAAM,QAAQ,QAAQ;EACtB,MAAM,SAAS,QAAQ;
|
|
1
|
+
{"version":3,"file":"BitcoinWaitForTransactionTask.js","names":[],"sources":["../../../../src/core/tasks/BitcoinWaitForTransactionTask.ts"],"sourcesContent":["import type { ReplacementReason } from '@bigmi/core'\nimport { waitForTransaction } from '@bigmi/core'\nimport {\n BaseStepExecutionTask,\n LiFiErrorCode,\n type TaskResult,\n TransactionError,\n} from '@lifi/sdk'\nimport type { BitcoinStepExecutorContext } from '../../types.js'\n\nexport class BitcoinWaitForTransactionTask extends BaseStepExecutionTask {\n async run(context: BitcoinStepExecutorContext): Promise<TaskResult> {\n const {\n step,\n statusManager,\n fromChain,\n isBridgeExecution,\n walletClient,\n publicClient,\n checkClient,\n } = context\n\n const action = statusManager.findAction(\n step,\n isBridgeExecution ? 'CROSS_CHAIN' : 'SWAP'\n )\n\n const txHex = action?.txHex\n const txHash = action?.txHash\n\n if (!txHash || !txHex) {\n throw new TransactionError(\n LiFiErrorCode.TransactionUnprepared,\n 'Unable to prepare transaction. Transaction hash or hex is not set.'\n )\n }\n\n checkClient(step)\n\n let replacementReason: ReplacementReason | undefined\n const transaction = await waitForTransaction(publicClient, {\n txId: txHash,\n txHex,\n senderAddress: walletClient.account?.address,\n onReplaced: (response) => {\n replacementReason = response.reason\n statusManager.updateAction(step, action.type, 'PENDING', {\n txHash: response.transaction.txid,\n txLink: `${fromChain.metamask.blockExplorerUrls[0]}tx/${response.transaction.txid}`,\n })\n },\n })\n\n if (replacementReason === 'cancelled') {\n throw new TransactionError(\n LiFiErrorCode.TransactionCanceled,\n 'User canceled transaction.'\n )\n }\n\n if (transaction.txid !== txHash) {\n statusManager.updateAction(step, action.type, 'PENDING', {\n txHash: transaction.txid,\n txLink: `${fromChain.metamask.blockExplorerUrls[0]}tx/${transaction.txid}`,\n })\n }\n\n if (isBridgeExecution) {\n statusManager.updateAction(step, action.type, 'DONE')\n }\n\n return { status: 'COMPLETED' }\n }\n}\n"],"mappings":";;;AAUA,IAAa,gCAAb,cAAmD,sBAAsB;CACvE,MAAM,IAAI,SAA0D;EAClE,MAAM,EACJ,MACA,eACA,WACA,mBACA,cACA,cACA,gBACE;EAEJ,MAAM,SAAS,cAAc,WAC3B,MACA,oBAAoB,gBAAgB,OACrC;EAED,MAAM,QAAQ,QAAQ;EACtB,MAAM,SAAS,QAAQ;EAEvB,IAAI,CAAC,UAAU,CAAC,OACd,MAAM,IAAI,iBACR,cAAc,uBACd,qEACD;EAGH,YAAY,KAAK;EAEjB,IAAI;EACJ,MAAM,cAAc,MAAM,mBAAmB,cAAc;GACzD,MAAM;GACN;GACA,eAAe,aAAa,SAAS;GACrC,aAAa,aAAa;IACxB,oBAAoB,SAAS;IAC7B,cAAc,aAAa,MAAM,OAAO,MAAM,WAAW;KACvD,QAAQ,SAAS,YAAY;KAC7B,QAAQ,GAAG,UAAU,SAAS,kBAAkB,GAAG,KAAK,SAAS,YAAY;KAC9E,CAAC;;GAEL,CAAC;EAEF,IAAI,sBAAsB,aACxB,MAAM,IAAI,iBACR,cAAc,qBACd,6BACD;EAGH,IAAI,YAAY,SAAS,QACvB,cAAc,aAAa,MAAM,OAAO,MAAM,WAAW;GACvD,QAAQ,YAAY;GACpB,QAAQ,GAAG,UAAU,SAAS,kBAAkB,GAAG,KAAK,YAAY;GACrE,CAAC;EAGJ,IAAI,mBACF,cAAc,aAAa,MAAM,OAAO,MAAM,OAAO;EAGvD,OAAO,EAAE,QAAQ,aAAa"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"parseBitcoinErrors.js","names":[],"sources":["../../../src/errors/parseBitcoinErrors.ts"],"sourcesContent":["import {\n BaseError,\n ErrorMessage,\n type ExecutionAction,\n LiFiErrorCode,\n type LiFiStep,\n SDKError,\n TransactionError,\n UnknownError,\n} from '@lifi/sdk'\n\nexport const parseBitcoinErrors = async (\n e: Error,\n step?: LiFiStep,\n action?: ExecutionAction\n): Promise<SDKError> => {\n if (e instanceof SDKError) {\n e.step = e.step ?? step\n e.action = e.action ?? action\n return e\n }\n\n const baseError = handleSpecificErrors(e)\n\n return new SDKError(baseError, step, action)\n}\n\nconst handleSpecificErrors = (e: any) => {\n // txn-mempool-conflict\n if (\n e.details?.includes?.('conflict') ||\n e.cause?.message?.includes?.('conflict')\n ) {\n return new TransactionError(\n LiFiErrorCode.TransactionConflict,\n 'Your transaction conflicts with another transaction already in the mempool. One or more inputs have been spent by another transaction.',\n e\n )\n }\n if (e.code === 4001 || e.code === -32000 || e.cause?.includes?.('rejected')) {\n return new TransactionError(LiFiErrorCode.SignatureRejected, e.message, e)\n }\n if (e.code === -5 || e.code === -32700 || e.code === -32064) {\n return new TransactionError(LiFiErrorCode.NotFound, e.message, e)\n }\n\n if (e instanceof BaseError) {\n return e\n }\n\n return new UnknownError(e.message || ErrorMessage.UnknownError, e)\n}\n"],"mappings":";;AAWA,MAAa,qBAAqB,OAChC,GACA,MACA,WACsB;
|
|
1
|
+
{"version":3,"file":"parseBitcoinErrors.js","names":[],"sources":["../../../src/errors/parseBitcoinErrors.ts"],"sourcesContent":["import {\n BaseError,\n ErrorMessage,\n type ExecutionAction,\n LiFiErrorCode,\n type LiFiStep,\n SDKError,\n TransactionError,\n UnknownError,\n} from '@lifi/sdk'\n\nexport const parseBitcoinErrors = async (\n e: Error,\n step?: LiFiStep,\n action?: ExecutionAction\n): Promise<SDKError> => {\n if (e instanceof SDKError) {\n e.step = e.step ?? step\n e.action = e.action ?? action\n return e\n }\n\n const baseError = handleSpecificErrors(e)\n\n return new SDKError(baseError, step, action)\n}\n\nconst handleSpecificErrors = (e: any) => {\n // txn-mempool-conflict\n if (\n e.details?.includes?.('conflict') ||\n e.cause?.message?.includes?.('conflict')\n ) {\n return new TransactionError(\n LiFiErrorCode.TransactionConflict,\n 'Your transaction conflicts with another transaction already in the mempool. One or more inputs have been spent by another transaction.',\n e\n )\n }\n if (e.code === 4001 || e.code === -32000 || e.cause?.includes?.('rejected')) {\n return new TransactionError(LiFiErrorCode.SignatureRejected, e.message, e)\n }\n if (e.code === -5 || e.code === -32700 || e.code === -32064) {\n return new TransactionError(LiFiErrorCode.NotFound, e.message, e)\n }\n\n if (e instanceof BaseError) {\n return e\n }\n\n return new UnknownError(e.message || ErrorMessage.UnknownError, e)\n}\n"],"mappings":";;AAWA,MAAa,qBAAqB,OAChC,GACA,MACA,WACsB;CACtB,IAAI,aAAa,UAAU;EACzB,EAAE,OAAO,EAAE,QAAQ;EACnB,EAAE,SAAS,EAAE,UAAU;EACvB,OAAO;;CAKT,OAAO,IAAI,SAFO,qBAAqB,EAEV,EAAE,MAAM,OAAO;;AAG9C,MAAM,wBAAwB,MAAW;CAEvC,IACE,EAAE,SAAS,WAAW,WAAW,IACjC,EAAE,OAAO,SAAS,WAAW,WAAW,EAExC,OAAO,IAAI,iBACT,cAAc,qBACd,0IACA,EACD;CAEH,IAAI,EAAE,SAAS,QAAQ,EAAE,SAAS,SAAU,EAAE,OAAO,WAAW,WAAW,EACzE,OAAO,IAAI,iBAAiB,cAAc,mBAAmB,EAAE,SAAS,EAAE;CAE5E,IAAI,EAAE,SAAS,MAAM,EAAE,SAAS,UAAU,EAAE,SAAS,QACnD,OAAO,IAAI,iBAAiB,cAAc,UAAU,EAAE,SAAS,EAAE;CAGnE,IAAI,aAAa,WACf,OAAO;CAGT,OAAO,IAAI,aAAa,EAAE,WAAW,aAAa,cAAc,EAAE"}
|
package/dist/esm/types.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"types.js","names":[],"sources":["../../src/types.ts"],"sourcesContent":["import type { Client } from '@bigmi/core'\nimport {\n ChainType,\n type LiFiStepExtended,\n type SDKProvider,\n type StepExecutorContext,\n} from '@lifi/sdk'\nimport type { PublicClient } from './client/publicClient.js'\n\nexport interface BitcoinProviderOptions {\n getWalletClient?: () => Promise<Client>\n}\n\nexport interface BitcoinStepExecutorContext extends StepExecutorContext {\n walletClient: Client\n publicClient: PublicClient\n checkClient: (step: LiFiStepExtended) => void\n}\n\nexport interface BitcoinSDKProvider extends SDKProvider {\n setOptions(options: BitcoinProviderOptions): void\n}\n\nexport function isBitcoinProvider(\n provider: SDKProvider\n): provider is BitcoinSDKProvider {\n return provider.type === ChainType.UTXO\n}\n"],"mappings":";;AAuBA,SAAgB,kBACd,UACgC;
|
|
1
|
+
{"version":3,"file":"types.js","names":[],"sources":["../../src/types.ts"],"sourcesContent":["import type { Client } from '@bigmi/core'\nimport {\n ChainType,\n type LiFiStepExtended,\n type SDKProvider,\n type StepExecutorContext,\n} from '@lifi/sdk'\nimport type { PublicClient } from './client/publicClient.js'\n\nexport interface BitcoinProviderOptions {\n getWalletClient?: () => Promise<Client>\n}\n\nexport interface BitcoinStepExecutorContext extends StepExecutorContext {\n walletClient: Client\n publicClient: PublicClient\n checkClient: (step: LiFiStepExtended) => void\n}\n\nexport interface BitcoinSDKProvider extends SDKProvider {\n setOptions(options: BitcoinProviderOptions): void\n}\n\nexport function isBitcoinProvider(\n provider: SDKProvider\n): provider is BitcoinSDKProvider {\n return provider.type === ChainType.UTXO\n}\n"],"mappings":";;AAuBA,SAAgB,kBACd,UACgC;CAChC,OAAO,SAAS,SAAS,UAAU"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"isPsbtFinalized.js","names":[],"sources":["../../../src/utils/isPsbtFinalized.ts"],"sourcesContent":["import type { Psbt } from 'bitcoinjs-lib'\n\nexport function isPsbtFinalized(psbt: Psbt): boolean {\n try {\n psbt.extractTransaction()\n return true\n } catch (_) {\n return false\n }\n}\n"],"mappings":";AAEA,SAAgB,gBAAgB,MAAqB;
|
|
1
|
+
{"version":3,"file":"isPsbtFinalized.js","names":[],"sources":["../../../src/utils/isPsbtFinalized.ts"],"sourcesContent":["import type { Psbt } from 'bitcoinjs-lib'\n\nexport function isPsbtFinalized(psbt: Psbt): boolean {\n try {\n psbt.extractTransaction()\n return true\n } catch (_) {\n return false\n }\n}\n"],"mappings":";AAEA,SAAgB,gBAAgB,MAAqB;CACnD,IAAI;EACF,KAAK,oBAAoB;EACzB,OAAO;UACA,GAAG;EACV,OAAO"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"toBigmiChainId.js","names":["ChainId","BigmiChainId"],"sources":["../../../src/utils/toBigmiChainId.ts"],"sourcesContent":["import { ChainId as BigmiChainId } from '@bigmi/core'\nimport { ChainId } from '@lifi/sdk'\n\nexport const toBigmiChainId = (chainId: ChainId): BigmiChainId => {\n switch (chainId) {\n case ChainId.BTC:\n return BigmiChainId.BITCOIN_MAINNET\n default:\n throw new Error(`Unsupported chainId mapping: ${chainId}`)\n }\n}\n"],"mappings":";;;AAGA,MAAa,kBAAkB,YAAmC;
|
|
1
|
+
{"version":3,"file":"toBigmiChainId.js","names":["ChainId","BigmiChainId"],"sources":["../../../src/utils/toBigmiChainId.ts"],"sourcesContent":["import { ChainId as BigmiChainId } from '@bigmi/core'\nimport { ChainId } from '@lifi/sdk'\n\nexport const toBigmiChainId = (chainId: ChainId): BigmiChainId => {\n switch (chainId) {\n case ChainId.BTC:\n return BigmiChainId.BITCOIN_MAINNET\n default:\n throw new Error(`Unsupported chainId mapping: ${chainId}`)\n }\n}\n"],"mappings":";;;AAGA,MAAa,kBAAkB,YAAmC;CAChE,QAAQ,SAAR;EACE,KAAKA,UAAQ,KACX,OAAOC,QAAa;EACtB,SACE,MAAM,IAAI,MAAM,gCAAgC,UAAU"}
|
package/dist/esm/version.d.ts
CHANGED
package/dist/esm/version.js
CHANGED
package/dist/esm/version.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"version.js","names":[],"sources":["../../src/version.ts"],"sourcesContent":["export const name = '@lifi/sdk-provider-bitcoin'\nexport const version = '4.0.0-beta.
|
|
1
|
+
{"version":3,"file":"version.js","names":[],"sources":["../../src/version.ts"],"sourcesContent":["export const name = '@lifi/sdk-provider-bitcoin'\nexport const version = '4.0.0-beta.9'\n"],"mappings":";AAAA,MAAa,OAAO;AACpB,MAAa,UAAU"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@lifi/sdk-provider-bitcoin",
|
|
3
|
-
"version": "4.0.0-beta.
|
|
3
|
+
"version": "4.0.0-beta.9",
|
|
4
4
|
"description": "LI.FI Bitcoin SDK Provider for Any-to-Any Cross-Chain-Swap",
|
|
5
5
|
"homepage": "https://github.com/lifinance/sdk",
|
|
6
6
|
"bugs": {
|
|
@@ -32,7 +32,7 @@
|
|
|
32
32
|
"@bitcoinerlab/secp256k1": "^1.2.0",
|
|
33
33
|
"bech32": "^2.0.0",
|
|
34
34
|
"bitcoinjs-lib": "^7.0.1",
|
|
35
|
-
"@lifi/sdk": "4.0.0-beta.
|
|
35
|
+
"@lifi/sdk": "4.0.0-beta.9"
|
|
36
36
|
},
|
|
37
37
|
"publishConfig": {
|
|
38
38
|
"access": "public"
|
package/src/version.ts
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
1
|
export const name = '@lifi/sdk-provider-bitcoin'
|
|
2
|
-
export const version = '4.0.0-beta.
|
|
2
|
+
export const version = '4.0.0-beta.9'
|