@gardenfi/core 0.2.0-beta.51 → 0.2.0-beta.52
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 +1 -1
- package/dist/index.js +6 -2
- package/package.json +1 -1
package/dist/index.cjs
CHANGED
|
@@ -20,7 +20,7 @@
|
|
|
20
20
|
OP_CHECKSIGADD
|
|
21
21
|
OP_2
|
|
22
22
|
OP_NUMEQUAL
|
|
23
|
-
`.trim().replace(/\s+/g," "))}leaves(){return[{version:tr,output:this.redeemLeaf()},[{version:tr,output:this.refundLeaf()},{version:tr,output:this.instantRefundLeaf()}]]}generateMerkleProofFor(t){const r=this.leafHash(1),n=this.leafHash(2),i=this.leafHash(0);switch(t){case 1:{const a=Pa(i,n);return[ye.crypto.taggedHash("TapBranch",Buffer.concat(a))]}case 0:return[n,r];case 2:return[i,r];default:throw new Error(we.invalidLeaf)}}}function Or(e,t){const r=[];for(let n=0;n<t;n++)r.push(e);return r}class za{constructor(){this.cache={}}set(t,r,n,i){const a={txHash:n,timeStamp:Date.now(),btcRedeemUTXO:i};this.cache[`${r}_${t.create_order.create_id}`]=a}get(t,r){return this.cache[`${r}_${t.create_order.create_id}`]||null}remove(t,r){delete this.cache[`${r}_${t.create_order.create_id}`]}}class qi{constructor(t,r){this.url=new ge.Url("/blocknumber/"+r,t)}async fetchBlockNumbers(){console.log("this.url :",this.url.toString());try{const t=await k.Fetcher.get(this.url);return k.Ok(t)}catch(t){return k.Err("Failed to fetch block numbers",t)}}}class ja{constructor(t){if(this.eventListeners=new Map,this.getOrderThreshold=20,this.pendingOrdersCount=0,this.useRelay=!0,this.orderBook=new J.Orderbook({url:t.orderbookURl,walletClient:t.wallets.evmWallet,auth:t.auth}),this.quote=t.quote,this.secretManager=t.secretManager,this.wallets=t.wallets,this.orderbookUrl=t.orderbookURl,this.auth=t.auth,this.orderExecutorCache=new za,!t.wallets.evmWallet.account)throw new Error("Account not found in evmWallet");this.evmAddress=t.wallets.evmWallet.account.address,this.blockNumberFetcher=t.blockNumberFetcher&&new qi(t.blockNumberFetcher.url,t.blockNumberFetcher.network)}getPendingOrderCount(){return this.pendingOrdersCount}setUseRelay(t){this.useRelay=t}async swap(t){const r=await this.validateAndFillParams(t);if(r.error)return k.Err(r.error);const{sendAddress:n,receiveAddress:i,timelock:a}=r.val,f=await this.orderBook.getOrdersCount(this.evmAddress);if(f.error)return k.Err(f.error);const u=f.val+1,l=this.secretManager.generateSecret(u);if(l.error)return k.Err(l.error);const{strategyId:y,btcAddress:g}=t.additionalData,m={strategy_id:y,...g&&{bitcoin_optional_recipient:g}},E={source_chain:t.fromAsset.chain,destination_chain:t.toAsset.chain,source_asset:t.fromAsset.atomicSwapAddress,destination_asset:t.toAsset.atomicSwapAddress,initiator_source_address:n,initiator_destination_address:i,source_amount:t.sendAmount,destination_amount:t.receiveAmount,fee:"1",nonce:u.toString(),timelock:a,secret_hash:k.trim0x(l.val.secretHash),min_destination_confirmations:t.minDestinationConfirmations??0,additional_data:m},I=await this.quote.getAttestedQuote(E);if(I.error)return k.Err(I.error);const v=await this.orderBook.createOrder(I.val);if(v.error)return k.Err(v.error);const P=await this.pollOrder(v.val);return P.error?k.Err(P.error):k.Ok(P.val)}async validateAndFillParams(t){if(t.fromAsset.chain===t.toAsset.chain&&t.fromAsset.atomicSwapAddress===t.toAsset.atomicSwapAddress)return k.Err("Source and destination assets cannot be the same");if(J.isMainnet(t.fromAsset.chain)&&!J.isMainnet(t.toAsset.chain)||!J.isMainnet(t.fromAsset.chain)&&J.isMainnet(t.toAsset.chain))return k.Err("Both assets should be on the same network (either mainnet or testnet)");if(J.isBitcoin(t.fromAsset.chain)||J.isBitcoin(t.toAsset.chain)){if(!this.wallets.btcWallet)return k.Err("btcWallet is required for bitcoin chain. Please provide btcWallet in the constructor");if(!t.additionalData.btcAddress)return k.Err("btcAddress in additionalData is required for bitcoin chain")}const r=await this.getAddresses(t.fromAsset.chain);if(r.error)return k.Err(r.error);const n=await this.getAddresses(t.toAsset.chain);if(n.error)return k.Err(n.error);const i=this.validateAmount(t.sendAmount);if(i.error)return k.Err(i.error);const a=this.validateAmount(t.receiveAmount);if(a.error)return k.Err(a.error);if(i<a)return k.Err("Send amount should be greater than receive amount");const f=this.getTimelock(t.fromAsset.chain);return f?k.Ok({sendAddress:r.val,receiveAddress:n.val,timelock:t.timelock??f}):k.Err("Unsupported chain for timelock")}async getAddresses(t){var n;switch(J.getBlockchainType(t)){case J.BlockchainType.EVM:return this.wallets.evmWallet.account?k.Ok(this.wallets.evmWallet.account.address):k.Err("EVM Wallet not found");case J.BlockchainType.Bitcoin:{const i=await((n=this.wallets.btcWallet)==null?void 0:n.getPublicKey());return!i||!Ca(i)?k.Err("Invalid btc public key"):k.Ok(Ot(i))}default:return k.Err("Unsupported chain")}}validateAmount(t){if(t==null||t.includes("."))return k.Err("Invalid amount ",t);const r=new Ds(t);return!r.isInteger()||r.isNaN()||r.lt(0)||r.isLessThanOrEqualTo(0)?k.Err("Invalid amount ",t):k.Ok(r)}getTimelock(t){switch(J.getBlockchainType(t)){case J.BlockchainType.EVM:return sr.evm;case J.BlockchainType.Bitcoin:return sr.btc;default:return}}async pollOrder(t){let r=await this.orderBook.getOrder(t,!0),n=0;for(;n<this.getOrderThreshold;){if(await ge.sleep(1e3),n++,r.error){if(!r.error.includes("result is undefined"))return k.Err(r.error)}else if(r.val&&r.val.create_order.create_id.toLowerCase()===t.toLowerCase())return k.Ok(r.val);r=await this.orderBook.getOrder(t,!0)}return k.Err(`Order not found, createOrder id: ${t}`)}emit(t,...r){(this.eventListeners.get(t)??[]).forEach(i=>{i(...r)})}async execute(t=5e3){return await this.orderBook.subscribeToOrders(!0,t,async r=>{var i;this.pendingOrdersCount=r.data.length,this.emit("onPendingOrdersChanged",r.data);const n=await((i=this.blockNumberFetcher)==null?void 0:i.fetchBlockNumbers());n&&console.log("blockNumbers :",n.val);for(let a=0;a<r.data.length;a++){const f=r.data[a],u=f.source_swap.chain,l=f.destination_swap.chain,y=this.getWallet(u),g=this.getWallet(l);if(y.error||g.error||!y.val||!g.val){this.emit("error",f,"Source or Destination Wallet not found while executing order");return}let m=n==null?void 0:n.val[u],E=n==null?void 0:n.val[l];if(console.log("sourceChainBlockNumber :",m),console.log("destinationChainBlockNumber :",E),!m||!E){const v=await this.fetchCurrentBlockNumbers(f,{source:y.val,destination:g.val});if(v.error){this.emit("error",f,"Error while fetching CurrentBlockNumbers: "+v.error);return}m=v.val.source,E=v.val.destination}switch(ji(f,m,E)){case ce.Redeem:{const v=this.secretManager.generateSecret(Number(f.create_order.nonce));if(v.error){this.emit("error",f,v.error);return}switch(J.getBlockchainType(f.destination_swap.chain)){case J.BlockchainType.EVM:{await this.evmRedeem(f,v.val.secret);break}case J.BlockchainType.Bitcoin:{await this.btcRedeem(g.val,f,v.val.secret);break}default:this.emit("error",f,"Unsupported chain: "+f.destination_swap.chain)}break}case ce.Refund:{switch(J.getBlockchainType(f.source_swap.chain)){case J.BlockchainType.EVM:{this.emit("error",f,"EVM refund is automatically done by relay service");break}case J.BlockchainType.Bitcoin:{await this.btcRefund(y.val,f);break}default:this.emit("error",f,"Unsupported chain: "+f.source_swap.chain)}break}}}},{per_page:500},!0)}async evmRedeem(t,r){if(this.emit("log",t.create_order.create_id,"executing evm redeem"),this.orderExecutorCache.get(t,ce.Redeem)){this.emit("log",t.create_order.create_id,"already redeemed");return}const a=await new Gi(t,this.orderbookUrl,this.auth).redeem(t.create_order.create_id,r);if(a.error){this.emit("error",t,a.error);return}this.emit("success",t,ce.Redeem,a.val),this.orderExecutorCache.set(t,ce.Redeem,a.val)}async btcRedeem(t,r,n){var f;const i=this.orderExecutorCache.get(r,ce.Redeem);let a=!1;if(i)if(i.btcRedeemUTXO&&i.btcRedeemUTXO!==r.destination_swap.initiate_tx_hash)a=!0,this.emit("log",r.create_order.create_id,"rbf btc redeem");else{this.emit("log",r.create_order.create_id,"btcRedeem: already redeemed");return}this.emit("log",r.create_order.create_id,"executing btc redeem");try{const l=await(await cr.from(t,Number(r.destination_swap.amount),r.create_order.secret_hash,Ot(r.destination_swap.initiator),Ot(r.destination_swap.redeemer),r.destination_swap.timelock,a?[r.destination_swap.initiate_tx_hash]:[])).redeem(k.trim0x(n),(f=r.create_order.additional_data)==null?void 0:f.bitcoin_optional_recipient);this.emit("success",r,ce.Redeem,l),this.orderExecutorCache.set(r,ce.Redeem,l,r.destination_swap.initiate_tx_hash)}catch(u){this.emit("error",r,"Failed btc redeem: "+u)}}async btcRefund(t,r){var n;if(!this.orderExecutorCache.get(r,ce.Refund)){this.emit("log",r.create_order.create_id,"executing btc refund");try{const a=await(await cr.from(t,Number(r.source_swap.amount),r.create_order.secret_hash,Ot(r.source_swap.initiator),Ot(r.source_swap.redeemer),r.source_swap.timelock)).refund((n=r.create_order.additional_data)==null?void 0:n.bitcoin_optional_recipient);this.emit("success",r,ce.Refund,a),this.orderExecutorCache.set(r,ce.Refund,a)}catch(i){this.emit("error",r,"Failed btc refund: "+i)}}}getWallet(t){switch(J.getBlockchainType(t)){case J.BlockchainType.EVM:return k.Ok(this.wallets.evmWallet);case J.BlockchainType.Bitcoin:return k.Ok(this.wallets.btcWallet);default:return k.Err("Unsupported chain for wallet")}}on(t,r){const n=this.eventListeners.get(t)??[];n.push(r),this.eventListeners.set(t,n)}off(t,r){const n=this.eventListeners.get(t)??[],i=n.indexOf(r);i!==-1&&n.splice(i,1)}async fetchCurrentBlockNumbers(t,r){if(!r||!r.source||!r.destination)return k.Err("Provide wallets to fetch the current block number");const n=J.isBitcoin(t.source_swap.chain)?await ge.fetchBitcoinBlockNumber(await r.source.getProvider()):await ge.fetchEVMBlockNumber(r.source);if(n.error)return k.Err(n.error);const i=J.isBitcoin(t.destination_swap.chain)?await ge.fetchBitcoinBlockNumber(await r.destination.getProvider()):await ge.fetchEVMBlockNumber(r.destination);return i.error?k.Err(i.error):k.Ok({source:n.val,destination:i.val})}}var Qe=typeof globalThis<"u"?globalThis:typeof window<"u"?window:typeof global<"u"?global:typeof self<"u"?self:{};function Ga(e){if(e.__esModule)return e;var t=e.default;if(typeof t=="function"){var r=function n(){return this instanceof n?Reflect.construct(t,arguments,this.constructor):t.apply(this,arguments)};r.prototype=t.prototype}else r={};return Object.defineProperty(r,"__esModule",{value:!0}),Object.keys(e).forEach(function(n){var i=Object.getOwnPropertyDescriptor(e,n);Object.defineProperty(r,n,i.get?i:{enumerable:!0,get:function(){return e[n]}})}),r}var Wi={},vt={},Et={};Object.defineProperty(Et,"__esModule",{value:!0});Et.testnet=Et.bitcoin=void 0;Et.bitcoin={messagePrefix:`Bitcoin Signed Message:
|
|
23
|
+
`.trim().replace(/\s+/g," "))}leaves(){return[{version:tr,output:this.redeemLeaf()},[{version:tr,output:this.refundLeaf()},{version:tr,output:this.instantRefundLeaf()}]]}generateMerkleProofFor(t){const r=this.leafHash(1),n=this.leafHash(2),i=this.leafHash(0);switch(t){case 1:{const a=Pa(i,n);return[ye.crypto.taggedHash("TapBranch",Buffer.concat(a))]}case 0:return[n,r];case 2:return[i,r];default:throw new Error(we.invalidLeaf)}}}function Or(e,t){const r=[];for(let n=0;n<t;n++)r.push(e);return r}class za{constructor(){this.cache={}}set(t,r,n,i){const a={txHash:n,timeStamp:Date.now(),btcRedeemUTXO:i};this.cache[`${r}_${t.create_order.create_id}`]=a}get(t,r){return this.cache[`${r}_${t.create_order.create_id}`]||null}remove(t,r){delete this.cache[`${r}_${t.create_order.create_id}`]}}class qi{constructor(t,r){this.url=new ge.Url("/blocknumber/"+r,t)}async fetchBlockNumbers(){console.log("this.url :",this.url.toString());try{const t=await k.Fetcher.get(this.url);return k.Ok(t)}catch(t){return k.Err("Failed to fetch block numbers",t)}}}class ja{constructor(t){if(this.eventListeners=new Map,this.getOrderThreshold=20,this.pendingOrdersCount=0,this.useRelay=!0,this.orderBook=new J.Orderbook({url:t.orderbookURl,walletClient:t.wallets.evmWallet,auth:t.auth}),this.quote=t.quote,this.secretManager=t.secretManager,this.wallets=t.wallets,this.orderbookUrl=t.orderbookURl,this.auth=t.auth,this.orderExecutorCache=new za,!t.wallets.evmWallet.account)throw new Error("Account not found in evmWallet");this.evmAddress=t.wallets.evmWallet.account.address,this.blockNumberFetcher=t.blockNumberFetcher&&new qi(t.blockNumberFetcher.url,t.blockNumberFetcher.network)}getPendingOrderCount(){return this.pendingOrdersCount}setUseRelay(t){this.useRelay=t}async swap(t){const r=await this.validateAndFillParams(t);if(r.error)return k.Err(r.error);const{sendAddress:n,receiveAddress:i,timelock:a}=r.val,f=await this.orderBook.getOrdersCount(this.evmAddress);if(f.error)return k.Err(f.error);const u=f.val+1,l=this.secretManager.generateSecret(u);if(l.error)return k.Err(l.error);const{strategyId:y,btcAddress:g}=t.additionalData,m={strategy_id:y,...g&&{bitcoin_optional_recipient:g}},E={source_chain:t.fromAsset.chain,destination_chain:t.toAsset.chain,source_asset:t.fromAsset.atomicSwapAddress,destination_asset:t.toAsset.atomicSwapAddress,initiator_source_address:n,initiator_destination_address:i,source_amount:t.sendAmount,destination_amount:t.receiveAmount,fee:"1",nonce:u.toString(),timelock:a,secret_hash:k.trim0x(l.val.secretHash),min_destination_confirmations:t.minDestinationConfirmations??0,additional_data:m},I=await this.quote.getAttestedQuote(E);if(I.error)return k.Err(I.error);const v=await this.orderBook.createOrder(I.val);if(v.error)return k.Err(v.error);const P=await this.pollOrder(v.val);return P.error?k.Err(P.error):k.Ok(P.val)}async validateAndFillParams(t){if(t.fromAsset.chain===t.toAsset.chain&&t.fromAsset.atomicSwapAddress===t.toAsset.atomicSwapAddress)return k.Err("Source and destination assets cannot be the same");if(J.isMainnet(t.fromAsset.chain)&&!J.isMainnet(t.toAsset.chain)||!J.isMainnet(t.fromAsset.chain)&&J.isMainnet(t.toAsset.chain))return k.Err("Both assets should be on the same network (either mainnet or testnet)");if(J.isBitcoin(t.fromAsset.chain)||J.isBitcoin(t.toAsset.chain)){if(!this.wallets.btcWallet)return k.Err("btcWallet is required for bitcoin chain. Please provide btcWallet in the constructor");if(!t.additionalData.btcAddress)return k.Err("btcAddress in additionalData is required for bitcoin chain")}const r=await this.getAddresses(t.fromAsset.chain);if(r.error)return k.Err(r.error);const n=await this.getAddresses(t.toAsset.chain);if(n.error)return k.Err(n.error);const i=this.validateAmount(t.sendAmount);if(i.error)return k.Err(i.error);const a=this.validateAmount(t.receiveAmount);if(a.error)return k.Err(a.error);if(i<a)return k.Err("Send amount should be greater than receive amount");const f=this.getTimelock(t.fromAsset.chain);return f?k.Ok({sendAddress:r.val,receiveAddress:n.val,timelock:t.timelock??f}):k.Err("Unsupported chain for timelock")}async getAddresses(t){var n;switch(J.getBlockchainType(t)){case J.BlockchainType.EVM:return this.wallets.evmWallet.account?k.Ok(this.wallets.evmWallet.account.address):k.Err("EVM Wallet not found");case J.BlockchainType.Bitcoin:{const i=await((n=this.wallets.btcWallet)==null?void 0:n.getPublicKey());return!i||!Ca(i)?k.Err("Invalid btc public key"):k.Ok(Ot(i))}default:return k.Err("Unsupported chain")}}validateAmount(t){if(t==null||t.includes("."))return k.Err("Invalid amount ",t);const r=new Ds(t);return!r.isInteger()||r.isNaN()||r.lt(0)||r.isLessThanOrEqualTo(0)?k.Err("Invalid amount ",t):k.Ok(r)}getTimelock(t){switch(J.getBlockchainType(t)){case J.BlockchainType.EVM:return sr.evm;case J.BlockchainType.Bitcoin:return sr.btc;default:return}}async pollOrder(t){let r=await this.orderBook.getOrder(t,!0),n=0;for(;n<this.getOrderThreshold;){if(await ge.sleep(1e3),n++,r.error){if(!r.error.includes("result is undefined"))return k.Err(r.error)}else if(r.val&&r.val.create_order.create_id.toLowerCase()===t.toLowerCase())return k.Ok(r.val);r=await this.orderBook.getOrder(t,!0)}return k.Err(`Order not found, createOrder id: ${t}`)}emit(t,...r){(this.eventListeners.get(t)??[]).forEach(i=>{i(...r)})}async execute(t=5e3){return await this.orderBook.subscribeToOrders(!0,t,async r=>{var i;this.pendingOrdersCount=r.data.length,this.emit("onPendingOrdersChanged",r.data);const n=await((i=this.blockNumberFetcher)==null?void 0:i.fetchBlockNumbers());for(let a=0;a<r.data.length;a++){const f=r.data[a],u=f.source_swap.chain,l=f.destination_swap.chain,y=this.getWallet(u),g=this.getWallet(l);if(y.error||g.error||!y.val||!g.val){this.emit("error",f,"Source or Destination Wallet not found while executing order");return}let m=n==null?void 0:n.val[u],E=n==null?void 0:n.val[l];if(console.log("orderId: ",f.create_order.create_id),n&&console.log("blockNumbers :",n.val),console.log("sourceChainBlockNumber :",u,m),console.log("destinationChainBlockNumber :",l,E),!m||!E){const v=await this.fetchCurrentBlockNumbers(f,{source:y.val,destination:g.val});if(v.error){this.emit("error",f,"Error while fetching CurrentBlockNumbers: "+v.error);return}m=v.val.source,E=v.val.destination}switch(ji(f,m,E)){case ce.Redeem:{const v=this.secretManager.generateSecret(Number(f.create_order.nonce));if(v.error){this.emit("error",f,v.error);return}switch(J.getBlockchainType(f.destination_swap.chain)){case J.BlockchainType.EVM:{await this.evmRedeem(f,v.val.secret);break}case J.BlockchainType.Bitcoin:{await this.btcRedeem(g.val,f,v.val.secret);break}default:this.emit("error",f,"Unsupported chain: "+f.destination_swap.chain)}break}case ce.Refund:{switch(J.getBlockchainType(f.source_swap.chain)){case J.BlockchainType.EVM:{this.emit("error",f,"EVM refund is automatically done by relay service");break}case J.BlockchainType.Bitcoin:{await this.btcRefund(y.val,f);break}default:this.emit("error",f,"Unsupported chain: "+f.source_swap.chain)}break}}}},{per_page:500},!0)}async evmRedeem(t,r){if(this.emit("log",t.create_order.create_id,"executing evm redeem"),this.orderExecutorCache.get(t,ce.Redeem)){this.emit("log",t.create_order.create_id,"already redeemed");return}const a=await new Gi(t,this.orderbookUrl,this.auth).redeem(t.create_order.create_id,r);if(a.error){this.emit("error",t,a.error);return}this.emit("success",t,ce.Redeem,a.val),this.orderExecutorCache.set(t,ce.Redeem,a.val)}async btcRedeem(t,r,n){var f;const i=this.orderExecutorCache.get(r,ce.Redeem);let a=!1;if(i)if(i.btcRedeemUTXO&&i.btcRedeemUTXO!==r.destination_swap.initiate_tx_hash)a=!0,this.emit("log",r.create_order.create_id,"rbf btc redeem");else{this.emit("log",r.create_order.create_id,"btcRedeem: already redeemed");return}this.emit("log",r.create_order.create_id,"executing btc redeem");try{const l=await(await cr.from(t,Number(r.destination_swap.amount),r.create_order.secret_hash,Ot(r.destination_swap.initiator),Ot(r.destination_swap.redeemer),r.destination_swap.timelock,a?[r.destination_swap.initiate_tx_hash]:[])).redeem(k.trim0x(n),(f=r.create_order.additional_data)==null?void 0:f.bitcoin_optional_recipient);this.emit("success",r,ce.Redeem,l),this.orderExecutorCache.set(r,ce.Redeem,l,r.destination_swap.initiate_tx_hash)}catch(u){this.emit("error",r,"Failed btc redeem: "+u)}}async btcRefund(t,r){var n;if(!this.orderExecutorCache.get(r,ce.Refund)){this.emit("log",r.create_order.create_id,"executing btc refund");try{const a=await(await cr.from(t,Number(r.source_swap.amount),r.create_order.secret_hash,Ot(r.source_swap.initiator),Ot(r.source_swap.redeemer),r.source_swap.timelock)).refund((n=r.create_order.additional_data)==null?void 0:n.bitcoin_optional_recipient);this.emit("success",r,ce.Refund,a),this.orderExecutorCache.set(r,ce.Refund,a)}catch(i){this.emit("error",r,"Failed btc refund: "+i)}}}getWallet(t){switch(J.getBlockchainType(t)){case J.BlockchainType.EVM:return k.Ok(this.wallets.evmWallet);case J.BlockchainType.Bitcoin:return k.Ok(this.wallets.btcWallet);default:return k.Err("Unsupported chain for wallet")}}on(t,r){const n=this.eventListeners.get(t)??[];n.push(r),this.eventListeners.set(t,n)}off(t,r){const n=this.eventListeners.get(t)??[],i=n.indexOf(r);i!==-1&&n.splice(i,1)}async fetchCurrentBlockNumbers(t,r){if(!r||!r.source||!r.destination)return k.Err("Provide wallets to fetch the current block number");const n=J.isBitcoin(t.source_swap.chain)?await ge.fetchBitcoinBlockNumber(await r.source.getProvider()):await ge.fetchEVMBlockNumber(r.source);if(n.error)return k.Err(n.error);const i=J.isBitcoin(t.destination_swap.chain)?await ge.fetchBitcoinBlockNumber(await r.destination.getProvider()):await ge.fetchEVMBlockNumber(r.destination);return i.error?k.Err(i.error):k.Ok({source:n.val,destination:i.val})}}var Qe=typeof globalThis<"u"?globalThis:typeof window<"u"?window:typeof global<"u"?global:typeof self<"u"?self:{};function Ga(e){if(e.__esModule)return e;var t=e.default;if(typeof t=="function"){var r=function n(){return this instanceof n?Reflect.construct(t,arguments,this.constructor):t.apply(this,arguments)};r.prototype=t.prototype}else r={};return Object.defineProperty(r,"__esModule",{value:!0}),Object.keys(e).forEach(function(n){var i=Object.getOwnPropertyDescriptor(e,n);Object.defineProperty(r,n,i.get?i:{enumerable:!0,get:function(){return e[n]}})}),r}var Wi={},vt={},Et={};Object.defineProperty(Et,"__esModule",{value:!0});Et.testnet=Et.bitcoin=void 0;Et.bitcoin={messagePrefix:`Bitcoin Signed Message:
|
|
24
24
|
`,bech32:"bc",bip32:{public:76067358,private:76066276},pubKeyHash:0,scriptHash:5,wif:128};Et.testnet={messagePrefix:`Bitcoin Signed Message:
|
|
25
25
|
`,bech32:"tb",bip32:{public:70617039,private:70615956},pubKeyHash:111,scriptHash:196,wif:239};var Vi={},zt={Array:function(e){return e!=null&&e.constructor===Array},Boolean:function(e){return typeof e=="boolean"},Function:function(e){return typeof e=="function"},Nil:function(e){return e==null},Number:function(e){return typeof e=="number"},Object:function(e){return typeof e=="object"},String:function(e){return typeof e=="string"},"":function(){return!0}};zt.Null=zt.Nil;for(var Dn in zt)zt[Dn].toJSON=(function(e){return e}).bind(null,Dn);var yn=zt,it=yn;function Ki(e){return e.name||e.toString().match(/function (.*?)\s*\(/)[1]}function gn(e){return it.Nil(e)?"":Ki(e.constructor)}function qa(e){return it.Function(e)?"":it.String(e)?JSON.stringify(e):e&&it.Object(e)?"":e}function mn(e,t){Error.captureStackTrace&&Error.captureStackTrace(e,t)}function lr(e){return it.Function(e)?e.toJSON?e.toJSON():Ki(e):it.Array(e)?"Array":e&&it.Object(e)?"Object":e!==void 0?e:""}function Yi(e,t,r){var n=qa(t);return"Expected "+lr(e)+", got"+(r!==""?" "+r:"")+(n!==""?" "+n:"")}function ze(e,t,r){r=r||gn(t),this.message=Yi(e,t,r),mn(this,ze),this.__type=e,this.__value=t,this.__valueTypeName=r}ze.prototype=Object.create(Error.prototype);ze.prototype.constructor=ze;function Wa(e,t,r,n,i){var a='" of type ';return t==="key"&&(a='" with key type '),Yi('property "'+lr(r)+a+lr(e),n,i)}function mt(e,t,r,n,i){e?(i=i||gn(n),this.message=Wa(e,r,t,n,i)):this.message='Unexpected property "'+t+'"',mn(this,ze),this.__label=r,this.__property=t,this.__type=e,this.__value=n,this.__valueTypeName=i}mt.prototype=Object.create(Error.prototype);mt.prototype.constructor=ze;function Va(e,t){return new ze(e,{},t)}function Ka(e,t,r){return e instanceof mt?(t=t+"."+e.__property,e=new mt(e.__type,t,e.__label,e.__value,e.__valueTypeName)):e instanceof ze&&(e=new mt(e.__type,t,r,e.__value,e.__valueTypeName)),mn(e),e}var Ji={TfTypeError:ze,TfPropertyTypeError:mt,tfCustomError:Va,tfSubError:Ka,tfJSON:lr,getValueTypeName:gn},Fr,$n;function Ya(){if($n)return Fr;$n=1;var e=yn,t=Ji;function r(S){return Buffer.isBuffer(S)}function n(S){return typeof S=="string"&&/^([0-9a-f]{2})+$/i.test(S)}function i(S,z){var M=S.toJSON();function $(oe){if(!S(oe))return!1;if(oe.length===z)return!0;throw t.tfCustomError(M+"(Length: "+z+")",M+"(Length: "+oe.length+")")}return $.toJSON=function(){return M},$}var a=i.bind(null,e.Array),f=i.bind(null,r),u=i.bind(null,n),l=i.bind(null,e.String);function y(S,z,M){M=M||e.Number;function $(oe,ke){return M(oe,ke)&&oe>S&&oe<z}return $.toJSON=function(){return`${M.toJSON()} between [${S}, ${z}]`},$}var g=Math.pow(2,53)-1;function m(S){return typeof S=="number"&&isFinite(S)}function E(S){return S<<24>>24===S}function I(S){return S<<16>>16===S}function v(S){return(S|0)===S}function P(S){return typeof S=="number"&&S>=-g&&S<=g&&Math.floor(S)===S}function T(S){return(S&255)===S}function C(S){return(S&65535)===S}function F(S){return S>>>0===S}function O(S){return typeof S=="number"&&S>=0&&S<=g&&Math.floor(S)===S}var L={ArrayN:a,Buffer:r,BufferN:f,Finite:m,Hex:n,HexN:u,Int8:E,Int16:I,Int32:v,Int53:P,Range:y,StringN:l,UInt8:T,UInt16:C,UInt32:F,UInt53:O};for(var U in L)L[U].toJSON=(function(S){return S}).bind(null,U);return Fr=L,Fr}var Kt=Ji,le=yn,De=Kt.tfJSON,Xi=Kt.TfTypeError,Qi=Kt.TfPropertyTypeError,Ft=Kt.tfSubError,Ja=Kt.getValueTypeName,$e={arrayOf:function(t,r){t=Fe(t),r=r||{};function n(i,a){return!le.Array(i)||le.Nil(i)||r.minLength!==void 0&&i.length<r.minLength||r.maxLength!==void 0&&i.length>r.maxLength||r.length!==void 0&&i.length!==r.length?!1:i.every(function(f,u){try{return xe(t,f,a)}catch(l){throw Ft(l,u)}})}return n.toJSON=function(){var i="["+De(t)+"]";return r.length!==void 0?i+="{"+r.length+"}":(r.minLength!==void 0||r.maxLength!==void 0)&&(i+="{"+(r.minLength===void 0?0:r.minLength)+","+(r.maxLength===void 0?1/0:r.maxLength)+"}"),i},n},maybe:function e(t){t=Fe(t);function r(n,i){return le.Nil(n)||t(n,i,e)}return r.toJSON=function(){return"?"+De(t)},r},map:function(t,r){t=Fe(t),r&&(r=Fe(r));function n(i,a){if(!le.Object(i)||le.Nil(i))return!1;for(var f in i){try{r&&xe(r,f,a)}catch(l){throw Ft(l,f,"key")}try{var u=i[f];xe(t,u,a)}catch(l){throw Ft(l,f)}}return!0}return r?n.toJSON=function(){return"{"+De(r)+": "+De(t)+"}"}:n.toJSON=function(){return"{"+De(t)+"}"},n},object:function(t){var r={};for(var n in t)r[n]=Fe(t[n]);function i(a,f){if(!le.Object(a)||le.Nil(a))return!1;var u;try{for(u in r){var l=r[u],y=a[u];xe(l,y,f)}}catch(g){throw Ft(g,u)}if(f){for(u in a)if(!r[u])throw new Qi(void 0,u)}return!0}return i.toJSON=function(){return De(r)},i},anyOf:function(){var t=[].slice.call(arguments).map(Fe);function r(n,i){return t.some(function(a){try{return xe(a,n,i)}catch{return!1}})}return r.toJSON=function(){return t.map(De).join("|")},r},allOf:function(){var t=[].slice.call(arguments).map(Fe);function r(n,i){return t.every(function(a){try{return xe(a,n,i)}catch{return!1}})}return r.toJSON=function(){return t.map(De).join(" & ")},r},quacksLike:function(t){function r(n){return t===Ja(n)}return r.toJSON=function(){return t},r},tuple:function(){var t=[].slice.call(arguments).map(Fe);function r(n,i){return le.Nil(n)||le.Nil(n.length)||i&&n.length!==t.length?!1:t.every(function(a,f){try{return xe(a,n[f],i)}catch(u){throw Ft(u,f)}})}return r.toJSON=function(){return"("+t.map(De).join(", ")+")"},r},value:function(t){function r(n){return n===t}return r.toJSON=function(){return t},r}};$e.oneOf=$e.anyOf;function Fe(e){if(le.String(e))return e[0]==="?"?$e.maybe(e.slice(1)):le[e]||$e.quacksLike(e);if(e&&le.Object(e)){if(le.Array(e)){if(e.length!==1)throw new TypeError("Expected compile() parameter of type Array of length 1");return $e.arrayOf(e[0])}return $e.object(e)}else if(le.Function(e))return e;return $e.value(e)}function xe(e,t,r,n){if(le.Function(e)){if(e(t,r))return!0;throw new Xi(n||e,t)}return xe(Fe(e),t,r)}for(var Xe in le)xe[Xe]=le[Xe];for(Xe in $e)xe[Xe]=$e[Xe];var Hn=Ya();for(Xe in Hn)xe[Xe]=Hn[Xe];xe.compile=Fe;xe.TfTypeError=Xi;xe.TfPropertyTypeError=Qi;var Xa=xe;(function(e){Object.defineProperty(e,"__esModule",{value:!0}),e.maybe=e.Boolean=e.Array=e.Buffer256bit=e.Network=e.typeforce=void 0,e.typeforce=Xa,e.Network=e.typeforce.compile({messagePrefix:e.typeforce.oneOf(e.typeforce.Buffer,e.typeforce.String),bip32:{public:e.typeforce.UInt32,private:e.typeforce.UInt32},pubKeyHash:e.typeforce.UInt8,scriptHash:e.typeforce.UInt8,wif:e.typeforce.UInt8}),e.Buffer256bit=e.typeforce.BufferN(32),e.Array=e.typeforce.Array,e.Boolean=e.typeforce.Boolean,e.maybe=e.typeforce.maybe})(Vi);var Qr={exports:{}},Zr={exports:{}},At={},wr={};wr.byteLength=ef;wr.toByteArray=rf;wr.fromByteArray=of;var Ue=[],Re=[],Qa=typeof Uint8Array<"u"?Uint8Array:Array,Ur="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/";for(var yt=0,Za=Ur.length;yt<Za;++yt)Ue[yt]=Ur[yt],Re[Ur.charCodeAt(yt)]=yt;Re[45]=62;Re[95]=63;function Zi(e){var t=e.length;if(t%4>0)throw new Error("Invalid string. Length must be a multiple of 4");var r=e.indexOf("=");r===-1&&(r=t);var n=r===t?0:4-r%4;return[r,n]}function ef(e){var t=Zi(e),r=t[0],n=t[1];return(r+n)*3/4-n}function tf(e,t,r){return(t+r)*3/4-r}function rf(e){var t,r=Zi(e),n=r[0],i=r[1],a=new Qa(tf(e,n,i)),f=0,u=i>0?n-4:n,l;for(l=0;l<u;l+=4)t=Re[e.charCodeAt(l)]<<18|Re[e.charCodeAt(l+1)]<<12|Re[e.charCodeAt(l+2)]<<6|Re[e.charCodeAt(l+3)],a[f++]=t>>16&255,a[f++]=t>>8&255,a[f++]=t&255;return i===2&&(t=Re[e.charCodeAt(l)]<<2|Re[e.charCodeAt(l+1)]>>4,a[f++]=t&255),i===1&&(t=Re[e.charCodeAt(l)]<<10|Re[e.charCodeAt(l+1)]<<4|Re[e.charCodeAt(l+2)]>>2,a[f++]=t>>8&255,a[f++]=t&255),a}function nf(e){return Ue[e>>18&63]+Ue[e>>12&63]+Ue[e>>6&63]+Ue[e&63]}function sf(e,t,r){for(var n,i=[],a=t;a<r;a+=3)n=(e[a]<<16&16711680)+(e[a+1]<<8&65280)+(e[a+2]&255),i.push(nf(n));return i.join("")}function of(e){for(var t,r=e.length,n=r%3,i=[],a=16383,f=0,u=r-n;f<u;f+=a)i.push(sf(e,f,f+a>u?u:f+a));return n===1?(t=e[r-1],i.push(Ue[t>>2]+Ue[t<<4&63]+"==")):n===2&&(t=(e[r-2]<<8)+e[r-1],i.push(Ue[t>>10]+Ue[t>>4&63]+Ue[t<<2&63]+"=")),i.join("")}var wn={};/*! ieee754. BSD-3-Clause License. Feross Aboukhadijeh <https://feross.org/opensource> */wn.read=function(e,t,r,n,i){var a,f,u=i*8-n-1,l=(1<<u)-1,y=l>>1,g=-7,m=r?i-1:0,E=r?-1:1,I=e[t+m];for(m+=E,a=I&(1<<-g)-1,I>>=-g,g+=u;g>0;a=a*256+e[t+m],m+=E,g-=8);for(f=a&(1<<-g)-1,a>>=-g,g+=n;g>0;f=f*256+e[t+m],m+=E,g-=8);if(a===0)a=1-y;else{if(a===l)return f?NaN:(I?-1:1)*(1/0);f=f+Math.pow(2,n),a=a-y}return(I?-1:1)*f*Math.pow(2,a-n)};wn.write=function(e,t,r,n,i,a){var f,u,l,y=a*8-i-1,g=(1<<y)-1,m=g>>1,E=i===23?Math.pow(2,-24)-Math.pow(2,-77):0,I=n?0:a-1,v=n?1:-1,P=t<0||t===0&&1/t<0?1:0;for(t=Math.abs(t),isNaN(t)||t===1/0?(u=isNaN(t)?1:0,f=g):(f=Math.floor(Math.log(t)/Math.LN2),t*(l=Math.pow(2,-f))<1&&(f--,l*=2),f+m>=1?t+=E/l:t+=E*Math.pow(2,1-m),t*l>=2&&(f++,l/=2),f+m>=g?(u=0,f=g):f+m>=1?(u=(t*l-1)*Math.pow(2,i),f=f+m):(u=t*Math.pow(2,m-1)*Math.pow(2,i),f=0));i>=8;e[r+I]=u&255,I+=v,u/=256,i-=8);for(f=f<<i|u,y+=i;y>0;e[r+I]=f&255,I+=v,f/=256,y-=8);e[r+I-v]|=P*128};/*!
|
|
26
26
|
* The buffer module from node.js, for the browser.
|
package/dist/index.js
CHANGED
|
@@ -2851,7 +2851,6 @@ class ll {
|
|
|
2851
2851
|
var i;
|
|
2852
2852
|
this.pendingOrdersCount = r.data.length, this.emit("onPendingOrdersChanged", r.data);
|
|
2853
2853
|
const n = await ((i = this.blockNumberFetcher) == null ? void 0 : i.fetchBlockNumbers());
|
|
2854
|
-
n && console.log("blockNumbers :", n.val);
|
|
2855
2854
|
for (let a = 0; a < r.data.length; a++) {
|
|
2856
2855
|
const f = r.data[a], u = f.source_swap.chain, l = f.destination_swap.chain, y = this.getWallet(u), g = this.getWallet(l);
|
|
2857
2856
|
if (y.error || g.error || !y.val || !g.val) {
|
|
@@ -2863,8 +2862,13 @@ class ll {
|
|
|
2863
2862
|
return;
|
|
2864
2863
|
}
|
|
2865
2864
|
let m = n == null ? void 0 : n.val[u], E = n == null ? void 0 : n.val[l];
|
|
2866
|
-
if (console.log("
|
|
2865
|
+
if (console.log("orderId: ", f.create_order.create_id), n && console.log("blockNumbers :", n.val), console.log(
|
|
2866
|
+
"sourceChainBlockNumber :",
|
|
2867
|
+
u,
|
|
2868
|
+
m
|
|
2869
|
+
), console.log(
|
|
2867
2870
|
"destinationChainBlockNumber :",
|
|
2871
|
+
l,
|
|
2868
2872
|
E
|
|
2869
2873
|
), !m || !E) {
|
|
2870
2874
|
const v = await this.fetchCurrentBlockNumbers(f, {
|