@lombard.finance/sdk 0.8.4 → 0.9.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.cjs CHANGED
@@ -1,2 +1,2 @@
1
- "use strict";var j=Object.defineProperty;var q=(e,t,n)=>t in e?j(e,t,{enumerable:!0,configurable:!0,writable:!0,value:n}):e[t]=n;var c=(e,t,n)=>(q(e,typeof t!="symbol"?t+"":t,n),n);Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const v=require("axios"),y=require("web3"),x=require("bignumber.js"),z=require("@bitcoin-js/tiny-secp256k1-asmjs"),f=require("bitcoinjs-lib");function Z(e){const t=Object.create(null,{[Symbol.toStringTag]:{value:"Module"}});if(e){for(const n in e)if(n!=="default"){const a=Object.getOwnPropertyDescriptor(e,n);Object.defineProperty(t,n,a.get?a:{enumerable:!0,get:()=>e[n]})}}return t.default=e,Object.freeze(t)}const K=Z(z),l={prod:"prod",testnet:"testnet",stage:"stage"},r={ethereum:1,holesky:17e3},A=l.prod,M="0x0000000000000000000000000000000000000000",J={baseApiUrl:"https://staging.prod.lombard.finance"},X={baseApiUrl:"https://gastald-testnet.prod.lombard.finance"},Y={baseApiUrl:"https://mainnet.prod.lombard.finance"},T=(e=A)=>{switch(e){case l.prod:return Y;case l.testnet:return X;default:return J}};function F(e){return typeof e=="string"?e:e instanceof Error?Q(e):ee(e)}function Q(e){return e.response?e.response.data.message:e.message}function ee(e){return e!=null&&e.message?e.message:"Unknown error"}const te={eth:"DESTINATION_BLOCKCHAIN_ETHEREUM"};function I(e){switch(e){case r.holesky:case r.ethereum:return te.eth;default:throw new Error(`Unknown chain ID: ${e}`)}}const L="sanctioned_address",ne="api/v1/address/generate",ae="destination address is under sanctions";async function se({address:e,chainId:t,signature:n,referralId:a,env:s,captchaToken:i}){const{baseApiUrl:o}=T(s),p=I(t),m={to_address:e,to_address_signature:n,to_chain:p,referral_id:a,nonce:0,captcha:i};try{const{data:b}=await v.post(ne,m,{baseURL:o});return b.address}catch(b){const g=F(b);if(ie(g))return L;throw new Error(g)}}function ie(e){return!!e.includes(ae)}const re="api/v1/address";async function oe({address:e,chainId:t,env:n,referralId:a}){const s=await k({address:e,chainId:t,env:n,referralId:a}),i=pe(s);if(!i)throw new Error("No address");return i.btc_address}function pe(e){if(!e.length)return;const t=e.reduce((n,a)=>n.created_at<a.created_at?a:n,e[0]);return t.deprecated?void 0:t}async function k({address:e,chainId:t,env:n,referralId:a}){const{baseApiUrl:s}=T(n),i=I(t),o={to_address:e,to_blockchain:i,limit:1,offset:0,asc:!1,referral_id:a},{data:p}=await v.get(re,{baseURL:s,params:o});return(p==null?void 0:p.addresses)||[]}const ue=8,U=10**ue;function N(e){return+e/U}function P(e){return Math.floor(+e*U)}function ye(e,t=A){switch(e){case"DESTINATION_BLOCKCHAIN_ETHEREUM":return t===l.prod?r.ethereum:r.holesky;default:return r.ethereum}}async function de({address:e,env:t}){const{baseApiUrl:n}=T(t),{data:a}=await v.get(`api/v1/address/outputs/${e}`,{baseURL:n});return((a==null?void 0:a.outputs)??[]).map(le(t))}function le(e){return t=>({txid:t.txid,index:t.index??0,blockHeight:t.block_height?Number(t.block_height):void 0,blockTime:t.block_time?Number(t.block_time):void 0,value:N(t.value),address:t.address,chainId:ye(t.to_chain,e),isClaimed:!!t.claim_tx,rawPayload:t.raw_payload,signature:t.signature,isRestricted:!!t.sanctioned,notarizationWaitDur:t.notarization_wait_dur?Number(t.notarization_wait_dur):void 0})}async function me({env:e,chainId:t,amount:n}){const{baseApiUrl:a}=T(e),s=I(t),{data:i}=await v.get(`api/v1/exchange/rate/${s}`,{baseURL:a,params:{amount:n}});return i.amount_out}const G={[r.ethereum]:"https://rpc.ankr.com/eth",[r.holesky]:"https://rpc.ankr.com/eth_holesky"};async function ce(e){const n=await(await fetch(e,{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({jsonrpc:"2.0",id:1,method:"eth_maxPriorityFeePerGas",params:[]})})).json(),a=y.utils.hexToNumber(n==null?void 0:n.result);return new x(Number(a))}const be=2,fe=25e3;class Te{constructor({chainId:t,rpcUrlConfig:n}){c(this,"chainId");c(this,"rpcConfig");this.chainId=t,this.rpcConfig={...G,...n}}getReadWeb3(){const t=this.getRpcUrl(),n=new y,a=new y.providers.HttpProvider(t);return n.setProvider(a),n}getRpcUrl(){var a;const{chainId:t}=this,n=(a=this.rpcConfig)==null?void 0:a[t];if(!n)throw console.error(`You might need to add the rpcConfig for the ${t} chain ID when creating the provider.`),new Error(`RPC URL for chainId ${t} not found`);return n}async getMaxFees(){const t=this.getReadWeb3(),n=this.getRpcUrl(),[a,s]=await Promise.all([t.eth.getBlock("latest"),ce(n)]);return!(a!=null&&a.baseFeePerGas)&&typeof(a==null?void 0:a.baseFeePerGas)!="bigint"?{}:{maxFeePerGas:+new x(a.baseFeePerGas.toString(10)).multipliedBy(be).plus(s),maxPriorityFeePerGas:+s}}async getSafeGasPriceWei(){const t=await this.getReadWeb3().eth.getGasPrice();return new x(t.toString(10)).plus(fe)}createContract(t,n){const a=this.getReadWeb3();return new a.eth.Contract(t,n)}}class C extends Te{constructor({provider:n,account:a,chainId:s,rpcUrlConfig:i}){super({chainId:s,rpcUrlConfig:i});c(this,"web3");c(this,"account");c(this,"rpcConfig");this.web3=new y(n),this.account=a,this.chainId=s,this.rpcConfig={...G,...i}}async signMessage(n){const{account:a}=this,s=`0x${Buffer.from(n,"utf8").toString("hex")}`;return this.web3.currentProvider.request({method:"personal_sign",params:[s,a]})}async sendTransactionAsync(n,a,s){const{chainId:i,web3:o}=this,p=this.getReadWeb3(),{data:m,estimate:b=!1,estimateFee:g=!1,extendedGasLimit:R,gasLimit:H="0",value:V="0",gasLimitMultiplier:$=1}=s;let{nonce:h}=s;h||(h=await p.eth.getTransactionCount(n)),console.log(`Nonce: ${h}`);const u={from:n,to:a,value:y.utils.numberToHex(V),data:m,nonce:h,chainId:y.utils.numberToHex(i)};if(b)try{const d=await p.eth.estimateGas(u),w=Math.round(Number(d)*$);R?u.gas=y.utils.numberToHex(w+R):u.gas=y.utils.numberToHex(w)}catch(d){throw new Error(d.message??"Failed to estimate gas limit for transaction.")}else u.gas=y.utils.numberToHex(H);const{maxFeePerGas:_,maxPriorityFeePerGas:D}=g?await this.getMaxFees().catch(()=>s):s;if(D!==void 0&&(u.maxPriorityFeePerGas=y.utils.numberToHex(D)),_!==void 0&&(u.maxFeePerGas=y.utils.numberToHex(_)),!u.maxFeePerGas&&!u.maxPriorityFeePerGas){const d=await this.getSafeGasPriceWei();u.gasPrice=d.toString(10)}if(!u.maxFeePerGas&&!u.maxPriorityFeePerGas){const d=await this.getSafeGasPriceWei();u.gasPrice=d.toString(10)}return console.log("Sending transaction via Web3: ",u),new Promise((d,w)=>{const B=o.eth.sendTransaction(u);B.once("transactionHash",async O=>{console.log(`Just signed transaction has is: ${O}`),d({receiptPromise:B,transactionHash:O})}).catch(w)})}createContract(n,a){return new this.web3.eth.Contract(n,a)}}function S(e){switch(e){case r.ethereum:return 1.3;case r.holesky:return 1.5;default:return 1.3}}function ge(e){return Object.values(r).includes(e)}const he={[r.holesky]:"0xED7bfd5C1790576105Af4649817f6d35A75CD818",[r.ethereum]:M},we={[r.holesky]:"0x38A13AB20D15ffbE5A7312d2336EF1552580a4E2",[r.ethereum]:M},ve={[r.holesky]:M,[r.ethereum]:"0x8236a87084f8b84306f72007f36f2618a5634494"};function W(e=A){switch(e){case l.prod:return ve;case l.testnet:return we;default:return he}}const Ce=[{constant:!0,inputs:[],name:"name",outputs:[{name:"",type:"string"}],payable:!1,stateMutability:"view",type:"function"},{constant:!1,inputs:[{name:"_spender",type:"address"},{name:"_value",type:"uint256"}],name:"approve",outputs:[{name:"",type:"bool"}],payable:!1,stateMutability:"nonpayable",type:"function"},{constant:!0,inputs:[],name:"totalSupply",outputs:[{name:"",type:"uint256"}],payable:!1,stateMutability:"view",type:"function"},{constant:!1,inputs:[{name:"_from",type:"address"},{name:"_to",type:"address"},{name:"_value",type:"uint256"}],name:"transferFrom",outputs:[{name:"",type:"bool"}],payable:!1,stateMutability:"nonpayable",type:"function"},{constant:!0,inputs:[],name:"decimals",outputs:[{name:"",type:"uint8"}],payable:!1,stateMutability:"view",type:"function"},{constant:!0,inputs:[{name:"_owner",type:"address"}],name:"balanceOf",outputs:[{name:"balance",type:"uint256"}],payable:!1,stateMutability:"view",type:"function"},{constant:!0,inputs:[],name:"symbol",outputs:[{name:"",type:"string"}],payable:!1,stateMutability:"view",type:"function"},{constant:!1,inputs:[{name:"_to",type:"address"},{name:"_value",type:"uint256"}],name:"transfer",outputs:[{name:"",type:"bool"}],payable:!1,stateMutability:"nonpayable",type:"function"},{constant:!0,inputs:[{name:"_owner",type:"address"},{name:"_spender",type:"address"}],name:"allowance",outputs:[{name:"",type:"uint256"}],payable:!1,stateMutability:"view",type:"function"},{payable:!0,stateMutability:"payable",type:"fallback"},{anonymous:!1,inputs:[{indexed:!0,name:"owner",type:"address"},{indexed:!0,name:"spender",type:"address"},{indexed:!1,name:"value",type:"uint256"}],name:"Approval",type:"event"},{anonymous:!1,inputs:[{indexed:!0,name:"from",type:"address"},{indexed:!0,name:"to",type:"address"},{indexed:!1,name:"value",type:"uint256"}],name:"Transfer",type:"event"}],xe=[{inputs:[],stateMutability:"nonpayable",type:"constructor"},{inputs:[{internalType:"uint256",name:"dustLimit",type:"uint256"}],name:"AmountBelowDustLimit",type:"error"},{inputs:[{internalType:"uint256",name:"fee",type:"uint256"}],name:"AmountLessThanCommission",type:"error"},{inputs:[],name:"AmountTooSmallToPayRelativeFee",type:"error"},{inputs:[{internalType:"uint256",name:"expected",type:"uint256"},{internalType:"uint256",name:"received",type:"uint256"}],name:"BadChainId",type:"error"},{inputs:[],name:"BadCommission",type:"error"},{inputs:[],name:"BadDestination",type:"error"},{inputs:[{internalType:"address",name:"expected",type:"address"},{internalType:"address",name:"received",type:"address"}],name:"BadToContractAddress",type:"error"},{inputs:[],name:"ECDSAInvalidSignature",type:"error"},{inputs:[{internalType:"uint256",name:"length",type:"uint256"}],name:"ECDSAInvalidSignatureLength",type:"error"},{inputs:[{internalType:"bytes32",name:"s",type:"bytes32"}],name:"ECDSAInvalidSignatureS",type:"error"},{inputs:[{internalType:"address",name:"spender",type:"address"},{internalType:"uint256",name:"allowance",type:"uint256"},{internalType:"uint256",name:"needed",type:"uint256"}],name:"ERC20InsufficientAllowance",type:"error"},{inputs:[{internalType:"address",name:"sender",type:"address"},{internalType:"uint256",name:"balance",type:"uint256"},{internalType:"uint256",name:"needed",type:"uint256"}],name:"ERC20InsufficientBalance",type:"error"},{inputs:[{internalType:"address",name:"approver",type:"address"}],name:"ERC20InvalidApprover",type:"error"},{inputs:[{internalType:"address",name:"receiver",type:"address"}],name:"ERC20InvalidReceiver",type:"error"},{inputs:[{internalType:"address",name:"sender",type:"address"}],name:"ERC20InvalidSender",type:"error"},{inputs:[{internalType:"address",name:"spender",type:"address"}],name:"ERC20InvalidSpender",type:"error"},{inputs:[],name:"EnforcedPause",type:"error"},{inputs:[],name:"ExpectedPause",type:"error"},{inputs:[],name:"InvalidDustFeeRate",type:"error"},{inputs:[],name:"InvalidInitialization",type:"error"},{inputs:[],name:"KnownDestination",type:"error"},{inputs:[],name:"MathOverflowedMulDiv",type:"error"},{inputs:[],name:"NotInitializing",type:"error"},{inputs:[{internalType:"address",name:"owner",type:"address"}],name:"OwnableInvalidOwner",type:"error"},{inputs:[{internalType:"address",name:"account",type:"address"}],name:"OwnableUnauthorizedAccount",type:"error"},{inputs:[],name:"ProofAlreadyUsed",type:"error"},{inputs:[],name:"ReentrancyGuardReentrantCall",type:"error"},{inputs:[],name:"ScriptPubkeyUnsupported",type:"error"},{inputs:[],name:"SignatureVerificationFailed",type:"error"},{inputs:[{internalType:"address",name:"account",type:"address"}],name:"UnauthorizedAccount",type:"error"},{inputs:[],name:"UnknownDestination",type:"error"},{inputs:[],name:"WithdrawalsDisabled",type:"error"},{inputs:[],name:"WrongAddressEncoding",type:"error"},{inputs:[],name:"WrongChainIdEncoding",type:"error"},{inputs:[],name:"WrongDataLength",type:"error"},{inputs:[],name:"WrongDataLength",type:"error"},{inputs:[],name:"WrongTxIdEncoding",type:"error"},{inputs:[],name:"ZeroAddress",type:"error"},{inputs:[],name:"ZeroAddress",type:"error"},{inputs:[],name:"ZeroAmount",type:"error"},{inputs:[],name:"ZeroAmount",type:"error"},{inputs:[],name:"ZeroChainId",type:"error"},{inputs:[],name:"ZeroChainId",type:"error"},{inputs:[],name:"ZeroContractHash",type:"error"},{inputs:[],name:"ZeroTxHash",type:"error"},{anonymous:!1,inputs:[{indexed:!0,internalType:"address",name:"owner",type:"address"},{indexed:!0,internalType:"address",name:"spender",type:"address"},{indexed:!1,internalType:"uint256",name:"value",type:"uint256"}],name:"Approval",type:"event"},{anonymous:!1,inputs:[{indexed:!0,internalType:"address",name:"prevVal",type:"address"},{indexed:!0,internalType:"address",name:"newVal",type:"address"}],name:"BasculeChanged",type:"event"},{anonymous:!1,inputs:[{indexed:!0,internalType:"bytes32",name:"toChain",type:"bytes32"},{indexed:!0,internalType:"bytes32",name:"toContract",type:"bytes32"}],name:"BridgeDestinationAdded",type:"event"},{anonymous:!1,inputs:[{indexed:!0,internalType:"bytes32",name:"toChain",type:"bytes32"},{indexed:!0,internalType:"bytes32",name:"toContract",type:"bytes32"}],name:"BridgeDestinationRemoved",type:"event"},{anonymous:!1,inputs:[{indexed:!0,internalType:"uint64",name:"prevValue",type:"uint64"},{indexed:!0,internalType:"uint64",name:"newValue",type:"uint64"}],name:"BurnCommissionChanged",type:"event"},{anonymous:!1,inputs:[{indexed:!0,internalType:"address",name:"prevVal",type:"address"},{indexed:!0,internalType:"address",name:"newVal",type:"address"}],name:"ConsortiumChanged",type:"event"},{anonymous:!1,inputs:[{indexed:!1,internalType:"uint64",name:"newValue",type:"uint64"},{indexed:!0,internalType:"bytes32",name:"toChain",type:"bytes32"}],name:"DepositAbsoluteCommissionChanged",type:"event"},{anonymous:!1,inputs:[{indexed:!1,internalType:"uint16",name:"newValue",type:"uint16"},{indexed:!0,internalType:"bytes32",name:"toChain",type:"bytes32"}],name:"DepositRelativeCommissionChanged",type:"event"},{anonymous:!1,inputs:[{indexed:!0,internalType:"address",name:"fromAddress",type:"address"},{indexed:!0,internalType:"bytes32",name:"toAddress",type:"bytes32"},{indexed:!1,internalType:"bytes32",name:"toContract",type:"bytes32"},{indexed:!1,internalType:"bytes32",name:"chainId",type:"bytes32"},{indexed:!1,internalType:"uint64",name:"amount",type:"uint64"}],name:"DepositToBridge",type:"event"},{anonymous:!1,inputs:[{indexed:!0,internalType:"uint256",name:"oldRate",type:"uint256"},{indexed:!0,internalType:"uint256",name:"newRate",type:"uint256"}],name:"DustFeeRateChanged",type:"event"},{anonymous:!1,inputs:[{indexed:!1,internalType:"uint64",name:"version",type:"uint64"}],name:"Initialized",type:"event"},{anonymous:!1,inputs:[{indexed:!1,internalType:"string",name:"name",type:"string"},{indexed:!1,internalType:"string",name:"symbol",type:"string"}],name:"NameAndSymbolChanged",type:"event"},{anonymous:!1,inputs:[{indexed:!0,internalType:"bytes32",name:"transactionId",type:"bytes32"},{indexed:!0,internalType:"uint32",name:"index",type:"uint32"},{indexed:!1,internalType:"bytes32",name:"proofHash",type:"bytes32"}],name:"OutputProcessed",type:"event"},{anonymous:!1,inputs:[{indexed:!0,internalType:"address",name:"previousOwner",type:"address"},{indexed:!0,internalType:"address",name:"newOwner",type:"address"}],name:"OwnershipTransferStarted",type:"event"},{anonymous:!1,inputs:[{indexed:!0,internalType:"address",name:"previousOwner",type:"address"},{indexed:!0,internalType:"address",name:"newOwner",type:"address"}],name:"OwnershipTransferred",type:"event"},{anonymous:!1,inputs:[{indexed:!1,internalType:"address",name:"account",type:"address"}],name:"Paused",type:"event"},{anonymous:!1,inputs:[{indexed:!0,internalType:"address",name:"previousPauser",type:"address"},{indexed:!0,internalType:"address",name:"newPauser",type:"address"}],name:"PauserRoleTransferred",type:"event"},{anonymous:!1,inputs:[{indexed:!0,internalType:"address",name:"from",type:"address"},{indexed:!0,internalType:"address",name:"to",type:"address"},{indexed:!1,internalType:"uint256",name:"value",type:"uint256"}],name:"Transfer",type:"event"},{anonymous:!1,inputs:[{indexed:!0,internalType:"address",name:"prevValue",type:"address"},{indexed:!0,internalType:"address",name:"newValue",type:"address"}],name:"TreasuryAddressChanged",type:"event"},{anonymous:!1,inputs:[{indexed:!1,internalType:"address",name:"account",type:"address"}],name:"Unpaused",type:"event"},{anonymous:!1,inputs:[{indexed:!0,internalType:"address",name:"fromAddress",type:"address"},{indexed:!1,internalType:"bytes",name:"scriptPubKey",type:"bytes"},{indexed:!1,internalType:"uint256",name:"amount",type:"uint256"}],name:"UnstakeRequest",type:"event"},{anonymous:!1,inputs:[{indexed:!0,internalType:"address",name:"toAddress",type:"address"},{indexed:!0,internalType:"bytes32",name:"txHash",type:"bytes32"},{indexed:!0,internalType:"uint32",name:"eventIndex",type:"uint32"},{indexed:!1,internalType:"bytes32",name:"proofHash",type:"bytes32"},{indexed:!1,internalType:"bytes32",name:"fromContract",type:"bytes32"},{indexed:!1,internalType:"bytes32",name:"fromChainId",type:"bytes32"},{indexed:!1,internalType:"uint64",name:"amount",type:"uint64"}],name:"WithdrawFromBridge",type:"event"},{anonymous:!1,inputs:[{indexed:!1,internalType:"bool",name:"",type:"bool"}],name:"WithdrawalsEnabled",type:"event"},{inputs:[],name:"Bascule",outputs:[{internalType:"contract IBascule",name:"",type:"address"}],stateMutability:"view",type:"function"},{inputs:[],name:"MAX_COMMISSION",outputs:[{internalType:"uint16",name:"",type:"uint16"}],stateMutability:"view",type:"function"},{inputs:[],name:"acceptOwnership",outputs:[],stateMutability:"nonpayable",type:"function"},{inputs:[{internalType:"bytes32",name:"toChain",type:"bytes32"},{internalType:"bytes32",name:"toContract",type:"bytes32"},{internalType:"uint16",name:"relCommission",type:"uint16"},{internalType:"uint64",name:"absCommission",type:"uint64"}],name:"addDestination",outputs:[],stateMutability:"nonpayable",type:"function"},{inputs:[{internalType:"address",name:"owner",type:"address"},{internalType:"address",name:"spender",type:"address"}],name:"allowance",outputs:[{internalType:"uint256",name:"",type:"uint256"}],stateMutability:"view",type:"function"},{inputs:[{internalType:"address",name:"spender",type:"address"},{internalType:"uint256",name:"value",type:"uint256"}],name:"approve",outputs:[{internalType:"bool",name:"",type:"bool"}],stateMutability:"nonpayable",type:"function"},{inputs:[{internalType:"address",name:"account",type:"address"}],name:"balanceOf",outputs:[{internalType:"uint256",name:"",type:"uint256"}],stateMutability:"view",type:"function"},{inputs:[{internalType:"uint256",name:"amount",type:"uint256"}],name:"burn",outputs:[],stateMutability:"nonpayable",type:"function"},{inputs:[{internalType:"bytes",name:"scriptPubkey",type:"bytes"},{internalType:"uint256",name:"amount",type:"uint256"}],name:"calcUnstakeRequestAmount",outputs:[{internalType:"uint256",name:"amountAfterFee",type:"uint256"},{internalType:"bool",name:"isAboveDust",type:"bool"}],stateMutability:"view",type:"function"},{inputs:[{internalType:"address",name:"newVal",type:"address"}],name:"changeBascule",outputs:[],stateMutability:"nonpayable",type:"function"},{inputs:[{internalType:"uint64",name:"newValue",type:"uint64"}],name:"changeBurnCommission",outputs:[],stateMutability:"nonpayable",type:"function"},{inputs:[{internalType:"address",name:"newVal",type:"address"}],name:"changeConsortium",outputs:[],stateMutability:"nonpayable",type:"function"},{inputs:[{internalType:"uint64",name:"newValue",type:"uint64"},{internalType:"bytes32",name:"chain",type:"bytes32"}],name:"changeDepositAbsoluteCommission",outputs:[],stateMutability:"nonpayable",type:"function"},{inputs:[{internalType:"uint16",name:"newValue",type:"uint16"},{internalType:"bytes32",name:"chain",type:"bytes32"}],name:"changeDepositRelativeCommission",outputs:[],stateMutability:"nonpayable",type:"function"},{inputs:[{internalType:"uint256",name:"newRate",type:"uint256"}],name:"changeDustFeeRate",outputs:[],stateMutability:"nonpayable",type:"function"},{inputs:[{internalType:"string",name:"name_",type:"string"},{internalType:"string",name:"symbol_",type:"string"}],name:"changeNameAndSymbol",outputs:[],stateMutability:"nonpayable",type:"function"},{inputs:[{internalType:"address",name:"newValue",type:"address"}],name:"changeTreasuryAddress",outputs:[],stateMutability:"nonpayable",type:"function"},{inputs:[],name:"consortium",outputs:[{internalType:"address",name:"",type:"address"}],stateMutability:"view",type:"function"},{inputs:[],name:"decimals",outputs:[{internalType:"uint8",name:"",type:"uint8"}],stateMutability:"view",type:"function"},{inputs:[{internalType:"bytes32",name:"toChain",type:"bytes32"},{internalType:"bytes32",name:"toAddress",type:"bytes32"},{internalType:"uint64",name:"amount",type:"uint64"}],name:"depositToBridge",outputs:[],stateMutability:"nonpayable",type:"function"},{inputs:[],name:"getBurnCommission",outputs:[{internalType:"uint64",name:"",type:"uint64"}],stateMutability:"view",type:"function"},{inputs:[{internalType:"bytes32",name:"toChain",type:"bytes32"}],name:"getDepositAbsoluteCommission",outputs:[{internalType:"uint64",name:"",type:"uint64"}],stateMutability:"view",type:"function"},{inputs:[{internalType:"bytes32",name:"toChain",type:"bytes32"}],name:"getDepositRelativeCommission",outputs:[{internalType:"uint16",name:"",type:"uint16"}],stateMutability:"view",type:"function"},{inputs:[{internalType:"bytes32",name:"chainId",type:"bytes32"}],name:"getDestination",outputs:[{internalType:"bytes32",name:"",type:"bytes32"}],stateMutability:"view",type:"function"},{inputs:[],name:"getDustFeeRate",outputs:[{internalType:"uint256",name:"",type:"uint256"}],stateMutability:"view",type:"function"},{inputs:[],name:"getTreasury",outputs:[{internalType:"address",name:"",type:"address"}],stateMutability:"view",type:"function"},{inputs:[{internalType:"address",name:"consortium_",type:"address"},{internalType:"uint64",name:"burnCommission_",type:"uint64"}],name:"initialize",outputs:[],stateMutability:"nonpayable",type:"function"},{inputs:[{internalType:"bytes32",name:"proof",type:"bytes32"}],name:"isUsed",outputs:[{internalType:"bool",name:"",type:"bool"}],stateMutability:"view",type:"function"},{inputs:[{internalType:"bytes",name:"data",type:"bytes"},{internalType:"bytes",name:"proofSignature",type:"bytes"}],name:"mint",outputs:[],stateMutability:"nonpayable",type:"function"},{inputs:[],name:"name",outputs:[{internalType:"string",name:"",type:"string"}],stateMutability:"view",type:"function"},{inputs:[],name:"owner",outputs:[{internalType:"address",name:"",type:"address"}],stateMutability:"view",type:"function"},{inputs:[],name:"pause",outputs:[],stateMutability:"nonpayable",type:"function"},{inputs:[],name:"paused",outputs:[{internalType:"bool",name:"",type:"bool"}],stateMutability:"view",type:"function"},{inputs:[],name:"pauser",outputs:[{internalType:"address",name:"",type:"address"}],stateMutability:"view",type:"function"},{inputs:[],name:"pendingOwner",outputs:[{internalType:"address",name:"",type:"address"}],stateMutability:"view",type:"function"},{inputs:[{internalType:"bytes",name:"scriptPubkey",type:"bytes"},{internalType:"uint256",name:"amount",type:"uint256"}],name:"redeem",outputs:[],stateMutability:"nonpayable",type:"function"},{inputs:[{internalType:"bytes32",name:"toChain",type:"bytes32"}],name:"removeDestination",outputs:[],stateMutability:"nonpayable",type:"function"},{inputs:[],name:"renounceOwnership",outputs:[],stateMutability:"nonpayable",type:"function"},{inputs:[],name:"symbol",outputs:[{internalType:"string",name:"",type:"string"}],stateMutability:"view",type:"function"},{inputs:[],name:"toggleWithdrawals",outputs:[],stateMutability:"nonpayable",type:"function"},{inputs:[],name:"totalSupply",outputs:[{internalType:"uint256",name:"",type:"uint256"}],stateMutability:"view",type:"function"},{inputs:[{internalType:"address",name:"to",type:"address"},{internalType:"uint256",name:"value",type:"uint256"}],name:"transfer",outputs:[{internalType:"bool",name:"",type:"bool"}],stateMutability:"nonpayable",type:"function"},{inputs:[{internalType:"address",name:"from",type:"address"},{internalType:"address",name:"to",type:"address"},{internalType:"uint256",name:"value",type:"uint256"}],name:"transferFrom",outputs:[{internalType:"bool",name:"",type:"bool"}],stateMutability:"nonpayable",type:"function"},{inputs:[{internalType:"address",name:"newOwner",type:"address"}],name:"transferOwnership",outputs:[],stateMutability:"nonpayable",type:"function"},{inputs:[{internalType:"address",name:"newPauser",type:"address"}],name:"transferPauserRole",outputs:[],stateMutability:"nonpayable",type:"function"},{inputs:[],name:"unpause",outputs:[],stateMutability:"nonpayable",type:"function"},{inputs:[{internalType:"bytes",name:"data",type:"bytes"},{internalType:"bytes",name:"proofSignature",type:"bytes"}],name:"withdrawFromBridge",outputs:[],stateMutability:"nonpayable",type:"function"}];function Ae(e){switch(e){case"LBTC":return xe;default:return Ce}}function E(e,t){const n=W(t),{chainId:a}=e;if(!ge(a))throw new Error(`This chain ${a} is not supported`);const s=n[a];if(!s)throw new Error(`Token address for chain ${a} is not defined`);const i=Ae("LBTC"),o=e.createContract(i,s);return o.options.address||(o.options.address=s),o}function Me({spender:e,amount:t,env:n,...a}){const s=new C(a),i=E(s,n),o=P(t),p=i.methods.approve(e,o);return s.sendTransactionAsync(s.account,i.options.address,{data:p.encodeABI(),estimate:!0,estimateFee:!0,gasLimitMultiplier:S(s.chainId)})}const Ie="insufficient funds",Pe="Insufficient funds for transfer. Make sure you have enough ETH to cover the gas cost.";async function Se({data:e,proofSignature:t,env:n,...a}){const s=new C(a),i=E(s,n),o=i.methods.mint(e,t);try{return await s.sendTransactionAsync(s.account,i.options.address,{data:o.encodeABI(),estimate:!0,estimateFee:!0,gasLimitMultiplier:S(s.chainId)})}catch(p){const m=F(p);throw m.includes(Ie)?new Error(Pe):new Error(m)}}async function Ee(e){const t=new C(e),n=`destination chain id is ${e.chainId}`;return t.signMessage(n)}f.initEccLib(K);function Re(e,t=l.prod){var i;const n=_e(e),s=(i=f.payments[n]({address:e,network:t===l.prod?f.networks.bitcoin:f.networks.testnet}).output)==null?void 0:i.toString("hex");if(!s)throw new Error("Output script is not found.");return`0x${s}`}function _e(e){const t=f.address.fromBech32(e);if(t.version===1&&t.data.length===32)return"p2tr";if(t.version===0&&t.data.length===20)return"p2wpkh";throw new Error("Payment type is not supported.")}function De({btcAddress:e,amount:t,env:n,...a}){const s=new C(a),i=E(s,n),o=Re(e,n),p=P(t),m=i.methods.redeem(o,p);return s.sendTransactionAsync(s.account,i.options.address,{data:m.encodeABI(),estimate:!0,estimateFee:!0,gasLimitMultiplier:S(s.chainId)})}exports.OChainId=r;exports.OEnv=l;exports.SANCTIONED_ADDRESS=L;exports.approveLBTC=Me;exports.claimLBTC=Se;exports.fromSatoshi=N;exports.generateDepositBtcAddress=se;exports.getApiConfig=T;exports.getDepositBtcAddress=oe;exports.getDepositBtcAddresses=k;exports.getDepositsByAddress=de;exports.getLBTCExchageRate=me;exports.getLbtcAddressConfig=W;exports.signLbtcDestionationAddr=Ee;exports.toSatoshi=P;exports.unstakeLBTC=De;
1
+ "use strict";var j=Object.defineProperty;var q=(e,t,n)=>t in e?j(e,t,{enumerable:!0,configurable:!0,writable:!0,value:n}):e[t]=n;var c=(e,t,n)=>(q(e,typeof t!="symbol"?t+"":t,n),n);Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const v=require("axios"),y=require("web3"),x=require("bignumber.js"),z=require("@bitcoin-js/tiny-secp256k1-asmjs"),f=require("bitcoinjs-lib");function Z(e){const t=Object.create(null,{[Symbol.toStringTag]:{value:"Module"}});if(e){for(const n in e)if(n!=="default"){const a=Object.getOwnPropertyDescriptor(e,n);Object.defineProperty(t,n,a.get?a:{enumerable:!0,get:()=>e[n]})}}return t.default=e,Object.freeze(t)}const K=Z(z),l={prod:"prod",testnet:"testnet",stage:"stage"},r={ethereum:1,holesky:17e3},M=l.prod,I="0x0000000000000000000000000000000000000000",J={baseApiUrl:"https://staging.prod.lombard.finance"},X={baseApiUrl:"https://gastald-testnet.prod.lombard.finance"},Y={baseApiUrl:"https://mainnet.prod.lombard.finance"},T=(e=M)=>{switch(e){case l.prod:return Y;case l.testnet:return X;default:return J}};function L(e){return typeof e=="string"?e:e instanceof Error?Q(e):ee(e)}function Q(e){return e.response?e.response.data.message:e.message}function ee(e){return e!=null&&e.message?e.message:"Unknown error"}const te={eth:"DESTINATION_BLOCKCHAIN_ETHEREUM"};function P(e){switch(e){case r.holesky:case r.ethereum:return te.eth;default:throw new Error(`Unknown chain ID: ${e}`)}}const k="sanctioned_address",ne="api/v1/address/generate",ae="destination address is under sanctions";async function se({address:e,chainId:t,signature:n,referralId:a,env:s,captchaToken:i}){const{baseApiUrl:o}=T(s),p=P(t),m={to_address:e,to_address_signature:n,to_chain:p,referral_id:a,nonce:0,captcha:i};try{const{data:b}=await v.post(ne,m,{baseURL:o});return b.address}catch(b){const h=L(b);if(ie(h))return k;throw new Error(h)}}function ie(e){return!!e.includes(ae)}const re="api/v1/address";async function oe({address:e,chainId:t,env:n,referralId:a}){const s=await U({address:e,chainId:t,env:n,referralId:a}),i=pe(s);if(!i)throw new Error("No address");return i.btc_address}function pe(e){if(!e.length)return;const t=e.reduce((n,a)=>n.created_at<a.created_at?a:n,e[0]);return t.deprecated?void 0:t}async function U({address:e,chainId:t,env:n,referralId:a}){const{baseApiUrl:s}=T(n),i=P(t),o={to_address:e,to_blockchain:i,limit:1,offset:0,asc:!1,referral_id:a},{data:p}=await v.get(re,{baseURL:s,params:o});return(p==null?void 0:p.addresses)||[]}const ue=8,N=10**ue;function G(e){return+e/N}function S(e){return Math.floor(+e*N)}function ye(e,t=M){switch(e){case"DESTINATION_BLOCKCHAIN_ETHEREUM":return t===l.prod?r.ethereum:r.holesky;default:return r.ethereum}}async function de({address:e,env:t}){const{baseApiUrl:n}=T(t),{data:a}=await v.get(`api/v1/address/outputs/${e}`,{baseURL:n});return((a==null?void 0:a.outputs)??[]).map(le(t))}function le(e){return t=>({txid:t.txid,index:t.index??0,blockHeight:t.block_height?Number(t.block_height):void 0,blockTime:t.block_time?Number(t.block_time):void 0,value:G(t.value),address:t.address,chainId:ye(t.to_chain,e),isClaimed:!!t.claim_tx,rawPayload:t.raw_payload,signature:t.signature,isRestricted:!!t.sanctioned,notarizationWaitDur:t.notarization_wait_dur?Number(t.notarization_wait_dur):void 0})}async function me({env:e,chainId:t,amount:n}){const{baseApiUrl:a}=T(e),s=P(t),{data:i}=await v.get(`api/v1/exchange/rate/${s}`,{baseURL:a,params:{amount:n}});return i.amount_out}const A={[r.ethereum]:"https://rpc.ankr.com/eth",[r.holesky]:"https://rpc.ankr.com/eth_holesky"};async function ce(e){const n=await(await fetch(e,{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({jsonrpc:"2.0",id:1,method:"eth_maxPriorityFeePerGas",params:[]})})).json(),a=y.utils.hexToNumber(n==null?void 0:n.result);return new x(Number(a))}const be=2,fe=25e3;class Te{constructor({chainId:t,rpcUrlConfig:n}){c(this,"chainId");c(this,"rpcConfig");this.chainId=t,this.rpcConfig={...A,...n}}getReadWeb3(){const t=this.getRpcUrl(),n=new y,a=new y.providers.HttpProvider(t);return n.setProvider(a),n}getRpcUrl(){var a;const{chainId:t}=this,n=(a=this.rpcConfig)==null?void 0:a[t];if(!n)throw console.error(`You might need to add the rpcConfig for the ${t} chain ID when creating the provider.`),new Error(`RPC URL for chainId ${t} not found`);return n}async getMaxFees(){const t=this.getReadWeb3(),n=this.getRpcUrl(),[a,s]=await Promise.all([t.eth.getBlock("latest"),ce(n)]);return!(a!=null&&a.baseFeePerGas)&&typeof(a==null?void 0:a.baseFeePerGas)!="bigint"?{}:{maxFeePerGas:+new x(a.baseFeePerGas.toString(10)).multipliedBy(be).plus(s),maxPriorityFeePerGas:+s}}async getSafeGasPriceWei(){const t=await this.getReadWeb3().eth.getGasPrice();return new x(t.toString(10)).plus(fe)}createContract(t,n){const a=this.getReadWeb3();return new a.eth.Contract(t,n)}}class C extends Te{constructor({provider:n,account:a,chainId:s,rpcUrlConfig:i}){super({chainId:s,rpcUrlConfig:i});c(this,"web3");c(this,"account");c(this,"rpcConfig",A);this.web3=new y(n),this.account=a,this.chainId=s,this.rpcConfig={...A,...i}}async signMessage(n){const{account:a}=this,s=`0x${Buffer.from(n,"utf8").toString("hex")}`;return this.web3.currentProvider.request({method:"personal_sign",params:[s,a]})}async sendTransactionAsync(n,a,s){const{chainId:i,web3:o}=this,p=this.getReadWeb3(),{data:m,estimate:b=!1,estimateFee:h=!1,extendedGasLimit:_,gasLimit:H="0",value:V="0",gasLimitMultiplier:$=1}=s;let{nonce:g}=s;g||(g=await p.eth.getTransactionCount(n)),console.log(`Nonce: ${g}`);const u={from:n,to:a,value:y.utils.numberToHex(V),data:m,nonce:g,chainId:y.utils.numberToHex(i)};if(b)try{const d=await p.eth.estimateGas(u),w=Math.round(Number(d)*$);_?u.gas=y.utils.numberToHex(w+_):u.gas=y.utils.numberToHex(w)}catch(d){throw new Error(d.message??"Failed to estimate gas limit for transaction.")}else u.gas=y.utils.numberToHex(H);const{maxFeePerGas:D,maxPriorityFeePerGas:B}=h?await this.getMaxFees().catch(()=>s):s;if(B!==void 0&&(u.maxPriorityFeePerGas=y.utils.numberToHex(B)),D!==void 0&&(u.maxFeePerGas=y.utils.numberToHex(D)),!u.maxFeePerGas&&!u.maxPriorityFeePerGas){const d=await this.getSafeGasPriceWei();u.gasPrice=d.toString(10)}if(!u.maxFeePerGas&&!u.maxPriorityFeePerGas){const d=await this.getSafeGasPriceWei();u.gasPrice=d.toString(10)}return console.log("Sending transaction via Web3: ",u),new Promise((d,w)=>{const O=o.eth.sendTransaction(u);O.once("transactionHash",async F=>{console.log(`Just signed transaction has is: ${F}`),d({receiptPromise:O,transactionHash:F})}).catch(w)})}createContract(n,a){return new this.web3.eth.Contract(n,a)}}function E(e){switch(e){case r.ethereum:return 1.3;case r.holesky:return 1.5;default:return 1.3}}function he(e){return Object.values(r).includes(e)}const ge={[r.holesky]:"0xED7bfd5C1790576105Af4649817f6d35A75CD818",[r.ethereum]:I},we={[r.holesky]:"0x38A13AB20D15ffbE5A7312d2336EF1552580a4E2",[r.ethereum]:I},ve={[r.holesky]:I,[r.ethereum]:"0x8236a87084f8b84306f72007f36f2618a5634494"};function W(e=M){switch(e){case l.prod:return ve;case l.testnet:return we;default:return ge}}const Ce=[{constant:!0,inputs:[],name:"name",outputs:[{name:"",type:"string"}],payable:!1,stateMutability:"view",type:"function"},{constant:!1,inputs:[{name:"_spender",type:"address"},{name:"_value",type:"uint256"}],name:"approve",outputs:[{name:"",type:"bool"}],payable:!1,stateMutability:"nonpayable",type:"function"},{constant:!0,inputs:[],name:"totalSupply",outputs:[{name:"",type:"uint256"}],payable:!1,stateMutability:"view",type:"function"},{constant:!1,inputs:[{name:"_from",type:"address"},{name:"_to",type:"address"},{name:"_value",type:"uint256"}],name:"transferFrom",outputs:[{name:"",type:"bool"}],payable:!1,stateMutability:"nonpayable",type:"function"},{constant:!0,inputs:[],name:"decimals",outputs:[{name:"",type:"uint8"}],payable:!1,stateMutability:"view",type:"function"},{constant:!0,inputs:[{name:"_owner",type:"address"}],name:"balanceOf",outputs:[{name:"balance",type:"uint256"}],payable:!1,stateMutability:"view",type:"function"},{constant:!0,inputs:[],name:"symbol",outputs:[{name:"",type:"string"}],payable:!1,stateMutability:"view",type:"function"},{constant:!1,inputs:[{name:"_to",type:"address"},{name:"_value",type:"uint256"}],name:"transfer",outputs:[{name:"",type:"bool"}],payable:!1,stateMutability:"nonpayable",type:"function"},{constant:!0,inputs:[{name:"_owner",type:"address"},{name:"_spender",type:"address"}],name:"allowance",outputs:[{name:"",type:"uint256"}],payable:!1,stateMutability:"view",type:"function"},{payable:!0,stateMutability:"payable",type:"fallback"},{anonymous:!1,inputs:[{indexed:!0,name:"owner",type:"address"},{indexed:!0,name:"spender",type:"address"},{indexed:!1,name:"value",type:"uint256"}],name:"Approval",type:"event"},{anonymous:!1,inputs:[{indexed:!0,name:"from",type:"address"},{indexed:!0,name:"to",type:"address"},{indexed:!1,name:"value",type:"uint256"}],name:"Transfer",type:"event"}],xe=[{inputs:[],stateMutability:"nonpayable",type:"constructor"},{inputs:[{internalType:"uint256",name:"dustLimit",type:"uint256"}],name:"AmountBelowDustLimit",type:"error"},{inputs:[{internalType:"uint256",name:"fee",type:"uint256"}],name:"AmountLessThanCommission",type:"error"},{inputs:[],name:"AmountTooSmallToPayRelativeFee",type:"error"},{inputs:[{internalType:"uint256",name:"expected",type:"uint256"},{internalType:"uint256",name:"received",type:"uint256"}],name:"BadChainId",type:"error"},{inputs:[],name:"BadCommission",type:"error"},{inputs:[],name:"BadDestination",type:"error"},{inputs:[{internalType:"address",name:"expected",type:"address"},{internalType:"address",name:"received",type:"address"}],name:"BadToContractAddress",type:"error"},{inputs:[],name:"ECDSAInvalidSignature",type:"error"},{inputs:[{internalType:"uint256",name:"length",type:"uint256"}],name:"ECDSAInvalidSignatureLength",type:"error"},{inputs:[{internalType:"bytes32",name:"s",type:"bytes32"}],name:"ECDSAInvalidSignatureS",type:"error"},{inputs:[{internalType:"address",name:"spender",type:"address"},{internalType:"uint256",name:"allowance",type:"uint256"},{internalType:"uint256",name:"needed",type:"uint256"}],name:"ERC20InsufficientAllowance",type:"error"},{inputs:[{internalType:"address",name:"sender",type:"address"},{internalType:"uint256",name:"balance",type:"uint256"},{internalType:"uint256",name:"needed",type:"uint256"}],name:"ERC20InsufficientBalance",type:"error"},{inputs:[{internalType:"address",name:"approver",type:"address"}],name:"ERC20InvalidApprover",type:"error"},{inputs:[{internalType:"address",name:"receiver",type:"address"}],name:"ERC20InvalidReceiver",type:"error"},{inputs:[{internalType:"address",name:"sender",type:"address"}],name:"ERC20InvalidSender",type:"error"},{inputs:[{internalType:"address",name:"spender",type:"address"}],name:"ERC20InvalidSpender",type:"error"},{inputs:[],name:"EnforcedPause",type:"error"},{inputs:[],name:"ExpectedPause",type:"error"},{inputs:[],name:"InvalidDustFeeRate",type:"error"},{inputs:[],name:"InvalidInitialization",type:"error"},{inputs:[],name:"KnownDestination",type:"error"},{inputs:[],name:"MathOverflowedMulDiv",type:"error"},{inputs:[],name:"NotInitializing",type:"error"},{inputs:[{internalType:"address",name:"owner",type:"address"}],name:"OwnableInvalidOwner",type:"error"},{inputs:[{internalType:"address",name:"account",type:"address"}],name:"OwnableUnauthorizedAccount",type:"error"},{inputs:[],name:"ProofAlreadyUsed",type:"error"},{inputs:[],name:"ReentrancyGuardReentrantCall",type:"error"},{inputs:[],name:"ScriptPubkeyUnsupported",type:"error"},{inputs:[],name:"SignatureVerificationFailed",type:"error"},{inputs:[{internalType:"address",name:"account",type:"address"}],name:"UnauthorizedAccount",type:"error"},{inputs:[],name:"UnknownDestination",type:"error"},{inputs:[],name:"WithdrawalsDisabled",type:"error"},{inputs:[],name:"WrongAddressEncoding",type:"error"},{inputs:[],name:"WrongChainIdEncoding",type:"error"},{inputs:[],name:"WrongDataLength",type:"error"},{inputs:[],name:"WrongDataLength",type:"error"},{inputs:[],name:"WrongTxIdEncoding",type:"error"},{inputs:[],name:"ZeroAddress",type:"error"},{inputs:[],name:"ZeroAddress",type:"error"},{inputs:[],name:"ZeroAmount",type:"error"},{inputs:[],name:"ZeroAmount",type:"error"},{inputs:[],name:"ZeroChainId",type:"error"},{inputs:[],name:"ZeroChainId",type:"error"},{inputs:[],name:"ZeroContractHash",type:"error"},{inputs:[],name:"ZeroTxHash",type:"error"},{anonymous:!1,inputs:[{indexed:!0,internalType:"address",name:"owner",type:"address"},{indexed:!0,internalType:"address",name:"spender",type:"address"},{indexed:!1,internalType:"uint256",name:"value",type:"uint256"}],name:"Approval",type:"event"},{anonymous:!1,inputs:[{indexed:!0,internalType:"address",name:"prevVal",type:"address"},{indexed:!0,internalType:"address",name:"newVal",type:"address"}],name:"BasculeChanged",type:"event"},{anonymous:!1,inputs:[{indexed:!0,internalType:"bytes32",name:"toChain",type:"bytes32"},{indexed:!0,internalType:"bytes32",name:"toContract",type:"bytes32"}],name:"BridgeDestinationAdded",type:"event"},{anonymous:!1,inputs:[{indexed:!0,internalType:"bytes32",name:"toChain",type:"bytes32"},{indexed:!0,internalType:"bytes32",name:"toContract",type:"bytes32"}],name:"BridgeDestinationRemoved",type:"event"},{anonymous:!1,inputs:[{indexed:!0,internalType:"uint64",name:"prevValue",type:"uint64"},{indexed:!0,internalType:"uint64",name:"newValue",type:"uint64"}],name:"BurnCommissionChanged",type:"event"},{anonymous:!1,inputs:[{indexed:!0,internalType:"address",name:"prevVal",type:"address"},{indexed:!0,internalType:"address",name:"newVal",type:"address"}],name:"ConsortiumChanged",type:"event"},{anonymous:!1,inputs:[{indexed:!1,internalType:"uint64",name:"newValue",type:"uint64"},{indexed:!0,internalType:"bytes32",name:"toChain",type:"bytes32"}],name:"DepositAbsoluteCommissionChanged",type:"event"},{anonymous:!1,inputs:[{indexed:!1,internalType:"uint16",name:"newValue",type:"uint16"},{indexed:!0,internalType:"bytes32",name:"toChain",type:"bytes32"}],name:"DepositRelativeCommissionChanged",type:"event"},{anonymous:!1,inputs:[{indexed:!0,internalType:"address",name:"fromAddress",type:"address"},{indexed:!0,internalType:"bytes32",name:"toAddress",type:"bytes32"},{indexed:!1,internalType:"bytes32",name:"toContract",type:"bytes32"},{indexed:!1,internalType:"bytes32",name:"chainId",type:"bytes32"},{indexed:!1,internalType:"uint64",name:"amount",type:"uint64"}],name:"DepositToBridge",type:"event"},{anonymous:!1,inputs:[{indexed:!0,internalType:"uint256",name:"oldRate",type:"uint256"},{indexed:!0,internalType:"uint256",name:"newRate",type:"uint256"}],name:"DustFeeRateChanged",type:"event"},{anonymous:!1,inputs:[{indexed:!1,internalType:"uint64",name:"version",type:"uint64"}],name:"Initialized",type:"event"},{anonymous:!1,inputs:[{indexed:!1,internalType:"string",name:"name",type:"string"},{indexed:!1,internalType:"string",name:"symbol",type:"string"}],name:"NameAndSymbolChanged",type:"event"},{anonymous:!1,inputs:[{indexed:!0,internalType:"bytes32",name:"transactionId",type:"bytes32"},{indexed:!0,internalType:"uint32",name:"index",type:"uint32"},{indexed:!1,internalType:"bytes32",name:"proofHash",type:"bytes32"}],name:"OutputProcessed",type:"event"},{anonymous:!1,inputs:[{indexed:!0,internalType:"address",name:"previousOwner",type:"address"},{indexed:!0,internalType:"address",name:"newOwner",type:"address"}],name:"OwnershipTransferStarted",type:"event"},{anonymous:!1,inputs:[{indexed:!0,internalType:"address",name:"previousOwner",type:"address"},{indexed:!0,internalType:"address",name:"newOwner",type:"address"}],name:"OwnershipTransferred",type:"event"},{anonymous:!1,inputs:[{indexed:!1,internalType:"address",name:"account",type:"address"}],name:"Paused",type:"event"},{anonymous:!1,inputs:[{indexed:!0,internalType:"address",name:"previousPauser",type:"address"},{indexed:!0,internalType:"address",name:"newPauser",type:"address"}],name:"PauserRoleTransferred",type:"event"},{anonymous:!1,inputs:[{indexed:!0,internalType:"address",name:"from",type:"address"},{indexed:!0,internalType:"address",name:"to",type:"address"},{indexed:!1,internalType:"uint256",name:"value",type:"uint256"}],name:"Transfer",type:"event"},{anonymous:!1,inputs:[{indexed:!0,internalType:"address",name:"prevValue",type:"address"},{indexed:!0,internalType:"address",name:"newValue",type:"address"}],name:"TreasuryAddressChanged",type:"event"},{anonymous:!1,inputs:[{indexed:!1,internalType:"address",name:"account",type:"address"}],name:"Unpaused",type:"event"},{anonymous:!1,inputs:[{indexed:!0,internalType:"address",name:"fromAddress",type:"address"},{indexed:!1,internalType:"bytes",name:"scriptPubKey",type:"bytes"},{indexed:!1,internalType:"uint256",name:"amount",type:"uint256"}],name:"UnstakeRequest",type:"event"},{anonymous:!1,inputs:[{indexed:!0,internalType:"address",name:"toAddress",type:"address"},{indexed:!0,internalType:"bytes32",name:"txHash",type:"bytes32"},{indexed:!0,internalType:"uint32",name:"eventIndex",type:"uint32"},{indexed:!1,internalType:"bytes32",name:"proofHash",type:"bytes32"},{indexed:!1,internalType:"bytes32",name:"fromContract",type:"bytes32"},{indexed:!1,internalType:"bytes32",name:"fromChainId",type:"bytes32"},{indexed:!1,internalType:"uint64",name:"amount",type:"uint64"}],name:"WithdrawFromBridge",type:"event"},{anonymous:!1,inputs:[{indexed:!1,internalType:"bool",name:"",type:"bool"}],name:"WithdrawalsEnabled",type:"event"},{inputs:[],name:"Bascule",outputs:[{internalType:"contract IBascule",name:"",type:"address"}],stateMutability:"view",type:"function"},{inputs:[],name:"MAX_COMMISSION",outputs:[{internalType:"uint16",name:"",type:"uint16"}],stateMutability:"view",type:"function"},{inputs:[],name:"acceptOwnership",outputs:[],stateMutability:"nonpayable",type:"function"},{inputs:[{internalType:"bytes32",name:"toChain",type:"bytes32"},{internalType:"bytes32",name:"toContract",type:"bytes32"},{internalType:"uint16",name:"relCommission",type:"uint16"},{internalType:"uint64",name:"absCommission",type:"uint64"}],name:"addDestination",outputs:[],stateMutability:"nonpayable",type:"function"},{inputs:[{internalType:"address",name:"owner",type:"address"},{internalType:"address",name:"spender",type:"address"}],name:"allowance",outputs:[{internalType:"uint256",name:"",type:"uint256"}],stateMutability:"view",type:"function"},{inputs:[{internalType:"address",name:"spender",type:"address"},{internalType:"uint256",name:"value",type:"uint256"}],name:"approve",outputs:[{internalType:"bool",name:"",type:"bool"}],stateMutability:"nonpayable",type:"function"},{inputs:[{internalType:"address",name:"account",type:"address"}],name:"balanceOf",outputs:[{internalType:"uint256",name:"",type:"uint256"}],stateMutability:"view",type:"function"},{inputs:[{internalType:"uint256",name:"amount",type:"uint256"}],name:"burn",outputs:[],stateMutability:"nonpayable",type:"function"},{inputs:[{internalType:"bytes",name:"scriptPubkey",type:"bytes"},{internalType:"uint256",name:"amount",type:"uint256"}],name:"calcUnstakeRequestAmount",outputs:[{internalType:"uint256",name:"amountAfterFee",type:"uint256"},{internalType:"bool",name:"isAboveDust",type:"bool"}],stateMutability:"view",type:"function"},{inputs:[{internalType:"address",name:"newVal",type:"address"}],name:"changeBascule",outputs:[],stateMutability:"nonpayable",type:"function"},{inputs:[{internalType:"uint64",name:"newValue",type:"uint64"}],name:"changeBurnCommission",outputs:[],stateMutability:"nonpayable",type:"function"},{inputs:[{internalType:"address",name:"newVal",type:"address"}],name:"changeConsortium",outputs:[],stateMutability:"nonpayable",type:"function"},{inputs:[{internalType:"uint64",name:"newValue",type:"uint64"},{internalType:"bytes32",name:"chain",type:"bytes32"}],name:"changeDepositAbsoluteCommission",outputs:[],stateMutability:"nonpayable",type:"function"},{inputs:[{internalType:"uint16",name:"newValue",type:"uint16"},{internalType:"bytes32",name:"chain",type:"bytes32"}],name:"changeDepositRelativeCommission",outputs:[],stateMutability:"nonpayable",type:"function"},{inputs:[{internalType:"uint256",name:"newRate",type:"uint256"}],name:"changeDustFeeRate",outputs:[],stateMutability:"nonpayable",type:"function"},{inputs:[{internalType:"string",name:"name_",type:"string"},{internalType:"string",name:"symbol_",type:"string"}],name:"changeNameAndSymbol",outputs:[],stateMutability:"nonpayable",type:"function"},{inputs:[{internalType:"address",name:"newValue",type:"address"}],name:"changeTreasuryAddress",outputs:[],stateMutability:"nonpayable",type:"function"},{inputs:[],name:"consortium",outputs:[{internalType:"address",name:"",type:"address"}],stateMutability:"view",type:"function"},{inputs:[],name:"decimals",outputs:[{internalType:"uint8",name:"",type:"uint8"}],stateMutability:"view",type:"function"},{inputs:[{internalType:"bytes32",name:"toChain",type:"bytes32"},{internalType:"bytes32",name:"toAddress",type:"bytes32"},{internalType:"uint64",name:"amount",type:"uint64"}],name:"depositToBridge",outputs:[],stateMutability:"nonpayable",type:"function"},{inputs:[],name:"getBurnCommission",outputs:[{internalType:"uint64",name:"",type:"uint64"}],stateMutability:"view",type:"function"},{inputs:[{internalType:"bytes32",name:"toChain",type:"bytes32"}],name:"getDepositAbsoluteCommission",outputs:[{internalType:"uint64",name:"",type:"uint64"}],stateMutability:"view",type:"function"},{inputs:[{internalType:"bytes32",name:"toChain",type:"bytes32"}],name:"getDepositRelativeCommission",outputs:[{internalType:"uint16",name:"",type:"uint16"}],stateMutability:"view",type:"function"},{inputs:[{internalType:"bytes32",name:"chainId",type:"bytes32"}],name:"getDestination",outputs:[{internalType:"bytes32",name:"",type:"bytes32"}],stateMutability:"view",type:"function"},{inputs:[],name:"getDustFeeRate",outputs:[{internalType:"uint256",name:"",type:"uint256"}],stateMutability:"view",type:"function"},{inputs:[],name:"getTreasury",outputs:[{internalType:"address",name:"",type:"address"}],stateMutability:"view",type:"function"},{inputs:[{internalType:"address",name:"consortium_",type:"address"},{internalType:"uint64",name:"burnCommission_",type:"uint64"}],name:"initialize",outputs:[],stateMutability:"nonpayable",type:"function"},{inputs:[{internalType:"bytes32",name:"proof",type:"bytes32"}],name:"isUsed",outputs:[{internalType:"bool",name:"",type:"bool"}],stateMutability:"view",type:"function"},{inputs:[{internalType:"bytes",name:"data",type:"bytes"},{internalType:"bytes",name:"proofSignature",type:"bytes"}],name:"mint",outputs:[],stateMutability:"nonpayable",type:"function"},{inputs:[],name:"name",outputs:[{internalType:"string",name:"",type:"string"}],stateMutability:"view",type:"function"},{inputs:[],name:"owner",outputs:[{internalType:"address",name:"",type:"address"}],stateMutability:"view",type:"function"},{inputs:[],name:"pause",outputs:[],stateMutability:"nonpayable",type:"function"},{inputs:[],name:"paused",outputs:[{internalType:"bool",name:"",type:"bool"}],stateMutability:"view",type:"function"},{inputs:[],name:"pauser",outputs:[{internalType:"address",name:"",type:"address"}],stateMutability:"view",type:"function"},{inputs:[],name:"pendingOwner",outputs:[{internalType:"address",name:"",type:"address"}],stateMutability:"view",type:"function"},{inputs:[{internalType:"bytes",name:"scriptPubkey",type:"bytes"},{internalType:"uint256",name:"amount",type:"uint256"}],name:"redeem",outputs:[],stateMutability:"nonpayable",type:"function"},{inputs:[{internalType:"bytes32",name:"toChain",type:"bytes32"}],name:"removeDestination",outputs:[],stateMutability:"nonpayable",type:"function"},{inputs:[],name:"renounceOwnership",outputs:[],stateMutability:"nonpayable",type:"function"},{inputs:[],name:"symbol",outputs:[{internalType:"string",name:"",type:"string"}],stateMutability:"view",type:"function"},{inputs:[],name:"toggleWithdrawals",outputs:[],stateMutability:"nonpayable",type:"function"},{inputs:[],name:"totalSupply",outputs:[{internalType:"uint256",name:"",type:"uint256"}],stateMutability:"view",type:"function"},{inputs:[{internalType:"address",name:"to",type:"address"},{internalType:"uint256",name:"value",type:"uint256"}],name:"transfer",outputs:[{internalType:"bool",name:"",type:"bool"}],stateMutability:"nonpayable",type:"function"},{inputs:[{internalType:"address",name:"from",type:"address"},{internalType:"address",name:"to",type:"address"},{internalType:"uint256",name:"value",type:"uint256"}],name:"transferFrom",outputs:[{internalType:"bool",name:"",type:"bool"}],stateMutability:"nonpayable",type:"function"},{inputs:[{internalType:"address",name:"newOwner",type:"address"}],name:"transferOwnership",outputs:[],stateMutability:"nonpayable",type:"function"},{inputs:[{internalType:"address",name:"newPauser",type:"address"}],name:"transferPauserRole",outputs:[],stateMutability:"nonpayable",type:"function"},{inputs:[],name:"unpause",outputs:[],stateMutability:"nonpayable",type:"function"},{inputs:[{internalType:"bytes",name:"data",type:"bytes"},{internalType:"bytes",name:"proofSignature",type:"bytes"}],name:"withdrawFromBridge",outputs:[],stateMutability:"nonpayable",type:"function"}];function Ae(e){switch(e){case"LBTC":return xe;default:return Ce}}function R(e,t){const n=W(t),{chainId:a}=e;if(!he(a))throw new Error(`This chain ${a} is not supported`);const s=n[a];if(!s)throw new Error(`Token address for chain ${a} is not defined`);const i=Ae("LBTC"),o=e.createContract(i,s);return o.options.address||(o.options.address=s),o}function Me({spender:e,amount:t,env:n,...a}){const s=new C(a),i=R(s,n),o=S(t),p=i.methods.approve(e,o);return s.sendTransactionAsync(s.account,i.options.address,{data:p.encodeABI(),estimate:!0,estimateFee:!0,gasLimitMultiplier:E(s.chainId)})}const Ie="insufficient funds",Pe="Insufficient funds for transfer. Make sure you have enough ETH to cover the gas cost.";async function Se({data:e,proofSignature:t,env:n,...a}){const s=new C(a),i=R(s,n),o=i.methods.mint(e,t);try{return await s.sendTransactionAsync(s.account,i.options.address,{data:o.encodeABI(),estimate:!0,estimateFee:!0,gasLimitMultiplier:E(s.chainId)})}catch(p){const m=L(p);throw m.includes(Ie)?new Error(Pe):new Error(m)}}async function Ee(e){const t=new C(e),n=`destination chain id is ${e.chainId}`;return t.signMessage(n)}f.initEccLib(K);function Re(e,t=l.prod){var i;const n=_e(e),s=(i=f.payments[n]({address:e,network:t===l.prod?f.networks.bitcoin:f.networks.testnet}).output)==null?void 0:i.toString("hex");if(!s)throw new Error("Output script is not found.");return`0x${s}`}function _e(e){const t=f.address.fromBech32(e);if(t.version===1&&t.data.length===32)return"p2tr";if(t.version===0&&t.data.length===20)return"p2wpkh";if(De(e))return"p2wsh";throw new Error("Address type is not supported.")}function De(e){return(e.startsWith("bc1")||e.startsWith("tb1"))&&e.length===62}function Be({btcAddress:e,amount:t,env:n,...a}){const s=new C(a),i=R(s,n),o=Re(e,n),p=S(t),m=i.methods.redeem(o,p);return s.sendTransactionAsync(s.account,i.options.address,{data:m.encodeABI(),estimate:!0,estimateFee:!0,gasLimitMultiplier:E(s.chainId)})}exports.OChainId=r;exports.OEnv=l;exports.SANCTIONED_ADDRESS=k;exports.approveLBTC=Me;exports.claimLBTC=Se;exports.fromSatoshi=G;exports.generateDepositBtcAddress=se;exports.getApiConfig=T;exports.getDepositBtcAddress=oe;exports.getDepositBtcAddresses=U;exports.getDepositsByAddress=de;exports.getLBTCExchageRate=me;exports.getLbtcAddressConfig=W;exports.signLbtcDestionationAddr=Ee;exports.toSatoshi=S;exports.unstakeLBTC=Be;
2
2
  //# sourceMappingURL=index.cjs.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.cjs","sources":["../src/common/types/types.ts","../src/common/const.ts","../src/sdk/apiConfig.ts","../src/common/utils/getErrorMessage.ts","../src/sdk/internalTypes.ts","../src/sdk/utils/getChainNameById.ts","../src/sdk/generateDepositBtcAddress/generateDepositBtcAddress.ts","../src/sdk/getDepositBtcAddress/getDepositBtcAddress.ts","../src/common/utils/convertSatoshi.ts","../src/sdk/utils/getCainIdByName.ts","../src/sdk/getDepositsByAddress/getDepositsByAddress.ts","../src/sdk/getLBTCExchageRate/getLBTCExchageRate.ts","../src/provider/rpcUrlConfig.ts","../src/provider/utils/getMaxPriorityFeePerGas.ts","../src/provider/ReadProvider.ts","../src/provider/Provider.ts","../src/web3Sdk/utils/getGasMultiplier.ts","../src/common/utils/isValidChain.ts","../src/web3Sdk/lbtcAddressConfig.ts","../src/web3Sdk/utils/getTokenABI.ts","../src/web3Sdk/utils/getLbtcTokenContract.ts","../src/web3Sdk/approveLBTC/approveLBTC.ts","../src/web3Sdk/claimLBTC/claimLBTC.ts","../src/web3Sdk/signLbtcDestionationAddr/signLbtcDestionationAddr.ts","../src/btcSdk/utils/getOutputScript.ts","../src/web3Sdk/unstakeLBTC/unstakeLBTC.ts"],"sourcesContent":["export const OEnv = {\n prod: 'prod',\n testnet: 'testnet',\n stage: 'stage',\n} as const;\n\nexport type TEnv = (typeof OEnv)[keyof typeof OEnv];\n\nexport const OChainId = {\n ethereum: 1,\n holesky: 17000,\n} as const;\n\nexport type TChainId = (typeof OChainId)[keyof typeof OChainId];\n\n/**\n * Abstract EIP-1193 provider\n */\nexport interface IEIP1193Provider {\n request: (args: any) => Promise<any>;\n}\n","import { OEnv, TEnv } from './types/types';\n\nexport const defaultEnv: TEnv = OEnv.prod;\n\n/**\n * Address of the zero account.\n * Can also be used as a placeholder for unknown addresses.\n */\nexport const ZERO_ADDRESS = '0x0000000000000000000000000000000000000000';\n","import { defaultEnv } from '../common/const';\nimport { OEnv, TEnv } from '../common/types/types';\n\ninterface IApiConfig {\n baseApiUrl: string;\n}\n\nconst stageConfig: IApiConfig = {\n baseApiUrl: 'https://staging.prod.lombard.finance',\n};\n\nconst testnetConfig: IApiConfig = {\n baseApiUrl: 'https://gastald-testnet.prod.lombard.finance',\n};\n\nconst prodConfig: IApiConfig = {\n baseApiUrl: 'https://mainnet.prod.lombard.finance',\n};\n\nexport const getApiConfig = (env: TEnv = defaultEnv): IApiConfig => {\n switch (env) {\n case OEnv.prod:\n return prodConfig;\n case OEnv.testnet:\n return testnetConfig;\n default:\n return stageConfig;\n }\n};\n","import { AxiosError } from 'axios';\n\n/**\n * Retrieves the error message from the given error object.\n *\n * @param error - The error object.\n * @returns The error message as a string.\n */\nexport function getErrorMessage(error: unknown): string {\n if (typeof error === 'string') {\n return error;\n }\n\n if (error instanceof Error) {\n return getAxiosErrorMessage(error as AxiosError);\n }\n\n return getErrorMessageFromObject(error);\n}\n\nfunction getAxiosErrorMessage(error: AxiosError): string {\n if (error.response) {\n return (error.response.data as { message: string }).message;\n }\n\n return error.message;\n}\n\nfunction getErrorMessageFromObject(error: any): string {\n if (error?.message) {\n return error.message;\n }\n\n return 'Unknown error';\n}\n","export const OChainName = {\n eth: 'DESTINATION_BLOCKCHAIN_ETHEREUM',\n} as const;\n\nexport type TChainName = (typeof OChainName)[keyof typeof OChainName];\n","import { OChainId, TChainId } from '../../common/types/types';\nimport { OChainName, TChainName } from '../internalTypes';\n\n/**\n * @param chainId the chain ID\n *\n * @returns the chain name\n */\nexport function getChainNameById(chainId: TChainId): TChainName {\n switch (chainId) {\n case OChainId.holesky:\n case OChainId.ethereum:\n return OChainName.eth;\n default:\n throw new Error(`Unknown chain ID: ${chainId}`);\n }\n}\n","import axios from 'axios';\nimport { IEnvParam } from '../../common/types/internalTypes';\nimport { TChainId } from '../../common/types/types';\nimport { getErrorMessage } from '../../common/utils/getErrorMessage';\nimport { getApiConfig } from '../apiConfig';\nimport { getChainNameById } from '../utils/getChainNameById';\n\n/**\n * The address wich will be returned if the provided EVM address is sanctioned.\n */\nexport const SANCTIONED_ADDRESS = 'sanctioned_address';\nconst ADDRESS_URL = 'api/v1/address/generate';\nconst SANCTIONS_MESSAGE = 'destination address is under sanctions';\n\ninterface IGenerateNewAddressResponse {\n address: string;\n}\n\nexport interface IGenerateDepositBtcAddressParams extends IEnvParam {\n /**\n * The destination EVM user address where LBTC will be claimed.\n */\n address: string;\n /**\n * The destination chain ID where LBTC will be claimed.\n */\n chainId: TChainId;\n /**\n * The signature of the address. The signature is generated by signing the address using EVM wallet.\n */\n signature: string;\n /**\n * The referral ID.\n */\n referralId: string;\n /**\n * The captcha token.\n */\n captchaToken?: string;\n}\n\n/**\n * Generates a BTC deposit address.\n *\n * If the provided EVM address is sanctioned, the function will return the `SANCTIONED_ADDRESS`.\n *\n * @param {IGenerateDepositBtcAddressParams} params - The parameters for generating the deposit address.\n * @returns {Promise<string>} The generated deposit address.\n */\nexport async function generateDepositBtcAddress({\n address,\n chainId,\n signature,\n referralId,\n env,\n captchaToken,\n}: IGenerateDepositBtcAddressParams): Promise<string> {\n const { baseApiUrl } = getApiConfig(env);\n const toChain = getChainNameById(chainId);\n\n const requestParams = {\n to_address: address,\n to_address_signature: signature,\n to_chain: toChain,\n referral_id: referralId,\n nonce: 0,\n captcha: captchaToken,\n };\n\n try {\n const { data } = await axios.post<IGenerateNewAddressResponse>(\n ADDRESS_URL,\n requestParams,\n { baseURL: baseApiUrl },\n );\n\n return data.address;\n } catch (error) {\n const errorMsg = getErrorMessage(error);\n\n if (isSanctioned(errorMsg)) {\n return SANCTIONED_ADDRESS;\n } else {\n throw new Error(errorMsg);\n }\n }\n}\n\nfunction isSanctioned(errorMsg: string): boolean {\n return !!errorMsg.includes(SANCTIONS_MESSAGE);\n}\n","import axios from 'axios';\nimport { IEnvParam } from '../../common/types/internalTypes';\nimport { TChainId } from '../../common/types/types';\nimport { getApiConfig } from '../apiConfig';\nimport { TChainName } from '../internalTypes';\nimport { getChainNameById } from '../utils/getChainNameById';\n\nconst ADDRESS_URL = 'api/v1/address';\n\ninterface IDepositAddress {\n btc_address: string;\n created_at: string;\n deprecated?: boolean;\n type: string;\n used?: boolean;\n deposit_metadata: {\n to_address: string;\n to_blockchain: TChainName;\n };\n}\n\ninterface IDepositAddressesResponse {\n addresses: IDepositAddress[];\n has_more?: boolean;\n}\n\nexport interface IGetDepositBtcAddressParams extends IEnvParam {\n /**\n * The destination EVM user address where LBTC will be claimed.\n */\n address: string;\n /**\n * The destination chain ID where LBTC will be claimed.\n */\n chainId: TChainId;\n /**\n * The referral ID.\n */\n referralId: string;\n}\n\n/**\n * Returns the address for depositing BTC.\n *\n * @param {IGetDepositBtcAddressParams} params - function parameters\n *\n * @returns {Promise<string>} the address for depositing BTC\n */\nexport async function getDepositBtcAddress({\n address,\n chainId,\n env,\n referralId,\n}: IGetDepositBtcAddressParams): Promise<string> {\n const addresses = await getDepositBtcAddresses({\n address,\n chainId,\n env,\n referralId,\n });\n\n const addressData = getActualAddress(addresses);\n\n if (!addressData) {\n throw new Error('No address');\n }\n\n return addressData.btc_address;\n}\n\n/**\n * Retrieves the actual deposit address from a list of deposit addresses.\n *\n * @param addresses - The list of deposit addresses.\n * @returns The actual deposit address or undefined if the last created address is deprecated.\n */\nfunction getActualAddress(\n addresses: IDepositAddress[],\n): IDepositAddress | undefined {\n if (!addresses.length) {\n return undefined;\n }\n\n const actualAddress = addresses.reduce((acc, address) => {\n if (acc.created_at < address.created_at) {\n return address;\n }\n return acc;\n }, addresses[0]);\n\n return actualAddress.deprecated ? undefined : actualAddress;\n}\n\n/**\n * Returns the addresses for depositing BTC.\n *\n * @param {IGetDepositBtcAddressParams} params - function parameters\n *\n * @returns {Promise<IDepositAddress[]>} the deposit addresses\n */\nexport async function getDepositBtcAddresses({\n address,\n chainId,\n env,\n referralId,\n}: IGetDepositBtcAddressParams): Promise<IDepositAddress[]> {\n const { baseApiUrl } = getApiConfig(env);\n const toBlockchain = getChainNameById(chainId);\n\n const requestrParams = {\n to_address: address,\n to_blockchain: toBlockchain,\n limit: 1,\n offset: 0,\n asc: false,\n referral_id: referralId,\n };\n\n const { data } = await axios.get<IDepositAddressesResponse>(ADDRESS_URL, {\n baseURL: baseApiUrl,\n params: requestrParams,\n });\n\n return data?.addresses || [];\n}\n","const BTC_DECIMALS = 8;\nconst SATOSHI_SCALE = 10 ** BTC_DECIMALS;\n\n/**\n * Convert Satoshi to BTC\n * @param amount - Satoshi amount\n * @returns BTC amount\n */\nexport function fromSatoshi(amount: number | string) {\n return +amount / SATOSHI_SCALE;\n}\n\n/**\n * Convert BTC to Satoshi\n *\n * @param amount - BTC amount\n * @returns Satoshi amount\n */\nexport function toSatoshi(amount: number | string) {\n return Math.floor(+amount * SATOSHI_SCALE);\n}\n","import { defaultEnv } from '../../common/const';\nimport { OChainId, OEnv, TChainId, TEnv } from '../../common/types/types';\nimport { TChainName } from '../internalTypes';\n\n/**\n * @param chainId the chain ID\n *\n * @returns the chain name\n */\nexport function getCainIdByName(\n chain: string,\n env: TEnv = defaultEnv,\n): TChainId {\n switch (chain as TChainName) {\n case 'DESTINATION_BLOCKCHAIN_ETHEREUM':\n return env === OEnv.prod ? OChainId.ethereum : OChainId.holesky;\n\n default:\n return OChainId.ethereum;\n }\n}\n","import axios from 'axios';\nimport { IEnvParam } from '../../common/types/internalTypes';\nimport { TChainId, TEnv } from '../../common/types/types';\nimport { fromSatoshi } from '../../common/utils/convertSatoshi';\nimport { getApiConfig } from '../apiConfig';\nimport { getCainIdByName } from '../utils/getCainIdByName';\n\ntype Address = string;\ntype Seconds = number;\n\ninterface IDepositResponse {\n txid: string;\n value: number;\n address: Address;\n to_chain: string;\n notarization_wait_dur?: string | number;\n index?: number;\n raw_payload?: string;\n payload?: string;\n signature?: string;\n claim_tx?: string;\n block_height?: string;\n block_time?: string;\n sanctioned?: boolean;\n}\n\ninterface IDepositsByAddressResponse {\n outputs: IDepositResponse[];\n}\n\nexport interface IDeposit {\n txid: string;\n index?: number;\n blockHeight?: number;\n blockTime?: number;\n value: number;\n address: Address;\n chainId: TChainId;\n isClaimed: boolean;\n rawPayload?: string;\n signature?: string;\n isRestricted?: boolean;\n notarizationWaitDur?: Seconds;\n}\n\nexport interface IGetDepositsByAddressParams extends IEnvParam {\n /**\n * The EVM address to get deposits for\n */\n address: Address;\n}\n\n/**\n * Returns all deposits for a given address\n *\n * @param {IGetDepositsByAddressParams} params\n *\n * @returns {Promise<IDeposit[]>} a list of deposits\n */\nexport async function getDepositsByAddress({\n address,\n env,\n}: IGetDepositsByAddressParams): Promise<IDeposit[]> {\n const { baseApiUrl } = getApiConfig(env);\n\n const { data } = await axios.get<IDepositsByAddressResponse | undefined>(\n `api/v1/address/outputs/${address}`,\n { baseURL: baseApiUrl },\n );\n\n const outputs = data?.outputs ?? [];\n\n return outputs.map(mapResponse(env));\n}\n\nfunction mapResponse(env?: TEnv) {\n return (data: IDepositResponse): IDeposit => ({\n txid: data.txid,\n index: data.index ?? 0,\n blockHeight: data.block_height ? Number(data.block_height) : undefined,\n blockTime: data.block_time ? Number(data.block_time) : undefined,\n value: fromSatoshi(data.value),\n address: data.address,\n chainId: getCainIdByName(data.to_chain, env),\n // todo: return claiming tx from the API when it's available\n isClaimed: !!data.claim_tx,\n rawPayload: data.raw_payload,\n signature: data.signature,\n isRestricted: !!data.sanctioned,\n notarizationWaitDur: data.notarization_wait_dur\n ? Number(data.notarization_wait_dur)\n : undefined,\n });\n}\n","import axios from 'axios';\nimport { IEnvParam } from '../../common/types/internalTypes';\nimport { TChainId } from '../../common/types/types';\nimport { getApiConfig } from '../apiConfig';\nimport { getChainNameById } from '../utils/getChainNameById';\n\ntype ExchangeRateResponse = {\n amount_out: string;\n};\n\nexport interface IGetLBTCExchageRateParams extends IEnvParam {\n /**\n * The chain id of the asset to get the exchange rate for\n */\n chainId: TChainId;\n /**\n * The amount of the asset to get the exchange rate for\n */\n amount: number;\n}\n\n/**\n * Retrieves the exchange rate for LBTC.\n *\n * @param {IGetLBTCExchageRateParams} params\n *\n * @returns {Promise<string>} - The exchange rate.\n */\nexport async function getLBTCExchageRate({\n env,\n chainId,\n amount,\n}: IGetLBTCExchageRateParams): Promise<string> {\n const { baseApiUrl } = getApiConfig(env);\n const chainIdName = getChainNameById(chainId);\n\n const { data } = await axios.get<ExchangeRateResponse>(\n `api/v1/exchange/rate/${chainIdName}`,\n { baseURL: baseApiUrl, params: { amount } },\n );\n\n return data.amount_out;\n}\n","import { OChainId } from '../common/types/types';\n\nexport type TRpcUrlConfig = Record<number, string>;\n\nexport const rpcUrlConfig: TRpcUrlConfig = {\n [OChainId.ethereum]: 'https://rpc.ankr.com/eth',\n [OChainId.holesky]: 'https://rpc.ankr.com/eth_holesky',\n};\n","import BigNumber from 'bignumber.js';\nimport Web3 from 'web3';\n\nexport async function getMaxPriorityFeePerGas(\n rpcUrl: string,\n): Promise<BigNumber> {\n const response = await fetch(rpcUrl, {\n method: 'POST',\n headers: {\n 'Content-Type': 'application/json',\n },\n body: JSON.stringify({\n jsonrpc: '2.0',\n id: 1,\n method: 'eth_maxPriorityFeePerGas',\n params: [],\n }),\n });\n\n const data = await response.json();\n\n const convertedHexValue = Web3.utils.hexToNumber(data?.result);\n\n return new BigNumber(Number(convertedHexValue));\n}\n","import BigNumber from 'bignumber.js';\nimport Web3, { Contract, ContractAbi } from 'web3';\nimport {\n TRpcUrlConfig,\n rpcUrlConfig as defaultRpcUrlConfig,\n} from './rpcUrlConfig';\nimport { IGetMaxFeesResult } from './types';\nimport { getMaxPriorityFeePerGas } from './utils/getMaxPriorityFeePerGas';\n\nconst FEE_MULTIPLIER = 2;\nconst ADDITIONAL_SAFE_GAS_PRICE_WEI = 25_000;\n\nexport interface IReadProviderParams {\n /**\n * Chain ID of the network to interact with.\n */\n chainId: number;\n /**\n * The RPC URL configuration. If not provided, the default configuration will be used.\n */\n rpcUrlConfig?: TRpcUrlConfig;\n}\n\nexport class ReadProvider {\n chainId: number;\n rpcConfig: TRpcUrlConfig;\n\n constructor({ chainId, rpcUrlConfig }: IReadProviderParams) {\n this.chainId = chainId;\n this.rpcConfig = { ...defaultRpcUrlConfig, ...rpcUrlConfig };\n }\n\n /**\n * Returns web3 instance for read operations.\n *\n * @public\n * @returns {Web3} Web3 instance.\n */\n public getReadWeb3(): Web3 {\n const rpcUrl = this.getRpcUrl();\n const readWeb3 = new Web3();\n const provider = new Web3.providers.HttpProvider(rpcUrl);\n readWeb3.setProvider(provider);\n return readWeb3;\n }\n\n /**\n * Retrieves the RPC URL based on the current chain ID.\n * @returns The RPC URL for the current chain ID.\n * @throws Error if the RPC URL for the current chain ID is not found.\n */\n getRpcUrl(): string {\n const { chainId } = this;\n const rpcUrl = this.rpcConfig?.[chainId];\n\n if (!rpcUrl) {\n console.error(\n `You might need to add the rpcConfig for the ${chainId} chain ID when creating the provider.`,\n );\n throw new Error(`RPC URL for chainId ${chainId} not found`);\n }\n\n return rpcUrl;\n }\n\n /**\n * Calculates max fees for transaction. Thess values are available for networks\n * with EIP-1559 support.\n *\n * @public\n * @note If current network is Binance Smart Chain, will return default values.\n * @returns {Promise<IGetMaxFeesResult>} Max fees for transaction.\n */\n public async getMaxFees(): Promise<IGetMaxFeesResult> {\n const web3 = this.getReadWeb3();\n const rpcUrl = this.getRpcUrl();\n\n const [block, maxPriorityFeePerGas] = await Promise.all([\n web3.eth.getBlock('latest'),\n getMaxPriorityFeePerGas(rpcUrl),\n ]);\n\n if (!block?.baseFeePerGas && typeof block?.baseFeePerGas !== 'bigint') {\n return {};\n }\n\n const maxFeePerGas = new BigNumber(block.baseFeePerGas.toString(10))\n .multipliedBy(FEE_MULTIPLIER)\n .plus(maxPriorityFeePerGas);\n\n return {\n maxFeePerGas: +maxFeePerGas,\n maxPriorityFeePerGas: +maxPriorityFeePerGas,\n };\n }\n\n /**\n * Returns safe gas price for transaction.\n *\n * @public\n * @returns {Promise<BigNumber>} Safe gas price.\n */\n public async getSafeGasPriceWei(): Promise<BigNumber> {\n const pureGasPriceWei = await this.getReadWeb3().eth.getGasPrice();\n\n return new BigNumber(pureGasPriceWei.toString(10)).plus(\n ADDITIONAL_SAFE_GAS_PRICE_WEI,\n );\n }\n\n /**\n * Creates a contract instance with the given ABI and address.\n *\n * @template AbiType - The type of the contract ABI.\n * @param {any} abi - The ABI of the contract.\n * @param {string} address - The address of the contract.\n * @returns {Contract<AbiType>} The contract instance.\n */\n public createContract<AbiType extends ContractAbi>(\n abi: any,\n address: string,\n ): Contract<AbiType> {\n const web3 = this.getReadWeb3();\n return new web3.eth.Contract<AbiType>(abi, address);\n }\n}\n","import Web3, { Contract, ContractAbi, Transaction, utils } from 'web3';\nimport { IEIP1193Provider } from '../common/types/types';\nimport { IReadProviderParams, ReadProvider } from './ReadProvider';\nimport {\n TRpcUrlConfig,\n rpcUrlConfig as defaultRpcUrlConfig,\n} from './rpcUrlConfig';\nimport { ISendOptions, IWeb3SendResult } from './types';\n\nexport interface IProviderParams extends IReadProviderParams {\n /**\n * The EIP-1193 provider instance.\n */\n provider: IEIP1193Provider;\n /**\n * The сurrent account address.\n */\n account: string;\n}\n\n/**\n * Provider for interacting with a blockchain network.\n */\nexport class Provider extends ReadProvider {\n web3: Web3;\n account: string;\n rpcConfig: TRpcUrlConfig;\n\n constructor({ provider, account, chainId, rpcUrlConfig }: IProviderParams) {\n super({ chainId, rpcUrlConfig });\n this.web3 = new Web3(provider);\n this.account = account;\n this.chainId = chainId;\n this.rpcConfig = { ...defaultRpcUrlConfig, ...rpcUrlConfig };\n }\n\n /**\n * Signs a message using the current provider and account.\n * @public\n * @param message - The message to be signed.\n * @returns A promise that resolves to the signed message as a string.\n */\n public async signMessage(message: string): Promise<string> {\n const { account } = this;\n\n const messageHex = `0x${Buffer.from(message, 'utf8').toString('hex')}`;\n\n const ethereum = this.web3.currentProvider as any;\n\n return ethereum.request({\n method: 'personal_sign',\n params: [messageHex, account],\n });\n }\n\n /**\n * Custom replacement for web3js [send](https://docs.web3js.org/libdocs/Contract#send).\n *\n * @public\n * @param {string} from - Address of the sender.\n * @param {string} to - Address of the recipient.\n * @param {ISendOptions} sendOptions - Options for sending transaction.\n * @returns {Promise<IWeb3SendResult>} Promise with transaction hash and receipt promise.\n */\n public async sendTransactionAsync(\n from: string,\n to: string,\n sendOptions: ISendOptions,\n ): Promise<IWeb3SendResult> {\n const { chainId, web3: web3Write } = this;\n const web3Read = this.getReadWeb3();\n\n const {\n data,\n estimate = false,\n estimateFee = false,\n extendedGasLimit,\n gasLimit = '0',\n value = '0',\n gasLimitMultiplier = 1,\n } = sendOptions;\n let { nonce } = sendOptions;\n\n if (!nonce) {\n nonce = await web3Read.eth.getTransactionCount(from);\n }\n\n console.log(`Nonce: ${nonce}`);\n\n const tx: Transaction = {\n from,\n to,\n value: utils.numberToHex(value),\n data,\n nonce,\n chainId: utils.numberToHex(chainId),\n };\n\n if (estimate) {\n try {\n const estimatedGas = await web3Read.eth.estimateGas(tx);\n const multipliedGasLimit = Math.round(\n Number(estimatedGas) * gasLimitMultiplier,\n );\n\n if (extendedGasLimit) {\n tx.gas = utils.numberToHex(multipliedGasLimit + extendedGasLimit);\n } else {\n tx.gas = utils.numberToHex(multipliedGasLimit);\n }\n } catch (e) {\n throw new Error(\n (e as Partial<Error>).message ??\n 'Failed to estimate gas limit for transaction.',\n );\n }\n } else {\n tx.gas = utils.numberToHex(gasLimit);\n }\n\n const { maxFeePerGas, maxPriorityFeePerGas } = estimateFee\n ? await this.getMaxFees().catch(() => sendOptions)\n : sendOptions;\n\n if (maxPriorityFeePerGas !== undefined) {\n tx.maxPriorityFeePerGas = utils.numberToHex(maxPriorityFeePerGas);\n }\n\n if (maxFeePerGas !== undefined) {\n tx.maxFeePerGas = utils.numberToHex(maxFeePerGas);\n }\n\n if (!tx.maxFeePerGas && !tx.maxPriorityFeePerGas) {\n const safeGasPrice = await this.getSafeGasPriceWei();\n tx.gasPrice = safeGasPrice.toString(10);\n }\n\n if (!tx.maxFeePerGas && !tx.maxPriorityFeePerGas) {\n const safeGasPrice = await this.getSafeGasPriceWei();\n tx.gasPrice = safeGasPrice.toString(10);\n }\n\n console.log('Sending transaction via Web3: ', tx);\n\n return new Promise((resolve, reject) => {\n const promise = web3Write.eth.sendTransaction(tx);\n\n promise\n .once('transactionHash', async (transactionHash: string) => {\n console.log(`Just signed transaction has is: ${transactionHash}`);\n\n resolve({\n receiptPromise: promise,\n transactionHash,\n });\n })\n .catch(reject);\n });\n }\n\n public createContract<AbiType extends ContractAbi>(\n abi: any,\n address: string,\n ): Contract<AbiType> {\n return new this.web3.eth.Contract<AbiType>(abi, address);\n }\n}\n","import { OChainId } from '../../common/types/types';\n\n/**\n * Returns the gas multiplier for the given chain ID.\n *\n * @param chainId - Chain ID.\n *\n * @returns Gas multiplier.\n */\nexport function getGasMultiplier(chainId: number): number {\n switch (chainId) {\n case OChainId.ethereum:\n return 1.3;\n case OChainId.holesky:\n return 1.5;\n default:\n return 1.3;\n }\n}\n","import { OChainId, TChainId } from '../types/types';\n\nexport function isValidChain(chainId: number): chainId is TChainId {\n return Object.values(OChainId).includes(chainId as TChainId);\n}\n","import {\n defaultEnv,\n ZERO_ADDRESS as PLACEHOLDER_ADDRESS,\n} from '../common/const';\nimport { OChainId, OEnv, TChainId, TEnv } from '../common/types/types';\n\ntype LbtcTokenConfig = Record<TChainId, string>;\n\nconst stageConfig: LbtcTokenConfig = {\n [OChainId.holesky]: '0xED7bfd5C1790576105Af4649817f6d35A75CD818',\n [OChainId.ethereum]: PLACEHOLDER_ADDRESS,\n};\n\nconst testnetConfig: LbtcTokenConfig = {\n [OChainId.holesky]: '0x38A13AB20D15ffbE5A7312d2336EF1552580a4E2',\n [OChainId.ethereum]: PLACEHOLDER_ADDRESS,\n};\n\nconst prodConfig: LbtcTokenConfig = {\n [OChainId.holesky]: PLACEHOLDER_ADDRESS,\n [OChainId.ethereum]: '0x8236a87084f8b84306f72007f36f2618a5634494',\n};\n\nexport function getLbtcAddressConfig(env: TEnv = defaultEnv): LbtcTokenConfig {\n switch (env) {\n case OEnv.prod:\n return prodConfig;\n case OEnv.testnet:\n return testnetConfig;\n default:\n return stageConfig;\n }\n}\n","import { IERC20, LBTCABI } from '../abi';\n\ntype Token = 'LBTC' | 'ERC20';\n\nexport function getTokenABI(token: Token) {\n switch (token) {\n case 'LBTC':\n return LBTCABI;\n default:\n return IERC20;\n }\n}\n","import { TEnv } from '../../common/types/types';\nimport { isValidChain } from '../../common/utils/isValidChain';\nimport { Provider } from '../../provider';\nimport { getLbtcAddressConfig } from '../lbtcAddressConfig';\nimport { getTokenABI } from './getTokenABI';\n\nexport function getLbtcTokenContract(provider: Provider, env?: TEnv) {\n const lbtcAddressConfig = getLbtcAddressConfig(env);\n const { chainId } = provider;\n\n if (!isValidChain(chainId)) {\n throw new Error(`This chain ${chainId} is not supported`);\n }\n\n const tokenAddress = lbtcAddressConfig[chainId];\n\n if (!tokenAddress) {\n throw new Error(`Token address for chain ${chainId} is not defined`);\n }\n\n const abi = getTokenABI('LBTC');\n\n const contract = provider.createContract(abi, tokenAddress);\n\n if (!contract.options.address) {\n contract.options.address = tokenAddress;\n }\n\n return contract as typeof contract & {\n options: typeof contract.options & { address: string };\n };\n}\n","import { IEnvParam } from '../../common/types/internalTypes';\nimport { toSatoshi } from '../../common/utils/convertSatoshi';\nimport { IWeb3SendResult, Provider } from '../../provider';\nimport { IProviderBasedParams } from '../types';\nimport { getGasMultiplier } from '../utils/getGasMultiplier';\nimport { getLbtcTokenContract } from '../utils/getLbtcTokenContract';\n\nexport interface IApproveLBTCParams extends IProviderBasedParams, IEnvParam {\n /**\n * Spender address\n */\n spender: string;\n /**\n * The amount of LBTC to approve\n */\n amount: number;\n}\n\n/**\n * Approves the transfer of a specified amount of LBTC tokens.\n *\n * @param {IApproveLBTCParams} params\n *\n * @returns {Promise<IWeb3SendResult>} transaction promise\n */\nexport function approveLBTC({\n spender,\n amount,\n env,\n ...providerParams\n}: IApproveLBTCParams): Promise<IWeb3SendResult> {\n const provider = new Provider(providerParams);\n const tokenContract = getLbtcTokenContract(provider, env);\n const amountSat = toSatoshi(amount);\n\n const tx = tokenContract.methods.approve(spender, amountSat);\n\n return provider.sendTransactionAsync(\n provider.account,\n tokenContract.options.address,\n {\n data: tx.encodeABI(),\n estimate: true,\n estimateFee: true,\n gasLimitMultiplier: getGasMultiplier(provider.chainId),\n },\n );\n}\n","import { IEnvParam } from '../../common/types/internalTypes';\nimport { getErrorMessage } from '../../common/utils/getErrorMessage';\nimport { IWeb3SendResult, Provider } from '../../provider';\nimport { IProviderBasedParams } from '../types';\nimport { getGasMultiplier } from '../utils/getGasMultiplier';\nimport { getLbtcTokenContract } from '../utils/getLbtcTokenContract';\n\nconst INSUFFICIENT_FUNDS_PARTIAL_ERROR = 'insufficient funds';\n\nconst INSUFFICIENT_FUNDS_ERROR =\n 'Insufficient funds for transfer. Make sure you have enough ETH to cover the gas cost.';\n\nexport interface IClaimLBTCParams extends IProviderBasedParams, IEnvParam {\n /**\n * Raw payload from deposit notarization.\n */\n data: string;\n /**\n * Signature from deposit notarization.\n */\n proofSignature: string;\n}\n\n/**\n * Claims LBTC.\n *\n * @param {IClaimLBTCParams} params - The parameters for claiming LBTC.\n *\n * @returns {Promise<IWeb3SendResult>} transaction promise\n */\nexport async function claimLBTC({\n data,\n proofSignature,\n env,\n ...providerParams\n}: IClaimLBTCParams): Promise<IWeb3SendResult> {\n const provider = new Provider(providerParams);\n const tokenContract = getLbtcTokenContract(provider, env);\n\n const tx = tokenContract.methods.mint(data, proofSignature);\n\n try {\n const result = await provider.sendTransactionAsync(\n provider.account,\n tokenContract.options.address,\n {\n data: tx.encodeABI(),\n estimate: true,\n estimateFee: true,\n gasLimitMultiplier: getGasMultiplier(provider.chainId),\n },\n );\n\n return result;\n } catch (error) {\n const errorMessage = getErrorMessage(error);\n\n if (errorMessage.includes(INSUFFICIENT_FUNDS_PARTIAL_ERROR)) {\n throw new Error(INSUFFICIENT_FUNDS_ERROR);\n }\n\n throw new Error(errorMessage);\n }\n}\n","import { Provider } from '../../provider';\nimport { IProviderBasedParams } from '../types';\n\nexport type SignLbtcDestionationAddrParams = IProviderBasedParams;\n\n/**\n * Signs the destination address for the LBTC in active chain\n * in the current account. Signing is necessary for the\n * generation of the deposit address.\n *\n * @param {SignLbtcDestionationAddrParams} params\n *\n * @returns {Promise<string>} The signature of the message.\n */\nexport async function signLbtcDestionationAddr(\n params: SignLbtcDestionationAddrParams,\n): Promise<string> {\n const provider = new Provider(params);\n\n const message = `destination chain id is ${params.chainId}`;\n\n return provider.signMessage(message);\n}\n","import * as ecc from '@bitcoin-js/tiny-secp256k1-asmjs';\nimport {\n address as addressUtils,\n initEccLib,\n networks,\n payments,\n} from 'bitcoinjs-lib';\nimport { OEnv, TEnv } from '../../common/types/types';\n\ninitEccLib(ecc);\n\n/**\n * Get output script from address.\n *\n * @param address - The address.\n * @param networkMode - The network mode.\n *\n * @returns The output script.\n */\nexport function getOutputScript(\n address: string,\n env: TEnv = OEnv.prod,\n): string {\n const paymentType = getPaymentType(address);\n\n const payment = payments[paymentType]({\n address,\n network: env === OEnv.prod ? networks.bitcoin : networks.testnet,\n });\n\n const paymentOutputScript = payment.output?.toString('hex');\n\n if (!paymentOutputScript) {\n throw new Error('Output script is not found.');\n }\n\n return `0x${paymentOutputScript}`;\n}\n\nfunction getPaymentType(address: string): 'p2tr' | 'p2wpkh' {\n const result = addressUtils.fromBech32(address);\n\n const isP2TR = result.version === 1 && result.data.length === 32;\n if (isP2TR) {\n return 'p2tr';\n }\n\n const isP2WPKH = result.version === 0 && result.data.length === 20;\n if (isP2WPKH) {\n return 'p2wpkh';\n }\n\n throw new Error('Payment type is not supported.');\n}\n","import { getOutputScript } from '../../btcSdk/utils/getOutputScript';\nimport { IEnvParam } from '../../common/types/internalTypes';\nimport { toSatoshi } from '../../common/utils/convertSatoshi';\nimport { IWeb3SendResult, Provider } from '../../provider';\nimport { IProviderBasedParams } from '../types';\nimport { getGasMultiplier } from '../utils/getGasMultiplier';\nimport { getLbtcTokenContract } from '../utils/getLbtcTokenContract';\n\nexport interface IUnstakeLBTCParams extends IProviderBasedParams, IEnvParam {\n /**\n * The BTC address to send the unstaked BTC to.\n */\n btcAddress: string;\n /**\n * The amount of LBTC to unstake.\n */\n amount: number;\n}\n\n/**\n * Unstakes LBTC to the specified BTC address.\n *\n * @param {IUnstakeLBTCParams} params\n *\n * @returns {Promise<IWeb3SendResult>} transaction promise\n */\nexport function unstakeLBTC({\n btcAddress,\n amount,\n env,\n ...providerParams\n}: IUnstakeLBTCParams): Promise<IWeb3SendResult> {\n const provider = new Provider(providerParams);\n const tokenContract = getLbtcTokenContract(provider, env);\n const outputScript = getOutputScript(btcAddress, env);\n\n const amountSat = toSatoshi(amount);\n\n const tx = tokenContract.methods.redeem(outputScript, amountSat);\n\n return provider.sendTransactionAsync(\n provider.account,\n tokenContract.options.address,\n {\n data: tx.encodeABI(),\n estimate: true,\n estimateFee: true,\n gasLimitMultiplier: getGasMultiplier(provider.chainId),\n },\n );\n}\n"],"names":["OEnv","OChainId","defaultEnv","ZERO_ADDRESS","stageConfig","testnetConfig","prodConfig","getApiConfig","env","getErrorMessage","error","getAxiosErrorMessage","getErrorMessageFromObject","OChainName","getChainNameById","chainId","SANCTIONED_ADDRESS","ADDRESS_URL","SANCTIONS_MESSAGE","generateDepositBtcAddress","address","signature","referralId","captchaToken","baseApiUrl","toChain","requestParams","data","axios","errorMsg","isSanctioned","getDepositBtcAddress","addresses","getDepositBtcAddresses","addressData","getActualAddress","actualAddress","acc","toBlockchain","requestrParams","BTC_DECIMALS","SATOSHI_SCALE","fromSatoshi","amount","toSatoshi","getCainIdByName","chain","getDepositsByAddress","mapResponse","getLBTCExchageRate","chainIdName","rpcUrlConfig","getMaxPriorityFeePerGas","rpcUrl","convertedHexValue","Web3","BigNumber","FEE_MULTIPLIER","ADDITIONAL_SAFE_GAS_PRICE_WEI","ReadProvider","__publicField","defaultRpcUrlConfig","readWeb3","provider","_a","web3","block","maxPriorityFeePerGas","pureGasPriceWei","abi","Provider","account","message","messageHex","from","to","sendOptions","web3Write","web3Read","estimate","estimateFee","extendedGasLimit","gasLimit","value","gasLimitMultiplier","nonce","tx","utils","estimatedGas","multipliedGasLimit","e","maxFeePerGas","safeGasPrice","resolve","reject","promise","transactionHash","getGasMultiplier","isValidChain","PLACEHOLDER_ADDRESS","getLbtcAddressConfig","getTokenABI","token","LBTCABI","IERC20","getLbtcTokenContract","lbtcAddressConfig","tokenAddress","contract","approveLBTC","spender","providerParams","tokenContract","amountSat","INSUFFICIENT_FUNDS_PARTIAL_ERROR","INSUFFICIENT_FUNDS_ERROR","claimLBTC","proofSignature","errorMessage","signLbtcDestionationAddr","params","initEccLib","ecc","getOutputScript","paymentType","getPaymentType","paymentOutputScript","payments","networks","result","addressUtils","unstakeLBTC","btcAddress","outputScript"],"mappings":"gqBAAaA,EAAO,CAClB,KAAM,OACN,QAAS,UACT,MAAO,OACT,EAIaC,EAAW,CACtB,SAAU,EACV,QAAS,IACX,ECTaC,EAAmBF,EAAK,KAMxBG,EAAe,6CCDtBC,EAA0B,CAC9B,WAAY,sCACd,EAEMC,EAA4B,CAChC,WAAY,8CACd,EAEMC,EAAyB,CAC7B,WAAY,sCACd,EAEaC,EAAe,CAACC,EAAYN,IAA2B,CAClE,OAAQM,EAAK,CACX,KAAKR,EAA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"index.cjs","sources":["../src/common/types/types.ts","../src/common/const.ts","../src/sdk/apiConfig.ts","../src/common/utils/getErrorMessage.ts","../src/sdk/internalTypes.ts","../src/sdk/utils/getChainNameById.ts","../src/sdk/generateDepositBtcAddress/generateDepositBtcAddress.ts","../src/sdk/getDepositBtcAddress/getDepositBtcAddress.ts","../src/common/utils/convertSatoshi.ts","../src/sdk/utils/getCainIdByName.ts","../src/sdk/getDepositsByAddress/getDepositsByAddress.ts","../src/sdk/getLBTCExchageRate/getLBTCExchageRate.ts","../src/provider/rpcUrlConfig.ts","../src/provider/utils/getMaxPriorityFeePerGas.ts","../src/provider/ReadProvider.ts","../src/provider/Provider.ts","../src/web3Sdk/utils/getGasMultiplier.ts","../src/common/utils/isValidChain.ts","../src/web3Sdk/lbtcAddressConfig.ts","../src/web3Sdk/utils/getTokenABI.ts","../src/web3Sdk/utils/getLbtcTokenContract.ts","../src/web3Sdk/approveLBTC/approveLBTC.ts","../src/web3Sdk/claimLBTC/claimLBTC.ts","../src/web3Sdk/signLbtcDestionationAddr/signLbtcDestionationAddr.ts","../src/btcSdk/utils/getOutputScript.ts","../src/web3Sdk/unstakeLBTC/unstakeLBTC.ts"],"sourcesContent":["export const OEnv = {\n prod: 'prod',\n testnet: 'testnet',\n stage: 'stage',\n} as const;\n\nexport type TEnv = (typeof OEnv)[keyof typeof OEnv];\n\nexport const OChainId = {\n ethereum: 1,\n holesky: 17000,\n} as const;\n\nexport type TChainId = (typeof OChainId)[keyof typeof OChainId];\n\n/**\n * Abstract EIP-1193 provider\n */\nexport interface IEIP1193Provider {\n request: (args: any) => Promise<any>;\n}\n","import { OEnv, TEnv } from './types/types';\n\nexport const defaultEnv: TEnv = OEnv.prod;\n\n/**\n * Address of the zero account.\n * Can also be used as a placeholder for unknown addresses.\n */\nexport const ZERO_ADDRESS = '0x0000000000000000000000000000000000000000';\n","import { defaultEnv } from '../common/const';\nimport { OEnv, TEnv } from '../common/types/types';\n\ninterface IApiConfig {\n baseApiUrl: string;\n}\n\nconst stageConfig: IApiConfig = {\n baseApiUrl: 'https://staging.prod.lombard.finance',\n};\n\nconst testnetConfig: IApiConfig = {\n baseApiUrl: 'https://gastald-testnet.prod.lombard.finance',\n};\n\nconst prodConfig: IApiConfig = {\n baseApiUrl: 'https://mainnet.prod.lombard.finance',\n};\n\nexport const getApiConfig = (env: TEnv = defaultEnv): IApiConfig => {\n switch (env) {\n case OEnv.prod:\n return prodConfig;\n case OEnv.testnet:\n return testnetConfig;\n default:\n return stageConfig;\n }\n};\n","import { AxiosError } from 'axios';\n\n/**\n * Retrieves the error message from the given error object.\n *\n * @param error - The error object.\n * @returns The error message as a string.\n */\nexport function getErrorMessage(error: unknown): string {\n if (typeof error === 'string') {\n return error;\n }\n\n if (error instanceof Error) {\n return getAxiosErrorMessage(error as AxiosError);\n }\n\n return getErrorMessageFromObject(error);\n}\n\nfunction getAxiosErrorMessage(error: AxiosError): string {\n if (error.response) {\n return (error.response.data as { message: string }).message;\n }\n\n return error.message;\n}\n\nfunction getErrorMessageFromObject(error: any): string {\n if (error?.message) {\n return error.message;\n }\n\n return 'Unknown error';\n}\n","export const OChainName = {\n eth: 'DESTINATION_BLOCKCHAIN_ETHEREUM',\n} as const;\n\nexport type TChainName = (typeof OChainName)[keyof typeof OChainName];\n","import { OChainId, TChainId } from '../../common/types/types';\nimport { OChainName, TChainName } from '../internalTypes';\n\n/**\n * @param chainId the chain ID\n *\n * @returns the chain name\n */\nexport function getChainNameById(chainId: TChainId): TChainName {\n switch (chainId) {\n case OChainId.holesky:\n case OChainId.ethereum:\n return OChainName.eth;\n default:\n throw new Error(`Unknown chain ID: ${chainId}`);\n }\n}\n","import axios from 'axios';\nimport { IEnvParam } from '../../common/types/internalTypes';\nimport { TChainId } from '../../common/types/types';\nimport { getErrorMessage } from '../../common/utils/getErrorMessage';\nimport { getApiConfig } from '../apiConfig';\nimport { getChainNameById } from '../utils/getChainNameById';\n\n/**\n * The address wich will be returned if the provided EVM address is sanctioned.\n */\nexport const SANCTIONED_ADDRESS = 'sanctioned_address';\nconst ADDRESS_URL = 'api/v1/address/generate';\nconst SANCTIONS_MESSAGE = 'destination address is under sanctions';\n\ninterface IGenerateNewAddressResponse {\n address: string;\n}\n\nexport interface IGenerateDepositBtcAddressParams extends IEnvParam {\n /**\n * The destination EVM user address where LBTC will be claimed.\n */\n address: string;\n /**\n * The destination chain ID where LBTC will be claimed.\n */\n chainId: TChainId;\n /**\n * The signature of the address. The signature is generated by signing the address using EVM wallet.\n */\n signature: string;\n /**\n * The referral ID.\n */\n referralId: string;\n /**\n * The captcha token.\n */\n captchaToken?: string;\n}\n\n/**\n * Generates a BTC deposit address.\n *\n * If the provided EVM address is sanctioned, the function will return the `SANCTIONED_ADDRESS`.\n *\n * @param {IGenerateDepositBtcAddressParams} params - The parameters for generating the deposit address.\n * @returns {Promise<string>} The generated deposit address.\n */\nexport async function generateDepositBtcAddress({\n address,\n chainId,\n signature,\n referralId,\n env,\n captchaToken,\n}: IGenerateDepositBtcAddressParams): Promise<string> {\n const { baseApiUrl } = getApiConfig(env);\n const toChain = getChainNameById(chainId);\n\n const requestParams = {\n to_address: address,\n to_address_signature: signature,\n to_chain: toChain,\n referral_id: referralId,\n nonce: 0,\n captcha: captchaToken,\n };\n\n try {\n const { data } = await axios.post<IGenerateNewAddressResponse>(\n ADDRESS_URL,\n requestParams,\n { baseURL: baseApiUrl },\n );\n\n return data.address;\n } catch (error) {\n const errorMsg = getErrorMessage(error);\n\n if (isSanctioned(errorMsg)) {\n return SANCTIONED_ADDRESS;\n } else {\n throw new Error(errorMsg);\n }\n }\n}\n\nfunction isSanctioned(errorMsg: string): boolean {\n return !!errorMsg.includes(SANCTIONS_MESSAGE);\n}\n","import axios from 'axios';\nimport { IEnvParam } from '../../common/types/internalTypes';\nimport { TChainId } from '../../common/types/types';\nimport { getApiConfig } from '../apiConfig';\nimport { TChainName } from '../internalTypes';\nimport { getChainNameById } from '../utils/getChainNameById';\n\nconst ADDRESS_URL = 'api/v1/address';\n\ninterface IDepositAddress {\n btc_address: string;\n created_at: string;\n deprecated?: boolean;\n type: string;\n used?: boolean;\n deposit_metadata: {\n to_address: string;\n to_blockchain: TChainName;\n };\n}\n\ninterface IDepositAddressesResponse {\n addresses: IDepositAddress[];\n has_more?: boolean;\n}\n\nexport interface IGetDepositBtcAddressParams extends IEnvParam {\n /**\n * The destination EVM user address where LBTC will be claimed.\n */\n address: string;\n /**\n * The destination chain ID where LBTC will be claimed.\n */\n chainId: TChainId;\n /**\n * The referral ID.\n */\n referralId: string;\n}\n\n/**\n * Returns the address for depositing BTC.\n *\n * @param {IGetDepositBtcAddressParams} params - function parameters\n *\n * @returns {Promise<string>} the address for depositing BTC\n */\nexport async function getDepositBtcAddress({\n address,\n chainId,\n env,\n referralId,\n}: IGetDepositBtcAddressParams): Promise<string> {\n const addresses = await getDepositBtcAddresses({\n address,\n chainId,\n env,\n referralId,\n });\n\n const addressData = getActualAddress(addresses);\n\n if (!addressData) {\n throw new Error('No address');\n }\n\n return addressData.btc_address;\n}\n\n/**\n * Retrieves the actual deposit address from a list of deposit addresses.\n *\n * @param addresses - The list of deposit addresses.\n * @returns The actual deposit address or undefined if the last created address is deprecated.\n */\nfunction getActualAddress(\n addresses: IDepositAddress[],\n): IDepositAddress | undefined {\n if (!addresses.length) {\n return undefined;\n }\n\n const actualAddress = addresses.reduce((acc, address) => {\n if (acc.created_at < address.created_at) {\n return address;\n }\n return acc;\n }, addresses[0]);\n\n return actualAddress.deprecated ? undefined : actualAddress;\n}\n\n/**\n * Returns the addresses for depositing BTC.\n *\n * @param {IGetDepositBtcAddressParams} params - function parameters\n *\n * @returns {Promise<IDepositAddress[]>} the deposit addresses\n */\nexport async function getDepositBtcAddresses({\n address,\n chainId,\n env,\n referralId,\n}: IGetDepositBtcAddressParams): Promise<IDepositAddress[]> {\n const { baseApiUrl } = getApiConfig(env);\n const toBlockchain = getChainNameById(chainId);\n\n const requestrParams = {\n to_address: address,\n to_blockchain: toBlockchain,\n limit: 1,\n offset: 0,\n asc: false,\n referral_id: referralId,\n };\n\n const { data } = await axios.get<IDepositAddressesResponse>(ADDRESS_URL, {\n baseURL: baseApiUrl,\n params: requestrParams,\n });\n\n return data?.addresses || [];\n}\n","const BTC_DECIMALS = 8;\nconst SATOSHI_SCALE = 10 ** BTC_DECIMALS;\n\n/**\n * Convert Satoshi to BTC\n * @param amount - Satoshi amount\n * @returns BTC amount\n */\nexport function fromSatoshi(amount: number | string) {\n return +amount / SATOSHI_SCALE;\n}\n\n/**\n * Convert BTC to Satoshi\n *\n * @param amount - BTC amount\n * @returns Satoshi amount\n */\nexport function toSatoshi(amount: number | string) {\n return Math.floor(+amount * SATOSHI_SCALE);\n}\n","import { defaultEnv } from '../../common/const';\nimport { OChainId, OEnv, TChainId, TEnv } from '../../common/types/types';\nimport { TChainName } from '../internalTypes';\n\n/**\n * @param chainId the chain ID\n *\n * @returns the chain name\n */\nexport function getCainIdByName(\n chain: string,\n env: TEnv = defaultEnv,\n): TChainId {\n switch (chain as TChainName) {\n case 'DESTINATION_BLOCKCHAIN_ETHEREUM':\n return env === OEnv.prod ? OChainId.ethereum : OChainId.holesky;\n\n default:\n return OChainId.ethereum;\n }\n}\n","import axios from 'axios';\nimport { IEnvParam } from '../../common/types/internalTypes';\nimport { TChainId, TEnv } from '../../common/types/types';\nimport { fromSatoshi } from '../../common/utils/convertSatoshi';\nimport { getApiConfig } from '../apiConfig';\nimport { getCainIdByName } from '../utils/getCainIdByName';\n\ntype Address = string;\ntype Seconds = number;\n\ninterface IDepositResponse {\n txid: string;\n value: number;\n address: Address;\n to_chain: string;\n notarization_wait_dur?: string | number;\n index?: number;\n raw_payload?: string;\n payload?: string;\n signature?: string;\n claim_tx?: string;\n block_height?: string;\n block_time?: string;\n sanctioned?: boolean;\n}\n\ninterface IDepositsByAddressResponse {\n outputs: IDepositResponse[];\n}\n\nexport interface IDeposit {\n txid: string;\n index?: number;\n blockHeight?: number;\n blockTime?: number;\n value: number;\n address: Address;\n chainId: TChainId;\n isClaimed: boolean;\n rawPayload?: string;\n signature?: string;\n isRestricted?: boolean;\n notarizationWaitDur?: Seconds;\n}\n\nexport interface IGetDepositsByAddressParams extends IEnvParam {\n /**\n * The EVM address to get deposits for\n */\n address: Address;\n}\n\n/**\n * Returns all deposits for a given address\n *\n * @param {IGetDepositsByAddressParams} params\n *\n * @returns {Promise<IDeposit[]>} a list of deposits\n */\nexport async function getDepositsByAddress({\n address,\n env,\n}: IGetDepositsByAddressParams): Promise<IDeposit[]> {\n const { baseApiUrl } = getApiConfig(env);\n\n const { data } = await axios.get<IDepositsByAddressResponse | undefined>(\n `api/v1/address/outputs/${address}`,\n { baseURL: baseApiUrl },\n );\n\n const outputs = data?.outputs ?? [];\n\n return outputs.map(mapResponse(env));\n}\n\nfunction mapResponse(env?: TEnv) {\n return (data: IDepositResponse): IDeposit => ({\n txid: data.txid,\n index: data.index ?? 0,\n blockHeight: data.block_height ? Number(data.block_height) : undefined,\n blockTime: data.block_time ? Number(data.block_time) : undefined,\n value: fromSatoshi(data.value),\n address: data.address,\n chainId: getCainIdByName(data.to_chain, env),\n // todo: return claiming tx from the API when it's available\n isClaimed: !!data.claim_tx,\n rawPayload: data.raw_payload,\n signature: data.signature,\n isRestricted: !!data.sanctioned,\n notarizationWaitDur: data.notarization_wait_dur\n ? Number(data.notarization_wait_dur)\n : undefined,\n });\n}\n","import axios from 'axios';\nimport { IEnvParam } from '../../common/types/internalTypes';\nimport { TChainId } from '../../common/types/types';\nimport { getApiConfig } from '../apiConfig';\nimport { getChainNameById } from '../utils/getChainNameById';\n\ntype ExchangeRateResponse = {\n amount_out: string;\n};\n\nexport interface IGetLBTCExchageRateParams extends IEnvParam {\n /**\n * The chain id of the asset to get the exchange rate for\n */\n chainId: TChainId;\n /**\n * The amount of the asset to get the exchange rate for\n */\n amount: number;\n}\n\n/**\n * Retrieves the exchange rate for LBTC.\n *\n * @param {IGetLBTCExchageRateParams} params\n *\n * @returns {Promise<string>} - The exchange rate.\n */\nexport async function getLBTCExchageRate({\n env,\n chainId,\n amount,\n}: IGetLBTCExchageRateParams): Promise<string> {\n const { baseApiUrl } = getApiConfig(env);\n const chainIdName = getChainNameById(chainId);\n\n const { data } = await axios.get<ExchangeRateResponse>(\n `api/v1/exchange/rate/${chainIdName}`,\n { baseURL: baseApiUrl, params: { amount } },\n );\n\n return data.amount_out;\n}\n","import { OChainId } from '../common/types/types';\n\nexport type TRpcUrlConfig = Record<number, string>;\n\nexport const rpcUrlConfig: TRpcUrlConfig = {\n [OChainId.ethereum]: 'https://rpc.ankr.com/eth',\n [OChainId.holesky]: 'https://rpc.ankr.com/eth_holesky',\n};\n","import BigNumber from 'bignumber.js';\nimport Web3 from 'web3';\n\nexport async function getMaxPriorityFeePerGas(\n rpcUrl: string,\n): Promise<BigNumber> {\n const response = await fetch(rpcUrl, {\n method: 'POST',\n headers: {\n 'Content-Type': 'application/json',\n },\n body: JSON.stringify({\n jsonrpc: '2.0',\n id: 1,\n method: 'eth_maxPriorityFeePerGas',\n params: [],\n }),\n });\n\n const data = await response.json();\n\n const convertedHexValue = Web3.utils.hexToNumber(data?.result);\n\n return new BigNumber(Number(convertedHexValue));\n}\n","import BigNumber from 'bignumber.js';\nimport Web3, { Contract, ContractAbi } from 'web3';\nimport {\n TRpcUrlConfig,\n rpcUrlConfig as defaultRpcUrlConfig,\n} from './rpcUrlConfig';\nimport { IGetMaxFeesResult } from './types';\nimport { getMaxPriorityFeePerGas } from './utils/getMaxPriorityFeePerGas';\n\nconst FEE_MULTIPLIER = 2;\nconst ADDITIONAL_SAFE_GAS_PRICE_WEI = 25_000;\n\nexport interface IReadProviderParams {\n /**\n * Chain ID of the network to interact with.\n */\n chainId: number;\n /**\n * The RPC URL configuration. If not provided, the default configuration will be used.\n */\n rpcUrlConfig?: TRpcUrlConfig;\n}\n\nexport class ReadProvider {\n chainId: number;\n rpcConfig: TRpcUrlConfig;\n\n constructor({ chainId, rpcUrlConfig }: IReadProviderParams) {\n this.chainId = chainId;\n this.rpcConfig = { ...defaultRpcUrlConfig, ...rpcUrlConfig };\n }\n\n /**\n * Returns web3 instance for read operations.\n *\n * @public\n * @returns {Web3} Web3 instance.\n */\n public getReadWeb3(): Web3 {\n const rpcUrl = this.getRpcUrl();\n const readWeb3 = new Web3();\n const provider = new Web3.providers.HttpProvider(rpcUrl);\n readWeb3.setProvider(provider);\n return readWeb3;\n }\n\n /**\n * Retrieves the RPC URL based on the current chain ID.\n * @returns The RPC URL for the current chain ID.\n * @throws Error if the RPC URL for the current chain ID is not found.\n */\n getRpcUrl(): string {\n const { chainId } = this;\n const rpcUrl = this.rpcConfig?.[chainId];\n\n if (!rpcUrl) {\n console.error(\n `You might need to add the rpcConfig for the ${chainId} chain ID when creating the provider.`,\n );\n throw new Error(`RPC URL for chainId ${chainId} not found`);\n }\n\n return rpcUrl;\n }\n\n /**\n * Calculates max fees for transaction. Thess values are available for networks\n * with EIP-1559 support.\n *\n * @public\n * @note If current network is Binance Smart Chain, will return default values.\n * @returns {Promise<IGetMaxFeesResult>} Max fees for transaction.\n */\n public async getMaxFees(): Promise<IGetMaxFeesResult> {\n const web3 = this.getReadWeb3();\n const rpcUrl = this.getRpcUrl();\n\n const [block, maxPriorityFeePerGas] = await Promise.all([\n web3.eth.getBlock('latest'),\n getMaxPriorityFeePerGas(rpcUrl),\n ]);\n\n if (!block?.baseFeePerGas && typeof block?.baseFeePerGas !== 'bigint') {\n return {};\n }\n\n const maxFeePerGas = new BigNumber(block.baseFeePerGas.toString(10))\n .multipliedBy(FEE_MULTIPLIER)\n .plus(maxPriorityFeePerGas);\n\n return {\n maxFeePerGas: +maxFeePerGas,\n maxPriorityFeePerGas: +maxPriorityFeePerGas,\n };\n }\n\n /**\n * Returns safe gas price for transaction.\n *\n * @public\n * @returns {Promise<BigNumber>} Safe gas price.\n */\n public async getSafeGasPriceWei(): Promise<BigNumber> {\n const pureGasPriceWei = await this.getReadWeb3().eth.getGasPrice();\n\n return new BigNumber(pureGasPriceWei.toString(10)).plus(\n ADDITIONAL_SAFE_GAS_PRICE_WEI,\n );\n }\n\n /**\n * Creates a contract instance with the given ABI and address.\n *\n * @template AbiType - The type of the contract ABI.\n * @param {any} abi - The ABI of the contract.\n * @param {string} address - The address of the contract.\n * @returns {Contract<AbiType>} The contract instance.\n */\n public createContract<AbiType extends ContractAbi>(\n abi: any,\n address: string,\n ): Contract<AbiType> {\n const web3 = this.getReadWeb3();\n return new web3.eth.Contract<AbiType>(abi, address);\n }\n}\n","import Web3, { Contract, ContractAbi, Transaction, utils } from 'web3';\nimport { IEIP1193Provider } from '../common/types/types';\nimport { IReadProviderParams, ReadProvider } from './ReadProvider';\nimport {\n TRpcUrlConfig,\n rpcUrlConfig as defaultRpcUrlConfig,\n} from './rpcUrlConfig';\nimport { ISendOptions, IWeb3SendResult } from './types';\n\nexport interface IProviderParams extends IReadProviderParams {\n /**\n * The EIP-1193 provider instance.\n */\n provider: IEIP1193Provider;\n /**\n * The сurrent account address.\n */\n account: string;\n}\n\n/**\n * Provider for interacting with a blockchain network.\n */\nexport class Provider extends ReadProvider {\n web3: Web3;\n account: string;\n rpcConfig: TRpcUrlConfig = defaultRpcUrlConfig;\n\n constructor({ provider, account, chainId, rpcUrlConfig }: IProviderParams) {\n super({ chainId, rpcUrlConfig });\n this.web3 = new Web3(provider);\n this.account = account;\n this.chainId = chainId;\n this.rpcConfig = { ...defaultRpcUrlConfig, ...rpcUrlConfig };\n }\n\n /**\n * Signs a message using the current provider and account.\n * @public\n * @param message - The message to be signed.\n * @returns A promise that resolves to the signed message as a string.\n */\n public async signMessage(message: string): Promise<string> {\n const { account } = this;\n\n const messageHex = `0x${Buffer.from(message, 'utf8').toString('hex')}`;\n\n const ethereum = this.web3.currentProvider as any;\n\n return ethereum.request({\n method: 'personal_sign',\n params: [messageHex, account],\n });\n }\n\n /**\n * Custom replacement for web3js [send](https://docs.web3js.org/libdocs/Contract#send).\n *\n * @public\n * @param {string} from - Address of the sender.\n * @param {string} to - Address of the recipient.\n * @param {ISendOptions} sendOptions - Options for sending transaction.\n * @returns {Promise<IWeb3SendResult>} Promise with transaction hash and receipt promise.\n */\n public async sendTransactionAsync(\n from: string,\n to: string,\n sendOptions: ISendOptions,\n ): Promise<IWeb3SendResult> {\n const { chainId, web3: web3Write } = this;\n const web3Read = this.getReadWeb3();\n\n const {\n data,\n estimate = false,\n estimateFee = false,\n extendedGasLimit,\n gasLimit = '0',\n value = '0',\n gasLimitMultiplier = 1,\n } = sendOptions;\n let { nonce } = sendOptions;\n\n if (!nonce) {\n nonce = await web3Read.eth.getTransactionCount(from);\n }\n\n console.log(`Nonce: ${nonce}`);\n\n const tx: Transaction = {\n from,\n to,\n value: utils.numberToHex(value),\n data,\n nonce,\n chainId: utils.numberToHex(chainId),\n };\n\n if (estimate) {\n try {\n const estimatedGas = await web3Read.eth.estimateGas(tx);\n const multipliedGasLimit = Math.round(\n Number(estimatedGas) * gasLimitMultiplier,\n );\n\n if (extendedGasLimit) {\n tx.gas = utils.numberToHex(multipliedGasLimit + extendedGasLimit);\n } else {\n tx.gas = utils.numberToHex(multipliedGasLimit);\n }\n } catch (e) {\n throw new Error(\n (e as Partial<Error>).message ??\n 'Failed to estimate gas limit for transaction.',\n );\n }\n } else {\n tx.gas = utils.numberToHex(gasLimit);\n }\n\n const { maxFeePerGas, maxPriorityFeePerGas } = estimateFee\n ? await this.getMaxFees().catch(() => sendOptions)\n : sendOptions;\n\n if (maxPriorityFeePerGas !== undefined) {\n tx.maxPriorityFeePerGas = utils.numberToHex(maxPriorityFeePerGas);\n }\n\n if (maxFeePerGas !== undefined) {\n tx.maxFeePerGas = utils.numberToHex(maxFeePerGas);\n }\n\n if (!tx.maxFeePerGas && !tx.maxPriorityFeePerGas) {\n const safeGasPrice = await this.getSafeGasPriceWei();\n tx.gasPrice = safeGasPrice.toString(10);\n }\n\n if (!tx.maxFeePerGas && !tx.maxPriorityFeePerGas) {\n const safeGasPrice = await this.getSafeGasPriceWei();\n tx.gasPrice = safeGasPrice.toString(10);\n }\n\n console.log('Sending transaction via Web3: ', tx);\n\n return new Promise((resolve, reject) => {\n const promise = web3Write.eth.sendTransaction(tx);\n\n promise\n .once('transactionHash', async (transactionHash: string) => {\n console.log(`Just signed transaction has is: ${transactionHash}`);\n\n resolve({\n receiptPromise: promise,\n transactionHash,\n });\n })\n .catch(reject);\n });\n }\n\n public createContract<AbiType extends ContractAbi>(\n abi: any,\n address: string,\n ): Contract<AbiType> {\n return new this.web3.eth.Contract<AbiType>(abi, address);\n }\n}\n","import { OChainId } from '../../common/types/types';\n\n/**\n * Returns the gas multiplier for the given chain ID.\n *\n * @param chainId - Chain ID.\n *\n * @returns Gas multiplier.\n */\nexport function getGasMultiplier(chainId: number): number {\n switch (chainId) {\n case OChainId.ethereum:\n return 1.3;\n case OChainId.holesky:\n return 1.5;\n default:\n return 1.3;\n }\n}\n","import { OChainId, TChainId } from '../types/types';\n\nexport function isValidChain(chainId: number): chainId is TChainId {\n return Object.values(OChainId).includes(chainId as TChainId);\n}\n","import {\n defaultEnv,\n ZERO_ADDRESS as PLACEHOLDER_ADDRESS,\n} from '../common/const';\nimport { OChainId, OEnv, TChainId, TEnv } from '../common/types/types';\n\ntype LbtcTokenConfig = Record<TChainId, string>;\n\nconst stageConfig: LbtcTokenConfig = {\n [OChainId.holesky]: '0xED7bfd5C1790576105Af4649817f6d35A75CD818',\n [OChainId.ethereum]: PLACEHOLDER_ADDRESS,\n};\n\nconst testnetConfig: LbtcTokenConfig = {\n [OChainId.holesky]: '0x38A13AB20D15ffbE5A7312d2336EF1552580a4E2',\n [OChainId.ethereum]: PLACEHOLDER_ADDRESS,\n};\n\nconst prodConfig: LbtcTokenConfig = {\n [OChainId.holesky]: PLACEHOLDER_ADDRESS,\n [OChainId.ethereum]: '0x8236a87084f8b84306f72007f36f2618a5634494',\n};\n\nexport function getLbtcAddressConfig(env: TEnv = defaultEnv): LbtcTokenConfig {\n switch (env) {\n case OEnv.prod:\n return prodConfig;\n case OEnv.testnet:\n return testnetConfig;\n default:\n return stageConfig;\n }\n}\n","import { IERC20, LBTCABI } from '../abi';\n\ntype Token = 'LBTC' | 'ERC20';\n\nexport function getTokenABI(token: Token) {\n switch (token) {\n case 'LBTC':\n return LBTCABI;\n default:\n return IERC20;\n }\n}\n","import { TEnv } from '../../common/types/types';\nimport { isValidChain } from '../../common/utils/isValidChain';\nimport { Provider } from '../../provider';\nimport { getLbtcAddressConfig } from '../lbtcAddressConfig';\nimport { getTokenABI } from './getTokenABI';\n\nexport function getLbtcTokenContract(provider: Provider, env?: TEnv) {\n const lbtcAddressConfig = getLbtcAddressConfig(env);\n const { chainId } = provider;\n\n if (!isValidChain(chainId)) {\n throw new Error(`This chain ${chainId} is not supported`);\n }\n\n const tokenAddress = lbtcAddressConfig[chainId];\n\n if (!tokenAddress) {\n throw new Error(`Token address for chain ${chainId} is not defined`);\n }\n\n const abi = getTokenABI('LBTC');\n\n const contract = provider.createContract(abi, tokenAddress);\n\n if (!contract.options.address) {\n contract.options.address = tokenAddress;\n }\n\n return contract as typeof contract & {\n options: typeof contract.options & { address: string };\n };\n}\n","import { IEnvParam } from '../../common/types/internalTypes';\nimport { toSatoshi } from '../../common/utils/convertSatoshi';\nimport { IWeb3SendResult, Provider } from '../../provider';\nimport { IProviderBasedParams } from '../types';\nimport { getGasMultiplier } from '../utils/getGasMultiplier';\nimport { getLbtcTokenContract } from '../utils/getLbtcTokenContract';\n\nexport interface IApproveLBTCParams extends IProviderBasedParams, IEnvParam {\n /**\n * Spender address\n */\n spender: string;\n /**\n * The amount of LBTC to approve\n */\n amount: number;\n}\n\n/**\n * Approves the transfer of a specified amount of LBTC tokens.\n *\n * @param {IApproveLBTCParams} params\n *\n * @returns {Promise<IWeb3SendResult>} transaction promise\n */\nexport function approveLBTC({\n spender,\n amount,\n env,\n ...providerParams\n}: IApproveLBTCParams): Promise<IWeb3SendResult> {\n const provider = new Provider(providerParams);\n const tokenContract = getLbtcTokenContract(provider, env);\n const amountSat = toSatoshi(amount);\n\n const tx = tokenContract.methods.approve(spender, amountSat);\n\n return provider.sendTransactionAsync(\n provider.account,\n tokenContract.options.address,\n {\n data: tx.encodeABI(),\n estimate: true,\n estimateFee: true,\n gasLimitMultiplier: getGasMultiplier(provider.chainId),\n },\n );\n}\n","import { IEnvParam } from '../../common/types/internalTypes';\nimport { getErrorMessage } from '../../common/utils/getErrorMessage';\nimport { IWeb3SendResult, Provider } from '../../provider';\nimport { IProviderBasedParams } from '../types';\nimport { getGasMultiplier } from '../utils/getGasMultiplier';\nimport { getLbtcTokenContract } from '../utils/getLbtcTokenContract';\n\nconst INSUFFICIENT_FUNDS_PARTIAL_ERROR = 'insufficient funds';\n\nconst INSUFFICIENT_FUNDS_ERROR =\n 'Insufficient funds for transfer. Make sure you have enough ETH to cover the gas cost.';\n\nexport interface IClaimLBTCParams extends IProviderBasedParams, IEnvParam {\n /**\n * Raw payload from deposit notarization.\n */\n data: string;\n /**\n * Signature from deposit notarization.\n */\n proofSignature: string;\n}\n\n/**\n * Claims LBTC.\n *\n * @param {IClaimLBTCParams} params - The parameters for claiming LBTC.\n *\n * @returns {Promise<IWeb3SendResult>} transaction promise\n */\nexport async function claimLBTC({\n data,\n proofSignature,\n env,\n ...providerParams\n}: IClaimLBTCParams): Promise<IWeb3SendResult> {\n const provider = new Provider(providerParams);\n const tokenContract = getLbtcTokenContract(provider, env);\n\n const tx = tokenContract.methods.mint(data, proofSignature);\n\n try {\n const result = await provider.sendTransactionAsync(\n provider.account,\n tokenContract.options.address,\n {\n data: tx.encodeABI(),\n estimate: true,\n estimateFee: true,\n gasLimitMultiplier: getGasMultiplier(provider.chainId),\n },\n );\n\n return result;\n } catch (error) {\n const errorMessage = getErrorMessage(error);\n\n if (errorMessage.includes(INSUFFICIENT_FUNDS_PARTIAL_ERROR)) {\n throw new Error(INSUFFICIENT_FUNDS_ERROR);\n }\n\n throw new Error(errorMessage);\n }\n}\n","import { Provider } from '../../provider';\nimport { IProviderBasedParams } from '../types';\n\nexport type SignLbtcDestionationAddrParams = IProviderBasedParams;\n\n/**\n * Signs the destination address for the LBTC in active chain\n * in the current account. Signing is necessary for the\n * generation of the deposit address.\n *\n * @param {SignLbtcDestionationAddrParams} params\n *\n * @returns {Promise<string>} The signature of the message.\n */\nexport async function signLbtcDestionationAddr(\n params: SignLbtcDestionationAddrParams,\n): Promise<string> {\n const provider = new Provider(params);\n\n const message = `destination chain id is ${params.chainId}`;\n\n return provider.signMessage(message);\n}\n","import * as ecc from '@bitcoin-js/tiny-secp256k1-asmjs';\nimport {\n address as addressUtils,\n initEccLib,\n networks,\n payments,\n} from 'bitcoinjs-lib';\nimport { OEnv, TEnv } from '../../common/types/types';\n\ninitEccLib(ecc);\n\ntype AddressType = 'p2tr' | 'p2wpkh' | 'p2wsh';\n\n/**\n * Get output script from address.\n *\n * @param address - The address.\n * @param networkMode - The network mode.\n *\n * @returns The output script.\n */\nexport function getOutputScript(\n address: string,\n env: TEnv = OEnv.prod,\n): string {\n const addressType = getAddressType(address);\n\n const payment = payments[addressType]({\n address,\n network: env === OEnv.prod ? networks.bitcoin : networks.testnet,\n });\n\n const paymentOutputScript = payment.output?.toString('hex');\n\n if (!paymentOutputScript) {\n throw new Error('Output script is not found.');\n }\n\n return `0x${paymentOutputScript}`;\n}\n\nfunction getAddressType(address: string): AddressType {\n const result = addressUtils.fromBech32(address);\n\n const isP2TR = result.version === 1 && result.data.length === 32;\n if (isP2TR) {\n return 'p2tr';\n }\n\n const isP2WPKH = result.version === 0 && result.data.length === 20;\n if (isP2WPKH) {\n return 'p2wpkh';\n }\n\n if (isP2WSHAddressType(address)) {\n return 'p2wsh';\n }\n\n throw new Error('Address type is not supported.');\n}\n\nfunction isP2WSHAddressType(address: string): boolean {\n return (\n (address.startsWith('bc1') || address.startsWith('tb1')) &&\n address.length === 62\n );\n}\n","import { getOutputScript } from '../../btcSdk/utils/getOutputScript';\nimport { IEnvParam } from '../../common/types/internalTypes';\nimport { toSatoshi } from '../../common/utils/convertSatoshi';\nimport { IWeb3SendResult, Provider } from '../../provider';\nimport { IProviderBasedParams } from '../types';\nimport { getGasMultiplier } from '../utils/getGasMultiplier';\nimport { getLbtcTokenContract } from '../utils/getLbtcTokenContract';\n\nexport interface IUnstakeLBTCParams extends IProviderBasedParams, IEnvParam {\n /**\n * The BTC address to send the unstaked BTC to.\n */\n btcAddress: string;\n /**\n * The amount of LBTC to unstake.\n */\n amount: number;\n}\n\n/**\n * Unstakes LBTC to the specified BTC address.\n *\n * @param {IUnstakeLBTCParams} params\n *\n * @returns {Promise<IWeb3SendResult>} transaction promise\n */\nexport function unstakeLBTC({\n btcAddress,\n amount,\n env,\n ...providerParams\n}: IUnstakeLBTCParams): Promise<IWeb3SendResult> {\n const provider = new Provider(providerParams);\n const tokenContract = getLbtcTokenContract(provider, env);\n const outputScript = getOutputScript(btcAddress, env);\n\n const amountSat = toSatoshi(amount);\n\n const tx = tokenContract.methods.redeem(outputScript, amountSat);\n\n return provider.sendTransactionAsync(\n provider.account,\n tokenContract.options.address,\n {\n data: tx.encodeABI(),\n estimate: true,\n estimateFee: true,\n gasLimitMultiplier: getGasMultiplier(provider.chainId),\n },\n );\n}\n"],"names":["OEnv","OChainId","defaultEnv","ZERO_ADDRESS","stageConfig","testnetConfig","prodConfig","getApiConfig","env","getErrorMessage","error","getAxiosErrorMessage","getErrorMessageFromObject","OChainName","getChainNameById","chainId","SANCTIONED_ADDRESS","ADDRESS_URL","SANCTIONS_MESSAGE","generateDepositBtcAddress","address","signature","referralId","captchaToken","baseApiUrl","toChain","requestParams","data","axios","errorMsg","isSanctioned","getDepositBtcAddress","addresses","getDepositBtcAddresses","addressData","getActualAddress","actualAddress","acc","toBlockchain","requestrParams","BTC_DECIMALS","SATOSHI_SCALE","fromSatoshi","amount","toSatoshi","getCainIdByName","chain","getDepositsByAddress","mapResponse","getLBTCExchageRate","chainIdName","rpcUrlConfig","getMaxPriorityFeePerGas","rpcUrl","convertedHexValue","Web3","BigNumber","FEE_MULTIPLIER","ADDITIONAL_SAFE_GAS_PRICE_WEI","ReadProvider","__publicField","defaultRpcUrlConfig","readWeb3","provider","_a","web3","block","maxPriorityFeePerGas","pureGasPriceWei","abi","Provider","account","message","messageHex","from","to","sendOptions","web3Write","web3Read","estimate","estimateFee","extendedGasLimit","gasLimit","value","gasLimitMultiplier","nonce","tx","utils","estimatedGas","multipliedGasLimit","e","maxFeePerGas","safeGasPrice","resolve","reject","promise","transactionHash","getGasMultiplier","isValidChain","PLACEHOLDER_ADDRESS","getLbtcAddressConfig","getTokenABI","token","LBTCABI","IERC20","getLbtcTokenContract","lbtcAddressConfig","tokenAddress","contract","approveLBTC","spender","providerParams","tokenContract","amountSat","INSUFFICIENT_FUNDS_PARTIAL_ERROR","INSUFFICIENT_FUNDS_ERROR","claimLBTC","proofSignature","errorMessage","signLbtcDestionationAddr","params","initEccLib","ecc","getOutputScript","addressType","getAddressType","paymentOutputScript","payments","networks","result","addressUtils","isP2WSHAddressType","unstakeLBTC","btcAddress","outputScript"],"mappings":"gqBAAaA,EAAO,CAClB,KAAM,OACN,QAAS,UACT,MAAO,OACT,EAIaC,EAAW,CACtB,SAAU,EACV,QAAS,IACX,ECTaC,EAAmBF,EAAK,KAMxBG,EAAe,6CCDtBC,EAA0B,CAC9B,WAAY,sCACd,EAEMC,EAA4B,CAChC,WAAY,8CACd,EAEMC,EAAyB,CAC7B,WAAY,sCACd,EAEaC,EAAe,CAACC,EAAYN,IAA2B,CAClE,OAAQM,EAAK,CACX,KAAKR,EAAK,KACD,OAAAM,EACT,KAAKN,EAAK,QACD,OAAAK,EACT,QACS,OAAAD,CACX,CACF,ECpBO,SAASK,EAAgBC,EAAwB,CAClD,OAAA,OAAOA,GAAU,SACZA,EAGLA,aAAiB,MACZC,EAAqBD,CAAmB,EAG1CE,GAA0BF,CAAK,CACxC,CAEA,SAASC,EAAqBD,EAA2B,CACvD,OAAIA,EAAM,SACAA,EAAM,SAAS,KAA6B,QAG/CA,EAAM,OACf,CAEA,SAASE,GAA0BF,EAAoB,CACrD,OA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xG,EACA,QAASZ,IAAQR,EAAK,KAAOgI,EAAAA,SAAS,QAAUA,EAAAA,SAAS,OAAA,CAC1D,EAEmC,SAAR,YAAAhE,EAAgB,SAAS,OAErD,GAAI,CAAC8D,EACG,MAAA,IAAI,MAAM,6BAA6B,EAG/C,MAAO,KAAKA,CAAmB,EACjC,CAEA,SAASD,GAAezG,EAA8B,CAC9C,MAAA6G,EAASC,EAAAA,QAAa,WAAW9G,CAAO,EAG9C,GADe6G,EAAO,UAAY,GAAKA,EAAO,KAAK,SAAW,GAErD,MAAA,OAIT,GADiBA,EAAO,UAAY,GAAKA,EAAO,KAAK,SAAW,GAEvD,MAAA,SAGL,GAAAE,GAAmB/G,CAAO,EACrB,MAAA,QAGH,MAAA,IAAI,MAAM,gCAAgC,CAClD,CAEA,SAAS+G,GAAmB/G,EAA0B,CAEjD,OAAAA,EAAQ,WAAW,KAAK,GAAKA,EAAQ,WAAW,KAAK,IACtDA,EAAQ,SAAW,EAEvB,CCxCO,SAASgH,GAAY,CAC1B,WAAAC,EACA,OAAA1F,EACA,IAAAnC,EACA,GAAGuG,CACL,EAAiD,CACzC,MAAAhD,EAAW,IAAIO,EAASyC,CAAc,EACtCC,EAAgBP,EAAqB1C,EAAUvD,CAAG,EAClD8H,EAAeX,GAAgBU,EAAY7H,CAAG,EAE9CyG,EAAYrE,EAAUD,CAAM,EAE5B2C,EAAK0B,EAAc,QAAQ,OAAOsB,EAAcrB,CAAS,EAE/D,OAAOlD,EAAS,qBACdA,EAAS,QACTiD,EAAc,QAAQ,QACtB,CACE,KAAM1B,EAAG,UAAU,EACnB,SAAU,GACV,YAAa,GACb,mBAAoBW,EAAiBlC,EAAS,OAAO,CACvD,CAAA,CAEJ"}
