@msafe/sui-app-store 0.0.231 → 0.0.239

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 nm=Object.create;var Un=Object.defineProperty;var om=Object.getOwnPropertyDescriptor;var am=Object.getOwnPropertyNames;var rm=Object.getPrototypeOf,im=Object.prototype.hasOwnProperty;var sm=(a,e)=>()=>(e||a((e={exports:{}}).exports,e),e.exports),Mi=(a,e)=>{for(var t in e)Un(a,t,{get:e[t],enumerable:!0})},Ks=(a,e,t,n)=>{if(e&&typeof e=="object"||typeof e=="function")for(let o of am(e))!im.call(a,o)&&o!==t&&Un(a,o,{get:()=>e[o],enumerable:!(n=om(e,o))||n.enumerable});return a};var Ut=(a,e,t)=>(t=a!=null?nm(rm(a)):{},Ks(e||!a||!a.__esModule?Un(t,"default",{value:a,enumerable:!0}):t,a)),cm=a=>Ks(Un({},"__esModule",{value:!0}),a);var Wd=sm((Nd,Is)=>{"use strict";(function(a,e){"use strict";function t(g,r){if(!g)throw new Error(r||"Assertion failed")}function n(g,r){g.super_=r;var c=function(){};c.prototype=r.prototype,g.prototype=new c,g.prototype.constructor=g}function o(g,r,c){if(o.isBN(g))return g;this.negative=0,this.words=null,this.length=0,this.red=null,g!==null&&((r==="le"||r==="be")&&(c=r,r=10),this._init(g||0,r||10,c||"be"))}typeof a=="object"?a.exports=o:e.BN=o,o.BN=o,o.wordSize=26;var i;try{typeof window<"u"&&typeof window.Buffer<"u"?i=window.Buffer:i=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,c){return r.cmp(c)>0?r:c},o.min=function(r,c){return r.cmp(c)<0?r:c},o.prototype._init=function(r,c,d){if(typeof r=="number")return this._initNumber(r,c,d);if(typeof r=="object")return this._initArray(r,c,d);c==="hex"&&(c=16),t(c===(c|0)&&c>=2&&c<=36),r=r.toString().replace(/\s+/g,"");var m=0;r[0]==="-"&&(m++,this.negative=1),m<r.length&&(c===16?this._parseHex(r,m,d):(this._parseBase(r,c,m),d==="le"&&this._initArray(this.toArray(),c,d)))},o.prototype._initNumber=function(r,c,d){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),d==="le"&&this._initArray(this.toArray(),c,d)},o.prototype._initArray=function(r,c,d){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 m=0;m<this.length;m++)this.words[m]=0;var f,y,w=0;if(d==="be")for(m=r.length-1,f=0;m>=0;m-=3)y=r[m]|r[m-1]<<8|r[m-2]<<16,this.words[f]|=y<<w&67108863,this.words[f+1]=y>>>26-w&67108863,w+=24,w>=26&&(w-=26,f++);else if(d==="le")for(m=0,f=0;m<r.length;m+=3)y=r[m]|r[m+1]<<8|r[m+2]<<16,this.words[f]|=y<<w&67108863,this.words[f+1]=y>>>26-w&67108863,w+=24,w>=26&&(w-=26,f++);return this._strip()};function l(g,r){var c=g.charCodeAt(r);if(c>=48&&c<=57)return c-48;if(c>=65&&c<=70)return c-55;if(c>=97&&c<=102)return c-87;t(!1,"Invalid character in "+g)}function u(g,r,c){var d=l(g,c);return c-1>=r&&(d|=l(g,c-1)<<4),d}o.prototype._parseHex=function(r,c,d){this.length=Math.ceil((r.length-c)/6),this.words=new Array(this.length);for(var m=0;m<this.length;m++)this.words[m]=0;var f=0,y=0,w;if(d==="be")for(m=r.length-1;m>=c;m-=2)w=u(r,c,m)<<f,this.words[y]|=w&67108863,f>=18?(f-=18,y+=1,this.words[y]|=w>>>26):f+=8;else{var p=r.length-c;for(m=p%2===0?c+1:c;m<r.length;m+=2)w=u(r,c,m)<<f,this.words[y]|=w&67108863,f>=18?(f-=18,y+=1,this.words[y]|=w>>>26):f+=8}this._strip()};function b(g,r,c,d){for(var m=0,f=0,y=Math.min(g.length,c),w=r;w<y;w++){var p=g.charCodeAt(w)-48;m*=d,p>=49?f=p-49+10:p>=17?f=p-17+10:f=p,t(p>=0&&f<d,"Invalid character"),m+=f}return m}o.prototype._parseBase=function(r,c,d){this.words=[0],this.length=1;for(var m=0,f=1;f<=67108863;f*=c)m++;m--,f=f/c|0;for(var y=r.length-d,w=y%m,p=Math.min(y,y-w)+d,s=0,h=d;h<p;h+=m)s=b(r,h,h+m,c),this.imuln(f),this.words[0]+s<67108864?this.words[0]+=s:this._iaddn(s);if(w!==0){var D=1;for(s=b(r,h,r.length,c),h=0;h<w;h++)D*=c;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 c=0;c<this.length;c++)r.words[c]=this.words[c];r.length=this.length,r.negative=this.negative,r.red=this.red};function T(g,r){g.words=r.words,g.length=r.length,g.negative=r.negative,g.red=r.red}if(o.prototype._move=function(r){T(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")]=S}catch{o.prototype.inspect=S}else o.prototype.inspect=S;function S(){return(this.red?"<BN-R: ":"<BN: ")+this.toString(16)+">"}var C=["","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"],I=[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,c){r=r||10,c=c|0||1;var d;if(r===16||r==="hex"){d="";for(var m=0,f=0,y=0;y<this.length;y++){var w=this.words[y],p=((w<<m|f)&16777215).toString(16);f=w>>>24-m&16777215,m+=2,m>=26&&(m-=26,y--),f!==0||y!==this.length-1?d=C[6-p.length]+p+d:d=p+d}for(f!==0&&(d=f.toString(16)+d);d.length%c!==0;)d="0"+d;return this.negative!==0&&(d="-"+d),d}if(r===(r|0)&&r>=2&&r<=36){var s=I[r],h=x[r];d="";var D=this.clone();for(D.negative=0;!D.isZero();){var A=D.modrn(h).toString(r);D=D.idivn(h),D.isZero()?d=A+d:d=C[s-A.length]+A+d}for(this.isZero()&&(d="0"+d);d.length%c!==0;)d="0"+d;return this.negative!==0&&(d="-"+d),d}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)},i&&(o.prototype.toBuffer=function(r,c){return this.toArrayLike(i,r,c)}),o.prototype.toArray=function(r,c){return this.toArrayLike(Array,r,c)};var v=function(r,c){return r.allocUnsafe?r.allocUnsafe(c):new r(c)};o.prototype.toArrayLike=function(r,c,d){this._strip();var m=this.byteLength(),f=d||Math.max(1,m);t(m<=f,"byte array longer than desired length"),t(f>0,"Requested array length <= 0");var y=v(r,f),w=c==="le"?"LE":"BE";return this["_toArrayLike"+w](y,m),y},o.prototype._toArrayLikeLE=function(r,c){for(var d=0,m=0,f=0,y=0;f<this.length;f++){var w=this.words[f]<<y|m;r[d++]=w&255,d<r.length&&(r[d++]=w>>8&255),d<r.length&&(r[d++]=w>>16&255),y===6?(d<r.length&&(r[d++]=w>>24&255),m=0,y=0):(m=w>>>24,y+=2)}if(d<r.length)for(r[d++]=m;d<r.length;)r[d++]=0},o.prototype._toArrayLikeBE=function(r,c){for(var d=r.length-1,m=0,f=0,y=0;f<this.length;f++){var w=this.words[f]<<y|m;r[d--]=w&255,d>=0&&(r[d--]=w>>8&255),d>=0&&(r[d--]=w>>16&255),y===6?(d>=0&&(r[d--]=w>>24&255),m=0,y=0):(m=w>>>24,y+=2)}if(d>=0)for(r[d--]=m;d>=0;)r[d--]=0},Math.clz32?o.prototype._countBits=function(r){return 32-Math.clz32(r)}:o.prototype._countBits=function(r){var c=r,d=0;return c>=4096&&(d+=13,c>>>=13),c>=64&&(d+=7,c>>>=7),c>=8&&(d+=4,c>>>=4),c>=2&&(d+=2,c>>>=2),d+c},o.prototype._zeroBits=function(r){if(r===0)return 26;var c=r,d=0;return c&8191||(d+=13,c>>>=13),c&127||(d+=7,c>>>=7),c&15||(d+=4,c>>>=4),c&3||(d+=2,c>>>=2),c&1||d++,d},o.prototype.bitLength=function(){var r=this.words[this.length-1],c=this._countBits(r);return(this.length-1)*26+c};function O(g){for(var r=new Array(g.bitLength()),c=0;c<r.length;c++){var d=c/26|0,m=c%26;r[c]=g.words[d]>>>m&1}return r}o.prototype.zeroBits=function(){if(this.isZero())return 0;for(var r=0,c=0;c<this.length;c++){var d=this._zeroBits(this.words[c]);if(r+=d,d!==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 c=0;c<r.length;c++)this.words[c]=this.words[c]|r.words[c];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 c;this.length>r.length?c=r:c=this;for(var d=0;d<c.length;d++)this.words[d]=this.words[d]&r.words[d];return this.length=c.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 c,d;this.length>r.length?(c=this,d=r):(c=r,d=this);for(var m=0;m<d.length;m++)this.words[m]=c.words[m]^d.words[m];if(this!==c)for(;m<c.length;m++)this.words[m]=c.words[m];return this.length=c.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 c=Math.ceil(r/26)|0,d=r%26;this._expand(c),d>0&&c--;for(var m=0;m<c;m++)this.words[m]=~this.words[m]&67108863;return d>0&&(this.words[m]=~this.words[m]&67108863>>26-d),this._strip()},o.prototype.notn=function(r){return this.clone().inotn(r)},o.prototype.setn=function(r,c){t(typeof r=="number"&&r>=0);var d=r/26|0,m=r%26;return this._expand(d+1),c?this.words[d]=this.words[d]|1<<m:this.words[d]=this.words[d]&~(1<<m),this._strip()},o.prototype.iadd=function(r){var c;if(this.negative!==0&&r.negative===0)return this.negative=0,c=this.isub(r),this.negative^=1,this._normSign();if(this.negative===0&&r.negative!==0)return r.negative=0,c=this.isub(r),r.negative=1,c._normSign();var d,m;this.length>r.length?(d=this,m=r):(d=r,m=this);for(var f=0,y=0;y<m.length;y++)c=(d.words[y]|0)+(m.words[y]|0)+f,this.words[y]=c&67108863,f=c>>>26;for(;f!==0&&y<d.length;y++)c=(d.words[y]|0)+f,this.words[y]=c&67108863,f=c>>>26;if(this.length=d.length,f!==0)this.words[this.length]=f,this.length++;else if(d!==this)for(;y<d.length;y++)this.words[y]=d.words[y];return this},o.prototype.add=function(r){var c;return r.negative!==0&&this.negative===0?(r.negative=0,c=this.sub(r),r.negative^=1,c):r.negative===0&&this.negative!==0?(this.negative=0,c=r.sub(this),this.negative=1,c):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 c=this.iadd(r);return r.negative=1,c._normSign()}else if(this.negative!==0)return this.negative=0,this.iadd(r),this.negative=1,this._normSign();var d=this.cmp(r);if(d===0)return this.negative=0,this.length=1,this.words[0]=0,this;var m,f;d>0?(m=this,f=r):(m=r,f=this);for(var y=0,w=0;w<f.length;w++)c=(m.words[w]|0)-(f.words[w]|0)+y,y=c>>26,this.words[w]=c&67108863;for(;y!==0&&w<m.length;w++)c=(m.words[w]|0)+y,y=c>>26,this.words[w]=c&67108863;if(y===0&&w<m.length&&m!==this)for(;w<m.length;w++)this.words[w]=m.words[w];return this.length=Math.max(this.length,w),m!==this&&(this.negative=1),this._strip()},o.prototype.sub=function(r){return this.clone().isub(r)};function L(g,r,c){c.negative=r.negative^g.negative;var d=g.length+r.length|0;c.length=d,d=d-1|0;var m=g.words[0]|0,f=r.words[0]|0,y=m*f,w=y&67108863,p=y/67108864|0;c.words[0]=w;for(var s=1;s<d;s++){for(var h=p>>>26,D=p&67108863,A=Math.min(s,r.length-1),M=Math.max(0,s-g.length+1);M<=A;M++){var _=s-M|0;m=g.words[_]|0,f=r.words[M]|0,y=m*f+D,h+=y/67108864|0,D=y&67108863}c.words[s]=D|0,p=h|0}return p!==0?c.words[s]=p|0:c.length--,c._strip()}var $=function(r,c,d){var m=r.words,f=c.words,y=d.words,w=0,p,s,h,D=m[0]|0,A=D&8191,M=D>>>13,_=m[1]|0,W=_&8191,U=_>>>13,ie=m[2]|0,q=ie&8191,F=ie>>>13,vs=m[3]|0,G=vs&8191,z=vs>>>13,Ds=m[4]|0,Q=Ds&8191,J=Ds>>>13,As=m[5]|0,X=As&8191,Y=As>>>13,Ms=m[6]|0,Z=Ms&8191,tt=Ms>>>13,Os=m[7]|0,et=Os&8191,nt=Os>>>13,Ps=m[8]|0,ot=Ps&8191,at=Ps>>>13,Rs=m[9]|0,rt=Rs&8191,it=Rs>>>13,Bs=f[0]|0,st=Bs&8191,ct=Bs>>>13,_s=f[1]|0,lt=_s&8191,ut=_s>>>13,Es=f[2]|0,dt=Es&8191,mt=Es>>>13,Ns=f[3]|0,pt=Ns&8191,ft=Ns>>>13,Ws=f[4]|0,ht=Ws&8191,bt=Ws>>>13,Ls=f[5]|0,gt=Ls&8191,yt=Ls>>>13,js=f[6]|0,Tt=js&8191,wt=js>>>13,Us=f[7]|0,St=Us&8191,Ct=Us>>>13,qs=f[8]|0,It=qs&8191,xt=qs>>>13,Fs=f[9]|0,kt=Fs&8191,vt=Fs>>>13;d.negative=r.negative^c.negative,d.length=19,p=Math.imul(A,st),s=Math.imul(A,ct),s=s+Math.imul(M,st)|0,h=Math.imul(M,ct);var ui=(w+p|0)+((s&8191)<<13)|0;w=(h+(s>>>13)|0)+(ui>>>26)|0,ui&=67108863,p=Math.imul(W,st),s=Math.imul(W,ct),s=s+Math.imul(U,st)|0,h=Math.imul(U,ct),p=p+Math.imul(A,lt)|0,s=s+Math.imul(A,ut)|0,s=s+Math.imul(M,lt)|0,h=h+Math.imul(M,ut)|0;var di=(w+p|0)+((s&8191)<<13)|0;w=(h+(s>>>13)|0)+(di>>>26)|0,di&=67108863,p=Math.imul(q,st),s=Math.imul(q,ct),s=s+Math.imul(F,st)|0,h=Math.imul(F,ct),p=p+Math.imul(W,lt)|0,s=s+Math.imul(W,ut)|0,s=s+Math.imul(U,lt)|0,h=h+Math.imul(U,ut)|0,p=p+Math.imul(A,dt)|0,s=s+Math.imul(A,mt)|0,s=s+Math.imul(M,dt)|0,h=h+Math.imul(M,mt)|0;var mi=(w+p|0)+((s&8191)<<13)|0;w=(h+(s>>>13)|0)+(mi>>>26)|0,mi&=67108863,p=Math.imul(G,st),s=Math.imul(G,ct),s=s+Math.imul(z,st)|0,h=Math.imul(z,ct),p=p+Math.imul(q,lt)|0,s=s+Math.imul(q,ut)|0,s=s+Math.imul(F,lt)|0,h=h+Math.imul(F,ut)|0,p=p+Math.imul(W,dt)|0,s=s+Math.imul(W,mt)|0,s=s+Math.imul(U,dt)|0,h=h+Math.imul(U,mt)|0,p=p+Math.imul(A,pt)|0,s=s+Math.imul(A,ft)|0,s=s+Math.imul(M,pt)|0,h=h+Math.imul(M,ft)|0;var pi=(w+p|0)+((s&8191)<<13)|0;w=(h+(s>>>13)|0)+(pi>>>26)|0,pi&=67108863,p=Math.imul(Q,st),s=Math.imul(Q,ct),s=s+Math.imul(J,st)|0,h=Math.imul(J,ct),p=p+Math.imul(G,lt)|0,s=s+Math.imul(G,ut)|0,s=s+Math.imul(z,lt)|0,h=h+Math.imul(z,ut)|0,p=p+Math.imul(q,dt)|0,s=s+Math.imul(q,mt)|0,s=s+Math.imul(F,dt)|0,h=h+Math.imul(F,mt)|0,p=p+Math.imul(W,pt)|0,s=s+Math.imul(W,ft)|0,s=s+Math.imul(U,pt)|0,h=h+Math.imul(U,ft)|0,p=p+Math.imul(A,ht)|0,s=s+Math.imul(A,bt)|0,s=s+Math.imul(M,ht)|0,h=h+Math.imul(M,bt)|0;var fi=(w+p|0)+((s&8191)<<13)|0;w=(h+(s>>>13)|0)+(fi>>>26)|0,fi&=67108863,p=Math.imul(X,st),s=Math.imul(X,ct),s=s+Math.imul(Y,st)|0,h=Math.imul(Y,ct),p=p+Math.imul(Q,lt)|0,s=s+Math.imul(Q,ut)|0,s=s+Math.imul(J,lt)|0,h=h+Math.imul(J,ut)|0,p=p+Math.imul(G,dt)|0,s=s+Math.imul(G,mt)|0,s=s+Math.imul(z,dt)|0,h=h+Math.imul(z,mt)|0,p=p+Math.imul(q,pt)|0,s=s+Math.imul(q,ft)|0,s=s+Math.imul(F,pt)|0,h=h+Math.imul(F,ft)|0,p=p+Math.imul(W,ht)|0,s=s+Math.imul(W,bt)|0,s=s+Math.imul(U,ht)|0,h=h+Math.imul(U,bt)|0,p=p+Math.imul(A,gt)|0,s=s+Math.imul(A,yt)|0,s=s+Math.imul(M,gt)|0,h=h+Math.imul(M,yt)|0;var hi=(w+p|0)+((s&8191)<<13)|0;w=(h+(s>>>13)|0)+(hi>>>26)|0,hi&=67108863,p=Math.imul(Z,st),s=Math.imul(Z,ct),s=s+Math.imul(tt,st)|0,h=Math.imul(tt,ct),p=p+Math.imul(X,lt)|0,s=s+Math.imul(X,ut)|0,s=s+Math.imul(Y,lt)|0,h=h+Math.imul(Y,ut)|0,p=p+Math.imul(Q,dt)|0,s=s+Math.imul(Q,mt)|0,s=s+Math.imul(J,dt)|0,h=h+Math.imul(J,mt)|0,p=p+Math.imul(G,pt)|0,s=s+Math.imul(G,ft)|0,s=s+Math.imul(z,pt)|0,h=h+Math.imul(z,ft)|0,p=p+Math.imul(q,ht)|0,s=s+Math.imul(q,bt)|0,s=s+Math.imul(F,ht)|0,h=h+Math.imul(F,bt)|0,p=p+Math.imul(W,gt)|0,s=s+Math.imul(W,yt)|0,s=s+Math.imul(U,gt)|0,h=h+Math.imul(U,yt)|0,p=p+Math.imul(A,Tt)|0,s=s+Math.imul(A,wt)|0,s=s+Math.imul(M,Tt)|0,h=h+Math.imul(M,wt)|0;var bi=(w+p|0)+((s&8191)<<13)|0;w=(h+(s>>>13)|0)+(bi>>>26)|0,bi&=67108863,p=Math.imul(et,st),s=Math.imul(et,ct),s=s+Math.imul(nt,st)|0,h=Math.imul(nt,ct),p=p+Math.imul(Z,lt)|0,s=s+Math.imul(Z,ut)|0,s=s+Math.imul(tt,lt)|0,h=h+Math.imul(tt,ut)|0,p=p+Math.imul(X,dt)|0,s=s+Math.imul(X,mt)|0,s=s+Math.imul(Y,dt)|0,h=h+Math.imul(Y,mt)|0,p=p+Math.imul(Q,pt)|0,s=s+Math.imul(Q,ft)|0,s=s+Math.imul(J,pt)|0,h=h+Math.imul(J,ft)|0,p=p+Math.imul(G,ht)|0,s=s+Math.imul(G,bt)|0,s=s+Math.imul(z,ht)|0,h=h+Math.imul(z,bt)|0,p=p+Math.imul(q,gt)|0,s=s+Math.imul(q,yt)|0,s=s+Math.imul(F,gt)|0,h=h+Math.imul(F,yt)|0,p=p+Math.imul(W,Tt)|0,s=s+Math.imul(W,wt)|0,s=s+Math.imul(U,Tt)|0,h=h+Math.imul(U,wt)|0,p=p+Math.imul(A,St)|0,s=s+Math.imul(A,Ct)|0,s=s+Math.imul(M,St)|0,h=h+Math.imul(M,Ct)|0;var gi=(w+p|0)+((s&8191)<<13)|0;w=(h+(s>>>13)|0)+(gi>>>26)|0,gi&=67108863,p=Math.imul(ot,st),s=Math.imul(ot,ct),s=s+Math.imul(at,st)|0,h=Math.imul(at,ct),p=p+Math.imul(et,lt)|0,s=s+Math.imul(et,ut)|0,s=s+Math.imul(nt,lt)|0,h=h+Math.imul(nt,ut)|0,p=p+Math.imul(Z,dt)|0,s=s+Math.imul(Z,mt)|0,s=s+Math.imul(tt,dt)|0,h=h+Math.imul(tt,mt)|0,p=p+Math.imul(X,pt)|0,s=s+Math.imul(X,ft)|0,s=s+Math.imul(Y,pt)|0,h=h+Math.imul(Y,ft)|0,p=p+Math.imul(Q,ht)|0,s=s+Math.imul(Q,bt)|0,s=s+Math.imul(J,ht)|0,h=h+Math.imul(J,bt)|0,p=p+Math.imul(G,gt)|0,s=s+Math.imul(G,yt)|0,s=s+Math.imul(z,gt)|0,h=h+Math.imul(z,yt)|0,p=p+Math.imul(q,Tt)|0,s=s+Math.imul(q,wt)|0,s=s+Math.imul(F,Tt)|0,h=h+Math.imul(F,wt)|0,p=p+Math.imul(W,St)|0,s=s+Math.imul(W,Ct)|0,s=s+Math.imul(U,St)|0,h=h+Math.imul(U,Ct)|0,p=p+Math.imul(A,It)|0,s=s+Math.imul(A,xt)|0,s=s+Math.imul(M,It)|0,h=h+Math.imul(M,xt)|0;var yi=(w+p|0)+((s&8191)<<13)|0;w=(h+(s>>>13)|0)+(yi>>>26)|0,yi&=67108863,p=Math.imul(rt,st),s=Math.imul(rt,ct),s=s+Math.imul(it,st)|0,h=Math.imul(it,ct),p=p+Math.imul(ot,lt)|0,s=s+Math.imul(ot,ut)|0,s=s+Math.imul(at,lt)|0,h=h+Math.imul(at,ut)|0,p=p+Math.imul(et,dt)|0,s=s+Math.imul(et,mt)|0,s=s+Math.imul(nt,dt)|0,h=h+Math.imul(nt,mt)|0,p=p+Math.imul(Z,pt)|0,s=s+Math.imul(Z,ft)|0,s=s+Math.imul(tt,pt)|0,h=h+Math.imul(tt,ft)|0,p=p+Math.imul(X,ht)|0,s=s+Math.imul(X,bt)|0,s=s+Math.imul(Y,ht)|0,h=h+Math.imul(Y,bt)|0,p=p+Math.imul(Q,gt)|0,s=s+Math.imul(Q,yt)|0,s=s+Math.imul(J,gt)|0,h=h+Math.imul(J,yt)|0,p=p+Math.imul(G,Tt)|0,s=s+Math.imul(G,wt)|0,s=s+Math.imul(z,Tt)|0,h=h+Math.imul(z,wt)|0,p=p+Math.imul(q,St)|0,s=s+Math.imul(q,Ct)|0,s=s+Math.imul(F,St)|0,h=h+Math.imul(F,Ct)|0,p=p+Math.imul(W,It)|0,s=s+Math.imul(W,xt)|0,s=s+Math.imul(U,It)|0,h=h+Math.imul(U,xt)|0,p=p+Math.imul(A,kt)|0,s=s+Math.imul(A,vt)|0,s=s+Math.imul(M,kt)|0,h=h+Math.imul(M,vt)|0;var Ti=(w+p|0)+((s&8191)<<13)|0;w=(h+(s>>>13)|0)+(Ti>>>26)|0,Ti&=67108863,p=Math.imul(rt,lt),s=Math.imul(rt,ut),s=s+Math.imul(it,lt)|0,h=Math.imul(it,ut),p=p+Math.imul(ot,dt)|0,s=s+Math.imul(ot,mt)|0,s=s+Math.imul(at,dt)|0,h=h+Math.imul(at,mt)|0,p=p+Math.imul(et,pt)|0,s=s+Math.imul(et,ft)|0,s=s+Math.imul(nt,pt)|0,h=h+Math.imul(nt,ft)|0,p=p+Math.imul(Z,ht)|0,s=s+Math.imul(Z,bt)|0,s=s+Math.imul(tt,ht)|0,h=h+Math.imul(tt,bt)|0,p=p+Math.imul(X,gt)|0,s=s+Math.imul(X,yt)|0,s=s+Math.imul(Y,gt)|0,h=h+Math.imul(Y,yt)|0,p=p+Math.imul(Q,Tt)|0,s=s+Math.imul(Q,wt)|0,s=s+Math.imul(J,Tt)|0,h=h+Math.imul(J,wt)|0,p=p+Math.imul(G,St)|0,s=s+Math.imul(G,Ct)|0,s=s+Math.imul(z,St)|0,h=h+Math.imul(z,Ct)|0,p=p+Math.imul(q,It)|0,s=s+Math.imul(q,xt)|0,s=s+Math.imul(F,It)|0,h=h+Math.imul(F,xt)|0,p=p+Math.imul(W,kt)|0,s=s+Math.imul(W,vt)|0,s=s+Math.imul(U,kt)|0,h=h+Math.imul(U,vt)|0;var wi=(w+p|0)+((s&8191)<<13)|0;w=(h+(s>>>13)|0)+(wi>>>26)|0,wi&=67108863,p=Math.imul(rt,dt),s=Math.imul(rt,mt),s=s+Math.imul(it,dt)|0,h=Math.imul(it,mt),p=p+Math.imul(ot,pt)|0,s=s+Math.imul(ot,ft)|0,s=s+Math.imul(at,pt)|0,h=h+Math.imul(at,ft)|0,p=p+Math.imul(et,ht)|0,s=s+Math.imul(et,bt)|0,s=s+Math.imul(nt,ht)|0,h=h+Math.imul(nt,bt)|0,p=p+Math.imul(Z,gt)|0,s=s+Math.imul(Z,yt)|0,s=s+Math.imul(tt,gt)|0,h=h+Math.imul(tt,yt)|0,p=p+Math.imul(X,Tt)|0,s=s+Math.imul(X,wt)|0,s=s+Math.imul(Y,Tt)|0,h=h+Math.imul(Y,wt)|0,p=p+Math.imul(Q,St)|0,s=s+Math.imul(Q,Ct)|0,s=s+Math.imul(J,St)|0,h=h+Math.imul(J,Ct)|0,p=p+Math.imul(G,It)|0,s=s+Math.imul(G,xt)|0,s=s+Math.imul(z,It)|0,h=h+Math.imul(z,xt)|0,p=p+Math.imul(q,kt)|0,s=s+Math.imul(q,vt)|0,s=s+Math.imul(F,kt)|0,h=h+Math.imul(F,vt)|0;var Si=(w+p|0)+((s&8191)<<13)|0;w=(h+(s>>>13)|0)+(Si>>>26)|0,Si&=67108863,p=Math.imul(rt,pt),s=Math.imul(rt,ft),s=s+Math.imul(it,pt)|0,h=Math.imul(it,ft),p=p+Math.imul(ot,ht)|0,s=s+Math.imul(ot,bt)|0,s=s+Math.imul(at,ht)|0,h=h+Math.imul(at,bt)|0,p=p+Math.imul(et,gt)|0,s=s+Math.imul(et,yt)|0,s=s+Math.imul(nt,gt)|0,h=h+Math.imul(nt,yt)|0,p=p+Math.imul(Z,Tt)|0,s=s+Math.imul(Z,wt)|0,s=s+Math.imul(tt,Tt)|0,h=h+Math.imul(tt,wt)|0,p=p+Math.imul(X,St)|0,s=s+Math.imul(X,Ct)|0,s=s+Math.imul(Y,St)|0,h=h+Math.imul(Y,Ct)|0,p=p+Math.imul(Q,It)|0,s=s+Math.imul(Q,xt)|0,s=s+Math.imul(J,It)|0,h=h+Math.imul(J,xt)|0,p=p+Math.imul(G,kt)|0,s=s+Math.imul(G,vt)|0,s=s+Math.imul(z,kt)|0,h=h+Math.imul(z,vt)|0;var Ci=(w+p|0)+((s&8191)<<13)|0;w=(h+(s>>>13)|0)+(Ci>>>26)|0,Ci&=67108863,p=Math.imul(rt,ht),s=Math.imul(rt,bt),s=s+Math.imul(it,ht)|0,h=Math.imul(it,bt),p=p+Math.imul(ot,gt)|0,s=s+Math.imul(ot,yt)|0,s=s+Math.imul(at,gt)|0,h=h+Math.imul(at,yt)|0,p=p+Math.imul(et,Tt)|0,s=s+Math.imul(et,wt)|0,s=s+Math.imul(nt,Tt)|0,h=h+Math.imul(nt,wt)|0,p=p+Math.imul(Z,St)|0,s=s+Math.imul(Z,Ct)|0,s=s+Math.imul(tt,St)|0,h=h+Math.imul(tt,Ct)|0,p=p+Math.imul(X,It)|0,s=s+Math.imul(X,xt)|0,s=s+Math.imul(Y,It)|0,h=h+Math.imul(Y,xt)|0,p=p+Math.imul(Q,kt)|0,s=s+Math.imul(Q,vt)|0,s=s+Math.imul(J,kt)|0,h=h+Math.imul(J,vt)|0;var Ii=(w+p|0)+((s&8191)<<13)|0;w=(h+(s>>>13)|0)+(Ii>>>26)|0,Ii&=67108863,p=Math.imul(rt,gt),s=Math.imul(rt,yt),s=s+Math.imul(it,gt)|0,h=Math.imul(it,yt),p=p+Math.imul(ot,Tt)|0,s=s+Math.imul(ot,wt)|0,s=s+Math.imul(at,Tt)|0,h=h+Math.imul(at,wt)|0,p=p+Math.imul(et,St)|0,s=s+Math.imul(et,Ct)|0,s=s+Math.imul(nt,St)|0,h=h+Math.imul(nt,Ct)|0,p=p+Math.imul(Z,It)|0,s=s+Math.imul(Z,xt)|0,s=s+Math.imul(tt,It)|0,h=h+Math.imul(tt,xt)|0,p=p+Math.imul(X,kt)|0,s=s+Math.imul(X,vt)|0,s=s+Math.imul(Y,kt)|0,h=h+Math.imul(Y,vt)|0;var xi=(w+p|0)+((s&8191)<<13)|0;w=(h+(s>>>13)|0)+(xi>>>26)|0,xi&=67108863,p=Math.imul(rt,Tt),s=Math.imul(rt,wt),s=s+Math.imul(it,Tt)|0,h=Math.imul(it,wt),p=p+Math.imul(ot,St)|0,s=s+Math.imul(ot,Ct)|0,s=s+Math.imul(at,St)|0,h=h+Math.imul(at,Ct)|0,p=p+Math.imul(et,It)|0,s=s+Math.imul(et,xt)|0,s=s+Math.imul(nt,It)|0,h=h+Math.imul(nt,xt)|0,p=p+Math.imul(Z,kt)|0,s=s+Math.imul(Z,vt)|0,s=s+Math.imul(tt,kt)|0,h=h+Math.imul(tt,vt)|0;var ki=(w+p|0)+((s&8191)<<13)|0;w=(h+(s>>>13)|0)+(ki>>>26)|0,ki&=67108863,p=Math.imul(rt,St),s=Math.imul(rt,Ct),s=s+Math.imul(it,St)|0,h=Math.imul(it,Ct),p=p+Math.imul(ot,It)|0,s=s+Math.imul(ot,xt)|0,s=s+Math.imul(at,It)|0,h=h+Math.imul(at,xt)|0,p=p+Math.imul(et,kt)|0,s=s+Math.imul(et,vt)|0,s=s+Math.imul(nt,kt)|0,h=h+Math.imul(nt,vt)|0;var vi=(w+p|0)+((s&8191)<<13)|0;w=(h+(s>>>13)|0)+(vi>>>26)|0,vi&=67108863,p=Math.imul(rt,It),s=Math.imul(rt,xt),s=s+Math.imul(it,It)|0,h=Math.imul(it,xt),p=p+Math.imul(ot,kt)|0,s=s+Math.imul(ot,vt)|0,s=s+Math.imul(at,kt)|0,h=h+Math.imul(at,vt)|0;var Di=(w+p|0)+((s&8191)<<13)|0;w=(h+(s>>>13)|0)+(Di>>>26)|0,Di&=67108863,p=Math.imul(rt,kt),s=Math.imul(rt,vt),s=s+Math.imul(it,kt)|0,h=Math.imul(it,vt);var Ai=(w+p|0)+((s&8191)<<13)|0;return w=(h+(s>>>13)|0)+(Ai>>>26)|0,Ai&=67108863,y[0]=ui,y[1]=di,y[2]=mi,y[3]=pi,y[4]=fi,y[5]=hi,y[6]=bi,y[7]=gi,y[8]=yi,y[9]=Ti,y[10]=wi,y[11]=Si,y[12]=Ci,y[13]=Ii,y[14]=xi,y[15]=ki,y[16]=vi,y[17]=Di,y[18]=Ai,w!==0&&(y[19]=w,d.length++),d};Math.imul||($=L);function Wt(g,r,c){c.negative=r.negative^g.negative,c.length=g.length+r.length;for(var d=0,m=0,f=0;f<c.length-1;f++){var y=m;m=0;for(var w=d&67108863,p=Math.min(f,r.length-1),s=Math.max(0,f-g.length+1);s<=p;s++){var h=f-s,D=g.words[h]|0,A=r.words[s]|0,M=D*A,_=M&67108863;y=y+(M/67108864|0)|0,_=_+w|0,w=_&67108863,y=y+(_>>>26)|0,m+=y>>>26,y&=67108863}c.words[f]=w,d=y,y=m}return d!==0?c.words[f]=d:c.length--,c._strip()}function Bt(g,r,c){return Wt(g,r,c)}o.prototype.mulTo=function(r,c){var d,m=this.length+r.length;return this.length===10&&r.length===10?d=$(this,r,c):m<63?d=L(this,r,c):m<1024?d=Wt(this,r,c):d=Bt(this,r,c),d};function _t(g,r){this.x=g,this.y=r}_t.prototype.makeRBT=function(r){for(var c=new Array(r),d=o.prototype._countBits(r)-1,m=0;m<r;m++)c[m]=this.revBin(m,d,r);return c},_t.prototype.revBin=function(r,c,d){if(r===0||r===d-1)return r;for(var m=0,f=0;f<c;f++)m|=(r&1)<<c-f-1,r>>=1;return m},_t.prototype.permute=function(r,c,d,m,f,y){for(var w=0;w<y;w++)m[w]=c[r[w]],f[w]=d[r[w]]},_t.prototype.transform=function(r,c,d,m,f,y){this.permute(y,r,c,d,m,f);for(var w=1;w<f;w<<=1)for(var p=w<<1,s=Math.cos(2*Math.PI/p),h=Math.sin(2*Math.PI/p),D=0;D<f;D+=p)for(var A=s,M=h,_=0;_<w;_++){var W=d[D+_],U=m[D+_],ie=d[D+_+w],q=m[D+_+w],F=A*ie-M*q;q=A*q+M*ie,ie=F,d[D+_]=W+ie,m[D+_]=U+q,d[D+_+w]=W-ie,m[D+_+w]=U-q,_!==p&&(F=s*A-h*M,M=s*M+h*A,A=F)}},_t.prototype.guessLen13b=function(r,c){var d=Math.max(c,r)|1,m=d&1,f=0;for(d=d/2|0;d;d=d>>>1)f++;return 1<<f+1+m},_t.prototype.conjugate=function(r,c,d){if(!(d<=1))for(var m=0;m<d/2;m++){var f=r[m];r[m]=r[d-m-1],r[d-m-1]=f,f=c[m],c[m]=-c[d-m-1],c[d-m-1]=-f}},_t.prototype.normalize13b=function(r,c){for(var d=0,m=0;m<c/2;m++){var f=Math.round(r[2*m+1]/c)*8192+Math.round(r[2*m]/c)+d;r[m]=f&67108863,f<67108864?d=0:d=f/67108864|0}return r},_t.prototype.convert13b=function(r,c,d,m){for(var f=0,y=0;y<c;y++)f=f+(r[y]|0),d[2*y]=f&8191,f=f>>>13,d[2*y+1]=f&8191,f=f>>>13;for(y=2*c;y<m;++y)d[y]=0;t(f===0),t((f&-8192)===0)},_t.prototype.stub=function(r){for(var c=new Array(r),d=0;d<r;d++)c[d]=0;return c},_t.prototype.mulp=function(r,c,d){var m=2*this.guessLen13b(r.length,c.length),f=this.makeRBT(m),y=this.stub(m),w=new Array(m),p=new Array(m),s=new Array(m),h=new Array(m),D=new Array(m),A=new Array(m),M=d.words;M.length=m,this.convert13b(r.words,r.length,w,m),this.convert13b(c.words,c.length,h,m),this.transform(w,y,p,s,m,f),this.transform(h,y,D,A,m,f);for(var _=0;_<m;_++){var W=p[_]*D[_]-s[_]*A[_];s[_]=p[_]*A[_]+s[_]*D[_],p[_]=W}return this.conjugate(p,s,m),this.transform(p,s,M,y,m,f),this.conjugate(M,y,m),this.normalize13b(M,m),d.negative=r.negative^c.negative,d.length=r.length+c.length,d._strip()},o.prototype.mul=function(r){var c=new o(null);return c.words=new Array(this.length+r.length),this.mulTo(r,c)},o.prototype.mulf=function(r){var c=new o(null);return c.words=new Array(this.length+r.length),Bt(this,r,c)},o.prototype.imul=function(r){return this.clone().mulTo(r,this)},o.prototype.imuln=function(r){var c=r<0;c&&(r=-r),t(typeof r=="number"),t(r<67108864);for(var d=0,m=0;m<this.length;m++){var f=(this.words[m]|0)*r,y=(f&67108863)+(d&67108863);d>>=26,d+=f/67108864|0,d+=y>>>26,this.words[m]=y&67108863}return d!==0&&(this.words[m]=d,this.length++),c?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 c=O(r);if(c.length===0)return new o(1);for(var d=this,m=0;m<c.length&&c[m]===0;m++,d=d.sqr());if(++m<c.length)for(var f=d.sqr();m<c.length;m++,f=f.sqr())c[m]!==0&&(d=d.mul(f));return d},o.prototype.iushln=function(r){t(typeof r=="number"&&r>=0);var c=r%26,d=(r-c)/26,m=67108863>>>26-c<<26-c,f;if(c!==0){var y=0;for(f=0;f<this.length;f++){var w=this.words[f]&m,p=(this.words[f]|0)-w<<c;this.words[f]=p|y,y=w>>>26-c}y&&(this.words[f]=y,this.length++)}if(d!==0){for(f=this.length-1;f>=0;f--)this.words[f+d]=this.words[f];for(f=0;f<d;f++)this.words[f]=0;this.length+=d}return this._strip()},o.prototype.ishln=function(r){return t(this.negative===0),this.iushln(r)},o.prototype.iushrn=function(r,c,d){t(typeof r=="number"&&r>=0);var m;c?m=(c-c%26)/26:m=0;var f=r%26,y=Math.min((r-f)/26,this.length),w=67108863^67108863>>>f<<f,p=d;if(m-=y,m=Math.max(0,m),p){for(var s=0;s<y;s++)p.words[s]=this.words[s];p.length=y}if(y!==0)if(this.length>y)for(this.length-=y,s=0;s<this.length;s++)this.words[s]=this.words[s+y];else this.words[0]=0,this.length=1;var h=0;for(s=this.length-1;s>=0&&(h!==0||s>=m);s--){var D=this.words[s]|0;this.words[s]=h<<26-f|D>>>f,h=D&w}return p&&h!==0&&(p.words[p.length++]=h),this.length===0&&(this.words[0]=0,this.length=1),this._strip()},o.prototype.ishrn=function(r,c,d){return t(this.negative===0),this.iushrn(r,c,d)},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 c=r%26,d=(r-c)/26,m=1<<c;if(this.length<=d)return!1;var f=this.words[d];return!!(f&m)},o.prototype.imaskn=function(r){t(typeof r=="number"&&r>=0);var c=r%26,d=(r-c)/26;if(t(this.negative===0,"imaskn works only with positive numbers"),this.length<=d)return this;if(c!==0&&d++,this.length=Math.min(d,this.length),c!==0){var m=67108863^67108863>>>c<<c;this.words[this.length-1]&=m}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 c=0;c<this.length&&this.words[c]>=67108864;c++)this.words[c]-=67108864,c===this.length-1?this.words[c+1]=1:this.words[c+1]++;return this.length=Math.max(this.length,c+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 c=0;c<this.length&&this.words[c]<0;c++)this.words[c]+=67108864,this.words[c+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,c,d){var m=r.length+d,f;this._expand(m);var y,w=0;for(f=0;f<r.length;f++){y=(this.words[f+d]|0)+w;var p=(r.words[f]|0)*c;y-=p&67108863,w=(y>>26)-(p/67108864|0),this.words[f+d]=y&67108863}for(;f<this.length-d;f++)y=(this.words[f+d]|0)+w,w=y>>26,this.words[f+d]=y&67108863;if(w===0)return this._strip();for(t(w===-1),w=0,f=0;f<this.length;f++)y=-(this.words[f]|0)+w,w=y>>26,this.words[f]=y&67108863;return this.negative=1,this._strip()},o.prototype._wordDiv=function(r,c){var d=this.length-r.length,m=this.clone(),f=r,y=f.words[f.length-1]|0,w=this._countBits(y);d=26-w,d!==0&&(f=f.ushln(d),m.iushln(d),y=f.words[f.length-1]|0);var p=m.length-f.length,s;if(c!=="mod"){s=new o(null),s.length=p+1,s.words=new Array(s.length);for(var h=0;h<s.length;h++)s.words[h]=0}var D=m.clone()._ishlnsubmul(f,1,p);D.negative===0&&(m=D,s&&(s.words[p]=1));for(var A=p-1;A>=0;A--){var M=(m.words[f.length+A]|0)*67108864+(m.words[f.length+A-1]|0);for(M=Math.min(M/y|0,67108863),m._ishlnsubmul(f,M,A);m.negative!==0;)M--,m.negative=0,m._ishlnsubmul(f,1,A),m.isZero()||(m.negative^=1);s&&(s.words[A]=M)}return s&&s._strip(),m._strip(),c!=="div"&&d!==0&&m.iushrn(d),{div:s||null,mod:m}},o.prototype.divmod=function(r,c,d){if(t(!r.isZero()),this.isZero())return{div:new o(0),mod:new o(0)};var m,f,y;return this.negative!==0&&r.negative===0?(y=this.neg().divmod(r,c),c!=="mod"&&(m=y.div.neg()),c!=="div"&&(f=y.mod.neg(),d&&f.negative!==0&&f.iadd(r)),{div:m,mod:f}):this.negative===0&&r.negative!==0?(y=this.divmod(r.neg(),c),c!=="mod"&&(m=y.div.neg()),{div:m,mod:y.mod}):this.negative&r.negative?(y=this.neg().divmod(r.neg(),c),c!=="div"&&(f=y.mod.neg(),d&&f.negative!==0&&f.isub(r)),{div:y.div,mod:f}):r.length>this.length||this.cmp(r)<0?{div:new o(0),mod:this}:r.length===1?c==="div"?{div:this.divn(r.words[0]),mod:null}:c==="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,c)},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 c=this.divmod(r);if(c.mod.isZero())return c.div;var d=c.div.negative!==0?c.mod.isub(r):c.mod,m=r.ushrn(1),f=r.andln(1),y=d.cmp(m);return y<0||f===1&&y===0?c.div:c.div.negative!==0?c.div.isubn(1):c.div.iaddn(1)},o.prototype.modrn=function(r){var c=r<0;c&&(r=-r),t(r<=67108863);for(var d=(1<<26)%r,m=0,f=this.length-1;f>=0;f--)m=(d*m+(this.words[f]|0))%r;return c?-m:m},o.prototype.modn=function(r){return this.modrn(r)},o.prototype.idivn=function(r){var c=r<0;c&&(r=-r),t(r<=67108863);for(var d=0,m=this.length-1;m>=0;m--){var f=(this.words[m]|0)+d*67108864;this.words[m]=f/r|0,d=f%r}return this._strip(),c?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 c=this,d=r.clone();c.negative!==0?c=c.umod(r):c=c.clone();for(var m=new o(1),f=new o(0),y=new o(0),w=new o(1),p=0;c.isEven()&&d.isEven();)c.iushrn(1),d.iushrn(1),++p;for(var s=d.clone(),h=c.clone();!c.isZero();){for(var D=0,A=1;!(c.words[0]&A)&&D<26;++D,A<<=1);if(D>0)for(c.iushrn(D);D-- >0;)(m.isOdd()||f.isOdd())&&(m.iadd(s),f.isub(h)),m.iushrn(1),f.iushrn(1);for(var M=0,_=1;!(d.words[0]&_)&&M<26;++M,_<<=1);if(M>0)for(d.iushrn(M);M-- >0;)(y.isOdd()||w.isOdd())&&(y.iadd(s),w.isub(h)),y.iushrn(1),w.iushrn(1);c.cmp(d)>=0?(c.isub(d),m.isub(y),f.isub(w)):(d.isub(c),y.isub(m),w.isub(f))}return{a:y,b:w,gcd:d.iushln(p)}},o.prototype._invmp=function(r){t(r.negative===0),t(!r.isZero());var c=this,d=r.clone();c.negative!==0?c=c.umod(r):c=c.clone();for(var m=new o(1),f=new o(0),y=d.clone();c.cmpn(1)>0&&d.cmpn(1)>0;){for(var w=0,p=1;!(c.words[0]&p)&&w<26;++w,p<<=1);if(w>0)for(c.iushrn(w);w-- >0;)m.isOdd()&&m.iadd(y),m.iushrn(1);for(var s=0,h=1;!(d.words[0]&h)&&s<26;++s,h<<=1);if(s>0)for(d.iushrn(s);s-- >0;)f.isOdd()&&f.iadd(y),f.iushrn(1);c.cmp(d)>=0?(c.isub(d),m.isub(f)):(d.isub(c),f.isub(m))}var D;return c.cmpn(1)===0?D=m:D=f,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 c=this.clone(),d=r.clone();c.negative=0,d.negative=0;for(var m=0;c.isEven()&&d.isEven();m++)c.iushrn(1),d.iushrn(1);do{for(;c.isEven();)c.iushrn(1);for(;d.isEven();)d.iushrn(1);var f=c.cmp(d);if(f<0){var y=c;c=d,d=y}else if(f===0||d.cmpn(1)===0)break;c.isub(d)}while(!0);return d.iushln(m)},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 c=r%26,d=(r-c)/26,m=1<<c;if(this.length<=d)return this._expand(d+1),this.words[d]|=m,this;for(var f=m,y=d;f!==0&&y<this.length;y++){var w=this.words[y]|0;w+=f,f=w>>>26,w&=67108863,this.words[y]=w}return f!==0&&(this.words[y]=f,this.length++),this},o.prototype.isZero=function(){return this.length===1&&this.words[0]===0},o.prototype.cmpn=function(r){var c=r<0;if(this.negative!==0&&!c)return-1;if(this.negative===0&&c)return 1;this._strip();var d;if(this.length>1)d=1;else{c&&(r=-r),t(r<=67108863,"Number is too big");var m=this.words[0]|0;d=m===r?0:m<r?-1:1}return this.negative!==0?-d|0:d},o.prototype.cmp=function(r){if(this.negative!==0&&r.negative===0)return-1;if(this.negative===0&&r.negative!==0)return 1;var c=this.ucmp(r);return this.negative!==0?-c|0:c},o.prototype.ucmp=function(r){if(this.length>r.length)return 1;if(this.length<r.length)return-1;for(var c=0,d=this.length-1;d>=0;d--){var m=this.words[d]|0,f=r.words[d]|0;if(m!==f){m<f?c=-1:m>f&&(c=1);break}}return c},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 V(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 ci={k256:null,p224:null,p192:null,p25519:null};function jt(g,r){this.name=g,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()}jt.prototype._tmp=function(){var r=new o(null);return r.words=new Array(Math.ceil(this.n/13)),r},jt.prototype.ireduce=function(r){var c=r,d;do this.split(c,this.tmp),c=this.imulK(c),c=c.iadd(this.tmp),d=c.bitLength();while(d>this.n);var m=d<this.n?-1:c.ucmp(this.p);return m===0?(c.words[0]=0,c.length=1):m>0?c.isub(this.p):c.strip!==void 0?c.strip():c._strip(),c},jt.prototype.split=function(r,c){r.iushrn(this.n,0,c)},jt.prototype.imulK=function(r){return r.imul(this.k)};function jn(){jt.call(this,"k256","ffffffff ffffffff ffffffff ffffffff ffffffff ffffffff fffffffe fffffc2f")}n(jn,jt),jn.prototype.split=function(r,c){for(var d=4194303,m=Math.min(r.length,9),f=0;f<m;f++)c.words[f]=r.words[f];if(c.length=m,r.length<=9){r.words[0]=0,r.length=1;return}var y=r.words[9];for(c.words[c.length++]=y&d,f=10;f<r.length;f++){var w=r.words[f]|0;r.words[f-10]=(w&d)<<4|y>>>22,y=w}y>>>=22,r.words[f-10]=y,y===0&&r.length>10?r.length-=10:r.length-=9},jn.prototype.imulK=function(r){r.words[r.length]=0,r.words[r.length+1]=0,r.length+=2;for(var c=0,d=0;d<r.length;d++){var m=r.words[d]|0;c+=m*977,r.words[d]=c&67108863,c=m*64+(c/67108864|0)}return r.words[r.length-1]===0&&(r.length--,r.words[r.length-1]===0&&r.length--),r};function xs(){jt.call(this,"p224","ffffffff ffffffff ffffffff ffffffff 00000000 00000000 00000001")}n(xs,jt);function ks(){jt.call(this,"p192","ffffffff ffffffff ffffffff fffffffe ffffffff ffffffff")}n(ks,jt);function li(){jt.call(this,"25519","7fffffffffffffff ffffffffffffffff ffffffffffffffff ffffffffffffffed")}n(li,jt),li.prototype.imulK=function(r){for(var c=0,d=0;d<r.length;d++){var m=(r.words[d]|0)*19+c,f=m&67108863;m>>>=26,r.words[d]=f,c=m}return c!==0&&(r.words[r.length++]=c),r},o._prime=function(r){if(ci[r])return ci[r];var c;if(r==="k256")c=new jn;else if(r==="p224")c=new xs;else if(r==="p192")c=new ks;else if(r==="p25519")c=new li;else throw new Error("Unknown prime "+r);return ci[r]=c,c};function V(g){if(typeof g=="string"){var r=o._prime(g);this.m=r.p,this.prime=r}else t(g.gtn(1),"modulus must be greater than 1"),this.m=g,this.prime=null}V.prototype._verify1=function(r){t(r.negative===0,"red works only with positives"),t(r.red,"red works only with red numbers")},V.prototype._verify2=function(r,c){t((r.negative|c.negative)===0,"red works only with positives"),t(r.red&&r.red===c.red,"red works only with red numbers")},V.prototype.imod=function(r){return this.prime?this.prime.ireduce(r)._forceRed(this):(T(r,r.umod(this.m)._forceRed(this)),r)},V.prototype.neg=function(r){return r.isZero()?r.clone():this.m.sub(r)._forceRed(this)},V.prototype.add=function(r,c){this._verify2(r,c);var d=r.add(c);return d.cmp(this.m)>=0&&d.isub(this.m),d._forceRed(this)},V.prototype.iadd=function(r,c){this._verify2(r,c);var d=r.iadd(c);return d.cmp(this.m)>=0&&d.isub(this.m),d},V.prototype.sub=function(r,c){this._verify2(r,c);var d=r.sub(c);return d.cmpn(0)<0&&d.iadd(this.m),d._forceRed(this)},V.prototype.isub=function(r,c){this._verify2(r,c);var d=r.isub(c);return d.cmpn(0)<0&&d.iadd(this.m),d},V.prototype.shl=function(r,c){return this._verify1(r),this.imod(r.ushln(c))},V.prototype.imul=function(r,c){return this._verify2(r,c),this.imod(r.imul(c))},V.prototype.mul=function(r,c){return this._verify2(r,c),this.imod(r.mul(c))},V.prototype.isqr=function(r){return this.imul(r,r.clone())},V.prototype.sqr=function(r){return this.mul(r,r)},V.prototype.sqrt=function(r){if(r.isZero())return r.clone();var c=this.m.andln(3);if(t(c%2===1),c===3){var d=this.m.add(new o(1)).iushrn(2);return this.pow(r,d)}for(var m=this.m.subn(1),f=0;!m.isZero()&&m.andln(1)===0;)f++,m.iushrn(1);t(!m.isZero());var y=new o(1).toRed(this),w=y.redNeg(),p=this.m.subn(1).iushrn(1),s=this.m.bitLength();for(s=new o(2*s*s).toRed(this);this.pow(s,p).cmp(w)!==0;)s.redIAdd(w);for(var h=this.pow(s,m),D=this.pow(r,m.addn(1).iushrn(1)),A=this.pow(r,m),M=f;A.cmp(y)!==0;){for(var _=A,W=0;_.cmp(y)!==0;W++)_=_.redSqr();t(W<M);var U=this.pow(h,new o(1).iushln(M-W-1));D=D.redMul(U),h=U.redSqr(),A=A.redMul(h),M=W}return D},V.prototype.invm=function(r){var c=r._invmp(this.m);return c.negative!==0?(c.negative=0,this.imod(c).redNeg()):this.imod(c)},V.prototype.pow=function(r,c){if(c.isZero())return new o(1).toRed(this);if(c.cmpn(1)===0)return r.clone();var d=4,m=new Array(1<<d);m[0]=new o(1).toRed(this),m[1]=r;for(var f=2;f<m.length;f++)m[f]=this.mul(m[f-1],r);var y=m[0],w=0,p=0,s=c.bitLength()%26;for(s===0&&(s=26),f=c.length-1;f>=0;f--){for(var h=c.words[f],D=s-1;D>=0;D--){var A=h>>D&1;if(y!==m[0]&&(y=this.sqr(y)),A===0&&w===0){p=0;continue}w<<=1,w|=A,p++,!(p!==d&&(f!==0||D!==0))&&(y=this.mul(y,m[w]),p=0,w=0)}s=26}return y},V.prototype.convertTo=function(r){var c=r.umod(this.m);return c===r?c.clone():c},V.prototype.convertFrom=function(r){var c=r.clone();return c.red=null,c},o.mont=function(r){return new Oe(r)};function Oe(g){V.call(this,g),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(Oe,V),Oe.prototype.convertTo=function(r){return this.imod(r.ushln(this.shift))},Oe.prototype.convertFrom=function(r){var c=this.imod(r.mul(this.rinv));return c.red=null,c},Oe.prototype.imul=function(r,c){if(r.isZero()||c.isZero())return r.words[0]=0,r.length=1,r;var d=r.imul(c),m=d.maskn(this.shift).mul(this.minv).imaskn(this.shift).mul(this.m),f=d.isub(m).iushrn(this.shift),y=f;return f.cmp(this.m)>=0?y=f.isub(this.m):f.cmpn(0)<0&&(y=f.iadd(this.m)),y._forceRed(this)},Oe.prototype.mul=function(r,c){if(r.isZero()||c.isZero())return new o(0)._forceRed(this);var d=r.mul(c),m=d.maskn(this.shift).mul(this.minv).imaskn(this.shift).mul(this.m),f=d.isub(m).iushrn(this.shift),y=f;return f.cmp(this.m)>=0?y=f.isub(this.m):f.cmpn(0)<0&&(y=f.iadd(this.m)),y._forceRed(this)},Oe.prototype.invm=function(r){var c=this.imod(r._invmp(this.m).mul(this.r2));return c._forceRed(this)}})(typeof Is>"u"||Is,Nd)});var yp={};Mi(yp,{appHelpers:()=>gp});module.exports=cm(yp);var Js=require("@msafe/sui3-utils");var ne=require("@alphafi/alphafi-sdk"),We=require("@msafe/sui3-utils"),Jt=require("@mysten/bcs");var qn=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=Jt.bcs.u64().parse((0,Jt.fromBase64)(t)):t.length===24?n=Jt.bcs.u128().parse((0,Jt.fromBase64)(t)):t.length===44?n=Jt.bcs.u256().parse((0,Jt.fromBase64)(t)):n=Jt.bcs.u64().parse((0,Jt.fromBase64)(t)),n}decodeDoubleAssetDeposit(e,t){let{amount_a:n,amount_b:o}=t,i=Number(n)>0;return console.log("Decoder.decodeDoubleAssetDeposit",n,o,i),{txType:We.TransactionType.Other,type:"depositDoubleAsset",intentionData:{poolName:e,amount:i?n:o,isAmountA:i}}}decodeSingleAssetDeposit(e,t){let{amount:n}=t;if(console.log("Decoder.decodeSingleAssetDeposit",n),this.getLiquidityChangeEvent().type.includes(":alphafi_navi_pool:")){let{coin:i}=ne.singleAssetPoolCoinMap[e],{expo:l}=ne.coinsList[i];n=Math.floor(Number(n)/10**(9-l)).toString()}return{txType:We.TransactionType.Other,type:"depositSingleAsset",intentionData:{poolName:e,amount:n}}}decodeWithdraw(e){let t=this.extractXTokensAmount();return console.log("Decoder.decodeWithdraw",t),{txType:We.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:We.TransactionType.Other,type:"withdrawAlpha",intentionData:{withdrawFromLocked:Number(n)>0,xTokensAmount:t}}}decodeClaimReward(){return{txType:We.TransactionType.Other,type:"claimReward",intentionData:{}}}};var Vs=require("@alphafi/alphafi-sdk");var $s=Ut(require("sort-keys-recursive")),k=class{constructor(e){this.data=e}serialize(){return JSON.stringify((0,$s.default)(this.data))}};var Fn=class a extends k{constructor(t){super(t);this.data=t}txType;txSubType;async build(t){let{account:n}=t;return await(0,Vs.claimRewardTxb)(n.address)}static fromData(t){return new a(t)}};var Hs=require("@alphafi/alphafi-sdk");var Kn=class a extends k{constructor(t){super(t);this.data=t}txType;txSubType;async build(t){let{account:n}=t,{poolName:o,amount:i,isAmountA:l}=this.data;return await(0,Hs.depositDoubleAssetTxb)(o,n.address,i,l)}static fromData(t){return console.log("DepositDoubleAssetIntention.fromData",t),new a(t)}};var Gs=require("@alphafi/alphafi-sdk");var $n=class a extends k{constructor(t){super(t);this.data=t}txType;txSubType;async build(t){let{account:n}=t,{poolName:o,amount:i}=this.data;return await(0,Gs.depositSingleAssetTxb)(o,n.address,i)}static fromData(t){return console.log("DepositSingleAssetIntention.fromData",t),new a(t)}};var zs=require("@alphafi/alphafi-sdk");var Vn=class a extends k{constructor(t){super(t);this.data=t}txType;txSubType;async build(t){let{account:n}=t,{poolName:o,xTokensAmount:i}=this.data;return await(0,zs.withdrawTxb)(i,o,n.address)}static fromData(t){return console.log("WithdrawIntention.fromData",t),new a(t)}};var Qs=require("@alphafi/alphafi-sdk");var Hn=class a extends k{constructor(t){super(t);this.data=t}txType;txSubType;async build(t){let{account:n}=t,{withdrawFromLocked:o,xTokensAmount:i}=this.data;return await(0,Qs.withdrawAlphaTxb)(i,o,n.address)}static fromData(t){return console.log("WithdrawAlphaIntention.fromData",t),new a(t)}};var Gn=class{application="alphafi";supportSDK="@mysten/sui";async deserialize(e){let{transaction:t,suiClient:n,account:o}=e,i=await n.devInspectTransactionBlock({sender:t.getData().sender,transactionBlock:t});console.log("AlphaFiHelper Sim result - ",i);let u=new qn(t,i).decode();return{txType:Js.TransactionType.Other,txSubType:u.type,intentionData:u.intentionData}}async build(e){let{account:t}=e;console.log("AlphaFi build transaction type",e.txSubType);let n;switch(e.txSubType){case"depositSingleAsset":n=$n.fromData(e.intentionData);break;case"depositDoubleAsset":n=Kn.fromData(e.intentionData);break;case"withdraw":n=Vn.fromData(e.intentionData);break;case"withdrawAlpha":n=Hn.fromData(e.intentionData);break;case"claimReward":n=Fn.fromData(e.intentionData);break;default:throw new Error("not implemented")}return n.build({account:t})}};var Sc=require("@msafe/sui3-utils");var Et=require("@msafe/sui3-utils"),zn=require("@mysten/sui/bcs"),Qn=require("bucket-protocol-sdk");var Jn=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(Qn.SBUCK_FOUNTAIN_PACKAGE_ID,"fountain_core","stake")}isSBUCKUnstakeTransaction(){return!!this.getMoveCallPackageModuleCommand(Qn.SBUCK_FOUNTAIN_PACKAGE_ID,"fountain_core","force_unstake")}isSBUCKClaimTransaction(){return!!this.getMoveCallPackageModuleCommand(Qn.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:Et.TransactionType.Other,type:"psm",intentionData:{coinType:e,amount:n,buckToCoin:t}}}decodeBorrow(){let e="",t="0",n,o=this.getStrapId(),i="0",l=this.getSplitCoinsCommands()[0].SplitCoins.amounts[0];if(l.$kind==="Input"&&(i=this.getPureInputU64(l.Input)),this.getMoveCallCommand("high_top_up")){let u=this.getMoveCallCommand("high_top_up").MoveCall;[e]=u.typeArguments;let b=u.arguments[1];b.$kind==="Input"&&(t=this.getPureInputU64(b.Input));let T=u.arguments[3];if(T.$kind==="Input"){let S=this.getPureAddresses(T.Input);S.length===1&&([n]=S)}}else if(this.getMoveCallCommand("high_borrow")){let u=this.getMoveCallCommand("high_borrow").MoveCall;[e]=u.typeArguments;let b=u.arguments[4];b.$kind==="Input"&&(t=this.getPureInputU64(b.Input));let T=u.arguments[5];if(T.$kind==="Input"){let S=this.getPureAddresses(T.Input);S.length===1&&([n]=S)}}else if(this.getMoveCallCommand("high_borrow_with_strap")){let u=this.getMoveCallCommand("high_borrow_with_strap").MoveCall;[e]=u.typeArguments;let b=u.arguments[5];b.$kind==="Input"&&(t=this.getPureInputU64(b.Input));let T=u.arguments[6];if(T.$kind==="Input"){let S=this.getPureAddresses(T.Input);S.length===1&&([n]=S)}}return{txType:Et.TransactionType.Other,type:"borrow",intentionData:{collateralType:e,collateralAmount:i,borrowAmount:t,insertionPlace:n,strapId:o}}}decodeRepay(){let e="",t="0",n="0",i,l=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 u=this.getMoveCallCommand("repay_and_withdraw").MoveCall;[e]=u.typeArguments;let b=u.arguments[4];b.$kind==="Input"&&(n=this.getPureInputU64(b.Input));let T=u.arguments[5];if(T.$kind==="Input"){let C=this.getPureAddresses(T.Input);C.length===1&&([i]=C)}let S=this.getSplitCoinsCommands()[0].SplitCoins.amounts[0];S.$kind==="Input"&&(t=this.getPureInputU64(S.Input))}else if(this.getMoveCallCommand("repay_and_withdraw_with_strap")){let u=this.getMoveCallCommand("repay_and_withdraw_with_strap").MoveCall;[e]=u.typeArguments;let b=u.arguments[5];b.$kind==="Input"&&(n=this.getPureInputU64(b.Input));let T=u.arguments[6];if(T.$kind==="Input"){let C=this.getPureAddresses(T.Input);C.length===1&&([i]=C)}let S=this.getSplitCoinsCommands()[0].SplitCoins.amounts[0];S.$kind==="Input"&&(t=this.getPureInputU64(S.Input))}return{txType:Et.TransactionType.Other,type:"repay",intentionData:{collateralType:e,repayAmount:t,withdrawAmount:n,isSurplus:!1,insertionPlace:i,strapId:l}}}decodeWithdraw(){let e="",t="0",n,o=this.getStrapId();if(this.getMoveCallCommand("withdraw_with_strap")){let i=this.getMoveCallCommand("withdraw_with_strap").MoveCall;[e]=i.typeArguments;let l=i.arguments[4];l.$kind==="Input"&&(t=this.getPureInputU64(l.Input));let u=i.arguments[5];if(u.$kind==="Input"){let b=this.getPureAddresses(u.Input);b.length===1&&([n]=b)}}else if(this.getMoveCallCommand("withdraw")){let i=this.getMoveCallCommand("withdraw").MoveCall;[e]=i.typeArguments;let l=i.arguments[3];l.$kind==="Input"&&(t=this.getPureInputU64(l.Input));let u=i.arguments[4];if(u.$kind==="Input"){let b=this.getPureAddresses(u.Input);b.length===1&&([n]=b)}}return{txType:Et.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:Et.TransactionType.Other,type:"close",intentionData:{collateralType:e,strapId:t}}}decodeSBUCKDeposit(){let t=this.getMoveCallCommand("into_balance").MoveCall.typeArguments[0],n="0",i=this.getSplitCoinsCommands()[0].SplitCoins.amounts[0];i.$kind==="Input"&&(n=this.getPureInputU64(i.Input));let l=this.isSBUCKStakeTransaction();return console.log("Decoder.decodeSBUCKDeposit",t,n,l),{txType:Et.TransactionType.Other,type:"sbuck-deposit",intentionData:{coinType:t,amount:n,isStake:l}}}decodeSBUCKUnstake(){let e="0",t=this.isSBUCKStakeTransaction();if(t){let b=this.getSplitCoinsCommands()[0].SplitCoins.amounts[0];b.$kind==="Input"&&(e=this.getPureInputU64(b.Input))}let n=[],o=this.getMoveCallModuleCommands("proof_rule","unlock");if(o.length>0)for(let u=0;u<o.length;u++){let b=o[u];n.push("")}else{let u=this.getMoveCallModuleCommands("fountain_core","force_unstake");for(let b=0;b<u.length;b++){let S=u[b].MoveCall.arguments[2];if(S.$kind==="Input"){let{objectId:C}=this.inputs[S.Input].UnresolvedObject;n.push(C)}}}let i=this.isSBUCKWithdrawTransaction(),l={stakeProofs:n,amount:e,isStake:t,toBuck:i};return console.log("Decoder.decodeSBUCKUnstake",l),{txType:Et.TransactionType.Other,type:"sbuck-unstake",intentionData:l}}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:Et.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 i=t[n].MoveCall.arguments[2];if(i.$kind==="Input"){let{objectId:l}=this.inputs[i.Input].UnresolvedObject;e.push(l)}}return console.log("Decoder.decodeSBUCKClaim",e),{txType:Et.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 i=this.getMoveCallModuleCommand("tank_operations","deposit").MoveCall.typeArguments[0];return console.log("Decoder.decodeTankDeposit",i,e),{txType:Et.TransactionType.Other,type:"tank-deposit",intentionData:{coinType:i,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:Et.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:Et.TransactionType.Other,type:"tank-claim",intentionData:{coinType:t}}}decodeLockedClaim(){let e="",t=0,n=this.getMoveCallModuleCommands("proof_rule","claim");for(let i=0;i<n.length;i++)[e]=n[i].MoveCall.typeArguments,t++;let o=this.getMoveCallModuleCommands("lst_proof_rule","claim");for(let i=0;i<o.length;i++)[e]=o[i].MoveCall.typeArguments,t++;return console.log("Decoder.decodeLockedClaim",e,t),{txType:Et.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 zn.bcs.U64.fromBase64(t.Pure.bytes)}getPureAddresses(e){let t=this.inputs[e];if(t.$kind!=="Pure")throw new Error("not pure argument");return zn.bcs.vector(zn.bcs.Address).fromBase64(t.Pure.bytes)}};var ec=require("@msafe/sui3-utils");var Ys=require("@mysten/sui/transactions"),Zs=require("bucket-protocol-sdk");var Xs=require("bucket-protocol-sdk"),Ot=(a,e)=>{let t=a==="sui:mainnet"?"mainnet":"testnet";return new Xs.BucketClient(t,e.address)};var tc=async(a,e,t)=>{let{coinType:n,amount:o,buckToCoin:i}=a,l=new Ys.Transaction,u=Ot(t,e);return await(0,Zs.buildPsmTx)(u,l,n,o,i,e.address),l};var Xn=class a extends k{constructor(t){super(t);this.data=t}txType=ec.TransactionType.Other;txSubType="psm";async build(t){let{account:n,network:o}=t;return await tc(this.data,n,o)}static fromData(t){return new a(t)}};var ic=require("@msafe/sui3-utils");var ln=require("@mysten/sui/transactions"),se=require("bucket-protocol-sdk");var nc=async(a,e,t)=>{let{collateralType:n,collateralAmount:o,borrowAmount:i,insertionPlace:l,strapId:u}=a,b=new ln.Transaction,T=Ot(t,e);return await(0,se.buildBorrowTx)(T,b,n,o,i,e.address,l,u),b},oc=async(a,e,t)=>{let{collateralType:n,withdrawAmount:o,insertionPlace:i,strapId:l}=a,u=new ln.Transaction,b=Ot(t,e);return await(0,se.buildWithdrawTx)(b,u,n,o,e.address,i,l),u},ac=async(a,e,t)=>{let{collateralType:n,repayAmount:o,withdrawAmount:i,isSurplus:l,insertionPlace:u,strapId:b}=a,T=new ln.Transaction,S=Ot(t,e);return await(0,se.buildRepayTx)(S,T,n,o,i,e.address,l,u,b),T},rc=async(a,e,t)=>{let{collateralType:n,recipient:o,strapId:i}=a,l=new ln.Transaction,u=Ot(t,e);return await(0,se.buildCloseTx)(u,l,n,o,i),l};var Yn=class a extends k{constructor(t){super(t);this.data=t}txType=ic.TransactionType.Other;txSubType="borrow";async build(t){let{account:n,network:o}=t;return await nc(this.data,n,o)}static fromData(t){return new a(t)}};var sc=require("@msafe/sui3-utils");var Zn=class a extends k{constructor(t){super(t);this.data=t}txType=sc.TransactionType.Other;txSubType="repay";async build(t){let{account:n,network:o}=t;return await ac(this.data,n,o)}static fromData(t){return new a(t)}};var cc=require("@msafe/sui3-utils");var to=class a extends k{constructor(t){super(t);this.data=t}txType=cc.TransactionType.Other;txSubType="withdraw";async build(t){let{account:n,network:o}=t;return await oc(this.data,n,o)}static fromData(t){return new a(t)}};var lc=require("@msafe/sui3-utils");var eo=class a extends k{constructor(t){super(t);this.data=t}txType=lc.TransactionType.Other;txSubType="close";async build(t){let{account:n,network:o}=t;return await rc(this.data,n,o)}static fromData(t){return new a(t)}};var dn=require("@msafe/sui3-utils");var un=require("@mysten/sui/transactions"),ce=require("bucket-protocol-sdk");var uc=async(a,e,t)=>{let{coinType:n,amount:o,isStake:i}=a,l=new un.Transaction,u=Ot(t,e);return await(0,ce.buildSBUCKDepositTx)(u,l,n,o,e.address,i),l},dc=async(a,e,t)=>{let{stakeProofs:n,amount:o,isStake:i,toBuck:l}=a,u=new un.Transaction,b=Ot(t,e);return await(0,ce.buildSBUCKUnstakeTx)(b,u,n,o,e.address,i,l),u},mc=async(a,e,t)=>{let{amount:n}=a,o=new un.Transaction,i=Ot(t,e);return await(0,ce.buildSBUCKWithdrawTx)(i,o,n,e.address),o},pc=async(a,e,t)=>{let{stakeProofs:n}=a,o=new un.Transaction,i=Ot(t,e);return await(0,ce.buildSBUCKClaimTx)(i,o,n,e.address),o};var no=class a extends k{constructor(t){super(t);this.data=t}txType=dn.TransactionType.Other;txSubType="sbuck-deposit";async build(t){let{account:n,network:o}=t;return await uc(this.data,n,o)}static fromData(t){return new a(t)}},oo=class a extends k{constructor(t){super(t);this.data=t}txType=dn.TransactionType.Other;txSubType="sbuck-unstake";async build(t){let{account:n,network:o}=t;return await dc(this.data,n,o)}static fromData(t){return new a(t)}},ao=class a extends k{constructor(t){super(t);this.data=t}txType=dn.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 a(t)}},ro=class a extends k{constructor(t){super(t);this.data=t}txType=dn.TransactionType.Other;txSubType="sbuck-claim";async build(t){let{account:n,network:o}=t;return await pc(this.data,n,o)}static fromData(t){return new a(t)}};var uo=require("@msafe/sui3-utils");var io=require("@mysten/sui/transactions"),Le=require("bucket-protocol-sdk");var fc=async(a,e,t)=>{let{coinType:n,amount:o}=a,i=new io.Transaction,l=Ot(t,e);return await(0,Le.buildTankDepositTx)(l,i,n,o,e.address),i},hc=async(a,e,t)=>{let{coinType:n,amount:o}=a,i=new io.Transaction,l=Ot(t,e);return await(0,Le.buildTankWithdrawTx)(l,i,n,o,e.address),i},bc=async(a,e,t)=>{let{coinType:n}=a,o=new io.Transaction,i=Ot(t,e);return await(0,Le.buildTankClaimTx)(i,o,n,e.address),o};var gc=require("@mysten/sui/transactions"),yc=require("bucket-protocol-sdk");var Tc=async(a,e,t)=>{let{coinType:n,proofCount:o}=a,i=new gc.Transaction,l=Ot(t,e);return await(0,yc.buildLockedClaimTx)(l,i,n,o,e.address),i};var so=class a extends k{constructor(t){super(t);this.data=t}txType=uo.TransactionType.Other;txSubType="tank-deposit";async build(t){let{account:n,network:o}=t;return await fc(this.data,n,o)}static fromData(t){return new a(t)}},co=class a extends k{constructor(t){super(t);this.data=t}txType=uo.TransactionType.Other;txSubType="tank-withdraw";async build(t){let{account:n,network:o}=t;return await hc(this.data,n,o)}static fromData(t){return new a(t)}},lo=class a extends k{constructor(t){super(t);this.data=t}txType=uo.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 a(t)}};var wc=require("@msafe/sui3-utils");var mo=class a extends k{constructor(t){super(t);this.data=t}txType=wc.TransactionType.Other;txSubType="lock-claim";async build(t){let{account:n,network:o}=t;return await Tc(this.data,n,o)}static fromData(t){return new a(t)}};var po=class{application="bucket";supportSDK="@mysten/sui";async deserialize(e){console.log("Bucket helper deserialize input: ",e);let{transaction:t}=e,o=new Jn(t).decode();return{txType:Sc.TransactionType.Other,txSubType:o.type,intentionData:o.intentionData}}async build(e){let{suiClient:t,account:n,network:o}=e,i;switch(e.txSubType){case"psm":i=Xn.fromData(e.intentionData);break;case"borrow":i=Yn.fromData(e.intentionData);break;case"withdraw":i=to.fromData(e.intentionData);break;case"repay":i=Zn.fromData(e.intentionData);break;case"close":i=eo.fromData(e.intentionData);break;case"tank-deposit":i=so.fromData(e.intentionData);break;case"tank-withdraw":i=co.fromData(e.intentionData);break;case"tank-claim":i=lo.fromData(e.intentionData);break;case"sbuck-deposit":i=no.fromData(e.intentionData);break;case"sbuck-unstake":i=oo.fromData(e.intentionData);break;case"sbuck-withdraw":i=ao.fromData(e.intentionData);break;case"sbuck-claim":i=ro.fromData(e.intentionData);break;case"lock-claim":i=mo.fromData(e.intentionData);break;default:throw new Error("not implemented")}return i.build({suiClient:t,account:n,network:o})}};var Il=require("@msafe/sui3-utils");var Rc=require("@msafe/sui3-utils");var mn=require("@cetusprotocol/aggregator-sdk"),Cc=require("@cetusprotocol/cetus-periphery-sdk"),Ic=require("@cetusprotocol/cetus-sui-clmm-sdk"),xc=require("@cetusprotocol/cetus-xcetus-sdk"),kc=Ut(require("@cetusprotocol/vaults-sdk")),pn=require("@mysten/sui/client"),um={fullRpcUrl:(0,pn.getFullnodeUrl)("mainnet"),simulationAccount:{address:"0x326ce9894f08dcaa337fa232641cc34db957aec9ff6614c1186bc9a7508df0bb"},cetus_config:{package_id:"0x95b8d278b876cae22206131fb9724f701c9444515813042f54f0a426c9a3bc2f",published_at:"0x95b8d278b876cae22206131fb9724f701c9444515813042f54f0a426c9a3bc2f",config:{coin_list_id:"0x8cbc11d9e10140db3d230f50b4d30e9b721201c0083615441707ffec1ef77b23",launchpad_pools_id:"0x1098fac992eab3a0ab7acf15bb654fc1cf29b5a6142c4ef1058e6c408dd15115",clmm_pools_id:"0x15b6a27dd9ae03eb455aba03b39e29aad74abd3757b8e18c0755651b2ae5b71e",admin_cap_id:"0x39d78781750e193ce35c45ff32c6c0c3f2941fa3ddaf8595c90c555589ddb113",global_config_id:"0x0408fa4e4a4c03cc0de8f23d0c2bbfe8913d178713c9a271ed4080973fe42d8f",coin_list_handle:"0x49136005e90e28c4695419ed4194cc240603f1ea8eb84e62275eaff088a71063",launchpad_pools_handle:"0x5e194a8efcf653830daf85a85b52e3ae8f65dc39481d54b2382acda25068375c",clmm_pools_handle:"0x37f60eb2d9d227949b95da8fea810db3c32d1e1fa8ed87434fc51664f87d83cb"}},clmm_pool:{package_id:"0x1eabed72c53feb3805120a081dc15963c204dc8d091542592abaf7a35689b2fb",published_at:"0xc6faf3703b0e8ba9ed06b7851134bbbe7565eb35ff823fd78432baa4cbeaa12e",version:4,config:{pools_id:"0xf699e7f2276f5c9a75944b37a0c5b5d9ddfd2471bf6242483b03ab2887d198d0",global_config_id:"0xdaa46292632c3c4d8f31f23ea0f9b36a28ff3677e9684980e4438403a67a3d8f",global_vault_id:"0xce7bceef26d3ad1f6d9b6f13a953f053e6ed3ca77907516481ce99ae8e588f2b",admin_cap_id:""}},integrate:{package_id:"0x996c4d9480708fb8b92aa7acf819fb0497b5ec8e65ba06601cae2fb6db3312c3",published_at:"0x2d8c2e0fc6dd25b0214b3fa747e0fd27fd54608142cd2e4f64c1cd350cc4add4",version:6},deepbook:{package_id:"0x000000000000000000000000000000000000000000000000000000000000dee9",published_at:"0x000000000000000000000000000000000000000000000000000000000000dee9"},deepbook_endpoint_v2:{package_id:"0x92aee86c01c79146d23938a00c7fff725ee0688c389be36d1bcbe03761b466c6",published_at:"0x92aee86c01c79146d23938a00c7fff725ee0688c389be36d1bcbe03761b466c6"},aggregatorUrl:"https://api-sui.cetus.zone/router",swapCountUrl:"https://api-sui.cetus.zone/v2/sui/swap/count"},dm={launchpad:{package_id:"0x80d114c5d474eabc2eb2fcd1a0903f1eb5b5096a8dc4184d72453f7a9be728e4",published_at:"0x80d114c5d474eabc2eb2fcd1a0903f1eb5b5096a8dc4184d72453f7a9be728e4",config:{pools_id:"0xfd8d37f7a1276878972d240302c8efe32f577220c1bbc6c8984d8b60dddfcab3",admin_cap_id:"0x66c70d58c69353714cc6fe2d3a62492d605a96a9821e2bd8274de17219c69980",config_cap_id:"0x02b8d23f033687579966e182c776fe0287cacdbb18bff56c29f141e29a18a4d1"}},ido:{package_id:"0x1192c9e20b4b0a8848a73a8c711b43e38f7ea1f307b556aab6ffab4e982e9c59",published_at:"0x1192c9e20b4b0a8848a73a8c711b43e38f7ea1f307b556aab6ffab4e982e9c59",config:{pools_id:"0xefc209b47acf1f23b29d166440904600229e520ad36228aaf2329b7c16be9762",admin_cap_id:"0x281859d366951830aeeda90779aa170d8ee6845875545470d33ecb890e78c8ce",package_version_id:"0xc93dc996106770af5f4e979b6808518f8cee080f22f35b936f071f59d834bb22"}},xcetus:{package_id:"0x9e69acc50ca03bc943c4f7c5304c2a6002d507b51c11913b247159c60422c606",published_at:"0x9e69acc50ca03bc943c4f7c5304c2a6002d507b51c11913b247159c60422c606",config:{xcetus_manager_id:"0x838b3dbade12b1e602efcaf8c8b818fae643e43176462bf14fd196afa59d1d9d",lock_manager_id:"0x288b59d9dedb51d0bb6cb5e13bfb30885ecf44f8c9076b6f5221c5ef6644fd28",lock_handle_id:"0x7c534bb7b8a2cc21538d0dbedd2437cc64f47106cb4c259b9ff921b5c3cb1a49"}},xcetus_dividends:{package_id:"0x785248249ac457dfd378bdc6d2fbbfec9d1daf65e9d728b820eb4888c8da2c10",published_at:"0x5aa58e1623885bd93de2331d05c29bf4930e54e56beeabcab8fe5385de2d31dc",config:{dividend_manager_id:"0x721c990bfc031d074341c6059a113a59c1febfbd2faeb62d49dcead8408fa6b5",dividend_admin_id:"0x682ba823134f156eac2bcfb27d85a284954a0e61998dc628c40b9bcb4a46ff30",dividend_settle_id:"0xade40abe9f6dd10b83b11085be18f07b63b681cf1c169b041fa16854403388c5",venft_dividends_id:"0x9dcdb97b4307684bedaeaf803d381b12321a31ecbb9dad7df2cd5f64384f9456",venft_dividends_id_v2:"0xaa21fbc1707786d56302952f8327362f4eb9a431a5bc574834e6d46125390de3"}},cetus_faucet:{package_id:"0x6864a6f921804860930db6ddbe2e16acdf8504495ea7481637a1c8b9a8fe54b",published_at:"0x6864a6f921804860930db6ddbe2e16acdf8504495ea7481637a1c8b9a8fe54b"},xtoken:{package_id:"",published_at:"",config:{xtoken_manager_id:"",lock_manager_id:"",lock_handle_id:""}},xtoken_dividends:{package_id:"",published_at:"",config:{dividend_manager_id:"",dividend_admin_id:"",dividend_settle_id:""}},token_faucet:{package_id:"",published_at:""},booster:{package_id:"",published_at:"",config:{booster_config_id:"",booster_pool_handle:""}},maker_bonus:{package_id:"",published_at:"",config:{maker_config_id:"",maker_pool_handle:""}},liquidity_stratefy:{package_id:"",published_at:"",version:void 0,config:void 0},vaults:{package_id:"0xd3453d9be7e35efe222f78a810bb3af1859fd1600926afced8b4936d825c9a05",published_at:"0x58e5de6e425397eeaf952d55c0f94637bee91b25d6138ce222f89cda0aefec03",version:1,config:{admin_cap_id:"0x78a42978709c4032fab7b33b782b5bcef64c1c6603250bf23644650b72144375",vaults_manager_id:"0x25b82dd2f5ee486ed1c8af144b89a8931cd9c29dee3a86a1bfe194fdea9d04a6",vaults_pool_handle:"0x9036bcc5aa7fd2cceec1659a6a1082871f45bc400c743f50063363457d1738bd",haedal:{package_id:"0xbde4ba4c2e274a60ce15c1cfff9e5c42e41654ac8b6d906a57efa4bd3c29f47d",published_at:"0xaabf0856070391df81fad9240049d69c5a51c3d376cc0885eeedd516526cc79b",version:1,config:{staking_id:"0x47b224762220393057ebf4f70501b6e657c3e56684737568439a04f80849b2ca",coin_type:"0xbde4ba4c2e274a60ce15c1cfff9e5c42e41654ac8b6d906a57efa4bd3c29f47d::hasui::HASUI"}},volo:{package_id:"0x549e8b69270defbfafd4f94e17ec44cdbdd99820b33bda2278dea3b9a32d3f55",published_at:"0x549e8b69270defbfafd4f94e17ec44cdbdd99820b33bda2278dea3b9a32d3f55",version:1,config:{native_pool:"0x7fa2faa111b8c65bea48a23049bfd81ca8f971a262d981dcd9a17c3825cb5baf",vsui_metadata:"0x680cd26af32b2bde8d3361e804c53ec1d1cfe24c7f039eb7f549e8dfde389a60",coin_type:"0x549e8b69270defbfafd4f94e17ec44cdbdd99820b33bda2278dea3b9a32d3f55::cert::CERT"}},aftermath:{package_id:"0x7f6ce7ade63857c4fd16ef7783fed2dfc4d7fb7e40615abdb653030b76aef0c6",published_at:"0x7f6ce7ade63857c4fd16ef7783fed2dfc4d7fb7e40615abdb653030b76aef0c6",version:1,config:{staked_sui_vault:"0x2f8f6d5da7f13ea37daa397724280483ed062769813b6f31e9788e59cc88994d",referral_vault:"0x4ce9a19b594599536c53edb25d22532f82f18038dc8ef618afd00fbbfb9845ef",safe:"0xeb685899830dd5837b47007809c76d91a098d52aabbf61e8ac467c59e5cc4610",validator_address:"0xd30018ec3f5ff1a3c75656abf927a87d7f0529e6dc89c7ddd1bd27ecb05e3db2",coin_type:"0xf325ce1300e8dac124071d3152c5c5ee6174914f8bc2161e88329cf579246efc::afsui::AFSUI"}}}},limit_order:{package_id:"",published_at:"",version:1,config:{rate_orders_indexer_id:"",rate_orders_indexer_handle:"",global_config_id:"",token_list_handle:"",user_orders_indexer_id:"",user_orders_indexer_handle:""}},frams:{package_id:"0x11ea791d82b5742cc8cab0bf7946035c97d9001d7c3803a93f119753da66f526",published_at:"0x7e4ca066f06a1132ab0499c8c0b87f847a0d90684afa902e52501a44dbd81992",version:1,config:{global_config_id:"0x21215f2f6de04b57dd87d9be7bb4e15499aec935e36078e2488f36436d64996e",rewarder_manager_id:"0xe0e155a88c77025056da08db5b1701a91b79edb6167462f768e387c3ed6614d5",rewarder_manager_handle:"0xb32e312cbb3367d6f3d2b4e57c9225e903d29b7b9f612dae2ddf75bdeb26a5aa",admin_cap_id:"0xf10fbf1fea5b7aeaa524b87769461a28c5c977613046360093673991f26d886c"}},dca:{package_id:"",published_at:"",version:0,config:{admin_cap_id:"",global_config_id:"",indexer_id:"",user_indexer_id:"",in_coin_whitelist_id:"",out_coin_whitelist_id:""}}},mm={fullRpcUrl:(0,pn.getFullnodeUrl)("mainnet"),simulationAccount:{address:"0x326ce9894f08dcaa337fa232641cc34db957aec9ff6614c1186bc9a7508df0bb"},xcetus:{package_id:"0x9e69acc50ca03bc943c4f7c5304c2a6002d507b51c11913b247159c60422c606",published_at:"0x9e69acc50ca03bc943c4f7c5304c2a6002d507b51c11913b247159c60422c606",config:{xcetus_manager_id:"0x838b3dbade12b1e602efcaf8c8b818fae643e43176462bf14fd196afa59d1d9d",lock_manager_id:"0x288b59d9dedb51d0bb6cb5e13bfb30885ecf44f8c9076b6f5221c5ef6644fd28",lock_handle_id:"0x7c534bb7b8a2cc21538d0dbedd2437cc64f47106cb4c259b9ff921b5c3cb1a49"}},xcetus_dividends:{package_id:"0x785248249ac457dfd378bdc6d2fbbfec9d1daf65e9d728b820eb4888c8da2c10",published_at:"0x5aa58e1623885bd93de2331d05c29bf4930e54e56beeabcab8fe5385de2d31dc",version:4,config:{dividend_manager_id:"0x721c990bfc031d074341c6059a113a59c1febfbd2faeb62d49dcead8408fa6b5",dividend_admin_id:"0x682ba823134f156eac2bcfb27d85a284954a0e61998dc628c40b9bcb4a46ff30",dividend_settle_id:"0xade40abe9f6dd10b83b11085be18f07b63b681cf1c169b041fa16854403388c5",venft_dividends_id:"0x9dcdb97b4307684bedaeaf803d381b12321a31ecbb9dad7df2cd5f64384f9456",venft_dividends_id_v2:"0xaa21fbc1707786d56302952f8327362f4eb9a431a5bc574834e6d46125390de3"}},cetus_faucet:{package_id:"0x6864a6f921804860930db6ddbe2e16acdf8504495ea7481637a1c8b9a8fe54b",published_at:"0x6864a6f921804860930db6ddbe2e16acdf8504495ea7481637a1c8b9a8fe54b"}},Pe=(a,e)=>{let t=um,n=new Ic.CetusClmmSDK(t);return n.senderAddress=e.address,n},Xt=(a,e)=>{let t=Pe(a,e),n=dm;return new Cc.CetusPeripherySDK(n,t)},pm="https://api-sui.cetus.zone/router_v2/find_routes",vc=(a,e)=>{let t=new pn.SuiClient({url:"https://fullnode.mainnet.sui.io/"});return new mn.AggregatorClient({endpoint:pm,signer:e.address,client:t,env:mn.Env.Mainnet})},fm={fullRpcUrl:"https://fullnode.mainnet.sui.io/",simulationAccount:{address:"0x326ce9894f08dcaa337fa232641cc34db957aec9ff6614c1186bc9a7508df0bb"},clmm_pool:{package_id:"0x1eabed72c53feb3805120a081dc15963c204dc8d091542592abaf7a35689b2fb",published_at:"0xc6faf3703b0e8ba9ed06b7851134bbbe7565eb35ff823fd78432baa4cbeaa12e",config:{pools_id:"0xf699e7f2276f5c9a75944b37a0c5b5d9ddfd2471bf6242483b03ab2887d198d0",global_config_id:"0xdaa46292632c3c4d8f31f23ea0f9b36a28ff3677e9684980e4438403a67a3d8f",global_vault_id:"0xce7bceef26d3ad1f6d9b6f13a953f053e6ed3ca77907516481ce99ae8e588f2b",admin_cap_id:""}},integrate:{package_id:"0x996c4d9480708fb8b92aa7acf819fb0497b5ec8e65ba06601cae2fb6db3312c3",published_at:"0x2d8c2e0fc6dd25b0214b3fa747e0fd27fd54608142cd2e4f64c1cd350cc4add4"},frams:{package_id:"0x11ea791d82b5742cc8cab0bf7946035c97d9001d7c3803a93f119753da66f526",published_at:"0x7e4ca066f06a1132ab0499c8c0b87f847a0d90684afa902e52501a44dbd81992",config:{global_config_id:"0x21215f2f6de04b57dd87d9be7bb4e15499aec935e36078e2488f36436d64996e",rewarder_manager_id:"0xe0e155a88c77025056da08db5b1701a91b79edb6167462f768e387c3ed6614d5",rewarder_manager_handle:"0xb32e312cbb3367d6f3d2b4e57c9225e903d29b7b9f612dae2ddf75bdeb26a5aa",admin_cap_id:"0xf10fbf1fea5b7aeaa524b87769461a28c5c977613046360093673991f26d886c"}},vaults:{package_id:"0xd3453d9be7e35efe222f78a810bb3af1859fd1600926afced8b4936d825c9a05",published_at:"0x58e5de6e425397eeaf952d55c0f94637bee91b25d6138ce222f89cda0aefec03",config:{admin_cap_id:"0x78a42978709c4032fab7b33b782b5bcef64c1c6603250bf23644650b72144375",vaults_manager_id:"0x25b82dd2f5ee486ed1c8af144b89a8931cd9c29dee3a86a1bfe194fdea9d04a6",vaults_pool_handle:"0x9036bcc5aa7fd2cceec1659a6a1082871f45bc400c743f50063363457d1738bd",haedal:{package_id:"0xbde4ba4c2e274a60ce15c1cfff9e5c42e41654ac8b6d906a57efa4bd3c29f47d",published_at:"0xaabf0856070391df81fad9240049d69c5a51c3d376cc0885eeedd516526cc79b",version:1,config:{staking_id:"0x47b224762220393057ebf4f70501b6e657c3e56684737568439a04f80849b2ca",coin_type:"0xbde4ba4c2e274a60ce15c1cfff9e5c42e41654ac8b6d906a57efa4bd3c29f47d::hasui::HASUI"}},volo:{package_id:"0x549e8b69270defbfafd4f94e17ec44cdbdd99820b33bda2278dea3b9a32d3f55",published_at:"0x549e8b69270defbfafd4f94e17ec44cdbdd99820b33bda2278dea3b9a32d3f55",version:1,config:{native_pool:"0x7fa2faa111b8c65bea48a23049bfd81ca8f971a262d981dcd9a17c3825cb5baf",vsui_metadata:"0x680cd26af32b2bde8d3361e804c53ec1d1cfe24c7f039eb7f549e8dfde389a60",coin_type:"0x549e8b69270defbfafd4f94e17ec44cdbdd99820b33bda2278dea3b9a32d3f55::cert::CERT"}},aftermath:{package_id:"0x7f6ce7ade63857c4fd16ef7783fed2dfc4d7fb7e40615abdb653030b76aef0c6",published_at:"0x7f6ce7ade63857c4fd16ef7783fed2dfc4d7fb7e40615abdb653030b76aef0c6",version:1,config:{staked_sui_vault:"0x2f8f6d5da7f13ea37daa397724280483ed062769813b6f31e9788e59cc88994d",referral_vault:"0x4ce9a19b594599536c53edb25d22532f82f18038dc8ef618afd00fbbfb9845ef",safe:"0xeb685899830dd5837b47007809c76d91a098d52aabbf61e8ac467c59e5cc4610",validator_address:"0xd30018ec3f5ff1a3c75656abf927a87d7f0529e6dc89c7ddd1bd27ecb05e3db2",coin_type:"0xf325ce1300e8dac124071d3152c5c5ee6174914f8bc2161e88329cf579246efc::afsui::AFSUI"}}}},aggregator:{endPoint:"https://api-sui.cetus.zone/router_v2/find_routes",fullNodeurl:"https://fullnode.mainnet.sui.io/",walletAddress:"0x326ce9894f08dcaa337fa232641cc34db957aec9ff6614c1186bc9a7508df0bb",env:mn.Env.Mainnet,providers:["CETUS","DEEPBOOK","KRIYA","KRIYAV3","FLOWX","FLOWXV3","AFTERMATH","TURBOS","HAEDAL","VOLO","AFSUI"]}},Oi=(a,e)=>{let t=new kc.default(fm);return t.senderAddress=e.address,t},je=(a,e)=>{let t=new xc.CetusXcetusSDK(mm);return t.senderAddress=e.address,t};var Dc=async(a,e,t)=>await Pe(t,e).Position.createAddLiquidityFixTokenPayload(a?.parameter,a?.gasEstimateArg),Ac=async(a,e,t)=>await Pe(t,e).Position.createAddLiquidityFixTokenPayload(a?.parameter,a?.gasEstimateArg),Mc=async(a,e,t)=>await Pe(t,e).Position.closePositionTransactionPayload(a),Oc=async(a,e,t)=>await Pe(t,e).Position.removeLiquidityTransactionPayload(a),Pc=async(a,e,t)=>await Pe(t,e).Rewarder.collectRewarderTransactionPayload(a);var fo=class a extends k{constructor(t){super(t);this.data=t}txType=Rc.TransactionType.Other;txSubType="OpenAndAddLiquidity";async build(t){let{account:n,network:o}=t,{txbParams:i}=this.data;return await Dc(i,n,o)}static fromData(t){return new a(t)}};var Bc=require("@msafe/sui3-utils");var ho=class a extends k{constructor(t){super(t);this.data=t}txType=Bc.TransactionType.Other;txSubType="ClaimFeeAndMining";async build(t){let{account:n,network:o}=t,{txbParams:i}=this.data;return await Pc(i,n,o)}static fromData(t){return new a(t)}};var _c=require("@msafe/sui3-utils");var bo=class a extends k{constructor(t){super(t);this.data=t}txType=_c.TransactionType.Other;txSubType="DecreaseLiquidity";async build(t){let{account:n,network:o}=t,{txbParams:i}=this.data;return await Oc(i,n,o)}static fromData(t){return new a(t)}};var $c=require("@msafe/sui3-utils");var Ec=async(a,e,t)=>await Xt(t,e).Farms.openPositionAddLiquidityStakePaylod(a),Nc=async(a,e,t)=>await Xt(t,e).Farms.addLiquidityFixCoinPayload(a),Wc=async(a,e,t)=>await Xt(t,e).Farms.removeLiquidityPayload(a),Lc=async(a,e,t)=>await Xt(t,e).Farms.removeLiquidityPayload(a),jc=async(a,e,t)=>await Xt(t,e).Farms.claimFeeAndClmmReward(a),Uc=async(a,e,t)=>await Xt(t,e).Farms.harvestPayload(a),qc=async(a,e,t)=>{let n=Xt(t,e),o=Object.values(a);return await n.Farms.batchHarvestPayload(o)},Fc=async(a,e,t)=>await Xt(t,e).Farms.depositPayload(a),Kc=async(a,e,t)=>await Xt(t,e).Farms.withdrawPayload(a);var go=class a extends k{constructor(t){super(t);this.data=t}txType=$c.TransactionType.Other;txSubType="FarmingOpenAndAddLiquidity";async build(t){let{account:n,network:o}=t,{txbParams:i}=this.data;return await Ec(i,n,o)}static fromData(t){return new a(t)}};var Vc=require("@msafe/sui3-utils");var yo=class a extends k{constructor(t){super(t);this.data=t}txType=Vc.TransactionType.Other;txSubType="FarmingBatchHarvest";async build(t){let{account:n,network:o}=t,{txbParams:i}=this.data;return await qc(i,n,o)}static fromData(t){return new a(t)}};var Hc=require("@msafe/sui3-utils");var To=class a extends k{constructor(t){super(t);this.data=t}txType=Hc.TransactionType.Other;txSubType="FarmingClaimFeeAndReward";async build(t){let{account:n,network:o}=t,{txbParams:i}=this.data;return await jc(i,n,o)}static fromData(t){return new a(t)}};var Gc=require("@msafe/sui3-utils");var wo=class a extends k{constructor(t){super(t);this.data=t}txType=Gc.TransactionType.Other;txSubType="FarmingDecreaseLiquidity";async build(t){let{account:n,network:o}=t,{txbParams:i}=this.data;return await Wc(i,n,o)}static fromData(t){return new a(t)}};var zc=require("@msafe/sui3-utils");var So=class a extends k{constructor(t){super(t);this.data=t}txType=zc.TransactionType.Other;txSubType="FarmingHarvest";async build(t){let{account:n,network:o}=t,{txbParams:i}=this.data;return await Uc(i,n,o)}static fromData(t){return new a(t)}};var Qc=require("@msafe/sui3-utils");var Co=class a extends k{constructor(t){super(t);this.data=t}txType=Qc.TransactionType.Other;txSubType="FarmingIncreaseLiquidity";async build(t){let{account:n,network:o}=t,{txbParams:i}=this.data;return await Nc(i,n,o)}static fromData(t){return new a(t)}};var Jc=require("@msafe/sui3-utils");var Io=class a extends k{constructor(t){super(t);this.data=t}txType=Jc.TransactionType.Other;txSubType="FarmingRemoveLiquidity";async build(t){let{account:n,network:o}=t,{txbParams:i}=this.data;return await Lc(i,n,o)}static fromData(t){return new a(t)}};var Xc=require("@msafe/sui3-utils");var xo=class a extends k{constructor(t){super(t);this.data=t}txType=Xc.TransactionType.Other;txSubType="FarmingStake";async build(t){let{account:n,network:o}=t,{txbParams:i}=this.data;return await Fc(i,n,o)}static fromData(t){return new a(t)}};var Yc=require("@msafe/sui3-utils");var ko=class a extends k{constructor(t){super(t);this.data=t}txType=Yc.TransactionType.Other;txSubType="FarmingUnstake";async build(t){let{account:n,network:o}=t,{txbParams:i}=this.data;return await Kc(i,n,o)}static fromData(t){return new a(t)}};var Zc=require("@msafe/sui3-utils");var vo=class a extends k{constructor(t){super(t);this.data=t}txType=Zc.TransactionType.Other;txSubType="IncreaseLiquidity";async build(t){let{account:n,network:o}=t,{txbParams:i}=this.data;return await Ac(i,n,o)}static fromData(t){return new a(t)}};var tl=require("@msafe/sui3-utils");var Do=class a extends k{constructor(t){super(t);this.data=t}txType=tl.TransactionType.Other;txSubType="RemoveLiquidity";async build(t){let{account:n,network:o}=t,{txbParams:i}=this.data;return await Mc(i,n,o)}static fromData(t){return new a(t)}};var al=require("@msafe/sui3-utils");var el=require("@cetusprotocol/aggregator-sdk"),nl=require("@mysten/sui/transactions");var ol=async(a,e,t)=>{let n=vc(t,e),o=new nl.Transaction;return await n.fastRouterSwap({...a,routers:(0,el.restituteMsafeFastRouterSwapParams)(a.routers),txb:o}),o};var Ao=class a extends k{constructor(t){super(t);this.data=t}txType=al.TransactionType.Other;txSubType="AggregatorSwap";async build(t){let{account:n,network:o}=t,{txbParams:i}=this.data;return await ol(i,n,o)}static fromData(t){return new a(t)}};var sl=require("@msafe/sui3-utils");var rl=async(a,e,t)=>await Oi(t,e).Vaults.deposit(a),il=async(a,e,t)=>await Oi(t,e).Vaults.withdraw(a);var Mo=class a extends k{constructor(t){super(t);this.data=t}txType=sl.TransactionType.Other;txSubType="AddVaultsPosition";async build(t){let{account:n,network:o}=t,{txbParams:i}=this.data;return await rl(i,n,o)}static fromData(t){return new a(t)}};var cl=require("@msafe/sui3-utils");var Oo=class a extends k{constructor(t){super(t);this.data=t}txType=cl.TransactionType.Other;txSubType="RemoveVaultsPosition";async build(t){let{account:n,network:o}=t,{txbParams:i}=this.data;return await il(i,n,o)}static fromData(t){return new a(t)}};var ml=require("@msafe/sui3-utils");var ul=require("@mysten/sui/transactions"),ll={package_id:"0x355714a1eeb7ab1d80902da6c92001170cda1212edf524c32aa308a3ac177c31",published_at:"0x355714a1eeb7ab1d80902da6c92001170cda1212edf524c32aa308a3ac177c31",cetus_coin_type:"0x06864a6f921804860930db6ddbe2e16acdf8504495ea7481637a1c8b9a8fe54b::cetus::CETUS"},dl=async(a,e,t)=>{console.log("getVestingRedeemTxb txbParams: ",a),console.log("getVestingRedeemTxb account: ",e),console.log("getVestingRedeemTxb network: ",t);let{pool:n,nftId:o,periods:i,CLOCK_ADDRESS:l}=a,u=new ul.Transaction;return i.forEach(b=>{u.moveCall({target:`${ll.published_at}::router::redeem`,typeArguments:[ll.cetus_coin_type],arguments:[u.object(n),u.object(o),u.pure(b),u.object(l)]})}),u};var Po=class a extends k{constructor(t){super(t);this.data=t}txType=ml.TransactionType.Other;txSubType="VestingRedeem";async build(t){let{account:n,network:o}=t,{txbParams:i}=this.data;return await dl(i,n,o)}static fromData(t){return new a(t)}};var yl=require("@msafe/sui3-utils");var pl=async(a,e,t)=>await je(t,e).XCetusModule.convertPayload(a),fl=async(a,e,t)=>await je(t,e).XCetusModule.redeemLockPayload(a),hl=async(a,e,t)=>await je(t,e).XCetusModule.redeemDividendV3Payload(a.veNftId,a.rewardList),bl=async(a,e,t)=>await je(t,e).XCetusModule.cancelRedeemPayload(a),gl=async(a,e,t)=>await je(t,e).XCetusModule.redeemPayload(a);var Ro=class a extends k{constructor(t){super(t);this.data=t}txType=yl.TransactionType.Other;txSubType="xCETUSCancelRedeem";async build(t){let{account:n,network:o}=t,{txbParams:i}=this.data;return await bl(i,n,o)}static fromData(t){return new a(t)}};var Tl=require("@msafe/sui3-utils");var Bo=class a extends k{constructor(t){super(t);this.data=t}txType=Tl.TransactionType.Other;txSubType="xCETUSClaimStakingRwewards";async build(t){let{account:n,network:o}=t,{txbParams:i}=this.data;return await hl(i,n,o)}static fromData(t){return new a(t)}};var wl=require("@msafe/sui3-utils");var _o=class a extends k{constructor(t){super(t);this.data=t}txType=wl.TransactionType.Other;txSubType="xCETUSConvert";async build(t){let{account:n,network:o}=t,{txbParams:i}=this.data;return await pl(i,n,o)}static fromData(t){return new a(t)}};var Sl=require("@msafe/sui3-utils");var Eo=class a extends k{constructor(t){super(t);this.data=t}txType=Sl.TransactionType.Other;txSubType="xCETUSRedeem";async build(t){let{account:n,network:o}=t,{txbParams:i}=this.data;return await gl(i,n,o)}static fromData(t){return new a(t)}};var Cl=require("@msafe/sui3-utils");var No=class a extends k{constructor(t){super(t);this.data=t}txType=Cl.TransactionType.Other;txSubType="xCETUSRedeemLock";async build(t){let{account:n,network:o}=t,{txbParams:i}=this.data;return await fl(i,n,o)}static fromData(t){return new a(t)}};var Wo=class{application="cetus";supportSDK="@mysten/sui";async deserialize(e){console.log("Cetus helper deserialize input: ",e);let{txbParams:t,action:n}=e;return{txType:Il.TransactionType.Other,txSubType:n,intentionData:{txbParams:{...t},action:n}}}async build(e){let{suiClient:t,account:n,network:o}=e,i;switch(e.txSubType){case"OpenAndAddLiquidity":i=fo.fromData(e.intentionData);break;case"IncreaseLiquidity":i=vo.fromData(e.intentionData);break;case"DecreaseLiquidity":i=bo.fromData(e.intentionData);break;case"RemoveLiquidity":i=Do.fromData(e.intentionData);break;case"ClaimFeeAndMining":i=ho.fromData(e.intentionData);break;case"FarmingOpenAndAddLiquidity":i=go.fromData(e.intentionData);break;case"FarmingIncreaseLiquidity":i=Co.fromData(e.intentionData);break;case"FarmingDecreaseLiquidity":i=wo.fromData(e.intentionData);break;case"FarmingRemoveLiquidity":i=Io.fromData(e.intentionData);break;case"FarmingClaimFeeAndReward":i=To.fromData(e.intentionData);break;case"FarmingHarvest":i=So.fromData(e.intentionData);break;case"FarmingBatchHarvest":i=yo.fromData(e.intentionData);break;case"FarmingStake":i=xo.fromData(e.intentionData);break;case"FarmingUnstake":i=ko.fromData(e.intentionData);break;case"xCETUSConvert":i=_o.fromData(e.intentionData);break;case"xCETUSRedeemLock":i=No.fromData(e.intentionData);break;case"xCETUSClaimStakingRwewards":i=Bo.fromData(e.intentionData);break;case"xCETUSCancelRedeem":i=Ro.fromData(e.intentionData);break;case"xCETUSRedeem":i=Eo.fromData(e.intentionData);break;case"VestingRedeem":i=Po.fromData(e.intentionData);break;case"AggregatorSwap":i=Ao.fromData(e.intentionData);break;case"AddVaultsPosition":i=Mo.fromData(e.intentionData);break;case"RemoveVaultsPosition":i=Oo.fromData(e.intentionData);break;default:throw new Error("not implemented")}return i.build({suiClient:t,account:n,network:o})}};var Hl=require("@msafe/sui3-utils");var xl=Ut(require("sort-keys-recursive")),P=class{constructor(e){this.data=e}serialize(){return JSON.stringify((0,xl.default)(this.data))}};var fn=require("@mysten/sui.js/client");var Pi={};Mi(Pi,{contractId:()=>gm,default:()=>Cm,feeObjId:()=>wm,roleObjId:()=>ym,status:()=>bm,transaction:()=>hm,upgradeCapObjId:()=>Sm,vaultObjId:()=>Tm});var hm="DiBZq4UmVVYiRL6ZJmFKYoHcxtxqrhsCXSkFyT7wUr3j",bm="success",gm="0x81c960dc653975fbd0072deca8afb92d322898c911622898ba1b2e3ad0c4bd8d",ym="0xc6ec0bdee0bb59a72077e9acd2f42457043cf47080b3d3fad4d39abf28bba63a",Tm="0xbc4021387fbac149119fd24e92be9e58f745774292f3a2a12e2ac6daf5363e1d",wm="0x4178f63970fe2daeb256dc5730ad172e82b3e8eb45f31b33e0daae72cd35e1e1",Sm="0xe1e9aa7d222d151bfe6dd83358b0d7fdcb11260f710800cfaf7ccc1b1e245115",Cm={transaction:hm,status:bm,contractId:gm,roleObjId:ym,vaultObjId:Tm,feeObjId:wm,upgradeCapObjId:Sm};var Ri={};Mi(Ri,{contractId:()=>km,default:()=>Om,feeObjId:()=>Am,roleObjId:()=>vm,status:()=>xm,transaction:()=>Im,upgradeCapObjId:()=>Mm,vaultObjId:()=>Dm});var Im="855FNDV8o8Z3fWULPnQo9qdhLJpsg7wZrkCpNyfw9KfB",xm="success",km="0xc357c3985e8fb875d6b37141497af660779aa1bab0ec489b2213efd74067d1fa",vm="0x5ab49bdf9fd1413e328ef242b3f8d83dde791b38a0b627bfc87fb25c010d34f1",Dm="0xb483558770d8eb26007f193b75db40f0a45f2e36863a687625885d4de6993378",Am="0x48453fc4d7cde3fe35aad89e5dfb496608a6a55ea529a1c0274681a808627f94",Mm="0x34279779a0d0d36bd5044b04830d607fa1b0ecf316548c8ac3a44151e4f1a42a",Om={transaction:Im,status:xm,contractId:km,roleObjId:vm,vaultObjId:Dm,feeObjId:Am,upgradeCapObjId:Mm};var Pm=(0,fn.getFullnodeUrl)("testnet"),Rm=(0,fn.getFullnodeUrl)("testnet"),Bm=(0,fn.getFullnodeUrl)("mainnet"),_m=(0,fn.getFullnodeUrl)("mainnet"),Em="https://bc3p6l5unl.execute-api.us-west-1.amazonaws.com/prod",Nm="https://rolsbkota7.execute-api.us-west-1.amazonaws.com/prod",Wm="https://6p6mkx33ne.execute-api.us-west-1.amazonaws.com/prod",Lm="https://xrae3mrjv5.execute-api.us-west-1.amazonaws.com/prod",kl=Pi,vl=Ri,jm=new Map([["dev",{env:"dev",rpc:{url:Pm},backend:{url:Em},contract:kl}],["stg",{env:"stg",rpc:{url:Rm},backend:{url:Nm},contract:kl}],["prev",{env:"prev",rpc:{url:Bm},backend:{url:Wm},contract:vl}],["prod",{env:"prod",rpc:{url:_m},backend:{url:Lm},contract:vl}]]);function Dl(a,e){let t=jm.get(a);if(!t)throw new Error(`Env not supported: ${a}`);return e&&e.rpc&&(t.rpc=e.rpc),e&&e.backend&&(t.backend=e.backend),e&&e.contract&&(t.contract=e.contract),t}var Al=require("@mysten/sui.js/client");var j=class extends Error{mpayErrorCode;context;constructor(e,t,n={}){let{cause:o,context:i}=n;o?super(`[MPay] ${t}: ${o}`):super(`[MPay] ${t}`),this.mpayErrorCode=e,this.context=i}};var Lo=class extends j{constructor(){super(11,"Backend is not specified")}};var jo=class extends j{constructor(){super(1,"Wallet not connected")}};var ae=Ut(require("axios"));var Ue=class extends j{constructor(e,t){super(10,e,{context:t})}};var Uo=class a{constructor(e){this.apiURL=e}static parseResponseData(e){if(e instanceof ae.AxiosError)throw new Ue(e.response?.statusText);if(e.status===200){if(e.data.success)return e.data.data;throw new Ue(e.data.code)}throw new Ue(e.status.toString())}async getIncomingStreams(e,t){let n=await ae.default.post(`${this.apiURL}/stream`,{recipient:e,...t});return a.parseResponseData(n)}async getOutgoingStreams(e,t){let n=await ae.default.post(`${this.apiURL}/stream`,{sender:e,...t});return a.parseResponseData(n)}async getStreamHistory(e){let t=await ae.default.post(`${this.apiURL}/stream-events`,e),n=a.parseResponseData(t);return n.data.forEach(o=>{let i=o;return i.data.type==="create_stream"?i.data.balance=BigInt(i.data.balance):i.data.type==="cancel_stream"?i.data.withdrawAmount=BigInt(i.data.withdrawAmount):i.data.type==="claim"||i.data.type==="auto_claim"?i.data.claimAmount=BigInt(i.data.claimAmount):i.data.type==="set_auto_claim"&&(i.data.enabled=!!i.data.enabled),i.createdAt=new Date(i.createdAt),i}),n}async getAllCoinTypes(e){let t=await ae.default.post(`${this.apiURL}/stream-info`,{address:e});return a.parseResponseData(t)}async getAllRecipients(e,t){let n=await ae.default.post(`${this.apiURL}/stream-info`,{sender:e,status:t});return a.parseResponseData(n)}async getAllSenders(e,t){let n=await ae.default.post(`${this.apiURL}/stream-info`,{recipient:e,status:t});return a.parseResponseData(n)}};var qe=class a{signer;suiClient;envConfig;_backend;constructor(e){this.envConfig=e,this.suiClient=new Al.SuiClient({url:e.rpc.url}),e.backend&&(this._backend=new Uo(e.backend.url))}static new(e,t){let n=Dl(e,t);return new a(n)}get walletType(){return this.wallet?this.wallet.type:"disconnected"}get backend(){if(!this._backend)throw new Lo;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 jo;return this.signer}async walletAddress(){return this.wallet.address()}};var Be=require("@mysten/sui.js/utils");var wn=require("@mysten/sui.js/transactions");var Wi=require("@mysten/sui.js/transactions"),Tn=require("@mysten/sui.js/utils");var Bi=50n,qo=10000n,Ml=25n,_i=100000000n;var Yt=class{constructor(e){this.object=e}moveArg(e){return e.object(this.object)}},hn=class{constructor(e){this.objects=e}moveArgs(e){return e.makeMoveVec({objects:this.objects.map(t=>e.object(t))})}},de=class a{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=l=>new a(t.result[l]);if(n===Symbol.iterator)return function*(){let l=0;for(;;)yield o(l),l++};if(typeof n=="symbol")return;let i=parseInt(n,10);if(!(Number.isNaN(i)||i<0))return o(i)}})}moveArg(){return this.result}};var Ei=require("buffer"),Ol=require("@mysten/sui.js/utils");var bn=class extends j{constructor(e,t){super(3,e,{context:t})}};var Fo=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 bn("Invalid contract return type.",{ctx:{expectType:"address",gotType:o}});return(0,Ol.normalizeSuiAddress)(Ei.Buffer.from(n).toString("hex"))}getU64(e=0,t=0){let[n,o]=this.getValue(e,t);if(o!=="u64")throw new bn("Invalid contract return type.",{ctx:{expectType:"u64",gotType:o}});return Ei.Buffer.from(n).readBigInt64LE()}};var Ni=require("@mysten/sui.js/bcs");var H=class extends j{constructor(e,t,n){super(2,`Invalid input: ${e}`,{context:{fieldKey:t,fieldValue:n}})}};var Rl={groupId:"string",name:"string"},Um=64;function Bl(a){return _l(a),Ni.bcs.ser(Rl,a).toString("base64")}function gn(a){let e=Ni.bcs.de(Rl,a,"base64");return _l(e),e}function _l(a){if(!Pl(a.name))throw new H("Invalid metadata: Name contains unknown character");if(!Pl(a.groupId))throw new H("Invalid metadata: Group ID contains unknown character");if(a.name.length>Um)throw new H("Invalid metadata: Name exceed max length 64")}function Pl(a){return/^[\x00-\x7F]+$/.test(a)}var yn=require("@mysten/sui.js/utils");function Ko(a,e){return(0,yn.normalizeStructTag)(a)===(0,yn.normalizeStructTag)(e)}function me(a,e){return(0,yn.normalizeStructTag)(a)===(0,yn.normalizeStructTag)(e)}var $o="txn.gas";var El=require("nanoid");function Nl(){return(0,El.nanoid)()}var Re=class a{constructor(e,t,n){this.globals=e;this.feeContract=t;this.streamContract=n}static convertCreateStreamInfoToInternal(e){return{metadata:Bl({name:e.name,groupId:Nl()}),coinType:(0,Tn.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 Wi.TransactionBlock,n=this.calculateFeesInternal(e),o=this.getCreateStreamCoinRequests(e,n),i=await this.wallet.requestCoins(o),l=await this.addMergeCoins(t,i[0]),u;o.length>1?u=await this.addMergeCoins(t,i[1]):u=l;for(let b=0;b<e.recipients.length;b++){let T=e.recipients[b],S=this.amountForRecipient(T,e.numberEpoch),C=this.getStreamFeeLocal(S),[I]=t.splitCoins(l,[t.pure(S+C,"u64")]),[x]=t.splitCoins(u,[t.pure(this.flatSuiFee,"u64")]);this.streamContract.createStream(t,{paymentCoin:new de(I),flatFeeCoin:new de(x),metadata:e.metadata,recipient:T.address,timeStart:e.startTime,cliff:T.cliffAmount,epochInterval:e.epochInterval,numEpoch:e.numberEpoch,amountPerEpoch:T.amountPerEpoch,cancelable:e.cancelable,coinType:e.coinType})}return t}calculateCreateStreamFees(e){let t=a.convertCreateStreamInfoToInternal(e);return this.calculateFeesInternal(t)}feeParams(){return{createFeePercent:{numerator:Bi,denominator:qo},claimFeePercent:{numerator:Ml,denominator:qo},flatFeePerStream:_i}}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===$o?n=e.gas:n=e.object(t.primaryCoin),n}getCreateStreamCoinRequests(e,t){let n=e.coinType;return Ko(n,Tn.SUI_TYPE_ARG)?[{coinType:n,amount:t.totalAmount+t.streamFeeAmount+t.flatFeeAmount}]:[{coinType:n,amount:t.totalAmount+t.streamFeeAmount},{coinType:Tn.SUI_TYPE_ARG,amount:t.flatFeeAmount}]}calculateFeesInternal(e){let t=e.recipients.reduce((o,i)=>{let l=this.amountForRecipient(i,e.numberEpoch),u=this.getStreamFeeLocal(l);return{totalAmount:o.totalAmount+l,streamFeeAmount:o.streamFeeAmount+u}},{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 _i}getStreamFeeLocal(e){return e*Bi/qo}async getStreamFeeRemote(e){let t=this.feeContract.streamingFee(new Wi.TransactionBlock,e),n=await this.globals.suiClient.devInspectTransactionBlock({sender:await this.globals.walletAddress(),transactionBlock:t});return new Fo(n).getU64()}get wallet(){return this.globals.wallet}};var Li=require("@mysten/sui.js/transactions");var Wl="0x0000000000000000000000000000000000000000000000000000000000000006";var Fe=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(Li.Transactions.MoveCall({target:n,arguments:t.arguments.map(o=>o instanceof hn?o.moveArgs(e):o instanceof Yt?o.moveArg(e):o instanceof de?o.moveArg():e.pure(o)),typeArguments:t.typeArgs})),e}addTransactionBlock(e,t,n=[],o=[]){e.add(Li.Transactions.MoveCall({target:t,arguments:n.map(i=>i instanceof hn?i.moveArgs(e):i instanceof Yt?i.moveArg(e):i instanceof de?i.moveArg():e.pure(i)),typeArguments:o}))}makeObject(e){return typeof e=="string"?new Yt(e):e}vaultObject(){return new Yt(this.config.vaultObjId)}roleObject(){return new Yt(this.config.roleObjId)}feeObject(){return new Yt(this.config.feeObjId)}clockObject(){return new Yt(Wl)}};var Ke=class a extends Fe{constructor(t,n){super(a.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(),i=this.feeObject();return this.addContractCall(t,{method:a.MethodName.set_streaming_fee,arguments:[o,i,n],typeArgs:[]})}setStreamingFlatFee(t,n){let o=this.roleObject(),i=this.feeObject();return this.addContractCall(t,{method:a.MethodName.set_streaming_flat_fee,arguments:[o,i,n],typeArgs:[]})}setClaimFee(t,n){let o=this.roleObject(),i=this.feeObject();return this.addContractCall(t,{method:a.MethodName.set_claim_fee,arguments:[o,i,n],typeArgs:[]})}streamingFee(t,n){let o=this.feeObject();return this.addContractCall(t,{method:a.MethodName.streaming_fee,arguments:[o,n],typeArgs:[]})}claimFee(t,n){return this.addContractCall(t,{method:a.MethodName.claim_fee,arguments:[this.feeObject(),n],typeArgs:[]})}feeDenominator(t){return this.addContractCall(t,{method:a.MethodName.fee_denominator,arguments:[this.feeObject()],typeArgs:[]})}};var Zt=class a extends Fe{constructor(t,n){super(a.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(),i=this.vaultObject(),l=this.makeObject(n.paymentCoin),u=this.makeObject(n.flatFeeCoin),b=this.clockObject();return this.addContractCall(t,{method:a.MethodName.create_stream,arguments:[o,i,l,u,n.metadata,n.recipient,n.timeStart,n.cliff,n.epochInterval,n.numEpoch,n.amountPerEpoch,n.cancelable,b],typeArgs:[n.coinType]})}setAutoClaim(t,n){let o=this.makeObject(n.streamId);return this.addContractCall(t,{method:a.MethodName.set_auto_claim,arguments:[o,n.enabled],typeArgs:[n.coinType]})}cancelStream(t,n){let o=this.makeObject(n.streamId),i=this.clockObject();return this.addContractCall(t,{method:a.MethodName.cancel_stream,arguments:[o,i],typeArgs:[n.coinType]})}claimStream(t,n){let o=this.makeObject(n.streamId),i=this.clockObject();return this.addContractCall(t,{method:a.MethodName.claim_stream,arguments:[o,i],typeArgs:[n.coinType]})}claimStreamByProxy(t,n){let o=this.makeObject(n.streamId),i=this.vaultObject(),l=this.feeObject(),u=this.clockObject();return this.addContractCall(t,{method:a.MethodName.claim_stream_by_proxy,arguments:[o,i,l,u],typeArgs:[n.coinType]})}get createStreamTarget(){return`${this.config.contractId}::${a.ModuleName}::${a.MethodName.create_stream}`}get setAutoClaimTarget(){return`${this.config.contractId}::${a.ModuleName}::${a.MethodName.set_auto_claim}`}get cancelStreamTarget(){return`${this.config.contractId}::${a.ModuleName}::${a.MethodName.cancel_stream}`}get claimStreamTarget(){return`${this.config.contractId}::${a.ModuleName}::${a.MethodName.claim_stream}`}get claimStreamByProxyTarget(){return`${this.config.contractId}::${a.ModuleName}::${a.MethodName.claim_stream_by_proxy}`}};var $e=class{constructor(e){this.globals=e;let t=e.envConfig.contract;this.feeContract=new Ke(t,e),this.streamContract=new Zt(t,e)}feeContract;streamContract;async createStreams(e){let t=Re.convertCreateStreamInfoToInternal(e);return this.createStreamHelper().buildCreateStreamTransactionBlock(t)}createStreamHelper(){return new Re(this.globals,this.feeContract,this.streamContract)}setAutoClaim(e,t,n){let o=new wn.TransactionBlock;return this.streamContract.setAutoClaim(o,{streamId:e,enabled:t,coinType:n})}claimStream(e,t){let n=new wn.TransactionBlock;return this.streamContract.claimStream(n,{streamId:e,coinType:t})}claimStreamByProxy(e,t){let n=new wn.TransactionBlock;return this.streamContract.claimStreamByProxy(n,{streamId:e,coinType:t})}cancelStream(e,t){let n=new wn.TransactionBlock;return this.streamContract.cancelStream(n,{streamId:e,coinType:t}),n}};var Ve=require("@mysten/sui.js/utils"),ji=require("luxon");var Vo=class extends j{constructor(e,t){super(12,`Transaction failed: ${t}`,{context:{status:e,msg:t}})}};var qm=1e3,Ho=class{constructor(e){this.globals=e;this.coinMetaHelper=new Ui(e.suiClient),this.createStreamHelper=new $e(e).createStreamHelper()}coinMetaHelper;createStreamHelper;getStreamIdsFromCreateStreamResponse(e){if(e.effects?.status.status!=="success")throw new Vo(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 H("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,l={realTotalAmount:o*e.steps+n,cliffAmount:n,amountPerStep:o};return this.validateStreamAmount(l,e.totalAmount),l}calculateTimelineByInterval(e){if(e.steps===0n)throw new H("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 H("Invalid stream steps: 0");let t=BigInt(e.total.toMillis())/e.steps,n=e.timeStart.plus(ji.Duration.fromMillis(Number(t*e.steps))),o={timeStart:e.timeStart,timeEnd:n,interval:ji.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,Ve.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,i)=>({...o,coinType:(0,Ve.normalizeStructTag)(o.coinType),coinMeta:n[i]}))}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 H("Stream amount too small","totalAmount",t);if(e.cliffAmount>e.realTotalAmount)throw new H("Invalid cliff settings")}validateTimeline(e){if(e.interval.toMillis()<qm)throw new H("Interval shall be at least 1 second","interval",e.interval)}},Ui=class{constructor(e){this.suiClient=e;this.coinMetaReg=new Map}coinMetaReg;async getCoinMeta(e){let t=(0,Ve.normalizeStructTag)(e||Ve.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"),Gi=require("luxon");var In=require("@mysten/sui.js/transactions"),xn=require("@mysten/sui.js/utils"),jl=require("luxon");var Go=class extends j{constructor(){super(7,"Connected wallet is not creator")}};var Sn=class extends j{constructor(){super(8,"Connected wallet is not recipient")}};var Cn=class extends j{constructor(e,t){super(6,e,{context:t})}};var At=class extends j{constructor(e,t={}){super(0,e,t)}};var zo=class extends j{constructor(e){super(5,"Stream not found",{context:{streamId:e}})}};var Jo=require("luxon"),Ll=(1n<<64n)-1n,Qo=1e3;function qi(a){let e;typeof a=="number"?e=a:typeof a=="bigint"?e=Number(a):e=a.toMillis();let t=Math.round(e/Qo);return Jo.DateTime.fromMillis(t*Qo)}function Fi(a){let e;typeof a=="number"?e=a:typeof a=="bigint"?e=Number(a):e=a.toMillis();let t=Math.round(e/Qo);return Jo.Duration.fromMillis(t*Qo)}var pe=class a{constructor(e,t,n){this.globals=e;this.streamId=t;this.rawData=n;this.streamContract=new Zt(e.envConfig.contract,e)}streamContract;type="Stream";static async new(e,t){let n=await a.fetchStreamData(e,t);return new a(e,t,n)}static fromObjectData(e,t,n){let o=a.parseRawStreamData(t,n);return new a(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 a.fetchStreamData(this.globals,this.streamId)}refreshWithData(e){if(e.data?.objectId!==this.streamId)throw new At("Object Id does not align");this.rawData=a.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 Go;let e=new In.TransactionBlock;return this.streamContract.cancelStream(e,{streamId:this.streamId,coinType:this.coinType}),e}async claim(){if(await this.globals.walletAddress()!==this.recipient)throw new Sn;let e=new In.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 Sn;let t=new In.TransactionBlock;return this.streamContract.setAutoClaim(t,{streamId:this.streamId,coinType:this.coinType,enabled:e}),t}async claimByProxy(){let e=new In.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 Fi(this.rawData.config.epochInterval)}get groupId(){let{metadata:e}=this.rawData.config;return gn(e).groupId}get name(){let{metadata:e}=this.rawData.config;return gn(e).name}get recipient(){return this.rawData.config.recipient}get timeStart(){return qi(this.rawData.config.timeStart)}get duration(){let e=this.rawData.config,t=e.epochInterval*e.totalEpoch;return Fi(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:qi((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===Ll?0n:this.rawData.status.epochClaimed*this.amountPerEpoch+this.cliff}get currentEpoch(){let e=jl.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 a.parseRawStreamData(t,n)}static parseRawStreamData(e,t){if(t.error)throw t.error.code==="notExists"?new zo(e):new Cn(`get stream data: ${t.error.code}`,{streamId:e,...t.error});let n=t.data.content;if(n.dataType!=="moveObject")throw new Cn("Unexpected object type",{gotType:n.dataType});let{typeParams:o}=(0,xn.parseStructTag)(n.type),i=(0,xn.normalizeStructTag)(o[0]),l=n.fields,u=l.config.fields,b=l.status.fields;return{coinType:i,autoClaim:l.auto_claim,balance:BigInt(l.balance.fields.balance),config:{amountPerEpoch:BigInt(u.amount_per_epoch),cancelable:u.cancelable,cliff:BigInt(u.cliff),creator:u.creator,epochInterval:BigInt(u.epoch_interval),metadata:u.metadata,recipient:u.recipient,timeStart:BigInt(u.time_start),totalEpoch:BigInt(u.total_epoch)},status:{status:b.status,epochCanceled:BigInt(b.epoch_canceled),epochClaimed:BigInt(b.epoch_claimed)}}}};var He=class extends j{constructor(e,t){super(9,`Invalid stream group: ${e}`,{context:t})}};async function $i(a){let e=[];for(;await a.hasNext();){let t=await a.next();e.push(t)}return e&&Array.isArray(e[0])?e.flat(1):e}var Ki=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)}},Ge=class{constructor(e){this.requester=e;this.pager=new Ki(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 Fm=25;async function Hi(a,e,t){let n=new kn(e),o=new vn(a,n,t);return await $i(o)}var kn=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]}},vn=class extends Ge{constructor(t,n,o){super(new Vi(t,n,o));this.suiClient=t;this.idIter=n;this.options=o}},Vi=class{constructor(e,t,n){this.suiClient=e;this.stringIter=t;this.options=n;this.filter=n?.filter,this.pageSize=n?.pageSize||Fm,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 i=await this.stringIter.next();i&&e.push(i)}let t=await this.suiClient.multiGetObjects({ids:e,options:this.objectOptions}),n;if(this.filter){let{filter:o}=this;n=t.filter(i=>o?.(i))}else n=t;return{data:n,hasNext:await this.stringIter.hasNext()}}};var Xo=class a{constructor(e,t){this.globals=e;this.streams=t;if(t.length===0)throw new He("stream size 0");let n=t.map(i=>i.groupId);if(new Set(n).size!==1)throw new H("Stream does not have same group ID")}type="StreamGroup";static async new(e,t){let n=await Hi(e.suiClient,t);return n.forEach(o=>{if(!o)throw new At("stream group object data undefined")}),a.newFromObjectResponse(e,t,n)}static async newFromObjectResponse(e,t,n){let o=await a.parseGroupStreams(e,t,n);return new a(e,o)}static checkStreamGroup(e){let t=e.map(i=>i.groupCommonInfo),n=t[0],o=!0;return t.forEach(i=>{Km(n,i)||(o=!1)}),o}async refresh(){let e=await Hi(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((i,l)=>pe.fromObjectData(e,t[l],i)).filter(i=>!!i);if(new Set(o.map(i=>i.groupId)).size!==1)throw new He("Not same group ID");if(!this.checkStreamGroup(o))throw new He("Not same stream settings");return o}};function Km(a,e){return a.name===e.name&&a.groupId===e.groupId&&a.creator===e.creator&&a.start.toMillis()===e.start.toMillis()&&a.interval.toMillis()===e.interval.toMillis()&&a.steps===e.steps&&a.cancelable===e.cancelable}var Dn=class a{constructor(e,t){this.it=e;this.pageSize=t}static async newIncoming(e){let t=await Yo.newIncoming(e);return new a(t,e.pageSize)}static async newOutgoing(e){let t=await Yo.newOutgoing(e);return new a(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}},Yo=class a{constructor(e){this.requester=e}cachedNext;static async newIncoming(e){let t=await Zo.newIncomingQuery(e);return new a(t)}static async newOutgoing(e){let t=await Zo.newOutgoingQuery(e);return new a(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}},Zo=class a{constructor(e,t,n,o){this.globals=e;this.recipient=t;this.groupRefs=n;this.query=o;this.current=0;let i=new kn(n.flat().map(l=>l.streamId));this.objectIter=new vn(e.suiClient,i)}current=0;objectIter;static async newIncomingQuery(e){let t=zm(e.query),n=await e.globals.walletAddress(),i=(await e.globals.backend.getIncomingStreams(n,t)).filter(u=>(0,fe.normalizeSuiAddress)(u.recipient)===(0,fe.normalizeSuiAddress)(n)),l=Ul(i);return new a(e.globals,n,l,e.query)}static async newOutgoingQuery(e){let t=Qm(e.query),n=await e.globals.walletAddress(),o=await e.globals.backend.getOutgoingStreams(n,t),i=Ul(o);return new a(e.globals,n,i,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 Hm(this.globals,e[0].streamId,this.objectIter);return this.current++,ql(t,this.query)?t:this.doNextRequest()}if(e.length>1){let t=await Gm(this.globals,e.map(n=>n.streamId),this.objectIter);return this.current++,Vm(t,this.query)?t:this.doNextRequest()}throw new At("Stream group with no stream")}};function Ul(a){let e=new Map;return a.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)=>Gi.DateTime.fromISO(n[0].createDate).toMillis()-Gi.DateTime.fromISO(t[0].createDate).toMillis())}function ql(a,e){if(e===void 0)return!0;let t=$m(a,e.status);if(e&&"claimable"in e&&e.claimable!==void 0){let n=e.claimable?a.progress.claimable!==0n:a.progress.claimable===0n;return t&&n}return t}function $m(a,e){return e===void 0?!0:Array.isArray(e)?e.includes(a.progress.status):a.progress.status===e}function Vm(a,e){if(!e)return!0;let t=!1;return a.streams.forEach(n=>{ql(n,e)&&(t=!0)}),t}async function Hm(a,e,t){let n=await Fl(t,e);return pe.fromObjectData(a,e,n)}async function Gm(a,e,t){let n=[];for(;n.length<e.length;){let o=await Fl(t,e[n.length]);n.push(o)}return Xo.newFromObjectResponse(a,e,n)}async function Fl(a,e){if(!await a.hasNext())throw new At("object iterator has been consumed");let t=await a.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 zm(a){return{status:zi(a?.status),coinType:Kl(a?.coinType),sender:$l(a?.sender)}}function Qm(a){return{status:zi(a?.status),coinType:Kl(a?.coinType),recipient:$l(a?.recipient)}}function zi(a){return a===void 0||a.length===0?"all":Array.isArray(a)?a.reduce((e,t)=>{let n=zi(t);return!e||e===n?n:"all"},void 0):Jm(a)}function Jm(a){switch(a){case"STREAMING":case"STREAMED":case"CANCELED":return"active";case"COMPLETED":case"SETTLED":return"inactive";default:throw new H("Unknown stream filtered status")}}function Kl(a){if(a)return Array.isArray(a)?a.length!==0?a.map(e=>(0,fe.normalizeStructTag)(e)):void 0:(0,fe.normalizeStructTag)(a)}function $l(a){if(a)return Array.isArray(a)?a.length!==0?a.map(e=>(0,fe.normalizeSuiAddress)(e)):void 0:(0,fe.normalizeSuiAddress)(a)}var ta=class extends j{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 Xm=25;async function Vl(a,e,t,n="0x2::sui::SUI",o=Xm){let i=new Qi(a,e,n,o),l=BigInt(0),u=[];for(;await i.hasNext()&&l<t;){let b=await i.next();b&&(u.push(b),l+=BigInt(b.balance))}if(l<t)throw new ta(n,t,l);return u}var Qi=class extends Ge{constructor(t,n,o,i){super(new Ji(t,n,o,i));this.suiClient=t;this.owner=n;this.coinType=o;this.reqPageSize=i}},Ji=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 Xi=class{constructor(e){this.msafe=e}get type(){return"msafe"}async address(){return this.msafe.address()}async requestCoins(e){return this.msafe.requestCoins(e)}},ea=class{constructor(e){this.account=e}async address(){return this.account.address}},Yi=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(Ko(e.coinType,Be.SUI_TYPE_ARG))return{primaryCoin:$o};if(e.amount<=0)throw new H("Invalid coin request","coinAmount",e.amount);let t=await Vl(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)}}},na=class{globals;helper;constructor(e,t){this.globals=qe.new(e,t),this.helper=new Ho(this.globals)}connectSingleWallet(e){let t=new Yi(e,this.globals.suiClient);this.globals.connectWallet(t)}connectMSafeAccount(e){let t=new Xi(e);this.globals.connectWallet(t)}async createStream(e){return this.builder().createStreams(e)}async getStream(e){return pe.new(this.globals,e)}async getIncomingStreams(e,t=10){return Dn.newIncoming({globals:this.globals,query:e,pageSize:t})}async getOutgoingStreams(e,t=10){return Dn.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,Be.normalizeStructTag)(n))}async getRecipientsForStreamFilter(e){let t=await this.wallet.address();return(await this.globals.backend.getAllRecipients(t,e)).map(o=>(0,Be.normalizeSuiAddress)(o))}async getCreatorsForStreamFilter(e){let t=await this.wallet.address();return(await this.globals.backend.getAllSenders(t,e)).map(o=>(0,Be.normalizeSuiAddress)(o))}get wallet(){return this.globals.wallet}builder(){return new $e(this.globals)}};var Ft=class extends P{application="mpay";getClient(e,t){let n=new na(e==="sui:mainnet"?"prod":"dev");return n.connectSingleWallet(new ea(t)),n}};var An=class extends Ft{constructor(t){super(t);this.data=t}txType=Hl.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 Gl=require("@msafe/sui3-utils");var Mn=class extends Ft{constructor(t){super(t);this.data=t}txType=Gl.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 zl=require("@msafe/sui3-utils");var On=class extends Ft{constructor(t){super(t);this.data=t}txType=zl.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 Ql=require("@msafe/sui3-utils");var Pn=class extends Ft{constructor(t){super(t);this.data=t}txType=Ql.TransactionType.Stream;txSubType="CreateStream";async build(t){let{network:n,account:o}=t;return this.getClient(n,o).createStream(this.data)}};var Zi=require("@mysten/sui.js/bcs"),he=require("@mysten/sui.js/utils"),ze=class a{constructor(e,t){this.moveCall=e;this.txb=t}decodeSharedObjectId(e){let t=this.getInputParam(e);return a.getSharedObjectId(t)}decodeOwnedObjectId(e){let t=this.getInputParam(e);return a.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 a.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 Zi.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 Zi.bcs.de(t,new Uint8Array(n))}typeArg(e){return(0,he.normalizeStructTag)(this.moveCall.typeArguments[e])}txArg(e){return this.moveCall.arguments[e]}};var oa=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"&&me(t.target,this.contract.createStreamTarget));if(e.length===0)throw new At("No create stream transactions");return e.map(t=>new ze(t,this.txb))}getCreationInfoFromMoveCall(e){let t=e.decodeInputString(4),{name:n,groupId:o}=gn(t),i=e.decodeInputAddress(5),l=e.decodeInputU64(6),u=e.decodeInputU64(7),b=e.decodeInputU64(8),T=e.decodeInputU64(9),S=e.decodeInputU64(10),C=e.decodeInputBool(11),I=e.typeArg(0);return{name:n,groupId:o,recipient:i,timeStart:l,cliff:u,epochInterval:b,totalEpoch:T,amountPerEpoch:S,cancelable:C,coinType:I}}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 H("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 Zt(this.globals.envConfig.contract,this.globals)}get feeContract(){return new Ke(this.globals.envConfig.contract,this.globals)}createStreamHelper(){return new Re(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 aa=class{constructor(e,t){this.globals=e;this.txb=t;this.contract=new Zt(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"&&me(t.target,this.contract.createStreamTarget))!==-1}isSetAutoClaimTransaction(){return this.transactions.length===1&&this.transactions[0].kind==="MoveCall"&&me(this.transactions[0].target,this.contract.setAutoClaimTarget)}isCancelStreamTransaction(){return this.transactions.length===1&&this.transactions[0].kind==="MoveCall"&&me(this.transactions[0].target,this.contract.cancelStreamTarget)}isClaimStreamTransaction(){return this.transactions.length===1&&this.transactions[0].kind==="MoveCall"&&me(this.transactions[0].target,this.contract.claimStreamTarget)}isClaimByProxyTransaction(){return this.transactions.length===1&&this.transactions[0].kind==="MoveCall"&&me(this.transactions[0].target,this.contract.claimStreamByProxyTarget)}decodeCreateStreamTransaction(){return new oa(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 ze(e,this.txb)}};var Jl=require("@msafe/sui3-utils");var Rn=class extends Ft{constructor(t){super(t);this.data=t}txType=Jl.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 ra=class{application="mpay";supportSDK="@mysten/sui.js";async deserialize(e){let{network:t,transactionBlock:n}=e,o=qe.new(t==="sui:mainnet"?"prod":"dev"),l=new aa(o,n).decode(),u;switch(l.type){case"CreateStream":u=new Pn(l.info);break;case"SetAutoClaim":u=new Rn({streamId:l.streamId,enabled:l.enabled});break;case"Claim":u=new On({streamId:l.streamId});break;case"ClaimByProxy":u=new Mn({streamId:l.streamId});break;case"Cancel":u=new An({streamId:l.streamId});break;default:throw new Error(`Unknown transaction type: ${l}`)}return{txType:u.txType,txSubType:u.txSubType,intentionData:u.data}}async build(e){let{intentionData:t}=e,n;switch(e.txSubType){case"CreateStream":n=new Pn(t);break;case"Claim":n=new On(t);break;case"ClaimByProxy":n=new Mn(t);break;case"SetAutoClaim":n=new Rn(t);break;case"Cancel":n=new An(t);break;default:throw new Error("not implemented")}return n.build({...e})}};var Bn=require("@msafe/sui3-utils");var Xl=require("@msafe/sui3-utils");var ia=class a extends P{constructor(t){super(t);this.data=t}txType;txSubType;async build(t){let{suiClient:n,account:o}=t;return(0,Xl.buildCoinTransferTxb)(n,this.data,o.address)}static fromData(t){return new a(t)}};var Yl=require("@msafe/sui3-utils");var sa=class a extends P{constructor(t){super(t);this.data=t}txType;txSubType;async build(t){let{suiClient:n,account:o}=t;return(0,Yl.buildObjectTransferTxb)(n,this.data,o.address)}static fromData(t){return new a(t)}};var ca=class{application="msafe-core";supportSDK="@mysten/sui.js";constructor(){this.application=Bn.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 Bn.TransactionSubTypes.assets.coin.send:o=ia.fromData(e.intentionData);break;case Bn.TransactionSubTypes.assets.object.send:o=sa.fromData(e.intentionData);break;default:throw new Error("not implemented")}return o.build({suiClient:t,account:n})}};var uu=require("@msafe/sui3-utils");var Zl=!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 ts(){if(!Zl)try{let a=await fetch("https://open-api.naviprotocol.io/api/msafe").then(i=>i.json()),{packageId:e,borrowFee:t,borrowFeeAddress:n,pool:o}=a;e&&(_n.ProtocolPackage=e),t&&(_n.borrowFee=t),n&&(_n.borrowFeeAddress=n),o&&(_n.pool=o),Zl=!0}catch(a){console.error(a.message)}}var Ht=_n;var be=require("@msafe/sui3-utils"),es=require("@mysten/sui.js/bcs"),ge=require("@mysten/sui.js/utils");var la=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(`${Ht.ProtocolPackage}::incentive_v3::entry_borrow`)}isEntryBorrowWithFeeTransaction(){return!!this.getMoveCallTransaction(`${Ht.ProtocolPackage}::incentive_v3::borrow`)}isEntryMultiDepositTransaction(){let e=`${Ht.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=`${Ht.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(`${Ht.ProtocolPackage}::incentive_v3::entry_deposit`)}isEntryRepayTransaction(){return!!this.getMoveCallTransaction(`${Ht.ProtocolPackage}::incentive_v3::entry_repay`)}isEntryWithdrawTransaction(){return!!this.getMoveCallTransaction(`${Ht.ProtocolPackage}::incentive_v3::withdraw`)}findPoolByAssetId(e){let t=Object.values(Ht.pool).find(n=>n.assetId===e);if(!t)throw new Error("Pool not found");return t}decodeEntryClaimAndDeposit(){return{txType:be.TransactionType.Other,type:"EntryClaimAndDeposit",intentionData:{type:"entry_claim_and_deposit"}}}decodeClaimReward(){return console.log("decode claims"),{txType:be.TransactionType.Other,type:"ClaimReward",intentionData:{type:"claim_reward"}}}decodeEntryBorrow(){let e=this.helper.decodeInputU8(4),t=this.helper.decodeInputU64(5);return{txType:be.TransactionType.Other,type:"EntryBorrow",intentionData:{amount:t,assetId:e}}}decodeEntryMultiDeposit(){let e=[],t=`${Ht.ProtocolPackage}::incentive_v3::entry_deposit`;return this.transactions.forEach(n=>{if(n.kind==="MoveCall"&&n.target===t){let o=new ua(n,this.txb),i=o.decodeInputU8(3),l=o.decodeInputU64(5);e.push({assetId:i,amount:l})}}),{txType:be.TransactionType.Other,type:"EntryMultiDeposit",intentionData:{list:e}}}decodeEntryDeposit(){let e=this.helper.decodeInputU8(3),t=this.helper.decodeInputU64(5);return{txType:be.TransactionType.Other,type:"EntryDeposit",intentionData:{amount:t,assetId:e}}}decodeEntryRepay(){let e=this.helper.decodeInputU8(4),t=this.helper.decodeInputU64(6);return{txType:be.TransactionType.Other,type:"EntryRepay",intentionData:{amount:t,assetId:e}}}decodeEntryWithdraw(){let e=this.helper.decodeInputU8(4),t=this.helper.decodeInputU64(5);return{txType:be.TransactionType.Other,type:"EntryWithdraw",intentionData:{amount:t,assetId:e}}}get helper(){let e=this.transactions.find(t=>t.kind==="MoveCall"&&t.target.startsWith(Ht.ProtocolPackage));return new ua(e,this.txb)}},ua=class a{constructor(e,t){this.moveCall=e;this.txb=t}decodeSharedObjectId(e){let t=this.getInputParam(e);return a.getSharedObjectId(t)}decodeOwnedObjectId(e){let t=this.getInputParam(e);return a.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,ge.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 a.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,ge.normalizeSuiAddress)(e.value.Object.ImmOrOwned.objectId)}return(0,ge.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,ge.normalizeSuiAddress)(e.value);if(!("Object"in e.value)||!("Shared"in e.value.Object))throw new Error("not Shared");return(0,ge.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,ge.normalizeStructTag)(this.moveCall.typeArguments[e])}txArg(e){return this.moveCall.arguments[e]}};var Kt=require("navi-sdk");async function Qe(a,e,t,n){return await(0,Kt.depositCoin)(a,e,t,n),a}async function tu(a,e,t,n){let[o]=await(0,Kt.withdrawCoin)(a,e,t);return a.transferObjects([o],a.pure(n)),a}async function eu(a,e,t,n){let[o]=await(0,Kt.borrowCoin)(a,e,t);return a.transferObjects([o],a.pure.address(n)),a}async function ns(a,e,t,n){return await(0,Kt.repayDebt)(a,e,t,n),a}async function nu(a,e){return await(0,Kt.claimAllRewardsPTB)(a,e)}async function ou(a,e){return await(0,Kt.claimAllRewardsResupplyPTB)(a,e)}var da=class a extends P{constructor(t){super(t);this.data=t}txType;txSubType;async build(t){let{type:n}=this.data;return console.log("claim reward",n),await nu(t.suiClient,t.account.address)}static fromData(t){return new a(t)}};var ma=class a extends P{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 ou(t.suiClient,t.account.address)}static fromData(t){return new a(t)}};var ru=require("@mysten/sui.js/transactions");var au=require("navi-sdk");function te(a){return Object.values(au.pool).find(e=>String(e.assetId)===String(a))}var pa=class a extends P{constructor(t){super(t);this.data=t}txType;txSubType;async build(t){let{assetId:n,amount:o}=this.data,i=new ru.TransactionBlock;console.log("build",this.data);let l=te(n);return await eu(i,l,o,t.account.address)}static fromData(t){return new a(t)}};var iu=require("@mysten/sui.js/transactions");async function Je(a,e,t){let n=await a.getCoins({owner:e,coinType:t});return console.log("getTokenObjs",e,n),n}var fa=class a extends P{constructor(t){super(t);this.data=t}txType;txSubType;async build(t){let{suiClient:n,account:o}=t,{assetId:i,amount:l}=this.data,u=new iu.TransactionBlock;console.log("build",this.data);let b=te(i);if(i===0){let[I]=u.splitCoins(u.gas,[l]);return await Qe(u,b,I,l)}let T=await Je(n,o.address,b.type);if(!T.data[0])throw new Error(`Insufficient balance for ${b.name} Token`);let S=T.data[0].coinObjectId;if(T.data.length>=2){let I=1;for(;I<T.data.length;)u.mergeCoins(S,[T.data[I].coinObjectId]),I++}return await Qe(u,b,u.object(S),l)}static fromData(t){return new a(t)}};var su=require("@mysten/sui.js/transactions");var ha=class a extends P{constructor(t){super(t);this.data=t}txType;txSubType;async build(t){let{suiClient:n,account:o}=t,{assetId:i,amount:l}=this.data,u=new su.TransactionBlock;console.log("build",this.data);let b=te(i);if(i===0){let[C]=u.splitCoins(u.gas,[l]);return ns(u,b,C,l)}let T=await Je(n,o.address,b.type);if(!T.data[0])throw new Error(`Insufficient balance for ${b.name} Token`);let S=T.data[0].coinObjectId;if(T.data.length>=2){let C=1;for(;C<T.data.length;)u.mergeCoins(S,[T.data[C].coinObjectId]),C++}return ns(u,b,u.object(S),l)}static fromData(t){return new a(t)}};var cu=require("@mysten/sui.js/transactions");var ba=class a extends P{constructor(t){super(t);this.data=t}txType;txSubType;async build(t){let{assetId:n,amount:o}=this.data,i=new cu.TransactionBlock;console.log("build",this.data);let l=te(n);return await tu(i,l,o,t.account.address)}static fromData(t){return new a(t)}};var lu=require("@mysten/sui.js/transactions");var ga=class a extends P{constructor(t){super(t);this.data=t}txType;txSubType;async build(t){let{suiClient:n,account:o}=t,{list:i}=this.data,l=new lu.TransactionBlock;console.log("build",this.data);for(let u=0;u<i.length;u++){let{assetId:b,amount:T}=i[u],S=te(b);if(b===0){let[x]=l.splitCoins(l.gas,[T]);await Qe(l,S,x,T);continue}let C=await Je(n,o.address,S.type);if(!C.data[0])throw new Error(`Insufficient balance for ${S.name} Token`);let I=C.data[0].coinObjectId;if(C.data.length>=2){let x=1;for(;x<C.data.length;)l.mergeCoins(I,[C.data[x].coinObjectId]),x++}await Qe(l,S,l.object(I),T)}return l}static fromData(t){return new a(t)}};var ya=class{application="navi";supportSDK="@mysten/sui.js";async deserialize(e){await ts();let{transactionBlock:t}=e,o=new la(t).decode();return{txType:uu.TransactionType.Other,txSubType:o.type,intentionData:o.intentionData}}async build(e){let{suiClient:t,account:n}=e,o;switch(await ts(),e.txSubType){case"EntryDeposit":o=fa.fromData(e.intentionData);break;case"EntryBorrow":o=pa.fromData(e.intentionData);break;case"EntryRepay":o=ha.fromData(e.intentionData);break;case"EntryWithdraw":o=ba.fromData(e.intentionData);break;case"EntryMultiDeposit":o=ga.fromData(e.intentionData);break;case"ClaimReward":o=da.fromData(e.intentionData);break;case"EntryClaimAndDeposit":o=ma.fromData(e.intentionData);break;default:throw new Error("not implemented")}return o.build({suiClient:t,account:n})}};var En=require("@msafe/sui3-utils"),du=require("@mysten/bcs"),mu=require("@mysten/sui/transactions"),pu=Ut(require("sort-keys-recursive")),fu="msafe-plain-tx",hu=En.TransactionSubTypes.others.plain,os=class a{constructor(e){this.data=e}application=fu;txType=En.TransactionType.Other;txSubType=hu;serialize(){return JSON.stringify((0,pu.default)(this.data))}async build(e){return mu.Transaction.from((0,du.fromHex)(this.data.content))}static fromData(e){return new a(e)}},Ta=class{application;supportSDK="@mysten/sui";constructor(){this.application=fu}async deserialize(e){let{content:t}=e.appContext;return{txType:En.TransactionType.Other,txSubType:hu,intentionData:{content:t}}}async build(e){let{suiClient:t,network:n,account:o}=e;return os.fromData(e.intentionData).build({suiClient:t,network:n,account:o})}};var is=require("@mysten/sui/client"),bu=require("@mysten/sui/transactions"),Ca=require("@mysten/sui.js/client"),gu=require("@mysten/sui.js/transactions");var Xe=require("@open-rpc/client-js");var tp={"-32700":"ParseError","-32600":"InvalidRequest","-32601":"MethodNotFound","-32602":"InvalidParams","-32603":"InternalError"},as=class extends Error{},wa=class extends as{code;type;constructor(e,t){super(e),this.code=t,this.type=tp[t]??"ServerError"}};function ep(a){let e=new URL(a);return e.protocol=e.protocol.replace("http","ws"),e.toString()}var np={WebSocketConstructor:typeof WebSocket<"u"?WebSocket:void 0,callTimeout:3e4,reconnectTimeout:3e3,maxReconnects:5},Sa=class{endpoint;options;#n=0;#a=0;#t=null;#e=null;#r=new Set;#o=new Map;constructor(e,t={}){this.endpoint=e,this.options={...np,...t},this.endpoint&&this.endpoint.startsWith("http")&&(this.endpoint=ep(this.endpoint))}async makeRequest(e,t){let n=await this.#i();return new Promise((o,i)=>{this.#n+=1,this.#o.set(this.#n,{resolve:o,reject:i,timeout:setTimeout(()=>{this.#o.delete(this.#n),i(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:i})=>{if(o)throw new wa(o.message,o.code);return i})}#i(){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:i}=this.#o.get(n.id);clearTimeout(i),o(n)}else if("params"in n){let{params:o}=n;this.#r.forEach(i=>{i.subscriptionId===o.subscription&&o.subscription===i.subscriptionId&&i.onMessage(o.result)})}})}),this.#e)}async#s(){return this.#t?.close(),this.#e=null,Promise.allSettled([...this.#r].map(e=>e.subscribe(this)))}async subscribe(e){let t=new rs(e);return this.#r.add(t),await t.subscribe(this),()=>t.unsubscribe(this)}},rs=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 ye=class{rpcClient;websocketClient;constructor({url:e,websocket:{url:t,...n}={},rpc:o}){let i=new Xe.HTTPTransport(o?.url??e,{headers:{"Content-Type":"application/json",...o?.headers}});this.rpcClient=new Xe.Client(new Xe.RequestManager([i])),this.websocketClient=new Sa(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 Ia=class a{apps;constructor(){this.apps=new Map}static fromHelpers(e){let t=new a;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 cs(e))}addHelper(e){this.apps.set(e.application,new ss(e))}getAppHelper(e){let t=this.apps.get(e);if(!t)throw new Error(`${e} not registered`);return t}},ss=class{constructor(e){this.helper=e}async deserialize(e){let t=new is.SuiClient({transport:new ye({url:e.clientUrl,rpc:{url:e.clientUrl}})}),n=new Ca.SuiClient({transport:new ye({url:e.clientUrl,rpc:{url:e.clientUrl}})}),o=await e.transactionBlock.build({client:n}),i=bu.Transaction.from(o);return this.helper.deserialize({...e,suiClient:t,transaction:i})}async build(e){let t=new is.SuiClient({transport:new ye({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 i=await o.build({client:t});return gu.TransactionBlock.from(i)}},cs=class{constructor(e){this.helper=e}async deserialize(e){let t=new Ca.SuiClient({transport:new ye({url:e.clientUrl,rpc:{url:e.clientUrl}})});return this.helper.deserialize({...e,transactionBlock:e.transactionBlock,suiClient:t})}async build(e){let t=new Ca.SuiClient({transport:new ye({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 vu=require("@msafe/sui3-utils"),ps=require("@scallop-io/sui-scallop-sdk");var Mt=require("@msafe/sui3-utils"),ds=require("@scallop-io/sui-scallop-sdk");var yu=require("@mysten/sui/utils"),Te=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"),scoin:this.address.get("scoin.id"),referral:this.address.get("referral.id")}}matchMoveCallCommand(e,t){let{address:n,module:o,name:i}=(0,yu.parseStructTag)(t);return e?e.package===n&&e.module===o&&e.function===i:!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((i,l,u)=>(i[l]=u,i),{}),o=[];return this.commands.forEach(i=>{this.isMoveCall(i)&&i.MoveCall&&t.has(i.MoveCall.package)&&(o[n[i.MoveCall.package]]=i.MoveCall)}),o}hasMoveCallCommand(e){return this.movecallsAsSet.has(e)}};var xa=require("@mysten/sui/bcs"),we=require("@mysten/sui/utils"),ls=class a{constructor(e,t){this.moveCall=e;this.transaction=t;this.cmdIdx=e?.MoveCall?t.getData().commands.findIndex(n=>{if(n.$kind==="MoveCall"){let o=`${n.MoveCall.package}::${n.MoveCall.module}::${n.MoveCall.function}`,i=`${e.MoveCall.package}::${e.MoveCall.module}::${e.MoveCall.function}`;return o===i}return!1}):-1}cmdIdx;get txBlockTransactions(){return this.transaction.blockData.transactions[this.cmdIdx]}decodeSharedObjectId(e){let t=this.getInputParam(e);return a.getSharedObjectId(t)}decodeOwnedObjectId(e){let t=this.getInputParam(e);return a.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,we.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 a.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=xa.bcs[t];return xa.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,we.normalizeSuiAddress)(e.value.Object.ImmOrOwned.objectId)}return(0,we.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,we.normalizeSuiAddress)(e.value);if(!("Object"in e.value)||!("Shared"in e.value.Object))throw new Error("not Shared");return(0,we.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 xa.bcs.U64.parse(new Uint8Array(t))}typeArg(e){return(0,we.normalizeStructTag)(this.txBlockTransactions.typeArguments[e])}txArg(e){return this.transaction.blockData.inputs[e]}},N=ls;var us=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)}},Rt=us;var Se=require("@mysten/sui/utils"),Tu=async(a,e)=>{let t=await a.suiKit.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 i=a.address.get("borrowIncentive.object");return o===`${i.slice(2)}::incentive_account::IncentiveProgramLockKey`},Ye={id:"0xc63072e7f5f4983a2efaf5bdba1480d5e7d74d57948e1c7cc436f8e22cbeb410",incentivePools:"0x64972b713ccec45ec3964809e477cea6f97350c0c50ca3aec85bb631639266ec",incentiveAccounts:"0x3c0b707068bdcea8bb859d751ad3e2149a9f83c13fcf4054ef91372a00bccdd3"},$t={unstakeObligation:(a,e,t)=>a.moveCall(`${Ye.id}::user::unstake`,[Ye.incentivePools,Ye.incentiveAccounts,a.object(e),a.object(t),Se.SUI_CLOCK_OBJECT_ID],[(0,Se.normalizeStructTag)(Se.SUI_TYPE_ARG)]),redeem_rewards:(a,e,t,n)=>a.moveCall(`${Ye.id}::user::redeem_rewards`,[Ye.incentivePools,Ye.incentiveAccounts,a.object(e),a.object(t),Se.SUI_CLOCK_OBJECT_ID],[(0,Se.normalizeStructTag)(n)])};var ka=class extends Te{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`);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`);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`),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`));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 Rt(t,this.transaction).getAmountInput().reduce((o,i)=>o+i,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 Rt(t,this.transaction).getAmountInput().reduce((o,i)=>o+i,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 Rt(t,this.transaction).getAmountInput().reduce((o,i)=>o+i,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 Rt(t,this.transaction).getAmountInput().reduce((i,l)=>i+l,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),i=this.helperBorrow.decodeOwnedObjectId(2);return{txType:Mt.TransactionType.Other,type:"BorrowWithBoost",intentionData:{amount:n,coinName:e,obligationKey:i,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),i=this.helperBorrowWithReferral.decodeOwnedObjectId(2);return{txType:Mt.TransactionType.Other,type:"BorrowWithReferral",intentionData:{amount:n,coinName:e,obligationKey:i,obligationId:o,veScaKey:t}}}decodeRepay(){let e=this.utils.parseCoinNameFromType(this.helperRepay.typeArg(0)),t=this.helperRepay.getNestedInputParam(3),n=new Rt(t,this.transaction).getAmountInput().reduce((i,l)=>i+l,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 Rt(n,this.transaction).getAmountInput().reduce((l,u)=>l+u,0),i=this.helperRepay.decodeSharedObjectId(1);return{txType:Mt.TransactionType.Other,type:"RepayWithBoost",intentionData:{amount:o,obligationId:i,coinName:e,veScaKey:t}}}decodeStakeSpool(){let e;this.isCreateStakeAccountTransaction()||(e=this.helperStake.decodeOwnedObjectId(1));let t=0;if(this.helperBurnScoin.moveCall){let i=this.helperBurnScoin.getNestedInputParam(1);t=new Rt(i,this.transaction).getAmountInput().reduce((l,u)=>l+u,0)}if(this.helperStake.moveCall&&t===0){let i=this.helperStake.getNestedInputParam(2);t=new Rt(i,this.transaction).getAmountInput().reduce((l,u)=>l+u,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 Rt(t,this.transaction).getAmountInput().reduce((i,l)=>i+l,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 i=o.decodeOwnedObjectId(1),l=o.decodeInputU64(2);e.push({id:i,coin:l})});let t=this.utils.parseCoinNameFromType(this.helperRedeems[0].typeArg(0)),n=0;if(this.helperBurnScoin.moveCall){let o=this.helperBurnScoin.getNestedInputParam(1);n=new Rt(o,this.transaction).getAmountInput().reduce((i,l)=>i+l,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 i=o.decodeOwnedObjectId(2),l=o.typeArg(0),u=this.utils.parseCoinNameFromType(l);e.push({stakeMarketCoinName:u,stakeAccountId:i})}),this.helperClaimBorrowV2Reward.forEach(o=>{let i=o.decodeSharedObjectId(4),l=o.decodeOwnedObjectId(3),u=this.utils.parseCoinNameFromType(o.typeArg(0));t.push({obligationId:l,obligationKey:i,rewardCoinName:u})}),this.helperClaimBorrowReward.forEach(o=>{let i=o.decodeSharedObjectId(2),l=o.decodeOwnedObjectId(3),u=this.utils.parseCoinNameFromType(o.typeArg(0));n.push({obligationId:l,obligationKey:i,rewardCoinName:u})}),{txType:Mt.TransactionType.Other,type:"ClaimIncentiveReward",intentionData:{lendingIncentive:e,borrowIncentiveV2:t,borrowIncentive:n}}}};var va=require("@msafe/sui3-utils");var Da=class extends Te{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:va.TransactionType.Other,type:"CreateReferralLink",intentionData:{}}}decodeClaimRevenueReferral(){let e=this.helperClaimRevenueReferral[0].decodeOwnedObjectId(2),t=this.helperClaimRevenueReferral.map(n=>n.typeArg(0));return{txType:va.TransactionType.Other,type:"ClaimRevenueReferral",intentionData:{veScaKey:e,coins:t}}}decodeBindReferral(){let e=this.helperBindReferral.decodePureArg(1,"Address");return{txType:va.TransactionType.Other,type:"BindReferral",intentionData:{veScaKey:e}}}};var Ze=require("@msafe/sui3-utils"),wu=require("@scallop-io/sui-scallop-sdk");var Aa=class extends Te{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()}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`)}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,`${wu.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`));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`));return new N(e,this.transaction)}decodeRedeemSca(){let e=this.helperRedeemSca.decodeOwnedObjectId(1);return{txType:Ze.TransactionType.Other,type:"RedeemSca",intentionData:{veScaKey:e}}}decodeRenewExpiredVeSca(){let e=this.helperRenewExpired.getNestedInputParam(4),t=this.helperRenewExpired.decodeInputU64(5),n=new Rt(e,this.transaction).getAmountInput().reduce((v,O)=>v+O,0),o=this.helperRenewExpired.decodeOwnedObjectId(1),i=!!this.helperRedeemSca.moveCall,l=[],u=[],b=[];this.helperOldUnstakeObligation.moveCall&&(l=[this.helperOldUnstakeObligation.decodeOwnedObjectId(2),this.helperOldUnstakeObligation.decodeSharedObjectId(3)]),this.helperUnstakeObligation.moveCall&&(u=[this.helperUnstakeObligation.decodeOwnedObjectId(3),this.helperUnstakeObligation.decodeSharedObjectId(4)]),this.helperStakeObligationWithVeSca.moveCall&&(b=[this.helperStakeObligationWithVeSca.decodeOwnedObjectId(3),this.helperStakeObligationWithVeSca.decodeSharedObjectId(4)]);let T=!1,S=!1,C,I,x=[{condition:l,isOld:!0},{condition:u,isOld:!1},{condition:b,isOld:!1}];for(let v=0;v<x.length;v++)x[v].condition.length>1&&([I,C]=x[v].condition,T=!0,S=x[v].isOld);return{txType:Ze.TransactionType.Other,type:"RenewExpStakePeriod",intentionData:{amount:n,unlockTime:t,obligationId:C,obligationKey:I,veScaKey:o,isHaveRedeem:i,isObligationLocked:T,isOldBorrowIncentive:S}}}decodeExtendStakePeriod(){let e=this.helperExtendStakePeriod.decodeInputU64(4),t=this.helperExtendStakePeriod.decodeOwnedObjectId(1),n=[],o=[],i=[];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&&(i=[this.helperStakeObligationWithVeSca.decodeOwnedObjectId(3),this.helperStakeObligationWithVeSca.decodeSharedObjectId(4)]);let l=!1,u=!1,b,T,S=[{condition:n,isOld:!0},{condition:o,isOld:!1},{condition:i,isOld:!1}];for(let C=0;C<S.length;C++)S[C].condition.length>1&&([T,b]=S[C].condition,l=!0,u=S[C].isOld);return{txType:Ze.TransactionType.Other,type:"ExtendStakePeriod",intentionData:{unlockTime:e,obligationId:b,obligationKey:T,veScaKey:t,isObligationLocked:l,isOldBorrowIncentive:u}}}decodePeriodAndStakeMoreSca(){let e=this.helperStakeMoreSca.getNestedInputParam(4),t=this.helperExtendStakePeriod.decodeInputU64(4),n=new Rt(e,this.transaction).getAmountInput().reduce((x,v)=>x+v,0),o=[],i=[],l,u=[];this.helperOldUnstakeObligation.moveCall&&(o=[this.helperOldUnstakeObligation.decodeOwnedObjectId(2),this.helperOldUnstakeObligation.decodeSharedObjectId(3)]),this.helperUnstakeObligation.moveCall&&(i=[this.helperUnstakeObligation.decodeOwnedObjectId(3),this.helperUnstakeObligation.decodeSharedObjectId(4)]),this.helperStakeMoreSca.moveCall&&(l=this.helperStakeMoreSca.decodeOwnedObjectId(1)),this.helperStakeObligationWithVeSca.moveCall&&(u=[this.helperStakeObligationWithVeSca.decodeOwnedObjectId(3),this.helperStakeObligationWithVeSca.decodeSharedObjectId(4)]);let b=!1,T=!1,S,C,I=[{condition:o,isOld:!0},{condition:i,isOld:!1},{condition:u,isOld:!1}];for(let x=0;x<I.length;x++)I[x].condition.length>1&&([C,S]=I[x].condition,b=!0,T=I[x].isOld);return{txType:Ze.TransactionType.Other,type:"ExtendPeriodAndStakeMore",intentionData:{amount:n,veScaKey:l,unlockTime:t,obligationId:S,obligationKey:C,isOldBorrowIncentive:T,isObligationLocked:b}}}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 Rt(e,this.transaction).getAmountInput().reduce((x,v)=>x+v,0),o=[],i=[],l,u=[];this.helperOldUnstakeObligation.moveCall&&(o=[this.helperOldUnstakeObligation.decodeOwnedObjectId(2),this.helperOldUnstakeObligation.decodeSharedObjectId(3)]),this.helperUnstakeObligation.moveCall&&(i=[this.helperUnstakeObligation.decodeOwnedObjectId(3),this.helperUnstakeObligation.decodeSharedObjectId(4)]),this.helperStakeMoreSca.moveCall&&(l=this.helperStakeMoreSca.decodeOwnedObjectId(1)),this.helperStakeObligationWithVeSca.moveCall&&(u=[this.helperStakeObligationWithVeSca.decodeOwnedObjectId(3),this.helperStakeObligationWithVeSca.decodeSharedObjectId(4)]);let b=!1,T=!1,S,C,I=[{condition:o,isOld:!0},{condition:i,isOld:!1},{condition:u,isOld:!1}];for(let x=0;x<I.length;x++)I[x].condition.length>1&&([C,S]=I[x].condition,b=!0,T=I[x].isOld);return{txType:Ze.TransactionType.Other,type:"StakeSca",intentionData:{amount:n,unlockTime:t,obligationId:S,obligationKey:C,veScaKey:l,isObligationLocked:b,isOldBorrowIncentive:T}}}};var Su=Ut(require("sort-keys-recursive")),R=class{constructor(e){this.data=e}get application(){return"msafe-core"}serialize(){return JSON.stringify((0,Su.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:i,obligationKey:l}=t;return await this.isObligationLocked(e.suiKit.client(),i)?(await o.unstakeObligationQuick(i,l),await n(e,o,t),await o.stakeObligationWithVeScaQuick(i,l,t.veScaKey)):await n(e,o,t),o}};var Ma=class a extends R{constructor(t){super(t);this.data=t}txType;txSubType;async borrow({account:t,scallopClient:n}){let{coinName:o,amount:i,obligationId:l,obligationKey:u}=this.data,b=t.address;return(await this.buildTxWithRefreshObligation(n,{walletAddress:b,obligationId:l,obligationKey:u},async(S,C)=>{let I=await C.borrowQuick(+i,o,l,u);C.transferObjects([I],b)})).txBlock}async build(t){return this.borrow(t)}static fromData(t){return new a(t)}};var Oa=class a extends R{constructor(t){super(t);this.data=t}txType;txSubType;async borrowWithBoost(t,n,o){let{obligationId:i,obligationKey:l,veScaKey:u,amount:b,coinName:T}=this.data;return(await this.buildTxWithRefreshObligation(t,{walletAddress:o,obligationId:i,obligationKey:l,veScaKey:u},async(C,I)=>{let x=await I.borrowQuick(+b,T,i,l);I.transferObjects([x],o)})).txBlock}async build(t){return this.borrowWithBoost(t.scallopClient,this.data,t.account.address)}static fromData(t){return new a(t)}};var Pa=class a extends R{constructor(t){super(t);this.data=t}txType;txSubType;async borrowWithReferral({account:t,scallopClient:n}){let o=t.address,{obligationId:i,obligationKey:l,veScaKey:u,coinName:b,amount:T}=this.data;return(await this.buildTxWithRefreshObligation(n,{walletAddress:o,obligationId:i,obligationKey:l,veScaKey:u},async(C,I)=>{let x=I.claimReferralTicket(b),v=await I.borrowWithReferralQuick(+T,b,x,i,l);I.burnReferralTicket(x,b),I.transferObjects([v],o)})).txBlock}async build(t){return this.borrowWithReferral(t)}static fromData(t){return new a(t)}};var Cu=require("@mysten/sui/utils");var Ra=class a extends R{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),i=await e.query.getLendings(void 0,t),l=await e.query.getObligations(t),u=Object.values(await e.query.getObligationAccounts(t)??[]),b=(()=>{let I=[...e.constants.whitelist.spool].map(x=>e.utils.parseCoinName(x));return Object.values(i??[]).filter(x=>!!x&&I.includes(x.coinName)).reduce((x,v)=>{let O=e.utils.parseMarketCoinName(v.coinName);return x[O]||(x[O]=0),x[O]+=v.availableClaimCoin,x},{})})(),T={};Object.entries(o).forEach(([I,x])=>{for(let v=0;v<x.length;v++){let O=x[v];if(!b[I])continue;let L=n.claim(O.id,I);T.sui?T.sui.push(L):T.sui=[L]}});let S=(()=>{let I={};return I.sui=Object.values(b).reduce((x,v)=>x+v,0),u.forEach(x=>{Object.values(x.borrowIncentives).forEach(v=>{v&&v.rewards.forEach(O=>{I[O.coinName]||(I[O.coinName]=0),I[O.coinName]?I[O.coinName]+=O.availableClaimCoin:I[O.coinName]=O.availableClaimCoin})})}),I})();if(l.length>0&&u.length>0)for(let I=0;I<u.length;I++){let x=u[I],v=!1,O=l.find($=>$.id===x.obligationId)?.keyId,L={};if(O){if(Object.values(x.borrowIncentives).forEach($=>{if($){let Wt=$.rewards.filter(Bt=>{let _t=Bt.coinName;return Bt.availableClaimCoin>0&&!L[_t]});v=Wt.length>0,Wt.forEach(Bt=>{let _t=n.claimBorrowIncentive(x.obligationId,O,Bt.coinName);L[Bt.coinName]=!0,T[Bt.coinName]?T[Bt.coinName].push(_t):T[Bt.coinName]=[_t]})}}),S.sui>0){let $=$t.redeem_rewards(n,O,x.obligationId,Cu.SUI_TYPE_ARG);T.sui?T.sui.push($):T.sui=[$]}if(v&&await Tu(e.query,x.obligationId)){n.unstakeObligation(x.obligationId,O);let Wt=await e.query.getBindedVeScaKey(x.obligationId);Wt?n.stakeObligationWithVesca(x.obligationId,O,Wt):n.stakeObligation(x.obligationId,O)}}}let C=(await Promise.all(Object.entries(T).map(async([I,x])=>{let v=x[0];if(x.length>1&&n.mergeCoins(v,x.slice(1)),I==="sui"){n.mergeCoins(n.gas,[v]);return}return await e.builder.utils.mergeSimilarCoins(n,v,e.utils.parseCoinType(I),t),v}))).filter(I=>!!I);return C.length>0&&n.transferObjects(C,t),n.txBlock}async build(e){return this.claimIncentiveRewards(e.scallopClient,e.account.address)}static fromData(e={}){return new a(e)}};var Ba=class a extends R{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 a(t)}};var _a=class a extends R{constructor(t){super(t);this.data=t}txType;txSubType;async migrateAndClaim({account:t,scallopClient:n}){let o=t.address,{obligationKey:i,obligationId:l,rewardCoinName:u,veScaKey:b}=this.data,T=n.builder.createTxBlock();T.setSender(o);let S=$t.redeem_rewards(T,i,l,n.utils.parseCoinType(u));return T.transferObjects([S],o),await T.unstakeObligationQuick(l,i),b?await T.stakeObligationWithVeScaQuick(l,i,b):await T.stakeObligationQuick(l,i),T.txBlock}async build(t){return this.migrateAndClaim(t)}static fromData(t){return new a(t)}};var Ea=class a extends R{constructor(t){super(t);this.data=t}txType;txSubType;async build(t){return t.scallopClient.migrateAllMarketCoin(!1,!1)}static fromData(t){return new a(t)}};var Na=class a extends R{constructor(t){super(t);this.data=t}txType;txSubType;async build(t){return t.scallopClient.openObligation(!1)}static fromData(t){return new a(t)}};var Wa=class a extends R{constructor(t){super(t);this.data=t}txType;txSubType;async repay({account:t,scallopClient:n}){let o=t.address,{coinName:i,amount:l,obligationId:u,obligationKey:b}=this.data;return(await this.buildTxWithRefreshObligation(n,{walletAddress:o,obligationId:u,obligationKey:b},async(S,C)=>{await C.repayQuick(+l,i,u)})).txBlock}async build(t){return this.repay(t)}static fromData(t){return new a(t)}};var La=class a extends R{constructor(t){super(t);this.data=t}txType;txSubType;async repayWithBoost({account:t,scallopClient:n}){let o=t.address,{coinName:i,amount:l,obligationId:u,veScaKey:b}=this.data,T=n.builder.createTxBlock();T.setSender(o);let S=n.constants.whitelist.borrowing.has(i);return S&&await T.unstakeObligationQuick(u,void 0),await T.repayQuick(+l,i,u),S&&await T.stakeObligationWithVeScaQuick(u,void 0,b),T.txBlock}async build(t){return this.repayWithBoost(t)}static fromData(t){return new a(t)}};var ja=class a extends R{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 a(t)}};var Ua=class a extends R{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 a(t)}};var qa=class a extends R{constructor(t){super(t);this.data=t}txType;txSubType;async unstakeAndWithdraw(t,n,o){let i=t.builder.createTxBlock();i.setSender(o);let{stakeAccountId:l,amount:u,coinName:b}=this.data,T=[];for(let S=0;S<l.length;S++){let{id:C,coin:I}=l[S],x=t.utils.parseMarketCoinName(b),[v]=await i.unstakeQuick(I,x,C);if(v){let O=i.withdraw(v,b);T.push(O)}}if(u>0){let S=await i.withdrawQuick(u,b);T.push(S)}return T.length>1&&i.mergeCoins(T[0],T.slice(1)),i.transferObjects(T,o),i.txBlock}async build(t){return this.unstakeAndWithdraw(t.scallopClient,this.data,t.account.address)}static fromData(t){return new a(t)}};var Fa=class a extends R{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 a(t)}};var Ka=class a extends R{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 a(t)}};var $a=class a extends R{constructor(t){super(t);this.data=t}txType;txSubType;async bindReferral({account:t,scallopClient:n}){let o=t.address,i=n.builder.createTxBlock();return i.setSender(o),i.bindToReferral(this.data.veScaKey),i.txBlock}async build(t){return this.bindReferral(t)}static fromData(t){return new a(t)}};var Va=class a extends R{constructor(t){super(t);this.data=t}txType;txSubType;async claimRevenueReferral({account:t,scallopClient:n}){let{veScaKey:o,coins:i}=this.data,l=t.address,u=n.builder.createTxBlock();u.setSender(l);let b=i.map(T=>n.utils.parseCoinNameFromType(T));return await u.claimReferralRevenueQuick(o,b),u.txBlock}async build(t){return this.claimRevenueReferral(t)}static fromData(t){return new a(t)}};var Ha=class a extends R{constructor(t){super(t);this.data=t}txType;txSubType;async createReferralLink({account:t,scallopClient:n}){let o=t.address,i=n.builder.createTxBlock();i.setSender(o);let l=i.mintEmptyVeSca();return i.transferObjects([l],o),i.txBlock}async build(t){return this.createReferralLink(t)}static fromData(t){return new a(t)}};var Iu=require("@scallop-io/sui-scallop-sdk");var Ga=class a extends R{constructor(t){super(t);this.data=t}txType;txSubType;async extendPeriodAndStakeMoreSca({account:t,scallopClient:n}){let{amount:o,veScaKey:i,unlockTime:l,obligationId:u,obligationKey:b,isOldBorrowIncentive:T,isObligationLocked:S}=this.data,C=t.address,I=n.builder.createTxBlock();I.setSender(C);let x=await n.utils.selectCoins(o,Iu.SCA_COIN_TYPE,C),[v,O]=I.takeAmountFromCoins(x,o);return I.extendLockPeriod(i,l),I.extendLockAmount(i,v),I.transferObjects([O],C),!u||!b||(S&&(T?$t.unstakeObligation(I,u,b):I.unstakeObligation(u,b)),I.stakeObligationWithVesca(u,b,i)),I.txBlock}async build(t){return this.extendPeriodAndStakeMoreSca(t)}static fromData(t){return new a(t)}};var za=class a extends R{constructor(t){super(t);this.data=t}txType;txSubType;async extendStakeScaLockPeriod({account:t,scallopClient:n}){let o=t.address,{veScaKey:i,unlockTime:l,obligationId:u,obligationKey:b,isObligationLocked:T,isOldBorrowIncentive:S}=this.data,C=n.builder.createTxBlock();return C.setSender(o),C.extendLockPeriod(i,l),u&&b&&(T&&(S?$t.unstakeObligation(C,b,u):C.unstakeObligation(u,b)),C.stakeObligationWithVesca(u,b,i)),C.txBlock}async build(t){return this.extendStakeScaLockPeriod(t)}static fromData(t){return new a(t)}};var Qa=class a extends R{constructor(t){super(t);this.data=t}txType;txSubType;async redeemSca({account:t,scallopClient:n}){let{veScaKey:o}=this.data,i=t.address,l=n.builder.createTxBlock();return l.setSender(i),await l.redeemScaQuick(o),l.txBlock}async build(t){return this.redeemSca(t)}static fromData(t){return new a(t)}};var xu=require("@scallop-io/sui-scallop-sdk");var Ja=class a extends R{constructor(t){super(t);this.data=t}txType;txSubType;async renewExpiredStakeSca({account:t,scallopClient:n}){let o=t.address,{amount:i,unlockTime:l,vescaKey:u,isHaveRedeem:b,obligation:T,obligationKey:S,isObligationLocked:C,isOldBorrowIncentive:I}=this.data,x=n.builder.createTxBlock();if(x.setSender(o),b){let $=x.redeemSca(u);x.transferObjects([$],o)}let v=await n.builder.utils.selectCoins(i,xu.SCA_COIN_TYPE,o),[O,L]=x.takeAmountFromCoins(v,i);return x.transferObjects([L],o),x.renewExpiredVeSca(u,O,l),!T||!S||(C&&(I?$t.unstakeObligation(x,S,T):x.unstakeObligation(T,S)),x.stakeObligationWithVesca(T,S,u)),x.txBlock}async build(t){return this.renewExpiredStakeSca(t)}static fromData(t){return new a(t)}};var ku=require("@scallop-io/sui-scallop-sdk");var Xa=class a extends R{constructor(t){super(t);this.data=t}txType;txSubType;async stakeSca({account:t,scallopClient:n}){let o=t.address,{amount:i,isObligationLocked:l,isOldBorrowIncentive:u,obligationId:b,obligationKey:T,unlockTime:S,veScaKey:C}=this.data,I=n.builder.createTxBlock();I.setSender(o);let x=await n.utils.selectCoins(i,ku.SCA_COIN_TYPE,o),[v,O]=I.takeAmountFromCoins(x,i),L;return C?I.extendLockAmount(C,v):L=I.lockSca(v,S),b&&T&&(l&&(u?$t.unstakeObligation(I,T,b):I.unstakeObligation(b,T)),I.stakeObligationWithVesca(b,T,C||L)),C||I.transferObjects([L,O],o),I.txBlock}async build(t){return this.stakeSca(t)}static fromData(t){return new a(t)}};var Ya=class a extends R{constructor(t){super(t);this.data=t}txType;txSubType;async supplyAndStake({account:t,scallopClient:n}){let o=t.address,{amount:i,coinName:l,stakeAccountId:u}=this.data,b=n.builder.createTxBlock();b.setSender(o);let T=await b.depositQuick(+i,l),S=n.utils.parseMarketCoinName(l);if(n.constants.whitelist.spool.has(S))return b.txBlock;let C=await n.query.getStakeAccounts(S,o),I=u||(C.length>0?C[0].id:void 0);if(I)await b.stakeQuick(T,S,I);else{let x=b.createStakeAccount(S);await b.stakeQuick(T,S,x),b.transferObjects([x],o)}return b.txBlock}async build(t){return this.supplyAndStake(t)}static fromData(t){return new a(t)}};var Za=class a extends R{constructor(t){super(t);this.data=t}txType;txSubType;async withdrawUnlockedSca({account:t,scallopClient:n}){let{vescaKey:o}=this.data,i=t.address,l=n.builder.createTxBlock();return l.setSender(i),await l.redeemScaQuick(o),l.txBlock}async build(t){return this.withdrawUnlockedSca(t)}static fromData(t){return new a(t)}};var tr=class{application="scallop";supportSDK="@mysten/sui";scallopClient;async deserialize(e){if(!this.scallopClient){let u=new ps.Scallop({addressId:"67c44a103fe1b8c454eb9699",walletAddress:e.account.address,suiClients:[e.suiClient]});this.scallopClient=await u.createScallopClient()}let{transaction:t}=e;console.log("transaction",t);let n=new ka(t,this.scallopClient),o=new Da(t,this.scallopClient),i=new Aa(t,this.scallopClient),l=n.decode()||o.decode()||i.decode();if(!l)throw new Error("Unknown transaction type");return{txType:vu.TransactionType.Other,txSubType:l.type,intentionData:l.intentionData}}async build(e){let{suiClient:t,account:n,network:o,txSubType:i,intentionData:l}=e;if(!this.scallopClient){let b=new ps.Scallop({addressId:"67c44a103fe1b8c454eb9699",walletAddress:e.account.address,suiClients:[e.suiClient]});this.scallopClient=await b.createScallopClient()}let u;switch(i){case"SupplyLending":u=ja.fromData(l);break;case"WithdrawLending":u=Ka.fromData(l);break;case"Borrow":u=Ma.fromData(l);break;case"Repay":u=Wa.fromData(l);break;case"DepositCollateral":u=Ba.fromData(l);break;case"WithdrawCollateral":u=Fa.fromData(l);break;case"OpenObligation":u=Na.fromData(l);break;case"UnstakeSpool":u=Ua.fromData(l);break;case"ClaimIncentiveReward":u=Ra.fromData(l);break;case"BorrowWithBoost":u=Oa.fromData(l);break;case"StakeSca":u=Xa.fromData(l);break;case"ExtendStakePeriod":u=za.fromData(l);break;case"ExtendPeriodAndStakeMore":u=Ga.fromData(l);break;case"RenewExpStakePeriod":u=Ja.fromData(l);break;case"WithdrawStakedSca":u=Za.fromData(l);break;case"SupplyAndStakeLending":u=Ya.fromData(l);break;case"WithdrawAndUnstakeLending":u=qa.fromData(l);break;case"RedeemSca":u=Qa.fromData(l);break;case"MigrateAndClaim":u=_a.fromData(l);break;case"BorrowWithReferral":u=Pa.fromData(l);break;case"CreateReferralLink":u=Ha.fromData(l);break;case"ClaimRevenueReferral":u=Va.fromData(l);break;case"BindReferral":u=$a.fromData(l);break;case"MigrateScoin":u=Ea.fromData(l);break;case"RepayWithBoost":u=La.fromData(l);break;default:throw new Error("not implemented")}return u.build({suiClient:t,account:n,network:o,scallopClient:this.scallopClient})}};var zu=require("@msafe/sui3-utils");var on=require("@msafe/sui3-utils"),Ie=require("@mysten/sui/utils");var Lu=require("@suilend/springsui-sdk/client");var Wu=require("@msafe/sui3-utils"),Ce=require("@suilend/sdk");var Ee=require("@msafe/sui3-utils"),en=require("@mysten/bcs"),tn=require("@mysten/sui/utils"),Ne=require("@suilend/frontend-sui"),fs=Ut(require("bignumber.js"));var er=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,tn.normalizeStructTag)(e.MintEvent.parsedJson.coin_type.name),n=e.MintEvent.parsedJson.liquidity_amount;return console.log("Decoder.decodeDeposit",t,n),{txType:Ee.TransactionType.Other,type:"deposit",intentionData:{coinType:t,value:n}}}decodeWithdraw(){let e={withdraw_ctokens:this.getMoveCallCommand("withdraw_ctokens")},t={RedeemEvent:this.simResult.events.find(b=>b.type.includes("lending_market::RedeemEvent"))},n=(0,tn.normalizeStructTag)(t.RedeemEvent.parsedJson.coin_type.name),o=t.RedeemEvent.parsedJson.liquidity_amount;console.log("Decoder.decodeWithdraw",n,o);let i=e.withdraw_ctokens.MoveCall.arguments[4].Input,l=new fs.default((0,en.toHex)((0,en.fromBase64)(this.inputs[i].Pure.bytes)),16).toString(),u=l===Ne.MAX_U64.toString();return console.log("decodeWithdraw - isMax:",u,"inputIndex:",i,"inputValue:",l,"MAX_U64.toString():",Ne.MAX_U64.toString()),u&&(o=Ne.MAX_U64.toString()),{txType:Ee.TransactionType.Other,type:"withdraw",intentionData:{coinType:n,value:o}}}decodeBorrow(){let e={borrow_request:this.getMoveCallCommand("borrow_request")},t={BorrowEvent:this.simResult.events.find(b=>b.type.includes("lending_market::BorrowEvent"))},n=(0,tn.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 i=e.borrow_request.MoveCall.arguments[4].Input,l=new fs.default((0,en.toHex)((0,en.fromBase64)(this.inputs[i].Pure.bytes)),16).toString(),u=l===Ne.MAX_U64.toString();return console.log("decodeBorrow - isMax:",u,"inputIndex:",i,"inputValue:",l,"MAX_U64.toString():",Ne.MAX_U64.toString()),u&&(o=Ne.MAX_U64.toString()),{txType:Ee.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,tn.normalizeStructTag)(e.RepayEvent.parsedJson.coin_type.name),n=e.RepayEvent.parsedJson.liquidity_amount;return console.log("Decoder.decodeRepay",t,n),{txType:Ee.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],i=(0,tn.normalizeStructTag)(o.parsedJson.coin_type.name),l=o.parsedJson.liquidity_amount;t[i]=`${+(t[i]??"0")+ +l}`}return console.log("Decoder.decodeClaimRewards",t),{txType:Ee.TransactionType.Other,type:"claim",intentionData:{value:t}}}decodeClaimAndDeposit(){return{txType:Ee.TransactionType.Other,type:"claimAndDeposit",intentionData:this.decodeClaim().intentionData}}};var Au=require("@mysten/sui/transactions");var Du=Ut(require("sort-keys-recursive")),Nt=class{constructor(e){this.data=e}serialize(){return JSON.stringify((0,Du.default)(this.data))}};var nr=class a extends Nt{constructor(t){super(t);this.data=t}txType;txSubType;async build(t){let{suiClient:n,account:o,suilendClient:i,obligationOwnerCap:l,obligation:u}=t;if(console.log("BorrowIntention.build",n,o,i,l,u),!l||!u)throw new Error("Obligation not found");let b=new Au.Transaction;return await i.borrowAndSendToUser(o.address,l.id,u.id,this.data.coinType,this.data.value,b),b}static fromData(t){return console.log("BorrowIntention.fromData",t),new a(t)}};var Ru=require("@mysten/sui/transactions");var Mu=require("@mysten/sui/utils"),Ou=require("@suilend/frontend-sui"),nn=require("@suilend/sdk"),Pu=Ut(require("bignumber.js")),ap=(a,e)=>{let t={[nn.Side.DEPOSIT]:[],[nn.Side.BORROW]:[]};return a.lendingMarket.reserves.forEach(n=>{[nn.Side.DEPOSIT,nn.Side.BORROW].forEach(o=>{let i=o===nn.Side.DEPOSIT?n.depositsPoolRewardManager:n.borrowsPoolRewardManager,l=e.userRewardManagers.find(u=>u.poolRewardManagerId===i.id);l&&(t[o]=i.poolRewards.map((u,b)=>({reserveArrayIndex:n.arrayIndex,rewardIndex:BigInt(b),rewardCoinType:(0,Mu.normalizeStructTag)(u.coinType.name),side:o})).filter(u=>!(0,Ou.isSendPoints)(u.rewardCoinType)&&!!l.rewards[Number(u.rewardIndex)]&&new Pu.default(l.rewards[Number(u.rewardIndex)].earnedRewards.value.toString()).gt(0)))})}),Object.values(t).flat()},or=ap;var ar=class a extends Nt{constructor(t){super(t);this.data=t}txType;txSubType;async build(t){let{suiClient:n,account:o,suilendClient:i,obligationOwnerCap:l,obligation:u}=t;if(console.log("ClaimIntention.build",n,o,i,l,u),!l||!u)throw new Error("Obligation not found");let b=new Ru.Transaction;return i.claimRewardsAndSendToUser(o.address,l.id,or(i,u),b),b}static fromData(t){return console.log("ClaimIntention.fromData",t),new a(t)}};var Bu=require("@mysten/sui/transactions");var rr=class a extends Nt{constructor(t){super(t);this.data=t}txType;txSubType;async build(t){let{suiClient:n,account:o,suilendClient:i,obligationOwnerCap:l,obligation:u}=t;if(console.log("ClaimAndDepositIntention.build",n,o,i,l,u),!l||!u)throw new Error("Obligation not found");let b=new Bu.Transaction;return i.claimRewardsAndDeposit(o.address,l.id,or(i,u),b),b}static fromData(t){return console.log("ClaimAndDepositIntention.fromData",t),new a(t)}};var _u=require("@mysten/sui/transactions");var ir=class a extends Nt{constructor(t){super(t);this.data=t}txType;txSubType;async build(t){let{suiClient:n,account:o,suilendClient:i,obligationOwnerCap:l,obligation:u}=t;console.log("DepositIntention.build",n,o,i,l,u);let b=new _u.Transaction;return await i.depositIntoObligation(o.address,this.data.coinType,this.data.value,b,l?.id),b}static fromData(t){return console.log("DepositIntention.fromData",t),new a(t)}};var Eu=require("@mysten/sui/transactions");var sr=class a extends Nt{constructor(t){super(t);this.data=t}txType;txSubType;async build(t){let{suiClient:n,account:o,suilendClient:i,obligationOwnerCap:l,obligation:u}=t;if(console.log("RepayIntention.build",n,o,i,l,u),!l||!u)throw new Error("Obligation not found");let b=new Eu.Transaction;return await i.repayIntoObligation(o.address,u.id,this.data.coinType,this.data.value,b),b}static fromData(t){return console.log("RepayIntention.fromData",t),new a(t)}};var Nu=require("@mysten/sui/transactions");var cr=class a extends Nt{constructor(t){super(t);this.data=t}txType;txSubType;async build(t){let{suiClient:n,account:o,suilendClient:i,obligationOwnerCap:l,obligation:u}=t;if(console.log("WithdrawIntention.build",n,o,i,l,u),!l||!u)throw new Error("Obligation not found");let b=new Nu.Transaction;return await i.withdrawAndSendToUser(o.address,l.id,u.id,this.data.coinType,this.data.value,b),b}static fromData(t){return console.log("WithdrawIntention.fromData",t),new a(t)}};var lr=async(a,e)=>{let t=await Ce.SuilendClient.initialize(Ce.LENDING_MARKET_ID,Ce.LENDING_MARKET_TYPE,a),n=await Ce.SuilendClient.getObligationOwnerCaps(e.address,t.lendingMarket.$typeArgs,a),o=await Promise.all(n.map(i=>Ce.SuilendClient.getObligation(i.obligationId,t.lendingMarket.$typeArgs,a)));return console.log("XXX getUtils - suilendClient:",t,"obligations:",o,"obligationOwnerCaps:",n),{suilendClient:t,obligationOwnerCaps:n,obligations:o}},ur=class{application="Suilend";supportSDK="@mysten/sui";utils;async deserialize(e){let{transaction:t,suiClient:n,account:o}=e;this.utils||(this.utils=await lr(n,o));let i=await n.devInspectTransactionBlock({sender:o.address,transactionBlock:t});console.log("SuilendAppHelper.deserialize - simResult:",i,"utils:",this.utils,"suiClient:",n);let u=new er(t,i).decode();return{txType:Wu.TransactionType.Other,txSubType:u.type,intentionData:u.intentionData}}async build(e){let{network:t,txSubType:n,intentionData:o,suiClient:i,account:l}=e;this.utils||(this.utils=await lr(i,l));let u;switch(n){case"deposit":u=ir.fromData(o);break;case"withdraw":u=cr.fromData(o);break;case"borrow":u=nr.fromData(o);break;case"repay":u=sr.fromData(o);break;case"claim":u=ar.fromData(o);break;case"claimAndDeposit":u=rr.fromData(o);break;default:throw new Error("not implemented")}let b=window.localStorage.getItem("obligationId"),T=this.utils.obligations?.find(C=>C.id===b)??this.utils.obligations?.[0],S=this.utils.obligationOwnerCaps?.find(C=>C.obligationId===T?.id);return u.build({network:t,suiClient:i,account:l,suilendClient:this.utils.suilendClient,obligationOwnerCap:S,obligation:T})}};var hs=async(a,e)=>{let t=await lr(a,e),n=await(0,Lu.fetchRegistryLiquidStakingInfoMap)(a);return{...t,LIQUID_STAKING_INFO_MAP:n}};var dr=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,Ie.normalizeStructTag)(e.MintEvent.parsedJson.event.typename.name),n=e.MintEvent.parsedJson.event.sui_amount_in;return console.log("Decoder.decodeStake",n),{txType:on.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,Ie.normalizeStructTag)(e.MintEvent.parsedJson.event.typename.name),n=e.MintEvent.parsedJson.event.sui_amount_in;return console.log("Decoder.decodeStakeAndDeposit",n),{txType:on.TransactionType.Other,type:"stakeAndDeposit",intentionData:{amount:n,outCoinType:t}}}decodeConvert(){let e={RedeemEvent:this.simResult.events.find(i=>i.type.includes("liquid_staking::RedeemEvent")),MintEvent:this.simResult.events.find(i=>i.type.includes("liquid_staking::MintEvent"))},t=(0,Ie.normalizeStructTag)(e.RedeemEvent.parsedJson.event.typename.name),n=(0,Ie.normalizeStructTag)(e.MintEvent.parsedJson.event.typename.name),o=e.RedeemEvent.parsedJson.event.lst_amount_in;return console.log("Decoder.decodeConvert",o),{txType:on.TransactionType.Other,type:"convert",intentionData:{amount:o,inCoinType:t,outCoinType:n}}}decodeConvertAndDeposit(){let e={RedeemEvent:this.simResult.events.find(i=>i.type.includes("liquid_staking::RedeemEvent")),MintEvent:this.simResult.events.find(i=>i.type.includes("liquid_staking::MintEvent"))},t=(0,Ie.normalizeStructTag)(e.RedeemEvent.parsedJson.event.typename.name),n=(0,Ie.normalizeStructTag)(e.MintEvent.parsedJson.event.typename.name),o=e.RedeemEvent.parsedJson.event.lst_amount_in;return console.log("Decoder.decodeConvertAndDeposit",o),{txType:on.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,Ie.normalizeStructTag)(e.RedeemEvent.parsedJson.event.typename.name),n=e.RedeemEvent.parsedJson.event.lst_amount_in;return console.log("Decoder.decodeUnstake",n),{txType:on.TransactionType.Other,type:"unstake",intentionData:{amount:n,inCoinType:t}}}};var Uu=require("@mysten/sui/transactions"),Nn=require("@suilend/springsui-sdk");var ju=Ut(require("sort-keys-recursive")),Vt=class{constructor(e){this.data=e}serialize(){return JSON.stringify((0,ju.default)(this.data))}};var mr=class a extends Vt{constructor(t){super(t);this.data=t}txType;txSubType;async build(t){let{suiClient:n,account:o,suilendClient:i,LIQUID_STAKING_INFO_MAP:l,obligationOwnerCap:u,obligation:b}=t;console.log("ConvertIntention.build",n,o,i,l,u,b);let T=await Nn.LstClient.initialize(n,Object.values(l).find(I=>I.type===this.data.inCoinType)),S=await Nn.LstClient.initialize(n,Object.values(l).find(I=>I.type===this.data.outCoinType)),C=new Uu.Transaction;return(0,Nn.convertLstsAndSendToUser)(T,S,C,o.address,this.data.amount),C}static fromData(t){return console.log("ConvertIntention.fromData",t),new a(t)}};var qu=require("@mysten/sui/transactions"),fr=require("@suilend/sdk"),Wn=require("@suilend/springsui-sdk");var pr=class a extends Vt{constructor(t){super(t);this.data=t}txType;txSubType;async build(t){let{suiClient:n,account:o,suilendClient:i,LIQUID_STAKING_INFO_MAP:l,obligationOwnerCap:u,obligation:b}=t;console.log("ConvertAndDepositIntention.build",n,o,i,l,u,b);let T=await Wn.LstClient.initialize(n,Object.values(l).find(O=>O.type===this.data.inCoinType)),S=await Wn.LstClient.initialize(n,Object.values(l).find(O=>O.type===this.data.outCoinType)),C=new qu.Transaction,{obligationOwnerCapId:I,didCreate:x}=(0,fr.createObligationIfNoneExists)(i,C,u),v=(0,Wn.convertLsts)(T,S,C,o.address,this.data.amount);return i.deposit(v,this.data.outCoinType,I,C),x&&(0,fr.sendObligationToUser)(I,o.address,C),C}static fromData(t){return console.log("ConvertAndDepositIntention.fromData",t),new a(t)}};var Fu=require("@mysten/sui/transactions"),Ku=require("@suilend/springsui-sdk");var hr=class a extends Vt{constructor(t){super(t);this.data=t}txType;txSubType;async build(t){let{suiClient:n,account:o,suilendClient:i,LIQUID_STAKING_INFO_MAP:l,obligationOwnerCap:u,obligation:b}=t;console.log("StakeIntention.build",n,o,i,l,u,b);let T=await Ku.LstClient.initialize(n,Object.values(l).find(C=>C.type===this.data.outCoinType)),S=new Fu.Transaction;return T.mintAmountAndRebalanceAndSendToUser(S,o.address,this.data.amount),S}static fromData(t){return console.log("StakeIntention.fromData",t),new a(t)}};var $u=require("@mysten/sui/transactions"),gr=require("@suilend/sdk"),Vu=require("@suilend/springsui-sdk");var br=class a extends Vt{constructor(t){super(t);this.data=t}txType;txSubType;async build(t){let{suiClient:n,account:o,suilendClient:i,LIQUID_STAKING_INFO_MAP:l,obligationOwnerCap:u,obligation:b}=t;console.log("StakeAndDepositIntention.build",n,o,i,l,u,b);let T=await Vu.LstClient.initialize(n,Object.values(l).find(v=>v.type===this.data.outCoinType)),S=new $u.Transaction,{obligationOwnerCapId:C,didCreate:I}=(0,gr.createObligationIfNoneExists)(i,S,u),x=T.mintAmountAndRebalance(S,o.address,this.data.amount);return i.deposit(x,this.data.outCoinType,C,S),I&&(0,gr.sendObligationToUser)(C,o.address,S),S}static fromData(t){return console.log("StakeAndDepositIntention.fromData",t),new a(t)}};var Hu=require("@mysten/sui/transactions"),Gu=require("@suilend/springsui-sdk");var yr=class a extends Vt{constructor(t){super(t);this.data=t}txType;txSubType;async build(t){let{suiClient:n,account:o,suilendClient:i,LIQUID_STAKING_INFO_MAP:l,obligationOwnerCap:u,obligation:b}=t;console.log("UnstakeIntention.build",n,o,i,l,u,b);let T=await Gu.LstClient.initialize(n,Object.values(l).find(C=>C.type===this.data.inCoinType)),S=new Hu.Transaction;return T.redeemAmountAndSendToUser(S,o.address,this.data.amount),S}static fromData(t){return console.log("UnstakeIntention.fromData",t),new a(t)}};var Tr=class{application="SpringSui";supportSDK="@mysten/sui";utils;async deserialize(e){let{transaction:t,suiClient:n,account:o}=e;this.utils||(this.utils=await hs(n,o));let i=await n.devInspectTransactionBlock({sender:o.address,transactionBlock:t});console.log("SpringSuiAppHelper.deserialize",i);let u=new dr(t,i).decode();return{txType:zu.TransactionType.Other,txSubType:u.type,intentionData:u.intentionData}}async build(e){let{network:t,txSubType:n,intentionData:o,suiClient:i,account:l}=e;this.utils||(this.utils=await hs(i,l));let u;switch(n){case"stake":u=hr.fromData(o);break;case"stakeAndDeposit":u=br.fromData(o);break;case"convert":u=mr.fromData(o);break;case"convertAndDeposit":u=pr.fromData(o);break;case"unstake":u=yr.fromData(o);break;default:throw new Error("not implemented")}return u.build({network:t,suiClient:i,account:l,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 Xu=require("@msafe/sui3-utils");var bs=require("@msafe/sui3-utils");var wr=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:bs.TransactionType.Other,type:"mint",intentionData:{amount:t}}}decodeRedeem(e){let{event:{lst_amount_in:t}}=e;return console.log("Decoder.decodeRedeem",t),{txType:bs.TransactionType.Other,type:"redeem",intentionData:{amount:t}}}};var Qu=require("@alphafi/stsui-sdk");var Sr=class a extends k{constructor(t){super(t);this.data=t}txType;txSubType;async build(t){let{account:n}=t,{amount:o}=this.data,i={lstInfo:"0x1adb343ab351458e151bc392fbf1558b3332467f23bda45ae67cd355a57fd5f5",lstCointype:"0xd1b72982e40348d069bb1ff701e634c117bb5f741f44dff91e472d3b01461e55::stsui::STSUI"},u=await new Qu.LST(i).mint(o,n.address);return u.setGasBudget(1e8),u}static fromData(t){return console.log("MintIntention.fromData",t),new a(t)}};var Ju=require("@alphafi/stsui-sdk");var Cr=class a extends k{constructor(t){super(t);this.data=t}txType;txSubType;async build(t){let{account:n}=t,{amount:o}=this.data,i={lstInfo:"0x1adb343ab351458e151bc392fbf1558b3332467f23bda45ae67cd355a57fd5f5",lstCointype:"0xd1b72982e40348d069bb1ff701e634c117bb5f741f44dff91e472d3b01461e55::stsui::STSUI"},u=await new Ju.LST(i).redeem(o,n.address);return u.setGasBudget(1e8),u}static fromData(t){return console.log("RedeemIntention.fromData",t),new a(t)}};var Ir=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 l=new wr(t,o).decode();return{txType:Xu.TransactionType.Other,txSubType:l.type,intentionData:l.intentionData}}async build(e){let{account:t}=e;console.log("StSui build transaction type",e.txSubType);let n;switch(e.txSubType){case"mint":n=Sr.fromData(e.intentionData);break;case"redeem":n=Cr.fromData(e.intentionData);break;default:throw new Error("build not implemented")}return n.build({account:t})}};var Td=require("@msafe/sui3-utils"),wd=require("turbos-clmm-sdk");var Lt=require("@msafe/sui3-utils"),gs=require("@mysten/sui.js/bcs"),ke=require("@mysten/sui.js/utils"),Yu=require("turbos-clmm-sdk");var Gt={PackageId:"0x02fe4933f4521250e55a15441096d1d4a38a7311195b0bca126fc0138c1f5a97",Claim:"0x0c822cec42f7ca703696b4232f1c47b348330c23580172a29aab465bc071d894",turbosCoinType:"0x5d1f47ea69bb0de31c313d7acf89b890dbb8991ea8e03c6c355171f84bb1ba4a::turbos::TURBOS"},zt={PackageId:"0xdee9"};var cp=(a,e,t,n)=>{if(a===1)switch(n.findIndex(l=>l===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(i=>i===e)){case 0:return[!0];case 1:return[!1];default:throw new Error(`not target: ${e}`)}},xr=class{constructor(e,t,n){this.txb=e;this.turbosSdk=t;this.config=n}get transactions(){return this.txb.blockData.transactions}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.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.target===e)}getMoveCallsTransaction(e){return e.every(t=>this.transactions.find(n=>n.kind==="MoveCall"&&n.target===t))}getSwapMoveCallTransaction(e){return this.transactions.find(t=>t.kind==="MoveCall"&&e.includes(t.target))}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`)}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(`${Gt.PackageId}::claim::join`)}isPrixClaimTransaction(){return!!this.getMoveCallTransaction(`${Gt.PackageId}::claim::claim`)}isRemoveLiquidityTransaction(){return!!this.getMoveCallsTransaction([`${this.config.PackageId}::position_manager::decrease_liquidity`,`${this.config.PackageId}::position_manager::burn`])}isSwapExactBaseForQuoteTransaction(){return!!this.getMoveCallTransaction(`${zt.PackageId}::clob_v2::swap_exact_base_for_quote`)}isSwapExactQuoteForBaseTransaction(){return!!this.getMoveCallTransaction(`${zt.PackageId}::clob_v2::swap_exact_quote_for_base`)}async decodeSwap(){let e=this.transactions.find(x=>x.kind==="MoveCall"),t=0;this.swap2Layer.includes(e.target)&&(t=1);let n=cp(t,e.target,this.swap1Layer,this.swap2Layer),o=n.map((x,v)=>{let O=this.helper.decodeSharedObjectId(v),L=this.helper.decodeInputU128(4+v+t),$=this.turbosSdk.math.sqrtPriceX64ToTickIndex(new Yu.BN(L.toString()));return{pool:O,a2b:x,nextTickIndex:$}}),i=n[0]||t===1?e.typeArguments[0]:e.typeArguments[1],l=t===1?e.typeArguments[4]:n[0]?e.typeArguments[1]:e.typeArguments[0],u=this.helper.decodeInputAddress(6+2*t),b=this.helper.decodeInputU64(7+2*t),T=this.helper.decodeInputBool(5+2*t),S=this.helper.decodeInputU64(2+t),C=this.helper.decodeInputU64(3+t),I=await this.turbosSdk.trade.computeSwapResultV2({pools:[{pool:o[0].pool,a2b:o[0].a2b,amountSpecified:S}],address:u,amountSpecifiedIsInput:T});return{txType:Lt.TransactionType.Other,type:"Swap",intentionData:{routes:o,coinTypeA:i,coinTypeB:l,address:u,amountA:T?S:C,amountB:T?C:S,amountSpecifiedIsInput:T,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),i=this.helper.decodeInputU32(4),l=this.helper.decodeInputBool(5),u=this.helper.decodeInputU32(6),b=this.helper.decodeInputBool(7),T=this.helper.decodeInputU64(13);return{txType:Lt.TransactionType.Other,type:"AddLiquidity",intentionData:{pool:e,slippage:10,address:t,amountA:n,amountB:o,tickLower:l?-i:i,tickUpper:b?-u:u,deadline:T}}}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),i=this.helper.decodeInputU64(6),l=this.helper.decodeInputU64(9);return{txType:Lt.TransactionType.Other,type:"IncreaseLiquidity",intentionData:{pool:t,slippage:10,address:e,amountA:o,amountB:i,nft:n,deadline:l}}}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),i=this.helper.decodeInputU64(4),l=this.helper.decodeInputU64(5),u=this.helper.decodeInputU64(6);return{txType:Lt.TransactionType.Other,type:"DecreaseLiquidity",intentionData:{pool:t,decreaseLiquidity:o,nft:n,amountA:i,amountB:l,slippage:10,address:e,deadline:u}}}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),i=this.helper.decodeInputU64(4),l=this.helper.decodeInputU64(6);return{txType:Lt.TransactionType.Other,type:"CollectFee",intentionData:{pool:e,address:n,collectAmountA:o,collectAmountB:i,nft:t,deadline:l}}}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(l=>l.decodeInputU64(5)),i=this.helper.decodeInputU64(7);return{txType:Lt.TransactionType.Other,type:"CollectReward",intentionData:{pool:e,address:n,rewardAmounts:o,nft:t,deadline:i}}}decodeBurn(){console.log(this.helper,"decodeBurn this.helper");let e=this.helper.decodeSharedObjectId(0),t=this.helper.decodeSharedObjectId(2);return{txType:Lt.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),i=this.decreaseLiquidityHelper.decodeInputU64(4),l=this.decreaseLiquidityHelper.decodeInputU64(5),u=this.decreaseLiquidityHelper.decodeInputU64(6),b=this.collectRewardHelper.map(C=>C.decodeInputU64(5)),T=this.collectFeeHelper.decodeInputU64(3)||0,S=this.collectFeeHelper.decodeInputU64(4)||0;return{txType:Lt.TransactionType.Other,type:"RemoveLiquidity",intentionData:{pool:t,decreaseLiquidity:o,nft:n,amountA:i,amountB:l,slippage:10,address:e,collectAmountA:T,collectAmountB:S,rewardAmounts:b,deadline:u}}}decodePrixClaim(){return{txType:Lt.TransactionType.Other,type:"PrixClaim",intentionData:{}}}decodePrixJoin(){return{txType:Lt.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:Lt.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:Lt.TransactionType.Other,type:"SwapExactQuoteForBase",intentionData:{poolId:e,amountIn:t,token1:n,token2:o}}}get helper(){let e=this.transactions.find(t=>t.kind==="MoveCall"&&t.target!=="0x2::coin::zero"&&t.target!=="0x0000000000000000000000000000000000000000000000000000000000000002::coin::zero");return new xe(e,this.txb)}get collectRewardHelper(){return this.transactions.filter(t=>t.kind==="MoveCall"&&t.target===`${this.config.PackageId}::position_manager::collect_reward`).map(t=>new xe(t,this.txb))}get collectFeeHelper(){let e=this.transactions.find(t=>t.kind==="MoveCall"&&t.target===`${this.config.PackageId}::position_manager::collect`);return new xe(e,this.txb)}get decreaseLiquidityHelper(){let e=this.transactions.find(t=>t.kind==="MoveCall"&&t.target===`${this.config.PackageId}::position_manager::decrease_liquidity`);return new xe(e,this.txb)}get swapExactBaseForQuoteHelper(){let e=this.transactions.find(t=>t.kind==="MoveCall"&&t.target===`${zt.PackageId}::clob_v2::swap_exact_base_for_quote`);return new xe(e,this.txb)}get swapExactQuoteForBaseHelper(){let e=this.transactions.find(t=>t.kind==="MoveCall"&&t.target===`${zt.PackageId}::clob_v2::swap_exact_quote_for_base`);return new xe(e,this.txb)}},xe=class a{constructor(e,t){this.moveCall=e;this.txb=t}decodeSharedObjectId(e){let t=this.getInputParam(e);return a.getSharedObjectId(t)}decodeOwnedObjectId(e){let t=this.getInputParam(e);return a.getOwnedObjectId(t)}decodeInputU128(e){let t=this.decodePureArg(e,"u128");return Number(t)}decodeInputU64(e){let t=this.decodePureArg(e,"u64");return Number(t)}decodeInputU32(e){let t=this.decodePureArg(e,"u32");return Number(t)}decodeInputU8(e){let t=this.decodePureArg(e,"u8");return Number(t)}decodeInputAddress(e){let t=this.decodePureArg(e,"address");return(0,ke.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 a.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 gs.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,ke.normalizeSuiAddress)(e.value.Object.ImmOrOwned.objectId)}return(0,ke.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,ke.normalizeSuiAddress)(e.value);if(!("Object"in e.value)||!("Shared"in e.value.Object))throw new Error("not Shared");return(0,ke.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 gs.bcs.de(t,new Uint8Array(n))}typeArg(e){return(0,ke.normalizeStructTag)(this.moveCall.typeArguments[e])}shortTypeArg(e){return this.moveCall.typeArguments[e]}txArg(e){return this.moveCall.arguments[e]}};var Zu=require("turbos-clmm-sdk");var kr=class a extends P{constructor(t){super(t);this.data=t}txType;txSubType;async build(t){let n=new Zu.TurbosSdk(t.network.replace("sui:",""),t.suiClient),{pool:o,address:i,amountA:l,amountB:u,slippage:b,tickLower:T,tickUpper:S,deadline:C,txb:I}=this.data;return n.pool.addLiquidity({pool:o,slippage:b,address:i,amountA:l,amountB:u,tickLower:T,tickUpper:S,deadline:C,txb:I})}static fromData(t){return new a(t)}};var td=require("turbos-clmm-sdk");var vr=class a extends P{constructor(t){super(t);this.data=t}txType;txSubType;async build(t){let n=new td.TurbosSdk(t.network.replace("sui:",""),t.suiClient),{pool:o,nft:i,txb:l}=this.data;return n.nft.burn({pool:o,nft:i,txb:l})}static fromData(t){return new a(t)}};var ed=require("turbos-clmm-sdk");var Dr=class a extends P{constructor(t){super(t);this.data=t}txType;txSubType;async build(t){let n=new ed.TurbosSdk(t.network.replace("sui:",""),t.suiClient),{pool:o,address:i,nft:l,collectAmountA:u,collectAmountB:b,deadline:T,txb:S}=this.data;return n.pool.collectFee({pool:o,address:i,collectAmountA:u,collectAmountB:b,nft:l,deadline:T,txb:S})}static fromData(t){return new a(t)}};var nd=require("turbos-clmm-sdk");var Ar=class a extends P{constructor(t){super(t);this.data=t}txType;txSubType;async build(t){let n=new nd.TurbosSdk(t.network.replace("sui:",""),t.suiClient),{pool:o,address:i,nft:l,rewardAmounts:u,deadline:b,txb:T}=this.data;return n.pool.collectReward({pool:o,address:i,rewardAmounts:u,nft:l,deadline:b,txb:T})}static fromData(t){return new a(t)}};var od=require("turbos-clmm-sdk");var Mr=class a extends P{constructor(t){super(t);this.data=t}txType;txSubType;async build(t){let n=new od.TurbosSdk(t.network.replace("sui:",""),t.suiClient),{fee:o,address:i,tickLower:l,tickUpper:u,sqrtPrice:b,slippage:T,coinTypeA:S,coinTypeB:C,amountA:I,amountB:x,deadline:v,txb:O}=this.data;return n.pool.createPool({fee:o,amountA:I,amountB:x,address:i,tickLower:l,tickUpper:u,sqrtPrice:b,slippage:T,coinTypeA:S,coinTypeB:C,deadline:v,txb:O})}static fromData(t){return new a(t)}};var ad=require("turbos-clmm-sdk");var Or=class a extends P{constructor(t){super(t);this.data=t}txType;txSubType;async build(t){let n=new ad.TurbosSdk(t.network.replace("sui:",""),t.suiClient),{pool:o,address:i,amountA:l,amountB:u,slippage:b,nft:T,decreaseLiquidity:S,deadline:C,txb:I}=this.data;return n.pool.decreaseLiquidity({pool:o,slippage:b,address:i,amountA:l,amountB:u,nft:T,decreaseLiquidity:S,deadline:C,txb:I})}static fromData(t){return new a(t)}};var rd=require("turbos-clmm-sdk");var Pr=class a extends P{constructor(t){super(t);this.data=t}txType;txSubType;async build(t){let n=new rd.TurbosSdk(t.network.replace("sui:",""),t.suiClient),{pool:o,address:i,amountA:l,amountB:u,slippage:b,nft:T,deadline:S,txb:C}=this.data;return n.pool.increaseLiquidity({pool:o,slippage:b,address:i,amountA:l,amountB:u,nft:T,deadline:S,txb:C})}static fromData(t){return new a(t)}};var id=require("@mysten/sui.js/transactions"),sd=require("@mysten/sui.js/utils");var Rr=class a extends P{constructor(t){super(t);this.data=t}txType;txSubType;async build(t){let n=new id.TransactionBlock;return n.moveCall({target:`${Gt.PackageId}::claim::claim`,typeArguments:[Gt.turbosCoinType],arguments:[n.object(Gt.Claim),n.object(sd.SUI_CLOCK_OBJECT_ID)]}),n}static fromData(t){return new a(t)}};var cd=require("@mysten/sui.js/transactions");var Br=class a extends P{constructor(t){super(t);this.data=t}txType;txSubType;async build(t){let n=new cd.TransactionBlock;return n.moveCall({target:`${Gt.PackageId}::claim::join`,typeArguments:[Gt.turbosCoinType],arguments:[n.object(Gt.Claim)]}),n}static fromData(t){return new a(t)}};var ld=require("@mysten/sui.js/transactions"),ud=require("turbos-clmm-sdk");var _r=class a extends P{constructor(t){super(t);this.data=t}txType;txSubType;async build(t){let n=new ud.TurbosSdk(t.network.replace("sui:",""),t.suiClient),o=new ld.TransactionBlock;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.nft.burn({txb:o,nft:this.data.nft,pool:this.data.pool}),o}static fromData(t){return new a(t)}};var dd=require("turbos-clmm-sdk");var Er=class a extends P{constructor(t){super(t);this.data=t}txType;txSubType;async build(t){console.log(this.data,"this.data");let n=new dd.TurbosSdk(t.network.replace("sui:",""),t.suiClient),{routes:o,coinTypeA:i,coinTypeB:l,address:u,amountA:b,amountB:T,slippage:S,amountSpecifiedIsInput:C,deadline:I,txb:x}=this.data;return n.trade.swap({routes:o,coinTypeA:i,coinTypeB:l,address:u,amountA:b,amountB:T,amountSpecifiedIsInput:C,slippage:S,deadline:I,txb:x})}static fromData(t){return new a(t)}};var gd=require("turbos-clmm-sdk");var ys=require("@mysten/sui.js/transactions"),Ts=require("@mysten/sui.js/utils");var md=require("turbos-clmm-sdk");var Ln=class{constructor(e){this.turbosSdk=e}async getCoinsData(e,t,n){let o=[],i;do i=await this.turbosSdk.provider.getCoins({owner:e,coinType:t,cursor:i?.nextCursor}),o.push(...i.data);while(i.hasNextPage);let l=[],u=0;return o.sort((b,T)=>Number(T.balance)-Number(b.balance)).some(b=>u>=n?!0:(u+=Number(b.balance),l.push(b),!1)),l}splitAndMergeCoin(e,t,n){if(!e||e.length<1)return[void 0,void 0];if(this.isSuiCoinAddress(e[0].coinType)){let[l]=n.splitCoins(n.gas,[n.pure(t)]);return[l,void 0]}let o=n.object(e[0].coinObjectId);e.length>1&&n.mergeCoins(o,e.slice(1).map(l=>n.object(l.coinObjectId)));let[i]=n.splitCoins(o,[n.pure(t)]);return[i,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:`${zt.PackageId}::custodian_v2::AccountCap`}});return t.data[0]?.data?(0,md.unstable_getObjectId)(t.data[0].data):void 0}createAccount(e){let[t]=e.moveCall({typeArguments:[],target:`${zt.PackageId}::clob_v2::create_account`,arguments:[]});return t}zero(e,t){return t.moveCall({typeArguments:[e],target:"0x2::coin::zero",arguments:[]})}};var pd=89,fd=1e6,hd=async a=>{let{token1:e,token2:t,poolId:n,amountIn:o,currentAddress:i,turbosSdk:l}=a,u=new ys.TransactionBlock,b=new Ln(l),T=await b.getCoinsData(i,t,o),[S,C]=b.splitAndMergeCoin(T,o,u);if(!S)throw new Error(`Not enough balance: ${t}`);let I=await b.IsAccountCap(i),x=I?u.object(I):b.createAccount(u),[v,O,L]=u.moveCall({typeArguments:[e,t],target:`${zt.PackageId}::clob_v2::swap_exact_quote_for_base`,arguments:[u.object(String(n)),u.pure(pd),x,u.pure(o),u.object((0,Ts.normalizeSuiObjectId)("0x6")),S]});return C&&u.transferObjects([C],u.pure(i)),u.transferObjects([v],u.pure(i)),u.transferObjects([O],u.pure(i)),I||u.transferObjects([x],u.pure(i)),u.setSenderIfNotSet(i),u.setGasBudget(fd),u},bd=async a=>{let{token1:e,token2:t,poolId:n,amountIn:o,currentAddress:i,turbosSdk:l}=a,u=new ys.TransactionBlock,b=new Ln(l),T=await b.getCoinsData(i,e,o),[S,C]=b.splitAndMergeCoin(T,o,u);if(!S)throw new Error(`Not enough balance: ${e}`);let I=await b.IsAccountCap(i),x=I?u.object(I):b.createAccount(u),v=b.zero(t,u),[O,L,$]=u.moveCall({typeArguments:[e,t],target:`${zt.PackageId}::clob_v2::swap_exact_base_for_quote`,arguments:[u.object(String(n)),u.pure(pd),x,u.pure(o),S,v,u.object((0,Ts.normalizeSuiObjectId)("0x6"))]});return C&&u.transferObjects([C],u.pure(i)),u.transferObjects([O],u.pure(i)),u.transferObjects([L],u.pure(i)),I||u.transferObjects([x],u.pure(i)),u.setSenderIfNotSet(i),u.setGasBudget(fd),u};var Nr=class a extends P{constructor(t){super(t);this.data=t}txType;txSubType;async build(t){let n=new gd.TurbosSdk(t.network.replace("sui:",""),t.suiClient);return await bd({...this.data,turbosSdk:n,currentAddress:t.account.address})}static fromData(t){return new a(t)}};var yd=require("turbos-clmm-sdk");var Wr=class a extends P{constructor(t){super(t);this.data=t}txType;txSubType;async build(t){let n=new yd.TurbosSdk(t.network.replace("sui:",""),t.suiClient);return await hd({...this.data,turbosSdk:n,currentAddress:t.account.address})}static fromData(t){return new a(t)}};var Lr=class{application="turbos";supportSDK="@mysten/sui.js";async deserialize(e){let t=new wd.TurbosSdk(e.network.replace("sui:",""),e.suiClient),n=await t.contract.getConfig(),{transactionBlock:o,account:i}=e;console.log(e,"input");let u=await new xr(o,t,n).decode(i.address);return{txType:Td.TransactionType.Other,txSubType:u.type,intentionData:u.intentionData}}async build(e){let{suiClient:t,account:n,network:o}=e,i;switch(console.log(e.intentionData,"intentionData"),e.txSubType){case"CreatePool":i=Mr.fromData(e.intentionData);break;case"AddLiquidity":i=kr.fromData(e.intentionData);break;case"IncreaseLiquidity":i=Pr.fromData(e.intentionData);break;case"DecreaseLiquidity":i=Or.fromData(e.intentionData);break;case"RemoveLiquidity":i=_r.fromData(e.intentionData);break;case"CollectFee":i=Dr.fromData(e.intentionData);break;case"CollectReward":i=Ar.fromData(e.intentionData);break;case"Burn":i=vr.fromData(e.intentionData);break;case"Swap":i=Er.fromData(e.intentionData);break;case"PrixJoin":i=Br.fromData(e.intentionData);break;case"PrixClaim":i=Rr.fromData(e.intentionData);break;case"SwapExactBaseForQuote":i=Nr.fromData(e.intentionData);break;case"SwapExactQuoteForBase":i=Wr.fromData(e.intentionData);break;default:throw new Error("not implemented")}return i.build({suiClient:t,account:n,network:o})}};var xd=require("@msafe/sui3-utils");var jr=require("@msafe/sui3-utils"),ws=require("@mysten/sui.js/bcs"),ve=require("@mysten/sui.js/utils");var lp={packageId:"0x549e8b69270defbfafd4f94e17ec44cdbdd99820b33bda2278dea3b9a32d3f55",poolObjectId:"0x7fa2faa111b8c65bea48a23049bfd81ca8f971a262d981dcd9a17c3825cb5baf",metadataObjectId:"0x680cd26af32b2bde8d3361e804c53ec1d1cfe24c7f039eb7f549e8dfde389a60",systemStateObjectId:"0x0000000000000000000000000000000000000000000000000000000000000005",certType:"0x549e8b69270defbfafd4f94e17ec44cdbdd99820b33bda2278dea3b9a32d3f55::cert::CERT",gasBudget:5e7},Dt=lp;var Ur=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:jr.TransactionType.Other,type:"Stake",intentionData:{amount:e}}}decodeUnStake(){let t=this.transactions.find(n=>n.kind==="SplitCoins").amounts[0].value.toNumber();return{txType:jr.TransactionType.Other,type:"UnStake",intentionData:{amount:t}}}decodeClaimTicket(){let e=this.helper.decodeOwnedObjectId(2);return console.log(e),{txType:jr.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 Ss(e,this.txb)}},Ss=class a{constructor(e,t){this.moveCall=e;this.txb=t}decodeSharedObjectId(e){let t=this.getInputParam(e);return a.getSharedObjectId(t)}decodeOwnedObjectId(e){let t=this.getInputParam(e);return a.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 a.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 ws.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 ws.bcs.de(t,new Uint8Array(n))}typeArg(e){return(0,ve.normalizeStructTag)(this.moveCall.typeArguments[e])}txArg(e){return this.moveCall.arguments[e]}};var Sd=require("@mysten/sui.js/transactions");var qr=class a extends P{constructor(t){super(t);this.data=t}txType;txSubType;async build(t){console.log(t);let n=new Sd.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 a(t)}};var Cd=require("@mysten/sui.js/transactions");var Fr=class a extends P{constructor(t){super(t);this.data=t}txType;txSubType;async build(t){console.log(t);let n=new Cd.TransactionBlock,{amount:o}=this.data,[i]=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),i]}),n}static fromData(t){return new a(t)}};var Id=require("@mysten/sui.js/transactions");var Kr=class a extends P{constructor(t){super(t);this.data=t}txType;txSubType;async build(t){console.log(t);let n=new Id.TransactionBlock,{amount:o}=this.data,i=(await t.suiClient.getAllCoins({owner:t.account.address,limit:100})).data,[l,...u]=i.filter(S=>S.coinType.split("::")[0]===Dt.certType.split("::")[0]),b=n.object(l.coinObjectId);u.length&&n.mergeCoins(b,u.map(S=>n.object(S.coinObjectId)));let T=n.splitCoins(n.object(l.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),T]}),n}static fromData(t){return new a(t)}};var $r=class{application="volo";supportSDK="@mysten/sui.js";async deserialize(e){let{transactionBlock:t}=e,o=new Ur(t).decode();return{txType:xd.TransactionType.Other,txSubType:o.type,intentionData:o.intentionData}}async build(e){let{suiClient:t,account:n}=e,o;switch(e.txSubType){case"Stake":o=Fr.fromData(e.intentionData);break;case"UnStake":o=Kr.fromData(e.intentionData);break;case"ClaimTicket":o=qr.fromData(e.intentionData);break;default:throw new Error("not implemented")}return o.build({suiClient:t,account:n})}};var Ed=require("@msafe/sui3-utils");var Cs=require("@cetusprotocol/cetus-sui-clmm-sdk"),De=require("@msafe/sui3-utils"),an=require("@mysten/bcs"),rn=require("@mysten/sui/bcs");var Vr=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,Cs.asIntN)(BigInt(this.getU32(this.getInputIndex(e,2)))).toString()),upperTick:Number((0,Cs.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(rn.bcs.u32().parse(Uint8Array.from((0,an.fromBase64)(this.inputs[e].Pure.bytes))))}getU64(e){return rn.bcs.u64().parse(Uint8Array.from((0,an.fromBase64)(this.inputs[e].Pure.bytes)))}getU128(e){return rn.bcs.u128().parse(Uint8Array.from((0,an.fromBase64)(this.inputs[e].Pure.bytes)))}getBoolean(e){return rn.bcs.bool().parse(Uint8Array.from((0,an.fromBase64)(this.inputs[e].Pure.bytes)))}getAddress(e){return rn.bcs.Address.parse(Uint8Array.from((0,an.fromBase64)(this.inputs[e].Pure.bytes)))}getTypeArguments(e){return e.MoveCall.typeArguments||[]}getInputIndex(e,t){return e.MoveCall.arguments[t].Input}};var Ad=require("@msafe/sui3-utils");var ee=require("@firefly-exchange/library-sui");var vd=require("@firefly-exchange/library-sui"),Dd=require("@firefly-exchange/library-sui/dist/src/spot"),kd={rpc:"https://fullnode.mainnet.sui.io/",objects:{GlobalConfig:"0x03db251ba509a8d5d8777b6338836082335d93eecbdd09a11e190a1cff51c352",BasePackage:"0x3492c874c1e3b3e2984e8c41b589e642d4d0a5d6459e5a9cfc2d52fd7c89c267",CurrentPackage:"0x6c796c3ab3421a68158e0df18e4657b2827b1f8fed5ed4b82dba9c935988711b"}},Me=(a,e)=>{if(a!=="sui:mainnet")throw new Error("Bluefin spot protocol is only available on sui::mainnet");let t=new vd.SuiClient({url:kd.rpc});return new Dd.OnChainCalls(t,kd.objects,{address:e.address,isUIWallet:!1})};var Pt=class{static async OpenPosition(e,t,n){let o=Me(n,t),i=await o.queryChain.getPool(e.pool),l=this.prototype.buildLiqInput(i,{...e,slippage:0});return await o.openPositionWithFixedAmount(i,e.lowerTick,e.upperTick,l,{returnTx:!0,sender:t.address})}static async provideLiquidity(e,t,n){let o=Me(n,t),i=await o.queryChain.getPool(e.pool),l=this.prototype.buildLiqInput(i,e);return await o.provideLiquidityWithFixedAmount(i,e.position,l,{returnTx:!0,sender:t.address})}static async removeLiquidity(e,t,n){let o=Me(n,t),i=await o.queryChain.getPool(e.pool);return await o.removeLiquidity(i,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=Me(n,t),i=await o.queryChain.getPool(e.pool);return await o.closePosition(i,e.position,{returnTx:!0,sender:t.address})}static async collectRewards(e,t,n){let o=Me(n,t),i=await o.queryChain.getPool(e.pool);return await o.collectRewards(i,e.position,{rewardCoinsType:e.collectRewardTokens,returnTx:!0,sender:t.address})}static async collectFee(e,t,n){let o=Me(n,t),i=await o.queryChain.getPool(e.pool);return await o.collectFee(i,e.position,{returnTx:!0,sender:t.address})}static async collectRewardsAndFee(e,t,n){let o=Me(n,t),i=await o.queryChain.getPool(e.pool);return console.log(e.position),await o.collectFeeAndRewards(i,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 Hr=class a extends k{constructor(t){super(t);this.data=t}txType=Ad.TransactionType.Other;txSubType="ClosePosition";async build(t){let{account:n,network:o}=t;return console.log(this.data),Pt.closePosition(this.data,n,o)}static fromData(t){return new a(t)}};var Md=require("@msafe/sui3-utils");var Gr=class a extends k{constructor(t){super(t);this.data=t}txType=Md.TransactionType.Other;txSubType="CollectFee";async build(t){let{account:n,network:o}=t;return console.log(this.data),Pt.collectFee(this.data,n,o)}static fromData(t){return new a(t)}};var Od=require("@msafe/sui3-utils");var zr=class a extends k{constructor(t){super(t);this.data=t}txType=Od.TransactionType.Other;txSubType="CollectRewards";async build(t){let{account:n,network:o}=t;return console.log(this.data),Pt.collectRewards(this.data,n,o)}static fromData(t){return new a(t)}};var Pd=require("@msafe/sui3-utils");var Qr=class a extends k{constructor(t){super(t);this.data=t}txType=Pd.TransactionType.Other;txSubType="CollectRewardsAndFee";async build(t){let{account:n,network:o}=t;return console.log(this.data),Pt.collectRewardsAndFee(this.data,n,o)}static fromData(t){return new a(t)}};var Rd=require("@msafe/sui3-utils");var Jr=class a extends k{constructor(t){super(t);this.data=t}txType=Rd.TransactionType.Other;txSubType="OpenPosition";async build(t){let{account:n,network:o}=t;return console.log(this.data),Pt.OpenPosition(this.data,n,o)}static fromData(t){return new a(t)}};var Bd=require("@msafe/sui3-utils");var Xr=class a extends k{constructor(t){super(t);this.data=t}txType=Bd.TransactionType.Other;txSubType="ProvideLiquidity";async build(t){let{account:n,network:o}=t;return console.log(this.data),Pt.provideLiquidity(this.data,n,o)}static fromData(t){return new a(t)}};var _d=require("@msafe/sui3-utils");var Yr=class a extends k{constructor(t){super(t);this.data=t}txType=_d.TransactionType.Other;txSubType="RemoveLiquidity";async build(t){let{account:n,network:o}=t;return console.log(this.data),Pt.removeLiquidity(this.data,n,o)}static fromData(t){return new a(t)}};var Zr=class{application="bluefin";supportSDK="@mysten/sui";async deserialize(e){console.log("Bluefin helper deserialize input: ",e);let{transaction:t}=e,o=new Vr(t).decode();return{txType:Ed.TransactionType.Other,txSubType:o.type,intentionData:o.intentionData}}async build(e){let{suiClient:t,account:n,network:o}=e;console.log(e.txSubType);let i;switch(e.txSubType){case"OpenPosition":i=Jr.fromData(e.intentionData);break;case"ProvideLiquidity":i=Xr.fromData(e.intentionData);break;case"RemoveLiquidity":i=Yr.fromData(e.intentionData);break;case"ClosePosition":i=Hr.fromData(e.intentionData);break;case"CollectFee":i=Gr.fromData(e.intentionData);break;case"CollectRewards":i=zr.fromData(e.intentionData);break;case"CollectRewardsAndFee":i=Qr.fromData(e.intentionData);break;default:throw new Error("not implemented")}return i.build({suiClient:t,account:n,network:o})}};var em=require("@msafe/sui3-utils");var Ud=require("@mmt-finance/clmm-sdk"),qd=require("@mysten/sui/transactions");var re=require("@mmt-finance/clmm-sdk/dist/utils/math/tickMath"),B=Ut(Wd());var dp="0x0000000000000000000000000000000000000000000000000000000000000002::sui::SUI",Qt=a=>a!=="0x2::sui::SUI"?a:"0x0000000000000000000000000000000000000000000000000000000000000002::sui::SUI",mp=async({suiClient:a,address:e,type:t})=>{let n,o=[],i=0;do{try{let l=await a.getCoins({owner:e,coinType:t,cursor:n,limit:50});o=o.concat(l.data),n=l.nextCursor,(!l.hasNextPage||i===8)&&(n=null)}catch(l){console.log(l),n=null}i++}while(n!==null);return o},pp=(a,e)=>{let t=[],n=BigInt(0);for(let o of e)n<a&&!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>=a)return t;throw new Error("Insufficient balance")},fp=(a,e,t,n)=>{if(a===dp){let[o]=n.splitCoins(n.gas,[n.pure.u64(t)]);return o}else{let o=pp(t,e);o.length>1&&n.mergeCoins(n.object(o[0]),o.slice(1).map(l=>n.object(l)));let[i]=n.splitCoins(n.object(o[0]),[n.pure.u64(t)]);return i}};async function sn(a,e,t,n,o){let i=await mp({suiClient:a.rpcClient,address:e,type:t});return fp(Qt(t),i.map(u=>({balance:BigInt(u.balance),objectId:u.coinObjectId})),n,o)}function E(a,e,t){let n=a.toTwos(t).shrn(e);return n.imaskn(t-e+1),n.fromTwos(t-e)}function hp(a){let e;return a&1?e=new B.default("79232123823359799118286999567"):e=new B.default("79228162514264337593543950336"),a&2&&(e=E(e.mul(new B.default("79236085330515764027303304731")),96,256)),a&4&&(e=E(e.mul(new B.default("79244008939048815603706035061")),96,256)),a&8&&(e=E(e.mul(new B.default("79259858533276714757314932305")),96,256)),a&16&&(e=E(e.mul(new B.default("79291567232598584799939703904")),96,256)),a&32&&(e=E(e.mul(new B.default("79355022692464371645785046466")),96,256)),a&64&&(e=E(e.mul(new B.default("79482085999252804386437311141")),96,256)),a&128&&(e=E(e.mul(new B.default("79736823300114093921829183326")),96,256)),a&256&&(e=E(e.mul(new B.default("80248749790819932309965073892")),96,256)),a&512&&(e=E(e.mul(new B.default("81282483887344747381513967011")),96,256)),a&1024&&(e=E(e.mul(new B.default("83390072131320151908154831281")),96,256)),a&2048&&(e=E(e.mul(new B.default("87770609709833776024991924138")),96,256)),a&4096&&(e=E(e.mul(new B.default("97234110755111693312479820773")),96,256)),a&8192&&(e=E(e.mul(new B.default("119332217159966728226237229890")),96,256)),a&16384&&(e=E(e.mul(new B.default("179736315981702064433883588727")),96,256)),a&32768&&(e=E(e.mul(new B.default("407748233172238350107850275304")),96,256)),a&65536&&(e=E(e.mul(new B.default("2098478828474011932436660412517")),96,256)),a&131072&&(e=E(e.mul(new B.default("55581415166113811149459800483533")),96,256)),a&262144&&(e=E(e.mul(new B.default("38992368544603139932233054999993551")),96,256)),E(e,32,256)}function bp(a){let e=Math.abs(a),t;return e&1?t=new B.default("18445821805675392311"):t=new B.default("18446744073709551616"),e&2&&(t=E(t.mul(new B.default("18444899583751176498")),64,256)),e&4&&(t=E(t.mul(new B.default("18443055278223354162")),64,256)),e&8&&(t=E(t.mul(new B.default("18439367220385604838")),64,256)),e&16&&(t=E(t.mul(new B.default("18431993317065449817")),64,256)),e&32&&(t=E(t.mul(new B.default("18417254355718160513")),64,256)),e&64&&(t=E(t.mul(new B.default("18387811781193591352")),64,256)),e&128&&(t=E(t.mul(new B.default("18329067761203520168")),64,256)),e&256&&(t=E(t.mul(new B.default("18212142134806087854")),64,256)),e&512&&(t=E(t.mul(new B.default("17980523815641551639")),64,256)),e&1024&&(t=E(t.mul(new B.default("17526086738831147013")),64,256)),e&2048&&(t=E(t.mul(new B.default("16651378430235024244")),64,256)),e&4096&&(t=E(t.mul(new B.default("15030750278693429944")),64,256)),e&8192&&(t=E(t.mul(new B.default("12247334978882834399")),64,256)),e&16384&&(t=E(t.mul(new B.default("8131365268884726200")),64,256)),e&32768&&(t=E(t.mul(new B.default("3584323654723342297")),64,256)),e&65536&&(t=E(t.mul(new B.default("696457651847595233")),64,256)),e&131072&&(t=E(t.mul(new B.default("26294789957452057")),64,256)),e&262144&&(t=E(t.mul(new B.default("37481735321082")),64,256)),t}var ti=(a,e,t)=>{let n=(0,re.convertI32ToSigned)(t?a+a%(e??1):a-a%(e??1));return n>0?new B.default(hp(n)):new B.default(bp(n))},Ld=async(a,e,t,n,o,i,l,u,b)=>{let T=ti((0,re.convertI32ToSigned)(u),i.tickSpacing),S=ti((0,re.convertI32ToSigned)(b),i.tickSpacing),C=BigInt(Math.ceil(Number(n)*10**i.tokenX.decimals)),I=BigInt(Math.ceil(Number(o)*10**i.tokenY.decimals)),x,v;Number(n)?x=await sn(a,t,Qt(i.tokenX.coinType),C,e):[x]=e.moveCall({target:"0x2::coin::zero",typeArguments:[i.tokenX.coinType],arguments:[]}),Number(o)?v=await sn(a,t,Qt(i.tokenY.coinType),I,e):[v]=e.moveCall({target:"0x2::coin::zero",typeArguments:[i.tokenY.coinType],arguments:[]});let O={objectId:l,tokenXType:i.tokenXType,tokenYType:i.tokenYType,tickSpacing:i.tickSpacing},L=a.Position.openPosition(e,O,T.toString(),S.toString());a.Pool.addLiquidity(e,O,L,x,v,BigInt(0),BigInt(0),t),e.transferObjects([L],e.pure.address(t))},jd=async(a,e,t,n,o,i,l,u,b)=>{try{let T=BigInt(Math.ceil(Number(o)*10**(i?l.tokenX.decimals:l.tokenY.decimals))),S=i?l.tokenX.coinType:l.tokenY.coinType;S=Qt(S);let C=await sn(a,n,S,T,e),I={objectId:l.objectId,tokenXType:Qt(l.tokenX.coinType),tokenYType:Qt(l.tokenY.coinType),tickSpacing:l.tickSpacing},x=ti((0,re.convertI32ToSigned)(u),l.tickSpacing),v=ti((0,re.convertI32ToSigned)(b),l.tickSpacing),O=a.Position.openPosition(e,I,x.toString(),v.toString()),$=(await t.getObject({id:l.objectId,options:{showContent:!0}}))?.data?.content?.fields?.sqrt_price??l.currentSqrtPrice,Wt=re.TickMath.sqrtPriceX64ToPrice(new B.default($?.toString()),l.tokenX.decimals,l.tokenY.decimals),Bt=re.TickMath.priceToSqrtPriceX64(Wt.mul(i?.99:1.01),l.tokenX.decimals,l.tokenY.decimals);await a.Pool.addLiquiditySingleSided(e,I,O,C,BigInt(0),BigInt(0),i,n,BigInt(Bt.toString())),e.transferObjects([O],e.pure.address(n))}catch(T){console.error(T)}};var ei=class a extends k{constructor(t){super(t);this.data=t}txType;txSubType;async build(){let t=Ud.MmtSDK.NEW({network:"mainnet"}),{params:n}=this.data,{address:o,amountA:i,amountB:l,pool:u,selectedLowTick:b,selectedHighTick:T}=n,S=new qd.Transaction;return await Ld(t,S,o,i,l,u,u.objectId,b,T),S}static fromData(t){return new a(t)}};var Fd=require("@mmt-finance/clmm-sdk"),Kd=require("@mysten/sui/transactions");var ni=class a extends k{constructor(t){super(t);this.data=t}txType;txSubType;async build(){let t=Fd.MmtSDK.NEW({network:"mainnet"}),{params:n}=this.data,{address:o,amount:i,isTokenX:l,pool:u,selectedLowTick:b,selectedHighTick:T}=n,S=new Kd.Transaction;return await jd(t,S,t.rpcClient,o,i,l,u,b,T),S}static fromData(t){return new a(t)}};var $d=require("@mmt-finance/clmm-sdk"),Vd=require("@mysten/sui/transactions");var cn=(a,e,t,n,o)=>{let i={objectId:n.objectId,tokenXType:n.tokenXType,tokenYType:n.tokenYType};(n?.rewarders?.length??0)>0&&a.Pool.collectAllRewards(o,i,n.rewarders,t.objectId,e),a.Pool.collectFee(o,n,t.objectId,e)};var oi=class a extends k{constructor(t){super(t);this.data=t}txType;txSubType;async build(){let t=$d.MmtSDK.NEW({network:"mainnet"}),{params:n}=this.data,{address:o,positions:i,pools:l}=n,u=new Vd.Transaction;for(let b of i){let T=l.find(S=>S.objectId===b.poolId);cn(t,o,b,T,u)}return u}static fromData(t){return new a(t)}};var Hd=require("@mmt-finance/clmm-sdk"),Gd=require("@mysten/sui/transactions");var ai=class a extends k{constructor(t){super(t);this.data=t}txType;txSubType;async build(){let t=Hd.MmtSDK.NEW({network:"mainnet"}),{params:n}=this.data,{address:o,position:i,pool:l}=n,u=new Gd.Transaction;return cn(t,o,i,l,u),u}static fromData(t){return new a(t)}};var zd=require("@mmt-finance/clmm-sdk"),Qd=require("@mysten/sui/transactions"),Jd=Ut(require("bignumber.js"));var ri=class a extends k{constructor(t){super(t);this.data=t}txType;txSubType;async build(){let t=zd.MmtSDK.NEW({network:"mainnet"}),{params:n}=this.data,{pool:o,position:i,address:l,withdrawPercentage:u}=n,b=new Qd.Transaction,T=o.tokenX.coinType,S=o.tokenY.coinType,C={objectId:o.objectId,tokenXType:T,tokenYType:S},I=BigInt(u===100?i.liquidity:new Jd.default(i.liquidity).multipliedBy(u/100).toFixed(0));return t.Pool.removeLiquidity(b,C,i.objectId,I,BigInt(0),BigInt(0),l),cn(t,l,i,o,b),u===100&&t.Position.closePosition(b,i.objectId),b}static fromData(t){return new a(t)}};var Zd=require("@mmt-finance/clmm-sdk"),tm=require("@mysten/sui/transactions");var Xd=require("@mmt-finance/clmm-sdk/dist/utils/poolUtils");var Yd=async(a,e,t,n,o,i)=>{let l=BigInt(Math.ceil(Number(n)*10**t.decimals)),u=await sn(a,o,Qt(t.coinType),l,i),b=t.coinType;for(let T=0;T<e.length;T+=1){let{objectId:S,tokenX:C,tokenY:I,isStable:x}=e[T],{id:v,isReverse:O}=Xd.mappedMmtV3Pool[S]||{id:S,isReverse:!1},L=Qt(C.coinType)===Qt(b);L=O?!L:L;let $=O?I.coinType:C.coinType,Wt=O?C.coinType:I.coinType,Bt=a.Pool.swap(i,{objectId:v,tokenXType:$,tokenYType:Wt,isStable:x},l,u,L,void 0);i.transferObjects([u],i.pure.address(o)),u=Bt,b=L?Wt:$,[l]=i.moveCall({target:"0x2::coin::value",typeArguments:[b],arguments:[u]})}i.transferObjects([u],i.pure.address(o))};var ii=class a extends k{constructor(t){super(t);this.data=t}txType;txSubType;async build(){let t=Zd.MmtSDK.NEW({network:"mainnet"}),{params:n}=this.data,{route:o,tokenIn:i,amountIn:l,address:u}=n,b=new tm.Transaction;return await Yd(t,o,i,l,u,b),b}static fromData(t){return new a(t)}};var si=class{application="mmt-dex";supportSDK="@mysten/sui";async deserialize(e){let{appContext:t}=e;return{txType:em.TransactionType.Other,txSubType:t.action,intentionData:t}}async build(e){let t;switch(e.txSubType){case"Swap":t=ii.fromData(e.intentionData);break;case"AddLiquidity":t=ei.fromData(e.intentionData);break;case"AddLiquiditySingleSide":t=ni.fromData(e.intentionData);break;case"ClaimRewards":t=ai.fromData(e.intentionData);break;case"ClaimAllRewards":t=oi.fromData(e.intentionData);break;case"RemoveLiquidity":t=ri.fromData(e.intentionData);break;default:throw new Error("not implemented")}return t.build()}};var gp=Ia.fromHelpers([new ca,new ya,new ra,new Ta,new Wo,new Lr,new si,new tr,new $r,new po,new ur,new Tr,new Gn,new Zr,new Ir]);
1
+ "use strict";var lp=Object.create;var jn=Object.defineProperty;var up=Object.getOwnPropertyDescriptor;var mp=Object.getOwnPropertyNames;var pp=Object.getPrototypeOf,dp=Object.prototype.hasOwnProperty;var fp=(a,e)=>()=>(e||a((e={exports:{}}).exports,e),e.exports),Ri=(a,e)=>{for(var t in e)jn(a,t,{get:e[t],enumerable:!0})},Gs=(a,e,t,n)=>{if(e&&typeof e=="object"||typeof e=="function")for(let o of mp(e))!dp.call(a,o)&&o!==t&&jn(a,o,{get:()=>e[o],enumerable:!(n=up(e,o))||n.enumerable});return a};var $t=(a,e,t)=>(t=a!=null?lp(pp(a)):{},Gs(e||!a||!a.__esModule?jn(t,"default",{value:a,enumerable:!0}):t,a)),hp=a=>Gs(jn({},"__esModule",{value:!0}),a);var Vm=fp((Km,Ds)=>{"use strict";(function(a,e){"use strict";function t(y,i){if(!y)throw new Error(i||"Assertion failed")}function n(y,i){y.super_=i;var l=function(){};l.prototype=i.prototype,y.prototype=new l,y.prototype.constructor=y}function o(y,i,l){if(o.isBN(y))return y;this.negative=0,this.words=null,this.length=0,this.red=null,y!==null&&((i==="le"||i==="be")&&(l=i,i=10),this._init(y||0,i||10,l||"be"))}typeof a=="object"?a.exports=o:e.BN=o,o.BN=o,o.wordSize=26;var r;try{typeof window<"u"&&typeof window.Buffer<"u"?r=window.Buffer:r=require("buffer").Buffer}catch{}o.isBN=function(i){return i instanceof o?!0:i!==null&&typeof i=="object"&&i.constructor.wordSize===o.wordSize&&Array.isArray(i.words)},o.max=function(i,l){return i.cmp(l)>0?i:l},o.min=function(i,l){return i.cmp(l)<0?i:l},o.prototype._init=function(i,l,m){if(typeof i=="number")return this._initNumber(i,l,m);if(typeof i=="object")return this._initArray(i,l,m);l==="hex"&&(l=16),t(l===(l|0)&&l>=2&&l<=36),i=i.toString().replace(/\s+/g,"");var p=0;i[0]==="-"&&(p++,this.negative=1),p<i.length&&(l===16?this._parseHex(i,p,m):(this._parseBase(i,l,p),m==="le"&&this._initArray(this.toArray(),l,m)))},o.prototype._initNumber=function(i,l,m){i<0&&(this.negative=1,i=-i),i<67108864?(this.words=[i&67108863],this.length=1):i<4503599627370496?(this.words=[i&67108863,i/67108864&67108863],this.length=2):(t(i<9007199254740992),this.words=[i&67108863,i/67108864&67108863,1],this.length=3),m==="le"&&this._initArray(this.toArray(),l,m)},o.prototype._initArray=function(i,l,m){if(t(typeof i.length=="number"),i.length<=0)return this.words=[0],this.length=1,this;this.length=Math.ceil(i.length/3),this.words=new Array(this.length);for(var p=0;p<this.length;p++)this.words[p]=0;var h,b,T=0;if(m==="be")for(p=i.length-1,h=0;p>=0;p-=3)b=i[p]|i[p-1]<<8|i[p-2]<<16,this.words[h]|=b<<T&67108863,this.words[h+1]=b>>>26-T&67108863,T+=24,T>=26&&(T-=26,h++);else if(m==="le")for(p=0,h=0;p<i.length;p+=3)b=i[p]|i[p+1]<<8|i[p+2]<<16,this.words[h]|=b<<T&67108863,this.words[h+1]=b>>>26-T&67108863,T+=24,T>=26&&(T-=26,h++);return this._strip()};function c(y,i){var l=y.charCodeAt(i);if(l>=48&&l<=57)return l-48;if(l>=65&&l<=70)return l-55;if(l>=97&&l<=102)return l-87;t(!1,"Invalid character in "+y)}function u(y,i,l){var m=c(y,l);return l-1>=i&&(m|=c(y,l-1)<<4),m}o.prototype._parseHex=function(i,l,m){this.length=Math.ceil((i.length-l)/6),this.words=new Array(this.length);for(var p=0;p<this.length;p++)this.words[p]=0;var h=0,b=0,T;if(m==="be")for(p=i.length-1;p>=l;p-=2)T=u(i,l,p)<<h,this.words[b]|=T&67108863,h>=18?(h-=18,b+=1,this.words[b]|=T>>>26):h+=8;else{var f=i.length-l;for(p=f%2===0?l+1:l;p<i.length;p+=2)T=u(i,l,p)<<h,this.words[b]|=T&67108863,h>=18?(h-=18,b+=1,this.words[b]|=T>>>26):h+=8}this._strip()};function d(y,i,l,m){for(var p=0,h=0,b=Math.min(y.length,l),T=i;T<b;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(i,l,m){this.words=[0],this.length=1;for(var p=0,h=1;h<=67108863;h*=l)p++;p--,h=h/l|0;for(var b=i.length-m,T=b%p,f=Math.min(b,b-T)+m,s=0,g=m;g<f;g+=p)s=d(i,g,g+p,l),this.imuln(h),this.words[0]+s<67108864?this.words[0]+=s:this._iaddn(s);if(T!==0){var D=1;for(s=d(i,g,i.length,l),g=0;g<T;g++)D*=l;this.imuln(D),this.words[0]+s<67108864?this.words[0]+=s:this._iaddn(s)}this._strip()},o.prototype.copy=function(i){i.words=new Array(this.length);for(var l=0;l<this.length;l++)i.words[l]=this.words[l];i.length=this.length,i.negative=this.negative,i.red=this.red};function S(y,i){y.words=i.words,y.length=i.length,y.negative=i.negative,y.red=i.red}if(o.prototype._move=function(i){S(i,this)},o.prototype.clone=function(){var i=new o(null);return this.copy(i),i},o.prototype._expand=function(i){for(;this.length<i;)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"],C=[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],k=[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(i,l){i=i||10,l=l|0||1;var m;if(i===16||i==="hex"){m="";for(var p=0,h=0,b=0;b<this.length;b++){var T=this.words[b],f=((T<<p|h)&16777215).toString(16);h=T>>>24-p&16777215,p+=2,p>=26&&(p-=26,b--),h!==0||b!==this.length-1?m=I[6-f.length]+f+m:m=f+m}for(h!==0&&(m=h.toString(16)+m);m.length%l!==0;)m="0"+m;return this.negative!==0&&(m="-"+m),m}if(i===(i|0)&&i>=2&&i<=36){var s=C[i],g=k[i];m="";var D=this.clone();for(D.negative=0;!D.isZero();){var O=D.modrn(g).toString(i);D=D.idivn(g),D.isZero()?m=O+m:m=I[s-O.length]+O+m}for(this.isZero()&&(m="0"+m);m.length%l!==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 i=this.words[0];return this.length===2?i+=this.words[1]*67108864:this.length===3&&this.words[2]===1?i+=4503599627370496+this.words[1]*67108864:this.length>2&&t(!1,"Number can only safely store up to 53 bits"),this.negative!==0?-i:i},o.prototype.toJSON=function(){return this.toString(16,2)},r&&(o.prototype.toBuffer=function(i,l){return this.toArrayLike(r,i,l)}),o.prototype.toArray=function(i,l){return this.toArrayLike(Array,i,l)};var x=function(i,l){return i.allocUnsafe?i.allocUnsafe(l):new i(l)};o.prototype.toArrayLike=function(i,l,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 b=x(i,h),T=l==="le"?"LE":"BE";return this["_toArrayLike"+T](b,p),b},o.prototype._toArrayLikeLE=function(i,l){for(var m=0,p=0,h=0,b=0;h<this.length;h++){var T=this.words[h]<<b|p;i[m++]=T&255,m<i.length&&(i[m++]=T>>8&255),m<i.length&&(i[m++]=T>>16&255),b===6?(m<i.length&&(i[m++]=T>>24&255),p=0,b=0):(p=T>>>24,b+=2)}if(m<i.length)for(i[m++]=p;m<i.length;)i[m++]=0},o.prototype._toArrayLikeBE=function(i,l){for(var m=i.length-1,p=0,h=0,b=0;h<this.length;h++){var T=this.words[h]<<b|p;i[m--]=T&255,m>=0&&(i[m--]=T>>8&255),m>=0&&(i[m--]=T>>16&255),b===6?(m>=0&&(i[m--]=T>>24&255),p=0,b=0):(p=T>>>24,b+=2)}if(m>=0)for(i[m--]=p;m>=0;)i[m--]=0},Math.clz32?o.prototype._countBits=function(i){return 32-Math.clz32(i)}:o.prototype._countBits=function(i){var l=i,m=0;return l>=4096&&(m+=13,l>>>=13),l>=64&&(m+=7,l>>>=7),l>=8&&(m+=4,l>>>=4),l>=2&&(m+=2,l>>>=2),m+l},o.prototype._zeroBits=function(i){if(i===0)return 26;var l=i,m=0;return l&8191||(m+=13,l>>>=13),l&127||(m+=7,l>>>=7),l&15||(m+=4,l>>>=4),l&3||(m+=2,l>>>=2),l&1||m++,m},o.prototype.bitLength=function(){var i=this.words[this.length-1],l=this._countBits(i);return(this.length-1)*26+l};function P(y){for(var i=new Array(y.bitLength()),l=0;l<i.length;l++){var m=l/26|0,p=l%26;i[l]=y.words[m]>>>p&1}return i}o.prototype.zeroBits=function(){if(this.isZero())return 0;for(var i=0,l=0;l<this.length;l++){var m=this._zeroBits(this.words[l]);if(i+=m,m!==26)break}return i},o.prototype.byteLength=function(){return Math.ceil(this.bitLength()/8)},o.prototype.toTwos=function(i){return this.negative!==0?this.abs().inotn(i).iaddn(1):this.clone()},o.prototype.fromTwos=function(i){return this.testn(i-1)?this.notn(i).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(i){for(;this.length<i.length;)this.words[this.length++]=0;for(var l=0;l<i.length;l++)this.words[l]=this.words[l]|i.words[l];return this._strip()},o.prototype.ior=function(i){return t((this.negative|i.negative)===0),this.iuor(i)},o.prototype.or=function(i){return this.length>i.length?this.clone().ior(i):i.clone().ior(this)},o.prototype.uor=function(i){return this.length>i.length?this.clone().iuor(i):i.clone().iuor(this)},o.prototype.iuand=function(i){var l;this.length>i.length?l=i:l=this;for(var m=0;m<l.length;m++)this.words[m]=this.words[m]&i.words[m];return this.length=l.length,this._strip()},o.prototype.iand=function(i){return t((this.negative|i.negative)===0),this.iuand(i)},o.prototype.and=function(i){return this.length>i.length?this.clone().iand(i):i.clone().iand(this)},o.prototype.uand=function(i){return this.length>i.length?this.clone().iuand(i):i.clone().iuand(this)},o.prototype.iuxor=function(i){var l,m;this.length>i.length?(l=this,m=i):(l=i,m=this);for(var p=0;p<m.length;p++)this.words[p]=l.words[p]^m.words[p];if(this!==l)for(;p<l.length;p++)this.words[p]=l.words[p];return this.length=l.length,this._strip()},o.prototype.ixor=function(i){return t((this.negative|i.negative)===0),this.iuxor(i)},o.prototype.xor=function(i){return this.length>i.length?this.clone().ixor(i):i.clone().ixor(this)},o.prototype.uxor=function(i){return this.length>i.length?this.clone().iuxor(i):i.clone().iuxor(this)},o.prototype.inotn=function(i){t(typeof i=="number"&&i>=0);var l=Math.ceil(i/26)|0,m=i%26;this._expand(l),m>0&&l--;for(var p=0;p<l;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(i){return this.clone().inotn(i)},o.prototype.setn=function(i,l){t(typeof i=="number"&&i>=0);var m=i/26|0,p=i%26;return this._expand(m+1),l?this.words[m]=this.words[m]|1<<p:this.words[m]=this.words[m]&~(1<<p),this._strip()},o.prototype.iadd=function(i){var l;if(this.negative!==0&&i.negative===0)return this.negative=0,l=this.isub(i),this.negative^=1,this._normSign();if(this.negative===0&&i.negative!==0)return i.negative=0,l=this.isub(i),i.negative=1,l._normSign();var m,p;this.length>i.length?(m=this,p=i):(m=i,p=this);for(var h=0,b=0;b<p.length;b++)l=(m.words[b]|0)+(p.words[b]|0)+h,this.words[b]=l&67108863,h=l>>>26;for(;h!==0&&b<m.length;b++)l=(m.words[b]|0)+h,this.words[b]=l&67108863,h=l>>>26;if(this.length=m.length,h!==0)this.words[this.length]=h,this.length++;else if(m!==this)for(;b<m.length;b++)this.words[b]=m.words[b];return this},o.prototype.add=function(i){var l;return i.negative!==0&&this.negative===0?(i.negative=0,l=this.sub(i),i.negative^=1,l):i.negative===0&&this.negative!==0?(this.negative=0,l=i.sub(this),this.negative=1,l):this.length>i.length?this.clone().iadd(i):i.clone().iadd(this)},o.prototype.isub=function(i){if(i.negative!==0){i.negative=0;var l=this.iadd(i);return i.negative=1,l._normSign()}else if(this.negative!==0)return this.negative=0,this.iadd(i),this.negative=1,this._normSign();var m=this.cmp(i);if(m===0)return this.negative=0,this.length=1,this.words[0]=0,this;var p,h;m>0?(p=this,h=i):(p=i,h=this);for(var b=0,T=0;T<h.length;T++)l=(p.words[T]|0)-(h.words[T]|0)+b,b=l>>26,this.words[T]=l&67108863;for(;b!==0&&T<p.length;T++)l=(p.words[T]|0)+b,b=l>>26,this.words[T]=l&67108863;if(b===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(i){return this.clone().isub(i)};function L(y,i,l){l.negative=i.negative^y.negative;var m=y.length+i.length|0;l.length=m,m=m-1|0;var p=y.words[0]|0,h=i.words[0]|0,b=p*h,T=b&67108863,f=b/67108864|0;l.words[0]=T;for(var s=1;s<m;s++){for(var g=f>>>26,D=f&67108863,O=Math.min(s,i.length-1),M=Math.max(0,s-y.length+1);M<=O;M++){var E=s-M|0;p=y.words[E]|0,h=i.words[M]|0,b=p*h+D,g+=b/67108864|0,D=b&67108863}l.words[s]=D|0,f=g|0}return f!==0?l.words[s]=f|0:l.length--,l._strip()}var V=function(i,l,m){var p=i.words,h=l.words,b=m.words,T=0,f,s,g,D=p[0]|0,O=D&8191,M=D>>>13,E=p[1]|0,_=E&8191,U=E>>>13,se=p[2]|0,q=se&8191,F=se>>>13,Ms=p[3]|0,G=Ms&8191,Q=Ms>>>13,Ps=p[4]|0,z=Ps&8191,J=Ps>>>13,Bs=p[5]|0,X=Bs&8191,Y=Bs>>>13,Rs=p[6]|0,Z=Rs&8191,tt=Rs>>>13,Es=p[7]|0,et=Es&8191,nt=Es>>>13,Ns=p[8]|0,ot=Ns&8191,at=Ns>>>13,Ws=p[9]|0,rt=Ws&8191,it=Ws>>>13,_s=h[0]|0,st=_s&8191,ct=_s>>>13,Ls=h[1]|0,lt=Ls&8191,ut=Ls>>>13,js=h[2]|0,mt=js&8191,pt=js>>>13,Us=h[3]|0,dt=Us&8191,ft=Us>>>13,qs=h[4]|0,ht=qs&8191,gt=qs>>>13,Fs=h[5]|0,yt=Fs&8191,bt=Fs>>>13,Ks=h[6]|0,St=Ks&8191,Tt=Ks>>>13,Vs=h[7]|0,wt=Vs&8191,It=Vs>>>13,$s=h[8]|0,Ct=$s&8191,kt=$s>>>13,Hs=h[9]|0,vt=Hs&8191,xt=Hs>>>13;m.negative=i.negative^l.negative,m.length=19,f=Math.imul(O,st),s=Math.imul(O,ct),s=s+Math.imul(M,st)|0,g=Math.imul(M,ct);var fi=(T+f|0)+((s&8191)<<13)|0;T=(g+(s>>>13)|0)+(fi>>>26)|0,fi&=67108863,f=Math.imul(_,st),s=Math.imul(_,ct),s=s+Math.imul(U,st)|0,g=Math.imul(U,ct),f=f+Math.imul(O,lt)|0,s=s+Math.imul(O,ut)|0,s=s+Math.imul(M,lt)|0,g=g+Math.imul(M,ut)|0;var hi=(T+f|0)+((s&8191)<<13)|0;T=(g+(s>>>13)|0)+(hi>>>26)|0,hi&=67108863,f=Math.imul(q,st),s=Math.imul(q,ct),s=s+Math.imul(F,st)|0,g=Math.imul(F,ct),f=f+Math.imul(_,lt)|0,s=s+Math.imul(_,ut)|0,s=s+Math.imul(U,lt)|0,g=g+Math.imul(U,ut)|0,f=f+Math.imul(O,mt)|0,s=s+Math.imul(O,pt)|0,s=s+Math.imul(M,mt)|0,g=g+Math.imul(M,pt)|0;var gi=(T+f|0)+((s&8191)<<13)|0;T=(g+(s>>>13)|0)+(gi>>>26)|0,gi&=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(q,lt)|0,s=s+Math.imul(q,ut)|0,s=s+Math.imul(F,lt)|0,g=g+Math.imul(F,ut)|0,f=f+Math.imul(_,mt)|0,s=s+Math.imul(_,pt)|0,s=s+Math.imul(U,mt)|0,g=g+Math.imul(U,pt)|0,f=f+Math.imul(O,dt)|0,s=s+Math.imul(O,ft)|0,s=s+Math.imul(M,dt)|0,g=g+Math.imul(M,ft)|0;var yi=(T+f|0)+((s&8191)<<13)|0;T=(g+(s>>>13)|0)+(yi>>>26)|0,yi&=67108863,f=Math.imul(z,st),s=Math.imul(z,ct),s=s+Math.imul(J,st)|0,g=Math.imul(J,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(q,mt)|0,s=s+Math.imul(q,pt)|0,s=s+Math.imul(F,mt)|0,g=g+Math.imul(F,pt)|0,f=f+Math.imul(_,dt)|0,s=s+Math.imul(_,ft)|0,s=s+Math.imul(U,dt)|0,g=g+Math.imul(U,ft)|0,f=f+Math.imul(O,ht)|0,s=s+Math.imul(O,gt)|0,s=s+Math.imul(M,ht)|0,g=g+Math.imul(M,gt)|0;var bi=(T+f|0)+((s&8191)<<13)|0;T=(g+(s>>>13)|0)+(bi>>>26)|0,bi&=67108863,f=Math.imul(X,st),s=Math.imul(X,ct),s=s+Math.imul(Y,st)|0,g=Math.imul(Y,ct),f=f+Math.imul(z,lt)|0,s=s+Math.imul(z,ut)|0,s=s+Math.imul(J,lt)|0,g=g+Math.imul(J,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(q,dt)|0,s=s+Math.imul(q,ft)|0,s=s+Math.imul(F,dt)|0,g=g+Math.imul(F,ft)|0,f=f+Math.imul(_,ht)|0,s=s+Math.imul(_,gt)|0,s=s+Math.imul(U,ht)|0,g=g+Math.imul(U,gt)|0,f=f+Math.imul(O,yt)|0,s=s+Math.imul(O,bt)|0,s=s+Math.imul(M,yt)|0,g=g+Math.imul(M,bt)|0;var Si=(T+f|0)+((s&8191)<<13)|0;T=(g+(s>>>13)|0)+(Si>>>26)|0,Si&=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(X,lt)|0,s=s+Math.imul(X,ut)|0,s=s+Math.imul(Y,lt)|0,g=g+Math.imul(Y,ut)|0,f=f+Math.imul(z,mt)|0,s=s+Math.imul(z,pt)|0,s=s+Math.imul(J,mt)|0,g=g+Math.imul(J,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(q,ht)|0,s=s+Math.imul(q,gt)|0,s=s+Math.imul(F,ht)|0,g=g+Math.imul(F,gt)|0,f=f+Math.imul(_,yt)|0,s=s+Math.imul(_,bt)|0,s=s+Math.imul(U,yt)|0,g=g+Math.imul(U,bt)|0,f=f+Math.imul(O,St)|0,s=s+Math.imul(O,Tt)|0,s=s+Math.imul(M,St)|0,g=g+Math.imul(M,Tt)|0;var Ti=(T+f|0)+((s&8191)<<13)|0;T=(g+(s>>>13)|0)+(Ti>>>26)|0,Ti&=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(X,mt)|0,s=s+Math.imul(X,pt)|0,s=s+Math.imul(Y,mt)|0,g=g+Math.imul(Y,pt)|0,f=f+Math.imul(z,dt)|0,s=s+Math.imul(z,ft)|0,s=s+Math.imul(J,dt)|0,g=g+Math.imul(J,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(q,yt)|0,s=s+Math.imul(q,bt)|0,s=s+Math.imul(F,yt)|0,g=g+Math.imul(F,bt)|0,f=f+Math.imul(_,St)|0,s=s+Math.imul(_,Tt)|0,s=s+Math.imul(U,St)|0,g=g+Math.imul(U,Tt)|0,f=f+Math.imul(O,wt)|0,s=s+Math.imul(O,It)|0,s=s+Math.imul(M,wt)|0,g=g+Math.imul(M,It)|0;var wi=(T+f|0)+((s&8191)<<13)|0;T=(g+(s>>>13)|0)+(wi>>>26)|0,wi&=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(X,dt)|0,s=s+Math.imul(X,ft)|0,s=s+Math.imul(Y,dt)|0,g=g+Math.imul(Y,ft)|0,f=f+Math.imul(z,ht)|0,s=s+Math.imul(z,gt)|0,s=s+Math.imul(J,ht)|0,g=g+Math.imul(J,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(q,St)|0,s=s+Math.imul(q,Tt)|0,s=s+Math.imul(F,St)|0,g=g+Math.imul(F,Tt)|0,f=f+Math.imul(_,wt)|0,s=s+Math.imul(_,It)|0,s=s+Math.imul(U,wt)|0,g=g+Math.imul(U,It)|0,f=f+Math.imul(O,Ct)|0,s=s+Math.imul(O,kt)|0,s=s+Math.imul(M,Ct)|0,g=g+Math.imul(M,kt)|0;var Ii=(T+f|0)+((s&8191)<<13)|0;T=(g+(s>>>13)|0)+(Ii>>>26)|0,Ii&=67108863,f=Math.imul(rt,st),s=Math.imul(rt,ct),s=s+Math.imul(it,st)|0,g=Math.imul(it,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(X,ht)|0,s=s+Math.imul(X,gt)|0,s=s+Math.imul(Y,ht)|0,g=g+Math.imul(Y,gt)|0,f=f+Math.imul(z,yt)|0,s=s+Math.imul(z,bt)|0,s=s+Math.imul(J,yt)|0,g=g+Math.imul(J,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(q,wt)|0,s=s+Math.imul(q,It)|0,s=s+Math.imul(F,wt)|0,g=g+Math.imul(F,It)|0,f=f+Math.imul(_,Ct)|0,s=s+Math.imul(_,kt)|0,s=s+Math.imul(U,Ct)|0,g=g+Math.imul(U,kt)|0,f=f+Math.imul(O,vt)|0,s=s+Math.imul(O,xt)|0,s=s+Math.imul(M,vt)|0,g=g+Math.imul(M,xt)|0;var Ci=(T+f|0)+((s&8191)<<13)|0;T=(g+(s>>>13)|0)+(Ci>>>26)|0,Ci&=67108863,f=Math.imul(rt,lt),s=Math.imul(rt,ut),s=s+Math.imul(it,lt)|0,g=Math.imul(it,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(X,yt)|0,s=s+Math.imul(X,bt)|0,s=s+Math.imul(Y,yt)|0,g=g+Math.imul(Y,bt)|0,f=f+Math.imul(z,St)|0,s=s+Math.imul(z,Tt)|0,s=s+Math.imul(J,St)|0,g=g+Math.imul(J,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(q,Ct)|0,s=s+Math.imul(q,kt)|0,s=s+Math.imul(F,Ct)|0,g=g+Math.imul(F,kt)|0,f=f+Math.imul(_,vt)|0,s=s+Math.imul(_,xt)|0,s=s+Math.imul(U,vt)|0,g=g+Math.imul(U,xt)|0;var ki=(T+f|0)+((s&8191)<<13)|0;T=(g+(s>>>13)|0)+(ki>>>26)|0,ki&=67108863,f=Math.imul(rt,mt),s=Math.imul(rt,pt),s=s+Math.imul(it,mt)|0,g=Math.imul(it,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(X,St)|0,s=s+Math.imul(X,Tt)|0,s=s+Math.imul(Y,St)|0,g=g+Math.imul(Y,Tt)|0,f=f+Math.imul(z,wt)|0,s=s+Math.imul(z,It)|0,s=s+Math.imul(J,wt)|0,g=g+Math.imul(J,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(q,vt)|0,s=s+Math.imul(q,xt)|0,s=s+Math.imul(F,vt)|0,g=g+Math.imul(F,xt)|0;var vi=(T+f|0)+((s&8191)<<13)|0;T=(g+(s>>>13)|0)+(vi>>>26)|0,vi&=67108863,f=Math.imul(rt,dt),s=Math.imul(rt,ft),s=s+Math.imul(it,dt)|0,g=Math.imul(it,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(X,wt)|0,s=s+Math.imul(X,It)|0,s=s+Math.imul(Y,wt)|0,g=g+Math.imul(Y,It)|0,f=f+Math.imul(z,Ct)|0,s=s+Math.imul(z,kt)|0,s=s+Math.imul(J,Ct)|0,g=g+Math.imul(J,kt)|0,f=f+Math.imul(G,vt)|0,s=s+Math.imul(G,xt)|0,s=s+Math.imul(Q,vt)|0,g=g+Math.imul(Q,xt)|0;var xi=(T+f|0)+((s&8191)<<13)|0;T=(g+(s>>>13)|0)+(xi>>>26)|0,xi&=67108863,f=Math.imul(rt,ht),s=Math.imul(rt,gt),s=s+Math.imul(it,ht)|0,g=Math.imul(it,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(X,Ct)|0,s=s+Math.imul(X,kt)|0,s=s+Math.imul(Y,Ct)|0,g=g+Math.imul(Y,kt)|0,f=f+Math.imul(z,vt)|0,s=s+Math.imul(z,xt)|0,s=s+Math.imul(J,vt)|0,g=g+Math.imul(J,xt)|0;var Di=(T+f|0)+((s&8191)<<13)|0;T=(g+(s>>>13)|0)+(Di>>>26)|0,Di&=67108863,f=Math.imul(rt,yt),s=Math.imul(rt,bt),s=s+Math.imul(it,yt)|0,g=Math.imul(it,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(X,vt)|0,s=s+Math.imul(X,xt)|0,s=s+Math.imul(Y,vt)|0,g=g+Math.imul(Y,xt)|0;var Ai=(T+f|0)+((s&8191)<<13)|0;T=(g+(s>>>13)|0)+(Ai>>>26)|0,Ai&=67108863,f=Math.imul(rt,St),s=Math.imul(rt,Tt),s=s+Math.imul(it,St)|0,g=Math.imul(it,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,xt)|0,s=s+Math.imul(tt,vt)|0,g=g+Math.imul(tt,xt)|0;var Oi=(T+f|0)+((s&8191)<<13)|0;T=(g+(s>>>13)|0)+(Oi>>>26)|0,Oi&=67108863,f=Math.imul(rt,wt),s=Math.imul(rt,It),s=s+Math.imul(it,wt)|0,g=Math.imul(it,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,xt)|0,s=s+Math.imul(nt,vt)|0,g=g+Math.imul(nt,xt)|0;var Mi=(T+f|0)+((s&8191)<<13)|0;T=(g+(s>>>13)|0)+(Mi>>>26)|0,Mi&=67108863,f=Math.imul(rt,Ct),s=Math.imul(rt,kt),s=s+Math.imul(it,Ct)|0,g=Math.imul(it,kt),f=f+Math.imul(ot,vt)|0,s=s+Math.imul(ot,xt)|0,s=s+Math.imul(at,vt)|0,g=g+Math.imul(at,xt)|0;var Pi=(T+f|0)+((s&8191)<<13)|0;T=(g+(s>>>13)|0)+(Pi>>>26)|0,Pi&=67108863,f=Math.imul(rt,vt),s=Math.imul(rt,xt),s=s+Math.imul(it,vt)|0,g=Math.imul(it,xt);var Bi=(T+f|0)+((s&8191)<<13)|0;return T=(g+(s>>>13)|0)+(Bi>>>26)|0,Bi&=67108863,b[0]=fi,b[1]=hi,b[2]=gi,b[3]=yi,b[4]=bi,b[5]=Si,b[6]=Ti,b[7]=wi,b[8]=Ii,b[9]=Ci,b[10]=ki,b[11]=vi,b[12]=xi,b[13]=Di,b[14]=Ai,b[15]=Oi,b[16]=Mi,b[17]=Pi,b[18]=Bi,T!==0&&(b[19]=T,m.length++),m};Math.imul||(V=L);function _t(y,i,l){l.negative=i.negative^y.negative,l.length=y.length+i.length;for(var m=0,p=0,h=0;h<l.length-1;h++){var b=p;p=0;for(var T=m&67108863,f=Math.min(h,i.length-1),s=Math.max(0,h-y.length+1);s<=f;s++){var g=h-s,D=y.words[g]|0,O=i.words[s]|0,M=D*O,E=M&67108863;b=b+(M/67108864|0)|0,E=E+T|0,T=E&67108863,b=b+(E>>>26)|0,p+=b>>>26,b&=67108863}l.words[h]=T,m=b,b=p}return m!==0?l.words[h]=m:l.length--,l._strip()}function Rt(y,i,l){return _t(y,i,l)}o.prototype.mulTo=function(i,l){var m,p=this.length+i.length;return this.length===10&&i.length===10?m=V(this,i,l):p<63?m=L(this,i,l):p<1024?m=_t(this,i,l):m=Rt(this,i,l),m};function Et(y,i){this.x=y,this.y=i}Et.prototype.makeRBT=function(i){for(var l=new Array(i),m=o.prototype._countBits(i)-1,p=0;p<i;p++)l[p]=this.revBin(p,m,i);return l},Et.prototype.revBin=function(i,l,m){if(i===0||i===m-1)return i;for(var p=0,h=0;h<l;h++)p|=(i&1)<<l-h-1,i>>=1;return p},Et.prototype.permute=function(i,l,m,p,h,b){for(var T=0;T<b;T++)p[T]=l[i[T]],h[T]=m[i[T]]},Et.prototype.transform=function(i,l,m,p,h,b){this.permute(b,i,l,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 O=s,M=g,E=0;E<T;E++){var _=m[D+E],U=p[D+E],se=m[D+E+T],q=p[D+E+T],F=O*se-M*q;q=O*q+M*se,se=F,m[D+E]=_+se,p[D+E]=U+q,m[D+E+T]=_-se,p[D+E+T]=U-q,E!==f&&(F=s*O-g*M,M=s*M+g*O,O=F)}},Et.prototype.guessLen13b=function(i,l){var m=Math.max(l,i)|1,p=m&1,h=0;for(m=m/2|0;m;m=m>>>1)h++;return 1<<h+1+p},Et.prototype.conjugate=function(i,l,m){if(!(m<=1))for(var p=0;p<m/2;p++){var h=i[p];i[p]=i[m-p-1],i[m-p-1]=h,h=l[p],l[p]=-l[m-p-1],l[m-p-1]=-h}},Et.prototype.normalize13b=function(i,l){for(var m=0,p=0;p<l/2;p++){var h=Math.round(i[2*p+1]/l)*8192+Math.round(i[2*p]/l)+m;i[p]=h&67108863,h<67108864?m=0:m=h/67108864|0}return i},Et.prototype.convert13b=function(i,l,m,p){for(var h=0,b=0;b<l;b++)h=h+(i[b]|0),m[2*b]=h&8191,h=h>>>13,m[2*b+1]=h&8191,h=h>>>13;for(b=2*l;b<p;++b)m[b]=0;t(h===0),t((h&-8192)===0)},Et.prototype.stub=function(i){for(var l=new Array(i),m=0;m<i;m++)l[m]=0;return l},Et.prototype.mulp=function(i,l,m){var p=2*this.guessLen13b(i.length,l.length),h=this.makeRBT(p),b=this.stub(p),T=new Array(p),f=new Array(p),s=new Array(p),g=new Array(p),D=new Array(p),O=new Array(p),M=m.words;M.length=p,this.convert13b(i.words,i.length,T,p),this.convert13b(l.words,l.length,g,p),this.transform(T,b,f,s,p,h),this.transform(g,b,D,O,p,h);for(var E=0;E<p;E++){var _=f[E]*D[E]-s[E]*O[E];s[E]=f[E]*O[E]+s[E]*D[E],f[E]=_}return this.conjugate(f,s,p),this.transform(f,s,M,b,p,h),this.conjugate(M,b,p),this.normalize13b(M,p),m.negative=i.negative^l.negative,m.length=i.length+l.length,m._strip()},o.prototype.mul=function(i){var l=new o(null);return l.words=new Array(this.length+i.length),this.mulTo(i,l)},o.prototype.mulf=function(i){var l=new o(null);return l.words=new Array(this.length+i.length),Rt(this,i,l)},o.prototype.imul=function(i){return this.clone().mulTo(i,this)},o.prototype.imuln=function(i){var l=i<0;l&&(i=-i),t(typeof i=="number"),t(i<67108864);for(var m=0,p=0;p<this.length;p++){var h=(this.words[p]|0)*i,b=(h&67108863)+(m&67108863);m>>=26,m+=h/67108864|0,m+=b>>>26,this.words[p]=b&67108863}return m!==0&&(this.words[p]=m,this.length++),l?this.ineg():this},o.prototype.muln=function(i){return this.clone().imuln(i)},o.prototype.sqr=function(){return this.mul(this)},o.prototype.isqr=function(){return this.imul(this.clone())},o.prototype.pow=function(i){var l=P(i);if(l.length===0)return new o(1);for(var m=this,p=0;p<l.length&&l[p]===0;p++,m=m.sqr());if(++p<l.length)for(var h=m.sqr();p<l.length;p++,h=h.sqr())l[p]!==0&&(m=m.mul(h));return m},o.prototype.iushln=function(i){t(typeof i=="number"&&i>=0);var l=i%26,m=(i-l)/26,p=67108863>>>26-l<<26-l,h;if(l!==0){var b=0;for(h=0;h<this.length;h++){var T=this.words[h]&p,f=(this.words[h]|0)-T<<l;this.words[h]=f|b,b=T>>>26-l}b&&(this.words[h]=b,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(i){return t(this.negative===0),this.iushln(i)},o.prototype.iushrn=function(i,l,m){t(typeof i=="number"&&i>=0);var p;l?p=(l-l%26)/26:p=0;var h=i%26,b=Math.min((i-h)/26,this.length),T=67108863^67108863>>>h<<h,f=m;if(p-=b,p=Math.max(0,p),f){for(var s=0;s<b;s++)f.words[s]=this.words[s];f.length=b}if(b!==0)if(this.length>b)for(this.length-=b,s=0;s<this.length;s++)this.words[s]=this.words[s+b];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(i,l,m){return t(this.negative===0),this.iushrn(i,l,m)},o.prototype.shln=function(i){return this.clone().ishln(i)},o.prototype.ushln=function(i){return this.clone().iushln(i)},o.prototype.shrn=function(i){return this.clone().ishrn(i)},o.prototype.ushrn=function(i){return this.clone().iushrn(i)},o.prototype.testn=function(i){t(typeof i=="number"&&i>=0);var l=i%26,m=(i-l)/26,p=1<<l;if(this.length<=m)return!1;var h=this.words[m];return!!(h&p)},o.prototype.imaskn=function(i){t(typeof i=="number"&&i>=0);var l=i%26,m=(i-l)/26;if(t(this.negative===0,"imaskn works only with positive numbers"),this.length<=m)return this;if(l!==0&&m++,this.length=Math.min(m,this.length),l!==0){var p=67108863^67108863>>>l<<l;this.words[this.length-1]&=p}return this._strip()},o.prototype.maskn=function(i){return this.clone().imaskn(i)},o.prototype.iaddn=function(i){return t(typeof i=="number"),t(i<67108864),i<0?this.isubn(-i):this.negative!==0?this.length===1&&(this.words[0]|0)<=i?(this.words[0]=i-(this.words[0]|0),this.negative=0,this):(this.negative=0,this.isubn(i),this.negative=1,this):this._iaddn(i)},o.prototype._iaddn=function(i){this.words[0]+=i;for(var l=0;l<this.length&&this.words[l]>=67108864;l++)this.words[l]-=67108864,l===this.length-1?this.words[l+1]=1:this.words[l+1]++;return this.length=Math.max(this.length,l+1),this},o.prototype.isubn=function(i){if(t(typeof i=="number"),t(i<67108864),i<0)return this.iaddn(-i);if(this.negative!==0)return this.negative=0,this.iaddn(i),this.negative=1,this;if(this.words[0]-=i,this.length===1&&this.words[0]<0)this.words[0]=-this.words[0],this.negative=1;else for(var l=0;l<this.length&&this.words[l]<0;l++)this.words[l]+=67108864,this.words[l+1]-=1;return this._strip()},o.prototype.addn=function(i){return this.clone().iaddn(i)},o.prototype.subn=function(i){return this.clone().isubn(i)},o.prototype.iabs=function(){return this.negative=0,this},o.prototype.abs=function(){return this.clone().iabs()},o.prototype._ishlnsubmul=function(i,l,m){var p=i.length+m,h;this._expand(p);var b,T=0;for(h=0;h<i.length;h++){b=(this.words[h+m]|0)+T;var f=(i.words[h]|0)*l;b-=f&67108863,T=(b>>26)-(f/67108864|0),this.words[h+m]=b&67108863}for(;h<this.length-m;h++)b=(this.words[h+m]|0)+T,T=b>>26,this.words[h+m]=b&67108863;if(T===0)return this._strip();for(t(T===-1),T=0,h=0;h<this.length;h++)b=-(this.words[h]|0)+T,T=b>>26,this.words[h]=b&67108863;return this.negative=1,this._strip()},o.prototype._wordDiv=function(i,l){var m=this.length-i.length,p=this.clone(),h=i,b=h.words[h.length-1]|0,T=this._countBits(b);m=26-T,m!==0&&(h=h.ushln(m),p.iushln(m),b=h.words[h.length-1]|0);var f=p.length-h.length,s;if(l!=="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 O=f-1;O>=0;O--){var M=(p.words[h.length+O]|0)*67108864+(p.words[h.length+O-1]|0);for(M=Math.min(M/b|0,67108863),p._ishlnsubmul(h,M,O);p.negative!==0;)M--,p.negative=0,p._ishlnsubmul(h,1,O),p.isZero()||(p.negative^=1);s&&(s.words[O]=M)}return s&&s._strip(),p._strip(),l!=="div"&&m!==0&&p.iushrn(m),{div:s||null,mod:p}},o.prototype.divmod=function(i,l,m){if(t(!i.isZero()),this.isZero())return{div:new o(0),mod:new o(0)};var p,h,b;return this.negative!==0&&i.negative===0?(b=this.neg().divmod(i,l),l!=="mod"&&(p=b.div.neg()),l!=="div"&&(h=b.mod.neg(),m&&h.negative!==0&&h.iadd(i)),{div:p,mod:h}):this.negative===0&&i.negative!==0?(b=this.divmod(i.neg(),l),l!=="mod"&&(p=b.div.neg()),{div:p,mod:b.mod}):this.negative&i.negative?(b=this.neg().divmod(i.neg(),l),l!=="div"&&(h=b.mod.neg(),m&&h.negative!==0&&h.isub(i)),{div:b.div,mod:h}):i.length>this.length||this.cmp(i)<0?{div:new o(0),mod:this}:i.length===1?l==="div"?{div:this.divn(i.words[0]),mod:null}:l==="mod"?{div:null,mod:new o(this.modrn(i.words[0]))}:{div:this.divn(i.words[0]),mod:new o(this.modrn(i.words[0]))}:this._wordDiv(i,l)},o.prototype.div=function(i){return this.divmod(i,"div",!1).div},o.prototype.mod=function(i){return this.divmod(i,"mod",!1).mod},o.prototype.umod=function(i){return this.divmod(i,"mod",!0).mod},o.prototype.divRound=function(i){var l=this.divmod(i);if(l.mod.isZero())return l.div;var m=l.div.negative!==0?l.mod.isub(i):l.mod,p=i.ushrn(1),h=i.andln(1),b=m.cmp(p);return b<0||h===1&&b===0?l.div:l.div.negative!==0?l.div.isubn(1):l.div.iaddn(1)},o.prototype.modrn=function(i){var l=i<0;l&&(i=-i),t(i<=67108863);for(var m=(1<<26)%i,p=0,h=this.length-1;h>=0;h--)p=(m*p+(this.words[h]|0))%i;return l?-p:p},o.prototype.modn=function(i){return this.modrn(i)},o.prototype.idivn=function(i){var l=i<0;l&&(i=-i),t(i<=67108863);for(var m=0,p=this.length-1;p>=0;p--){var h=(this.words[p]|0)+m*67108864;this.words[p]=h/i|0,m=h%i}return this._strip(),l?this.ineg():this},o.prototype.divn=function(i){return this.clone().idivn(i)},o.prototype.egcd=function(i){t(i.negative===0),t(!i.isZero());var l=this,m=i.clone();l.negative!==0?l=l.umod(i):l=l.clone();for(var p=new o(1),h=new o(0),b=new o(0),T=new o(1),f=0;l.isEven()&&m.isEven();)l.iushrn(1),m.iushrn(1),++f;for(var s=m.clone(),g=l.clone();!l.isZero();){for(var D=0,O=1;!(l.words[0]&O)&&D<26;++D,O<<=1);if(D>0)for(l.iushrn(D);D-- >0;)(p.isOdd()||h.isOdd())&&(p.iadd(s),h.isub(g)),p.iushrn(1),h.iushrn(1);for(var M=0,E=1;!(m.words[0]&E)&&M<26;++M,E<<=1);if(M>0)for(m.iushrn(M);M-- >0;)(b.isOdd()||T.isOdd())&&(b.iadd(s),T.isub(g)),b.iushrn(1),T.iushrn(1);l.cmp(m)>=0?(l.isub(m),p.isub(b),h.isub(T)):(m.isub(l),b.isub(p),T.isub(h))}return{a:b,b:T,gcd:m.iushln(f)}},o.prototype._invmp=function(i){t(i.negative===0),t(!i.isZero());var l=this,m=i.clone();l.negative!==0?l=l.umod(i):l=l.clone();for(var p=new o(1),h=new o(0),b=m.clone();l.cmpn(1)>0&&m.cmpn(1)>0;){for(var T=0,f=1;!(l.words[0]&f)&&T<26;++T,f<<=1);if(T>0)for(l.iushrn(T);T-- >0;)p.isOdd()&&p.iadd(b),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(b),h.iushrn(1);l.cmp(m)>=0?(l.isub(m),p.isub(h)):(m.isub(l),h.isub(p))}var D;return l.cmpn(1)===0?D=p:D=h,D.cmpn(0)<0&&D.iadd(i),D},o.prototype.gcd=function(i){if(this.isZero())return i.abs();if(i.isZero())return this.abs();var l=this.clone(),m=i.clone();l.negative=0,m.negative=0;for(var p=0;l.isEven()&&m.isEven();p++)l.iushrn(1),m.iushrn(1);do{for(;l.isEven();)l.iushrn(1);for(;m.isEven();)m.iushrn(1);var h=l.cmp(m);if(h<0){var b=l;l=m,m=b}else if(h===0||m.cmpn(1)===0)break;l.isub(m)}while(!0);return m.iushln(p)},o.prototype.invm=function(i){return this.egcd(i).a.umod(i)},o.prototype.isEven=function(){return(this.words[0]&1)===0},o.prototype.isOdd=function(){return(this.words[0]&1)===1},o.prototype.andln=function(i){return this.words[0]&i},o.prototype.bincn=function(i){t(typeof i=="number");var l=i%26,m=(i-l)/26,p=1<<l;if(this.length<=m)return this._expand(m+1),this.words[m]|=p,this;for(var h=p,b=m;h!==0&&b<this.length;b++){var T=this.words[b]|0;T+=h,h=T>>>26,T&=67108863,this.words[b]=T}return h!==0&&(this.words[b]=h,this.length++),this},o.prototype.isZero=function(){return this.length===1&&this.words[0]===0},o.prototype.cmpn=function(i){var l=i<0;if(this.negative!==0&&!l)return-1;if(this.negative===0&&l)return 1;this._strip();var m;if(this.length>1)m=1;else{l&&(i=-i),t(i<=67108863,"Number is too big");var p=this.words[0]|0;m=p===i?0:p<i?-1:1}return this.negative!==0?-m|0:m},o.prototype.cmp=function(i){if(this.negative!==0&&i.negative===0)return-1;if(this.negative===0&&i.negative!==0)return 1;var l=this.ucmp(i);return this.negative!==0?-l|0:l},o.prototype.ucmp=function(i){if(this.length>i.length)return 1;if(this.length<i.length)return-1;for(var l=0,m=this.length-1;m>=0;m--){var p=this.words[m]|0,h=i.words[m]|0;if(p!==h){p<h?l=-1:p>h&&(l=1);break}}return l},o.prototype.gtn=function(i){return this.cmpn(i)===1},o.prototype.gt=function(i){return this.cmp(i)===1},o.prototype.gten=function(i){return this.cmpn(i)>=0},o.prototype.gte=function(i){return this.cmp(i)>=0},o.prototype.ltn=function(i){return this.cmpn(i)===-1},o.prototype.lt=function(i){return this.cmp(i)===-1},o.prototype.lten=function(i){return this.cmpn(i)<=0},o.prototype.lte=function(i){return this.cmp(i)<=0},o.prototype.eqn=function(i){return this.cmpn(i)===0},o.prototype.eq=function(i){return this.cmp(i)===0},o.red=function(i){return new $(i)},o.prototype.toRed=function(i){return t(!this.red,"Already a number in reduction context"),t(this.negative===0,"red works only with positives"),i.convertTo(this)._forceRed(i)},o.prototype.fromRed=function(){return t(this.red,"fromRed works only with numbers in reduction context"),this.red.convertFrom(this)},o.prototype._forceRed=function(i){return this.red=i,this},o.prototype.forceRed=function(i){return t(!this.red,"Already a number in reduction context"),this._forceRed(i)},o.prototype.redAdd=function(i){return t(this.red,"redAdd works only with red numbers"),this.red.add(this,i)},o.prototype.redIAdd=function(i){return t(this.red,"redIAdd works only with red numbers"),this.red.iadd(this,i)},o.prototype.redSub=function(i){return t(this.red,"redSub works only with red numbers"),this.red.sub(this,i)},o.prototype.redISub=function(i){return t(this.red,"redISub works only with red numbers"),this.red.isub(this,i)},o.prototype.redShl=function(i){return t(this.red,"redShl works only with red numbers"),this.red.shl(this,i)},o.prototype.redMul=function(i){return t(this.red,"redMul works only with red numbers"),this.red._verify2(this,i),this.red.mul(this,i)},o.prototype.redIMul=function(i){return t(this.red,"redMul works only with red numbers"),this.red._verify2(this,i),this.red.imul(this,i)},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(i){return t(this.red&&!i.red,"redPow(normalNum)"),this.red._verify1(this),this.red.pow(this,i)};var pi={k256:null,p224:null,p192:null,p25519:null};function jt(y,i){this.name=y,this.p=new o(i,16),this.n=this.p.bitLength(),this.k=new o(1).iushln(this.n).isub(this.p),this.tmp=this._tmp()}jt.prototype._tmp=function(){var i=new o(null);return i.words=new Array(Math.ceil(this.n/13)),i},jt.prototype.ireduce=function(i){var l=i,m;do this.split(l,this.tmp),l=this.imulK(l),l=l.iadd(this.tmp),m=l.bitLength();while(m>this.n);var p=m<this.n?-1:l.ucmp(this.p);return p===0?(l.words[0]=0,l.length=1):p>0?l.isub(this.p):l.strip!==void 0?l.strip():l._strip(),l},jt.prototype.split=function(i,l){i.iushrn(this.n,0,l)},jt.prototype.imulK=function(i){return i.imul(this.k)};function Ln(){jt.call(this,"k256","ffffffff ffffffff ffffffff ffffffff ffffffff ffffffff fffffffe fffffc2f")}n(Ln,jt),Ln.prototype.split=function(i,l){for(var m=4194303,p=Math.min(i.length,9),h=0;h<p;h++)l.words[h]=i.words[h];if(l.length=p,i.length<=9){i.words[0]=0,i.length=1;return}var b=i.words[9];for(l.words[l.length++]=b&m,h=10;h<i.length;h++){var T=i.words[h]|0;i.words[h-10]=(T&m)<<4|b>>>22,b=T}b>>>=22,i.words[h-10]=b,b===0&&i.length>10?i.length-=10:i.length-=9},Ln.prototype.imulK=function(i){i.words[i.length]=0,i.words[i.length+1]=0,i.length+=2;for(var l=0,m=0;m<i.length;m++){var p=i.words[m]|0;l+=p*977,i.words[m]=l&67108863,l=p*64+(l/67108864|0)}return i.words[i.length-1]===0&&(i.length--,i.words[i.length-1]===0&&i.length--),i};function As(){jt.call(this,"p224","ffffffff ffffffff ffffffff ffffffff 00000000 00000000 00000001")}n(As,jt);function Os(){jt.call(this,"p192","ffffffff ffffffff ffffffff fffffffe ffffffff ffffffff")}n(Os,jt);function di(){jt.call(this,"25519","7fffffffffffffff ffffffffffffffff ffffffffffffffff ffffffffffffffed")}n(di,jt),di.prototype.imulK=function(i){for(var l=0,m=0;m<i.length;m++){var p=(i.words[m]|0)*19+l,h=p&67108863;p>>>=26,i.words[m]=h,l=p}return l!==0&&(i.words[i.length++]=l),i},o._prime=function(i){if(pi[i])return pi[i];var l;if(i==="k256")l=new Ln;else if(i==="p224")l=new As;else if(i==="p192")l=new Os;else if(i==="p25519")l=new di;else throw new Error("Unknown prime "+i);return pi[i]=l,l};function $(y){if(typeof y=="string"){var i=o._prime(y);this.m=i.p,this.prime=i}else t(y.gtn(1),"modulus must be greater than 1"),this.m=y,this.prime=null}$.prototype._verify1=function(i){t(i.negative===0,"red works only with positives"),t(i.red,"red works only with red numbers")},$.prototype._verify2=function(i,l){t((i.negative|l.negative)===0,"red works only with positives"),t(i.red&&i.red===l.red,"red works only with red numbers")},$.prototype.imod=function(i){return this.prime?this.prime.ireduce(i)._forceRed(this):(S(i,i.umod(this.m)._forceRed(this)),i)},$.prototype.neg=function(i){return i.isZero()?i.clone():this.m.sub(i)._forceRed(this)},$.prototype.add=function(i,l){this._verify2(i,l);var m=i.add(l);return m.cmp(this.m)>=0&&m.isub(this.m),m._forceRed(this)},$.prototype.iadd=function(i,l){this._verify2(i,l);var m=i.iadd(l);return m.cmp(this.m)>=0&&m.isub(this.m),m},$.prototype.sub=function(i,l){this._verify2(i,l);var m=i.sub(l);return m.cmpn(0)<0&&m.iadd(this.m),m._forceRed(this)},$.prototype.isub=function(i,l){this._verify2(i,l);var m=i.isub(l);return m.cmpn(0)<0&&m.iadd(this.m),m},$.prototype.shl=function(i,l){return this._verify1(i),this.imod(i.ushln(l))},$.prototype.imul=function(i,l){return this._verify2(i,l),this.imod(i.imul(l))},$.prototype.mul=function(i,l){return this._verify2(i,l),this.imod(i.mul(l))},$.prototype.isqr=function(i){return this.imul(i,i.clone())},$.prototype.sqr=function(i){return this.mul(i,i)},$.prototype.sqrt=function(i){if(i.isZero())return i.clone();var l=this.m.andln(3);if(t(l%2===1),l===3){var m=this.m.add(new o(1)).iushrn(2);return this.pow(i,m)}for(var p=this.m.subn(1),h=0;!p.isZero()&&p.andln(1)===0;)h++,p.iushrn(1);t(!p.isZero());var b=new o(1).toRed(this),T=b.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(i,p.addn(1).iushrn(1)),O=this.pow(i,p),M=h;O.cmp(b)!==0;){for(var E=O,_=0;E.cmp(b)!==0;_++)E=E.redSqr();t(_<M);var U=this.pow(g,new o(1).iushln(M-_-1));D=D.redMul(U),g=U.redSqr(),O=O.redMul(g),M=_}return D},$.prototype.invm=function(i){var l=i._invmp(this.m);return l.negative!==0?(l.negative=0,this.imod(l).redNeg()):this.imod(l)},$.prototype.pow=function(i,l){if(l.isZero())return new o(1).toRed(this);if(l.cmpn(1)===0)return i.clone();var m=4,p=new Array(1<<m);p[0]=new o(1).toRed(this),p[1]=i;for(var h=2;h<p.length;h++)p[h]=this.mul(p[h-1],i);var b=p[0],T=0,f=0,s=l.bitLength()%26;for(s===0&&(s=26),h=l.length-1;h>=0;h--){for(var g=l.words[h],D=s-1;D>=0;D--){var O=g>>D&1;if(b!==p[0]&&(b=this.sqr(b)),O===0&&T===0){f=0;continue}T<<=1,T|=O,f++,!(f!==m&&(h!==0||D!==0))&&(b=this.mul(b,p[T]),f=0,T=0)}s=26}return b},$.prototype.convertTo=function(i){var l=i.umod(this.m);return l===i?l.clone():l},$.prototype.convertFrom=function(i){var l=i.clone();return l.red=null,l},o.mont=function(i){return new Pe(i)};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(i){return this.imod(i.ushln(this.shift))},Pe.prototype.convertFrom=function(i){var l=this.imod(i.mul(this.rinv));return l.red=null,l},Pe.prototype.imul=function(i,l){if(i.isZero()||l.isZero())return i.words[0]=0,i.length=1,i;var m=i.imul(l),p=m.maskn(this.shift).mul(this.minv).imaskn(this.shift).mul(this.m),h=m.isub(p).iushrn(this.shift),b=h;return h.cmp(this.m)>=0?b=h.isub(this.m):h.cmpn(0)<0&&(b=h.iadd(this.m)),b._forceRed(this)},Pe.prototype.mul=function(i,l){if(i.isZero()||l.isZero())return new o(0)._forceRed(this);var m=i.mul(l),p=m.maskn(this.shift).mul(this.minv).imaskn(this.shift).mul(this.m),h=m.isub(p).iushrn(this.shift),b=h;return h.cmp(this.m)>=0?b=h.isub(this.m):h.cmpn(0)<0&&(b=h.iadd(this.m)),b._forceRed(this)},Pe.prototype.invm=function(i){var l=this.imod(i._invmp(this.m).mul(this.r2));return l._forceRed(this)}})(typeof Ds>"u"||Ds,Km)});var wd={};Ri(wd,{appHelpers:()=>Td});module.exports=hp(wd);var tc=require("@msafe/sui3-utils");var oe=require("@alphafi/alphafi-sdk"),Le=require("@msafe/sui3-utils"),Jt=require("@mysten/bcs");var Un=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=oe.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&&oe.poolInfo[t].assetTypes.length===2}isSingleAssetDepositEvent(e,t){return e.event_type===0&&oe.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=Jt.bcs.u64().parse((0,Jt.fromBase64)(t)):t.length===24?n=Jt.bcs.u128().parse((0,Jt.fromBase64)(t)):t.length===44?n=Jt.bcs.u256().parse((0,Jt.fromBase64)(t)):n=Jt.bcs.u64().parse((0,Jt.fromBase64)(t)),n}decodeDoubleAssetDeposit(e,t){let{amount_a:n,amount_b:o}=t,r=Number(n)>0;return console.log("Decoder.decodeDoubleAssetDeposit",n,o,r),{txType:Le.TransactionType.Other,type:"depositDoubleAsset",intentionData:{poolName:e,amount:r?n:o,isAmountA:r}}}decodeSingleAssetDeposit(e,t){let{amount:n}=t;if(console.log("Decoder.decodeSingleAssetDeposit",n),this.getLiquidityChangeEvent().type.includes(":alphafi_navi_pool:")){let{coin:r}=oe.singleAssetPoolCoinMap[e],{expo:c}=oe.coinsList[r];n=Math.floor(Number(n)/10**(9-c)).toString()}return{txType:Le.TransactionType.Other,type:"depositSingleAsset",intentionData:{poolName:e,amount:n}}}decodeWithdraw(e){let t=this.extractXTokensAmount();return console.log("Decoder.decodeWithdraw",t),{txType:Le.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:Le.TransactionType.Other,type:"withdrawAlpha",intentionData:{withdrawFromLocked:Number(n)>0,xTokensAmount:t}}}decodeClaimReward(){return{txType:Le.TransactionType.Other,type:"claimReward",intentionData:{}}}};var zs=require("@alphafi/alphafi-sdk");var Qs=$t(require("sort-keys-recursive")),v=class{constructor(e){this.data=e}serialize(){return JSON.stringify((0,Qs.default)(this.data))}};var qn=class a extends v{constructor(t){super(t);this.data=t}txType;txSubType;async build(t){let{account:n}=t;return await(0,zs.claimRewardTxb)(n.address)}static fromData(t){return new a(t)}};var Js=require("@alphafi/alphafi-sdk");var Fn=class a extends v{constructor(t){super(t);this.data=t}txType;txSubType;async build(t){let{account:n}=t,{poolName:o,amount:r,isAmountA:c}=this.data;return await(0,Js.depositDoubleAssetTxb)(o,n.address,r,c)}static fromData(t){return console.log("DepositDoubleAssetIntention.fromData",t),new a(t)}};var Xs=require("@alphafi/alphafi-sdk");var Kn=class a extends v{constructor(t){super(t);this.data=t}txType;txSubType;async build(t){let{account:n}=t,{poolName:o,amount:r}=this.data;return await(0,Xs.depositSingleAssetTxb)(o,n.address,r)}static fromData(t){return console.log("DepositSingleAssetIntention.fromData",t),new a(t)}};var Ys=require("@alphafi/alphafi-sdk");var Vn=class a extends v{constructor(t){super(t);this.data=t}txType;txSubType;async build(t){let{account:n}=t,{poolName:o,xTokensAmount:r}=this.data;return await(0,Ys.withdrawTxb)(r,o,n.address)}static fromData(t){return console.log("WithdrawIntention.fromData",t),new a(t)}};var Zs=require("@alphafi/alphafi-sdk");var $n=class a extends v{constructor(t){super(t);this.data=t}txType;txSubType;async build(t){let{account:n}=t,{withdrawFromLocked:o,xTokensAmount:r}=this.data;return await(0,Zs.withdrawAlphaTxb)(r,o,n.address)}static fromData(t){return console.log("WithdrawAlphaIntention.fromData",t),new a(t)}};var Hn=class{application="alphafi";supportSDK="@mysten/sui";async deserialize(e){let{transaction:t,suiClient:n,account:o}=e,r=await n.devInspectTransactionBlock({sender:t.getData().sender,transactionBlock:t});console.log("AlphaFiHelper Sim result - ",r);let u=new Un(t,r).decode();return{txType:tc.TransactionType.Other,txSubType:u.type,intentionData:u.intentionData}}async build(e){let{account:t}=e;console.log("AlphaFi build transaction type",e.txSubType);let n;switch(e.txSubType){case"depositSingleAsset":n=Kn.fromData(e.intentionData);break;case"depositDoubleAsset":n=Fn.fromData(e.intentionData);break;case"withdraw":n=Vn.fromData(e.intentionData);break;case"withdrawAlpha":n=$n.fromData(e.intentionData);break;case"claimReward":n=qn.fromData(e.intentionData);break;default:throw new Error("not implemented")}return n.build({account:t})}};var vc=require("@msafe/sui3-utils");var Nt=require("@msafe/sui3-utils"),Gn=require("@mysten/sui/bcs"),Qn=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(Qn.SBUCK_FOUNTAIN_PACKAGE_ID,"fountain_core","stake")}isSBUCKUnstakeTransaction(){return!!this.getMoveCallPackageModuleCommand(Qn.SBUCK_FOUNTAIN_PACKAGE_ID,"fountain_core","force_unstake")}isSBUCKClaimTransaction(){return!!this.getMoveCallPackageModuleCommand(Qn.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:Nt.TransactionType.Other,type:"psm",intentionData:{coinType:e,amount:n,buckToCoin:t}}}decodeBorrow(){let e="",t="0",n,o=this.getStrapId(),r="0",c=this.getSplitCoinsCommands()[0].SplitCoins.amounts[0];if(c.$kind==="Input"&&(r=this.getPureInputU64(c.Input)),this.getMoveCallCommand("high_top_up")){let u=this.getMoveCallCommand("high_top_up").MoveCall;[e]=u.typeArguments;let d=u.arguments[1];d.$kind==="Input"&&(t=this.getPureInputU64(d.Input));let S=u.arguments[3];if(S.$kind==="Input"){let w=this.getPureAddresses(S.Input);w.length===1&&([n]=w)}}else if(this.getMoveCallCommand("high_borrow")){let u=this.getMoveCallCommand("high_borrow").MoveCall;[e]=u.typeArguments;let d=u.arguments[4];d.$kind==="Input"&&(t=this.getPureInputU64(d.Input));let S=u.arguments[5];if(S.$kind==="Input"){let w=this.getPureAddresses(S.Input);w.length===1&&([n]=w)}}else if(this.getMoveCallCommand("high_borrow_with_strap")){let u=this.getMoveCallCommand("high_borrow_with_strap").MoveCall;[e]=u.typeArguments;let d=u.arguments[5];d.$kind==="Input"&&(t=this.getPureInputU64(d.Input));let S=u.arguments[6];if(S.$kind==="Input"){let w=this.getPureAddresses(S.Input);w.length===1&&([n]=w)}}return{txType:Nt.TransactionType.Other,type:"borrow",intentionData:{collateralType:e,collateralAmount:r,borrowAmount:t,insertionPlace:n,strapId:o}}}decodeRepay(){let e="",t="0",n="0",r,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 u=this.getMoveCallCommand("repay_and_withdraw").MoveCall;[e]=u.typeArguments;let d=u.arguments[4];d.$kind==="Input"&&(n=this.getPureInputU64(d.Input));let S=u.arguments[5];if(S.$kind==="Input"){let I=this.getPureAddresses(S.Input);I.length===1&&([r]=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 u=this.getMoveCallCommand("repay_and_withdraw_with_strap").MoveCall;[e]=u.typeArguments;let d=u.arguments[5];d.$kind==="Input"&&(n=this.getPureInputU64(d.Input));let S=u.arguments[6];if(S.$kind==="Input"){let I=this.getPureAddresses(S.Input);I.length===1&&([r]=I)}let w=this.getSplitCoinsCommands()[0].SplitCoins.amounts[0];w.$kind==="Input"&&(t=this.getPureInputU64(w.Input))}return{txType:Nt.TransactionType.Other,type:"repay",intentionData:{collateralType:e,repayAmount:t,withdrawAmount:n,isSurplus:!1,insertionPlace:r,strapId:c}}}decodeWithdraw(){let e="",t="0",n,o=this.getStrapId();if(this.getMoveCallCommand("withdraw_with_strap")){let r=this.getMoveCallCommand("withdraw_with_strap").MoveCall;[e]=r.typeArguments;let c=r.arguments[4];c.$kind==="Input"&&(t=this.getPureInputU64(c.Input));let u=r.arguments[5];if(u.$kind==="Input"){let d=this.getPureAddresses(u.Input);d.length===1&&([n]=d)}}else if(this.getMoveCallCommand("withdraw")){let r=this.getMoveCallCommand("withdraw").MoveCall;[e]=r.typeArguments;let c=r.arguments[3];c.$kind==="Input"&&(t=this.getPureInputU64(c.Input));let u=r.arguments[4];if(u.$kind==="Input"){let d=this.getPureAddresses(u.Input);d.length===1&&([n]=d)}}return{txType:Nt.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:Nt.TransactionType.Other,type:"close",intentionData:{collateralType:e,strapId:t}}}decodeSBUCKDeposit(){let t=this.getMoveCallCommand("into_balance").MoveCall.typeArguments[0],n="0",r=this.getSplitCoinsCommands()[0].SplitCoins.amounts[0];r.$kind==="Input"&&(n=this.getPureInputU64(r.Input));let c=this.isSBUCKStakeTransaction();return console.log("Decoder.decodeSBUCKDeposit",t,n,c),{txType:Nt.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 u=0;u<o.length;u++){let d=o[u];n.push("")}else{let u=this.getMoveCallModuleCommands("fountain_core","force_unstake");for(let d=0;d<u.length;d++){let w=u[d].MoveCall.arguments[2];if(w.$kind==="Input"){let{objectId:I}=this.inputs[w.Input].UnresolvedObject;n.push(I)}}}let r=this.isSBUCKWithdrawTransaction(),c={stakeProofs:n,amount:e,isStake:t,toBuck:r};return console.log("Decoder.decodeSBUCKUnstake",c),{txType:Nt.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:Nt.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 r=t[n].MoveCall.arguments[2];if(r.$kind==="Input"){let{objectId:c}=this.inputs[r.Input].UnresolvedObject;e.push(c)}}return console.log("Decoder.decodeSBUCKClaim",e),{txType:Nt.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 r=this.getMoveCallModuleCommand("tank_operations","deposit").MoveCall.typeArguments[0];return console.log("Decoder.decodeTankDeposit",r,e),{txType:Nt.TransactionType.Other,type:"tank-deposit",intentionData:{coinType:r,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:Nt.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:Nt.TransactionType.Other,type:"tank-claim",intentionData:{coinType:t}}}decodeLockedClaim(){let e="",t=0,n=this.getMoveCallModuleCommands("proof_rule","claim");for(let r=0;r<n.length;r++)[e]=n[r].MoveCall.typeArguments,t++;let o=this.getMoveCallModuleCommands("lst_proof_rule","claim");for(let r=0;r<o.length;r++)[e]=o[r].MoveCall.typeArguments,t++;return console.log("Decoder.decodeLockedClaim",e,t),{txType:Nt.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 Gn.bcs.U64.fromBase64(t.Pure.bytes)}getPureAddresses(e){let t=this.inputs[e];if(t.$kind!=="Pure")throw new Error("not pure argument");return Gn.bcs.vector(Gn.bcs.Address).fromBase64(t.Pure.bytes)}};var rc=require("@msafe/sui3-utils");var nc=require("@mysten/sui/transactions"),oc=require("bucket-protocol-sdk");var ec=require("bucket-protocol-sdk"),Mt=(a,e)=>{let t=a==="sui:mainnet"?"mainnet":"testnet";return new ec.BucketClient(t,e.address)};var ac=async(a,e,t)=>{let{coinType:n,amount:o,buckToCoin:r}=a,c=new nc.Transaction,u=Mt(t,e);return await(0,oc.buildPsmTx)(u,c,n,o,r,e.address),c};var Jn=class a extends v{constructor(t){super(t);this.data=t}txType=rc.TransactionType.Other;txSubType="psm";async build(t){let{account:n,network:o}=t;return await ac(this.data,n,o)}static fromData(t){return new a(t)}};var uc=require("@msafe/sui3-utils");var un=require("@mysten/sui/transactions"),ce=require("bucket-protocol-sdk");var ic=async(a,e,t)=>{let{collateralType:n,collateralAmount:o,borrowAmount:r,insertionPlace:c,strapId:u}=a,d=new un.Transaction,S=Mt(t,e);return await(0,ce.buildBorrowTx)(S,d,n,o,r,e.address,c,u),d},sc=async(a,e,t)=>{let{collateralType:n,withdrawAmount:o,insertionPlace:r,strapId:c}=a,u=new un.Transaction,d=Mt(t,e);return await(0,ce.buildWithdrawTx)(d,u,n,o,e.address,r,c),u},cc=async(a,e,t)=>{let{collateralType:n,repayAmount:o,withdrawAmount:r,isSurplus:c,insertionPlace:u,strapId:d}=a,S=new un.Transaction,w=Mt(t,e);return await(0,ce.buildRepayTx)(w,S,n,o,r,e.address,c,u,d),S},lc=async(a,e,t)=>{let{collateralType:n,recipient:o,strapId:r}=a,c=new un.Transaction,u=Mt(t,e);return await(0,ce.buildCloseTx)(u,c,n,o,r),c};var Xn=class a extends v{constructor(t){super(t);this.data=t}txType=uc.TransactionType.Other;txSubType="borrow";async build(t){let{account:n,network:o}=t;return await ic(this.data,n,o)}static fromData(t){return new a(t)}};var mc=require("@msafe/sui3-utils");var Yn=class a extends v{constructor(t){super(t);this.data=t}txType=mc.TransactionType.Other;txSubType="repay";async build(t){let{account:n,network:o}=t;return await cc(this.data,n,o)}static fromData(t){return new a(t)}};var pc=require("@msafe/sui3-utils");var Zn=class a extends v{constructor(t){super(t);this.data=t}txType=pc.TransactionType.Other;txSubType="withdraw";async build(t){let{account:n,network:o}=t;return await sc(this.data,n,o)}static fromData(t){return new a(t)}};var dc=require("@msafe/sui3-utils");var to=class a extends v{constructor(t){super(t);this.data=t}txType=dc.TransactionType.Other;txSubType="close";async build(t){let{account:n,network:o}=t;return await lc(this.data,n,o)}static fromData(t){return new a(t)}};var pn=require("@msafe/sui3-utils");var mn=require("@mysten/sui/transactions"),le=require("bucket-protocol-sdk");var fc=async(a,e,t)=>{let{coinType:n,amount:o,isStake:r}=a,c=new mn.Transaction,u=Mt(t,e);return await(0,le.buildSBUCKDepositTx)(u,c,n,o,e.address,r),c},hc=async(a,e,t)=>{let{stakeProofs:n,amount:o,isStake:r,toBuck:c}=a,u=new mn.Transaction,d=Mt(t,e);return await(0,le.buildSBUCKUnstakeTx)(d,u,n,o,e.address,r,c),u},gc=async(a,e,t)=>{let{amount:n}=a,o=new mn.Transaction,r=Mt(t,e);return await(0,le.buildSBUCKWithdrawTx)(r,o,n,e.address),o},yc=async(a,e,t)=>{let{stakeProofs:n}=a,o=new mn.Transaction,r=Mt(t,e);return await(0,le.buildSBUCKClaimTx)(r,o,n,e.address),o};var eo=class a extends v{constructor(t){super(t);this.data=t}txType=pn.TransactionType.Other;txSubType="sbuck-deposit";async build(t){let{account:n,network:o}=t;return await fc(this.data,n,o)}static fromData(t){return new a(t)}},no=class a extends v{constructor(t){super(t);this.data=t}txType=pn.TransactionType.Other;txSubType="sbuck-unstake";async build(t){let{account:n,network:o}=t;return await hc(this.data,n,o)}static fromData(t){return new a(t)}},oo=class a extends v{constructor(t){super(t);this.data=t}txType=pn.TransactionType.Other;txSubType="sbuck-withdraw";async build(t){let{account:n,network:o}=t;return await gc(this.data,n,o)}static fromData(t){return new a(t)}},ao=class a extends v{constructor(t){super(t);this.data=t}txType=pn.TransactionType.Other;txSubType="sbuck-claim";async build(t){let{account:n,network:o}=t;return await yc(this.data,n,o)}static fromData(t){return new a(t)}};var lo=require("@msafe/sui3-utils");var ro=require("@mysten/sui/transactions"),je=require("bucket-protocol-sdk");var bc=async(a,e,t)=>{let{coinType:n,amount:o}=a,r=new ro.Transaction,c=Mt(t,e);return await(0,je.buildTankDepositTx)(c,r,n,o,e.address),r},Sc=async(a,e,t)=>{let{coinType:n,amount:o}=a,r=new ro.Transaction,c=Mt(t,e);return await(0,je.buildTankWithdrawTx)(c,r,n,o,e.address),r},Tc=async(a,e,t)=>{let{coinType:n}=a,o=new ro.Transaction,r=Mt(t,e);return await(0,je.buildTankClaimTx)(r,o,n,e.address),o};var wc=require("@mysten/sui/transactions"),Ic=require("bucket-protocol-sdk");var Cc=async(a,e,t)=>{let{coinType:n,proofCount:o}=a,r=new wc.Transaction,c=Mt(t,e);return await(0,Ic.buildLockedClaimTx)(c,r,n,o,e.address),r};var io=class a extends v{constructor(t){super(t);this.data=t}txType=lo.TransactionType.Other;txSubType="tank-deposit";async build(t){let{account:n,network:o}=t;return await bc(this.data,n,o)}static fromData(t){return new a(t)}},so=class a extends v{constructor(t){super(t);this.data=t}txType=lo.TransactionType.Other;txSubType="tank-withdraw";async build(t){let{account:n,network:o}=t;return await Sc(this.data,n,o)}static fromData(t){return new a(t)}},co=class a extends v{constructor(t){super(t);this.data=t}txType=lo.TransactionType.Other;txSubType="tank-claim";async build(t){let{account:n,network:o}=t;return await Tc(this.data,n,o)}static fromData(t){return new a(t)}};var kc=require("@msafe/sui3-utils");var uo=class a extends v{constructor(t){super(t);this.data=t}txType=kc.TransactionType.Other;txSubType="lock-claim";async build(t){let{account:n,network:o}=t;return await Cc(this.data,n,o)}static fromData(t){return new a(t)}};var mo=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:vc.TransactionType.Other,txSubType:o.type,intentionData:o.intentionData}}async build(e){let{suiClient:t,account:n,network:o}=e,r;switch(e.txSubType){case"psm":r=Jn.fromData(e.intentionData);break;case"borrow":r=Xn.fromData(e.intentionData);break;case"withdraw":r=Zn.fromData(e.intentionData);break;case"repay":r=Yn.fromData(e.intentionData);break;case"close":r=to.fromData(e.intentionData);break;case"tank-deposit":r=io.fromData(e.intentionData);break;case"tank-withdraw":r=so.fromData(e.intentionData);break;case"tank-claim":r=co.fromData(e.intentionData);break;case"sbuck-deposit":r=eo.fromData(e.intentionData);break;case"sbuck-unstake":r=no.fromData(e.intentionData);break;case"sbuck-withdraw":r=oo.fromData(e.intentionData);break;case"sbuck-claim":r=ao.fromData(e.intentionData);break;case"lock-claim":r=uo.fromData(e.intentionData);break;default:throw new Error("not implemented")}return r.build({suiClient:t,account:n,network:o})}};var Dl=require("@msafe/sui3-utils");var Wc=require("@msafe/sui3-utils");var po=require("@cetusprotocol/aggregator-sdk"),xc=require("@cetusprotocol/farms-sdk"),Dc=require("@cetusprotocol/sui-clmm-sdk"),Ac=require("@cetusprotocol/vaults-sdk"),Oc=require("@cetusprotocol/xcetus-sdk"),Be=require("@mysten/sui/client"),Ue=(a,e)=>{let t=Dc.CetusClmmSDK.createSDK({env:"mainnet",sui_client:new Be.SuiClient({url:(0,Be.getFullnodeUrl)("mainnet")})});return t.setSenderAddress(e.address),t},Xt=(a,e)=>{let t=xc.CetusFarmsSDK.createSDK({env:"mainnet",sui_client:new Be.SuiClient({url:(0,Be.getFullnodeUrl)("mainnet")})});return t.setSenderAddress(e.address),t},yp="https://api-sui.cetus.zone/router_v2/find_routes",Mc=(a,e)=>{let t=new Be.SuiClient({url:"https://fullnode.mainnet.sui.io/"});return new po.AggregatorClient({endpoint:yp,signer:e.address,client:t,env:po.Env.Mainnet})},Ei=(a,e)=>{let t=Ac.CetusVaultsSDK.createSDK({env:"mainnet"});return t.setSenderAddress(e.address),t},qe=(a,e)=>{let t=Oc.CetusXcetusSDK.createSDK({env:"mainnet"});return t.setSenderAddress(e.address),t};var Pc=async(a,e,t)=>await Ue(t,e).Position.createAddLiquidityFixTokenPayload(a?.parameter,a?.gasEstimateArg),Bc=async(a,e,t)=>await Ue(t,e).Position.createAddLiquidityFixTokenPayload(a?.parameter,a?.gasEstimateArg),Rc=async(a,e,t)=>await Ue(t,e).Position.closePositionPayload(a),Ec=async(a,e,t)=>await Ue(t,e).Position.removeLiquidityPayload(a),Nc=async(a,e,t)=>await Ue(t,e).Rewarder.collectRewarderPayload(a);var fo=class a extends v{constructor(t){super(t);this.data=t}txType=Wc.TransactionType.Other;txSubType="OpenAndAddLiquidity";async build(t){let{account:n,network:o}=t,{txbParams:r}=this.data;return await Pc(r,n,o)}static fromData(t){return new a(t)}};var _c=require("@msafe/sui3-utils");var ho=class a extends v{constructor(t){super(t);this.data=t}txType=_c.TransactionType.Other;txSubType="ClaimFeeAndMining";async build(t){let{account:n,network:o}=t,{txbParams:r}=this.data;return await Nc(r,n,o)}static fromData(t){return new a(t)}};var Lc=require("@msafe/sui3-utils");var go=class a extends v{constructor(t){super(t);this.data=t}txType=Lc.TransactionType.Other;txSubType="DecreaseLiquidity";async build(t){let{account:n,network:o}=t,{txbParams:r}=this.data;return await Ec(r,n,o)}static fromData(t){return new a(t)}};var Qc=require("@msafe/sui3-utils");var jc=async(a,e,t)=>await Xt(t,e).Farms.openPositionAddLiquidityStakePayload(a),Uc=async(a,e,t)=>await Xt(t,e).Farms.addLiquidityFixCoinPayload(a),qc=async(a,e,t)=>await Xt(t,e).Farms.removeLiquidityPayload(a),Fc=async(a,e,t)=>await Xt(t,e).Farms.removeLiquidityPayload(a),Kc=async(a,e,t)=>await Xt(t,e).Farms.claimFeeAndClmmReward(a),Vc=async(a,e,t)=>await Xt(t,e).Farms.harvestPayload(a),$c=async(a,e,t)=>{let n=Xt(t,e),o=Object.values(a);return await n.Farms.batchHarvestPayload(o)},Hc=async(a,e,t)=>await Xt(t,e).Farms.depositPayload(a),Gc=async(a,e,t)=>await Xt(t,e).Farms.withdrawPayload(a);var yo=class a extends v{constructor(t){super(t);this.data=t}txType=Qc.TransactionType.Other;txSubType="FarmingOpenAndAddLiquidity";async build(t){let{account:n,network:o}=t,{txbParams:r}=this.data;return await jc(r,n,o)}static fromData(t){return new a(t)}};var zc=require("@msafe/sui3-utils");var bo=class a extends v{constructor(t){super(t);this.data=t}txType=zc.TransactionType.Other;txSubType="FarmingBatchHarvest";async build(t){let{account:n,network:o}=t,{txbParams:r}=this.data;return await $c(r,n,o)}static fromData(t){return new a(t)}};var Jc=require("@msafe/sui3-utils");var So=class a extends v{constructor(t){super(t);this.data=t}txType=Jc.TransactionType.Other;txSubType="FarmingClaimFeeAndReward";async build(t){let{account:n,network:o}=t,{txbParams:r}=this.data;return await Kc(r,n,o)}static fromData(t){return new a(t)}};var Xc=require("@msafe/sui3-utils");var To=class a extends v{constructor(t){super(t);this.data=t}txType=Xc.TransactionType.Other;txSubType="FarmingDecreaseLiquidity";async build(t){let{account:n,network:o}=t,{txbParams:r}=this.data;return await qc(r,n,o)}static fromData(t){return new a(t)}};var Yc=require("@msafe/sui3-utils");var wo=class a extends v{constructor(t){super(t);this.data=t}txType=Yc.TransactionType.Other;txSubType="FarmingHarvest";async build(t){let{account:n,network:o}=t,{txbParams:r}=this.data;return await Vc(r,n,o)}static fromData(t){return new a(t)}};var Zc=require("@msafe/sui3-utils");var Io=class a extends v{constructor(t){super(t);this.data=t}txType=Zc.TransactionType.Other;txSubType="FarmingIncreaseLiquidity";async build(t){let{account:n,network:o}=t,{txbParams:r}=this.data;return await Uc(r,n,o)}static fromData(t){return new a(t)}};var tl=require("@msafe/sui3-utils");var Co=class a extends v{constructor(t){super(t);this.data=t}txType=tl.TransactionType.Other;txSubType="FarmingRemoveLiquidity";async build(t){let{account:n,network:o}=t,{txbParams:r}=this.data;return await Fc(r,n,o)}static fromData(t){return new a(t)}};var el=require("@msafe/sui3-utils");var ko=class a extends v{constructor(t){super(t);this.data=t}txType=el.TransactionType.Other;txSubType="FarmingStake";async build(t){let{account:n,network:o}=t,{txbParams:r}=this.data;return await Hc(r,n,o)}static fromData(t){return new a(t)}};var nl=require("@msafe/sui3-utils");var vo=class a extends v{constructor(t){super(t);this.data=t}txType=nl.TransactionType.Other;txSubType="FarmingUnstake";async build(t){let{account:n,network:o}=t,{txbParams:r}=this.data;return await Gc(r,n,o)}static fromData(t){return new a(t)}};var ol=require("@msafe/sui3-utils");var xo=class a extends v{constructor(t){super(t);this.data=t}txType=ol.TransactionType.Other;txSubType="IncreaseLiquidity";async build(t){let{account:n,network:o}=t,{txbParams:r}=this.data;return await Bc(r,n,o)}static fromData(t){return new a(t)}};var al=require("@msafe/sui3-utils");var Do=class a extends v{constructor(t){super(t);this.data=t}txType=al.TransactionType.Other;txSubType="RemoveLiquidity";async build(t){let{account:n,network:o}=t,{txbParams:r}=this.data;return await Rc(r,n,o)}static fromData(t){return new a(t)}};var cl=require("@msafe/sui3-utils");var rl=require("@cetusprotocol/aggregator-sdk"),il=require("@mysten/sui/transactions");var sl=async(a,e,t)=>{let n=Mc(t,e),o=new il.Transaction;return await n.fastRouterSwap({...a,routers:(0,rl.restituteMsafeFastRouterSwapParams)(a.routers),txb:o}),o};var Ao=class a extends v{constructor(t){super(t);this.data=t}txType=cl.TransactionType.Other;txSubType="AggregatorSwap";async build(t){let{account:n,network:o}=t,{txbParams:r}=this.data;return await sl(r,n,o)}static fromData(t){return new a(t)}};var ml=require("@msafe/sui3-utils");var Ni=require("@mysten/sui/transactions");var ll=async(a,e,t)=>{let n=Ei(t,e),o=new Ni.Transaction;return o.setSender(e.address),await n.Vaults.deposit(a,o),o},ul=async(a,e,t)=>{let n=Ei(t,e),o=new Ni.Transaction;return await n.Vaults.withdraw(a,o),o};var Oo=class a extends v{constructor(t){super(t);this.data=t}txType=ml.TransactionType.Other;txSubType="AddVaultsPosition";async build(t){let{account:n,network:o}=t,{txbParams:r}=this.data;return await ll(r,n,o)}static fromData(t){return new a(t)}};var pl=require("@msafe/sui3-utils");var Mo=class a extends v{constructor(t){super(t);this.data=t}txType=pl.TransactionType.Other;txSubType="RemoveVaultsPosition";async build(t){let{account:n,network:o}=t,{txbParams:r}=this.data;return await ul(r,n,o)}static fromData(t){return new a(t)}};var gl=require("@msafe/sui3-utils");var fl=require("@mysten/sui/transactions"),dl={package_id:"0x355714a1eeb7ab1d80902da6c92001170cda1212edf524c32aa308a3ac177c31",published_at:"0x355714a1eeb7ab1d80902da6c92001170cda1212edf524c32aa308a3ac177c31",cetus_coin_type:"0x06864a6f921804860930db6ddbe2e16acdf8504495ea7481637a1c8b9a8fe54b::cetus::CETUS"},hl=async(a,e,t)=>{console.log("getVestingRedeemTxb txbParams: ",a),console.log("getVestingRedeemTxb account: ",e),console.log("getVestingRedeemTxb network: ",t);let{pool:n,nftId:o,periods:r,CLOCK_ADDRESS:c}=a,u=new fl.Transaction;return r.forEach(d=>{u.moveCall({target:`${dl.published_at}::router::redeem`,typeArguments:[dl.cetus_coin_type],arguments:[u.object(n),u.object(o),u.pure(d),u.object(c)]})}),u};var Po=class a extends v{constructor(t){super(t);this.data=t}txType=gl.TransactionType.Other;txSubType="VestingRedeem";async build(t){let{account:n,network:o}=t,{txbParams:r}=this.data;return await hl(r,n,o)}static fromData(t){return new a(t)}};var Il=require("@msafe/sui3-utils");var yl=async(a,e,t)=>await qe(t,e).XCetusModule.convertPayload(a),bl=async(a,e,t)=>await qe(t,e).XCetusModule.redeemLockPayload(a),Sl=async(a,e,t)=>await qe(t,e).XCetusModule.redeemDividendV3Payload(a.veNftId,a.rewardList),Tl=async(a,e,t)=>await qe(t,e).XCetusModule.cancelRedeemPayload(a),wl=async(a,e,t)=>await qe(t,e).XCetusModule.redeemPayload(a);var Bo=class a extends v{constructor(t){super(t);this.data=t}txType=Il.TransactionType.Other;txSubType="xCETUSCancelRedeem";async build(t){let{account:n,network:o}=t,{txbParams:r}=this.data;return await Tl(r,n,o)}static fromData(t){return new a(t)}};var Cl=require("@msafe/sui3-utils");var Ro=class a extends v{constructor(t){super(t);this.data=t}txType=Cl.TransactionType.Other;txSubType="xCETUSClaimStakingRwewards";async build(t){let{account:n,network:o}=t,{txbParams:r}=this.data;return await Sl(r,n,o)}static fromData(t){return new a(t)}};var kl=require("@msafe/sui3-utils");var Eo=class a extends v{constructor(t){super(t);this.data=t}txType=kl.TransactionType.Other;txSubType="xCETUSConvert";async build(t){let{account:n,network:o}=t,{txbParams:r}=this.data;return await yl(r,n,o)}static fromData(t){return new a(t)}};var vl=require("@msafe/sui3-utils");var No=class a extends v{constructor(t){super(t);this.data=t}txType=vl.TransactionType.Other;txSubType="xCETUSRedeem";async build(t){let{account:n,network:o}=t,{txbParams:r}=this.data;return await wl(r,n,o)}static fromData(t){return new a(t)}};var xl=require("@msafe/sui3-utils");var Wo=class a extends v{constructor(t){super(t);this.data=t}txType=xl.TransactionType.Other;txSubType="xCETUSRedeemLock";async build(t){let{account:n,network:o}=t,{txbParams:r}=this.data;return await bl(r,n,o)}static fromData(t){return new a(t)}};var _o=class{application="cetus";supportSDK="@mysten/sui";async deserialize(e){console.log("Cetus helper deserialize input: ",e);let{txbParams:t,action:n}=e;return{txType:Dl.TransactionType.Other,txSubType:n,intentionData:{txbParams:{...t},action:n}}}async build(e){let{suiClient:t,account:n,network:o}=e,r;switch(e.txSubType){case"OpenAndAddLiquidity":r=fo.fromData(e.intentionData);break;case"IncreaseLiquidity":r=xo.fromData(e.intentionData);break;case"DecreaseLiquidity":r=go.fromData(e.intentionData);break;case"RemoveLiquidity":r=Do.fromData(e.intentionData);break;case"ClaimFeeAndMining":r=ho.fromData(e.intentionData);break;case"FarmingOpenAndAddLiquidity":r=yo.fromData(e.intentionData);break;case"FarmingIncreaseLiquidity":r=Io.fromData(e.intentionData);break;case"FarmingDecreaseLiquidity":r=To.fromData(e.intentionData);break;case"FarmingRemoveLiquidity":r=Co.fromData(e.intentionData);break;case"FarmingClaimFeeAndReward":r=So.fromData(e.intentionData);break;case"FarmingHarvest":r=wo.fromData(e.intentionData);break;case"FarmingBatchHarvest":r=bo.fromData(e.intentionData);break;case"FarmingStake":r=ko.fromData(e.intentionData);break;case"FarmingUnstake":r=vo.fromData(e.intentionData);break;case"xCETUSConvert":r=Eo.fromData(e.intentionData);break;case"xCETUSRedeemLock":r=Wo.fromData(e.intentionData);break;case"xCETUSClaimStakingRwewards":r=Ro.fromData(e.intentionData);break;case"xCETUSCancelRedeem":r=Bo.fromData(e.intentionData);break;case"xCETUSRedeem":r=No.fromData(e.intentionData);break;case"VestingRedeem":r=Po.fromData(e.intentionData);break;case"AggregatorSwap":r=Ao.fromData(e.intentionData);break;case"AddVaultsPosition":r=Oo.fromData(e.intentionData);break;case"RemoveVaultsPosition":r=Mo.fromData(e.intentionData);break;default:throw new Error("not implemented")}return r.build({suiClient:t,account:n,network:o})}};var Jl=require("@msafe/sui3-utils");var Al=$t(require("sort-keys-recursive")),B=class{constructor(e){this.data=e}serialize(){return JSON.stringify((0,Al.default)(this.data))}};var dn=require("@mysten/sui.js/client");var Wi={};Ri(Wi,{contractId:()=>Tp,default:()=>vp,feeObjId:()=>Cp,roleObjId:()=>wp,status:()=>Sp,transaction:()=>bp,upgradeCapObjId:()=>kp,vaultObjId:()=>Ip});var bp="DiBZq4UmVVYiRL6ZJmFKYoHcxtxqrhsCXSkFyT7wUr3j",Sp="success",Tp="0x81c960dc653975fbd0072deca8afb92d322898c911622898ba1b2e3ad0c4bd8d",wp="0xc6ec0bdee0bb59a72077e9acd2f42457043cf47080b3d3fad4d39abf28bba63a",Ip="0xbc4021387fbac149119fd24e92be9e58f745774292f3a2a12e2ac6daf5363e1d",Cp="0x4178f63970fe2daeb256dc5730ad172e82b3e8eb45f31b33e0daae72cd35e1e1",kp="0xe1e9aa7d222d151bfe6dd83358b0d7fdcb11260f710800cfaf7ccc1b1e245115",vp={transaction:bp,status:Sp,contractId:Tp,roleObjId:wp,vaultObjId:Ip,feeObjId:Cp,upgradeCapObjId:kp};var _i={};Ri(_i,{contractId:()=>Ap,default:()=>Rp,feeObjId:()=>Pp,roleObjId:()=>Op,status:()=>Dp,transaction:()=>xp,upgradeCapObjId:()=>Bp,vaultObjId:()=>Mp});var xp="855FNDV8o8Z3fWULPnQo9qdhLJpsg7wZrkCpNyfw9KfB",Dp="success",Ap="0xc357c3985e8fb875d6b37141497af660779aa1bab0ec489b2213efd74067d1fa",Op="0x5ab49bdf9fd1413e328ef242b3f8d83dde791b38a0b627bfc87fb25c010d34f1",Mp="0xb483558770d8eb26007f193b75db40f0a45f2e36863a687625885d4de6993378",Pp="0x48453fc4d7cde3fe35aad89e5dfb496608a6a55ea529a1c0274681a808627f94",Bp="0x34279779a0d0d36bd5044b04830d607fa1b0ecf316548c8ac3a44151e4f1a42a",Rp={transaction:xp,status:Dp,contractId:Ap,roleObjId:Op,vaultObjId:Mp,feeObjId:Pp,upgradeCapObjId:Bp};var Ep=(0,dn.getFullnodeUrl)("testnet"),Np=(0,dn.getFullnodeUrl)("testnet"),Wp=(0,dn.getFullnodeUrl)("mainnet"),_p=(0,dn.getFullnodeUrl)("mainnet"),Lp="https://bc3p6l5unl.execute-api.us-west-1.amazonaws.com/prod",jp="https://rolsbkota7.execute-api.us-west-1.amazonaws.com/prod",Up="https://6p6mkx33ne.execute-api.us-west-1.amazonaws.com/prod",qp="https://xrae3mrjv5.execute-api.us-west-1.amazonaws.com/prod",Ol=Wi,Ml=_i,Fp=new Map([["dev",{env:"dev",rpc:{url:Ep},backend:{url:Lp},contract:Ol}],["stg",{env:"stg",rpc:{url:Np},backend:{url:jp},contract:Ol}],["prev",{env:"prev",rpc:{url:Wp},backend:{url:Up},contract:Ml}],["prod",{env:"prod",rpc:{url:_p},backend:{url:qp},contract:Ml}]]);function Pl(a,e){let t=Fp.get(a);if(!t)throw new Error(`Env not supported: ${a}`);return e&&e.rpc&&(t.rpc=e.rpc),e&&e.backend&&(t.backend=e.backend),e&&e.contract&&(t.contract=e.contract),t}var Bl=require("@mysten/sui.js/client");var j=class extends Error{mpayErrorCode;context;constructor(e,t,n={}){let{cause:o,context:r}=n;o?super(`[MPay] ${t}: ${o}`):super(`[MPay] ${t}`),this.mpayErrorCode=e,this.context=r}};var Lo=class extends j{constructor(){super(11,"Backend is not specified")}};var jo=class extends j{constructor(){super(1,"Wallet not connected")}};var re=$t(require("axios"));var Fe=class extends j{constructor(e,t){super(10,e,{context:t})}};var Uo=class a{constructor(e){this.apiURL=e}static parseResponseData(e){if(e instanceof re.AxiosError)throw new Fe(e.response?.statusText);if(e.status===200){if(e.data.success)return e.data.data;throw new Fe(e.data.code)}throw new Fe(e.status.toString())}async getIncomingStreams(e,t){let n=await re.default.post(`${this.apiURL}/stream`,{recipient:e,...t});return a.parseResponseData(n)}async getOutgoingStreams(e,t){let n=await re.default.post(`${this.apiURL}/stream`,{sender:e,...t});return a.parseResponseData(n)}async getStreamHistory(e){let t=await re.default.post(`${this.apiURL}/stream-events`,e),n=a.parseResponseData(t);return n.data.forEach(o=>{let r=o;return r.data.type==="create_stream"?r.data.balance=BigInt(r.data.balance):r.data.type==="cancel_stream"?r.data.withdrawAmount=BigInt(r.data.withdrawAmount):r.data.type==="claim"||r.data.type==="auto_claim"?r.data.claimAmount=BigInt(r.data.claimAmount):r.data.type==="set_auto_claim"&&(r.data.enabled=!!r.data.enabled),r.createdAt=new Date(r.createdAt),r}),n}async getAllCoinTypes(e){let t=await re.default.post(`${this.apiURL}/stream-info`,{address:e});return a.parseResponseData(t)}async getAllRecipients(e,t){let n=await re.default.post(`${this.apiURL}/stream-info`,{sender:e,status:t});return a.parseResponseData(n)}async getAllSenders(e,t){let n=await re.default.post(`${this.apiURL}/stream-info`,{recipient:e,status:t});return a.parseResponseData(n)}};var Ke=class a{signer;suiClient;envConfig;_backend;constructor(e){this.envConfig=e,this.suiClient=new Bl.SuiClient({url:e.rpc.url}),e.backend&&(this._backend=new Uo(e.backend.url))}static new(e,t){let n=Pl(e,t);return new a(n)}get walletType(){return this.wallet?this.wallet.type:"disconnected"}get backend(){if(!this._backend)throw new Lo;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 jo;return this.signer}async walletAddress(){return this.wallet.address()}};var Ee=require("@mysten/sui.js/utils");var Sn=require("@mysten/sui.js/transactions");var Fi=require("@mysten/sui.js/transactions"),bn=require("@mysten/sui.js/utils");var Li=50n,qo=10000n,Rl=25n,ji=100000000n;var Yt=class{constructor(e){this.object=e}moveArg(e){return e.object(this.object)}},fn=class{constructor(e){this.objects=e}moveArgs(e){return e.makeMoveVec({objects:this.objects.map(t=>e.object(t))})}},pe=class a{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 a(t.result[c]);if(n===Symbol.iterator)return function*(){let c=0;for(;;)yield o(c),c++};if(typeof n=="symbol")return;let r=parseInt(n,10);if(!(Number.isNaN(r)||r<0))return o(r)}})}moveArg(){return this.result}};var Ui=require("buffer"),El=require("@mysten/sui.js/utils");var hn=class extends j{constructor(e,t){super(3,e,{context:t})}};var Fo=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 hn("Invalid contract return type.",{ctx:{expectType:"address",gotType:o}});return(0,El.normalizeSuiAddress)(Ui.Buffer.from(n).toString("hex"))}getU64(e=0,t=0){let[n,o]=this.getValue(e,t);if(o!=="u64")throw new hn("Invalid contract return type.",{ctx:{expectType:"u64",gotType:o}});return Ui.Buffer.from(n).readBigInt64LE()}};var qi=require("@mysten/sui.js/bcs");var H=class extends j{constructor(e,t,n){super(2,`Invalid input: ${e}`,{context:{fieldKey:t,fieldValue:n}})}};var Wl={groupId:"string",name:"string"},Kp=64;function _l(a){return Ll(a),qi.bcs.ser(Wl,a).toString("base64")}function gn(a){let e=qi.bcs.de(Wl,a,"base64");return Ll(e),e}function Ll(a){if(!Nl(a.name))throw new H("Invalid metadata: Name contains unknown character");if(!Nl(a.groupId))throw new H("Invalid metadata: Group ID contains unknown character");if(a.name.length>Kp)throw new H("Invalid metadata: Name exceed max length 64")}function Nl(a){return/^[\x00-\x7F]+$/.test(a)}var yn=require("@mysten/sui.js/utils");function Ko(a,e){return(0,yn.normalizeStructTag)(a)===(0,yn.normalizeStructTag)(e)}function de(a,e){return(0,yn.normalizeStructTag)(a)===(0,yn.normalizeStructTag)(e)}var Vo="txn.gas";var jl=require("nanoid");function Ul(){return(0,jl.nanoid)()}var Re=class a{constructor(e,t,n){this.globals=e;this.feeContract=t;this.streamContract=n}static convertCreateStreamInfoToInternal(e){return{metadata:_l({name:e.name,groupId:Ul()}),coinType:(0,bn.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 Fi.TransactionBlock,n=this.calculateFeesInternal(e),o=this.getCreateStreamCoinRequests(e,n),r=await this.wallet.requestCoins(o),c=await this.addMergeCoins(t,r[0]),u;o.length>1?u=await this.addMergeCoins(t,r[1]):u=c;for(let d=0;d<e.recipients.length;d++){let S=e.recipients[d],w=this.amountForRecipient(S,e.numberEpoch),I=this.getStreamFeeLocal(w),[C]=t.splitCoins(c,[t.pure(w+I,"u64")]),[k]=t.splitCoins(u,[t.pure(this.flatSuiFee,"u64")]);this.streamContract.createStream(t,{paymentCoin:new pe(C),flatFeeCoin:new pe(k),metadata:e.metadata,recipient:S.address,timeStart:e.startTime,cliff:S.cliffAmount,epochInterval:e.epochInterval,numEpoch:e.numberEpoch,amountPerEpoch:S.amountPerEpoch,cancelable:e.cancelable,coinType:e.coinType})}return t}calculateCreateStreamFees(e){let t=a.convertCreateStreamInfoToInternal(e);return this.calculateFeesInternal(t)}feeParams(){return{createFeePercent:{numerator:Li,denominator:qo},claimFeePercent:{numerator:Rl,denominator:qo},flatFeePerStream:ji}}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===Vo?n=e.gas:n=e.object(t.primaryCoin),n}getCreateStreamCoinRequests(e,t){let n=e.coinType;return Ko(n,bn.SUI_TYPE_ARG)?[{coinType:n,amount:t.totalAmount+t.streamFeeAmount+t.flatFeeAmount}]:[{coinType:n,amount:t.totalAmount+t.streamFeeAmount},{coinType:bn.SUI_TYPE_ARG,amount:t.flatFeeAmount}]}calculateFeesInternal(e){let t=e.recipients.reduce((o,r)=>{let c=this.amountForRecipient(r,e.numberEpoch),u=this.getStreamFeeLocal(c);return{totalAmount:o.totalAmount+c,streamFeeAmount:o.streamFeeAmount+u}},{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 ji}getStreamFeeLocal(e){return e*Li/qo}async getStreamFeeRemote(e){let t=this.feeContract.streamingFee(new Fi.TransactionBlock,e),n=await this.globals.suiClient.devInspectTransactionBlock({sender:await this.globals.walletAddress(),transactionBlock:t});return new Fo(n).getU64()}get wallet(){return this.globals.wallet}};var Ki=require("@mysten/sui.js/transactions");var ql="0x0000000000000000000000000000000000000000000000000000000000000006";var Ve=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(Ki.Transactions.MoveCall({target:n,arguments:t.arguments.map(o=>o instanceof fn?o.moveArgs(e):o instanceof Yt?o.moveArg(e):o instanceof pe?o.moveArg():e.pure(o)),typeArguments:t.typeArgs})),e}addTransactionBlock(e,t,n=[],o=[]){e.add(Ki.Transactions.MoveCall({target:t,arguments:n.map(r=>r instanceof fn?r.moveArgs(e):r instanceof Yt?r.moveArg(e):r instanceof pe?r.moveArg():e.pure(r)),typeArguments:o}))}makeObject(e){return typeof e=="string"?new Yt(e):e}vaultObject(){return new Yt(this.config.vaultObjId)}roleObject(){return new Yt(this.config.roleObjId)}feeObject(){return new Yt(this.config.feeObjId)}clockObject(){return new Yt(ql)}};var $e=class a extends Ve{constructor(t,n){super(a.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(),r=this.feeObject();return this.addContractCall(t,{method:a.MethodName.set_streaming_fee,arguments:[o,r,n],typeArgs:[]})}setStreamingFlatFee(t,n){let o=this.roleObject(),r=this.feeObject();return this.addContractCall(t,{method:a.MethodName.set_streaming_flat_fee,arguments:[o,r,n],typeArgs:[]})}setClaimFee(t,n){let o=this.roleObject(),r=this.feeObject();return this.addContractCall(t,{method:a.MethodName.set_claim_fee,arguments:[o,r,n],typeArgs:[]})}streamingFee(t,n){let o=this.feeObject();return this.addContractCall(t,{method:a.MethodName.streaming_fee,arguments:[o,n],typeArgs:[]})}claimFee(t,n){return this.addContractCall(t,{method:a.MethodName.claim_fee,arguments:[this.feeObject(),n],typeArgs:[]})}feeDenominator(t){return this.addContractCall(t,{method:a.MethodName.fee_denominator,arguments:[this.feeObject()],typeArgs:[]})}};var Zt=class a extends Ve{constructor(t,n){super(a.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(),r=this.vaultObject(),c=this.makeObject(n.paymentCoin),u=this.makeObject(n.flatFeeCoin),d=this.clockObject();return this.addContractCall(t,{method:a.MethodName.create_stream,arguments:[o,r,c,u,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:a.MethodName.set_auto_claim,arguments:[o,n.enabled],typeArgs:[n.coinType]})}cancelStream(t,n){let o=this.makeObject(n.streamId),r=this.clockObject();return this.addContractCall(t,{method:a.MethodName.cancel_stream,arguments:[o,r],typeArgs:[n.coinType]})}claimStream(t,n){let o=this.makeObject(n.streamId),r=this.clockObject();return this.addContractCall(t,{method:a.MethodName.claim_stream,arguments:[o,r],typeArgs:[n.coinType]})}claimStreamByProxy(t,n){let o=this.makeObject(n.streamId),r=this.vaultObject(),c=this.feeObject(),u=this.clockObject();return this.addContractCall(t,{method:a.MethodName.claim_stream_by_proxy,arguments:[o,r,c,u],typeArgs:[n.coinType]})}get createStreamTarget(){return`${this.config.contractId}::${a.ModuleName}::${a.MethodName.create_stream}`}get setAutoClaimTarget(){return`${this.config.contractId}::${a.ModuleName}::${a.MethodName.set_auto_claim}`}get cancelStreamTarget(){return`${this.config.contractId}::${a.ModuleName}::${a.MethodName.cancel_stream}`}get claimStreamTarget(){return`${this.config.contractId}::${a.ModuleName}::${a.MethodName.claim_stream}`}get claimStreamByProxyTarget(){return`${this.config.contractId}::${a.ModuleName}::${a.MethodName.claim_stream_by_proxy}`}};var He=class{constructor(e){this.globals=e;let t=e.envConfig.contract;this.feeContract=new $e(t,e),this.streamContract=new Zt(t,e)}feeContract;streamContract;async createStreams(e){let t=Re.convertCreateStreamInfoToInternal(e);return this.createStreamHelper().buildCreateStreamTransactionBlock(t)}createStreamHelper(){return new Re(this.globals,this.feeContract,this.streamContract)}setAutoClaim(e,t,n){let o=new Sn.TransactionBlock;return this.streamContract.setAutoClaim(o,{streamId:e,enabled:t,coinType:n})}claimStream(e,t){let n=new Sn.TransactionBlock;return this.streamContract.claimStream(n,{streamId:e,coinType:t})}claimStreamByProxy(e,t){let n=new Sn.TransactionBlock;return this.streamContract.claimStreamByProxy(n,{streamId:e,coinType:t})}cancelStream(e,t){let n=new Sn.TransactionBlock;return this.streamContract.cancelStream(n,{streamId:e,coinType:t}),n}};var Ge=require("@mysten/sui.js/utils"),Vi=require("luxon");var $o=class extends j{constructor(e,t){super(12,`Transaction failed: ${t}`,{context:{status:e,msg:t}})}};var Vp=1e3,Ho=class{constructor(e){this.globals=e;this.coinMetaHelper=new $i(e.suiClient),this.createStreamHelper=new He(e).createStreamHelper()}coinMetaHelper;createStreamHelper;getStreamIdsFromCreateStreamResponse(e){if(e.effects?.status.status!=="success")throw new $o(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 H("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 H("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 H("Invalid stream steps: 0");let t=BigInt(e.total.toMillis())/e.steps,n=e.timeStart.plus(Vi.Duration.fromMillis(Number(t*e.steps))),o={timeStart:e.timeStart,timeEnd:n,interval:Vi.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,r)=>({...o,coinType:(0,Ge.normalizeStructTag)(o.coinType),coinMeta:n[r]}))}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 H("Stream amount too small","totalAmount",t);if(e.cliffAmount>e.realTotalAmount)throw new H("Invalid cliff settings")}validateTimeline(e){if(e.interval.toMillis()<Vp)throw new H("Interval shall be at least 1 second","interval",e.interval)}},$i=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 he=require("@mysten/sui.js/utils"),Yi=require("luxon");var In=require("@mysten/sui.js/transactions"),Cn=require("@mysten/sui.js/utils"),Kl=require("luxon");var Go=class extends j{constructor(){super(7,"Connected wallet is not creator")}};var Tn=class extends j{constructor(){super(8,"Connected wallet is not recipient")}};var wn=class extends j{constructor(e,t){super(6,e,{context:t})}};var At=class extends j{constructor(e,t={}){super(0,e,t)}};var Qo=class extends j{constructor(e){super(5,"Stream not found",{context:{streamId:e}})}};var Jo=require("luxon"),Fl=(1n<<64n)-1n,zo=1e3;function Hi(a){let e;typeof a=="number"?e=a:typeof a=="bigint"?e=Number(a):e=a.toMillis();let t=Math.round(e/zo);return Jo.DateTime.fromMillis(t*zo)}function Gi(a){let e;typeof a=="number"?e=a:typeof a=="bigint"?e=Number(a):e=a.toMillis();let t=Math.round(e/zo);return Jo.Duration.fromMillis(t*zo)}var fe=class a{constructor(e,t,n){this.globals=e;this.streamId=t;this.rawData=n;this.streamContract=new Zt(e.envConfig.contract,e)}streamContract;type="Stream";static async new(e,t){let n=await a.fetchStreamData(e,t);return new a(e,t,n)}static fromObjectData(e,t,n){let o=a.parseRawStreamData(t,n);return new a(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 a.fetchStreamData(this.globals,this.streamId)}refreshWithData(e){if(e.data?.objectId!==this.streamId)throw new At("Object Id does not align");this.rawData=a.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 Go;let e=new In.TransactionBlock;return this.streamContract.cancelStream(e,{streamId:this.streamId,coinType:this.coinType}),e}async claim(){if(await this.globals.walletAddress()!==this.recipient)throw new Tn;let e=new In.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 Tn;let t=new In.TransactionBlock;return this.streamContract.setAutoClaim(t,{streamId:this.streamId,coinType:this.coinType,enabled:e}),t}async claimByProxy(){let e=new In.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,Cn.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 Gi(this.rawData.config.epochInterval)}get groupId(){let{metadata:e}=this.rawData.config;return gn(e).groupId}get name(){let{metadata:e}=this.rawData.config;return gn(e).name}get recipient(){return this.rawData.config.recipient}get timeStart(){return Hi(this.rawData.config.timeStart)}get duration(){let e=this.rawData.config,t=e.epochInterval*e.totalEpoch;return Gi(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:Hi((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===Fl?0n:this.rawData.status.epochClaimed*this.amountPerEpoch+this.cliff}get currentEpoch(){let e=Kl.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 a.parseRawStreamData(t,n)}static parseRawStreamData(e,t){if(t.error)throw t.error.code==="notExists"?new Qo(e):new wn(`get stream data: ${t.error.code}`,{streamId:e,...t.error});let n=t.data.content;if(n.dataType!=="moveObject")throw new wn("Unexpected object type",{gotType:n.dataType});let{typeParams:o}=(0,Cn.parseStructTag)(n.type),r=(0,Cn.normalizeStructTag)(o[0]),c=n.fields,u=c.config.fields,d=c.status.fields;return{coinType:r,autoClaim:c.auto_claim,balance:BigInt(c.balance.fields.balance),config:{amountPerEpoch:BigInt(u.amount_per_epoch),cancelable:u.cancelable,cliff:BigInt(u.cliff),creator:u.creator,epochInterval:BigInt(u.epoch_interval),metadata:u.metadata,recipient:u.recipient,timeStart:BigInt(u.time_start),totalEpoch:BigInt(u.total_epoch)},status:{status:d.status,epochCanceled:BigInt(d.epoch_canceled),epochClaimed:BigInt(d.epoch_claimed)}}}};var Qe=class extends j{constructor(e,t){super(9,`Invalid stream group: ${e}`,{context:t})}};async function zi(a){let e=[];for(;await a.hasNext();){let t=await a.next();e.push(t)}return e&&Array.isArray(e[0])?e.flat(1):e}var Qi=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)}},ze=class{constructor(e){this.requester=e;this.pager=new Qi(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 $p=25;async function Xi(a,e,t){let n=new kn(e),o=new vn(a,n,t);return await zi(o)}var kn=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]}},vn=class extends ze{constructor(t,n,o){super(new Ji(t,n,o));this.suiClient=t;this.idIter=n;this.options=o}},Ji=class{constructor(e,t,n){this.suiClient=e;this.stringIter=t;this.options=n;this.filter=n?.filter,this.pageSize=n?.pageSize||$p,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 r=await this.stringIter.next();r&&e.push(r)}let t=await this.suiClient.multiGetObjects({ids:e,options:this.objectOptions}),n;if(this.filter){let{filter:o}=this;n=t.filter(r=>o?.(r))}else n=t;return{data:n,hasNext:await this.stringIter.hasNext()}}};var Xo=class a{constructor(e,t){this.globals=e;this.streams=t;if(t.length===0)throw new Qe("stream size 0");let n=t.map(r=>r.groupId);if(new Set(n).size!==1)throw new H("Stream does not have same group ID")}type="StreamGroup";static async new(e,t){let n=await Xi(e.suiClient,t);return n.forEach(o=>{if(!o)throw new At("stream group object data undefined")}),a.newFromObjectResponse(e,t,n)}static async newFromObjectResponse(e,t,n){let o=await a.parseGroupStreams(e,t,n);return new a(e,o)}static checkStreamGroup(e){let t=e.map(r=>r.groupCommonInfo),n=t[0],o=!0;return t.forEach(r=>{Hp(n,r)||(o=!1)}),o}async refresh(){let e=await Xi(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((r,c)=>fe.fromObjectData(e,t[c],r)).filter(r=>!!r);if(new Set(o.map(r=>r.groupId)).size!==1)throw new Qe("Not same group ID");if(!this.checkStreamGroup(o))throw new Qe("Not same stream settings");return o}};function Hp(a,e){return a.name===e.name&&a.groupId===e.groupId&&a.creator===e.creator&&a.start.toMillis()===e.start.toMillis()&&a.interval.toMillis()===e.interval.toMillis()&&a.steps===e.steps&&a.cancelable===e.cancelable}var xn=class a{constructor(e,t){this.it=e;this.pageSize=t}static async newIncoming(e){let t=await Yo.newIncoming(e);return new a(t,e.pageSize)}static async newOutgoing(e){let t=await Yo.newOutgoing(e);return new a(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}},Yo=class a{constructor(e){this.requester=e}cachedNext;static async newIncoming(e){let t=await Zo.newIncomingQuery(e);return new a(t)}static async newOutgoing(e){let t=await Zo.newOutgoingQuery(e);return new a(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}},Zo=class a{constructor(e,t,n,o){this.globals=e;this.recipient=t;this.groupRefs=n;this.query=o;this.current=0;let r=new kn(n.flat().map(c=>c.streamId));this.objectIter=new vn(e.suiClient,r)}current=0;objectIter;static async newIncomingQuery(e){let t=Xp(e.query),n=await e.globals.walletAddress(),r=(await e.globals.backend.getIncomingStreams(n,t)).filter(u=>(0,he.normalizeSuiAddress)(u.recipient)===(0,he.normalizeSuiAddress)(n)),c=Vl(r);return new a(e.globals,n,c,e.query)}static async newOutgoingQuery(e){let t=Yp(e.query),n=await e.globals.walletAddress(),o=await e.globals.backend.getOutgoingStreams(n,t),r=Vl(o);return new a(e.globals,n,r,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 zp(this.globals,e[0].streamId,this.objectIter);return this.current++,$l(t,this.query)?t:this.doNextRequest()}if(e.length>1){let t=await Jp(this.globals,e.map(n=>n.streamId),this.objectIter);return this.current++,Qp(t,this.query)?t:this.doNextRequest()}throw new At("Stream group with no stream")}};function Vl(a){let e=new Map;return a.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)=>Yi.DateTime.fromISO(n[0].createDate).toMillis()-Yi.DateTime.fromISO(t[0].createDate).toMillis())}function $l(a,e){if(e===void 0)return!0;let t=Gp(a,e.status);if(e&&"claimable"in e&&e.claimable!==void 0){let n=e.claimable?a.progress.claimable!==0n:a.progress.claimable===0n;return t&&n}return t}function Gp(a,e){return e===void 0?!0:Array.isArray(e)?e.includes(a.progress.status):a.progress.status===e}function Qp(a,e){if(!e)return!0;let t=!1;return a.streams.forEach(n=>{$l(n,e)&&(t=!0)}),t}async function zp(a,e,t){let n=await Hl(t,e);return fe.fromObjectData(a,e,n)}async function Jp(a,e,t){let n=[];for(;n.length<e.length;){let o=await Hl(t,e[n.length]);n.push(o)}return Xo.newFromObjectResponse(a,e,n)}async function Hl(a,e){if(!await a.hasNext())throw new At("object iterator has been consumed");let t=await a.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 Xp(a){return{status:Zi(a?.status),coinType:Gl(a?.coinType),sender:Ql(a?.sender)}}function Yp(a){return{status:Zi(a?.status),coinType:Gl(a?.coinType),recipient:Ql(a?.recipient)}}function Zi(a){return a===void 0||a.length===0?"all":Array.isArray(a)?a.reduce((e,t)=>{let n=Zi(t);return!e||e===n?n:"all"},void 0):Zp(a)}function Zp(a){switch(a){case"STREAMING":case"STREAMED":case"CANCELED":return"active";case"COMPLETED":case"SETTLED":return"inactive";default:throw new H("Unknown stream filtered status")}}function Gl(a){if(a)return Array.isArray(a)?a.length!==0?a.map(e=>(0,he.normalizeStructTag)(e)):void 0:(0,he.normalizeStructTag)(a)}function Ql(a){if(a)return Array.isArray(a)?a.length!==0?a.map(e=>(0,he.normalizeSuiAddress)(e)):void 0:(0,he.normalizeSuiAddress)(a)}var ta=class extends j{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 td=25;async function zl(a,e,t,n="0x2::sui::SUI",o=td){let r=new ts(a,e,n,o),c=BigInt(0),u=[];for(;await r.hasNext()&&c<t;){let d=await r.next();d&&(u.push(d),c+=BigInt(d.balance))}if(c<t)throw new ta(n,t,c);return u}var ts=class extends ze{constructor(t,n,o,r){super(new es(t,n,o,r));this.suiClient=t;this.owner=n;this.coinType=o;this.reqPageSize=r}},es=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 ns=class{constructor(e){this.msafe=e}get type(){return"msafe"}async address(){return this.msafe.address()}async requestCoins(e){return this.msafe.requestCoins(e)}},ea=class{constructor(e){this.account=e}async address(){return this.account.address}},os=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(Ko(e.coinType,Ee.SUI_TYPE_ARG))return{primaryCoin:Vo};if(e.amount<=0)throw new H("Invalid coin request","coinAmount",e.amount);let t=await zl(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)}}},na=class{globals;helper;constructor(e,t){this.globals=Ke.new(e,t),this.helper=new Ho(this.globals)}connectSingleWallet(e){let t=new os(e,this.globals.suiClient);this.globals.connectWallet(t)}connectMSafeAccount(e){let t=new ns(e);this.globals.connectWallet(t)}async createStream(e){return this.builder().createStreams(e)}async getStream(e){return fe.new(this.globals,e)}async getIncomingStreams(e,t=10){return xn.newIncoming({globals:this.globals,query:e,pageSize:t})}async getOutgoingStreams(e,t=10){return xn.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 He(this.globals)}};var qt=class extends B{application="mpay";getClient(e,t){let n=new na(e==="sui:mainnet"?"prod":"dev");return n.connectSingleWallet(new ea(t)),n}};var Dn=class extends qt{constructor(t){super(t);this.data=t}txType=Jl.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 Xl=require("@msafe/sui3-utils");var An=class extends qt{constructor(t){super(t);this.data=t}txType=Xl.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 Yl=require("@msafe/sui3-utils");var On=class extends qt{constructor(t){super(t);this.data=t}txType=Yl.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 Zl=require("@msafe/sui3-utils");var Mn=class extends qt{constructor(t){super(t);this.data=t}txType=Zl.TransactionType.Stream;txSubType="CreateStream";async build(t){let{network:n,account:o}=t;return this.getClient(n,o).createStream(this.data)}};var as=require("@mysten/sui.js/bcs"),ge=require("@mysten/sui.js/utils"),Je=class a{constructor(e,t){this.moveCall=e;this.txb=t}decodeSharedObjectId(e){let t=this.getInputParam(e);return a.getSharedObjectId(t)}decodeOwnedObjectId(e){let t=this.getInputParam(e);return a.getOwnedObjectId(t)}decodeInputU64(e){let t=this.decodePureArg(e,"u64");return BigInt(t)}decodeInputAddress(e){let t=this.decodePureArg(e,"address");return(0,ge.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 a.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 as.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,ge.normalizeSuiAddress)(e.value.Object.ImmOrOwned.objectId)}return(0,ge.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,ge.normalizeSuiAddress)(e.value);if(!("Object"in e.value)||!("Shared"in e.value.Object))throw new Error("not Shared");return(0,ge.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 as.bcs.de(t,new Uint8Array(n))}typeArg(e){return(0,ge.normalizeStructTag)(this.moveCall.typeArguments[e])}txArg(e){return this.moveCall.arguments[e]}};var oa=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"&&de(t.target,this.contract.createStreamTarget));if(e.length===0)throw new At("No create stream transactions");return e.map(t=>new Je(t,this.txb))}getCreationInfoFromMoveCall(e){let t=e.decodeInputString(4),{name:n,groupId:o}=gn(t),r=e.decodeInputAddress(5),c=e.decodeInputU64(6),u=e.decodeInputU64(7),d=e.decodeInputU64(8),S=e.decodeInputU64(9),w=e.decodeInputU64(10),I=e.decodeInputBool(11),C=e.typeArg(0);return{name:n,groupId:o,recipient:r,timeStart:c,cliff:u,epochInterval:d,totalEpoch:S,amountPerEpoch:w,cancelable:I,coinType:C}}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 H("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 Zt(this.globals.envConfig.contract,this.globals)}get feeContract(){return new $e(this.globals.envConfig.contract,this.globals)}createStreamHelper(){return new Re(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 aa=class{constructor(e,t){this.globals=e;this.txb=t;this.contract=new Zt(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"&&de(t.target,this.contract.createStreamTarget))!==-1}isSetAutoClaimTransaction(){return this.transactions.length===1&&this.transactions[0].kind==="MoveCall"&&de(this.transactions[0].target,this.contract.setAutoClaimTarget)}isCancelStreamTransaction(){return this.transactions.length===1&&this.transactions[0].kind==="MoveCall"&&de(this.transactions[0].target,this.contract.cancelStreamTarget)}isClaimStreamTransaction(){return this.transactions.length===1&&this.transactions[0].kind==="MoveCall"&&de(this.transactions[0].target,this.contract.claimStreamTarget)}isClaimByProxyTransaction(){return this.transactions.length===1&&this.transactions[0].kind==="MoveCall"&&de(this.transactions[0].target,this.contract.claimStreamByProxyTarget)}decodeCreateStreamTransaction(){return new oa(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 Je(e,this.txb)}};var tu=require("@msafe/sui3-utils");var Pn=class extends qt{constructor(t){super(t);this.data=t}txType=tu.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 ra=class{application="mpay";supportSDK="@mysten/sui.js";async deserialize(e){let{network:t,transactionBlock:n}=e,o=Ke.new(t==="sui:mainnet"?"prod":"dev"),c=new aa(o,n).decode(),u;switch(c.type){case"CreateStream":u=new Mn(c.info);break;case"SetAutoClaim":u=new Pn({streamId:c.streamId,enabled:c.enabled});break;case"Claim":u=new On({streamId:c.streamId});break;case"ClaimByProxy":u=new An({streamId:c.streamId});break;case"Cancel":u=new Dn({streamId:c.streamId});break;default:throw new Error(`Unknown transaction type: ${c}`)}return{txType:u.txType,txSubType:u.txSubType,intentionData:u.data}}async build(e){let{intentionData:t}=e,n;switch(e.txSubType){case"CreateStream":n=new Mn(t);break;case"Claim":n=new On(t);break;case"ClaimByProxy":n=new An(t);break;case"SetAutoClaim":n=new Pn(t);break;case"Cancel":n=new Dn(t);break;default:throw new Error("not implemented")}return n.build({...e})}};var Bn=require("@msafe/sui3-utils");var eu=require("@msafe/sui3-utils");var ia=class a extends B{constructor(t){super(t);this.data=t}txType;txSubType;async build(t){let{suiClient:n,account:o}=t;return(0,eu.buildCoinTransferTxb)(n,this.data,o.address)}static fromData(t){return new a(t)}};var nu=require("@msafe/sui3-utils");var sa=class a extends B{constructor(t){super(t);this.data=t}txType;txSubType;async build(t){let{suiClient:n,account:o}=t;return(0,nu.buildObjectTransferTxb)(n,this.data,o.address)}static fromData(t){return new a(t)}};var ca=class{application="msafe-core";supportSDK="@mysten/sui.js";constructor(){this.application=Bn.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 Bn.TransactionSubTypes.assets.coin.send:o=ia.fromData(e.intentionData);break;case Bn.TransactionSubTypes.assets.object.send:o=sa.fromData(e.intentionData);break;default:throw new Error("not implemented")}return o.build({suiClient:t,account:n})}};var fu=require("@msafe/sui3-utils");var ou=!1,Rn={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 rs(){if(!ou)try{let a=await fetch("https://open-api.naviprotocol.io/api/msafe").then(r=>r.json()),{packageId:e,borrowFee:t,borrowFeeAddress:n,pool:o}=a;e&&(Rn.ProtocolPackage=e),t&&(Rn.borrowFee=t),n&&(Rn.borrowFeeAddress=n),o&&(Rn.pool=o),ou=!0}catch(a){console.error(a.message)}}var Ht=Rn;var ye=require("@msafe/sui3-utils"),is=require("@mysten/sui.js/bcs"),be=require("@mysten/sui.js/utils");var la=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(`${Ht.ProtocolPackage}::incentive_v3::entry_borrow`)}isEntryBorrowWithFeeTransaction(){return!!this.getMoveCallTransaction(`${Ht.ProtocolPackage}::incentive_v3::borrow`)}isEntryMultiDepositTransaction(){let e=`${Ht.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=`${Ht.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(`${Ht.ProtocolPackage}::incentive_v3::entry_deposit`)}isEntryRepayTransaction(){return!!this.getMoveCallTransaction(`${Ht.ProtocolPackage}::incentive_v3::entry_repay`)}isEntryWithdrawTransaction(){return!!this.getMoveCallTransaction(`${Ht.ProtocolPackage}::incentive_v3::withdraw`)}findPoolByAssetId(e){let t=Object.values(Ht.pool).find(n=>n.assetId===e);if(!t)throw new Error("Pool not found");return t}decodeEntryClaimAndDeposit(){return{txType:ye.TransactionType.Other,type:"EntryClaimAndDeposit",intentionData:{type:"entry_claim_and_deposit"}}}decodeClaimReward(){return console.log("decode claims"),{txType:ye.TransactionType.Other,type:"ClaimReward",intentionData:{type:"claim_reward"}}}decodeEntryBorrow(){let e=this.helper.decodeInputU8(4),t=this.helper.decodeInputU64(5);return{txType:ye.TransactionType.Other,type:"EntryBorrow",intentionData:{amount:t,assetId:e}}}decodeEntryMultiDeposit(){let e=[],t=`${Ht.ProtocolPackage}::incentive_v3::entry_deposit`;return this.transactions.forEach(n=>{if(n.kind==="MoveCall"&&n.target===t){let o=new ua(n,this.txb),r=o.decodeInputU8(3),c=o.decodeInputU64(5);e.push({assetId:r,amount:c})}}),{txType:ye.TransactionType.Other,type:"EntryMultiDeposit",intentionData:{list:e}}}decodeEntryDeposit(){let e=this.helper.decodeInputU8(3),t=this.helper.decodeInputU64(5);return{txType:ye.TransactionType.Other,type:"EntryDeposit",intentionData:{amount:t,assetId:e}}}decodeEntryRepay(){let e=this.helper.decodeInputU8(4),t=this.helper.decodeInputU64(6);return{txType:ye.TransactionType.Other,type:"EntryRepay",intentionData:{amount:t,assetId:e}}}decodeEntryWithdraw(){let e=this.helper.decodeInputU8(4),t=this.helper.decodeInputU64(5);return{txType:ye.TransactionType.Other,type:"EntryWithdraw",intentionData:{amount:t,assetId:e}}}get helper(){let e=this.transactions.find(t=>t.kind==="MoveCall"&&t.target.startsWith(Ht.ProtocolPackage));return new ua(e,this.txb)}},ua=class a{constructor(e,t){this.moveCall=e;this.txb=t}decodeSharedObjectId(e){let t=this.getInputParam(e);return a.getSharedObjectId(t)}decodeOwnedObjectId(e){let t=this.getInputParam(e);return a.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,be.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 a.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 is.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,be.normalizeSuiAddress)(e.value.Object.ImmOrOwned.objectId)}return(0,be.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,be.normalizeSuiAddress)(e.value);if(!("Object"in e.value)||!("Shared"in e.value.Object))throw new Error("not Shared");return(0,be.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 is.bcs.de(t,new Uint8Array(n))}typeArg(e){return(0,be.normalizeStructTag)(this.moveCall.typeArguments[e])}txArg(e){return this.moveCall.arguments[e]}};var Ft=require("navi-sdk");async function Xe(a,e,t,n){return await(0,Ft.depositCoin)(a,e,t,n),a}async function au(a,e,t,n){let[o]=await(0,Ft.withdrawCoin)(a,e,t);return a.transferObjects([o],a.pure(n)),a}async function ru(a,e,t,n){let[o]=await(0,Ft.borrowCoin)(a,e,t);return a.transferObjects([o],a.pure.address(n)),a}async function ss(a,e,t,n){return await(0,Ft.repayDebt)(a,e,t,n),a}async function iu(a,e){return await(0,Ft.claimAllRewardsPTB)(a,e)}async function su(a,e){return await(0,Ft.claimAllRewardsResupplyPTB)(a,e)}var ma=class a extends B{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 a(t)}};var pa=class a extends B{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 su(t.suiClient,t.account.address)}static fromData(t){return new a(t)}};var lu=require("@mysten/sui.js/transactions");var cu=require("navi-sdk");function te(a){return Object.values(cu.pool).find(e=>String(e.assetId)===String(a))}var da=class a extends B{constructor(t){super(t);this.data=t}txType;txSubType;async build(t){let{assetId:n,amount:o}=this.data,r=new lu.TransactionBlock;console.log("build",this.data);let c=te(n);return await ru(r,c,o,t.account.address)}static fromData(t){return new a(t)}};var uu=require("@mysten/sui.js/transactions");async function Ye(a,e,t){let n=await a.getCoins({owner:e,coinType:t});return console.log("getTokenObjs",e,n),n}var fa=class a extends B{constructor(t){super(t);this.data=t}txType;txSubType;async build(t){let{suiClient:n,account:o}=t,{assetId:r,amount:c}=this.data,u=new uu.TransactionBlock;console.log("build",this.data);let d=te(r);if(r===0){let[C]=u.splitCoins(u.gas,[c]);return await Xe(u,d,C,c)}let S=await Ye(n,o.address,d.type);if(!S.data[0])throw new Error(`Insufficient balance for ${d.name} Token`);let w=S.data[0].coinObjectId;if(S.data.length>=2){let C=1;for(;C<S.data.length;)u.mergeCoins(w,[S.data[C].coinObjectId]),C++}return await Xe(u,d,u.object(w),c)}static fromData(t){return new a(t)}};var mu=require("@mysten/sui.js/transactions");var ha=class a extends B{constructor(t){super(t);this.data=t}txType;txSubType;async build(t){let{suiClient:n,account:o}=t,{assetId:r,amount:c}=this.data,u=new mu.TransactionBlock;console.log("build",this.data);let d=te(r);if(r===0){let[I]=u.splitCoins(u.gas,[c]);return ss(u,d,I,c)}let S=await Ye(n,o.address,d.type);if(!S.data[0])throw new Error(`Insufficient balance for ${d.name} Token`);let w=S.data[0].coinObjectId;if(S.data.length>=2){let I=1;for(;I<S.data.length;)u.mergeCoins(w,[S.data[I].coinObjectId]),I++}return ss(u,d,u.object(w),c)}static fromData(t){return new a(t)}};var pu=require("@mysten/sui.js/transactions");var ga=class a extends B{constructor(t){super(t);this.data=t}txType;txSubType;async build(t){let{assetId:n,amount:o}=this.data,r=new pu.TransactionBlock;console.log("build",this.data);let c=te(n);return await au(r,c,o,t.account.address)}static fromData(t){return new a(t)}};var du=require("@mysten/sui.js/transactions");var ya=class a extends B{constructor(t){super(t);this.data=t}txType;txSubType;async build(t){let{suiClient:n,account:o}=t,{list:r}=this.data,c=new du.TransactionBlock;console.log("build",this.data);for(let u=0;u<r.length;u++){let{assetId:d,amount:S}=r[u],w=te(d);if(d===0){let[k]=c.splitCoins(c.gas,[S]);await Xe(c,w,k,S);continue}let I=await Ye(n,o.address,w.type);if(!I.data[0])throw new Error(`Insufficient balance for ${w.name} Token`);let C=I.data[0].coinObjectId;if(I.data.length>=2){let k=1;for(;k<I.data.length;)c.mergeCoins(C,[I.data[k].coinObjectId]),k++}await Xe(c,w,c.object(C),S)}return c}static fromData(t){return new a(t)}};var ba=class{application="navi";supportSDK="@mysten/sui.js";async deserialize(e){await rs();let{transactionBlock:t}=e,o=new la(t).decode();return{txType:fu.TransactionType.Other,txSubType:o.type,intentionData:o.intentionData}}async build(e){let{suiClient:t,account:n}=e,o;switch(await rs(),e.txSubType){case"EntryDeposit":o=fa.fromData(e.intentionData);break;case"EntryBorrow":o=da.fromData(e.intentionData);break;case"EntryRepay":o=ha.fromData(e.intentionData);break;case"EntryWithdraw":o=ga.fromData(e.intentionData);break;case"EntryMultiDeposit":o=ya.fromData(e.intentionData);break;case"ClaimReward":o=ma.fromData(e.intentionData);break;case"EntryClaimAndDeposit":o=pa.fromData(e.intentionData);break;default:throw new Error("not implemented")}return o.build({suiClient:t,account:n})}};var En=require("@msafe/sui3-utils"),hu=require("@mysten/bcs"),gu=require("@mysten/sui/transactions"),yu=$t(require("sort-keys-recursive")),bu="msafe-plain-tx",Su=En.TransactionSubTypes.others.plain,cs=class a{constructor(e){this.data=e}application=bu;txType=En.TransactionType.Other;txSubType=Su;serialize(){return JSON.stringify((0,yu.default)(this.data))}async build(e){return gu.Transaction.from((0,hu.fromHex)(this.data.content))}static fromData(e){return new a(e)}},Sa=class{application;supportSDK="@mysten/sui";constructor(){this.application=bu}async deserialize(e){let{content:t}=e.appContext;return{txType:En.TransactionType.Other,txSubType:Su,intentionData:{content:t}}}async build(e){let{suiClient:t,network:n,account:o}=e;return cs.fromData(e.intentionData).build({suiClient:t,network:n,account:o})}};var ms=require("@mysten/sui/client"),Tu=require("@mysten/sui/transactions"),Ia=require("@mysten/sui.js/client"),wu=require("@mysten/sui.js/transactions");var Ze=require("@open-rpc/client-js");var od={"-32700":"ParseError","-32600":"InvalidRequest","-32601":"MethodNotFound","-32602":"InvalidParams","-32603":"InternalError"},ls=class extends Error{},Ta=class extends ls{code;type;constructor(e,t){super(e),this.code=t,this.type=od[t]??"ServerError"}};function ad(a){let e=new URL(a);return e.protocol=e.protocol.replace("http","ws"),e.toString()}var rd={WebSocketConstructor:typeof WebSocket<"u"?WebSocket:void 0,callTimeout:3e4,reconnectTimeout:3e3,maxReconnects:5},wa=class{endpoint;options;#n=0;#a=0;#t=null;#e=null;#r=new Set;#o=new Map;constructor(e,t={}){this.endpoint=e,this.options={...rd,...t},this.endpoint&&this.endpoint.startsWith("http")&&(this.endpoint=ad(this.endpoint))}async makeRequest(e,t){let n=await this.#i();return new Promise((o,r)=>{this.#n+=1,this.#o.set(this.#n,{resolve:o,reject:r,timeout:setTimeout(()=>{this.#o.delete(this.#n),r(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:r})=>{if(o)throw new Ta(o.message,o.code);return r})}#i(){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:r}=this.#o.get(n.id);clearTimeout(r),o(n)}else if("params"in n){let{params:o}=n;this.#r.forEach(r=>{r.subscriptionId===o.subscription&&o.subscription===r.subscriptionId&&r.onMessage(o.result)})}})}),this.#e)}async#s(){return this.#t?.close(),this.#e=null,Promise.allSettled([...this.#r].map(e=>e.subscribe(this)))}async subscribe(e){let t=new us(e);return this.#r.add(t),await t.subscribe(this),()=>t.unsubscribe(this)}},us=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 Se=class{rpcClient;websocketClient;constructor({url:e,websocket:{url:t,...n}={},rpc:o}){let r=new Ze.HTTPTransport(o?.url??e,{headers:{"Content-Type":"application/json",...o?.headers}});this.rpcClient=new Ze.Client(new Ze.RequestManager([r])),this.websocketClient=new wa(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 Ca=class a{apps;constructor(){this.apps=new Map}static fromHelpers(e){let t=new a;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 ds(e))}addHelper(e){this.apps.set(e.application,new ps(e))}getAppHelper(e){let t=this.apps.get(e);if(!t)throw new Error(`${e} not registered`);return t}},ps=class{constructor(e){this.helper=e}async deserialize(e){let t=new ms.SuiClient({transport:new Se({url:e.clientUrl,rpc:{url:e.clientUrl}})}),n=new Ia.SuiClient({transport:new Se({url:e.clientUrl,rpc:{url:e.clientUrl}})}),o=await e.transactionBlock.build({client:n}),r=Tu.Transaction.from(o);return this.helper.deserialize({...e,suiClient:t,transaction:r})}async build(e){let t=new ms.SuiClient({transport:new Se({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 r=await o.build({client:t});return wu.TransactionBlock.from(r)}},ds=class{constructor(e){this.helper=e}async deserialize(e){let t=new Ia.SuiClient({transport:new Se({url:e.clientUrl,rpc:{url:e.clientUrl}})});return this.helper.deserialize({...e,transactionBlock:e.transactionBlock,suiClient:t})}async build(e){let t=new Ia.SuiClient({transport:new Se({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 Pu=require("@msafe/sui3-utils"),Bu=require("@mysten/sui/client"),Ru=require("@scallop-io/sui-scallop-sdk");var Ot=require("@msafe/sui3-utils"),gs=require("@scallop-io/sui-scallop-sdk");var Iu=require("@mysten/sui/utils"),Te=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:r}=(0,Iu.parseStructTag)(t);return e?e.package===n&&e.module===o&&e.function===r:!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((r,c,u)=>(r[c]=u,r),{}),o=[];return this.commands.forEach(r=>{this.isMoveCall(r)&&r.MoveCall&&t.has(r.MoveCall.package)&&(o[n[r.MoveCall.package]]=r.MoveCall)}),o}hasMoveCallCommand(e){return this.movecallsAsSet.has(e)}};var ka=require("@mysten/sui/bcs"),we=require("@mysten/sui/utils"),fs=class a{constructor(e,t,n=0){this.moveCall=e;this.transaction=t;let o=[];e?.MoveCall&&t.getData().commands.filter((r,c)=>{if(r.$kind==="MoveCall"){let u=`${r.MoveCall.package}::${r.MoveCall.module}::${r.MoveCall.function}`,d=`${e.MoveCall.package}::${e.MoveCall.module}::${e.MoveCall.function}`;return u===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 a.getSharedObjectId(t)}decodeOwnedObjectId(e){let t=this.getInputParam(e);return a.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,we.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 a.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=ka.bcs[t];return ka.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,we.normalizeSuiAddress)(e.value.Object.ImmOrOwned.objectId)}return(0,we.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,we.normalizeSuiAddress)(e.value);if(!("Object"in e.value)||!("Shared"in e.value.Object))throw new Error("not Shared");return(0,we.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 ka.bcs.U64.parse(new Uint8Array(t))}typeArg(e){return(0,we.normalizeStructTag)(this.txBlockTransactions.typeArguments[e])}txArg(e){return this.transaction.blockData.inputs[e]}},W=fs;var hs=class{constructor(e,t){this.splitCoin=e;this.txb=t}getAmountInput(){return this.splitCoin.amounts.map(e=>{if(e.kind==="Input")return Number(W.getPureInputValue(e,"U64"))}).filter(e=>e!==void 0)}},Bt=hs;var Ie=require("@mysten/sui/utils"),Cu=async(a,e)=>{let t=await a.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 r=a.address.get("borrowIncentive.object");return o===`${r.slice(2)}::incentive_account::IncentiveProgramLockKey`},tn={id:"0xc63072e7f5f4983a2efaf5bdba1480d5e7d74d57948e1c7cc436f8e22cbeb410",incentivePools:"0x64972b713ccec45ec3964809e477cea6f97350c0c50ca3aec85bb631639266ec",incentiveAccounts:"0x3c0b707068bdcea8bb859d751ad3e2149a9f83c13fcf4054ef91372a00bccdd3"},Kt={unstakeObligation:(a,e,t)=>a.moveCall(`${tn.id}::user::unstake`,[tn.incentivePools,tn.incentiveAccounts,a.object(e),a.object(t),Ie.SUI_CLOCK_OBJECT_ID],[(0,Ie.normalizeStructTag)(Ie.SUI_TYPE_ARG)]),redeem_rewards:(a,e,t,n)=>a.moveCall(`${tn.id}::user::redeem_rewards`,[tn.incentivePools,tn.incentiveAccounts,a.object(e),a.object(t),Ie.SUI_CLOCK_OBJECT_ID],[(0,Ie.normalizeStructTag)(n)])};var ku=(a,e)=>{let t=[];for(let n=0;n<a.length;n+=e)t.push(a.slice(n,n+e));return t};var va=class extends Te{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(`${gs.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 W(t,this.transaction))}get helperClaimBorrowV2Reward(){return this.commands.filter(t=>this.filterMoveCallCommands(t,`${this.coreId.borrowIncentivePkg}::user::redeem_rewards`)).map(t=>new W(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 W(e,this.transaction)}get helperClaimBorrowReward(){return this.commands.filter(t=>this.filterMoveCallCommands(t,`${gs.OLD_BORROW_INCENTIVE_PROTOCOL_ID}::user::redeem_rewards`)).map(t=>new W(t,this.transaction))}get helperMint(){let e=this.commands.find(t=>this.filterMoveCallCommands(t,`${this.coreId.protocolPkg}::mint::mint`));return new W(e,this.transaction)}get helperUnstakes(){return this.commands.filter(t=>this.filterMoveCallCommands(t,`${this.coreId.spoolPkg}::user::unstake`)).map(t=>new W(t,this.transaction))}get helperRedeems(){return this.commands.filter(t=>this.filterMoveCallCommands(t,`${this.coreId.protocolPkg}::redeem::redeem`)).map(t=>new W(t,this.transaction))}get helperRedeem(){let e=this.commands.find(t=>this.filterMoveCallCommands(t,`${this.coreId.protocolPkg}::redeem::redeem`));return new W(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 W(e,this.transaction)}get helperStake(){let e=this.commands.find(t=>this.filterMoveCallCommands(t,`${this.coreId.spoolPkg}::user::stake`));return new W(e,this.transaction)}get helperUnstake(){let e=this.commands.find(t=>this.filterMoveCallCommands(t,`${this.coreId.spoolPkg}::user::unstake`));return new W(e,this.transaction)}get helperDepositCollateral(){let e=this.commands.find(t=>this.filterMoveCallCommands(t,`${this.coreId.protocolPkg}::deposit_collateral::deposit_collateral`));return new W(e,this.transaction)}get helperWithdrawCollateral(){let e=this.commands.find(t=>this.filterMoveCallCommands(t,`${this.coreId.protocolPkg}::withdraw_collateral::withdraw_collateral`));return new W(e,this.transaction)}get helperBorrow(){let e=this.commands.find(t=>this.filterMoveCallCommands(t,`${this.coreId.protocolPkg}::borrow::borrow`));return new W(e,this.transaction)}get helperBorrowWithReferral(){let e=this.commands.find(t=>this.filterMoveCallCommands(t,`${this.coreId.protocolPkg}::borrow::borrow_with_referral`));return new W(e,this.transaction)}get helperRepay(){let e=this.commands.find(t=>this.filterMoveCallCommands(t,`${this.coreId.protocolPkg}::repay::repay`));return new W(e,this.transaction)}decodeMigrateScoin(){return{txType:Ot.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:Ot.TransactionType.Other,type:"MigrateAndClaim",intentionData:{obligationKey:t,obligationId:n,rewardCoinName:o,veScaKey:e}}}decodeOpenObligation(){return{txType:Ot.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,r)=>o+r,0);return{txType:Ot.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,r)=>o+r,0);return{txType:Ot.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,r)=>o+r,0);return{txType:Ot.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((r,c)=>r+c,0),o=this.helperDepositCollateral.decodeSharedObjectId(1);return{txType:Ot.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:Ot.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:Ot.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),r=this.helperBorrow.decodeOwnedObjectId(2);return{txType:Ot.TransactionType.Other,type:"BorrowWithBoost",intentionData:{amount:n,coinName:e,obligationKey:r,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),r=this.helperBorrowWithReferral.decodeOwnedObjectId(2);return{txType:Ot.TransactionType.Other,type:"BorrowWithReferral",intentionData:{amount:n,coinName:e,obligationKey:r,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((r,c)=>r+c,0),o=this.helperRepay.decodeSharedObjectId(1);return{txType:Ot.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,u)=>c+u,0),r=this.helperRepay.decodeSharedObjectId(1);return{txType:Ot.TransactionType.Other,type:"RepayWithBoost",intentionData:{amount:o,obligationId:r,coinName:e,veScaKey:t}}}decodeStakeSpool(){let e;this.isCreateStakeAccountTransaction()||(e=this.helperStake.decodeOwnedObjectId(1));let t=0;if(this.helperBurnScoin.moveCall){let r=this.helperBurnScoin.getNestedInputParam(1);t=new Bt(r,this.transaction).getAmountInput().reduce((c,u)=>c+u,0)}if(this.helperStake.moveCall&&t===0){let r=this.helperStake.getNestedInputParam(2);t=new Bt(r,this.transaction).getAmountInput().reduce((c,u)=>c+u,0)}let n=this.helperStake.typeArg(0),o=this.utils.parseCoinNameFromType(n);return{txType:Ot.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:Ot.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((r,c)=>r+c,0),o;return this.isCreateStakeAccountTransaction()||(o=this.helperStake.decodeOwnedObjectId(1)),{txType:Ot.TransactionType.Other,type:"SupplyAndStakeLending",intentionData:{amount:n,coinName:e,stakeAccountId:o}}}decodeUnstakeAndWithdraw(){let e=[];this.helperUnstakes.forEach(o=>{let r=o.decodeOwnedObjectId(1),c=o.decodeInputU64(2);e.push({id:r,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((r,c)=>r+c,0)}return{txType:Ot.TransactionType.Other,type:"WithdrawAndUnstakeLending",intentionData:{amount:n,coinName:t,stakeAccountId:e}}}decodeClaimReward(){let e=[],t=[],n=[];return this.helperClaimLendingReward.forEach(o=>{let r=o.decodeOwnedObjectId(2),c=o.typeArg(0),u=this.utils.parseCoinNameFromType(c);e.push({stakeMarketCoinName:u,stakeAccountId:r})}),this.helperClaimBorrowV2Reward.forEach(o=>{let r=o.decodeSharedObjectId(4),c=o.decodeOwnedObjectId(3),u=this.utils.parseCoinNameFromType(o.typeArg(0));t.push({obligationId:c,obligationKey:r,rewardCoinName:u})}),this.helperClaimBorrowReward.forEach(o=>{let r=o.decodeSharedObjectId(2),c=o.decodeOwnedObjectId(3),u=this.utils.parseCoinNameFromType(o.typeArg(0));n.push({obligationId:c,obligationKey:r,rewardCoinName:u})}),{txType:Ot.TransactionType.Other,type:"ClaimIncentiveReward",intentionData:{lendingIncentive:e,borrowIncentiveV2:t,borrowIncentive:n}}}};var xa=require("@msafe/sui3-utils");var Da=class extends Te{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 W(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 W(e,this.transaction)}decodeCreateReferralLink(){return{txType:xa.TransactionType.Other,type:"CreateReferralLink",intentionData:{}}}decodeClaimRevenueReferral(){let e=this.helperClaimRevenueReferral[0].decodeOwnedObjectId(2),t=this.helperClaimRevenueReferral.map(n=>n.typeArg(0));return{txType:xa.TransactionType.Other,type:"ClaimRevenueReferral",intentionData:{veScaKey:e,coins:t}}}decodeBindReferral(){let e=this.helperBindReferral.decodePureArg(1,"Address");return{txType:xa.TransactionType.Other,type:"BindReferral",intentionData:{veScaKey:e}}}};var ee=require("@msafe/sui3-utils"),vu=require("@scallop-io/sui-scallop-sdk");var Aa=class extends Te{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(u=>this.filterMoveCallCommands(u,`${this.coreId.borrowIncentivePkg}::user::unstake_v2`)),t=this.commands.filter(u=>this.filterMoveCallCommands(u,`${this.coreId.borrowIncentivePkg}::user::stake_with_ve_sca_v2`)),n=this.commands.filter(u=>this.filterMoveCallCommands(u,`${this.coreId.borrowIncentivePkg}::user::deactivate_boost_v2`)),o=e.length>0&&t.length>0&&e.length===t.length,r=n.length>0;return this.commands.length===e.length+t.length+n.length&&(o||r)}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),r=this.inputs.filter((d,S)=>d.$kind==="Object"&&o.has(S)).map(d=>d.Object.ImmOrOwnedObject),c=`${this.coreId.veScaObjId}::ve_sca::VeScaKey`,u=ku(r.map(({objectId:d})=>d),50);for(let d=0;d<u.length;d++){let S=u[d];if((await this.scallopClient.scallopSuiKit.queryGetObjects(S,{showType:!0})).some(I=>I.type!==c))return!1}return r.length>0}get helperStakeMoreSca(){let e=this.commands.find(t=>this.filterMoveCallCommands(t,`${this.coreId.veScaPkgId}::ve_sca::lock_more_sca`));return new W(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 W(e,this.transaction)}get helperExtendStakePeriod(){let e=this.commands.find(t=>this.filterMoveCallCommands(t,`${this.coreId.veScaPkgId}::ve_sca::extend_lock_period`));return new W(e,this.transaction)}get helperRedeemSca(){let e=this.commands.find(t=>this.filterMoveCallCommands(t,`${this.coreId.veScaPkgId}::ve_sca::redeem`));return new W(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 W(e,this.transaction)}get helperOldUnstakeObligation(){let e=this.commands.find(t=>this.filterMoveCallCommands(t,`${vu.OLD_BORROW_INCENTIVE_PROTOCOL_ID}::user::unstake`));return new W(e,this.transaction)}get helperUnstakeObligation(){let e=this.commands.find(t=>this.filterMoveCallCommands(t,`${this.coreId.borrowIncentivePkg}::user::unstake_v2`));return new W(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 W(e,this.transaction)}getMergeSplitVeScaHelper(e){let t=this.commands.find(n=>this.filterMoveCallCommands(n,`${this.coreId.veScaPkgId}::ve_sca::${e}`));return new W(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=[],r=0,c=0,u=0;return this.commands.forEach(d=>{this.filterMoveCallCommands(d,e)?(o.push({action:"unstake",helper:new W(d,this.transaction,r)}),r++):this.filterMoveCallCommands(d,t)?(o.push({action:"stake",helper:new W(d,this.transaction,c)}),c++):this.filterMoveCallCommands(d,n)&&(o.push({action:"deactivate",helper:new W(d,this.transaction,u)}),u++)}),o}decodeRedeemSca(){let e=this.helperRedeemSca.decodeOwnedObjectId(1);return{txType:ee.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((x,P)=>x+P,0),o=this.helperRenewExpired.decodeOwnedObjectId(1),r=!!this.helperRedeemSca.moveCall,c=[],u=[],d=[];this.helperOldUnstakeObligation.moveCall&&(c=[this.helperOldUnstakeObligation.decodeOwnedObjectId(2),this.helperOldUnstakeObligation.decodeSharedObjectId(3)]),this.helperUnstakeObligation.moveCall&&(u=[this.helperUnstakeObligation.decodeOwnedObjectId(3),this.helperUnstakeObligation.decodeSharedObjectId(4)]),this.helperStakeObligationWithVeSca.moveCall&&(d=[this.helperStakeObligationWithVeSca.decodeOwnedObjectId(3),this.helperStakeObligationWithVeSca.decodeSharedObjectId(4)]);let S=!1,w=!1,I,C,k=[{condition:c,isOld:!0},{condition:u,isOld:!1},{condition:d,isOld:!1}];for(let x=0;x<k.length;x++)k[x].condition.length>1&&([C,I]=k[x].condition,S=!0,w=k[x].isOld);return{txType:ee.TransactionType.Other,type:"RenewExpStakePeriod",intentionData:{amount:n,unlockTime:t,obligationId:I,obligationKey:C,veScaKey:o,isHaveRedeem:r,isObligationLocked:S,isOldBorrowIncentive:w}}}decodeExtendStakePeriod(){let e=this.helperExtendStakePeriod.decodeInputU64(4),t=this.helperExtendStakePeriod.decodeOwnedObjectId(1),n=[],o=[],r=[];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&&(r=[this.helperStakeObligationWithVeSca.decodeOwnedObjectId(3),this.helperStakeObligationWithVeSca.decodeSharedObjectId(4)]);let c=!1,u=!1,d,S,w=[{condition:n,isOld:!0},{condition:o,isOld:!1},{condition:r,isOld:!1}];for(let I=0;I<w.length;I++)w[I].condition.length>1&&([S,d]=w[I].condition,c=!0,u=w[I].isOld);return{txType:ee.TransactionType.Other,type:"ExtendStakePeriod",intentionData:{unlockTime:e,obligationId:d,obligationKey:S,veScaKey:t,isObligationLocked:c,isOldBorrowIncentive:u}}}decodePeriodAndStakeMoreSca(){let e=this.helperStakeMoreSca.getNestedInputParam(4),t=this.helperExtendStakePeriod.decodeInputU64(4),n=new Bt(e,this.transaction).getAmountInput().reduce((k,x)=>k+x,0),o=[],r=[],c,u=[];this.helperOldUnstakeObligation.moveCall&&(o=[this.helperOldUnstakeObligation.decodeOwnedObjectId(2),this.helperOldUnstakeObligation.decodeSharedObjectId(3)]),this.helperUnstakeObligation.moveCall&&(r=[this.helperUnstakeObligation.decodeOwnedObjectId(3),this.helperUnstakeObligation.decodeSharedObjectId(4)]),this.helperStakeMoreSca.moveCall&&(c=this.helperStakeMoreSca.decodeOwnedObjectId(1)),this.helperStakeObligationWithVeSca.moveCall&&(u=[this.helperStakeObligationWithVeSca.decodeOwnedObjectId(3),this.helperStakeObligationWithVeSca.decodeSharedObjectId(4)]);let d=!1,S=!1,w,I,C=[{condition:o,isOld:!0},{condition:r,isOld:!1},{condition:u,isOld:!1}];for(let k=0;k<C.length;k++)C[k].condition.length>1&&([I,w]=C[k].condition,d=!0,S=C[k].isOld);return{txType:ee.TransactionType.Other,type:"ExtendPeriodAndStakeMore",intentionData:{amount:n,veScaKey:c,unlockTime:t,obligationId:w,obligationKey:I,isOldBorrowIncentive:S,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((k,x)=>k+x,0),o=[],r=[],c,u=[];this.helperOldUnstakeObligation.moveCall&&(o=[this.helperOldUnstakeObligation.decodeOwnedObjectId(2),this.helperOldUnstakeObligation.decodeSharedObjectId(3)]),this.helperUnstakeObligation.moveCall&&(r=[this.helperUnstakeObligation.decodeOwnedObjectId(3),this.helperUnstakeObligation.decodeSharedObjectId(4)]),this.helperStakeMoreSca.moveCall&&(c=this.helperStakeMoreSca.decodeOwnedObjectId(1)),this.helperStakeObligationWithVeSca.moveCall&&(u=[this.helperStakeObligationWithVeSca.decodeOwnedObjectId(3),this.helperStakeObligationWithVeSca.decodeSharedObjectId(4)]);let d=!1,S=!1,w,I,C=[{condition:o,isOld:!0},{condition:r,isOld:!1},{condition:u,isOld:!1}];for(let k=0;k<C.length;k++)C[k].condition.length>1&&([I,w]=C[k].condition,d=!0,S=C[k].isOld);return{txType:ee.TransactionType.Other,type:"StakeSca",intentionData:{amount:n,unlockTime:t,obligationId:w,obligationKey:I,veScaKey:c,isObligationLocked:d,isOldBorrowIncentive:S}}}decodeMergeVesca(){let e=this.getMergeSplitVeScaHelper("merge"),t={targetVeScaKey:e.decodeOwnedObjectId(1),sourceVeScaKey:e.decodeOwnedObjectId(2)};return{txType:ee.TransactionType.Other,type:"MergeVeSca",intentionData:t}}decodeSplitVesca(){let e=this.getMergeSplitVeScaHelper("split"),t={targetVeScaKey:e.decodeOwnedObjectId(1),splitAmount:e.decodeInputU64(4)};return{txType:ee.TransactionType.Other,type:"SplitVeSca",intentionData:t}}decodeVeScaObligationBindings(){let e=this.getVeScaObligationBindingHelpers(),t=(o,r)=>{switch(o){case"stake":return{veScaKey:r.decodeOwnedObjectId(9),obligationId:r.decodeSharedObjectId(4),obligationKey:r.decodeOwnedObjectId(3)};case"unstake":return{obligationId:r.decodeSharedObjectId(4),obligationKey:r.decodeOwnedObjectId(3)};case"deactivate":return{veScaKey:r.decodeOwnedObjectId(4),obligationId:r.decodeSharedObjectId(3)};default:throw new Error(`Invalid action ${o}`)}},n=e.map(({action:o,helper:r})=>({action:o,args:t(o,r)}));return{txType:ee.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),r=this.inputs.filter((c,u)=>c.$kind==="Object"&&o.has(u)).map(c=>c.Object.ImmOrOwnedObject);return{xType:ee.TransactionType.Other,type:"TransferVeScaKeys",intentionData:{veScaKeys:r}}}};var xu=$t(require("sort-keys-recursive")),A=class{constructor(e){this.data=e}get application(){return"msafe-core"}serialize(){return JSON.stringify((0,xu.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:r,obligationKey:c}=t;return await this.isObligationLocked(e.scallopSuiKit.client,r)?(await o.unstakeObligationQuick(r,c),await n(e,o,t),await o.stakeObligationWithVeScaQuick(r,c,t.veScaKey)):await n(e,o,t),o}};var Oa=class a extends A{constructor(t){super(t);this.data=t}txType;txSubType;async borrow({account:t,scallopClient:n}){let{coinName:o,amount:r,obligationId:c,obligationKey:u}=this.data,d=t.address;return(await this.buildTxWithRefreshObligation(n,{walletAddress:d,obligationId:c,obligationKey:u},async(w,I)=>{let C=await I.borrowQuick(+r,o,c,u);I.transferObjects([C],d)})).txBlock}async build(t){return this.borrow(t)}static fromData(t){return new a(t)}};var Ma=class a extends A{constructor(t){super(t);this.data=t}txType;txSubType;async borrowWithBoost(t,n){let{obligationId:o,obligationKey:r,veScaKey:c,amount:u,coinName:d}=this.data;return(await this.buildTxWithRefreshObligation(t,{walletAddress:n,obligationId:o,obligationKey:r,veScaKey:c},async(w,I)=>{let C=await I.borrowQuick(+u,d,o,r);I.transferObjects([C],n)})).txBlock}async build(t){return this.borrowWithBoost(t.scallopClient,t.account.address)}static fromData(t){return new a(t)}};var Pa=class a extends A{constructor(t){super(t);this.data=t}txType;txSubType;async borrowWithReferral({account:t,scallopClient:n}){let o=t.address,{obligationId:r,obligationKey:c,veScaKey:u,coinName:d,amount:S}=this.data;return(await this.buildTxWithRefreshObligation(n,{walletAddress:o,obligationId:r,obligationKey:c,veScaKey:u},async(I,C)=>{let k=C.claimReferralTicket(d),x=await C.borrowWithReferralQuick(+S,d,k,r,c);C.burnReferralTicket(k,d),C.transferObjects([x],o)})).txBlock}async build(t){return this.borrowWithReferral(t)}static fromData(t){return new a(t)}};var Du=require("@mysten/sui/utils");var Ba=class a 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),r=await e.query.getLendings(void 0,t),c=await e.query.getObligations(t),u=Object.values(await e.query.getObligationAccounts(t)??[]),d=(()=>{let C=[...e.constants.whitelist.spool].map(k=>e.utils.parseCoinName(k));return Object.values(r??[]).filter(k=>!!k&&C.includes(k.coinName)).reduce((k,x)=>{let P=e.utils.parseMarketCoinName(x.coinName);return k[P]||(k[P]=0),k[P]+=x.availableClaimCoin,k},{})})(),S={};Object.entries(o).forEach(([C,k])=>{for(let x=0;x<k.length;x++){let P=k[x];if(!d[C])continue;let L=n.claim(P.id,C);S.sui?S.sui.push(L):S.sui=[L]}});let w=(()=>{let C={};return C.sui=Object.values(d).reduce((k,x)=>k+x,0),u.forEach(k=>{Object.values(k.borrowIncentives).forEach(x=>{x&&x.rewards.forEach(P=>{C[P.coinName]||(C[P.coinName]=0),C[P.coinName]?C[P.coinName]+=P.availableClaimCoin:C[P.coinName]=P.availableClaimCoin})})}),C})();if(c.length>0&&u.length>0)for(let C=0;C<u.length;C++){let k=u[C],x=!1,P=c.find(V=>V.id===k.obligationId)?.keyId,L={};if(P){if(Object.values(k.borrowIncentives).forEach(V=>{if(V){let _t=V.rewards.filter(Rt=>{let Et=Rt.coinName;return Rt.availableClaimCoin>0&&!L[Et]});x=_t.length>0,_t.forEach(Rt=>{let Et=n.claimBorrowIncentive(k.obligationId,P,Rt.coinName);L[Rt.coinName]=!0,S[Rt.coinName]?S[Rt.coinName].push(Et):S[Rt.coinName]=[Et]})}}),w.sui>0){let V=Kt.redeem_rewards(n,P,k.obligationId,Du.SUI_TYPE_ARG);S.sui?S.sui.push(V):S.sui=[V]}if(x&&await Cu(e.query,k.obligationId)){n.unstakeObligation(k.obligationId,P);let _t=await e.query.getBindedVeScaKey(k.obligationId);_t?n.stakeObligationWithVesca(k.obligationId,P,_t):n.stakeObligation(k.obligationId,P)}}}let I=(await Promise.all(Object.entries(S).map(async([C,k])=>{let x=k[0];if(k.length>1&&n.mergeCoins(x,k.slice(1)),C==="sui"){n.mergeCoins(n.gas,[x]);return}return await e.builder.utils.mergeSimilarCoins(n,x,e.utils.parseCoinType(C),t),x}))).filter(C=>!!C);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 a(e)}};var Ra=class a 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 a(t)}};var Ea=class a extends A{constructor(t){super(t);this.data=t}txType;txSubType;async migrateAndClaim({account:t,scallopClient:n}){let o=t.address,{obligationKey:r,obligationId:c,rewardCoinName:u,veScaKey:d}=this.data,S=n.builder.createTxBlock();S.setSender(o);let w=Kt.redeem_rewards(S,r,c,n.utils.parseCoinType(u));return S.transferObjects([w],o),await S.unstakeObligationQuick(c,r),d?await S.stakeObligationWithVeScaQuick(c,r,d):await S.stakeObligationQuick(c,r),S.txBlock}async build(t){return this.migrateAndClaim(t)}static fromData(t){return new a(t)}};var Na=class a 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 a(t)}};var Wa=class a extends A{constructor(t){super(t);this.data=t}txType;txSubType;async build(t){return t.scallopClient.openObligation(!1)}static fromData(t){return new a(t)}};var _a=class a extends A{constructor(t){super(t);this.data=t}txType;txSubType;async repay({account:t,scallopClient:n}){let o=t.address,{coinName:r,amount:c,obligationId:u,obligationKey:d}=this.data;return(await this.buildTxWithRefreshObligation(n,{walletAddress:o,obligationId:u,obligationKey:d},async(w,I)=>{await I.repayQuick(+c,r,u)})).txBlock}async build(t){return this.repay(t)}static fromData(t){return new a(t)}};var La=class a extends A{constructor(t){super(t);this.data=t}txType;txSubType;async repayWithBoost({account:t,scallopClient:n}){let o=t.address,{coinName:r,amount:c,obligationId:u,veScaKey:d}=this.data,S=n.builder.createTxBlock();S.setSender(o);let w=n.constants.whitelist.borrowing.has(r);return w&&await S.unstakeObligationQuick(u,void 0),await S.repayQuick(+c,r,u),w&&await S.stakeObligationWithVeScaQuick(u,void 0,d),S.txBlock}async build(t){return this.repayWithBoost(t)}static fromData(t){return new a(t)}};var ja=class a 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 a(t)}};var Ua=class a 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 a(t)}};var qa=class a extends A{constructor(t){super(t);this.data=t}txType;txSubType;async unstakeAndWithdraw(t,n,o){let r=t.builder.createTxBlock();r.setSender(o);let{stakeAccountId:c,amount:u,coinName:d}=this.data,S=[];for(let w=0;w<c.length;w++){let{id:I,coin:C}=c[w],k=t.utils.parseMarketCoinName(d),[x]=await r.unstakeQuick(C,k,I);if(x){let P=r.withdraw(x,d);S.push(P)}}if(u>0){let w=await r.withdrawQuick(u,d);S.push(w)}return S.length>1&&r.mergeCoins(S[0],S.slice(1)),r.transferObjects(S,o),r.txBlock}async build(t){return this.unstakeAndWithdraw(t.scallopClient,this.data,t.account.address)}static fromData(t){return new a(t)}};var Fa=class a 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 a(t)}};var Ka=class a 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 a(t)}};var Va=class a extends A{constructor(t){super(t);this.data=t}txType;txSubType;async bindReferral({account:t,scallopClient:n}){let o=t.address,r=n.builder.createTxBlock();return r.setSender(o),r.bindToReferral(this.data.veScaKey),r.txBlock}async build(t){return this.bindReferral(t)}static fromData(t){return new a(t)}};var $a=class a extends A{constructor(t){super(t);this.data=t}txType;txSubType;async claimRevenueReferral({account:t,scallopClient:n}){let{veScaKey:o,coins:r}=this.data,c=t.address,u=n.builder.createTxBlock();u.setSender(c);let d=r.map(S=>n.utils.parseCoinNameFromType(S));return await u.claimReferralRevenueQuick(o,d),u.txBlock}async build(t){return this.claimRevenueReferral(t)}static fromData(t){return new a(t)}};var Ha=class a extends A{constructor(t){super(t);this.data=t}txType;txSubType;async createReferralLink({account:t,scallopClient:n}){let o=t.address,r=n.builder.createTxBlock();r.setSender(o);let c=r.mintEmptyVeSca();return r.transferObjects([c],o),r.txBlock}async build(t){return this.createReferralLink(t)}static fromData(t){return new a(t)}};var Au=require("@scallop-io/sui-scallop-sdk");var Ga=class a extends A{constructor(t){super(t);this.data=t}txType;txSubType;async extendPeriodAndStakeMoreSca({account:t,scallopClient:n}){let{amount:o,veScaKey:r,unlockTime:c,obligationId:u,obligationKey:d,isOldBorrowIncentive:S,isObligationLocked:w}=this.data,I=t.address,C=n.builder.createTxBlock();C.setSender(I);let k=await n.utils.selectCoins(o,Au.SCA_COIN_TYPE,I),[x,P]=C.takeAmountFromCoins(k,o);return C.extendLockPeriod(r,c),C.extendLockAmount(r,x),C.transferObjects([P],I),!u||!d||(w&&(S?Kt.unstakeObligation(C,u,d):C.unstakeObligation(u,d)),C.stakeObligationWithVesca(u,d,r)),C.txBlock}async build(t){return this.extendPeriodAndStakeMoreSca(t)}static fromData(t){return new a(t)}};var Qa=class a extends A{constructor(t){super(t);this.data=t}txType;txSubType;async extendStakeScaLockPeriod({account:t,scallopClient:n}){let o=t.address,{veScaKey:r,unlockTime:c,obligationId:u,obligationKey:d,isObligationLocked:S,isOldBorrowIncentive:w}=this.data,I=n.builder.createTxBlock();return I.setSender(o),I.extendLockPeriod(r,c),u&&d&&(S&&(w?Kt.unstakeObligation(I,d,u):I.unstakeObligation(u,d)),I.stakeObligationWithVesca(u,d,r)),I.txBlock}async build(t){return this.extendStakeScaLockPeriod(t)}static fromData(t){return new a(t)}};var za=class a extends A{constructor(t){super(t);this.data=t}txType;txSubType;async handleUnsubForKeys(t,n,o){let{targetVeScaKey:r,sourceVeScaKey:c}=this.data,[u,d]=await Promise.all([n.getBindedObligationId(r),n.getBindedObligationId(c)]);u&&await t.unstakeObligationQuick(u),d&&await t.unstakeObligationQuick(d),o(t,r,c),u&&await t.stakeObligationWithVeScaQuick(u,void 0,r),d&&await t.stakeObligationWithVeScaQuick(d,void 0,c)}async build(t){let{scallopClient:n,account:{address:o}}=t,r=n.builder.createTxBlock();return r.setSender(o),await this.handleUnsubForKeys(r,n.query,async(c,u,d)=>{c.mergeVeSca(r.object(u),r.object(d))}),r.txBlock}static fromData(t){return new a(t)}};var Ja=class a extends A{constructor(t){super(t);this.data=t}txType;txSubType;async redeemSca({account:t,scallopClient:n}){let{veScaKey:o}=this.data,r=t.address,c=n.builder.createTxBlock();return c.setSender(r),await c.redeemScaQuick(o),c.txBlock}async build(t){return this.redeemSca(t)}static fromData(t){return new a(t)}};var Ou=require("@scallop-io/sui-scallop-sdk");var Xa=class a extends A{constructor(t){super(t);this.data=t}txType;txSubType;async renewExpiredStakeSca({account:t,scallopClient:n}){let o=t.address,{amount:r,unlockTime:c,veScaKey:u,isHaveRedeem:d,obligation:S,obligationKey:w,isObligationLocked:I,isOldBorrowIncentive:C}=this.data,k=n.builder.createTxBlock();if(k.setSender(o),d){let V=k.redeemSca(u);k.transferObjects([V],o)}let x=await n.builder.utils.selectCoins(r,Ou.SCA_COIN_TYPE,o),[P,L]=k.takeAmountFromCoins(x,r);return k.transferObjects([L],o),k.renewExpiredVeSca(u,P,c),!S||!w||(I&&(C?Kt.unstakeObligation(k,w,S):k.unstakeObligation(S,w)),k.stakeObligationWithVesca(S,w,u)),k.txBlock}async build(t){return this.renewExpiredStakeSca(t)}static fromData(t){return new a(t)}};var Ya=class a extends A{constructor(t){super(t);this.data=t}txType;txSubType;async handleUnsubForKeys(t,n,o){let{targetVeScaKey:r,splitAmount:c}=this.data,u=await n.getBindedObligationId(r);u&&await t.unstakeObligationQuick(u),o(t,r,c.toString()),u&&await t.stakeObligationWithVeScaQuick(u,void 0,r)}async build(t){let{scallopClient:n,account:{address:o}}=t,r=n.builder.createTxBlock();return r.setSender(o),await this.handleUnsubForKeys(r,n.query,(c,u,d)=>{let S=c.splitVeSca(u,d.toString());c.transferObjects([S],o)}),r.txBlock}static fromData(t){return new a(t)}};var Mu=require("@scallop-io/sui-scallop-sdk");var Za=class a extends A{constructor(t){super(t);this.data=t}txType;txSubType;async stakeSca({account:t,scallopClient:n}){let o=t.address,{amount:r,isObligationLocked:c,isOldBorrowIncentive:u,obligationId:d,obligationKey:S,unlockTime:w,veScaKey:I}=this.data,C=n.builder.createTxBlock();C.setSender(o);let k=await n.utils.selectCoins(r,Mu.SCA_COIN_TYPE,o),[x,P]=C.takeAmountFromCoins(k,r),L;return I?C.extendLockAmount(I,x):L=C.lockSca(x,w),d&&S&&(c&&(u?Kt.unstakeObligation(C,S,d):C.unstakeObligation(d,S)),C.stakeObligationWithVesca(d,S,I||L)),I||C.transferObjects([L,P],o),C.txBlock}async build(t){return this.stakeSca(t)}static fromData(t){return new a(t)}};var tr=class a extends A{constructor(t){super(t);this.data=t}txType;txSubType;async supplyAndStake({account:t,scallopClient:n}){let o=t.address,{amount:r,coinName:c,stakeAccountId:u}=this.data,d=n.builder.createTxBlock();d.setSender(o);let S=await d.depositQuick(+r,c),w=n.utils.parseMarketCoinName(c);if(n.constants.whitelist.spool.has(w))return d.txBlock;let I=await n.query.getStakeAccounts(w,o),C=u||(I.length>0?I[0].id:void 0);if(C)await d.stakeQuick(S,w,C);else{let k=d.createStakeAccount(w);await d.stakeQuick(S,w,k),d.transferObjects([k],o)}return d.txBlock}async build(t){return this.supplyAndStake(t)}static fromData(t){return new a(t)}};var er=class a 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,r=n.builder.createTxBlock();r.setSender(o);let{bindingDatas:c}=this.data;return c.forEach(u=>this.handleAction(r,u)),r.txBlock}static fromData(t){return new a(t)}};var nr=class a extends A{constructor(t){super(t);this.data=t}txType;txSubType;async build(t){let{scallopClient:n,account:{address:o}}=t,r=n.builder.createTxBlock();r.setSender(o);let{veScaKeys:c}=this.data;return r.transferObjects(c.map(u=>r.objectRef(u)),r.pure.address(o)),r.txBlock}static fromData(t){return new a(t)}};var or=class a extends A{constructor(t){super(t);this.data=t}txType;txSubType;async withdrawUnlockedSca({account:t,scallopClient:n}){let{vescaKey:o}=this.data,r=t.address,c=n.builder.createTxBlock();return c.setSender(r),await c.redeemScaQuick(o),c.txBlock}async build(t){return this.withdrawUnlockedSca(t)}static fromData(t){return new a(t)}};var ar=class{application="scallop";supportSDK="@mysten/sui";scallopClient;async initScallopClient(e,t){if(!this.scallopClient){let n=new Ru.Scallop({addressId:"67c44a103fe1b8c454eb9699",walletAddress:e,suiClients:[t],fullnodeUrls:[t.transport.rpcClient.requestManager.transports[0]?.uri??(0,Bu.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 r=new va(t,this.scallopClient),c=new Da(t,this.scallopClient),u=new Aa(t,this.scallopClient),d=r.decode()||c.decode()||await u.decode();if(!d)throw new Error("Unknown transaction type");return{txType:Pu.TransactionType.Other,txSubType:d.type,intentionData:d.intentionData}}async build(e){let{suiClient:t,account:n,network:o,txSubType:r,intentionData:c}=e;await this.initScallopClient(n.address,t);let u;switch(r){case"SupplyLending":u=ja.fromData(c);break;case"WithdrawLending":u=Ka.fromData(c);break;case"Borrow":u=Oa.fromData(c);break;case"Repay":u=_a.fromData(c);break;case"DepositCollateral":u=Ra.fromData(c);break;case"WithdrawCollateral":u=Fa.fromData(c);break;case"OpenObligation":u=Wa.fromData(c);break;case"UnstakeSpool":u=Ua.fromData(c);break;case"ClaimIncentiveReward":u=Ba.fromData(c);break;case"BorrowWithBoost":u=Ma.fromData(c);break;case"StakeSca":u=Za.fromData(c);break;case"ExtendStakePeriod":u=Qa.fromData(c);break;case"ExtendPeriodAndStakeMore":u=Ga.fromData(c);break;case"RenewExpStakePeriod":u=Xa.fromData(c);break;case"WithdrawStakedSca":u=or.fromData(c);break;case"SupplyAndStakeLending":u=tr.fromData(c);break;case"WithdrawAndUnstakeLending":u=qa.fromData(c);break;case"RedeemSca":u=Ja.fromData(c);break;case"MigrateAndClaim":u=Ea.fromData(c);break;case"BorrowWithReferral":u=Pa.fromData(c);break;case"CreateReferralLink":u=Ha.fromData(c);break;case"ClaimRevenueReferral":u=$a.fromData(c);break;case"BindReferral":u=Va.fromData(c);break;case"MigrateScoin":u=Na.fromData(c);break;case"RepayWithBoost":u=La.fromData(c);break;case"MergeVeSca":u=za.fromData(c);break;case"SplitVeSca":u=Ya.fromData(c);break;case"VeScaObligationBindings":{u=er.fromData(c);break}case"TransferVeScaKeys":{u=nr.fromData(c);break}default:throw new Error("not implemented")}return u.build({suiClient:t,account:n,network:o,scallopClient:this.scallopClient})}};var em=require("@msafe/sui3-utils");var an=require("@msafe/sui3-utils"),ke=require("@mysten/sui/utils");var $u=require("@suilend/springsui-sdk/client");var Vu=require("@msafe/sui3-utils"),Ce=require("@suilend/sdk");var We=require("@msafe/sui3-utils"),nn=require("@mysten/bcs"),en=require("@mysten/sui/utils"),_e=require("@suilend/frontend-sui"),bs=$t(require("bignumber.js"));var rr=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,en.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,en.normalizeStructTag)(t.RedeemEvent.parsedJson.coin_type.name),o=t.RedeemEvent.parsedJson.liquidity_amount;console.log("Decoder.decodeWithdraw",n,o);let r=e.withdraw_ctokens.MoveCall.arguments[4].Input,c=new bs.default((0,nn.toHex)((0,nn.fromBase64)(this.inputs[r].Pure.bytes)),16).toString(),u=c===_e.MAX_U64.toString();return console.log("decodeWithdraw - isMax:",u,"inputIndex:",r,"inputValue:",c,"MAX_U64.toString():",_e.MAX_U64.toString()),u&&(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,en.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 r=e.borrow_request.MoveCall.arguments[4].Input,c=new bs.default((0,nn.toHex)((0,nn.fromBase64)(this.inputs[r].Pure.bytes)),16).toString(),u=c===_e.MAX_U64.toString();return console.log("decodeBorrow - isMax:",u,"inputIndex:",r,"inputValue:",c,"MAX_U64.toString():",_e.MAX_U64.toString()),u&&(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,en.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],r=(0,en.normalizeStructTag)(o.parsedJson.coin_type.name),c=o.parsedJson.liquidity_amount;t[r]=`${+(t[r]??"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 Nu=require("@mysten/sui/transactions");var Eu=$t(require("sort-keys-recursive")),Wt=class{constructor(e){this.data=e}serialize(){return JSON.stringify((0,Eu.default)(this.data))}};var ir=class a extends Wt{constructor(t){super(t);this.data=t}txType;txSubType;async build(t){let{suiClient:n,account:o,suilendClient:r,obligationOwnerCap:c,obligation:u}=t;if(console.log("BorrowIntention.build",n,o,r,c,u),!c||!u)throw new Error("Obligation not found");let d=new Nu.Transaction;return await r.borrowAndSendToUser(o.address,c.id,u.id,this.data.coinType,this.data.value,d),d}static fromData(t){return console.log("BorrowIntention.fromData",t),new a(t)}};var ju=require("@mysten/sui/transactions");var Wu=require("@mysten/sui/utils"),_u=require("@suilend/frontend-sui"),on=require("@suilend/sdk"),Lu=$t(require("bignumber.js")),sd=(a,e)=>{let t={[on.Side.DEPOSIT]:[],[on.Side.BORROW]:[]};return a.lendingMarket.reserves.forEach(n=>{[on.Side.DEPOSIT,on.Side.BORROW].forEach(o=>{let r=o===on.Side.DEPOSIT?n.depositsPoolRewardManager:n.borrowsPoolRewardManager,c=e.userRewardManagers.find(u=>u.poolRewardManagerId===r.id);c&&(t[o]=r.poolRewards.map((u,d)=>({reserveArrayIndex:n.arrayIndex,rewardIndex:BigInt(d),rewardCoinType:(0,Wu.normalizeStructTag)(u.coinType.name),side:o})).filter(u=>!(0,_u.isSendPoints)(u.rewardCoinType)&&!!c.rewards[Number(u.rewardIndex)]&&new Lu.default(c.rewards[Number(u.rewardIndex)].earnedRewards.value.toString()).gt(0)))})}),Object.values(t).flat()},sr=sd;var cr=class a extends Wt{constructor(t){super(t);this.data=t}txType;txSubType;async build(t){let{suiClient:n,account:o,suilendClient:r,obligationOwnerCap:c,obligation:u}=t;if(console.log("ClaimIntention.build",n,o,r,c,u),!c||!u)throw new Error("Obligation not found");let d=new ju.Transaction;return r.claimRewardsAndSendToUser(o.address,c.id,sr(r,u),d),d}static fromData(t){return console.log("ClaimIntention.fromData",t),new a(t)}};var Uu=require("@mysten/sui/transactions");var lr=class a extends Wt{constructor(t){super(t);this.data=t}txType;txSubType;async build(t){let{suiClient:n,account:o,suilendClient:r,obligationOwnerCap:c,obligation:u}=t;if(console.log("ClaimAndDepositIntention.build",n,o,r,c,u),!c||!u)throw new Error("Obligation not found");let d=new Uu.Transaction;return r.claimRewardsAndDeposit(o.address,c.id,sr(r,u),d),d}static fromData(t){return console.log("ClaimAndDepositIntention.fromData",t),new a(t)}};var qu=require("@mysten/sui/transactions");var ur=class a extends Wt{constructor(t){super(t);this.data=t}txType;txSubType;async build(t){let{suiClient:n,account:o,suilendClient:r,obligationOwnerCap:c,obligation:u}=t;console.log("DepositIntention.build",n,o,r,c,u);let d=new qu.Transaction;return await r.depositIntoObligation(o.address,this.data.coinType,this.data.value,d,c?.id),d}static fromData(t){return console.log("DepositIntention.fromData",t),new a(t)}};var Fu=require("@mysten/sui/transactions");var mr=class a extends Wt{constructor(t){super(t);this.data=t}txType;txSubType;async build(t){let{suiClient:n,account:o,suilendClient:r,obligationOwnerCap:c,obligation:u}=t;if(console.log("RepayIntention.build",n,o,r,c,u),!c||!u)throw new Error("Obligation not found");let d=new Fu.Transaction;return await r.repayIntoObligation(o.address,u.id,this.data.coinType,this.data.value,d),d}static fromData(t){return console.log("RepayIntention.fromData",t),new a(t)}};var Ku=require("@mysten/sui/transactions");var pr=class a extends Wt{constructor(t){super(t);this.data=t}txType;txSubType;async build(t){let{suiClient:n,account:o,suilendClient:r,obligationOwnerCap:c,obligation:u}=t;if(console.log("WithdrawIntention.build",n,o,r,c,u),!c||!u)throw new Error("Obligation not found");let d=new Ku.Transaction;return await r.withdrawAndSendToUser(o.address,c.id,u.id,this.data.coinType,this.data.value,d),d}static fromData(t){return console.log("WithdrawIntention.fromData",t),new a(t)}};var dr=async(a,e)=>{let t=await Ce.SuilendClient.initialize(Ce.LENDING_MARKET_ID,Ce.LENDING_MARKET_TYPE,a),n=await Ce.SuilendClient.getObligationOwnerCaps(e.address,t.lendingMarket.$typeArgs,a),o=await Promise.all(n.map(r=>Ce.SuilendClient.getObligation(r.obligationId,t.lendingMarket.$typeArgs,a)));return console.log("XXX getUtils - suilendClient:",t,"obligations:",o,"obligationOwnerCaps:",n),{suilendClient:t,obligationOwnerCaps:n,obligations:o}},fr=class{application="Suilend";supportSDK="@mysten/sui";utils;async deserialize(e){let{transaction:t,suiClient:n,account:o}=e;this.utils||(this.utils=await dr(n,o));let r=await n.devInspectTransactionBlock({sender:o.address,transactionBlock:t});console.log("SuilendAppHelper.deserialize - simResult:",r,"utils:",this.utils,"suiClient:",n);let u=new rr(t,r).decode();return{txType:Vu.TransactionType.Other,txSubType:u.type,intentionData:u.intentionData}}async build(e){let{network:t,txSubType:n,intentionData:o,suiClient:r,account:c}=e;this.utils||(this.utils=await dr(r,c));let u;switch(n){case"deposit":u=ur.fromData(o);break;case"withdraw":u=pr.fromData(o);break;case"borrow":u=ir.fromData(o);break;case"repay":u=mr.fromData(o);break;case"claim":u=cr.fromData(o);break;case"claimAndDeposit":u=lr.fromData(o);break;default:throw new Error("not implemented")}let d=window.localStorage.getItem("obligationId"),S=this.utils.obligations?.find(I=>I.id===d)??this.utils.obligations?.[0],w=this.utils.obligationOwnerCaps?.find(I=>I.obligationId===S?.id);return u.build({network:t,suiClient:r,account:c,suilendClient:this.utils.suilendClient,obligationOwnerCap:w,obligation:S})}};var Ss=async(a,e)=>{let t=await dr(a,e),n=await(0,$u.fetchRegistryLiquidStakingInfoMap)(a);return{...t,LIQUID_STAKING_INFO_MAP:n}};var hr=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,ke.normalizeStructTag)(e.MintEvent.parsedJson.event.typename.name),n=e.MintEvent.parsedJson.event.sui_amount_in;return console.log("Decoder.decodeStake",n),{txType:an.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,ke.normalizeStructTag)(e.MintEvent.parsedJson.event.typename.name),n=e.MintEvent.parsedJson.event.sui_amount_in;return console.log("Decoder.decodeStakeAndDeposit",n),{txType:an.TransactionType.Other,type:"stakeAndDeposit",intentionData:{amount:n,outCoinType:t}}}decodeConvert(){let e={RedeemEvent:this.simResult.events.find(r=>r.type.includes("liquid_staking::RedeemEvent")),MintEvent:this.simResult.events.find(r=>r.type.includes("liquid_staking::MintEvent"))},t=(0,ke.normalizeStructTag)(e.RedeemEvent.parsedJson.event.typename.name),n=(0,ke.normalizeStructTag)(e.MintEvent.parsedJson.event.typename.name),o=e.RedeemEvent.parsedJson.event.lst_amount_in;return console.log("Decoder.decodeConvert",o),{txType:an.TransactionType.Other,type:"convert",intentionData:{amount:o,inCoinType:t,outCoinType:n}}}decodeConvertAndDeposit(){let e={RedeemEvent:this.simResult.events.find(r=>r.type.includes("liquid_staking::RedeemEvent")),MintEvent:this.simResult.events.find(r=>r.type.includes("liquid_staking::MintEvent"))},t=(0,ke.normalizeStructTag)(e.RedeemEvent.parsedJson.event.typename.name),n=(0,ke.normalizeStructTag)(e.MintEvent.parsedJson.event.typename.name),o=e.RedeemEvent.parsedJson.event.lst_amount_in;return console.log("Decoder.decodeConvertAndDeposit",o),{txType:an.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,ke.normalizeStructTag)(e.RedeemEvent.parsedJson.event.typename.name),n=e.RedeemEvent.parsedJson.event.lst_amount_in;return console.log("Decoder.decodeUnstake",n),{txType:an.TransactionType.Other,type:"unstake",intentionData:{amount:n,inCoinType:t}}}};var Gu=require("@mysten/sui/transactions"),Nn=require("@suilend/springsui-sdk");var Hu=$t(require("sort-keys-recursive")),Vt=class{constructor(e){this.data=e}serialize(){return JSON.stringify((0,Hu.default)(this.data))}};var gr=class a extends Vt{constructor(t){super(t);this.data=t}txType;txSubType;async build(t){let{suiClient:n,account:o,suilendClient:r,LIQUID_STAKING_INFO_MAP:c,obligationOwnerCap:u,obligation:d}=t;console.log("ConvertIntention.build",n,o,r,c,u,d);let S=await Nn.LstClient.initialize(n,Object.values(c).find(C=>C.type===this.data.inCoinType)),w=await Nn.LstClient.initialize(n,Object.values(c).find(C=>C.type===this.data.outCoinType)),I=new Gu.Transaction;return(0,Nn.convertLstsAndSendToUser)(S,w,I,o.address,this.data.amount),I}static fromData(t){return console.log("ConvertIntention.fromData",t),new a(t)}};var Qu=require("@mysten/sui/transactions"),br=require("@suilend/sdk"),Wn=require("@suilend/springsui-sdk");var yr=class a extends Vt{constructor(t){super(t);this.data=t}txType;txSubType;async build(t){let{suiClient:n,account:o,suilendClient:r,LIQUID_STAKING_INFO_MAP:c,obligationOwnerCap:u,obligation:d}=t;console.log("ConvertAndDepositIntention.build",n,o,r,c,u,d);let S=await Wn.LstClient.initialize(n,Object.values(c).find(P=>P.type===this.data.inCoinType)),w=await Wn.LstClient.initialize(n,Object.values(c).find(P=>P.type===this.data.outCoinType)),I=new Qu.Transaction,{obligationOwnerCapId:C,didCreate:k}=(0,br.createObligationIfNoneExists)(r,I,u),x=(0,Wn.convertLsts)(S,w,I,o.address,this.data.amount);return r.deposit(x,this.data.outCoinType,C,I),k&&(0,br.sendObligationToUser)(C,o.address,I),I}static fromData(t){return console.log("ConvertAndDepositIntention.fromData",t),new a(t)}};var zu=require("@mysten/sui/transactions"),Ju=require("@suilend/springsui-sdk");var Sr=class a extends Vt{constructor(t){super(t);this.data=t}txType;txSubType;async build(t){let{suiClient:n,account:o,suilendClient:r,LIQUID_STAKING_INFO_MAP:c,obligationOwnerCap:u,obligation:d}=t;console.log("StakeIntention.build",n,o,r,c,u,d);let S=await Ju.LstClient.initialize(n,Object.values(c).find(I=>I.type===this.data.outCoinType)),w=new zu.Transaction;return S.mintAmountAndRebalanceAndSendToUser(w,o.address,this.data.amount),w}static fromData(t){return console.log("StakeIntention.fromData",t),new a(t)}};var Xu=require("@mysten/sui/transactions"),wr=require("@suilend/sdk"),Yu=require("@suilend/springsui-sdk");var Tr=class a extends Vt{constructor(t){super(t);this.data=t}txType;txSubType;async build(t){let{suiClient:n,account:o,suilendClient:r,LIQUID_STAKING_INFO_MAP:c,obligationOwnerCap:u,obligation:d}=t;console.log("StakeAndDepositIntention.build",n,o,r,c,u,d);let S=await Yu.LstClient.initialize(n,Object.values(c).find(x=>x.type===this.data.outCoinType)),w=new Xu.Transaction,{obligationOwnerCapId:I,didCreate:C}=(0,wr.createObligationIfNoneExists)(r,w,u),k=S.mintAmountAndRebalance(w,o.address,this.data.amount);return r.deposit(k,this.data.outCoinType,I,w),C&&(0,wr.sendObligationToUser)(I,o.address,w),w}static fromData(t){return console.log("StakeAndDepositIntention.fromData",t),new a(t)}};var Zu=require("@mysten/sui/transactions"),tm=require("@suilend/springsui-sdk");var Ir=class a extends Vt{constructor(t){super(t);this.data=t}txType;txSubType;async build(t){let{suiClient:n,account:o,suilendClient:r,LIQUID_STAKING_INFO_MAP:c,obligationOwnerCap:u,obligation:d}=t;console.log("UnstakeIntention.build",n,o,r,c,u,d);let S=await tm.LstClient.initialize(n,Object.values(c).find(I=>I.type===this.data.inCoinType)),w=new Zu.Transaction;return S.redeemAmountAndSendToUser(w,o.address,this.data.amount),w}static fromData(t){return console.log("UnstakeIntention.fromData",t),new a(t)}};var Cr=class{application="SpringSui";supportSDK="@mysten/sui";utils;async deserialize(e){let{transaction:t,suiClient:n,account:o}=e;this.utils||(this.utils=await Ss(n,o));let r=await n.devInspectTransactionBlock({sender:o.address,transactionBlock:t});console.log("SpringSuiAppHelper.deserialize",r);let u=new hr(t,r).decode();return{txType:em.TransactionType.Other,txSubType:u.type,intentionData:u.intentionData}}async build(e){let{network:t,txSubType:n,intentionData:o,suiClient:r,account:c}=e;this.utils||(this.utils=await Ss(r,c));let u;switch(n){case"stake":u=Sr.fromData(o);break;case"stakeAndDeposit":u=Tr.fromData(o);break;case"convert":u=gr.fromData(o);break;case"convertAndDeposit":u=yr.fromData(o);break;case"unstake":u=Ir.fromData(o);break;default:throw new Error("not implemented")}return u.build({network:t,suiClient:r,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 am=require("@msafe/sui3-utils");var Ts=require("@msafe/sui3-utils");var kr=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:Ts.TransactionType.Other,type:"mint",intentionData:{amount:t}}}decodeRedeem(e){let{event:{lst_amount_in:t}}=e;return console.log("Decoder.decodeRedeem",t),{txType:Ts.TransactionType.Other,type:"redeem",intentionData:{amount:t}}}};var nm=require("@alphafi/stsui-sdk");var vr=class a extends v{constructor(t){super(t);this.data=t}txType;txSubType;async build(t){let{account:n}=t,{amount:o}=this.data,r={lstInfo:"0x1adb343ab351458e151bc392fbf1558b3332467f23bda45ae67cd355a57fd5f5",lstCointype:"0xd1b72982e40348d069bb1ff701e634c117bb5f741f44dff91e472d3b01461e55::stsui::STSUI"},u=await new nm.LST(r).mint(o,n.address);return u.setGasBudget(1e8),u}static fromData(t){return console.log("MintIntention.fromData",t),new a(t)}};var om=require("@alphafi/stsui-sdk");var xr=class a extends v{constructor(t){super(t);this.data=t}txType;txSubType;async build(t){let{account:n}=t,{amount:o}=this.data,r={lstInfo:"0x1adb343ab351458e151bc392fbf1558b3332467f23bda45ae67cd355a57fd5f5",lstCointype:"0xd1b72982e40348d069bb1ff701e634c117bb5f741f44dff91e472d3b01461e55::stsui::STSUI"},u=await new om.LST(r).redeem(o,n.address);return u.setGasBudget(1e8),u}static fromData(t){return console.log("RedeemIntention.fromData",t),new a(t)}};var Dr=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 kr(t,o).decode();return{txType:am.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=vr.fromData(e.intentionData);break;case"redeem":n=xr.fromData(e.intentionData);break;default:throw new Error("build not implemented")}return n.build({account:t})}};var xm=require("@msafe/sui3-utils"),Dm=require("turbos-clmm-sdk");var Lt=require("@msafe/sui3-utils"),ws=require("@mysten/sui.js/bcs"),xe=require("@mysten/sui.js/utils"),rm=require("turbos-clmm-sdk");var Gt={PackageId:"0x02fe4933f4521250e55a15441096d1d4a38a7311195b0bca126fc0138c1f5a97",Claim:"0x0c822cec42f7ca703696b4232f1c47b348330c23580172a29aab465bc071d894",turbosCoinType:"0x5d1f47ea69bb0de31c313d7acf89b890dbb8991ea8e03c6c355171f84bb1ba4a::turbos::TURBOS"},Qt={PackageId:"0xdee9"};var md=(a,e,t,n)=>{if(a===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(r=>r===e)){case 0:return[!0];case 1:return[!1];default:throw new Error(`not target: ${e}`)}},Ar=class{constructor(e,t,n){this.txb=e;this.turbosSdk=t;this.config=n}get transactions(){return this.txb.blockData.transactions}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.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.target===e)}getMoveCallsTransaction(e){return e.every(t=>this.transactions.find(n=>n.kind==="MoveCall"&&n.target===t))}getSwapMoveCallTransaction(e){return this.transactions.find(t=>t.kind==="MoveCall"&&e.includes(t.target))}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`)}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(`${Gt.PackageId}::claim::join`)}isPrixClaimTransaction(){return!!this.getMoveCallTransaction(`${Gt.PackageId}::claim::claim`)}isRemoveLiquidityTransaction(){return!!this.getMoveCallsTransaction([`${this.config.PackageId}::position_manager::decrease_liquidity`,`${this.config.PackageId}::position_manager::burn`])}isSwapExactBaseForQuoteTransaction(){return!!this.getMoveCallTransaction(`${Qt.PackageId}::clob_v2::swap_exact_base_for_quote`)}isSwapExactQuoteForBaseTransaction(){return!!this.getMoveCallTransaction(`${Qt.PackageId}::clob_v2::swap_exact_quote_for_base`)}async decodeSwap(){let e=this.transactions.find(k=>k.kind==="MoveCall"),t=0;this.swap2Layer.includes(e.target)&&(t=1);let n=md(t,e.target,this.swap1Layer,this.swap2Layer),o=n.map((k,x)=>{let P=this.helper.decodeSharedObjectId(x),L=this.helper.decodeInputU128(4+x+t),V=this.turbosSdk.math.sqrtPriceX64ToTickIndex(new rm.BN(L.toString()));return{pool:P,a2b:k,nextTickIndex:V}}),r=n[0]||t===1?e.typeArguments[0]:e.typeArguments[1],c=t===1?e.typeArguments[4]:n[0]?e.typeArguments[1]:e.typeArguments[0],u=this.helper.decodeInputAddress(6+2*t),d=this.helper.decodeInputU64(7+2*t),S=this.helper.decodeInputBool(5+2*t),w=this.helper.decodeInputU64(2+t),I=this.helper.decodeInputU64(3+t),C=await this.turbosSdk.trade.computeSwapResultV2({pools:[{pool:o[0].pool,a2b:o[0].a2b,amountSpecified:w}],address:u,amountSpecifiedIsInput:S});return{txType:Lt.TransactionType.Other,type:"Swap",intentionData:{routes:o,coinTypeA:r,coinTypeB:c,address:u,amountA:S?w:I,amountB:S?I:w,amountSpecifiedIsInput:S,slippage:"0.1",deadline:d}}}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),r=this.helper.decodeInputU32(4),c=this.helper.decodeInputBool(5),u=this.helper.decodeInputU32(6),d=this.helper.decodeInputBool(7),S=this.helper.decodeInputU64(13);return{txType:Lt.TransactionType.Other,type:"AddLiquidity",intentionData:{pool:e,slippage:10,address:t,amountA:n,amountB:o,tickLower:c?-r:r,tickUpper:d?-u:u,deadline:S}}}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),r=this.helper.decodeInputU64(6),c=this.helper.decodeInputU64(9);return{txType:Lt.TransactionType.Other,type:"IncreaseLiquidity",intentionData:{pool:t,slippage:10,address:e,amountA:o,amountB:r,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),r=this.helper.decodeInputU64(4),c=this.helper.decodeInputU64(5),u=this.helper.decodeInputU64(6);return{txType:Lt.TransactionType.Other,type:"DecreaseLiquidity",intentionData:{pool:t,decreaseLiquidity:o,nft:n,amountA:r,amountB:c,slippage:10,address:e,deadline:u}}}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),r=this.helper.decodeInputU64(4),c=this.helper.decodeInputU64(6);return{txType:Lt.TransactionType.Other,type:"CollectFee",intentionData:{pool:e,address:n,collectAmountA:o,collectAmountB:r,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)),r=this.helper.decodeInputU64(7);return{txType:Lt.TransactionType.Other,type:"CollectReward",intentionData:{pool:e,address:n,rewardAmounts:o,nft:t,deadline:r}}}decodeBurn(){console.log(this.helper,"decodeBurn this.helper");let e=this.helper.decodeSharedObjectId(0),t=this.helper.decodeSharedObjectId(2);return{txType:Lt.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),r=this.decreaseLiquidityHelper.decodeInputU64(4),c=this.decreaseLiquidityHelper.decodeInputU64(5),u=this.decreaseLiquidityHelper.decodeInputU64(6),d=this.collectRewardHelper.map(I=>I.decodeInputU64(5)),S=this.collectFeeHelper.decodeInputU64(3)||0,w=this.collectFeeHelper.decodeInputU64(4)||0;return{txType:Lt.TransactionType.Other,type:"RemoveLiquidity",intentionData:{pool:t,decreaseLiquidity:o,nft:n,amountA:r,amountB:c,slippage:10,address:e,collectAmountA:S,collectAmountB:w,rewardAmounts:d,deadline:u}}}decodePrixClaim(){return{txType:Lt.TransactionType.Other,type:"PrixClaim",intentionData:{}}}decodePrixJoin(){return{txType:Lt.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:Lt.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:Lt.TransactionType.Other,type:"SwapExactQuoteForBase",intentionData:{poolId:e,amountIn:t,token1:n,token2:o}}}get helper(){let e=this.transactions.find(t=>t.kind==="MoveCall"&&t.target!=="0x2::coin::zero"&&t.target!=="0x0000000000000000000000000000000000000000000000000000000000000002::coin::zero");return new ve(e,this.txb)}get collectRewardHelper(){return this.transactions.filter(t=>t.kind==="MoveCall"&&t.target===`${this.config.PackageId}::position_manager::collect_reward`).map(t=>new ve(t,this.txb))}get collectFeeHelper(){let e=this.transactions.find(t=>t.kind==="MoveCall"&&t.target===`${this.config.PackageId}::position_manager::collect`);return new ve(e,this.txb)}get decreaseLiquidityHelper(){let e=this.transactions.find(t=>t.kind==="MoveCall"&&t.target===`${this.config.PackageId}::position_manager::decrease_liquidity`);return new ve(e,this.txb)}get swapExactBaseForQuoteHelper(){let e=this.transactions.find(t=>t.kind==="MoveCall"&&t.target===`${Qt.PackageId}::clob_v2::swap_exact_base_for_quote`);return new ve(e,this.txb)}get swapExactQuoteForBaseHelper(){let e=this.transactions.find(t=>t.kind==="MoveCall"&&t.target===`${Qt.PackageId}::clob_v2::swap_exact_quote_for_base`);return new ve(e,this.txb)}},ve=class a{constructor(e,t){this.moveCall=e;this.txb=t}decodeSharedObjectId(e){let t=this.getInputParam(e);return a.getSharedObjectId(t)}decodeOwnedObjectId(e){let t=this.getInputParam(e);return a.getOwnedObjectId(t)}decodeInputU128(e){let t=this.decodePureArg(e,"u128");return Number(t)}decodeInputU64(e){let t=this.decodePureArg(e,"u64");return Number(t)}decodeInputU32(e){let t=this.decodePureArg(e,"u32");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 a.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 ws.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 ws.bcs.de(t,new Uint8Array(n))}typeArg(e){return(0,xe.normalizeStructTag)(this.moveCall.typeArguments[e])}shortTypeArg(e){return this.moveCall.typeArguments[e]}txArg(e){return this.moveCall.arguments[e]}};var im=require("turbos-clmm-sdk");var Or=class a extends B{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:r,amountA:c,amountB:u,slippage:d,tickLower:S,tickUpper:w,deadline:I,txb:C}=this.data;return n.pool.addLiquidity({pool:o,slippage:d,address:r,amountA:c,amountB:u,tickLower:S,tickUpper:w,deadline:I,txb:C})}static fromData(t){return new a(t)}};var sm=require("turbos-clmm-sdk");var Mr=class a extends B{constructor(t){super(t);this.data=t}txType;txSubType;async build(t){let n=new sm.TurbosSdk(t.network.replace("sui:",""),t.suiClient),{pool:o,nft:r,txb:c}=this.data;return n.nft.burn({pool:o,nft:r,txb:c})}static fromData(t){return new a(t)}};var cm=require("turbos-clmm-sdk");var Pr=class a extends B{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,address:r,nft:c,collectAmountA:u,collectAmountB:d,deadline:S,txb:w}=this.data;return n.pool.collectFee({pool:o,address:r,collectAmountA:u,collectAmountB:d,nft:c,deadline:S,txb:w})}static fromData(t){return new a(t)}};var lm=require("turbos-clmm-sdk");var Br=class a extends B{constructor(t){super(t);this.data=t}txType;txSubType;async build(t){let n=new lm.TurbosSdk(t.network.replace("sui:",""),t.suiClient),{pool:o,address:r,nft:c,rewardAmounts:u,deadline:d,txb:S}=this.data;return n.pool.collectReward({pool:o,address:r,rewardAmounts:u,nft:c,deadline:d,txb:S})}static fromData(t){return new a(t)}};var um=require("turbos-clmm-sdk");var Rr=class a extends B{constructor(t){super(t);this.data=t}txType;txSubType;async build(t){let n=new um.TurbosSdk(t.network.replace("sui:",""),t.suiClient),{fee:o,address:r,tickLower:c,tickUpper:u,sqrtPrice:d,slippage:S,coinTypeA:w,coinTypeB:I,amountA:C,amountB:k,deadline:x,txb:P}=this.data;return n.pool.createPool({fee:o,amountA:C,amountB:k,address:r,tickLower:c,tickUpper:u,sqrtPrice:d,slippage:S,coinTypeA:w,coinTypeB:I,deadline:x,txb:P})}static fromData(t){return new a(t)}};var mm=require("turbos-clmm-sdk");var Er=class a extends B{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:r,amountA:c,amountB:u,slippage:d,nft:S,decreaseLiquidity:w,deadline:I,txb:C}=this.data;return n.pool.decreaseLiquidity({pool:o,slippage:d,address:r,amountA:c,amountB:u,nft:S,decreaseLiquidity:w,deadline:I,txb:C})}static fromData(t){return new a(t)}};var pm=require("turbos-clmm-sdk");var Nr=class a extends B{constructor(t){super(t);this.data=t}txType;txSubType;async build(t){let n=new pm.TurbosSdk(t.network.replace("sui:",""),t.suiClient),{pool:o,address:r,amountA:c,amountB:u,slippage:d,nft:S,deadline:w,txb:I}=this.data;return n.pool.increaseLiquidity({pool:o,slippage:d,address:r,amountA:c,amountB:u,nft:S,deadline:w,txb:I})}static fromData(t){return new a(t)}};var dm=require("@mysten/sui.js/transactions"),fm=require("@mysten/sui.js/utils");var Wr=class a extends B{constructor(t){super(t);this.data=t}txType;txSubType;async build(t){let n=new dm.TransactionBlock;return n.moveCall({target:`${Gt.PackageId}::claim::claim`,typeArguments:[Gt.turbosCoinType],arguments:[n.object(Gt.Claim),n.object(fm.SUI_CLOCK_OBJECT_ID)]}),n}static fromData(t){return new a(t)}};var hm=require("@mysten/sui.js/transactions");var _r=class a extends B{constructor(t){super(t);this.data=t}txType;txSubType;async build(t){let n=new hm.TransactionBlock;return n.moveCall({target:`${Gt.PackageId}::claim::join`,typeArguments:[Gt.turbosCoinType],arguments:[n.object(Gt.Claim)]}),n}static fromData(t){return new a(t)}};var gm=require("@mysten/sui.js/transactions"),ym=require("turbos-clmm-sdk");var Lr=class a extends B{constructor(t){super(t);this.data=t}txType;txSubType;async build(t){let n=new ym.TurbosSdk(t.network.replace("sui:",""),t.suiClient),o=new gm.TransactionBlock;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.nft.burn({txb:o,nft:this.data.nft,pool:this.data.pool}),o}static fromData(t){return new a(t)}};var bm=require("turbos-clmm-sdk");var jr=class a extends B{constructor(t){super(t);this.data=t}txType;txSubType;async build(t){console.log(this.data,"this.data");let n=new bm.TurbosSdk(t.network.replace("sui:",""),t.suiClient),{routes:o,coinTypeA:r,coinTypeB:c,address:u,amountA:d,amountB:S,slippage:w,amountSpecifiedIsInput:I,deadline:C,txb:k}=this.data;return n.trade.swap({routes:o,coinTypeA:r,coinTypeB:c,address:u,amountA:d,amountB:S,amountSpecifiedIsInput:I,slippage:w,deadline:C,txb:k})}static fromData(t){return new a(t)}};var km=require("turbos-clmm-sdk");var Is=require("@mysten/sui.js/transactions"),Cs=require("@mysten/sui.js/utils");var Sm=require("turbos-clmm-sdk");var _n=class{constructor(e){this.turbosSdk=e}async getCoinsData(e,t,n){let o=[],r;do r=await this.turbosSdk.provider.getCoins({owner:e,coinType:t,cursor:r?.nextCursor}),o.push(...r.data);while(r.hasNextPage);let c=[],u=0;return o.sort((d,S)=>Number(S.balance)-Number(d.balance)).some(d=>u>=n?!0:(u+=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(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[r]=n.splitCoins(o,[n.pure(t)]);return[r,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:`${Qt.PackageId}::custodian_v2::AccountCap`}});return t.data[0]?.data?(0,Sm.unstable_getObjectId)(t.data[0].data):void 0}createAccount(e){let[t]=e.moveCall({typeArguments:[],target:`${Qt.PackageId}::clob_v2::create_account`,arguments:[]});return t}zero(e,t){return t.moveCall({typeArguments:[e],target:"0x2::coin::zero",arguments:[]})}};var Tm=89,wm=1e6,Im=async a=>{let{token1:e,token2:t,poolId:n,amountIn:o,currentAddress:r,turbosSdk:c}=a,u=new Is.TransactionBlock,d=new _n(c),S=await d.getCoinsData(r,t,o),[w,I]=d.splitAndMergeCoin(S,o,u);if(!w)throw new Error(`Not enough balance: ${t}`);let C=await d.IsAccountCap(r),k=C?u.object(C):d.createAccount(u),[x,P,L]=u.moveCall({typeArguments:[e,t],target:`${Qt.PackageId}::clob_v2::swap_exact_quote_for_base`,arguments:[u.object(String(n)),u.pure(Tm),k,u.pure(o),u.object((0,Cs.normalizeSuiObjectId)("0x6")),w]});return I&&u.transferObjects([I],u.pure(r)),u.transferObjects([x],u.pure(r)),u.transferObjects([P],u.pure(r)),C||u.transferObjects([k],u.pure(r)),u.setSenderIfNotSet(r),u.setGasBudget(wm),u},Cm=async a=>{let{token1:e,token2:t,poolId:n,amountIn:o,currentAddress:r,turbosSdk:c}=a,u=new Is.TransactionBlock,d=new _n(c),S=await d.getCoinsData(r,e,o),[w,I]=d.splitAndMergeCoin(S,o,u);if(!w)throw new Error(`Not enough balance: ${e}`);let C=await d.IsAccountCap(r),k=C?u.object(C):d.createAccount(u),x=d.zero(t,u),[P,L,V]=u.moveCall({typeArguments:[e,t],target:`${Qt.PackageId}::clob_v2::swap_exact_base_for_quote`,arguments:[u.object(String(n)),u.pure(Tm),k,u.pure(o),w,x,u.object((0,Cs.normalizeSuiObjectId)("0x6"))]});return I&&u.transferObjects([I],u.pure(r)),u.transferObjects([P],u.pure(r)),u.transferObjects([L],u.pure(r)),C||u.transferObjects([k],u.pure(r)),u.setSenderIfNotSet(r),u.setGasBudget(wm),u};var Ur=class a extends B{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 Cm({...this.data,turbosSdk:n,currentAddress:t.account.address})}static fromData(t){return new a(t)}};var vm=require("turbos-clmm-sdk");var qr=class a extends B{constructor(t){super(t);this.data=t}txType;txSubType;async build(t){let n=new vm.TurbosSdk(t.network.replace("sui:",""),t.suiClient);return await Im({...this.data,turbosSdk:n,currentAddress:t.account.address})}static fromData(t){return new a(t)}};var Fr=class{application="turbos";supportSDK="@mysten/sui.js";async deserialize(e){let t=new Dm.TurbosSdk(e.network.replace("sui:",""),e.suiClient),n=await t.contract.getConfig(),{transactionBlock:o,account:r}=e;console.log(e,"input");let u=await new Ar(o,t,n).decode(r.address);return{txType:xm.TransactionType.Other,txSubType:u.type,intentionData:u.intentionData}}async build(e){let{suiClient:t,account:n,network:o}=e,r;switch(console.log(e.intentionData,"intentionData"),e.txSubType){case"CreatePool":r=Rr.fromData(e.intentionData);break;case"AddLiquidity":r=Or.fromData(e.intentionData);break;case"IncreaseLiquidity":r=Nr.fromData(e.intentionData);break;case"DecreaseLiquidity":r=Er.fromData(e.intentionData);break;case"RemoveLiquidity":r=Lr.fromData(e.intentionData);break;case"CollectFee":r=Pr.fromData(e.intentionData);break;case"CollectReward":r=Br.fromData(e.intentionData);break;case"Burn":r=Mr.fromData(e.intentionData);break;case"Swap":r=jr.fromData(e.intentionData);break;case"PrixJoin":r=_r.fromData(e.intentionData);break;case"PrixClaim":r=Wr.fromData(e.intentionData);break;case"SwapExactBaseForQuote":r=Ur.fromData(e.intentionData);break;case"SwapExactQuoteForBase":r=qr.fromData(e.intentionData);break;default:throw new Error("not implemented")}return r.build({suiClient:t,account:n,network:o})}};var Pm=require("@msafe/sui3-utils");var Kr=require("@msafe/sui3-utils"),ks=require("@mysten/sui.js/bcs"),De=require("@mysten/sui.js/utils");var pd={packageId:"0x549e8b69270defbfafd4f94e17ec44cdbdd99820b33bda2278dea3b9a32d3f55",poolObjectId:"0x7fa2faa111b8c65bea48a23049bfd81ca8f971a262d981dcd9a17c3825cb5baf",metadataObjectId:"0x680cd26af32b2bde8d3361e804c53ec1d1cfe24c7f039eb7f549e8dfde389a60",systemStateObjectId:"0x0000000000000000000000000000000000000000000000000000000000000005",certType:"0x549e8b69270defbfafd4f94e17ec44cdbdd99820b33bda2278dea3b9a32d3f55::cert::CERT",gasBudget:5e7},Dt=pd;var Vr=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:Kr.TransactionType.Other,type:"Stake",intentionData:{amount:e}}}decodeUnStake(){let t=this.transactions.find(n=>n.kind==="SplitCoins").amounts[0].value.toNumber();return{txType:Kr.TransactionType.Other,type:"UnStake",intentionData:{amount:t}}}decodeClaimTicket(){let e=this.helper.decodeOwnedObjectId(2);return console.log(e),{txType:Kr.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 vs(e,this.txb)}},vs=class a{constructor(e,t){this.moveCall=e;this.txb=t}decodeSharedObjectId(e){let t=this.getInputParam(e);return a.getSharedObjectId(t)}decodeOwnedObjectId(e){let t=this.getInputParam(e);return a.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,De.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 a.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 ks.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,De.normalizeSuiAddress)(e.value.Object.ImmOrOwned.objectId)}return(0,De.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,De.normalizeSuiAddress)(e.value);if(!("Object"in e.value)||!("Shared"in e.value.Object))throw new Error("not Shared");return(0,De.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 ks.bcs.de(t,new Uint8Array(n))}typeArg(e){return(0,De.normalizeStructTag)(this.moveCall.typeArguments[e])}txArg(e){return this.moveCall.arguments[e]}};var Am=require("@mysten/sui.js/transactions");var $r=class a extends B{constructor(t){super(t);this.data=t}txType;txSubType;async build(t){console.log(t);let n=new Am.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 a(t)}};var Om=require("@mysten/sui.js/transactions");var Hr=class a extends B{constructor(t){super(t);this.data=t}txType;txSubType;async build(t){console.log(t);let n=new Om.TransactionBlock,{amount:o}=this.data,[r]=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),r]}),n}static fromData(t){return new a(t)}};var Mm=require("@mysten/sui.js/transactions");var Gr=class a extends B{constructor(t){super(t);this.data=t}txType;txSubType;async build(t){console.log(t);let n=new Mm.TransactionBlock,{amount:o}=this.data,r=(await t.suiClient.getAllCoins({owner:t.account.address,limit:100})).data,[c,...u]=r.filter(w=>w.coinType.split("::")[0]===Dt.certType.split("::")[0]),d=n.object(c.coinObjectId);u.length&&n.mergeCoins(d,u.map(w=>n.object(w.coinObjectId)));let S=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),S]}),n}static fromData(t){return new a(t)}};var Qr=class{application="volo";supportSDK="@mysten/sui.js";async deserialize(e){let{transactionBlock:t}=e,o=new Vr(t).decode();return{txType:Pm.TransactionType.Other,txSubType:o.type,intentionData:o.intentionData}}async build(e){let{suiClient:t,account:n}=e,o;switch(e.txSubType){case"Stake":o=Hr.fromData(e.intentionData);break;case"UnStake":o=Gr.fromData(e.intentionData);break;case"ClaimTicket":o=$r.fromData(e.intentionData);break;default:throw new Error("not implemented")}return o.build({suiClient:t,account:n})}};var Fm=require("@msafe/sui3-utils");var xs=require("@cetusprotocol/common-sdk"),Ae=require("@msafe/sui3-utils"),rn=require("@mysten/bcs"),sn=require("@mysten/sui/bcs");var zr=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:Ae.TransactionType.Other,type:"OpenPosition",intentionData:{pool:this.getSharedObjectID(this.getInputIndex(e,1)),lowerTick:Number((0,xs.asIntN)(BigInt(this.getU32(this.getInputIndex(e,2)))).toString()),upperTick:Number((0,xs.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:Ae.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:Ae.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:Ae.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:Ae.TransactionType.Other,type:"CollectRewards",intentionData:{pool:e[0].pool,position:e[0].position,collectRewardTokens:e.map(t=>t.rewardCoinType)}}}decodeCollectFeeTx(){return{txType:Ae.TransactionType.Other,type:"CollectFee",intentionData:this.getFeeCallData()}}decodeCollectRewardsAndFeeTx(){let e=this.getFeeCallData();return{txType:Ae.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(sn.bcs.u32().parse(Uint8Array.from((0,rn.fromBase64)(this.inputs[e].Pure.bytes))))}getU64(e){return sn.bcs.u64().parse(Uint8Array.from((0,rn.fromBase64)(this.inputs[e].Pure.bytes)))}getU128(e){return sn.bcs.u128().parse(Uint8Array.from((0,rn.fromBase64)(this.inputs[e].Pure.bytes)))}getBoolean(e){return sn.bcs.bool().parse(Uint8Array.from((0,rn.fromBase64)(this.inputs[e].Pure.bytes)))}getAddress(e){return sn.bcs.Address.parse(Uint8Array.from((0,rn.fromBase64)(this.inputs[e].Pure.bytes)))}getTypeArguments(e){return e.MoveCall.typeArguments||[]}getInputIndex(e,t){return e.MoveCall.arguments[t].Input}};var Nm=require("@msafe/sui3-utils");var ne=require("@firefly-exchange/library-sui");var Rm=require("@firefly-exchange/library-sui"),Em=require("@firefly-exchange/library-sui/dist/src/spot"),Bm={rpc:"https://fullnode.mainnet.sui.io/",objects:{GlobalConfig:"0x03db251ba509a8d5d8777b6338836082335d93eecbdd09a11e190a1cff51c352",BasePackage:"0x3492c874c1e3b3e2984e8c41b589e642d4d0a5d6459e5a9cfc2d52fd7c89c267",CurrentPackage:"0x6c796c3ab3421a68158e0df18e4657b2827b1f8fed5ed4b82dba9c935988711b"}},Me=(a,e)=>{if(a!=="sui:mainnet")throw new Error("Bluefin spot protocol is only available on sui::mainnet");let t=new Rm.SuiClient({url:Bm.rpc});return new Em.OnChainCalls(t,Bm.objects,{address:e.address,isUIWallet:!1})};var Pt=class{static async OpenPosition(e,t,n){let o=Me(n,t),r=await o.queryChain.getPool(e.pool),c=this.prototype.buildLiqInput(r,{...e,slippage:0});return await o.openPositionWithFixedAmount(r,e.lowerTick,e.upperTick,c,{returnTx:!0,sender:t.address})}static async provideLiquidity(e,t,n){let o=Me(n,t),r=await o.queryChain.getPool(e.pool),c=this.prototype.buildLiqInput(r,e);return await o.provideLiquidityWithFixedAmount(r,e.position,c,{returnTx:!0,sender:t.address})}static async removeLiquidity(e,t,n){let o=Me(n,t),r=await o.queryChain.getPool(e.pool);return await o.removeLiquidity(r,e.position,{liquidityAmount:new ne.BN(e.liquidity),tokenMaxA:new ne.BN(e.maxAmountTokenA),tokenMaxB:new ne.BN(e.maxAmountTokenB)},{returnTx:!0,sender:t.address})}static async closePosition(e,t,n){let o=Me(n,t),r=await o.queryChain.getPool(e.pool);return await o.closePosition(r,e.position,{returnTx:!0,sender:t.address})}static async collectRewards(e,t,n){let o=Me(n,t),r=await o.queryChain.getPool(e.pool);return await o.collectRewards(r,e.position,{rewardCoinsType:e.collectRewardTokens,returnTx:!0,sender:t.address})}static async collectFee(e,t,n){let o=Me(n,t),r=await o.queryChain.getPool(e.pool);return await o.collectFee(r,e.position,{returnTx:!0,sender:t.address})}static async collectRewardsAndFee(e,t,n){let o=Me(n,t),r=await o.queryChain.getPool(e.pool);return console.log(e.position),await o.collectFeeAndRewards(r,e.position,{returnTx:!0,sender:t.address})}buildLiqInput(e,t){return{...ne.ClmmPoolUtil.estLiquidityAndCoinAmountFromOneAmounts(t.lowerTick,t.upperTick,new ne.BN(t.tokenAmount),t.isTokenAFixed,!0,0,new ne.BN(e.current_sqrt_price)),tokenMaxA:new ne.BN(t.maxAmountTokenA),tokenMaxB:new ne.BN(t.maxAmountTokenB)}}};var Jr=class a extends v{constructor(t){super(t);this.data=t}txType=Nm.TransactionType.Other;txSubType="ClosePosition";async build(t){let{account:n,network:o}=t;return console.log(this.data),Pt.closePosition(this.data,n,o)}static fromData(t){return new a(t)}};var Wm=require("@msafe/sui3-utils");var Xr=class a extends v{constructor(t){super(t);this.data=t}txType=Wm.TransactionType.Other;txSubType="CollectFee";async build(t){let{account:n,network:o}=t;return console.log(this.data),Pt.collectFee(this.data,n,o)}static fromData(t){return new a(t)}};var _m=require("@msafe/sui3-utils");var Yr=class a extends v{constructor(t){super(t);this.data=t}txType=_m.TransactionType.Other;txSubType="CollectRewards";async build(t){let{account:n,network:o}=t;return console.log(this.data),Pt.collectRewards(this.data,n,o)}static fromData(t){return new a(t)}};var Lm=require("@msafe/sui3-utils");var Zr=class a extends v{constructor(t){super(t);this.data=t}txType=Lm.TransactionType.Other;txSubType="CollectRewardsAndFee";async build(t){let{account:n,network:o}=t;return console.log(this.data),Pt.collectRewardsAndFee(this.data,n,o)}static fromData(t){return new a(t)}};var jm=require("@msafe/sui3-utils");var ti=class a extends v{constructor(t){super(t);this.data=t}txType=jm.TransactionType.Other;txSubType="OpenPosition";async build(t){let{account:n,network:o}=t;return console.log(this.data),Pt.OpenPosition(this.data,n,o)}static fromData(t){return new a(t)}};var Um=require("@msafe/sui3-utils");var ei=class a extends v{constructor(t){super(t);this.data=t}txType=Um.TransactionType.Other;txSubType="ProvideLiquidity";async build(t){let{account:n,network:o}=t;return console.log(this.data),Pt.provideLiquidity(this.data,n,o)}static fromData(t){return new a(t)}};var qm=require("@msafe/sui3-utils");var ni=class a extends v{constructor(t){super(t);this.data=t}txType=qm.TransactionType.Other;txSubType="RemoveLiquidity";async build(t){let{account:n,network:o}=t;return console.log(this.data),Pt.removeLiquidity(this.data,n,o)}static fromData(t){return new a(t)}};var oi=class{application="bluefin";supportSDK="@mysten/sui";async deserialize(e){console.log("Bluefin helper deserialize input: ",e);let{transaction:t}=e,o=new zr(t).decode();return{txType:Fm.TransactionType.Other,txSubType:o.type,intentionData:o.intentionData}}async build(e){let{suiClient:t,account:n,network:o}=e;console.log(e.txSubType);let r;switch(e.txSubType){case"OpenPosition":r=ti.fromData(e.intentionData);break;case"ProvideLiquidity":r=ei.fromData(e.intentionData);break;case"RemoveLiquidity":r=ni.fromData(e.intentionData);break;case"ClosePosition":r=Jr.fromData(e.intentionData);break;case"CollectFee":r=Xr.fromData(e.intentionData);break;case"CollectRewards":r=Yr.fromData(e.intentionData);break;case"CollectRewardsAndFee":r=Zr.fromData(e.intentionData);break;default:throw new Error("not implemented")}return r.build({suiClient:t,account:n,network:o})}};var cp=require("@msafe/sui3-utils");var Gm=require("@mmt-finance/clmm-sdk"),Qm=require("@mysten/sui/transactions");var ie=require("@mmt-finance/clmm-sdk/dist/utils/math/tickMath"),R=$t(Vm());var fd="0x0000000000000000000000000000000000000000000000000000000000000002::sui::SUI",zt=a=>a!=="0x2::sui::SUI"?a:"0x0000000000000000000000000000000000000000000000000000000000000002::sui::SUI",hd=async({suiClient:a,address:e,type:t})=>{let n,o=[],r=0;do{try{let c=await a.getCoins({owner:e,coinType:t,cursor:n,limit:50});o=o.concat(c.data),n=c.nextCursor,(!c.hasNextPage||r===8)&&(n=null)}catch(c){console.log(c),n=null}r++}while(n!==null);return o},gd=(a,e)=>{let t=[],n=BigInt(0);for(let o of e)n<a&&!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>=a)return t;throw new Error("Insufficient balance")},yd=(a,e,t,n)=>{if(a===fd){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[r]=n.splitCoins(n.object(o[0]),[n.pure.u64(t)]);return r}};async function cn(a,e,t,n,o){let r=await hd({suiClient:a.rpcClient,address:e,type:t});return yd(zt(t),r.map(u=>({balance:BigInt(u.balance),objectId:u.coinObjectId})),n,o)}function N(a,e,t){let n=a.toTwos(t).shrn(e);return n.imaskn(t-e+1),n.fromTwos(t-e)}function bd(a){let e;return a&1?e=new R.default("79232123823359799118286999567"):e=new R.default("79228162514264337593543950336"),a&2&&(e=N(e.mul(new R.default("79236085330515764027303304731")),96,256)),a&4&&(e=N(e.mul(new R.default("79244008939048815603706035061")),96,256)),a&8&&(e=N(e.mul(new R.default("79259858533276714757314932305")),96,256)),a&16&&(e=N(e.mul(new R.default("79291567232598584799939703904")),96,256)),a&32&&(e=N(e.mul(new R.default("79355022692464371645785046466")),96,256)),a&64&&(e=N(e.mul(new R.default("79482085999252804386437311141")),96,256)),a&128&&(e=N(e.mul(new R.default("79736823300114093921829183326")),96,256)),a&256&&(e=N(e.mul(new R.default("80248749790819932309965073892")),96,256)),a&512&&(e=N(e.mul(new R.default("81282483887344747381513967011")),96,256)),a&1024&&(e=N(e.mul(new R.default("83390072131320151908154831281")),96,256)),a&2048&&(e=N(e.mul(new R.default("87770609709833776024991924138")),96,256)),a&4096&&(e=N(e.mul(new R.default("97234110755111693312479820773")),96,256)),a&8192&&(e=N(e.mul(new R.default("119332217159966728226237229890")),96,256)),a&16384&&(e=N(e.mul(new R.default("179736315981702064433883588727")),96,256)),a&32768&&(e=N(e.mul(new R.default("407748233172238350107850275304")),96,256)),a&65536&&(e=N(e.mul(new R.default("2098478828474011932436660412517")),96,256)),a&131072&&(e=N(e.mul(new R.default("55581415166113811149459800483533")),96,256)),a&262144&&(e=N(e.mul(new R.default("38992368544603139932233054999993551")),96,256)),N(e,32,256)}function Sd(a){let e=Math.abs(a),t;return e&1?t=new R.default("18445821805675392311"):t=new R.default("18446744073709551616"),e&2&&(t=N(t.mul(new R.default("18444899583751176498")),64,256)),e&4&&(t=N(t.mul(new R.default("18443055278223354162")),64,256)),e&8&&(t=N(t.mul(new R.default("18439367220385604838")),64,256)),e&16&&(t=N(t.mul(new R.default("18431993317065449817")),64,256)),e&32&&(t=N(t.mul(new R.default("18417254355718160513")),64,256)),e&64&&(t=N(t.mul(new R.default("18387811781193591352")),64,256)),e&128&&(t=N(t.mul(new R.default("18329067761203520168")),64,256)),e&256&&(t=N(t.mul(new R.default("18212142134806087854")),64,256)),e&512&&(t=N(t.mul(new R.default("17980523815641551639")),64,256)),e&1024&&(t=N(t.mul(new R.default("17526086738831147013")),64,256)),e&2048&&(t=N(t.mul(new R.default("16651378430235024244")),64,256)),e&4096&&(t=N(t.mul(new R.default("15030750278693429944")),64,256)),e&8192&&(t=N(t.mul(new R.default("12247334978882834399")),64,256)),e&16384&&(t=N(t.mul(new R.default("8131365268884726200")),64,256)),e&32768&&(t=N(t.mul(new R.default("3584323654723342297")),64,256)),e&65536&&(t=N(t.mul(new R.default("696457651847595233")),64,256)),e&131072&&(t=N(t.mul(new R.default("26294789957452057")),64,256)),e&262144&&(t=N(t.mul(new R.default("37481735321082")),64,256)),t}var ai=(a,e,t)=>{let n=(0,ie.convertI32ToSigned)(t?a+a%(e??1):a-a%(e??1));return n>0?new R.default(bd(n)):new R.default(Sd(n))},$m=async(a,e,t,n,o,r,c,u,d)=>{let S=ai((0,ie.convertI32ToSigned)(u),r.tickSpacing),w=ai((0,ie.convertI32ToSigned)(d),r.tickSpacing),I=BigInt(Math.ceil(Number(n)*10**r.tokenX.decimals)),C=BigInt(Math.ceil(Number(o)*10**r.tokenY.decimals)),k,x;Number(n)?k=await cn(a,t,zt(r.tokenX.coinType),I,e):[k]=e.moveCall({target:"0x2::coin::zero",typeArguments:[r.tokenX.coinType],arguments:[]}),Number(o)?x=await cn(a,t,zt(r.tokenY.coinType),C,e):[x]=e.moveCall({target:"0x2::coin::zero",typeArguments:[r.tokenY.coinType],arguments:[]});let P={objectId:c,tokenXType:r.tokenXType,tokenYType:r.tokenYType,tickSpacing:r.tickSpacing},L=a.Position.openPosition(e,P,S.toString(),w.toString());a.Pool.addLiquidity(e,P,L,k,x,BigInt(0),BigInt(0),t),e.transferObjects([L],e.pure.address(t))},Hm=async(a,e,t,n,o,r,c,u,d)=>{try{let S=BigInt(Math.ceil(Number(o)*10**(r?c.tokenX.decimals:c.tokenY.decimals))),w=r?c.tokenX.coinType:c.tokenY.coinType;w=zt(w);let I=await cn(a,n,w,S,e),C={objectId:c.objectId,tokenXType:zt(c.tokenX.coinType),tokenYType:zt(c.tokenY.coinType),tickSpacing:c.tickSpacing},k=ai((0,ie.convertI32ToSigned)(u),c.tickSpacing),x=ai((0,ie.convertI32ToSigned)(d),c.tickSpacing),P=a.Position.openPosition(e,C,k.toString(),x.toString()),V=(await t.getObject({id:c.objectId,options:{showContent:!0}}))?.data?.content?.fields?.sqrt_price??c.currentSqrtPrice,_t=ie.TickMath.sqrtPriceX64ToPrice(new R.default(V?.toString()),c.tokenX.decimals,c.tokenY.decimals),Rt=ie.TickMath.priceToSqrtPriceX64(_t.mul(r?.99:1.01),c.tokenX.decimals,c.tokenY.decimals);await a.Pool.addLiquiditySingleSided(e,C,P,I,BigInt(0),BigInt(0),r,n,BigInt(Rt.toString())),e.transferObjects([P],e.pure.address(n))}catch(S){console.error(S)}};var ri=class a extends v{constructor(t){super(t);this.data=t}txType;txSubType;async build(){let t=Gm.MmtSDK.NEW({network:"mainnet"}),{params:n}=this.data,{address:o,amountA:r,amountB:c,pool:u,selectedLowTick:d,selectedHighTick:S}=n,w=new Qm.Transaction;return await $m(t,w,o,r,c,u,u.objectId,d,S),w}static fromData(t){return new a(t)}};var zm=require("@mmt-finance/clmm-sdk"),Jm=require("@mysten/sui/transactions");var ii=class a extends v{constructor(t){super(t);this.data=t}txType;txSubType;async build(){let t=zm.MmtSDK.NEW({network:"mainnet"}),{params:n}=this.data,{address:o,amount:r,isTokenX:c,pool:u,selectedLowTick:d,selectedHighTick:S}=n,w=new Jm.Transaction;return await Hm(t,w,t.rpcClient,o,r,c,u,d,S),w}static fromData(t){return new a(t)}};var Xm=require("@mmt-finance/clmm-sdk"),Ym=require("@mysten/sui/transactions");var ln=(a,e,t,n,o)=>{let r={objectId:n.objectId,tokenXType:n.tokenXType,tokenYType:n.tokenYType};(n?.rewarders?.length??0)>0&&a.Pool.collectAllRewards(o,r,n.rewarders,t.objectId,e),a.Pool.collectFee(o,n,t.objectId,e)};var si=class a extends v{constructor(t){super(t);this.data=t}txType;txSubType;async build(){let t=Xm.MmtSDK.NEW({network:"mainnet"}),{params:n}=this.data,{address:o,positions:r,pools:c}=n,u=new Ym.Transaction;for(let d of r){let S=c.find(w=>w.objectId===d.poolId);ln(t,o,d,S,u)}return u}static fromData(t){return new a(t)}};var Zm=require("@mmt-finance/clmm-sdk"),tp=require("@mysten/sui/transactions");var ci=class a extends v{constructor(t){super(t);this.data=t}txType;txSubType;async build(){let t=Zm.MmtSDK.NEW({network:"mainnet"}),{params:n}=this.data,{address:o,position:r,pool:c}=n,u=new tp.Transaction;return ln(t,o,r,c,u),u}static fromData(t){return new a(t)}};var ep=require("@mmt-finance/clmm-sdk"),np=require("@mysten/sui/transactions"),op=$t(require("bignumber.js"));var li=class a extends v{constructor(t){super(t);this.data=t}txType;txSubType;async build(){let t=ep.MmtSDK.NEW({network:"mainnet"}),{params:n}=this.data,{pool:o,position:r,address:c,withdrawPercentage:u}=n,d=new np.Transaction,S=o.tokenX.coinType,w=o.tokenY.coinType,I={objectId:o.objectId,tokenXType:S,tokenYType:w},C=BigInt(u===100?r.liquidity:new op.default(r.liquidity).multipliedBy(u/100).toFixed(0));return t.Pool.removeLiquidity(d,I,r.objectId,C,BigInt(0),BigInt(0),c),ln(t,c,r,o,d),u===100&&t.Position.closePosition(d,r.objectId),d}static fromData(t){return new a(t)}};var ip=require("@mmt-finance/clmm-sdk"),sp=require("@mysten/sui/transactions");var ap=require("@mmt-finance/clmm-sdk/dist/utils/poolUtils");var rp=async(a,e,t,n,o,r)=>{let c=BigInt(Math.ceil(Number(n)*10**t.decimals)),u=await cn(a,o,zt(t.coinType),c,r),d=t.coinType;for(let S=0;S<e.length;S+=1){let{objectId:w,tokenX:I,tokenY:C,isStable:k}=e[S],{id:x,isReverse:P}=ap.mappedMmtV3Pool[w]||{id:w,isReverse:!1},L=zt(I.coinType)===zt(d);L=P?!L:L;let V=P?C.coinType:I.coinType,_t=P?I.coinType:C.coinType,Rt=a.Pool.swap(r,{objectId:x,tokenXType:V,tokenYType:_t,isStable:k},c,u,L,void 0);r.transferObjects([u],r.pure.address(o)),u=Rt,d=L?_t:V,[c]=r.moveCall({target:"0x2::coin::value",typeArguments:[d],arguments:[u]})}r.transferObjects([u],r.pure.address(o))};var ui=class a extends v{constructor(t){super(t);this.data=t}txType;txSubType;async build(){let t=ip.MmtSDK.NEW({network:"mainnet"}),{params:n}=this.data,{route:o,tokenIn:r,amountIn:c,address:u}=n,d=new sp.Transaction;return await rp(t,o,r,c,u,d),d}static fromData(t){return new a(t)}};var mi=class{application="mmt-dex";supportSDK="@mysten/sui";async deserialize(e){let{appContext:t}=e;return{txType:cp.TransactionType.Other,txSubType:t.action,intentionData:t}}async build(e){let t;switch(e.txSubType){case"Swap":t=ui.fromData(e.intentionData);break;case"AddLiquidity":t=ri.fromData(e.intentionData);break;case"AddLiquiditySingleSide":t=ii.fromData(e.intentionData);break;case"ClaimRewards":t=ci.fromData(e.intentionData);break;case"ClaimAllRewards":t=si.fromData(e.intentionData);break;case"RemoveLiquidity":t=li.fromData(e.intentionData);break;default:throw new Error("not implemented")}return t.build()}};var Td=Ca.fromHelpers([new ca,new ba,new ra,new Sa,new _o,new Fr,new mi,new ar,new Qr,new mo,new fr,new Cr,new Hn,new oi,new Dr]);
2
2
  //# sourceMappingURL=index.js.map