@lifi/sdk-provider-bitcoin 4.0.0-alpha.2 → 4.0.0-alpha.21
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 +1 -1
- package/dist/cjs/BitcoinProvider.js.map +1 -1
- package/dist/cjs/client/publicClient.d.ts +1 -2
- package/dist/cjs/core/BitcoinStepExecutor.d.ts +15 -0
- package/dist/cjs/core/BitcoinStepExecutor.js +53 -0
- package/dist/cjs/core/BitcoinStepExecutor.js.map +1 -0
- package/dist/cjs/core/tasks/BitcoinSignAndExecuteTask.d.ts +5 -0
- package/dist/cjs/core/tasks/BitcoinSignAndExecuteTask.js +101 -0
- package/dist/cjs/core/tasks/BitcoinSignAndExecuteTask.js.map +1 -0
- package/dist/cjs/core/tasks/BitcoinWaitForTransactionTask.d.ts +5 -0
- package/dist/cjs/core/tasks/BitcoinWaitForTransactionTask.js +45 -0
- package/dist/cjs/core/tasks/BitcoinWaitForTransactionTask.js.map +1 -0
- package/dist/cjs/errors/parseBitcoinErrors.d.ts +2 -2
- package/dist/cjs/errors/parseBitcoinErrors.js +3 -3
- package/dist/cjs/errors/parseBitcoinErrors.js.map +1 -1
- package/dist/cjs/types.d.ts +7 -1
- package/dist/cjs/types.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 +1 -1
- package/dist/esm/BitcoinProvider.js.map +1 -1
- package/dist/esm/client/publicClient.d.ts +1 -2
- package/dist/esm/core/BitcoinStepExecutor.d.ts +15 -0
- package/dist/esm/core/BitcoinStepExecutor.js +51 -0
- package/dist/esm/core/BitcoinStepExecutor.js.map +1 -0
- package/dist/esm/core/tasks/BitcoinSignAndExecuteTask.d.ts +5 -0
- package/dist/esm/core/tasks/BitcoinSignAndExecuteTask.js +106 -0
- package/dist/esm/core/tasks/BitcoinSignAndExecuteTask.js.map +1 -0
- package/dist/esm/core/tasks/BitcoinWaitForTransactionTask.d.ts +5 -0
- package/dist/esm/core/tasks/BitcoinWaitForTransactionTask.js +41 -0
- package/dist/esm/core/tasks/BitcoinWaitForTransactionTask.js.map +1 -0
- package/dist/esm/errors/parseBitcoinErrors.d.ts +2 -2
- package/dist/esm/errors/parseBitcoinErrors.js +3 -3
- package/dist/esm/errors/parseBitcoinErrors.js.map +1 -1
- package/dist/esm/types.d.ts +7 -1
- package/dist/esm/types.js +1 -1
- package/dist/esm/types.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/dist/types/client/publicClient.d.ts +1 -2
- package/dist/types/client/publicClient.d.ts.map +1 -1
- package/dist/types/core/BitcoinStepExecutor.d.ts +16 -0
- package/dist/types/core/BitcoinStepExecutor.d.ts.map +1 -0
- package/dist/types/core/tasks/BitcoinSignAndExecuteTask.d.ts +6 -0
- package/dist/types/core/tasks/BitcoinSignAndExecuteTask.d.ts.map +1 -0
- package/dist/types/core/tasks/BitcoinWaitForTransactionTask.d.ts +6 -0
- package/dist/types/core/tasks/BitcoinWaitForTransactionTask.d.ts.map +1 -0
- package/dist/types/errors/parseBitcoinErrors.d.ts +2 -2
- package/dist/types/errors/parseBitcoinErrors.d.ts.map +1 -1
- package/dist/types/types.d.ts +7 -1
- package/dist/types/types.d.ts.map +1 -1
- package/dist/types/version.d.ts +1 -1
- package/dist/types/version.d.ts.map +1 -1
- package/package.json +4 -4
- package/src/BitcoinProvider.ts +1 -1
- package/src/client/publicClient.ts +1 -1
- package/src/core/BitcoinStepExecutor.ts +98 -0
- package/src/core/tasks/BitcoinSignAndExecuteTask.ts +168 -0
- package/src/core/tasks/BitcoinWaitForTransactionTask.ts +74 -0
- package/src/errors/parseBitcoinErrors.ts +4 -4
- package/src/types.ts +13 -1
- package/src/version.ts +1 -1
- package/dist/cjs/BitcoinStepExecutor.d.ts +0 -12
- package/dist/cjs/BitcoinStepExecutor.js +0 -199
- package/dist/cjs/BitcoinStepExecutor.js.map +0 -1
- package/dist/esm/BitcoinStepExecutor.d.ts +0 -12
- package/dist/esm/BitcoinStepExecutor.js +0 -212
- package/dist/esm/BitcoinStepExecutor.js.map +0 -1
- package/dist/types/BitcoinStepExecutor.d.ts +0 -13
- package/dist/types/BitcoinStepExecutor.d.ts.map +0 -1
- package/src/BitcoinStepExecutor.ts +0 -344
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
import { waitForTransaction } from '@bigmi/core';
|
|
2
|
+
import { BaseStepExecutionTask, LiFiErrorCode, TransactionError, } from '@lifi/sdk';
|
|
3
|
+
export class BitcoinWaitForTransactionTask extends BaseStepExecutionTask {
|
|
4
|
+
async run(context) {
|
|
5
|
+
const { step, statusManager, fromChain, isBridgeExecution, walletClient, publicClient, checkClient, } = context;
|
|
6
|
+
const action = statusManager.findAction(step, isBridgeExecution ? 'CROSS_CHAIN' : 'SWAP');
|
|
7
|
+
const txHex = action?.txHex;
|
|
8
|
+
const txHash = action?.txHash;
|
|
9
|
+
if (!txHash || !txHex) {
|
|
10
|
+
throw new TransactionError(LiFiErrorCode.TransactionUnprepared, 'Unable to prepare transaction. Transaction hash or hex is not set.');
|
|
11
|
+
}
|
|
12
|
+
checkClient(step);
|
|
13
|
+
let replacementReason;
|
|
14
|
+
const transaction = await waitForTransaction(publicClient, {
|
|
15
|
+
txId: txHash,
|
|
16
|
+
txHex,
|
|
17
|
+
senderAddress: walletClient.account?.address,
|
|
18
|
+
onReplaced: (response) => {
|
|
19
|
+
replacementReason = response.reason;
|
|
20
|
+
statusManager.updateAction(step, action.type, 'PENDING', {
|
|
21
|
+
txHash: response.transaction.txid,
|
|
22
|
+
txLink: `${fromChain.metamask.blockExplorerUrls[0]}tx/${response.transaction.txid}`,
|
|
23
|
+
});
|
|
24
|
+
},
|
|
25
|
+
});
|
|
26
|
+
if (replacementReason === 'cancelled') {
|
|
27
|
+
throw new TransactionError(LiFiErrorCode.TransactionCanceled, 'User canceled transaction.');
|
|
28
|
+
}
|
|
29
|
+
if (transaction.txid !== txHash) {
|
|
30
|
+
statusManager.updateAction(step, action.type, 'PENDING', {
|
|
31
|
+
txHash: transaction.txid,
|
|
32
|
+
txLink: `${fromChain.metamask.blockExplorerUrls[0]}tx/${transaction.txid}`,
|
|
33
|
+
});
|
|
34
|
+
}
|
|
35
|
+
if (isBridgeExecution) {
|
|
36
|
+
statusManager.updateAction(step, action.type, 'DONE');
|
|
37
|
+
}
|
|
38
|
+
return { status: 'COMPLETED' };
|
|
39
|
+
}
|
|
40
|
+
}
|
|
41
|
+
//# sourceMappingURL=BitcoinWaitForTransactionTask.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"BitcoinWaitForTransactionTask.js","sourceRoot":"","sources":["../../../../src/core/tasks/BitcoinWaitForTransactionTask.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,kBAAkB,EAAE,MAAM,aAAa,CAAA;AAChD,OAAO,EACL,qBAAqB,EACrB,aAAa,EAEb,gBAAgB,GACjB,MAAM,WAAW,CAAA;AAGlB,MAAM,OAAO,6BAA8B,SAAQ,qBAAqB;IACtE,KAAK,CAAC,GAAG,CAAC,OAAmC;QAC3C,MAAM,EACJ,IAAI,EACJ,aAAa,EACb,SAAS,EACT,iBAAiB,EACjB,YAAY,EACZ,YAAY,EACZ,WAAW,GACZ,GAAG,OAAO,CAAA;QAEX,MAAM,MAAM,GAAG,aAAa,CAAC,UAAU,CACrC,IAAI,EACJ,iBAAiB,CAAC,CAAC,CAAC,aAAa,CAAC,CAAC,CAAC,MAAM,CAC3C,CAAA;QAED,MAAM,KAAK,GAAG,MAAM,EAAE,KAAK,CAAA;QAC3B,MAAM,MAAM,GAAG,MAAM,EAAE,MAAM,CAAA;QAE7B,IAAI,CAAC,MAAM,IAAI,CAAC,KAAK,EAAE,CAAC;YACtB,MAAM,IAAI,gBAAgB,CACxB,aAAa,CAAC,qBAAqB,EACnC,oEAAoE,CACrE,CAAA;QACH,CAAC;QAED,WAAW,CAAC,IAAI,CAAC,CAAA;QAEjB,IAAI,iBAAgD,CAAA;QACpD,MAAM,WAAW,GAAG,MAAM,kBAAkB,CAAC,YAAY,EAAE;YACzD,IAAI,EAAE,MAAM;YACZ,KAAK;YACL,aAAa,EAAE,YAAY,CAAC,OAAO,EAAE,OAAO;YAC5C,UAAU,EAAE,CAAC,QAAQ,EAAE,EAAE;gBACvB,iBAAiB,GAAG,QAAQ,CAAC,MAAM,CAAA;gBACnC,aAAa,CAAC,YAAY,CAAC,IAAI,EAAE,MAAM,CAAC,IAAI,EAAE,SAAS,EAAE;oBACvD,MAAM,EAAE,QAAQ,CAAC,WAAW,CAAC,IAAI;oBACjC,MAAM,EAAE,GAAG,SAAS,CAAC,QAAQ,CAAC,iBAAiB,CAAC,CAAC,CAAC,MAAM,QAAQ,CAAC,WAAW,CAAC,IAAI,EAAE;iBACpF,CAAC,CAAA;YACJ,CAAC;SACF,CAAC,CAAA;QAEF,IAAI,iBAAiB,KAAK,WAAW,EAAE,CAAC;YACtC,MAAM,IAAI,gBAAgB,CACxB,aAAa,CAAC,mBAAmB,EACjC,4BAA4B,CAC7B,CAAA;QACH,CAAC;QAED,IAAI,WAAW,CAAC,IAAI,KAAK,MAAM,EAAE,CAAC;YAChC,aAAa,CAAC,YAAY,CAAC,IAAI,EAAE,MAAM,CAAC,IAAI,EAAE,SAAS,EAAE;gBACvD,MAAM,EAAE,WAAW,CAAC,IAAI;gBACxB,MAAM,EAAE,GAAG,SAAS,CAAC,QAAQ,CAAC,iBAAiB,CAAC,CAAC,CAAC,MAAM,WAAW,CAAC,IAAI,EAAE;aAC3E,CAAC,CAAA;QACJ,CAAC;QAED,IAAI,iBAAiB,EAAE,CAAC;YACtB,aAAa,CAAC,YAAY,CAAC,IAAI,EAAE,MAAM,CAAC,IAAI,EAAE,MAAM,CAAC,CAAA;QACvD,CAAC;QAED,OAAO,EAAE,MAAM,EAAE,WAAW,EAAE,CAAA;IAChC,CAAC;CACF"}
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import { type
|
|
2
|
-
export declare const parseBitcoinErrors: (e: Error, step?: LiFiStep,
|
|
1
|
+
import { type ExecutionAction, type LiFiStep, SDKError } from '@lifi/sdk';
|
|
2
|
+
export declare const parseBitcoinErrors: (e: Error, step?: LiFiStep, action?: ExecutionAction) => Promise<SDKError>;
|
|
@@ -1,12 +1,12 @@
|
|
|
1
1
|
import { BaseError, ErrorMessage, LiFiErrorCode, SDKError, TransactionError, UnknownError, } from '@lifi/sdk';
|
|
2
|
-
export const parseBitcoinErrors = async (e, step,
|
|
2
|
+
export const parseBitcoinErrors = async (e, step, action) => {
|
|
3
3
|
if (e instanceof SDKError) {
|
|
4
4
|
e.step = e.step ?? step;
|
|
5
|
-
e.
|
|
5
|
+
e.action = e.action ?? action;
|
|
6
6
|
return e;
|
|
7
7
|
}
|
|
8
8
|
const baseError = handleSpecificErrors(e);
|
|
9
|
-
return new SDKError(baseError, step,
|
|
9
|
+
return new SDKError(baseError, step, action);
|
|
10
10
|
};
|
|
11
11
|
const handleSpecificErrors = (e) => {
|
|
12
12
|
// txn-mempool-conflict
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"parseBitcoinErrors.js","sourceRoot":"","sources":["../../../src/errors/parseBitcoinErrors.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,SAAS,EACT,YAAY,
|
|
1
|
+
{"version":3,"file":"parseBitcoinErrors.js","sourceRoot":"","sources":["../../../src/errors/parseBitcoinErrors.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,SAAS,EACT,YAAY,EAEZ,aAAa,EAEb,QAAQ,EACR,gBAAgB,EAChB,YAAY,GACb,MAAM,WAAW,CAAA;AAElB,MAAM,CAAC,MAAM,kBAAkB,GAAG,KAAK,EACrC,CAAQ,EACR,IAAe,EACf,MAAwB,EACL,EAAE;IACrB,IAAI,CAAC,YAAY,QAAQ,EAAE,CAAC;QAC1B,CAAC,CAAC,IAAI,GAAG,CAAC,CAAC,IAAI,IAAI,IAAI,CAAA;QACvB,CAAC,CAAC,MAAM,GAAG,CAAC,CAAC,MAAM,IAAI,MAAM,CAAA;QAC7B,OAAO,CAAC,CAAA;IACV,CAAC;IAED,MAAM,SAAS,GAAG,oBAAoB,CAAC,CAAC,CAAC,CAAA;IAEzC,OAAO,IAAI,QAAQ,CAAC,SAAS,EAAE,IAAI,EAAE,MAAM,CAAC,CAAA;AAC9C,CAAC,CAAA;AAED,MAAM,oBAAoB,GAAG,CAAC,CAAM,EAAE,EAAE;IACtC,uBAAuB;IACvB,IACE,CAAC,CAAC,OAAO,EAAE,QAAQ,EAAE,CAAC,UAAU,CAAC;QACjC,CAAC,CAAC,KAAK,EAAE,OAAO,EAAE,QAAQ,EAAE,CAAC,UAAU,CAAC,EACxC,CAAC;QACD,OAAO,IAAI,gBAAgB,CACzB,aAAa,CAAC,mBAAmB,EACjC,wIAAwI,EACxI,CAAC,CACF,CAAA;IACH,CAAC;IACD,IAAI,CAAC,CAAC,IAAI,KAAK,IAAI,IAAI,CAAC,CAAC,IAAI,KAAK,CAAC,KAAK,IAAI,CAAC,CAAC,KAAK,EAAE,QAAQ,EAAE,CAAC,UAAU,CAAC,EAAE,CAAC;QAC5E,OAAO,IAAI,gBAAgB,CAAC,aAAa,CAAC,iBAAiB,EAAE,CAAC,CAAC,OAAO,EAAE,CAAC,CAAC,CAAA;IAC5E,CAAC;IACD,IAAI,CAAC,CAAC,IAAI,KAAK,CAAC,CAAC,IAAI,CAAC,CAAC,IAAI,KAAK,CAAC,KAAK,IAAI,CAAC,CAAC,IAAI,KAAK,CAAC,KAAK,EAAE,CAAC;QAC5D,OAAO,IAAI,gBAAgB,CAAC,aAAa,CAAC,QAAQ,EAAE,CAAC,CAAC,OAAO,EAAE,CAAC,CAAC,CAAA;IACnE,CAAC;IAED,IAAI,CAAC,YAAY,SAAS,EAAE,CAAC;QAC3B,OAAO,CAAC,CAAA;IACV,CAAC;IAED,OAAO,IAAI,YAAY,CAAC,CAAC,CAAC,OAAO,IAAI,YAAY,CAAC,YAAY,EAAE,CAAC,CAAC,CAAA;AACpE,CAAC,CAAA"}
|
package/dist/esm/types.d.ts
CHANGED
|
@@ -1,8 +1,14 @@
|
|
|
1
1
|
import type { Client } from '@bigmi/core';
|
|
2
|
-
import { type SDKProvider } from '@lifi/sdk';
|
|
2
|
+
import { type LiFiStepExtended, type SDKProvider, type StepExecutorContext } from '@lifi/sdk';
|
|
3
|
+
import type { PublicClient } from './client/publicClient.js';
|
|
3
4
|
export interface BitcoinProviderOptions {
|
|
4
5
|
getWalletClient?: () => Promise<Client>;
|
|
5
6
|
}
|
|
7
|
+
export interface BitcoinStepExecutorContext extends StepExecutorContext {
|
|
8
|
+
walletClient: Client;
|
|
9
|
+
publicClient: PublicClient;
|
|
10
|
+
checkClient: (step: LiFiStepExtended) => void;
|
|
11
|
+
}
|
|
6
12
|
export interface BitcoinSDKProvider extends SDKProvider {
|
|
7
13
|
setOptions(options: BitcoinProviderOptions): void;
|
|
8
14
|
}
|
package/dist/esm/types.js
CHANGED
package/dist/esm/types.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"types.js","sourceRoot":"","sources":["../../src/types.ts"],"names":[],"mappings":"AACA,OAAO,
|
|
1
|
+
{"version":3,"file":"types.js","sourceRoot":"","sources":["../../src/types.ts"],"names":[],"mappings":"AACA,OAAO,EACL,SAAS,GAIV,MAAM,WAAW,CAAA;AAiBlB,MAAM,UAAU,iBAAiB,CAC/B,QAAqB;IAErB,OAAO,QAAQ,CAAC,IAAI,KAAK,SAAS,CAAC,IAAI,CAAA;AACzC,CAAC"}
|
package/dist/esm/version.d.ts
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
1
|
export declare const name = "@lifi/sdk-provider-bitcoin";
|
|
2
|
-
export declare const version = "4.0.0-alpha.
|
|
2
|
+
export declare const version = "4.0.0-alpha.21";
|
package/dist/esm/version.js
CHANGED
package/dist/esm/version.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"version.js","sourceRoot":"","sources":["../../src/version.ts"],"names":[],"mappings":"AAAA,MAAM,CAAC,MAAM,IAAI,GAAG,4BAA4B,CAAA;AAChD,MAAM,CAAC,MAAM,OAAO,GAAG,
|
|
1
|
+
{"version":3,"file":"version.js","sourceRoot":"","sources":["../../src/version.ts"],"names":[],"mappings":"AAAA,MAAM,CAAC,MAAM,IAAI,GAAG,4BAA4B,CAAA;AAChD,MAAM,CAAC,MAAM,OAAO,GAAG,gBAAgB,CAAA"}
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { type Account, type Chain, type Client, type FallbackTransport, type HttpTransport, type PublicActions, type UTXOSchema, type WalletActions } from '@bigmi/core';
|
|
2
2
|
import type { SDKClient } from '@lifi/sdk';
|
|
3
|
-
type PublicClient = Client<FallbackTransport<readonly HttpTransport[]>, Chain, Account | undefined, UTXOSchema, PublicActions & WalletActions>;
|
|
3
|
+
export type PublicClient = Client<FallbackTransport<readonly HttpTransport[]>, Chain, Account | undefined, UTXOSchema, PublicActions & WalletActions>;
|
|
4
4
|
/**
|
|
5
5
|
* Get an instance of a provider for a specific chain
|
|
6
6
|
* @param client - The SDK client
|
|
@@ -8,5 +8,4 @@ type PublicClient = Client<FallbackTransport<readonly HttpTransport[]>, Chain, A
|
|
|
8
8
|
* @returns The public client for the given chain
|
|
9
9
|
*/
|
|
10
10
|
export declare const getBitcoinPublicClient: (client: SDKClient, chainId: number) => Promise<PublicClient>;
|
|
11
|
-
export {};
|
|
12
11
|
//# sourceMappingURL=publicClient.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"publicClient.d.ts","sourceRoot":"","sources":["../../../src/client/publicClient.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,KAAK,OAAO,EAGZ,KAAK,KAAK,EACV,KAAK,MAAM,EAEX,KAAK,iBAAiB,EAEtB,KAAK,aAAa,EAGlB,KAAK,aAAa,EAGlB,KAAK,UAAU,EACf,KAAK,aAAa,EAEnB,MAAM,aAAa,CAAA;AACpB,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,WAAW,CAAA;AAG1C,
|
|
1
|
+
{"version":3,"file":"publicClient.d.ts","sourceRoot":"","sources":["../../../src/client/publicClient.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,KAAK,OAAO,EAGZ,KAAK,KAAK,EACV,KAAK,MAAM,EAEX,KAAK,iBAAiB,EAEtB,KAAK,aAAa,EAGlB,KAAK,aAAa,EAGlB,KAAK,UAAU,EACf,KAAK,aAAa,EAEnB,MAAM,aAAa,CAAA;AACpB,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,WAAW,CAAA;AAG1C,MAAM,MAAM,YAAY,GAAG,MAAM,CAC/B,iBAAiB,CAAC,SAAS,aAAa,EAAE,CAAC,EAC3C,KAAK,EACL,OAAO,GAAG,SAAS,EACnB,UAAU,EACV,aAAa,GAAG,aAAa,CAC9B,CAAA;AAKD;;;;;GAKG;AACH,eAAO,MAAM,sBAAsB,GACjC,QAAQ,SAAS,EACjB,SAAS,MAAM,KACd,OAAO,CAAC,YAAY,CA0CtB,CAAA"}
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import type { Client } from '@bigmi/core';
|
|
2
|
+
import { BaseStepExecutor, type ExecutionAction, type LiFiStepExtended, type SDKError, type StepExecutorBaseContext, type StepExecutorOptions, TaskPipeline } from '@lifi/sdk';
|
|
3
|
+
import type { BitcoinStepExecutorContext } from '../types.js';
|
|
4
|
+
interface BitcoinStepExecutorOptions extends StepExecutorOptions {
|
|
5
|
+
client: Client;
|
|
6
|
+
}
|
|
7
|
+
export declare class BitcoinStepExecutor extends BaseStepExecutor {
|
|
8
|
+
private client;
|
|
9
|
+
constructor(options: BitcoinStepExecutorOptions);
|
|
10
|
+
checkClient: (step: LiFiStepExtended) => void;
|
|
11
|
+
createPipeline: (context: BitcoinStepExecutorContext) => TaskPipeline;
|
|
12
|
+
parseErrors: (error: Error, step?: LiFiStepExtended, action?: ExecutionAction) => Promise<SDKError>;
|
|
13
|
+
createContext: (baseContext: StepExecutorBaseContext) => Promise<BitcoinStepExecutorContext>;
|
|
14
|
+
}
|
|
15
|
+
export {};
|
|
16
|
+
//# sourceMappingURL=BitcoinStepExecutor.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"BitcoinStepExecutor.d.ts","sourceRoot":"","sources":["../../../src/core/BitcoinStepExecutor.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,aAAa,CAAA;AACzC,OAAO,EACL,gBAAgB,EAEhB,KAAK,eAAe,EAEpB,KAAK,gBAAgB,EAErB,KAAK,QAAQ,EACb,KAAK,uBAAuB,EAC5B,KAAK,mBAAmB,EACxB,YAAY,EAGb,MAAM,WAAW,CAAA;AAGlB,OAAO,KAAK,EAAE,0BAA0B,EAAE,MAAM,aAAa,CAAA;AAI7D,UAAU,0BAA2B,SAAQ,mBAAmB;IAC9D,MAAM,EAAE,MAAM,CAAA;CACf;AAED,qBAAa,mBAAoB,SAAQ,gBAAgB;IACvD,OAAO,CAAC,MAAM,CAAQ;gBAEV,OAAO,EAAE,0BAA0B;IAK/C,WAAW,GAAI,MAAM,gBAAgB,UASpC;IAEQ,cAAc,GAAI,SAAS,0BAA0B,kBA8B7D;IAEQ,WAAW,GAClB,OAAO,KAAK,EACZ,OAAO,gBAAgB,EACvB,SAAS,eAAe,KACvB,OAAO,CAAC,QAAQ,CAAC,CAA2C;IAEtD,aAAa,GACpB,aAAa,uBAAuB,KACnC,OAAO,CAAC,0BAA0B,CAAC,CAYrC;CACF"}
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
import { BaseStepExecutionTask, type TaskResult } from '@lifi/sdk';
|
|
2
|
+
import type { BitcoinStepExecutorContext } from '../../types.js';
|
|
3
|
+
export declare class BitcoinSignAndExecuteTask extends BaseStepExecutionTask {
|
|
4
|
+
run(context: BitcoinStepExecutorContext): Promise<TaskResult>;
|
|
5
|
+
}
|
|
6
|
+
//# sourceMappingURL=BitcoinSignAndExecuteTask.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"BitcoinSignAndExecuteTask.d.ts","sourceRoot":"","sources":["../../../../src/core/tasks/BitcoinSignAndExecuteTask.ts"],"names":[],"mappings":"AAQA,OAAO,EACL,qBAAqB,EAGrB,KAAK,UAAU,EAEhB,MAAM,WAAW,CAAA;AAElB,OAAO,KAAK,EAAE,0BAA0B,EAAE,MAAM,gBAAgB,CAAA;AAKhE,qBAAa,yBAA0B,SAAQ,qBAAqB;IAC5D,GAAG,CAAC,OAAO,EAAE,0BAA0B,GAAG,OAAO,CAAC,UAAU,CAAC;CAiJpE"}
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
import { BaseStepExecutionTask, type TaskResult } from '@lifi/sdk';
|
|
2
|
+
import type { BitcoinStepExecutorContext } from '../../types.js';
|
|
3
|
+
export declare class BitcoinWaitForTransactionTask extends BaseStepExecutionTask {
|
|
4
|
+
run(context: BitcoinStepExecutorContext): Promise<TaskResult>;
|
|
5
|
+
}
|
|
6
|
+
//# sourceMappingURL=BitcoinWaitForTransactionTask.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"BitcoinWaitForTransactionTask.d.ts","sourceRoot":"","sources":["../../../../src/core/tasks/BitcoinWaitForTransactionTask.ts"],"names":[],"mappings":"AAEA,OAAO,EACL,qBAAqB,EAErB,KAAK,UAAU,EAEhB,MAAM,WAAW,CAAA;AAClB,OAAO,KAAK,EAAE,0BAA0B,EAAE,MAAM,gBAAgB,CAAA;AAEhE,qBAAa,6BAA8B,SAAQ,qBAAqB;IAChE,GAAG,CAAC,OAAO,EAAE,0BAA0B,GAAG,OAAO,CAAC,UAAU,CAAC;CA8DpE"}
|
|
@@ -1,3 +1,3 @@
|
|
|
1
|
-
import { type
|
|
2
|
-
export declare const parseBitcoinErrors: (e: Error, step?: LiFiStep,
|
|
1
|
+
import { type ExecutionAction, type LiFiStep, SDKError } from '@lifi/sdk';
|
|
2
|
+
export declare const parseBitcoinErrors: (e: Error, step?: LiFiStep, action?: ExecutionAction) => Promise<SDKError>;
|
|
3
3
|
//# sourceMappingURL=parseBitcoinErrors.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"parseBitcoinErrors.d.ts","sourceRoot":"","sources":["../../../src/errors/parseBitcoinErrors.ts"],"names":[],"mappings":"AAAA,OAAO,
|
|
1
|
+
{"version":3,"file":"parseBitcoinErrors.d.ts","sourceRoot":"","sources":["../../../src/errors/parseBitcoinErrors.ts"],"names":[],"mappings":"AAAA,OAAO,EAGL,KAAK,eAAe,EAEpB,KAAK,QAAQ,EACb,QAAQ,EAGT,MAAM,WAAW,CAAA;AAElB,eAAO,MAAM,kBAAkB,GAC7B,GAAG,KAAK,EACR,OAAO,QAAQ,EACf,SAAS,eAAe,KACvB,OAAO,CAAC,QAAQ,CAUlB,CAAA"}
|
package/dist/types/types.d.ts
CHANGED
|
@@ -1,8 +1,14 @@
|
|
|
1
1
|
import type { Client } from '@bigmi/core';
|
|
2
|
-
import { type SDKProvider } from '@lifi/sdk';
|
|
2
|
+
import { type LiFiStepExtended, type SDKProvider, type StepExecutorContext } from '@lifi/sdk';
|
|
3
|
+
import type { PublicClient } from './client/publicClient.js';
|
|
3
4
|
export interface BitcoinProviderOptions {
|
|
4
5
|
getWalletClient?: () => Promise<Client>;
|
|
5
6
|
}
|
|
7
|
+
export interface BitcoinStepExecutorContext extends StepExecutorContext {
|
|
8
|
+
walletClient: Client;
|
|
9
|
+
publicClient: PublicClient;
|
|
10
|
+
checkClient: (step: LiFiStepExtended) => void;
|
|
11
|
+
}
|
|
6
12
|
export interface BitcoinSDKProvider extends SDKProvider {
|
|
7
13
|
setOptions(options: BitcoinProviderOptions): void;
|
|
8
14
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../../src/types.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,aAAa,CAAA;AACzC,OAAO,
|
|
1
|
+
{"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../../src/types.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,aAAa,CAAA;AACzC,OAAO,EAEL,KAAK,gBAAgB,EACrB,KAAK,WAAW,EAChB,KAAK,mBAAmB,EACzB,MAAM,WAAW,CAAA;AAClB,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,0BAA0B,CAAA;AAE5D,MAAM,WAAW,sBAAsB;IACrC,eAAe,CAAC,EAAE,MAAM,OAAO,CAAC,MAAM,CAAC,CAAA;CACxC;AAED,MAAM,WAAW,0BAA2B,SAAQ,mBAAmB;IACrE,YAAY,EAAE,MAAM,CAAA;IACpB,YAAY,EAAE,YAAY,CAAA;IAC1B,WAAW,EAAE,CAAC,IAAI,EAAE,gBAAgB,KAAK,IAAI,CAAA;CAC9C;AAED,MAAM,WAAW,kBAAmB,SAAQ,WAAW;IACrD,UAAU,CAAC,OAAO,EAAE,sBAAsB,GAAG,IAAI,CAAA;CAClD;AAED,wBAAgB,iBAAiB,CAC/B,QAAQ,EAAE,WAAW,GACpB,QAAQ,IAAI,kBAAkB,CAEhC"}
|
package/dist/types/version.d.ts
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"version.d.ts","sourceRoot":"","sources":["../../src/version.ts"],"names":[],"mappings":"AAAA,eAAO,MAAM,IAAI,+BAA+B,CAAA;AAChD,eAAO,MAAM,OAAO,
|
|
1
|
+
{"version":3,"file":"version.d.ts","sourceRoot":"","sources":["../../src/version.ts"],"names":[],"mappings":"AAAA,eAAO,MAAM,IAAI,+BAA+B,CAAA;AAChD,eAAO,MAAM,OAAO,mBAAmB,CAAA"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@lifi/sdk-provider-bitcoin",
|
|
3
|
-
"version": "4.0.0-alpha.
|
|
3
|
+
"version": "4.0.0-alpha.21",
|
|
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": {
|
|
@@ -28,11 +28,11 @@
|
|
|
28
28
|
"./package.json": "./package.json"
|
|
29
29
|
},
|
|
30
30
|
"dependencies": {
|
|
31
|
-
"@bigmi/core": "^0.
|
|
31
|
+
"@bigmi/core": "^0.7.0",
|
|
32
32
|
"@bitcoinerlab/secp256k1": "^1.2.0",
|
|
33
33
|
"bech32": "^2.0.0",
|
|
34
|
-
"bitcoinjs-lib": "^7.0.
|
|
35
|
-
"@lifi/sdk": "4.0.0-alpha.
|
|
34
|
+
"bitcoinjs-lib": "^7.0.1",
|
|
35
|
+
"@lifi/sdk": "4.0.0-alpha.21"
|
|
36
36
|
},
|
|
37
37
|
"publishConfig": {
|
|
38
38
|
"access": "public"
|
package/src/BitcoinProvider.ts
CHANGED
|
@@ -2,7 +2,7 @@ import { isUTXOAddress } from '@bigmi/core'
|
|
|
2
2
|
import { ChainType, type StepExecutorOptions } from '@lifi/sdk'
|
|
3
3
|
import { getBitcoinBalance } from './actions/getBitcoinBalance.js'
|
|
4
4
|
import { resolveBitcoinAddress } from './actions/resolveBitcoinAddress.js'
|
|
5
|
-
import { BitcoinStepExecutor } from './BitcoinStepExecutor.js'
|
|
5
|
+
import { BitcoinStepExecutor } from './core/BitcoinStepExecutor.js'
|
|
6
6
|
import type { BitcoinProviderOptions, BitcoinSDKProvider } from './types.js'
|
|
7
7
|
|
|
8
8
|
export function BitcoinProvider(
|
|
@@ -20,7 +20,7 @@ import {
|
|
|
20
20
|
import type { SDKClient } from '@lifi/sdk'
|
|
21
21
|
import { toBigmiChainId } from '../utils/toBigmiChainId.js'
|
|
22
22
|
|
|
23
|
-
type PublicClient = Client<
|
|
23
|
+
export type PublicClient = Client<
|
|
24
24
|
FallbackTransport<readonly HttpTransport[]>,
|
|
25
25
|
Chain,
|
|
26
26
|
Account | undefined,
|
|
@@ -0,0 +1,98 @@
|
|
|
1
|
+
import type { Client } from '@bigmi/core'
|
|
2
|
+
import {
|
|
3
|
+
BaseStepExecutor,
|
|
4
|
+
CheckBalanceTask,
|
|
5
|
+
type ExecutionAction,
|
|
6
|
+
LiFiErrorCode,
|
|
7
|
+
type LiFiStepExtended,
|
|
8
|
+
PrepareTransactionTask,
|
|
9
|
+
type SDKError,
|
|
10
|
+
type StepExecutorBaseContext,
|
|
11
|
+
type StepExecutorOptions,
|
|
12
|
+
TaskPipeline,
|
|
13
|
+
TransactionError,
|
|
14
|
+
WaitForTransactionStatusTask,
|
|
15
|
+
} from '@lifi/sdk'
|
|
16
|
+
import { getBitcoinPublicClient } from '../client/publicClient.js'
|
|
17
|
+
import { parseBitcoinErrors } from '../errors/parseBitcoinErrors.js'
|
|
18
|
+
import type { BitcoinStepExecutorContext } from '../types.js'
|
|
19
|
+
import { BitcoinSignAndExecuteTask } from './tasks/BitcoinSignAndExecuteTask.js'
|
|
20
|
+
import { BitcoinWaitForTransactionTask } from './tasks/BitcoinWaitForTransactionTask.js'
|
|
21
|
+
|
|
22
|
+
interface BitcoinStepExecutorOptions extends StepExecutorOptions {
|
|
23
|
+
client: Client
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
export class BitcoinStepExecutor extends BaseStepExecutor {
|
|
27
|
+
private client: Client
|
|
28
|
+
|
|
29
|
+
constructor(options: BitcoinStepExecutorOptions) {
|
|
30
|
+
super(options)
|
|
31
|
+
this.client = options.client
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
checkClient = (step: LiFiStepExtended) => {
|
|
35
|
+
// TODO: check chain and possibly implement chain switch?
|
|
36
|
+
// Prevent execution of the quote by wallet different from the one which requested the quote
|
|
37
|
+
if (this.client.account?.address !== step.action.fromAddress) {
|
|
38
|
+
throw new TransactionError(
|
|
39
|
+
LiFiErrorCode.WalletChangedDuringExecution,
|
|
40
|
+
'The wallet address that requested the quote does not match the wallet address attempting to sign the transaction.'
|
|
41
|
+
)
|
|
42
|
+
}
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
override createPipeline = (context: BitcoinStepExecutorContext) => {
|
|
46
|
+
const { step, isBridgeExecution } = context
|
|
47
|
+
|
|
48
|
+
const tasks = [
|
|
49
|
+
new CheckBalanceTask(),
|
|
50
|
+
new PrepareTransactionTask(),
|
|
51
|
+
new BitcoinSignAndExecuteTask(),
|
|
52
|
+
new BitcoinWaitForTransactionTask(),
|
|
53
|
+
new WaitForTransactionStatusTask(
|
|
54
|
+
isBridgeExecution ? 'RECEIVING_CHAIN' : 'SWAP'
|
|
55
|
+
),
|
|
56
|
+
]
|
|
57
|
+
const swapOrBridgeAction = this.statusManager.findAction(
|
|
58
|
+
step,
|
|
59
|
+
isBridgeExecution ? 'CROSS_CHAIN' : 'SWAP'
|
|
60
|
+
)
|
|
61
|
+
|
|
62
|
+
const taskName = swapOrBridgeAction?.txHash
|
|
63
|
+
? swapOrBridgeAction?.status === 'DONE'
|
|
64
|
+
? WaitForTransactionStatusTask.name
|
|
65
|
+
: BitcoinWaitForTransactionTask.name
|
|
66
|
+
: CheckBalanceTask.name
|
|
67
|
+
|
|
68
|
+
const firstTaskIndex = tasks.findIndex(
|
|
69
|
+
(task) => task.constructor.name === taskName
|
|
70
|
+
)
|
|
71
|
+
|
|
72
|
+
const tasksToRun = tasks.slice(firstTaskIndex)
|
|
73
|
+
|
|
74
|
+
return new TaskPipeline(tasksToRun)
|
|
75
|
+
}
|
|
76
|
+
|
|
77
|
+
override parseErrors = (
|
|
78
|
+
error: Error,
|
|
79
|
+
step?: LiFiStepExtended,
|
|
80
|
+
action?: ExecutionAction
|
|
81
|
+
): Promise<SDKError> => parseBitcoinErrors(error, step, action)
|
|
82
|
+
|
|
83
|
+
override createContext = async (
|
|
84
|
+
baseContext: StepExecutorBaseContext
|
|
85
|
+
): Promise<BitcoinStepExecutorContext> => {
|
|
86
|
+
const { client, fromChain } = baseContext
|
|
87
|
+
|
|
88
|
+
const publicClient = await getBitcoinPublicClient(client, fromChain.id)
|
|
89
|
+
|
|
90
|
+
return {
|
|
91
|
+
...baseContext,
|
|
92
|
+
pollingIntervalMs: 10_000,
|
|
93
|
+
checkClient: this.checkClient,
|
|
94
|
+
walletClient: this.client,
|
|
95
|
+
publicClient,
|
|
96
|
+
}
|
|
97
|
+
}
|
|
98
|
+
}
|
|
@@ -0,0 +1,168 @@
|
|
|
1
|
+
import {
|
|
2
|
+
AddressType,
|
|
3
|
+
getAddressInfo,
|
|
4
|
+
hexToUnit8Array,
|
|
5
|
+
signPsbt,
|
|
6
|
+
withTimeout,
|
|
7
|
+
} from '@bigmi/core'
|
|
8
|
+
import * as ecc from '@bitcoinerlab/secp256k1'
|
|
9
|
+
import {
|
|
10
|
+
BaseStepExecutionTask,
|
|
11
|
+
getTransactionRequestData,
|
|
12
|
+
LiFiErrorCode,
|
|
13
|
+
type TaskResult,
|
|
14
|
+
TransactionError,
|
|
15
|
+
} from '@lifi/sdk'
|
|
16
|
+
import { address, initEccLib, networks, Psbt } from 'bitcoinjs-lib'
|
|
17
|
+
import type { BitcoinStepExecutorContext } from '../../types.js'
|
|
18
|
+
import { generateRedeemScript } from '../../utils/generateRedeemScript.js'
|
|
19
|
+
import { isPsbtFinalized } from '../../utils/isPsbtFinalized.js'
|
|
20
|
+
import { toXOnly } from '../../utils/toXOnly.js'
|
|
21
|
+
|
|
22
|
+
export class BitcoinSignAndExecuteTask extends BaseStepExecutionTask {
|
|
23
|
+
async run(context: BitcoinStepExecutorContext): Promise<TaskResult> {
|
|
24
|
+
const {
|
|
25
|
+
step,
|
|
26
|
+
walletClient,
|
|
27
|
+
statusManager,
|
|
28
|
+
executionOptions,
|
|
29
|
+
fromChain,
|
|
30
|
+
publicClient,
|
|
31
|
+
checkClient,
|
|
32
|
+
isBridgeExecution,
|
|
33
|
+
} = context
|
|
34
|
+
|
|
35
|
+
const action = statusManager.findAction(
|
|
36
|
+
step,
|
|
37
|
+
isBridgeExecution ? 'CROSS_CHAIN' : 'SWAP'
|
|
38
|
+
)
|
|
39
|
+
|
|
40
|
+
if (!action) {
|
|
41
|
+
throw new TransactionError(
|
|
42
|
+
LiFiErrorCode.TransactionUnprepared,
|
|
43
|
+
'Unable to prepare transaction. Action not found.'
|
|
44
|
+
)
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
const transactionRequestData = await getTransactionRequestData(
|
|
48
|
+
step,
|
|
49
|
+
executionOptions
|
|
50
|
+
)
|
|
51
|
+
|
|
52
|
+
checkClient(step)
|
|
53
|
+
|
|
54
|
+
const psbtHex = transactionRequestData
|
|
55
|
+
|
|
56
|
+
// Initialize ECC library required for Taproot operations
|
|
57
|
+
// https://github.com/bitcoinjs/bitcoinjs-lib?tab=readme-ov-file#using-taproot
|
|
58
|
+
initEccLib(ecc)
|
|
59
|
+
|
|
60
|
+
const psbt = Psbt.fromHex(psbtHex, { network: networks.bitcoin })
|
|
61
|
+
|
|
62
|
+
psbt.data.inputs.forEach((input, index) => {
|
|
63
|
+
const accountAddress = input.witnessUtxo
|
|
64
|
+
? address.fromOutputScript(input.witnessUtxo.script, networks.bitcoin)
|
|
65
|
+
: (walletClient.account?.address as string)
|
|
66
|
+
const addressInfo = getAddressInfo(accountAddress)
|
|
67
|
+
if (addressInfo.type === AddressType.p2tr) {
|
|
68
|
+
// Taproot (P2TR) addresses require specific PSBT fields for proper signing
|
|
69
|
+
|
|
70
|
+
// tapInternalKey: Required for Taproot key-path spending
|
|
71
|
+
// Most wallets / libraries usually handle this already
|
|
72
|
+
if (!input.tapInternalKey) {
|
|
73
|
+
const pubKey = walletClient.account?.publicKey
|
|
74
|
+
if (pubKey) {
|
|
75
|
+
const tapInternalKey = toXOnly(hexToUnit8Array(pubKey))
|
|
76
|
+
psbt.updateInput(index, {
|
|
77
|
+
tapInternalKey,
|
|
78
|
+
})
|
|
79
|
+
}
|
|
80
|
+
}
|
|
81
|
+
// sighashType: Required by bitcoinjs-lib even though the bitcoin protocol allows defaults
|
|
82
|
+
// check if sighashType is default (0) or not set (undefined)
|
|
83
|
+
if (!input.sighashType) {
|
|
84
|
+
psbt.updateInput(index, {
|
|
85
|
+
sighashType: 1, // Default to Transaction.SIGHASH_ALL - 1
|
|
86
|
+
})
|
|
87
|
+
}
|
|
88
|
+
}
|
|
89
|
+
// redeemScript: Required by Pay-to-Script-Hash (P2SH) addresses for proper spending
|
|
90
|
+
if (addressInfo.type === AddressType.p2sh) {
|
|
91
|
+
if (!input.redeemScript) {
|
|
92
|
+
const pubKey = walletClient.account?.publicKey
|
|
93
|
+
if (pubKey) {
|
|
94
|
+
psbt.updateInput(index, {
|
|
95
|
+
redeemScript: generateRedeemScript(hexToUnit8Array(pubKey)),
|
|
96
|
+
})
|
|
97
|
+
}
|
|
98
|
+
}
|
|
99
|
+
}
|
|
100
|
+
})
|
|
101
|
+
|
|
102
|
+
const inputsToSign = Array.from(
|
|
103
|
+
psbt.data.inputs
|
|
104
|
+
.reduce((map, input, index) => {
|
|
105
|
+
const accountAddress = input.witnessUtxo
|
|
106
|
+
? address.fromOutputScript(
|
|
107
|
+
input.witnessUtxo.script,
|
|
108
|
+
networks.bitcoin
|
|
109
|
+
)
|
|
110
|
+
: (walletClient.account?.address as string)
|
|
111
|
+
if (map.has(accountAddress)) {
|
|
112
|
+
map.get(accountAddress)!.signingIndexes.push(index)
|
|
113
|
+
} else {
|
|
114
|
+
map.set(accountAddress, {
|
|
115
|
+
address: accountAddress,
|
|
116
|
+
sigHash: 1, // Default to Transaction.SIGHASH_ALL - 1
|
|
117
|
+
signingIndexes: [index],
|
|
118
|
+
})
|
|
119
|
+
}
|
|
120
|
+
return map
|
|
121
|
+
}, new Map<
|
|
122
|
+
string,
|
|
123
|
+
{ address: string; sigHash: number; signingIndexes: number[] }
|
|
124
|
+
>())
|
|
125
|
+
.values()
|
|
126
|
+
)
|
|
127
|
+
|
|
128
|
+
// We give users 10 minutes to sign the transaction or it should be considered expired
|
|
129
|
+
const signedPsbtHex = await withTimeout(
|
|
130
|
+
() =>
|
|
131
|
+
signPsbt(walletClient, {
|
|
132
|
+
psbt: psbt.toHex(),
|
|
133
|
+
inputsToSign: inputsToSign,
|
|
134
|
+
finalize: false,
|
|
135
|
+
}),
|
|
136
|
+
{
|
|
137
|
+
timeout: 600_000,
|
|
138
|
+
errorInstance: new TransactionError(
|
|
139
|
+
LiFiErrorCode.TransactionExpired,
|
|
140
|
+
'Transaction has expired.'
|
|
141
|
+
),
|
|
142
|
+
}
|
|
143
|
+
)
|
|
144
|
+
|
|
145
|
+
const signedPsbt = Psbt.fromHex(signedPsbtHex)
|
|
146
|
+
|
|
147
|
+
if (!isPsbtFinalized(signedPsbt)) {
|
|
148
|
+
signedPsbt.finalizeAllInputs()
|
|
149
|
+
}
|
|
150
|
+
|
|
151
|
+
const txHex = signedPsbt.extractTransaction().toHex()
|
|
152
|
+
|
|
153
|
+
const txHash = await publicClient.sendUTXOTransaction({
|
|
154
|
+
hex: txHex,
|
|
155
|
+
})
|
|
156
|
+
|
|
157
|
+
statusManager.updateAction(step, action.type, 'PENDING', {
|
|
158
|
+
txHash: txHash,
|
|
159
|
+
txLink: `${fromChain.metamask.blockExplorerUrls[0]}tx/${txHash}`,
|
|
160
|
+
txHex,
|
|
161
|
+
signedAt: Date.now(),
|
|
162
|
+
})
|
|
163
|
+
|
|
164
|
+
return {
|
|
165
|
+
status: 'COMPLETED',
|
|
166
|
+
}
|
|
167
|
+
}
|
|
168
|
+
}
|
|
@@ -0,0 +1,74 @@
|
|
|
1
|
+
import type { ReplacementReason } from '@bigmi/core'
|
|
2
|
+
import { waitForTransaction } from '@bigmi/core'
|
|
3
|
+
import {
|
|
4
|
+
BaseStepExecutionTask,
|
|
5
|
+
LiFiErrorCode,
|
|
6
|
+
type TaskResult,
|
|
7
|
+
TransactionError,
|
|
8
|
+
} from '@lifi/sdk'
|
|
9
|
+
import type { BitcoinStepExecutorContext } from '../../types.js'
|
|
10
|
+
|
|
11
|
+
export class BitcoinWaitForTransactionTask extends BaseStepExecutionTask {
|
|
12
|
+
async run(context: BitcoinStepExecutorContext): Promise<TaskResult> {
|
|
13
|
+
const {
|
|
14
|
+
step,
|
|
15
|
+
statusManager,
|
|
16
|
+
fromChain,
|
|
17
|
+
isBridgeExecution,
|
|
18
|
+
walletClient,
|
|
19
|
+
publicClient,
|
|
20
|
+
checkClient,
|
|
21
|
+
} = context
|
|
22
|
+
|
|
23
|
+
const action = statusManager.findAction(
|
|
24
|
+
step,
|
|
25
|
+
isBridgeExecution ? 'CROSS_CHAIN' : 'SWAP'
|
|
26
|
+
)
|
|
27
|
+
|
|
28
|
+
const txHex = action?.txHex
|
|
29
|
+
const txHash = action?.txHash
|
|
30
|
+
|
|
31
|
+
if (!txHash || !txHex) {
|
|
32
|
+
throw new TransactionError(
|
|
33
|
+
LiFiErrorCode.TransactionUnprepared,
|
|
34
|
+
'Unable to prepare transaction. Transaction hash or hex is not set.'
|
|
35
|
+
)
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
checkClient(step)
|
|
39
|
+
|
|
40
|
+
let replacementReason: ReplacementReason | undefined
|
|
41
|
+
const transaction = await waitForTransaction(publicClient, {
|
|
42
|
+
txId: txHash,
|
|
43
|
+
txHex,
|
|
44
|
+
senderAddress: walletClient.account?.address,
|
|
45
|
+
onReplaced: (response) => {
|
|
46
|
+
replacementReason = response.reason
|
|
47
|
+
statusManager.updateAction(step, action.type, 'PENDING', {
|
|
48
|
+
txHash: response.transaction.txid,
|
|
49
|
+
txLink: `${fromChain.metamask.blockExplorerUrls[0]}tx/${response.transaction.txid}`,
|
|
50
|
+
})
|
|
51
|
+
},
|
|
52
|
+
})
|
|
53
|
+
|
|
54
|
+
if (replacementReason === 'cancelled') {
|
|
55
|
+
throw new TransactionError(
|
|
56
|
+
LiFiErrorCode.TransactionCanceled,
|
|
57
|
+
'User canceled transaction.'
|
|
58
|
+
)
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
if (transaction.txid !== txHash) {
|
|
62
|
+
statusManager.updateAction(step, action.type, 'PENDING', {
|
|
63
|
+
txHash: transaction.txid,
|
|
64
|
+
txLink: `${fromChain.metamask.blockExplorerUrls[0]}tx/${transaction.txid}`,
|
|
65
|
+
})
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
if (isBridgeExecution) {
|
|
69
|
+
statusManager.updateAction(step, action.type, 'DONE')
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
return { status: 'COMPLETED' }
|
|
73
|
+
}
|
|
74
|
+
}
|