@xoxno/sdk-js 1.0.227 → 1.0.228
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/cjs/sdk/stellar/__tests__/amount.test.d.ts +1 -0
- package/dist/cjs/sdk/stellar/lending.d.ts +9 -0
- package/dist/esm/sdk/stellar/lending.js +22 -1
- package/dist/index.cjs +1 -1
- package/dist/sdk/stellar/__tests__/amount.test.d.ts +1 -0
- package/dist/sdk/stellar/index.cjs +1 -1
- package/dist/sdk/stellar/index.esm.js +1 -1
- package/dist/sdk/stellar/lending.d.ts +9 -0
- package/package.json +1 -1
|
@@ -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,Asset as r,BASE_FEE as n,Contract as o,ScInt as s,StrKey as i,TransactionBuilder as a,rpc as u,scValToBigInt as l,scValToNative as c,xdr as d}from"@stellar/stellar-sdk";var p={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,s=a(t),i=s[0],u=s[1],l=new o(function(t,e,r){return 3*(e+r)/4-r}(0,i,u)),c=0,d=u>0?i-4:i;for(r=0;r<d;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,s=[],i=16383,a=0,u=n-o;a<u;a+=i)s.push(l(t,a,a+i>u?u:a+i));return 1===o?(e=t[n-1],s.push(r[e>>2]+r[e<<4&63]+"==")):2===o&&(e=(t[n-2]<<8)+t[n-1],s.push(r[e>>10]+r[e>>4&63]+r[e<<2&63]+"=")),s.join("")};for(var r=[],n=[],o="undefined"!=typeof Uint8Array?Uint8Array:Array,s="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/",i=0;i<64;++i)r[i]=s[i],n[s.charCodeAt(i)]=i;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=[],s=e;s<r;s+=3)n=(t[s]<<16&16711680)+(t[s+1]<<8&65280)+(255&t[s+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),s="function"==typeof Symbol&&"function"==typeof Symbol.for?Symbol.for("nodejs.util.inspect.custom"):null;e.hp=u,e.IS=50;const i=2147483647;function a(t){if(t>i)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 d(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 f(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 f(t,e,r);if("undefined"!=typeof SharedArrayBuffer&&(K(t,SharedArrayBuffer)||t&&K(t.buffer,SharedArrayBuffer)))return f(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||Y(t.length)?a(0):p(t):"Buffer"===t.type&&Array.isArray(t.data)?p(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 d(t){return c(t),a(t<0?0:0|h(t))}function p(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 f(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>=i)throw new RangeError("Attempt to allocate Buffer larger than maximum size: 0x"+i.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 q(this,e,r);case"utf8":case"utf-8":return R(this,e,r);case"ascii":return A(this,e,r);case"latin1":case"binary":return x(this,e,r);case"base64":return E(this,e,r);case"ucs2":case"ucs-2":case"utf16le":case"utf-16le":return T(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),Y(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 s,i=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;i=2,a/=2,u/=2,r/=2}function l(t,e){return 1===i?t[e]:t.readUInt16BE(e*i)}if(o){let n=-1;for(s=r;s<a;s++)if(l(t,s)===l(e,-1===n?0:s-n)){if(-1===n&&(n=s),s-n+1===u)return n*i}else-1!==n&&(s-=s-n),n=-1}else for(r+u>a&&(r=a-u),s=r;s>=0;s--){let r=!0;for(let n=0;n<u;n++)if(l(t,s+n)!==l(e,n)){r=!1;break}if(r)return s}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 s=e.length;let i;for(n>s/2&&(n=s/2),i=0;i<n;++i){const n=parseInt(e.substr(2*i,2),16);if(Y(n))return i;t[r+i]=n}return i}function I(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 B(t,e,r,n){return H(function(t,e){let r,n,o;const s=[];for(let i=0;i<t.length&&!((e-=2)<0);++i)r=t.charCodeAt(i),n=r>>8,o=r%256,s.push(o),s.push(n);return s}(e,t.length-r),t,r,n)}function E(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 s=null,i=e>239?4:e>223?3:e>191?2:1;if(o+i<=r){let r,n,a,u;switch(i){case 1:e<128&&(s=e);break;case 2:r=t[o+1],128==(192&r)&&(u=(31&e)<<6|63&r,u>127&&(s=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)&&(s=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&&(s=u))}}null===s?(s=65533,i=1):s>65535&&(s-=65536,n.push(s>>>10&1023|55296),s=56320|1023&s),n.push(s),o+=i}return function(t){const e=t.length;if(e<=k)return String.fromCharCode.apply(String,t);let r="",n=0;for(;n<e;)r+=String.fromCharCode.apply(String,t.slice(n,n+=k));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 d(t)},u.allocUnsafeSlow=function(t){return d(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,s=Math.min(r,n);o<s;++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+">"},s&&(u.prototype[s]=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 s=(o>>>=0)-(n>>>=0),i=(r>>>=0)-(e>>>=0);const a=Math.min(s,i),l=this.slice(n,o),c=t.slice(e,r);for(let t=0;t<a;++t)if(l[t]!==c[t]){s=l[t],i=c[t];break}return s<i?-1:i<s?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 s=!1;for(;;)switch(n){case"hex":return v(this,t,e,r);case"utf8":case"utf-8":return I(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 B(this,t,e,r);default:if(s)throw new TypeError("Unknown encoding: "+n);n=(""+n).toLowerCase(),s=!0}},u.prototype.toJSON=function(){return{type:"Buffer",data:Array.prototype.slice.call(this._arr||this,0)}};const k=4096;function A(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 x(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 q(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+=Z[t[n]];return o}function T(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 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,n,o,s){if(!u.isBuffer(t))throw new TypeError('"buffer" argument must be a Buffer instance');if(e>o||e<s)throw new RangeError('"value" argument is out of bounds');if(r+n>t.length)throw new RangeError("Index out of range")}function O(t,e,r,n,o){F(e,n,o,t,r,7);let s=Number(e&BigInt(4294967295));t[r++]=s,s>>=8,t[r++]=s,s>>=8,t[r++]=s,s>>=8,t[r++]=s;let i=Number(e>>BigInt(32)&BigInt(4294967295));return t[r++]=i,i>>=8,t[r++]=i,i>>=8,t[r++]=i,i>>=8,t[r++]=i,r}function C(t,e,r,n,o){F(e,n,o,t,r,7);let s=Number(e&BigInt(4294967295));t[r+7]=s,s>>=8,t[r+6]=s,s>>=8,t[r+5]=s,s>>=8,t[r+4]=s;let i=Number(e>>BigInt(32)&BigInt(4294967295));return t[r+3]=i,i>>=8,t[r+2]=i,i>>=8,t[r+1]=i,i>>=8,t[r]=i,r+8}function N(t,e,r,n,o,s){if(r+n>t.length)throw new RangeError("Index out of range");if(r<0)throw new RangeError("Index out of range")}function P(t,e,r,n,s){return e=+e,r>>>=0,s||N(t,0,r,4),o.write(t,e,r,n,23,4),r+4}function L(t,e,r,n,s){return e=+e,r>>>=0,s||N(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||U(t,e,this.length);let n=this[t],o=1,s=0;for(;++s<e&&(o*=256);)n+=this[t+s]*o;return n},u.prototype.readUintBE=u.prototype.readUIntBE=function(t,e,r){t>>>=0,e>>>=0,r||U(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||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=J((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 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=J((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 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||U(t,e,this.length);let n=this[t],o=1,s=0;for(;++s<e&&(o*=256);)n+=this[t+s]*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||U(t,e,this.length);let n=e,o=1,s=this[t+--n];for(;n>0&&(o*=256);)s+=this[t+--n]*o;return o*=128,s>=o&&(s-=Math.pow(2,8*e)),s},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=J((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 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=J((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 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||U(t,4,this.length),o.read(this,t,!0,23,4)},u.prototype.readFloatBE=function(t,e){return t>>>=0,e||U(t,4,this.length),o.read(this,t,!1,23,4)},u.prototype.readDoubleLE=function(t,e){return t>>>=0,e||U(t,8,this.length),o.read(this,t,!0,52,8)},u.prototype.readDoubleBE=function(t,e){return t>>>=0,e||U(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,s=0;for(this[e]=255&t;++s<r&&(o*=256);)this[e+s]=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,s=1;for(this[e+o]=255&t;--o>=0&&(s*=256);)this[e+o]=t/s&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=J((function(t,e=0){return O(this,t,e,BigInt(0),BigInt("0xffffffffffffffff"))})),u.prototype.writeBigUInt64BE=J((function(t,e=0){return C(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,s=1,i=0;for(this[e]=255&t;++o<r&&(s*=256);)t<0&&0===i&&0!==this[e+o-1]&&(i=1),this[e+o]=(t/s|0)-i&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,s=1,i=0;for(this[e+o]=255&t;--o>=0&&(s*=256);)t<0&&0===i&&0!==this[e+o+1]&&(i=1),this[e+o]=(t/s|0)-i&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=J((function(t,e=0){return O(this,t,e,-BigInt("0x8000000000000000"),BigInt("0x7fffffffffffffff"))})),u.prototype.writeBigInt64BE=J((function(t,e=0){return C(this,t,e,-BigInt("0x8000000000000000"),BigInt("0x7fffffffffffffff"))})),u.prototype.writeFloatLE=function(t,e,r){return P(this,t,e,!0,r)},u.prototype.writeFloatBE=function(t,e,r){return P(this,t,e,!1,r)},u.prototype.writeDoubleLE=function(t,e,r){return L(this,t,e,!0,r)},u.prototype.writeDoubleBE=function(t,e,r){return L(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 s=u.isBuffer(t)?t:u.from(t,n),i=s.length;if(0===i)throw new TypeError('The value "'+t+'" is invalid for argument "value"');for(o=0;o<r-e;++o)this[o+e]=s[o%i]}return this};const M={};function D(t,e,r){M[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 W(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 F(t,e,r,n,o,s){if(t>r||t<e){const n="bigint"==typeof e?"n":"";let o;throw o=s>3?0===e||e===BigInt(0)?`>= 0${n} and < 2${n} ** ${8*(s+1)}${n}`:`>= -(2${n} ** ${8*(s+1)-1}${n}) and < 2 ** ${8*(s+1)-1}${n}`:`>= ${e}${n} and <= ${r}${n}`,new M.ERR_OUT_OF_RANGE("value",o,t)}!function(t,e,r){z(e,"offset"),void 0!==t[e]&&void 0!==t[e+r]||V(e,t.length-(r+1))}(n,o,s)}function z(t,e){if("number"!=typeof t)throw new M.ERR_INVALID_ARG_TYPE(e,"number",t)}function V(t,e,r){if(Math.floor(t)!==t)throw z(t,r),new M.ERR_OUT_OF_RANGE(r||"offset","an integer",t);if(e<0)throw new M.ERR_BUFFER_OUT_OF_BOUNDS;throw new M.ERR_OUT_OF_RANGE(r||"offset",`>= ${r?1:0} and <= ${e}`,t)}D("ERR_BUFFER_OUT_OF_BOUNDS",(function(t){return t?`${t} is outside of buffer bounds`:"Attempt to access memory outside buffer bounds"}),RangeError),D("ERR_INVALID_ARG_TYPE",(function(t,e){return`The "${t}" argument must be of type number. Received type ${typeof e}`}),TypeError),D("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=W(String(r)):"bigint"==typeof r&&(o=String(r),(r>BigInt(2)**BigInt(32)||r<-(BigInt(2)**BigInt(32)))&&(o=W(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 s=[];for(let i=0;i<n;++i){if(r=t.charCodeAt(i),r>55295&&r<57344){if(!o){if(r>56319){(e-=3)>-1&&s.push(239,191,189);continue}if(i+1===n){(e-=3)>-1&&s.push(239,191,189);continue}o=r;continue}if(r<56320){(e-=3)>-1&&s.push(239,191,189),o=r;continue}r=65536+(o-55296<<10|r-56320)}else o&&(e-=3)>-1&&s.push(239,191,189);if(o=null,r<128){if((e-=1)<0)break;s.push(r)}else if(r<2048){if((e-=2)<0)break;s.push(r>>6|192,63&r|128)}else if(r<65536){if((e-=3)<0)break;s.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;s.push(r>>18|240,r>>12&63|128,r>>6&63|128,63&r|128)}}return s}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 Y(t){return t!=t}const Z=function(){const t="0123456789abcdef",e=new Array(256);for(let r=0;r<16;++r){const n=16*r;for(let o=0;o<16;++o)e[n+o]=t[r]+t[o]}return e}();function J(t){return"undefined"==typeof BigInt?Q:t}function Q(){throw new Error("BigInt not supported")}},251(t,e){e.read=function(t,e,r,n,o){var s,i,a=8*o-n-1,u=(1<<a)-1,l=u>>1,c=-7,d=r?o-1:0,p=r?-1:1,f=t[e+d];for(d+=p,s=f&(1<<-c)-1,f>>=-c,c+=a;c>0;s=256*s+t[e+d],d+=p,c-=8);for(i=s&(1<<-c)-1,s>>=-c,c+=n;c>0;i=256*i+t[e+d],d+=p,c-=8);if(0===s)s=1-l;else{if(s===u)return i?NaN:1/0*(f?-1:1);i+=Math.pow(2,n),s-=l}return(f?-1:1)*i*Math.pow(2,s-n)},e.write=function(t,e,r,n,o,s){var i,a,u,l=8*s-o-1,c=(1<<l)-1,d=c>>1,p=23===o?Math.pow(2,-24)-Math.pow(2,-77):0,f=n?0:s-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,i=c):(i=Math.floor(Math.log(e)/Math.LN2),e*(u=Math.pow(2,-i))<1&&(i--,u*=2),(e+=i+d>=1?p/u:p*Math.pow(2,1-d))*u>=2&&(i++,u/=2),i+d>=c?(a=0,i=c):i+d>=1?(a=(e*u-1)*Math.pow(2,o),i+=d):(a=e*Math.pow(2,d-1)*Math.pow(2,o),i=0));o>=8;t[r+f]=255&a,f+=h,a/=256,o-=8);for(i=i<<o|a,l+=o;l>0;t[r+f]=255&i,f+=h,i/=256,l-=8);t[r+f-h]|=128*m}},468(t,e,r){r.d(e,{gm:()=>b,IY:()=>y,Vd:()=>g});const n={type:"string"},o={type:"number"},s={type:"boolean"},i={...n,nullable:!0},a={...o,nullable:!0},u={...n,enum:["mainnet","testnet"]},l={...n,enum:["ready","stale","incomplete"]};function c(t){return{type:"object",required:Object.keys(t),properties:t}}const d={sac:n,symbol:n,name:n,decimals:a,logoUrl:i},p=c({valid:s,stale:s,deviation:s,timestamp:a}),f=c({...d,hubId:o,hubName:n,amountRaw:{...i,description:"Integer token base units, never scaled shares."},amount:i,apy:{...a,description:"Fraction: 0.05 means 5%."},priceUsd:a,valueUsd:a,priceStatus:p,indexRay:i,indexedAt:o,indexedLedger:o}),h=c({amountRaw:i,amount:i,usd:a}),m=c({spokeId:o,spokeName:n,ltvBps:o,supplyCapacity:h,borrowCapacity:h,canSupply:s,canBeCollateral:s,canBorrow:s,canOpenAccount:{...s,description:"Spoke admits new accounts; other entry gates still apply."}}),g={type:"array",items:c({accountId:n,nftContract:n,nftImage:{...n,format:"uri",description:"Dynamic position SVG served by the network's XOXNO API."},network:u,spokeId:a,spokeName:i,supplied:{type:"array",items:f},borrow:{type:"array",items:f},hasDebt:{...s,nullable:!0,description:"Null when account rows are unavailable."},healthFactor:{...a,description:"Null without debt or when risk inputs are unavailable."},borrowLimitUsd:a,availableBorrowUsd:{...a,description:"Account headroom, before per-market constraints."},netApy:{...a,description:"Net annual yield divided by positive net equity; fraction."},dataStatus:l})},y={type:"array",items:c({...d,hubId:o,hubName:n,network:u,supplyApy:{...a,description:"Fraction: 0.05 means 5%."},borrowApy:{...a,description:"Fraction: 0.05 means 5%."},priceUsd:a,priceStatus:p,spokes:{type:"array",items:m},dataStatus:l,indexedAt:{...o,description:"Pool state timestamp. Capacities are indexed snapshot estimates; prepare/simulate before signing."},indexedLedger:o})};function w(t){if(!t)return;const e=/\s*<([^<>\s]+)>\s*((?:;\s*[\w!#$%&'*+.^`|~-]+\s*=\s*(?:"(?:[^"\\\r\n]|\\.)*"|[\w!#$%&'*+.^`|~:/-]+)\s*)*)(,|$)/gy;let r,n=0;for(;n<t.length;){const o=e.exec(t);if(!o||o[3]&&e.lastIndex===t.length)throw new Error("Invalid pagination Link header");let s=!1,i=!1;for(const t of o[2].matchAll(/;\s*([\w!#$%&'*+.^`|~-]+)\s*=\s*(?:"((?:[^"\\\r\n]|\\.)*)"|([\w!#$%&'*+.^`|~:/-]+))\s*/g))if("rel"===t[1].toLowerCase()){if(i)throw new Error("Duplicate pagination link relation");i=!0,s=(t[2]??t[3]).replace(/\\(.)/g,"$1").toLowerCase().split(/\s+/).includes("next")}if(s){if(void 0!==r)throw new Error("Multiple next pagination links");r=o[1]}n=e.lastIndex}return r}function b(t){const e=new URL(t.baseUrl.trim());if(!["https:","http:"].includes(e.protocol)||e.username||e.password||e.search||e.hash)throw new Error("baseUrl must be an HTTP API root without credentials, query or fragment");e.pathname=`${e.pathname.replace(/\/+$/,"")}/`;const r=t.fetch??globalThis.fetch?.bind(globalThis);if(!r)throw new Error("A fetch implementation is required");async function n(t,n){const o=new URL(`stellar-lending/v1/${t}`,e);let s=o;const i=new Set,a=[];for(;;){if(i.has(s.href))throw new Error("Pagination Link cycle");i.add(s.href);const t=await r(s.href,{signal:n,redirect:"error"});if(t.redirected||t.url&&new URL(t.url).href!==s.href)throw new Error("Stellar lending redirects are not allowed");if(!t.ok)throw new Error(`Stellar lending request failed: HTTP ${t.status}`);const e=await t.json();if(!Array.isArray(e))throw new Error("Stellar lending response must be an array");a.push(...e);const u=w(t.headers.get("Link"));if(!u)break;const l=new URL(u,s);if(l.origin!==o.origin||l.pathname!==o.pathname||l.username||l.password||l.hash)throw new Error("Pagination Link must stay on the same API endpoint");s=l}return a}return{assets:({usage:t,signal:e}={})=>{if(void 0!==t&&"collateral"!==t&&"borrow"!==t)throw new Error("usage must be collateral or borrow");return n("assets"+(t?`?usage=${t}`:""),e)},positions:(t,{signal:e}={})=>{if(!t.trim()||"."===t||".."===t)throw new Error("owner is required");return n(`users/${encodeURIComponent(t)}/positions`,e)}}}}},f={};function h(t){var e=f[t];if(void 0!==e)return e.exports;var r=f[t]={exports:{}};return p[t](r,r.exports,h),r.exports}h.d=(t,e)=>{for(var r in e)h.o(e,r)&&!h.o(t,r)&&Object.defineProperty(t,r,{enumerable:!0,get:e[r]})},h.o=(t,e)=>Object.prototype.hasOwnProperty.call(t,e);const m="erd1qqqqqqqqqqqqqpgq705fxpfrjne0tl3ece0rrspykq88mynn4kxs2cg43s",g="erd1qqqqqqqqqqqqqpgqd9rvv2n378e27jcts8vfwynpx0gfl5ufz6hqhfy0u0",y="erd1qqqqqqqqqqqqqpgq8xwzu82v8ex3h4ayl5lsvxqxnhecpwyvwe0sf2qj4e";var w;!function(t){t.MAINNET="1",t.DEVNET="D"}(w||(w={}));class b{apiUrl;chain;init;config;constructor(t){if(!t?.apiUrl?.trim())throw new Error("XOXNOClient: apiUrl is required");const{chain:e=w.MAINNET,apiUrl:r,...n}=t;this.apiUrl=r.trim().replace(/\/$/,""),this.chain=e,this.init=n,this.config=e==w.MAINNET?{mediaUrl:"https://media.xoxno.com",gatewayUrl:"https://gateway.xoxno.com",XO_SC:"erd1qqqqqqqqqqqqqpgq6wegs2xkypfpync8mn2sa5cmpqjlvrhwz5nqgepyg8",FM_SC:m,DR_SC:g,KG_SC:y,Staking_SC:"erd1qqqqqqqqqqqqqpgqvpkd3g3uwludduv3797j54qt6c888wa59w2shntt6z",Manager_SC:"erd1qqqqqqqqqqqqqpgqg9fa0dmpn8fu3fnleeqn5zt8rl8mdqjkys5s2gtas7",P2P_SC:"erd1qqqqqqqqqqqqqpgq47y8hnct68v6asjv6gxem6h9rumn9frzah0skhxxt6"}:{mediaUrl:"https://devnet-media.xoxno.com",gatewayUrl:"https://devnet-gateway.xoxno.com",XO_SC:"erd1qqqqqqqqqqqqqpgql0dnz6n5hpuw8cptlt00khd0nn4ja8eadsfq2xrqw4",FM_SC:m,DR_SC:g,KG_SC:y,Staking_SC:"erd1qqqqqqqqqqqqqpgqsc5hnewwpep8qq0d7kjjzrquapuucrygah0s85zres",Manager_SC:"erd1qqqqqqqqqqqqqpgqluclyhfsa2uw7q9cjwd8knk989hg57u8ah0slq2nlr",P2P_SC:"erd1qqqqqqqqqqqqqpgqfja7ukpngrun78ueq583l0vd6aj4ekhrah0sa9wyrv"}}fetchWithTimeout=async(t,{params:e,...r}={})=>{const{next:n,cache:o,debug:s,timeout:i,...a}=this.init,{next:u,cache:l,debug:c,timeout:d,headers:p,method:f="GET",...h}=r,m=p?.Authorization,g="Bearer undefined"===m?void 0:m,y="GET"!==f&&"HEAD"!==f&&"PUT"!==f,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("&"),v=`${this.apiUrl}${t}${b.length?`?${b}`:""}`,{revalidate:I,...S}=n??{},{revalidate:_,...B}=u??{},E="GET"!==f||g?void 0:_??I,R="GET"!==f||g||E?void 0:l??o,k=h.body,A=d??i??(null==k?3e4:0),x=A>0?AbortSignal.timeout(A):void 0,q=h.signal??a.signal,T=x&&q?AbortSignal.any([q,x]):x??q,U={...a,...h,method:f,...Object.keys(w).length?{headers:w}:{},...T?{signal:T}:{},cache:R,next:{...S,...B,revalidate:E}};(c??s)&&console.debug("SDK fetch: ",v,U);const $=await fetch(v,U).catch((t=>{if(t instanceof Error&&!t.message.match(/^http(s?):\/\//))throw Object.assign(new Error(`${v}: ${t.message}`),{cause:t});throw t})),O=await $.text();if(!$.ok){let t;try{t=JSON.parse(O)}catch{t={message:O}}const e=[v,$.status,$.statusText,t.message].filter(Boolean).join(";;");throw new Error(e)}try{return JSON.parse(O)}catch{return O}}}const v={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",lendingPool:"CBXRNDQMAJFG4VUKMKFEMFS75UUXE2SPSNV4LEEFCSNBCN66PYRWBKXO",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",lendingPool:"CBSGF6QOQAMPFBEVSYPEQHSZRIHJ6RCGUPCRDMUX36DEKRWFAO2PZB5A",aggregatorRouter:"CDNTWMWW2WGYTKIZTJYNGNVQQZI4KTC5BQRZ3275KESRX5T4O3AYECL5",governance:"CDS33JDOYH3F3FL4QUQ6DV4WKHML2AKHF4LADTZ57FRUAEBTE7NMY5FQ",priceAggregator:"CAALOOTIDXCX7D7FMQIBSSAJLPKOM3GMXS4UUSTDIG42JCRRJHOPUHOP",positionNftContract:"CDVN5JU675MEDPVRPCYC45AHFC275UH57WEU5OTFE4WFGZBNN7HTLPSY"}},I=v;function S(t){return v["testnet"===t?"stellarTestnet":"stellarMainnet"]}const _={mainnet:v.stellarMainnet.passphrase,testnet:v.stellarTestnet.passphrase};var B=h(287);const E=["Soroswap","Aquarius","Phoenix","Sushi","CometDex"],R={Soroswap:0,Aquarius:1,Phoenix:2,Sushi:3,CometDex:4},k=1,A=1e6,x=5,q=6,T=0,U=1,$=2,O=128,C=48,N=32,P=256,L=O-$,M=t=>new e(t).toScVal(),D=t=>new s(t).toI128(),W=t=>d.ScVal.scvU32(t),F=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 s("string"==typeof t?t:t.toString()).toU64()},z=t=>d.ScVal.scvBool(t),V=t=>d.ScVal.scvString(t),X=t=>d.ScVal.scvSymbol(t),j=()=>d.ScVal.scvVoid(),G=t=>d.ScVal.scvVec(t),H=(t,e=32)=>{const r=t.startsWith("0x")?t.slice(2):t,n=B.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 d.ScVal.scvBytes(n)},K=(t,e)=>null==t?j():e(t),Y=(t,e)=>tt({asset:M(e),hub_id:W(t)}),Z=(t,e,r)=>d.ScVal.scvVec([Y(t,e),D(r)]),J=t=>d.ScVal.scvVec(t.map((t=>Z(t.hubId,t.asset,t.amount)))),Q=t=>{if("Transfer"===t)return G([X("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 G([X("Credit"),F(e)])}throw new Error(`Stellar builder: SeizeMode must be 'Transfer' or { Credit: accountId }, got ${JSON.stringify(t)}`)},tt=t=>{const e=Object.keys(t).sort().map((e=>new d.ScMapEntry({key:X(e),val:t[e]})));return d.ScVal.scvMap(e)};class et{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>=P)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>=L)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>=N)throw new Error("Stellar builder: strategy uses more than 32 split weights");if(!Number.isInteger(t)||t<=0||t>A)throw new Error(`Stellar builder: split weight ${t} outside 1..=${A}`);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(R[r.venue],0===n?e:U,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 s=o.reduce(((t,r)=>t+e[r].splitPpm),0);if(s>A)throw new Error(`Stellar builder: split weights for one token sum to ${s}, above ${A}`);const i=s===A;let a=A;o.forEach(((t,n)=>{r[t]=!0;const s=e[t];let u;if(n+1===o.length&&i)u=T;else{if(0===a)throw new Error("Stellar builder: split weights exhaust the group before its last path");const t=Math.floor(s.splitPpm*A/a);a-=Math.min(s.splitPpm,a),u=O+this.weight(t)}this.emitPath(s,u)}))}}toBytes(t,e,r){if(0===this.ops.length)throw new Error("Stellar builder: strategy lowered to zero instructions");if(this.ops.length>C)throw new Error(`Stellar builder: strategy has ${this.ops.length} instructions, the router accepts ${C}`);const n=[k,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 B.hp.from(n)}get assetList(){return this.assets}get amountList(){return this.amounts}}const rt=t=>{const e=new et(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(x,T,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,s]=n,[i,a]=t.preSwapFromA?[o,s]:[s,o];e.emit(R.Aquarius,$+e.amount(r),e.asset(t.mintPool),e.asset(i),e.asset(a))}e.emit(q,T,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 tt({amounts:d.ScVal.scvVec(e.amountList.map((t=>D(t)))),assets:d.ScVal.scvVec(e.assetList.map((t=>M(t)))),ops:d.ScVal.scvBytes(e.toBytes(r,n,o))})},nt=t=>{const e=B.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 d.ScVal.scvBytes(e)},ot=()=>d.ScVal.scvBytes(B.hp.alloc(0)),st=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 B.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=B.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},it=t=>{if("string"==typeof t)return nt(st(t));if(t instanceof Uint8Array)return 0===t.length?ot():nt(t);if(t&&"object"==typeof t)return"routeXdr"in(r=t)&&"string"==typeof r.routeXdr?nt(st(t.routeXdr)):(t=>"swapXdr"in t&&"string"==typeof t.swapXdr)(t)?nt(st(t.swapXdr)):(t=>"bytes"in t&&("string"==typeof t.bytes||t.bytes instanceof Uint8Array))(t)?"string"==typeof t.bytes?nt(st(t.bytes)):0===t.bytes.length?ot():nt(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||!E.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>A)throw new Error(`Stellar builder: \`steps.paths[].splitPpm\` for ${t} sums to ${n}, above ${A}`);if(!e.mintPool&&n!==A)throw new Error(`Stellar builder: \`steps.paths[].splitPpm\` for ${t} must sum to ${A}, got ${n}`)}return e})(t),d.ScVal.scvBytes(B.hp.from(rt(e).toXDR("base64"),"base64")));var e,r;throw new Error("Stellar builder: `steps` must be opaque strategy bytes (`routeXdr`, base64/hex string, or Uint8Array)")},at=t=>{if("string"==typeof t)return(t=>{const e=t.startsWith("0x")?t.slice(2):t,r=B.hp.from(e,"hex");return d.ScVal.scvBytes(r)})(t);if(t instanceof Uint8Array)return d.ScVal.scvBytes(B.hp.from(t));throw new Error("Stellar builder: `data` must be a hex string or Uint8Array (Soroban Bytes payload)")};function ut(e,r,s){if(!e.controllerAddress)throw new Error("Stellar lending controllerAddress is required");const i=new o(e.controllerAddress),u=new t(e.caller,e.sourceSequence);return{xdr:new a(u,{fee:e.fee??n,networkPassphrase:_[e.network]}).addOperation(i.call(r,...s)).setTimeout(e.timeoutSeconds??300).build().toXDR()}}function lt(t){if(!Number.isInteger(t)||t<1||t>4294967295)throw new Error("Stellar builder: spokeId must be an integer from 1 to 4294967295");return W(t)}function ct(t,e){const r=e.accountNonce??0;return ut(t,"supply",[M(t.caller),F(r),lt(e.spokeId),J([...e.assets])])}function dt(t,e){return ct(t,{accountNonce:e.accountNonce,spokeId:e.spokeId,assets:[{hubId:e.hubId,asset:e.asset,amount:e.amount}]})}function pt(t,e){return ut(t,"borrow",[M(t.caller),F(e.accountNonce),J([...e.borrows]),K(e.to,M)])}function ft(t,e){return pt(t,{accountNonce:e.accountNonce,borrows:[{hubId:e.hubId,asset:e.asset,amount:e.amount}],to:e.to})}function ht(t,e){return ut(t,"withdraw",[M(t.caller),F(e.accountNonce),J([...e.withdrawals]),K(e.to,M)])}function mt(t,e){return ht(t,{accountNonce:e.accountNonce,withdrawals:[{hubId:e.hubId,asset:e.asset,amount:e.amount}],to:e.to})}function gt(t,e){return ut(t,"repay",[M(t.caller),F(e.accountNonce),J([...e.payments])])}function yt(t,e){return gt(t,{accountNonce:e.accountNonce,payments:[{hubId:e.hubId,asset:e.asset,amount:e.amount}]})}function wt(t,e){return ut(t,"liquidate",[M(t.caller),F(e.accountNonce),J([...e.debtPayments]),Q(e.seizeMode??"Transfer")])}function bt(t){const e=c(d.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 vt(t,e){return ut(t,"flash_loan",[M(t.caller),Y(e.hubId,e.asset),D(e.amount),M(e.receiver),at(e.data)])}function It(t,e){return ut(t,"migrate_from_blend",[M(t.caller),F(e.accountId),lt(e.spokeId),W(e.hubId),M(e.blendPool),G(e.collateralTokens.map(M)),G(e.supplyTokens.map(M)),(r=e.debtCaps.map((t=>({token:t.token,amount:t.cap}))),d.ScVal.scvVec(r.map((t=>{return e=t.token,r=t.amount,d.ScVal.scvVec([M(e),D(r)]);var e,r}))))]);var r}function St(t,e){const r=e.accountNonce??0;return ut(t,"multiply",[M(t.caller),F(r),lt(e.spokeId),Y(e.collateral.hubId,e.collateral.asset),D(e.debtToFlashLoan),Y(e.debt.hubId,e.debt.asset),W(e.mode),it(e.steps),K(e.initialPayment,(t=>Z(t.hubId,t.asset,t.amount))),K(e.convertSwap,it)])}function _t(t,e){return ut(t,"swap_debt",[M(t.caller),F(e.accountNonce),Y(e.existingDebt.hubId,e.existingDebt.asset),D(e.newDebtAmount),Y(e.newDebt.hubId,e.newDebt.asset),it(e.steps)])}function Bt(t,e){return ut(t,"swap_collateral",[M(t.caller),F(e.accountNonce),Y(e.current.hubId,e.current.asset),D(e.fromAmount),Y(e.newCollateral.hubId,e.newCollateral.asset),it(e.steps)])}function Et(t,e){return ut(t,"repay_debt_with_collateral",[M(t.caller),F(e.accountNonce),Y(e.collateral.hubId,e.collateral.asset),D(e.collateralAmount),Y(e.debt.hubId,e.debt.asset),it(e.steps),z(e.closePosition)])}const Rt="/stellar-lending",kt=encodeURIComponent,At=(t,e)=>t.fetchWithTimeout(`${Rt}/context`,e),xt=(t,e)=>t.fetchWithTimeout(`${Rt}/live-state`,e),qt=(t,e)=>t.fetchWithTimeout(`${Rt}/markets/detailed`,e),Tt=(t,e)=>t.fetchWithTimeout(`${Rt}/assets`,e),Ut=(t,e)=>t.fetchWithTimeout(`${Rt}/hubs`,e),$t=(t,e)=>t.fetchWithTimeout(`${Rt}/spokes`,e),Ot=(t,e={},r)=>t.fetchWithTimeout(`${Rt}/reserves`,{...r,params:{...e}}),Ct=(t,e,r,n,o)=>t.fetchWithTimeout(`${Rt}/reserves/${e}/${r}/${kt(n)}`,o),Nt=(t,e,r)=>t.fetchWithTimeout(`${Rt}/assets/${kt(e)}`,r),Pt=(t,e,r)=>t.fetchWithTimeout(`${Rt}/hubs/${e}`,r),Lt=(t,e,r)=>t.fetchWithTimeout(`${Rt}/spokes/${e}`,r),Mt=(t,e,r)=>t.fetchWithTimeout(`${Rt}/users/${kt(e)}/positions`,r),Dt=(t,e,r)=>t.fetchWithTimeout(`${Rt}/accounts/${kt(e)}/positions`,r),Wt=(t,e,r,n)=>t.fetchWithTimeout(`${Rt}/users/${kt(e)}/assets/${kt(r)}/balance`,n),Ft=(t,e,r,n)=>t.fetchWithTimeout(`${Rt}/assets/${kt(e)}/page`,{...n,params:{...r}}),zt=(t,e,r,n)=>t.fetchWithTimeout(`${Rt}/assets/${kt(e)}/markets`,{...n,params:{side:r}}),Vt=(t,e,r,n,o,s)=>t.fetchWithTimeout(`${Rt}/reserves/${e}/${r}/${kt(n)}/holders`,{...s,params:{side:o}}),Xt=(t,e,r,n)=>t.fetchWithTimeout(`${Rt}/hubs/${e}/holders`,{...n,params:{side:r}}),jt=(t,e,r,n)=>t.fetchWithTimeout(`${Rt}/spokes/${e}/holders`,{...n,params:{side:r}}),Gt=(t,e,r,n)=>t.fetchWithTimeout(`${Rt}/assets/${kt(e)}/graph`,{...n,params:{...r}}),Ht=(t,e,r,n)=>t.fetchWithTimeout(`${Rt}/hubs/${e}/graph`,{...n,params:{...r}}),Kt=(t,e,r,n)=>t.fetchWithTimeout(`${Rt}/spokes/${e}/graph`,{...n,params:{...r}}),Yt=(t,e,r,n,o,s)=>t.fetchWithTimeout(`${Rt}/reserves/${e}/${r}/${kt(n)}/graph`,{...s,params:{...o}}),Zt=(t,e,r={},n)=>t.fetchWithTimeout(`${Rt}/users/${kt(e)}/activity`,{...n,params:{...r}}),Jt=(t,e,r={},n)=>t.fetchWithTimeout(`${Rt}/users/${kt(e)}/activity/page`,{...n,params:{...r}}),Qt=(t,e={},r)=>t.fetchWithTimeout(`${Rt}/governance/proposals`,{...r,params:{...e}}),te=(t,e={},r)=>t.fetchWithTimeout(`${Rt}/positions`,{...r,params:{...e}}),ee=(t,e={},r)=>t.fetchWithTimeout(`${Rt}/participants`,{...r,params:{...e}}),re=(t,e={},r)=>t.fetchWithTimeout(`${Rt}/liquidations/leaderboard`,{...r,params:{...e}}),ne=(t,e={},r)=>t.fetchWithTimeout(`${Rt}/distribution`,{...r,params:{...e}}),oe=(t,e={},r)=>t.fetchWithTimeout(`${Rt}/campaign/leaderboard`,{...r,params:{...e}}),se=(t,e,r)=>t.fetchWithTimeout(`${Rt}/stats/history`,{...r,params:{...e}}),ie=(t,e,r)=>t.fetchWithTimeout(`${Rt}/revenue`,{...r,params:{...e}}),ae=(t,e,r)=>t.fetchWithTimeout(`${Rt}/revenue/fees`,{...r,params:{...e}}),ue=(t,e,r)=>t.fetchWithTimeout(`${Rt}/liquidations`,{...r,params:{...e}}),le=(t,e,r)=>t.fetchWithTimeout(`${Rt}/volume`,{...r,params:{...e}}),ce=(t,e,r)=>t.fetchWithTimeout(`${Rt}/active-users`,{...r,params:{...e}}),de=(t,e,r)=>t.fetchWithTimeout(`${Rt}/rate-spread`,{...r,params:{...e}}),pe=(t,e,r)=>t.fetchWithTimeout(`${Rt}/defillama`,{...r,params:{...e}}),fe=(t,e,r,n)=>t.fetchWithTimeout(`${Rt}/users/${kt(e)}/history`,{...n,params:{...r}}),he=(t,e,r)=>t.fetchWithTimeout(`${Rt}/pnl`,{...r,params:{accountId:e}}),me=(t,e,r)=>t.fetchWithTimeout(`${Rt}/pnl/scope`,{...r,params:{scope:e}}),ge=(t,e,r)=>t.fetchWithTimeout(`${Rt}/campaign/me`,{...r,params:{owner:e}}),ye=t=>({context:e=>At(t,e),liveState:e=>xt(t,e),marketsDetailed:e=>qt(t,e),assets:e=>Tt(t,e),hubs:e=>Ut(t,e),spokes:e=>$t(t,e),reserves:(e={},r)=>void 0!==r||"hubId"in e||"spokeId"in e||"asset"in e?Ot(t,e,r):Ot(t,{},e),reserve:(e,r,n,o)=>Ct(t,e,r,n,o),asset:(e,r)=>Nt(t,e,r),hub:(e,r)=>Pt(t,e,r),spoke:(e,r)=>Lt(t,e,r),userPositions:(e,r)=>Mt(t,e,r),accountPositions:(e,r)=>Dt(t,e,r),walletBalance:(e,r,n)=>Wt(t,e,r,n),assetPage:(e,r,n)=>Ft(t,e,r,n),assetMarkets:(e,r,n)=>zt(t,e,r,n),reserveHolders:(e,r,n,o,s)=>Vt(t,e,r,n,o,s),hubHolders:(e,r,n)=>Xt(t,e,r,n),spokeHolders:(e,r,n)=>jt(t,e,r,n),assetGraph:(e,r,n)=>Gt(t,e,r,n),hubGraph:(e,r,n)=>Ht(t,e,r,n),spokeGraph:(e,r,n)=>Kt(t,e,r,n),reserveGraph:(e,r,n,o,s)=>Yt(t,e,r,n,o,s),userActivity:(e,r={},n)=>Zt(t,e,r,n),userActivityPage:(e,r={},n)=>Jt(t,e,r,n),governanceProposals:(e={},r)=>Qt(t,e,r),positionsLeaderboard:(e={},r)=>te(t,e,r),participants:(e={},r)=>ee(t,e,r),liquidationsLeaderboard:(e={},r)=>re(t,e,r),distribution:(e={},r)=>ne(t,e,r),campaignLeaderboard:(e={},r)=>oe(t,e,r),statsHistory:(e,r)=>se(t,e,r),revenue:(e,r)=>ie(t,e,r),feeRevenue:(e,r)=>ae(t,e,r),liquidations:(e,r)=>ue(t,e,r),volume:(e,r)=>le(t,e,r),activeUsers:(e,r)=>ce(t,e,r),rateSpread:(e,r)=>de(t,e,r),defillama:(e,r)=>pe(t,e,r),userHistory:(e,r,n)=>fe(t,e,r,n),positionsPnl:(e,r)=>he(t,e,r),pnlByScope:(e,r)=>me(t,e,r),campaignMe:(e,r)=>ge(t,e,r)});var we=h(468);const be=t=>tt({base_borrow_rate:D(t.baseBorrowRateRay),max_borrow_rate:D(t.maxBorrowRateRay),max_utilization:D(t.maxUtilizationRay),mid_utilization:D(t.midUtilizationRay),optimal_utilization:D(t.optimalUtilizationRay),reserve_factor:W(t.reserveFactorBps),slope1:D(t.slope1Ray),slope2:D(t.slope2Ray),slope3:D(t.slope3Ray)}),ve=t=>tt({asset_decimals:W(t.assetDecimals),asset_id:M(t.assetId),base_borrow_rate:D(t.baseBorrowRateRay),flashloan_fee:W(t.flashloanFeeBps),is_flashloanable:z(t.isFlashloanable),max_borrow_rate:D(t.maxBorrowRateRay),max_utilization:D(t.maxUtilizationRay),mid_utilization:D(t.midUtilizationRay),optimal_utilization:D(t.optimalUtilizationRay),reserve_factor:W(t.reserveFactorBps),slope1:D(t.slope1Ray),slope2:D(t.slope2Ray),slope3:D(t.slope3Ray)}),Ie=t=>tt({max_borrow_positions:W(t.maxBorrowPositions),max_supply_positions:W(t.maxSupplyPositions)}),Se=t=>{if("Token"in t&&t.Token)return G([X("Token"),M(t.Token)]);if("Ref"in t&&t.Ref)return G([X("Ref"),X(t.Ref)]);throw new Error(`Stellar builder: PriceKey must be { Token } or { Ref }, got ${JSON.stringify(t)}`)},_e=t=>{if("Stellar"in t)return G([X("Stellar"),M(t.Stellar)]);if("Symbol"in t)return G([X("Symbol"),X(t.Symbol)]);if("String"in t)return G([X("String"),V(t.String)]);throw new Error(`Stellar builder: unknown OracleAssetRef ${JSON.stringify(t)}`)},Be=t=>{if("Spot"===t)return G([X("Spot")]);if(t&&"object"==typeof t&&"Twap"in t)return G([X("Twap"),W(Number(t.Twap))]);throw new Error(`Stellar builder: unknown OracleReadMode ${JSON.stringify(t)}`)},Ee=t=>{if("Reflector"===t||"RedStone"===t||"Xoxno"===t)return G([X(t)]);throw new Error(`Stellar builder: unknown ProviderKind "${t}"`)},Re=t=>{if("Market"===t||"Fundamental"===t)return G([X(t)]);throw new Error(`Stellar builder: unknown FeedNature "${t}"`)},ke=t=>{if("Reflector"in t){const e=t.Reflector;return G([X("Reflector"),tt({asset:_e(e.asset),contract:M(e.contract),read_mode:Be(e.readMode)})])}if("MultiFeed"in t){const e=t.MultiFeed;return G([X("MultiFeed"),tt({contract:M(e.contract),feed_id:V(e.feedId),kind:Ee(e.kind),nature:Re(e.nature)})])}throw new Error(`Stellar builder: unknown ProviderRef ${JSON.stringify(t)}`)},Ae=t=>{const e=t;return tt({decimals:W(e.decimals),max_stale_seconds:F(e.maxStaleSeconds),provider:ke(e.provider)})},xe=t=>{if("RequireDisjoint"===t)return G([X("RequireDisjoint")]);if(t&&"object"==typeof t&&"AllowShared"in t){const e=t.AllowShared;return G([X("AllowShared"),G(e.map((t=>tt({contract:M(t.contract),kind:Ee(t.kind)}))))])}throw new Error(`Stellar builder: unknown IndependencePolicy ${JSON.stringify(t)}`)},qe=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 tt({asset_decimals:W(Number(e.assetDecimals)),independence:xe(e.independence),max_price_stale_seconds:F(Number(e.maxPriceStaleSeconds)),max_sanity_price_wad:D(String(e.maxSanityPriceWad)),min_sanity_price_wad:D(String(e.minSanityPriceWad)),sources:G(r.map((t=>(t=>{if("Feed"in t)return G([X("Feed"),Ae(t.Feed)]);if("Scaled"in t){const e=t.Scaled;return G([X("Scaled"),tt({factor:Ae(e.factor),max_factor_wad:D(e.maxFactorWad),min_factor_wad:D(e.minFactorWad),quote:Se(e.quote)})])}if("LpShare"in t){const e=t.LpShare;return G([X("LpShare"),tt({key_a:Se(e.keyA),key_b:Se(e.keyB),kind:G([X(e.kind||"ConstantProduct")]),pool:M(e.pool),reserve_a_decimals:W(e.reserveADecimals),reserve_b_decimals:W(e.reserveBDecimals),share_decimals:W(e.shareDecimals)})])}throw new Error(`Stellar builder: unknown PriceSource ${JSON.stringify(t)}`)})(t)))),tolerance:tt({lower_ratio_bps:W(o),upper_ratio_bps:W(n)})})};function Te(t,e){return ut(t,"upgrade",[H(e.wasmHash)])}function Ue(t,e){return ut(t,"migrate",[W(e.newVersion)])}function $e(t){return ut(t,"pause",[])}function Oe(t){return ut(t,"unpause",[])}function Ce(t,e){return ut(t,"grant_role",[M(e.account),X(e.role)])}function Ne(t,e){return ut(t,"revoke_role",[M(e.account),X(e.role)])}function Pe(t,e){return ut(t,"transfer_ownership",[M(e.newOwner),W(e.liveUntilLedger)])}function Le(t){return ut(t,"accept_ownership",[])}function Me(t,e){return ut(t,"set_swap_aggregator",[M(e.aggregator)])}function De(t,e){return ut(t,"set_price_aggregator",[M(e.aggregator)])}function We(t,e){return ut(t,"set_accumulator",[M(e.accumulator)])}function Fe(t,e){return ut(t,"set_position_limits",[Ie(e)])}function ze(t,e){return ut(t,"approve_blend_pool",[M(e.pool)])}function Ve(t,e){return ut(t,"revoke_blend_pool",[M(e.pool)])}function Xe(t,e){return ut(t,"set_oracle",[Se(e.key),qe(e.oracle)])}function je(t,e){const r=e.toleranceBps,n=e.upperRatioBps??1e4+r,o=e.lowerRatioBps??Math.max(1,Math.floor(1e8/n));return ut(t,"set_tolerance",[Se(e.key),tt({lower_ratio_bps:W(o),upper_ratio_bps:W(n)})])}function Ge(t,e){return ut(t,"set_spoke_asset_flags",[W(e.spokeId),Y(e.hubId,e.asset),z(e.paused),z(e.frozen),z(e.noSeize)])}function He(t,e){return ut(t,"set_oracle_sanity_bounds",[M(e.asset),D(e.minPriceWad),D(e.maxPriceWad)])}function Ke(t,e){return ut(t,"update_indexes",[M(t.caller),G(e.assets.map((t=>Y(t.hubId,t.asset))))])}function Ye(t,e){return ut(t,"renew_account",[M(t.caller),F(e.accountNonce)])}function Ze(t,e){return ut(t,"create_liquidity_pool",[W(e.hubId),M(e.asset),ve(e.params)])}function Je(t,e){return ut(t,"upgrade_liquidity_pool_params",[Y(e.hubId,e.asset),be(e.params)])}function Qe(t,e){return ut(t,"claim_revenue",[M(t.caller),G(e.assets.map((t=>Y(t.hubId,t.asset))))])}function tr(t,e){return ut(t,"add_rewards",[M(t.caller),J(e.rewards)])}function er(t,e){return ut(t,"update_account_threshold",[M(t.caller),z(e.hasRisks),G(e.accountNonces.map((t=>F(t))))])}const rr="00".repeat(32),nr=t=>{if("string"==typeof t)return H(t);const e=B.hp.from(t);if(32!==e.length)throw new Error(`Stellar governance builder: expected a 32-byte salt (got ${e.length} bytes)`);return d.ScVal.scvBytes(e)},or=(t,...e)=>G([X(t),...e]),sr=t=>tt({new_owner:M(t.newOwner),live_until_ledger:W(t.liveUntilLedger)}),ir=t=>tt({asset:M(t.asset),bonus:W(t.bonus),borrow_cap:D(t.borrowCap),can_borrow:z(t.canBorrow),can_collateral:z(t.canCollateral),frozen:z(t.frozen),hub_id:W(t.hubId),paused:z(t.paused),liquidation_fees:W(t.liquidationFees),ltv:W(t.ltv),no_seize:z(t.noSeize),spoke_id:W(t.spokeId),supply_cap:D(t.supplyCap),threshold:W(t.threshold)}),ar=t=>tt({account:M(t.account),role:X(t.role)});function ur(e,r,s){if(!e.governanceAddress)throw new Error("Stellar governanceAddress is required");const i=new o(e.governanceAddress),u=new t(e.caller,e.sourceSequence);return{xdr:new a(u,{fee:e.fee??n,networkPassphrase:_[e.network]}).addOperation(i.call(r,...s)).setTimeout(e.timeoutSeconds??300).build().toXDR()}}const lr=(t,e,r)=>ur(t,"propose",[M(t.caller),e,nr(r)]),cr=(t,e,r)=>ur(t,"execute_self",[j(),e,nr(r)]);function dr(t,e,r){return lr(t,or("SetSwapAggregator",M(e.aggregator)),r)}function pr(t,e,r){return lr(t,or("SetPriceAggregator",M(e.aggregator)),r)}function fr(t,e,r){return lr(t,or("SetAccumulator",M(e.accumulator)),r)}function hr(t,e,r){return lr(t,or("SetPositionLimits",Ie(e)),r)}function mr(t,e){return lr(t,or("CreateHub"),e)}function gr(t,e){return lr(t,or("AddSpoke"),e)}function yr(t,e,r){return lr(t,or("RemoveSpoke",W(e.spokeId)),r)}function wr(t,e,r){return lr(t,or("AddAssetToSpoke",ir(e)),r)}function br(t,e,r){return lr(t,or("EditAssetInSpoke",ir(e)),r)}function vr(t,e,r){return lr(t,or("RemoveAssetFromSpoke",tt({hub_asset:Y((n=e).hubId,n.asset),spoke_id:W(n.spokeId)})),r);var n}function Ir(t,e,r){return lr(t,or("SetSpokeLiquidationCurve",tt({hf_for_max_bonus_wad:D((n=e).hfForMaxBonusWad),liquidation_bonus_factor_bps:W(n.liquidationBonusFactorBps),spoke_id:W(n.spokeId),target_hf_wad:D(n.targetHfWad)})),r);var n}function Sr(t,e,r){return lr(t,or("SetPositionManager",M(e.manager),z(e.isActive)),r)}function _r(t,e,r){return lr(t,or("SetMinBorrowCollateralUsd",D(e.floorWad)),r)}function Br(t,e,r){return lr(t,or("ApproveToken",M(e.token)),r)}function Er(t,e,r){return lr(t,or("RevokeToken",M(e.token)),r)}function Rr(t,e,r){return lr(t,or("ApproveBlendPool",M(e.pool)),r)}function kr(t,e,r){return lr(t,or("RevokeBlendPool",M(e.pool)),r)}function Ar(t,e,r){return lr(t,or("CreateLiquidityPool",tt({asset:M((n=e).asset),hub_id:W(n.hubId),params:ve(n.params)})),r);var n}function xr(t,e,r){return lr(t,or("UpgradeLiquidityPoolParams",tt({hub_asset:Y((n=e).hubId,n.asset),params:be(n.params)})),r);var n}function qr(t,e,r){return lr(t,or("DeployPool",H(e.wasmHash)),r)}function Tr(t,e,r){return lr(t,or("UpgradePool",H(e.wasmHash)),r)}function Ur(t,e,r){return lr(t,or("UpgradeController",H(e.wasmHash)),r)}function $r(t,e,r){return lr(t,or("MigrateController",W(e.newVersion)),r)}function Or(t,e,r){return lr(t,or("TransferCtrlOwnership",sr(e)),r)}function Cr(t,e,r){return lr(t,or("ConfigureAssetOracle",tt({key:Se((n=e).key),oracle:qe(n.oracle)})),r);var n}function Nr(t,e,r){return lr(t,or("EditOracleTolerance",tt({key:Se((n=e).key),tolerance:W(n.tolerance)})),r);var n}function Pr(t,e,r){return lr(t,or("UpgradeGov",H(e.wasmHash)),r)}function Lr(t,e,r){return lr(t,or("UpdateGovDelay",W(e.newDelay)),r)}function Mr(t,e,r){return lr(t,or("GrantGovRole",ar(e)),r)}function Dr(t,e,r){return lr(t,or("RevokeGovRole",ar(e)),r)}function Wr(t,e,r){return lr(t,or("TransferGovOwnership",sr(e)),r)}function Fr(t,e){const r=G(e.argsXdr.map((t=>d.ScVal.fromXDR(t,"base64")))),n=nr(e.predecessor??rr);return ur(t,"execute",[j(),M(e.target),X(e.functionName),r,n,nr(e.salt)])}function zr(t,e,r){return cr(t,or("UpgradeGov",H(e.wasmHash)),r)}function Vr(t,e,r){return cr(t,or("UpdateGovDelay",W(e.newDelay)),r)}function Xr(t,e,r){return cr(t,or("GrantGovRole",ar(e)),r)}function jr(t,e,r){return cr(t,or("RevokeGovRole",ar(e)),r)}function Gr(t,e,r){return cr(t,or("TransferGovOwnership",sr(e)),r)}const Hr=t=>G(t.map(M));function Kr(t,e,r){return ur(t,"propose_canceller_reset",[Hr(e.newCancellers),nr(r)])}function Yr(t,e,r){return ur(t,"execute_canceller_reset",[K(e.executor,M),Hr(e.newCancellers),nr(r)])}function Zr(t,e){return ur(t,"set_spoke_asset_flags",[M(t.caller),W(e.spokeId),Y(e.hubId,e.asset),z(e.paused),z(e.frozen),z(e.noSeize)])}function Jr(t,e){return ur(t,"set_oracle_sanity_bounds",[M(t.caller),M(e.asset),D(e.minPriceWad),D(e.maxPriceWad)])}function Qr(t){return ur(t,"create_hub",[M(t.caller)])}function tn(t){return ur(t,"add_spoke",[M(t.caller)])}function en(t,e){return ur(t,"revoke_role_immediate",[M(e.account),X(e.role)])}function rn(t){return ur(t,"pause",[M(t.caller)])}function nn(t,e){return lr(t,or("Unpause"),e)}const on=t=>t.toXDR("base64"),sn=t=>d.ScVal.fromXDR(t,"base64"),an=t=>t.map((t=>String(c(sn(t))))).join(":"),un=t=>"bigint"==typeof t||"number"==typeof t?t.toString():String(t),ln=t=>Number(t),cn=t=>String(t),dn=t=>t instanceof Uint8Array?B.hp.from(t).toString("hex"):B.hp.isBuffer(t)?t.toString("hex"):String(t),pn=["None","Multiply","Long","Short"],fn=["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"],hn=t=>Array.isArray(t)?t:[],mn=(t,e)=>{const r="Borrow"===e;return{action:(n=t[0],fn[ln(n)]??un(n)),positionType:e,hubId:ln(t[1]),asset:cn(t[2]),scaledAmountRay:un(t[3]),indexRay:un(t[4]),amount:un(t[5]),liquidationThresholdBps:r?void 0:ln(t[6]),liquidationBonusBps:r?void 0:ln(t[7]),loanToValueBps:r?void 0:ln(t[8]),liquidationFeesBps:r?void 0:ln(t[9])};var n},gn=t=>{return{owner:cn(t[0]),spokeId:ln(t[1]),mode:(e=t[2],pn[ln(e)]??"None")};var e},yn=t=>Array.isArray(t)?t[1]:void 0,wn=t=>{const e=(r=t,Array.isArray(r)?cn(r[0]):cn(r));var r;if("Token"===e)return{Token:cn(yn(t))};if("Ref"===e)return{Ref:cn(yn(t))};if(t&&"object"==typeof t&&!Array.isArray(t)){const e=t;if(void 0!==e.Token)return{Token:cn(e.Token)};if(void 0!==e.Ref)return{Ref:cn(e.Ref)}}return{Token:cn(t)}},bn=t=>{const e=t.tolerance??{};return{assetDecimals:ln(t.asset_decimals),maxPriceStaleSeconds:ln(t.max_price_stale_seconds),sources:hn(t.sources).map((t=>t)),tolerance:{upperRatio:ln(e.upper_ratio_bps),lowerRatio:ln(e.lower_ratio_bps)},independence:t.independence,minSanityPriceWad:un(t.min_sanity_price_wad),maxSanityPriceWad:un(t.max_sanity_price_wad)}},vn={"market:create":t=>({topic:"market:create",data:{hubId:ln(t.hub_id),baseAsset:cn(t.base_asset),maxBorrowRate:un(t.max_borrow_rate),baseBorrowRate:un(t.base_borrow_rate),slope1:un(t.slope1),slope2:un(t.slope2),slope3:un(t.slope3),midUtilization:un(t.mid_utilization),optimalUtilization:un(t.optimal_utilization),maxUtilization:un(t.max_utilization),reserveFactor:ln(t.reserve_factor),marketAddress:cn(t.market_address)}}),"market:params_update":t=>({topic:"market:params_update",data:{asset:cn(t.asset),maxBorrowRateRay:un(t.max_borrow_rate),baseBorrowRateRay:un(t.base_borrow_rate),slope1Ray:un(t.slope1),slope2Ray:un(t.slope2),slope3Ray:un(t.slope3),midUtilizationRay:un(t.mid_utilization),optimalUtilizationRay:un(t.optimal_utilization),maxUtilizationRay:un(t.max_utilization),reserveFactorBps:ln(t.reserve_factor)}}),"market:batch_state_update":t=>({topic:"market:batch_state_update",data:{updates:hn(t).map((t=>{return e=hn(t),{hubId:ln(e[0]),asset:cn(e[1]),timestamp:ln(e[2]),supplyIndexRay:un(e[3]),borrowIndexRay:un(e[4]),cash:un(e[5]),suppliedRay:un(e[6]),borrowedRay:un(e[7]),revenueRay:un(e[8])};var e}))}}),"market:batch_params_update":t=>({topic:"market:batch_params_update",data:{updates:hn(t).map((t=>{const e=t;return{hubId:ln(e.hub_id),asset:cn(e.asset),params:(r=e.params,{maxBorrowRateRay:un(r.max_borrow_rate),baseBorrowRateRay:un(r.base_borrow_rate),slope1Ray:un(r.slope1),slope2Ray:un(r.slope2),slope3Ray:un(r.slope3),midUtilizationRay:un(r.mid_utilization),optimalUtilizationRay:un(r.optimal_utilization),maxUtilizationRay:un(r.max_utilization),reserveFactorBps:ln(r.reserve_factor),isFlashloanable:Boolean(r.is_flashloanable),flashloanFeeBps:ln(r.flashloan_fee),assetId:cn(r.asset_id),assetDecimals:ln(r.asset_decimals)})};var r}))}}),"position:batch_update":t=>{const e=hn(t);return{topic:"position:batch_update",data:{accountId:un(e[0]),accountAttributes:gn(hn(e[1])),updates:[...hn(e[2]).map((t=>mn(hn(t),"Deposit"))),...hn(e[3]).map((t=>mn(hn(t),"Borrow")))]}}},"position:flash_loan":t=>({topic:"position:flash_loan",data:{hubId:ln(t.hub_id),asset:cn(t.asset),receiver:cn(t.receiver),caller:cn(t.caller),amount:un(t.amount),fee:un(t.fee)}}),"config:asset_oracle":t=>({topic:"config:asset_oracle",data:{key:wn(t.key),oracle:bn(t.oracle)}}),"config:oracle":t=>({topic:"config:oracle",data:{asset:cn(t.asset),oracle:bn(t.config??t.oracle)}}),"position:liquidation":t=>({topic:"position:liquidation",data:{liquidator:cn(t.liquidator),accountId:un(t.account_id),repaidUsdWad:un(t.repaid_usd_wad),bonusBps:un(t.bonus_bps)}}),"debt:bad_debt":t=>({topic:"debt:bad_debt",data:{accountId:un(t.account_id),totalBorrowUsdWad:un(t.total_borrow_usd_wad),totalCollateralUsdWad:un(t.total_collateral_usd_wad)}}),"strategy:initial_payment":t=>({topic:"strategy:initial_payment",data:{token:cn(t.token),amount:un(t.amount),usdValueWad:un(t.usd_value_wad),accountId:un(t.account_id)}}),"strategy:fee":t=>({topic:"strategy:fee",data:{hubId:ln(t.hub_id),asset:cn(t.asset),amount:un(t.amount),fee:un(t.fee),amountSent:un(t.amount_sent)}}),"config:approve_blend_pool":t=>({topic:"config:approve_blend_pool",data:{pool:cn(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:dn(t.wasm_hash??t.pool),approved:Boolean(t.approved)}}),"config:swap_aggregator":t=>({topic:"config:swap_aggregator",data:{aggregator:cn(t.aggregator??t.swap_aggregator)}}),"config:price_aggregator":t=>({topic:"config:price_aggregator",data:{aggregator:cn(t.aggregator??t.price_aggregator)}}),"config:aggregator":t=>({topic:"config:aggregator",data:{aggregator:cn(t.aggregator)}}),"config:accumulator":t=>({topic:"config:accumulator",data:{accumulator:cn(t.accumulator)}}),"config:pool_template":t=>({topic:"config:pool_template",data:{wasmHash:dn(t.wasm_hash)}}),"config:position_limits":t=>({topic:"config:position_limits",data:{maxSupplyPositions:ln(t.max_supply_positions),maxBorrowPositions:ln(t.max_borrow_positions)}}),"config:min_borrow_collateral":t=>({topic:"config:min_borrow_collateral",data:{minBorrowCollateralUsdWad:un(t.min_borrow_collateral_usd_wad??t.floor_wad??t.value)}}),"config:oracle_disabled":t=>({topic:"config:oracle_disabled",data:{asset:cn(t.asset)}}),"config:spoke":t=>{const e=t.spoke;return{topic:"config:spoke",data:{spokeId:ln(e.spoke_id),isDeprecated:Boolean(e.is_deprecated),liquidationTargetHfWad:un(e.liquidation_target_hf_wad),healthFactorForMaxBonusWad:un(e.hf_for_max_bonus_wad),liquidationBonusFactorBps:ln(e.liquidation_bonus_factor_bps)}}}},In=Object.freeze(Object.keys(vn));function Sn(t,e){const r=an(t),n=vn[r];return n?n(c(sn(e))):null}const _n=1e4;function Bn(t,e){return`${t}-${BigInt(e).toString(10)}`}function En(t){const e=t.split("-");return e.length>=2&&parseInt(e[1],10)||0}function Rn(t,e=0){return 1e4*t+e}function kn(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 An=(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 xn(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=An(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,simulate:t.simulate,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 qn(t){if(!t.baseUrl)throw new Error("Stellar quote baseUrl is required");const e=An(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()}function Tn(t,e){const r=t[e];return"function"==typeof r?r.call(t):r}function Un(t){if(!t||"object"!=typeof t)return;const e=t;return"function"==typeof e.switch?e.switch().name:e.type}function $n(t){return On(Tn(t,"bytes"))}function On(t){const e=t;return B.hp.from("value"in e?e.value:e)}const Cn=10,Nn=5,Pn=3,Ln=Cn+Nn*C+Pn*N,Mn=16384;class Dn extends Error{code;constructor(t,e){super(`Stellar route verification failed [${t}]: ${e}`),this.name="StellarRouteVerificationError",this.code=t}}const Wn=(t,e)=>{throw new Dn(t,e)},Fn=t=>{const e="string"==typeof t?t:t&&"object"==typeof t&&"routeXdr"in t?t.routeXdr:void 0;if("string"==typeof e&&e.length>2*Mn)return Wn("OVERSIZED",`encoded route has ${e.length} characters`);try{return $n(it(t))}catch(t){return Wn("MALFORMED",t instanceof Error?t.message:String(t))}},zn=t=>{let e;try{e=d.ScVal.fromXDR(t)}catch(t){return Wn("MALFORMED",`payload is not one XDR ScVal: ${t instanceof Error?t.message:String(t)}`)}if("scvMap"!==Un(e))return Wn("MALFORMED","payload must be a StrategyPayload map");const r=Tn(e,"map")??[];if("amounts,assets,ops"!==r.map((t=>"scvSymbol"===Un(Tn(t,"key"))?Tn(Tn(t,"key"),"sym").toString():"")).join(","))return Wn("MALFORMED","payload fields must be exactly amounts, assets, ops");const[n,o,s]=r.map((t=>Tn(t,"val")));return"scvVec"!==Un(n)||"scvVec"!==Un(o)||"scvBytes"!==Un(s)?Wn("MALFORMED","payload field has the wrong type"):{amounts:Tn(n,"vec")??[],assets:Tn(o,"vec")??[],ops:$n(s)}};function Vn(t){const r=Fn(t);0===r.length&&Wn("MALFORMED","route is empty"),r.length>Mn&&Wn("OVERSIZED",`route has ${r.length} bytes, above ${Mn}`);const n=zn(r),o=n.assets.length,s=n.amounts.length;0===o&&Wn("MALFORMED","asset registry is empty"),(o>P||s>L)&&Wn("OVERSIZED",`registries hold ${o} assets and ${s} amounts`);const i=n.assets.map(((t,r)=>"scvAddress"!==Un(t)?Wn("MALFORMED",`assets[${r}] is not an address`):e.fromScAddress(Tn(t,"address")).toString())),a=n.amounts.map(((t,e)=>"scvI128"!==Un(t)?Wn("MALFORMED",`amounts[${e}] is not an i128`):l(t))),u=n.ops;u.length<Cn&&Wn("MALFORMED","program header is truncated"),u.length>Ln&&Wn("OVERSIZED",`program has ${u.length} bytes, above ${Ln}`);const c=t=>{const e=u[t];return void 0===e?Wn("MALFORMED",`program byte ${t} is missing`):e},d=c(0);d!==k&&Wn("UNSUPPORTED_VERSION",`program version ${d}, expected ${k}`);const p=c(8),f=c(9);0===p&&Wn("INVALID_STRUCTURE","program has no instructions"),(p>C||f>N)&&Wn("OVERSIZED",`program declares ${p} instructions and ${f} weights`);const h=Cn+Nn*p;u.length!==h+Pn*f&&Wn("MALFORMED","program length does not match its instruction and weight counts");const m=c(1),g=c(2),y=c(3);(m>=o||g>=o||y>=s)&&Wn("MALFORMED","header index is outside its registry"),m===g&&Wn("INVALID_STRUCTURE","token_in equals token_out");const w=u.readUInt32BE(4),b=[];for(let t=0;t<f;t+=1){const e=u.readUIntBE(h+Pn*t,Pn);(0===e||e>A)&&Wn("INVALID_STRUCTURE",`split weight ${e} outside 1..=${A}`),b.push(e)}const v=t=>i[t]??Wn("MALFORMED",`asset index ${t} is outside the registry`),I=t=>a[t]??Wn("MALFORMED",`amount index ${t} is outside the registry`),S=[];let _;for(let t=0;t<p;t+=1){const e=Cn+Nn*t,r=c(e),n=c(e+1),o=c(e+2),i=c(e+3),a=c(e+4);let u;if(r>q&&Wn("UNKNOWN_OPCODE",`instruction ${t} has opcode ${r}`),n===T)u={kind:"all"};else if(n===U)void 0!==_&&_===i||Wn("INVALID_STRUCTURE",`instruction ${t} does not chain onto its predecessor`),u={kind:"prev"};else if(n>=O){const e=b[n-O];void 0===e&&Wn("MALFORMED",`instruction ${t} weight index is out of range`),u={kind:"ppm",ppm:e}}else u={kind:"fixed",amount:I(n-$)};const l=v(o);r!==x&&r!==q?(i===a&&Wn("INVALID_STRUCTURE",`instruction ${t} swaps a token for itself`),S.push({kind:"swap",venue:E[r],mode:u,pool:l,tokenIn:v(i),tokenOut:v(a)}),_=a):("all"!==u.kind&&Wn("MALFORMED",`liquidity instruction ${t} must use mode All`),a>=s&&Wn("MALFORMED",`instruction ${t} amount index is out of range`),S.push({kind:r===x?"burn":"mint",pool:l,shareToken:v(i),amountIndex:a}),_=r===q?i:void 0)}const B=I(y);return B<=0n&&Wn("MIN_OUT_TOO_LOW",`encoded total_min_out is ${B}`),{version:d,tokenIn:v(m),tokenOut:v(g),totalMinOut:B,referralId:w,assets:i,amounts:a,ops:S,weights:b}}function Xn(t,e){if(i.isValidContract(t))return t;if(!e)return Wn("EXPECTATION_MISSING",`token ${t} is not a contract id; pass \`network\` to derive its asset contract`);try{const n=t.indexOf(":");return("XLM"===t||"native"===t?r.native():new r(t.slice(0,n),t.slice(n+1))).contractId(_[e])}catch{return Wn("MALFORMED",`token id ${t} is not a contract id or a classic asset`)}}const jn=(t,e)=>"bigint"==typeof t?t:/^\d+$/.test(t)?BigInt(t):Wn("EXPECTATION_MISSING",`${e} must be a base-unit integer string`);function Gn(t,e){const r=jn(e.minOut,"expected.minOut");r<=0n&&Wn("EXPECTATION_MISSING","expected.minOut must be positive");const n=Vn(t);if(n.tokenIn!==e.tokenIn&&Wn("TOKEN_IN_MISMATCH",`route spends ${n.tokenIn}, expected ${e.tokenIn}`),n.tokenOut!==e.tokenOut&&Wn("TOKEN_OUT_MISMATCH",`route delivers ${n.tokenOut}, expected ${e.tokenOut}`),n.totalMinOut<r&&Wn("MIN_OUT_TOO_LOW",`route enforces a minimum of ${n.totalMinOut}, below the expected ${r}`),void 0!==e.amountIn){const t=jn(e.amountIn,"expected.amountIn");for(const e of n.ops)"swap"===e.kind&&"fixed"===e.mode.kind&&e.tokenIn===n.tokenIn&&e.mode.amount>t&&Wn("AMOUNT_IN_EXCEEDED",`a leg spends ${e.mode.amount}, above the input ${t}`)}return n}const Hn=t=>rt(t).toXDR("base64");function Kn(e,r){if(!e.routerAddress)throw new Error("Stellar aggregator routerAddress is required");const s=new o(e.routerAddress),i=new t(e.caller,e.sourceSequence),u=it(((t,e)=>(t=>Boolean(t&&"object"==typeof t&&!(t instanceof Uint8Array)&&"paths"in t))(t)&&void 0===t.referralId?{...t,referralId:e??0}:t)(r,e.referralId));return{xdr:new a(i,{fee:e.fee??n,networkPassphrase:_[e.network]}).addOperation(s.call("execute_strategy",M(e.caller),D(e.totalIn),u)).setTimeout(e.timeoutSeconds??300).build().toXDR()}}function Yn(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(Jn),splitPpm:t.splitPpm}))):[{hops:t.hops.map(Jn),splitPpm:1e6}],referralId:e.referralId??0,tokenIn:t.from,tokenOut:t.to,totalMinOut:t.amountOutMin}}function Zn(t,e={}){const r=e.expected??{},n="string"==typeof t.routeXdr&&t.routeXdr.length>0?{routeXdr:t.routeXdr}:Yn(t,e),o=[t.amountOutMin,r.minOut].filter((t=>void 0!==t)).map((t=>{if("bigint"==typeof t)return t;if("string"!=typeof t||!/^\d+$/.test(t))throw new Dn("MALFORMED","minimum output must be a base-unit integer string");return BigInt(t)})).reduce(((t,e)=>void 0===t||e>t?e:t),void 0);if(void 0===o)throw new Dn("EXPECTATION_MISSING","quote has no `amountOutMin`; pass `slippage` when fetching it or `expected.minOut`");return Gn(n,{tokenIn:Xn(r.tokenIn??t.from,e.network),tokenOut:Xn(r.tokenOut??t.to,e.network),minOut:o,amountIn:r.amountIn??t.amountIn}),n}const Jn=t=>({amountOut:t.amountOut,pool:t.address,tokenIn:t.from,tokenOut:t.to,venue:t.dex});function Qn(t){try{const{envelopeXdr:r,networkPassphrase:n,routerAddress:o,viewer:s,operationIndex:u}=t;if(!n||!i.isValidContract(o)||new e(s).toString()!==s||"string"!=typeof r||r.length>1048576||r.length%4!=0||!/^[A-Za-z0-9+/]+={0,2}$/.test(r)||void 0!==u&&(!Number.isSafeInteger(u)||u<0))return null;const c=a.fromXDR(r,n),d="innerTransaction"in c?c.innerTransaction:c;if(void 0!==u&&u>=d.operations.length)return null;let p=null;for(const[t,r]of d.operations.entries()){if(void 0!==u&&t!==u)continue;if("invokeHostFunction"!==r.type)continue;const n=r.func;if("hostFunctionTypeInvokeContract"!==Un(n))continue;const a=Tn(n,"invokeContract");if(e.fromScAddress(Tn(a,"contractAddress")).toString()!==o||"execute_strategy"!==Tn(a,"functionName").toString())continue;const c=Tn(a,"args"),[d,f,h]=c;if(3!==c.length||!d||!f||!h||"scvAddress"!==Un(d)||"scvI128"!==Un(f)||"scvBytes"!==Un(h))return null;if(e.fromScAddress(Tn(d,"address")).toString()!==s)continue;const m=l(f);if(m<=0n)return null;const g=Vn($n(h));if(g.tokenIn===g.tokenOut||!i.isValidContract(g.tokenIn)||!i.isValidContract(g.tokenOut))return null;if(p)return null;p={tokenIn:g.tokenIn,tokenOut:g.tokenOut,amountInAtoms:m.toString(),operationIndex:t}}return p}catch{return null}}class to extends Error{code;offender;constructor(t,e,r){super(`Stellar authorization check failed [${t}]: ${e}${r?` — ${r.contract}.${r.fn}(${r.args.join(", ")})`:""}`),this.name="StellarAuthPolicyError",this.code=t,this.offender=r}}const eo=t=>t&&"scvAddress"===Un(t)?e.fromScAddress(Tn(t,"address")).toString():void 0,ro=t=>t&&"scvI128"===Un(t)?l(t):void 0,no=t=>t&&"scvVec"===Un(t)?Tn(t,"vec")??[]:void 0,oo=(t,e)=>{if(!t||"scvMap"!==Un(t))return;const r=(Tn(t,"map")??[]).find((t=>"scvSymbol"===Un(Tn(t,"key"))&&Tn(Tn(t,"key"),"sym").toString()===e));return r?Tn(r,"val"):void 0},so=t=>eo(t)??ro(t)?.toString()??t.toXDR("base64"),io=t=>({contract:e.fromScAddress(Tn(t,"contractAddress")).toString(),fn:Tn(t,"functionName").toString(),args:Tn(t,"args").map(so)}),ao=t=>{const e=Tn(t,"function");return"sorobanAuthorizedFunctionTypeContractFn"===Un(e)?Tn(e,"contractFn"):void 0};function uo(t,r,n){const o=t.filter((t=>{const o=Tn(t,"credentials"),s=Un(o);if("sorobanCredentialsAddress"!==s&&"sorobanCredentialsSourceAccount"!==s)throw new to("MALFORMED_TRANSACTION","unsupported authorization credentials");return("sorobanCredentialsAddress"===s?e.fromScAddress(Tn(Tn(o,"address"),"address")).toString():n??r.caller)===r.caller}));if(o.length>1)throw new to("DUPLICATE_ENTRY",`${o.length} authorization entries for ${r.caller}, expected one`);const s=o[0];if(!s)return;const i=ao(Tn(s,"rootInvocation"));if(!i)throw new to("UNEXPECTED_ROOT","root is not a contract call");const a=io(i);if(a.contract!==r.root.contract||a.fn!==r.root.fn)throw new to("UNEXPECTED_ROOT",`expected ${r.root.contract}.${r.root.fn}`,a);const u=r.transfers.map((()=>0n)),l=(r.calls??[]).map((()=>0));for(const t of Tn(Tn(s,"rootInvocation"),"subInvocations")){const e=ao(t);if(!e)throw new to("UNEXPECTED_CALL","sub-invocation is not a contract call");const n=io(e);if(Tn(t,"subInvocations").length>0)throw new to("NESTED_INVOCATION","sub-invocation carries its own sub-invocations",n);const o=(r.calls??[]).findIndex((t=>t.contract===n.contract&&t.fn===n.fn));if(-1!==o){const t=(r.calls??[])[o],s=t.reject(Tn(e,"args"));if(s)throw new to("UNEXPECTED_CALL",s,n);if(l[o]=(l[o]??0)+1,(l[o]??0)>t.maxCount)throw new to("UNEXPECTED_CALL",`more than ${t.maxCount} calls`,n);continue}if("transfer"!==n.fn||3!==Tn(e,"args").length)throw new to("UNEXPECTED_CALL","only `transfer` is allowed",n);if(!r.transfers.some((t=>t.token===n.contract)))throw new to("UNEXPECTED_TOKEN","transfer on an unexpected token",n);const[s,i,a]=Tn(e,"args");if(eo(s)!==r.caller)throw new to("UNEXPECTED_SENDER","transfer is not from the caller",n);const c=eo(i),d=r.transfers.findIndex((t=>t.token===n.contract&&t.to===c));if(-1===d)throw new to("UNEXPECTED_RECIPIENT","transfer to an unexpected recipient",n);const p=ro(a),f=r.transfers[d],h=(u[d]??0n)+(p??0n);if(void 0===p||p<=0n||h>f.maxAmount)throw new to("AMOUNT_EXCEEDED",`transfers total ${h}, above the expected ${f.maxAmount}`,n);u[d]=h}}const lo=t=>{throw new to("MALFORMED_TRANSACTION",t)},co=(t,e)=>{const r=new Map;for(const e of no(t)??lo("payments argument is not a vector")){const[t,n]=no(e)??[],o=eo(oo(t,"asset")),s=ro(n);if(void 0===o||void 0===s||s<0n)return lo("payment is not a (HubAssetKey, i128) tuple");r.set(o,(r.get(o)??0n)+s)}return[...r].map((([t,r])=>({token:t,to:e,maxAmount:r})))},po=new Set([1,3,5]),fo=(t,e,r)=>({contract:t,fn:"submit",maxCount:2,reject:t=>{if(4!==t.length)return"submit must have four arguments";if(eo(t[0])!==e)return"`from` is not the caller";if(eo(t[1])!==r||eo(t[2])!==r)return"`spender` and `to` must be the lending controller";const n=no(t[3]);if(!n)return"requests is not a vector";for(const t of n){const e=oo(t,"request_type");if(!e||"scvU32"!==Un(e)||!po.has(Tn(e,"u32")))return"request is not a withdraw, withdraw-collateral, or repay"}}});function ho(t,e,r){const{contract:n,fn:o}=io(e),s=Tn(e,"args"),i={caller:t,root:{contract:n,fn:o},transfers:[]};if(n===r.governance)return i;if(n===r.aggregatorRouter){if("execute_strategy"!==o)return i;const e=ro(s[1]);if(eo(s[0])!==t||void 0===e||"scvBytes"!==Un(s[2]))return lo("execute_strategy arguments must be (caller, total_in, swap_xdr)");const r=Vn($n(s[2]));return i.transfers=[{token:r.tokenIn,to:n,maxAmount:e}],i}if(n!==r.lendingController)throw new to("UNSUPPORTED_CONTRACT",`no authorization policy for contract ${n}; pass an explicit policy`);if(eo(s[0])!==t)throw new to("CALLER_MISMATCH",`${o} is not invoked for ${t}`);switch(o){case"supply":i.transfers=co(s[3],r.lendingPool);break;case"repay":case"liquidate":i.transfers=co(s[2],r.lendingPool);break;case"multiply":{const t=s[8];t&&"scvVoid"!==Un(t)&&(i.transfers=co(d.ScVal.scvVec([t]),n));break}case"migrate_from_blend":{const e=eo(s[4])??lo("blend_pool is not an address");i.calls=[fo(e,t,n)];break}}return i}const mo=t=>{let e;try{e=d.TransactionEnvelope.fromXDR(t,"base64")}catch{return lo("not a transaction envelope")}if("envelopeTypeTx"!==Un(e))return lo("expected a regular (v1) transaction");const r=Tn(Tn(e,"v1"),"tx"),n=Tn(r,"operations")[0];if(!n||1!==Tn(r,"operations").length)return lo("expected exactly one operation");const o=Tn(n,"body");if("invokeHostFunction"!==Un(o))return lo("operation is not a contract invocation");const s=Tn(o,"invokeHostFunctionOp");return"hostFunctionTypeInvokeContract"!==Un(Tn(s,"hostFunction"))?lo("host function is not a contract call"):{source:(a=Tn(n,"sourceAccount")??Tn(r,"sourceAccount"),i.encodeEd25519PublicKey(On("keyTypeMuxedEd25519"===Un(a)?Tn(Tn(a,"med25519"),"ed25519"):Tn(a,"ed25519")))),op:s,call:Tn(Tn(s,"hostFunction"),"invokeContract")};var a};function go(t,e){const r=mo(t);if(void 0!==e.builtXdr&&Tn(mo(e.builtXdr).op,"hostFunction").toXDR("base64")!==Tn(r.op,"hostFunction").toXDR("base64"))throw new to("INVOCATION_CHANGED","the prepared transaction does not invoke what was built",io(r.call));const n=e.policy??ho(e.caller,r.call,{...S(e.network),...e.deployment});uo(Tn(r.op,"auth"),n,r.source)}function yo(t,e){const r=e instanceof Error?e.message:String(e);return new Error(`[xoxno-invoked:${t}] ${r}`)}async function wo(t,e,r){const n=r?.instructionLeeway??2e7;if(!Number.isInteger(n)||n<0||n>4294967295)throw new Error("instructionLeeway must be an integer from 0 to 4294967295");const o=a.fromXDR(e,r?.network?_[r.network]:"");try{const e=await t.simulateTransaction(o,{cpuInstructions:n});if(u.Api.isSimulationError(e))throw new Error(e.error);return u.assembleTransaction(o,e).build().toXDR()}catch(t){if(r?.invokedContractId)throw yo(r.invokedContractId,t);throw t}}async function bo(t,e,r){return wo(t,e.xdr,r)}function vo(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 Io(t,e){return new Uint8Array(0)}const So=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 B.hp.from(e,"hex")};function _o(e){const r=new t(e.caller,e.sourceSequence),n=new o(e.forwarderAddress).call("mint_and_forward",d.ScVal.scvBytes(So(e.message)),d.ScVal.scvBytes(So(e.attestation)));return{xdr:new a(r,{fee:e.fee??"10000000",networkPassphrase:_[e.network]}).addOperation(n).setTimeout(e.timeoutSeconds??120).build().toXDR()}}const Bo=10n**27n,Eo=10n**18n,Ro=10000n,ko=27,Ao=18;function xo(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 qo(t,e,r){if(0n===r)throw new Error("Stellar math: division by zero");return t*e/r}function To(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 Uo(t,e,r){if(0n===r)throw new Error("Stellar math: division by zero");return(t*e+r/2n)/r}function $o(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 Oo=t=>10n**BigInt(t);function Co(t,e,r){return e===r?t:r>e?t*Oo(r-e):t/Oo(e-r)}function No(t,e,r){if(e===r)return t;if(r>e)return t*Oo(r-e);const n=Oo(e-r),o=t/n;return t%n===0n?o:o+1n}function Po(t,e,r){return e===r?t:r>e?t*Oo(r-e):$o(t,Oo(e-r))}const Lo={floor:qo,ceil:To,halfUp:Uo},Mo={floor:Co,ceil:No,halfUp:Po};function Do(t,e,r,n){return Mo[n](Lo[n](t,e,Bo),ko,r)}function Wo(t,e,r){return Do(xo(t,"scaledRay"),xo(e,"indexRay"),r,"floor")}function Fo(t,e,r){return Do(xo(t,"scaledRay"),xo(e,"indexRay"),r,"ceil")}function zo(t,e,r){return Do(xo(t,"scaledRay"),xo(e,"indexRay"),r,"halfUp")}function Vo(t,e){if(e>ko)throw new Error(`Stellar math: decimals ${e} exceed RAY scale`);return Co(t,e,ko)}function Xo(t,e,r,n){const o=Lo[n](t,e,Bo),s=Mo[n](o,ko,Ao);return Lo[n](s,r,Eo)}function jo(t,e,r,n){const o=Mo[n](Vo(t,e),ko,Ao);return Lo[n](o,r,Eo)}const Go=t=>Number(t)/1e18,Ho=t=>Number(t)/1e27,Ko=(t,e)=>Number(t)/10**e;function Yo(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 Zo=t=>Yo(t,Ao),Jo=(t,e)=>Uo(t,e,Bo),Qo=(t,e)=>Uo(t,Bo,e);function ts(t,e){return 0n===e?0n:Qo(t,e)}function es(t,e){const r=t>Bo?Bo:t,n=xo(e.baseRateRay,"irm.baseRateRay"),o=xo(e.slope1Ray,"irm.slope1Ray"),s=xo(e.slope2Ray,"irm.slope2Ray"),i=xo(e.slope3Ray,"irm.slope3Ray"),a=xo(e.midUtilizationRay,"irm.midUtilizationRay"),u=xo(e.optimalUtilizationRay,"irm.optimalUtilizationRay"),l=xo(e.maxBorrowRateRay,"irm.maxBorrowRateRay");let c;if(r<a)c=n+Qo(Jo(r,o),a);else if(r<u){const t=u-a;c=n+o+Qo(Jo(r-a,s),t)}else{const t=Bo-u;c=n+o+s+(0n===t?0n:Qo(Jo(r-u,i),t))}return c>l?l:c}function rs(t,e,r){return 0n===t||!Number.isInteger(r)||r<0||r>=1e4?0n:Uo(Jo(t,e),Ro-BigInt(r),Ro)}const ns=t=>Ho(t),os=t=>Math.expm1(Ho(t)),ss=5n*Eo,is=(t,e,r)=>`${t}:${e}:${r}`;function as(t,e,r,n){const o=Array.isArray(t)?t:void 0,s=o?o.find((t=>t.spokeId===e&&t.hubId===r&&t.asset===n)):t[is(e,r,n)]??Object.values(t).find((t=>t.spokeId===e&&t.hubId===r&&t.asset===n));if(!s)throw new Error(`Stellar math: no reserve for ${is(e,r,n)}`);return s}const us=/^0*[1-9]\d*$/,ls=t=>"string"==typeof t&&us.test(t)?BigInt(t).toString():null,cs=(t,e)=>`${t}:${e}`;function ds(t){const e=new Map,r=new Map,n=new Set,o=new Set;for(const s of t?.indexes??[]){const t=cs(s.hubId,s.asset),i=ls(s.supplyIndex),a=ls(s.borrowIndex),u=ls(s.usdPrice),l=e.get(t),c=l&&ls(l.supplyIndex)===i&&ls(l.borrowIndex)===a&&ls(l.usdPrice)===u;null==i||null==a||null==u||l&&!c?n.add(t):l||e.set(t,s);const d=!1===s.valid||!0===s.stale||!0===s.deviation,p=r.get(s.asset);null==u||d||void 0!==p&&p.toString()!==u?o.add(s.asset):void 0===p&&r.set(s.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 ps=(t,e)=>qo(t,BigInt(e),Ro);function fs(t,e,r,n){const o="supply"===t.side,s=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:Go(t.priceWad),amountBase:e.toString(),amountShort:Ko(e,t.decimals),usdWad:r.toString(),usd:Go(r),gateUsdWad:n.toString(),entryLtvBps:t.entryLtvBps,entryLiquidationThresholdBps:t.entryLiquidationThresholdBps,entryLiquidationBonusBps:t.entryLiquidationBonusBps,entryLiquidationFeesBps:t.entryLiquidationFeesBps,ltvWeightedUsdWad:o?ps(n,s).toString():"0",liquidationWeightedUsdWad:o?ps(n,t.entryLiquidationThresholdBps).toString():"0",liveDataUsed:t.liveDataUsed}}function hs(t){if("supply"===t.side)return fs(t,Do(t.scaledRay,t.indexRay,t.decimals,"floor"),Xo(t.scaledRay,t.indexRay,t.priceWad,"halfUp"),Xo(t.scaledRay,t.indexRay,t.priceWad,"floor"));const e=Do(t.scaledRay,t.indexRay,t.decimals,"ceil"),r=Xo(t.scaledRay,t.indexRay,t.priceWad,"ceil");return fs(t,e,r,r)}function ms(t,e,r,n){const o=Vo(e,r);return"supply"===t?qo(o,Bo,n):To(o,Bo,n)}function gs(t,e,r,n){const o=Vo(e,r);return"supply"===t?To(o,Bo,n):qo(o,Bo,n)}function ys(t,e){return hs({...t,scaledRay:ms(t.side,e,t.decimals,t.indexRay)})}const ws=(...t)=>{for(const e of t){const t=ls(e);if(null!=t)return BigInt(t)}return Bo};function bs(t,e,r,n){const o=xo("supply"===t?e.supplyScaledRay:e.borrowScaledRay,`${t}ScaledRay`);if(0n===o)return null;const s=n.indexes.get(cs(e.hubId,e.asset)),i=n.prices.get(e.asset),a="supply"===t?ws(s?.supplyIndex,e.liveSupplyIndexRay,r.liveSupplyIndexRay,e.supplyIndexRay):ws(s?.borrowIndex,e.liveBorrowIndexRay,r.liveBorrowIndexRay,e.borrowIndexRay),u=i??Zo(r.usdPrice);return hs({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!==s&&void 0!==i})}const vs=(t,e)=>t.reduce(((t,r)=>t+BigInt(e(r))),0n);function Is(t,e,r,n,o){const s=vs(e,(t=>t.usdWad)),i=vs(e,(t=>t.ltvWeightedUsdWad)),a=vs(e,(t=>t.liquidationWeightedUsdWad)),u=vs(r,(t=>t.usdWad)),l=0n===u?null:qo(a,Eo,u),c=0n===a?0:Number(u)/Number(a)*100,d=i<n||i<=u?0n:i-u;return{...t,supplies:e,borrows:r,totalCollateralUsdWad:s.toString(),totalCollateralUsd:Go(s),ltvWeightedCollateralUsdWad:i.toString(),ltvWeightedCollateralUsd:Go(i),liquidationWeightedCollateralUsdWad:a.toString(),liquidationWeightedCollateralUsd:Go(a),totalDebtUsdWad:u.toString(),totalDebtUsd:Go(u),healthFactorWad:null===l?null:l.toString(),healthFactor:null===l?null:Go(l),healthPercent:c,borrowLimitUsdWad:i.toString(),borrowLimitUsd:Go(i),availableBorrowUsdWad:d.toString(),availableBorrowUsd:Go(d),minBorrowCollateralUsdWad:n.toString(),minBorrowCollateralUsd:Go(n),isLiquidatable:null!==l&&l<Eo,liveDataValid:o}}function Ss(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 s=ds(n),i=[],a=[];for(const t of e){const e=as(r,t.spokeId,t.hubId,t.asset),n=bs("supply",t,e,s);n&&i.push(n);const o=bs("borrow",t,e,s);o&&a.push(o)}const u=null!=n?.minBorrowCollateralUsdWad?xo(n.minBorrowCollateralUsdWad,"minBorrowCollateralUsdWad"):ss,l=void 0!==n&&[...i,...a].every((t=>t.liveDataUsed));return Is({accountId:o.accountId,owner:o.owner,spokeId:o.spokeId,mode:o.positionMode},i,a,u,l)}const _s=200n,Bs=t=>t.reduce(((t,e)=>e.amount<t.amount?e:t)),Es=t=>t<0n?0n:t,Rs=(t,e,r,n)=>({amountBase:t.amount,amountShort:Ko(t.amount,e),isFullClose:r,reason:t.reason,projectedUtilization:n}),ks=t=>({amountBase:0n,amountShort:0,isFullClose:!1,reason:t,projectedUtilization:null});function As(t){const e=t.assetDecimals,r=xo(t.irm.maxUtilizationRay,"irm.maxUtilizationRay");return{suppliedBase:Yo(t.hubPool.suppliedShort,e),borrowedBase:Yo(t.hubPool.borrowedShort,e),cashBase:Yo(t.availableLiquidityShort,e),spokeSuppliedBase:Yo(t.suppliedShort,e),spokeBorrowedBase:Yo(t.borrowedShort,e),maxUtilizationRay:r>=Bo?null:r}}const xs=(t,e)=>t<=0n?null:Number(e)/Number(t);function qs(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 Ts=(t,e)=>t.find((t=>t.hubId===e.hubId&&t.asset===e.asset));function Us(t,e,r){if(e.paused)return ks("paused");if(e.frozen)return ks("frozen");if(!e.isBorrowable)return ks("cap");const n=e.assetDecimals,o=As(e),s=Ts(t.borrows,e),i=ds(r).indexes.get(cs(e.hubId,e.asset)),a=s?BigInt(s.indexRay):xo(i?.borrowIndex??e.liveBorrowIndexRay,"borrowIndex"),u=s?BigInt(s.usdPriceWad):function(t,e){return ds(e).prices.get(t.asset)??Zo(t.usdPrice)}(e,r),l=s?BigInt(s.scaledRay):0n,c=BigInt(t.totalDebtUsdWad)-(s?BigInt(s.usdWad):0n),d=BigInt(t.ltvWeightedCollateralUsdWad),p=BigInt(t.minBorrowCollateralUsdWad),f=[];if(d<p)f.push({amount:0n,reason:"minCollateral"});else{const e=d-BigInt(t.totalDebtUsdWad),r=e<=0n||u<=0n?0n:qo(e,10n**BigInt(n),u),o=t=>c+Xo(l+ms("borrow",t,n,a),a,u,"ceil");f.push({amount:0n===r?0n:qs(r+16n,(t=>o(t)<=d)),reason:"ltv"})}f.push({amount:Es(xo(e.borrowCap,"borrowCap")-o.spokeBorrowedBase),reason:"cap"});const h=Uo(o.suppliedBase,200n,Ro);f.push({amount:Es(o.cashBase-h),reason:"liquidity"});const m=function(t,e){const r=t.maxUtilizationRay;if(null===r)return null;const n=Vo(t.suppliedBase,e);return 0n===n?null:qs(Es(qo(t.suppliedBase,r,Bo)-t.borrowedBase)+16n,(o=>ts(Vo(t.borrowedBase+o,e),n)<=r))}(o,n);null!==m&&f.push({amount:m,reason:"utilizationCap"});const g=Bs(f);return Rs(g,n,!1,xs(o.suppliedBase,o.borrowedBase+g.amount))}function $s(t,e,r){if(e.paused)return ks("paused");const n=Ts(t.supplies,e);if(!n)return ks(null);const o=n.decimals,s=As(e),i=BigInt(n.scaledRay),a=BigInt(n.indexRay),u=BigInt(n.usdPriceWad),l=BigInt(n.amountBase),c=Do(i,a,o,"halfUp"),d=BigInt(t.totalDebtUsdWad),p=BigInt(t.minBorrowCollateralUsdWad),f=BigInt(Math.min(n.entryLtvBps,n.entryLiquidationThresholdBps)),h=[];let m=!0;if(d>0n&&f>0n){const e=d>p?d:p,r=p>d?"minCollateral":"healthFactor",s=BigInt(t.ltvWeightedCollateralUsdWad)-BigInt(n.ltvWeightedUsdWad);if(s<e){m=!1;const t=e-s,l=To(t,Ro,f),d=BigInt(n.gateUsdWad)-l,p=d<=0n?0n:qo(d,10n**BigInt(o),u),g=c>0n?c-1n:0n,y=p+16n>g?g:p+16n,w=t=>{const e=gs("supply",t,o,a);return qo(Xo(e>=i?0n:i-e,a,u,"floor"),f,Ro)};h.push({amount:qs(y,(e=>w(e)>=t)),reason:r})}}h.push({amount:l,reason:null}),h.push({amount:s.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=To(t.borrowedBase,Bo,r),o=t.suppliedBase<n?0n:t.suppliedBase-n+16n,s=Vo(t.borrowedBase,e);return qs(o>t.suppliedBase?t.suppliedBase:o,(n=>{const o=Vo(t.suppliedBase-n,e);return o>0n&&ts(s,o)<=r}))}(s,o);null!==g&&h.push({amount:g,reason:"utilizationCap"});const y=Bs(h),w=m&&y.amount>=l;return Rs(y,o,w,xs(s.suppliedBase-y.amount,s.borrowedBase))}function Os(t){if(t.paused)return ks("paused");if(t.frozen)return ks("frozen");const e=t.assetDecimals,r=As(t),n={amount:Es(xo(t.supplyCap,"supplyCap")-r.spokeSuppliedBase),reason:"cap"};return Rs(n,e,!1,xs(r.suppliedBase+n.amount,r.borrowedBase))}function Cs(t,e,r){if(e.paused)return ks("paused");const n=Ts(t.borrows,e);if(!n)return ks(null);const o=n.decimals,s=As(e),i=BigInt(n.amountBase),a=void 0===r?null:xo(r,"walletBalance"),u=null!==a&&a<i?{amount:a,reason:"liquidity"}:{amount:i,reason:null};return Rs(u,o,u.amount>=i,xs(s.suppliedBase,Es(s.borrowedBase-u.amount)))}const Ns=(t,e)=>t.hubId===e.hubId&&t.asset===e.asset,Ps=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 Ls(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=>Ns(e,t))),s=-1===o?void 0:e[o],i=Ps(t.amountBase);let a;if(s){const t={side:s.side,hubId:s.hubId,asset:s.asset,decimals:s.decimals,indexRay:BigInt(s.indexRay),priceWad:BigInt(s.usdPriceWad),entryLtvBps:s.entryLtvBps,entryLiquidationThresholdBps:s.entryLiquidationThresholdBps,entryLiquidationBonusBps:s.entryLiquidationBonusBps,entryLiquidationFeesBps:s.entryLiquidationFeesBps,liveDataUsed:s.liveDataUsed},e=BigInt(s.scaledRay);let r;if(i>=0n)r=e+ms(t.side,i,t.decimals,t.indexRay);else{const n=-i,o=n>=("supply"===t.side?Do(e,t.indexRay,t.decimals,"halfUp"):BigInt(s.amountBase))?e:gs(t.side,n,t.decimals,t.indexRay);r=o>=e?0n:e-o}a=0n===r?null:hs({...t,scaledRay:r})}else a=i<=0n?null:ys(Ms(t),i);-1===o?a&&e.push(a):a?e[o]=a:e.splice(o,1)}return Is({accountId:t.accountId,owner:t.owner,spokeId:t.spokeId,mode:t.mode},r,n,BigInt(t.minBorrowCollateralUsdWad),t.liveDataValid)}function Ms(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:xo("supply"===t.side?e.liveSupplyIndexRay:e.liveBorrowIndexRay,"reserve live index"),priceWad:Zo(e.usdPrice),entryLtvBps:e.collateralFactorBps,entryLiquidationThresholdBps:e.liquidationThresholdBps,entryLiquidationBonusBps:e.liquidationPenaltyBps,entryLiquidationFeesBps:e.liquidationFeesBps,liveDataUsed:!1}}function Ds(t,e=0n,r=0n){const n=t.assetDecimals,o=t=>t<0n?0n:t,s=o(Yo(t.hubPool.suppliedShort,n)+Ps(e)),i=ts(Vo(o(Yo(t.hubPool.borrowedShort,n)+Ps(r)),n),Vo(s,n)),a=es(i,t.irm),u=rs(i,a,t.irm.reserveFactorBps);return{utilization:Ho(i),utilizationRay:i.toString(),borrowAprRay:a.toString(),supplyAprRay:u.toString(),borrowApr:ns(a),supplyApr:ns(u),borrowApy:os(a),supplyApy:os(u)}}const Ws={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."},14:{name:"AmountMustBePositive",message:"The amount must be greater than zero."},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 Fs(t){const e=t.match(/Error\(Contract,\s*#(\d+)\)/);if(!e)return null;const r=Number(e[1]),n=Ws[r];return n?{code:r,...n}:null}export{Ro as BPS,ss as DEFAULT_MIN_BORROW_COLLATERAL_USD_WAD,_s as LIQUIDATION_BUFFER_BPS,Bo as RAY,ko as RAY_DECIMALS,rr as STELLAR_GOVERNANCE_ZERO_PREDECESSOR,In as STELLAR_LENDING_TOPICS,v as STELLAR_NETWORKS,_ as STELLAR_NETWORK_PASSPHRASE,Mn as STELLAR_ROUTE_MAX_BYTES,_n as SYNTHETIC_EVENT_ORDER_STRIDE,to as StellarAuthPolicyError,Dn as StellarRouteVerificationError,Eo as WAD,Ao as WAD_DECIMALS,b as XOXNOClient,Is as aggregateAccountRisk,es as annualBorrowRateRay,uo as assertStellarAuthEntries,go as assertStellarPreparedTxAuth,Vo as baseToRay,Ko as baseToShort,jo as baseValueWad,ds as buildLiveSnapshot,Io as buildSameTokenRepaySwapSteps,Le as buildStellarAcceptOwnershipTx,tr as buildStellarAddRewardsTx,ze as buildStellarApproveBlendPoolTx,pt as buildStellarBorrowBatchTx,ft as buildStellarBorrowTx,_o as buildStellarCctpForwardTx,Qe as buildStellarClaimRevenueTx,Ze as buildStellarCreateLiquidityPoolTx,Yr as buildStellarExecuteCancellerResetTx,Kn as buildStellarExecuteStrategyTx,vt as buildStellarFlashLoanTx,tn as buildStellarGovernanceAddSpokeImmediateTx,Qr as buildStellarGovernanceCreateHubImmediateTx,zr as buildStellarGovernanceExecuteGovernanceUpgradeTx,Xr as buildStellarGovernanceExecuteGrantGovernanceRoleTx,jr as buildStellarGovernanceExecuteRevokeGovernanceRoleTx,Gr as buildStellarGovernanceExecuteTransferGovOwnTx,Fr as buildStellarGovernanceExecuteTx,Vr as buildStellarGovernanceExecuteUpdateDelayTx,rn as buildStellarGovernancePauseTx,en as buildStellarGovernanceRevokeRoleImmediateTx,Jr as buildStellarGovernanceSetOracleSanityBoundsImmediateTx,Zr as buildStellarGovernanceSetSpokeAssetFlagsImmediateTx,Ce as buildStellarGrantRoleTx,Bn as buildStellarLendingIdentifier,wt as buildStellarLiquidateTx,It as buildStellarMigrateFromBlendTx,Ue as buildStellarMigrateTx,St as buildStellarMultiplyTx,$e as buildStellarPauseTx,wr as buildStellarProposeAddAssetToSpokeTx,gr as buildStellarProposeAddSpokeTx,Rr as buildStellarProposeApproveBlendPoolTx,Br as buildStellarProposeApproveTokenTx,Kr as buildStellarProposeCancellerResetTx,Cr as buildStellarProposeConfigureAssetOracleTx,mr as buildStellarProposeCreateHubTx,Ar as buildStellarProposeCreateLiquidityPoolTx,qr as buildStellarProposeDeployPoolTx,br as buildStellarProposeEditAssetInSpokeTx,Nr as buildStellarProposeEditOracleToleranceTx,Pr as buildStellarProposeGovernanceUpgradeTx,Mr as buildStellarProposeGrantGovernanceRoleTx,$r as buildStellarProposeMigrateControllerTx,vr as buildStellarProposeRemoveAssetFromSpokeTx,yr as buildStellarProposeRemoveSpokeTx,kr as buildStellarProposeRevokeBlendPoolTx,Dr as buildStellarProposeRevokeGovernanceRoleTx,Er as buildStellarProposeRevokeTokenTx,fr as buildStellarProposeSetAccumulatorTx,_r as buildStellarProposeSetMinBorrowCollatTx,hr as buildStellarProposeSetPositionLimitsTx,Sr as buildStellarProposeSetPositionManagerTx,pr as buildStellarProposeSetPriceAggregatorTx,Ir as buildStellarProposeSetSpokeLiquidationCurveTx,dr as buildStellarProposeSetSwapAggregatorTx,Or as buildStellarProposeTransferCtrlOwnershipTx,Wr as buildStellarProposeTransferGovOwnTx,nn as buildStellarProposeUnpauseTx,Lr as buildStellarProposeUpdateDelayTx,Ur as buildStellarProposeUpgradeControllerTx,xr as buildStellarProposeUpgradePoolParamsTx,Tr as buildStellarProposeUpgradePoolTx,Ye as buildStellarRenewAccountTx,gt as buildStellarRepayBatchTx,Et as buildStellarRepayDebtWithCollateralTx,yt as buildStellarRepayTx,Ve as buildStellarRevokeBlendPoolTx,Ne as buildStellarRevokeRoleTx,We as buildStellarSetAccumulatorTx,He as buildStellarSetOracleSanityBoundsTx,je as buildStellarSetOracleToleranceTx,Xe as buildStellarSetOracleTx,Fe as buildStellarSetPositionLimitsTx,De as buildStellarSetPriceAggregatorTx,Ge as buildStellarSetSpokeAssetFlagsTx,Me as buildStellarSetSwapAggregatorTx,ct as buildStellarSupplyBatchTx,dt as buildStellarSupplyTx,Bt as buildStellarSwapCollateralTx,_t as buildStellarSwapDebtTx,Pe as buildStellarTransferOwnershipTx,Oe as buildStellarUnpauseTx,er as buildStellarUpdateAccountThresholdTx,Ke as buildStellarUpdateIndexesTx,Te as buildStellarUpgradeControllerTx,Je as buildStellarUpgradeLiquidityPoolParamsTx,ht as buildStellarWithdrawBatchTx,mt as buildStellarWithdrawTx,ut as buildTx,gs as burnShares,Ss as computeAccountRisk,Sn as decodeStellarLendingEvent,bt as decodeStellarLiquidateReturn,Vn as decodeStellarRouteBytes,Qn as decodeStellarSwapEnvelope,rs as depositRateRay,$o as divByIntHalfUp,qe as encodeAssetOracle,be as encodeInterestRateModel,ve as encodeMarketParamsRaw,Ie as encodePositionLimits,Se as encodePriceKey,Hn as encodeStrategyPayloadToRouteXdr,En as extractEventOrder,Dt as getStellarAccountPositions,ce as getStellarActiveUsersSeries,xn as getStellarAggregatorQuote,Nt as getStellarAsset,Gt as getStellarAssetGraph,zt as getStellarAssetMarkets,Ft as getStellarAssetPage,Tt as getStellarAssets,oe as getStellarCampaignLeaderboard,ge as getStellarCampaignMe,pe as getStellarDefiLlamaDimensions,S as getStellarDeployment,qt as getStellarDetailedMarkets,ae as getStellarFeeRevenueSeries,Qt as getStellarGovernanceProposals,ne as getStellarHolderDistribution,Pt as getStellarHub,Ht as getStellarHubGraph,Xt as getStellarHubHolders,Ut as getStellarHubs,At as getStellarLendingContext,xt as getStellarLendingLiveState,re as getStellarLiquidationsLeaderboard,ue as getStellarLiquidationsSeries,ee as getStellarParticipantCounts,me as getStellarPnlByScope,te as getStellarPositionsLeaderboard,he as getStellarPositionsPnl,qn as getStellarQuoteTokens,de as getStellarRateSpreadSeries,Ct as getStellarReserve,Yt as getStellarReserveGraph,Vt as getStellarReserveHolders,Ot as getStellarReserves,ie as getStellarRevenueSeries,Lt as getStellarSpoke,Kt as getStellarSpokeGraph,jt as getStellarSpokeHolders,$t as getStellarSpokes,se as getStellarStatsHistory,Zt as getStellarUserActivity,Jt as getStellarUserActivityPage,fe as getStellarUserHistory,Mt as getStellarUserPositions,le as getStellarVolumeSeries,Wt as getStellarWalletBalance,cs as liveIndexKey,Yn as mapQuoteResponseToStrategyPayload,Zn as mapQuoteResponseToStrategySwap,Fs as mapSorobanError,kn as mapStellarPositionActivityType,Us as maxBorrow,Cs as maxRepay,Os as maxSupply,$s as maxWithdraw,ms as mintShares,To as mulDivCeil,qo as mulDivFloor,Uo as mulDivHalfUp,Yo as numberToScaled,Zo as numberToWad,Xo as positionValueWad,bo as prepareStellarBuiltTx,wo as prepareStellarTxXdr,Ls as projectAccountRisk,Ds as projectReserveApy,os as rayAprToApy,ns as rayAprToNumber,Ho as rayToNumber,No as rescaleCeil,Co as rescaleFloor,Po as rescaleHalfUp,is as reserveKey,as as resolveReserve,ho as stellarAuthPolicyForInvocation,an as stellarLendingDispatchKey,ye as stellarLendingRead,I as stellarNetworks,Xn as stellarTokenContractId,Rn as syntheticEventOrder,yo as tagStellarInvokedContractError,on as toBase64Xdr,xo as toBigInt,vo as toStellarPositionMode,Do as unscale,Fo as unscaleBorrowCeil,zo as unscaleHalfUp,Wo as unscaleSupplyFloor,ts as utilizationRay,ys as valueBasePosition,hs as valueScaledPosition,Gn as verifyStellarRouteBytes,Go as wadToNumber};export const createStellarLendingReadClient=we.gm;export const lendingAssetsSchema=we.IY;export const lendingPositionsSchema=we.Vd;
|
|
2
|
+
"undefined"!=typeof globalThis&&void 0===globalThis.self&&(globalThis.self=globalThis);import{Account as t,Address as e,Asset as r,BASE_FEE as n,Contract as o,ScInt as s,Soroban as i,StrKey as a,TransactionBuilder as u,rpc as l,scValToBigInt as c,scValToNative as p,xdr as d}from"@stellar/stellar-sdk";var f={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,s=a(t),i=s[0],u=s[1],l=new o(function(t,e,r){return 3*(e+r)/4-r}(0,i,u)),c=0,p=u>0?i-4:i;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,s=[],i=16383,a=0,u=n-o;a<u;a+=i)s.push(l(t,a,a+i>u?u:a+i));return 1===o?(e=t[n-1],s.push(r[e>>2]+r[e<<4&63]+"==")):2===o&&(e=(t[n-2]<<8)+t[n-1],s.push(r[e>>10]+r[e>>4&63]+r[e<<2&63]+"=")),s.join("")};for(var r=[],n=[],o="undefined"!=typeof Uint8Array?Uint8Array:Array,s="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/",i=0;i<64;++i)r[i]=s[i],n[s.charCodeAt(i)]=i;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=[],s=e;s<r;s+=3)n=(t[s]<<16&16711680)+(t[s+1]<<8&65280)+(255&t[s+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),s="function"==typeof Symbol&&"function"==typeof Symbol.for?Symbol.for("nodejs.util.inspect.custom"):null;e.hp=u,e.IS=50;const i=2147483647;function a(t){if(t>i)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 f(e.buffer,e.byteOffset,e.byteLength)}return d(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 f(t,e,r);if("undefined"!=typeof SharedArrayBuffer&&(K(t,SharedArrayBuffer)||t&&K(t.buffer,SharedArrayBuffer)))return f(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||Y(t.length)?a(0):d(t):"Buffer"===t.type&&Array.isArray(t.data)?d(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 d(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 f(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>=i)throw new RangeError("Attempt to allocate Buffer larger than maximum size: 0x"+i.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 q(this,e,r);case"utf8":case"utf-8":return R(this,e,r);case"ascii":return A(this,e,r);case"latin1":case"binary":return x(this,e,r);case"base64":return E(this,e,r);case"ucs2":case"ucs-2":case"utf16le":case"utf-16le":return T(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),Y(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 s,i=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;i=2,a/=2,u/=2,r/=2}function l(t,e){return 1===i?t[e]:t.readUInt16BE(e*i)}if(o){let n=-1;for(s=r;s<a;s++)if(l(t,s)===l(e,-1===n?0:s-n)){if(-1===n&&(n=s),s-n+1===u)return n*i}else-1!==n&&(s-=s-n),n=-1}else for(r+u>a&&(r=a-u),s=r;s>=0;s--){let r=!0;for(let n=0;n<u;n++)if(l(t,s+n)!==l(e,n)){r=!1;break}if(r)return s}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 s=e.length;let i;for(n>s/2&&(n=s/2),i=0;i<n;++i){const n=parseInt(e.substr(2*i,2),16);if(Y(n))return i;t[r+i]=n}return i}function I(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 B(t,e,r,n){return H(function(t,e){let r,n,o;const s=[];for(let i=0;i<t.length&&!((e-=2)<0);++i)r=t.charCodeAt(i),n=r>>8,o=r%256,s.push(o),s.push(n);return s}(e,t.length-r),t,r,n)}function E(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 s=null,i=e>239?4:e>223?3:e>191?2:1;if(o+i<=r){let r,n,a,u;switch(i){case 1:e<128&&(s=e);break;case 2:r=t[o+1],128==(192&r)&&(u=(31&e)<<6|63&r,u>127&&(s=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)&&(s=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&&(s=u))}}null===s?(s=65533,i=1):s>65535&&(s-=65536,n.push(s>>>10&1023|55296),s=56320|1023&s),n.push(s),o+=i}return function(t){const e=t.length;if(e<=k)return String.fromCharCode.apply(String,t);let r="",n=0;for(;n<e;)r+=String.fromCharCode.apply(String,t.slice(n,n+=k));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,s=Math.min(r,n);o<s;++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+">"},s&&(u.prototype[s]=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 s=(o>>>=0)-(n>>>=0),i=(r>>>=0)-(e>>>=0);const a=Math.min(s,i),l=this.slice(n,o),c=t.slice(e,r);for(let t=0;t<a;++t)if(l[t]!==c[t]){s=l[t],i=c[t];break}return s<i?-1:i<s?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 s=!1;for(;;)switch(n){case"hex":return v(this,t,e,r);case"utf8":case"utf-8":return I(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 B(this,t,e,r);default:if(s)throw new TypeError("Unknown encoding: "+n);n=(""+n).toLowerCase(),s=!0}},u.prototype.toJSON=function(){return{type:"Buffer",data:Array.prototype.slice.call(this._arr||this,0)}};const k=4096;function A(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 x(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 q(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+=Z[t[n]];return o}function T(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 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,n,o,s){if(!u.isBuffer(t))throw new TypeError('"buffer" argument must be a Buffer instance');if(e>o||e<s)throw new RangeError('"value" argument is out of bounds');if(r+n>t.length)throw new RangeError("Index out of range")}function O(t,e,r,n,o){F(e,n,o,t,r,7);let s=Number(e&BigInt(4294967295));t[r++]=s,s>>=8,t[r++]=s,s>>=8,t[r++]=s,s>>=8,t[r++]=s;let i=Number(e>>BigInt(32)&BigInt(4294967295));return t[r++]=i,i>>=8,t[r++]=i,i>>=8,t[r++]=i,i>>=8,t[r++]=i,r}function C(t,e,r,n,o){F(e,n,o,t,r,7);let s=Number(e&BigInt(4294967295));t[r+7]=s,s>>=8,t[r+6]=s,s>>=8,t[r+5]=s,s>>=8,t[r+4]=s;let i=Number(e>>BigInt(32)&BigInt(4294967295));return t[r+3]=i,i>>=8,t[r+2]=i,i>>=8,t[r+1]=i,i>>=8,t[r]=i,r+8}function N(t,e,r,n,o,s){if(r+n>t.length)throw new RangeError("Index out of range");if(r<0)throw new RangeError("Index out of range")}function P(t,e,r,n,s){return e=+e,r>>>=0,s||N(t,0,r,4),o.write(t,e,r,n,23,4),r+4}function L(t,e,r,n,s){return e=+e,r>>>=0,s||N(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||U(t,e,this.length);let n=this[t],o=1,s=0;for(;++s<e&&(o*=256);)n+=this[t+s]*o;return n},u.prototype.readUintBE=u.prototype.readUIntBE=function(t,e,r){t>>>=0,e>>>=0,r||U(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||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=J((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 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=J((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 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||U(t,e,this.length);let n=this[t],o=1,s=0;for(;++s<e&&(o*=256);)n+=this[t+s]*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||U(t,e,this.length);let n=e,o=1,s=this[t+--n];for(;n>0&&(o*=256);)s+=this[t+--n]*o;return o*=128,s>=o&&(s-=Math.pow(2,8*e)),s},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=J((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 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=J((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 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||U(t,4,this.length),o.read(this,t,!0,23,4)},u.prototype.readFloatBE=function(t,e){return t>>>=0,e||U(t,4,this.length),o.read(this,t,!1,23,4)},u.prototype.readDoubleLE=function(t,e){return t>>>=0,e||U(t,8,this.length),o.read(this,t,!0,52,8)},u.prototype.readDoubleBE=function(t,e){return t>>>=0,e||U(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,s=0;for(this[e]=255&t;++s<r&&(o*=256);)this[e+s]=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,s=1;for(this[e+o]=255&t;--o>=0&&(s*=256);)this[e+o]=t/s&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=J((function(t,e=0){return O(this,t,e,BigInt(0),BigInt("0xffffffffffffffff"))})),u.prototype.writeBigUInt64BE=J((function(t,e=0){return C(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,s=1,i=0;for(this[e]=255&t;++o<r&&(s*=256);)t<0&&0===i&&0!==this[e+o-1]&&(i=1),this[e+o]=(t/s|0)-i&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,s=1,i=0;for(this[e+o]=255&t;--o>=0&&(s*=256);)t<0&&0===i&&0!==this[e+o+1]&&(i=1),this[e+o]=(t/s|0)-i&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=J((function(t,e=0){return O(this,t,e,-BigInt("0x8000000000000000"),BigInt("0x7fffffffffffffff"))})),u.prototype.writeBigInt64BE=J((function(t,e=0){return C(this,t,e,-BigInt("0x8000000000000000"),BigInt("0x7fffffffffffffff"))})),u.prototype.writeFloatLE=function(t,e,r){return P(this,t,e,!0,r)},u.prototype.writeFloatBE=function(t,e,r){return P(this,t,e,!1,r)},u.prototype.writeDoubleLE=function(t,e,r){return L(this,t,e,!0,r)},u.prototype.writeDoubleBE=function(t,e,r){return L(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 s=u.isBuffer(t)?t:u.from(t,n),i=s.length;if(0===i)throw new TypeError('The value "'+t+'" is invalid for argument "value"');for(o=0;o<r-e;++o)this[o+e]=s[o%i]}return this};const M={};function D(t,e,r){M[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 W(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 F(t,e,r,n,o,s){if(t>r||t<e){const n="bigint"==typeof e?"n":"";let o;throw o=s>3?0===e||e===BigInt(0)?`>= 0${n} and < 2${n} ** ${8*(s+1)}${n}`:`>= -(2${n} ** ${8*(s+1)-1}${n}) and < 2 ** ${8*(s+1)-1}${n}`:`>= ${e}${n} and <= ${r}${n}`,new M.ERR_OUT_OF_RANGE("value",o,t)}!function(t,e,r){z(e,"offset"),void 0!==t[e]&&void 0!==t[e+r]||V(e,t.length-(r+1))}(n,o,s)}function z(t,e){if("number"!=typeof t)throw new M.ERR_INVALID_ARG_TYPE(e,"number",t)}function V(t,e,r){if(Math.floor(t)!==t)throw z(t,r),new M.ERR_OUT_OF_RANGE(r||"offset","an integer",t);if(e<0)throw new M.ERR_BUFFER_OUT_OF_BOUNDS;throw new M.ERR_OUT_OF_RANGE(r||"offset",`>= ${r?1:0} and <= ${e}`,t)}D("ERR_BUFFER_OUT_OF_BOUNDS",(function(t){return t?`${t} is outside of buffer bounds`:"Attempt to access memory outside buffer bounds"}),RangeError),D("ERR_INVALID_ARG_TYPE",(function(t,e){return`The "${t}" argument must be of type number. Received type ${typeof e}`}),TypeError),D("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=W(String(r)):"bigint"==typeof r&&(o=String(r),(r>BigInt(2)**BigInt(32)||r<-(BigInt(2)**BigInt(32)))&&(o=W(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 s=[];for(let i=0;i<n;++i){if(r=t.charCodeAt(i),r>55295&&r<57344){if(!o){if(r>56319){(e-=3)>-1&&s.push(239,191,189);continue}if(i+1===n){(e-=3)>-1&&s.push(239,191,189);continue}o=r;continue}if(r<56320){(e-=3)>-1&&s.push(239,191,189),o=r;continue}r=65536+(o-55296<<10|r-56320)}else o&&(e-=3)>-1&&s.push(239,191,189);if(o=null,r<128){if((e-=1)<0)break;s.push(r)}else if(r<2048){if((e-=2)<0)break;s.push(r>>6|192,63&r|128)}else if(r<65536){if((e-=3)<0)break;s.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;s.push(r>>18|240,r>>12&63|128,r>>6&63|128,63&r|128)}}return s}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 Y(t){return t!=t}const Z=function(){const t="0123456789abcdef",e=new Array(256);for(let r=0;r<16;++r){const n=16*r;for(let o=0;o<16;++o)e[n+o]=t[r]+t[o]}return e}();function J(t){return"undefined"==typeof BigInt?Q:t}function Q(){throw new Error("BigInt not supported")}},251(t,e){e.read=function(t,e,r,n,o){var s,i,a=8*o-n-1,u=(1<<a)-1,l=u>>1,c=-7,p=r?o-1:0,d=r?-1:1,f=t[e+p];for(p+=d,s=f&(1<<-c)-1,f>>=-c,c+=a;c>0;s=256*s+t[e+p],p+=d,c-=8);for(i=s&(1<<-c)-1,s>>=-c,c+=n;c>0;i=256*i+t[e+p],p+=d,c-=8);if(0===s)s=1-l;else{if(s===u)return i?NaN:1/0*(f?-1:1);i+=Math.pow(2,n),s-=l}return(f?-1:1)*i*Math.pow(2,s-n)},e.write=function(t,e,r,n,o,s){var i,a,u,l=8*s-o-1,c=(1<<l)-1,p=c>>1,d=23===o?Math.pow(2,-24)-Math.pow(2,-77):0,f=n?0:s-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,i=c):(i=Math.floor(Math.log(e)/Math.LN2),e*(u=Math.pow(2,-i))<1&&(i--,u*=2),(e+=i+p>=1?d/u:d*Math.pow(2,1-p))*u>=2&&(i++,u/=2),i+p>=c?(a=0,i=c):i+p>=1?(a=(e*u-1)*Math.pow(2,o),i+=p):(a=e*Math.pow(2,p-1)*Math.pow(2,o),i=0));o>=8;t[r+f]=255&a,f+=h,a/=256,o-=8);for(i=i<<o|a,l+=o;l>0;t[r+f]=255&i,f+=h,i/=256,l-=8);t[r+f-h]|=128*m}},468(t,e,r){r.d(e,{gm:()=>b,IY:()=>y,Vd:()=>g});const n={type:"string"},o={type:"number"},s={type:"boolean"},i={...n,nullable:!0},a={...o,nullable:!0},u={...n,enum:["mainnet","testnet"]},l={...n,enum:["ready","stale","incomplete"]};function c(t){return{type:"object",required:Object.keys(t),properties:t}}const p={sac:n,symbol:n,name:n,decimals:a,logoUrl:i},d=c({valid:s,stale:s,deviation:s,timestamp:a}),f=c({...p,hubId:o,hubName:n,amountRaw:{...i,description:"Integer token base units, never scaled shares."},amount:i,apy:{...a,description:"Fraction: 0.05 means 5%."},priceUsd:a,valueUsd:a,priceStatus:d,indexRay:i,indexedAt:o,indexedLedger:o}),h=c({amountRaw:i,amount:i,usd:a}),m=c({spokeId:o,spokeName:n,ltvBps:o,supplyCapacity:h,borrowCapacity:h,canSupply:s,canBeCollateral:s,canBorrow:s,canOpenAccount:{...s,description:"Spoke admits new accounts; other entry gates still apply."}}),g={type:"array",items:c({accountId:n,nftContract:n,nftImage:{...n,format:"uri",description:"Dynamic position SVG served by the network's XOXNO API."},network:u,spokeId:a,spokeName:i,supplied:{type:"array",items:f},borrow:{type:"array",items:f},hasDebt:{...s,nullable:!0,description:"Null when account rows are unavailable."},healthFactor:{...a,description:"Null without debt or when risk inputs are unavailable."},borrowLimitUsd:a,availableBorrowUsd:{...a,description:"Account headroom, before per-market constraints."},netApy:{...a,description:"Net annual yield divided by positive net equity; fraction."},dataStatus:l})},y={type:"array",items:c({...p,hubId:o,hubName:n,network:u,supplyApy:{...a,description:"Fraction: 0.05 means 5%."},borrowApy:{...a,description:"Fraction: 0.05 means 5%."},priceUsd:a,priceStatus:d,spokes:{type:"array",items:m},dataStatus:l,indexedAt:{...o,description:"Pool state timestamp. Capacities are indexed snapshot estimates; prepare/simulate before signing."},indexedLedger:o})};function w(t){if(!t)return;const e=/\s*<([^<>\s]+)>\s*((?:;\s*[\w!#$%&'*+.^`|~-]+\s*=\s*(?:"(?:[^"\\\r\n]|\\.)*"|[\w!#$%&'*+.^`|~:/-]+)\s*)*)(,|$)/gy;let r,n=0;for(;n<t.length;){const o=e.exec(t);if(!o||o[3]&&e.lastIndex===t.length)throw new Error("Invalid pagination Link header");let s=!1,i=!1;for(const t of o[2].matchAll(/;\s*([\w!#$%&'*+.^`|~-]+)\s*=\s*(?:"((?:[^"\\\r\n]|\\.)*)"|([\w!#$%&'*+.^`|~:/-]+))\s*/g))if("rel"===t[1].toLowerCase()){if(i)throw new Error("Duplicate pagination link relation");i=!0,s=(t[2]??t[3]).replace(/\\(.)/g,"$1").toLowerCase().split(/\s+/).includes("next")}if(s){if(void 0!==r)throw new Error("Multiple next pagination links");r=o[1]}n=e.lastIndex}return r}function b(t){const e=new URL(t.baseUrl.trim());if(!["https:","http:"].includes(e.protocol)||e.username||e.password||e.search||e.hash)throw new Error("baseUrl must be an HTTP API root without credentials, query or fragment");e.pathname=`${e.pathname.replace(/\/+$/,"")}/`;const r=t.fetch??globalThis.fetch?.bind(globalThis);if(!r)throw new Error("A fetch implementation is required");async function n(t,n){const o=new URL(`stellar-lending/v1/${t}`,e);let s=o;const i=new Set,a=[];for(;;){if(i.has(s.href))throw new Error("Pagination Link cycle");i.add(s.href);const t=await r(s.href,{signal:n,redirect:"error"});if(t.redirected||t.url&&new URL(t.url).href!==s.href)throw new Error("Stellar lending redirects are not allowed");if(!t.ok)throw new Error(`Stellar lending request failed: HTTP ${t.status}`);const e=await t.json();if(!Array.isArray(e))throw new Error("Stellar lending response must be an array");a.push(...e);const u=w(t.headers.get("Link"));if(!u)break;const l=new URL(u,s);if(l.origin!==o.origin||l.pathname!==o.pathname||l.username||l.password||l.hash)throw new Error("Pagination Link must stay on the same API endpoint");s=l}return a}return{assets:({usage:t,signal:e}={})=>{if(void 0!==t&&"collateral"!==t&&"borrow"!==t)throw new Error("usage must be collateral or borrow");return n("assets"+(t?`?usage=${t}`:""),e)},positions:(t,{signal:e}={})=>{if(!t.trim()||"."===t||".."===t)throw new Error("owner is required");return n(`users/${encodeURIComponent(t)}/positions`,e)}}}}},h={};function m(t){var e=h[t];if(void 0!==e)return e.exports;var r=h[t]={exports:{}};return f[t](r,r.exports,m),r.exports}m.d=(t,e)=>{for(var r in e)m.o(e,r)&&!m.o(t,r)&&Object.defineProperty(t,r,{enumerable:!0,get:e[r]})},m.o=(t,e)=>Object.prototype.hasOwnProperty.call(t,e);const g="erd1qqqqqqqqqqqqqpgq705fxpfrjne0tl3ece0rrspykq88mynn4kxs2cg43s",y="erd1qqqqqqqqqqqqqpgqd9rvv2n378e27jcts8vfwynpx0gfl5ufz6hqhfy0u0",w="erd1qqqqqqqqqqqqqpgq8xwzu82v8ex3h4ayl5lsvxqxnhecpwyvwe0sf2qj4e";var b;!function(t){t.MAINNET="1",t.DEVNET="D"}(b||(b={}));class v{apiUrl;chain;init;config;constructor(t){if(!t?.apiUrl?.trim())throw new Error("XOXNOClient: apiUrl is required");const{chain:e=b.MAINNET,apiUrl:r,...n}=t;this.apiUrl=r.trim().replace(/\/$/,""),this.chain=e,this.init=n,this.config=e==b.MAINNET?{mediaUrl:"https://media.xoxno.com",gatewayUrl:"https://gateway.xoxno.com",XO_SC:"erd1qqqqqqqqqqqqqpgq6wegs2xkypfpync8mn2sa5cmpqjlvrhwz5nqgepyg8",FM_SC:g,DR_SC:y,KG_SC:w,Staking_SC:"erd1qqqqqqqqqqqqqpgqvpkd3g3uwludduv3797j54qt6c888wa59w2shntt6z",Manager_SC:"erd1qqqqqqqqqqqqqpgqg9fa0dmpn8fu3fnleeqn5zt8rl8mdqjkys5s2gtas7",P2P_SC:"erd1qqqqqqqqqqqqqpgq47y8hnct68v6asjv6gxem6h9rumn9frzah0skhxxt6"}:{mediaUrl:"https://devnet-media.xoxno.com",gatewayUrl:"https://devnet-gateway.xoxno.com",XO_SC:"erd1qqqqqqqqqqqqqpgql0dnz6n5hpuw8cptlt00khd0nn4ja8eadsfq2xrqw4",FM_SC:g,DR_SC:y,KG_SC:w,Staking_SC:"erd1qqqqqqqqqqqqqpgqsc5hnewwpep8qq0d7kjjzrquapuucrygah0s85zres",Manager_SC:"erd1qqqqqqqqqqqqqpgqluclyhfsa2uw7q9cjwd8knk989hg57u8ah0slq2nlr",P2P_SC:"erd1qqqqqqqqqqqqqpgqfja7ukpngrun78ueq583l0vd6aj4ekhrah0sa9wyrv"}}fetchWithTimeout=async(t,{params:e,...r}={})=>{const{next:n,cache:o,debug:s,timeout:i,...a}=this.init,{next:u,cache:l,debug:c,timeout:p,headers:d,method:f="GET",...h}=r,m=d?.Authorization,g="Bearer undefined"===m?void 0:m,y="GET"!==f&&"HEAD"!==f&&"PUT"!==f,w={...d,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:I,...S}=n??{},{revalidate:_,...B}=u??{},E="GET"!==f||g?void 0:_??I,R="GET"!==f||g||E?void 0:l??o,k=h.body,A=p??i??(null==k?3e4:0),x=A>0?AbortSignal.timeout(A):void 0,q=h.signal??a.signal,T=x&&q?AbortSignal.any([q,x]):x??q,U={...a,...h,method:f,...Object.keys(w).length?{headers:w}:{},...T?{signal:T}:{},cache:R,next:{...S,...B,revalidate:E}};(c??s)&&console.debug("SDK fetch: ",v,U);const $=await fetch(v,U).catch((t=>{if(t instanceof Error&&!t.message.match(/^http(s?):\/\//))throw Object.assign(new Error(`${v}: ${t.message}`),{cause:t});throw t})),O=await $.text();if(!$.ok){let t;try{t=JSON.parse(O)}catch{t={message:O}}const e=[v,$.status,$.statusText,t.message].filter(Boolean).join(";;");throw new Error(e)}try{return JSON.parse(O)}catch{return O}}}const I={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",lendingPool:"CBXRNDQMAJFG4VUKMKFEMFS75UUXE2SPSNV4LEEFCSNBCN66PYRWBKXO",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",lendingPool:"CBSGF6QOQAMPFBEVSYPEQHSZRIHJ6RCGUPCRDMUX36DEKRWFAO2PZB5A",aggregatorRouter:"CDNTWMWW2WGYTKIZTJYNGNVQQZI4KTC5BQRZ3275KESRX5T4O3AYECL5",governance:"CDS33JDOYH3F3FL4QUQ6DV4WKHML2AKHF4LADTZ57FRUAEBTE7NMY5FQ",priceAggregator:"CAALOOTIDXCX7D7FMQIBSSAJLPKOM3GMXS4UUSTDIG42JCRRJHOPUHOP",positionNftContract:"CDVN5JU675MEDPVRPCYC45AHFC275UH57WEU5OTFE4WFGZBNN7HTLPSY"}},S=I;function _(t){return I["testnet"===t?"stellarTestnet":"stellarMainnet"]}const B={mainnet:I.stellarMainnet.passphrase,testnet:I.stellarTestnet.passphrase};var E=m(287);const R=["Soroswap","Aquarius","Phoenix","Sushi","CometDex"],k={Soroswap:0,Aquarius:1,Phoenix:2,Sushi:3,CometDex:4},A=1,x=1e6,q=5,T=6,U=0,$=1,O=2,C=128,N=48,P=32,L=256,M=C-O,D=t=>new e(t).toScVal(),W=t=>new s(t).toI128(),F=t=>d.ScVal.scvU32(t),z=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 s("string"==typeof t?t:t.toString()).toU64()},V=t=>d.ScVal.scvBool(t),X=t=>d.ScVal.scvString(t),j=t=>d.ScVal.scvSymbol(t),G=()=>d.ScVal.scvVoid(),H=t=>d.ScVal.scvVec(t),K=(t,e=32)=>{const r=t.startsWith("0x")?t.slice(2):t,n=E.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 d.ScVal.scvBytes(n)},Y=(t,e)=>null==t?G():e(t),Z=(t,e)=>et({asset:D(e),hub_id:F(t)}),J=(t,e,r)=>d.ScVal.scvVec([Z(t,e),W(r)]),Q=t=>d.ScVal.scvVec(t.map((t=>J(t.hubId,t.asset,t.amount)))),tt=t=>{if("Transfer"===t)return H([j("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 H([j("Credit"),z(e)])}throw new Error(`Stellar builder: SeizeMode must be 'Transfer' or { Credit: accountId }, got ${JSON.stringify(t)}`)},et=t=>{const e=Object.keys(t).sort().map((e=>new d.ScMapEntry({key:j(e),val:t[e]})));return d.ScVal.scvMap(e)};class rt{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>=L)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>=M)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>=P)throw new Error("Stellar builder: strategy uses more than 32 split weights");if(!Number.isInteger(t)||t<=0||t>x)throw new Error(`Stellar builder: split weight ${t} outside 1..=${x}`);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(k[r.venue],0===n?e:$,this.asset(r.pool),this.asset(r.tokenIn),this.asset(r.tokenOut))}))}lowerPaths(t){const e=t.filter((t=>t.hops.length>0)),r=Array.from({length:e.length},(()=>!1));for(let t=0;t<e.length;t+=1){if(r[t])continue;const n=e[t].hops[0]?.tokenIn,o=[];for(let r=t;r<e.length;r+=1)e[r].hops[0]?.tokenIn===n&&o.push(r);const s=o.reduce(((t,r)=>t+e[r].splitPpm),0);if(s>x)throw new Error(`Stellar builder: split weights for one token sum to ${s}, above ${x}`);const i=s===x;let a=x;o.forEach(((t,n)=>{r[t]=!0;const s=e[t];let u;if(n+1===o.length&&i)u=U;else{if(0===a)throw new Error("Stellar builder: split weights exhaust the group before its last path");const t=Math.floor(s.splitPpm*x/a);a-=Math.min(s.splitPpm,a),u=C+this.weight(t)}this.emitPath(s,u)}))}}toBytes(t,e,r){if(0===this.ops.length)throw new Error("Stellar builder: strategy lowered to zero instructions");if(this.ops.length>N)throw new Error(`Stellar builder: strategy has ${this.ops.length} instructions, the router accepts ${N}`);const n=[A,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 E.hp.from(n)}get assetList(){return this.assets}get amountList(){return this.amounts}}const nt=t=>{const e=new rt(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(q,U,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,s]=n,[i,a]=t.preSwapFromA?[o,s]:[s,o];e.emit(k.Aquarius,O+e.amount(r),e.asset(t.mintPool),e.asset(i),e.asset(a))}e.emit(T,U,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 et({amounts:d.ScVal.scvVec(e.amountList.map((t=>W(t)))),assets:d.ScVal.scvVec(e.assetList.map((t=>D(t)))),ops:d.ScVal.scvBytes(e.toBytes(r,n,o))})},ot=t=>{const e=E.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 d.ScVal.scvBytes(e)},st=()=>d.ScVal.scvBytes(E.hp.alloc(0)),it=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 E.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=E.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},at=t=>{if("string"==typeof t)return ot(it(t));if(t instanceof Uint8Array)return 0===t.length?st():ot(t);if(t&&"object"==typeof t)return"routeXdr"in(r=t)&&"string"==typeof r.routeXdr?ot(it(t.routeXdr)):(t=>"swapXdr"in t&&"string"==typeof t.swapXdr)(t)?ot(it(t.swapXdr)):(t=>"bytes"in t&&("string"==typeof t.bytes||t.bytes instanceof Uint8Array))(t)?"string"==typeof t.bytes?ot(it(t.bytes)):0===t.bytes.length?st():ot(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||!R.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>x)throw new Error(`Stellar builder: \`steps.paths[].splitPpm\` for ${t} sums to ${n}, above ${x}`);if(!e.mintPool&&n!==x)throw new Error(`Stellar builder: \`steps.paths[].splitPpm\` for ${t} must sum to ${x}, got ${n}`)}return e})(t),d.ScVal.scvBytes(E.hp.from(nt(e).toXDR("base64"),"base64")));var e,r;throw new Error("Stellar builder: `steps` must be opaque strategy bytes (`routeXdr`, base64/hex string, or Uint8Array)")},ut=t=>{if("string"==typeof t)return(t=>{const e=t.startsWith("0x")?t.slice(2):t,r=E.hp.from(e,"hex");return d.ScVal.scvBytes(r)})(t);if(t instanceof Uint8Array)return d.ScVal.scvBytes(E.hp.from(t));throw new Error("Stellar builder: `data` must be a hex string or Uint8Array (Soroban Bytes payload)")};function lt(t,e){if("number"!=typeof e||!Number.isInteger(e)||e<0||e>18)throw new Error("Token decimals must be an integer from 0 to 18");if("string"!=typeof t||!/^\d+(?:\.\d+)?$/.test(t))throw new Error("Token amount must be plain decimal text");const r=i.parseTokenAmount(t,e),n=BigInt(r);if(n<=0n||n>(1n<<127n)-1n)throw new Error("Token amount must be within the positive i128 range");return r}function ct(e,r,s){if(!e.controllerAddress)throw new Error("Stellar lending controllerAddress is required");const i=new o(e.controllerAddress),a=new t(e.caller,e.sourceSequence);return{xdr:new u(a,{fee:e.fee??n,networkPassphrase:B[e.network]}).addOperation(i.call(r,...s)).setTimeout(e.timeoutSeconds??300).build().toXDR()}}function pt(t){if(!Number.isInteger(t)||t<1||t>4294967295)throw new Error("Stellar builder: spokeId must be an integer from 1 to 4294967295");return F(t)}function dt(t,e){const r=e.accountNonce??0;return ct(t,"supply",[D(t.caller),z(r),pt(e.spokeId),Q([...e.assets])])}function ft(t,e){return dt(t,{accountNonce:e.accountNonce,spokeId:e.spokeId,assets:[{hubId:e.hubId,asset:e.asset,amount:e.amount}]})}function ht(t,e){return ct(t,"borrow",[D(t.caller),z(e.accountNonce),Q([...e.borrows]),Y(e.to,D)])}function mt(t,e){return ht(t,{accountNonce:e.accountNonce,borrows:[{hubId:e.hubId,asset:e.asset,amount:e.amount}],to:e.to})}function gt(t,e){return ct(t,"withdraw",[D(t.caller),z(e.accountNonce),Q([...e.withdrawals]),Y(e.to,D)])}function yt(t,e){return gt(t,{accountNonce:e.accountNonce,withdrawals:[{hubId:e.hubId,asset:e.asset,amount:e.amount}],to:e.to})}function wt(t,e){return ct(t,"repay",[D(t.caller),z(e.accountNonce),Q([...e.payments])])}function bt(t,e){return wt(t,{accountNonce:e.accountNonce,payments:[{hubId:e.hubId,asset:e.asset,amount:e.amount}]})}function vt(t,e){return ct(t,"liquidate",[D(t.caller),z(e.accountNonce),Q([...e.debtPayments]),tt(e.seizeMode??"Transfer")])}function It(t){const e=p(d.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 St(t,e){return ct(t,"flash_loan",[D(t.caller),Z(e.hubId,e.asset),W(e.amount),D(e.receiver),ut(e.data)])}function _t(t,e){return ct(t,"migrate_from_blend",[D(t.caller),z(e.accountId),pt(e.spokeId),F(e.hubId),D(e.blendPool),H(e.collateralTokens.map(D)),H(e.supplyTokens.map(D)),(r=e.debtCaps.map((t=>({token:t.token,amount:t.cap}))),d.ScVal.scvVec(r.map((t=>{return e=t.token,r=t.amount,d.ScVal.scvVec([D(e),W(r)]);var e,r}))))]);var r}function Bt(t,e){const r=e.accountNonce??0;return ct(t,"multiply",[D(t.caller),z(r),pt(e.spokeId),Z(e.collateral.hubId,e.collateral.asset),W(e.debtToFlashLoan),Z(e.debt.hubId,e.debt.asset),F(e.mode),at(e.steps),Y(e.initialPayment,(t=>J(t.hubId,t.asset,t.amount))),Y(e.convertSwap,at)])}function Et(t,e){return ct(t,"swap_debt",[D(t.caller),z(e.accountNonce),Z(e.existingDebt.hubId,e.existingDebt.asset),W(e.newDebtAmount),Z(e.newDebt.hubId,e.newDebt.asset),at(e.steps)])}function Rt(t,e){return ct(t,"swap_collateral",[D(t.caller),z(e.accountNonce),Z(e.current.hubId,e.current.asset),W(e.fromAmount),Z(e.newCollateral.hubId,e.newCollateral.asset),at(e.steps)])}function kt(t,e){return ct(t,"repay_debt_with_collateral",[D(t.caller),z(e.accountNonce),Z(e.collateral.hubId,e.collateral.asset),W(e.collateralAmount),Z(e.debt.hubId,e.debt.asset),at(e.steps),V(e.closePosition)])}const At="/stellar-lending",xt=encodeURIComponent,qt=(t,e)=>t.fetchWithTimeout(`${At}/context`,e),Tt=(t,e)=>t.fetchWithTimeout(`${At}/live-state`,e),Ut=(t,e)=>t.fetchWithTimeout(`${At}/markets/detailed`,e),$t=(t,e)=>t.fetchWithTimeout(`${At}/assets`,e),Ot=(t,e)=>t.fetchWithTimeout(`${At}/hubs`,e),Ct=(t,e)=>t.fetchWithTimeout(`${At}/spokes`,e),Nt=(t,e={},r)=>t.fetchWithTimeout(`${At}/reserves`,{...r,params:{...e}}),Pt=(t,e,r,n,o)=>t.fetchWithTimeout(`${At}/reserves/${e}/${r}/${xt(n)}`,o),Lt=(t,e,r)=>t.fetchWithTimeout(`${At}/assets/${xt(e)}`,r),Mt=(t,e,r)=>t.fetchWithTimeout(`${At}/hubs/${e}`,r),Dt=(t,e,r)=>t.fetchWithTimeout(`${At}/spokes/${e}`,r),Wt=(t,e,r)=>t.fetchWithTimeout(`${At}/users/${xt(e)}/positions`,r),Ft=(t,e,r)=>t.fetchWithTimeout(`${At}/accounts/${xt(e)}/positions`,r),zt=(t,e,r,n)=>t.fetchWithTimeout(`${At}/users/${xt(e)}/assets/${xt(r)}/balance`,n),Vt=(t,e,r,n)=>t.fetchWithTimeout(`${At}/assets/${xt(e)}/page`,{...n,params:{...r}}),Xt=(t,e,r,n)=>t.fetchWithTimeout(`${At}/assets/${xt(e)}/markets`,{...n,params:{side:r}}),jt=(t,e,r,n,o,s)=>t.fetchWithTimeout(`${At}/reserves/${e}/${r}/${xt(n)}/holders`,{...s,params:{side:o}}),Gt=(t,e,r,n)=>t.fetchWithTimeout(`${At}/hubs/${e}/holders`,{...n,params:{side:r}}),Ht=(t,e,r,n)=>t.fetchWithTimeout(`${At}/spokes/${e}/holders`,{...n,params:{side:r}}),Kt=(t,e,r,n)=>t.fetchWithTimeout(`${At}/assets/${xt(e)}/graph`,{...n,params:{...r}}),Yt=(t,e,r,n)=>t.fetchWithTimeout(`${At}/hubs/${e}/graph`,{...n,params:{...r}}),Zt=(t,e,r,n)=>t.fetchWithTimeout(`${At}/spokes/${e}/graph`,{...n,params:{...r}}),Jt=(t,e,r,n,o,s)=>t.fetchWithTimeout(`${At}/reserves/${e}/${r}/${xt(n)}/graph`,{...s,params:{...o}}),Qt=(t,e,r={},n)=>t.fetchWithTimeout(`${At}/users/${xt(e)}/activity`,{...n,params:{...r}}),te=(t,e,r={},n)=>t.fetchWithTimeout(`${At}/users/${xt(e)}/activity/page`,{...n,params:{...r}}),ee=(t,e={},r)=>t.fetchWithTimeout(`${At}/governance/proposals`,{...r,params:{...e}}),re=(t,e={},r)=>t.fetchWithTimeout(`${At}/positions`,{...r,params:{...e}}),ne=(t,e={},r)=>t.fetchWithTimeout(`${At}/participants`,{...r,params:{...e}}),oe=(t,e={},r)=>t.fetchWithTimeout(`${At}/liquidations/leaderboard`,{...r,params:{...e}}),se=(t,e={},r)=>t.fetchWithTimeout(`${At}/distribution`,{...r,params:{...e}}),ie=(t,e={},r)=>t.fetchWithTimeout(`${At}/campaign/leaderboard`,{...r,params:{...e}}),ae=(t,e,r)=>t.fetchWithTimeout(`${At}/stats/history`,{...r,params:{...e}}),ue=(t,e,r)=>t.fetchWithTimeout(`${At}/revenue`,{...r,params:{...e}}),le=(t,e,r)=>t.fetchWithTimeout(`${At}/revenue/fees`,{...r,params:{...e}}),ce=(t,e,r)=>t.fetchWithTimeout(`${At}/liquidations`,{...r,params:{...e}}),pe=(t,e,r)=>t.fetchWithTimeout(`${At}/volume`,{...r,params:{...e}}),de=(t,e,r)=>t.fetchWithTimeout(`${At}/active-users`,{...r,params:{...e}}),fe=(t,e,r)=>t.fetchWithTimeout(`${At}/rate-spread`,{...r,params:{...e}}),he=(t,e,r)=>t.fetchWithTimeout(`${At}/defillama`,{...r,params:{...e}}),me=(t,e,r,n)=>t.fetchWithTimeout(`${At}/users/${xt(e)}/history`,{...n,params:{...r}}),ge=(t,e,r)=>t.fetchWithTimeout(`${At}/pnl`,{...r,params:{accountId:e}}),ye=(t,e,r)=>t.fetchWithTimeout(`${At}/pnl/scope`,{...r,params:{scope:e}}),we=(t,e,r)=>t.fetchWithTimeout(`${At}/campaign/me`,{...r,params:{owner:e}}),be=t=>({context:e=>qt(t,e),liveState:e=>Tt(t,e),marketsDetailed:e=>Ut(t,e),assets:e=>$t(t,e),hubs:e=>Ot(t,e),spokes:e=>Ct(t,e),reserves:(e={},r)=>void 0!==r||"hubId"in e||"spokeId"in e||"asset"in e?Nt(t,e,r):Nt(t,{},e),reserve:(e,r,n,o)=>Pt(t,e,r,n,o),asset:(e,r)=>Lt(t,e,r),hub:(e,r)=>Mt(t,e,r),spoke:(e,r)=>Dt(t,e,r),userPositions:(e,r)=>Wt(t,e,r),accountPositions:(e,r)=>Ft(t,e,r),walletBalance:(e,r,n)=>zt(t,e,r,n),assetPage:(e,r,n)=>Vt(t,e,r,n),assetMarkets:(e,r,n)=>Xt(t,e,r,n),reserveHolders:(e,r,n,o,s)=>jt(t,e,r,n,o,s),hubHolders:(e,r,n)=>Gt(t,e,r,n),spokeHolders:(e,r,n)=>Ht(t,e,r,n),assetGraph:(e,r,n)=>Kt(t,e,r,n),hubGraph:(e,r,n)=>Yt(t,e,r,n),spokeGraph:(e,r,n)=>Zt(t,e,r,n),reserveGraph:(e,r,n,o,s)=>Jt(t,e,r,n,o,s),userActivity:(e,r={},n)=>Qt(t,e,r,n),userActivityPage:(e,r={},n)=>te(t,e,r,n),governanceProposals:(e={},r)=>ee(t,e,r),positionsLeaderboard:(e={},r)=>re(t,e,r),participants:(e={},r)=>ne(t,e,r),liquidationsLeaderboard:(e={},r)=>oe(t,e,r),distribution:(e={},r)=>se(t,e,r),campaignLeaderboard:(e={},r)=>ie(t,e,r),statsHistory:(e,r)=>ae(t,e,r),revenue:(e,r)=>ue(t,e,r),feeRevenue:(e,r)=>le(t,e,r),liquidations:(e,r)=>ce(t,e,r),volume:(e,r)=>pe(t,e,r),activeUsers:(e,r)=>de(t,e,r),rateSpread:(e,r)=>fe(t,e,r),defillama:(e,r)=>he(t,e,r),userHistory:(e,r,n)=>me(t,e,r,n),positionsPnl:(e,r)=>ge(t,e,r),pnlByScope:(e,r)=>ye(t,e,r),campaignMe:(e,r)=>we(t,e,r)});var ve=m(468);const Ie=t=>et({base_borrow_rate:W(t.baseBorrowRateRay),max_borrow_rate:W(t.maxBorrowRateRay),max_utilization:W(t.maxUtilizationRay),mid_utilization:W(t.midUtilizationRay),optimal_utilization:W(t.optimalUtilizationRay),reserve_factor:F(t.reserveFactorBps),slope1:W(t.slope1Ray),slope2:W(t.slope2Ray),slope3:W(t.slope3Ray)}),Se=t=>et({asset_decimals:F(t.assetDecimals),asset_id:D(t.assetId),base_borrow_rate:W(t.baseBorrowRateRay),flashloan_fee:F(t.flashloanFeeBps),is_flashloanable:V(t.isFlashloanable),max_borrow_rate:W(t.maxBorrowRateRay),max_utilization:W(t.maxUtilizationRay),mid_utilization:W(t.midUtilizationRay),optimal_utilization:W(t.optimalUtilizationRay),reserve_factor:F(t.reserveFactorBps),slope1:W(t.slope1Ray),slope2:W(t.slope2Ray),slope3:W(t.slope3Ray)}),_e=t=>et({max_borrow_positions:F(t.maxBorrowPositions),max_supply_positions:F(t.maxSupplyPositions)}),Be=t=>{if("Token"in t&&t.Token)return H([j("Token"),D(t.Token)]);if("Ref"in t&&t.Ref)return H([j("Ref"),j(t.Ref)]);throw new Error(`Stellar builder: PriceKey must be { Token } or { Ref }, got ${JSON.stringify(t)}`)},Ee=t=>{if("Stellar"in t)return H([j("Stellar"),D(t.Stellar)]);if("Symbol"in t)return H([j("Symbol"),j(t.Symbol)]);if("String"in t)return H([j("String"),X(t.String)]);throw new Error(`Stellar builder: unknown OracleAssetRef ${JSON.stringify(t)}`)},Re=t=>{if("Spot"===t)return H([j("Spot")]);if(t&&"object"==typeof t&&"Twap"in t)return H([j("Twap"),F(Number(t.Twap))]);throw new Error(`Stellar builder: unknown OracleReadMode ${JSON.stringify(t)}`)},ke=t=>{if("Reflector"===t||"RedStone"===t||"Xoxno"===t)return H([j(t)]);throw new Error(`Stellar builder: unknown ProviderKind "${t}"`)},Ae=t=>{if("Market"===t||"Fundamental"===t)return H([j(t)]);throw new Error(`Stellar builder: unknown FeedNature "${t}"`)},xe=t=>{if("Reflector"in t){const e=t.Reflector;return H([j("Reflector"),et({asset:Ee(e.asset),contract:D(e.contract),read_mode:Re(e.readMode)})])}if("MultiFeed"in t){const e=t.MultiFeed;return H([j("MultiFeed"),et({contract:D(e.contract),feed_id:X(e.feedId),kind:ke(e.kind),nature:Ae(e.nature)})])}throw new Error(`Stellar builder: unknown ProviderRef ${JSON.stringify(t)}`)},qe=t=>{const e=t;return et({decimals:F(e.decimals),max_stale_seconds:z(e.maxStaleSeconds),provider:xe(e.provider)})},Te=t=>{if("RequireDisjoint"===t)return H([j("RequireDisjoint")]);if(t&&"object"==typeof t&&"AllowShared"in t){const e=t.AllowShared;return H([j("AllowShared"),H(e.map((t=>et({contract:D(t.contract),kind:ke(t.kind)}))))])}throw new Error(`Stellar builder: unknown IndependencePolicy ${JSON.stringify(t)}`)},Ue=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 et({asset_decimals:F(Number(e.assetDecimals)),independence:Te(e.independence),max_price_stale_seconds:z(Number(e.maxPriceStaleSeconds)),max_sanity_price_wad:W(String(e.maxSanityPriceWad)),min_sanity_price_wad:W(String(e.minSanityPriceWad)),sources:H(r.map((t=>(t=>{if("Feed"in t)return H([j("Feed"),qe(t.Feed)]);if("Scaled"in t){const e=t.Scaled;return H([j("Scaled"),et({factor:qe(e.factor),max_factor_wad:W(e.maxFactorWad),min_factor_wad:W(e.minFactorWad),quote:Be(e.quote)})])}if("LpShare"in t){const e=t.LpShare;return H([j("LpShare"),et({key_a:Be(e.keyA),key_b:Be(e.keyB),kind:H([j(e.kind||"ConstantProduct")]),pool:D(e.pool),reserve_a_decimals:F(e.reserveADecimals),reserve_b_decimals:F(e.reserveBDecimals),share_decimals:F(e.shareDecimals)})])}throw new Error(`Stellar builder: unknown PriceSource ${JSON.stringify(t)}`)})(t)))),tolerance:et({lower_ratio_bps:F(o),upper_ratio_bps:F(n)})})};function $e(t,e){return ct(t,"upgrade",[K(e.wasmHash)])}function Oe(t,e){return ct(t,"migrate",[F(e.newVersion)])}function Ce(t){return ct(t,"pause",[])}function Ne(t){return ct(t,"unpause",[])}function Pe(t,e){return ct(t,"grant_role",[D(e.account),j(e.role)])}function Le(t,e){return ct(t,"revoke_role",[D(e.account),j(e.role)])}function Me(t,e){return ct(t,"transfer_ownership",[D(e.newOwner),F(e.liveUntilLedger)])}function De(t){return ct(t,"accept_ownership",[])}function We(t,e){return ct(t,"set_swap_aggregator",[D(e.aggregator)])}function Fe(t,e){return ct(t,"set_price_aggregator",[D(e.aggregator)])}function ze(t,e){return ct(t,"set_accumulator",[D(e.accumulator)])}function Ve(t,e){return ct(t,"set_position_limits",[_e(e)])}function Xe(t,e){return ct(t,"approve_blend_pool",[D(e.pool)])}function je(t,e){return ct(t,"revoke_blend_pool",[D(e.pool)])}function Ge(t,e){return ct(t,"set_oracle",[Be(e.key),Ue(e.oracle)])}function He(t,e){const r=e.toleranceBps,n=e.upperRatioBps??1e4+r,o=e.lowerRatioBps??Math.max(1,Math.floor(1e8/n));return ct(t,"set_tolerance",[Be(e.key),et({lower_ratio_bps:F(o),upper_ratio_bps:F(n)})])}function Ke(t,e){return ct(t,"set_spoke_asset_flags",[F(e.spokeId),Z(e.hubId,e.asset),V(e.paused),V(e.frozen),V(e.noSeize)])}function Ye(t,e){return ct(t,"set_oracle_sanity_bounds",[D(e.asset),W(e.minPriceWad),W(e.maxPriceWad)])}function Ze(t,e){return ct(t,"update_indexes",[D(t.caller),H(e.assets.map((t=>Z(t.hubId,t.asset))))])}function Je(t,e){return ct(t,"renew_account",[D(t.caller),z(e.accountNonce)])}function Qe(t,e){return ct(t,"create_liquidity_pool",[F(e.hubId),D(e.asset),Se(e.params)])}function tr(t,e){return ct(t,"upgrade_liquidity_pool_params",[Z(e.hubId,e.asset),Ie(e.params)])}function er(t,e){return ct(t,"claim_revenue",[D(t.caller),H(e.assets.map((t=>Z(t.hubId,t.asset))))])}function rr(t,e){return ct(t,"add_rewards",[D(t.caller),Q(e.rewards)])}function nr(t,e){return ct(t,"update_account_threshold",[D(t.caller),V(e.hasRisks),H(e.accountNonces.map((t=>z(t))))])}const or="00".repeat(32),sr=t=>{if("string"==typeof t)return K(t);const e=E.hp.from(t);if(32!==e.length)throw new Error(`Stellar governance builder: expected a 32-byte salt (got ${e.length} bytes)`);return d.ScVal.scvBytes(e)},ir=(t,...e)=>H([j(t),...e]),ar=t=>et({new_owner:D(t.newOwner),live_until_ledger:F(t.liveUntilLedger)}),ur=t=>et({asset:D(t.asset),bonus:F(t.bonus),borrow_cap:W(t.borrowCap),can_borrow:V(t.canBorrow),can_collateral:V(t.canCollateral),frozen:V(t.frozen),hub_id:F(t.hubId),paused:V(t.paused),liquidation_fees:F(t.liquidationFees),ltv:F(t.ltv),no_seize:V(t.noSeize),spoke_id:F(t.spokeId),supply_cap:W(t.supplyCap),threshold:F(t.threshold)}),lr=t=>et({account:D(t.account),role:j(t.role)});function cr(e,r,s){if(!e.governanceAddress)throw new Error("Stellar governanceAddress is required");const i=new o(e.governanceAddress),a=new t(e.caller,e.sourceSequence);return{xdr:new u(a,{fee:e.fee??n,networkPassphrase:B[e.network]}).addOperation(i.call(r,...s)).setTimeout(e.timeoutSeconds??300).build().toXDR()}}const pr=(t,e,r)=>cr(t,"propose",[D(t.caller),e,sr(r)]),dr=(t,e,r)=>cr(t,"execute_self",[G(),e,sr(r)]);function fr(t,e,r){return pr(t,ir("SetSwapAggregator",D(e.aggregator)),r)}function hr(t,e,r){return pr(t,ir("SetPriceAggregator",D(e.aggregator)),r)}function mr(t,e,r){return pr(t,ir("SetAccumulator",D(e.accumulator)),r)}function gr(t,e,r){return pr(t,ir("SetPositionLimits",_e(e)),r)}function yr(t,e){return pr(t,ir("CreateHub"),e)}function wr(t,e){return pr(t,ir("AddSpoke"),e)}function br(t,e,r){return pr(t,ir("RemoveSpoke",F(e.spokeId)),r)}function vr(t,e,r){return pr(t,ir("AddAssetToSpoke",ur(e)),r)}function Ir(t,e,r){return pr(t,ir("EditAssetInSpoke",ur(e)),r)}function Sr(t,e,r){return pr(t,ir("RemoveAssetFromSpoke",et({hub_asset:Z((n=e).hubId,n.asset),spoke_id:F(n.spokeId)})),r);var n}function _r(t,e,r){return pr(t,ir("SetSpokeLiquidationCurve",et({hf_for_max_bonus_wad:W((n=e).hfForMaxBonusWad),liquidation_bonus_factor_bps:F(n.liquidationBonusFactorBps),spoke_id:F(n.spokeId),target_hf_wad:W(n.targetHfWad)})),r);var n}function Br(t,e,r){return pr(t,ir("SetPositionManager",D(e.manager),V(e.isActive)),r)}function Er(t,e,r){return pr(t,ir("SetMinBorrowCollateralUsd",W(e.floorWad)),r)}function Rr(t,e,r){return pr(t,ir("ApproveToken",D(e.token)),r)}function kr(t,e,r){return pr(t,ir("RevokeToken",D(e.token)),r)}function Ar(t,e,r){return pr(t,ir("ApproveBlendPool",D(e.pool)),r)}function xr(t,e,r){return pr(t,ir("RevokeBlendPool",D(e.pool)),r)}function qr(t,e,r){return pr(t,ir("CreateLiquidityPool",et({asset:D((n=e).asset),hub_id:F(n.hubId),params:Se(n.params)})),r);var n}function Tr(t,e,r){return pr(t,ir("UpgradeLiquidityPoolParams",et({hub_asset:Z((n=e).hubId,n.asset),params:Ie(n.params)})),r);var n}function Ur(t,e,r){return pr(t,ir("DeployPool",K(e.wasmHash)),r)}function $r(t,e,r){return pr(t,ir("UpgradePool",K(e.wasmHash)),r)}function Or(t,e,r){return pr(t,ir("UpgradeController",K(e.wasmHash)),r)}function Cr(t,e,r){return pr(t,ir("MigrateController",F(e.newVersion)),r)}function Nr(t,e,r){return pr(t,ir("TransferCtrlOwnership",ar(e)),r)}function Pr(t,e,r){return pr(t,ir("ConfigureAssetOracle",et({key:Be((n=e).key),oracle:Ue(n.oracle)})),r);var n}function Lr(t,e,r){return pr(t,ir("EditOracleTolerance",et({key:Be((n=e).key),tolerance:F(n.tolerance)})),r);var n}function Mr(t,e,r){return pr(t,ir("UpgradeGov",K(e.wasmHash)),r)}function Dr(t,e,r){return pr(t,ir("UpdateGovDelay",F(e.newDelay)),r)}function Wr(t,e,r){return pr(t,ir("GrantGovRole",lr(e)),r)}function Fr(t,e,r){return pr(t,ir("RevokeGovRole",lr(e)),r)}function zr(t,e,r){return pr(t,ir("TransferGovOwnership",ar(e)),r)}function Vr(t,e){const r=H(e.argsXdr.map((t=>d.ScVal.fromXDR(t,"base64")))),n=sr(e.predecessor??or);return cr(t,"execute",[G(),D(e.target),j(e.functionName),r,n,sr(e.salt)])}function Xr(t,e,r){return dr(t,ir("UpgradeGov",K(e.wasmHash)),r)}function jr(t,e,r){return dr(t,ir("UpdateGovDelay",F(e.newDelay)),r)}function Gr(t,e,r){return dr(t,ir("GrantGovRole",lr(e)),r)}function Hr(t,e,r){return dr(t,ir("RevokeGovRole",lr(e)),r)}function Kr(t,e,r){return dr(t,ir("TransferGovOwnership",ar(e)),r)}const Yr=t=>H(t.map(D));function Zr(t,e,r){return cr(t,"propose_canceller_reset",[Yr(e.newCancellers),sr(r)])}function Jr(t,e,r){return cr(t,"execute_canceller_reset",[Y(e.executor,D),Yr(e.newCancellers),sr(r)])}function Qr(t,e){return cr(t,"set_spoke_asset_flags",[D(t.caller),F(e.spokeId),Z(e.hubId,e.asset),V(e.paused),V(e.frozen),V(e.noSeize)])}function tn(t,e){return cr(t,"set_oracle_sanity_bounds",[D(t.caller),D(e.asset),W(e.minPriceWad),W(e.maxPriceWad)])}function en(t){return cr(t,"create_hub",[D(t.caller)])}function rn(t){return cr(t,"add_spoke",[D(t.caller)])}function nn(t,e){return cr(t,"revoke_role_immediate",[D(e.account),j(e.role)])}function on(t){return cr(t,"pause",[D(t.caller)])}function sn(t,e){return pr(t,ir("Unpause"),e)}const an=t=>t.toXDR("base64"),un=t=>d.ScVal.fromXDR(t,"base64"),ln=t=>t.map((t=>String(p(un(t))))).join(":"),cn=t=>"bigint"==typeof t||"number"==typeof t?t.toString():String(t),pn=t=>Number(t),dn=t=>String(t),fn=t=>t instanceof Uint8Array?E.hp.from(t).toString("hex"):E.hp.isBuffer(t)?t.toString("hex"):String(t),hn=["None","Multiply","Long","Short"],mn=["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"],gn=t=>Array.isArray(t)?t:[],yn=(t,e)=>{const r="Borrow"===e;return{action:(n=t[0],mn[pn(n)]??cn(n)),positionType:e,hubId:pn(t[1]),asset:dn(t[2]),scaledAmountRay:cn(t[3]),indexRay:cn(t[4]),amount:cn(t[5]),liquidationThresholdBps:r?void 0:pn(t[6]),liquidationBonusBps:r?void 0:pn(t[7]),loanToValueBps:r?void 0:pn(t[8]),liquidationFeesBps:r?void 0:pn(t[9])};var n},wn=t=>{return{owner:dn(t[0]),spokeId:pn(t[1]),mode:(e=t[2],hn[pn(e)]??"None")};var e},bn=t=>Array.isArray(t)?t[1]:void 0,vn=t=>{const e=(r=t,Array.isArray(r)?dn(r[0]):dn(r));var r;if("Token"===e)return{Token:dn(bn(t))};if("Ref"===e)return{Ref:dn(bn(t))};if(t&&"object"==typeof t&&!Array.isArray(t)){const e=t;if(void 0!==e.Token)return{Token:dn(e.Token)};if(void 0!==e.Ref)return{Ref:dn(e.Ref)}}return{Token:dn(t)}},In=t=>{const e=t.tolerance??{};return{assetDecimals:pn(t.asset_decimals),maxPriceStaleSeconds:pn(t.max_price_stale_seconds),sources:gn(t.sources).map((t=>t)),tolerance:{upperRatio:pn(e.upper_ratio_bps),lowerRatio:pn(e.lower_ratio_bps)},independence:t.independence,minSanityPriceWad:cn(t.min_sanity_price_wad),maxSanityPriceWad:cn(t.max_sanity_price_wad)}},Sn={"market:create":t=>({topic:"market:create",data:{hubId:pn(t.hub_id),baseAsset:dn(t.base_asset),maxBorrowRate:cn(t.max_borrow_rate),baseBorrowRate:cn(t.base_borrow_rate),slope1:cn(t.slope1),slope2:cn(t.slope2),slope3:cn(t.slope3),midUtilization:cn(t.mid_utilization),optimalUtilization:cn(t.optimal_utilization),maxUtilization:cn(t.max_utilization),reserveFactor:pn(t.reserve_factor),marketAddress:dn(t.market_address)}}),"market:params_update":t=>({topic:"market:params_update",data:{asset:dn(t.asset),maxBorrowRateRay:cn(t.max_borrow_rate),baseBorrowRateRay:cn(t.base_borrow_rate),slope1Ray:cn(t.slope1),slope2Ray:cn(t.slope2),slope3Ray:cn(t.slope3),midUtilizationRay:cn(t.mid_utilization),optimalUtilizationRay:cn(t.optimal_utilization),maxUtilizationRay:cn(t.max_utilization),reserveFactorBps:pn(t.reserve_factor)}}),"market:batch_state_update":t=>({topic:"market:batch_state_update",data:{updates:gn(t).map((t=>{return e=gn(t),{hubId:pn(e[0]),asset:dn(e[1]),timestamp:pn(e[2]),supplyIndexRay:cn(e[3]),borrowIndexRay:cn(e[4]),cash:cn(e[5]),suppliedRay:cn(e[6]),borrowedRay:cn(e[7]),revenueRay:cn(e[8])};var e}))}}),"market:batch_params_update":t=>({topic:"market:batch_params_update",data:{updates:gn(t).map((t=>{const e=t;return{hubId:pn(e.hub_id),asset:dn(e.asset),params:(r=e.params,{maxBorrowRateRay:cn(r.max_borrow_rate),baseBorrowRateRay:cn(r.base_borrow_rate),slope1Ray:cn(r.slope1),slope2Ray:cn(r.slope2),slope3Ray:cn(r.slope3),midUtilizationRay:cn(r.mid_utilization),optimalUtilizationRay:cn(r.optimal_utilization),maxUtilizationRay:cn(r.max_utilization),reserveFactorBps:pn(r.reserve_factor),isFlashloanable:Boolean(r.is_flashloanable),flashloanFeeBps:pn(r.flashloan_fee),assetId:dn(r.asset_id),assetDecimals:pn(r.asset_decimals)})};var r}))}}),"position:batch_update":t=>{const e=gn(t);return{topic:"position:batch_update",data:{accountId:cn(e[0]),accountAttributes:wn(gn(e[1])),updates:[...gn(e[2]).map((t=>yn(gn(t),"Deposit"))),...gn(e[3]).map((t=>yn(gn(t),"Borrow")))]}}},"position:flash_loan":t=>({topic:"position:flash_loan",data:{hubId:pn(t.hub_id),asset:dn(t.asset),receiver:dn(t.receiver),caller:dn(t.caller),amount:cn(t.amount),fee:cn(t.fee)}}),"config:asset_oracle":t=>({topic:"config:asset_oracle",data:{key:vn(t.key),oracle:In(t.oracle)}}),"config:oracle":t=>({topic:"config:oracle",data:{asset:dn(t.asset),oracle:In(t.config??t.oracle)}}),"position:liquidation":t=>({topic:"position:liquidation",data:{liquidator:dn(t.liquidator),accountId:cn(t.account_id),repaidUsdWad:cn(t.repaid_usd_wad),bonusBps:cn(t.bonus_bps)}}),"debt:bad_debt":t=>({topic:"debt:bad_debt",data:{accountId:cn(t.account_id),totalBorrowUsdWad:cn(t.total_borrow_usd_wad),totalCollateralUsdWad:cn(t.total_collateral_usd_wad)}}),"strategy:initial_payment":t=>({topic:"strategy:initial_payment",data:{token:dn(t.token),amount:cn(t.amount),usdValueWad:cn(t.usd_value_wad),accountId:cn(t.account_id)}}),"strategy:fee":t=>({topic:"strategy:fee",data:{hubId:pn(t.hub_id),asset:dn(t.asset),amount:cn(t.amount),fee:cn(t.fee),amountSent:cn(t.amount_sent)}}),"config:approve_blend_pool":t=>({topic:"config:approve_blend_pool",data:{pool:dn(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:fn(t.wasm_hash??t.pool),approved:Boolean(t.approved)}}),"config:swap_aggregator":t=>({topic:"config:swap_aggregator",data:{aggregator:dn(t.aggregator??t.swap_aggregator)}}),"config:price_aggregator":t=>({topic:"config:price_aggregator",data:{aggregator:dn(t.aggregator??t.price_aggregator)}}),"config:aggregator":t=>({topic:"config:aggregator",data:{aggregator:dn(t.aggregator)}}),"config:accumulator":t=>({topic:"config:accumulator",data:{accumulator:dn(t.accumulator)}}),"config:pool_template":t=>({topic:"config:pool_template",data:{wasmHash:fn(t.wasm_hash)}}),"config:position_limits":t=>({topic:"config:position_limits",data:{maxSupplyPositions:pn(t.max_supply_positions),maxBorrowPositions:pn(t.max_borrow_positions)}}),"config:min_borrow_collateral":t=>({topic:"config:min_borrow_collateral",data:{minBorrowCollateralUsdWad:cn(t.min_borrow_collateral_usd_wad??t.floor_wad??t.value)}}),"config:oracle_disabled":t=>({topic:"config:oracle_disabled",data:{asset:dn(t.asset)}}),"config:spoke":t=>{const e=t.spoke;return{topic:"config:spoke",data:{spokeId:pn(e.spoke_id),isDeprecated:Boolean(e.is_deprecated),liquidationTargetHfWad:cn(e.liquidation_target_hf_wad),healthFactorForMaxBonusWad:cn(e.hf_for_max_bonus_wad),liquidationBonusFactorBps:pn(e.liquidation_bonus_factor_bps)}}}},_n=Object.freeze(Object.keys(Sn));function Bn(t,e){const r=ln(t),n=Sn[r];return n?n(p(un(e))):null}const En=1e4;function Rn(t,e){return`${t}-${BigInt(e).toString(10)}`}function kn(t){const e=t.split("-");return e.length>=2&&parseInt(e[1],10)||0}function An(t,e=0){return 1e4*t+e}function xn(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 qn=(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 Tn(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=qn(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,simulate:t.simulate,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 Un(t){if(!t.baseUrl)throw new Error("Stellar quote baseUrl is required");const e=qn(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()}function $n(t,e){const r=t[e];return"function"==typeof r?r.call(t):r}function On(t){if(!t||"object"!=typeof t)return;const e=t;return"function"==typeof e.switch?e.switch().name:e.type}function Cn(t){return Nn($n(t,"bytes"))}function Nn(t){const e=t;return E.hp.from("value"in e?e.value:e)}const Pn=10,Ln=5,Mn=3,Dn=Pn+Ln*N+Mn*P,Wn=16384;class Fn extends Error{code;constructor(t,e){super(`Stellar route verification failed [${t}]: ${e}`),this.name="StellarRouteVerificationError",this.code=t}}const zn=(t,e)=>{throw new Fn(t,e)},Vn=t=>{const e="string"==typeof t?t:t&&"object"==typeof t&&"routeXdr"in t?t.routeXdr:void 0;if("string"==typeof e&&e.length>2*Wn)return zn("OVERSIZED",`encoded route has ${e.length} characters`);try{return Cn(at(t))}catch(t){return zn("MALFORMED",t instanceof Error?t.message:String(t))}},Xn=t=>{let e;try{e=d.ScVal.fromXDR(t)}catch(t){return zn("MALFORMED",`payload is not one XDR ScVal: ${t instanceof Error?t.message:String(t)}`)}if("scvMap"!==On(e))return zn("MALFORMED","payload must be a StrategyPayload map");const r=$n(e,"map")??[];if("amounts,assets,ops"!==r.map((t=>"scvSymbol"===On($n(t,"key"))?$n($n(t,"key"),"sym").toString():"")).join(","))return zn("MALFORMED","payload fields must be exactly amounts, assets, ops");const[n,o,s]=r.map((t=>$n(t,"val")));return"scvVec"!==On(n)||"scvVec"!==On(o)||"scvBytes"!==On(s)?zn("MALFORMED","payload field has the wrong type"):{amounts:$n(n,"vec")??[],assets:$n(o,"vec")??[],ops:Cn(s)}};function jn(t){const r=Vn(t);0===r.length&&zn("MALFORMED","route is empty"),r.length>Wn&&zn("OVERSIZED",`route has ${r.length} bytes, above ${Wn}`);const n=Xn(r),o=n.assets.length,s=n.amounts.length;0===o&&zn("MALFORMED","asset registry is empty"),(o>L||s>M)&&zn("OVERSIZED",`registries hold ${o} assets and ${s} amounts`);const i=n.assets.map(((t,r)=>"scvAddress"!==On(t)?zn("MALFORMED",`assets[${r}] is not an address`):e.fromScAddress($n(t,"address")).toString())),a=n.amounts.map(((t,e)=>"scvI128"!==On(t)?zn("MALFORMED",`amounts[${e}] is not an i128`):c(t))),u=n.ops;u.length<Pn&&zn("MALFORMED","program header is truncated"),u.length>Dn&&zn("OVERSIZED",`program has ${u.length} bytes, above ${Dn}`);const l=t=>{const e=u[t];return void 0===e?zn("MALFORMED",`program byte ${t} is missing`):e},p=l(0);p!==A&&zn("UNSUPPORTED_VERSION",`program version ${p}, expected ${A}`);const d=l(8),f=l(9);0===d&&zn("INVALID_STRUCTURE","program has no instructions"),(d>N||f>P)&&zn("OVERSIZED",`program declares ${d} instructions and ${f} weights`);const h=Pn+Ln*d;u.length!==h+Mn*f&&zn("MALFORMED","program length does not match its instruction and weight counts");const m=l(1),g=l(2),y=l(3);(m>=o||g>=o||y>=s)&&zn("MALFORMED","header index is outside its registry"),m===g&&zn("INVALID_STRUCTURE","token_in equals token_out");const w=u.readUInt32BE(4),b=[];for(let t=0;t<f;t+=1){const e=u.readUIntBE(h+Mn*t,Mn);(0===e||e>x)&&zn("INVALID_STRUCTURE",`split weight ${e} outside 1..=${x}`),b.push(e)}const v=t=>i[t]??zn("MALFORMED",`asset index ${t} is outside the registry`),I=t=>a[t]??zn("MALFORMED",`amount index ${t} is outside the registry`),S=[];let _;for(let t=0;t<d;t+=1){const e=Pn+Ln*t,r=l(e),n=l(e+1),o=l(e+2),i=l(e+3),a=l(e+4);let u;if(r>T&&zn("UNKNOWN_OPCODE",`instruction ${t} has opcode ${r}`),n===U)u={kind:"all"};else if(n===$)void 0!==_&&_===i||zn("INVALID_STRUCTURE",`instruction ${t} does not chain onto its predecessor`),u={kind:"prev"};else if(n>=C){const e=b[n-C];void 0===e&&zn("MALFORMED",`instruction ${t} weight index is out of range`),u={kind:"ppm",ppm:e}}else u={kind:"fixed",amount:I(n-O)};const c=v(o);r!==q&&r!==T?(i===a&&zn("INVALID_STRUCTURE",`instruction ${t} swaps a token for itself`),S.push({kind:"swap",venue:R[r],mode:u,pool:c,tokenIn:v(i),tokenOut:v(a)}),_=a):("all"!==u.kind&&zn("MALFORMED",`liquidity instruction ${t} must use mode All`),a>=s&&zn("MALFORMED",`instruction ${t} amount index is out of range`),S.push({kind:r===q?"burn":"mint",pool:c,shareToken:v(i),amountIndex:a}),_=r===T?i:void 0)}const B=I(y);return B<=0n&&zn("MIN_OUT_TOO_LOW",`encoded total_min_out is ${B}`),{version:p,tokenIn:v(m),tokenOut:v(g),totalMinOut:B,referralId:w,assets:i,amounts:a,ops:S,weights:b}}function Gn(t,e){if(a.isValidContract(t))return t;if(!e)return zn("EXPECTATION_MISSING",`token ${t} is not a contract id; pass \`network\` to derive its asset contract`);try{const n=t.indexOf(":");return("XLM"===t||"native"===t?r.native():new r(t.slice(0,n),t.slice(n+1))).contractId(B[e])}catch{return zn("MALFORMED",`token id ${t} is not a contract id or a classic asset`)}}const Hn=(t,e)=>"bigint"==typeof t?t:/^\d+$/.test(t)?BigInt(t):zn("EXPECTATION_MISSING",`${e} must be a base-unit integer string`);function Kn(t,e){const r=Hn(e.minOut,"expected.minOut");r<=0n&&zn("EXPECTATION_MISSING","expected.minOut must be positive");const n=jn(t);if(n.tokenIn!==e.tokenIn&&zn("TOKEN_IN_MISMATCH",`route spends ${n.tokenIn}, expected ${e.tokenIn}`),n.tokenOut!==e.tokenOut&&zn("TOKEN_OUT_MISMATCH",`route delivers ${n.tokenOut}, expected ${e.tokenOut}`),n.totalMinOut<r&&zn("MIN_OUT_TOO_LOW",`route enforces a minimum of ${n.totalMinOut}, below the expected ${r}`),void 0!==e.amountIn){const t=Hn(e.amountIn,"expected.amountIn");for(const e of n.ops)"swap"===e.kind&&"fixed"===e.mode.kind&&e.tokenIn===n.tokenIn&&e.mode.amount>t&&zn("AMOUNT_IN_EXCEEDED",`a leg spends ${e.mode.amount}, above the input ${t}`)}return n}const Yn=t=>nt(t).toXDR("base64");function Zn(e,r){if(!e.routerAddress)throw new Error("Stellar aggregator routerAddress is required");const s=new o(e.routerAddress),i=new t(e.caller,e.sourceSequence),a=at(((t,e)=>(t=>Boolean(t&&"object"==typeof t&&!(t instanceof Uint8Array)&&"paths"in t))(t)&&void 0===t.referralId?{...t,referralId:e??0}:t)(r,e.referralId));return{xdr:new u(i,{fee:e.fee??n,networkPassphrase:B[e.network]}).addOperation(s.call("execute_strategy",D(e.caller),W(e.totalIn),a)).setTimeout(e.timeoutSeconds??300).build().toXDR()}}function Jn(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(to),splitPpm:t.splitPpm}))):[{hops:t.hops.map(to),splitPpm:1e6}],referralId:e.referralId??0,tokenIn:t.from,tokenOut:t.to,totalMinOut:t.amountOutMin}}function Qn(t,e={}){const r=e.expected??{},n="string"==typeof t.routeXdr&&t.routeXdr.length>0?{routeXdr:t.routeXdr}:Jn(t,e),o=[t.amountOutMin,r.minOut].filter((t=>void 0!==t)).map((t=>{if("bigint"==typeof t)return t;if("string"!=typeof t||!/^\d+$/.test(t))throw new Fn("MALFORMED","minimum output must be a base-unit integer string");return BigInt(t)})).reduce(((t,e)=>void 0===t||e>t?e:t),void 0);if(void 0===o)throw new Fn("EXPECTATION_MISSING","quote has no `amountOutMin`; pass `slippage` when fetching it or `expected.minOut`");return Kn(n,{tokenIn:Gn(r.tokenIn??t.from,e.network),tokenOut:Gn(r.tokenOut??t.to,e.network),minOut:o,amountIn:r.amountIn??t.amountIn}),n}const to=t=>({amountOut:t.amountOut,pool:t.address,tokenIn:t.from,tokenOut:t.to,venue:t.dex});function eo(t){try{const{envelopeXdr:r,networkPassphrase:n,routerAddress:o,viewer:s,operationIndex:i}=t;if(!n||!a.isValidContract(o)||new e(s).toString()!==s||"string"!=typeof r||r.length>1048576||r.length%4!=0||!/^[A-Za-z0-9+/]+={0,2}$/.test(r)||void 0!==i&&(!Number.isSafeInteger(i)||i<0))return null;const l=u.fromXDR(r,n),p="innerTransaction"in l?l.innerTransaction:l;if(void 0!==i&&i>=p.operations.length)return null;let d=null;for(const[t,r]of p.operations.entries()){if(void 0!==i&&t!==i)continue;if("invokeHostFunction"!==r.type)continue;const n=r.func;if("hostFunctionTypeInvokeContract"!==On(n))continue;const u=$n(n,"invokeContract");if(e.fromScAddress($n(u,"contractAddress")).toString()!==o||"execute_strategy"!==$n(u,"functionName").toString())continue;const l=$n(u,"args"),[p,f,h]=l;if(3!==l.length||!p||!f||!h||"scvAddress"!==On(p)||"scvI128"!==On(f)||"scvBytes"!==On(h))return null;if(e.fromScAddress($n(p,"address")).toString()!==s)continue;const m=c(f);if(m<=0n)return null;const g=jn(Cn(h));if(g.tokenIn===g.tokenOut||!a.isValidContract(g.tokenIn)||!a.isValidContract(g.tokenOut))return null;if(d)return null;d={tokenIn:g.tokenIn,tokenOut:g.tokenOut,amountInAtoms:m.toString(),operationIndex:t}}return d}catch{return null}}class ro extends Error{code;offender;constructor(t,e,r){super(`Stellar authorization check failed [${t}]: ${e}${r?` — ${r.contract}.${r.fn}(${r.args.join(", ")})`:""}`),this.name="StellarAuthPolicyError",this.code=t,this.offender=r}}const no=t=>t&&"scvAddress"===On(t)?e.fromScAddress($n(t,"address")).toString():void 0,oo=t=>t&&"scvI128"===On(t)?c(t):void 0,so=t=>t&&"scvVec"===On(t)?$n(t,"vec")??[]:void 0,io=(t,e)=>{if(!t||"scvMap"!==On(t))return;const r=($n(t,"map")??[]).find((t=>"scvSymbol"===On($n(t,"key"))&&$n($n(t,"key"),"sym").toString()===e));return r?$n(r,"val"):void 0},ao=t=>no(t)??oo(t)?.toString()??t.toXDR("base64"),uo=t=>({contract:e.fromScAddress($n(t,"contractAddress")).toString(),fn:$n(t,"functionName").toString(),args:$n(t,"args").map(ao)}),lo=t=>{const e=$n(t,"function");return"sorobanAuthorizedFunctionTypeContractFn"===On(e)?$n(e,"contractFn"):void 0};function co(t,r,n){const o=t.filter((t=>{const o=$n(t,"credentials"),s=On(o);if("sorobanCredentialsAddress"!==s&&"sorobanCredentialsSourceAccount"!==s)throw new ro("MALFORMED_TRANSACTION","unsupported authorization credentials");return("sorobanCredentialsAddress"===s?e.fromScAddress($n($n(o,"address"),"address")).toString():n??r.caller)===r.caller}));if(o.length>1)throw new ro("DUPLICATE_ENTRY",`${o.length} authorization entries for ${r.caller}, expected one`);const s=o[0];if(!s)return;const i=lo($n(s,"rootInvocation"));if(!i)throw new ro("UNEXPECTED_ROOT","root is not a contract call");const a=uo(i);if(a.contract!==r.root.contract||a.fn!==r.root.fn)throw new ro("UNEXPECTED_ROOT",`expected ${r.root.contract}.${r.root.fn}`,a);const u=r.transfers.map((()=>0n)),l=(r.calls??[]).map((()=>0));for(const t of $n($n(s,"rootInvocation"),"subInvocations")){const e=lo(t);if(!e)throw new ro("UNEXPECTED_CALL","sub-invocation is not a contract call");const n=uo(e);if($n(t,"subInvocations").length>0)throw new ro("NESTED_INVOCATION","sub-invocation carries its own sub-invocations",n);const o=(r.calls??[]).findIndex((t=>t.contract===n.contract&&t.fn===n.fn));if(-1!==o){const t=(r.calls??[])[o],s=t.reject($n(e,"args"));if(s)throw new ro("UNEXPECTED_CALL",s,n);if(l[o]=(l[o]??0)+1,(l[o]??0)>t.maxCount)throw new ro("UNEXPECTED_CALL",`more than ${t.maxCount} calls`,n);continue}if("transfer"!==n.fn||3!==$n(e,"args").length)throw new ro("UNEXPECTED_CALL","only `transfer` is allowed",n);if(!r.transfers.some((t=>t.token===n.contract)))throw new ro("UNEXPECTED_TOKEN","transfer on an unexpected token",n);const[s,i,a]=$n(e,"args");if(no(s)!==r.caller)throw new ro("UNEXPECTED_SENDER","transfer is not from the caller",n);const c=no(i),p=r.transfers.findIndex((t=>t.token===n.contract&&t.to===c));if(-1===p)throw new ro("UNEXPECTED_RECIPIENT","transfer to an unexpected recipient",n);const d=oo(a),f=r.transfers[p],h=(u[p]??0n)+(d??0n);if(void 0===d||d<=0n||h>f.maxAmount)throw new ro("AMOUNT_EXCEEDED",`transfers total ${h}, above the expected ${f.maxAmount}`,n);u[p]=h}}const po=t=>{throw new ro("MALFORMED_TRANSACTION",t)},fo=(t,e)=>{const r=new Map;for(const e of so(t)??po("payments argument is not a vector")){const[t,n]=so(e)??[],o=no(io(t,"asset")),s=oo(n);if(void 0===o||void 0===s||s<0n)return po("payment is not a (HubAssetKey, i128) tuple");r.set(o,(r.get(o)??0n)+s)}return[...r].map((([t,r])=>({token:t,to:e,maxAmount:r})))},ho=new Set([1,3,5]),mo=(t,e,r)=>({contract:t,fn:"submit",maxCount:2,reject:t=>{if(4!==t.length)return"submit must have four arguments";if(no(t[0])!==e)return"`from` is not the caller";if(no(t[1])!==r||no(t[2])!==r)return"`spender` and `to` must be the lending controller";const n=so(t[3]);if(!n)return"requests is not a vector";for(const t of n){const e=io(t,"request_type");if(!e||"scvU32"!==On(e)||!ho.has($n(e,"u32")))return"request is not a withdraw, withdraw-collateral, or repay"}}});function go(t,e,r){const{contract:n,fn:o}=uo(e),s=$n(e,"args"),i={caller:t,root:{contract:n,fn:o},transfers:[]};if(n===r.governance)return i;if(n===r.aggregatorRouter){if("execute_strategy"!==o)return i;const e=oo(s[1]);if(no(s[0])!==t||void 0===e||"scvBytes"!==On(s[2]))return po("execute_strategy arguments must be (caller, total_in, swap_xdr)");const r=jn(Cn(s[2]));return i.transfers=[{token:r.tokenIn,to:n,maxAmount:e}],i}if(n!==r.lendingController)throw new ro("UNSUPPORTED_CONTRACT",`no authorization policy for contract ${n}; pass an explicit policy`);if(no(s[0])!==t)throw new ro("CALLER_MISMATCH",`${o} is not invoked for ${t}`);switch(o){case"supply":i.transfers=fo(s[3],r.lendingPool);break;case"repay":case"liquidate":i.transfers=fo(s[2],r.lendingPool);break;case"multiply":{const t=s[8];t&&"scvVoid"!==On(t)&&(i.transfers=fo(d.ScVal.scvVec([t]),n));break}case"migrate_from_blend":{const e=no(s[4])??po("blend_pool is not an address");i.calls=[mo(e,t,n)];break}}return i}const yo=t=>{let e;try{e=d.TransactionEnvelope.fromXDR(t,"base64")}catch{return po("not a transaction envelope")}if("envelopeTypeTx"!==On(e))return po("expected a regular (v1) transaction");const r=$n($n(e,"v1"),"tx"),n=$n(r,"operations")[0];if(!n||1!==$n(r,"operations").length)return po("expected exactly one operation");const o=$n(n,"body");if("invokeHostFunction"!==On(o))return po("operation is not a contract invocation");const s=$n(o,"invokeHostFunctionOp");return"hostFunctionTypeInvokeContract"!==On($n(s,"hostFunction"))?po("host function is not a contract call"):{source:(i=$n(n,"sourceAccount")??$n(r,"sourceAccount"),a.encodeEd25519PublicKey(Nn("keyTypeMuxedEd25519"===On(i)?$n($n(i,"med25519"),"ed25519"):$n(i,"ed25519")))),op:s,call:$n($n(s,"hostFunction"),"invokeContract")};var i};function wo(t,e){const r=yo(t);if(void 0!==e.builtXdr&&$n(yo(e.builtXdr).op,"hostFunction").toXDR("base64")!==$n(r.op,"hostFunction").toXDR("base64"))throw new ro("INVOCATION_CHANGED","the prepared transaction does not invoke what was built",uo(r.call));const n=e.policy??go(e.caller,r.call,{..._(e.network),...e.deployment});co($n(r.op,"auth"),n,r.source)}function bo(t,e){const r=e instanceof Error?e.message:String(e);return new Error(`[xoxno-invoked:${t}] ${r}`)}async function vo(t,e,r){const n=r?.instructionLeeway??2e7;if(!Number.isInteger(n)||n<0||n>4294967295)throw new Error("instructionLeeway must be an integer from 0 to 4294967295");const o=u.fromXDR(e,r?.network?B[r.network]:"");try{const e=await t.simulateTransaction(o,{cpuInstructions:n});if(l.Api.isSimulationError(e))throw new Error(e.error);return l.assembleTransaction(o,e).build().toXDR()}catch(t){if(r?.invokedContractId)throw bo(r.invokedContractId,t);throw t}}async function Io(t,e,r){return vo(t,e.xdr,r)}function So(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 _o(t,e){return new Uint8Array(0)}const Bo=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 E.hp.from(e,"hex")};function Eo(e){const r=new t(e.caller,e.sourceSequence),n=new o(e.forwarderAddress).call("mint_and_forward",d.ScVal.scvBytes(Bo(e.message)),d.ScVal.scvBytes(Bo(e.attestation)));return{xdr:new u(r,{fee:e.fee??"10000000",networkPassphrase:B[e.network]}).addOperation(n).setTimeout(e.timeoutSeconds??120).build().toXDR()}}const Ro=10n**27n,ko=10n**18n,Ao=10000n,xo=27,qo=18;function To(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 Uo(t,e,r){if(0n===r)throw new Error("Stellar math: division by zero");return t*e/r}function $o(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 Oo(t,e,r){if(0n===r)throw new Error("Stellar math: division by zero");return(t*e+r/2n)/r}function Co(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 No=t=>10n**BigInt(t);function Po(t,e,r){return e===r?t:r>e?t*No(r-e):t/No(e-r)}function Lo(t,e,r){if(e===r)return t;if(r>e)return t*No(r-e);const n=No(e-r),o=t/n;return t%n===0n?o:o+1n}function Mo(t,e,r){return e===r?t:r>e?t*No(r-e):Co(t,No(e-r))}const Do={floor:Uo,ceil:$o,halfUp:Oo},Wo={floor:Po,ceil:Lo,halfUp:Mo};function Fo(t,e,r,n){return Wo[n](Do[n](t,e,Ro),xo,r)}function zo(t,e,r){return Fo(To(t,"scaledRay"),To(e,"indexRay"),r,"floor")}function Vo(t,e,r){return Fo(To(t,"scaledRay"),To(e,"indexRay"),r,"ceil")}function Xo(t,e,r){return Fo(To(t,"scaledRay"),To(e,"indexRay"),r,"halfUp")}function jo(t,e){if(e>xo)throw new Error(`Stellar math: decimals ${e} exceed RAY scale`);return Po(t,e,xo)}function Go(t,e,r,n){const o=Do[n](t,e,Ro),s=Wo[n](o,xo,qo);return Do[n](s,r,ko)}function Ho(t,e,r,n){const o=Wo[n](jo(t,e),xo,qo);return Do[n](o,r,ko)}const Ko=t=>Number(t)/1e18,Yo=t=>Number(t)/1e27,Zo=(t,e)=>Number(t)/10**e;function Jo(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 Qo=t=>Jo(t,qo),ts=(t,e)=>Oo(t,e,Ro),es=(t,e)=>Oo(t,Ro,e);function rs(t,e){return 0n===e?0n:es(t,e)}function ns(t,e){const r=t>Ro?Ro:t,n=To(e.baseRateRay,"irm.baseRateRay"),o=To(e.slope1Ray,"irm.slope1Ray"),s=To(e.slope2Ray,"irm.slope2Ray"),i=To(e.slope3Ray,"irm.slope3Ray"),a=To(e.midUtilizationRay,"irm.midUtilizationRay"),u=To(e.optimalUtilizationRay,"irm.optimalUtilizationRay"),l=To(e.maxBorrowRateRay,"irm.maxBorrowRateRay");let c;if(r<a)c=n+es(ts(r,o),a);else if(r<u){const t=u-a;c=n+o+es(ts(r-a,s),t)}else{const t=Ro-u;c=n+o+s+(0n===t?0n:es(ts(r-u,i),t))}return c>l?l:c}function os(t,e,r){return 0n===t||!Number.isInteger(r)||r<0||r>=1e4?0n:Oo(ts(t,e),Ao-BigInt(r),Ao)}const ss=t=>Yo(t),is=t=>Math.expm1(Yo(t)),as=5n*ko,us=(t,e,r)=>`${t}:${e}:${r}`;function ls(t,e,r,n){const o=Array.isArray(t)?t:void 0,s=o?o.find((t=>t.spokeId===e&&t.hubId===r&&t.asset===n)):t[us(e,r,n)]??Object.values(t).find((t=>t.spokeId===e&&t.hubId===r&&t.asset===n));if(!s)throw new Error(`Stellar math: no reserve for ${us(e,r,n)}`);return s}const cs=/^0*[1-9]\d*$/,ps=t=>"string"==typeof t&&cs.test(t)?BigInt(t).toString():null,ds=(t,e)=>`${t}:${e}`;function fs(t){const e=new Map,r=new Map,n=new Set,o=new Set;for(const s of t?.indexes??[]){const t=ds(s.hubId,s.asset),i=ps(s.supplyIndex),a=ps(s.borrowIndex),u=ps(s.usdPrice),l=e.get(t),c=l&&ps(l.supplyIndex)===i&&ps(l.borrowIndex)===a&&ps(l.usdPrice)===u;null==i||null==a||null==u||l&&!c?n.add(t):l||e.set(t,s);const p=!1===s.valid||!0===s.stale||!0===s.deviation,d=r.get(s.asset);null==u||p||void 0!==d&&d.toString()!==u?o.add(s.asset):void 0===d&&r.set(s.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 hs=(t,e)=>Uo(t,BigInt(e),Ao);function ms(t,e,r,n){const o="supply"===t.side,s=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:Ko(t.priceWad),amountBase:e.toString(),amountShort:Zo(e,t.decimals),usdWad:r.toString(),usd:Ko(r),gateUsdWad:n.toString(),entryLtvBps:t.entryLtvBps,entryLiquidationThresholdBps:t.entryLiquidationThresholdBps,entryLiquidationBonusBps:t.entryLiquidationBonusBps,entryLiquidationFeesBps:t.entryLiquidationFeesBps,ltvWeightedUsdWad:o?hs(n,s).toString():"0",liquidationWeightedUsdWad:o?hs(n,t.entryLiquidationThresholdBps).toString():"0",liveDataUsed:t.liveDataUsed}}function gs(t){if("supply"===t.side)return ms(t,Fo(t.scaledRay,t.indexRay,t.decimals,"floor"),Go(t.scaledRay,t.indexRay,t.priceWad,"halfUp"),Go(t.scaledRay,t.indexRay,t.priceWad,"floor"));const e=Fo(t.scaledRay,t.indexRay,t.decimals,"ceil"),r=Go(t.scaledRay,t.indexRay,t.priceWad,"ceil");return ms(t,e,r,r)}function ys(t,e,r,n){const o=jo(e,r);return"supply"===t?Uo(o,Ro,n):$o(o,Ro,n)}function ws(t,e,r,n){const o=jo(e,r);return"supply"===t?$o(o,Ro,n):Uo(o,Ro,n)}function bs(t,e){return gs({...t,scaledRay:ys(t.side,e,t.decimals,t.indexRay)})}const vs=(...t)=>{for(const e of t){const t=ps(e);if(null!=t)return BigInt(t)}return Ro};function Is(t,e,r,n){const o=To("supply"===t?e.supplyScaledRay:e.borrowScaledRay,`${t}ScaledRay`);if(0n===o)return null;const s=n.indexes.get(ds(e.hubId,e.asset)),i=n.prices.get(e.asset),a="supply"===t?vs(s?.supplyIndex,e.liveSupplyIndexRay,r.liveSupplyIndexRay,e.supplyIndexRay):vs(s?.borrowIndex,e.liveBorrowIndexRay,r.liveBorrowIndexRay,e.borrowIndexRay),u=i??Qo(r.usdPrice);return gs({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!==s&&void 0!==i})}const Ss=(t,e)=>t.reduce(((t,r)=>t+BigInt(e(r))),0n);function _s(t,e,r,n,o){const s=Ss(e,(t=>t.usdWad)),i=Ss(e,(t=>t.ltvWeightedUsdWad)),a=Ss(e,(t=>t.liquidationWeightedUsdWad)),u=Ss(r,(t=>t.usdWad)),l=0n===u?null:Uo(a,ko,u),c=0n===a?0:Number(u)/Number(a)*100,p=i<n||i<=u?0n:i-u;return{...t,supplies:e,borrows:r,totalCollateralUsdWad:s.toString(),totalCollateralUsd:Ko(s),ltvWeightedCollateralUsdWad:i.toString(),ltvWeightedCollateralUsd:Ko(i),liquidationWeightedCollateralUsdWad:a.toString(),liquidationWeightedCollateralUsd:Ko(a),totalDebtUsdWad:u.toString(),totalDebtUsd:Ko(u),healthFactorWad:null===l?null:l.toString(),healthFactor:null===l?null:Ko(l),healthPercent:c,borrowLimitUsdWad:i.toString(),borrowLimitUsd:Ko(i),availableBorrowUsdWad:p.toString(),availableBorrowUsd:Ko(p),minBorrowCollateralUsdWad:n.toString(),minBorrowCollateralUsd:Ko(n),isLiquidatable:null!==l&&l<ko,liveDataValid:o}}function Bs(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 s=fs(n),i=[],a=[];for(const t of e){const e=ls(r,t.spokeId,t.hubId,t.asset),n=Is("supply",t,e,s);n&&i.push(n);const o=Is("borrow",t,e,s);o&&a.push(o)}const u=null!=n?.minBorrowCollateralUsdWad?To(n.minBorrowCollateralUsdWad,"minBorrowCollateralUsdWad"):as,l=void 0!==n&&[...i,...a].every((t=>t.liveDataUsed));return _s({accountId:o.accountId,owner:o.owner,spokeId:o.spokeId,mode:o.positionMode},i,a,u,l)}const Es=200n,Rs=t=>t.reduce(((t,e)=>e.amount<t.amount?e:t)),ks=t=>t<0n?0n:t,As=(t,e,r,n)=>({amountBase:t.amount,amountShort:Zo(t.amount,e),isFullClose:r,reason:t.reason,projectedUtilization:n}),xs=t=>({amountBase:0n,amountShort:0,isFullClose:!1,reason:t,projectedUtilization:null});function qs(t){const e=t.assetDecimals,r=To(t.irm.maxUtilizationRay,"irm.maxUtilizationRay");return{suppliedBase:Jo(t.hubPool.suppliedShort,e),borrowedBase:Jo(t.hubPool.borrowedShort,e),cashBase:Jo(t.availableLiquidityShort,e),spokeSuppliedBase:Jo(t.suppliedShort,e),spokeBorrowedBase:Jo(t.borrowedShort,e),maxUtilizationRay:r>=Ro?null:r}}const Ts=(t,e)=>t<=0n?null:Number(e)/Number(t);function Us(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 $s=(t,e)=>t.find((t=>t.hubId===e.hubId&&t.asset===e.asset));function Os(t,e,r){if(e.paused)return xs("paused");if(e.frozen)return xs("frozen");if(!e.isBorrowable)return xs("cap");const n=e.assetDecimals,o=qs(e),s=$s(t.borrows,e),i=fs(r).indexes.get(ds(e.hubId,e.asset)),a=s?BigInt(s.indexRay):To(i?.borrowIndex??e.liveBorrowIndexRay,"borrowIndex"),u=s?BigInt(s.usdPriceWad):function(t,e){return fs(e).prices.get(t.asset)??Qo(t.usdPrice)}(e,r),l=s?BigInt(s.scaledRay):0n,c=BigInt(t.totalDebtUsdWad)-(s?BigInt(s.usdWad):0n),p=BigInt(t.ltvWeightedCollateralUsdWad),d=BigInt(t.minBorrowCollateralUsdWad),f=[];if(p<d)f.push({amount:0n,reason:"minCollateral"});else{const e=p-BigInt(t.totalDebtUsdWad),r=e<=0n||u<=0n?0n:Uo(e,10n**BigInt(n),u),o=t=>c+Go(l+ys("borrow",t,n,a),a,u,"ceil");f.push({amount:0n===r?0n:Us(r+16n,(t=>o(t)<=p)),reason:"ltv"})}f.push({amount:ks(To(e.borrowCap,"borrowCap")-o.spokeBorrowedBase),reason:"cap"});const h=Oo(o.suppliedBase,200n,Ao);f.push({amount:ks(o.cashBase-h),reason:"liquidity"});const m=function(t,e){const r=t.maxUtilizationRay;if(null===r)return null;const n=jo(t.suppliedBase,e);return 0n===n?null:Us(ks(Uo(t.suppliedBase,r,Ro)-t.borrowedBase)+16n,(o=>rs(jo(t.borrowedBase+o,e),n)<=r))}(o,n);null!==m&&f.push({amount:m,reason:"utilizationCap"});const g=Rs(f);return As(g,n,!1,Ts(o.suppliedBase,o.borrowedBase+g.amount))}function Cs(t,e,r){if(e.paused)return xs("paused");const n=$s(t.supplies,e);if(!n)return xs(null);const o=n.decimals,s=qs(e),i=BigInt(n.scaledRay),a=BigInt(n.indexRay),u=BigInt(n.usdPriceWad),l=BigInt(n.amountBase),c=Fo(i,a,o,"halfUp"),p=BigInt(t.totalDebtUsdWad),d=BigInt(t.minBorrowCollateralUsdWad),f=BigInt(Math.min(n.entryLtvBps,n.entryLiquidationThresholdBps)),h=[];let m=!0;if(p>0n&&f>0n){const e=p>d?p:d,r=d>p?"minCollateral":"healthFactor",s=BigInt(t.ltvWeightedCollateralUsdWad)-BigInt(n.ltvWeightedUsdWad);if(s<e){m=!1;const t=e-s,l=$o(t,Ao,f),p=BigInt(n.gateUsdWad)-l,d=p<=0n?0n:Uo(p,10n**BigInt(o),u),g=c>0n?c-1n:0n,y=d+16n>g?g:d+16n,w=t=>{const e=ws("supply",t,o,a);return Uo(Go(e>=i?0n:i-e,a,u,"floor"),f,Ao)};h.push({amount:Us(y,(e=>w(e)>=t)),reason:r})}}h.push({amount:l,reason:null}),h.push({amount:s.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=$o(t.borrowedBase,Ro,r),o=t.suppliedBase<n?0n:t.suppliedBase-n+16n,s=jo(t.borrowedBase,e);return Us(o>t.suppliedBase?t.suppliedBase:o,(n=>{const o=jo(t.suppliedBase-n,e);return o>0n&&rs(s,o)<=r}))}(s,o);null!==g&&h.push({amount:g,reason:"utilizationCap"});const y=Rs(h),w=m&&y.amount>=l;return As(y,o,w,Ts(s.suppliedBase-y.amount,s.borrowedBase))}function Ns(t){if(t.paused)return xs("paused");if(t.frozen)return xs("frozen");const e=t.assetDecimals,r=qs(t),n={amount:ks(To(t.supplyCap,"supplyCap")-r.spokeSuppliedBase),reason:"cap"};return As(n,e,!1,Ts(r.suppliedBase+n.amount,r.borrowedBase))}function Ps(t,e,r){if(e.paused)return xs("paused");const n=$s(t.borrows,e);if(!n)return xs(null);const o=n.decimals,s=qs(e),i=BigInt(n.amountBase),a=void 0===r?null:To(r,"walletBalance"),u=null!==a&&a<i?{amount:a,reason:"liquidity"}:{amount:i,reason:null};return As(u,o,u.amount>=i,Ts(s.suppliedBase,ks(s.borrowedBase-u.amount)))}const Ls=(t,e)=>t.hubId===e.hubId&&t.asset===e.asset,Ms=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 Ds(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=>Ls(e,t))),s=-1===o?void 0:e[o],i=Ms(t.amountBase);let a;if(s){const t={side:s.side,hubId:s.hubId,asset:s.asset,decimals:s.decimals,indexRay:BigInt(s.indexRay),priceWad:BigInt(s.usdPriceWad),entryLtvBps:s.entryLtvBps,entryLiquidationThresholdBps:s.entryLiquidationThresholdBps,entryLiquidationBonusBps:s.entryLiquidationBonusBps,entryLiquidationFeesBps:s.entryLiquidationFeesBps,liveDataUsed:s.liveDataUsed},e=BigInt(s.scaledRay);let r;if(i>=0n)r=e+ys(t.side,i,t.decimals,t.indexRay);else{const n=-i,o=n>=("supply"===t.side?Fo(e,t.indexRay,t.decimals,"halfUp"):BigInt(s.amountBase))?e:ws(t.side,n,t.decimals,t.indexRay);r=o>=e?0n:e-o}a=0n===r?null:gs({...t,scaledRay:r})}else a=i<=0n?null:bs(Ws(t),i);-1===o?a&&e.push(a):a?e[o]=a:e.splice(o,1)}return _s({accountId:t.accountId,owner:t.owner,spokeId:t.spokeId,mode:t.mode},r,n,BigInt(t.minBorrowCollateralUsdWad),t.liveDataValid)}function Ws(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:To("supply"===t.side?e.liveSupplyIndexRay:e.liveBorrowIndexRay,"reserve live index"),priceWad:Qo(e.usdPrice),entryLtvBps:e.collateralFactorBps,entryLiquidationThresholdBps:e.liquidationThresholdBps,entryLiquidationBonusBps:e.liquidationPenaltyBps,entryLiquidationFeesBps:e.liquidationFeesBps,liveDataUsed:!1}}function Fs(t,e=0n,r=0n){const n=t.assetDecimals,o=t=>t<0n?0n:t,s=o(Jo(t.hubPool.suppliedShort,n)+Ms(e)),i=rs(jo(o(Jo(t.hubPool.borrowedShort,n)+Ms(r)),n),jo(s,n)),a=ns(i,t.irm),u=os(i,a,t.irm.reserveFactorBps);return{utilization:Yo(i),utilizationRay:i.toString(),borrowAprRay:a.toString(),supplyAprRay:u.toString(),borrowApr:ss(a),supplyApr:ss(u),borrowApy:is(a),supplyApy:is(u)}}const zs={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."},14:{name:"AmountMustBePositive",message:"The amount must be greater than zero."},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 Vs(t){const e=t.match(/Error\(Contract,\s*#(\d+)\)/);if(!e)return null;const r=Number(e[1]),n=zs[r];return n?{code:r,...n}:null}export{Ao as BPS,as as DEFAULT_MIN_BORROW_COLLATERAL_USD_WAD,Es as LIQUIDATION_BUFFER_BPS,Ro as RAY,xo as RAY_DECIMALS,or as STELLAR_GOVERNANCE_ZERO_PREDECESSOR,_n as STELLAR_LENDING_TOPICS,I as STELLAR_NETWORKS,B as STELLAR_NETWORK_PASSPHRASE,Wn as STELLAR_ROUTE_MAX_BYTES,En as SYNTHETIC_EVENT_ORDER_STRIDE,ro as StellarAuthPolicyError,Fn as StellarRouteVerificationError,ko as WAD,qo as WAD_DECIMALS,v as XOXNOClient,_s as aggregateAccountRisk,ns as annualBorrowRateRay,co as assertStellarAuthEntries,wo as assertStellarPreparedTxAuth,jo as baseToRay,Zo as baseToShort,Ho as baseValueWad,fs as buildLiveSnapshot,_o as buildSameTokenRepaySwapSteps,De as buildStellarAcceptOwnershipTx,rr as buildStellarAddRewardsTx,Xe as buildStellarApproveBlendPoolTx,ht as buildStellarBorrowBatchTx,mt as buildStellarBorrowTx,Eo as buildStellarCctpForwardTx,er as buildStellarClaimRevenueTx,Qe as buildStellarCreateLiquidityPoolTx,Jr as buildStellarExecuteCancellerResetTx,Zn as buildStellarExecuteStrategyTx,St as buildStellarFlashLoanTx,rn as buildStellarGovernanceAddSpokeImmediateTx,en as buildStellarGovernanceCreateHubImmediateTx,Xr as buildStellarGovernanceExecuteGovernanceUpgradeTx,Gr as buildStellarGovernanceExecuteGrantGovernanceRoleTx,Hr as buildStellarGovernanceExecuteRevokeGovernanceRoleTx,Kr as buildStellarGovernanceExecuteTransferGovOwnTx,Vr as buildStellarGovernanceExecuteTx,jr as buildStellarGovernanceExecuteUpdateDelayTx,on as buildStellarGovernancePauseTx,nn as buildStellarGovernanceRevokeRoleImmediateTx,tn as buildStellarGovernanceSetOracleSanityBoundsImmediateTx,Qr as buildStellarGovernanceSetSpokeAssetFlagsImmediateTx,Pe as buildStellarGrantRoleTx,Rn as buildStellarLendingIdentifier,vt as buildStellarLiquidateTx,_t as buildStellarMigrateFromBlendTx,Oe as buildStellarMigrateTx,Bt as buildStellarMultiplyTx,Ce as buildStellarPauseTx,vr as buildStellarProposeAddAssetToSpokeTx,wr as buildStellarProposeAddSpokeTx,Ar as buildStellarProposeApproveBlendPoolTx,Rr as buildStellarProposeApproveTokenTx,Zr as buildStellarProposeCancellerResetTx,Pr as buildStellarProposeConfigureAssetOracleTx,yr as buildStellarProposeCreateHubTx,qr as buildStellarProposeCreateLiquidityPoolTx,Ur as buildStellarProposeDeployPoolTx,Ir as buildStellarProposeEditAssetInSpokeTx,Lr as buildStellarProposeEditOracleToleranceTx,Mr as buildStellarProposeGovernanceUpgradeTx,Wr as buildStellarProposeGrantGovernanceRoleTx,Cr as buildStellarProposeMigrateControllerTx,Sr as buildStellarProposeRemoveAssetFromSpokeTx,br as buildStellarProposeRemoveSpokeTx,xr as buildStellarProposeRevokeBlendPoolTx,Fr as buildStellarProposeRevokeGovernanceRoleTx,kr as buildStellarProposeRevokeTokenTx,mr as buildStellarProposeSetAccumulatorTx,Er as buildStellarProposeSetMinBorrowCollatTx,gr as buildStellarProposeSetPositionLimitsTx,Br as buildStellarProposeSetPositionManagerTx,hr as buildStellarProposeSetPriceAggregatorTx,_r as buildStellarProposeSetSpokeLiquidationCurveTx,fr as buildStellarProposeSetSwapAggregatorTx,Nr as buildStellarProposeTransferCtrlOwnershipTx,zr as buildStellarProposeTransferGovOwnTx,sn as buildStellarProposeUnpauseTx,Dr as buildStellarProposeUpdateDelayTx,Or as buildStellarProposeUpgradeControllerTx,Tr as buildStellarProposeUpgradePoolParamsTx,$r as buildStellarProposeUpgradePoolTx,Je as buildStellarRenewAccountTx,wt as buildStellarRepayBatchTx,kt as buildStellarRepayDebtWithCollateralTx,bt as buildStellarRepayTx,je as buildStellarRevokeBlendPoolTx,Le as buildStellarRevokeRoleTx,ze as buildStellarSetAccumulatorTx,Ye as buildStellarSetOracleSanityBoundsTx,He as buildStellarSetOracleToleranceTx,Ge as buildStellarSetOracleTx,Ve as buildStellarSetPositionLimitsTx,Fe as buildStellarSetPriceAggregatorTx,Ke as buildStellarSetSpokeAssetFlagsTx,We as buildStellarSetSwapAggregatorTx,dt as buildStellarSupplyBatchTx,ft as buildStellarSupplyTx,Rt as buildStellarSwapCollateralTx,Et as buildStellarSwapDebtTx,Me as buildStellarTransferOwnershipTx,Ne as buildStellarUnpauseTx,nr as buildStellarUpdateAccountThresholdTx,Ze as buildStellarUpdateIndexesTx,$e as buildStellarUpgradeControllerTx,tr as buildStellarUpgradeLiquidityPoolParamsTx,gt as buildStellarWithdrawBatchTx,yt as buildStellarWithdrawTx,ct as buildTx,ws as burnShares,Bs as computeAccountRisk,Bn as decodeStellarLendingEvent,It as decodeStellarLiquidateReturn,jn as decodeStellarRouteBytes,eo as decodeStellarSwapEnvelope,os as depositRateRay,Co as divByIntHalfUp,Ue as encodeAssetOracle,Ie as encodeInterestRateModel,Se as encodeMarketParamsRaw,_e as encodePositionLimits,Be as encodePriceKey,Yn as encodeStrategyPayloadToRouteXdr,kn as extractEventOrder,Ft as getStellarAccountPositions,de as getStellarActiveUsersSeries,Tn as getStellarAggregatorQuote,Lt as getStellarAsset,Kt as getStellarAssetGraph,Xt as getStellarAssetMarkets,Vt as getStellarAssetPage,$t as getStellarAssets,ie as getStellarCampaignLeaderboard,we as getStellarCampaignMe,he as getStellarDefiLlamaDimensions,_ as getStellarDeployment,Ut as getStellarDetailedMarkets,le as getStellarFeeRevenueSeries,ee as getStellarGovernanceProposals,se as getStellarHolderDistribution,Mt as getStellarHub,Yt as getStellarHubGraph,Gt as getStellarHubHolders,Ot as getStellarHubs,qt as getStellarLendingContext,Tt as getStellarLendingLiveState,oe as getStellarLiquidationsLeaderboard,ce as getStellarLiquidationsSeries,ne as getStellarParticipantCounts,ye as getStellarPnlByScope,re as getStellarPositionsLeaderboard,ge as getStellarPositionsPnl,Un as getStellarQuoteTokens,fe as getStellarRateSpreadSeries,Pt as getStellarReserve,Jt as getStellarReserveGraph,jt as getStellarReserveHolders,Nt as getStellarReserves,ue as getStellarRevenueSeries,Dt as getStellarSpoke,Zt as getStellarSpokeGraph,Ht as getStellarSpokeHolders,Ct as getStellarSpokes,ae as getStellarStatsHistory,Qt as getStellarUserActivity,te as getStellarUserActivityPage,me as getStellarUserHistory,Wt as getStellarUserPositions,pe as getStellarVolumeSeries,zt as getStellarWalletBalance,ds as liveIndexKey,Jn as mapQuoteResponseToStrategyPayload,Qn as mapQuoteResponseToStrategySwap,Vs as mapSorobanError,xn as mapStellarPositionActivityType,Os as maxBorrow,Ps as maxRepay,Ns as maxSupply,Cs as maxWithdraw,ys as mintShares,$o as mulDivCeil,Uo as mulDivFloor,Oo as mulDivHalfUp,Jo as numberToScaled,Qo as numberToWad,lt as parseStellarTokenAmount,Go as positionValueWad,Io as prepareStellarBuiltTx,vo as prepareStellarTxXdr,Ds as projectAccountRisk,Fs as projectReserveApy,is as rayAprToApy,ss as rayAprToNumber,Yo as rayToNumber,Lo as rescaleCeil,Po as rescaleFloor,Mo as rescaleHalfUp,us as reserveKey,ls as resolveReserve,go as stellarAuthPolicyForInvocation,ln as stellarLendingDispatchKey,be as stellarLendingRead,S as stellarNetworks,Gn as stellarTokenContractId,An as syntheticEventOrder,bo as tagStellarInvokedContractError,an as toBase64Xdr,To as toBigInt,So as toStellarPositionMode,Fo as unscale,Vo as unscaleBorrowCeil,Xo as unscaleHalfUp,zo as unscaleSupplyFloor,rs as utilizationRay,bs as valueBasePosition,gs as valueScaledPosition,Kn as verifyStellarRouteBytes,Ko as wadToNumber};export const createStellarLendingReadClient=ve.gm;export const lendingAssetsSchema=ve.IY;export const lendingPositionsSchema=ve.Vd;
|