@lifi/sdk-provider-bitcoin 4.0.1-alpha.0 → 4.0.1
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/CHANGELOG.md +23 -0
- package/README.md +88 -5
- package/dist/cjs/BitcoinProvider.d.ts +7 -2
- package/dist/cjs/BitcoinProvider.js +30 -34
- package/dist/cjs/BitcoinProvider.js.map +1 -1
- package/dist/cjs/_virtual/_rolldown/runtime.js +23 -0
- package/dist/cjs/actions/getBitcoinBalance.d.ts +7 -2
- package/dist/cjs/actions/getBitcoinBalance.js +21 -24
- package/dist/cjs/actions/getBitcoinBalance.js.map +1 -1
- package/dist/cjs/actions/resolveBitcoinAddress.d.ts +5 -1
- package/dist/cjs/actions/resolveBitcoinAddress.js +6 -4
- package/dist/cjs/actions/resolveBitcoinAddress.js.map +1 -1
- package/dist/cjs/client/publicClient.d.ts +14 -4
- package/dist/cjs/client/publicClient.js +38 -42
- package/dist/cjs/client/publicClient.js.map +1 -1
- package/dist/cjs/core/BitcoinStepExecutor.d.ts +19 -0
- package/dist/cjs/core/BitcoinStepExecutor.js +47 -0
- package/dist/cjs/core/BitcoinStepExecutor.js.map +1 -0
- package/dist/cjs/core/tasks/BitcoinSignAndExecuteTask.d.ts +10 -0
- package/dist/cjs/core/tasks/BitcoinSignAndExecuteTask.js +75 -0
- package/dist/cjs/core/tasks/BitcoinSignAndExecuteTask.js.map +1 -0
- package/dist/cjs/core/tasks/BitcoinWaitForTransactionTask.d.ts +10 -0
- package/dist/cjs/core/tasks/BitcoinWaitForTransactionTask.js +38 -0
- package/dist/cjs/core/tasks/BitcoinWaitForTransactionTask.js.map +1 -0
- package/dist/cjs/errors/parseBitcoinErrors.d.ts +7 -2
- package/dist/cjs/errors/parseBitcoinErrors.js +17 -26
- package/dist/cjs/errors/parseBitcoinErrors.js.map +1 -1
- package/dist/cjs/index.d.ts +3 -3
- package/dist/cjs/index.js +5 -8
- package/dist/cjs/types.d.ts +18 -7
- package/dist/cjs/types.js +7 -5
- package/dist/cjs/types.js.map +1 -1
- package/dist/cjs/utils/generateRedeemScript.d.ts +10 -1
- package/dist/cjs/utils/generateRedeemScript.js +11 -5
- package/dist/cjs/utils/generateRedeemScript.js.map +1 -1
- package/dist/cjs/utils/isPsbtFinalized.d.ts +7 -2
- package/dist/cjs/utils/isPsbtFinalized.js +11 -10
- package/dist/cjs/utils/isPsbtFinalized.js.map +1 -1
- package/dist/cjs/utils/toBigmiChainId.d.ts +8 -3
- package/dist/cjs/utils/toBigmiChainId.js +10 -11
- package/dist/cjs/utils/toBigmiChainId.js.map +1 -1
- package/dist/cjs/utils/toXOnly.d.ts +5 -1
- package/dist/cjs/utils/toXOnly.js +4 -3
- package/dist/cjs/utils/toXOnly.js.map +1 -1
- package/dist/cjs/version.d.ts +6 -2
- package/dist/cjs/version.js +8 -5
- package/dist/cjs/version.js.map +1 -1
- package/dist/esm/BitcoinProvider.d.ts +7 -2
- package/dist/esm/BitcoinProvider.d.ts.map +1 -0
- package/dist/esm/BitcoinProvider.js +30 -32
- package/dist/esm/BitcoinProvider.js.map +1 -1
- package/dist/esm/actions/getBitcoinBalance.d.ts +7 -2
- package/dist/esm/actions/getBitcoinBalance.d.ts.map +1 -0
- package/dist/esm/actions/getBitcoinBalance.js +22 -22
- package/dist/esm/actions/getBitcoinBalance.js.map +1 -1
- package/dist/esm/actions/resolveBitcoinAddress.d.ts +5 -1
- package/dist/esm/actions/resolveBitcoinAddress.d.ts.map +1 -0
- package/dist/esm/actions/resolveBitcoinAddress.js +6 -3
- package/dist/esm/actions/resolveBitcoinAddress.js.map +1 -1
- package/dist/esm/client/publicClient.d.ts +13 -9
- package/dist/esm/client/publicClient.d.ts.map +1 -0
- package/dist/esm/client/publicClient.js +38 -46
- package/dist/esm/client/publicClient.js.map +1 -1
- package/dist/esm/core/BitcoinStepExecutor.d.ts +19 -0
- package/dist/esm/core/BitcoinStepExecutor.d.ts.map +1 -0
- package/dist/esm/core/BitcoinStepExecutor.js +46 -0
- package/dist/esm/core/BitcoinStepExecutor.js.map +1 -0
- package/dist/esm/core/tasks/BitcoinSignAndExecuteTask.d.ts +10 -0
- package/dist/esm/core/tasks/BitcoinSignAndExecuteTask.d.ts.map +1 -0
- package/dist/esm/core/tasks/BitcoinSignAndExecuteTask.js +72 -0
- package/dist/esm/core/tasks/BitcoinSignAndExecuteTask.js.map +1 -0
- package/dist/esm/core/tasks/BitcoinWaitForTransactionTask.d.ts +10 -0
- package/dist/esm/core/tasks/BitcoinWaitForTransactionTask.d.ts.map +1 -0
- package/dist/esm/core/tasks/BitcoinWaitForTransactionTask.js +37 -0
- package/dist/esm/core/tasks/BitcoinWaitForTransactionTask.js.map +1 -0
- package/dist/esm/errors/parseBitcoinErrors.d.ts +7 -2
- package/dist/esm/errors/parseBitcoinErrors.d.ts.map +1 -0
- package/dist/esm/errors/parseBitcoinErrors.js +17 -24
- package/dist/esm/errors/parseBitcoinErrors.js.map +1 -1
- package/dist/esm/index.d.ts +3 -3
- package/dist/esm/index.js +3 -4
- package/dist/esm/package.json +1 -1
- package/dist/esm/types.d.ts +18 -7
- package/dist/esm/types.d.ts.map +1 -0
- package/dist/esm/types.js +7 -3
- package/dist/esm/types.js.map +1 -1
- package/dist/esm/utils/generateRedeemScript.d.ts +9 -5
- package/dist/esm/utils/generateRedeemScript.d.ts.map +1 -0
- package/dist/esm/utils/generateRedeemScript.js +10 -8
- package/dist/esm/utils/generateRedeemScript.js.map +1 -1
- package/dist/esm/utils/isPsbtFinalized.d.ts +7 -2
- package/dist/esm/utils/isPsbtFinalized.d.ts.map +1 -0
- package/dist/esm/utils/isPsbtFinalized.js +11 -8
- package/dist/esm/utils/isPsbtFinalized.js.map +1 -1
- package/dist/esm/utils/toBigmiChainId.d.ts +8 -3
- package/dist/esm/utils/toBigmiChainId.d.ts.map +1 -0
- package/dist/esm/utils/toBigmiChainId.js +11 -9
- package/dist/esm/utils/toBigmiChainId.js.map +1 -1
- package/dist/esm/utils/toXOnly.d.ts +5 -1
- package/dist/esm/utils/toXOnly.d.ts.map +1 -0
- package/dist/esm/utils/toXOnly.js +5 -2
- package/dist/esm/utils/toXOnly.js.map +1 -1
- package/dist/esm/version.d.ts +6 -2
- package/dist/esm/version.d.ts.map +1 -0
- package/dist/esm/version.js +6 -2
- package/dist/esm/version.js.map +1 -1
- package/package.json +7 -6
- package/src/BitcoinProvider.ts +1 -1
- package/src/actions/getBitcoinBalance.ts +15 -3
- package/src/client/publicClient.ts +1 -1
- package/src/core/BitcoinStepExecutor.ts +100 -0
- package/src/core/tasks/BitcoinSignAndExecuteTask.ts +168 -0
- package/src/core/tasks/BitcoinWaitForTransactionTask.ts +74 -0
- package/src/types.ts +13 -1
- package/src/utils/generateRedeemScript.ts +3 -1
- package/src/utils/toXOnly.ts +1 -1
- package/src/version.ts +1 -1
- package/dist/cjs/BitcoinStepExecutor.d.ts +0 -12
- package/dist/cjs/BitcoinStepExecutor.js +0 -198
- package/dist/cjs/BitcoinStepExecutor.js.map +0 -1
- package/dist/cjs/index.js.map +0 -1
- package/dist/esm/BitcoinStepExecutor.d.ts +0 -12
- package/dist/esm/BitcoinStepExecutor.js +0 -210
- package/dist/esm/BitcoinStepExecutor.js.map +0 -1
- package/dist/esm/index.js.map +0 -1
- package/dist/types/BitcoinProvider.d.ts +0 -3
- package/dist/types/BitcoinProvider.d.ts.map +0 -1
- package/dist/types/BitcoinStepExecutor.d.ts +0 -13
- package/dist/types/BitcoinStepExecutor.d.ts.map +0 -1
- package/dist/types/actions/getBitcoinBalance.d.ts +0 -3
- package/dist/types/actions/getBitcoinBalance.d.ts.map +0 -1
- package/dist/types/actions/resolveBitcoinAddress.d.ts +0 -2
- package/dist/types/actions/resolveBitcoinAddress.d.ts.map +0 -1
- package/dist/types/client/publicClient.d.ts +0 -12
- package/dist/types/client/publicClient.d.ts.map +0 -1
- package/dist/types/errors/parseBitcoinErrors.d.ts +0 -3
- package/dist/types/errors/parseBitcoinErrors.d.ts.map +0 -1
- package/dist/types/index.d.ts +0 -4
- package/dist/types/index.d.ts.map +0 -1
- package/dist/types/types.d.ts +0 -10
- package/dist/types/types.d.ts.map +0 -1
- package/dist/types/utils/generateRedeemScript.d.ts +0 -7
- package/dist/types/utils/generateRedeemScript.d.ts.map +0 -1
- package/dist/types/utils/isPsbtFinalized.d.ts +0 -3
- package/dist/types/utils/isPsbtFinalized.d.ts.map +0 -1
- package/dist/types/utils/toBigmiChainId.d.ts +0 -4
- package/dist/types/utils/toBigmiChainId.d.ts.map +0 -1
- package/dist/types/utils/toXOnly.d.ts +0 -2
- package/dist/types/utils/toXOnly.d.ts.map +0 -1
- package/dist/types/version.d.ts +0 -3
- package/dist/types/version.d.ts.map +0 -1
- package/src/BitcoinStepExecutor.ts +0 -333
package/CHANGELOG.md
ADDED
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
# @lifi/sdk-provider-bitcoin
|
|
2
|
+
|
|
3
|
+
## 4.0.1
|
|
4
|
+
|
|
5
|
+
### Patch Changes
|
|
6
|
+
|
|
7
|
+
- Updated dependencies [[`bf3d047`](https://github.com/lifinance/sdk/commit/bf3d047ebdc9a8b3a5a6362f65d25aa1eb652ffa)]:
|
|
8
|
+
- @lifi/sdk@4.0.1
|
|
9
|
+
|
|
10
|
+
## 4.0.0
|
|
11
|
+
|
|
12
|
+
### Patch Changes
|
|
13
|
+
|
|
14
|
+
- [#398](https://github.com/lifinance/sdk/pull/398) [`e4e4600`](https://github.com/lifinance/sdk/commit/e4e460063aa22d672f1ea3fd26ffa9faf2655398) Thanks [@chybisov](https://github.com/chybisov)! - Bump @bigmi/core to 0.8.1.
|
|
15
|
+
|
|
16
|
+
- Updated dependencies []:
|
|
17
|
+
- @lifi/sdk@4.0.0
|
|
18
|
+
|
|
19
|
+
## 4.0.0-beta.12
|
|
20
|
+
|
|
21
|
+
### Patch Changes
|
|
22
|
+
|
|
23
|
+
- [#398](https://github.com/lifinance/sdk/pull/398) [`e4e4600`](https://github.com/lifinance/sdk/commit/e4e460063aa22d672f1ea3fd26ffa9faf2655398) Thanks [@chybisov](https://github.com/chybisov)! - Bump @bigmi/core to 0.8.1.
|
package/README.md
CHANGED
|
@@ -13,18 +13,23 @@
|
|
|
13
13
|
|
|
14
14
|
[**LI.FI SDK**](https://docs.li.fi/sdk/overview) features include:
|
|
15
15
|
|
|
16
|
+
- **Modular architecture** - Install only the provider packages you need for your supported blockchain ecosystems (EVM, Solana, Bitcoin, Sui, Tron)
|
|
16
17
|
- All ecosystems, chains, bridges, exchanges, and solvers that [LI.FI](https://docs.li.fi/introduction/chains) supports
|
|
17
18
|
- Complete functionality covering full-cycle from obtaining routes/quotes to executing transactions
|
|
18
19
|
- Easy tracking of the route and quote execution through the robust event and hooks handling
|
|
19
20
|
- Highly customizable settings to tailor the SDK to your specific needs including configuration of RPCs and options to allow or deny certain chains, tokens, bridges, exchanges, solvers
|
|
20
21
|
- Supports widely adopted industry standards, including [EIP-5792](https://eips.ethereum.org/EIPS/eip-5792), [ERC-2612](https://eips.ethereum.org/EIPS/eip-2612), [EIP-712](https://eips.ethereum.org/EIPS/eip-712), and [Permit2](https://github.com/Uniswap/permit2)
|
|
21
|
-
- SDK ecosystem providers are based on industry-standard libraries ([Viem](https://viem.sh/), [
|
|
22
|
+
- SDK ecosystem providers are based on industry-standard libraries ([Viem](https://viem.sh/) for EVM, [Solana Kit](https://github.com/solana-labs/solana-web3.js) for Solana, [Bigmi](https://github.com/lifinance/bigmi) for Bitcoin, [Mysten Sui SDK](https://github.com/MystenLabs/sui/tree/main/sdk) for Sui, [TronWeb](https://tronweb.network/) for Tron)
|
|
22
23
|
- Support for arbitrary contract calls on the destination chain
|
|
23
24
|
- Designed for optimal performance with tree-shaking and dead-code elimination, ensuring minimal bundle sizes and faster page load times in front-end environments
|
|
24
25
|
- Compatibility tested with Node.js and popular front-end tools like Vite
|
|
25
26
|
|
|
26
27
|
## Installation
|
|
27
28
|
|
|
29
|
+
The LI.FI SDK follows a modular architecture. Install the core SDK package and the provider packages for the blockchain ecosystems you need:
|
|
30
|
+
|
|
31
|
+
### Core SDK
|
|
32
|
+
|
|
28
33
|
```bash
|
|
29
34
|
pnpm add @lifi/sdk
|
|
30
35
|
```
|
|
@@ -35,17 +40,95 @@ or
|
|
|
35
40
|
npm install --save @lifi/sdk
|
|
36
41
|
```
|
|
37
42
|
|
|
43
|
+
### Provider Packages
|
|
44
|
+
|
|
45
|
+
Install provider packages based on the blockchain ecosystems you want to support:
|
|
46
|
+
|
|
47
|
+
**EVM Chains (Ethereum, Polygon, Arbitrum, Optimism, etc.)**
|
|
48
|
+
```bash
|
|
49
|
+
pnpm add @lifi/sdk-provider-ethereum
|
|
50
|
+
```
|
|
51
|
+
|
|
52
|
+
**Solana**
|
|
53
|
+
```bash
|
|
54
|
+
pnpm add @lifi/sdk-provider-solana
|
|
55
|
+
```
|
|
56
|
+
|
|
57
|
+
**Bitcoin**
|
|
58
|
+
```bash
|
|
59
|
+
pnpm add @lifi/sdk-provider-bitcoin
|
|
60
|
+
```
|
|
61
|
+
|
|
62
|
+
**Sui**
|
|
63
|
+
```bash
|
|
64
|
+
pnpm add @lifi/sdk-provider-sui
|
|
65
|
+
```
|
|
66
|
+
|
|
67
|
+
**Tron**
|
|
68
|
+
```bash
|
|
69
|
+
pnpm add @lifi/sdk-provider-tron
|
|
70
|
+
```
|
|
71
|
+
|
|
72
|
+
## Architecture
|
|
73
|
+
|
|
74
|
+
The LI.FI SDK uses a modular provider architecture:
|
|
75
|
+
|
|
76
|
+
- **`@lifi/sdk`** - Core SDK package containing shared functionality, actions, and execution logic
|
|
77
|
+
- **Provider packages** - Ecosystem-specific packages that handle wallet interactions and transaction execution for different blockchain types
|
|
78
|
+
|
|
79
|
+
This architecture allows you to:
|
|
80
|
+
- Install only the providers you need, reducing bundle size
|
|
81
|
+
- Use ecosystem-specific libraries optimized for each blockchain
|
|
82
|
+
- Maintain clean separation between core SDK logic and blockchain-specific implementations
|
|
83
|
+
|
|
38
84
|
## Quick Start
|
|
39
85
|
|
|
40
86
|
### Set up the SDK
|
|
41
87
|
|
|
42
|
-
|
|
88
|
+
Create SDK config with your integrator string and configure the providers for the blockchain ecosystems you want to support.
|
|
43
89
|
|
|
90
|
+
**For EVM chains:**
|
|
44
91
|
```ts
|
|
45
|
-
import {
|
|
92
|
+
import { createClient } from '@lifi/sdk'
|
|
93
|
+
import { EthereumProvider } from '@lifi/sdk-provider-ethereum'
|
|
94
|
+
import { createWalletClient, http } from 'viem'
|
|
95
|
+
import { mainnet } from 'viem/chains'
|
|
96
|
+
|
|
97
|
+
// Add your account (e.g. privateKeyToAccount, mnemonicToAccount)
|
|
98
|
+
const walletClient = createWalletClient({
|
|
99
|
+
account,
|
|
100
|
+
chain: mainnet,
|
|
101
|
+
transport: http(),
|
|
102
|
+
})
|
|
46
103
|
|
|
47
|
-
|
|
104
|
+
const client = createClient({
|
|
105
|
+
integrator: 'Your dApp/company name',
|
|
106
|
+
providers: [
|
|
107
|
+
EthereumProvider({
|
|
108
|
+
getWalletClient: () => Promise.resolve(walletClient),
|
|
109
|
+
}),
|
|
110
|
+
],
|
|
111
|
+
})
|
|
112
|
+
```
|
|
113
|
+
|
|
114
|
+
**For multiple ecosystems:**
|
|
115
|
+
```ts
|
|
116
|
+
import { createClient } from '@lifi/sdk'
|
|
117
|
+
import { EthereumProvider } from '@lifi/sdk-provider-ethereum'
|
|
118
|
+
import { SolanaProvider } from '@lifi/sdk-provider-solana'
|
|
119
|
+
import { BitcoinProvider } from '@lifi/sdk-provider-bitcoin'
|
|
120
|
+
import { SuiProvider } from '@lifi/sdk-provider-sui'
|
|
121
|
+
import { TronProvider } from '@lifi/sdk-provider-tron'
|
|
122
|
+
|
|
123
|
+
const client = createClient({
|
|
48
124
|
integrator: 'Your dApp/company name',
|
|
125
|
+
providers: [
|
|
126
|
+
EthereumProvider({ /* options */ }),
|
|
127
|
+
SolanaProvider({ /* options */ }),
|
|
128
|
+
BitcoinProvider({ /* options */ }),
|
|
129
|
+
SuiProvider({ /* options */ }),
|
|
130
|
+
TronProvider({ /* options */ }),
|
|
131
|
+
],
|
|
49
132
|
})
|
|
50
133
|
```
|
|
51
134
|
|
|
@@ -56,7 +139,7 @@ Now you can interact with the SDK and for example request a quote.
|
|
|
56
139
|
```ts
|
|
57
140
|
import { ChainId, getQuote } from '@lifi/sdk'
|
|
58
141
|
|
|
59
|
-
const quote = await getQuote({
|
|
142
|
+
const quote = await getQuote(client, {
|
|
60
143
|
fromAddress: '0xd8dA6BF26964aF9D7eEd9e03E53415D37aA96045',
|
|
61
144
|
fromChain: ChainId.ARB,
|
|
62
145
|
toChain: ChainId.OPT,
|
|
@@ -1,2 +1,7 @@
|
|
|
1
|
-
import
|
|
2
|
-
|
|
1
|
+
import { BitcoinProviderOptions, BitcoinSDKProvider } from "./types.js";
|
|
2
|
+
|
|
3
|
+
//#region src/BitcoinProvider.d.ts
|
|
4
|
+
declare function BitcoinProvider(options?: BitcoinProviderOptions): BitcoinSDKProvider;
|
|
5
|
+
//#endregion
|
|
6
|
+
export { BitcoinProvider };
|
|
7
|
+
//# sourceMappingURL=BitcoinProvider.d.ts.map
|
|
@@ -1,37 +1,33 @@
|
|
|
1
|
-
"
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
const
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
const BitcoinStepExecutor_js_1 = require("./BitcoinStepExecutor.js");
|
|
1
|
+
Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
|
|
2
|
+
const require_actions_getBitcoinBalance = require("./actions/getBitcoinBalance.js");
|
|
3
|
+
const require_actions_resolveBitcoinAddress = require("./actions/resolveBitcoinAddress.js");
|
|
4
|
+
const require_core_BitcoinStepExecutor = require("./core/BitcoinStepExecutor.js");
|
|
5
|
+
let _bigmi_core = require("@bigmi/core");
|
|
6
|
+
let _lifi_sdk = require("@lifi/sdk");
|
|
7
|
+
//#region src/BitcoinProvider.ts
|
|
9
8
|
function BitcoinProvider(options) {
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
return executor;
|
|
31
|
-
},
|
|
32
|
-
setOptions(options) {
|
|
33
|
-
Object.assign(_options, options);
|
|
34
|
-
},
|
|
35
|
-
};
|
|
9
|
+
const _options = options ?? {};
|
|
10
|
+
return {
|
|
11
|
+
get type() {
|
|
12
|
+
return _lifi_sdk.ChainType.UTXO;
|
|
13
|
+
},
|
|
14
|
+
isAddress: _bigmi_core.isUTXOAddress,
|
|
15
|
+
resolveAddress: require_actions_resolveBitcoinAddress.resolveBitcoinAddress,
|
|
16
|
+
getBalance: require_actions_getBitcoinBalance.getBitcoinBalance,
|
|
17
|
+
async getStepExecutor(options) {
|
|
18
|
+
if (!_options.getWalletClient) throw new Error("Client is not provided.");
|
|
19
|
+
return new require_core_BitcoinStepExecutor.BitcoinStepExecutor({
|
|
20
|
+
client: await _options.getWalletClient(),
|
|
21
|
+
routeId: options.routeId,
|
|
22
|
+
executionOptions: { ...options.executionOptions }
|
|
23
|
+
});
|
|
24
|
+
},
|
|
25
|
+
setOptions(options) {
|
|
26
|
+
Object.assign(_options, options);
|
|
27
|
+
}
|
|
28
|
+
};
|
|
36
29
|
}
|
|
30
|
+
//#endregion
|
|
31
|
+
exports.BitcoinProvider = BitcoinProvider;
|
|
32
|
+
|
|
37
33
|
//# sourceMappingURL=BitcoinProvider.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"BitcoinProvider.js","
|
|
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,CAAC;CACrD,OAAO;EACL,IAAI,OAAO;GACT,OAAOA,UAAAA,UAAU;EACnB;EACA,WAAWC,YAAAA;EACX,gBAAgBC,sCAAAA;EAChB,YAAYC,kCAAAA;EACZ,MAAM,gBACJ,SAC8B;GAC9B,IAAI,CAAC,SAAS,iBACZ,MAAM,IAAI,MAAM,yBAAyB;GAa3C,OAAO,IARcC,iCAAAA,oBAAoB;IACvC,QAAQ,MAHiB,SAAS,gBAAgB;IAIlD,SAAS,QAAQ;IACjB,kBAAkB,EAChB,GAAG,QAAQ,iBACb;GACF,CAEc;EAChB;EACA,WAAW,SAAiC;GAC1C,OAAO,OAAO,UAAU,OAAO;EACjC;CACF;AACF"}
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
//#region \0rolldown/runtime.js
|
|
2
|
+
var __create = Object.create;
|
|
3
|
+
var __defProp = Object.defineProperty;
|
|
4
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
5
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
6
|
+
var __getProtoOf = Object.getPrototypeOf;
|
|
7
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
8
|
+
var __copyProps = (to, from, except, desc) => {
|
|
9
|
+
if (from && typeof from === "object" || typeof from === "function") for (var keys = __getOwnPropNames(from), i = 0, n = keys.length, key; i < n; i++) {
|
|
10
|
+
key = keys[i];
|
|
11
|
+
if (!__hasOwnProp.call(to, key) && key !== except) __defProp(to, key, {
|
|
12
|
+
get: ((k) => from[k]).bind(null, key),
|
|
13
|
+
enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable
|
|
14
|
+
});
|
|
15
|
+
}
|
|
16
|
+
return to;
|
|
17
|
+
};
|
|
18
|
+
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", {
|
|
19
|
+
value: mod,
|
|
20
|
+
enumerable: true
|
|
21
|
+
}) : target, mod));
|
|
22
|
+
//#endregion
|
|
23
|
+
exports.__toESM = __toESM;
|
|
@@ -1,2 +1,7 @@
|
|
|
1
|
-
import {
|
|
2
|
-
|
|
1
|
+
import { SDKClient, Token, TokenAmount } from "@lifi/sdk";
|
|
2
|
+
|
|
3
|
+
//#region src/actions/getBitcoinBalance.d.ts
|
|
4
|
+
declare const getBitcoinBalance: (client: SDKClient, walletAddress: string, tokens: Token[]) => Promise<TokenAmount[]>;
|
|
5
|
+
//#endregion
|
|
6
|
+
export { getBitcoinBalance };
|
|
7
|
+
//# sourceMappingURL=getBitcoinBalance.d.ts.map
|
|
@@ -1,28 +1,25 @@
|
|
|
1
|
-
"
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
const publicClient_js_1 = require("../client/publicClient.js");
|
|
1
|
+
Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
|
|
2
|
+
const require_client_publicClient = require("../client/publicClient.js");
|
|
3
|
+
let _lifi_sdk = require("@lifi/sdk");
|
|
4
|
+
//#region src/actions/getBitcoinBalance.ts
|
|
6
5
|
const getBitcoinBalance = async (client, walletAddress, tokens) => {
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
...token,
|
|
23
|
-
amount: balance,
|
|
24
|
-
blockNumber: BigInt(blockCount),
|
|
25
|
-
}));
|
|
6
|
+
if (tokens.length === 0) return [];
|
|
7
|
+
const { chainId } = tokens[0];
|
|
8
|
+
for (const token of tokens) if (token.chainId !== chainId) console.warn("Requested tokens have to be on the same chain.");
|
|
9
|
+
const bigmiClient = await require_client_publicClient.getBitcoinPublicClient(client, _lifi_sdk.ChainId.BTC);
|
|
10
|
+
const [balance, blockCount] = await Promise.allSettled([bigmiClient.getBalance({ address: walletAddress }), bigmiClient.getBlockCount()]);
|
|
11
|
+
const blockNumber = blockCount.status === "fulfilled" ? BigInt(blockCount.value) : 0n;
|
|
12
|
+
if (balance.status !== "fulfilled") return tokens.map((token) => ({
|
|
13
|
+
...token,
|
|
14
|
+
blockNumber
|
|
15
|
+
}));
|
|
16
|
+
return tokens.map((token) => ({
|
|
17
|
+
...token,
|
|
18
|
+
amount: balance.value,
|
|
19
|
+
blockNumber
|
|
20
|
+
}));
|
|
26
21
|
};
|
|
22
|
+
//#endregion
|
|
27
23
|
exports.getBitcoinBalance = getBitcoinBalance;
|
|
24
|
+
|
|
28
25
|
//# sourceMappingURL=getBitcoinBalance.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"getBitcoinBalance.js","
|
|
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,CAAC;CAEV,MAAM,EAAE,YAAY,OAAO;CAC3B,KAAK,MAAM,SAAS,QAClB,IAAI,MAAM,YAAY,SACpB,QAAQ,KAAK,gDAAgD;CAGjE,MAAM,cAAc,MAAMA,4BAAAA,uBAAuB,QAAQC,UAAAA,QAAQ,GAAG;CACpE,MAAM,CAAC,SAAS,cAAc,MAAM,QAAQ,WAAW,CACrD,YAAY,WAAW,EAAE,SAAS,cAAc,CAAC,GACjD,YAAY,cAAc,CAC5B,CAAC;CAED,MAAM,cACJ,WAAW,WAAW,cAAc,OAAO,WAAW,KAAK,IAAI;CAEjE,IAAI,QAAQ,WAAW,aAGrB,OAAO,OAAO,KAAK,WAAW;EAC5B,GAAG;EACH;CACF,EAAE;CAGJ,OAAO,OAAO,KAAK,WAAW;EAC5B,GAAG;EACH,QAAQ,QAAQ;EAChB;CACF,EAAE;AACJ"}
|
|
@@ -1 +1,5 @@
|
|
|
1
|
-
|
|
1
|
+
//#region src/actions/resolveBitcoinAddress.d.ts
|
|
2
|
+
declare function resolveBitcoinAddress(name: string): Promise<string | undefined>;
|
|
3
|
+
//#endregion
|
|
4
|
+
export { resolveBitcoinAddress };
|
|
5
|
+
//# sourceMappingURL=resolveBitcoinAddress.d.ts.map
|
|
@@ -1,7 +1,9 @@
|
|
|
1
|
-
"
|
|
2
|
-
|
|
3
|
-
exports.resolveBitcoinAddress = resolveBitcoinAddress;
|
|
1
|
+
Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
|
|
2
|
+
//#region src/actions/resolveBitcoinAddress.ts
|
|
4
3
|
async function resolveBitcoinAddress(name) {
|
|
5
|
-
|
|
4
|
+
return name;
|
|
6
5
|
}
|
|
6
|
+
//#endregion
|
|
7
|
+
exports.resolveBitcoinAddress = resolveBitcoinAddress;
|
|
8
|
+
|
|
7
9
|
//# sourceMappingURL=resolveBitcoinAddress.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"resolveBitcoinAddress.js","
|
|
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;AACT"}
|
|
@@ -1,5 +1,15 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import
|
|
1
|
+
import { Account, Chain, Client, FallbackTransport, HttpTransport, PublicActions, UTXOSchema, WalletActions } from "@bigmi/core";
|
|
2
|
+
import { SDKClient } from "@lifi/sdk";
|
|
3
|
+
|
|
4
|
+
//#region src/client/publicClient.d.ts
|
|
3
5
|
type PublicClient = Client<FallbackTransport<readonly HttpTransport[]>, Chain, Account | undefined, UTXOSchema, PublicActions & WalletActions>;
|
|
4
|
-
|
|
5
|
-
|
|
6
|
+
/**
|
|
7
|
+
* Get an instance of a provider for a specific chain
|
|
8
|
+
* @param client - The SDK client
|
|
9
|
+
* @param chainId - Id of the chain the provider is for
|
|
10
|
+
* @returns The public client for the given chain
|
|
11
|
+
*/
|
|
12
|
+
declare const getBitcoinPublicClient: (client: SDKClient, chainId: number) => Promise<PublicClient>;
|
|
13
|
+
//#endregion
|
|
14
|
+
export { PublicClient, getBitcoinPublicClient };
|
|
15
|
+
//# sourceMappingURL=publicClient.d.ts.map
|
|
@@ -1,47 +1,43 @@
|
|
|
1
|
-
"
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
const toBigmiChainId_js_1 = require("../utils/toBigmiChainId.js");
|
|
1
|
+
Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
|
|
2
|
+
const require_utils_toBigmiChainId = require("../utils/toBigmiChainId.js");
|
|
3
|
+
let _bigmi_core = require("@bigmi/core");
|
|
4
|
+
//#region src/client/publicClient.ts
|
|
6
5
|
const publicClients = {};
|
|
6
|
+
/**
|
|
7
|
+
* Get an instance of a provider for a specific chain
|
|
8
|
+
* @param client - The SDK client
|
|
9
|
+
* @param chainId - Id of the chain the provider is for
|
|
10
|
+
* @returns The public client for the given chain
|
|
11
|
+
*/
|
|
7
12
|
const getBitcoinPublicClient = async (client, chainId) => {
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
]),
|
|
35
|
-
pollingInterval: 10_000,
|
|
36
|
-
})
|
|
37
|
-
.extend(core_1.publicActions)
|
|
38
|
-
.extend(core_1.walletActions);
|
|
39
|
-
publicClients[chainId] = bigmiClient;
|
|
40
|
-
}
|
|
41
|
-
if (!publicClients[chainId]) {
|
|
42
|
-
throw new Error(`Unable to configure provider for chain ${chainId}`);
|
|
43
|
-
}
|
|
44
|
-
return publicClients[chainId];
|
|
13
|
+
if (!publicClients[chainId]) {
|
|
14
|
+
const fallbackTransports = (await client.getRpcUrlsByChainId(chainId)).map((url) => (0, _bigmi_core.http)(url, { fetchOptions: { method: "POST" } }));
|
|
15
|
+
const _chain = await client.getChainById(chainId);
|
|
16
|
+
publicClients[chainId] = (0, _bigmi_core.createClient)({
|
|
17
|
+
chain: {
|
|
18
|
+
..._chain,
|
|
19
|
+
..._chain.metamask,
|
|
20
|
+
id: require_utils_toBigmiChainId.toBigmiChainId(_chain.id),
|
|
21
|
+
name: _chain.metamask.chainName,
|
|
22
|
+
rpcUrls: {
|
|
23
|
+
default: { http: _chain.metamask.rpcUrls },
|
|
24
|
+
public: { http: _chain.metamask.rpcUrls }
|
|
25
|
+
}
|
|
26
|
+
},
|
|
27
|
+
rpcSchema: (0, _bigmi_core.rpcSchema)(),
|
|
28
|
+
transport: (0, _bigmi_core.fallback)([
|
|
29
|
+
(0, _bigmi_core.blockchair)(),
|
|
30
|
+
(0, _bigmi_core.blockcypher)(),
|
|
31
|
+
(0, _bigmi_core.mempool)(),
|
|
32
|
+
...fallbackTransports
|
|
33
|
+
]),
|
|
34
|
+
pollingInterval: 1e4
|
|
35
|
+
}).extend(_bigmi_core.publicActions).extend(_bigmi_core.walletActions);
|
|
36
|
+
}
|
|
37
|
+
if (!publicClients[chainId]) throw new Error(`Unable to configure provider for chain ${chainId}`);
|
|
38
|
+
return publicClients[chainId];
|
|
45
39
|
};
|
|
40
|
+
//#endregion
|
|
46
41
|
exports.getBitcoinPublicClient = getBitcoinPublicClient;
|
|
42
|
+
|
|
47
43
|
//# sourceMappingURL=publicClient.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"publicClient.js","
|
|
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,CAAC;;;;;;;AAQrD,MAAa,yBAAyB,OACpC,QACA,YAC0B;CAC1B,IAAI,CAAC,cAAc,UAAU;EAE3B,MAAM,sBAAqB,MADR,OAAO,oBAAoB,OAAO,EAAA,CACrB,KAAK,SAAA,GAAA,YAAA,KAAA,CAC9B,KAAK,EACR,cAAc,EACZ,QAAQ,OACV,EACF,CAAC,CACH;EACA,MAAM,SAAS,MAAM,OAAO,aAAa,OAAO;EAwBhD,cAAc,YAAA,GAAA,YAAA,aAAA,CAbmB;GAC/B,OAAA;IAVA,GAAG;IACH,GAAG,OAAO;IACV,IAAIA,6BAAAA,eAAe,OAAO,EAAE;IAC5B,MAAM,OAAO,SAAS;IACtB,SAAS;KACP,SAAS,EAAE,MAAM,OAAO,SAAS,QAAQ;KACzC,QAAQ,EAAE,MAAM,OAAO,SAAS,QAAQ;IAC1C;GAGI;GACJ,YAAA,GAAA,YAAA,UAAA,CAAiC;GACjC,YAAA,GAAA,YAAA,SAAA,CAAoB;gCACP;iCACC;6BACJ;IACR,GAAG;GACL,CAAC;GACD,iBAAiB;EACnB,CAAC,CAAC,CACC,OAAOC,YAAAA,aAAa,CAAC,CACrB,OAAOC,YAAAA,aACyB;CACrC;CAEA,IAAI,CAAC,cAAc,UACjB,MAAM,IAAI,MAAM,0CAA0C,SAAS;CAGrE,OAAO,cAAc;AACvB"}
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
import { BitcoinStepExecutorContext } from "../types.js";
|
|
2
|
+
import { Client } from "@bigmi/core";
|
|
3
|
+
import { BaseStepExecutor, ExecutionAction, LiFiStepExtended, SDKError, StepExecutorBaseContext, StepExecutorOptions, TaskPipeline } from "@lifi/sdk";
|
|
4
|
+
|
|
5
|
+
//#region src/core/BitcoinStepExecutor.d.ts
|
|
6
|
+
interface BitcoinStepExecutorOptions extends StepExecutorOptions {
|
|
7
|
+
client: Client;
|
|
8
|
+
}
|
|
9
|
+
declare class BitcoinStepExecutor extends BaseStepExecutor {
|
|
10
|
+
private client;
|
|
11
|
+
constructor(options: BitcoinStepExecutorOptions);
|
|
12
|
+
checkClient: (step: LiFiStepExtended) => void;
|
|
13
|
+
override createPipeline: (context: BitcoinStepExecutorContext) => TaskPipeline;
|
|
14
|
+
override parseErrors: (error: Error, step?: LiFiStepExtended, action?: ExecutionAction) => Promise<SDKError>;
|
|
15
|
+
override createContext: (baseContext: StepExecutorBaseContext) => Promise<BitcoinStepExecutorContext>;
|
|
16
|
+
}
|
|
17
|
+
//#endregion
|
|
18
|
+
export { BitcoinStepExecutor };
|
|
19
|
+
//# sourceMappingURL=BitcoinStepExecutor.d.ts.map
|
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
|
|
2
|
+
const require_client_publicClient = require("../client/publicClient.js");
|
|
3
|
+
const require_errors_parseBitcoinErrors = require("../errors/parseBitcoinErrors.js");
|
|
4
|
+
const require_core_tasks_BitcoinSignAndExecuteTask = require("./tasks/BitcoinSignAndExecuteTask.js");
|
|
5
|
+
const require_core_tasks_BitcoinWaitForTransactionTask = require("./tasks/BitcoinWaitForTransactionTask.js");
|
|
6
|
+
let _lifi_sdk = require("@lifi/sdk");
|
|
7
|
+
//#region src/core/BitcoinStepExecutor.ts
|
|
8
|
+
var BitcoinStepExecutor = class extends _lifi_sdk.BaseStepExecutor {
|
|
9
|
+
client;
|
|
10
|
+
constructor(options) {
|
|
11
|
+
super(options);
|
|
12
|
+
this.client = options.client;
|
|
13
|
+
}
|
|
14
|
+
checkClient = (step) => {
|
|
15
|
+
if (this.client.account?.address !== step.action.fromAddress) throw new _lifi_sdk.TransactionError(_lifi_sdk.LiFiErrorCode.WalletChangedDuringExecution, "The wallet address that requested the quote does not match the wallet address attempting to sign the transaction.");
|
|
16
|
+
};
|
|
17
|
+
createPipeline = (context) => {
|
|
18
|
+
const { step, isBridgeExecution } = context;
|
|
19
|
+
const tasks = [
|
|
20
|
+
new _lifi_sdk.CheckBalanceTask(),
|
|
21
|
+
new _lifi_sdk.PrepareTransactionTask(),
|
|
22
|
+
new require_core_tasks_BitcoinSignAndExecuteTask.BitcoinSignAndExecuteTask(),
|
|
23
|
+
new require_core_tasks_BitcoinWaitForTransactionTask.BitcoinWaitForTransactionTask(),
|
|
24
|
+
new _lifi_sdk.WaitForTransactionStatusTask(isBridgeExecution ? "RECEIVING_CHAIN" : "SWAP")
|
|
25
|
+
];
|
|
26
|
+
const swapOrBridgeAction = this.statusManager.findAction(step, isBridgeExecution ? "CROSS_CHAIN" : "SWAP");
|
|
27
|
+
const taskName = swapOrBridgeAction?.txHash ? swapOrBridgeAction?.status === "DONE" ? _lifi_sdk.WaitForTransactionStatusTask.name : require_core_tasks_BitcoinWaitForTransactionTask.BitcoinWaitForTransactionTask.name : _lifi_sdk.CheckBalanceTask.name;
|
|
28
|
+
const firstTaskIndex = tasks.findIndex((task) => task.constructor.name === taskName);
|
|
29
|
+
return new _lifi_sdk.TaskPipeline(tasks.slice(firstTaskIndex));
|
|
30
|
+
};
|
|
31
|
+
parseErrors = (error, step, action) => require_errors_parseBitcoinErrors.parseBitcoinErrors(error, step, action);
|
|
32
|
+
createContext = async (baseContext) => {
|
|
33
|
+
const { client, fromChain } = baseContext;
|
|
34
|
+
const publicClient = await require_client_publicClient.getBitcoinPublicClient(client, fromChain.id);
|
|
35
|
+
return {
|
|
36
|
+
...baseContext,
|
|
37
|
+
pollingIntervalMs: 1e4,
|
|
38
|
+
checkClient: this.checkClient,
|
|
39
|
+
walletClient: this.client,
|
|
40
|
+
publicClient
|
|
41
|
+
};
|
|
42
|
+
};
|
|
43
|
+
};
|
|
44
|
+
//#endregion
|
|
45
|
+
exports.BitcoinStepExecutor = BitcoinStepExecutor;
|
|
46
|
+
|
|
47
|
+
//# sourceMappingURL=BitcoinStepExecutor.js.map
|
|
@@ -0,0 +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;EAC/C,MAAM,OAAO;EACb,KAAK,SAAS,QAAQ;CACxB;CAEA,eAAe,SAAiC;EAG9C,IAAI,KAAK,OAAO,SAAS,YAAY,KAAK,OAAO,aAC/C,MAAM,IAAIC,UAAAA,iBACRC,UAAAA,cAAc,8BACd,mHACF;CAEJ;CAEA,kBACE,YACiB;EACjB,MAAM,EAAE,MAAM,sBAAsB;EAEpC,MAAM,QAAQ;GACZ,IAAIC,UAAAA,iBAAiB;GACrB,IAAIC,UAAAA,uBAAuB;GAC3B,IAAIC,6CAAAA,0BAA0B;GAC9B,IAAIC,iDAAAA,8BAA8B;GAClC,IAAIC,UAAAA,6BACF,oBAAoB,oBAAoB,MAC1C;EACF;EACA,MAAM,qBAAqB,KAAK,cAAc,WAC5C,MACA,oBAAoB,gBAAgB,MACtC;EAEA,MAAM,WAAW,oBAAoB,SACjC,oBAAoB,WAAW,SAC7BA,UAAAA,6BAA6B,OAC7BD,iDAAAA,8BAA8B,OAChCH,UAAAA,iBAAiB;EAErB,MAAM,iBAAiB,MAAM,WAC1B,SAAS,KAAK,YAAY,SAAS,QACtC;EAIA,OAAO,IAAIK,UAAAA,aAFQ,MAAM,MAAM,cAEE,CAAC;CACpC;CAEA,eACE,OACA,MACA,WACsBC,kCAAAA,mBAAmB,OAAO,MAAM,MAAM;CAE9D,gBAAyB,OACvB,gBACwC;EACxC,MAAM,EAAE,QAAQ,cAAc;EAE9B,MAAM,eAAe,MAAMC,4BAAAA,uBAAuB,QAAQ,UAAU,EAAE;EAEtE,OAAO;GACL,GAAG;GACH,mBAAmB;GACnB,aAAa,KAAK;GAClB,cAAc,KAAK;GACnB;EACF;CACF;AACF"}
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import { BitcoinStepExecutorContext } from "../../types.js";
|
|
2
|
+
import { BaseStepExecutionTask, TaskResult } from "@lifi/sdk";
|
|
3
|
+
|
|
4
|
+
//#region src/core/tasks/BitcoinSignAndExecuteTask.d.ts
|
|
5
|
+
declare class BitcoinSignAndExecuteTask extends BaseStepExecutionTask {
|
|
6
|
+
run(context: BitcoinStepExecutorContext): Promise<TaskResult>;
|
|
7
|
+
}
|
|
8
|
+
//#endregion
|
|
9
|
+
export { BitcoinSignAndExecuteTask };
|
|
10
|
+
//# sourceMappingURL=BitcoinSignAndExecuteTask.d.ts.map
|