@lombard.finance/sdk 4.4.0 → 4.4.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +8 -0
- package/dist/api-functions/getDepositsByAddress/getDepositsByAddress.d.ts +13 -1
- package/dist/api-functions/getDepositsByAddress/getDepositsByAddress.d.ts.map +1 -1
- package/dist/api.cjs +1 -1
- package/dist/api.js +1 -1
- package/dist/btc.cjs +1 -1
- package/dist/btc.js +2 -2
- package/dist/chunks/{BtcActions-BOVJrdTI.cjs → BtcActions-BIBsbYIt.cjs} +2 -2
- package/dist/chunks/{BtcActions-BOVJrdTI.cjs.map → BtcActions-BIBsbYIt.cjs.map} +1 -1
- package/dist/chunks/{BtcActions-_a8r3Q7c.js → BtcActions-Df41lbsb.js} +2 -2
- package/dist/chunks/{BtcActions-_a8r3Q7c.js.map → BtcActions-Df41lbsb.js.map} +1 -1
- package/dist/chunks/{EvmActions-D4vFpbYk.js → EvmActions-5lPqhRaM.js} +2 -2
- package/dist/chunks/{EvmActions-D4vFpbYk.js.map → EvmActions-5lPqhRaM.js.map} +1 -1
- package/dist/chunks/{EvmActions-VrDbgMDy.cjs → EvmActions-BY_18gTg.cjs} +2 -2
- package/dist/chunks/{EvmActions-VrDbgMDy.cjs.map → EvmActions-BY_18gTg.cjs.map} +1 -1
- package/dist/chunks/ReferralsClient-Cmrjo9bN.cjs.map +1 -1
- package/dist/chunks/ReferralsClient-DvEsA3II.js.map +1 -1
- package/dist/chunks/depositStatus-CFo5jW89.cjs +2 -0
- package/dist/chunks/depositStatus-CFo5jW89.cjs.map +1 -0
- package/dist/chunks/{depositStatus-05_X7FVs.js → depositStatus-DTc01ZoZ.js} +42 -40
- package/dist/chunks/depositStatus-DTc01ZoZ.js.map +1 -0
- package/dist/chunks/{events-5c8IHjEF.cjs → events-6PV6NP-o.cjs} +2 -2
- package/dist/chunks/{events-5c8IHjEF.cjs.map → events-6PV6NP-o.cjs.map} +1 -1
- package/dist/chunks/{events-rgJZNpHd.js → events-BvRwXePq.js} +4 -4
- package/dist/chunks/{events-rgJZNpHd.js.map → events-BvRwXePq.js.map} +1 -1
- package/dist/chunks/{statusConstants-Zii1786K.js → statusConstants-C4YNx2q0.js} +2 -2
- package/dist/chunks/{statusConstants-Zii1786K.js.map → statusConstants-C4YNx2q0.js.map} +1 -1
- package/dist/chunks/{statusConstants-Cri7yswV.cjs → statusConstants-DlM2oPfW.cjs} +2 -2
- package/dist/chunks/{statusConstants-Cri7yswV.cjs.map → statusConstants-DlM2oPfW.cjs.map} +1 -1
- package/dist/core.cjs +1 -1
- package/dist/core.js +4 -4
- package/dist/evm.cjs +1 -1
- package/dist/evm.js +2 -2
- package/dist/index.cjs +1 -1
- package/dist/index.js +5 -5
- package/dist/shared/deposits/depositStatus.d.ts +9 -5
- package/dist/shared/deposits/depositStatus.d.ts.map +1 -1
- package/package.json +1 -1
- package/dist/chunks/depositStatus-05_X7FVs.js.map +0 -1
- package/dist/chunks/depositStatus-CUjHpXFJ.cjs +0 -2
- package/dist/chunks/depositStatus-CUjHpXFJ.cjs.map +0 -1
package/CHANGELOG.md
CHANGED
|
@@ -1,3 +1,11 @@
|
|
|
1
|
+
# 4.4.1
|
|
2
|
+
|
|
3
|
+
- Fixed `getDepositStatus()` never returning `'expired'` despite the backend setting `SESSION_STATE_EXPIRED` on the deposit's `sessionState` field. The expired check is now correctly placed after `failed` and `auto_claimed` so that more definitive terminal states take priority.
|
|
4
|
+
- Deprecated `MIN_CLAIM_AMOUNT_BTC` in favour of `MIN_STAKE_AMOUNT_BTC`. Both constants are identical (`0.0002` BTC) — `MIN_CLAIM_AMOUNT_BTC` is now a re-export alias and will be removed in a future major version.
|
|
5
|
+
- Improved `isNative` JSDoc on the `Deposit` type to clarify that `false` means a Bitcoin mainnet direct deposit and `true` means an EVM/alt-chain native deposit.
|
|
6
|
+
|
|
7
|
+
---
|
|
8
|
+
|
|
1
9
|
# 4.4.0
|
|
2
10
|
|
|
3
11
|
- Added Solana destination support for BTC deposits, including destination signing and route configuration for Solana chains.
|
|
@@ -130,7 +130,19 @@ export interface DirectDepositsResponse {
|
|
|
130
130
|
* Direct BTC Deposits or Native Deposits APIs.
|
|
131
131
|
*/
|
|
132
132
|
export interface Deposit {
|
|
133
|
-
/**
|
|
133
|
+
/**
|
|
134
|
+
* Whether this deposit originates from the Native Deposits API (EVM/alt-chain source).
|
|
135
|
+
*
|
|
136
|
+
* - `false` — Bitcoin mainnet direct deposit: the user sent BTC directly to a
|
|
137
|
+
* Lombard deposit address. This is the most common case for BTC stakers.
|
|
138
|
+
* - `true` — Native deposit: the deposit originated on an EVM or alt-chain
|
|
139
|
+
* (e.g. a chain using Lombard's native deposits flow).
|
|
140
|
+
*
|
|
141
|
+
* When polling for standard BTC deposit status, filter on `isNative === false`.
|
|
142
|
+
*
|
|
143
|
+
* @remarks A rename to a more descriptive field (e.g. `depositSource`) is
|
|
144
|
+
* planned in a future major version to avoid confusion with "native BTC".
|
|
145
|
+
*/
|
|
134
146
|
isNative: boolean;
|
|
135
147
|
/** Transaction hash on the source blockchain. */
|
|
136
148
|
txHash: string;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"getDepositsByAddress.d.ts","sourceRoot":"","sources":["../../../src/api-functions/getDepositsByAddress/getDepositsByAddress.ts"],"names":[],"mappings":"AACA,OAAO,SAAS,MAAM,cAAc,CAAC;AAIrC,OAAO,EACL,OAAO,EACP,WAAW,EACX,eAAe,EACf,QAAQ,EACT,MAAM,qBAAqB,CAAC;AAC7B,OAAO,EAAE,SAAS,EAAE,MAAM,yBAAyB,CAAC;AACpD,OAAO,EAGL,KAAK,EACN,MAAM,8BAA8B,CAAC;AAYtC,KAAK,OAAO,GAAG,MAAM,CAAC;AAEtB;;GAEG;AACH,oBAAY,mBAAmB;IAC7B,uCAAuC;IACvC,+BAA+B,oCAAoC;IAEnE,iFAAiF;IACjF,2BAA2B,gCAAgC;IAE3D,sDAAsD;IACtD,6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tB
|
|
1
|
+
{"version":3,"file":"getDepositsByAddress.d.ts","sourceRoot":"","sources":["../../../src/api-functions/getDepositsByAddress/getDepositsByAddress.ts"],"names":[],"mappings":"AACA,OAAO,SAAS,MAAM,cAAc,CAAC;AAIrC,OAAO,EACL,OAAO,EACP,WAAW,EACX,eAAe,EACf,QAAQ,EACT,MAAM,qBAAqB,CAAC;AAC7B,OAAO,EAAE,SAAS,EAAE,MAAM,yBAAyB,CAAC;AACpD,OAAO,EAGL,KAAK,EACN,MAAM,8BAA8B,CAAC;AAYtC,KAAK,OAAO,GAAG,MAAM,CAAC;AAEtB;;GAEG;AACH,oBAAY,mBAAmB;IAC7B,uCAAuC;IACvC,+BAA+B,oCAAoC;IAEnE,iFAAiF;IACjF,2BAA2B,gCAAgC;IAE3D,sDAAsD;IACtD,6BAA6B,kCAAkC;IAE/D,yDAAyD;IACzD,oCAAoC,yCAAyC;IAE7E,sCAAsC;IACtC,0BAA0B,+BAA+B;IAEzD,kDAAkD;IAClD,+BAA+B,oCAAoC;CACpE;AAED;;GAEG;AACH,oBAAY,aAAa;IACvB,8CAA8C;IAC9C,yBAAyB,8BAA8B;IAEvD,mCAAmC;IACnC,qBAAqB,0BAA0B;IAE/C,yCAAyC;IACzC,uBAAuB,4BAA4B;IAEnD,6CAA6C;IAC7C,qBAAqB,0BAA0B;CAChD;AAED,MAAM,WAAW,aAAa;IAC5B,gDAAgD;IAChD,OAAO,EAAE,MAAM,CAAC;IAEhB,wEAAwE;IACxE,WAAW,EAAE,MAAM,CAAC;IAEpB,6DAA6D;IAC7D,eAAe,EAAE,MAAM,CAAC;IAExB,wCAAwC;IACxC,aAAa,EAAE,MAAM,CAAC;IAEtB,yCAAyC;IACzC,YAAY,EAAE,MAAM,CAAC;IAErB,gDAAgD;IAChD,UAAU,EAAE,MAAM,CAAC;IAEnB,yDAAyD;IACzD,gBAAgB,EAAE,MAAM,CAAC;IAEzB,oDAAoD;IACpD,YAAY,EAAE,MAAM,CAAC;IAErB,6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ReferralsClient-Cmrjo9bN.cjs"),s=require("./chunks/getUserStakeAndBakeSignature-CSEyzgMc.cjs"),r=require("./chunks/get-exchange-ratio-BEhD4gLB.cjs"),t=require("./chunks/depositStatus-
|
|
1
|
+
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const e=require("./chunks/ReferralsClient-Cmrjo9bN.cjs"),s=require("./chunks/getUserStakeAndBakeSignature-CSEyzgMc.cjs"),r=require("./chunks/get-exchange-ratio-BEhD4gLB.cjs"),t=require("./chunks/depositStatus-CFo5jW89.cjs"),i=require("./chunks/storeNetworkFeeSignature-Buk4091C.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,7 +1,7 @@
|
|
|
1
1
|
import { ENotarizationStatus as s, ESessionState as o, PayoutTxStatus as r, ReferralsClient as i, fetchBTCbDeposits as a, fetchDirectDeposits as n, fetchUnstakesByAddress as g, getDepositBtcAddress as d, getDepositBtcAddresses as p, getDepositsByAddress as S, getLuxSeason1Points as D, getLuxSeason2Points as A, getPointsByAddress as c, getUnstakesByAddress as f, storeStakeAndBakeSignature as u } from "./chunks/ReferralsClient-DvEsA3II.js";
|
|
2
2
|
import { SANCTIONED_ADDRESS as x, generateDepositBtcAddress as C, getUserStakeAndBakeSignature as m } from "./chunks/getUserStakeAndBakeSignature-Su-k10ap.js";
|
|
3
3
|
import { getExchangeRatio as R } from "./chunks/get-exchange-ratio-B-xzYND1.js";
|
|
4
|
-
import { MIN_CLAIM_AMOUNT_BTC as l, REQUIRED_CONFIRMATIONS as E, calcConfirmations as T, depositRequiresAction as y, getConfirmationProgress as I, getDepositStatus as P, getDepositStatusDisplay as h, getLBTCExchangeRate as U, isDepositClaimable as _, isDepositPending as L, isDepositTerminal as M, setReferral as O } from "./chunks/depositStatus-
|
|
4
|
+
import { MIN_CLAIM_AMOUNT_BTC as l, REQUIRED_CONFIRMATIONS as E, calcConfirmations as T, depositRequiresAction as y, getConfirmationProgress as I, getDepositStatus as P, getDepositStatusDisplay as h, getLBTCExchangeRate as U, isDepositClaimable as _, isDepositPending as L, isDepositTerminal as M, setReferral as O } from "./chunks/depositStatus-DTc01ZoZ.js";
|
|
5
5
|
import { getNetworkFeeSignature as b, storeNetworkFeeSignature as w } from "./chunks/storeNetworkFeeSignature-BODIpq3Y.js";
|
|
6
6
|
export {
|
|
7
7
|
s as ENotarizationStatus,
|
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-BIBsbYIt.cjs"),c=require("./chunks/statusConstants-DlM2oPfW.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 { BtcActions as c, BtcDeposit as e, BtcDepositAndDeploy as p, BtcStake as B, BtcStakeAndDeploy as i, btcActions as n, btcModule as s } from "./chunks/BtcActions-
|
|
2
|
-
import { BtcActionStatus as r } from "./chunks/statusConstants-
|
|
1
|
+
import { BtcActions as c, BtcDeposit as e, BtcDepositAndDeploy as p, BtcStake as B, BtcStakeAndDeploy as i, btcActions as n, btcModule as s } from "./chunks/BtcActions-Df41lbsb.js";
|
|
2
|
+
import { BtcActionStatus as r } from "./chunks/statusConstants-C4YNx2q0.js";
|
|
3
3
|
export {
|
|
4
4
|
r as BtcActionStatus,
|
|
5
5
|
c 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 p=(s,r,i)=>H(s,typeof r!="symbol"?r+"":r,i);const Y=require("axios"),t=require("./statusConstants-Cri7yswV.cjs"),A=require("./token-addresses-nzvTOi24.cjs"),u=require("./index-BKzxeh1Y.cjs"),l=require("./tokens-BkvA0Gp1.cjs"),D=require("./satoshi-CZEsHl5X.cjs"),c=require("./defi-registry-DDNavtO1.cjs"),R=require("./getUserStakeAndBakeSignature-CSEyzgMc.cjs"),$=require("./config-DmCmanM_.cjs"),q=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 j(s){const{code:r,message:i}=s;throw r===U?new Error(G):new Error(i)}const K={mempoolApiUrl:"https://mempool.space/signet"},Z={mempoolApiUrl:"https://mempool.space"},W=s=>s==="mainnet"?Z:K;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:a}=await Y.get(e);return a.height}catch(a){j(a)}}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:a=6,onProgress:n,onComplete:o}=s,h=await r();if(!h)return;const d=h.blockHeight;if(typeof d!="number")return;const T=await e.getCurrentBlockHeight(i),_=Math.max(0,T-d),N=_>=a,w=h.isClaimed??!1,B={confirmations:_,requiredConfirmations:a,hasEnoughConfirmations:N,isClaimed:w,steps:{created:t.StepStatus.COMPLETE,verifying:N?t.StepStatus.COMPLETE:t.StepStatus.PENDING,issuing:w?t.StepStatus.COMPLETE:t.StepStatus.PENDING}};return n==null||n(B),w&&(o==null||o()),B}function f(s){if(s===R.SANCTIONED_ADDRESS)throw new t.LombardError(t.ValidationErrorCode.INVALID_PARAMETER,"Destination address is under sanctions")}class I extends t.BaseAction{constructor(i,e,a){super(a);p(this,"_amount");p(this,"_recipient");p(this,"_depositAddress");p(this,"_referralCode");p(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(i){const e=this.getStatusConfig();return this.assertStatus(e.ready,"generateDepositAddress"),this.ensureAuthorized(),this._depositAddress?this._depositAddress:this.act(async()=>{const a=this.getDepositAddressParams(i),n=await this.ctx.api.generateDepositAddress(a);f(n),this._depositAddress=n;const o=this.getInitialSteps(),h=Object.fromEntries(Object.entries(o).map(([d],T)=>[d,T===0?t.StepStatus.COMPLETE:t.StepStatus.IDLE]));return this.emitProgress({status:e.addressReady,steps:h,metadata:{depositAddress:n}}),n},e.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(),a=await this.trySendBitcoin(e);return a?{depositAddress:e,txHash:a}:{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(h=>h.depositAddress===i);if(o)return{blockHeight:o.blockHeight,isClaimed:o.isClaimed}},onProgress:n=>{this.emitProgress({status:this.status,steps:n.steps,confirmations:n.confirmations,requiredConfirmations:n.requiredConfirmations,metadata:{isClaimed:n.isClaimed}})},onComplete:()=>{this.emitCompleted()}})}async trySendBitcoin(i){const e=this._amount;if(e)try{const a=await this.ctx.getProvider("bitcoin");if(!a)return;const n=a;if(n.sendBitcoin){const o=D.toSatoshi(e).toNumber();return n.sendBitcoin(i,o)}}catch{}}}function E(s,r=A.Token.LBTC){switch(s){case c.AssetId.LBTC:return A.Token.LBTC;case c.AssetId.BTCb:return A.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 A.addChain({provider:s,chainId:r}),await s.request({method:"wallet_switchEthereumChain",params:[{chainId:`0x${r.toString(16)}`}]});return}catch(a){const n=a;throw n.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: ${n.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 C(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,A.Token.BTCb)},async restoreFeeSignature(s,r,i){const e=await l.getTokenContractInfo(A.Token.BTCb,r,s.env),a=await s.api.getFeeSignature({address:i,chainId:r,tokenAddress:e.address});return!a.hasSignature||a.expirationDate&&new Date(Number(a.expirationDate)*1e3)<new Date?null:{hasSignature:!0,signature:a.signature,typedData:a.typedData}},async authorizeFee(s,{chainId:r,recipient:i,fee:e}){const a=s.capabilities.require("evm"),n=await s.getProvider("evm");if(!n)throw t.LombardError.providerMissing(String(r),"evm");await C(n,r);const o=D.toSatoshi(e).toString(),h=await l.getTokenContractInfo(A.Token.BTCb,r,s.env),d=await a.signNetworkFee({fee:o,account:i,chainId:r,provider:n,token:A.Token.BTCb});return await s.api.storeFeeSignature({address:i,signature:d.signature,typedData:d.typedData,tokenAddress:h.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(c.AssetId.BTCb).filter(s=>t.isEvmChain(s)),supportedAssetsOut:[c.AssetId.BTCb],addressSchema:t.evmAddressSchema,getFeeAuthConfig(s){return st.includes(s)?it:null},async signDestination(s,r,i){const e=s.capabilities.require("evm"),a=await s.getProvider("evm");if(!a)throw t.LombardError.providerMissing(String(i),"evm");return await C(a,i),{signature:(await e.signLbtcDestination({address:r,chainId:i,provider:a})).signature}}},m=s=>`${s}${t.CAIP2_SEPARATOR}`;function nt(s){return String(s).startsWith(m(t.CHAIN_PREFIXES.EIP155))}function b(s){return String(s).startsWith(m(t.CHAIN_PREFIXES.SOLANA))}function at(s){return String(s).startsWith(m(t.CHAIN_PREFIXES.SUI))}function ot(s){return String(s).startsWith(m(t.CHAIN_PREFIXES.STARKNET))}function ut(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 dt={chainType:"solana",routes:[{sourceChains:[t.Chain.BITCOIN_SIGNET],envs:[u.r.stage,u.r.dev]}],destChains:t.getAllAssetChains(c.AssetId.BTCb).filter(s=>b(s)),supportedAssetsOut:[c.AssetId.BTCb],addressSchema:t.solanaAddressSchema,getFeeAuthConfig:()=>null,async signDestination(s,r,i){const e=s.capabilities.require("solana"),a=ut(i),{signature:n}=await e.signLbtcDestination({network:a});return{signature:n}}},ct={evm:rt,solana:dt};function ht(s){return ct[s]}function pt(s,r){return s.destChains.includes(r)}function At(s,r){return s.supportedAssetsOut.includes(r)}function St(s,r,i){return s.routes.some(e=>e.envs.includes(i)&&(!r||e.sourceChains.includes(r)))}class k extends I{constructor(i,e){super(i,e,t.BtcActionStatus.IDLE);p(this,"config");p(this,"chainId");p(this,"authState",{authorized:!1});p(this,"feeAuthConfig",null);const a=t.getChainType(e.destChain),n=ht(a);if(!n)throw new t.LombardError(t.ValidationErrorCode.INVALID_CHAIN,`Unsupported destination chain type: ${a} (${e.destChain})`);if(!At(n,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(!pt(n,e.destChain))throw new t.LombardError(t.ValidationErrorCode.INVALID_CHAIN,`Destination chain ${e.destChain} is not supported for ${a} BTC deposits`);if(!St(n,e.sourceChain,i.env))throw t.LombardError.routeNotFound({assetOut:e.assetOut,sourceChain:e.sourceChain,destChain:e.destChain,env:i.env});this.config=n,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}get mintingFee(){return this.authState.mintingFee}getDepositAddressParams(i){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,captchaToken:i}}async generateDepositAddress(i){if(!this.authState.signature){const e=await this.config.signDestination(this.ctx,this.ensureRecipient(),this.chainId);this.authState.signature=e.signature,this.authState.typedData=e.typedData}return this.generateDepositAddressImpl(i)}getExpectedToken(){return E(this.params.assetOut,A.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=this.config.getFeeAuthConfig(this.params.destChain),await this.resumeFromExistingDeposit(e.recipient)){if(this.feeAuthConfig){const n=await this.feeAuthConfig.restoreFeeSignature(this.ctx,this.chainId,e.recipient);if(!(n!=null&&n.hasSignature)){this.authState.mintingFee=await this.feeAuthConfig.getMintingFee(this.ctx,this.chainId),this.updateStatus(t.BtcActionStatus.NEEDS_FEE_AUTHORIZATION),this.emitInitialProgress();return}n.signature&&(this.authState.signature=n.signature,this.authState.typedData=n.typedData),this.authState.authorized=!0}this.updateStatus(t.BtcActionStatus.ADDRESS_READY),this.emitInitialProgress();return}if(this.feeAuthConfig){const n=await this.feeAuthConfig.restoreFeeSignature(this.ctx,this.chainId,e.recipient);if(n!=null&&n.hasSignature){n.signature&&(this.authState.signature=n.signature,this.authState.typedData=n.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 this.config.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 gt=$.VEDA_VAULT_STAKE_AND_BAKE_CHAINS.map(s=>t.evmChainIdToChain(s)),Ct={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:gt,supportedAssetsOut:[c.AssetId.LBTC],supportedProtocols:yt(c.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:a,token:n}){const o=s.capabilities.require("evm"),h=await s.getProvider("evm");if(!h)throw t.LombardError.providerMissing(String(r),"evm");await C(h,r);const d=await o.signStakeAndBake({value:e,account:i,chainId:r,provider:h,vaultKey:a,token:n});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=Ct;function Et(s){return S.destChains.includes(s)}function Dt(s){return S.supportedAssetsOut.includes(s)}function lt(s,r){return s?S.routes.some(i=>i.sourceChains.includes(s)&&i.envs.includes(r)):!0}function O(s){return s in c.DEFI_REGISTRY}function ft(s){if(!O(s)){const r=Object.keys(c.DEFI_REGISTRY).join(", ");throw new Error(`Unsupported protocol: ${s}. Supported protocols: ${r}`)}return s}function It(s){return Object.entries(c.DEFI_REGISTRY).filter(([r,i])=>s in i).map(([r])=>r)}const v={mainnet:[t.Chain.AVALANCHE],testnet:[t.Chain.AVALANCHE_FUJI]},mt={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:[c.AssetId.BTCb],supportedProtocols:It(c.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:a,token:n}){const o=s.capabilities.require("evm"),h=await s.getProvider("evm");if(!h)throw t.LombardError.providerMissing(String(r),"evm");await C(h,r);const d=await o.signStakeAndBake({value:e,account:i,chainId:r,provider:h,vaultKey:a,token:n});return await s.api.storeStakeAndBakeSignature({signature:d.signature,typedData:d.typedData}),{signature:d.signature,typedData:d.typedData,approvalTxHash:d.approvalTxHash}}},g=mt;function Tt(s){return g.destChains.includes(s)}function wt(s){return g.supportedAssetsOut.includes(s)}function P(s){return s in c.DEFI_REGISTRY}function L(s){if(!P(s)){const r=Object.keys(c.DEFI_REGISTRY).join(", ");throw new Error(`Unsupported protocol: ${s}. Supported protocols: ${r}`)}return s}function yt(s){return Object.entries(c.DEFI_REGISTRY).filter(([r,i])=>s in i).map(([r])=>r)}function _t(s,r){return g.routes.some(i=>i.sourceChains.includes(s)&&i.envs.includes(r))}class F extends I{constructor(i,e){super(i,e,t.BtcActionStatus.IDLE);p(this,"chainId");p(this,"authState",{authorized:!1});if(!wt(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(!Tt(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(!P(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 a=e.sourceChain??t.Chain.BITCOIN_MAINNET;if(!_t(a,i.env))throw t.LombardError.routeNotFound({assetOut:e.assetOut,sourceChain:a,destChain:e.destChain,env:i.env});const n=t.parseChainIdentifier(e.destChain);if(typeof n!="number"||!A.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,wrapping:t.StepStatus.IDLE,depositing:t.StepStatus.IDLE}}isAuthorized(){return this.authState.authorized}getChainId(){return this.chainId}getDepositAddressParams(i){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,captchaToken:i}}getExpectedToken(){return E(this.params.assetOut,A.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 g.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 a=D.toSatoshi(e),n=E(this.params.assetOut,A.Token.BTCb),o=await g.authorizeDepositAndDeploy(this.ctx,{chainId:this.chainId,recipient:i,amount:a.toString(),vaultKey:L(this.params.protocol),token:n});this.authState.signature=o.signature,this.authState.typedData=o.typedData,this.authState.authorized=!0},t.BtcActionStatus.READY)}async generateDepositAddress(i){return this.assertStatus(t.BtcActionStatus.READY,"generateDepositAddress"),this.ensureAuthorized(),this._depositAddress?this._depositAddress:this.act(async()=>{const e=this.getDepositAddressParams(i),a=await this.ctx.api.generateDepositAddress(e);return f(a),this._depositAddress=a,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:a}}),a},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(h=>h.depositAddress===i);if(o)return{blockHeight:o.blockHeight,isClaimed:o.isClaimed}},onProgress:n=>{this.emitProgress({status:this.status,steps:{created:t.StepStatus.COMPLETE,verifying:n.hasEnoughConfirmations?t.StepStatus.COMPLETE:t.StepStatus.PENDING,wrapping:n.isClaimed?t.StepStatus.COMPLETE:t.StepStatus.PENDING,depositing:t.StepStatus.PENDING},confirmations:n.confirmations,requiredConfirmations:n.requiredConfirmations,metadata:{isClaimed:n.isClaimed}})},onComplete:()=>{this.emitCompleted()}})}}const Nt=[t.Chain.ETHEREUM,t.Chain.SEPOLIA],Bt={async getMintingFee(s,r){return s.capabilities.require("evm").getMintingFee(r)},async restoreFeeSignature(s,r,i){const e=await l.getTokenContractInfo(A.Token.LBTC,r,s.env),a=await s.api.getFeeSignature({address:i,chainId:r,tokenAddress:e.address});return!a.hasSignature||a.expirationDate&&new Date(Number(a.expirationDate)*1e3)<new Date?null:{hasSignature:!0,signature:a.signature,typedData:a.typedData}},async authorizeFee(s,{chainId:r,recipient:i,fee:e}){const a=s.capabilities.require("evm"),n=await s.getProvider("evm");if(!n)throw t.LombardError.providerMissing(String(r),"evm");await C(n,r);const o=D.toSatoshi(e).toString(),h=await l.getTokenContractInfo(A.Token.LBTC,r,s.env),d=await a.signNetworkFee({fee:o,account:i,chainId:r,provider:n,token:A.Token.LBTC});return await s.api.storeFeeSignature({address:i,signature:d.signature,typedData:d.typedData,tokenAddress:h.address}),{signature:d.signature,typedData:d.typedData}}},vt={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(c.AssetId.LBTC).filter(s=>nt(s)),supportedAssetsOut:[c.AssetId.LBTC],addressSchema:t.evmAddressSchema,getFeeAuthConfig(s){return Nt.includes(s)?Bt:null},async getSignature(s,r,i){const e=s.capabilities.require("evm"),a=await s.getProvider("evm");if(!a)throw t.LombardError.providerMissing(String(i),"evm");return await C(a,i),e.signLbtcDestination({chainId:i,address:r,provider:a})}};function Lt(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 Rt={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(c.AssetId.LBTC).filter(s=>b(s)),supportedAssetsOut:[c.AssetId.LBTC],addressSchema:t.solanaAddressSchema,getFeeAuthConfig:()=>null,async getSignature(s,r,i){const e=s.capabilities.require("solana"),a=Lt(i),{signature:n}=await e.signLbtcDestination({network:a});return{signature:n}}},bt={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(c.AssetId.LBTC).filter(s=>ot(s)),supportedAssetsOut:[c.AssetId.LBTC],addressSchema:t.starknetAddressSchema,getFeeAuthConfig:()=>null,async getSignature(s,r,i){const e=s.capabilities.require("starknet"),{signature:a,pubKey:n}=await e.signLbtcDestination({chainId:i}),o=q.pad(r,{size:32});return{signature:a,pubKey:n,paddedAddress:o}}},kt={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(c.AssetId.LBTC).filter(s=>at(s)),supportedAssetsOut:[c.AssetId.LBTC],addressSchema:t.suiAddressSchema,getFeeAuthConfig:()=>null,async getSignature(s,r,i){const e=s.capabilities.require("sui"),{signature:a}=await e.signLbtcDestination({chainId:i});return{signature:a}}},Ot={evm:vt,solana:Rt,sui:kt,starknet:bt};function Pt(s){return Ot[s]}function Ft(s,r,i){return r?s.routes.some(e=>e.sourceChains.includes(r)&&e.envs.includes(i)):!0}function xt(s,r){return s.destChains.includes(r)}function Mt(s,r){return s.supportedAssetsOut.includes(r)}class x extends I{constructor(i,e){super(i,e,t.BtcActionStatus.IDLE);p(this,"config");p(this,"chainId");p(this,"authState",{authorized:!1});p(this,"feeAuthConfig",null);const a=t.getChainType(e.destChain),n=Pt(a);if(!n)throw new t.LombardError(t.ValidationErrorCode.INVALID_CHAIN,`Unsupported destination chain type: ${a} (${e.destChain})`);if(!Mt(n,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(!xt(n,e.destChain))throw new t.LombardError(t.ValidationErrorCode.INVALID_CHAIN,`Destination chain ${e.destChain} is not supported for ${a}`);if(!Ft(n,e.sourceChain,i.env))throw t.LombardError.routeNotFound({assetOut:e.assetOut,sourceChain:e.sourceChain,destChain:e.destChain,env:i.env});this.config=n,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(i){var n;const e=this.ensureRecipient(),a=this.getActiveSignature();if(!a)throw new t.LombardError(t.ValidationErrorCode.INVALID_PARAMETER,"Missing signature. Complete authorization first.");return{address:a.paddedAddress??e,chainId:this.chainId,signature:a.signature,token:this.getExpectedToken(),eip712Data:(n=this.authState.networkFee)==null?void 0:n.typedData,pubKey:a.pubKey,partnerId:this.ctx.partner.getPartnerId(),referrerCode:this._referralCode,captchaToken:i}}getExpectedToken(){return E(this.params.assetOut,A.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 n=await this.feeAuthConfig.restoreFeeSignature(this.ctx,this.chainId,e.recipient);if(!(n!=null&&n.hasSignature)){this.authState.mintingFee=await this.feeAuthConfig.getMintingFee(this.ctx,this.chainId),this.updateStatus(t.BtcActionStatus.NEEDS_FEE_AUTHORIZATION),this.emitInitialProgress();return}n.signature&&(this.authState.networkFee={signature:n.signature,typedData:n.typedData}),this.authState.authorized=!0}this.updateStatus(t.BtcActionStatus.ADDRESS_READY),this.emitInitialProgress();return}if(this.feeAuthConfig){const n=await this.feeAuthConfig.restoreFeeSignature(this.ctx,this.chainId,e.recipient);if(n!=null&&n.hasSignature){n.signature&&(this.authState.networkFee={signature:n.signature,typedData:n.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 a=this.ensureMintingFee(),n=await this.feeAuthConfig.authorizeFee(this.ctx,{chainId:this.chainId,recipient:i,fee:a});this.authState.networkFee={signature:n.signature,typedData:n.typedData}}else this.authState.destinationSignature=await this.config.getSignature(this.ctx,i,this.chainId);this.authState.authorized=!0},t.BtcActionStatus.READY)}async generateDepositAddress(i){if(this.assertStatus(t.BtcActionStatus.READY,"generateDepositAddress"),this.ensureAuthorized(),this._depositAddress)return this._depositAddress;if(!this.getActiveSignature()){const e=await this.config.getSignature(this.ctx,this.ensureRecipient(),this.chainId);this.authState.destinationSignature=e}return this.act(async()=>{const e=this.getDepositAddressParams(i),a=await this.ctx.api.generateDepositAddress(e);return f(a),this._depositAddress=a,this.emitProgress({status:t.BtcActionStatus.ADDRESS_READY,steps:{created:t.StepStatus.COMPLETE,verifying:t.StepStatus.IDLE,issuing:t.StepStatus.IDLE},metadata:{depositAddress:a}}),a},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 M extends I{constructor(i,e){super(i,e,t.BtcActionStatus.IDLE);p(this,"chainId");p(this,"authState",{authorized:!1});if(!Dt(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(!Et(e.destChain))throw new t.LombardError(t.ValidationErrorCode.INVALID_CHAIN,`Destination chain ${e.destChain} is not supported for stake and deploy`);if(!O(e.protocol))throw new t.LombardError(t.ValidationErrorCode.INVALID_PARAMETER,`Protocol ${e.protocol} is not supported for stake and deploy`);if(!lt(e.sourceChain,i.env))throw t.LombardError.routeNotFound({assetOut:e.assetOut,sourceChain:e.sourceChain,destChain:e.destChain,env:i.env});const a=t.parseChainIdentifier(e.destChain);if(typeof a!="number"||!A.isValidChain(a))throw new t.LombardError(t.ValidationErrorCode.INVALID_CHAIN,`Unsupported EVM chain: ${e.destChain}`);this.chainId=a}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(i){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,captchaToken:i}}getExpectedToken(){return E(this.params.assetOut,A.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 n=await S.restoreStakeAndBakeSignature(this.ctx,this.chainId,e.recipient);if(n!=null&&n.hasSignature){n.signature&&(this.authState.signature=n.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 a=D.toSatoshi(e),n=this.params.assetIn??c.AssetId.BTC,o=await S.authorizeStakeAndBake(this.ctx,{chainId:this.chainId,recipient:i,amount:a.toString(),vaultKey:ft(this.params.protocol),token:n});this.authState.signature=o.signature,this.authState.typedData=o.typedData,this.authState.authorized=!0},t.BtcActionStatus.READY)}async generateDepositAddress(i){return this.assertStatus(t.BtcActionStatus.READY,"generateDepositAddress"),this.ensureAuthorized(),this._depositAddress?this._depositAddress:this.act(async()=>{const e=this.getDepositAddressParams(i),a=await this.ctx.api.generateDepositAddress(e);return f(a),this._depositAddress=a,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:a}}),a},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(h=>h.depositAddress===i);if(o)return{blockHeight:o.blockHeight,isClaimed:o.isClaimed}},onProgress:n=>{this.emitProgress({status:this.status,steps:{created:t.StepStatus.COMPLETE,verifying:n.hasEnoughConfirmations?t.StepStatus.COMPLETE:t.StepStatus.PENDING,issuing:n.isClaimed?t.StepStatus.COMPLETE:t.StepStatus.PENDING,depositing:t.StepStatus.PENDING},confirmations:n.confirmations,requiredConfirmations:n.requiredConfirmations,metadata:{isClaimed:n.isClaimed}})},onComplete:()=>{this.emitCompleted()}})}}class V{constructor(r){p(this,"ctx");this.ctx=t.createBtcCoreContext(r)}stake(r){return new x(this.ctx,r)}stakeAndDeploy(r){return new M(this.ctx,r)}deposit(r){return new k(this.ctx,r)}depositAndDeploy(r){return new F(this.ctx,r)}}function Vt(s){return new V(s)}exports.BtcActions=V;exports.BtcDeposit=k;exports.BtcDepositAndDeploy=F;exports.BtcStake=x;exports.BtcStakeAndDeploy=M;exports.btcActions=Vt;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 p=(s,r,i)=>H(s,typeof r!="symbol"?r+"":r,i);const Y=require("axios"),t=require("./statusConstants-DlM2oPfW.cjs"),A=require("./token-addresses-nzvTOi24.cjs"),u=require("./index-BKzxeh1Y.cjs"),l=require("./tokens-BkvA0Gp1.cjs"),D=require("./satoshi-CZEsHl5X.cjs"),c=require("./defi-registry-DDNavtO1.cjs"),R=require("./getUserStakeAndBakeSignature-CSEyzgMc.cjs"),$=require("./config-DmCmanM_.cjs"),q=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 j(s){const{code:r,message:i}=s;throw r===U?new Error(G):new Error(i)}const K={mempoolApiUrl:"https://mempool.space/signet"},Z={mempoolApiUrl:"https://mempool.space"},W=s=>s==="mainnet"?Z:K;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:a}=await Y.get(e);return a.height}catch(a){j(a)}}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:a=6,onProgress:n,onComplete:o}=s,h=await r();if(!h)return;const d=h.blockHeight;if(typeof d!="number")return;const T=await e.getCurrentBlockHeight(i),_=Math.max(0,T-d),N=_>=a,w=h.isClaimed??!1,B={confirmations:_,requiredConfirmations:a,hasEnoughConfirmations:N,isClaimed:w,steps:{created:t.StepStatus.COMPLETE,verifying:N?t.StepStatus.COMPLETE:t.StepStatus.PENDING,issuing:w?t.StepStatus.COMPLETE:t.StepStatus.PENDING}};return n==null||n(B),w&&(o==null||o()),B}function f(s){if(s===R.SANCTIONED_ADDRESS)throw new t.LombardError(t.ValidationErrorCode.INVALID_PARAMETER,"Destination address is under sanctions")}class I extends t.BaseAction{constructor(i,e,a){super(a);p(this,"_amount");p(this,"_recipient");p(this,"_depositAddress");p(this,"_referralCode");p(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(i){const e=this.getStatusConfig();return this.assertStatus(e.ready,"generateDepositAddress"),this.ensureAuthorized(),this._depositAddress?this._depositAddress:this.act(async()=>{const a=this.getDepositAddressParams(i),n=await this.ctx.api.generateDepositAddress(a);f(n),this._depositAddress=n;const o=this.getInitialSteps(),h=Object.fromEntries(Object.entries(o).map(([d],T)=>[d,T===0?t.StepStatus.COMPLETE:t.StepStatus.IDLE]));return this.emitProgress({status:e.addressReady,steps:h,metadata:{depositAddress:n}}),n},e.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(),a=await this.trySendBitcoin(e);return a?{depositAddress:e,txHash:a}:{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(h=>h.depositAddress===i);if(o)return{blockHeight:o.blockHeight,isClaimed:o.isClaimed}},onProgress:n=>{this.emitProgress({status:this.status,steps:n.steps,confirmations:n.confirmations,requiredConfirmations:n.requiredConfirmations,metadata:{isClaimed:n.isClaimed}})},onComplete:()=>{this.emitCompleted()}})}async trySendBitcoin(i){const e=this._amount;if(e)try{const a=await this.ctx.getProvider("bitcoin");if(!a)return;const n=a;if(n.sendBitcoin){const o=D.toSatoshi(e).toNumber();return n.sendBitcoin(i,o)}}catch{}}}function E(s,r=A.Token.LBTC){switch(s){case c.AssetId.LBTC:return A.Token.LBTC;case c.AssetId.BTCb:return A.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 A.addChain({provider:s,chainId:r}),await s.request({method:"wallet_switchEthereumChain",params:[{chainId:`0x${r.toString(16)}`}]});return}catch(a){const n=a;throw n.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: ${n.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 C(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,A.Token.BTCb)},async restoreFeeSignature(s,r,i){const e=await l.getTokenContractInfo(A.Token.BTCb,r,s.env),a=await s.api.getFeeSignature({address:i,chainId:r,tokenAddress:e.address});return!a.hasSignature||a.expirationDate&&new Date(Number(a.expirationDate)*1e3)<new Date?null:{hasSignature:!0,signature:a.signature,typedData:a.typedData}},async authorizeFee(s,{chainId:r,recipient:i,fee:e}){const a=s.capabilities.require("evm"),n=await s.getProvider("evm");if(!n)throw t.LombardError.providerMissing(String(r),"evm");await C(n,r);const o=D.toSatoshi(e).toString(),h=await l.getTokenContractInfo(A.Token.BTCb,r,s.env),d=await a.signNetworkFee({fee:o,account:i,chainId:r,provider:n,token:A.Token.BTCb});return await s.api.storeFeeSignature({address:i,signature:d.signature,typedData:d.typedData,tokenAddress:h.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(c.AssetId.BTCb).filter(s=>t.isEvmChain(s)),supportedAssetsOut:[c.AssetId.BTCb],addressSchema:t.evmAddressSchema,getFeeAuthConfig(s){return st.includes(s)?it:null},async signDestination(s,r,i){const e=s.capabilities.require("evm"),a=await s.getProvider("evm");if(!a)throw t.LombardError.providerMissing(String(i),"evm");return await C(a,i),{signature:(await e.signLbtcDestination({address:r,chainId:i,provider:a})).signature}}},m=s=>`${s}${t.CAIP2_SEPARATOR}`;function nt(s){return String(s).startsWith(m(t.CHAIN_PREFIXES.EIP155))}function b(s){return String(s).startsWith(m(t.CHAIN_PREFIXES.SOLANA))}function at(s){return String(s).startsWith(m(t.CHAIN_PREFIXES.SUI))}function ot(s){return String(s).startsWith(m(t.CHAIN_PREFIXES.STARKNET))}function ut(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 dt={chainType:"solana",routes:[{sourceChains:[t.Chain.BITCOIN_SIGNET],envs:[u.r.stage,u.r.dev]}],destChains:t.getAllAssetChains(c.AssetId.BTCb).filter(s=>b(s)),supportedAssetsOut:[c.AssetId.BTCb],addressSchema:t.solanaAddressSchema,getFeeAuthConfig:()=>null,async signDestination(s,r,i){const e=s.capabilities.require("solana"),a=ut(i),{signature:n}=await e.signLbtcDestination({network:a});return{signature:n}}},ct={evm:rt,solana:dt};function ht(s){return ct[s]}function pt(s,r){return s.destChains.includes(r)}function At(s,r){return s.supportedAssetsOut.includes(r)}function St(s,r,i){return s.routes.some(e=>e.envs.includes(i)&&(!r||e.sourceChains.includes(r)))}class k extends I{constructor(i,e){super(i,e,t.BtcActionStatus.IDLE);p(this,"config");p(this,"chainId");p(this,"authState",{authorized:!1});p(this,"feeAuthConfig",null);const a=t.getChainType(e.destChain),n=ht(a);if(!n)throw new t.LombardError(t.ValidationErrorCode.INVALID_CHAIN,`Unsupported destination chain type: ${a} (${e.destChain})`);if(!At(n,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(!pt(n,e.destChain))throw new t.LombardError(t.ValidationErrorCode.INVALID_CHAIN,`Destination chain ${e.destChain} is not supported for ${a} BTC deposits`);if(!St(n,e.sourceChain,i.env))throw t.LombardError.routeNotFound({assetOut:e.assetOut,sourceChain:e.sourceChain,destChain:e.destChain,env:i.env});this.config=n,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}get mintingFee(){return this.authState.mintingFee}getDepositAddressParams(i){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,captchaToken:i}}async generateDepositAddress(i){if(!this.authState.signature){const e=await this.config.signDestination(this.ctx,this.ensureRecipient(),this.chainId);this.authState.signature=e.signature,this.authState.typedData=e.typedData}return this.generateDepositAddressImpl(i)}getExpectedToken(){return E(this.params.assetOut,A.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=this.config.getFeeAuthConfig(this.params.destChain),await this.resumeFromExistingDeposit(e.recipient)){if(this.feeAuthConfig){const n=await this.feeAuthConfig.restoreFeeSignature(this.ctx,this.chainId,e.recipient);if(!(n!=null&&n.hasSignature)){this.authState.mintingFee=await this.feeAuthConfig.getMintingFee(this.ctx,this.chainId),this.updateStatus(t.BtcActionStatus.NEEDS_FEE_AUTHORIZATION),this.emitInitialProgress();return}n.signature&&(this.authState.signature=n.signature,this.authState.typedData=n.typedData),this.authState.authorized=!0}this.updateStatus(t.BtcActionStatus.ADDRESS_READY),this.emitInitialProgress();return}if(this.feeAuthConfig){const n=await this.feeAuthConfig.restoreFeeSignature(this.ctx,this.chainId,e.recipient);if(n!=null&&n.hasSignature){n.signature&&(this.authState.signature=n.signature,this.authState.typedData=n.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 this.config.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 gt=$.VEDA_VAULT_STAKE_AND_BAKE_CHAINS.map(s=>t.evmChainIdToChain(s)),Ct={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:gt,supportedAssetsOut:[c.AssetId.LBTC],supportedProtocols:yt(c.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:a,token:n}){const o=s.capabilities.require("evm"),h=await s.getProvider("evm");if(!h)throw t.LombardError.providerMissing(String(r),"evm");await C(h,r);const d=await o.signStakeAndBake({value:e,account:i,chainId:r,provider:h,vaultKey:a,token:n});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=Ct;function Et(s){return S.destChains.includes(s)}function Dt(s){return S.supportedAssetsOut.includes(s)}function lt(s,r){return s?S.routes.some(i=>i.sourceChains.includes(s)&&i.envs.includes(r)):!0}function O(s){return s in c.DEFI_REGISTRY}function ft(s){if(!O(s)){const r=Object.keys(c.DEFI_REGISTRY).join(", ");throw new Error(`Unsupported protocol: ${s}. Supported protocols: ${r}`)}return s}function It(s){return Object.entries(c.DEFI_REGISTRY).filter(([r,i])=>s in i).map(([r])=>r)}const v={mainnet:[t.Chain.AVALANCHE],testnet:[t.Chain.AVALANCHE_FUJI]},mt={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:[c.AssetId.BTCb],supportedProtocols:It(c.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:a,token:n}){const o=s.capabilities.require("evm"),h=await s.getProvider("evm");if(!h)throw t.LombardError.providerMissing(String(r),"evm");await C(h,r);const d=await o.signStakeAndBake({value:e,account:i,chainId:r,provider:h,vaultKey:a,token:n});return await s.api.storeStakeAndBakeSignature({signature:d.signature,typedData:d.typedData}),{signature:d.signature,typedData:d.typedData,approvalTxHash:d.approvalTxHash}}},g=mt;function Tt(s){return g.destChains.includes(s)}function wt(s){return g.supportedAssetsOut.includes(s)}function P(s){return s in c.DEFI_REGISTRY}function L(s){if(!P(s)){const r=Object.keys(c.DEFI_REGISTRY).join(", ");throw new Error(`Unsupported protocol: ${s}. Supported protocols: ${r}`)}return s}function yt(s){return Object.entries(c.DEFI_REGISTRY).filter(([r,i])=>s in i).map(([r])=>r)}function _t(s,r){return g.routes.some(i=>i.sourceChains.includes(s)&&i.envs.includes(r))}class F extends I{constructor(i,e){super(i,e,t.BtcActionStatus.IDLE);p(this,"chainId");p(this,"authState",{authorized:!1});if(!wt(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(!Tt(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(!P(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 a=e.sourceChain??t.Chain.BITCOIN_MAINNET;if(!_t(a,i.env))throw t.LombardError.routeNotFound({assetOut:e.assetOut,sourceChain:a,destChain:e.destChain,env:i.env});const n=t.parseChainIdentifier(e.destChain);if(typeof n!="number"||!A.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,wrapping:t.StepStatus.IDLE,depositing:t.StepStatus.IDLE}}isAuthorized(){return this.authState.authorized}getChainId(){return this.chainId}getDepositAddressParams(i){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,captchaToken:i}}getExpectedToken(){return E(this.params.assetOut,A.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 g.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 a=D.toSatoshi(e),n=E(this.params.assetOut,A.Token.BTCb),o=await g.authorizeDepositAndDeploy(this.ctx,{chainId:this.chainId,recipient:i,amount:a.toString(),vaultKey:L(this.params.protocol),token:n});this.authState.signature=o.signature,this.authState.typedData=o.typedData,this.authState.authorized=!0},t.BtcActionStatus.READY)}async generateDepositAddress(i){return this.assertStatus(t.BtcActionStatus.READY,"generateDepositAddress"),this.ensureAuthorized(),this._depositAddress?this._depositAddress:this.act(async()=>{const e=this.getDepositAddressParams(i),a=await this.ctx.api.generateDepositAddress(e);return f(a),this._depositAddress=a,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:a}}),a},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(h=>h.depositAddress===i);if(o)return{blockHeight:o.blockHeight,isClaimed:o.isClaimed}},onProgress:n=>{this.emitProgress({status:this.status,steps:{created:t.StepStatus.COMPLETE,verifying:n.hasEnoughConfirmations?t.StepStatus.COMPLETE:t.StepStatus.PENDING,wrapping:n.isClaimed?t.StepStatus.COMPLETE:t.StepStatus.PENDING,depositing:t.StepStatus.PENDING},confirmations:n.confirmations,requiredConfirmations:n.requiredConfirmations,metadata:{isClaimed:n.isClaimed}})},onComplete:()=>{this.emitCompleted()}})}}const Nt=[t.Chain.ETHEREUM,t.Chain.SEPOLIA],Bt={async getMintingFee(s,r){return s.capabilities.require("evm").getMintingFee(r)},async restoreFeeSignature(s,r,i){const e=await l.getTokenContractInfo(A.Token.LBTC,r,s.env),a=await s.api.getFeeSignature({address:i,chainId:r,tokenAddress:e.address});return!a.hasSignature||a.expirationDate&&new Date(Number(a.expirationDate)*1e3)<new Date?null:{hasSignature:!0,signature:a.signature,typedData:a.typedData}},async authorizeFee(s,{chainId:r,recipient:i,fee:e}){const a=s.capabilities.require("evm"),n=await s.getProvider("evm");if(!n)throw t.LombardError.providerMissing(String(r),"evm");await C(n,r);const o=D.toSatoshi(e).toString(),h=await l.getTokenContractInfo(A.Token.LBTC,r,s.env),d=await a.signNetworkFee({fee:o,account:i,chainId:r,provider:n,token:A.Token.LBTC});return await s.api.storeFeeSignature({address:i,signature:d.signature,typedData:d.typedData,tokenAddress:h.address}),{signature:d.signature,typedData:d.typedData}}},vt={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(c.AssetId.LBTC).filter(s=>nt(s)),supportedAssetsOut:[c.AssetId.LBTC],addressSchema:t.evmAddressSchema,getFeeAuthConfig(s){return Nt.includes(s)?Bt:null},async getSignature(s,r,i){const e=s.capabilities.require("evm"),a=await s.getProvider("evm");if(!a)throw t.LombardError.providerMissing(String(i),"evm");return await C(a,i),e.signLbtcDestination({chainId:i,address:r,provider:a})}};function Lt(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 Rt={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(c.AssetId.LBTC).filter(s=>b(s)),supportedAssetsOut:[c.AssetId.LBTC],addressSchema:t.solanaAddressSchema,getFeeAuthConfig:()=>null,async getSignature(s,r,i){const e=s.capabilities.require("solana"),a=Lt(i),{signature:n}=await e.signLbtcDestination({network:a});return{signature:n}}},bt={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(c.AssetId.LBTC).filter(s=>ot(s)),supportedAssetsOut:[c.AssetId.LBTC],addressSchema:t.starknetAddressSchema,getFeeAuthConfig:()=>null,async getSignature(s,r,i){const e=s.capabilities.require("starknet"),{signature:a,pubKey:n}=await e.signLbtcDestination({chainId:i}),o=q.pad(r,{size:32});return{signature:a,pubKey:n,paddedAddress:o}}},kt={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(c.AssetId.LBTC).filter(s=>at(s)),supportedAssetsOut:[c.AssetId.LBTC],addressSchema:t.suiAddressSchema,getFeeAuthConfig:()=>null,async getSignature(s,r,i){const e=s.capabilities.require("sui"),{signature:a}=await e.signLbtcDestination({chainId:i});return{signature:a}}},Ot={evm:vt,solana:Rt,sui:kt,starknet:bt};function Pt(s){return Ot[s]}function Ft(s,r,i){return r?s.routes.some(e=>e.sourceChains.includes(r)&&e.envs.includes(i)):!0}function xt(s,r){return s.destChains.includes(r)}function Mt(s,r){return s.supportedAssetsOut.includes(r)}class x extends I{constructor(i,e){super(i,e,t.BtcActionStatus.IDLE);p(this,"config");p(this,"chainId");p(this,"authState",{authorized:!1});p(this,"feeAuthConfig",null);const a=t.getChainType(e.destChain),n=Pt(a);if(!n)throw new t.LombardError(t.ValidationErrorCode.INVALID_CHAIN,`Unsupported destination chain type: ${a} (${e.destChain})`);if(!Mt(n,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(!xt(n,e.destChain))throw new t.LombardError(t.ValidationErrorCode.INVALID_CHAIN,`Destination chain ${e.destChain} is not supported for ${a}`);if(!Ft(n,e.sourceChain,i.env))throw t.LombardError.routeNotFound({assetOut:e.assetOut,sourceChain:e.sourceChain,destChain:e.destChain,env:i.env});this.config=n,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(i){var n;const e=this.ensureRecipient(),a=this.getActiveSignature();if(!a)throw new t.LombardError(t.ValidationErrorCode.INVALID_PARAMETER,"Missing signature. Complete authorization first.");return{address:a.paddedAddress??e,chainId:this.chainId,signature:a.signature,token:this.getExpectedToken(),eip712Data:(n=this.authState.networkFee)==null?void 0:n.typedData,pubKey:a.pubKey,partnerId:this.ctx.partner.getPartnerId(),referrerCode:this._referralCode,captchaToken:i}}getExpectedToken(){return E(this.params.assetOut,A.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 n=await this.feeAuthConfig.restoreFeeSignature(this.ctx,this.chainId,e.recipient);if(!(n!=null&&n.hasSignature)){this.authState.mintingFee=await this.feeAuthConfig.getMintingFee(this.ctx,this.chainId),this.updateStatus(t.BtcActionStatus.NEEDS_FEE_AUTHORIZATION),this.emitInitialProgress();return}n.signature&&(this.authState.networkFee={signature:n.signature,typedData:n.typedData}),this.authState.authorized=!0}this.updateStatus(t.BtcActionStatus.ADDRESS_READY),this.emitInitialProgress();return}if(this.feeAuthConfig){const n=await this.feeAuthConfig.restoreFeeSignature(this.ctx,this.chainId,e.recipient);if(n!=null&&n.hasSignature){n.signature&&(this.authState.networkFee={signature:n.signature,typedData:n.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 a=this.ensureMintingFee(),n=await this.feeAuthConfig.authorizeFee(this.ctx,{chainId:this.chainId,recipient:i,fee:a});this.authState.networkFee={signature:n.signature,typedData:n.typedData}}else this.authState.destinationSignature=await this.config.getSignature(this.ctx,i,this.chainId);this.authState.authorized=!0},t.BtcActionStatus.READY)}async generateDepositAddress(i){if(this.assertStatus(t.BtcActionStatus.READY,"generateDepositAddress"),this.ensureAuthorized(),this._depositAddress)return this._depositAddress;if(!this.getActiveSignature()){const e=await this.config.getSignature(this.ctx,this.ensureRecipient(),this.chainId);this.authState.destinationSignature=e}return this.act(async()=>{const e=this.getDepositAddressParams(i),a=await this.ctx.api.generateDepositAddress(e);return f(a),this._depositAddress=a,this.emitProgress({status:t.BtcActionStatus.ADDRESS_READY,steps:{created:t.StepStatus.COMPLETE,verifying:t.StepStatus.IDLE,issuing:t.StepStatus.IDLE},metadata:{depositAddress:a}}),a},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 M extends I{constructor(i,e){super(i,e,t.BtcActionStatus.IDLE);p(this,"chainId");p(this,"authState",{authorized:!1});if(!Dt(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(!Et(e.destChain))throw new t.LombardError(t.ValidationErrorCode.INVALID_CHAIN,`Destination chain ${e.destChain} is not supported for stake and deploy`);if(!O(e.protocol))throw new t.LombardError(t.ValidationErrorCode.INVALID_PARAMETER,`Protocol ${e.protocol} is not supported for stake and deploy`);if(!lt(e.sourceChain,i.env))throw t.LombardError.routeNotFound({assetOut:e.assetOut,sourceChain:e.sourceChain,destChain:e.destChain,env:i.env});const a=t.parseChainIdentifier(e.destChain);if(typeof a!="number"||!A.isValidChain(a))throw new t.LombardError(t.ValidationErrorCode.INVALID_CHAIN,`Unsupported EVM chain: ${e.destChain}`);this.chainId=a}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(i){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,captchaToken:i}}getExpectedToken(){return E(this.params.assetOut,A.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 n=await S.restoreStakeAndBakeSignature(this.ctx,this.chainId,e.recipient);if(n!=null&&n.hasSignature){n.signature&&(this.authState.signature=n.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 a=D.toSatoshi(e),n=this.params.assetIn??c.AssetId.BTC,o=await S.authorizeStakeAndBake(this.ctx,{chainId:this.chainId,recipient:i,amount:a.toString(),vaultKey:ft(this.params.protocol),token:n});this.authState.signature=o.signature,this.authState.typedData=o.typedData,this.authState.authorized=!0},t.BtcActionStatus.READY)}async generateDepositAddress(i){return this.assertStatus(t.BtcActionStatus.READY,"generateDepositAddress"),this.ensureAuthorized(),this._depositAddress?this._depositAddress:this.act(async()=>{const e=this.getDepositAddressParams(i),a=await this.ctx.api.generateDepositAddress(e);return f(a),this._depositAddress=a,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:a}}),a},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(h=>h.depositAddress===i);if(o)return{blockHeight:o.blockHeight,isClaimed:o.isClaimed}},onProgress:n=>{this.emitProgress({status:this.status,steps:{created:t.StepStatus.COMPLETE,verifying:n.hasEnoughConfirmations?t.StepStatus.COMPLETE:t.StepStatus.PENDING,issuing:n.isClaimed?t.StepStatus.COMPLETE:t.StepStatus.PENDING,depositing:t.StepStatus.PENDING},confirmations:n.confirmations,requiredConfirmations:n.requiredConfirmations,metadata:{isClaimed:n.isClaimed}})},onComplete:()=>{this.emitCompleted()}})}}class V{constructor(r){p(this,"ctx");this.ctx=t.createBtcCoreContext(r)}stake(r){return new x(this.ctx,r)}stakeAndDeploy(r){return new M(this.ctx,r)}deposit(r){return new k(this.ctx,r)}depositAndDeploy(r){return new F(this.ctx,r)}}function Vt(s){return new V(s)}exports.BtcActions=V;exports.BtcDeposit=k;exports.BtcDepositAndDeploy=F;exports.BtcStake=x;exports.BtcStakeAndDeploy=M;exports.btcActions=Vt;exports.btcModule=Q;
|
|
2
|
+
//# sourceMappingURL=BtcActions-BIBsbYIt.cjs.map
|