@xoxno/sdk-js 1.0.223 → 1.0.225
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/cjs/sdk/stellar/__tests__/admin.test.d.ts +0 -12
- package/dist/cjs/sdk/stellar/__tests__/builders-hubasset.test.d.ts +0 -11
- package/dist/cjs/sdk/stellar/__tests__/governance.test.d.ts +0 -4
- package/dist/cjs/sdk/stellar/__tests__/lending.test.d.ts +0 -20
- package/dist/cjs/sdk/stellar/__tests__/strategy-program.test.d.ts +0 -8
- package/dist/cjs/sdk/stellar/__tests__/swap-history.test.d.ts +1 -0
- package/dist/cjs/sdk/stellar/index.d.ts +1 -0
- package/dist/cjs/sdk/stellar/swap-history.d.ts +25 -0
- package/dist/cjs/sdk/stellar/swap-index.d.ts +2 -0
- package/dist/cjs/sdk/stellar/xdr-compat.d.ts +11 -0
- package/dist/esm/index.js +3 -0
- package/dist/esm/sdk/index.js +198 -0
- package/dist/esm/sdk/stellar/admin.js +385 -0
- package/dist/esm/sdk/stellar/auth-policy.js +310 -0
- package/dist/esm/sdk/stellar/cctp.js +23 -0
- package/dist/esm/sdk/stellar/contracts.js +49 -0
- package/dist/esm/sdk/stellar/events/decode.js +415 -0
- package/dist/esm/sdk/stellar/events/id.js +62 -0
- package/dist/esm/sdk/stellar/events/index.js +2 -0
- package/dist/esm/sdk/stellar/governance.js +403 -0
- package/dist/esm/sdk/stellar/index.js +25 -0
- package/dist/esm/sdk/stellar/lending-api-types.js +3 -0
- package/dist/esm/sdk/stellar/lending-read-types.js +1 -0
- package/dist/esm/sdk/stellar/lending-read.js +341 -0
- package/dist/esm/sdk/stellar/lending.js +358 -0
- package/dist/esm/sdk/stellar/math/account.js +256 -0
- package/dist/esm/sdk/stellar/math/index.js +11 -0
- package/dist/esm/sdk/stellar/math/limits.js +273 -0
- package/dist/esm/sdk/stellar/math/projection.js +130 -0
- package/dist/esm/sdk/stellar/math/rates.js +62 -0
- package/dist/esm/sdk/stellar/math/scaled.js +156 -0
- package/dist/esm/sdk/stellar/position-mode.js +11 -0
- package/dist/esm/sdk/stellar/prepare.js +47 -0
- package/dist/esm/sdk/stellar/quote.js +87 -0
- package/dist/esm/sdk/stellar/repay-swap.js +12 -0
- package/dist/esm/sdk/stellar/route-verify.js +285 -0
- package/dist/esm/sdk/stellar/scval-encode.js +464 -0
- package/dist/esm/sdk/stellar/swap-history.js +46 -0
- package/dist/esm/sdk/stellar/swap-index.js +1 -0
- package/dist/esm/sdk/stellar/swap.js +117 -0
- package/dist/esm/sdk/stellar/xdr-compat.js +17 -0
- package/dist/esm/sdk/stellar-schema.js +129 -0
- package/dist/esm/sdk/swagger.js +1957 -0
- package/dist/esm/sdk/types.js +1 -0
- package/dist/esm/sdk/utils.js +21 -0
- package/dist/esm/utils/api.js +169 -0
- package/dist/esm/utils/const.js +11 -0
- package/dist/esm/utils/errors.js +20 -0
- package/dist/esm/utils/guards.js +29 -0
- package/dist/esm/utils/helpers.js +20 -0
- package/dist/esm/utils/regex.js +14 -0
- package/dist/esm/utils/soroban-errors.js +149 -0
- package/dist/index.cjs +1 -1
- package/dist/index.esm.js +1 -2
- package/dist/sdk/stellar/__tests__/admin.test.d.ts +0 -12
- package/dist/sdk/stellar/__tests__/builders-hubasset.test.d.ts +0 -11
- package/dist/sdk/stellar/__tests__/governance.test.d.ts +0 -4
- package/dist/sdk/stellar/__tests__/lending.test.d.ts +0 -20
- package/dist/sdk/stellar/__tests__/strategy-program.test.d.ts +0 -8
- package/dist/sdk/stellar/__tests__/swap-history.test.d.ts +1 -0
- package/dist/sdk/stellar/index.cjs +1 -1
- package/dist/sdk/stellar/index.d.ts +1 -0
- package/dist/sdk/stellar/index.esm.js +1 -1
- package/dist/sdk/stellar/swap-history.d.ts +25 -0
- package/dist/sdk/stellar/swap-index.cjs +2 -0
- package/dist/sdk/stellar/swap-index.d.ts +2 -0
- package/dist/sdk/stellar/swap-index.esm.js +2 -0
- package/dist/sdk/stellar/swap-index.esm.js.LICENSE.txt +8 -0
- package/dist/sdk/stellar/xdr-compat.d.ts +11 -0
- package/package.json +16 -5
- /package/dist/{index.esm.js.LICENSE.txt → sdk/stellar/swap-index.cjs.LICENSE.txt} +0 -0
|
@@ -0,0 +1,2 @@
|
|
|
1
|
+
/*! For license information please see swap-index.cjs.LICENSE.txt */
|
|
2
|
+
"undefined"!=typeof globalThis&&void 0===globalThis.self&&(globalThis.self=globalThis),(()=>{var t={526(t,e){"use strict";e.byteLength=function(t){var e=u(t),r=e[0],n=e[1];return 3*(r+n)/4-n},e.toByteArray=function(t){var e,r,i=u(t),s=i[0],f=i[1],a=new o(function(t,e,r){return 3*(e+r)/4-r}(0,s,f)),h=0,l=f>0?s-4:s;for(r=0;r<l;r+=4)e=n[t.charCodeAt(r)]<<18|n[t.charCodeAt(r+1)]<<12|n[t.charCodeAt(r+2)]<<6|n[t.charCodeAt(r+3)],a[h++]=e>>16&255,a[h++]=e>>8&255,a[h++]=255&e;return 2===f&&(e=n[t.charCodeAt(r)]<<2|n[t.charCodeAt(r+1)]>>4,a[h++]=255&e),1===f&&(e=n[t.charCodeAt(r)]<<10|n[t.charCodeAt(r+1)]<<4|n[t.charCodeAt(r+2)]>>2,a[h++]=e>>8&255,a[h++]=255&e),a},e.fromByteArray=function(t){for(var e,n=t.length,o=n%3,i=[],s=16383,u=0,a=n-o;u<a;u+=s)i.push(f(t,u,u+s>a?a:u+s));return 1===o?(e=t[n-1],i.push(r[e>>2]+r[e<<4&63]+"==")):2===o&&(e=(t[n-2]<<8)+t[n-1],i.push(r[e>>10]+r[e>>4&63]+r[e<<2&63]+"=")),i.join("")};for(var r=[],n=[],o="undefined"!=typeof Uint8Array?Uint8Array:Array,i="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/",s=0;s<64;++s)r[s]=i[s],n[i.charCodeAt(s)]=s;function u(t){var e=t.length;if(e%4>0)throw new Error("Invalid string. Length must be a multiple of 4");var r=t.indexOf("=");return-1===r&&(r=e),[r,r===e?0:4-r%4]}function f(t,e,n){for(var o,i,s=[],u=e;u<n;u+=3)o=(t[u]<<16&16711680)+(t[u+1]<<8&65280)+(255&t[u+2]),s.push(r[(i=o)>>18&63]+r[i>>12&63]+r[i>>6&63]+r[63&i]);return s.join("")}n["-".charCodeAt(0)]=62,n["_".charCodeAt(0)]=63},287(t,e,r){"use strict";const n=r(526),o=r(251),i="function"==typeof Symbol&&"function"==typeof Symbol.for?Symbol.for("nodejs.util.inspect.custom"):null;e.hp=f,e.IS=50;const s=2147483647;function u(t){if(t>s)throw new RangeError('The value "'+t+'" is invalid for option "size"');const e=new Uint8Array(t);return Object.setPrototypeOf(e,f.prototype),e}function f(t,e,r){if("number"==typeof t){if("string"==typeof e)throw new TypeError('The "string" argument must be of type string. Received type number');return l(t)}return a(t,e,r)}function a(t,e,r){if("string"==typeof t)return function(t,e){if("string"==typeof e&&""!==e||(e="utf8"),!f.isEncoding(e))throw new TypeError("Unknown encoding: "+e);const r=0|y(t,e);let n=u(r);const o=n.write(t,e);return o!==r&&(n=n.slice(0,o)),n}(t,e);if(ArrayBuffer.isView(t))return function(t){if(W(t,Uint8Array)){const e=new Uint8Array(t);return p(e.buffer,e.byteOffset,e.byteLength)}return c(t)}(t);if(null==t)throw new TypeError("The first argument must be one of type string, Buffer, ArrayBuffer, Array, or Array-like Object. Received type "+typeof t);if(W(t,ArrayBuffer)||t&&W(t.buffer,ArrayBuffer))return p(t,e,r);if("undefined"!=typeof SharedArrayBuffer&&(W(t,SharedArrayBuffer)||t&&W(t.buffer,SharedArrayBuffer)))return p(t,e,r);if("number"==typeof t)throw new TypeError('The "value" argument must not be of type number. Received type number');const n=t.valueOf&&t.valueOf();if(null!=n&&n!==t)return f.from(n,e,r);const o=function(t){if(f.isBuffer(t)){const e=0|g(t.length),r=u(e);return 0===r.length||t.copy(r,0,0,e),r}return void 0!==t.length?"number"!=typeof t.length||K(t.length)?u(0):c(t):"Buffer"===t.type&&Array.isArray(t.data)?c(t.data):void 0}(t);if(o)return o;if("undefined"!=typeof Symbol&&null!=Symbol.toPrimitive&&"function"==typeof t[Symbol.toPrimitive])return f.from(t[Symbol.toPrimitive]("string"),e,r);throw new TypeError("The first argument must be one of type string, Buffer, ArrayBuffer, Array, or Array-like Object. Received type "+typeof t)}function h(t){if("number"!=typeof t)throw new TypeError('"size" argument must be of type number');if(t<0)throw new RangeError('The value "'+t+'" is invalid for option "size"')}function l(t){return h(t),u(t<0?0:0|g(t))}function c(t){const e=t.length<0?0:0|g(t.length),r=u(e);for(let n=0;n<e;n+=1)r[n]=255&t[n];return r}function p(t,e,r){if(e<0||t.byteLength<e)throw new RangeError('"offset" is outside of buffer bounds');if(t.byteLength<e+(r||0))throw new RangeError('"length" is outside of buffer bounds');let n;return n=void 0===e&&void 0===r?new Uint8Array(t):void 0===r?new Uint8Array(t,e):new Uint8Array(t,e,r),Object.setPrototypeOf(n,f.prototype),n}function g(t){if(t>=s)throw new RangeError("Attempt to allocate Buffer larger than maximum size: 0x"+s.toString(16)+" bytes");return 0|t}function y(t,e){if(f.isBuffer(t))return t.length;if(ArrayBuffer.isView(t)||W(t,ArrayBuffer))return t.byteLength;if("string"!=typeof t)throw new TypeError('The "string" argument must be one of type string, Buffer, or ArrayBuffer. Received type '+typeof t);const r=t.length,n=arguments.length>2&&!0===arguments[2];if(!n&&0===r)return 0;let o=!1;for(;;)switch(e){case"ascii":case"latin1":case"binary":return r;case"utf8":case"utf-8":return Z(t).length;case"ucs2":case"ucs-2":case"utf16le":case"utf-16le":return 2*r;case"hex":return r>>>1;case"base64":return G(t).length;default:if(o)return n?-1:Z(t).length;e=(""+e).toLowerCase(),o=!0}}function d(t,e,r){let n=!1;if((void 0===e||e<0)&&(e=0),e>this.length)return"";if((void 0===r||r>this.length)&&(r=this.length),r<=0)return"";if((r>>>=0)<=(e>>>=0))return"";for(t||(t="utf8");;)switch(t){case"hex":return M(this,e,r);case"utf8":case"utf-8":return O(this,e,r);case"ascii":return U(this,e,r);case"latin1":case"binary":return k(this,e,r);case"base64":return S(this,e,r);case"ucs2":case"ucs-2":case"utf16le":case"utf-16le":return $(this,e,r);default:if(n)throw new TypeError("Unknown encoding: "+t);t=(t+"").toLowerCase(),n=!0}}function w(t,e,r){const n=t[e];t[e]=t[r],t[r]=n}function m(t,e,r,n,o){if(0===t.length)return-1;if("string"==typeof r?(n=r,r=0):r>2147483647?r=2147483647:r<-2147483648&&(r=-2147483648),K(r=+r)&&(r=o?0:t.length-1),r<0&&(r=t.length+r),r>=t.length){if(o)return-1;r=t.length-1}else if(r<0){if(!o)return-1;r=0}if("string"==typeof e&&(e=f.from(e,n)),f.isBuffer(e))return 0===e.length?-1:b(t,e,r,n,o);if("number"==typeof e)return e&=255,"function"==typeof Uint8Array.prototype.indexOf?o?Uint8Array.prototype.indexOf.call(t,e,r):Uint8Array.prototype.lastIndexOf.call(t,e,r):b(t,[e],r,n,o);throw new TypeError("val must be string, number or Buffer")}function b(t,e,r,n,o){let i,s=1,u=t.length,f=e.length;if(void 0!==n&&("ucs2"===(n=String(n).toLowerCase())||"ucs-2"===n||"utf16le"===n||"utf-16le"===n)){if(t.length<2||e.length<2)return-1;s=2,u/=2,f/=2,r/=2}function a(t,e){return 1===s?t[e]:t.readUInt16BE(e*s)}if(o){let n=-1;for(i=r;i<u;i++)if(a(t,i)===a(e,-1===n?0:i-n)){if(-1===n&&(n=i),i-n+1===f)return n*s}else-1!==n&&(i-=i-n),n=-1}else for(r+f>u&&(r=u-f),i=r;i>=0;i--){let r=!0;for(let n=0;n<f;n++)if(a(t,i+n)!==a(e,n)){r=!1;break}if(r)return i}return-1}function E(t,e,r,n){r=Number(r)||0;const o=t.length-r;n?(n=Number(n))>o&&(n=o):n=o;const i=e.length;let s;for(n>i/2&&(n=i/2),s=0;s<n;++s){const n=parseInt(e.substr(2*s,2),16);if(K(n))return s;t[r+s]=n}return s}function A(t,e,r,n){return Y(Z(e,t.length-r),t,r,n)}function I(t,e,r,n){return Y(function(t){const e=[];for(let r=0;r<t.length;++r)e.push(255&t.charCodeAt(r));return e}(e),t,r,n)}function v(t,e,r,n){return Y(G(e),t,r,n)}function B(t,e,r,n){return Y(function(t,e){let r,n,o;const i=[];for(let s=0;s<t.length&&!((e-=2)<0);++s)r=t.charCodeAt(s),n=r>>8,o=r%256,i.push(o),i.push(n);return i}(e,t.length-r),t,r,n)}function S(t,e,r){return 0===e&&r===t.length?n.fromByteArray(t):n.fromByteArray(t.slice(e,r))}function O(t,e,r){r=Math.min(t.length,r);const n=[];let o=e;for(;o<r;){const e=t[o];let i=null,s=e>239?4:e>223?3:e>191?2:1;if(o+s<=r){let r,n,u,f;switch(s){case 1:e<128&&(i=e);break;case 2:r=t[o+1],128==(192&r)&&(f=(31&e)<<6|63&r,f>127&&(i=f));break;case 3:r=t[o+1],n=t[o+2],128==(192&r)&&128==(192&n)&&(f=(15&e)<<12|(63&r)<<6|63&n,f>2047&&(f<55296||f>57343)&&(i=f));break;case 4:r=t[o+1],n=t[o+2],u=t[o+3],128==(192&r)&&128==(192&n)&&128==(192&u)&&(f=(15&e)<<18|(63&r)<<12|(63&n)<<6|63&u,f>65535&&f<1114112&&(i=f))}}null===i?(i=65533,s=1):i>65535&&(i-=65536,n.push(i>>>10&1023|55296),i=56320|1023&i),n.push(i),o+=s}return function(t){const e=t.length;if(e<=R)return String.fromCharCode.apply(String,t);let r="",n=0;for(;n<e;)r+=String.fromCharCode.apply(String,t.slice(n,n+=R));return r}(n)}f.TYPED_ARRAY_SUPPORT=function(){try{const t=new Uint8Array(1),e={foo:function(){return 42}};return Object.setPrototypeOf(e,Uint8Array.prototype),Object.setPrototypeOf(t,e),42===t.foo()}catch(t){return!1}}(),f.TYPED_ARRAY_SUPPORT||"undefined"==typeof console||"function"!=typeof console.error||console.error("This browser lacks typed array (Uint8Array) support which is required by `buffer` v5.x. Use `buffer` v4.x if you require old browser support."),Object.defineProperty(f.prototype,"parent",{enumerable:!0,get:function(){if(f.isBuffer(this))return this.buffer}}),Object.defineProperty(f.prototype,"offset",{enumerable:!0,get:function(){if(f.isBuffer(this))return this.byteOffset}}),f.poolSize=8192,f.from=function(t,e,r){return a(t,e,r)},Object.setPrototypeOf(f.prototype,Uint8Array.prototype),Object.setPrototypeOf(f,Uint8Array),f.alloc=function(t,e,r){return function(t,e,r){return h(t),t<=0?u(t):void 0!==e?"string"==typeof r?u(t).fill(e,r):u(t).fill(e):u(t)}(t,e,r)},f.allocUnsafe=function(t){return l(t)},f.allocUnsafeSlow=function(t){return l(t)},f.isBuffer=function(t){return null!=t&&!0===t._isBuffer&&t!==f.prototype},f.compare=function(t,e){if(W(t,Uint8Array)&&(t=f.from(t,t.offset,t.byteLength)),W(e,Uint8Array)&&(e=f.from(e,e.offset,e.byteLength)),!f.isBuffer(t)||!f.isBuffer(e))throw new TypeError('The "buf1", "buf2" arguments must be one of type Buffer or Uint8Array');if(t===e)return 0;let r=t.length,n=e.length;for(let o=0,i=Math.min(r,n);o<i;++o)if(t[o]!==e[o]){r=t[o],n=e[o];break}return r<n?-1:n<r?1:0},f.isEncoding=function(t){switch(String(t).toLowerCase()){case"hex":case"utf8":case"utf-8":case"ascii":case"latin1":case"binary":case"base64":case"ucs2":case"ucs-2":case"utf16le":case"utf-16le":return!0;default:return!1}},f.concat=function(t,e){if(!Array.isArray(t))throw new TypeError('"list" argument must be an Array of Buffers');if(0===t.length)return f.alloc(0);let r;if(void 0===e)for(e=0,r=0;r<t.length;++r)e+=t[r].length;const n=f.allocUnsafe(e);let o=0;for(r=0;r<t.length;++r){let e=t[r];if(W(e,Uint8Array))o+e.length>n.length?(f.isBuffer(e)||(e=f.from(e)),e.copy(n,o)):Uint8Array.prototype.set.call(n,e,o);else{if(!f.isBuffer(e))throw new TypeError('"list" argument must be an Array of Buffers');e.copy(n,o)}o+=e.length}return n},f.byteLength=y,f.prototype._isBuffer=!0,f.prototype.swap16=function(){const t=this.length;if(t%2!=0)throw new RangeError("Buffer size must be a multiple of 16-bits");for(let e=0;e<t;e+=2)w(this,e,e+1);return this},f.prototype.swap32=function(){const t=this.length;if(t%4!=0)throw new RangeError("Buffer size must be a multiple of 32-bits");for(let e=0;e<t;e+=4)w(this,e,e+3),w(this,e+1,e+2);return this},f.prototype.swap64=function(){const t=this.length;if(t%8!=0)throw new RangeError("Buffer size must be a multiple of 64-bits");for(let e=0;e<t;e+=8)w(this,e,e+7),w(this,e+1,e+6),w(this,e+2,e+5),w(this,e+3,e+4);return this},f.prototype.toString=function(){const t=this.length;return 0===t?"":0===arguments.length?O(this,0,t):d.apply(this,arguments)},f.prototype.toLocaleString=f.prototype.toString,f.prototype.equals=function(t){if(!f.isBuffer(t))throw new TypeError("Argument must be a Buffer");return this===t||0===f.compare(this,t)},f.prototype.inspect=function(){let t="";const r=e.IS;return t=this.toString("hex",0,r).replace(/(.{2})/g,"$1 ").trim(),this.length>r&&(t+=" ... "),"<Buffer "+t+">"},i&&(f.prototype[i]=f.prototype.inspect),f.prototype.compare=function(t,e,r,n,o){if(W(t,Uint8Array)&&(t=f.from(t,t.offset,t.byteLength)),!f.isBuffer(t))throw new TypeError('The "target" argument must be one of type Buffer or Uint8Array. Received type '+typeof t);if(void 0===e&&(e=0),void 0===r&&(r=t?t.length:0),void 0===n&&(n=0),void 0===o&&(o=this.length),e<0||r>t.length||n<0||o>this.length)throw new RangeError("out of range index");if(n>=o&&e>=r)return 0;if(n>=o)return-1;if(e>=r)return 1;if(this===t)return 0;let i=(o>>>=0)-(n>>>=0),s=(r>>>=0)-(e>>>=0);const u=Math.min(i,s),a=this.slice(n,o),h=t.slice(e,r);for(let t=0;t<u;++t)if(a[t]!==h[t]){i=a[t],s=h[t];break}return i<s?-1:s<i?1:0},f.prototype.includes=function(t,e,r){return-1!==this.indexOf(t,e,r)},f.prototype.indexOf=function(t,e,r){return m(this,t,e,r,!0)},f.prototype.lastIndexOf=function(t,e,r){return m(this,t,e,r,!1)},f.prototype.write=function(t,e,r,n){if(void 0===e)n="utf8",r=this.length,e=0;else if(void 0===r&&"string"==typeof e)n=e,r=this.length,e=0;else{if(!isFinite(e))throw new Error("Buffer.write(string, encoding, offset[, length]) is no longer supported");e>>>=0,isFinite(r)?(r>>>=0,void 0===n&&(n="utf8")):(n=r,r=void 0)}const o=this.length-e;if((void 0===r||r>o)&&(r=o),t.length>0&&(r<0||e<0)||e>this.length)throw new RangeError("Attempt to write outside buffer bounds");n||(n="utf8");let i=!1;for(;;)switch(n){case"hex":return E(this,t,e,r);case"utf8":case"utf-8":return A(this,t,e,r);case"ascii":case"latin1":case"binary":return I(this,t,e,r);case"base64":return v(this,t,e,r);case"ucs2":case"ucs-2":case"utf16le":case"utf-16le":return B(this,t,e,r);default:if(i)throw new TypeError("Unknown encoding: "+n);n=(""+n).toLowerCase(),i=!0}},f.prototype.toJSON=function(){return{type:"Buffer",data:Array.prototype.slice.call(this._arr||this,0)}};const R=4096;function U(t,e,r){let n="";r=Math.min(t.length,r);for(let o=e;o<r;++o)n+=String.fromCharCode(127&t[o]);return n}function k(t,e,r){let n="";r=Math.min(t.length,r);for(let o=e;o<r;++o)n+=String.fromCharCode(t[o]);return n}function M(t,e,r){const n=t.length;(!e||e<0)&&(e=0),(!r||r<0||r>n)&&(r=n);let o="";for(let n=e;n<r;++n)o+=H[t[n]];return o}function $(t,e,r){const n=t.slice(e,r);let o="";for(let t=0;t<n.length-1;t+=2)o+=String.fromCharCode(n[t]+256*n[t+1]);return o}function x(t,e,r){if(t%1!=0||t<0)throw new RangeError("offset is not uint");if(t+e>r)throw new RangeError("Trying to access beyond buffer length")}function T(t,e,r,n,o,i){if(!f.isBuffer(t))throw new TypeError('"buffer" argument must be a Buffer instance');if(e>o||e<i)throw new RangeError('"value" argument is out of bounds');if(r+n>t.length)throw new RangeError("Index out of range")}function L(t,e,r,n,o){j(e,n,o,t,r,7);let i=Number(e&BigInt(4294967295));t[r++]=i,i>>=8,t[r++]=i,i>>=8,t[r++]=i,i>>=8,t[r++]=i;let s=Number(e>>BigInt(32)&BigInt(4294967295));return t[r++]=s,s>>=8,t[r++]=s,s>>=8,t[r++]=s,s>>=8,t[r++]=s,r}function P(t,e,r,n,o){j(e,n,o,t,r,7);let i=Number(e&BigInt(4294967295));t[r+7]=i,i>>=8,t[r+6]=i,i>>=8,t[r+5]=i,i>>=8,t[r+4]=i;let s=Number(e>>BigInt(32)&BigInt(4294967295));return t[r+3]=s,s>>=8,t[r+2]=s,s>>=8,t[r+1]=s,s>>=8,t[r]=s,r+8}function _(t,e,r,n,o,i){if(r+n>t.length)throw new RangeError("Index out of range");if(r<0)throw new RangeError("Index out of range")}function D(t,e,r,n,i){return e=+e,r>>>=0,i||_(t,0,r,4),o.write(t,e,r,n,23,4),r+4}function C(t,e,r,n,i){return e=+e,r>>>=0,i||_(t,0,r,8),o.write(t,e,r,n,52,8),r+8}f.prototype.slice=function(t,e){const r=this.length;(t=~~t)<0?(t+=r)<0&&(t=0):t>r&&(t=r),(e=void 0===e?r:~~e)<0?(e+=r)<0&&(e=0):e>r&&(e=r),e<t&&(e=t);const n=this.subarray(t,e);return Object.setPrototypeOf(n,f.prototype),n},f.prototype.readUintLE=f.prototype.readUIntLE=function(t,e,r){t>>>=0,e>>>=0,r||x(t,e,this.length);let n=this[t],o=1,i=0;for(;++i<e&&(o*=256);)n+=this[t+i]*o;return n},f.prototype.readUintBE=f.prototype.readUIntBE=function(t,e,r){t>>>=0,e>>>=0,r||x(t,e,this.length);let n=this[t+--e],o=1;for(;e>0&&(o*=256);)n+=this[t+--e]*o;return n},f.prototype.readUint8=f.prototype.readUInt8=function(t,e){return t>>>=0,e||x(t,1,this.length),this[t]},f.prototype.readUint16LE=f.prototype.readUInt16LE=function(t,e){return t>>>=0,e||x(t,2,this.length),this[t]|this[t+1]<<8},f.prototype.readUint16BE=f.prototype.readUInt16BE=function(t,e){return t>>>=0,e||x(t,2,this.length),this[t]<<8|this[t+1]},f.prototype.readUint32LE=f.prototype.readUInt32LE=function(t,e){return t>>>=0,e||x(t,4,this.length),(this[t]|this[t+1]<<8|this[t+2]<<16)+16777216*this[t+3]},f.prototype.readUint32BE=f.prototype.readUInt32BE=function(t,e){return t>>>=0,e||x(t,4,this.length),16777216*this[t]+(this[t+1]<<16|this[t+2]<<8|this[t+3])},f.prototype.readBigUInt64LE=J((function(t){X(t>>>=0,"offset");const e=this[t],r=this[t+7];void 0!==e&&void 0!==r||z(t,this.length-8);const n=e+256*this[++t]+65536*this[++t]+this[++t]*2**24,o=this[++t]+256*this[++t]+65536*this[++t]+r*2**24;return BigInt(n)+(BigInt(o)<<BigInt(32))})),f.prototype.readBigUInt64BE=J((function(t){X(t>>>=0,"offset");const e=this[t],r=this[t+7];void 0!==e&&void 0!==r||z(t,this.length-8);const n=e*2**24+65536*this[++t]+256*this[++t]+this[++t],o=this[++t]*2**24+65536*this[++t]+256*this[++t]+r;return(BigInt(n)<<BigInt(32))+BigInt(o)})),f.prototype.readIntLE=function(t,e,r){t>>>=0,e>>>=0,r||x(t,e,this.length);let n=this[t],o=1,i=0;for(;++i<e&&(o*=256);)n+=this[t+i]*o;return o*=128,n>=o&&(n-=Math.pow(2,8*e)),n},f.prototype.readIntBE=function(t,e,r){t>>>=0,e>>>=0,r||x(t,e,this.length);let n=e,o=1,i=this[t+--n];for(;n>0&&(o*=256);)i+=this[t+--n]*o;return o*=128,i>=o&&(i-=Math.pow(2,8*e)),i},f.prototype.readInt8=function(t,e){return t>>>=0,e||x(t,1,this.length),128&this[t]?-1*(255-this[t]+1):this[t]},f.prototype.readInt16LE=function(t,e){t>>>=0,e||x(t,2,this.length);const r=this[t]|this[t+1]<<8;return 32768&r?4294901760|r:r},f.prototype.readInt16BE=function(t,e){t>>>=0,e||x(t,2,this.length);const r=this[t+1]|this[t]<<8;return 32768&r?4294901760|r:r},f.prototype.readInt32LE=function(t,e){return t>>>=0,e||x(t,4,this.length),this[t]|this[t+1]<<8|this[t+2]<<16|this[t+3]<<24},f.prototype.readInt32BE=function(t,e){return t>>>=0,e||x(t,4,this.length),this[t]<<24|this[t+1]<<16|this[t+2]<<8|this[t+3]},f.prototype.readBigInt64LE=J((function(t){X(t>>>=0,"offset");const e=this[t],r=this[t+7];void 0!==e&&void 0!==r||z(t,this.length-8);const n=this[t+4]+256*this[t+5]+65536*this[t+6]+(r<<24);return(BigInt(n)<<BigInt(32))+BigInt(e+256*this[++t]+65536*this[++t]+this[++t]*2**24)})),f.prototype.readBigInt64BE=J((function(t){X(t>>>=0,"offset");const e=this[t],r=this[t+7];void 0!==e&&void 0!==r||z(t,this.length-8);const n=(e<<24)+65536*this[++t]+256*this[++t]+this[++t];return(BigInt(n)<<BigInt(32))+BigInt(this[++t]*2**24+65536*this[++t]+256*this[++t]+r)})),f.prototype.readFloatLE=function(t,e){return t>>>=0,e||x(t,4,this.length),o.read(this,t,!0,23,4)},f.prototype.readFloatBE=function(t,e){return t>>>=0,e||x(t,4,this.length),o.read(this,t,!1,23,4)},f.prototype.readDoubleLE=function(t,e){return t>>>=0,e||x(t,8,this.length),o.read(this,t,!0,52,8)},f.prototype.readDoubleBE=function(t,e){return t>>>=0,e||x(t,8,this.length),o.read(this,t,!1,52,8)},f.prototype.writeUintLE=f.prototype.writeUIntLE=function(t,e,r,n){t=+t,e>>>=0,r>>>=0,n||T(this,t,e,r,Math.pow(2,8*r)-1,0);let o=1,i=0;for(this[e]=255&t;++i<r&&(o*=256);)this[e+i]=t/o&255;return e+r},f.prototype.writeUintBE=f.prototype.writeUIntBE=function(t,e,r,n){t=+t,e>>>=0,r>>>=0,n||T(this,t,e,r,Math.pow(2,8*r)-1,0);let o=r-1,i=1;for(this[e+o]=255&t;--o>=0&&(i*=256);)this[e+o]=t/i&255;return e+r},f.prototype.writeUint8=f.prototype.writeUInt8=function(t,e,r){return t=+t,e>>>=0,r||T(this,t,e,1,255,0),this[e]=255&t,e+1},f.prototype.writeUint16LE=f.prototype.writeUInt16LE=function(t,e,r){return t=+t,e>>>=0,r||T(this,t,e,2,65535,0),this[e]=255&t,this[e+1]=t>>>8,e+2},f.prototype.writeUint16BE=f.prototype.writeUInt16BE=function(t,e,r){return t=+t,e>>>=0,r||T(this,t,e,2,65535,0),this[e]=t>>>8,this[e+1]=255&t,e+2},f.prototype.writeUint32LE=f.prototype.writeUInt32LE=function(t,e,r){return t=+t,e>>>=0,r||T(this,t,e,4,4294967295,0),this[e+3]=t>>>24,this[e+2]=t>>>16,this[e+1]=t>>>8,this[e]=255&t,e+4},f.prototype.writeUint32BE=f.prototype.writeUInt32BE=function(t,e,r){return t=+t,e>>>=0,r||T(this,t,e,4,4294967295,0),this[e]=t>>>24,this[e+1]=t>>>16,this[e+2]=t>>>8,this[e+3]=255&t,e+4},f.prototype.writeBigUInt64LE=J((function(t,e=0){return L(this,t,e,BigInt(0),BigInt("0xffffffffffffffff"))})),f.prototype.writeBigUInt64BE=J((function(t,e=0){return P(this,t,e,BigInt(0),BigInt("0xffffffffffffffff"))})),f.prototype.writeIntLE=function(t,e,r,n){if(t=+t,e>>>=0,!n){const n=Math.pow(2,8*r-1);T(this,t,e,r,n-1,-n)}let o=0,i=1,s=0;for(this[e]=255&t;++o<r&&(i*=256);)t<0&&0===s&&0!==this[e+o-1]&&(s=1),this[e+o]=(t/i|0)-s&255;return e+r},f.prototype.writeIntBE=function(t,e,r,n){if(t=+t,e>>>=0,!n){const n=Math.pow(2,8*r-1);T(this,t,e,r,n-1,-n)}let o=r-1,i=1,s=0;for(this[e+o]=255&t;--o>=0&&(i*=256);)t<0&&0===s&&0!==this[e+o+1]&&(s=1),this[e+o]=(t/i|0)-s&255;return e+r},f.prototype.writeInt8=function(t,e,r){return t=+t,e>>>=0,r||T(this,t,e,1,127,-128),t<0&&(t=255+t+1),this[e]=255&t,e+1},f.prototype.writeInt16LE=function(t,e,r){return t=+t,e>>>=0,r||T(this,t,e,2,32767,-32768),this[e]=255&t,this[e+1]=t>>>8,e+2},f.prototype.writeInt16BE=function(t,e,r){return t=+t,e>>>=0,r||T(this,t,e,2,32767,-32768),this[e]=t>>>8,this[e+1]=255&t,e+2},f.prototype.writeInt32LE=function(t,e,r){return t=+t,e>>>=0,r||T(this,t,e,4,2147483647,-2147483648),this[e]=255&t,this[e+1]=t>>>8,this[e+2]=t>>>16,this[e+3]=t>>>24,e+4},f.prototype.writeInt32BE=function(t,e,r){return t=+t,e>>>=0,r||T(this,t,e,4,2147483647,-2147483648),t<0&&(t=4294967295+t+1),this[e]=t>>>24,this[e+1]=t>>>16,this[e+2]=t>>>8,this[e+3]=255&t,e+4},f.prototype.writeBigInt64LE=J((function(t,e=0){return L(this,t,e,-BigInt("0x8000000000000000"),BigInt("0x7fffffffffffffff"))})),f.prototype.writeBigInt64BE=J((function(t,e=0){return P(this,t,e,-BigInt("0x8000000000000000"),BigInt("0x7fffffffffffffff"))})),f.prototype.writeFloatLE=function(t,e,r){return D(this,t,e,!0,r)},f.prototype.writeFloatBE=function(t,e,r){return D(this,t,e,!1,r)},f.prototype.writeDoubleLE=function(t,e,r){return C(this,t,e,!0,r)},f.prototype.writeDoubleBE=function(t,e,r){return C(this,t,e,!1,r)},f.prototype.copy=function(t,e,r,n){if(!f.isBuffer(t))throw new TypeError("argument should be a Buffer");if(r||(r=0),n||0===n||(n=this.length),e>=t.length&&(e=t.length),e||(e=0),n>0&&n<r&&(n=r),n===r)return 0;if(0===t.length||0===this.length)return 0;if(e<0)throw new RangeError("targetStart out of bounds");if(r<0||r>=this.length)throw new RangeError("Index out of range");if(n<0)throw new RangeError("sourceEnd out of bounds");n>this.length&&(n=this.length),t.length-e<n-r&&(n=t.length-e+r);const o=n-r;return this===t&&"function"==typeof Uint8Array.prototype.copyWithin?this.copyWithin(e,r,n):Uint8Array.prototype.set.call(t,this.subarray(r,n),e),o},f.prototype.fill=function(t,e,r,n){if("string"==typeof t){if("string"==typeof e?(n=e,e=0,r=this.length):"string"==typeof r&&(n=r,r=this.length),void 0!==n&&"string"!=typeof n)throw new TypeError("encoding must be a string");if("string"==typeof n&&!f.isEncoding(n))throw new TypeError("Unknown encoding: "+n);if(1===t.length){const e=t.charCodeAt(0);("utf8"===n&&e<128||"latin1"===n)&&(t=e)}}else"number"==typeof t?t&=255:"boolean"==typeof t&&(t=Number(t));if(e<0||this.length<e||this.length<r)throw new RangeError("Out of range index");if(r<=e)return this;let o;if(e>>>=0,r=void 0===r?this.length:r>>>0,t||(t=0),"number"==typeof t)for(o=e;o<r;++o)this[o]=t;else{const i=f.isBuffer(t)?t:f.from(t,n),s=i.length;if(0===s)throw new TypeError('The value "'+t+'" is invalid for argument "value"');for(o=0;o<r-e;++o)this[o+e]=i[o%s]}return this};const N={};function F(t,e,r){N[t]=class extends r{constructor(){super(),Object.defineProperty(this,"message",{value:e.apply(this,arguments),writable:!0,configurable:!0}),this.name=`${this.name} [${t}]`,this.stack,delete this.name}get code(){return t}set code(t){Object.defineProperty(this,"code",{configurable:!0,enumerable:!0,value:t,writable:!0})}toString(){return`${this.name} [${t}]: ${this.message}`}}}function V(t){let e="",r=t.length;const n="-"===t[0]?1:0;for(;r>=n+4;r-=3)e=`_${t.slice(r-3,r)}${e}`;return`${t.slice(0,r)}${e}`}function j(t,e,r,n,o,i){if(t>r||t<e){const n="bigint"==typeof e?"n":"";let o;throw o=i>3?0===e||e===BigInt(0)?`>= 0${n} and < 2${n} ** ${8*(i+1)}${n}`:`>= -(2${n} ** ${8*(i+1)-1}${n}) and < 2 ** ${8*(i+1)-1}${n}`:`>= ${e}${n} and <= ${r}${n}`,new N.ERR_OUT_OF_RANGE("value",o,t)}!function(t,e,r){X(e,"offset"),void 0!==t[e]&&void 0!==t[e+r]||z(e,t.length-(r+1))}(n,o,i)}function X(t,e){if("number"!=typeof t)throw new N.ERR_INVALID_ARG_TYPE(e,"number",t)}function z(t,e,r){if(Math.floor(t)!==t)throw X(t,r),new N.ERR_OUT_OF_RANGE(r||"offset","an integer",t);if(e<0)throw new N.ERR_BUFFER_OUT_OF_BOUNDS;throw new N.ERR_OUT_OF_RANGE(r||"offset",`>= ${r?1:0} and <= ${e}`,t)}F("ERR_BUFFER_OUT_OF_BOUNDS",(function(t){return t?`${t} is outside of buffer bounds`:"Attempt to access memory outside buffer bounds"}),RangeError),F("ERR_INVALID_ARG_TYPE",(function(t,e){return`The "${t}" argument must be of type number. Received type ${typeof e}`}),TypeError),F("ERR_OUT_OF_RANGE",(function(t,e,r){let n=`The value of "${t}" is out of range.`,o=r;return Number.isInteger(r)&&Math.abs(r)>2**32?o=V(String(r)):"bigint"==typeof r&&(o=String(r),(r>BigInt(2)**BigInt(32)||r<-(BigInt(2)**BigInt(32)))&&(o=V(o)),o+="n"),n+=` It must be ${e}. Received ${o}`,n}),RangeError);const q=/[^+/0-9A-Za-z-_]/g;function Z(t,e){let r;e=e||1/0;const n=t.length;let o=null;const i=[];for(let s=0;s<n;++s){if(r=t.charCodeAt(s),r>55295&&r<57344){if(!o){if(r>56319){(e-=3)>-1&&i.push(239,191,189);continue}if(s+1===n){(e-=3)>-1&&i.push(239,191,189);continue}o=r;continue}if(r<56320){(e-=3)>-1&&i.push(239,191,189),o=r;continue}r=65536+(o-55296<<10|r-56320)}else o&&(e-=3)>-1&&i.push(239,191,189);if(o=null,r<128){if((e-=1)<0)break;i.push(r)}else if(r<2048){if((e-=2)<0)break;i.push(r>>6|192,63&r|128)}else if(r<65536){if((e-=3)<0)break;i.push(r>>12|224,r>>6&63|128,63&r|128)}else{if(!(r<1114112))throw new Error("Invalid code point");if((e-=4)<0)break;i.push(r>>18|240,r>>12&63|128,r>>6&63|128,63&r|128)}}return i}function G(t){return n.toByteArray(function(t){if((t=(t=t.split("=")[0]).trim().replace(q,"")).length<2)return"";for(;t.length%4!=0;)t+="=";return t}(t))}function Y(t,e,r,n){let o;for(o=0;o<n&&!(o+r>=e.length||o>=t.length);++o)e[o+r]=t[o];return o}function W(t,e){return t instanceof e||null!=t&&null!=t.constructor&&null!=t.constructor.name&&t.constructor.name===e.name}function K(t){return t!=t}const H=function(){const t="0123456789abcdef",e=new Array(256);for(let r=0;r<16;++r){const n=16*r;for(let o=0;o<16;++o)e[n+o]=t[r]+t[o]}return e}();function J(t){return"undefined"==typeof BigInt?Q:t}function Q(){throw new Error("BigInt not supported")}},251(t,e){e.read=function(t,e,r,n,o){var i,s,u=8*o-n-1,f=(1<<u)-1,a=f>>1,h=-7,l=r?o-1:0,c=r?-1:1,p=t[e+l];for(l+=c,i=p&(1<<-h)-1,p>>=-h,h+=u;h>0;i=256*i+t[e+l],l+=c,h-=8);for(s=i&(1<<-h)-1,i>>=-h,h+=n;h>0;s=256*s+t[e+l],l+=c,h-=8);if(0===i)i=1-a;else{if(i===f)return s?NaN:1/0*(p?-1:1);s+=Math.pow(2,n),i-=a}return(p?-1:1)*s*Math.pow(2,i-n)},e.write=function(t,e,r,n,o,i){var s,u,f,a=8*i-o-1,h=(1<<a)-1,l=h>>1,c=23===o?Math.pow(2,-24)-Math.pow(2,-77):0,p=n?0:i-1,g=n?1:-1,y=e<0||0===e&&1/e<0?1:0;for(e=Math.abs(e),isNaN(e)||e===1/0?(u=isNaN(e)?1:0,s=h):(s=Math.floor(Math.log(e)/Math.LN2),e*(f=Math.pow(2,-s))<1&&(s--,f*=2),(e+=s+l>=1?c/f:c*Math.pow(2,1-l))*f>=2&&(s++,f/=2),s+l>=h?(u=0,s=h):s+l>=1?(u=(e*f-1)*Math.pow(2,o),s+=l):(u=e*Math.pow(2,l-1)*Math.pow(2,o),s=0));o>=8;t[r+p]=255&u,p+=g,u/=256,o-=8);for(s=s<<o|u,a+=o;a>0;t[r+p]=255&s,p+=g,s/=256,a-=8);t[r+p-g]|=128*y}}},e={};function r(n){var o=e[n];if(void 0!==o)return o.exports;var i=e[n]={exports:{}};return t[n](i,i.exports,r),i.exports}r.d=(t,e)=>{for(var n in e)r.o(e,n)&&!r.o(t,n)&&Object.defineProperty(t,n,{enumerable:!0,get:e[n]})},r.o=(t,e)=>Object.prototype.hasOwnProperty.call(t,e),r.r=t=>{"undefined"!=typeof Symbol&&Symbol.toStringTag&&Object.defineProperty(t,Symbol.toStringTag,{value:"Module"}),Object.defineProperty(t,"__esModule",{value:!0})};var n={};(()=>{"use strict";r.r(n),r.d(n,{decodeStellarSwapEnvelope:()=>_});const t=require("@stellar/stellar-sdk");var e=r(287);function o(t,e){const r=t[e];return"function"==typeof r?r.call(t):r}function i(t){if(!t||"object"!=typeof t)return;const e=t;return"function"==typeof e.switch?e.switch().name:e.type}function s(t){return function(t){const r=t;return e.hp.from("value"in r?r.value:r)}(o(t,"bytes"))}const u=["Soroswap","Aquarius","Phoenix","Sushi","CometDex"],f={Soroswap:0,Aquarius:1,Phoenix:2,Sushi:3,CometDex:4},a=1,h=1e6,l=5,c=6,p=0,g=1,y=2,d=128,w=48,m=32,b=256,E=d-y;class A{assets=[];amounts=[];ops=[];weights=[];constructor(t){this.amounts.push(t)}asset(t){const e=this.assets.indexOf(t);if(-1!==e)return e;if(this.assets.length>=b)throw new Error("Stellar builder: strategy references more than 256 distinct addresses");return this.assets.push(t),this.assets.length-1}amount(t){if(this.amounts.length>=E)throw new Error("Stellar builder: strategy references too many distinct amounts");return this.amounts.push(t),this.amounts.length-1}weight(t){if(this.weights.length>=m)throw new Error("Stellar builder: strategy uses more than 32 split weights");if(!Number.isInteger(t)||t<=0||t>h)throw new Error(`Stellar builder: split weight ${t} outside 1..=${h}`);return this.weights.push(t),this.weights.length-1}emit(t,e,r,n,o){this.ops.push([t,e,r,n,o])}emitPath(t,e){t.hops.forEach(((r,n)=>{if(r.tokenIn===r.tokenOut)throw new Error("Stellar builder: hop swaps a token for itself");const o=t.hops[n-1];if(o&&r.tokenIn!==o.tokenOut)throw new Error("Stellar builder: hop does not chain onto its predecessor's output");this.emit(f[r.venue],0===n?e:g,this.asset(r.pool),this.asset(r.tokenIn),this.asset(r.tokenOut))}))}lowerPaths(t){const e=t.filter((t=>t.hops.length>0)),r=Array.from({length:e.length},(()=>!1));for(let t=0;t<e.length;t+=1){if(r[t])continue;const n=e[t].hops[0]?.tokenIn,o=[];for(let r=t;r<e.length;r+=1)e[r].hops[0]?.tokenIn===n&&o.push(r);const i=o.reduce(((t,r)=>t+e[r].splitPpm),0);if(i>h)throw new Error(`Stellar builder: split weights for one token sum to ${i}, above ${h}`);const s=i===h;let u=h;o.forEach(((t,n)=>{r[t]=!0;const i=e[t];let f;if(n+1===o.length&&s)f=p;else{if(0===u)throw new Error("Stellar builder: split weights exhaust the group before its last path");const t=Math.floor(i.splitPpm*h/u);u-=Math.min(i.splitPpm,u),f=d+this.weight(t)}this.emitPath(i,f)}))}}toBytes(t,r,n){if(0===this.ops.length)throw new Error("Stellar builder: strategy lowered to zero instructions");if(this.ops.length>w)throw new Error(`Stellar builder: strategy has ${this.ops.length} instructions, the router accepts ${w}`);const o=[a,t,r,0,n>>>24&255,n>>>16&255,n>>>8&255,255&n,this.ops.length,this.weights.length];for(const t of this.ops)o.push(...t);for(const t of this.weights)o.push(t>>>16&255,t>>>8&255,255&t);return e.hp.from(o)}get assetList(){return this.assets}get amountList(){return this.amounts}}const I=r=>t.xdr.ScVal.scvBytes(e.hp.from((e=>{const r=new A(e.totalMinOut),n=r.asset(e.tokenIn),o=r.asset(e.tokenOut);if(n===o)throw new Error("Stellar builder: `tokenIn` and `tokenOut` are the same asset");if(e.burnPool){const t=r.asset(e.burnPool),o=r.amountList.length;for(const t of e.burnMinAmounts??[])r.amount(t);r.emit(l,p,t,n,o)}if(r.lowerPaths(e.paths),e.mintPool){const t=e.preSwapAmount;if(t&&BigInt(t)>0n){const n=e.mintPoolTokens;if(!n||2!==n.length)throw new Error("Stellar builder: `preSwapAmount` needs `mintPoolTokens` to name the pool’s two constituents");const[o,i]=n,[s,u]=e.preSwapFromA?[o,i]:[i,o];r.emit(f.Aquarius,y+r.amount(t),r.asset(e.mintPool),r.asset(s),r.asset(u))}r.emit(c,p,r.asset(e.mintPool),o,r.amount(e.mintMinShares??"1"))}const i=Number(e.referralId??0);if(!Number.isInteger(i)||i<0||i>4294967295)throw new Error(`Stellar builder: referral id ${e.referralId} does not fit the wire’s u32`);return(e=>{const r=Object.keys(e).sort().map((r=>{return new t.xdr.ScMapEntry({key:(n=r,t.xdr.ScVal.scvSymbol(n)),val:e[r]});var n}));return t.xdr.ScVal.scvMap(r)})({amounts:t.xdr.ScVal.scvVec(r.amountList.map((e=>{return r=e,new t.ScInt(r).toI128();var r}))),assets:t.xdr.ScVal.scvVec(r.assetList.map((e=>(e=>new t.Address(e).toScVal())(e)))),ops:t.xdr.ScVal.scvBytes(r.toBytes(n,o,i))})})(r).toXDR("base64"),"base64")),v=r=>{const n=e.hp.from(r);if(0===n.length)throw new Error("Stellar builder: strategy swap bytes must be non-empty base64 routeXdr, 0x hex string, or Uint8Array");return t.xdr.ScVal.scvBytes(n)},B=()=>t.xdr.ScVal.scvBytes(e.hp.alloc(0)),S=t=>{const r=t.trim();if(r.startsWith("0x")){const t=r.slice(2);if(!((n=t).length>0&&n.length%2==0&&/^[0-9a-fA-F]+$/.test(n)))throw new Error("Stellar builder: strategy swap bytes hex string must be 0x-prefixed and even-length");return e.hp.from(t,"hex")}var n;if(!/^[A-Za-z0-9+/]+={0,2}$/.test(r))throw new Error("Stellar builder: strategy swap bytes must be base64 routeXdr or 0x-prefixed hex");const o=e.hp.from(r,"base64");if(0===o.length)throw new Error("Stellar builder: strategy swap bytes must be non-empty base64 routeXdr, 0x hex string, or Uint8Array");return o},O=10,R=5,U=3,k=O+R*w+U*m,M=16384;class $ extends Error{code;constructor(t,e){super(`Stellar route verification failed [${t}]: ${e}`),this.name="StellarRouteVerificationError",this.code=t}}const x=(t,e)=>{throw new $(t,e)},T=t=>{const e="string"==typeof t?t:t&&"object"==typeof t&&"routeXdr"in t?t.routeXdr:void 0;if("string"==typeof e&&e.length>2*M)return x("OVERSIZED",`encoded route has ${e.length} characters`);try{return s((t=>{if("string"==typeof t)return v(S(t));if(t instanceof Uint8Array)return 0===t.length?B():v(t);if(t&&"object"==typeof t)return"routeXdr"in(e=t)&&"string"==typeof e.routeXdr?v(S(t.routeXdr)):(t=>"swapXdr"in t&&"string"==typeof t.swapXdr)(t)?v(S(t.swapXdr)):(t=>"bytes"in t&&("string"==typeof t.bytes||t.bytes instanceof Uint8Array))(t)?"string"==typeof t.bytes?v(S(t.bytes)):0===t.bytes.length?B():v(t.bytes):I((t=>{if(!t||"object"!=typeof t)throw new Error("Stellar builder: decoded strategy `steps` must be a StrategyPayload ({ paths, tokenIn, tokenOut, totalMinOut })");const e=t;if(!Array.isArray(e.paths)||0===e.paths.length&&!e.burnPool&&!e.mintPool)throw new Error("Stellar builder: `steps.paths` needs a strategy path or a liquidity burn/mint operation");if("string"!=typeof e.tokenIn)throw new Error("Stellar builder: `steps.tokenIn` must be a contract address");if("string"!=typeof e.tokenOut)throw new Error("Stellar builder: `steps.tokenOut` must be a contract address");if("string"!=typeof e.totalMinOut)throw new Error("Stellar builder: `steps.totalMinOut` must be an i128 decimal string");const r=new Map;for(const[t,n]of e.paths.entries()){if(!n||"number"!=typeof n.splitPpm||n.splitPpm<=0||!Array.isArray(n.hops)||0===n.hops.length)throw new Error(`Stellar builder: \`steps.paths[${t}]\` must have splitPpm > 0 and a non-empty hops array`);for(const[e,r]of n.hops.entries())if(!r||"string"!=typeof r.pool||"string"!=typeof r.tokenIn||"string"!=typeof r.tokenOut||!u.includes(r.venue))throw new Error(`Stellar builder: \`steps.paths[${t}].hops[${e}]\` must have pool, tokenIn, tokenOut, and a valid Soroban venue`);const e=n.hops[0];r.set(e.tokenIn,(r.get(e.tokenIn)??0)+n.splitPpm)}for(const[t,n]of r){if(n>h)throw new Error(`Stellar builder: \`steps.paths[].splitPpm\` for ${t} sums to ${n}, above ${h}`);if(!e.mintPool&&n!==h)throw new Error(`Stellar builder: \`steps.paths[].splitPpm\` for ${t} must sum to ${h}, got ${n}`)}return e})(t));var e;throw new Error("Stellar builder: `steps` must be opaque strategy bytes (`routeXdr`, base64/hex string, or Uint8Array)")})(t))}catch(t){return x("MALFORMED",t instanceof Error?t.message:String(t))}},L=e=>{let r;try{r=t.xdr.ScVal.fromXDR(e)}catch(t){return x("MALFORMED",`payload is not one XDR ScVal: ${t instanceof Error?t.message:String(t)}`)}if("scvMap"!==i(r))return x("MALFORMED","payload must be a StrategyPayload map");const n=o(r,"map")??[];if("amounts,assets,ops"!==n.map((t=>"scvSymbol"===i(o(t,"key"))?o(o(t,"key"),"sym").toString():"")).join(","))return x("MALFORMED","payload fields must be exactly amounts, assets, ops");const[u,f,a]=n.map((t=>o(t,"val")));return"scvVec"!==i(u)||"scvVec"!==i(f)||"scvBytes"!==i(a)?x("MALFORMED","payload field has the wrong type"):{amounts:o(u,"vec")??[],assets:o(f,"vec")??[],ops:s(a)}};function P(e){const r=T(e);0===r.length&&x("MALFORMED","route is empty"),r.length>M&&x("OVERSIZED",`route has ${r.length} bytes, above ${M}`);const n=L(r),s=n.assets.length,f=n.amounts.length;0===s&&x("MALFORMED","asset registry is empty"),(s>b||f>E)&&x("OVERSIZED",`registries hold ${s} assets and ${f} amounts`);const A=n.assets.map(((e,r)=>"scvAddress"!==i(e)?x("MALFORMED",`assets[${r}] is not an address`):t.Address.fromScAddress(o(e,"address")).toString())),I=n.amounts.map(((e,r)=>"scvI128"!==i(e)?x("MALFORMED",`amounts[${r}] is not an i128`):(0,t.scValToBigInt)(e))),v=n.ops;v.length<O&&x("MALFORMED","program header is truncated"),v.length>k&&x("OVERSIZED",`program has ${v.length} bytes, above ${k}`);const B=t=>{const e=v[t];return void 0===e?x("MALFORMED",`program byte ${t} is missing`):e},S=B(0);S!==a&&x("UNSUPPORTED_VERSION",`program version ${S}, expected ${a}`);const $=B(8),P=B(9);0===$&&x("INVALID_STRUCTURE","program has no instructions"),($>w||P>m)&&x("OVERSIZED",`program declares ${$} instructions and ${P} weights`);const _=O+R*$;v.length!==_+U*P&&x("MALFORMED","program length does not match its instruction and weight counts");const D=B(1),C=B(2),N=B(3);(D>=s||C>=s||N>=f)&&x("MALFORMED","header index is outside its registry"),D===C&&x("INVALID_STRUCTURE","token_in equals token_out");const F=v.readUInt32BE(4),V=[];for(let t=0;t<P;t+=1){const e=v.readUIntBE(_+U*t,U);(0===e||e>h)&&x("INVALID_STRUCTURE",`split weight ${e} outside 1..=${h}`),V.push(e)}const j=t=>A[t]??x("MALFORMED",`asset index ${t} is outside the registry`),X=t=>I[t]??x("MALFORMED",`amount index ${t} is outside the registry`),z=[];let q;for(let t=0;t<$;t+=1){const e=O+R*t,r=B(e),n=B(e+1),o=B(e+2),i=B(e+3),s=B(e+4);let a;if(r>c&&x("UNKNOWN_OPCODE",`instruction ${t} has opcode ${r}`),n===p)a={kind:"all"};else if(n===g)void 0!==q&&q===i||x("INVALID_STRUCTURE",`instruction ${t} does not chain onto its predecessor`),a={kind:"prev"};else if(n>=d){const e=V[n-d];void 0===e&&x("MALFORMED",`instruction ${t} weight index is out of range`),a={kind:"ppm",ppm:e}}else a={kind:"fixed",amount:X(n-y)};const h=j(o);r!==l&&r!==c?(i===s&&x("INVALID_STRUCTURE",`instruction ${t} swaps a token for itself`),z.push({kind:"swap",venue:u[r],mode:a,pool:h,tokenIn:j(i),tokenOut:j(s)}),q=s):("all"!==a.kind&&x("MALFORMED",`liquidity instruction ${t} must use mode All`),s>=f&&x("MALFORMED",`instruction ${t} amount index is out of range`),z.push({kind:r===l?"burn":"mint",pool:h,shareToken:j(i),amountIndex:s}),q=r===c?i:void 0)}const Z=X(N);return Z<=0n&&x("MIN_OUT_TOO_LOW",`encoded total_min_out is ${Z}`),{version:S,tokenIn:j(D),tokenOut:j(C),totalMinOut:Z,referralId:F,assets:A,amounts:I,ops:z,weights:V}}function _(e){try{const{envelopeXdr:r,networkPassphrase:n,routerAddress:u,viewer:f,operationIndex:a}=e;if(!n||!t.StrKey.isValidContract(u)||new t.Address(f).toString()!==f||"string"!=typeof r||r.length>1048576||r.length%4!=0||!/^[A-Za-z0-9+/]+={0,2}$/.test(r)||void 0!==a&&(!Number.isSafeInteger(a)||a<0))return null;const h=t.TransactionBuilder.fromXDR(r,n),l="innerTransaction"in h?h.innerTransaction:h;if(void 0!==a&&a>=l.operations.length)return null;let c=null;for(const[e,r]of l.operations.entries()){if(void 0!==a&&e!==a)continue;if("invokeHostFunction"!==r.type)continue;const n=r.func;if("hostFunctionTypeInvokeContract"!==i(n))continue;const h=o(n,"invokeContract");if(t.Address.fromScAddress(o(h,"contractAddress")).toString()!==u||"execute_strategy"!==o(h,"functionName").toString())continue;const l=o(h,"args"),[p,g,y]=l;if(3!==l.length||!p||!g||!y||"scvAddress"!==i(p)||"scvI128"!==i(g)||"scvBytes"!==i(y))return null;if(t.Address.fromScAddress(o(p,"address")).toString()!==f)continue;const d=(0,t.scValToBigInt)(g);if(d<=0n)return null;const w=P(s(y));if(w.tokenIn===w.tokenOut||!t.StrKey.isValidContract(w.tokenIn)||!t.StrKey.isValidContract(w.tokenOut))return null;if(c)return null;c={tokenIn:w.tokenIn,tokenOut:w.tokenOut,amountInAtoms:d.toString(),operationIndex:e}}return c}catch{return null}}})(),module.exports=n})();
|
|
@@ -0,0 +1,2 @@
|
|
|
1
|
+
/*! For license information please see swap-index.esm.js.LICENSE.txt */
|
|
2
|
+
"undefined"!=typeof globalThis&&void 0===globalThis.self&&(globalThis.self=globalThis);import{Address as t,ScInt as e,StrKey as r,TransactionBuilder as n,scValToBigInt as o,xdr as i}from"@stellar/stellar-sdk";var s={526(t,e){e.byteLength=function(t){var e=u(t),r=e[0],n=e[1];return 3*(r+n)/4-n},e.toByteArray=function(t){var e,r,i=u(t),s=i[0],f=i[1],a=new o(function(t,e,r){return 3*(e+r)/4-r}(0,s,f)),h=0,l=f>0?s-4:s;for(r=0;r<l;r+=4)e=n[t.charCodeAt(r)]<<18|n[t.charCodeAt(r+1)]<<12|n[t.charCodeAt(r+2)]<<6|n[t.charCodeAt(r+3)],a[h++]=e>>16&255,a[h++]=e>>8&255,a[h++]=255&e;return 2===f&&(e=n[t.charCodeAt(r)]<<2|n[t.charCodeAt(r+1)]>>4,a[h++]=255&e),1===f&&(e=n[t.charCodeAt(r)]<<10|n[t.charCodeAt(r+1)]<<4|n[t.charCodeAt(r+2)]>>2,a[h++]=e>>8&255,a[h++]=255&e),a},e.fromByteArray=function(t){for(var e,n=t.length,o=n%3,i=[],s=16383,u=0,a=n-o;u<a;u+=s)i.push(f(t,u,u+s>a?a:u+s));return 1===o?(e=t[n-1],i.push(r[e>>2]+r[e<<4&63]+"==")):2===o&&(e=(t[n-2]<<8)+t[n-1],i.push(r[e>>10]+r[e>>4&63]+r[e<<2&63]+"=")),i.join("")};for(var r=[],n=[],o="undefined"!=typeof Uint8Array?Uint8Array:Array,i="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/",s=0;s<64;++s)r[s]=i[s],n[i.charCodeAt(s)]=s;function u(t){var e=t.length;if(e%4>0)throw new Error("Invalid string. Length must be a multiple of 4");var r=t.indexOf("=");return-1===r&&(r=e),[r,r===e?0:4-r%4]}function f(t,e,n){for(var o,i,s=[],u=e;u<n;u+=3)o=(t[u]<<16&16711680)+(t[u+1]<<8&65280)+(255&t[u+2]),s.push(r[(i=o)>>18&63]+r[i>>12&63]+r[i>>6&63]+r[63&i]);return s.join("")}n["-".charCodeAt(0)]=62,n["_".charCodeAt(0)]=63},287(t,e,r){const n=r(526),o=r(251),i="function"==typeof Symbol&&"function"==typeof Symbol.for?Symbol.for("nodejs.util.inspect.custom"):null;e.hp=f,e.IS=50;const s=2147483647;function u(t){if(t>s)throw new RangeError('The value "'+t+'" is invalid for option "size"');const e=new Uint8Array(t);return Object.setPrototypeOf(e,f.prototype),e}function f(t,e,r){if("number"==typeof t){if("string"==typeof e)throw new TypeError('The "string" argument must be of type string. Received type number');return l(t)}return a(t,e,r)}function a(t,e,r){if("string"==typeof t)return function(t,e){if("string"==typeof e&&""!==e||(e="utf8"),!f.isEncoding(e))throw new TypeError("Unknown encoding: "+e);const r=0|y(t,e);let n=u(r);const o=n.write(t,e);return o!==r&&(n=n.slice(0,o)),n}(t,e);if(ArrayBuffer.isView(t))return function(t){if(W(t,Uint8Array)){const e=new Uint8Array(t);return p(e.buffer,e.byteOffset,e.byteLength)}return c(t)}(t);if(null==t)throw new TypeError("The first argument must be one of type string, Buffer, ArrayBuffer, Array, or Array-like Object. Received type "+typeof t);if(W(t,ArrayBuffer)||t&&W(t.buffer,ArrayBuffer))return p(t,e,r);if("undefined"!=typeof SharedArrayBuffer&&(W(t,SharedArrayBuffer)||t&&W(t.buffer,SharedArrayBuffer)))return p(t,e,r);if("number"==typeof t)throw new TypeError('The "value" argument must not be of type number. Received type number');const n=t.valueOf&&t.valueOf();if(null!=n&&n!==t)return f.from(n,e,r);const o=function(t){if(f.isBuffer(t)){const e=0|g(t.length),r=u(e);return 0===r.length||t.copy(r,0,0,e),r}return void 0!==t.length?"number"!=typeof t.length||K(t.length)?u(0):c(t):"Buffer"===t.type&&Array.isArray(t.data)?c(t.data):void 0}(t);if(o)return o;if("undefined"!=typeof Symbol&&null!=Symbol.toPrimitive&&"function"==typeof t[Symbol.toPrimitive])return f.from(t[Symbol.toPrimitive]("string"),e,r);throw new TypeError("The first argument must be one of type string, Buffer, ArrayBuffer, Array, or Array-like Object. Received type "+typeof t)}function h(t){if("number"!=typeof t)throw new TypeError('"size" argument must be of type number');if(t<0)throw new RangeError('The value "'+t+'" is invalid for option "size"')}function l(t){return h(t),u(t<0?0:0|g(t))}function c(t){const e=t.length<0?0:0|g(t.length),r=u(e);for(let n=0;n<e;n+=1)r[n]=255&t[n];return r}function p(t,e,r){if(e<0||t.byteLength<e)throw new RangeError('"offset" is outside of buffer bounds');if(t.byteLength<e+(r||0))throw new RangeError('"length" is outside of buffer bounds');let n;return n=void 0===e&&void 0===r?new Uint8Array(t):void 0===r?new Uint8Array(t,e):new Uint8Array(t,e,r),Object.setPrototypeOf(n,f.prototype),n}function g(t){if(t>=s)throw new RangeError("Attempt to allocate Buffer larger than maximum size: 0x"+s.toString(16)+" bytes");return 0|t}function y(t,e){if(f.isBuffer(t))return t.length;if(ArrayBuffer.isView(t)||W(t,ArrayBuffer))return t.byteLength;if("string"!=typeof t)throw new TypeError('The "string" argument must be one of type string, Buffer, or ArrayBuffer. Received type '+typeof t);const r=t.length,n=arguments.length>2&&!0===arguments[2];if(!n&&0===r)return 0;let o=!1;for(;;)switch(e){case"ascii":case"latin1":case"binary":return r;case"utf8":case"utf-8":return Z(t).length;case"ucs2":case"ucs-2":case"utf16le":case"utf-16le":return 2*r;case"hex":return r>>>1;case"base64":return G(t).length;default:if(o)return n?-1:Z(t).length;e=(""+e).toLowerCase(),o=!0}}function d(t,e,r){let n=!1;if((void 0===e||e<0)&&(e=0),e>this.length)return"";if((void 0===r||r>this.length)&&(r=this.length),r<=0)return"";if((r>>>=0)<=(e>>>=0))return"";for(t||(t="utf8");;)switch(t){case"hex":return $(this,e,r);case"utf8":case"utf-8":return O(this,e,r);case"ascii":return U(this,e,r);case"latin1":case"binary":return k(this,e,r);case"base64":return S(this,e,r);case"ucs2":case"ucs-2":case"utf16le":case"utf-16le":return M(this,e,r);default:if(n)throw new TypeError("Unknown encoding: "+t);t=(t+"").toLowerCase(),n=!0}}function w(t,e,r){const n=t[e];t[e]=t[r],t[r]=n}function m(t,e,r,n,o){if(0===t.length)return-1;if("string"==typeof r?(n=r,r=0):r>2147483647?r=2147483647:r<-2147483648&&(r=-2147483648),K(r=+r)&&(r=o?0:t.length-1),r<0&&(r=t.length+r),r>=t.length){if(o)return-1;r=t.length-1}else if(r<0){if(!o)return-1;r=0}if("string"==typeof e&&(e=f.from(e,n)),f.isBuffer(e))return 0===e.length?-1:b(t,e,r,n,o);if("number"==typeof e)return e&=255,"function"==typeof Uint8Array.prototype.indexOf?o?Uint8Array.prototype.indexOf.call(t,e,r):Uint8Array.prototype.lastIndexOf.call(t,e,r):b(t,[e],r,n,o);throw new TypeError("val must be string, number or Buffer")}function b(t,e,r,n,o){let i,s=1,u=t.length,f=e.length;if(void 0!==n&&("ucs2"===(n=String(n).toLowerCase())||"ucs-2"===n||"utf16le"===n||"utf-16le"===n)){if(t.length<2||e.length<2)return-1;s=2,u/=2,f/=2,r/=2}function a(t,e){return 1===s?t[e]:t.readUInt16BE(e*s)}if(o){let n=-1;for(i=r;i<u;i++)if(a(t,i)===a(e,-1===n?0:i-n)){if(-1===n&&(n=i),i-n+1===f)return n*s}else-1!==n&&(i-=i-n),n=-1}else for(r+f>u&&(r=u-f),i=r;i>=0;i--){let r=!0;for(let n=0;n<f;n++)if(a(t,i+n)!==a(e,n)){r=!1;break}if(r)return i}return-1}function E(t,e,r,n){r=Number(r)||0;const o=t.length-r;n?(n=Number(n))>o&&(n=o):n=o;const i=e.length;let s;for(n>i/2&&(n=i/2),s=0;s<n;++s){const n=parseInt(e.substr(2*s,2),16);if(K(n))return s;t[r+s]=n}return s}function I(t,e,r,n){return Y(Z(e,t.length-r),t,r,n)}function A(t,e,r,n){return Y(function(t){const e=[];for(let r=0;r<t.length;++r)e.push(255&t.charCodeAt(r));return e}(e),t,r,n)}function B(t,e,r,n){return Y(G(e),t,r,n)}function v(t,e,r,n){return Y(function(t,e){let r,n,o;const i=[];for(let s=0;s<t.length&&!((e-=2)<0);++s)r=t.charCodeAt(s),n=r>>8,o=r%256,i.push(o),i.push(n);return i}(e,t.length-r),t,r,n)}function S(t,e,r){return 0===e&&r===t.length?n.fromByteArray(t):n.fromByteArray(t.slice(e,r))}function O(t,e,r){r=Math.min(t.length,r);const n=[];let o=e;for(;o<r;){const e=t[o];let i=null,s=e>239?4:e>223?3:e>191?2:1;if(o+s<=r){let r,n,u,f;switch(s){case 1:e<128&&(i=e);break;case 2:r=t[o+1],128==(192&r)&&(f=(31&e)<<6|63&r,f>127&&(i=f));break;case 3:r=t[o+1],n=t[o+2],128==(192&r)&&128==(192&n)&&(f=(15&e)<<12|(63&r)<<6|63&n,f>2047&&(f<55296||f>57343)&&(i=f));break;case 4:r=t[o+1],n=t[o+2],u=t[o+3],128==(192&r)&&128==(192&n)&&128==(192&u)&&(f=(15&e)<<18|(63&r)<<12|(63&n)<<6|63&u,f>65535&&f<1114112&&(i=f))}}null===i?(i=65533,s=1):i>65535&&(i-=65536,n.push(i>>>10&1023|55296),i=56320|1023&i),n.push(i),o+=s}return function(t){const e=t.length;if(e<=R)return String.fromCharCode.apply(String,t);let r="",n=0;for(;n<e;)r+=String.fromCharCode.apply(String,t.slice(n,n+=R));return r}(n)}f.TYPED_ARRAY_SUPPORT=function(){try{const t=new Uint8Array(1),e={foo:function(){return 42}};return Object.setPrototypeOf(e,Uint8Array.prototype),Object.setPrototypeOf(t,e),42===t.foo()}catch(t){return!1}}(),f.TYPED_ARRAY_SUPPORT||"undefined"==typeof console||"function"!=typeof console.error||console.error("This browser lacks typed array (Uint8Array) support which is required by `buffer` v5.x. Use `buffer` v4.x if you require old browser support."),Object.defineProperty(f.prototype,"parent",{enumerable:!0,get:function(){if(f.isBuffer(this))return this.buffer}}),Object.defineProperty(f.prototype,"offset",{enumerable:!0,get:function(){if(f.isBuffer(this))return this.byteOffset}}),f.poolSize=8192,f.from=function(t,e,r){return a(t,e,r)},Object.setPrototypeOf(f.prototype,Uint8Array.prototype),Object.setPrototypeOf(f,Uint8Array),f.alloc=function(t,e,r){return function(t,e,r){return h(t),t<=0?u(t):void 0!==e?"string"==typeof r?u(t).fill(e,r):u(t).fill(e):u(t)}(t,e,r)},f.allocUnsafe=function(t){return l(t)},f.allocUnsafeSlow=function(t){return l(t)},f.isBuffer=function(t){return null!=t&&!0===t._isBuffer&&t!==f.prototype},f.compare=function(t,e){if(W(t,Uint8Array)&&(t=f.from(t,t.offset,t.byteLength)),W(e,Uint8Array)&&(e=f.from(e,e.offset,e.byteLength)),!f.isBuffer(t)||!f.isBuffer(e))throw new TypeError('The "buf1", "buf2" arguments must be one of type Buffer or Uint8Array');if(t===e)return 0;let r=t.length,n=e.length;for(let o=0,i=Math.min(r,n);o<i;++o)if(t[o]!==e[o]){r=t[o],n=e[o];break}return r<n?-1:n<r?1:0},f.isEncoding=function(t){switch(String(t).toLowerCase()){case"hex":case"utf8":case"utf-8":case"ascii":case"latin1":case"binary":case"base64":case"ucs2":case"ucs-2":case"utf16le":case"utf-16le":return!0;default:return!1}},f.concat=function(t,e){if(!Array.isArray(t))throw new TypeError('"list" argument must be an Array of Buffers');if(0===t.length)return f.alloc(0);let r;if(void 0===e)for(e=0,r=0;r<t.length;++r)e+=t[r].length;const n=f.allocUnsafe(e);let o=0;for(r=0;r<t.length;++r){let e=t[r];if(W(e,Uint8Array))o+e.length>n.length?(f.isBuffer(e)||(e=f.from(e)),e.copy(n,o)):Uint8Array.prototype.set.call(n,e,o);else{if(!f.isBuffer(e))throw new TypeError('"list" argument must be an Array of Buffers');e.copy(n,o)}o+=e.length}return n},f.byteLength=y,f.prototype._isBuffer=!0,f.prototype.swap16=function(){const t=this.length;if(t%2!=0)throw new RangeError("Buffer size must be a multiple of 16-bits");for(let e=0;e<t;e+=2)w(this,e,e+1);return this},f.prototype.swap32=function(){const t=this.length;if(t%4!=0)throw new RangeError("Buffer size must be a multiple of 32-bits");for(let e=0;e<t;e+=4)w(this,e,e+3),w(this,e+1,e+2);return this},f.prototype.swap64=function(){const t=this.length;if(t%8!=0)throw new RangeError("Buffer size must be a multiple of 64-bits");for(let e=0;e<t;e+=8)w(this,e,e+7),w(this,e+1,e+6),w(this,e+2,e+5),w(this,e+3,e+4);return this},f.prototype.toString=function(){const t=this.length;return 0===t?"":0===arguments.length?O(this,0,t):d.apply(this,arguments)},f.prototype.toLocaleString=f.prototype.toString,f.prototype.equals=function(t){if(!f.isBuffer(t))throw new TypeError("Argument must be a Buffer");return this===t||0===f.compare(this,t)},f.prototype.inspect=function(){let t="";const r=e.IS;return t=this.toString("hex",0,r).replace(/(.{2})/g,"$1 ").trim(),this.length>r&&(t+=" ... "),"<Buffer "+t+">"},i&&(f.prototype[i]=f.prototype.inspect),f.prototype.compare=function(t,e,r,n,o){if(W(t,Uint8Array)&&(t=f.from(t,t.offset,t.byteLength)),!f.isBuffer(t))throw new TypeError('The "target" argument must be one of type Buffer or Uint8Array. Received type '+typeof t);if(void 0===e&&(e=0),void 0===r&&(r=t?t.length:0),void 0===n&&(n=0),void 0===o&&(o=this.length),e<0||r>t.length||n<0||o>this.length)throw new RangeError("out of range index");if(n>=o&&e>=r)return 0;if(n>=o)return-1;if(e>=r)return 1;if(this===t)return 0;let i=(o>>>=0)-(n>>>=0),s=(r>>>=0)-(e>>>=0);const u=Math.min(i,s),a=this.slice(n,o),h=t.slice(e,r);for(let t=0;t<u;++t)if(a[t]!==h[t]){i=a[t],s=h[t];break}return i<s?-1:s<i?1:0},f.prototype.includes=function(t,e,r){return-1!==this.indexOf(t,e,r)},f.prototype.indexOf=function(t,e,r){return m(this,t,e,r,!0)},f.prototype.lastIndexOf=function(t,e,r){return m(this,t,e,r,!1)},f.prototype.write=function(t,e,r,n){if(void 0===e)n="utf8",r=this.length,e=0;else if(void 0===r&&"string"==typeof e)n=e,r=this.length,e=0;else{if(!isFinite(e))throw new Error("Buffer.write(string, encoding, offset[, length]) is no longer supported");e>>>=0,isFinite(r)?(r>>>=0,void 0===n&&(n="utf8")):(n=r,r=void 0)}const o=this.length-e;if((void 0===r||r>o)&&(r=o),t.length>0&&(r<0||e<0)||e>this.length)throw new RangeError("Attempt to write outside buffer bounds");n||(n="utf8");let i=!1;for(;;)switch(n){case"hex":return E(this,t,e,r);case"utf8":case"utf-8":return I(this,t,e,r);case"ascii":case"latin1":case"binary":return A(this,t,e,r);case"base64":return B(this,t,e,r);case"ucs2":case"ucs-2":case"utf16le":case"utf-16le":return v(this,t,e,r);default:if(i)throw new TypeError("Unknown encoding: "+n);n=(""+n).toLowerCase(),i=!0}},f.prototype.toJSON=function(){return{type:"Buffer",data:Array.prototype.slice.call(this._arr||this,0)}};const R=4096;function U(t,e,r){let n="";r=Math.min(t.length,r);for(let o=e;o<r;++o)n+=String.fromCharCode(127&t[o]);return n}function k(t,e,r){let n="";r=Math.min(t.length,r);for(let o=e;o<r;++o)n+=String.fromCharCode(t[o]);return n}function $(t,e,r){const n=t.length;(!e||e<0)&&(e=0),(!r||r<0||r>n)&&(r=n);let o="";for(let n=e;n<r;++n)o+=H[t[n]];return o}function M(t,e,r){const n=t.slice(e,r);let o="";for(let t=0;t<n.length-1;t+=2)o+=String.fromCharCode(n[t]+256*n[t+1]);return o}function L(t,e,r){if(t%1!=0||t<0)throw new RangeError("offset is not uint");if(t+e>r)throw new RangeError("Trying to access beyond buffer length")}function T(t,e,r,n,o,i){if(!f.isBuffer(t))throw new TypeError('"buffer" argument must be a Buffer instance');if(e>o||e<i)throw new RangeError('"value" argument is out of bounds');if(r+n>t.length)throw new RangeError("Index out of range")}function x(t,e,r,n,o){j(e,n,o,t,r,7);let i=Number(e&BigInt(4294967295));t[r++]=i,i>>=8,t[r++]=i,i>>=8,t[r++]=i,i>>=8,t[r++]=i;let s=Number(e>>BigInt(32)&BigInt(4294967295));return t[r++]=s,s>>=8,t[r++]=s,s>>=8,t[r++]=s,s>>=8,t[r++]=s,r}function P(t,e,r,n,o){j(e,n,o,t,r,7);let i=Number(e&BigInt(4294967295));t[r+7]=i,i>>=8,t[r+6]=i,i>>=8,t[r+5]=i,i>>=8,t[r+4]=i;let s=Number(e>>BigInt(32)&BigInt(4294967295));return t[r+3]=s,s>>=8,t[r+2]=s,s>>=8,t[r+1]=s,s>>=8,t[r]=s,r+8}function _(t,e,r,n,o,i){if(r+n>t.length)throw new RangeError("Index out of range");if(r<0)throw new RangeError("Index out of range")}function D(t,e,r,n,i){return e=+e,r>>>=0,i||_(t,0,r,4),o.write(t,e,r,n,23,4),r+4}function C(t,e,r,n,i){return e=+e,r>>>=0,i||_(t,0,r,8),o.write(t,e,r,n,52,8),r+8}f.prototype.slice=function(t,e){const r=this.length;(t=~~t)<0?(t+=r)<0&&(t=0):t>r&&(t=r),(e=void 0===e?r:~~e)<0?(e+=r)<0&&(e=0):e>r&&(e=r),e<t&&(e=t);const n=this.subarray(t,e);return Object.setPrototypeOf(n,f.prototype),n},f.prototype.readUintLE=f.prototype.readUIntLE=function(t,e,r){t>>>=0,e>>>=0,r||L(t,e,this.length);let n=this[t],o=1,i=0;for(;++i<e&&(o*=256);)n+=this[t+i]*o;return n},f.prototype.readUintBE=f.prototype.readUIntBE=function(t,e,r){t>>>=0,e>>>=0,r||L(t,e,this.length);let n=this[t+--e],o=1;for(;e>0&&(o*=256);)n+=this[t+--e]*o;return n},f.prototype.readUint8=f.prototype.readUInt8=function(t,e){return t>>>=0,e||L(t,1,this.length),this[t]},f.prototype.readUint16LE=f.prototype.readUInt16LE=function(t,e){return t>>>=0,e||L(t,2,this.length),this[t]|this[t+1]<<8},f.prototype.readUint16BE=f.prototype.readUInt16BE=function(t,e){return t>>>=0,e||L(t,2,this.length),this[t]<<8|this[t+1]},f.prototype.readUint32LE=f.prototype.readUInt32LE=function(t,e){return t>>>=0,e||L(t,4,this.length),(this[t]|this[t+1]<<8|this[t+2]<<16)+16777216*this[t+3]},f.prototype.readUint32BE=f.prototype.readUInt32BE=function(t,e){return t>>>=0,e||L(t,4,this.length),16777216*this[t]+(this[t+1]<<16|this[t+2]<<8|this[t+3])},f.prototype.readBigUInt64LE=J((function(t){X(t>>>=0,"offset");const e=this[t],r=this[t+7];void 0!==e&&void 0!==r||z(t,this.length-8);const n=e+256*this[++t]+65536*this[++t]+this[++t]*2**24,o=this[++t]+256*this[++t]+65536*this[++t]+r*2**24;return BigInt(n)+(BigInt(o)<<BigInt(32))})),f.prototype.readBigUInt64BE=J((function(t){X(t>>>=0,"offset");const e=this[t],r=this[t+7];void 0!==e&&void 0!==r||z(t,this.length-8);const n=e*2**24+65536*this[++t]+256*this[++t]+this[++t],o=this[++t]*2**24+65536*this[++t]+256*this[++t]+r;return(BigInt(n)<<BigInt(32))+BigInt(o)})),f.prototype.readIntLE=function(t,e,r){t>>>=0,e>>>=0,r||L(t,e,this.length);let n=this[t],o=1,i=0;for(;++i<e&&(o*=256);)n+=this[t+i]*o;return o*=128,n>=o&&(n-=Math.pow(2,8*e)),n},f.prototype.readIntBE=function(t,e,r){t>>>=0,e>>>=0,r||L(t,e,this.length);let n=e,o=1,i=this[t+--n];for(;n>0&&(o*=256);)i+=this[t+--n]*o;return o*=128,i>=o&&(i-=Math.pow(2,8*e)),i},f.prototype.readInt8=function(t,e){return t>>>=0,e||L(t,1,this.length),128&this[t]?-1*(255-this[t]+1):this[t]},f.prototype.readInt16LE=function(t,e){t>>>=0,e||L(t,2,this.length);const r=this[t]|this[t+1]<<8;return 32768&r?4294901760|r:r},f.prototype.readInt16BE=function(t,e){t>>>=0,e||L(t,2,this.length);const r=this[t+1]|this[t]<<8;return 32768&r?4294901760|r:r},f.prototype.readInt32LE=function(t,e){return t>>>=0,e||L(t,4,this.length),this[t]|this[t+1]<<8|this[t+2]<<16|this[t+3]<<24},f.prototype.readInt32BE=function(t,e){return t>>>=0,e||L(t,4,this.length),this[t]<<24|this[t+1]<<16|this[t+2]<<8|this[t+3]},f.prototype.readBigInt64LE=J((function(t){X(t>>>=0,"offset");const e=this[t],r=this[t+7];void 0!==e&&void 0!==r||z(t,this.length-8);const n=this[t+4]+256*this[t+5]+65536*this[t+6]+(r<<24);return(BigInt(n)<<BigInt(32))+BigInt(e+256*this[++t]+65536*this[++t]+this[++t]*2**24)})),f.prototype.readBigInt64BE=J((function(t){X(t>>>=0,"offset");const e=this[t],r=this[t+7];void 0!==e&&void 0!==r||z(t,this.length-8);const n=(e<<24)+65536*this[++t]+256*this[++t]+this[++t];return(BigInt(n)<<BigInt(32))+BigInt(this[++t]*2**24+65536*this[++t]+256*this[++t]+r)})),f.prototype.readFloatLE=function(t,e){return t>>>=0,e||L(t,4,this.length),o.read(this,t,!0,23,4)},f.prototype.readFloatBE=function(t,e){return t>>>=0,e||L(t,4,this.length),o.read(this,t,!1,23,4)},f.prototype.readDoubleLE=function(t,e){return t>>>=0,e||L(t,8,this.length),o.read(this,t,!0,52,8)},f.prototype.readDoubleBE=function(t,e){return t>>>=0,e||L(t,8,this.length),o.read(this,t,!1,52,8)},f.prototype.writeUintLE=f.prototype.writeUIntLE=function(t,e,r,n){t=+t,e>>>=0,r>>>=0,n||T(this,t,e,r,Math.pow(2,8*r)-1,0);let o=1,i=0;for(this[e]=255&t;++i<r&&(o*=256);)this[e+i]=t/o&255;return e+r},f.prototype.writeUintBE=f.prototype.writeUIntBE=function(t,e,r,n){t=+t,e>>>=0,r>>>=0,n||T(this,t,e,r,Math.pow(2,8*r)-1,0);let o=r-1,i=1;for(this[e+o]=255&t;--o>=0&&(i*=256);)this[e+o]=t/i&255;return e+r},f.prototype.writeUint8=f.prototype.writeUInt8=function(t,e,r){return t=+t,e>>>=0,r||T(this,t,e,1,255,0),this[e]=255&t,e+1},f.prototype.writeUint16LE=f.prototype.writeUInt16LE=function(t,e,r){return t=+t,e>>>=0,r||T(this,t,e,2,65535,0),this[e]=255&t,this[e+1]=t>>>8,e+2},f.prototype.writeUint16BE=f.prototype.writeUInt16BE=function(t,e,r){return t=+t,e>>>=0,r||T(this,t,e,2,65535,0),this[e]=t>>>8,this[e+1]=255&t,e+2},f.prototype.writeUint32LE=f.prototype.writeUInt32LE=function(t,e,r){return t=+t,e>>>=0,r||T(this,t,e,4,4294967295,0),this[e+3]=t>>>24,this[e+2]=t>>>16,this[e+1]=t>>>8,this[e]=255&t,e+4},f.prototype.writeUint32BE=f.prototype.writeUInt32BE=function(t,e,r){return t=+t,e>>>=0,r||T(this,t,e,4,4294967295,0),this[e]=t>>>24,this[e+1]=t>>>16,this[e+2]=t>>>8,this[e+3]=255&t,e+4},f.prototype.writeBigUInt64LE=J((function(t,e=0){return x(this,t,e,BigInt(0),BigInt("0xffffffffffffffff"))})),f.prototype.writeBigUInt64BE=J((function(t,e=0){return P(this,t,e,BigInt(0),BigInt("0xffffffffffffffff"))})),f.prototype.writeIntLE=function(t,e,r,n){if(t=+t,e>>>=0,!n){const n=Math.pow(2,8*r-1);T(this,t,e,r,n-1,-n)}let o=0,i=1,s=0;for(this[e]=255&t;++o<r&&(i*=256);)t<0&&0===s&&0!==this[e+o-1]&&(s=1),this[e+o]=(t/i|0)-s&255;return e+r},f.prototype.writeIntBE=function(t,e,r,n){if(t=+t,e>>>=0,!n){const n=Math.pow(2,8*r-1);T(this,t,e,r,n-1,-n)}let o=r-1,i=1,s=0;for(this[e+o]=255&t;--o>=0&&(i*=256);)t<0&&0===s&&0!==this[e+o+1]&&(s=1),this[e+o]=(t/i|0)-s&255;return e+r},f.prototype.writeInt8=function(t,e,r){return t=+t,e>>>=0,r||T(this,t,e,1,127,-128),t<0&&(t=255+t+1),this[e]=255&t,e+1},f.prototype.writeInt16LE=function(t,e,r){return t=+t,e>>>=0,r||T(this,t,e,2,32767,-32768),this[e]=255&t,this[e+1]=t>>>8,e+2},f.prototype.writeInt16BE=function(t,e,r){return t=+t,e>>>=0,r||T(this,t,e,2,32767,-32768),this[e]=t>>>8,this[e+1]=255&t,e+2},f.prototype.writeInt32LE=function(t,e,r){return t=+t,e>>>=0,r||T(this,t,e,4,2147483647,-2147483648),this[e]=255&t,this[e+1]=t>>>8,this[e+2]=t>>>16,this[e+3]=t>>>24,e+4},f.prototype.writeInt32BE=function(t,e,r){return t=+t,e>>>=0,r||T(this,t,e,4,2147483647,-2147483648),t<0&&(t=4294967295+t+1),this[e]=t>>>24,this[e+1]=t>>>16,this[e+2]=t>>>8,this[e+3]=255&t,e+4},f.prototype.writeBigInt64LE=J((function(t,e=0){return x(this,t,e,-BigInt("0x8000000000000000"),BigInt("0x7fffffffffffffff"))})),f.prototype.writeBigInt64BE=J((function(t,e=0){return P(this,t,e,-BigInt("0x8000000000000000"),BigInt("0x7fffffffffffffff"))})),f.prototype.writeFloatLE=function(t,e,r){return D(this,t,e,!0,r)},f.prototype.writeFloatBE=function(t,e,r){return D(this,t,e,!1,r)},f.prototype.writeDoubleLE=function(t,e,r){return C(this,t,e,!0,r)},f.prototype.writeDoubleBE=function(t,e,r){return C(this,t,e,!1,r)},f.prototype.copy=function(t,e,r,n){if(!f.isBuffer(t))throw new TypeError("argument should be a Buffer");if(r||(r=0),n||0===n||(n=this.length),e>=t.length&&(e=t.length),e||(e=0),n>0&&n<r&&(n=r),n===r)return 0;if(0===t.length||0===this.length)return 0;if(e<0)throw new RangeError("targetStart out of bounds");if(r<0||r>=this.length)throw new RangeError("Index out of range");if(n<0)throw new RangeError("sourceEnd out of bounds");n>this.length&&(n=this.length),t.length-e<n-r&&(n=t.length-e+r);const o=n-r;return this===t&&"function"==typeof Uint8Array.prototype.copyWithin?this.copyWithin(e,r,n):Uint8Array.prototype.set.call(t,this.subarray(r,n),e),o},f.prototype.fill=function(t,e,r,n){if("string"==typeof t){if("string"==typeof e?(n=e,e=0,r=this.length):"string"==typeof r&&(n=r,r=this.length),void 0!==n&&"string"!=typeof n)throw new TypeError("encoding must be a string");if("string"==typeof n&&!f.isEncoding(n))throw new TypeError("Unknown encoding: "+n);if(1===t.length){const e=t.charCodeAt(0);("utf8"===n&&e<128||"latin1"===n)&&(t=e)}}else"number"==typeof t?t&=255:"boolean"==typeof t&&(t=Number(t));if(e<0||this.length<e||this.length<r)throw new RangeError("Out of range index");if(r<=e)return this;let o;if(e>>>=0,r=void 0===r?this.length:r>>>0,t||(t=0),"number"==typeof t)for(o=e;o<r;++o)this[o]=t;else{const i=f.isBuffer(t)?t:f.from(t,n),s=i.length;if(0===s)throw new TypeError('The value "'+t+'" is invalid for argument "value"');for(o=0;o<r-e;++o)this[o+e]=i[o%s]}return this};const N={};function F(t,e,r){N[t]=class extends r{constructor(){super(),Object.defineProperty(this,"message",{value:e.apply(this,arguments),writable:!0,configurable:!0}),this.name=`${this.name} [${t}]`,this.stack,delete this.name}get code(){return t}set code(t){Object.defineProperty(this,"code",{configurable:!0,enumerable:!0,value:t,writable:!0})}toString(){return`${this.name} [${t}]: ${this.message}`}}}function V(t){let e="",r=t.length;const n="-"===t[0]?1:0;for(;r>=n+4;r-=3)e=`_${t.slice(r-3,r)}${e}`;return`${t.slice(0,r)}${e}`}function j(t,e,r,n,o,i){if(t>r||t<e){const n="bigint"==typeof e?"n":"";let o;throw o=i>3?0===e||e===BigInt(0)?`>= 0${n} and < 2${n} ** ${8*(i+1)}${n}`:`>= -(2${n} ** ${8*(i+1)-1}${n}) and < 2 ** ${8*(i+1)-1}${n}`:`>= ${e}${n} and <= ${r}${n}`,new N.ERR_OUT_OF_RANGE("value",o,t)}!function(t,e,r){X(e,"offset"),void 0!==t[e]&&void 0!==t[e+r]||z(e,t.length-(r+1))}(n,o,i)}function X(t,e){if("number"!=typeof t)throw new N.ERR_INVALID_ARG_TYPE(e,"number",t)}function z(t,e,r){if(Math.floor(t)!==t)throw X(t,r),new N.ERR_OUT_OF_RANGE(r||"offset","an integer",t);if(e<0)throw new N.ERR_BUFFER_OUT_OF_BOUNDS;throw new N.ERR_OUT_OF_RANGE(r||"offset",`>= ${r?1:0} and <= ${e}`,t)}F("ERR_BUFFER_OUT_OF_BOUNDS",(function(t){return t?`${t} is outside of buffer bounds`:"Attempt to access memory outside buffer bounds"}),RangeError),F("ERR_INVALID_ARG_TYPE",(function(t,e){return`The "${t}" argument must be of type number. Received type ${typeof e}`}),TypeError),F("ERR_OUT_OF_RANGE",(function(t,e,r){let n=`The value of "${t}" is out of range.`,o=r;return Number.isInteger(r)&&Math.abs(r)>2**32?o=V(String(r)):"bigint"==typeof r&&(o=String(r),(r>BigInt(2)**BigInt(32)||r<-(BigInt(2)**BigInt(32)))&&(o=V(o)),o+="n"),n+=` It must be ${e}. Received ${o}`,n}),RangeError);const q=/[^+/0-9A-Za-z-_]/g;function Z(t,e){let r;e=e||1/0;const n=t.length;let o=null;const i=[];for(let s=0;s<n;++s){if(r=t.charCodeAt(s),r>55295&&r<57344){if(!o){if(r>56319){(e-=3)>-1&&i.push(239,191,189);continue}if(s+1===n){(e-=3)>-1&&i.push(239,191,189);continue}o=r;continue}if(r<56320){(e-=3)>-1&&i.push(239,191,189),o=r;continue}r=65536+(o-55296<<10|r-56320)}else o&&(e-=3)>-1&&i.push(239,191,189);if(o=null,r<128){if((e-=1)<0)break;i.push(r)}else if(r<2048){if((e-=2)<0)break;i.push(r>>6|192,63&r|128)}else if(r<65536){if((e-=3)<0)break;i.push(r>>12|224,r>>6&63|128,63&r|128)}else{if(!(r<1114112))throw new Error("Invalid code point");if((e-=4)<0)break;i.push(r>>18|240,r>>12&63|128,r>>6&63|128,63&r|128)}}return i}function G(t){return n.toByteArray(function(t){if((t=(t=t.split("=")[0]).trim().replace(q,"")).length<2)return"";for(;t.length%4!=0;)t+="=";return t}(t))}function Y(t,e,r,n){let o;for(o=0;o<n&&!(o+r>=e.length||o>=t.length);++o)e[o+r]=t[o];return o}function W(t,e){return t instanceof e||null!=t&&null!=t.constructor&&null!=t.constructor.name&&t.constructor.name===e.name}function K(t){return t!=t}const H=function(){const t="0123456789abcdef",e=new Array(256);for(let r=0;r<16;++r){const n=16*r;for(let o=0;o<16;++o)e[n+o]=t[r]+t[o]}return e}();function J(t){return"undefined"==typeof BigInt?Q:t}function Q(){throw new Error("BigInt not supported")}},251(t,e){e.read=function(t,e,r,n,o){var i,s,u=8*o-n-1,f=(1<<u)-1,a=f>>1,h=-7,l=r?o-1:0,c=r?-1:1,p=t[e+l];for(l+=c,i=p&(1<<-h)-1,p>>=-h,h+=u;h>0;i=256*i+t[e+l],l+=c,h-=8);for(s=i&(1<<-h)-1,i>>=-h,h+=n;h>0;s=256*s+t[e+l],l+=c,h-=8);if(0===i)i=1-a;else{if(i===f)return s?NaN:1/0*(p?-1:1);s+=Math.pow(2,n),i-=a}return(p?-1:1)*s*Math.pow(2,i-n)},e.write=function(t,e,r,n,o,i){var s,u,f,a=8*i-o-1,h=(1<<a)-1,l=h>>1,c=23===o?Math.pow(2,-24)-Math.pow(2,-77):0,p=n?0:i-1,g=n?1:-1,y=e<0||0===e&&1/e<0?1:0;for(e=Math.abs(e),isNaN(e)||e===1/0?(u=isNaN(e)?1:0,s=h):(s=Math.floor(Math.log(e)/Math.LN2),e*(f=Math.pow(2,-s))<1&&(s--,f*=2),(e+=s+l>=1?c/f:c*Math.pow(2,1-l))*f>=2&&(s++,f/=2),s+l>=h?(u=0,s=h):s+l>=1?(u=(e*f-1)*Math.pow(2,o),s+=l):(u=e*Math.pow(2,l-1)*Math.pow(2,o),s=0));o>=8;t[r+p]=255&u,p+=g,u/=256,o-=8);for(s=s<<o|u,a+=o;a>0;t[r+p]=255&s,p+=g,s/=256,a-=8);t[r+p-g]|=128*y}}},u={};function f(t){var e=u[t];if(void 0!==e)return e.exports;var r=u[t]={exports:{}};return s[t](r,r.exports,f),r.exports}f.d=(t,e)=>{for(var r in e)f.o(e,r)&&!f.o(t,r)&&Object.defineProperty(t,r,{enumerable:!0,get:e[r]})},f.o=(t,e)=>Object.prototype.hasOwnProperty.call(t,e);var a=f(287);function h(t,e){const r=t[e];return"function"==typeof r?r.call(t):r}function l(t){if(!t||"object"!=typeof t)return;const e=t;return"function"==typeof e.switch?e.switch().name:e.type}function c(t){return function(t){const e=t;return a.hp.from("value"in e?e.value:e)}(h(t,"bytes"))}const p=["Soroswap","Aquarius","Phoenix","Sushi","CometDex"],g={Soroswap:0,Aquarius:1,Phoenix:2,Sushi:3,CometDex:4},y=1,d=1e6,w=5,m=6,b=0,E=1,I=2,A=128,B=48,v=32,S=256,O=A-I;class R{assets=[];amounts=[];ops=[];weights=[];constructor(t){this.amounts.push(t)}asset(t){const e=this.assets.indexOf(t);if(-1!==e)return e;if(this.assets.length>=S)throw new Error("Stellar builder: strategy references more than 256 distinct addresses");return this.assets.push(t),this.assets.length-1}amount(t){if(this.amounts.length>=O)throw new Error("Stellar builder: strategy references too many distinct amounts");return this.amounts.push(t),this.amounts.length-1}weight(t){if(this.weights.length>=v)throw new Error("Stellar builder: strategy uses more than 32 split weights");if(!Number.isInteger(t)||t<=0||t>d)throw new Error(`Stellar builder: split weight ${t} outside 1..=${d}`);return this.weights.push(t),this.weights.length-1}emit(t,e,r,n,o){this.ops.push([t,e,r,n,o])}emitPath(t,e){t.hops.forEach(((r,n)=>{if(r.tokenIn===r.tokenOut)throw new Error("Stellar builder: hop swaps a token for itself");const o=t.hops[n-1];if(o&&r.tokenIn!==o.tokenOut)throw new Error("Stellar builder: hop does not chain onto its predecessor's output");this.emit(g[r.venue],0===n?e:E,this.asset(r.pool),this.asset(r.tokenIn),this.asset(r.tokenOut))}))}lowerPaths(t){const e=t.filter((t=>t.hops.length>0)),r=Array.from({length:e.length},(()=>!1));for(let t=0;t<e.length;t+=1){if(r[t])continue;const n=e[t].hops[0]?.tokenIn,o=[];for(let r=t;r<e.length;r+=1)e[r].hops[0]?.tokenIn===n&&o.push(r);const i=o.reduce(((t,r)=>t+e[r].splitPpm),0);if(i>d)throw new Error(`Stellar builder: split weights for one token sum to ${i}, above ${d}`);const s=i===d;let u=d;o.forEach(((t,n)=>{r[t]=!0;const i=e[t];let f;if(n+1===o.length&&s)f=b;else{if(0===u)throw new Error("Stellar builder: split weights exhaust the group before its last path");const t=Math.floor(i.splitPpm*d/u);u-=Math.min(i.splitPpm,u),f=A+this.weight(t)}this.emitPath(i,f)}))}}toBytes(t,e,r){if(0===this.ops.length)throw new Error("Stellar builder: strategy lowered to zero instructions");if(this.ops.length>B)throw new Error(`Stellar builder: strategy has ${this.ops.length} instructions, the router accepts ${B}`);const n=[y,t,e,0,r>>>24&255,r>>>16&255,r>>>8&255,255&r,this.ops.length,this.weights.length];for(const t of this.ops)n.push(...t);for(const t of this.weights)n.push(t>>>16&255,t>>>8&255,255&t);return a.hp.from(n)}get assetList(){return this.assets}get amountList(){return this.amounts}}const U=r=>i.ScVal.scvBytes(a.hp.from((r=>{const n=new R(r.totalMinOut),o=n.asset(r.tokenIn),s=n.asset(r.tokenOut);if(o===s)throw new Error("Stellar builder: `tokenIn` and `tokenOut` are the same asset");if(r.burnPool){const t=n.asset(r.burnPool),e=n.amountList.length;for(const t of r.burnMinAmounts??[])n.amount(t);n.emit(w,b,t,o,e)}if(n.lowerPaths(r.paths),r.mintPool){const t=r.preSwapAmount;if(t&&BigInt(t)>0n){const e=r.mintPoolTokens;if(!e||2!==e.length)throw new Error("Stellar builder: `preSwapAmount` needs `mintPoolTokens` to name the pool’s two constituents");const[o,i]=e,[s,u]=r.preSwapFromA?[o,i]:[i,o];n.emit(g.Aquarius,I+n.amount(t),n.asset(r.mintPool),n.asset(s),n.asset(u))}n.emit(m,b,n.asset(r.mintPool),s,n.amount(r.mintMinShares??"1"))}const u=Number(r.referralId??0);if(!Number.isInteger(u)||u<0||u>4294967295)throw new Error(`Stellar builder: referral id ${r.referralId} does not fit the wire’s u32`);return(t=>{const e=Object.keys(t).sort().map((e=>{return new i.ScMapEntry({key:(r=e,i.ScVal.scvSymbol(r)),val:t[e]});var r}));return i.ScVal.scvMap(e)})({amounts:i.ScVal.scvVec(n.amountList.map((t=>new e(t).toI128()))),assets:i.ScVal.scvVec(n.assetList.map((e=>(e=>new t(e).toScVal())(e)))),ops:i.ScVal.scvBytes(n.toBytes(o,s,u))})})(r).toXDR("base64"),"base64")),k=t=>{const e=a.hp.from(t);if(0===e.length)throw new Error("Stellar builder: strategy swap bytes must be non-empty base64 routeXdr, 0x hex string, or Uint8Array");return i.ScVal.scvBytes(e)},$=()=>i.ScVal.scvBytes(a.hp.alloc(0)),M=t=>{const e=t.trim();if(e.startsWith("0x")){const t=e.slice(2);if(!((r=t).length>0&&r.length%2==0&&/^[0-9a-fA-F]+$/.test(r)))throw new Error("Stellar builder: strategy swap bytes hex string must be 0x-prefixed and even-length");return a.hp.from(t,"hex")}var r;if(!/^[A-Za-z0-9+/]+={0,2}$/.test(e))throw new Error("Stellar builder: strategy swap bytes must be base64 routeXdr or 0x-prefixed hex");const n=a.hp.from(e,"base64");if(0===n.length)throw new Error("Stellar builder: strategy swap bytes must be non-empty base64 routeXdr, 0x hex string, or Uint8Array");return n},L=10,T=5,x=3,P=L+T*B+x*v,_=16384;class D extends Error{code;constructor(t,e){super(`Stellar route verification failed [${t}]: ${e}`),this.name="StellarRouteVerificationError",this.code=t}}const C=(t,e)=>{throw new D(t,e)},N=t=>{const e="string"==typeof t?t:t&&"object"==typeof t&&"routeXdr"in t?t.routeXdr:void 0;if("string"==typeof e&&e.length>2*_)return C("OVERSIZED",`encoded route has ${e.length} characters`);try{return c((t=>{if("string"==typeof t)return k(M(t));if(t instanceof Uint8Array)return 0===t.length?$():k(t);if(t&&"object"==typeof t)return"routeXdr"in(e=t)&&"string"==typeof e.routeXdr?k(M(t.routeXdr)):(t=>"swapXdr"in t&&"string"==typeof t.swapXdr)(t)?k(M(t.swapXdr)):(t=>"bytes"in t&&("string"==typeof t.bytes||t.bytes instanceof Uint8Array))(t)?"string"==typeof t.bytes?k(M(t.bytes)):0===t.bytes.length?$():k(t.bytes):U((t=>{if(!t||"object"!=typeof t)throw new Error("Stellar builder: decoded strategy `steps` must be a StrategyPayload ({ paths, tokenIn, tokenOut, totalMinOut })");const e=t;if(!Array.isArray(e.paths)||0===e.paths.length&&!e.burnPool&&!e.mintPool)throw new Error("Stellar builder: `steps.paths` needs a strategy path or a liquidity burn/mint operation");if("string"!=typeof e.tokenIn)throw new Error("Stellar builder: `steps.tokenIn` must be a contract address");if("string"!=typeof e.tokenOut)throw new Error("Stellar builder: `steps.tokenOut` must be a contract address");if("string"!=typeof e.totalMinOut)throw new Error("Stellar builder: `steps.totalMinOut` must be an i128 decimal string");const r=new Map;for(const[t,n]of e.paths.entries()){if(!n||"number"!=typeof n.splitPpm||n.splitPpm<=0||!Array.isArray(n.hops)||0===n.hops.length)throw new Error(`Stellar builder: \`steps.paths[${t}]\` must have splitPpm > 0 and a non-empty hops array`);for(const[e,r]of n.hops.entries())if(!r||"string"!=typeof r.pool||"string"!=typeof r.tokenIn||"string"!=typeof r.tokenOut||!p.includes(r.venue))throw new Error(`Stellar builder: \`steps.paths[${t}].hops[${e}]\` must have pool, tokenIn, tokenOut, and a valid Soroban venue`);const e=n.hops[0];r.set(e.tokenIn,(r.get(e.tokenIn)??0)+n.splitPpm)}for(const[t,n]of r){if(n>d)throw new Error(`Stellar builder: \`steps.paths[].splitPpm\` for ${t} sums to ${n}, above ${d}`);if(!e.mintPool&&n!==d)throw new Error(`Stellar builder: \`steps.paths[].splitPpm\` for ${t} must sum to ${d}, got ${n}`)}return e})(t));var e;throw new Error("Stellar builder: `steps` must be opaque strategy bytes (`routeXdr`, base64/hex string, or Uint8Array)")})(t))}catch(t){return C("MALFORMED",t instanceof Error?t.message:String(t))}},F=t=>{let e;try{e=i.ScVal.fromXDR(t)}catch(t){return C("MALFORMED",`payload is not one XDR ScVal: ${t instanceof Error?t.message:String(t)}`)}if("scvMap"!==l(e))return C("MALFORMED","payload must be a StrategyPayload map");const r=h(e,"map")??[];if("amounts,assets,ops"!==r.map((t=>"scvSymbol"===l(h(t,"key"))?h(h(t,"key"),"sym").toString():"")).join(","))return C("MALFORMED","payload fields must be exactly amounts, assets, ops");const[n,o,s]=r.map((t=>h(t,"val")));return"scvVec"!==l(n)||"scvVec"!==l(o)||"scvBytes"!==l(s)?C("MALFORMED","payload field has the wrong type"):{amounts:h(n,"vec")??[],assets:h(o,"vec")??[],ops:c(s)}};function V(e){const r=N(e);0===r.length&&C("MALFORMED","route is empty"),r.length>_&&C("OVERSIZED",`route has ${r.length} bytes, above ${_}`);const n=F(r),i=n.assets.length,s=n.amounts.length;0===i&&C("MALFORMED","asset registry is empty"),(i>S||s>O)&&C("OVERSIZED",`registries hold ${i} assets and ${s} amounts`);const u=n.assets.map(((e,r)=>"scvAddress"!==l(e)?C("MALFORMED",`assets[${r}] is not an address`):t.fromScAddress(h(e,"address")).toString())),f=n.amounts.map(((t,e)=>"scvI128"!==l(t)?C("MALFORMED",`amounts[${e}] is not an i128`):o(t))),a=n.ops;a.length<L&&C("MALFORMED","program header is truncated"),a.length>P&&C("OVERSIZED",`program has ${a.length} bytes, above ${P}`);const c=t=>{const e=a[t];return void 0===e?C("MALFORMED",`program byte ${t} is missing`):e},g=c(0);g!==y&&C("UNSUPPORTED_VERSION",`program version ${g}, expected ${y}`);const R=c(8),U=c(9);0===R&&C("INVALID_STRUCTURE","program has no instructions"),(R>B||U>v)&&C("OVERSIZED",`program declares ${R} instructions and ${U} weights`);const k=L+T*R;a.length!==k+x*U&&C("MALFORMED","program length does not match its instruction and weight counts");const $=c(1),M=c(2),D=c(3);($>=i||M>=i||D>=s)&&C("MALFORMED","header index is outside its registry"),$===M&&C("INVALID_STRUCTURE","token_in equals token_out");const V=a.readUInt32BE(4),j=[];for(let t=0;t<U;t+=1){const e=a.readUIntBE(k+x*t,x);(0===e||e>d)&&C("INVALID_STRUCTURE",`split weight ${e} outside 1..=${d}`),j.push(e)}const X=t=>u[t]??C("MALFORMED",`asset index ${t} is outside the registry`),z=t=>f[t]??C("MALFORMED",`amount index ${t} is outside the registry`),q=[];let Z;for(let t=0;t<R;t+=1){const e=L+T*t,r=c(e),n=c(e+1),o=c(e+2),i=c(e+3),u=c(e+4);let f;if(r>m&&C("UNKNOWN_OPCODE",`instruction ${t} has opcode ${r}`),n===b)f={kind:"all"};else if(n===E)void 0!==Z&&Z===i||C("INVALID_STRUCTURE",`instruction ${t} does not chain onto its predecessor`),f={kind:"prev"};else if(n>=A){const e=j[n-A];void 0===e&&C("MALFORMED",`instruction ${t} weight index is out of range`),f={kind:"ppm",ppm:e}}else f={kind:"fixed",amount:z(n-I)};const a=X(o);r!==w&&r!==m?(i===u&&C("INVALID_STRUCTURE",`instruction ${t} swaps a token for itself`),q.push({kind:"swap",venue:p[r],mode:f,pool:a,tokenIn:X(i),tokenOut:X(u)}),Z=u):("all"!==f.kind&&C("MALFORMED",`liquidity instruction ${t} must use mode All`),u>=s&&C("MALFORMED",`instruction ${t} amount index is out of range`),q.push({kind:r===w?"burn":"mint",pool:a,shareToken:X(i),amountIndex:u}),Z=r===m?i:void 0)}const G=z(D);return G<=0n&&C("MIN_OUT_TOO_LOW",`encoded total_min_out is ${G}`),{version:g,tokenIn:X($),tokenOut:X(M),totalMinOut:G,referralId:V,assets:u,amounts:f,ops:q,weights:j}}function j(e){try{const{envelopeXdr:i,networkPassphrase:s,routerAddress:u,viewer:f,operationIndex:a}=e;if(!s||!r.isValidContract(u)||new t(f).toString()!==f||"string"!=typeof i||i.length>1048576||i.length%4!=0||!/^[A-Za-z0-9+/]+={0,2}$/.test(i)||void 0!==a&&(!Number.isSafeInteger(a)||a<0))return null;const p=n.fromXDR(i,s),g="innerTransaction"in p?p.innerTransaction:p;if(void 0!==a&&a>=g.operations.length)return null;let y=null;for(const[e,n]of g.operations.entries()){if(void 0!==a&&e!==a)continue;if("invokeHostFunction"!==n.type)continue;const i=n.func;if("hostFunctionTypeInvokeContract"!==l(i))continue;const s=h(i,"invokeContract");if(t.fromScAddress(h(s,"contractAddress")).toString()!==u||"execute_strategy"!==h(s,"functionName").toString())continue;const p=h(s,"args"),[g,d,w]=p;if(3!==p.length||!g||!d||!w||"scvAddress"!==l(g)||"scvI128"!==l(d)||"scvBytes"!==l(w))return null;if(t.fromScAddress(h(g,"address")).toString()!==f)continue;const m=o(d);if(m<=0n)return null;const b=V(c(w));if(b.tokenIn===b.tokenOut||!r.isValidContract(b.tokenIn)||!r.isValidContract(b.tokenOut))return null;if(y)return null;y={tokenIn:b.tokenIn,tokenOut:b.tokenOut,amountInAtoms:m.toString(),operationIndex:e}}return y}catch{return null}}export{j as decodeStellarSwapEnvelope};
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import { Buffer } from 'buffer';
|
|
2
|
+
type FieldValue<T> = T extends (...args: never[]) => infer R ? R : T;
|
|
3
|
+
/** SDK 16 exposes XDR getters; SDK 17 exposes the same fields as properties. */
|
|
4
|
+
export declare function xdrField<T, K extends keyof T>(value: T, key: K): FieldValue<T[K]>;
|
|
5
|
+
export declare function xdrType(value: unknown): string | undefined;
|
|
6
|
+
/** SDK 17 opaque byte fields wrap their Uint8Array in `value`. */
|
|
7
|
+
export declare function xdrBytes(value: {
|
|
8
|
+
bytes: unknown;
|
|
9
|
+
}): Buffer;
|
|
10
|
+
export declare function xdrOpaque(value: unknown): Buffer;
|
|
11
|
+
export {};
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@xoxno/sdk-js",
|
|
3
|
-
"version": "1.0.
|
|
3
|
+
"version": "1.0.225",
|
|
4
4
|
"description": "The SDK to interact with the XOXNO Protocol!",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"exports": {
|
|
@@ -23,6 +23,16 @@
|
|
|
23
23
|
"types": "./dist/cjs/sdk/stellar/index.d.ts",
|
|
24
24
|
"default": "./dist/sdk/stellar/index.cjs"
|
|
25
25
|
}
|
|
26
|
+
},
|
|
27
|
+
"./stellar-swap": {
|
|
28
|
+
"import": {
|
|
29
|
+
"types": "./dist/sdk/stellar/swap-index.d.ts",
|
|
30
|
+
"default": "./dist/sdk/stellar/swap-index.esm.js"
|
|
31
|
+
},
|
|
32
|
+
"require": {
|
|
33
|
+
"types": "./dist/cjs/sdk/stellar/swap-index.d.ts",
|
|
34
|
+
"default": "./dist/sdk/stellar/swap-index.cjs"
|
|
35
|
+
}
|
|
26
36
|
}
|
|
27
37
|
},
|
|
28
38
|
"types": "./dist/index.d.ts",
|
|
@@ -36,10 +46,10 @@
|
|
|
36
46
|
"test": "node --experimental-vm-modules node_modules/jest/bin/jest.js",
|
|
37
47
|
"build:sdk": "npx bun run src/sdk/parseSwagger.ts --offline && npx oxlint src/sdk/swagger.ts --fix && npx bun run md/extract.ts",
|
|
38
48
|
"build:types": "tsc --emitDeclarationOnly && node scripts/emit-cjs-dts.mjs",
|
|
39
|
-
"build:esm": "webpack --config webpack-esm.config.mjs",
|
|
49
|
+
"build:esm": "swc src -d dist/esm --strip-leading-paths --config-file swc-esm.json -C jsc.baseUrl=$PWD/src && node scripts/emit-esm-entries.mjs && webpack --config webpack-esm.config.mjs",
|
|
40
50
|
"build:cjs": "webpack --config webpack-cjs.config.mjs",
|
|
41
51
|
"build": "npm run build:sdk && npm run build:types && npm run build:esm && npm run build:cjs",
|
|
42
|
-
"verify:dist": "node -e \"const m=require('./dist/index.cjs'); if(typeof m.decodeStellarLendingEvent!=='function')throw new Error('CJS require broken'); console.log('CJS ok')\" && node --input-type=module -e \"import('./dist/index.esm.js').then(m=>{if(typeof m.decodeStellarLendingEvent!=='function')throw new Error('ESM import broken'); console.log('ESM ok')})\"",
|
|
52
|
+
"verify:dist": "node -e \"const m=require('./dist/index.cjs'); if(typeof m.decodeStellarLendingEvent!=='function')throw new Error('CJS require broken'); console.log('CJS ok')\" && node --input-type=module -e \"import('./dist/index.esm.js').then(m=>{if(typeof m.decodeStellarLendingEvent!=='function')throw new Error('ESM import broken'); console.log('ESM ok')})\" && npm run test:swap",
|
|
43
53
|
"prepublishOnly": "npm run verify:dist",
|
|
44
54
|
"lint": "oxlint src",
|
|
45
55
|
"format": "oxlint src --fix",
|
|
@@ -49,7 +59,8 @@
|
|
|
49
59
|
"update:sdk": "bun run src/sdk/parseSwagger.ts && bun run md/extract.ts",
|
|
50
60
|
"docs:stellar": "typedoc --options typedoc.stellar.json",
|
|
51
61
|
"check:examples": "tsc --project tsconfig.examples.json",
|
|
52
|
-
"test:browser": "node --experimental-vm-modules scripts/check-stellar-browser.mjs"
|
|
62
|
+
"test:browser": "node --experimental-vm-modules scripts/check-stellar-browser.mjs",
|
|
63
|
+
"test:swap": "node scripts/check-stellar-swap.mjs"
|
|
53
64
|
},
|
|
54
65
|
"config": {
|
|
55
66
|
"commitizen": {
|
|
@@ -122,6 +133,6 @@
|
|
|
122
133
|
"buffer": "^6.0.3"
|
|
123
134
|
},
|
|
124
135
|
"peerDependencies": {
|
|
125
|
-
"@stellar/stellar-sdk": ">=15.0.0 <
|
|
136
|
+
"@stellar/stellar-sdk": ">=15.0.0 <18.0.0"
|
|
126
137
|
}
|
|
127
138
|
}
|
|
File without changes
|