@msafe/sui-app-store 0.0.282 → 0.0.283

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.js CHANGED
@@ -1,2 +1,2 @@
1
- "use strict";var jp=Object.create;var Kn=Object.defineProperty;var Up=Object.getOwnPropertyDescriptor;var qp=Object.getOwnPropertyNames;var Fp=Object.getPrototypeOf,Kp=Object.prototype.hasOwnProperty;var $p=(i,e)=>()=>(e||i((e={exports:{}}).exports,e),e.exports),Vr=(i,e)=>{for(var t in e)Kn(i,t,{get:e[t],enumerable:!0})},rc=(i,e,t,n)=>{if(e&&typeof e=="object"||typeof e=="function")for(let o of qp(e))!Kp.call(i,o)&&o!==t&&Kn(i,o,{get:()=>e[o],enumerable:!(n=Up(e,o))||n.enumerable});return i};var Ut=(i,e,t)=>(t=i!=null?jp(Fp(i)):{},rc(e||!i||!i.__esModule?Kn(t,"default",{value:i,enumerable:!0}):t,i)),Vp=i=>rc(Kn({},"__esModule",{value:!0}),i);var cp=$p((sp,_s)=>{"use strict";(function(i,e){"use strict";function t(y,r){if(!y)throw new Error(r||"Assertion failed")}function n(y,r){y.super_=r;var u=function(){};u.prototype=r.prototype,y.prototype=new u,y.prototype.constructor=y}function o(y,r,u){if(o.isBN(y))return y;this.negative=0,this.words=null,this.length=0,this.red=null,y!==null&&((r==="le"||r==="be")&&(u=r,r=10),this._init(y||0,r||10,u||"be"))}typeof i=="object"?i.exports=o:e.BN=o,o.BN=o,o.wordSize=26;var a;try{typeof window<"u"&&typeof window.Buffer<"u"?a=window.Buffer:a=require("buffer").Buffer}catch{}o.isBN=function(r){return r instanceof o?!0:r!==null&&typeof r=="object"&&r.constructor.wordSize===o.wordSize&&Array.isArray(r.words)},o.max=function(r,u){return r.cmp(u)>0?r:u},o.min=function(r,u){return r.cmp(u)<0?r:u},o.prototype._init=function(r,u,m){if(typeof r=="number")return this._initNumber(r,u,m);if(typeof r=="object")return this._initArray(r,u,m);u==="hex"&&(u=16),t(u===(u|0)&&u>=2&&u<=36),r=r.toString().replace(/\s+/g,"");var p=0;r[0]==="-"&&(p++,this.negative=1),p<r.length&&(u===16?this._parseHex(r,p,m):(this._parseBase(r,u,p),m==="le"&&this._initArray(this.toArray(),u,m)))},o.prototype._initNumber=function(r,u,m){r<0&&(this.negative=1,r=-r),r<67108864?(this.words=[r&67108863],this.length=1):r<4503599627370496?(this.words=[r&67108863,r/67108864&67108863],this.length=2):(t(r<9007199254740992),this.words=[r&67108863,r/67108864&67108863,1],this.length=3),m==="le"&&this._initArray(this.toArray(),u,m)},o.prototype._initArray=function(r,u,m){if(t(typeof r.length=="number"),r.length<=0)return this.words=[0],this.length=1,this;this.length=Math.ceil(r.length/3),this.words=new Array(this.length);for(var p=0;p<this.length;p++)this.words[p]=0;var h,S,T=0;if(m==="be")for(p=r.length-1,h=0;p>=0;p-=3)S=r[p]|r[p-1]<<8|r[p-2]<<16,this.words[h]|=S<<T&67108863,this.words[h+1]=S>>>26-T&67108863,T+=24,T>=26&&(T-=26,h++);else if(m==="le")for(p=0,h=0;p<r.length;p+=3)S=r[p]|r[p+1]<<8|r[p+2]<<16,this.words[h]|=S<<T&67108863,this.words[h+1]=S>>>26-T&67108863,T+=24,T>=26&&(T-=26,h++);return this._strip()};function c(y,r){var u=y.charCodeAt(r);if(u>=48&&u<=57)return u-48;if(u>=65&&u<=70)return u-55;if(u>=97&&u<=102)return u-87;t(!1,"Invalid character in "+y)}function l(y,r,u){var m=c(y,u);return u-1>=r&&(m|=c(y,u-1)<<4),m}o.prototype._parseHex=function(r,u,m){this.length=Math.ceil((r.length-u)/6),this.words=new Array(this.length);for(var p=0;p<this.length;p++)this.words[p]=0;var h=0,S=0,T;if(m==="be")for(p=r.length-1;p>=u;p-=2)T=l(r,u,p)<<h,this.words[S]|=T&67108863,h>=18?(h-=18,S+=1,this.words[S]|=T>>>26):h+=8;else{var f=r.length-u;for(p=f%2===0?u+1:u;p<r.length;p+=2)T=l(r,u,p)<<h,this.words[S]|=T&67108863,h>=18?(h-=18,S+=1,this.words[S]|=T>>>26):h+=8}this._strip()};function d(y,r,u,m){for(var p=0,h=0,S=Math.min(y.length,u),T=r;T<S;T++){var f=y.charCodeAt(T)-48;p*=m,f>=49?h=f-49+10:f>=17?h=f-17+10:h=f,t(f>=0&&h<m,"Invalid character"),p+=h}return p}o.prototype._parseBase=function(r,u,m){this.words=[0],this.length=1;for(var p=0,h=1;h<=67108863;h*=u)p++;p--,h=h/u|0;for(var S=r.length-m,T=S%p,f=Math.min(S,S-T)+m,s=0,g=m;g<f;g+=p)s=d(r,g,g+p,u),this.imuln(h),this.words[0]+s<67108864?this.words[0]+=s:this._iaddn(s);if(T!==0){var x=1;for(s=d(r,g,r.length,u),g=0;g<T;g++)x*=u;this.imuln(x),this.words[0]+s<67108864?this.words[0]+=s:this._iaddn(s)}this._strip()},o.prototype.copy=function(r){r.words=new Array(this.length);for(var u=0;u<this.length;u++)r.words[u]=this.words[u];r.length=this.length,r.negative=this.negative,r.red=this.red};function b(y,r){y.words=r.words,y.length=r.length,y.negative=r.negative,y.red=r.red}if(o.prototype._move=function(r){b(r,this)},o.prototype.clone=function(){var r=new o(null);return this.copy(r),r},o.prototype._expand=function(r){for(;this.length<r;)this.words[this.length++]=0;return this},o.prototype._strip=function(){for(;this.length>1&&this.words[this.length-1]===0;)this.length--;return this._normSign()},o.prototype._normSign=function(){return this.length===1&&this.words[0]===0&&(this.negative=0),this},typeof Symbol<"u"&&typeof Symbol.for=="function")try{o.prototype[Symbol.for("nodejs.util.inspect.custom")]=w}catch{o.prototype.inspect=w}else o.prototype.inspect=w;function w(){return(this.red?"<BN-R: ":"<BN: ")+this.toString(16)+">"}var I=["","0","00","000","0000","00000","000000","0000000","00000000","000000000","0000000000","00000000000","000000000000","0000000000000","00000000000000","000000000000000","0000000000000000","00000000000000000","000000000000000000","0000000000000000000","00000000000000000000","000000000000000000000","0000000000000000000000","00000000000000000000000","000000000000000000000000","0000000000000000000000000"],k=[0,0,25,16,12,11,10,9,8,8,7,7,7,7,6,6,6,6,6,6,6,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5],v=[0,0,33554432,43046721,16777216,48828125,60466176,40353607,16777216,43046721,1e7,19487171,35831808,62748517,7529536,11390625,16777216,24137569,34012224,47045881,64e6,4084101,5153632,6436343,7962624,9765625,11881376,14348907,17210368,20511149,243e5,28629151,33554432,39135393,45435424,52521875,60466176];o.prototype.toString=function(r,u){r=r||10,u=u|0||1;var m;if(r===16||r==="hex"){m="";for(var p=0,h=0,S=0;S<this.length;S++){var T=this.words[S],f=((T<<p|h)&16777215).toString(16);h=T>>>24-p&16777215,p+=2,p>=26&&(p-=26,S--),h!==0||S!==this.length-1?m=I[6-f.length]+f+m:m=f+m}for(h!==0&&(m=h.toString(16)+m);m.length%u!==0;)m="0"+m;return this.negative!==0&&(m="-"+m),m}if(r===(r|0)&&r>=2&&r<=36){var s=k[r],g=v[r];m="";var x=this.clone();for(x.negative=0;!x.isZero();){var M=x.modrn(g).toString(r);x=x.idivn(g),x.isZero()?m=M+m:m=I[s-M.length]+M+m}for(this.isZero()&&(m="0"+m);m.length%u!==0;)m="0"+m;return this.negative!==0&&(m="-"+m),m}t(!1,"Base should be between 2 and 36")},o.prototype.toNumber=function(){var r=this.words[0];return this.length===2?r+=this.words[1]*67108864:this.length===3&&this.words[2]===1?r+=4503599627370496+this.words[1]*67108864:this.length>2&&t(!1,"Number can only safely store up to 53 bits"),this.negative!==0?-r:r},o.prototype.toJSON=function(){return this.toString(16,2)},a&&(o.prototype.toBuffer=function(r,u){return this.toArrayLike(a,r,u)}),o.prototype.toArray=function(r,u){return this.toArrayLike(Array,r,u)};var D=function(r,u){return r.allocUnsafe?r.allocUnsafe(u):new r(u)};o.prototype.toArrayLike=function(r,u,m){this._strip();var p=this.byteLength(),h=m||Math.max(1,p);t(p<=h,"byte array longer than desired length"),t(h>0,"Requested array length <= 0");var S=D(r,h),T=u==="le"?"LE":"BE";return this["_toArrayLike"+T](S,p),S},o.prototype._toArrayLikeLE=function(r,u){for(var m=0,p=0,h=0,S=0;h<this.length;h++){var T=this.words[h]<<S|p;r[m++]=T&255,m<r.length&&(r[m++]=T>>8&255),m<r.length&&(r[m++]=T>>16&255),S===6?(m<r.length&&(r[m++]=T>>24&255),p=0,S=0):(p=T>>>24,S+=2)}if(m<r.length)for(r[m++]=p;m<r.length;)r[m++]=0},o.prototype._toArrayLikeBE=function(r,u){for(var m=r.length-1,p=0,h=0,S=0;h<this.length;h++){var T=this.words[h]<<S|p;r[m--]=T&255,m>=0&&(r[m--]=T>>8&255),m>=0&&(r[m--]=T>>16&255),S===6?(m>=0&&(r[m--]=T>>24&255),p=0,S=0):(p=T>>>24,S+=2)}if(m>=0)for(r[m--]=p;m>=0;)r[m--]=0},Math.clz32?o.prototype._countBits=function(r){return 32-Math.clz32(r)}:o.prototype._countBits=function(r){var u=r,m=0;return u>=4096&&(m+=13,u>>>=13),u>=64&&(m+=7,u>>>=7),u>=8&&(m+=4,u>>>=4),u>=2&&(m+=2,u>>>=2),m+u},o.prototype._zeroBits=function(r){if(r===0)return 26;var u=r,m=0;return u&8191||(m+=13,u>>>=13),u&127||(m+=7,u>>>=7),u&15||(m+=4,u>>>=4),u&3||(m+=2,u>>>=2),u&1||m++,m},o.prototype.bitLength=function(){var r=this.words[this.length-1],u=this._countBits(r);return(this.length-1)*26+u};function P(y){for(var r=new Array(y.bitLength()),u=0;u<r.length;u++){var m=u/26|0,p=u%26;r[u]=y.words[m]>>>p&1}return r}o.prototype.zeroBits=function(){if(this.isZero())return 0;for(var r=0,u=0;u<this.length;u++){var m=this._zeroBits(this.words[u]);if(r+=m,m!==26)break}return r},o.prototype.byteLength=function(){return Math.ceil(this.bitLength()/8)},o.prototype.toTwos=function(r){return this.negative!==0?this.abs().inotn(r).iaddn(1):this.clone()},o.prototype.fromTwos=function(r){return this.testn(r-1)?this.notn(r).iaddn(1).ineg():this.clone()},o.prototype.isNeg=function(){return this.negative!==0},o.prototype.neg=function(){return this.clone().ineg()},o.prototype.ineg=function(){return this.isZero()||(this.negative^=1),this},o.prototype.iuor=function(r){for(;this.length<r.length;)this.words[this.length++]=0;for(var u=0;u<r.length;u++)this.words[u]=this.words[u]|r.words[u];return this._strip()},o.prototype.ior=function(r){return t((this.negative|r.negative)===0),this.iuor(r)},o.prototype.or=function(r){return this.length>r.length?this.clone().ior(r):r.clone().ior(this)},o.prototype.uor=function(r){return this.length>r.length?this.clone().iuor(r):r.clone().iuor(this)},o.prototype.iuand=function(r){var u;this.length>r.length?u=r:u=this;for(var m=0;m<u.length;m++)this.words[m]=this.words[m]&r.words[m];return this.length=u.length,this._strip()},o.prototype.iand=function(r){return t((this.negative|r.negative)===0),this.iuand(r)},o.prototype.and=function(r){return this.length>r.length?this.clone().iand(r):r.clone().iand(this)},o.prototype.uand=function(r){return this.length>r.length?this.clone().iuand(r):r.clone().iuand(this)},o.prototype.iuxor=function(r){var u,m;this.length>r.length?(u=this,m=r):(u=r,m=this);for(var p=0;p<m.length;p++)this.words[p]=u.words[p]^m.words[p];if(this!==u)for(;p<u.length;p++)this.words[p]=u.words[p];return this.length=u.length,this._strip()},o.prototype.ixor=function(r){return t((this.negative|r.negative)===0),this.iuxor(r)},o.prototype.xor=function(r){return this.length>r.length?this.clone().ixor(r):r.clone().ixor(this)},o.prototype.uxor=function(r){return this.length>r.length?this.clone().iuxor(r):r.clone().iuxor(this)},o.prototype.inotn=function(r){t(typeof r=="number"&&r>=0);var u=Math.ceil(r/26)|0,m=r%26;this._expand(u),m>0&&u--;for(var p=0;p<u;p++)this.words[p]=~this.words[p]&67108863;return m>0&&(this.words[p]=~this.words[p]&67108863>>26-m),this._strip()},o.prototype.notn=function(r){return this.clone().inotn(r)},o.prototype.setn=function(r,u){t(typeof r=="number"&&r>=0);var m=r/26|0,p=r%26;return this._expand(m+1),u?this.words[m]=this.words[m]|1<<p:this.words[m]=this.words[m]&~(1<<p),this._strip()},o.prototype.iadd=function(r){var u;if(this.negative!==0&&r.negative===0)return this.negative=0,u=this.isub(r),this.negative^=1,this._normSign();if(this.negative===0&&r.negative!==0)return r.negative=0,u=this.isub(r),r.negative=1,u._normSign();var m,p;this.length>r.length?(m=this,p=r):(m=r,p=this);for(var h=0,S=0;S<p.length;S++)u=(m.words[S]|0)+(p.words[S]|0)+h,this.words[S]=u&67108863,h=u>>>26;for(;h!==0&&S<m.length;S++)u=(m.words[S]|0)+h,this.words[S]=u&67108863,h=u>>>26;if(this.length=m.length,h!==0)this.words[this.length]=h,this.length++;else if(m!==this)for(;S<m.length;S++)this.words[S]=m.words[S];return this},o.prototype.add=function(r){var u;return r.negative!==0&&this.negative===0?(r.negative=0,u=this.sub(r),r.negative^=1,u):r.negative===0&&this.negative!==0?(this.negative=0,u=r.sub(this),this.negative=1,u):this.length>r.length?this.clone().iadd(r):r.clone().iadd(this)},o.prototype.isub=function(r){if(r.negative!==0){r.negative=0;var u=this.iadd(r);return r.negative=1,u._normSign()}else if(this.negative!==0)return this.negative=0,this.iadd(r),this.negative=1,this._normSign();var m=this.cmp(r);if(m===0)return this.negative=0,this.length=1,this.words[0]=0,this;var p,h;m>0?(p=this,h=r):(p=r,h=this);for(var S=0,T=0;T<h.length;T++)u=(p.words[T]|0)-(h.words[T]|0)+S,S=u>>26,this.words[T]=u&67108863;for(;S!==0&&T<p.length;T++)u=(p.words[T]|0)+S,S=u>>26,this.words[T]=u&67108863;if(S===0&&T<p.length&&p!==this)for(;T<p.length;T++)this.words[T]=p.words[T];return this.length=Math.max(this.length,T),p!==this&&(this.negative=1),this._strip()},o.prototype.sub=function(r){return this.clone().isub(r)};function K(y,r,u){u.negative=r.negative^y.negative;var m=y.length+r.length|0;u.length=m,m=m-1|0;var p=y.words[0]|0,h=r.words[0]|0,S=p*h,T=S&67108863,f=S/67108864|0;u.words[0]=T;for(var s=1;s<m;s++){for(var g=f>>>26,x=f&67108863,M=Math.min(s,r.length-1),O=Math.max(0,s-y.length+1);O<=M;O++){var B=s-O|0;p=y.words[B]|0,h=r.words[O]|0,S=p*h+x,g+=S/67108864|0,x=S&67108863}u.words[s]=x|0,f=g|0}return f!==0?u.words[s]=f|0:u.length--,u._strip()}var H=function(r,u,m){var p=r.words,h=u.words,S=m.words,T=0,f,s,g,x=p[0]|0,M=x&8191,O=x>>>13,B=p[1]|0,W=B&8191,j=B>>>13,re=p[2]|0,U=re&8191,q=re>>>13,Ks=p[3]|0,X=Ks&8191,z=Ks>>>13,$s=p[4]|0,G=$s&8191,Q=$s>>>13,Vs=p[5]|0,J=Vs&8191,Y=Vs>>>13,Hs=p[6]|0,Z=Hs&8191,tt=Hs>>>13,Xs=p[7]|0,et=Xs&8191,nt=Xs>>>13,zs=p[8]|0,ot=zs&8191,at=zs>>>13,Gs=p[9]|0,it=Gs&8191,rt=Gs>>>13,Qs=h[0]|0,st=Qs&8191,ct=Qs>>>13,Js=h[1]|0,lt=Js&8191,ut=Js>>>13,Ys=h[2]|0,mt=Ys&8191,pt=Ys>>>13,Zs=h[3]|0,dt=Zs&8191,ft=Zs>>>13,tc=h[4]|0,ht=tc&8191,gt=tc>>>13,ec=h[5]|0,yt=ec&8191,bt=ec>>>13,nc=h[6]|0,St=nc&8191,Tt=nc>>>13,oc=h[7]|0,wt=oc&8191,It=oc>>>13,ac=h[8]|0,Ct=ac&8191,kt=ac>>>13,ic=h[9]|0,vt=ic&8191,Dt=ic>>>13;m.negative=r.negative^u.negative,m.length=19,f=Math.imul(M,st),s=Math.imul(M,ct),s=s+Math.imul(O,st)|0,g=Math.imul(O,ct);var Dr=(T+f|0)+((s&8191)<<13)|0;T=(g+(s>>>13)|0)+(Dr>>>26)|0,Dr&=67108863,f=Math.imul(W,st),s=Math.imul(W,ct),s=s+Math.imul(j,st)|0,g=Math.imul(j,ct),f=f+Math.imul(M,lt)|0,s=s+Math.imul(M,ut)|0,s=s+Math.imul(O,lt)|0,g=g+Math.imul(O,ut)|0;var xr=(T+f|0)+((s&8191)<<13)|0;T=(g+(s>>>13)|0)+(xr>>>26)|0,xr&=67108863,f=Math.imul(U,st),s=Math.imul(U,ct),s=s+Math.imul(q,st)|0,g=Math.imul(q,ct),f=f+Math.imul(W,lt)|0,s=s+Math.imul(W,ut)|0,s=s+Math.imul(j,lt)|0,g=g+Math.imul(j,ut)|0,f=f+Math.imul(M,mt)|0,s=s+Math.imul(M,pt)|0,s=s+Math.imul(O,mt)|0,g=g+Math.imul(O,pt)|0;var Ar=(T+f|0)+((s&8191)<<13)|0;T=(g+(s>>>13)|0)+(Ar>>>26)|0,Ar&=67108863,f=Math.imul(X,st),s=Math.imul(X,ct),s=s+Math.imul(z,st)|0,g=Math.imul(z,ct),f=f+Math.imul(U,lt)|0,s=s+Math.imul(U,ut)|0,s=s+Math.imul(q,lt)|0,g=g+Math.imul(q,ut)|0,f=f+Math.imul(W,mt)|0,s=s+Math.imul(W,pt)|0,s=s+Math.imul(j,mt)|0,g=g+Math.imul(j,pt)|0,f=f+Math.imul(M,dt)|0,s=s+Math.imul(M,ft)|0,s=s+Math.imul(O,dt)|0,g=g+Math.imul(O,ft)|0;var Mr=(T+f|0)+((s&8191)<<13)|0;T=(g+(s>>>13)|0)+(Mr>>>26)|0,Mr&=67108863,f=Math.imul(G,st),s=Math.imul(G,ct),s=s+Math.imul(Q,st)|0,g=Math.imul(Q,ct),f=f+Math.imul(X,lt)|0,s=s+Math.imul(X,ut)|0,s=s+Math.imul(z,lt)|0,g=g+Math.imul(z,ut)|0,f=f+Math.imul(U,mt)|0,s=s+Math.imul(U,pt)|0,s=s+Math.imul(q,mt)|0,g=g+Math.imul(q,pt)|0,f=f+Math.imul(W,dt)|0,s=s+Math.imul(W,ft)|0,s=s+Math.imul(j,dt)|0,g=g+Math.imul(j,ft)|0,f=f+Math.imul(M,ht)|0,s=s+Math.imul(M,gt)|0,s=s+Math.imul(O,ht)|0,g=g+Math.imul(O,gt)|0;var Or=(T+f|0)+((s&8191)<<13)|0;T=(g+(s>>>13)|0)+(Or>>>26)|0,Or&=67108863,f=Math.imul(J,st),s=Math.imul(J,ct),s=s+Math.imul(Y,st)|0,g=Math.imul(Y,ct),f=f+Math.imul(G,lt)|0,s=s+Math.imul(G,ut)|0,s=s+Math.imul(Q,lt)|0,g=g+Math.imul(Q,ut)|0,f=f+Math.imul(X,mt)|0,s=s+Math.imul(X,pt)|0,s=s+Math.imul(z,mt)|0,g=g+Math.imul(z,pt)|0,f=f+Math.imul(U,dt)|0,s=s+Math.imul(U,ft)|0,s=s+Math.imul(q,dt)|0,g=g+Math.imul(q,ft)|0,f=f+Math.imul(W,ht)|0,s=s+Math.imul(W,gt)|0,s=s+Math.imul(j,ht)|0,g=g+Math.imul(j,gt)|0,f=f+Math.imul(M,yt)|0,s=s+Math.imul(M,bt)|0,s=s+Math.imul(O,yt)|0,g=g+Math.imul(O,bt)|0;var Pr=(T+f|0)+((s&8191)<<13)|0;T=(g+(s>>>13)|0)+(Pr>>>26)|0,Pr&=67108863,f=Math.imul(Z,st),s=Math.imul(Z,ct),s=s+Math.imul(tt,st)|0,g=Math.imul(tt,ct),f=f+Math.imul(J,lt)|0,s=s+Math.imul(J,ut)|0,s=s+Math.imul(Y,lt)|0,g=g+Math.imul(Y,ut)|0,f=f+Math.imul(G,mt)|0,s=s+Math.imul(G,pt)|0,s=s+Math.imul(Q,mt)|0,g=g+Math.imul(Q,pt)|0,f=f+Math.imul(X,dt)|0,s=s+Math.imul(X,ft)|0,s=s+Math.imul(z,dt)|0,g=g+Math.imul(z,ft)|0,f=f+Math.imul(U,ht)|0,s=s+Math.imul(U,gt)|0,s=s+Math.imul(q,ht)|0,g=g+Math.imul(q,gt)|0,f=f+Math.imul(W,yt)|0,s=s+Math.imul(W,bt)|0,s=s+Math.imul(j,yt)|0,g=g+Math.imul(j,bt)|0,f=f+Math.imul(M,St)|0,s=s+Math.imul(M,Tt)|0,s=s+Math.imul(O,St)|0,g=g+Math.imul(O,Tt)|0;var Rr=(T+f|0)+((s&8191)<<13)|0;T=(g+(s>>>13)|0)+(Rr>>>26)|0,Rr&=67108863,f=Math.imul(et,st),s=Math.imul(et,ct),s=s+Math.imul(nt,st)|0,g=Math.imul(nt,ct),f=f+Math.imul(Z,lt)|0,s=s+Math.imul(Z,ut)|0,s=s+Math.imul(tt,lt)|0,g=g+Math.imul(tt,ut)|0,f=f+Math.imul(J,mt)|0,s=s+Math.imul(J,pt)|0,s=s+Math.imul(Y,mt)|0,g=g+Math.imul(Y,pt)|0,f=f+Math.imul(G,dt)|0,s=s+Math.imul(G,ft)|0,s=s+Math.imul(Q,dt)|0,g=g+Math.imul(Q,ft)|0,f=f+Math.imul(X,ht)|0,s=s+Math.imul(X,gt)|0,s=s+Math.imul(z,ht)|0,g=g+Math.imul(z,gt)|0,f=f+Math.imul(U,yt)|0,s=s+Math.imul(U,bt)|0,s=s+Math.imul(q,yt)|0,g=g+Math.imul(q,bt)|0,f=f+Math.imul(W,St)|0,s=s+Math.imul(W,Tt)|0,s=s+Math.imul(j,St)|0,g=g+Math.imul(j,Tt)|0,f=f+Math.imul(M,wt)|0,s=s+Math.imul(M,It)|0,s=s+Math.imul(O,wt)|0,g=g+Math.imul(O,It)|0;var Br=(T+f|0)+((s&8191)<<13)|0;T=(g+(s>>>13)|0)+(Br>>>26)|0,Br&=67108863,f=Math.imul(ot,st),s=Math.imul(ot,ct),s=s+Math.imul(at,st)|0,g=Math.imul(at,ct),f=f+Math.imul(et,lt)|0,s=s+Math.imul(et,ut)|0,s=s+Math.imul(nt,lt)|0,g=g+Math.imul(nt,ut)|0,f=f+Math.imul(Z,mt)|0,s=s+Math.imul(Z,pt)|0,s=s+Math.imul(tt,mt)|0,g=g+Math.imul(tt,pt)|0,f=f+Math.imul(J,dt)|0,s=s+Math.imul(J,ft)|0,s=s+Math.imul(Y,dt)|0,g=g+Math.imul(Y,ft)|0,f=f+Math.imul(G,ht)|0,s=s+Math.imul(G,gt)|0,s=s+Math.imul(Q,ht)|0,g=g+Math.imul(Q,gt)|0,f=f+Math.imul(X,yt)|0,s=s+Math.imul(X,bt)|0,s=s+Math.imul(z,yt)|0,g=g+Math.imul(z,bt)|0,f=f+Math.imul(U,St)|0,s=s+Math.imul(U,Tt)|0,s=s+Math.imul(q,St)|0,g=g+Math.imul(q,Tt)|0,f=f+Math.imul(W,wt)|0,s=s+Math.imul(W,It)|0,s=s+Math.imul(j,wt)|0,g=g+Math.imul(j,It)|0,f=f+Math.imul(M,Ct)|0,s=s+Math.imul(M,kt)|0,s=s+Math.imul(O,Ct)|0,g=g+Math.imul(O,kt)|0;var Er=(T+f|0)+((s&8191)<<13)|0;T=(g+(s>>>13)|0)+(Er>>>26)|0,Er&=67108863,f=Math.imul(it,st),s=Math.imul(it,ct),s=s+Math.imul(rt,st)|0,g=Math.imul(rt,ct),f=f+Math.imul(ot,lt)|0,s=s+Math.imul(ot,ut)|0,s=s+Math.imul(at,lt)|0,g=g+Math.imul(at,ut)|0,f=f+Math.imul(et,mt)|0,s=s+Math.imul(et,pt)|0,s=s+Math.imul(nt,mt)|0,g=g+Math.imul(nt,pt)|0,f=f+Math.imul(Z,dt)|0,s=s+Math.imul(Z,ft)|0,s=s+Math.imul(tt,dt)|0,g=g+Math.imul(tt,ft)|0,f=f+Math.imul(J,ht)|0,s=s+Math.imul(J,gt)|0,s=s+Math.imul(Y,ht)|0,g=g+Math.imul(Y,gt)|0,f=f+Math.imul(G,yt)|0,s=s+Math.imul(G,bt)|0,s=s+Math.imul(Q,yt)|0,g=g+Math.imul(Q,bt)|0,f=f+Math.imul(X,St)|0,s=s+Math.imul(X,Tt)|0,s=s+Math.imul(z,St)|0,g=g+Math.imul(z,Tt)|0,f=f+Math.imul(U,wt)|0,s=s+Math.imul(U,It)|0,s=s+Math.imul(q,wt)|0,g=g+Math.imul(q,It)|0,f=f+Math.imul(W,Ct)|0,s=s+Math.imul(W,kt)|0,s=s+Math.imul(j,Ct)|0,g=g+Math.imul(j,kt)|0,f=f+Math.imul(M,vt)|0,s=s+Math.imul(M,Dt)|0,s=s+Math.imul(O,vt)|0,g=g+Math.imul(O,Dt)|0;var Nr=(T+f|0)+((s&8191)<<13)|0;T=(g+(s>>>13)|0)+(Nr>>>26)|0,Nr&=67108863,f=Math.imul(it,lt),s=Math.imul(it,ut),s=s+Math.imul(rt,lt)|0,g=Math.imul(rt,ut),f=f+Math.imul(ot,mt)|0,s=s+Math.imul(ot,pt)|0,s=s+Math.imul(at,mt)|0,g=g+Math.imul(at,pt)|0,f=f+Math.imul(et,dt)|0,s=s+Math.imul(et,ft)|0,s=s+Math.imul(nt,dt)|0,g=g+Math.imul(nt,ft)|0,f=f+Math.imul(Z,ht)|0,s=s+Math.imul(Z,gt)|0,s=s+Math.imul(tt,ht)|0,g=g+Math.imul(tt,gt)|0,f=f+Math.imul(J,yt)|0,s=s+Math.imul(J,bt)|0,s=s+Math.imul(Y,yt)|0,g=g+Math.imul(Y,bt)|0,f=f+Math.imul(G,St)|0,s=s+Math.imul(G,Tt)|0,s=s+Math.imul(Q,St)|0,g=g+Math.imul(Q,Tt)|0,f=f+Math.imul(X,wt)|0,s=s+Math.imul(X,It)|0,s=s+Math.imul(z,wt)|0,g=g+Math.imul(z,It)|0,f=f+Math.imul(U,Ct)|0,s=s+Math.imul(U,kt)|0,s=s+Math.imul(q,Ct)|0,g=g+Math.imul(q,kt)|0,f=f+Math.imul(W,vt)|0,s=s+Math.imul(W,Dt)|0,s=s+Math.imul(j,vt)|0,g=g+Math.imul(j,Dt)|0;var Wr=(T+f|0)+((s&8191)<<13)|0;T=(g+(s>>>13)|0)+(Wr>>>26)|0,Wr&=67108863,f=Math.imul(it,mt),s=Math.imul(it,pt),s=s+Math.imul(rt,mt)|0,g=Math.imul(rt,pt),f=f+Math.imul(ot,dt)|0,s=s+Math.imul(ot,ft)|0,s=s+Math.imul(at,dt)|0,g=g+Math.imul(at,ft)|0,f=f+Math.imul(et,ht)|0,s=s+Math.imul(et,gt)|0,s=s+Math.imul(nt,ht)|0,g=g+Math.imul(nt,gt)|0,f=f+Math.imul(Z,yt)|0,s=s+Math.imul(Z,bt)|0,s=s+Math.imul(tt,yt)|0,g=g+Math.imul(tt,bt)|0,f=f+Math.imul(J,St)|0,s=s+Math.imul(J,Tt)|0,s=s+Math.imul(Y,St)|0,g=g+Math.imul(Y,Tt)|0,f=f+Math.imul(G,wt)|0,s=s+Math.imul(G,It)|0,s=s+Math.imul(Q,wt)|0,g=g+Math.imul(Q,It)|0,f=f+Math.imul(X,Ct)|0,s=s+Math.imul(X,kt)|0,s=s+Math.imul(z,Ct)|0,g=g+Math.imul(z,kt)|0,f=f+Math.imul(U,vt)|0,s=s+Math.imul(U,Dt)|0,s=s+Math.imul(q,vt)|0,g=g+Math.imul(q,Dt)|0;var _r=(T+f|0)+((s&8191)<<13)|0;T=(g+(s>>>13)|0)+(_r>>>26)|0,_r&=67108863,f=Math.imul(it,dt),s=Math.imul(it,ft),s=s+Math.imul(rt,dt)|0,g=Math.imul(rt,ft),f=f+Math.imul(ot,ht)|0,s=s+Math.imul(ot,gt)|0,s=s+Math.imul(at,ht)|0,g=g+Math.imul(at,gt)|0,f=f+Math.imul(et,yt)|0,s=s+Math.imul(et,bt)|0,s=s+Math.imul(nt,yt)|0,g=g+Math.imul(nt,bt)|0,f=f+Math.imul(Z,St)|0,s=s+Math.imul(Z,Tt)|0,s=s+Math.imul(tt,St)|0,g=g+Math.imul(tt,Tt)|0,f=f+Math.imul(J,wt)|0,s=s+Math.imul(J,It)|0,s=s+Math.imul(Y,wt)|0,g=g+Math.imul(Y,It)|0,f=f+Math.imul(G,Ct)|0,s=s+Math.imul(G,kt)|0,s=s+Math.imul(Q,Ct)|0,g=g+Math.imul(Q,kt)|0,f=f+Math.imul(X,vt)|0,s=s+Math.imul(X,Dt)|0,s=s+Math.imul(z,vt)|0,g=g+Math.imul(z,Dt)|0;var Lr=(T+f|0)+((s&8191)<<13)|0;T=(g+(s>>>13)|0)+(Lr>>>26)|0,Lr&=67108863,f=Math.imul(it,ht),s=Math.imul(it,gt),s=s+Math.imul(rt,ht)|0,g=Math.imul(rt,gt),f=f+Math.imul(ot,yt)|0,s=s+Math.imul(ot,bt)|0,s=s+Math.imul(at,yt)|0,g=g+Math.imul(at,bt)|0,f=f+Math.imul(et,St)|0,s=s+Math.imul(et,Tt)|0,s=s+Math.imul(nt,St)|0,g=g+Math.imul(nt,Tt)|0,f=f+Math.imul(Z,wt)|0,s=s+Math.imul(Z,It)|0,s=s+Math.imul(tt,wt)|0,g=g+Math.imul(tt,It)|0,f=f+Math.imul(J,Ct)|0,s=s+Math.imul(J,kt)|0,s=s+Math.imul(Y,Ct)|0,g=g+Math.imul(Y,kt)|0,f=f+Math.imul(G,vt)|0,s=s+Math.imul(G,Dt)|0,s=s+Math.imul(Q,vt)|0,g=g+Math.imul(Q,Dt)|0;var jr=(T+f|0)+((s&8191)<<13)|0;T=(g+(s>>>13)|0)+(jr>>>26)|0,jr&=67108863,f=Math.imul(it,yt),s=Math.imul(it,bt),s=s+Math.imul(rt,yt)|0,g=Math.imul(rt,bt),f=f+Math.imul(ot,St)|0,s=s+Math.imul(ot,Tt)|0,s=s+Math.imul(at,St)|0,g=g+Math.imul(at,Tt)|0,f=f+Math.imul(et,wt)|0,s=s+Math.imul(et,It)|0,s=s+Math.imul(nt,wt)|0,g=g+Math.imul(nt,It)|0,f=f+Math.imul(Z,Ct)|0,s=s+Math.imul(Z,kt)|0,s=s+Math.imul(tt,Ct)|0,g=g+Math.imul(tt,kt)|0,f=f+Math.imul(J,vt)|0,s=s+Math.imul(J,Dt)|0,s=s+Math.imul(Y,vt)|0,g=g+Math.imul(Y,Dt)|0;var Ur=(T+f|0)+((s&8191)<<13)|0;T=(g+(s>>>13)|0)+(Ur>>>26)|0,Ur&=67108863,f=Math.imul(it,St),s=Math.imul(it,Tt),s=s+Math.imul(rt,St)|0,g=Math.imul(rt,Tt),f=f+Math.imul(ot,wt)|0,s=s+Math.imul(ot,It)|0,s=s+Math.imul(at,wt)|0,g=g+Math.imul(at,It)|0,f=f+Math.imul(et,Ct)|0,s=s+Math.imul(et,kt)|0,s=s+Math.imul(nt,Ct)|0,g=g+Math.imul(nt,kt)|0,f=f+Math.imul(Z,vt)|0,s=s+Math.imul(Z,Dt)|0,s=s+Math.imul(tt,vt)|0,g=g+Math.imul(tt,Dt)|0;var qr=(T+f|0)+((s&8191)<<13)|0;T=(g+(s>>>13)|0)+(qr>>>26)|0,qr&=67108863,f=Math.imul(it,wt),s=Math.imul(it,It),s=s+Math.imul(rt,wt)|0,g=Math.imul(rt,It),f=f+Math.imul(ot,Ct)|0,s=s+Math.imul(ot,kt)|0,s=s+Math.imul(at,Ct)|0,g=g+Math.imul(at,kt)|0,f=f+Math.imul(et,vt)|0,s=s+Math.imul(et,Dt)|0,s=s+Math.imul(nt,vt)|0,g=g+Math.imul(nt,Dt)|0;var Fr=(T+f|0)+((s&8191)<<13)|0;T=(g+(s>>>13)|0)+(Fr>>>26)|0,Fr&=67108863,f=Math.imul(it,Ct),s=Math.imul(it,kt),s=s+Math.imul(rt,Ct)|0,g=Math.imul(rt,kt),f=f+Math.imul(ot,vt)|0,s=s+Math.imul(ot,Dt)|0,s=s+Math.imul(at,vt)|0,g=g+Math.imul(at,Dt)|0;var Kr=(T+f|0)+((s&8191)<<13)|0;T=(g+(s>>>13)|0)+(Kr>>>26)|0,Kr&=67108863,f=Math.imul(it,vt),s=Math.imul(it,Dt),s=s+Math.imul(rt,vt)|0,g=Math.imul(rt,Dt);var $r=(T+f|0)+((s&8191)<<13)|0;return T=(g+(s>>>13)|0)+($r>>>26)|0,$r&=67108863,S[0]=Dr,S[1]=xr,S[2]=Ar,S[3]=Mr,S[4]=Or,S[5]=Pr,S[6]=Rr,S[7]=Br,S[8]=Er,S[9]=Nr,S[10]=Wr,S[11]=_r,S[12]=Lr,S[13]=jr,S[14]=Ur,S[15]=qr,S[16]=Fr,S[17]=Kr,S[18]=$r,T!==0&&(S[19]=T,m.length++),m};Math.imul||(H=K);function Et(y,r,u){u.negative=r.negative^y.negative,u.length=y.length+r.length;for(var m=0,p=0,h=0;h<u.length-1;h++){var S=p;p=0;for(var T=m&67108863,f=Math.min(h,r.length-1),s=Math.max(0,h-y.length+1);s<=f;s++){var g=h-s,x=y.words[g]|0,M=r.words[s]|0,O=x*M,B=O&67108863;S=S+(O/67108864|0)|0,B=B+T|0,T=B&67108863,S=S+(B>>>26)|0,p+=S>>>26,S&=67108863}u.words[h]=T,m=S,S=p}return m!==0?u.words[h]=m:u.length--,u._strip()}function Wt(y,r,u){return Et(y,r,u)}o.prototype.mulTo=function(r,u){var m,p=this.length+r.length;return this.length===10&&r.length===10?m=H(this,r,u):p<63?m=K(this,r,u):p<1024?m=Et(this,r,u):m=Wt(this,r,u),m};function Ot(y,r){this.x=y,this.y=r}Ot.prototype.makeRBT=function(r){for(var u=new Array(r),m=o.prototype._countBits(r)-1,p=0;p<r;p++)u[p]=this.revBin(p,m,r);return u},Ot.prototype.revBin=function(r,u,m){if(r===0||r===m-1)return r;for(var p=0,h=0;h<u;h++)p|=(r&1)<<u-h-1,r>>=1;return p},Ot.prototype.permute=function(r,u,m,p,h,S){for(var T=0;T<S;T++)p[T]=u[r[T]],h[T]=m[r[T]]},Ot.prototype.transform=function(r,u,m,p,h,S){this.permute(S,r,u,m,p,h);for(var T=1;T<h;T<<=1)for(var f=T<<1,s=Math.cos(2*Math.PI/f),g=Math.sin(2*Math.PI/f),x=0;x<h;x+=f)for(var M=s,O=g,B=0;B<T;B++){var W=m[x+B],j=p[x+B],re=m[x+B+T],U=p[x+B+T],q=M*re-O*U;U=M*U+O*re,re=q,m[x+B]=W+re,p[x+B]=j+U,m[x+B+T]=W-re,p[x+B+T]=j-U,B!==f&&(q=s*M-g*O,O=s*O+g*M,M=q)}},Ot.prototype.guessLen13b=function(r,u){var m=Math.max(u,r)|1,p=m&1,h=0;for(m=m/2|0;m;m=m>>>1)h++;return 1<<h+1+p},Ot.prototype.conjugate=function(r,u,m){if(!(m<=1))for(var p=0;p<m/2;p++){var h=r[p];r[p]=r[m-p-1],r[m-p-1]=h,h=u[p],u[p]=-u[m-p-1],u[m-p-1]=-h}},Ot.prototype.normalize13b=function(r,u){for(var m=0,p=0;p<u/2;p++){var h=Math.round(r[2*p+1]/u)*8192+Math.round(r[2*p]/u)+m;r[p]=h&67108863,h<67108864?m=0:m=h/67108864|0}return r},Ot.prototype.convert13b=function(r,u,m,p){for(var h=0,S=0;S<u;S++)h=h+(r[S]|0),m[2*S]=h&8191,h=h>>>13,m[2*S+1]=h&8191,h=h>>>13;for(S=2*u;S<p;++S)m[S]=0;t(h===0),t((h&-8192)===0)},Ot.prototype.stub=function(r){for(var u=new Array(r),m=0;m<r;m++)u[m]=0;return u},Ot.prototype.mulp=function(r,u,m){var p=2*this.guessLen13b(r.length,u.length),h=this.makeRBT(p),S=this.stub(p),T=new Array(p),f=new Array(p),s=new Array(p),g=new Array(p),x=new Array(p),M=new Array(p),O=m.words;O.length=p,this.convert13b(r.words,r.length,T,p),this.convert13b(u.words,u.length,g,p),this.transform(T,S,f,s,p,h),this.transform(g,S,x,M,p,h);for(var B=0;B<p;B++){var W=f[B]*x[B]-s[B]*M[B];s[B]=f[B]*M[B]+s[B]*x[B],f[B]=W}return this.conjugate(f,s,p),this.transform(f,s,O,S,p,h),this.conjugate(O,S,p),this.normalize13b(O,p),m.negative=r.negative^u.negative,m.length=r.length+u.length,m._strip()},o.prototype.mul=function(r){var u=new o(null);return u.words=new Array(this.length+r.length),this.mulTo(r,u)},o.prototype.mulf=function(r){var u=new o(null);return u.words=new Array(this.length+r.length),Wt(this,r,u)},o.prototype.imul=function(r){return this.clone().mulTo(r,this)},o.prototype.imuln=function(r){var u=r<0;u&&(r=-r),t(typeof r=="number"),t(r<67108864);for(var m=0,p=0;p<this.length;p++){var h=(this.words[p]|0)*r,S=(h&67108863)+(m&67108863);m>>=26,m+=h/67108864|0,m+=S>>>26,this.words[p]=S&67108863}return m!==0&&(this.words[p]=m,this.length++),u?this.ineg():this},o.prototype.muln=function(r){return this.clone().imuln(r)},o.prototype.sqr=function(){return this.mul(this)},o.prototype.isqr=function(){return this.imul(this.clone())},o.prototype.pow=function(r){var u=P(r);if(u.length===0)return new o(1);for(var m=this,p=0;p<u.length&&u[p]===0;p++,m=m.sqr());if(++p<u.length)for(var h=m.sqr();p<u.length;p++,h=h.sqr())u[p]!==0&&(m=m.mul(h));return m},o.prototype.iushln=function(r){t(typeof r=="number"&&r>=0);var u=r%26,m=(r-u)/26,p=67108863>>>26-u<<26-u,h;if(u!==0){var S=0;for(h=0;h<this.length;h++){var T=this.words[h]&p,f=(this.words[h]|0)-T<<u;this.words[h]=f|S,S=T>>>26-u}S&&(this.words[h]=S,this.length++)}if(m!==0){for(h=this.length-1;h>=0;h--)this.words[h+m]=this.words[h];for(h=0;h<m;h++)this.words[h]=0;this.length+=m}return this._strip()},o.prototype.ishln=function(r){return t(this.negative===0),this.iushln(r)},o.prototype.iushrn=function(r,u,m){t(typeof r=="number"&&r>=0);var p;u?p=(u-u%26)/26:p=0;var h=r%26,S=Math.min((r-h)/26,this.length),T=67108863^67108863>>>h<<h,f=m;if(p-=S,p=Math.max(0,p),f){for(var s=0;s<S;s++)f.words[s]=this.words[s];f.length=S}if(S!==0)if(this.length>S)for(this.length-=S,s=0;s<this.length;s++)this.words[s]=this.words[s+S];else this.words[0]=0,this.length=1;var g=0;for(s=this.length-1;s>=0&&(g!==0||s>=p);s--){var x=this.words[s]|0;this.words[s]=g<<26-h|x>>>h,g=x&T}return f&&g!==0&&(f.words[f.length++]=g),this.length===0&&(this.words[0]=0,this.length=1),this._strip()},o.prototype.ishrn=function(r,u,m){return t(this.negative===0),this.iushrn(r,u,m)},o.prototype.shln=function(r){return this.clone().ishln(r)},o.prototype.ushln=function(r){return this.clone().iushln(r)},o.prototype.shrn=function(r){return this.clone().ishrn(r)},o.prototype.ushrn=function(r){return this.clone().iushrn(r)},o.prototype.testn=function(r){t(typeof r=="number"&&r>=0);var u=r%26,m=(r-u)/26,p=1<<u;if(this.length<=m)return!1;var h=this.words[m];return!!(h&p)},o.prototype.imaskn=function(r){t(typeof r=="number"&&r>=0);var u=r%26,m=(r-u)/26;if(t(this.negative===0,"imaskn works only with positive numbers"),this.length<=m)return this;if(u!==0&&m++,this.length=Math.min(m,this.length),u!==0){var p=67108863^67108863>>>u<<u;this.words[this.length-1]&=p}return this._strip()},o.prototype.maskn=function(r){return this.clone().imaskn(r)},o.prototype.iaddn=function(r){return t(typeof r=="number"),t(r<67108864),r<0?this.isubn(-r):this.negative!==0?this.length===1&&(this.words[0]|0)<=r?(this.words[0]=r-(this.words[0]|0),this.negative=0,this):(this.negative=0,this.isubn(r),this.negative=1,this):this._iaddn(r)},o.prototype._iaddn=function(r){this.words[0]+=r;for(var u=0;u<this.length&&this.words[u]>=67108864;u++)this.words[u]-=67108864,u===this.length-1?this.words[u+1]=1:this.words[u+1]++;return this.length=Math.max(this.length,u+1),this},o.prototype.isubn=function(r){if(t(typeof r=="number"),t(r<67108864),r<0)return this.iaddn(-r);if(this.negative!==0)return this.negative=0,this.iaddn(r),this.negative=1,this;if(this.words[0]-=r,this.length===1&&this.words[0]<0)this.words[0]=-this.words[0],this.negative=1;else for(var u=0;u<this.length&&this.words[u]<0;u++)this.words[u]+=67108864,this.words[u+1]-=1;return this._strip()},o.prototype.addn=function(r){return this.clone().iaddn(r)},o.prototype.subn=function(r){return this.clone().isubn(r)},o.prototype.iabs=function(){return this.negative=0,this},o.prototype.abs=function(){return this.clone().iabs()},o.prototype._ishlnsubmul=function(r,u,m){var p=r.length+m,h;this._expand(p);var S,T=0;for(h=0;h<r.length;h++){S=(this.words[h+m]|0)+T;var f=(r.words[h]|0)*u;S-=f&67108863,T=(S>>26)-(f/67108864|0),this.words[h+m]=S&67108863}for(;h<this.length-m;h++)S=(this.words[h+m]|0)+T,T=S>>26,this.words[h+m]=S&67108863;if(T===0)return this._strip();for(t(T===-1),T=0,h=0;h<this.length;h++)S=-(this.words[h]|0)+T,T=S>>26,this.words[h]=S&67108863;return this.negative=1,this._strip()},o.prototype._wordDiv=function(r,u){var m=this.length-r.length,p=this.clone(),h=r,S=h.words[h.length-1]|0,T=this._countBits(S);m=26-T,m!==0&&(h=h.ushln(m),p.iushln(m),S=h.words[h.length-1]|0);var f=p.length-h.length,s;if(u!=="mod"){s=new o(null),s.length=f+1,s.words=new Array(s.length);for(var g=0;g<s.length;g++)s.words[g]=0}var x=p.clone()._ishlnsubmul(h,1,f);x.negative===0&&(p=x,s&&(s.words[f]=1));for(var M=f-1;M>=0;M--){var O=(p.words[h.length+M]|0)*67108864+(p.words[h.length+M-1]|0);for(O=Math.min(O/S|0,67108863),p._ishlnsubmul(h,O,M);p.negative!==0;)O--,p.negative=0,p._ishlnsubmul(h,1,M),p.isZero()||(p.negative^=1);s&&(s.words[M]=O)}return s&&s._strip(),p._strip(),u!=="div"&&m!==0&&p.iushrn(m),{div:s||null,mod:p}},o.prototype.divmod=function(r,u,m){if(t(!r.isZero()),this.isZero())return{div:new o(0),mod:new o(0)};var p,h,S;return this.negative!==0&&r.negative===0?(S=this.neg().divmod(r,u),u!=="mod"&&(p=S.div.neg()),u!=="div"&&(h=S.mod.neg(),m&&h.negative!==0&&h.iadd(r)),{div:p,mod:h}):this.negative===0&&r.negative!==0?(S=this.divmod(r.neg(),u),u!=="mod"&&(p=S.div.neg()),{div:p,mod:S.mod}):this.negative&r.negative?(S=this.neg().divmod(r.neg(),u),u!=="div"&&(h=S.mod.neg(),m&&h.negative!==0&&h.isub(r)),{div:S.div,mod:h}):r.length>this.length||this.cmp(r)<0?{div:new o(0),mod:this}:r.length===1?u==="div"?{div:this.divn(r.words[0]),mod:null}:u==="mod"?{div:null,mod:new o(this.modrn(r.words[0]))}:{div:this.divn(r.words[0]),mod:new o(this.modrn(r.words[0]))}:this._wordDiv(r,u)},o.prototype.div=function(r){return this.divmod(r,"div",!1).div},o.prototype.mod=function(r){return this.divmod(r,"mod",!1).mod},o.prototype.umod=function(r){return this.divmod(r,"mod",!0).mod},o.prototype.divRound=function(r){var u=this.divmod(r);if(u.mod.isZero())return u.div;var m=u.div.negative!==0?u.mod.isub(r):u.mod,p=r.ushrn(1),h=r.andln(1),S=m.cmp(p);return S<0||h===1&&S===0?u.div:u.div.negative!==0?u.div.isubn(1):u.div.iaddn(1)},o.prototype.modrn=function(r){var u=r<0;u&&(r=-r),t(r<=67108863);for(var m=(1<<26)%r,p=0,h=this.length-1;h>=0;h--)p=(m*p+(this.words[h]|0))%r;return u?-p:p},o.prototype.modn=function(r){return this.modrn(r)},o.prototype.idivn=function(r){var u=r<0;u&&(r=-r),t(r<=67108863);for(var m=0,p=this.length-1;p>=0;p--){var h=(this.words[p]|0)+m*67108864;this.words[p]=h/r|0,m=h%r}return this._strip(),u?this.ineg():this},o.prototype.divn=function(r){return this.clone().idivn(r)},o.prototype.egcd=function(r){t(r.negative===0),t(!r.isZero());var u=this,m=r.clone();u.negative!==0?u=u.umod(r):u=u.clone();for(var p=new o(1),h=new o(0),S=new o(0),T=new o(1),f=0;u.isEven()&&m.isEven();)u.iushrn(1),m.iushrn(1),++f;for(var s=m.clone(),g=u.clone();!u.isZero();){for(var x=0,M=1;!(u.words[0]&M)&&x<26;++x,M<<=1);if(x>0)for(u.iushrn(x);x-- >0;)(p.isOdd()||h.isOdd())&&(p.iadd(s),h.isub(g)),p.iushrn(1),h.iushrn(1);for(var O=0,B=1;!(m.words[0]&B)&&O<26;++O,B<<=1);if(O>0)for(m.iushrn(O);O-- >0;)(S.isOdd()||T.isOdd())&&(S.iadd(s),T.isub(g)),S.iushrn(1),T.iushrn(1);u.cmp(m)>=0?(u.isub(m),p.isub(S),h.isub(T)):(m.isub(u),S.isub(p),T.isub(h))}return{a:S,b:T,gcd:m.iushln(f)}},o.prototype._invmp=function(r){t(r.negative===0),t(!r.isZero());var u=this,m=r.clone();u.negative!==0?u=u.umod(r):u=u.clone();for(var p=new o(1),h=new o(0),S=m.clone();u.cmpn(1)>0&&m.cmpn(1)>0;){for(var T=0,f=1;!(u.words[0]&f)&&T<26;++T,f<<=1);if(T>0)for(u.iushrn(T);T-- >0;)p.isOdd()&&p.iadd(S),p.iushrn(1);for(var s=0,g=1;!(m.words[0]&g)&&s<26;++s,g<<=1);if(s>0)for(m.iushrn(s);s-- >0;)h.isOdd()&&h.iadd(S),h.iushrn(1);u.cmp(m)>=0?(u.isub(m),p.isub(h)):(m.isub(u),h.isub(p))}var x;return u.cmpn(1)===0?x=p:x=h,x.cmpn(0)<0&&x.iadd(r),x},o.prototype.gcd=function(r){if(this.isZero())return r.abs();if(r.isZero())return this.abs();var u=this.clone(),m=r.clone();u.negative=0,m.negative=0;for(var p=0;u.isEven()&&m.isEven();p++)u.iushrn(1),m.iushrn(1);do{for(;u.isEven();)u.iushrn(1);for(;m.isEven();)m.iushrn(1);var h=u.cmp(m);if(h<0){var S=u;u=m,m=S}else if(h===0||m.cmpn(1)===0)break;u.isub(m)}while(!0);return m.iushln(p)},o.prototype.invm=function(r){return this.egcd(r).a.umod(r)},o.prototype.isEven=function(){return(this.words[0]&1)===0},o.prototype.isOdd=function(){return(this.words[0]&1)===1},o.prototype.andln=function(r){return this.words[0]&r},o.prototype.bincn=function(r){t(typeof r=="number");var u=r%26,m=(r-u)/26,p=1<<u;if(this.length<=m)return this._expand(m+1),this.words[m]|=p,this;for(var h=p,S=m;h!==0&&S<this.length;S++){var T=this.words[S]|0;T+=h,h=T>>>26,T&=67108863,this.words[S]=T}return h!==0&&(this.words[S]=h,this.length++),this},o.prototype.isZero=function(){return this.length===1&&this.words[0]===0},o.prototype.cmpn=function(r){var u=r<0;if(this.negative!==0&&!u)return-1;if(this.negative===0&&u)return 1;this._strip();var m;if(this.length>1)m=1;else{u&&(r=-r),t(r<=67108863,"Number is too big");var p=this.words[0]|0;m=p===r?0:p<r?-1:1}return this.negative!==0?-m|0:m},o.prototype.cmp=function(r){if(this.negative!==0&&r.negative===0)return-1;if(this.negative===0&&r.negative!==0)return 1;var u=this.ucmp(r);return this.negative!==0?-u|0:u},o.prototype.ucmp=function(r){if(this.length>r.length)return 1;if(this.length<r.length)return-1;for(var u=0,m=this.length-1;m>=0;m--){var p=this.words[m]|0,h=r.words[m]|0;if(p!==h){p<h?u=-1:p>h&&(u=1);break}}return u},o.prototype.gtn=function(r){return this.cmpn(r)===1},o.prototype.gt=function(r){return this.cmp(r)===1},o.prototype.gten=function(r){return this.cmpn(r)>=0},o.prototype.gte=function(r){return this.cmp(r)>=0},o.prototype.ltn=function(r){return this.cmpn(r)===-1},o.prototype.lt=function(r){return this.cmp(r)===-1},o.prototype.lten=function(r){return this.cmpn(r)<=0},o.prototype.lte=function(r){return this.cmp(r)<=0},o.prototype.eqn=function(r){return this.cmpn(r)===0},o.prototype.eq=function(r){return this.cmp(r)===0},o.red=function(r){return new $(r)},o.prototype.toRed=function(r){return t(!this.red,"Already a number in reduction context"),t(this.negative===0,"red works only with positives"),r.convertTo(this)._forceRed(r)},o.prototype.fromRed=function(){return t(this.red,"fromRed works only with numbers in reduction context"),this.red.convertFrom(this)},o.prototype._forceRed=function(r){return this.red=r,this},o.prototype.forceRed=function(r){return t(!this.red,"Already a number in reduction context"),this._forceRed(r)},o.prototype.redAdd=function(r){return t(this.red,"redAdd works only with red numbers"),this.red.add(this,r)},o.prototype.redIAdd=function(r){return t(this.red,"redIAdd works only with red numbers"),this.red.iadd(this,r)},o.prototype.redSub=function(r){return t(this.red,"redSub works only with red numbers"),this.red.sub(this,r)},o.prototype.redISub=function(r){return t(this.red,"redISub works only with red numbers"),this.red.isub(this,r)},o.prototype.redShl=function(r){return t(this.red,"redShl works only with red numbers"),this.red.shl(this,r)},o.prototype.redMul=function(r){return t(this.red,"redMul works only with red numbers"),this.red._verify2(this,r),this.red.mul(this,r)},o.prototype.redIMul=function(r){return t(this.red,"redMul works only with red numbers"),this.red._verify2(this,r),this.red.imul(this,r)},o.prototype.redSqr=function(){return t(this.red,"redSqr works only with red numbers"),this.red._verify1(this),this.red.sqr(this)},o.prototype.redISqr=function(){return t(this.red,"redISqr works only with red numbers"),this.red._verify1(this),this.red.isqr(this)},o.prototype.redSqrt=function(){return t(this.red,"redSqrt works only with red numbers"),this.red._verify1(this),this.red.sqrt(this)},o.prototype.redInvm=function(){return t(this.red,"redInvm works only with red numbers"),this.red._verify1(this),this.red.invm(this)},o.prototype.redNeg=function(){return t(this.red,"redNeg works only with red numbers"),this.red._verify1(this),this.red.neg(this)},o.prototype.redPow=function(r){return t(this.red&&!r.red,"redPow(normalNum)"),this.red._verify1(this),this.red.pow(this,r)};var mn={k256:null,p224:null,p192:null,p25519:null};function _t(y,r){this.name=y,this.p=new o(r,16),this.n=this.p.bitLength(),this.k=new o(1).iushln(this.n).isub(this.p),this.tmp=this._tmp()}_t.prototype._tmp=function(){var r=new o(null);return r.words=new Array(Math.ceil(this.n/13)),r},_t.prototype.ireduce=function(r){var u=r,m;do this.split(u,this.tmp),u=this.imulK(u),u=u.iadd(this.tmp),m=u.bitLength();while(m>this.n);var p=m<this.n?-1:u.ucmp(this.p);return p===0?(u.words[0]=0,u.length=1):p>0?u.isub(this.p):u.strip!==void 0?u.strip():u._strip(),u},_t.prototype.split=function(r,u){r.iushrn(this.n,0,u)},_t.prototype.imulK=function(r){return r.imul(this.k)};function Fn(){_t.call(this,"k256","ffffffff ffffffff ffffffff ffffffff ffffffff ffffffff fffffffe fffffc2f")}n(Fn,_t),Fn.prototype.split=function(r,u){for(var m=4194303,p=Math.min(r.length,9),h=0;h<p;h++)u.words[h]=r.words[h];if(u.length=p,r.length<=9){r.words[0]=0,r.length=1;return}var S=r.words[9];for(u.words[u.length++]=S&m,h=10;h<r.length;h++){var T=r.words[h]|0;r.words[h-10]=(T&m)<<4|S>>>22,S=T}S>>>=22,r.words[h-10]=S,S===0&&r.length>10?r.length-=10:r.length-=9},Fn.prototype.imulK=function(r){r.words[r.length]=0,r.words[r.length+1]=0,r.length+=2;for(var u=0,m=0;m<r.length;m++){var p=r.words[m]|0;u+=p*977,r.words[m]=u&67108863,u=p*64+(u/67108864|0)}return r.words[r.length-1]===0&&(r.length--,r.words[r.length-1]===0&&r.length--),r};function qs(){_t.call(this,"p224","ffffffff ffffffff ffffffff ffffffff 00000000 00000000 00000001")}n(qs,_t);function Fs(){_t.call(this,"p192","ffffffff ffffffff ffffffff fffffffe ffffffff ffffffff")}n(Fs,_t);function vr(){_t.call(this,"25519","7fffffffffffffff ffffffffffffffff ffffffffffffffff ffffffffffffffed")}n(vr,_t),vr.prototype.imulK=function(r){for(var u=0,m=0;m<r.length;m++){var p=(r.words[m]|0)*19+u,h=p&67108863;p>>>=26,r.words[m]=h,u=p}return u!==0&&(r.words[r.length++]=u),r},o._prime=function(r){if(mn[r])return mn[r];var u;if(r==="k256")u=new Fn;else if(r==="p224")u=new qs;else if(r==="p192")u=new Fs;else if(r==="p25519")u=new vr;else throw new Error("Unknown prime "+r);return mn[r]=u,u};function $(y){if(typeof y=="string"){var r=o._prime(y);this.m=r.p,this.prime=r}else t(y.gtn(1),"modulus must be greater than 1"),this.m=y,this.prime=null}$.prototype._verify1=function(r){t(r.negative===0,"red works only with positives"),t(r.red,"red works only with red numbers")},$.prototype._verify2=function(r,u){t((r.negative|u.negative)===0,"red works only with positives"),t(r.red&&r.red===u.red,"red works only with red numbers")},$.prototype.imod=function(r){return this.prime?this.prime.ireduce(r)._forceRed(this):(b(r,r.umod(this.m)._forceRed(this)),r)},$.prototype.neg=function(r){return r.isZero()?r.clone():this.m.sub(r)._forceRed(this)},$.prototype.add=function(r,u){this._verify2(r,u);var m=r.add(u);return m.cmp(this.m)>=0&&m.isub(this.m),m._forceRed(this)},$.prototype.iadd=function(r,u){this._verify2(r,u);var m=r.iadd(u);return m.cmp(this.m)>=0&&m.isub(this.m),m},$.prototype.sub=function(r,u){this._verify2(r,u);var m=r.sub(u);return m.cmpn(0)<0&&m.iadd(this.m),m._forceRed(this)},$.prototype.isub=function(r,u){this._verify2(r,u);var m=r.isub(u);return m.cmpn(0)<0&&m.iadd(this.m),m},$.prototype.shl=function(r,u){return this._verify1(r),this.imod(r.ushln(u))},$.prototype.imul=function(r,u){return this._verify2(r,u),this.imod(r.imul(u))},$.prototype.mul=function(r,u){return this._verify2(r,u),this.imod(r.mul(u))},$.prototype.isqr=function(r){return this.imul(r,r.clone())},$.prototype.sqr=function(r){return this.mul(r,r)},$.prototype.sqrt=function(r){if(r.isZero())return r.clone();var u=this.m.andln(3);if(t(u%2===1),u===3){var m=this.m.add(new o(1)).iushrn(2);return this.pow(r,m)}for(var p=this.m.subn(1),h=0;!p.isZero()&&p.andln(1)===0;)h++,p.iushrn(1);t(!p.isZero());var S=new o(1).toRed(this),T=S.redNeg(),f=this.m.subn(1).iushrn(1),s=this.m.bitLength();for(s=new o(2*s*s).toRed(this);this.pow(s,f).cmp(T)!==0;)s.redIAdd(T);for(var g=this.pow(s,p),x=this.pow(r,p.addn(1).iushrn(1)),M=this.pow(r,p),O=h;M.cmp(S)!==0;){for(var B=M,W=0;B.cmp(S)!==0;W++)B=B.redSqr();t(W<O);var j=this.pow(g,new o(1).iushln(O-W-1));x=x.redMul(j),g=j.redSqr(),M=M.redMul(g),O=W}return x},$.prototype.invm=function(r){var u=r._invmp(this.m);return u.negative!==0?(u.negative=0,this.imod(u).redNeg()):this.imod(u)},$.prototype.pow=function(r,u){if(u.isZero())return new o(1).toRed(this);if(u.cmpn(1)===0)return r.clone();var m=4,p=new Array(1<<m);p[0]=new o(1).toRed(this),p[1]=r;for(var h=2;h<p.length;h++)p[h]=this.mul(p[h-1],r);var S=p[0],T=0,f=0,s=u.bitLength()%26;for(s===0&&(s=26),h=u.length-1;h>=0;h--){for(var g=u.words[h],x=s-1;x>=0;x--){var M=g>>x&1;if(S!==p[0]&&(S=this.sqr(S)),M===0&&T===0){f=0;continue}T<<=1,T|=M,f++,!(f!==m&&(h!==0||x!==0))&&(S=this.mul(S,p[T]),f=0,T=0)}s=26}return S},$.prototype.convertTo=function(r){var u=r.umod(this.m);return u===r?u.clone():u},$.prototype.convertFrom=function(r){var u=r.clone();return u.red=null,u},o.mont=function(r){return new Pe(r)};function Pe(y){$.call(this,y),this.shift=this.m.bitLength(),this.shift%26!==0&&(this.shift+=26-this.shift%26),this.r=new o(1).iushln(this.shift),this.r2=this.imod(this.r.sqr()),this.rinv=this.r._invmp(this.m),this.minv=this.rinv.mul(this.r).isubn(1).div(this.m),this.minv=this.minv.umod(this.r),this.minv=this.r.sub(this.minv)}n(Pe,$),Pe.prototype.convertTo=function(r){return this.imod(r.ushln(this.shift))},Pe.prototype.convertFrom=function(r){var u=this.imod(r.mul(this.rinv));return u.red=null,u},Pe.prototype.imul=function(r,u){if(r.isZero()||u.isZero())return r.words[0]=0,r.length=1,r;var m=r.imul(u),p=m.maskn(this.shift).mul(this.minv).imaskn(this.shift).mul(this.m),h=m.isub(p).iushrn(this.shift),S=h;return h.cmp(this.m)>=0?S=h.isub(this.m):h.cmpn(0)<0&&(S=h.iadd(this.m)),S._forceRed(this)},Pe.prototype.mul=function(r,u){if(r.isZero()||u.isZero())return new o(0)._forceRed(this);var m=r.mul(u),p=m.maskn(this.shift).mul(this.minv).imaskn(this.shift).mul(this.m),h=m.isub(p).iushrn(this.shift),S=h;return h.cmp(this.m)>=0?S=h.isub(this.m):h.cmpn(0)<0&&(S=h.iadd(this.m)),S._forceRed(this)},Pe.prototype.invm=function(r){var u=this.imod(r._invmp(this.m).mul(this.r2));return u._forceRed(this)}})(typeof _s>"u"||_s,sp)});var ef={};Vr(ef,{appHelpers:()=>tf});module.exports=Vp(ef);var dc=require("@msafe/sui3-utils");var ne=require("@alphafi/alphafi-sdk"),qe=require("@msafe/sui3-utils"),Qt=require("@mysten/bcs");var $n=class{constructor(e,t){this.transaction=e;this.simResult=t}decode(){if(this.isClaimRewardTransaction())return this.decodeClaimReward();let e=this.getLiquidityChangeEvent();if(!e)throw new Error("No liquidity change event found. Unable to decode transaction.");let t=e.parsedJson,n=t.pool_id,o=ne.poolIdPoolNameMap[n];if(console.log("Decoder event data - ",t),console.log("Decoder poolName - ",o),this.isWithdrawAlphaEvent(e))return this.decodeWithdrawAlpha(t);if(this.isWithdrawEvent(t))return this.decodeWithdraw(o);if(this.isDoubleAssetDepositEvent(t,o))return this.decodeDoubleAssetDeposit(o,t);if(this.isSingleAssetDepositEvent(t,o))return this.decodeSingleAssetDeposit(o,t);throw new Error("Unknown transaction type")}get commands(){return this.transaction.getData().commands}get inputs(){return this.transaction.getData().inputs}getMoveCallCommand(e){return this.commands.find(t=>t.$kind==="MoveCall"&&t.MoveCall.function===e)}getLiquidityChangeEvent(){return this.simResult.events.find(e=>this.isLiquidityChangeEventType(e.type))}isClaimRewardTransaction(){return!!this.getMoveCallCommand("get_user_rewards_all")}isLiquidityChangeEventType(e){return e.includes("LiquidityChangeEvent")||e.includes("LiquidityChangeNewNewEvent")||e.includes("WithdrawEventV2")}isWithdrawAlphaEvent(e){return e.type.includes("WithdrawEventV2")}isWithdrawEvent(e){return e.event_type===1}isDoubleAssetDepositEvent(e,t){return e.event_type===0&&ne.poolInfo[t].assetTypes.length===2}isSingleAssetDepositEvent(e,t){return e.event_type===0&&ne.poolInfo[t].assetTypes.length===1}extractXTokensAmount(){let e=this.inputs.find(o=>o.Pure!==void 0);if(!e||!e.Pure?.bytes)throw new Error("Unable to extract xTokensAmount from inputs");let{bytes:t}=e.Pure,n;return t.length===12?n=Qt.bcs.u64().parse((0,Qt.fromBase64)(t)):t.length===24?n=Qt.bcs.u128().parse((0,Qt.fromBase64)(t)):t.length===44?n=Qt.bcs.u256().parse((0,Qt.fromBase64)(t)):n=Qt.bcs.u64().parse((0,Qt.fromBase64)(t)),n}decodeDoubleAssetDeposit(e,t){let{amount_a:n,amount_b:o}=t,a=Number(n)>0;return console.log("Decoder.decodeDoubleAssetDeposit",n,o,a),{txType:qe.TransactionType.Other,type:"depositDoubleAsset",intentionData:{poolName:e,amount:a?n:o,isAmountA:a}}}decodeSingleAssetDeposit(e,t){let{amount:n}=t;if(console.log("Decoder.decodeSingleAssetDeposit",n),this.getLiquidityChangeEvent().type.includes(":alphafi_navi_pool:")){let{coin:a}=ne.singleAssetPoolCoinMap[e],{expo:c}=ne.coinsList[a];n=Math.floor(Number(n)/10**(9-c)).toString()}return{txType:qe.TransactionType.Other,type:"depositSingleAsset",intentionData:{poolName:e,amount:n}}}decodeWithdraw(e){let t=this.extractXTokensAmount();return console.log("Decoder.decodeWithdraw",t),{txType:qe.TransactionType.Other,type:"withdraw",intentionData:{poolName:e,xTokensAmount:t}}}decodeWithdrawAlpha(e){let t=this.extractXTokensAmount(),{amount_withdrawn_from_locked:n}=e;return console.log("Decoder.decodeWithdrawAlpha",t,n),{txType:qe.TransactionType.Other,type:"withdrawAlpha",intentionData:{withdrawFromLocked:Number(n)>0,xTokensAmount:t}}}decodeClaimReward(){return{txType:qe.TransactionType.Other,type:"claimReward",intentionData:{}}}};var cc=require("@alphafi/alphafi-sdk");var sc=Ut(require("sort-keys-recursive")),C=class{constructor(e){this.data=e}serialize(){return JSON.stringify((0,sc.default)(this.data))}};var Vn=class i extends C{constructor(t){super(t);this.data=t}txType;txSubType;async build(t){let{account:n}=t;return await(0,cc.claimRewardTxb)(n.address)}static fromData(t){return new i(t)}};var lc=require("@alphafi/alphafi-sdk");var Hn=class i extends C{constructor(t){super(t);this.data=t}txType;txSubType;async build(t){let{account:n}=t,{poolName:o,amount:a,isAmountA:c}=this.data;return await(0,lc.depositDoubleAssetTxb)(o,n.address,a,c)}static fromData(t){return console.log("DepositDoubleAssetIntention.fromData",t),new i(t)}};var uc=require("@alphafi/alphafi-sdk");var Xn=class i extends C{constructor(t){super(t);this.data=t}txType;txSubType;async build(t){let{account:n}=t,{poolName:o,amount:a}=this.data;return await(0,uc.depositSingleAssetTxb)(o,n.address,a)}static fromData(t){return console.log("DepositSingleAssetIntention.fromData",t),new i(t)}};var mc=require("@alphafi/alphafi-sdk");var zn=class i extends C{constructor(t){super(t);this.data=t}txType;txSubType;async build(t){let{account:n}=t,{poolName:o,xTokensAmount:a}=this.data;return await(0,mc.withdrawTxb)(a,o,n.address)}static fromData(t){return console.log("WithdrawIntention.fromData",t),new i(t)}};var pc=require("@alphafi/alphafi-sdk");var Gn=class i extends C{constructor(t){super(t);this.data=t}txType;txSubType;async build(t){let{account:n}=t,{withdrawFromLocked:o,xTokensAmount:a}=this.data;return await(0,pc.withdrawAlphaTxb)(a,o,n.address)}static fromData(t){return console.log("WithdrawAlphaIntention.fromData",t),new i(t)}};var Qn=class{application="alphafi";supportSDK="@mysten/sui";async deserialize(e){let{transaction:t,suiClient:n,account:o}=e,a=await n.devInspectTransactionBlock({sender:t.getData().sender,transactionBlock:t});console.log("AlphaFiHelper Sim result - ",a);let l=new $n(t,a).decode();return{txType:dc.TransactionType.Other,txSubType:l.type,intentionData:l.intentionData}}async build(e){let{account:t}=e;console.log("AlphaFi build transaction type",e.txSubType);let n;switch(e.txSubType){case"depositSingleAsset":n=Xn.fromData(e.intentionData);break;case"depositDoubleAsset":n=Hn.fromData(e.intentionData);break;case"withdraw":n=zn.fromData(e.intentionData);break;case"withdrawAlpha":n=Gn.fromData(e.intentionData);break;case"claimReward":n=Vn.fromData(e.intentionData);break;default:throw new Error("not implemented")}return n.build({account:t})}};var Lc=require("@msafe/sui3-utils");var Lt=require("@msafe/sui3-utils"),Jn=require("@mysten/sui/bcs"),Yn=require("bucket-protocol-sdk");var Zn=class{constructor(e){this.transaction=e}decode(){if(this.isSBUCKDepositTransaction())return this.decodeSBUCKDeposit();if(this.isSBUCKUnstakeTransaction())return this.decodeSBUCKUnstake();if(this.isSBUCKWithdrawTransaction())return this.decodeSBUCKWithdraw();if(this.isSBUCKClaimTransaction())return this.decodeSBUCKClaim();if(this.isLockedClaimTransaction())return this.decodeLockedClaim();if(this.isBorrowTransaction())return this.decodeBorrow();if(this.isRepayTransaction())return this.decodeRepay();if(this.isWithdrawTransaction())return this.decodeWithdraw();if(this.isCloseTransaction())return this.decodeClose();if(this.isTankDepositTransaction())return this.decodeTankDeposit();if(this.isTankWithdrawTransaction())return this.decodeTankWithdraw();if(this.isTankClaimTransaction())return this.decodeTankClaim();if(this.isPsmTransaction())return this.decodePsm();throw new Error("Unknown transaction type")}get commands(){return this.transaction.getData().commands}get inputs(){return this.transaction.getData().inputs}getMoveCallCommand(e){return this.commands.find(t=>t.$kind==="MoveCall"&&t.MoveCall.function===e)}getMoveCallModuleCommand(e,t){return this.commands.find(n=>n.$kind==="MoveCall"&&n.MoveCall.module===e&&n.MoveCall.function===t)}getMoveCallPackageModuleCommand(e,t,n){return this.commands.find(o=>o.$kind==="MoveCall"&&o.MoveCall.package===e&&o.MoveCall.module===t&&o.MoveCall.function===n)}getMoveCallModuleCommands(e,t){return this.commands.filter(n=>n.$kind==="MoveCall"&&n.MoveCall.module===e&&n.MoveCall.function===t)}getSplitCoinsCommands(){return this.commands.filter(e=>e.$kind==="SplitCoins")}getTransferCommands(){return this.commands.filter(e=>e.$kind==="TransferObjects")}isPsmTransaction(){return!!this.getMoveCallCommand("charge_reservoir")||!!this.getMoveCallCommand("discharge_reservoir")}isStrapNewTransaction(){return!!this.getMoveCallModuleCommand("strap","new")}isBorrowTransaction(){return!!this.getMoveCallModuleCommand("bucket_operations","high_top_up")||!!this.getMoveCallModuleCommand("bucket_operations","high_borrow")||!!this.getMoveCallModuleCommand("bucket_operations","high_borrow_with_strap")}isRepayTransaction(){return!!this.getMoveCallModuleCommand("bucket_operations","fully_repay")||!!this.getMoveCallModuleCommand("bucket_operations","fully_repay_with_strap")||!!this.getMoveCallModuleCommand("bucket_operations","repay_and_withdraw")||!!this.getMoveCallModuleCommand("bucket_operations","repay_and_withdraw_with_strap")}isWithdrawTransaction(){return!!this.getMoveCallModuleCommand("buck","withdraw")||!!this.getMoveCallModuleCommand("buck","withdraw_with_strap")}isCloseTransaction(){return!!this.getMoveCallModuleCommand("bucket_operations","destroy_empty_strap")}isTankDepositTransaction(){return!!this.getMoveCallModuleCommand("tank_operations","deposit")}isTankWithdrawTransaction(){return!!this.getMoveCallModuleCommand("tank_operations","withdraw")}isTankClaimTransaction(){return!!this.getMoveCallModuleCommand("tank_operations","claim")}isSBUCKDepositTransaction(){return!!this.getMoveCallModuleCommand("buck","buck_to_sbuck")}isSBUCKWithdrawTransaction(){return!!this.getMoveCallModuleCommand("buck","sbuck_to_buck")}isSBUCKStakeTransaction(){return!!this.getMoveCallPackageModuleCommand(Yn.SBUCK_FOUNTAIN_PACKAGE_ID,"fountain_core","stake")}isSBUCKUnstakeTransaction(){return!!this.getMoveCallPackageModuleCommand(Yn.SBUCK_FOUNTAIN_PACKAGE_ID,"fountain_core","force_unstake")}isSBUCKClaimTransaction(){return!!this.getMoveCallPackageModuleCommand(Yn.SBUCK_FOUNTAIN_PACKAGE_ID,"fountain_core","claim")}isLockedClaimTransaction(){return!!this.getMoveCallModuleCommand("proof_rule","claim")||!!this.getMoveCallModuleCommand("lst_proof_rule","claim")}isLstUnlockTransaction(){return!!this.getMoveCallModuleCommand("lst_proof_rule","unlock")}decodePsm(){let e,t,n="0",o=this.getSplitCoinsCommands()[0].SplitCoins.amounts[0];return o.$kind==="Input"&&(n=this.getPureInputU64(o.Input)),this.getMoveCallCommand("charge_reservoir")?([e]=this.getMoveCallCommand("charge_reservoir").MoveCall.typeArguments,t=!1):([e]=this.getMoveCallCommand("discharge_reservoir").MoveCall.typeArguments,t=!0),console.log("Decoder.decodePsm",e,n,t),{txType:Lt.TransactionType.Other,type:"psm",intentionData:{coinType:e,amount:n,buckToCoin:t}}}decodeBorrow(){let e="",t="0",n,o=this.getStrapId(),a="0",c=this.getSplitCoinsCommands()[0].SplitCoins.amounts[0];if(c.$kind==="Input"&&(a=this.getPureInputU64(c.Input)),this.getMoveCallCommand("high_top_up")){let l=this.getMoveCallCommand("high_top_up").MoveCall;[e]=l.typeArguments;let d=l.arguments[1];d.$kind==="Input"&&(t=this.getPureInputU64(d.Input));let b=l.arguments[3];if(b.$kind==="Input"){let w=this.getPureAddresses(b.Input);w.length===1&&([n]=w)}}else if(this.getMoveCallCommand("high_borrow")){let l=this.getMoveCallCommand("high_borrow").MoveCall;[e]=l.typeArguments;let d=l.arguments[4];d.$kind==="Input"&&(t=this.getPureInputU64(d.Input));let b=l.arguments[5];if(b.$kind==="Input"){let w=this.getPureAddresses(b.Input);w.length===1&&([n]=w)}}else if(this.getMoveCallCommand("high_borrow_with_strap")){let l=this.getMoveCallCommand("high_borrow_with_strap").MoveCall;[e]=l.typeArguments;let d=l.arguments[5];d.$kind==="Input"&&(t=this.getPureInputU64(d.Input));let b=l.arguments[6];if(b.$kind==="Input"){let w=this.getPureAddresses(b.Input);w.length===1&&([n]=w)}}return{txType:Lt.TransactionType.Other,type:"borrow",intentionData:{collateralType:e,collateralAmount:a,borrowAmount:t,insertionPlace:n,strapId:o}}}decodeRepay(){let e="",t="0",n="0",a,c=this.getStrapId();if(this.getMoveCallCommand("fully_repay"))[e]=this.getMoveCallCommand("fully_repay").MoveCall.typeArguments;else if(this.getMoveCallCommand("fully_repay_with_strap"))[e]=this.getMoveCallCommand("fully_repay_with_strap").MoveCall.typeArguments;else if(this.getMoveCallCommand("repay_and_withdraw")){let l=this.getMoveCallCommand("repay_and_withdraw").MoveCall;[e]=l.typeArguments;let d=l.arguments[4];d.$kind==="Input"&&(n=this.getPureInputU64(d.Input));let b=l.arguments[5];if(b.$kind==="Input"){let I=this.getPureAddresses(b.Input);I.length===1&&([a]=I)}let w=this.getSplitCoinsCommands()[0].SplitCoins.amounts[0];w.$kind==="Input"&&(t=this.getPureInputU64(w.Input))}else if(this.getMoveCallCommand("repay_and_withdraw_with_strap")){let l=this.getMoveCallCommand("repay_and_withdraw_with_strap").MoveCall;[e]=l.typeArguments;let d=l.arguments[5];d.$kind==="Input"&&(n=this.getPureInputU64(d.Input));let b=l.arguments[6];if(b.$kind==="Input"){let I=this.getPureAddresses(b.Input);I.length===1&&([a]=I)}let w=this.getSplitCoinsCommands()[0].SplitCoins.amounts[0];w.$kind==="Input"&&(t=this.getPureInputU64(w.Input))}return{txType:Lt.TransactionType.Other,type:"repay",intentionData:{collateralType:e,repayAmount:t,withdrawAmount:n,isSurplus:!1,insertionPlace:a,strapId:c}}}decodeWithdraw(){let e="",t="0",n,o=this.getStrapId();if(this.getMoveCallCommand("withdraw_with_strap")){let a=this.getMoveCallCommand("withdraw_with_strap").MoveCall;[e]=a.typeArguments;let c=a.arguments[4];c.$kind==="Input"&&(t=this.getPureInputU64(c.Input));let l=a.arguments[5];if(l.$kind==="Input"){let d=this.getPureAddresses(l.Input);d.length===1&&([n]=d)}}else if(this.getMoveCallCommand("withdraw")){let a=this.getMoveCallCommand("withdraw").MoveCall;[e]=a.typeArguments;let c=a.arguments[3];c.$kind==="Input"&&(t=this.getPureInputU64(c.Input));let l=a.arguments[4];if(l.$kind==="Input"){let d=this.getPureAddresses(l.Input);d.length===1&&([n]=d)}}return{txType:Lt.TransactionType.Other,type:"withdraw",intentionData:{collateralType:e,withdrawAmount:t,insertionPlace:n,strapId:o}}}decodeClose(){let e="",t=this.getStrapId();return this.getMoveCallCommand("destroy_empty_strap")&&([e]=this.getMoveCallCommand("destroy_empty_strap").MoveCall.typeArguments),{txType:Lt.TransactionType.Other,type:"close",intentionData:{collateralType:e,strapId:t}}}decodeSBUCKDeposit(){let t=this.getMoveCallCommand("into_balance").MoveCall.typeArguments[0],n="0",a=this.getSplitCoinsCommands()[0].SplitCoins.amounts[0];a.$kind==="Input"&&(n=this.getPureInputU64(a.Input));let c=this.isSBUCKStakeTransaction();return console.log("Decoder.decodeSBUCKDeposit",t,n,c),{txType:Lt.TransactionType.Other,type:"sbuck-deposit",intentionData:{coinType:t,amount:n,isStake:c}}}decodeSBUCKUnstake(){let e="0",t=this.isSBUCKStakeTransaction();if(t){let d=this.getSplitCoinsCommands()[0].SplitCoins.amounts[0];d.$kind==="Input"&&(e=this.getPureInputU64(d.Input))}let n=[],o=this.getMoveCallModuleCommands("proof_rule","unlock");if(o.length>0)for(let l=0;l<o.length;l++){let d=o[l];n.push("")}else{let l=this.getMoveCallModuleCommands("fountain_core","force_unstake");for(let d=0;d<l.length;d++){let w=l[d].MoveCall.arguments[2];if(w.$kind==="Input"){let{objectId:I}=this.inputs[w.Input].UnresolvedObject;n.push(I)}}}let a=this.isSBUCKWithdrawTransaction(),c={stakeProofs:n,amount:e,isStake:t,toBuck:a};return console.log("Decoder.decodeSBUCKUnstake",c),{txType:Lt.TransactionType.Other,type:"sbuck-unstake",intentionData:c}}decodeSBUCKWithdraw(){let e="0",n=this.getSplitCoinsCommands()[0].SplitCoins.amounts[0];return n.$kind==="Input"&&(e=this.getPureInputU64(n.Input)),console.log("Decoder.SBUCKWithdraw",e),{txType:Lt.TransactionType.Other,type:"sbuck-withdraw",intentionData:{amount:e}}}decodeSBUCKClaim(){let e=[],t=this.getMoveCallModuleCommands("fountain_core","claim");for(let n=0;n<t.length;n++){let a=t[n].MoveCall.arguments[2];if(a.$kind==="Input"){let{objectId:c}=this.inputs[a.Input].UnresolvedObject;e.push(c)}}return console.log("Decoder.decodeSBUCKClaim",e),{txType:Lt.TransactionType.Other,type:"sbuck-claim",intentionData:{stakeProofs:e}}}decodeTankDeposit(){let e="0",n=this.getSplitCoinsCommands()[0].SplitCoins.amounts[0];n.$kind==="Input"&&(e=this.getPureInputU64(n.Input));let a=this.getMoveCallModuleCommand("tank_operations","deposit").MoveCall.typeArguments[0];return console.log("Decoder.decodeTankDeposit",a,e),{txType:Lt.TransactionType.Other,type:"tank-deposit",intentionData:{coinType:a,amount:e}}}decodeTankWithdraw(){let e=this.getMoveCallModuleCommand("tank_operations","withdraw").MoveCall,t=e.typeArguments[0],n="0",o=e.arguments[5];return o.$kind==="Input"&&(n=this.getPureInputU64(o.Input)),console.log("Decoder.decodeTankWithdraw",t,n),{txType:Lt.TransactionType.Other,type:"tank-withdraw",intentionData:{coinType:t,amount:n}}}decodeTankClaim(){let t=this.getMoveCallModuleCommand("tank_operations","claim").MoveCall.typeArguments[0];return console.log("Decoder.decodeTankClaim",t),{txType:Lt.TransactionType.Other,type:"tank-claim",intentionData:{coinType:t}}}decodeLockedClaim(){let e="",t=0,n=this.getMoveCallModuleCommands("proof_rule","claim");for(let a=0;a<n.length;a++)[e]=n[a].MoveCall.typeArguments,t++;let o=this.getMoveCallModuleCommands("lst_proof_rule","claim");for(let a=0;a<o.length;a++)[e]=o[a].MoveCall.typeArguments,t++;return console.log("Decoder.decodeLockedClaim",e,t),{txType:Lt.TransactionType.Other,type:"lock-claim",intentionData:{coinType:e,proofCount:t}}}getCoinInput(e){if(this.inputs[e].$kind!=="Object")throw new Error("not Object argument")}getStrapId(){let e;if(this.isStrapNewTransaction()?e="new":this.isLstUnlockTransaction()&&(e="locked"),!e){let t=this.getMoveCallModuleCommand("fountain","unstake");if(t){let n=t.MoveCall.arguments[2];n.$kind==="Input"&&(e=this.inputs[n.Input].UnresolvedObject.objectId)}}return e}getPureInputU64(e){let t=this.inputs[e];if(t.$kind!=="Pure")throw new Error("not pure argument");return Jn.bcs.U64.fromBase64(t.Pure.bytes)}getPureAddresses(e){let t=this.inputs[e];if(t.$kind!=="Pure")throw new Error("not pure argument");return Jn.bcs.vector(Jn.bcs.Address).fromBase64(t.Pure.bytes)}};var bc=require("@msafe/sui3-utils");var hc=require("@mysten/sui/transactions"),gc=require("bucket-protocol-sdk");var fc=require("bucket-protocol-sdk"),Pt=(i,e)=>{let t=i==="sui:mainnet"?"mainnet":"testnet";return new fc.BucketClient(t,e.address)};var yc=async(i,e,t)=>{let{coinType:n,amount:o,buckToCoin:a}=i,c=new hc.Transaction,l=Pt(t,e);return await(0,gc.buildPsmTx)(l,c,n,o,a,e.address),c};var to=class i extends C{constructor(t){super(t);this.data=t}txType=bc.TransactionType.Other;txSubType="psm";async build(t){let{account:n,network:o}=t;return await yc(this.data,n,o)}static fromData(t){return new i(t)}};var Cc=require("@msafe/sui3-utils");var pn=require("@mysten/sui/transactions"),se=require("bucket-protocol-sdk");var Sc=async(i,e,t)=>{let{collateralType:n,collateralAmount:o,borrowAmount:a,insertionPlace:c,strapId:l}=i,d=new pn.Transaction,b=Pt(t,e);return await(0,se.buildBorrowTx)(b,d,n,o,a,e.address,c,l),d},Tc=async(i,e,t)=>{let{collateralType:n,withdrawAmount:o,insertionPlace:a,strapId:c}=i,l=new pn.Transaction,d=Pt(t,e);return await(0,se.buildWithdrawTx)(d,l,n,o,e.address,a,c),l},wc=async(i,e,t)=>{let{collateralType:n,repayAmount:o,withdrawAmount:a,isSurplus:c,insertionPlace:l,strapId:d}=i,b=new pn.Transaction,w=Pt(t,e);return await(0,se.buildRepayTx)(w,b,n,o,a,e.address,c,l,d),b},Ic=async(i,e,t)=>{let{collateralType:n,recipient:o,strapId:a}=i,c=new pn.Transaction,l=Pt(t,e);return await(0,se.buildCloseTx)(l,c,n,o,a),c};var eo=class i extends C{constructor(t){super(t);this.data=t}txType=Cc.TransactionType.Other;txSubType="borrow";async build(t){let{account:n,network:o}=t;return await Sc(this.data,n,o)}static fromData(t){return new i(t)}};var kc=require("@msafe/sui3-utils");var no=class i extends C{constructor(t){super(t);this.data=t}txType=kc.TransactionType.Other;txSubType="repay";async build(t){let{account:n,network:o}=t;return await wc(this.data,n,o)}static fromData(t){return new i(t)}};var vc=require("@msafe/sui3-utils");var oo=class i extends C{constructor(t){super(t);this.data=t}txType=vc.TransactionType.Other;txSubType="withdraw";async build(t){let{account:n,network:o}=t;return await Tc(this.data,n,o)}static fromData(t){return new i(t)}};var Dc=require("@msafe/sui3-utils");var ao=class i extends C{constructor(t){super(t);this.data=t}txType=Dc.TransactionType.Other;txSubType="close";async build(t){let{account:n,network:o}=t;return await Ic(this.data,n,o)}static fromData(t){return new i(t)}};var fn=require("@msafe/sui3-utils");var dn=require("@mysten/sui/transactions"),ce=require("bucket-protocol-sdk");var xc=async(i,e,t)=>{let{coinType:n,amount:o,isStake:a}=i,c=new dn.Transaction,l=Pt(t,e);return await(0,ce.buildSBUCKDepositTx)(l,c,n,o,e.address,a),c},Ac=async(i,e,t)=>{let{stakeProofs:n,amount:o,isStake:a,toBuck:c}=i,l=new dn.Transaction,d=Pt(t,e);return await(0,ce.buildSBUCKUnstakeTx)(d,l,n,o,e.address,a,c),l},Mc=async(i,e,t)=>{let{amount:n}=i,o=new dn.Transaction,a=Pt(t,e);return await(0,ce.buildSBUCKWithdrawTx)(a,o,n,e.address),o},Oc=async(i,e,t)=>{let{stakeProofs:n}=i,o=new dn.Transaction,a=Pt(t,e);return await(0,ce.buildSBUCKClaimTx)(a,o,n,e.address),o};var io=class i extends C{constructor(t){super(t);this.data=t}txType=fn.TransactionType.Other;txSubType="sbuck-deposit";async build(t){let{account:n,network:o}=t;return await xc(this.data,n,o)}static fromData(t){return new i(t)}},ro=class i extends C{constructor(t){super(t);this.data=t}txType=fn.TransactionType.Other;txSubType="sbuck-unstake";async build(t){let{account:n,network:o}=t;return await Ac(this.data,n,o)}static fromData(t){return new i(t)}},so=class i extends C{constructor(t){super(t);this.data=t}txType=fn.TransactionType.Other;txSubType="sbuck-withdraw";async build(t){let{account:n,network:o}=t;return await Mc(this.data,n,o)}static fromData(t){return new i(t)}},co=class i extends C{constructor(t){super(t);this.data=t}txType=fn.TransactionType.Other;txSubType="sbuck-claim";async build(t){let{account:n,network:o}=t;return await Oc(this.data,n,o)}static fromData(t){return new i(t)}};var fo=require("@msafe/sui3-utils");var lo=require("@mysten/sui/transactions"),Fe=require("bucket-protocol-sdk");var Pc=async(i,e,t)=>{let{coinType:n,amount:o}=i,a=new lo.Transaction,c=Pt(t,e);return await(0,Fe.buildTankDepositTx)(c,a,n,o,e.address),a},Rc=async(i,e,t)=>{let{coinType:n,amount:o}=i,a=new lo.Transaction,c=Pt(t,e);return await(0,Fe.buildTankWithdrawTx)(c,a,n,o,e.address),a},Bc=async(i,e,t)=>{let{coinType:n}=i,o=new lo.Transaction,a=Pt(t,e);return await(0,Fe.buildTankClaimTx)(a,o,n,e.address),o};var Ec=require("@mysten/sui/transactions"),Nc=require("bucket-protocol-sdk");var Wc=async(i,e,t)=>{let{coinType:n,proofCount:o}=i,a=new Ec.Transaction,c=Pt(t,e);return await(0,Nc.buildLockedClaimTx)(c,a,n,o,e.address),a};var uo=class i extends C{constructor(t){super(t);this.data=t}txType=fo.TransactionType.Other;txSubType="tank-deposit";async build(t){let{account:n,network:o}=t;return await Pc(this.data,n,o)}static fromData(t){return new i(t)}},mo=class i extends C{constructor(t){super(t);this.data=t}txType=fo.TransactionType.Other;txSubType="tank-withdraw";async build(t){let{account:n,network:o}=t;return await Rc(this.data,n,o)}static fromData(t){return new i(t)}},po=class i extends C{constructor(t){super(t);this.data=t}txType=fo.TransactionType.Other;txSubType="tank-claim";async build(t){let{account:n,network:o}=t;return await Bc(this.data,n,o)}static fromData(t){return new i(t)}};var _c=require("@msafe/sui3-utils");var ho=class i extends C{constructor(t){super(t);this.data=t}txType=_c.TransactionType.Other;txSubType="lock-claim";async build(t){let{account:n,network:o}=t;return await Wc(this.data,n,o)}static fromData(t){return new i(t)}};var go=class{application="bucket";supportSDK="@mysten/sui";async deserialize(e){console.log("Bucket helper deserialize input: ",e);let{transaction:t}=e,o=new Zn(t).decode();return{txType:Lc.TransactionType.Other,txSubType:o.type,intentionData:o.intentionData}}async build(e){let{suiClient:t,account:n,network:o}=e,a;switch(e.txSubType){case"psm":a=to.fromData(e.intentionData);break;case"borrow":a=eo.fromData(e.intentionData);break;case"withdraw":a=oo.fromData(e.intentionData);break;case"repay":a=no.fromData(e.intentionData);break;case"close":a=ao.fromData(e.intentionData);break;case"tank-deposit":a=uo.fromData(e.intentionData);break;case"tank-withdraw":a=mo.fromData(e.intentionData);break;case"tank-claim":a=po.fromData(e.intentionData);break;case"sbuck-deposit":a=io.fromData(e.intentionData);break;case"sbuck-unstake":a=ro.fromData(e.intentionData);break;case"sbuck-withdraw":a=so.fromData(e.intentionData);break;case"sbuck-claim":a=co.fromData(e.intentionData);break;case"lock-claim":a=ho.fromData(e.intentionData);break;default:throw new Error("not implemented")}return a.build({suiClient:t,account:n,network:o})}};var Kl=require("@msafe/sui3-utils");var Gc=require("@msafe/sui3-utils");var yo=require("@cetusprotocol/aggregator-sdk"),jc=require("@cetusprotocol/farms-sdk"),Uc=require("@cetusprotocol/sui-clmm-sdk"),qc=require("@cetusprotocol/vaults-sdk"),Fc=require("@cetusprotocol/xcetus-sdk"),Re=require("@mysten/sui/client"),ae=(i,e)=>{let t=Uc.CetusClmmSDK.createSDK({env:"mainnet",sui_client:new Re.SuiClient({url:(0,Re.getFullnodeUrl)("mainnet")})});return t.setSenderAddress(e.address),t},qt=(i,e)=>{let t=jc.CetusFarmsSDK.createSDK({env:"mainnet",sui_client:new Re.SuiClient({url:(0,Re.getFullnodeUrl)("mainnet")})});return t.setSenderAddress(e.address),t},Xp="https://api-sui.cetus.zone/router_v2/find_routes",Kc=(i,e)=>{let t=new Re.SuiClient({url:"https://fullnode.mainnet.sui.io/"});return new yo.AggregatorClient({endpoint:Xp,signer:e.address,client:t,env:yo.Env.Mainnet})},hn=(i,e)=>{let t=qc.CetusVaultsSDK.createSDK({env:"mainnet"});return t.setSenderAddress(e.address),t},Ke=(i,e)=>{let t=Fc.CetusXcetusSDK.createSDK({env:"mainnet"});return t.setSenderAddress(e.address),t};var $c=async(i,e,t)=>await ae(t,e).Position.createAddLiquidityFixTokenPayload(i?.parameter,i?.gasEstimateArg),Vc=async(i,e,t)=>await ae(t,e).Position.createAddLiquidityFixTokenPayload(i?.parameter,i?.gasEstimateArg),Hc=async(i,e,t)=>await ae(t,e).Position.closePositionPayload(i),Xc=async(i,e,t)=>await ae(t,e).Position.removeLiquidityPayload(i),zc=async(i,e,t)=>await ae(t,e).Rewarder.collectRewarderPayload(i);var bo=class i extends C{constructor(t){super(t);this.data=t}txType=Gc.TransactionType.Other;txSubType="OpenAndAddLiquidity";async build(t){let{account:n,network:o}=t,{txbParams:a}=this.data;return await $c(a,n,o)}static fromData(t){return new i(t)}};var Qc=require("@msafe/sui3-utils");var So=class i extends C{constructor(t){super(t);this.data=t}txType=Qc.TransactionType.Other;txSubType="ClaimFeeAndMining";async build(t){let{account:n,network:o}=t,{txbParams:a}=this.data;return await zc(a,n,o)}static fromData(t){return new i(t)}};var Jc=require("@msafe/sui3-utils");var To=class i extends C{constructor(t){super(t);this.data=t}txType=Jc.TransactionType.Other;txSubType="DecreaseLiquidity";async build(t){let{account:n,network:o}=t,{txbParams:a}=this.data;return await Xc(a,n,o)}static fromData(t){return new i(t)}};var sl=require("@msafe/sui3-utils");var Yc=async(i,e,t)=>await qt(t,e).Farms.openPositionAddLiquidityStakePayload(i),Zc=async(i,e,t)=>await qt(t,e).Farms.addLiquidityFixCoinPayload(i),tl=async(i,e,t)=>await qt(t,e).Farms.removeLiquidityPayload(i),el=async(i,e,t)=>await qt(t,e).Farms.removeLiquidityPayload(i),nl=async(i,e,t)=>await qt(t,e).Farms.claimFeeAndClmmReward(i),ol=async(i,e,t)=>await qt(t,e).Farms.harvestPayload(i),al=async(i,e,t)=>{let n=qt(t,e),o=Object.values(i);return await n.Farms.batchHarvestPayload(o)},il=async(i,e,t)=>await qt(t,e).Farms.depositPayload(i),rl=async(i,e,t)=>await qt(t,e).Farms.withdrawPayload(i);var wo=class i extends C{constructor(t){super(t);this.data=t}txType=sl.TransactionType.Other;txSubType="FarmingOpenAndAddLiquidity";async build(t){let{account:n,network:o}=t,{txbParams:a}=this.data;return await Yc(a,n,o)}static fromData(t){return new i(t)}};var cl=require("@msafe/sui3-utils");var Io=class i extends C{constructor(t){super(t);this.data=t}txType=cl.TransactionType.Other;txSubType="FarmingBatchHarvest";async build(t){let{account:n,network:o}=t,{txbParams:a}=this.data;return await al(a,n,o)}static fromData(t){return new i(t)}};var ll=require("@msafe/sui3-utils");var Co=class i extends C{constructor(t){super(t);this.data=t}txType=ll.TransactionType.Other;txSubType="FarmingClaimFeeAndReward";async build(t){let{account:n,network:o}=t,{txbParams:a}=this.data;return await nl(a,n,o)}static fromData(t){return new i(t)}};var ul=require("@msafe/sui3-utils");var ko=class i extends C{constructor(t){super(t);this.data=t}txType=ul.TransactionType.Other;txSubType="FarmingDecreaseLiquidity";async build(t){let{account:n,network:o}=t,{txbParams:a}=this.data;return await tl(a,n,o)}static fromData(t){return new i(t)}};var ml=require("@msafe/sui3-utils");var vo=class i extends C{constructor(t){super(t);this.data=t}txType=ml.TransactionType.Other;txSubType="FarmingHarvest";async build(t){let{account:n,network:o}=t,{txbParams:a}=this.data;return await ol(a,n,o)}static fromData(t){return new i(t)}};var pl=require("@msafe/sui3-utils");var Do=class i extends C{constructor(t){super(t);this.data=t}txType=pl.TransactionType.Other;txSubType="FarmingIncreaseLiquidity";async build(t){let{account:n,network:o}=t,{txbParams:a}=this.data;return await Zc(a,n,o)}static fromData(t){return new i(t)}};var dl=require("@msafe/sui3-utils");var xo=class i extends C{constructor(t){super(t);this.data=t}txType=dl.TransactionType.Other;txSubType="FarmingRemoveLiquidity";async build(t){let{account:n,network:o}=t,{txbParams:a}=this.data;return await el(a,n,o)}static fromData(t){return new i(t)}};var fl=require("@msafe/sui3-utils");var Ao=class i extends C{constructor(t){super(t);this.data=t}txType=fl.TransactionType.Other;txSubType="FarmingStake";async build(t){let{account:n,network:o}=t,{txbParams:a}=this.data;return await il(a,n,o)}static fromData(t){return new i(t)}};var hl=require("@msafe/sui3-utils");var Mo=class i extends C{constructor(t){super(t);this.data=t}txType=hl.TransactionType.Other;txSubType="FarmingUnstake";async build(t){let{account:n,network:o}=t,{txbParams:a}=this.data;return await rl(a,n,o)}static fromData(t){return new i(t)}};var gl=require("@msafe/sui3-utils");var Oo=class i extends C{constructor(t){super(t);this.data=t}txType=gl.TransactionType.Other;txSubType="IncreaseLiquidity";async build(t){let{account:n,network:o}=t,{txbParams:a}=this.data;return await Vc(a,n,o)}static fromData(t){return new i(t)}};var Sl=require("@msafe/sui3-utils");var gn=require("@mysten/sui/transactions"),Po=Ut(require("haedal-vault-sdk"));var zp=async(i,e,t)=>{let n=hn(t,e),o=new gn.Transaction;return o.setSender(e.address),n.Vest.buildRedeemPayload(i.params,o),o},Gp=async(i,e,t)=>{let n=new Po.default(Po.vaults_mainnet);n.senderAddress=e.address;let o=new gn.Transaction;return o.setSender(e.address),await n?.Vest.buildRedeemPayload(i.params,o),o},yl=(i,e,t)=>{let n=ae(t,e),o=new gn.Transaction;return n?.Vest.buildRedeemPayload(i.params,o),o},Qp=async(i,e,t)=>{let n=ae(t,e),o=qt(t,e),a=new gn.Transaction,c=await o.Farms.withdrawReturnPayload(i.withdrawParams,a);return n.Vest.buildRedeemPayload(i.redeemParms.map(l=>({...l,clmm_position_id:c})),a),o.Farms.depositPayload({...i.depositParams,clmm_position_id:c},a),a},bl=async(i,e,t)=>i.type==="clmm"?yl(i,e,t):i.type==="farms"?Qp(i,e,t):i.type==="vaults"?zp(i,e,t):i.type==="haedalVaults"?Gp(i,e,t):yl(i,e,t);var Ro=class i extends C{constructor(t){super(t);this.data=t}txType=Sl.TransactionType.Other;txSubType="PosVestingRedeem";async build(t){let{account:n,network:o}=t,{txbParams:a}=this.data;return await bl(a,n,o)}static fromData(t){return new i(t)}};var Tl=require("@msafe/sui3-utils");var Bo=class i extends C{constructor(t){super(t);this.data=t}txType=Tl.TransactionType.Other;txSubType="RemoveLiquidity";async build(t){let{account:n,network:o}=t,{txbParams:a}=this.data;return await Hc(a,n,o)}static fromData(t){return new i(t)}};var kl=require("@msafe/sui3-utils");var wl=require("@cetusprotocol/aggregator-sdk"),Il=require("@mysten/sui/transactions");var Cl=async(i,e,t)=>{let n=Kc(t,e),o=new Il.Transaction;return await n.fastRouterSwap({...i,routers:(0,wl.restituteMsafeFastRouterSwapParams)(i.routers),txb:o}),o};var Eo=class i extends C{constructor(t){super(t);this.data=t}txType=kl.TransactionType.Other;txSubType="AggregatorSwap";async build(t){let{account:n,network:o}=t,{txbParams:a}=this.data;return await Cl(a,n,o)}static fromData(t){return new i(t)}};var xl=require("@msafe/sui3-utils");var Hr=require("@mysten/sui/transactions");var vl=async(i,e,t)=>{let n=hn(t,e),o=new Hr.Transaction;return o.setSender(e.address),await n.Vaults.deposit(i,o),o},Dl=async(i,e,t)=>{let n=hn(t,e),o=new Hr.Transaction;return await n.Vaults.withdraw(i,o),o};var No=class i extends C{constructor(t){super(t);this.data=t}txType=xl.TransactionType.Other;txSubType="AddVaultsPosition";async build(t){let{account:n,network:o}=t,{txbParams:a}=this.data;return await vl(a,n,o)}static fromData(t){return new i(t)}};var Al=require("@msafe/sui3-utils");var Wo=class i extends C{constructor(t){super(t);this.data=t}txType=Al.TransactionType.Other;txSubType="RemoveVaultsPosition";async build(t){let{account:n,network:o}=t,{txbParams:a}=this.data;return await Dl(a,n,o)}static fromData(t){return new i(t)}};var Rl=require("@msafe/sui3-utils");var Ol=require("@mysten/sui/transactions"),Ml={package_id:"0x355714a1eeb7ab1d80902da6c92001170cda1212edf524c32aa308a3ac177c31",published_at:"0x355714a1eeb7ab1d80902da6c92001170cda1212edf524c32aa308a3ac177c31",cetus_coin_type:"0x06864a6f921804860930db6ddbe2e16acdf8504495ea7481637a1c8b9a8fe54b::cetus::CETUS"},Pl=async(i,e,t)=>{console.log("getVestingRedeemTxb txbParams: ",i),console.log("getVestingRedeemTxb account: ",e),console.log("getVestingRedeemTxb network: ",t);let{pool:n,nftId:o,periods:a,CLOCK_ADDRESS:c}=i,l=new Ol.Transaction;return a.forEach(d=>{l.moveCall({target:`${Ml.published_at}::router::redeem`,typeArguments:[Ml.cetus_coin_type],arguments:[l.object(n),l.object(o),l.pure(d),l.object(c)]})}),l};var _o=class i extends C{constructor(t){super(t);this.data=t}txType=Rl.TransactionType.Other;txSubType="VestingRedeem";async build(t){let{account:n,network:o}=t,{txbParams:a}=this.data;return await Pl(a,n,o)}static fromData(t){return new i(t)}};var Ll=require("@msafe/sui3-utils");var Bl=async(i,e,t)=>await Ke(t,e).XCetusModule.convertPayload(i),El=async(i,e,t)=>await Ke(t,e).XCetusModule.redeemLockPayload(i),Nl=async(i,e,t)=>await Ke(t,e).XCetusModule.redeemDividendV3Payload(i.veNftId,i.rewardList),Wl=async(i,e,t)=>await Ke(t,e).XCetusModule.cancelRedeemPayload(i),_l=async(i,e,t)=>await Ke(t,e).XCetusModule.redeemPayload(i);var Lo=class i extends C{constructor(t){super(t);this.data=t}txType=Ll.TransactionType.Other;txSubType="xCETUSCancelRedeem";async build(t){let{account:n,network:o}=t,{txbParams:a}=this.data;return await Wl(a,n,o)}static fromData(t){return new i(t)}};var jl=require("@msafe/sui3-utils");var jo=class i extends C{constructor(t){super(t);this.data=t}txType=jl.TransactionType.Other;txSubType="xCETUSClaimStakingRwewards";async build(t){let{account:n,network:o}=t,{txbParams:a}=this.data;return await Nl(a,n,o)}static fromData(t){return new i(t)}};var Ul=require("@msafe/sui3-utils");var Uo=class i extends C{constructor(t){super(t);this.data=t}txType=Ul.TransactionType.Other;txSubType="xCETUSConvert";async build(t){let{account:n,network:o}=t,{txbParams:a}=this.data;return await Bl(a,n,o)}static fromData(t){return new i(t)}};var ql=require("@msafe/sui3-utils");var qo=class i extends C{constructor(t){super(t);this.data=t}txType=ql.TransactionType.Other;txSubType="xCETUSRedeem";async build(t){let{account:n,network:o}=t,{txbParams:a}=this.data;return await _l(a,n,o)}static fromData(t){return new i(t)}};var Fl=require("@msafe/sui3-utils");var Fo=class i extends C{constructor(t){super(t);this.data=t}txType=Fl.TransactionType.Other;txSubType="xCETUSRedeemLock";async build(t){let{account:n,network:o}=t,{txbParams:a}=this.data;return await El(a,n,o)}static fromData(t){return new i(t)}};var Ko=class{application="cetus";supportSDK="@mysten/sui";async deserialize(e){console.log("Cetus helper deserialize input: ",e);let{txbParams:t,action:n}=e;return{txType:Kl.TransactionType.Other,txSubType:n,intentionData:{txbParams:{...t},action:n}}}async build(e){let{suiClient:t,account:n,network:o}=e,a;switch(e.txSubType){case"OpenAndAddLiquidity":a=bo.fromData(e.intentionData);break;case"IncreaseLiquidity":a=Oo.fromData(e.intentionData);break;case"DecreaseLiquidity":a=To.fromData(e.intentionData);break;case"RemoveLiquidity":a=Bo.fromData(e.intentionData);break;case"ClaimFeeAndMining":a=So.fromData(e.intentionData);break;case"FarmingOpenAndAddLiquidity":a=wo.fromData(e.intentionData);break;case"FarmingIncreaseLiquidity":a=Do.fromData(e.intentionData);break;case"FarmingDecreaseLiquidity":a=ko.fromData(e.intentionData);break;case"FarmingRemoveLiquidity":a=xo.fromData(e.intentionData);break;case"FarmingClaimFeeAndReward":a=Co.fromData(e.intentionData);break;case"FarmingHarvest":a=vo.fromData(e.intentionData);break;case"FarmingBatchHarvest":a=Io.fromData(e.intentionData);break;case"FarmingStake":a=Ao.fromData(e.intentionData);break;case"FarmingUnstake":a=Mo.fromData(e.intentionData);break;case"xCETUSConvert":a=Uo.fromData(e.intentionData);break;case"xCETUSRedeemLock":a=Fo.fromData(e.intentionData);break;case"xCETUSClaimStakingRwewards":a=jo.fromData(e.intentionData);break;case"xCETUSCancelRedeem":a=Lo.fromData(e.intentionData);break;case"xCETUSRedeem":a=qo.fromData(e.intentionData);break;case"VestingRedeem":a=_o.fromData(e.intentionData);break;case"AggregatorSwap":a=Eo.fromData(e.intentionData);break;case"AddVaultsPosition":a=No.fromData(e.intentionData);break;case"RemoveVaultsPosition":a=Wo.fromData(e.intentionData);break;case"PosVestingRedeem":a=Ro.fromData(e.intentionData);break;default:throw new Error("not implemented")}return a.build({suiClient:t,account:n,network:o})}};var pu=require("@msafe/sui3-utils");var $l=Ut(require("sort-keys-recursive")),_=class{constructor(e){this.data=e}serialize(){return JSON.stringify((0,$l.default)(this.data))}};var yn=require("@mysten/sui.js/client");var Xr={};Vr(Xr,{contractId:()=>Zp,default:()=>ad,feeObjId:()=>nd,roleObjId:()=>td,status:()=>Yp,transaction:()=>Jp,upgradeCapObjId:()=>od,vaultObjId:()=>ed});var Jp="DiBZq4UmVVYiRL6ZJmFKYoHcxtxqrhsCXSkFyT7wUr3j",Yp="success",Zp="0x81c960dc653975fbd0072deca8afb92d322898c911622898ba1b2e3ad0c4bd8d",td="0xc6ec0bdee0bb59a72077e9acd2f42457043cf47080b3d3fad4d39abf28bba63a",ed="0xbc4021387fbac149119fd24e92be9e58f745774292f3a2a12e2ac6daf5363e1d",nd="0x4178f63970fe2daeb256dc5730ad172e82b3e8eb45f31b33e0daae72cd35e1e1",od="0xe1e9aa7d222d151bfe6dd83358b0d7fdcb11260f710800cfaf7ccc1b1e245115",ad={transaction:Jp,status:Yp,contractId:Zp,roleObjId:td,vaultObjId:ed,feeObjId:nd,upgradeCapObjId:od};var zr={};Vr(zr,{contractId:()=>sd,default:()=>pd,feeObjId:()=>ud,roleObjId:()=>cd,status:()=>rd,transaction:()=>id,upgradeCapObjId:()=>md,vaultObjId:()=>ld});var id="855FNDV8o8Z3fWULPnQo9qdhLJpsg7wZrkCpNyfw9KfB",rd="success",sd="0xc357c3985e8fb875d6b37141497af660779aa1bab0ec489b2213efd74067d1fa",cd="0x5ab49bdf9fd1413e328ef242b3f8d83dde791b38a0b627bfc87fb25c010d34f1",ld="0xb483558770d8eb26007f193b75db40f0a45f2e36863a687625885d4de6993378",ud="0x48453fc4d7cde3fe35aad89e5dfb496608a6a55ea529a1c0274681a808627f94",md="0x34279779a0d0d36bd5044b04830d607fa1b0ecf316548c8ac3a44151e4f1a42a",pd={transaction:id,status:rd,contractId:sd,roleObjId:cd,vaultObjId:ld,feeObjId:ud,upgradeCapObjId:md};var dd=(0,yn.getFullnodeUrl)("testnet"),fd=(0,yn.getFullnodeUrl)("testnet"),hd=(0,yn.getFullnodeUrl)("mainnet"),gd=(0,yn.getFullnodeUrl)("mainnet"),yd="https://bc3p6l5unl.execute-api.us-west-1.amazonaws.com/prod",bd="https://rolsbkota7.execute-api.us-west-1.amazonaws.com/prod",Sd="https://6p6mkx33ne.execute-api.us-west-1.amazonaws.com/prod",Td="https://xrae3mrjv5.execute-api.us-west-1.amazonaws.com/prod",Vl=Xr,Hl=zr,wd=new Map([["dev",{env:"dev",rpc:{url:dd},backend:{url:yd},contract:Vl}],["stg",{env:"stg",rpc:{url:fd},backend:{url:bd},contract:Vl}],["prev",{env:"prev",rpc:{url:hd},backend:{url:Sd},contract:Hl}],["prod",{env:"prod",rpc:{url:gd},backend:{url:Td},contract:Hl}]]);function Xl(i,e){let t=wd.get(i);if(!t)throw new Error(`Env not supported: ${i}`);return e&&e.rpc&&(t.rpc=e.rpc),e&&e.backend&&(t.backend=e.backend),e&&e.contract&&(t.contract=e.contract),t}var zl=require("@mysten/sui.js/client");var L=class extends Error{mpayErrorCode;context;constructor(e,t,n={}){let{cause:o,context:a}=n;o?super(`[MPay] ${t}: ${o}`):super(`[MPay] ${t}`),this.mpayErrorCode=e,this.context=a}};var $o=class extends L{constructor(){super(11,"Backend is not specified")}};var Vo=class extends L{constructor(){super(1,"Wallet not connected")}};var ie=Ut(require("axios"));var $e=class extends L{constructor(e,t){super(10,e,{context:t})}};var Ho=class i{constructor(e){this.apiURL=e}static parseResponseData(e){if(e instanceof ie.AxiosError)throw new $e(e.response?.statusText);if(e.status===200){if(e.data.success)return e.data.data;throw new $e(e.data.code)}throw new $e(e.status.toString())}async getIncomingStreams(e,t){let n=await ie.default.post(`${this.apiURL}/stream`,{recipient:e,...t});return i.parseResponseData(n)}async getOutgoingStreams(e,t){let n=await ie.default.post(`${this.apiURL}/stream`,{sender:e,...t});return i.parseResponseData(n)}async getStreamHistory(e){let t=await ie.default.post(`${this.apiURL}/stream-events`,e),n=i.parseResponseData(t);return n.data.forEach(o=>{let a=o;return a.data.type==="create_stream"?a.data.balance=BigInt(a.data.balance):a.data.type==="cancel_stream"?a.data.withdrawAmount=BigInt(a.data.withdrawAmount):a.data.type==="claim"||a.data.type==="auto_claim"?a.data.claimAmount=BigInt(a.data.claimAmount):a.data.type==="set_auto_claim"&&(a.data.enabled=!!a.data.enabled),a.createdAt=new Date(a.createdAt),a}),n}async getAllCoinTypes(e){let t=await ie.default.post(`${this.apiURL}/stream-info`,{address:e});return i.parseResponseData(t)}async getAllRecipients(e,t){let n=await ie.default.post(`${this.apiURL}/stream-info`,{sender:e,status:t});return i.parseResponseData(n)}async getAllSenders(e,t){let n=await ie.default.post(`${this.apiURL}/stream-info`,{recipient:e,status:t});return i.parseResponseData(n)}};var Ve=class i{signer;suiClient;envConfig;_backend;constructor(e){this.envConfig=e,this.suiClient=new zl.SuiClient({url:e.rpc.url}),e.backend&&(this._backend=new Ho(e.backend.url))}static new(e,t){let n=Xl(e,t);return new i(n)}get walletType(){return this.wallet?this.wallet.type:"disconnected"}get backend(){if(!this._backend)throw new $o;return this._backend}set backend(e){this._backend=e}connectWallet(e){this.signer=e}disconnect(){this.signer=void 0}get wallet(){if(!this.signer)throw new Vo;return this.signer}async walletAddress(){return this.wallet.address()}};var Ee=require("@mysten/sui.js/utils");var Cn=require("@mysten/sui.js/transactions");var Zr=require("@mysten/sui.js/transactions"),In=require("@mysten/sui.js/utils");var Gr=50n,Xo=10000n,Gl=25n,Qr=100000000n;var Jt=class{constructor(e){this.object=e}moveArg(e){return e.object(this.object)}},bn=class{constructor(e){this.objects=e}moveArgs(e){return e.makeMoveVec({objects:this.objects.map(t=>e.object(t))})}},me=class i{constructor(e){this.result=e;return new Proxy(this,{set(){throw new Error("The transaction result is a proxy, and does not support setting properties directly")},get(t,n){if(n in t)return Reflect.get(t,n);let o=c=>new i(t.result[c]);if(n===Symbol.iterator)return function*(){let c=0;for(;;)yield o(c),c++};if(typeof n=="symbol")return;let a=parseInt(n,10);if(!(Number.isNaN(a)||a<0))return o(a)}})}moveArg(){return this.result}};var Jr=require("buffer"),Ql=require("@mysten/sui.js/utils");var Sn=class extends L{constructor(e,t){super(3,e,{context:t})}};var zo=class{constructor(e){this.results=e}callResult(e){return this.results.results[e]}returnValue(e,t){return e.returnValues[t]}getValue(e=0,t=0){let n=this.callResult(e);return this.returnValue(n,t)}getAddress(e=0,t=0){let[n,o]=this.getValue(e,t);if(o!=="address")throw new Sn("Invalid contract return type.",{ctx:{expectType:"address",gotType:o}});return(0,Ql.normalizeSuiAddress)(Jr.Buffer.from(n).toString("hex"))}getU64(e=0,t=0){let[n,o]=this.getValue(e,t);if(o!=="u64")throw new Sn("Invalid contract return type.",{ctx:{expectType:"u64",gotType:o}});return Jr.Buffer.from(n).readBigInt64LE()}};var Yr=require("@mysten/sui.js/bcs");var V=class extends L{constructor(e,t,n){super(2,`Invalid input: ${e}`,{context:{fieldKey:t,fieldValue:n}})}};var Yl={groupId:"string",name:"string"},Id=64;function Zl(i){return tu(i),Yr.bcs.ser(Yl,i).toString("base64")}function Tn(i){let e=Yr.bcs.de(Yl,i,"base64");return tu(e),e}function tu(i){if(!Jl(i.name))throw new V("Invalid metadata: Name contains unknown character");if(!Jl(i.groupId))throw new V("Invalid metadata: Group ID contains unknown character");if(i.name.length>Id)throw new V("Invalid metadata: Name exceed max length 64")}function Jl(i){return/^[\x00-\x7F]+$/.test(i)}var wn=require("@mysten/sui.js/utils");function Go(i,e){return(0,wn.normalizeStructTag)(i)===(0,wn.normalizeStructTag)(e)}function pe(i,e){return(0,wn.normalizeStructTag)(i)===(0,wn.normalizeStructTag)(e)}var Qo="txn.gas";var eu=require("nanoid");function nu(){return(0,eu.nanoid)()}var Be=class i{constructor(e,t,n){this.globals=e;this.feeContract=t;this.streamContract=n}static convertCreateStreamInfoToInternal(e){return{metadata:Zl({name:e.name,groupId:nu()}),coinType:(0,In.normalizeStructTag)(e.coinType),recipients:e.recipients.map(t=>({address:t.address,cliffAmount:t.cliffAmount,amountPerEpoch:t.amountPerStep})),epochInterval:e.interval,numberEpoch:e.steps,startTime:e.startTimeMs,cancelable:e.cancelable}}async buildCreateStreamTransactionBlock(e){let t=new Zr.TransactionBlock,n=this.calculateFeesInternal(e),o=this.getCreateStreamCoinRequests(e,n),a=await this.wallet.requestCoins(o),c=await this.addMergeCoins(t,a[0]),l;o.length>1?l=await this.addMergeCoins(t,a[1]):l=c;for(let d=0;d<e.recipients.length;d++){let b=e.recipients[d],w=this.amountForRecipient(b,e.numberEpoch),I=this.getStreamFeeLocal(w),[k]=t.splitCoins(c,[t.pure(w+I,"u64")]),[v]=t.splitCoins(l,[t.pure(this.flatSuiFee,"u64")]);this.streamContract.createStream(t,{paymentCoin:new me(k),flatFeeCoin:new me(v),metadata:e.metadata,recipient:b.address,timeStart:e.startTime,cliff:b.cliffAmount,epochInterval:e.epochInterval,numEpoch:e.numberEpoch,amountPerEpoch:b.amountPerEpoch,cancelable:e.cancelable,coinType:e.coinType})}return t}calculateCreateStreamFees(e){let t=i.convertCreateStreamInfoToInternal(e);return this.calculateFeesInternal(t)}feeParams(){return{createFeePercent:{numerator:Gr,denominator:Xo},claimFeePercent:{numerator:Gl,denominator:Xo},flatFeePerStream:Qr}}async addMergeCoins(e,t){let n;return t.mergedCoins&&t.mergedCoins.length?(e.mergeCoins(e.object(t.primaryCoin),t.mergedCoins.map(o=>e.object(o))),n=e.object(t.primaryCoin)):t.primaryCoin===Qo?n=e.gas:n=e.object(t.primaryCoin),n}getCreateStreamCoinRequests(e,t){let n=e.coinType;return Go(n,In.SUI_TYPE_ARG)?[{coinType:n,amount:t.totalAmount+t.streamFeeAmount+t.flatFeeAmount}]:[{coinType:n,amount:t.totalAmount+t.streamFeeAmount},{coinType:In.SUI_TYPE_ARG,amount:t.flatFeeAmount}]}calculateFeesInternal(e){let t=e.recipients.reduce((o,a)=>{let c=this.amountForRecipient(a,e.numberEpoch),l=this.getStreamFeeLocal(c);return{totalAmount:o.totalAmount+c,streamFeeAmount:o.streamFeeAmount+l}},{totalAmount:0n,streamFeeAmount:0n});return{flatFeeAmount:BigInt(e.recipients.length)*this.flatSuiFee,...t}}amountForRecipient(e,t){return BigInt(e.amountPerEpoch)*BigInt(t)+BigInt(e.cliffAmount)}get flatSuiFee(){return Qr}getStreamFeeLocal(e){return e*Gr/Xo}async getStreamFeeRemote(e){let t=this.feeContract.streamingFee(new Zr.TransactionBlock,e),n=await this.globals.suiClient.devInspectTransactionBlock({sender:await this.globals.walletAddress(),transactionBlock:t});return new zo(n).getU64()}get wallet(){return this.globals.wallet}};var ts=require("@mysten/sui.js/transactions");var ou="0x0000000000000000000000000000000000000000000000000000000000000006";var He=class{constructor(e,t,n){this.moduleName=e;this.config=t;this.globals=n}addContractCall(e,t){let n=`${this.config.contractId}::${this.moduleName}::${t.method}`;return e.add(ts.Transactions.MoveCall({target:n,arguments:t.arguments.map(o=>o instanceof bn?o.moveArgs(e):o instanceof Jt?o.moveArg(e):o instanceof me?o.moveArg():e.pure(o)),typeArguments:t.typeArgs})),e}addTransactionBlock(e,t,n=[],o=[]){e.add(ts.Transactions.MoveCall({target:t,arguments:n.map(a=>a instanceof bn?a.moveArgs(e):a instanceof Jt?a.moveArg(e):a instanceof me?a.moveArg():e.pure(a)),typeArguments:o}))}makeObject(e){return typeof e=="string"?new Jt(e):e}vaultObject(){return new Jt(this.config.vaultObjId)}roleObject(){return new Jt(this.config.roleObjId)}feeObject(){return new Jt(this.config.feeObjId)}clockObject(){return new Jt(ou)}};var Xe=class i extends He{constructor(t,n){super(i.ModuleName,t,n);this.config=t;this.globals=n}static ModuleName="fee_module";static MethodName={set_streaming_fee:"set_streaming_fee",set_claim_fee:"set_claim_fee",set_streaming_flat_fee:"set_streaming_flat_fee",streaming_flat_fee:"streaming_flat_fee",streaming_fee:"streaming_fee",claim_fee:"claim_fee",fee_denominator:"fee_denominator"};setStreamingFee(t,n){let o=this.roleObject(),a=this.feeObject();return this.addContractCall(t,{method:i.MethodName.set_streaming_fee,arguments:[o,a,n],typeArgs:[]})}setStreamingFlatFee(t,n){let o=this.roleObject(),a=this.feeObject();return this.addContractCall(t,{method:i.MethodName.set_streaming_flat_fee,arguments:[o,a,n],typeArgs:[]})}setClaimFee(t,n){let o=this.roleObject(),a=this.feeObject();return this.addContractCall(t,{method:i.MethodName.set_claim_fee,arguments:[o,a,n],typeArgs:[]})}streamingFee(t,n){let o=this.feeObject();return this.addContractCall(t,{method:i.MethodName.streaming_fee,arguments:[o,n],typeArgs:[]})}claimFee(t,n){return this.addContractCall(t,{method:i.MethodName.claim_fee,arguments:[this.feeObject(),n],typeArgs:[]})}feeDenominator(t){return this.addContractCall(t,{method:i.MethodName.fee_denominator,arguments:[this.feeObject()],typeArgs:[]})}};var Yt=class i extends He{constructor(t,n){super(i.ModuleName,t,n);this.config=t;this.globals=n}static ModuleName="stream";static MethodName={create_stream:"create_stream",set_auto_claim:"set_auto_claim",cancel_stream:"cancel_stream",claim_stream:"claim_stream",claim_stream_by_proxy:"claim_stream_by_proxy",stream_current_epoch:"stream_current_epoch",now_milli_seconds:"now_milli_seconds"};createStream(t,n){let o=this.feeObject(),a=this.vaultObject(),c=this.makeObject(n.paymentCoin),l=this.makeObject(n.flatFeeCoin),d=this.clockObject();return this.addContractCall(t,{method:i.MethodName.create_stream,arguments:[o,a,c,l,n.metadata,n.recipient,n.timeStart,n.cliff,n.epochInterval,n.numEpoch,n.amountPerEpoch,n.cancelable,d],typeArgs:[n.coinType]})}setAutoClaim(t,n){let o=this.makeObject(n.streamId);return this.addContractCall(t,{method:i.MethodName.set_auto_claim,arguments:[o,n.enabled],typeArgs:[n.coinType]})}cancelStream(t,n){let o=this.makeObject(n.streamId),a=this.clockObject();return this.addContractCall(t,{method:i.MethodName.cancel_stream,arguments:[o,a],typeArgs:[n.coinType]})}claimStream(t,n){let o=this.makeObject(n.streamId),a=this.clockObject();return this.addContractCall(t,{method:i.MethodName.claim_stream,arguments:[o,a],typeArgs:[n.coinType]})}claimStreamByProxy(t,n){let o=this.makeObject(n.streamId),a=this.vaultObject(),c=this.feeObject(),l=this.clockObject();return this.addContractCall(t,{method:i.MethodName.claim_stream_by_proxy,arguments:[o,a,c,l],typeArgs:[n.coinType]})}get createStreamTarget(){return`${this.config.contractId}::${i.ModuleName}::${i.MethodName.create_stream}`}get setAutoClaimTarget(){return`${this.config.contractId}::${i.ModuleName}::${i.MethodName.set_auto_claim}`}get cancelStreamTarget(){return`${this.config.contractId}::${i.ModuleName}::${i.MethodName.cancel_stream}`}get claimStreamTarget(){return`${this.config.contractId}::${i.ModuleName}::${i.MethodName.claim_stream}`}get claimStreamByProxyTarget(){return`${this.config.contractId}::${i.ModuleName}::${i.MethodName.claim_stream_by_proxy}`}};var ze=class{constructor(e){this.globals=e;let t=e.envConfig.contract;this.feeContract=new Xe(t,e),this.streamContract=new Yt(t,e)}feeContract;streamContract;async createStreams(e){let t=Be.convertCreateStreamInfoToInternal(e);return this.createStreamHelper().buildCreateStreamTransactionBlock(t)}createStreamHelper(){return new Be(this.globals,this.feeContract,this.streamContract)}setAutoClaim(e,t,n){let o=new Cn.TransactionBlock;return this.streamContract.setAutoClaim(o,{streamId:e,enabled:t,coinType:n})}claimStream(e,t){let n=new Cn.TransactionBlock;return this.streamContract.claimStream(n,{streamId:e,coinType:t})}claimStreamByProxy(e,t){let n=new Cn.TransactionBlock;return this.streamContract.claimStreamByProxy(n,{streamId:e,coinType:t})}cancelStream(e,t){let n=new Cn.TransactionBlock;return this.streamContract.cancelStream(n,{streamId:e,coinType:t}),n}};var Ge=require("@mysten/sui.js/utils"),es=require("luxon");var Jo=class extends L{constructor(e,t){super(12,`Transaction failed: ${t}`,{context:{status:e,msg:t}})}};var Cd=1e3,Yo=class{constructor(e){this.globals=e;this.coinMetaHelper=new ns(e.suiClient),this.createStreamHelper=new ze(e).createStreamHelper()}coinMetaHelper;createStreamHelper;getStreamIdsFromCreateStreamResponse(e){if(e.effects?.status.status!=="success")throw new Jo(e.effects?.status.status,e.effects?.status.error);return e.objectChanges.filter(t=>t.type==="created"&&t.objectType.startsWith(`${this.globals.envConfig.contract.contractId}::stream::Stream`)).map(t=>t.objectId)}calculateCreateStreamFees(e){return this.createStreamHelper.calculateCreateStreamFees(e)}feeParams(){return this.createStreamHelper.feeParams()}calculateStreamAmount(e){if(e.steps===0n)throw new V("Invalid stream steps: 0");let t=e.cliff?e.cliff:{numerator:0n,denominator:100n},n=e.totalAmount*t.numerator/t.denominator,o=(e.totalAmount-n)/e.steps,c={realTotalAmount:o*e.steps+n,cliffAmount:n,amountPerStep:o};return this.validateStreamAmount(c,e.totalAmount),c}calculateTimelineByInterval(e){if(e.steps===0n)throw new V("Invalid stream steps: 0");let t=e.timeStart.plus(e.interval.toMillis()*Number(e.steps)),n={timeStart:e.timeStart,timeEnd:t,interval:e.interval,steps:e.steps};return this.validateTimeline(n),n}calculateTimelineByTotalDuration(e){if(e.steps===0n)throw new V("Invalid stream steps: 0");let t=BigInt(e.total.toMillis())/e.steps,n=e.timeStart.plus(es.Duration.fromMillis(Number(t*e.steps))),o={timeStart:e.timeStart,timeEnd:n,interval:es.Duration.fromMillis(Number(t)),steps:e.steps};return this.validateTimeline(o),o}async getBalance(e,t){let n=await this.globals.suiClient.getBalance({owner:e,coinType:t}),o=await this.getCoinMeta(t);return{...n,coinType:(0,Ge.normalizeStructTag)(n.coinType),coinMeta:o}}async getAllBalance(e){let t=await this.globals.suiClient.getAllBalances({owner:e}),n=await Promise.all(t.map(o=>this.getCoinMeta(o.coinType)));return t.map((o,a)=>({...o,coinType:(0,Ge.normalizeStructTag)(o.coinType),coinMeta:n[a]}))}async getCoinMeta(e){return this.coinMetaHelper.getCoinMeta(e)}async simulateTransactionBlock(e){return this.globals.suiClient.devInspectTransactionBlock({transactionBlock:e,sender:await this.globals.wallet.address()})}validateStreamAmount(e,t){if(e.amountPerStep===0n)throw new V("Stream amount too small","totalAmount",t);if(e.cliffAmount>e.realTotalAmount)throw new V("Invalid cliff settings")}validateTimeline(e){if(e.interval.toMillis()<Cd)throw new V("Interval shall be at least 1 second","interval",e.interval)}},ns=class{constructor(e){this.suiClient=e;this.coinMetaReg=new Map}coinMetaReg;async getCoinMeta(e){let t=(0,Ge.normalizeStructTag)(e||Ge.SUI_TYPE_ARG);if(this.coinMetaReg.has(t))return this.coinMetaReg.get(t);let n=await this.queryCoinMeta(t);return n&&this.coinMetaReg.set(t,n),n}async queryCoinMeta(e){return await this.suiClient.getCoinMetadata({coinType:e})||void 0}};var fe=require("@mysten/sui.js/utils"),ls=require("luxon");var Dn=require("@mysten/sui.js/transactions"),xn=require("@mysten/sui.js/utils"),iu=require("luxon");var Zo=class extends L{constructor(){super(7,"Connected wallet is not creator")}};var kn=class extends L{constructor(){super(8,"Connected wallet is not recipient")}};var vn=class extends L{constructor(e,t){super(6,e,{context:t})}};var At=class extends L{constructor(e,t={}){super(0,e,t)}};var ta=class extends L{constructor(e){super(5,"Stream not found",{context:{streamId:e}})}};var na=require("luxon"),au=(1n<<64n)-1n,ea=1e3;function os(i){let e;typeof i=="number"?e=i:typeof i=="bigint"?e=Number(i):e=i.toMillis();let t=Math.round(e/ea);return na.DateTime.fromMillis(t*ea)}function as(i){let e;typeof i=="number"?e=i:typeof i=="bigint"?e=Number(i):e=i.toMillis();let t=Math.round(e/ea);return na.Duration.fromMillis(t*ea)}var de=class i{constructor(e,t,n){this.globals=e;this.streamId=t;this.rawData=n;this.streamContract=new Yt(e.envConfig.contract,e)}streamContract;type="Stream";static async new(e,t){let n=await i.fetchStreamData(e,t);return new i(e,t,n)}static fromObjectData(e,t,n){let o=i.parseRawStreamData(t,n);return new i(e,t,o)}get info(){return{name:this.name,creator:this.creator,coinType:this.coinType,totalAmount:this.totalAmount,start:this.timeStart,end:this.timeEnd,cancelable:this.cancelable,cliffAmount:this.cliff,duration:this.duration,interval:this.interval,steps:this.totalSteps,nextReleaseDate:this.nextReleaseDate,nextReleaseAmount:this.nextReleaseAmount,groupId:this.groupId,streamId:this.streamId,recipient:this.recipient,progress:this.progress,autoClaim:this.autoClaim}}get groupCommonInfo(){return{name:this.name,groupId:this.groupId,creator:this.creator,start:this.timeStart,interval:this.interval,steps:this.totalSteps,cancelable:this.cancelable}}async refresh(){this.rawData=await i.fetchStreamData(this.globals,this.streamId)}refreshWithData(e){if(e.data?.objectId!==this.streamId)throw new At("Object Id does not align");this.rawData=i.parseRawStreamData(this.streamId,e)}async historyEvents(e){return this.globals.backend.getStreamHistory({streamId:this.streamId,pagination:e})}async cancel(){if(await this.globals.walletAddress()!==this.creator)throw new Zo;let e=new Dn.TransactionBlock;return this.streamContract.cancelStream(e,{streamId:this.streamId,coinType:this.coinType}),e}async claim(){if(await this.globals.walletAddress()!==this.recipient)throw new kn;let e=new Dn.TransactionBlock;return this.streamContract.claimStream(e,{streamId:this.streamId,coinType:this.coinType}),e}async setAutoClaim(e){if(await this.globals.walletAddress()!==this.recipient)throw new kn;let t=new Dn.TransactionBlock;return this.streamContract.setAutoClaim(t,{streamId:this.streamId,coinType:this.coinType,enabled:e}),t}async claimByProxy(){let e=new Dn.TransactionBlock;return this.streamContract.claimStreamByProxy(e,{streamId:this.streamId,coinType:this.coinType}),e}get wallet(){return this.globals.wallet}get client(){return this.globals.suiClient}get coinType(){return(0,xn.normalizeStructTag)(this.rawData.coinType)}get progress(){return{status:this.streamStatus,total:this.totalAmount,streamed:this.streamedAmount,claimed:this.claimedAmount,claimable:this.claimable,canceled:this.canceledAmount}}get balance(){return this.rawData.balance}get autoClaim(){return this.rawData.autoClaim}get amountPerEpoch(){return this.rawData.config.amountPerEpoch}get cancelable(){return this.rawData.config.cancelable}get cliff(){return this.rawData.config.cliff}get creator(){return this.rawData.config.creator}get interval(){return as(this.rawData.config.epochInterval)}get groupId(){let{metadata:e}=this.rawData.config;return Tn(e).groupId}get name(){let{metadata:e}=this.rawData.config;return Tn(e).name}get recipient(){return this.rawData.config.recipient}get timeStart(){return os(this.rawData.config.timeStart)}get duration(){let e=this.rawData.config,t=e.epochInterval*e.totalEpoch;return as(t)}get timeEnd(){return this.timeStart.plus(this.duration)}get totalSteps(){return this.rawData.config.totalEpoch}get claimable(){return this.streamedAmount-this.claimedAmount}get nextReleaseDate(){return this.currentEpoch===-1n?this.timeStart:this.currentEpoch>=this.totalSteps||this.isCanceled?null:os((this.currentEpoch+1n)*this.rawData.config.epochInterval+this.rawData.config.timeStart)}get nextReleaseAmount(){return this.currentEpoch===-1n?this.cliff:this.currentEpoch>=this.totalSteps||this.isCanceled?null:this.amountPerEpoch}get streamStatus(){let e=this.rawData.status.status;return e===16?"CANCELED":e===17?"SETTLED":e===1?"COMPLETED":this.currentEpoch>=this.totalSteps?"STREAMED":"STREAMING"}get streamedAmount(){return this.currentEpoch===-1n?0n:this.isCanceled?this.rawData.status.epochCanceled*this.amountPerEpoch+this.cliff:this.currentEpoch*this.amountPerEpoch+this.cliff}get claimedAmount(){return this.rawData.status.epochClaimed===au?0n:this.rawData.status.epochClaimed*this.amountPerEpoch+this.cliff}get currentEpoch(){let e=iu.DateTime.now().toMillis(),t=this.timeStart.toMillis();if(e<t)return-1n;let n=Math.floor((e-t)/Number(this.rawData.config.epochInterval));return BigInt(n)>Number(this.rawData.config.totalEpoch)?this.rawData.config.totalEpoch:BigInt(n)}get totalAmount(){let e=this.rawData.config;return e.amountPerEpoch*e.totalEpoch+e.cliff}get isCanceled(){let e=this.rawData.status.status;return e===16||e===17}get canceledAmount(){return this.isCanceled?this.totalAmount-this.streamedAmount:0n}static async fetchStreamData(e,t){let n=await e.suiClient.getObject({id:t,options:{showContent:!0,showType:!0}});return i.parseRawStreamData(t,n)}static parseRawStreamData(e,t){if(t.error)throw t.error.code==="notExists"?new ta(e):new vn(`get stream data: ${t.error.code}`,{streamId:e,...t.error});let n=t.data.content;if(n.dataType!=="moveObject")throw new vn("Unexpected object type",{gotType:n.dataType});let{typeParams:o}=(0,xn.parseStructTag)(n.type),a=(0,xn.normalizeStructTag)(o[0]),c=n.fields,l=c.config.fields,d=c.status.fields;return{coinType:a,autoClaim:c.auto_claim,balance:BigInt(c.balance.fields.balance),config:{amountPerEpoch:BigInt(l.amount_per_epoch),cancelable:l.cancelable,cliff:BigInt(l.cliff),creator:l.creator,epochInterval:BigInt(l.epoch_interval),metadata:l.metadata,recipient:l.recipient,timeStart:BigInt(l.time_start),totalEpoch:BigInt(l.total_epoch)},status:{status:d.status,epochCanceled:BigInt(d.epoch_canceled),epochClaimed:BigInt(d.epoch_claimed)}}}};var Qe=class extends L{constructor(e,t){super(9,`Invalid stream group: ${e}`,{context:t})}};async function rs(i){let e=[];for(;await i.hasNext();){let t=await i.next();e.push(t)}return e&&Array.isArray(e[0])?e.flat(1):e}var is=class{constructor(e){this.requester=e;this.curPage=void 0,this.init=!0}curPage;init;async hasNext(){if(this.init)return this.curPage||(this.curPage=await this.requester.doNextRequest()),!!this.curPage.data?.length||this.curPage.hasNext;if(!this.curPage)throw new Error("invalid implementation of iterator");return this.curPage.hasNext}async next(){return this.init?(this.init=!1,this.curPage||(this.curPage=await this.requester.doNextRequest()),this.curPage.data):(this.curPage=await this.requester.doNextRequest(),this.curPage.data)}},Je=class{constructor(e){this.requester=e;this.pager=new is(e),this.curData=[],this.cursor=0}cursor;pager;curData;async hasNext(){return this.cursor<this.curData.length-1?!0:this.pager.hasNext()}async next(){for(this.cursor+=1;this.cursor>=this.curData.length;)if(await this.pager.hasNext())this.curData=await this.pager.next(),this.cursor=0;else throw new Error("not more data");return this.curData[this.cursor]}};var kd=25;async function cs(i,e,t){let n=new An(e),o=new Mn(i,n,t);return await rs(o)}var An=class{constructor(e){this.ids=e;this.cursor=-1}cursor;async hasNext(){return this.cursor<this.ids.length-1}async next(){if(this.cursor+=1,this.cursor>=this.ids.length)throw new Error("invalid iterator implementation");return this.ids[this.cursor]}},Mn=class extends Je{constructor(t,n,o){super(new ss(t,n,o));this.suiClient=t;this.idIter=n;this.options=o}},ss=class{constructor(e,t,n){this.suiClient=e;this.stringIter=t;this.options=n;this.filter=n?.filter,this.pageSize=n?.pageSize||kd,this.objectOptions=n?.objectOptions||{showType:!0,showContent:!0}}filter;pageSize;objectOptions;async doNextRequest(){let e=[];for(;e.length<this.pageSize&&await this.stringIter.hasNext();){let a=await this.stringIter.next();a&&e.push(a)}let t=await this.suiClient.multiGetObjects({ids:e,options:this.objectOptions}),n;if(this.filter){let{filter:o}=this;n=t.filter(a=>o?.(a))}else n=t;return{data:n,hasNext:await this.stringIter.hasNext()}}};var oa=class i{constructor(e,t){this.globals=e;this.streams=t;if(t.length===0)throw new Qe("stream size 0");let n=t.map(a=>a.groupId);if(new Set(n).size!==1)throw new V("Stream does not have same group ID")}type="StreamGroup";static async new(e,t){let n=await cs(e.suiClient,t);return n.forEach(o=>{if(!o)throw new At("stream group object data undefined")}),i.newFromObjectResponse(e,t,n)}static async newFromObjectResponse(e,t,n){let o=await i.parseGroupStreams(e,t,n);return new i(e,o)}static checkStreamGroup(e){let t=e.map(a=>a.groupCommonInfo),n=t[0],o=!0;return t.forEach(a=>{vd(n,a)||(o=!1)}),o}async refresh(){let e=await cs(this.globals.suiClient,this.streams.map(t=>t.streamId));this.streams.forEach((t,n)=>{t.refreshWithData(e[n])})}get groupId(){return this.streams[0].groupId}get creator(){return this.streams[0].creator}get info(){return{groupId:this.groupId,streamIds:this.streams.map(e=>e.streamId),progress:this.progress,name:this.streams[0].name,creator:this.creator,coinType:this.streams[0].coinType,totalAmount:this.streams.reduce((e,t)=>e+t.totalAmount,0n),start:this.streams[0].timeStart,end:this.streams[0].timeEnd,cancelable:this.streams[0].cancelable,cliffAmount:this.streams.reduce((e,t)=>e+t.cliff,0n),duration:this.streams[0].duration,interval:this.streams[0].interval,steps:this.streams[0].totalSteps,nextReleaseAmount:this.streams.reduce((e,t)=>t.nextReleaseAmount===null?e:e+t.nextReleaseAmount,0n),nextReleaseDate:this.streams[0].nextReleaseDate}}get progress(){return{total:this.streams.reduce((e,t)=>e+t.totalAmount,0n),streamed:this.streams.reduce((e,t)=>e+t.streamedAmount,0n),claimed:this.streams.reduce((e,t)=>e+t.claimedAmount,0n),claimable:this.streams.reduce((e,t)=>e+t.claimable,0n),canceled:this.streams.reduce((e,t)=>e+t.canceledAmount,0n)}}async historyEvents(e){return this.globals.backend.getStreamHistory({groupId:this.groupId,pagination:e})}static async parseGroupStreams(e,t,n){let o=n.map((a,c)=>de.fromObjectData(e,t[c],a)).filter(a=>!!a);if(new Set(o.map(a=>a.groupId)).size!==1)throw new Qe("Not same group ID");if(!this.checkStreamGroup(o))throw new Qe("Not same stream settings");return o}};function vd(i,e){return i.name===e.name&&i.groupId===e.groupId&&i.creator===e.creator&&i.start.toMillis()===e.start.toMillis()&&i.interval.toMillis()===e.interval.toMillis()&&i.steps===e.steps&&i.cancelable===e.cancelable}var On=class i{constructor(e,t){this.it=e;this.pageSize=t}static async newIncoming(e){let t=await aa.newIncoming(e);return new i(t,e.pageSize)}static async newOutgoing(e){let t=await aa.newOutgoing(e);return new i(t,e.pageSize)}async hasNext(){return this.it.hasNext()}async next(){let e=[];for(;e.length<this.pageSize&&await this.it.hasNext();)e.push(await this.it.next());return e}},aa=class i{constructor(e){this.requester=e}cachedNext;static async newIncoming(e){let t=await ia.newIncomingQuery(e);return new i(t)}static async newOutgoing(e){let t=await ia.newOutgoingQuery(e);return new i(t)}async hasNext(){return this.cachedNext===void 0&&(this.cachedNext=await this.requester.doNextRequest()),this.cachedNext!==null}async next(){if(this.cachedNext===void 0){let t=await this.requester.doNextRequest();if(t===null)throw new At("No more results");return t}let e=this.cachedNext;if(this.cachedNext=void 0,e===null)throw new At("No more results");return e}},ia=class i{constructor(e,t,n,o){this.globals=e;this.recipient=t;this.groupRefs=n;this.query=o;this.current=0;let a=new An(n.flat().map(c=>c.streamId));this.objectIter=new Mn(e.suiClient,a)}current=0;objectIter;static async newIncomingQuery(e){let t=Od(e.query),n=await e.globals.walletAddress(),a=(await e.globals.backend.getIncomingStreams(n,t)).filter(l=>(0,fe.normalizeSuiAddress)(l.recipient)===(0,fe.normalizeSuiAddress)(n)),c=ru(a);return new i(e.globals,n,c,e.query)}static async newOutgoingQuery(e){let t=Pd(e.query),n=await e.globals.walletAddress(),o=await e.globals.backend.getOutgoingStreams(n,t),a=ru(o);return new i(e.globals,n,a,e.query)}async doNextRequest(){if(this.current>=this.groupRefs.length)return null;let e=this.groupRefs[this.current];if(e.length===1){let t=await Ad(this.globals,e[0].streamId,this.objectIter);return this.current++,su(t,this.query)?t:this.doNextRequest()}if(e.length>1){let t=await Md(this.globals,e.map(n=>n.streamId),this.objectIter);return this.current++,xd(t,this.query)?t:this.doNextRequest()}throw new At("Stream group with no stream")}};function ru(i){let e=new Map;return i.forEach(t=>{let n=e.get(t.groupId);n?(n.push(t),e.set(t.groupId,n)):e.set(t.groupId,[t])}),Array.from(e.values()).sort((t,n)=>ls.DateTime.fromISO(n[0].createDate).toMillis()-ls.DateTime.fromISO(t[0].createDate).toMillis())}function su(i,e){if(e===void 0)return!0;let t=Dd(i,e.status);if(e&&"claimable"in e&&e.claimable!==void 0){let n=e.claimable?i.progress.claimable!==0n:i.progress.claimable===0n;return t&&n}return t}function Dd(i,e){return e===void 0?!0:Array.isArray(e)?e.includes(i.progress.status):i.progress.status===e}function xd(i,e){if(!e)return!0;let t=!1;return i.streams.forEach(n=>{su(n,e)&&(t=!0)}),t}async function Ad(i,e,t){let n=await cu(t,e);return de.fromObjectData(i,e,n)}async function Md(i,e,t){let n=[];for(;n.length<e.length;){let o=await cu(t,e[n.length]);n.push(o)}return oa.newFromObjectResponse(i,e,n)}async function cu(i,e){if(!await i.hasNext())throw new At("object iterator has been consumed");let t=await i.next();if(!t||t.error||t.data===void 0||t.data===null)throw new At("object iterator undefined response",{cause:t?.error});if(t?.data?.objectId!==e)throw new At("stream id not aligned");return t}function Od(i){return{status:us(i?.status),coinType:lu(i?.coinType),sender:uu(i?.sender)}}function Pd(i){return{status:us(i?.status),coinType:lu(i?.coinType),recipient:uu(i?.recipient)}}function us(i){return i===void 0||i.length===0?"all":Array.isArray(i)?i.reduce((e,t)=>{let n=us(t);return!e||e===n?n:"all"},void 0):Rd(i)}function Rd(i){switch(i){case"STREAMING":case"STREAMED":case"CANCELED":return"active";case"COMPLETED":case"SETTLED":return"inactive";default:throw new V("Unknown stream filtered status")}}function lu(i){if(i)return Array.isArray(i)?i.length!==0?i.map(e=>(0,fe.normalizeStructTag)(e)):void 0:(0,fe.normalizeStructTag)(i)}function uu(i){if(i)return Array.isArray(i)?i.length!==0?i.map(e=>(0,fe.normalizeSuiAddress)(e)):void 0:(0,fe.normalizeSuiAddress)(i)}var ra=class extends L{constructor(t,n,o){super(4,`Not enough balance: ${t}`,{context:{coinType:t,requestAmount:n,gotAmount:o}});this.coinType=t;this.requestAmount=n;this.gotAmount=o}};var Bd=25;async function mu(i,e,t,n="0x2::sui::SUI",o=Bd){let a=new ms(i,e,n,o),c=BigInt(0),l=[];for(;await a.hasNext()&&c<t;){let d=await a.next();d&&(l.push(d),c+=BigInt(d.balance))}if(c<t)throw new ra(n,t,c);return l}var ms=class extends Je{constructor(t,n,o,a){super(new ps(t,n,o,a));this.suiClient=t;this.owner=n;this.coinType=o;this.reqPageSize=a}},ps=class{constructor(e,t,n,o){this.suiClient=e;this.owner=t;this.coinType=n;this.reqPageSize=o;if(o<=0)throw new At("Invalid reqPageSize")}nextCursor;async doNextRequest(){let e=await this.suiClient.getCoins({owner:this.owner,coinType:this.coinType,cursor:this.nextCursor,limit:this.reqPageSize});return this.nextCursor=e.nextCursor,{data:e.data,hasNext:e.hasNextPage}}};var ds=class{constructor(e){this.msafe=e}get type(){return"msafe"}async address(){return this.msafe.address()}async requestCoins(e){return this.msafe.requestCoins(e)}},sa=class{constructor(e){this.account=e}async address(){return this.account.address}},fs=class{constructor(e,t){this.singleWallet=e;this.suiClient=t}get type(){return"single"}async address(){return this.singleWallet.address()}async requestCoins(e){return Promise.all(e.map(t=>this.requestCoin(t)))}async requestCoin(e){if(Go(e.coinType,Ee.SUI_TYPE_ARG))return{primaryCoin:Qo};if(e.amount<=0)throw new V("Invalid coin request","coinAmount",e.amount);let t=await mu(this.suiClient,await this.address(),e.amount,e.coinType);if(t.length===0)throw new At("no coins available");return{primaryCoin:t[0].coinObjectId,mergedCoins:t.slice(1).map(n=>n.coinObjectId)}}},ca=class{globals;helper;constructor(e,t){this.globals=Ve.new(e,t),this.helper=new Yo(this.globals)}connectSingleWallet(e){let t=new fs(e,this.globals.suiClient);this.globals.connectWallet(t)}connectMSafeAccount(e){let t=new ds(e);this.globals.connectWallet(t)}async createStream(e){return this.builder().createStreams(e)}async getStream(e){return de.new(this.globals,e)}async getIncomingStreams(e,t=10){return On.newIncoming({globals:this.globals,query:e,pageSize:t})}async getOutgoingStreams(e,t=10){return On.newOutgoing({globals:this.globals,query:e,pageSize:t})}async getCoinTypesForStreamFilter(){let e=await this.wallet.address();return(await this.globals.backend.getAllCoinTypes(e)).map(n=>(0,Ee.normalizeStructTag)(n))}async getRecipientsForStreamFilter(e){let t=await this.wallet.address();return(await this.globals.backend.getAllRecipients(t,e)).map(o=>(0,Ee.normalizeSuiAddress)(o))}async getCreatorsForStreamFilter(e){let t=await this.wallet.address();return(await this.globals.backend.getAllSenders(t,e)).map(o=>(0,Ee.normalizeSuiAddress)(o))}get wallet(){return this.globals.wallet}builder(){return new ze(this.globals)}};var Kt=class extends _{application="mpay";getClient(e,t){let n=new ca(e==="sui:mainnet"?"prod":"dev");return n.connectSingleWallet(new sa(t)),n}};var Pn=class extends Kt{constructor(t){super(t);this.data=t}txType=pu.TransactionType.Stream;txSubType="Cancel";async build(t){let{network:n,account:o}=t;return(await this.getClient(n,o).getStream(this.data.streamId)).cancel()}};var du=require("@msafe/sui3-utils");var Rn=class extends Kt{constructor(t){super(t);this.data=t}txType=du.TransactionType.Stream;txSubType="ClaimByProxy";async build(t){let{network:n,account:o}=t;return(await this.getClient(n,o).getStream(this.data.streamId)).claimByProxy()}};var fu=require("@msafe/sui3-utils");var Bn=class extends Kt{constructor(t){super(t);this.data=t}txType=fu.TransactionType.Stream;txSubType="Claim";async build(t){let{network:n,account:o}=t;return(await this.getClient(n,o).getStream(this.data.streamId)).claim()}};var hu=require("@msafe/sui3-utils");var En=class extends Kt{constructor(t){super(t);this.data=t}txType=hu.TransactionType.Stream;txSubType="CreateStream";async build(t){let{network:n,account:o}=t;return this.getClient(n,o).createStream(this.data)}};var hs=require("@mysten/sui.js/bcs"),he=require("@mysten/sui.js/utils"),Ye=class i{constructor(e,t){this.moveCall=e;this.txb=t}decodeSharedObjectId(e){let t=this.getInputParam(e);return i.getSharedObjectId(t)}decodeOwnedObjectId(e){let t=this.getInputParam(e);return i.getOwnedObjectId(t)}decodeInputU64(e){let t=this.decodePureArg(e,"u64");return BigInt(t)}decodeInputAddress(e){let t=this.decodePureArg(e,"address");return(0,he.normalizeSuiAddress)(t)}decodeInputString(e){return this.decodePureArg(e,"string")}decodeInputBool(e){return this.decodePureArg(e,"bool")}decodePureArg(e,t){let n=this.getInputParam(e);return i.getPureInputValue(n,t)}getInputParam(e){let t=this.moveCall.arguments[e];if(t.kind!=="Input")throw new Error("not input type");return this.txb.blockData.inputs[t.index]}static getPureInputValue(e,t){if(e.type!=="pure")throw new Error("not pure argument");if(typeof e.value=="object"&&"Pure"in e.value){let n=e.value.Pure;return hs.bcs.de(t,new Uint8Array(n))}return e.value}static getOwnedObjectId(e){if(e.type!=="object")throw new Error(`not object argument: ${JSON.stringify(e)}`);if(typeof e.value=="object"){if(!("Object"in e.value)||!("ImmOrOwned"in e.value.Object))throw new Error("not ImmOrOwned");return(0,he.normalizeSuiAddress)(e.value.Object.ImmOrOwned.objectId)}return(0,he.normalizeSuiAddress)(e.value)}static getSharedObjectId(e){if(e.type!=="object")throw new Error(`not object argument: ${JSON.stringify(e)}`);if(typeof e.value!="object")return(0,he.normalizeSuiAddress)(e.value);if(!("Object"in e.value)||!("Shared"in e.value.Object))throw new Error("not Shared");return(0,he.normalizeSuiAddress)(e.value.Object.Shared.objectId)}static getPureInput(e,t){if(e.type!=="pure")throw new Error("not pure argument");if(typeof e.value!="object")return e.value;if(!("Pure"in e.value))throw new Error("Pure not in value");let n=e.value.Pure;return hs.bcs.de(t,new Uint8Array(n))}typeArg(e){return(0,he.normalizeStructTag)(this.moveCall.typeArguments[e])}txArg(e){return this.moveCall.arguments[e]}};var la=class{constructor(e,t){this.globals=e;this.txb=t}decode(){let e=this.decodeCreateStreamInfo(),t=this.createStreamHelper().calculateCreateStreamFees(e);return{type:"CreateStream",info:e,fees:t}}decodeCreateStreamInfo(){let t=this.createStreamTransactions().map(n=>this.getCreationInfoFromMoveCall(n));return this.aggregateGroupStreamInfo(t)}createStreamTransactions(){let e=this.transactions.filter(t=>t.kind==="MoveCall"&&pe(t.target,this.contract.createStreamTarget));if(e.length===0)throw new At("No create stream transactions");return e.map(t=>new Ye(t,this.txb))}getCreationInfoFromMoveCall(e){let t=e.decodeInputString(4),{name:n,groupId:o}=Tn(t),a=e.decodeInputAddress(5),c=e.decodeInputU64(6),l=e.decodeInputU64(7),d=e.decodeInputU64(8),b=e.decodeInputU64(9),w=e.decodeInputU64(10),I=e.decodeInputBool(11),k=e.typeArg(0);return{name:n,groupId:o,recipient:a,timeStart:c,cliff:l,epochInterval:d,totalEpoch:b,amountPerEpoch:w,cancelable:I,coinType:k}}aggregateGroupStreamInfo(e){if(new Set(e.map(o=>JSON.stringify({name:o.name,groupId:o.groupId,timeStart:String(o.timeStart),epochInterval:String(o.epochInterval),totalEpoch:String(o.totalEpoch),cancelable:o.cancelable,coinType:o.coinType}))).size!==1)throw new V("Stream group not have common info");let n=e.map(o=>({address:o.recipient,amountPerStep:o.amountPerEpoch,cliffAmount:o.cliff}));return{name:e[0].name,coinType:e[0].coinType,recipients:n,interval:e[0].epochInterval,steps:e[0].totalEpoch,startTimeMs:e[0].timeStart,cancelable:e[0].cancelable}}mergeCoinTransactions(){return this.transactions.filter(e=>e.kind==="MergeCoins")}get transactions(){return this.txb.blockData.transactions}get contract(){return new Yt(this.globals.envConfig.contract,this.globals)}get feeContract(){return new Xe(this.globals.envConfig.contract,this.globals)}createStreamHelper(){return new Be(this.globals,this.feeContract,this.contract)}getInputArg(e){if(e.kind!=="Input")throw new Error("not input type");return"value"in e?e:this.txb.blockData.inputs[e.index]}};var ua=class{constructor(e,t){this.globals=e;this.txb=t;this.contract=new Yt(e.envConfig.contract,e)}contract;decode(){if(this.isCreateStreamTransaction())return this.decodeCreateStreamTransaction();if(this.isClaimByProxyTransaction())return this.decodeClaimByProxyTransaction();if(this.isSetAutoClaimTransaction())return this.decodeSetAutoClaimTransaction();if(this.isCancelStreamTransaction())return this.decodeCancelStreamTransaction();if(this.isClaimStreamTransaction())return this.decodeClaimTransaction();throw new Error("Unknown stream transaction type")}get transactions(){return this.txb.blockData.transactions}isCreateStreamTransaction(){return this.transactions.findIndex(t=>t.kind==="MoveCall"&&pe(t.target,this.contract.createStreamTarget))!==-1}isSetAutoClaimTransaction(){return this.transactions.length===1&&this.transactions[0].kind==="MoveCall"&&pe(this.transactions[0].target,this.contract.setAutoClaimTarget)}isCancelStreamTransaction(){return this.transactions.length===1&&this.transactions[0].kind==="MoveCall"&&pe(this.transactions[0].target,this.contract.cancelStreamTarget)}isClaimStreamTransaction(){return this.transactions.length===1&&this.transactions[0].kind==="MoveCall"&&pe(this.transactions[0].target,this.contract.claimStreamTarget)}isClaimByProxyTransaction(){return this.transactions.length===1&&this.transactions[0].kind==="MoveCall"&&pe(this.transactions[0].target,this.contract.claimStreamByProxyTarget)}decodeCreateStreamTransaction(){return new la(this.globals,this.txb).decode()}decodeSetAutoClaimTransaction(){let e=this.helper.decodeSharedObjectId(0),t=this.helper.decodeInputBool(1);return{type:"SetAutoClaim",streamId:e,enabled:t}}decodeClaimTransaction(){let e=this.helper.decodeSharedObjectId(0);return{type:"Claim",streamId:e}}decodeClaimByProxyTransaction(){let e=this.helper.decodeSharedObjectId(0);return{type:"ClaimByProxy",streamId:e}}decodeCancelStreamTransaction(){let e=this.helper.decodeSharedObjectId(0);return{type:"Cancel",streamId:e}}get helper(){let e=this.transactions[0];return new Ye(e,this.txb)}};var gu=require("@msafe/sui3-utils");var Nn=class extends Kt{constructor(t){super(t);this.data=t}txType=gu.TransactionType.Stream;txSubType="SetAutoClaim";async build(t){let{network:n,account:o}=t;return(await this.getClient(n,o).getStream(this.data.streamId)).setAutoClaim(this.data.enabled)}};var ma=class{application="mpay";supportSDK="@mysten/sui.js";async deserialize(e){let{network:t,transactionBlock:n}=e,o=Ve.new(t==="sui:mainnet"?"prod":"dev"),c=new ua(o,n).decode(),l;switch(c.type){case"CreateStream":l=new En(c.info);break;case"SetAutoClaim":l=new Nn({streamId:c.streamId,enabled:c.enabled});break;case"Claim":l=new Bn({streamId:c.streamId});break;case"ClaimByProxy":l=new Rn({streamId:c.streamId});break;case"Cancel":l=new Pn({streamId:c.streamId});break;default:throw new Error(`Unknown transaction type: ${c}`)}return{txType:l.txType,txSubType:l.txSubType,intentionData:l.data}}async build(e){let{intentionData:t}=e,n;switch(e.txSubType){case"CreateStream":n=new En(t);break;case"Claim":n=new Bn(t);break;case"ClaimByProxy":n=new Rn(t);break;case"SetAutoClaim":n=new Nn(t);break;case"Cancel":n=new Pn(t);break;default:throw new Error("not implemented")}return n.build({...e})}};var Wn=require("@msafe/sui3-utils");var yu=require("@msafe/sui3-utils");var pa=class i extends _{constructor(t){super(t);this.data=t}txType;txSubType;async build(t){let{suiClient:n,account:o}=t;return(0,yu.buildCoinTransferTxb)(n,this.data,o.address)}static fromData(t){return new i(t)}};var bu=require("@msafe/sui3-utils");var da=class i extends _{constructor(t){super(t);this.data=t}txType;txSubType;async build(t){let{suiClient:n,account:o}=t;return(0,bu.buildObjectTransferTxb)(n,this.data,o.address)}static fromData(t){return new i(t)}};var fa=class{application="msafe-core";supportSDK="@mysten/sui.js";constructor(){this.application=Wn.TransactionDefaultApplication}deserialize(){throw new Error("MSafe core transaction intention should be build from API")}async build(e){let{suiClient:t,account:n}=e,o;switch(e.txSubType){case Wn.TransactionSubTypes.assets.coin.send:o=pa.fromData(e.intentionData);break;case Wn.TransactionSubTypes.assets.object.send:o=da.fromData(e.intentionData);break;default:throw new Error("not implemented")}return o.build({suiClient:t,account:n})}};var Ou=require("@msafe/sui3-utils");var Su=!1,_n={ProtocolPackage:"0x81c408448d0d57b3e371ea94de1d40bf852784d3e225de1e74acab3e8395c18f",StorageId:"0xbb4e2f4b6205c2e2a2db47aeb4f830796ec7c005f88537ee775986639bc442fe",Incentive:"0xaaf735bf83ff564e1b219a0d644de894ef5bdc4b2250b126b2a46dd002331821",IncentiveV2:"0xf87a8acb8b81d14307894d12595541a73f19933f88e1326d5be349c7a6f7559c",gasBudget:5e7,PriceOracle:"0x1568865ed9a0b5ec414220e8f79b3d04c77acc82358f6e5ae4635687392ffbef",ReserveParentId:"0xe6d4c6610b86ce7735ea754596d71d72d10c7980b5052fc3c8cdf8d09fea9b4b",pool:{sui:{name:"SUI",assetId:0,poolId:"0x96df0fce3c471489f4debaaa762cf960b3d97820bd1f3f025ff8190730e958c5",fondPoolId:"0xf975bc2d4cca10e3ace8887e20afd77b46c383b4465eac694c4688344955dea4",type:"0x2::sui::SUI",coinType:"sui",reserveObjectId:"0xab644b5fd11aa11e930d1c7bc903ef609a9feaf9ffe1b23532ad8441854fbfaf",borrowBalanceParentId:"0xe7ff0daa9d090727210abe6a8b6c0c5cd483f3692a10610386e4dc9c57871ba7",supplyBalanceParentId:"0x589c83af4b035a3bc64c40d9011397b539b97ea47edf7be8f33d643606bf96f8"},wusdc:{name:"wUSDC",assetId:1,coinType:"wusdc",poolId:"0xa02a98f9c88db51c6f5efaaf2261c81f34dd56d86073387e0ef1805ca22e39c8",type:"0x5d4b302506645c37ff133b98c4b50a5ae14841659738d6d733d59d0d217a93bf::coin::COIN",reserveObjectId:"0xeb3903f7748ace73429bd52a70fff278aac1725d3b58afa781f25ce3450ac203",borrowBalanceParentId:"0x8a3aaa817a811131c624658f6e77cba04ab5829293d2c49c1a9cce8ac9c8dec4",supplyBalanceParentId:"0x8d0a4467806458052d577c8cd2be6031e972f2b8f5f77fce98aa12cd85330da9"},usdt:{name:"USDT",coinType:"usdt",assetId:2,poolId:"0x0e060c3b5b8de00fb50511b7a45188c8e34b6995c01f69d98ea5a466fe10d103",type:"0xc060006111016b8a020ad5b33834984a437aaa7d3c74c18e09a95d48aceab08c::coin::COIN",reserveObjectId:"0xb8c5eab02a0202f638958cc79a69a2d30055565caad1684b3c8bbca3bddcb322",borrowBalanceParentId:"0xc14d8292a7d69ae31164bafab7ca8a5bfda11f998540fe976a674ed0673e448f",supplyBalanceParentId:"0x7e2a49ff9d2edd875f82b76a9b21e2a5a098e7130abfd510a203b6ea08ab9257"},weth:{name:"WETH",coinType:"weth",assetId:3,poolId:"0x71b9f6e822c48ce827bceadce82201d6a7559f7b0350ed1daa1dc2ba3ac41b56",type:"0xaf8cd5edc19c4512f4259f0bee101a40d41ebed738ade5874359610ef8eeced5::coin::COIN",reserveObjectId:"0xafecf4b57899d377cc8c9de75854c68925d9f512d0c47150ca52a0d3a442b735",borrowBalanceParentId:"0x7568d06a1b6ffc416a36c82791e3daf0e621cf19d4a2724fc6f74842661b6323",supplyBalanceParentId:"0xa668905b1ad445a3159b4d29b1181c4a62d864861b463dd9106cc0d97ffe8f7f"},cetus:{name:"CETUS",coinType:"cetus",assetId:4,poolId:"0x3c376f857ec4247b8ee456c1db19e9c74e0154d4876915e54221b5052d5b1e2e",type:"0x06864a6f921804860930db6ddbe2e16acdf8504495ea7481637a1c8b9a8fe54b::cetus::CETUS",reserveObjectId:"0x66a807c06212537fe46aa6719a00e4fa1e85a932d0b53ce7c4b1041983645133",borrowBalanceParentId:"0x4c3da45ffff6432b4592a39cdb3ce12f4a28034cbcb804bb071facc81fdd923d",supplyBalanceParentId:"0x6adc72faf2a9a15a583c9fb04f457c6a5f0b456bc9b4832413a131dfd4faddae"},voloSui:{name:"VoloSui",coinType:"voloSui",assetId:5,poolId:"0x9790c2c272e15b6bf9b341eb531ef16bcc8ed2b20dfda25d060bf47f5dd88d01",fondPoolId:"0xe2b5ada45273676e0da8ae10f8fe079a7cec3d0f59187d3d20b1549c275b07ea",type:"0x549e8b69270defbfafd4f94e17ec44cdbdd99820b33bda2278dea3b9a32d3f55::cert::CERT",reserveObjectId:"0xd4fd7e094af9819b06ea3136c13a6ae8da184016b78cf19773ac26d2095793e2",borrowBalanceParentId:"0x8fa5eccbca2c4ba9aae3b87fd44aa75aa5f5b41ea2d9be4d5321379384974984",supplyBalanceParentId:"0xe6457d247b6661b1cac123351998f88f3e724ff6e9ea542127b5dcb3176b3841"},haSui:{name:"HaedalSui",coinType:"haSui",assetId:6,poolId:"0x6fd9cb6ebd76bc80340a9443d72ea0ae282ee20e2fd7544f6ffcd2c070d9557a",fondPoolId:"0xa20e18085ce04be8aa722fbe85423f1ad6b1ae3b1be81ffac00a30f1d6d6ab51",type:"0xbde4ba4c2e274a60ce15c1cfff9e5c42e41654ac8b6d906a57efa4bd3c29f47d::hasui::HASUI",reserveObjectId:"0x0c9f7a6ca561dc566bd75744bcc71a6af1dc3caf7bd32c099cd640bb5f3bb0e3",borrowBalanceParentId:"0x01f36898e020be6c3423e5c95d9f348868813cd4d0be39b0c8df9d8de4722b00",supplyBalanceParentId:"0x278b8e3d09c3548c60c51ed2f8eed281876ea58c392f71b7ff650cc9286d095b"},navx:{name:"NAVX",coinType:"navx",assetId:7,poolId:"0xc0e02e7a245e855dd365422faf76f87d9f5b2148a26d48dda6e8253c3fe9fa60",fondPoolId:"0x9dae0cf104a193217904f88a48ce2cf0221e8cd9073878edd05101d6b771fa09",type:"0xa99b8952d4f7d947ea77fe0ecdcc9e5fc0bcab2841d6e2a5aa00c3044e5544b5::navx::NAVX",reserveObjectId:"0x2e13b2f1f714c0c5fa72264f147ef7632b48ec2501f810c07df3ccb59d6fdc81",borrowBalanceParentId:"0xa5bf13075aa400cbdd4690a617c5f008e1fae0511dcd4f7121f09817df6c8d8b",supplyBalanceParentId:"0x59dedca8dc44e8df50b190f8b5fe673098c1273ac6168c0a4addf3613afcdee5"},wbtc:{name:"WBTC",coinType:"wbtc",assetId:8,poolId:"0xd162cbe40f8829ce71c9b3d3bf3a83859689a79fa220b23d70dc0300b777ae6e",type:"0x027792d9fed7f9844eb4839566001bb6f6cb4804f66aa2da6fe1ee242d896881::coin::COIN",reserveObjectId:"0x8b4d81f004e4e9faf4540951a896b6d96e42598a270e6375f598b99742db767e",borrowBalanceParentId:"0x55e1f3c9e6e5cf9fff563bdd61db07a3826458c56ef72c455e049ab3b1b0e99c",supplyBalanceParentId:"0x821e505a0091b089edba94deaa14c2f2230d026bbaa7b85680554441aad447e0"},ausd:{name:"AUSD",coinType:"ausd",assetId:9,poolId:"0xc9208c1e75f990b2c814fa3a45f1bf0e85bb78404cfdb2ae6bb97de58bb30932",type:"0x2053d08c1e2bd02791056171aab0fd12bd7cd7efad2ab8f6b9c8902f14df2ff2::ausd::AUSD",reserveObjectId:"0x918889c6a9d9b93108531d4d59a4ebb9cc4d41689798ffc1d4aed6e1ae816ec0",borrowBalanceParentId:"0x551300b9441c9a3a16ca1d7972c1dbb4715e15004ccd5f001b2c2eee22fd92c1",supplyBalanceParentId:"0xe151af690355de8be1c0281fbd0d483c099ea51920a57c4bf8c9666fd36808fd"},nusdc:{name:"USDC",assetId:10,coinType:"nusdc",poolId:"0xa3582097b4c57630046c0c49a88bfc6b202a3ec0a9db5597c31765f7563755a8",type:"0xdba34672e30cb065b1f93e3ab55318768fd6fef66c15942c9f7cb846e2f900e7::usdc::USDC",reserveObjectId:"0x4c8a2c72a22ae8da803a8519798d312c86e74a9e0d6ec0eec2bfcf7e4b3fef5e",borrowBalanceParentId:"0xb0b0c7470e96cabbb4f1e8d06bef2fbea65f4dbac52afae8635d9286b1ea9a09",supplyBalanceParentId:"0x08b5ce8574ac3bc9327e66ad5decd34d07ee798f724ad01058e8855ac9acb605"},eth:{name:"ETH",assetId:11,coinType:"eth",poolId:"0x78ba01c21d8301be15690d3c30dc9f111871e38cfb0b2dd4b70cc6052fba41bb",type:"0xd0e89b2af5e4910726fbcd8b8dd37bb79b29e5f83f7491bca830e94f7f226d29::eth::ETH",reserveObjectId:"0x376faea6dfbffab9ea808474cb751d91222b6d664f38c0f1d23de442a8edb1ce",borrowBalanceParentId:"0xf0c6ce5cfaee96073876a5fab7426043f3a798b79502c4caeb6d9772cd35af1f",supplyBalanceParentId:"0xc0a0cb43620eb8a84d5a4a50a85650e7fa7ba81e660f9cc2863404fd84591d4b"},usdy:{name:"USDY",assetId:12,coinType:"usdy",poolId:"0x4b6253a9f8cf7f5d31e6d04aed4046b9e325a1681d34e0eff11a8441525d4563",type:"0x960b531667636f39e85867775f52f6b1f220a058c4de786905bdf761e06a56bb::usdy::USDY",reserveObjectId:"",borrowBalanceParentId:"",supplyBalanceParentId:""}},borrowFee:.003,borrowFeeAddress:"0x70b9b10704263cf53392849e33b1f5fd16005869b4198ed5524836bad1234ea2"};async function gs(){if(!Su)try{let i=await fetch("https://open-api.naviprotocol.io/api/msafe").then(a=>a.json()),{packageId:e,borrowFee:t,borrowFeeAddress:n,pool:o}=i;e&&(_n.ProtocolPackage=e),t&&(_n.borrowFee=t),n&&(_n.borrowFeeAddress=n),o&&(_n.pool=o),Su=!0}catch(i){console.error(i.message)}}var Xt=_n;var ge=require("@msafe/sui3-utils"),ys=require("@mysten/sui.js/bcs"),ye=require("@mysten/sui.js/utils");var ha=class{constructor(e){this.txb=e}decode(){if(console.log("txb",this.txb),this.isClaimRewardTransaction())return this.decodeClaimReward();if(this.isEntryBorrowTransaction())return this.decodeEntryBorrow();if(this.isEntryBorrowWithFeeTransaction())return this.decodeEntryBorrow();if(this.isEntryMultiDepositTransaction())return this.decodeEntryMultiDeposit();if(this.isEntryDepositTransaction())return this.decodeEntryDeposit();if(this.isEntryRepayTransaction())return this.decodeEntryRepay();if(this.isEntryWithdrawTransaction())return this.decodeEntryWithdraw();if(this.isEntryClaimAndDepositTransaction())return this.decodeEntryClaimAndDeposit();throw new Error("Unknown transaction type")}get transactions(){return this.txb.blockData.transactions}getMoveCallTransaction(e){return this.transactions.find(t=>t.kind==="MoveCall"&&t.target===e)}isClaimRewardTransaction(){return!!this.transactions.find(t=>!!(t.kind==="MoveCall"&&t.target.includes("claim_reward")))}isEntryBorrowTransaction(){return!!this.getMoveCallTransaction(`${Xt.ProtocolPackage}::incentive_v3::entry_borrow`)}isEntryBorrowWithFeeTransaction(){return!!this.getMoveCallTransaction(`${Xt.ProtocolPackage}::incentive_v3::borrow`)}isEntryMultiDepositTransaction(){let e=`${Xt.ProtocolPackage}::incentive_v3::entry_deposit`,t=this.transactions.filter(o=>o.kind==="MoveCall"&&o.target===e);return this.transactions.find(o=>o.kind==="MoveCall"&&o.target.includes("claim_reward"))?!1:t.length>1}isEntryClaimAndDepositTransaction(){let e=`${Xt.ProtocolPackage}::incentive_v3::entry_deposit`,t=this.transactions.filter(o=>o.kind==="MoveCall"&&o.target===e);return!!(this.transactions.find(o=>o.kind==="MoveCall"&&o.target.includes("claim_reward"))&&t.length>0)}isEntryDepositTransaction(){return!!this.getMoveCallTransaction(`${Xt.ProtocolPackage}::incentive_v3::entry_deposit`)}isEntryRepayTransaction(){return!!this.getMoveCallTransaction(`${Xt.ProtocolPackage}::incentive_v3::entry_repay`)}isEntryWithdrawTransaction(){return!!this.getMoveCallTransaction(`${Xt.ProtocolPackage}::incentive_v3::withdraw`)}findPoolByAssetId(e){let t=Object.values(Xt.pool).find(n=>n.assetId===e);if(!t)throw new Error("Pool not found");return t}decodeEntryClaimAndDeposit(){return{txType:ge.TransactionType.Other,type:"EntryClaimAndDeposit",intentionData:{type:"entry_claim_and_deposit"}}}decodeClaimReward(){return console.log("decode claims"),{txType:ge.TransactionType.Other,type:"ClaimReward",intentionData:{type:"claim_reward"}}}decodeEntryBorrow(){let e=this.helper.decodeInputU8(4),t=this.helper.decodeInputU64(5);return{txType:ge.TransactionType.Other,type:"EntryBorrow",intentionData:{amount:t,assetId:e}}}decodeEntryMultiDeposit(){let e=[],t=`${Xt.ProtocolPackage}::incentive_v3::entry_deposit`;return this.transactions.forEach(n=>{if(n.kind==="MoveCall"&&n.target===t){let o=new ga(n,this.txb),a=o.decodeInputU8(3),c=o.decodeInputU64(5);e.push({assetId:a,amount:c})}}),{txType:ge.TransactionType.Other,type:"EntryMultiDeposit",intentionData:{list:e}}}decodeEntryDeposit(){let e=this.helper.decodeInputU8(3),t=this.helper.decodeInputU64(5);return{txType:ge.TransactionType.Other,type:"EntryDeposit",intentionData:{amount:t,assetId:e}}}decodeEntryRepay(){let e=this.helper.decodeInputU8(4),t=this.helper.decodeInputU64(6);return{txType:ge.TransactionType.Other,type:"EntryRepay",intentionData:{amount:t,assetId:e}}}decodeEntryWithdraw(){let e=this.helper.decodeInputU8(4),t=this.helper.decodeInputU64(5);return{txType:ge.TransactionType.Other,type:"EntryWithdraw",intentionData:{amount:t,assetId:e}}}get helper(){let e=this.transactions.find(t=>t.kind==="MoveCall"&&t.target.startsWith(Xt.ProtocolPackage));return new ga(e,this.txb)}},ga=class i{constructor(e,t){this.moveCall=e;this.txb=t}decodeSharedObjectId(e){let t=this.getInputParam(e);return i.getSharedObjectId(t)}decodeOwnedObjectId(e){let t=this.getInputParam(e);return i.getOwnedObjectId(t)}decodeInputU64(e){let t=this.decodePureArg(e,"u64");return Number(t)}decodeInputU8(e){let t=this.decodePureArg(e,"u8");return Number(t)}decodeInputAddress(e){let t=this.decodePureArg(e,"address");return(0,ye.normalizeSuiAddress)(t)}decodeInputString(e){return this.decodePureArg(e,"string")}decodeInputBool(e){return this.decodePureArg(e,"bool")}decodePureArg(e,t){let n=this.getInputParam(e);return i.getPureInputValue(n,t)}getInputParam(e){let t=this.moveCall.arguments[e];if(t.kind!=="Input")throw new Error("not input type");return this.txb.blockData.inputs[t.index]}static getPureInputValue(e,t){if(e.type!=="pure")throw new Error("not pure argument");if(typeof e.value=="object"&&"Pure"in e.value){let n=e.value.Pure;return ys.bcs.de(t,new Uint8Array(n))}return e.value}static getOwnedObjectId(e){if(e.type!=="object")throw new Error(`not object argument: ${JSON.stringify(e)}`);if(typeof e.value=="object"){if(!("Object"in e.value)||!("ImmOrOwned"in e.value.Object))throw new Error("not ImmOrOwned");return(0,ye.normalizeSuiAddress)(e.value.Object.ImmOrOwned.objectId)}return(0,ye.normalizeSuiAddress)(e.value)}static getSharedObjectId(e){if(e.type!=="object")throw new Error(`not object argument: ${JSON.stringify(e)}`);if(typeof e.value!="object")return(0,ye.normalizeSuiAddress)(e.value);if(!("Object"in e.value)||!("Shared"in e.value.Object))throw new Error("not Shared");return(0,ye.normalizeSuiAddress)(e.value.Object.Shared.objectId)}static getPureInput(e,t){if(e.type!=="pure")throw new Error("not pure argument");if(typeof e.value!="object")return e.value;if(!("Pure"in e.value))throw new Error("Pure not in value");let n=e.value.Pure;return ys.bcs.de(t,new Uint8Array(n))}typeArg(e){return(0,ye.normalizeStructTag)(this.moveCall.typeArguments[e])}txArg(e){return this.moveCall.arguments[e]}};var $t=require("navi-sdk");async function Ze(i,e,t,n){return await(0,$t.depositCoin)(i,e,t,n),i}async function Tu(i,e,t,n){let[o]=await(0,$t.withdrawCoin)(i,e,t);return i.transferObjects([o],i.pure(n)),i}async function wu(i,e,t,n){let[o]=await(0,$t.borrowCoin)(i,e,t);return i.transferObjects([o],i.pure.address(n)),i}async function bs(i,e,t,n){return await(0,$t.repayDebt)(i,e,t,n),i}async function Iu(i,e){return await(0,$t.claimAllRewardsPTB)(i,e)}async function Cu(i,e){return await(0,$t.claimAllRewardsResupplyPTB)(i,e)}var ya=class i extends _{constructor(t){super(t);this.data=t}txType;txSubType;async build(t){let{type:n}=this.data;return console.log("claim reward",n),await Iu(t.suiClient,t.account.address)}static fromData(t){return new i(t)}};var ba=class i extends _{constructor(t){super(t);this.data=t}txType;txSubType;async build(t){let{type:n}=this.data;return console.log("claim reward and supply",n),await Cu(t.suiClient,t.account.address)}static fromData(t){return new i(t)}};var vu=require("@mysten/sui.js/transactions");var ku=require("navi-sdk");function Zt(i){return Object.values(ku.pool).find(e=>String(e.assetId)===String(i))}var Sa=class i extends _{constructor(t){super(t);this.data=t}txType;txSubType;async build(t){let{assetId:n,amount:o}=this.data,a=new vu.TransactionBlock;console.log("build",this.data);let c=Zt(n);return await wu(a,c,o,t.account.address)}static fromData(t){return new i(t)}};var Du=require("@mysten/sui.js/transactions");async function tn(i,e,t){let n=await i.getCoins({owner:e,coinType:t});return console.log("getTokenObjs",e,n),n}var Ta=class i extends _{constructor(t){super(t);this.data=t}txType;txSubType;async build(t){let{suiClient:n,account:o}=t,{assetId:a,amount:c}=this.data,l=new Du.TransactionBlock;console.log("build",this.data);let d=Zt(a);if(a===0){let[k]=l.splitCoins(l.gas,[c]);return await Ze(l,d,k,c)}let b=await tn(n,o.address,d.type);if(!b.data[0])throw new Error(`Insufficient balance for ${d.name} Token`);let w=b.data[0].coinObjectId;if(b.data.length>=2){let k=1;for(;k<b.data.length;)l.mergeCoins(w,[b.data[k].coinObjectId]),k++}return await Ze(l,d,l.object(w),c)}static fromData(t){return new i(t)}};var xu=require("@mysten/sui.js/transactions");var wa=class i extends _{constructor(t){super(t);this.data=t}txType;txSubType;async build(t){let{suiClient:n,account:o}=t,{assetId:a,amount:c}=this.data,l=new xu.TransactionBlock;console.log("build",this.data);let d=Zt(a);if(a===0){let[I]=l.splitCoins(l.gas,[c]);return bs(l,d,I,c)}let b=await tn(n,o.address,d.type);if(!b.data[0])throw new Error(`Insufficient balance for ${d.name} Token`);let w=b.data[0].coinObjectId;if(b.data.length>=2){let I=1;for(;I<b.data.length;)l.mergeCoins(w,[b.data[I].coinObjectId]),I++}return bs(l,d,l.object(w),c)}static fromData(t){return new i(t)}};var Au=require("@mysten/sui.js/transactions");var Ia=class i extends _{constructor(t){super(t);this.data=t}txType;txSubType;async build(t){let{assetId:n,amount:o}=this.data,a=new Au.TransactionBlock;console.log("build",this.data);let c=Zt(n);return await Tu(a,c,o,t.account.address)}static fromData(t){return new i(t)}};var Mu=require("@mysten/sui.js/transactions");var Ca=class i extends _{constructor(t){super(t);this.data=t}txType;txSubType;async build(t){let{suiClient:n,account:o}=t,{list:a}=this.data,c=new Mu.TransactionBlock;console.log("build",this.data);for(let l=0;l<a.length;l++){let{assetId:d,amount:b}=a[l],w=Zt(d);if(d===0){let[v]=c.splitCoins(c.gas,[b]);await Ze(c,w,v,b);continue}let I=await tn(n,o.address,w.type);if(!I.data[0])throw new Error(`Insufficient balance for ${w.name} Token`);let k=I.data[0].coinObjectId;if(I.data.length>=2){let v=1;for(;v<I.data.length;)c.mergeCoins(k,[I.data[v].coinObjectId]),v++}await Ze(c,w,c.object(k),b)}return c}static fromData(t){return new i(t)}};var ka=class{application="navi";supportSDK="@mysten/sui.js";async deserialize(e){await gs();let{transactionBlock:t}=e,o=new ha(t).decode();return{txType:Ou.TransactionType.Other,txSubType:o.type,intentionData:o.intentionData}}async build(e){let{suiClient:t,account:n}=e,o;switch(await gs(),e.txSubType){case"EntryDeposit":o=Ta.fromData(e.intentionData);break;case"EntryBorrow":o=Sa.fromData(e.intentionData);break;case"EntryRepay":o=wa.fromData(e.intentionData);break;case"EntryWithdraw":o=Ia.fromData(e.intentionData);break;case"EntryMultiDeposit":o=Ca.fromData(e.intentionData);break;case"ClaimReward":o=ya.fromData(e.intentionData);break;case"EntryClaimAndDeposit":o=ba.fromData(e.intentionData);break;default:throw new Error("not implemented")}return o.build({suiClient:t,account:n})}};var Ln=require("@msafe/sui3-utils"),Pu=require("@mysten/bcs"),Ru=require("@mysten/sui/transactions"),Bu=Ut(require("sort-keys-recursive")),Eu="msafe-plain-tx",Nu=Ln.TransactionSubTypes.others.plain,Ss=class i{constructor(e){this.data=e}application=Eu;txType=Ln.TransactionType.Other;txSubType=Nu;serialize(){return JSON.stringify((0,Bu.default)(this.data))}async build(e){return Ru.Transaction.from((0,Pu.fromHex)(this.data.content))}static fromData(e){return new i(e)}},va=class{application;supportSDK="@mysten/sui";constructor(){this.application=Eu}async deserialize(e){let{content:t}=e.appContext;return{txType:Ln.TransactionType.Other,txSubType:Nu,intentionData:{content:t}}}async build(e){let{suiClient:t,network:n,account:o}=e;return Ss.fromData(e.intentionData).build({suiClient:t,network:n,account:o})}};var Is=require("@mysten/sui/client"),Wu=require("@mysten/sui/transactions"),Aa=require("@mysten/sui.js/client"),_u=require("@mysten/sui.js/transactions");var en=require("@open-rpc/client-js");var Wd={"-32700":"ParseError","-32600":"InvalidRequest","-32601":"MethodNotFound","-32602":"InvalidParams","-32603":"InternalError"},Ts=class extends Error{},Da=class extends Ts{code;type;constructor(e,t){super(e),this.code=t,this.type=Wd[t]??"ServerError"}};function _d(i){let e=new URL(i);return e.protocol=e.protocol.replace("http","ws"),e.toString()}var Ld={WebSocketConstructor:typeof WebSocket<"u"?WebSocket:void 0,callTimeout:3e4,reconnectTimeout:3e3,maxReconnects:5},xa=class{endpoint;options;#n=0;#a=0;#t=null;#e=null;#i=new Set;#o=new Map;constructor(e,t={}){this.endpoint=e,this.options={...Ld,...t},this.endpoint&&this.endpoint.startsWith("http")&&(this.endpoint=_d(this.endpoint))}async makeRequest(e,t){let n=await this.#r();return new Promise((o,a)=>{this.#n+=1,this.#o.set(this.#n,{resolve:o,reject:a,timeout:setTimeout(()=>{this.#o.delete(this.#n),a(new Error(`Request timeout: ${e}`))},this.options.callTimeout)}),n.send(JSON.stringify({jsonrpc:"2.0",id:this.#n,method:e,params:t}))}).then(({error:o,result:a})=>{if(o)throw new Da(o.message,o.code);return a})}#r(){return this.#e?this.#e:(this.#e=new Promise(e=>{this.#t?.close(),this.#t=new this.options.WebSocketConstructor(this.endpoint),this.#t.addEventListener("open",()=>{this.#a=0,e(this.#t)}),this.#t.addEventListener("close",()=>{this.#a++,this.#a<=this.options.maxReconnects&&setTimeout(()=>{this.#s()},this.options.reconnectTimeout)}),this.#t.addEventListener("message",({data:t})=>{let n;try{n=JSON.parse(t)}catch(o){console.error(new Error(`Failed to parse RPC message: ${t}`,{cause:o}));return}if("id"in n&&n.id!=null&&this.#o.has(n.id)){let{resolve:o,timeout:a}=this.#o.get(n.id);clearTimeout(a),o(n)}else if("params"in n){let{params:o}=n;this.#i.forEach(a=>{a.subscriptionId===o.subscription&&o.subscription===a.subscriptionId&&a.onMessage(o.result)})}})}),this.#e)}async#s(){return this.#t?.close(),this.#e=null,Promise.allSettled([...this.#i].map(e=>e.subscribe(this)))}async subscribe(e){let t=new ws(e);return this.#i.add(t),await t.subscribe(this),()=>t.unsubscribe(this)}},ws=class{subscriptionId=null;input;subscribed=!1;constructor(e){this.input=e}onMessage(e){this.subscribed&&this.input.onMessage(e)}async unsubscribe(e){let{subscriptionId:t}=this;return this.subscribed=!1,t==null?!1:(this.subscriptionId=null,e.makeRequest(this.input.unsubscribe,[t]))}async subscribe(e){this.subscriptionId=null,this.subscribed=!0;let t=await e.makeRequest(this.input.method,this.input.params);this.subscribed&&(this.subscriptionId=t)}};var be=class{rpcClient;websocketClient;constructor({url:e,websocket:{url:t,...n}={},rpc:o}){let a=new en.HTTPTransport(o?.url??e,{headers:{"Content-Type":"application/json",...o?.headers}});this.rpcClient=new en.Client(new en.RequestManager([a])),this.websocketClient=new xa(t??e,n)}async request(e){return await this.rpcClient.request(e)}async subscribe(e){let t=await this.websocketClient.subscribe(e);return async()=>!!await t()}};var Ma=class i{apps;constructor(){this.apps=new Map}static fromHelpers(e){let t=new i;for(let n=0;n<e.length;n++){let o=e[n];switch(o.supportSDK){case"@mysten/sui.js":t.addLegacyHelper(o);break;case"@mysten/sui":t.addHelper(o);break;default:throw new Error(`${o.application}: ${o.supportSDK} SDK not supported`)}}return t}addLegacyHelper(e){this.apps.set(e.application,new ks(e))}addHelper(e){this.apps.set(e.application,new Cs(e))}getAppHelper(e){let t=this.apps.get(e);if(!t)throw new Error(`${e} not registered`);return t}},Cs=class{constructor(e){this.helper=e}async deserialize(e){let t=new Is.SuiClient({transport:new be({url:e.clientUrl,rpc:{url:e.clientUrl}})}),n=new Aa.SuiClient({transport:new be({url:e.clientUrl,rpc:{url:e.clientUrl}})}),o=await e.transactionBlock.build({client:n}),a=Wu.Transaction.from(o);return this.helper.deserialize({...e,suiClient:t,transaction:a})}async build(e){let t=new Is.SuiClient({transport:new be({url:e.clientUrl,rpc:{url:e.clientUrl}})}),n=await t.getBalance({owner:e.account.address});if(Number(n.totalBalance)<1e8)throw new Error("Insufficient gas fee");let o=await this.helper.build({...e,suiClient:t});o.setSender(e.account.address);let a=await o.build({client:t});return _u.TransactionBlock.from(a)}},ks=class{constructor(e){this.helper=e}async deserialize(e){let t=new Aa.SuiClient({transport:new be({url:e.clientUrl,rpc:{url:e.clientUrl}})});return this.helper.deserialize({...e,transactionBlock:e.transactionBlock,suiClient:t})}async build(e){let t=new Aa.SuiClient({transport:new be({url:e.clientUrl,rpc:{url:e.clientUrl}})}),n=await t.getBalance({owner:e.account.address});if(Number(n.totalBalance)<1e8)throw new Error("Insufficient gas fee");return this.helper.build({...e,suiClient:t})}};var Xu=require("@msafe/sui3-utils"),zu=require("@mysten/sui/client"),Gu=require("@scallop-io/sui-scallop-sdk");var Mt=require("@msafe/sui3-utils"),xs=require("@scallop-io/sui-scallop-sdk");var Lu=require("@mysten/sui/utils"),Se=class{constructor(e,t){this.transaction=e;this.scallopClient=t;this.scallopClient=t,this.inputs=e.getData().inputs,this.commands=e.getData().commands,this.movecallsAsSet=new Set(this.commands.filter(this.isMoveCall).map(n=>`${n.MoveCall.package}::${n.MoveCall.module}::${n.MoveCall.function}`))}inputs;commands;movecallsAsSet;get address(){return this.scallopClient.address}get utils(){return this.scallopClient.utils}get coreId(){return{protocolPkg:this.address.get("core.packages.protocol.id"),market:this.address.get("core.market"),version:this.address.get("core.version"),coinDecimalsRegistry:this.address.get("core.coinDecimalsRegistry"),xOracle:this.address.get("core.oracles.xOracle"),spoolPkg:this.address.get("spool.id"),borrowIncentivePkg:this.address.get("borrowIncentive.id"),veScaPkgId:this.address.get("vesca.id"),veScaObjId:this.address.get("vesca.object"),scoin:this.address.get("scoin.id"),referral:this.address.get("referral.id")}}matchMoveCallCommand(e,t){let{address:n,module:o,name:a}=(0,Lu.parseStructTag)(t);return e?e.package===n&&e.module===o&&e.function===a:!1}isMoveCall(e){return e.$kind==="MoveCall"&&!!e.MoveCall}filterMoveCallCommands(e,t){return this.isMoveCall(e)&&this.matchMoveCallCommand(e.MoveCall,t)}getMoveCallCommands(e){let t=new Set(e),n=e.reduce((a,c,l)=>(a[c]=l,a),{}),o=[];return this.commands.forEach(a=>{this.isMoveCall(a)&&a.MoveCall&&t.has(a.MoveCall.package)&&(o[n[a.MoveCall.package]]=a.MoveCall)}),o}hasMoveCallCommand(e){return this.movecallsAsSet.has(e)}};var Oa=require("@mysten/sui/bcs"),Te=require("@mysten/sui/utils"),vs=class i{constructor(e,t,n=0){this.moveCall=e;this.transaction=t;let o=[];e?.MoveCall&&t.getData().commands.filter((a,c)=>{if(a.$kind==="MoveCall"){let l=`${a.MoveCall.package}::${a.MoveCall.module}::${a.MoveCall.function}`,d=`${e.MoveCall.package}::${e.MoveCall.module}::${e.MoveCall.function}`;return l===d?(o.push(c),!0):!1}return!1}),this.cmdIdx=o[n]}cmdIdx;get txBlockTransactions(){return this.transaction.blockData.transactions[this.cmdIdx]}decodeSharedObjectId(e){let t=this.getInputParam(e);return i.getSharedObjectId(t)}decodeOwnedObjectId(e){let t=this.getInputParam(e);return i.getOwnedObjectId(t)}decodeInputU64(e){let t=this.decodePureArg(e,"U64");return Number(t)}decodeInputU8(e){let t=this.decodePureArg(e,"U8");return Number(t)}decodeInputAddress(e){let t=this.decodePureArg(e,"Address");return(0,Te.normalizeSuiAddress)(t)}decodeInputString(e){return this.decodePureArg(e,"String")}decodeInputBool(e){return this.decodePureArg(e,"Bool")}decodePureArg(e,t){let n=this.getInputParam(e);return i.getPureInputValue(n,t)}getInputParam(e){let t=this.txBlockTransactions.arguments[e];if(t.kind!=="Input")throw new Error("not input type");return t}getNestedInputParam(e){let t=this.txBlockTransactions.arguments[e];if(t.kind!=="NestedResult")throw new Error("not input type");return this.transaction.blockData.transactions[t.index]}static getPureInputValue(e,t){if(e.type!=="pure")throw new Error("not pure argument");if(typeof e.value=="object"&&"Pure"in e.value){let n=e.value.Pure,o=Oa.bcs[t];return Oa.bcs[t].parse(new Uint8Array(n))}return e.value}static getOwnedObjectId(e){if(e.type!=="object")throw new Error(`not object argument: ${JSON.stringify(e)}`);if(typeof e.value=="object"){if(!("Object"in e.value)||!("ImmOrOwned"in e.value.Object))throw new Error("not ImmOrOwned");return(0,Te.normalizeSuiAddress)(e.value.Object.ImmOrOwned.objectId)}return(0,Te.normalizeSuiAddress)(e.value)}static getSharedObjectId(e){if(e.type!=="object")throw new Error(`not object argument: ${JSON.stringify(e)}`);if(typeof e.value!="object")return(0,Te.normalizeSuiAddress)(e.value);if(!("Object"in e.value)||!("Shared"in e.value.Object))throw new Error("not Shared");return(0,Te.normalizeSuiAddress)(e.value.Object.Shared.objectId)}static getPureInput(e){if(e.type!=="pure")throw new Error("not pure argument");if(typeof e.value!="object")return e.value;if(!("Pure"in e.value))throw new Error("Pure not in value");let t=e.value.Pure;return Oa.bcs.U64.parse(new Uint8Array(t))}typeArg(e){return(0,Te.normalizeStructTag)(this.txBlockTransactions.typeArguments[e])}txArg(e){return this.transaction.blockData.inputs[e]}},N=vs;var Ds=class{constructor(e,t){this.splitCoin=e;this.txb=t}getAmountInput(){return this.splitCoin.amounts.map(e=>{if(e.kind==="Input")return Number(N.getPureInputValue(e,"U64"))}).filter(e=>e!==void 0)}},Bt=Ds;var we=require("@mysten/sui/utils"),ju=async(i,e)=>{let t=await i.scallopSuiKit.client.getObject({id:e,options:{showContent:!0}});if(t?.data?.content?.dataType!=="moveObject")return!1;let o=t.data.content.fields.lock_key?.fields.name;if(!o)return!1;let a=i.address.get("borrowIncentive.object");return o===`${a.slice(2)}::incentive_account::IncentiveProgramLockKey`},nn={id:"0xc63072e7f5f4983a2efaf5bdba1480d5e7d74d57948e1c7cc436f8e22cbeb410",incentivePools:"0x64972b713ccec45ec3964809e477cea6f97350c0c50ca3aec85bb631639266ec",incentiveAccounts:"0x3c0b707068bdcea8bb859d751ad3e2149a9f83c13fcf4054ef91372a00bccdd3"},Vt={unstakeObligation:(i,e,t)=>i.moveCall(`${nn.id}::user::unstake`,[nn.incentivePools,nn.incentiveAccounts,i.object(e),i.object(t),we.SUI_CLOCK_OBJECT_ID],[(0,we.normalizeStructTag)(we.SUI_TYPE_ARG)]),redeem_rewards:(i,e,t,n)=>i.moveCall(`${nn.id}::user::redeem_rewards`,[nn.incentivePools,nn.incentiveAccounts,i.object(e),i.object(t),we.SUI_CLOCK_OBJECT_ID],[(0,we.normalizeStructTag)(n)])};var Uu=(i,e)=>{let t=[];for(let n=0;n<i.length;n+=e)t.push(i.slice(n,n+e));return t};var Pa=class extends Se{decode(){if(this.isSupplyWithStakeSpoolTransaction())return this.decodeSupplyWithStakeSpool();if(this.isUnstakeAndWithdrawTransaction())return this.decodeUnstakeAndWithdraw();if(this.isStakeSpoolTransaction())return this.decodeStakeSpool();if(this.isDepositCollateralTransaction())return this.decodeDepositCollateral();if(this.isWithdrawCollateralTransaction())return this.decodeWithdrawCollateral();if(this.isWithdrawLendingScoinTransaction())return this.decodeWithdrawLendingScoin();if(this.isWithdrawLendingTransaction())return this.decodeWithdrawLending();if(this.isSupplyLendingTransaction())return this.decodeSupplyLending();if(this.isBorrowWithReferralTransaction())return this.decodeBorrowWithReferral();if(this.isBorrowWithBoostTransaction())return this.decodeBorrowWithBoost();if(this.isBorrowTransaction())return this.decodeBorrow();if(this.isRepayWithBoostTransaction())return this.decodeRepayWithBoost();if(this.isRepayTransaction())return this.decodeRepay();if(this.isUnstakeSpoolTransaction())return this.decodeUnstakeSpool();if(this.isMigrateAndClaim())return this.decodeMigrateAndClaim();if(this.isClaimRewardTransaction())return this.decodeClaimReward();if(this.isOpenObligationTransaction())return this.decodeOpenObligation();if(this.isMigrateScoinTransaction())return this.decodeMigrateScoin()}isMigrateScoinTransaction(){return this.hasMoveCallCommand(`${this.coreId.scoin}::s_coin_converter::mint_s_coin`)}isSupplyLendingTransaction(){return this.hasMoveCallCommand(`${this.coreId.protocolPkg}::mint::mint`)}isSupplyWithStakeSpoolTransaction(){let e=this.hasMoveCallCommand(`${this.coreId.protocolPkg}::mint::mint`),t=this.hasMoveCallCommand(`${this.coreId.spoolPkg}::user::stake`);return e&&t}isUnstakeAndWithdrawTransaction(){let e=this.hasMoveCallCommand(`${this.coreId.spoolPkg}::user::unstake`),t=this.hasMoveCallCommand(`${this.coreId.protocolPkg}::redeem::redeem`);return e&&t}isStakeSpoolTransaction(){return this.hasMoveCallCommand(`${this.coreId.spoolPkg}::user::stake`)}isWithdrawLendingTransaction(){return this.hasMoveCallCommand(`${this.coreId.protocolPkg}::redeem::redeem`)}isWithdrawLendingScoinTransaction(){let e=this.hasMoveCallCommand(`${this.coreId.protocolPkg}::redeem::redeem`),t=this.hasMoveCallCommand(`${this.coreId.scoin}::s_coin_converter::burn_s_coin`);return e&&t}isDepositCollateralTransaction(){return this.hasMoveCallCommand(`${this.coreId.protocolPkg}::deposit_collateral::deposit_collateral`)}isWithdrawCollateralTransaction(){return this.hasMoveCallCommand(`${this.coreId.protocolPkg}::withdraw_collateral::withdraw_collateral`)}isBorrowTransaction(){return this.hasMoveCallCommand(`${this.coreId.protocolPkg}::borrow::borrow`)}isBorrowWithBoostTransaction(){let e=this.hasMoveCallCommand(`${this.coreId.protocolPkg}::borrow::borrow`),t=this.hasMoveCallCommand(`${this.coreId.borrowIncentivePkg}::user::stake_with_ve_sca_v2`);return e&&t}isBorrowWithReferralTransaction(){return this.hasMoveCallCommand(`${this.coreId.protocolPkg}::borrow::borrow_with_referral`)}isRepayTransaction(){return this.hasMoveCallCommand(`${this.coreId.protocolPkg}::repay::repay`)}isRepayWithBoostTransaction(){let e=this.hasMoveCallCommand(`${this.coreId.protocolPkg}::repay::repay`),t=this.hasMoveCallCommand(`${this.coreId.borrowIncentivePkg}::user::stake_with_ve_sca_v2`);return e&&t}isUnstakeSpoolTransaction(){return this.hasMoveCallCommand(`${this.coreId.spoolPkg}::user::unstake`)}isCreateStakeAccountTransaction(){return this.hasMoveCallCommand(`${this.coreId.spoolPkg}::user::new_spool_account`)}isClaimRewardTransaction(){let e=this.hasMoveCallCommand(`${this.coreId.spoolPkg}::user::redeem_rewards`),t=this.hasMoveCallCommand(`${this.coreId.borrowIncentivePkg}::user::redeem_rewards`);return e||t}isOpenObligationTransaction(){return this.hasMoveCallCommand(`${this.coreId.protocolPkg}::open_obligation::open_obligation`)}isMigrateAndClaim(){let e=this.hasMoveCallCommand(`${xs.OLD_BORROW_INCENTIVE_PROTOCOL_ID}::user::redeem_rewards`),t=this.hasMoveCallCommand(`${this.coreId.borrowIncentivePkg}::user::stake_with_ve_sca_v2`),n=this.hasMoveCallCommand(`${this.coreId.borrowIncentivePkg}::user::stake`);return e&&(t||n)}get helperClaimLendingReward(){return this.commands.filter(t=>this.filterMoveCallCommands(t,`${this.coreId.spoolPkg}::user::redeem_rewards`)).map(t=>new N(t,this.transaction))}get helperClaimBorrowV2Reward(){return this.commands.filter(t=>this.filterMoveCallCommands(t,`${this.coreId.borrowIncentivePkg}::user::redeem_rewards`)).map(t=>new N(t,this.transaction))}get helperStakeObligationWithVeSca(){let e=this.commands.find(t=>this.filterMoveCallCommands(t,`${this.coreId.borrowIncentivePkg}::user::stake_with_ve_sca_v2`));return new N(e,this.transaction)}get helperClaimBorrowReward(){return this.commands.filter(t=>this.filterMoveCallCommands(t,`${xs.OLD_BORROW_INCENTIVE_PROTOCOL_ID}::user::redeem_rewards`)).map(t=>new N(t,this.transaction))}get helperMint(){let e=this.commands.find(t=>this.filterMoveCallCommands(t,`${this.coreId.protocolPkg}::mint::mint`));return new N(e,this.transaction)}get helperUnstakes(){return this.commands.filter(t=>this.filterMoveCallCommands(t,`${this.coreId.spoolPkg}::user::unstake`)).map(t=>new N(t,this.transaction))}get helperRedeems(){return this.commands.filter(t=>this.filterMoveCallCommands(t,`${this.coreId.protocolPkg}::redeem::redeem`)).map(t=>new N(t,this.transaction))}get helperRedeem(){let e=this.commands.find(t=>this.filterMoveCallCommands(t,`${this.coreId.protocolPkg}::redeem::redeem`));return new N(e,this.transaction)}get helperBurnScoin(){let e=this.commands.find(t=>this.filterMoveCallCommands(t,`${this.coreId.scoin}::s_coin_converter::burn_s_coin`));return new N(e,this.transaction)}get helperStake(){let e=this.commands.find(t=>this.filterMoveCallCommands(t,`${this.coreId.spoolPkg}::user::stake`));return new N(e,this.transaction)}get helperUnstake(){let e=this.commands.find(t=>this.filterMoveCallCommands(t,`${this.coreId.spoolPkg}::user::unstake`));return new N(e,this.transaction)}get helperDepositCollateral(){let e=this.commands.find(t=>this.filterMoveCallCommands(t,`${this.coreId.protocolPkg}::deposit_collateral::deposit_collateral`));return new N(e,this.transaction)}get helperWithdrawCollateral(){let e=this.commands.find(t=>this.filterMoveCallCommands(t,`${this.coreId.protocolPkg}::withdraw_collateral::withdraw_collateral`));return new N(e,this.transaction)}get helperBorrow(){let e=this.commands.find(t=>this.filterMoveCallCommands(t,`${this.coreId.protocolPkg}::borrow::borrow`));return new N(e,this.transaction)}get helperBorrowWithReferral(){let e=this.commands.find(t=>this.filterMoveCallCommands(t,`${this.coreId.protocolPkg}::borrow::borrow_with_referral`));return new N(e,this.transaction)}get helperRepay(){let e=this.commands.find(t=>this.filterMoveCallCommands(t,`${this.coreId.protocolPkg}::repay::repay`));return new N(e,this.transaction)}decodeMigrateScoin(){return{txType:Mt.TransactionType.Other,type:"MigrateScoin",intentionData:{}}}decodeMigrateAndClaim(){let e;this.helperStakeObligationWithVeSca.moveCall&&(e=this.helperStakeObligationWithVeSca.decodeOwnedObjectId(9));let t=this.helperClaimBorrowReward[0].decodeOwnedObjectId(2),n=this.helperClaimBorrowReward[0].decodeSharedObjectId(3),o=this.utils.parseCoinNameFromType(this.helperClaimBorrowReward[0].typeArg(0));return{txType:Mt.TransactionType.Other,type:"MigrateAndClaim",intentionData:{obligationKey:t,obligationId:n,rewardCoinName:o,veScaKey:e}}}decodeOpenObligation(){return{txType:Mt.TransactionType.Other,type:"OpenObligation",intentionData:{}}}decodeSupplyLending(){let e=this.utils.parseCoinNameFromType(this.helperMint.typeArg(0)),t=this.helperMint.getNestedInputParam(2),n=new Bt(t,this.transaction).getAmountInput().reduce((o,a)=>o+a,0);return{txType:Mt.TransactionType.Other,type:"SupplyLending",intentionData:{amount:n,coinName:e}}}decodeWithdrawLending(){let e=this.utils.parseCoinNameFromType(this.helperRedeem.typeArg(0)),t=this.helperRedeem.getNestedInputParam(2),n=new Bt(t,this.transaction).getAmountInput().reduce((o,a)=>o+a,0);return{txType:Mt.TransactionType.Other,type:"WithdrawLending",intentionData:{amount:n,coinName:e}}}decodeWithdrawLendingScoin(){let e=this.utils.parseCoinNameFromType(this.helperRedeem.typeArg(0));console.log({coinName:e});let t=this.helperBurnScoin.getNestedInputParam(1),n=new Bt(t,this.transaction).getAmountInput().reduce((o,a)=>o+a,0);return{txType:Mt.TransactionType.Other,type:"WithdrawLending",intentionData:{amount:n,coinName:e}}}decodeDepositCollateral(){let e=this.utils.parseCoinNameFromType(this.helperDepositCollateral.typeArg(0)),t=this.helperDepositCollateral.getNestedInputParam(3),n=new Bt(t,this.transaction).getAmountInput().reduce((a,c)=>a+c,0),o=this.helperDepositCollateral.decodeSharedObjectId(1);return{txType:Mt.TransactionType.Other,type:"DepositCollateral",intentionData:{amount:n,obligationId:o,collateralCoinName:e}}}decodeWithdrawCollateral(){let e=this.utils.parseCoinNameFromType(this.helperWithdrawCollateral.typeArg(0)),t=this.helperWithdrawCollateral.decodeInputU64(5),n=this.helperWithdrawCollateral.decodeSharedObjectId(1),o=this.helperWithdrawCollateral.decodeOwnedObjectId(2);return{txType:Mt.TransactionType.Other,type:"WithdrawCollateral",intentionData:{amount:t,collateralCoinName:e,obligationKey:o,obligationId:n}}}decodeBorrow(){let e=this.utils.parseCoinNameFromType(this.helperBorrow.typeArg(0)),t=this.helperBorrow.decodeInputU64(5),n=this.helperBorrow.decodeSharedObjectId(1),o=this.helperBorrow.decodeOwnedObjectId(2);return{txType:Mt.TransactionType.Other,type:"Borrow",intentionData:{amount:t,coinName:e,obligationKey:o,obligationId:n}}}decodeBorrowWithBoost(){let e=this.utils.parseCoinNameFromType(this.helperBorrow.typeArg(0)),t=this.helperStakeObligationWithVeSca.decodeOwnedObjectId(9),n=this.helperBorrow.decodeInputU64(5),o=this.helperBorrow.decodeSharedObjectId(1),a=this.helperBorrow.decodeOwnedObjectId(2);return{txType:Mt.TransactionType.Other,type:"BorrowWithBoost",intentionData:{amount:n,coinName:e,obligationKey:a,obligationId:o,veScaKey:t}}}decodeBorrowWithReferral(){let e=this.utils.parseCoinNameFromType(this.helperBorrowWithReferral.typeArg(0)),t;this.helperStakeObligationWithVeSca.moveCall&&(t=this.helperStakeObligationWithVeSca.decodeOwnedObjectId(9));let n=this.helperBorrowWithReferral.decodeInputU64(6),o=this.helperBorrowWithReferral.decodeSharedObjectId(1),a=this.helperBorrowWithReferral.decodeOwnedObjectId(2);return{txType:Mt.TransactionType.Other,type:"BorrowWithReferral",intentionData:{amount:n,coinName:e,obligationKey:a,obligationId:o,veScaKey:t}}}decodeRepay(){let e=this.utils.parseCoinNameFromType(this.helperRepay.typeArg(0)),t=this.helperRepay.getNestedInputParam(3),n=new Bt(t,this.transaction).getAmountInput().reduce((a,c)=>a+c,0),o=this.helperRepay.decodeSharedObjectId(1);return{txType:Mt.TransactionType.Other,type:"Repay",intentionData:{amount:n,obligationId:o,coinName:e}}}decodeRepayWithBoost(){let e=this.utils.parseCoinNameFromType(this.helperRepay.typeArg(0)),t=this.helperStakeObligationWithVeSca.decodeOwnedObjectId(9),n=this.helperRepay.getNestedInputParam(3),o=new Bt(n,this.transaction).getAmountInput().reduce((c,l)=>c+l,0),a=this.helperRepay.decodeSharedObjectId(1);return{txType:Mt.TransactionType.Other,type:"RepayWithBoost",intentionData:{amount:o,obligationId:a,coinName:e,veScaKey:t}}}decodeStakeSpool(){let e;this.isCreateStakeAccountTransaction()||(e=this.helperStake.decodeOwnedObjectId(1));let t=0;if(this.helperBurnScoin.moveCall){let a=this.helperBurnScoin.getNestedInputParam(1);t=new Bt(a,this.transaction).getAmountInput().reduce((c,l)=>c+l,0)}if(this.helperStake.moveCall&&t===0){let a=this.helperStake.getNestedInputParam(2);t=new Bt(a,this.transaction).getAmountInput().reduce((c,l)=>c+l,0)}let n=this.helperStake.typeArg(0),o=this.utils.parseCoinNameFromType(n);return{txType:Mt.TransactionType.Other,type:"StakeSpool",intentionData:{amount:t,marketCoinName:o,stakeAccountId:e}}}decodeUnstakeSpool(){let e=this.helperUnstake.decodeOwnedObjectId(1),t=this.helperUnstake.decodeInputU64(2),n=this.helperUnstake.typeArg(0),o=this.utils.parseCoinNameFromType(n);return{txType:Mt.TransactionType.Other,type:"UnstakeSpool",intentionData:{amount:t,marketCoinName:o,stakeAccountId:e}}}decodeSupplyWithStakeSpool(){let e=this.utils.parseCoinNameFromType(this.helperMint.typeArg(0)),t=this.helperMint.getNestedInputParam(2),n=new Bt(t,this.transaction).getAmountInput().reduce((a,c)=>a+c,0),o;return this.isCreateStakeAccountTransaction()||(o=this.helperStake.decodeOwnedObjectId(1)),{txType:Mt.TransactionType.Other,type:"SupplyAndStakeLending",intentionData:{amount:n,coinName:e,stakeAccountId:o}}}decodeUnstakeAndWithdraw(){let e=[];this.helperUnstakes.forEach(o=>{let a=o.decodeOwnedObjectId(1),c=o.decodeInputU64(2);e.push({id:a,coin:c})});let t=this.utils.parseCoinNameFromType(this.helperRedeems[0].typeArg(0)),n=0;if(this.helperBurnScoin.moveCall){let o=this.helperBurnScoin.getNestedInputParam(1);n=new Bt(o,this.transaction).getAmountInput().reduce((a,c)=>a+c,0)}return{txType:Mt.TransactionType.Other,type:"WithdrawAndUnstakeLending",intentionData:{amount:n,coinName:t,stakeAccountId:e}}}decodeClaimReward(){let e=[],t=[],n=[];return this.helperClaimLendingReward.forEach(o=>{let a=o.decodeOwnedObjectId(2),c=o.typeArg(0),l=this.utils.parseCoinNameFromType(c);e.push({stakeMarketCoinName:l,stakeAccountId:a})}),this.helperClaimBorrowV2Reward.forEach(o=>{let a=o.decodeSharedObjectId(4),c=o.decodeOwnedObjectId(3),l=this.utils.parseCoinNameFromType(o.typeArg(0));t.push({obligationId:c,obligationKey:a,rewardCoinName:l})}),this.helperClaimBorrowReward.forEach(o=>{let a=o.decodeSharedObjectId(2),c=o.decodeOwnedObjectId(3),l=this.utils.parseCoinNameFromType(o.typeArg(0));n.push({obligationId:c,obligationKey:a,rewardCoinName:l})}),{txType:Mt.TransactionType.Other,type:"ClaimIncentiveReward",intentionData:{lendingIncentive:e,borrowIncentiveV2:t,borrowIncentive:n}}}};var Ra=require("@msafe/sui3-utils");var Ba=class extends Se{decode(){if(this.isCreateReferralLink())return this.decodeCreateReferralLink();if(this.isClaimRevenueReferral())return this.decodeClaimRevenueReferral();if(this.isBindReferral())return this.decodeBindReferral()}isClaimRevenueReferral(){return this.hasMoveCallCommand(`${this.coreId.referral}::referral_revenue_pool::claim_revenue_with_ve_sca_key`)}isCreateReferralLink(){return this.hasMoveCallCommand(`${this.coreId.veScaPkgId}::ve_sca::mint_ve_sca_placeholder_key`)}isBindReferral(){return this.hasMoveCallCommand(`${this.coreId.referral}::referral_bindings::bind_ve_sca_referrer`)}get helperClaimRevenueReferral(){return this.commands.filter(t=>this.filterMoveCallCommands(t,`${this.coreId.referral}::referral_revenue_pool::claim_revenue_with_ve_sca_key`)).map(t=>new N(t,this.transaction))}get helperBindReferral(){let e=this.commands.find(t=>this.filterMoveCallCommands(t,`${this.coreId.referral}::referral_bindings::bind_ve_sca_referrer`));return new N(e,this.transaction)}decodeCreateReferralLink(){return{txType:Ra.TransactionType.Other,type:"CreateReferralLink",intentionData:{}}}decodeClaimRevenueReferral(){let e=this.helperClaimRevenueReferral[0].decodeOwnedObjectId(2),t=this.helperClaimRevenueReferral.map(n=>n.typeArg(0));return{txType:Ra.TransactionType.Other,type:"ClaimRevenueReferral",intentionData:{veScaKey:e,coins:t}}}decodeBindReferral(){let e=this.helperBindReferral.decodePureArg(1,"Address");return{txType:Ra.TransactionType.Other,type:"BindReferral",intentionData:{veScaKey:e}}}};var te=require("@msafe/sui3-utils"),qu=require("@scallop-io/sui-scallop-sdk");var Ea=class extends Se{async decode(){if(this.isExtendPeriodAndStakeMoreSca())return this.decodePeriodAndStakeMoreSca();if(this.isStakeScaFirsTime()||this.isStakeMoreSca())return this.decodeStakeSca();if(this.isRenewExpiredVeSca())return this.decodeRenewExpiredVeSca();if(this.isExtendPeriod())return this.decodeExtendStakePeriod();if(this.isRedeemSca())return this.decodeRedeemSca();if(this.isMergeVeSca())return this.decodeMergeVesca();if(this.isSplitVeSca())return this.decodeSplitVesca();if(this.isVeScaObligationBindings())return this.decodeVeScaObligationBindings();if(await this.isTransferVeScaKey())return this.decodeTransferVeScaKey()}isStakeScaFirsTime(){return this.hasMoveCallCommand(`${this.coreId.veScaPkgId}::ve_sca::mint_ve_sca_key`)}isExtendPeriodAndStakeMoreSca(){let e=this.hasMoveCallCommand(`${this.coreId.veScaPkgId}::ve_sca::extend_lock_period`),t=this.hasMoveCallCommand(`${this.coreId.veScaPkgId}::ve_sca::lock_more_sca`);return!!e&&!!t}isRedeemSca(){return this.hasMoveCallCommand(`${this.coreId.veScaPkgId}::ve_sca::redeem`)}isStakeMoreSca(){return this.hasMoveCallCommand(`${this.coreId.veScaPkgId}::ve_sca::lock_more_sca`)}isExtendPeriod(){return this.hasMoveCallCommand(`${this.coreId.veScaPkgId}::ve_sca::extend_lock_period`)}isRenewExpiredVeSca(){return this.hasMoveCallCommand(`${this.coreId.veScaPkgId}::ve_sca::renew_expired_ve_sca`)}isMergeVeSca(){return this.hasMoveCallCommand(`${this.coreId.veScaPkgId}::ve_sca::merge`)}isSplitVeSca(){return this.hasMoveCallCommand(`${this.coreId.veScaPkgId}::ve_sca::split`)}isVeScaObligationBindings(){let e=this.commands.filter(l=>this.filterMoveCallCommands(l,`${this.coreId.borrowIncentivePkg}::user::unstake_v2`)),t=this.commands.filter(l=>this.filterMoveCallCommands(l,`${this.coreId.borrowIncentivePkg}::user::stake_with_ve_sca_v2`)),n=this.commands.filter(l=>this.filterMoveCallCommands(l,`${this.coreId.borrowIncentivePkg}::user::deactivate_boost_v2`)),o=e.length>0&&t.length>0&&e.length===t.length,a=n.length>0;return this.commands.length===e.length+t.length+n.length&&(o||a)}async isTransferVeScaKey(){let e=this.commands.filter(d=>d.$kind==="TransferObjects");if(e.length!==1)return!1;let{objects:t}=e[0].TransferObjects,n=t.filter(d=>d.$kind==="Input").map(({Input:d})=>d);if(n.length!==t.length)return!1;let o=new Set(n),a=this.inputs.filter((d,b)=>d.$kind==="Object"&&o.has(b)).map(d=>d.Object.ImmOrOwnedObject),c=`${this.coreId.veScaObjId}::ve_sca::VeScaKey`,l=Uu(a.map(({objectId:d})=>d),50);for(let d=0;d<l.length;d++){let b=l[d];if((await this.scallopClient.scallopSuiKit.queryGetObjects(b,{showType:!0})).some(I=>I.type!==c))return!1}return a.length>0}get helperStakeMoreSca(){let e=this.commands.find(t=>this.filterMoveCallCommands(t,`${this.coreId.veScaPkgId}::ve_sca::lock_more_sca`));return new N(e,this.transaction)}get helperStakeSca(){let e=this.commands.find(t=>this.filterMoveCallCommands(t,`${this.coreId.veScaPkgId}::ve_sca::mint_ve_sca_key`));return new N(e,this.transaction)}get helperExtendStakePeriod(){let e=this.commands.find(t=>this.filterMoveCallCommands(t,`${this.coreId.veScaPkgId}::ve_sca::extend_lock_period`));return new N(e,this.transaction)}get helperRedeemSca(){let e=this.commands.find(t=>this.filterMoveCallCommands(t,`${this.coreId.veScaPkgId}::ve_sca::redeem`));return new N(e,this.transaction)}get helperRenewExpired(){let e=this.commands.find(t=>this.filterMoveCallCommands(t,`${this.coreId.veScaPkgId}::ve_sca::renew_expired_ve_sca`));return new N(e,this.transaction)}get helperOldUnstakeObligation(){let e=this.commands.find(t=>this.filterMoveCallCommands(t,`${qu.OLD_BORROW_INCENTIVE_PROTOCOL_ID}::user::unstake`));return new N(e,this.transaction)}get helperUnstakeObligation(){let e=this.commands.find(t=>this.filterMoveCallCommands(t,`${this.coreId.borrowIncentivePkg}::user::unstake_v2`));return new N(e,this.transaction)}get helperStakeObligationWithVeSca(){let e=this.commands.find(t=>this.filterMoveCallCommands(t,`${this.coreId.borrowIncentivePkg}::user::stake_with_ve_sca_v2`));return new N(e,this.transaction)}getMergeSplitVeScaHelper(e){let t=this.commands.find(n=>this.filterMoveCallCommands(n,`${this.coreId.veScaPkgId}::ve_sca::${e}`));return new N(t,this.transaction)}getVeScaObligationBindingHelpers(){let e=`${this.coreId.borrowIncentivePkg}::user::unstake_v2`,t=`${this.coreId.borrowIncentivePkg}::user::stake_with_ve_sca_v2`,n=`${this.coreId.borrowIncentivePkg}::user::deactivate_boost_v2`,o=[],a=0,c=0,l=0;return this.commands.forEach(d=>{this.filterMoveCallCommands(d,e)?(o.push({action:"unstake",helper:new N(d,this.transaction,a)}),a++):this.filterMoveCallCommands(d,t)?(o.push({action:"stake",helper:new N(d,this.transaction,c)}),c++):this.filterMoveCallCommands(d,n)&&(o.push({action:"deactivate",helper:new N(d,this.transaction,l)}),l++)}),o}decodeRedeemSca(){let e=this.helperRedeemSca.decodeOwnedObjectId(1);return{txType:te.TransactionType.Other,type:"RedeemSca",intentionData:{veScaKey:e}}}decodeRenewExpiredVeSca(){let e=this.helperRenewExpired.getNestedInputParam(4),t=this.helperRenewExpired.decodeInputU64(5),n=new Bt(e,this.transaction).getAmountInput().reduce((D,P)=>D+P,0),o=this.helperRenewExpired.decodeOwnedObjectId(1),a=!!this.helperRedeemSca.moveCall,c=[],l=[],d=[];this.helperOldUnstakeObligation.moveCall&&(c=[this.helperOldUnstakeObligation.decodeOwnedObjectId(2),this.helperOldUnstakeObligation.decodeSharedObjectId(3)]),this.helperUnstakeObligation.moveCall&&(l=[this.helperUnstakeObligation.decodeOwnedObjectId(3),this.helperUnstakeObligation.decodeSharedObjectId(4)]),this.helperStakeObligationWithVeSca.moveCall&&(d=[this.helperStakeObligationWithVeSca.decodeOwnedObjectId(3),this.helperStakeObligationWithVeSca.decodeSharedObjectId(4)]);let b=!1,w=!1,I,k,v=[{condition:c,isOld:!0},{condition:l,isOld:!1},{condition:d,isOld:!1}];for(let D=0;D<v.length;D++)v[D].condition.length>1&&([k,I]=v[D].condition,b=!0,w=v[D].isOld);return{txType:te.TransactionType.Other,type:"RenewExpStakePeriod",intentionData:{amount:n,unlockTime:t,obligationId:I,obligationKey:k,veScaKey:o,isHaveRedeem:a,isObligationLocked:b,isOldBorrowIncentive:w}}}decodeExtendStakePeriod(){let e=this.helperExtendStakePeriod.decodeInputU64(4),t=this.helperExtendStakePeriod.decodeOwnedObjectId(1),n=[],o=[],a=[];this.helperOldUnstakeObligation.moveCall&&(n=[this.helperOldUnstakeObligation.decodeOwnedObjectId(2),this.helperOldUnstakeObligation.decodeSharedObjectId(3)]),this.helperUnstakeObligation.moveCall&&(o=[this.helperUnstakeObligation.decodeOwnedObjectId(3),this.helperUnstakeObligation.decodeSharedObjectId(4)]),this.helperStakeObligationWithVeSca.moveCall&&(a=[this.helperStakeObligationWithVeSca.decodeOwnedObjectId(3),this.helperStakeObligationWithVeSca.decodeSharedObjectId(4)]);let c=!1,l=!1,d,b,w=[{condition:n,isOld:!0},{condition:o,isOld:!1},{condition:a,isOld:!1}];for(let I=0;I<w.length;I++)w[I].condition.length>1&&([b,d]=w[I].condition,c=!0,l=w[I].isOld);return{txType:te.TransactionType.Other,type:"ExtendStakePeriod",intentionData:{unlockTime:e,obligationId:d,obligationKey:b,veScaKey:t,isObligationLocked:c,isOldBorrowIncentive:l}}}decodePeriodAndStakeMoreSca(){let e=this.helperStakeMoreSca.getNestedInputParam(4),t=this.helperExtendStakePeriod.decodeInputU64(4),n=new Bt(e,this.transaction).getAmountInput().reduce((v,D)=>v+D,0),o=[],a=[],c,l=[];this.helperOldUnstakeObligation.moveCall&&(o=[this.helperOldUnstakeObligation.decodeOwnedObjectId(2),this.helperOldUnstakeObligation.decodeSharedObjectId(3)]),this.helperUnstakeObligation.moveCall&&(a=[this.helperUnstakeObligation.decodeOwnedObjectId(3),this.helperUnstakeObligation.decodeSharedObjectId(4)]),this.helperStakeMoreSca.moveCall&&(c=this.helperStakeMoreSca.decodeOwnedObjectId(1)),this.helperStakeObligationWithVeSca.moveCall&&(l=[this.helperStakeObligationWithVeSca.decodeOwnedObjectId(3),this.helperStakeObligationWithVeSca.decodeSharedObjectId(4)]);let d=!1,b=!1,w,I,k=[{condition:o,isOld:!0},{condition:a,isOld:!1},{condition:l,isOld:!1}];for(let v=0;v<k.length;v++)k[v].condition.length>1&&([I,w]=k[v].condition,d=!0,b=k[v].isOld);return{txType:te.TransactionType.Other,type:"ExtendPeriodAndStakeMore",intentionData:{amount:n,veScaKey:c,unlockTime:t,obligationId:w,obligationKey:I,isOldBorrowIncentive:b,isObligationLocked:d}}}decodeStakeSca(){let e,t;this.helperStakeSca.moveCall&&this.helperStakeMoreSca.moveCall===void 0?(e=this.helperStakeSca.getNestedInputParam(3),t=this.helperStakeSca.decodeInputU64(4)):e=this.helperStakeMoreSca.getNestedInputParam(4);let n=new Bt(e,this.transaction).getAmountInput().reduce((v,D)=>v+D,0),o=[],a=[],c,l=[];this.helperOldUnstakeObligation.moveCall&&(o=[this.helperOldUnstakeObligation.decodeOwnedObjectId(2),this.helperOldUnstakeObligation.decodeSharedObjectId(3)]),this.helperUnstakeObligation.moveCall&&(a=[this.helperUnstakeObligation.decodeOwnedObjectId(3),this.helperUnstakeObligation.decodeSharedObjectId(4)]),this.helperStakeMoreSca.moveCall&&(c=this.helperStakeMoreSca.decodeOwnedObjectId(1)),this.helperStakeObligationWithVeSca.moveCall&&(l=[this.helperStakeObligationWithVeSca.decodeOwnedObjectId(3),this.helperStakeObligationWithVeSca.decodeSharedObjectId(4)]);let d=!1,b=!1,w,I,k=[{condition:o,isOld:!0},{condition:a,isOld:!1},{condition:l,isOld:!1}];for(let v=0;v<k.length;v++)k[v].condition.length>1&&([I,w]=k[v].condition,d=!0,b=k[v].isOld);return{txType:te.TransactionType.Other,type:"StakeSca",intentionData:{amount:n,unlockTime:t,obligationId:w,obligationKey:I,veScaKey:c,isObligationLocked:d,isOldBorrowIncentive:b}}}decodeMergeVesca(){let e=this.getMergeSplitVeScaHelper("merge"),t={targetVeScaKey:e.decodeOwnedObjectId(1),sourceVeScaKey:e.decodeOwnedObjectId(2)};return{txType:te.TransactionType.Other,type:"MergeVeSca",intentionData:t}}decodeSplitVesca(){let e=this.getMergeSplitVeScaHelper("split"),t={targetVeScaKey:e.decodeOwnedObjectId(1),splitAmount:e.decodeInputU64(4)};return{txType:te.TransactionType.Other,type:"SplitVeSca",intentionData:t}}decodeVeScaObligationBindings(){let e=this.getVeScaObligationBindingHelpers(),t=(o,a)=>{switch(o){case"stake":return{veScaKey:a.decodeOwnedObjectId(9),obligationId:a.decodeSharedObjectId(4),obligationKey:a.decodeOwnedObjectId(3)};case"unstake":return{obligationId:a.decodeSharedObjectId(4),obligationKey:a.decodeOwnedObjectId(3)};case"deactivate":return{veScaKey:a.decodeOwnedObjectId(4),obligationId:a.decodeSharedObjectId(3)};default:throw new Error(`Invalid action ${o}`)}},n=e.map(({action:o,helper:a})=>({action:o,args:t(o,a)}));return{txType:te.TransactionType.Other,type:"VeScaObligationBindings",intentionData:{bindingDatas:n}}}decodeTransferVeScaKey(){let e=this.commands.filter(c=>c.$kind==="TransferObjects"),{objects:t}=e[0].TransferObjects,n=t.filter(c=>c.$kind==="Input").map(({Input:c})=>c);if(n.length!==t.length)return!1;let o=new Set(n),a=this.inputs.filter((c,l)=>c.$kind==="Object"&&o.has(l)).map(c=>c.Object.ImmOrOwnedObject);return{xType:te.TransactionType.Other,type:"TransferVeScaKeys",intentionData:{veScaKeys:a}}}};var Fu=Ut(require("sort-keys-recursive")),A=class{constructor(e){this.data=e}get application(){return"msafe-core"}serialize(){return JSON.stringify((0,Fu.default)(this.data))}isObligationLocked=async(e,t)=>{let n=await e.getObject({id:typeof t=="string"?t:t.objectId,options:{showContent:!0}}),o=!1;return n&&n?.data.content?.dataType==="moveObject"&&"lock_key"in n.data.content.fields&&(o=!!n.data.content.fields.lock_key),o};async buildTxWithRefreshObligation(e,t,n){let o=e.builder.createTxBlock();o.setSender(t.walletAddress);let{obligationId:a,obligationKey:c}=t;return await this.isObligationLocked(e.scallopSuiKit.client,a)?(await o.unstakeObligationQuick(a,c),await n(e,o,t),await o.stakeObligationWithVeScaQuick(a,c,t.veScaKey)):await n(e,o,t),o}};var Na=class i extends A{constructor(t){super(t);this.data=t}txType;txSubType;async borrow({account:t,scallopClient:n}){let{coinName:o,amount:a,obligationId:c,obligationKey:l}=this.data,d=t.address;return(await this.buildTxWithRefreshObligation(n,{walletAddress:d,obligationId:c,obligationKey:l},async(w,I)=>{let k=await I.borrowQuick(+a,o,c,l);I.transferObjects([k],d)})).txBlock}async build(t){return this.borrow(t)}static fromData(t){return new i(t)}};var Wa=class i extends A{constructor(t){super(t);this.data=t}txType;txSubType;async borrowWithBoost(t,n){let{obligationId:o,obligationKey:a,veScaKey:c,amount:l,coinName:d}=this.data;return(await this.buildTxWithRefreshObligation(t,{walletAddress:n,obligationId:o,obligationKey:a,veScaKey:c},async(w,I)=>{let k=await I.borrowQuick(+l,d,o,a);I.transferObjects([k],n)})).txBlock}async build(t){return this.borrowWithBoost(t.scallopClient,t.account.address)}static fromData(t){return new i(t)}};var _a=class i extends A{constructor(t){super(t);this.data=t}txType;txSubType;async borrowWithReferral({account:t,scallopClient:n}){let o=t.address,{obligationId:a,obligationKey:c,veScaKey:l,coinName:d,amount:b}=this.data;return(await this.buildTxWithRefreshObligation(n,{walletAddress:o,obligationId:a,obligationKey:c,veScaKey:l},async(I,k)=>{let v=k.claimReferralTicket(d),D=await k.borrowWithReferralQuick(+b,d,v,a,c);k.burnReferralTicket(v,d),k.transferObjects([D],o)})).txBlock}async build(t){return this.borrowWithReferral(t)}static fromData(t){return new i(t)}};var Ku=require("@mysten/sui/utils");var La=class i extends A{txType;txSubType;constructor(e={}){super(e)}async claimIncentiveRewards(e,t){let n=e.builder.createTxBlock();n.setSender(t);let o=await e.query.getAllStakeAccounts(t),a=await e.query.getLendings(void 0,t),c=await e.query.getObligations(t),l=Object.values(await e.query.getObligationAccounts(t)??[]),d=(()=>{let k=[...e.constants.whitelist.spool].map(v=>e.utils.parseCoinName(v));return Object.values(a??[]).filter(v=>!!v&&k.includes(v.coinName)).reduce((v,D)=>{let P=e.utils.parseMarketCoinName(D.coinName);return v[P]||(v[P]=0),v[P]+=D.availableClaimCoin,v},{})})(),b={};Object.entries(o).forEach(([k,v])=>{for(let D=0;D<v.length;D++){let P=v[D];if(!d[k])continue;let K=n.claim(P.id,k);b.sui?b.sui.push(K):b.sui=[K]}});let w=(()=>{let k={};return k.sui=Object.values(d).reduce((v,D)=>v+D,0),l.forEach(v=>{Object.values(v.borrowIncentives).forEach(D=>{D&&D.rewards.forEach(P=>{k[P.coinName]||(k[P.coinName]=0),k[P.coinName]?k[P.coinName]+=P.availableClaimCoin:k[P.coinName]=P.availableClaimCoin})})}),k})();if(c.length>0&&l.length>0)for(let k=0;k<l.length;k++){let v=l[k],D=!1,P=c.find(H=>H.id===v.obligationId)?.keyId,K={};if(P){if(Object.values(v.borrowIncentives).forEach(H=>{if(H){let Et=H.rewards.filter(Wt=>{let Ot=Wt.coinName;return Wt.availableClaimCoin>0&&!K[Ot]});D=Et.length>0,Et.forEach(Wt=>{let Ot=n.claimBorrowIncentive(v.obligationId,P,Wt.coinName);K[Wt.coinName]=!0,b[Wt.coinName]?b[Wt.coinName].push(Ot):b[Wt.coinName]=[Ot]})}}),w.sui>0){let H=Vt.redeem_rewards(n,P,v.obligationId,Ku.SUI_TYPE_ARG);b.sui?b.sui.push(H):b.sui=[H]}if(D&&await ju(e.query,v.obligationId)){n.unstakeObligation(v.obligationId,P);let Et=await e.query.getBindedVeScaKey(v.obligationId);Et?n.stakeObligationWithVesca(v.obligationId,P,Et):n.stakeObligation(v.obligationId,P)}}}let I=(await Promise.all(Object.entries(b).map(async([k,v])=>{let D=v[0];if(v.length>1&&n.mergeCoins(D,v.slice(1)),k==="sui"){n.mergeCoins(n.gas,[D]);return}return await e.builder.utils.mergeSimilarCoins(n,D,e.utils.parseCoinType(k),t),D}))).filter(k=>!!k);return I.length>0&&n.transferObjects(I,t),n.txBlock}async build(e){return this.claimIncentiveRewards(e.scallopClient,e.account.address)}static fromData(e={}){return new i(e)}};var ja=class i extends A{constructor(t){super(t);this.data=t}txType;txSubType;async build(t){return t.scallopClient.depositCollateral(this.data.collateralCoinName,+this.data.amount,!1,this.data.obligationId)}static fromData(t){return new i(t)}};var Ua=class i extends A{constructor(t){super(t);this.data=t}txType;txSubType;async migrateAndClaim({account:t,scallopClient:n}){let o=t.address,{obligationKey:a,obligationId:c,rewardCoinName:l,veScaKey:d}=this.data,b=n.builder.createTxBlock();b.setSender(o);let w=Vt.redeem_rewards(b,a,c,n.utils.parseCoinType(l));return b.transferObjects([w],o),await b.unstakeObligationQuick(c,a),d?await b.stakeObligationWithVeScaQuick(c,a,d):await b.stakeObligationQuick(c,a),b.txBlock}async build(t){return this.migrateAndClaim(t)}static fromData(t){return new i(t)}};var qa=class i extends A{constructor(t){super(t);this.data=t}txType;txSubType;async build(t){return t.scallopClient.migrateAllMarketCoin(!1,!1)}static fromData(t){return new i(t)}};var Fa=class i extends A{constructor(t){super(t);this.data=t}txType;txSubType;async build(t){return t.scallopClient.openObligation(!1)}static fromData(t){return new i(t)}};var Ka=class i extends A{constructor(t){super(t);this.data=t}txType;txSubType;async repay({account:t,scallopClient:n}){let o=t.address,{coinName:a,amount:c,obligationId:l,obligationKey:d}=this.data;return(await this.buildTxWithRefreshObligation(n,{walletAddress:o,obligationId:l,obligationKey:d},async(w,I)=>{await I.repayQuick(+c,a,l)})).txBlock}async build(t){return this.repay(t)}static fromData(t){return new i(t)}};var $a=class i extends A{constructor(t){super(t);this.data=t}txType;txSubType;async repayWithBoost({account:t,scallopClient:n}){let o=t.address,{coinName:a,amount:c,obligationId:l,veScaKey:d}=this.data,b=n.builder.createTxBlock();b.setSender(o);let w=n.constants.whitelist.borrowing.has(a);return w&&await b.unstakeObligationQuick(l,void 0),await b.repayQuick(+c,a,l),w&&await b.stakeObligationWithVeScaQuick(l,void 0,d),b.txBlock}async build(t){return this.repayWithBoost(t)}static fromData(t){return new i(t)}};var Va=class i extends A{constructor(t){super(t);this.data=t}txType;txSubType;async build(t){return t.scallopClient.deposit(this.data.coinName,+this.data.amount,!1,t.account.address)}static fromData(t){return new i(t)}};var Ha=class i extends A{constructor(t){super(t);this.data=t}txType;txSubType;async build(t){return t.scallopClient.unstake(this.data.marketCoinName,+this.data.amount,!1)}static fromData(t){return new i(t)}};var Xa=class i extends A{constructor(t){super(t);this.data=t}txType;txSubType;async unstakeAndWithdraw(t,n,o){let a=t.builder.createTxBlock();a.setSender(o);let{stakeAccountId:c,amount:l,coinName:d}=this.data,b=[];for(let w=0;w<c.length;w++){let{id:I,coin:k}=c[w],v=t.utils.parseMarketCoinName(d),[D]=await a.unstakeQuick(k,v,I);if(D){let P=a.withdraw(D,d);b.push(P)}}if(l>0){let w=await a.withdrawQuick(l,d);b.push(w)}return b.length>1&&a.mergeCoins(b[0],b.slice(1)),a.transferObjects(b,o),a.txBlock}async build(t){return this.unstakeAndWithdraw(t.scallopClient,this.data,t.account.address)}static fromData(t){return new i(t)}};var za=class i extends A{constructor(t){super(t);this.data=t}txType;txSubType;async build(t){return t.scallopClient.withdrawCollateral(this.data.collateralCoinName,Number(this.data.amount),!1,this.data.obligationId,this.data.obligationKey,t.account.address)}static fromData(t){return new i(t)}};var Ga=class i extends A{constructor(t){super(t);this.data=t}txType;txSubType;async build(t){return t.scallopClient.withdraw(this.data.coinName,Number(this.data.amount),!1,t.account.address)}static fromData(t){return new i(t)}};var Qa=class i extends A{constructor(t){super(t);this.data=t}txType;txSubType;async bindReferral({account:t,scallopClient:n}){let o=t.address,a=n.builder.createTxBlock();return a.setSender(o),a.bindToReferral(this.data.veScaKey),a.txBlock}async build(t){return this.bindReferral(t)}static fromData(t){return new i(t)}};var Ja=class i extends A{constructor(t){super(t);this.data=t}txType;txSubType;async claimRevenueReferral({account:t,scallopClient:n}){let{veScaKey:o,coins:a}=this.data,c=t.address,l=n.builder.createTxBlock();l.setSender(c);let d=a.map(b=>n.utils.parseCoinNameFromType(b));return await l.claimReferralRevenueQuick(o,d),l.txBlock}async build(t){return this.claimRevenueReferral(t)}static fromData(t){return new i(t)}};var Ya=class i extends A{constructor(t){super(t);this.data=t}txType;txSubType;async createReferralLink({account:t,scallopClient:n}){let o=t.address,a=n.builder.createTxBlock();a.setSender(o);let c=a.mintEmptyVeSca();return a.transferObjects([c],o),a.txBlock}async build(t){return this.createReferralLink(t)}static fromData(t){return new i(t)}};var $u=require("@scallop-io/sui-scallop-sdk");var Za=class i extends A{constructor(t){super(t);this.data=t}txType;txSubType;async extendPeriodAndStakeMoreSca({account:t,scallopClient:n}){let{amount:o,veScaKey:a,unlockTime:c,obligationId:l,obligationKey:d,isOldBorrowIncentive:b,isObligationLocked:w}=this.data,I=t.address,k=n.builder.createTxBlock();k.setSender(I);let v=await n.utils.selectCoins(o,$u.SCA_COIN_TYPE,I),[D,P]=k.takeAmountFromCoins(v,o);return k.extendLockPeriod(a,c),k.extendLockAmount(a,D),k.transferObjects([P],I),!l||!d||(w&&(b?Vt.unstakeObligation(k,l,d):k.unstakeObligation(l,d)),k.stakeObligationWithVesca(l,d,a)),k.txBlock}async build(t){return this.extendPeriodAndStakeMoreSca(t)}static fromData(t){return new i(t)}};var ti=class i extends A{constructor(t){super(t);this.data=t}txType;txSubType;async extendStakeScaLockPeriod({account:t,scallopClient:n}){let o=t.address,{veScaKey:a,unlockTime:c,obligationId:l,obligationKey:d,isObligationLocked:b,isOldBorrowIncentive:w}=this.data,I=n.builder.createTxBlock();return I.setSender(o),I.extendLockPeriod(a,c),l&&d&&(b&&(w?Vt.unstakeObligation(I,d,l):I.unstakeObligation(l,d)),I.stakeObligationWithVesca(l,d,a)),I.txBlock}async build(t){return this.extendStakeScaLockPeriod(t)}static fromData(t){return new i(t)}};var ei=class i extends A{constructor(t){super(t);this.data=t}txType;txSubType;async handleUnsubForKeys(t,n,o){let{targetVeScaKey:a,sourceVeScaKey:c}=this.data,[l,d]=await Promise.all([n.getBindedObligationId(a),n.getBindedObligationId(c)]);l&&await t.unstakeObligationQuick(l),d&&await t.unstakeObligationQuick(d),o(t,a,c),l&&await t.stakeObligationWithVeScaQuick(l,void 0,a),d&&await t.stakeObligationWithVeScaQuick(d,void 0,c)}async build(t){let{scallopClient:n,account:{address:o}}=t,a=n.builder.createTxBlock();return a.setSender(o),await this.handleUnsubForKeys(a,n.query,async(c,l,d)=>{c.mergeVeSca(a.object(l),a.object(d))}),a.txBlock}static fromData(t){return new i(t)}};var ni=class i extends A{constructor(t){super(t);this.data=t}txType;txSubType;async redeemSca({account:t,scallopClient:n}){let{veScaKey:o}=this.data,a=t.address,c=n.builder.createTxBlock();return c.setSender(a),await c.redeemScaQuick(o),c.txBlock}async build(t){return this.redeemSca(t)}static fromData(t){return new i(t)}};var Vu=require("@scallop-io/sui-scallop-sdk");var oi=class i extends A{constructor(t){super(t);this.data=t}txType;txSubType;async renewExpiredStakeSca({account:t,scallopClient:n}){let o=t.address,{amount:a,unlockTime:c,veScaKey:l,isHaveRedeem:d,obligation:b,obligationKey:w,isObligationLocked:I,isOldBorrowIncentive:k}=this.data,v=n.builder.createTxBlock();if(v.setSender(o),d){let H=v.redeemSca(l);v.transferObjects([H],o)}let D=await n.builder.utils.selectCoins(a,Vu.SCA_COIN_TYPE,o),[P,K]=v.takeAmountFromCoins(D,a);return v.transferObjects([K],o),v.renewExpiredVeSca(l,P,c),!b||!w||(I&&(k?Vt.unstakeObligation(v,w,b):v.unstakeObligation(b,w)),v.stakeObligationWithVesca(b,w,l)),v.txBlock}async build(t){return this.renewExpiredStakeSca(t)}static fromData(t){return new i(t)}};var ai=class i extends A{constructor(t){super(t);this.data=t}txType;txSubType;async handleUnsubForKeys(t,n,o){let{targetVeScaKey:a,splitAmount:c}=this.data,l=await n.getBindedObligationId(a);l&&await t.unstakeObligationQuick(l),o(t,a,c.toString()),l&&await t.stakeObligationWithVeScaQuick(l,void 0,a)}async build(t){let{scallopClient:n,account:{address:o}}=t,a=n.builder.createTxBlock();return a.setSender(o),await this.handleUnsubForKeys(a,n.query,(c,l,d)=>{let b=c.splitVeSca(l,d.toString());c.transferObjects([b],o)}),a.txBlock}static fromData(t){return new i(t)}};var Hu=require("@scallop-io/sui-scallop-sdk");var ii=class i extends A{constructor(t){super(t);this.data=t}txType;txSubType;async stakeSca({account:t,scallopClient:n}){let o=t.address,{amount:a,isObligationLocked:c,isOldBorrowIncentive:l,obligationId:d,obligationKey:b,unlockTime:w,veScaKey:I}=this.data,k=n.builder.createTxBlock();k.setSender(o);let v=await n.utils.selectCoins(a,Hu.SCA_COIN_TYPE,o),[D,P]=k.takeAmountFromCoins(v,a),K;return I?k.extendLockAmount(I,D):K=k.lockSca(D,w),d&&b&&(c&&(l?Vt.unstakeObligation(k,b,d):k.unstakeObligation(d,b)),k.stakeObligationWithVesca(d,b,I||K)),I||k.transferObjects([K,P],o),k.txBlock}async build(t){return this.stakeSca(t)}static fromData(t){return new i(t)}};var ri=class i extends A{constructor(t){super(t);this.data=t}txType;txSubType;async supplyAndStake({account:t,scallopClient:n}){let o=t.address,{amount:a,coinName:c,stakeAccountId:l}=this.data,d=n.builder.createTxBlock();d.setSender(o);let b=await d.depositQuick(+a,c),w=n.utils.parseMarketCoinName(c);if(n.constants.whitelist.spool.has(w))return d.txBlock;let I=await n.query.getStakeAccounts(w,o),k=l||(I.length>0?I[0].id:void 0);if(k)await d.stakeQuick(b,w,k);else{let v=d.createStakeAccount(w);await d.stakeQuick(b,w,v),d.transferObjects([v],o)}return d.txBlock}async build(t){return this.supplyAndStake(t)}static fromData(t){return new i(t)}};var si=class i extends A{constructor(t){super(t);this.data=t}txType;txSubType;handleAction(t,{action:n,args:o}){switch(n){case"deactivate":return t.deactivateBoost(o.obligationId,o.veScaKey);case"stake":return t.stakeObligationWithVesca(o.obligationId,o.obligationKey,o.veScaKey);case"unstake":return t.unstakeObligation(o.obligationId,o.obligationKey);default:throw new Error("Invalid action")}}async build(t){let{scallopClient:n,account:{address:o}}=t,a=n.builder.createTxBlock();a.setSender(o);let{bindingDatas:c}=this.data;return c.forEach(l=>this.handleAction(a,l)),a.txBlock}static fromData(t){return new i(t)}};var ci=class i extends A{constructor(t){super(t);this.data=t}txType;txSubType;async build(t){let{scallopClient:n,account:{address:o}}=t,a=n.builder.createTxBlock();a.setSender(o);let{veScaKeys:c}=this.data;return a.transferObjects(c.map(l=>a.objectRef(l)),a.pure.address(o)),a.txBlock}static fromData(t){return new i(t)}};var li=class i extends A{constructor(t){super(t);this.data=t}txType;txSubType;async withdrawUnlockedSca({account:t,scallopClient:n}){let{vescaKey:o}=this.data,a=t.address,c=n.builder.createTxBlock();return c.setSender(a),await c.redeemScaQuick(o),c.txBlock}async build(t){return this.withdrawUnlockedSca(t)}static fromData(t){return new i(t)}};var ui=class{application="scallop";supportSDK="@mysten/sui";scallopClient;async initScallopClient(e,t){if(!this.scallopClient){let n=new Gu.Scallop({addressId:"67c44a103fe1b8c454eb9699",walletAddress:e,suiClients:[t],fullnodeUrls:[t.transport.rpcClient.requestManager.transports[0]?.uri??(0,zu.getFullnodeUrl)("mainnet")]});this.scallopClient=await n.createScallopClient()}}async deserialize(e){let{transaction:t,suiClient:n,account:o}=e;await this.initScallopClient(o.address,n),console.log("transaction",t);let a=new Pa(t,this.scallopClient),c=new Ba(t,this.scallopClient),l=new Ea(t,this.scallopClient),d=a.decode()||c.decode()||await l.decode();if(!d)throw new Error("Unknown transaction type");return{txType:Xu.TransactionType.Other,txSubType:d.type,intentionData:d.intentionData}}async build(e){let{suiClient:t,account:n,network:o,txSubType:a,intentionData:c}=e;await this.initScallopClient(n.address,t);let l;switch(a){case"SupplyLending":l=Va.fromData(c);break;case"WithdrawLending":l=Ga.fromData(c);break;case"Borrow":l=Na.fromData(c);break;case"Repay":l=Ka.fromData(c);break;case"DepositCollateral":l=ja.fromData(c);break;case"WithdrawCollateral":l=za.fromData(c);break;case"OpenObligation":l=Fa.fromData(c);break;case"UnstakeSpool":l=Ha.fromData(c);break;case"ClaimIncentiveReward":l=La.fromData(c);break;case"BorrowWithBoost":l=Wa.fromData(c);break;case"StakeSca":l=ii.fromData(c);break;case"ExtendStakePeriod":l=ti.fromData(c);break;case"ExtendPeriodAndStakeMore":l=Za.fromData(c);break;case"RenewExpStakePeriod":l=oi.fromData(c);break;case"WithdrawStakedSca":l=li.fromData(c);break;case"SupplyAndStakeLending":l=ri.fromData(c);break;case"WithdrawAndUnstakeLending":l=Xa.fromData(c);break;case"RedeemSca":l=ni.fromData(c);break;case"MigrateAndClaim":l=Ua.fromData(c);break;case"BorrowWithReferral":l=_a.fromData(c);break;case"CreateReferralLink":l=Ya.fromData(c);break;case"ClaimRevenueReferral":l=Ja.fromData(c);break;case"BindReferral":l=Qa.fromData(c);break;case"MigrateScoin":l=qa.fromData(c);break;case"RepayWithBoost":l=$a.fromData(c);break;case"MergeVeSca":l=ei.fromData(c);break;case"SplitVeSca":l=ai.fromData(c);break;case"VeScaObligationBindings":{l=si.fromData(c);break}case"TransferVeScaKeys":{l=ci.fromData(c);break}default:throw new Error("not implemented")}return l.build({suiClient:t,account:n,network:o,scallopClient:this.scallopClient})}};var ym=require("@msafe/sui3-utils");var sn=require("@msafe/sui3-utils"),Ce=require("@mysten/sui/utils");var sm=require("@suilend/sui-fe");var rm=require("@msafe/sui3-utils"),Ie=require("@suilend/sdk");var We=require("@msafe/sui3-utils"),an=require("@mysten/bcs"),on=require("@mysten/sui/utils"),_e=require("@suilend/sui-fe"),Ms=Ut(require("bignumber.js"));var mi=class{constructor(e,t){this.transaction=e;this.simResult=t}decode(){if(this.isDepositTransaction())return this.decodeDeposit();if(this.isWithdrawTransaction())return this.decodeWithdraw();if(this.isBorrowTransaction())return this.decodeBorrow();if(this.isRepayTransaction())return this.decodeRepay();if(this.isClaimTransaction())return this.decodeClaim();if(this.isClaimAndDepositTransaction())return this.decodeClaimAndDeposit();throw new Error("Unknown transaction type")}get inputs(){return console.log("this.transaction.getData().inputs",this.transaction.getData().inputs),this.transaction.getData().inputs}get commands(){return console.log("this.transaction.getData().commands",this.transaction.getData().commands),this.transaction.getData().commands}getMoveCallCommand(e){return this.commands.find(t=>t.$kind==="MoveCall"&&t.MoveCall.function===e)}hasDepositTransactionMoveCallCommands(){return!!this.getMoveCallCommand("deposit_liquidity_and_mint_ctokens")&&!!this.getMoveCallCommand("deposit_ctokens_into_obligation")}hasClaimTransactionMoveCallCommands(){return!!this.getMoveCallCommand("claim_rewards")}isDepositTransaction(){return!this.hasClaimTransactionMoveCallCommands()&&this.hasDepositTransactionMoveCallCommands()}isWithdrawTransaction(){return!!this.getMoveCallCommand("withdraw_ctokens")&&!!this.getMoveCallCommand("redeem_ctokens_and_withdraw_liquidity_request")}isBorrowTransaction(){return!!this.getMoveCallCommand("borrow_request")}isRepayTransaction(){return!!this.getMoveCallCommand("repay")}isClaimTransaction(){return this.hasClaimTransactionMoveCallCommands()&&!this.hasDepositTransactionMoveCallCommands()}isClaimAndDepositTransaction(){return this.hasClaimTransactionMoveCallCommands()&&this.hasDepositTransactionMoveCallCommands()}decodeDeposit(){let e={MintEvent:this.simResult.events.find(o=>o.type.includes("lending_market::MintEvent"))},t=(0,on.normalizeStructTag)(e.MintEvent.parsedJson.coin_type.name),n=e.MintEvent.parsedJson.liquidity_amount;return console.log("Decoder.decodeDeposit",t,n),{txType:We.TransactionType.Other,type:"deposit",intentionData:{coinType:t,value:n}}}decodeWithdraw(){let e={withdraw_ctokens:this.getMoveCallCommand("withdraw_ctokens")},t={RedeemEvent:this.simResult.events.find(d=>d.type.includes("lending_market::RedeemEvent"))},n=(0,on.normalizeStructTag)(t.RedeemEvent.parsedJson.coin_type.name),o=t.RedeemEvent.parsedJson.liquidity_amount;console.log("Decoder.decodeWithdraw",n,o);let a=e.withdraw_ctokens.MoveCall.arguments[4].Input,c=new Ms.default((0,an.toHex)((0,an.fromBase64)(this.inputs[a].Pure.bytes)),16).toString(),l=c===_e.MAX_U64.toString();return console.log("decodeWithdraw - isMax:",l,"inputIndex:",a,"inputValue:",c,"MAX_U64.toString():",_e.MAX_U64.toString()),l&&(o=_e.MAX_U64.toString()),{txType:We.TransactionType.Other,type:"withdraw",intentionData:{coinType:n,value:o}}}decodeBorrow(){let e={borrow_request:this.getMoveCallCommand("borrow_request")},t={BorrowEvent:this.simResult.events.find(d=>d.type.includes("lending_market::BorrowEvent"))},n=(0,on.normalizeStructTag)(t.BorrowEvent.parsedJson.coin_type.name),o=`${+t.BorrowEvent.parsedJson.liquidity_amount-+t.BorrowEvent.parsedJson.origination_fee_amount}`;console.log("Decoder.decodeBorrow",n,o);let a=e.borrow_request.MoveCall.arguments[4].Input,c=new Ms.default((0,an.toHex)((0,an.fromBase64)(this.inputs[a].Pure.bytes)),16).toString(),l=c===_e.MAX_U64.toString();return console.log("decodeBorrow - isMax:",l,"inputIndex:",a,"inputValue:",c,"MAX_U64.toString():",_e.MAX_U64.toString()),l&&(o=_e.MAX_U64.toString()),{txType:We.TransactionType.Other,type:"borrow",intentionData:{coinType:n,value:o}}}decodeRepay(){let e={RepayEvent:this.simResult.events.find(o=>o.type.includes("lending_market::RepayEvent"))},t=(0,on.normalizeStructTag)(e.RepayEvent.parsedJson.coin_type.name),n=e.RepayEvent.parsedJson.liquidity_amount;return console.log("Decoder.decodeRepay",t,n),{txType:We.TransactionType.Other,type:"repay",intentionData:{coinType:t,value:n}}}decodeClaim(){let e={ClaimReward:this.simResult.events.filter(n=>n.type.includes("lending_market::ClaimReward"))},t={};for(let n=0;n<e.ClaimReward.length;n++){let o=e.ClaimReward[n],a=(0,on.normalizeStructTag)(o.parsedJson.coin_type.name),c=o.parsedJson.liquidity_amount;t[a]=`${+(t[a]??"0")+ +c}`}return console.log("Decoder.decodeClaimRewards",t),{txType:We.TransactionType.Other,type:"claim",intentionData:{value:t}}}decodeClaimAndDeposit(){return{txType:We.TransactionType.Other,type:"claimAndDeposit",intentionData:this.decodeClaim().intentionData}}};var Ju=require("@mysten/sui/transactions");var Qu=Ut(require("sort-keys-recursive")),jt=class{constructor(e){this.data=e}serialize(){return JSON.stringify((0,Qu.default)(this.data))}};var pi=class i extends jt{constructor(t){super(t);this.data=t}txType;txSubType;async build(t){let{suiClient:n,account:o,suilendClient:a,obligationOwnerCap:c,obligation:l}=t;if(console.log("BorrowIntention.build",n,o,a,c,l),!c||!l)throw new Error("Obligation not found");let d=new Ju.Transaction;return await a.borrowAndSendToUser(o.address,c.id,l.id,this.data.coinType,this.data.value,d),d}static fromData(t){return console.log("BorrowIntention.fromData",t),new i(t)}};var em=require("@mysten/sui/transactions");var Yu=require("@mysten/sui/utils"),rn=require("@suilend/sdk"),Zu=require("@suilend/sui-fe"),tm=Ut(require("bignumber.js")),Ud=(i,e)=>{let t={[rn.Side.DEPOSIT]:[],[rn.Side.BORROW]:[]};return i.lendingMarket.reserves.forEach(n=>{[rn.Side.DEPOSIT,rn.Side.BORROW].forEach(o=>{let a=o===rn.Side.DEPOSIT?n.depositsPoolRewardManager:n.borrowsPoolRewardManager,c=e.userRewardManagers.find(l=>l.poolRewardManagerId===a.id);c&&(t[o]=a.poolRewards.map((l,d)=>({reserveArrayIndex:n.arrayIndex,rewardIndex:BigInt(d),rewardCoinType:(0,Yu.normalizeStructTag)(l.coinType.name),side:o})).filter(l=>!(0,Zu.isSendPoints)(l.rewardCoinType)&&!!c.rewards[Number(l.rewardIndex)]&&new tm.default(c.rewards[Number(l.rewardIndex)].earnedRewards.value.toString()).gt(0)))})}),Object.values(t).flat()},di=Ud;var fi=class i extends jt{constructor(t){super(t);this.data=t}txType;txSubType;async build(t){let{suiClient:n,account:o,suilendClient:a,obligationOwnerCap:c,obligation:l}=t;if(console.log("ClaimIntention.build",n,o,a,c,l),!c||!l)throw new Error("Obligation not found");let d=new em.Transaction;return a.claimRewardsAndSendToUser(o.address,c.id,di(a,l),d),d}static fromData(t){return console.log("ClaimIntention.fromData",t),new i(t)}};var nm=require("@mysten/sui/transactions");var hi=class i extends jt{constructor(t){super(t);this.data=t}txType;txSubType;async build(t){let{suiClient:n,account:o,suilendClient:a,obligationOwnerCap:c,obligation:l}=t;if(console.log("ClaimAndDepositIntention.build",n,o,a,c,l),!c||!l)throw new Error("Obligation not found");let d=new nm.Transaction;return a.claimRewardsAndDeposit(o.address,c.id,di(a,l),d),d}static fromData(t){return console.log("ClaimAndDepositIntention.fromData",t),new i(t)}};var om=require("@mysten/sui/transactions");var gi=class i extends jt{constructor(t){super(t);this.data=t}txType;txSubType;async build(t){let{suiClient:n,account:o,suilendClient:a,obligationOwnerCap:c,obligation:l}=t;console.log("DepositIntention.build",n,o,a,c,l);let d=new om.Transaction;return await a.depositIntoObligation(o.address,this.data.coinType,this.data.value,d,c?.id),d}static fromData(t){return console.log("DepositIntention.fromData",t),new i(t)}};var am=require("@mysten/sui/transactions");var yi=class i extends jt{constructor(t){super(t);this.data=t}txType;txSubType;async build(t){let{suiClient:n,account:o,suilendClient:a,obligationOwnerCap:c,obligation:l}=t;if(console.log("RepayIntention.build",n,o,a,c,l),!c||!l)throw new Error("Obligation not found");let d=new am.Transaction;return await a.repayIntoObligation(o.address,l.id,this.data.coinType,this.data.value,d),d}static fromData(t){return console.log("RepayIntention.fromData",t),new i(t)}};var im=require("@mysten/sui/transactions");var bi=class i extends jt{constructor(t){super(t);this.data=t}txType;txSubType;async build(t){let{suiClient:n,account:o,suilendClient:a,obligationOwnerCap:c,obligation:l}=t;if(console.log("WithdrawIntention.build",n,o,a,c,l),!c||!l)throw new Error("Obligation not found");let d=new im.Transaction;return await a.withdrawAndSendToUser(o.address,c.id,l.id,this.data.coinType,this.data.value,d),d}static fromData(t){return console.log("WithdrawIntention.fromData",t),new i(t)}};var Si=async(i,e)=>{let t=await Ie.SuilendClient.initialize(Ie.LENDING_MARKET_ID,Ie.LENDING_MARKET_TYPE,i),n=await Ie.SuilendClient.getObligationOwnerCaps(e.address,t.lendingMarket.$typeArgs,i),o=await Promise.all(n.map(a=>Ie.SuilendClient.getObligation(a.obligationId,t.lendingMarket.$typeArgs,i)));return console.log("XXX getUtils - suilendClient:",t,"obligations:",o,"obligationOwnerCaps:",n),{suilendClient:t,obligationOwnerCaps:n,obligations:o}},Ti=class{application="Suilend";supportSDK="@mysten/sui";utils;async deserialize(e){let{transaction:t,suiClient:n,account:o}=e;this.utils||(this.utils=await Si(n,o));let a=await n.devInspectTransactionBlock({sender:o.address,transactionBlock:t});console.log("SuilendAppHelper.deserialize - simResult:",a,"utils:",this.utils,"suiClient:",n);let l=new mi(t,a).decode();return{txType:rm.TransactionType.Other,txSubType:l.type,intentionData:l.intentionData}}async build(e){let{network:t,txSubType:n,intentionData:o,suiClient:a,account:c}=e;this.utils||(this.utils=await Si(a,c));let l;switch(n){case"deposit":l=gi.fromData(o);break;case"withdraw":l=bi.fromData(o);break;case"borrow":l=pi.fromData(o);break;case"repay":l=yi.fromData(o);break;case"claim":l=fi.fromData(o);break;case"claimAndDeposit":l=hi.fromData(o);break;default:throw new Error("not implemented")}let d=window.localStorage.getItem("obligationId"),b=this.utils.obligations?.find(I=>I.id===d)??this.utils.obligations?.[0],w=this.utils.obligationOwnerCaps?.find(I=>I.obligationId===b?.id);return l.build({network:t,suiClient:a,account:c,suilendClient:this.utils.suilendClient,obligationOwnerCap:w,obligation:b})}};var Os=async(i,e)=>{let t=await Si(i,e),n=await fetch(`${sm.API_URL}/springsui/lst-info`),o=await n.json();if(n?.statusCode===500)throw new Error("Failed to fetch SpringSui LST data");let c=Object.fromEntries(Object.values(o).map(l=>[l.LIQUID_STAKING_INFO.type,l.LIQUID_STAKING_INFO]));return{...t,LIQUID_STAKING_INFO_MAP:c}};var wi=class{constructor(e,t){this.transaction=e;this.simResult=t}decode(){if(this.isStakeTransaction())return this.decodeStake();if(this.isStakeAndDepositTransaction())return this.decodeStakeAndDeposit();if(this.isConvertTransaction())return this.decodeConvert();if(this.isConvertAndDepositTransaction())return this.decodeConvertAndDeposit();if(this.isUnstakeTransaction())return this.decodeUnstake();throw new Error("Unknown transaction type")}get commands(){return this.transaction.getData().commands}getMoveCallCommand(e){return this.commands.find(t=>t.$kind==="MoveCall"&&t.MoveCall.function===e)}hasSuilendDepositTransactionMoveCallCommands(){return!!this.getMoveCallCommand("deposit_liquidity_and_mint_ctokens")&&!!this.getMoveCallCommand("deposit_ctokens_into_obligation")}hasMintMoveCallCommands(){return!!this.getMoveCallCommand("mint")}hasRedeemMoveCallCommands(){return!!this.getMoveCallCommand("redeem")}isStakeTransaction(){return this.hasMintMoveCallCommands()&&!this.hasRedeemMoveCallCommands()&&!this.hasSuilendDepositTransactionMoveCallCommands()}isStakeAndDepositTransaction(){return this.hasMintMoveCallCommands()&&!this.hasRedeemMoveCallCommands()&&this.hasSuilendDepositTransactionMoveCallCommands()}isConvertTransaction(){return this.hasMintMoveCallCommands()&&this.hasRedeemMoveCallCommands()&&!this.hasSuilendDepositTransactionMoveCallCommands()}isConvertAndDepositTransaction(){return this.hasMintMoveCallCommands()&&this.hasRedeemMoveCallCommands()&&this.hasSuilendDepositTransactionMoveCallCommands()}isUnstakeTransaction(){return!this.hasMintMoveCallCommands()&&this.hasRedeemMoveCallCommands()&&!this.hasSuilendDepositTransactionMoveCallCommands()}decodeStake(){let e={MintEvent:this.simResult.events.find(o=>o.type.includes("liquid_staking::MintEvent"))},t=(0,Ce.normalizeStructTag)(e.MintEvent.parsedJson.event.typename.name),n=e.MintEvent.parsedJson.event.sui_amount_in;return console.log("Decoder.decodeStake",n),{txType:sn.TransactionType.Other,type:"stake",intentionData:{amount:n,outCoinType:t}}}decodeStakeAndDeposit(){let e={MintEvent:this.simResult.events.find(o=>o.type.includes("liquid_staking::MintEvent"))},t=(0,Ce.normalizeStructTag)(e.MintEvent.parsedJson.event.typename.name),n=e.MintEvent.parsedJson.event.sui_amount_in;return console.log("Decoder.decodeStakeAndDeposit",n),{txType:sn.TransactionType.Other,type:"stakeAndDeposit",intentionData:{amount:n,outCoinType:t}}}decodeConvert(){let e={RedeemEvent:this.simResult.events.find(a=>a.type.includes("liquid_staking::RedeemEvent")),MintEvent:this.simResult.events.find(a=>a.type.includes("liquid_staking::MintEvent"))},t=(0,Ce.normalizeStructTag)(e.RedeemEvent.parsedJson.event.typename.name),n=(0,Ce.normalizeStructTag)(e.MintEvent.parsedJson.event.typename.name),o=e.RedeemEvent.parsedJson.event.lst_amount_in;return console.log("Decoder.decodeConvert",o),{txType:sn.TransactionType.Other,type:"convert",intentionData:{amount:o,inCoinType:t,outCoinType:n}}}decodeConvertAndDeposit(){let e={RedeemEvent:this.simResult.events.find(a=>a.type.includes("liquid_staking::RedeemEvent")),MintEvent:this.simResult.events.find(a=>a.type.includes("liquid_staking::MintEvent"))},t=(0,Ce.normalizeStructTag)(e.RedeemEvent.parsedJson.event.typename.name),n=(0,Ce.normalizeStructTag)(e.MintEvent.parsedJson.event.typename.name),o=e.RedeemEvent.parsedJson.event.lst_amount_in;return console.log("Decoder.decodeConvertAndDeposit",o),{txType:sn.TransactionType.Other,type:"convertAndDeposit",intentionData:{amount:o,inCoinType:t,outCoinType:n}}}decodeUnstake(){let e={RedeemEvent:this.simResult.events.find(o=>o.type.includes("liquid_staking::RedeemEvent"))},t=(0,Ce.normalizeStructTag)(e.RedeemEvent.parsedJson.event.typename.name),n=e.RedeemEvent.parsedJson.event.lst_amount_in;return console.log("Decoder.decodeUnstake",n),{txType:sn.TransactionType.Other,type:"unstake",intentionData:{amount:n,inCoinType:t}}}};var lm=require("@mysten/sui/transactions"),jn=require("@suilend/springsui-sdk");var cm=Ut(require("sort-keys-recursive")),Ht=class{constructor(e){this.data=e}serialize(){return JSON.stringify((0,cm.default)(this.data))}};var Ii=class i extends Ht{constructor(t){super(t);this.data=t}txType;txSubType;async build(t){let{suiClient:n,account:o,suilendClient:a,LIQUID_STAKING_INFO_MAP:c,obligationOwnerCap:l,obligation:d}=t;console.log("ConvertIntention.build",n,o,a,c,l,d);let b=await jn.LstClient.initialize(n,Object.values(c).find(k=>k.type===this.data.inCoinType)),w=await jn.LstClient.initialize(n,Object.values(c).find(k=>k.type===this.data.outCoinType)),I=new lm.Transaction;return(0,jn.convertLstsAndSendToUser)(b,w,I,o.address,this.data.amount),I}static fromData(t){return console.log("ConvertIntention.fromData",t),new i(t)}};var um=require("@mysten/sui/transactions"),ki=require("@suilend/sdk"),Un=require("@suilend/springsui-sdk");var Ci=class i extends Ht{constructor(t){super(t);this.data=t}txType;txSubType;async build(t){let{suiClient:n,account:o,suilendClient:a,LIQUID_STAKING_INFO_MAP:c,obligationOwnerCap:l,obligation:d}=t;console.log("ConvertAndDepositIntention.build",n,o,a,c,l,d);let b=await Un.LstClient.initialize(n,Object.values(c).find(P=>P.type===this.data.inCoinType)),w=await Un.LstClient.initialize(n,Object.values(c).find(P=>P.type===this.data.outCoinType)),I=new um.Transaction,{obligationOwnerCapId:k,didCreate:v}=(0,ki.createObligationIfNoneExists)(a,I,l),D=(0,Un.convertLsts)(b,w,I,o.address,this.data.amount);return a.deposit(D,this.data.outCoinType,k,I),v&&(0,ki.sendObligationToUser)(k,o.address,I),I}static fromData(t){return console.log("ConvertAndDepositIntention.fromData",t),new i(t)}};var mm=require("@mysten/sui/transactions"),pm=require("@suilend/springsui-sdk");var vi=class i extends Ht{constructor(t){super(t);this.data=t}txType;txSubType;async build(t){let{suiClient:n,account:o,suilendClient:a,LIQUID_STAKING_INFO_MAP:c,obligationOwnerCap:l,obligation:d}=t;console.log("StakeIntention.build",n,o,a,c,l,d);let b=await pm.LstClient.initialize(n,Object.values(c).find(I=>I.type===this.data.outCoinType)),w=new mm.Transaction;return b.mintAmountAndRebalanceAndSendToUser(w,o.address,this.data.amount),w}static fromData(t){return console.log("StakeIntention.fromData",t),new i(t)}};var dm=require("@mysten/sui/transactions"),xi=require("@suilend/sdk"),fm=require("@suilend/springsui-sdk");var Di=class i extends Ht{constructor(t){super(t);this.data=t}txType;txSubType;async build(t){let{suiClient:n,account:o,suilendClient:a,LIQUID_STAKING_INFO_MAP:c,obligationOwnerCap:l,obligation:d}=t;console.log("StakeAndDepositIntention.build",n,o,a,c,l,d);let b=await fm.LstClient.initialize(n,Object.values(c).find(D=>D.type===this.data.outCoinType)),w=new dm.Transaction,{obligationOwnerCapId:I,didCreate:k}=(0,xi.createObligationIfNoneExists)(a,w,l),v=b.mintAmountAndRebalance(w,o.address,this.data.amount);return a.deposit(v,this.data.outCoinType,I,w),k&&(0,xi.sendObligationToUser)(I,o.address,w),w}static fromData(t){return console.log("StakeAndDepositIntention.fromData",t),new i(t)}};var hm=require("@mysten/sui/transactions"),gm=require("@suilend/springsui-sdk");var Ai=class i extends Ht{constructor(t){super(t);this.data=t}txType;txSubType;async build(t){let{suiClient:n,account:o,suilendClient:a,LIQUID_STAKING_INFO_MAP:c,obligationOwnerCap:l,obligation:d}=t;console.log("UnstakeIntention.build",n,o,a,c,l,d);let b=await gm.LstClient.initialize(n,Object.values(c).find(I=>I.type===this.data.inCoinType)),w=new hm.Transaction;return b.redeemAmountAndSendToUser(w,o.address,this.data.amount),w}static fromData(t){return console.log("UnstakeIntention.fromData",t),new i(t)}};var Mi=class{application="SpringSui";supportSDK="@mysten/sui";utils;async deserialize(e){let{transaction:t,suiClient:n,account:o}=e;this.utils||(this.utils=await Os(n,o));let a=await n.devInspectTransactionBlock({sender:o.address,transactionBlock:t});console.log("SpringSuiAppHelper.deserialize",a);let l=new wi(t,a).decode();return{txType:ym.TransactionType.Other,txSubType:l.type,intentionData:l.intentionData}}async build(e){let{network:t,txSubType:n,intentionData:o,suiClient:a,account:c}=e;this.utils||(this.utils=await Os(a,c));let l;switch(n){case"stake":l=vi.fromData(o);break;case"stakeAndDeposit":l=Di.fromData(o);break;case"convert":l=Ii.fromData(o);break;case"convertAndDeposit":l=Ci.fromData(o);break;case"unstake":l=Ai.fromData(o);break;default:throw new Error("not implemented")}return l.build({network:t,suiClient:a,account:c,suilendClient:this.utils.suilendClient,LIQUID_STAKING_INFO_MAP:this.utils.LIQUID_STAKING_INFO_MAP,obligationOwnerCap:this.utils.obligationOwnerCaps?.[0],obligation:this.utils.obligations?.[0]})}};var Tm=require("@msafe/sui3-utils");var Ps=require("@msafe/sui3-utils");var Oi=class{constructor(e,t){this.transaction=e;this.simResult=t}decode(){if(this.isMintTransaction()){let e=this.getLiquidityChangeEvent("MintEvent");if(!e)throw new Error("No liquidity change event found. Unable to decode transaction.");let t=e.parsedJson;return console.log("Decoder event data - ",t),this.decodeMint(t)}if(this.isRedeemTransaction()){let e=this.getLiquidityChangeEvent("RedeemEvent");if(!e)throw new Error("No liquidity change event found. Unable to decode transaction.");let t=e.parsedJson;return console.log("Decoder event data - ",t),this.decodeRedeem(t)}throw new Error("Unknown transaction type")}get commands(){return this.transaction.getData().commands}getMoveCallCommand(e){return this.commands.find(t=>t.$kind==="MoveCall"&&t.MoveCall.function===e)}getLiquidityChangeEvent(e){return this.simResult.events.find(t=>this.isLiquidityChangeEventType(t.type,e))}isLiquidityChangeEventType(e,t){return e.includes(t)}isMintTransaction(){return!!this.getMoveCallCommand("mint")}isRedeemTransaction(){return!!this.getMoveCallCommand("redeem")}decodeMint(e){let{event:{sui_amount_in:t}}=e;return console.log("Decoder.decodeMint",t),{txType:Ps.TransactionType.Other,type:"mint",intentionData:{amount:t}}}decodeRedeem(e){let{event:{lst_amount_in:t}}=e;return console.log("Decoder.decodeRedeem",t),{txType:Ps.TransactionType.Other,type:"redeem",intentionData:{amount:t}}}};var bm=require("@alphafi/stsui-sdk");var Pi=class i extends C{constructor(t){super(t);this.data=t}txType;txSubType;async build(t){let{account:n}=t,{amount:o}=this.data,a={lstInfo:"0x1adb343ab351458e151bc392fbf1558b3332467f23bda45ae67cd355a57fd5f5",lstCointype:"0xd1b72982e40348d069bb1ff701e634c117bb5f741f44dff91e472d3b01461e55::stsui::STSUI"},l=await new bm.LST(a).mint(o,n.address);return l.setGasBudget(1e8),l}static fromData(t){return console.log("MintIntention.fromData",t),new i(t)}};var Sm=require("@alphafi/stsui-sdk");var Ri=class i extends C{constructor(t){super(t);this.data=t}txType;txSubType;async build(t){let{account:n}=t,{amount:o}=this.data,a={lstInfo:"0x1adb343ab351458e151bc392fbf1558b3332467f23bda45ae67cd355a57fd5f5",lstCointype:"0xd1b72982e40348d069bb1ff701e634c117bb5f741f44dff91e472d3b01461e55::stsui::STSUI"},l=await new Sm.LST(a).redeem(o,n.address);return l.setGasBudget(1e8),l}static fromData(t){return console.log("RedeemIntention.fromData",t),new i(t)}};var Bi=class{application="stsui";supportSDK="@mysten/sui";async deserialize(e){let{transaction:t,suiClient:n}=e,o=await n.devInspectTransactionBlock({sender:t.getData().sender,transactionBlock:t});console.log("StSuiHelper Sim result - ",o);let c=new Oi(t,o).decode();return{txType:Tm.TransactionType.Other,txSubType:c.type,intentionData:c.intentionData}}async build(e){let{account:t}=e;console.log("StSui build transaction type",e.txSubType);let n;switch(e.txSubType){case"mint":n=Pi.fromData(e.intentionData);break;case"redeem":n=Ri.fromData(e.intentionData);break;default:throw new Error("build not implemented")}return n.build({account:t})}};var $m=require("@msafe/sui3-utils"),Vm=require("turbos-clmm-sdk");var Nt=require("@msafe/sui3-utils"),Le=require("@mysten/bcs"),je=require("@mysten/sui/bcs"),wm=require("turbos-clmm-sdk");var zt={PackageId:"0x02fe4933f4521250e55a15441096d1d4a38a7311195b0bca126fc0138c1f5a97",Claim:"0x0c822cec42f7ca703696b4232f1c47b348330c23580172a29aab465bc071d894",turbosCoinType:"0x5d1f47ea69bb0de31c313d7acf89b890dbb8991ea8e03c6c355171f84bb1ba4a::turbos::TURBOS"},Gt={PackageId:"0xdee9"};var $d=(i,e,t,n)=>{if(i===1)switch(n.findIndex(c=>c===e)){case 0:return[!0,!0];case 1:return[!0,!1];case 2:return[!1,!0];case 3:return[!1,!1];default:throw new Error(`not target: ${e}`)}switch(t.findIndex(a=>a===e)){case 0:return[!0];case 1:return[!1];default:throw new Error(`not target: ${e}`)}},Ei=class{constructor(e,t,n){this.txb=e;this.turbosSdk=t;this.config=n}get transactions(){return this.txb.getData().commands}get swap1Layer(){return[`${this.config.PackageId}::swap_router::swap_a_b`,`${this.config.PackageId}::swap_router::swap_b_a`]}get swap2Layer(){return[`${this.config.PackageId}::swap_router::swap_a_b_b_c`,`${this.config.PackageId}::swap_router::swap_a_b_c_b`,`${this.config.PackageId}::swap_router::swap_b_a_b_c`,`${this.config.PackageId}::swap_router::swap_b_a_c_b`]}async decode(e){if(this.isSwapTransaction())return this.decodeSwap();if(this.isAddLiquidityTransaction())return this.decodeAddLiquidity();if(this.isIncreaseLiquidityTransaction())return this.decodeIncreaseLiquidity(e);if(this.isRemoveLiquidityTransaction())return this.decodeRemoveLiquidity(e);if(this.isDecreaseLiquidityTransaction())return this.decodeDecreaseLiquidity(e);if(this.isRemoveLiquidityWithReturnTransaction())return this.decodeRemoveLiquidityWithReturn(e);if(this.isDecreaseLiquidityWithReturnTransaction())return this.decodeDecreaseLiquidityWithReturn(e);if(this.isCollectFeeTransaction())return this.decodeCollectFee();if(this.isCollectRewardTransaction())return this.decodeCollectReward();if(this.isBurnTransaction())return this.decodeBurn();if(this.isPrixClaimTransaction())return this.decodePrixClaim();if(this.isPrixJoinTransaction())return this.decodePrixJoin();if(this.isSwapExactBaseForQuoteTransaction())return this.decodeSwapExactBaseForQuote();if(this.isSwapExactQuoteForBaseTransaction())return this.decodeSwapExactQuoteForBase();throw new Error("Unknown transaction type")}getMoveCallTransaction(e){return this.transactions.find(t=>t.$kind==="MoveCall"?`${t.MoveCall.package}::${t.MoveCall.module}::${t.MoveCall.function}`===e:!1)}getMoveCallsTransaction(e){return e.every(t=>this.transactions.find(n=>n.$kind==="MoveCall"?`${n.MoveCall.package}::${n.MoveCall.module}::${n.MoveCall.function}`===t:!1))}getSwapMoveCallTransaction(e){return this.transactions.find(t=>{if(t.$kind==="MoveCall"){let n=`${t.MoveCall.package}::${t.MoveCall.module}::${t.MoveCall.function}`;return!!e.includes(n)}return!1})}isSwapTransaction(){return!!this.getSwapMoveCallTransaction([...this.swap1Layer,...this.swap2Layer])}isAddLiquidityTransaction(){return!!this.getMoveCallTransaction(`${this.config.PackageId}::position_manager::mint`)}isIncreaseLiquidityTransaction(){return!!this.getMoveCallTransaction(`${this.config.PackageId}::position_manager::increase_liquidity`)}isDecreaseLiquidityTransaction(){return!!this.getMoveCallTransaction(`${this.config.PackageId}::position_manager::decrease_liquidity`)}isDecreaseLiquidityWithReturnTransaction(){return!!this.getMoveCallTransaction(`${this.config.PackageId}::position_manager::decrease_liquidity_with_return_`)}isCollectFeeTransaction(){return!!this.getMoveCallTransaction(`${this.config.PackageId}::position_manager::collect`)}isCollectRewardTransaction(){return!!this.getMoveCallTransaction(`${this.config.PackageId}::position_manager::collect_reward`)}isBurnTransaction(){return!!this.getMoveCallTransaction(`${this.config.PackageId}::position_manager::burn`)}isPrixJoinTransaction(){return!!this.getMoveCallTransaction(`${zt.PackageId}::claim::join`)}isPrixClaimTransaction(){return!!this.getMoveCallTransaction(`${zt.PackageId}::claim::claim`)}isRemoveLiquidityTransaction(){return!!this.getMoveCallsTransaction([`${this.config.PackageId}::position_manager::decrease_liquidity`,`${this.config.PackageId}::position_manager::burn`])}isRemoveLiquidityWithReturnTransaction(){return!!this.getMoveCallsTransaction([`${this.config.PackageId}::position_manager::decrease_liquidity_with_return_`,`${this.config.PackageId}::position_manager::burn`])}isSwapExactBaseForQuoteTransaction(){return!!this.getMoveCallTransaction(`${Gt.PackageId}::clob_v2::swap_exact_base_for_quote`)}isSwapExactQuoteForBaseTransaction(){return!!this.getMoveCallTransaction(`${Gt.PackageId}::clob_v2::swap_exact_quote_for_base`)}async decodeSwap(){let e=this.transactions.find(v=>v.$kind==="MoveCall"),t=0,n=`${e.MoveCall.package}::${e.MoveCall.module}::${e.MoveCall.function}`;this.swap2Layer.includes(n)&&(t=1);let o=$d(t,n,this.swap1Layer,this.swap2Layer),a=o.map((v,D)=>{let P=this.helper.decodeSharedObjectId(D),K=this.helper.decodeInputU128(4+D+t),H=this.turbosSdk.math.sqrtPriceX64ToTickIndex(new wm.BN(K.toString()));return{pool:P,a2b:v,nextTickIndex:H}}),c=o[0]||t===1?e.MoveCall.typeArguments[0]:e.MoveCall.typeArguments[1],l=t===1?e.MoveCall.typeArguments[4]:o[0]?e.MoveCall.typeArguments[1]:e.MoveCall.typeArguments[0],d=this.helper.decodeInputAddress(6+2*t),b=this.helper.decodeInputU64(7+2*t),w=this.helper.decodeInputBool(5+2*t),I=this.helper.decodeInputU64(2+t),k=this.helper.decodeInputU64(3+t);return{txType:Nt.TransactionType.Other,type:"Swap",intentionData:{routes:a,coinTypeA:c,coinTypeB:l,address:d,amountA:w?I:k,amountB:w?k:I,amountSpecifiedIsInput:w,slippage:"0.1",deadline:b}}}decodeAddLiquidity(){console.log(this.helper,"decodeAddLiquidity this.helper");let e=this.helper.decodeSharedObjectId(0),t=this.helper.decodeInputAddress(12),n=this.helper.decodeInputU64(8),o=this.helper.decodeInputU64(9),a=this.helper.decodeInputU32(4),c=this.helper.decodeInputBool(5),l=this.helper.decodeInputU32(6),d=this.helper.decodeInputBool(7),b=this.helper.decodeInputU64(13);return{txType:Nt.TransactionType.Other,type:"AddLiquidity",intentionData:{pool:e,slippage:10,address:t,amountA:n,amountB:o,tickLower:c?-a:a,tickUpper:d?-l:l,deadline:b}}}decodeIncreaseLiquidity(e){console.log(this.helper,"decodeIncreaseLiquidity this.helper");let t=this.helper.decodeSharedObjectId(0),n=this.helper.decodeSharedObjectId(4),o=this.helper.decodeInputU64(5),a=this.helper.decodeInputU64(6),c=this.helper.decodeInputU64(9);return{txType:Nt.TransactionType.Other,type:"IncreaseLiquidity",intentionData:{pool:t,slippage:10,address:e,amountA:o,amountB:a,nft:n,deadline:c}}}decodeDecreaseLiquidity(e){console.log(this.helper,"decodeDecreaseLiquidity this.helper");let t=this.helper.decodeSharedObjectId(0),n=this.helper.decodeSharedObjectId(2),o=this.helper.decodeInputU64(3),a=this.helper.decodeInputU64(4),c=this.helper.decodeInputU64(5),l=this.helper.decodeInputU64(6);return{txType:Nt.TransactionType.Other,type:"DecreaseLiquidity",intentionData:{pool:t,decreaseLiquidity:o,nft:n,amountA:a,amountB:c,slippage:10,address:e,deadline:l}}}decodeDecreaseLiquidityWithReturn(e){console.log(this.helper,"decodeDecreaseLiquidityWithReturn this.helper");let t=this.helper.decodeSharedObjectId(0),n=this.helper.decodeSharedObjectId(2),o=this.helper.decodeInputU64(3),a=this.helper.decodeInputU64(4),c=this.helper.decodeInputU64(5),l=this.helper.decodeInputU64(6);return{txType:Nt.TransactionType.Other,type:"DecreaseLiquidityWithReturn",intentionData:{pool:t,decreaseLiquidity:o,nft:n,amountA:a,amountB:c,slippage:10,address:e,deadline:l}}}decodeCollectFee(){console.log(this.helper,"decodeCollectFee this.helper");let e=this.helper.decodeSharedObjectId(0),t=this.helper.decodeSharedObjectId(2),n=this.helper.decodeInputAddress(5),o=this.helper.decodeInputU64(3),a=this.helper.decodeInputU64(4),c=this.helper.decodeInputU64(6);return{txType:Nt.TransactionType.Other,type:"CollectFee",intentionData:{pool:e,address:n,collectAmountA:o,collectAmountB:a,nft:t,deadline:c}}}decodeCollectReward(){console.log(this.helper,"decodeCollectReward this.helper");let e=this.helper.decodeSharedObjectId(0),t=this.helper.decodeSharedObjectId(2),n=this.helper.decodeInputAddress(6),o=this.collectRewardHelper.map(c=>c.decodeInputU64(5)),a=this.helper.decodeInputU64(7);return{txType:Nt.TransactionType.Other,type:"CollectReward",intentionData:{pool:e,address:n,rewardAmounts:o,nft:t,deadline:a}}}decodeBurn(){console.log(this.helper,"decodeBurn this.helper");let e=this.helper.decodeSharedObjectId(0),t=this.helper.decodeSharedObjectId(2);return{txType:Nt.TransactionType.Other,type:"Burn",intentionData:{pool:e,nft:t}}}decodeRemoveLiquidity(e){console.log(this.helper,"decodeRemoveLiquidity this.helper");let t=this.decreaseLiquidityHelper.decodeSharedObjectId(0),n=this.decreaseLiquidityHelper.decodeSharedObjectId(2),o=this.decreaseLiquidityHelper.decodeInputU64(3),a=this.decreaseLiquidityHelper.decodeInputU64(4),c=this.decreaseLiquidityHelper.decodeInputU64(5),l=this.decreaseLiquidityHelper.decodeInputU64(6),d=this.collectRewardHelper.map(I=>I.decodeInputU64(5)),b=this.collectFeeHelper.decodeInputU64(3)||0,w=this.collectFeeHelper.decodeInputU64(4)||0;return{txType:Nt.TransactionType.Other,type:"RemoveLiquidity",intentionData:{pool:t,decreaseLiquidity:o,nft:n,amountA:a,amountB:c,slippage:10,address:e,collectAmountA:b,collectAmountB:w,rewardAmounts:d,deadline:l}}}decodeRemoveLiquidityWithReturn(e){console.log(this.helper,"decodeRemoveLiquidityWithReturn this.helper");let t=this.decreaseLiquidityHelper.decodeSharedObjectId(0),n=this.decreaseLiquidityHelper.decodeSharedObjectId(2),o=this.decreaseLiquidityHelper.decodeInputU64(3),a=this.decreaseLiquidityHelper.decodeInputU64(4),c=this.decreaseLiquidityHelper.decodeInputU64(5),l=this.decreaseLiquidityHelper.decodeInputU64(6),d=this.collectRewardHelper.map(I=>I.decodeInputU64(5)),b=this.collectFeeHelper.decodeInputU64(3)||0,w=this.collectFeeHelper.decodeInputU64(4)||0;return{txType:Nt.TransactionType.Other,type:"removeLiquidityWithReturn",intentionData:{pool:t,decreaseLiquidity:o,nft:n,amountA:a,amountB:c,slippage:10,address:e,collectAmountA:b,collectAmountB:w,rewardAmounts:d,deadline:l}}}decodePrixClaim(){return{txType:Nt.TransactionType.Other,type:"PrixClaim",intentionData:{}}}decodePrixJoin(){return{txType:Nt.TransactionType.Other,type:"PrixJoin",intentionData:{}}}decodeSwapExactBaseForQuote(){let e=this.swapExactBaseForQuoteHelper.decodeSharedObjectId(0),t=this.swapExactBaseForQuoteHelper.decodeInputU64(3),n=this.swapExactBaseForQuoteHelper.shortTypeArg(0),o=this.swapExactBaseForQuoteHelper.shortTypeArg(1);return{txType:Nt.TransactionType.Other,type:"SwapExactBaseForQuote",intentionData:{poolId:e,amountIn:t,token1:n,token2:o}}}decodeSwapExactQuoteForBase(){let e=this.swapExactQuoteForBaseHelper.decodeSharedObjectId(0),t=this.swapExactQuoteForBaseHelper.decodeInputU64(3),n=this.swapExactQuoteForBaseHelper.shortTypeArg(0),o=this.swapExactQuoteForBaseHelper.shortTypeArg(1);return{txType:Nt.TransactionType.Other,type:"SwapExactQuoteForBase",intentionData:{poolId:e,amountIn:t,token1:n,token2:o}}}get helper(){let e=this.transactions.find(t=>{if(t.$kind==="MoveCall"){let n=`${t.MoveCall.package}::${t.MoveCall.module}::${t.MoveCall.function}`;return n!=="0x2::coin::zero"&&n!=="0x0000000000000000000000000000000000000000000000000000000000000002::coin::zero"}return!1});return new ke(e,this.txb)}get collectRewardHelper(){return this.transactions.filter(t=>t.$kind==="MoveCall"?`${t.MoveCall.package}::${t.MoveCall.module}::${t.MoveCall.function}`===`${this.config.PackageId}::position_manager::collect_reward`:!1).map(t=>new ke(t,this.txb))}get collectFeeHelper(){let e=this.transactions.find(t=>t.$kind==="MoveCall"?`${t.MoveCall.package}::${t.MoveCall.module}::${t.MoveCall.function}`===`${this.config.PackageId}::position_manager::collect`:!1);return new ke(e,this.txb)}get decreaseLiquidityHelper(){let e=this.transactions.find(t=>t.$kind==="MoveCall"?`${t.MoveCall.package}::${t.MoveCall.module}::${t.MoveCall.function}`===`${this.config.PackageId}::position_manager::decrease_liquidity`:!1);return new ke(e,this.txb)}get swapExactBaseForQuoteHelper(){let e=this.transactions.find(t=>t.$kind==="MoveCall"?`${t.MoveCall.package}::${t.MoveCall.module}::${t.MoveCall.function}`===`${Gt.PackageId}::clob_v2::swap_exact_base_for_quote`:!1);return new ke(e,this.txb)}get swapExactQuoteForBaseHelper(){let e=this.transactions.find(t=>t.$kind==="MoveCall"?`${t.MoveCall.package}::${t.MoveCall.module}::${t.MoveCall.function}`===`${Gt.PackageId}::clob_v2::swap_exact_quote_for_base`:!1);return new ke(e,this.txb)}},ke=class{constructor(e,t){this.moveCall=e;this.txb=t}get inputs(){return this.txb.getData().inputs}decodeSharedObjectId(e){return this.inputs[e].Object?.SharedObject?.objectId||this.inputs[e].UnresolvedObject.objectId}decodeOwnedObjectId(e){return this.inputs[e].Object?.ImmOrOwnedObject?.objectId||this.inputs[e].UnresolvedObject.objectId}decodeInputU128(e){return Number(je.bcs.u128().parse(Uint8Array.from((0,Le.fromBase64)(this.inputs[e].Pure.bytes))))}decodeInputU64(e){return Number(je.bcs.u64().parse(Uint8Array.from((0,Le.fromBase64)(this.inputs[e].Pure.bytes))))}decodeInputU32(e){return Number(je.bcs.u32().parse(Uint8Array.from((0,Le.fromBase64)(this.inputs[e].Pure.bytes))))}decodeInputU8(e){return Number(je.bcs.u8().parse(Uint8Array.from((0,Le.fromBase64)(this.inputs[e].Pure.bytes))))}decodeInputAddress(e){return je.bcs.Address.parse(Uint8Array.from((0,Le.fromBase64)(this.inputs[e].Pure.bytes)))}decodeInputBool(e){return je.bcs.bool().parse(Uint8Array.from((0,Le.fromBase64)(this.inputs[e].Pure.bytes)))}shortTypeArg(e){return this.moveCall.MoveCall.typeArguments[e]}txArg(e){return this.moveCall.MoveCall.arguments[e]}};var Im=require("turbos-clmm-sdk");var Ni=class i extends C{constructor(t){super(t);this.data=t}txType;txSubType;async build(t){let n=new Im.TurbosSdk(t.network.replace("sui:",""),t.suiClient),{pool:o,address:a,amountA:c,amountB:l,slippage:d,tickLower:b,tickUpper:w,deadline:I,txb:k}=this.data;return n.pool.addLiquidity({pool:o,slippage:d,address:a,amountA:c,amountB:l,tickLower:b,tickUpper:w,deadline:I,txb:k})}static fromData(t){return new i(t)}};var Cm=require("turbos-clmm-sdk");var Wi=class i extends C{constructor(t){super(t);this.data=t}txType;txSubType;async build(t){let n=new Cm.TurbosSdk(t.network.replace("sui:",""),t.suiClient),{pool:o,nft:a,txb:c}=this.data;return n.position.burn({pool:o,nft:a,txb:c})}static fromData(t){return new i(t)}};var km=require("turbos-clmm-sdk");var _i=class i extends C{constructor(t){super(t);this.data=t}txType;txSubType;async build(t){let n=new km.TurbosSdk(t.network.replace("sui:",""),t.suiClient),{pool:o,address:a,nft:c,collectAmountA:l,collectAmountB:d,deadline:b,txb:w}=this.data;return n.pool.collectFee({pool:o,address:a,collectAmountA:l,collectAmountB:d,nft:c,deadline:b,txb:w})}static fromData(t){return new i(t)}};var vm=require("turbos-clmm-sdk");var Li=class i extends C{constructor(t){super(t);this.data=t}txType;txSubType;async build(t){let n=new vm.TurbosSdk(t.network.replace("sui:",""),t.suiClient),{pool:o,address:a,nft:c,rewardAmounts:l,deadline:d,txb:b}=this.data;return n.pool.collectReward({pool:o,address:a,rewardAmounts:l,nft:c,deadline:d,txb:b})}static fromData(t){return new i(t)}};var Dm=require("turbos-clmm-sdk");var ji=class i extends C{constructor(t){super(t);this.data=t}txType;txSubType;async build(t){let n=new Dm.TurbosSdk(t.network.replace("sui:",""),t.suiClient),{fee:o,address:a,tickLower:c,tickUpper:l,sqrtPrice:d,slippage:b,coinTypeA:w,coinTypeB:I,amountA:k,amountB:v,deadline:D,txb:P}=this.data;return n.pool.createPool({fee:o,amountA:k,amountB:v,address:a,tickLower:c,tickUpper:l,sqrtPrice:d,slippage:b,coinTypeA:w,coinTypeB:I,deadline:D,txb:P})}static fromData(t){return new i(t)}};var xm=require("turbos-clmm-sdk");var Ui=class i extends C{constructor(t){super(t);this.data=t}txType;txSubType;async build(t){let n=new xm.TurbosSdk(t.network.replace("sui:",""),t.suiClient),{pool:o,address:a,amountA:c,amountB:l,slippage:d,nft:b,decreaseLiquidity:w,deadline:I,txb:k}=this.data;return n.pool.decreaseLiquidity({pool:o,slippage:d,address:a,amountA:c,amountB:l,nft:b,decreaseLiquidity:w,deadline:I,txb:k})}static fromData(t){return new i(t)}};var Am=require("turbos-clmm-sdk");var qi=class i extends C{constructor(t){super(t);this.data=t}txType;txSubType;async build(t){let n=new Am.TurbosSdk(t.network.replace("sui:",""),t.suiClient),{pool:o,address:a,amountA:c,amountB:l,slippage:d,nft:b,decreaseLiquidity:w,deadline:I}=this.data,{txb:k,coinA:v,coinB:D}=await n.pool.decreaseLiquidityWithReturn({pool:o,slippage:d,address:a,amountA:c,amountB:l,nft:b,decreaseLiquidity:w,deadline:I});return k.transferObjects([v,D],this.data.address),k}static fromData(t){return new i(t)}};var Mm=require("turbos-clmm-sdk");var Fi=class i extends C{constructor(t){super(t);this.data=t}txType;txSubType;async build(t){let n=new Mm.TurbosSdk(t.network.replace("sui:",""),t.suiClient),{pool:o,address:a,amountA:c,amountB:l,slippage:d,nft:b,deadline:w,txb:I}=this.data;return n.pool.increaseLiquidity({pool:o,slippage:d,address:a,amountA:c,amountB:l,nft:b,deadline:w,txb:I})}static fromData(t){return new i(t)}};var Om=require("@mysten/sui/transactions"),Pm=require("@mysten/sui/utils");var Ki=class i extends C{constructor(t){super(t);this.data=t}txType;txSubType;async build(t){let n=new Om.Transaction;return n.moveCall({target:`${zt.PackageId}::claim::claim`,typeArguments:[zt.turbosCoinType],arguments:[n.object(zt.Claim),n.object(Pm.SUI_CLOCK_OBJECT_ID)]}),n}static fromData(t){return new i(t)}};var Rm=require("@mysten/sui/transactions");var $i=class i extends C{constructor(t){super(t);this.data=t}txType;txSubType;async build(t){let n=new Rm.Transaction;return n.moveCall({target:`${zt.PackageId}::claim::join`,typeArguments:[zt.turbosCoinType],arguments:[n.object(zt.Claim)]}),n}static fromData(t){return new i(t)}};var Bm=require("@mysten/sui/transactions"),Em=require("turbos-clmm-sdk");var Vi=class i extends C{constructor(t){super(t);this.data=t}txType;txSubType;async build(t){let n=new Em.TurbosSdk(t.network.replace("sui:",""),t.suiClient),o=new Bm.Transaction;return o=await n.pool.collectFee({txb:o,...this.data}),o=await n.pool.collectReward({txb:o,...this.data}),o=await n.pool.decreaseLiquidity({txb:o,...this.data}),o=await n.position.burn({txb:o,nft:this.data.nft,pool:this.data.pool}),o}static fromData(t){return new i(t)}};var Nm=require("turbos-clmm-sdk");var Hi=class i extends C{constructor(t){super(t);this.data=t}txType;txSubType;async build(t){let n=new Nm.TurbosSdk(t.network.replace("sui:",""),t.suiClient),{txb:o,coinA:a,coinB:c}=await n.pool.removeLiquidityWithReturn({...this.data});return o.transferObjects([a,c],this.data.address),o}static fromData(t){return new i(t)}};var Wm=require("turbos-clmm-sdk");var Xi=class i extends C{constructor(t){super(t);this.data=t}txType;txSubType;async build(t){console.log(this.data,"this.data");let n=new Wm.TurbosSdk(t.network.replace("sui:",""),t.suiClient),{routes:o,coinTypeA:a,coinTypeB:c,address:l,amountA:d,amountB:b,slippage:w,amountSpecifiedIsInput:I,deadline:k,txb:v}=this.data;return n.trade.swap({routes:o,coinTypeA:a,coinTypeB:c,address:l,amountA:d,amountB:b,amountSpecifiedIsInput:I,slippage:w,deadline:k,txb:v})}static fromData(t){return new i(t)}};var Fm=require("turbos-clmm-sdk");var Rs=require("@mysten/sui/transactions"),Bs=require("@mysten/sui/utils");var _m=require("turbos-clmm-sdk");var qn=class{constructor(e){this.turbosSdk=e}async getCoinsData(e,t,n){let o=[],a;do a=await this.turbosSdk.provider.getCoins({owner:e,coinType:t,cursor:a?.nextCursor}),o.push(...a.data);while(a.hasNextPage);let c=[],l=0;return o.sort((d,b)=>Number(b.balance)-Number(d.balance)).some(d=>l>=n?!0:(l+=Number(d.balance),c.push(d),!1)),c}splitAndMergeCoin(e,t,n){if(!e||e.length<1)return[void 0,void 0];if(this.isSuiCoinAddress(e[0].coinType)){let[c]=n.splitCoins(n.gas,[n.pure.u64(t)]);return[c,void 0]}let o=n.object(e[0].coinObjectId);e.length>1&&n.mergeCoins(o,e.slice(1).map(c=>n.object(c.coinObjectId)));let[a]=n.splitCoins(o,[n.pure.u64(t)]);return[a,o]}isSuiCoinAddress(e){return e.toLocaleLowerCase()==="0x2::sui::sui"}async IsAccountCap(e){let t=await this.turbosSdk.provider.getOwnedObjects({owner:e,options:{showContent:!0,showType:!0,showOwner:!0},filter:{StructType:`${Gt.PackageId}::custodian_v2::AccountCap`}});return t.data[0]?.data?(0,_m.unstable_getObjectId)(t.data[0].data):void 0}createAccount(e){let[t]=e.moveCall({typeArguments:[],target:`${Gt.PackageId}::clob_v2::create_account`,arguments:[]});return t}zero(e,t){return t.moveCall({typeArguments:[e],target:"0x2::coin::zero",arguments:[]})}};var Lm=89,jm=1e6,Um=async i=>{let{token1:e,token2:t,poolId:n,amountIn:o,currentAddress:a,turbosSdk:c}=i,l=new Rs.Transaction,d=new qn(c),b=await d.getCoinsData(a,t,o),[w,I]=d.splitAndMergeCoin(b,o,l);if(!w)throw new Error(`Not enough balance: ${t}`);let k=await d.IsAccountCap(a),v=k?l.object(k):d.createAccount(l),[D,P,K]=l.moveCall({typeArguments:[e,t],target:`${Gt.PackageId}::clob_v2::swap_exact_quote_for_base`,arguments:[l.object(String(n)),l.pure.u64(Lm),v,l.pure.u64(o),l.object((0,Bs.normalizeSuiObjectId)("0x6")),w]});return I&&l.transferObjects([I],l.pure.address(a)),l.transferObjects([D],l.pure.address(a)),l.transferObjects([P],l.pure.address(a)),k||l.transferObjects([v],l.pure.address(a)),l.setSenderIfNotSet(a),l.setGasBudget(jm),l},qm=async i=>{let{token1:e,token2:t,poolId:n,amountIn:o,currentAddress:a,turbosSdk:c}=i,l=new Rs.Transaction,d=new qn(c),b=await d.getCoinsData(a,e,o),[w,I]=d.splitAndMergeCoin(b,o,l);if(!w)throw new Error(`Not enough balance: ${e}`);let k=await d.IsAccountCap(a),v=k?l.object(k):d.createAccount(l),D=d.zero(t,l),[P,K,H]=l.moveCall({typeArguments:[e,t],target:`${Gt.PackageId}::clob_v2::swap_exact_base_for_quote`,arguments:[l.object(String(n)),l.pure.u64(Lm),v,l.pure.u64(o),w,D,l.object((0,Bs.normalizeSuiObjectId)("0x6"))]});return I&&l.transferObjects([I],l.pure.address(a)),l.transferObjects([P],l.pure.address(a)),l.transferObjects([K],l.pure.address(a)),k||l.transferObjects([v],l.pure.address(a)),l.setSenderIfNotSet(a),l.setGasBudget(jm),l};var zi=class i extends C{constructor(t){super(t);this.data=t}txType;txSubType;async build(t){let n=new Fm.TurbosSdk(t.network.replace("sui:",""),t.suiClient);return await qm({...this.data,turbosSdk:n,currentAddress:t.account.address})}static fromData(t){return new i(t)}};var Km=require("turbos-clmm-sdk");var Gi=class i extends C{constructor(t){super(t);this.data=t}txType;txSubType;async build(t){let n=new Km.TurbosSdk(t.network.replace("sui:",""),t.suiClient);return await Um({...this.data,turbosSdk:n,currentAddress:t.account.address})}static fromData(t){return new i(t)}};var Qi=class{application="turbos";supportSDK="@mysten/sui";async deserialize(e){console.log(e,"input");let t=new Vm.TurbosSdk(e.network.replace("sui:","")),n=await t.contract.getConfig(),{transaction:o,account:a}=e,l=await new Ei(o,t,n).decode(a.address);return{txType:$m.TransactionType.Other,txSubType:l.type,intentionData:l.intentionData}}async build(e){let{suiClient:t,account:n,network:o}=e;console.log(e.intentionData,"intentionData");let a;switch(e.txSubType){case"CreatePool":a=ji.fromData(e.intentionData);break;case"AddLiquidity":a=Ni.fromData(e.intentionData);break;case"IncreaseLiquidity":a=Fi.fromData(e.intentionData);break;case"DecreaseLiquidity":a=Ui.fromData(e.intentionData);break;case"DecreaseLiquidityWithReturn":a=qi.fromData(e.intentionData);break;case"RemoveLiquidity":a=Vi.fromData(e.intentionData);break;case"removeLiquidityWithReturn":a=Hi.fromData(e.intentionData);break;case"CollectFee":a=_i.fromData(e.intentionData);break;case"CollectReward":a=Li.fromData(e.intentionData);break;case"Burn":a=Wi.fromData(e.intentionData);break;case"Swap":a=Xi.fromData(e.intentionData);break;case"PrixJoin":a=$i.fromData(e.intentionData);break;case"PrixClaim":a=Ki.fromData(e.intentionData);break;case"SwapExactBaseForQuote":a=zi.fromData(e.intentionData);break;case"SwapExactQuoteForBase":a=Gi.fromData(e.intentionData);break;default:throw new Error("not implemented")}return a.build({suiClient:t,account:n,network:o})}};var Gm=require("@msafe/sui3-utils");var Ji=require("@msafe/sui3-utils"),Es=require("@mysten/sui.js/bcs"),ve=require("@mysten/sui.js/utils");var Vd={packageId:"0x549e8b69270defbfafd4f94e17ec44cdbdd99820b33bda2278dea3b9a32d3f55",poolObjectId:"0x7fa2faa111b8c65bea48a23049bfd81ca8f971a262d981dcd9a17c3825cb5baf",metadataObjectId:"0x680cd26af32b2bde8d3361e804c53ec1d1cfe24c7f039eb7f549e8dfde389a60",systemStateObjectId:"0x0000000000000000000000000000000000000000000000000000000000000005",certType:"0x549e8b69270defbfafd4f94e17ec44cdbdd99820b33bda2278dea3b9a32d3f55::cert::CERT",gasBudget:5e7},xt=Vd;var Yi=class{constructor(e){this.txb=e}decode(){if(console.log("txb",this.txb),this.isStakeTransaction())return this.decodeStake();if(this.isUnStakeTransaction())return this.decodeUnStake();if(this.isClaimTicketTransaction())return this.decodeClaimTicket();throw new Error("Unknown transaction type")}get transactions(){return this.txb.blockData.transactions}getMoveCallTransaction(e){return this.transactions.find(t=>t.kind==="MoveCall"&&t.target===e)}isStakeTransaction(){return!!this.getMoveCallTransaction(`${xt.packageId}::native_pool::stake`)}isUnStakeTransaction(){return!!this.getMoveCallTransaction(`${xt.packageId}::native_pool::unstake`)}isClaimTicketTransaction(){return!!this.getMoveCallTransaction(`${xt.packageId}::native_pool::burn_ticket`)}decodeStake(){let e=this.transactions[0].amounts[0].value.toNumber();return{txType:Ji.TransactionType.Other,type:"Stake",intentionData:{amount:e}}}decodeUnStake(){let t=this.transactions.find(n=>n.kind==="SplitCoins").amounts[0].value.toNumber();return{txType:Ji.TransactionType.Other,type:"UnStake",intentionData:{amount:t}}}decodeClaimTicket(){let e=this.helper.decodeOwnedObjectId(2);return console.log(e),{txType:Ji.TransactionType.Other,type:"ClaimTicket",intentionData:{ticketId:e}}}get helper(){let e=this.transactions.find(t=>t.kind==="MoveCall"&&t.target.startsWith(xt.packageId));return new Ns(e,this.txb)}},Ns=class i{constructor(e,t){this.moveCall=e;this.txb=t}decodeSharedObjectId(e){let t=this.getInputParam(e);return i.getSharedObjectId(t)}decodeOwnedObjectId(e){let t=this.getInputParam(e);return i.getOwnedObjectId(t)}decodeInputU64(e){let t=this.decodePureArg(e,"u64");return Number(t)}decodeInputU8(e){let t=this.decodePureArg(e,"u8");return Number(t)}decodeInputAddress(e){let t=this.decodePureArg(e,"address");return(0,ve.normalizeSuiAddress)(t)}decodeInputString(e){return this.decodePureArg(e,"string")}decodeInputBool(e){return this.decodePureArg(e,"bool")}decodePureArg(e,t){let n=this.getInputParam(e);return i.getPureInputValue(n,t)}getInputParam(e){let t=this.moveCall.arguments[e];if(t.kind!=="Input")throw new Error("not input type");return this.txb.blockData.inputs[t.index]}static getPureInputValue(e,t){if(e.type!=="pure")throw new Error("not pure argument");if(typeof e.value=="object"&&"Pure"in e.value){let n=e.value.Pure;return Es.bcs.de(t,new Uint8Array(n))}return e.value}static getOwnedObjectId(e){if(e.type!=="object")throw new Error(`not object argument: ${JSON.stringify(e)}`);if(typeof e.value=="object"){if(!("Object"in e.value)||!("ImmOrOwned"in e.value.Object))throw new Error("not ImmOrOwned");return(0,ve.normalizeSuiAddress)(e.value.Object.ImmOrOwned.objectId)}return(0,ve.normalizeSuiAddress)(e.value)}static getSharedObjectId(e){if(e.type!=="object")throw new Error(`not object argument: ${JSON.stringify(e)}`);if(typeof e.value!="object")return(0,ve.normalizeSuiAddress)(e.value);if(!("Object"in e.value)||!("Shared"in e.value.Object))throw new Error("not Shared");return(0,ve.normalizeSuiAddress)(e.value.Object.Shared.objectId)}static getPureInput(e,t){if(e.type!=="pure")throw new Error("not pure argument");if(typeof e.value!="object")return e.value;if(!("Pure"in e.value))throw new Error("Pure not in value");let n=e.value.Pure;return Es.bcs.de(t,new Uint8Array(n))}typeArg(e){return(0,ve.normalizeStructTag)(this.moveCall.typeArguments[e])}txArg(e){return this.moveCall.arguments[e]}};var Hm=require("@mysten/sui.js/transactions");var Zi=class i extends _{constructor(t){super(t);this.data=t}txType;txSubType;async build(t){console.log(t);let n=new Hm.TransactionBlock,{ticketId:o}=this.data;return n.moveCall({target:`${xt.packageId}::native_pool::burn_ticket`,arguments:[n.object(xt.poolObjectId),n.object(xt.systemStateObjectId),n.object(o)]}),n}static fromData(t){return new i(t)}};var Xm=require("@mysten/sui.js/transactions");var tr=class i extends _{constructor(t){super(t);this.data=t}txType;txSubType;async build(t){console.log(t);let n=new Xm.TransactionBlock,{amount:o}=this.data,[a]=n.splitCoins(n.gas,[n.pure(o)]);return n.moveCall({target:`${xt.packageId}::native_pool::stake`,arguments:[n.object(xt.poolObjectId),n.object(xt.metadataObjectId),n.object(xt.systemStateObjectId),a]}),n}static fromData(t){return new i(t)}};var zm=require("@mysten/sui.js/transactions");var er=class i extends _{constructor(t){super(t);this.data=t}txType;txSubType;async build(t){console.log(t);let n=new zm.TransactionBlock,{amount:o}=this.data,a=(await t.suiClient.getAllCoins({owner:t.account.address,limit:100})).data,[c,...l]=a.filter(w=>w.coinType.split("::")[0]===xt.certType.split("::")[0]),d=n.object(c.coinObjectId);l.length&&n.mergeCoins(d,l.map(w=>n.object(w.coinObjectId)));let b=n.splitCoins(n.object(c.coinObjectId),[n.pure(o)]);return n.moveCall({target:`${xt.packageId}::native_pool::unstake`,arguments:[n.object(xt.poolObjectId),n.object(xt.metadataObjectId),n.object(xt.systemStateObjectId),b]}),n}static fromData(t){return new i(t)}};var nr=class{application="volo";supportSDK="@mysten/sui.js";async deserialize(e){let{transactionBlock:t}=e,o=new Yi(t).decode();return{txType:Gm.TransactionType.Other,txSubType:o.type,intentionData:o.intentionData}}async build(e){let{suiClient:t,account:n}=e,o;switch(e.txSubType){case"Stake":o=tr.fromData(e.intentionData);break;case"UnStake":o=er.fromData(e.intentionData);break;case"ClaimTicket":o=Zi.fromData(e.intentionData);break;default:throw new Error("not implemented")}return o.build({suiClient:t,account:n})}};var rp=require("@msafe/sui3-utils");var Ws=require("@cetusprotocol/common-sdk"),De=require("@msafe/sui3-utils"),cn=require("@mysten/bcs"),ln=require("@mysten/sui/bcs");var or=class{constructor(e){this.transaction=e}decode(){if(this.isOpenPositionTx())return this.decodeOpenPositionTx();if(this.isClosePositionTx())return this.decodeClosePositionTx();if(this.isProvideLiquidityTx())return this.decodeProvideLiquidityTx();if(this.isRemoveLiquidityTx())return this.decodeRemoveLiquidityTx();if(this.isCollectRewardsAndFeeTx())return this.decodeCollectRewardsAndFeeTx();if(this.isCollectRewardsTx())return this.decodeCollectRewardsTx();if(this.isCollectFeeTx())return this.decodeCollectFeeTx();throw new Error("Unknown transaction type")}decodeOpenPositionTx(){let e=this.getMoveCallCommand("open_position"),t=this.getMoveCallCommand("provide_liquidity_with_fixed_amount");return{txType:De.TransactionType.Other,type:"OpenPosition",intentionData:{pool:this.getSharedObjectID(this.getInputIndex(e,1)),lowerTick:Number((0,Ws.asIntN)(BigInt(this.getU32(this.getInputIndex(e,2)))).toString()),upperTick:Number((0,Ws.asIntN)(BigInt(this.getU32(this.getInputIndex(e,3)))).toString()),tokenAmount:this.getU64(this.getInputIndex(t,6)),maxAmountTokenA:this.getU64(this.getInputIndex(t,7)),maxAmountTokenB:this.getU64(this.getInputIndex(t,8)),isTokenAFixed:this.getBoolean(this.getInputIndex(t,9))}}}decodeClosePositionTx(){let e=this.getMoveCallCommand("close_position"),t=this.getCollectRewardCallData();return{txType:De.TransactionType.Other,type:"ClosePosition",intentionData:{pool:this.getSharedObjectID(this.getInputIndex(e,2)),position:this.getOwnedObjectID(this.getInputIndex(e,3)),transferTokensTo:this.getAddress(this.getInputIndex(e,4)),collectRewardTokens:t.map(n=>n.rewardCoinType),collectFeeTokens:this.getTypeArguments(e)}}}decodeProvideLiquidityTx(){let e=this.getMoveCallCommand("provide_liquidity_with_fixed_amount");return{txType:De.TransactionType.Other,type:"ProvideLiquidity",intentionData:{pool:this.getSharedObjectID(this.getInputIndex(e,2)),position:this.getOwnedObjectID(this.getInputIndex(e,3)),tokenAmount:this.getU64(this.getInputIndex(e,6)),maxAmountTokenA:this.getU64(this.getInputIndex(e,7)),maxAmountTokenB:this.getU64(this.getInputIndex(e,8)),isTokenAFixed:this.getBoolean(this.getInputIndex(e,9))}}}decodeRemoveLiquidityTx(){let e=this.getMoveCallCommand("remove_liquidity");return{txType:De.TransactionType.Other,type:"RemoveLiquidity",intentionData:{pool:this.getSharedObjectID(this.getInputIndex(e,2)),position:this.getOwnedObjectID(this.getInputIndex(e,3)),liquidity:this.getU128(this.getInputIndex(e,4)),maxAmountTokenA:this.getU64(this.getInputIndex(e,5)),maxAmountTokenB:this.getU64(this.getInputIndex(e,6)),transferTokensTo:this.getAddress(this.getInputIndex(e,7)),...this.collectTokens()}}}decodeCollectRewardsTx(){let e=this.getCollectRewardCallData();return{txType:De.TransactionType.Other,type:"CollectRewards",intentionData:{pool:e[0].pool,position:e[0].position,collectRewardTokens:e.map(t=>t.rewardCoinType)}}}decodeCollectFeeTx(){return{txType:De.TransactionType.Other,type:"CollectFee",intentionData:this.getFeeCallData()}}decodeCollectRewardsAndFeeTx(){let e=this.getFeeCallData();return{txType:De.TransactionType.Other,type:"CollectRewardsAndFee",intentionData:{pool:e.pool,position:e.position,...this.collectTokens()}}}getFeeCallData(){let e=this.getMoveCallCommand("collect_fee");return{pool:this.getSharedObjectID(this.getInputIndex(e,2)),position:this.getOwnedObjectID(this.getInputIndex(e,3)),collectFeeTokens:this.getTypeArguments(e)}}getCollectRewardCallData(){let e=[];return this.commands.forEach(t=>{t.$kind==="MoveCall"&&t.MoveCall.function==="collect_reward"&&e.push({pool:this.getSharedObjectID(this.getInputIndex(t,2)),position:this.getOwnedObjectID(this.getInputIndex(t,3)),rewardCoinType:this.getTypeArguments(t)[2]})}),e}collectTokens(){let e=this.getFeeCallData(),t=this.getCollectRewardCallData();return{collectFeeTokens:e.collectFeeTokens,collectRewardTokens:t.map(n=>n.rewardCoinType)}}get commands(){return this.transaction.getData().commands}get inputs(){return this.transaction.getData().inputs}isOpenPositionTx(){return!!this.getMoveCallCommand("open_position")}isProvideLiquidityTx(){return!!this.getMoveCallCommand("provide_liquidity_with_fixed_amount")}isRemoveLiquidityTx(){return!!this.getMoveCallCommand("remove_liquidity")}isCollectRewardsTx(){return!!this.getMoveCallCommand("collect_reward")}isCollectFeeTx(){return!!this.getMoveCallCommand("collect_fee")}isCollectRewardsAndFeeTx(){return this.isCollectRewardsTx()&&this.isCollectFeeTx()}isClosePositionTx(){return!!this.getMoveCallCommand("close_position")}getMoveCallCommand(e){return this.commands.find(t=>t.$kind==="MoveCall"&&t.MoveCall.function===e)}getSharedObjectID(e){return this.inputs[e].Object.SharedObject.objectId}getOwnedObjectID(e){return this.inputs[e].Object.ImmOrOwnedObject.objectId}getU32(e){return String(ln.bcs.u32().parse(Uint8Array.from((0,cn.fromBase64)(this.inputs[e].Pure.bytes))))}getU64(e){return ln.bcs.u64().parse(Uint8Array.from((0,cn.fromBase64)(this.inputs[e].Pure.bytes)))}getU128(e){return ln.bcs.u128().parse(Uint8Array.from((0,cn.fromBase64)(this.inputs[e].Pure.bytes)))}getBoolean(e){return ln.bcs.bool().parse(Uint8Array.from((0,cn.fromBase64)(this.inputs[e].Pure.bytes)))}getAddress(e){return ln.bcs.Address.parse(Uint8Array.from((0,cn.fromBase64)(this.inputs[e].Pure.bytes)))}getTypeArguments(e){return e.MoveCall.typeArguments||[]}getInputIndex(e,t){return e.MoveCall.arguments[t].Input}};var Zm=require("@msafe/sui3-utils");var ee=require("@firefly-exchange/library-sui");var Jm=require("@firefly-exchange/library-sui"),Ym=require("@firefly-exchange/library-sui/dist/src/spot"),Qm={rpc:"https://fullnode.mainnet.sui.io/",objects:{GlobalConfig:"0x03db251ba509a8d5d8777b6338836082335d93eecbdd09a11e190a1cff51c352",BasePackage:"0x3492c874c1e3b3e2984e8c41b589e642d4d0a5d6459e5a9cfc2d52fd7c89c267",CurrentPackage:"0x67b34b728c4e28e704dcfecf7c5cf55c7fc593b6c65c20d1836d97c209c1928a"}},Ae=(i,e)=>{if(i!=="sui:mainnet")throw new Error("Bluefin spot protocol is only available on sui::mainnet");let t=new Jm.SuiClient({url:Qm.rpc});return new Ym.OnChainCalls(t,Qm.objects,{address:e.address,isUIWallet:!1})};var Rt=class{static async OpenPosition(e,t,n){let o=Ae(n,t),a=await o.queryChain.getPool(e.pool),c=this.prototype.buildLiqInput(a,{...e,slippage:0});return await o.openPositionWithFixedAmount(a,e.lowerTick,e.upperTick,c,{returnTx:!0,sender:t.address})}static async provideLiquidity(e,t,n){let o=Ae(n,t),a=await o.queryChain.getPool(e.pool),c=this.prototype.buildLiqInput(a,e);return await o.provideLiquidityWithFixedAmount(a,e.position,c,{returnTx:!0,sender:t.address})}static async removeLiquidity(e,t,n){let o=Ae(n,t),a=await o.queryChain.getPool(e.pool);return await o.removeLiquidity(a,e.position,{liquidityAmount:new ee.BN(e.liquidity),tokenMaxA:new ee.BN(e.maxAmountTokenA),tokenMaxB:new ee.BN(e.maxAmountTokenB)},{returnTx:!0,sender:t.address})}static async closePosition(e,t,n){let o=Ae(n,t),a=await o.queryChain.getPool(e.pool);return await o.closePosition(a,e.position,{returnTx:!0,sender:t.address})}static async collectRewards(e,t,n){let o=Ae(n,t),a=await o.queryChain.getPool(e.pool);return await o.collectRewards(a,e.position,{rewardCoinsType:e.collectRewardTokens,returnTx:!0,sender:t.address})}static async collectFee(e,t,n){let o=Ae(n,t),a=await o.queryChain.getPool(e.pool);return await o.collectFee(a,e.position,{returnTx:!0,sender:t.address})}static async collectRewardsAndFee(e,t,n){let o=Ae(n,t),a=await o.queryChain.getPool(e.pool);return console.log(e.position),await o.collectFeeAndRewards(a,e.position,{returnTx:!0,sender:t.address})}buildLiqInput(e,t){return{...ee.ClmmPoolUtil.estLiquidityAndCoinAmountFromOneAmounts(t.lowerTick,t.upperTick,new ee.BN(t.tokenAmount),t.isTokenAFixed,!0,0,new ee.BN(e.current_sqrt_price)),tokenMaxA:new ee.BN(t.maxAmountTokenA),tokenMaxB:new ee.BN(t.maxAmountTokenB)}}};var ar=class i extends C{constructor(t){super(t);this.data=t}txType=Zm.TransactionType.Other;txSubType="ClosePosition";async build(t){let{account:n,network:o}=t;return console.log(this.data),Rt.closePosition(this.data,n,o)}static fromData(t){return new i(t)}};var tp=require("@msafe/sui3-utils");var ir=class i extends C{constructor(t){super(t);this.data=t}txType=tp.TransactionType.Other;txSubType="CollectFee";async build(t){let{account:n,network:o}=t;return console.log(this.data),Rt.collectFee(this.data,n,o)}static fromData(t){return new i(t)}};var ep=require("@msafe/sui3-utils");var rr=class i extends C{constructor(t){super(t);this.data=t}txType=ep.TransactionType.Other;txSubType="CollectRewards";async build(t){let{account:n,network:o}=t;return console.log(this.data),Rt.collectRewards(this.data,n,o)}static fromData(t){return new i(t)}};var np=require("@msafe/sui3-utils");var sr=class i extends C{constructor(t){super(t);this.data=t}txType=np.TransactionType.Other;txSubType="CollectRewardsAndFee";async build(t){let{account:n,network:o}=t;return console.log(this.data),Rt.collectRewardsAndFee(this.data,n,o)}static fromData(t){return new i(t)}};var op=require("@msafe/sui3-utils");var cr=class i extends C{constructor(t){super(t);this.data=t}txType=op.TransactionType.Other;txSubType="OpenPosition";async build(t){let{account:n,network:o}=t;return console.log(this.data),Rt.OpenPosition(this.data,n,o)}static fromData(t){return new i(t)}};var ap=require("@msafe/sui3-utils");var lr=class i extends C{constructor(t){super(t);this.data=t}txType=ap.TransactionType.Other;txSubType="ProvideLiquidity";async build(t){let{account:n,network:o}=t;return console.log(this.data),Rt.provideLiquidity(this.data,n,o)}static fromData(t){return new i(t)}};var ip=require("@msafe/sui3-utils");var ur=class i extends C{constructor(t){super(t);this.data=t}txType=ip.TransactionType.Other;txSubType="RemoveLiquidity";async build(t){let{account:n,network:o}=t;return console.log(this.data),Rt.removeLiquidity(this.data,n,o)}static fromData(t){return new i(t)}};var mr=class{application="bluefin";supportSDK="@mysten/sui";async deserialize(e){console.log("Bluefin helper deserialize input: ",e);let{transaction:t}=e,o=new or(t).decode();return{txType:rp.TransactionType.Other,txSubType:o.type,intentionData:o.intentionData}}async build(e){let{suiClient:t,account:n,network:o}=e;console.log(e.txSubType);let a;switch(e.txSubType){case"OpenPosition":a=cr.fromData(e.intentionData);break;case"ProvideLiquidity":a=lr.fromData(e.intentionData);break;case"RemoveLiquidity":a=ur.fromData(e.intentionData);break;case"ClosePosition":a=ar.fromData(e.intentionData);break;case"CollectFee":a=ir.fromData(e.intentionData);break;case"CollectRewards":a=rr.fromData(e.intentionData);break;case"CollectRewardsAndFee":a=sr.fromData(e.intentionData);break;default:throw new Error("not implemented")}return a.build({suiClient:t,account:n,network:o})}};var Lp=require("@msafe/sui3-utils");var yp=require("@mmt-finance/clmm-sdk"),bp=require("@mysten/sui/transactions");var Ue=require("@mmt-finance/clmm-sdk/dist/utils/math/tickMath"),R=Ut(cp());var Xd="0x0000000000000000000000000000000000000000000000000000000000000002::sui::SUI",Me=i=>i!=="0x2::sui::SUI"?i:"0x0000000000000000000000000000000000000000000000000000000000000002::sui::SUI",zd=async({suiClient:i,address:e,type:t})=>{let n,o=[],a=0;do{try{let c=await i.getCoins({owner:e,coinType:t,cursor:n,limit:50});o=o.concat(c.data),n=c.nextCursor,(!c.hasNextPage||a===8)&&(n=null)}catch(c){console.log(c),n=null}a++}while(n!==null);return o},Gd=(i,e)=>{let t=[],n=BigInt(0);for(let o of e)n<i&&!t.includes(o.objectId)&&(t.push(o.objectId),n+=BigInt(o.balance)),o.balance===BigInt(0)&&!t.includes(o.objectId)&&t.push(o.objectId);if(n>=i)return t;throw new Error("Insufficient balance")},Qd=(i,e,t,n)=>{if(i===Xd){let[o]=n.splitCoins(n.gas,[n.pure.u64(t)]);return o}else{let o=Gd(t,e);o.length>1&&n.mergeCoins(n.object(o[0]),o.slice(1).map(c=>n.object(c)));let[a]=n.splitCoins(n.object(o[0]),[n.pure.u64(t)]);return a}};async function lp(i,e,t,n,o){let a=await zd({suiClient:i.rpcClient,address:e,type:t});return Qd(Me(t),a.map(l=>({balance:BigInt(l.balance),objectId:l.coinObjectId})),n,o)}function E(i,e,t){let n=i.toTwos(t).shrn(e);return n.imaskn(t-e+1),n.fromTwos(t-e)}function Jd(i){let e;return i&1?e=new R.default("79232123823359799118286999567"):e=new R.default("79228162514264337593543950336"),i&2&&(e=E(e.mul(new R.default("79236085330515764027303304731")),96,256)),i&4&&(e=E(e.mul(new R.default("79244008939048815603706035061")),96,256)),i&8&&(e=E(e.mul(new R.default("79259858533276714757314932305")),96,256)),i&16&&(e=E(e.mul(new R.default("79291567232598584799939703904")),96,256)),i&32&&(e=E(e.mul(new R.default("79355022692464371645785046466")),96,256)),i&64&&(e=E(e.mul(new R.default("79482085999252804386437311141")),96,256)),i&128&&(e=E(e.mul(new R.default("79736823300114093921829183326")),96,256)),i&256&&(e=E(e.mul(new R.default("80248749790819932309965073892")),96,256)),i&512&&(e=E(e.mul(new R.default("81282483887344747381513967011")),96,256)),i&1024&&(e=E(e.mul(new R.default("83390072131320151908154831281")),96,256)),i&2048&&(e=E(e.mul(new R.default("87770609709833776024991924138")),96,256)),i&4096&&(e=E(e.mul(new R.default("97234110755111693312479820773")),96,256)),i&8192&&(e=E(e.mul(new R.default("119332217159966728226237229890")),96,256)),i&16384&&(e=E(e.mul(new R.default("179736315981702064433883588727")),96,256)),i&32768&&(e=E(e.mul(new R.default("407748233172238350107850275304")),96,256)),i&65536&&(e=E(e.mul(new R.default("2098478828474011932436660412517")),96,256)),i&131072&&(e=E(e.mul(new R.default("55581415166113811149459800483533")),96,256)),i&262144&&(e=E(e.mul(new R.default("38992368544603139932233054999993551")),96,256)),E(e,32,256)}function Yd(i){let e=Math.abs(i),t;return e&1?t=new R.default("18445821805675392311"):t=new R.default("18446744073709551616"),e&2&&(t=E(t.mul(new R.default("18444899583751176498")),64,256)),e&4&&(t=E(t.mul(new R.default("18443055278223354162")),64,256)),e&8&&(t=E(t.mul(new R.default("18439367220385604838")),64,256)),e&16&&(t=E(t.mul(new R.default("18431993317065449817")),64,256)),e&32&&(t=E(t.mul(new R.default("18417254355718160513")),64,256)),e&64&&(t=E(t.mul(new R.default("18387811781193591352")),64,256)),e&128&&(t=E(t.mul(new R.default("18329067761203520168")),64,256)),e&256&&(t=E(t.mul(new R.default("18212142134806087854")),64,256)),e&512&&(t=E(t.mul(new R.default("17980523815641551639")),64,256)),e&1024&&(t=E(t.mul(new R.default("17526086738831147013")),64,256)),e&2048&&(t=E(t.mul(new R.default("16651378430235024244")),64,256)),e&4096&&(t=E(t.mul(new R.default("15030750278693429944")),64,256)),e&8192&&(t=E(t.mul(new R.default("12247334978882834399")),64,256)),e&16384&&(t=E(t.mul(new R.default("8131365268884726200")),64,256)),e&32768&&(t=E(t.mul(new R.default("3584323654723342297")),64,256)),e&65536&&(t=E(t.mul(new R.default("696457651847595233")),64,256)),e&131072&&(t=E(t.mul(new R.default("26294789957452057")),64,256)),e&262144&&(t=E(t.mul(new R.default("37481735321082")),64,256)),t}var up=(i,e,t)=>{let n=(0,Ue.convertI32ToSigned)(t?i+i%(e??1):i-i%(e??1));return n>0?new R.default(Jd(n)):new R.default(Yd(n))};function mp(i,e){if(!/^(\d+)(\.\d+)?$/.test(i))return BigInt(0);let[t,n=""]=i.split("."),o=(n+"0".repeat(e)).slice(0,e),c=(t+o).replace(/^0+/,"")||"0";return BigInt(c)}async function Oe({address:i,coinType:e,coinAmount:t,coinDecimals:n,tx:o,mmt:a}){let c=mp(t,n),l;return Number(t)?l=await lp(a,i,Me(e),c,o):[l]=o.moveCall({target:"0x2::coin::zero",typeArguments:[e],arguments:[]}),l}function pp({mmt:i,tx:e,poolModel:t,selectedLowTick:n,selectedHighTick:o}){let a=up((0,Ue.convertI32ToSigned)(n),t.tickSpacing),c=up((0,Ue.convertI32ToSigned)(o),t.tickSpacing);return i.Position.openPosition(e,t,a.toString(),c.toString())}var Zd=(i,e)=>{let n=1e4-Math.floor(e*100);return i*BigInt(n)/BigInt(1e4)};function pr(i,e,t){let n=mp(i,e);return Number(i)===0?BigInt(0):Zd(n,t)}async function dr({poolId:i,currentSqrtPrice:e,tokenX:t,tokenY:n,slippagePercentage:o,isTokenX:a,suiClient:c}){let d=(await c.getObject({id:i,options:{showContent:!0}}))?.data?.content?.fields?.sqrt_price??e,b=Ue.TickMath.sqrtPriceX64ToPrice(new R.default(d?.toString()),t.decimals,n.decimals),w=a?(100-o)/100:(100+o)/100,I=Ue.TickMath.priceToSqrtPriceX64(b.mul(w),t.decimals,n.decimals);return BigInt(I.toString())}var dp=async(i,e,t,n,o,a,c,l,d,b)=>{let w=await Oe({mmt:i,address:t,coinType:a.tokenX.coinType,coinAmount:n,coinDecimals:a.tokenX.decimals,tx:e}),I=await Oe({mmt:i,address:t,coinType:a.tokenY.coinType,coinAmount:o,coinDecimals:a.tokenY.decimals,tx:e}),k={objectId:c,tokenXType:a.tokenXType,tokenYType:a.tokenYType,tickSpacing:a.tickSpacing},v=pp({mmt:i,tx:e,poolModel:k,selectedLowTick:l,selectedHighTick:d}),D=pr(n,a.tokenX.decimals,b),P=pr(o,a.tokenY.decimals,b);i.Pool.addLiquidity(e,k,v,w,I,D,P,t),e.transferObjects([v],e.pure.address(t))},fp=async(i,e,t,n,o,a,c,l,d,b,w)=>{try{let I=await Oe({mmt:i,address:n,coinType:a?c.tokenX.coinType:c.tokenY.coinType,coinAmount:o,coinDecimals:a?c.tokenX.decimals:c.tokenY.decimals,tx:e}),k={objectId:c.poolId,tokenXType:Me(c.tokenX.coinType),tokenYType:Me(c.tokenY.coinType),tickSpacing:c.tickSpacing},v=pp({mmt:i,tx:e,poolModel:k,selectedLowTick:l,selectedHighTick:d}),D=await dr({suiClient:t,poolId:c.poolId,currentSqrtPrice:c.currentSqrtPrice,tokenX:c.tokenX,tokenY:c.tokenY,slippagePercentage:b,isTokenX:a});await i.Pool.addLiquiditySingleSidedV2({txb:e,pool:k,position:v,inputCoin:I,isXtoY:a,limitSqrtPrice:D,slippagePercentage:w,transferToAddress:n,useMvr:!0}),e.transferObjects([v],e.pure.address(n))}catch(I){console.error(I)}},hp=async(i,e,t,n,o,a,c,l)=>{let d=await Oe({mmt:i,address:t,coinType:a.tokenX.coinType,coinAmount:n,coinDecimals:a.tokenX.decimals,tx:e}),b=await Oe({mmt:i,address:t,coinType:a.tokenY.coinType,coinAmount:o,coinDecimals:a.tokenY.decimals,tx:e}),w={objectId:a.poolId,tokenXType:a.tokenXType,tokenYType:a.tokenYType,tickSpacing:a.tickSpacing},I=pr(n,a.tokenX.decimals,l),k=pr(o,a.tokenY.decimals,l);i.Pool.addLiquidity(e,w,c,d,b,I,k,t)},gp=async(i,e,t,n,o,a,c,l,d)=>{try{let b=await Oe({mmt:i,address:t,coinType:o?a.tokenX.coinType:a.tokenY.coinType,coinAmount:n,coinDecimals:o?a.tokenX.decimals:a.tokenY.decimals,tx:e}),w={objectId:a.poolId,tokenXType:a.tokenX.coinType,tokenYType:a.tokenY.coinType,tickSpacing:a.tickSpacing},I=await dr({suiClient:i.rpcClient,poolId:a.poolId,currentSqrtPrice:a.currentSqrtPrice,tokenX:a.tokenX,tokenY:a.tokenY,slippagePercentage:l,isTokenX:o});await i.Pool.addLiquiditySingleSidedV2({txb:e,pool:w,position:c,inputCoin:b,isXtoY:o,limitSqrtPrice:I,slippagePercentage:d,transferToAddress:t})}catch(b){throw console.error(b),b}};var fr=class i extends C{constructor(t){super(t);this.data=t}txType;txSubType;async build(){let t=yp.MmtSDK.NEW({network:"mainnet"}),{params:n}=this.data,{address:o,amountA:a,amountB:c,pool:l,selectedLowTick:d,selectedHighTick:b,slippage:w}=n,I=new bp.Transaction;return await dp(t,I,o,a,c,l,l.poolId,d,b,w),I}static fromData(t){return new i(t)}};var Sp=require("@mmt-finance/clmm-sdk"),Tp=require("@mysten/sui/transactions");var hr=class i extends C{constructor(t){super(t);this.data=t}txType;txSubType;async build(){let t=Sp.MmtSDK.NEW({network:"mainnet"}),{params:n}=this.data,{address:o,amount:a,isTokenX:c,pool:l,selectedLowTick:d,selectedHighTick:b,swapSlippage:w,addLiquiditySlippage:I}=n,k=new Tp.Transaction;return await fp(t,k,t.rpcClient,o,a,c,l,d,b,w,I),k}static fromData(t){return new i(t)}};var wp=require("@mmt-finance/clmm-sdk"),Ip=require("@mysten/sui/transactions");var un=(i,e,t,n,o)=>{let a={objectId:n.poolId,tokenXType:n.tokenXType,tokenYType:n.tokenYType};n?.rewarders&&n?.rewarders.length>0&&i.Pool.collectAllRewards(o,a,n.rewarders.map(c=>({coin_type:c.coinType,flow_rate:c.flowRate,reward_amount:c.rewardAmount,rewards_allocated:c.rewardsAllocated,hasEnded:c.hasEnded})),t.objectId,e),i.Pool.collectFee(o,{objectId:n.poolId,tokenXType:n.tokenXType,tokenYType:n.tokenYType,isStable:n.isStable,tickSpacing:n.tickSpacing},t.objectId,e)};var gr=class i extends C{constructor(t){super(t);this.data=t}txType;txSubType;async build(){let t=wp.MmtSDK.NEW({network:"mainnet"}),{params:n}=this.data,{address:o,positions:a,pools:c}=n,l=new Ip.Transaction;for(let d of a){let b=c.find(w=>w.poolId===d.poolId);b&&un(t,o,d,b,l)}return l}static fromData(t){return new i(t)}};var Cp=require("@mmt-finance/clmm-sdk"),kp=require("@mysten/sui/transactions");var yr=class i extends C{constructor(t){super(t);this.data=t}txType;txSubType;async build(){let t=Cp.MmtSDK.NEW({network:"mainnet"}),{params:n}=this.data,{address:o,position:a,pool:c}=n,l=new kp.Transaction;return un(t,o,a,c,l),l}static fromData(t){return new i(t)}};var vp=require("@mmt-finance/clmm-sdk"),Dp=require("@mysten/sui/transactions");var br=class i extends C{constructor(t){super(t);this.data=t}txType;txSubType;async build(){let t=vp.MmtSDK.NEW({network:"mainnet"}),{params:n}=this.data,{address:o,amountA:a,amountB:c,pool:l,positionObjectId:d,slippage:b}=n,w=new Dp.Transaction;return await hp(t,w,o,a,c,l,d,b),w}static fromData(t){return new i(t)}};var xp=require("@mmt-finance/clmm-sdk"),Ap=require("@mysten/sui/transactions");var Sr=class i extends C{constructor(t){super(t);this.data=t}txType;txSubType;async build(){let t=xp.MmtSDK.NEW({network:"mainnet"}),{params:n}=this.data,{address:o,amount:a,isTokenX:c,pool:l,positionObjectId:d,swapSlippage:b,addLiquiditySlippage:w}=n,I=new Ap.Transaction;return await gp(t,I,o,a,c,l,d,b,w),I}static fromData(t){return new i(t)}};var Mp=require("@mmt-finance/clmm-sdk"),Op=require("@mysten/sui/transactions"),Pp=Ut(require("bignumber.js"));var Tr=class i extends C{constructor(t){super(t);this.data=t}txType;txSubType;async build(){let t=Mp.MmtSDK.NEW({network:"mainnet"}),{params:n}=this.data,{pool:o,position:a,address:c,withdrawPercentage:l}=n,d=new Op.Transaction,b=o.tokenX.coinType,w=o.tokenY.coinType,I={objectId:o.poolId,tokenXType:b,tokenYType:w},k=BigInt(l===100?a.liquidity:new Pp.default(a.liquidity).multipliedBy(l/100).toFixed(0));return t.Pool.removeLiquidity(d,I,a.objectId,k,BigInt(0),BigInt(0),c),un(t,c,a,o,d),l===100&&t.Position.closePosition(d,a.objectId),d}static fromData(t){return new i(t)}};var js=require("@mysten/sui/transactions"),Us=require("@suilend/springsui-sdk"),Ls={id:"0x0431232199873db77a92aa645cd43521437e9cc5c6fff07fd03edb88afe0b25a",type:"0x2b6602099970374cf58a2a1b9d96f005fccceb81e92eb059873baf420eb6c717::x_sui::X_SUI",weightHookId:"0x9e35c13dbb0bc437e8ad5a95ec463622f58763e060552ae8d100db77f4904601"},Rp=async(i,e,t)=>{let n=await Us.LstClient.initialize(i,Ls),o=new js.Transaction,[a]=o.splitCoins(o.gas,[BigInt(t)]),c=n.mint(o,a);return o.transferObjects([c],e),o},Bp=async(i,e,t)=>{let n=await Us.LstClient.initialize(i,Ls),o=await i.getCoins({owner:e,coinType:Ls.type,limit:1e3});if(o.data.length===0)throw new Error("No lst coins found");let a=new js.Transaction,c=o.data[0];o.data.length>1&&a.mergeCoins(c.coinObjectId,o.data.slice(1).map(b=>b.coinObjectId));let[l]=a.splitCoins(c.coinObjectId,[BigInt(t)]),d=n.redeem(a,l);return a.transferObjects([d],e),a};var wr=class i extends C{constructor(t){super(t);this.data=t}txType;txSubType;async build(t){let{params:n}=this.data,{address:o,amount:a}=n;return await Rp(t.suiClient,o,a)}static fromData(t){return new i(t)}};var Wp=require("@mmt-finance/clmm-sdk"),_p=require("@mysten/sui/transactions");var Ep=require("@mmt-finance/clmm-sdk/dist/utils/poolUtils");var Np=async(i,e,t,n,o,a,c)=>{let l=await Oe({mmt:i,tx:a,address:o,coinType:t.coinType,coinAmount:n,coinDecimals:t.decimals}),d=a.moveCall({target:"0x2::coin::value",typeArguments:[t.coinType],arguments:[l]}),b=t.coinType;for(let w=0;w<e.length;w+=1){let{poolId:I,tokenX:k,tokenY:v,isStable:D,currentSqrtPrice:P}=e[w],{id:K,isReverse:H}=Ep.mappedMmtV3Pool[I]||{id:I,isReverse:!1},Et=Me(k.coinType)===Me(b);Et=H?!Et:Et;let Wt=H?v.coinType:k.coinType,Ot=H?k.coinType:v.coinType,mn=await dr({poolId:K,tokenX:k,tokenY:v,slippagePercentage:c,isTokenX:Et,suiClient:i.rpcClient,currentSqrtPrice:P}),_t=i.Pool.swap(a,{objectId:K,tokenXType:Wt,tokenYType:Ot,isStable:D},d,l,Et,void 0,mn,!1);a.transferObjects([l],a.pure.address(o)),l=_t,b=Et?Ot:Wt,d=a.moveCall({target:"0x2::coin::value",typeArguments:[b],arguments:[l]})}a.transferObjects([l],a.pure.address(o))};var Ir=class i extends C{constructor(t){super(t);this.data=t}txType;txSubType;async build(){let t=Wp.MmtSDK.NEW({network:"mainnet"}),{params:n}=this.data,{route:o,tokenIn:a,amountIn:c,address:l,slippage:d}=n,b=new _p.Transaction;return await Np(t,o,a,c,l,b,d),b}static fromData(t){return new i(t)}};var Cr=class i extends C{constructor(t){super(t);this.data=t}txType;txSubType;async build(t){let{params:n}=this.data,{address:o,amount:a}=n;return await Bp(t.suiClient,o,a)}static fromData(t){return new i(t)}};var kr=class{application="mmt-dex";supportSDK="@mysten/sui";async deserialize(e){let{appContext:t}=e;return{txType:Lp.TransactionType.Other,txSubType:t.action,intentionData:t}}async build(e){let t;switch(e.txSubType){case"Swap":t=Ir.fromData(e.intentionData);break;case"AddLiquidity":t=fr.fromData(e.intentionData);break;case"AddLiquiditySingleSide":t=hr.fromData(e.intentionData);break;case"ClaimRewards":t=yr.fromData(e.intentionData);break;case"ClaimAllRewards":t=gr.fromData(e.intentionData);break;case"RemoveLiquidity":t=Tr.fromData(e.intentionData);break;case"StakeXSui":t=wr.fromData(e.intentionData);break;case"UnstakeXSui":t=Cr.fromData(e.intentionData);break;case"ManageLiquidity":t=br.fromData(e.intentionData);break;case"ManageLiquiditySingleSide":t=Sr.fromData(e.intentionData);break;default:throw new Error("not implemented")}return t.build({suiClient:e.suiClient})}};var tf=Ma.fromHelpers([new fa,new ka,new ma,new va,new Ko,new Qi,new kr,new ui,new nr,new go,new Ti,new Mi,new Qn,new mr,new Bi]);
1
+ "use strict";var jp=Object.create;var Kn=Object.defineProperty;var Up=Object.getOwnPropertyDescriptor;var qp=Object.getOwnPropertyNames;var Fp=Object.getPrototypeOf,Kp=Object.prototype.hasOwnProperty;var $p=(i,e)=>()=>(e||i((e={exports:{}}).exports,e),e.exports),Vr=(i,e)=>{for(var t in e)Kn(i,t,{get:e[t],enumerable:!0})},rc=(i,e,t,n)=>{if(e&&typeof e=="object"||typeof e=="function")for(let o of qp(e))!Kp.call(i,o)&&o!==t&&Kn(i,o,{get:()=>e[o],enumerable:!(n=Up(e,o))||n.enumerable});return i};var Ut=(i,e,t)=>(t=i!=null?jp(Fp(i)):{},rc(e||!i||!i.__esModule?Kn(t,"default",{value:i,enumerable:!0}):t,i)),Vp=i=>rc(Kn({},"__esModule",{value:!0}),i);var cp=$p((sp,_s)=>{"use strict";(function(i,e){"use strict";function t(y,r){if(!y)throw new Error(r||"Assertion failed")}function n(y,r){y.super_=r;var u=function(){};u.prototype=r.prototype,y.prototype=new u,y.prototype.constructor=y}function o(y,r,u){if(o.isBN(y))return y;this.negative=0,this.words=null,this.length=0,this.red=null,y!==null&&((r==="le"||r==="be")&&(u=r,r=10),this._init(y||0,r||10,u||"be"))}typeof i=="object"?i.exports=o:e.BN=o,o.BN=o,o.wordSize=26;var a;try{typeof window<"u"&&typeof window.Buffer<"u"?a=window.Buffer:a=require("buffer").Buffer}catch{}o.isBN=function(r){return r instanceof o?!0:r!==null&&typeof r=="object"&&r.constructor.wordSize===o.wordSize&&Array.isArray(r.words)},o.max=function(r,u){return r.cmp(u)>0?r:u},o.min=function(r,u){return r.cmp(u)<0?r:u},o.prototype._init=function(r,u,m){if(typeof r=="number")return this._initNumber(r,u,m);if(typeof r=="object")return this._initArray(r,u,m);u==="hex"&&(u=16),t(u===(u|0)&&u>=2&&u<=36),r=r.toString().replace(/\s+/g,"");var p=0;r[0]==="-"&&(p++,this.negative=1),p<r.length&&(u===16?this._parseHex(r,p,m):(this._parseBase(r,u,p),m==="le"&&this._initArray(this.toArray(),u,m)))},o.prototype._initNumber=function(r,u,m){r<0&&(this.negative=1,r=-r),r<67108864?(this.words=[r&67108863],this.length=1):r<4503599627370496?(this.words=[r&67108863,r/67108864&67108863],this.length=2):(t(r<9007199254740992),this.words=[r&67108863,r/67108864&67108863,1],this.length=3),m==="le"&&this._initArray(this.toArray(),u,m)},o.prototype._initArray=function(r,u,m){if(t(typeof r.length=="number"),r.length<=0)return this.words=[0],this.length=1,this;this.length=Math.ceil(r.length/3),this.words=new Array(this.length);for(var p=0;p<this.length;p++)this.words[p]=0;var h,S,T=0;if(m==="be")for(p=r.length-1,h=0;p>=0;p-=3)S=r[p]|r[p-1]<<8|r[p-2]<<16,this.words[h]|=S<<T&67108863,this.words[h+1]=S>>>26-T&67108863,T+=24,T>=26&&(T-=26,h++);else if(m==="le")for(p=0,h=0;p<r.length;p+=3)S=r[p]|r[p+1]<<8|r[p+2]<<16,this.words[h]|=S<<T&67108863,this.words[h+1]=S>>>26-T&67108863,T+=24,T>=26&&(T-=26,h++);return this._strip()};function c(y,r){var u=y.charCodeAt(r);if(u>=48&&u<=57)return u-48;if(u>=65&&u<=70)return u-55;if(u>=97&&u<=102)return u-87;t(!1,"Invalid character in "+y)}function l(y,r,u){var m=c(y,u);return u-1>=r&&(m|=c(y,u-1)<<4),m}o.prototype._parseHex=function(r,u,m){this.length=Math.ceil((r.length-u)/6),this.words=new Array(this.length);for(var p=0;p<this.length;p++)this.words[p]=0;var h=0,S=0,T;if(m==="be")for(p=r.length-1;p>=u;p-=2)T=l(r,u,p)<<h,this.words[S]|=T&67108863,h>=18?(h-=18,S+=1,this.words[S]|=T>>>26):h+=8;else{var f=r.length-u;for(p=f%2===0?u+1:u;p<r.length;p+=2)T=l(r,u,p)<<h,this.words[S]|=T&67108863,h>=18?(h-=18,S+=1,this.words[S]|=T>>>26):h+=8}this._strip()};function d(y,r,u,m){for(var p=0,h=0,S=Math.min(y.length,u),T=r;T<S;T++){var f=y.charCodeAt(T)-48;p*=m,f>=49?h=f-49+10:f>=17?h=f-17+10:h=f,t(f>=0&&h<m,"Invalid character"),p+=h}return p}o.prototype._parseBase=function(r,u,m){this.words=[0],this.length=1;for(var p=0,h=1;h<=67108863;h*=u)p++;p--,h=h/u|0;for(var S=r.length-m,T=S%p,f=Math.min(S,S-T)+m,s=0,g=m;g<f;g+=p)s=d(r,g,g+p,u),this.imuln(h),this.words[0]+s<67108864?this.words[0]+=s:this._iaddn(s);if(T!==0){var D=1;for(s=d(r,g,r.length,u),g=0;g<T;g++)D*=u;this.imuln(D),this.words[0]+s<67108864?this.words[0]+=s:this._iaddn(s)}this._strip()},o.prototype.copy=function(r){r.words=new Array(this.length);for(var u=0;u<this.length;u++)r.words[u]=this.words[u];r.length=this.length,r.negative=this.negative,r.red=this.red};function b(y,r){y.words=r.words,y.length=r.length,y.negative=r.negative,y.red=r.red}if(o.prototype._move=function(r){b(r,this)},o.prototype.clone=function(){var r=new o(null);return this.copy(r),r},o.prototype._expand=function(r){for(;this.length<r;)this.words[this.length++]=0;return this},o.prototype._strip=function(){for(;this.length>1&&this.words[this.length-1]===0;)this.length--;return this._normSign()},o.prototype._normSign=function(){return this.length===1&&this.words[0]===0&&(this.negative=0),this},typeof Symbol<"u"&&typeof Symbol.for=="function")try{o.prototype[Symbol.for("nodejs.util.inspect.custom")]=I}catch{o.prototype.inspect=I}else o.prototype.inspect=I;function I(){return(this.red?"<BN-R: ":"<BN: ")+this.toString(16)+">"}var w=["","0","00","000","0000","00000","000000","0000000","00000000","000000000","0000000000","00000000000","000000000000","0000000000000","00000000000000","000000000000000","0000000000000000","00000000000000000","000000000000000000","0000000000000000000","00000000000000000000","000000000000000000000","0000000000000000000000","00000000000000000000000","000000000000000000000000","0000000000000000000000000"],k=[0,0,25,16,12,11,10,9,8,8,7,7,7,7,6,6,6,6,6,6,6,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5],x=[0,0,33554432,43046721,16777216,48828125,60466176,40353607,16777216,43046721,1e7,19487171,35831808,62748517,7529536,11390625,16777216,24137569,34012224,47045881,64e6,4084101,5153632,6436343,7962624,9765625,11881376,14348907,17210368,20511149,243e5,28629151,33554432,39135393,45435424,52521875,60466176];o.prototype.toString=function(r,u){r=r||10,u=u|0||1;var m;if(r===16||r==="hex"){m="";for(var p=0,h=0,S=0;S<this.length;S++){var T=this.words[S],f=((T<<p|h)&16777215).toString(16);h=T>>>24-p&16777215,p+=2,p>=26&&(p-=26,S--),h!==0||S!==this.length-1?m=w[6-f.length]+f+m:m=f+m}for(h!==0&&(m=h.toString(16)+m);m.length%u!==0;)m="0"+m;return this.negative!==0&&(m="-"+m),m}if(r===(r|0)&&r>=2&&r<=36){var s=k[r],g=x[r];m="";var D=this.clone();for(D.negative=0;!D.isZero();){var M=D.modrn(g).toString(r);D=D.idivn(g),D.isZero()?m=M+m:m=w[s-M.length]+M+m}for(this.isZero()&&(m="0"+m);m.length%u!==0;)m="0"+m;return this.negative!==0&&(m="-"+m),m}t(!1,"Base should be between 2 and 36")},o.prototype.toNumber=function(){var r=this.words[0];return this.length===2?r+=this.words[1]*67108864:this.length===3&&this.words[2]===1?r+=4503599627370496+this.words[1]*67108864:this.length>2&&t(!1,"Number can only safely store up to 53 bits"),this.negative!==0?-r:r},o.prototype.toJSON=function(){return this.toString(16,2)},a&&(o.prototype.toBuffer=function(r,u){return this.toArrayLike(a,r,u)}),o.prototype.toArray=function(r,u){return this.toArrayLike(Array,r,u)};var v=function(r,u){return r.allocUnsafe?r.allocUnsafe(u):new r(u)};o.prototype.toArrayLike=function(r,u,m){this._strip();var p=this.byteLength(),h=m||Math.max(1,p);t(p<=h,"byte array longer than desired length"),t(h>0,"Requested array length <= 0");var S=v(r,h),T=u==="le"?"LE":"BE";return this["_toArrayLike"+T](S,p),S},o.prototype._toArrayLikeLE=function(r,u){for(var m=0,p=0,h=0,S=0;h<this.length;h++){var T=this.words[h]<<S|p;r[m++]=T&255,m<r.length&&(r[m++]=T>>8&255),m<r.length&&(r[m++]=T>>16&255),S===6?(m<r.length&&(r[m++]=T>>24&255),p=0,S=0):(p=T>>>24,S+=2)}if(m<r.length)for(r[m++]=p;m<r.length;)r[m++]=0},o.prototype._toArrayLikeBE=function(r,u){for(var m=r.length-1,p=0,h=0,S=0;h<this.length;h++){var T=this.words[h]<<S|p;r[m--]=T&255,m>=0&&(r[m--]=T>>8&255),m>=0&&(r[m--]=T>>16&255),S===6?(m>=0&&(r[m--]=T>>24&255),p=0,S=0):(p=T>>>24,S+=2)}if(m>=0)for(r[m--]=p;m>=0;)r[m--]=0},Math.clz32?o.prototype._countBits=function(r){return 32-Math.clz32(r)}:o.prototype._countBits=function(r){var u=r,m=0;return u>=4096&&(m+=13,u>>>=13),u>=64&&(m+=7,u>>>=7),u>=8&&(m+=4,u>>>=4),u>=2&&(m+=2,u>>>=2),m+u},o.prototype._zeroBits=function(r){if(r===0)return 26;var u=r,m=0;return u&8191||(m+=13,u>>>=13),u&127||(m+=7,u>>>=7),u&15||(m+=4,u>>>=4),u&3||(m+=2,u>>>=2),u&1||m++,m},o.prototype.bitLength=function(){var r=this.words[this.length-1],u=this._countBits(r);return(this.length-1)*26+u};function P(y){for(var r=new Array(y.bitLength()),u=0;u<r.length;u++){var m=u/26|0,p=u%26;r[u]=y.words[m]>>>p&1}return r}o.prototype.zeroBits=function(){if(this.isZero())return 0;for(var r=0,u=0;u<this.length;u++){var m=this._zeroBits(this.words[u]);if(r+=m,m!==26)break}return r},o.prototype.byteLength=function(){return Math.ceil(this.bitLength()/8)},o.prototype.toTwos=function(r){return this.negative!==0?this.abs().inotn(r).iaddn(1):this.clone()},o.prototype.fromTwos=function(r){return this.testn(r-1)?this.notn(r).iaddn(1).ineg():this.clone()},o.prototype.isNeg=function(){return this.negative!==0},o.prototype.neg=function(){return this.clone().ineg()},o.prototype.ineg=function(){return this.isZero()||(this.negative^=1),this},o.prototype.iuor=function(r){for(;this.length<r.length;)this.words[this.length++]=0;for(var u=0;u<r.length;u++)this.words[u]=this.words[u]|r.words[u];return this._strip()},o.prototype.ior=function(r){return t((this.negative|r.negative)===0),this.iuor(r)},o.prototype.or=function(r){return this.length>r.length?this.clone().ior(r):r.clone().ior(this)},o.prototype.uor=function(r){return this.length>r.length?this.clone().iuor(r):r.clone().iuor(this)},o.prototype.iuand=function(r){var u;this.length>r.length?u=r:u=this;for(var m=0;m<u.length;m++)this.words[m]=this.words[m]&r.words[m];return this.length=u.length,this._strip()},o.prototype.iand=function(r){return t((this.negative|r.negative)===0),this.iuand(r)},o.prototype.and=function(r){return this.length>r.length?this.clone().iand(r):r.clone().iand(this)},o.prototype.uand=function(r){return this.length>r.length?this.clone().iuand(r):r.clone().iuand(this)},o.prototype.iuxor=function(r){var u,m;this.length>r.length?(u=this,m=r):(u=r,m=this);for(var p=0;p<m.length;p++)this.words[p]=u.words[p]^m.words[p];if(this!==u)for(;p<u.length;p++)this.words[p]=u.words[p];return this.length=u.length,this._strip()},o.prototype.ixor=function(r){return t((this.negative|r.negative)===0),this.iuxor(r)},o.prototype.xor=function(r){return this.length>r.length?this.clone().ixor(r):r.clone().ixor(this)},o.prototype.uxor=function(r){return this.length>r.length?this.clone().iuxor(r):r.clone().iuxor(this)},o.prototype.inotn=function(r){t(typeof r=="number"&&r>=0);var u=Math.ceil(r/26)|0,m=r%26;this._expand(u),m>0&&u--;for(var p=0;p<u;p++)this.words[p]=~this.words[p]&67108863;return m>0&&(this.words[p]=~this.words[p]&67108863>>26-m),this._strip()},o.prototype.notn=function(r){return this.clone().inotn(r)},o.prototype.setn=function(r,u){t(typeof r=="number"&&r>=0);var m=r/26|0,p=r%26;return this._expand(m+1),u?this.words[m]=this.words[m]|1<<p:this.words[m]=this.words[m]&~(1<<p),this._strip()},o.prototype.iadd=function(r){var u;if(this.negative!==0&&r.negative===0)return this.negative=0,u=this.isub(r),this.negative^=1,this._normSign();if(this.negative===0&&r.negative!==0)return r.negative=0,u=this.isub(r),r.negative=1,u._normSign();var m,p;this.length>r.length?(m=this,p=r):(m=r,p=this);for(var h=0,S=0;S<p.length;S++)u=(m.words[S]|0)+(p.words[S]|0)+h,this.words[S]=u&67108863,h=u>>>26;for(;h!==0&&S<m.length;S++)u=(m.words[S]|0)+h,this.words[S]=u&67108863,h=u>>>26;if(this.length=m.length,h!==0)this.words[this.length]=h,this.length++;else if(m!==this)for(;S<m.length;S++)this.words[S]=m.words[S];return this},o.prototype.add=function(r){var u;return r.negative!==0&&this.negative===0?(r.negative=0,u=this.sub(r),r.negative^=1,u):r.negative===0&&this.negative!==0?(this.negative=0,u=r.sub(this),this.negative=1,u):this.length>r.length?this.clone().iadd(r):r.clone().iadd(this)},o.prototype.isub=function(r){if(r.negative!==0){r.negative=0;var u=this.iadd(r);return r.negative=1,u._normSign()}else if(this.negative!==0)return this.negative=0,this.iadd(r),this.negative=1,this._normSign();var m=this.cmp(r);if(m===0)return this.negative=0,this.length=1,this.words[0]=0,this;var p,h;m>0?(p=this,h=r):(p=r,h=this);for(var S=0,T=0;T<h.length;T++)u=(p.words[T]|0)-(h.words[T]|0)+S,S=u>>26,this.words[T]=u&67108863;for(;S!==0&&T<p.length;T++)u=(p.words[T]|0)+S,S=u>>26,this.words[T]=u&67108863;if(S===0&&T<p.length&&p!==this)for(;T<p.length;T++)this.words[T]=p.words[T];return this.length=Math.max(this.length,T),p!==this&&(this.negative=1),this._strip()},o.prototype.sub=function(r){return this.clone().isub(r)};function K(y,r,u){u.negative=r.negative^y.negative;var m=y.length+r.length|0;u.length=m,m=m-1|0;var p=y.words[0]|0,h=r.words[0]|0,S=p*h,T=S&67108863,f=S/67108864|0;u.words[0]=T;for(var s=1;s<m;s++){for(var g=f>>>26,D=f&67108863,M=Math.min(s,r.length-1),O=Math.max(0,s-y.length+1);O<=M;O++){var B=s-O|0;p=y.words[B]|0,h=r.words[O]|0,S=p*h+D,g+=S/67108864|0,D=S&67108863}u.words[s]=D|0,f=g|0}return f!==0?u.words[s]=f|0:u.length--,u._strip()}var H=function(r,u,m){var p=r.words,h=u.words,S=m.words,T=0,f,s,g,D=p[0]|0,M=D&8191,O=D>>>13,B=p[1]|0,W=B&8191,j=B>>>13,re=p[2]|0,U=re&8191,q=re>>>13,Ks=p[3]|0,X=Ks&8191,z=Ks>>>13,$s=p[4]|0,G=$s&8191,Q=$s>>>13,Vs=p[5]|0,J=Vs&8191,Y=Vs>>>13,Hs=p[6]|0,Z=Hs&8191,tt=Hs>>>13,Xs=p[7]|0,et=Xs&8191,nt=Xs>>>13,zs=p[8]|0,ot=zs&8191,at=zs>>>13,Gs=p[9]|0,it=Gs&8191,rt=Gs>>>13,Qs=h[0]|0,st=Qs&8191,ct=Qs>>>13,Js=h[1]|0,lt=Js&8191,ut=Js>>>13,Ys=h[2]|0,mt=Ys&8191,pt=Ys>>>13,Zs=h[3]|0,dt=Zs&8191,ft=Zs>>>13,tc=h[4]|0,ht=tc&8191,gt=tc>>>13,ec=h[5]|0,yt=ec&8191,bt=ec>>>13,nc=h[6]|0,St=nc&8191,Tt=nc>>>13,oc=h[7]|0,It=oc&8191,wt=oc>>>13,ac=h[8]|0,Ct=ac&8191,kt=ac>>>13,ic=h[9]|0,xt=ic&8191,vt=ic>>>13;m.negative=r.negative^u.negative,m.length=19,f=Math.imul(M,st),s=Math.imul(M,ct),s=s+Math.imul(O,st)|0,g=Math.imul(O,ct);var vr=(T+f|0)+((s&8191)<<13)|0;T=(g+(s>>>13)|0)+(vr>>>26)|0,vr&=67108863,f=Math.imul(W,st),s=Math.imul(W,ct),s=s+Math.imul(j,st)|0,g=Math.imul(j,ct),f=f+Math.imul(M,lt)|0,s=s+Math.imul(M,ut)|0,s=s+Math.imul(O,lt)|0,g=g+Math.imul(O,ut)|0;var Dr=(T+f|0)+((s&8191)<<13)|0;T=(g+(s>>>13)|0)+(Dr>>>26)|0,Dr&=67108863,f=Math.imul(U,st),s=Math.imul(U,ct),s=s+Math.imul(q,st)|0,g=Math.imul(q,ct),f=f+Math.imul(W,lt)|0,s=s+Math.imul(W,ut)|0,s=s+Math.imul(j,lt)|0,g=g+Math.imul(j,ut)|0,f=f+Math.imul(M,mt)|0,s=s+Math.imul(M,pt)|0,s=s+Math.imul(O,mt)|0,g=g+Math.imul(O,pt)|0;var Ar=(T+f|0)+((s&8191)<<13)|0;T=(g+(s>>>13)|0)+(Ar>>>26)|0,Ar&=67108863,f=Math.imul(X,st),s=Math.imul(X,ct),s=s+Math.imul(z,st)|0,g=Math.imul(z,ct),f=f+Math.imul(U,lt)|0,s=s+Math.imul(U,ut)|0,s=s+Math.imul(q,lt)|0,g=g+Math.imul(q,ut)|0,f=f+Math.imul(W,mt)|0,s=s+Math.imul(W,pt)|0,s=s+Math.imul(j,mt)|0,g=g+Math.imul(j,pt)|0,f=f+Math.imul(M,dt)|0,s=s+Math.imul(M,ft)|0,s=s+Math.imul(O,dt)|0,g=g+Math.imul(O,ft)|0;var Mr=(T+f|0)+((s&8191)<<13)|0;T=(g+(s>>>13)|0)+(Mr>>>26)|0,Mr&=67108863,f=Math.imul(G,st),s=Math.imul(G,ct),s=s+Math.imul(Q,st)|0,g=Math.imul(Q,ct),f=f+Math.imul(X,lt)|0,s=s+Math.imul(X,ut)|0,s=s+Math.imul(z,lt)|0,g=g+Math.imul(z,ut)|0,f=f+Math.imul(U,mt)|0,s=s+Math.imul(U,pt)|0,s=s+Math.imul(q,mt)|0,g=g+Math.imul(q,pt)|0,f=f+Math.imul(W,dt)|0,s=s+Math.imul(W,ft)|0,s=s+Math.imul(j,dt)|0,g=g+Math.imul(j,ft)|0,f=f+Math.imul(M,ht)|0,s=s+Math.imul(M,gt)|0,s=s+Math.imul(O,ht)|0,g=g+Math.imul(O,gt)|0;var Or=(T+f|0)+((s&8191)<<13)|0;T=(g+(s>>>13)|0)+(Or>>>26)|0,Or&=67108863,f=Math.imul(J,st),s=Math.imul(J,ct),s=s+Math.imul(Y,st)|0,g=Math.imul(Y,ct),f=f+Math.imul(G,lt)|0,s=s+Math.imul(G,ut)|0,s=s+Math.imul(Q,lt)|0,g=g+Math.imul(Q,ut)|0,f=f+Math.imul(X,mt)|0,s=s+Math.imul(X,pt)|0,s=s+Math.imul(z,mt)|0,g=g+Math.imul(z,pt)|0,f=f+Math.imul(U,dt)|0,s=s+Math.imul(U,ft)|0,s=s+Math.imul(q,dt)|0,g=g+Math.imul(q,ft)|0,f=f+Math.imul(W,ht)|0,s=s+Math.imul(W,gt)|0,s=s+Math.imul(j,ht)|0,g=g+Math.imul(j,gt)|0,f=f+Math.imul(M,yt)|0,s=s+Math.imul(M,bt)|0,s=s+Math.imul(O,yt)|0,g=g+Math.imul(O,bt)|0;var Pr=(T+f|0)+((s&8191)<<13)|0;T=(g+(s>>>13)|0)+(Pr>>>26)|0,Pr&=67108863,f=Math.imul(Z,st),s=Math.imul(Z,ct),s=s+Math.imul(tt,st)|0,g=Math.imul(tt,ct),f=f+Math.imul(J,lt)|0,s=s+Math.imul(J,ut)|0,s=s+Math.imul(Y,lt)|0,g=g+Math.imul(Y,ut)|0,f=f+Math.imul(G,mt)|0,s=s+Math.imul(G,pt)|0,s=s+Math.imul(Q,mt)|0,g=g+Math.imul(Q,pt)|0,f=f+Math.imul(X,dt)|0,s=s+Math.imul(X,ft)|0,s=s+Math.imul(z,dt)|0,g=g+Math.imul(z,ft)|0,f=f+Math.imul(U,ht)|0,s=s+Math.imul(U,gt)|0,s=s+Math.imul(q,ht)|0,g=g+Math.imul(q,gt)|0,f=f+Math.imul(W,yt)|0,s=s+Math.imul(W,bt)|0,s=s+Math.imul(j,yt)|0,g=g+Math.imul(j,bt)|0,f=f+Math.imul(M,St)|0,s=s+Math.imul(M,Tt)|0,s=s+Math.imul(O,St)|0,g=g+Math.imul(O,Tt)|0;var Rr=(T+f|0)+((s&8191)<<13)|0;T=(g+(s>>>13)|0)+(Rr>>>26)|0,Rr&=67108863,f=Math.imul(et,st),s=Math.imul(et,ct),s=s+Math.imul(nt,st)|0,g=Math.imul(nt,ct),f=f+Math.imul(Z,lt)|0,s=s+Math.imul(Z,ut)|0,s=s+Math.imul(tt,lt)|0,g=g+Math.imul(tt,ut)|0,f=f+Math.imul(J,mt)|0,s=s+Math.imul(J,pt)|0,s=s+Math.imul(Y,mt)|0,g=g+Math.imul(Y,pt)|0,f=f+Math.imul(G,dt)|0,s=s+Math.imul(G,ft)|0,s=s+Math.imul(Q,dt)|0,g=g+Math.imul(Q,ft)|0,f=f+Math.imul(X,ht)|0,s=s+Math.imul(X,gt)|0,s=s+Math.imul(z,ht)|0,g=g+Math.imul(z,gt)|0,f=f+Math.imul(U,yt)|0,s=s+Math.imul(U,bt)|0,s=s+Math.imul(q,yt)|0,g=g+Math.imul(q,bt)|0,f=f+Math.imul(W,St)|0,s=s+Math.imul(W,Tt)|0,s=s+Math.imul(j,St)|0,g=g+Math.imul(j,Tt)|0,f=f+Math.imul(M,It)|0,s=s+Math.imul(M,wt)|0,s=s+Math.imul(O,It)|0,g=g+Math.imul(O,wt)|0;var Br=(T+f|0)+((s&8191)<<13)|0;T=(g+(s>>>13)|0)+(Br>>>26)|0,Br&=67108863,f=Math.imul(ot,st),s=Math.imul(ot,ct),s=s+Math.imul(at,st)|0,g=Math.imul(at,ct),f=f+Math.imul(et,lt)|0,s=s+Math.imul(et,ut)|0,s=s+Math.imul(nt,lt)|0,g=g+Math.imul(nt,ut)|0,f=f+Math.imul(Z,mt)|0,s=s+Math.imul(Z,pt)|0,s=s+Math.imul(tt,mt)|0,g=g+Math.imul(tt,pt)|0,f=f+Math.imul(J,dt)|0,s=s+Math.imul(J,ft)|0,s=s+Math.imul(Y,dt)|0,g=g+Math.imul(Y,ft)|0,f=f+Math.imul(G,ht)|0,s=s+Math.imul(G,gt)|0,s=s+Math.imul(Q,ht)|0,g=g+Math.imul(Q,gt)|0,f=f+Math.imul(X,yt)|0,s=s+Math.imul(X,bt)|0,s=s+Math.imul(z,yt)|0,g=g+Math.imul(z,bt)|0,f=f+Math.imul(U,St)|0,s=s+Math.imul(U,Tt)|0,s=s+Math.imul(q,St)|0,g=g+Math.imul(q,Tt)|0,f=f+Math.imul(W,It)|0,s=s+Math.imul(W,wt)|0,s=s+Math.imul(j,It)|0,g=g+Math.imul(j,wt)|0,f=f+Math.imul(M,Ct)|0,s=s+Math.imul(M,kt)|0,s=s+Math.imul(O,Ct)|0,g=g+Math.imul(O,kt)|0;var Er=(T+f|0)+((s&8191)<<13)|0;T=(g+(s>>>13)|0)+(Er>>>26)|0,Er&=67108863,f=Math.imul(it,st),s=Math.imul(it,ct),s=s+Math.imul(rt,st)|0,g=Math.imul(rt,ct),f=f+Math.imul(ot,lt)|0,s=s+Math.imul(ot,ut)|0,s=s+Math.imul(at,lt)|0,g=g+Math.imul(at,ut)|0,f=f+Math.imul(et,mt)|0,s=s+Math.imul(et,pt)|0,s=s+Math.imul(nt,mt)|0,g=g+Math.imul(nt,pt)|0,f=f+Math.imul(Z,dt)|0,s=s+Math.imul(Z,ft)|0,s=s+Math.imul(tt,dt)|0,g=g+Math.imul(tt,ft)|0,f=f+Math.imul(J,ht)|0,s=s+Math.imul(J,gt)|0,s=s+Math.imul(Y,ht)|0,g=g+Math.imul(Y,gt)|0,f=f+Math.imul(G,yt)|0,s=s+Math.imul(G,bt)|0,s=s+Math.imul(Q,yt)|0,g=g+Math.imul(Q,bt)|0,f=f+Math.imul(X,St)|0,s=s+Math.imul(X,Tt)|0,s=s+Math.imul(z,St)|0,g=g+Math.imul(z,Tt)|0,f=f+Math.imul(U,It)|0,s=s+Math.imul(U,wt)|0,s=s+Math.imul(q,It)|0,g=g+Math.imul(q,wt)|0,f=f+Math.imul(W,Ct)|0,s=s+Math.imul(W,kt)|0,s=s+Math.imul(j,Ct)|0,g=g+Math.imul(j,kt)|0,f=f+Math.imul(M,xt)|0,s=s+Math.imul(M,vt)|0,s=s+Math.imul(O,xt)|0,g=g+Math.imul(O,vt)|0;var Nr=(T+f|0)+((s&8191)<<13)|0;T=(g+(s>>>13)|0)+(Nr>>>26)|0,Nr&=67108863,f=Math.imul(it,lt),s=Math.imul(it,ut),s=s+Math.imul(rt,lt)|0,g=Math.imul(rt,ut),f=f+Math.imul(ot,mt)|0,s=s+Math.imul(ot,pt)|0,s=s+Math.imul(at,mt)|0,g=g+Math.imul(at,pt)|0,f=f+Math.imul(et,dt)|0,s=s+Math.imul(et,ft)|0,s=s+Math.imul(nt,dt)|0,g=g+Math.imul(nt,ft)|0,f=f+Math.imul(Z,ht)|0,s=s+Math.imul(Z,gt)|0,s=s+Math.imul(tt,ht)|0,g=g+Math.imul(tt,gt)|0,f=f+Math.imul(J,yt)|0,s=s+Math.imul(J,bt)|0,s=s+Math.imul(Y,yt)|0,g=g+Math.imul(Y,bt)|0,f=f+Math.imul(G,St)|0,s=s+Math.imul(G,Tt)|0,s=s+Math.imul(Q,St)|0,g=g+Math.imul(Q,Tt)|0,f=f+Math.imul(X,It)|0,s=s+Math.imul(X,wt)|0,s=s+Math.imul(z,It)|0,g=g+Math.imul(z,wt)|0,f=f+Math.imul(U,Ct)|0,s=s+Math.imul(U,kt)|0,s=s+Math.imul(q,Ct)|0,g=g+Math.imul(q,kt)|0,f=f+Math.imul(W,xt)|0,s=s+Math.imul(W,vt)|0,s=s+Math.imul(j,xt)|0,g=g+Math.imul(j,vt)|0;var Wr=(T+f|0)+((s&8191)<<13)|0;T=(g+(s>>>13)|0)+(Wr>>>26)|0,Wr&=67108863,f=Math.imul(it,mt),s=Math.imul(it,pt),s=s+Math.imul(rt,mt)|0,g=Math.imul(rt,pt),f=f+Math.imul(ot,dt)|0,s=s+Math.imul(ot,ft)|0,s=s+Math.imul(at,dt)|0,g=g+Math.imul(at,ft)|0,f=f+Math.imul(et,ht)|0,s=s+Math.imul(et,gt)|0,s=s+Math.imul(nt,ht)|0,g=g+Math.imul(nt,gt)|0,f=f+Math.imul(Z,yt)|0,s=s+Math.imul(Z,bt)|0,s=s+Math.imul(tt,yt)|0,g=g+Math.imul(tt,bt)|0,f=f+Math.imul(J,St)|0,s=s+Math.imul(J,Tt)|0,s=s+Math.imul(Y,St)|0,g=g+Math.imul(Y,Tt)|0,f=f+Math.imul(G,It)|0,s=s+Math.imul(G,wt)|0,s=s+Math.imul(Q,It)|0,g=g+Math.imul(Q,wt)|0,f=f+Math.imul(X,Ct)|0,s=s+Math.imul(X,kt)|0,s=s+Math.imul(z,Ct)|0,g=g+Math.imul(z,kt)|0,f=f+Math.imul(U,xt)|0,s=s+Math.imul(U,vt)|0,s=s+Math.imul(q,xt)|0,g=g+Math.imul(q,vt)|0;var _r=(T+f|0)+((s&8191)<<13)|0;T=(g+(s>>>13)|0)+(_r>>>26)|0,_r&=67108863,f=Math.imul(it,dt),s=Math.imul(it,ft),s=s+Math.imul(rt,dt)|0,g=Math.imul(rt,ft),f=f+Math.imul(ot,ht)|0,s=s+Math.imul(ot,gt)|0,s=s+Math.imul(at,ht)|0,g=g+Math.imul(at,gt)|0,f=f+Math.imul(et,yt)|0,s=s+Math.imul(et,bt)|0,s=s+Math.imul(nt,yt)|0,g=g+Math.imul(nt,bt)|0,f=f+Math.imul(Z,St)|0,s=s+Math.imul(Z,Tt)|0,s=s+Math.imul(tt,St)|0,g=g+Math.imul(tt,Tt)|0,f=f+Math.imul(J,It)|0,s=s+Math.imul(J,wt)|0,s=s+Math.imul(Y,It)|0,g=g+Math.imul(Y,wt)|0,f=f+Math.imul(G,Ct)|0,s=s+Math.imul(G,kt)|0,s=s+Math.imul(Q,Ct)|0,g=g+Math.imul(Q,kt)|0,f=f+Math.imul(X,xt)|0,s=s+Math.imul(X,vt)|0,s=s+Math.imul(z,xt)|0,g=g+Math.imul(z,vt)|0;var Lr=(T+f|0)+((s&8191)<<13)|0;T=(g+(s>>>13)|0)+(Lr>>>26)|0,Lr&=67108863,f=Math.imul(it,ht),s=Math.imul(it,gt),s=s+Math.imul(rt,ht)|0,g=Math.imul(rt,gt),f=f+Math.imul(ot,yt)|0,s=s+Math.imul(ot,bt)|0,s=s+Math.imul(at,yt)|0,g=g+Math.imul(at,bt)|0,f=f+Math.imul(et,St)|0,s=s+Math.imul(et,Tt)|0,s=s+Math.imul(nt,St)|0,g=g+Math.imul(nt,Tt)|0,f=f+Math.imul(Z,It)|0,s=s+Math.imul(Z,wt)|0,s=s+Math.imul(tt,It)|0,g=g+Math.imul(tt,wt)|0,f=f+Math.imul(J,Ct)|0,s=s+Math.imul(J,kt)|0,s=s+Math.imul(Y,Ct)|0,g=g+Math.imul(Y,kt)|0,f=f+Math.imul(G,xt)|0,s=s+Math.imul(G,vt)|0,s=s+Math.imul(Q,xt)|0,g=g+Math.imul(Q,vt)|0;var jr=(T+f|0)+((s&8191)<<13)|0;T=(g+(s>>>13)|0)+(jr>>>26)|0,jr&=67108863,f=Math.imul(it,yt),s=Math.imul(it,bt),s=s+Math.imul(rt,yt)|0,g=Math.imul(rt,bt),f=f+Math.imul(ot,St)|0,s=s+Math.imul(ot,Tt)|0,s=s+Math.imul(at,St)|0,g=g+Math.imul(at,Tt)|0,f=f+Math.imul(et,It)|0,s=s+Math.imul(et,wt)|0,s=s+Math.imul(nt,It)|0,g=g+Math.imul(nt,wt)|0,f=f+Math.imul(Z,Ct)|0,s=s+Math.imul(Z,kt)|0,s=s+Math.imul(tt,Ct)|0,g=g+Math.imul(tt,kt)|0,f=f+Math.imul(J,xt)|0,s=s+Math.imul(J,vt)|0,s=s+Math.imul(Y,xt)|0,g=g+Math.imul(Y,vt)|0;var Ur=(T+f|0)+((s&8191)<<13)|0;T=(g+(s>>>13)|0)+(Ur>>>26)|0,Ur&=67108863,f=Math.imul(it,St),s=Math.imul(it,Tt),s=s+Math.imul(rt,St)|0,g=Math.imul(rt,Tt),f=f+Math.imul(ot,It)|0,s=s+Math.imul(ot,wt)|0,s=s+Math.imul(at,It)|0,g=g+Math.imul(at,wt)|0,f=f+Math.imul(et,Ct)|0,s=s+Math.imul(et,kt)|0,s=s+Math.imul(nt,Ct)|0,g=g+Math.imul(nt,kt)|0,f=f+Math.imul(Z,xt)|0,s=s+Math.imul(Z,vt)|0,s=s+Math.imul(tt,xt)|0,g=g+Math.imul(tt,vt)|0;var qr=(T+f|0)+((s&8191)<<13)|0;T=(g+(s>>>13)|0)+(qr>>>26)|0,qr&=67108863,f=Math.imul(it,It),s=Math.imul(it,wt),s=s+Math.imul(rt,It)|0,g=Math.imul(rt,wt),f=f+Math.imul(ot,Ct)|0,s=s+Math.imul(ot,kt)|0,s=s+Math.imul(at,Ct)|0,g=g+Math.imul(at,kt)|0,f=f+Math.imul(et,xt)|0,s=s+Math.imul(et,vt)|0,s=s+Math.imul(nt,xt)|0,g=g+Math.imul(nt,vt)|0;var Fr=(T+f|0)+((s&8191)<<13)|0;T=(g+(s>>>13)|0)+(Fr>>>26)|0,Fr&=67108863,f=Math.imul(it,Ct),s=Math.imul(it,kt),s=s+Math.imul(rt,Ct)|0,g=Math.imul(rt,kt),f=f+Math.imul(ot,xt)|0,s=s+Math.imul(ot,vt)|0,s=s+Math.imul(at,xt)|0,g=g+Math.imul(at,vt)|0;var Kr=(T+f|0)+((s&8191)<<13)|0;T=(g+(s>>>13)|0)+(Kr>>>26)|0,Kr&=67108863,f=Math.imul(it,xt),s=Math.imul(it,vt),s=s+Math.imul(rt,xt)|0,g=Math.imul(rt,vt);var $r=(T+f|0)+((s&8191)<<13)|0;return T=(g+(s>>>13)|0)+($r>>>26)|0,$r&=67108863,S[0]=vr,S[1]=Dr,S[2]=Ar,S[3]=Mr,S[4]=Or,S[5]=Pr,S[6]=Rr,S[7]=Br,S[8]=Er,S[9]=Nr,S[10]=Wr,S[11]=_r,S[12]=Lr,S[13]=jr,S[14]=Ur,S[15]=qr,S[16]=Fr,S[17]=Kr,S[18]=$r,T!==0&&(S[19]=T,m.length++),m};Math.imul||(H=K);function Et(y,r,u){u.negative=r.negative^y.negative,u.length=y.length+r.length;for(var m=0,p=0,h=0;h<u.length-1;h++){var S=p;p=0;for(var T=m&67108863,f=Math.min(h,r.length-1),s=Math.max(0,h-y.length+1);s<=f;s++){var g=h-s,D=y.words[g]|0,M=r.words[s]|0,O=D*M,B=O&67108863;S=S+(O/67108864|0)|0,B=B+T|0,T=B&67108863,S=S+(B>>>26)|0,p+=S>>>26,S&=67108863}u.words[h]=T,m=S,S=p}return m!==0?u.words[h]=m:u.length--,u._strip()}function Wt(y,r,u){return Et(y,r,u)}o.prototype.mulTo=function(r,u){var m,p=this.length+r.length;return this.length===10&&r.length===10?m=H(this,r,u):p<63?m=K(this,r,u):p<1024?m=Et(this,r,u):m=Wt(this,r,u),m};function Ot(y,r){this.x=y,this.y=r}Ot.prototype.makeRBT=function(r){for(var u=new Array(r),m=o.prototype._countBits(r)-1,p=0;p<r;p++)u[p]=this.revBin(p,m,r);return u},Ot.prototype.revBin=function(r,u,m){if(r===0||r===m-1)return r;for(var p=0,h=0;h<u;h++)p|=(r&1)<<u-h-1,r>>=1;return p},Ot.prototype.permute=function(r,u,m,p,h,S){for(var T=0;T<S;T++)p[T]=u[r[T]],h[T]=m[r[T]]},Ot.prototype.transform=function(r,u,m,p,h,S){this.permute(S,r,u,m,p,h);for(var T=1;T<h;T<<=1)for(var f=T<<1,s=Math.cos(2*Math.PI/f),g=Math.sin(2*Math.PI/f),D=0;D<h;D+=f)for(var M=s,O=g,B=0;B<T;B++){var W=m[D+B],j=p[D+B],re=m[D+B+T],U=p[D+B+T],q=M*re-O*U;U=M*U+O*re,re=q,m[D+B]=W+re,p[D+B]=j+U,m[D+B+T]=W-re,p[D+B+T]=j-U,B!==f&&(q=s*M-g*O,O=s*O+g*M,M=q)}},Ot.prototype.guessLen13b=function(r,u){var m=Math.max(u,r)|1,p=m&1,h=0;for(m=m/2|0;m;m=m>>>1)h++;return 1<<h+1+p},Ot.prototype.conjugate=function(r,u,m){if(!(m<=1))for(var p=0;p<m/2;p++){var h=r[p];r[p]=r[m-p-1],r[m-p-1]=h,h=u[p],u[p]=-u[m-p-1],u[m-p-1]=-h}},Ot.prototype.normalize13b=function(r,u){for(var m=0,p=0;p<u/2;p++){var h=Math.round(r[2*p+1]/u)*8192+Math.round(r[2*p]/u)+m;r[p]=h&67108863,h<67108864?m=0:m=h/67108864|0}return r},Ot.prototype.convert13b=function(r,u,m,p){for(var h=0,S=0;S<u;S++)h=h+(r[S]|0),m[2*S]=h&8191,h=h>>>13,m[2*S+1]=h&8191,h=h>>>13;for(S=2*u;S<p;++S)m[S]=0;t(h===0),t((h&-8192)===0)},Ot.prototype.stub=function(r){for(var u=new Array(r),m=0;m<r;m++)u[m]=0;return u},Ot.prototype.mulp=function(r,u,m){var p=2*this.guessLen13b(r.length,u.length),h=this.makeRBT(p),S=this.stub(p),T=new Array(p),f=new Array(p),s=new Array(p),g=new Array(p),D=new Array(p),M=new Array(p),O=m.words;O.length=p,this.convert13b(r.words,r.length,T,p),this.convert13b(u.words,u.length,g,p),this.transform(T,S,f,s,p,h),this.transform(g,S,D,M,p,h);for(var B=0;B<p;B++){var W=f[B]*D[B]-s[B]*M[B];s[B]=f[B]*M[B]+s[B]*D[B],f[B]=W}return this.conjugate(f,s,p),this.transform(f,s,O,S,p,h),this.conjugate(O,S,p),this.normalize13b(O,p),m.negative=r.negative^u.negative,m.length=r.length+u.length,m._strip()},o.prototype.mul=function(r){var u=new o(null);return u.words=new Array(this.length+r.length),this.mulTo(r,u)},o.prototype.mulf=function(r){var u=new o(null);return u.words=new Array(this.length+r.length),Wt(this,r,u)},o.prototype.imul=function(r){return this.clone().mulTo(r,this)},o.prototype.imuln=function(r){var u=r<0;u&&(r=-r),t(typeof r=="number"),t(r<67108864);for(var m=0,p=0;p<this.length;p++){var h=(this.words[p]|0)*r,S=(h&67108863)+(m&67108863);m>>=26,m+=h/67108864|0,m+=S>>>26,this.words[p]=S&67108863}return m!==0&&(this.words[p]=m,this.length++),u?this.ineg():this},o.prototype.muln=function(r){return this.clone().imuln(r)},o.prototype.sqr=function(){return this.mul(this)},o.prototype.isqr=function(){return this.imul(this.clone())},o.prototype.pow=function(r){var u=P(r);if(u.length===0)return new o(1);for(var m=this,p=0;p<u.length&&u[p]===0;p++,m=m.sqr());if(++p<u.length)for(var h=m.sqr();p<u.length;p++,h=h.sqr())u[p]!==0&&(m=m.mul(h));return m},o.prototype.iushln=function(r){t(typeof r=="number"&&r>=0);var u=r%26,m=(r-u)/26,p=67108863>>>26-u<<26-u,h;if(u!==0){var S=0;for(h=0;h<this.length;h++){var T=this.words[h]&p,f=(this.words[h]|0)-T<<u;this.words[h]=f|S,S=T>>>26-u}S&&(this.words[h]=S,this.length++)}if(m!==0){for(h=this.length-1;h>=0;h--)this.words[h+m]=this.words[h];for(h=0;h<m;h++)this.words[h]=0;this.length+=m}return this._strip()},o.prototype.ishln=function(r){return t(this.negative===0),this.iushln(r)},o.prototype.iushrn=function(r,u,m){t(typeof r=="number"&&r>=0);var p;u?p=(u-u%26)/26:p=0;var h=r%26,S=Math.min((r-h)/26,this.length),T=67108863^67108863>>>h<<h,f=m;if(p-=S,p=Math.max(0,p),f){for(var s=0;s<S;s++)f.words[s]=this.words[s];f.length=S}if(S!==0)if(this.length>S)for(this.length-=S,s=0;s<this.length;s++)this.words[s]=this.words[s+S];else this.words[0]=0,this.length=1;var g=0;for(s=this.length-1;s>=0&&(g!==0||s>=p);s--){var D=this.words[s]|0;this.words[s]=g<<26-h|D>>>h,g=D&T}return f&&g!==0&&(f.words[f.length++]=g),this.length===0&&(this.words[0]=0,this.length=1),this._strip()},o.prototype.ishrn=function(r,u,m){return t(this.negative===0),this.iushrn(r,u,m)},o.prototype.shln=function(r){return this.clone().ishln(r)},o.prototype.ushln=function(r){return this.clone().iushln(r)},o.prototype.shrn=function(r){return this.clone().ishrn(r)},o.prototype.ushrn=function(r){return this.clone().iushrn(r)},o.prototype.testn=function(r){t(typeof r=="number"&&r>=0);var u=r%26,m=(r-u)/26,p=1<<u;if(this.length<=m)return!1;var h=this.words[m];return!!(h&p)},o.prototype.imaskn=function(r){t(typeof r=="number"&&r>=0);var u=r%26,m=(r-u)/26;if(t(this.negative===0,"imaskn works only with positive numbers"),this.length<=m)return this;if(u!==0&&m++,this.length=Math.min(m,this.length),u!==0){var p=67108863^67108863>>>u<<u;this.words[this.length-1]&=p}return this._strip()},o.prototype.maskn=function(r){return this.clone().imaskn(r)},o.prototype.iaddn=function(r){return t(typeof r=="number"),t(r<67108864),r<0?this.isubn(-r):this.negative!==0?this.length===1&&(this.words[0]|0)<=r?(this.words[0]=r-(this.words[0]|0),this.negative=0,this):(this.negative=0,this.isubn(r),this.negative=1,this):this._iaddn(r)},o.prototype._iaddn=function(r){this.words[0]+=r;for(var u=0;u<this.length&&this.words[u]>=67108864;u++)this.words[u]-=67108864,u===this.length-1?this.words[u+1]=1:this.words[u+1]++;return this.length=Math.max(this.length,u+1),this},o.prototype.isubn=function(r){if(t(typeof r=="number"),t(r<67108864),r<0)return this.iaddn(-r);if(this.negative!==0)return this.negative=0,this.iaddn(r),this.negative=1,this;if(this.words[0]-=r,this.length===1&&this.words[0]<0)this.words[0]=-this.words[0],this.negative=1;else for(var u=0;u<this.length&&this.words[u]<0;u++)this.words[u]+=67108864,this.words[u+1]-=1;return this._strip()},o.prototype.addn=function(r){return this.clone().iaddn(r)},o.prototype.subn=function(r){return this.clone().isubn(r)},o.prototype.iabs=function(){return this.negative=0,this},o.prototype.abs=function(){return this.clone().iabs()},o.prototype._ishlnsubmul=function(r,u,m){var p=r.length+m,h;this._expand(p);var S,T=0;for(h=0;h<r.length;h++){S=(this.words[h+m]|0)+T;var f=(r.words[h]|0)*u;S-=f&67108863,T=(S>>26)-(f/67108864|0),this.words[h+m]=S&67108863}for(;h<this.length-m;h++)S=(this.words[h+m]|0)+T,T=S>>26,this.words[h+m]=S&67108863;if(T===0)return this._strip();for(t(T===-1),T=0,h=0;h<this.length;h++)S=-(this.words[h]|0)+T,T=S>>26,this.words[h]=S&67108863;return this.negative=1,this._strip()},o.prototype._wordDiv=function(r,u){var m=this.length-r.length,p=this.clone(),h=r,S=h.words[h.length-1]|0,T=this._countBits(S);m=26-T,m!==0&&(h=h.ushln(m),p.iushln(m),S=h.words[h.length-1]|0);var f=p.length-h.length,s;if(u!=="mod"){s=new o(null),s.length=f+1,s.words=new Array(s.length);for(var g=0;g<s.length;g++)s.words[g]=0}var D=p.clone()._ishlnsubmul(h,1,f);D.negative===0&&(p=D,s&&(s.words[f]=1));for(var M=f-1;M>=0;M--){var O=(p.words[h.length+M]|0)*67108864+(p.words[h.length+M-1]|0);for(O=Math.min(O/S|0,67108863),p._ishlnsubmul(h,O,M);p.negative!==0;)O--,p.negative=0,p._ishlnsubmul(h,1,M),p.isZero()||(p.negative^=1);s&&(s.words[M]=O)}return s&&s._strip(),p._strip(),u!=="div"&&m!==0&&p.iushrn(m),{div:s||null,mod:p}},o.prototype.divmod=function(r,u,m){if(t(!r.isZero()),this.isZero())return{div:new o(0),mod:new o(0)};var p,h,S;return this.negative!==0&&r.negative===0?(S=this.neg().divmod(r,u),u!=="mod"&&(p=S.div.neg()),u!=="div"&&(h=S.mod.neg(),m&&h.negative!==0&&h.iadd(r)),{div:p,mod:h}):this.negative===0&&r.negative!==0?(S=this.divmod(r.neg(),u),u!=="mod"&&(p=S.div.neg()),{div:p,mod:S.mod}):this.negative&r.negative?(S=this.neg().divmod(r.neg(),u),u!=="div"&&(h=S.mod.neg(),m&&h.negative!==0&&h.isub(r)),{div:S.div,mod:h}):r.length>this.length||this.cmp(r)<0?{div:new o(0),mod:this}:r.length===1?u==="div"?{div:this.divn(r.words[0]),mod:null}:u==="mod"?{div:null,mod:new o(this.modrn(r.words[0]))}:{div:this.divn(r.words[0]),mod:new o(this.modrn(r.words[0]))}:this._wordDiv(r,u)},o.prototype.div=function(r){return this.divmod(r,"div",!1).div},o.prototype.mod=function(r){return this.divmod(r,"mod",!1).mod},o.prototype.umod=function(r){return this.divmod(r,"mod",!0).mod},o.prototype.divRound=function(r){var u=this.divmod(r);if(u.mod.isZero())return u.div;var m=u.div.negative!==0?u.mod.isub(r):u.mod,p=r.ushrn(1),h=r.andln(1),S=m.cmp(p);return S<0||h===1&&S===0?u.div:u.div.negative!==0?u.div.isubn(1):u.div.iaddn(1)},o.prototype.modrn=function(r){var u=r<0;u&&(r=-r),t(r<=67108863);for(var m=(1<<26)%r,p=0,h=this.length-1;h>=0;h--)p=(m*p+(this.words[h]|0))%r;return u?-p:p},o.prototype.modn=function(r){return this.modrn(r)},o.prototype.idivn=function(r){var u=r<0;u&&(r=-r),t(r<=67108863);for(var m=0,p=this.length-1;p>=0;p--){var h=(this.words[p]|0)+m*67108864;this.words[p]=h/r|0,m=h%r}return this._strip(),u?this.ineg():this},o.prototype.divn=function(r){return this.clone().idivn(r)},o.prototype.egcd=function(r){t(r.negative===0),t(!r.isZero());var u=this,m=r.clone();u.negative!==0?u=u.umod(r):u=u.clone();for(var p=new o(1),h=new o(0),S=new o(0),T=new o(1),f=0;u.isEven()&&m.isEven();)u.iushrn(1),m.iushrn(1),++f;for(var s=m.clone(),g=u.clone();!u.isZero();){for(var D=0,M=1;!(u.words[0]&M)&&D<26;++D,M<<=1);if(D>0)for(u.iushrn(D);D-- >0;)(p.isOdd()||h.isOdd())&&(p.iadd(s),h.isub(g)),p.iushrn(1),h.iushrn(1);for(var O=0,B=1;!(m.words[0]&B)&&O<26;++O,B<<=1);if(O>0)for(m.iushrn(O);O-- >0;)(S.isOdd()||T.isOdd())&&(S.iadd(s),T.isub(g)),S.iushrn(1),T.iushrn(1);u.cmp(m)>=0?(u.isub(m),p.isub(S),h.isub(T)):(m.isub(u),S.isub(p),T.isub(h))}return{a:S,b:T,gcd:m.iushln(f)}},o.prototype._invmp=function(r){t(r.negative===0),t(!r.isZero());var u=this,m=r.clone();u.negative!==0?u=u.umod(r):u=u.clone();for(var p=new o(1),h=new o(0),S=m.clone();u.cmpn(1)>0&&m.cmpn(1)>0;){for(var T=0,f=1;!(u.words[0]&f)&&T<26;++T,f<<=1);if(T>0)for(u.iushrn(T);T-- >0;)p.isOdd()&&p.iadd(S),p.iushrn(1);for(var s=0,g=1;!(m.words[0]&g)&&s<26;++s,g<<=1);if(s>0)for(m.iushrn(s);s-- >0;)h.isOdd()&&h.iadd(S),h.iushrn(1);u.cmp(m)>=0?(u.isub(m),p.isub(h)):(m.isub(u),h.isub(p))}var D;return u.cmpn(1)===0?D=p:D=h,D.cmpn(0)<0&&D.iadd(r),D},o.prototype.gcd=function(r){if(this.isZero())return r.abs();if(r.isZero())return this.abs();var u=this.clone(),m=r.clone();u.negative=0,m.negative=0;for(var p=0;u.isEven()&&m.isEven();p++)u.iushrn(1),m.iushrn(1);do{for(;u.isEven();)u.iushrn(1);for(;m.isEven();)m.iushrn(1);var h=u.cmp(m);if(h<0){var S=u;u=m,m=S}else if(h===0||m.cmpn(1)===0)break;u.isub(m)}while(!0);return m.iushln(p)},o.prototype.invm=function(r){return this.egcd(r).a.umod(r)},o.prototype.isEven=function(){return(this.words[0]&1)===0},o.prototype.isOdd=function(){return(this.words[0]&1)===1},o.prototype.andln=function(r){return this.words[0]&r},o.prototype.bincn=function(r){t(typeof r=="number");var u=r%26,m=(r-u)/26,p=1<<u;if(this.length<=m)return this._expand(m+1),this.words[m]|=p,this;for(var h=p,S=m;h!==0&&S<this.length;S++){var T=this.words[S]|0;T+=h,h=T>>>26,T&=67108863,this.words[S]=T}return h!==0&&(this.words[S]=h,this.length++),this},o.prototype.isZero=function(){return this.length===1&&this.words[0]===0},o.prototype.cmpn=function(r){var u=r<0;if(this.negative!==0&&!u)return-1;if(this.negative===0&&u)return 1;this._strip();var m;if(this.length>1)m=1;else{u&&(r=-r),t(r<=67108863,"Number is too big");var p=this.words[0]|0;m=p===r?0:p<r?-1:1}return this.negative!==0?-m|0:m},o.prototype.cmp=function(r){if(this.negative!==0&&r.negative===0)return-1;if(this.negative===0&&r.negative!==0)return 1;var u=this.ucmp(r);return this.negative!==0?-u|0:u},o.prototype.ucmp=function(r){if(this.length>r.length)return 1;if(this.length<r.length)return-1;for(var u=0,m=this.length-1;m>=0;m--){var p=this.words[m]|0,h=r.words[m]|0;if(p!==h){p<h?u=-1:p>h&&(u=1);break}}return u},o.prototype.gtn=function(r){return this.cmpn(r)===1},o.prototype.gt=function(r){return this.cmp(r)===1},o.prototype.gten=function(r){return this.cmpn(r)>=0},o.prototype.gte=function(r){return this.cmp(r)>=0},o.prototype.ltn=function(r){return this.cmpn(r)===-1},o.prototype.lt=function(r){return this.cmp(r)===-1},o.prototype.lten=function(r){return this.cmpn(r)<=0},o.prototype.lte=function(r){return this.cmp(r)<=0},o.prototype.eqn=function(r){return this.cmpn(r)===0},o.prototype.eq=function(r){return this.cmp(r)===0},o.red=function(r){return new $(r)},o.prototype.toRed=function(r){return t(!this.red,"Already a number in reduction context"),t(this.negative===0,"red works only with positives"),r.convertTo(this)._forceRed(r)},o.prototype.fromRed=function(){return t(this.red,"fromRed works only with numbers in reduction context"),this.red.convertFrom(this)},o.prototype._forceRed=function(r){return this.red=r,this},o.prototype.forceRed=function(r){return t(!this.red,"Already a number in reduction context"),this._forceRed(r)},o.prototype.redAdd=function(r){return t(this.red,"redAdd works only with red numbers"),this.red.add(this,r)},o.prototype.redIAdd=function(r){return t(this.red,"redIAdd works only with red numbers"),this.red.iadd(this,r)},o.prototype.redSub=function(r){return t(this.red,"redSub works only with red numbers"),this.red.sub(this,r)},o.prototype.redISub=function(r){return t(this.red,"redISub works only with red numbers"),this.red.isub(this,r)},o.prototype.redShl=function(r){return t(this.red,"redShl works only with red numbers"),this.red.shl(this,r)},o.prototype.redMul=function(r){return t(this.red,"redMul works only with red numbers"),this.red._verify2(this,r),this.red.mul(this,r)},o.prototype.redIMul=function(r){return t(this.red,"redMul works only with red numbers"),this.red._verify2(this,r),this.red.imul(this,r)},o.prototype.redSqr=function(){return t(this.red,"redSqr works only with red numbers"),this.red._verify1(this),this.red.sqr(this)},o.prototype.redISqr=function(){return t(this.red,"redISqr works only with red numbers"),this.red._verify1(this),this.red.isqr(this)},o.prototype.redSqrt=function(){return t(this.red,"redSqrt works only with red numbers"),this.red._verify1(this),this.red.sqrt(this)},o.prototype.redInvm=function(){return t(this.red,"redInvm works only with red numbers"),this.red._verify1(this),this.red.invm(this)},o.prototype.redNeg=function(){return t(this.red,"redNeg works only with red numbers"),this.red._verify1(this),this.red.neg(this)},o.prototype.redPow=function(r){return t(this.red&&!r.red,"redPow(normalNum)"),this.red._verify1(this),this.red.pow(this,r)};var mn={k256:null,p224:null,p192:null,p25519:null};function _t(y,r){this.name=y,this.p=new o(r,16),this.n=this.p.bitLength(),this.k=new o(1).iushln(this.n).isub(this.p),this.tmp=this._tmp()}_t.prototype._tmp=function(){var r=new o(null);return r.words=new Array(Math.ceil(this.n/13)),r},_t.prototype.ireduce=function(r){var u=r,m;do this.split(u,this.tmp),u=this.imulK(u),u=u.iadd(this.tmp),m=u.bitLength();while(m>this.n);var p=m<this.n?-1:u.ucmp(this.p);return p===0?(u.words[0]=0,u.length=1):p>0?u.isub(this.p):u.strip!==void 0?u.strip():u._strip(),u},_t.prototype.split=function(r,u){r.iushrn(this.n,0,u)},_t.prototype.imulK=function(r){return r.imul(this.k)};function Fn(){_t.call(this,"k256","ffffffff ffffffff ffffffff ffffffff ffffffff ffffffff fffffffe fffffc2f")}n(Fn,_t),Fn.prototype.split=function(r,u){for(var m=4194303,p=Math.min(r.length,9),h=0;h<p;h++)u.words[h]=r.words[h];if(u.length=p,r.length<=9){r.words[0]=0,r.length=1;return}var S=r.words[9];for(u.words[u.length++]=S&m,h=10;h<r.length;h++){var T=r.words[h]|0;r.words[h-10]=(T&m)<<4|S>>>22,S=T}S>>>=22,r.words[h-10]=S,S===0&&r.length>10?r.length-=10:r.length-=9},Fn.prototype.imulK=function(r){r.words[r.length]=0,r.words[r.length+1]=0,r.length+=2;for(var u=0,m=0;m<r.length;m++){var p=r.words[m]|0;u+=p*977,r.words[m]=u&67108863,u=p*64+(u/67108864|0)}return r.words[r.length-1]===0&&(r.length--,r.words[r.length-1]===0&&r.length--),r};function qs(){_t.call(this,"p224","ffffffff ffffffff ffffffff ffffffff 00000000 00000000 00000001")}n(qs,_t);function Fs(){_t.call(this,"p192","ffffffff ffffffff ffffffff fffffffe ffffffff ffffffff")}n(Fs,_t);function xr(){_t.call(this,"25519","7fffffffffffffff ffffffffffffffff ffffffffffffffff ffffffffffffffed")}n(xr,_t),xr.prototype.imulK=function(r){for(var u=0,m=0;m<r.length;m++){var p=(r.words[m]|0)*19+u,h=p&67108863;p>>>=26,r.words[m]=h,u=p}return u!==0&&(r.words[r.length++]=u),r},o._prime=function(r){if(mn[r])return mn[r];var u;if(r==="k256")u=new Fn;else if(r==="p224")u=new qs;else if(r==="p192")u=new Fs;else if(r==="p25519")u=new xr;else throw new Error("Unknown prime "+r);return mn[r]=u,u};function $(y){if(typeof y=="string"){var r=o._prime(y);this.m=r.p,this.prime=r}else t(y.gtn(1),"modulus must be greater than 1"),this.m=y,this.prime=null}$.prototype._verify1=function(r){t(r.negative===0,"red works only with positives"),t(r.red,"red works only with red numbers")},$.prototype._verify2=function(r,u){t((r.negative|u.negative)===0,"red works only with positives"),t(r.red&&r.red===u.red,"red works only with red numbers")},$.prototype.imod=function(r){return this.prime?this.prime.ireduce(r)._forceRed(this):(b(r,r.umod(this.m)._forceRed(this)),r)},$.prototype.neg=function(r){return r.isZero()?r.clone():this.m.sub(r)._forceRed(this)},$.prototype.add=function(r,u){this._verify2(r,u);var m=r.add(u);return m.cmp(this.m)>=0&&m.isub(this.m),m._forceRed(this)},$.prototype.iadd=function(r,u){this._verify2(r,u);var m=r.iadd(u);return m.cmp(this.m)>=0&&m.isub(this.m),m},$.prototype.sub=function(r,u){this._verify2(r,u);var m=r.sub(u);return m.cmpn(0)<0&&m.iadd(this.m),m._forceRed(this)},$.prototype.isub=function(r,u){this._verify2(r,u);var m=r.isub(u);return m.cmpn(0)<0&&m.iadd(this.m),m},$.prototype.shl=function(r,u){return this._verify1(r),this.imod(r.ushln(u))},$.prototype.imul=function(r,u){return this._verify2(r,u),this.imod(r.imul(u))},$.prototype.mul=function(r,u){return this._verify2(r,u),this.imod(r.mul(u))},$.prototype.isqr=function(r){return this.imul(r,r.clone())},$.prototype.sqr=function(r){return this.mul(r,r)},$.prototype.sqrt=function(r){if(r.isZero())return r.clone();var u=this.m.andln(3);if(t(u%2===1),u===3){var m=this.m.add(new o(1)).iushrn(2);return this.pow(r,m)}for(var p=this.m.subn(1),h=0;!p.isZero()&&p.andln(1)===0;)h++,p.iushrn(1);t(!p.isZero());var S=new o(1).toRed(this),T=S.redNeg(),f=this.m.subn(1).iushrn(1),s=this.m.bitLength();for(s=new o(2*s*s).toRed(this);this.pow(s,f).cmp(T)!==0;)s.redIAdd(T);for(var g=this.pow(s,p),D=this.pow(r,p.addn(1).iushrn(1)),M=this.pow(r,p),O=h;M.cmp(S)!==0;){for(var B=M,W=0;B.cmp(S)!==0;W++)B=B.redSqr();t(W<O);var j=this.pow(g,new o(1).iushln(O-W-1));D=D.redMul(j),g=j.redSqr(),M=M.redMul(g),O=W}return D},$.prototype.invm=function(r){var u=r._invmp(this.m);return u.negative!==0?(u.negative=0,this.imod(u).redNeg()):this.imod(u)},$.prototype.pow=function(r,u){if(u.isZero())return new o(1).toRed(this);if(u.cmpn(1)===0)return r.clone();var m=4,p=new Array(1<<m);p[0]=new o(1).toRed(this),p[1]=r;for(var h=2;h<p.length;h++)p[h]=this.mul(p[h-1],r);var S=p[0],T=0,f=0,s=u.bitLength()%26;for(s===0&&(s=26),h=u.length-1;h>=0;h--){for(var g=u.words[h],D=s-1;D>=0;D--){var M=g>>D&1;if(S!==p[0]&&(S=this.sqr(S)),M===0&&T===0){f=0;continue}T<<=1,T|=M,f++,!(f!==m&&(h!==0||D!==0))&&(S=this.mul(S,p[T]),f=0,T=0)}s=26}return S},$.prototype.convertTo=function(r){var u=r.umod(this.m);return u===r?u.clone():u},$.prototype.convertFrom=function(r){var u=r.clone();return u.red=null,u},o.mont=function(r){return new Pe(r)};function Pe(y){$.call(this,y),this.shift=this.m.bitLength(),this.shift%26!==0&&(this.shift+=26-this.shift%26),this.r=new o(1).iushln(this.shift),this.r2=this.imod(this.r.sqr()),this.rinv=this.r._invmp(this.m),this.minv=this.rinv.mul(this.r).isubn(1).div(this.m),this.minv=this.minv.umod(this.r),this.minv=this.r.sub(this.minv)}n(Pe,$),Pe.prototype.convertTo=function(r){return this.imod(r.ushln(this.shift))},Pe.prototype.convertFrom=function(r){var u=this.imod(r.mul(this.rinv));return u.red=null,u},Pe.prototype.imul=function(r,u){if(r.isZero()||u.isZero())return r.words[0]=0,r.length=1,r;var m=r.imul(u),p=m.maskn(this.shift).mul(this.minv).imaskn(this.shift).mul(this.m),h=m.isub(p).iushrn(this.shift),S=h;return h.cmp(this.m)>=0?S=h.isub(this.m):h.cmpn(0)<0&&(S=h.iadd(this.m)),S._forceRed(this)},Pe.prototype.mul=function(r,u){if(r.isZero()||u.isZero())return new o(0)._forceRed(this);var m=r.mul(u),p=m.maskn(this.shift).mul(this.minv).imaskn(this.shift).mul(this.m),h=m.isub(p).iushrn(this.shift),S=h;return h.cmp(this.m)>=0?S=h.isub(this.m):h.cmpn(0)<0&&(S=h.iadd(this.m)),S._forceRed(this)},Pe.prototype.invm=function(r){var u=this.imod(r._invmp(this.m).mul(this.r2));return u._forceRed(this)}})(typeof _s>"u"||_s,sp)});var ef={};Vr(ef,{appHelpers:()=>tf});module.exports=Vp(ef);var dc=require("@msafe/sui3-utils");var ne=require("@alphafi/alphafi-sdk"),qe=require("@msafe/sui3-utils"),Qt=require("@mysten/bcs");var $n=class{constructor(e,t){this.transaction=e;this.simResult=t}decode(){if(this.isClaimRewardTransaction())return this.decodeClaimReward();let e=this.getLiquidityChangeEvent();if(!e)throw new Error("No liquidity change event found. Unable to decode transaction.");let t=e.parsedJson,n=t.pool_id,o=ne.poolIdPoolNameMap[n];if(console.log("Decoder event data - ",t),console.log("Decoder poolName - ",o),this.isWithdrawAlphaEvent(e))return this.decodeWithdrawAlpha(t);if(this.isWithdrawEvent(t))return this.decodeWithdraw(o);if(this.isDoubleAssetDepositEvent(t,o))return this.decodeDoubleAssetDeposit(o,t);if(this.isSingleAssetDepositEvent(t,o))return this.decodeSingleAssetDeposit(o,t);throw new Error("Unknown transaction type")}get commands(){return this.transaction.getData().commands}get inputs(){return this.transaction.getData().inputs}getMoveCallCommand(e){return this.commands.find(t=>t.$kind==="MoveCall"&&t.MoveCall.function===e)}getLiquidityChangeEvent(){return this.simResult.events.find(e=>this.isLiquidityChangeEventType(e.type))}isClaimRewardTransaction(){return!!this.getMoveCallCommand("get_user_rewards_all")}isLiquidityChangeEventType(e){return e.includes("LiquidityChangeEvent")||e.includes("LiquidityChangeNewNewEvent")||e.includes("WithdrawEventV2")}isWithdrawAlphaEvent(e){return e.type.includes("WithdrawEventV2")}isWithdrawEvent(e){return e.event_type===1}isDoubleAssetDepositEvent(e,t){return e.event_type===0&&ne.poolInfo[t].assetTypes.length===2}isSingleAssetDepositEvent(e,t){return e.event_type===0&&ne.poolInfo[t].assetTypes.length===1}extractXTokensAmount(){let e=this.inputs.find(o=>o.Pure!==void 0);if(!e||!e.Pure?.bytes)throw new Error("Unable to extract xTokensAmount from inputs");let{bytes:t}=e.Pure,n;return t.length===12?n=Qt.bcs.u64().parse((0,Qt.fromBase64)(t)):t.length===24?n=Qt.bcs.u128().parse((0,Qt.fromBase64)(t)):t.length===44?n=Qt.bcs.u256().parse((0,Qt.fromBase64)(t)):n=Qt.bcs.u64().parse((0,Qt.fromBase64)(t)),n}decodeDoubleAssetDeposit(e,t){let{amount_a:n,amount_b:o}=t,a=Number(n)>0;return console.log("Decoder.decodeDoubleAssetDeposit",n,o,a),{txType:qe.TransactionType.Other,type:"depositDoubleAsset",intentionData:{poolName:e,amount:a?n:o,isAmountA:a}}}decodeSingleAssetDeposit(e,t){let{amount:n}=t;if(console.log("Decoder.decodeSingleAssetDeposit",n),this.getLiquidityChangeEvent().type.includes(":alphafi_navi_pool:")){let{coin:a}=ne.singleAssetPoolCoinMap[e],{expo:c}=ne.coinsList[a];n=Math.floor(Number(n)/10**(9-c)).toString()}return{txType:qe.TransactionType.Other,type:"depositSingleAsset",intentionData:{poolName:e,amount:n}}}decodeWithdraw(e){let t=this.extractXTokensAmount();return console.log("Decoder.decodeWithdraw",t),{txType:qe.TransactionType.Other,type:"withdraw",intentionData:{poolName:e,xTokensAmount:t}}}decodeWithdrawAlpha(e){let t=this.extractXTokensAmount(),{amount_withdrawn_from_locked:n}=e;return console.log("Decoder.decodeWithdrawAlpha",t,n),{txType:qe.TransactionType.Other,type:"withdrawAlpha",intentionData:{withdrawFromLocked:Number(n)>0,xTokensAmount:t}}}decodeClaimReward(){return{txType:qe.TransactionType.Other,type:"claimReward",intentionData:{}}}};var cc=require("@alphafi/alphafi-sdk");var sc=Ut(require("sort-keys-recursive")),C=class{constructor(e){this.data=e}serialize(){return JSON.stringify((0,sc.default)(this.data))}};var Vn=class i extends C{constructor(t){super(t);this.data=t}txType;txSubType;async build(t){let{account:n}=t;return await(0,cc.claimRewardTxb)(n.address)}static fromData(t){return new i(t)}};var lc=require("@alphafi/alphafi-sdk");var Hn=class i extends C{constructor(t){super(t);this.data=t}txType;txSubType;async build(t){let{account:n}=t,{poolName:o,amount:a,isAmountA:c}=this.data;return await(0,lc.depositDoubleAssetTxb)(o,n.address,a,c)}static fromData(t){return console.log("DepositDoubleAssetIntention.fromData",t),new i(t)}};var uc=require("@alphafi/alphafi-sdk");var Xn=class i extends C{constructor(t){super(t);this.data=t}txType;txSubType;async build(t){let{account:n}=t,{poolName:o,amount:a}=this.data;return await(0,uc.depositSingleAssetTxb)(o,n.address,a)}static fromData(t){return console.log("DepositSingleAssetIntention.fromData",t),new i(t)}};var mc=require("@alphafi/alphafi-sdk");var zn=class i extends C{constructor(t){super(t);this.data=t}txType;txSubType;async build(t){let{account:n}=t,{poolName:o,xTokensAmount:a}=this.data;return await(0,mc.withdrawTxb)(a,o,n.address)}static fromData(t){return console.log("WithdrawIntention.fromData",t),new i(t)}};var pc=require("@alphafi/alphafi-sdk");var Gn=class i extends C{constructor(t){super(t);this.data=t}txType;txSubType;async build(t){let{account:n}=t,{withdrawFromLocked:o,xTokensAmount:a}=this.data;return await(0,pc.withdrawAlphaTxb)(a,o,n.address)}static fromData(t){return console.log("WithdrawAlphaIntention.fromData",t),new i(t)}};var Qn=class{application="alphafi";supportSDK="@mysten/sui";async deserialize(e){let{transaction:t,suiClient:n,account:o}=e,a=await n.devInspectTransactionBlock({sender:t.getData().sender,transactionBlock:t});console.log("AlphaFiHelper Sim result - ",a);let l=new $n(t,a).decode();return{txType:dc.TransactionType.Other,txSubType:l.type,intentionData:l.intentionData}}async build(e){let{account:t}=e;console.log("AlphaFi build transaction type",e.txSubType);let n;switch(e.txSubType){case"depositSingleAsset":n=Xn.fromData(e.intentionData);break;case"depositDoubleAsset":n=Hn.fromData(e.intentionData);break;case"withdraw":n=zn.fromData(e.intentionData);break;case"withdrawAlpha":n=Gn.fromData(e.intentionData);break;case"claimReward":n=Vn.fromData(e.intentionData);break;default:throw new Error("not implemented")}return n.build({account:t})}};var Lc=require("@msafe/sui3-utils");var Lt=require("@msafe/sui3-utils"),Jn=require("@mysten/sui/bcs"),Yn=require("bucket-protocol-sdk");var Zn=class{constructor(e){this.transaction=e}decode(){if(this.isSBUCKDepositTransaction())return this.decodeSBUCKDeposit();if(this.isSBUCKUnstakeTransaction())return this.decodeSBUCKUnstake();if(this.isSBUCKWithdrawTransaction())return this.decodeSBUCKWithdraw();if(this.isSBUCKClaimTransaction())return this.decodeSBUCKClaim();if(this.isLockedClaimTransaction())return this.decodeLockedClaim();if(this.isBorrowTransaction())return this.decodeBorrow();if(this.isRepayTransaction())return this.decodeRepay();if(this.isWithdrawTransaction())return this.decodeWithdraw();if(this.isCloseTransaction())return this.decodeClose();if(this.isTankDepositTransaction())return this.decodeTankDeposit();if(this.isTankWithdrawTransaction())return this.decodeTankWithdraw();if(this.isTankClaimTransaction())return this.decodeTankClaim();if(this.isPsmTransaction())return this.decodePsm();throw new Error("Unknown transaction type")}get commands(){return this.transaction.getData().commands}get inputs(){return this.transaction.getData().inputs}getMoveCallCommand(e){return this.commands.find(t=>t.$kind==="MoveCall"&&t.MoveCall.function===e)}getMoveCallModuleCommand(e,t){return this.commands.find(n=>n.$kind==="MoveCall"&&n.MoveCall.module===e&&n.MoveCall.function===t)}getMoveCallPackageModuleCommand(e,t,n){return this.commands.find(o=>o.$kind==="MoveCall"&&o.MoveCall.package===e&&o.MoveCall.module===t&&o.MoveCall.function===n)}getMoveCallModuleCommands(e,t){return this.commands.filter(n=>n.$kind==="MoveCall"&&n.MoveCall.module===e&&n.MoveCall.function===t)}getSplitCoinsCommands(){return this.commands.filter(e=>e.$kind==="SplitCoins")}getTransferCommands(){return this.commands.filter(e=>e.$kind==="TransferObjects")}isPsmTransaction(){return!!this.getMoveCallCommand("charge_reservoir")||!!this.getMoveCallCommand("discharge_reservoir")}isStrapNewTransaction(){return!!this.getMoveCallModuleCommand("strap","new")}isBorrowTransaction(){return!!this.getMoveCallModuleCommand("bucket_operations","high_top_up")||!!this.getMoveCallModuleCommand("bucket_operations","high_borrow")||!!this.getMoveCallModuleCommand("bucket_operations","high_borrow_with_strap")}isRepayTransaction(){return!!this.getMoveCallModuleCommand("bucket_operations","fully_repay")||!!this.getMoveCallModuleCommand("bucket_operations","fully_repay_with_strap")||!!this.getMoveCallModuleCommand("bucket_operations","repay_and_withdraw")||!!this.getMoveCallModuleCommand("bucket_operations","repay_and_withdraw_with_strap")}isWithdrawTransaction(){return!!this.getMoveCallModuleCommand("buck","withdraw")||!!this.getMoveCallModuleCommand("buck","withdraw_with_strap")}isCloseTransaction(){return!!this.getMoveCallModuleCommand("bucket_operations","destroy_empty_strap")}isTankDepositTransaction(){return!!this.getMoveCallModuleCommand("tank_operations","deposit")}isTankWithdrawTransaction(){return!!this.getMoveCallModuleCommand("tank_operations","withdraw")}isTankClaimTransaction(){return!!this.getMoveCallModuleCommand("tank_operations","claim")}isSBUCKDepositTransaction(){return!!this.getMoveCallModuleCommand("buck","buck_to_sbuck")}isSBUCKWithdrawTransaction(){return!!this.getMoveCallModuleCommand("buck","sbuck_to_buck")}isSBUCKStakeTransaction(){return!!this.getMoveCallPackageModuleCommand(Yn.SBUCK_FOUNTAIN_PACKAGE_ID,"fountain_core","stake")}isSBUCKUnstakeTransaction(){return!!this.getMoveCallPackageModuleCommand(Yn.SBUCK_FOUNTAIN_PACKAGE_ID,"fountain_core","force_unstake")}isSBUCKClaimTransaction(){return!!this.getMoveCallPackageModuleCommand(Yn.SBUCK_FOUNTAIN_PACKAGE_ID,"fountain_core","claim")}isLockedClaimTransaction(){return!!this.getMoveCallModuleCommand("proof_rule","claim")||!!this.getMoveCallModuleCommand("lst_proof_rule","claim")}isLstUnlockTransaction(){return!!this.getMoveCallModuleCommand("lst_proof_rule","unlock")}decodePsm(){let e,t,n="0",o=this.getSplitCoinsCommands()[0].SplitCoins.amounts[0];return o.$kind==="Input"&&(n=this.getPureInputU64(o.Input)),this.getMoveCallCommand("charge_reservoir")?([e]=this.getMoveCallCommand("charge_reservoir").MoveCall.typeArguments,t=!1):([e]=this.getMoveCallCommand("discharge_reservoir").MoveCall.typeArguments,t=!0),console.log("Decoder.decodePsm",e,n,t),{txType:Lt.TransactionType.Other,type:"psm",intentionData:{coinType:e,amount:n,buckToCoin:t}}}decodeBorrow(){let e="",t="0",n,o=this.getStrapId(),a="0",c=this.getSplitCoinsCommands()[0].SplitCoins.amounts[0];if(c.$kind==="Input"&&(a=this.getPureInputU64(c.Input)),this.getMoveCallCommand("high_top_up")){let l=this.getMoveCallCommand("high_top_up").MoveCall;[e]=l.typeArguments;let d=l.arguments[1];d.$kind==="Input"&&(t=this.getPureInputU64(d.Input));let b=l.arguments[3];if(b.$kind==="Input"){let I=this.getPureAddresses(b.Input);I.length===1&&([n]=I)}}else if(this.getMoveCallCommand("high_borrow")){let l=this.getMoveCallCommand("high_borrow").MoveCall;[e]=l.typeArguments;let d=l.arguments[4];d.$kind==="Input"&&(t=this.getPureInputU64(d.Input));let b=l.arguments[5];if(b.$kind==="Input"){let I=this.getPureAddresses(b.Input);I.length===1&&([n]=I)}}else if(this.getMoveCallCommand("high_borrow_with_strap")){let l=this.getMoveCallCommand("high_borrow_with_strap").MoveCall;[e]=l.typeArguments;let d=l.arguments[5];d.$kind==="Input"&&(t=this.getPureInputU64(d.Input));let b=l.arguments[6];if(b.$kind==="Input"){let I=this.getPureAddresses(b.Input);I.length===1&&([n]=I)}}return{txType:Lt.TransactionType.Other,type:"borrow",intentionData:{collateralType:e,collateralAmount:a,borrowAmount:t,insertionPlace:n,strapId:o}}}decodeRepay(){let e="",t="0",n="0",a,c=this.getStrapId();if(this.getMoveCallCommand("fully_repay"))[e]=this.getMoveCallCommand("fully_repay").MoveCall.typeArguments;else if(this.getMoveCallCommand("fully_repay_with_strap"))[e]=this.getMoveCallCommand("fully_repay_with_strap").MoveCall.typeArguments;else if(this.getMoveCallCommand("repay_and_withdraw")){let l=this.getMoveCallCommand("repay_and_withdraw").MoveCall;[e]=l.typeArguments;let d=l.arguments[4];d.$kind==="Input"&&(n=this.getPureInputU64(d.Input));let b=l.arguments[5];if(b.$kind==="Input"){let w=this.getPureAddresses(b.Input);w.length===1&&([a]=w)}let I=this.getSplitCoinsCommands()[0].SplitCoins.amounts[0];I.$kind==="Input"&&(t=this.getPureInputU64(I.Input))}else if(this.getMoveCallCommand("repay_and_withdraw_with_strap")){let l=this.getMoveCallCommand("repay_and_withdraw_with_strap").MoveCall;[e]=l.typeArguments;let d=l.arguments[5];d.$kind==="Input"&&(n=this.getPureInputU64(d.Input));let b=l.arguments[6];if(b.$kind==="Input"){let w=this.getPureAddresses(b.Input);w.length===1&&([a]=w)}let I=this.getSplitCoinsCommands()[0].SplitCoins.amounts[0];I.$kind==="Input"&&(t=this.getPureInputU64(I.Input))}return{txType:Lt.TransactionType.Other,type:"repay",intentionData:{collateralType:e,repayAmount:t,withdrawAmount:n,isSurplus:!1,insertionPlace:a,strapId:c}}}decodeWithdraw(){let e="",t="0",n,o=this.getStrapId();if(this.getMoveCallCommand("withdraw_with_strap")){let a=this.getMoveCallCommand("withdraw_with_strap").MoveCall;[e]=a.typeArguments;let c=a.arguments[4];c.$kind==="Input"&&(t=this.getPureInputU64(c.Input));let l=a.arguments[5];if(l.$kind==="Input"){let d=this.getPureAddresses(l.Input);d.length===1&&([n]=d)}}else if(this.getMoveCallCommand("withdraw")){let a=this.getMoveCallCommand("withdraw").MoveCall;[e]=a.typeArguments;let c=a.arguments[3];c.$kind==="Input"&&(t=this.getPureInputU64(c.Input));let l=a.arguments[4];if(l.$kind==="Input"){let d=this.getPureAddresses(l.Input);d.length===1&&([n]=d)}}return{txType:Lt.TransactionType.Other,type:"withdraw",intentionData:{collateralType:e,withdrawAmount:t,insertionPlace:n,strapId:o}}}decodeClose(){let e="",t=this.getStrapId();return this.getMoveCallCommand("destroy_empty_strap")&&([e]=this.getMoveCallCommand("destroy_empty_strap").MoveCall.typeArguments),{txType:Lt.TransactionType.Other,type:"close",intentionData:{collateralType:e,strapId:t}}}decodeSBUCKDeposit(){let t=this.getMoveCallCommand("into_balance").MoveCall.typeArguments[0],n="0",a=this.getSplitCoinsCommands()[0].SplitCoins.amounts[0];a.$kind==="Input"&&(n=this.getPureInputU64(a.Input));let c=this.isSBUCKStakeTransaction();return console.log("Decoder.decodeSBUCKDeposit",t,n,c),{txType:Lt.TransactionType.Other,type:"sbuck-deposit",intentionData:{coinType:t,amount:n,isStake:c}}}decodeSBUCKUnstake(){let e="0",t=this.isSBUCKStakeTransaction();if(t){let d=this.getSplitCoinsCommands()[0].SplitCoins.amounts[0];d.$kind==="Input"&&(e=this.getPureInputU64(d.Input))}let n=[],o=this.getMoveCallModuleCommands("proof_rule","unlock");if(o.length>0)for(let l=0;l<o.length;l++){let d=o[l];n.push("")}else{let l=this.getMoveCallModuleCommands("fountain_core","force_unstake");for(let d=0;d<l.length;d++){let I=l[d].MoveCall.arguments[2];if(I.$kind==="Input"){let{objectId:w}=this.inputs[I.Input].UnresolvedObject;n.push(w)}}}let a=this.isSBUCKWithdrawTransaction(),c={stakeProofs:n,amount:e,isStake:t,toBuck:a};return console.log("Decoder.decodeSBUCKUnstake",c),{txType:Lt.TransactionType.Other,type:"sbuck-unstake",intentionData:c}}decodeSBUCKWithdraw(){let e="0",n=this.getSplitCoinsCommands()[0].SplitCoins.amounts[0];return n.$kind==="Input"&&(e=this.getPureInputU64(n.Input)),console.log("Decoder.SBUCKWithdraw",e),{txType:Lt.TransactionType.Other,type:"sbuck-withdraw",intentionData:{amount:e}}}decodeSBUCKClaim(){let e=[],t=this.getMoveCallModuleCommands("fountain_core","claim");for(let n=0;n<t.length;n++){let a=t[n].MoveCall.arguments[2];if(a.$kind==="Input"){let{objectId:c}=this.inputs[a.Input].UnresolvedObject;e.push(c)}}return console.log("Decoder.decodeSBUCKClaim",e),{txType:Lt.TransactionType.Other,type:"sbuck-claim",intentionData:{stakeProofs:e}}}decodeTankDeposit(){let e="0",n=this.getSplitCoinsCommands()[0].SplitCoins.amounts[0];n.$kind==="Input"&&(e=this.getPureInputU64(n.Input));let a=this.getMoveCallModuleCommand("tank_operations","deposit").MoveCall.typeArguments[0];return console.log("Decoder.decodeTankDeposit",a,e),{txType:Lt.TransactionType.Other,type:"tank-deposit",intentionData:{coinType:a,amount:e}}}decodeTankWithdraw(){let e=this.getMoveCallModuleCommand("tank_operations","withdraw").MoveCall,t=e.typeArguments[0],n="0",o=e.arguments[5];return o.$kind==="Input"&&(n=this.getPureInputU64(o.Input)),console.log("Decoder.decodeTankWithdraw",t,n),{txType:Lt.TransactionType.Other,type:"tank-withdraw",intentionData:{coinType:t,amount:n}}}decodeTankClaim(){let t=this.getMoveCallModuleCommand("tank_operations","claim").MoveCall.typeArguments[0];return console.log("Decoder.decodeTankClaim",t),{txType:Lt.TransactionType.Other,type:"tank-claim",intentionData:{coinType:t}}}decodeLockedClaim(){let e="",t=0,n=this.getMoveCallModuleCommands("proof_rule","claim");for(let a=0;a<n.length;a++)[e]=n[a].MoveCall.typeArguments,t++;let o=this.getMoveCallModuleCommands("lst_proof_rule","claim");for(let a=0;a<o.length;a++)[e]=o[a].MoveCall.typeArguments,t++;return console.log("Decoder.decodeLockedClaim",e,t),{txType:Lt.TransactionType.Other,type:"lock-claim",intentionData:{coinType:e,proofCount:t}}}getCoinInput(e){if(this.inputs[e].$kind!=="Object")throw new Error("not Object argument")}getStrapId(){let e;if(this.isStrapNewTransaction()?e="new":this.isLstUnlockTransaction()&&(e="locked"),!e){let t=this.getMoveCallModuleCommand("fountain","unstake");if(t){let n=t.MoveCall.arguments[2];n.$kind==="Input"&&(e=this.inputs[n.Input].UnresolvedObject.objectId)}}return e}getPureInputU64(e){let t=this.inputs[e];if(t.$kind!=="Pure")throw new Error("not pure argument");return Jn.bcs.U64.fromBase64(t.Pure.bytes)}getPureAddresses(e){let t=this.inputs[e];if(t.$kind!=="Pure")throw new Error("not pure argument");return Jn.bcs.vector(Jn.bcs.Address).fromBase64(t.Pure.bytes)}};var bc=require("@msafe/sui3-utils");var hc=require("@mysten/sui/transactions"),gc=require("bucket-protocol-sdk");var fc=require("bucket-protocol-sdk"),Pt=(i,e)=>{let t=i==="sui:mainnet"?"mainnet":"testnet";return new fc.BucketClient(t,e.address)};var yc=async(i,e,t)=>{let{coinType:n,amount:o,buckToCoin:a}=i,c=new hc.Transaction,l=Pt(t,e);return await(0,gc.buildPsmTx)(l,c,n,o,a,e.address),c};var to=class i extends C{constructor(t){super(t);this.data=t}txType=bc.TransactionType.Other;txSubType="psm";async build(t){let{account:n,network:o}=t;return await yc(this.data,n,o)}static fromData(t){return new i(t)}};var Cc=require("@msafe/sui3-utils");var pn=require("@mysten/sui/transactions"),se=require("bucket-protocol-sdk");var Sc=async(i,e,t)=>{let{collateralType:n,collateralAmount:o,borrowAmount:a,insertionPlace:c,strapId:l}=i,d=new pn.Transaction,b=Pt(t,e);return await(0,se.buildBorrowTx)(b,d,n,o,a,e.address,c,l),d},Tc=async(i,e,t)=>{let{collateralType:n,withdrawAmount:o,insertionPlace:a,strapId:c}=i,l=new pn.Transaction,d=Pt(t,e);return await(0,se.buildWithdrawTx)(d,l,n,o,e.address,a,c),l},Ic=async(i,e,t)=>{let{collateralType:n,repayAmount:o,withdrawAmount:a,isSurplus:c,insertionPlace:l,strapId:d}=i,b=new pn.Transaction,I=Pt(t,e);return await(0,se.buildRepayTx)(I,b,n,o,a,e.address,c,l,d),b},wc=async(i,e,t)=>{let{collateralType:n,recipient:o,strapId:a}=i,c=new pn.Transaction,l=Pt(t,e);return await(0,se.buildCloseTx)(l,c,n,o,a),c};var eo=class i extends C{constructor(t){super(t);this.data=t}txType=Cc.TransactionType.Other;txSubType="borrow";async build(t){let{account:n,network:o}=t;return await Sc(this.data,n,o)}static fromData(t){return new i(t)}};var kc=require("@msafe/sui3-utils");var no=class i extends C{constructor(t){super(t);this.data=t}txType=kc.TransactionType.Other;txSubType="repay";async build(t){let{account:n,network:o}=t;return await Ic(this.data,n,o)}static fromData(t){return new i(t)}};var xc=require("@msafe/sui3-utils");var oo=class i extends C{constructor(t){super(t);this.data=t}txType=xc.TransactionType.Other;txSubType="withdraw";async build(t){let{account:n,network:o}=t;return await Tc(this.data,n,o)}static fromData(t){return new i(t)}};var vc=require("@msafe/sui3-utils");var ao=class i extends C{constructor(t){super(t);this.data=t}txType=vc.TransactionType.Other;txSubType="close";async build(t){let{account:n,network:o}=t;return await wc(this.data,n,o)}static fromData(t){return new i(t)}};var fn=require("@msafe/sui3-utils");var dn=require("@mysten/sui/transactions"),ce=require("bucket-protocol-sdk");var Dc=async(i,e,t)=>{let{coinType:n,amount:o,isStake:a}=i,c=new dn.Transaction,l=Pt(t,e);return await(0,ce.buildSBUCKDepositTx)(l,c,n,o,e.address,a),c},Ac=async(i,e,t)=>{let{stakeProofs:n,amount:o,isStake:a,toBuck:c}=i,l=new dn.Transaction,d=Pt(t,e);return await(0,ce.buildSBUCKUnstakeTx)(d,l,n,o,e.address,a,c),l},Mc=async(i,e,t)=>{let{amount:n}=i,o=new dn.Transaction,a=Pt(t,e);return await(0,ce.buildSBUCKWithdrawTx)(a,o,n,e.address),o},Oc=async(i,e,t)=>{let{stakeProofs:n}=i,o=new dn.Transaction,a=Pt(t,e);return await(0,ce.buildSBUCKClaimTx)(a,o,n,e.address),o};var io=class i extends C{constructor(t){super(t);this.data=t}txType=fn.TransactionType.Other;txSubType="sbuck-deposit";async build(t){let{account:n,network:o}=t;return await Dc(this.data,n,o)}static fromData(t){return new i(t)}},ro=class i extends C{constructor(t){super(t);this.data=t}txType=fn.TransactionType.Other;txSubType="sbuck-unstake";async build(t){let{account:n,network:o}=t;return await Ac(this.data,n,o)}static fromData(t){return new i(t)}},so=class i extends C{constructor(t){super(t);this.data=t}txType=fn.TransactionType.Other;txSubType="sbuck-withdraw";async build(t){let{account:n,network:o}=t;return await Mc(this.data,n,o)}static fromData(t){return new i(t)}},co=class i extends C{constructor(t){super(t);this.data=t}txType=fn.TransactionType.Other;txSubType="sbuck-claim";async build(t){let{account:n,network:o}=t;return await Oc(this.data,n,o)}static fromData(t){return new i(t)}};var fo=require("@msafe/sui3-utils");var lo=require("@mysten/sui/transactions"),Fe=require("bucket-protocol-sdk");var Pc=async(i,e,t)=>{let{coinType:n,amount:o}=i,a=new lo.Transaction,c=Pt(t,e);return await(0,Fe.buildTankDepositTx)(c,a,n,o,e.address),a},Rc=async(i,e,t)=>{let{coinType:n,amount:o}=i,a=new lo.Transaction,c=Pt(t,e);return await(0,Fe.buildTankWithdrawTx)(c,a,n,o,e.address),a},Bc=async(i,e,t)=>{let{coinType:n}=i,o=new lo.Transaction,a=Pt(t,e);return await(0,Fe.buildTankClaimTx)(a,o,n,e.address),o};var Ec=require("@mysten/sui/transactions"),Nc=require("bucket-protocol-sdk");var Wc=async(i,e,t)=>{let{coinType:n,proofCount:o}=i,a=new Ec.Transaction,c=Pt(t,e);return await(0,Nc.buildLockedClaimTx)(c,a,n,o,e.address),a};var uo=class i extends C{constructor(t){super(t);this.data=t}txType=fo.TransactionType.Other;txSubType="tank-deposit";async build(t){let{account:n,network:o}=t;return await Pc(this.data,n,o)}static fromData(t){return new i(t)}},mo=class i extends C{constructor(t){super(t);this.data=t}txType=fo.TransactionType.Other;txSubType="tank-withdraw";async build(t){let{account:n,network:o}=t;return await Rc(this.data,n,o)}static fromData(t){return new i(t)}},po=class i extends C{constructor(t){super(t);this.data=t}txType=fo.TransactionType.Other;txSubType="tank-claim";async build(t){let{account:n,network:o}=t;return await Bc(this.data,n,o)}static fromData(t){return new i(t)}};var _c=require("@msafe/sui3-utils");var ho=class i extends C{constructor(t){super(t);this.data=t}txType=_c.TransactionType.Other;txSubType="lock-claim";async build(t){let{account:n,network:o}=t;return await Wc(this.data,n,o)}static fromData(t){return new i(t)}};var go=class{application="bucket";supportSDK="@mysten/sui";async deserialize(e){console.log("Bucket helper deserialize input: ",e);let{transaction:t}=e,o=new Zn(t).decode();return{txType:Lc.TransactionType.Other,txSubType:o.type,intentionData:o.intentionData}}async build(e){let{suiClient:t,account:n,network:o}=e,a;switch(e.txSubType){case"psm":a=to.fromData(e.intentionData);break;case"borrow":a=eo.fromData(e.intentionData);break;case"withdraw":a=oo.fromData(e.intentionData);break;case"repay":a=no.fromData(e.intentionData);break;case"close":a=ao.fromData(e.intentionData);break;case"tank-deposit":a=uo.fromData(e.intentionData);break;case"tank-withdraw":a=mo.fromData(e.intentionData);break;case"tank-claim":a=po.fromData(e.intentionData);break;case"sbuck-deposit":a=io.fromData(e.intentionData);break;case"sbuck-unstake":a=ro.fromData(e.intentionData);break;case"sbuck-withdraw":a=so.fromData(e.intentionData);break;case"sbuck-claim":a=co.fromData(e.intentionData);break;case"lock-claim":a=ho.fromData(e.intentionData);break;default:throw new Error("not implemented")}return a.build({suiClient:t,account:n,network:o})}};var Kl=require("@msafe/sui3-utils");var Gc=require("@msafe/sui3-utils");var yo=require("@cetusprotocol/aggregator-sdk"),jc=require("@cetusprotocol/farms-sdk"),Uc=require("@cetusprotocol/sui-clmm-sdk"),qc=require("@cetusprotocol/vaults-sdk"),Fc=require("@cetusprotocol/xcetus-sdk"),Re=require("@mysten/sui/client"),ae=(i,e)=>{let t=Uc.CetusClmmSDK.createSDK({env:"mainnet",sui_client:new Re.SuiClient({url:(0,Re.getFullnodeUrl)("mainnet")})});return t.setSenderAddress(e.address),t},qt=(i,e)=>{let t=jc.CetusFarmsSDK.createSDK({env:"mainnet",sui_client:new Re.SuiClient({url:(0,Re.getFullnodeUrl)("mainnet")})});return t.setSenderAddress(e.address),t},Xp="https://api-sui.cetus.zone/router_v2/find_routes",Kc=(i,e)=>{let t=new Re.SuiClient({url:"https://fullnode.mainnet.sui.io/"});return new yo.AggregatorClient({endpoint:Xp,signer:e.address,client:t,env:yo.Env.Mainnet})},hn=(i,e)=>{let t=qc.CetusVaultsSDK.createSDK({env:"mainnet"});return t.setSenderAddress(e.address),t},Ke=(i,e)=>{let t=Fc.CetusXcetusSDK.createSDK({env:"mainnet"});return t.setSenderAddress(e.address),t};var $c=async(i,e,t)=>await ae(t,e).Position.createAddLiquidityFixTokenPayload(i?.parameter,i?.gasEstimateArg),Vc=async(i,e,t)=>await ae(t,e).Position.createAddLiquidityFixTokenPayload(i?.parameter,i?.gasEstimateArg),Hc=async(i,e,t)=>await ae(t,e).Position.closePositionPayload(i),Xc=async(i,e,t)=>await ae(t,e).Position.removeLiquidityPayload(i),zc=async(i,e,t)=>await ae(t,e).Rewarder.collectRewarderPayload(i);var bo=class i extends C{constructor(t){super(t);this.data=t}txType=Gc.TransactionType.Other;txSubType="OpenAndAddLiquidity";async build(t){let{account:n,network:o}=t,{txbParams:a}=this.data;return await $c(a,n,o)}static fromData(t){return new i(t)}};var Qc=require("@msafe/sui3-utils");var So=class i extends C{constructor(t){super(t);this.data=t}txType=Qc.TransactionType.Other;txSubType="ClaimFeeAndMining";async build(t){let{account:n,network:o}=t,{txbParams:a}=this.data;return await zc(a,n,o)}static fromData(t){return new i(t)}};var Jc=require("@msafe/sui3-utils");var To=class i extends C{constructor(t){super(t);this.data=t}txType=Jc.TransactionType.Other;txSubType="DecreaseLiquidity";async build(t){let{account:n,network:o}=t,{txbParams:a}=this.data;return await Xc(a,n,o)}static fromData(t){return new i(t)}};var sl=require("@msafe/sui3-utils");var Yc=async(i,e,t)=>await qt(t,e).Farms.openPositionAddLiquidityStakePayload(i),Zc=async(i,e,t)=>await qt(t,e).Farms.addLiquidityFixCoinPayload(i),tl=async(i,e,t)=>await qt(t,e).Farms.removeLiquidityPayload(i),el=async(i,e,t)=>await qt(t,e).Farms.removeLiquidityPayload(i),nl=async(i,e,t)=>await qt(t,e).Farms.claimFeeAndClmmReward(i),ol=async(i,e,t)=>await qt(t,e).Farms.harvestPayload(i),al=async(i,e,t)=>{let n=qt(t,e),o=Object.values(i);return await n.Farms.batchHarvestPayload(o)},il=async(i,e,t)=>await qt(t,e).Farms.depositPayload(i),rl=async(i,e,t)=>await qt(t,e).Farms.withdrawPayload(i);var Io=class i extends C{constructor(t){super(t);this.data=t}txType=sl.TransactionType.Other;txSubType="FarmingOpenAndAddLiquidity";async build(t){let{account:n,network:o}=t,{txbParams:a}=this.data;return await Yc(a,n,o)}static fromData(t){return new i(t)}};var cl=require("@msafe/sui3-utils");var wo=class i extends C{constructor(t){super(t);this.data=t}txType=cl.TransactionType.Other;txSubType="FarmingBatchHarvest";async build(t){let{account:n,network:o}=t,{txbParams:a}=this.data;return await al(a,n,o)}static fromData(t){return new i(t)}};var ll=require("@msafe/sui3-utils");var Co=class i extends C{constructor(t){super(t);this.data=t}txType=ll.TransactionType.Other;txSubType="FarmingClaimFeeAndReward";async build(t){let{account:n,network:o}=t,{txbParams:a}=this.data;return await nl(a,n,o)}static fromData(t){return new i(t)}};var ul=require("@msafe/sui3-utils");var ko=class i extends C{constructor(t){super(t);this.data=t}txType=ul.TransactionType.Other;txSubType="FarmingDecreaseLiquidity";async build(t){let{account:n,network:o}=t,{txbParams:a}=this.data;return await tl(a,n,o)}static fromData(t){return new i(t)}};var ml=require("@msafe/sui3-utils");var xo=class i extends C{constructor(t){super(t);this.data=t}txType=ml.TransactionType.Other;txSubType="FarmingHarvest";async build(t){let{account:n,network:o}=t,{txbParams:a}=this.data;return await ol(a,n,o)}static fromData(t){return new i(t)}};var pl=require("@msafe/sui3-utils");var vo=class i extends C{constructor(t){super(t);this.data=t}txType=pl.TransactionType.Other;txSubType="FarmingIncreaseLiquidity";async build(t){let{account:n,network:o}=t,{txbParams:a}=this.data;return await Zc(a,n,o)}static fromData(t){return new i(t)}};var dl=require("@msafe/sui3-utils");var Do=class i extends C{constructor(t){super(t);this.data=t}txType=dl.TransactionType.Other;txSubType="FarmingRemoveLiquidity";async build(t){let{account:n,network:o}=t,{txbParams:a}=this.data;return await el(a,n,o)}static fromData(t){return new i(t)}};var fl=require("@msafe/sui3-utils");var Ao=class i extends C{constructor(t){super(t);this.data=t}txType=fl.TransactionType.Other;txSubType="FarmingStake";async build(t){let{account:n,network:o}=t,{txbParams:a}=this.data;return await il(a,n,o)}static fromData(t){return new i(t)}};var hl=require("@msafe/sui3-utils");var Mo=class i extends C{constructor(t){super(t);this.data=t}txType=hl.TransactionType.Other;txSubType="FarmingUnstake";async build(t){let{account:n,network:o}=t,{txbParams:a}=this.data;return await rl(a,n,o)}static fromData(t){return new i(t)}};var gl=require("@msafe/sui3-utils");var Oo=class i extends C{constructor(t){super(t);this.data=t}txType=gl.TransactionType.Other;txSubType="IncreaseLiquidity";async build(t){let{account:n,network:o}=t,{txbParams:a}=this.data;return await Vc(a,n,o)}static fromData(t){return new i(t)}};var Sl=require("@msafe/sui3-utils");var gn=require("@mysten/sui/transactions"),Po=Ut(require("haedal-vault-sdk"));var zp=async(i,e,t)=>{let n=hn(t,e),o=new gn.Transaction;return o.setSender(e.address),n.Vest.buildRedeemPayload(i.params,o),o},Gp=async(i,e,t)=>{let n=new Po.default(Po.vaults_mainnet);n.senderAddress=e.address;let o=new gn.Transaction;return o.setSender(e.address),await n?.Vest.buildRedeemPayload(i.params,o),o},yl=(i,e,t)=>{let n=ae(t,e),o=new gn.Transaction;return n?.Vest.buildRedeemPayload(i.params,o),o},Qp=async(i,e,t)=>{let n=ae(t,e),o=qt(t,e),a=new gn.Transaction,c=await o.Farms.withdrawReturnPayload(i.withdrawParams,a);return n.Vest.buildRedeemPayload(i.redeemParms.map(l=>({...l,clmm_position_id:c})),a),o.Farms.depositPayload({...i.depositParams,clmm_position_id:c},a),a},bl=async(i,e,t)=>i.type==="clmm"?yl(i,e,t):i.type==="farms"?Qp(i,e,t):i.type==="vaults"?zp(i,e,t):i.type==="haedalVaults"?Gp(i,e,t):yl(i,e,t);var Ro=class i extends C{constructor(t){super(t);this.data=t}txType=Sl.TransactionType.Other;txSubType="PosVestingRedeem";async build(t){let{account:n,network:o}=t,{txbParams:a}=this.data;return await bl(a,n,o)}static fromData(t){return new i(t)}};var Tl=require("@msafe/sui3-utils");var Bo=class i extends C{constructor(t){super(t);this.data=t}txType=Tl.TransactionType.Other;txSubType="RemoveLiquidity";async build(t){let{account:n,network:o}=t,{txbParams:a}=this.data;return await Hc(a,n,o)}static fromData(t){return new i(t)}};var kl=require("@msafe/sui3-utils");var Il=require("@cetusprotocol/aggregator-sdk"),wl=require("@mysten/sui/transactions");var Cl=async(i,e,t)=>{let n=Kc(t,e),o=new wl.Transaction;return await n.fastRouterSwap({...i,routers:(0,Il.restituteMsafeFastRouterSwapParams)(i.routers),txb:o}),o};var Eo=class i extends C{constructor(t){super(t);this.data=t}txType=kl.TransactionType.Other;txSubType="AggregatorSwap";async build(t){let{account:n,network:o}=t,{txbParams:a}=this.data;return await Cl(a,n,o)}static fromData(t){return new i(t)}};var Dl=require("@msafe/sui3-utils");var Hr=require("@mysten/sui/transactions");var xl=async(i,e,t)=>{let n=hn(t,e),o=new Hr.Transaction;return o.setSender(e.address),await n.Vaults.deposit(i,o),o},vl=async(i,e,t)=>{let n=hn(t,e),o=new Hr.Transaction;return await n.Vaults.withdraw(i,o),o};var No=class i extends C{constructor(t){super(t);this.data=t}txType=Dl.TransactionType.Other;txSubType="AddVaultsPosition";async build(t){let{account:n,network:o}=t,{txbParams:a}=this.data;return await xl(a,n,o)}static fromData(t){return new i(t)}};var Al=require("@msafe/sui3-utils");var Wo=class i extends C{constructor(t){super(t);this.data=t}txType=Al.TransactionType.Other;txSubType="RemoveVaultsPosition";async build(t){let{account:n,network:o}=t,{txbParams:a}=this.data;return await vl(a,n,o)}static fromData(t){return new i(t)}};var Rl=require("@msafe/sui3-utils");var Ol=require("@mysten/sui/transactions"),Ml={package_id:"0x355714a1eeb7ab1d80902da6c92001170cda1212edf524c32aa308a3ac177c31",published_at:"0x355714a1eeb7ab1d80902da6c92001170cda1212edf524c32aa308a3ac177c31",cetus_coin_type:"0x06864a6f921804860930db6ddbe2e16acdf8504495ea7481637a1c8b9a8fe54b::cetus::CETUS"},Pl=async(i,e,t)=>{console.log("getVestingRedeemTxb txbParams: ",i),console.log("getVestingRedeemTxb account: ",e),console.log("getVestingRedeemTxb network: ",t);let{pool:n,nftId:o,periods:a,CLOCK_ADDRESS:c}=i,l=new Ol.Transaction;return a.forEach(d=>{l.moveCall({target:`${Ml.published_at}::router::redeem`,typeArguments:[Ml.cetus_coin_type],arguments:[l.object(n),l.object(o),l.pure(d),l.object(c)]})}),l};var _o=class i extends C{constructor(t){super(t);this.data=t}txType=Rl.TransactionType.Other;txSubType="VestingRedeem";async build(t){let{account:n,network:o}=t,{txbParams:a}=this.data;return await Pl(a,n,o)}static fromData(t){return new i(t)}};var Ll=require("@msafe/sui3-utils");var Bl=async(i,e,t)=>await Ke(t,e).XCetusModule.convertPayload(i),El=async(i,e,t)=>await Ke(t,e).XCetusModule.redeemLockPayload(i),Nl=async(i,e,t)=>await Ke(t,e).XCetusModule.redeemDividendV3Payload(i.veNftId,i.rewardList),Wl=async(i,e,t)=>await Ke(t,e).XCetusModule.cancelRedeemPayload(i),_l=async(i,e,t)=>await Ke(t,e).XCetusModule.redeemPayload(i);var Lo=class i extends C{constructor(t){super(t);this.data=t}txType=Ll.TransactionType.Other;txSubType="xCETUSCancelRedeem";async build(t){let{account:n,network:o}=t,{txbParams:a}=this.data;return await Wl(a,n,o)}static fromData(t){return new i(t)}};var jl=require("@msafe/sui3-utils");var jo=class i extends C{constructor(t){super(t);this.data=t}txType=jl.TransactionType.Other;txSubType="xCETUSClaimStakingRwewards";async build(t){let{account:n,network:o}=t,{txbParams:a}=this.data;return await Nl(a,n,o)}static fromData(t){return new i(t)}};var Ul=require("@msafe/sui3-utils");var Uo=class i extends C{constructor(t){super(t);this.data=t}txType=Ul.TransactionType.Other;txSubType="xCETUSConvert";async build(t){let{account:n,network:o}=t,{txbParams:a}=this.data;return await Bl(a,n,o)}static fromData(t){return new i(t)}};var ql=require("@msafe/sui3-utils");var qo=class i extends C{constructor(t){super(t);this.data=t}txType=ql.TransactionType.Other;txSubType="xCETUSRedeem";async build(t){let{account:n,network:o}=t,{txbParams:a}=this.data;return await _l(a,n,o)}static fromData(t){return new i(t)}};var Fl=require("@msafe/sui3-utils");var Fo=class i extends C{constructor(t){super(t);this.data=t}txType=Fl.TransactionType.Other;txSubType="xCETUSRedeemLock";async build(t){let{account:n,network:o}=t,{txbParams:a}=this.data;return await El(a,n,o)}static fromData(t){return new i(t)}};var Ko=class{application="cetus";supportSDK="@mysten/sui";async deserialize(e){console.log("Cetus helper deserialize input: ",e);let{txbParams:t,action:n}=e;return{txType:Kl.TransactionType.Other,txSubType:n,intentionData:{txbParams:{...t},action:n}}}async build(e){let{suiClient:t,account:n,network:o}=e,a;switch(e.txSubType){case"OpenAndAddLiquidity":a=bo.fromData(e.intentionData);break;case"IncreaseLiquidity":a=Oo.fromData(e.intentionData);break;case"DecreaseLiquidity":a=To.fromData(e.intentionData);break;case"RemoveLiquidity":a=Bo.fromData(e.intentionData);break;case"ClaimFeeAndMining":a=So.fromData(e.intentionData);break;case"FarmingOpenAndAddLiquidity":a=Io.fromData(e.intentionData);break;case"FarmingIncreaseLiquidity":a=vo.fromData(e.intentionData);break;case"FarmingDecreaseLiquidity":a=ko.fromData(e.intentionData);break;case"FarmingRemoveLiquidity":a=Do.fromData(e.intentionData);break;case"FarmingClaimFeeAndReward":a=Co.fromData(e.intentionData);break;case"FarmingHarvest":a=xo.fromData(e.intentionData);break;case"FarmingBatchHarvest":a=wo.fromData(e.intentionData);break;case"FarmingStake":a=Ao.fromData(e.intentionData);break;case"FarmingUnstake":a=Mo.fromData(e.intentionData);break;case"xCETUSConvert":a=Uo.fromData(e.intentionData);break;case"xCETUSRedeemLock":a=Fo.fromData(e.intentionData);break;case"xCETUSClaimStakingRwewards":a=jo.fromData(e.intentionData);break;case"xCETUSCancelRedeem":a=Lo.fromData(e.intentionData);break;case"xCETUSRedeem":a=qo.fromData(e.intentionData);break;case"VestingRedeem":a=_o.fromData(e.intentionData);break;case"AggregatorSwap":a=Eo.fromData(e.intentionData);break;case"AddVaultsPosition":a=No.fromData(e.intentionData);break;case"RemoveVaultsPosition":a=Wo.fromData(e.intentionData);break;case"PosVestingRedeem":a=Ro.fromData(e.intentionData);break;default:throw new Error("not implemented")}return a.build({suiClient:t,account:n,network:o})}};var pu=require("@msafe/sui3-utils");var $l=Ut(require("sort-keys-recursive")),_=class{constructor(e){this.data=e}serialize(){return JSON.stringify((0,$l.default)(this.data))}};var yn=require("@mysten/sui.js/client");var Xr={};Vr(Xr,{contractId:()=>Zp,default:()=>ad,feeObjId:()=>nd,roleObjId:()=>td,status:()=>Yp,transaction:()=>Jp,upgradeCapObjId:()=>od,vaultObjId:()=>ed});var Jp="DiBZq4UmVVYiRL6ZJmFKYoHcxtxqrhsCXSkFyT7wUr3j",Yp="success",Zp="0x81c960dc653975fbd0072deca8afb92d322898c911622898ba1b2e3ad0c4bd8d",td="0xc6ec0bdee0bb59a72077e9acd2f42457043cf47080b3d3fad4d39abf28bba63a",ed="0xbc4021387fbac149119fd24e92be9e58f745774292f3a2a12e2ac6daf5363e1d",nd="0x4178f63970fe2daeb256dc5730ad172e82b3e8eb45f31b33e0daae72cd35e1e1",od="0xe1e9aa7d222d151bfe6dd83358b0d7fdcb11260f710800cfaf7ccc1b1e245115",ad={transaction:Jp,status:Yp,contractId:Zp,roleObjId:td,vaultObjId:ed,feeObjId:nd,upgradeCapObjId:od};var zr={};Vr(zr,{contractId:()=>sd,default:()=>pd,feeObjId:()=>ud,roleObjId:()=>cd,status:()=>rd,transaction:()=>id,upgradeCapObjId:()=>md,vaultObjId:()=>ld});var id="855FNDV8o8Z3fWULPnQo9qdhLJpsg7wZrkCpNyfw9KfB",rd="success",sd="0xc357c3985e8fb875d6b37141497af660779aa1bab0ec489b2213efd74067d1fa",cd="0x5ab49bdf9fd1413e328ef242b3f8d83dde791b38a0b627bfc87fb25c010d34f1",ld="0xb483558770d8eb26007f193b75db40f0a45f2e36863a687625885d4de6993378",ud="0x48453fc4d7cde3fe35aad89e5dfb496608a6a55ea529a1c0274681a808627f94",md="0x34279779a0d0d36bd5044b04830d607fa1b0ecf316548c8ac3a44151e4f1a42a",pd={transaction:id,status:rd,contractId:sd,roleObjId:cd,vaultObjId:ld,feeObjId:ud,upgradeCapObjId:md};var dd=(0,yn.getFullnodeUrl)("testnet"),fd=(0,yn.getFullnodeUrl)("testnet"),hd=(0,yn.getFullnodeUrl)("mainnet"),gd=(0,yn.getFullnodeUrl)("mainnet"),yd="https://bc3p6l5unl.execute-api.us-west-1.amazonaws.com/prod",bd="https://rolsbkota7.execute-api.us-west-1.amazonaws.com/prod",Sd="https://6p6mkx33ne.execute-api.us-west-1.amazonaws.com/prod",Td="https://xrae3mrjv5.execute-api.us-west-1.amazonaws.com/prod",Vl=Xr,Hl=zr,Id=new Map([["dev",{env:"dev",rpc:{url:dd},backend:{url:yd},contract:Vl}],["stg",{env:"stg",rpc:{url:fd},backend:{url:bd},contract:Vl}],["prev",{env:"prev",rpc:{url:hd},backend:{url:Sd},contract:Hl}],["prod",{env:"prod",rpc:{url:gd},backend:{url:Td},contract:Hl}]]);function Xl(i,e){let t=Id.get(i);if(!t)throw new Error(`Env not supported: ${i}`);return e&&e.rpc&&(t.rpc=e.rpc),e&&e.backend&&(t.backend=e.backend),e&&e.contract&&(t.contract=e.contract),t}var zl=require("@mysten/sui.js/client");var L=class extends Error{mpayErrorCode;context;constructor(e,t,n={}){let{cause:o,context:a}=n;o?super(`[MPay] ${t}: ${o}`):super(`[MPay] ${t}`),this.mpayErrorCode=e,this.context=a}};var $o=class extends L{constructor(){super(11,"Backend is not specified")}};var Vo=class extends L{constructor(){super(1,"Wallet not connected")}};var ie=Ut(require("axios"));var $e=class extends L{constructor(e,t){super(10,e,{context:t})}};var Ho=class i{constructor(e){this.apiURL=e}static parseResponseData(e){if(e instanceof ie.AxiosError)throw new $e(e.response?.statusText);if(e.status===200){if(e.data.success)return e.data.data;throw new $e(e.data.code)}throw new $e(e.status.toString())}async getIncomingStreams(e,t){let n=await ie.default.post(`${this.apiURL}/stream`,{recipient:e,...t});return i.parseResponseData(n)}async getOutgoingStreams(e,t){let n=await ie.default.post(`${this.apiURL}/stream`,{sender:e,...t});return i.parseResponseData(n)}async getStreamHistory(e){let t=await ie.default.post(`${this.apiURL}/stream-events`,e),n=i.parseResponseData(t);return n.data.forEach(o=>{let a=o;return a.data.type==="create_stream"?a.data.balance=BigInt(a.data.balance):a.data.type==="cancel_stream"?a.data.withdrawAmount=BigInt(a.data.withdrawAmount):a.data.type==="claim"||a.data.type==="auto_claim"?a.data.claimAmount=BigInt(a.data.claimAmount):a.data.type==="set_auto_claim"&&(a.data.enabled=!!a.data.enabled),a.createdAt=new Date(a.createdAt),a}),n}async getAllCoinTypes(e){let t=await ie.default.post(`${this.apiURL}/stream-info`,{address:e});return i.parseResponseData(t)}async getAllRecipients(e,t){let n=await ie.default.post(`${this.apiURL}/stream-info`,{sender:e,status:t});return i.parseResponseData(n)}async getAllSenders(e,t){let n=await ie.default.post(`${this.apiURL}/stream-info`,{recipient:e,status:t});return i.parseResponseData(n)}};var Ve=class i{signer;suiClient;envConfig;_backend;constructor(e){this.envConfig=e,this.suiClient=new zl.SuiClient({url:e.rpc.url}),e.backend&&(this._backend=new Ho(e.backend.url))}static new(e,t){let n=Xl(e,t);return new i(n)}get walletType(){return this.wallet?this.wallet.type:"disconnected"}get backend(){if(!this._backend)throw new $o;return this._backend}set backend(e){this._backend=e}connectWallet(e){this.signer=e}disconnect(){this.signer=void 0}get wallet(){if(!this.signer)throw new Vo;return this.signer}async walletAddress(){return this.wallet.address()}};var Ee=require("@mysten/sui.js/utils");var Cn=require("@mysten/sui.js/transactions");var Zr=require("@mysten/sui.js/transactions"),wn=require("@mysten/sui.js/utils");var Gr=50n,Xo=10000n,Gl=25n,Qr=100000000n;var Jt=class{constructor(e){this.object=e}moveArg(e){return e.object(this.object)}},bn=class{constructor(e){this.objects=e}moveArgs(e){return e.makeMoveVec({objects:this.objects.map(t=>e.object(t))})}},me=class i{constructor(e){this.result=e;return new Proxy(this,{set(){throw new Error("The transaction result is a proxy, and does not support setting properties directly")},get(t,n){if(n in t)return Reflect.get(t,n);let o=c=>new i(t.result[c]);if(n===Symbol.iterator)return function*(){let c=0;for(;;)yield o(c),c++};if(typeof n=="symbol")return;let a=parseInt(n,10);if(!(Number.isNaN(a)||a<0))return o(a)}})}moveArg(){return this.result}};var Jr=require("buffer"),Ql=require("@mysten/sui.js/utils");var Sn=class extends L{constructor(e,t){super(3,e,{context:t})}};var zo=class{constructor(e){this.results=e}callResult(e){return this.results.results[e]}returnValue(e,t){return e.returnValues[t]}getValue(e=0,t=0){let n=this.callResult(e);return this.returnValue(n,t)}getAddress(e=0,t=0){let[n,o]=this.getValue(e,t);if(o!=="address")throw new Sn("Invalid contract return type.",{ctx:{expectType:"address",gotType:o}});return(0,Ql.normalizeSuiAddress)(Jr.Buffer.from(n).toString("hex"))}getU64(e=0,t=0){let[n,o]=this.getValue(e,t);if(o!=="u64")throw new Sn("Invalid contract return type.",{ctx:{expectType:"u64",gotType:o}});return Jr.Buffer.from(n).readBigInt64LE()}};var Yr=require("@mysten/sui.js/bcs");var V=class extends L{constructor(e,t,n){super(2,`Invalid input: ${e}`,{context:{fieldKey:t,fieldValue:n}})}};var Yl={groupId:"string",name:"string"},wd=64;function Zl(i){return tu(i),Yr.bcs.ser(Yl,i).toString("base64")}function Tn(i){let e=Yr.bcs.de(Yl,i,"base64");return tu(e),e}function tu(i){if(!Jl(i.name))throw new V("Invalid metadata: Name contains unknown character");if(!Jl(i.groupId))throw new V("Invalid metadata: Group ID contains unknown character");if(i.name.length>wd)throw new V("Invalid metadata: Name exceed max length 64")}function Jl(i){return/^[\x00-\x7F]+$/.test(i)}var In=require("@mysten/sui.js/utils");function Go(i,e){return(0,In.normalizeStructTag)(i)===(0,In.normalizeStructTag)(e)}function pe(i,e){return(0,In.normalizeStructTag)(i)===(0,In.normalizeStructTag)(e)}var Qo="txn.gas";var eu=require("nanoid");function nu(){return(0,eu.nanoid)()}var Be=class i{constructor(e,t,n){this.globals=e;this.feeContract=t;this.streamContract=n}static convertCreateStreamInfoToInternal(e){return{metadata:Zl({name:e.name,groupId:nu()}),coinType:(0,wn.normalizeStructTag)(e.coinType),recipients:e.recipients.map(t=>({address:t.address,cliffAmount:t.cliffAmount,amountPerEpoch:t.amountPerStep})),epochInterval:e.interval,numberEpoch:e.steps,startTime:e.startTimeMs,cancelable:e.cancelable}}async buildCreateStreamTransactionBlock(e){let t=new Zr.TransactionBlock,n=this.calculateFeesInternal(e),o=this.getCreateStreamCoinRequests(e,n),a=await this.wallet.requestCoins(o),c=await this.addMergeCoins(t,a[0]),l;o.length>1?l=await this.addMergeCoins(t,a[1]):l=c;for(let d=0;d<e.recipients.length;d++){let b=e.recipients[d],I=this.amountForRecipient(b,e.numberEpoch),w=this.getStreamFeeLocal(I),[k]=t.splitCoins(c,[t.pure(I+w,"u64")]),[x]=t.splitCoins(l,[t.pure(this.flatSuiFee,"u64")]);this.streamContract.createStream(t,{paymentCoin:new me(k),flatFeeCoin:new me(x),metadata:e.metadata,recipient:b.address,timeStart:e.startTime,cliff:b.cliffAmount,epochInterval:e.epochInterval,numEpoch:e.numberEpoch,amountPerEpoch:b.amountPerEpoch,cancelable:e.cancelable,coinType:e.coinType})}return t}calculateCreateStreamFees(e){let t=i.convertCreateStreamInfoToInternal(e);return this.calculateFeesInternal(t)}feeParams(){return{createFeePercent:{numerator:Gr,denominator:Xo},claimFeePercent:{numerator:Gl,denominator:Xo},flatFeePerStream:Qr}}async addMergeCoins(e,t){let n;return t.mergedCoins&&t.mergedCoins.length?(e.mergeCoins(e.object(t.primaryCoin),t.mergedCoins.map(o=>e.object(o))),n=e.object(t.primaryCoin)):t.primaryCoin===Qo?n=e.gas:n=e.object(t.primaryCoin),n}getCreateStreamCoinRequests(e,t){let n=e.coinType;return Go(n,wn.SUI_TYPE_ARG)?[{coinType:n,amount:t.totalAmount+t.streamFeeAmount+t.flatFeeAmount}]:[{coinType:n,amount:t.totalAmount+t.streamFeeAmount},{coinType:wn.SUI_TYPE_ARG,amount:t.flatFeeAmount}]}calculateFeesInternal(e){let t=e.recipients.reduce((o,a)=>{let c=this.amountForRecipient(a,e.numberEpoch),l=this.getStreamFeeLocal(c);return{totalAmount:o.totalAmount+c,streamFeeAmount:o.streamFeeAmount+l}},{totalAmount:0n,streamFeeAmount:0n});return{flatFeeAmount:BigInt(e.recipients.length)*this.flatSuiFee,...t}}amountForRecipient(e,t){return BigInt(e.amountPerEpoch)*BigInt(t)+BigInt(e.cliffAmount)}get flatSuiFee(){return Qr}getStreamFeeLocal(e){return e*Gr/Xo}async getStreamFeeRemote(e){let t=this.feeContract.streamingFee(new Zr.TransactionBlock,e),n=await this.globals.suiClient.devInspectTransactionBlock({sender:await this.globals.walletAddress(),transactionBlock:t});return new zo(n).getU64()}get wallet(){return this.globals.wallet}};var ts=require("@mysten/sui.js/transactions");var ou="0x0000000000000000000000000000000000000000000000000000000000000006";var He=class{constructor(e,t,n){this.moduleName=e;this.config=t;this.globals=n}addContractCall(e,t){let n=`${this.config.contractId}::${this.moduleName}::${t.method}`;return e.add(ts.Transactions.MoveCall({target:n,arguments:t.arguments.map(o=>o instanceof bn?o.moveArgs(e):o instanceof Jt?o.moveArg(e):o instanceof me?o.moveArg():e.pure(o)),typeArguments:t.typeArgs})),e}addTransactionBlock(e,t,n=[],o=[]){e.add(ts.Transactions.MoveCall({target:t,arguments:n.map(a=>a instanceof bn?a.moveArgs(e):a instanceof Jt?a.moveArg(e):a instanceof me?a.moveArg():e.pure(a)),typeArguments:o}))}makeObject(e){return typeof e=="string"?new Jt(e):e}vaultObject(){return new Jt(this.config.vaultObjId)}roleObject(){return new Jt(this.config.roleObjId)}feeObject(){return new Jt(this.config.feeObjId)}clockObject(){return new Jt(ou)}};var Xe=class i extends He{constructor(t,n){super(i.ModuleName,t,n);this.config=t;this.globals=n}static ModuleName="fee_module";static MethodName={set_streaming_fee:"set_streaming_fee",set_claim_fee:"set_claim_fee",set_streaming_flat_fee:"set_streaming_flat_fee",streaming_flat_fee:"streaming_flat_fee",streaming_fee:"streaming_fee",claim_fee:"claim_fee",fee_denominator:"fee_denominator"};setStreamingFee(t,n){let o=this.roleObject(),a=this.feeObject();return this.addContractCall(t,{method:i.MethodName.set_streaming_fee,arguments:[o,a,n],typeArgs:[]})}setStreamingFlatFee(t,n){let o=this.roleObject(),a=this.feeObject();return this.addContractCall(t,{method:i.MethodName.set_streaming_flat_fee,arguments:[o,a,n],typeArgs:[]})}setClaimFee(t,n){let o=this.roleObject(),a=this.feeObject();return this.addContractCall(t,{method:i.MethodName.set_claim_fee,arguments:[o,a,n],typeArgs:[]})}streamingFee(t,n){let o=this.feeObject();return this.addContractCall(t,{method:i.MethodName.streaming_fee,arguments:[o,n],typeArgs:[]})}claimFee(t,n){return this.addContractCall(t,{method:i.MethodName.claim_fee,arguments:[this.feeObject(),n],typeArgs:[]})}feeDenominator(t){return this.addContractCall(t,{method:i.MethodName.fee_denominator,arguments:[this.feeObject()],typeArgs:[]})}};var Yt=class i extends He{constructor(t,n){super(i.ModuleName,t,n);this.config=t;this.globals=n}static ModuleName="stream";static MethodName={create_stream:"create_stream",set_auto_claim:"set_auto_claim",cancel_stream:"cancel_stream",claim_stream:"claim_stream",claim_stream_by_proxy:"claim_stream_by_proxy",stream_current_epoch:"stream_current_epoch",now_milli_seconds:"now_milli_seconds"};createStream(t,n){let o=this.feeObject(),a=this.vaultObject(),c=this.makeObject(n.paymentCoin),l=this.makeObject(n.flatFeeCoin),d=this.clockObject();return this.addContractCall(t,{method:i.MethodName.create_stream,arguments:[o,a,c,l,n.metadata,n.recipient,n.timeStart,n.cliff,n.epochInterval,n.numEpoch,n.amountPerEpoch,n.cancelable,d],typeArgs:[n.coinType]})}setAutoClaim(t,n){let o=this.makeObject(n.streamId);return this.addContractCall(t,{method:i.MethodName.set_auto_claim,arguments:[o,n.enabled],typeArgs:[n.coinType]})}cancelStream(t,n){let o=this.makeObject(n.streamId),a=this.clockObject();return this.addContractCall(t,{method:i.MethodName.cancel_stream,arguments:[o,a],typeArgs:[n.coinType]})}claimStream(t,n){let o=this.makeObject(n.streamId),a=this.clockObject();return this.addContractCall(t,{method:i.MethodName.claim_stream,arguments:[o,a],typeArgs:[n.coinType]})}claimStreamByProxy(t,n){let o=this.makeObject(n.streamId),a=this.vaultObject(),c=this.feeObject(),l=this.clockObject();return this.addContractCall(t,{method:i.MethodName.claim_stream_by_proxy,arguments:[o,a,c,l],typeArgs:[n.coinType]})}get createStreamTarget(){return`${this.config.contractId}::${i.ModuleName}::${i.MethodName.create_stream}`}get setAutoClaimTarget(){return`${this.config.contractId}::${i.ModuleName}::${i.MethodName.set_auto_claim}`}get cancelStreamTarget(){return`${this.config.contractId}::${i.ModuleName}::${i.MethodName.cancel_stream}`}get claimStreamTarget(){return`${this.config.contractId}::${i.ModuleName}::${i.MethodName.claim_stream}`}get claimStreamByProxyTarget(){return`${this.config.contractId}::${i.ModuleName}::${i.MethodName.claim_stream_by_proxy}`}};var ze=class{constructor(e){this.globals=e;let t=e.envConfig.contract;this.feeContract=new Xe(t,e),this.streamContract=new Yt(t,e)}feeContract;streamContract;async createStreams(e){let t=Be.convertCreateStreamInfoToInternal(e);return this.createStreamHelper().buildCreateStreamTransactionBlock(t)}createStreamHelper(){return new Be(this.globals,this.feeContract,this.streamContract)}setAutoClaim(e,t,n){let o=new Cn.TransactionBlock;return this.streamContract.setAutoClaim(o,{streamId:e,enabled:t,coinType:n})}claimStream(e,t){let n=new Cn.TransactionBlock;return this.streamContract.claimStream(n,{streamId:e,coinType:t})}claimStreamByProxy(e,t){let n=new Cn.TransactionBlock;return this.streamContract.claimStreamByProxy(n,{streamId:e,coinType:t})}cancelStream(e,t){let n=new Cn.TransactionBlock;return this.streamContract.cancelStream(n,{streamId:e,coinType:t}),n}};var Ge=require("@mysten/sui.js/utils"),es=require("luxon");var Jo=class extends L{constructor(e,t){super(12,`Transaction failed: ${t}`,{context:{status:e,msg:t}})}};var Cd=1e3,Yo=class{constructor(e){this.globals=e;this.coinMetaHelper=new ns(e.suiClient),this.createStreamHelper=new ze(e).createStreamHelper()}coinMetaHelper;createStreamHelper;getStreamIdsFromCreateStreamResponse(e){if(e.effects?.status.status!=="success")throw new Jo(e.effects?.status.status,e.effects?.status.error);return e.objectChanges.filter(t=>t.type==="created"&&t.objectType.startsWith(`${this.globals.envConfig.contract.contractId}::stream::Stream`)).map(t=>t.objectId)}calculateCreateStreamFees(e){return this.createStreamHelper.calculateCreateStreamFees(e)}feeParams(){return this.createStreamHelper.feeParams()}calculateStreamAmount(e){if(e.steps===0n)throw new V("Invalid stream steps: 0");let t=e.cliff?e.cliff:{numerator:0n,denominator:100n},n=e.totalAmount*t.numerator/t.denominator,o=(e.totalAmount-n)/e.steps,c={realTotalAmount:o*e.steps+n,cliffAmount:n,amountPerStep:o};return this.validateStreamAmount(c,e.totalAmount),c}calculateTimelineByInterval(e){if(e.steps===0n)throw new V("Invalid stream steps: 0");let t=e.timeStart.plus(e.interval.toMillis()*Number(e.steps)),n={timeStart:e.timeStart,timeEnd:t,interval:e.interval,steps:e.steps};return this.validateTimeline(n),n}calculateTimelineByTotalDuration(e){if(e.steps===0n)throw new V("Invalid stream steps: 0");let t=BigInt(e.total.toMillis())/e.steps,n=e.timeStart.plus(es.Duration.fromMillis(Number(t*e.steps))),o={timeStart:e.timeStart,timeEnd:n,interval:es.Duration.fromMillis(Number(t)),steps:e.steps};return this.validateTimeline(o),o}async getBalance(e,t){let n=await this.globals.suiClient.getBalance({owner:e,coinType:t}),o=await this.getCoinMeta(t);return{...n,coinType:(0,Ge.normalizeStructTag)(n.coinType),coinMeta:o}}async getAllBalance(e){let t=await this.globals.suiClient.getAllBalances({owner:e}),n=await Promise.all(t.map(o=>this.getCoinMeta(o.coinType)));return t.map((o,a)=>({...o,coinType:(0,Ge.normalizeStructTag)(o.coinType),coinMeta:n[a]}))}async getCoinMeta(e){return this.coinMetaHelper.getCoinMeta(e)}async simulateTransactionBlock(e){return this.globals.suiClient.devInspectTransactionBlock({transactionBlock:e,sender:await this.globals.wallet.address()})}validateStreamAmount(e,t){if(e.amountPerStep===0n)throw new V("Stream amount too small","totalAmount",t);if(e.cliffAmount>e.realTotalAmount)throw new V("Invalid cliff settings")}validateTimeline(e){if(e.interval.toMillis()<Cd)throw new V("Interval shall be at least 1 second","interval",e.interval)}},ns=class{constructor(e){this.suiClient=e;this.coinMetaReg=new Map}coinMetaReg;async getCoinMeta(e){let t=(0,Ge.normalizeStructTag)(e||Ge.SUI_TYPE_ARG);if(this.coinMetaReg.has(t))return this.coinMetaReg.get(t);let n=await this.queryCoinMeta(t);return n&&this.coinMetaReg.set(t,n),n}async queryCoinMeta(e){return await this.suiClient.getCoinMetadata({coinType:e})||void 0}};var fe=require("@mysten/sui.js/utils"),ls=require("luxon");var vn=require("@mysten/sui.js/transactions"),Dn=require("@mysten/sui.js/utils"),iu=require("luxon");var Zo=class extends L{constructor(){super(7,"Connected wallet is not creator")}};var kn=class extends L{constructor(){super(8,"Connected wallet is not recipient")}};var xn=class extends L{constructor(e,t){super(6,e,{context:t})}};var At=class extends L{constructor(e,t={}){super(0,e,t)}};var ta=class extends L{constructor(e){super(5,"Stream not found",{context:{streamId:e}})}};var na=require("luxon"),au=(1n<<64n)-1n,ea=1e3;function os(i){let e;typeof i=="number"?e=i:typeof i=="bigint"?e=Number(i):e=i.toMillis();let t=Math.round(e/ea);return na.DateTime.fromMillis(t*ea)}function as(i){let e;typeof i=="number"?e=i:typeof i=="bigint"?e=Number(i):e=i.toMillis();let t=Math.round(e/ea);return na.Duration.fromMillis(t*ea)}var de=class i{constructor(e,t,n){this.globals=e;this.streamId=t;this.rawData=n;this.streamContract=new Yt(e.envConfig.contract,e)}streamContract;type="Stream";static async new(e,t){let n=await i.fetchStreamData(e,t);return new i(e,t,n)}static fromObjectData(e,t,n){let o=i.parseRawStreamData(t,n);return new i(e,t,o)}get info(){return{name:this.name,creator:this.creator,coinType:this.coinType,totalAmount:this.totalAmount,start:this.timeStart,end:this.timeEnd,cancelable:this.cancelable,cliffAmount:this.cliff,duration:this.duration,interval:this.interval,steps:this.totalSteps,nextReleaseDate:this.nextReleaseDate,nextReleaseAmount:this.nextReleaseAmount,groupId:this.groupId,streamId:this.streamId,recipient:this.recipient,progress:this.progress,autoClaim:this.autoClaim}}get groupCommonInfo(){return{name:this.name,groupId:this.groupId,creator:this.creator,start:this.timeStart,interval:this.interval,steps:this.totalSteps,cancelable:this.cancelable}}async refresh(){this.rawData=await i.fetchStreamData(this.globals,this.streamId)}refreshWithData(e){if(e.data?.objectId!==this.streamId)throw new At("Object Id does not align");this.rawData=i.parseRawStreamData(this.streamId,e)}async historyEvents(e){return this.globals.backend.getStreamHistory({streamId:this.streamId,pagination:e})}async cancel(){if(await this.globals.walletAddress()!==this.creator)throw new Zo;let e=new vn.TransactionBlock;return this.streamContract.cancelStream(e,{streamId:this.streamId,coinType:this.coinType}),e}async claim(){if(await this.globals.walletAddress()!==this.recipient)throw new kn;let e=new vn.TransactionBlock;return this.streamContract.claimStream(e,{streamId:this.streamId,coinType:this.coinType}),e}async setAutoClaim(e){if(await this.globals.walletAddress()!==this.recipient)throw new kn;let t=new vn.TransactionBlock;return this.streamContract.setAutoClaim(t,{streamId:this.streamId,coinType:this.coinType,enabled:e}),t}async claimByProxy(){let e=new vn.TransactionBlock;return this.streamContract.claimStreamByProxy(e,{streamId:this.streamId,coinType:this.coinType}),e}get wallet(){return this.globals.wallet}get client(){return this.globals.suiClient}get coinType(){return(0,Dn.normalizeStructTag)(this.rawData.coinType)}get progress(){return{status:this.streamStatus,total:this.totalAmount,streamed:this.streamedAmount,claimed:this.claimedAmount,claimable:this.claimable,canceled:this.canceledAmount}}get balance(){return this.rawData.balance}get autoClaim(){return this.rawData.autoClaim}get amountPerEpoch(){return this.rawData.config.amountPerEpoch}get cancelable(){return this.rawData.config.cancelable}get cliff(){return this.rawData.config.cliff}get creator(){return this.rawData.config.creator}get interval(){return as(this.rawData.config.epochInterval)}get groupId(){let{metadata:e}=this.rawData.config;return Tn(e).groupId}get name(){let{metadata:e}=this.rawData.config;return Tn(e).name}get recipient(){return this.rawData.config.recipient}get timeStart(){return os(this.rawData.config.timeStart)}get duration(){let e=this.rawData.config,t=e.epochInterval*e.totalEpoch;return as(t)}get timeEnd(){return this.timeStart.plus(this.duration)}get totalSteps(){return this.rawData.config.totalEpoch}get claimable(){return this.streamedAmount-this.claimedAmount}get nextReleaseDate(){return this.currentEpoch===-1n?this.timeStart:this.currentEpoch>=this.totalSteps||this.isCanceled?null:os((this.currentEpoch+1n)*this.rawData.config.epochInterval+this.rawData.config.timeStart)}get nextReleaseAmount(){return this.currentEpoch===-1n?this.cliff:this.currentEpoch>=this.totalSteps||this.isCanceled?null:this.amountPerEpoch}get streamStatus(){let e=this.rawData.status.status;return e===16?"CANCELED":e===17?"SETTLED":e===1?"COMPLETED":this.currentEpoch>=this.totalSteps?"STREAMED":"STREAMING"}get streamedAmount(){return this.currentEpoch===-1n?0n:this.isCanceled?this.rawData.status.epochCanceled*this.amountPerEpoch+this.cliff:this.currentEpoch*this.amountPerEpoch+this.cliff}get claimedAmount(){return this.rawData.status.epochClaimed===au?0n:this.rawData.status.epochClaimed*this.amountPerEpoch+this.cliff}get currentEpoch(){let e=iu.DateTime.now().toMillis(),t=this.timeStart.toMillis();if(e<t)return-1n;let n=Math.floor((e-t)/Number(this.rawData.config.epochInterval));return BigInt(n)>Number(this.rawData.config.totalEpoch)?this.rawData.config.totalEpoch:BigInt(n)}get totalAmount(){let e=this.rawData.config;return e.amountPerEpoch*e.totalEpoch+e.cliff}get isCanceled(){let e=this.rawData.status.status;return e===16||e===17}get canceledAmount(){return this.isCanceled?this.totalAmount-this.streamedAmount:0n}static async fetchStreamData(e,t){let n=await e.suiClient.getObject({id:t,options:{showContent:!0,showType:!0}});return i.parseRawStreamData(t,n)}static parseRawStreamData(e,t){if(t.error)throw t.error.code==="notExists"?new ta(e):new xn(`get stream data: ${t.error.code}`,{streamId:e,...t.error});let n=t.data.content;if(n.dataType!=="moveObject")throw new xn("Unexpected object type",{gotType:n.dataType});let{typeParams:o}=(0,Dn.parseStructTag)(n.type),a=(0,Dn.normalizeStructTag)(o[0]),c=n.fields,l=c.config.fields,d=c.status.fields;return{coinType:a,autoClaim:c.auto_claim,balance:BigInt(c.balance.fields.balance),config:{amountPerEpoch:BigInt(l.amount_per_epoch),cancelable:l.cancelable,cliff:BigInt(l.cliff),creator:l.creator,epochInterval:BigInt(l.epoch_interval),metadata:l.metadata,recipient:l.recipient,timeStart:BigInt(l.time_start),totalEpoch:BigInt(l.total_epoch)},status:{status:d.status,epochCanceled:BigInt(d.epoch_canceled),epochClaimed:BigInt(d.epoch_claimed)}}}};var Qe=class extends L{constructor(e,t){super(9,`Invalid stream group: ${e}`,{context:t})}};async function rs(i){let e=[];for(;await i.hasNext();){let t=await i.next();e.push(t)}return e&&Array.isArray(e[0])?e.flat(1):e}var is=class{constructor(e){this.requester=e;this.curPage=void 0,this.init=!0}curPage;init;async hasNext(){if(this.init)return this.curPage||(this.curPage=await this.requester.doNextRequest()),!!this.curPage.data?.length||this.curPage.hasNext;if(!this.curPage)throw new Error("invalid implementation of iterator");return this.curPage.hasNext}async next(){return this.init?(this.init=!1,this.curPage||(this.curPage=await this.requester.doNextRequest()),this.curPage.data):(this.curPage=await this.requester.doNextRequest(),this.curPage.data)}},Je=class{constructor(e){this.requester=e;this.pager=new is(e),this.curData=[],this.cursor=0}cursor;pager;curData;async hasNext(){return this.cursor<this.curData.length-1?!0:this.pager.hasNext()}async next(){for(this.cursor+=1;this.cursor>=this.curData.length;)if(await this.pager.hasNext())this.curData=await this.pager.next(),this.cursor=0;else throw new Error("not more data");return this.curData[this.cursor]}};var kd=25;async function cs(i,e,t){let n=new An(e),o=new Mn(i,n,t);return await rs(o)}var An=class{constructor(e){this.ids=e;this.cursor=-1}cursor;async hasNext(){return this.cursor<this.ids.length-1}async next(){if(this.cursor+=1,this.cursor>=this.ids.length)throw new Error("invalid iterator implementation");return this.ids[this.cursor]}},Mn=class extends Je{constructor(t,n,o){super(new ss(t,n,o));this.suiClient=t;this.idIter=n;this.options=o}},ss=class{constructor(e,t,n){this.suiClient=e;this.stringIter=t;this.options=n;this.filter=n?.filter,this.pageSize=n?.pageSize||kd,this.objectOptions=n?.objectOptions||{showType:!0,showContent:!0}}filter;pageSize;objectOptions;async doNextRequest(){let e=[];for(;e.length<this.pageSize&&await this.stringIter.hasNext();){let a=await this.stringIter.next();a&&e.push(a)}let t=await this.suiClient.multiGetObjects({ids:e,options:this.objectOptions}),n;if(this.filter){let{filter:o}=this;n=t.filter(a=>o?.(a))}else n=t;return{data:n,hasNext:await this.stringIter.hasNext()}}};var oa=class i{constructor(e,t){this.globals=e;this.streams=t;if(t.length===0)throw new Qe("stream size 0");let n=t.map(a=>a.groupId);if(new Set(n).size!==1)throw new V("Stream does not have same group ID")}type="StreamGroup";static async new(e,t){let n=await cs(e.suiClient,t);return n.forEach(o=>{if(!o)throw new At("stream group object data undefined")}),i.newFromObjectResponse(e,t,n)}static async newFromObjectResponse(e,t,n){let o=await i.parseGroupStreams(e,t,n);return new i(e,o)}static checkStreamGroup(e){let t=e.map(a=>a.groupCommonInfo),n=t[0],o=!0;return t.forEach(a=>{xd(n,a)||(o=!1)}),o}async refresh(){let e=await cs(this.globals.suiClient,this.streams.map(t=>t.streamId));this.streams.forEach((t,n)=>{t.refreshWithData(e[n])})}get groupId(){return this.streams[0].groupId}get creator(){return this.streams[0].creator}get info(){return{groupId:this.groupId,streamIds:this.streams.map(e=>e.streamId),progress:this.progress,name:this.streams[0].name,creator:this.creator,coinType:this.streams[0].coinType,totalAmount:this.streams.reduce((e,t)=>e+t.totalAmount,0n),start:this.streams[0].timeStart,end:this.streams[0].timeEnd,cancelable:this.streams[0].cancelable,cliffAmount:this.streams.reduce((e,t)=>e+t.cliff,0n),duration:this.streams[0].duration,interval:this.streams[0].interval,steps:this.streams[0].totalSteps,nextReleaseAmount:this.streams.reduce((e,t)=>t.nextReleaseAmount===null?e:e+t.nextReleaseAmount,0n),nextReleaseDate:this.streams[0].nextReleaseDate}}get progress(){return{total:this.streams.reduce((e,t)=>e+t.totalAmount,0n),streamed:this.streams.reduce((e,t)=>e+t.streamedAmount,0n),claimed:this.streams.reduce((e,t)=>e+t.claimedAmount,0n),claimable:this.streams.reduce((e,t)=>e+t.claimable,0n),canceled:this.streams.reduce((e,t)=>e+t.canceledAmount,0n)}}async historyEvents(e){return this.globals.backend.getStreamHistory({groupId:this.groupId,pagination:e})}static async parseGroupStreams(e,t,n){let o=n.map((a,c)=>de.fromObjectData(e,t[c],a)).filter(a=>!!a);if(new Set(o.map(a=>a.groupId)).size!==1)throw new Qe("Not same group ID");if(!this.checkStreamGroup(o))throw new Qe("Not same stream settings");return o}};function xd(i,e){return i.name===e.name&&i.groupId===e.groupId&&i.creator===e.creator&&i.start.toMillis()===e.start.toMillis()&&i.interval.toMillis()===e.interval.toMillis()&&i.steps===e.steps&&i.cancelable===e.cancelable}var On=class i{constructor(e,t){this.it=e;this.pageSize=t}static async newIncoming(e){let t=await aa.newIncoming(e);return new i(t,e.pageSize)}static async newOutgoing(e){let t=await aa.newOutgoing(e);return new i(t,e.pageSize)}async hasNext(){return this.it.hasNext()}async next(){let e=[];for(;e.length<this.pageSize&&await this.it.hasNext();)e.push(await this.it.next());return e}},aa=class i{constructor(e){this.requester=e}cachedNext;static async newIncoming(e){let t=await ia.newIncomingQuery(e);return new i(t)}static async newOutgoing(e){let t=await ia.newOutgoingQuery(e);return new i(t)}async hasNext(){return this.cachedNext===void 0&&(this.cachedNext=await this.requester.doNextRequest()),this.cachedNext!==null}async next(){if(this.cachedNext===void 0){let t=await this.requester.doNextRequest();if(t===null)throw new At("No more results");return t}let e=this.cachedNext;if(this.cachedNext=void 0,e===null)throw new At("No more results");return e}},ia=class i{constructor(e,t,n,o){this.globals=e;this.recipient=t;this.groupRefs=n;this.query=o;this.current=0;let a=new An(n.flat().map(c=>c.streamId));this.objectIter=new Mn(e.suiClient,a)}current=0;objectIter;static async newIncomingQuery(e){let t=Od(e.query),n=await e.globals.walletAddress(),a=(await e.globals.backend.getIncomingStreams(n,t)).filter(l=>(0,fe.normalizeSuiAddress)(l.recipient)===(0,fe.normalizeSuiAddress)(n)),c=ru(a);return new i(e.globals,n,c,e.query)}static async newOutgoingQuery(e){let t=Pd(e.query),n=await e.globals.walletAddress(),o=await e.globals.backend.getOutgoingStreams(n,t),a=ru(o);return new i(e.globals,n,a,e.query)}async doNextRequest(){if(this.current>=this.groupRefs.length)return null;let e=this.groupRefs[this.current];if(e.length===1){let t=await Ad(this.globals,e[0].streamId,this.objectIter);return this.current++,su(t,this.query)?t:this.doNextRequest()}if(e.length>1){let t=await Md(this.globals,e.map(n=>n.streamId),this.objectIter);return this.current++,Dd(t,this.query)?t:this.doNextRequest()}throw new At("Stream group with no stream")}};function ru(i){let e=new Map;return i.forEach(t=>{let n=e.get(t.groupId);n?(n.push(t),e.set(t.groupId,n)):e.set(t.groupId,[t])}),Array.from(e.values()).sort((t,n)=>ls.DateTime.fromISO(n[0].createDate).toMillis()-ls.DateTime.fromISO(t[0].createDate).toMillis())}function su(i,e){if(e===void 0)return!0;let t=vd(i,e.status);if(e&&"claimable"in e&&e.claimable!==void 0){let n=e.claimable?i.progress.claimable!==0n:i.progress.claimable===0n;return t&&n}return t}function vd(i,e){return e===void 0?!0:Array.isArray(e)?e.includes(i.progress.status):i.progress.status===e}function Dd(i,e){if(!e)return!0;let t=!1;return i.streams.forEach(n=>{su(n,e)&&(t=!0)}),t}async function Ad(i,e,t){let n=await cu(t,e);return de.fromObjectData(i,e,n)}async function Md(i,e,t){let n=[];for(;n.length<e.length;){let o=await cu(t,e[n.length]);n.push(o)}return oa.newFromObjectResponse(i,e,n)}async function cu(i,e){if(!await i.hasNext())throw new At("object iterator has been consumed");let t=await i.next();if(!t||t.error||t.data===void 0||t.data===null)throw new At("object iterator undefined response",{cause:t?.error});if(t?.data?.objectId!==e)throw new At("stream id not aligned");return t}function Od(i){return{status:us(i?.status),coinType:lu(i?.coinType),sender:uu(i?.sender)}}function Pd(i){return{status:us(i?.status),coinType:lu(i?.coinType),recipient:uu(i?.recipient)}}function us(i){return i===void 0||i.length===0?"all":Array.isArray(i)?i.reduce((e,t)=>{let n=us(t);return!e||e===n?n:"all"},void 0):Rd(i)}function Rd(i){switch(i){case"STREAMING":case"STREAMED":case"CANCELED":return"active";case"COMPLETED":case"SETTLED":return"inactive";default:throw new V("Unknown stream filtered status")}}function lu(i){if(i)return Array.isArray(i)?i.length!==0?i.map(e=>(0,fe.normalizeStructTag)(e)):void 0:(0,fe.normalizeStructTag)(i)}function uu(i){if(i)return Array.isArray(i)?i.length!==0?i.map(e=>(0,fe.normalizeSuiAddress)(e)):void 0:(0,fe.normalizeSuiAddress)(i)}var ra=class extends L{constructor(t,n,o){super(4,`Not enough balance: ${t}`,{context:{coinType:t,requestAmount:n,gotAmount:o}});this.coinType=t;this.requestAmount=n;this.gotAmount=o}};var Bd=25;async function mu(i,e,t,n="0x2::sui::SUI",o=Bd){let a=new ms(i,e,n,o),c=BigInt(0),l=[];for(;await a.hasNext()&&c<t;){let d=await a.next();d&&(l.push(d),c+=BigInt(d.balance))}if(c<t)throw new ra(n,t,c);return l}var ms=class extends Je{constructor(t,n,o,a){super(new ps(t,n,o,a));this.suiClient=t;this.owner=n;this.coinType=o;this.reqPageSize=a}},ps=class{constructor(e,t,n,o){this.suiClient=e;this.owner=t;this.coinType=n;this.reqPageSize=o;if(o<=0)throw new At("Invalid reqPageSize")}nextCursor;async doNextRequest(){let e=await this.suiClient.getCoins({owner:this.owner,coinType:this.coinType,cursor:this.nextCursor,limit:this.reqPageSize});return this.nextCursor=e.nextCursor,{data:e.data,hasNext:e.hasNextPage}}};var ds=class{constructor(e){this.msafe=e}get type(){return"msafe"}async address(){return this.msafe.address()}async requestCoins(e){return this.msafe.requestCoins(e)}},sa=class{constructor(e){this.account=e}async address(){return this.account.address}},fs=class{constructor(e,t){this.singleWallet=e;this.suiClient=t}get type(){return"single"}async address(){return this.singleWallet.address()}async requestCoins(e){return Promise.all(e.map(t=>this.requestCoin(t)))}async requestCoin(e){if(Go(e.coinType,Ee.SUI_TYPE_ARG))return{primaryCoin:Qo};if(e.amount<=0)throw new V("Invalid coin request","coinAmount",e.amount);let t=await mu(this.suiClient,await this.address(),e.amount,e.coinType);if(t.length===0)throw new At("no coins available");return{primaryCoin:t[0].coinObjectId,mergedCoins:t.slice(1).map(n=>n.coinObjectId)}}},ca=class{globals;helper;constructor(e,t){this.globals=Ve.new(e,t),this.helper=new Yo(this.globals)}connectSingleWallet(e){let t=new fs(e,this.globals.suiClient);this.globals.connectWallet(t)}connectMSafeAccount(e){let t=new ds(e);this.globals.connectWallet(t)}async createStream(e){return this.builder().createStreams(e)}async getStream(e){return de.new(this.globals,e)}async getIncomingStreams(e,t=10){return On.newIncoming({globals:this.globals,query:e,pageSize:t})}async getOutgoingStreams(e,t=10){return On.newOutgoing({globals:this.globals,query:e,pageSize:t})}async getCoinTypesForStreamFilter(){let e=await this.wallet.address();return(await this.globals.backend.getAllCoinTypes(e)).map(n=>(0,Ee.normalizeStructTag)(n))}async getRecipientsForStreamFilter(e){let t=await this.wallet.address();return(await this.globals.backend.getAllRecipients(t,e)).map(o=>(0,Ee.normalizeSuiAddress)(o))}async getCreatorsForStreamFilter(e){let t=await this.wallet.address();return(await this.globals.backend.getAllSenders(t,e)).map(o=>(0,Ee.normalizeSuiAddress)(o))}get wallet(){return this.globals.wallet}builder(){return new ze(this.globals)}};var Kt=class extends _{application="mpay";getClient(e,t){let n=new ca(e==="sui:mainnet"?"prod":"dev");return n.connectSingleWallet(new sa(t)),n}};var Pn=class extends Kt{constructor(t){super(t);this.data=t}txType=pu.TransactionType.Stream;txSubType="Cancel";async build(t){let{network:n,account:o}=t;return(await this.getClient(n,o).getStream(this.data.streamId)).cancel()}};var du=require("@msafe/sui3-utils");var Rn=class extends Kt{constructor(t){super(t);this.data=t}txType=du.TransactionType.Stream;txSubType="ClaimByProxy";async build(t){let{network:n,account:o}=t;return(await this.getClient(n,o).getStream(this.data.streamId)).claimByProxy()}};var fu=require("@msafe/sui3-utils");var Bn=class extends Kt{constructor(t){super(t);this.data=t}txType=fu.TransactionType.Stream;txSubType="Claim";async build(t){let{network:n,account:o}=t;return(await this.getClient(n,o).getStream(this.data.streamId)).claim()}};var hu=require("@msafe/sui3-utils");var En=class extends Kt{constructor(t){super(t);this.data=t}txType=hu.TransactionType.Stream;txSubType="CreateStream";async build(t){let{network:n,account:o}=t;return this.getClient(n,o).createStream(this.data)}};var hs=require("@mysten/sui.js/bcs"),he=require("@mysten/sui.js/utils"),Ye=class i{constructor(e,t){this.moveCall=e;this.txb=t}decodeSharedObjectId(e){let t=this.getInputParam(e);return i.getSharedObjectId(t)}decodeOwnedObjectId(e){let t=this.getInputParam(e);return i.getOwnedObjectId(t)}decodeInputU64(e){let t=this.decodePureArg(e,"u64");return BigInt(t)}decodeInputAddress(e){let t=this.decodePureArg(e,"address");return(0,he.normalizeSuiAddress)(t)}decodeInputString(e){return this.decodePureArg(e,"string")}decodeInputBool(e){return this.decodePureArg(e,"bool")}decodePureArg(e,t){let n=this.getInputParam(e);return i.getPureInputValue(n,t)}getInputParam(e){let t=this.moveCall.arguments[e];if(t.kind!=="Input")throw new Error("not input type");return this.txb.blockData.inputs[t.index]}static getPureInputValue(e,t){if(e.type!=="pure")throw new Error("not pure argument");if(typeof e.value=="object"&&"Pure"in e.value){let n=e.value.Pure;return hs.bcs.de(t,new Uint8Array(n))}return e.value}static getOwnedObjectId(e){if(e.type!=="object")throw new Error(`not object argument: ${JSON.stringify(e)}`);if(typeof e.value=="object"){if(!("Object"in e.value)||!("ImmOrOwned"in e.value.Object))throw new Error("not ImmOrOwned");return(0,he.normalizeSuiAddress)(e.value.Object.ImmOrOwned.objectId)}return(0,he.normalizeSuiAddress)(e.value)}static getSharedObjectId(e){if(e.type!=="object")throw new Error(`not object argument: ${JSON.stringify(e)}`);if(typeof e.value!="object")return(0,he.normalizeSuiAddress)(e.value);if(!("Object"in e.value)||!("Shared"in e.value.Object))throw new Error("not Shared");return(0,he.normalizeSuiAddress)(e.value.Object.Shared.objectId)}static getPureInput(e,t){if(e.type!=="pure")throw new Error("not pure argument");if(typeof e.value!="object")return e.value;if(!("Pure"in e.value))throw new Error("Pure not in value");let n=e.value.Pure;return hs.bcs.de(t,new Uint8Array(n))}typeArg(e){return(0,he.normalizeStructTag)(this.moveCall.typeArguments[e])}txArg(e){return this.moveCall.arguments[e]}};var la=class{constructor(e,t){this.globals=e;this.txb=t}decode(){let e=this.decodeCreateStreamInfo(),t=this.createStreamHelper().calculateCreateStreamFees(e);return{type:"CreateStream",info:e,fees:t}}decodeCreateStreamInfo(){let t=this.createStreamTransactions().map(n=>this.getCreationInfoFromMoveCall(n));return this.aggregateGroupStreamInfo(t)}createStreamTransactions(){let e=this.transactions.filter(t=>t.kind==="MoveCall"&&pe(t.target,this.contract.createStreamTarget));if(e.length===0)throw new At("No create stream transactions");return e.map(t=>new Ye(t,this.txb))}getCreationInfoFromMoveCall(e){let t=e.decodeInputString(4),{name:n,groupId:o}=Tn(t),a=e.decodeInputAddress(5),c=e.decodeInputU64(6),l=e.decodeInputU64(7),d=e.decodeInputU64(8),b=e.decodeInputU64(9),I=e.decodeInputU64(10),w=e.decodeInputBool(11),k=e.typeArg(0);return{name:n,groupId:o,recipient:a,timeStart:c,cliff:l,epochInterval:d,totalEpoch:b,amountPerEpoch:I,cancelable:w,coinType:k}}aggregateGroupStreamInfo(e){if(new Set(e.map(o=>JSON.stringify({name:o.name,groupId:o.groupId,timeStart:String(o.timeStart),epochInterval:String(o.epochInterval),totalEpoch:String(o.totalEpoch),cancelable:o.cancelable,coinType:o.coinType}))).size!==1)throw new V("Stream group not have common info");let n=e.map(o=>({address:o.recipient,amountPerStep:o.amountPerEpoch,cliffAmount:o.cliff}));return{name:e[0].name,coinType:e[0].coinType,recipients:n,interval:e[0].epochInterval,steps:e[0].totalEpoch,startTimeMs:e[0].timeStart,cancelable:e[0].cancelable}}mergeCoinTransactions(){return this.transactions.filter(e=>e.kind==="MergeCoins")}get transactions(){return this.txb.blockData.transactions}get contract(){return new Yt(this.globals.envConfig.contract,this.globals)}get feeContract(){return new Xe(this.globals.envConfig.contract,this.globals)}createStreamHelper(){return new Be(this.globals,this.feeContract,this.contract)}getInputArg(e){if(e.kind!=="Input")throw new Error("not input type");return"value"in e?e:this.txb.blockData.inputs[e.index]}};var ua=class{constructor(e,t){this.globals=e;this.txb=t;this.contract=new Yt(e.envConfig.contract,e)}contract;decode(){if(this.isCreateStreamTransaction())return this.decodeCreateStreamTransaction();if(this.isClaimByProxyTransaction())return this.decodeClaimByProxyTransaction();if(this.isSetAutoClaimTransaction())return this.decodeSetAutoClaimTransaction();if(this.isCancelStreamTransaction())return this.decodeCancelStreamTransaction();if(this.isClaimStreamTransaction())return this.decodeClaimTransaction();throw new Error("Unknown stream transaction type")}get transactions(){return this.txb.blockData.transactions}isCreateStreamTransaction(){return this.transactions.findIndex(t=>t.kind==="MoveCall"&&pe(t.target,this.contract.createStreamTarget))!==-1}isSetAutoClaimTransaction(){return this.transactions.length===1&&this.transactions[0].kind==="MoveCall"&&pe(this.transactions[0].target,this.contract.setAutoClaimTarget)}isCancelStreamTransaction(){return this.transactions.length===1&&this.transactions[0].kind==="MoveCall"&&pe(this.transactions[0].target,this.contract.cancelStreamTarget)}isClaimStreamTransaction(){return this.transactions.length===1&&this.transactions[0].kind==="MoveCall"&&pe(this.transactions[0].target,this.contract.claimStreamTarget)}isClaimByProxyTransaction(){return this.transactions.length===1&&this.transactions[0].kind==="MoveCall"&&pe(this.transactions[0].target,this.contract.claimStreamByProxyTarget)}decodeCreateStreamTransaction(){return new la(this.globals,this.txb).decode()}decodeSetAutoClaimTransaction(){let e=this.helper.decodeSharedObjectId(0),t=this.helper.decodeInputBool(1);return{type:"SetAutoClaim",streamId:e,enabled:t}}decodeClaimTransaction(){let e=this.helper.decodeSharedObjectId(0);return{type:"Claim",streamId:e}}decodeClaimByProxyTransaction(){let e=this.helper.decodeSharedObjectId(0);return{type:"ClaimByProxy",streamId:e}}decodeCancelStreamTransaction(){let e=this.helper.decodeSharedObjectId(0);return{type:"Cancel",streamId:e}}get helper(){let e=this.transactions[0];return new Ye(e,this.txb)}};var gu=require("@msafe/sui3-utils");var Nn=class extends Kt{constructor(t){super(t);this.data=t}txType=gu.TransactionType.Stream;txSubType="SetAutoClaim";async build(t){let{network:n,account:o}=t;return(await this.getClient(n,o).getStream(this.data.streamId)).setAutoClaim(this.data.enabled)}};var ma=class{application="mpay";supportSDK="@mysten/sui.js";async deserialize(e){let{network:t,transactionBlock:n}=e,o=Ve.new(t==="sui:mainnet"?"prod":"dev"),c=new ua(o,n).decode(),l;switch(c.type){case"CreateStream":l=new En(c.info);break;case"SetAutoClaim":l=new Nn({streamId:c.streamId,enabled:c.enabled});break;case"Claim":l=new Bn({streamId:c.streamId});break;case"ClaimByProxy":l=new Rn({streamId:c.streamId});break;case"Cancel":l=new Pn({streamId:c.streamId});break;default:throw new Error(`Unknown transaction type: ${c}`)}return{txType:l.txType,txSubType:l.txSubType,intentionData:l.data}}async build(e){let{intentionData:t}=e,n;switch(e.txSubType){case"CreateStream":n=new En(t);break;case"Claim":n=new Bn(t);break;case"ClaimByProxy":n=new Rn(t);break;case"SetAutoClaim":n=new Nn(t);break;case"Cancel":n=new Pn(t);break;default:throw new Error("not implemented")}return n.build({...e})}};var Wn=require("@msafe/sui3-utils");var yu=require("@msafe/sui3-utils");var pa=class i extends _{constructor(t){super(t);this.data=t}txType;txSubType;async build(t){let{suiClient:n,account:o}=t;return(0,yu.buildCoinTransferTxb)(n,this.data,o.address)}static fromData(t){return new i(t)}};var bu=require("@msafe/sui3-utils");var da=class i extends _{constructor(t){super(t);this.data=t}txType;txSubType;async build(t){let{suiClient:n,account:o}=t;return(0,bu.buildObjectTransferTxb)(n,this.data,o.address)}static fromData(t){return new i(t)}};var fa=class{application="msafe-core";supportSDK="@mysten/sui.js";constructor(){this.application=Wn.TransactionDefaultApplication}deserialize(){throw new Error("MSafe core transaction intention should be build from API")}async build(e){let{suiClient:t,account:n}=e,o;switch(e.txSubType){case Wn.TransactionSubTypes.assets.coin.send:o=pa.fromData(e.intentionData);break;case Wn.TransactionSubTypes.assets.object.send:o=da.fromData(e.intentionData);break;default:throw new Error("not implemented")}return o.build({suiClient:t,account:n})}};var Ou=require("@msafe/sui3-utils");var Su=!1,_n={ProtocolPackage:"0x81c408448d0d57b3e371ea94de1d40bf852784d3e225de1e74acab3e8395c18f",StorageId:"0xbb4e2f4b6205c2e2a2db47aeb4f830796ec7c005f88537ee775986639bc442fe",Incentive:"0xaaf735bf83ff564e1b219a0d644de894ef5bdc4b2250b126b2a46dd002331821",IncentiveV2:"0xf87a8acb8b81d14307894d12595541a73f19933f88e1326d5be349c7a6f7559c",gasBudget:5e7,PriceOracle:"0x1568865ed9a0b5ec414220e8f79b3d04c77acc82358f6e5ae4635687392ffbef",ReserveParentId:"0xe6d4c6610b86ce7735ea754596d71d72d10c7980b5052fc3c8cdf8d09fea9b4b",pool:{sui:{name:"SUI",assetId:0,poolId:"0x96df0fce3c471489f4debaaa762cf960b3d97820bd1f3f025ff8190730e958c5",fondPoolId:"0xf975bc2d4cca10e3ace8887e20afd77b46c383b4465eac694c4688344955dea4",type:"0x2::sui::SUI",coinType:"sui",reserveObjectId:"0xab644b5fd11aa11e930d1c7bc903ef609a9feaf9ffe1b23532ad8441854fbfaf",borrowBalanceParentId:"0xe7ff0daa9d090727210abe6a8b6c0c5cd483f3692a10610386e4dc9c57871ba7",supplyBalanceParentId:"0x589c83af4b035a3bc64c40d9011397b539b97ea47edf7be8f33d643606bf96f8"},wusdc:{name:"wUSDC",assetId:1,coinType:"wusdc",poolId:"0xa02a98f9c88db51c6f5efaaf2261c81f34dd56d86073387e0ef1805ca22e39c8",type:"0x5d4b302506645c37ff133b98c4b50a5ae14841659738d6d733d59d0d217a93bf::coin::COIN",reserveObjectId:"0xeb3903f7748ace73429bd52a70fff278aac1725d3b58afa781f25ce3450ac203",borrowBalanceParentId:"0x8a3aaa817a811131c624658f6e77cba04ab5829293d2c49c1a9cce8ac9c8dec4",supplyBalanceParentId:"0x8d0a4467806458052d577c8cd2be6031e972f2b8f5f77fce98aa12cd85330da9"},usdt:{name:"USDT",coinType:"usdt",assetId:2,poolId:"0x0e060c3b5b8de00fb50511b7a45188c8e34b6995c01f69d98ea5a466fe10d103",type:"0xc060006111016b8a020ad5b33834984a437aaa7d3c74c18e09a95d48aceab08c::coin::COIN",reserveObjectId:"0xb8c5eab02a0202f638958cc79a69a2d30055565caad1684b3c8bbca3bddcb322",borrowBalanceParentId:"0xc14d8292a7d69ae31164bafab7ca8a5bfda11f998540fe976a674ed0673e448f",supplyBalanceParentId:"0x7e2a49ff9d2edd875f82b76a9b21e2a5a098e7130abfd510a203b6ea08ab9257"},weth:{name:"WETH",coinType:"weth",assetId:3,poolId:"0x71b9f6e822c48ce827bceadce82201d6a7559f7b0350ed1daa1dc2ba3ac41b56",type:"0xaf8cd5edc19c4512f4259f0bee101a40d41ebed738ade5874359610ef8eeced5::coin::COIN",reserveObjectId:"0xafecf4b57899d377cc8c9de75854c68925d9f512d0c47150ca52a0d3a442b735",borrowBalanceParentId:"0x7568d06a1b6ffc416a36c82791e3daf0e621cf19d4a2724fc6f74842661b6323",supplyBalanceParentId:"0xa668905b1ad445a3159b4d29b1181c4a62d864861b463dd9106cc0d97ffe8f7f"},cetus:{name:"CETUS",coinType:"cetus",assetId:4,poolId:"0x3c376f857ec4247b8ee456c1db19e9c74e0154d4876915e54221b5052d5b1e2e",type:"0x06864a6f921804860930db6ddbe2e16acdf8504495ea7481637a1c8b9a8fe54b::cetus::CETUS",reserveObjectId:"0x66a807c06212537fe46aa6719a00e4fa1e85a932d0b53ce7c4b1041983645133",borrowBalanceParentId:"0x4c3da45ffff6432b4592a39cdb3ce12f4a28034cbcb804bb071facc81fdd923d",supplyBalanceParentId:"0x6adc72faf2a9a15a583c9fb04f457c6a5f0b456bc9b4832413a131dfd4faddae"},voloSui:{name:"VoloSui",coinType:"voloSui",assetId:5,poolId:"0x9790c2c272e15b6bf9b341eb531ef16bcc8ed2b20dfda25d060bf47f5dd88d01",fondPoolId:"0xe2b5ada45273676e0da8ae10f8fe079a7cec3d0f59187d3d20b1549c275b07ea",type:"0x549e8b69270defbfafd4f94e17ec44cdbdd99820b33bda2278dea3b9a32d3f55::cert::CERT",reserveObjectId:"0xd4fd7e094af9819b06ea3136c13a6ae8da184016b78cf19773ac26d2095793e2",borrowBalanceParentId:"0x8fa5eccbca2c4ba9aae3b87fd44aa75aa5f5b41ea2d9be4d5321379384974984",supplyBalanceParentId:"0xe6457d247b6661b1cac123351998f88f3e724ff6e9ea542127b5dcb3176b3841"},haSui:{name:"HaedalSui",coinType:"haSui",assetId:6,poolId:"0x6fd9cb6ebd76bc80340a9443d72ea0ae282ee20e2fd7544f6ffcd2c070d9557a",fondPoolId:"0xa20e18085ce04be8aa722fbe85423f1ad6b1ae3b1be81ffac00a30f1d6d6ab51",type:"0xbde4ba4c2e274a60ce15c1cfff9e5c42e41654ac8b6d906a57efa4bd3c29f47d::hasui::HASUI",reserveObjectId:"0x0c9f7a6ca561dc566bd75744bcc71a6af1dc3caf7bd32c099cd640bb5f3bb0e3",borrowBalanceParentId:"0x01f36898e020be6c3423e5c95d9f348868813cd4d0be39b0c8df9d8de4722b00",supplyBalanceParentId:"0x278b8e3d09c3548c60c51ed2f8eed281876ea58c392f71b7ff650cc9286d095b"},navx:{name:"NAVX",coinType:"navx",assetId:7,poolId:"0xc0e02e7a245e855dd365422faf76f87d9f5b2148a26d48dda6e8253c3fe9fa60",fondPoolId:"0x9dae0cf104a193217904f88a48ce2cf0221e8cd9073878edd05101d6b771fa09",type:"0xa99b8952d4f7d947ea77fe0ecdcc9e5fc0bcab2841d6e2a5aa00c3044e5544b5::navx::NAVX",reserveObjectId:"0x2e13b2f1f714c0c5fa72264f147ef7632b48ec2501f810c07df3ccb59d6fdc81",borrowBalanceParentId:"0xa5bf13075aa400cbdd4690a617c5f008e1fae0511dcd4f7121f09817df6c8d8b",supplyBalanceParentId:"0x59dedca8dc44e8df50b190f8b5fe673098c1273ac6168c0a4addf3613afcdee5"},wbtc:{name:"WBTC",coinType:"wbtc",assetId:8,poolId:"0xd162cbe40f8829ce71c9b3d3bf3a83859689a79fa220b23d70dc0300b777ae6e",type:"0x027792d9fed7f9844eb4839566001bb6f6cb4804f66aa2da6fe1ee242d896881::coin::COIN",reserveObjectId:"0x8b4d81f004e4e9faf4540951a896b6d96e42598a270e6375f598b99742db767e",borrowBalanceParentId:"0x55e1f3c9e6e5cf9fff563bdd61db07a3826458c56ef72c455e049ab3b1b0e99c",supplyBalanceParentId:"0x821e505a0091b089edba94deaa14c2f2230d026bbaa7b85680554441aad447e0"},ausd:{name:"AUSD",coinType:"ausd",assetId:9,poolId:"0xc9208c1e75f990b2c814fa3a45f1bf0e85bb78404cfdb2ae6bb97de58bb30932",type:"0x2053d08c1e2bd02791056171aab0fd12bd7cd7efad2ab8f6b9c8902f14df2ff2::ausd::AUSD",reserveObjectId:"0x918889c6a9d9b93108531d4d59a4ebb9cc4d41689798ffc1d4aed6e1ae816ec0",borrowBalanceParentId:"0x551300b9441c9a3a16ca1d7972c1dbb4715e15004ccd5f001b2c2eee22fd92c1",supplyBalanceParentId:"0xe151af690355de8be1c0281fbd0d483c099ea51920a57c4bf8c9666fd36808fd"},nusdc:{name:"USDC",assetId:10,coinType:"nusdc",poolId:"0xa3582097b4c57630046c0c49a88bfc6b202a3ec0a9db5597c31765f7563755a8",type:"0xdba34672e30cb065b1f93e3ab55318768fd6fef66c15942c9f7cb846e2f900e7::usdc::USDC",reserveObjectId:"0x4c8a2c72a22ae8da803a8519798d312c86e74a9e0d6ec0eec2bfcf7e4b3fef5e",borrowBalanceParentId:"0xb0b0c7470e96cabbb4f1e8d06bef2fbea65f4dbac52afae8635d9286b1ea9a09",supplyBalanceParentId:"0x08b5ce8574ac3bc9327e66ad5decd34d07ee798f724ad01058e8855ac9acb605"},eth:{name:"ETH",assetId:11,coinType:"eth",poolId:"0x78ba01c21d8301be15690d3c30dc9f111871e38cfb0b2dd4b70cc6052fba41bb",type:"0xd0e89b2af5e4910726fbcd8b8dd37bb79b29e5f83f7491bca830e94f7f226d29::eth::ETH",reserveObjectId:"0x376faea6dfbffab9ea808474cb751d91222b6d664f38c0f1d23de442a8edb1ce",borrowBalanceParentId:"0xf0c6ce5cfaee96073876a5fab7426043f3a798b79502c4caeb6d9772cd35af1f",supplyBalanceParentId:"0xc0a0cb43620eb8a84d5a4a50a85650e7fa7ba81e660f9cc2863404fd84591d4b"},usdy:{name:"USDY",assetId:12,coinType:"usdy",poolId:"0x4b6253a9f8cf7f5d31e6d04aed4046b9e325a1681d34e0eff11a8441525d4563",type:"0x960b531667636f39e85867775f52f6b1f220a058c4de786905bdf761e06a56bb::usdy::USDY",reserveObjectId:"",borrowBalanceParentId:"",supplyBalanceParentId:""}},borrowFee:.003,borrowFeeAddress:"0x70b9b10704263cf53392849e33b1f5fd16005869b4198ed5524836bad1234ea2"};async function gs(){if(!Su)try{let i=await fetch("https://open-api.naviprotocol.io/api/msafe").then(a=>a.json()),{packageId:e,borrowFee:t,borrowFeeAddress:n,pool:o}=i;e&&(_n.ProtocolPackage=e),t&&(_n.borrowFee=t),n&&(_n.borrowFeeAddress=n),o&&(_n.pool=o),Su=!0}catch(i){console.error(i.message)}}var Xt=_n;var ge=require("@msafe/sui3-utils"),ys=require("@mysten/sui.js/bcs"),ye=require("@mysten/sui.js/utils");var ha=class{constructor(e){this.txb=e}decode(){if(console.log("txb",this.txb),this.isClaimRewardTransaction())return this.decodeClaimReward();if(this.isEntryBorrowTransaction())return this.decodeEntryBorrow();if(this.isEntryBorrowWithFeeTransaction())return this.decodeEntryBorrow();if(this.isEntryMultiDepositTransaction())return this.decodeEntryMultiDeposit();if(this.isEntryDepositTransaction())return this.decodeEntryDeposit();if(this.isEntryRepayTransaction())return this.decodeEntryRepay();if(this.isEntryWithdrawTransaction())return this.decodeEntryWithdraw();if(this.isEntryClaimAndDepositTransaction())return this.decodeEntryClaimAndDeposit();throw new Error("Unknown transaction type")}get transactions(){return this.txb.blockData.transactions}getMoveCallTransaction(e){return this.transactions.find(t=>t.kind==="MoveCall"&&t.target===e)}isClaimRewardTransaction(){return!!this.transactions.find(t=>!!(t.kind==="MoveCall"&&t.target.includes("claim_reward")))}isEntryBorrowTransaction(){return!!this.getMoveCallTransaction(`${Xt.ProtocolPackage}::incentive_v3::entry_borrow`)}isEntryBorrowWithFeeTransaction(){return!!this.getMoveCallTransaction(`${Xt.ProtocolPackage}::incentive_v3::borrow`)}isEntryMultiDepositTransaction(){let e=`${Xt.ProtocolPackage}::incentive_v3::entry_deposit`,t=this.transactions.filter(o=>o.kind==="MoveCall"&&o.target===e);return this.transactions.find(o=>o.kind==="MoveCall"&&o.target.includes("claim_reward"))?!1:t.length>1}isEntryClaimAndDepositTransaction(){let e=`${Xt.ProtocolPackage}::incentive_v3::entry_deposit`,t=this.transactions.filter(o=>o.kind==="MoveCall"&&o.target===e);return!!(this.transactions.find(o=>o.kind==="MoveCall"&&o.target.includes("claim_reward"))&&t.length>0)}isEntryDepositTransaction(){return!!this.getMoveCallTransaction(`${Xt.ProtocolPackage}::incentive_v3::entry_deposit`)}isEntryRepayTransaction(){return!!this.getMoveCallTransaction(`${Xt.ProtocolPackage}::incentive_v3::entry_repay`)}isEntryWithdrawTransaction(){return!!this.getMoveCallTransaction(`${Xt.ProtocolPackage}::incentive_v3::withdraw`)}findPoolByAssetId(e){let t=Object.values(Xt.pool).find(n=>n.assetId===e);if(!t)throw new Error("Pool not found");return t}decodeEntryClaimAndDeposit(){return{txType:ge.TransactionType.Other,type:"EntryClaimAndDeposit",intentionData:{type:"entry_claim_and_deposit"}}}decodeClaimReward(){return console.log("decode claims"),{txType:ge.TransactionType.Other,type:"ClaimReward",intentionData:{type:"claim_reward"}}}decodeEntryBorrow(){let e=this.helper.decodeInputU8(4),t=this.helper.decodeInputU64(5);return{txType:ge.TransactionType.Other,type:"EntryBorrow",intentionData:{amount:t,assetId:e}}}decodeEntryMultiDeposit(){let e=[],t=`${Xt.ProtocolPackage}::incentive_v3::entry_deposit`;return this.transactions.forEach(n=>{if(n.kind==="MoveCall"&&n.target===t){let o=new ga(n,this.txb),a=o.decodeInputU8(3),c=o.decodeInputU64(5);e.push({assetId:a,amount:c})}}),{txType:ge.TransactionType.Other,type:"EntryMultiDeposit",intentionData:{list:e}}}decodeEntryDeposit(){let e=this.helper.decodeInputU8(3),t=this.helper.decodeInputU64(5);return{txType:ge.TransactionType.Other,type:"EntryDeposit",intentionData:{amount:t,assetId:e}}}decodeEntryRepay(){let e=this.helper.decodeInputU8(4),t=this.helper.decodeInputU64(6);return{txType:ge.TransactionType.Other,type:"EntryRepay",intentionData:{amount:t,assetId:e}}}decodeEntryWithdraw(){let e=this.helper.decodeInputU8(4),t=this.helper.decodeInputU64(5);return{txType:ge.TransactionType.Other,type:"EntryWithdraw",intentionData:{amount:t,assetId:e}}}get helper(){let e=this.transactions.find(t=>t.kind==="MoveCall"&&t.target.startsWith(Xt.ProtocolPackage));return new ga(e,this.txb)}},ga=class i{constructor(e,t){this.moveCall=e;this.txb=t}decodeSharedObjectId(e){let t=this.getInputParam(e);return i.getSharedObjectId(t)}decodeOwnedObjectId(e){let t=this.getInputParam(e);return i.getOwnedObjectId(t)}decodeInputU64(e){let t=this.decodePureArg(e,"u64");return Number(t)}decodeInputU8(e){let t=this.decodePureArg(e,"u8");return Number(t)}decodeInputAddress(e){let t=this.decodePureArg(e,"address");return(0,ye.normalizeSuiAddress)(t)}decodeInputString(e){return this.decodePureArg(e,"string")}decodeInputBool(e){return this.decodePureArg(e,"bool")}decodePureArg(e,t){let n=this.getInputParam(e);return i.getPureInputValue(n,t)}getInputParam(e){let t=this.moveCall.arguments[e];if(t.kind!=="Input")throw new Error("not input type");return this.txb.blockData.inputs[t.index]}static getPureInputValue(e,t){if(e.type!=="pure")throw new Error("not pure argument");if(typeof e.value=="object"&&"Pure"in e.value){let n=e.value.Pure;return ys.bcs.de(t,new Uint8Array(n))}return e.value}static getOwnedObjectId(e){if(e.type!=="object")throw new Error(`not object argument: ${JSON.stringify(e)}`);if(typeof e.value=="object"){if(!("Object"in e.value)||!("ImmOrOwned"in e.value.Object))throw new Error("not ImmOrOwned");return(0,ye.normalizeSuiAddress)(e.value.Object.ImmOrOwned.objectId)}return(0,ye.normalizeSuiAddress)(e.value)}static getSharedObjectId(e){if(e.type!=="object")throw new Error(`not object argument: ${JSON.stringify(e)}`);if(typeof e.value!="object")return(0,ye.normalizeSuiAddress)(e.value);if(!("Object"in e.value)||!("Shared"in e.value.Object))throw new Error("not Shared");return(0,ye.normalizeSuiAddress)(e.value.Object.Shared.objectId)}static getPureInput(e,t){if(e.type!=="pure")throw new Error("not pure argument");if(typeof e.value!="object")return e.value;if(!("Pure"in e.value))throw new Error("Pure not in value");let n=e.value.Pure;return ys.bcs.de(t,new Uint8Array(n))}typeArg(e){return(0,ye.normalizeStructTag)(this.moveCall.typeArguments[e])}txArg(e){return this.moveCall.arguments[e]}};var $t=require("navi-sdk");async function Ze(i,e,t,n){return await(0,$t.depositCoin)(i,e,t,n),i}async function Tu(i,e,t,n){let[o]=await(0,$t.withdrawCoin)(i,e,t);return i.transferObjects([o],i.pure(n)),i}async function Iu(i,e,t,n){let[o]=await(0,$t.borrowCoin)(i,e,t);return i.transferObjects([o],i.pure.address(n)),i}async function bs(i,e,t,n){return await(0,$t.repayDebt)(i,e,t,n),i}async function wu(i,e){return await(0,$t.claimAllRewardsPTB)(i,e)}async function Cu(i,e){return await(0,$t.claimAllRewardsResupplyPTB)(i,e)}var ya=class i extends _{constructor(t){super(t);this.data=t}txType;txSubType;async build(t){let{type:n}=this.data;return console.log("claim reward",n),await wu(t.suiClient,t.account.address)}static fromData(t){return new i(t)}};var ba=class i extends _{constructor(t){super(t);this.data=t}txType;txSubType;async build(t){let{type:n}=this.data;return console.log("claim reward and supply",n),await Cu(t.suiClient,t.account.address)}static fromData(t){return new i(t)}};var xu=require("@mysten/sui.js/transactions");var ku=require("navi-sdk");function Zt(i){return Object.values(ku.pool).find(e=>String(e.assetId)===String(i))}var Sa=class i extends _{constructor(t){super(t);this.data=t}txType;txSubType;async build(t){let{assetId:n,amount:o}=this.data,a=new xu.TransactionBlock;console.log("build",this.data);let c=Zt(n);return await Iu(a,c,o,t.account.address)}static fromData(t){return new i(t)}};var vu=require("@mysten/sui.js/transactions");async function tn(i,e,t){let n=await i.getCoins({owner:e,coinType:t});return console.log("getTokenObjs",e,n),n}var Ta=class i extends _{constructor(t){super(t);this.data=t}txType;txSubType;async build(t){let{suiClient:n,account:o}=t,{assetId:a,amount:c}=this.data,l=new vu.TransactionBlock;console.log("build",this.data);let d=Zt(a);if(a===0){let[k]=l.splitCoins(l.gas,[c]);return await Ze(l,d,k,c)}let b=await tn(n,o.address,d.type);if(!b.data[0])throw new Error(`Insufficient balance for ${d.name} Token`);let I=b.data[0].coinObjectId;if(b.data.length>=2){let k=1;for(;k<b.data.length;)l.mergeCoins(I,[b.data[k].coinObjectId]),k++}return await Ze(l,d,l.object(I),c)}static fromData(t){return new i(t)}};var Du=require("@mysten/sui.js/transactions");var Ia=class i extends _{constructor(t){super(t);this.data=t}txType;txSubType;async build(t){let{suiClient:n,account:o}=t,{assetId:a,amount:c}=this.data,l=new Du.TransactionBlock;console.log("build",this.data);let d=Zt(a);if(a===0){let[w]=l.splitCoins(l.gas,[c]);return bs(l,d,w,c)}let b=await tn(n,o.address,d.type);if(!b.data[0])throw new Error(`Insufficient balance for ${d.name} Token`);let I=b.data[0].coinObjectId;if(b.data.length>=2){let w=1;for(;w<b.data.length;)l.mergeCoins(I,[b.data[w].coinObjectId]),w++}return bs(l,d,l.object(I),c)}static fromData(t){return new i(t)}};var Au=require("@mysten/sui.js/transactions");var wa=class i extends _{constructor(t){super(t);this.data=t}txType;txSubType;async build(t){let{assetId:n,amount:o}=this.data,a=new Au.TransactionBlock;console.log("build",this.data);let c=Zt(n);return await Tu(a,c,o,t.account.address)}static fromData(t){return new i(t)}};var Mu=require("@mysten/sui.js/transactions");var Ca=class i extends _{constructor(t){super(t);this.data=t}txType;txSubType;async build(t){let{suiClient:n,account:o}=t,{list:a}=this.data,c=new Mu.TransactionBlock;console.log("build",this.data);for(let l=0;l<a.length;l++){let{assetId:d,amount:b}=a[l],I=Zt(d);if(d===0){let[x]=c.splitCoins(c.gas,[b]);await Ze(c,I,x,b);continue}let w=await tn(n,o.address,I.type);if(!w.data[0])throw new Error(`Insufficient balance for ${I.name} Token`);let k=w.data[0].coinObjectId;if(w.data.length>=2){let x=1;for(;x<w.data.length;)c.mergeCoins(k,[w.data[x].coinObjectId]),x++}await Ze(c,I,c.object(k),b)}return c}static fromData(t){return new i(t)}};var ka=class{application="navi";supportSDK="@mysten/sui.js";async deserialize(e){await gs();let{transactionBlock:t}=e,o=new ha(t).decode();return{txType:Ou.TransactionType.Other,txSubType:o.type,intentionData:o.intentionData}}async build(e){let{suiClient:t,account:n}=e,o;switch(await gs(),e.txSubType){case"EntryDeposit":o=Ta.fromData(e.intentionData);break;case"EntryBorrow":o=Sa.fromData(e.intentionData);break;case"EntryRepay":o=Ia.fromData(e.intentionData);break;case"EntryWithdraw":o=wa.fromData(e.intentionData);break;case"EntryMultiDeposit":o=Ca.fromData(e.intentionData);break;case"ClaimReward":o=ya.fromData(e.intentionData);break;case"EntryClaimAndDeposit":o=ba.fromData(e.intentionData);break;default:throw new Error("not implemented")}return o.build({suiClient:t,account:n})}};var Ln=require("@msafe/sui3-utils"),Pu=require("@mysten/bcs"),Ru=require("@mysten/sui/transactions"),Bu=Ut(require("sort-keys-recursive")),Eu="msafe-plain-tx",Nu=Ln.TransactionSubTypes.others.plain,Ss=class i{constructor(e){this.data=e}application=Eu;txType=Ln.TransactionType.Other;txSubType=Nu;serialize(){return JSON.stringify((0,Bu.default)(this.data))}async build(e){return Ru.Transaction.from((0,Pu.fromHex)(this.data.content))}static fromData(e){return new i(e)}},xa=class{application;supportSDK="@mysten/sui";constructor(){this.application=Eu}async deserialize(e){let{content:t}=e.appContext;return{txType:Ln.TransactionType.Other,txSubType:Nu,intentionData:{content:t}}}async build(e){let{suiClient:t,network:n,account:o}=e;return Ss.fromData(e.intentionData).build({suiClient:t,network:n,account:o})}};var ws=require("@mysten/sui/client"),Wu=require("@mysten/sui/transactions"),Aa=require("@mysten/sui.js/client"),_u=require("@mysten/sui.js/transactions");var en=require("@open-rpc/client-js");var Wd={"-32700":"ParseError","-32600":"InvalidRequest","-32601":"MethodNotFound","-32602":"InvalidParams","-32603":"InternalError"},Ts=class extends Error{},va=class extends Ts{code;type;constructor(e,t){super(e),this.code=t,this.type=Wd[t]??"ServerError"}};function _d(i){let e=new URL(i);return e.protocol=e.protocol.replace("http","ws"),e.toString()}var Ld={WebSocketConstructor:typeof WebSocket<"u"?WebSocket:void 0,callTimeout:3e4,reconnectTimeout:3e3,maxReconnects:5},Da=class{endpoint;options;#n=0;#a=0;#t=null;#e=null;#i=new Set;#o=new Map;constructor(e,t={}){this.endpoint=e,this.options={...Ld,...t},this.endpoint&&this.endpoint.startsWith("http")&&(this.endpoint=_d(this.endpoint))}async makeRequest(e,t){let n=await this.#r();return new Promise((o,a)=>{this.#n+=1,this.#o.set(this.#n,{resolve:o,reject:a,timeout:setTimeout(()=>{this.#o.delete(this.#n),a(new Error(`Request timeout: ${e}`))},this.options.callTimeout)}),n.send(JSON.stringify({jsonrpc:"2.0",id:this.#n,method:e,params:t}))}).then(({error:o,result:a})=>{if(o)throw new va(o.message,o.code);return a})}#r(){return this.#e?this.#e:(this.#e=new Promise(e=>{this.#t?.close(),this.#t=new this.options.WebSocketConstructor(this.endpoint),this.#t.addEventListener("open",()=>{this.#a=0,e(this.#t)}),this.#t.addEventListener("close",()=>{this.#a++,this.#a<=this.options.maxReconnects&&setTimeout(()=>{this.#s()},this.options.reconnectTimeout)}),this.#t.addEventListener("message",({data:t})=>{let n;try{n=JSON.parse(t)}catch(o){console.error(new Error(`Failed to parse RPC message: ${t}`,{cause:o}));return}if("id"in n&&n.id!=null&&this.#o.has(n.id)){let{resolve:o,timeout:a}=this.#o.get(n.id);clearTimeout(a),o(n)}else if("params"in n){let{params:o}=n;this.#i.forEach(a=>{a.subscriptionId===o.subscription&&o.subscription===a.subscriptionId&&a.onMessage(o.result)})}})}),this.#e)}async#s(){return this.#t?.close(),this.#e=null,Promise.allSettled([...this.#i].map(e=>e.subscribe(this)))}async subscribe(e){let t=new Is(e);return this.#i.add(t),await t.subscribe(this),()=>t.unsubscribe(this)}},Is=class{subscriptionId=null;input;subscribed=!1;constructor(e){this.input=e}onMessage(e){this.subscribed&&this.input.onMessage(e)}async unsubscribe(e){let{subscriptionId:t}=this;return this.subscribed=!1,t==null?!1:(this.subscriptionId=null,e.makeRequest(this.input.unsubscribe,[t]))}async subscribe(e){this.subscriptionId=null,this.subscribed=!0;let t=await e.makeRequest(this.input.method,this.input.params);this.subscribed&&(this.subscriptionId=t)}};var be=class{rpcClient;websocketClient;constructor({url:e,websocket:{url:t,...n}={},rpc:o}){let a=new en.HTTPTransport(o?.url??e,{headers:{"Content-Type":"application/json",...o?.headers}});this.rpcClient=new en.Client(new en.RequestManager([a])),this.websocketClient=new Da(t??e,n)}async request(e){return await this.rpcClient.request(e)}async subscribe(e){let t=await this.websocketClient.subscribe(e);return async()=>!!await t()}};var Ma=class i{apps;constructor(){this.apps=new Map}static fromHelpers(e){let t=new i;for(let n=0;n<e.length;n++){let o=e[n];switch(o.supportSDK){case"@mysten/sui.js":t.addLegacyHelper(o);break;case"@mysten/sui":t.addHelper(o);break;default:throw new Error(`${o.application}: ${o.supportSDK} SDK not supported`)}}return t}addLegacyHelper(e){this.apps.set(e.application,new ks(e))}addHelper(e){this.apps.set(e.application,new Cs(e))}getAppHelper(e){let t=this.apps.get(e);if(!t)throw new Error(`${e} not registered`);return t}},Cs=class{constructor(e){this.helper=e}async deserialize(e){let t=new ws.SuiClient({transport:new be({url:e.clientUrl,rpc:{url:e.clientUrl}})}),n=new Aa.SuiClient({transport:new be({url:e.clientUrl,rpc:{url:e.clientUrl}})}),o=await e.transactionBlock.build({client:n}),a=Wu.Transaction.from(o);return this.helper.deserialize({...e,suiClient:t,transaction:a})}async build(e){let t=new ws.SuiClient({transport:new be({url:e.clientUrl,rpc:{url:e.clientUrl}})}),n=await t.getBalance({owner:e.account.address});if(Number(n.totalBalance)<1e8)throw new Error("Insufficient gas fee");let o=await this.helper.build({...e,suiClient:t});o.setSender(e.account.address);let a=await o.build({client:t});return _u.TransactionBlock.from(a)}},ks=class{constructor(e){this.helper=e}async deserialize(e){let t=new Aa.SuiClient({transport:new be({url:e.clientUrl,rpc:{url:e.clientUrl}})});return this.helper.deserialize({...e,transactionBlock:e.transactionBlock,suiClient:t})}async build(e){let t=new Aa.SuiClient({transport:new be({url:e.clientUrl,rpc:{url:e.clientUrl}})}),n=await t.getBalance({owner:e.account.address});if(Number(n.totalBalance)<1e8)throw new Error("Insufficient gas fee");return this.helper.build({...e,suiClient:t})}};var Xu=require("@msafe/sui3-utils"),zu=require("@mysten/sui/client"),Gu=require("@scallop-io/sui-scallop-sdk");var Mt=require("@msafe/sui3-utils"),Ds=require("@scallop-io/sui-scallop-sdk");var Lu=require("@mysten/sui/utils"),Se=class{constructor(e,t){this.transaction=e;this.scallopClient=t;this.scallopClient=t,this.inputs=e.getData().inputs,this.commands=e.getData().commands,this.movecallsAsSet=new Set(this.commands.filter(this.isMoveCall).map(n=>`${n.MoveCall.package}::${n.MoveCall.module}::${n.MoveCall.function}`))}inputs;commands;movecallsAsSet;get address(){return this.scallopClient.address}get utils(){return this.scallopClient.utils}get coreId(){return{protocolPkg:this.address.get("core.packages.protocol.id"),market:this.address.get("core.market"),version:this.address.get("core.version"),coinDecimalsRegistry:this.address.get("core.coinDecimalsRegistry"),xOracle:this.address.get("core.oracles.xOracle"),spoolPkg:this.address.get("spool.id"),borrowIncentivePkg:this.address.get("borrowIncentive.id"),veScaPkgId:this.address.get("vesca.id"),veScaObjId:this.address.get("vesca.object"),scoin:this.address.get("scoin.id"),referral:this.address.get("referral.id")}}matchMoveCallCommand(e,t){let{address:n,module:o,name:a}=(0,Lu.parseStructTag)(t);return e?e.package===n&&e.module===o&&e.function===a:!1}isMoveCall(e){return e.$kind==="MoveCall"&&!!e.MoveCall}filterMoveCallCommands(e,t){return this.isMoveCall(e)&&this.matchMoveCallCommand(e.MoveCall,t)}getMoveCallCommands(e){let t=new Set(e),n=e.reduce((a,c,l)=>(a[c]=l,a),{}),o=[];return this.commands.forEach(a=>{this.isMoveCall(a)&&a.MoveCall&&t.has(a.MoveCall.package)&&(o[n[a.MoveCall.package]]=a.MoveCall)}),o}hasMoveCallCommand(e){return this.movecallsAsSet.has(e)}};var Oa=require("@mysten/sui/bcs"),Te=require("@mysten/sui/utils"),xs=class i{constructor(e,t,n=0){this.moveCall=e;this.transaction=t;let o=[];e?.MoveCall&&t.getData().commands.filter((a,c)=>{if(a.$kind==="MoveCall"){let l=`${a.MoveCall.package}::${a.MoveCall.module}::${a.MoveCall.function}`,d=`${e.MoveCall.package}::${e.MoveCall.module}::${e.MoveCall.function}`;return l===d?(o.push(c),!0):!1}return!1}),this.cmdIdx=o[n]}cmdIdx;get txBlockTransactions(){return this.transaction.blockData.transactions[this.cmdIdx]}decodeSharedObjectId(e){let t=this.getInputParam(e);return i.getSharedObjectId(t)}decodeOwnedObjectId(e){let t=this.getInputParam(e);return i.getOwnedObjectId(t)}decodeInputU64(e){let t=this.decodePureArg(e,"U64");return Number(t)}decodeInputU8(e){let t=this.decodePureArg(e,"U8");return Number(t)}decodeInputAddress(e){let t=this.decodePureArg(e,"Address");return(0,Te.normalizeSuiAddress)(t)}decodeInputString(e){return this.decodePureArg(e,"String")}decodeInputBool(e){return this.decodePureArg(e,"Bool")}decodePureArg(e,t){let n=this.getInputParam(e);return i.getPureInputValue(n,t)}getInputParam(e){let t=this.txBlockTransactions.arguments[e];if(t.kind!=="Input")throw new Error("not input type");return t}getNestedInputParam(e){let t=this.txBlockTransactions.arguments[e];if(t.kind!=="NestedResult")throw new Error("not input type");return this.transaction.blockData.transactions[t.index]}static getPureInputValue(e,t){if(e.type!=="pure")throw new Error("not pure argument");if(typeof e.value=="object"&&"Pure"in e.value){let n=e.value.Pure,o=Oa.bcs[t];return Oa.bcs[t].parse(new Uint8Array(n))}return e.value}static getOwnedObjectId(e){if(e.type!=="object")throw new Error(`not object argument: ${JSON.stringify(e)}`);if(typeof e.value=="object"){if(!("Object"in e.value)||!("ImmOrOwned"in e.value.Object))throw new Error("not ImmOrOwned");return(0,Te.normalizeSuiAddress)(e.value.Object.ImmOrOwned.objectId)}return(0,Te.normalizeSuiAddress)(e.value)}static getSharedObjectId(e){if(e.type!=="object")throw new Error(`not object argument: ${JSON.stringify(e)}`);if(typeof e.value!="object")return(0,Te.normalizeSuiAddress)(e.value);if(!("Object"in e.value)||!("Shared"in e.value.Object))throw new Error("not Shared");return(0,Te.normalizeSuiAddress)(e.value.Object.Shared.objectId)}static getPureInput(e){if(e.type!=="pure")throw new Error("not pure argument");if(typeof e.value!="object")return e.value;if(!("Pure"in e.value))throw new Error("Pure not in value");let t=e.value.Pure;return Oa.bcs.U64.parse(new Uint8Array(t))}typeArg(e){return(0,Te.normalizeStructTag)(this.txBlockTransactions.typeArguments[e])}txArg(e){return this.transaction.blockData.inputs[e]}},N=xs;var vs=class{constructor(e,t){this.splitCoin=e;this.txb=t}getAmountInput(){return this.splitCoin.amounts.map(e=>{if(e.kind==="Input")return Number(N.getPureInputValue(e,"U64"))}).filter(e=>e!==void 0)}},Bt=vs;var Ie=require("@mysten/sui/utils"),ju=async(i,e)=>{let t=await i.scallopSuiKit.client.getObject({id:e,options:{showContent:!0}});if(t?.data?.content?.dataType!=="moveObject")return!1;let o=t.data.content.fields.lock_key?.fields.name;if(!o)return!1;let a=i.address.get("borrowIncentive.object");return o===`${a.slice(2)}::incentive_account::IncentiveProgramLockKey`},nn={id:"0xc63072e7f5f4983a2efaf5bdba1480d5e7d74d57948e1c7cc436f8e22cbeb410",incentivePools:"0x64972b713ccec45ec3964809e477cea6f97350c0c50ca3aec85bb631639266ec",incentiveAccounts:"0x3c0b707068bdcea8bb859d751ad3e2149a9f83c13fcf4054ef91372a00bccdd3"},Vt={unstakeObligation:(i,e,t)=>i.moveCall(`${nn.id}::user::unstake`,[nn.incentivePools,nn.incentiveAccounts,i.object(e),i.object(t),Ie.SUI_CLOCK_OBJECT_ID],[(0,Ie.normalizeStructTag)(Ie.SUI_TYPE_ARG)]),redeem_rewards:(i,e,t,n)=>i.moveCall(`${nn.id}::user::redeem_rewards`,[nn.incentivePools,nn.incentiveAccounts,i.object(e),i.object(t),Ie.SUI_CLOCK_OBJECT_ID],[(0,Ie.normalizeStructTag)(n)])};var Uu=(i,e)=>{let t=[];for(let n=0;n<i.length;n+=e)t.push(i.slice(n,n+e));return t};var Pa=class extends Se{decode(){if(this.isSupplyWithStakeSpoolTransaction())return this.decodeSupplyWithStakeSpool();if(this.isUnstakeAndWithdrawTransaction())return this.decodeUnstakeAndWithdraw();if(this.isStakeSpoolTransaction())return this.decodeStakeSpool();if(this.isDepositCollateralTransaction())return this.decodeDepositCollateral();if(this.isWithdrawCollateralTransaction())return this.decodeWithdrawCollateral();if(this.isWithdrawLendingScoinTransaction())return this.decodeWithdrawLendingScoin();if(this.isWithdrawLendingTransaction())return this.decodeWithdrawLending();if(this.isSupplyLendingTransaction())return this.decodeSupplyLending();if(this.isBorrowWithReferralTransaction())return this.decodeBorrowWithReferral();if(this.isBorrowWithBoostTransaction())return this.decodeBorrowWithBoost();if(this.isBorrowTransaction())return this.decodeBorrow();if(this.isRepayWithBoostTransaction())return this.decodeRepayWithBoost();if(this.isRepayTransaction())return this.decodeRepay();if(this.isUnstakeSpoolTransaction())return this.decodeUnstakeSpool();if(this.isMigrateAndClaim())return this.decodeMigrateAndClaim();if(this.isClaimRewardTransaction())return this.decodeClaimReward();if(this.isOpenObligationTransaction())return this.decodeOpenObligation();if(this.isMigrateScoinTransaction())return this.decodeMigrateScoin()}isMigrateScoinTransaction(){return this.hasMoveCallCommand(`${this.coreId.scoin}::s_coin_converter::mint_s_coin`)}isSupplyLendingTransaction(){return this.hasMoveCallCommand(`${this.coreId.protocolPkg}::mint::mint`)}isSupplyWithStakeSpoolTransaction(){let e=this.hasMoveCallCommand(`${this.coreId.protocolPkg}::mint::mint`),t=this.hasMoveCallCommand(`${this.coreId.spoolPkg}::user::stake`);return e&&t}isUnstakeAndWithdrawTransaction(){let e=this.hasMoveCallCommand(`${this.coreId.spoolPkg}::user::unstake`),t=this.hasMoveCallCommand(`${this.coreId.protocolPkg}::redeem::redeem`);return e&&t}isStakeSpoolTransaction(){return this.hasMoveCallCommand(`${this.coreId.spoolPkg}::user::stake`)}isWithdrawLendingTransaction(){return this.hasMoveCallCommand(`${this.coreId.protocolPkg}::redeem::redeem`)}isWithdrawLendingScoinTransaction(){let e=this.hasMoveCallCommand(`${this.coreId.protocolPkg}::redeem::redeem`),t=this.hasMoveCallCommand(`${this.coreId.scoin}::s_coin_converter::burn_s_coin`);return e&&t}isDepositCollateralTransaction(){return this.hasMoveCallCommand(`${this.coreId.protocolPkg}::deposit_collateral::deposit_collateral`)}isWithdrawCollateralTransaction(){return this.hasMoveCallCommand(`${this.coreId.protocolPkg}::withdraw_collateral::withdraw_collateral`)}isBorrowTransaction(){return this.hasMoveCallCommand(`${this.coreId.protocolPkg}::borrow::borrow`)}isBorrowWithBoostTransaction(){let e=this.hasMoveCallCommand(`${this.coreId.protocolPkg}::borrow::borrow`),t=this.hasMoveCallCommand(`${this.coreId.borrowIncentivePkg}::user::stake_with_ve_sca_v2`);return e&&t}isBorrowWithReferralTransaction(){return this.hasMoveCallCommand(`${this.coreId.protocolPkg}::borrow::borrow_with_referral`)}isRepayTransaction(){return this.hasMoveCallCommand(`${this.coreId.protocolPkg}::repay::repay`)}isRepayWithBoostTransaction(){let e=this.hasMoveCallCommand(`${this.coreId.protocolPkg}::repay::repay`),t=this.hasMoveCallCommand(`${this.coreId.borrowIncentivePkg}::user::stake_with_ve_sca_v2`);return e&&t}isUnstakeSpoolTransaction(){return this.hasMoveCallCommand(`${this.coreId.spoolPkg}::user::unstake`)}isCreateStakeAccountTransaction(){return this.hasMoveCallCommand(`${this.coreId.spoolPkg}::user::new_spool_account`)}isClaimRewardTransaction(){let e=this.hasMoveCallCommand(`${this.coreId.spoolPkg}::user::redeem_rewards`),t=this.hasMoveCallCommand(`${this.coreId.borrowIncentivePkg}::user::redeem_rewards`);return e||t}isOpenObligationTransaction(){return this.hasMoveCallCommand(`${this.coreId.protocolPkg}::open_obligation::open_obligation`)}isMigrateAndClaim(){let e=this.hasMoveCallCommand(`${Ds.OLD_BORROW_INCENTIVE_PROTOCOL_ID}::user::redeem_rewards`),t=this.hasMoveCallCommand(`${this.coreId.borrowIncentivePkg}::user::stake_with_ve_sca_v2`),n=this.hasMoveCallCommand(`${this.coreId.borrowIncentivePkg}::user::stake`);return e&&(t||n)}get helperClaimLendingReward(){return this.commands.filter(t=>this.filterMoveCallCommands(t,`${this.coreId.spoolPkg}::user::redeem_rewards`)).map(t=>new N(t,this.transaction))}get helperClaimBorrowV2Reward(){return this.commands.filter(t=>this.filterMoveCallCommands(t,`${this.coreId.borrowIncentivePkg}::user::redeem_rewards`)).map(t=>new N(t,this.transaction))}get helperStakeObligationWithVeSca(){let e=this.commands.find(t=>this.filterMoveCallCommands(t,`${this.coreId.borrowIncentivePkg}::user::stake_with_ve_sca_v2`));return new N(e,this.transaction)}get helperClaimBorrowReward(){return this.commands.filter(t=>this.filterMoveCallCommands(t,`${Ds.OLD_BORROW_INCENTIVE_PROTOCOL_ID}::user::redeem_rewards`)).map(t=>new N(t,this.transaction))}get helperMint(){let e=this.commands.find(t=>this.filterMoveCallCommands(t,`${this.coreId.protocolPkg}::mint::mint`));return new N(e,this.transaction)}get helperUnstakes(){return this.commands.filter(t=>this.filterMoveCallCommands(t,`${this.coreId.spoolPkg}::user::unstake`)).map(t=>new N(t,this.transaction))}get helperRedeems(){return this.commands.filter(t=>this.filterMoveCallCommands(t,`${this.coreId.protocolPkg}::redeem::redeem`)).map(t=>new N(t,this.transaction))}get helperRedeem(){let e=this.commands.find(t=>this.filterMoveCallCommands(t,`${this.coreId.protocolPkg}::redeem::redeem`));return new N(e,this.transaction)}get helperBurnScoin(){let e=this.commands.find(t=>this.filterMoveCallCommands(t,`${this.coreId.scoin}::s_coin_converter::burn_s_coin`));return new N(e,this.transaction)}get helperStake(){let e=this.commands.find(t=>this.filterMoveCallCommands(t,`${this.coreId.spoolPkg}::user::stake`));return new N(e,this.transaction)}get helperUnstake(){let e=this.commands.find(t=>this.filterMoveCallCommands(t,`${this.coreId.spoolPkg}::user::unstake`));return new N(e,this.transaction)}get helperDepositCollateral(){let e=this.commands.find(t=>this.filterMoveCallCommands(t,`${this.coreId.protocolPkg}::deposit_collateral::deposit_collateral`));return new N(e,this.transaction)}get helperWithdrawCollateral(){let e=this.commands.find(t=>this.filterMoveCallCommands(t,`${this.coreId.protocolPkg}::withdraw_collateral::withdraw_collateral`));return new N(e,this.transaction)}get helperBorrow(){let e=this.commands.find(t=>this.filterMoveCallCommands(t,`${this.coreId.protocolPkg}::borrow::borrow`));return new N(e,this.transaction)}get helperBorrowWithReferral(){let e=this.commands.find(t=>this.filterMoveCallCommands(t,`${this.coreId.protocolPkg}::borrow::borrow_with_referral`));return new N(e,this.transaction)}get helperRepay(){let e=this.commands.find(t=>this.filterMoveCallCommands(t,`${this.coreId.protocolPkg}::repay::repay`));return new N(e,this.transaction)}decodeMigrateScoin(){return{txType:Mt.TransactionType.Other,type:"MigrateScoin",intentionData:{}}}decodeMigrateAndClaim(){let e;this.helperStakeObligationWithVeSca.moveCall&&(e=this.helperStakeObligationWithVeSca.decodeOwnedObjectId(9));let t=this.helperClaimBorrowReward[0].decodeOwnedObjectId(2),n=this.helperClaimBorrowReward[0].decodeSharedObjectId(3),o=this.utils.parseCoinNameFromType(this.helperClaimBorrowReward[0].typeArg(0));return{txType:Mt.TransactionType.Other,type:"MigrateAndClaim",intentionData:{obligationKey:t,obligationId:n,rewardCoinName:o,veScaKey:e}}}decodeOpenObligation(){return{txType:Mt.TransactionType.Other,type:"OpenObligation",intentionData:{}}}decodeSupplyLending(){let e=this.utils.parseCoinNameFromType(this.helperMint.typeArg(0)),t=this.helperMint.getNestedInputParam(2),n=new Bt(t,this.transaction).getAmountInput().reduce((o,a)=>o+a,0);return{txType:Mt.TransactionType.Other,type:"SupplyLending",intentionData:{amount:n,coinName:e}}}decodeWithdrawLending(){let e=this.utils.parseCoinNameFromType(this.helperRedeem.typeArg(0)),t=this.helperRedeem.getNestedInputParam(2),n=new Bt(t,this.transaction).getAmountInput().reduce((o,a)=>o+a,0);return{txType:Mt.TransactionType.Other,type:"WithdrawLending",intentionData:{amount:n,coinName:e}}}decodeWithdrawLendingScoin(){let e=this.utils.parseCoinNameFromType(this.helperRedeem.typeArg(0));console.log({coinName:e});let t=this.helperBurnScoin.getNestedInputParam(1),n=new Bt(t,this.transaction).getAmountInput().reduce((o,a)=>o+a,0);return{txType:Mt.TransactionType.Other,type:"WithdrawLending",intentionData:{amount:n,coinName:e}}}decodeDepositCollateral(){let e=this.utils.parseCoinNameFromType(this.helperDepositCollateral.typeArg(0)),t=this.helperDepositCollateral.getNestedInputParam(3),n=new Bt(t,this.transaction).getAmountInput().reduce((a,c)=>a+c,0),o=this.helperDepositCollateral.decodeSharedObjectId(1);return{txType:Mt.TransactionType.Other,type:"DepositCollateral",intentionData:{amount:n,obligationId:o,collateralCoinName:e}}}decodeWithdrawCollateral(){let e=this.utils.parseCoinNameFromType(this.helperWithdrawCollateral.typeArg(0)),t=this.helperWithdrawCollateral.decodeInputU64(5),n=this.helperWithdrawCollateral.decodeSharedObjectId(1),o=this.helperWithdrawCollateral.decodeOwnedObjectId(2);return{txType:Mt.TransactionType.Other,type:"WithdrawCollateral",intentionData:{amount:t,collateralCoinName:e,obligationKey:o,obligationId:n}}}decodeBorrow(){let e=this.utils.parseCoinNameFromType(this.helperBorrow.typeArg(0)),t=this.helperBorrow.decodeInputU64(5),n=this.helperBorrow.decodeSharedObjectId(1),o=this.helperBorrow.decodeOwnedObjectId(2);return{txType:Mt.TransactionType.Other,type:"Borrow",intentionData:{amount:t,coinName:e,obligationKey:o,obligationId:n}}}decodeBorrowWithBoost(){let e=this.utils.parseCoinNameFromType(this.helperBorrow.typeArg(0)),t=this.helperStakeObligationWithVeSca.decodeOwnedObjectId(9),n=this.helperBorrow.decodeInputU64(5),o=this.helperBorrow.decodeSharedObjectId(1),a=this.helperBorrow.decodeOwnedObjectId(2);return{txType:Mt.TransactionType.Other,type:"BorrowWithBoost",intentionData:{amount:n,coinName:e,obligationKey:a,obligationId:o,veScaKey:t}}}decodeBorrowWithReferral(){let e=this.utils.parseCoinNameFromType(this.helperBorrowWithReferral.typeArg(0)),t;this.helperStakeObligationWithVeSca.moveCall&&(t=this.helperStakeObligationWithVeSca.decodeOwnedObjectId(9));let n=this.helperBorrowWithReferral.decodeInputU64(6),o=this.helperBorrowWithReferral.decodeSharedObjectId(1),a=this.helperBorrowWithReferral.decodeOwnedObjectId(2);return{txType:Mt.TransactionType.Other,type:"BorrowWithReferral",intentionData:{amount:n,coinName:e,obligationKey:a,obligationId:o,veScaKey:t}}}decodeRepay(){let e=this.utils.parseCoinNameFromType(this.helperRepay.typeArg(0)),t=this.helperRepay.getNestedInputParam(3),n=new Bt(t,this.transaction).getAmountInput().reduce((a,c)=>a+c,0),o=this.helperRepay.decodeSharedObjectId(1);return{txType:Mt.TransactionType.Other,type:"Repay",intentionData:{amount:n,obligationId:o,coinName:e}}}decodeRepayWithBoost(){let e=this.utils.parseCoinNameFromType(this.helperRepay.typeArg(0)),t=this.helperStakeObligationWithVeSca.decodeOwnedObjectId(9),n=this.helperRepay.getNestedInputParam(3),o=new Bt(n,this.transaction).getAmountInput().reduce((c,l)=>c+l,0),a=this.helperRepay.decodeSharedObjectId(1);return{txType:Mt.TransactionType.Other,type:"RepayWithBoost",intentionData:{amount:o,obligationId:a,coinName:e,veScaKey:t}}}decodeStakeSpool(){let e;this.isCreateStakeAccountTransaction()||(e=this.helperStake.decodeOwnedObjectId(1));let t=0;if(this.helperBurnScoin.moveCall){let a=this.helperBurnScoin.getNestedInputParam(1);t=new Bt(a,this.transaction).getAmountInput().reduce((c,l)=>c+l,0)}if(this.helperStake.moveCall&&t===0){let a=this.helperStake.getNestedInputParam(2);t=new Bt(a,this.transaction).getAmountInput().reduce((c,l)=>c+l,0)}let n=this.helperStake.typeArg(0),o=this.utils.parseCoinNameFromType(n);return{txType:Mt.TransactionType.Other,type:"StakeSpool",intentionData:{amount:t,marketCoinName:o,stakeAccountId:e}}}decodeUnstakeSpool(){let e=this.helperUnstake.decodeOwnedObjectId(1),t=this.helperUnstake.decodeInputU64(2),n=this.helperUnstake.typeArg(0),o=this.utils.parseCoinNameFromType(n);return{txType:Mt.TransactionType.Other,type:"UnstakeSpool",intentionData:{amount:t,marketCoinName:o,stakeAccountId:e}}}decodeSupplyWithStakeSpool(){let e=this.utils.parseCoinNameFromType(this.helperMint.typeArg(0)),t=this.helperMint.getNestedInputParam(2),n=new Bt(t,this.transaction).getAmountInput().reduce((a,c)=>a+c,0),o;return this.isCreateStakeAccountTransaction()||(o=this.helperStake.decodeOwnedObjectId(1)),{txType:Mt.TransactionType.Other,type:"SupplyAndStakeLending",intentionData:{amount:n,coinName:e,stakeAccountId:o}}}decodeUnstakeAndWithdraw(){let e=[];this.helperUnstakes.forEach(o=>{let a=o.decodeOwnedObjectId(1),c=o.decodeInputU64(2);e.push({id:a,coin:c})});let t=this.utils.parseCoinNameFromType(this.helperRedeems[0].typeArg(0)),n=0;if(this.helperBurnScoin.moveCall){let o=this.helperBurnScoin.getNestedInputParam(1);n=new Bt(o,this.transaction).getAmountInput().reduce((a,c)=>a+c,0)}return{txType:Mt.TransactionType.Other,type:"WithdrawAndUnstakeLending",intentionData:{amount:n,coinName:t,stakeAccountId:e}}}decodeClaimReward(){let e=[],t=[],n=[];return this.helperClaimLendingReward.forEach(o=>{let a=o.decodeOwnedObjectId(2),c=o.typeArg(0),l=this.utils.parseCoinNameFromType(c);e.push({stakeMarketCoinName:l,stakeAccountId:a})}),this.helperClaimBorrowV2Reward.forEach(o=>{let a=o.decodeSharedObjectId(4),c=o.decodeOwnedObjectId(3),l=this.utils.parseCoinNameFromType(o.typeArg(0));t.push({obligationId:c,obligationKey:a,rewardCoinName:l})}),this.helperClaimBorrowReward.forEach(o=>{let a=o.decodeSharedObjectId(2),c=o.decodeOwnedObjectId(3),l=this.utils.parseCoinNameFromType(o.typeArg(0));n.push({obligationId:c,obligationKey:a,rewardCoinName:l})}),{txType:Mt.TransactionType.Other,type:"ClaimIncentiveReward",intentionData:{lendingIncentive:e,borrowIncentiveV2:t,borrowIncentive:n}}}};var Ra=require("@msafe/sui3-utils");var Ba=class extends Se{decode(){if(this.isCreateReferralLink())return this.decodeCreateReferralLink();if(this.isClaimRevenueReferral())return this.decodeClaimRevenueReferral();if(this.isBindReferral())return this.decodeBindReferral()}isClaimRevenueReferral(){return this.hasMoveCallCommand(`${this.coreId.referral}::referral_revenue_pool::claim_revenue_with_ve_sca_key`)}isCreateReferralLink(){return this.hasMoveCallCommand(`${this.coreId.veScaPkgId}::ve_sca::mint_ve_sca_placeholder_key`)}isBindReferral(){return this.hasMoveCallCommand(`${this.coreId.referral}::referral_bindings::bind_ve_sca_referrer`)}get helperClaimRevenueReferral(){return this.commands.filter(t=>this.filterMoveCallCommands(t,`${this.coreId.referral}::referral_revenue_pool::claim_revenue_with_ve_sca_key`)).map(t=>new N(t,this.transaction))}get helperBindReferral(){let e=this.commands.find(t=>this.filterMoveCallCommands(t,`${this.coreId.referral}::referral_bindings::bind_ve_sca_referrer`));return new N(e,this.transaction)}decodeCreateReferralLink(){return{txType:Ra.TransactionType.Other,type:"CreateReferralLink",intentionData:{}}}decodeClaimRevenueReferral(){let e=this.helperClaimRevenueReferral[0].decodeOwnedObjectId(2),t=this.helperClaimRevenueReferral.map(n=>n.typeArg(0));return{txType:Ra.TransactionType.Other,type:"ClaimRevenueReferral",intentionData:{veScaKey:e,coins:t}}}decodeBindReferral(){let e=this.helperBindReferral.decodePureArg(1,"Address");return{txType:Ra.TransactionType.Other,type:"BindReferral",intentionData:{veScaKey:e}}}};var te=require("@msafe/sui3-utils"),qu=require("@scallop-io/sui-scallop-sdk");var Ea=class extends Se{async decode(){if(this.isExtendPeriodAndStakeMoreSca())return this.decodePeriodAndStakeMoreSca();if(this.isStakeScaFirsTime()||this.isStakeMoreSca())return this.decodeStakeSca();if(this.isRenewExpiredVeSca())return this.decodeRenewExpiredVeSca();if(this.isExtendPeriod())return this.decodeExtendStakePeriod();if(this.isRedeemSca())return this.decodeRedeemSca();if(this.isMergeVeSca())return this.decodeMergeVesca();if(this.isSplitVeSca())return this.decodeSplitVesca();if(this.isVeScaObligationBindings())return this.decodeVeScaObligationBindings();if(await this.isTransferVeScaKey())return this.decodeTransferVeScaKey()}isStakeScaFirsTime(){return this.hasMoveCallCommand(`${this.coreId.veScaPkgId}::ve_sca::mint_ve_sca_key`)}isExtendPeriodAndStakeMoreSca(){let e=this.hasMoveCallCommand(`${this.coreId.veScaPkgId}::ve_sca::extend_lock_period`),t=this.hasMoveCallCommand(`${this.coreId.veScaPkgId}::ve_sca::lock_more_sca`);return!!e&&!!t}isRedeemSca(){return this.hasMoveCallCommand(`${this.coreId.veScaPkgId}::ve_sca::redeem`)}isStakeMoreSca(){return this.hasMoveCallCommand(`${this.coreId.veScaPkgId}::ve_sca::lock_more_sca`)}isExtendPeriod(){return this.hasMoveCallCommand(`${this.coreId.veScaPkgId}::ve_sca::extend_lock_period`)}isRenewExpiredVeSca(){return this.hasMoveCallCommand(`${this.coreId.veScaPkgId}::ve_sca::renew_expired_ve_sca`)}isMergeVeSca(){return this.hasMoveCallCommand(`${this.coreId.veScaPkgId}::ve_sca::merge`)}isSplitVeSca(){return this.hasMoveCallCommand(`${this.coreId.veScaPkgId}::ve_sca::split`)}isVeScaObligationBindings(){let e=this.commands.filter(l=>this.filterMoveCallCommands(l,`${this.coreId.borrowIncentivePkg}::user::unstake_v2`)),t=this.commands.filter(l=>this.filterMoveCallCommands(l,`${this.coreId.borrowIncentivePkg}::user::stake_with_ve_sca_v2`)),n=this.commands.filter(l=>this.filterMoveCallCommands(l,`${this.coreId.borrowIncentivePkg}::user::deactivate_boost_v2`)),o=e.length>0&&t.length>0&&e.length===t.length,a=n.length>0;return this.commands.length===e.length+t.length+n.length&&(o||a)}async isTransferVeScaKey(){let e=this.commands.filter(d=>d.$kind==="TransferObjects");if(e.length!==1)return!1;let{objects:t}=e[0].TransferObjects,n=t.filter(d=>d.$kind==="Input").map(({Input:d})=>d);if(n.length!==t.length)return!1;let o=new Set(n),a=this.inputs.filter((d,b)=>d.$kind==="Object"&&o.has(b)).map(d=>d.Object.ImmOrOwnedObject),c=`${this.coreId.veScaObjId}::ve_sca::VeScaKey`,l=Uu(a.map(({objectId:d})=>d),50);for(let d=0;d<l.length;d++){let b=l[d];if((await this.scallopClient.scallopSuiKit.queryGetObjects(b,{showType:!0})).some(w=>w.type!==c))return!1}return a.length>0}get helperStakeMoreSca(){let e=this.commands.find(t=>this.filterMoveCallCommands(t,`${this.coreId.veScaPkgId}::ve_sca::lock_more_sca`));return new N(e,this.transaction)}get helperStakeSca(){let e=this.commands.find(t=>this.filterMoveCallCommands(t,`${this.coreId.veScaPkgId}::ve_sca::mint_ve_sca_key`));return new N(e,this.transaction)}get helperExtendStakePeriod(){let e=this.commands.find(t=>this.filterMoveCallCommands(t,`${this.coreId.veScaPkgId}::ve_sca::extend_lock_period`));return new N(e,this.transaction)}get helperRedeemSca(){let e=this.commands.find(t=>this.filterMoveCallCommands(t,`${this.coreId.veScaPkgId}::ve_sca::redeem`));return new N(e,this.transaction)}get helperRenewExpired(){let e=this.commands.find(t=>this.filterMoveCallCommands(t,`${this.coreId.veScaPkgId}::ve_sca::renew_expired_ve_sca`));return new N(e,this.transaction)}get helperOldUnstakeObligation(){let e=this.commands.find(t=>this.filterMoveCallCommands(t,`${qu.OLD_BORROW_INCENTIVE_PROTOCOL_ID}::user::unstake`));return new N(e,this.transaction)}get helperUnstakeObligation(){let e=this.commands.find(t=>this.filterMoveCallCommands(t,`${this.coreId.borrowIncentivePkg}::user::unstake_v2`));return new N(e,this.transaction)}get helperStakeObligationWithVeSca(){let e=this.commands.find(t=>this.filterMoveCallCommands(t,`${this.coreId.borrowIncentivePkg}::user::stake_with_ve_sca_v2`));return new N(e,this.transaction)}getMergeSplitVeScaHelper(e){let t=this.commands.find(n=>this.filterMoveCallCommands(n,`${this.coreId.veScaPkgId}::ve_sca::${e}`));return new N(t,this.transaction)}getVeScaObligationBindingHelpers(){let e=`${this.coreId.borrowIncentivePkg}::user::unstake_v2`,t=`${this.coreId.borrowIncentivePkg}::user::stake_with_ve_sca_v2`,n=`${this.coreId.borrowIncentivePkg}::user::deactivate_boost_v2`,o=[],a=0,c=0,l=0;return this.commands.forEach(d=>{this.filterMoveCallCommands(d,e)?(o.push({action:"unstake",helper:new N(d,this.transaction,a)}),a++):this.filterMoveCallCommands(d,t)?(o.push({action:"stake",helper:new N(d,this.transaction,c)}),c++):this.filterMoveCallCommands(d,n)&&(o.push({action:"deactivate",helper:new N(d,this.transaction,l)}),l++)}),o}decodeRedeemSca(){let e=this.helperRedeemSca.decodeOwnedObjectId(1);return{txType:te.TransactionType.Other,type:"RedeemSca",intentionData:{veScaKey:e}}}decodeRenewExpiredVeSca(){let e=this.helperRenewExpired.getNestedInputParam(4),t=this.helperRenewExpired.decodeInputU64(5),n=new Bt(e,this.transaction).getAmountInput().reduce((v,P)=>v+P,0),o=this.helperRenewExpired.decodeOwnedObjectId(1),a=!!this.helperRedeemSca.moveCall,c=[],l=[],d=[];this.helperOldUnstakeObligation.moveCall&&(c=[this.helperOldUnstakeObligation.decodeOwnedObjectId(2),this.helperOldUnstakeObligation.decodeSharedObjectId(3)]),this.helperUnstakeObligation.moveCall&&(l=[this.helperUnstakeObligation.decodeOwnedObjectId(3),this.helperUnstakeObligation.decodeSharedObjectId(4)]),this.helperStakeObligationWithVeSca.moveCall&&(d=[this.helperStakeObligationWithVeSca.decodeOwnedObjectId(3),this.helperStakeObligationWithVeSca.decodeSharedObjectId(4)]);let b=!1,I=!1,w,k,x=[{condition:c,isOld:!0},{condition:l,isOld:!1},{condition:d,isOld:!1}];for(let v=0;v<x.length;v++)x[v].condition.length>1&&([k,w]=x[v].condition,b=!0,I=x[v].isOld);return{txType:te.TransactionType.Other,type:"RenewExpStakePeriod",intentionData:{amount:n,unlockTime:t,obligationId:w,obligationKey:k,veScaKey:o,isHaveRedeem:a,isObligationLocked:b,isOldBorrowIncentive:I}}}decodeExtendStakePeriod(){let e=this.helperExtendStakePeriod.decodeInputU64(4),t=this.helperExtendStakePeriod.decodeOwnedObjectId(1),n=[],o=[],a=[];this.helperOldUnstakeObligation.moveCall&&(n=[this.helperOldUnstakeObligation.decodeOwnedObjectId(2),this.helperOldUnstakeObligation.decodeSharedObjectId(3)]),this.helperUnstakeObligation.moveCall&&(o=[this.helperUnstakeObligation.decodeOwnedObjectId(3),this.helperUnstakeObligation.decodeSharedObjectId(4)]),this.helperStakeObligationWithVeSca.moveCall&&(a=[this.helperStakeObligationWithVeSca.decodeOwnedObjectId(3),this.helperStakeObligationWithVeSca.decodeSharedObjectId(4)]);let c=!1,l=!1,d,b,I=[{condition:n,isOld:!0},{condition:o,isOld:!1},{condition:a,isOld:!1}];for(let w=0;w<I.length;w++)I[w].condition.length>1&&([b,d]=I[w].condition,c=!0,l=I[w].isOld);return{txType:te.TransactionType.Other,type:"ExtendStakePeriod",intentionData:{unlockTime:e,obligationId:d,obligationKey:b,veScaKey:t,isObligationLocked:c,isOldBorrowIncentive:l}}}decodePeriodAndStakeMoreSca(){let e=this.helperStakeMoreSca.getNestedInputParam(4),t=this.helperExtendStakePeriod.decodeInputU64(4),n=new Bt(e,this.transaction).getAmountInput().reduce((x,v)=>x+v,0),o=[],a=[],c,l=[];this.helperOldUnstakeObligation.moveCall&&(o=[this.helperOldUnstakeObligation.decodeOwnedObjectId(2),this.helperOldUnstakeObligation.decodeSharedObjectId(3)]),this.helperUnstakeObligation.moveCall&&(a=[this.helperUnstakeObligation.decodeOwnedObjectId(3),this.helperUnstakeObligation.decodeSharedObjectId(4)]),this.helperStakeMoreSca.moveCall&&(c=this.helperStakeMoreSca.decodeOwnedObjectId(1)),this.helperStakeObligationWithVeSca.moveCall&&(l=[this.helperStakeObligationWithVeSca.decodeOwnedObjectId(3),this.helperStakeObligationWithVeSca.decodeSharedObjectId(4)]);let d=!1,b=!1,I,w,k=[{condition:o,isOld:!0},{condition:a,isOld:!1},{condition:l,isOld:!1}];for(let x=0;x<k.length;x++)k[x].condition.length>1&&([w,I]=k[x].condition,d=!0,b=k[x].isOld);return{txType:te.TransactionType.Other,type:"ExtendPeriodAndStakeMore",intentionData:{amount:n,veScaKey:c,unlockTime:t,obligationId:I,obligationKey:w,isOldBorrowIncentive:b,isObligationLocked:d}}}decodeStakeSca(){let e,t;this.helperStakeSca.moveCall&&this.helperStakeMoreSca.moveCall===void 0?(e=this.helperStakeSca.getNestedInputParam(3),t=this.helperStakeSca.decodeInputU64(4)):e=this.helperStakeMoreSca.getNestedInputParam(4);let n=new Bt(e,this.transaction).getAmountInput().reduce((x,v)=>x+v,0),o=[],a=[],c,l=[];this.helperOldUnstakeObligation.moveCall&&(o=[this.helperOldUnstakeObligation.decodeOwnedObjectId(2),this.helperOldUnstakeObligation.decodeSharedObjectId(3)]),this.helperUnstakeObligation.moveCall&&(a=[this.helperUnstakeObligation.decodeOwnedObjectId(3),this.helperUnstakeObligation.decodeSharedObjectId(4)]),this.helperStakeMoreSca.moveCall&&(c=this.helperStakeMoreSca.decodeOwnedObjectId(1)),this.helperStakeObligationWithVeSca.moveCall&&(l=[this.helperStakeObligationWithVeSca.decodeOwnedObjectId(3),this.helperStakeObligationWithVeSca.decodeSharedObjectId(4)]);let d=!1,b=!1,I,w,k=[{condition:o,isOld:!0},{condition:a,isOld:!1},{condition:l,isOld:!1}];for(let x=0;x<k.length;x++)k[x].condition.length>1&&([w,I]=k[x].condition,d=!0,b=k[x].isOld);return{txType:te.TransactionType.Other,type:"StakeSca",intentionData:{amount:n,unlockTime:t,obligationId:I,obligationKey:w,veScaKey:c,isObligationLocked:d,isOldBorrowIncentive:b}}}decodeMergeVesca(){let e=this.getMergeSplitVeScaHelper("merge"),t={targetVeScaKey:e.decodeOwnedObjectId(1),sourceVeScaKey:e.decodeOwnedObjectId(2)};return{txType:te.TransactionType.Other,type:"MergeVeSca",intentionData:t}}decodeSplitVesca(){let e=this.getMergeSplitVeScaHelper("split"),t={targetVeScaKey:e.decodeOwnedObjectId(1),splitAmount:e.decodeInputU64(4)};return{txType:te.TransactionType.Other,type:"SplitVeSca",intentionData:t}}decodeVeScaObligationBindings(){let e=this.getVeScaObligationBindingHelpers(),t=(o,a)=>{switch(o){case"stake":return{veScaKey:a.decodeOwnedObjectId(9),obligationId:a.decodeSharedObjectId(4),obligationKey:a.decodeOwnedObjectId(3)};case"unstake":return{obligationId:a.decodeSharedObjectId(4),obligationKey:a.decodeOwnedObjectId(3)};case"deactivate":return{veScaKey:a.decodeOwnedObjectId(4),obligationId:a.decodeSharedObjectId(3)};default:throw new Error(`Invalid action ${o}`)}},n=e.map(({action:o,helper:a})=>({action:o,args:t(o,a)}));return{txType:te.TransactionType.Other,type:"VeScaObligationBindings",intentionData:{bindingDatas:n}}}decodeTransferVeScaKey(){let e=this.commands.filter(c=>c.$kind==="TransferObjects"),{objects:t}=e[0].TransferObjects,n=t.filter(c=>c.$kind==="Input").map(({Input:c})=>c);if(n.length!==t.length)return!1;let o=new Set(n),a=this.inputs.filter((c,l)=>c.$kind==="Object"&&o.has(l)).map(c=>c.Object.ImmOrOwnedObject);return{xType:te.TransactionType.Other,type:"TransferVeScaKeys",intentionData:{veScaKeys:a}}}};var Fu=Ut(require("sort-keys-recursive")),A=class{constructor(e){this.data=e}get application(){return"msafe-core"}serialize(){return JSON.stringify((0,Fu.default)(this.data))}isObligationLocked=async(e,t)=>{let n=await e.getObject({id:typeof t=="string"?t:t.objectId,options:{showContent:!0}}),o=!1;return n&&n?.data.content?.dataType==="moveObject"&&"lock_key"in n.data.content.fields&&(o=!!n.data.content.fields.lock_key),o};async buildTxWithRefreshObligation(e,t,n){let o=e.builder.createTxBlock();o.setSender(t.walletAddress);let{obligationId:a,obligationKey:c}=t;return await this.isObligationLocked(e.scallopSuiKit.client,a)?(await o.unstakeObligationQuick(a,c),await n(e,o,t),await o.stakeObligationWithVeScaQuick(a,c,t.veScaKey)):await n(e,o,t),o}};var Na=class i extends A{constructor(t){super(t);this.data=t}txType;txSubType;async borrow({account:t,scallopClient:n}){let{coinName:o,amount:a,obligationId:c,obligationKey:l}=this.data,d=t.address;return(await this.buildTxWithRefreshObligation(n,{walletAddress:d,obligationId:c,obligationKey:l},async(I,w)=>{let k=await w.borrowQuick(+a,o,c,l);w.transferObjects([k],d)})).txBlock}async build(t){return this.borrow(t)}static fromData(t){return new i(t)}};var Wa=class i extends A{constructor(t){super(t);this.data=t}txType;txSubType;async borrowWithBoost(t,n){let{obligationId:o,obligationKey:a,veScaKey:c,amount:l,coinName:d}=this.data;return(await this.buildTxWithRefreshObligation(t,{walletAddress:n,obligationId:o,obligationKey:a,veScaKey:c},async(I,w)=>{let k=await w.borrowQuick(+l,d,o,a);w.transferObjects([k],n)})).txBlock}async build(t){return this.borrowWithBoost(t.scallopClient,t.account.address)}static fromData(t){return new i(t)}};var _a=class i extends A{constructor(t){super(t);this.data=t}txType;txSubType;async borrowWithReferral({account:t,scallopClient:n}){let o=t.address,{obligationId:a,obligationKey:c,veScaKey:l,coinName:d,amount:b}=this.data;return(await this.buildTxWithRefreshObligation(n,{walletAddress:o,obligationId:a,obligationKey:c,veScaKey:l},async(w,k)=>{let x=k.claimReferralTicket(d),v=await k.borrowWithReferralQuick(+b,d,x,a,c);k.burnReferralTicket(x,d),k.transferObjects([v],o)})).txBlock}async build(t){return this.borrowWithReferral(t)}static fromData(t){return new i(t)}};var Ku=require("@mysten/sui/utils");var La=class i extends A{txType;txSubType;constructor(e={}){super(e)}async claimIncentiveRewards(e,t){let n=e.builder.createTxBlock();n.setSender(t);let o=await e.query.getAllStakeAccounts(t),a=await e.query.getLendings(void 0,t),c=await e.query.getObligations(t),l=Object.values(await e.query.getObligationAccounts(t)??[]),d=(()=>{let k=[...e.constants.whitelist.spool].map(x=>e.utils.parseCoinName(x));return Object.values(a??[]).filter(x=>!!x&&k.includes(x.coinName)).reduce((x,v)=>{let P=e.utils.parseMarketCoinName(v.coinName);return x[P]||(x[P]=0),x[P]+=v.availableClaimCoin,x},{})})(),b={};Object.entries(o).forEach(([k,x])=>{for(let v=0;v<x.length;v++){let P=x[v];if(!d[k])continue;let K=n.claim(P.id,k);b.sui?b.sui.push(K):b.sui=[K]}});let I=(()=>{let k={};return k.sui=Object.values(d).reduce((x,v)=>x+v,0),l.forEach(x=>{Object.values(x.borrowIncentives).forEach(v=>{v&&v.rewards.forEach(P=>{k[P.coinName]||(k[P.coinName]=0),k[P.coinName]?k[P.coinName]+=P.availableClaimCoin:k[P.coinName]=P.availableClaimCoin})})}),k})();if(c.length>0&&l.length>0)for(let k=0;k<l.length;k++){let x=l[k],v=!1,P=c.find(H=>H.id===x.obligationId)?.keyId,K={};if(P){if(Object.values(x.borrowIncentives).forEach(H=>{if(H){let Et=H.rewards.filter(Wt=>{let Ot=Wt.coinName;return Wt.availableClaimCoin>0&&!K[Ot]});v=Et.length>0,Et.forEach(Wt=>{let Ot=n.claimBorrowIncentive(x.obligationId,P,Wt.coinName);K[Wt.coinName]=!0,b[Wt.coinName]?b[Wt.coinName].push(Ot):b[Wt.coinName]=[Ot]})}}),I.sui>0){let H=Vt.redeem_rewards(n,P,x.obligationId,Ku.SUI_TYPE_ARG);b.sui?b.sui.push(H):b.sui=[H]}if(v&&await ju(e.query,x.obligationId)){n.unstakeObligation(x.obligationId,P);let Et=await e.query.getBindedVeScaKey(x.obligationId);Et?n.stakeObligationWithVesca(x.obligationId,P,Et):n.stakeObligation(x.obligationId,P)}}}let w=(await Promise.all(Object.entries(b).map(async([k,x])=>{let v=x[0];if(x.length>1&&n.mergeCoins(v,x.slice(1)),k==="sui"){n.mergeCoins(n.gas,[v]);return}return await e.builder.utils.mergeSimilarCoins(n,v,e.utils.parseCoinType(k),t),v}))).filter(k=>!!k);return w.length>0&&n.transferObjects(w,t),n.txBlock}async build(e){return this.claimIncentiveRewards(e.scallopClient,e.account.address)}static fromData(e={}){return new i(e)}};var ja=class i extends A{constructor(t){super(t);this.data=t}txType;txSubType;async build(t){return t.scallopClient.depositCollateral(this.data.collateralCoinName,+this.data.amount,!1,this.data.obligationId)}static fromData(t){return new i(t)}};var Ua=class i extends A{constructor(t){super(t);this.data=t}txType;txSubType;async migrateAndClaim({account:t,scallopClient:n}){let o=t.address,{obligationKey:a,obligationId:c,rewardCoinName:l,veScaKey:d}=this.data,b=n.builder.createTxBlock();b.setSender(o);let I=Vt.redeem_rewards(b,a,c,n.utils.parseCoinType(l));return b.transferObjects([I],o),await b.unstakeObligationQuick(c,a),d?await b.stakeObligationWithVeScaQuick(c,a,d):await b.stakeObligationQuick(c,a),b.txBlock}async build(t){return this.migrateAndClaim(t)}static fromData(t){return new i(t)}};var qa=class i extends A{constructor(t){super(t);this.data=t}txType;txSubType;async build(t){return t.scallopClient.migrateAllMarketCoin(!1,!1)}static fromData(t){return new i(t)}};var Fa=class i extends A{constructor(t){super(t);this.data=t}txType;txSubType;async build(t){return t.scallopClient.openObligation(!1)}static fromData(t){return new i(t)}};var Ka=class i extends A{constructor(t){super(t);this.data=t}txType;txSubType;async repay({account:t,scallopClient:n}){let o=t.address,{coinName:a,amount:c,obligationId:l,obligationKey:d}=this.data;return(await this.buildTxWithRefreshObligation(n,{walletAddress:o,obligationId:l,obligationKey:d},async(I,w)=>{await w.repayQuick(+c,a,l)})).txBlock}async build(t){return this.repay(t)}static fromData(t){return new i(t)}};var $a=class i extends A{constructor(t){super(t);this.data=t}txType;txSubType;async repayWithBoost({account:t,scallopClient:n}){let o=t.address,{coinName:a,amount:c,obligationId:l,veScaKey:d}=this.data,b=n.builder.createTxBlock();b.setSender(o);let I=n.constants.whitelist.borrowing.has(a);return I&&await b.unstakeObligationQuick(l,void 0),await b.repayQuick(+c,a,l),I&&await b.stakeObligationWithVeScaQuick(l,void 0,d),b.txBlock}async build(t){return this.repayWithBoost(t)}static fromData(t){return new i(t)}};var Va=class i extends A{constructor(t){super(t);this.data=t}txType;txSubType;async build(t){return t.scallopClient.deposit(this.data.coinName,+this.data.amount,!1,t.account.address)}static fromData(t){return new i(t)}};var Ha=class i extends A{constructor(t){super(t);this.data=t}txType;txSubType;async build(t){return t.scallopClient.unstake(this.data.marketCoinName,+this.data.amount,!1)}static fromData(t){return new i(t)}};var Xa=class i extends A{constructor(t){super(t);this.data=t}txType;txSubType;async unstakeAndWithdraw(t,n,o){let a=t.builder.createTxBlock();a.setSender(o);let{stakeAccountId:c,amount:l,coinName:d}=this.data,b=[];for(let I=0;I<c.length;I++){let{id:w,coin:k}=c[I],x=t.utils.parseMarketCoinName(d),[v]=await a.unstakeQuick(k,x,w);if(v){let P=a.withdraw(v,d);b.push(P)}}if(l>0){let I=await a.withdrawQuick(l,d);b.push(I)}return b.length>1&&a.mergeCoins(b[0],b.slice(1)),a.transferObjects(b,o),a.txBlock}async build(t){return this.unstakeAndWithdraw(t.scallopClient,this.data,t.account.address)}static fromData(t){return new i(t)}};var za=class i extends A{constructor(t){super(t);this.data=t}txType;txSubType;async build(t){return t.scallopClient.withdrawCollateral(this.data.collateralCoinName,Number(this.data.amount),!1,this.data.obligationId,this.data.obligationKey,t.account.address)}static fromData(t){return new i(t)}};var Ga=class i extends A{constructor(t){super(t);this.data=t}txType;txSubType;async build(t){return t.scallopClient.withdraw(this.data.coinName,Number(this.data.amount),!1,t.account.address)}static fromData(t){return new i(t)}};var Qa=class i extends A{constructor(t){super(t);this.data=t}txType;txSubType;async bindReferral({account:t,scallopClient:n}){let o=t.address,a=n.builder.createTxBlock();return a.setSender(o),a.bindToReferral(this.data.veScaKey),a.txBlock}async build(t){return this.bindReferral(t)}static fromData(t){return new i(t)}};var Ja=class i extends A{constructor(t){super(t);this.data=t}txType;txSubType;async claimRevenueReferral({account:t,scallopClient:n}){let{veScaKey:o,coins:a}=this.data,c=t.address,l=n.builder.createTxBlock();l.setSender(c);let d=a.map(b=>n.utils.parseCoinNameFromType(b));return await l.claimReferralRevenueQuick(o,d),l.txBlock}async build(t){return this.claimRevenueReferral(t)}static fromData(t){return new i(t)}};var Ya=class i extends A{constructor(t){super(t);this.data=t}txType;txSubType;async createReferralLink({account:t,scallopClient:n}){let o=t.address,a=n.builder.createTxBlock();a.setSender(o);let c=a.mintEmptyVeSca();return a.transferObjects([c],o),a.txBlock}async build(t){return this.createReferralLink(t)}static fromData(t){return new i(t)}};var $u=require("@scallop-io/sui-scallop-sdk");var Za=class i extends A{constructor(t){super(t);this.data=t}txType;txSubType;async extendPeriodAndStakeMoreSca({account:t,scallopClient:n}){let{amount:o,veScaKey:a,unlockTime:c,obligationId:l,obligationKey:d,isOldBorrowIncentive:b,isObligationLocked:I}=this.data,w=t.address,k=n.builder.createTxBlock();k.setSender(w);let x=await n.utils.selectCoins(o,$u.SCA_COIN_TYPE,w),[v,P]=k.takeAmountFromCoins(x,o);return k.extendLockPeriod(a,c),k.extendLockAmount(a,v),k.transferObjects([P],w),!l||!d||(I&&(b?Vt.unstakeObligation(k,l,d):k.unstakeObligation(l,d)),k.stakeObligationWithVesca(l,d,a)),k.txBlock}async build(t){return this.extendPeriodAndStakeMoreSca(t)}static fromData(t){return new i(t)}};var ti=class i extends A{constructor(t){super(t);this.data=t}txType;txSubType;async extendStakeScaLockPeriod({account:t,scallopClient:n}){let o=t.address,{veScaKey:a,unlockTime:c,obligationId:l,obligationKey:d,isObligationLocked:b,isOldBorrowIncentive:I}=this.data,w=n.builder.createTxBlock();return w.setSender(o),w.extendLockPeriod(a,c),l&&d&&(b&&(I?Vt.unstakeObligation(w,d,l):w.unstakeObligation(l,d)),w.stakeObligationWithVesca(l,d,a)),w.txBlock}async build(t){return this.extendStakeScaLockPeriod(t)}static fromData(t){return new i(t)}};var ei=class i extends A{constructor(t){super(t);this.data=t}txType;txSubType;async handleUnsubForKeys(t,n,o){let{targetVeScaKey:a,sourceVeScaKey:c}=this.data,[l,d]=await Promise.all([n.getBindedObligationId(a),n.getBindedObligationId(c)]);l&&await t.unstakeObligationQuick(l),d&&await t.unstakeObligationQuick(d),o(t,a,c),l&&await t.stakeObligationWithVeScaQuick(l,void 0,a),d&&await t.stakeObligationWithVeScaQuick(d,void 0,c)}async build(t){let{scallopClient:n,account:{address:o}}=t,a=n.builder.createTxBlock();return a.setSender(o),await this.handleUnsubForKeys(a,n.query,async(c,l,d)=>{c.mergeVeSca(a.object(l),a.object(d))}),a.txBlock}static fromData(t){return new i(t)}};var ni=class i extends A{constructor(t){super(t);this.data=t}txType;txSubType;async redeemSca({account:t,scallopClient:n}){let{veScaKey:o}=this.data,a=t.address,c=n.builder.createTxBlock();return c.setSender(a),await c.redeemScaQuick(o),c.txBlock}async build(t){return this.redeemSca(t)}static fromData(t){return new i(t)}};var Vu=require("@scallop-io/sui-scallop-sdk");var oi=class i extends A{constructor(t){super(t);this.data=t}txType;txSubType;async renewExpiredStakeSca({account:t,scallopClient:n}){let o=t.address,{amount:a,unlockTime:c,veScaKey:l,isHaveRedeem:d,obligation:b,obligationKey:I,isObligationLocked:w,isOldBorrowIncentive:k}=this.data,x=n.builder.createTxBlock();if(x.setSender(o),d){let H=x.redeemSca(l);x.transferObjects([H],o)}let v=await n.builder.utils.selectCoins(a,Vu.SCA_COIN_TYPE,o),[P,K]=x.takeAmountFromCoins(v,a);return x.transferObjects([K],o),x.renewExpiredVeSca(l,P,c),!b||!I||(w&&(k?Vt.unstakeObligation(x,I,b):x.unstakeObligation(b,I)),x.stakeObligationWithVesca(b,I,l)),x.txBlock}async build(t){return this.renewExpiredStakeSca(t)}static fromData(t){return new i(t)}};var ai=class i extends A{constructor(t){super(t);this.data=t}txType;txSubType;async handleUnsubForKeys(t,n,o){let{targetVeScaKey:a,splitAmount:c}=this.data,l=await n.getBindedObligationId(a);l&&await t.unstakeObligationQuick(l),o(t,a,c.toString()),l&&await t.stakeObligationWithVeScaQuick(l,void 0,a)}async build(t){let{scallopClient:n,account:{address:o}}=t,a=n.builder.createTxBlock();return a.setSender(o),await this.handleUnsubForKeys(a,n.query,(c,l,d)=>{let b=c.splitVeSca(l,d.toString());c.transferObjects([b],o)}),a.txBlock}static fromData(t){return new i(t)}};var Hu=require("@scallop-io/sui-scallop-sdk");var ii=class i extends A{constructor(t){super(t);this.data=t}txType;txSubType;async stakeSca({account:t,scallopClient:n}){let o=t.address,{amount:a,isObligationLocked:c,isOldBorrowIncentive:l,obligationId:d,obligationKey:b,unlockTime:I,veScaKey:w}=this.data,k=n.builder.createTxBlock();k.setSender(o);let x=await n.utils.selectCoins(a,Hu.SCA_COIN_TYPE,o),[v,P]=k.takeAmountFromCoins(x,a),K;return w?k.extendLockAmount(w,v):K=k.lockSca(v,I),d&&b&&(c&&(l?Vt.unstakeObligation(k,b,d):k.unstakeObligation(d,b)),k.stakeObligationWithVesca(d,b,w||K)),w||k.transferObjects([K,P],o),k.txBlock}async build(t){return this.stakeSca(t)}static fromData(t){return new i(t)}};var ri=class i extends A{constructor(t){super(t);this.data=t}txType;txSubType;async supplyAndStake({account:t,scallopClient:n}){let o=t.address,{amount:a,coinName:c,stakeAccountId:l}=this.data,d=n.builder.createTxBlock();d.setSender(o);let b=await d.depositQuick(+a,c),I=n.utils.parseMarketCoinName(c);if(n.constants.whitelist.spool.has(I))return d.txBlock;let w=await n.query.getStakeAccounts(I,o),k=l||(w.length>0?w[0].id:void 0);if(k)await d.stakeQuick(b,I,k);else{let x=d.createStakeAccount(I);await d.stakeQuick(b,I,x),d.transferObjects([x],o)}return d.txBlock}async build(t){return this.supplyAndStake(t)}static fromData(t){return new i(t)}};var si=class i extends A{constructor(t){super(t);this.data=t}txType;txSubType;handleAction(t,{action:n,args:o}){switch(n){case"deactivate":return t.deactivateBoost(o.obligationId,o.veScaKey);case"stake":return t.stakeObligationWithVesca(o.obligationId,o.obligationKey,o.veScaKey);case"unstake":return t.unstakeObligation(o.obligationId,o.obligationKey);default:throw new Error("Invalid action")}}async build(t){let{scallopClient:n,account:{address:o}}=t,a=n.builder.createTxBlock();a.setSender(o);let{bindingDatas:c}=this.data;return c.forEach(l=>this.handleAction(a,l)),a.txBlock}static fromData(t){return new i(t)}};var ci=class i extends A{constructor(t){super(t);this.data=t}txType;txSubType;async build(t){let{scallopClient:n,account:{address:o}}=t,a=n.builder.createTxBlock();a.setSender(o);let{veScaKeys:c}=this.data;return a.transferObjects(c.map(l=>a.objectRef(l)),a.pure.address(o)),a.txBlock}static fromData(t){return new i(t)}};var li=class i extends A{constructor(t){super(t);this.data=t}txType;txSubType;async withdrawUnlockedSca({account:t,scallopClient:n}){let{vescaKey:o}=this.data,a=t.address,c=n.builder.createTxBlock();return c.setSender(a),await c.redeemScaQuick(o),c.txBlock}async build(t){return this.withdrawUnlockedSca(t)}static fromData(t){return new i(t)}};var ui=class{application="scallop";supportSDK="@mysten/sui";scallopClient;async initScallopClient(e,t){if(!this.scallopClient){let n=new Gu.Scallop({addressId:"67c44a103fe1b8c454eb9699",walletAddress:e,suiClients:[t],fullnodeUrls:[t.transport.rpcClient.requestManager.transports[0]?.uri??(0,zu.getFullnodeUrl)("mainnet")]});this.scallopClient=await n.createScallopClient()}}async deserialize(e){let{transaction:t,suiClient:n,account:o}=e;await this.initScallopClient(o.address,n),console.log("transaction",t);let a=new Pa(t,this.scallopClient),c=new Ba(t,this.scallopClient),l=new Ea(t,this.scallopClient),d=a.decode()||c.decode()||await l.decode();if(!d)throw new Error("Unknown transaction type");return{txType:Xu.TransactionType.Other,txSubType:d.type,intentionData:d.intentionData}}async build(e){let{suiClient:t,account:n,network:o,txSubType:a,intentionData:c}=e;await this.initScallopClient(n.address,t);let l;switch(a){case"SupplyLending":l=Va.fromData(c);break;case"WithdrawLending":l=Ga.fromData(c);break;case"Borrow":l=Na.fromData(c);break;case"Repay":l=Ka.fromData(c);break;case"DepositCollateral":l=ja.fromData(c);break;case"WithdrawCollateral":l=za.fromData(c);break;case"OpenObligation":l=Fa.fromData(c);break;case"UnstakeSpool":l=Ha.fromData(c);break;case"ClaimIncentiveReward":l=La.fromData(c);break;case"BorrowWithBoost":l=Wa.fromData(c);break;case"StakeSca":l=ii.fromData(c);break;case"ExtendStakePeriod":l=ti.fromData(c);break;case"ExtendPeriodAndStakeMore":l=Za.fromData(c);break;case"RenewExpStakePeriod":l=oi.fromData(c);break;case"WithdrawStakedSca":l=li.fromData(c);break;case"SupplyAndStakeLending":l=ri.fromData(c);break;case"WithdrawAndUnstakeLending":l=Xa.fromData(c);break;case"RedeemSca":l=ni.fromData(c);break;case"MigrateAndClaim":l=Ua.fromData(c);break;case"BorrowWithReferral":l=_a.fromData(c);break;case"CreateReferralLink":l=Ya.fromData(c);break;case"ClaimRevenueReferral":l=Ja.fromData(c);break;case"BindReferral":l=Qa.fromData(c);break;case"MigrateScoin":l=qa.fromData(c);break;case"RepayWithBoost":l=$a.fromData(c);break;case"MergeVeSca":l=ei.fromData(c);break;case"SplitVeSca":l=ai.fromData(c);break;case"VeScaObligationBindings":{l=si.fromData(c);break}case"TransferVeScaKeys":{l=ci.fromData(c);break}default:throw new Error("not implemented")}return l.build({suiClient:t,account:n,network:o,scallopClient:this.scallopClient})}};var ym=require("@msafe/sui3-utils");var sn=require("@msafe/sui3-utils"),Ce=require("@mysten/sui/utils");var sm=require("@suilend/sui-fe");var rm=require("@msafe/sui3-utils"),we=require("@suilend/sdk");var We=require("@msafe/sui3-utils"),an=require("@mysten/bcs"),on=require("@mysten/sui/utils"),_e=require("@suilend/sui-fe"),Ms=Ut(require("bignumber.js"));var mi=class{constructor(e,t){this.transaction=e;this.simResult=t}decode(){if(this.isDepositTransaction())return this.decodeDeposit();if(this.isWithdrawTransaction())return this.decodeWithdraw();if(this.isBorrowTransaction())return this.decodeBorrow();if(this.isRepayTransaction())return this.decodeRepay();if(this.isClaimTransaction())return this.decodeClaim();if(this.isClaimAndDepositTransaction())return this.decodeClaimAndDeposit();throw new Error("Unknown transaction type")}get inputs(){return console.log("this.transaction.getData().inputs",this.transaction.getData().inputs),this.transaction.getData().inputs}get commands(){return console.log("this.transaction.getData().commands",this.transaction.getData().commands),this.transaction.getData().commands}getMoveCallCommand(e){return this.commands.find(t=>t.$kind==="MoveCall"&&t.MoveCall.function===e)}hasDepositTransactionMoveCallCommands(){return!!this.getMoveCallCommand("deposit_liquidity_and_mint_ctokens")&&!!this.getMoveCallCommand("deposit_ctokens_into_obligation")}hasClaimTransactionMoveCallCommands(){return!!this.getMoveCallCommand("claim_rewards")}isDepositTransaction(){return!this.hasClaimTransactionMoveCallCommands()&&this.hasDepositTransactionMoveCallCommands()}isWithdrawTransaction(){return!!this.getMoveCallCommand("withdraw_ctokens")&&!!this.getMoveCallCommand("redeem_ctokens_and_withdraw_liquidity_request")}isBorrowTransaction(){return!!this.getMoveCallCommand("borrow_request")}isRepayTransaction(){return!!this.getMoveCallCommand("repay")}isClaimTransaction(){return this.hasClaimTransactionMoveCallCommands()&&!this.hasDepositTransactionMoveCallCommands()}isClaimAndDepositTransaction(){return this.hasClaimTransactionMoveCallCommands()&&this.hasDepositTransactionMoveCallCommands()}decodeDeposit(){let e={MintEvent:this.simResult.events.find(o=>o.type.includes("lending_market::MintEvent"))},t=(0,on.normalizeStructTag)(e.MintEvent.parsedJson.coin_type.name),n=e.MintEvent.parsedJson.liquidity_amount;return console.log("Decoder.decodeDeposit",t,n),{txType:We.TransactionType.Other,type:"deposit",intentionData:{coinType:t,value:n}}}decodeWithdraw(){let e={withdraw_ctokens:this.getMoveCallCommand("withdraw_ctokens")},t={RedeemEvent:this.simResult.events.find(d=>d.type.includes("lending_market::RedeemEvent"))},n=(0,on.normalizeStructTag)(t.RedeemEvent.parsedJson.coin_type.name),o=t.RedeemEvent.parsedJson.liquidity_amount;console.log("Decoder.decodeWithdraw",n,o);let a=e.withdraw_ctokens.MoveCall.arguments[4].Input,c=new Ms.default((0,an.toHex)((0,an.fromBase64)(this.inputs[a].Pure.bytes)),16).toString(),l=c===_e.MAX_U64.toString();return console.log("decodeWithdraw - isMax:",l,"inputIndex:",a,"inputValue:",c,"MAX_U64.toString():",_e.MAX_U64.toString()),l&&(o=_e.MAX_U64.toString()),{txType:We.TransactionType.Other,type:"withdraw",intentionData:{coinType:n,value:o}}}decodeBorrow(){let e={borrow_request:this.getMoveCallCommand("borrow_request")},t={BorrowEvent:this.simResult.events.find(d=>d.type.includes("lending_market::BorrowEvent"))},n=(0,on.normalizeStructTag)(t.BorrowEvent.parsedJson.coin_type.name),o=`${+t.BorrowEvent.parsedJson.liquidity_amount-+t.BorrowEvent.parsedJson.origination_fee_amount}`;console.log("Decoder.decodeBorrow",n,o);let a=e.borrow_request.MoveCall.arguments[4].Input,c=new Ms.default((0,an.toHex)((0,an.fromBase64)(this.inputs[a].Pure.bytes)),16).toString(),l=c===_e.MAX_U64.toString();return console.log("decodeBorrow - isMax:",l,"inputIndex:",a,"inputValue:",c,"MAX_U64.toString():",_e.MAX_U64.toString()),l&&(o=_e.MAX_U64.toString()),{txType:We.TransactionType.Other,type:"borrow",intentionData:{coinType:n,value:o}}}decodeRepay(){let e={RepayEvent:this.simResult.events.find(o=>o.type.includes("lending_market::RepayEvent"))},t=(0,on.normalizeStructTag)(e.RepayEvent.parsedJson.coin_type.name),n=e.RepayEvent.parsedJson.liquidity_amount;return console.log("Decoder.decodeRepay",t,n),{txType:We.TransactionType.Other,type:"repay",intentionData:{coinType:t,value:n}}}decodeClaim(){let e={ClaimReward:this.simResult.events.filter(n=>n.type.includes("lending_market::ClaimReward"))},t={};for(let n=0;n<e.ClaimReward.length;n++){let o=e.ClaimReward[n],a=(0,on.normalizeStructTag)(o.parsedJson.coin_type.name),c=o.parsedJson.liquidity_amount;t[a]=`${+(t[a]??"0")+ +c}`}return console.log("Decoder.decodeClaimRewards",t),{txType:We.TransactionType.Other,type:"claim",intentionData:{value:t}}}decodeClaimAndDeposit(){return{txType:We.TransactionType.Other,type:"claimAndDeposit",intentionData:this.decodeClaim().intentionData}}};var Ju=require("@mysten/sui/transactions");var Qu=Ut(require("sort-keys-recursive")),jt=class{constructor(e){this.data=e}serialize(){return JSON.stringify((0,Qu.default)(this.data))}};var pi=class i extends jt{constructor(t){super(t);this.data=t}txType;txSubType;async build(t){let{suiClient:n,account:o,suilendClient:a,obligationOwnerCap:c,obligation:l}=t;if(console.log("BorrowIntention.build",n,o,a,c,l),!c||!l)throw new Error("Obligation not found");let d=new Ju.Transaction;return await a.borrowAndSendToUser(o.address,c.id,l.id,this.data.coinType,this.data.value,d),d}static fromData(t){return console.log("BorrowIntention.fromData",t),new i(t)}};var em=require("@mysten/sui/transactions");var Yu=require("@mysten/sui/utils"),rn=require("@suilend/sdk"),Zu=require("@suilend/sui-fe"),tm=Ut(require("bignumber.js")),Ud=(i,e)=>{let t={[rn.Side.DEPOSIT]:[],[rn.Side.BORROW]:[]};return i.lendingMarket.reserves.forEach(n=>{[rn.Side.DEPOSIT,rn.Side.BORROW].forEach(o=>{let a=o===rn.Side.DEPOSIT?n.depositsPoolRewardManager:n.borrowsPoolRewardManager,c=e.userRewardManagers.find(l=>l.poolRewardManagerId===a.id);c&&(t[o]=a.poolRewards.map((l,d)=>({reserveArrayIndex:n.arrayIndex,rewardIndex:BigInt(d),rewardCoinType:(0,Yu.normalizeStructTag)(l.coinType.name),side:o})).filter(l=>!(0,Zu.isSendPoints)(l.rewardCoinType)&&!!c.rewards[Number(l.rewardIndex)]&&new tm.default(c.rewards[Number(l.rewardIndex)].earnedRewards.value.toString()).gt(0)))})}),Object.values(t).flat()},di=Ud;var fi=class i extends jt{constructor(t){super(t);this.data=t}txType;txSubType;async build(t){let{suiClient:n,account:o,suilendClient:a,obligationOwnerCap:c,obligation:l}=t;if(console.log("ClaimIntention.build",n,o,a,c,l),!c||!l)throw new Error("Obligation not found");let d=new em.Transaction;return a.claimRewardsAndSendToUser(o.address,c.id,di(a,l),d),d}static fromData(t){return console.log("ClaimIntention.fromData",t),new i(t)}};var nm=require("@mysten/sui/transactions");var hi=class i extends jt{constructor(t){super(t);this.data=t}txType;txSubType;async build(t){let{suiClient:n,account:o,suilendClient:a,obligationOwnerCap:c,obligation:l}=t;if(console.log("ClaimAndDepositIntention.build",n,o,a,c,l),!c||!l)throw new Error("Obligation not found");let d=new nm.Transaction;return a.claimRewardsAndDeposit(o.address,c.id,di(a,l),d),d}static fromData(t){return console.log("ClaimAndDepositIntention.fromData",t),new i(t)}};var om=require("@mysten/sui/transactions");var gi=class i extends jt{constructor(t){super(t);this.data=t}txType;txSubType;async build(t){let{suiClient:n,account:o,suilendClient:a,obligationOwnerCap:c,obligation:l}=t;console.log("DepositIntention.build",n,o,a,c,l);let d=new om.Transaction;return await a.depositIntoObligation(o.address,this.data.coinType,this.data.value,d,c?.id),d}static fromData(t){return console.log("DepositIntention.fromData",t),new i(t)}};var am=require("@mysten/sui/transactions");var yi=class i extends jt{constructor(t){super(t);this.data=t}txType;txSubType;async build(t){let{suiClient:n,account:o,suilendClient:a,obligationOwnerCap:c,obligation:l}=t;if(console.log("RepayIntention.build",n,o,a,c,l),!c||!l)throw new Error("Obligation not found");let d=new am.Transaction;return await a.repayIntoObligation(o.address,l.id,this.data.coinType,this.data.value,d),d}static fromData(t){return console.log("RepayIntention.fromData",t),new i(t)}};var im=require("@mysten/sui/transactions");var bi=class i extends jt{constructor(t){super(t);this.data=t}txType;txSubType;async build(t){let{suiClient:n,account:o,suilendClient:a,obligationOwnerCap:c,obligation:l}=t;if(console.log("WithdrawIntention.build",n,o,a,c,l),!c||!l)throw new Error("Obligation not found");let d=new im.Transaction;return await a.withdrawAndSendToUser(o.address,c.id,l.id,this.data.coinType,this.data.value,d),d}static fromData(t){return console.log("WithdrawIntention.fromData",t),new i(t)}};var Si=async(i,e)=>{let t=await we.SuilendClient.initialize(we.LENDING_MARKET_ID,we.LENDING_MARKET_TYPE,i),n=await we.SuilendClient.getObligationOwnerCaps(e.address,t.lendingMarket.$typeArgs,i),o=await Promise.all(n.map(a=>we.SuilendClient.getObligation(a.obligationId,t.lendingMarket.$typeArgs,i)));return console.log("XXX getUtils - suilendClient:",t,"obligations:",o,"obligationOwnerCaps:",n),{suilendClient:t,obligationOwnerCaps:n,obligations:o}},Ti=class{application="Suilend";supportSDK="@mysten/sui";utils;async deserialize(e){let{transaction:t,suiClient:n,account:o}=e;this.utils||(this.utils=await Si(n,o));let a=await n.devInspectTransactionBlock({sender:o.address,transactionBlock:t});console.log("SuilendAppHelper.deserialize - simResult:",a,"utils:",this.utils,"suiClient:",n);let l=new mi(t,a).decode();return{txType:rm.TransactionType.Other,txSubType:l.type,intentionData:l.intentionData}}async build(e){let{network:t,txSubType:n,intentionData:o,suiClient:a,account:c}=e;this.utils||(this.utils=await Si(a,c));let l;switch(n){case"deposit":l=gi.fromData(o);break;case"withdraw":l=bi.fromData(o);break;case"borrow":l=pi.fromData(o);break;case"repay":l=yi.fromData(o);break;case"claim":l=fi.fromData(o);break;case"claimAndDeposit":l=hi.fromData(o);break;default:throw new Error("not implemented")}let d=window.localStorage.getItem("obligationId"),b=this.utils.obligations?.find(w=>w.id===d)??this.utils.obligations?.[0],I=this.utils.obligationOwnerCaps?.find(w=>w.obligationId===b?.id);return l.build({network:t,suiClient:a,account:c,suilendClient:this.utils.suilendClient,obligationOwnerCap:I,obligation:b})}};var Os=async(i,e)=>{let t=await Si(i,e),n=await fetch(`${sm.API_URL}/springsui/lst-info`),o=await n.json();if(n?.statusCode===500)throw new Error("Failed to fetch SpringSui LST data");let c=Object.fromEntries(Object.values(o).map(l=>[l.LIQUID_STAKING_INFO.type,l.LIQUID_STAKING_INFO]));return{...t,LIQUID_STAKING_INFO_MAP:c}};var Ii=class{constructor(e,t){this.transaction=e;this.simResult=t}decode(){if(this.isStakeTransaction())return this.decodeStake();if(this.isStakeAndDepositTransaction())return this.decodeStakeAndDeposit();if(this.isConvertTransaction())return this.decodeConvert();if(this.isConvertAndDepositTransaction())return this.decodeConvertAndDeposit();if(this.isUnstakeTransaction())return this.decodeUnstake();throw new Error("Unknown transaction type")}get commands(){return this.transaction.getData().commands}getMoveCallCommand(e){return this.commands.find(t=>t.$kind==="MoveCall"&&t.MoveCall.function===e)}hasSuilendDepositTransactionMoveCallCommands(){return!!this.getMoveCallCommand("deposit_liquidity_and_mint_ctokens")&&!!this.getMoveCallCommand("deposit_ctokens_into_obligation")}hasMintMoveCallCommands(){return!!this.getMoveCallCommand("mint")}hasRedeemMoveCallCommands(){return!!this.getMoveCallCommand("redeem")}isStakeTransaction(){return this.hasMintMoveCallCommands()&&!this.hasRedeemMoveCallCommands()&&!this.hasSuilendDepositTransactionMoveCallCommands()}isStakeAndDepositTransaction(){return this.hasMintMoveCallCommands()&&!this.hasRedeemMoveCallCommands()&&this.hasSuilendDepositTransactionMoveCallCommands()}isConvertTransaction(){return this.hasMintMoveCallCommands()&&this.hasRedeemMoveCallCommands()&&!this.hasSuilendDepositTransactionMoveCallCommands()}isConvertAndDepositTransaction(){return this.hasMintMoveCallCommands()&&this.hasRedeemMoveCallCommands()&&this.hasSuilendDepositTransactionMoveCallCommands()}isUnstakeTransaction(){return!this.hasMintMoveCallCommands()&&this.hasRedeemMoveCallCommands()&&!this.hasSuilendDepositTransactionMoveCallCommands()}decodeStake(){let e={MintEvent:this.simResult.events.find(o=>o.type.includes("liquid_staking::MintEvent"))},t=(0,Ce.normalizeStructTag)(e.MintEvent.parsedJson.event.typename.name),n=e.MintEvent.parsedJson.event.sui_amount_in;return console.log("Decoder.decodeStake",n),{txType:sn.TransactionType.Other,type:"stake",intentionData:{amount:n,outCoinType:t}}}decodeStakeAndDeposit(){let e={MintEvent:this.simResult.events.find(o=>o.type.includes("liquid_staking::MintEvent"))},t=(0,Ce.normalizeStructTag)(e.MintEvent.parsedJson.event.typename.name),n=e.MintEvent.parsedJson.event.sui_amount_in;return console.log("Decoder.decodeStakeAndDeposit",n),{txType:sn.TransactionType.Other,type:"stakeAndDeposit",intentionData:{amount:n,outCoinType:t}}}decodeConvert(){let e={RedeemEvent:this.simResult.events.find(a=>a.type.includes("liquid_staking::RedeemEvent")),MintEvent:this.simResult.events.find(a=>a.type.includes("liquid_staking::MintEvent"))},t=(0,Ce.normalizeStructTag)(e.RedeemEvent.parsedJson.event.typename.name),n=(0,Ce.normalizeStructTag)(e.MintEvent.parsedJson.event.typename.name),o=e.RedeemEvent.parsedJson.event.lst_amount_in;return console.log("Decoder.decodeConvert",o),{txType:sn.TransactionType.Other,type:"convert",intentionData:{amount:o,inCoinType:t,outCoinType:n}}}decodeConvertAndDeposit(){let e={RedeemEvent:this.simResult.events.find(a=>a.type.includes("liquid_staking::RedeemEvent")),MintEvent:this.simResult.events.find(a=>a.type.includes("liquid_staking::MintEvent"))},t=(0,Ce.normalizeStructTag)(e.RedeemEvent.parsedJson.event.typename.name),n=(0,Ce.normalizeStructTag)(e.MintEvent.parsedJson.event.typename.name),o=e.RedeemEvent.parsedJson.event.lst_amount_in;return console.log("Decoder.decodeConvertAndDeposit",o),{txType:sn.TransactionType.Other,type:"convertAndDeposit",intentionData:{amount:o,inCoinType:t,outCoinType:n}}}decodeUnstake(){let e={RedeemEvent:this.simResult.events.find(o=>o.type.includes("liquid_staking::RedeemEvent"))},t=(0,Ce.normalizeStructTag)(e.RedeemEvent.parsedJson.event.typename.name),n=e.RedeemEvent.parsedJson.event.lst_amount_in;return console.log("Decoder.decodeUnstake",n),{txType:sn.TransactionType.Other,type:"unstake",intentionData:{amount:n,inCoinType:t}}}};var lm=require("@mysten/sui/transactions"),jn=require("@suilend/springsui-sdk");var cm=Ut(require("sort-keys-recursive")),Ht=class{constructor(e){this.data=e}serialize(){return JSON.stringify((0,cm.default)(this.data))}};var wi=class i extends Ht{constructor(t){super(t);this.data=t}txType;txSubType;async build(t){let{suiClient:n,account:o,suilendClient:a,LIQUID_STAKING_INFO_MAP:c,obligationOwnerCap:l,obligation:d}=t;console.log("ConvertIntention.build",n,o,a,c,l,d);let b=await jn.LstClient.initialize(n,Object.values(c).find(k=>k.type===this.data.inCoinType)),I=await jn.LstClient.initialize(n,Object.values(c).find(k=>k.type===this.data.outCoinType)),w=new lm.Transaction;return(0,jn.convertLstsAndSendToUser)(b,I,w,o.address,this.data.amount),w}static fromData(t){return console.log("ConvertIntention.fromData",t),new i(t)}};var um=require("@mysten/sui/transactions"),ki=require("@suilend/sdk"),Un=require("@suilend/springsui-sdk");var Ci=class i extends Ht{constructor(t){super(t);this.data=t}txType;txSubType;async build(t){let{suiClient:n,account:o,suilendClient:a,LIQUID_STAKING_INFO_MAP:c,obligationOwnerCap:l,obligation:d}=t;console.log("ConvertAndDepositIntention.build",n,o,a,c,l,d);let b=await Un.LstClient.initialize(n,Object.values(c).find(P=>P.type===this.data.inCoinType)),I=await Un.LstClient.initialize(n,Object.values(c).find(P=>P.type===this.data.outCoinType)),w=new um.Transaction,{obligationOwnerCapId:k,didCreate:x}=(0,ki.createObligationIfNoneExists)(a,w,l),v=(0,Un.convertLsts)(b,I,w,o.address,this.data.amount);return a.deposit(v,this.data.outCoinType,k,w),x&&(0,ki.sendObligationToUser)(k,o.address,w),w}static fromData(t){return console.log("ConvertAndDepositIntention.fromData",t),new i(t)}};var mm=require("@mysten/sui/transactions"),pm=require("@suilend/springsui-sdk");var xi=class i extends Ht{constructor(t){super(t);this.data=t}txType;txSubType;async build(t){let{suiClient:n,account:o,suilendClient:a,LIQUID_STAKING_INFO_MAP:c,obligationOwnerCap:l,obligation:d}=t;console.log("StakeIntention.build",n,o,a,c,l,d);let b=await pm.LstClient.initialize(n,Object.values(c).find(w=>w.type===this.data.outCoinType)),I=new mm.Transaction;return b.mintAmountAndRebalanceAndSendToUser(I,o.address,this.data.amount),I}static fromData(t){return console.log("StakeIntention.fromData",t),new i(t)}};var dm=require("@mysten/sui/transactions"),Di=require("@suilend/sdk"),fm=require("@suilend/springsui-sdk");var vi=class i extends Ht{constructor(t){super(t);this.data=t}txType;txSubType;async build(t){let{suiClient:n,account:o,suilendClient:a,LIQUID_STAKING_INFO_MAP:c,obligationOwnerCap:l,obligation:d}=t;console.log("StakeAndDepositIntention.build",n,o,a,c,l,d);let b=await fm.LstClient.initialize(n,Object.values(c).find(v=>v.type===this.data.outCoinType)),I=new dm.Transaction,{obligationOwnerCapId:w,didCreate:k}=(0,Di.createObligationIfNoneExists)(a,I,l),x=b.mintAmountAndRebalance(I,o.address,this.data.amount);return a.deposit(x,this.data.outCoinType,w,I),k&&(0,Di.sendObligationToUser)(w,o.address,I),I}static fromData(t){return console.log("StakeAndDepositIntention.fromData",t),new i(t)}};var hm=require("@mysten/sui/transactions"),gm=require("@suilend/springsui-sdk");var Ai=class i extends Ht{constructor(t){super(t);this.data=t}txType;txSubType;async build(t){let{suiClient:n,account:o,suilendClient:a,LIQUID_STAKING_INFO_MAP:c,obligationOwnerCap:l,obligation:d}=t;console.log("UnstakeIntention.build",n,o,a,c,l,d);let b=await gm.LstClient.initialize(n,Object.values(c).find(w=>w.type===this.data.inCoinType)),I=new hm.Transaction;return b.redeemAmountAndSendToUser(I,o.address,this.data.amount),I}static fromData(t){return console.log("UnstakeIntention.fromData",t),new i(t)}};var Mi=class{application="SpringSui";supportSDK="@mysten/sui";utils;async deserialize(e){let{transaction:t,suiClient:n,account:o}=e;this.utils||(this.utils=await Os(n,o));let a=await n.devInspectTransactionBlock({sender:o.address,transactionBlock:t});console.log("SpringSuiAppHelper.deserialize",a);let l=new Ii(t,a).decode();return{txType:ym.TransactionType.Other,txSubType:l.type,intentionData:l.intentionData}}async build(e){let{network:t,txSubType:n,intentionData:o,suiClient:a,account:c}=e;this.utils||(this.utils=await Os(a,c));let l;switch(n){case"stake":l=xi.fromData(o);break;case"stakeAndDeposit":l=vi.fromData(o);break;case"convert":l=wi.fromData(o);break;case"convertAndDeposit":l=Ci.fromData(o);break;case"unstake":l=Ai.fromData(o);break;default:throw new Error("not implemented")}return l.build({network:t,suiClient:a,account:c,suilendClient:this.utils.suilendClient,LIQUID_STAKING_INFO_MAP:this.utils.LIQUID_STAKING_INFO_MAP,obligationOwnerCap:this.utils.obligationOwnerCaps?.[0],obligation:this.utils.obligations?.[0]})}};var Tm=require("@msafe/sui3-utils");var Ps=require("@msafe/sui3-utils");var Oi=class{constructor(e,t){this.transaction=e;this.simResult=t}decode(){if(this.isMintTransaction()){let e=this.getLiquidityChangeEvent("MintEvent");if(!e)throw new Error("No liquidity change event found. Unable to decode transaction.");let t=e.parsedJson;return console.log("Decoder event data - ",t),this.decodeMint(t)}if(this.isRedeemTransaction()){let e=this.getLiquidityChangeEvent("RedeemEvent");if(!e)throw new Error("No liquidity change event found. Unable to decode transaction.");let t=e.parsedJson;return console.log("Decoder event data - ",t),this.decodeRedeem(t)}throw new Error("Unknown transaction type")}get commands(){return this.transaction.getData().commands}getMoveCallCommand(e){return this.commands.find(t=>t.$kind==="MoveCall"&&t.MoveCall.function===e)}getLiquidityChangeEvent(e){return this.simResult.events.find(t=>this.isLiquidityChangeEventType(t.type,e))}isLiquidityChangeEventType(e,t){return e.includes(t)}isMintTransaction(){return!!this.getMoveCallCommand("mint")}isRedeemTransaction(){return!!this.getMoveCallCommand("redeem")}decodeMint(e){let{event:{sui_amount_in:t}}=e;return console.log("Decoder.decodeMint",t),{txType:Ps.TransactionType.Other,type:"mint",intentionData:{amount:t}}}decodeRedeem(e){let{event:{lst_amount_in:t}}=e;return console.log("Decoder.decodeRedeem",t),{txType:Ps.TransactionType.Other,type:"redeem",intentionData:{amount:t}}}};var bm=require("@alphafi/stsui-sdk");var Pi=class i extends C{constructor(t){super(t);this.data=t}txType;txSubType;async build(t){let{account:n}=t,{amount:o}=this.data,a={lstInfo:"0x1adb343ab351458e151bc392fbf1558b3332467f23bda45ae67cd355a57fd5f5",lstCointype:"0xd1b72982e40348d069bb1ff701e634c117bb5f741f44dff91e472d3b01461e55::stsui::STSUI"},l=await new bm.LST(a).mint(o,n.address);return l.setGasBudget(1e8),l}static fromData(t){return console.log("MintIntention.fromData",t),new i(t)}};var Sm=require("@alphafi/stsui-sdk");var Ri=class i extends C{constructor(t){super(t);this.data=t}txType;txSubType;async build(t){let{account:n}=t,{amount:o}=this.data,a={lstInfo:"0x1adb343ab351458e151bc392fbf1558b3332467f23bda45ae67cd355a57fd5f5",lstCointype:"0xd1b72982e40348d069bb1ff701e634c117bb5f741f44dff91e472d3b01461e55::stsui::STSUI"},l=await new Sm.LST(a).redeem(o,n.address);return l.setGasBudget(1e8),l}static fromData(t){return console.log("RedeemIntention.fromData",t),new i(t)}};var Bi=class{application="stsui";supportSDK="@mysten/sui";async deserialize(e){let{transaction:t,suiClient:n}=e,o=await n.devInspectTransactionBlock({sender:t.getData().sender,transactionBlock:t});console.log("StSuiHelper Sim result - ",o);let c=new Oi(t,o).decode();return{txType:Tm.TransactionType.Other,txSubType:c.type,intentionData:c.intentionData}}async build(e){let{account:t}=e;console.log("StSui build transaction type",e.txSubType);let n;switch(e.txSubType){case"mint":n=Pi.fromData(e.intentionData);break;case"redeem":n=Ri.fromData(e.intentionData);break;default:throw new Error("build not implemented")}return n.build({account:t})}};var $m=require("@msafe/sui3-utils"),Vm=require("turbos-clmm-sdk");var Nt=require("@msafe/sui3-utils"),Le=require("@mysten/bcs"),je=require("@mysten/sui/bcs"),Im=require("turbos-clmm-sdk");var zt={PackageId:"0x02fe4933f4521250e55a15441096d1d4a38a7311195b0bca126fc0138c1f5a97",Claim:"0x0c822cec42f7ca703696b4232f1c47b348330c23580172a29aab465bc071d894",turbosCoinType:"0x5d1f47ea69bb0de31c313d7acf89b890dbb8991ea8e03c6c355171f84bb1ba4a::turbos::TURBOS"},Gt={PackageId:"0xdee9"};var $d=(i,e,t,n)=>{if(i===1)switch(n.findIndex(c=>c===e)){case 0:return[!0,!0];case 1:return[!0,!1];case 2:return[!1,!0];case 3:return[!1,!1];default:throw new Error(`not target: ${e}`)}switch(t.findIndex(a=>a===e)){case 0:return[!0];case 1:return[!1];default:throw new Error(`not target: ${e}`)}},Ei=class{constructor(e,t,n){this.txb=e;this.turbosSdk=t;this.config=n}get transactions(){return this.txb.getData().commands}get swap1Layer(){return[`${this.config.PackageId}::swap_router::swap_a_b`,`${this.config.PackageId}::swap_router::swap_b_a`]}get swap2Layer(){return[`${this.config.PackageId}::swap_router::swap_a_b_b_c`,`${this.config.PackageId}::swap_router::swap_a_b_c_b`,`${this.config.PackageId}::swap_router::swap_b_a_b_c`,`${this.config.PackageId}::swap_router::swap_b_a_c_b`]}async decode(e){if(this.isSwapTransaction())return this.decodeSwap();if(this.isAddLiquidityTransaction())return this.decodeAddLiquidity();if(this.isIncreaseLiquidityTransaction())return this.decodeIncreaseLiquidity(e);if(this.isRemoveLiquidityTransaction())return this.decodeRemoveLiquidity(e);if(this.isDecreaseLiquidityTransaction())return this.decodeDecreaseLiquidity(e);if(this.isRemoveLiquidityWithReturnTransaction())return this.decodeRemoveLiquidityWithReturn(e);if(this.isDecreaseLiquidityWithReturnTransaction())return this.decodeDecreaseLiquidityWithReturn(e);if(this.isCollectFeeTransaction())return this.decodeCollectFee();if(this.isCollectRewardTransaction())return this.decodeCollectReward();if(this.isBurnTransaction())return this.decodeBurn();if(this.isPrixClaimTransaction())return this.decodePrixClaim();if(this.isPrixJoinTransaction())return this.decodePrixJoin();if(this.isSwapExactBaseForQuoteTransaction())return this.decodeSwapExactBaseForQuote();if(this.isSwapExactQuoteForBaseTransaction())return this.decodeSwapExactQuoteForBase();throw new Error("Unknown transaction type")}getMoveCallTransaction(e){return this.transactions.find(t=>t.$kind==="MoveCall"?`${t.MoveCall.package}::${t.MoveCall.module}::${t.MoveCall.function}`===e:!1)}getMoveCallsTransaction(e){return e.every(t=>this.transactions.find(n=>n.$kind==="MoveCall"?`${n.MoveCall.package}::${n.MoveCall.module}::${n.MoveCall.function}`===t:!1))}getSwapMoveCallTransaction(e){return this.transactions.find(t=>{if(t.$kind==="MoveCall"){let n=`${t.MoveCall.package}::${t.MoveCall.module}::${t.MoveCall.function}`;return!!e.includes(n)}return!1})}isSwapTransaction(){return!!this.getSwapMoveCallTransaction([...this.swap1Layer,...this.swap2Layer])}isAddLiquidityTransaction(){return!!this.getMoveCallTransaction(`${this.config.PackageId}::position_manager::mint`)}isIncreaseLiquidityTransaction(){return!!this.getMoveCallTransaction(`${this.config.PackageId}::position_manager::increase_liquidity`)}isDecreaseLiquidityTransaction(){return!!this.getMoveCallTransaction(`${this.config.PackageId}::position_manager::decrease_liquidity`)}isDecreaseLiquidityWithReturnTransaction(){return!!this.getMoveCallTransaction(`${this.config.PackageId}::position_manager::decrease_liquidity_with_return_`)}isCollectFeeTransaction(){return!!this.getMoveCallTransaction(`${this.config.PackageId}::position_manager::collect`)}isCollectRewardTransaction(){return!!this.getMoveCallTransaction(`${this.config.PackageId}::position_manager::collect_reward`)}isBurnTransaction(){return!!this.getMoveCallTransaction(`${this.config.PackageId}::position_manager::burn`)}isPrixJoinTransaction(){return!!this.getMoveCallTransaction(`${zt.PackageId}::claim::join`)}isPrixClaimTransaction(){return!!this.getMoveCallTransaction(`${zt.PackageId}::claim::claim`)}isRemoveLiquidityTransaction(){return!!this.getMoveCallsTransaction([`${this.config.PackageId}::position_manager::decrease_liquidity`,`${this.config.PackageId}::position_manager::burn`])}isRemoveLiquidityWithReturnTransaction(){return!!this.getMoveCallsTransaction([`${this.config.PackageId}::position_manager::decrease_liquidity_with_return_`,`${this.config.PackageId}::position_manager::burn`])}isSwapExactBaseForQuoteTransaction(){return!!this.getMoveCallTransaction(`${Gt.PackageId}::clob_v2::swap_exact_base_for_quote`)}isSwapExactQuoteForBaseTransaction(){return!!this.getMoveCallTransaction(`${Gt.PackageId}::clob_v2::swap_exact_quote_for_base`)}async decodeSwap(){let e=this.transactions.find(x=>x.$kind==="MoveCall"),t=0,n=`${e.MoveCall.package}::${e.MoveCall.module}::${e.MoveCall.function}`;this.swap2Layer.includes(n)&&(t=1);let o=$d(t,n,this.swap1Layer,this.swap2Layer),a=o.map((x,v)=>{let P=this.helper.decodeSharedObjectId(this.helper.getInputsIndex(v)),K=this.helper.decodeInputU128(this.helper.getInputsIndex(4+v+t)),H=this.turbosSdk.math.sqrtPriceX64ToTickIndex(new Im.BN(K.toString()));return{pool:P,a2b:x,nextTickIndex:H}}),c=o[0]||t===1?e.MoveCall.typeArguments[0]:e.MoveCall.typeArguments[1],l=t===1?e.MoveCall.typeArguments[4]:o[0]?e.MoveCall.typeArguments[1]:e.MoveCall.typeArguments[0],d=this.helper.decodeInputAddress(this.helper.getInputsIndex(6+2*t)),b=this.helper.decodeInputU64(this.helper.getInputsIndex(7+2*t)),I=this.helper.decodeInputBool(this.helper.getInputsIndex(5+2*t)),w=this.helper.decodeInputU64(this.helper.getInputsIndex(2+t)),k=this.helper.decodeInputU64(this.helper.getInputsIndex(3+t));return{txType:Nt.TransactionType.Other,type:"Swap",intentionData:{routes:a,coinTypeA:c,coinTypeB:l,address:d,amountA:I?w:k,amountB:I?k:w,amountSpecifiedIsInput:I,slippage:"0.1",deadline:b}}}decodeAddLiquidity(){console.log(this.helper,"decodeAddLiquidity this.helper");let e=this.helper.decodeSharedObjectId(this.helper.getInputsIndex(0)),t=this.helper.decodeInputAddress(this.helper.getInputsIndex(12)),n=this.helper.decodeInputU64(this.helper.getInputsIndex(8)),o=this.helper.decodeInputU64(this.helper.getInputsIndex(9)),a=this.helper.decodeInputU32(this.helper.getInputsIndex(4)),c=this.helper.decodeInputBool(this.helper.getInputsIndex(5)),l=this.helper.decodeInputU32(this.helper.getInputsIndex(6)),d=this.helper.decodeInputBool(this.helper.getInputsIndex(7)),b=this.helper.decodeInputU64(this.helper.getInputsIndex(13));return{txType:Nt.TransactionType.Other,type:"AddLiquidity",intentionData:{pool:e,slippage:10,address:t,amountA:n,amountB:o,tickLower:c?-a:a,tickUpper:d?-l:l,deadline:b}}}decodeIncreaseLiquidity(e){console.log(this.helper,"decodeIncreaseLiquidity this.helper");let t=this.helper.decodeSharedObjectId(this.helper.getInputsIndex(0)),n=this.helper.decodeSharedObjectId(this.helper.getInputsIndex(4)),o=this.helper.decodeInputU64(this.helper.getInputsIndex(5)),a=this.helper.decodeInputU64(this.helper.getInputsIndex(6)),c=this.helper.decodeInputU64(this.helper.getInputsIndex(9));return{txType:Nt.TransactionType.Other,type:"IncreaseLiquidity",intentionData:{pool:t,slippage:10,address:e,amountA:o,amountB:a,nft:n,deadline:c}}}decodeDecreaseLiquidity(e){console.log(this.helper,"decodeDecreaseLiquidity this.helper");let t=this.helper.decodeSharedObjectId(this.helper.getInputsIndex(0)),n=this.helper.decodeSharedObjectId(this.helper.getInputsIndex(2)),o=this.helper.decodeInputU64(this.helper.getInputsIndex(3)),a=this.helper.decodeInputU64(this.helper.getInputsIndex(4)),c=this.helper.decodeInputU64(this.helper.getInputsIndex(5)),l=this.helper.decodeInputU64(this.helper.getInputsIndex(6));return{txType:Nt.TransactionType.Other,type:"DecreaseLiquidity",intentionData:{pool:t,decreaseLiquidity:o,nft:n,amountA:a,amountB:c,slippage:10,address:e,deadline:l}}}decodeDecreaseLiquidityWithReturn(e){console.log(this.helper,"decodeDecreaseLiquidityWithReturn this.helper");let t=this.helper.decodeSharedObjectId(0),n=this.helper.decodeSharedObjectId(2),o=this.helper.decodeInputU64(3),a=this.helper.decodeInputU64(4),c=this.helper.decodeInputU64(5),l=this.helper.decodeInputU64(6);return{txType:Nt.TransactionType.Other,type:"DecreaseLiquidityWithReturn",intentionData:{pool:t,decreaseLiquidity:o,nft:n,amountA:a,amountB:c,slippage:10,address:e,deadline:l}}}decodeCollectFee(){console.log(this.helper,"decodeCollectFee this.helper");let e=this.helper.decodeSharedObjectId(this.helper.getInputsIndex(0)),t=this.helper.decodeSharedObjectId(this.helper.getInputsIndex(2)),n=this.helper.decodeInputAddress(this.helper.getInputsIndex(5)),o=this.helper.decodeInputU64(this.helper.getInputsIndex(3)),a=this.helper.decodeInputU64(this.helper.getInputsIndex(4)),c=this.helper.decodeInputU64(this.helper.getInputsIndex(6));return{txType:Nt.TransactionType.Other,type:"CollectFee",intentionData:{pool:e,address:n,collectAmountA:o,collectAmountB:a,nft:t,deadline:c}}}decodeCollectReward(){console.log(this.helper,"decodeCollectReward this.helper");let e=this.helper.decodeSharedObjectId(this.helper.getInputsIndex(0)),t=this.helper.decodeSharedObjectId(this.helper.getInputsIndex(2)),n=this.helper.decodeInputAddress(this.helper.getInputsIndex(6)),o=this.collectRewardHelper.map(c=>c.decodeInputU64(c.getInputsIndex(5))),a=this.helper.decodeInputU64(7);return{txType:Nt.TransactionType.Other,type:"CollectReward",intentionData:{pool:e,address:n,rewardAmounts:o,nft:t,deadline:a}}}decodeBurn(){console.log(this.helper,"decodeBurn this.helper");let e=this.helper.decodeSharedObjectId(this.helper.getInputsIndex(0)),t=this.helper.decodeSharedObjectId(this.helper.getInputsIndex(2));return{txType:Nt.TransactionType.Other,type:"Burn",intentionData:{pool:e,nft:t}}}decodeRemoveLiquidity(e){console.log(this.helper,"decodeRemoveLiquidity this.helper");let t=this.decreaseLiquidityHelper.decodeSharedObjectId(this.decreaseLiquidityHelper.getInputsIndex(0)),n=this.decreaseLiquidityHelper.decodeSharedObjectId(this.decreaseLiquidityHelper.getInputsIndex(2)),o=this.decreaseLiquidityHelper.decodeInputU64(this.decreaseLiquidityHelper.getInputsIndex(3)),a=this.decreaseLiquidityHelper.decodeInputU64(this.decreaseLiquidityHelper.getInputsIndex(4)),c=this.decreaseLiquidityHelper.decodeInputU64(this.decreaseLiquidityHelper.getInputsIndex(5)),l=this.decreaseLiquidityHelper.decodeInputU64(this.decreaseLiquidityHelper.getInputsIndex(6)),d=this.collectRewardHelper.map(w=>w.decodeInputU64(w.getInputsIndex(5))),b=this.collectFeeHelper.decodeInputU64(this.collectFeeHelper.getInputsIndex(3))||0,I=this.collectFeeHelper.decodeInputU64(this.collectFeeHelper.getInputsIndex(4))||0;return{txType:Nt.TransactionType.Other,type:"RemoveLiquidity",intentionData:{pool:t,decreaseLiquidity:o,nft:n,amountA:a,amountB:c,slippage:10,address:e,collectAmountA:b,collectAmountB:I,rewardAmounts:d,deadline:l}}}decodeRemoveLiquidityWithReturn(e){console.log(this.helper,"decodeRemoveLiquidityWithReturn this.helper");let t=this.decreaseLiquidityHelper.decodeSharedObjectId(0),n=this.decreaseLiquidityHelper.decodeSharedObjectId(2),o=this.decreaseLiquidityHelper.decodeInputU64(3),a=this.decreaseLiquidityHelper.decodeInputU64(4),c=this.decreaseLiquidityHelper.decodeInputU64(5),l=this.decreaseLiquidityHelper.decodeInputU64(6),d=this.collectRewardHelper.map(w=>w.decodeInputU64(5)),b=this.collectFeeHelper.decodeInputU64(3)||0,I=this.collectFeeHelper.decodeInputU64(4)||0;return{txType:Nt.TransactionType.Other,type:"removeLiquidityWithReturn",intentionData:{pool:t,decreaseLiquidity:o,nft:n,amountA:a,amountB:c,slippage:10,address:e,collectAmountA:b,collectAmountB:I,rewardAmounts:d,deadline:l}}}decodePrixClaim(){return{txType:Nt.TransactionType.Other,type:"PrixClaim",intentionData:{}}}decodePrixJoin(){return{txType:Nt.TransactionType.Other,type:"PrixJoin",intentionData:{}}}decodeSwapExactBaseForQuote(){let e=this.swapExactBaseForQuoteHelper.decodeSharedObjectId(0),t=this.swapExactBaseForQuoteHelper.decodeInputU64(3),n=this.swapExactBaseForQuoteHelper.shortTypeArg(0),o=this.swapExactBaseForQuoteHelper.shortTypeArg(1);return{txType:Nt.TransactionType.Other,type:"SwapExactBaseForQuote",intentionData:{poolId:e,amountIn:t,token1:n,token2:o}}}decodeSwapExactQuoteForBase(){let e=this.swapExactQuoteForBaseHelper.decodeSharedObjectId(0),t=this.swapExactQuoteForBaseHelper.decodeInputU64(3),n=this.swapExactQuoteForBaseHelper.shortTypeArg(0),o=this.swapExactQuoteForBaseHelper.shortTypeArg(1);return{txType:Nt.TransactionType.Other,type:"SwapExactQuoteForBase",intentionData:{poolId:e,amountIn:t,token1:n,token2:o}}}get helper(){let e=this.transactions.find(t=>{if(t.$kind==="MoveCall"){let n=`${t.MoveCall.package}::${t.MoveCall.module}::${t.MoveCall.function}`;return n!=="0x2::coin::zero"&&n!=="0x0000000000000000000000000000000000000000000000000000000000000002::coin::zero"}return!1});return new ke(e,this.txb)}get collectRewardHelper(){return this.transactions.filter(t=>t.$kind==="MoveCall"?`${t.MoveCall.package}::${t.MoveCall.module}::${t.MoveCall.function}`===`${this.config.PackageId}::position_manager::collect_reward`:!1).map(t=>new ke(t,this.txb))}get collectFeeHelper(){let e=this.transactions.find(t=>t.$kind==="MoveCall"?`${t.MoveCall.package}::${t.MoveCall.module}::${t.MoveCall.function}`===`${this.config.PackageId}::position_manager::collect`:!1);return new ke(e,this.txb)}get decreaseLiquidityHelper(){let e=this.transactions.find(t=>t.$kind==="MoveCall"?`${t.MoveCall.package}::${t.MoveCall.module}::${t.MoveCall.function}`===`${this.config.PackageId}::position_manager::decrease_liquidity`:!1);return new ke(e,this.txb)}get swapExactBaseForQuoteHelper(){let e=this.transactions.find(t=>t.$kind==="MoveCall"?`${t.MoveCall.package}::${t.MoveCall.module}::${t.MoveCall.function}`===`${Gt.PackageId}::clob_v2::swap_exact_base_for_quote`:!1);return new ke(e,this.txb)}get swapExactQuoteForBaseHelper(){let e=this.transactions.find(t=>t.$kind==="MoveCall"?`${t.MoveCall.package}::${t.MoveCall.module}::${t.MoveCall.function}`===`${Gt.PackageId}::clob_v2::swap_exact_quote_for_base`:!1);return new ke(e,this.txb)}},ke=class{constructor(e,t){this.moveCall=e;this.txb=t}get inputs(){return this.txb.getData().inputs}getInputsIndex(e){return this.moveCall.MoveCall.arguments[e].Input}decodeSharedObjectId(e){return this.inputs[e].Object?.SharedObject?.objectId||this.inputs[e].UnresolvedObject.objectId}decodeOwnedObjectId(e){return this.inputs[e].Object?.ImmOrOwnedObject?.objectId||this.inputs[e].UnresolvedObject.objectId}decodeInputU128(e){return Number(je.bcs.u128().parse(Uint8Array.from((0,Le.fromBase64)(this.inputs[e].Pure.bytes))))}decodeInputU64(e){return Number(je.bcs.u64().parse(Uint8Array.from((0,Le.fromBase64)(this.inputs[e].Pure.bytes))))}decodeInputU32(e){return Number(je.bcs.u32().parse(Uint8Array.from((0,Le.fromBase64)(this.inputs[e].Pure.bytes))))}decodeInputU8(e){return Number(je.bcs.u8().parse(Uint8Array.from((0,Le.fromBase64)(this.inputs[e].Pure.bytes))))}decodeInputAddress(e){return je.bcs.Address.parse(Uint8Array.from((0,Le.fromBase64)(this.inputs[e].Pure.bytes)))}decodeInputBool(e){return je.bcs.bool().parse(Uint8Array.from((0,Le.fromBase64)(this.inputs[e].Pure.bytes)))}shortTypeArg(e){return this.moveCall.MoveCall.typeArguments[e]}txArg(e){return this.moveCall.MoveCall.arguments[e]}};var wm=require("turbos-clmm-sdk");var Ni=class i extends C{constructor(t){super(t);this.data=t}txType;txSubType;async build(t){let n=new wm.TurbosSdk(t.network.replace("sui:",""),t.suiClient),{pool:o,address:a,amountA:c,amountB:l,slippage:d,tickLower:b,tickUpper:I,deadline:w,txb:k}=this.data;return n.pool.addLiquidity({pool:o,slippage:d,address:a,amountA:c,amountB:l,tickLower:b,tickUpper:I,deadline:w,txb:k})}static fromData(t){return new i(t)}};var Cm=require("turbos-clmm-sdk");var Wi=class i extends C{constructor(t){super(t);this.data=t}txType;txSubType;async build(t){let n=new Cm.TurbosSdk(t.network.replace("sui:",""),t.suiClient),{pool:o,nft:a,txb:c}=this.data;return n.position.burn({pool:o,nft:a,txb:c})}static fromData(t){return new i(t)}};var km=require("turbos-clmm-sdk");var _i=class i extends C{constructor(t){super(t);this.data=t}txType;txSubType;async build(t){let n=new km.TurbosSdk(t.network.replace("sui:",""),t.suiClient),{pool:o,address:a,nft:c,collectAmountA:l,collectAmountB:d,deadline:b,txb:I}=this.data;return n.pool.collectFee({pool:o,address:a,collectAmountA:l,collectAmountB:d,nft:c,deadline:b,txb:I})}static fromData(t){return new i(t)}};var xm=require("turbos-clmm-sdk");var Li=class i extends C{constructor(t){super(t);this.data=t}txType;txSubType;async build(t){let n=new xm.TurbosSdk(t.network.replace("sui:",""),t.suiClient),{pool:o,address:a,nft:c,rewardAmounts:l,deadline:d,txb:b}=this.data;return n.pool.collectReward({pool:o,address:a,rewardAmounts:l,nft:c,deadline:d,txb:b})}static fromData(t){return new i(t)}};var vm=require("turbos-clmm-sdk");var ji=class i extends C{constructor(t){super(t);this.data=t}txType;txSubType;async build(t){let n=new vm.TurbosSdk(t.network.replace("sui:",""),t.suiClient),{fee:o,address:a,tickLower:c,tickUpper:l,sqrtPrice:d,slippage:b,coinTypeA:I,coinTypeB:w,amountA:k,amountB:x,deadline:v,txb:P}=this.data;return n.pool.createPool({fee:o,amountA:k,amountB:x,address:a,tickLower:c,tickUpper:l,sqrtPrice:d,slippage:b,coinTypeA:I,coinTypeB:w,deadline:v,txb:P})}static fromData(t){return new i(t)}};var Dm=require("turbos-clmm-sdk");var Ui=class i extends C{constructor(t){super(t);this.data=t}txType;txSubType;async build(t){let n=new Dm.TurbosSdk(t.network.replace("sui:",""),t.suiClient),{pool:o,address:a,amountA:c,amountB:l,slippage:d,nft:b,decreaseLiquidity:I,deadline:w,txb:k}=this.data;return n.pool.decreaseLiquidity({pool:o,slippage:d,address:a,amountA:c,amountB:l,nft:b,decreaseLiquidity:I,deadline:w,txb:k})}static fromData(t){return new i(t)}};var Am=require("turbos-clmm-sdk");var qi=class i extends C{constructor(t){super(t);this.data=t}txType;txSubType;async build(t){let n=new Am.TurbosSdk(t.network.replace("sui:",""),t.suiClient),{pool:o,address:a,amountA:c,amountB:l,slippage:d,nft:b,decreaseLiquidity:I,deadline:w}=this.data,{txb:k,coinA:x,coinB:v}=await n.pool.decreaseLiquidityWithReturn({pool:o,slippage:d,address:a,amountA:c,amountB:l,nft:b,decreaseLiquidity:I,deadline:w});return k.transferObjects([x,v],this.data.address),k}static fromData(t){return new i(t)}};var Mm=require("turbos-clmm-sdk");var Fi=class i extends C{constructor(t){super(t);this.data=t}txType;txSubType;async build(t){let n=new Mm.TurbosSdk(t.network.replace("sui:",""),t.suiClient),{pool:o,address:a,amountA:c,amountB:l,slippage:d,nft:b,deadline:I,txb:w}=this.data;return n.pool.increaseLiquidity({pool:o,slippage:d,address:a,amountA:c,amountB:l,nft:b,deadline:I,txb:w})}static fromData(t){return new i(t)}};var Om=require("@mysten/sui/transactions"),Pm=require("@mysten/sui/utils");var Ki=class i extends C{constructor(t){super(t);this.data=t}txType;txSubType;async build(t){let n=new Om.Transaction;return n.moveCall({target:`${zt.PackageId}::claim::claim`,typeArguments:[zt.turbosCoinType],arguments:[n.object(zt.Claim),n.object(Pm.SUI_CLOCK_OBJECT_ID)]}),n}static fromData(t){return new i(t)}};var Rm=require("@mysten/sui/transactions");var $i=class i extends C{constructor(t){super(t);this.data=t}txType;txSubType;async build(t){let n=new Rm.Transaction;return n.moveCall({target:`${zt.PackageId}::claim::join`,typeArguments:[zt.turbosCoinType],arguments:[n.object(zt.Claim)]}),n}static fromData(t){return new i(t)}};var Bm=require("@mysten/sui/transactions"),Em=require("turbos-clmm-sdk");var Vi=class i extends C{constructor(t){super(t);this.data=t}txType;txSubType;async build(t){let n=new Em.TurbosSdk(t.network.replace("sui:",""),t.suiClient),o=new Bm.Transaction;return o=await n.pool.collectFee({txb:o,...this.data}),o=await n.pool.collectReward({txb:o,...this.data}),o=await n.pool.decreaseLiquidity({txb:o,...this.data}),o=await n.position.burn({txb:o,nft:this.data.nft,pool:this.data.pool}),o}static fromData(t){return new i(t)}};var Nm=require("turbos-clmm-sdk");var Hi=class i extends C{constructor(t){super(t);this.data=t}txType;txSubType;async build(t){let n=new Nm.TurbosSdk(t.network.replace("sui:",""),t.suiClient),{txb:o,coinA:a,coinB:c}=await n.pool.removeLiquidityWithReturn({...this.data});return o.transferObjects([a,c],this.data.address),o}static fromData(t){return new i(t)}};var Wm=require("turbos-clmm-sdk");var Xi=class i extends C{constructor(t){super(t);this.data=t}txType;txSubType;async build(t){console.log(this.data,"this.data");let n=new Wm.TurbosSdk(t.network.replace("sui:",""),t.suiClient),{routes:o,coinTypeA:a,coinTypeB:c,address:l,amountA:d,amountB:b,slippage:I,amountSpecifiedIsInput:w,deadline:k,txb:x}=this.data;return n.trade.swap({routes:o,coinTypeA:a,coinTypeB:c,address:l,amountA:d,amountB:b,amountSpecifiedIsInput:w,slippage:I,deadline:k,txb:x})}static fromData(t){return new i(t)}};var Fm=require("turbos-clmm-sdk");var Rs=require("@mysten/sui/transactions"),Bs=require("@mysten/sui/utils");var _m=require("turbos-clmm-sdk");var qn=class{constructor(e){this.turbosSdk=e}async getCoinsData(e,t,n){let o=[],a;do a=await this.turbosSdk.provider.getCoins({owner:e,coinType:t,cursor:a?.nextCursor}),o.push(...a.data);while(a.hasNextPage);let c=[],l=0;return o.sort((d,b)=>Number(b.balance)-Number(d.balance)).some(d=>l>=n?!0:(l+=Number(d.balance),c.push(d),!1)),c}splitAndMergeCoin(e,t,n){if(!e||e.length<1)return[void 0,void 0];if(this.isSuiCoinAddress(e[0].coinType)){let[c]=n.splitCoins(n.gas,[n.pure.u64(t)]);return[c,void 0]}let o=n.object(e[0].coinObjectId);e.length>1&&n.mergeCoins(o,e.slice(1).map(c=>n.object(c.coinObjectId)));let[a]=n.splitCoins(o,[n.pure.u64(t)]);return[a,o]}isSuiCoinAddress(e){return e.toLocaleLowerCase()==="0x2::sui::sui"}async IsAccountCap(e){let t=await this.turbosSdk.provider.getOwnedObjects({owner:e,options:{showContent:!0,showType:!0,showOwner:!0},filter:{StructType:`${Gt.PackageId}::custodian_v2::AccountCap`}});return t.data[0]?.data?(0,_m.unstable_getObjectId)(t.data[0].data):void 0}createAccount(e){let[t]=e.moveCall({typeArguments:[],target:`${Gt.PackageId}::clob_v2::create_account`,arguments:[]});return t}zero(e,t){return t.moveCall({typeArguments:[e],target:"0x2::coin::zero",arguments:[]})}};var Lm=89,jm=1e6,Um=async i=>{let{token1:e,token2:t,poolId:n,amountIn:o,currentAddress:a,turbosSdk:c}=i,l=new Rs.Transaction,d=new qn(c),b=await d.getCoinsData(a,t,o),[I,w]=d.splitAndMergeCoin(b,o,l);if(!I)throw new Error(`Not enough balance: ${t}`);let k=await d.IsAccountCap(a),x=k?l.object(k):d.createAccount(l),[v,P,K]=l.moveCall({typeArguments:[e,t],target:`${Gt.PackageId}::clob_v2::swap_exact_quote_for_base`,arguments:[l.object(String(n)),l.pure.u64(Lm),x,l.pure.u64(o),l.object((0,Bs.normalizeSuiObjectId)("0x6")),I]});return w&&l.transferObjects([w],l.pure.address(a)),l.transferObjects([v],l.pure.address(a)),l.transferObjects([P],l.pure.address(a)),k||l.transferObjects([x],l.pure.address(a)),l.setSenderIfNotSet(a),l.setGasBudget(jm),l},qm=async i=>{let{token1:e,token2:t,poolId:n,amountIn:o,currentAddress:a,turbosSdk:c}=i,l=new Rs.Transaction,d=new qn(c),b=await d.getCoinsData(a,e,o),[I,w]=d.splitAndMergeCoin(b,o,l);if(!I)throw new Error(`Not enough balance: ${e}`);let k=await d.IsAccountCap(a),x=k?l.object(k):d.createAccount(l),v=d.zero(t,l),[P,K,H]=l.moveCall({typeArguments:[e,t],target:`${Gt.PackageId}::clob_v2::swap_exact_base_for_quote`,arguments:[l.object(String(n)),l.pure.u64(Lm),x,l.pure.u64(o),I,v,l.object((0,Bs.normalizeSuiObjectId)("0x6"))]});return w&&l.transferObjects([w],l.pure.address(a)),l.transferObjects([P],l.pure.address(a)),l.transferObjects([K],l.pure.address(a)),k||l.transferObjects([x],l.pure.address(a)),l.setSenderIfNotSet(a),l.setGasBudget(jm),l};var zi=class i extends C{constructor(t){super(t);this.data=t}txType;txSubType;async build(t){let n=new Fm.TurbosSdk(t.network.replace("sui:",""),t.suiClient);return await qm({...this.data,turbosSdk:n,currentAddress:t.account.address})}static fromData(t){return new i(t)}};var Km=require("turbos-clmm-sdk");var Gi=class i extends C{constructor(t){super(t);this.data=t}txType;txSubType;async build(t){let n=new Km.TurbosSdk(t.network.replace("sui:",""),t.suiClient);return await Um({...this.data,turbosSdk:n,currentAddress:t.account.address})}static fromData(t){return new i(t)}};var Qi=class{application="turbos";supportSDK="@mysten/sui";async deserialize(e){console.log(e,"input");let t=new Vm.TurbosSdk(e.network.replace("sui:","")),n=await t.contract.getConfig(),{transaction:o,account:a}=e,l=await new Ei(o,t,n).decode(a.address);return{txType:$m.TransactionType.Other,txSubType:l.type,intentionData:l.intentionData}}async build(e){let{suiClient:t,account:n,network:o}=e;console.log(e.intentionData,"intentionData");let a;switch(e.txSubType){case"CreatePool":a=ji.fromData(e.intentionData);break;case"AddLiquidity":a=Ni.fromData(e.intentionData);break;case"IncreaseLiquidity":a=Fi.fromData(e.intentionData);break;case"DecreaseLiquidity":a=Ui.fromData(e.intentionData);break;case"DecreaseLiquidityWithReturn":a=qi.fromData(e.intentionData);break;case"RemoveLiquidity":a=Vi.fromData(e.intentionData);break;case"removeLiquidityWithReturn":a=Hi.fromData(e.intentionData);break;case"CollectFee":a=_i.fromData(e.intentionData);break;case"CollectReward":a=Li.fromData(e.intentionData);break;case"Burn":a=Wi.fromData(e.intentionData);break;case"Swap":a=Xi.fromData(e.intentionData);break;case"PrixJoin":a=$i.fromData(e.intentionData);break;case"PrixClaim":a=Ki.fromData(e.intentionData);break;case"SwapExactBaseForQuote":a=zi.fromData(e.intentionData);break;case"SwapExactQuoteForBase":a=Gi.fromData(e.intentionData);break;default:throw new Error("not implemented")}return a.build({suiClient:t,account:n,network:o})}};var Gm=require("@msafe/sui3-utils");var Ji=require("@msafe/sui3-utils"),Es=require("@mysten/sui.js/bcs"),xe=require("@mysten/sui.js/utils");var Vd={packageId:"0x549e8b69270defbfafd4f94e17ec44cdbdd99820b33bda2278dea3b9a32d3f55",poolObjectId:"0x7fa2faa111b8c65bea48a23049bfd81ca8f971a262d981dcd9a17c3825cb5baf",metadataObjectId:"0x680cd26af32b2bde8d3361e804c53ec1d1cfe24c7f039eb7f549e8dfde389a60",systemStateObjectId:"0x0000000000000000000000000000000000000000000000000000000000000005",certType:"0x549e8b69270defbfafd4f94e17ec44cdbdd99820b33bda2278dea3b9a32d3f55::cert::CERT",gasBudget:5e7},Dt=Vd;var Yi=class{constructor(e){this.txb=e}decode(){if(console.log("txb",this.txb),this.isStakeTransaction())return this.decodeStake();if(this.isUnStakeTransaction())return this.decodeUnStake();if(this.isClaimTicketTransaction())return this.decodeClaimTicket();throw new Error("Unknown transaction type")}get transactions(){return this.txb.blockData.transactions}getMoveCallTransaction(e){return this.transactions.find(t=>t.kind==="MoveCall"&&t.target===e)}isStakeTransaction(){return!!this.getMoveCallTransaction(`${Dt.packageId}::native_pool::stake`)}isUnStakeTransaction(){return!!this.getMoveCallTransaction(`${Dt.packageId}::native_pool::unstake`)}isClaimTicketTransaction(){return!!this.getMoveCallTransaction(`${Dt.packageId}::native_pool::burn_ticket`)}decodeStake(){let e=this.transactions[0].amounts[0].value.toNumber();return{txType:Ji.TransactionType.Other,type:"Stake",intentionData:{amount:e}}}decodeUnStake(){let t=this.transactions.find(n=>n.kind==="SplitCoins").amounts[0].value.toNumber();return{txType:Ji.TransactionType.Other,type:"UnStake",intentionData:{amount:t}}}decodeClaimTicket(){let e=this.helper.decodeOwnedObjectId(2);return console.log(e),{txType:Ji.TransactionType.Other,type:"ClaimTicket",intentionData:{ticketId:e}}}get helper(){let e=this.transactions.find(t=>t.kind==="MoveCall"&&t.target.startsWith(Dt.packageId));return new Ns(e,this.txb)}},Ns=class i{constructor(e,t){this.moveCall=e;this.txb=t}decodeSharedObjectId(e){let t=this.getInputParam(e);return i.getSharedObjectId(t)}decodeOwnedObjectId(e){let t=this.getInputParam(e);return i.getOwnedObjectId(t)}decodeInputU64(e){let t=this.decodePureArg(e,"u64");return Number(t)}decodeInputU8(e){let t=this.decodePureArg(e,"u8");return Number(t)}decodeInputAddress(e){let t=this.decodePureArg(e,"address");return(0,xe.normalizeSuiAddress)(t)}decodeInputString(e){return this.decodePureArg(e,"string")}decodeInputBool(e){return this.decodePureArg(e,"bool")}decodePureArg(e,t){let n=this.getInputParam(e);return i.getPureInputValue(n,t)}getInputParam(e){let t=this.moveCall.arguments[e];if(t.kind!=="Input")throw new Error("not input type");return this.txb.blockData.inputs[t.index]}static getPureInputValue(e,t){if(e.type!=="pure")throw new Error("not pure argument");if(typeof e.value=="object"&&"Pure"in e.value){let n=e.value.Pure;return Es.bcs.de(t,new Uint8Array(n))}return e.value}static getOwnedObjectId(e){if(e.type!=="object")throw new Error(`not object argument: ${JSON.stringify(e)}`);if(typeof e.value=="object"){if(!("Object"in e.value)||!("ImmOrOwned"in e.value.Object))throw new Error("not ImmOrOwned");return(0,xe.normalizeSuiAddress)(e.value.Object.ImmOrOwned.objectId)}return(0,xe.normalizeSuiAddress)(e.value)}static getSharedObjectId(e){if(e.type!=="object")throw new Error(`not object argument: ${JSON.stringify(e)}`);if(typeof e.value!="object")return(0,xe.normalizeSuiAddress)(e.value);if(!("Object"in e.value)||!("Shared"in e.value.Object))throw new Error("not Shared");return(0,xe.normalizeSuiAddress)(e.value.Object.Shared.objectId)}static getPureInput(e,t){if(e.type!=="pure")throw new Error("not pure argument");if(typeof e.value!="object")return e.value;if(!("Pure"in e.value))throw new Error("Pure not in value");let n=e.value.Pure;return Es.bcs.de(t,new Uint8Array(n))}typeArg(e){return(0,xe.normalizeStructTag)(this.moveCall.typeArguments[e])}txArg(e){return this.moveCall.arguments[e]}};var Hm=require("@mysten/sui.js/transactions");var Zi=class i extends _{constructor(t){super(t);this.data=t}txType;txSubType;async build(t){console.log(t);let n=new Hm.TransactionBlock,{ticketId:o}=this.data;return n.moveCall({target:`${Dt.packageId}::native_pool::burn_ticket`,arguments:[n.object(Dt.poolObjectId),n.object(Dt.systemStateObjectId),n.object(o)]}),n}static fromData(t){return new i(t)}};var Xm=require("@mysten/sui.js/transactions");var tr=class i extends _{constructor(t){super(t);this.data=t}txType;txSubType;async build(t){console.log(t);let n=new Xm.TransactionBlock,{amount:o}=this.data,[a]=n.splitCoins(n.gas,[n.pure(o)]);return n.moveCall({target:`${Dt.packageId}::native_pool::stake`,arguments:[n.object(Dt.poolObjectId),n.object(Dt.metadataObjectId),n.object(Dt.systemStateObjectId),a]}),n}static fromData(t){return new i(t)}};var zm=require("@mysten/sui.js/transactions");var er=class i extends _{constructor(t){super(t);this.data=t}txType;txSubType;async build(t){console.log(t);let n=new zm.TransactionBlock,{amount:o}=this.data,a=(await t.suiClient.getAllCoins({owner:t.account.address,limit:100})).data,[c,...l]=a.filter(I=>I.coinType.split("::")[0]===Dt.certType.split("::")[0]),d=n.object(c.coinObjectId);l.length&&n.mergeCoins(d,l.map(I=>n.object(I.coinObjectId)));let b=n.splitCoins(n.object(c.coinObjectId),[n.pure(o)]);return n.moveCall({target:`${Dt.packageId}::native_pool::unstake`,arguments:[n.object(Dt.poolObjectId),n.object(Dt.metadataObjectId),n.object(Dt.systemStateObjectId),b]}),n}static fromData(t){return new i(t)}};var nr=class{application="volo";supportSDK="@mysten/sui.js";async deserialize(e){let{transactionBlock:t}=e,o=new Yi(t).decode();return{txType:Gm.TransactionType.Other,txSubType:o.type,intentionData:o.intentionData}}async build(e){let{suiClient:t,account:n}=e,o;switch(e.txSubType){case"Stake":o=tr.fromData(e.intentionData);break;case"UnStake":o=er.fromData(e.intentionData);break;case"ClaimTicket":o=Zi.fromData(e.intentionData);break;default:throw new Error("not implemented")}return o.build({suiClient:t,account:n})}};var rp=require("@msafe/sui3-utils");var Ws=require("@cetusprotocol/common-sdk"),ve=require("@msafe/sui3-utils"),cn=require("@mysten/bcs"),ln=require("@mysten/sui/bcs");var or=class{constructor(e){this.transaction=e}decode(){if(this.isOpenPositionTx())return this.decodeOpenPositionTx();if(this.isClosePositionTx())return this.decodeClosePositionTx();if(this.isProvideLiquidityTx())return this.decodeProvideLiquidityTx();if(this.isRemoveLiquidityTx())return this.decodeRemoveLiquidityTx();if(this.isCollectRewardsAndFeeTx())return this.decodeCollectRewardsAndFeeTx();if(this.isCollectRewardsTx())return this.decodeCollectRewardsTx();if(this.isCollectFeeTx())return this.decodeCollectFeeTx();throw new Error("Unknown transaction type")}decodeOpenPositionTx(){let e=this.getMoveCallCommand("open_position"),t=this.getMoveCallCommand("provide_liquidity_with_fixed_amount");return{txType:ve.TransactionType.Other,type:"OpenPosition",intentionData:{pool:this.getSharedObjectID(this.getInputIndex(e,1)),lowerTick:Number((0,Ws.asIntN)(BigInt(this.getU32(this.getInputIndex(e,2)))).toString()),upperTick:Number((0,Ws.asIntN)(BigInt(this.getU32(this.getInputIndex(e,3)))).toString()),tokenAmount:this.getU64(this.getInputIndex(t,6)),maxAmountTokenA:this.getU64(this.getInputIndex(t,7)),maxAmountTokenB:this.getU64(this.getInputIndex(t,8)),isTokenAFixed:this.getBoolean(this.getInputIndex(t,9))}}}decodeClosePositionTx(){let e=this.getMoveCallCommand("close_position"),t=this.getCollectRewardCallData();return{txType:ve.TransactionType.Other,type:"ClosePosition",intentionData:{pool:this.getSharedObjectID(this.getInputIndex(e,2)),position:this.getOwnedObjectID(this.getInputIndex(e,3)),transferTokensTo:this.getAddress(this.getInputIndex(e,4)),collectRewardTokens:t.map(n=>n.rewardCoinType),collectFeeTokens:this.getTypeArguments(e)}}}decodeProvideLiquidityTx(){let e=this.getMoveCallCommand("provide_liquidity_with_fixed_amount");return{txType:ve.TransactionType.Other,type:"ProvideLiquidity",intentionData:{pool:this.getSharedObjectID(this.getInputIndex(e,2)),position:this.getOwnedObjectID(this.getInputIndex(e,3)),tokenAmount:this.getU64(this.getInputIndex(e,6)),maxAmountTokenA:this.getU64(this.getInputIndex(e,7)),maxAmountTokenB:this.getU64(this.getInputIndex(e,8)),isTokenAFixed:this.getBoolean(this.getInputIndex(e,9))}}}decodeRemoveLiquidityTx(){let e=this.getMoveCallCommand("remove_liquidity");return{txType:ve.TransactionType.Other,type:"RemoveLiquidity",intentionData:{pool:this.getSharedObjectID(this.getInputIndex(e,2)),position:this.getOwnedObjectID(this.getInputIndex(e,3)),liquidity:this.getU128(this.getInputIndex(e,4)),maxAmountTokenA:this.getU64(this.getInputIndex(e,5)),maxAmountTokenB:this.getU64(this.getInputIndex(e,6)),transferTokensTo:this.getAddress(this.getInputIndex(e,7)),...this.collectTokens()}}}decodeCollectRewardsTx(){let e=this.getCollectRewardCallData();return{txType:ve.TransactionType.Other,type:"CollectRewards",intentionData:{pool:e[0].pool,position:e[0].position,collectRewardTokens:e.map(t=>t.rewardCoinType)}}}decodeCollectFeeTx(){return{txType:ve.TransactionType.Other,type:"CollectFee",intentionData:this.getFeeCallData()}}decodeCollectRewardsAndFeeTx(){let e=this.getFeeCallData();return{txType:ve.TransactionType.Other,type:"CollectRewardsAndFee",intentionData:{pool:e.pool,position:e.position,...this.collectTokens()}}}getFeeCallData(){let e=this.getMoveCallCommand("collect_fee");return{pool:this.getSharedObjectID(this.getInputIndex(e,2)),position:this.getOwnedObjectID(this.getInputIndex(e,3)),collectFeeTokens:this.getTypeArguments(e)}}getCollectRewardCallData(){let e=[];return this.commands.forEach(t=>{t.$kind==="MoveCall"&&t.MoveCall.function==="collect_reward"&&e.push({pool:this.getSharedObjectID(this.getInputIndex(t,2)),position:this.getOwnedObjectID(this.getInputIndex(t,3)),rewardCoinType:this.getTypeArguments(t)[2]})}),e}collectTokens(){let e=this.getFeeCallData(),t=this.getCollectRewardCallData();return{collectFeeTokens:e.collectFeeTokens,collectRewardTokens:t.map(n=>n.rewardCoinType)}}get commands(){return this.transaction.getData().commands}get inputs(){return this.transaction.getData().inputs}isOpenPositionTx(){return!!this.getMoveCallCommand("open_position")}isProvideLiquidityTx(){return!!this.getMoveCallCommand("provide_liquidity_with_fixed_amount")}isRemoveLiquidityTx(){return!!this.getMoveCallCommand("remove_liquidity")}isCollectRewardsTx(){return!!this.getMoveCallCommand("collect_reward")}isCollectFeeTx(){return!!this.getMoveCallCommand("collect_fee")}isCollectRewardsAndFeeTx(){return this.isCollectRewardsTx()&&this.isCollectFeeTx()}isClosePositionTx(){return!!this.getMoveCallCommand("close_position")}getMoveCallCommand(e){return this.commands.find(t=>t.$kind==="MoveCall"&&t.MoveCall.function===e)}getSharedObjectID(e){return this.inputs[e].Object.SharedObject.objectId}getOwnedObjectID(e){return this.inputs[e].Object.ImmOrOwnedObject.objectId}getU32(e){return String(ln.bcs.u32().parse(Uint8Array.from((0,cn.fromBase64)(this.inputs[e].Pure.bytes))))}getU64(e){return ln.bcs.u64().parse(Uint8Array.from((0,cn.fromBase64)(this.inputs[e].Pure.bytes)))}getU128(e){return ln.bcs.u128().parse(Uint8Array.from((0,cn.fromBase64)(this.inputs[e].Pure.bytes)))}getBoolean(e){return ln.bcs.bool().parse(Uint8Array.from((0,cn.fromBase64)(this.inputs[e].Pure.bytes)))}getAddress(e){return ln.bcs.Address.parse(Uint8Array.from((0,cn.fromBase64)(this.inputs[e].Pure.bytes)))}getTypeArguments(e){return e.MoveCall.typeArguments||[]}getInputIndex(e,t){return e.MoveCall.arguments[t].Input}};var Zm=require("@msafe/sui3-utils");var ee=require("@firefly-exchange/library-sui");var Jm=require("@firefly-exchange/library-sui"),Ym=require("@firefly-exchange/library-sui/dist/src/spot"),Qm={rpc:"https://fullnode.mainnet.sui.io/",objects:{GlobalConfig:"0x03db251ba509a8d5d8777b6338836082335d93eecbdd09a11e190a1cff51c352",BasePackage:"0x3492c874c1e3b3e2984e8c41b589e642d4d0a5d6459e5a9cfc2d52fd7c89c267",CurrentPackage:"0x67b34b728c4e28e704dcfecf7c5cf55c7fc593b6c65c20d1836d97c209c1928a"}},Ae=(i,e)=>{if(i!=="sui:mainnet")throw new Error("Bluefin spot protocol is only available on sui::mainnet");let t=new Jm.SuiClient({url:Qm.rpc});return new Ym.OnChainCalls(t,Qm.objects,{address:e.address,isUIWallet:!1})};var Rt=class{static async OpenPosition(e,t,n){let o=Ae(n,t),a=await o.queryChain.getPool(e.pool),c=this.prototype.buildLiqInput(a,{...e,slippage:0});return await o.openPositionWithFixedAmount(a,e.lowerTick,e.upperTick,c,{returnTx:!0,sender:t.address})}static async provideLiquidity(e,t,n){let o=Ae(n,t),a=await o.queryChain.getPool(e.pool),c=this.prototype.buildLiqInput(a,e);return await o.provideLiquidityWithFixedAmount(a,e.position,c,{returnTx:!0,sender:t.address})}static async removeLiquidity(e,t,n){let o=Ae(n,t),a=await o.queryChain.getPool(e.pool);return await o.removeLiquidity(a,e.position,{liquidityAmount:new ee.BN(e.liquidity),tokenMaxA:new ee.BN(e.maxAmountTokenA),tokenMaxB:new ee.BN(e.maxAmountTokenB)},{returnTx:!0,sender:t.address})}static async closePosition(e,t,n){let o=Ae(n,t),a=await o.queryChain.getPool(e.pool);return await o.closePosition(a,e.position,{returnTx:!0,sender:t.address})}static async collectRewards(e,t,n){let o=Ae(n,t),a=await o.queryChain.getPool(e.pool);return await o.collectRewards(a,e.position,{rewardCoinsType:e.collectRewardTokens,returnTx:!0,sender:t.address})}static async collectFee(e,t,n){let o=Ae(n,t),a=await o.queryChain.getPool(e.pool);return await o.collectFee(a,e.position,{returnTx:!0,sender:t.address})}static async collectRewardsAndFee(e,t,n){let o=Ae(n,t),a=await o.queryChain.getPool(e.pool);return console.log(e.position),await o.collectFeeAndRewards(a,e.position,{returnTx:!0,sender:t.address})}buildLiqInput(e,t){return{...ee.ClmmPoolUtil.estLiquidityAndCoinAmountFromOneAmounts(t.lowerTick,t.upperTick,new ee.BN(t.tokenAmount),t.isTokenAFixed,!0,0,new ee.BN(e.current_sqrt_price)),tokenMaxA:new ee.BN(t.maxAmountTokenA),tokenMaxB:new ee.BN(t.maxAmountTokenB)}}};var ar=class i extends C{constructor(t){super(t);this.data=t}txType=Zm.TransactionType.Other;txSubType="ClosePosition";async build(t){let{account:n,network:o}=t;return console.log(this.data),Rt.closePosition(this.data,n,o)}static fromData(t){return new i(t)}};var tp=require("@msafe/sui3-utils");var ir=class i extends C{constructor(t){super(t);this.data=t}txType=tp.TransactionType.Other;txSubType="CollectFee";async build(t){let{account:n,network:o}=t;return console.log(this.data),Rt.collectFee(this.data,n,o)}static fromData(t){return new i(t)}};var ep=require("@msafe/sui3-utils");var rr=class i extends C{constructor(t){super(t);this.data=t}txType=ep.TransactionType.Other;txSubType="CollectRewards";async build(t){let{account:n,network:o}=t;return console.log(this.data),Rt.collectRewards(this.data,n,o)}static fromData(t){return new i(t)}};var np=require("@msafe/sui3-utils");var sr=class i extends C{constructor(t){super(t);this.data=t}txType=np.TransactionType.Other;txSubType="CollectRewardsAndFee";async build(t){let{account:n,network:o}=t;return console.log(this.data),Rt.collectRewardsAndFee(this.data,n,o)}static fromData(t){return new i(t)}};var op=require("@msafe/sui3-utils");var cr=class i extends C{constructor(t){super(t);this.data=t}txType=op.TransactionType.Other;txSubType="OpenPosition";async build(t){let{account:n,network:o}=t;return console.log(this.data),Rt.OpenPosition(this.data,n,o)}static fromData(t){return new i(t)}};var ap=require("@msafe/sui3-utils");var lr=class i extends C{constructor(t){super(t);this.data=t}txType=ap.TransactionType.Other;txSubType="ProvideLiquidity";async build(t){let{account:n,network:o}=t;return console.log(this.data),Rt.provideLiquidity(this.data,n,o)}static fromData(t){return new i(t)}};var ip=require("@msafe/sui3-utils");var ur=class i extends C{constructor(t){super(t);this.data=t}txType=ip.TransactionType.Other;txSubType="RemoveLiquidity";async build(t){let{account:n,network:o}=t;return console.log(this.data),Rt.removeLiquidity(this.data,n,o)}static fromData(t){return new i(t)}};var mr=class{application="bluefin";supportSDK="@mysten/sui";async deserialize(e){console.log("Bluefin helper deserialize input: ",e);let{transaction:t}=e,o=new or(t).decode();return{txType:rp.TransactionType.Other,txSubType:o.type,intentionData:o.intentionData}}async build(e){let{suiClient:t,account:n,network:o}=e;console.log(e.txSubType);let a;switch(e.txSubType){case"OpenPosition":a=cr.fromData(e.intentionData);break;case"ProvideLiquidity":a=lr.fromData(e.intentionData);break;case"RemoveLiquidity":a=ur.fromData(e.intentionData);break;case"ClosePosition":a=ar.fromData(e.intentionData);break;case"CollectFee":a=ir.fromData(e.intentionData);break;case"CollectRewards":a=rr.fromData(e.intentionData);break;case"CollectRewardsAndFee":a=sr.fromData(e.intentionData);break;default:throw new Error("not implemented")}return a.build({suiClient:t,account:n,network:o})}};var Lp=require("@msafe/sui3-utils");var yp=require("@mmt-finance/clmm-sdk"),bp=require("@mysten/sui/transactions");var Ue=require("@mmt-finance/clmm-sdk/dist/utils/math/tickMath"),R=Ut(cp());var Xd="0x0000000000000000000000000000000000000000000000000000000000000002::sui::SUI",Me=i=>i!=="0x2::sui::SUI"?i:"0x0000000000000000000000000000000000000000000000000000000000000002::sui::SUI",zd=async({suiClient:i,address:e,type:t})=>{let n,o=[],a=0;do{try{let c=await i.getCoins({owner:e,coinType:t,cursor:n,limit:50});o=o.concat(c.data),n=c.nextCursor,(!c.hasNextPage||a===8)&&(n=null)}catch(c){console.log(c),n=null}a++}while(n!==null);return o},Gd=(i,e)=>{let t=[],n=BigInt(0);for(let o of e)n<i&&!t.includes(o.objectId)&&(t.push(o.objectId),n+=BigInt(o.balance)),o.balance===BigInt(0)&&!t.includes(o.objectId)&&t.push(o.objectId);if(n>=i)return t;throw new Error("Insufficient balance")},Qd=(i,e,t,n)=>{if(i===Xd){let[o]=n.splitCoins(n.gas,[n.pure.u64(t)]);return o}else{let o=Gd(t,e);o.length>1&&n.mergeCoins(n.object(o[0]),o.slice(1).map(c=>n.object(c)));let[a]=n.splitCoins(n.object(o[0]),[n.pure.u64(t)]);return a}};async function lp(i,e,t,n,o){let a=await zd({suiClient:i.rpcClient,address:e,type:t});return Qd(Me(t),a.map(l=>({balance:BigInt(l.balance),objectId:l.coinObjectId})),n,o)}function E(i,e,t){let n=i.toTwos(t).shrn(e);return n.imaskn(t-e+1),n.fromTwos(t-e)}function Jd(i){let e;return i&1?e=new R.default("79232123823359799118286999567"):e=new R.default("79228162514264337593543950336"),i&2&&(e=E(e.mul(new R.default("79236085330515764027303304731")),96,256)),i&4&&(e=E(e.mul(new R.default("79244008939048815603706035061")),96,256)),i&8&&(e=E(e.mul(new R.default("79259858533276714757314932305")),96,256)),i&16&&(e=E(e.mul(new R.default("79291567232598584799939703904")),96,256)),i&32&&(e=E(e.mul(new R.default("79355022692464371645785046466")),96,256)),i&64&&(e=E(e.mul(new R.default("79482085999252804386437311141")),96,256)),i&128&&(e=E(e.mul(new R.default("79736823300114093921829183326")),96,256)),i&256&&(e=E(e.mul(new R.default("80248749790819932309965073892")),96,256)),i&512&&(e=E(e.mul(new R.default("81282483887344747381513967011")),96,256)),i&1024&&(e=E(e.mul(new R.default("83390072131320151908154831281")),96,256)),i&2048&&(e=E(e.mul(new R.default("87770609709833776024991924138")),96,256)),i&4096&&(e=E(e.mul(new R.default("97234110755111693312479820773")),96,256)),i&8192&&(e=E(e.mul(new R.default("119332217159966728226237229890")),96,256)),i&16384&&(e=E(e.mul(new R.default("179736315981702064433883588727")),96,256)),i&32768&&(e=E(e.mul(new R.default("407748233172238350107850275304")),96,256)),i&65536&&(e=E(e.mul(new R.default("2098478828474011932436660412517")),96,256)),i&131072&&(e=E(e.mul(new R.default("55581415166113811149459800483533")),96,256)),i&262144&&(e=E(e.mul(new R.default("38992368544603139932233054999993551")),96,256)),E(e,32,256)}function Yd(i){let e=Math.abs(i),t;return e&1?t=new R.default("18445821805675392311"):t=new R.default("18446744073709551616"),e&2&&(t=E(t.mul(new R.default("18444899583751176498")),64,256)),e&4&&(t=E(t.mul(new R.default("18443055278223354162")),64,256)),e&8&&(t=E(t.mul(new R.default("18439367220385604838")),64,256)),e&16&&(t=E(t.mul(new R.default("18431993317065449817")),64,256)),e&32&&(t=E(t.mul(new R.default("18417254355718160513")),64,256)),e&64&&(t=E(t.mul(new R.default("18387811781193591352")),64,256)),e&128&&(t=E(t.mul(new R.default("18329067761203520168")),64,256)),e&256&&(t=E(t.mul(new R.default("18212142134806087854")),64,256)),e&512&&(t=E(t.mul(new R.default("17980523815641551639")),64,256)),e&1024&&(t=E(t.mul(new R.default("17526086738831147013")),64,256)),e&2048&&(t=E(t.mul(new R.default("16651378430235024244")),64,256)),e&4096&&(t=E(t.mul(new R.default("15030750278693429944")),64,256)),e&8192&&(t=E(t.mul(new R.default("12247334978882834399")),64,256)),e&16384&&(t=E(t.mul(new R.default("8131365268884726200")),64,256)),e&32768&&(t=E(t.mul(new R.default("3584323654723342297")),64,256)),e&65536&&(t=E(t.mul(new R.default("696457651847595233")),64,256)),e&131072&&(t=E(t.mul(new R.default("26294789957452057")),64,256)),e&262144&&(t=E(t.mul(new R.default("37481735321082")),64,256)),t}var up=(i,e,t)=>{let n=(0,Ue.convertI32ToSigned)(t?i+i%(e??1):i-i%(e??1));return n>0?new R.default(Jd(n)):new R.default(Yd(n))};function mp(i,e){if(!/^(\d+)(\.\d+)?$/.test(i))return BigInt(0);let[t,n=""]=i.split("."),o=(n+"0".repeat(e)).slice(0,e),c=(t+o).replace(/^0+/,"")||"0";return BigInt(c)}async function Oe({address:i,coinType:e,coinAmount:t,coinDecimals:n,tx:o,mmt:a}){let c=mp(t,n),l;return Number(t)?l=await lp(a,i,Me(e),c,o):[l]=o.moveCall({target:"0x2::coin::zero",typeArguments:[e],arguments:[]}),l}function pp({mmt:i,tx:e,poolModel:t,selectedLowTick:n,selectedHighTick:o}){let a=up((0,Ue.convertI32ToSigned)(n),t.tickSpacing),c=up((0,Ue.convertI32ToSigned)(o),t.tickSpacing);return i.Position.openPosition(e,t,a.toString(),c.toString())}var Zd=(i,e)=>{let n=1e4-Math.floor(e*100);return i*BigInt(n)/BigInt(1e4)};function pr(i,e,t){let n=mp(i,e);return Number(i)===0?BigInt(0):Zd(n,t)}async function dr({poolId:i,currentSqrtPrice:e,tokenX:t,tokenY:n,slippagePercentage:o,isTokenX:a,suiClient:c}){let d=(await c.getObject({id:i,options:{showContent:!0}}))?.data?.content?.fields?.sqrt_price??e,b=Ue.TickMath.sqrtPriceX64ToPrice(new R.default(d?.toString()),t.decimals,n.decimals),I=a?(100-o)/100:(100+o)/100,w=Ue.TickMath.priceToSqrtPriceX64(b.mul(I),t.decimals,n.decimals);return BigInt(w.toString())}var dp=async(i,e,t,n,o,a,c,l,d,b)=>{let I=await Oe({mmt:i,address:t,coinType:a.tokenX.coinType,coinAmount:n,coinDecimals:a.tokenX.decimals,tx:e}),w=await Oe({mmt:i,address:t,coinType:a.tokenY.coinType,coinAmount:o,coinDecimals:a.tokenY.decimals,tx:e}),k={objectId:c,tokenXType:a.tokenXType,tokenYType:a.tokenYType,tickSpacing:a.tickSpacing},x=pp({mmt:i,tx:e,poolModel:k,selectedLowTick:l,selectedHighTick:d}),v=pr(n,a.tokenX.decimals,b),P=pr(o,a.tokenY.decimals,b);i.Pool.addLiquidity(e,k,x,I,w,v,P,t),e.transferObjects([x],e.pure.address(t))},fp=async(i,e,t,n,o,a,c,l,d,b,I)=>{try{let w=await Oe({mmt:i,address:n,coinType:a?c.tokenX.coinType:c.tokenY.coinType,coinAmount:o,coinDecimals:a?c.tokenX.decimals:c.tokenY.decimals,tx:e}),k={objectId:c.poolId,tokenXType:Me(c.tokenX.coinType),tokenYType:Me(c.tokenY.coinType),tickSpacing:c.tickSpacing},x=pp({mmt:i,tx:e,poolModel:k,selectedLowTick:l,selectedHighTick:d}),v=await dr({suiClient:t,poolId:c.poolId,currentSqrtPrice:c.currentSqrtPrice,tokenX:c.tokenX,tokenY:c.tokenY,slippagePercentage:b,isTokenX:a});await i.Pool.addLiquiditySingleSidedV2({txb:e,pool:k,position:x,inputCoin:w,isXtoY:a,limitSqrtPrice:v,slippagePercentage:I,transferToAddress:n,useMvr:!0}),e.transferObjects([x],e.pure.address(n))}catch(w){console.error(w)}},hp=async(i,e,t,n,o,a,c,l)=>{let d=await Oe({mmt:i,address:t,coinType:a.tokenX.coinType,coinAmount:n,coinDecimals:a.tokenX.decimals,tx:e}),b=await Oe({mmt:i,address:t,coinType:a.tokenY.coinType,coinAmount:o,coinDecimals:a.tokenY.decimals,tx:e}),I={objectId:a.poolId,tokenXType:a.tokenXType,tokenYType:a.tokenYType,tickSpacing:a.tickSpacing},w=pr(n,a.tokenX.decimals,l),k=pr(o,a.tokenY.decimals,l);i.Pool.addLiquidity(e,I,c,d,b,w,k,t)},gp=async(i,e,t,n,o,a,c,l,d)=>{try{let b=await Oe({mmt:i,address:t,coinType:o?a.tokenX.coinType:a.tokenY.coinType,coinAmount:n,coinDecimals:o?a.tokenX.decimals:a.tokenY.decimals,tx:e}),I={objectId:a.poolId,tokenXType:a.tokenX.coinType,tokenYType:a.tokenY.coinType,tickSpacing:a.tickSpacing},w=await dr({suiClient:i.rpcClient,poolId:a.poolId,currentSqrtPrice:a.currentSqrtPrice,tokenX:a.tokenX,tokenY:a.tokenY,slippagePercentage:l,isTokenX:o});await i.Pool.addLiquiditySingleSidedV2({txb:e,pool:I,position:c,inputCoin:b,isXtoY:o,limitSqrtPrice:w,slippagePercentage:d,transferToAddress:t})}catch(b){throw console.error(b),b}};var fr=class i extends C{constructor(t){super(t);this.data=t}txType;txSubType;async build(){let t=yp.MmtSDK.NEW({network:"mainnet"}),{params:n}=this.data,{address:o,amountA:a,amountB:c,pool:l,selectedLowTick:d,selectedHighTick:b,slippage:I}=n,w=new bp.Transaction;return await dp(t,w,o,a,c,l,l.poolId,d,b,I),w}static fromData(t){return new i(t)}};var Sp=require("@mmt-finance/clmm-sdk"),Tp=require("@mysten/sui/transactions");var hr=class i extends C{constructor(t){super(t);this.data=t}txType;txSubType;async build(){let t=Sp.MmtSDK.NEW({network:"mainnet"}),{params:n}=this.data,{address:o,amount:a,isTokenX:c,pool:l,selectedLowTick:d,selectedHighTick:b,swapSlippage:I,addLiquiditySlippage:w}=n,k=new Tp.Transaction;return await fp(t,k,t.rpcClient,o,a,c,l,d,b,I,w),k}static fromData(t){return new i(t)}};var Ip=require("@mmt-finance/clmm-sdk"),wp=require("@mysten/sui/transactions");var un=(i,e,t,n,o)=>{let a={objectId:n.poolId,tokenXType:n.tokenXType,tokenYType:n.tokenYType};n?.rewarders&&n?.rewarders.length>0&&i.Pool.collectAllRewards(o,a,n.rewarders.map(c=>({coin_type:c.coinType,flow_rate:c.flowRate,reward_amount:c.rewardAmount,rewards_allocated:c.rewardsAllocated,hasEnded:c.hasEnded})),t.objectId,e),i.Pool.collectFee(o,{objectId:n.poolId,tokenXType:n.tokenXType,tokenYType:n.tokenYType,isStable:n.isStable,tickSpacing:n.tickSpacing},t.objectId,e)};var gr=class i extends C{constructor(t){super(t);this.data=t}txType;txSubType;async build(){let t=Ip.MmtSDK.NEW({network:"mainnet"}),{params:n}=this.data,{address:o,positions:a,pools:c}=n,l=new wp.Transaction;for(let d of a){let b=c.find(I=>I.poolId===d.poolId);b&&un(t,o,d,b,l)}return l}static fromData(t){return new i(t)}};var Cp=require("@mmt-finance/clmm-sdk"),kp=require("@mysten/sui/transactions");var yr=class i extends C{constructor(t){super(t);this.data=t}txType;txSubType;async build(){let t=Cp.MmtSDK.NEW({network:"mainnet"}),{params:n}=this.data,{address:o,position:a,pool:c}=n,l=new kp.Transaction;return un(t,o,a,c,l),l}static fromData(t){return new i(t)}};var xp=require("@mmt-finance/clmm-sdk"),vp=require("@mysten/sui/transactions");var br=class i extends C{constructor(t){super(t);this.data=t}txType;txSubType;async build(){let t=xp.MmtSDK.NEW({network:"mainnet"}),{params:n}=this.data,{address:o,amountA:a,amountB:c,pool:l,positionObjectId:d,slippage:b}=n,I=new vp.Transaction;return await hp(t,I,o,a,c,l,d,b),I}static fromData(t){return new i(t)}};var Dp=require("@mmt-finance/clmm-sdk"),Ap=require("@mysten/sui/transactions");var Sr=class i extends C{constructor(t){super(t);this.data=t}txType;txSubType;async build(){let t=Dp.MmtSDK.NEW({network:"mainnet"}),{params:n}=this.data,{address:o,amount:a,isTokenX:c,pool:l,positionObjectId:d,swapSlippage:b,addLiquiditySlippage:I}=n,w=new Ap.Transaction;return await gp(t,w,o,a,c,l,d,b,I),w}static fromData(t){return new i(t)}};var Mp=require("@mmt-finance/clmm-sdk"),Op=require("@mysten/sui/transactions"),Pp=Ut(require("bignumber.js"));var Tr=class i extends C{constructor(t){super(t);this.data=t}txType;txSubType;async build(){let t=Mp.MmtSDK.NEW({network:"mainnet"}),{params:n}=this.data,{pool:o,position:a,address:c,withdrawPercentage:l}=n,d=new Op.Transaction,b=o.tokenX.coinType,I=o.tokenY.coinType,w={objectId:o.poolId,tokenXType:b,tokenYType:I},k=BigInt(l===100?a.liquidity:new Pp.default(a.liquidity).multipliedBy(l/100).toFixed(0));return t.Pool.removeLiquidity(d,w,a.objectId,k,BigInt(0),BigInt(0),c),un(t,c,a,o,d),l===100&&t.Position.closePosition(d,a.objectId),d}static fromData(t){return new i(t)}};var js=require("@mysten/sui/transactions"),Us=require("@suilend/springsui-sdk"),Ls={id:"0x0431232199873db77a92aa645cd43521437e9cc5c6fff07fd03edb88afe0b25a",type:"0x2b6602099970374cf58a2a1b9d96f005fccceb81e92eb059873baf420eb6c717::x_sui::X_SUI",weightHookId:"0x9e35c13dbb0bc437e8ad5a95ec463622f58763e060552ae8d100db77f4904601"},Rp=async(i,e,t)=>{let n=await Us.LstClient.initialize(i,Ls),o=new js.Transaction,[a]=o.splitCoins(o.gas,[BigInt(t)]),c=n.mint(o,a);return o.transferObjects([c],e),o},Bp=async(i,e,t)=>{let n=await Us.LstClient.initialize(i,Ls),o=await i.getCoins({owner:e,coinType:Ls.type,limit:1e3});if(o.data.length===0)throw new Error("No lst coins found");let a=new js.Transaction,c=o.data[0];o.data.length>1&&a.mergeCoins(c.coinObjectId,o.data.slice(1).map(b=>b.coinObjectId));let[l]=a.splitCoins(c.coinObjectId,[BigInt(t)]),d=n.redeem(a,l);return a.transferObjects([d],e),a};var Ir=class i extends C{constructor(t){super(t);this.data=t}txType;txSubType;async build(t){let{params:n}=this.data,{address:o,amount:a}=n;return await Rp(t.suiClient,o,a)}static fromData(t){return new i(t)}};var Wp=require("@mmt-finance/clmm-sdk"),_p=require("@mysten/sui/transactions");var Ep=require("@mmt-finance/clmm-sdk/dist/utils/poolUtils");var Np=async(i,e,t,n,o,a,c)=>{let l=await Oe({mmt:i,tx:a,address:o,coinType:t.coinType,coinAmount:n,coinDecimals:t.decimals}),d=a.moveCall({target:"0x2::coin::value",typeArguments:[t.coinType],arguments:[l]}),b=t.coinType;for(let I=0;I<e.length;I+=1){let{poolId:w,tokenX:k,tokenY:x,isStable:v,currentSqrtPrice:P}=e[I],{id:K,isReverse:H}=Ep.mappedMmtV3Pool[w]||{id:w,isReverse:!1},Et=Me(k.coinType)===Me(b);Et=H?!Et:Et;let Wt=H?x.coinType:k.coinType,Ot=H?k.coinType:x.coinType,mn=await dr({poolId:K,tokenX:k,tokenY:x,slippagePercentage:c,isTokenX:Et,suiClient:i.rpcClient,currentSqrtPrice:P}),_t=i.Pool.swap(a,{objectId:K,tokenXType:Wt,tokenYType:Ot,isStable:v},d,l,Et,void 0,mn,!1);a.transferObjects([l],a.pure.address(o)),l=_t,b=Et?Ot:Wt,d=a.moveCall({target:"0x2::coin::value",typeArguments:[b],arguments:[l]})}a.transferObjects([l],a.pure.address(o))};var wr=class i extends C{constructor(t){super(t);this.data=t}txType;txSubType;async build(){let t=Wp.MmtSDK.NEW({network:"mainnet"}),{params:n}=this.data,{route:o,tokenIn:a,amountIn:c,address:l,slippage:d}=n,b=new _p.Transaction;return await Np(t,o,a,c,l,b,d),b}static fromData(t){return new i(t)}};var Cr=class i extends C{constructor(t){super(t);this.data=t}txType;txSubType;async build(t){let{params:n}=this.data,{address:o,amount:a}=n;return await Bp(t.suiClient,o,a)}static fromData(t){return new i(t)}};var kr=class{application="mmt-dex";supportSDK="@mysten/sui";async deserialize(e){let{appContext:t}=e;return{txType:Lp.TransactionType.Other,txSubType:t.action,intentionData:t}}async build(e){let t;switch(e.txSubType){case"Swap":t=wr.fromData(e.intentionData);break;case"AddLiquidity":t=fr.fromData(e.intentionData);break;case"AddLiquiditySingleSide":t=hr.fromData(e.intentionData);break;case"ClaimRewards":t=yr.fromData(e.intentionData);break;case"ClaimAllRewards":t=gr.fromData(e.intentionData);break;case"RemoveLiquidity":t=Tr.fromData(e.intentionData);break;case"StakeXSui":t=Ir.fromData(e.intentionData);break;case"UnstakeXSui":t=Cr.fromData(e.intentionData);break;case"ManageLiquidity":t=br.fromData(e.intentionData);break;case"ManageLiquiditySingleSide":t=Sr.fromData(e.intentionData);break;default:throw new Error("not implemented")}return t.build({suiClient:e.suiClient})}};var tf=Ma.fromHelpers([new fa,new ka,new ma,new xa,new Ko,new Qi,new kr,new ui,new nr,new go,new Ti,new Mi,new Qn,new mr,new Bi]);
2
2
  //# sourceMappingURL=index.js.map