@gardenfi/core 0.2.0-beta.21 → 0.2.0-beta.22
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 +3 -11
- package/package.json +1 -1
package/dist/index.cjs
CHANGED
|
@@ -17,7 +17,7 @@
|
|
|
17
17
|
OP_CHECKSIGADD
|
|
18
18
|
OP_2
|
|
19
19
|
OP_NUMEQUAL
|
|
20
|
-
`.trim().replace(/\s+/g," "))}leaves(){return[{version:Ot,output:this.redeemLeaf()},[{version:Ot,output:this.refundLeaf()},{version:Ot,output:this.instantRefundLeaf()}]]}generateMerkleProofFor(t){const r=this.leafHash(1),a=this.leafHash(2),o=this.leafHash(0);switch(t){case 1:{const f=mi(o,a);return[de.crypto.taggedHash("TapBranch",Buffer.concat(f))]}case 0:return[a,r];case 2:return[o,r];default:throw new Error(ye.invalidLeaf)}}}function rr(e,t){const r=[];for(let a=0;a<t;a++)r.push(e);return r}class Ci{constructor(t,r){this.order=t,this.store=r}getOrder(){return this.order}set(t,r){const a={txHash:r,timeStamp:Date.now()};this.store.setItem(`${t}_${this.order.create_order.create_id}`,JSON.stringify(a))}get(t){const r=this.store.getItem(`${t}_${this.order.create_order.create_id}`);if(!r)return null;const a=JSON.parse(r);return!a.timeStamp||!a.txHash?null:a}remove(t){this.store.removeItem(`${t}_${this.order.create_order.create_id}`)}}class Oi{constructor(t){if(this.eventListeners=new Map,this.getOrderThreshold=20,this.pendingOrdersCount=0,this.useRelay=!0,this.orderBook=new ee.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.store=new pe.MemoryStorage,!t.wallets.evmWallet.account)throw new Error("Account not found in evmWallet");this.evmAddress=t.wallets.evmWallet.account.address}getPendingOrderCount(){return this.pendingOrdersCount}setUseRelay(t){this.useRelay=t}async swap(t){const r=await this.validateAndFillParams(t);if(r.error)return L.Err(r.error);const{sendAddress:a,receiveAddress:o,timelock:f}=r.val,c=await this.orderBook.getOrdersCount(this.evmAddress);if(c.error)return L.Err(c.error);const u=c.val+1,p=this.secretManager.generateSecret(u);if(p.error)return L.Err(p.error);const{strategyId:w,btcAddress:m}=t.additionalData,v={strategy_id:w,...m&&{bitcoin_optional_recipient:m}},A={source_chain:t.fromAsset.chain,destination_chain:t.toAsset.chain,source_asset:t.fromAsset.atomicSwapAddress,destination_asset:t.toAsset.atomicSwapAddress,initiator_source_address:a,initiator_destination_address:o,source_amount:t.sendAmount,destination_amount:t.receiveAmount,fee:"1",nonce:u.toString(),timelock:f,secret_hash:L.trim0x(p.val.secretHash),min_destination_confirmations:t.minDestinationConfirmations??0,additional_data:v},k=await this.quote.getAttestedQuote(A);if(k.error)return L.Err(k.error);const R=await this.orderBook.createOrder(k.val);if(R.error)return L.Err(R.error);const C=await this.pollOrder(R.val);return C.error?L.Err(C.error):L.Ok(C.val)}async validateAndFillParams(t){if(t.fromAsset.chain===t.toAsset.chain&&t.fromAsset.atomicSwapAddress===t.toAsset.atomicSwapAddress)return L.Err("Source and destination assets cannot be the same");if(ee.isMainnet(t.fromAsset.chain)&&!ee.isMainnet(t.toAsset.chain)||!ee.isMainnet(t.fromAsset.chain)&&ee.isMainnet(t.toAsset.chain))return L.Err("Both assets should be on the same network (either mainnet or testnet)");if(ee.isBitcoin(t.fromAsset.chain)||ee.isBitcoin(t.toAsset.chain)){if(!this.wallets.btcWallet)return L.Err("btcWallet is required for bitcoin chain. Please provide btcWallet in the constructor");if(!t.additionalData.btcAddress)return L.Err("btcAddress in additionalData is required for bitcoin chain")}const r=await this.getAddresses(t.fromAsset.chain);if(r.error)return L.Err(r.error);const a=await this.getAddresses(t.toAsset.chain);if(a.error)return L.Err(a.error);const o=this.validateAmount(t.sendAmount);if(o.error)return L.Err(o.error);const f=this.validateAmount(t.receiveAmount);if(f.error)return L.Err(f.error);if(o<f)return L.Err("Send amount should be greater than receive amount");const c=this.getTimelock(t.fromAsset.chain);return c?L.Ok({sendAddress:r.val,receiveAddress:a.val,timelock:t.timelock??c}):L.Err("Unsupported chain for timelock")}async getAddresses(t){var a;switch(ee.getBlockchainType(t)){case ee.BlockchainType.EVM:return this.wallets.evmWallet.account?L.Ok(this.wallets.evmWallet.account.address):L.Err("EVM Wallet not found");case ee.BlockchainType.Bitcoin:{const o=await((a=this.wallets.btcWallet)==null?void 0:a.getPublicKey());return!o||!vi(o)?L.Err("Invalid btc public key"):L.Ok(yt(o))}default:return L.Err("Unsupported chain")}}validateAmount(t){const r=BigInt(t);return t==null||r<=0n||t.includes(".")?L.Err("Invalid amount ",t):L.Ok(r)}getTimelock(t){switch(ee.getBlockchainType(t)){case ee.BlockchainType.EVM:return gr.evm;case ee.BlockchainType.Bitcoin:return gr.btc;default:return}}async pollOrder(t){let r=await this.orderBook.getOrder(t,!0),a=0;for(;a<this.getOrderThreshold;){if(await pe.sleep(1e3),a++,r.error){if(!r.error.includes("result is undefined"))return L.Err(r.error)}else if(r.val&&r.val.create_order.create_id.toLowerCase()===t.toLowerCase())return L.Ok(r.val);r=await this.orderBook.getOrder(t,!0)}return L.Err(`Order not found, createOrder id: ${t}`)}emit(t,...r){(this.eventListeners.get(t)??[]).forEach(o=>{o(...r)})}async execute(t=5e3){return await this.orderBook.subscribeToOrders(!0,t,async r=>{var a,o;this.pendingOrdersCount=r.data.length,this.emit("onPendingOrdersChanged",r.data);for(let f=0;f<r.data.length;f++){const c=r.data[f]
|
|
20
|
+
`.trim().replace(/\s+/g," "))}leaves(){return[{version:Ot,output:this.redeemLeaf()},[{version:Ot,output:this.refundLeaf()},{version:Ot,output:this.instantRefundLeaf()}]]}generateMerkleProofFor(t){const r=this.leafHash(1),a=this.leafHash(2),o=this.leafHash(0);switch(t){case 1:{const f=mi(o,a);return[de.crypto.taggedHash("TapBranch",Buffer.concat(f))]}case 0:return[a,r];case 2:return[o,r];default:throw new Error(ye.invalidLeaf)}}}function rr(e,t){const r=[];for(let a=0;a<t;a++)r.push(e);return r}class Ci{constructor(t,r){this.order=t,this.store=r}getOrder(){return this.order}set(t,r){const a={txHash:r,timeStamp:Date.now()};this.store.setItem(`${t}_${this.order.create_order.create_id}`,JSON.stringify(a))}get(t){const r=this.store.getItem(`${t}_${this.order.create_order.create_id}`);if(!r)return null;const a=JSON.parse(r);return!a.timeStamp||!a.txHash?null:a}remove(t){this.store.removeItem(`${t}_${this.order.create_order.create_id}`)}}class Oi{constructor(t){if(this.eventListeners=new Map,this.getOrderThreshold=20,this.pendingOrdersCount=0,this.useRelay=!0,this.orderBook=new ee.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.store=new pe.MemoryStorage,!t.wallets.evmWallet.account)throw new Error("Account not found in evmWallet");this.evmAddress=t.wallets.evmWallet.account.address}getPendingOrderCount(){return this.pendingOrdersCount}setUseRelay(t){this.useRelay=t}async swap(t){const r=await this.validateAndFillParams(t);if(r.error)return L.Err(r.error);const{sendAddress:a,receiveAddress:o,timelock:f}=r.val,c=await this.orderBook.getOrdersCount(this.evmAddress);if(c.error)return L.Err(c.error);const u=c.val+1,p=this.secretManager.generateSecret(u);if(p.error)return L.Err(p.error);const{strategyId:w,btcAddress:m}=t.additionalData,v={strategy_id:w,...m&&{bitcoin_optional_recipient:m}},A={source_chain:t.fromAsset.chain,destination_chain:t.toAsset.chain,source_asset:t.fromAsset.atomicSwapAddress,destination_asset:t.toAsset.atomicSwapAddress,initiator_source_address:a,initiator_destination_address:o,source_amount:t.sendAmount,destination_amount:t.receiveAmount,fee:"1",nonce:u.toString(),timelock:f,secret_hash:L.trim0x(p.val.secretHash),min_destination_confirmations:t.minDestinationConfirmations??0,additional_data:v},k=await this.quote.getAttestedQuote(A);if(k.error)return L.Err(k.error);const R=await this.orderBook.createOrder(k.val);if(R.error)return L.Err(R.error);const C=await this.pollOrder(R.val);return C.error?L.Err(C.error):L.Ok(C.val)}async validateAndFillParams(t){if(t.fromAsset.chain===t.toAsset.chain&&t.fromAsset.atomicSwapAddress===t.toAsset.atomicSwapAddress)return L.Err("Source and destination assets cannot be the same");if(ee.isMainnet(t.fromAsset.chain)&&!ee.isMainnet(t.toAsset.chain)||!ee.isMainnet(t.fromAsset.chain)&&ee.isMainnet(t.toAsset.chain))return L.Err("Both assets should be on the same network (either mainnet or testnet)");if(ee.isBitcoin(t.fromAsset.chain)||ee.isBitcoin(t.toAsset.chain)){if(!this.wallets.btcWallet)return L.Err("btcWallet is required for bitcoin chain. Please provide btcWallet in the constructor");if(!t.additionalData.btcAddress)return L.Err("btcAddress in additionalData is required for bitcoin chain")}const r=await this.getAddresses(t.fromAsset.chain);if(r.error)return L.Err(r.error);const a=await this.getAddresses(t.toAsset.chain);if(a.error)return L.Err(a.error);const o=this.validateAmount(t.sendAmount);if(o.error)return L.Err(o.error);const f=this.validateAmount(t.receiveAmount);if(f.error)return L.Err(f.error);if(o<f)return L.Err("Send amount should be greater than receive amount");const c=this.getTimelock(t.fromAsset.chain);return c?L.Ok({sendAddress:r.val,receiveAddress:a.val,timelock:t.timelock??c}):L.Err("Unsupported chain for timelock")}async getAddresses(t){var a;switch(ee.getBlockchainType(t)){case ee.BlockchainType.EVM:return this.wallets.evmWallet.account?L.Ok(this.wallets.evmWallet.account.address):L.Err("EVM Wallet not found");case ee.BlockchainType.Bitcoin:{const o=await((a=this.wallets.btcWallet)==null?void 0:a.getPublicKey());return!o||!vi(o)?L.Err("Invalid btc public key"):L.Ok(yt(o))}default:return L.Err("Unsupported chain")}}validateAmount(t){const r=BigInt(t);return t==null||r<=0n||t.includes(".")?L.Err("Invalid amount ",t):L.Ok(r)}getTimelock(t){switch(ee.getBlockchainType(t)){case ee.BlockchainType.EVM:return gr.evm;case ee.BlockchainType.Bitcoin:return gr.btc;default:return}}async pollOrder(t){let r=await this.orderBook.getOrder(t,!0),a=0;for(;a<this.getOrderThreshold;){if(await pe.sleep(1e3),a++,r.error){if(!r.error.includes("result is undefined"))return L.Err(r.error)}else if(r.val&&r.val.create_order.create_id.toLowerCase()===t.toLowerCase())return L.Ok(r.val);r=await this.orderBook.getOrder(t,!0)}return L.Err(`Order not found, createOrder id: ${t}`)}emit(t,...r){(this.eventListeners.get(t)??[]).forEach(o=>{o(...r)})}async execute(t=5e3){return await this.orderBook.subscribeToOrders(!0,t,async r=>{var a,o;this.pendingOrdersCount=r.data.length,this.emit("onPendingOrdersChanged",r.data);for(let f=0;f<r.data.length;f++){const c=r.data[f],u=c.source_swap.chain,p=c.destination_swap.chain,w=this.getWallet(u),m=this.getWallet(p);if(w.error||m.error||!w.val||!m.val){this.emit("error",c,"Source or Destination Wallet not found while executing order");return}const v=await this.fetchCurrentBlockNumbers(c,{source:w.val,destination:m.val});if(v.error){this.emit("error",c,"Error while fetching CurrentBlockNumbers: "+v.error);return}const A=wn(c,v.val.source,v.val.destination),k=new Ci(c,this.store);if(k.get(A))continue;switch(ee.getBlockchainType(c.destination_swap.chain)){case ee.BlockchainType.EVM:switch(A){case Se.Redeem:{console.log("executing evm redeem...");const S=new mn(c,this.orderbookUrl,this.auth),I=this.secretManager.generateSecret(Number(c.create_order.nonce));if(I.error){this.emit("error",c,I.error);return}const O=await S.redeem(c.create_order.create_id,I.val.secret);if(O.error){this.emit("error",c,O.error);return}this.emit("success",c,Se.Redeem,O.val),k.set(A,O.val);break}case Se.Refund:{this.emit("error",c,"EVM refund is automatically done by relay service");break}}break;case ee.BlockchainType.Bitcoin:switch(A){case Se.Redeem:{try{const S=await Nt.from(m.val,Number(c.destination_swap.amount),c.create_order.secret_hash,yt(c.destination_swap.initiator),yt(c.destination_swap.redeemer),c.destination_swap.timelock),I=this.secretManager.generateSecret(Number(c.create_order.nonce));if(I.error){this.emit("error",c,I.error);return}const O=await S.redeem(L.trim0x(I.val.secret),(a=c.create_order.additional_data)==null?void 0:a.bitcoin_optional_recipient);this.emit("success",c,Se.Redeem,O),k.set(A,O)}catch(S){this.emit("error",c,"Failed btc redeem: "+S)}break}case Se.Refund:{try{const I=await(await Nt.from(w.val,Number(c.source_swap.amount),c.create_order.secret_hash,yt(c.source_swap.initiator),yt(c.source_swap.redeemer),c.source_swap.timelock)).refund((o=c.create_order.additional_data)==null?void 0:o.bitcoin_optional_recipient);this.emit("success",c,Se.Refund,I),k.set(A,I)}catch(S){this.emit("error",c,"Failed btc refund: "+S)}break}}break;default:this.emit("error",c,"Unsupported chain: "+c.destination_swap.chain)}}},!0)}getWallet(t){switch(ee.getBlockchainType(t)){case ee.BlockchainType.EVM:return L.Ok(this.wallets.evmWallet);case ee.BlockchainType.Bitcoin:return L.Ok(this.wallets.btcWallet);default:return L.Err("Unsupported chain for wallet")}}on(t,r){const a=this.eventListeners.get(t)??[];a.push(r),this.eventListeners.set(t,a)}off(t,r){const a=this.eventListeners.get(t)??[],o=a.indexOf(r);o!==-1&&a.splice(o,1)}async fetchCurrentBlockNumbers(t,r){if(!r||!r.source||!r.destination)return L.Err("Provide wallets to fetch the current block number");const a=ee.isBitcoin(t.source_swap.chain)?await pe.fetchBitcoinBlockNumber(await r.source.getProvider()):await pe.fetchEVMBlockNumber(r.source);if(a.error)return L.Err(a.error);const o=ee.isBitcoin(t.destination_swap.chain)?await pe.fetchBitcoinBlockNumber(await r.destination.getProvider()):await pe.fetchEVMBlockNumber(r.destination);return o.error?L.Err(o.error):L.Ok({source:a.val,destination:o.val})}}var Ge=typeof globalThis<"u"?globalThis:typeof window<"u"?window:typeof global<"u"?global:typeof self<"u"?self:{};function Li(e){if(e.__esModule)return e;var t=e.default;if(typeof t=="function"){var r=function a(){return this instanceof a?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(a){var o=Object.getOwnPropertyDescriptor(e,a);Object.defineProperty(r,a,o.get?o:{enumerable:!0,get:function(){return e[a]}})}),r}var vn={},ut={},ct={};Object.defineProperty(ct,"__esModule",{value:!0});ct.testnet=ct.bitcoin=void 0;ct.bitcoin={messagePrefix:`Bitcoin Signed Message:
|
|
21
21
|
`,bech32:"bc",bip32:{public:76067358,private:76066276},pubKeyHash:0,scriptHash:5,wif:128};ct.testnet={messagePrefix:`Bitcoin Signed Message:
|
|
22
22
|
`,bech32:"tb",bip32:{public:70617039,private:70615956},pubKeyHash:111,scriptHash:196,wif:239};var xn={},Bt={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}};Bt.Null=Bt.Nil;for(var $r in Bt)Bt[$r].toJSON=(function(e){return e}).bind(null,$r);var Ir=Bt,Qe=Ir;function En(e){return e.name||e.toString().match(/function (.*?)\s*\(/)[1]}function kr(e){return Qe.Nil(e)?"":En(e.constructor)}function Mi(e){return Qe.Function(e)?"":Qe.String(e)?JSON.stringify(e):e&&Qe.Object(e)?"":e}function Cr(e,t){Error.captureStackTrace&&Error.captureStackTrace(e,t)}function Dt(e){return Qe.Function(e)?e.toJSON?e.toJSON():En(e):Qe.Array(e)?"Array":e&&Qe.Object(e)?"Object":e!==void 0?e:""}function Bn(e,t,r){var a=Mi(t);return"Expected "+Dt(e)+", got"+(r!==""?" "+r:"")+(a!==""?" "+a:"")}function De(e,t,r){r=r||kr(t),this.message=Bn(e,t,r),Cr(this,De),this.__type=e,this.__value=t,this.__valueTypeName=r}De.prototype=Object.create(Error.prototype);De.prototype.constructor=De;function Pi(e,t,r,a,o){var f='" of type ';return t==="key"&&(f='" with key type '),Bn('property "'+Dt(r)+f+Dt(e),a,o)}function ot(e,t,r,a,o){e?(o=o||kr(a),this.message=Pi(e,r,t,a,o)):this.message='Unexpected property "'+t+'"',Cr(this,De),this.__label=r,this.__property=t,this.__type=e,this.__value=a,this.__valueTypeName=o}ot.prototype=Object.create(Error.prototype);ot.prototype.constructor=De;function Fi(e,t){return new De(e,{},t)}function Ni(e,t,r){return e instanceof ot?(t=t+"."+e.__property,e=new ot(e.__type,t,e.__label,e.__value,e.__valueTypeName)):e instanceof De&&(e=new ot(e.__type,t,r,e.__value,e.__valueTypeName)),Cr(e),e}var Rn={TfTypeError:De,TfPropertyTypeError:ot,tfCustomError:Fi,tfSubError:Ni,tfJSON:Dt,getValueTypeName:kr},nr,Hr;function Di(){if(Hr)return nr;Hr=1;var e=Ir,t=Rn;function r(E){return Buffer.isBuffer(E)}function a(E){return typeof E=="string"&&/^([0-9a-f]{2})+$/i.test(E)}function o(E,j){var D=E.toJSON();function $(ne){if(!E(ne))return!1;if(ne.length===j)return!0;throw t.tfCustomError(D+"(Length: "+j+")",D+"(Length: "+ne.length+")")}return $.toJSON=function(){return D},$}var f=o.bind(null,e.Array),c=o.bind(null,r),u=o.bind(null,a),p=o.bind(null,e.String);function w(E,j,D){D=D||e.Number;function $(ne,Te){return D(ne,Te)&&ne>E&&ne<j}return $.toJSON=function(){return`${D.toJSON()} between [${E}, ${j}]`},$}var m=Math.pow(2,53)-1;function v(E){return typeof E=="number"&&isFinite(E)}function A(E){return E<<24>>24===E}function k(E){return E<<16>>16===E}function R(E){return(E|0)===E}function C(E){return typeof E=="number"&&E>=-m&&E<=m&&Math.floor(E)===E}function S(E){return(E&255)===E}function I(E){return(E&65535)===E}function O(E){return E>>>0===E}function P(E){return typeof E=="number"&&E>=0&&E<=m&&Math.floor(E)===E}var M={ArrayN:f,Buffer:r,BufferN:c,Finite:v,Hex:a,HexN:u,Int8:A,Int16:k,Int32:R,Int53:C,Range:w,StringN:p,UInt8:S,UInt16:I,UInt32:O,UInt53:P};for(var N in M)M[N].toJSON=(function(E){return E}).bind(null,N);return nr=M,nr}var St=Rn,fe=Ir,Pe=St.tfJSON,Sn=St.TfTypeError,An=St.TfPropertyTypeError,_t=St.tfSubError,Ui=St.getValueTypeName,Fe={arrayOf:function(t,r){t=Oe(t),r=r||{};function a(o,f){return!fe.Array(o)||fe.Nil(o)||r.minLength!==void 0&&o.length<r.minLength||r.maxLength!==void 0&&o.length>r.maxLength||r.length!==void 0&&o.length!==r.length?!1:o.every(function(c,u){try{return ge(t,c,f)}catch(p){throw _t(p,u)}})}return a.toJSON=function(){var o="["+Pe(t)+"]";return r.length!==void 0?o+="{"+r.length+"}":(r.minLength!==void 0||r.maxLength!==void 0)&&(o+="{"+(r.minLength===void 0?0:r.minLength)+","+(r.maxLength===void 0?1/0:r.maxLength)+"}"),o},a},maybe:function e(t){t=Oe(t);function r(a,o){return fe.Nil(a)||t(a,o,e)}return r.toJSON=function(){return"?"+Pe(t)},r},map:function(t,r){t=Oe(t),r&&(r=Oe(r));function a(o,f){if(!fe.Object(o)||fe.Nil(o))return!1;for(var c in o){try{r&&ge(r,c,f)}catch(p){throw _t(p,c,"key")}try{var u=o[c];ge(t,u,f)}catch(p){throw _t(p,c)}}return!0}return r?a.toJSON=function(){return"{"+Pe(r)+": "+Pe(t)+"}"}:a.toJSON=function(){return"{"+Pe(t)+"}"},a},object:function(t){var r={};for(var a in t)r[a]=Oe(t[a]);function o(f,c){if(!fe.Object(f)||fe.Nil(f))return!1;var u;try{for(u in r){var p=r[u],w=f[u];ge(p,w,c)}}catch(m){throw _t(m,u)}if(c){for(u in f)if(!r[u])throw new An(void 0,u)}return!0}return o.toJSON=function(){return Pe(r)},o},anyOf:function(){var t=[].slice.call(arguments).map(Oe);function r(a,o){return t.some(function(f){try{return ge(f,a,o)}catch{return!1}})}return r.toJSON=function(){return t.map(Pe).join("|")},r},allOf:function(){var t=[].slice.call(arguments).map(Oe);function r(a,o){return t.every(function(f){try{return ge(f,a,o)}catch{return!1}})}return r.toJSON=function(){return t.map(Pe).join(" & ")},r},quacksLike:function(t){function r(a){return t===Ui(a)}return r.toJSON=function(){return t},r},tuple:function(){var t=[].slice.call(arguments).map(Oe);function r(a,o){return fe.Nil(a)||fe.Nil(a.length)||o&&a.length!==t.length?!1:t.every(function(f,c){try{return ge(f,a[c],o)}catch(u){throw _t(u,c)}})}return r.toJSON=function(){return"("+t.map(Pe).join(", ")+")"},r},value:function(t){function r(a){return a===t}return r.toJSON=function(){return t},r}};Fe.oneOf=Fe.anyOf;function Oe(e){if(fe.String(e))return e[0]==="?"?Fe.maybe(e.slice(1)):fe[e]||Fe.quacksLike(e);if(e&&fe.Object(e)){if(fe.Array(e)){if(e.length!==1)throw new TypeError("Expected compile() parameter of type Array of length 1");return Fe.arrayOf(e[0])}return Fe.object(e)}else if(fe.Function(e))return e;return Fe.value(e)}function ge(e,t,r,a){if(fe.Function(e)){if(e(t,r))return!0;throw new Sn(a||e,t)}return ge(Oe(e),t,r)}for(var Ke in fe)ge[Ke]=fe[Ke];for(Ke in Fe)ge[Ke]=Fe[Ke];var jr=Di();for(Ke in jr)ge[Ke]=jr[Ke];ge.compile=Oe;ge.TfTypeError=Sn;ge.TfPropertyTypeError=An;var $i=ge;(function(e){Object.defineProperty(e,"__esModule",{value:!0}),e.maybe=e.Boolean=e.Array=e.Buffer256bit=e.Network=e.typeforce=void 0,e.typeforce=$i,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})(xn);var mr={exports:{}},vr={exports:{}},ht={},Wt={};Wt.byteLength=qi;Wt.toByteArray=Ki;Wt.fromByteArray=Ji;var Le=[],Re=[],Hi=typeof Uint8Array<"u"?Uint8Array:Array,ir="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/";for(var at=0,ji=ir.length;at<ji;++at)Le[at]=ir[at],Re[ir.charCodeAt(at)]=at;Re[45]=62;Re[95]=63;function Tn(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 a=r===t?0:4-r%4;return[r,a]}function qi(e){var t=Tn(e),r=t[0],a=t[1];return(r+a)*3/4-a}function Wi(e,t,r){return(t+r)*3/4-r}function Ki(e){var t,r=Tn(e),a=r[0],o=r[1],f=new Hi(Wi(e,a,o)),c=0,u=o>0?a-4:a,p;for(p=0;p<u;p+=4)t=Re[e.charCodeAt(p)]<<18|Re[e.charCodeAt(p+1)]<<12|Re[e.charCodeAt(p+2)]<<6|Re[e.charCodeAt(p+3)],f[c++]=t>>16&255,f[c++]=t>>8&255,f[c++]=t&255;return o===2&&(t=Re[e.charCodeAt(p)]<<2|Re[e.charCodeAt(p+1)]>>4,f[c++]=t&255),o===1&&(t=Re[e.charCodeAt(p)]<<10|Re[e.charCodeAt(p+1)]<<4|Re[e.charCodeAt(p+2)]>>2,f[c++]=t>>8&255,f[c++]=t&255),f}function Gi(e){return Le[e>>18&63]+Le[e>>12&63]+Le[e>>6&63]+Le[e&63]}function Vi(e,t,r){for(var a,o=[],f=t;f<r;f+=3)a=(e[f]<<16&16711680)+(e[f+1]<<8&65280)+(e[f+2]&255),o.push(Gi(a));return o.join("")}function Ji(e){for(var t,r=e.length,a=r%3,o=[],f=16383,c=0,u=r-a;c<u;c+=f)o.push(Vi(e,c,c+f>u?u:c+f));return a===1?(t=e[r-1],o.push(Le[t>>2]+Le[t<<4&63]+"==")):a===2&&(t=(e[r-2]<<8)+e[r-1],o.push(Le[t>>10]+Le[t>>4&63]+Le[t<<2&63]+"=")),o.join("")}var Or={};/*! ieee754. BSD-3-Clause License. Feross Aboukhadijeh <https://feross.org/opensource> */Or.read=function(e,t,r,a,o){var f,c,u=o*8-a-1,p=(1<<u)-1,w=p>>1,m=-7,v=r?o-1:0,A=r?-1:1,k=e[t+v];for(v+=A,f=k&(1<<-m)-1,k>>=-m,m+=u;m>0;f=f*256+e[t+v],v+=A,m-=8);for(c=f&(1<<-m)-1,f>>=-m,m+=a;m>0;c=c*256+e[t+v],v+=A,m-=8);if(f===0)f=1-w;else{if(f===p)return c?NaN:(k?-1:1)*(1/0);c=c+Math.pow(2,a),f=f-w}return(k?-1:1)*c*Math.pow(2,f-a)};Or.write=function(e,t,r,a,o,f){var c,u,p,w=f*8-o-1,m=(1<<w)-1,v=m>>1,A=o===23?Math.pow(2,-24)-Math.pow(2,-77):0,k=a?0:f-1,R=a?1:-1,C=t<0||t===0&&1/t<0?1:0;for(t=Math.abs(t),isNaN(t)||t===1/0?(u=isNaN(t)?1:0,c=m):(c=Math.floor(Math.log(t)/Math.LN2),t*(p=Math.pow(2,-c))<1&&(c--,p*=2),c+v>=1?t+=A/p:t+=A*Math.pow(2,1-v),t*p>=2&&(c++,p/=2),c+v>=m?(u=0,c=m):c+v>=1?(u=(t*p-1)*Math.pow(2,o),c=c+v):(u=t*Math.pow(2,v-1)*Math.pow(2,o),c=0));o>=8;e[r+k]=u&255,k+=R,u/=256,o-=8);for(c=c<<o|u,w+=o;w>0;e[r+k]=c&255,k+=R,c/=256,w-=8);e[r+k-R]|=C*128};/*!
|
|
23
23
|
* The buffer module from node.js, for the browser.
|
package/dist/index.js
CHANGED
|
@@ -1287,9 +1287,7 @@ class Zs {
|
|
|
1287
1287
|
var a, o;
|
|
1288
1288
|
this.pendingOrdersCount = r.data.length, this.emit("onPendingOrdersChanged", r.data);
|
|
1289
1289
|
for (let f = 0; f < r.data.length; f++) {
|
|
1290
|
-
const c = r.data[f];
|
|
1291
|
-
console.log("orderID :", c.create_order.create_id);
|
|
1292
|
-
const u = c.source_swap.chain, p = c.destination_swap.chain, w = this.getWallet(u), m = this.getWallet(p);
|
|
1290
|
+
const c = r.data[f], u = c.source_swap.chain, p = c.destination_swap.chain, w = this.getWallet(u), m = this.getWallet(p);
|
|
1293
1291
|
if (w.error || m.error || !w.val || !m.val) {
|
|
1294
1292
|
this.emit(
|
|
1295
1293
|
"error",
|
|
@@ -1302,7 +1300,7 @@ class Zs {
|
|
|
1302
1300
|
source: w.val,
|
|
1303
1301
|
destination: m.val
|
|
1304
1302
|
});
|
|
1305
|
-
if (
|
|
1303
|
+
if (v.error) {
|
|
1306
1304
|
this.emit(
|
|
1307
1305
|
"error",
|
|
1308
1306
|
c,
|
|
@@ -1314,13 +1312,7 @@ class Zs {
|
|
|
1314
1312
|
c,
|
|
1315
1313
|
v.val.source,
|
|
1316
1314
|
v.val.destination
|
|
1317
|
-
);
|
|
1318
|
-
console.log(
|
|
1319
|
-
"orderAction :",
|
|
1320
|
-
A,
|
|
1321
|
-
c.create_order.create_id
|
|
1322
|
-
);
|
|
1323
|
-
const C = new Gi(c, this.store);
|
|
1315
|
+
), C = new Gi(c, this.store);
|
|
1324
1316
|
if (C.get(A)) continue;
|
|
1325
1317
|
switch (Ft(c.destination_swap.chain)) {
|
|
1326
1318
|
case We.EVM:
|