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