@xoxno/sdk-js 1.0.217 → 1.0.218

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.
@@ -1,2 +1,2 @@
1
1
  /*! For license information please see index.esm.js.LICENSE.txt */
2
- "undefined"!=typeof globalThis&&void 0===globalThis.self&&(globalThis.self=globalThis);import{Account as t,Address as e,BASE_FEE as r,Contract as o,ScInt as n,TransactionBuilder as i,scValToNative as s,xdr as a}from"@stellar/stellar-sdk";var u={526(t,e){e.byteLength=function(t){var e=a(t),r=e[0],o=e[1];return 3*(r+o)/4-o},e.toByteArray=function(t){var e,r,i=a(t),s=i[0],u=i[1],l=new n(function(t,e,r){return 3*(e+r)/4-r}(0,s,u)),c=0,f=u>0?s-4:s;for(r=0;r<f;r+=4)e=o[t.charCodeAt(r)]<<18|o[t.charCodeAt(r+1)]<<12|o[t.charCodeAt(r+2)]<<6|o[t.charCodeAt(r+3)],l[c++]=e>>16&255,l[c++]=e>>8&255,l[c++]=255&e;return 2===u&&(e=o[t.charCodeAt(r)]<<2|o[t.charCodeAt(r+1)]>>4,l[c++]=255&e),1===u&&(e=o[t.charCodeAt(r)]<<10|o[t.charCodeAt(r+1)]<<4|o[t.charCodeAt(r+2)]>>2,l[c++]=e>>8&255,l[c++]=255&e),l},e.fromByteArray=function(t){for(var e,o=t.length,n=o%3,i=[],s=16383,a=0,u=o-n;a<u;a+=s)i.push(l(t,a,a+s>u?u:a+s));return 1===n?(e=t[o-1],i.push(r[e>>2]+r[e<<4&63]+"==")):2===n&&(e=(t[o-2]<<8)+t[o-1],i.push(r[e>>10]+r[e>>4&63]+r[e<<2&63]+"=")),i.join("")};for(var r=[],o=[],n="undefined"!=typeof Uint8Array?Uint8Array:Array,i="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/",s=0;s<64;++s)r[s]=i[s],o[i.charCodeAt(s)]=s;function a(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 u(t){return r[t>>18&63]+r[t>>12&63]+r[t>>6&63]+r[63&t]}function l(t,e,r){for(var o,n=[],i=e;i<r;i+=3)o=(t[i]<<16&16711680)+(t[i+1]<<8&65280)+(255&t[i+2]),n.push(u(o));return n.join("")}o["-".charCodeAt(0)]=62,o["_".charCodeAt(0)]=63},287(t,e,r){const o=r(526),n=r(251),i="function"==typeof Symbol&&"function"==typeof Symbol.for?Symbol.for("nodejs.util.inspect.custom"):null;e.hp=u,e.IS=50;const s=2147483647;function a(t){if(t>s)throw new RangeError('The value "'+t+'" is invalid for option "size"');const e=new Uint8Array(t);return Object.setPrototypeOf(e,u.prototype),e}function u(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 f(t)}return l(t,e,r)}function l(t,e,r){if("string"==typeof t)return function(t,e){if("string"==typeof e&&""!==e||(e="utf8"),!u.isEncoding(e))throw new TypeError("Unknown encoding: "+e);const r=0|m(t,e);let o=a(r);const n=o.write(t,e);return n!==r&&(o=o.slice(0,n)),o}(t,e);if(ArrayBuffer.isView(t))return function(t){if(K(t,Uint8Array)){const e=new Uint8Array(t);return h(e.buffer,e.byteOffset,e.byteLength)}return p(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(K(t,ArrayBuffer)||t&&K(t.buffer,ArrayBuffer))return h(t,e,r);if("undefined"!=typeof SharedArrayBuffer&&(K(t,SharedArrayBuffer)||t&&K(t.buffer,SharedArrayBuffer)))return h(t,e,r);if("number"==typeof t)throw new TypeError('The "value" argument must not be of type number. Received type number');const o=t.valueOf&&t.valueOf();if(null!=o&&o!==t)return u.from(o,e,r);const n=function(t){if(u.isBuffer(t)){const e=0|d(t.length),r=a(e);return 0===r.length||t.copy(r,0,0,e),r}return void 0!==t.length?"number"!=typeof t.length||J(t.length)?a(0):p(t):"Buffer"===t.type&&Array.isArray(t.data)?p(t.data):void 0}(t);if(n)return n;if("undefined"!=typeof Symbol&&null!=Symbol.toPrimitive&&"function"==typeof t[Symbol.toPrimitive])return u.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 c(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 f(t){return c(t),a(t<0?0:0|d(t))}function p(t){const e=t.length<0?0:0|d(t.length),r=a(e);for(let o=0;o<e;o+=1)r[o]=255&t[o];return r}function h(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 o;return o=void 0===e&&void 0===r?new Uint8Array(t):void 0===r?new Uint8Array(t,e):new Uint8Array(t,e,r),Object.setPrototypeOf(o,u.prototype),o}function d(t){if(t>=s)throw new RangeError("Attempt to allocate Buffer larger than maximum size: 0x"+s.toString(16)+" bytes");return 0|t}function m(t,e){if(u.isBuffer(t))return t.length;if(ArrayBuffer.isView(t)||K(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,o=arguments.length>2&&!0===arguments[2];if(!o&&0===r)return 0;let n=!1;for(;;)switch(e){case"ascii":case"latin1":case"binary":return r;case"utf8":case"utf-8":return j(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(n)return o?-1:j(t).length;e=(""+e).toLowerCase(),n=!0}}function g(t,e,r){let o=!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 R(this,e,r);case"utf8":case"utf-8":return E(this,e,r);case"ascii":return A(this,e,r);case"latin1":case"binary":return T(this,e,r);case"base64":return k(this,e,r);case"ucs2":case"ucs-2":case"utf16le":case"utf-16le":return x(this,e,r);default:if(o)throw new TypeError("Unknown encoding: "+t);t=(t+"").toLowerCase(),o=!0}}function y(t,e,r){const o=t[e];t[e]=t[r],t[r]=o}function w(t,e,r,o,n){if(0===t.length)return-1;if("string"==typeof r?(o=r,r=0):r>2147483647?r=2147483647:r<-2147483648&&(r=-2147483648),J(r=+r)&&(r=n?0:t.length-1),r<0&&(r=t.length+r),r>=t.length){if(n)return-1;r=t.length-1}else if(r<0){if(!n)return-1;r=0}if("string"==typeof e&&(e=u.from(e,o)),u.isBuffer(e))return 0===e.length?-1:b(t,e,r,o,n);if("number"==typeof e)return e&=255,"function"==typeof Uint8Array.prototype.indexOf?n?Uint8Array.prototype.indexOf.call(t,e,r):Uint8Array.prototype.lastIndexOf.call(t,e,r):b(t,[e],r,o,n);throw new TypeError("val must be string, number or Buffer")}function b(t,e,r,o,n){let i,s=1,a=t.length,u=e.length;if(void 0!==o&&("ucs2"===(o=String(o).toLowerCase())||"ucs-2"===o||"utf16le"===o||"utf-16le"===o)){if(t.length<2||e.length<2)return-1;s=2,a/=2,u/=2,r/=2}function l(t,e){return 1===s?t[e]:t.readUInt16BE(e*s)}if(n){let o=-1;for(i=r;i<a;i++)if(l(t,i)===l(e,-1===o?0:i-o)){if(-1===o&&(o=i),i-o+1===u)return o*s}else-1!==o&&(i-=i-o),o=-1}else for(r+u>a&&(r=a-u),i=r;i>=0;i--){let r=!0;for(let o=0;o<u;o++)if(l(t,i+o)!==l(e,o)){r=!1;break}if(r)return i}return-1}function _(t,e,r,o){r=Number(r)||0;const n=t.length-r;o?(o=Number(o))>n&&(o=n):o=n;const i=e.length;let s;for(o>i/2&&(o=i/2),s=0;s<o;++s){const o=parseInt(e.substr(2*s,2),16);if(J(o))return s;t[r+s]=o}return s}function v(t,e,r,o){return H(j(e,t.length-r),t,r,o)}function S(t,e,r,o){return H(function(t){const e=[];for(let r=0;r<t.length;++r)e.push(255&t.charCodeAt(r));return e}(e),t,r,o)}function q(t,e,r,o){return H(G(e),t,r,o)}function I(t,e,r,o){return H(function(t,e){let r,o,n;const i=[];for(let s=0;s<t.length&&!((e-=2)<0);++s)r=t.charCodeAt(s),o=r>>8,n=r%256,i.push(n),i.push(o);return i}(e,t.length-r),t,r,o)}function k(t,e,r){return 0===e&&r===t.length?o.fromByteArray(t):o.fromByteArray(t.slice(e,r))}function E(t,e,r){r=Math.min(t.length,r);const o=[];let n=e;for(;n<r;){const e=t[n];let i=null,s=e>239?4:e>223?3:e>191?2:1;if(n+s<=r){let r,o,a,u;switch(s){case 1:e<128&&(i=e);break;case 2:r=t[n+1],128==(192&r)&&(u=(31&e)<<6|63&r,u>127&&(i=u));break;case 3:r=t[n+1],o=t[n+2],128==(192&r)&&128==(192&o)&&(u=(15&e)<<12|(63&r)<<6|63&o,u>2047&&(u<55296||u>57343)&&(i=u));break;case 4:r=t[n+1],o=t[n+2],a=t[n+3],128==(192&r)&&128==(192&o)&&128==(192&a)&&(u=(15&e)<<18|(63&r)<<12|(63&o)<<6|63&a,u>65535&&u<1114112&&(i=u))}}null===i?(i=65533,s=1):i>65535&&(i-=65536,o.push(i>>>10&1023|55296),i=56320|1023&i),o.push(i),n+=s}return function(t){const e=t.length;if(e<=B)return String.fromCharCode.apply(String,t);let r="",o=0;for(;o<e;)r+=String.fromCharCode.apply(String,t.slice(o,o+=B));return r}(o)}u.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}}(),u.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(u.prototype,"parent",{enumerable:!0,get:function(){if(u.isBuffer(this))return this.buffer}}),Object.defineProperty(u.prototype,"offset",{enumerable:!0,get:function(){if(u.isBuffer(this))return this.byteOffset}}),u.poolSize=8192,u.from=function(t,e,r){return l(t,e,r)},Object.setPrototypeOf(u.prototype,Uint8Array.prototype),Object.setPrototypeOf(u,Uint8Array),u.alloc=function(t,e,r){return function(t,e,r){return c(t),t<=0?a(t):void 0!==e?"string"==typeof r?a(t).fill(e,r):a(t).fill(e):a(t)}(t,e,r)},u.allocUnsafe=function(t){return f(t)},u.allocUnsafeSlow=function(t){return f(t)},u.isBuffer=function(t){return null!=t&&!0===t._isBuffer&&t!==u.prototype},u.compare=function(t,e){if(K(t,Uint8Array)&&(t=u.from(t,t.offset,t.byteLength)),K(e,Uint8Array)&&(e=u.from(e,e.offset,e.byteLength)),!u.isBuffer(t)||!u.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,o=e.length;for(let n=0,i=Math.min(r,o);n<i;++n)if(t[n]!==e[n]){r=t[n],o=e[n];break}return r<o?-1:o<r?1:0},u.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}},u.concat=function(t,e){if(!Array.isArray(t))throw new TypeError('"list" argument must be an Array of Buffers');if(0===t.length)return u.alloc(0);let r;if(void 0===e)for(e=0,r=0;r<t.length;++r)e+=t[r].length;const o=u.allocUnsafe(e);let n=0;for(r=0;r<t.length;++r){let e=t[r];if(K(e,Uint8Array))n+e.length>o.length?(u.isBuffer(e)||(e=u.from(e)),e.copy(o,n)):Uint8Array.prototype.set.call(o,e,n);else{if(!u.isBuffer(e))throw new TypeError('"list" argument must be an Array of Buffers');e.copy(o,n)}n+=e.length}return o},u.byteLength=m,u.prototype._isBuffer=!0,u.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)y(this,e,e+1);return this},u.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)y(this,e,e+3),y(this,e+1,e+2);return this},u.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)y(this,e,e+7),y(this,e+1,e+6),y(this,e+2,e+5),y(this,e+3,e+4);return this},u.prototype.toString=function(){const t=this.length;return 0===t?"":0===arguments.length?E(this,0,t):g.apply(this,arguments)},u.prototype.toLocaleString=u.prototype.toString,u.prototype.equals=function(t){if(!u.isBuffer(t))throw new TypeError("Argument must be a Buffer");return this===t||0===u.compare(this,t)},u.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&&(u.prototype[i]=u.prototype.inspect),u.prototype.compare=function(t,e,r,o,n){if(K(t,Uint8Array)&&(t=u.from(t,t.offset,t.byteLength)),!u.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===o&&(o=0),void 0===n&&(n=this.length),e<0||r>t.length||o<0||n>this.length)throw new RangeError("out of range index");if(o>=n&&e>=r)return 0;if(o>=n)return-1;if(e>=r)return 1;if(this===t)return 0;let i=(n>>>=0)-(o>>>=0),s=(r>>>=0)-(e>>>=0);const a=Math.min(i,s),l=this.slice(o,n),c=t.slice(e,r);for(let t=0;t<a;++t)if(l[t]!==c[t]){i=l[t],s=c[t];break}return i<s?-1:s<i?1:0},u.prototype.includes=function(t,e,r){return-1!==this.indexOf(t,e,r)},u.prototype.indexOf=function(t,e,r){return w(this,t,e,r,!0)},u.prototype.lastIndexOf=function(t,e,r){return w(this,t,e,r,!1)},u.prototype.write=function(t,e,r,o){if(void 0===e)o="utf8",r=this.length,e=0;else if(void 0===r&&"string"==typeof e)o=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===o&&(o="utf8")):(o=r,r=void 0)}const n=this.length-e;if((void 0===r||r>n)&&(r=n),t.length>0&&(r<0||e<0)||e>this.length)throw new RangeError("Attempt to write outside buffer bounds");o||(o="utf8");let i=!1;for(;;)switch(o){case"hex":return _(this,t,e,r);case"utf8":case"utf-8":return v(this,t,e,r);case"ascii":case"latin1":case"binary":return S(this,t,e,r);case"base64":return q(this,t,e,r);case"ucs2":case"ucs-2":case"utf16le":case"utf-16le":return I(this,t,e,r);default:if(i)throw new TypeError("Unknown encoding: "+o);o=(""+o).toLowerCase(),i=!0}},u.prototype.toJSON=function(){return{type:"Buffer",data:Array.prototype.slice.call(this._arr||this,0)}};const B=4096;function A(t,e,r){let o="";r=Math.min(t.length,r);for(let n=e;n<r;++n)o+=String.fromCharCode(127&t[n]);return o}function T(t,e,r){let o="";r=Math.min(t.length,r);for(let n=e;n<r;++n)o+=String.fromCharCode(t[n]);return o}function R(t,e,r){const o=t.length;(!e||e<0)&&(e=0),(!r||r<0||r>o)&&(r=o);let n="";for(let o=e;o<r;++o)n+=Y[t[o]];return n}function x(t,e,r){const o=t.slice(e,r);let n="";for(let t=0;t<o.length-1;t+=2)n+=String.fromCharCode(o[t]+256*o[t+1]);return n}function U(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,e,r,o,n,i){if(!u.isBuffer(t))throw new TypeError('"buffer" argument must be a Buffer instance');if(e>n||e<i)throw new RangeError('"value" argument is out of bounds');if(r+o>t.length)throw new RangeError("Index out of range")}function O(t,e,r,o,n){F(e,o,n,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,o,n){F(e,o,n,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 C(t,e,r,o,n,i){if(r+o>t.length)throw new RangeError("Index out of range");if(r<0)throw new RangeError("Index out of range")}function N(t,e,r,o,i){return e=+e,r>>>=0,i||C(t,0,r,4),n.write(t,e,r,o,23,4),r+4}function M(t,e,r,o,i){return e=+e,r>>>=0,i||C(t,0,r,8),n.write(t,e,r,o,52,8),r+8}u.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 o=this.subarray(t,e);return Object.setPrototypeOf(o,u.prototype),o},u.prototype.readUintLE=u.prototype.readUIntLE=function(t,e,r){t>>>=0,e>>>=0,r||U(t,e,this.length);let o=this[t],n=1,i=0;for(;++i<e&&(n*=256);)o+=this[t+i]*n;return o},u.prototype.readUintBE=u.prototype.readUIntBE=function(t,e,r){t>>>=0,e>>>=0,r||U(t,e,this.length);let o=this[t+--e],n=1;for(;e>0&&(n*=256);)o+=this[t+--e]*n;return o},u.prototype.readUint8=u.prototype.readUInt8=function(t,e){return t>>>=0,e||U(t,1,this.length),this[t]},u.prototype.readUint16LE=u.prototype.readUInt16LE=function(t,e){return t>>>=0,e||U(t,2,this.length),this[t]|this[t+1]<<8},u.prototype.readUint16BE=u.prototype.readUInt16BE=function(t,e){return t>>>=0,e||U(t,2,this.length),this[t]<<8|this[t+1]},u.prototype.readUint32LE=u.prototype.readUInt32LE=function(t,e){return t>>>=0,e||U(t,4,this.length),(this[t]|this[t+1]<<8|this[t+2]<<16)+16777216*this[t+3]},u.prototype.readUint32BE=u.prototype.readUInt32BE=function(t,e){return t>>>=0,e||U(t,4,this.length),16777216*this[t]+(this[t+1]<<16|this[t+2]<<8|this[t+3])},u.prototype.readBigUInt64LE=Z((function(t){z(t>>>=0,"offset");const e=this[t],r=this[t+7];void 0!==e&&void 0!==r||V(t,this.length-8);const o=e+256*this[++t]+65536*this[++t]+this[++t]*2**24,n=this[++t]+256*this[++t]+65536*this[++t]+r*2**24;return BigInt(o)+(BigInt(n)<<BigInt(32))})),u.prototype.readBigUInt64BE=Z((function(t){z(t>>>=0,"offset");const e=this[t],r=this[t+7];void 0!==e&&void 0!==r||V(t,this.length-8);const o=e*2**24+65536*this[++t]+256*this[++t]+this[++t],n=this[++t]*2**24+65536*this[++t]+256*this[++t]+r;return(BigInt(o)<<BigInt(32))+BigInt(n)})),u.prototype.readIntLE=function(t,e,r){t>>>=0,e>>>=0,r||U(t,e,this.length);let o=this[t],n=1,i=0;for(;++i<e&&(n*=256);)o+=this[t+i]*n;return n*=128,o>=n&&(o-=Math.pow(2,8*e)),o},u.prototype.readIntBE=function(t,e,r){t>>>=0,e>>>=0,r||U(t,e,this.length);let o=e,n=1,i=this[t+--o];for(;o>0&&(n*=256);)i+=this[t+--o]*n;return n*=128,i>=n&&(i-=Math.pow(2,8*e)),i},u.prototype.readInt8=function(t,e){return t>>>=0,e||U(t,1,this.length),128&this[t]?-1*(255-this[t]+1):this[t]},u.prototype.readInt16LE=function(t,e){t>>>=0,e||U(t,2,this.length);const r=this[t]|this[t+1]<<8;return 32768&r?4294901760|r:r},u.prototype.readInt16BE=function(t,e){t>>>=0,e||U(t,2,this.length);const r=this[t+1]|this[t]<<8;return 32768&r?4294901760|r:r},u.prototype.readInt32LE=function(t,e){return t>>>=0,e||U(t,4,this.length),this[t]|this[t+1]<<8|this[t+2]<<16|this[t+3]<<24},u.prototype.readInt32BE=function(t,e){return t>>>=0,e||U(t,4,this.length),this[t]<<24|this[t+1]<<16|this[t+2]<<8|this[t+3]},u.prototype.readBigInt64LE=Z((function(t){z(t>>>=0,"offset");const e=this[t],r=this[t+7];void 0!==e&&void 0!==r||V(t,this.length-8);const o=this[t+4]+256*this[t+5]+65536*this[t+6]+(r<<24);return(BigInt(o)<<BigInt(32))+BigInt(e+256*this[++t]+65536*this[++t]+this[++t]*2**24)})),u.prototype.readBigInt64BE=Z((function(t){z(t>>>=0,"offset");const e=this[t],r=this[t+7];void 0!==e&&void 0!==r||V(t,this.length-8);const o=(e<<24)+65536*this[++t]+256*this[++t]+this[++t];return(BigInt(o)<<BigInt(32))+BigInt(this[++t]*2**24+65536*this[++t]+256*this[++t]+r)})),u.prototype.readFloatLE=function(t,e){return t>>>=0,e||U(t,4,this.length),n.read(this,t,!0,23,4)},u.prototype.readFloatBE=function(t,e){return t>>>=0,e||U(t,4,this.length),n.read(this,t,!1,23,4)},u.prototype.readDoubleLE=function(t,e){return t>>>=0,e||U(t,8,this.length),n.read(this,t,!0,52,8)},u.prototype.readDoubleBE=function(t,e){return t>>>=0,e||U(t,8,this.length),n.read(this,t,!1,52,8)},u.prototype.writeUintLE=u.prototype.writeUIntLE=function(t,e,r,o){t=+t,e>>>=0,r>>>=0,o||$(this,t,e,r,Math.pow(2,8*r)-1,0);let n=1,i=0;for(this[e]=255&t;++i<r&&(n*=256);)this[e+i]=t/n&255;return e+r},u.prototype.writeUintBE=u.prototype.writeUIntBE=function(t,e,r,o){t=+t,e>>>=0,r>>>=0,o||$(this,t,e,r,Math.pow(2,8*r)-1,0);let n=r-1,i=1;for(this[e+n]=255&t;--n>=0&&(i*=256);)this[e+n]=t/i&255;return e+r},u.prototype.writeUint8=u.prototype.writeUInt8=function(t,e,r){return t=+t,e>>>=0,r||$(this,t,e,1,255,0),this[e]=255&t,e+1},u.prototype.writeUint16LE=u.prototype.writeUInt16LE=function(t,e,r){return t=+t,e>>>=0,r||$(this,t,e,2,65535,0),this[e]=255&t,this[e+1]=t>>>8,e+2},u.prototype.writeUint16BE=u.prototype.writeUInt16BE=function(t,e,r){return t=+t,e>>>=0,r||$(this,t,e,2,65535,0),this[e]=t>>>8,this[e+1]=255&t,e+2},u.prototype.writeUint32LE=u.prototype.writeUInt32LE=function(t,e,r){return t=+t,e>>>=0,r||$(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},u.prototype.writeUint32BE=u.prototype.writeUInt32BE=function(t,e,r){return t=+t,e>>>=0,r||$(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},u.prototype.writeBigUInt64LE=Z((function(t,e=0){return O(this,t,e,BigInt(0),BigInt("0xffffffffffffffff"))})),u.prototype.writeBigUInt64BE=Z((function(t,e=0){return P(this,t,e,BigInt(0),BigInt("0xffffffffffffffff"))})),u.prototype.writeIntLE=function(t,e,r,o){if(t=+t,e>>>=0,!o){const o=Math.pow(2,8*r-1);$(this,t,e,r,o-1,-o)}let n=0,i=1,s=0;for(this[e]=255&t;++n<r&&(i*=256);)t<0&&0===s&&0!==this[e+n-1]&&(s=1),this[e+n]=(t/i|0)-s&255;return e+r},u.prototype.writeIntBE=function(t,e,r,o){if(t=+t,e>>>=0,!o){const o=Math.pow(2,8*r-1);$(this,t,e,r,o-1,-o)}let n=r-1,i=1,s=0;for(this[e+n]=255&t;--n>=0&&(i*=256);)t<0&&0===s&&0!==this[e+n+1]&&(s=1),this[e+n]=(t/i|0)-s&255;return e+r},u.prototype.writeInt8=function(t,e,r){return t=+t,e>>>=0,r||$(this,t,e,1,127,-128),t<0&&(t=255+t+1),this[e]=255&t,e+1},u.prototype.writeInt16LE=function(t,e,r){return t=+t,e>>>=0,r||$(this,t,e,2,32767,-32768),this[e]=255&t,this[e+1]=t>>>8,e+2},u.prototype.writeInt16BE=function(t,e,r){return t=+t,e>>>=0,r||$(this,t,e,2,32767,-32768),this[e]=t>>>8,this[e+1]=255&t,e+2},u.prototype.writeInt32LE=function(t,e,r){return t=+t,e>>>=0,r||$(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},u.prototype.writeInt32BE=function(t,e,r){return t=+t,e>>>=0,r||$(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},u.prototype.writeBigInt64LE=Z((function(t,e=0){return O(this,t,e,-BigInt("0x8000000000000000"),BigInt("0x7fffffffffffffff"))})),u.prototype.writeBigInt64BE=Z((function(t,e=0){return P(this,t,e,-BigInt("0x8000000000000000"),BigInt("0x7fffffffffffffff"))})),u.prototype.writeFloatLE=function(t,e,r){return N(this,t,e,!0,r)},u.prototype.writeFloatBE=function(t,e,r){return N(this,t,e,!1,r)},u.prototype.writeDoubleLE=function(t,e,r){return M(this,t,e,!0,r)},u.prototype.writeDoubleBE=function(t,e,r){return M(this,t,e,!1,r)},u.prototype.copy=function(t,e,r,o){if(!u.isBuffer(t))throw new TypeError("argument should be a Buffer");if(r||(r=0),o||0===o||(o=this.length),e>=t.length&&(e=t.length),e||(e=0),o>0&&o<r&&(o=r),o===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(o<0)throw new RangeError("sourceEnd out of bounds");o>this.length&&(o=this.length),t.length-e<o-r&&(o=t.length-e+r);const n=o-r;return this===t&&"function"==typeof Uint8Array.prototype.copyWithin?this.copyWithin(e,r,o):Uint8Array.prototype.set.call(t,this.subarray(r,o),e),n},u.prototype.fill=function(t,e,r,o){if("string"==typeof t){if("string"==typeof e?(o=e,e=0,r=this.length):"string"==typeof r&&(o=r,r=this.length),void 0!==o&&"string"!=typeof o)throw new TypeError("encoding must be a string");if("string"==typeof o&&!u.isEncoding(o))throw new TypeError("Unknown encoding: "+o);if(1===t.length){const e=t.charCodeAt(0);("utf8"===o&&e<128||"latin1"===o)&&(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 n;if(e>>>=0,r=void 0===r?this.length:r>>>0,t||(t=0),"number"==typeof t)for(n=e;n<r;++n)this[n]=t;else{const i=u.isBuffer(t)?t:u.from(t,o),s=i.length;if(0===s)throw new TypeError('The value "'+t+'" is invalid for argument "value"');for(n=0;n<r-e;++n)this[n+e]=i[n%s]}return this};const W={};function L(t,e,r){W[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 D(t){let e="",r=t.length;const o="-"===t[0]?1:0;for(;r>=o+4;r-=3)e=`_${t.slice(r-3,r)}${e}`;return`${t.slice(0,r)}${e}`}function F(t,e,r,o,n,i){if(t>r||t<e){const o="bigint"==typeof e?"n":"";let n;throw n=i>3?0===e||e===BigInt(0)?`>= 0${o} and < 2${o} ** ${8*(i+1)}${o}`:`>= -(2${o} ** ${8*(i+1)-1}${o}) and < 2 ** ${8*(i+1)-1}${o}`:`>= ${e}${o} and <= ${r}${o}`,new W.ERR_OUT_OF_RANGE("value",n,t)}!function(t,e,r){z(e,"offset"),void 0!==t[e]&&void 0!==t[e+r]||V(e,t.length-(r+1))}(o,n,i)}function z(t,e){if("number"!=typeof t)throw new W.ERR_INVALID_ARG_TYPE(e,"number",t)}function V(t,e,r){if(Math.floor(t)!==t)throw z(t,r),new W.ERR_OUT_OF_RANGE(r||"offset","an integer",t);if(e<0)throw new W.ERR_BUFFER_OUT_OF_BOUNDS;throw new W.ERR_OUT_OF_RANGE(r||"offset",`>= ${r?1:0} and <= ${e}`,t)}L("ERR_BUFFER_OUT_OF_BOUNDS",(function(t){return t?`${t} is outside of buffer bounds`:"Attempt to access memory outside buffer bounds"}),RangeError),L("ERR_INVALID_ARG_TYPE",(function(t,e){return`The "${t}" argument must be of type number. Received type ${typeof e}`}),TypeError),L("ERR_OUT_OF_RANGE",(function(t,e,r){let o=`The value of "${t}" is out of range.`,n=r;return Number.isInteger(r)&&Math.abs(r)>2**32?n=D(String(r)):"bigint"==typeof r&&(n=String(r),(r>BigInt(2)**BigInt(32)||r<-(BigInt(2)**BigInt(32)))&&(n=D(n)),n+="n"),o+=` It must be ${e}. Received ${n}`,o}),RangeError);const X=/[^+/0-9A-Za-z-_]/g;function j(t,e){let r;e=e||1/0;const o=t.length;let n=null;const i=[];for(let s=0;s<o;++s){if(r=t.charCodeAt(s),r>55295&&r<57344){if(!n){if(r>56319){(e-=3)>-1&&i.push(239,191,189);continue}if(s+1===o){(e-=3)>-1&&i.push(239,191,189);continue}n=r;continue}if(r<56320){(e-=3)>-1&&i.push(239,191,189),n=r;continue}r=65536+(n-55296<<10|r-56320)}else n&&(e-=3)>-1&&i.push(239,191,189);if(n=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 o.toByteArray(function(t){if((t=(t=t.split("=")[0]).trim().replace(X,"")).length<2)return"";for(;t.length%4!=0;)t+="=";return t}(t))}function H(t,e,r,o){let n;for(n=0;n<o&&!(n+r>=e.length||n>=t.length);++n)e[n+r]=t[n];return n}function K(t,e){return t instanceof e||null!=t&&null!=t.constructor&&null!=t.constructor.name&&t.constructor.name===e.name}function J(t){return t!=t}const Y=function(){const t="0123456789abcdef",e=new Array(256);for(let r=0;r<16;++r){const o=16*r;for(let n=0;n<16;++n)e[o+n]=t[r]+t[n]}return e}();function Z(t){return"undefined"==typeof BigInt?Q:t}function Q(){throw new Error("BigInt not supported")}},251(t,e){e.read=function(t,e,r,o,n){var i,s,a=8*n-o-1,u=(1<<a)-1,l=u>>1,c=-7,f=r?n-1:0,p=r?-1:1,h=t[e+f];for(f+=p,i=h&(1<<-c)-1,h>>=-c,c+=a;c>0;i=256*i+t[e+f],f+=p,c-=8);for(s=i&(1<<-c)-1,i>>=-c,c+=o;c>0;s=256*s+t[e+f],f+=p,c-=8);if(0===i)i=1-l;else{if(i===u)return s?NaN:1/0*(h?-1:1);s+=Math.pow(2,o),i-=l}return(h?-1:1)*s*Math.pow(2,i-o)},e.write=function(t,e,r,o,n,i){var s,a,u,l=8*i-n-1,c=(1<<l)-1,f=c>>1,p=23===n?Math.pow(2,-24)-Math.pow(2,-77):0,h=o?0:i-1,d=o?1:-1,m=e<0||0===e&&1/e<0?1:0;for(e=Math.abs(e),isNaN(e)||e===1/0?(a=isNaN(e)?1:0,s=c):(s=Math.floor(Math.log(e)/Math.LN2),e*(u=Math.pow(2,-s))<1&&(s--,u*=2),(e+=s+f>=1?p/u:p*Math.pow(2,1-f))*u>=2&&(s++,u/=2),s+f>=c?(a=0,s=c):s+f>=1?(a=(e*u-1)*Math.pow(2,n),s+=f):(a=e*Math.pow(2,f-1)*Math.pow(2,n),s=0));n>=8;t[r+h]=255&a,h+=d,a/=256,n-=8);for(s=s<<n|a,l+=n;l>0;t[r+h]=255&s,h+=d,s/=256,l-=8);t[r+h-d]|=128*m}},387(t,e,r){r.d(e,{GW:()=>i});var o,n=r(564);!function(t){t.MAINNET="1",t.DEVNET="D"}(o||(o={}));class i{apiUrl;chain;init;config;constructor(t){if(!t?.apiUrl?.trim())throw new Error("XOXNOClient: apiUrl is required");const{chain:e=o.MAINNET,apiUrl:r,...i}=t;this.apiUrl=r.trim().replace(/\/$/,""),this.chain=e,this.init=i,this.config=e==o.MAINNET?{mediaUrl:"https://media.xoxno.com",gatewayUrl:"https://gateway.xoxno.com",XO_SC:n.s0,FM_SC:n.ZZ,DR_SC:n.sM,KG_SC:n.KL,Staking_SC:n.V,Manager_SC:n.Rh,P2P_SC:n.EP}:{mediaUrl:"https://devnet-media.xoxno.com",gatewayUrl:"https://devnet-gateway.xoxno.com",XO_SC:n.cM,FM_SC:n.ZZ,DR_SC:n.sM,KG_SC:n.KL,Staking_SC:n.J6,Manager_SC:n.Ff,P2P_SC:n.gx}}fetchWithTimeout=async(t,{params:e,...r}={})=>{const{next:o,cache:n,debug:i,timeout:s,...a}=this.init,{next:u,cache:l,debug:c,timeout:f,headers:p,method:h="GET",...d}=r,m=p?.Authorization,g="Bearer undefined"===m?void 0:m,y="GET"!==h&&"HEAD"!==h&&"PUT"!==h,w={...p,Referer:"https://xoxno.sdk","User-Agent":"XOXNO/1.0/SDK",...y?{"Content-Type":"application/json"}:{},...g?{Authorization:g}:{}},b=Object.entries(e??{}).filter((([,t])=>void 0!==t)).flatMap((([t,e])=>Array.isArray(e)?e.filter((t=>void 0!==t)).map((e=>`${t}=${encodeURIComponent(e)}`)):`${t}=${encodeURIComponent(e)}`)).join("&"),_=`${this.apiUrl}${t}${b.length?`?${b}`:""}`,{revalidate:v,...S}=o??{},{revalidate:q,...I}=u??{},k="GET"!==h||g?void 0:q??v,E="GET"!==h||g||k?void 0:l??n,B=d.body,A=f??s??(null==B?3e4:0),T=A>0?AbortSignal.timeout(A):void 0,R=d.signal??a.signal,x=T&&R?AbortSignal.any([R,T]):T??R,U={...a,...d,method:h,...Object.keys(w).length?{headers:w}:{},...x?{signal:x}:{},cache:E,next:{...S,...I,revalidate:k}};(c??i)&&console.debug("SDK fetch: ",_,U);const $=await fetch(_,U).catch((t=>{if(t instanceof Error&&!t.message.match(/^http(s?):\/\//))throw Object.assign(new Error(`${_}: ${t.message}`),{cause:t});throw t})),O=await $.text();if(!$.ok){let t;try{t=JSON.parse(O)}catch{t={message:O}}const e=[_,$.status,$.statusText,t.message].filter(Boolean).join(";;");throw new Error(e)}try{return JSON.parse(O)}catch{return O}}}},564(t,e,r){r.d(e,{EP:()=>l,Ff:()=>p,J6:()=>f,KL:()=>s,Rh:()=>u,V:()=>a,ZZ:()=>n,cM:()=>c,gx:()=>h,s0:()=>o,sM:()=>i});const o="erd1qqqqqqqqqqqqqpgq6wegs2xkypfpync8mn2sa5cmpqjlvrhwz5nqgepyg8",n="erd1qqqqqqqqqqqqqpgq705fxpfrjne0tl3ece0rrspykq88mynn4kxs2cg43s",i="erd1qqqqqqqqqqqqqpgqd9rvv2n378e27jcts8vfwynpx0gfl5ufz6hqhfy0u0",s="erd1qqqqqqqqqqqqqpgq8xwzu82v8ex3h4ayl5lsvxqxnhecpwyvwe0sf2qj4e",a="erd1qqqqqqqqqqqqqpgqvpkd3g3uwludduv3797j54qt6c888wa59w2shntt6z",u="erd1qqqqqqqqqqqqqpgqg9fa0dmpn8fu3fnleeqn5zt8rl8mdqjkys5s2gtas7",l="erd1qqqqqqqqqqqqqpgq47y8hnct68v6asjv6gxem6h9rumn9frzah0skhxxt6",c="erd1qqqqqqqqqqqqqpgql0dnz6n5hpuw8cptlt00khd0nn4ja8eadsfq2xrqw4",f="erd1qqqqqqqqqqqqqpgqsc5hnewwpep8qq0d7kjjzrquapuucrygah0s85zres",p="erd1qqqqqqqqqqqqqpgqluclyhfsa2uw7q9cjwd8knk989hg57u8ah0slq2nlr",h="erd1qqqqqqqqqqqqqpgqfja7ukpngrun78ueq583l0vd6aj4ekhrah0sa9wyrv"}},l={};function c(t){var e=l[t];if(void 0!==e)return e.exports;var r=l[t]={exports:{}};return u[t](r,r.exports,c),r.exports}c.d=(t,e)=>{for(var r in e)c.o(e,r)&&!c.o(t,r)&&Object.defineProperty(t,r,{enumerable:!0,get:e[r]})},c.o=(t,e)=>Object.prototype.hasOwnProperty.call(t,e);var f=c(387);const p={stellarMainnet:{name:"mainnet",passphrase:"Public Global Stellar Network ; September 2015",horizonUrl:"https://horizon.stellar.org",sorobanRpcUrl:"https://stellar-gateway.xoxno.com",quoteUrl:"https://stellar-swap.xoxno.com",explorerNetwork:"public",aquariusApiUrl:"https://amm-api.aqua.network",aquariusRouter:"CBQDHNBFBZYE4MKPWBSJOPIYLW4SFSXAXUTSXJN76GNKYVYPCKWC6QUK",lendingController:"CAUCMIN5KSXEVZ7NMXR3LZATGD5EFIEUI5XWTFLYRO2R5OTXI22WE5JX",aggregatorRouter:"CCVENFSVCBYDHVOACFZXMNNYVOZ3LKXPZYU5LUI4N7KTXOKRVYD7F3TR",governance:"CC44PEQW7HSEPKAZ5ZRPH2JS5M5KVJXCUBLJ2ZX4E3WCDKMNFILHC2AD",priceAggregator:"CBGUF2G2Q7HCVCWYISDXBHPVBGMYNXA7PG2VET66YBZX6IKOOV27NSMV",positionNftContract:"CAWCSG77AY2W24QZ6ZXLHZU4UXEFHZBM6EI4A4IF7JB5CTY4XND3TI6C"},stellarTestnet:{name:"testnet",passphrase:"Test SDF Network ; September 2015",horizonUrl:"https://horizon-testnet.stellar.org",sorobanRpcUrl:"https://stellar-testnet-gateway.xoxno.com",quoteUrl:"https://testnet-stellar-swap.xoxno.com",explorerNetwork:"testnet",aquariusApiUrl:"https://amm-api-testnet.aqua.network",aquariusRouter:"CBCFTQSPDBAIZ6R6PJQKSQWKNKWH2QIV3I4J72SHWBIK3ADRRAM5A6GD",lendingController:"CCXRWJ6SIU2WPFEGLFGJVITPL57QAYIMIO6OAM2NBGNDQSSCK2FFV3F3",aggregatorRouter:"CDNTWMWW2WGYTKIZTJYNGNVQQZI4KTC5BQRZ3275KESRX5T4O3AYECL5",governance:"CDS33JDOYH3F3FL4QUQ6DV4WKHML2AKHF4LADTZ57FRUAEBTE7NMY5FQ",priceAggregator:"CAALOOTIDXCX7D7FMQIBSSAJLPKOM3GMXS4UUSTDIG42JCRRJHOPUHOP",positionNftContract:"CDVN5JU675MEDPVRPCYC45AHFC275UH57WEU5OTFE4WFGZBNN7HTLPSY"}},h=p;function d(t){return p["testnet"===t?"stellarTestnet":"stellarMainnet"]}const m={mainnet:p.stellarMainnet.passphrase,testnet:p.stellarTestnet.passphrase};var g=c(287);const y=["Soroswap","Aquarius","Phoenix","Sushi","CometDex"],w={Soroswap:0,Aquarius:1,Phoenix:2,Sushi:3,CometDex:4},b=1e6,_=t=>new e(t).toScVal(),v=t=>new n(t).toI128(),S=t=>a.ScVal.scvU32(t),q=t=>{if("number"==typeof t&&!Number.isSafeInteger(t))throw new Error("Stellar builder: u64 numbers must be safe integers; pass a decimal string for larger values");return new n("string"==typeof t?t:t.toString()).toU64()},I=t=>a.ScVal.scvBool(t),k=t=>a.ScVal.scvString(t),E=t=>a.ScVal.scvSymbol(t),B=()=>a.ScVal.scvVoid(),A=t=>a.ScVal.scvVec(t),T=(t,e=32)=>{const r=t.startsWith("0x")?t.slice(2):t,o=g.hp.from(r,"hex");if(o.length!==e)throw new Error(`Stellar builder: expected a ${e}-byte BytesN (got ${o.length} bytes from "${t}")`);return a.ScVal.scvBytes(o)},R=(t,e)=>null==t?B():e(t),x=(t,e)=>P({asset:_(e),hub_id:S(t)}),U=(t,e,r)=>a.ScVal.scvVec([x(t,e),v(r)]),$=t=>a.ScVal.scvVec(t.map((t=>U(t.hubId,t.asset,t.amount)))),O=t=>{if("Transfer"===t)return A([E("Transfer")]);if(t&&"object"==typeof t&&"Credit"in t){const e=t.Credit;if("number"==typeof e&&!Number.isInteger(e))throw new Error(`Stellar builder: SeizeMode Credit account id must be an integer u64, got ${e}`);return A([E("Credit"),q(e)])}throw new Error(`Stellar builder: SeizeMode must be 'Transfer' or { Credit: accountId }, got ${JSON.stringify(t)}`)},P=t=>{const e=Object.keys(t).sort().map((e=>new a.ScMapEntry({key:E(e),val:t[e]})));return a.ScVal.scvMap(e)};class C{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>=256)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>=126)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>=32)throw new Error("Stellar builder: strategy uses more than 32 split weights");if(!Number.isInteger(t)||t<=0||t>b)throw new Error(`Stellar builder: split weight ${t} outside 1..=1000000`);return this.weights.push(t),this.weights.length-1}emit(t,e,r,o,n){this.ops.push([t,e,r,o,n])}emitPath(t,e){t.hops.forEach(((r,o)=>{if(r.tokenIn===r.tokenOut)throw new Error("Stellar builder: hop swaps a token for itself");const n=t.hops[o-1];if(n&&r.tokenIn!==n.tokenOut)throw new Error("Stellar builder: hop does not chain onto its predecessor's output");this.emit(w[r.venue],0===o?e:1,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 o=e[t].hops[0]?.tokenIn,n=[];for(let r=t;r<e.length;r+=1)e[r].hops[0]?.tokenIn===o&&n.push(r);const i=n.reduce(((t,r)=>t+e[r].splitPpm),0);if(i>b)throw new Error(`Stellar builder: split weights for one token sum to ${i}, above 1000000`);const s=i===b;let a=b;n.forEach(((t,o)=>{r[t]=!0;const i=e[t];let u;if(o+1===n.length&&s)u=0;else{if(0===a)throw new Error("Stellar builder: split weights exhaust the group before its last path");const t=Math.floor(i.splitPpm*b/a);a-=Math.min(i.splitPpm,a),u=128+this.weight(t)}this.emitPath(i,u)}))}}toBytes(t,e,r){if(0===this.ops.length)throw new Error("Stellar builder: strategy lowered to zero instructions");if(this.ops.length>48)throw new Error(`Stellar builder: strategy has ${this.ops.length} instructions, the router accepts 48`);const o=[1,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)o.push(...t);for(const t of this.weights)o.push(t>>>16&255,t>>>8&255,255&t);return g.hp.from(o)}get assetList(){return this.assets}get amountList(){return this.amounts}}const N=t=>{const e=new C(t.totalMinOut),r=e.asset(t.tokenIn),o=e.asset(t.tokenOut);if(r===o)throw new Error("Stellar builder: `tokenIn` and `tokenOut` are the same asset");if(t.burnPool){const o=e.asset(t.burnPool),n=e.amountList.length;for(const r of t.burnMinAmounts??[])e.amount(r);e.emit(5,0,o,r,n)}if(e.lowerPaths(t.paths),t.mintPool){const r=t.preSwapAmount;if(r&&BigInt(r)>0n){const o=t.mintPoolTokens;if(!o||2!==o.length)throw new Error("Stellar builder: `preSwapAmount` needs `mintPoolTokens` to name the pool’s two constituents");const[n,i]=o,[s,a]=t.preSwapFromA?[n,i]:[i,n];e.emit(w.Aquarius,2+e.amount(r),e.asset(t.mintPool),e.asset(s),e.asset(a))}e.emit(6,0,e.asset(t.mintPool),o,e.amount(t.mintMinShares??"1"))}const n=Number(t.referralId??0);if(!Number.isInteger(n)||n<0||n>4294967295)throw new Error(`Stellar builder: referral id ${t.referralId} does not fit the wire’s u32`);return P({amounts:a.ScVal.scvVec(e.amountList.map((t=>v(t)))),assets:a.ScVal.scvVec(e.assetList.map((t=>_(t)))),ops:a.ScVal.scvBytes(e.toBytes(r,o,n))})},M=t=>{const e=g.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 a.ScVal.scvBytes(e)},W=()=>a.ScVal.scvBytes(g.hp.alloc(0)),L=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 g.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 o=g.hp.from(e,"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},D=t=>{if("string"==typeof t)return M(L(t));if(t instanceof Uint8Array)return 0===t.length?W():M(t);if(t&&"object"==typeof t)return"routeXdr"in(r=t)&&"string"==typeof r.routeXdr?M(L(t.routeXdr)):(t=>"swapXdr"in t&&"string"==typeof t.swapXdr)(t)?M(L(t.swapXdr)):(t=>"bytes"in t&&("string"==typeof t.bytes||t.bytes instanceof Uint8Array))(t)?"string"==typeof t.bytes?M(L(t.bytes)):0===t.bytes.length?W():M(t.bytes):(e=(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,o]of e.paths.entries()){if(!o||"number"!=typeof o.splitPpm||o.splitPpm<=0||!Array.isArray(o.hops)||0===o.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 o.hops.entries())if(!r||"string"!=typeof r.pool||"string"!=typeof r.tokenIn||"string"!=typeof r.tokenOut||!y.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=o.hops[0];r.set(e.tokenIn,(r.get(e.tokenIn)??0)+o.splitPpm)}for(const[t,o]of r){if(o>b)throw new Error(`Stellar builder: \`steps.paths[].splitPpm\` for ${t} sums to ${o}, above 1000000`);if(!e.mintPool&&o!==b)throw new Error(`Stellar builder: \`steps.paths[].splitPpm\` for ${t} must sum to 1000000, got ${o}`)}return e})(t),a.ScVal.scvBytes(g.hp.from(N(e).toXDR("base64"),"base64")));var e,r;throw new Error("Stellar builder: `steps` must be opaque strategy bytes (`routeXdr`, base64/hex string, or Uint8Array)")},F=t=>{if("string"==typeof t)return(t=>{const e=t.startsWith("0x")?t.slice(2):t,r=g.hp.from(e,"hex");return a.ScVal.scvBytes(r)})(t);if(t instanceof Uint8Array)return a.ScVal.scvBytes(g.hp.from(t));throw new Error("Stellar builder: `data` must be a hex string or Uint8Array (Soroban Bytes payload)")};function z(e,n,s){if(!e.controllerAddress)throw new Error("Stellar lending controllerAddress is required");const a=new o(e.controllerAddress),u=new t(e.caller,e.sourceSequence);return{xdr:new i(u,{fee:e.fee??r,networkPassphrase:m[e.network]}).addOperation(a.call(n,...s)).setTimeout(e.timeoutSeconds??300).build().toXDR()}}function V(t){if(!Number.isInteger(t)||t<1||t>4294967295)throw new Error("Stellar builder: spokeId must be an integer from 1 to 4294967295");return S(t)}function X(t,e){const r=e.accountNonce??0;return z(t,"supply",[_(t.caller),q(r),V(e.spokeId),$([...e.assets])])}function j(t,e){return X(t,{accountNonce:e.accountNonce,spokeId:e.spokeId,assets:[{hubId:e.hubId,asset:e.asset,amount:e.amount}]})}function G(t,e){return z(t,"borrow",[_(t.caller),q(e.accountNonce),$([...e.borrows]),R(e.to,_)])}function H(t,e){return G(t,{accountNonce:e.accountNonce,borrows:[{hubId:e.hubId,asset:e.asset,amount:e.amount}],to:e.to})}function K(t,e){return z(t,"withdraw",[_(t.caller),q(e.accountNonce),$([...e.withdrawals]),R(e.to,_)])}function J(t,e){return K(t,{accountNonce:e.accountNonce,withdrawals:[{hubId:e.hubId,asset:e.asset,amount:e.amount}],to:e.to})}function Y(t,e){return z(t,"repay",[_(t.caller),q(e.accountNonce),$([...e.payments])])}function Z(t,e){return Y(t,{accountNonce:e.accountNonce,payments:[{hubId:e.hubId,asset:e.asset,amount:e.amount}]})}function Q(t,e){return z(t,"liquidate",[_(t.caller),q(e.accountNonce),$([...e.debtPayments]),O(e.seizeMode??"Transfer")])}function tt(t){const e=s(a.ScVal.fromXDR(t,"base64"));if("bigint"==typeof e||"number"==typeof e)return e.toString();throw new Error("Stellar builder: liquidate return value must be a u64, got "+typeof e)}function et(t,e){return z(t,"flash_loan",[_(t.caller),x(e.hubId,e.asset),v(e.amount),_(e.receiver),F(e.data)])}function rt(t,e){return z(t,"migrate_from_blend",[_(t.caller),q(e.accountId),V(e.spokeId),S(e.hubId),_(e.blendPool),A(e.collateralTokens.map(_)),A(e.supplyTokens.map(_)),(r=e.debtCaps.map((t=>({token:t.token,amount:t.cap}))),a.ScVal.scvVec(r.map((t=>{return e=t.token,r=t.amount,a.ScVal.scvVec([_(e),v(r)]);var e,r}))))]);var r}function ot(t,e){const r=e.accountNonce??0;return z(t,"multiply",[_(t.caller),q(r),V(e.spokeId),x(e.collateral.hubId,e.collateral.asset),v(e.debtToFlashLoan),x(e.debt.hubId,e.debt.asset),S(e.mode),D(e.steps),R(e.initialPayment,(t=>U(t.hubId,t.asset,t.amount))),R(e.convertSwap,D)])}function nt(t,e){return z(t,"swap_debt",[_(t.caller),q(e.accountNonce),x(e.existingDebt.hubId,e.existingDebt.asset),v(e.newDebtAmount),x(e.newDebt.hubId,e.newDebt.asset),D(e.steps)])}function it(t,e){return z(t,"swap_collateral",[_(t.caller),q(e.accountNonce),x(e.current.hubId,e.current.asset),v(e.fromAmount),x(e.newCollateral.hubId,e.newCollateral.asset),D(e.steps)])}function st(t,e){return z(t,"repay_debt_with_collateral",[_(t.caller),q(e.accountNonce),x(e.collateral.hubId,e.collateral.asset),v(e.collateralAmount),x(e.debt.hubId,e.debt.asset),D(e.steps),I(e.closePosition)])}const at="/stellar-lending",ut=encodeURIComponent,lt=(t,e)=>t.fetchWithTimeout(`${at}/context`,e),ct=(t,e)=>t.fetchWithTimeout(`${at}/live-state`,e),ft=(t,e)=>t.fetchWithTimeout(`${at}/markets/detailed`,e),pt=(t,e)=>t.fetchWithTimeout(`${at}/assets`,e),ht=(t,e)=>t.fetchWithTimeout(`${at}/hubs`,e),dt=(t,e)=>t.fetchWithTimeout(`${at}/spokes`,e),mt=(t,e={},r)=>t.fetchWithTimeout(`${at}/reserves`,{...r,params:{...e}}),gt=(t,e,r,o,n)=>t.fetchWithTimeout(`${at}/reserves/${e}/${r}/${ut(o)}`,n),yt=(t,e,r)=>t.fetchWithTimeout(`${at}/assets/${ut(e)}`,r),wt=(t,e,r)=>t.fetchWithTimeout(`${at}/hubs/${e}`,r),bt=(t,e,r)=>t.fetchWithTimeout(`${at}/spokes/${e}`,r),_t=(t,e,r)=>t.fetchWithTimeout(`${at}/users/${ut(e)}/positions`,r),vt=(t,e,r)=>t.fetchWithTimeout(`${at}/accounts/${ut(e)}/positions`,r),St=(t,e,r,o)=>t.fetchWithTimeout(`${at}/users/${ut(e)}/assets/${ut(r)}/balance`,o),qt=(t,e,r,o)=>t.fetchWithTimeout(`${at}/assets/${ut(e)}/page`,{...o,params:{...r}}),It=(t,e,r,o)=>t.fetchWithTimeout(`${at}/assets/${ut(e)}/markets`,{...o,params:{side:r}}),kt=(t,e,r,o,n,i)=>t.fetchWithTimeout(`${at}/reserves/${e}/${r}/${ut(o)}/holders`,{...i,params:{side:n}}),Et=(t,e,r,o)=>t.fetchWithTimeout(`${at}/hubs/${e}/holders`,{...o,params:{side:r}}),Bt=(t,e,r,o)=>t.fetchWithTimeout(`${at}/spokes/${e}/holders`,{...o,params:{side:r}}),At=(t,e,r,o)=>t.fetchWithTimeout(`${at}/assets/${ut(e)}/graph`,{...o,params:{...r}}),Tt=(t,e,r,o)=>t.fetchWithTimeout(`${at}/hubs/${e}/graph`,{...o,params:{...r}}),Rt=(t,e,r,o)=>t.fetchWithTimeout(`${at}/spokes/${e}/graph`,{...o,params:{...r}}),xt=(t,e,r,o,n,i)=>t.fetchWithTimeout(`${at}/reserves/${e}/${r}/${ut(o)}/graph`,{...i,params:{...n}}),Ut=(t,e,r={},o)=>t.fetchWithTimeout(`${at}/users/${ut(e)}/activity`,{...o,params:{...r}}),$t=(t,e,r={},o)=>t.fetchWithTimeout(`${at}/users/${ut(e)}/activity/page`,{...o,params:{...r}}),Ot=(t,e={},r)=>t.fetchWithTimeout(`${at}/governance/proposals`,{...r,params:{...e}}),Pt=(t,e={},r)=>t.fetchWithTimeout(`${at}/positions`,{...r,params:{...e}}),Ct=(t,e={},r)=>t.fetchWithTimeout(`${at}/participants`,{...r,params:{...e}}),Nt=(t,e={},r)=>t.fetchWithTimeout(`${at}/liquidations/leaderboard`,{...r,params:{...e}}),Mt=(t,e={},r)=>t.fetchWithTimeout(`${at}/distribution`,{...r,params:{...e}}),Wt=(t,e={},r)=>t.fetchWithTimeout(`${at}/campaign/leaderboard`,{...r,params:{...e}}),Lt=(t,e,r)=>t.fetchWithTimeout(`${at}/stats/history`,{...r,params:{...e}}),Dt=(t,e,r)=>t.fetchWithTimeout(`${at}/revenue`,{...r,params:{...e}}),Ft=(t,e,r)=>t.fetchWithTimeout(`${at}/revenue/fees`,{...r,params:{...e}}),zt=(t,e,r)=>t.fetchWithTimeout(`${at}/liquidations`,{...r,params:{...e}}),Vt=(t,e,r)=>t.fetchWithTimeout(`${at}/volume`,{...r,params:{...e}}),Xt=(t,e,r)=>t.fetchWithTimeout(`${at}/active-users`,{...r,params:{...e}}),jt=(t,e,r)=>t.fetchWithTimeout(`${at}/rate-spread`,{...r,params:{...e}}),Gt=(t,e,r)=>t.fetchWithTimeout(`${at}/defillama`,{...r,params:{...e}}),Ht=(t,e,r,o)=>t.fetchWithTimeout(`${at}/users/${ut(e)}/history`,{...o,params:{...r}}),Kt=(t,e,r)=>t.fetchWithTimeout(`${at}/pnl`,{...r,params:{accountId:e}}),Jt=(t,e,r)=>t.fetchWithTimeout(`${at}/pnl/scope`,{...r,params:{scope:e}}),Yt=(t,e,r)=>t.fetchWithTimeout(`${at}/campaign/me`,{...r,params:{owner:e}}),Zt=t=>({context:e=>lt(t,e),liveState:e=>ct(t,e),marketsDetailed:e=>ft(t,e),assets:e=>pt(t,e),hubs:e=>ht(t,e),spokes:e=>dt(t,e),reserves:(e={},r)=>void 0!==r||"hubId"in e||"spokeId"in e||"asset"in e?mt(t,e,r):mt(t,{},e),reserve:(e,r,o,n)=>gt(t,e,r,o,n),asset:(e,r)=>yt(t,e,r),hub:(e,r)=>wt(t,e,r),spoke:(e,r)=>bt(t,e,r),userPositions:(e,r)=>_t(t,e,r),accountPositions:(e,r)=>vt(t,e,r),walletBalance:(e,r,o)=>St(t,e,r,o),assetPage:(e,r,o)=>qt(t,e,r,o),assetMarkets:(e,r,o)=>It(t,e,r,o),reserveHolders:(e,r,o,n,i)=>kt(t,e,r,o,n,i),hubHolders:(e,r,o)=>Et(t,e,r,o),spokeHolders:(e,r,o)=>Bt(t,e,r,o),assetGraph:(e,r,o)=>At(t,e,r,o),hubGraph:(e,r,o)=>Tt(t,e,r,o),spokeGraph:(e,r,o)=>Rt(t,e,r,o),reserveGraph:(e,r,o,n,i)=>xt(t,e,r,o,n,i),userActivity:(e,r={},o)=>Ut(t,e,r,o),userActivityPage:(e,r={},o)=>$t(t,e,r,o),governanceProposals:(e={},r)=>Ot(t,e,r),positionsLeaderboard:(e={},r)=>Pt(t,e,r),participants:(e={},r)=>Ct(t,e,r),liquidationsLeaderboard:(e={},r)=>Nt(t,e,r),distribution:(e={},r)=>Mt(t,e,r),campaignLeaderboard:(e={},r)=>Wt(t,e,r),statsHistory:(e,r)=>Lt(t,e,r),revenue:(e,r)=>Dt(t,e,r),feeRevenue:(e,r)=>Ft(t,e,r),liquidations:(e,r)=>zt(t,e,r),volume:(e,r)=>Vt(t,e,r),activeUsers:(e,r)=>Xt(t,e,r),rateSpread:(e,r)=>jt(t,e,r),defillama:(e,r)=>Gt(t,e,r),userHistory:(e,r,o)=>Ht(t,e,r,o),positionsPnl:(e,r)=>Kt(t,e,r),pnlByScope:(e,r)=>Jt(t,e,r),campaignMe:(e,r)=>Yt(t,e,r)}),Qt=t=>P({base_borrow_rate:v(t.baseBorrowRateRay),max_borrow_rate:v(t.maxBorrowRateRay),max_utilization:v(t.maxUtilizationRay),mid_utilization:v(t.midUtilizationRay),optimal_utilization:v(t.optimalUtilizationRay),reserve_factor:S(t.reserveFactorBps),slope1:v(t.slope1Ray),slope2:v(t.slope2Ray),slope3:v(t.slope3Ray)}),te=t=>P({asset_decimals:S(t.assetDecimals),asset_id:_(t.assetId),base_borrow_rate:v(t.baseBorrowRateRay),flashloan_fee:S(t.flashloanFeeBps),is_flashloanable:I(t.isFlashloanable),max_borrow_rate:v(t.maxBorrowRateRay),max_utilization:v(t.maxUtilizationRay),mid_utilization:v(t.midUtilizationRay),optimal_utilization:v(t.optimalUtilizationRay),reserve_factor:S(t.reserveFactorBps),slope1:v(t.slope1Ray),slope2:v(t.slope2Ray),slope3:v(t.slope3Ray)}),ee=t=>P({max_borrow_positions:S(t.maxBorrowPositions),max_supply_positions:S(t.maxSupplyPositions)}),re=t=>{if("Token"in t&&t.Token)return A([E("Token"),_(t.Token)]);if("Ref"in t&&t.Ref)return A([E("Ref"),E(t.Ref)]);throw new Error(`Stellar builder: PriceKey must be { Token } or { Ref }, got ${JSON.stringify(t)}`)},oe=t=>{if("Stellar"in t)return A([E("Stellar"),_(t.Stellar)]);if("Symbol"in t)return A([E("Symbol"),E(t.Symbol)]);if("String"in t)return A([E("String"),k(t.String)]);throw new Error(`Stellar builder: unknown OracleAssetRef ${JSON.stringify(t)}`)},ne=t=>{if("Spot"===t)return A([E("Spot")]);if(t&&"object"==typeof t&&"Twap"in t)return A([E("Twap"),S(Number(t.Twap))]);throw new Error(`Stellar builder: unknown OracleReadMode ${JSON.stringify(t)}`)},ie=t=>{if("Reflector"===t||"RedStone"===t||"Xoxno"===t)return A([E(t)]);throw new Error(`Stellar builder: unknown ProviderKind "${t}"`)},se=t=>{if("Market"===t||"Fundamental"===t)return A([E(t)]);throw new Error(`Stellar builder: unknown FeedNature "${t}"`)},ae=t=>{if("Reflector"in t){const e=t.Reflector;return A([E("Reflector"),P({asset:oe(e.asset),contract:_(e.contract),read_mode:ne(e.readMode)})])}if("MultiFeed"in t){const e=t.MultiFeed;return A([E("MultiFeed"),P({contract:_(e.contract),feed_id:k(e.feedId),kind:ie(e.kind),nature:se(e.nature)})])}throw new Error(`Stellar builder: unknown ProviderRef ${JSON.stringify(t)}`)},ue=t=>{const e=t;return P({decimals:S(e.decimals),max_stale_seconds:q(e.maxStaleSeconds),provider:ae(e.provider)})},le=t=>{if("RequireDisjoint"===t)return A([E("RequireDisjoint")]);if(t&&"object"==typeof t&&"AllowShared"in t){const e=t.AllowShared;return A([E("AllowShared"),A(e.map((t=>P({contract:_(t.contract),kind:ie(t.kind)}))))])}throw new Error(`Stellar builder: unknown IndependencePolicy ${JSON.stringify(t)}`)},ce=t=>{const e=t,r=e.sources??[];let o,n;if("number"==typeof e.toleranceBps)o=1e4+e.toleranceBps,n=Math.max(1,Math.floor(1e8/o));else{const t=e.tolerance??{};o=Number(t.upperRatioBps),n=Number(t.lowerRatioBps)}return P({asset_decimals:S(Number(e.assetDecimals)),independence:le(e.independence),max_price_stale_seconds:q(Number(e.maxPriceStaleSeconds)),max_sanity_price_wad:v(String(e.maxSanityPriceWad)),min_sanity_price_wad:v(String(e.minSanityPriceWad)),sources:A(r.map((t=>(t=>{if("Feed"in t)return A([E("Feed"),ue(t.Feed)]);if("Scaled"in t){const e=t.Scaled;return A([E("Scaled"),P({factor:ue(e.factor),max_factor_wad:v(e.maxFactorWad),min_factor_wad:v(e.minFactorWad),quote:re(e.quote)})])}if("LpShare"in t){const e=t.LpShare;return A([E("LpShare"),P({key_a:re(e.keyA),key_b:re(e.keyB),kind:A([E(e.kind||"ConstantProduct")]),pool:_(e.pool),reserve_a_decimals:S(e.reserveADecimals),reserve_b_decimals:S(e.reserveBDecimals),share_decimals:S(e.shareDecimals)})])}throw new Error(`Stellar builder: unknown PriceSource ${JSON.stringify(t)}`)})(t)))),tolerance:P({lower_ratio_bps:S(n),upper_ratio_bps:S(o)})})},fe=ce;function pe(t,e){return z(t,"upgrade",[T(e.wasmHash)])}function he(t,e){return z(t,"migrate",[S(e.newVersion)])}function de(t){return z(t,"pause",[])}function me(t){return z(t,"unpause",[])}function ge(t,e){return z(t,"grant_role",[_(e.account),E(e.role)])}function ye(t,e){return z(t,"revoke_role",[_(e.account),E(e.role)])}function we(t,e){return z(t,"transfer_ownership",[_(e.newOwner),S(e.liveUntilLedger)])}function be(t){return z(t,"accept_ownership",[])}function _e(t,e){return z(t,"set_swap_aggregator",[_(e.aggregator)])}function ve(t,e){return z(t,"set_price_aggregator",[_(e.aggregator)])}const Se=_e;function qe(t,e){return z(t,"set_accumulator",[_(e.accumulator)])}function Ie(t,e){return z(t,"set_position_limits",[ee(e)])}function ke(t,e){return z(t,"approve_blend_pool",[_(e.pool)])}function Ee(t,e){return z(t,"revoke_blend_pool",[_(e.pool)])}const Be=ke,Ae=Ee;function Te(t,e){return z(t,"set_oracle",[re(e.key),ce(e.oracle)])}const Re=Te;function xe(t,e){const r=e.toleranceBps,o=e.upperRatioBps??1e4+r,n=e.lowerRatioBps??Math.max(1,Math.floor(1e8/o));return z(t,"set_tolerance",[re(e.key),P({lower_ratio_bps:S(n),upper_ratio_bps:S(o)})])}function Ue(t,e){return z(t,"set_spoke_asset_flags",[S(e.spokeId),x(e.hubId,e.asset),I(e.paused),I(e.frozen),I(e.noSeize)])}function $e(t,e){return z(t,"set_oracle_sanity_bounds",[_(e.asset),v(e.minPriceWad),v(e.maxPriceWad)])}function Oe(t,e){return z(t,"update_indexes",[_(t.caller),A(e.assets.map((t=>x(t.hubId,t.asset))))])}function Pe(t,e){return z(t,"renew_account",[_(t.caller),q(e.accountNonce)])}function Ce(t,e){return z(t,"create_liquidity_pool",[S(e.hubId),_(e.asset),te(e.params)])}function Ne(t,e){return z(t,"upgrade_liquidity_pool_params",[x(e.hubId,e.asset),Qt(e.params)])}function Me(t,e){return z(t,"claim_revenue",[_(t.caller),A(e.assets.map((t=>x(t.hubId,t.asset))))])}function We(t,e){return z(t,"add_rewards",[_(t.caller),$(e.rewards)])}function Le(t,e){return z(t,"update_account_threshold",[_(t.caller),I(e.hasRisks),A(e.accountNonces.map((t=>q(t))))])}const De="00".repeat(32),Fe=t=>{if("string"==typeof t)return T(t);const e=g.hp.from(t);if(32!==e.length)throw new Error(`Stellar governance builder: expected a 32-byte salt (got ${e.length} bytes)`);return a.ScVal.scvBytes(e)},ze=(t,...e)=>A([E(t),...e]),Ve=t=>P({new_owner:_(t.newOwner),live_until_ledger:S(t.liveUntilLedger)}),Xe=t=>P({asset:_(t.asset),bonus:S(t.bonus),borrow_cap:v(t.borrowCap),can_borrow:I(t.canBorrow),can_collateral:I(t.canCollateral),frozen:I(t.frozen),hub_id:S(t.hubId),paused:I(t.paused),liquidation_fees:S(t.liquidationFees),ltv:S(t.ltv),no_seize:I(t.noSeize),spoke_id:S(t.spokeId),supply_cap:v(t.supplyCap),threshold:S(t.threshold)}),je=t=>P({account:_(t.account),role:E(t.role)});function Ge(e,n,s){if(!e.governanceAddress)throw new Error("Stellar governanceAddress is required");const a=new o(e.governanceAddress),u=new t(e.caller,e.sourceSequence);return{xdr:new i(u,{fee:e.fee??r,networkPassphrase:m[e.network]}).addOperation(a.call(n,...s)).setTimeout(e.timeoutSeconds??300).build().toXDR()}}const He=(t,e,r)=>Ge(t,"propose",[_(t.caller),e,Fe(r)]),Ke=(t,e,r)=>Ge(t,"execute_self",[B(),e,Fe(r)]);function Je(t,e,r){return He(t,ze("SetSwapAggregator",_(e.aggregator)),r)}function Ye(t,e,r){return He(t,ze("SetPriceAggregator",_(e.aggregator)),r)}const Ze=Je;function Qe(t,e,r){return He(t,ze("SetAccumulator",_(e.accumulator)),r)}function tr(t,e,r){return He(t,ze("SetPositionLimits",ee(e)),r)}function er(t,e){return He(t,ze("CreateHub"),e)}function rr(t,e){return He(t,ze("AddSpoke"),e)}function or(t,e,r){return He(t,ze("RemoveSpoke",S(e.spokeId)),r)}function nr(t,e,r){return He(t,ze("AddAssetToSpoke",Xe(e)),r)}function ir(t,e,r){return He(t,ze("EditAssetInSpoke",Xe(e)),r)}function sr(t,e,r){return He(t,ze("RemoveAssetFromSpoke",P({hub_asset:x((o=e).hubId,o.asset),spoke_id:S(o.spokeId)})),r);var o}function ar(t,e,r){return He(t,ze("SetSpokeLiquidationCurve",P({hf_for_max_bonus_wad:v((o=e).hfForMaxBonusWad),liquidation_bonus_factor_bps:S(o.liquidationBonusFactorBps),spoke_id:S(o.spokeId),target_hf_wad:v(o.targetHfWad)})),r);var o}function ur(t,e,r){return He(t,ze("SetPositionManager",_(e.manager),I(e.isActive)),r)}function lr(t,e,r){return He(t,ze("SetMinBorrowCollateralUsd",v(e.floorWad)),r)}function cr(t,e,r){return He(t,ze("ApproveToken",_(e.token)),r)}function fr(t,e,r){return He(t,ze("RevokeToken",_(e.token)),r)}function pr(t,e,r){return He(t,ze("ApproveBlendPool",_(e.pool)),r)}function hr(t,e,r){return He(t,ze("RevokeBlendPool",_(e.pool)),r)}function dr(t,e,r){return He(t,ze("CreateLiquidityPool",P({asset:_((o=e).asset),hub_id:S(o.hubId),params:te(o.params)})),r);var o}function mr(t,e,r){return He(t,ze("UpgradeLiquidityPoolParams",P({hub_asset:x((o=e).hubId,o.asset),params:Qt(o.params)})),r);var o}function gr(t,e,r){return He(t,ze("DeployPool",T(e.wasmHash)),r)}function yr(t,e,r){return He(t,ze("UpgradePool",T(e.wasmHash)),r)}function wr(t,e,r){return He(t,ze("UpgradeController",T(e.wasmHash)),r)}function br(t,e,r){return He(t,ze("MigrateController",S(e.newVersion)),r)}function _r(t,e,r){return He(t,ze("TransferCtrlOwnership",Ve(e)),r)}function vr(t,e,r){return He(t,ze("ConfigureAssetOracle",P({key:re((o=e).key),oracle:ce(o.oracle)})),r);var o}const Sr=vr;function qr(t,e,r){return He(t,ze("EditOracleTolerance",P({key:re((o=e).key),tolerance:S(o.tolerance)})),r);var o}function Ir(t,e,r){return He(t,ze("UpgradeGov",T(e.wasmHash)),r)}function kr(t,e,r){return He(t,ze("UpdateGovDelay",S(e.newDelay)),r)}function Er(t,e,r){return He(t,ze("GrantGovRole",je(e)),r)}function Br(t,e,r){return He(t,ze("RevokeGovRole",je(e)),r)}function Ar(t,e,r){return He(t,ze("TransferGovOwnership",Ve(e)),r)}function Tr(t,e){const r=A(e.argsXdr.map((t=>a.ScVal.fromXDR(t,"base64")))),o=Fe(e.predecessor??De);return Ge(t,"execute",[B(),_(e.target),E(e.functionName),r,o,Fe(e.salt)])}function Rr(t,e,r){return Ke(t,ze("UpgradeGov",T(e.wasmHash)),r)}function xr(t,e,r){return Ke(t,ze("UpdateGovDelay",S(e.newDelay)),r)}function Ur(t,e,r){return Ke(t,ze("GrantGovRole",je(e)),r)}function $r(t,e,r){return Ke(t,ze("RevokeGovRole",je(e)),r)}function Or(t,e,r){return Ke(t,ze("TransferGovOwnership",Ve(e)),r)}const Pr=t=>A(t.map(_));function Cr(t,e,r){return Ge(t,"propose_canceller_reset",[Pr(e.newCancellers),Fe(r)])}function Nr(t,e,r){return Ge(t,"execute_canceller_reset",[R(e.executor,_),Pr(e.newCancellers),Fe(r)])}function Mr(t,e){return Ge(t,"set_spoke_asset_flags",[_(t.caller),S(e.spokeId),x(e.hubId,e.asset),I(e.paused),I(e.frozen),I(e.noSeize)])}function Wr(t,e){return Ge(t,"set_oracle_sanity_bounds",[_(t.caller),_(e.asset),v(e.minPriceWad),v(e.maxPriceWad)])}function Lr(t){return Ge(t,"create_hub",[_(t.caller)])}function Dr(t){return Ge(t,"add_spoke",[_(t.caller)])}function Fr(t,e){return Ge(t,"revoke_role_immediate",[_(e.account),E(e.role)])}function zr(t){return Ge(t,"pause",[_(t.caller)])}function Vr(t,e){return He(t,ze("Unpause"),e)}const Xr=t=>t.toXDR("base64"),jr=t=>a.ScVal.fromXDR(t,"base64"),Gr=t=>t.map((t=>String(s(jr(t))))).join(":"),Hr=t=>"bigint"==typeof t||"number"==typeof t?t.toString():String(t),Kr=t=>Number(t),Jr=t=>String(t),Yr=t=>t instanceof Uint8Array?g.hp.from(t).toString("hex"):g.hp.isBuffer(t)?t.toString("hex"):String(t),Zr=["None","Multiply","Long","Short"],Qr=["supply","borrow","withdraw","repay","liq_repay","liq_seize","multiply","param_upd","sw_debt_r","sw_col_wd","rp_col_wd","rp_col_r","close_wd","migrate","rp_col_net","liq_credit"],to=t=>Array.isArray(t)?t:[],eo=(t,e)=>{const r="Borrow"===e;return{action:(o=t[0],Qr[Kr(o)]??Hr(o)),positionType:e,hubId:Kr(t[1]),asset:Jr(t[2]),scaledAmountRay:Hr(t[3]),indexRay:Hr(t[4]),amount:Hr(t[5]),liquidationThresholdBps:r?void 0:Kr(t[6]),liquidationBonusBps:r?void 0:Kr(t[7]),loanToValueBps:r?void 0:Kr(t[8]),liquidationFeesBps:r?void 0:Kr(t[9])};var o},ro=t=>{return{owner:Jr(t[0]),spokeId:Kr(t[1]),mode:(e=t[2],Zr[Kr(e)]??"None")};var e},oo=t=>Array.isArray(t)?t[1]:void 0,no=t=>{const e=(r=t,Array.isArray(r)?Jr(r[0]):Jr(r));var r;if("Token"===e)return{Token:Jr(oo(t))};if("Ref"===e)return{Ref:Jr(oo(t))};if(t&&"object"==typeof t&&!Array.isArray(t)){const e=t;if(void 0!==e.Token)return{Token:Jr(e.Token)};if(void 0!==e.Ref)return{Ref:Jr(e.Ref)}}return{Token:Jr(t)}},io=t=>{const e=t.tolerance??{};return{assetDecimals:Kr(t.asset_decimals),maxPriceStaleSeconds:Kr(t.max_price_stale_seconds),sources:to(t.sources).map((t=>t)),tolerance:{upperRatio:Kr(e.upper_ratio_bps),lowerRatio:Kr(e.lower_ratio_bps)},independence:t.independence,minSanityPriceWad:Hr(t.min_sanity_price_wad),maxSanityPriceWad:Hr(t.max_sanity_price_wad)}},so={"market:create":t=>({topic:"market:create",data:{hubId:Kr(t.hub_id),baseAsset:Jr(t.base_asset),maxBorrowRate:Hr(t.max_borrow_rate),baseBorrowRate:Hr(t.base_borrow_rate),slope1:Hr(t.slope1),slope2:Hr(t.slope2),slope3:Hr(t.slope3),midUtilization:Hr(t.mid_utilization),optimalUtilization:Hr(t.optimal_utilization),maxUtilization:Hr(t.max_utilization),reserveFactor:Kr(t.reserve_factor),marketAddress:Jr(t.market_address)}}),"market:params_update":t=>({topic:"market:params_update",data:{asset:Jr(t.asset),maxBorrowRateRay:Hr(t.max_borrow_rate),baseBorrowRateRay:Hr(t.base_borrow_rate),slope1Ray:Hr(t.slope1),slope2Ray:Hr(t.slope2),slope3Ray:Hr(t.slope3),midUtilizationRay:Hr(t.mid_utilization),optimalUtilizationRay:Hr(t.optimal_utilization),maxUtilizationRay:Hr(t.max_utilization),reserveFactorBps:Kr(t.reserve_factor)}}),"market:batch_state_update":t=>({topic:"market:batch_state_update",data:{updates:to(t).map((t=>{return e=to(t),{hubId:Kr(e[0]),asset:Jr(e[1]),timestamp:Kr(e[2]),supplyIndexRay:Hr(e[3]),borrowIndexRay:Hr(e[4]),cash:Hr(e[5]),suppliedRay:Hr(e[6]),borrowedRay:Hr(e[7]),revenueRay:Hr(e[8])};var e}))}}),"market:batch_params_update":t=>({topic:"market:batch_params_update",data:{updates:to(t).map((t=>{const e=t;return{hubId:Kr(e.hub_id),asset:Jr(e.asset),params:(r=e.params,{maxBorrowRateRay:Hr(r.max_borrow_rate),baseBorrowRateRay:Hr(r.base_borrow_rate),slope1Ray:Hr(r.slope1),slope2Ray:Hr(r.slope2),slope3Ray:Hr(r.slope3),midUtilizationRay:Hr(r.mid_utilization),optimalUtilizationRay:Hr(r.optimal_utilization),maxUtilizationRay:Hr(r.max_utilization),reserveFactorBps:Kr(r.reserve_factor),isFlashloanable:Boolean(r.is_flashloanable),flashloanFeeBps:Kr(r.flashloan_fee),assetId:Jr(r.asset_id),assetDecimals:Kr(r.asset_decimals)})};var r}))}}),"position:batch_update":t=>{const e=to(t);return{topic:"position:batch_update",data:{accountId:Hr(e[0]),accountAttributes:ro(to(e[1])),updates:[...to(e[2]).map((t=>eo(to(t),"Deposit"))),...to(e[3]).map((t=>eo(to(t),"Borrow")))]}}},"position:flash_loan":t=>({topic:"position:flash_loan",data:{hubId:Kr(t.hub_id),asset:Jr(t.asset),receiver:Jr(t.receiver),caller:Jr(t.caller),amount:Hr(t.amount),fee:Hr(t.fee)}}),"config:asset_oracle":t=>({topic:"config:asset_oracle",data:{key:no(t.key),oracle:io(t.oracle)}}),"config:oracle":t=>({topic:"config:oracle",data:{asset:Jr(t.asset),oracle:io(t.config??t.oracle)}}),"position:liquidation":t=>({topic:"position:liquidation",data:{liquidator:Jr(t.liquidator),accountId:Hr(t.account_id),repaidUsdWad:Hr(t.repaid_usd_wad),bonusBps:Hr(t.bonus_bps)}}),"debt:bad_debt":t=>({topic:"debt:bad_debt",data:{accountId:Hr(t.account_id),totalBorrowUsdWad:Hr(t.total_borrow_usd_wad),totalCollateralUsdWad:Hr(t.total_collateral_usd_wad)}}),"strategy:initial_payment":t=>({topic:"strategy:initial_payment",data:{token:Jr(t.token),amount:Hr(t.amount),usdValueWad:Hr(t.usd_value_wad),accountId:Hr(t.account_id)}}),"strategy:fee":t=>({topic:"strategy:fee",data:{hubId:Kr(t.hub_id),asset:Jr(t.asset),amount:Hr(t.amount),fee:Hr(t.fee),amountSent:Hr(t.amount_sent)}}),"config:approve_blend_pool":t=>({topic:"config:approve_blend_pool",data:{pool:Jr(t.pool??t.blend_pool??t.token),approved:Boolean(t.approved??t.is_approved??!0)}}),"config:approve_token":t=>({topic:"config:approve_token",data:{wasmHash:Yr(t.wasm_hash??t.pool),approved:Boolean(t.approved)}}),"config:swap_aggregator":t=>({topic:"config:swap_aggregator",data:{aggregator:Jr(t.aggregator??t.swap_aggregator)}}),"config:price_aggregator":t=>({topic:"config:price_aggregator",data:{aggregator:Jr(t.aggregator??t.price_aggregator)}}),"config:aggregator":t=>({topic:"config:aggregator",data:{aggregator:Jr(t.aggregator)}}),"config:accumulator":t=>({topic:"config:accumulator",data:{accumulator:Jr(t.accumulator)}}),"config:pool_template":t=>({topic:"config:pool_template",data:{wasmHash:Yr(t.wasm_hash)}}),"config:position_limits":t=>({topic:"config:position_limits",data:{maxSupplyPositions:Kr(t.max_supply_positions),maxBorrowPositions:Kr(t.max_borrow_positions)}}),"config:min_borrow_collateral":t=>({topic:"config:min_borrow_collateral",data:{minBorrowCollateralUsdWad:Hr(t.min_borrow_collateral_usd_wad??t.floor_wad??t.value)}}),"config:oracle_disabled":t=>({topic:"config:oracle_disabled",data:{asset:Jr(t.asset)}}),"config:spoke":t=>{const e=t.spoke;return{topic:"config:spoke",data:{spokeId:Kr(e.spoke_id),isDeprecated:Boolean(e.is_deprecated),liquidationTargetHfWad:Hr(e.liquidation_target_hf_wad),healthFactorForMaxBonusWad:Hr(e.hf_for_max_bonus_wad),liquidationBonusFactorBps:Kr(e.liquidation_bonus_factor_bps)}}}},ao=Object.freeze(Object.keys(so));function uo(t,e){const r=Gr(t),o=so[r];return o?o(s(jr(e))):null}const lo=1e4;function co(t,e){return`${t}-${BigInt(e).toString(10)}`}function fo(t){const e=t.split("-");return e.length>=2&&parseInt(e[1],10)||0}function po(t,e=0){return 1e4*t+e}function ho(t){switch(t){case"liq_repay":return"lendingLiquidateRepayDebt";case"liq_seize":return"lendingLiquidateSeizeCollateral";case"liq_credit":default:return"lendingUpdateAccountPosition";case"param_upd":return"lendingUpdateAccountParameters"}}const mo=(t,e,r)=>{const o=new URL(e,t.endsWith("/")?t:`${t}/`);if(r)for(const[t,e]of Object.entries(r))void 0!==e&&o.searchParams.set(t,String(e));return o.toString()};async function go(t,e){if(!e.baseUrl)throw new Error("Stellar quote baseUrl is required");if(null==t.amountIn==(null==t.amountOut))throw new Error("getStellarAggregatorQuote: exactly one of `amountIn` or `amountOut` must be provided");const r=mo(e.baseUrl,"api/v1/quote",{from:t.from,to:t.to,amountIn:t.amountIn,amountOut:t.amountOut,maxHops:t.maxHops,maxSplits:t.maxSplits,slippage:t.slippage,includePaths:t.includePaths,sender:t.sender,router:t.router,referralId:t.referralId,platform:t.platform,fresh:t.fresh}),o=await fetch(r,e.fetchOptions);if(!o.ok){const t=await o.text().catch((()=>""));throw new Error(`Stellar quote server responded ${o.status} ${o.statusText} for ${r} — ${t}`)}return await o.json()}async function yo(t){if(!t.baseUrl)throw new Error("Stellar quote baseUrl is required");const e=mo(t.baseUrl,"api/v1/tokens"),r=await fetch(e,t.fetchOptions);if(!r.ok){const t=await r.text().catch((()=>""));throw new Error(`Stellar quote server responded ${r.status} ${r.statusText} for ${e} — ${t}`)}return await r.json()}const wo=(t,e)=>(t=>Boolean(t&&"object"==typeof t&&!(t instanceof Uint8Array)&&"paths"in t))(t)&&void 0===t.referralId?{...t,referralId:e??0}:t,bo=t=>N(t).toXDR("base64");function _o(e,n){if(!e.routerAddress)throw new Error("Stellar aggregator routerAddress is required");const s=new o(e.routerAddress),a=new t(e.caller,e.sourceSequence),u=D(wo(n,e.referralId));return{xdr:new i(a,{fee:e.fee??r,networkPassphrase:m[e.network]}).addOperation(s.call("execute_strategy",_(e.caller),v(e.totalIn),u)).setTimeout(e.timeoutSeconds??300).build().toXDR()}}function vo(t,e){return _o(t,e)}function So(t,e={}){if("string"!=typeof t.amountOutMin)throw new Error("mapQuoteResponseToStrategyPayload: quote response is missing `amountOutMin`. Pass `slippage` when fetching the quote.");return{paths:t.paths?t.paths.map((t=>({hops:t.swaps.map(ko),splitPpm:t.splitPpm}))):[{hops:t.hops.map(ko),splitPpm:1e6}],referralId:e.referralId??0,tokenIn:t.from,tokenOut:t.to,totalMinOut:t.amountOutMin}}function qo(t,e={}){const r=t;return"string"==typeof r.routeXdr&&r.routeXdr.length>0?{routeXdr:r.routeXdr}:So(t,e)}const Io=So,ko=t=>({amountOut:t.amountOut,pool:t.address,tokenIn:t.from,tokenOut:t.to,venue:t.dex});function Eo(t,e){const r=e instanceof Error?e.message:String(e);return new Error(`[xoxno-invoked:${t}] ${r}`)}async function Bo(t,e,r){const o=i.fromXDR(e,r?.network?m[r.network]:"");try{return(await t.prepareTransaction(o)).toXDR()}catch(t){if(r?.invokedContractId)throw Eo(r.invokedContractId,t);throw t}}async function Ao(t,e,r){return Bo(t,e.xdr,r)}function To(t){if(t<=0||t>4)throw new Error(`Invalid PositionMode ${t} for Stellar — expected 1 (Normal) through 4 (Short). "None" (0) has no Stellar equivalent.`);return t-1}function Ro(t,e){return new Uint8Array(0)}const xo=t=>{const e=t.startsWith("0x")?t.slice(2):t;if(e.length%2!=0)throw new Error("buildStellarCctpForwardTx: hex input must have even length");return g.hp.from(e,"hex")};function Uo(e){const r=new t(e.caller,e.sourceSequence),n=new o(e.forwarderAddress).call("mint_and_forward",a.ScVal.scvBytes(xo(e.message)),a.ScVal.scvBytes(xo(e.attestation)));return{xdr:new i(r,{fee:e.fee??"10000000",networkPassphrase:m[e.network]}).addOperation(n).setTimeout(e.timeoutSeconds??120).build().toXDR()}}const $o={1:{name:"AssetNotSupported",message:"This asset is not supported by the protocol."},2:{name:"AssetAlreadySupported",message:"This asset is already supported."},3:{name:"InvalidTicker",message:"Invalid asset ticker."},6:{name:"InvalidAsset",message:"Invalid asset address."},10:{name:"InvalidWasmHash",message:"The WASM hash is empty or invalid."},11:{name:"InvalidExchangeSrc",message:"The oracle configuration is invalid."},12:{name:"PairNotActive",message:"No oracle is configured for this asset."},32:{name:"OwnerNotSet",message:"The contract owner has not been set."},39:{name:"InvalidTimelockDelay",message:"The timelock delay is out of the allowed range."},41:{name:"InvalidRole",message:"The caller does not hold the required role."},43:{name:"HubNotActive",message:"This hub is not active."},44:{name:"NotAuthorized",message:"The caller is not authorized to perform this action."},46:{name:"OperationNotCancellable",message:"This governance operation cannot be cancelled."},113:{name:"InvalidLiqThreshold",message:"LTV, liquidation threshold, or bonus is out of bounds."},116:{name:"InvalidBorrowParams",message:"Supply or borrow cap configuration is invalid."},117:{name:"InvalidUtilRange",message:"Interest-rate utilization breakpoints are invalid."},132:{name:"AssetDecimalsTooHigh",message:"Asset decimals exceed the protocol maximum (27)."},300:{name:"SpokeNotFound",message:"This spoke does not exist."},301:{name:"SpokeDeprecated",message:"This spoke has been deprecated."},307:{name:"AssetNotInSpoke",message:"This asset is not listed on the spoke."},308:{name:"AssetAlreadyInSpoke",message:"This asset is already listed in the spoke."},309:{name:"SpokeAssetInUse",message:"This spoke asset still has live positions; drain usage before removal."},315:{name:"SpokeAssetPaused",message:"This spoke asset is paused."},316:{name:"SpokeAssetFrozen",message:"This spoke asset is frozen."},317:{name:"SpokeAssetFlagRelaxation",message:"Guardian flag updates may only tighten; clearing a flag requires the timelocked edit."},318:{name:"SpokeAssetSeizureHalted",message:"Liquidation seizure is halted for this spoke asset."},220:{name:"InvalidOracleBase",message:"The oracle quote asset/market is missing or invalid."},221:{name:"InvalidOracleDecimals",message:"The oracle decimals value is invalid."},224:{name:"InvalidSanityBounds",message:"Oracle sanity bounds are invalid (require 0 < min < max)."},225:{name:"OracleCycleDetected",message:"A cycle was detected in the oracle quote chain."}};function Oo(t){const e=t.match(/Error\(Contract,\s*#(\d+)\)/);if(!e)return null;const r=Number(e[1]),o=$o[r];return o?{code:r,...o}:null}export{De as STELLAR_GOVERNANCE_ZERO_PREDECESSOR,ao as STELLAR_LENDING_TOPICS,p as STELLAR_NETWORKS,m as STELLAR_NETWORK_PASSPHRASE,lo as SYNTHETIC_EVENT_ORDER_STRIDE,Ro as buildSameTokenRepaySwapSteps,be as buildStellarAcceptOwnershipTx,We as buildStellarAddRewardsTx,ke as buildStellarApproveBlendPoolTx,Be as buildStellarApproveTokenTx,vo as buildStellarBatchSwapTx,G as buildStellarBorrowBatchTx,H as buildStellarBorrowTx,Uo as buildStellarCctpForwardTx,Me as buildStellarClaimRevenueTx,Ce as buildStellarCreateLiquidityPoolTx,Nr as buildStellarExecuteCancellerResetTx,_o as buildStellarExecuteStrategyTx,et as buildStellarFlashLoanTx,Dr as buildStellarGovernanceAddSpokeImmediateTx,Lr as buildStellarGovernanceCreateHubImmediateTx,Rr as buildStellarGovernanceExecuteGovernanceUpgradeTx,Ur as buildStellarGovernanceExecuteGrantGovernanceRoleTx,$r as buildStellarGovernanceExecuteRevokeGovernanceRoleTx,Or as buildStellarGovernanceExecuteTransferGovOwnTx,Tr as buildStellarGovernanceExecuteTx,xr as buildStellarGovernanceExecuteUpdateDelayTx,zr as buildStellarGovernancePauseTx,Fr as buildStellarGovernanceRevokeRoleImmediateTx,Wr as buildStellarGovernanceSetOracleSanityBoundsImmediateTx,Mr as buildStellarGovernanceSetSpokeAssetFlagsImmediateTx,ge as buildStellarGrantRoleTx,co as buildStellarLendingIdentifier,Q as buildStellarLiquidateTx,rt as buildStellarMigrateFromBlendTx,he as buildStellarMigrateTx,ot as buildStellarMultiplyTx,de as buildStellarPauseTx,nr as buildStellarProposeAddAssetToSpokeTx,rr as buildStellarProposeAddSpokeTx,pr as buildStellarProposeApproveBlendPoolTx,cr as buildStellarProposeApproveTokenTx,Cr as buildStellarProposeCancellerResetTx,vr as buildStellarProposeConfigureAssetOracleTx,Sr as buildStellarProposeConfigureMarketOracleTx,er as buildStellarProposeCreateHubTx,dr as buildStellarProposeCreateLiquidityPoolTx,gr as buildStellarProposeDeployPoolTx,ir as buildStellarProposeEditAssetInSpokeTx,qr as buildStellarProposeEditOracleToleranceTx,Ir as buildStellarProposeGovernanceUpgradeTx,Er as buildStellarProposeGrantGovernanceRoleTx,br as buildStellarProposeMigrateControllerTx,sr as buildStellarProposeRemoveAssetFromSpokeTx,or as buildStellarProposeRemoveSpokeTx,hr as buildStellarProposeRevokeBlendPoolTx,Br as buildStellarProposeRevokeGovernanceRoleTx,fr as buildStellarProposeRevokeTokenTx,Qe as buildStellarProposeSetAccumulatorTx,Ze as buildStellarProposeSetAggregatorTx,lr as buildStellarProposeSetMinBorrowCollatTx,tr as buildStellarProposeSetPositionLimitsTx,ur as buildStellarProposeSetPositionManagerTx,Ye as buildStellarProposeSetPriceAggregatorTx,ar as buildStellarProposeSetSpokeLiquidationCurveTx,Je as buildStellarProposeSetSwapAggregatorTx,_r as buildStellarProposeTransferCtrlOwnershipTx,Ar as buildStellarProposeTransferGovOwnTx,Vr as buildStellarProposeUnpauseTx,kr as buildStellarProposeUpdateDelayTx,wr as buildStellarProposeUpgradeControllerTx,mr as buildStellarProposeUpgradePoolParamsTx,yr as buildStellarProposeUpgradePoolTx,Pe as buildStellarRenewAccountTx,Y as buildStellarRepayBatchTx,st as buildStellarRepayDebtWithCollateralTx,Z as buildStellarRepayTx,Ee as buildStellarRevokeBlendPoolTx,ye as buildStellarRevokeRoleTx,Ae as buildStellarRevokeTokenTx,qe as buildStellarSetAccumulatorTx,Se as buildStellarSetAggregatorTx,Re as buildStellarSetMarketOracleConfigTx,$e as buildStellarSetOracleSanityBoundsTx,xe as buildStellarSetOracleToleranceTx,Te as buildStellarSetOracleTx,Ie as buildStellarSetPositionLimitsTx,ve as buildStellarSetPriceAggregatorTx,Ue as buildStellarSetSpokeAssetFlagsTx,_e as buildStellarSetSwapAggregatorTx,X as buildStellarSupplyBatchTx,j as buildStellarSupplyTx,it as buildStellarSwapCollateralTx,nt as buildStellarSwapDebtTx,we as buildStellarTransferOwnershipTx,me as buildStellarUnpauseTx,Le as buildStellarUpdateAccountThresholdTx,Oe as buildStellarUpdateIndexesTx,pe as buildStellarUpgradeControllerTx,Ne as buildStellarUpgradeLiquidityPoolParamsTx,K as buildStellarWithdrawBatchTx,J as buildStellarWithdrawTx,z as buildTx,uo as decodeStellarLendingEvent,tt as decodeStellarLiquidateReturn,ce as encodeAssetOracle,Qt as encodeInterestRateModel,fe as encodeMarketOracleConfigInput,te as encodeMarketParamsRaw,ee as encodePositionLimits,re as encodePriceKey,bo as encodeStrategyPayloadToRouteXdr,fo as extractEventOrder,vt as getStellarAccountPositions,Xt as getStellarActiveUsersSeries,go as getStellarAggregatorQuote,yt as getStellarAsset,At as getStellarAssetGraph,It as getStellarAssetMarkets,qt as getStellarAssetPage,pt as getStellarAssets,Wt as getStellarCampaignLeaderboard,Yt as getStellarCampaignMe,Gt as getStellarDefiLlamaDimensions,d as getStellarDeployment,ft as getStellarDetailedMarkets,Ft as getStellarFeeRevenueSeries,Ot as getStellarGovernanceProposals,Mt as getStellarHolderDistribution,wt as getStellarHub,Tt as getStellarHubGraph,Et as getStellarHubHolders,ht as getStellarHubs,lt as getStellarLendingContext,ct as getStellarLendingLiveState,Nt as getStellarLiquidationsLeaderboard,zt as getStellarLiquidationsSeries,Ct as getStellarParticipantCounts,Jt as getStellarPnlByScope,Pt as getStellarPositionsLeaderboard,Kt as getStellarPositionsPnl,yo as getStellarQuoteTokens,jt as getStellarRateSpreadSeries,gt as getStellarReserve,xt as getStellarReserveGraph,kt as getStellarReserveHolders,mt as getStellarReserves,Dt as getStellarRevenueSeries,bt as getStellarSpoke,Rt as getStellarSpokeGraph,Bt as getStellarSpokeHolders,dt as getStellarSpokes,Lt as getStellarStatsHistory,Ut as getStellarUserActivity,$t as getStellarUserActivityPage,Ht as getStellarUserHistory,_t as getStellarUserPositions,Vt as getStellarVolumeSeries,St as getStellarWalletBalance,Io as mapQuoteResponseToAggregatorSwap,So as mapQuoteResponseToStrategyPayload,qo as mapQuoteResponseToStrategySwap,Oo as mapSorobanError,ho as mapStellarPositionActivityType,Ao as prepareStellarBuiltTx,Bo as prepareStellarTxXdr,Gr as stellarLendingDispatchKey,Zt as stellarLendingRead,h as stellarNetworks,po as syntheticEventOrder,Eo as tagStellarInvokedContractError,Xr as toBase64Xdr,To as toStellarPositionMode};export const XOXNOClient=f.GW;
2
+ "undefined"!=typeof globalThis&&void 0===globalThis.self&&(globalThis.self=globalThis);import{Account as t,Address as e,BASE_FEE as r,Contract as n,ScInt as o,TransactionBuilder as i,scValToNative as s,xdr as a}from"@stellar/stellar-sdk";var u={526(t,e){e.byteLength=function(t){var e=a(t),r=e[0],n=e[1];return 3*(r+n)/4-n},e.toByteArray=function(t){var e,r,i=a(t),s=i[0],u=i[1],l=new o(function(t,e,r){return 3*(e+r)/4-r}(0,s,u)),c=0,p=u>0?s-4:s;for(r=0;r<p;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)],l[c++]=e>>16&255,l[c++]=e>>8&255,l[c++]=255&e;return 2===u&&(e=n[t.charCodeAt(r)]<<2|n[t.charCodeAt(r+1)]>>4,l[c++]=255&e),1===u&&(e=n[t.charCodeAt(r)]<<10|n[t.charCodeAt(r+1)]<<4|n[t.charCodeAt(r+2)]>>2,l[c++]=e>>8&255,l[c++]=255&e),l},e.fromByteArray=function(t){for(var e,n=t.length,o=n%3,i=[],s=16383,a=0,u=n-o;a<u;a+=s)i.push(l(t,a,a+s>u?u:a+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 a(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 u(t){return r[t>>18&63]+r[t>>12&63]+r[t>>6&63]+r[63&t]}function l(t,e,r){for(var n,o=[],i=e;i<r;i+=3)n=(t[i]<<16&16711680)+(t[i+1]<<8&65280)+(255&t[i+2]),o.push(u(n));return o.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=u,e.IS=50;const s=2147483647;function a(t){if(t>s)throw new RangeError('The value "'+t+'" is invalid for option "size"');const e=new Uint8Array(t);return Object.setPrototypeOf(e,u.prototype),e}function u(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 p(t)}return l(t,e,r)}function l(t,e,r){if("string"==typeof t)return function(t,e){if("string"==typeof e&&""!==e||(e="utf8"),!u.isEncoding(e))throw new TypeError("Unknown encoding: "+e);const r=0|m(t,e);let n=a(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(K(t,Uint8Array)){const e=new Uint8Array(t);return d(e.buffer,e.byteOffset,e.byteLength)}return f(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(K(t,ArrayBuffer)||t&&K(t.buffer,ArrayBuffer))return d(t,e,r);if("undefined"!=typeof SharedArrayBuffer&&(K(t,SharedArrayBuffer)||t&&K(t.buffer,SharedArrayBuffer)))return d(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 u.from(n,e,r);const o=function(t){if(u.isBuffer(t)){const e=0|h(t.length),r=a(e);return 0===r.length||t.copy(r,0,0,e),r}return void 0!==t.length?"number"!=typeof t.length||J(t.length)?a(0):f(t):"Buffer"===t.type&&Array.isArray(t.data)?f(t.data):void 0}(t);if(o)return o;if("undefined"!=typeof Symbol&&null!=Symbol.toPrimitive&&"function"==typeof t[Symbol.toPrimitive])return u.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 c(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 p(t){return c(t),a(t<0?0:0|h(t))}function f(t){const e=t.length<0?0:0|h(t.length),r=a(e);for(let n=0;n<e;n+=1)r[n]=255&t[n];return r}function d(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,u.prototype),n}function h(t){if(t>=s)throw new RangeError("Attempt to allocate Buffer larger than maximum size: 0x"+s.toString(16)+" bytes");return 0|t}function m(t,e){if(u.isBuffer(t))return t.length;if(ArrayBuffer.isView(t)||K(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 j(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:j(t).length;e=(""+e).toLowerCase(),o=!0}}function g(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 A(this,e,r);case"utf8":case"utf-8":return R(this,e,r);case"ascii":return k(this,e,r);case"latin1":case"binary":return E(this,e,r);case"base64":return q(this,e,r);case"ucs2":case"ucs-2":case"utf16le":case"utf-16le":return U(this,e,r);default:if(n)throw new TypeError("Unknown encoding: "+t);t=(t+"").toLowerCase(),n=!0}}function y(t,e,r){const n=t[e];t[e]=t[r],t[r]=n}function w(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),J(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=u.from(e,n)),u.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,a=t.length,u=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,a/=2,u/=2,r/=2}function l(t,e){return 1===s?t[e]:t.readUInt16BE(e*s)}if(o){let n=-1;for(i=r;i<a;i++)if(l(t,i)===l(e,-1===n?0:i-n)){if(-1===n&&(n=i),i-n+1===u)return n*s}else-1!==n&&(i-=i-n),n=-1}else for(r+u>a&&(r=a-u),i=r;i>=0;i--){let r=!0;for(let n=0;n<u;n++)if(l(t,i+n)!==l(e,n)){r=!1;break}if(r)return i}return-1}function v(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(J(n))return s;t[r+s]=n}return s}function B(t,e,r,n){return H(j(e,t.length-r),t,r,n)}function S(t,e,r,n){return H(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 _(t,e,r,n){return H(G(e),t,r,n)}function I(t,e,r,n){return H(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 q(t,e,r){return 0===e&&r===t.length?n.fromByteArray(t):n.fromByteArray(t.slice(e,r))}function R(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,a,u;switch(s){case 1:e<128&&(i=e);break;case 2:r=t[o+1],128==(192&r)&&(u=(31&e)<<6|63&r,u>127&&(i=u));break;case 3:r=t[o+1],n=t[o+2],128==(192&r)&&128==(192&n)&&(u=(15&e)<<12|(63&r)<<6|63&n,u>2047&&(u<55296||u>57343)&&(i=u));break;case 4:r=t[o+1],n=t[o+2],a=t[o+3],128==(192&r)&&128==(192&n)&&128==(192&a)&&(u=(15&e)<<18|(63&r)<<12|(63&n)<<6|63&a,u>65535&&u<1114112&&(i=u))}}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<=x)return String.fromCharCode.apply(String,t);let r="",n=0;for(;n<e;)r+=String.fromCharCode.apply(String,t.slice(n,n+=x));return r}(n)}u.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}}(),u.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(u.prototype,"parent",{enumerable:!0,get:function(){if(u.isBuffer(this))return this.buffer}}),Object.defineProperty(u.prototype,"offset",{enumerable:!0,get:function(){if(u.isBuffer(this))return this.byteOffset}}),u.poolSize=8192,u.from=function(t,e,r){return l(t,e,r)},Object.setPrototypeOf(u.prototype,Uint8Array.prototype),Object.setPrototypeOf(u,Uint8Array),u.alloc=function(t,e,r){return function(t,e,r){return c(t),t<=0?a(t):void 0!==e?"string"==typeof r?a(t).fill(e,r):a(t).fill(e):a(t)}(t,e,r)},u.allocUnsafe=function(t){return p(t)},u.allocUnsafeSlow=function(t){return p(t)},u.isBuffer=function(t){return null!=t&&!0===t._isBuffer&&t!==u.prototype},u.compare=function(t,e){if(K(t,Uint8Array)&&(t=u.from(t,t.offset,t.byteLength)),K(e,Uint8Array)&&(e=u.from(e,e.offset,e.byteLength)),!u.isBuffer(t)||!u.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},u.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}},u.concat=function(t,e){if(!Array.isArray(t))throw new TypeError('"list" argument must be an Array of Buffers');if(0===t.length)return u.alloc(0);let r;if(void 0===e)for(e=0,r=0;r<t.length;++r)e+=t[r].length;const n=u.allocUnsafe(e);let o=0;for(r=0;r<t.length;++r){let e=t[r];if(K(e,Uint8Array))o+e.length>n.length?(u.isBuffer(e)||(e=u.from(e)),e.copy(n,o)):Uint8Array.prototype.set.call(n,e,o);else{if(!u.isBuffer(e))throw new TypeError('"list" argument must be an Array of Buffers');e.copy(n,o)}o+=e.length}return n},u.byteLength=m,u.prototype._isBuffer=!0,u.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)y(this,e,e+1);return this},u.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)y(this,e,e+3),y(this,e+1,e+2);return this},u.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)y(this,e,e+7),y(this,e+1,e+6),y(this,e+2,e+5),y(this,e+3,e+4);return this},u.prototype.toString=function(){const t=this.length;return 0===t?"":0===arguments.length?R(this,0,t):g.apply(this,arguments)},u.prototype.toLocaleString=u.prototype.toString,u.prototype.equals=function(t){if(!u.isBuffer(t))throw new TypeError("Argument must be a Buffer");return this===t||0===u.compare(this,t)},u.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&&(u.prototype[i]=u.prototype.inspect),u.prototype.compare=function(t,e,r,n,o){if(K(t,Uint8Array)&&(t=u.from(t,t.offset,t.byteLength)),!u.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 a=Math.min(i,s),l=this.slice(n,o),c=t.slice(e,r);for(let t=0;t<a;++t)if(l[t]!==c[t]){i=l[t],s=c[t];break}return i<s?-1:s<i?1:0},u.prototype.includes=function(t,e,r){return-1!==this.indexOf(t,e,r)},u.prototype.indexOf=function(t,e,r){return w(this,t,e,r,!0)},u.prototype.lastIndexOf=function(t,e,r){return w(this,t,e,r,!1)},u.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 v(this,t,e,r);case"utf8":case"utf-8":return B(this,t,e,r);case"ascii":case"latin1":case"binary":return S(this,t,e,r);case"base64":return _(this,t,e,r);case"ucs2":case"ucs-2":case"utf16le":case"utf-16le":return I(this,t,e,r);default:if(i)throw new TypeError("Unknown encoding: "+n);n=(""+n).toLowerCase(),i=!0}},u.prototype.toJSON=function(){return{type:"Buffer",data:Array.prototype.slice.call(this._arr||this,0)}};const x=4096;function k(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 E(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 A(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+=Y[t[n]];return o}function U(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 T(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,e,r,n,o,i){if(!u.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 C(t,e,r,n,o){z(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){z(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 W(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 O(t,e,r,n,i){return e=+e,r>>>=0,i||W(t,0,r,4),o.write(t,e,r,n,23,4),r+4}function N(t,e,r,n,i){return e=+e,r>>>=0,i||W(t,0,r,8),o.write(t,e,r,n,52,8),r+8}u.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,u.prototype),n},u.prototype.readUintLE=u.prototype.readUIntLE=function(t,e,r){t>>>=0,e>>>=0,r||T(t,e,this.length);let n=this[t],o=1,i=0;for(;++i<e&&(o*=256);)n+=this[t+i]*o;return n},u.prototype.readUintBE=u.prototype.readUIntBE=function(t,e,r){t>>>=0,e>>>=0,r||T(t,e,this.length);let n=this[t+--e],o=1;for(;e>0&&(o*=256);)n+=this[t+--e]*o;return n},u.prototype.readUint8=u.prototype.readUInt8=function(t,e){return t>>>=0,e||T(t,1,this.length),this[t]},u.prototype.readUint16LE=u.prototype.readUInt16LE=function(t,e){return t>>>=0,e||T(t,2,this.length),this[t]|this[t+1]<<8},u.prototype.readUint16BE=u.prototype.readUInt16BE=function(t,e){return t>>>=0,e||T(t,2,this.length),this[t]<<8|this[t+1]},u.prototype.readUint32LE=u.prototype.readUInt32LE=function(t,e){return t>>>=0,e||T(t,4,this.length),(this[t]|this[t+1]<<8|this[t+2]<<16)+16777216*this[t+3]},u.prototype.readUint32BE=u.prototype.readUInt32BE=function(t,e){return t>>>=0,e||T(t,4,this.length),16777216*this[t]+(this[t+1]<<16|this[t+2]<<8|this[t+3])},u.prototype.readBigUInt64LE=Z((function(t){F(t>>>=0,"offset");const e=this[t],r=this[t+7];void 0!==e&&void 0!==r||V(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))})),u.prototype.readBigUInt64BE=Z((function(t){F(t>>>=0,"offset");const e=this[t],r=this[t+7];void 0!==e&&void 0!==r||V(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)})),u.prototype.readIntLE=function(t,e,r){t>>>=0,e>>>=0,r||T(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},u.prototype.readIntBE=function(t,e,r){t>>>=0,e>>>=0,r||T(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},u.prototype.readInt8=function(t,e){return t>>>=0,e||T(t,1,this.length),128&this[t]?-1*(255-this[t]+1):this[t]},u.prototype.readInt16LE=function(t,e){t>>>=0,e||T(t,2,this.length);const r=this[t]|this[t+1]<<8;return 32768&r?4294901760|r:r},u.prototype.readInt16BE=function(t,e){t>>>=0,e||T(t,2,this.length);const r=this[t+1]|this[t]<<8;return 32768&r?4294901760|r:r},u.prototype.readInt32LE=function(t,e){return t>>>=0,e||T(t,4,this.length),this[t]|this[t+1]<<8|this[t+2]<<16|this[t+3]<<24},u.prototype.readInt32BE=function(t,e){return t>>>=0,e||T(t,4,this.length),this[t]<<24|this[t+1]<<16|this[t+2]<<8|this[t+3]},u.prototype.readBigInt64LE=Z((function(t){F(t>>>=0,"offset");const e=this[t],r=this[t+7];void 0!==e&&void 0!==r||V(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)})),u.prototype.readBigInt64BE=Z((function(t){F(t>>>=0,"offset");const e=this[t],r=this[t+7];void 0!==e&&void 0!==r||V(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)})),u.prototype.readFloatLE=function(t,e){return t>>>=0,e||T(t,4,this.length),o.read(this,t,!0,23,4)},u.prototype.readFloatBE=function(t,e){return t>>>=0,e||T(t,4,this.length),o.read(this,t,!1,23,4)},u.prototype.readDoubleLE=function(t,e){return t>>>=0,e||T(t,8,this.length),o.read(this,t,!0,52,8)},u.prototype.readDoubleBE=function(t,e){return t>>>=0,e||T(t,8,this.length),o.read(this,t,!1,52,8)},u.prototype.writeUintLE=u.prototype.writeUIntLE=function(t,e,r,n){t=+t,e>>>=0,r>>>=0,n||$(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},u.prototype.writeUintBE=u.prototype.writeUIntBE=function(t,e,r,n){t=+t,e>>>=0,r>>>=0,n||$(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},u.prototype.writeUint8=u.prototype.writeUInt8=function(t,e,r){return t=+t,e>>>=0,r||$(this,t,e,1,255,0),this[e]=255&t,e+1},u.prototype.writeUint16LE=u.prototype.writeUInt16LE=function(t,e,r){return t=+t,e>>>=0,r||$(this,t,e,2,65535,0),this[e]=255&t,this[e+1]=t>>>8,e+2},u.prototype.writeUint16BE=u.prototype.writeUInt16BE=function(t,e,r){return t=+t,e>>>=0,r||$(this,t,e,2,65535,0),this[e]=t>>>8,this[e+1]=255&t,e+2},u.prototype.writeUint32LE=u.prototype.writeUInt32LE=function(t,e,r){return t=+t,e>>>=0,r||$(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},u.prototype.writeUint32BE=u.prototype.writeUInt32BE=function(t,e,r){return t=+t,e>>>=0,r||$(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},u.prototype.writeBigUInt64LE=Z((function(t,e=0){return C(this,t,e,BigInt(0),BigInt("0xffffffffffffffff"))})),u.prototype.writeBigUInt64BE=Z((function(t,e=0){return P(this,t,e,BigInt(0),BigInt("0xffffffffffffffff"))})),u.prototype.writeIntLE=function(t,e,r,n){if(t=+t,e>>>=0,!n){const n=Math.pow(2,8*r-1);$(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},u.prototype.writeIntBE=function(t,e,r,n){if(t=+t,e>>>=0,!n){const n=Math.pow(2,8*r-1);$(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},u.prototype.writeInt8=function(t,e,r){return t=+t,e>>>=0,r||$(this,t,e,1,127,-128),t<0&&(t=255+t+1),this[e]=255&t,e+1},u.prototype.writeInt16LE=function(t,e,r){return t=+t,e>>>=0,r||$(this,t,e,2,32767,-32768),this[e]=255&t,this[e+1]=t>>>8,e+2},u.prototype.writeInt16BE=function(t,e,r){return t=+t,e>>>=0,r||$(this,t,e,2,32767,-32768),this[e]=t>>>8,this[e+1]=255&t,e+2},u.prototype.writeInt32LE=function(t,e,r){return t=+t,e>>>=0,r||$(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},u.prototype.writeInt32BE=function(t,e,r){return t=+t,e>>>=0,r||$(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},u.prototype.writeBigInt64LE=Z((function(t,e=0){return C(this,t,e,-BigInt("0x8000000000000000"),BigInt("0x7fffffffffffffff"))})),u.prototype.writeBigInt64BE=Z((function(t,e=0){return P(this,t,e,-BigInt("0x8000000000000000"),BigInt("0x7fffffffffffffff"))})),u.prototype.writeFloatLE=function(t,e,r){return O(this,t,e,!0,r)},u.prototype.writeFloatBE=function(t,e,r){return O(this,t,e,!1,r)},u.prototype.writeDoubleLE=function(t,e,r){return N(this,t,e,!0,r)},u.prototype.writeDoubleBE=function(t,e,r){return N(this,t,e,!1,r)},u.prototype.copy=function(t,e,r,n){if(!u.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},u.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&&!u.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=u.isBuffer(t)?t:u.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 L={};function M(t,e,r){L[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 D(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 z(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 L.ERR_OUT_OF_RANGE("value",o,t)}!function(t,e,r){F(e,"offset"),void 0!==t[e]&&void 0!==t[e+r]||V(e,t.length-(r+1))}(n,o,i)}function F(t,e){if("number"!=typeof t)throw new L.ERR_INVALID_ARG_TYPE(e,"number",t)}function V(t,e,r){if(Math.floor(t)!==t)throw F(t,r),new L.ERR_OUT_OF_RANGE(r||"offset","an integer",t);if(e<0)throw new L.ERR_BUFFER_OUT_OF_BOUNDS;throw new L.ERR_OUT_OF_RANGE(r||"offset",`>= ${r?1:0} and <= ${e}`,t)}M("ERR_BUFFER_OUT_OF_BOUNDS",(function(t){return t?`${t} is outside of buffer bounds`:"Attempt to access memory outside buffer bounds"}),RangeError),M("ERR_INVALID_ARG_TYPE",(function(t,e){return`The "${t}" argument must be of type number. Received type ${typeof e}`}),TypeError),M("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=D(String(r)):"bigint"==typeof r&&(o=String(r),(r>BigInt(2)**BigInt(32)||r<-(BigInt(2)**BigInt(32)))&&(o=D(o)),o+="n"),n+=` It must be ${e}. Received ${o}`,n}),RangeError);const X=/[^+/0-9A-Za-z-_]/g;function j(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(X,"")).length<2)return"";for(;t.length%4!=0;)t+="=";return t}(t))}function H(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 K(t,e){return t instanceof e||null!=t&&null!=t.constructor&&null!=t.constructor.name&&t.constructor.name===e.name}function J(t){return t!=t}const Y=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 Z(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,a=8*o-n-1,u=(1<<a)-1,l=u>>1,c=-7,p=r?o-1:0,f=r?-1:1,d=t[e+p];for(p+=f,i=d&(1<<-c)-1,d>>=-c,c+=a;c>0;i=256*i+t[e+p],p+=f,c-=8);for(s=i&(1<<-c)-1,i>>=-c,c+=n;c>0;s=256*s+t[e+p],p+=f,c-=8);if(0===i)i=1-l;else{if(i===u)return s?NaN:1/0*(d?-1:1);s+=Math.pow(2,n),i-=l}return(d?-1:1)*s*Math.pow(2,i-n)},e.write=function(t,e,r,n,o,i){var s,a,u,l=8*i-o-1,c=(1<<l)-1,p=c>>1,f=23===o?Math.pow(2,-24)-Math.pow(2,-77):0,d=n?0:i-1,h=n?1:-1,m=e<0||0===e&&1/e<0?1:0;for(e=Math.abs(e),isNaN(e)||e===1/0?(a=isNaN(e)?1:0,s=c):(s=Math.floor(Math.log(e)/Math.LN2),e*(u=Math.pow(2,-s))<1&&(s--,u*=2),(e+=s+p>=1?f/u:f*Math.pow(2,1-p))*u>=2&&(s++,u/=2),s+p>=c?(a=0,s=c):s+p>=1?(a=(e*u-1)*Math.pow(2,o),s+=p):(a=e*Math.pow(2,p-1)*Math.pow(2,o),s=0));o>=8;t[r+d]=255&a,d+=h,a/=256,o-=8);for(s=s<<o|a,l+=o;l>0;t[r+d]=255&s,d+=h,s/=256,l-=8);t[r+d-h]|=128*m}},387(t,e,r){r.d(e,{GW:()=>i});var n,o=r(564);!function(t){t.MAINNET="1",t.DEVNET="D"}(n||(n={}));class i{apiUrl;chain;init;config;constructor(t){if(!t?.apiUrl?.trim())throw new Error("XOXNOClient: apiUrl is required");const{chain:e=n.MAINNET,apiUrl:r,...i}=t;this.apiUrl=r.trim().replace(/\/$/,""),this.chain=e,this.init=i,this.config=e==n.MAINNET?{mediaUrl:"https://media.xoxno.com",gatewayUrl:"https://gateway.xoxno.com",XO_SC:o.s0,FM_SC:o.ZZ,DR_SC:o.sM,KG_SC:o.KL,Staking_SC:o.V,Manager_SC:o.Rh,P2P_SC:o.EP}:{mediaUrl:"https://devnet-media.xoxno.com",gatewayUrl:"https://devnet-gateway.xoxno.com",XO_SC:o.cM,FM_SC:o.ZZ,DR_SC:o.sM,KG_SC:o.KL,Staking_SC:o.J6,Manager_SC:o.Ff,P2P_SC:o.gx}}fetchWithTimeout=async(t,{params:e,...r}={})=>{const{next:n,cache:o,debug:i,timeout:s,...a}=this.init,{next:u,cache:l,debug:c,timeout:p,headers:f,method:d="GET",...h}=r,m=f?.Authorization,g="Bearer undefined"===m?void 0:m,y="GET"!==d&&"HEAD"!==d&&"PUT"!==d,w={...f,Referer:"https://xoxno.sdk","User-Agent":"XOXNO/1.0/SDK",...y?{"Content-Type":"application/json"}:{},...g?{Authorization:g}:{}},b=Object.entries(e??{}).filter((([,t])=>void 0!==t)).flatMap((([t,e])=>Array.isArray(e)?e.filter((t=>void 0!==t)).map((e=>`${t}=${encodeURIComponent(e)}`)):`${t}=${encodeURIComponent(e)}`)).join("&"),v=`${this.apiUrl}${t}${b.length?`?${b}`:""}`,{revalidate:B,...S}=n??{},{revalidate:_,...I}=u??{},q="GET"!==d||g?void 0:_??B,R="GET"!==d||g||q?void 0:l??o,x=h.body,k=p??s??(null==x?3e4:0),E=k>0?AbortSignal.timeout(k):void 0,A=h.signal??a.signal,U=E&&A?AbortSignal.any([A,E]):E??A,T={...a,...h,method:d,...Object.keys(w).length?{headers:w}:{},...U?{signal:U}:{},cache:R,next:{...S,...I,revalidate:q}};(c??i)&&console.debug("SDK fetch: ",v,T);const $=await fetch(v,T).catch((t=>{if(t instanceof Error&&!t.message.match(/^http(s?):\/\//))throw Object.assign(new Error(`${v}: ${t.message}`),{cause:t});throw t})),C=await $.text();if(!$.ok){let t;try{t=JSON.parse(C)}catch{t={message:C}}const e=[v,$.status,$.statusText,t.message].filter(Boolean).join(";;");throw new Error(e)}try{return JSON.parse(C)}catch{return C}}}},564(t,e,r){r.d(e,{EP:()=>l,Ff:()=>f,J6:()=>p,KL:()=>s,Rh:()=>u,V:()=>a,ZZ:()=>o,cM:()=>c,gx:()=>d,s0:()=>n,sM:()=>i});const n="erd1qqqqqqqqqqqqqpgq6wegs2xkypfpync8mn2sa5cmpqjlvrhwz5nqgepyg8",o="erd1qqqqqqqqqqqqqpgq705fxpfrjne0tl3ece0rrspykq88mynn4kxs2cg43s",i="erd1qqqqqqqqqqqqqpgqd9rvv2n378e27jcts8vfwynpx0gfl5ufz6hqhfy0u0",s="erd1qqqqqqqqqqqqqpgq8xwzu82v8ex3h4ayl5lsvxqxnhecpwyvwe0sf2qj4e",a="erd1qqqqqqqqqqqqqpgqvpkd3g3uwludduv3797j54qt6c888wa59w2shntt6z",u="erd1qqqqqqqqqqqqqpgqg9fa0dmpn8fu3fnleeqn5zt8rl8mdqjkys5s2gtas7",l="erd1qqqqqqqqqqqqqpgq47y8hnct68v6asjv6gxem6h9rumn9frzah0skhxxt6",c="erd1qqqqqqqqqqqqqpgql0dnz6n5hpuw8cptlt00khd0nn4ja8eadsfq2xrqw4",p="erd1qqqqqqqqqqqqqpgqsc5hnewwpep8qq0d7kjjzrquapuucrygah0s85zres",f="erd1qqqqqqqqqqqqqpgqluclyhfsa2uw7q9cjwd8knk989hg57u8ah0slq2nlr",d="erd1qqqqqqqqqqqqqpgqfja7ukpngrun78ueq583l0vd6aj4ekhrah0sa9wyrv"}},l={};function c(t){var e=l[t];if(void 0!==e)return e.exports;var r=l[t]={exports:{}};return u[t](r,r.exports,c),r.exports}c.d=(t,e)=>{for(var r in e)c.o(e,r)&&!c.o(t,r)&&Object.defineProperty(t,r,{enumerable:!0,get:e[r]})},c.o=(t,e)=>Object.prototype.hasOwnProperty.call(t,e);var p=c(387);const f={stellarMainnet:{name:"mainnet",passphrase:"Public Global Stellar Network ; September 2015",horizonUrl:"https://horizon.stellar.org",sorobanRpcUrl:"https://stellar-gateway.xoxno.com",quoteUrl:"https://stellar-swap.xoxno.com",explorerNetwork:"public",aquariusApiUrl:"https://amm-api.aqua.network",aquariusRouter:"CBQDHNBFBZYE4MKPWBSJOPIYLW4SFSXAXUTSXJN76GNKYVYPCKWC6QUK",lendingController:"CAUCMIN5KSXEVZ7NMXR3LZATGD5EFIEUI5XWTFLYRO2R5OTXI22WE5JX",aggregatorRouter:"CCVENFSVCBYDHVOACFZXMNNYVOZ3LKXPZYU5LUI4N7KTXOKRVYD7F3TR",governance:"CC44PEQW7HSEPKAZ5ZRPH2JS5M5KVJXCUBLJ2ZX4E3WCDKMNFILHC2AD",priceAggregator:"CBGUF2G2Q7HCVCWYISDXBHPVBGMYNXA7PG2VET66YBZX6IKOOV27NSMV",positionNftContract:"CAWCSG77AY2W24QZ6ZXLHZU4UXEFHZBM6EI4A4IF7JB5CTY4XND3TI6C"},stellarTestnet:{name:"testnet",passphrase:"Test SDF Network ; September 2015",horizonUrl:"https://horizon-testnet.stellar.org",sorobanRpcUrl:"https://stellar-testnet-gateway.xoxno.com",quoteUrl:"https://testnet-stellar-swap.xoxno.com",explorerNetwork:"testnet",aquariusApiUrl:"https://amm-api-testnet.aqua.network",aquariusRouter:"CBCFTQSPDBAIZ6R6PJQKSQWKNKWH2QIV3I4J72SHWBIK3ADRRAM5A6GD",lendingController:"CCXRWJ6SIU2WPFEGLFGJVITPL57QAYIMIO6OAM2NBGNDQSSCK2FFV3F3",aggregatorRouter:"CDNTWMWW2WGYTKIZTJYNGNVQQZI4KTC5BQRZ3275KESRX5T4O3AYECL5",governance:"CDS33JDOYH3F3FL4QUQ6DV4WKHML2AKHF4LADTZ57FRUAEBTE7NMY5FQ",priceAggregator:"CAALOOTIDXCX7D7FMQIBSSAJLPKOM3GMXS4UUSTDIG42JCRRJHOPUHOP",positionNftContract:"CDVN5JU675MEDPVRPCYC45AHFC275UH57WEU5OTFE4WFGZBNN7HTLPSY"}},d=f;function h(t){return f["testnet"===t?"stellarTestnet":"stellarMainnet"]}const m={mainnet:f.stellarMainnet.passphrase,testnet:f.stellarTestnet.passphrase};var g=c(287);const y=["Soroswap","Aquarius","Phoenix","Sushi","CometDex"],w={Soroswap:0,Aquarius:1,Phoenix:2,Sushi:3,CometDex:4},b=1e6,v=t=>new e(t).toScVal(),B=t=>new o(t).toI128(),S=t=>a.ScVal.scvU32(t),_=t=>{if("number"==typeof t&&!Number.isSafeInteger(t))throw new Error("Stellar builder: u64 numbers must be safe integers; pass a decimal string for larger values");return new o("string"==typeof t?t:t.toString()).toU64()},I=t=>a.ScVal.scvBool(t),q=t=>a.ScVal.scvString(t),R=t=>a.ScVal.scvSymbol(t),x=()=>a.ScVal.scvVoid(),k=t=>a.ScVal.scvVec(t),E=(t,e=32)=>{const r=t.startsWith("0x")?t.slice(2):t,n=g.hp.from(r,"hex");if(n.length!==e)throw new Error(`Stellar builder: expected a ${e}-byte BytesN (got ${n.length} bytes from "${t}")`);return a.ScVal.scvBytes(n)},A=(t,e)=>null==t?x():e(t),U=(t,e)=>P({asset:v(e),hub_id:S(t)}),T=(t,e,r)=>a.ScVal.scvVec([U(t,e),B(r)]),$=t=>a.ScVal.scvVec(t.map((t=>T(t.hubId,t.asset,t.amount)))),C=t=>{if("Transfer"===t)return k([R("Transfer")]);if(t&&"object"==typeof t&&"Credit"in t){const e=t.Credit;if("number"==typeof e&&!Number.isInteger(e))throw new Error(`Stellar builder: SeizeMode Credit account id must be an integer u64, got ${e}`);return k([R("Credit"),_(e)])}throw new Error(`Stellar builder: SeizeMode must be 'Transfer' or { Credit: accountId }, got ${JSON.stringify(t)}`)},P=t=>{const e=Object.keys(t).sort().map((e=>new a.ScMapEntry({key:R(e),val:t[e]})));return a.ScVal.scvMap(e)};class W{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>=256)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>=126)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>=32)throw new Error("Stellar builder: strategy uses more than 32 split weights");if(!Number.isInteger(t)||t<=0||t>b)throw new Error(`Stellar builder: split weight ${t} outside 1..=1000000`);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(w[r.venue],0===n?e:1,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>b)throw new Error(`Stellar builder: split weights for one token sum to ${i}, above 1000000`);const s=i===b;let a=b;o.forEach(((t,n)=>{r[t]=!0;const i=e[t];let u;if(n+1===o.length&&s)u=0;else{if(0===a)throw new Error("Stellar builder: split weights exhaust the group before its last path");const t=Math.floor(i.splitPpm*b/a);a-=Math.min(i.splitPpm,a),u=128+this.weight(t)}this.emitPath(i,u)}))}}toBytes(t,e,r){if(0===this.ops.length)throw new Error("Stellar builder: strategy lowered to zero instructions");if(this.ops.length>48)throw new Error(`Stellar builder: strategy has ${this.ops.length} instructions, the router accepts 48`);const n=[1,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 g.hp.from(n)}get assetList(){return this.assets}get amountList(){return this.amounts}}const O=t=>{const e=new W(t.totalMinOut),r=e.asset(t.tokenIn),n=e.asset(t.tokenOut);if(r===n)throw new Error("Stellar builder: `tokenIn` and `tokenOut` are the same asset");if(t.burnPool){const n=e.asset(t.burnPool),o=e.amountList.length;for(const r of t.burnMinAmounts??[])e.amount(r);e.emit(5,0,n,r,o)}if(e.lowerPaths(t.paths),t.mintPool){const r=t.preSwapAmount;if(r&&BigInt(r)>0n){const n=t.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,a]=t.preSwapFromA?[o,i]:[i,o];e.emit(w.Aquarius,2+e.amount(r),e.asset(t.mintPool),e.asset(s),e.asset(a))}e.emit(6,0,e.asset(t.mintPool),n,e.amount(t.mintMinShares??"1"))}const o=Number(t.referralId??0);if(!Number.isInteger(o)||o<0||o>4294967295)throw new Error(`Stellar builder: referral id ${t.referralId} does not fit the wire’s u32`);return P({amounts:a.ScVal.scvVec(e.amountList.map((t=>B(t)))),assets:a.ScVal.scvVec(e.assetList.map((t=>v(t)))),ops:a.ScVal.scvBytes(e.toBytes(r,n,o))})},N=t=>{const e=g.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 a.ScVal.scvBytes(e)},L=()=>a.ScVal.scvBytes(g.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 g.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=g.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},D=t=>{if("string"==typeof t)return N(M(t));if(t instanceof Uint8Array)return 0===t.length?L():N(t);if(t&&"object"==typeof t)return"routeXdr"in(r=t)&&"string"==typeof r.routeXdr?N(M(t.routeXdr)):(t=>"swapXdr"in t&&"string"==typeof t.swapXdr)(t)?N(M(t.swapXdr)):(t=>"bytes"in t&&("string"==typeof t.bytes||t.bytes instanceof Uint8Array))(t)?"string"==typeof t.bytes?N(M(t.bytes)):0===t.bytes.length?L():N(t.bytes):(e=(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||!y.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>b)throw new Error(`Stellar builder: \`steps.paths[].splitPpm\` for ${t} sums to ${n}, above 1000000`);if(!e.mintPool&&n!==b)throw new Error(`Stellar builder: \`steps.paths[].splitPpm\` for ${t} must sum to 1000000, got ${n}`)}return e})(t),a.ScVal.scvBytes(g.hp.from(O(e).toXDR("base64"),"base64")));var e,r;throw new Error("Stellar builder: `steps` must be opaque strategy bytes (`routeXdr`, base64/hex string, or Uint8Array)")},z=t=>{if("string"==typeof t)return(t=>{const e=t.startsWith("0x")?t.slice(2):t,r=g.hp.from(e,"hex");return a.ScVal.scvBytes(r)})(t);if(t instanceof Uint8Array)return a.ScVal.scvBytes(g.hp.from(t));throw new Error("Stellar builder: `data` must be a hex string or Uint8Array (Soroban Bytes payload)")};function F(e,o,s){if(!e.controllerAddress)throw new Error("Stellar lending controllerAddress is required");const a=new n(e.controllerAddress),u=new t(e.caller,e.sourceSequence);return{xdr:new i(u,{fee:e.fee??r,networkPassphrase:m[e.network]}).addOperation(a.call(o,...s)).setTimeout(e.timeoutSeconds??300).build().toXDR()}}function V(t){if(!Number.isInteger(t)||t<1||t>4294967295)throw new Error("Stellar builder: spokeId must be an integer from 1 to 4294967295");return S(t)}function X(t,e){const r=e.accountNonce??0;return F(t,"supply",[v(t.caller),_(r),V(e.spokeId),$([...e.assets])])}function j(t,e){return X(t,{accountNonce:e.accountNonce,spokeId:e.spokeId,assets:[{hubId:e.hubId,asset:e.asset,amount:e.amount}]})}function G(t,e){return F(t,"borrow",[v(t.caller),_(e.accountNonce),$([...e.borrows]),A(e.to,v)])}function H(t,e){return G(t,{accountNonce:e.accountNonce,borrows:[{hubId:e.hubId,asset:e.asset,amount:e.amount}],to:e.to})}function K(t,e){return F(t,"withdraw",[v(t.caller),_(e.accountNonce),$([...e.withdrawals]),A(e.to,v)])}function J(t,e){return K(t,{accountNonce:e.accountNonce,withdrawals:[{hubId:e.hubId,asset:e.asset,amount:e.amount}],to:e.to})}function Y(t,e){return F(t,"repay",[v(t.caller),_(e.accountNonce),$([...e.payments])])}function Z(t,e){return Y(t,{accountNonce:e.accountNonce,payments:[{hubId:e.hubId,asset:e.asset,amount:e.amount}]})}function Q(t,e){return F(t,"liquidate",[v(t.caller),_(e.accountNonce),$([...e.debtPayments]),C(e.seizeMode??"Transfer")])}function tt(t){const e=s(a.ScVal.fromXDR(t,"base64"));if("bigint"==typeof e||"number"==typeof e)return e.toString();throw new Error("Stellar builder: liquidate return value must be a u64, got "+typeof e)}function et(t,e){return F(t,"flash_loan",[v(t.caller),U(e.hubId,e.asset),B(e.amount),v(e.receiver),z(e.data)])}function rt(t,e){return F(t,"migrate_from_blend",[v(t.caller),_(e.accountId),V(e.spokeId),S(e.hubId),v(e.blendPool),k(e.collateralTokens.map(v)),k(e.supplyTokens.map(v)),(r=e.debtCaps.map((t=>({token:t.token,amount:t.cap}))),a.ScVal.scvVec(r.map((t=>{return e=t.token,r=t.amount,a.ScVal.scvVec([v(e),B(r)]);var e,r}))))]);var r}function nt(t,e){const r=e.accountNonce??0;return F(t,"multiply",[v(t.caller),_(r),V(e.spokeId),U(e.collateral.hubId,e.collateral.asset),B(e.debtToFlashLoan),U(e.debt.hubId,e.debt.asset),S(e.mode),D(e.steps),A(e.initialPayment,(t=>T(t.hubId,t.asset,t.amount))),A(e.convertSwap,D)])}function ot(t,e){return F(t,"swap_debt",[v(t.caller),_(e.accountNonce),U(e.existingDebt.hubId,e.existingDebt.asset),B(e.newDebtAmount),U(e.newDebt.hubId,e.newDebt.asset),D(e.steps)])}function it(t,e){return F(t,"swap_collateral",[v(t.caller),_(e.accountNonce),U(e.current.hubId,e.current.asset),B(e.fromAmount),U(e.newCollateral.hubId,e.newCollateral.asset),D(e.steps)])}function st(t,e){return F(t,"repay_debt_with_collateral",[v(t.caller),_(e.accountNonce),U(e.collateral.hubId,e.collateral.asset),B(e.collateralAmount),U(e.debt.hubId,e.debt.asset),D(e.steps),I(e.closePosition)])}const at="/stellar-lending",ut=encodeURIComponent,lt=(t,e)=>t.fetchWithTimeout(`${at}/context`,e),ct=(t,e)=>t.fetchWithTimeout(`${at}/live-state`,e),pt=(t,e)=>t.fetchWithTimeout(`${at}/markets/detailed`,e),ft=(t,e)=>t.fetchWithTimeout(`${at}/assets`,e),dt=(t,e)=>t.fetchWithTimeout(`${at}/hubs`,e),ht=(t,e)=>t.fetchWithTimeout(`${at}/spokes`,e),mt=(t,e={},r)=>t.fetchWithTimeout(`${at}/reserves`,{...r,params:{...e}}),gt=(t,e,r,n,o)=>t.fetchWithTimeout(`${at}/reserves/${e}/${r}/${ut(n)}`,o),yt=(t,e,r)=>t.fetchWithTimeout(`${at}/assets/${ut(e)}`,r),wt=(t,e,r)=>t.fetchWithTimeout(`${at}/hubs/${e}`,r),bt=(t,e,r)=>t.fetchWithTimeout(`${at}/spokes/${e}`,r),vt=(t,e,r)=>t.fetchWithTimeout(`${at}/users/${ut(e)}/positions`,r),Bt=(t,e,r)=>t.fetchWithTimeout(`${at}/accounts/${ut(e)}/positions`,r),St=(t,e,r,n)=>t.fetchWithTimeout(`${at}/users/${ut(e)}/assets/${ut(r)}/balance`,n),_t=(t,e,r,n)=>t.fetchWithTimeout(`${at}/assets/${ut(e)}/page`,{...n,params:{...r}}),It=(t,e,r,n)=>t.fetchWithTimeout(`${at}/assets/${ut(e)}/markets`,{...n,params:{side:r}}),qt=(t,e,r,n,o,i)=>t.fetchWithTimeout(`${at}/reserves/${e}/${r}/${ut(n)}/holders`,{...i,params:{side:o}}),Rt=(t,e,r,n)=>t.fetchWithTimeout(`${at}/hubs/${e}/holders`,{...n,params:{side:r}}),xt=(t,e,r,n)=>t.fetchWithTimeout(`${at}/spokes/${e}/holders`,{...n,params:{side:r}}),kt=(t,e,r,n)=>t.fetchWithTimeout(`${at}/assets/${ut(e)}/graph`,{...n,params:{...r}}),Et=(t,e,r,n)=>t.fetchWithTimeout(`${at}/hubs/${e}/graph`,{...n,params:{...r}}),At=(t,e,r,n)=>t.fetchWithTimeout(`${at}/spokes/${e}/graph`,{...n,params:{...r}}),Ut=(t,e,r,n,o,i)=>t.fetchWithTimeout(`${at}/reserves/${e}/${r}/${ut(n)}/graph`,{...i,params:{...o}}),Tt=(t,e,r={},n)=>t.fetchWithTimeout(`${at}/users/${ut(e)}/activity`,{...n,params:{...r}}),$t=(t,e,r={},n)=>t.fetchWithTimeout(`${at}/users/${ut(e)}/activity/page`,{...n,params:{...r}}),Ct=(t,e={},r)=>t.fetchWithTimeout(`${at}/governance/proposals`,{...r,params:{...e}}),Pt=(t,e={},r)=>t.fetchWithTimeout(`${at}/positions`,{...r,params:{...e}}),Wt=(t,e={},r)=>t.fetchWithTimeout(`${at}/participants`,{...r,params:{...e}}),Ot=(t,e={},r)=>t.fetchWithTimeout(`${at}/liquidations/leaderboard`,{...r,params:{...e}}),Nt=(t,e={},r)=>t.fetchWithTimeout(`${at}/distribution`,{...r,params:{...e}}),Lt=(t,e={},r)=>t.fetchWithTimeout(`${at}/campaign/leaderboard`,{...r,params:{...e}}),Mt=(t,e,r)=>t.fetchWithTimeout(`${at}/stats/history`,{...r,params:{...e}}),Dt=(t,e,r)=>t.fetchWithTimeout(`${at}/revenue`,{...r,params:{...e}}),zt=(t,e,r)=>t.fetchWithTimeout(`${at}/revenue/fees`,{...r,params:{...e}}),Ft=(t,e,r)=>t.fetchWithTimeout(`${at}/liquidations`,{...r,params:{...e}}),Vt=(t,e,r)=>t.fetchWithTimeout(`${at}/volume`,{...r,params:{...e}}),Xt=(t,e,r)=>t.fetchWithTimeout(`${at}/active-users`,{...r,params:{...e}}),jt=(t,e,r)=>t.fetchWithTimeout(`${at}/rate-spread`,{...r,params:{...e}}),Gt=(t,e,r)=>t.fetchWithTimeout(`${at}/defillama`,{...r,params:{...e}}),Ht=(t,e,r,n)=>t.fetchWithTimeout(`${at}/users/${ut(e)}/history`,{...n,params:{...r}}),Kt=(t,e,r)=>t.fetchWithTimeout(`${at}/pnl`,{...r,params:{accountId:e}}),Jt=(t,e,r)=>t.fetchWithTimeout(`${at}/pnl/scope`,{...r,params:{scope:e}}),Yt=(t,e,r)=>t.fetchWithTimeout(`${at}/campaign/me`,{...r,params:{owner:e}}),Zt=t=>({context:e=>lt(t,e),liveState:e=>ct(t,e),marketsDetailed:e=>pt(t,e),assets:e=>ft(t,e),hubs:e=>dt(t,e),spokes:e=>ht(t,e),reserves:(e={},r)=>void 0!==r||"hubId"in e||"spokeId"in e||"asset"in e?mt(t,e,r):mt(t,{},e),reserve:(e,r,n,o)=>gt(t,e,r,n,o),asset:(e,r)=>yt(t,e,r),hub:(e,r)=>wt(t,e,r),spoke:(e,r)=>bt(t,e,r),userPositions:(e,r)=>vt(t,e,r),accountPositions:(e,r)=>Bt(t,e,r),walletBalance:(e,r,n)=>St(t,e,r,n),assetPage:(e,r,n)=>_t(t,e,r,n),assetMarkets:(e,r,n)=>It(t,e,r,n),reserveHolders:(e,r,n,o,i)=>qt(t,e,r,n,o,i),hubHolders:(e,r,n)=>Rt(t,e,r,n),spokeHolders:(e,r,n)=>xt(t,e,r,n),assetGraph:(e,r,n)=>kt(t,e,r,n),hubGraph:(e,r,n)=>Et(t,e,r,n),spokeGraph:(e,r,n)=>At(t,e,r,n),reserveGraph:(e,r,n,o,i)=>Ut(t,e,r,n,o,i),userActivity:(e,r={},n)=>Tt(t,e,r,n),userActivityPage:(e,r={},n)=>$t(t,e,r,n),governanceProposals:(e={},r)=>Ct(t,e,r),positionsLeaderboard:(e={},r)=>Pt(t,e,r),participants:(e={},r)=>Wt(t,e,r),liquidationsLeaderboard:(e={},r)=>Ot(t,e,r),distribution:(e={},r)=>Nt(t,e,r),campaignLeaderboard:(e={},r)=>Lt(t,e,r),statsHistory:(e,r)=>Mt(t,e,r),revenue:(e,r)=>Dt(t,e,r),feeRevenue:(e,r)=>zt(t,e,r),liquidations:(e,r)=>Ft(t,e,r),volume:(e,r)=>Vt(t,e,r),activeUsers:(e,r)=>Xt(t,e,r),rateSpread:(e,r)=>jt(t,e,r),defillama:(e,r)=>Gt(t,e,r),userHistory:(e,r,n)=>Ht(t,e,r,n),positionsPnl:(e,r)=>Kt(t,e,r),pnlByScope:(e,r)=>Jt(t,e,r),campaignMe:(e,r)=>Yt(t,e,r)}),Qt=t=>P({base_borrow_rate:B(t.baseBorrowRateRay),max_borrow_rate:B(t.maxBorrowRateRay),max_utilization:B(t.maxUtilizationRay),mid_utilization:B(t.midUtilizationRay),optimal_utilization:B(t.optimalUtilizationRay),reserve_factor:S(t.reserveFactorBps),slope1:B(t.slope1Ray),slope2:B(t.slope2Ray),slope3:B(t.slope3Ray)}),te=t=>P({asset_decimals:S(t.assetDecimals),asset_id:v(t.assetId),base_borrow_rate:B(t.baseBorrowRateRay),flashloan_fee:S(t.flashloanFeeBps),is_flashloanable:I(t.isFlashloanable),max_borrow_rate:B(t.maxBorrowRateRay),max_utilization:B(t.maxUtilizationRay),mid_utilization:B(t.midUtilizationRay),optimal_utilization:B(t.optimalUtilizationRay),reserve_factor:S(t.reserveFactorBps),slope1:B(t.slope1Ray),slope2:B(t.slope2Ray),slope3:B(t.slope3Ray)}),ee=t=>P({max_borrow_positions:S(t.maxBorrowPositions),max_supply_positions:S(t.maxSupplyPositions)}),re=t=>{if("Token"in t&&t.Token)return k([R("Token"),v(t.Token)]);if("Ref"in t&&t.Ref)return k([R("Ref"),R(t.Ref)]);throw new Error(`Stellar builder: PriceKey must be { Token } or { Ref }, got ${JSON.stringify(t)}`)},ne=t=>{if("Stellar"in t)return k([R("Stellar"),v(t.Stellar)]);if("Symbol"in t)return k([R("Symbol"),R(t.Symbol)]);if("String"in t)return k([R("String"),q(t.String)]);throw new Error(`Stellar builder: unknown OracleAssetRef ${JSON.stringify(t)}`)},oe=t=>{if("Spot"===t)return k([R("Spot")]);if(t&&"object"==typeof t&&"Twap"in t)return k([R("Twap"),S(Number(t.Twap))]);throw new Error(`Stellar builder: unknown OracleReadMode ${JSON.stringify(t)}`)},ie=t=>{if("Reflector"===t||"RedStone"===t||"Xoxno"===t)return k([R(t)]);throw new Error(`Stellar builder: unknown ProviderKind "${t}"`)},se=t=>{if("Market"===t||"Fundamental"===t)return k([R(t)]);throw new Error(`Stellar builder: unknown FeedNature "${t}"`)},ae=t=>{if("Reflector"in t){const e=t.Reflector;return k([R("Reflector"),P({asset:ne(e.asset),contract:v(e.contract),read_mode:oe(e.readMode)})])}if("MultiFeed"in t){const e=t.MultiFeed;return k([R("MultiFeed"),P({contract:v(e.contract),feed_id:q(e.feedId),kind:ie(e.kind),nature:se(e.nature)})])}throw new Error(`Stellar builder: unknown ProviderRef ${JSON.stringify(t)}`)},ue=t=>{const e=t;return P({decimals:S(e.decimals),max_stale_seconds:_(e.maxStaleSeconds),provider:ae(e.provider)})},le=t=>{if("RequireDisjoint"===t)return k([R("RequireDisjoint")]);if(t&&"object"==typeof t&&"AllowShared"in t){const e=t.AllowShared;return k([R("AllowShared"),k(e.map((t=>P({contract:v(t.contract),kind:ie(t.kind)}))))])}throw new Error(`Stellar builder: unknown IndependencePolicy ${JSON.stringify(t)}`)},ce=t=>{const e=t,r=e.sources??[];let n,o;if("number"==typeof e.toleranceBps)n=1e4+e.toleranceBps,o=Math.max(1,Math.floor(1e8/n));else{const t=e.tolerance??{};n=Number(t.upperRatioBps),o=Number(t.lowerRatioBps)}return P({asset_decimals:S(Number(e.assetDecimals)),independence:le(e.independence),max_price_stale_seconds:_(Number(e.maxPriceStaleSeconds)),max_sanity_price_wad:B(String(e.maxSanityPriceWad)),min_sanity_price_wad:B(String(e.minSanityPriceWad)),sources:k(r.map((t=>(t=>{if("Feed"in t)return k([R("Feed"),ue(t.Feed)]);if("Scaled"in t){const e=t.Scaled;return k([R("Scaled"),P({factor:ue(e.factor),max_factor_wad:B(e.maxFactorWad),min_factor_wad:B(e.minFactorWad),quote:re(e.quote)})])}if("LpShare"in t){const e=t.LpShare;return k([R("LpShare"),P({key_a:re(e.keyA),key_b:re(e.keyB),kind:k([R(e.kind||"ConstantProduct")]),pool:v(e.pool),reserve_a_decimals:S(e.reserveADecimals),reserve_b_decimals:S(e.reserveBDecimals),share_decimals:S(e.shareDecimals)})])}throw new Error(`Stellar builder: unknown PriceSource ${JSON.stringify(t)}`)})(t)))),tolerance:P({lower_ratio_bps:S(o),upper_ratio_bps:S(n)})})},pe=ce;function fe(t,e){return F(t,"upgrade",[E(e.wasmHash)])}function de(t,e){return F(t,"migrate",[S(e.newVersion)])}function he(t){return F(t,"pause",[])}function me(t){return F(t,"unpause",[])}function ge(t,e){return F(t,"grant_role",[v(e.account),R(e.role)])}function ye(t,e){return F(t,"revoke_role",[v(e.account),R(e.role)])}function we(t,e){return F(t,"transfer_ownership",[v(e.newOwner),S(e.liveUntilLedger)])}function be(t){return F(t,"accept_ownership",[])}function ve(t,e){return F(t,"set_swap_aggregator",[v(e.aggregator)])}function Be(t,e){return F(t,"set_price_aggregator",[v(e.aggregator)])}const Se=ve;function _e(t,e){return F(t,"set_accumulator",[v(e.accumulator)])}function Ie(t,e){return F(t,"set_position_limits",[ee(e)])}function qe(t,e){return F(t,"approve_blend_pool",[v(e.pool)])}function Re(t,e){return F(t,"revoke_blend_pool",[v(e.pool)])}const xe=qe,ke=Re;function Ee(t,e){return F(t,"set_oracle",[re(e.key),ce(e.oracle)])}const Ae=Ee;function Ue(t,e){const r=e.toleranceBps,n=e.upperRatioBps??1e4+r,o=e.lowerRatioBps??Math.max(1,Math.floor(1e8/n));return F(t,"set_tolerance",[re(e.key),P({lower_ratio_bps:S(o),upper_ratio_bps:S(n)})])}function Te(t,e){return F(t,"set_spoke_asset_flags",[S(e.spokeId),U(e.hubId,e.asset),I(e.paused),I(e.frozen),I(e.noSeize)])}function $e(t,e){return F(t,"set_oracle_sanity_bounds",[v(e.asset),B(e.minPriceWad),B(e.maxPriceWad)])}function Ce(t,e){return F(t,"update_indexes",[v(t.caller),k(e.assets.map((t=>U(t.hubId,t.asset))))])}function Pe(t,e){return F(t,"renew_account",[v(t.caller),_(e.accountNonce)])}function We(t,e){return F(t,"create_liquidity_pool",[S(e.hubId),v(e.asset),te(e.params)])}function Oe(t,e){return F(t,"upgrade_liquidity_pool_params",[U(e.hubId,e.asset),Qt(e.params)])}function Ne(t,e){return F(t,"claim_revenue",[v(t.caller),k(e.assets.map((t=>U(t.hubId,t.asset))))])}function Le(t,e){return F(t,"add_rewards",[v(t.caller),$(e.rewards)])}function Me(t,e){return F(t,"update_account_threshold",[v(t.caller),I(e.hasRisks),k(e.accountNonces.map((t=>_(t))))])}const De="00".repeat(32),ze=t=>{if("string"==typeof t)return E(t);const e=g.hp.from(t);if(32!==e.length)throw new Error(`Stellar governance builder: expected a 32-byte salt (got ${e.length} bytes)`);return a.ScVal.scvBytes(e)},Fe=(t,...e)=>k([R(t),...e]),Ve=t=>P({new_owner:v(t.newOwner),live_until_ledger:S(t.liveUntilLedger)}),Xe=t=>P({asset:v(t.asset),bonus:S(t.bonus),borrow_cap:B(t.borrowCap),can_borrow:I(t.canBorrow),can_collateral:I(t.canCollateral),frozen:I(t.frozen),hub_id:S(t.hubId),paused:I(t.paused),liquidation_fees:S(t.liquidationFees),ltv:S(t.ltv),no_seize:I(t.noSeize),spoke_id:S(t.spokeId),supply_cap:B(t.supplyCap),threshold:S(t.threshold)}),je=t=>P({account:v(t.account),role:R(t.role)});function Ge(e,o,s){if(!e.governanceAddress)throw new Error("Stellar governanceAddress is required");const a=new n(e.governanceAddress),u=new t(e.caller,e.sourceSequence);return{xdr:new i(u,{fee:e.fee??r,networkPassphrase:m[e.network]}).addOperation(a.call(o,...s)).setTimeout(e.timeoutSeconds??300).build().toXDR()}}const He=(t,e,r)=>Ge(t,"propose",[v(t.caller),e,ze(r)]),Ke=(t,e,r)=>Ge(t,"execute_self",[x(),e,ze(r)]);function Je(t,e,r){return He(t,Fe("SetSwapAggregator",v(e.aggregator)),r)}function Ye(t,e,r){return He(t,Fe("SetPriceAggregator",v(e.aggregator)),r)}const Ze=Je;function Qe(t,e,r){return He(t,Fe("SetAccumulator",v(e.accumulator)),r)}function tr(t,e,r){return He(t,Fe("SetPositionLimits",ee(e)),r)}function er(t,e){return He(t,Fe("CreateHub"),e)}function rr(t,e){return He(t,Fe("AddSpoke"),e)}function nr(t,e,r){return He(t,Fe("RemoveSpoke",S(e.spokeId)),r)}function or(t,e,r){return He(t,Fe("AddAssetToSpoke",Xe(e)),r)}function ir(t,e,r){return He(t,Fe("EditAssetInSpoke",Xe(e)),r)}function sr(t,e,r){return He(t,Fe("RemoveAssetFromSpoke",P({hub_asset:U((n=e).hubId,n.asset),spoke_id:S(n.spokeId)})),r);var n}function ar(t,e,r){return He(t,Fe("SetSpokeLiquidationCurve",P({hf_for_max_bonus_wad:B((n=e).hfForMaxBonusWad),liquidation_bonus_factor_bps:S(n.liquidationBonusFactorBps),spoke_id:S(n.spokeId),target_hf_wad:B(n.targetHfWad)})),r);var n}function ur(t,e,r){return He(t,Fe("SetPositionManager",v(e.manager),I(e.isActive)),r)}function lr(t,e,r){return He(t,Fe("SetMinBorrowCollateralUsd",B(e.floorWad)),r)}function cr(t,e,r){return He(t,Fe("ApproveToken",v(e.token)),r)}function pr(t,e,r){return He(t,Fe("RevokeToken",v(e.token)),r)}function fr(t,e,r){return He(t,Fe("ApproveBlendPool",v(e.pool)),r)}function dr(t,e,r){return He(t,Fe("RevokeBlendPool",v(e.pool)),r)}function hr(t,e,r){return He(t,Fe("CreateLiquidityPool",P({asset:v((n=e).asset),hub_id:S(n.hubId),params:te(n.params)})),r);var n}function mr(t,e,r){return He(t,Fe("UpgradeLiquidityPoolParams",P({hub_asset:U((n=e).hubId,n.asset),params:Qt(n.params)})),r);var n}function gr(t,e,r){return He(t,Fe("DeployPool",E(e.wasmHash)),r)}function yr(t,e,r){return He(t,Fe("UpgradePool",E(e.wasmHash)),r)}function wr(t,e,r){return He(t,Fe("UpgradeController",E(e.wasmHash)),r)}function br(t,e,r){return He(t,Fe("MigrateController",S(e.newVersion)),r)}function vr(t,e,r){return He(t,Fe("TransferCtrlOwnership",Ve(e)),r)}function Br(t,e,r){return He(t,Fe("ConfigureAssetOracle",P({key:re((n=e).key),oracle:ce(n.oracle)})),r);var n}const Sr=Br;function _r(t,e,r){return He(t,Fe("EditOracleTolerance",P({key:re((n=e).key),tolerance:S(n.tolerance)})),r);var n}function Ir(t,e,r){return He(t,Fe("UpgradeGov",E(e.wasmHash)),r)}function qr(t,e,r){return He(t,Fe("UpdateGovDelay",S(e.newDelay)),r)}function Rr(t,e,r){return He(t,Fe("GrantGovRole",je(e)),r)}function xr(t,e,r){return He(t,Fe("RevokeGovRole",je(e)),r)}function kr(t,e,r){return He(t,Fe("TransferGovOwnership",Ve(e)),r)}function Er(t,e){const r=k(e.argsXdr.map((t=>a.ScVal.fromXDR(t,"base64")))),n=ze(e.predecessor??De);return Ge(t,"execute",[x(),v(e.target),R(e.functionName),r,n,ze(e.salt)])}function Ar(t,e,r){return Ke(t,Fe("UpgradeGov",E(e.wasmHash)),r)}function Ur(t,e,r){return Ke(t,Fe("UpdateGovDelay",S(e.newDelay)),r)}function Tr(t,e,r){return Ke(t,Fe("GrantGovRole",je(e)),r)}function $r(t,e,r){return Ke(t,Fe("RevokeGovRole",je(e)),r)}function Cr(t,e,r){return Ke(t,Fe("TransferGovOwnership",Ve(e)),r)}const Pr=t=>k(t.map(v));function Wr(t,e,r){return Ge(t,"propose_canceller_reset",[Pr(e.newCancellers),ze(r)])}function Or(t,e,r){return Ge(t,"execute_canceller_reset",[A(e.executor,v),Pr(e.newCancellers),ze(r)])}function Nr(t,e){return Ge(t,"set_spoke_asset_flags",[v(t.caller),S(e.spokeId),U(e.hubId,e.asset),I(e.paused),I(e.frozen),I(e.noSeize)])}function Lr(t,e){return Ge(t,"set_oracle_sanity_bounds",[v(t.caller),v(e.asset),B(e.minPriceWad),B(e.maxPriceWad)])}function Mr(t){return Ge(t,"create_hub",[v(t.caller)])}function Dr(t){return Ge(t,"add_spoke",[v(t.caller)])}function zr(t,e){return Ge(t,"revoke_role_immediate",[v(e.account),R(e.role)])}function Fr(t){return Ge(t,"pause",[v(t.caller)])}function Vr(t,e){return He(t,Fe("Unpause"),e)}const Xr=t=>t.toXDR("base64"),jr=t=>a.ScVal.fromXDR(t,"base64"),Gr=t=>t.map((t=>String(s(jr(t))))).join(":"),Hr=t=>"bigint"==typeof t||"number"==typeof t?t.toString():String(t),Kr=t=>Number(t),Jr=t=>String(t),Yr=t=>t instanceof Uint8Array?g.hp.from(t).toString("hex"):g.hp.isBuffer(t)?t.toString("hex"):String(t),Zr=["None","Multiply","Long","Short"],Qr=["supply","borrow","withdraw","repay","liq_repay","liq_seize","multiply","param_upd","sw_debt_r","sw_col_wd","rp_col_wd","rp_col_r","close_wd","migrate","rp_col_net","liq_credit"],tn=t=>Array.isArray(t)?t:[],en=(t,e)=>{const r="Borrow"===e;return{action:(n=t[0],Qr[Kr(n)]??Hr(n)),positionType:e,hubId:Kr(t[1]),asset:Jr(t[2]),scaledAmountRay:Hr(t[3]),indexRay:Hr(t[4]),amount:Hr(t[5]),liquidationThresholdBps:r?void 0:Kr(t[6]),liquidationBonusBps:r?void 0:Kr(t[7]),loanToValueBps:r?void 0:Kr(t[8]),liquidationFeesBps:r?void 0:Kr(t[9])};var n},rn=t=>{return{owner:Jr(t[0]),spokeId:Kr(t[1]),mode:(e=t[2],Zr[Kr(e)]??"None")};var e},nn=t=>Array.isArray(t)?t[1]:void 0,on=t=>{const e=(r=t,Array.isArray(r)?Jr(r[0]):Jr(r));var r;if("Token"===e)return{Token:Jr(nn(t))};if("Ref"===e)return{Ref:Jr(nn(t))};if(t&&"object"==typeof t&&!Array.isArray(t)){const e=t;if(void 0!==e.Token)return{Token:Jr(e.Token)};if(void 0!==e.Ref)return{Ref:Jr(e.Ref)}}return{Token:Jr(t)}},sn=t=>{const e=t.tolerance??{};return{assetDecimals:Kr(t.asset_decimals),maxPriceStaleSeconds:Kr(t.max_price_stale_seconds),sources:tn(t.sources).map((t=>t)),tolerance:{upperRatio:Kr(e.upper_ratio_bps),lowerRatio:Kr(e.lower_ratio_bps)},independence:t.independence,minSanityPriceWad:Hr(t.min_sanity_price_wad),maxSanityPriceWad:Hr(t.max_sanity_price_wad)}},an={"market:create":t=>({topic:"market:create",data:{hubId:Kr(t.hub_id),baseAsset:Jr(t.base_asset),maxBorrowRate:Hr(t.max_borrow_rate),baseBorrowRate:Hr(t.base_borrow_rate),slope1:Hr(t.slope1),slope2:Hr(t.slope2),slope3:Hr(t.slope3),midUtilization:Hr(t.mid_utilization),optimalUtilization:Hr(t.optimal_utilization),maxUtilization:Hr(t.max_utilization),reserveFactor:Kr(t.reserve_factor),marketAddress:Jr(t.market_address)}}),"market:params_update":t=>({topic:"market:params_update",data:{asset:Jr(t.asset),maxBorrowRateRay:Hr(t.max_borrow_rate),baseBorrowRateRay:Hr(t.base_borrow_rate),slope1Ray:Hr(t.slope1),slope2Ray:Hr(t.slope2),slope3Ray:Hr(t.slope3),midUtilizationRay:Hr(t.mid_utilization),optimalUtilizationRay:Hr(t.optimal_utilization),maxUtilizationRay:Hr(t.max_utilization),reserveFactorBps:Kr(t.reserve_factor)}}),"market:batch_state_update":t=>({topic:"market:batch_state_update",data:{updates:tn(t).map((t=>{return e=tn(t),{hubId:Kr(e[0]),asset:Jr(e[1]),timestamp:Kr(e[2]),supplyIndexRay:Hr(e[3]),borrowIndexRay:Hr(e[4]),cash:Hr(e[5]),suppliedRay:Hr(e[6]),borrowedRay:Hr(e[7]),revenueRay:Hr(e[8])};var e}))}}),"market:batch_params_update":t=>({topic:"market:batch_params_update",data:{updates:tn(t).map((t=>{const e=t;return{hubId:Kr(e.hub_id),asset:Jr(e.asset),params:(r=e.params,{maxBorrowRateRay:Hr(r.max_borrow_rate),baseBorrowRateRay:Hr(r.base_borrow_rate),slope1Ray:Hr(r.slope1),slope2Ray:Hr(r.slope2),slope3Ray:Hr(r.slope3),midUtilizationRay:Hr(r.mid_utilization),optimalUtilizationRay:Hr(r.optimal_utilization),maxUtilizationRay:Hr(r.max_utilization),reserveFactorBps:Kr(r.reserve_factor),isFlashloanable:Boolean(r.is_flashloanable),flashloanFeeBps:Kr(r.flashloan_fee),assetId:Jr(r.asset_id),assetDecimals:Kr(r.asset_decimals)})};var r}))}}),"position:batch_update":t=>{const e=tn(t);return{topic:"position:batch_update",data:{accountId:Hr(e[0]),accountAttributes:rn(tn(e[1])),updates:[...tn(e[2]).map((t=>en(tn(t),"Deposit"))),...tn(e[3]).map((t=>en(tn(t),"Borrow")))]}}},"position:flash_loan":t=>({topic:"position:flash_loan",data:{hubId:Kr(t.hub_id),asset:Jr(t.asset),receiver:Jr(t.receiver),caller:Jr(t.caller),amount:Hr(t.amount),fee:Hr(t.fee)}}),"config:asset_oracle":t=>({topic:"config:asset_oracle",data:{key:on(t.key),oracle:sn(t.oracle)}}),"config:oracle":t=>({topic:"config:oracle",data:{asset:Jr(t.asset),oracle:sn(t.config??t.oracle)}}),"position:liquidation":t=>({topic:"position:liquidation",data:{liquidator:Jr(t.liquidator),accountId:Hr(t.account_id),repaidUsdWad:Hr(t.repaid_usd_wad),bonusBps:Hr(t.bonus_bps)}}),"debt:bad_debt":t=>({topic:"debt:bad_debt",data:{accountId:Hr(t.account_id),totalBorrowUsdWad:Hr(t.total_borrow_usd_wad),totalCollateralUsdWad:Hr(t.total_collateral_usd_wad)}}),"strategy:initial_payment":t=>({topic:"strategy:initial_payment",data:{token:Jr(t.token),amount:Hr(t.amount),usdValueWad:Hr(t.usd_value_wad),accountId:Hr(t.account_id)}}),"strategy:fee":t=>({topic:"strategy:fee",data:{hubId:Kr(t.hub_id),asset:Jr(t.asset),amount:Hr(t.amount),fee:Hr(t.fee),amountSent:Hr(t.amount_sent)}}),"config:approve_blend_pool":t=>({topic:"config:approve_blend_pool",data:{pool:Jr(t.pool??t.blend_pool??t.token),approved:Boolean(t.approved??t.is_approved??!0)}}),"config:approve_token":t=>({topic:"config:approve_token",data:{wasmHash:Yr(t.wasm_hash??t.pool),approved:Boolean(t.approved)}}),"config:swap_aggregator":t=>({topic:"config:swap_aggregator",data:{aggregator:Jr(t.aggregator??t.swap_aggregator)}}),"config:price_aggregator":t=>({topic:"config:price_aggregator",data:{aggregator:Jr(t.aggregator??t.price_aggregator)}}),"config:aggregator":t=>({topic:"config:aggregator",data:{aggregator:Jr(t.aggregator)}}),"config:accumulator":t=>({topic:"config:accumulator",data:{accumulator:Jr(t.accumulator)}}),"config:pool_template":t=>({topic:"config:pool_template",data:{wasmHash:Yr(t.wasm_hash)}}),"config:position_limits":t=>({topic:"config:position_limits",data:{maxSupplyPositions:Kr(t.max_supply_positions),maxBorrowPositions:Kr(t.max_borrow_positions)}}),"config:min_borrow_collateral":t=>({topic:"config:min_borrow_collateral",data:{minBorrowCollateralUsdWad:Hr(t.min_borrow_collateral_usd_wad??t.floor_wad??t.value)}}),"config:oracle_disabled":t=>({topic:"config:oracle_disabled",data:{asset:Jr(t.asset)}}),"config:spoke":t=>{const e=t.spoke;return{topic:"config:spoke",data:{spokeId:Kr(e.spoke_id),isDeprecated:Boolean(e.is_deprecated),liquidationTargetHfWad:Hr(e.liquidation_target_hf_wad),healthFactorForMaxBonusWad:Hr(e.hf_for_max_bonus_wad),liquidationBonusFactorBps:Kr(e.liquidation_bonus_factor_bps)}}}},un=Object.freeze(Object.keys(an));function ln(t,e){const r=Gr(t),n=an[r];return n?n(s(jr(e))):null}const cn=1e4;function pn(t,e){return`${t}-${BigInt(e).toString(10)}`}function fn(t){const e=t.split("-");return e.length>=2&&parseInt(e[1],10)||0}function dn(t,e=0){return 1e4*t+e}function hn(t){switch(t){case"liq_repay":return"lendingLiquidateRepayDebt";case"liq_seize":return"lendingLiquidateSeizeCollateral";case"liq_credit":default:return"lendingUpdateAccountPosition";case"param_upd":return"lendingUpdateAccountParameters"}}const mn=(t,e,r)=>{const n=new URL(e,t.endsWith("/")?t:`${t}/`);if(r)for(const[t,e]of Object.entries(r))void 0!==e&&n.searchParams.set(t,String(e));return n.toString()};async function gn(t,e){if(!e.baseUrl)throw new Error("Stellar quote baseUrl is required");if(null==t.amountIn==(null==t.amountOut))throw new Error("getStellarAggregatorQuote: exactly one of `amountIn` or `amountOut` must be provided");const r=mn(e.baseUrl,"api/v1/quote",{from:t.from,to:t.to,amountIn:t.amountIn,amountOut:t.amountOut,maxHops:t.maxHops,maxSplits:t.maxSplits,slippage:t.slippage,includePaths:t.includePaths,sender:t.sender,router:t.router,referralId:t.referralId,platform:t.platform,fresh:t.fresh}),n=await fetch(r,e.fetchOptions);if(!n.ok){const t=await n.text().catch((()=>""));throw new Error(`Stellar quote server responded ${n.status} ${n.statusText} for ${r} — ${t}`)}return await n.json()}async function yn(t){if(!t.baseUrl)throw new Error("Stellar quote baseUrl is required");const e=mn(t.baseUrl,"api/v1/tokens"),r=await fetch(e,t.fetchOptions);if(!r.ok){const t=await r.text().catch((()=>""));throw new Error(`Stellar quote server responded ${r.status} ${r.statusText} for ${e} — ${t}`)}return await r.json()}const wn=(t,e)=>(t=>Boolean(t&&"object"==typeof t&&!(t instanceof Uint8Array)&&"paths"in t))(t)&&void 0===t.referralId?{...t,referralId:e??0}:t,bn=t=>O(t).toXDR("base64");function vn(e,o){if(!e.routerAddress)throw new Error("Stellar aggregator routerAddress is required");const s=new n(e.routerAddress),a=new t(e.caller,e.sourceSequence),u=D(wn(o,e.referralId));return{xdr:new i(a,{fee:e.fee??r,networkPassphrase:m[e.network]}).addOperation(s.call("execute_strategy",v(e.caller),B(e.totalIn),u)).setTimeout(e.timeoutSeconds??300).build().toXDR()}}function Bn(t,e){return vn(t,e)}function Sn(t,e={}){if("string"!=typeof t.amountOutMin)throw new Error("mapQuoteResponseToStrategyPayload: quote response is missing `amountOutMin`. Pass `slippage` when fetching the quote.");return{paths:t.paths?t.paths.map((t=>({hops:t.swaps.map(qn),splitPpm:t.splitPpm}))):[{hops:t.hops.map(qn),splitPpm:1e6}],referralId:e.referralId??0,tokenIn:t.from,tokenOut:t.to,totalMinOut:t.amountOutMin}}function _n(t,e={}){const r=t;return"string"==typeof r.routeXdr&&r.routeXdr.length>0?{routeXdr:r.routeXdr}:Sn(t,e)}const In=Sn,qn=t=>({amountOut:t.amountOut,pool:t.address,tokenIn:t.from,tokenOut:t.to,venue:t.dex});function Rn(t,e){const r=e instanceof Error?e.message:String(e);return new Error(`[xoxno-invoked:${t}] ${r}`)}async function xn(t,e,r){const n=i.fromXDR(e,r?.network?m[r.network]:"");try{return(await t.prepareTransaction(n)).toXDR()}catch(t){if(r?.invokedContractId)throw Rn(r.invokedContractId,t);throw t}}async function kn(t,e,r){return xn(t,e.xdr,r)}function En(t){if(t<=0||t>4)throw new Error(`Invalid PositionMode ${t} for Stellar — expected 1 (Normal) through 4 (Short). "None" (0) has no Stellar equivalent.`);return t-1}function An(t,e){return new Uint8Array(0)}const Un=t=>{const e=t.startsWith("0x")?t.slice(2):t;if(e.length%2!=0)throw new Error("buildStellarCctpForwardTx: hex input must have even length");return g.hp.from(e,"hex")};function Tn(e){const r=new t(e.caller,e.sourceSequence),o=new n(e.forwarderAddress).call("mint_and_forward",a.ScVal.scvBytes(Un(e.message)),a.ScVal.scvBytes(Un(e.attestation)));return{xdr:new i(r,{fee:e.fee??"10000000",networkPassphrase:m[e.network]}).addOperation(o).setTimeout(e.timeoutSeconds??120).build().toXDR()}}const $n=10n**27n,Cn=10n**18n,Pn=10000n,Wn=27,On=18;function Nn(t,e="value"){let r;if("bigint"==typeof t)r=t;else if("number"==typeof t){if(!Number.isSafeInteger(t))throw new Error(`Stellar math: ${e} must be a safe integer, got ${t}`);r=BigInt(t)}else{const n=t.trim();if(!/^-?\d+$/.test(n))throw new Error(`Stellar math: ${e} must be a decimal integer string, got "${t}"`);r=BigInt(n)}if(r<0n)throw new Error(`Stellar math: ${e} must be non-negative, got ${r}`);return r}function Ln(t,e,r){if(0n===r)throw new Error("Stellar math: division by zero");return t*e/r}function Mn(t,e,r){if(0n===r)throw new Error("Stellar math: division by zero");const n=t*e,o=n/r;return n%r===0n?o:o+1n}function Dn(t,e,r){if(0n===r)throw new Error("Stellar math: division by zero");return(t*e+r/2n)/r}function zn(t,e){if(0n===e)throw new Error("Stellar math: division by zero");const r=t/e;return t%e>=e/2n+e%2n?r+1n:r}const Fn=t=>10n**BigInt(t);function Vn(t,e,r){return e===r?t:r>e?t*Fn(r-e):t/Fn(e-r)}function Xn(t,e,r){if(e===r)return t;if(r>e)return t*Fn(r-e);const n=Fn(e-r),o=t/n;return t%n===0n?o:o+1n}function jn(t,e,r){return e===r?t:r>e?t*Fn(r-e):zn(t,Fn(e-r))}const Gn={floor:Ln,ceil:Mn,halfUp:Dn},Hn={floor:Vn,ceil:Xn,halfUp:jn};function Kn(t,e,r,n){return Hn[n](Gn[n](t,e,$n),Wn,r)}function Jn(t,e,r){return Kn(Nn(t,"scaledRay"),Nn(e,"indexRay"),r,"floor")}function Yn(t,e,r){return Kn(Nn(t,"scaledRay"),Nn(e,"indexRay"),r,"ceil")}function Zn(t,e,r){return Kn(Nn(t,"scaledRay"),Nn(e,"indexRay"),r,"halfUp")}function Qn(t,e){if(e>Wn)throw new Error(`Stellar math: decimals ${e} exceed RAY scale`);return Vn(t,e,Wn)}function to(t,e,r,n){const o=Gn[n](t,e,$n),i=Hn[n](o,Wn,On);return Gn[n](i,r,Cn)}function eo(t,e,r,n){const o=Hn[n](Qn(t,e),Wn,On);return Gn[n](o,r,Cn)}const ro=t=>Number(t)/1e18,no=t=>Number(t)/1e27,oo=(t,e)=>Number(t)/10**e;function io(t,e){if(!Number.isFinite(t)||t<=0||t>=1e21)return 0n;const r=t.toFixed(e),[n="0",o=""]=r.split(".");return BigInt(n+o.padEnd(e,"0"))}const so=t=>io(t,On),ao=(t,e)=>Dn(t,e,$n),uo=(t,e)=>Dn(t,$n,e);function lo(t,e){return 0n===e?0n:uo(t,e)}function co(t,e){const r=t>$n?$n:t,n=Nn(e.baseRateRay,"irm.baseRateRay"),o=Nn(e.slope1Ray,"irm.slope1Ray"),i=Nn(e.slope2Ray,"irm.slope2Ray"),s=Nn(e.slope3Ray,"irm.slope3Ray"),a=Nn(e.midUtilizationRay,"irm.midUtilizationRay"),u=Nn(e.optimalUtilizationRay,"irm.optimalUtilizationRay"),l=Nn(e.maxBorrowRateRay,"irm.maxBorrowRateRay");let c;if(r<a)c=n+uo(ao(r,o),a);else if(r<u){const t=u-a;c=n+o+uo(ao(r-a,i),t)}else{const t=$n-u;c=n+o+i+(0n===t?0n:uo(ao(r-u,s),t))}return c>l?l:c}function po(t,e,r){return 0n===t||!Number.isInteger(r)||r<0||r>=1e4?0n:Dn(ao(t,e),Pn-BigInt(r),Pn)}const fo=t=>no(t),ho=t=>Math.expm1(no(t)),mo=5n*Cn,go=(t,e,r)=>`${t}:${e}:${r}`;function yo(t,e,r,n){const o=Array.isArray(t)?t:void 0,i=o?o.find((t=>t.spokeId===e&&t.hubId===r&&t.asset===n)):t[go(e,r,n)]??Object.values(t).find((t=>t.spokeId===e&&t.hubId===r&&t.asset===n));if(!i)throw new Error(`Stellar math: no reserve for ${go(e,r,n)}`);return i}const wo=/^0*[1-9]\d*$/,bo=t=>"string"==typeof t&&wo.test(t)?BigInt(t).toString():null,vo=(t,e)=>`${t}:${e}`;function Bo(t){const e=new Map,r=new Map,n=new Set,o=new Set;for(const i of t?.indexes??[]){const t=vo(i.hubId,i.asset),s=bo(i.supplyIndex),a=bo(i.borrowIndex),u=bo(i.usdPrice),l=e.get(t),c=l&&bo(l.supplyIndex)===s&&bo(l.borrowIndex)===a&&bo(l.usdPrice)===u;null==s||null==a||null==u||l&&!c?n.add(t):l||e.set(t,i);const p=!1===i.valid||!0===i.stale||!0===i.deviation,f=r.get(i.asset);null==u||p||void 0!==f&&f.toString()!==u?o.add(i.asset):void 0===f&&r.set(i.asset,BigInt(u))}for(const t of n)e.delete(t);for(const t of o)r.delete(t);return{indexes:e,prices:r,rejectedIndexKeys:n,rejectedAssets:o}}const So=(t,e)=>Ln(t,BigInt(e),Pn);function _o(t,e,r,n){const o="supply"===t.side,i=Math.min(t.entryLtvBps,t.entryLiquidationThresholdBps);return{side:t.side,hubId:t.hubId,asset:t.asset,decimals:t.decimals,scaledRay:t.scaledRay.toString(),indexRay:t.indexRay.toString(),usdPriceWad:t.priceWad.toString(),usdPrice:ro(t.priceWad),amountBase:e.toString(),amountShort:oo(e,t.decimals),usdWad:r.toString(),usd:ro(r),gateUsdWad:n.toString(),entryLtvBps:t.entryLtvBps,entryLiquidationThresholdBps:t.entryLiquidationThresholdBps,entryLiquidationBonusBps:t.entryLiquidationBonusBps,entryLiquidationFeesBps:t.entryLiquidationFeesBps,ltvWeightedUsdWad:o?So(n,i).toString():"0",liquidationWeightedUsdWad:o?So(n,t.entryLiquidationThresholdBps).toString():"0",liveDataUsed:t.liveDataUsed}}function Io(t){if("supply"===t.side)return _o(t,Kn(t.scaledRay,t.indexRay,t.decimals,"floor"),to(t.scaledRay,t.indexRay,t.priceWad,"halfUp"),to(t.scaledRay,t.indexRay,t.priceWad,"floor"));const e=Kn(t.scaledRay,t.indexRay,t.decimals,"ceil"),r=to(t.scaledRay,t.indexRay,t.priceWad,"ceil");return _o(t,e,r,r)}function qo(t,e,r,n){const o=Qn(e,r);return"supply"===t?Ln(o,$n,n):Mn(o,$n,n)}function Ro(t,e,r,n){const o=Qn(e,r);return"supply"===t?Mn(o,$n,n):Ln(o,$n,n)}function xo(t,e){return Io({...t,scaledRay:qo(t.side,e,t.decimals,t.indexRay)})}const ko=(...t)=>{for(const e of t){const t=bo(e);if(null!=t)return BigInt(t)}return $n};function Eo(t,e,r,n){const o=Nn("supply"===t?e.supplyScaledRay:e.borrowScaledRay,`${t}ScaledRay`);if(0n===o)return null;const i=n.indexes.get(vo(e.hubId,e.asset)),s=n.prices.get(e.asset),a="supply"===t?ko(i?.supplyIndex,e.liveSupplyIndexRay,r.liveSupplyIndexRay,e.supplyIndexRay):ko(i?.borrowIndex,e.liveBorrowIndexRay,r.liveBorrowIndexRay,e.borrowIndexRay),u=s??so(r.usdPrice);return Io({side:t,hubId:e.hubId,asset:e.asset,decimals:r.assetDecimals,scaledRay:o,indexRay:a,priceWad:u,entryLtvBps:e.entryLtvBps,entryLiquidationThresholdBps:e.entryLiquidationThresholdBps,entryLiquidationBonusBps:e.entryLiquidationBonusBps,entryLiquidationFeesBps:e.entryLiquidationFeesBps,liveDataUsed:void 0!==i&&void 0!==s})}const Ao=(t,e)=>t.reduce(((t,r)=>t+BigInt(e(r))),0n);function Uo(t,e,r,n,o){const i=Ao(e,(t=>t.usdWad)),s=Ao(e,(t=>t.ltvWeightedUsdWad)),a=Ao(e,(t=>t.liquidationWeightedUsdWad)),u=Ao(r,(t=>t.usdWad)),l=0n===u?null:Ln(a,Cn,u),c=0n===a?0:Number(u)/Number(a)*100,p=s<n||s<=u?0n:s-u;return{...t,supplies:e,borrows:r,totalCollateralUsdWad:i.toString(),totalCollateralUsd:ro(i),ltvWeightedCollateralUsdWad:s.toString(),ltvWeightedCollateralUsd:ro(s),liquidationWeightedCollateralUsdWad:a.toString(),liquidationWeightedCollateralUsd:ro(a),totalDebtUsdWad:u.toString(),totalDebtUsd:ro(u),healthFactorWad:null===l?null:l.toString(),healthFactor:null===l?null:ro(l),healthPercent:c,borrowLimitUsdWad:s.toString(),borrowLimitUsd:ro(s),availableBorrowUsdWad:p.toString(),availableBorrowUsd:ro(p),minBorrowCollateralUsdWad:n.toString(),minBorrowCollateralUsd:ro(n),isLiquidatable:null!==l&&l<Cn,liveDataValid:o}}function To(t){const{positions:e,reserves:r,liveState:n}=t,o=e[0];if(!o)throw new Error("Stellar math: computeAccountRisk needs at least one position row");for(const t of e)if(t.accountId!==o.accountId)throw new Error(`Stellar math: computeAccountRisk received mixed account ids (${o.accountId}, ${t.accountId})`);const i=Bo(n),s=[],a=[];for(const t of e){const e=yo(r,t.spokeId,t.hubId,t.asset),n=Eo("supply",t,e,i);n&&s.push(n);const o=Eo("borrow",t,e,i);o&&a.push(o)}const u=null!=n?.minBorrowCollateralUsdWad?Nn(n.minBorrowCollateralUsdWad,"minBorrowCollateralUsdWad"):mo,l=void 0!==n&&[...s,...a].every((t=>t.liveDataUsed));return Uo({accountId:o.accountId,owner:o.owner,spokeId:o.spokeId,mode:o.positionMode},s,a,u,l)}const $o=200n,Co=t=>t.reduce(((t,e)=>e.amount<t.amount?e:t)),Po=t=>t<0n?0n:t,Wo=(t,e,r,n)=>({amountBase:t.amount,amountShort:oo(t.amount,e),isFullClose:r,reason:t.reason,projectedUtilization:n}),Oo=t=>({amountBase:0n,amountShort:0,isFullClose:!1,reason:t,projectedUtilization:null});function No(t){const e=t.assetDecimals,r=Nn(t.irm.maxUtilizationRay,"irm.maxUtilizationRay");return{suppliedBase:io(t.hubPool.suppliedShort,e),borrowedBase:io(t.hubPool.borrowedShort,e),cashBase:io(t.availableLiquidityShort,e),spokeSuppliedBase:io(t.suppliedShort,e),spokeBorrowedBase:io(t.borrowedShort,e),maxUtilizationRay:r>=$n?null:r}}const Lo=(t,e)=>t<=0n?null:Number(e)/Number(t);function Mo(t,e){if(t<=0n||!e(0n))return 0n;let r=0n,n=t+1n;for(;n-r>1n;){const t=(r+n)/2n;e(t)?r=t:n=t}return r}const Do=(t,e)=>t.find((t=>t.hubId===e.hubId&&t.asset===e.asset));function zo(t,e,r){if(e.paused)return Oo("paused");if(e.frozen)return Oo("frozen");if(!e.isBorrowable)return Oo("cap");const n=e.assetDecimals,o=No(e),i=Do(t.borrows,e),s=Bo(r).indexes.get(vo(e.hubId,e.asset)),a=i?BigInt(i.indexRay):Nn(s?.borrowIndex??e.liveBorrowIndexRay,"borrowIndex"),u=i?BigInt(i.usdPriceWad):function(t,e){return Bo(e).prices.get(t.asset)??so(t.usdPrice)}(e,r),l=i?BigInt(i.scaledRay):0n,c=BigInt(t.totalDebtUsdWad)-(i?BigInt(i.usdWad):0n),p=BigInt(t.ltvWeightedCollateralUsdWad),f=BigInt(t.minBorrowCollateralUsdWad),d=[];if(p<f)d.push({amount:0n,reason:"minCollateral"});else{const e=p-BigInt(t.totalDebtUsdWad),r=e<=0n||u<=0n?0n:Ln(e,10n**BigInt(n),u),o=t=>c+to(l+qo("borrow",t,n,a),a,u,"ceil");d.push({amount:0n===r?0n:Mo(r+16n,(t=>o(t)<=p)),reason:"ltv"})}d.push({amount:Po(Nn(e.borrowCap,"borrowCap")-o.spokeBorrowedBase),reason:"cap"});const h=Dn(o.suppliedBase,200n,Pn);d.push({amount:Po(o.cashBase-h),reason:"liquidity"});const m=function(t,e){const r=t.maxUtilizationRay;if(null===r)return null;const n=Qn(t.suppliedBase,e);return 0n===n?null:Mo(Po(Ln(t.suppliedBase,r,$n)-t.borrowedBase)+16n,(o=>lo(Qn(t.borrowedBase+o,e),n)<=r))}(o,n);null!==m&&d.push({amount:m,reason:"utilizationCap"});const g=Co(d);return Wo(g,n,!1,Lo(o.suppliedBase,o.borrowedBase+g.amount))}function Fo(t,e,r){if(e.paused)return Oo("paused");const n=Do(t.supplies,e);if(!n)return Oo(null);const o=n.decimals,i=No(e),s=BigInt(n.scaledRay),a=BigInt(n.indexRay),u=BigInt(n.usdPriceWad),l=BigInt(n.amountBase),c=Kn(s,a,o,"halfUp"),p=BigInt(t.totalDebtUsdWad),f=BigInt(t.minBorrowCollateralUsdWad),d=BigInt(Math.min(n.entryLtvBps,n.entryLiquidationThresholdBps)),h=[];let m=!0;if(p>0n&&d>0n){const e=p>f?p:f,r=f>p?"minCollateral":"healthFactor",i=BigInt(t.ltvWeightedCollateralUsdWad)-BigInt(n.ltvWeightedUsdWad);if(i<e){m=!1;const t=e-i,l=Mn(t,Pn,d),p=BigInt(n.gateUsdWad)-l,f=p<=0n?0n:Ln(p,10n**BigInt(o),u),g=c>0n?c-1n:0n,y=f+16n>g?g:f+16n,w=t=>{const e=Ro("supply",t,o,a);return Ln(to(e>=s?0n:s-e,a,u,"floor"),d,Pn)};h.push({amount:Mo(y,(e=>w(e)>=t)),reason:r})}}h.push({amount:l,reason:null}),h.push({amount:i.cashBase,reason:"liquidity"});const g=function(t,e){const r=t.maxUtilizationRay;if(null===r||0n===t.borrowedBase)return null;if(0n===r)return 0n;const n=Mn(t.borrowedBase,$n,r),o=t.suppliedBase<n?0n:t.suppliedBase-n+16n,i=Qn(t.borrowedBase,e);return Mo(o>t.suppliedBase?t.suppliedBase:o,(n=>{const o=Qn(t.suppliedBase-n,e);return o>0n&&lo(i,o)<=r}))}(i,o);null!==g&&h.push({amount:g,reason:"utilizationCap"});const y=Co(h),w=m&&y.amount>=l;return Wo(y,o,w,Lo(i.suppliedBase-y.amount,i.borrowedBase))}function Vo(t){if(t.paused)return Oo("paused");if(t.frozen)return Oo("frozen");const e=t.assetDecimals,r=No(t),n={amount:Po(Nn(t.supplyCap,"supplyCap")-r.spokeSuppliedBase),reason:"cap"};return Wo(n,e,!1,Lo(r.suppliedBase+n.amount,r.borrowedBase))}function Xo(t,e,r){if(e.paused)return Oo("paused");const n=Do(t.borrows,e);if(!n)return Oo(null);const o=n.decimals,i=No(e),s=BigInt(n.amountBase),a=void 0===r?null:Nn(r,"walletBalance"),u=null!==a&&a<s?{amount:a,reason:"liquidity"}:{amount:s,reason:null};return Wo(u,o,u.amount>=s,Lo(i.suppliedBase,Po(i.borrowedBase-u.amount)))}const jo=(t,e)=>t.hubId===e.hubId&&t.asset===e.asset,Go=t=>{if("bigint"==typeof t)return t;const e=t.trim();if(!/^-?\d+$/.test(e))throw new Error(`Stellar math: delta amountBase must be an integer string, got "${t}"`);return BigInt(e)};function Ho(t,e){const r=[...t.supplies],n=[...t.borrows];for(const t of e){const e="supply"===t.side?r:n,o=e.findIndex((e=>jo(e,t))),i=-1===o?void 0:e[o],s=Go(t.amountBase);let a;if(i){const t={side:i.side,hubId:i.hubId,asset:i.asset,decimals:i.decimals,indexRay:BigInt(i.indexRay),priceWad:BigInt(i.usdPriceWad),entryLtvBps:i.entryLtvBps,entryLiquidationThresholdBps:i.entryLiquidationThresholdBps,entryLiquidationBonusBps:i.entryLiquidationBonusBps,entryLiquidationFeesBps:i.entryLiquidationFeesBps,liveDataUsed:i.liveDataUsed},e=BigInt(i.scaledRay);let r;if(s>=0n)r=e+qo(t.side,s,t.decimals,t.indexRay);else{const n=-s,o=n>=("supply"===t.side?Kn(e,t.indexRay,t.decimals,"halfUp"):BigInt(i.amountBase))?e:Ro(t.side,n,t.decimals,t.indexRay);r=o>=e?0n:e-o}a=0n===r?null:Io({...t,scaledRay:r})}else a=s<=0n?null:xo(Ko(t),s);-1===o?a&&e.push(a):a?e[o]=a:e.splice(o,1)}return Uo({accountId:t.accountId,owner:t.owner,spokeId:t.spokeId,mode:t.mode},r,n,BigInt(t.minBorrowCollateralUsdWad),t.liveDataValid)}function Ko(t){const e=t.reserve;if(!e)throw new Error(`Stellar math: projectAccountRisk needs \`reserve\` for a new ${t.side} position on ${t.hubId}:${t.asset}`);return{side:t.side,hubId:t.hubId,asset:t.asset,decimals:e.assetDecimals,indexRay:Nn("supply"===t.side?e.liveSupplyIndexRay:e.liveBorrowIndexRay,"reserve live index"),priceWad:so(e.usdPrice),entryLtvBps:e.collateralFactorBps,entryLiquidationThresholdBps:e.liquidationThresholdBps,entryLiquidationBonusBps:e.liquidationPenaltyBps,entryLiquidationFeesBps:e.liquidationFeesBps,liveDataUsed:!1}}function Jo(t,e=0n,r=0n){const n=t.assetDecimals,o=t=>t<0n?0n:t,i=o(io(t.hubPool.suppliedShort,n)+Go(e)),s=lo(Qn(o(io(t.hubPool.borrowedShort,n)+Go(r)),n),Qn(i,n)),a=co(s,t.irm),u=po(s,a,t.irm.reserveFactorBps);return{utilization:no(s),utilizationRay:s.toString(),borrowAprRay:a.toString(),supplyAprRay:u.toString(),borrowApr:fo(a),supplyApr:fo(u),borrowApy:ho(a),supplyApy:ho(u)}}const Yo={1:{name:"AssetNotSupported",message:"This asset is not supported by the protocol."},2:{name:"AssetAlreadySupported",message:"This asset is already supported."},3:{name:"InvalidTicker",message:"Invalid asset ticker."},6:{name:"InvalidAsset",message:"Invalid asset address."},10:{name:"InvalidWasmHash",message:"The WASM hash is empty or invalid."},11:{name:"InvalidExchangeSrc",message:"The oracle configuration is invalid."},12:{name:"PairNotActive",message:"No oracle is configured for this asset."},32:{name:"OwnerNotSet",message:"The contract owner has not been set."},39:{name:"InvalidTimelockDelay",message:"The timelock delay is out of the allowed range."},41:{name:"InvalidRole",message:"The caller does not hold the required role."},43:{name:"HubNotActive",message:"This hub is not active."},44:{name:"NotAuthorized",message:"The caller is not authorized to perform this action."},46:{name:"OperationNotCancellable",message:"This governance operation cannot be cancelled."},113:{name:"InvalidLiqThreshold",message:"LTV, liquidation threshold, or bonus is out of bounds."},116:{name:"InvalidBorrowParams",message:"Supply or borrow cap configuration is invalid."},117:{name:"InvalidUtilRange",message:"Interest-rate utilization breakpoints are invalid."},132:{name:"AssetDecimalsTooHigh",message:"Asset decimals exceed the protocol maximum (27)."},300:{name:"SpokeNotFound",message:"This spoke does not exist."},301:{name:"SpokeDeprecated",message:"This spoke has been deprecated."},307:{name:"AssetNotInSpoke",message:"This asset is not listed on the spoke."},308:{name:"AssetAlreadyInSpoke",message:"This asset is already listed in the spoke."},309:{name:"SpokeAssetInUse",message:"This spoke asset still has live positions; drain usage before removal."},315:{name:"SpokeAssetPaused",message:"This spoke asset is paused."},316:{name:"SpokeAssetFrozen",message:"This spoke asset is frozen."},317:{name:"SpokeAssetFlagRelaxation",message:"Guardian flag updates may only tighten; clearing a flag requires the timelocked edit."},318:{name:"SpokeAssetSeizureHalted",message:"Liquidation seizure is halted for this spoke asset."},220:{name:"InvalidOracleBase",message:"The oracle quote asset/market is missing or invalid."},221:{name:"InvalidOracleDecimals",message:"The oracle decimals value is invalid."},224:{name:"InvalidSanityBounds",message:"Oracle sanity bounds are invalid (require 0 < min < max)."},225:{name:"OracleCycleDetected",message:"A cycle was detected in the oracle quote chain."}};function Zo(t){const e=t.match(/Error\(Contract,\s*#(\d+)\)/);if(!e)return null;const r=Number(e[1]),n=Yo[r];return n?{code:r,...n}:null}export{Pn as BPS,mo as DEFAULT_MIN_BORROW_COLLATERAL_USD_WAD,$o as LIQUIDATION_BUFFER_BPS,$n as RAY,Wn as RAY_DECIMALS,De as STELLAR_GOVERNANCE_ZERO_PREDECESSOR,un as STELLAR_LENDING_TOPICS,f as STELLAR_NETWORKS,m as STELLAR_NETWORK_PASSPHRASE,cn as SYNTHETIC_EVENT_ORDER_STRIDE,Cn as WAD,On as WAD_DECIMALS,Uo as aggregateAccountRisk,co as annualBorrowRateRay,Qn as baseToRay,oo as baseToShort,eo as baseValueWad,Bo as buildLiveSnapshot,An as buildSameTokenRepaySwapSteps,be as buildStellarAcceptOwnershipTx,Le as buildStellarAddRewardsTx,qe as buildStellarApproveBlendPoolTx,xe as buildStellarApproveTokenTx,Bn as buildStellarBatchSwapTx,G as buildStellarBorrowBatchTx,H as buildStellarBorrowTx,Tn as buildStellarCctpForwardTx,Ne as buildStellarClaimRevenueTx,We as buildStellarCreateLiquidityPoolTx,Or as buildStellarExecuteCancellerResetTx,vn as buildStellarExecuteStrategyTx,et as buildStellarFlashLoanTx,Dr as buildStellarGovernanceAddSpokeImmediateTx,Mr as buildStellarGovernanceCreateHubImmediateTx,Ar as buildStellarGovernanceExecuteGovernanceUpgradeTx,Tr as buildStellarGovernanceExecuteGrantGovernanceRoleTx,$r as buildStellarGovernanceExecuteRevokeGovernanceRoleTx,Cr as buildStellarGovernanceExecuteTransferGovOwnTx,Er as buildStellarGovernanceExecuteTx,Ur as buildStellarGovernanceExecuteUpdateDelayTx,Fr as buildStellarGovernancePauseTx,zr as buildStellarGovernanceRevokeRoleImmediateTx,Lr as buildStellarGovernanceSetOracleSanityBoundsImmediateTx,Nr as buildStellarGovernanceSetSpokeAssetFlagsImmediateTx,ge as buildStellarGrantRoleTx,pn as buildStellarLendingIdentifier,Q as buildStellarLiquidateTx,rt as buildStellarMigrateFromBlendTx,de as buildStellarMigrateTx,nt as buildStellarMultiplyTx,he as buildStellarPauseTx,or as buildStellarProposeAddAssetToSpokeTx,rr as buildStellarProposeAddSpokeTx,fr as buildStellarProposeApproveBlendPoolTx,cr as buildStellarProposeApproveTokenTx,Wr as buildStellarProposeCancellerResetTx,Br as buildStellarProposeConfigureAssetOracleTx,Sr as buildStellarProposeConfigureMarketOracleTx,er as buildStellarProposeCreateHubTx,hr as buildStellarProposeCreateLiquidityPoolTx,gr as buildStellarProposeDeployPoolTx,ir as buildStellarProposeEditAssetInSpokeTx,_r as buildStellarProposeEditOracleToleranceTx,Ir as buildStellarProposeGovernanceUpgradeTx,Rr as buildStellarProposeGrantGovernanceRoleTx,br as buildStellarProposeMigrateControllerTx,sr as buildStellarProposeRemoveAssetFromSpokeTx,nr as buildStellarProposeRemoveSpokeTx,dr as buildStellarProposeRevokeBlendPoolTx,xr as buildStellarProposeRevokeGovernanceRoleTx,pr as buildStellarProposeRevokeTokenTx,Qe as buildStellarProposeSetAccumulatorTx,Ze as buildStellarProposeSetAggregatorTx,lr as buildStellarProposeSetMinBorrowCollatTx,tr as buildStellarProposeSetPositionLimitsTx,ur as buildStellarProposeSetPositionManagerTx,Ye as buildStellarProposeSetPriceAggregatorTx,ar as buildStellarProposeSetSpokeLiquidationCurveTx,Je as buildStellarProposeSetSwapAggregatorTx,vr as buildStellarProposeTransferCtrlOwnershipTx,kr as buildStellarProposeTransferGovOwnTx,Vr as buildStellarProposeUnpauseTx,qr as buildStellarProposeUpdateDelayTx,wr as buildStellarProposeUpgradeControllerTx,mr as buildStellarProposeUpgradePoolParamsTx,yr as buildStellarProposeUpgradePoolTx,Pe as buildStellarRenewAccountTx,Y as buildStellarRepayBatchTx,st as buildStellarRepayDebtWithCollateralTx,Z as buildStellarRepayTx,Re as buildStellarRevokeBlendPoolTx,ye as buildStellarRevokeRoleTx,ke as buildStellarRevokeTokenTx,_e as buildStellarSetAccumulatorTx,Se as buildStellarSetAggregatorTx,Ae as buildStellarSetMarketOracleConfigTx,$e as buildStellarSetOracleSanityBoundsTx,Ue as buildStellarSetOracleToleranceTx,Ee as buildStellarSetOracleTx,Ie as buildStellarSetPositionLimitsTx,Be as buildStellarSetPriceAggregatorTx,Te as buildStellarSetSpokeAssetFlagsTx,ve as buildStellarSetSwapAggregatorTx,X as buildStellarSupplyBatchTx,j as buildStellarSupplyTx,it as buildStellarSwapCollateralTx,ot as buildStellarSwapDebtTx,we as buildStellarTransferOwnershipTx,me as buildStellarUnpauseTx,Me as buildStellarUpdateAccountThresholdTx,Ce as buildStellarUpdateIndexesTx,fe as buildStellarUpgradeControllerTx,Oe as buildStellarUpgradeLiquidityPoolParamsTx,K as buildStellarWithdrawBatchTx,J as buildStellarWithdrawTx,F as buildTx,Ro as burnShares,To as computeAccountRisk,ln as decodeStellarLendingEvent,tt as decodeStellarLiquidateReturn,po as depositRateRay,zn as divByIntHalfUp,ce as encodeAssetOracle,Qt as encodeInterestRateModel,pe as encodeMarketOracleConfigInput,te as encodeMarketParamsRaw,ee as encodePositionLimits,re as encodePriceKey,bn as encodeStrategyPayloadToRouteXdr,fn as extractEventOrder,Bt as getStellarAccountPositions,Xt as getStellarActiveUsersSeries,gn as getStellarAggregatorQuote,yt as getStellarAsset,kt as getStellarAssetGraph,It as getStellarAssetMarkets,_t as getStellarAssetPage,ft as getStellarAssets,Lt as getStellarCampaignLeaderboard,Yt as getStellarCampaignMe,Gt as getStellarDefiLlamaDimensions,h as getStellarDeployment,pt as getStellarDetailedMarkets,zt as getStellarFeeRevenueSeries,Ct as getStellarGovernanceProposals,Nt as getStellarHolderDistribution,wt as getStellarHub,Et as getStellarHubGraph,Rt as getStellarHubHolders,dt as getStellarHubs,lt as getStellarLendingContext,ct as getStellarLendingLiveState,Ot as getStellarLiquidationsLeaderboard,Ft as getStellarLiquidationsSeries,Wt as getStellarParticipantCounts,Jt as getStellarPnlByScope,Pt as getStellarPositionsLeaderboard,Kt as getStellarPositionsPnl,yn as getStellarQuoteTokens,jt as getStellarRateSpreadSeries,gt as getStellarReserve,Ut as getStellarReserveGraph,qt as getStellarReserveHolders,mt as getStellarReserves,Dt as getStellarRevenueSeries,bt as getStellarSpoke,At as getStellarSpokeGraph,xt as getStellarSpokeHolders,ht as getStellarSpokes,Mt as getStellarStatsHistory,Tt as getStellarUserActivity,$t as getStellarUserActivityPage,Ht as getStellarUserHistory,vt as getStellarUserPositions,Vt as getStellarVolumeSeries,St as getStellarWalletBalance,vo as liveIndexKey,In as mapQuoteResponseToAggregatorSwap,Sn as mapQuoteResponseToStrategyPayload,_n as mapQuoteResponseToStrategySwap,Zo as mapSorobanError,hn as mapStellarPositionActivityType,zo as maxBorrow,Xo as maxRepay,Vo as maxSupply,Fo as maxWithdraw,qo as mintShares,Mn as mulDivCeil,Ln as mulDivFloor,Dn as mulDivHalfUp,io as numberToScaled,so as numberToWad,to as positionValueWad,kn as prepareStellarBuiltTx,xn as prepareStellarTxXdr,Ho as projectAccountRisk,Jo as projectReserveApy,ho as rayAprToApy,fo as rayAprToNumber,no as rayToNumber,Xn as rescaleCeil,Vn as rescaleFloor,jn as rescaleHalfUp,go as reserveKey,yo as resolveReserve,Gr as stellarLendingDispatchKey,Zt as stellarLendingRead,d as stellarNetworks,dn as syntheticEventOrder,Rn as tagStellarInvokedContractError,Xr as toBase64Xdr,Nn as toBigInt,En as toStellarPositionMode,Kn as unscale,Yn as unscaleBorrowCeil,Zn as unscaleHalfUp,Jn as unscaleSupplyFloor,lo as utilizationRay,xo as valueBasePosition,Io as valueScaledPosition,ro as wadToNumber};export const XOXNOClient=p.GW;