package/dist/index.js CHANGED
@@ -5,7 +5,7 @@ import w from "axios";
5
5
  import g, { utils as m } from "web3";
6
6
  import C from "bignumber.js";
7
7
  import * as $ from "@bitcoin-js/tiny-secp256k1-asmjs";
8
- import { initEccLib as z, payments as Z, networks as F, address as K } from "bitcoinjs-lib";
8
+ import { initEccLib as z, payments as Z, networks as U, address as K } from "bitcoinjs-lib";
9
9
  const l = {
10
10
  prod: "prod",
11
11
  testnet: "testnet",
@@ -13,13 +13,13 @@ const l = {
13
13
  }, r = {
14
14
  ethereum: 1,
15
15
  holesky: 17e3
16
- }, A = l.prod, M = "0x0000000000000000000000000000000000000000", j = {
16
+ }, M = l.prod, I = "0x0000000000000000000000000000000000000000", j = {
17
17
  baseApiUrl: "https://staging.prod.lombard.finance"
18
18
  }, q = {
19
19
  baseApiUrl: "https://gastald-testnet.prod.lombard.finance"
20
20
  }, J = {
21
21
  baseApiUrl: "https://mainnet.prod.lombard.finance"
22
- }, v = (e = A) => {
22
+ }, v = (e = M) => {
23
23
  switch (e) {
24
24
  case l.prod:
25
25
  return J;
@@ -29,7 +29,7 @@ const l = {
29
29
  return j;
30
30
  }
31
31
  };
32
- function U(e) {
32
+ function L(e) {
33
33
  return typeof e == "string" ? e : e instanceof Error ? X(e) : Y(e);
34
34
  }
35
35
  function X(e) {
@@ -41,7 +41,7 @@ function Y(e) {
41
41
  const Q = {
42
42
  eth: "DESTINATION_BLOCKCHAIN_ETHEREUM"
43
43
  };
44
- function I(e) {
44
+ function P(e) {
45
45
  switch (e) {
46
46
  case r.holesky:
47
47
  case r.ethereum:
@@ -51,7 +51,7 @@ function I(e) {
51
51
  }
52
52
  }
53
53
  const ee = "sanctioned_address", te = "api/v1/address/generate", ne = "destination address is under sanctions";
54
- async function De({
54
+ async function Be({
55
55
  address: e,
56
56
  chainId: t,
57
57
  signature: n,
@@ -59,7 +59,7 @@ async function De({
59
59
  env: s,
60
60
  captchaToken: i
61
61
  }) {
62
- const { baseApiUrl: o } = v(s), p = I(t), d = {
62
+ const { baseApiUrl: o } = v(s), p = P(t), d = {
63
63
  to_address: e,
64
64
  to_address_signature: n,
65
65
  to_chain: p,
@@ -75,7 +75,7 @@ async function De({
75
75
  );
76
76
  return f.address;
77
77
  } catch (f) {
78
- const b = U(f);
78
+ const b = L(f);
79
79
  if (ae(b))
80
80
  return ee;
81
81
  throw new Error(b);
@@ -85,7 +85,7 @@ function ae(e) {
85
85
  return !!e.includes(ne);
86
86
  }
87
87
  const se = "api/v1/address";
88
- async function Be({
88
+ async function Fe({
89
89
  address: e,
90
90
  chainId: t,
91
91
  env: n,
@@ -113,7 +113,7 @@ async function re({
113
113
  env: n,
114
114
  referralId: a
115
115
  }) {
116
- const { baseApiUrl: s } = v(n), i = I(t), o = {
116
+ const { baseApiUrl: s } = v(n), i = P(t), o = {
117
117
  to_address: e,
118
118
  to_blockchain: i,
119
119
  limit: 1,
@@ -126,14 +126,14 @@ async function re({
126
126
  });
127
127
  return (p == null ? void 0 : p.addresses) || [];
128
128
  }
129
- const oe = 8, L = 10 ** oe;
129
+ const oe = 8, k = 10 ** oe;
130
130
  function pe(e) {
131
- return +e / L;
131
+ return +e / k;
132
132
  }
133
- function k(e) {
134
- return Math.floor(+e * L);
133
+ function O(e) {
134
+ return Math.floor(+e * k);
135
135
  }
136
- function ue(e, t = A) {
136
+ function ue(e, t = M) {
137
137
  switch (e) {
138
138
  case "DESTINATION_BLOCKCHAIN_ETHEREUM":
139
139
  return t === l.prod ? r.ethereum : r.holesky;
@@ -141,7 +141,7 @@ function ue(e, t = A) {
141
141
  return r.ethereum;
142
142
  }
143
143
  }
144
- async function Fe({
144
+ async function Ue({
145
145
  address: e,
146
146
  env: t
147
147
  }) {
@@ -168,18 +168,18 @@ function ye(e) {
168
168
  notarizationWaitDur: t.notarization_wait_dur ? Number(t.notarization_wait_dur) : void 0
169
169
  });
170
170
  }
171
- async function Ue({
171
+ async function Le({
172
172
  env: e,
173
173
  chainId: t,
174
174
  amount: n
175
175
  }) {
176
- const { baseApiUrl: a } = v(e), s = I(t), { data: i } = await w.get(
176
+ const { baseApiUrl: a } = v(e), s = P(t), { data: i } = await w.get(
177
177
  `api/v1/exchange/rate/${s}`,
178
178
  { baseURL: a, params: { amount: n } }
179
179
  );
180
180
  return i.amount_out;
181
181
  }
182
- const O = {
182
+ const A = {
183
183
  [r.ethereum]: "https://rpc.ankr.com/eth",
184
184
  [r.holesky]: "https://rpc.ankr.com/eth_holesky"
185
185
  };
@@ -203,7 +203,7 @@ class ce {
203
203
  constructor({ chainId: t, rpcUrlConfig: n }) {
204
204
  c(this, "chainId");
205
205
  c(this, "rpcConfig");
206
- this.chainId = t, this.rpcConfig = { ...O, ...n };
206
+ this.chainId = t, this.rpcConfig = { ...A, ...n };
207
207
  }
208
208
  /**
209
209
  * Returns web3 instance for read operations.
@@ -277,8 +277,8 @@ class x extends ce {
277
277
  super({ chainId: s, rpcUrlConfig: i });
278
278
  c(this, "web3");
279
279
  c(this, "account");
280
- c(this, "rpcConfig");
281
- this.web3 = new g(n), this.account = a, this.chainId = s, this.rpcConfig = { ...O, ...i };
280
+ c(this, "rpcConfig", A);
281
+ this.web3 = new g(n), this.account = a, this.chainId = s, this.rpcConfig = { ...A, ...i };
282
282
  }
283
283
  /**
284
284
  * Signs a message using the current provider and account.
@@ -307,7 +307,7 @@ class x extends ce {
307
307
  data: d,
308
308
  estimate: f = !1,
309
309
  estimateFee: b = !1,
310
- extendedGasLimit: S,
310
+ extendedGasLimit: R,
311
311
  gasLimit: N = "0",
312
312
  value: G = "0",
313
313
  gasLimitMultiplier: W = 1
@@ -327,7 +327,7 @@ class x extends ce {
327
327
  const y = await p.eth.estimateGas(u), h = Math.round(
328
328
  Number(y) * W
329
329
  );
330
- S ? u.gas = m.numberToHex(h + S) : u.gas = m.numberToHex(h);
330
+ R ? u.gas = m.numberToHex(h + R) : u.gas = m.numberToHex(h);
331
331
  } catch (y) {
332
332
  throw new Error(
333
333
  y.message ?? "Failed to estimate gas limit for transaction."
@@ -335,8 +335,8 @@ class x extends ce {
335
335
  }
336
336
  else
337
337
  u.gas = m.numberToHex(N);
338
- const { maxFeePerGas: R, maxPriorityFeePerGas: _ } = b ? await this.getMaxFees().catch(() => s) : s;
339
- if (_ !== void 0 && (u.maxPriorityFeePerGas = m.numberToHex(_)), R !== void 0 && (u.maxFeePerGas = m.numberToHex(R)), !u.maxFeePerGas && !u.maxPriorityFeePerGas) {
338
+ const { maxFeePerGas: _, maxPriorityFeePerGas: D } = b ? await this.getMaxFees().catch(() => s) : s;
339
+ if (D !== void 0 && (u.maxPriorityFeePerGas = m.numberToHex(D)), _ !== void 0 && (u.maxFeePerGas = m.numberToHex(_)), !u.maxFeePerGas && !u.maxPriorityFeePerGas) {
340
340
  const y = await this.getSafeGasPriceWei();
341
341
  u.gasPrice = y.toString(10);
342
342
  }
@@ -345,11 +345,11 @@ class x extends ce {
345
345
  u.gasPrice = y.toString(10);
346
346
  }
347
347
  return console.log("Sending transaction via Web3: ", u), new Promise((y, h) => {
348
- const D = o.eth.sendTransaction(u);
349
- D.once("transactionHash", async (B) => {
350
- console.log(`Just signed transaction has is: ${B}`), y({
351
- receiptPromise: D,
352
- transactionHash: B
348
+ const B = o.eth.sendTransaction(u);
349
+ B.once("transactionHash", async (F) => {
350
+ console.log(`Just signed transaction has is: ${F}`), y({
351
+ receiptPromise: B,
352
+ transactionHash: F
353
353
  });
354
354
  }).catch(h);
355
355
  });
@@ -358,7 +358,7 @@ class x extends ce {
358
358
  return new this.web3.eth.Contract(n, a);
359
359
  }
360
360
  }
361
- function P(e) {
361
+ function E(e) {
362
362
  switch (e) {
363
363
  case r.ethereum:
364
364
  return 1.3;
@@ -373,15 +373,15 @@ function fe(e) {
373
373
  }
374
374
  const be = {
375
375
  [r.holesky]: "0xED7bfd5C1790576105Af4649817f6d35A75CD818",
376
- [r.ethereum]: M
376
+ [r.ethereum]: I
377
377
  }, Te = {
378
378
  [r.holesky]: "0x38A13AB20D15ffbE5A7312d2336EF1552580a4E2",
379
- [r.ethereum]: M
379
+ [r.ethereum]: I
380
380
  }, he = {
381
- [r.holesky]: M,
381
+ [r.holesky]: I,
382
382
  [r.ethereum]: "0x8236a87084f8b84306f72007f36f2618a5634494"
383
383
  };
384
- function ge(e = A) {
384
+ function ge(e = M) {
385
385
  switch (e) {
386
386
  case l.prod:
387
387
  return he;
@@ -2193,7 +2193,7 @@ function xe(e) {
2193
2193
  return we;
2194
2194
  }
2195
2195
  }
2196
- function E(e, t) {
2196
+ function S(e, t) {
2197
2197
  const n = ge(t), { chainId: a } = e;
2198
2198
  if (!fe(a))
2199
2199
  throw new Error(`This chain ${a} is not supported`);
@@ -2203,13 +2203,13 @@ function E(e, t) {
2203
2203
  const i = xe("LBTC"), o = e.createContract(i, s);
2204
2204
  return o.options.address || (o.options.address = s), o;
2205
2205
  }
2206
- function Le({
2206
+ function ke({
2207
2207
  spender: e,
2208
2208
  amount: t,
2209
2209
  env: n,
2210
2210
  ...a
2211
2211
  }) {
2212
- const s = new x(a), i = E(s, n), o = k(t), p = i.methods.approve(e, o);
2212
+ const s = new x(a), i = S(s, n), o = O(t), p = i.methods.approve(e, o);
2213
2213
  return s.sendTransactionAsync(
2214
2214
  s.account,
2215
2215
  i.options.address,
@@ -2217,18 +2217,18 @@ function Le({
2217
2217
  data: p.encodeABI(),
2218
2218
  estimate: !0,
2219
2219
  estimateFee: !0,
2220
- gasLimitMultiplier: P(s.chainId)
2220
+ gasLimitMultiplier: E(s.chainId)
2221
2221
  }
2222
2222
  );
2223
2223
  }
2224
2224
  const Ce = "insufficient funds", Ae = "Insufficient funds for transfer. Make sure you have enough ETH to cover the gas cost.";
2225
- async function ke({
2225
+ async function Oe({
2226
2226
  data: e,
2227
2227
  proofSignature: t,
2228
2228
  env: n,
2229
2229
  ...a
2230
2230
  }) {
2231
- const s = new x(a), i = E(s, n), o = i.methods.mint(e, t);
2231
+ const s = new x(a), i = S(s, n), o = i.methods.mint(e, t);
2232
2232
  try {
2233
2233
  return await s.sendTransactionAsync(
2234
2234
  s.account,
@@ -2237,15 +2237,15 @@ async function ke({
2237
2237
  data: o.encodeABI(),
2238
2238
  estimate: !0,
2239
2239
  estimateFee: !0,
2240
- gasLimitMultiplier: P(s.chainId)
2240
+ gasLimitMultiplier: E(s.chainId)
2241
2241
  }
2242
2242
  );
2243
2243
  } catch (p) {
2244
- const d = U(p);
2244
+ const d = L(p);
2245
2245
  throw d.includes(Ce) ? new Error(Ae) : new Error(d);
2246
2246
  }
2247
2247
  }
2248
- async function Oe(e) {
2248
+ async function Ne(e) {
2249
2249
  const t = new x(e), n = `destination chain id is ${e.chainId}`;
2250
2250
  return t.signMessage(n);
2251
2251
  }
@@ -2254,7 +2254,7 @@ function Me(e, t = l.prod) {
2254
2254
  var i;
2255
2255
  const n = Ie(e), s = (i = Z[n]({
2256
2256
  address: e,
2257
- network: t === l.prod ? F.bitcoin : F.testnet
2257
+ network: t === l.prod ? U.bitcoin : U.testnet
2258
2258
  }).output) == null ? void 0 : i.toString("hex");
2259
2259
  if (!s)
2260
2260
  throw new Error("Output script is not found.");
@@ -2266,15 +2266,20 @@ function Ie(e) {
2266
2266
  return "p2tr";
2267
2267
  if (t.version === 0 && t.data.length === 20)
2268
2268
  return "p2wpkh";
2269
- throw new Error("Payment type is not supported.");
2269
+ if (Pe(e))
2270
+ return "p2wsh";
2271
+ throw new Error("Address type is not supported.");
2272
+ }
2273
+ function Pe(e) {
2274
+ return (e.startsWith("bc1") || e.startsWith("tb1")) && e.length === 62;
2270
2275
  }
2271
- function Ne({
2276
+ function Ge({
2272
2277
  btcAddress: e,
2273
2278
  amount: t,
2274
2279
  env: n,
2275
2280
  ...a
2276
2281
  }) {
2277
- const s = new x(a), i = E(s, n), o = Me(e, n), p = k(t), d = i.methods.redeem(o, p);
2282
+ const s = new x(a), i = S(s, n), o = Me(e, n), p = O(t), d = i.methods.redeem(o, p);
2278
2283
  return s.sendTransactionAsync(
2279
2284
  s.account,
2280
2285
  i.options.address,
@@ -2282,7 +2287,7 @@ function Ne({
2282
2287
  data: d.encodeABI(),
2283
2288
  estimate: !0,
2284
2289
  estimateFee: !0,
2285
- gasLimitMultiplier: P(s.chainId)
2290
+ gasLimitMultiplier: E(s.chainId)
2286
2291
  }
2287
2292
  );
2288
2293
  }
@@ -2290,18 +2295,18 @@ export {
2290
2295
  r as OChainId,
2291
2296
  l as OEnv,
2292
2297
  ee as SANCTIONED_ADDRESS,
2293
- Le as approveLBTC,
2294
- ke as claimLBTC,
2298
+ ke as approveLBTC,
2299
+ Oe as claimLBTC,
2295
2300
  pe as fromSatoshi,
2296
- De as generateDepositBtcAddress,
2301
+ Be as generateDepositBtcAddress,
2297
2302
  v as getApiConfig,
2298
- Be as getDepositBtcAddress,
2303
+ Fe as getDepositBtcAddress,
2299
2304
  re as getDepositBtcAddresses,
2300
- Fe as getDepositsByAddress,
2301
- Ue as getLBTCExchageRate,
2305
+ Ue as getDepositsByAddress,
2306
+ Le as getLBTCExchageRate,
2302
2307
  ge as getLbtcAddressConfig,
2303
- Oe as signLbtcDestionationAddr,
2304
- k as toSatoshi,
2305
- Ne as unstakeLBTC
2308
+ Ne as signLbtcDestionationAddr,
2309
+ O as toSatoshi,
2310
+ Ge as unstakeLBTC
2306
2311
  };
2307
2312
  //# sourceMappingURL=index.js.map
package/dist/index.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","sources":["../src/common/types/types.ts","../src/common/const.ts","../src/sdk/apiConfig.ts","../src/common/utils/getErrorMessage.ts","../src/sdk/internalTypes.ts","../src/sdk/utils/getChainNameById.ts","../src/sdk/generateDepositBtcAddress/generateDepositBtcAddress.ts","../src/sdk/getDepositBtcAddress/getDepositBtcAddress.ts","../src/common/utils/convertSatoshi.ts","../src/sdk/utils/getCainIdByName.ts","../src/sdk/getDepositsByAddress/getDepositsByAddress.ts","../src/sdk/getLBTCExchageRate/getLBTCExchageRate.ts","../src/provider/rpcUrlConfig.ts","../src/provider/utils/getMaxPriorityFeePerGas.ts","../src/provider/ReadProvider.ts","../src/provider/Provider.ts","../src/web3Sdk/utils/getGasMultiplier.ts","../src/common/utils/isValidChain.ts","../src/web3Sdk/lbtcAddressConfig.ts","../src/web3Sdk/utils/getTokenABI.ts","../src/web3Sdk/utils/getLbtcTokenContract.ts","../src/web3Sdk/approveLBTC/approveLBTC.ts","../src/web3Sdk/claimLBTC/claimLBTC.ts","../src/web3Sdk/signLbtcDestionationAddr/signLbtcDestionationAddr.ts","../src/btcSdk/utils/getOutputScript.ts","../src/web3Sdk/unstakeLBTC/unstakeLBTC.ts"],"sourcesContent":["export const OEnv = {\n prod: 'prod',\n testnet: 'testnet',\n stage: 'stage',\n} as const;\n\nexport type TEnv = (typeof OEnv)[keyof typeof OEnv];\n\nexport const OChainId = {\n ethereum: 1,\n holesky: 17000,\n} as const;\n\nexport type TChainId = (typeof OChainId)[keyof typeof OChainId];\n\n/**\n * Abstract EIP-1193 provider\n */\nexport interface IEIP1193Provider {\n request: (args: any) => Promise<any>;\n}\n","import { OEnv, TEnv } from './types/types';\n\nexport const defaultEnv: TEnv = OEnv.prod;\n\n/**\n * Address of the zero account.\n * Can also be used as a placeholder for unknown addresses.\n */\nexport const ZERO_ADDRESS = '0x0000000000000000000000000000000000000000';\n","import { defaultEnv } from '../common/const';\nimport { OEnv, TEnv } from '../common/types/types';\n\ninterface IApiConfig {\n baseApiUrl: string;\n}\n\nconst stageConfig: IApiConfig = {\n baseApiUrl: 'https://staging.prod.lombard.finance',\n};\n\nconst testnetConfig: IApiConfig = {\n baseApiUrl: 'https://gastald-testnet.prod.lombard.finance',\n};\n\nconst prodConfig: IApiConfig = {\n baseApiUrl: 'https://mainnet.prod.lombard.finance',\n};\n\nexport const getApiConfig = (env: TEnv = defaultEnv): IApiConfig => {\n switch (env) {\n case OEnv.prod:\n return prodConfig;\n case OEnv.testnet:\n return testnetConfig;\n default:\n return stageConfig;\n }\n};\n","import { AxiosError } from 'axios';\n\n/**\n * Retrieves the error message from the given error object.\n *\n * @param error - The error object.\n * @returns The error message as a string.\n */\nexport function getErrorMessage(error: unknown): string {\n if (typeof error === 'string') {\n return error;\n }\n\n if (error instanceof Error) {\n return getAxiosErrorMessage(error as AxiosError);\n }\n\n return getErrorMessageFromObject(error);\n}\n\nfunction getAxiosErrorMessage(error: AxiosError): string {\n if (error.response) {\n return (error.response.data as { message: string }).message;\n }\n\n return error.message;\n}\n\nfunction getErrorMessageFromObject(error: any): string {\n if (error?.message) {\n return error.message;\n }\n\n return 'Unknown error';\n}\n","export const OChainName = {\n eth: 'DESTINATION_BLOCKCHAIN_ETHEREUM',\n} as const;\n\nexport type TChainName = (typeof OChainName)[keyof typeof OChainName];\n","import { OChainId, TChainId } from '../../common/types/types';\nimport { OChainName, TChainName } from '../internalTypes';\n\n/**\n * @param chainId the chain ID\n *\n * @returns the chain name\n */\nexport function getChainNameById(chainId: TChainId): TChainName {\n switch (chainId) {\n case OChainId.holesky:\n case OChainId.ethereum:\n return OChainName.eth;\n default:\n throw new Error(`Unknown chain ID: ${chainId}`);\n }\n}\n","import axios from 'axios';\nimport { IEnvParam } from '../../common/types/internalTypes';\nimport { TChainId } from '../../common/types/types';\nimport { getErrorMessage } from '../../common/utils/getErrorMessage';\nimport { getApiConfig } from '../apiConfig';\nimport { getChainNameById } from '../utils/getChainNameById';\n\n/**\n * The address wich will be returned if the provided EVM address is sanctioned.\n */\nexport const SANCTIONED_ADDRESS = 'sanctioned_address';\nconst ADDRESS_URL = 'api/v1/address/generate';\nconst SANCTIONS_MESSAGE = 'destination address is under sanctions';\n\ninterface IGenerateNewAddressResponse {\n address: string;\n}\n\nexport interface IGenerateDepositBtcAddressParams extends IEnvParam {\n /**\n * The destination EVM user address where LBTC will be claimed.\n */\n address: string;\n /**\n * The destination chain ID where LBTC will be claimed.\n */\n chainId: TChainId;\n /**\n * The signature of the address. The signature is generated by signing the address using EVM wallet.\n */\n signature: string;\n /**\n * The referral ID.\n */\n referralId: string;\n /**\n * The captcha token.\n */\n captchaToken?: string;\n}\n\n/**\n * Generates a BTC deposit address.\n *\n * If the provided EVM address is sanctioned, the function will return the `SANCTIONED_ADDRESS`.\n *\n * @param {IGenerateDepositBtcAddressParams} params - The parameters for generating the deposit address.\n * @returns {Promise<string>} The generated deposit address.\n */\nexport async function generateDepositBtcAddress({\n address,\n chainId,\n signature,\n referralId,\n env,\n captchaToken,\n}: IGenerateDepositBtcAddressParams): Promise<string> {\n const { baseApiUrl } = getApiConfig(env);\n const toChain = getChainNameById(chainId);\n\n const requestParams = {\n to_address: address,\n to_address_signature: signature,\n to_chain: toChain,\n referral_id: referralId,\n nonce: 0,\n captcha: captchaToken,\n };\n\n try {\n const { data } = await axios.post<IGenerateNewAddressResponse>(\n ADDRESS_URL,\n requestParams,\n { baseURL: baseApiUrl },\n );\n\n return data.address;\n } catch (error) {\n const errorMsg = getErrorMessage(error);\n\n if (isSanctioned(errorMsg)) {\n return SANCTIONED_ADDRESS;\n } else {\n throw new Error(errorMsg);\n }\n }\n}\n\nfunction isSanctioned(errorMsg: string): boolean {\n return !!errorMsg.includes(SANCTIONS_MESSAGE);\n}\n","import axios from 'axios';\nimport { IEnvParam } from '../../common/types/internalTypes';\nimport { TChainId } from '../../common/types/types';\nimport { getApiConfig } from '../apiConfig';\nimport { TChainName } from '../internalTypes';\nimport { getChainNameById } from '../utils/getChainNameById';\n\nconst ADDRESS_URL = 'api/v1/address';\n\ninterface IDepositAddress {\n btc_address: string;\n created_at: string;\n deprecated?: boolean;\n type: string;\n used?: boolean;\n deposit_metadata: {\n to_address: string;\n to_blockchain: TChainName;\n };\n}\n\ninterface IDepositAddressesResponse {\n addresses: IDepositAddress[];\n has_more?: boolean;\n}\n\nexport interface IGetDepositBtcAddressParams extends IEnvParam {\n /**\n * The destination EVM user address where LBTC will be claimed.\n */\n address: string;\n /**\n * The destination chain ID where LBTC will be claimed.\n */\n chainId: TChainId;\n /**\n * The referral ID.\n */\n referralId: string;\n}\n\n/**\n * Returns the address for depositing BTC.\n *\n * @param {IGetDepositBtcAddressParams} params - function parameters\n *\n * @returns {Promise<string>} the address for depositing BTC\n */\nexport async function getDepositBtcAddress({\n address,\n chainId,\n env,\n referralId,\n}: IGetDepositBtcAddressParams): Promise<string> {\n const addresses = await getDepositBtcAddresses({\n address,\n chainId,\n env,\n referralId,\n });\n\n const addressData = getActualAddress(addresses);\n\n if (!addressData) {\n throw new Error('No address');\n }\n\n return addressData.btc_address;\n}\n\n/**\n * Retrieves the actual deposit address from a list of deposit addresses.\n *\n * @param addresses - The list of deposit addresses.\n * @returns The actual deposit address or undefined if the last created address is deprecated.\n */\nfunction getActualAddress(\n addresses: IDepositAddress[],\n): IDepositAddress | undefined {\n if (!addresses.length) {\n return undefined;\n }\n\n const actualAddress = addresses.reduce((acc, address) => {\n if (acc.created_at < address.created_at) {\n return address;\n }\n return acc;\n }, addresses[0]);\n\n return actualAddress.deprecated ? undefined : actualAddress;\n}\n\n/**\n * Returns the addresses for depositing BTC.\n *\n * @param {IGetDepositBtcAddressParams} params - function parameters\n *\n * @returns {Promise<IDepositAddress[]>} the deposit addresses\n */\nexport async function getDepositBtcAddresses({\n address,\n chainId,\n env,\n referralId,\n}: IGetDepositBtcAddressParams): Promise<IDepositAddress[]> {\n const { baseApiUrl } = getApiConfig(env);\n const toBlockchain = getChainNameById(chainId);\n\n const requestrParams = {\n to_address: address,\n to_blockchain: toBlockchain,\n limit: 1,\n offset: 0,\n asc: false,\n referral_id: referralId,\n };\n\n const { data } = await axios.get<IDepositAddressesResponse>(ADDRESS_URL, {\n baseURL: baseApiUrl,\n params: requestrParams,\n });\n\n return data?.addresses || [];\n}\n","const BTC_DECIMALS = 8;\nconst SATOSHI_SCALE = 10 ** BTC_DECIMALS;\n\n/**\n * Convert Satoshi to BTC\n * @param amount - Satoshi amount\n * @returns BTC amount\n */\nexport function fromSatoshi(amount: number | string) {\n return +amount / SATOSHI_SCALE;\n}\n\n/**\n * Convert BTC to Satoshi\n *\n * @param amount - BTC amount\n * @returns Satoshi amount\n */\nexport function toSatoshi(amount: number | string) {\n return Math.floor(+amount * SATOSHI_SCALE);\n}\n","import { defaultEnv } from '../../common/const';\nimport { OChainId, OEnv, TChainId, TEnv } from '../../common/types/types';\nimport { TChainName } from '../internalTypes';\n\n/**\n * @param chainId the chain ID\n *\n * @returns the chain name\n */\nexport function getCainIdByName(\n chain: string,\n env: TEnv = defaultEnv,\n): TChainId {\n switch (chain as TChainName) {\n case 'DESTINATION_BLOCKCHAIN_ETHEREUM':\n return env === OEnv.prod ? OChainId.ethereum : OChainId.holesky;\n\n default:\n return OChainId.ethereum;\n }\n}\n","import axios from 'axios';\nimport { IEnvParam } from '../../common/types/internalTypes';\nimport { TChainId, TEnv } from '../../common/types/types';\nimport { fromSatoshi } from '../../common/utils/convertSatoshi';\nimport { getApiConfig } from '../apiConfig';\nimport { getCainIdByName } from '../utils/getCainIdByName';\n\ntype Address = string;\ntype Seconds = number;\n\ninterface IDepositResponse {\n txid: string;\n value: number;\n address: Address;\n to_chain: string;\n notarization_wait_dur?: string | number;\n index?: number;\n raw_payload?: string;\n payload?: string;\n signature?: string;\n claim_tx?: string;\n block_height?: string;\n block_time?: string;\n sanctioned?: boolean;\n}\n\ninterface IDepositsByAddressResponse {\n outputs: IDepositResponse[];\n}\n\nexport interface IDeposit {\n txid: string;\n index?: number;\n blockHeight?: number;\n blockTime?: number;\n value: number;\n address: Address;\n chainId: TChainId;\n isClaimed: boolean;\n rawPayload?: string;\n signature?: string;\n isRestricted?: boolean;\n notarizationWaitDur?: Seconds;\n}\n\nexport interface IGetDepositsByAddressParams extends IEnvParam {\n /**\n * The EVM address to get deposits for\n */\n address: Address;\n}\n\n/**\n * Returns all deposits for a given address\n *\n * @param {IGetDepositsByAddressParams} params\n *\n * @returns {Promise<IDeposit[]>} a list of deposits\n */\nexport async function getDepositsByAddress({\n address,\n env,\n}: IGetDepositsByAddressParams): Promise<IDeposit[]> {\n const { baseApiUrl } = getApiConfig(env);\n\n const { data } = await axios.get<IDepositsByAddressResponse | undefined>(\n `api/v1/address/outputs/${address}`,\n { baseURL: baseApiUrl },\n );\n\n const outputs = data?.outputs ?? [];\n\n return outputs.map(mapResponse(env));\n}\n\nfunction mapResponse(env?: TEnv) {\n return (data: IDepositResponse): IDeposit => ({\n txid: data.txid,\n index: data.index ?? 0,\n blockHeight: data.block_height ? Number(data.block_height) : undefined,\n blockTime: data.block_time ? Number(data.block_time) : undefined,\n value: fromSatoshi(data.value),\n address: data.address,\n chainId: getCainIdByName(data.to_chain, env),\n // todo: return claiming tx from the API when it's available\n isClaimed: !!data.claim_tx,\n rawPayload: data.raw_payload,\n signature: data.signature,\n isRestricted: !!data.sanctioned,\n notarizationWaitDur: data.notarization_wait_dur\n ? Number(data.notarization_wait_dur)\n : undefined,\n });\n}\n","import axios from 'axios';\nimport { IEnvParam } from '../../common/types/internalTypes';\nimport { TChainId } from '../../common/types/types';\nimport { getApiConfig } from '../apiConfig';\nimport { getChainNameById } from '../utils/getChainNameById';\n\ntype ExchangeRateResponse = {\n amount_out: string;\n};\n\nexport interface IGetLBTCExchageRateParams extends IEnvParam {\n /**\n * The chain id of the asset to get the exchange rate for\n */\n chainId: TChainId;\n /**\n * The amount of the asset to get the exchange rate for\n */\n amount: number;\n}\n\n/**\n * Retrieves the exchange rate for LBTC.\n *\n * @param {IGetLBTCExchageRateParams} params\n *\n * @returns {Promise<string>} - The exchange rate.\n */\nexport async function getLBTCExchageRate({\n env,\n chainId,\n amount,\n}: IGetLBTCExchageRateParams): Promise<string> {\n const { baseApiUrl } = getApiConfig(env);\n const chainIdName = getChainNameById(chainId);\n\n const { data } = await axios.get<ExchangeRateResponse>(\n `api/v1/exchange/rate/${chainIdName}`,\n { baseURL: baseApiUrl, params: { amount } },\n );\n\n return data.amount_out;\n}\n","import { OChainId } from '../common/types/types';\n\nexport type TRpcUrlConfig = Record<number, string>;\n\nexport const rpcUrlConfig: TRpcUrlConfig = {\n [OChainId.ethereum]: 'https://rpc.ankr.com/eth',\n [OChainId.holesky]: 'https://rpc.ankr.com/eth_holesky',\n};\n","import BigNumber from 'bignumber.js';\nimport Web3 from 'web3';\n\nexport async function getMaxPriorityFeePerGas(\n rpcUrl: string,\n): Promise<BigNumber> {\n const response = await fetch(rpcUrl, {\n method: 'POST',\n headers: {\n 'Content-Type': 'application/json',\n },\n body: JSON.stringify({\n jsonrpc: '2.0',\n id: 1,\n method: 'eth_maxPriorityFeePerGas',\n params: [],\n }),\n });\n\n const data = await response.json();\n\n const convertedHexValue = Web3.utils.hexToNumber(data?.result);\n\n return new BigNumber(Number(convertedHexValue));\n}\n","import BigNumber from 'bignumber.js';\nimport Web3, { Contract, ContractAbi } from 'web3';\nimport {\n TRpcUrlConfig,\n rpcUrlConfig as defaultRpcUrlConfig,\n} from './rpcUrlConfig';\nimport { IGetMaxFeesResult } from './types';\nimport { getMaxPriorityFeePerGas } from './utils/getMaxPriorityFeePerGas';\n\nconst FEE_MULTIPLIER = 2;\nconst ADDITIONAL_SAFE_GAS_PRICE_WEI = 25_000;\n\nexport interface IReadProviderParams {\n /**\n * Chain ID of the network to interact with.\n */\n chainId: number;\n /**\n * The RPC URL configuration. If not provided, the default configuration will be used.\n */\n rpcUrlConfig?: TRpcUrlConfig;\n}\n\nexport class ReadProvider {\n chainId: number;\n rpcConfig: TRpcUrlConfig;\n\n constructor({ chainId, rpcUrlConfig }: IReadProviderParams) {\n this.chainId = chainId;\n this.rpcConfig = { ...defaultRpcUrlConfig, ...rpcUrlConfig };\n }\n\n /**\n * Returns web3 instance for read operations.\n *\n * @public\n * @returns {Web3} Web3 instance.\n */\n public getReadWeb3(): Web3 {\n const rpcUrl = this.getRpcUrl();\n const readWeb3 = new Web3();\n const provider = new Web3.providers.HttpProvider(rpcUrl);\n readWeb3.setProvider(provider);\n return readWeb3;\n }\n\n /**\n * Retrieves the RPC URL based on the current chain ID.\n * @returns The RPC URL for the current chain ID.\n * @throws Error if the RPC URL for the current chain ID is not found.\n */\n getRpcUrl(): string {\n const { chainId } = this;\n const rpcUrl = this.rpcConfig?.[chainId];\n\n if (!rpcUrl) {\n console.error(\n `You might need to add the rpcConfig for the ${chainId} chain ID when creating the provider.`,\n );\n throw new Error(`RPC URL for chainId ${chainId} not found`);\n }\n\n return rpcUrl;\n }\n\n /**\n * Calculates max fees for transaction. Thess values are available for networks\n * with EIP-1559 support.\n *\n * @public\n * @note If current network is Binance Smart Chain, will return default values.\n * @returns {Promise<IGetMaxFeesResult>} Max fees for transaction.\n */\n public async getMaxFees(): Promise<IGetMaxFeesResult> {\n const web3 = this.getReadWeb3();\n const rpcUrl = this.getRpcUrl();\n\n const [block, maxPriorityFeePerGas] = await Promise.all([\n web3.eth.getBlock('latest'),\n getMaxPriorityFeePerGas(rpcUrl),\n ]);\n\n if (!block?.baseFeePerGas && typeof block?.baseFeePerGas !== 'bigint') {\n return {};\n }\n\n const maxFeePerGas = new BigNumber(block.baseFeePerGas.toString(10))\n .multipliedBy(FEE_MULTIPLIER)\n .plus(maxPriorityFeePerGas);\n\n return {\n maxFeePerGas: +maxFeePerGas,\n maxPriorityFeePerGas: +maxPriorityFeePerGas,\n };\n }\n\n /**\n * Returns safe gas price for transaction.\n *\n * @public\n * @returns {Promise<BigNumber>} Safe gas price.\n */\n public async getSafeGasPriceWei(): Promise<BigNumber> {\n const pureGasPriceWei = await this.getReadWeb3().eth.getGasPrice();\n\n return new BigNumber(pureGasPriceWei.toString(10)).plus(\n ADDITIONAL_SAFE_GAS_PRICE_WEI,\n );\n }\n\n /**\n * Creates a contract instance with the given ABI and address.\n *\n * @template AbiType - The type of the contract ABI.\n * @param {any} abi - The ABI of the contract.\n * @param {string} address - The address of the contract.\n * @returns {Contract<AbiType>} The contract instance.\n */\n public createContract<AbiType extends ContractAbi>(\n abi: any,\n address: string,\n ): Contract<AbiType> {\n const web3 = this.getReadWeb3();\n return new web3.eth.Contract<AbiType>(abi, address);\n }\n}\n","import Web3, { Contract, ContractAbi, Transaction, utils } from 'web3';\nimport { IEIP1193Provider } from '../common/types/types';\nimport { IReadProviderParams, ReadProvider } from './ReadProvider';\nimport {\n TRpcUrlConfig,\n rpcUrlConfig as defaultRpcUrlConfig,\n} from './rpcUrlConfig';\nimport { ISendOptions, IWeb3SendResult } from './types';\n\nexport interface IProviderParams extends IReadProviderParams {\n /**\n * The EIP-1193 provider instance.\n */\n provider: IEIP1193Provider;\n /**\n * The сurrent account address.\n */\n account: string;\n}\n\n/**\n * Provider for interacting with a blockchain network.\n */\nexport class Provider extends ReadProvider {\n web3: Web3;\n account: string;\n rpcConfig: TRpcUrlConfig;\n\n constructor({ provider, account, chainId, rpcUrlConfig }: IProviderParams) {\n super({ chainId, rpcUrlConfig });\n this.web3 = new Web3(provider);\n this.account = account;\n this.chainId = chainId;\n this.rpcConfig = { ...defaultRpcUrlConfig, ...rpcUrlConfig };\n }\n\n /**\n * Signs a message using the current provider and account.\n * @public\n * @param message - The message to be signed.\n * @returns A promise that resolves to the signed message as a string.\n */\n public async signMessage(message: string): Promise<string> {\n const { account } = this;\n\n const messageHex = `0x${Buffer.from(message, 'utf8').toString('hex')}`;\n\n const ethereum = this.web3.currentProvider as any;\n\n return ethereum.request({\n method: 'personal_sign',\n params: [messageHex, account],\n });\n }\n\n /**\n * Custom replacement for web3js [send](https://docs.web3js.org/libdocs/Contract#send).\n *\n * @public\n * @param {string} from - Address of the sender.\n * @param {string} to - Address of the recipient.\n * @param {ISendOptions} sendOptions - Options for sending transaction.\n * @returns {Promise<IWeb3SendResult>} Promise with transaction hash and receipt promise.\n */\n public async sendTransactionAsync(\n from: string,\n to: string,\n sendOptions: ISendOptions,\n ): Promise<IWeb3SendResult> {\n const { chainId, web3: web3Write } = this;\n const web3Read = this.getReadWeb3();\n\n const {\n data,\n estimate = false,\n estimateFee = false,\n extendedGasLimit,\n gasLimit = '0',\n value = '0',\n gasLimitMultiplier = 1,\n } = sendOptions;\n let { nonce } = sendOptions;\n\n if (!nonce) {\n nonce = await web3Read.eth.getTransactionCount(from);\n }\n\n console.log(`Nonce: ${nonce}`);\n\n const tx: Transaction = {\n from,\n to,\n value: utils.numberToHex(value),\n data,\n nonce,\n chainId: utils.numberToHex(chainId),\n };\n\n if (estimate) {\n try {\n const estimatedGas = await web3Read.eth.estimateGas(tx);\n const multipliedGasLimit = Math.round(\n Number(estimatedGas) * gasLimitMultiplier,\n );\n\n if (extendedGasLimit) {\n tx.gas = utils.numberToHex(multipliedGasLimit + extendedGasLimit);\n } else {\n tx.gas = utils.numberToHex(multipliedGasLimit);\n }\n } catch (e) {\n throw new Error(\n (e as Partial<Error>).message ??\n 'Failed to estimate gas limit for transaction.',\n );\n }\n } else {\n tx.gas = utils.numberToHex(gasLimit);\n }\n\n const { maxFeePerGas, maxPriorityFeePerGas } = estimateFee\n ? await this.getMaxFees().catch(() => sendOptions)\n : sendOptions;\n\n if (maxPriorityFeePerGas !== undefined) {\n tx.maxPriorityFeePerGas = utils.numberToHex(maxPriorityFeePerGas);\n }\n\n if (maxFeePerGas !== undefined) {\n tx.maxFeePerGas = utils.numberToHex(maxFeePerGas);\n }\n\n if (!tx.maxFeePerGas && !tx.maxPriorityFeePerGas) {\n const safeGasPrice = await this.getSafeGasPriceWei();\n tx.gasPrice = safeGasPrice.toString(10);\n }\n\n if (!tx.maxFeePerGas && !tx.maxPriorityFeePerGas) {\n const safeGasPrice = await this.getSafeGasPriceWei();\n tx.gasPrice = safeGasPrice.toString(10);\n }\n\n console.log('Sending transaction via Web3: ', tx);\n\n return new Promise((resolve, reject) => {\n const promise = web3Write.eth.sendTransaction(tx);\n\n promise\n .once('transactionHash', async (transactionHash: string) => {\n console.log(`Just signed transaction has is: ${transactionHash}`);\n\n resolve({\n receiptPromise: promise,\n transactionHash,\n });\n })\n .catch(reject);\n });\n }\n\n public createContract<AbiType extends ContractAbi>(\n abi: any,\n address: string,\n ): Contract<AbiType> {\n return new this.web3.eth.Contract<AbiType>(abi, address);\n }\n}\n","import { OChainId } from '../../common/types/types';\n\n/**\n * Returns the gas multiplier for the given chain ID.\n *\n * @param chainId - Chain ID.\n *\n * @returns Gas multiplier.\n */\nexport function getGasMultiplier(chainId: number): number {\n switch (chainId) {\n case OChainId.ethereum:\n return 1.3;\n case OChainId.holesky:\n return 1.5;\n default:\n return 1.3;\n }\n}\n","import { OChainId, TChainId } from '../types/types';\n\nexport function isValidChain(chainId: number): chainId is TChainId {\n return Object.values(OChainId).includes(chainId as TChainId);\n}\n","import {\n defaultEnv,\n ZERO_ADDRESS as PLACEHOLDER_ADDRESS,\n} from '../common/const';\nimport { OChainId, OEnv, TChainId, TEnv } from '../common/types/types';\n\ntype LbtcTokenConfig = Record<TChainId, string>;\n\nconst stageConfig: LbtcTokenConfig = {\n [OChainId.holesky]: '0xED7bfd5C1790576105Af4649817f6d35A75CD818',\n [OChainId.ethereum]: PLACEHOLDER_ADDRESS,\n};\n\nconst testnetConfig: LbtcTokenConfig = {\n [OChainId.holesky]: '0x38A13AB20D15ffbE5A7312d2336EF1552580a4E2',\n [OChainId.ethereum]: PLACEHOLDER_ADDRESS,\n};\n\nconst prodConfig: LbtcTokenConfig = {\n [OChainId.holesky]: PLACEHOLDER_ADDRESS,\n [OChainId.ethereum]: '0x8236a87084f8b84306f72007f36f2618a5634494',\n};\n\nexport function getLbtcAddressConfig(env: TEnv = defaultEnv): LbtcTokenConfig {\n switch (env) {\n case OEnv.prod:\n return prodConfig;\n case OEnv.testnet:\n return testnetConfig;\n default:\n return stageConfig;\n }\n}\n","import { IERC20, LBTCABI } from '../abi';\n\ntype Token = 'LBTC' | 'ERC20';\n\nexport function getTokenABI(token: Token) {\n switch (token) {\n case 'LBTC':\n return LBTCABI;\n default:\n return IERC20;\n }\n}\n","import { TEnv } from '../../common/types/types';\nimport { isValidChain } from '../../common/utils/isValidChain';\nimport { Provider } from '../../provider';\nimport { getLbtcAddressConfig } from '../lbtcAddressConfig';\nimport { getTokenABI } from './getTokenABI';\n\nexport function getLbtcTokenContract(provider: Provider, env?: TEnv) {\n const lbtcAddressConfig = getLbtcAddressConfig(env);\n const { chainId } = provider;\n\n if (!isValidChain(chainId)) {\n throw new Error(`This chain ${chainId} is not supported`);\n }\n\n const tokenAddress = lbtcAddressConfig[chainId];\n\n if (!tokenAddress) {\n throw new Error(`Token address for chain ${chainId} is not defined`);\n }\n\n const abi = getTokenABI('LBTC');\n\n const contract = provider.createContract(abi, tokenAddress);\n\n if (!contract.options.address) {\n contract.options.address = tokenAddress;\n }\n\n return contract as typeof contract & {\n options: typeof contract.options & { address: string };\n };\n}\n","import { IEnvParam } from '../../common/types/internalTypes';\nimport { toSatoshi } from '../../common/utils/convertSatoshi';\nimport { IWeb3SendResult, Provider } from '../../provider';\nimport { IProviderBasedParams } from '../types';\nimport { getGasMultiplier } from '../utils/getGasMultiplier';\nimport { getLbtcTokenContract } from '../utils/getLbtcTokenContract';\n\nexport interface IApproveLBTCParams extends IProviderBasedParams, IEnvParam {\n /**\n * Spender address\n */\n spender: string;\n /**\n * The amount of LBTC to approve\n */\n amount: number;\n}\n\n/**\n * Approves the transfer of a specified amount of LBTC tokens.\n *\n * @param {IApproveLBTCParams} params\n *\n * @returns {Promise<IWeb3SendResult>} transaction promise\n */\nexport function approveLBTC({\n spender,\n amount,\n env,\n ...providerParams\n}: IApproveLBTCParams): Promise<IWeb3SendResult> {\n const provider = new Provider(providerParams);\n const tokenContract = getLbtcTokenContract(provider, env);\n const amountSat = toSatoshi(amount);\n\n const tx = tokenContract.methods.approve(spender, amountSat);\n\n return provider.sendTransactionAsync(\n provider.account,\n tokenContract.options.address,\n {\n data: tx.encodeABI(),\n estimate: true,\n estimateFee: true,\n gasLimitMultiplier: getGasMultiplier(provider.chainId),\n },\n );\n}\n","import { IEnvParam } from '../../common/types/internalTypes';\nimport { getErrorMessage } from '../../common/utils/getErrorMessage';\nimport { IWeb3SendResult, Provider } from '../../provider';\nimport { IProviderBasedParams } from '../types';\nimport { getGasMultiplier } from '../utils/getGasMultiplier';\nimport { getLbtcTokenContract } from '../utils/getLbtcTokenContract';\n\nconst INSUFFICIENT_FUNDS_PARTIAL_ERROR = 'insufficient funds';\n\nconst INSUFFICIENT_FUNDS_ERROR =\n 'Insufficient funds for transfer. Make sure you have enough ETH to cover the gas cost.';\n\nexport interface IClaimLBTCParams extends IProviderBasedParams, IEnvParam {\n /**\n * Raw payload from deposit notarization.\n */\n data: string;\n /**\n * Signature from deposit notarization.\n */\n proofSignature: string;\n}\n\n/**\n * Claims LBTC.\n *\n * @param {IClaimLBTCParams} params - The parameters for claiming LBTC.\n *\n * @returns {Promise<IWeb3SendResult>} transaction promise\n */\nexport async function claimLBTC({\n data,\n proofSignature,\n env,\n ...providerParams\n}: IClaimLBTCParams): Promise<IWeb3SendResult> {\n const provider = new Provider(providerParams);\n const tokenContract = getLbtcTokenContract(provider, env);\n\n const tx = tokenContract.methods.mint(data, proofSignature);\n\n try {\n const result = await provider.sendTransactionAsync(\n provider.account,\n tokenContract.options.address,\n {\n data: tx.encodeABI(),\n estimate: true,\n estimateFee: true,\n gasLimitMultiplier: getGasMultiplier(provider.chainId),\n },\n );\n\n return result;\n } catch (error) {\n const errorMessage = getErrorMessage(error);\n\n if (errorMessage.includes(INSUFFICIENT_FUNDS_PARTIAL_ERROR)) {\n throw new Error(INSUFFICIENT_FUNDS_ERROR);\n }\n\n throw new Error(errorMessage);\n }\n}\n","import { Provider } from '../../provider';\nimport { IProviderBasedParams } from '../types';\n\nexport type SignLbtcDestionationAddrParams = IProviderBasedParams;\n\n/**\n * Signs the destination address for the LBTC in active chain\n * in the current account. Signing is necessary for the\n * generation of the deposit address.\n *\n * @param {SignLbtcDestionationAddrParams} params\n *\n * @returns {Promise<string>} The signature of the message.\n */\nexport async function signLbtcDestionationAddr(\n params: SignLbtcDestionationAddrParams,\n): Promise<string> {\n const provider = new Provider(params);\n\n const message = `destination chain id is ${params.chainId}`;\n\n return provider.signMessage(message);\n}\n","import * as ecc from '@bitcoin-js/tiny-secp256k1-asmjs';\nimport {\n address as addressUtils,\n initEccLib,\n networks,\n payments,\n} from 'bitcoinjs-lib';\nimport { OEnv, TEnv } from '../../common/types/types';\n\ninitEccLib(ecc);\n\n/**\n * Get output script from address.\n *\n * @param address - The address.\n * @param networkMode - The network mode.\n *\n * @returns The output script.\n */\nexport function getOutputScript(\n address: string,\n env: TEnv = OEnv.prod,\n): string {\n const paymentType = getPaymentType(address);\n\n const payment = payments[paymentType]({\n address,\n network: env === OEnv.prod ? networks.bitcoin : networks.testnet,\n });\n\n const paymentOutputScript = payment.output?.toString('hex');\n\n if (!paymentOutputScript) {\n throw new Error('Output script is not found.');\n }\n\n return `0x${paymentOutputScript}`;\n}\n\nfunction getPaymentType(address: string): 'p2tr' | 'p2wpkh' {\n const result = addressUtils.fromBech32(address);\n\n const isP2TR = result.version === 1 && result.data.length === 32;\n if (isP2TR) {\n return 'p2tr';\n }\n\n const isP2WPKH = result.version === 0 && result.data.length === 20;\n if (isP2WPKH) {\n return 'p2wpkh';\n }\n\n throw new Error('Payment type is not supported.');\n}\n","import { getOutputScript } from '../../btcSdk/utils/getOutputScript';\nimport { IEnvParam } from '../../common/types/internalTypes';\nimport { toSatoshi } from '../../common/utils/convertSatoshi';\nimport { IWeb3SendResult, Provider } from '../../provider';\nimport { IProviderBasedParams } from '../types';\nimport { getGasMultiplier } from '../utils/getGasMultiplier';\nimport { getLbtcTokenContract } from '../utils/getLbtcTokenContract';\n\nexport interface IUnstakeLBTCParams extends IProviderBasedParams, IEnvParam {\n /**\n * The BTC address to send the unstaked BTC to.\n */\n btcAddress: string;\n /**\n * The amount of LBTC to unstake.\n */\n amount: number;\n}\n\n/**\n * Unstakes LBTC to the specified BTC address.\n *\n * @param {IUnstakeLBTCParams} params\n *\n * @returns {Promise<IWeb3SendResult>} transaction promise\n */\nexport function unstakeLBTC({\n btcAddress,\n amount,\n env,\n ...providerParams\n}: IUnstakeLBTCParams): Promise<IWeb3SendResult> {\n const provider = new Provider(providerParams);\n const tokenContract = getLbtcTokenContract(provider, env);\n const outputScript = getOutputScript(btcAddress, env);\n\n const amountSat = toSatoshi(amount);\n\n const tx = tokenContract.methods.redeem(outputScript, amountSat);\n\n return provider.sendTransactionAsync(\n provider.account,\n tokenContract.options.address,\n {\n data: tx.encodeABI(),\n estimate: true,\n estimateFee: true,\n gasLimitMultiplier: getGasMultiplier(provider.chainId),\n },\n );\n}\n"],"names":["OEnv","OChainId","defaultEnv","ZERO_ADDRESS","stageConfig","testnetConfig","prodConfig","getApiConfig","env","getErrorMessage","error","getAxiosErrorMessage","getErrorMessageFromObject","OChainName","getChainNameById","chainId","SANCTIONED_ADDRESS","ADDRESS_URL","SANCTIONS_MESSAGE","generateDepositBtcAddress","address","signature","referralId","captchaToken","baseApiUrl","toChain","requestParams","data","axios","errorMsg","isSanctioned","getDepositBtcAddress","addresses","getDepositBtcAddresses","addressData","getActualAddress","actualAddress","acc","toBlockchain","requestrParams","BTC_DECIMALS","SATOSHI_SCALE","fromSatoshi","amount","toSatoshi","getCainIdByName","chain","getDepositsByAddress","mapResponse","getLBTCExchageRate","chainIdName","rpcUrlConfig","getMaxPriorityFeePerGas","rpcUrl","convertedHexValue","Web3","BigNumber","FEE_MULTIPLIER","ADDITIONAL_SAFE_GAS_PRICE_WEI","ReadProvider","__publicField","defaultRpcUrlConfig","readWeb3","provider","_a","web3","block","maxPriorityFeePerGas","pureGasPriceWei","abi","Provider","account","message","messageHex","from","to","sendOptions","web3Write","web3Read","estimate","estimateFee","extendedGasLimit","gasLimit","value","gasLimitMultiplier","nonce","tx","utils","estimatedGas","multipliedGasLimit","e","maxFeePerGas","safeGasPrice","resolve","reject","promise","transactionHash","getGasMultiplier","isValidChain","PLACEHOLDER_ADDRESS","getLbtcAddressConfig","getTokenABI","token","LBTCABI","IERC20","getLbtcTokenContract","lbtcAddressConfig","tokenAddress","contract","approveLBTC","spender","providerParams","tokenContract","amountSat","INSUFFICIENT_FUNDS_PARTIAL_ERROR","INSUFFICIENT_FUNDS_ERROR","claimLBTC","proofSignature","errorMessage","signLbtcDestionationAddr","params","initEccLib","ecc","getOutputScript","paymentType","getPaymentType","paymentOutputScript","payments","networks","result","addressUtils","unstakeLBTC","btcAddress","outputScript"],"mappings":";;;;;;;;AAAO,MAAMA,IAAO;AAAA,EAClB,MAAM;AAAA,EACN,SAAS;AAAA,EACT,OAAO;AACT,GAIaC,IAAW;AAAA,EACtB,UAAU;AAAA,EACV,SAAS;AACX,GCT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,GAAcpB,CAAS;AAE/D,SAAOlD,EAAS;AAAA,IACdA,EAAS;AAAA,IACTiD,EAAc,QAAQ;AAAA,IACtB;AAAA,MACE,MAAM1B,EAAG,UAAU;AAAA,MACnB,UAAU;AAAA,MACV,aAAa;AAAA,MACb,oBAAoBW,EAAiBlC,EAAS,OAAO;AAAA,IACvD;AAAA,EAAA;AAEJ;"}
1
+ {"version":3,"file":"index.js","sources":["../src/common/types/types.ts","../src/common/const.ts","../src/sdk/apiConfig.ts","../src/common/utils/getErrorMessage.ts","../src/sdk/internalTypes.ts","../src/sdk/utils/getChainNameById.ts","../src/sdk/generateDepositBtcAddress/generateDepositBtcAddress.ts","../src/sdk/getDepositBtcAddress/getDepositBtcAddress.ts","../src/common/utils/convertSatoshi.ts","../src/sdk/utils/getCainIdByName.ts","../src/sdk/getDepositsByAddress/getDepositsByAddress.ts","../src/sdk/getLBTCExchageRate/getLBTCExchageRate.ts","../src/provider/rpcUrlConfig.ts","../src/provider/utils/getMaxPriorityFeePerGas.ts","../src/provider/ReadProvider.ts","../src/provider/Provider.ts","../src/web3Sdk/utils/getGasMultiplier.ts","../src/common/utils/isValidChain.ts","../src/web3Sdk/lbtcAddressConfig.ts","../src/web3Sdk/utils/getTokenABI.ts","../src/web3Sdk/utils/getLbtcTokenContract.ts","../src/web3Sdk/approveLBTC/approveLBTC.ts","../src/web3Sdk/claimLBTC/claimLBTC.ts","../src/web3Sdk/signLbtcDestionationAddr/signLbtcDestionationAddr.ts","../src/btcSdk/utils/getOutputScript.ts","../src/web3Sdk/unstakeLBTC/unstakeLBTC.ts"],"sourcesContent":["export const OEnv = {\n prod: 'prod',\n testnet: 'testnet',\n stage: 'stage',\n} as const;\n\nexport type TEnv = (typeof OEnv)[keyof typeof OEnv];\n\nexport const OChainId = {\n ethereum: 1,\n holesky: 17000,\n} as const;\n\nexport type TChainId = (typeof OChainId)[keyof typeof OChainId];\n\n/**\n * Abstract EIP-1193 provider\n */\nexport interface IEIP1193Provider {\n request: (args: any) => Promise<any>;\n}\n","import { OEnv, TEnv } from './types/types';\n\nexport const defaultEnv: TEnv = OEnv.prod;\n\n/**\n * Address of the zero account.\n * Can also be used as a placeholder for unknown addresses.\n */\nexport const ZERO_ADDRESS = '0x0000000000000000000000000000000000000000';\n","import { defaultEnv } from '../common/const';\nimport { OEnv, TEnv } from '../common/types/types';\n\ninterface IApiConfig {\n baseApiUrl: string;\n}\n\nconst stageConfig: IApiConfig = {\n baseApiUrl: 'https://staging.prod.lombard.finance',\n};\n\nconst testnetConfig: IApiConfig = {\n baseApiUrl: 'https://gastald-testnet.prod.lombard.finance',\n};\n\nconst prodConfig: IApiConfig = {\n baseApiUrl: 'https://mainnet.prod.lombard.finance',\n};\n\nexport const getApiConfig = (env: TEnv = defaultEnv): IApiConfig => {\n switch (env) {\n case OEnv.prod:\n return prodConfig;\n case OEnv.testnet:\n return testnetConfig;\n default:\n return stageConfig;\n }\n};\n","import { AxiosError } from 'axios';\n\n/**\n * Retrieves the error message from the given error object.\n *\n * @param error - The error object.\n * @returns The error message as a string.\n */\nexport function getErrorMessage(error: unknown): string {\n if (typeof error === 'string') {\n return error;\n }\n\n if (error instanceof Error) {\n return getAxiosErrorMessage(error as AxiosError);\n }\n\n return getErrorMessageFromObject(error);\n}\n\nfunction getAxiosErrorMessage(error: AxiosError): string {\n if (error.response) {\n return (error.response.data as { message: string }).message;\n }\n\n return error.message;\n}\n\nfunction getErrorMessageFromObject(error: any): string {\n if (error?.message) {\n return error.message;\n }\n\n return 'Unknown error';\n}\n","export const OChainName = {\n eth: 'DESTINATION_BLOCKCHAIN_ETHEREUM',\n} as const;\n\nexport type TChainName = (typeof OChainName)[keyof typeof OChainName];\n","import { OChainId, TChainId } from '../../common/types/types';\nimport { OChainName, TChainName } from '../internalTypes';\n\n/**\n * @param chainId the chain ID\n *\n * @returns the chain name\n */\nexport function getChainNameById(chainId: TChainId): TChainName {\n switch (chainId) {\n case OChainId.holesky:\n case OChainId.ethereum:\n return OChainName.eth;\n default:\n throw new Error(`Unknown chain ID: ${chainId}`);\n }\n}\n","import axios from 'axios';\nimport { IEnvParam } from '../../common/types/internalTypes';\nimport { TChainId } from '../../common/types/types';\nimport { getErrorMessage } from '../../common/utils/getErrorMessage';\nimport { getApiConfig } from '../apiConfig';\nimport { getChainNameById } from '../utils/getChainNameById';\n\n/**\n * The address wich will be returned if the provided EVM address is sanctioned.\n */\nexport const SANCTIONED_ADDRESS = 'sanctioned_address';\nconst ADDRESS_URL = 'api/v1/address/generate';\nconst SANCTIONS_MESSAGE = 'destination address is under sanctions';\n\ninterface IGenerateNewAddressResponse {\n address: string;\n}\n\nexport interface IGenerateDepositBtcAddressParams extends IEnvParam {\n /**\n * The destination EVM user address where LBTC will be claimed.\n */\n address: string;\n /**\n * The destination chain ID where LBTC will be claimed.\n */\n chainId: TChainId;\n /**\n * The signature of the address. The signature is generated by signing the address using EVM wallet.\n */\n signature: string;\n /**\n * The referral ID.\n */\n referralId: string;\n /**\n * The captcha token.\n */\n captchaToken?: string;\n}\n\n/**\n * Generates a BTC deposit address.\n *\n * If the provided EVM address is sanctioned, the function will return the `SANCTIONED_ADDRESS`.\n *\n * @param {IGenerateDepositBtcAddressParams} params - The parameters for generating the deposit address.\n * @returns {Promise<string>} The generated deposit address.\n */\nexport async function generateDepositBtcAddress({\n address,\n chainId,\n signature,\n referralId,\n env,\n captchaToken,\n}: IGenerateDepositBtcAddressParams): Promise<string> {\n const { baseApiUrl } = getApiConfig(env);\n const toChain = getChainNameById(chainId);\n\n const requestParams = {\n to_address: address,\n to_address_signature: signature,\n to_chain: toChain,\n referral_id: referralId,\n nonce: 0,\n captcha: captchaToken,\n };\n\n try {\n const { data } = await axios.post<IGenerateNewAddressResponse>(\n ADDRESS_URL,\n requestParams,\n { baseURL: baseApiUrl },\n );\n\n return data.address;\n } catch (error) {\n const errorMsg = getErrorMessage(error);\n\n if (isSanctioned(errorMsg)) {\n return SANCTIONED_ADDRESS;\n } else {\n throw new Error(errorMsg);\n }\n }\n}\n\nfunction isSanctioned(errorMsg: string): boolean {\n return !!errorMsg.includes(SANCTIONS_MESSAGE);\n}\n","import axios from 'axios';\nimport { IEnvParam } from '../../common/types/internalTypes';\nimport { TChainId } from '../../common/types/types';\nimport { getApiConfig } from '../apiConfig';\nimport { TChainName } from '../internalTypes';\nimport { getChainNameById } from '../utils/getChainNameById';\n\nconst ADDRESS_URL = 'api/v1/address';\n\ninterface IDepositAddress {\n btc_address: string;\n created_at: string;\n deprecated?: boolean;\n type: string;\n used?: boolean;\n deposit_metadata: {\n to_address: string;\n to_blockchain: TChainName;\n };\n}\n\ninterface IDepositAddressesResponse {\n addresses: IDepositAddress[];\n has_more?: boolean;\n}\n\nexport interface IGetDepositBtcAddressParams extends IEnvParam {\n /**\n * The destination EVM user address where LBTC will be claimed.\n */\n address: string;\n /**\n * The destination chain ID where LBTC will be claimed.\n */\n chainId: TChainId;\n /**\n * The referral ID.\n */\n referralId: string;\n}\n\n/**\n * Returns the address for depositing BTC.\n *\n * @param {IGetDepositBtcAddressParams} params - function parameters\n *\n * @returns {Promise<string>} the address for depositing BTC\n */\nexport async function getDepositBtcAddress({\n address,\n chainId,\n env,\n referralId,\n}: IGetDepositBtcAddressParams): Promise<string> {\n const addresses = await getDepositBtcAddresses({\n address,\n chainId,\n env,\n referralId,\n });\n\n const addressData = getActualAddress(addresses);\n\n if (!addressData) {\n throw new Error('No address');\n }\n\n return addressData.btc_address;\n}\n\n/**\n * Retrieves the actual deposit address from a list of deposit addresses.\n *\n * @param addresses - The list of deposit addresses.\n * @returns The actual deposit address or undefined if the last created address is deprecated.\n */\nfunction getActualAddress(\n addresses: IDepositAddress[],\n): IDepositAddress | undefined {\n if (!addresses.length) {\n return undefined;\n }\n\n const actualAddress = addresses.reduce((acc, address) => {\n if (acc.created_at < address.created_at) {\n return address;\n }\n return acc;\n }, addresses[0]);\n\n return actualAddress.deprecated ? undefined : actualAddress;\n}\n\n/**\n * Returns the addresses for depositing BTC.\n *\n * @param {IGetDepositBtcAddressParams} params - function parameters\n *\n * @returns {Promise<IDepositAddress[]>} the deposit addresses\n */\nexport async function getDepositBtcAddresses({\n address,\n chainId,\n env,\n referralId,\n}: IGetDepositBtcAddressParams): Promise<IDepositAddress[]> {\n const { baseApiUrl } = getApiConfig(env);\n const toBlockchain = getChainNameById(chainId);\n\n const requestrParams = {\n to_address: address,\n to_blockchain: toBlockchain,\n limit: 1,\n offset: 0,\n asc: false,\n referral_id: referralId,\n };\n\n const { data } = await axios.get<IDepositAddressesResponse>(ADDRESS_URL, {\n baseURL: baseApiUrl,\n params: requestrParams,\n });\n\n return data?.addresses || [];\n}\n","const BTC_DECIMALS = 8;\nconst SATOSHI_SCALE = 10 ** BTC_DECIMALS;\n\n/**\n * Convert Satoshi to BTC\n * @param amount - Satoshi amount\n * @returns BTC amount\n */\nexport function fromSatoshi(amount: number | string) {\n return +amount / SATOSHI_SCALE;\n}\n\n/**\n * Convert BTC to Satoshi\n *\n * @param amount - BTC amount\n * @returns Satoshi amount\n */\nexport function toSatoshi(amount: number | string) {\n return Math.floor(+amount * SATOSHI_SCALE);\n}\n","import { defaultEnv } from '../../common/const';\nimport { OChainId, OEnv, TChainId, TEnv } from '../../common/types/types';\nimport { TChainName } from '../internalTypes';\n\n/**\n * @param chainId the chain ID\n *\n * @returns the chain name\n */\nexport function getCainIdByName(\n chain: string,\n env: TEnv = defaultEnv,\n): TChainId {\n switch (chain as TChainName) {\n case 'DESTINATION_BLOCKCHAIN_ETHEREUM':\n return env === OEnv.prod ? OChainId.ethereum : OChainId.holesky;\n\n default:\n return OChainId.ethereum;\n }\n}\n","import axios from 'axios';\nimport { IEnvParam } from '../../common/types/internalTypes';\nimport { TChainId, TEnv } from '../../common/types/types';\nimport { fromSatoshi } from '../../common/utils/convertSatoshi';\nimport { getApiConfig } from '../apiConfig';\nimport { getCainIdByName } from '../utils/getCainIdByName';\n\ntype Address = string;\ntype Seconds = number;\n\ninterface IDepositResponse {\n txid: string;\n value: number;\n address: Address;\n to_chain: string;\n notarization_wait_dur?: string | number;\n index?: number;\n raw_payload?: string;\n payload?: string;\n signature?: string;\n claim_tx?: string;\n block_height?: string;\n block_time?: string;\n sanctioned?: boolean;\n}\n\ninterface IDepositsByAddressResponse {\n outputs: IDepositResponse[];\n}\n\nexport interface IDeposit {\n txid: string;\n index?: number;\n blockHeight?: number;\n blockTime?: number;\n value: number;\n address: Address;\n chainId: TChainId;\n isClaimed: boolean;\n rawPayload?: string;\n signature?: string;\n isRestricted?: boolean;\n notarizationWaitDur?: Seconds;\n}\n\nexport interface IGetDepositsByAddressParams extends IEnvParam {\n /**\n * The EVM address to get deposits for\n */\n address: Address;\n}\n\n/**\n * Returns all deposits for a given address\n *\n * @param {IGetDepositsByAddressParams} params\n *\n * @returns {Promise<IDeposit[]>} a list of deposits\n */\nexport async function getDepositsByAddress({\n address,\n env,\n}: IGetDepositsByAddressParams): Promise<IDeposit[]> {\n const { baseApiUrl } = getApiConfig(env);\n\n const { data } = await axios.get<IDepositsByAddressResponse | undefined>(\n `api/v1/address/outputs/${address}`,\n { baseURL: baseApiUrl },\n );\n\n const outputs = data?.outputs ?? [];\n\n return outputs.map(mapResponse(env));\n}\n\nfunction mapResponse(env?: TEnv) {\n return (data: IDepositResponse): IDeposit => ({\n txid: data.txid,\n index: data.index ?? 0,\n blockHeight: data.block_height ? Number(data.block_height) : undefined,\n blockTime: data.block_time ? Number(data.block_time) : undefined,\n value: fromSatoshi(data.value),\n address: data.address,\n chainId: getCainIdByName(data.to_chain, env),\n // todo: return claiming tx from the API when it's available\n isClaimed: !!data.claim_tx,\n rawPayload: data.raw_payload,\n signature: data.signature,\n isRestricted: !!data.sanctioned,\n notarizationWaitDur: data.notarization_wait_dur\n ? Number(data.notarization_wait_dur)\n : undefined,\n });\n}\n","import axios from 'axios';\nimport { IEnvParam } from '../../common/types/internalTypes';\nimport { TChainId } from '../../common/types/types';\nimport { getApiConfig } from '../apiConfig';\nimport { getChainNameById } from '../utils/getChainNameById';\n\ntype ExchangeRateResponse = {\n amount_out: string;\n};\n\nexport interface IGetLBTCExchageRateParams extends IEnvParam {\n /**\n * The chain id of the asset to get the exchange rate for\n */\n chainId: TChainId;\n /**\n * The amount of the asset to get the exchange rate for\n */\n amount: number;\n}\n\n/**\n * Retrieves the exchange rate for LBTC.\n *\n * @param {IGetLBTCExchageRateParams} params\n *\n * @returns {Promise<string>} - The exchange rate.\n */\nexport async function getLBTCExchageRate({\n env,\n chainId,\n amount,\n}: IGetLBTCExchageRateParams): Promise<string> {\n const { baseApiUrl } = getApiConfig(env);\n const chainIdName = getChainNameById(chainId);\n\n const { data } = await axios.get<ExchangeRateResponse>(\n `api/v1/exchange/rate/${chainIdName}`,\n { baseURL: baseApiUrl, params: { amount } },\n );\n\n return data.amount_out;\n}\n","import { OChainId } from '../common/types/types';\n\nexport type TRpcUrlConfig = Record<number, string>;\n\nexport const rpcUrlConfig: TRpcUrlConfig = {\n [OChainId.ethereum]: 'https://rpc.ankr.com/eth',\n [OChainId.holesky]: 'https://rpc.ankr.com/eth_holesky',\n};\n","import BigNumber from 'bignumber.js';\nimport Web3 from 'web3';\n\nexport async function getMaxPriorityFeePerGas(\n rpcUrl: string,\n): Promise<BigNumber> {\n const response = await fetch(rpcUrl, {\n method: 'POST',\n headers: {\n 'Content-Type': 'application/json',\n },\n body: JSON.stringify({\n jsonrpc: '2.0',\n id: 1,\n method: 'eth_maxPriorityFeePerGas',\n params: [],\n }),\n });\n\n const data = await response.json();\n\n const convertedHexValue = Web3.utils.hexToNumber(data?.result);\n\n return new BigNumber(Number(convertedHexValue));\n}\n","import BigNumber from 'bignumber.js';\nimport Web3, { Contract, ContractAbi } from 'web3';\nimport {\n TRpcUrlConfig,\n rpcUrlConfig as defaultRpcUrlConfig,\n} from './rpcUrlConfig';\nimport { IGetMaxFeesResult } from './types';\nimport { getMaxPriorityFeePerGas } from './utils/getMaxPriorityFeePerGas';\n\nconst FEE_MULTIPLIER = 2;\nconst ADDITIONAL_SAFE_GAS_PRICE_WEI = 25_000;\n\nexport interface IReadProviderParams {\n /**\n * Chain ID of the network to interact with.\n */\n chainId: number;\n /**\n * The RPC URL configuration. If not provided, the default configuration will be used.\n */\n rpcUrlConfig?: TRpcUrlConfig;\n}\n\nexport class ReadProvider {\n chainId: number;\n rpcConfig: TRpcUrlConfig;\n\n constructor({ chainId, rpcUrlConfig }: IReadProviderParams) {\n this.chainId = chainId;\n this.rpcConfig = { ...defaultRpcUrlConfig, ...rpcUrlConfig };\n }\n\n /**\n * Returns web3 instance for read operations.\n *\n * @public\n * @returns {Web3} Web3 instance.\n */\n public getReadWeb3(): Web3 {\n const rpcUrl = this.getRpcUrl();\n const readWeb3 = new Web3();\n const provider = new Web3.providers.HttpProvider(rpcUrl);\n readWeb3.setProvider(provider);\n return readWeb3;\n }\n\n /**\n * Retrieves the RPC URL based on the current chain ID.\n * @returns The RPC URL for the current chain ID.\n * @throws Error if the RPC URL for the current chain ID is not found.\n */\n getRpcUrl(): string {\n const { chainId } = this;\n const rpcUrl = this.rpcConfig?.[chainId];\n\n if (!rpcUrl) {\n console.error(\n `You might need to add the rpcConfig for the ${chainId} chain ID when creating the provider.`,\n );\n throw new Error(`RPC URL for chainId ${chainId} not found`);\n }\n\n return rpcUrl;\n }\n\n /**\n * Calculates max fees for transaction. Thess values are available for networks\n * with EIP-1559 support.\n *\n * @public\n * @note If current network is Binance Smart Chain, will return default values.\n * @returns {Promise<IGetMaxFeesResult>} Max fees for transaction.\n */\n public async getMaxFees(): Promise<IGetMaxFeesResult> {\n const web3 = this.getReadWeb3();\n const rpcUrl = this.getRpcUrl();\n\n const [block, maxPriorityFeePerGas] = await Promise.all([\n web3.eth.getBlock('latest'),\n getMaxPriorityFeePerGas(rpcUrl),\n ]);\n\n if (!block?.baseFeePerGas && typeof block?.baseFeePerGas !== 'bigint') {\n return {};\n }\n\n const maxFeePerGas = new BigNumber(block.baseFeePerGas.toString(10))\n .multipliedBy(FEE_MULTIPLIER)\n .plus(maxPriorityFeePerGas);\n\n return {\n maxFeePerGas: +maxFeePerGas,\n maxPriorityFeePerGas: +maxPriorityFeePerGas,\n };\n }\n\n /**\n * Returns safe gas price for transaction.\n *\n * @public\n * @returns {Promise<BigNumber>} Safe gas price.\n */\n public async getSafeGasPriceWei(): Promise<BigNumber> {\n const pureGasPriceWei = await this.getReadWeb3().eth.getGasPrice();\n\n return new BigNumber(pureGasPriceWei.toString(10)).plus(\n ADDITIONAL_SAFE_GAS_PRICE_WEI,\n );\n }\n\n /**\n * Creates a contract instance with the given ABI and address.\n *\n * @template AbiType - The type of the contract ABI.\n * @param {any} abi - The ABI of the contract.\n * @param {string} address - The address of the contract.\n * @returns {Contract<AbiType>} The contract instance.\n */\n public createContract<AbiType extends ContractAbi>(\n abi: any,\n address: string,\n ): Contract<AbiType> {\n const web3 = this.getReadWeb3();\n return new web3.eth.Contract<AbiType>(abi, address);\n }\n}\n","import Web3, { Contract, ContractAbi, Transaction, utils } from 'web3';\nimport { IEIP1193Provider } from '../common/types/types';\nimport { IReadProviderParams, ReadProvider } from './ReadProvider';\nimport {\n TRpcUrlConfig,\n rpcUrlConfig as defaultRpcUrlConfig,\n} from './rpcUrlConfig';\nimport { ISendOptions, IWeb3SendResult } from './types';\n\nexport interface IProviderParams extends IReadProviderParams {\n /**\n * The EIP-1193 provider instance.\n */\n provider: IEIP1193Provider;\n /**\n * The сurrent account address.\n */\n account: string;\n}\n\n/**\n * Provider for interacting with a blockchain network.\n */\nexport class Provider extends ReadProvider {\n web3: Web3;\n account: string;\n rpcConfig: TRpcUrlConfig = defaultRpcUrlConfig;\n\n constructor({ provider, account, chainId, rpcUrlConfig }: IProviderParams) {\n super({ chainId, rpcUrlConfig });\n this.web3 = new Web3(provider);\n this.account = account;\n this.chainId = chainId;\n this.rpcConfig = { ...defaultRpcUrlConfig, ...rpcUrlConfig };\n }\n\n /**\n * Signs a message using the current provider and account.\n * @public\n * @param message - The message to be signed.\n * @returns A promise that resolves to the signed message as a string.\n */\n public async signMessage(message: string): Promise<string> {\n const { account } = this;\n\n const messageHex = `0x${Buffer.from(message, 'utf8').toString('hex')}`;\n\n const ethereum = this.web3.currentProvider as any;\n\n return ethereum.request({\n method: 'personal_sign',\n params: [messageHex, account],\n });\n }\n\n /**\n * Custom replacement for web3js [send](https://docs.web3js.org/libdocs/Contract#send).\n *\n * @public\n * @param {string} from - Address of the sender.\n * @param {string} to - Address of the recipient.\n * @param {ISendOptions} sendOptions - Options for sending transaction.\n * @returns {Promise<IWeb3SendResult>} Promise with transaction hash and receipt promise.\n */\n public async sendTransactionAsync(\n from: string,\n to: string,\n sendOptions: ISendOptions,\n ): Promise<IWeb3SendResult> {\n const { chainId, web3: web3Write } = this;\n const web3Read = this.getReadWeb3();\n\n const {\n data,\n estimate = false,\n estimateFee = false,\n extendedGasLimit,\n gasLimit = '0',\n value = '0',\n gasLimitMultiplier = 1,\n } = sendOptions;\n let { nonce } = sendOptions;\n\n if (!nonce) {\n nonce = await web3Read.eth.getTransactionCount(from);\n }\n\n console.log(`Nonce: ${nonce}`);\n\n const tx: Transaction = {\n from,\n to,\n value: utils.numberToHex(value),\n data,\n nonce,\n chainId: utils.numberToHex(chainId),\n };\n\n if (estimate) {\n try {\n const estimatedGas = await web3Read.eth.estimateGas(tx);\n const multipliedGasLimit = Math.round(\n Number(estimatedGas) * gasLimitMultiplier,\n );\n\n if (extendedGasLimit) {\n tx.gas = utils.numberToHex(multipliedGasLimit + extendedGasLimit);\n } else {\n tx.gas = utils.numberToHex(multipliedGasLimit);\n }\n } catch (e) {\n throw new Error(\n (e as Partial<Error>).message ??\n 'Failed to estimate gas limit for transaction.',\n );\n }\n } else {\n tx.gas = utils.numberToHex(gasLimit);\n }\n\n const { maxFeePerGas, maxPriorityFeePerGas } = estimateFee\n ? await this.getMaxFees().catch(() => sendOptions)\n : sendOptions;\n\n if (maxPriorityFeePerGas !== undefined) {\n tx.maxPriorityFeePerGas = utils.numberToHex(maxPriorityFeePerGas);\n }\n\n if (maxFeePerGas !== undefined) {\n tx.maxFeePerGas = utils.numberToHex(maxFeePerGas);\n }\n\n if (!tx.maxFeePerGas && !tx.maxPriorityFeePerGas) {\n const safeGasPrice = await this.getSafeGasPriceWei();\n tx.gasPrice = safeGasPrice.toString(10);\n }\n\n if (!tx.maxFeePerGas && !tx.maxPriorityFeePerGas) {\n const safeGasPrice = await this.getSafeGasPriceWei();\n tx.gasPrice = safeGasPrice.toString(10);\n }\n\n console.log('Sending transaction via Web3: ', tx);\n\n return new Promise((resolve, reject) => {\n const promise = web3Write.eth.sendTransaction(tx);\n\n promise\n .once('transactionHash', async (transactionHash: string) => {\n console.log(`Just signed transaction has is: ${transactionHash}`);\n\n resolve({\n receiptPromise: promise,\n transactionHash,\n });\n })\n .catch(reject);\n });\n }\n\n public createContract<AbiType extends ContractAbi>(\n abi: any,\n address: string,\n ): Contract<AbiType> {\n return new this.web3.eth.Contract<AbiType>(abi, address);\n }\n}\n","import { OChainId } from '../../common/types/types';\n\n/**\n * Returns the gas multiplier for the given chain ID.\n *\n * @param chainId - Chain ID.\n *\n * @returns Gas multiplier.\n */\nexport function getGasMultiplier(chainId: number): number {\n switch (chainId) {\n case OChainId.ethereum:\n return 1.3;\n case OChainId.holesky:\n return 1.5;\n default:\n return 1.3;\n }\n}\n","import { OChainId, TChainId } from '../types/types';\n\nexport function isValidChain(chainId: number): chainId is TChainId {\n return Object.values(OChainId).includes(chainId as TChainId);\n}\n","import {\n defaultEnv,\n ZERO_ADDRESS as PLACEHOLDER_ADDRESS,\n} from '../common/const';\nimport { OChainId, OEnv, TChainId, TEnv } from '../common/types/types';\n\ntype LbtcTokenConfig = Record<TChainId, string>;\n\nconst stageConfig: LbtcTokenConfig = {\n [OChainId.holesky]: '0xED7bfd5C1790576105Af4649817f6d35A75CD818',\n [OChainId.ethereum]: PLACEHOLDER_ADDRESS,\n};\n\nconst testnetConfig: LbtcTokenConfig = {\n [OChainId.holesky]: '0x38A13AB20D15ffbE5A7312d2336EF1552580a4E2',\n [OChainId.ethereum]: PLACEHOLDER_ADDRESS,\n};\n\nconst prodConfig: LbtcTokenConfig = {\n [OChainId.holesky]: PLACEHOLDER_ADDRESS,\n [OChainId.ethereum]: '0x8236a87084f8b84306f72007f36f2618a5634494',\n};\n\nexport function getLbtcAddressConfig(env: TEnv = defaultEnv): LbtcTokenConfig {\n switch (env) {\n case OEnv.prod:\n return prodConfig;\n case OEnv.testnet:\n return testnetConfig;\n default:\n return stageConfig;\n }\n}\n","import { IERC20, LBTCABI } from '../abi';\n\ntype Token = 'LBTC' | 'ERC20';\n\nexport function getTokenABI(token: Token) {\n switch (token) {\n case 'LBTC':\n return LBTCABI;\n default:\n return IERC20;\n }\n}\n","import { TEnv } from '../../common/types/types';\nimport { isValidChain } from '../../common/utils/isValidChain';\nimport { Provider } from '../../provider';\nimport { getLbtcAddressConfig } from '../lbtcAddressConfig';\nimport { getTokenABI } from './getTokenABI';\n\nexport function getLbtcTokenContract(provider: Provider, env?: TEnv) {\n const lbtcAddressConfig = getLbtcAddressConfig(env);\n const { chainId } = provider;\n\n if (!isValidChain(chainId)) {\n throw new Error(`This chain ${chainId} is not supported`);\n }\n\n const tokenAddress = lbtcAddressConfig[chainId];\n\n if (!tokenAddress) {\n throw new Error(`Token address for chain ${chainId} is not defined`);\n }\n\n const abi = getTokenABI('LBTC');\n\n const contract = provider.createContract(abi, tokenAddress);\n\n if (!contract.options.address) {\n contract.options.address = tokenAddress;\n }\n\n return contract as typeof contract & {\n options: typeof contract.options & { address: string };\n };\n}\n","import { IEnvParam } from '../../common/types/internalTypes';\nimport { toSatoshi } from '../../common/utils/convertSatoshi';\nimport { IWeb3SendResult, Provider } from '../../provider';\nimport { IProviderBasedParams } from '../types';\nimport { getGasMultiplier } from '../utils/getGasMultiplier';\nimport { getLbtcTokenContract } from '../utils/getLbtcTokenContract';\n\nexport interface IApproveLBTCParams extends IProviderBasedParams, IEnvParam {\n /**\n * Spender address\n */\n spender: string;\n /**\n * The amount of LBTC to approve\n */\n amount: number;\n}\n\n/**\n * Approves the transfer of a specified amount of LBTC tokens.\n *\n * @param {IApproveLBTCParams} params\n *\n * @returns {Promise<IWeb3SendResult>} transaction promise\n */\nexport function approveLBTC({\n spender,\n amount,\n env,\n ...providerParams\n}: IApproveLBTCParams): Promise<IWeb3SendResult> {\n const provider = new Provider(providerParams);\n const tokenContract = getLbtcTokenContract(provider, env);\n const amountSat = toSatoshi(amount);\n\n const tx = tokenContract.methods.approve(spender, amountSat);\n\n return provider.sendTransactionAsync(\n provider.account,\n tokenContract.options.address,\n {\n data: tx.encodeABI(),\n estimate: true,\n estimateFee: true,\n gasLimitMultiplier: getGasMultiplier(provider.chainId),\n },\n );\n}\n","import { IEnvParam } from '../../common/types/internalTypes';\nimport { getErrorMessage } from '../../common/utils/getErrorMessage';\nimport { IWeb3SendResult, Provider } from '../../provider';\nimport { IProviderBasedParams } from '../types';\nimport { getGasMultiplier } from '../utils/getGasMultiplier';\nimport { getLbtcTokenContract } from '../utils/getLbtcTokenContract';\n\nconst INSUFFICIENT_FUNDS_PARTIAL_ERROR = 'insufficient funds';\n\nconst INSUFFICIENT_FUNDS_ERROR =\n 'Insufficient funds for transfer. Make sure you have enough ETH to cover the gas cost.';\n\nexport interface IClaimLBTCParams extends IProviderBasedParams, IEnvParam {\n /**\n * Raw payload from deposit notarization.\n */\n data: string;\n /**\n * Signature from deposit notarization.\n */\n proofSignature: string;\n}\n\n/**\n * Claims LBTC.\n *\n * @param {IClaimLBTCParams} params - The parameters for claiming LBTC.\n *\n * @returns {Promise<IWeb3SendResult>} transaction promise\n */\nexport async function claimLBTC({\n data,\n proofSignature,\n env,\n ...providerParams\n}: IClaimLBTCParams): Promise<IWeb3SendResult> {\n const provider = new Provider(providerParams);\n const tokenContract = getLbtcTokenContract(provider, env);\n\n const tx = tokenContract.methods.mint(data, proofSignature);\n\n try {\n const result = await provider.sendTransactionAsync(\n provider.account,\n tokenContract.options.address,\n {\n data: tx.encodeABI(),\n estimate: true,\n estimateFee: true,\n gasLimitMultiplier: getGasMultiplier(provider.chainId),\n },\n );\n\n return result;\n } catch (error) {\n const errorMessage = getErrorMessage(error);\n\n if (errorMessage.includes(INSUFFICIENT_FUNDS_PARTIAL_ERROR)) {\n throw new Error(INSUFFICIENT_FUNDS_ERROR);\n }\n\n throw new Error(errorMessage);\n }\n}\n","import { Provider } from '../../provider';\nimport { IProviderBasedParams } from '../types';\n\nexport type SignLbtcDestionationAddrParams = IProviderBasedParams;\n\n/**\n * Signs the destination address for the LBTC in active chain\n * in the current account. Signing is necessary for the\n * generation of the deposit address.\n *\n * @param {SignLbtcDestionationAddrParams} params\n *\n * @returns {Promise<string>} The signature of the message.\n */\nexport async function signLbtcDestionationAddr(\n params: SignLbtcDestionationAddrParams,\n): Promise<string> {\n const provider = new Provider(params);\n\n const message = `destination chain id is ${params.chainId}`;\n\n return provider.signMessage(message);\n}\n","import * as ecc from '@bitcoin-js/tiny-secp256k1-asmjs';\nimport {\n address as addressUtils,\n initEccLib,\n networks,\n payments,\n} from 'bitcoinjs-lib';\nimport { OEnv, TEnv } from '../../common/types/types';\n\ninitEccLib(ecc);\n\ntype AddressType = 'p2tr' | 'p2wpkh' | 'p2wsh';\n\n/**\n * Get output script from address.\n *\n * @param address - The address.\n * @param networkMode - The network mode.\n *\n * @returns The output script.\n */\nexport function getOutputScript(\n address: string,\n env: TEnv = OEnv.prod,\n): string {\n const addressType = getAddressType(address);\n\n const payment = payments[addressType]({\n address,\n network: env === OEnv.prod ? networks.bitcoin : networks.testnet,\n });\n\n const paymentOutputScript = payment.output?.toString('hex');\n\n if (!paymentOutputScript) {\n throw new Error('Output script is not found.');\n }\n\n return `0x${paymentOutputScript}`;\n}\n\nfunction getAddressType(address: string): AddressType {\n const result = addressUtils.fromBech32(address);\n\n const isP2TR = result.version === 1 && result.data.length === 32;\n if (isP2TR) {\n return 'p2tr';\n }\n\n const isP2WPKH = result.version === 0 && result.data.length === 20;\n if (isP2WPKH) {\n return 'p2wpkh';\n }\n\n if (isP2WSHAddressType(address)) {\n return 'p2wsh';\n }\n\n throw new Error('Address type is not supported.');\n}\n\nfunction isP2WSHAddressType(address: string): boolean {\n return (\n (address.startsWith('bc1') || address.startsWith('tb1')) &&\n address.length === 62\n );\n}\n","import { getOutputScript } from '../../btcSdk/utils/getOutputScript';\nimport { IEnvParam } from '../../common/types/internalTypes';\nimport { toSatoshi } from '../../common/utils/convertSatoshi';\nimport { IWeb3SendResult, Provider } from '../../provider';\nimport { IProviderBasedParams } from '../types';\nimport { getGasMultiplier } from '../utils/getGasMultiplier';\nimport { getLbtcTokenContract } from '../utils/getLbtcTokenContract';\n\nexport interface IUnstakeLBTCParams extends IProviderBasedParams, IEnvParam {\n /**\n * The BTC address to send the unstaked BTC to.\n */\n btcAddress: string;\n /**\n * The amount of LBTC to unstake.\n */\n amount: number;\n}\n\n/**\n * Unstakes LBTC to the specified BTC address.\n *\n * @param {IUnstakeLBTCParams} params\n *\n * @returns {Promise<IWeb3SendResult>} transaction promise\n */\nexport function unstakeLBTC({\n btcAddress,\n amount,\n env,\n ...providerParams\n}: IUnstakeLBTCParams): Promise<IWeb3SendResult> {\n const provider = new Provider(providerParams);\n const tokenContract = getLbtcTokenContract(provider, env);\n const outputScript = getOutputScript(btcAddress, env);\n\n const amountSat = toSatoshi(amount);\n\n const tx = tokenContract.methods.redeem(outputScript, amountSat);\n\n return provider.sendTransactionAsync(\n provider.account,\n tokenContract.options.address,\n {\n data: tx.encodeABI(),\n estimate: true,\n estimateFee: true,\n gasLimitMultiplier: getGasMultiplier(provider.chainId),\n },\n );\n}\n"],"names":["OEnv","OChainId","defaultEnv","ZERO_ADDRESS","stageConfig","testnetConfig","prodConfig","getApiConfig","env","getErrorMessage","error","getAxiosErrorMessage","getErrorMessageFromObject","OChainName","getChainNameById","chainId","SANCTIONED_ADDRESS","ADDRESS_URL","SANCTIONS_MESSAGE","generateDepositBtcAddress","address","signature","referralId","captchaToken","baseApiUrl","toChain","requestParams","data","axios","errorMsg","isSanctioned","getDepositBtcAddress","addresses","getDepositBtcAddresses","addressData","getActualAddress","actualAddress","acc","toBlockchain","requestrParams","BTC_DECIMALS","SATOSHI_SCALE","fromSatoshi","amount","toSatoshi","getCainIdByName","chain","getDepositsByAddress","mapResponse","getLBTCExchageRate","chainIdName","rpcUrlConfig","getMaxPriorityFeePerGas","rpcUrl","convertedHexValue","Web3","BigNumber","FEE_MULTIPLIER","ADDITIONAL_SAFE_GAS_PRICE_WEI","ReadProvider","__publicField","defaultRpcUrlConfig","readWeb3","provider","_a","web3","block","maxPriorityFeePerGas","pureGasPriceWei","abi","Provider","account","message","messageHex","from","to","sendOptions","web3Write","web3Read","estimate","estimateFee","extendedGasLimit","gasLimit","value","gasLimitMultiplier","nonce","tx","utils","estimatedGas","multipliedGasLimit","e","maxFeePerGas","safeGasPrice","resolve","reject","promise","transactionHash","getGasMultiplier","isValidChain","PLACEHOLDER_ADDRESS","getLbtcAddressConfig","getTokenABI","token","LBTCABI","IERC20","getLbtcTokenContract","lbtcAddressConfig","tokenAddress","contract","approveLBTC","spender","providerParams","tokenContract","amountSat","INSUFFICIENT_FUNDS_PARTIAL_ERROR","INSUFFICIENT_FUNDS_ERROR","claimLBTC","proofSignature","errorMessage","signLbtcDestionationAddr","params","initEccLib","ecc","getOutputScript","addressType","getAddressType","paymentOutputScript","payments","networks","result","addressUtils","isP2WSHAddressType","unstakeLBTC","btcAddress","outputScript"],"mappings":";;;;;;;;AAAO,MAAMA,IAAO;AAAA,EAClB,MAAM;AAAA,EACN,SAAS;AAAA,EACT,OAAO;AACT,GAIaC,IAAW;AAAA,EACtB,UAAU;AAAA,EACV,SAAS;AACX,GCTaC,IAAmBF,EAAK,MAMxBG,IAAe,8CCDtBC,IAA0B;AAAA,EAC9B,YAAY;AACd,GAEMC,IAA4B;AAAA,EAChC,YAAY;AACd,GAEMC,IAAyB;AAAA,EAC7B,YAAY;AACd,GAEaC,IAAe,CAACC,IAAYN,MAA2B;AAClE,UAAQM,GAAK;AAAA,IACX,KAAKR,EAAK;AACD,aAA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IACTiD,EAAc,QAAQ;AAAA,IACtB;AAAA,MACE,MAAM1B,EAAG,UAAU;AAAA,MACnB,UAAU;AAAA,MACV,aAAa;AAAA,MACb,oBAAoBW,EAAiBlC,EAAS,OAAO;AAAA,IACvD;AAAA,EAAA;AAEJ;"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@lombard.finance/sdk",
3
- "version": "0.8.4",
3
+ "version": "0.9.0",
4
4
  "exports": {
5
5
  ".": {
6
6
  "import": "./dist/index.js",
@@ -9,6 +9,8 @@ import { OEnv, TEnv } from '../../common/types/types';
9
9
 
10
10
  initEccLib(ecc);
11
11
 
12
+ type AddressType = 'p2tr' | 'p2wpkh' | 'p2wsh';
13
+
12
14
  /**
13
15
  * Get output script from address.
14
16
  *
@@ -21,9 +23,9 @@ export function getOutputScript(
21
23
  address: string,
22
24
  env: TEnv = OEnv.prod,
23
25
  ): string {
24
- const paymentType = getPaymentType(address);
26
+ const addressType = getAddressType(address);
25
27
 
26
- const payment = payments[paymentType]({
28
+ const payment = payments[addressType]({
27
29
  address,
28
30
  network: env === OEnv.prod ? networks.bitcoin : networks.testnet,
29
31
  });
@@ -37,7 +39,7 @@ export function getOutputScript(
37
39
  return `0x${paymentOutputScript}`;
38
40
  }
39
41
 
40
- function getPaymentType(address: string): 'p2tr' | 'p2wpkh' {
42
+ function getAddressType(address: string): AddressType {
41
43
  const result = addressUtils.fromBech32(address);
42
44
 
43
45
  const isP2TR = result.version === 1 && result.data.length === 32;
@@ -50,5 +52,16 @@ function getPaymentType(address: string): 'p2tr' | 'p2wpkh' {
50
52
  return 'p2wpkh';
51
53
  }
52
54
 
53
- throw new Error('Payment type is not supported.');
55
+ if (isP2WSHAddressType(address)) {
56
+ return 'p2wsh';
57
+ }
58
+
59
+ throw new Error('Address type is not supported.');
60
+ }
61
+
62
+ function isP2WSHAddressType(address: string): boolean {
63
+ return (
64
+ (address.startsWith('bc1') || address.startsWith('tb1')) &&
65
+ address.length === 62
66
+ );
54
67
  }
@@ -24,7 +24,7 @@ export interface IProviderParams extends IReadProviderParams {
24
24
  export class Provider extends ReadProvider {
25
25
  web3: Web3;
26
26
  account: string;
27
- rpcConfig: TRpcUrlConfig;
27
+ rpcConfig: TRpcUrlConfig = defaultRpcUrlConfig;
28
28
 
29
29
  constructor({ provider, account, chainId, rpcUrlConfig }: IProviderParams) {
30
30
  super({ chainId, rpcUrlConfig });