@lombard.finance/sdk 4.4.1 → 4.5.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.
Files changed (38) hide show
  1. package/CHANGELOG.md +13 -0
  2. package/dist/btc.cjs +1 -1
  3. package/dist/btc.js +2 -2
  4. package/dist/chunks/{BtcActions-BIBsbYIt.cjs → BtcActions-B-ttz47_.cjs} +2 -2
  5. package/dist/chunks/{BtcActions-BIBsbYIt.cjs.map → BtcActions-B-ttz47_.cjs.map} +1 -1
  6. package/dist/chunks/{BtcActions-Df41lbsb.js → BtcActions-HGHFC106.js} +2 -2
  7. package/dist/chunks/{BtcActions-Df41lbsb.js.map → BtcActions-HGHFC106.js.map} +1 -1
  8. package/dist/chunks/{EvmActions-BY_18gTg.cjs → EvmActions-BGxXtQFZ.cjs} +2 -2
  9. package/dist/chunks/{EvmActions-BY_18gTg.cjs.map → EvmActions-BGxXtQFZ.cjs.map} +1 -1
  10. package/dist/chunks/{EvmActions-5lPqhRaM.js → EvmActions-TNM8i9Xg.js} +2 -2
  11. package/dist/chunks/{EvmActions-5lPqhRaM.js.map → EvmActions-TNM8i9Xg.js.map} +1 -1
  12. package/dist/chunks/{events-BvRwXePq.js → events-83d3qdxG.js} +4 -4
  13. package/dist/chunks/{events-BvRwXePq.js.map → events-83d3qdxG.js.map} +1 -1
  14. package/dist/chunks/{events-6PV6NP-o.cjs → events-DvTn2yHn.cjs} +2 -2
  15. package/dist/chunks/{events-6PV6NP-o.cjs.map → events-DvTn2yHn.cjs.map} +1 -1
  16. package/dist/chunks/{statusConstants-DlM2oPfW.cjs → statusConstants-8ra-0ydr.cjs} +2 -2
  17. package/dist/chunks/{statusConstants-DlM2oPfW.cjs.map → statusConstants-8ra-0ydr.cjs.map} +1 -1
  18. package/dist/chunks/{statusConstants-C4YNx2q0.js → statusConstants-qfM-LJfE.js} +2 -2
  19. package/dist/chunks/{statusConstants-C4YNx2q0.js.map → statusConstants-qfM-LJfE.js.map} +1 -1
  20. package/dist/core.cjs +1 -1
  21. package/dist/core.js +4 -4
  22. package/dist/entries/vaults.d.ts +1 -1
  23. package/dist/entries/vaults.d.ts.map +1 -1
  24. package/dist/evm.cjs +1 -1
  25. package/dist/evm.js +2 -2
  26. package/dist/index.cjs +1 -1
  27. package/dist/index.js +4 -4
  28. package/dist/vaults/index.d.ts +2 -0
  29. package/dist/vaults/index.d.ts.map +1 -1
  30. package/dist/vaults/lib/ops/get-vault-minimum-deposit.d.ts +32 -0
  31. package/dist/vaults/lib/ops/get-vault-minimum-deposit.d.ts.map +1 -0
  32. package/dist/vaults/lib/ops/preview-vault-deposit.d.ts +38 -0
  33. package/dist/vaults/lib/ops/preview-vault-deposit.d.ts.map +1 -0
  34. package/dist/vaults.cjs +1 -1
  35. package/dist/vaults.cjs.map +1 -1
  36. package/dist/vaults.js +162 -15
  37. package/dist/vaults.js.map +1 -1
  38. package/package.json +1 -1
package/CHANGELOG.md CHANGED
@@ -1,3 +1,16 @@
1
+ # 4.5.1
2
+
3
+ - **Solana companion package** (`@lombard.finance/sdk-solana` ≥1.2.2): consortium `claimToken()` uses epoch-seeded session PDAs and an updated Consortium IDL. Upgrade the Solana package when targeting the upgraded consortium program. This `@lombard.finance/sdk` release documents that dependency; see `packages/sdk-solana/CHANGELOG.md` for details.
4
+
5
+ ---
6
+
7
+ # 4.5.0
8
+
9
+ - Added `getVaultMinimumDeposit()` to calculate the minimum deposit amount for a given token that produces at least 1 vault share. The minimum is derived from the on-chain exchange rate and updates as the vault accrues yield.
10
+ - Added `previewVaultDeposit()` to simulate a vault deposit and return the expected shares for a given amount. Uses the on-chain Lens contract for accurate results including share premiums.
11
+
12
+ ---
13
+
1
14
  # 4.4.1
2
15
 
3
16
  - 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.
package/dist/btc.cjs CHANGED
@@ -1,2 +1,2 @@
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;
1
+ "use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const t=require("./chunks/BtcActions-B-ttz47_.cjs"),c=require("./chunks/statusConstants-8ra-0ydr.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-Df41lbsb.js";
2
- import { BtcActionStatus as r } from "./chunks/statusConstants-C4YNx2q0.js";
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-HGHFC106.js";
2
+ import { BtcActionStatus as r } from "./chunks/statusConstants-qfM-LJfE.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-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
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-8ra-0ydr.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-B-ttz47_.cjs.map