@lombard.finance/sdk 4.2.0 → 4.3.0
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 +0 -94
- package/README.md +10 -59
- package/dist/api.cjs +1 -1
- package/dist/api.js +5 -5
- package/dist/bridge/lib/ccip-config.d.ts.map +1 -1
- package/dist/bridge/lib/config.d.ts +3 -3
- package/dist/bridge/lib/config.d.ts.map +1 -1
- package/dist/bridge.cjs +1 -1
- package/dist/bridge.js +1 -1
- package/dist/btc.cjs +1 -1
- package/dist/btc.js +2 -2
- package/dist/chunks/{BtcActions-D9eBmDj6.cjs → BtcActions-ByhBml_1.cjs} +2 -2
- package/dist/chunks/{BtcActions-D9eBmDj6.cjs.map → BtcActions-ByhBml_1.cjs.map} +1 -1
- package/dist/chunks/{BtcActions-DGqmtxjd.js → BtcActions-C_A1dUQ0.js} +20 -20
- package/dist/chunks/{BtcActions-DGqmtxjd.js.map → BtcActions-C_A1dUQ0.js.map} +1 -1
- package/dist/chunks/{EvmActions-BOwYPThp.cjs → EvmActions-DoYIhj61.cjs} +2 -2
- package/dist/chunks/{EvmActions-BOwYPThp.cjs.map → EvmActions-DoYIhj61.cjs.map} +1 -1
- package/dist/chunks/{EvmActions-MW5mNmqs.js → EvmActions-DucgT60w.js} +45 -45
- package/dist/chunks/{EvmActions-MW5mNmqs.js.map → EvmActions-DucgT60w.js.map} +1 -1
- package/dist/chunks/{ReferralsClient-DUwyIUe3.cjs → ReferralsClient-BC-1wT1q.cjs} +2 -2
- package/dist/chunks/{ReferralsClient-DUwyIUe3.cjs.map → ReferralsClient-BC-1wT1q.cjs.map} +1 -1
- package/dist/chunks/{ReferralsClient-JjWLlIO4.js → ReferralsClient-DbFWWtVi.js} +20 -20
- package/dist/chunks/{ReferralsClient-JjWLlIO4.js.map → ReferralsClient-DbFWWtVi.js.map} +1 -1
- package/dist/chunks/approveLBTC-B5-ZWqct.js +26 -0
- package/dist/chunks/{approveLBTC-DOP0wsm3.js.map → approveLBTC-B5-ZWqct.js.map} +1 -1
- package/dist/chunks/{approveLBTC-CN6rJF6_.cjs → approveLBTC-CZiZmdcX.cjs} +2 -2
- package/dist/chunks/{approveLBTC-CN6rJF6_.cjs.map → approveLBTC-CZiZmdcX.cjs.map} +1 -1
- package/dist/chunks/blockchain-identifier-BmadkNtK.js +113 -0
- package/dist/chunks/blockchain-identifier-BmadkNtK.js.map +1 -0
- package/dist/chunks/{blockchain-identifier-DtIGGlIi.cjs → blockchain-identifier-BzMQWh-C.cjs} +2 -2
- package/dist/chunks/blockchain-identifier-BzMQWh-C.cjs.map +1 -0
- package/dist/chunks/bridge-BzRlY9pP.cjs +12 -0
- package/dist/chunks/bridge-BzRlY9pP.cjs.map +1 -0
- package/dist/chunks/{bridge-DyAiDpxD.js → bridge-CTsiodO1.js} +72 -95
- package/dist/chunks/bridge-CTsiodO1.js.map +1 -0
- package/dist/chunks/{config-_8X_2sG4.js → config-hFKqUyg3.js} +2 -2
- package/dist/chunks/{config-_8X_2sG4.js.map → config-hFKqUyg3.js.map} +1 -1
- package/dist/chunks/{config-DqbLaiRi.cjs → config-l4ZaZw_g.cjs} +2 -2
- package/dist/chunks/{config-DqbLaiRi.cjs.map → config-l4ZaZw_g.cjs.map} +1 -1
- package/dist/chunks/{defi-registry-NGWlyxAY.cjs → defi-registry-BIRv_zkp.cjs} +2 -2
- package/dist/chunks/{defi-registry-NGWlyxAY.cjs.map → defi-registry-BIRv_zkp.cjs.map} +1 -1
- package/dist/chunks/{defi-registry-dhrQMy94.js → defi-registry-wNFN3qyB.js} +7 -7
- package/dist/chunks/{defi-registry-dhrQMy94.js.map → defi-registry-wNFN3qyB.js.map} +1 -1
- package/dist/chunks/{depositStatus-K6gky8zH.cjs → depositStatus-C3-EgT2a.cjs} +2 -2
- package/dist/chunks/{depositStatus-K6gky8zH.cjs.map → depositStatus-C3-EgT2a.cjs.map} +1 -1
- package/dist/chunks/{depositStatus-DeCO-K5Q.js → depositStatus-DM7fRmbN.js} +8 -8
- package/dist/chunks/{depositStatus-DeCO-K5Q.js.map → depositStatus-DM7fRmbN.js.map} +1 -1
- package/dist/chunks/{events-DIKZG4SZ.cjs → events-BTtwgCev.cjs} +2 -2
- package/dist/chunks/{events-DIKZG4SZ.cjs.map → events-BTtwgCev.cjs.map} +1 -1
- package/dist/chunks/{events-CLVUaKQS.js → events-DPi6MDRA.js} +35 -35
- package/dist/chunks/{events-CLVUaKQS.js.map → events-DPi6MDRA.js.map} +1 -1
- package/dist/chunks/{get-exchange-ratio-CM8W0jTw.cjs → get-exchange-ratio-C-7DadfD.cjs} +2 -2
- package/dist/chunks/{get-exchange-ratio-CM8W0jTw.cjs.map → get-exchange-ratio-C-7DadfD.cjs.map} +1 -1
- package/dist/chunks/get-exchange-ratio-NtnkG1kZ.js +20 -0
- package/dist/chunks/{get-exchange-ratio-B0CNEGOB.js.map → get-exchange-ratio-NtnkG1kZ.js.map} +1 -1
- package/dist/chunks/{get-positions-summary-Cled5YPA.js → get-positions-summary-B_MmGHLv.js} +4 -4
- package/dist/chunks/{get-positions-summary-Cled5YPA.js.map → get-positions-summary-B_MmGHLv.js.map} +1 -1
- package/dist/chunks/{get-positions-summary-Co7RZBiK.cjs → get-positions-summary-DkZZYbGP.cjs} +2 -2
- package/dist/chunks/{get-positions-summary-Co7RZBiK.cjs.map → get-positions-summary-DkZZYbGP.cjs.map} +1 -1
- package/dist/chunks/{get-vault-tvl-Bydlvlrv.cjs → get-vault-tvl-DmTUbOY7.cjs} +2 -2
- package/dist/chunks/{get-vault-tvl-Bydlvlrv.cjs.map → get-vault-tvl-DmTUbOY7.cjs.map} +1 -1
- package/dist/chunks/{get-vault-tvl-DxjO9xDs.js → get-vault-tvl-YAXePAW3.js} +4 -4
- package/dist/chunks/{get-vault-tvl-DxjO9xDs.js.map → get-vault-tvl-YAXePAW3.js.map} +1 -1
- package/dist/chunks/{get-vault-withdrawals-CSQqKFB8.js → get-vault-withdrawals-BrpZlt6s.js} +3 -3
- package/dist/chunks/{get-vault-withdrawals-CSQqKFB8.js.map → get-vault-withdrawals-BrpZlt6s.js.map} +1 -1
- package/dist/chunks/{get-vault-withdrawals-DBA3ok0m.cjs → get-vault-withdrawals-CWcYy_sH.cjs} +2 -2
- package/dist/chunks/{get-vault-withdrawals-DBA3ok0m.cjs.map → get-vault-withdrawals-CWcYy_sH.cjs.map} +1 -1
- package/dist/chunks/{getSharesByAddress-De7as74h.cjs → getSharesByAddress-U48H_ygt.cjs} +2 -2
- package/dist/chunks/{getSharesByAddress-De7as74h.cjs.map → getSharesByAddress-U48H_ygt.cjs.map} +1 -1
- package/dist/chunks/{getSharesByAddress-CK2q7gBI.js → getSharesByAddress-cUtkrKTq.js} +14 -14
- package/dist/chunks/{getSharesByAddress-CK2q7gBI.js.map → getSharesByAddress-cUtkrKTq.js.map} +1 -1
- package/dist/chunks/{getUserStakeAndBakeSignature--XsK93Lb.cjs → getUserStakeAndBakeSignature-BxRq2cI1.cjs} +2 -2
- package/dist/chunks/{getUserStakeAndBakeSignature--XsK93Lb.cjs.map → getUserStakeAndBakeSignature-BxRq2cI1.cjs.map} +1 -1
- package/dist/chunks/{getUserStakeAndBakeSignature-2xPkL9v_.js → getUserStakeAndBakeSignature-NGGblnJl.js} +11 -11
- package/dist/chunks/{getUserStakeAndBakeSignature-2xPkL9v_.js.map → getUserStakeAndBakeSignature-NGGblnJl.js.map} +1 -1
- package/dist/chunks/index-BKzxeh1Y.cjs.map +1 -1
- package/dist/chunks/index-CfcQ_g3t.js.map +1 -1
- package/dist/chunks/{lbtc-addresses-NHg9Gk5y.js → lbtc-addresses-BLRmtR3c.js} +2 -2
- package/dist/chunks/{lbtc-addresses-NHg9Gk5y.js.map → lbtc-addresses-BLRmtR3c.js.map} +1 -1
- package/dist/chunks/{lbtc-addresses-bj--zuK9.cjs → lbtc-addresses-xyTYV7hx.cjs} +2 -2
- package/dist/chunks/{lbtc-addresses-bj--zuK9.cjs.map → lbtc-addresses-xyTYV7hx.cjs.map} +1 -1
- package/dist/chunks/{statusConstants-ZJia15m2.js → statusConstants-CJk6vOiM.js} +844 -853
- package/dist/chunks/statusConstants-CJk6vOiM.js.map +1 -0
- package/dist/chunks/statusConstants-fmtIEEEM.cjs +2 -0
- package/dist/chunks/statusConstants-fmtIEEEM.cjs.map +1 -0
- package/dist/chunks/{storeNetworkFeeSignature-BZUZOxns.js → storeNetworkFeeSignature-BZGL2Zn_.js} +8 -8
- package/dist/chunks/{storeNetworkFeeSignature-BZUZOxns.js.map → storeNetworkFeeSignature-BZGL2Zn_.js.map} +1 -1
- package/dist/chunks/{storeNetworkFeeSignature-pV7xUOSo.cjs → storeNetworkFeeSignature-D7yo6lDV.cjs} +2 -2
- package/dist/chunks/{storeNetworkFeeSignature-pV7xUOSo.cjs.map → storeNetworkFeeSignature-D7yo6lDV.cjs.map} +1 -1
- package/dist/chunks/token-addresses-DRBecUa7.cjs +2 -0
- package/dist/chunks/token-addresses-DRBecUa7.cjs.map +1 -0
- package/dist/chunks/token-addresses-FKpA3uc4.js +541 -0
- package/dist/chunks/token-addresses-FKpA3uc4.js.map +1 -0
- package/dist/chunks/{tokens-Bw35TZqd.js → tokens-C6qZHzph.js} +28 -30
- package/dist/chunks/tokens-C6qZHzph.js.map +1 -0
- package/dist/chunks/tokens-D_HeVB5p.cjs +2 -0
- package/dist/chunks/tokens-D_HeVB5p.cjs.map +1 -0
- package/dist/chunks/{unstakeLBTC-Huy_ncVl.js → unstakeLBTC-B4Rwf65e.js} +141 -129
- package/dist/chunks/unstakeLBTC-B4Rwf65e.js.map +1 -0
- package/dist/chunks/unstakeLBTC-Wlfi14de.cjs +2 -0
- package/dist/chunks/unstakeLBTC-Wlfi14de.cjs.map +1 -0
- package/dist/chunks/{withdraw-Z77x7Hj4.cjs → withdraw-C1fMFSwy.cjs} +2 -2
- package/dist/chunks/{withdraw-Z77x7Hj4.cjs.map → withdraw-C1fMFSwy.cjs.map} +1 -1
- package/dist/chunks/{withdraw-CVNVJ7-x.js → withdraw-hHueI2p7.js} +9 -9
- package/dist/chunks/{withdraw-CVNVJ7-x.js.map → withdraw-hHueI2p7.js.map} +1 -1
- package/dist/clients/rpc-url-config.d.ts.map +1 -1
- package/dist/common/chains.d.ts +343 -112
- package/dist/common/chains.d.ts.map +1 -1
- package/dist/common/feature-config.d.ts.map +1 -1
- package/dist/contract-functions/getLBTCMintingFee/getLBTCMintingFee.d.ts +27 -0
- package/dist/contract-functions/getLBTCMintingFee/getLBTCMintingFee.d.ts.map +1 -1
- package/dist/contract-functions/signLbtcDestionationAddr/signLbtcDestinationAddr.d.ts +26 -0
- package/dist/contract-functions/signLbtcDestionationAddr/signLbtcDestinationAddr.d.ts.map +1 -1
- package/dist/contracts.cjs +1 -1
- package/dist/contracts.js +26 -24
- package/dist/core/chains/catalog.d.ts.map +1 -1
- package/dist/core/chains/types.d.ts +0 -1
- package/dist/core/chains/types.d.ts.map +1 -1
- package/dist/core.cjs +1 -1
- package/dist/core.js +29 -29
- package/dist/defi.cjs +1 -1
- package/dist/defi.js +3 -3
- package/dist/entries/contracts.d.ts +2 -2
- package/dist/entries/contracts.d.ts.map +1 -1
- package/dist/entries/evm.d.ts +1 -1
- package/dist/entries/evm.d.ts.map +1 -1
- package/dist/entries/utils.d.ts +1 -1
- package/dist/entries/utils.d.ts.map +1 -1
- package/dist/evm.cjs +1 -1
- package/dist/evm.js +34 -35
- package/dist/index.cjs +1 -1
- package/dist/index.d.ts +3 -3
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +188 -187
- package/dist/metrics.cjs +1 -1
- package/dist/metrics.js +1 -1
- package/dist/stories/components/decorators/wagmi-decorator.d.ts.map +1 -1
- package/dist/tokens/token-addresses.d.ts.map +1 -1
- package/dist/utils.cjs +1 -1
- package/dist/utils.js +48 -49
- package/dist/vaults.cjs +1 -1
- package/dist/vaults.js +15 -15
- package/package.json +2 -2
- package/dist/chunks/approveLBTC-DOP0wsm3.js +0 -26
- package/dist/chunks/blockchain-identifier-DtIGGlIi.cjs.map +0 -1
- package/dist/chunks/blockchain-identifier-PNEhu-QU.js +0 -113
- package/dist/chunks/blockchain-identifier-PNEhu-QU.js.map +0 -1
- package/dist/chunks/bridge-DkZMwO7c.cjs +0 -12
- package/dist/chunks/bridge-DkZMwO7c.cjs.map +0 -1
- package/dist/chunks/bridge-DyAiDpxD.js.map +0 -1
- package/dist/chunks/get-exchange-ratio-B0CNEGOB.js +0 -20
- package/dist/chunks/statusConstants-DTDi_4Go.cjs +0 -2
- package/dist/chunks/statusConstants-DTDi_4Go.cjs.map +0 -1
- package/dist/chunks/statusConstants-ZJia15m2.js.map +0 -1
- package/dist/chunks/token-addresses-D859i6tX.cjs +0 -2
- package/dist/chunks/token-addresses-D859i6tX.cjs.map +0 -1
- package/dist/chunks/token-addresses-DmAr89jP.js +0 -579
- package/dist/chunks/token-addresses-DmAr89jP.js.map +0 -1
- package/dist/chunks/tokens-Bw35TZqd.js.map +0 -1
- package/dist/chunks/tokens-DLGMNeqZ.cjs +0 -2
- package/dist/chunks/tokens-DLGMNeqZ.cjs.map +0 -1
- package/dist/chunks/unstakeLBTC-CqZzj9WL.cjs +0 -2
- package/dist/chunks/unstakeLBTC-CqZzj9WL.cjs.map +0 -1
- package/dist/chunks/unstakeLBTC-Huy_ncVl.js.map +0 -1
package/CHANGELOG.md
CHANGED
|
@@ -1,97 +1,3 @@
|
|
|
1
|
-
# 4.2.0
|
|
2
|
-
|
|
3
|
-
## Vault Withdraw Actions
|
|
4
|
-
|
|
5
|
-
Added new actions for withdrawing from DeFi vaults (Veda):
|
|
6
|
-
|
|
7
|
-
### New Features
|
|
8
|
-
|
|
9
|
-
- **`sdk.chain.evm.withdraw()`**: Queue vault share withdrawals from Veda vaults
|
|
10
|
-
- Supports Ethereum, Base, BSC, and Corn chains
|
|
11
|
-
- Full action lifecycle: prepare → approve → execute
|
|
12
|
-
- Automatic balance and allowance checks
|
|
13
|
-
- 14-day withdrawal queue with 0.01% discount
|
|
14
|
-
|
|
15
|
-
- **`sdk.chain.evm.cancelWithdraw()`**: Cancel pending withdrawal requests
|
|
16
|
-
- Cancel open withdrawals before they expire
|
|
17
|
-
- Zeros out the atomic request on-chain
|
|
18
|
-
|
|
19
|
-
- **`sdk.api.vaultWithdrawals(address)`**: Query vault withdrawals
|
|
20
|
-
- Returns withdrawals categorized by status: open, fulfilled, cancelled, expired
|
|
21
|
-
- Supports querying across all chains or a specific chain
|
|
22
|
-
|
|
23
|
-
### New Error Codes
|
|
24
|
-
|
|
25
|
-
Added `WithdrawErrorCode` enum for withdraw-specific errors:
|
|
26
|
-
- `INSUFFICIENT_SHARES`: Not enough vault shares
|
|
27
|
-
- `INVALID_AMOUNT`: Invalid withdrawal amount
|
|
28
|
-
- `NO_PENDING_WITHDRAWAL`: No pending withdrawal to cancel
|
|
29
|
-
- `WITHDRAWAL_EXPIRED`: Withdrawal request expired
|
|
30
|
-
- `PROTOCOL_NOT_SUPPORTED`: Protocol not supported on chain
|
|
31
|
-
|
|
32
|
-
### Usage
|
|
33
|
-
|
|
34
|
-
```typescript
|
|
35
|
-
// Queue a withdrawal
|
|
36
|
-
const withdraw = sdk.chain.evm.withdraw({
|
|
37
|
-
sourceChain: Chain.ETHEREUM,
|
|
38
|
-
protocol: 'veda',
|
|
39
|
-
recipient: '0x...',
|
|
40
|
-
});
|
|
41
|
-
await withdraw.prepare({ amount: '0.1' });
|
|
42
|
-
if (withdraw.needsApproval) await withdraw.approve();
|
|
43
|
-
const { txHash } = await withdraw.execute();
|
|
44
|
-
|
|
45
|
-
// Cancel a pending withdrawal
|
|
46
|
-
const cancel = sdk.chain.evm.cancelWithdraw({
|
|
47
|
-
chain: Chain.ETHEREUM,
|
|
48
|
-
protocol: 'veda',
|
|
49
|
-
});
|
|
50
|
-
await cancel.prepare();
|
|
51
|
-
await cancel.execute();
|
|
52
|
-
|
|
53
|
-
// Query withdrawals
|
|
54
|
-
const withdrawals = await sdk.api.vaultWithdrawals('0x...');
|
|
55
|
-
console.log(`Open: ${withdrawals.open.length}`);
|
|
56
|
-
|
|
57
|
-
### Breaking Changes / Migration
|
|
58
|
-
|
|
59
|
-
**viem is now a peer dependency**
|
|
60
|
-
|
|
61
|
-
You must install viem separately in your project:
|
|
62
|
-
```bash
|
|
63
|
-
npm install viem@^2.21.0
|
|
64
|
-
# or
|
|
65
|
-
yarn add viem@^2.21.0
|
|
66
|
-
```
|
|
67
|
-
|
|
68
|
-
## getOutputScript
|
|
69
|
-
|
|
70
|
-
**getOutputScript() is now async**
|
|
71
|
-
|
|
72
|
-
The `getOutputScript()` function from `@lombard.finance/sdk-common` is now async and must be awaited:
|
|
73
|
-
```typescript
|
|
74
|
-
// Before
|
|
75
|
-
const script = getOutputScript(address);
|
|
76
|
-
|
|
77
|
-
// After
|
|
78
|
-
const script = await getOutputScript(address);
|
|
79
|
-
```
|
|
80
|
-
|
|
81
|
-
See the [README](./README.md) for subpath import examples and migration guidance.
|
|
82
|
-
|
|
83
|
-
### Bundle Size Optimization
|
|
84
|
-
- Added 11 subpath imports for tree-shaking (`/btc`, `/evm`, `/utils`, `/api`, `/contracts`, `/core`, `/metrics`, `/vaults`, `/defi`, `/bridge`, `/debug`)
|
|
85
|
-
- Moved viem to peerDependencies (55-64% bundle reduction)
|
|
86
|
-
- Replaced barrel exports with explicit named exports
|
|
87
|
-
- Enabled lazy bitcoinjs-lib initialization
|
|
88
|
-
|
|
89
|
-
### Developer Experience
|
|
90
|
-
- Enabled source maps for production builds
|
|
91
|
-
- Documented elliptic transitive dependency advisory
|
|
92
|
-
|
|
93
|
-
---
|
|
94
|
-
|
|
95
1
|
# 4.1.1
|
|
96
2
|
|
|
97
3
|
- Fixed BTCb claiming on Avalanche chains: `getBasculeDepositStatus` now uses `getBascule()` for Bridge Token Adapter contracts instead of `Bascule()`, resolving "Function 'Bascule' not found on ABI" errors
|
package/README.md
CHANGED
|
@@ -13,10 +13,10 @@ npm install @lombard.finance/sdk
|
|
|
13
13
|
The SDK requires these peer dependencies:
|
|
14
14
|
|
|
15
15
|
```bash
|
|
16
|
-
npm install
|
|
16
|
+
npm install axios@^1 bignumber.js@^9 @bitcoinerlab/secp256k1@1.2.0 bitcoinjs-lib@6.1.5 @layerzerolabs/lz-v2-utilities@3.0.17
|
|
17
17
|
```
|
|
18
18
|
|
|
19
|
-
> **Note:**
|
|
19
|
+
> **Note:** `viem` is included as a direct dependency and does not need to be installed separately.
|
|
20
20
|
|
|
21
21
|
## Quick Start
|
|
22
22
|
|
|
@@ -65,29 +65,6 @@ const sdk = await createLombardSDK({
|
|
|
65
65
|
});
|
|
66
66
|
```
|
|
67
67
|
|
|
68
|
-
### Subpath Imports (Optimized Bundle Size)
|
|
69
|
-
|
|
70
|
-
For applications where bundle size is critical, use subpath imports to only include what you need:
|
|
71
|
-
|
|
72
|
-
```typescript
|
|
73
|
-
// Import only BTC staking functionality
|
|
74
|
-
import { BtcStake, BtcActions } from '@lombard.finance/sdk/btc';
|
|
75
|
-
|
|
76
|
-
// Import only EVM functionality
|
|
77
|
-
import { EvmActions } from '@lombard.finance/sdk/evm';
|
|
78
|
-
|
|
79
|
-
// Import only utilities (smallest bundle)
|
|
80
|
-
import { toSatoshi, fromSatoshi, ChainId } from '@lombard.finance/sdk/utils';
|
|
81
|
-
|
|
82
|
-
// Import only API functions
|
|
83
|
-
import { getDepositsByAddress } from '@lombard.finance/sdk/api';
|
|
84
|
-
|
|
85
|
-
// Import only contract functions
|
|
86
|
-
import { unstakeLBTC, claimLBTC } from '@lombard.finance/sdk/contracts';
|
|
87
|
-
```
|
|
88
|
-
|
|
89
|
-
Available subpaths: `/core`, `/api`, `/contracts`, `/btc`, `/evm`, `/metrics`, `/utils`, `/vaults`, `/defi`, `/bridge`, `/debug`
|
|
90
|
-
|
|
91
68
|
## Architecture
|
|
92
69
|
|
|
93
70
|
The SDK uses an **action-based architecture** where each operation (stake, unstake, deploy, etc.) is represented as an action object with a consistent lifecycle:
|
|
@@ -115,14 +92,12 @@ create → prepare → execute → complete
|
|
|
115
92
|
Query deposits, unstakes, points, and exchange rates:
|
|
116
93
|
|
|
117
94
|
```typescript
|
|
118
|
-
const deposits = await sdk.api.
|
|
119
|
-
const unstakes = await sdk.api.
|
|
120
|
-
const points = await sdk.api.
|
|
121
|
-
const
|
|
95
|
+
const deposits = await sdk.api.getDeposits({ address });
|
|
96
|
+
const unstakes = await sdk.api.getUnstakes({ address });
|
|
97
|
+
const points = await sdk.api.getPoints({ address });
|
|
98
|
+
const rate = await sdk.api.getExchangeRate();
|
|
122
99
|
```
|
|
123
100
|
|
|
124
|
-
> **Note (v4.0+):** These convenience methods are wrappers around `getDepositsByAddress()`, `getUnstakesByAddress()`, `getPointsByAddress()`, and `getExchangeRatio()`. Both APIs are supported.
|
|
125
|
-
|
|
126
101
|
## Playground
|
|
127
102
|
|
|
128
103
|
Try the SDK interactively at **[lombard.finance/playground](https://lombard.finance/playground)**.
|
|
@@ -135,11 +110,10 @@ The playground provides:
|
|
|
135
110
|
|
|
136
111
|
## Documentation
|
|
137
112
|
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
- [
|
|
141
|
-
- [
|
|
142
|
-
- [User Guides](https://docs.lombard.finance/build/the-lombard-sdk/user-guides)
|
|
113
|
+
- [Getting Started](./docs/user-guides/QS-01-GETTING-STARTED.md)
|
|
114
|
+
- [Action Lifecycle](./docs/user-guides/DG-01-ACTION-LIFECYCLE.md)
|
|
115
|
+
- [Migration from v3.x](./docs/user-guides/MIGRATION-V4.md)
|
|
116
|
+
- [Full Documentation Index](./docs/user-guides/INDEX.md)
|
|
143
117
|
|
|
144
118
|
## Non-EVM Chains
|
|
145
119
|
|
|
@@ -178,29 +152,6 @@ const sdk = await createLombardSDK({
|
|
|
178
152
|
- **Node.js**: 18+ (ESM support required)
|
|
179
153
|
- **Browser**: Modern browsers with ES2020 support
|
|
180
154
|
|
|
181
|
-
## Security Notes
|
|
182
|
-
|
|
183
|
-
### Transitive `elliptic` Dependency
|
|
184
|
-
|
|
185
|
-
The `@layerzerolabs/lz-v2-utilities` peer dependency has a transitive dependency on `elliptic`, which has a known vulnerability ([CVE-2025-14505](https://github.com/advisories/GHSA-848j-6mx2-7j84)).
|
|
186
|
-
|
|
187
|
-
**This does NOT affect SDK functionality.** The SDK uses `@layerzerolabs/lz-v2-utilities` only for building LayerZero message options (byte arrays), not for any cryptographic signature operations. The vulnerable ECDSA code path is never executed.
|
|
188
|
-
|
|
189
|
-
If your security policy requires eliminating this dependency:
|
|
190
|
-
- Avoid using the legacy `bridgeOFT` function (deprecated in favor of `bridgeCCIP`)
|
|
191
|
-
- The vulnerability will be resolved when LayerZero updates their dependencies
|
|
192
|
-
|
|
193
|
-
### Bridge Functions
|
|
194
|
-
|
|
195
|
-
The SDK provides two bridging mechanisms:
|
|
196
|
-
|
|
197
|
-
| Function | Description | Status |
|
|
198
|
-
|----------|-------------|--------|
|
|
199
|
-
| `bridgeCCIP()` | Chainlink CCIP-based cross-chain bridge | **Recommended** |
|
|
200
|
-
| `bridgeOFT()` | LayerZero OFT-based cross-chain bridge | Legacy (deprecated) |
|
|
201
|
-
|
|
202
|
-
**Use `bridgeCCIP()`** for all new integrations. It provides better security guarantees and doesn't depend on the `elliptic` library. See [`src/bridge/`](./src/bridge/) for implementation details.
|
|
203
|
-
|
|
204
155
|
## Environment
|
|
205
156
|
|
|
206
157
|
| Environment | Description | Use For |
|
package/dist/api.cjs
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const e=require("./chunks/ReferralsClient-
|
|
1
|
+
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const e=require("./chunks/ReferralsClient-BC-1wT1q.cjs"),s=require("./chunks/getUserStakeAndBakeSignature-BxRq2cI1.cjs"),r=require("./chunks/get-exchange-ratio-C-7DadfD.cjs"),t=require("./chunks/depositStatus-C3-EgT2a.cjs"),i=require("./chunks/storeNetworkFeeSignature-D7yo6lDV.cjs");exports.ENotarizationStatus=e.ENotarizationStatus;exports.ESessionState=e.ESessionState;exports.PayoutTxStatus=e.PayoutTxStatus;exports.ReferralsClient=e.ReferralsClient;exports.fetchBTCbDeposits=e.fetchBTCbDeposits;exports.fetchDirectDeposits=e.fetchDirectDeposits;exports.fetchUnstakesByAddress=e.fetchUnstakesByAddress;exports.getDepositBtcAddress=e.getDepositBtcAddress;exports.getDepositBtcAddresses=e.getDepositBtcAddresses;exports.getDepositsByAddress=e.getDepositsByAddress;exports.getLuxSeason1Points=e.getLuxSeason1Points;exports.getLuxSeason2Points=e.getLuxSeason2Points;exports.getPointsByAddress=e.getPointsByAddress;exports.getUnstakesByAddress=e.getUnstakesByAddress;exports.storeStakeAndBakeSignature=e.storeStakeAndBakeSignature;exports.SANCTIONED_ADDRESS=s.SANCTIONED_ADDRESS;exports.generateDepositBtcAddress=s.generateDepositBtcAddress;exports.getUserStakeAndBakeSignature=s.getUserStakeAndBakeSignature;exports.getExchangeRatio=r.getExchangeRatio;exports.MIN_CLAIM_AMOUNT_BTC=t.MIN_CLAIM_AMOUNT_BTC;exports.REQUIRED_CONFIRMATIONS=t.REQUIRED_CONFIRMATIONS;exports.calcConfirmations=t.calcConfirmations;exports.depositRequiresAction=t.depositRequiresAction;exports.getConfirmationProgress=t.getConfirmationProgress;exports.getDepositStatus=t.getDepositStatus;exports.getDepositStatusDisplay=t.getDepositStatusDisplay;exports.getLBTCExchangeRate=t.getLBTCExchangeRate;exports.isDepositClaimable=t.isDepositClaimable;exports.isDepositPending=t.isDepositPending;exports.isDepositTerminal=t.isDepositTerminal;exports.setReferral=t.setReferral;exports.getNetworkFeeSignature=i.getNetworkFeeSignature;exports.storeNetworkFeeSignature=i.storeNetworkFeeSignature;
|
|
2
2
|
//# sourceMappingURL=api.cjs.map
|
package/dist/api.js
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
|
-
import { E as t,
|
|
2
|
-
import { S as R, g as x, a as C } from "./chunks/getUserStakeAndBakeSignature-
|
|
3
|
-
import { g as m } from "./chunks/get-exchange-ratio-
|
|
4
|
-
import { M as N, R as l, c as T, d as h, g as P, a as y, b as I,
|
|
5
|
-
import { g as F, s as w } from "./chunks/storeNetworkFeeSignature-
|
|
1
|
+
import { E as t, a, P as o, R as i, f as r, b as g, c as n, g as d, d as S, e as p, h as D, i as A, j as c, k as f, s as u } from "./chunks/ReferralsClient-DbFWWtVi.js";
|
|
2
|
+
import { S as R, g as x, a as C } from "./chunks/getUserStakeAndBakeSignature-NGGblnJl.js";
|
|
3
|
+
import { g as m } from "./chunks/get-exchange-ratio-NtnkG1kZ.js";
|
|
4
|
+
import { M as N, R as l, c as T, d as h, g as P, a as y, b as I, e as M, i as U, f as _, h as b, s as L } from "./chunks/depositStatus-DM7fRmbN.js";
|
|
5
|
+
import { g as F, s as w } from "./chunks/storeNetworkFeeSignature-BZGL2Zn_.js";
|
|
6
6
|
export {
|
|
7
7
|
t as ENotarizationStatus,
|
|
8
8
|
a as ESessionState,
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"ccip-config.d.ts","sourceRoot":"","sources":["../../../src/bridge/lib/ccip-config.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,EAAE,MAAM,MAAM,CAAC;AAE/B,OAAO,EAAE,OAAO,EAAE,MAAM,qBAAqB,CAAC;AAE9C,MAAM,MAAM,eAAe,GAAG;IAC5B,aAAa,EAAE,OAAO,CAAC;IACvB,aAAa,EAAE,MAAM,CAAC;CACvB,CAAC;AAEF,KAAK,UAAU,GAAG,MAAM,CAAC,MAAM,EAAE,eAAe,CAAC,CAAC;AAElD,eAAO,MAAM,WAAW,EAAE,
|
|
1
|
+
{"version":3,"file":"ccip-config.d.ts","sourceRoot":"","sources":["../../../src/bridge/lib/ccip-config.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,EAAE,MAAM,MAAM,CAAC;AAE/B,OAAO,EAAE,OAAO,EAAE,MAAM,qBAAqB,CAAC;AAE9C,MAAM,MAAM,eAAe,GAAG;IAC5B,aAAa,EAAE,OAAO,CAAC;IACvB,aAAa,EAAE,MAAM,CAAC;CACvB,CAAC;AAEF,KAAK,UAAU,GAAG,MAAM,CAAC,MAAM,EAAE,eAAe,CAAC,CAAC;AAElD,eAAO,MAAM,WAAW,EAAE,UAsDzB,CAAC;AAEF,wBAAgB,aAAa,CAAC,OAAO,EAAE,OAAO,GAAG,eAAe,GAAG,SAAS,CAE3E"}
|
|
@@ -11,10 +11,10 @@ export declare const BRIDGE_EXPLORER_URL_MAP: {
|
|
|
11
11
|
CCIP: string;
|
|
12
12
|
OFT: string;
|
|
13
13
|
};
|
|
14
|
-
export declare const CCIP_BRIDGE_CHAINS: (1 | 8453 | 84532 | 56 | 43114 | 43113 | 747474 |
|
|
14
|
+
export declare const CCIP_BRIDGE_CHAINS: (1 | 8453 | 84532 | 56 | 43114 | 43113 | 747474 | 146 | 11155111 | 17000 | 143 | 988)[];
|
|
15
15
|
export type CCIPBridgeChain = (typeof CCIP_BRIDGE_CHAINS)[number];
|
|
16
16
|
export declare const OFT_BRIDGE_CHAINS: (1 | 80094 | 80084 | 21000000 | 42793 | 1923 | 239 | 11155111)[];
|
|
17
|
-
export declare const BRIDGE_CHAINS: (1 | 8453 | 84532 | 56 | 43114 | 43113 | 80094 | 80084 | 21000000 | 42793 | 747474 |
|
|
17
|
+
export declare const BRIDGE_CHAINS: (1 | 8453 | 84532 | 56 | 43114 | 43113 | 80094 | 80084 | 21000000 | 42793 | 747474 | 146 | 1923 | 239 | 11155111 | 17000 | 143 | 988)[];
|
|
18
18
|
export type BridgeChain = CCIPBridgeChain | OFTBridgeChain;
|
|
19
19
|
export declare const OFT_GAS_LIMIT = 90000;
|
|
20
20
|
export declare const OFT_HI_GAS_LIMIT = 200000;
|
|
@@ -24,7 +24,7 @@ type BridgeInfo = {
|
|
|
24
24
|
type: BridgeType;
|
|
25
25
|
contract: ContractInfo;
|
|
26
26
|
};
|
|
27
|
-
export declare const BRIDGES: Map<"[from:1, to: 1]" | "[from:1, to: 8453]" | "[from:1, to: 84532]" | "[from:1, to: 56]" | "[from:1, to: 43114]" | "[from:1, to: 43113]" | "[from:1, to: 747474]" | "[from:1, to:
|
|
27
|
+
export declare const BRIDGES: Map<"[from:1, to: 1]" | "[from:1, to: 8453]" | "[from:1, to: 84532]" | "[from:1, to: 56]" | "[from:1, to: 43114]" | "[from:1, to: 43113]" | "[from:1, to: 747474]" | "[from:1, to: 146]" | "[from:1, to: 11155111]" | "[from:1, to: 17000]" | "[from:1, to: 143]" | "[from:1, to: 988]" | "[from:8453, to: 1]" | "[from:8453, to: 8453]" | "[from:8453, to: 84532]" | "[from:8453, to: 56]" | "[from:8453, to: 43114]" | "[from:8453, to: 43113]" | "[from:8453, to: 747474]" | "[from:8453, to: 146]" | "[from:8453, to: 11155111]" | "[from:8453, to: 17000]" | "[from:8453, to: 143]" | "[from:8453, to: 988]" | "[from:84532, to: 1]" | "[from:84532, to: 8453]" | "[from:84532, to: 84532]" | "[from:84532, to: 56]" | "[from:84532, to: 43114]" | "[from:84532, to: 43113]" | "[from:84532, to: 747474]" | "[from:84532, to: 146]" | "[from:84532, to: 11155111]" | "[from:84532, to: 17000]" | "[from:84532, to: 143]" | "[from:84532, to: 988]" | "[from:56, to: 1]" | "[from:56, to: 8453]" | "[from:56, to: 84532]" | "[from:56, to: 56]" | "[from:56, to: 43114]" | "[from:56, to: 43113]" | "[from:56, to: 747474]" | "[from:56, to: 146]" | "[from:56, to: 11155111]" | "[from:56, to: 17000]" | "[from:56, to: 143]" | "[from:56, to: 988]" | "[from:43114, to: 1]" | "[from:43114, to: 8453]" | "[from:43114, to: 84532]" | "[from:43114, to: 56]" | "[from:43114, to: 43114]" | "[from:43114, to: 43113]" | "[from:43114, to: 747474]" | "[from:43114, to: 146]" | "[from:43114, to: 11155111]" | "[from:43114, to: 17000]" | "[from:43114, to: 143]" | "[from:43114, to: 988]" | "[from:43113, to: 1]" | "[from:43113, to: 8453]" | "[from:43113, to: 84532]" | "[from:43113, to: 56]" | "[from:43113, to: 43114]" | "[from:43113, to: 43113]" | "[from:43113, to: 747474]" | "[from:43113, to: 146]" | "[from:43113, to: 11155111]" | "[from:43113, to: 17000]" | "[from:43113, to: 143]" | "[from:43113, to: 988]" | "[from:747474, to: 1]" | "[from:747474, to: 8453]" | "[from:747474, to: 84532]" | "[from:747474, to: 56]" | "[from:747474, to: 43114]" | "[from:747474, to: 43113]" | "[from:747474, to: 747474]" | "[from:747474, to: 146]" | "[from:747474, to: 11155111]" | "[from:747474, to: 17000]" | "[from:747474, to: 143]" | "[from:747474, to: 988]" | "[from:146, to: 1]" | "[from:146, to: 8453]" | "[from:146, to: 84532]" | "[from:146, to: 56]" | "[from:146, to: 43114]" | "[from:146, to: 43113]" | "[from:146, to: 747474]" | "[from:146, to: 146]" | "[from:146, to: 11155111]" | "[from:146, to: 17000]" | "[from:146, to: 143]" | "[from:146, to: 988]" | "[from:11155111, to: 1]" | "[from:11155111, to: 8453]" | "[from:11155111, to: 84532]" | "[from:11155111, to: 56]" | "[from:11155111, to: 43114]" | "[from:11155111, to: 43113]" | "[from:11155111, to: 747474]" | "[from:11155111, to: 146]" | "[from:11155111, to: 11155111]" | "[from:11155111, to: 17000]" | "[from:11155111, to: 143]" | "[from:11155111, to: 988]" | "[from:17000, to: 1]" | "[from:17000, to: 8453]" | "[from:17000, to: 84532]" | "[from:17000, to: 56]" | "[from:17000, to: 43114]" | "[from:17000, to: 43113]" | "[from:17000, to: 747474]" | "[from:17000, to: 146]" | "[from:17000, to: 11155111]" | "[from:17000, to: 17000]" | "[from:17000, to: 143]" | "[from:17000, to: 988]" | "[from:143, to: 1]" | "[from:143, to: 8453]" | "[from:143, to: 84532]" | "[from:143, to: 56]" | "[from:143, to: 43114]" | "[from:143, to: 43113]" | "[from:143, to: 747474]" | "[from:143, to: 146]" | "[from:143, to: 11155111]" | "[from:143, to: 17000]" | "[from:143, to: 143]" | "[from:143, to: 988]" | "[from:988, to: 1]" | "[from:988, to: 8453]" | "[from:988, to: 84532]" | "[from:988, to: 56]" | "[from:988, to: 43114]" | "[from:988, to: 43113]" | "[from:988, to: 747474]" | "[from:988, to: 146]" | "[from:988, to: 11155111]" | "[from:988, to: 17000]" | "[from:988, to: 143]" | "[from:988, to: 988]" | "[from:1, to: 80094]" | "[from:1, to: 80084]" | "[from:1, to: 21000000]" | "[from:1, to: 42793]" | "[from:1, to: 1923]" | "[from:1, to: 239]" | "[from:80094, to: 1]" | "[from:80094, to: 80094]" | "[from:80094, to: 80084]" | "[from:80094, to: 21000000]" | "[from:80094, to: 42793]" | "[from:80094, to: 1923]" | "[from:80094, to: 239]" | "[from:80094, to: 11155111]" | "[from:80084, to: 1]" | "[from:80084, to: 80094]" | "[from:80084, to: 80084]" | "[from:80084, to: 21000000]" | "[from:80084, to: 42793]" | "[from:80084, to: 1923]" | "[from:80084, to: 239]" | "[from:80084, to: 11155111]" | "[from:21000000, to: 1]" | "[from:21000000, to: 80094]" | "[from:21000000, to: 80084]" | "[from:21000000, to: 21000000]" | "[from:21000000, to: 42793]" | "[from:21000000, to: 1923]" | "[from:21000000, to: 239]" | "[from:21000000, to: 11155111]" | "[from:42793, to: 1]" | "[from:42793, to: 80094]" | "[from:42793, to: 80084]" | "[from:42793, to: 21000000]" | "[from:42793, to: 42793]" | "[from:42793, to: 1923]" | "[from:42793, to: 239]" | "[from:42793, to: 11155111]" | "[from:1923, to: 1]" | "[from:1923, to: 80094]" | "[from:1923, to: 80084]" | "[from:1923, to: 21000000]" | "[from:1923, to: 42793]" | "[from:1923, to: 1923]" | "[from:1923, to: 239]" | "[from:1923, to: 11155111]" | "[from:239, to: 1]" | "[from:239, to: 80094]" | "[from:239, to: 80084]" | "[from:239, to: 21000000]" | "[from:239, to: 42793]" | "[from:239, to: 1923]" | "[from:239, to: 239]" | "[from:239, to: 11155111]" | "[from:11155111, to: 80094]" | "[from:11155111, to: 80084]" | "[from:11155111, to: 21000000]" | "[from:11155111, to: 42793]" | "[from:11155111, to: 1923]" | "[from:11155111, to: 239]" | "[from:8453, to: 80094]" | "[from:8453, to: 80084]" | "[from:8453, to: 21000000]" | "[from:8453, to: 42793]" | "[from:8453, to: 1923]" | "[from:8453, to: 239]" | "[from:84532, to: 80094]" | "[from:84532, to: 80084]" | "[from:84532, to: 21000000]" | "[from:84532, to: 42793]" | "[from:84532, to: 1923]" | "[from:84532, to: 239]" | "[from:56, to: 80094]" | "[from:56, to: 80084]" | "[from:56, to: 21000000]" | "[from:56, to: 42793]" | "[from:56, to: 1923]" | "[from:56, to: 239]" | "[from:43114, to: 80094]" | "[from:43114, to: 80084]" | "[from:43114, to: 21000000]" | "[from:43114, to: 42793]" | "[from:43114, to: 1923]" | "[from:43114, to: 239]" | "[from:43113, to: 80094]" | "[from:43113, to: 80084]" | "[from:43113, to: 21000000]" | "[from:43113, to: 42793]" | "[from:43113, to: 1923]" | "[from:43113, to: 239]" | "[from:80094, to: 8453]" | "[from:80094, to: 84532]" | "[from:80094, to: 56]" | "[from:80094, to: 43114]" | "[from:80094, to: 43113]" | "[from:80094, to: 747474]" | "[from:80094, to: 146]" | "[from:80094, to: 17000]" | "[from:80094, to: 143]" | "[from:80094, to: 988]" | "[from:80084, to: 8453]" | "[from:80084, to: 84532]" | "[from:80084, to: 56]" | "[from:80084, to: 43114]" | "[from:80084, to: 43113]" | "[from:80084, to: 747474]" | "[from:80084, to: 146]" | "[from:80084, to: 17000]" | "[from:80084, to: 143]" | "[from:80084, to: 988]" | "[from:21000000, to: 8453]" | "[from:21000000, to: 84532]" | "[from:21000000, to: 56]" | "[from:21000000, to: 43114]" | "[from:21000000, to: 43113]" | "[from:21000000, to: 747474]" | "[from:21000000, to: 146]" | "[from:21000000, to: 17000]" | "[from:21000000, to: 143]" | "[from:21000000, to: 988]" | "[from:42793, to: 8453]" | "[from:42793, to: 84532]" | "[from:42793, to: 56]" | "[from:42793, to: 43114]" | "[from:42793, to: 43113]" | "[from:42793, to: 747474]" | "[from:42793, to: 146]" | "[from:42793, to: 17000]" | "[from:42793, to: 143]" | "[from:42793, to: 988]" | "[from:747474, to: 80094]" | "[from:747474, to: 80084]" | "[from:747474, to: 21000000]" | "[from:747474, to: 42793]" | "[from:747474, to: 1923]" | "[from:747474, to: 239]" | "[from:146, to: 80094]" | "[from:146, to: 80084]" | "[from:146, to: 21000000]" | "[from:146, to: 42793]" | "[from:146, to: 1923]" | "[from:146, to: 239]" | "[from:1923, to: 8453]" | "[from:1923, to: 84532]" | "[from:1923, to: 56]" | "[from:1923, to: 43114]" | "[from:1923, to: 43113]" | "[from:1923, to: 747474]" | "[from:1923, to: 146]" | "[from:1923, to: 17000]" | "[from:1923, to: 143]" | "[from:1923, to: 988]" | "[from:239, to: 8453]" | "[from:239, to: 84532]" | "[from:239, to: 56]" | "[from:239, to: 43114]" | "[from:239, to: 43113]" | "[from:239, to: 747474]" | "[from:239, to: 146]" | "[from:239, to: 17000]" | "[from:239, to: 143]" | "[from:239, to: 988]" | "[from:17000, to: 80094]" | "[from:17000, to: 80084]" | "[from:17000, to: 21000000]" | "[from:17000, to: 42793]" | "[from:17000, to: 1923]" | "[from:17000, to: 239]" | "[from:143, to: 80094]" | "[from:143, to: 80084]" | "[from:143, to: 21000000]" | "[from:143, to: 42793]" | "[from:143, to: 1923]" | "[from:143, to: 239]" | "[from:988, to: 80094]" | "[from:988, to: 80084]" | "[from:988, to: 21000000]" | "[from:988, to: 42793]" | "[from:988, to: 1923]" | "[from:988, to: 239]", BridgeInfo>;
|
|
28
28
|
/** Gets the bridge information */
|
|
29
29
|
export declare const getBridgeInfo: (from: BridgeChain, to: BridgeChain) => BridgeInfo | undefined;
|
|
30
30
|
export {};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"config.d.ts","sourceRoot":"","sources":["../../../src/bridge/lib/config.ts"],"names":[],"mappings":"AAAA,OAAO,SAAS,MAAM,cAAc,CAAC;AAIrC,OAAO,EAAE,YAAY,EAAE,MAAM,4BAA4B,CAAC;AAM1D,eAAO,MAAM,iBAAiB,WAAsB,CAAC;AAErD,oBAAY,UAAU;IACpB,+DAA+D;IAC/D,IAAI,SAAS;IAEb,iDAAiD;IACjD,GAAG,QAAQ;CACZ;AAED,eAAO,MAAM,uBAAuB;;;CAGnC,CAAC;AAEF,eAAO,MAAM,kBAAkB,
|
|
1
|
+
{"version":3,"file":"config.d.ts","sourceRoot":"","sources":["../../../src/bridge/lib/config.ts"],"names":[],"mappings":"AAAA,OAAO,SAAS,MAAM,cAAc,CAAC;AAIrC,OAAO,EAAE,YAAY,EAAE,MAAM,4BAA4B,CAAC;AAM1D,eAAO,MAAM,iBAAiB,WAAsB,CAAC;AAErD,oBAAY,UAAU;IACpB,+DAA+D;IAC/D,IAAI,SAAS;IAEb,iDAAiD;IACjD,GAAG,QAAQ;CACZ;AAED,eAAO,MAAM,uBAAuB;;;CAGnC,CAAC;AAEF,eAAO,MAAM,kBAAkB,yFAe9B,CAAC;AACF,MAAM,MAAM,eAAe,GAAG,CAAC,OAAO,kBAAkB,CAAC,CAAC,MAAM,CAAC,CAAC;AAElE,eAAO,MAAM,iBAAiB,kEAW7B,CAAC;AAEF,eAAO,MAAM,aAAa,yIAGxB,CAAC;AACH,MAAM,MAAM,WAAW,GAAG,eAAe,GAAG,cAAc,CAAC;AAE3D,eAAO,MAAM,aAAa,QAAS,CAAC;AACpC,eAAO,MAAM,gBAAgB,SAAU,CAAC;AACxC,eAAO,MAAM,uBAAuB,gEAWnC,CAAC;AAEF,MAAM,MAAM,cAAc,GAAG,CAAC,OAAO,iBAAiB,CAAC,CAAC,MAAM,CAAC,CAAC;AAUhE,KAAK,UAAU,GAAG;IAAE,IAAI,EAAE,UAAU,CAAC;IAAC,QAAQ,EAAE,YAAY,CAAA;CAAE,CAAC;AA4Q/D,eAAO,MAAM,OAAO,whRAGlB,CAAC;AAEH,kCAAkC;AAClC,eAAO,MAAM,aAAa,GAAI,MAAM,WAAW,EAAE,IAAI,WAAW,2BAE/D,CAAC"}
|
package/dist/bridge.cjs
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const I=require("./chunks/bridge-
|
|
1
|
+
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const I=require("./chunks/bridge-BzRlY9pP.cjs");exports.OFT_GAS_LIMIT=I.OFT_GAS_LIMIT;exports.OFT_HI_GAS_LIMIT=I.OFT_HI_GAS_LIMIT;exports.OFT_HI_GAS_LIMIT_CHAINS=I.OFT_HI_GAS_LIMIT_CHAINS;exports.bridge=I.bridge;exports.bridgeCCIP=I.bridgeCCIP;exports.bridgeOFT=I.bridgeOFT;exports.getBridgeInfo=I.getBridgeInfo;
|
|
2
2
|
//# sourceMappingURL=bridge.cjs.map
|
package/dist/bridge.js
CHANGED
package/dist/btc.cjs
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const t=require("./chunks/BtcActions-
|
|
1
|
+
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const t=require("./chunks/BtcActions-ByhBml_1.cjs"),c=require("./chunks/statusConstants-fmtIEEEM.cjs");exports.BtcActions=t.BtcActions;exports.BtcDeposit=t.BtcDeposit;exports.BtcDepositAndDeploy=t.BtcDepositAndDeploy;exports.BtcStake=t.BtcStake;exports.BtcStakeAndDeploy=t.BtcStakeAndDeploy;exports.btcActions=t.btcActions;exports.btcModule=t.btcModule;exports.BtcActionStatus=c.BtcActionStatus;
|
|
2
2
|
//# sourceMappingURL=btc.cjs.map
|
package/dist/btc.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { B as a, c,
|
|
2
|
-
import { B as A } from "./chunks/statusConstants-
|
|
1
|
+
import { B as a, a as c, b as o, c as e, d as B, e as p, f as i } from "./chunks/BtcActions-C_A1dUQ0.js";
|
|
2
|
+
import { B as A } from "./chunks/statusConstants-CJk6vOiM.js";
|
|
3
3
|
export {
|
|
4
4
|
A as BtcActionStatus,
|
|
5
5
|
a as BtcActions,
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
"use strict";var z=Object.defineProperty;var H=(s,r,i)=>r in s?z(s,r,{enumerable:!0,configurable:!0,writable:!0,value:i}):s[r]=i;var A=(s,r,i)=>H(s,typeof r!="symbol"?r+"":r,i);const Y=require("axios"),p=require("./token-addresses-D859i6tX.cjs"),t=require("./statusConstants-DTDi_4Go.cjs"),u=require("./index-BKzxeh1Y.cjs"),f=require("./tokens-DLGMNeqZ.cjs"),l=require("./satoshi-CZEsHl5X.cjs"),h=require("./defi-registry-NGWlyxAY.cjs"),R=require("./getUserStakeAndBakeSignature--XsK93Lb.cjs"),q=require("./config-DqbLaiRi.cjs"),$=require("viem"),U="ERR_NETWORK",G="This may be due to your Adblocker. Please disable any Adblocker and refresh the page to restore full functionality.";function K(s){const{code:r,message:i}=s;throw r===U?new Error(G):new Error(i)}const j={mempoolApiUrl:"https://mempool.space/signet"},Z={mempoolApiUrl:"https://mempool.space"},W=s=>s==="mainnet"?Z:j;async function X(s){const{mempoolApiUrl:r}=W(s),i=Math.floor(Date.now()/1e3),e=`${r}/api/v1/mining/blocks/timestamp/${i}`;try{const{data:n}=await Y.get(e);return n.height}catch(n){K(n)}}class J{async getCurrentBlockHeight(r){return X(r)}}function Q(){return{id:"btc",chain:"btc",register(){return new J}}}async function y(s){const{fetchDeposit:r,network:i,btcService:e,requiredConfirmations:n=6,onProgress:a,onComplete:o}=s,c=await r();if(!c)return;const d=c.blockHeight;if(typeof d!="number")return;const V=await e.getCurrentBlockHeight(i),_=Math.max(0,V-d),B=_>=n,T=c.isClaimed??!1,N={confirmations:_,requiredConfirmations:n,hasEnoughConfirmations:B,isClaimed:T,steps:{created:t.StepStatus.COMPLETE,verifying:B?t.StepStatus.COMPLETE:t.StepStatus.PENDING,issuing:T?t.StepStatus.COMPLETE:t.StepStatus.PENDING}};return a==null||a(N),T&&(o==null||o()),N}function I(s){if(s===R.SANCTIONED_ADDRESS)throw new t.LombardError(t.ValidationErrorCode.INVALID_PARAMETER,"Destination address is under sanctions")}class m extends t.BaseAction{constructor(i,e,n){super(n);A(this,"_amount");A(this,"_recipient");A(this,"_depositAddress");A(this,"_referralCode");A(this,"_chainId");this.ctx=i,this.params=e}get amount(){return this._amount}get recipient(){return this._recipient}get depositAddress(){return this._depositAddress}get referralCode(){return this._referralCode}get bitcoinNetwork(){return this.params.sourceChain===t.Chain.BITCOIN_MAINNET?"mainnet":"testnet"}get prepareSchema(){return t.objectType({amount:t.btcStakeAmountSchema,recipient:this.getAddressSchema(),referralCode:t.referralCodeSchema})}validatePrepareParams(i){return t.validatePrepareParams(this.prepareSchema,i,{destChain:this.params.destChain})}ensureRecipient(){if(!this._recipient)throw t.LombardError.missingParameter("recipient");return this._recipient}ensureAmount(){if(!this._amount)throw t.LombardError.missingParameter("amount");return this._amount}ensureDepositAddress(){if(!this._depositAddress)throw new t.LombardError(t.ValidationErrorCode.INVALID_PARAMETER,"Deposit address not generated. Call generateDepositAddress() first.");return this._depositAddress}getAuthRequiredMessage(){return"Authorization required. Complete the authorization step first."}ensureAuthorized(){if(!this.isAuthorized())throw new t.LombardError(t.ValidationErrorCode.INVALID_PARAMETER,this.getAuthRequiredMessage())}async resumeFromExistingDeposit(i){try{const e=await this.ctx.api.getDepositAddress({address:i,chainId:this.getChainId(),token:this.getExpectedToken(),partnerId:this.ctx.partner.getPartnerId()});return e?(this._depositAddress=e,!0):!1}catch{return!1}}async generateDepositAddressImpl(){const i=this.getStatusConfig();return this.assertStatus(i.ready,"generateDepositAddress"),this.ensureAuthorized(),this._depositAddress?this._depositAddress:this.act(async()=>{const e=this.getDepositAddressParams(),n=await this.ctx.api.generateDepositAddress(e);I(n),this._depositAddress=n;const a=this.getInitialSteps(),o=Object.fromEntries(Object.entries(a).map(([c],d)=>[c,d===0?t.StepStatus.COMPLETE:t.StepStatus.IDLE]));return this.emitProgress({status:i.addressReady,steps:o,metadata:{depositAddress:n}}),n},i.addressReady)}async executeImpl(){const i=this.getStatusConfig();return this.act(async()=>{this.assertStatus(i.addressReady,"execute"),this._depositAddress||await this.generateDepositAddressImpl();const e=this.ensureDepositAddress(),n=await this.trySendBitcoin(e);return n?{depositAddress:e,txHash:n}:{depositAddress:e}})}emitInitialProgress(){this.emitProgress({status:this.status,steps:this.getInitialSteps()})}async monitorDeposit(){const i=this._depositAddress,e=this._recipient;if(!i||!e)throw t.LombardError.missingParameter("depositAddress or recipient");return await y({network:this.bitcoinNetwork,btcService:this.ctx.btc,fetchDeposit:async()=>{const o=(await this.ctx.api.getDeposits(e)).find(c=>c.depositAddress===i);if(o)return{blockHeight:o.blockHeight,isClaimed:o.isClaimed}},onProgress:a=>{this.emitProgress({status:this.status,steps:a.steps,confirmations:a.confirmations,requiredConfirmations:a.requiredConfirmations,metadata:{isClaimed:a.isClaimed}})},onComplete:()=>{this.emitCompleted()}})}async trySendBitcoin(i){const e=this._amount;if(e)try{const n=await this.ctx.getProvider("bitcoin");if(!n)return;const a=n;if(a.sendBitcoin){const o=l.toSatoshi(e).toNumber();return a.sendBitcoin(i,o)}}catch{}}}function D(s,r=p.Token.LBTC){switch(s){case h.AssetId.LBTC:return p.Token.LBTC;case h.AssetId.BTCb:return p.Token.BTCb;default:return r}}async function tt(s,r){try{await s.request({method:"wallet_switchEthereumChain",params:[{chainId:`0x${r.toString(16)}`}]})}catch(i){const e=i;if(e.code===4902)try{await p.addChain({provider:s,chainId:r}),await s.request({method:"wallet_switchEthereumChain",params:[{chainId:`0x${r.toString(16)}`}]});return}catch(n){const a=n;throw a.code===4001?new t.LombardError(t.ValidationErrorCode.INVALID_PARAMETER,"User rejected adding chain to wallet."):new t.LombardError(t.ValidationErrorCode.INVALID_CHAIN,`Failed to add chain ${r} to wallet: ${a.message||"Unknown error"}`)}throw e.code===4001?new t.LombardError(t.ValidationErrorCode.INVALID_PARAMETER,"User rejected chain switch request."):new t.LombardError(t.ValidationErrorCode.INVALID_CHAIN,`Failed to switch to chain ${r}: ${e.message||"Unknown error"}`)}}async function et(s){const r=await s.request({method:"eth_chainId"});return parseInt(r,16)}async function E(s,r){await et(s)!==r&&await tt(s,r)}const st=[t.Chain.ETHEREUM,t.Chain.SEPOLIA],it={async getMintingFee(s,r){return s.capabilities.require("evm").getMintingFee(r,p.Token.BTCb)},async restoreFeeSignature(s,r,i){const e=await f.getTokenContractInfo(p.Token.BTCb,r,s.env),n=await s.api.getFeeSignature({address:i,chainId:r,tokenAddress:e.address});return!n.hasSignature||n.expirationDate&&new Date(Number(n.expirationDate)*1e3)<new Date?null:{hasSignature:!0,signature:n.signature,typedData:n.typedData}},async authorizeFee(s,{chainId:r,recipient:i,fee:e}){const n=s.capabilities.require("evm"),a=await s.getProvider("evm");if(!a)throw t.LombardError.providerMissing(String(r),"evm");await E(a,r);const o=l.toSatoshi(e).toString(),c=await f.getTokenContractInfo(p.Token.BTCb,r,s.env),d=await n.signNetworkFee({fee:o,account:i,chainId:r,provider:a,token:p.Token.BTCb});return await s.api.storeFeeSignature({address:i,signature:d.signature,typedData:d.typedData,tokenAddress:c.address}),{signature:d.signature,typedData:d.typedData}}},rt={chainType:"evm",routes:[{sourceChains:[t.Chain.BITCOIN_MAINNET],envs:[u.r.prod]},{sourceChains:[t.Chain.BITCOIN_SIGNET],envs:[u.r.stage,u.r.dev,u.r.testnet,u.r.ibc]}],destChains:t.getAllAssetChains(h.AssetId.BTCb).filter(s=>t.isEvmChain(s)),supportedAssetsOut:[h.AssetId.BTCb],addressSchema:t.evmAddressSchema,getFeeAuthConfig(s){return st.includes(s)?it:null},async signDestination(s,r,i){const e=s.capabilities.require("evm"),n=await s.getProvider("evm");if(!n)throw t.LombardError.providerMissing(String(i),"evm");return await E(n,i),{signature:(await e.signLbtcDestination({address:r,chainId:i,provider:n})).signature}}},g=rt;function at(s){return g.destChains.includes(s)}function nt(s){return g.supportedAssetsOut.includes(s)}function ot(s,r){return s?g.routes.some(i=>i.sourceChains.includes(s)&&i.envs.includes(r)):!0}class b extends m{constructor(i,e){super(i,e,t.BtcActionStatus.IDLE);A(this,"chainId");A(this,"authState",{authorized:!1});A(this,"feeAuthConfig",null);if(!nt(e.assetOut))throw new t.LombardError(t.ValidationErrorCode.INVALID_ASSET,`Asset ${e.assetOut} is not supported for BTC deposits. BTC Deposit produces BTC.b. For LBTC, use BtcStake instead.`);if(!at(e.destChain))throw new t.LombardError(t.ValidationErrorCode.INVALID_CHAIN,`Destination chain ${e.destChain} is not supported for BTC deposits. BTC.b is currently available on Avalanche and Katana.`);if(!ot(e.sourceChain,i.env))throw t.LombardError.routeNotFound({assetOut:e.assetOut,sourceChain:e.sourceChain,destChain:e.destChain,env:i.env});const n=t.parseChainIdentifier(e.destChain);if(typeof n!="number"||!p.isValidChain(n))throw new t.LombardError(t.ValidationErrorCode.INVALID_CHAIN,`Unsupported EVM chain: ${e.destChain}`);this.chainId=n}getAddressSchema(){return g.addressSchema}getStatusConfig(){return{idle:t.BtcActionStatus.IDLE,ready:t.BtcActionStatus.READY,addressReady:t.BtcActionStatus.ADDRESS_READY}}getInitialSteps(){return{created:t.StepStatus.IDLE,verifying:t.StepStatus.IDLE,issuing:t.StepStatus.IDLE}}isAuthorized(){return this.authState.authorized}getChainId(){return this.chainId}get mintingFee(){return this.authState.mintingFee}getDepositAddressParams(){return{address:this.ensureRecipient(),chainId:this.chainId,signature:this.authState.signature,token:this.getExpectedToken(),eip712Data:this.authState.typedData,partnerId:this.ctx.partner.getPartnerId(),referrerCode:this._referralCode}}async generateDepositAddress(){if(!this.authState.signature){const i=await g.signDestination(this.ctx,this.ensureRecipient(),this.chainId);this.authState.signature=i.signature,this.authState.typedData=i.typedData}return this.generateDepositAddressImpl()}getExpectedToken(){return D(this.params.assetOut,p.Token.BTCb)}getAuthRequiredMessage(){return this.feeAuthConfig?"Fee authorization required. Call authorizeFee() first.":"Address confirmation required. Call confirmAddress() first."}async prepare(i){return this.assertStatus(t.BtcActionStatus.IDLE,"prepare"),this.act(async()=>{const e=this.validatePrepareParams(i);if(this._amount=e.amount,this._recipient=e.recipient,this._referralCode=e.referralCode,this.feeAuthConfig=g.getFeeAuthConfig(this.params.destChain),await this.resumeFromExistingDeposit(e.recipient)){if(this.feeAuthConfig){const a=await this.feeAuthConfig.restoreFeeSignature(this.ctx,this.chainId,e.recipient);if(!(a!=null&&a.hasSignature)){this.authState.mintingFee=await this.feeAuthConfig.getMintingFee(this.ctx,this.chainId),this.updateStatus(t.BtcActionStatus.NEEDS_FEE_AUTHORIZATION),this.emitInitialProgress();return}a.signature&&(this.authState.signature=a.signature,this.authState.typedData=a.typedData),this.authState.authorized=!0}this.updateStatus(t.BtcActionStatus.ADDRESS_READY),this.emitInitialProgress();return}if(this.feeAuthConfig){const a=await this.feeAuthConfig.restoreFeeSignature(this.ctx,this.chainId,e.recipient);if(a!=null&&a.hasSignature){a.signature&&(this.authState.signature=a.signature,this.authState.typedData=a.typedData),this.authState.authorized=!0,this.updateStatus(t.BtcActionStatus.READY),this.emitInitialProgress();return}this.authState.mintingFee=await this.feeAuthConfig.getMintingFee(this.ctx,this.chainId),this.updateStatus(t.BtcActionStatus.NEEDS_FEE_AUTHORIZATION)}else this.updateStatus(t.BtcActionStatus.NEEDS_ADDRESS_CONFIRMATION);this.emitInitialProgress()})}async authorizeFee(){if(this.assertStatus([t.BtcActionStatus.NEEDS_FEE_AUTHORIZATION,t.BtcActionStatus.READY],"authorizeFee"),this.status===t.BtcActionStatus.READY)return;if(!this.feeAuthConfig)throw new t.LombardError(t.ValidationErrorCode.INVALID_PARAMETER,"Fee authorization is not required for this destination chain. Use confirmAddress() instead.");const i=this.ensureRecipient();if(!this.authState.mintingFee)throw new t.LombardError(t.ValidationErrorCode.INVALID_STATE,"Minting fee not available. Call prepare() first.");return this.act(async()=>{const e=await this.feeAuthConfig.authorizeFee(this.ctx,{chainId:this.chainId,recipient:i,fee:this.authState.mintingFee});this.authState.signature=e.signature,this.authState.typedData=e.typedData,this.authState.authorized=!0},t.BtcActionStatus.READY)}async confirmAddress(){if(this.assertStatus([t.BtcActionStatus.NEEDS_ADDRESS_CONFIRMATION,t.BtcActionStatus.READY],"confirmAddress"),this.status===t.BtcActionStatus.READY)return;if(this.feeAuthConfig)throw new t.LombardError(t.ValidationErrorCode.INVALID_PARAMETER,"This destination chain requires fee authorization. Use authorizeFee() instead.");const i=this.ensureRecipient();return this.act(async()=>{const e=await g.signDestination(this.ctx,i,this.chainId);this.authState.signature=e.signature,this.authState.typedData=e.typedData,this.authState.authorized=!0},t.BtcActionStatus.READY)}async execute(){return this.executeImpl()}async monitorDeposit(){return super.monitorDeposit()}}const ut=q.VEDA_VAULT_STAKE_AND_BAKE_CHAINS.map(s=>t.evmChainIdToChain(s)),dt={chainType:"evm",routes:[{sourceChains:[t.Chain.BITCOIN_MAINNET],envs:[u.r.prod]},{sourceChains:[t.Chain.BITCOIN_SIGNET],envs:[u.r.stage,u.r.dev,u.r.testnet,u.r.ibc]}],destChains:ut,supportedAssetsOut:[h.AssetId.LBTC],supportedProtocols:Dt(h.AssetId.LBTC),addressSchema:t.evmAddressSchema,async getStakeAndBakeFee(s,r,i){return s.capabilities.require("evm").getStakeAndBakeFee(r,i)},async authorizeStakeAndBake(s,{chainId:r,recipient:i,amount:e,vaultKey:n,token:a}){const o=s.capabilities.require("evm"),c=await s.getProvider("evm");if(!c)throw t.LombardError.providerMissing(String(r),"evm");await E(c,r);const d=await o.signStakeAndBake({value:e,account:i,chainId:r,provider:c,vaultKey:n,token:a});return await s.api.storeStakeAndBakeSignature({signature:d.signature,typedData:d.typedData}),{signature:d.signature,typedData:d.typedData}},async restoreStakeAndBakeSignature(s,r,i){try{const e=await R.getUserStakeAndBakeSignature({userDestinationAddress:i,chainId:r,env:s.env});return!(e.signature||e.expirationDate)||e.expirationDate&&Number(e.expirationDate)*1e3<Date.now()?null:{hasSignature:!0,signature:e.signature,depositAmount:e.depositAmount,expirationDate:e.expirationDate}}catch{return null}}},S=dt;function ct(s){return S.destChains.includes(s)}function ht(s){return S.supportedAssetsOut.includes(s)}function pt(s,r){return s?S.routes.some(i=>i.sourceChains.includes(s)&&i.envs.includes(r)):!0}function k(s){return s in h.DEFI_REGISTRY}function At(s){if(!k(s)){const r=Object.keys(h.DEFI_REGISTRY).join(", ");throw new Error(`Unsupported protocol: ${s}. Supported protocols: ${r}`)}return s}function St(s){return Object.entries(h.DEFI_REGISTRY).filter(([r,i])=>s in i).map(([r])=>r)}const v={mainnet:[t.Chain.AVALANCHE],testnet:[t.Chain.AVALANCHE_FUJI]},gt={chainType:"evm",routes:[{sourceChains:[t.Chain.BITCOIN_MAINNET],envs:[u.r.prod]},{sourceChains:[t.Chain.BITCOIN_SIGNET],envs:[u.r.stage,u.r.dev,u.r.testnet,u.r.ibc]}],destChains:[...v.mainnet,...v.testnet],supportedAssetsOut:[h.AssetId.BTCb],supportedProtocols:St(h.AssetId.BTCb),addressSchema:t.evmAddressSchema,async getDepositAndDeployFee(s,r,i){return s.capabilities.require("evm").getStakeAndBakeFee(r,i)},async authorizeDepositAndDeploy(s,{chainId:r,recipient:i,amount:e,vaultKey:n,token:a}){const o=s.capabilities.require("evm"),c=await s.getProvider("evm");if(!c)throw t.LombardError.providerMissing(String(r),"evm");await E(c,r);const d=await o.signStakeAndBake({value:e,account:i,chainId:r,provider:c,vaultKey:n,token:a});return await s.api.storeStakeAndBakeSignature({signature:d.signature,typedData:d.typedData}),{signature:d.signature,typedData:d.typedData,approvalTxHash:d.approvalTxHash}}},C=gt;function Ct(s){return C.destChains.includes(s)}function Et(s){return C.supportedAssetsOut.includes(s)}function O(s){return s in h.DEFI_REGISTRY}function L(s){if(!O(s)){const r=Object.keys(h.DEFI_REGISTRY).join(", ");throw new Error(`Unsupported protocol: ${s}. Supported protocols: ${r}`)}return s}function Dt(s){return Object.entries(h.DEFI_REGISTRY).filter(([r,i])=>s in i).map(([r])=>r)}function lt(s,r){return C.routes.some(i=>i.sourceChains.includes(s)&&i.envs.includes(r))}class P extends m{constructor(i,e){super(i,e,t.BtcActionStatus.IDLE);A(this,"chainId");A(this,"authState",{authorized:!1});if(!Et(e.assetOut))throw new t.LombardError(t.ValidationErrorCode.INVALID_ASSET,`Asset ${e.assetOut} is not supported for deposit and deploy. DepositAndDeploy produces BTC.b which is then deployed to a vault like Silo.`);if(!Ct(e.destChain))throw new t.LombardError(t.ValidationErrorCode.INVALID_CHAIN,`Destination chain ${e.destChain} is not supported for deposit and deploy. Supported chains: Avalanche, Avalanche Fuji`);if(!O(e.protocol))throw new t.LombardError(t.ValidationErrorCode.INVALID_PARAMETER,`Protocol ${e.protocol} is not supported for deposit and deploy. DepositAndDeploy with BTC.b only supports Silo protocol.`);const n=e.sourceChain??t.Chain.BITCOIN_MAINNET;if(!lt(n,i.env))throw t.LombardError.routeNotFound({assetOut:e.assetOut,sourceChain:n,destChain:e.destChain,env:i.env});const a=t.parseChainIdentifier(e.destChain);if(typeof a!="number"||!p.isValidChain(a))throw new t.LombardError(t.ValidationErrorCode.INVALID_CHAIN,`Unsupported EVM chain: ${e.destChain}`);this.chainId=a}getAddressSchema(){return C.addressSchema}getStatusConfig(){return{idle:t.BtcActionStatus.IDLE,ready:t.BtcActionStatus.READY,addressReady:t.BtcActionStatus.ADDRESS_READY}}getInitialSteps(){return{created:t.StepStatus.IDLE,verifying:t.StepStatus.IDLE,wrapping:t.StepStatus.IDLE,depositing:t.StepStatus.IDLE}}isAuthorized(){return this.authState.authorized}getChainId(){return this.chainId}getDepositAddressParams(){return{address:this.ensureRecipient(),chainId:this.chainId,signature:this.authState.signature,token:this.getExpectedToken(),signatureData:this.authState.typedData,partnerId:this.ctx.partner.getPartnerId(),referrerCode:this._referralCode}}getExpectedToken(){return D(this.params.assetOut,p.Token.BTCb)}getAuthRequiredMessage(){return"Deposit authorization required. Call authorizeDeposit() first."}get fee(){return this.authState.fee}async prepare(i){return this.assertStatus(t.BtcActionStatus.IDLE,"prepare"),this.act(async()=>{const e=this.validatePrepareParams(i);this._amount=e.amount,this._recipient=e.recipient,this._referralCode=e.referralCode,this.authState.fee=await C.getDepositAndDeployFee(this.ctx,this.chainId,L(this.params.protocol)),this.updateStatus(t.BtcActionStatus.NEEDS_DEPLOY_AUTHORIZATION),this.emitInitialProgress()},t.BtcActionStatus.NEEDS_DEPLOY_AUTHORIZATION)}async authorizeDeposit(){if(this.assertStatus([t.BtcActionStatus.NEEDS_DEPLOY_AUTHORIZATION,t.BtcActionStatus.READY],"authorizeDeposit"),this.status===t.BtcActionStatus.READY)return;const i=this.ensureRecipient(),e=this.ensureAmount();return this.act(async()=>{const n=l.toSatoshi(e),a=D(this.params.assetOut,p.Token.BTCb),o=await C.authorizeDepositAndDeploy(this.ctx,{chainId:this.chainId,recipient:i,amount:n.toString(),vaultKey:L(this.params.protocol),token:a});this.authState.signature=o.signature,this.authState.typedData=o.typedData,this.authState.authorized=!0},t.BtcActionStatus.READY)}async generateDepositAddress(){return this.assertStatus(t.BtcActionStatus.READY,"generateDepositAddress"),this.ensureAuthorized(),this._depositAddress?this._depositAddress:this.act(async()=>{const i=this.getDepositAddressParams(),e=await this.ctx.api.generateDepositAddress(i);return I(e),this._depositAddress=e,this.emitProgress({status:t.BtcActionStatus.ADDRESS_READY,steps:{created:t.StepStatus.COMPLETE,verifying:t.StepStatus.IDLE,wrapping:t.StepStatus.IDLE,depositing:t.StepStatus.IDLE},metadata:{depositAddress:e}}),e},t.BtcActionStatus.ADDRESS_READY)}async execute(){return this.act(async()=>{this.assertStatus(t.BtcActionStatus.ADDRESS_READY,"execute"),this._depositAddress||await this.generateDepositAddress();const i=this.ensureDepositAddress(),e=await this.trySendBitcoin(i);return e?{depositAddress:i,txHash:e}:{depositAddress:i}})}async monitorDeposit(){const i=this._depositAddress,e=this._recipient;if(!i||!e)throw t.LombardError.missingParameter("depositAddress or recipient");return await y({network:this.bitcoinNetwork,btcService:this.ctx.btc,fetchDeposit:async()=>{const o=(await this.ctx.api.getDeposits(e)).find(c=>c.depositAddress===i);if(o)return{blockHeight:o.blockHeight,isClaimed:o.isClaimed}},onProgress:a=>{this.emitProgress({status:this.status,steps:{created:t.StepStatus.COMPLETE,verifying:a.hasEnoughConfirmations?t.StepStatus.COMPLETE:t.StepStatus.PENDING,wrapping:a.isClaimed?t.StepStatus.COMPLETE:t.StepStatus.PENDING,depositing:t.StepStatus.PENDING},confirmations:a.confirmations,requiredConfirmations:a.requiredConfirmations,metadata:{isClaimed:a.isClaimed}})},onComplete:()=>{this.emitCompleted()}})}}const w=s=>`${s}${t.CAIP2_SEPARATOR}`;function ft(s){return String(s).startsWith(w(t.CHAIN_PREFIXES.EIP155))}function It(s){return String(s).startsWith(w(t.CHAIN_PREFIXES.SOLANA))}function mt(s){return String(s).startsWith(w(t.CHAIN_PREFIXES.SUI))}function wt(s){return String(s).startsWith(w(t.CHAIN_PREFIXES.STARKNET))}const Tt=[t.Chain.ETHEREUM,t.Chain.SEPOLIA],yt={async getMintingFee(s,r){return s.capabilities.require("evm").getMintingFee(r)},async restoreFeeSignature(s,r,i){const e=await f.getTokenContractInfo(p.Token.LBTC,r,s.env),n=await s.api.getFeeSignature({address:i,chainId:r,tokenAddress:e.address});return!n.hasSignature||n.expirationDate&&new Date(Number(n.expirationDate)*1e3)<new Date?null:{hasSignature:!0,signature:n.signature,typedData:n.typedData}},async authorizeFee(s,{chainId:r,recipient:i,fee:e}){const n=s.capabilities.require("evm"),a=await s.getProvider("evm");if(!a)throw t.LombardError.providerMissing(String(r),"evm");await E(a,r);const o=l.toSatoshi(e).toString(),c=await f.getTokenContractInfo(p.Token.LBTC,r,s.env),d=await n.signNetworkFee({fee:o,account:i,chainId:r,provider:a,token:p.Token.LBTC});return await s.api.storeFeeSignature({address:i,signature:d.signature,typedData:d.typedData,tokenAddress:c.address}),{signature:d.signature,typedData:d.typedData}}},_t={chainType:"evm",routes:[{sourceChains:[t.Chain.BITCOIN_MAINNET],envs:[u.r.prod]},{sourceChains:[t.Chain.BITCOIN_SIGNET],envs:[u.r.testnet,u.r.stage,u.r.dev,u.r.ibc]}],destChains:t.getAllAssetChains(h.AssetId.LBTC).filter(s=>ft(s)),supportedAssetsOut:[h.AssetId.LBTC],addressSchema:t.evmAddressSchema,getFeeAuthConfig(s){return Tt.includes(s)?yt:null},async getSignature(s,r,i){const e=s.capabilities.require("evm"),n=await s.getProvider("evm");if(!n)throw t.LombardError.providerMissing(String(i),"evm");return await E(n,i),e.signLbtcDestination({chainId:i,address:r,provider:n})}};function Bt(s){const r={[t.Chain.SOLANA_MAINNET]:"mainnet-beta",[t.Chain.SOLANA_DEVNET]:"devnet",[t.Chain.SOLANA_TESTNET]:"testnet","solana:mainnet-beta":"mainnet-beta","solana:devnet":"devnet","solana:testnet":"testnet"},i=r[s];if(!i)throw new t.LombardError(t.ValidationErrorCode.INVALID_CHAIN,`Unknown Solana chain: ${s}. Expected one of: ${Object.keys(r).join(", ")}`);return i}const Nt={chainType:"solana",routes:[{sourceChains:[t.Chain.BITCOIN_MAINNET],envs:[u.r.prod]},{sourceChains:[t.Chain.BITCOIN_SIGNET],envs:[u.r.testnet,u.r.stage,u.r.dev,u.r.ibc]}],destChains:t.getAllAssetChains(h.AssetId.LBTC).filter(s=>It(s)),supportedAssetsOut:[h.AssetId.LBTC],addressSchema:t.solanaAddressSchema,getFeeAuthConfig:()=>null,async getSignature(s,r,i){const e=s.capabilities.require("solana"),n=Bt(i),{signature:a}=await e.signLbtcDestination({network:n});return{signature:a}}},vt={chainType:"starknet",routes:[{sourceChains:[t.Chain.BITCOIN_MAINNET],envs:[u.r.prod]},{sourceChains:[t.Chain.BITCOIN_SIGNET],envs:[u.r.testnet,u.r.stage,u.r.dev,u.r.ibc]}],destChains:t.getAllAssetChains(h.AssetId.LBTC).filter(s=>wt(s)),supportedAssetsOut:[h.AssetId.LBTC],addressSchema:t.starknetAddressSchema,getFeeAuthConfig:()=>null,async getSignature(s,r,i){const e=s.capabilities.require("starknet"),{signature:n,pubKey:a}=await e.signLbtcDestination({chainId:i}),o=$.pad(r,{size:32});return{signature:n,pubKey:a,paddedAddress:o}}},Lt={chainType:"sui",routes:[{sourceChains:[t.Chain.BITCOIN_MAINNET],envs:[u.r.prod]},{sourceChains:[t.Chain.BITCOIN_SIGNET],envs:[u.r.testnet,u.r.stage,u.r.dev,u.r.ibc]}],destChains:t.getAllAssetChains(h.AssetId.LBTC).filter(s=>mt(s)),supportedAssetsOut:[h.AssetId.LBTC],addressSchema:t.suiAddressSchema,getFeeAuthConfig:()=>null,async getSignature(s,r,i){const e=s.capabilities.require("sui"),{signature:n}=await e.signLbtcDestination({chainId:i});return{signature:n}}},Rt={evm:_t,solana:Nt,sui:Lt,starknet:vt};function bt(s){return Rt[s]}function kt(s,r,i){return r?s.routes.some(e=>e.sourceChains.includes(r)&&e.envs.includes(i)):!0}function Ot(s,r){return s.destChains.includes(r)}function Pt(s,r){return s.supportedAssetsOut.includes(r)}class F extends m{constructor(i,e){super(i,e,t.BtcActionStatus.IDLE);A(this,"config");A(this,"chainId");A(this,"authState",{authorized:!1});A(this,"feeAuthConfig",null);const n=t.getChainType(e.destChain),a=bt(n);if(!a)throw new t.LombardError(t.ValidationErrorCode.INVALID_CHAIN,`Unsupported destination chain type: ${n} (${e.destChain})`);if(!Pt(a,e.assetOut))throw new t.LombardError(t.ValidationErrorCode.INVALID_ASSET,`Asset ${e.assetOut} is not supported for BTC staking. BTC Stake produces LBTC. For BTC.b, use BtcDeposit instead.`);if(!Ot(a,e.destChain))throw new t.LombardError(t.ValidationErrorCode.INVALID_CHAIN,`Destination chain ${e.destChain} is not supported for ${n}`);if(!kt(a,e.sourceChain,i.env))throw t.LombardError.routeNotFound({assetOut:e.assetOut,sourceChain:e.sourceChain,destChain:e.destChain,env:i.env});this.config=a,this.chainId=t.parseChainIdentifier(e.destChain)}getAddressSchema(){return this.config.addressSchema}getStatusConfig(){return{idle:t.BtcActionStatus.IDLE,ready:t.BtcActionStatus.READY,addressReady:t.BtcActionStatus.ADDRESS_READY}}getInitialSteps(){return{created:t.StepStatus.IDLE,verifying:t.StepStatus.IDLE,issuing:t.StepStatus.IDLE}}isAuthorized(){return this.authState.authorized}getChainId(){return this.chainId}getDepositAddressParams(){var n;const i=this.ensureRecipient(),e=this.getActiveSignature();if(!e)throw new t.LombardError(t.ValidationErrorCode.INVALID_PARAMETER,"Missing signature. Complete authorization first.");return{address:e.paddedAddress??i,chainId:this.chainId,signature:e.signature,token:this.getExpectedToken(),eip712Data:(n=this.authState.networkFee)==null?void 0:n.typedData,pubKey:e.pubKey,partnerId:this.ctx.partner.getPartnerId(),referrerCode:this._referralCode}}getExpectedToken(){return D(this.params.assetOut,p.Token.LBTC)}getAuthRequiredMessage(){return"Authorization required. Call authorize() first."}get mintingFee(){return this.authState.mintingFee}async prepare(i){return this.assertStatus(t.BtcActionStatus.IDLE,"prepare"),this.act(async()=>{const e=this.validatePrepareParams(i);if(this._amount=e.amount,this._recipient=e.recipient,this._referralCode=e.referralCode,this.feeAuthConfig=this.config.getFeeAuthConfig(this.params.destChain),await this.resumeFromExistingDeposit(e.recipient)){if(this.feeAuthConfig){const a=await this.feeAuthConfig.restoreFeeSignature(this.ctx,this.chainId,e.recipient);if(!(a!=null&&a.hasSignature)){this.authState.mintingFee=await this.feeAuthConfig.getMintingFee(this.ctx,this.chainId),this.updateStatus(t.BtcActionStatus.NEEDS_FEE_AUTHORIZATION),this.emitInitialProgress();return}a.signature&&(this.authState.networkFee={signature:a.signature,typedData:a.typedData}),this.authState.authorized=!0}this.updateStatus(t.BtcActionStatus.ADDRESS_READY),this.emitInitialProgress();return}if(this.feeAuthConfig){const a=await this.feeAuthConfig.restoreFeeSignature(this.ctx,this.chainId,e.recipient);if(a!=null&&a.hasSignature){a.signature&&(this.authState.networkFee={signature:a.signature,typedData:a.typedData}),this.authState.authorized=!0,this.updateStatus(t.BtcActionStatus.READY),this.emitInitialProgress();return}this.authState.mintingFee=await this.feeAuthConfig.getMintingFee(this.ctx,this.chainId),this.updateStatus(t.BtcActionStatus.NEEDS_FEE_AUTHORIZATION)}else this.updateStatus(t.BtcActionStatus.NEEDS_ADDRESS_CONFIRMATION);this.emitInitialProgress()})}async authorize(){if(this.assertStatus([t.BtcActionStatus.NEEDS_FEE_AUTHORIZATION,t.BtcActionStatus.NEEDS_ADDRESS_CONFIRMATION,t.BtcActionStatus.READY],"authorize"),this.status===t.BtcActionStatus.READY)return;const i=this.ensureRecipient(),e=this.feeAuthConfig!==null;return this.act(async()=>{if(e){const n=this.ensureMintingFee(),a=await this.feeAuthConfig.authorizeFee(this.ctx,{chainId:this.chainId,recipient:i,fee:n});this.authState.networkFee={signature:a.signature,typedData:a.typedData}}else this.authState.destinationSignature=await this.config.getSignature(this.ctx,i,this.chainId);this.authState.authorized=!0},t.BtcActionStatus.READY)}async generateDepositAddress(){if(this.assertStatus(t.BtcActionStatus.READY,"generateDepositAddress"),this.ensureAuthorized(),this._depositAddress)return this._depositAddress;if(!this.getActiveSignature()){const i=await this.config.getSignature(this.ctx,this.ensureRecipient(),this.chainId);this.authState.destinationSignature=i}return this.act(async()=>{const i=this.getDepositAddressParams(),e=await this.ctx.api.generateDepositAddress(i);return I(e),this._depositAddress=e,this.emitProgress({status:t.BtcActionStatus.ADDRESS_READY,steps:{created:t.StepStatus.COMPLETE,verifying:t.StepStatus.IDLE,issuing:t.StepStatus.IDLE},metadata:{depositAddress:e}}),e},t.BtcActionStatus.ADDRESS_READY)}async execute(){return this.executeImpl()}async monitorDeposit(){return super.monitorDeposit()}ensureMintingFee(){if(!this.authState.mintingFee)throw new t.LombardError(t.ValidationErrorCode.INVALID_PARAMETER,"Minting fee not fetched. Call prepare() first.");return this.authState.mintingFee}getActiveSignature(){var i;return(i=this.authState.networkFee)!=null&&i.signature?{signature:this.authState.networkFee.signature}:this.authState.destinationSignature}}class x extends m{constructor(i,e){super(i,e,t.BtcActionStatus.IDLE);A(this,"chainId");A(this,"authState",{authorized:!1});if(!ht(e.assetOut))throw new t.LombardError(t.ValidationErrorCode.INVALID_ASSET,`Asset ${e.assetOut} is not supported for stake and deploy. StakeAndDeploy produces LBTC which is then deployed to a vault.`);if(!ct(e.destChain))throw new t.LombardError(t.ValidationErrorCode.INVALID_CHAIN,`Destination chain ${e.destChain} is not supported for stake and deploy`);if(!k(e.protocol))throw new t.LombardError(t.ValidationErrorCode.INVALID_PARAMETER,`Protocol ${e.protocol} is not supported for stake and deploy`);if(!pt(e.sourceChain,i.env))throw t.LombardError.routeNotFound({assetOut:e.assetOut,sourceChain:e.sourceChain,destChain:e.destChain,env:i.env});const n=t.parseChainIdentifier(e.destChain);if(typeof n!="number"||!p.isValidChain(n))throw new t.LombardError(t.ValidationErrorCode.INVALID_CHAIN,`Unsupported EVM chain: ${e.destChain}`);this.chainId=n}getAddressSchema(){return S.addressSchema}getStatusConfig(){return{idle:t.BtcActionStatus.IDLE,ready:t.BtcActionStatus.READY,addressReady:t.BtcActionStatus.ADDRESS_READY}}getInitialSteps(){return{created:t.StepStatus.IDLE,verifying:t.StepStatus.IDLE,issuing:t.StepStatus.IDLE,depositing:t.StepStatus.IDLE}}isAuthorized(){return this.authState.authorized}getChainId(){return this.chainId}getDepositAddressParams(){return{address:this.ensureRecipient(),chainId:this.chainId,signature:this.authState.signature,token:this.getExpectedToken(),signatureData:this.authState.typedData,partnerId:this.ctx.partner.getPartnerId(),referrerCode:this._referralCode}}getExpectedToken(){return D(this.params.assetOut,p.Token.LBTC)}getAuthRequiredMessage(){return"Deposit authorization required. Call authorizeDeposit() first."}get fee(){return this.authState.fee}async prepare(i){return this.assertStatus(t.BtcActionStatus.IDLE,"prepare"),this.act(async()=>{const e=this.validatePrepareParams(i);if(this._amount=e.amount,this._recipient=e.recipient,this._referralCode=e.referralCode,this.authState.fee=await S.getStakeAndBakeFee(this.ctx,this.chainId,this.params.protocol),await this.resumeFromExistingDeposit(e.recipient)){const o=await S.restoreStakeAndBakeSignature(this.ctx,this.chainId,e.recipient);if(o!=null&&o.hasSignature){o.signature&&(this.authState.signature=o.signature),this.authState.authorized=!0,this.updateStatus(t.BtcActionStatus.ADDRESS_READY),this.emitInitialProgress();return}this.updateStatus(t.BtcActionStatus.NEEDS_DEPLOY_AUTHORIZATION),this.emitInitialProgress();return}const a=await S.restoreStakeAndBakeSignature(this.ctx,this.chainId,e.recipient);if(a!=null&&a.hasSignature){a.signature&&(this.authState.signature=a.signature),this.authState.authorized=!0,this.updateStatus(t.BtcActionStatus.READY),this.emitInitialProgress();return}this.updateStatus(t.BtcActionStatus.NEEDS_DEPLOY_AUTHORIZATION),this.emitInitialProgress()})}async authorizeDeposit(){if(this.assertStatus([t.BtcActionStatus.NEEDS_DEPLOY_AUTHORIZATION,t.BtcActionStatus.READY],"authorizeDeposit"),this.status===t.BtcActionStatus.READY)return;const i=this.ensureRecipient(),e=this.ensureAmount();return this.act(async()=>{const n=l.toSatoshi(e),a=this.params.assetIn??h.AssetId.BTC,o=await S.authorizeStakeAndBake(this.ctx,{chainId:this.chainId,recipient:i,amount:n.toString(),vaultKey:At(this.params.protocol),token:a});this.authState.signature=o.signature,this.authState.typedData=o.typedData,this.authState.authorized=!0},t.BtcActionStatus.READY)}async generateDepositAddress(){return this.assertStatus(t.BtcActionStatus.READY,"generateDepositAddress"),this.ensureAuthorized(),this._depositAddress?this._depositAddress:this.act(async()=>{const i=this.getDepositAddressParams(),e=await this.ctx.api.generateDepositAddress(i);return I(e),this._depositAddress=e,this.emitProgress({status:t.BtcActionStatus.ADDRESS_READY,steps:{created:t.StepStatus.COMPLETE,verifying:t.StepStatus.IDLE,issuing:t.StepStatus.IDLE,depositing:t.StepStatus.IDLE},metadata:{depositAddress:e}}),e},t.BtcActionStatus.ADDRESS_READY)}async execute(){return this.act(async()=>{this.assertStatus(t.BtcActionStatus.ADDRESS_READY,"execute"),this._depositAddress||await this.generateDepositAddress();const i=this.ensureDepositAddress(),e=await this.trySendBitcoin(i);return e?{depositAddress:i,txHash:e}:{depositAddress:i}})}async monitorDeposit(){const i=this._depositAddress,e=this._recipient;if(!i||!e)throw t.LombardError.missingParameter("depositAddress or recipient");return await y({network:this.bitcoinNetwork,btcService:this.ctx.btc,fetchDeposit:async()=>{const o=(await this.ctx.api.getDeposits(e)).find(c=>c.depositAddress===i);if(o)return{blockHeight:o.blockHeight,isClaimed:o.isClaimed}},onProgress:a=>{this.emitProgress({status:this.status,steps:{created:t.StepStatus.COMPLETE,verifying:a.hasEnoughConfirmations?t.StepStatus.COMPLETE:t.StepStatus.PENDING,issuing:a.isClaimed?t.StepStatus.COMPLETE:t.StepStatus.PENDING,depositing:t.StepStatus.PENDING},confirmations:a.confirmations,requiredConfirmations:a.requiredConfirmations,metadata:{isClaimed:a.isClaimed}})},onComplete:()=>{this.emitCompleted()}})}}class M{constructor(r){A(this,"ctx");this.ctx=t.createBtcCoreContext(r)}stake(r){return new F(this.ctx,r)}stakeAndDeploy(r){return new x(this.ctx,r)}deposit(r){return new b(this.ctx,r)}depositAndDeploy(r){return new P(this.ctx,r)}}function Ft(s){return new M(s)}exports.BtcActions=M;exports.BtcDeposit=b;exports.BtcDepositAndDeploy=P;exports.BtcStake=F;exports.BtcStakeAndDeploy=x;exports.btcActions=Ft;exports.btcModule=Q;
|
|
2
|
-
//# sourceMappingURL=BtcActions-
|
|
1
|
+
"use strict";var z=Object.defineProperty;var H=(s,r,i)=>r in s?z(s,r,{enumerable:!0,configurable:!0,writable:!0,value:i}):s[r]=i;var A=(s,r,i)=>H(s,typeof r!="symbol"?r+"":r,i);const Y=require("axios"),p=require("./token-addresses-DRBecUa7.cjs"),t=require("./statusConstants-fmtIEEEM.cjs"),u=require("./index-BKzxeh1Y.cjs"),f=require("./tokens-D_HeVB5p.cjs"),l=require("./satoshi-CZEsHl5X.cjs"),h=require("./defi-registry-BIRv_zkp.cjs"),R=require("./getUserStakeAndBakeSignature-BxRq2cI1.cjs"),q=require("./config-l4ZaZw_g.cjs"),$=require("viem"),U="ERR_NETWORK",G="This may be due to your Adblocker. Please disable any Adblocker and refresh the page to restore full functionality.";function K(s){const{code:r,message:i}=s;throw r===U?new Error(G):new Error(i)}const j={mempoolApiUrl:"https://mempool.space/signet"},Z={mempoolApiUrl:"https://mempool.space"},W=s=>s==="mainnet"?Z:j;async function X(s){const{mempoolApiUrl:r}=W(s),i=Math.floor(Date.now()/1e3),e=`${r}/api/v1/mining/blocks/timestamp/${i}`;try{const{data:n}=await Y.get(e);return n.height}catch(n){K(n)}}class J{async getCurrentBlockHeight(r){return X(r)}}function Q(){return{id:"btc",chain:"btc",register(){return new J}}}async function y(s){const{fetchDeposit:r,network:i,btcService:e,requiredConfirmations:n=6,onProgress:a,onComplete:o}=s,c=await r();if(!c)return;const d=c.blockHeight;if(typeof d!="number")return;const V=await e.getCurrentBlockHeight(i),_=Math.max(0,V-d),B=_>=n,T=c.isClaimed??!1,N={confirmations:_,requiredConfirmations:n,hasEnoughConfirmations:B,isClaimed:T,steps:{created:t.StepStatus.COMPLETE,verifying:B?t.StepStatus.COMPLETE:t.StepStatus.PENDING,issuing:T?t.StepStatus.COMPLETE:t.StepStatus.PENDING}};return a==null||a(N),T&&(o==null||o()),N}function I(s){if(s===R.SANCTIONED_ADDRESS)throw new t.LombardError(t.ValidationErrorCode.INVALID_PARAMETER,"Destination address is under sanctions")}class m extends t.BaseAction{constructor(i,e,n){super(n);A(this,"_amount");A(this,"_recipient");A(this,"_depositAddress");A(this,"_referralCode");A(this,"_chainId");this.ctx=i,this.params=e}get amount(){return this._amount}get recipient(){return this._recipient}get depositAddress(){return this._depositAddress}get referralCode(){return this._referralCode}get bitcoinNetwork(){return this.params.sourceChain===t.Chain.BITCOIN_MAINNET?"mainnet":"testnet"}get prepareSchema(){return t.objectType({amount:t.btcStakeAmountSchema,recipient:this.getAddressSchema(),referralCode:t.referralCodeSchema})}validatePrepareParams(i){return t.validatePrepareParams(this.prepareSchema,i,{destChain:this.params.destChain})}ensureRecipient(){if(!this._recipient)throw t.LombardError.missingParameter("recipient");return this._recipient}ensureAmount(){if(!this._amount)throw t.LombardError.missingParameter("amount");return this._amount}ensureDepositAddress(){if(!this._depositAddress)throw new t.LombardError(t.ValidationErrorCode.INVALID_PARAMETER,"Deposit address not generated. Call generateDepositAddress() first.");return this._depositAddress}getAuthRequiredMessage(){return"Authorization required. Complete the authorization step first."}ensureAuthorized(){if(!this.isAuthorized())throw new t.LombardError(t.ValidationErrorCode.INVALID_PARAMETER,this.getAuthRequiredMessage())}async resumeFromExistingDeposit(i){try{const e=await this.ctx.api.getDepositAddress({address:i,chainId:this.getChainId(),token:this.getExpectedToken(),partnerId:this.ctx.partner.getPartnerId()});return e?(this._depositAddress=e,!0):!1}catch{return!1}}async generateDepositAddressImpl(){const i=this.getStatusConfig();return this.assertStatus(i.ready,"generateDepositAddress"),this.ensureAuthorized(),this._depositAddress?this._depositAddress:this.act(async()=>{const e=this.getDepositAddressParams(),n=await this.ctx.api.generateDepositAddress(e);I(n),this._depositAddress=n;const a=this.getInitialSteps(),o=Object.fromEntries(Object.entries(a).map(([c],d)=>[c,d===0?t.StepStatus.COMPLETE:t.StepStatus.IDLE]));return this.emitProgress({status:i.addressReady,steps:o,metadata:{depositAddress:n}}),n},i.addressReady)}async executeImpl(){const i=this.getStatusConfig();return this.act(async()=>{this.assertStatus(i.addressReady,"execute"),this._depositAddress||await this.generateDepositAddressImpl();const e=this.ensureDepositAddress(),n=await this.trySendBitcoin(e);return n?{depositAddress:e,txHash:n}:{depositAddress:e}})}emitInitialProgress(){this.emitProgress({status:this.status,steps:this.getInitialSteps()})}async monitorDeposit(){const i=this._depositAddress,e=this._recipient;if(!i||!e)throw t.LombardError.missingParameter("depositAddress or recipient");return await y({network:this.bitcoinNetwork,btcService:this.ctx.btc,fetchDeposit:async()=>{const o=(await this.ctx.api.getDeposits(e)).find(c=>c.depositAddress===i);if(o)return{blockHeight:o.blockHeight,isClaimed:o.isClaimed}},onProgress:a=>{this.emitProgress({status:this.status,steps:a.steps,confirmations:a.confirmations,requiredConfirmations:a.requiredConfirmations,metadata:{isClaimed:a.isClaimed}})},onComplete:()=>{this.emitCompleted()}})}async trySendBitcoin(i){const e=this._amount;if(e)try{const n=await this.ctx.getProvider("bitcoin");if(!n)return;const a=n;if(a.sendBitcoin){const o=l.toSatoshi(e).toNumber();return a.sendBitcoin(i,o)}}catch{}}}function D(s,r=p.Token.LBTC){switch(s){case h.AssetId.LBTC:return p.Token.LBTC;case h.AssetId.BTCb:return p.Token.BTCb;default:return r}}async function tt(s,r){try{await s.request({method:"wallet_switchEthereumChain",params:[{chainId:`0x${r.toString(16)}`}]})}catch(i){const e=i;if(e.code===4902)try{await p.addChain({provider:s,chainId:r}),await s.request({method:"wallet_switchEthereumChain",params:[{chainId:`0x${r.toString(16)}`}]});return}catch(n){const a=n;throw a.code===4001?new t.LombardError(t.ValidationErrorCode.INVALID_PARAMETER,"User rejected adding chain to wallet."):new t.LombardError(t.ValidationErrorCode.INVALID_CHAIN,`Failed to add chain ${r} to wallet: ${a.message||"Unknown error"}`)}throw e.code===4001?new t.LombardError(t.ValidationErrorCode.INVALID_PARAMETER,"User rejected chain switch request."):new t.LombardError(t.ValidationErrorCode.INVALID_CHAIN,`Failed to switch to chain ${r}: ${e.message||"Unknown error"}`)}}async function et(s){const r=await s.request({method:"eth_chainId"});return parseInt(r,16)}async function E(s,r){await et(s)!==r&&await tt(s,r)}const st=[t.Chain.ETHEREUM,t.Chain.SEPOLIA],it={async getMintingFee(s,r){return s.capabilities.require("evm").getMintingFee(r,p.Token.BTCb)},async restoreFeeSignature(s,r,i){const e=await f.getTokenContractInfo(p.Token.BTCb,r,s.env),n=await s.api.getFeeSignature({address:i,chainId:r,tokenAddress:e.address});return!n.hasSignature||n.expirationDate&&new Date(Number(n.expirationDate)*1e3)<new Date?null:{hasSignature:!0,signature:n.signature,typedData:n.typedData}},async authorizeFee(s,{chainId:r,recipient:i,fee:e}){const n=s.capabilities.require("evm"),a=await s.getProvider("evm");if(!a)throw t.LombardError.providerMissing(String(r),"evm");await E(a,r);const o=l.toSatoshi(e).toString(),c=await f.getTokenContractInfo(p.Token.BTCb,r,s.env),d=await n.signNetworkFee({fee:o,account:i,chainId:r,provider:a,token:p.Token.BTCb});return await s.api.storeFeeSignature({address:i,signature:d.signature,typedData:d.typedData,tokenAddress:c.address}),{signature:d.signature,typedData:d.typedData}}},rt={chainType:"evm",routes:[{sourceChains:[t.Chain.BITCOIN_MAINNET],envs:[u.r.prod]},{sourceChains:[t.Chain.BITCOIN_SIGNET],envs:[u.r.stage,u.r.dev,u.r.testnet,u.r.ibc]}],destChains:t.getAllAssetChains(h.AssetId.BTCb).filter(s=>t.isEvmChain(s)),supportedAssetsOut:[h.AssetId.BTCb],addressSchema:t.evmAddressSchema,getFeeAuthConfig(s){return st.includes(s)?it:null},async signDestination(s,r,i){const e=s.capabilities.require("evm"),n=await s.getProvider("evm");if(!n)throw t.LombardError.providerMissing(String(i),"evm");return await E(n,i),{signature:(await e.signLbtcDestination({address:r,chainId:i,provider:n})).signature}}},g=rt;function at(s){return g.destChains.includes(s)}function nt(s){return g.supportedAssetsOut.includes(s)}function ot(s,r){return s?g.routes.some(i=>i.sourceChains.includes(s)&&i.envs.includes(r)):!0}class b extends m{constructor(i,e){super(i,e,t.BtcActionStatus.IDLE);A(this,"chainId");A(this,"authState",{authorized:!1});A(this,"feeAuthConfig",null);if(!nt(e.assetOut))throw new t.LombardError(t.ValidationErrorCode.INVALID_ASSET,`Asset ${e.assetOut} is not supported for BTC deposits. BTC Deposit produces BTC.b. For LBTC, use BtcStake instead.`);if(!at(e.destChain))throw new t.LombardError(t.ValidationErrorCode.INVALID_CHAIN,`Destination chain ${e.destChain} is not supported for BTC deposits. BTC.b is currently available on Avalanche and Katana.`);if(!ot(e.sourceChain,i.env))throw t.LombardError.routeNotFound({assetOut:e.assetOut,sourceChain:e.sourceChain,destChain:e.destChain,env:i.env});const n=t.parseChainIdentifier(e.destChain);if(typeof n!="number"||!p.isValidChain(n))throw new t.LombardError(t.ValidationErrorCode.INVALID_CHAIN,`Unsupported EVM chain: ${e.destChain}`);this.chainId=n}getAddressSchema(){return g.addressSchema}getStatusConfig(){return{idle:t.BtcActionStatus.IDLE,ready:t.BtcActionStatus.READY,addressReady:t.BtcActionStatus.ADDRESS_READY}}getInitialSteps(){return{created:t.StepStatus.IDLE,verifying:t.StepStatus.IDLE,issuing:t.StepStatus.IDLE}}isAuthorized(){return this.authState.authorized}getChainId(){return this.chainId}get mintingFee(){return this.authState.mintingFee}getDepositAddressParams(){return{address:this.ensureRecipient(),chainId:this.chainId,signature:this.authState.signature,token:this.getExpectedToken(),eip712Data:this.authState.typedData,partnerId:this.ctx.partner.getPartnerId(),referrerCode:this._referralCode}}async generateDepositAddress(){if(!this.authState.signature){const i=await g.signDestination(this.ctx,this.ensureRecipient(),this.chainId);this.authState.signature=i.signature,this.authState.typedData=i.typedData}return this.generateDepositAddressImpl()}getExpectedToken(){return D(this.params.assetOut,p.Token.BTCb)}getAuthRequiredMessage(){return this.feeAuthConfig?"Fee authorization required. Call authorizeFee() first.":"Address confirmation required. Call confirmAddress() first."}async prepare(i){return this.assertStatus(t.BtcActionStatus.IDLE,"prepare"),this.act(async()=>{const e=this.validatePrepareParams(i);if(this._amount=e.amount,this._recipient=e.recipient,this._referralCode=e.referralCode,this.feeAuthConfig=g.getFeeAuthConfig(this.params.destChain),await this.resumeFromExistingDeposit(e.recipient)){if(this.feeAuthConfig){const a=await this.feeAuthConfig.restoreFeeSignature(this.ctx,this.chainId,e.recipient);if(!(a!=null&&a.hasSignature)){this.authState.mintingFee=await this.feeAuthConfig.getMintingFee(this.ctx,this.chainId),this.updateStatus(t.BtcActionStatus.NEEDS_FEE_AUTHORIZATION),this.emitInitialProgress();return}a.signature&&(this.authState.signature=a.signature,this.authState.typedData=a.typedData),this.authState.authorized=!0}this.updateStatus(t.BtcActionStatus.ADDRESS_READY),this.emitInitialProgress();return}if(this.feeAuthConfig){const a=await this.feeAuthConfig.restoreFeeSignature(this.ctx,this.chainId,e.recipient);if(a!=null&&a.hasSignature){a.signature&&(this.authState.signature=a.signature,this.authState.typedData=a.typedData),this.authState.authorized=!0,this.updateStatus(t.BtcActionStatus.READY),this.emitInitialProgress();return}this.authState.mintingFee=await this.feeAuthConfig.getMintingFee(this.ctx,this.chainId),this.updateStatus(t.BtcActionStatus.NEEDS_FEE_AUTHORIZATION)}else this.updateStatus(t.BtcActionStatus.NEEDS_ADDRESS_CONFIRMATION);this.emitInitialProgress()})}async authorizeFee(){if(this.assertStatus([t.BtcActionStatus.NEEDS_FEE_AUTHORIZATION,t.BtcActionStatus.READY],"authorizeFee"),this.status===t.BtcActionStatus.READY)return;if(!this.feeAuthConfig)throw new t.LombardError(t.ValidationErrorCode.INVALID_PARAMETER,"Fee authorization is not required for this destination chain. Use confirmAddress() instead.");const i=this.ensureRecipient();if(!this.authState.mintingFee)throw new t.LombardError(t.ValidationErrorCode.INVALID_STATE,"Minting fee not available. Call prepare() first.");return this.act(async()=>{const e=await this.feeAuthConfig.authorizeFee(this.ctx,{chainId:this.chainId,recipient:i,fee:this.authState.mintingFee});this.authState.signature=e.signature,this.authState.typedData=e.typedData,this.authState.authorized=!0},t.BtcActionStatus.READY)}async confirmAddress(){if(this.assertStatus([t.BtcActionStatus.NEEDS_ADDRESS_CONFIRMATION,t.BtcActionStatus.READY],"confirmAddress"),this.status===t.BtcActionStatus.READY)return;if(this.feeAuthConfig)throw new t.LombardError(t.ValidationErrorCode.INVALID_PARAMETER,"This destination chain requires fee authorization. Use authorizeFee() instead.");const i=this.ensureRecipient();return this.act(async()=>{const e=await g.signDestination(this.ctx,i,this.chainId);this.authState.signature=e.signature,this.authState.typedData=e.typedData,this.authState.authorized=!0},t.BtcActionStatus.READY)}async execute(){return this.executeImpl()}async monitorDeposit(){return super.monitorDeposit()}}const ut=q.VEDA_VAULT_STAKE_AND_BAKE_CHAINS.map(s=>t.evmChainIdToChain(s)),dt={chainType:"evm",routes:[{sourceChains:[t.Chain.BITCOIN_MAINNET],envs:[u.r.prod]},{sourceChains:[t.Chain.BITCOIN_SIGNET],envs:[u.r.stage,u.r.dev,u.r.testnet,u.r.ibc]}],destChains:ut,supportedAssetsOut:[h.AssetId.LBTC],supportedProtocols:Dt(h.AssetId.LBTC),addressSchema:t.evmAddressSchema,async getStakeAndBakeFee(s,r,i){return s.capabilities.require("evm").getStakeAndBakeFee(r,i)},async authorizeStakeAndBake(s,{chainId:r,recipient:i,amount:e,vaultKey:n,token:a}){const o=s.capabilities.require("evm"),c=await s.getProvider("evm");if(!c)throw t.LombardError.providerMissing(String(r),"evm");await E(c,r);const d=await o.signStakeAndBake({value:e,account:i,chainId:r,provider:c,vaultKey:n,token:a});return await s.api.storeStakeAndBakeSignature({signature:d.signature,typedData:d.typedData}),{signature:d.signature,typedData:d.typedData}},async restoreStakeAndBakeSignature(s,r,i){try{const e=await R.getUserStakeAndBakeSignature({userDestinationAddress:i,chainId:r,env:s.env});return!(e.signature||e.expirationDate)||e.expirationDate&&Number(e.expirationDate)*1e3<Date.now()?null:{hasSignature:!0,signature:e.signature,depositAmount:e.depositAmount,expirationDate:e.expirationDate}}catch{return null}}},S=dt;function ct(s){return S.destChains.includes(s)}function ht(s){return S.supportedAssetsOut.includes(s)}function pt(s,r){return s?S.routes.some(i=>i.sourceChains.includes(s)&&i.envs.includes(r)):!0}function k(s){return s in h.DEFI_REGISTRY}function At(s){if(!k(s)){const r=Object.keys(h.DEFI_REGISTRY).join(", ");throw new Error(`Unsupported protocol: ${s}. Supported protocols: ${r}`)}return s}function St(s){return Object.entries(h.DEFI_REGISTRY).filter(([r,i])=>s in i).map(([r])=>r)}const v={mainnet:[t.Chain.AVALANCHE],testnet:[t.Chain.AVALANCHE_FUJI]},gt={chainType:"evm",routes:[{sourceChains:[t.Chain.BITCOIN_MAINNET],envs:[u.r.prod]},{sourceChains:[t.Chain.BITCOIN_SIGNET],envs:[u.r.stage,u.r.dev,u.r.testnet,u.r.ibc]}],destChains:[...v.mainnet,...v.testnet],supportedAssetsOut:[h.AssetId.BTCb],supportedProtocols:St(h.AssetId.BTCb),addressSchema:t.evmAddressSchema,async getDepositAndDeployFee(s,r,i){return s.capabilities.require("evm").getStakeAndBakeFee(r,i)},async authorizeDepositAndDeploy(s,{chainId:r,recipient:i,amount:e,vaultKey:n,token:a}){const o=s.capabilities.require("evm"),c=await s.getProvider("evm");if(!c)throw t.LombardError.providerMissing(String(r),"evm");await E(c,r);const d=await o.signStakeAndBake({value:e,account:i,chainId:r,provider:c,vaultKey:n,token:a});return await s.api.storeStakeAndBakeSignature({signature:d.signature,typedData:d.typedData}),{signature:d.signature,typedData:d.typedData,approvalTxHash:d.approvalTxHash}}},C=gt;function Ct(s){return C.destChains.includes(s)}function Et(s){return C.supportedAssetsOut.includes(s)}function O(s){return s in h.DEFI_REGISTRY}function L(s){if(!O(s)){const r=Object.keys(h.DEFI_REGISTRY).join(", ");throw new Error(`Unsupported protocol: ${s}. Supported protocols: ${r}`)}return s}function Dt(s){return Object.entries(h.DEFI_REGISTRY).filter(([r,i])=>s in i).map(([r])=>r)}function lt(s,r){return C.routes.some(i=>i.sourceChains.includes(s)&&i.envs.includes(r))}class P extends m{constructor(i,e){super(i,e,t.BtcActionStatus.IDLE);A(this,"chainId");A(this,"authState",{authorized:!1});if(!Et(e.assetOut))throw new t.LombardError(t.ValidationErrorCode.INVALID_ASSET,`Asset ${e.assetOut} is not supported for deposit and deploy. DepositAndDeploy produces BTC.b which is then deployed to a vault like Silo.`);if(!Ct(e.destChain))throw new t.LombardError(t.ValidationErrorCode.INVALID_CHAIN,`Destination chain ${e.destChain} is not supported for deposit and deploy. Supported chains: Avalanche, Avalanche Fuji`);if(!O(e.protocol))throw new t.LombardError(t.ValidationErrorCode.INVALID_PARAMETER,`Protocol ${e.protocol} is not supported for deposit and deploy. DepositAndDeploy with BTC.b only supports Silo protocol.`);const n=e.sourceChain??t.Chain.BITCOIN_MAINNET;if(!lt(n,i.env))throw t.LombardError.routeNotFound({assetOut:e.assetOut,sourceChain:n,destChain:e.destChain,env:i.env});const a=t.parseChainIdentifier(e.destChain);if(typeof a!="number"||!p.isValidChain(a))throw new t.LombardError(t.ValidationErrorCode.INVALID_CHAIN,`Unsupported EVM chain: ${e.destChain}`);this.chainId=a}getAddressSchema(){return C.addressSchema}getStatusConfig(){return{idle:t.BtcActionStatus.IDLE,ready:t.BtcActionStatus.READY,addressReady:t.BtcActionStatus.ADDRESS_READY}}getInitialSteps(){return{created:t.StepStatus.IDLE,verifying:t.StepStatus.IDLE,wrapping:t.StepStatus.IDLE,depositing:t.StepStatus.IDLE}}isAuthorized(){return this.authState.authorized}getChainId(){return this.chainId}getDepositAddressParams(){return{address:this.ensureRecipient(),chainId:this.chainId,signature:this.authState.signature,token:this.getExpectedToken(),signatureData:this.authState.typedData,partnerId:this.ctx.partner.getPartnerId(),referrerCode:this._referralCode}}getExpectedToken(){return D(this.params.assetOut,p.Token.BTCb)}getAuthRequiredMessage(){return"Deposit authorization required. Call authorizeDeposit() first."}get fee(){return this.authState.fee}async prepare(i){return this.assertStatus(t.BtcActionStatus.IDLE,"prepare"),this.act(async()=>{const e=this.validatePrepareParams(i);this._amount=e.amount,this._recipient=e.recipient,this._referralCode=e.referralCode,this.authState.fee=await C.getDepositAndDeployFee(this.ctx,this.chainId,L(this.params.protocol)),this.updateStatus(t.BtcActionStatus.NEEDS_DEPLOY_AUTHORIZATION),this.emitInitialProgress()},t.BtcActionStatus.NEEDS_DEPLOY_AUTHORIZATION)}async authorizeDeposit(){if(this.assertStatus([t.BtcActionStatus.NEEDS_DEPLOY_AUTHORIZATION,t.BtcActionStatus.READY],"authorizeDeposit"),this.status===t.BtcActionStatus.READY)return;const i=this.ensureRecipient(),e=this.ensureAmount();return this.act(async()=>{const n=l.toSatoshi(e),a=D(this.params.assetOut,p.Token.BTCb),o=await C.authorizeDepositAndDeploy(this.ctx,{chainId:this.chainId,recipient:i,amount:n.toString(),vaultKey:L(this.params.protocol),token:a});this.authState.signature=o.signature,this.authState.typedData=o.typedData,this.authState.authorized=!0},t.BtcActionStatus.READY)}async generateDepositAddress(){return this.assertStatus(t.BtcActionStatus.READY,"generateDepositAddress"),this.ensureAuthorized(),this._depositAddress?this._depositAddress:this.act(async()=>{const i=this.getDepositAddressParams(),e=await this.ctx.api.generateDepositAddress(i);return I(e),this._depositAddress=e,this.emitProgress({status:t.BtcActionStatus.ADDRESS_READY,steps:{created:t.StepStatus.COMPLETE,verifying:t.StepStatus.IDLE,wrapping:t.StepStatus.IDLE,depositing:t.StepStatus.IDLE},metadata:{depositAddress:e}}),e},t.BtcActionStatus.ADDRESS_READY)}async execute(){return this.act(async()=>{this.assertStatus(t.BtcActionStatus.ADDRESS_READY,"execute"),this._depositAddress||await this.generateDepositAddress();const i=this.ensureDepositAddress(),e=await this.trySendBitcoin(i);return e?{depositAddress:i,txHash:e}:{depositAddress:i}})}async monitorDeposit(){const i=this._depositAddress,e=this._recipient;if(!i||!e)throw t.LombardError.missingParameter("depositAddress or recipient");return await y({network:this.bitcoinNetwork,btcService:this.ctx.btc,fetchDeposit:async()=>{const o=(await this.ctx.api.getDeposits(e)).find(c=>c.depositAddress===i);if(o)return{blockHeight:o.blockHeight,isClaimed:o.isClaimed}},onProgress:a=>{this.emitProgress({status:this.status,steps:{created:t.StepStatus.COMPLETE,verifying:a.hasEnoughConfirmations?t.StepStatus.COMPLETE:t.StepStatus.PENDING,wrapping:a.isClaimed?t.StepStatus.COMPLETE:t.StepStatus.PENDING,depositing:t.StepStatus.PENDING},confirmations:a.confirmations,requiredConfirmations:a.requiredConfirmations,metadata:{isClaimed:a.isClaimed}})},onComplete:()=>{this.emitCompleted()}})}}const w=s=>`${s}${t.CAIP2_SEPARATOR}`;function ft(s){return String(s).startsWith(w(t.CHAIN_PREFIXES.EIP155))}function It(s){return String(s).startsWith(w(t.CHAIN_PREFIXES.SOLANA))}function mt(s){return String(s).startsWith(w(t.CHAIN_PREFIXES.SUI))}function wt(s){return String(s).startsWith(w(t.CHAIN_PREFIXES.STARKNET))}const Tt=[t.Chain.ETHEREUM,t.Chain.SEPOLIA],yt={async getMintingFee(s,r){return s.capabilities.require("evm").getMintingFee(r)},async restoreFeeSignature(s,r,i){const e=await f.getTokenContractInfo(p.Token.LBTC,r,s.env),n=await s.api.getFeeSignature({address:i,chainId:r,tokenAddress:e.address});return!n.hasSignature||n.expirationDate&&new Date(Number(n.expirationDate)*1e3)<new Date?null:{hasSignature:!0,signature:n.signature,typedData:n.typedData}},async authorizeFee(s,{chainId:r,recipient:i,fee:e}){const n=s.capabilities.require("evm"),a=await s.getProvider("evm");if(!a)throw t.LombardError.providerMissing(String(r),"evm");await E(a,r);const o=l.toSatoshi(e).toString(),c=await f.getTokenContractInfo(p.Token.LBTC,r,s.env),d=await n.signNetworkFee({fee:o,account:i,chainId:r,provider:a,token:p.Token.LBTC});return await s.api.storeFeeSignature({address:i,signature:d.signature,typedData:d.typedData,tokenAddress:c.address}),{signature:d.signature,typedData:d.typedData}}},_t={chainType:"evm",routes:[{sourceChains:[t.Chain.BITCOIN_MAINNET],envs:[u.r.prod]},{sourceChains:[t.Chain.BITCOIN_SIGNET],envs:[u.r.testnet,u.r.stage,u.r.dev,u.r.ibc]}],destChains:t.getAllAssetChains(h.AssetId.LBTC).filter(s=>ft(s)),supportedAssetsOut:[h.AssetId.LBTC],addressSchema:t.evmAddressSchema,getFeeAuthConfig(s){return Tt.includes(s)?yt:null},async getSignature(s,r,i){const e=s.capabilities.require("evm"),n=await s.getProvider("evm");if(!n)throw t.LombardError.providerMissing(String(i),"evm");return await E(n,i),e.signLbtcDestination({chainId:i,address:r,provider:n})}};function Bt(s){const r={[t.Chain.SOLANA_MAINNET]:"mainnet-beta",[t.Chain.SOLANA_DEVNET]:"devnet",[t.Chain.SOLANA_TESTNET]:"testnet","solana:mainnet-beta":"mainnet-beta","solana:devnet":"devnet","solana:testnet":"testnet"},i=r[s];if(!i)throw new t.LombardError(t.ValidationErrorCode.INVALID_CHAIN,`Unknown Solana chain: ${s}. Expected one of: ${Object.keys(r).join(", ")}`);return i}const Nt={chainType:"solana",routes:[{sourceChains:[t.Chain.BITCOIN_MAINNET],envs:[u.r.prod]},{sourceChains:[t.Chain.BITCOIN_SIGNET],envs:[u.r.testnet,u.r.stage,u.r.dev,u.r.ibc]}],destChains:t.getAllAssetChains(h.AssetId.LBTC).filter(s=>It(s)),supportedAssetsOut:[h.AssetId.LBTC],addressSchema:t.solanaAddressSchema,getFeeAuthConfig:()=>null,async getSignature(s,r,i){const e=s.capabilities.require("solana"),n=Bt(i),{signature:a}=await e.signLbtcDestination({network:n});return{signature:a}}},vt={chainType:"starknet",routes:[{sourceChains:[t.Chain.BITCOIN_MAINNET],envs:[u.r.prod]},{sourceChains:[t.Chain.BITCOIN_SIGNET],envs:[u.r.testnet,u.r.stage,u.r.dev,u.r.ibc]}],destChains:t.getAllAssetChains(h.AssetId.LBTC).filter(s=>wt(s)),supportedAssetsOut:[h.AssetId.LBTC],addressSchema:t.starknetAddressSchema,getFeeAuthConfig:()=>null,async getSignature(s,r,i){const e=s.capabilities.require("starknet"),{signature:n,pubKey:a}=await e.signLbtcDestination({chainId:i}),o=$.pad(r,{size:32});return{signature:n,pubKey:a,paddedAddress:o}}},Lt={chainType:"sui",routes:[{sourceChains:[t.Chain.BITCOIN_MAINNET],envs:[u.r.prod]},{sourceChains:[t.Chain.BITCOIN_SIGNET],envs:[u.r.testnet,u.r.stage,u.r.dev,u.r.ibc]}],destChains:t.getAllAssetChains(h.AssetId.LBTC).filter(s=>mt(s)),supportedAssetsOut:[h.AssetId.LBTC],addressSchema:t.suiAddressSchema,getFeeAuthConfig:()=>null,async getSignature(s,r,i){const e=s.capabilities.require("sui"),{signature:n}=await e.signLbtcDestination({chainId:i});return{signature:n}}},Rt={evm:_t,solana:Nt,sui:Lt,starknet:vt};function bt(s){return Rt[s]}function kt(s,r,i){return r?s.routes.some(e=>e.sourceChains.includes(r)&&e.envs.includes(i)):!0}function Ot(s,r){return s.destChains.includes(r)}function Pt(s,r){return s.supportedAssetsOut.includes(r)}class F extends m{constructor(i,e){super(i,e,t.BtcActionStatus.IDLE);A(this,"config");A(this,"chainId");A(this,"authState",{authorized:!1});A(this,"feeAuthConfig",null);const n=t.getChainType(e.destChain),a=bt(n);if(!a)throw new t.LombardError(t.ValidationErrorCode.INVALID_CHAIN,`Unsupported destination chain type: ${n} (${e.destChain})`);if(!Pt(a,e.assetOut))throw new t.LombardError(t.ValidationErrorCode.INVALID_ASSET,`Asset ${e.assetOut} is not supported for BTC staking. BTC Stake produces LBTC. For BTC.b, use BtcDeposit instead.`);if(!Ot(a,e.destChain))throw new t.LombardError(t.ValidationErrorCode.INVALID_CHAIN,`Destination chain ${e.destChain} is not supported for ${n}`);if(!kt(a,e.sourceChain,i.env))throw t.LombardError.routeNotFound({assetOut:e.assetOut,sourceChain:e.sourceChain,destChain:e.destChain,env:i.env});this.config=a,this.chainId=t.parseChainIdentifier(e.destChain)}getAddressSchema(){return this.config.addressSchema}getStatusConfig(){return{idle:t.BtcActionStatus.IDLE,ready:t.BtcActionStatus.READY,addressReady:t.BtcActionStatus.ADDRESS_READY}}getInitialSteps(){return{created:t.StepStatus.IDLE,verifying:t.StepStatus.IDLE,issuing:t.StepStatus.IDLE}}isAuthorized(){return this.authState.authorized}getChainId(){return this.chainId}getDepositAddressParams(){var n;const i=this.ensureRecipient(),e=this.getActiveSignature();if(!e)throw new t.LombardError(t.ValidationErrorCode.INVALID_PARAMETER,"Missing signature. Complete authorization first.");return{address:e.paddedAddress??i,chainId:this.chainId,signature:e.signature,token:this.getExpectedToken(),eip712Data:(n=this.authState.networkFee)==null?void 0:n.typedData,pubKey:e.pubKey,partnerId:this.ctx.partner.getPartnerId(),referrerCode:this._referralCode}}getExpectedToken(){return D(this.params.assetOut,p.Token.LBTC)}getAuthRequiredMessage(){return"Authorization required. Call authorize() first."}get mintingFee(){return this.authState.mintingFee}async prepare(i){return this.assertStatus(t.BtcActionStatus.IDLE,"prepare"),this.act(async()=>{const e=this.validatePrepareParams(i);if(this._amount=e.amount,this._recipient=e.recipient,this._referralCode=e.referralCode,this.feeAuthConfig=this.config.getFeeAuthConfig(this.params.destChain),await this.resumeFromExistingDeposit(e.recipient)){if(this.feeAuthConfig){const a=await this.feeAuthConfig.restoreFeeSignature(this.ctx,this.chainId,e.recipient);if(!(a!=null&&a.hasSignature)){this.authState.mintingFee=await this.feeAuthConfig.getMintingFee(this.ctx,this.chainId),this.updateStatus(t.BtcActionStatus.NEEDS_FEE_AUTHORIZATION),this.emitInitialProgress();return}a.signature&&(this.authState.networkFee={signature:a.signature,typedData:a.typedData}),this.authState.authorized=!0}this.updateStatus(t.BtcActionStatus.ADDRESS_READY),this.emitInitialProgress();return}if(this.feeAuthConfig){const a=await this.feeAuthConfig.restoreFeeSignature(this.ctx,this.chainId,e.recipient);if(a!=null&&a.hasSignature){a.signature&&(this.authState.networkFee={signature:a.signature,typedData:a.typedData}),this.authState.authorized=!0,this.updateStatus(t.BtcActionStatus.READY),this.emitInitialProgress();return}this.authState.mintingFee=await this.feeAuthConfig.getMintingFee(this.ctx,this.chainId),this.updateStatus(t.BtcActionStatus.NEEDS_FEE_AUTHORIZATION)}else this.updateStatus(t.BtcActionStatus.NEEDS_ADDRESS_CONFIRMATION);this.emitInitialProgress()})}async authorize(){if(this.assertStatus([t.BtcActionStatus.NEEDS_FEE_AUTHORIZATION,t.BtcActionStatus.NEEDS_ADDRESS_CONFIRMATION,t.BtcActionStatus.READY],"authorize"),this.status===t.BtcActionStatus.READY)return;const i=this.ensureRecipient(),e=this.feeAuthConfig!==null;return this.act(async()=>{if(e){const n=this.ensureMintingFee(),a=await this.feeAuthConfig.authorizeFee(this.ctx,{chainId:this.chainId,recipient:i,fee:n});this.authState.networkFee={signature:a.signature,typedData:a.typedData}}else this.authState.destinationSignature=await this.config.getSignature(this.ctx,i,this.chainId);this.authState.authorized=!0},t.BtcActionStatus.READY)}async generateDepositAddress(){if(this.assertStatus(t.BtcActionStatus.READY,"generateDepositAddress"),this.ensureAuthorized(),this._depositAddress)return this._depositAddress;if(!this.getActiveSignature()){const i=await this.config.getSignature(this.ctx,this.ensureRecipient(),this.chainId);this.authState.destinationSignature=i}return this.act(async()=>{const i=this.getDepositAddressParams(),e=await this.ctx.api.generateDepositAddress(i);return I(e),this._depositAddress=e,this.emitProgress({status:t.BtcActionStatus.ADDRESS_READY,steps:{created:t.StepStatus.COMPLETE,verifying:t.StepStatus.IDLE,issuing:t.StepStatus.IDLE},metadata:{depositAddress:e}}),e},t.BtcActionStatus.ADDRESS_READY)}async execute(){return this.executeImpl()}async monitorDeposit(){return super.monitorDeposit()}ensureMintingFee(){if(!this.authState.mintingFee)throw new t.LombardError(t.ValidationErrorCode.INVALID_PARAMETER,"Minting fee not fetched. Call prepare() first.");return this.authState.mintingFee}getActiveSignature(){var i;return(i=this.authState.networkFee)!=null&&i.signature?{signature:this.authState.networkFee.signature}:this.authState.destinationSignature}}class x extends m{constructor(i,e){super(i,e,t.BtcActionStatus.IDLE);A(this,"chainId");A(this,"authState",{authorized:!1});if(!ht(e.assetOut))throw new t.LombardError(t.ValidationErrorCode.INVALID_ASSET,`Asset ${e.assetOut} is not supported for stake and deploy. StakeAndDeploy produces LBTC which is then deployed to a vault.`);if(!ct(e.destChain))throw new t.LombardError(t.ValidationErrorCode.INVALID_CHAIN,`Destination chain ${e.destChain} is not supported for stake and deploy`);if(!k(e.protocol))throw new t.LombardError(t.ValidationErrorCode.INVALID_PARAMETER,`Protocol ${e.protocol} is not supported for stake and deploy`);if(!pt(e.sourceChain,i.env))throw t.LombardError.routeNotFound({assetOut:e.assetOut,sourceChain:e.sourceChain,destChain:e.destChain,env:i.env});const n=t.parseChainIdentifier(e.destChain);if(typeof n!="number"||!p.isValidChain(n))throw new t.LombardError(t.ValidationErrorCode.INVALID_CHAIN,`Unsupported EVM chain: ${e.destChain}`);this.chainId=n}getAddressSchema(){return S.addressSchema}getStatusConfig(){return{idle:t.BtcActionStatus.IDLE,ready:t.BtcActionStatus.READY,addressReady:t.BtcActionStatus.ADDRESS_READY}}getInitialSteps(){return{created:t.StepStatus.IDLE,verifying:t.StepStatus.IDLE,issuing:t.StepStatus.IDLE,depositing:t.StepStatus.IDLE}}isAuthorized(){return this.authState.authorized}getChainId(){return this.chainId}getDepositAddressParams(){return{address:this.ensureRecipient(),chainId:this.chainId,signature:this.authState.signature,token:this.getExpectedToken(),signatureData:this.authState.typedData,partnerId:this.ctx.partner.getPartnerId(),referrerCode:this._referralCode}}getExpectedToken(){return D(this.params.assetOut,p.Token.LBTC)}getAuthRequiredMessage(){return"Deposit authorization required. Call authorizeDeposit() first."}get fee(){return this.authState.fee}async prepare(i){return this.assertStatus(t.BtcActionStatus.IDLE,"prepare"),this.act(async()=>{const e=this.validatePrepareParams(i);if(this._amount=e.amount,this._recipient=e.recipient,this._referralCode=e.referralCode,this.authState.fee=await S.getStakeAndBakeFee(this.ctx,this.chainId,this.params.protocol),await this.resumeFromExistingDeposit(e.recipient)){const o=await S.restoreStakeAndBakeSignature(this.ctx,this.chainId,e.recipient);if(o!=null&&o.hasSignature){o.signature&&(this.authState.signature=o.signature),this.authState.authorized=!0,this.updateStatus(t.BtcActionStatus.ADDRESS_READY),this.emitInitialProgress();return}this.updateStatus(t.BtcActionStatus.NEEDS_DEPLOY_AUTHORIZATION),this.emitInitialProgress();return}const a=await S.restoreStakeAndBakeSignature(this.ctx,this.chainId,e.recipient);if(a!=null&&a.hasSignature){a.signature&&(this.authState.signature=a.signature),this.authState.authorized=!0,this.updateStatus(t.BtcActionStatus.READY),this.emitInitialProgress();return}this.updateStatus(t.BtcActionStatus.NEEDS_DEPLOY_AUTHORIZATION),this.emitInitialProgress()})}async authorizeDeposit(){if(this.assertStatus([t.BtcActionStatus.NEEDS_DEPLOY_AUTHORIZATION,t.BtcActionStatus.READY],"authorizeDeposit"),this.status===t.BtcActionStatus.READY)return;const i=this.ensureRecipient(),e=this.ensureAmount();return this.act(async()=>{const n=l.toSatoshi(e),a=this.params.assetIn??h.AssetId.BTC,o=await S.authorizeStakeAndBake(this.ctx,{chainId:this.chainId,recipient:i,amount:n.toString(),vaultKey:At(this.params.protocol),token:a});this.authState.signature=o.signature,this.authState.typedData=o.typedData,this.authState.authorized=!0},t.BtcActionStatus.READY)}async generateDepositAddress(){return this.assertStatus(t.BtcActionStatus.READY,"generateDepositAddress"),this.ensureAuthorized(),this._depositAddress?this._depositAddress:this.act(async()=>{const i=this.getDepositAddressParams(),e=await this.ctx.api.generateDepositAddress(i);return I(e),this._depositAddress=e,this.emitProgress({status:t.BtcActionStatus.ADDRESS_READY,steps:{created:t.StepStatus.COMPLETE,verifying:t.StepStatus.IDLE,issuing:t.StepStatus.IDLE,depositing:t.StepStatus.IDLE},metadata:{depositAddress:e}}),e},t.BtcActionStatus.ADDRESS_READY)}async execute(){return this.act(async()=>{this.assertStatus(t.BtcActionStatus.ADDRESS_READY,"execute"),this._depositAddress||await this.generateDepositAddress();const i=this.ensureDepositAddress(),e=await this.trySendBitcoin(i);return e?{depositAddress:i,txHash:e}:{depositAddress:i}})}async monitorDeposit(){const i=this._depositAddress,e=this._recipient;if(!i||!e)throw t.LombardError.missingParameter("depositAddress or recipient");return await y({network:this.bitcoinNetwork,btcService:this.ctx.btc,fetchDeposit:async()=>{const o=(await this.ctx.api.getDeposits(e)).find(c=>c.depositAddress===i);if(o)return{blockHeight:o.blockHeight,isClaimed:o.isClaimed}},onProgress:a=>{this.emitProgress({status:this.status,steps:{created:t.StepStatus.COMPLETE,verifying:a.hasEnoughConfirmations?t.StepStatus.COMPLETE:t.StepStatus.PENDING,issuing:a.isClaimed?t.StepStatus.COMPLETE:t.StepStatus.PENDING,depositing:t.StepStatus.PENDING},confirmations:a.confirmations,requiredConfirmations:a.requiredConfirmations,metadata:{isClaimed:a.isClaimed}})},onComplete:()=>{this.emitCompleted()}})}}class M{constructor(r){A(this,"ctx");this.ctx=t.createBtcCoreContext(r)}stake(r){return new F(this.ctx,r)}stakeAndDeploy(r){return new x(this.ctx,r)}deposit(r){return new b(this.ctx,r)}depositAndDeploy(r){return new P(this.ctx,r)}}function Ft(s){return new M(s)}exports.BtcActions=M;exports.BtcDeposit=b;exports.BtcDepositAndDeploy=P;exports.BtcStake=F;exports.BtcStakeAndDeploy=x;exports.btcActions=Ft;exports.btcModule=Q;
|
|
2
|
+
//# sourceMappingURL=BtcActions-ByhBml_1.cjs.map
|