@msafe/sui-app-store 0.0.311 → 0.0.327

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 cd=Object.create;var Vn=Object.defineProperty;var ld=Object.getOwnPropertyDescriptor;var ud=Object.getOwnPropertyNames;var md=Object.getPrototypeOf,pd=Object.prototype.hasOwnProperty;var dd=(a,e)=>()=>(e||a((e={exports:{}}).exports,e),e.exports),Yr=(a,e)=>{for(var t in e)Vn(a,t,{get:e[t],enumerable:!0})},hc=(a,e,t,n)=>{if(e&&typeof e=="object"||typeof e=="function")for(let o of ud(e))!pd.call(a,o)&&o!==t&&Vn(a,o,{get:()=>e[o],enumerable:!(n=ld(e,o))||n.enumerable});return a};var qt=(a,e,t)=>(t=a!=null?cd(md(a)):{},hc(e||!a||!a.__esModule?Vn(t,"default",{value:a,enumerable:!0}):t,a)),fd=a=>hc(Vn({},"__esModule",{value:!0}),a);var Ip=dd((Sp,$s)=>{"use strict";(function(a,e){"use strict";function t(y,r){if(!y)throw new Error(r||"Assertion failed")}function n(y,r){y.super_=r;var u=function(){};u.prototype=r.prototype,y.prototype=new u,y.prototype.constructor=y}function o(y,r,u){if(o.isBN(y))return y;this.negative=0,this.words=null,this.length=0,this.red=null,y!==null&&((r==="le"||r==="be")&&(u=r,r=10),this._init(y||0,r||10,u||"be"))}typeof 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,u){return r.cmp(u)>0?r:u},o.min=function(r,u){return r.cmp(u)<0?r:u},o.prototype._init=function(r,u,m){if(typeof r=="number")return this._initNumber(r,u,m);if(typeof r=="object")return this._initArray(r,u,m);u==="hex"&&(u=16),t(u===(u|0)&&u>=2&&u<=36),r=r.toString().replace(/\s+/g,"");var p=0;r[0]==="-"&&(p++,this.negative=1),p<r.length&&(u===16?this._parseHex(r,p,m):(this._parseBase(r,u,p),m==="le"&&this._initArray(this.toArray(),u,m)))},o.prototype._initNumber=function(r,u,m){r<0&&(this.negative=1,r=-r),r<67108864?(this.words=[r&67108863],this.length=1):r<4503599627370496?(this.words=[r&67108863,r/67108864&67108863],this.length=2):(t(r<9007199254740992),this.words=[r&67108863,r/67108864&67108863,1],this.length=3),m==="le"&&this._initArray(this.toArray(),u,m)},o.prototype._initArray=function(r,u,m){if(t(typeof r.length=="number"),r.length<=0)return this.words=[0],this.length=1,this;this.length=Math.ceil(r.length/3),this.words=new Array(this.length);for(var p=0;p<this.length;p++)this.words[p]=0;var h,T,w=0;if(m==="be")for(p=r.length-1,h=0;p>=0;p-=3)T=r[p]|r[p-1]<<8|r[p-2]<<16,this.words[h]|=T<<w&67108863,this.words[h+1]=T>>>26-w&67108863,w+=24,w>=26&&(w-=26,h++);else if(m==="le")for(p=0,h=0;p<r.length;p+=3)T=r[p]|r[p+1]<<8|r[p+2]<<16,this.words[h]|=T<<w&67108863,this.words[h+1]=T>>>26-w&67108863,w+=24,w>=26&&(w-=26,h++);return this._strip()};function s(y,r){var u=y.charCodeAt(r);if(u>=48&&u<=57)return u-48;if(u>=65&&u<=70)return u-55;if(u>=97&&u<=102)return u-87;t(!1,"Invalid character in "+y)}function l(y,r,u){var m=s(y,u);return u-1>=r&&(m|=s(y,u-1)<<4),m}o.prototype._parseHex=function(r,u,m){this.length=Math.ceil((r.length-u)/6),this.words=new Array(this.length);for(var p=0;p<this.length;p++)this.words[p]=0;var h=0,T=0,w;if(m==="be")for(p=r.length-1;p>=u;p-=2)w=l(r,u,p)<<h,this.words[T]|=w&67108863,h>=18?(h-=18,T+=1,this.words[T]|=w>>>26):h+=8;else{var f=r.length-u;for(p=f%2===0?u+1:u;p<r.length;p+=2)w=l(r,u,p)<<h,this.words[T]|=w&67108863,h>=18?(h-=18,T+=1,this.words[T]|=w>>>26):h+=8}this._strip()};function d(y,r,u,m){for(var p=0,h=0,T=Math.min(y.length,u),w=r;w<T;w++){var f=y.charCodeAt(w)-48;p*=m,f>=49?h=f-49+10:f>=17?h=f-17+10:h=f,t(f>=0&&h<m,"Invalid character"),p+=h}return p}o.prototype._parseBase=function(r,u,m){this.words=[0],this.length=1;for(var p=0,h=1;h<=67108863;h*=u)p++;p--,h=h/u|0;for(var T=r.length-m,w=T%p,f=Math.min(T,T-w)+m,c=0,g=m;g<f;g+=p)c=d(r,g,g+p,u),this.imuln(h),this.words[0]+c<67108864?this.words[0]+=c:this._iaddn(c);if(w!==0){var v=1;for(c=d(r,g,r.length,u),g=0;g<w;g++)v*=u;this.imuln(v),this.words[0]+c<67108864?this.words[0]+=c:this._iaddn(c)}this._strip()},o.prototype.copy=function(r){r.words=new Array(this.length);for(var u=0;u<this.length;u++)r.words[u]=this.words[u];r.length=this.length,r.negative=this.negative,r.red=this.red};function b(y,r){y.words=r.words,y.length=r.length,y.negative=r.negative,y.red=r.red}if(o.prototype._move=function(r){b(r,this)},o.prototype.clone=function(){var r=new o(null);return this.copy(r),r},o.prototype._expand=function(r){for(;this.length<r;)this.words[this.length++]=0;return this},o.prototype._strip=function(){for(;this.length>1&&this.words[this.length-1]===0;)this.length--;return this._normSign()},o.prototype._normSign=function(){return this.length===1&&this.words[0]===0&&(this.negative=0),this},typeof Symbol<"u"&&typeof Symbol.for=="function")try{o.prototype[Symbol.for("nodejs.util.inspect.custom")]=I}catch{o.prototype.inspect=I}else o.prototype.inspect=I;function I(){return(this.red?"<BN-R: ":"<BN: ")+this.toString(16)+">"}var 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"],x=[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],D=[0,0,33554432,43046721,16777216,48828125,60466176,40353607,16777216,43046721,1e7,19487171,35831808,62748517,7529536,11390625,16777216,24137569,34012224,47045881,64e6,4084101,5153632,6436343,7962624,9765625,11881376,14348907,17210368,20511149,243e5,28629151,33554432,39135393,45435424,52521875,60466176];o.prototype.toString=function(r,u){r=r||10,u=u|0||1;var m;if(r===16||r==="hex"){m="";for(var p=0,h=0,T=0;T<this.length;T++){var w=this.words[T],f=((w<<p|h)&16777215).toString(16);h=w>>>24-p&16777215,p+=2,p>=26&&(p-=26,T--),h!==0||T!==this.length-1?m=C[6-f.length]+f+m:m=f+m}for(h!==0&&(m=h.toString(16)+m);m.length%u!==0;)m="0"+m;return this.negative!==0&&(m="-"+m),m}if(r===(r|0)&&r>=2&&r<=36){var c=x[r],g=D[r];m="";var v=this.clone();for(v.negative=0;!v.isZero();){var M=v.modrn(g).toString(r);v=v.idivn(g),v.isZero()?m=M+m:m=C[c-M.length]+M+m}for(this.isZero()&&(m="0"+m);m.length%u!==0;)m="0"+m;return this.negative!==0&&(m="-"+m),m}t(!1,"Base should be between 2 and 36")},o.prototype.toNumber=function(){var r=this.words[0];return this.length===2?r+=this.words[1]*67108864:this.length===3&&this.words[2]===1?r+=4503599627370496+this.words[1]*67108864:this.length>2&&t(!1,"Number can only safely store up to 53 bits"),this.negative!==0?-r:r},o.prototype.toJSON=function(){return this.toString(16,2)},i&&(o.prototype.toBuffer=function(r,u){return this.toArrayLike(i,r,u)}),o.prototype.toArray=function(r,u){return this.toArrayLike(Array,r,u)};var k=function(r,u){return r.allocUnsafe?r.allocUnsafe(u):new r(u)};o.prototype.toArrayLike=function(r,u,m){this._strip();var p=this.byteLength(),h=m||Math.max(1,p);t(p<=h,"byte array longer than desired length"),t(h>0,"Requested array length <= 0");var T=k(r,h),w=u==="le"?"LE":"BE";return this["_toArrayLike"+w](T,p),T},o.prototype._toArrayLikeLE=function(r,u){for(var m=0,p=0,h=0,T=0;h<this.length;h++){var w=this.words[h]<<T|p;r[m++]=w&255,m<r.length&&(r[m++]=w>>8&255),m<r.length&&(r[m++]=w>>16&255),T===6?(m<r.length&&(r[m++]=w>>24&255),p=0,T=0):(p=w>>>24,T+=2)}if(m<r.length)for(r[m++]=p;m<r.length;)r[m++]=0},o.prototype._toArrayLikeBE=function(r,u){for(var m=r.length-1,p=0,h=0,T=0;h<this.length;h++){var w=this.words[h]<<T|p;r[m--]=w&255,m>=0&&(r[m--]=w>>8&255),m>=0&&(r[m--]=w>>16&255),T===6?(m>=0&&(r[m--]=w>>24&255),p=0,T=0):(p=w>>>24,T+=2)}if(m>=0)for(r[m--]=p;m>=0;)r[m--]=0},Math.clz32?o.prototype._countBits=function(r){return 32-Math.clz32(r)}:o.prototype._countBits=function(r){var u=r,m=0;return u>=4096&&(m+=13,u>>>=13),u>=64&&(m+=7,u>>>=7),u>=8&&(m+=4,u>>>=4),u>=2&&(m+=2,u>>>=2),m+u},o.prototype._zeroBits=function(r){if(r===0)return 26;var u=r,m=0;return(u&8191)===0&&(m+=13,u>>>=13),(u&127)===0&&(m+=7,u>>>=7),(u&15)===0&&(m+=4,u>>>=4),(u&3)===0&&(m+=2,u>>>=2),(u&1)===0&&m++,m},o.prototype.bitLength=function(){var r=this.words[this.length-1],u=this._countBits(r);return(this.length-1)*26+u};function P(y){for(var r=new Array(y.bitLength()),u=0;u<r.length;u++){var m=u/26|0,p=u%26;r[u]=y.words[m]>>>p&1}return r}o.prototype.zeroBits=function(){if(this.isZero())return 0;for(var r=0,u=0;u<this.length;u++){var m=this._zeroBits(this.words[u]);if(r+=m,m!==26)break}return r},o.prototype.byteLength=function(){return Math.ceil(this.bitLength()/8)},o.prototype.toTwos=function(r){return this.negative!==0?this.abs().inotn(r).iaddn(1):this.clone()},o.prototype.fromTwos=function(r){return this.testn(r-1)?this.notn(r).iaddn(1).ineg():this.clone()},o.prototype.isNeg=function(){return this.negative!==0},o.prototype.neg=function(){return this.clone().ineg()},o.prototype.ineg=function(){return this.isZero()||(this.negative^=1),this},o.prototype.iuor=function(r){for(;this.length<r.length;)this.words[this.length++]=0;for(var u=0;u<r.length;u++)this.words[u]=this.words[u]|r.words[u];return this._strip()},o.prototype.ior=function(r){return t((this.negative|r.negative)===0),this.iuor(r)},o.prototype.or=function(r){return this.length>r.length?this.clone().ior(r):r.clone().ior(this)},o.prototype.uor=function(r){return this.length>r.length?this.clone().iuor(r):r.clone().iuor(this)},o.prototype.iuand=function(r){var u;this.length>r.length?u=r:u=this;for(var m=0;m<u.length;m++)this.words[m]=this.words[m]&r.words[m];return this.length=u.length,this._strip()},o.prototype.iand=function(r){return t((this.negative|r.negative)===0),this.iuand(r)},o.prototype.and=function(r){return this.length>r.length?this.clone().iand(r):r.clone().iand(this)},o.prototype.uand=function(r){return this.length>r.length?this.clone().iuand(r):r.clone().iuand(this)},o.prototype.iuxor=function(r){var u,m;this.length>r.length?(u=this,m=r):(u=r,m=this);for(var p=0;p<m.length;p++)this.words[p]=u.words[p]^m.words[p];if(this!==u)for(;p<u.length;p++)this.words[p]=u.words[p];return this.length=u.length,this._strip()},o.prototype.ixor=function(r){return t((this.negative|r.negative)===0),this.iuxor(r)},o.prototype.xor=function(r){return this.length>r.length?this.clone().ixor(r):r.clone().ixor(this)},o.prototype.uxor=function(r){return this.length>r.length?this.clone().iuxor(r):r.clone().iuxor(this)},o.prototype.inotn=function(r){t(typeof r=="number"&&r>=0);var u=Math.ceil(r/26)|0,m=r%26;this._expand(u),m>0&&u--;for(var p=0;p<u;p++)this.words[p]=~this.words[p]&67108863;return m>0&&(this.words[p]=~this.words[p]&67108863>>26-m),this._strip()},o.prototype.notn=function(r){return this.clone().inotn(r)},o.prototype.setn=function(r,u){t(typeof r=="number"&&r>=0);var m=r/26|0,p=r%26;return this._expand(m+1),u?this.words[m]=this.words[m]|1<<p:this.words[m]=this.words[m]&~(1<<p),this._strip()},o.prototype.iadd=function(r){var u;if(this.negative!==0&&r.negative===0)return this.negative=0,u=this.isub(r),this.negative^=1,this._normSign();if(this.negative===0&&r.negative!==0)return r.negative=0,u=this.isub(r),r.negative=1,u._normSign();var m,p;this.length>r.length?(m=this,p=r):(m=r,p=this);for(var h=0,T=0;T<p.length;T++)u=(m.words[T]|0)+(p.words[T]|0)+h,this.words[T]=u&67108863,h=u>>>26;for(;h!==0&&T<m.length;T++)u=(m.words[T]|0)+h,this.words[T]=u&67108863,h=u>>>26;if(this.length=m.length,h!==0)this.words[this.length]=h,this.length++;else if(m!==this)for(;T<m.length;T++)this.words[T]=m.words[T];return this},o.prototype.add=function(r){var u;return r.negative!==0&&this.negative===0?(r.negative=0,u=this.sub(r),r.negative^=1,u):r.negative===0&&this.negative!==0?(this.negative=0,u=r.sub(this),this.negative=1,u):this.length>r.length?this.clone().iadd(r):r.clone().iadd(this)},o.prototype.isub=function(r){if(r.negative!==0){r.negative=0;var u=this.iadd(r);return r.negative=1,u._normSign()}else if(this.negative!==0)return this.negative=0,this.iadd(r),this.negative=1,this._normSign();var m=this.cmp(r);if(m===0)return this.negative=0,this.length=1,this.words[0]=0,this;var p,h;m>0?(p=this,h=r):(p=r,h=this);for(var T=0,w=0;w<h.length;w++)u=(p.words[w]|0)-(h.words[w]|0)+T,T=u>>26,this.words[w]=u&67108863;for(;T!==0&&w<p.length;w++)u=(p.words[w]|0)+T,T=u>>26,this.words[w]=u&67108863;if(T===0&&w<p.length&&p!==this)for(;w<p.length;w++)this.words[w]=p.words[w];return this.length=Math.max(this.length,w),p!==this&&(this.negative=1),this._strip()},o.prototype.sub=function(r){return this.clone().isub(r)};function U(y,r,u){u.negative=r.negative^y.negative;var m=y.length+r.length|0;u.length=m,m=m-1|0;var p=y.words[0]|0,h=r.words[0]|0,T=p*h,w=T&67108863,f=T/67108864|0;u.words[0]=w;for(var c=1;c<m;c++){for(var g=f>>>26,v=f&67108863,M=Math.min(c,r.length-1),O=Math.max(0,c-y.length+1);O<=M;O++){var B=c-O|0;p=y.words[B]|0,h=r.words[O]|0,T=p*h+v,g+=T/67108864|0,v=T&67108863}u.words[c]=v|0,f=g|0}return f!==0?u.words[c]=f|0:u.length--,u._strip()}var K=function(r,u,m){var p=r.words,h=u.words,T=m.words,w=0,f,c,g,v=p[0]|0,M=v&8191,O=v>>>13,B=p[1]|0,N=B&8191,L=B>>>13,ue=p[2]|0,j=ue&8191,F=ue>>>13,Ys=p[3]|0,H=Ys&8191,X=Ys>>>13,Zs=p[4]|0,z=Zs&8191,G=Zs>>>13,tc=p[5]|0,Q=tc&8191,J=tc>>>13,ec=p[6]|0,Y=ec&8191,Z=ec>>>13,nc=p[7]|0,tt=nc&8191,et=nc>>>13,oc=p[8]|0,nt=oc&8191,ot=oc>>>13,ac=p[9]|0,at=ac&8191,it=ac>>>13,ic=h[0]|0,rt=ic&8191,st=ic>>>13,rc=h[1]|0,ct=rc&8191,lt=rc>>>13,sc=h[2]|0,ut=sc&8191,mt=sc>>>13,cc=h[3]|0,pt=cc&8191,dt=cc>>>13,lc=h[4]|0,ft=lc&8191,ht=lc>>>13,uc=h[5]|0,gt=uc&8191,yt=uc>>>13,mc=h[6]|0,bt=mc&8191,Tt=mc>>>13,pc=h[7]|0,St=pc&8191,It=pc>>>13,dc=h[8]|0,wt=dc&8191,Ct=dc>>>13,fc=h[9]|0,xt=fc&8191,Dt=fc>>>13;m.negative=r.negative^u.negative,m.length=19,f=Math.imul(M,rt),c=Math.imul(M,st),c=c+Math.imul(O,rt)|0,g=Math.imul(O,st);var Br=(w+f|0)+((c&8191)<<13)|0;w=(g+(c>>>13)|0)+(Br>>>26)|0,Br&=67108863,f=Math.imul(N,rt),c=Math.imul(N,st),c=c+Math.imul(L,rt)|0,g=Math.imul(L,st),f=f+Math.imul(M,ct)|0,c=c+Math.imul(M,lt)|0,c=c+Math.imul(O,ct)|0,g=g+Math.imul(O,lt)|0;var Er=(w+f|0)+((c&8191)<<13)|0;w=(g+(c>>>13)|0)+(Er>>>26)|0,Er&=67108863,f=Math.imul(j,rt),c=Math.imul(j,st),c=c+Math.imul(F,rt)|0,g=Math.imul(F,st),f=f+Math.imul(N,ct)|0,c=c+Math.imul(N,lt)|0,c=c+Math.imul(L,ct)|0,g=g+Math.imul(L,lt)|0,f=f+Math.imul(M,ut)|0,c=c+Math.imul(M,mt)|0,c=c+Math.imul(O,ut)|0,g=g+Math.imul(O,mt)|0;var Wr=(w+f|0)+((c&8191)<<13)|0;w=(g+(c>>>13)|0)+(Wr>>>26)|0,Wr&=67108863,f=Math.imul(H,rt),c=Math.imul(H,st),c=c+Math.imul(X,rt)|0,g=Math.imul(X,st),f=f+Math.imul(j,ct)|0,c=c+Math.imul(j,lt)|0,c=c+Math.imul(F,ct)|0,g=g+Math.imul(F,lt)|0,f=f+Math.imul(N,ut)|0,c=c+Math.imul(N,mt)|0,c=c+Math.imul(L,ut)|0,g=g+Math.imul(L,mt)|0,f=f+Math.imul(M,pt)|0,c=c+Math.imul(M,dt)|0,c=c+Math.imul(O,pt)|0,g=g+Math.imul(O,dt)|0;var Nr=(w+f|0)+((c&8191)<<13)|0;w=(g+(c>>>13)|0)+(Nr>>>26)|0,Nr&=67108863,f=Math.imul(z,rt),c=Math.imul(z,st),c=c+Math.imul(G,rt)|0,g=Math.imul(G,st),f=f+Math.imul(H,ct)|0,c=c+Math.imul(H,lt)|0,c=c+Math.imul(X,ct)|0,g=g+Math.imul(X,lt)|0,f=f+Math.imul(j,ut)|0,c=c+Math.imul(j,mt)|0,c=c+Math.imul(F,ut)|0,g=g+Math.imul(F,mt)|0,f=f+Math.imul(N,pt)|0,c=c+Math.imul(N,dt)|0,c=c+Math.imul(L,pt)|0,g=g+Math.imul(L,dt)|0,f=f+Math.imul(M,ft)|0,c=c+Math.imul(M,ht)|0,c=c+Math.imul(O,ft)|0,g=g+Math.imul(O,ht)|0;var _r=(w+f|0)+((c&8191)<<13)|0;w=(g+(c>>>13)|0)+(_r>>>26)|0,_r&=67108863,f=Math.imul(Q,rt),c=Math.imul(Q,st),c=c+Math.imul(J,rt)|0,g=Math.imul(J,st),f=f+Math.imul(z,ct)|0,c=c+Math.imul(z,lt)|0,c=c+Math.imul(G,ct)|0,g=g+Math.imul(G,lt)|0,f=f+Math.imul(H,ut)|0,c=c+Math.imul(H,mt)|0,c=c+Math.imul(X,ut)|0,g=g+Math.imul(X,mt)|0,f=f+Math.imul(j,pt)|0,c=c+Math.imul(j,dt)|0,c=c+Math.imul(F,pt)|0,g=g+Math.imul(F,dt)|0,f=f+Math.imul(N,ft)|0,c=c+Math.imul(N,ht)|0,c=c+Math.imul(L,ft)|0,g=g+Math.imul(L,ht)|0,f=f+Math.imul(M,gt)|0,c=c+Math.imul(M,yt)|0,c=c+Math.imul(O,gt)|0,g=g+Math.imul(O,yt)|0;var Lr=(w+f|0)+((c&8191)<<13)|0;w=(g+(c>>>13)|0)+(Lr>>>26)|0,Lr&=67108863,f=Math.imul(Y,rt),c=Math.imul(Y,st),c=c+Math.imul(Z,rt)|0,g=Math.imul(Z,st),f=f+Math.imul(Q,ct)|0,c=c+Math.imul(Q,lt)|0,c=c+Math.imul(J,ct)|0,g=g+Math.imul(J,lt)|0,f=f+Math.imul(z,ut)|0,c=c+Math.imul(z,mt)|0,c=c+Math.imul(G,ut)|0,g=g+Math.imul(G,mt)|0,f=f+Math.imul(H,pt)|0,c=c+Math.imul(H,dt)|0,c=c+Math.imul(X,pt)|0,g=g+Math.imul(X,dt)|0,f=f+Math.imul(j,ft)|0,c=c+Math.imul(j,ht)|0,c=c+Math.imul(F,ft)|0,g=g+Math.imul(F,ht)|0,f=f+Math.imul(N,gt)|0,c=c+Math.imul(N,yt)|0,c=c+Math.imul(L,gt)|0,g=g+Math.imul(L,yt)|0,f=f+Math.imul(M,bt)|0,c=c+Math.imul(M,Tt)|0,c=c+Math.imul(O,bt)|0,g=g+Math.imul(O,Tt)|0;var jr=(w+f|0)+((c&8191)<<13)|0;w=(g+(c>>>13)|0)+(jr>>>26)|0,jr&=67108863,f=Math.imul(tt,rt),c=Math.imul(tt,st),c=c+Math.imul(et,rt)|0,g=Math.imul(et,st),f=f+Math.imul(Y,ct)|0,c=c+Math.imul(Y,lt)|0,c=c+Math.imul(Z,ct)|0,g=g+Math.imul(Z,lt)|0,f=f+Math.imul(Q,ut)|0,c=c+Math.imul(Q,mt)|0,c=c+Math.imul(J,ut)|0,g=g+Math.imul(J,mt)|0,f=f+Math.imul(z,pt)|0,c=c+Math.imul(z,dt)|0,c=c+Math.imul(G,pt)|0,g=g+Math.imul(G,dt)|0,f=f+Math.imul(H,ft)|0,c=c+Math.imul(H,ht)|0,c=c+Math.imul(X,ft)|0,g=g+Math.imul(X,ht)|0,f=f+Math.imul(j,gt)|0,c=c+Math.imul(j,yt)|0,c=c+Math.imul(F,gt)|0,g=g+Math.imul(F,yt)|0,f=f+Math.imul(N,bt)|0,c=c+Math.imul(N,Tt)|0,c=c+Math.imul(L,bt)|0,g=g+Math.imul(L,Tt)|0,f=f+Math.imul(M,St)|0,c=c+Math.imul(M,It)|0,c=c+Math.imul(O,St)|0,g=g+Math.imul(O,It)|0;var Ur=(w+f|0)+((c&8191)<<13)|0;w=(g+(c>>>13)|0)+(Ur>>>26)|0,Ur&=67108863,f=Math.imul(nt,rt),c=Math.imul(nt,st),c=c+Math.imul(ot,rt)|0,g=Math.imul(ot,st),f=f+Math.imul(tt,ct)|0,c=c+Math.imul(tt,lt)|0,c=c+Math.imul(et,ct)|0,g=g+Math.imul(et,lt)|0,f=f+Math.imul(Y,ut)|0,c=c+Math.imul(Y,mt)|0,c=c+Math.imul(Z,ut)|0,g=g+Math.imul(Z,mt)|0,f=f+Math.imul(Q,pt)|0,c=c+Math.imul(Q,dt)|0,c=c+Math.imul(J,pt)|0,g=g+Math.imul(J,dt)|0,f=f+Math.imul(z,ft)|0,c=c+Math.imul(z,ht)|0,c=c+Math.imul(G,ft)|0,g=g+Math.imul(G,ht)|0,f=f+Math.imul(H,gt)|0,c=c+Math.imul(H,yt)|0,c=c+Math.imul(X,gt)|0,g=g+Math.imul(X,yt)|0,f=f+Math.imul(j,bt)|0,c=c+Math.imul(j,Tt)|0,c=c+Math.imul(F,bt)|0,g=g+Math.imul(F,Tt)|0,f=f+Math.imul(N,St)|0,c=c+Math.imul(N,It)|0,c=c+Math.imul(L,St)|0,g=g+Math.imul(L,It)|0,f=f+Math.imul(M,wt)|0,c=c+Math.imul(M,Ct)|0,c=c+Math.imul(O,wt)|0,g=g+Math.imul(O,Ct)|0;var qr=(w+f|0)+((c&8191)<<13)|0;w=(g+(c>>>13)|0)+(qr>>>26)|0,qr&=67108863,f=Math.imul(at,rt),c=Math.imul(at,st),c=c+Math.imul(it,rt)|0,g=Math.imul(it,st),f=f+Math.imul(nt,ct)|0,c=c+Math.imul(nt,lt)|0,c=c+Math.imul(ot,ct)|0,g=g+Math.imul(ot,lt)|0,f=f+Math.imul(tt,ut)|0,c=c+Math.imul(tt,mt)|0,c=c+Math.imul(et,ut)|0,g=g+Math.imul(et,mt)|0,f=f+Math.imul(Y,pt)|0,c=c+Math.imul(Y,dt)|0,c=c+Math.imul(Z,pt)|0,g=g+Math.imul(Z,dt)|0,f=f+Math.imul(Q,ft)|0,c=c+Math.imul(Q,ht)|0,c=c+Math.imul(J,ft)|0,g=g+Math.imul(J,ht)|0,f=f+Math.imul(z,gt)|0,c=c+Math.imul(z,yt)|0,c=c+Math.imul(G,gt)|0,g=g+Math.imul(G,yt)|0,f=f+Math.imul(H,bt)|0,c=c+Math.imul(H,Tt)|0,c=c+Math.imul(X,bt)|0,g=g+Math.imul(X,Tt)|0,f=f+Math.imul(j,St)|0,c=c+Math.imul(j,It)|0,c=c+Math.imul(F,St)|0,g=g+Math.imul(F,It)|0,f=f+Math.imul(N,wt)|0,c=c+Math.imul(N,Ct)|0,c=c+Math.imul(L,wt)|0,g=g+Math.imul(L,Ct)|0,f=f+Math.imul(M,xt)|0,c=c+Math.imul(M,Dt)|0,c=c+Math.imul(O,xt)|0,g=g+Math.imul(O,Dt)|0;var Fr=(w+f|0)+((c&8191)<<13)|0;w=(g+(c>>>13)|0)+(Fr>>>26)|0,Fr&=67108863,f=Math.imul(at,ct),c=Math.imul(at,lt),c=c+Math.imul(it,ct)|0,g=Math.imul(it,lt),f=f+Math.imul(nt,ut)|0,c=c+Math.imul(nt,mt)|0,c=c+Math.imul(ot,ut)|0,g=g+Math.imul(ot,mt)|0,f=f+Math.imul(tt,pt)|0,c=c+Math.imul(tt,dt)|0,c=c+Math.imul(et,pt)|0,g=g+Math.imul(et,dt)|0,f=f+Math.imul(Y,ft)|0,c=c+Math.imul(Y,ht)|0,c=c+Math.imul(Z,ft)|0,g=g+Math.imul(Z,ht)|0,f=f+Math.imul(Q,gt)|0,c=c+Math.imul(Q,yt)|0,c=c+Math.imul(J,gt)|0,g=g+Math.imul(J,yt)|0,f=f+Math.imul(z,bt)|0,c=c+Math.imul(z,Tt)|0,c=c+Math.imul(G,bt)|0,g=g+Math.imul(G,Tt)|0,f=f+Math.imul(H,St)|0,c=c+Math.imul(H,It)|0,c=c+Math.imul(X,St)|0,g=g+Math.imul(X,It)|0,f=f+Math.imul(j,wt)|0,c=c+Math.imul(j,Ct)|0,c=c+Math.imul(F,wt)|0,g=g+Math.imul(F,Ct)|0,f=f+Math.imul(N,xt)|0,c=c+Math.imul(N,Dt)|0,c=c+Math.imul(L,xt)|0,g=g+Math.imul(L,Dt)|0;var Kr=(w+f|0)+((c&8191)<<13)|0;w=(g+(c>>>13)|0)+(Kr>>>26)|0,Kr&=67108863,f=Math.imul(at,ut),c=Math.imul(at,mt),c=c+Math.imul(it,ut)|0,g=Math.imul(it,mt),f=f+Math.imul(nt,pt)|0,c=c+Math.imul(nt,dt)|0,c=c+Math.imul(ot,pt)|0,g=g+Math.imul(ot,dt)|0,f=f+Math.imul(tt,ft)|0,c=c+Math.imul(tt,ht)|0,c=c+Math.imul(et,ft)|0,g=g+Math.imul(et,ht)|0,f=f+Math.imul(Y,gt)|0,c=c+Math.imul(Y,yt)|0,c=c+Math.imul(Z,gt)|0,g=g+Math.imul(Z,yt)|0,f=f+Math.imul(Q,bt)|0,c=c+Math.imul(Q,Tt)|0,c=c+Math.imul(J,bt)|0,g=g+Math.imul(J,Tt)|0,f=f+Math.imul(z,St)|0,c=c+Math.imul(z,It)|0,c=c+Math.imul(G,St)|0,g=g+Math.imul(G,It)|0,f=f+Math.imul(H,wt)|0,c=c+Math.imul(H,Ct)|0,c=c+Math.imul(X,wt)|0,g=g+Math.imul(X,Ct)|0,f=f+Math.imul(j,xt)|0,c=c+Math.imul(j,Dt)|0,c=c+Math.imul(F,xt)|0,g=g+Math.imul(F,Dt)|0;var Vr=(w+f|0)+((c&8191)<<13)|0;w=(g+(c>>>13)|0)+(Vr>>>26)|0,Vr&=67108863,f=Math.imul(at,pt),c=Math.imul(at,dt),c=c+Math.imul(it,pt)|0,g=Math.imul(it,dt),f=f+Math.imul(nt,ft)|0,c=c+Math.imul(nt,ht)|0,c=c+Math.imul(ot,ft)|0,g=g+Math.imul(ot,ht)|0,f=f+Math.imul(tt,gt)|0,c=c+Math.imul(tt,yt)|0,c=c+Math.imul(et,gt)|0,g=g+Math.imul(et,yt)|0,f=f+Math.imul(Y,bt)|0,c=c+Math.imul(Y,Tt)|0,c=c+Math.imul(Z,bt)|0,g=g+Math.imul(Z,Tt)|0,f=f+Math.imul(Q,St)|0,c=c+Math.imul(Q,It)|0,c=c+Math.imul(J,St)|0,g=g+Math.imul(J,It)|0,f=f+Math.imul(z,wt)|0,c=c+Math.imul(z,Ct)|0,c=c+Math.imul(G,wt)|0,g=g+Math.imul(G,Ct)|0,f=f+Math.imul(H,xt)|0,c=c+Math.imul(H,Dt)|0,c=c+Math.imul(X,xt)|0,g=g+Math.imul(X,Dt)|0;var $r=(w+f|0)+((c&8191)<<13)|0;w=(g+(c>>>13)|0)+($r>>>26)|0,$r&=67108863,f=Math.imul(at,ft),c=Math.imul(at,ht),c=c+Math.imul(it,ft)|0,g=Math.imul(it,ht),f=f+Math.imul(nt,gt)|0,c=c+Math.imul(nt,yt)|0,c=c+Math.imul(ot,gt)|0,g=g+Math.imul(ot,yt)|0,f=f+Math.imul(tt,bt)|0,c=c+Math.imul(tt,Tt)|0,c=c+Math.imul(et,bt)|0,g=g+Math.imul(et,Tt)|0,f=f+Math.imul(Y,St)|0,c=c+Math.imul(Y,It)|0,c=c+Math.imul(Z,St)|0,g=g+Math.imul(Z,It)|0,f=f+Math.imul(Q,wt)|0,c=c+Math.imul(Q,Ct)|0,c=c+Math.imul(J,wt)|0,g=g+Math.imul(J,Ct)|0,f=f+Math.imul(z,xt)|0,c=c+Math.imul(z,Dt)|0,c=c+Math.imul(G,xt)|0,g=g+Math.imul(G,Dt)|0;var Hr=(w+f|0)+((c&8191)<<13)|0;w=(g+(c>>>13)|0)+(Hr>>>26)|0,Hr&=67108863,f=Math.imul(at,gt),c=Math.imul(at,yt),c=c+Math.imul(it,gt)|0,g=Math.imul(it,yt),f=f+Math.imul(nt,bt)|0,c=c+Math.imul(nt,Tt)|0,c=c+Math.imul(ot,bt)|0,g=g+Math.imul(ot,Tt)|0,f=f+Math.imul(tt,St)|0,c=c+Math.imul(tt,It)|0,c=c+Math.imul(et,St)|0,g=g+Math.imul(et,It)|0,f=f+Math.imul(Y,wt)|0,c=c+Math.imul(Y,Ct)|0,c=c+Math.imul(Z,wt)|0,g=g+Math.imul(Z,Ct)|0,f=f+Math.imul(Q,xt)|0,c=c+Math.imul(Q,Dt)|0,c=c+Math.imul(J,xt)|0,g=g+Math.imul(J,Dt)|0;var Xr=(w+f|0)+((c&8191)<<13)|0;w=(g+(c>>>13)|0)+(Xr>>>26)|0,Xr&=67108863,f=Math.imul(at,bt),c=Math.imul(at,Tt),c=c+Math.imul(it,bt)|0,g=Math.imul(it,Tt),f=f+Math.imul(nt,St)|0,c=c+Math.imul(nt,It)|0,c=c+Math.imul(ot,St)|0,g=g+Math.imul(ot,It)|0,f=f+Math.imul(tt,wt)|0,c=c+Math.imul(tt,Ct)|0,c=c+Math.imul(et,wt)|0,g=g+Math.imul(et,Ct)|0,f=f+Math.imul(Y,xt)|0,c=c+Math.imul(Y,Dt)|0,c=c+Math.imul(Z,xt)|0,g=g+Math.imul(Z,Dt)|0;var zr=(w+f|0)+((c&8191)<<13)|0;w=(g+(c>>>13)|0)+(zr>>>26)|0,zr&=67108863,f=Math.imul(at,St),c=Math.imul(at,It),c=c+Math.imul(it,St)|0,g=Math.imul(it,It),f=f+Math.imul(nt,wt)|0,c=c+Math.imul(nt,Ct)|0,c=c+Math.imul(ot,wt)|0,g=g+Math.imul(ot,Ct)|0,f=f+Math.imul(tt,xt)|0,c=c+Math.imul(tt,Dt)|0,c=c+Math.imul(et,xt)|0,g=g+Math.imul(et,Dt)|0;var Gr=(w+f|0)+((c&8191)<<13)|0;w=(g+(c>>>13)|0)+(Gr>>>26)|0,Gr&=67108863,f=Math.imul(at,wt),c=Math.imul(at,Ct),c=c+Math.imul(it,wt)|0,g=Math.imul(it,Ct),f=f+Math.imul(nt,xt)|0,c=c+Math.imul(nt,Dt)|0,c=c+Math.imul(ot,xt)|0,g=g+Math.imul(ot,Dt)|0;var Qr=(w+f|0)+((c&8191)<<13)|0;w=(g+(c>>>13)|0)+(Qr>>>26)|0,Qr&=67108863,f=Math.imul(at,xt),c=Math.imul(at,Dt),c=c+Math.imul(it,xt)|0,g=Math.imul(it,Dt);var Jr=(w+f|0)+((c&8191)<<13)|0;return w=(g+(c>>>13)|0)+(Jr>>>26)|0,Jr&=67108863,T[0]=Br,T[1]=Er,T[2]=Wr,T[3]=Nr,T[4]=_r,T[5]=Lr,T[6]=jr,T[7]=Ur,T[8]=qr,T[9]=Fr,T[10]=Kr,T[11]=Vr,T[12]=$r,T[13]=Hr,T[14]=Xr,T[15]=zr,T[16]=Gr,T[17]=Qr,T[18]=Jr,w!==0&&(T[19]=w,m.length++),m};Math.imul||(K=U);function Bt(y,r,u){u.negative=r.negative^y.negative,u.length=y.length+r.length;for(var m=0,p=0,h=0;h<u.length-1;h++){var T=p;p=0;for(var w=m&67108863,f=Math.min(h,r.length-1),c=Math.max(0,h-y.length+1);c<=f;c++){var g=h-c,v=y.words[g]|0,M=r.words[c]|0,O=v*M,B=O&67108863;T=T+(O/67108864|0)|0,B=B+w|0,w=B&67108863,T=T+(B>>>26)|0,p+=T>>>26,T&=67108863}u.words[h]=w,m=T,T=p}return m!==0?u.words[h]=m:u.length--,u._strip()}function Wt(y,r,u){return Bt(y,r,u)}o.prototype.mulTo=function(r,u){var m,p=this.length+r.length;return this.length===10&&r.length===10?m=K(this,r,u):p<63?m=U(this,r,u):p<1024?m=Bt(this,r,u):m=Wt(this,r,u),m};function Ot(y,r){this.x=y,this.y=r}Ot.prototype.makeRBT=function(r){for(var u=new Array(r),m=o.prototype._countBits(r)-1,p=0;p<r;p++)u[p]=this.revBin(p,m,r);return u},Ot.prototype.revBin=function(r,u,m){if(r===0||r===m-1)return r;for(var p=0,h=0;h<u;h++)p|=(r&1)<<u-h-1,r>>=1;return p},Ot.prototype.permute=function(r,u,m,p,h,T){for(var w=0;w<T;w++)p[w]=u[r[w]],h[w]=m[r[w]]},Ot.prototype.transform=function(r,u,m,p,h,T){this.permute(T,r,u,m,p,h);for(var w=1;w<h;w<<=1)for(var f=w<<1,c=Math.cos(2*Math.PI/f),g=Math.sin(2*Math.PI/f),v=0;v<h;v+=f)for(var M=c,O=g,B=0;B<w;B++){var N=m[v+B],L=p[v+B],ue=m[v+B+w],j=p[v+B+w],F=M*ue-O*j;j=M*j+O*ue,ue=F,m[v+B]=N+ue,p[v+B]=L+j,m[v+B+w]=N-ue,p[v+B+w]=L-j,B!==f&&(F=c*M-g*O,O=c*O+g*M,M=F)}},Ot.prototype.guessLen13b=function(r,u){var m=Math.max(u,r)|1,p=m&1,h=0;for(m=m/2|0;m;m=m>>>1)h++;return 1<<h+1+p},Ot.prototype.conjugate=function(r,u,m){if(!(m<=1))for(var p=0;p<m/2;p++){var h=r[p];r[p]=r[m-p-1],r[m-p-1]=h,h=u[p],u[p]=-u[m-p-1],u[m-p-1]=-h}},Ot.prototype.normalize13b=function(r,u){for(var m=0,p=0;p<u/2;p++){var h=Math.round(r[2*p+1]/u)*8192+Math.round(r[2*p]/u)+m;r[p]=h&67108863,h<67108864?m=0:m=h/67108864|0}return r},Ot.prototype.convert13b=function(r,u,m,p){for(var h=0,T=0;T<u;T++)h=h+(r[T]|0),m[2*T]=h&8191,h=h>>>13,m[2*T+1]=h&8191,h=h>>>13;for(T=2*u;T<p;++T)m[T]=0;t(h===0),t((h&-8192)===0)},Ot.prototype.stub=function(r){for(var u=new Array(r),m=0;m<r;m++)u[m]=0;return u},Ot.prototype.mulp=function(r,u,m){var p=2*this.guessLen13b(r.length,u.length),h=this.makeRBT(p),T=this.stub(p),w=new Array(p),f=new Array(p),c=new Array(p),g=new Array(p),v=new Array(p),M=new Array(p),O=m.words;O.length=p,this.convert13b(r.words,r.length,w,p),this.convert13b(u.words,u.length,g,p),this.transform(w,T,f,c,p,h),this.transform(g,T,v,M,p,h);for(var B=0;B<p;B++){var N=f[B]*v[B]-c[B]*M[B];c[B]=f[B]*M[B]+c[B]*v[B],f[B]=N}return this.conjugate(f,c,p),this.transform(f,c,O,T,p,h),this.conjugate(O,T,p),this.normalize13b(O,p),m.negative=r.negative^u.negative,m.length=r.length+u.length,m._strip()},o.prototype.mul=function(r){var u=new o(null);return u.words=new Array(this.length+r.length),this.mulTo(r,u)},o.prototype.mulf=function(r){var u=new o(null);return u.words=new Array(this.length+r.length),Wt(this,r,u)},o.prototype.imul=function(r){return this.clone().mulTo(r,this)},o.prototype.imuln=function(r){var u=r<0;u&&(r=-r),t(typeof r=="number"),t(r<67108864);for(var m=0,p=0;p<this.length;p++){var h=(this.words[p]|0)*r,T=(h&67108863)+(m&67108863);m>>=26,m+=h/67108864|0,m+=T>>>26,this.words[p]=T&67108863}return m!==0&&(this.words[p]=m,this.length++),this.length=r===0?1:this.length,u?this.ineg():this},o.prototype.muln=function(r){return this.clone().imuln(r)},o.prototype.sqr=function(){return this.mul(this)},o.prototype.isqr=function(){return this.imul(this.clone())},o.prototype.pow=function(r){var u=P(r);if(u.length===0)return new o(1);for(var m=this,p=0;p<u.length&&u[p]===0;p++,m=m.sqr());if(++p<u.length)for(var h=m.sqr();p<u.length;p++,h=h.sqr())u[p]!==0&&(m=m.mul(h));return m},o.prototype.iushln=function(r){t(typeof r=="number"&&r>=0);var u=r%26,m=(r-u)/26,p=67108863>>>26-u<<26-u,h;if(u!==0){var T=0;for(h=0;h<this.length;h++){var w=this.words[h]&p,f=(this.words[h]|0)-w<<u;this.words[h]=f|T,T=w>>>26-u}T&&(this.words[h]=T,this.length++)}if(m!==0){for(h=this.length-1;h>=0;h--)this.words[h+m]=this.words[h];for(h=0;h<m;h++)this.words[h]=0;this.length+=m}return this._strip()},o.prototype.ishln=function(r){return t(this.negative===0),this.iushln(r)},o.prototype.iushrn=function(r,u,m){t(typeof r=="number"&&r>=0);var p;u?p=(u-u%26)/26:p=0;var h=r%26,T=Math.min((r-h)/26,this.length),w=67108863^67108863>>>h<<h,f=m;if(p-=T,p=Math.max(0,p),f){for(var c=0;c<T;c++)f.words[c]=this.words[c];f.length=T}if(T!==0)if(this.length>T)for(this.length-=T,c=0;c<this.length;c++)this.words[c]=this.words[c+T];else this.words[0]=0,this.length=1;var g=0;for(c=this.length-1;c>=0&&(g!==0||c>=p);c--){var v=this.words[c]|0;this.words[c]=g<<26-h|v>>>h,g=v&w}return f&&g!==0&&(f.words[f.length++]=g),this.length===0&&(this.words[0]=0,this.length=1),this._strip()},o.prototype.ishrn=function(r,u,m){return t(this.negative===0),this.iushrn(r,u,m)},o.prototype.shln=function(r){return this.clone().ishln(r)},o.prototype.ushln=function(r){return this.clone().iushln(r)},o.prototype.shrn=function(r){return this.clone().ishrn(r)},o.prototype.ushrn=function(r){return this.clone().iushrn(r)},o.prototype.testn=function(r){t(typeof r=="number"&&r>=0);var u=r%26,m=(r-u)/26,p=1<<u;if(this.length<=m)return!1;var h=this.words[m];return!!(h&p)},o.prototype.imaskn=function(r){t(typeof r=="number"&&r>=0);var u=r%26,m=(r-u)/26;if(t(this.negative===0,"imaskn works only with positive numbers"),this.length<=m)return this;if(u!==0&&m++,this.length=Math.min(m,this.length),u!==0){var p=67108863^67108863>>>u<<u;this.words[this.length-1]&=p}return this._strip()},o.prototype.maskn=function(r){return this.clone().imaskn(r)},o.prototype.iaddn=function(r){return t(typeof r=="number"),t(r<67108864),r<0?this.isubn(-r):this.negative!==0?this.length===1&&(this.words[0]|0)<=r?(this.words[0]=r-(this.words[0]|0),this.negative=0,this):(this.negative=0,this.isubn(r),this.negative=1,this):this._iaddn(r)},o.prototype._iaddn=function(r){this.words[0]+=r;for(var u=0;u<this.length&&this.words[u]>=67108864;u++)this.words[u]-=67108864,u===this.length-1?this.words[u+1]=1:this.words[u+1]++;return this.length=Math.max(this.length,u+1),this},o.prototype.isubn=function(r){if(t(typeof r=="number"),t(r<67108864),r<0)return this.iaddn(-r);if(this.negative!==0)return this.negative=0,this.iaddn(r),this.negative=1,this;if(this.words[0]-=r,this.length===1&&this.words[0]<0)this.words[0]=-this.words[0],this.negative=1;else for(var u=0;u<this.length&&this.words[u]<0;u++)this.words[u]+=67108864,this.words[u+1]-=1;return this._strip()},o.prototype.addn=function(r){return this.clone().iaddn(r)},o.prototype.subn=function(r){return this.clone().isubn(r)},o.prototype.iabs=function(){return this.negative=0,this},o.prototype.abs=function(){return this.clone().iabs()},o.prototype._ishlnsubmul=function(r,u,m){var p=r.length+m,h;this._expand(p);var T,w=0;for(h=0;h<r.length;h++){T=(this.words[h+m]|0)+w;var f=(r.words[h]|0)*u;T-=f&67108863,w=(T>>26)-(f/67108864|0),this.words[h+m]=T&67108863}for(;h<this.length-m;h++)T=(this.words[h+m]|0)+w,w=T>>26,this.words[h+m]=T&67108863;if(w===0)return this._strip();for(t(w===-1),w=0,h=0;h<this.length;h++)T=-(this.words[h]|0)+w,w=T>>26,this.words[h]=T&67108863;return this.negative=1,this._strip()},o.prototype._wordDiv=function(r,u){var m=this.length-r.length,p=this.clone(),h=r,T=h.words[h.length-1]|0,w=this._countBits(T);m=26-w,m!==0&&(h=h.ushln(m),p.iushln(m),T=h.words[h.length-1]|0);var f=p.length-h.length,c;if(u!=="mod"){c=new o(null),c.length=f+1,c.words=new Array(c.length);for(var g=0;g<c.length;g++)c.words[g]=0}var v=p.clone()._ishlnsubmul(h,1,f);v.negative===0&&(p=v,c&&(c.words[f]=1));for(var M=f-1;M>=0;M--){var O=(p.words[h.length+M]|0)*67108864+(p.words[h.length+M-1]|0);for(O=Math.min(O/T|0,67108863),p._ishlnsubmul(h,O,M);p.negative!==0;)O--,p.negative=0,p._ishlnsubmul(h,1,M),p.isZero()||(p.negative^=1);c&&(c.words[M]=O)}return c&&c._strip(),p._strip(),u!=="div"&&m!==0&&p.iushrn(m),{div:c||null,mod:p}},o.prototype.divmod=function(r,u,m){if(t(!r.isZero()),this.isZero())return{div:new o(0),mod:new o(0)};var p,h,T;return this.negative!==0&&r.negative===0?(T=this.neg().divmod(r,u),u!=="mod"&&(p=T.div.neg()),u!=="div"&&(h=T.mod.neg(),m&&h.negative!==0&&h.iadd(r)),{div:p,mod:h}):this.negative===0&&r.negative!==0?(T=this.divmod(r.neg(),u),u!=="mod"&&(p=T.div.neg()),{div:p,mod:T.mod}):(this.negative&r.negative)!==0?(T=this.neg().divmod(r.neg(),u),u!=="div"&&(h=T.mod.neg(),m&&h.negative!==0&&h.isub(r)),{div:T.div,mod:h}):r.length>this.length||this.cmp(r)<0?{div:new o(0),mod:this}:r.length===1?u==="div"?{div:this.divn(r.words[0]),mod:null}:u==="mod"?{div:null,mod:new o(this.modrn(r.words[0]))}:{div:this.divn(r.words[0]),mod:new o(this.modrn(r.words[0]))}:this._wordDiv(r,u)},o.prototype.div=function(r){return this.divmod(r,"div",!1).div},o.prototype.mod=function(r){return this.divmod(r,"mod",!1).mod},o.prototype.umod=function(r){return this.divmod(r,"mod",!0).mod},o.prototype.divRound=function(r){var u=this.divmod(r);if(u.mod.isZero())return u.div;var m=u.div.negative!==0?u.mod.isub(r):u.mod,p=r.ushrn(1),h=r.andln(1),T=m.cmp(p);return T<0||h===1&&T===0?u.div:u.div.negative!==0?u.div.isubn(1):u.div.iaddn(1)},o.prototype.modrn=function(r){var u=r<0;u&&(r=-r),t(r<=67108863);for(var m=(1<<26)%r,p=0,h=this.length-1;h>=0;h--)p=(m*p+(this.words[h]|0))%r;return u?-p:p},o.prototype.modn=function(r){return this.modrn(r)},o.prototype.idivn=function(r){var u=r<0;u&&(r=-r),t(r<=67108863);for(var m=0,p=this.length-1;p>=0;p--){var h=(this.words[p]|0)+m*67108864;this.words[p]=h/r|0,m=h%r}return this._strip(),u?this.ineg():this},o.prototype.divn=function(r){return this.clone().idivn(r)},o.prototype.egcd=function(r){t(r.negative===0),t(!r.isZero());var u=this,m=r.clone();u.negative!==0?u=u.umod(r):u=u.clone();for(var p=new o(1),h=new o(0),T=new o(0),w=new o(1),f=0;u.isEven()&&m.isEven();)u.iushrn(1),m.iushrn(1),++f;for(var c=m.clone(),g=u.clone();!u.isZero();){for(var v=0,M=1;(u.words[0]&M)===0&&v<26;++v,M<<=1);if(v>0)for(u.iushrn(v);v-- >0;)(p.isOdd()||h.isOdd())&&(p.iadd(c),h.isub(g)),p.iushrn(1),h.iushrn(1);for(var O=0,B=1;(m.words[0]&B)===0&&O<26;++O,B<<=1);if(O>0)for(m.iushrn(O);O-- >0;)(T.isOdd()||w.isOdd())&&(T.iadd(c),w.isub(g)),T.iushrn(1),w.iushrn(1);u.cmp(m)>=0?(u.isub(m),p.isub(T),h.isub(w)):(m.isub(u),T.isub(p),w.isub(h))}return{a:T,b:w,gcd:m.iushln(f)}},o.prototype._invmp=function(r){t(r.negative===0),t(!r.isZero());var u=this,m=r.clone();u.negative!==0?u=u.umod(r):u=u.clone();for(var p=new o(1),h=new o(0),T=m.clone();u.cmpn(1)>0&&m.cmpn(1)>0;){for(var w=0,f=1;(u.words[0]&f)===0&&w<26;++w,f<<=1);if(w>0)for(u.iushrn(w);w-- >0;)p.isOdd()&&p.iadd(T),p.iushrn(1);for(var c=0,g=1;(m.words[0]&g)===0&&c<26;++c,g<<=1);if(c>0)for(m.iushrn(c);c-- >0;)h.isOdd()&&h.iadd(T),h.iushrn(1);u.cmp(m)>=0?(u.isub(m),p.isub(h)):(m.isub(u),h.isub(p))}var v;return u.cmpn(1)===0?v=p:v=h,v.cmpn(0)<0&&v.iadd(r),v},o.prototype.gcd=function(r){if(this.isZero())return r.abs();if(r.isZero())return this.abs();var u=this.clone(),m=r.clone();u.negative=0,m.negative=0;for(var p=0;u.isEven()&&m.isEven();p++)u.iushrn(1),m.iushrn(1);do{for(;u.isEven();)u.iushrn(1);for(;m.isEven();)m.iushrn(1);var h=u.cmp(m);if(h<0){var T=u;u=m,m=T}else if(h===0||m.cmpn(1)===0)break;u.isub(m)}while(!0);return m.iushln(p)},o.prototype.invm=function(r){return this.egcd(r).a.umod(r)},o.prototype.isEven=function(){return(this.words[0]&1)===0},o.prototype.isOdd=function(){return(this.words[0]&1)===1},o.prototype.andln=function(r){return this.words[0]&r},o.prototype.bincn=function(r){t(typeof r=="number");var u=r%26,m=(r-u)/26,p=1<<u;if(this.length<=m)return this._expand(m+1),this.words[m]|=p,this;for(var h=p,T=m;h!==0&&T<this.length;T++){var w=this.words[T]|0;w+=h,h=w>>>26,w&=67108863,this.words[T]=w}return h!==0&&(this.words[T]=h,this.length++),this},o.prototype.isZero=function(){return this.length===1&&this.words[0]===0},o.prototype.cmpn=function(r){var u=r<0;if(this.negative!==0&&!u)return-1;if(this.negative===0&&u)return 1;this._strip();var m;if(this.length>1)m=1;else{u&&(r=-r),t(r<=67108863,"Number is too big");var p=this.words[0]|0;m=p===r?0:p<r?-1:1}return this.negative!==0?-m|0:m},o.prototype.cmp=function(r){if(this.negative!==0&&r.negative===0)return-1;if(this.negative===0&&r.negative!==0)return 1;var u=this.ucmp(r);return this.negative!==0?-u|0:u},o.prototype.ucmp=function(r){if(this.length>r.length)return 1;if(this.length<r.length)return-1;for(var u=0,m=this.length-1;m>=0;m--){var p=this.words[m]|0,h=r.words[m]|0;if(p!==h){p<h?u=-1:p>h&&(u=1);break}}return u},o.prototype.gtn=function(r){return this.cmpn(r)===1},o.prototype.gt=function(r){return this.cmp(r)===1},o.prototype.gten=function(r){return this.cmpn(r)>=0},o.prototype.gte=function(r){return this.cmp(r)>=0},o.prototype.ltn=function(r){return this.cmpn(r)===-1},o.prototype.lt=function(r){return this.cmp(r)===-1},o.prototype.lten=function(r){return this.cmpn(r)<=0},o.prototype.lte=function(r){return this.cmp(r)<=0},o.prototype.eqn=function(r){return this.cmpn(r)===0},o.prototype.eq=function(r){return this.cmp(r)===0},o.red=function(r){return new 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 mn={k256:null,p224:null,p192:null,p25519:null};function Nt(y,r){this.name=y,this.p=new o(r,16),this.n=this.p.bitLength(),this.k=new o(1).iushln(this.n).isub(this.p),this.tmp=this._tmp()}Nt.prototype._tmp=function(){var r=new o(null);return r.words=new Array(Math.ceil(this.n/13)),r},Nt.prototype.ireduce=function(r){var u=r,m;do this.split(u,this.tmp),u=this.imulK(u),u=u.iadd(this.tmp),m=u.bitLength();while(m>this.n);var p=m<this.n?-1:u.ucmp(this.p);return p===0?(u.words[0]=0,u.length=1):p>0?u.isub(this.p):u.strip!==void 0?u.strip():u._strip(),u},Nt.prototype.split=function(r,u){r.iushrn(this.n,0,u)},Nt.prototype.imulK=function(r){return r.imul(this.k)};function Kn(){Nt.call(this,"k256","ffffffff ffffffff ffffffff ffffffff ffffffff ffffffff fffffffe fffffc2f")}n(Kn,Nt),Kn.prototype.split=function(r,u){for(var m=4194303,p=Math.min(r.length,9),h=0;h<p;h++)u.words[h]=r.words[h];if(u.length=p,r.length<=9){r.words[0]=0,r.length=1;return}var T=r.words[9];for(u.words[u.length++]=T&m,h=10;h<r.length;h++){var w=r.words[h]|0;r.words[h-10]=(w&m)<<4|T>>>22,T=w}T>>>=22,r.words[h-10]=T,T===0&&r.length>10?r.length-=10:r.length-=9},Kn.prototype.imulK=function(r){r.words[r.length]=0,r.words[r.length+1]=0,r.length+=2;for(var u=0,m=0;m<r.length;m++){var p=r.words[m]|0;u+=p*977,r.words[m]=u&67108863,u=p*64+(u/67108864|0)}return r.words[r.length-1]===0&&(r.length--,r.words[r.length-1]===0&&r.length--),r};function Qs(){Nt.call(this,"p224","ffffffff ffffffff ffffffff ffffffff 00000000 00000000 00000001")}n(Qs,Nt);function Js(){Nt.call(this,"p192","ffffffff ffffffff ffffffff fffffffe ffffffff ffffffff")}n(Js,Nt);function Rr(){Nt.call(this,"25519","7fffffffffffffff ffffffffffffffff ffffffffffffffff ffffffffffffffed")}n(Rr,Nt),Rr.prototype.imulK=function(r){for(var u=0,m=0;m<r.length;m++){var p=(r.words[m]|0)*19+u,h=p&67108863;p>>>=26,r.words[m]=h,u=p}return u!==0&&(r.words[r.length++]=u),r},o._prime=function(r){if(mn[r])return mn[r];var u;if(r==="k256")u=new Kn;else if(r==="p224")u=new Qs;else if(r==="p192")u=new Js;else if(r==="p25519")u=new Rr;else throw new Error("Unknown prime "+r);return mn[r]=u,u};function V(y){if(typeof y=="string"){var r=o._prime(y);this.m=r.p,this.prime=r}else t(y.gtn(1),"modulus must be greater than 1"),this.m=y,this.prime=null}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,u){t((r.negative|u.negative)===0,"red works only with positives"),t(r.red&&r.red===u.red,"red works only with red numbers")},V.prototype.imod=function(r){return this.prime?this.prime.ireduce(r)._forceRed(this):(b(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,u){this._verify2(r,u);var m=r.add(u);return m.cmp(this.m)>=0&&m.isub(this.m),m._forceRed(this)},V.prototype.iadd=function(r,u){this._verify2(r,u);var m=r.iadd(u);return m.cmp(this.m)>=0&&m.isub(this.m),m},V.prototype.sub=function(r,u){this._verify2(r,u);var m=r.sub(u);return m.cmpn(0)<0&&m.iadd(this.m),m._forceRed(this)},V.prototype.isub=function(r,u){this._verify2(r,u);var m=r.isub(u);return m.cmpn(0)<0&&m.iadd(this.m),m},V.prototype.shl=function(r,u){return this._verify1(r),this.imod(r.ushln(u))},V.prototype.imul=function(r,u){return this._verify2(r,u),this.imod(r.imul(u))},V.prototype.mul=function(r,u){return this._verify2(r,u),this.imod(r.mul(u))},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 u=this.m.andln(3);if(t(u%2===1),u===3){var m=this.m.add(new o(1)).iushrn(2);return this.pow(r,m)}for(var p=this.m.subn(1),h=0;!p.isZero()&&p.andln(1)===0;)h++,p.iushrn(1);t(!p.isZero());var T=new o(1).toRed(this),w=T.redNeg(),f=this.m.subn(1).iushrn(1),c=this.m.bitLength();for(c=new o(2*c*c).toRed(this);this.pow(c,f).cmp(w)!==0;)c.redIAdd(w);for(var g=this.pow(c,p),v=this.pow(r,p.addn(1).iushrn(1)),M=this.pow(r,p),O=h;M.cmp(T)!==0;){for(var B=M,N=0;B.cmp(T)!==0;N++)B=B.redSqr();t(N<O);var L=this.pow(g,new o(1).iushln(O-N-1));v=v.redMul(L),g=L.redSqr(),M=M.redMul(g),O=N}return v},V.prototype.invm=function(r){var u=r._invmp(this.m);return u.negative!==0?(u.negative=0,this.imod(u).redNeg()):this.imod(u)},V.prototype.pow=function(r,u){if(u.isZero())return new o(1).toRed(this);if(u.cmpn(1)===0)return r.clone();var m=4,p=new Array(1<<m);p[0]=new o(1).toRed(this),p[1]=r;for(var h=2;h<p.length;h++)p[h]=this.mul(p[h-1],r);var T=p[0],w=0,f=0,c=u.bitLength()%26;for(c===0&&(c=26),h=u.length-1;h>=0;h--){for(var g=u.words[h],v=c-1;v>=0;v--){var M=g>>v&1;if(T!==p[0]&&(T=this.sqr(T)),M===0&&w===0){f=0;continue}w<<=1,w|=M,f++,!(f!==m&&(h!==0||v!==0))&&(T=this.mul(T,p[w]),f=0,w=0)}c=26}return T},V.prototype.convertTo=function(r){var u=r.umod(this.m);return u===r?u.clone():u},V.prototype.convertFrom=function(r){var u=r.clone();return u.red=null,u},o.mont=function(r){return new Pe(r)};function Pe(y){V.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,V),Pe.prototype.convertTo=function(r){return this.imod(r.ushln(this.shift))},Pe.prototype.convertFrom=function(r){var u=this.imod(r.mul(this.rinv));return u.red=null,u},Pe.prototype.imul=function(r,u){if(r.isZero()||u.isZero())return r.words[0]=0,r.length=1,r;var m=r.imul(u),p=m.maskn(this.shift).mul(this.minv).imaskn(this.shift).mul(this.m),h=m.isub(p).iushrn(this.shift),T=h;return h.cmp(this.m)>=0?T=h.isub(this.m):h.cmpn(0)<0&&(T=h.iadd(this.m)),T._forceRed(this)},Pe.prototype.mul=function(r,u){if(r.isZero()||u.isZero())return new o(0)._forceRed(this);var m=r.mul(u),p=m.maskn(this.shift).mul(this.minv).imaskn(this.shift).mul(this.m),h=m.isub(p).iushrn(this.shift),T=h;return h.cmp(this.m)>=0?T=h.isub(this.m):h.cmpn(0)<0&&(T=h.iadd(this.m)),T._forceRed(this)},Pe.prototype.invm=function(r){var u=this.imod(r._invmp(this.m).mul(this.r2));return u._forceRed(this)}})(typeof $s>"u"||$s,Sp)});var Df={};Yr(Df,{appHelpers:()=>xf});module.exports=fd(Df);var wc=require("@msafe/sui3-utils");var ae=require("@alphafi/alphafi-sdk"),Fe=require("@msafe/sui3-utils"),Jt=require("@mysten/bcs");var $n=class{constructor(e,t){this.transaction=e;this.simResult=t}decode(){if(this.isClaimRewardTransaction())return this.decodeClaimReward();let e=this.getLiquidityChangeEvent();if(!e)throw new Error("No liquidity change event found. Unable to decode transaction.");let t=e.parsedJson,n=t.pool_id,o=ae.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&&ae.poolInfo[t].assetTypes.length===2}isSingleAssetDepositEvent(e,t){return e.event_type===0&&ae.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:Fe.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}=ae.singleAssetPoolCoinMap[e],{expo:s}=ae.coinsList[i];n=Math.floor(Number(n)/10**(9-s)).toString()}return{txType:Fe.TransactionType.Other,type:"depositSingleAsset",intentionData:{poolName:e,amount:n}}}decodeWithdraw(e){let t=this.extractXTokensAmount();return console.log("Decoder.decodeWithdraw",t),{txType:Fe.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:Fe.TransactionType.Other,type:"withdrawAlpha",intentionData:{withdrawFromLocked:Number(n)>0,xTokensAmount:t}}}decodeClaimReward(){return{txType:Fe.TransactionType.Other,type:"claimReward",intentionData:{}}}};var yc=require("@alphafi/alphafi-sdk");var gc=qt(require("sort-keys-recursive")),S=class{constructor(e){this.data=e}serialize(){return JSON.stringify((0,gc.default)(this.data))}};var Hn=class a extends S{constructor(t){super(t);this.data=t}txType;txSubType;async build(t){let{account:n}=t;return await(0,yc.claimRewardTxb)(n.address)}static fromData(t){return new a(t)}};var bc=require("@alphafi/alphafi-sdk");var Xn=class a extends S{constructor(t){super(t);this.data=t}txType;txSubType;async build(t){let{account:n}=t,{poolName:o,amount:i,isAmountA:s}=this.data;return await(0,bc.depositDoubleAssetTxb)(o,n.address,i,s)}static fromData(t){return console.log("DepositDoubleAssetIntention.fromData",t),new a(t)}};var Tc=require("@alphafi/alphafi-sdk");var zn=class a extends S{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,Tc.depositSingleAssetTxb)(o,n.address,i)}static fromData(t){return console.log("DepositSingleAssetIntention.fromData",t),new a(t)}};var Sc=require("@alphafi/alphafi-sdk");var Gn=class a extends S{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,Sc.withdrawTxb)(i,o,n.address)}static fromData(t){return console.log("WithdrawIntention.fromData",t),new a(t)}};var Ic=require("@alphafi/alphafi-sdk");var Qn=class a extends S{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,Ic.withdrawAlphaTxb)(i,o,n.address)}static fromData(t){return console.log("WithdrawAlphaIntention.fromData",t),new a(t)}};var Jn=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 l=new $n(t,i).decode();return{txType:wc.TransactionType.Other,txSubType:l.type,intentionData:l.intentionData}}async build(e){let{account:t}=e;console.log("AlphaFi build transaction type",e.txSubType);let n;switch(e.txSubType){case"depositSingleAsset":n=zn.fromData(e.intentionData);break;case"depositDoubleAsset":n=Xn.fromData(e.intentionData);break;case"withdraw":n=Gn.fromData(e.intentionData);break;case"withdrawAlpha":n=Qn.fromData(e.intentionData);break;case"claimReward":n=Hn.fromData(e.intentionData);break;default:throw new Error("not implemented")}return n.build({account:t})}};var Xc=require("@msafe/sui3-utils");var _t=require("@msafe/sui3-utils"),Yn=require("@mysten/sui/bcs"),Zn=require("bucket-protocol-sdk");var to=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(Zn.SBUCK_FOUNTAIN_PACKAGE_ID,"fountain_core","stake")}isSBUCKUnstakeTransaction(){return!!this.getMoveCallPackageModuleCommand(Zn.SBUCK_FOUNTAIN_PACKAGE_ID,"fountain_core","force_unstake")}isSBUCKClaimTransaction(){return!!this.getMoveCallPackageModuleCommand(Zn.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:_t.TransactionType.Other,type:"psm",intentionData:{coinType:e,amount:n,buckToCoin:t}}}decodeBorrow(){let e="",t="0",n,o=this.getStrapId(),i="0",s=this.getSplitCoinsCommands()[0].SplitCoins.amounts[0];if(s.$kind==="Input"&&(i=this.getPureInputU64(s.Input)),this.getMoveCallCommand("high_top_up")){let l=this.getMoveCallCommand("high_top_up").MoveCall;[e]=l.typeArguments;let d=l.arguments[1];d.$kind==="Input"&&(t=this.getPureInputU64(d.Input));let b=l.arguments[3];if(b.$kind==="Input"){let I=this.getPureAddresses(b.Input);I.length===1&&([n]=I)}}else if(this.getMoveCallCommand("high_borrow")){let l=this.getMoveCallCommand("high_borrow").MoveCall;[e]=l.typeArguments;let d=l.arguments[4];d.$kind==="Input"&&(t=this.getPureInputU64(d.Input));let b=l.arguments[5];if(b.$kind==="Input"){let I=this.getPureAddresses(b.Input);I.length===1&&([n]=I)}}else if(this.getMoveCallCommand("high_borrow_with_strap")){let l=this.getMoveCallCommand("high_borrow_with_strap").MoveCall;[e]=l.typeArguments;let d=l.arguments[5];d.$kind==="Input"&&(t=this.getPureInputU64(d.Input));let b=l.arguments[6];if(b.$kind==="Input"){let I=this.getPureAddresses(b.Input);I.length===1&&([n]=I)}}return{txType:_t.TransactionType.Other,type:"borrow",intentionData:{collateralType:e,collateralAmount:i,borrowAmount:t,insertionPlace:n,strapId:o}}}decodeRepay(){let e="",t="0",n="0",i,s=this.getStrapId();if(this.getMoveCallCommand("fully_repay"))[e]=this.getMoveCallCommand("fully_repay").MoveCall.typeArguments;else if(this.getMoveCallCommand("fully_repay_with_strap"))[e]=this.getMoveCallCommand("fully_repay_with_strap").MoveCall.typeArguments;else if(this.getMoveCallCommand("repay_and_withdraw")){let l=this.getMoveCallCommand("repay_and_withdraw").MoveCall;[e]=l.typeArguments;let d=l.arguments[4];d.$kind==="Input"&&(n=this.getPureInputU64(d.Input));let b=l.arguments[5];if(b.$kind==="Input"){let C=this.getPureAddresses(b.Input);C.length===1&&([i]=C)}let I=this.getSplitCoinsCommands()[0].SplitCoins.amounts[0];I.$kind==="Input"&&(t=this.getPureInputU64(I.Input))}else if(this.getMoveCallCommand("repay_and_withdraw_with_strap")){let l=this.getMoveCallCommand("repay_and_withdraw_with_strap").MoveCall;[e]=l.typeArguments;let d=l.arguments[5];d.$kind==="Input"&&(n=this.getPureInputU64(d.Input));let b=l.arguments[6];if(b.$kind==="Input"){let C=this.getPureAddresses(b.Input);C.length===1&&([i]=C)}let I=this.getSplitCoinsCommands()[0].SplitCoins.amounts[0];I.$kind==="Input"&&(t=this.getPureInputU64(I.Input))}return{txType:_t.TransactionType.Other,type:"repay",intentionData:{collateralType:e,repayAmount:t,withdrawAmount:n,isSurplus:!1,insertionPlace:i,strapId:s}}}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 s=i.arguments[4];s.$kind==="Input"&&(t=this.getPureInputU64(s.Input));let l=i.arguments[5];if(l.$kind==="Input"){let d=this.getPureAddresses(l.Input);d.length===1&&([n]=d)}}else if(this.getMoveCallCommand("withdraw")){let i=this.getMoveCallCommand("withdraw").MoveCall;[e]=i.typeArguments;let s=i.arguments[3];s.$kind==="Input"&&(t=this.getPureInputU64(s.Input));let l=i.arguments[4];if(l.$kind==="Input"){let d=this.getPureAddresses(l.Input);d.length===1&&([n]=d)}}return{txType:_t.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:_t.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 s=this.isSBUCKStakeTransaction();return console.log("Decoder.decodeSBUCKDeposit",t,n,s),{txType:_t.TransactionType.Other,type:"sbuck-deposit",intentionData:{coinType:t,amount:n,isStake:s}}}decodeSBUCKUnstake(){let e="0",t=this.isSBUCKStakeTransaction();if(t){let d=this.getSplitCoinsCommands()[0].SplitCoins.amounts[0];d.$kind==="Input"&&(e=this.getPureInputU64(d.Input))}let n=[],o=this.getMoveCallModuleCommands("proof_rule","unlock");if(o.length>0)for(let l=0;l<o.length;l++){let d=o[l];n.push("")}else{let l=this.getMoveCallModuleCommands("fountain_core","force_unstake");for(let d=0;d<l.length;d++){let I=l[d].MoveCall.arguments[2];if(I.$kind==="Input"){let{objectId:C}=this.inputs[I.Input].UnresolvedObject;n.push(C)}}}let i=this.isSBUCKWithdrawTransaction(),s={stakeProofs:n,amount:e,isStake:t,toBuck:i};return console.log("Decoder.decodeSBUCKUnstake",s),{txType:_t.TransactionType.Other,type:"sbuck-unstake",intentionData:s}}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:_t.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:s}=this.inputs[i.Input].UnresolvedObject;e.push(s)}}return console.log("Decoder.decodeSBUCKClaim",e),{txType:_t.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:_t.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:_t.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:_t.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:_t.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 Yn.bcs.U64.fromBase64(t.Pure.bytes)}getPureAddresses(e){let t=this.inputs[e];if(t.$kind!=="Pure")throw new Error("not pure argument");return Yn.bcs.vector(Yn.bcs.Address).fromBase64(t.Pure.bytes)}};var vc=require("@msafe/sui3-utils");var xc=require("@mysten/sui/transactions"),Dc=require("bucket-protocol-sdk");var Cc=require("bucket-protocol-sdk"),Pt=(a,e)=>{let t=a==="sui:mainnet"?"mainnet":"testnet";return new Cc.BucketClient(t,e.address)};var kc=async(a,e,t)=>{let{coinType:n,amount:o,buckToCoin:i}=a,s=new xc.Transaction,l=Pt(t,e);return await(0,Dc.buildPsmTx)(l,s,n,o,i,e.address),s};var eo=class a extends S{constructor(t){super(t);this.data=t}txType=vc.TransactionType.Other;txSubType="psm";async build(t){let{account:n,network:o}=t;return await kc(this.data,n,o)}static fromData(t){return new a(t)}};var Rc=require("@msafe/sui3-utils");var pn=require("@mysten/sui/transactions"),me=require("bucket-protocol-sdk");var Ac=async(a,e,t)=>{let{collateralType:n,collateralAmount:o,borrowAmount:i,insertionPlace:s,strapId:l}=a,d=new pn.Transaction,b=Pt(t,e);return await(0,me.buildBorrowTx)(b,d,n,o,i,e.address,s,l),d},Mc=async(a,e,t)=>{let{collateralType:n,withdrawAmount:o,insertionPlace:i,strapId:s}=a,l=new pn.Transaction,d=Pt(t,e);return await(0,me.buildWithdrawTx)(d,l,n,o,e.address,i,s),l},Oc=async(a,e,t)=>{let{collateralType:n,repayAmount:o,withdrawAmount:i,isSurplus:s,insertionPlace:l,strapId:d}=a,b=new pn.Transaction,I=Pt(t,e);return await(0,me.buildRepayTx)(I,b,n,o,i,e.address,s,l,d),b},Pc=async(a,e,t)=>{let{collateralType:n,recipient:o,strapId:i}=a,s=new pn.Transaction,l=Pt(t,e);return await(0,me.buildCloseTx)(l,s,n,o,i),s};var no=class a extends S{constructor(t){super(t);this.data=t}txType=Rc.TransactionType.Other;txSubType="borrow";async build(t){let{account:n,network:o}=t;return await Ac(this.data,n,o)}static fromData(t){return new a(t)}};var Bc=require("@msafe/sui3-utils");var oo=class a extends S{constructor(t){super(t);this.data=t}txType=Bc.TransactionType.Other;txSubType="repay";async build(t){let{account:n,network:o}=t;return await Oc(this.data,n,o)}static fromData(t){return new a(t)}};var Ec=require("@msafe/sui3-utils");var ao=class a extends S{constructor(t){super(t);this.data=t}txType=Ec.TransactionType.Other;txSubType="withdraw";async build(t){let{account:n,network:o}=t;return await Mc(this.data,n,o)}static fromData(t){return new a(t)}};var Wc=require("@msafe/sui3-utils");var io=class a extends S{constructor(t){super(t);this.data=t}txType=Wc.TransactionType.Other;txSubType="close";async build(t){let{account:n,network:o}=t;return await Pc(this.data,n,o)}static fromData(t){return new a(t)}};var fn=require("@msafe/sui3-utils");var dn=require("@mysten/sui/transactions"),pe=require("bucket-protocol-sdk");var Nc=async(a,e,t)=>{let{coinType:n,amount:o,isStake:i}=a,s=new dn.Transaction,l=Pt(t,e);return await(0,pe.buildSBUCKDepositTx)(l,s,n,o,e.address,i),s},_c=async(a,e,t)=>{let{stakeProofs:n,amount:o,isStake:i,toBuck:s}=a,l=new dn.Transaction,d=Pt(t,e);return await(0,pe.buildSBUCKUnstakeTx)(d,l,n,o,e.address,i,s),l},Lc=async(a,e,t)=>{let{amount:n}=a,o=new dn.Transaction,i=Pt(t,e);return await(0,pe.buildSBUCKWithdrawTx)(i,o,n,e.address),o},jc=async(a,e,t)=>{let{stakeProofs:n}=a,o=new dn.Transaction,i=Pt(t,e);return await(0,pe.buildSBUCKClaimTx)(i,o,n,e.address),o};var ro=class a extends S{constructor(t){super(t);this.data=t}txType=fn.TransactionType.Other;txSubType="sbuck-deposit";async build(t){let{account:n,network:o}=t;return await Nc(this.data,n,o)}static fromData(t){return new a(t)}},so=class a extends S{constructor(t){super(t);this.data=t}txType=fn.TransactionType.Other;txSubType="sbuck-unstake";async build(t){let{account:n,network:o}=t;return await _c(this.data,n,o)}static fromData(t){return new a(t)}},co=class a extends S{constructor(t){super(t);this.data=t}txType=fn.TransactionType.Other;txSubType="sbuck-withdraw";async build(t){let{account:n,network:o}=t;return await Lc(this.data,n,o)}static fromData(t){return new a(t)}},lo=class a extends S{constructor(t){super(t);this.data=t}txType=fn.TransactionType.Other;txSubType="sbuck-claim";async build(t){let{account:n,network:o}=t;return await jc(this.data,n,o)}static fromData(t){return new a(t)}};var ho=require("@msafe/sui3-utils");var uo=require("@mysten/sui/transactions"),Ke=require("bucket-protocol-sdk");var Uc=async(a,e,t)=>{let{coinType:n,amount:o}=a,i=new uo.Transaction,s=Pt(t,e);return await(0,Ke.buildTankDepositTx)(s,i,n,o,e.address),i},qc=async(a,e,t)=>{let{coinType:n,amount:o}=a,i=new uo.Transaction,s=Pt(t,e);return await(0,Ke.buildTankWithdrawTx)(s,i,n,o,e.address),i},Fc=async(a,e,t)=>{let{coinType:n}=a,o=new uo.Transaction,i=Pt(t,e);return await(0,Ke.buildTankClaimTx)(i,o,n,e.address),o};var Kc=require("@mysten/sui/transactions"),Vc=require("bucket-protocol-sdk");var $c=async(a,e,t)=>{let{coinType:n,proofCount:o}=a,i=new Kc.Transaction,s=Pt(t,e);return await(0,Vc.buildLockedClaimTx)(s,i,n,o,e.address),i};var mo=class a extends S{constructor(t){super(t);this.data=t}txType=ho.TransactionType.Other;txSubType="tank-deposit";async build(t){let{account:n,network:o}=t;return await Uc(this.data,n,o)}static fromData(t){return new a(t)}},po=class a extends S{constructor(t){super(t);this.data=t}txType=ho.TransactionType.Other;txSubType="tank-withdraw";async build(t){let{account:n,network:o}=t;return await qc(this.data,n,o)}static fromData(t){return new a(t)}},fo=class a extends S{constructor(t){super(t);this.data=t}txType=ho.TransactionType.Other;txSubType="tank-claim";async build(t){let{account:n,network:o}=t;return await Fc(this.data,n,o)}static fromData(t){return new a(t)}};var Hc=require("@msafe/sui3-utils");var go=class a extends S{constructor(t){super(t);this.data=t}txType=Hc.TransactionType.Other;txSubType="lock-claim";async build(t){let{account:n,network:o}=t;return await $c(this.data,n,o)}static fromData(t){return new a(t)}};var yo=class{application="bucket";supportSDK="@mysten/sui";async deserialize(e){console.log("Bucket helper deserialize input: ",e);let{transaction:t}=e,o=new to(t).decode();return{txType:Xc.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=eo.fromData(e.intentionData);break;case"borrow":i=no.fromData(e.intentionData);break;case"withdraw":i=ao.fromData(e.intentionData);break;case"repay":i=oo.fromData(e.intentionData);break;case"close":i=io.fromData(e.intentionData);break;case"tank-deposit":i=mo.fromData(e.intentionData);break;case"tank-withdraw":i=po.fromData(e.intentionData);break;case"tank-claim":i=fo.fromData(e.intentionData);break;case"sbuck-deposit":i=ro.fromData(e.intentionData);break;case"sbuck-unstake":i=so.fromData(e.intentionData);break;case"sbuck-withdraw":i=co.fromData(e.intentionData);break;case"sbuck-claim":i=lo.fromData(e.intentionData);break;case"lock-claim":i=go.fromData(e.intentionData);break;default:throw new Error("not implemented")}return i.build({suiClient:t,account:n,network:o})}};var tu=require("@msafe/sui3-utils");var il=require("@msafe/sui3-utils");var bo=require("@cetusprotocol/aggregator-sdk"),zc=require("@cetusprotocol/farms-sdk"),Gc=require("@cetusprotocol/sui-clmm-sdk"),Qc=require("@cetusprotocol/vaults-sdk"),Jc=require("@cetusprotocol/xcetus-sdk"),Re=require("@mysten/sui/client"),Yt=(a,e)=>{let t=Gc.CetusClmmSDK.createSDK({env:"mainnet",sui_client:new Re.SuiClient({url:(0,Re.getFullnodeUrl)("mainnet")})});return t.setSenderAddress(e.address),t},Ft=(a,e)=>{let t=zc.CetusFarmsSDK.createSDK({env:"mainnet",sui_client:new Re.SuiClient({url:(0,Re.getFullnodeUrl)("mainnet")})});return t.setSenderAddress(e.address),t},gd="https://api-sui.cetus.zone/router_v2/find_routes",Yc=(a,e)=>{let t=new Re.SuiClient({url:"https://fullnode.mainnet.sui.io/"});return new bo.AggregatorClient({endpoint:gd,signer:e.address,client:t,env:bo.Env.Mainnet})},hn=(a,e)=>{let t=Qc.CetusVaultsSDK.createSDK({env:"mainnet"});return t.setSenderAddress(e.address),t},Ve=(a,e)=>{let t=Jc.CetusXcetusSDK.createSDK({env:"mainnet"});return t.setSenderAddress(e.address),t};var Zc=async(a,e,t)=>await Yt(t,e).Pool.createPoolPayload(a),tl=async(a,e,t)=>await Yt(t,e).Position.createAddLiquidityFixTokenPayload(a?.parameter,a?.gasEstimateArg),el=async(a,e,t)=>await Yt(t,e).Position.createAddLiquidityFixTokenPayload(a?.parameter,a?.gasEstimateArg),nl=async(a,e,t)=>await Yt(t,e).Position.closePositionPayload(a),ol=async(a,e,t)=>await Yt(t,e).Position.removeLiquidityPayload(a),al=async(a,e,t)=>await Yt(t,e).Rewarder.collectRewarderPayload(a);var To=class a extends S{constructor(t){super(t);this.data=t}txType=il.TransactionType.Other;txSubType="OpenAndAddLiquidity";async build(t){let{account:n,network:o}=t,{txbParams:i}=this.data;return await tl(i,n,o)}static fromData(t){return new a(t)}};var rl=require("@msafe/sui3-utils");var So=class a extends S{constructor(t){super(t);this.data=t}txType=rl.TransactionType.Other;txSubType="ClaimFeeAndMining";async build(t){let{account:n,network:o}=t,{txbParams:i}=this.data;return await al(i,n,o)}static fromData(t){return new a(t)}};var sl=require("@msafe/sui3-utils");var Io=class a extends S{constructor(t){super(t);this.data=t}txType=sl.TransactionType.Other;txSubType="CreatePool";async build(t){let{account:n,network:o}=t,{txbParams:i}=this.data;return await Zc(i,n,o)}static fromData(t){return new a(t)}};var cl=require("@msafe/sui3-utils");var wo=class a extends S{constructor(t){super(t);this.data=t}txType=cl.TransactionType.Other;txSubType="DecreaseLiquidity";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 bl=require("@msafe/sui3-utils");var ll=async(a,e,t)=>await Ft(t,e).Farms.openPositionAddLiquidityStakePayload(a),ul=async(a,e,t)=>await Ft(t,e).Farms.addLiquidityFixCoinPayload(a),ml=async(a,e,t)=>await Ft(t,e).Farms.removeLiquidityPayload(a),pl=async(a,e,t)=>await Ft(t,e).Farms.removeLiquidityPayload(a),dl=async(a,e,t)=>await Ft(t,e).Farms.claimFeeAndClmmReward(a),fl=async(a,e,t)=>await Ft(t,e).Farms.harvestPayload(a),hl=async(a,e,t)=>{let n=Ft(t,e),o=Object.values(a);return await n.Farms.batchHarvestPayload(o)},gl=async(a,e,t)=>await Ft(t,e).Farms.depositPayload(a),yl=async(a,e,t)=>await Ft(t,e).Farms.withdrawPayload(a);var Co=class a extends S{constructor(t){super(t);this.data=t}txType=bl.TransactionType.Other;txSubType="FarmingOpenAndAddLiquidity";async build(t){let{account:n,network:o}=t,{txbParams:i}=this.data;return await ll(i,n,o)}static fromData(t){return new a(t)}};var Tl=require("@msafe/sui3-utils");var xo=class a extends S{constructor(t){super(t);this.data=t}txType=Tl.TransactionType.Other;txSubType="FarmingBatchHarvest";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 Sl=require("@msafe/sui3-utils");var Do=class a extends S{constructor(t){super(t);this.data=t}txType=Sl.TransactionType.Other;txSubType="FarmingClaimFeeAndReward";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 Il=require("@msafe/sui3-utils");var ko=class a extends S{constructor(t){super(t);this.data=t}txType=Il.TransactionType.Other;txSubType="FarmingDecreaseLiquidity";async build(t){let{account:n,network:o}=t,{txbParams:i}=this.data;return await ml(i,n,o)}static fromData(t){return new a(t)}};var wl=require("@msafe/sui3-utils");var vo=class a extends S{constructor(t){super(t);this.data=t}txType=wl.TransactionType.Other;txSubType="FarmingHarvest";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 Cl=require("@msafe/sui3-utils");var Ao=class a extends S{constructor(t){super(t);this.data=t}txType=Cl.TransactionType.Other;txSubType="FarmingIncreaseLiquidity";async build(t){let{account:n,network:o}=t,{txbParams:i}=this.data;return await ul(i,n,o)}static fromData(t){return new a(t)}};var xl=require("@msafe/sui3-utils");var Mo=class a extends S{constructor(t){super(t);this.data=t}txType=xl.TransactionType.Other;txSubType="FarmingRemoveLiquidity";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 Dl=require("@msafe/sui3-utils");var Oo=class a extends S{constructor(t){super(t);this.data=t}txType=Dl.TransactionType.Other;txSubType="FarmingStake";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 kl=require("@msafe/sui3-utils");var Po=class a extends S{constructor(t){super(t);this.data=t}txType=kl.TransactionType.Other;txSubType="FarmingUnstake";async build(t){let{account:n,network:o}=t,{txbParams:i}=this.data;return await yl(i,n,o)}static fromData(t){return new a(t)}};var vl=require("@msafe/sui3-utils");var Ro=class a extends S{constructor(t){super(t);this.data=t}txType=vl.TransactionType.Other;txSubType="IncreaseLiquidity";async build(t){let{account:n,network:o}=t,{txbParams:i}=this.data;return await el(i,n,o)}static fromData(t){return new a(t)}};var Ol=require("@msafe/sui3-utils");var gn=require("@mysten/sui/transactions"),Bo=qt(require("haedal-vault-sdk"));var yd=async(a,e,t)=>{let n=hn(t,e),o=new gn.Transaction;return o.setSender(e.address),n.Vest.buildRedeemPayload(a.params,o),o},bd=async(a,e,t)=>{let n=new Bo.default(Bo.vaults_mainnet);n.senderAddress=e.address;let o=new gn.Transaction;return o.setSender(e.address),await n?.Vest.buildRedeemPayload(a.params,o),o},Al=(a,e,t)=>{let n=Yt(t,e),o=new gn.Transaction;return n?.Vest.buildRedeemPayload(a.params,o),o},Td=async(a,e,t)=>{let n=Yt(t,e),o=Ft(t,e),i=new gn.Transaction,s=await o.Farms.withdrawReturnPayload(a.withdrawParams,i);return n.Vest.buildRedeemPayload(a.redeemParms.map(l=>({...l,clmm_position_id:s})),i),o.Farms.depositPayload({...a.depositParams,clmm_position_id:s},i),i},Ml=async(a,e,t)=>a.type==="clmm"?Al(a,e,t):a.type==="farms"?Td(a,e,t):a.type==="vaults"?yd(a,e,t):a.type==="haedalVaults"?bd(a,e,t):Al(a,e,t);var Eo=class a extends S{constructor(t){super(t);this.data=t}txType=Ol.TransactionType.Other;txSubType="PosVestingRedeem";async build(t){let{account:n,network:o}=t,{txbParams:i}=this.data;return await Ml(i,n,o)}static fromData(t){return new a(t)}};var Pl=require("@msafe/sui3-utils");var Wo=class a extends S{constructor(t){super(t);this.data=t}txType=Pl.TransactionType.Other;txSubType="RemoveLiquidity";async build(t){let{account:n,network:o}=t,{txbParams:i}=this.data;return await nl(i,n,o)}static fromData(t){return new a(t)}};var Wl=require("@msafe/sui3-utils");var Rl=require("@cetusprotocol/aggregator-sdk"),Bl=require("@mysten/sui/transactions");var El=async(a,e,t)=>{let n=Yc(t,e),o=new Bl.Transaction;return await n.fastRouterSwap({...a,router:(0,Rl.restituteMsafeFastRouterSwapParams)(a.router),txb:o}),o};var No=class a extends S{constructor(t){super(t);this.data=t}txType=Wl.TransactionType.Other;txSubType="AggregatorSwap";async build(t){let{account:n,network:o}=t,{txbParams:i}=this.data;return await El(i,n,o)}static fromData(t){return new a(t)}};var Ll=require("@msafe/sui3-utils");var Zr=require("@mysten/sui/transactions");var Nl=async(a,e,t)=>{let n=hn(t,e),o=new Zr.Transaction;return o.setSender(e.address),await n.Vaults.deposit(a,o),o},_l=async(a,e,t)=>{let n=hn(t,e),o=new Zr.Transaction;return await n.Vaults.withdraw(a,o),o};var _o=class a extends S{constructor(t){super(t);this.data=t}txType=Ll.TransactionType.Other;txSubType="AddVaultsPosition";async build(t){let{account:n,network:o}=t,{txbParams:i}=this.data;return await Nl(i,n,o)}static fromData(t){return new a(t)}};var jl=require("@msafe/sui3-utils");var Lo=class a extends S{constructor(t){super(t);this.data=t}txType=jl.TransactionType.Other;txSubType="RemoveVaultsPosition";async build(t){let{account:n,network:o}=t,{txbParams:i}=this.data;return await _l(i,n,o)}static fromData(t){return new a(t)}};var Kl=require("@msafe/sui3-utils");var ql=require("@mysten/sui/transactions"),Ul={package_id:"0x355714a1eeb7ab1d80902da6c92001170cda1212edf524c32aa308a3ac177c31",published_at:"0x355714a1eeb7ab1d80902da6c92001170cda1212edf524c32aa308a3ac177c31",cetus_coin_type:"0x06864a6f921804860930db6ddbe2e16acdf8504495ea7481637a1c8b9a8fe54b::cetus::CETUS"},Fl=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:s}=a,l=new ql.Transaction;return i.forEach(d=>{l.moveCall({target:`${Ul.published_at}::router::redeem`,typeArguments:[Ul.cetus_coin_type],arguments:[l.object(n),l.object(o),l.pure(d),l.object(s)]})}),l};var jo=class a extends S{constructor(t){super(t);this.data=t}txType=Kl.TransactionType.Other;txSubType="VestingRedeem";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 Gl=require("@msafe/sui3-utils");var Vl=async(a,e,t)=>await Ve(t,e).XCetusModule.convertPayload(a),$l=async(a,e,t)=>await Ve(t,e).XCetusModule.redeemLockPayload(a),Hl=async(a,e,t)=>await Ve(t,e).XCetusModule.redeemDividendV3Payload(a.veNftId,a.rewardList),Xl=async(a,e,t)=>await Ve(t,e).XCetusModule.cancelRedeemPayload(a),zl=async(a,e,t)=>await Ve(t,e).XCetusModule.redeemPayload(a);var Uo=class a extends S{constructor(t){super(t);this.data=t}txType=Gl.TransactionType.Other;txSubType="xCETUSCancelRedeem";async build(t){let{account:n,network:o}=t,{txbParams:i}=this.data;return await Xl(i,n,o)}static fromData(t){return new a(t)}};var Ql=require("@msafe/sui3-utils");var qo=class a extends S{constructor(t){super(t);this.data=t}txType=Ql.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 Jl=require("@msafe/sui3-utils");var Fo=class a extends S{constructor(t){super(t);this.data=t}txType=Jl.TransactionType.Other;txSubType="xCETUSConvert";async build(t){let{account:n,network:o}=t,{txbParams:i}=this.data;return await Vl(i,n,o)}static fromData(t){return new a(t)}};var Yl=require("@msafe/sui3-utils");var Ko=class a extends S{constructor(t){super(t);this.data=t}txType=Yl.TransactionType.Other;txSubType="xCETUSRedeem";async build(t){let{account:n,network:o}=t,{txbParams:i}=this.data;return await zl(i,n,o)}static fromData(t){return new a(t)}};var Zl=require("@msafe/sui3-utils");var Vo=class a extends S{constructor(t){super(t);this.data=t}txType=Zl.TransactionType.Other;txSubType="xCETUSRedeemLock";async build(t){let{account:n,network:o}=t,{txbParams:i}=this.data;return await $l(i,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:tu.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=To.fromData(e.intentionData);break;case"IncreaseLiquidity":i=Ro.fromData(e.intentionData);break;case"DecreaseLiquidity":i=wo.fromData(e.intentionData);break;case"RemoveLiquidity":i=Wo.fromData(e.intentionData);break;case"ClaimFeeAndMining":i=So.fromData(e.intentionData);break;case"FarmingOpenAndAddLiquidity":i=Co.fromData(e.intentionData);break;case"FarmingIncreaseLiquidity":i=Ao.fromData(e.intentionData);break;case"FarmingDecreaseLiquidity":i=ko.fromData(e.intentionData);break;case"FarmingRemoveLiquidity":i=Mo.fromData(e.intentionData);break;case"FarmingClaimFeeAndReward":i=Do.fromData(e.intentionData);break;case"FarmingHarvest":i=vo.fromData(e.intentionData);break;case"FarmingBatchHarvest":i=xo.fromData(e.intentionData);break;case"FarmingStake":i=Oo.fromData(e.intentionData);break;case"FarmingUnstake":i=Po.fromData(e.intentionData);break;case"xCETUSConvert":i=Fo.fromData(e.intentionData);break;case"xCETUSRedeemLock":i=Vo.fromData(e.intentionData);break;case"xCETUSClaimStakingRwewards":i=qo.fromData(e.intentionData);break;case"xCETUSCancelRedeem":i=Uo.fromData(e.intentionData);break;case"xCETUSRedeem":i=Ko.fromData(e.intentionData);break;case"VestingRedeem":i=jo.fromData(e.intentionData);break;case"AggregatorSwap":i=No.fromData(e.intentionData);break;case"AddVaultsPosition":i=_o.fromData(e.intentionData);break;case"RemoveVaultsPosition":i=Lo.fromData(e.intentionData);break;case"PosVestingRedeem":i=Eo.fromData(e.intentionData);break;case"CreatePool":i=Io.fromData(e.intentionData);break;default:throw new Error("not implemented")}return i.build({suiClient:t,account:n,network:o})}};var Cu=require("@msafe/sui3-utils");var eu=qt(require("sort-keys-recursive")),Lt=class{constructor(e){this.data=e}serialize(){return JSON.stringify((0,eu.default)(this.data))}};var yn=require("@mysten/sui.js/client");var ts={};Yr(ts,{contractId:()=>wd,default:()=>vd,feeObjId:()=>Dd,roleObjId:()=>Cd,status:()=>Id,transaction:()=>Sd,upgradeCapObjId:()=>kd,vaultObjId:()=>xd});var Sd="DiBZq4UmVVYiRL6ZJmFKYoHcxtxqrhsCXSkFyT7wUr3j",Id="success",wd="0x81c960dc653975fbd0072deca8afb92d322898c911622898ba1b2e3ad0c4bd8d",Cd="0xc6ec0bdee0bb59a72077e9acd2f42457043cf47080b3d3fad4d39abf28bba63a",xd="0xbc4021387fbac149119fd24e92be9e58f745774292f3a2a12e2ac6daf5363e1d",Dd="0x4178f63970fe2daeb256dc5730ad172e82b3e8eb45f31b33e0daae72cd35e1e1",kd="0xe1e9aa7d222d151bfe6dd83358b0d7fdcb11260f710800cfaf7ccc1b1e245115",vd={transaction:Sd,status:Id,contractId:wd,roleObjId:Cd,vaultObjId:xd,feeObjId:Dd,upgradeCapObjId:kd};var es={};Yr(es,{contractId:()=>Od,default:()=>Wd,feeObjId:()=>Bd,roleObjId:()=>Pd,status:()=>Md,transaction:()=>Ad,upgradeCapObjId:()=>Ed,vaultObjId:()=>Rd});var Ad="855FNDV8o8Z3fWULPnQo9qdhLJpsg7wZrkCpNyfw9KfB",Md="success",Od="0xc357c3985e8fb875d6b37141497af660779aa1bab0ec489b2213efd74067d1fa",Pd="0x5ab49bdf9fd1413e328ef242b3f8d83dde791b38a0b627bfc87fb25c010d34f1",Rd="0xb483558770d8eb26007f193b75db40f0a45f2e36863a687625885d4de6993378",Bd="0x48453fc4d7cde3fe35aad89e5dfb496608a6a55ea529a1c0274681a808627f94",Ed="0x34279779a0d0d36bd5044b04830d607fa1b0ecf316548c8ac3a44151e4f1a42a",Wd={transaction:Ad,status:Md,contractId:Od,roleObjId:Pd,vaultObjId:Rd,feeObjId:Bd,upgradeCapObjId:Ed};var Nd=(0,yn.getFullnodeUrl)("testnet"),_d=(0,yn.getFullnodeUrl)("testnet"),Ld=(0,yn.getFullnodeUrl)("mainnet"),jd=(0,yn.getFullnodeUrl)("mainnet"),Ud="https://bc3p6l5unl.execute-api.us-west-1.amazonaws.com/prod",qd="https://rolsbkota7.execute-api.us-west-1.amazonaws.com/prod",Fd="https://6p6mkx33ne.execute-api.us-west-1.amazonaws.com/prod",Kd="https://xrae3mrjv5.execute-api.us-west-1.amazonaws.com/prod",nu=ts,ou=es,Vd=new Map([["dev",{env:"dev",rpc:{url:Nd},backend:{url:Ud},contract:nu}],["stg",{env:"stg",rpc:{url:_d},backend:{url:qd},contract:nu}],["prev",{env:"prev",rpc:{url:Ld},backend:{url:Fd},contract:ou}],["prod",{env:"prod",rpc:{url:jd},backend:{url:Kd},contract:ou}]]);function au(a,e){let t=Vd.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 iu=require("@mysten/sui.js/client");var _=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 Ho=class extends _{constructor(){super(11,"Backend is not specified")}};var Xo=class extends _{constructor(){super(1,"Wallet not connected")}};var re=qt(require("axios"));var $e=class extends _{constructor(e,t){super(10,e,{context:t})}};var zo=class a{constructor(e){this.apiURL=e}static parseResponseData(e){if(e instanceof re.AxiosError)throw new $e(e.response?.statusText);if(e.status===200){if(e.data.success)return e.data.data;throw new $e(e.data.code)}throw new $e(e.status.toString())}async getIncomingStreams(e,t){let n=await 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 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 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 He=class a{signer;suiClient;envConfig;_backend;constructor(e){this.envConfig=e,this.suiClient=new iu.SuiClient({url:e.rpc.url}),e.backend&&(this._backend=new zo(e.backend.url))}static new(e,t){let n=au(e,t);return new a(n)}get walletType(){return this.wallet?this.wallet.type:"disconnected"}get backend(){if(!this._backend)throw new Ho;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 Xo;return this.signer}async walletAddress(){return this.wallet.address()}};var Ee=require("@mysten/sui.js/utils");var Cn=require("@mysten/sui.js/transactions");var rs=require("@mysten/sui.js/transactions"),wn=require("@mysten/sui.js/utils");var ns=50n,Go=10000n,ru=25n,os=100000000n;var Zt=class{constructor(e){this.object=e}moveArg(e){return e.object(this.object)}},bn=class{constructor(e){this.objects=e}moveArgs(e){return e.makeMoveVec({objects:this.objects.map(t=>e.object(t))})}},he=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=s=>new a(t.result[s]);if(n===Symbol.iterator)return function*(){let s=0;for(;;)yield o(s),s++};if(typeof n=="symbol")return;let i=parseInt(n,10);if(!(Number.isNaN(i)||i<0))return o(i)}})}moveArg(){return this.result}};var as=require("buffer"),su=require("@mysten/sui.js/utils");var Tn=class extends _{constructor(e,t){super(3,e,{context:t})}};var Qo=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 Tn("Invalid contract return type.",{ctx:{expectType:"address",gotType:o}});return(0,su.normalizeSuiAddress)(as.Buffer.from(n).toString("hex"))}getU64(e=0,t=0){let[n,o]=this.getValue(e,t);if(o!=="u64")throw new Tn("Invalid contract return type.",{ctx:{expectType:"u64",gotType:o}});return as.Buffer.from(n).readBigInt64LE()}};var is=require("@mysten/sui.js/bcs");var $=class extends _{constructor(e,t,n){super(2,`Invalid input: ${e}`,{context:{fieldKey:t,fieldValue:n}})}};var lu={groupId:"string",name:"string"},$d=64;function uu(a){return mu(a),is.bcs.ser(lu,a).toString("base64")}function Sn(a){let e=is.bcs.de(lu,a,"base64");return mu(e),e}function mu(a){if(!cu(a.name))throw new $("Invalid metadata: Name contains unknown character");if(!cu(a.groupId))throw new $("Invalid metadata: Group ID contains unknown character");if(a.name.length>$d)throw new $("Invalid metadata: Name exceed max length 64")}function cu(a){return/^[\x00-\x7F]+$/.test(a)}var In=require("@mysten/sui.js/utils");function Jo(a,e){return(0,In.normalizeStructTag)(a)===(0,In.normalizeStructTag)(e)}function ge(a,e){return(0,In.normalizeStructTag)(a)===(0,In.normalizeStructTag)(e)}var Yo="txn.gas";var pu=require("nanoid");function du(){return(0,pu.nanoid)()}var Be=class a{constructor(e,t,n){this.globals=e;this.feeContract=t;this.streamContract=n}static convertCreateStreamInfoToInternal(e){return{metadata:uu({name:e.name,groupId:du()}),coinType:(0,wn.normalizeStructTag)(e.coinType),recipients:e.recipients.map(t=>({address:t.address,cliffAmount:t.cliffAmount,amountPerEpoch:t.amountPerStep})),epochInterval:e.interval,numberEpoch:e.steps,startTime:e.startTimeMs,cancelable:e.cancelable}}async buildCreateStreamTransactionBlock(e){let t=new rs.TransactionBlock,n=this.calculateFeesInternal(e),o=this.getCreateStreamCoinRequests(e,n),i=await this.wallet.requestCoins(o),s=await this.addMergeCoins(t,i[0]),l;o.length>1?l=await this.addMergeCoins(t,i[1]):l=s;for(let d=0;d<e.recipients.length;d++){let b=e.recipients[d],I=this.amountForRecipient(b,e.numberEpoch),C=this.getStreamFeeLocal(I),[x]=t.splitCoins(s,[t.pure(I+C,"u64")]),[D]=t.splitCoins(l,[t.pure(this.flatSuiFee,"u64")]);this.streamContract.createStream(t,{paymentCoin:new he(x),flatFeeCoin:new he(D),metadata:e.metadata,recipient:b.address,timeStart:e.startTime,cliff:b.cliffAmount,epochInterval:e.epochInterval,numEpoch:e.numberEpoch,amountPerEpoch:b.amountPerEpoch,cancelable:e.cancelable,coinType:e.coinType})}return t}calculateCreateStreamFees(e){let t=a.convertCreateStreamInfoToInternal(e);return this.calculateFeesInternal(t)}feeParams(){return{createFeePercent:{numerator:ns,denominator:Go},claimFeePercent:{numerator:ru,denominator:Go},flatFeePerStream:os}}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===Yo?n=e.gas:n=e.object(t.primaryCoin),n}getCreateStreamCoinRequests(e,t){let n=e.coinType;return Jo(n,wn.SUI_TYPE_ARG)?[{coinType:n,amount:t.totalAmount+t.streamFeeAmount+t.flatFeeAmount}]:[{coinType:n,amount:t.totalAmount+t.streamFeeAmount},{coinType:wn.SUI_TYPE_ARG,amount:t.flatFeeAmount}]}calculateFeesInternal(e){let t=e.recipients.reduce((o,i)=>{let s=this.amountForRecipient(i,e.numberEpoch),l=this.getStreamFeeLocal(s);return{totalAmount:o.totalAmount+s,streamFeeAmount:o.streamFeeAmount+l}},{totalAmount:0n,streamFeeAmount:0n});return{flatFeeAmount:BigInt(e.recipients.length)*this.flatSuiFee,...t}}amountForRecipient(e,t){return BigInt(e.amountPerEpoch)*BigInt(t)+BigInt(e.cliffAmount)}get flatSuiFee(){return os}getStreamFeeLocal(e){return e*ns/Go}async getStreamFeeRemote(e){let t=this.feeContract.streamingFee(new rs.TransactionBlock,e),n=await this.globals.suiClient.devInspectTransactionBlock({sender:await this.globals.walletAddress(),transactionBlock:t});return new Qo(n).getU64()}get wallet(){return this.globals.wallet}};var ss=require("@mysten/sui.js/transactions");var fu="0x0000000000000000000000000000000000000000000000000000000000000006";var Xe=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(ss.Transactions.MoveCall({target:n,arguments:t.arguments.map(o=>o instanceof bn?o.moveArgs(e):o instanceof Zt?o.moveArg(e):o instanceof he?o.moveArg():e.pure(o)),typeArguments:t.typeArgs})),e}addTransactionBlock(e,t,n=[],o=[]){e.add(ss.Transactions.MoveCall({target:t,arguments:n.map(i=>i instanceof bn?i.moveArgs(e):i instanceof Zt?i.moveArg(e):i instanceof he?i.moveArg():e.pure(i)),typeArguments:o}))}makeObject(e){return typeof e=="string"?new Zt(e):e}vaultObject(){return new Zt(this.config.vaultObjId)}roleObject(){return new Zt(this.config.roleObjId)}feeObject(){return new Zt(this.config.feeObjId)}clockObject(){return new Zt(fu)}};var ze=class a extends Xe{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 te=class a extends Xe{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(),s=this.makeObject(n.paymentCoin),l=this.makeObject(n.flatFeeCoin),d=this.clockObject();return this.addContractCall(t,{method:a.MethodName.create_stream,arguments:[o,i,s,l,n.metadata,n.recipient,n.timeStart,n.cliff,n.epochInterval,n.numEpoch,n.amountPerEpoch,n.cancelable,d],typeArgs:[n.coinType]})}setAutoClaim(t,n){let o=this.makeObject(n.streamId);return this.addContractCall(t,{method: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(),s=this.feeObject(),l=this.clockObject();return this.addContractCall(t,{method:a.MethodName.claim_stream_by_proxy,arguments:[o,i,s,l],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 Ge=class{constructor(e){this.globals=e;let t=e.envConfig.contract;this.feeContract=new ze(t,e),this.streamContract=new te(t,e)}feeContract;streamContract;async createStreams(e){let t=Be.convertCreateStreamInfoToInternal(e);return this.createStreamHelper().buildCreateStreamTransactionBlock(t)}createStreamHelper(){return new Be(this.globals,this.feeContract,this.streamContract)}setAutoClaim(e,t,n){let o=new Cn.TransactionBlock;return this.streamContract.setAutoClaim(o,{streamId:e,enabled:t,coinType:n})}claimStream(e,t){let n=new Cn.TransactionBlock;return this.streamContract.claimStream(n,{streamId:e,coinType:t})}claimStreamByProxy(e,t){let n=new Cn.TransactionBlock;return this.streamContract.claimStreamByProxy(n,{streamId:e,coinType:t})}cancelStream(e,t){let n=new Cn.TransactionBlock;return this.streamContract.cancelStream(n,{streamId:e,coinType:t}),n}};var Qe=require("@mysten/sui.js/utils"),cs=require("luxon");var Zo=class extends _{constructor(e,t){super(12,`Transaction failed: ${t}`,{context:{status:e,msg:t}})}};var Hd=1e3,ta=class{constructor(e){this.globals=e;this.coinMetaHelper=new ls(e.suiClient),this.createStreamHelper=new Ge(e).createStreamHelper()}coinMetaHelper;createStreamHelper;getStreamIdsFromCreateStreamResponse(e){if(e.effects?.status.status!=="success")throw new Zo(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 $("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,s={realTotalAmount:o*e.steps+n,cliffAmount:n,amountPerStep:o};return this.validateStreamAmount(s,e.totalAmount),s}calculateTimelineByInterval(e){if(e.steps===0n)throw new $("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 $("Invalid stream steps: 0");let t=BigInt(e.total.toMillis())/e.steps,n=e.timeStart.plus(cs.Duration.fromMillis(Number(t*e.steps))),o={timeStart:e.timeStart,timeEnd:n,interval:cs.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,Qe.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,Qe.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 $("Stream amount too small","totalAmount",t);if(e.cliffAmount>e.realTotalAmount)throw new $("Invalid cliff settings")}validateTimeline(e){if(e.interval.toMillis()<Hd)throw new $("Interval shall be at least 1 second","interval",e.interval)}},ls=class{constructor(e){this.suiClient=e;this.coinMetaReg=new Map}coinMetaReg;async getCoinMeta(e){let t=(0,Qe.normalizeStructTag)(e||Qe.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 be=require("@mysten/sui.js/utils"),gs=require("luxon");var kn=require("@mysten/sui.js/transactions"),vn=require("@mysten/sui.js/utils"),gu=require("luxon");var ea=class extends _{constructor(){super(7,"Connected wallet is not creator")}};var xn=class extends _{constructor(){super(8,"Connected wallet is not recipient")}};var Dn=class extends _{constructor(e,t){super(6,e,{context:t})}};var vt=class extends _{constructor(e,t={}){super(0,e,t)}};var na=class extends _{constructor(e){super(5,"Stream not found",{context:{streamId:e}})}};var aa=require("luxon"),hu=(1n<<64n)-1n,oa=1e3;function us(a){let e;typeof a=="number"?e=a:typeof a=="bigint"?e=Number(a):e=a.toMillis();let t=Math.round(e/oa);return aa.DateTime.fromMillis(t*oa)}function ms(a){let e;typeof a=="number"?e=a:typeof a=="bigint"?e=Number(a):e=a.toMillis();let t=Math.round(e/oa);return aa.Duration.fromMillis(t*oa)}var ye=class a{constructor(e,t,n){this.globals=e;this.streamId=t;this.rawData=n;this.streamContract=new te(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 vt("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 ea;let e=new kn.TransactionBlock;return this.streamContract.cancelStream(e,{streamId:this.streamId,coinType:this.coinType}),e}async claim(){if(await this.globals.walletAddress()!==this.recipient)throw new xn;let e=new kn.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 xn;let t=new kn.TransactionBlock;return this.streamContract.setAutoClaim(t,{streamId:this.streamId,coinType:this.coinType,enabled:e}),t}async claimByProxy(){let e=new kn.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,vn.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 ms(this.rawData.config.epochInterval)}get groupId(){let{metadata:e}=this.rawData.config;return Sn(e).groupId}get name(){let{metadata:e}=this.rawData.config;return Sn(e).name}get recipient(){return this.rawData.config.recipient}get timeStart(){return us(this.rawData.config.timeStart)}get duration(){let e=this.rawData.config,t=e.epochInterval*e.totalEpoch;return ms(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:us((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===hu?0n:this.rawData.status.epochClaimed*this.amountPerEpoch+this.cliff}get currentEpoch(){let e=gu.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 na(e):new Dn(`get stream data: ${t.error.code}`,{streamId:e,...t.error});let n=t.data.content;if(n.dataType!=="moveObject")throw new Dn("Unexpected object type",{gotType:n.dataType});let{typeParams:o}=(0,vn.parseStructTag)(n.type),i=(0,vn.normalizeStructTag)(o[0]),s=n.fields,l=s.config.fields,d=s.status.fields;return{coinType:i,autoClaim:s.auto_claim,balance:BigInt(s.balance.fields.balance),config:{amountPerEpoch:BigInt(l.amount_per_epoch),cancelable:l.cancelable,cliff:BigInt(l.cliff),creator:l.creator,epochInterval:BigInt(l.epoch_interval),metadata:l.metadata,recipient:l.recipient,timeStart:BigInt(l.time_start),totalEpoch:BigInt(l.total_epoch)},status:{status:d.status,epochCanceled:BigInt(d.epoch_canceled),epochClaimed:BigInt(d.epoch_claimed)}}}};var Je=class extends _{constructor(e,t){super(9,`Invalid stream group: ${e}`,{context:t})}};async function ds(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 ps=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)}},Ye=class{constructor(e){this.requester=e;this.pager=new ps(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 Xd=25;async function hs(a,e,t){let n=new An(e),o=new Mn(a,n,t);return await ds(o)}var An=class{constructor(e){this.ids=e;this.cursor=-1}cursor;async hasNext(){return this.cursor<this.ids.length-1}async next(){if(this.cursor+=1,this.cursor>=this.ids.length)throw new Error("invalid iterator implementation");return this.ids[this.cursor]}},Mn=class extends Ye{constructor(t,n,o){super(new fs(t,n,o));this.suiClient=t;this.idIter=n;this.options=o}},fs=class{constructor(e,t,n){this.suiClient=e;this.stringIter=t;this.options=n;this.filter=n?.filter,this.pageSize=n?.pageSize||Xd,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 ia=class a{constructor(e,t){this.globals=e;this.streams=t;if(t.length===0)throw new Je("stream size 0");let n=t.map(i=>i.groupId);if(new Set(n).size!==1)throw new $("Stream does not have same group ID")}type="StreamGroup";static async new(e,t){let n=await hs(e.suiClient,t);return n.forEach(o=>{if(!o)throw new vt("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=>{zd(n,i)||(o=!1)}),o}async refresh(){let e=await hs(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,s)=>ye.fromObjectData(e,t[s],i)).filter(i=>!!i);if(new Set(o.map(i=>i.groupId)).size!==1)throw new Je("Not same group ID");if(!this.checkStreamGroup(o))throw new Je("Not same stream settings");return o}};function zd(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 On=class a{constructor(e,t){this.it=e;this.pageSize=t}static async newIncoming(e){let t=await ra.newIncoming(e);return new a(t,e.pageSize)}static async newOutgoing(e){let t=await ra.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}},ra=class a{constructor(e){this.requester=e}cachedNext;static async newIncoming(e){let t=await sa.newIncomingQuery(e);return new a(t)}static async newOutgoing(e){let t=await sa.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 vt("No more results");return t}let e=this.cachedNext;if(this.cachedNext=void 0,e===null)throw new vt("No more results");return e}},sa=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 An(n.flat().map(s=>s.streamId));this.objectIter=new Mn(e.suiClient,i)}current=0;objectIter;static async newIncomingQuery(e){let t=Zd(e.query),n=await e.globals.walletAddress(),i=(await e.globals.backend.getIncomingStreams(n,t)).filter(l=>(0,be.normalizeSuiAddress)(l.recipient)===(0,be.normalizeSuiAddress)(n)),s=yu(i);return new a(e.globals,n,s,e.query)}static async newOutgoingQuery(e){let t=tf(e.query),n=await e.globals.walletAddress(),o=await e.globals.backend.getOutgoingStreams(n,t),i=yu(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 Jd(this.globals,e[0].streamId,this.objectIter);return this.current++,bu(t,this.query)?t:this.doNextRequest()}if(e.length>1){let t=await Yd(this.globals,e.map(n=>n.streamId),this.objectIter);return this.current++,Qd(t,this.query)?t:this.doNextRequest()}throw new vt("Stream group with no stream")}};function yu(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)=>gs.DateTime.fromISO(n[0].createDate).toMillis()-gs.DateTime.fromISO(t[0].createDate).toMillis())}function bu(a,e){if(e===void 0)return!0;let t=Gd(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 Gd(a,e){return e===void 0?!0:Array.isArray(e)?e.includes(a.progress.status):a.progress.status===e}function Qd(a,e){if(!e)return!0;let t=!1;return a.streams.forEach(n=>{bu(n,e)&&(t=!0)}),t}async function Jd(a,e,t){let n=await Tu(t,e);return ye.fromObjectData(a,e,n)}async function Yd(a,e,t){let n=[];for(;n.length<e.length;){let o=await Tu(t,e[n.length]);n.push(o)}return ia.newFromObjectResponse(a,e,n)}async function Tu(a,e){if(!await a.hasNext())throw new vt("object iterator has been consumed");let t=await a.next();if(!t||t.error||t.data===void 0||t.data===null)throw new vt("object iterator undefined response",{cause:t?.error});if(t?.data?.objectId!==e)throw new vt("stream id not aligned");return t}function Zd(a){return{status:ys(a?.status),coinType:Su(a?.coinType),sender:Iu(a?.sender)}}function tf(a){return{status:ys(a?.status),coinType:Su(a?.coinType),recipient:Iu(a?.recipient)}}function ys(a){return a===void 0||a.length===0?"all":Array.isArray(a)?a.reduce((e,t)=>{let n=ys(t);return!e||e===n?n:"all"},void 0):ef(a)}function ef(a){switch(a){case"STREAMING":case"STREAMED":case"CANCELED":return"active";case"COMPLETED":case"SETTLED":return"inactive";default:throw new $("Unknown stream filtered status")}}function Su(a){if(a)return Array.isArray(a)?a.length!==0?a.map(e=>(0,be.normalizeStructTag)(e)):void 0:(0,be.normalizeStructTag)(a)}function Iu(a){if(a)return Array.isArray(a)?a.length!==0?a.map(e=>(0,be.normalizeSuiAddress)(e)):void 0:(0,be.normalizeSuiAddress)(a)}var ca=class extends _{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 nf=25;async function wu(a,e,t,n="0x2::sui::SUI",o=nf){let i=new bs(a,e,n,o),s=BigInt(0),l=[];for(;await i.hasNext()&&s<t;){let d=await i.next();d&&(l.push(d),s+=BigInt(d.balance))}if(s<t)throw new ca(n,t,s);return l}var bs=class extends Ye{constructor(t,n,o,i){super(new Ts(t,n,o,i));this.suiClient=t;this.owner=n;this.coinType=o;this.reqPageSize=i}},Ts=class{constructor(e,t,n,o){this.suiClient=e;this.owner=t;this.coinType=n;this.reqPageSize=o;if(o<=0)throw new vt("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 Ss=class{constructor(e){this.msafe=e}get type(){return"msafe"}async address(){return this.msafe.address()}async requestCoins(e){return this.msafe.requestCoins(e)}},la=class{constructor(e){this.account=e}async address(){return this.account.address}},Is=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(Jo(e.coinType,Ee.SUI_TYPE_ARG))return{primaryCoin:Yo};if(e.amount<=0)throw new $("Invalid coin request","coinAmount",e.amount);let t=await wu(this.suiClient,await this.address(),e.amount,e.coinType);if(t.length===0)throw new vt("no coins available");return{primaryCoin:t[0].coinObjectId,mergedCoins:t.slice(1).map(n=>n.coinObjectId)}}},ua=class{globals;helper;constructor(e,t){this.globals=He.new(e,t),this.helper=new ta(this.globals)}connectSingleWallet(e){let t=new Is(e,this.globals.suiClient);this.globals.connectWallet(t)}connectMSafeAccount(e){let t=new Ss(e);this.globals.connectWallet(t)}async createStream(e){return this.builder().createStreams(e)}async getStream(e){return ye.new(this.globals,e)}async getIncomingStreams(e,t=10){return On.newIncoming({globals:this.globals,query:e,pageSize:t})}async getOutgoingStreams(e,t=10){return On.newOutgoing({globals:this.globals,query:e,pageSize:t})}async getCoinTypesForStreamFilter(){let e=await this.wallet.address();return(await this.globals.backend.getAllCoinTypes(e)).map(n=>(0,Ee.normalizeStructTag)(n))}async getRecipientsForStreamFilter(e){let t=await this.wallet.address();return(await this.globals.backend.getAllRecipients(t,e)).map(o=>(0,Ee.normalizeSuiAddress)(o))}async getCreatorsForStreamFilter(e){let t=await this.wallet.address();return(await this.globals.backend.getAllSenders(t,e)).map(o=>(0,Ee.normalizeSuiAddress)(o))}get wallet(){return this.globals.wallet}builder(){return new Ge(this.globals)}};var Vt=class extends Lt{application="mpay";getClient(e,t){let n=new ua(e==="sui:mainnet"?"prod":"dev");return n.connectSingleWallet(new la(t)),n}};var Pn=class extends Vt{constructor(t){super(t);this.data=t}txType=Cu.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 xu=require("@msafe/sui3-utils");var Rn=class extends Vt{constructor(t){super(t);this.data=t}txType=xu.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 Du=require("@msafe/sui3-utils");var Bn=class extends Vt{constructor(t){super(t);this.data=t}txType=Du.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 ku=require("@msafe/sui3-utils");var En=class extends Vt{constructor(t){super(t);this.data=t}txType=ku.TransactionType.Stream;txSubType="CreateStream";async build(t){let{network:n,account:o}=t;return this.getClient(n,o).createStream(this.data)}};var ws=require("@mysten/sui.js/bcs"),Te=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,Te.normalizeSuiAddress)(t)}decodeInputString(e){return this.decodePureArg(e,"string")}decodeInputBool(e){return this.decodePureArg(e,"bool")}decodePureArg(e,t){let n=this.getInputParam(e);return 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,Te.normalizeSuiAddress)(e.value.Object.ImmOrOwned.objectId)}return(0,Te.normalizeSuiAddress)(e.value)}static getSharedObjectId(e){if(e.type!=="object")throw new Error(`not object argument: ${JSON.stringify(e)}`);if(typeof e.value!="object")return(0,Te.normalizeSuiAddress)(e.value);if(!("Object"in e.value)||!("Shared"in e.value.Object))throw new Error("not Shared");return(0,Te.normalizeSuiAddress)(e.value.Object.Shared.objectId)}static getPureInput(e,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,Te.normalizeStructTag)(this.moveCall.typeArguments[e])}txArg(e){return this.moveCall.arguments[e]}};var ma=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"&&ge(t.target,this.contract.createStreamTarget));if(e.length===0)throw new vt("No create stream transactions");return e.map(t=>new Ze(t,this.txb))}getCreationInfoFromMoveCall(e){let t=e.decodeInputString(4),{name:n,groupId:o}=Sn(t),i=e.decodeInputAddress(5),s=e.decodeInputU64(6),l=e.decodeInputU64(7),d=e.decodeInputU64(8),b=e.decodeInputU64(9),I=e.decodeInputU64(10),C=e.decodeInputBool(11),x=e.typeArg(0);return{name:n,groupId:o,recipient:i,timeStart:s,cliff:l,epochInterval:d,totalEpoch:b,amountPerEpoch:I,cancelable:C,coinType:x}}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 $("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 te(this.globals.envConfig.contract,this.globals)}get feeContract(){return new ze(this.globals.envConfig.contract,this.globals)}createStreamHelper(){return new Be(this.globals,this.feeContract,this.contract)}getInputArg(e){if(e.kind!=="Input")throw new Error("not input type");return"value"in e?e:this.txb.blockData.inputs[e.index]}};var pa=class{constructor(e,t){this.globals=e;this.txb=t;this.contract=new te(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"&&ge(t.target,this.contract.createStreamTarget))!==-1}isSetAutoClaimTransaction(){return this.transactions.length===1&&this.transactions[0].kind==="MoveCall"&&ge(this.transactions[0].target,this.contract.setAutoClaimTarget)}isCancelStreamTransaction(){return this.transactions.length===1&&this.transactions[0].kind==="MoveCall"&&ge(this.transactions[0].target,this.contract.cancelStreamTarget)}isClaimStreamTransaction(){return this.transactions.length===1&&this.transactions[0].kind==="MoveCall"&&ge(this.transactions[0].target,this.contract.claimStreamTarget)}isClaimByProxyTransaction(){return this.transactions.length===1&&this.transactions[0].kind==="MoveCall"&&ge(this.transactions[0].target,this.contract.claimStreamByProxyTarget)}decodeCreateStreamTransaction(){return new ma(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 vu=require("@msafe/sui3-utils");var Wn=class extends Vt{constructor(t){super(t);this.data=t}txType=vu.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 da=class{application="mpay";supportSDK="@mysten/sui.js";async deserialize(e){let{network:t,transactionBlock:n}=e,o=He.new(t==="sui:mainnet"?"prod":"dev"),s=new pa(o,n).decode(),l;switch(s.type){case"CreateStream":l=new En(s.info);break;case"SetAutoClaim":l=new Wn({streamId:s.streamId,enabled:s.enabled});break;case"Claim":l=new Bn({streamId:s.streamId});break;case"ClaimByProxy":l=new Rn({streamId:s.streamId});break;case"Cancel":l=new Pn({streamId:s.streamId});break;default:throw new Error(`Unknown transaction type: ${s}`)}return{txType:l.txType,txSubType:l.txSubType,intentionData:l.data}}async build(e){let{intentionData:t}=e,n;switch(e.txSubType){case"CreateStream":n=new En(t);break;case"Claim":n=new Bn(t);break;case"ClaimByProxy":n=new Rn(t);break;case"SetAutoClaim":n=new Wn(t);break;case"Cancel":n=new Pn(t);break;default:throw new Error("not implemented")}return n.build({...e})}};var Nn=require("@msafe/sui3-utils");var Au=require("@msafe/sui3-utils");var fa=class a extends Lt{constructor(t){super(t);this.data=t}txType;txSubType;async build(t){let{suiClient:n,account:o}=t;return(0,Au.buildCoinTransferTxb)(n,this.data,o.address)}static fromData(t){return new a(t)}};var Mu=require("@msafe/sui3-utils");var ha=class a extends Lt{constructor(t){super(t);this.data=t}txType;txSubType;async build(t){let{suiClient:n,account:o}=t;return(0,Mu.buildObjectTransferTxb)(n,this.data,o.address)}static fromData(t){return new a(t)}};var ga=class{application="msafe-core";supportSDK="@mysten/sui.js";constructor(){this.application=Nn.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 Nn.TransactionSubTypes.assets.coin.send:o=fa.fromData(e.intentionData);break;case Nn.TransactionSubTypes.assets.object.send:o=ha.fromData(e.intentionData);break;default:throw new Error("not implemented")}return o.build({suiClient:t,account:n})}};var qu=require("@msafe/sui3-utils");var Ou=!1,_n={ProtocolPackage:"0xee0041239b89564ce870a7dec5ddc5d114367ab94a1137e90aa0633cb76518e0",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 Cs(){if(!Ou)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),Ou=!0}catch(a){console.error(a.message)}}var Xt=_n;var Se=require("@msafe/sui3-utils"),Ie=require("@mysten/sui/utils"),xs=require("@mysten/sui.js/bcs");var ya=class{constructor(e){this.txb=e}decode(){if(console.log("txb",this.txb),this.isClaimRewardTransaction())return this.decodeClaimReward();if(this.isEntryBorrowTransaction())return this.decodeEntryBorrow();if(this.isEntryBorrowWithFeeTransaction())return this.decodeEntryBorrow();if(this.isEntryMultiDepositTransaction())return this.decodeEntryMultiDeposit();if(this.isEntryDepositTransaction())return this.decodeEntryDeposit();if(this.isEntryRepayTransaction())return this.decodeEntryRepay();if(this.isEntryWithdrawTransaction())return this.decodeEntryWithdraw();if(this.isEntryClaimAndDepositTransaction())return this.decodeEntryClaimAndDeposit();throw new Error("Unknown transaction type")}get transactions(){return this.txb.blockData.transactions}getMoveCallTransaction(e){return this.transactions.find(t=>t.kind==="MoveCall"&&t.target===e)}isClaimRewardTransaction(){return!!this.transactions.find(t=>!!(t.kind==="MoveCall"&&t.target.includes("claim_reward")))}isEntryBorrowTransaction(){return!!this.getMoveCallTransaction(`${Xt.ProtocolPackage}::incentive_v3::entry_borrow_v2`)}isEntryBorrowWithFeeTransaction(){return!!this.getMoveCallTransaction(`${Xt.ProtocolPackage}::incentive_v3::borrow_v2`)}isEntryMultiDepositTransaction(){let e=`${Xt.ProtocolPackage}::incentive_v3::entry_deposit`,t=this.transactions.filter(o=>o.kind==="MoveCall"&&o.target===e);return this.transactions.find(o=>o.kind==="MoveCall"&&o.target.includes("claim_reward"))?!1:t.length>1}isEntryClaimAndDepositTransaction(){let e=`${Xt.ProtocolPackage}::incentive_v3::entry_deposit`,t=this.transactions.filter(o=>o.kind==="MoveCall"&&o.target===e);return!!(this.transactions.find(o=>o.kind==="MoveCall"&&o.target.includes("claim_reward"))&&t.length>0)}isEntryDepositTransaction(){return!!this.getMoveCallTransaction(`${Xt.ProtocolPackage}::incentive_v3::entry_deposit`)}isEntryRepayTransaction(){return!!this.getMoveCallTransaction(`${Xt.ProtocolPackage}::incentive_v3::entry_repay`)}isEntryWithdrawTransaction(){return!!this.getMoveCallTransaction(`${Xt.ProtocolPackage}::incentive_v3::withdraw_v2`)}findPoolByAssetId(e){let t=Object.values(Xt.pool).find(n=>n.assetId===e);if(!t)throw new Error("Pool not found");return t}decodeEntryClaimAndDeposit(){return{txType:Se.TransactionType.Other,type:"EntryClaimAndDeposit",intentionData:{type:"entry_claim_and_deposit"}}}decodeClaimReward(){return console.log("decode claims"),{txType:Se.TransactionType.Other,type:"ClaimReward",intentionData:{type:"claim_reward"}}}decodeEntryBorrow(){let e=this.helper.decodeInputU8(4),t=this.helper.decodeInputU64(5);return{txType:Se.TransactionType.Other,type:"EntryBorrow",intentionData:{amount:t,assetId:e}}}decodeEntryMultiDeposit(){let e=[],t=`${Xt.ProtocolPackage}::incentive_v3::entry_deposit`;return this.transactions.forEach(n=>{if(n.kind==="MoveCall"&&n.target===t){let o=new ba(n,this.txb),i=o.decodeInputU8(3),s=o.decodeInputU64(5);e.push({assetId:i,amount:s})}}),{txType:Se.TransactionType.Other,type:"EntryMultiDeposit",intentionData:{list:e}}}decodeEntryDeposit(){let e=this.helper.decodeInputU8(3),t=this.helper.decodeInputU64(5);return{txType:Se.TransactionType.Other,type:"EntryDeposit",intentionData:{amount:t,assetId:e}}}decodeEntryRepay(){let e=this.helper.decodeInputU8(4),t=this.helper.decodeInputU64(6);return{txType:Se.TransactionType.Other,type:"EntryRepay",intentionData:{amount:t,assetId:e}}}decodeEntryWithdraw(){let e=this.helper.decodeInputU8(4),t=this.helper.decodeInputU64(5);return{txType:Se.TransactionType.Other,type:"EntryWithdraw",intentionData:{amount:t,assetId:e}}}get helper(){let e=this.transactions.find(t=>t.kind==="MoveCall"&&t.target.startsWith(Xt.ProtocolPackage));return new ba(e,this.txb)}},ba=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,Ie.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 xs.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,Ie.normalizeSuiAddress)(e.value.Object.ImmOrOwned.objectId)}return(0,Ie.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,Ie.normalizeSuiAddress)(e.value);if(!("Object"in e.value)||!("Shared"in e.value.Object))throw new Error("not Shared");return(0,Ie.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 xs.bcs.de(t,new Uint8Array(n))}typeArg(e){return(0,Ie.normalizeStructTag)(this.moveCall.typeArguments[e])}txArg(e){return this.moveCall.arguments[e]}};var Ds=require("@mysten/sui/transactions"),jt=require("@naviprotocol/lending");async function tn(a,e,t,n){return await(0,jt.depositCoinPTB)(a,e,t,{amount:n}),a}async function Pu(a,e,t,n){let[o]=await(0,jt.withdrawCoinPTB)(a,e,t);return a.transferObjects([o],a.pure.address(n)),a}async function Ru(a,e,t,n){let[o]=await(0,jt.borrowCoinPTB)(a,e,t);return a.transferObjects([o],a.pure.address(n)),a}async function ks(a,e,t,n){return await(0,jt.repayCoinPTB)(a,e,t,{amount:n}),a}async function Bu(a,e){let t=new Ds.Transaction,n=await(0,jt.getUserAvailableLendingRewards)(e,{client:a});return await(0,jt.claimLendingRewardsPTB)(t,n),t}async function Eu(a,e){let t=new Ds.Transaction,n=await(0,jt.getUserAvailableLendingRewards)(e,{client:a});return await(0,jt.claimLendingRewardsPTB)(t,n,{customCoinReceive:{type:"depositNAVI",depositNAVI:{fallbackReceiveAddress:e}}}),t}var Ta=class a extends S{constructor(t){super(t);this.data=t}txType;txSubType;async build(t){let{type:n}=this.data;return console.log("claim reward",n),await Bu(t.suiClient,t.account.address)}static fromData(t){return new a(t)}};var Sa=class a extends S{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 Eu(t.suiClient,t.account.address)}static fromData(t){return new a(t)}};var Nu=require("@mysten/sui/transactions");var Wu=require("@naviprotocol/lending");async function ee(a){return(0,Wu.getPool)(a)}var Ia=class a extends S{constructor(t){super(t);this.data=t}txType;txSubType;async build(t){let{assetId:n,amount:o}=this.data,i=new Nu.Transaction;console.log("build",this.data);let s=await ee(n);return await Ru(i,s,o,t.account.address)}static fromData(t){return new a(t)}};var _u=require("@mysten/sui/transactions");async function en(a,e,t){let n=await a.getCoins({owner:e,coinType:t});return console.log("getTokenObjs",e,n),n}var wa=class a extends S{constructor(t){super(t);this.data=t}txType;txSubType;async build(t){let{suiClient:n,account:o}=t,{assetId:i,amount:s}=this.data,l=new _u.Transaction;console.log("build",this.data);let d=await ee(i);if(i===0){let[x]=l.splitCoins(l.gas,[s]);return await tn(l,d,x,s)}let b=await en(n,o.address,d.suiCoinType);if(!b.data[0])throw new Error(`Insufficient balance for ${d.suiCoinType} Token`);let I=b.data[0].coinObjectId;if(b.data.length>=2){let x=1;for(;x<b.data.length;)l.mergeCoins(I,[b.data[x].coinObjectId]),x++}return await tn(l,d,l.object(I),s)}static fromData(t){return new a(t)}};var Lu=require("@mysten/sui/transactions");var Ca=class a extends S{constructor(t){super(t);this.data=t}txType;txSubType;async build(t){let{suiClient:n,account:o}=t,{assetId:i,amount:s}=this.data,l=new Lu.Transaction;console.log("build",this.data);let d=await ee(i);if(i===0){let[C]=l.splitCoins(l.gas,[s]);return ks(l,d,C,s)}let b=await en(n,o.address,d.suiCoinType);if(!b.data[0])throw new Error(`Insufficient balance for ${d.suiCoinType} Token`);let I=b.data[0].coinObjectId;if(b.data.length>=2){let C=1;for(;C<b.data.length;)l.mergeCoins(I,[b.data[C].coinObjectId]),C++}return ks(l,d,l.object(I),s)}static fromData(t){return new a(t)}};var ju=require("@mysten/sui/transactions");var xa=class a extends S{constructor(t){super(t);this.data=t}txType;txSubType;async build(t){let{assetId:n,amount:o}=this.data,i=new ju.Transaction;console.log("build",this.data);let s=await ee(n);return await Pu(i,s,o,t.account.address)}static fromData(t){return new a(t)}};var Uu=require("@mysten/sui/transactions");var Da=class a extends S{constructor(t){super(t);this.data=t}txType;txSubType;async build(t){let{suiClient:n,account:o}=t,{list:i}=this.data,s=new Uu.Transaction;console.log("build",this.data);for(let l=0;l<i.length;l++){let{assetId:d,amount:b}=i[l],I=await ee(d);if(d===0){let[D]=s.splitCoins(s.gas,[b]);await tn(s,I,D,b);continue}let C=await en(n,o.address,I.suiCoinType);if(!C.data[0])throw new Error(`Insufficient balance for ${I.suiCoinType} Token`);let x=C.data[0].coinObjectId;if(C.data.length>=2){let D=1;for(;D<C.data.length;)s.mergeCoins(x,[C.data[D].coinObjectId]),D++}await tn(s,I,s.object(x),b)}return s}static fromData(t){return new a(t)}};var ka=class{application="navi";supportSDK="@mysten/sui";async deserialize(e){await Cs();let{transaction:t}=e,o=new ya(t).decode();return{txType:qu.TransactionType.Other,txSubType:o.type,intentionData:o.intentionData}}async build(e){let{suiClient:t,account:n}=e,o;switch(await Cs(),e.txSubType){case"EntryDeposit":o=wa.fromData(e.intentionData);break;case"EntryBorrow":o=Ia.fromData(e.intentionData);break;case"EntryRepay":o=Ca.fromData(e.intentionData);break;case"EntryWithdraw":o=xa.fromData(e.intentionData);break;case"EntryMultiDeposit":o=Da.fromData(e.intentionData);break;case"ClaimReward":o=Ta.fromData(e.intentionData);break;case"EntryClaimAndDeposit":o=Sa.fromData(e.intentionData);break;default:throw new Error("not implemented")}return o.build({suiClient:t,account:n})}};var Ln=require("@msafe/sui3-utils"),Fu=require("@mysten/bcs"),Ku=require("@mysten/sui/transactions"),Vu=qt(require("sort-keys-recursive")),$u="msafe-plain-tx",Hu=Ln.TransactionSubTypes.others.plain,vs=class a{constructor(e){this.data=e}application=$u;txType=Ln.TransactionType.Other;txSubType=Hu;serialize(){return JSON.stringify((0,Vu.default)(this.data))}async build(e){return Ku.Transaction.from((0,Fu.fromHex)(this.data.content))}static fromData(e){return new a(e)}},va=class{application;supportSDK="@mysten/sui";constructor(){this.application=$u}async deserialize(e){let{content:t}=e.appContext;return{txType:Ln.TransactionType.Other,txSubType:Hu,intentionData:{content:t}}}async build(e){let{suiClient:t,network:n,account:o}=e;return vs.fromData(e.intentionData).build({suiClient:t,network:n,account:o})}};var Os=require("@mysten/sui/client"),Xu=require("@mysten/sui/transactions"),Oa=require("@mysten/sui.js/client"),zu=require("@mysten/sui.js/transactions");var nn=require("@open-rpc/client-js");var rf={"-32700":"ParseError","-32600":"InvalidRequest","-32601":"MethodNotFound","-32602":"InvalidParams","-32603":"InternalError"},As=class extends Error{},Aa=class extends As{code;type;constructor(e,t){super(e),this.code=t,this.type=rf[t]??"ServerError"}};function sf(a){let e=new URL(a);return e.protocol=e.protocol.replace("http","ws"),e.toString()}var cf={WebSocketConstructor:typeof WebSocket<"u"?WebSocket:void 0,callTimeout:3e4,reconnectTimeout:3e3,maxReconnects:5},Ma=class{endpoint;options;#n=0;#a=0;#t=null;#e=null;#i=new Set;#o=new Map;constructor(e,t={}){this.endpoint=e,this.options={...cf,...t},this.endpoint&&this.endpoint.startsWith("http")&&(this.endpoint=sf(this.endpoint))}async makeRequest(e,t){let n=await this.#r();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 Aa(o.message,o.code);return i})}#r(){return this.#e?this.#e:(this.#e=new Promise(e=>{this.#t?.close(),this.#t=new this.options.WebSocketConstructor(this.endpoint),this.#t.addEventListener("open",()=>{this.#a=0,e(this.#t)}),this.#t.addEventListener("close",()=>{this.#a++,this.#a<=this.options.maxReconnects&&setTimeout(()=>{this.#s()},this.options.reconnectTimeout)}),this.#t.addEventListener("message",({data:t})=>{let n;try{n=JSON.parse(t)}catch(o){console.error(new Error(`Failed to parse RPC message: ${t}`,{cause:o}));return}if("id"in n&&n.id!=null&&this.#o.has(n.id)){let{resolve:o,timeout:i}=this.#o.get(n.id);clearTimeout(i),o(n)}else if("params"in n){let{params:o}=n;this.#i.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.#i].map(e=>e.subscribe(this)))}async subscribe(e){let t=new Ms(e);return this.#i.add(t),await t.subscribe(this),()=>t.unsubscribe(this)}},Ms=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 we=class{rpcClient;websocketClient;constructor({url:e,websocket:{url:t,...n}={},rpc:o}){let i=new nn.HTTPTransport(o?.url??e,{headers:{"Content-Type":"application/json",...o?.headers}});this.rpcClient=new nn.Client(new nn.RequestManager([i])),this.websocketClient=new Ma(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 Pa=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 Rs(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 Os.SuiClient({transport:new we({url:e.clientUrl,rpc:{url:e.clientUrl}})}),n=new Oa.SuiClient({transport:new we({url:e.clientUrl,rpc:{url:e.clientUrl}})}),o=await e.transactionBlock.build({client:n}),i=Xu.Transaction.from(o);return this.helper.deserialize({...e,suiClient:t,transaction:i})}async build(e){let t=new Os.SuiClient({transport:new we({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 zu.TransactionBlock.from(i)}},Rs=class{constructor(e){this.helper=e}async deserialize(e){let t=new Oa.SuiClient({transport:new we({url:e.clientUrl,rpc:{url:e.clientUrl}})});return this.helper.deserialize({...e,transactionBlock:e.transactionBlock,suiClient:t})}async build(e){let t=new Oa.SuiClient({transport:new we({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 am=require("@msafe/sui3-utils"),im=require("@mysten/sui/client"),rm=require("@scallop-io/sui-scallop-sdk");var At=require("@msafe/sui3-utils"),Ws=require("@scallop-io/sui-scallop-sdk");var Gu=require("@mysten/sui/utils"),Ce=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:i}=(0,Gu.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,s,l)=>(i[s]=l,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 Ra=require("@mysten/sui/bcs"),xe=require("@mysten/sui/utils"),Bs=class a{constructor(e,t,n=0){this.moveCall=e;this.transaction=t;let o=[];e?.MoveCall&&t.getData().commands.filter((i,s)=>{if(i.$kind==="MoveCall"){let l=`${i.MoveCall.package}::${i.MoveCall.module}::${i.MoveCall.function}`,d=`${e.MoveCall.package}::${e.MoveCall.module}::${e.MoveCall.function}`;return l===d?(o.push(s),!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,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.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=Ra.bcs[t];return Ra.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,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){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 Ra.bcs.U64.parse(new Uint8Array(t))}typeArg(e){return(0,xe.normalizeStructTag)(this.txBlockTransactions.typeArguments[e])}txArg(e){return this.transaction.blockData.inputs[e]}},W=Bs;var Es=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)}},Rt=Es;var De=require("@mysten/sui/utils"),Qu=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 i=a.address.get("borrowIncentive.object");return o===`${i.slice(2)}::incentive_account::IncentiveProgramLockKey`},on={id:"0xc63072e7f5f4983a2efaf5bdba1480d5e7d74d57948e1c7cc436f8e22cbeb410",incentivePools:"0x64972b713ccec45ec3964809e477cea6f97350c0c50ca3aec85bb631639266ec",incentiveAccounts:"0x3c0b707068bdcea8bb859d751ad3e2149a9f83c13fcf4054ef91372a00bccdd3"},$t={unstakeObligation:(a,e,t)=>a.moveCall(`${on.id}::user::unstake`,[on.incentivePools,on.incentiveAccounts,a.object(e),a.object(t),De.SUI_CLOCK_OBJECT_ID],[(0,De.normalizeStructTag)(De.SUI_TYPE_ARG)]),redeem_rewards:(a,e,t,n)=>a.moveCall(`${on.id}::user::redeem_rewards`,[on.incentivePools,on.incentiveAccounts,a.object(e),a.object(t),De.SUI_CLOCK_OBJECT_ID],[(0,De.normalizeStructTag)(n)])};var Ju=(a,e)=>{let t=[];for(let n=0;n<a.length;n+=e)t.push(a.slice(n,n+e));return t};var Ba=class extends Ce{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(`${Ws.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,`${Ws.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:At.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:At.TransactionType.Other,type:"MigrateAndClaim",intentionData:{obligationKey:t,obligationId:n,rewardCoinName:o,veScaKey:e}}}decodeOpenObligation(){return{txType:At.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:At.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:At.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:At.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,s)=>i+s,0),o=this.helperDepositCollateral.decodeSharedObjectId(1);return{txType:At.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:At.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:At.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:At.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:At.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,s)=>i+s,0),o=this.helperRepay.decodeSharedObjectId(1);return{txType:At.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((s,l)=>s+l,0),i=this.helperRepay.decodeSharedObjectId(1);return{txType:At.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((s,l)=>s+l,0)}if(this.helperStake.moveCall&&t===0){let i=this.helperStake.getNestedInputParam(2);t=new Rt(i,this.transaction).getAmountInput().reduce((s,l)=>s+l,0)}let n=this.helperStake.typeArg(0),o=this.utils.parseCoinNameFromType(n);return{txType:At.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:At.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,s)=>i+s,0),o;return this.isCreateStakeAccountTransaction()||(o=this.helperStake.decodeOwnedObjectId(1)),{txType:At.TransactionType.Other,type:"SupplyAndStakeLending",intentionData:{amount:n,coinName:e,stakeAccountId:o}}}decodeUnstakeAndWithdraw(){let e=[];this.helperUnstakes.forEach(o=>{let i=o.decodeOwnedObjectId(1),s=o.decodeInputU64(2);e.push({id:i,coin:s})});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,s)=>i+s,0)}return{txType:At.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),s=o.typeArg(0),l=this.utils.parseCoinNameFromType(s);e.push({stakeMarketCoinName:l,stakeAccountId:i})}),this.helperClaimBorrowV2Reward.forEach(o=>{let i=o.decodeSharedObjectId(4),s=o.decodeOwnedObjectId(3),l=this.utils.parseCoinNameFromType(o.typeArg(0));t.push({obligationId:s,obligationKey:i,rewardCoinName:l})}),this.helperClaimBorrowReward.forEach(o=>{let i=o.decodeSharedObjectId(2),s=o.decodeOwnedObjectId(3),l=this.utils.parseCoinNameFromType(o.typeArg(0));n.push({obligationId:s,obligationKey:i,rewardCoinName:l})}),{txType:At.TransactionType.Other,type:"ClaimIncentiveReward",intentionData:{lendingIncentive:e,borrowIncentiveV2:t,borrowIncentive:n}}}};var Ea=require("@msafe/sui3-utils");var Wa=class extends Ce{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:Ea.TransactionType.Other,type:"CreateReferralLink",intentionData:{}}}decodeClaimRevenueReferral(){let e=this.helperClaimRevenueReferral[0].decodeOwnedObjectId(2),t=this.helperClaimRevenueReferral.map(n=>n.typeArg(0));return{txType:Ea.TransactionType.Other,type:"ClaimRevenueReferral",intentionData:{veScaKey:e,coins:t}}}decodeBindReferral(){let e=this.helperBindReferral.decodePureArg(1,"Address");return{txType:Ea.TransactionType.Other,type:"BindReferral",intentionData:{veScaKey:e}}}};var ne=require("@msafe/sui3-utils"),Yu=require("@scallop-io/sui-scallop-sdk");var Na=class extends Ce{async decode(){if(this.isExtendPeriodAndStakeMoreSca())return this.decodePeriodAndStakeMoreSca();if(this.isStakeScaFirsTime()||this.isStakeMoreSca())return this.decodeStakeSca();if(this.isRenewExpiredVeSca())return this.decodeRenewExpiredVeSca();if(this.isExtendPeriod())return this.decodeExtendStakePeriod();if(this.isRedeemSca())return this.decodeRedeemSca();if(this.isMergeVeSca())return this.decodeMergeVesca();if(this.isSplitVeSca())return this.decodeSplitVesca();if(this.isVeScaObligationBindings())return this.decodeVeScaObligationBindings();if(await this.isTransferVeScaKey())return this.decodeTransferVeScaKey()}isStakeScaFirsTime(){return this.hasMoveCallCommand(`${this.coreId.veScaPkgId}::ve_sca::mint_ve_sca_key`)}isExtendPeriodAndStakeMoreSca(){let e=this.hasMoveCallCommand(`${this.coreId.veScaPkgId}::ve_sca::extend_lock_period`),t=this.hasMoveCallCommand(`${this.coreId.veScaPkgId}::ve_sca::lock_more_sca`);return!!e&&!!t}isRedeemSca(){return this.hasMoveCallCommand(`${this.coreId.veScaPkgId}::ve_sca::redeem`)}isStakeMoreSca(){return this.hasMoveCallCommand(`${this.coreId.veScaPkgId}::ve_sca::lock_more_sca`)}isExtendPeriod(){return this.hasMoveCallCommand(`${this.coreId.veScaPkgId}::ve_sca::extend_lock_period`)}isRenewExpiredVeSca(){return this.hasMoveCallCommand(`${this.coreId.veScaPkgId}::ve_sca::renew_expired_ve_sca`)}isMergeVeSca(){return this.hasMoveCallCommand(`${this.coreId.veScaPkgId}::ve_sca::merge`)}isSplitVeSca(){return this.hasMoveCallCommand(`${this.coreId.veScaPkgId}::ve_sca::split`)}isVeScaObligationBindings(){let e=this.commands.filter(l=>this.filterMoveCallCommands(l,`${this.coreId.borrowIncentivePkg}::user::unstake_v2`)),t=this.commands.filter(l=>this.filterMoveCallCommands(l,`${this.coreId.borrowIncentivePkg}::user::stake_with_ve_sca_v2`)),n=this.commands.filter(l=>this.filterMoveCallCommands(l,`${this.coreId.borrowIncentivePkg}::user::deactivate_boost_v2`)),o=e.length>0&&t.length>0&&e.length===t.length,i=n.length>0;return this.commands.length===e.length+t.length+n.length&&(o||i)}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),i=this.inputs.filter((d,b)=>d.$kind==="Object"&&o.has(b)).map(d=>d.Object.ImmOrOwnedObject),s=`${this.coreId.veScaObjId}::ve_sca::VeScaKey`,l=Ju(i.map(({objectId:d})=>d),50);for(let d=0;d<l.length;d++){let b=l[d];if((await this.scallopClient.scallopSuiKit.queryGetObjects(b,{showType:!0})).some(C=>C.type!==s))return!1}return i.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,`${Yu.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=[],i=0,s=0,l=0;return this.commands.forEach(d=>{this.filterMoveCallCommands(d,e)?(o.push({action:"unstake",helper:new W(d,this.transaction,i)}),i++):this.filterMoveCallCommands(d,t)?(o.push({action:"stake",helper:new W(d,this.transaction,s)}),s++):this.filterMoveCallCommands(d,n)&&(o.push({action:"deactivate",helper:new W(d,this.transaction,l)}),l++)}),o}decodeRedeemSca(){let e=this.helperRedeemSca.decodeOwnedObjectId(1);return{txType:ne.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((k,P)=>k+P,0),o=this.helperRenewExpired.decodeOwnedObjectId(1),i=!!this.helperRedeemSca.moveCall,s=[],l=[],d=[];this.helperOldUnstakeObligation.moveCall&&(s=[this.helperOldUnstakeObligation.decodeOwnedObjectId(2),this.helperOldUnstakeObligation.decodeSharedObjectId(3)]),this.helperUnstakeObligation.moveCall&&(l=[this.helperUnstakeObligation.decodeOwnedObjectId(3),this.helperUnstakeObligation.decodeSharedObjectId(4)]),this.helperStakeObligationWithVeSca.moveCall&&(d=[this.helperStakeObligationWithVeSca.decodeOwnedObjectId(3),this.helperStakeObligationWithVeSca.decodeSharedObjectId(4)]);let b=!1,I=!1,C,x,D=[{condition:s,isOld:!0},{condition:l,isOld:!1},{condition:d,isOld:!1}];for(let k=0;k<D.length;k++)D[k].condition.length>1&&([x,C]=D[k].condition,b=!0,I=D[k].isOld);return{txType:ne.TransactionType.Other,type:"RenewExpStakePeriod",intentionData:{amount:n,unlockTime:t,obligationId:C,obligationKey:x,veScaKey:o,isHaveRedeem:i,isObligationLocked:b,isOldBorrowIncentive:I}}}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 s=!1,l=!1,d,b,I=[{condition:n,isOld:!0},{condition:o,isOld:!1},{condition:i,isOld:!1}];for(let C=0;C<I.length;C++)I[C].condition.length>1&&([b,d]=I[C].condition,s=!0,l=I[C].isOld);return{txType:ne.TransactionType.Other,type:"ExtendStakePeriod",intentionData:{unlockTime:e,obligationId:d,obligationKey:b,veScaKey:t,isObligationLocked:s,isOldBorrowIncentive:l}}}decodePeriodAndStakeMoreSca(){let e=this.helperStakeMoreSca.getNestedInputParam(4),t=this.helperExtendStakePeriod.decodeInputU64(4),n=new Rt(e,this.transaction).getAmountInput().reduce((D,k)=>D+k,0),o=[],i=[],s,l=[];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&&(s=this.helperStakeMoreSca.decodeOwnedObjectId(1)),this.helperStakeObligationWithVeSca.moveCall&&(l=[this.helperStakeObligationWithVeSca.decodeOwnedObjectId(3),this.helperStakeObligationWithVeSca.decodeSharedObjectId(4)]);let d=!1,b=!1,I,C,x=[{condition:o,isOld:!0},{condition:i,isOld:!1},{condition:l,isOld:!1}];for(let D=0;D<x.length;D++)x[D].condition.length>1&&([C,I]=x[D].condition,d=!0,b=x[D].isOld);return{txType:ne.TransactionType.Other,type:"ExtendPeriodAndStakeMore",intentionData:{amount:n,veScaKey:s,unlockTime:t,obligationId:I,obligationKey:C,isOldBorrowIncentive:b,isObligationLocked:d}}}decodeStakeSca(){let e,t;this.helperStakeSca.moveCall&&this.helperStakeMoreSca.moveCall===void 0?(e=this.helperStakeSca.getNestedInputParam(3),t=this.helperStakeSca.decodeInputU64(4)):e=this.helperStakeMoreSca.getNestedInputParam(4);let n=new Rt(e,this.transaction).getAmountInput().reduce((D,k)=>D+k,0),o=[],i=[],s,l=[];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&&(s=this.helperStakeMoreSca.decodeOwnedObjectId(1)),this.helperStakeObligationWithVeSca.moveCall&&(l=[this.helperStakeObligationWithVeSca.decodeOwnedObjectId(3),this.helperStakeObligationWithVeSca.decodeSharedObjectId(4)]);let d=!1,b=!1,I,C,x=[{condition:o,isOld:!0},{condition:i,isOld:!1},{condition:l,isOld:!1}];for(let D=0;D<x.length;D++)x[D].condition.length>1&&([C,I]=x[D].condition,d=!0,b=x[D].isOld);return{txType:ne.TransactionType.Other,type:"StakeSca",intentionData:{amount:n,unlockTime:t,obligationId:I,obligationKey:C,veScaKey:s,isObligationLocked:d,isOldBorrowIncentive:b}}}decodeMergeVesca(){let e=this.getMergeSplitVeScaHelper("merge"),t={targetVeScaKey:e.decodeOwnedObjectId(1),sourceVeScaKey:e.decodeOwnedObjectId(2)};return{txType:ne.TransactionType.Other,type:"MergeVeSca",intentionData:t}}decodeSplitVesca(){let e=this.getMergeSplitVeScaHelper("split"),t={targetVeScaKey:e.decodeOwnedObjectId(1),splitAmount:e.decodeInputU64(4)};return{txType:ne.TransactionType.Other,type:"SplitVeSca",intentionData:t}}decodeVeScaObligationBindings(){let e=this.getVeScaObligationBindingHelpers(),t=(o,i)=>{switch(o){case"stake":return{veScaKey:i.decodeOwnedObjectId(9),obligationId:i.decodeSharedObjectId(4),obligationKey:i.decodeOwnedObjectId(3)};case"unstake":return{obligationId:i.decodeSharedObjectId(4),obligationKey:i.decodeOwnedObjectId(3)};case"deactivate":return{veScaKey:i.decodeOwnedObjectId(4),obligationId:i.decodeSharedObjectId(3)};default:throw new Error(`Invalid action ${o}`)}},n=e.map(({action:o,helper:i})=>({action:o,args:t(o,i)}));return{txType:ne.TransactionType.Other,type:"VeScaObligationBindings",intentionData:{bindingDatas:n}}}decodeTransferVeScaKey(){let e=this.commands.filter(s=>s.$kind==="TransferObjects"),{objects:t}=e[0].TransferObjects,n=t.filter(s=>s.$kind==="Input").map(({Input:s})=>s);if(n.length!==t.length)return!1;let o=new Set(n),i=this.inputs.filter((s,l)=>s.$kind==="Object"&&o.has(l)).map(s=>s.Object.ImmOrOwnedObject);return{xType:ne.TransactionType.Other,type:"TransferVeScaKeys",intentionData:{veScaKeys:i}}}};var Zu=qt(require("sort-keys-recursive")),A=class{constructor(e){this.data=e}get application(){return"msafe-core"}serialize(){return JSON.stringify((0,Zu.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:s}=t;return await this.isObligationLocked(e.scallopSuiKit.client,i)?(await o.unstakeObligationQuick(i,s),await n(e,o,t),await o.stakeObligationWithVeScaQuick(i,s,t.veScaKey)):await n(e,o,t),o}};var _a=class a extends A{constructor(t){super(t);this.data=t}txType;txSubType;async borrow({account:t,scallopClient:n}){let{coinName:o,amount:i,obligationId:s,obligationKey:l}=this.data,d=t.address;return(await this.buildTxWithRefreshObligation(n,{walletAddress:d,obligationId:s,obligationKey:l},async(I,C)=>{let x=await C.borrowQuick(+i,o,s,l);C.transferObjects([x],d)})).txBlock}async build(t){return this.borrow(t)}static fromData(t){return new a(t)}};var La=class a extends A{constructor(t){super(t);this.data=t}txType;txSubType;async borrowWithBoost(t,n){let{obligationId:o,obligationKey:i,veScaKey:s,amount:l,coinName:d}=this.data;return(await this.buildTxWithRefreshObligation(t,{walletAddress:n,obligationId:o,obligationKey:i,veScaKey:s},async(I,C)=>{let x=await C.borrowQuick(+l,d,o,i);C.transferObjects([x],n)})).txBlock}async build(t){return this.borrowWithBoost(t.scallopClient,t.account.address)}static fromData(t){return new a(t)}};var ja=class a extends A{constructor(t){super(t);this.data=t}txType;txSubType;async borrowWithReferral({account:t,scallopClient:n}){let o=t.address,{obligationId:i,obligationKey:s,veScaKey:l,coinName:d,amount:b}=this.data;return(await this.buildTxWithRefreshObligation(n,{walletAddress:o,obligationId:i,obligationKey:s,veScaKey:l},async(C,x)=>{let D=x.claimReferralTicket(d),k=await x.borrowWithReferralQuick(+b,d,D,i,s);x.burnReferralTicket(D,d),x.transferObjects([k],o)})).txBlock}async build(t){return this.borrowWithReferral(t)}static fromData(t){return new a(t)}};var tm=require("@mysten/sui/utils");var Ua=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),i=await e.query.getLendings(void 0,t),s=await e.query.getObligations(t),l=Object.values(await e.query.getObligationAccounts(t)??[]),d=(()=>{let x=[...e.constants.whitelist.spool].map(D=>e.utils.parseCoinName(D));return Object.values(i??[]).filter(D=>!!D&&x.includes(D.coinName)).reduce((D,k)=>{let P=e.utils.parseMarketCoinName(k.coinName);return D[P]||(D[P]=0),D[P]+=k.availableClaimCoin,D},{})})(),b={};Object.entries(o).forEach(([x,D])=>{for(let k=0;k<D.length;k++){let P=D[k];if(!d[x])continue;let U=n.claim(P.id,x);b.sui?b.sui.push(U):b.sui=[U]}});let I=(()=>{let x={};return x.sui=Object.values(d).reduce((D,k)=>D+k,0),l.forEach(D=>{Object.values(D.borrowIncentives).forEach(k=>{k&&k.rewards.forEach(P=>{x[P.coinName]||(x[P.coinName]=0),x[P.coinName]?x[P.coinName]+=P.availableClaimCoin:x[P.coinName]=P.availableClaimCoin})})}),x})();if(s.length>0&&l.length>0)for(let x=0;x<l.length;x++){let D=l[x],k=!1,P=s.find(K=>K.id===D.obligationId)?.keyId,U={};if(P){if(Object.values(D.borrowIncentives).forEach(K=>{if(K){let Bt=K.rewards.filter(Wt=>{let Ot=Wt.coinName;return Wt.availableClaimCoin>0&&!U[Ot]});k=Bt.length>0,Bt.forEach(Wt=>{let Ot=n.claimBorrowIncentive(D.obligationId,P,Wt.coinName);U[Wt.coinName]=!0,b[Wt.coinName]?b[Wt.coinName].push(Ot):b[Wt.coinName]=[Ot]})}}),I.sui>0){let K=$t.redeem_rewards(n,P,D.obligationId,tm.SUI_TYPE_ARG);b.sui?b.sui.push(K):b.sui=[K]}if(k&&await Qu(e.query,D.obligationId)){n.unstakeObligation(D.obligationId,P);let Bt=await e.query.getBindedVeScaKey(D.obligationId);Bt?n.stakeObligationWithVesca(D.obligationId,P,Bt):n.stakeObligation(D.obligationId,P)}}}let C=(await Promise.all(Object.entries(b).map(async([x,D])=>{let k=D[0];if(D.length>1&&n.mergeCoins(k,D.slice(1)),x==="sui"){n.mergeCoins(n.gas,[k]);return}return await e.builder.utils.mergeSimilarCoins(n,k,e.utils.parseCoinType(x),t),k}))).filter(x=>!!x);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 qa=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 Fa=class a extends A{constructor(t){super(t);this.data=t}txType;txSubType;async migrateAndClaim({account:t,scallopClient:n}){let o=t.address,{obligationKey:i,obligationId:s,rewardCoinName:l,veScaKey:d}=this.data,b=n.builder.createTxBlock();b.setSender(o);let I=$t.redeem_rewards(b,i,s,n.utils.parseCoinType(l));return b.transferObjects([I],o),await b.unstakeObligationQuick(s,i),d?await b.stakeObligationWithVeScaQuick(s,i,d):await b.stakeObligationQuick(s,i),b.txBlock}async build(t){return this.migrateAndClaim(t)}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.migrateAllMarketCoin(!1,!1)}static fromData(t){return new a(t)}};var Va=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:i,amount:s,obligationId:l,obligationKey:d}=this.data;return(await this.buildTxWithRefreshObligation(n,{walletAddress:o,obligationId:l,obligationKey:d},async(I,C)=>{await C.repayQuick(+s,i,l)})).txBlock}async build(t){return this.repay(t)}static fromData(t){return new a(t)}};var Ha=class a extends A{constructor(t){super(t);this.data=t}txType;txSubType;async repayWithBoost({account:t,scallopClient:n}){let o=t.address,{coinName:i,amount:s,obligationId:l,veScaKey:d}=this.data,b=n.builder.createTxBlock();b.setSender(o);let I=n.constants.whitelist.borrowing.has(i);return I&&await b.unstakeObligationQuick(l,void 0),await b.repayQuick(+s,i,l),I&&await b.stakeObligationWithVeScaQuick(l,void 0,d),b.txBlock}async build(t){return this.repayWithBoost(t)}static fromData(t){return new a(t)}};var Xa=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 za=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 Ga=class a extends A{constructor(t){super(t);this.data=t}txType;txSubType;async unstakeAndWithdraw(t,n,o){let i=t.builder.createTxBlock();i.setSender(o);let{stakeAccountId:s,amount:l,coinName:d}=this.data,b=[];for(let I=0;I<s.length;I++){let{id:C,coin:x}=s[I],D=t.utils.parseMarketCoinName(d),[k]=await i.unstakeQuick(x,D,C);if(k){let P=i.withdraw(k,d);b.push(P)}}if(l>0){let I=await i.withdrawQuick(l,d);b.push(I)}return b.length>1&&i.mergeCoins(b[0],b.slice(1)),i.transferObjects(b,o),i.txBlock}async build(t){return this.unstakeAndWithdraw(t.scallopClient,this.data,t.account.address)}static fromData(t){return new a(t)}};var Qa=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 Ja=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 Ya=class a extends A{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 Za=class a extends A{constructor(t){super(t);this.data=t}txType;txSubType;async claimRevenueReferral({account:t,scallopClient:n}){let{veScaKey:o,coins:i}=this.data,s=t.address,l=n.builder.createTxBlock();l.setSender(s);let d=i.map(b=>n.utils.parseCoinNameFromType(b));return await l.claimReferralRevenueQuick(o,d),l.txBlock}async build(t){return this.claimRevenueReferral(t)}static fromData(t){return new a(t)}};var ti=class a extends A{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 s=i.mintEmptyVeSca();return i.transferObjects([s],o),i.txBlock}async build(t){return this.createReferralLink(t)}static fromData(t){return new a(t)}};var em=require("@scallop-io/sui-scallop-sdk");var ei=class a extends A{constructor(t){super(t);this.data=t}txType;txSubType;async extendPeriodAndStakeMoreSca({account:t,scallopClient:n}){let{amount:o,veScaKey:i,unlockTime:s,obligationId:l,obligationKey:d,isOldBorrowIncentive:b,isObligationLocked:I}=this.data,C=t.address,x=n.builder.createTxBlock();x.setSender(C);let D=await n.utils.selectCoins(o,em.SCA_COIN_TYPE,C),[k,P]=x.takeAmountFromCoins(D,o);return x.extendLockPeriod(i,s),x.extendLockAmount(i,k),x.transferObjects([P],C),!l||!d||(I&&(b?$t.unstakeObligation(x,l,d):x.unstakeObligation(l,d)),x.stakeObligationWithVesca(l,d,i)),x.txBlock}async build(t){return this.extendPeriodAndStakeMoreSca(t)}static fromData(t){return new a(t)}};var ni=class a extends A{constructor(t){super(t);this.data=t}txType;txSubType;async extendStakeScaLockPeriod({account:t,scallopClient:n}){let o=t.address,{veScaKey:i,unlockTime:s,obligationId:l,obligationKey:d,isObligationLocked:b,isOldBorrowIncentive:I}=this.data,C=n.builder.createTxBlock();return C.setSender(o),C.extendLockPeriod(i,s),l&&d&&(b&&(I?$t.unstakeObligation(C,d,l):C.unstakeObligation(l,d)),C.stakeObligationWithVesca(l,d,i)),C.txBlock}async build(t){return this.extendStakeScaLockPeriod(t)}static fromData(t){return new a(t)}};var oi=class a extends A{constructor(t){super(t);this.data=t}txType;txSubType;async handleUnsubForKeys(t,n,o){let{targetVeScaKey:i,sourceVeScaKey:s}=this.data,[l,d]=await Promise.all([n.getBindedObligationId(i),n.getBindedObligationId(s)]);l&&await t.unstakeObligationQuick(l),d&&await t.unstakeObligationQuick(d),o(t,i,s),l&&await t.stakeObligationWithVeScaQuick(l,void 0,i),d&&await t.stakeObligationWithVeScaQuick(d,void 0,s)}async build(t){let{scallopClient:n,account:{address:o}}=t,i=n.builder.createTxBlock();return i.setSender(o),await this.handleUnsubForKeys(i,n.query,async(s,l,d)=>{s.mergeVeSca(i.object(l),i.object(d))}),i.txBlock}static fromData(t){return new a(t)}};var ai=class a extends A{constructor(t){super(t);this.data=t}txType;txSubType;async redeemSca({account:t,scallopClient:n}){let{veScaKey:o}=this.data,i=t.address,s=n.builder.createTxBlock();return s.setSender(i),await s.redeemScaQuick({veScaKey:o}),s.txBlock}async build(t){return this.redeemSca(t)}static fromData(t){return new a(t)}};var nm=require("@scallop-io/sui-scallop-sdk");var ii=class a extends A{constructor(t){super(t);this.data=t}txType;txSubType;async renewExpiredStakeSca({account:t,scallopClient:n}){let o=t.address,{amount:i,unlockTime:s,veScaKey:l,isHaveRedeem:d,obligation:b,obligationKey:I,isObligationLocked:C,isOldBorrowIncentive:x}=this.data,D=n.builder.createTxBlock();if(D.setSender(o),d){let K=D.redeemSca(l);D.transferObjects([K],o)}let k=await n.builder.utils.selectCoins(i,nm.SCA_COIN_TYPE,o),[P,U]=D.takeAmountFromCoins(k,i);return D.transferObjects([U],o),D.renewExpiredVeSca(l,P,s),!b||!I||(C&&(x?$t.unstakeObligation(D,I,b):D.unstakeObligation(b,I)),D.stakeObligationWithVesca(b,I,l)),D.txBlock}async build(t){return this.renewExpiredStakeSca(t)}static fromData(t){return new a(t)}};var ri=class a extends A{constructor(t){super(t);this.data=t}txType;txSubType;async handleUnsubForKeys(t,n,o){let{targetVeScaKey:i,splitAmount:s}=this.data,l=await n.getBindedObligationId(i);l&&await t.unstakeObligationQuick(l),o(t,i,s.toString()),l&&await t.stakeObligationWithVeScaQuick(l,void 0,i)}async build(t){let{scallopClient:n,account:{address:o}}=t,i=n.builder.createTxBlock();return i.setSender(o),await this.handleUnsubForKeys(i,n.query,(s,l,d)=>{let b=s.splitVeSca(l,d.toString());s.transferObjects([b],o)}),i.txBlock}static fromData(t){return new a(t)}};var om=require("@scallop-io/sui-scallop-sdk");var si=class a extends A{constructor(t){super(t);this.data=t}txType;txSubType;async stakeSca({account:t,scallopClient:n}){let o=t.address,{amount:i,isObligationLocked:s,isOldBorrowIncentive:l,obligationId:d,obligationKey:b,unlockTime:I,veScaKey:C}=this.data,x=n.builder.createTxBlock();x.setSender(o);let D=await n.utils.selectCoins(i,om.SCA_COIN_TYPE,o),[k,P]=x.takeAmountFromCoins(D,i),U;return C?x.extendLockAmount(C,k):U=x.lockSca(k,I),d&&b&&(s&&(l?$t.unstakeObligation(x,b,d):x.unstakeObligation(d,b)),x.stakeObligationWithVesca(d,b,C||U)),C||x.transferObjects([U,P],o),x.txBlock}async build(t){return this.stakeSca(t)}static fromData(t){return new a(t)}};var ci=class a extends A{constructor(t){super(t);this.data=t}txType;txSubType;async supplyAndStake({account:t,scallopClient:n}){let o=t.address,{amount:i,coinName:s,stakeAccountId:l}=this.data,d=n.builder.createTxBlock();d.setSender(o);let b=await d.depositQuick(+i,s),I=n.utils.parseMarketCoinName(s);if(n.constants.whitelist.spool.has(I))return d.txBlock;let C=await n.query.getStakeAccounts(I,o),x=l||(C.length>0?C[0].id:void 0);if(x)await d.stakeQuick(b,I,x);else{let D=d.createStakeAccount(I);await d.stakeQuick(b,I,D),d.transferObjects([D],o)}return d.txBlock}async build(t){return this.supplyAndStake(t)}static fromData(t){return new a(t)}};var li=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,i=n.builder.createTxBlock();i.setSender(o);let{bindingDatas:s}=this.data;return s.forEach(l=>this.handleAction(i,l)),i.txBlock}static fromData(t){return new a(t)}};var ui=class a extends A{constructor(t){super(t);this.data=t}txType;txSubType;async build(t){let{scallopClient:n,account:{address:o}}=t,i=n.builder.createTxBlock();i.setSender(o);let{veScaKeys:s}=this.data;return i.transferObjects(s.map(l=>i.objectRef(l)),i.pure.address(o)),i.txBlock}static fromData(t){return new a(t)}};var mi=class a extends A{constructor(t){super(t);this.data=t}txType;txSubType;async withdrawUnlockedSca({account:t,scallopClient:n}){let{vescaKey:o}=this.data,i=t.address,s=n.builder.createTxBlock();return s.setSender(i),await s.redeemScaQuick({veScaKey:o}),s.txBlock}async build(t){return this.withdrawUnlockedSca(t)}static fromData(t){return new a(t)}};var pi=class{application="scallop";supportSDK="@mysten/sui";scallopClient;async initScallopClient(e,t){if(!this.scallopClient){let n=new rm.Scallop({addressId:"67c44a103fe1b8c454eb9699",walletAddress:e,suiClients:[t],fullnodeUrls:[t.transport.rpcClient.requestManager.transports[0]?.uri??(0,im.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 i=new Ba(t,this.scallopClient),s=new Wa(t,this.scallopClient),l=new Na(t,this.scallopClient),d=i.decode()||s.decode()||await l.decode();if(!d)throw new Error("Unknown transaction type");return{txType:am.TransactionType.Other,txSubType:d.type,intentionData:d.intentionData}}async build(e){let{suiClient:t,account:n,network:o,txSubType:i,intentionData:s}=e;await this.initScallopClient(n.address,t);let l;switch(i){case"SupplyLending":l=Xa.fromData(s);break;case"WithdrawLending":l=Ja.fromData(s);break;case"Borrow":l=_a.fromData(s);break;case"Repay":l=$a.fromData(s);break;case"DepositCollateral":l=qa.fromData(s);break;case"WithdrawCollateral":l=Qa.fromData(s);break;case"OpenObligation":l=Va.fromData(s);break;case"UnstakeSpool":l=za.fromData(s);break;case"ClaimIncentiveReward":l=Ua.fromData(s);break;case"BorrowWithBoost":l=La.fromData(s);break;case"StakeSca":l=si.fromData(s);break;case"ExtendStakePeriod":l=ni.fromData(s);break;case"ExtendPeriodAndStakeMore":l=ei.fromData(s);break;case"RenewExpStakePeriod":l=ii.fromData(s);break;case"WithdrawStakedSca":l=mi.fromData(s);break;case"SupplyAndStakeLending":l=ci.fromData(s);break;case"WithdrawAndUnstakeLending":l=Ga.fromData(s);break;case"RedeemSca":l=ai.fromData(s);break;case"MigrateAndClaim":l=Fa.fromData(s);break;case"BorrowWithReferral":l=ja.fromData(s);break;case"CreateReferralLink":l=ti.fromData(s);break;case"ClaimRevenueReferral":l=Za.fromData(s);break;case"BindReferral":l=Ya.fromData(s);break;case"MigrateScoin":l=Ka.fromData(s);break;case"RepayWithBoost":l=Ha.fromData(s);break;case"MergeVeSca":l=oi.fromData(s);break;case"SplitVeSca":l=ri.fromData(s);break;case"VeScaObligationBindings":{l=li.fromData(s);break}case"TransferVeScaKeys":{l=ui.fromData(s);break}default:throw new Error("not implemented")}return l.build({suiClient:t,account:n,network:o,scallopClient:this.scallopClient})}};var Am=require("@msafe/sui3-utils");var cn=require("@msafe/sui3-utils"),ve=require("@mysten/sui/utils");var bm=require("@suilend/sui-fe");var ym=require("@msafe/sui3-utils"),ke=require("@suilend/sdk");var Ne=require("@msafe/sui3-utils"),rn=require("@mysten/bcs"),an=require("@mysten/sui/utils"),_e=require("@suilend/sui-fe"),_s=qt(require("bignumber.js"));var di=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,an.normalizeStructTag)(e.MintEvent.parsedJson.coin_type.name),n=e.MintEvent.parsedJson.liquidity_amount;return console.log("Decoder.decodeDeposit",t,n),{txType:Ne.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,an.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,s=new _s.default((0,rn.toHex)((0,rn.fromBase64)(this.inputs[i].Pure.bytes)),16).toString(),l=s===_e.MAX_U64.toString();return console.log("decodeWithdraw - isMax:",l,"inputIndex:",i,"inputValue:",s,"MAX_U64.toString():",_e.MAX_U64.toString()),l&&(o=_e.MAX_U64.toString()),{txType:Ne.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,an.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,s=new _s.default((0,rn.toHex)((0,rn.fromBase64)(this.inputs[i].Pure.bytes)),16).toString(),l=s===_e.MAX_U64.toString();return console.log("decodeBorrow - isMax:",l,"inputIndex:",i,"inputValue:",s,"MAX_U64.toString():",_e.MAX_U64.toString()),l&&(o=_e.MAX_U64.toString()),{txType:Ne.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,an.normalizeStructTag)(e.RepayEvent.parsedJson.coin_type.name),n=e.RepayEvent.parsedJson.liquidity_amount;return console.log("Decoder.decodeRepay",t,n),{txType:Ne.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,an.normalizeStructTag)(o.parsedJson.coin_type.name),s=o.parsedJson.liquidity_amount;t[i]=`${+(t[i]??"0")+ +s}`}return console.log("Decoder.decodeClaimRewards",t),{txType:Ne.TransactionType.Other,type:"claim",intentionData:{value:t}}}decodeClaimAndDeposit(){return{txType:Ne.TransactionType.Other,type:"claimAndDeposit",intentionData:this.decodeClaim().intentionData}}};var cm=require("@mysten/sui/transactions");var sm=qt(require("sort-keys-recursive")),Ut=class{constructor(e){this.data=e}serialize(){return JSON.stringify((0,sm.default)(this.data))}};var fi=class a extends Ut{constructor(t){super(t);this.data=t}txType;txSubType;async build(t){let{suiClient:n,account:o,suilendClient:i,obligationOwnerCap:s,obligation:l}=t;if(console.log("BorrowIntention.build",n,o,i,s,l),!s||!l)throw new Error("Obligation not found");let d=new cm.Transaction;return await i.borrowAndSendToUser(o.address,s.id,l.id,this.data.coinType,this.data.value,d),d}static fromData(t){return console.log("BorrowIntention.fromData",t),new a(t)}};var pm=require("@mysten/sui/transactions");var lm=require("@mysten/sui/utils"),sn=require("@suilend/sdk"),um=require("@suilend/sui-fe"),mm=qt(require("bignumber.js")),uf=(a,e)=>{let t={[sn.Side.DEPOSIT]:[],[sn.Side.BORROW]:[]};return a.lendingMarket.reserves.forEach(n=>{[sn.Side.DEPOSIT,sn.Side.BORROW].forEach(o=>{let i=o===sn.Side.DEPOSIT?n.depositsPoolRewardManager:n.borrowsPoolRewardManager,s=e.userRewardManagers.find(l=>l.poolRewardManagerId===i.id);s&&(t[o]=i.poolRewards.map((l,d)=>({reserveArrayIndex:n.arrayIndex,rewardIndex:BigInt(d),rewardCoinType:(0,lm.normalizeStructTag)(l.coinType.name),side:o})).filter(l=>!(0,um.isSendPoints)(l.rewardCoinType)&&!!s.rewards[Number(l.rewardIndex)]&&new mm.default(s.rewards[Number(l.rewardIndex)].earnedRewards.value.toString()).gt(0)))})}),Object.values(t).flat()},hi=uf;var gi=class a extends Ut{constructor(t){super(t);this.data=t}txType;txSubType;async build(t){let{suiClient:n,account:o,suilendClient:i,obligationOwnerCap:s,obligation:l}=t;if(console.log("ClaimIntention.build",n,o,i,s,l),!s||!l)throw new Error("Obligation not found");let d=new pm.Transaction;return i.claimRewardsAndSendToUser(o.address,s.id,hi(i,l),d),d}static fromData(t){return console.log("ClaimIntention.fromData",t),new a(t)}};var dm=require("@mysten/sui/transactions");var yi=class a extends Ut{constructor(t){super(t);this.data=t}txType;txSubType;async build(t){let{suiClient:n,account:o,suilendClient:i,obligationOwnerCap:s,obligation:l}=t;if(console.log("ClaimAndDepositIntention.build",n,o,i,s,l),!s||!l)throw new Error("Obligation not found");let d=new dm.Transaction;return i.claimRewardsAndDeposit(o.address,s.id,hi(i,l),d),d}static fromData(t){return console.log("ClaimAndDepositIntention.fromData",t),new a(t)}};var fm=require("@mysten/sui/transactions");var bi=class a extends Ut{constructor(t){super(t);this.data=t}txType;txSubType;async build(t){let{suiClient:n,account:o,suilendClient:i,obligationOwnerCap:s,obligation:l}=t;console.log("DepositIntention.build",n,o,i,s,l);let d=new fm.Transaction;return await i.depositIntoObligation(o.address,this.data.coinType,this.data.value,d,s?.id),d}static fromData(t){return console.log("DepositIntention.fromData",t),new a(t)}};var hm=require("@mysten/sui/transactions");var Ti=class a extends Ut{constructor(t){super(t);this.data=t}txType;txSubType;async build(t){let{suiClient:n,account:o,suilendClient:i,obligationOwnerCap:s,obligation:l}=t;if(console.log("RepayIntention.build",n,o,i,s,l),!s||!l)throw new Error("Obligation not found");let d=new hm.Transaction;return await i.repayIntoObligation(o.address,l.id,this.data.coinType,this.data.value,d),d}static fromData(t){return console.log("RepayIntention.fromData",t),new a(t)}};var gm=require("@mysten/sui/transactions");var Si=class a extends Ut{constructor(t){super(t);this.data=t}txType;txSubType;async build(t){let{suiClient:n,account:o,suilendClient:i,obligationOwnerCap:s,obligation:l}=t;if(console.log("WithdrawIntention.build",n,o,i,s,l),!s||!l)throw new Error("Obligation not found");let d=new gm.Transaction;return await i.withdrawAndSendToUser(o.address,s.id,l.id,this.data.coinType,this.data.value,d),d}static fromData(t){return console.log("WithdrawIntention.fromData",t),new a(t)}};var Ii=async(a,e)=>{let t=await ke.SuilendClient.initialize(ke.LENDING_MARKET_ID,ke.LENDING_MARKET_TYPE,a),n=await ke.SuilendClient.getObligationOwnerCaps(e.address,t.lendingMarket.$typeArgs,a),o=await Promise.all(n.map(i=>ke.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}},wi=class{application="Suilend";supportSDK="@mysten/sui";utils;async deserialize(e){let{transaction:t,suiClient:n,account:o}=e;this.utils||(this.utils=await Ii(n,o));let i=await n.devInspectTransactionBlock({sender:o.address,transactionBlock:t});console.log("SuilendAppHelper.deserialize - simResult:",i,"utils:",this.utils,"suiClient:",n);let l=new di(t,i).decode();return{txType:ym.TransactionType.Other,txSubType:l.type,intentionData:l.intentionData}}async build(e){let{network:t,txSubType:n,intentionData:o,suiClient:i,account:s}=e;this.utils||(this.utils=await Ii(i,s));let l;switch(n){case"deposit":l=bi.fromData(o);break;case"withdraw":l=Si.fromData(o);break;case"borrow":l=fi.fromData(o);break;case"repay":l=Ti.fromData(o);break;case"claim":l=gi.fromData(o);break;case"claimAndDeposit":l=yi.fromData(o);break;default:throw new Error("not implemented")}let d=window.localStorage.getItem("obligationId"),b=this.utils.obligations?.find(C=>C.id===d)??this.utils.obligations?.[0],I=this.utils.obligationOwnerCaps?.find(C=>C.obligationId===b?.id);return l.build({network:t,suiClient:i,account:s,suilendClient:this.utils.suilendClient,obligationOwnerCap:I,obligation:b})}};var Ls=async(a,e)=>{let t=await Ii(a,e),n=await fetch(`${bm.API_URL}/springsui/lst-info`),o=await n.json();if(n?.statusCode===500)throw new Error("Failed to fetch SpringSui LST data");let s=Object.fromEntries(Object.values(o).map(l=>[l.LIQUID_STAKING_INFO.type,l.LIQUID_STAKING_INFO]));return{...t,LIQUID_STAKING_INFO_MAP:s}};var Ci=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,ve.normalizeStructTag)(e.MintEvent.parsedJson.event.typename.name),n=e.MintEvent.parsedJson.event.sui_amount_in;return console.log("Decoder.decodeStake",n),{txType:cn.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,ve.normalizeStructTag)(e.MintEvent.parsedJson.event.typename.name),n=e.MintEvent.parsedJson.event.sui_amount_in;return console.log("Decoder.decodeStakeAndDeposit",n),{txType:cn.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,ve.normalizeStructTag)(e.RedeemEvent.parsedJson.event.typename.name),n=(0,ve.normalizeStructTag)(e.MintEvent.parsedJson.event.typename.name),o=e.RedeemEvent.parsedJson.event.lst_amount_in;return console.log("Decoder.decodeConvert",o),{txType:cn.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,ve.normalizeStructTag)(e.RedeemEvent.parsedJson.event.typename.name),n=(0,ve.normalizeStructTag)(e.MintEvent.parsedJson.event.typename.name),o=e.RedeemEvent.parsedJson.event.lst_amount_in;return console.log("Decoder.decodeConvertAndDeposit",o),{txType:cn.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,ve.normalizeStructTag)(e.RedeemEvent.parsedJson.event.typename.name),n=e.RedeemEvent.parsedJson.event.lst_amount_in;return console.log("Decoder.decodeUnstake",n),{txType:cn.TransactionType.Other,type:"unstake",intentionData:{amount:n,inCoinType:t}}}};var Sm=require("@mysten/sui/transactions"),jn=require("@suilend/springsui-sdk");var Tm=qt(require("sort-keys-recursive")),Ht=class{constructor(e){this.data=e}serialize(){return JSON.stringify((0,Tm.default)(this.data))}};var xi=class a extends Ht{constructor(t){super(t);this.data=t}txType;txSubType;async build(t){let{suiClient:n,account:o,suilendClient:i,LIQUID_STAKING_INFO_MAP:s,obligationOwnerCap:l,obligation:d}=t;console.log("ConvertIntention.build",n,o,i,s,l,d);let b=await jn.LstClient.initialize(n,Object.values(s).find(x=>x.type===this.data.inCoinType)),I=await jn.LstClient.initialize(n,Object.values(s).find(x=>x.type===this.data.outCoinType)),C=new Sm.Transaction;return(0,jn.convertLstsAndRebalanceAndSendToUser)(b,I,C,o.address,this.data.amount),C}static fromData(t){return console.log("ConvertIntention.fromData",t),new a(t)}};var Im=require("@mysten/sui/transactions"),ki=require("@suilend/sdk"),Un=require("@suilend/springsui-sdk");var Di=class a extends Ht{constructor(t){super(t);this.data=t}txType;txSubType;async build(t){let{suiClient:n,account:o,suilendClient:i,LIQUID_STAKING_INFO_MAP:s,obligationOwnerCap:l,obligation:d}=t;console.log("ConvertAndDepositIntention.build",n,o,i,s,l,d);let b=await Un.LstClient.initialize(n,Object.values(s).find(P=>P.type===this.data.inCoinType)),I=await Un.LstClient.initialize(n,Object.values(s).find(P=>P.type===this.data.outCoinType)),C=new Im.Transaction,{obligationOwnerCapId:x,didCreate:D}=(0,ki.createObligationIfNoneExists)(i,C,l),k=(0,Un.convertLstsAndRebalance)(b,I,C,o.address,this.data.amount);return i.deposit(k,this.data.outCoinType,x,C),D&&(0,ki.sendObligationToUser)(x,o.address,C),C}static fromData(t){return console.log("ConvertAndDepositIntention.fromData",t),new a(t)}};var wm=require("@mysten/sui/transactions"),Cm=require("@suilend/springsui-sdk");var vi=class a extends Ht{constructor(t){super(t);this.data=t}txType;txSubType;async build(t){let{suiClient:n,account:o,suilendClient:i,LIQUID_STAKING_INFO_MAP:s,obligationOwnerCap:l,obligation:d}=t;console.log("StakeIntention.build",n,o,i,s,l,d);let b=await Cm.LstClient.initialize(n,Object.values(s).find(C=>C.type===this.data.outCoinType)),I=new wm.Transaction;return b.mintAmountAndRebalanceAndSendToUser(I,o.address,this.data.amount),I}static fromData(t){return console.log("StakeIntention.fromData",t),new a(t)}};var xm=require("@mysten/sui/transactions"),Mi=require("@suilend/sdk"),Dm=require("@suilend/springsui-sdk");var Ai=class a extends Ht{constructor(t){super(t);this.data=t}txType;txSubType;async build(t){let{suiClient:n,account:o,suilendClient:i,LIQUID_STAKING_INFO_MAP:s,obligationOwnerCap:l,obligation:d}=t;console.log("StakeAndDepositIntention.build",n,o,i,s,l,d);let b=await Dm.LstClient.initialize(n,Object.values(s).find(k=>k.type===this.data.outCoinType)),I=new xm.Transaction,{obligationOwnerCapId:C,didCreate:x}=(0,Mi.createObligationIfNoneExists)(i,I,l),D=b.mintAmountAndRebalance(I,o.address,this.data.amount);return i.deposit(D,this.data.outCoinType,C,I),x&&(0,Mi.sendObligationToUser)(C,o.address,I),I}static fromData(t){return console.log("StakeAndDepositIntention.fromData",t),new a(t)}};var km=require("@mysten/sui/transactions"),vm=require("@suilend/springsui-sdk");var Oi=class a extends Ht{constructor(t){super(t);this.data=t}txType;txSubType;async build(t){let{suiClient:n,account:o,suilendClient:i,LIQUID_STAKING_INFO_MAP:s,obligationOwnerCap:l,obligation:d}=t;console.log("UnstakeIntention.build",n,o,i,s,l,d);let b=await vm.LstClient.initialize(n,Object.values(s).find(C=>C.type===this.data.inCoinType)),I=new km.Transaction;return b.redeemAmountAndRebalanceAndSendToUser(I,o.address,this.data.amount),I}static fromData(t){return console.log("UnstakeIntention.fromData",t),new a(t)}};var Pi=class{application="SpringSui";supportSDK="@mysten/sui";utils;async deserialize(e){let{transaction:t,suiClient:n,account:o}=e;this.utils||(this.utils=await Ls(n,o));let i=await n.devInspectTransactionBlock({sender:o.address,transactionBlock:t});console.log("SpringSuiAppHelper.deserialize",i);let l=new Ci(t,i).decode();return{txType:Am.TransactionType.Other,txSubType:l.type,intentionData:l.intentionData}}async build(e){let{network:t,txSubType:n,intentionData:o,suiClient:i,account:s}=e;this.utils||(this.utils=await Ls(i,s));let l;switch(n){case"stake":l=vi.fromData(o);break;case"stakeAndDeposit":l=Ai.fromData(o);break;case"convert":l=xi.fromData(o);break;case"convertAndDeposit":l=Di.fromData(o);break;case"unstake":l=Oi.fromData(o);break;default:throw new Error("not implemented")}return l.build({network:t,suiClient:i,account:s,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 Pm=require("@msafe/sui3-utils");var js=require("@msafe/sui3-utils");var Ri=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:js.TransactionType.Other,type:"mint",intentionData:{amount:t}}}decodeRedeem(e){let{event:{lst_amount_in:t}}=e;return console.log("Decoder.decodeRedeem",t),{txType:js.TransactionType.Other,type:"redeem",intentionData:{amount:t}}}};var Mm=require("@alphafi/stsui-sdk");var Bi=class a extends S{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"},l=await new Mm.LST(i).mint(o,n.address);return l.setGasBudget(1e8),l}static fromData(t){return console.log("MintIntention.fromData",t),new a(t)}};var Om=require("@alphafi/stsui-sdk");var Ei=class a extends S{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"},l=await new Om.LST(i).redeem(o,n.address);return l.setGasBudget(1e8),l}static fromData(t){return console.log("RedeemIntention.fromData",t),new a(t)}};var Wi=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 s=new Ri(t,o).decode();return{txType:Pm.TransactionType.Other,txSubType:s.type,intentionData:s.intentionData}}async build(e){let{account:t}=e;console.log("StSui build transaction type",e.txSubType);let n;switch(e.txSubType){case"mint":n=Bi.fromData(e.intentionData);break;case"redeem":n=Ei.fromData(e.intentionData);break;default:throw new Error("build not implemented")}return n.build({account:t})}};var ep=require("@msafe/sui3-utils"),np=require("turbos-clmm-sdk");var Et=require("@msafe/sui3-utils"),Le=require("@mysten/bcs"),je=require("@mysten/sui/bcs"),Rm=require("turbos-clmm-sdk");var zt={PackageId:"0x02fe4933f4521250e55a15441096d1d4a38a7311195b0bca126fc0138c1f5a97",Claim:"0x0c822cec42f7ca703696b4232f1c47b348330c23580172a29aab465bc071d894",turbosCoinType:"0x5d1f47ea69bb0de31c313d7acf89b890dbb8991ea8e03c6c355171f84bb1ba4a::turbos::TURBOS"},Gt={PackageId:"0xdee9"};var ff=(a,e,t,n)=>{if(a===1)switch(n.findIndex(s=>s===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}`)}},Ni=class{constructor(e,t,n){this.txb=e;this.turbosSdk=t;this.config=n}get transactions(){return this.txb.getData().commands}get swap1Layer(){return[`${this.config.PackageId}::swap_router::swap_a_b`,`${this.config.PackageId}::swap_router::swap_b_a`]}get swap2Layer(){return[`${this.config.PackageId}::swap_router::swap_a_b_b_c`,`${this.config.PackageId}::swap_router::swap_a_b_c_b`,`${this.config.PackageId}::swap_router::swap_b_a_b_c`,`${this.config.PackageId}::swap_router::swap_b_a_c_b`]}async decode(e){if(this.isSwapTransaction())return this.decodeSwap();if(this.isAddLiquidityTransaction())return this.decodeAddLiquidity();if(this.isIncreaseLiquidityTransaction())return this.decodeIncreaseLiquidity(e);if(this.isRemoveLiquidityTransaction())return this.decodeRemoveLiquidity(e);if(this.isDecreaseLiquidityTransaction())return this.decodeDecreaseLiquidity(e);if(this.isRemoveLiquidityWithReturnTransaction())return this.decodeRemoveLiquidityWithReturn(e);if(this.isDecreaseLiquidityWithReturnTransaction())return this.decodeDecreaseLiquidityWithReturn(e);if(this.isCollectFeeTransaction())return this.decodeCollectFee();if(this.isCollectRewardTransaction())return this.decodeCollectReward();if(this.isBurnTransaction())return this.decodeBurn();if(this.isPrixClaimTransaction())return this.decodePrixClaim();if(this.isPrixJoinTransaction())return this.decodePrixJoin();if(this.isSwapExactBaseForQuoteTransaction())return this.decodeSwapExactBaseForQuote();if(this.isSwapExactQuoteForBaseTransaction())return this.decodeSwapExactQuoteForBase();throw new Error("Unknown transaction type")}getMoveCallTransaction(e){return this.transactions.find(t=>t.$kind==="MoveCall"?`${t.MoveCall.package}::${t.MoveCall.module}::${t.MoveCall.function}`===e:!1)}getMoveCallsTransaction(e){return e.every(t=>this.transactions.find(n=>n.$kind==="MoveCall"?`${n.MoveCall.package}::${n.MoveCall.module}::${n.MoveCall.function}`===t:!1))}getSwapMoveCallTransaction(e){return this.transactions.find(t=>{if(t.$kind==="MoveCall"){let n=`${t.MoveCall.package}::${t.MoveCall.module}::${t.MoveCall.function}`;return!!e.includes(n)}return!1})}isSwapTransaction(){return!!this.getSwapMoveCallTransaction([...this.swap1Layer,...this.swap2Layer])}isAddLiquidityTransaction(){return!!this.getMoveCallTransaction(`${this.config.PackageId}::position_manager::mint`)}isIncreaseLiquidityTransaction(){return!!this.getMoveCallTransaction(`${this.config.PackageId}::position_manager::increase_liquidity`)}isDecreaseLiquidityTransaction(){return!!this.getMoveCallTransaction(`${this.config.PackageId}::position_manager::decrease_liquidity`)}isDecreaseLiquidityWithReturnTransaction(){return!!this.getMoveCallTransaction(`${this.config.PackageId}::position_manager::decrease_liquidity_with_return_`)}isCollectFeeTransaction(){return!!this.getMoveCallTransaction(`${this.config.PackageId}::position_manager::collect`)}isCollectRewardTransaction(){return!!this.getMoveCallTransaction(`${this.config.PackageId}::position_manager::collect_reward`)}isBurnTransaction(){return!!this.getMoveCallTransaction(`${this.config.PackageId}::position_manager::burn`)}isPrixJoinTransaction(){return!!this.getMoveCallTransaction(`${zt.PackageId}::claim::join`)}isPrixClaimTransaction(){return!!this.getMoveCallTransaction(`${zt.PackageId}::claim::claim`)}isRemoveLiquidityTransaction(){return!!this.getMoveCallsTransaction([`${this.config.PackageId}::position_manager::decrease_liquidity`,`${this.config.PackageId}::position_manager::burn`])}isRemoveLiquidityWithReturnTransaction(){return!!this.getMoveCallsTransaction([`${this.config.PackageId}::position_manager::decrease_liquidity_with_return_`,`${this.config.PackageId}::position_manager::burn`])}isSwapExactBaseForQuoteTransaction(){return!!this.getMoveCallTransaction(`${Gt.PackageId}::clob_v2::swap_exact_base_for_quote`)}isSwapExactQuoteForBaseTransaction(){return!!this.getMoveCallTransaction(`${Gt.PackageId}::clob_v2::swap_exact_quote_for_base`)}async decodeSwap(){let e=this.transactions.find(D=>D.$kind==="MoveCall"),t=0,n=`${e.MoveCall.package}::${e.MoveCall.module}::${e.MoveCall.function}`;console.log(n,"moveCallTarget"),this.swap2Layer.includes(n)&&(t=1);let o=ff(t,n,this.swap1Layer,this.swap2Layer),i=o.map((D,k)=>{let P=this.helper.decodeSharedObjectId(this.helper.getInputsIndex(k)),U=this.helper.decodeInputU128(this.helper.getInputsIndex(4+k+t)),K=this.turbosSdk.math.sqrtPriceX64ToTickIndex(new Rm.BN(U.toString()));return{pool:P,a2b:D,nextTickIndex:K}}),s=o[0]||t===1?e.MoveCall.typeArguments[0]:e.MoveCall.typeArguments[1],l=t===1?e.MoveCall.typeArguments[4]:o[0]?e.MoveCall.typeArguments[1]:e.MoveCall.typeArguments[0],d=this.helper.decodeInputAddress(this.helper.getInputsIndex(6+2*t)),b=this.helper.decodeInputU64(this.helper.getInputsIndex(7+2*t)),I=this.helper.decodeInputBool(this.helper.getInputsIndex(5+2*t)),C=this.helper.decodeInputU64(this.helper.getInputsIndex(2+t)),x=this.helper.decodeInputU64(this.helper.getInputsIndex(3+t));return{txType:Et.TransactionType.Other,type:"Swap",intentionData:{routes:i,coinTypeA:s,coinTypeB:l,address:d,amountA:I?C:x,amountB:I?x:C,amountSpecifiedIsInput:I,slippage:"0.1",deadline:b}}}decodeAddLiquidity(){console.log(this.helper,"decodeAddLiquidity this.helper");let e=this.helper.decodeSharedObjectId(this.helper.getInputsIndex(0)),t=this.helper.decodeInputAddress(this.helper.getInputsIndex(12)),n=this.helper.decodeInputU64(this.helper.getInputsIndex(8)),o=this.helper.decodeInputU64(this.helper.getInputsIndex(9)),i=this.helper.decodeInputU32(this.helper.getInputsIndex(4)),s=this.helper.decodeInputBool(this.helper.getInputsIndex(5)),l=this.helper.decodeInputU32(this.helper.getInputsIndex(6)),d=this.helper.decodeInputBool(this.helper.getInputsIndex(7)),b=this.helper.decodeInputU64(this.helper.getInputsIndex(13));return{txType:Et.TransactionType.Other,type:"AddLiquidity",intentionData:{pool:e,slippage:30,address:t,amountA:n,amountB:o,tickLower:s?-i:i,tickUpper:d?-l:l,deadline:b}}}decodeIncreaseLiquidity(e){console.log(this.helper,"decodeIncreaseLiquidity this.helper");let t=this.helper.decodeSharedObjectId(this.helper.getInputsIndex(0)),n=this.helper.decodeOwnedObjectId(this.helper.getInputsIndex(4)),o=this.helper.decodeInputU64(this.helper.getInputsIndex(5)),i=this.helper.decodeInputU64(this.helper.getInputsIndex(6)),s=this.helper.decodeInputU64(this.helper.getInputsIndex(9));return{txType:Et.TransactionType.Other,type:"IncreaseLiquidity",intentionData:{pool:t,slippage:30,address:e,amountA:o,amountB:i,nft:n,deadline:s}}}decodeDecreaseLiquidity(e){console.log(this.helper,"decodeDecreaseLiquidity this.helper");let t=this.helper.decodeSharedObjectId(this.helper.getInputsIndex(0)),n=this.helper.decodeOwnedObjectId(this.helper.getInputsIndex(2)),o=this.helper.decodeInputU64(this.helper.getInputsIndex(3)),i=this.helper.decodeInputU64(this.helper.getInputsIndex(4)),s=this.helper.decodeInputU64(this.helper.getInputsIndex(5)),l=this.helper.decodeInputU64(this.helper.getInputsIndex(6));return{txType:Et.TransactionType.Other,type:"DecreaseLiquidity",intentionData:{pool:t,decreaseLiquidity:o,nft:n,amountA:i,amountB:s,slippage:10,address:e,deadline:l}}}decodeDecreaseLiquidityWithReturn(e){console.log(this.helper,"decodeDecreaseLiquidityWithReturn this.helper");let t=this.helper.decodeSharedObjectId(0),n=this.helper.decodeOwnedObjectId(2),o=this.helper.decodeInputU64(3),i=this.helper.decodeInputU64(4),s=this.helper.decodeInputU64(5),l=this.helper.decodeInputU64(6);return{txType:Et.TransactionType.Other,type:"DecreaseLiquidityWithReturn",intentionData:{pool:t,decreaseLiquidity:o,nft:n,amountA:i,amountB:s,slippage:10,address:e,deadline:l}}}decodeCollectFee(){console.log(this.helper,"decodeCollectFee this.helper");let e=this.helper.decodeSharedObjectId(this.helper.getInputsIndex(0)),t=this.helper.decodeOwnedObjectId(this.helper.getInputsIndex(2)),n=this.helper.decodeInputAddress(this.helper.getInputsIndex(5)),o=this.helper.decodeInputU64(this.helper.getInputsIndex(3)),i=this.helper.decodeInputU64(this.helper.getInputsIndex(4)),s=this.helper.decodeInputU64(this.helper.getInputsIndex(6));return{txType:Et.TransactionType.Other,type:"CollectFee",intentionData:{pool:e,address:n,collectAmountA:o,collectAmountB:i,nft:t,deadline:s}}}decodeCollectReward(){console.log(this.helper,"decodeCollectReward this.helper");let e=this.helper.decodeSharedObjectId(this.helper.getInputsIndex(0)),t=this.helper.decodeOwnedObjectId(this.helper.getInputsIndex(2)),n=this.helper.decodeInputAddress(this.helper.getInputsIndex(6)),o=[0,0,0];this.collectRewardHelper.forEach(s=>{let l=s.decodeInputU64(s.getInputsIndex(4)),d=s.decodeInputU64(s.getInputsIndex(5));o[l]=d});let i=this.helper.decodeInputU64(7);return{txType:Et.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(this.helper.getInputsIndex(0)),t=this.helper.decodeOwnedObjectId(this.helper.getInputsIndex(2));return{txType:Et.TransactionType.Other,type:"Burn",intentionData:{pool:e,nft:t}}}decodeRemoveLiquidity(e){console.log(this.helper,"decodeRemoveLiquidity this.helper");let t=30,n=this.decreaseLiquidityHelper.decodeSharedObjectId(this.decreaseLiquidityHelper.getInputsIndex(0)),o=this.decreaseLiquidityHelper.decodeOwnedObjectId(this.decreaseLiquidityHelper.getInputsIndex(2)),i=this.decreaseLiquidityHelper.decodeInputU64(this.decreaseLiquidityHelper.getInputsIndex(3)),s=this.decreaseLiquidityHelper.decodeInputU64(this.decreaseLiquidityHelper.getInputsIndex(4)),l=this.decreaseLiquidityHelper.decodeInputU64(this.decreaseLiquidityHelper.getInputsIndex(5)),d=this.decreaseLiquidityHelper.decodeInputU64(this.decreaseLiquidityHelper.getInputsIndex(6)),b=[0,0,0];this.collectRewardHelper.forEach(x=>{let D=x.decodeInputU64(x.getInputsIndex(4)),k=x.decodeInputU64(x.getInputsIndex(5));b[D]=k});let I=this.collectFeeHelper.decodeInputU64(this.collectFeeHelper.getInputsIndex(3))||0,C=this.collectFeeHelper.decodeInputU64(this.collectFeeHelper.getInputsIndex(4))||0;return{txType:Et.TransactionType.Other,type:"RemoveLiquidity",intentionData:{pool:n,decreaseLiquidity:i,nft:o,amountA:(s/(100-t)*100).toFixed(0),amountB:(l/(100-t)*100).toFixed(0),slippage:t,address:e,collectAmountA:I,collectAmountB:C,rewardAmounts:b,deadline:d}}}decodeRemoveLiquidityWithReturn(e){console.log(this.helper,"decodeRemoveLiquidityWithReturn this.helper");let t=this.decreaseLiquidityHelper.decodeSharedObjectId(0),n=this.decreaseLiquidityHelper.decodeOwnedObjectId(2),o=this.decreaseLiquidityHelper.decodeInputU64(3),i=this.decreaseLiquidityHelper.decodeInputU64(4),s=this.decreaseLiquidityHelper.decodeInputU64(5),l=this.decreaseLiquidityHelper.decodeInputU64(6),d=this.collectRewardHelper.map(C=>C.decodeInputU64(5)),b=this.collectFeeHelper.decodeInputU64(3)||0,I=this.collectFeeHelper.decodeInputU64(4)||0;return{txType:Et.TransactionType.Other,type:"removeLiquidityWithReturn",intentionData:{pool:t,decreaseLiquidity:o,nft:n,amountA:i,amountB:s,slippage:10,address:e,collectAmountA:b,collectAmountB:I,rewardAmounts:d,deadline:l}}}decodePrixClaim(){return{txType:Et.TransactionType.Other,type:"PrixClaim",intentionData:{}}}decodePrixJoin(){return{txType:Et.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:Et.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:Et.TransactionType.Other,type:"SwapExactQuoteForBase",intentionData:{poolId:e,amountIn:t,token1:n,token2:o}}}get helper(){let e=this.transactions.find(t=>{if(t.$kind==="MoveCall"){let n=`${t.MoveCall.package}::${t.MoveCall.module}::${t.MoveCall.function}`;return n!=="0x2::coin::zero"&&n!=="0x0000000000000000000000000000000000000000000000000000000000000002::coin::zero"}return!1});return new Ae(e,this.txb)}get collectRewardHelper(){return this.transactions.filter(t=>t.$kind==="MoveCall"?`${t.MoveCall.package}::${t.MoveCall.module}::${t.MoveCall.function}`===`${this.config.PackageId}::position_manager::collect_reward`:!1).map(t=>new Ae(t,this.txb))}get collectFeeHelper(){let e=this.transactions.find(t=>t.$kind==="MoveCall"?`${t.MoveCall.package}::${t.MoveCall.module}::${t.MoveCall.function}`===`${this.config.PackageId}::position_manager::collect`:!1);return new Ae(e,this.txb)}get decreaseLiquidityHelper(){let e=this.transactions.find(t=>t.$kind==="MoveCall"?`${t.MoveCall.package}::${t.MoveCall.module}::${t.MoveCall.function}`===`${this.config.PackageId}::position_manager::decrease_liquidity`:!1);return new Ae(e,this.txb)}get swapExactBaseForQuoteHelper(){let e=this.transactions.find(t=>t.$kind==="MoveCall"?`${t.MoveCall.package}::${t.MoveCall.module}::${t.MoveCall.function}`===`${Gt.PackageId}::clob_v2::swap_exact_base_for_quote`:!1);return new Ae(e,this.txb)}get swapExactQuoteForBaseHelper(){let e=this.transactions.find(t=>t.$kind==="MoveCall"?`${t.MoveCall.package}::${t.MoveCall.module}::${t.MoveCall.function}`===`${Gt.PackageId}::clob_v2::swap_exact_quote_for_base`:!1);return new Ae(e,this.txb)}},Ae=class{constructor(e,t){this.moveCall=e;this.txb=t}get inputs(){return this.txb.getData().inputs}getInputsIndex(e){return this.moveCall.MoveCall.arguments[e].Input}decodeSharedObjectId(e){return this.inputs[e].Object?.SharedObject?.objectId||this.inputs[e].UnresolvedObject.objectId}decodeOwnedObjectId(e){return this.inputs[e].Object?.ImmOrOwnedObject?.objectId||this.inputs[e].UnresolvedObject.objectId}decodeInputU128(e){return Number(je.bcs.u128().parse(Uint8Array.from((0,Le.fromBase64)(this.inputs[e].Pure.bytes))))}decodeInputU64(e){return Number(je.bcs.u64().parse(Uint8Array.from((0,Le.fromBase64)(this.inputs[e].Pure.bytes))))}decodeInputU32(e){return Number(je.bcs.u32().parse(Uint8Array.from((0,Le.fromBase64)(this.inputs[e].Pure.bytes))))}decodeInputU8(e){return Number(je.bcs.u8().parse(Uint8Array.from((0,Le.fromBase64)(this.inputs[e].Pure.bytes))))}decodeInputAddress(e){return je.bcs.Address.parse(Uint8Array.from((0,Le.fromBase64)(this.inputs[e].Pure.bytes)))}decodeInputBool(e){return je.bcs.bool().parse(Uint8Array.from((0,Le.fromBase64)(this.inputs[e].Pure.bytes)))}shortTypeArg(e){return this.moveCall.MoveCall.typeArguments[e]}txArg(e){return this.moveCall.MoveCall.arguments[e]}};var Bm=require("turbos-clmm-sdk");var _i=class a extends S{constructor(t){super(t);this.data=t}txType;txSubType;async build(t){let n=new Bm.TurbosSdk(t.network.replace("sui:",""),t.suiClient),{pool:o,address:i,amountA:s,amountB:l,slippage:d,tickLower:b,tickUpper:I,deadline:C,txb:x}=this.data;return n.pool.addLiquidity({pool:o,slippage:d,address:i,amountA:s,amountB:l,tickLower:b,tickUpper:I,deadline:C,txb:x})}static fromData(t){return new a(t)}};var Em=require("turbos-clmm-sdk");var Li=class a extends S{constructor(t){super(t);this.data=t}txType;txSubType;async build(t){let n=new Em.TurbosSdk(t.network.replace("sui:",""),t.suiClient),{pool:o,nft:i,txb:s}=this.data;return n.position.burn({pool:o,nft:i,txb:s})}static fromData(t){return new a(t)}};var Wm=require("turbos-clmm-sdk");var ji=class a extends S{constructor(t){super(t);this.data=t}txType;txSubType;async build(t){let n=new Wm.TurbosSdk(t.network.replace("sui:",""),t.suiClient),{pool:o,address:i,nft:s,collectAmountA:l,collectAmountB:d,deadline:b,txb:I}=this.data;return n.pool.collectFee({pool:o,address:i,collectAmountA:l,collectAmountB:d,nft:s,deadline:b,txb:I})}static fromData(t){return new a(t)}};var Nm=require("turbos-clmm-sdk");var Ui=class a extends S{constructor(t){super(t);this.data=t}txType;txSubType;async build(t){let n=new Nm.TurbosSdk(t.network.replace("sui:",""),t.suiClient),{pool:o,address:i,nft:s,rewardAmounts:l,deadline:d,txb:b}=this.data;return n.pool.collectReward({pool:o,address:i,rewardAmounts:l,nft:s,deadline:d,txb:b})}static fromData(t){return new a(t)}};var _m=require("turbos-clmm-sdk");var qi=class a extends S{constructor(t){super(t);this.data=t}txType;txSubType;async build(t){let n=new _m.TurbosSdk(t.network.replace("sui:",""),t.suiClient),{fee:o,address:i,tickLower:s,tickUpper:l,sqrtPrice:d,slippage:b,coinTypeA:I,coinTypeB:C,amountA:x,amountB:D,deadline:k,txb:P}=this.data;return n.pool.createPool({fee:o,amountA:x,amountB:D,address:i,tickLower:s,tickUpper:l,sqrtPrice:d,slippage:b,coinTypeA:I,coinTypeB:C,deadline:k,txb:P})}static fromData(t){return new a(t)}};var Lm=require("turbos-clmm-sdk");var Fi=class a extends S{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:i,amountA:s,amountB:l,slippage:d,nft:b,decreaseLiquidity:I,deadline:C,txb:x}=this.data;return n.pool.decreaseLiquidity({pool:o,slippage:d,address:i,amountA:s,amountB:l,nft:b,decreaseLiquidity:I,deadline:C,txb:x})}static fromData(t){return new a(t)}};var jm=require("turbos-clmm-sdk");var Ki=class a extends S{constructor(t){super(t);this.data=t}txType;txSubType;async build(t){let n=new jm.TurbosSdk(t.network.replace("sui:",""),t.suiClient),{pool:o,address:i,amountA:s,amountB:l,slippage:d,nft:b,decreaseLiquidity:I,deadline:C}=this.data,{txb:x,coinA:D,coinB:k}=await n.pool.decreaseLiquidityWithReturn({pool:o,slippage:d,address:i,amountA:s,amountB:l,nft:b,decreaseLiquidity:I,deadline:C});return x.transferObjects([D,k],this.data.address),x}static fromData(t){return new a(t)}};var Um=require("turbos-clmm-sdk");var Vi=class a extends S{constructor(t){super(t);this.data=t}txType;txSubType;async build(t){let n=new Um.TurbosSdk(t.network.replace("sui:",""),t.suiClient),{pool:o,address:i,amountA:s,amountB:l,slippage:d,nft:b,deadline:I,txb:C}=this.data;return n.pool.increaseLiquidity({pool:o,slippage:d,address:i,amountA:s,amountB:l,nft:b,deadline:I,txb:C})}static fromData(t){return new a(t)}};var qm=require("@mysten/sui/transactions"),Fm=require("@mysten/sui/utils");var $i=class a extends S{constructor(t){super(t);this.data=t}txType;txSubType;async build(t){let n=new qm.Transaction;return n.moveCall({target:`${zt.PackageId}::claim::claim`,typeArguments:[zt.turbosCoinType],arguments:[n.object(zt.Claim),n.object(Fm.SUI_CLOCK_OBJECT_ID)]}),n}static fromData(t){return new a(t)}};var Km=require("@mysten/sui/transactions");var Hi=class a extends S{constructor(t){super(t);this.data=t}txType;txSubType;async build(t){let n=new Km.Transaction;return n.moveCall({target:`${zt.PackageId}::claim::join`,typeArguments:[zt.turbosCoinType],arguments:[n.object(zt.Claim)]}),n}static fromData(t){return new a(t)}};var Vm=require("@mysten/sui/transactions"),$m=require("turbos-clmm-sdk");var Xi=class a extends S{constructor(t){super(t);this.data=t}txType;txSubType;async build(t){let n=new $m.TurbosSdk(t.network.replace("sui:",""),t.suiClient),o=new Vm.Transaction;return o=await n.pool.collectFee({txb:o,...this.data}),o=await n.pool.collectReward({txb:o,...this.data}),o=await n.pool.decreaseLiquidity({txb:o,...this.data}),o=await n.position.burn({txb:o,nft:this.data.nft,pool:this.data.pool}),o}static fromData(t){return new a(t)}};var Hm=require("turbos-clmm-sdk");var zi=class a extends S{constructor(t){super(t);this.data=t}txType;txSubType;async build(t){let n=new Hm.TurbosSdk(t.network.replace("sui:",""),t.suiClient),{txb:o,coinA:i,coinB:s}=await n.pool.removeLiquidityWithReturn({...this.data});return o.transferObjects([i,s],this.data.address),o}static fromData(t){return new a(t)}};var Xm=require("turbos-clmm-sdk");var Gi=class a extends S{constructor(t){super(t);this.data=t}txType;txSubType;async build(t){console.log(this.data,"this.data");let n=new Xm.TurbosSdk(t.network.replace("sui:",""),t.suiClient),{routes:o,coinTypeA:i,coinTypeB:s,address:l,amountA:d,amountB:b,slippage:I,amountSpecifiedIsInput:C,deadline:x,txb:D}=this.data;return n.trade.swap({routes:o,coinTypeA:i,coinTypeB:s,address:l,amountA:d,amountB:b,amountSpecifiedIsInput:C,slippage:I,deadline:x,txb:D})}static fromData(t){return new a(t)}};var Zm=require("turbos-clmm-sdk");var Us=require("@mysten/sui/transactions"),qs=require("@mysten/sui/utils");var zm=require("turbos-clmm-sdk");var qn=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 s=[],l=0;return o.sort((d,b)=>Number(b.balance)-Number(d.balance)).some(d=>l>=n?!0:(l+=Number(d.balance),s.push(d),!1)),s}splitAndMergeCoin(e,t,n){if(!e||e.length<1)return[void 0,void 0];if(this.isSuiCoinAddress(e[0].coinType)){let[s]=n.splitCoins(n.gas,[n.pure.u64(t)]);return[s,void 0]}let o=n.object(e[0].coinObjectId);e.length>1&&n.mergeCoins(o,e.slice(1).map(s=>n.object(s.coinObjectId)));let[i]=n.splitCoins(o,[n.pure.u64(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:`${Gt.PackageId}::custodian_v2::AccountCap`}});return t.data[0]?.data?(0,zm.unstable_getObjectId)(t.data[0].data):void 0}createAccount(e){let[t]=e.moveCall({typeArguments:[],target:`${Gt.PackageId}::clob_v2::create_account`,arguments:[]});return t}zero(e,t){return t.moveCall({typeArguments:[e],target:"0x2::coin::zero",arguments:[]})}};var Gm=89,Qm=1e6,Jm=async a=>{let{token1:e,token2:t,poolId:n,amountIn:o,currentAddress:i,turbosSdk:s}=a,l=new Us.Transaction,d=new qn(s),b=await d.getCoinsData(i,t,o),[I,C]=d.splitAndMergeCoin(b,o,l);if(!I)throw new Error(`Not enough balance: ${t}`);let x=await d.IsAccountCap(i),D=x?l.object(x):d.createAccount(l),[k,P,U]=l.moveCall({typeArguments:[e,t],target:`${Gt.PackageId}::clob_v2::swap_exact_quote_for_base`,arguments:[l.object(String(n)),l.pure.u64(Gm),D,l.pure.u64(o),l.object((0,qs.normalizeSuiObjectId)("0x6")),I]});return C&&l.transferObjects([C],l.pure.address(i)),l.transferObjects([k],l.pure.address(i)),l.transferObjects([P],l.pure.address(i)),x||l.transferObjects([D],l.pure.address(i)),l.setSenderIfNotSet(i),l.setGasBudget(Qm),l},Ym=async a=>{let{token1:e,token2:t,poolId:n,amountIn:o,currentAddress:i,turbosSdk:s}=a,l=new Us.Transaction,d=new qn(s),b=await d.getCoinsData(i,e,o),[I,C]=d.splitAndMergeCoin(b,o,l);if(!I)throw new Error(`Not enough balance: ${e}`);let x=await d.IsAccountCap(i),D=x?l.object(x):d.createAccount(l),k=d.zero(t,l),[P,U,K]=l.moveCall({typeArguments:[e,t],target:`${Gt.PackageId}::clob_v2::swap_exact_base_for_quote`,arguments:[l.object(String(n)),l.pure.u64(Gm),D,l.pure.u64(o),I,k,l.object((0,qs.normalizeSuiObjectId)("0x6"))]});return C&&l.transferObjects([C],l.pure.address(i)),l.transferObjects([P],l.pure.address(i)),l.transferObjects([U],l.pure.address(i)),x||l.transferObjects([D],l.pure.address(i)),l.setSenderIfNotSet(i),l.setGasBudget(Qm),l};var Qi=class a extends S{constructor(t){super(t);this.data=t}txType;txSubType;async build(t){let n=new Zm.TurbosSdk(t.network.replace("sui:",""),t.suiClient);return await Ym({...this.data,turbosSdk:n,currentAddress:t.account.address})}static fromData(t){return new a(t)}};var tp=require("turbos-clmm-sdk");var Ji=class a extends S{constructor(t){super(t);this.data=t}txType;txSubType;async build(t){let n=new tp.TurbosSdk(t.network.replace("sui:",""),t.suiClient);return await Jm({...this.data,turbosSdk:n,currentAddress:t.account.address})}static fromData(t){return new a(t)}};var Yi=class{application="turbos";supportSDK="@mysten/sui";async deserialize(e){console.log(e,"input");let t=new np.TurbosSdk(e.network.replace("sui:","")),n=await t.contract.getConfig(),{transaction:o,account:i}=e,l=await new Ni(o,t,n).decode(i.address);return{txType:ep.TransactionType.Other,txSubType:l.type,intentionData:l.intentionData}}async build(e){let{suiClient:t,account:n,network:o}=e;console.log(e.intentionData,"intentionData");let i;switch(e.txSubType){case"CreatePool":i=qi.fromData(e.intentionData);break;case"AddLiquidity":i=_i.fromData(e.intentionData);break;case"IncreaseLiquidity":i=Vi.fromData(e.intentionData);break;case"DecreaseLiquidity":i=Fi.fromData(e.intentionData);break;case"DecreaseLiquidityWithReturn":i=Ki.fromData(e.intentionData);break;case"RemoveLiquidity":i=Xi.fromData(e.intentionData);break;case"removeLiquidityWithReturn":i=zi.fromData(e.intentionData);break;case"CollectFee":i=ji.fromData(e.intentionData);break;case"CollectReward":i=Ui.fromData(e.intentionData);break;case"Burn":i=Li.fromData(e.intentionData);break;case"Swap":i=Gi.fromData(e.intentionData);break;case"PrixJoin":i=Hi.fromData(e.intentionData);break;case"PrixClaim":i=$i.fromData(e.intentionData);break;case"SwapExactBaseForQuote":i=Qi.fromData(e.intentionData);break;case"SwapExactQuoteForBase":i=Ji.fromData(e.intentionData);break;default:throw new Error("not implemented")}return i.build({suiClient:t,account:n,network:o})}};var rp=require("@msafe/sui3-utils");var Zi=require("@msafe/sui3-utils"),Fs=require("@mysten/sui.js/bcs"),Me=require("@mysten/sui.js/utils");var hf={packageId:"0x549e8b69270defbfafd4f94e17ec44cdbdd99820b33bda2278dea3b9a32d3f55",poolObjectId:"0x7fa2faa111b8c65bea48a23049bfd81ca8f971a262d981dcd9a17c3825cb5baf",metadataObjectId:"0x680cd26af32b2bde8d3361e804c53ec1d1cfe24c7f039eb7f549e8dfde389a60",systemStateObjectId:"0x0000000000000000000000000000000000000000000000000000000000000005",certType:"0x549e8b69270defbfafd4f94e17ec44cdbdd99820b33bda2278dea3b9a32d3f55::cert::CERT",gasBudget:5e7},kt=hf;var tr=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(`${kt.packageId}::native_pool::stake`)}isUnStakeTransaction(){return!!this.getMoveCallTransaction(`${kt.packageId}::native_pool::unstake`)}isClaimTicketTransaction(){return!!this.getMoveCallTransaction(`${kt.packageId}::native_pool::burn_ticket`)}decodeStake(){let e=this.transactions[0].amounts[0].value.toNumber();return{txType:Zi.TransactionType.Other,type:"Stake",intentionData:{amount:e}}}decodeUnStake(){let t=this.transactions.find(n=>n.kind==="SplitCoins").amounts[0].value.toNumber();return{txType:Zi.TransactionType.Other,type:"UnStake",intentionData:{amount:t}}}decodeClaimTicket(){let e=this.helper.decodeOwnedObjectId(2);return console.log(e),{txType:Zi.TransactionType.Other,type:"ClaimTicket",intentionData:{ticketId:e}}}get helper(){let e=this.transactions.find(t=>t.kind==="MoveCall"&&t.target.startsWith(kt.packageId));return new Ks(e,this.txb)}},Ks=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,Me.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 Fs.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,Me.normalizeSuiAddress)(e.value.Object.ImmOrOwned.objectId)}return(0,Me.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,Me.normalizeSuiAddress)(e.value);if(!("Object"in e.value)||!("Shared"in e.value.Object))throw new Error("not Shared");return(0,Me.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 Fs.bcs.de(t,new Uint8Array(n))}typeArg(e){return(0,Me.normalizeStructTag)(this.moveCall.typeArguments[e])}txArg(e){return this.moveCall.arguments[e]}};var op=require("@mysten/sui.js/transactions");var er=class a extends Lt{constructor(t){super(t);this.data=t}txType;txSubType;async build(t){console.log(t);let n=new op.TransactionBlock,{ticketId:o}=this.data;return n.moveCall({target:`${kt.packageId}::native_pool::burn_ticket`,arguments:[n.object(kt.poolObjectId),n.object(kt.systemStateObjectId),n.object(o)]}),n}static fromData(t){return new a(t)}};var ap=require("@mysten/sui.js/transactions");var nr=class a extends Lt{constructor(t){super(t);this.data=t}txType;txSubType;async build(t){console.log(t);let n=new ap.TransactionBlock,{amount:o}=this.data,[i]=n.splitCoins(n.gas,[n.pure(o)]);return n.moveCall({target:`${kt.packageId}::native_pool::stake`,arguments:[n.object(kt.poolObjectId),n.object(kt.metadataObjectId),n.object(kt.systemStateObjectId),i]}),n}static fromData(t){return new a(t)}};var ip=require("@mysten/sui.js/transactions");var or=class a extends Lt{constructor(t){super(t);this.data=t}txType;txSubType;async build(t){console.log(t);let n=new ip.TransactionBlock,{amount:o}=this.data,i=(await t.suiClient.getAllCoins({owner:t.account.address,limit:100})).data,[s,...l]=i.filter(I=>I.coinType.split("::")[0]===kt.certType.split("::")[0]),d=n.object(s.coinObjectId);l.length&&n.mergeCoins(d,l.map(I=>n.object(I.coinObjectId)));let b=n.splitCoins(n.object(s.coinObjectId),[n.pure(o)]);return n.moveCall({target:`${kt.packageId}::native_pool::unstake`,arguments:[n.object(kt.poolObjectId),n.object(kt.metadataObjectId),n.object(kt.systemStateObjectId),b]}),n}static fromData(t){return new a(t)}};var ar=class{application="volo";supportSDK="@mysten/sui.js";async deserialize(e){let{transactionBlock:t}=e,o=new tr(t).decode();return{txType:rp.TransactionType.Other,txSubType:o.type,intentionData:o.intentionData}}async build(e){let{suiClient:t,account:n}=e,o;switch(e.txSubType){case"Stake":o=nr.fromData(e.intentionData);break;case"UnStake":o=or.fromData(e.intentionData);break;case"ClaimTicket":o=er.fromData(e.intentionData);break;default:throw new Error("not implemented")}return o.build({suiClient:t,account:n})}};var Tp=require("@msafe/sui3-utils");var Vs=require("@cetusprotocol/common-sdk"),se=require("@msafe/sui3-utils"),ln=require("@mysten/bcs"),un=require("@mysten/sui/bcs");var ir=class{constructor(e,t){this.transaction=e;this.appContext=t}async 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();if(this.isAggregator7KSwapTx())return this.decodeAggregator7KSwapTx();throw new Error("Unknown transaction type")}decodeOpenPositionTx(){let e=this.getMoveCallCommand("open_position"),t=this.getMoveCallCommand("provide_liquidity_with_fixed_amount");return{txType:se.TransactionType.Other,type:"OpenPosition",intentionData:{pool:this.getSharedObjectID(this.getInputIndex(e,1)),lowerTick:Number((0,Vs.asIntN)(BigInt(this.getU32(this.getInputIndex(e,2)))).toString()),upperTick:Number((0,Vs.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:se.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:se.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:se.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:se.TransactionType.Other,type:"CollectRewards",intentionData:{pool:e[0].pool,position:e[0].position,collectRewardTokens:e.map(t=>t.rewardCoinType)}}}decodeCollectFeeTx(){return{txType:se.TransactionType.Other,type:"CollectFee",intentionData:this.getFeeCallData()}}decodeCollectRewardsAndFeeTx(){let e=this.getFeeCallData();return{txType:se.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}async decodeAggregator7KSwapTx(){let{appContext:e}=this;return console.log("appContext",e),{txType:se.TransactionType.Other,type:"Aggregator7KSwap",intentionData:{tokenIn:e.txParams.tokenIn,tokenOut:e.txParams.tokenOut,amountIn:String(e.txParams.amountIn),maxSlippage:String(e.txParams.maxSlippage)}}}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")}isAggregator7KSwapTx(){return!!this.commands.find(e=>e.$kind==="MoveCall"&&e.MoveCall.function.toLowerCase().includes("settle"))}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(un.bcs.u32().parse(Uint8Array.from((0,ln.fromBase64)(this.inputs[e].Pure.bytes))))}getU64(e){return un.bcs.u64().parse(Uint8Array.from((0,ln.fromBase64)(this.inputs[e].Pure.bytes)))}getU128(e){return un.bcs.u128().parse(Uint8Array.from((0,ln.fromBase64)(this.inputs[e].Pure.bytes)))}getBoolean(e){return un.bcs.bool().parse(Uint8Array.from((0,ln.fromBase64)(this.inputs[e].Pure.bytes)))}getAddress(e){return un.bcs.Address.parse(Uint8Array.from((0,ln.fromBase64)(this.inputs[e].Pure.bytes)))}getTypeArguments(e){return e.MoveCall.typeArguments||[]}getInputIndex(e,t){return e.MoveCall.arguments[t].Input}};var mp=require("@msafe/sui3-utils");var rr=require("@bluefin-exchange/bluefin7k-aggregator-sdk"),oe=require("@firefly-exchange/library-sui"),up=require("turbos-clmm-sdk");var cp=require("@firefly-exchange/library-sui"),lp=require("@firefly-exchange/library-sui/spot"),sp={rpc:"https://fullnode.mainnet.sui.io/",objects:{GlobalConfig:"0x03db251ba509a8d5d8777b6338836082335d93eecbdd09a11e190a1cff51c352",BasePackage:"0x3492c874c1e3b3e2984e8c41b589e642d4d0a5d6459e5a9cfc2d52fd7c89c267",CurrentPackage:"0x67b34b728c4e28e704dcfecf7c5cf55c7fc593b6c65c20d1836d97c209c1928a"}},le=(a,e)=>{if(a!=="sui:mainnet")throw new Error("Bluefin spot protocol is only available on sui::mainnet");let t=new cp.SuiClient({url:sp.rpc});return new lp.OnChainCalls(t,sp.objects,{address:e.address,isUIWallet:!1})};var Mt=class{static async OpenPosition(e,t,n){let o=le(n,t),i=await o.queryChain.getPool(e.pool),s=this.prototype.buildLiqInput(i,{...e,slippage:0});return await o.openPositionWithFixedAmount(i,e.lowerTick,e.upperTick,s,{returnTx:!0,sender:t.address})}static async provideLiquidity(e,t,n){let o=le(n,t),i=await o.queryChain.getPool(e.pool),s=this.prototype.buildLiqInput(i,e);return await o.provideLiquidityWithFixedAmount(i,e.position,s,{returnTx:!0,sender:t.address})}static async removeLiquidity(e,t,n){let o=le(n,t),i=await o.queryChain.getPool(e.pool);return await o.removeLiquidity(i,e.position,{liquidityAmount:new oe.BN(e.liquidity),tokenMaxA:new oe.BN(e.maxAmountTokenA),tokenMaxB:new oe.BN(e.maxAmountTokenB)},{returnTx:!0,sender:t.address})}static async closePosition(e,t,n){let o=le(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=le(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=le(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=le(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})}static async aggregator7KSwap(e,t,n){let o=le(n,t),i=await(0,rr.getQuote)({tokenIn:e.tokenIn.address,tokenOut:e.tokenOut.address,amountIn:new up.Decimal(e.amountIn).mul(10**e.tokenIn.decimals).toString()}),s=await(0,rr.buildTx)({quoteResponse:i,accountAddress:t.address,slippage:e.maxSlippage,commission:{partner:"0x956d6ea2da156a037952964badc51f997cc5581c86a0e05f74049e6effab9347",commissionBps:0}});return s.tx.setSender(t.address),s.tx}buildLiqInput(e,t){return{...oe.ClmmPoolUtil.estLiquidityAndCoinAmountFromOneAmounts(t.lowerTick,t.upperTick,new oe.BN(t.tokenAmount),t.isTokenAFixed,!0,0,new oe.BN(e.current_sqrt_price)),tokenMaxA:new oe.BN(t.maxAmountTokenA),tokenMaxB:new oe.BN(t.maxAmountTokenB)}}};var sr=class a extends S{constructor(t){super(t);this.data=t}txType=mp.TransactionType.Other;txSubType="Aggregator7KSwap";async build(t){let{account:n,network:o}=t;return console.log(this.data),Mt.aggregator7KSwap(this.data,n,o)}static fromData(t){return new a(t)}};var pp=require("@msafe/sui3-utils");var cr=class a extends S{constructor(t){super(t);this.data=t}txType=pp.TransactionType.Other;txSubType="ClosePosition";async build(t){let{account:n,network:o}=t;return console.log(this.data),Mt.closePosition(this.data,n,o)}static fromData(t){return new a(t)}};var dp=require("@msafe/sui3-utils");var lr=class a extends S{constructor(t){super(t);this.data=t}txType=dp.TransactionType.Other;txSubType="CollectFee";async build(t){let{account:n,network:o}=t;return console.log(this.data),Mt.collectFee(this.data,n,o)}static fromData(t){return new a(t)}};var fp=require("@msafe/sui3-utils");var ur=class a extends S{constructor(t){super(t);this.data=t}txType=fp.TransactionType.Other;txSubType="CollectRewards";async build(t){let{account:n,network:o}=t;return console.log(this.data),Mt.collectRewards(this.data,n,o)}static fromData(t){return new a(t)}};var hp=require("@msafe/sui3-utils");var mr=class a extends S{constructor(t){super(t);this.data=t}txType=hp.TransactionType.Other;txSubType="CollectRewardsAndFee";async build(t){let{account:n,network:o}=t;return console.log(this.data),Mt.collectRewardsAndFee(this.data,n,o)}static fromData(t){return new a(t)}};var gp=require("@msafe/sui3-utils");var pr=class a extends S{constructor(t){super(t);this.data=t}txType=gp.TransactionType.Other;txSubType="OpenPosition";async build(t){let{account:n,network:o}=t;return console.log(this.data),Mt.OpenPosition(this.data,n,o)}static fromData(t){return new a(t)}};var yp=require("@msafe/sui3-utils");var dr=class a extends S{constructor(t){super(t);this.data=t}txType=yp.TransactionType.Other;txSubType="ProvideLiquidity";async build(t){let{account:n,network:o}=t;return console.log(this.data),Mt.provideLiquidity(this.data,n,o)}static fromData(t){return new a(t)}};var bp=require("@msafe/sui3-utils");var fr=class a extends S{constructor(t){super(t);this.data=t}txType=bp.TransactionType.Other;txSubType="RemoveLiquidity";async build(t){let{account:n,network:o}=t;return console.log(this.data),Mt.removeLiquidity(this.data,n,o)}static fromData(t){return new a(t)}};var hr=class{application="bluefin";supportSDK="@mysten/sui";async deserialize(e){console.log("Bluefin helper deserialize input: ",e);let{transaction:t,appContext:n}=e,i=await new ir(t,n).decode();return{txType:Tp.TransactionType.Other,txSubType:i.type,intentionData:{appContext:e.appContext,...i.intentionData}}}async build(e){let{suiClient:t,account:n,network:o}=e;console.log(e.txSubType);let i;switch(e.txSubType){case"OpenPosition":i=pr.fromData(e.intentionData);break;case"ProvideLiquidity":i=dr.fromData(e.intentionData);break;case"RemoveLiquidity":i=fr.fromData(e.intentionData);break;case"ClosePosition":i=cr.fromData(e.intentionData);break;case"CollectFee":i=lr.fromData(e.intentionData);break;case"CollectRewards":i=ur.fromData(e.intentionData);break;case"CollectRewardsAndFee":i=mr.fromData(e.intentionData);break;case"Aggregator7KSwap":i=sr.fromData(e.intentionData);break;default:throw new Error("not implemented")}return i.build({suiClient:t,account:n,network:o})}};var od=require("@msafe/sui3-utils");var Wp=require("@mmt-finance/clmm-sdk"),Np=require("@mysten/sui/transactions");var qe=require("@mmt-finance/clmm-sdk/dist/utils/math/tickMath"),Dp=qt(require("bignumber.js")),R=qt(Ip());var yf="0x0000000000000000000000000000000000000000000000000000000000000002::sui::SUI",Qt=a=>a!=="0x2::sui::SUI"?a:"0x0000000000000000000000000000000000000000000000000000000000000002::sui::SUI",bf=async({suiClient:a,address:e,type:t})=>{let n,o=[],i=0;do{try{let s=await a.getCoins({owner:e,coinType:t,cursor:n,limit:50});o=o.concat(s.data),n=s.nextCursor,(!s.hasNextPage||i===8)&&(n=null)}catch(s){console.log(s),n=null}i++}while(n!==null);return o},Tf=(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")},Sf=(a,e,t,n)=>{if(a===yf){let[o]=n.splitCoins(n.gas,[n.pure.u64(t)]);return o}else{let o=Tf(t,e);o.length>1&&n.mergeCoins(n.object(o[0]),o.slice(1).map(s=>n.object(s)));let[i]=n.splitCoins(n.object(o[0]),[n.pure.u64(t)]);return i}};async function wp(a,e,t,n,o){let i=await bf({suiClient:a.rpcClient,address:e,type:t});return Sf(Qt(t),i.map(l=>({balance:BigInt(l.balance),objectId:l.coinObjectId})),n,o)}var Ue=(a,e,t,n,o)=>{let i={objectId:n.poolId,tokenXType:n.tokenXType,tokenYType:n.tokenYType};n?.rewarders&&n?.rewarders.length>0&&a.Pool.collectAllRewards(o,i,n.rewarders.map(s=>({coin_type:s.coinType,flow_rate:s.flowRate,reward_amount:s.rewardAmount,rewards_allocated:s.rewardsAllocated,hasEnded:s.hasEnded})),t.objectId,e),a.Pool.collectFee(o,{objectId:n.poolId,tokenXType:n.tokenXType,tokenYType:n.tokenYType,isStable:n.isStable,tickSpacing:n.tickSpacing},t.objectId,e)};async function Cp({sdk:a,address:e,positionId:t,pool:n,txb:o,targetCoinType:i,slippage:s}){let l={objectId:n.poolId,tokenXType:n.tokenXType,tokenYType:n.tokenYType},d=n.rewarders.map(I=>I.coinType);d.length>0&&(console.log("claimRewardsAsTargetCoin input",{pool:l,positionId:t,rewarderCoinTypes:d,targetCoinType:i,slippage:s,toAddress:e}),await a.Pool.claimRewardsAs({txb:o,pool:l,positionId:t,rewarderCoinTypes:d,targetCoinType:i,slippage:s,toAddress:e}));let b=await a.Pool.getAllPools();return await a.Pool.claimFeeAs({txb:o,pool:l,positionId:t,targetCoinType:i,slippage:s,toAddress:e,pools:b}),o}function E(a,e,t){let n=a.toTwos(t).shrn(e);return n.imaskn(t-e+1),n.fromTwos(t-e)}function If(a){let e;return(a&1)!==0?e=new R.default("79232123823359799118286999567"):e=new R.default("79228162514264337593543950336"),(a&2)!==0&&(e=E(e.mul(new R.default("79236085330515764027303304731")),96,256)),(a&4)!==0&&(e=E(e.mul(new R.default("79244008939048815603706035061")),96,256)),(a&8)!==0&&(e=E(e.mul(new R.default("79259858533276714757314932305")),96,256)),(a&16)!==0&&(e=E(e.mul(new R.default("79291567232598584799939703904")),96,256)),(a&32)!==0&&(e=E(e.mul(new R.default("79355022692464371645785046466")),96,256)),(a&64)!==0&&(e=E(e.mul(new R.default("79482085999252804386437311141")),96,256)),(a&128)!==0&&(e=E(e.mul(new R.default("79736823300114093921829183326")),96,256)),(a&256)!==0&&(e=E(e.mul(new R.default("80248749790819932309965073892")),96,256)),(a&512)!==0&&(e=E(e.mul(new R.default("81282483887344747381513967011")),96,256)),(a&1024)!==0&&(e=E(e.mul(new R.default("83390072131320151908154831281")),96,256)),(a&2048)!==0&&(e=E(e.mul(new R.default("87770609709833776024991924138")),96,256)),(a&4096)!==0&&(e=E(e.mul(new R.default("97234110755111693312479820773")),96,256)),(a&8192)!==0&&(e=E(e.mul(new R.default("119332217159966728226237229890")),96,256)),(a&16384)!==0&&(e=E(e.mul(new R.default("179736315981702064433883588727")),96,256)),(a&32768)!==0&&(e=E(e.mul(new R.default("407748233172238350107850275304")),96,256)),(a&65536)!==0&&(e=E(e.mul(new R.default("2098478828474011932436660412517")),96,256)),(a&131072)!==0&&(e=E(e.mul(new R.default("55581415166113811149459800483533")),96,256)),(a&262144)!==0&&(e=E(e.mul(new R.default("38992368544603139932233054999993551")),96,256)),E(e,32,256)}function wf(a){let e=Math.abs(a),t;return(e&1)!==0?t=new R.default("18445821805675392311"):t=new R.default("18446744073709551616"),(e&2)!==0&&(t=E(t.mul(new R.default("18444899583751176498")),64,256)),(e&4)!==0&&(t=E(t.mul(new R.default("18443055278223354162")),64,256)),(e&8)!==0&&(t=E(t.mul(new R.default("18439367220385604838")),64,256)),(e&16)!==0&&(t=E(t.mul(new R.default("18431993317065449817")),64,256)),(e&32)!==0&&(t=E(t.mul(new R.default("18417254355718160513")),64,256)),(e&64)!==0&&(t=E(t.mul(new R.default("18387811781193591352")),64,256)),(e&128)!==0&&(t=E(t.mul(new R.default("18329067761203520168")),64,256)),(e&256)!==0&&(t=E(t.mul(new R.default("18212142134806087854")),64,256)),(e&512)!==0&&(t=E(t.mul(new R.default("17980523815641551639")),64,256)),(e&1024)!==0&&(t=E(t.mul(new R.default("17526086738831147013")),64,256)),(e&2048)!==0&&(t=E(t.mul(new R.default("16651378430235024244")),64,256)),(e&4096)!==0&&(t=E(t.mul(new R.default("15030750278693429944")),64,256)),(e&8192)!==0&&(t=E(t.mul(new R.default("12247334978882834399")),64,256)),(e&16384)!==0&&(t=E(t.mul(new R.default("8131365268884726200")),64,256)),(e&32768)!==0&&(t=E(t.mul(new R.default("3584323654723342297")),64,256)),(e&65536)!==0&&(t=E(t.mul(new R.default("696457651847595233")),64,256)),(e&131072)!==0&&(t=E(t.mul(new R.default("26294789957452057")),64,256)),(e&262144)!==0&&(t=E(t.mul(new R.default("37481735321082")),64,256)),t}var xp=(a,e,t)=>{let n=(0,qe.convertI32ToSigned)(t?a+a%(e??1):a-a%(e??1));return n>0?new R.default(If(n)):new R.default(wf(n))};function kp(a,e){if(!/^(\d+)(\.\d+)?$/.test(a))return BigInt(0);let[t,n=""]=a.split("."),o=(n+"0".repeat(e)).slice(0,e),s=(t+o).replace(/^0+/,"")||"0";return BigInt(s)}async function Oe({address:a,coinType:e,coinAmount:t,coinDecimals:n,tx:o,mmt:i}){let s=kp(t,n),l;return Number(t)?l=await wp(i,a,Qt(e),s,o):[l]=o.moveCall({target:"0x2::coin::zero",typeArguments:[e],arguments:[]}),l}function vp({mmt:a,tx:e,poolModel:t,selectedLowTick:n,selectedHighTick:o}){let i=xp((0,qe.convertI32ToSigned)(n),t.tickSpacing),s=xp((0,qe.convertI32ToSigned)(o),t.tickSpacing);return a.Position.openPosition(e,t,i.toString(),s.toString())}var Cf=(a,e)=>{let n=1e4-Math.floor(e*100);return a*BigInt(n)/BigInt(1e4)};function gr(a,e,t){let n=kp(a,e);return Number(a)===0?BigInt(0):Cf(n,t)}async function Fn({poolId:a,currentSqrtPrice:e,tokenX:t,tokenY:n,slippagePercentage:o,isTokenX:i,suiClient:s}){let d=(await s.getObject({id:a,options:{showContent:!0}}))?.data?.content?.fields?.sqrt_price??e,b=qe.TickMath.sqrtPriceX64ToPrice(new R.default(d?.toString()),t.decimals,n.decimals),I=i?(100-o)/100:(100+o)/100,C=qe.TickMath.priceToSqrtPriceX64(b.mul(I),t.decimals,n.decimals);return BigInt(C.toString())}var Ap=async(a,e,t,n,o,i,s,l,d,b)=>{let I=await Oe({mmt:a,address:t,coinType:i.tokenX.coinType,coinAmount:n,coinDecimals:i.tokenX.decimals,tx:e}),C=await Oe({mmt:a,address:t,coinType:i.tokenY.coinType,coinAmount:o,coinDecimals:i.tokenY.decimals,tx:e}),x={objectId:s,tokenXType:i.tokenXType,tokenYType:i.tokenYType,tickSpacing:i.tickSpacing},D=vp({mmt:a,tx:e,poolModel:x,selectedLowTick:l,selectedHighTick:d}),k=gr(n,i.tokenX.decimals,b),P=gr(o,i.tokenY.decimals,b);a.Pool.addLiquidity(e,x,D,I,C,k,P,t),e.transferObjects([D],e.pure.address(t))},Mp=async(a,e,t,n,o,i,s,l,d,b,I)=>{try{let C=await Oe({mmt:a,address:n,coinType:i?s.tokenX.coinType:s.tokenY.coinType,coinAmount:o,coinDecimals:i?s.tokenX.decimals:s.tokenY.decimals,tx:e}),x={objectId:s.poolId,tokenXType:Qt(s.tokenX.coinType),tokenYType:Qt(s.tokenY.coinType),tickSpacing:s.tickSpacing},D=vp({mmt:a,tx:e,poolModel:x,selectedLowTick:l,selectedHighTick:d}),k=await Fn({suiClient:t,poolId:s.poolId,currentSqrtPrice:s.currentSqrtPrice,tokenX:s.tokenX,tokenY:s.tokenY,slippagePercentage:b,isTokenX:i});await a.Pool.addLiquiditySingleSidedV2({txb:e,pool:x,position:D,inputCoin:C,isXtoY:i,limitSqrtPrice:k,slippagePercentage:I,transferToAddress:n,useMvr:!0}),e.transferObjects([D],e.pure.address(n))}catch(C){console.error(C)}},Op=async(a,e,t,n,o,i,s,l)=>{let d=await Oe({mmt:a,address:t,coinType:i.tokenX.coinType,coinAmount:n,coinDecimals:i.tokenX.decimals,tx:e}),b=await Oe({mmt:a,address:t,coinType:i.tokenY.coinType,coinAmount:o,coinDecimals:i.tokenY.decimals,tx:e}),I={objectId:i.poolId,tokenXType:i.tokenXType,tokenYType:i.tokenYType,tickSpacing:i.tickSpacing},C=gr(n,i.tokenX.decimals,l),x=gr(o,i.tokenY.decimals,l);a.Pool.addLiquidity(e,I,s,d,b,C,x,t)},Pp=async(a,e,t,n,o,i,s,l,d)=>{try{let b=await Oe({mmt:a,address:t,coinType:o?i.tokenX.coinType:i.tokenY.coinType,coinAmount:n,coinDecimals:o?i.tokenX.decimals:i.tokenY.decimals,tx:e}),I={objectId:i.poolId,tokenXType:i.tokenX.coinType,tokenYType:i.tokenY.coinType,tickSpacing:i.tickSpacing},C=await Fn({suiClient:a.rpcClient,poolId:i.poolId,currentSqrtPrice:i.currentSqrtPrice,tokenX:i.tokenX,tokenY:i.tokenY,slippagePercentage:l,isTokenX:o});await a.Pool.addLiquiditySingleSidedV2({txb:e,pool:I,position:s,inputCoin:b,isXtoY:o,limitSqrtPrice:C,slippagePercentage:d,transferToAddress:t})}catch(b){throw console.error(b),b}},Rp=(a,e)=>BigInt(e===100?a:new Dp.default(a).multipliedBy(e/100).toFixed(0)),Bp=async(a,e,t,n,o,i)=>{let s=Rp(t.liquidity,o),l=n.tokenX.coinType,d=n.tokenY.coinType,b={objectId:n?.poolId,tokenXType:l,tokenYType:d};a.Pool.removeLiquidity(i,b,t.objectId,s,BigInt(0),BigInt(0),e),Ue(a,e,t,n,i),o===100&&a.Position.closePosition(i,t.objectId)},Ep=async({sdk:a,address:e,position:t,pool:n,withdrawPercentage:o,txb:i,targetCoinType:s,slippage:l})=>{let d=Rp(t.liquidity,o),b=Qt(n.tokenX.coinType),I=Qt(n.tokenY.coinType),C=Qt(s)===I,x={objectId:n?.poolId,tokenXType:b,tokenYType:I},{removeLpCoinA:D,removeLpCoinB:k}=a.Pool.removeLiquidity(i,x,t.objectId,d,BigInt(0),BigInt(0)),P=await Fn({suiClient:a.rpcClient,poolId:n.poolId,currentSqrtPrice:n.currentSqrtPrice,tokenX:n.tokenX,tokenY:n.tokenY,isTokenX:C,slippagePercentage:l}),U=C?D:k,K=i.moveCall({target:"0x2::coin::value",arguments:[U],typeArguments:[C?b:I]});i.transferObjects([C?k:D],e),a.Pool.swapV2({txb:i,transferToAddress:e,pool:x,limitSqrtPrice:P,amount:K,inputCoin:U,isXtoY:C}),Ue(a,e,t,n,i),o===100&&a.Position.closePosition(i,t.objectId)};var yr=class a extends S{constructor(t){super(t);this.data=t}txType;txSubType;async build(){let t=Wp.MmtSDK.NEW({network:"mainnet"}),{params:n}=this.data,{address:o,amountA:i,amountB:s,pool:l,selectedLowTick:d,selectedHighTick:b,slippage:I}=n,C=new Np.Transaction;return await Ap(t,C,o,i,s,l,l.poolId,d,b,I),C}static fromData(t){return new a(t)}};var _p=require("@mmt-finance/clmm-sdk"),Lp=require("@mysten/sui/transactions");var br=class a extends S{constructor(t){super(t);this.data=t}txType;txSubType;async build(){let t=_p.MmtSDK.NEW({network:"mainnet"}),{params:n}=this.data,{address:o,amount:i,isTokenX:s,pool:l,selectedLowTick:d,selectedHighTick:b,swapSlippage:I,addLiquiditySlippage:C}=n,x=new Lp.Transaction;return await Mp(t,x,t.rpcClient,o,i,s,l,d,b,I,C),x}static fromData(t){return new a(t)}};var jp=require("@mmt-finance/clmm-sdk"),Up=require("@mysten/sui/transactions");var Tr=class a extends S{constructor(t){super(t);this.data=t}txType;txSubType;async build(){let t=jp.MmtSDK.NEW({network:"mainnet"}),{params:n}=this.data,{address:o,positions:i,pools:s}=n,l=new Up.Transaction;for(let d of i){let b=s.find(I=>I.poolId===d.poolId);b&&Ue(t,o,d,b,l)}return l}static fromData(t){return new a(t)}};var qp=require("@mmt-finance/clmm-sdk"),Fp=require("@mysten/sui/transactions");var Sr=class a extends S{constructor(t){super(t);this.data=t}txType;txSubType;async build(){let t=qp.MmtSDK.NEW({network:"mainnet"}),{params:n}=this.data,o=new Fp.Transaction;return await Promise.all(n.claimParams.map(i=>Cp({...i,sdk:t,txb:o}))),o}static fromData(t){return new a(t)}};var Kp=require("@mmt-finance/clmm-sdk"),Vp=require("@mysten/sui/transactions");var Ir=class a extends S{constructor(t){super(t);this.data=t}txType;txSubType;async build(){let t=Kp.MmtSDK.NEW({network:"mainnet"}),{params:n}=this.data,{address:o,position:i,pool:s}=n,l=new Vp.Transaction;return Ue(t,o,i,s,l),l}static fromData(t){return new a(t)}};var $p=require("@mmt-finance/clmm-sdk"),Hp=require("@mysten/sui/transactions");var wr=class a extends S{constructor(t){super(t);this.data=t}txType;txSubType;async build(){let t=$p.MmtSDK.NEW({network:"mainnet"}),{params:n}=this.data,{address:o,amountA:i,amountB:s,pool:l,positionObjectId:d,slippage:b}=n,I=new Hp.Transaction;return await Op(t,I,o,i,s,l,d,b),I}static fromData(t){return new a(t)}};var Xp=require("@mmt-finance/clmm-sdk"),zp=require("@mysten/sui/transactions");var Cr=class a extends S{constructor(t){super(t);this.data=t}txType;txSubType;async build(){let t=Xp.MmtSDK.NEW({network:"mainnet"}),{params:n}=this.data,{address:o,amount:i,isTokenX:s,pool:l,positionObjectId:d,swapSlippage:b,addLiquiditySlippage:I}=n,C=new zp.Transaction;return await Pp(t,C,o,i,s,l,d,b,I),C}static fromData(t){return new a(t)}};var Gp=require("@mmt-finance/clmm-sdk"),Qp=require("@mysten/sui/transactions");var xr=class a extends S{constructor(t){super(t);this.data=t}txType;txSubType;async build(){let t=Gp.MmtSDK.NEW({network:"mainnet"}),{params:n}=this.data,{pool:o,position:i,address:s,withdrawPercentage:l,zapOutOn:d,targetCoinType:b,slippage:I}=n,C=new Qp.Transaction;return d?await Ep({sdk:t,address:s,position:i,pool:o,withdrawPercentage:l,txb:C,targetCoinType:b,slippage:I}):await Bp(t,s,i,o,l,C),C}static fromData(t){return new a(t)}};var Xs=require("@mysten/sui/transactions"),zs=require("@suilend/springsui-sdk"),Hs={id:"0x0431232199873db77a92aa645cd43521437e9cc5c6fff07fd03edb88afe0b25a",type:"0x2b6602099970374cf58a2a1b9d96f005fccceb81e92eb059873baf420eb6c717::x_sui::X_SUI",weightHookId:"0x9e35c13dbb0bc437e8ad5a95ec463622f58763e060552ae8d100db77f4904601"},Jp=async(a,e,t)=>{let n=await zs.LstClient.initialize(a,Hs),o=new Xs.Transaction,[i]=o.splitCoins(o.gas,[BigInt(t)]),s=n.mint(o,i);return o.transferObjects([s],e),o},Yp=async(a,e,t)=>{let n=await zs.LstClient.initialize(a,Hs),o=await a.getCoins({owner:e,coinType:Hs.type,limit:1e3});if(o.data.length===0)throw new Error("No lst coins found");let i=new Xs.Transaction,s=o.data[0];o.data.length>1&&i.mergeCoins(s.coinObjectId,o.data.slice(1).map(b=>b.coinObjectId));let[l]=i.splitCoins(s.coinObjectId,[BigInt(t)]),d=n.redeem(i,l);return i.transferObjects([d],e),i};var Dr=class a extends S{constructor(t){super(t);this.data=t}txType;txSubType;async build(t){let{params:n}=this.data,{address:o,amount:i}=n;return await Jp(t.suiClient,o,i)}static fromData(t){return new a(t)}};var ed=require("@mmt-finance/clmm-sdk"),nd=require("@mysten/sui/transactions");var Zp=require("@mmt-finance/clmm-sdk/dist/utils/poolUtils");var td=async(a,e,t,n,o,i,s)=>{let l=await Oe({mmt:a,tx:i,address:o,coinType:t.coinType,coinAmount:n,coinDecimals:t.decimals}),d=i.moveCall({target:"0x2::coin::value",typeArguments:[t.coinType],arguments:[l]}),b=t.coinType;for(let I=0;I<e.length;I+=1){let{poolId:C,tokenX:x,tokenY:D,isStable:k,currentSqrtPrice:P}=e[I],{id:U,isReverse:K}=Zp.mappedMmtV3Pool[C]||{id:C,isReverse:!1},Bt=Qt(x.coinType)===Qt(b);Bt=K?!Bt:Bt;let Wt=K?D.coinType:x.coinType,Ot=K?x.coinType:D.coinType,mn=await Fn({poolId:U,tokenX:x,tokenY:D,slippagePercentage:s,isTokenX:Bt,suiClient:a.rpcClient,currentSqrtPrice:P}),Nt=a.Pool.swap(i,{objectId:U,tokenXType:Wt,tokenYType:Ot,isStable:k},d,l,Bt,void 0,mn,!1);i.transferObjects([l],i.pure.address(o)),l=Nt,b=Bt?Ot:Wt,d=i.moveCall({target:"0x2::coin::value",typeArguments:[b],arguments:[l]})}i.transferObjects([l],i.pure.address(o))};var kr=class a extends S{constructor(t){super(t);this.data=t}txType;txSubType;async build(){let t=ed.MmtSDK.NEW({network:"mainnet"}),{params:n}=this.data,{route:o,tokenIn:i,amountIn:s,address:l,slippage:d}=n,b=new nd.Transaction;return await td(t,o,i,s,l,b,d),b}static fromData(t){return new a(t)}};var vr=class a extends S{constructor(t){super(t);this.data=t}txType;txSubType;async build(t){let{params:n}=this.data,{address:o,amount:i}=n;return await Yp(t.suiClient,o,i)}static fromData(t){return new a(t)}};var Ar=class{application="mmt-dex";supportSDK="@mysten/sui";async deserialize(e){let{appContext:t}=e;return{txType:od.TransactionType.Other,txSubType:t.action,intentionData:t}}async build(e){let t;switch(e.txSubType){case"Swap":t=kr.fromData(e.intentionData);break;case"AddLiquidity":t=yr.fromData(e.intentionData);break;case"AddLiquiditySingleSide":t=br.fromData(e.intentionData);break;case"ClaimRewards":t=Ir.fromData(e.intentionData);break;case"ClaimAllRewards":t=Tr.fromData(e.intentionData);break;case"ClaimRewardsAs":t=Sr.fromData(e.intentionData);break;case"RemoveLiquidity":t=xr.fromData(e.intentionData);break;case"StakeXSui":t=Dr.fromData(e.intentionData);break;case"UnstakeXSui":t=vr.fromData(e.intentionData);break;case"ManageLiquidity":t=wr.fromData(e.intentionData);break;case"ManageLiquiditySingleSide":t=Cr.fromData(e.intentionData);break;default:throw new Error(`not implemented ${e.txSubType}`)}return t.build({suiClient:e.suiClient})}};var Gs=require("@msafe/sui3-utils");var ad=require("@mysten/sui/transactions"),id=require("@nemoprotocol/vaults-sdk");var Mr=class a extends S{constructor(t){super(t);this.data=t}txType;txSubType;async build(t){let{suiClient:n,account:o}=t,i=id.Vaults.createSDK({client:n}),s=new ad.Transaction;return await i.deposit(this.data,o.address,s),s}static fromData(t){return new a(t)}};var rd=require("@mysten/sui/transactions"),sd=require("@nemoprotocol/vaults-sdk");var Or=class a extends S{constructor(t){super(t);this.data=t}txType;txSubType;async build(t){let{suiClient:n,account:o}=t,i=sd.Vaults.createSDK({client:n}),s=new rd.Transaction;return await i.withdraw(this.data,o.address,s),s}static fromData(t){return new a(t)}};var Pr=class{application="nemo";supportSDK="@mysten/sui";async deserialize(e){let t=e.transaction.blockData.transactions.find(o=>o.kind==="MoveCall"&&o.target.toString().toLowerCase().includes("deposit::deposit_non_entry")),n=e.transaction.blockData.transactions.find(o=>o.kind==="MoveCall"&&o.target.toString().toLowerCase().includes("withdraw::withdraw"));if(t)return{txType:Gs.TransactionType.Other,txSubType:"VaultDeposit",intentionData:e.appContext};if(n)return{txType:Gs.TransactionType.Other,txSubType:"VaultWithdraw",intentionData:e.appContext}}async build(e){let{suiClient:t,account:n}=e;console.log(e.txSubType);let o;switch(e.txSubType){case"VaultDeposit":o=Mr.fromData(e.intentionData);break;case"VaultWithdraw":o=Or.fromData(e.intentionData);break;default:throw new Error("not implemented")}return o.build({suiClient:t,account:n})}};var xf=Pa.fromHelpers([new ga,new ka,new da,new va,new $o,new Yi,new Ar,new pi,new ar,new yo,new wi,new Pi,new Jn,new hr,new Wi,new Pr]);
1
+ "use strict";var Pd=Object.create;var Gn=Object.defineProperty;var Rd=Object.getOwnPropertyDescriptor;var Bd=Object.getOwnPropertyNames;var Ed=Object.getPrototypeOf,Nd=Object.prototype.hasOwnProperty;var Wd=(a,e)=>()=>(e||a((e={exports:{}}).exports,e),e.exports),rs=(a,e)=>{for(var t in e)Gn(a,t,{get:e[t],enumerable:!0})},Ic=(a,e,t,n)=>{if(e&&typeof e=="object"||typeof e=="function")for(let o of Bd(e))!Nd.call(a,o)&&o!==t&&Gn(a,o,{get:()=>e[o],enumerable:!(n=Rd(e,o))||n.enumerable});return a};var Ft=(a,e,t)=>(t=a!=null?Pd(Ed(a)):{},Ic(e||!a||!a.__esModule?Gn(t,"default",{value:a,enumerable:!0}):t,a)),_d=a=>Ic(Gn({},"__esModule",{value:!0}),a);var vp=Wd((kp,Zs)=>{"use strict";(function(a,e){"use strict";function t(y,r){if(!y)throw new Error(r||"Assertion failed")}function n(y,r){y.super_=r;var u=function(){};u.prototype=r.prototype,y.prototype=new u,y.prototype.constructor=y}function o(y,r,u){if(o.isBN(y))return y;this.negative=0,this.words=null,this.length=0,this.red=null,y!==null&&((r==="le"||r==="be")&&(u=r,r=10),this._init(y||0,r||10,u||"be"))}typeof 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,u){return r.cmp(u)>0?r:u},o.min=function(r,u){return r.cmp(u)<0?r:u},o.prototype._init=function(r,u,m){if(typeof r=="number")return this._initNumber(r,u,m);if(typeof r=="object")return this._initArray(r,u,m);u==="hex"&&(u=16),t(u===(u|0)&&u>=2&&u<=36),r=r.toString().replace(/\s+/g,"");var d=0;r[0]==="-"&&(d++,this.negative=1),d<r.length&&(u===16?this._parseHex(r,d,m):(this._parseBase(r,u,d),m==="le"&&this._initArray(this.toArray(),u,m)))},o.prototype._initNumber=function(r,u,m){r<0&&(this.negative=1,r=-r),r<67108864?(this.words=[r&67108863],this.length=1):r<4503599627370496?(this.words=[r&67108863,r/67108864&67108863],this.length=2):(t(r<9007199254740992),this.words=[r&67108863,r/67108864&67108863,1],this.length=3),m==="le"&&this._initArray(this.toArray(),u,m)},o.prototype._initArray=function(r,u,m){if(t(typeof r.length=="number"),r.length<=0)return this.words=[0],this.length=1,this;this.length=Math.ceil(r.length/3),this.words=new Array(this.length);for(var d=0;d<this.length;d++)this.words[d]=0;var h,T,C=0;if(m==="be")for(d=r.length-1,h=0;d>=0;d-=3)T=r[d]|r[d-1]<<8|r[d-2]<<16,this.words[h]|=T<<C&67108863,this.words[h+1]=T>>>26-C&67108863,C+=24,C>=26&&(C-=26,h++);else if(m==="le")for(d=0,h=0;d<r.length;d+=3)T=r[d]|r[d+1]<<8|r[d+2]<<16,this.words[h]|=T<<C&67108863,this.words[h+1]=T>>>26-C&67108863,C+=24,C>=26&&(C-=26,h++);return this._strip()};function s(y,r){var u=y.charCodeAt(r);if(u>=48&&u<=57)return u-48;if(u>=65&&u<=70)return u-55;if(u>=97&&u<=102)return u-87;t(!1,"Invalid character in "+y)}function c(y,r,u){var m=s(y,u);return u-1>=r&&(m|=s(y,u-1)<<4),m}o.prototype._parseHex=function(r,u,m){this.length=Math.ceil((r.length-u)/6),this.words=new Array(this.length);for(var d=0;d<this.length;d++)this.words[d]=0;var h=0,T=0,C;if(m==="be")for(d=r.length-1;d>=u;d-=2)C=c(r,u,d)<<h,this.words[T]|=C&67108863,h>=18?(h-=18,T+=1,this.words[T]|=C>>>26):h+=8;else{var f=r.length-u;for(d=f%2===0?u+1:u;d<r.length;d+=2)C=c(r,u,d)<<h,this.words[T]|=C&67108863,h>=18?(h-=18,T+=1,this.words[T]|=C>>>26):h+=8}this._strip()};function p(y,r,u,m){for(var d=0,h=0,T=Math.min(y.length,u),C=r;C<T;C++){var f=y.charCodeAt(C)-48;d*=m,f>=49?h=f-49+10:f>=17?h=f-17+10:h=f,t(f>=0&&h<m,"Invalid character"),d+=h}return d}o.prototype._parseBase=function(r,u,m){this.words=[0],this.length=1;for(var d=0,h=1;h<=67108863;h*=u)d++;d--,h=h/u|0;for(var T=r.length-m,C=T%d,f=Math.min(T,T-C)+m,l=0,g=m;g<f;g+=d)l=p(r,g,g+d,u),this.imuln(h),this.words[0]+l<67108864?this.words[0]+=l:this._iaddn(l);if(C!==0){var v=1;for(l=p(r,g,r.length,u),g=0;g<C;g++)v*=u;this.imuln(v),this.words[0]+l<67108864?this.words[0]+=l:this._iaddn(l)}this._strip()},o.prototype.copy=function(r){r.words=new Array(this.length);for(var u=0;u<this.length;u++)r.words[u]=this.words[u];r.length=this.length,r.negative=this.negative,r.red=this.red};function b(y,r){y.words=r.words,y.length=r.length,y.negative=r.negative,y.red=r.red}if(o.prototype._move=function(r){b(r,this)},o.prototype.clone=function(){var r=new o(null);return this.copy(r),r},o.prototype._expand=function(r){for(;this.length<r;)this.words[this.length++]=0;return this},o.prototype._strip=function(){for(;this.length>1&&this.words[this.length-1]===0;)this.length--;return this._normSign()},o.prototype._normSign=function(){return this.length===1&&this.words[0]===0&&(this.negative=0),this},typeof Symbol<"u"&&typeof Symbol.for=="function")try{o.prototype[Symbol.for("nodejs.util.inspect.custom")]=S}catch{o.prototype.inspect=S}else o.prototype.inspect=S;function S(){return(this.red?"<BN-R: ":"<BN: ")+this.toString(16)+">"}var w=["","0","00","000","0000","00000","000000","0000000","00000000","000000000","0000000000","00000000000","000000000000","0000000000000","00000000000000","000000000000000","0000000000000000","00000000000000000","000000000000000000","0000000000000000000","00000000000000000000","000000000000000000000","0000000000000000000000","00000000000000000000000","000000000000000000000000","0000000000000000000000000"],D=[0,0,25,16,12,11,10,9,8,8,7,7,7,7,6,6,6,6,6,6,6,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5],x=[0,0,33554432,43046721,16777216,48828125,60466176,40353607,16777216,43046721,1e7,19487171,35831808,62748517,7529536,11390625,16777216,24137569,34012224,47045881,64e6,4084101,5153632,6436343,7962624,9765625,11881376,14348907,17210368,20511149,243e5,28629151,33554432,39135393,45435424,52521875,60466176];o.prototype.toString=function(r,u){r=r||10,u=u|0||1;var m;if(r===16||r==="hex"){m="";for(var d=0,h=0,T=0;T<this.length;T++){var C=this.words[T],f=((C<<d|h)&16777215).toString(16);h=C>>>24-d&16777215,d+=2,d>=26&&(d-=26,T--),h!==0||T!==this.length-1?m=w[6-f.length]+f+m:m=f+m}for(h!==0&&(m=h.toString(16)+m);m.length%u!==0;)m="0"+m;return this.negative!==0&&(m="-"+m),m}if(r===(r|0)&&r>=2&&r<=36){var l=D[r],g=x[r];m="";var v=this.clone();for(v.negative=0;!v.isZero();){var O=v.modrn(g).toString(r);v=v.idivn(g),v.isZero()?m=O+m:m=w[l-O.length]+O+m}for(this.isZero()&&(m="0"+m);m.length%u!==0;)m="0"+m;return this.negative!==0&&(m="-"+m),m}t(!1,"Base should be between 2 and 36")},o.prototype.toNumber=function(){var r=this.words[0];return this.length===2?r+=this.words[1]*67108864:this.length===3&&this.words[2]===1?r+=4503599627370496+this.words[1]*67108864:this.length>2&&t(!1,"Number can only safely store up to 53 bits"),this.negative!==0?-r:r},o.prototype.toJSON=function(){return this.toString(16,2)},i&&(o.prototype.toBuffer=function(r,u){return this.toArrayLike(i,r,u)}),o.prototype.toArray=function(r,u){return this.toArrayLike(Array,r,u)};var k=function(r,u){return r.allocUnsafe?r.allocUnsafe(u):new r(u)};o.prototype.toArrayLike=function(r,u,m){this._strip();var d=this.byteLength(),h=m||Math.max(1,d);t(d<=h,"byte array longer than desired length"),t(h>0,"Requested array length <= 0");var T=k(r,h),C=u==="le"?"LE":"BE";return this["_toArrayLike"+C](T,d),T},o.prototype._toArrayLikeLE=function(r,u){for(var m=0,d=0,h=0,T=0;h<this.length;h++){var C=this.words[h]<<T|d;r[m++]=C&255,m<r.length&&(r[m++]=C>>8&255),m<r.length&&(r[m++]=C>>16&255),T===6?(m<r.length&&(r[m++]=C>>24&255),d=0,T=0):(d=C>>>24,T+=2)}if(m<r.length)for(r[m++]=d;m<r.length;)r[m++]=0},o.prototype._toArrayLikeBE=function(r,u){for(var m=r.length-1,d=0,h=0,T=0;h<this.length;h++){var C=this.words[h]<<T|d;r[m--]=C&255,m>=0&&(r[m--]=C>>8&255),m>=0&&(r[m--]=C>>16&255),T===6?(m>=0&&(r[m--]=C>>24&255),d=0,T=0):(d=C>>>24,T+=2)}if(m>=0)for(r[m--]=d;m>=0;)r[m--]=0},Math.clz32?o.prototype._countBits=function(r){return 32-Math.clz32(r)}:o.prototype._countBits=function(r){var u=r,m=0;return u>=4096&&(m+=13,u>>>=13),u>=64&&(m+=7,u>>>=7),u>=8&&(m+=4,u>>>=4),u>=2&&(m+=2,u>>>=2),m+u},o.prototype._zeroBits=function(r){if(r===0)return 26;var u=r,m=0;return(u&8191)===0&&(m+=13,u>>>=13),(u&127)===0&&(m+=7,u>>>=7),(u&15)===0&&(m+=4,u>>>=4),(u&3)===0&&(m+=2,u>>>=2),(u&1)===0&&m++,m},o.prototype.bitLength=function(){var r=this.words[this.length-1],u=this._countBits(r);return(this.length-1)*26+u};function M(y){for(var r=new Array(y.bitLength()),u=0;u<r.length;u++){var m=u/26|0,d=u%26;r[u]=y.words[m]>>>d&1}return r}o.prototype.zeroBits=function(){if(this.isZero())return 0;for(var r=0,u=0;u<this.length;u++){var m=this._zeroBits(this.words[u]);if(r+=m,m!==26)break}return r},o.prototype.byteLength=function(){return Math.ceil(this.bitLength()/8)},o.prototype.toTwos=function(r){return this.negative!==0?this.abs().inotn(r).iaddn(1):this.clone()},o.prototype.fromTwos=function(r){return this.testn(r-1)?this.notn(r).iaddn(1).ineg():this.clone()},o.prototype.isNeg=function(){return this.negative!==0},o.prototype.neg=function(){return this.clone().ineg()},o.prototype.ineg=function(){return this.isZero()||(this.negative^=1),this},o.prototype.iuor=function(r){for(;this.length<r.length;)this.words[this.length++]=0;for(var u=0;u<r.length;u++)this.words[u]=this.words[u]|r.words[u];return this._strip()},o.prototype.ior=function(r){return t((this.negative|r.negative)===0),this.iuor(r)},o.prototype.or=function(r){return this.length>r.length?this.clone().ior(r):r.clone().ior(this)},o.prototype.uor=function(r){return this.length>r.length?this.clone().iuor(r):r.clone().iuor(this)},o.prototype.iuand=function(r){var u;this.length>r.length?u=r:u=this;for(var m=0;m<u.length;m++)this.words[m]=this.words[m]&r.words[m];return this.length=u.length,this._strip()},o.prototype.iand=function(r){return t((this.negative|r.negative)===0),this.iuand(r)},o.prototype.and=function(r){return this.length>r.length?this.clone().iand(r):r.clone().iand(this)},o.prototype.uand=function(r){return this.length>r.length?this.clone().iuand(r):r.clone().iuand(this)},o.prototype.iuxor=function(r){var u,m;this.length>r.length?(u=this,m=r):(u=r,m=this);for(var d=0;d<m.length;d++)this.words[d]=u.words[d]^m.words[d];if(this!==u)for(;d<u.length;d++)this.words[d]=u.words[d];return this.length=u.length,this._strip()},o.prototype.ixor=function(r){return t((this.negative|r.negative)===0),this.iuxor(r)},o.prototype.xor=function(r){return this.length>r.length?this.clone().ixor(r):r.clone().ixor(this)},o.prototype.uxor=function(r){return this.length>r.length?this.clone().iuxor(r):r.clone().iuxor(this)},o.prototype.inotn=function(r){t(typeof r=="number"&&r>=0);var u=Math.ceil(r/26)|0,m=r%26;this._expand(u),m>0&&u--;for(var d=0;d<u;d++)this.words[d]=~this.words[d]&67108863;return m>0&&(this.words[d]=~this.words[d]&67108863>>26-m),this._strip()},o.prototype.notn=function(r){return this.clone().inotn(r)},o.prototype.setn=function(r,u){t(typeof r=="number"&&r>=0);var m=r/26|0,d=r%26;return this._expand(m+1),u?this.words[m]=this.words[m]|1<<d:this.words[m]=this.words[m]&~(1<<d),this._strip()},o.prototype.iadd=function(r){var u;if(this.negative!==0&&r.negative===0)return this.negative=0,u=this.isub(r),this.negative^=1,this._normSign();if(this.negative===0&&r.negative!==0)return r.negative=0,u=this.isub(r),r.negative=1,u._normSign();var m,d;this.length>r.length?(m=this,d=r):(m=r,d=this);for(var h=0,T=0;T<d.length;T++)u=(m.words[T]|0)+(d.words[T]|0)+h,this.words[T]=u&67108863,h=u>>>26;for(;h!==0&&T<m.length;T++)u=(m.words[T]|0)+h,this.words[T]=u&67108863,h=u>>>26;if(this.length=m.length,h!==0)this.words[this.length]=h,this.length++;else if(m!==this)for(;T<m.length;T++)this.words[T]=m.words[T];return this},o.prototype.add=function(r){var u;return r.negative!==0&&this.negative===0?(r.negative=0,u=this.sub(r),r.negative^=1,u):r.negative===0&&this.negative!==0?(this.negative=0,u=r.sub(this),this.negative=1,u):this.length>r.length?this.clone().iadd(r):r.clone().iadd(this)},o.prototype.isub=function(r){if(r.negative!==0){r.negative=0;var u=this.iadd(r);return r.negative=1,u._normSign()}else if(this.negative!==0)return this.negative=0,this.iadd(r),this.negative=1,this._normSign();var m=this.cmp(r);if(m===0)return this.negative=0,this.length=1,this.words[0]=0,this;var d,h;m>0?(d=this,h=r):(d=r,h=this);for(var T=0,C=0;C<h.length;C++)u=(d.words[C]|0)-(h.words[C]|0)+T,T=u>>26,this.words[C]=u&67108863;for(;T!==0&&C<d.length;C++)u=(d.words[C]|0)+T,T=u>>26,this.words[C]=u&67108863;if(T===0&&C<d.length&&d!==this)for(;C<d.length;C++)this.words[C]=d.words[C];return this.length=Math.max(this.length,C),d!==this&&(this.negative=1),this._strip()},o.prototype.sub=function(r){return this.clone().isub(r)};function L(y,r,u){u.negative=r.negative^y.negative;var m=y.length+r.length|0;u.length=m,m=m-1|0;var d=y.words[0]|0,h=r.words[0]|0,T=d*h,C=T&67108863,f=T/67108864|0;u.words[0]=C;for(var l=1;l<m;l++){for(var g=f>>>26,v=f&67108863,O=Math.min(l,r.length-1),P=Math.max(0,l-y.length+1);P<=O;P++){var B=l-P|0;d=y.words[B]|0,h=r.words[P]|0,T=d*h+v,g+=T/67108864|0,v=T&67108863}u.words[l]=v|0,f=g|0}return f!==0?u.words[l]=f|0:u.length--,u._strip()}var U=function(r,u,m){var d=r.words,h=u.words,T=m.words,C=0,f,l,g,v=d[0]|0,O=v&8191,P=v>>>13,B=d[1]|0,_=B&8191,F=B>>>13,me=d[2]|0,K=me&8191,$=me>>>13,ac=d[3]|0,z=ac&8191,G=ac>>>13,ic=d[4]|0,Q=ic&8191,Y=ic>>>13,rc=d[5]|0,J=rc&8191,Z=rc>>>13,sc=d[6]|0,tt=sc&8191,et=sc>>>13,cc=d[7]|0,nt=cc&8191,ot=cc>>>13,lc=d[8]|0,at=lc&8191,it=lc>>>13,uc=d[9]|0,rt=uc&8191,st=uc>>>13,mc=h[0]|0,ct=mc&8191,lt=mc>>>13,pc=h[1]|0,ut=pc&8191,mt=pc>>>13,dc=h[2]|0,pt=dc&8191,dt=dc>>>13,fc=h[3]|0,ft=fc&8191,ht=fc>>>13,hc=h[4]|0,gt=hc&8191,yt=hc>>>13,gc=h[5]|0,bt=gc&8191,Tt=gc>>>13,yc=h[6]|0,St=yc&8191,It=yc>>>13,bc=h[7]|0,wt=bc&8191,Ct=bc>>>13,Tc=h[8]|0,Dt=Tc&8191,xt=Tc>>>13,Sc=h[9]|0,kt=Sc&8191,vt=Sc>>>13;m.negative=r.negative^u.negative,m.length=19,f=Math.imul(O,ct),l=Math.imul(O,lt),l=l+Math.imul(P,ct)|0,g=Math.imul(P,lt);var qr=(C+f|0)+((l&8191)<<13)|0;C=(g+(l>>>13)|0)+(qr>>>26)|0,qr&=67108863,f=Math.imul(_,ct),l=Math.imul(_,lt),l=l+Math.imul(F,ct)|0,g=Math.imul(F,lt),f=f+Math.imul(O,ut)|0,l=l+Math.imul(O,mt)|0,l=l+Math.imul(P,ut)|0,g=g+Math.imul(P,mt)|0;var Fr=(C+f|0)+((l&8191)<<13)|0;C=(g+(l>>>13)|0)+(Fr>>>26)|0,Fr&=67108863,f=Math.imul(K,ct),l=Math.imul(K,lt),l=l+Math.imul($,ct)|0,g=Math.imul($,lt),f=f+Math.imul(_,ut)|0,l=l+Math.imul(_,mt)|0,l=l+Math.imul(F,ut)|0,g=g+Math.imul(F,mt)|0,f=f+Math.imul(O,pt)|0,l=l+Math.imul(O,dt)|0,l=l+Math.imul(P,pt)|0,g=g+Math.imul(P,dt)|0;var Kr=(C+f|0)+((l&8191)<<13)|0;C=(g+(l>>>13)|0)+(Kr>>>26)|0,Kr&=67108863,f=Math.imul(z,ct),l=Math.imul(z,lt),l=l+Math.imul(G,ct)|0,g=Math.imul(G,lt),f=f+Math.imul(K,ut)|0,l=l+Math.imul(K,mt)|0,l=l+Math.imul($,ut)|0,g=g+Math.imul($,mt)|0,f=f+Math.imul(_,pt)|0,l=l+Math.imul(_,dt)|0,l=l+Math.imul(F,pt)|0,g=g+Math.imul(F,dt)|0,f=f+Math.imul(O,ft)|0,l=l+Math.imul(O,ht)|0,l=l+Math.imul(P,ft)|0,g=g+Math.imul(P,ht)|0;var Vr=(C+f|0)+((l&8191)<<13)|0;C=(g+(l>>>13)|0)+(Vr>>>26)|0,Vr&=67108863,f=Math.imul(Q,ct),l=Math.imul(Q,lt),l=l+Math.imul(Y,ct)|0,g=Math.imul(Y,lt),f=f+Math.imul(z,ut)|0,l=l+Math.imul(z,mt)|0,l=l+Math.imul(G,ut)|0,g=g+Math.imul(G,mt)|0,f=f+Math.imul(K,pt)|0,l=l+Math.imul(K,dt)|0,l=l+Math.imul($,pt)|0,g=g+Math.imul($,dt)|0,f=f+Math.imul(_,ft)|0,l=l+Math.imul(_,ht)|0,l=l+Math.imul(F,ft)|0,g=g+Math.imul(F,ht)|0,f=f+Math.imul(O,gt)|0,l=l+Math.imul(O,yt)|0,l=l+Math.imul(P,gt)|0,g=g+Math.imul(P,yt)|0;var $r=(C+f|0)+((l&8191)<<13)|0;C=(g+(l>>>13)|0)+($r>>>26)|0,$r&=67108863,f=Math.imul(J,ct),l=Math.imul(J,lt),l=l+Math.imul(Z,ct)|0,g=Math.imul(Z,lt),f=f+Math.imul(Q,ut)|0,l=l+Math.imul(Q,mt)|0,l=l+Math.imul(Y,ut)|0,g=g+Math.imul(Y,mt)|0,f=f+Math.imul(z,pt)|0,l=l+Math.imul(z,dt)|0,l=l+Math.imul(G,pt)|0,g=g+Math.imul(G,dt)|0,f=f+Math.imul(K,ft)|0,l=l+Math.imul(K,ht)|0,l=l+Math.imul($,ft)|0,g=g+Math.imul($,ht)|0,f=f+Math.imul(_,gt)|0,l=l+Math.imul(_,yt)|0,l=l+Math.imul(F,gt)|0,g=g+Math.imul(F,yt)|0,f=f+Math.imul(O,bt)|0,l=l+Math.imul(O,Tt)|0,l=l+Math.imul(P,bt)|0,g=g+Math.imul(P,Tt)|0;var Hr=(C+f|0)+((l&8191)<<13)|0;C=(g+(l>>>13)|0)+(Hr>>>26)|0,Hr&=67108863,f=Math.imul(tt,ct),l=Math.imul(tt,lt),l=l+Math.imul(et,ct)|0,g=Math.imul(et,lt),f=f+Math.imul(J,ut)|0,l=l+Math.imul(J,mt)|0,l=l+Math.imul(Z,ut)|0,g=g+Math.imul(Z,mt)|0,f=f+Math.imul(Q,pt)|0,l=l+Math.imul(Q,dt)|0,l=l+Math.imul(Y,pt)|0,g=g+Math.imul(Y,dt)|0,f=f+Math.imul(z,ft)|0,l=l+Math.imul(z,ht)|0,l=l+Math.imul(G,ft)|0,g=g+Math.imul(G,ht)|0,f=f+Math.imul(K,gt)|0,l=l+Math.imul(K,yt)|0,l=l+Math.imul($,gt)|0,g=g+Math.imul($,yt)|0,f=f+Math.imul(_,bt)|0,l=l+Math.imul(_,Tt)|0,l=l+Math.imul(F,bt)|0,g=g+Math.imul(F,Tt)|0,f=f+Math.imul(O,St)|0,l=l+Math.imul(O,It)|0,l=l+Math.imul(P,St)|0,g=g+Math.imul(P,It)|0;var Xr=(C+f|0)+((l&8191)<<13)|0;C=(g+(l>>>13)|0)+(Xr>>>26)|0,Xr&=67108863,f=Math.imul(nt,ct),l=Math.imul(nt,lt),l=l+Math.imul(ot,ct)|0,g=Math.imul(ot,lt),f=f+Math.imul(tt,ut)|0,l=l+Math.imul(tt,mt)|0,l=l+Math.imul(et,ut)|0,g=g+Math.imul(et,mt)|0,f=f+Math.imul(J,pt)|0,l=l+Math.imul(J,dt)|0,l=l+Math.imul(Z,pt)|0,g=g+Math.imul(Z,dt)|0,f=f+Math.imul(Q,ft)|0,l=l+Math.imul(Q,ht)|0,l=l+Math.imul(Y,ft)|0,g=g+Math.imul(Y,ht)|0,f=f+Math.imul(z,gt)|0,l=l+Math.imul(z,yt)|0,l=l+Math.imul(G,gt)|0,g=g+Math.imul(G,yt)|0,f=f+Math.imul(K,bt)|0,l=l+Math.imul(K,Tt)|0,l=l+Math.imul($,bt)|0,g=g+Math.imul($,Tt)|0,f=f+Math.imul(_,St)|0,l=l+Math.imul(_,It)|0,l=l+Math.imul(F,St)|0,g=g+Math.imul(F,It)|0,f=f+Math.imul(O,wt)|0,l=l+Math.imul(O,Ct)|0,l=l+Math.imul(P,wt)|0,g=g+Math.imul(P,Ct)|0;var zr=(C+f|0)+((l&8191)<<13)|0;C=(g+(l>>>13)|0)+(zr>>>26)|0,zr&=67108863,f=Math.imul(at,ct),l=Math.imul(at,lt),l=l+Math.imul(it,ct)|0,g=Math.imul(it,lt),f=f+Math.imul(nt,ut)|0,l=l+Math.imul(nt,mt)|0,l=l+Math.imul(ot,ut)|0,g=g+Math.imul(ot,mt)|0,f=f+Math.imul(tt,pt)|0,l=l+Math.imul(tt,dt)|0,l=l+Math.imul(et,pt)|0,g=g+Math.imul(et,dt)|0,f=f+Math.imul(J,ft)|0,l=l+Math.imul(J,ht)|0,l=l+Math.imul(Z,ft)|0,g=g+Math.imul(Z,ht)|0,f=f+Math.imul(Q,gt)|0,l=l+Math.imul(Q,yt)|0,l=l+Math.imul(Y,gt)|0,g=g+Math.imul(Y,yt)|0,f=f+Math.imul(z,bt)|0,l=l+Math.imul(z,Tt)|0,l=l+Math.imul(G,bt)|0,g=g+Math.imul(G,Tt)|0,f=f+Math.imul(K,St)|0,l=l+Math.imul(K,It)|0,l=l+Math.imul($,St)|0,g=g+Math.imul($,It)|0,f=f+Math.imul(_,wt)|0,l=l+Math.imul(_,Ct)|0,l=l+Math.imul(F,wt)|0,g=g+Math.imul(F,Ct)|0,f=f+Math.imul(O,Dt)|0,l=l+Math.imul(O,xt)|0,l=l+Math.imul(P,Dt)|0,g=g+Math.imul(P,xt)|0;var Gr=(C+f|0)+((l&8191)<<13)|0;C=(g+(l>>>13)|0)+(Gr>>>26)|0,Gr&=67108863,f=Math.imul(rt,ct),l=Math.imul(rt,lt),l=l+Math.imul(st,ct)|0,g=Math.imul(st,lt),f=f+Math.imul(at,ut)|0,l=l+Math.imul(at,mt)|0,l=l+Math.imul(it,ut)|0,g=g+Math.imul(it,mt)|0,f=f+Math.imul(nt,pt)|0,l=l+Math.imul(nt,dt)|0,l=l+Math.imul(ot,pt)|0,g=g+Math.imul(ot,dt)|0,f=f+Math.imul(tt,ft)|0,l=l+Math.imul(tt,ht)|0,l=l+Math.imul(et,ft)|0,g=g+Math.imul(et,ht)|0,f=f+Math.imul(J,gt)|0,l=l+Math.imul(J,yt)|0,l=l+Math.imul(Z,gt)|0,g=g+Math.imul(Z,yt)|0,f=f+Math.imul(Q,bt)|0,l=l+Math.imul(Q,Tt)|0,l=l+Math.imul(Y,bt)|0,g=g+Math.imul(Y,Tt)|0,f=f+Math.imul(z,St)|0,l=l+Math.imul(z,It)|0,l=l+Math.imul(G,St)|0,g=g+Math.imul(G,It)|0,f=f+Math.imul(K,wt)|0,l=l+Math.imul(K,Ct)|0,l=l+Math.imul($,wt)|0,g=g+Math.imul($,Ct)|0,f=f+Math.imul(_,Dt)|0,l=l+Math.imul(_,xt)|0,l=l+Math.imul(F,Dt)|0,g=g+Math.imul(F,xt)|0,f=f+Math.imul(O,kt)|0,l=l+Math.imul(O,vt)|0,l=l+Math.imul(P,kt)|0,g=g+Math.imul(P,vt)|0;var Qr=(C+f|0)+((l&8191)<<13)|0;C=(g+(l>>>13)|0)+(Qr>>>26)|0,Qr&=67108863,f=Math.imul(rt,ut),l=Math.imul(rt,mt),l=l+Math.imul(st,ut)|0,g=Math.imul(st,mt),f=f+Math.imul(at,pt)|0,l=l+Math.imul(at,dt)|0,l=l+Math.imul(it,pt)|0,g=g+Math.imul(it,dt)|0,f=f+Math.imul(nt,ft)|0,l=l+Math.imul(nt,ht)|0,l=l+Math.imul(ot,ft)|0,g=g+Math.imul(ot,ht)|0,f=f+Math.imul(tt,gt)|0,l=l+Math.imul(tt,yt)|0,l=l+Math.imul(et,gt)|0,g=g+Math.imul(et,yt)|0,f=f+Math.imul(J,bt)|0,l=l+Math.imul(J,Tt)|0,l=l+Math.imul(Z,bt)|0,g=g+Math.imul(Z,Tt)|0,f=f+Math.imul(Q,St)|0,l=l+Math.imul(Q,It)|0,l=l+Math.imul(Y,St)|0,g=g+Math.imul(Y,It)|0,f=f+Math.imul(z,wt)|0,l=l+Math.imul(z,Ct)|0,l=l+Math.imul(G,wt)|0,g=g+Math.imul(G,Ct)|0,f=f+Math.imul(K,Dt)|0,l=l+Math.imul(K,xt)|0,l=l+Math.imul($,Dt)|0,g=g+Math.imul($,xt)|0,f=f+Math.imul(_,kt)|0,l=l+Math.imul(_,vt)|0,l=l+Math.imul(F,kt)|0,g=g+Math.imul(F,vt)|0;var Yr=(C+f|0)+((l&8191)<<13)|0;C=(g+(l>>>13)|0)+(Yr>>>26)|0,Yr&=67108863,f=Math.imul(rt,pt),l=Math.imul(rt,dt),l=l+Math.imul(st,pt)|0,g=Math.imul(st,dt),f=f+Math.imul(at,ft)|0,l=l+Math.imul(at,ht)|0,l=l+Math.imul(it,ft)|0,g=g+Math.imul(it,ht)|0,f=f+Math.imul(nt,gt)|0,l=l+Math.imul(nt,yt)|0,l=l+Math.imul(ot,gt)|0,g=g+Math.imul(ot,yt)|0,f=f+Math.imul(tt,bt)|0,l=l+Math.imul(tt,Tt)|0,l=l+Math.imul(et,bt)|0,g=g+Math.imul(et,Tt)|0,f=f+Math.imul(J,St)|0,l=l+Math.imul(J,It)|0,l=l+Math.imul(Z,St)|0,g=g+Math.imul(Z,It)|0,f=f+Math.imul(Q,wt)|0,l=l+Math.imul(Q,Ct)|0,l=l+Math.imul(Y,wt)|0,g=g+Math.imul(Y,Ct)|0,f=f+Math.imul(z,Dt)|0,l=l+Math.imul(z,xt)|0,l=l+Math.imul(G,Dt)|0,g=g+Math.imul(G,xt)|0,f=f+Math.imul(K,kt)|0,l=l+Math.imul(K,vt)|0,l=l+Math.imul($,kt)|0,g=g+Math.imul($,vt)|0;var Jr=(C+f|0)+((l&8191)<<13)|0;C=(g+(l>>>13)|0)+(Jr>>>26)|0,Jr&=67108863,f=Math.imul(rt,ft),l=Math.imul(rt,ht),l=l+Math.imul(st,ft)|0,g=Math.imul(st,ht),f=f+Math.imul(at,gt)|0,l=l+Math.imul(at,yt)|0,l=l+Math.imul(it,gt)|0,g=g+Math.imul(it,yt)|0,f=f+Math.imul(nt,bt)|0,l=l+Math.imul(nt,Tt)|0,l=l+Math.imul(ot,bt)|0,g=g+Math.imul(ot,Tt)|0,f=f+Math.imul(tt,St)|0,l=l+Math.imul(tt,It)|0,l=l+Math.imul(et,St)|0,g=g+Math.imul(et,It)|0,f=f+Math.imul(J,wt)|0,l=l+Math.imul(J,Ct)|0,l=l+Math.imul(Z,wt)|0,g=g+Math.imul(Z,Ct)|0,f=f+Math.imul(Q,Dt)|0,l=l+Math.imul(Q,xt)|0,l=l+Math.imul(Y,Dt)|0,g=g+Math.imul(Y,xt)|0,f=f+Math.imul(z,kt)|0,l=l+Math.imul(z,vt)|0,l=l+Math.imul(G,kt)|0,g=g+Math.imul(G,vt)|0;var Zr=(C+f|0)+((l&8191)<<13)|0;C=(g+(l>>>13)|0)+(Zr>>>26)|0,Zr&=67108863,f=Math.imul(rt,gt),l=Math.imul(rt,yt),l=l+Math.imul(st,gt)|0,g=Math.imul(st,yt),f=f+Math.imul(at,bt)|0,l=l+Math.imul(at,Tt)|0,l=l+Math.imul(it,bt)|0,g=g+Math.imul(it,Tt)|0,f=f+Math.imul(nt,St)|0,l=l+Math.imul(nt,It)|0,l=l+Math.imul(ot,St)|0,g=g+Math.imul(ot,It)|0,f=f+Math.imul(tt,wt)|0,l=l+Math.imul(tt,Ct)|0,l=l+Math.imul(et,wt)|0,g=g+Math.imul(et,Ct)|0,f=f+Math.imul(J,Dt)|0,l=l+Math.imul(J,xt)|0,l=l+Math.imul(Z,Dt)|0,g=g+Math.imul(Z,xt)|0,f=f+Math.imul(Q,kt)|0,l=l+Math.imul(Q,vt)|0,l=l+Math.imul(Y,kt)|0,g=g+Math.imul(Y,vt)|0;var ts=(C+f|0)+((l&8191)<<13)|0;C=(g+(l>>>13)|0)+(ts>>>26)|0,ts&=67108863,f=Math.imul(rt,bt),l=Math.imul(rt,Tt),l=l+Math.imul(st,bt)|0,g=Math.imul(st,Tt),f=f+Math.imul(at,St)|0,l=l+Math.imul(at,It)|0,l=l+Math.imul(it,St)|0,g=g+Math.imul(it,It)|0,f=f+Math.imul(nt,wt)|0,l=l+Math.imul(nt,Ct)|0,l=l+Math.imul(ot,wt)|0,g=g+Math.imul(ot,Ct)|0,f=f+Math.imul(tt,Dt)|0,l=l+Math.imul(tt,xt)|0,l=l+Math.imul(et,Dt)|0,g=g+Math.imul(et,xt)|0,f=f+Math.imul(J,kt)|0,l=l+Math.imul(J,vt)|0,l=l+Math.imul(Z,kt)|0,g=g+Math.imul(Z,vt)|0;var es=(C+f|0)+((l&8191)<<13)|0;C=(g+(l>>>13)|0)+(es>>>26)|0,es&=67108863,f=Math.imul(rt,St),l=Math.imul(rt,It),l=l+Math.imul(st,St)|0,g=Math.imul(st,It),f=f+Math.imul(at,wt)|0,l=l+Math.imul(at,Ct)|0,l=l+Math.imul(it,wt)|0,g=g+Math.imul(it,Ct)|0,f=f+Math.imul(nt,Dt)|0,l=l+Math.imul(nt,xt)|0,l=l+Math.imul(ot,Dt)|0,g=g+Math.imul(ot,xt)|0,f=f+Math.imul(tt,kt)|0,l=l+Math.imul(tt,vt)|0,l=l+Math.imul(et,kt)|0,g=g+Math.imul(et,vt)|0;var ns=(C+f|0)+((l&8191)<<13)|0;C=(g+(l>>>13)|0)+(ns>>>26)|0,ns&=67108863,f=Math.imul(rt,wt),l=Math.imul(rt,Ct),l=l+Math.imul(st,wt)|0,g=Math.imul(st,Ct),f=f+Math.imul(at,Dt)|0,l=l+Math.imul(at,xt)|0,l=l+Math.imul(it,Dt)|0,g=g+Math.imul(it,xt)|0,f=f+Math.imul(nt,kt)|0,l=l+Math.imul(nt,vt)|0,l=l+Math.imul(ot,kt)|0,g=g+Math.imul(ot,vt)|0;var os=(C+f|0)+((l&8191)<<13)|0;C=(g+(l>>>13)|0)+(os>>>26)|0,os&=67108863,f=Math.imul(rt,Dt),l=Math.imul(rt,xt),l=l+Math.imul(st,Dt)|0,g=Math.imul(st,xt),f=f+Math.imul(at,kt)|0,l=l+Math.imul(at,vt)|0,l=l+Math.imul(it,kt)|0,g=g+Math.imul(it,vt)|0;var as=(C+f|0)+((l&8191)<<13)|0;C=(g+(l>>>13)|0)+(as>>>26)|0,as&=67108863,f=Math.imul(rt,kt),l=Math.imul(rt,vt),l=l+Math.imul(st,kt)|0,g=Math.imul(st,vt);var is=(C+f|0)+((l&8191)<<13)|0;return C=(g+(l>>>13)|0)+(is>>>26)|0,is&=67108863,T[0]=qr,T[1]=Fr,T[2]=Kr,T[3]=Vr,T[4]=$r,T[5]=Hr,T[6]=Xr,T[7]=zr,T[8]=Gr,T[9]=Qr,T[10]=Yr,T[11]=Jr,T[12]=Zr,T[13]=ts,T[14]=es,T[15]=ns,T[16]=os,T[17]=as,T[18]=is,C!==0&&(T[19]=C,m.length++),m};Math.imul||(U=L);function q(y,r,u){u.negative=r.negative^y.negative,u.length=y.length+r.length;for(var m=0,d=0,h=0;h<u.length-1;h++){var T=d;d=0;for(var C=m&67108863,f=Math.min(h,r.length-1),l=Math.max(0,h-y.length+1);l<=f;l++){var g=h-l,v=y.words[g]|0,O=r.words[l]|0,P=v*O,B=P&67108863;T=T+(P/67108864|0)|0,B=B+C|0,C=B&67108863,T=T+(B>>>26)|0,d+=T>>>26,T&=67108863}u.words[h]=C,m=T,T=d}return m!==0?u.words[h]=m:u.length--,u._strip()}function Mt(y,r,u){return q(y,r,u)}o.prototype.mulTo=function(r,u){var m,d=this.length+r.length;return this.length===10&&r.length===10?m=U(this,r,u):d<63?m=L(this,r,u):d<1024?m=q(this,r,u):m=Mt(this,r,u),m};function W(y,r){this.x=y,this.y=r}W.prototype.makeRBT=function(r){for(var u=new Array(r),m=o.prototype._countBits(r)-1,d=0;d<r;d++)u[d]=this.revBin(d,m,r);return u},W.prototype.revBin=function(r,u,m){if(r===0||r===m-1)return r;for(var d=0,h=0;h<u;h++)d|=(r&1)<<u-h-1,r>>=1;return d},W.prototype.permute=function(r,u,m,d,h,T){for(var C=0;C<T;C++)d[C]=u[r[C]],h[C]=m[r[C]]},W.prototype.transform=function(r,u,m,d,h,T){this.permute(T,r,u,m,d,h);for(var C=1;C<h;C<<=1)for(var f=C<<1,l=Math.cos(2*Math.PI/f),g=Math.sin(2*Math.PI/f),v=0;v<h;v+=f)for(var O=l,P=g,B=0;B<C;B++){var _=m[v+B],F=d[v+B],me=m[v+B+C],K=d[v+B+C],$=O*me-P*K;K=O*K+P*me,me=$,m[v+B]=_+me,d[v+B]=F+K,m[v+B+C]=_-me,d[v+B+C]=F-K,B!==f&&($=l*O-g*P,P=l*P+g*O,O=$)}},W.prototype.guessLen13b=function(r,u){var m=Math.max(u,r)|1,d=m&1,h=0;for(m=m/2|0;m;m=m>>>1)h++;return 1<<h+1+d},W.prototype.conjugate=function(r,u,m){if(!(m<=1))for(var d=0;d<m/2;d++){var h=r[d];r[d]=r[m-d-1],r[m-d-1]=h,h=u[d],u[d]=-u[m-d-1],u[m-d-1]=-h}},W.prototype.normalize13b=function(r,u){for(var m=0,d=0;d<u/2;d++){var h=Math.round(r[2*d+1]/u)*8192+Math.round(r[2*d]/u)+m;r[d]=h&67108863,h<67108864?m=0:m=h/67108864|0}return r},W.prototype.convert13b=function(r,u,m,d){for(var h=0,T=0;T<u;T++)h=h+(r[T]|0),m[2*T]=h&8191,h=h>>>13,m[2*T+1]=h&8191,h=h>>>13;for(T=2*u;T<d;++T)m[T]=0;t(h===0),t((h&-8192)===0)},W.prototype.stub=function(r){for(var u=new Array(r),m=0;m<r;m++)u[m]=0;return u},W.prototype.mulp=function(r,u,m){var d=2*this.guessLen13b(r.length,u.length),h=this.makeRBT(d),T=this.stub(d),C=new Array(d),f=new Array(d),l=new Array(d),g=new Array(d),v=new Array(d),O=new Array(d),P=m.words;P.length=d,this.convert13b(r.words,r.length,C,d),this.convert13b(u.words,u.length,g,d),this.transform(C,T,f,l,d,h),this.transform(g,T,v,O,d,h);for(var B=0;B<d;B++){var _=f[B]*v[B]-l[B]*O[B];l[B]=f[B]*O[B]+l[B]*v[B],f[B]=_}return this.conjugate(f,l,d),this.transform(f,l,P,T,d,h),this.conjugate(P,T,d),this.normalize13b(P,d),m.negative=r.negative^u.negative,m.length=r.length+u.length,m._strip()},o.prototype.mul=function(r){var u=new o(null);return u.words=new Array(this.length+r.length),this.mulTo(r,u)},o.prototype.mulf=function(r){var u=new o(null);return u.words=new Array(this.length+r.length),Mt(this,r,u)},o.prototype.imul=function(r){return this.clone().mulTo(r,this)},o.prototype.imuln=function(r){var u=r<0;u&&(r=-r),t(typeof r=="number"),t(r<67108864);for(var m=0,d=0;d<this.length;d++){var h=(this.words[d]|0)*r,T=(h&67108863)+(m&67108863);m>>=26,m+=h/67108864|0,m+=T>>>26,this.words[d]=T&67108863}return m!==0&&(this.words[d]=m,this.length++),this.length=r===0?1:this.length,u?this.ineg():this},o.prototype.muln=function(r){return this.clone().imuln(r)},o.prototype.sqr=function(){return this.mul(this)},o.prototype.isqr=function(){return this.imul(this.clone())},o.prototype.pow=function(r){var u=M(r);if(u.length===0)return new o(1);for(var m=this,d=0;d<u.length&&u[d]===0;d++,m=m.sqr());if(++d<u.length)for(var h=m.sqr();d<u.length;d++,h=h.sqr())u[d]!==0&&(m=m.mul(h));return m},o.prototype.iushln=function(r){t(typeof r=="number"&&r>=0);var u=r%26,m=(r-u)/26,d=67108863>>>26-u<<26-u,h;if(u!==0){var T=0;for(h=0;h<this.length;h++){var C=this.words[h]&d,f=(this.words[h]|0)-C<<u;this.words[h]=f|T,T=C>>>26-u}T&&(this.words[h]=T,this.length++)}if(m!==0){for(h=this.length-1;h>=0;h--)this.words[h+m]=this.words[h];for(h=0;h<m;h++)this.words[h]=0;this.length+=m}return this._strip()},o.prototype.ishln=function(r){return t(this.negative===0),this.iushln(r)},o.prototype.iushrn=function(r,u,m){t(typeof r=="number"&&r>=0);var d;u?d=(u-u%26)/26:d=0;var h=r%26,T=Math.min((r-h)/26,this.length),C=67108863^67108863>>>h<<h,f=m;if(d-=T,d=Math.max(0,d),f){for(var l=0;l<T;l++)f.words[l]=this.words[l];f.length=T}if(T!==0)if(this.length>T)for(this.length-=T,l=0;l<this.length;l++)this.words[l]=this.words[l+T];else this.words[0]=0,this.length=1;var g=0;for(l=this.length-1;l>=0&&(g!==0||l>=d);l--){var v=this.words[l]|0;this.words[l]=g<<26-h|v>>>h,g=v&C}return f&&g!==0&&(f.words[f.length++]=g),this.length===0&&(this.words[0]=0,this.length=1),this._strip()},o.prototype.ishrn=function(r,u,m){return t(this.negative===0),this.iushrn(r,u,m)},o.prototype.shln=function(r){return this.clone().ishln(r)},o.prototype.ushln=function(r){return this.clone().iushln(r)},o.prototype.shrn=function(r){return this.clone().ishrn(r)},o.prototype.ushrn=function(r){return this.clone().iushrn(r)},o.prototype.testn=function(r){t(typeof r=="number"&&r>=0);var u=r%26,m=(r-u)/26,d=1<<u;if(this.length<=m)return!1;var h=this.words[m];return!!(h&d)},o.prototype.imaskn=function(r){t(typeof r=="number"&&r>=0);var u=r%26,m=(r-u)/26;if(t(this.negative===0,"imaskn works only with positive numbers"),this.length<=m)return this;if(u!==0&&m++,this.length=Math.min(m,this.length),u!==0){var d=67108863^67108863>>>u<<u;this.words[this.length-1]&=d}return this._strip()},o.prototype.maskn=function(r){return this.clone().imaskn(r)},o.prototype.iaddn=function(r){return t(typeof r=="number"),t(r<67108864),r<0?this.isubn(-r):this.negative!==0?this.length===1&&(this.words[0]|0)<=r?(this.words[0]=r-(this.words[0]|0),this.negative=0,this):(this.negative=0,this.isubn(r),this.negative=1,this):this._iaddn(r)},o.prototype._iaddn=function(r){this.words[0]+=r;for(var u=0;u<this.length&&this.words[u]>=67108864;u++)this.words[u]-=67108864,u===this.length-1?this.words[u+1]=1:this.words[u+1]++;return this.length=Math.max(this.length,u+1),this},o.prototype.isubn=function(r){if(t(typeof r=="number"),t(r<67108864),r<0)return this.iaddn(-r);if(this.negative!==0)return this.negative=0,this.iaddn(r),this.negative=1,this;if(this.words[0]-=r,this.length===1&&this.words[0]<0)this.words[0]=-this.words[0],this.negative=1;else for(var u=0;u<this.length&&this.words[u]<0;u++)this.words[u]+=67108864,this.words[u+1]-=1;return this._strip()},o.prototype.addn=function(r){return this.clone().iaddn(r)},o.prototype.subn=function(r){return this.clone().isubn(r)},o.prototype.iabs=function(){return this.negative=0,this},o.prototype.abs=function(){return this.clone().iabs()},o.prototype._ishlnsubmul=function(r,u,m){var d=r.length+m,h;this._expand(d);var T,C=0;for(h=0;h<r.length;h++){T=(this.words[h+m]|0)+C;var f=(r.words[h]|0)*u;T-=f&67108863,C=(T>>26)-(f/67108864|0),this.words[h+m]=T&67108863}for(;h<this.length-m;h++)T=(this.words[h+m]|0)+C,C=T>>26,this.words[h+m]=T&67108863;if(C===0)return this._strip();for(t(C===-1),C=0,h=0;h<this.length;h++)T=-(this.words[h]|0)+C,C=T>>26,this.words[h]=T&67108863;return this.negative=1,this._strip()},o.prototype._wordDiv=function(r,u){var m=this.length-r.length,d=this.clone(),h=r,T=h.words[h.length-1]|0,C=this._countBits(T);m=26-C,m!==0&&(h=h.ushln(m),d.iushln(m),T=h.words[h.length-1]|0);var f=d.length-h.length,l;if(u!=="mod"){l=new o(null),l.length=f+1,l.words=new Array(l.length);for(var g=0;g<l.length;g++)l.words[g]=0}var v=d.clone()._ishlnsubmul(h,1,f);v.negative===0&&(d=v,l&&(l.words[f]=1));for(var O=f-1;O>=0;O--){var P=(d.words[h.length+O]|0)*67108864+(d.words[h.length+O-1]|0);for(P=Math.min(P/T|0,67108863),d._ishlnsubmul(h,P,O);d.negative!==0;)P--,d.negative=0,d._ishlnsubmul(h,1,O),d.isZero()||(d.negative^=1);l&&(l.words[O]=P)}return l&&l._strip(),d._strip(),u!=="div"&&m!==0&&d.iushrn(m),{div:l||null,mod:d}},o.prototype.divmod=function(r,u,m){if(t(!r.isZero()),this.isZero())return{div:new o(0),mod:new o(0)};var d,h,T;return this.negative!==0&&r.negative===0?(T=this.neg().divmod(r,u),u!=="mod"&&(d=T.div.neg()),u!=="div"&&(h=T.mod.neg(),m&&h.negative!==0&&h.iadd(r)),{div:d,mod:h}):this.negative===0&&r.negative!==0?(T=this.divmod(r.neg(),u),u!=="mod"&&(d=T.div.neg()),{div:d,mod:T.mod}):(this.negative&r.negative)!==0?(T=this.neg().divmod(r.neg(),u),u!=="div"&&(h=T.mod.neg(),m&&h.negative!==0&&h.isub(r)),{div:T.div,mod:h}):r.length>this.length||this.cmp(r)<0?{div:new o(0),mod:this}:r.length===1?u==="div"?{div:this.divn(r.words[0]),mod:null}:u==="mod"?{div:null,mod:new o(this.modrn(r.words[0]))}:{div:this.divn(r.words[0]),mod:new o(this.modrn(r.words[0]))}:this._wordDiv(r,u)},o.prototype.div=function(r){return this.divmod(r,"div",!1).div},o.prototype.mod=function(r){return this.divmod(r,"mod",!1).mod},o.prototype.umod=function(r){return this.divmod(r,"mod",!0).mod},o.prototype.divRound=function(r){var u=this.divmod(r);if(u.mod.isZero())return u.div;var m=u.div.negative!==0?u.mod.isub(r):u.mod,d=r.ushrn(1),h=r.andln(1),T=m.cmp(d);return T<0||h===1&&T===0?u.div:u.div.negative!==0?u.div.isubn(1):u.div.iaddn(1)},o.prototype.modrn=function(r){var u=r<0;u&&(r=-r),t(r<=67108863);for(var m=(1<<26)%r,d=0,h=this.length-1;h>=0;h--)d=(m*d+(this.words[h]|0))%r;return u?-d:d},o.prototype.modn=function(r){return this.modrn(r)},o.prototype.idivn=function(r){var u=r<0;u&&(r=-r),t(r<=67108863);for(var m=0,d=this.length-1;d>=0;d--){var h=(this.words[d]|0)+m*67108864;this.words[d]=h/r|0,m=h%r}return this._strip(),u?this.ineg():this},o.prototype.divn=function(r){return this.clone().idivn(r)},o.prototype.egcd=function(r){t(r.negative===0),t(!r.isZero());var u=this,m=r.clone();u.negative!==0?u=u.umod(r):u=u.clone();for(var d=new o(1),h=new o(0),T=new o(0),C=new o(1),f=0;u.isEven()&&m.isEven();)u.iushrn(1),m.iushrn(1),++f;for(var l=m.clone(),g=u.clone();!u.isZero();){for(var v=0,O=1;(u.words[0]&O)===0&&v<26;++v,O<<=1);if(v>0)for(u.iushrn(v);v-- >0;)(d.isOdd()||h.isOdd())&&(d.iadd(l),h.isub(g)),d.iushrn(1),h.iushrn(1);for(var P=0,B=1;(m.words[0]&B)===0&&P<26;++P,B<<=1);if(P>0)for(m.iushrn(P);P-- >0;)(T.isOdd()||C.isOdd())&&(T.iadd(l),C.isub(g)),T.iushrn(1),C.iushrn(1);u.cmp(m)>=0?(u.isub(m),d.isub(T),h.isub(C)):(m.isub(u),T.isub(d),C.isub(h))}return{a:T,b:C,gcd:m.iushln(f)}},o.prototype._invmp=function(r){t(r.negative===0),t(!r.isZero());var u=this,m=r.clone();u.negative!==0?u=u.umod(r):u=u.clone();for(var d=new o(1),h=new o(0),T=m.clone();u.cmpn(1)>0&&m.cmpn(1)>0;){for(var C=0,f=1;(u.words[0]&f)===0&&C<26;++C,f<<=1);if(C>0)for(u.iushrn(C);C-- >0;)d.isOdd()&&d.iadd(T),d.iushrn(1);for(var l=0,g=1;(m.words[0]&g)===0&&l<26;++l,g<<=1);if(l>0)for(m.iushrn(l);l-- >0;)h.isOdd()&&h.iadd(T),h.iushrn(1);u.cmp(m)>=0?(u.isub(m),d.isub(h)):(m.isub(u),h.isub(d))}var v;return u.cmpn(1)===0?v=d:v=h,v.cmpn(0)<0&&v.iadd(r),v},o.prototype.gcd=function(r){if(this.isZero())return r.abs();if(r.isZero())return this.abs();var u=this.clone(),m=r.clone();u.negative=0,m.negative=0;for(var d=0;u.isEven()&&m.isEven();d++)u.iushrn(1),m.iushrn(1);do{for(;u.isEven();)u.iushrn(1);for(;m.isEven();)m.iushrn(1);var h=u.cmp(m);if(h<0){var T=u;u=m,m=T}else if(h===0||m.cmpn(1)===0)break;u.isub(m)}while(!0);return m.iushln(d)},o.prototype.invm=function(r){return this.egcd(r).a.umod(r)},o.prototype.isEven=function(){return(this.words[0]&1)===0},o.prototype.isOdd=function(){return(this.words[0]&1)===1},o.prototype.andln=function(r){return this.words[0]&r},o.prototype.bincn=function(r){t(typeof r=="number");var u=r%26,m=(r-u)/26,d=1<<u;if(this.length<=m)return this._expand(m+1),this.words[m]|=d,this;for(var h=d,T=m;h!==0&&T<this.length;T++){var C=this.words[T]|0;C+=h,h=C>>>26,C&=67108863,this.words[T]=C}return h!==0&&(this.words[T]=h,this.length++),this},o.prototype.isZero=function(){return this.length===1&&this.words[0]===0},o.prototype.cmpn=function(r){var u=r<0;if(this.negative!==0&&!u)return-1;if(this.negative===0&&u)return 1;this._strip();var m;if(this.length>1)m=1;else{u&&(r=-r),t(r<=67108863,"Number is too big");var d=this.words[0]|0;m=d===r?0:d<r?-1:1}return this.negative!==0?-m|0:m},o.prototype.cmp=function(r){if(this.negative!==0&&r.negative===0)return-1;if(this.negative===0&&r.negative!==0)return 1;var u=this.ucmp(r);return this.negative!==0?-u|0:u},o.prototype.ucmp=function(r){if(this.length>r.length)return 1;if(this.length<r.length)return-1;for(var u=0,m=this.length-1;m>=0;m--){var d=this.words[m]|0,h=r.words[m]|0;if(d!==h){d<h?u=-1:d>h&&(u=1);break}}return u},o.prototype.gtn=function(r){return this.cmpn(r)===1},o.prototype.gt=function(r){return this.cmp(r)===1},o.prototype.gten=function(r){return this.cmpn(r)>=0},o.prototype.gte=function(r){return this.cmp(r)>=0},o.prototype.ltn=function(r){return this.cmpn(r)===-1},o.prototype.lt=function(r){return this.cmp(r)===-1},o.prototype.lten=function(r){return this.cmpn(r)<=0},o.prototype.lte=function(r){return this.cmp(r)<=0},o.prototype.eqn=function(r){return this.cmpn(r)===0},o.prototype.eq=function(r){return this.cmp(r)===0},o.red=function(r){return new H(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 Ke={k256:null,p224:null,p192:null,p25519:null};function Bt(y,r){this.name=y,this.p=new o(r,16),this.n=this.p.bitLength(),this.k=new o(1).iushln(this.n).isub(this.p),this.tmp=this._tmp()}Bt.prototype._tmp=function(){var r=new o(null);return r.words=new Array(Math.ceil(this.n/13)),r},Bt.prototype.ireduce=function(r){var u=r,m;do this.split(u,this.tmp),u=this.imulK(u),u=u.iadd(this.tmp),m=u.bitLength();while(m>this.n);var d=m<this.n?-1:u.ucmp(this.p);return d===0?(u.words[0]=0,u.length=1):d>0?u.isub(this.p):u.strip!==void 0?u.strip():u._strip(),u},Bt.prototype.split=function(r,u){r.iushrn(this.n,0,u)},Bt.prototype.imulK=function(r){return r.imul(this.k)};function Ve(){Bt.call(this,"k256","ffffffff ffffffff ffffffff ffffffff ffffffff ffffffff fffffffe fffffc2f")}n(Ve,Bt),Ve.prototype.split=function(r,u){for(var m=4194303,d=Math.min(r.length,9),h=0;h<d;h++)u.words[h]=r.words[h];if(u.length=d,r.length<=9){r.words[0]=0,r.length=1;return}var T=r.words[9];for(u.words[u.length++]=T&m,h=10;h<r.length;h++){var C=r.words[h]|0;r.words[h-10]=(C&m)<<4|T>>>22,T=C}T>>>=22,r.words[h-10]=T,T===0&&r.length>10?r.length-=10:r.length-=9},Ve.prototype.imulK=function(r){r.words[r.length]=0,r.words[r.length+1]=0,r.length+=2;for(var u=0,m=0;m<r.length;m++){var d=r.words[m]|0;u+=d*977,r.words[m]=u&67108863,u=d*64+(u/67108864|0)}return r.words[r.length-1]===0&&(r.length--,r.words[r.length-1]===0&&r.length--),r};function Xn(){Bt.call(this,"p224","ffffffff ffffffff ffffffff ffffffff 00000000 00000000 00000001")}n(Xn,Bt);function zn(){Bt.call(this,"p192","ffffffff ffffffff ffffffff fffffffe ffffffff ffffffff")}n(zn,Bt);function hn(){Bt.call(this,"25519","7fffffffffffffff ffffffffffffffff ffffffffffffffff ffffffffffffffed")}n(hn,Bt),hn.prototype.imulK=function(r){for(var u=0,m=0;m<r.length;m++){var d=(r.words[m]|0)*19+u,h=d&67108863;d>>>=26,r.words[m]=h,u=d}return u!==0&&(r.words[r.length++]=u),r},o._prime=function(r){if(Ke[r])return Ke[r];var u;if(r==="k256")u=new Ve;else if(r==="p224")u=new Xn;else if(r==="p192")u=new zn;else if(r==="p25519")u=new hn;else throw new Error("Unknown prime "+r);return Ke[r]=u,u};function H(y){if(typeof y=="string"){var r=o._prime(y);this.m=r.p,this.prime=r}else t(y.gtn(1),"modulus must be greater than 1"),this.m=y,this.prime=null}H.prototype._verify1=function(r){t(r.negative===0,"red works only with positives"),t(r.red,"red works only with red numbers")},H.prototype._verify2=function(r,u){t((r.negative|u.negative)===0,"red works only with positives"),t(r.red&&r.red===u.red,"red works only with red numbers")},H.prototype.imod=function(r){return this.prime?this.prime.ireduce(r)._forceRed(this):(b(r,r.umod(this.m)._forceRed(this)),r)},H.prototype.neg=function(r){return r.isZero()?r.clone():this.m.sub(r)._forceRed(this)},H.prototype.add=function(r,u){this._verify2(r,u);var m=r.add(u);return m.cmp(this.m)>=0&&m.isub(this.m),m._forceRed(this)},H.prototype.iadd=function(r,u){this._verify2(r,u);var m=r.iadd(u);return m.cmp(this.m)>=0&&m.isub(this.m),m},H.prototype.sub=function(r,u){this._verify2(r,u);var m=r.sub(u);return m.cmpn(0)<0&&m.iadd(this.m),m._forceRed(this)},H.prototype.isub=function(r,u){this._verify2(r,u);var m=r.isub(u);return m.cmpn(0)<0&&m.iadd(this.m),m},H.prototype.shl=function(r,u){return this._verify1(r),this.imod(r.ushln(u))},H.prototype.imul=function(r,u){return this._verify2(r,u),this.imod(r.imul(u))},H.prototype.mul=function(r,u){return this._verify2(r,u),this.imod(r.mul(u))},H.prototype.isqr=function(r){return this.imul(r,r.clone())},H.prototype.sqr=function(r){return this.mul(r,r)},H.prototype.sqrt=function(r){if(r.isZero())return r.clone();var u=this.m.andln(3);if(t(u%2===1),u===3){var m=this.m.add(new o(1)).iushrn(2);return this.pow(r,m)}for(var d=this.m.subn(1),h=0;!d.isZero()&&d.andln(1)===0;)h++,d.iushrn(1);t(!d.isZero());var T=new o(1).toRed(this),C=T.redNeg(),f=this.m.subn(1).iushrn(1),l=this.m.bitLength();for(l=new o(2*l*l).toRed(this);this.pow(l,f).cmp(C)!==0;)l.redIAdd(C);for(var g=this.pow(l,d),v=this.pow(r,d.addn(1).iushrn(1)),O=this.pow(r,d),P=h;O.cmp(T)!==0;){for(var B=O,_=0;B.cmp(T)!==0;_++)B=B.redSqr();t(_<P);var F=this.pow(g,new o(1).iushln(P-_-1));v=v.redMul(F),g=F.redSqr(),O=O.redMul(g),P=_}return v},H.prototype.invm=function(r){var u=r._invmp(this.m);return u.negative!==0?(u.negative=0,this.imod(u).redNeg()):this.imod(u)},H.prototype.pow=function(r,u){if(u.isZero())return new o(1).toRed(this);if(u.cmpn(1)===0)return r.clone();var m=4,d=new Array(1<<m);d[0]=new o(1).toRed(this),d[1]=r;for(var h=2;h<d.length;h++)d[h]=this.mul(d[h-1],r);var T=d[0],C=0,f=0,l=u.bitLength()%26;for(l===0&&(l=26),h=u.length-1;h>=0;h--){for(var g=u.words[h],v=l-1;v>=0;v--){var O=g>>v&1;if(T!==d[0]&&(T=this.sqr(T)),O===0&&C===0){f=0;continue}C<<=1,C|=O,f++,!(f!==m&&(h!==0||v!==0))&&(T=this.mul(T,d[C]),f=0,C=0)}l=26}return T},H.prototype.convertTo=function(r){var u=r.umod(this.m);return u===r?u.clone():u},H.prototype.convertFrom=function(r){var u=r.clone();return u.red=null,u},o.mont=function(r){return new Pe(r)};function Pe(y){H.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,H),Pe.prototype.convertTo=function(r){return this.imod(r.ushln(this.shift))},Pe.prototype.convertFrom=function(r){var u=this.imod(r.mul(this.rinv));return u.red=null,u},Pe.prototype.imul=function(r,u){if(r.isZero()||u.isZero())return r.words[0]=0,r.length=1,r;var m=r.imul(u),d=m.maskn(this.shift).mul(this.minv).imaskn(this.shift).mul(this.m),h=m.isub(d).iushrn(this.shift),T=h;return h.cmp(this.m)>=0?T=h.isub(this.m):h.cmpn(0)<0&&(T=h.iadd(this.m)),T._forceRed(this)},Pe.prototype.mul=function(r,u){if(r.isZero()||u.isZero())return new o(0)._forceRed(this);var m=r.mul(u),d=m.maskn(this.shift).mul(this.minv).imaskn(this.shift).mul(this.m),h=m.isub(d).iushrn(this.shift),T=h;return h.cmp(this.m)>=0?T=h.isub(this.m):h.cmpn(0)<0&&(T=h.iadd(this.m)),T._forceRed(this)},Pe.prototype.invm=function(r){var u=this.imod(r._invmp(this.m).mul(this.r2));return u._forceRed(this)}})(typeof Zs>"u"||Zs,kp)});var zf={};rs(zf,{appHelpers:()=>Xf});module.exports=_d(zf);var Ac=require("@msafe/sui3-utils");var ie=require("@alphafi/alphafi-sdk"),$e=require("@msafe/sui3-utils"),Yt=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=ie.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&&ie.poolInfo[t].assetTypes.length===2}isSingleAssetDepositEvent(e,t){return e.event_type===0&&ie.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=Yt.bcs.u64().parse((0,Yt.fromBase64)(t)):t.length===24?n=Yt.bcs.u128().parse((0,Yt.fromBase64)(t)):t.length===44?n=Yt.bcs.u256().parse((0,Yt.fromBase64)(t)):n=Yt.bcs.u64().parse((0,Yt.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:$e.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}=ie.singleAssetPoolCoinMap[e],{expo:s}=ie.coinsList[i];n=Math.floor(Number(n)/10**(9-s)).toString()}return{txType:$e.TransactionType.Other,type:"depositSingleAsset",intentionData:{poolName:e,amount:n}}}decodeWithdraw(e){let t=this.extractXTokensAmount();return console.log("Decoder.decodeWithdraw",t),{txType:$e.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:$e.TransactionType.Other,type:"withdrawAlpha",intentionData:{withdrawFromLocked:Number(n)>0,xTokensAmount:t}}}decodeClaimReward(){return{txType:$e.TransactionType.Other,type:"claimReward",intentionData:{}}}};var Cc=require("@alphafi/alphafi-sdk");var wc=Ft(require("sort-keys-recursive")),I=class{constructor(e){this.data=e}serialize(){return JSON.stringify((0,wc.default)(this.data))}};var Yn=class a extends I{constructor(t){super(t);this.data=t}txType;txSubType;async build(t){let{account:n}=t;return await(0,Cc.claimRewardTxb)(n.address)}static fromData(t){return new a(t)}};var Dc=require("@alphafi/alphafi-sdk");var Jn=class a extends I{constructor(t){super(t);this.data=t}txType;txSubType;async build(t){let{account:n}=t,{poolName:o,amount:i,isAmountA:s}=this.data;return await(0,Dc.depositDoubleAssetTxb)(o,n.address,i,s)}static fromData(t){return console.log("DepositDoubleAssetIntention.fromData",t),new a(t)}};var xc=require("@alphafi/alphafi-sdk");var Zn=class a extends I{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,xc.depositSingleAssetTxb)(o,n.address,i)}static fromData(t){return console.log("DepositSingleAssetIntention.fromData",t),new a(t)}};var kc=require("@alphafi/alphafi-sdk");var to=class a extends I{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,kc.withdrawTxb)(i,o,n.address)}static fromData(t){return console.log("WithdrawIntention.fromData",t),new a(t)}};var vc=require("@alphafi/alphafi-sdk");var eo=class a extends I{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,vc.withdrawAlphaTxb)(i,o,n.address)}static fromData(t){return console.log("WithdrawAlphaIntention.fromData",t),new a(t)}};var no=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 c=new Qn(t,i).decode();return{txType:Ac.TransactionType.Other,txSubType:c.type,intentionData:c.intentionData}}async build(e){let{account:t}=e;console.log("AlphaFi build transaction type",e.txSubType);let n;switch(e.txSubType){case"depositSingleAsset":n=Zn.fromData(e.intentionData);break;case"depositDoubleAsset":n=Jn.fromData(e.intentionData);break;case"withdraw":n=to.fromData(e.intentionData);break;case"withdrawAlpha":n=eo.fromData(e.intentionData);break;case"claimReward":n=Yn.fromData(e.intentionData);break;default:throw new Error("not implemented")}return n.build({account:t})}};var Zc=require("@msafe/sui3-utils");var Lt=require("@msafe/sui3-utils"),oo=require("@mysten/sui/bcs"),ao=require("bucket-protocol-sdk");var io=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(ao.SBUCK_FOUNTAIN_PACKAGE_ID,"fountain_core","stake")}isSBUCKUnstakeTransaction(){return!!this.getMoveCallPackageModuleCommand(ao.SBUCK_FOUNTAIN_PACKAGE_ID,"fountain_core","force_unstake")}isSBUCKClaimTransaction(){return!!this.getMoveCallPackageModuleCommand(ao.SBUCK_FOUNTAIN_PACKAGE_ID,"fountain_core","claim")}isLockedClaimTransaction(){return!!this.getMoveCallModuleCommand("proof_rule","claim")||!!this.getMoveCallModuleCommand("lst_proof_rule","claim")}isLstUnlockTransaction(){return!!this.getMoveCallModuleCommand("lst_proof_rule","unlock")}decodePsm(){let e,t,n="0",o=this.getSplitCoinsCommands()[0].SplitCoins.amounts[0];return o.$kind==="Input"&&(n=this.getPureInputU64(o.Input)),this.getMoveCallCommand("charge_reservoir")?([e]=this.getMoveCallCommand("charge_reservoir").MoveCall.typeArguments,t=!1):([e]=this.getMoveCallCommand("discharge_reservoir").MoveCall.typeArguments,t=!0),console.log("Decoder.decodePsm",e,n,t),{txType:Lt.TransactionType.Other,type:"psm",intentionData:{coinType:e,amount:n,buckToCoin:t}}}decodeBorrow(){let e="",t="0",n,o=this.getStrapId(),i="0",s=this.getSplitCoinsCommands()[0].SplitCoins.amounts[0];if(s.$kind==="Input"&&(i=this.getPureInputU64(s.Input)),this.getMoveCallCommand("high_top_up")){let c=this.getMoveCallCommand("high_top_up").MoveCall;[e]=c.typeArguments;let p=c.arguments[1];p.$kind==="Input"&&(t=this.getPureInputU64(p.Input));let b=c.arguments[3];if(b.$kind==="Input"){let S=this.getPureAddresses(b.Input);S.length===1&&([n]=S)}}else if(this.getMoveCallCommand("high_borrow")){let c=this.getMoveCallCommand("high_borrow").MoveCall;[e]=c.typeArguments;let p=c.arguments[4];p.$kind==="Input"&&(t=this.getPureInputU64(p.Input));let b=c.arguments[5];if(b.$kind==="Input"){let S=this.getPureAddresses(b.Input);S.length===1&&([n]=S)}}else if(this.getMoveCallCommand("high_borrow_with_strap")){let c=this.getMoveCallCommand("high_borrow_with_strap").MoveCall;[e]=c.typeArguments;let p=c.arguments[5];p.$kind==="Input"&&(t=this.getPureInputU64(p.Input));let b=c.arguments[6];if(b.$kind==="Input"){let S=this.getPureAddresses(b.Input);S.length===1&&([n]=S)}}return{txType:Lt.TransactionType.Other,type:"borrow",intentionData:{collateralType:e,collateralAmount:i,borrowAmount:t,insertionPlace:n,strapId:o}}}decodeRepay(){let e="",t="0",n="0",i,s=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 c=this.getMoveCallCommand("repay_and_withdraw").MoveCall;[e]=c.typeArguments;let p=c.arguments[4];p.$kind==="Input"&&(n=this.getPureInputU64(p.Input));let b=c.arguments[5];if(b.$kind==="Input"){let w=this.getPureAddresses(b.Input);w.length===1&&([i]=w)}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 c=this.getMoveCallCommand("repay_and_withdraw_with_strap").MoveCall;[e]=c.typeArguments;let p=c.arguments[5];p.$kind==="Input"&&(n=this.getPureInputU64(p.Input));let b=c.arguments[6];if(b.$kind==="Input"){let w=this.getPureAddresses(b.Input);w.length===1&&([i]=w)}let S=this.getSplitCoinsCommands()[0].SplitCoins.amounts[0];S.$kind==="Input"&&(t=this.getPureInputU64(S.Input))}return{txType:Lt.TransactionType.Other,type:"repay",intentionData:{collateralType:e,repayAmount:t,withdrawAmount:n,isSurplus:!1,insertionPlace:i,strapId:s}}}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 s=i.arguments[4];s.$kind==="Input"&&(t=this.getPureInputU64(s.Input));let c=i.arguments[5];if(c.$kind==="Input"){let p=this.getPureAddresses(c.Input);p.length===1&&([n]=p)}}else if(this.getMoveCallCommand("withdraw")){let i=this.getMoveCallCommand("withdraw").MoveCall;[e]=i.typeArguments;let s=i.arguments[3];s.$kind==="Input"&&(t=this.getPureInputU64(s.Input));let c=i.arguments[4];if(c.$kind==="Input"){let p=this.getPureAddresses(c.Input);p.length===1&&([n]=p)}}return{txType:Lt.TransactionType.Other,type:"withdraw",intentionData:{collateralType:e,withdrawAmount:t,insertionPlace:n,strapId:o}}}decodeClose(){let e="",t=this.getStrapId();return this.getMoveCallCommand("destroy_empty_strap")&&([e]=this.getMoveCallCommand("destroy_empty_strap").MoveCall.typeArguments),{txType:Lt.TransactionType.Other,type:"close",intentionData:{collateralType:e,strapId:t}}}decodeSBUCKDeposit(){let t=this.getMoveCallCommand("into_balance").MoveCall.typeArguments[0],n="0",i=this.getSplitCoinsCommands()[0].SplitCoins.amounts[0];i.$kind==="Input"&&(n=this.getPureInputU64(i.Input));let s=this.isSBUCKStakeTransaction();return console.log("Decoder.decodeSBUCKDeposit",t,n,s),{txType:Lt.TransactionType.Other,type:"sbuck-deposit",intentionData:{coinType:t,amount:n,isStake:s}}}decodeSBUCKUnstake(){let e="0",t=this.isSBUCKStakeTransaction();if(t){let p=this.getSplitCoinsCommands()[0].SplitCoins.amounts[0];p.$kind==="Input"&&(e=this.getPureInputU64(p.Input))}let n=[],o=this.getMoveCallModuleCommands("proof_rule","unlock");if(o.length>0)for(let c=0;c<o.length;c++){let p=o[c];n.push("")}else{let c=this.getMoveCallModuleCommands("fountain_core","force_unstake");for(let p=0;p<c.length;p++){let S=c[p].MoveCall.arguments[2];if(S.$kind==="Input"){let{objectId:w}=this.inputs[S.Input].UnresolvedObject;n.push(w)}}}let i=this.isSBUCKWithdrawTransaction(),s={stakeProofs:n,amount:e,isStake:t,toBuck:i};return console.log("Decoder.decodeSBUCKUnstake",s),{txType:Lt.TransactionType.Other,type:"sbuck-unstake",intentionData:s}}decodeSBUCKWithdraw(){let e="0",n=this.getSplitCoinsCommands()[0].SplitCoins.amounts[0];return n.$kind==="Input"&&(e=this.getPureInputU64(n.Input)),console.log("Decoder.SBUCKWithdraw",e),{txType:Lt.TransactionType.Other,type:"sbuck-withdraw",intentionData:{amount:e}}}decodeSBUCKClaim(){let e=[],t=this.getMoveCallModuleCommands("fountain_core","claim");for(let n=0;n<t.length;n++){let i=t[n].MoveCall.arguments[2];if(i.$kind==="Input"){let{objectId:s}=this.inputs[i.Input].UnresolvedObject;e.push(s)}}return console.log("Decoder.decodeSBUCKClaim",e),{txType:Lt.TransactionType.Other,type:"sbuck-claim",intentionData:{stakeProofs:e}}}decodeTankDeposit(){let e="0",n=this.getSplitCoinsCommands()[0].SplitCoins.amounts[0];n.$kind==="Input"&&(e=this.getPureInputU64(n.Input));let i=this.getMoveCallModuleCommand("tank_operations","deposit").MoveCall.typeArguments[0];return console.log("Decoder.decodeTankDeposit",i,e),{txType:Lt.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:Lt.TransactionType.Other,type:"tank-withdraw",intentionData:{coinType:t,amount:n}}}decodeTankClaim(){let t=this.getMoveCallModuleCommand("tank_operations","claim").MoveCall.typeArguments[0];return console.log("Decoder.decodeTankClaim",t),{txType:Lt.TransactionType.Other,type:"tank-claim",intentionData:{coinType:t}}}decodeLockedClaim(){let e="",t=0,n=this.getMoveCallModuleCommands("proof_rule","claim");for(let 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:Lt.TransactionType.Other,type:"lock-claim",intentionData:{coinType:e,proofCount:t}}}getCoinInput(e){if(this.inputs[e].$kind!=="Object")throw new Error("not Object argument")}getStrapId(){let e;if(this.isStrapNewTransaction()?e="new":this.isLstUnlockTransaction()&&(e="locked"),!e){let t=this.getMoveCallModuleCommand("fountain","unstake");if(t){let n=t.MoveCall.arguments[2];n.$kind==="Input"&&(e=this.inputs[n.Input].UnresolvedObject.objectId)}}return e}getPureInputU64(e){let t=this.inputs[e];if(t.$kind!=="Pure")throw new Error("not pure argument");return oo.bcs.U64.fromBase64(t.Pure.bytes)}getPureAddresses(e){let t=this.inputs[e];if(t.$kind!=="Pure")throw new Error("not pure argument");return oo.bcs.vector(oo.bcs.Address).fromBase64(t.Pure.bytes)}};var Bc=require("@msafe/sui3-utils");var Oc=require("@mysten/sui/transactions"),Pc=require("bucket-protocol-sdk");var Mc=require("bucket-protocol-sdk"),Et=(a,e)=>{let t=a==="sui:mainnet"?"mainnet":"testnet";return new Mc.BucketClient(t,e.address)};var Rc=async(a,e,t)=>{let{coinType:n,amount:o,buckToCoin:i}=a,s=new Oc.Transaction,c=Et(t,e);return await(0,Pc.buildPsmTx)(c,s,n,o,i,e.address),s};var ro=class a extends I{constructor(t){super(t);this.data=t}txType=Bc.TransactionType.Other;txSubType="psm";async build(t){let{account:n,network:o}=t;return await Rc(this.data,n,o)}static fromData(t){return new a(t)}};var Lc=require("@msafe/sui3-utils");var gn=require("@mysten/sui/transactions"),pe=require("bucket-protocol-sdk");var Ec=async(a,e,t)=>{let{collateralType:n,collateralAmount:o,borrowAmount:i,insertionPlace:s,strapId:c}=a,p=new gn.Transaction,b=Et(t,e);return await(0,pe.buildBorrowTx)(b,p,n,o,i,e.address,s,c),p},Nc=async(a,e,t)=>{let{collateralType:n,withdrawAmount:o,insertionPlace:i,strapId:s}=a,c=new gn.Transaction,p=Et(t,e);return await(0,pe.buildWithdrawTx)(p,c,n,o,e.address,i,s),c},Wc=async(a,e,t)=>{let{collateralType:n,repayAmount:o,withdrawAmount:i,isSurplus:s,insertionPlace:c,strapId:p}=a,b=new gn.Transaction,S=Et(t,e);return await(0,pe.buildRepayTx)(S,b,n,o,i,e.address,s,c,p),b},_c=async(a,e,t)=>{let{collateralType:n,recipient:o,strapId:i}=a,s=new gn.Transaction,c=Et(t,e);return await(0,pe.buildCloseTx)(c,s,n,o,i),s};var so=class a extends I{constructor(t){super(t);this.data=t}txType=Lc.TransactionType.Other;txSubType="borrow";async build(t){let{account:n,network:o}=t;return await Ec(this.data,n,o)}static fromData(t){return new a(t)}};var jc=require("@msafe/sui3-utils");var co=class a extends I{constructor(t){super(t);this.data=t}txType=jc.TransactionType.Other;txSubType="repay";async build(t){let{account:n,network:o}=t;return await Wc(this.data,n,o)}static fromData(t){return new a(t)}};var Uc=require("@msafe/sui3-utils");var lo=class a extends I{constructor(t){super(t);this.data=t}txType=Uc.TransactionType.Other;txSubType="withdraw";async build(t){let{account:n,network:o}=t;return await Nc(this.data,n,o)}static fromData(t){return new a(t)}};var qc=require("@msafe/sui3-utils");var uo=class a extends I{constructor(t){super(t);this.data=t}txType=qc.TransactionType.Other;txSubType="close";async build(t){let{account:n,network:o}=t;return await _c(this.data,n,o)}static fromData(t){return new a(t)}};var bn=require("@msafe/sui3-utils");var yn=require("@mysten/sui/transactions"),de=require("bucket-protocol-sdk");var Fc=async(a,e,t)=>{let{coinType:n,amount:o,isStake:i}=a,s=new yn.Transaction,c=Et(t,e);return await(0,de.buildSBUCKDepositTx)(c,s,n,o,e.address,i),s},Kc=async(a,e,t)=>{let{stakeProofs:n,amount:o,isStake:i,toBuck:s}=a,c=new yn.Transaction,p=Et(t,e);return await(0,de.buildSBUCKUnstakeTx)(p,c,n,o,e.address,i,s),c},Vc=async(a,e,t)=>{let{amount:n}=a,o=new yn.Transaction,i=Et(t,e);return await(0,de.buildSBUCKWithdrawTx)(i,o,n,e.address),o},$c=async(a,e,t)=>{let{stakeProofs:n}=a,o=new yn.Transaction,i=Et(t,e);return await(0,de.buildSBUCKClaimTx)(i,o,n,e.address),o};var mo=class a extends I{constructor(t){super(t);this.data=t}txType=bn.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)}},po=class a extends I{constructor(t){super(t);this.data=t}txType=bn.TransactionType.Other;txSubType="sbuck-unstake";async build(t){let{account:n,network:o}=t;return await Kc(this.data,n,o)}static fromData(t){return new a(t)}},fo=class a extends I{constructor(t){super(t);this.data=t}txType=bn.TransactionType.Other;txSubType="sbuck-withdraw";async build(t){let{account:n,network:o}=t;return await Vc(this.data,n,o)}static fromData(t){return new a(t)}},ho=class a extends I{constructor(t){super(t);this.data=t}txType=bn.TransactionType.Other;txSubType="sbuck-claim";async build(t){let{account:n,network:o}=t;return await $c(this.data,n,o)}static fromData(t){return new a(t)}};var So=require("@msafe/sui3-utils");var go=require("@mysten/sui/transactions"),He=require("bucket-protocol-sdk");var Hc=async(a,e,t)=>{let{coinType:n,amount:o}=a,i=new go.Transaction,s=Et(t,e);return await(0,He.buildTankDepositTx)(s,i,n,o,e.address),i},Xc=async(a,e,t)=>{let{coinType:n,amount:o}=a,i=new go.Transaction,s=Et(t,e);return await(0,He.buildTankWithdrawTx)(s,i,n,o,e.address),i},zc=async(a,e,t)=>{let{coinType:n}=a,o=new go.Transaction,i=Et(t,e);return await(0,He.buildTankClaimTx)(i,o,n,e.address),o};var Gc=require("@mysten/sui/transactions"),Qc=require("bucket-protocol-sdk");var Yc=async(a,e,t)=>{let{coinType:n,proofCount:o}=a,i=new Gc.Transaction,s=Et(t,e);return await(0,Qc.buildLockedClaimTx)(s,i,n,o,e.address),i};var yo=class a extends I{constructor(t){super(t);this.data=t}txType=So.TransactionType.Other;txSubType="tank-deposit";async build(t){let{account:n,network:o}=t;return await Hc(this.data,n,o)}static fromData(t){return new a(t)}},bo=class a extends I{constructor(t){super(t);this.data=t}txType=So.TransactionType.Other;txSubType="tank-withdraw";async build(t){let{account:n,network:o}=t;return await Xc(this.data,n,o)}static fromData(t){return new a(t)}},To=class a extends I{constructor(t){super(t);this.data=t}txType=So.TransactionType.Other;txSubType="tank-claim";async build(t){let{account:n,network:o}=t;return await zc(this.data,n,o)}static fromData(t){return new a(t)}};var Jc=require("@msafe/sui3-utils");var Io=class a extends I{constructor(t){super(t);this.data=t}txType=Jc.TransactionType.Other;txSubType="lock-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 wo=class{application="bucket";supportSDK="@mysten/sui";async deserialize(e){console.log("Bucket helper deserialize input: ",e);let{transaction:t}=e,o=new io(t).decode();return{txType:Zc.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=ro.fromData(e.intentionData);break;case"borrow":i=so.fromData(e.intentionData);break;case"withdraw":i=lo.fromData(e.intentionData);break;case"repay":i=co.fromData(e.intentionData);break;case"close":i=uo.fromData(e.intentionData);break;case"tank-deposit":i=yo.fromData(e.intentionData);break;case"tank-withdraw":i=bo.fromData(e.intentionData);break;case"tank-claim":i=To.fromData(e.intentionData);break;case"sbuck-deposit":i=mo.fromData(e.intentionData);break;case"sbuck-unstake":i=po.fromData(e.intentionData);break;case"sbuck-withdraw":i=fo.fromData(e.intentionData);break;case"sbuck-claim":i=ho.fromData(e.intentionData);break;case"lock-claim":i=Io.fromData(e.intentionData);break;default:throw new Error("not implemented")}return i.build({suiClient:t,account:n,network:o})}};var ru=require("@msafe/sui3-utils");var ml=require("@msafe/sui3-utils");var Co=require("@cetusprotocol/aggregator-sdk"),tl=require("@cetusprotocol/farms-sdk"),el=require("@cetusprotocol/sui-clmm-sdk"),nl=require("@cetusprotocol/vaults-sdk"),ol=require("@cetusprotocol/xcetus-sdk"),Re=require("@mysten/sui/client"),Jt=(a,e)=>{let t=el.CetusClmmSDK.createSDK({env:"mainnet",sui_client:new Re.SuiClient({url:(0,Re.getFullnodeUrl)("mainnet")})});return t.setSenderAddress(e.address),t},Kt=(a,e)=>{let t=tl.CetusFarmsSDK.createSDK({env:"mainnet",sui_client:new Re.SuiClient({url:(0,Re.getFullnodeUrl)("mainnet")})});return t.setSenderAddress(e.address),t},jd="https://api-sui.cetus.zone/router_v2/find_routes",al=(a,e)=>{let t=new Re.SuiClient({url:"https://fullnode.mainnet.sui.io/"});return new Co.AggregatorClient({endpoint:jd,signer:e.address,client:t,env:Co.Env.Mainnet})},Tn=(a,e)=>{let t=nl.CetusVaultsSDK.createSDK({env:"mainnet"});return t.setSenderAddress(e.address),t},Xe=(a,e)=>{let t=ol.CetusXcetusSDK.createSDK({env:"mainnet"});return t.setSenderAddress(e.address),t};var il=async(a,e,t)=>await Jt(t,e).Pool.createPoolPayload(a),rl=async(a,e,t)=>await Jt(t,e).Position.createAddLiquidityFixTokenPayload(a?.parameter,a?.gasEstimateArg),sl=async(a,e,t)=>await Jt(t,e).Position.createAddLiquidityFixTokenPayload(a?.parameter,a?.gasEstimateArg),cl=async(a,e,t)=>await Jt(t,e).Position.closePositionPayload(a),ll=async(a,e,t)=>await Jt(t,e).Position.removeLiquidityPayload(a),ul=async(a,e,t)=>await Jt(t,e).Rewarder.collectRewarderPayload(a);var Do=class a extends I{constructor(t){super(t);this.data=t}txType=ml.TransactionType.Other;txSubType="OpenAndAddLiquidity";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 pl=require("@msafe/sui3-utils");var xo=class a extends I{constructor(t){super(t);this.data=t}txType=pl.TransactionType.Other;txSubType="ClaimFeeAndMining";async build(t){let{account:n,network:o}=t,{txbParams:i}=this.data;return await ul(i,n,o)}static fromData(t){return new a(t)}};var dl=require("@msafe/sui3-utils");var ko=class a extends I{constructor(t){super(t);this.data=t}txType=dl.TransactionType.Other;txSubType="CreatePool";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 fl=require("@msafe/sui3-utils");var vo=class a extends I{constructor(t){super(t);this.data=t}txType=fl.TransactionType.Other;txSubType="DecreaseLiquidity";async build(t){let{account:n,network:o}=t,{txbParams:i}=this.data;return await ll(i,n,o)}static fromData(t){return new a(t)}};var Dl=require("@msafe/sui3-utils");var hl=async(a,e,t)=>await Kt(t,e).Farms.openPositionAddLiquidityStakePayload(a),gl=async(a,e,t)=>await Kt(t,e).Farms.addLiquidityFixCoinPayload(a),yl=async(a,e,t)=>await Kt(t,e).Farms.removeLiquidityPayload(a),bl=async(a,e,t)=>await Kt(t,e).Farms.removeLiquidityPayload(a),Tl=async(a,e,t)=>await Kt(t,e).Farms.claimFeeAndClmmReward(a),Sl=async(a,e,t)=>await Kt(t,e).Farms.harvestPayload(a),Il=async(a,e,t)=>{let n=Kt(t,e),o=Object.values(a);return await n.Farms.batchHarvestPayload(o)},wl=async(a,e,t)=>await Kt(t,e).Farms.depositPayload(a),Cl=async(a,e,t)=>await Kt(t,e).Farms.withdrawPayload(a);var Ao=class a extends I{constructor(t){super(t);this.data=t}txType=Dl.TransactionType.Other;txSubType="FarmingOpenAndAddLiquidity";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 xl=require("@msafe/sui3-utils");var Mo=class a extends I{constructor(t){super(t);this.data=t}txType=xl.TransactionType.Other;txSubType="FarmingBatchHarvest";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 kl=require("@msafe/sui3-utils");var Oo=class a extends I{constructor(t){super(t);this.data=t}txType=kl.TransactionType.Other;txSubType="FarmingClaimFeeAndReward";async build(t){let{account:n,network:o}=t,{txbParams:i}=this.data;return await Tl(i,n,o)}static fromData(t){return new a(t)}};var vl=require("@msafe/sui3-utils");var Po=class a extends I{constructor(t){super(t);this.data=t}txType=vl.TransactionType.Other;txSubType="FarmingDecreaseLiquidity";async build(t){let{account:n,network:o}=t,{txbParams:i}=this.data;return await yl(i,n,o)}static fromData(t){return new a(t)}};var Al=require("@msafe/sui3-utils");var Ro=class a extends I{constructor(t){super(t);this.data=t}txType=Al.TransactionType.Other;txSubType="FarmingHarvest";async build(t){let{account:n,network:o}=t,{txbParams:i}=this.data;return await Sl(i,n,o)}static fromData(t){return new a(t)}};var Ml=require("@msafe/sui3-utils");var Bo=class a extends I{constructor(t){super(t);this.data=t}txType=Ml.TransactionType.Other;txSubType="FarmingIncreaseLiquidity";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 Ol=require("@msafe/sui3-utils");var Eo=class a extends I{constructor(t){super(t);this.data=t}txType=Ol.TransactionType.Other;txSubType="FarmingRemoveLiquidity";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 Pl=require("@msafe/sui3-utils");var No=class a extends I{constructor(t){super(t);this.data=t}txType=Pl.TransactionType.Other;txSubType="FarmingStake";async build(t){let{account:n,network:o}=t,{txbParams:i}=this.data;return await wl(i,n,o)}static fromData(t){return new a(t)}};var Rl=require("@msafe/sui3-utils");var Wo=class a extends I{constructor(t){super(t);this.data=t}txType=Rl.TransactionType.Other;txSubType="FarmingUnstake";async build(t){let{account:n,network:o}=t,{txbParams:i}=this.data;return await Cl(i,n,o)}static fromData(t){return new a(t)}};var Bl=require("@msafe/sui3-utils");var _o=class a extends I{constructor(t){super(t);this.data=t}txType=Bl.TransactionType.Other;txSubType="IncreaseLiquidity";async build(t){let{account:n,network:o}=t,{txbParams:i}=this.data;return await sl(i,n,o)}static fromData(t){return new a(t)}};var Wl=require("@msafe/sui3-utils");var Sn=require("@mysten/sui/transactions"),Lo=Ft(require("haedal-vault-sdk"));var Ud=async(a,e,t)=>{let n=Tn(t,e),o=new Sn.Transaction;return o.setSender(e.address),n.Vest.buildRedeemPayload(a.params,o),o},qd=async(a,e,t)=>{let n=new Lo.default(Lo.vaults_mainnet);n.senderAddress=e.address;let o=new Sn.Transaction;return o.setSender(e.address),await n?.Vest.buildRedeemPayload(a.params,o),o},El=(a,e,t)=>{let n=Jt(t,e),o=new Sn.Transaction;return n?.Vest.buildRedeemPayload(a.params,o),o},Fd=async(a,e,t)=>{let n=Jt(t,e),o=Kt(t,e),i=new Sn.Transaction,s=await o.Farms.withdrawReturnPayload(a.withdrawParams,i);return n.Vest.buildRedeemPayload(a.redeemParms.map(c=>({...c,clmm_position_id:s})),i),o.Farms.depositPayload({...a.depositParams,clmm_position_id:s},i),i},Nl=async(a,e,t)=>a.type==="clmm"?El(a,e,t):a.type==="farms"?Fd(a,e,t):a.type==="vaults"?Ud(a,e,t):a.type==="haedalVaults"?qd(a,e,t):El(a,e,t);var jo=class a extends I{constructor(t){super(t);this.data=t}txType=Wl.TransactionType.Other;txSubType="PosVestingRedeem";async build(t){let{account:n,network:o}=t,{txbParams:i}=this.data;return await Nl(i,n,o)}static fromData(t){return new a(t)}};var _l=require("@msafe/sui3-utils");var Uo=class a extends I{constructor(t){super(t);this.data=t}txType=_l.TransactionType.Other;txSubType="RemoveLiquidity";async build(t){let{account:n,network:o}=t,{txbParams:i}=this.data;return await cl(i,n,o)}static fromData(t){return new a(t)}};var ql=require("@msafe/sui3-utils");var Ll=require("@cetusprotocol/aggregator-sdk"),jl=require("@mysten/sui/transactions");var Ul=async(a,e,t)=>{let n=al(t,e),o=new jl.Transaction;return await n.fastRouterSwap({...a,router:(0,Ll.restituteMsafeFastRouterSwapParams)(a.router),txb:o}),o};var qo=class a extends I{constructor(t){super(t);this.data=t}txType=ql.TransactionType.Other;txSubType="AggregatorSwap";async build(t){let{account:n,network:o}=t,{txbParams:i}=this.data;return await Ul(i,n,o)}static fromData(t){return new a(t)}};var Vl=require("@msafe/sui3-utils");var ss=require("@mysten/sui/transactions");var Fl=async(a,e,t)=>{let n=Tn(t,e),o=new ss.Transaction;return o.setSender(e.address),await n.Vaults.deposit(a,o),o},Kl=async(a,e,t)=>{let n=Tn(t,e),o=new ss.Transaction;return await n.Vaults.withdraw(a,o),o};var Fo=class a extends I{constructor(t){super(t);this.data=t}txType=Vl.TransactionType.Other;txSubType="AddVaultsPosition";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 $l=require("@msafe/sui3-utils");var Ko=class a extends I{constructor(t){super(t);this.data=t}txType=$l.TransactionType.Other;txSubType="RemoveVaultsPosition";async build(t){let{account:n,network:o}=t,{txbParams:i}=this.data;return await Kl(i,n,o)}static fromData(t){return new a(t)}};var Gl=require("@msafe/sui3-utils");var Xl=require("@mysten/sui/transactions"),Hl={package_id:"0x355714a1eeb7ab1d80902da6c92001170cda1212edf524c32aa308a3ac177c31",published_at:"0x355714a1eeb7ab1d80902da6c92001170cda1212edf524c32aa308a3ac177c31",cetus_coin_type:"0x06864a6f921804860930db6ddbe2e16acdf8504495ea7481637a1c8b9a8fe54b::cetus::CETUS"},zl=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:s}=a,c=new Xl.Transaction;return i.forEach(p=>{c.moveCall({target:`${Hl.published_at}::router::redeem`,typeArguments:[Hl.cetus_coin_type],arguments:[c.object(n),c.object(o),c.pure(p),c.object(s)]})}),c};var Vo=class a extends I{constructor(t){super(t);this.data=t}txType=Gl.TransactionType.Other;txSubType="VestingRedeem";async build(t){let{account:n,network:o}=t,{txbParams:i}=this.data;return await zl(i,n,o)}static fromData(t){return new a(t)}};var eu=require("@msafe/sui3-utils");var Ql=async(a,e,t)=>await Xe(t,e).XCetusModule.convertPayload(a),Yl=async(a,e,t)=>await Xe(t,e).XCetusModule.redeemLockPayload(a),Jl=async(a,e,t)=>await Xe(t,e).XCetusModule.redeemDividendV3Payload(a.veNftId,a.rewardList),Zl=async(a,e,t)=>await Xe(t,e).XCetusModule.cancelRedeemPayload(a),tu=async(a,e,t)=>await Xe(t,e).XCetusModule.redeemPayload(a);var $o=class a extends I{constructor(t){super(t);this.data=t}txType=eu.TransactionType.Other;txSubType="xCETUSCancelRedeem";async build(t){let{account:n,network:o}=t,{txbParams:i}=this.data;return await Zl(i,n,o)}static fromData(t){return new a(t)}};var nu=require("@msafe/sui3-utils");var Ho=class a extends I{constructor(t){super(t);this.data=t}txType=nu.TransactionType.Other;txSubType="xCETUSClaimStakingRwewards";async build(t){let{account:n,network:o}=t,{txbParams:i}=this.data;return await Jl(i,n,o)}static fromData(t){return new a(t)}};var ou=require("@msafe/sui3-utils");var Xo=class a extends I{constructor(t){super(t);this.data=t}txType=ou.TransactionType.Other;txSubType="xCETUSConvert";async build(t){let{account:n,network:o}=t,{txbParams:i}=this.data;return await Ql(i,n,o)}static fromData(t){return new a(t)}};var au=require("@msafe/sui3-utils");var zo=class a extends I{constructor(t){super(t);this.data=t}txType=au.TransactionType.Other;txSubType="xCETUSRedeem";async build(t){let{account:n,network:o}=t,{txbParams:i}=this.data;return await tu(i,n,o)}static fromData(t){return new a(t)}};var iu=require("@msafe/sui3-utils");var Go=class a extends I{constructor(t){super(t);this.data=t}txType=iu.TransactionType.Other;txSubType="xCETUSRedeemLock";async build(t){let{account:n,network:o}=t,{txbParams:i}=this.data;return await Yl(i,n,o)}static fromData(t){return new a(t)}};var Qo=class{application="cetus";supportSDK="@mysten/sui";async deserialize(e){console.log("Cetus helper deserialize input: ",e);let{txbParams:t,action:n}=e;return{txType:ru.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=Do.fromData(e.intentionData);break;case"IncreaseLiquidity":i=_o.fromData(e.intentionData);break;case"DecreaseLiquidity":i=vo.fromData(e.intentionData);break;case"RemoveLiquidity":i=Uo.fromData(e.intentionData);break;case"ClaimFeeAndMining":i=xo.fromData(e.intentionData);break;case"FarmingOpenAndAddLiquidity":i=Ao.fromData(e.intentionData);break;case"FarmingIncreaseLiquidity":i=Bo.fromData(e.intentionData);break;case"FarmingDecreaseLiquidity":i=Po.fromData(e.intentionData);break;case"FarmingRemoveLiquidity":i=Eo.fromData(e.intentionData);break;case"FarmingClaimFeeAndReward":i=Oo.fromData(e.intentionData);break;case"FarmingHarvest":i=Ro.fromData(e.intentionData);break;case"FarmingBatchHarvest":i=Mo.fromData(e.intentionData);break;case"FarmingStake":i=No.fromData(e.intentionData);break;case"FarmingUnstake":i=Wo.fromData(e.intentionData);break;case"xCETUSConvert":i=Xo.fromData(e.intentionData);break;case"xCETUSRedeemLock":i=Go.fromData(e.intentionData);break;case"xCETUSClaimStakingRwewards":i=Ho.fromData(e.intentionData);break;case"xCETUSCancelRedeem":i=$o.fromData(e.intentionData);break;case"xCETUSRedeem":i=zo.fromData(e.intentionData);break;case"VestingRedeem":i=Vo.fromData(e.intentionData);break;case"AggregatorSwap":i=qo.fromData(e.intentionData);break;case"AddVaultsPosition":i=Fo.fromData(e.intentionData);break;case"RemoveVaultsPosition":i=Ko.fromData(e.intentionData);break;case"PosVestingRedeem":i=jo.fromData(e.intentionData);break;case"CreatePool":i=ko.fromData(e.intentionData);break;default:throw new Error("not implemented")}return i.build({suiClient:t,account:n,network:o})}};var Mu=require("@msafe/sui3-utils");var su=Ft(require("sort-keys-recursive")),jt=class{constructor(e){this.data=e}serialize(){return JSON.stringify((0,su.default)(this.data))}};var In=require("@mysten/sui.js/client");var cs={};rs(cs,{contractId:()=>$d,default:()=>Qd,feeObjId:()=>zd,roleObjId:()=>Hd,status:()=>Vd,transaction:()=>Kd,upgradeCapObjId:()=>Gd,vaultObjId:()=>Xd});var Kd="DiBZq4UmVVYiRL6ZJmFKYoHcxtxqrhsCXSkFyT7wUr3j",Vd="success",$d="0x81c960dc653975fbd0072deca8afb92d322898c911622898ba1b2e3ad0c4bd8d",Hd="0xc6ec0bdee0bb59a72077e9acd2f42457043cf47080b3d3fad4d39abf28bba63a",Xd="0xbc4021387fbac149119fd24e92be9e58f745774292f3a2a12e2ac6daf5363e1d",zd="0x4178f63970fe2daeb256dc5730ad172e82b3e8eb45f31b33e0daae72cd35e1e1",Gd="0xe1e9aa7d222d151bfe6dd83358b0d7fdcb11260f710800cfaf7ccc1b1e245115",Qd={transaction:Kd,status:Vd,contractId:$d,roleObjId:Hd,vaultObjId:Xd,feeObjId:zd,upgradeCapObjId:Gd};var ls={};rs(ls,{contractId:()=>Zd,default:()=>af,feeObjId:()=>nf,roleObjId:()=>tf,status:()=>Jd,transaction:()=>Yd,upgradeCapObjId:()=>of,vaultObjId:()=>ef});var Yd="855FNDV8o8Z3fWULPnQo9qdhLJpsg7wZrkCpNyfw9KfB",Jd="success",Zd="0xc357c3985e8fb875d6b37141497af660779aa1bab0ec489b2213efd74067d1fa",tf="0x5ab49bdf9fd1413e328ef242b3f8d83dde791b38a0b627bfc87fb25c010d34f1",ef="0xb483558770d8eb26007f193b75db40f0a45f2e36863a687625885d4de6993378",nf="0x48453fc4d7cde3fe35aad89e5dfb496608a6a55ea529a1c0274681a808627f94",of="0x34279779a0d0d36bd5044b04830d607fa1b0ecf316548c8ac3a44151e4f1a42a",af={transaction:Yd,status:Jd,contractId:Zd,roleObjId:tf,vaultObjId:ef,feeObjId:nf,upgradeCapObjId:of};var rf=(0,In.getFullnodeUrl)("testnet"),sf=(0,In.getFullnodeUrl)("testnet"),cf=(0,In.getFullnodeUrl)("mainnet"),lf=(0,In.getFullnodeUrl)("mainnet"),uf="https://bc3p6l5unl.execute-api.us-west-1.amazonaws.com/prod",mf="https://rolsbkota7.execute-api.us-west-1.amazonaws.com/prod",pf="https://6p6mkx33ne.execute-api.us-west-1.amazonaws.com/prod",df="https://xrae3mrjv5.execute-api.us-west-1.amazonaws.com/prod",cu=cs,lu=ls,ff=new Map([["dev",{env:"dev",rpc:{url:rf},backend:{url:uf},contract:cu}],["stg",{env:"stg",rpc:{url:sf},backend:{url:mf},contract:cu}],["prev",{env:"prev",rpc:{url:cf},backend:{url:pf},contract:lu}],["prod",{env:"prod",rpc:{url:lf},backend:{url:df},contract:lu}]]);function uu(a,e){let t=ff.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 mu=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 Yo=class extends j{constructor(){super(11,"Backend is not specified")}};var Jo=class extends j{constructor(){super(1,"Wallet not connected")}};var se=Ft(require("axios"));var ze=class extends j{constructor(e,t){super(10,e,{context:t})}};var Zo=class a{constructor(e){this.apiURL=e}static parseResponseData(e){if(e instanceof se.AxiosError)throw new ze(e.response?.statusText);if(e.status===200){if(e.data.success)return e.data.data;throw new ze(e.data.code)}throw new ze(e.status.toString())}async getIncomingStreams(e,t){let n=await se.default.post(`${this.apiURL}/stream`,{recipient:e,...t});return a.parseResponseData(n)}async getOutgoingStreams(e,t){let n=await se.default.post(`${this.apiURL}/stream`,{sender:e,...t});return a.parseResponseData(n)}async getStreamHistory(e){let t=await se.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 se.default.post(`${this.apiURL}/stream-info`,{address:e});return a.parseResponseData(t)}async getAllRecipients(e,t){let n=await se.default.post(`${this.apiURL}/stream-info`,{sender:e,status:t});return a.parseResponseData(n)}async getAllSenders(e,t){let n=await se.default.post(`${this.apiURL}/stream-info`,{recipient:e,status:t});return a.parseResponseData(n)}};var Ge=class a{signer;suiClient;envConfig;_backend;constructor(e){this.envConfig=e,this.suiClient=new mu.SuiClient({url:e.rpc.url}),e.backend&&(this._backend=new Zo(e.backend.url))}static new(e,t){let n=uu(e,t);return new a(n)}get walletType(){return this.wallet?this.wallet.type:"disconnected"}get backend(){if(!this._backend)throw new Yo;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 vn=require("@mysten/sui.js/transactions");var fs=require("@mysten/sui.js/transactions"),kn=require("@mysten/sui.js/utils");var us=50n,ta=10000n,pu=25n,ms=100000000n;var Zt=class{constructor(e){this.object=e}moveArg(e){return e.object(this.object)}},wn=class{constructor(e){this.objects=e}moveArgs(e){return e.makeMoveVec({objects:this.objects.map(t=>e.object(t))})}},ge=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=s=>new a(t.result[s]);if(n===Symbol.iterator)return function*(){let s=0;for(;;)yield o(s),s++};if(typeof n=="symbol")return;let i=parseInt(n,10);if(!(Number.isNaN(i)||i<0))return o(i)}})}moveArg(){return this.result}};var ps=require("buffer"),du=require("@mysten/sui.js/utils");var Cn=class extends j{constructor(e,t){super(3,e,{context:t})}};var ea=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 Cn("Invalid contract return type.",{ctx:{expectType:"address",gotType:o}});return(0,du.normalizeSuiAddress)(ps.Buffer.from(n).toString("hex"))}getU64(e=0,t=0){let[n,o]=this.getValue(e,t);if(o!=="u64")throw new Cn("Invalid contract return type.",{ctx:{expectType:"u64",gotType:o}});return ps.Buffer.from(n).readBigInt64LE()}};var ds=require("@mysten/sui.js/bcs");var X=class extends j{constructor(e,t,n){super(2,`Invalid input: ${e}`,{context:{fieldKey:t,fieldValue:n}})}};var hu={groupId:"string",name:"string"},hf=64;function gu(a){return yu(a),ds.bcs.ser(hu,a).toString("base64")}function Dn(a){let e=ds.bcs.de(hu,a,"base64");return yu(e),e}function yu(a){if(!fu(a.name))throw new X("Invalid metadata: Name contains unknown character");if(!fu(a.groupId))throw new X("Invalid metadata: Group ID contains unknown character");if(a.name.length>hf)throw new X("Invalid metadata: Name exceed max length 64")}function fu(a){return/^[\x00-\x7F]+$/.test(a)}var xn=require("@mysten/sui.js/utils");function na(a,e){return(0,xn.normalizeStructTag)(a)===(0,xn.normalizeStructTag)(e)}function ye(a,e){return(0,xn.normalizeStructTag)(a)===(0,xn.normalizeStructTag)(e)}var oa="txn.gas";var bu=require("nanoid");function Tu(){return(0,bu.nanoid)()}var Be=class a{constructor(e,t,n){this.globals=e;this.feeContract=t;this.streamContract=n}static convertCreateStreamInfoToInternal(e){return{metadata:gu({name:e.name,groupId:Tu()}),coinType:(0,kn.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 fs.TransactionBlock,n=this.calculateFeesInternal(e),o=this.getCreateStreamCoinRequests(e,n),i=await this.wallet.requestCoins(o),s=await this.addMergeCoins(t,i[0]),c;o.length>1?c=await this.addMergeCoins(t,i[1]):c=s;for(let p=0;p<e.recipients.length;p++){let b=e.recipients[p],S=this.amountForRecipient(b,e.numberEpoch),w=this.getStreamFeeLocal(S),[D]=t.splitCoins(s,[t.pure(S+w,"u64")]),[x]=t.splitCoins(c,[t.pure(this.flatSuiFee,"u64")]);this.streamContract.createStream(t,{paymentCoin:new ge(D),flatFeeCoin:new ge(x),metadata:e.metadata,recipient:b.address,timeStart:e.startTime,cliff:b.cliffAmount,epochInterval:e.epochInterval,numEpoch:e.numberEpoch,amountPerEpoch:b.amountPerEpoch,cancelable:e.cancelable,coinType:e.coinType})}return t}calculateCreateStreamFees(e){let t=a.convertCreateStreamInfoToInternal(e);return this.calculateFeesInternal(t)}feeParams(){return{createFeePercent:{numerator:us,denominator:ta},claimFeePercent:{numerator:pu,denominator:ta},flatFeePerStream:ms}}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===oa?n=e.gas:n=e.object(t.primaryCoin),n}getCreateStreamCoinRequests(e,t){let n=e.coinType;return na(n,kn.SUI_TYPE_ARG)?[{coinType:n,amount:t.totalAmount+t.streamFeeAmount+t.flatFeeAmount}]:[{coinType:n,amount:t.totalAmount+t.streamFeeAmount},{coinType:kn.SUI_TYPE_ARG,amount:t.flatFeeAmount}]}calculateFeesInternal(e){let t=e.recipients.reduce((o,i)=>{let s=this.amountForRecipient(i,e.numberEpoch),c=this.getStreamFeeLocal(s);return{totalAmount:o.totalAmount+s,streamFeeAmount:o.streamFeeAmount+c}},{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 ms}getStreamFeeLocal(e){return e*us/ta}async getStreamFeeRemote(e){let t=this.feeContract.streamingFee(new fs.TransactionBlock,e),n=await this.globals.suiClient.devInspectTransactionBlock({sender:await this.globals.walletAddress(),transactionBlock:t});return new ea(n).getU64()}get wallet(){return this.globals.wallet}};var hs=require("@mysten/sui.js/transactions");var Su="0x0000000000000000000000000000000000000000000000000000000000000006";var Qe=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(hs.Transactions.MoveCall({target:n,arguments:t.arguments.map(o=>o instanceof wn?o.moveArgs(e):o instanceof Zt?o.moveArg(e):o instanceof ge?o.moveArg():e.pure(o)),typeArguments:t.typeArgs})),e}addTransactionBlock(e,t,n=[],o=[]){e.add(hs.Transactions.MoveCall({target:t,arguments:n.map(i=>i instanceof wn?i.moveArgs(e):i instanceof Zt?i.moveArg(e):i instanceof ge?i.moveArg():e.pure(i)),typeArguments:o}))}makeObject(e){return typeof e=="string"?new Zt(e):e}vaultObject(){return new Zt(this.config.vaultObjId)}roleObject(){return new Zt(this.config.roleObjId)}feeObject(){return new Zt(this.config.feeObjId)}clockObject(){return new Zt(Su)}};var Ye=class a extends Qe{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 te=class a extends Qe{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(),s=this.makeObject(n.paymentCoin),c=this.makeObject(n.flatFeeCoin),p=this.clockObject();return this.addContractCall(t,{method:a.MethodName.create_stream,arguments:[o,i,s,c,n.metadata,n.recipient,n.timeStart,n.cliff,n.epochInterval,n.numEpoch,n.amountPerEpoch,n.cancelable,p],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(),s=this.feeObject(),c=this.clockObject();return this.addContractCall(t,{method:a.MethodName.claim_stream_by_proxy,arguments:[o,i,s,c],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 Je=class{constructor(e){this.globals=e;let t=e.envConfig.contract;this.feeContract=new Ye(t,e),this.streamContract=new te(t,e)}feeContract;streamContract;async createStreams(e){let t=Be.convertCreateStreamInfoToInternal(e);return this.createStreamHelper().buildCreateStreamTransactionBlock(t)}createStreamHelper(){return new Be(this.globals,this.feeContract,this.streamContract)}setAutoClaim(e,t,n){let o=new vn.TransactionBlock;return this.streamContract.setAutoClaim(o,{streamId:e,enabled:t,coinType:n})}claimStream(e,t){let n=new vn.TransactionBlock;return this.streamContract.claimStream(n,{streamId:e,coinType:t})}claimStreamByProxy(e,t){let n=new vn.TransactionBlock;return this.streamContract.claimStreamByProxy(n,{streamId:e,coinType:t})}cancelStream(e,t){let n=new vn.TransactionBlock;return this.streamContract.cancelStream(n,{streamId:e,coinType:t}),n}};var Ze=require("@mysten/sui.js/utils"),gs=require("luxon");var aa=class extends j{constructor(e,t){super(12,`Transaction failed: ${t}`,{context:{status:e,msg:t}})}};var gf=1e3,ia=class{constructor(e){this.globals=e;this.coinMetaHelper=new ys(e.suiClient),this.createStreamHelper=new Je(e).createStreamHelper()}coinMetaHelper;createStreamHelper;getStreamIdsFromCreateStreamResponse(e){if(e.effects?.status.status!=="success")throw new aa(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 X("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,s={realTotalAmount:o*e.steps+n,cliffAmount:n,amountPerStep:o};return this.validateStreamAmount(s,e.totalAmount),s}calculateTimelineByInterval(e){if(e.steps===0n)throw new X("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 X("Invalid stream steps: 0");let t=BigInt(e.total.toMillis())/e.steps,n=e.timeStart.plus(gs.Duration.fromMillis(Number(t*e.steps))),o={timeStart:e.timeStart,timeEnd:n,interval:gs.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,Ze.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,Ze.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 X("Stream amount too small","totalAmount",t);if(e.cliffAmount>e.realTotalAmount)throw new X("Invalid cliff settings")}validateTimeline(e){if(e.interval.toMillis()<gf)throw new X("Interval shall be at least 1 second","interval",e.interval)}},ys=class{constructor(e){this.suiClient=e;this.coinMetaReg=new Map}coinMetaReg;async getCoinMeta(e){let t=(0,Ze.normalizeStructTag)(e||Ze.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 Te=require("@mysten/sui.js/utils"),Ds=require("luxon");var On=require("@mysten/sui.js/transactions"),Pn=require("@mysten/sui.js/utils"),wu=require("luxon");var ra=class extends j{constructor(){super(7,"Connected wallet is not creator")}};var An=class extends j{constructor(){super(8,"Connected wallet is not recipient")}};var Mn=class extends j{constructor(e,t){super(6,e,{context:t})}};var Ot=class extends j{constructor(e,t={}){super(0,e,t)}};var sa=class extends j{constructor(e){super(5,"Stream not found",{context:{streamId:e}})}};var la=require("luxon"),Iu=(1n<<64n)-1n,ca=1e3;function bs(a){let e;typeof a=="number"?e=a:typeof a=="bigint"?e=Number(a):e=a.toMillis();let t=Math.round(e/ca);return la.DateTime.fromMillis(t*ca)}function Ts(a){let e;typeof a=="number"?e=a:typeof a=="bigint"?e=Number(a):e=a.toMillis();let t=Math.round(e/ca);return la.Duration.fromMillis(t*ca)}var be=class a{constructor(e,t,n){this.globals=e;this.streamId=t;this.rawData=n;this.streamContract=new te(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 Ot("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 ra;let e=new On.TransactionBlock;return this.streamContract.cancelStream(e,{streamId:this.streamId,coinType:this.coinType}),e}async claim(){if(await this.globals.walletAddress()!==this.recipient)throw new An;let e=new On.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 An;let t=new On.TransactionBlock;return this.streamContract.setAutoClaim(t,{streamId:this.streamId,coinType:this.coinType,enabled:e}),t}async claimByProxy(){let e=new On.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,Pn.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 Ts(this.rawData.config.epochInterval)}get groupId(){let{metadata:e}=this.rawData.config;return Dn(e).groupId}get name(){let{metadata:e}=this.rawData.config;return Dn(e).name}get recipient(){return this.rawData.config.recipient}get timeStart(){return bs(this.rawData.config.timeStart)}get duration(){let e=this.rawData.config,t=e.epochInterval*e.totalEpoch;return Ts(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:bs((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===Iu?0n:this.rawData.status.epochClaimed*this.amountPerEpoch+this.cliff}get currentEpoch(){let e=wu.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 sa(e):new Mn(`get stream data: ${t.error.code}`,{streamId:e,...t.error});let n=t.data.content;if(n.dataType!=="moveObject")throw new Mn("Unexpected object type",{gotType:n.dataType});let{typeParams:o}=(0,Pn.parseStructTag)(n.type),i=(0,Pn.normalizeStructTag)(o[0]),s=n.fields,c=s.config.fields,p=s.status.fields;return{coinType:i,autoClaim:s.auto_claim,balance:BigInt(s.balance.fields.balance),config:{amountPerEpoch:BigInt(c.amount_per_epoch),cancelable:c.cancelable,cliff:BigInt(c.cliff),creator:c.creator,epochInterval:BigInt(c.epoch_interval),metadata:c.metadata,recipient:c.recipient,timeStart:BigInt(c.time_start),totalEpoch:BigInt(c.total_epoch)},status:{status:p.status,epochCanceled:BigInt(p.epoch_canceled),epochClaimed:BigInt(p.epoch_claimed)}}}};var tn=class extends j{constructor(e,t){super(9,`Invalid stream group: ${e}`,{context:t})}};async function Is(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 Ss=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)}},en=class{constructor(e){this.requester=e;this.pager=new Ss(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 yf=25;async function Cs(a,e,t){let n=new Rn(e),o=new Bn(a,n,t);return await Is(o)}var Rn=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]}},Bn=class extends en{constructor(t,n,o){super(new ws(t,n,o));this.suiClient=t;this.idIter=n;this.options=o}},ws=class{constructor(e,t,n){this.suiClient=e;this.stringIter=t;this.options=n;this.filter=n?.filter,this.pageSize=n?.pageSize||yf,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 ua=class a{constructor(e,t){this.globals=e;this.streams=t;if(t.length===0)throw new tn("stream size 0");let n=t.map(i=>i.groupId);if(new Set(n).size!==1)throw new X("Stream does not have same group ID")}type="StreamGroup";static async new(e,t){let n=await Cs(e.suiClient,t);return n.forEach(o=>{if(!o)throw new Ot("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=>{bf(n,i)||(o=!1)}),o}async refresh(){let e=await Cs(this.globals.suiClient,this.streams.map(t=>t.streamId));this.streams.forEach((t,n)=>{t.refreshWithData(e[n])})}get groupId(){return this.streams[0].groupId}get creator(){return this.streams[0].creator}get info(){return{groupId:this.groupId,streamIds:this.streams.map(e=>e.streamId),progress:this.progress,name:this.streams[0].name,creator:this.creator,coinType:this.streams[0].coinType,totalAmount:this.streams.reduce((e,t)=>e+t.totalAmount,0n),start:this.streams[0].timeStart,end:this.streams[0].timeEnd,cancelable:this.streams[0].cancelable,cliffAmount:this.streams.reduce((e,t)=>e+t.cliff,0n),duration:this.streams[0].duration,interval:this.streams[0].interval,steps:this.streams[0].totalSteps,nextReleaseAmount:this.streams.reduce((e,t)=>t.nextReleaseAmount===null?e:e+t.nextReleaseAmount,0n),nextReleaseDate:this.streams[0].nextReleaseDate}}get progress(){return{total:this.streams.reduce((e,t)=>e+t.totalAmount,0n),streamed:this.streams.reduce((e,t)=>e+t.streamedAmount,0n),claimed:this.streams.reduce((e,t)=>e+t.claimedAmount,0n),claimable:this.streams.reduce((e,t)=>e+t.claimable,0n),canceled:this.streams.reduce((e,t)=>e+t.canceledAmount,0n)}}async historyEvents(e){return this.globals.backend.getStreamHistory({groupId:this.groupId,pagination:e})}static async parseGroupStreams(e,t,n){let o=n.map((i,s)=>be.fromObjectData(e,t[s],i)).filter(i=>!!i);if(new Set(o.map(i=>i.groupId)).size!==1)throw new tn("Not same group ID");if(!this.checkStreamGroup(o))throw new tn("Not same stream settings");return o}};function bf(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 En=class a{constructor(e,t){this.it=e;this.pageSize=t}static async newIncoming(e){let t=await ma.newIncoming(e);return new a(t,e.pageSize)}static async newOutgoing(e){let t=await ma.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}},ma=class a{constructor(e){this.requester=e}cachedNext;static async newIncoming(e){let t=await pa.newIncomingQuery(e);return new a(t)}static async newOutgoing(e){let t=await pa.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 Ot("No more results");return t}let e=this.cachedNext;if(this.cachedNext=void 0,e===null)throw new Ot("No more results");return e}},pa=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 Rn(n.flat().map(s=>s.streamId));this.objectIter=new Bn(e.suiClient,i)}current=0;objectIter;static async newIncomingQuery(e){let t=Cf(e.query),n=await e.globals.walletAddress(),i=(await e.globals.backend.getIncomingStreams(n,t)).filter(c=>(0,Te.normalizeSuiAddress)(c.recipient)===(0,Te.normalizeSuiAddress)(n)),s=Cu(i);return new a(e.globals,n,s,e.query)}static async newOutgoingQuery(e){let t=Df(e.query),n=await e.globals.walletAddress(),o=await e.globals.backend.getOutgoingStreams(n,t),i=Cu(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 If(this.globals,e[0].streamId,this.objectIter);return this.current++,Du(t,this.query)?t:this.doNextRequest()}if(e.length>1){let t=await wf(this.globals,e.map(n=>n.streamId),this.objectIter);return this.current++,Sf(t,this.query)?t:this.doNextRequest()}throw new Ot("Stream group with no stream")}};function Cu(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)=>Ds.DateTime.fromISO(n[0].createDate).toMillis()-Ds.DateTime.fromISO(t[0].createDate).toMillis())}function Du(a,e){if(e===void 0)return!0;let t=Tf(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 Tf(a,e){return e===void 0?!0:Array.isArray(e)?e.includes(a.progress.status):a.progress.status===e}function Sf(a,e){if(!e)return!0;let t=!1;return a.streams.forEach(n=>{Du(n,e)&&(t=!0)}),t}async function If(a,e,t){let n=await xu(t,e);return be.fromObjectData(a,e,n)}async function wf(a,e,t){let n=[];for(;n.length<e.length;){let o=await xu(t,e[n.length]);n.push(o)}return ua.newFromObjectResponse(a,e,n)}async function xu(a,e){if(!await a.hasNext())throw new Ot("object iterator has been consumed");let t=await a.next();if(!t||t.error||t.data===void 0||t.data===null)throw new Ot("object iterator undefined response",{cause:t?.error});if(t?.data?.objectId!==e)throw new Ot("stream id not aligned");return t}function Cf(a){return{status:xs(a?.status),coinType:ku(a?.coinType),sender:vu(a?.sender)}}function Df(a){return{status:xs(a?.status),coinType:ku(a?.coinType),recipient:vu(a?.recipient)}}function xs(a){return a===void 0||a.length===0?"all":Array.isArray(a)?a.reduce((e,t)=>{let n=xs(t);return!e||e===n?n:"all"},void 0):xf(a)}function xf(a){switch(a){case"STREAMING":case"STREAMED":case"CANCELED":return"active";case"COMPLETED":case"SETTLED":return"inactive";default:throw new X("Unknown stream filtered status")}}function ku(a){if(a)return Array.isArray(a)?a.length!==0?a.map(e=>(0,Te.normalizeStructTag)(e)):void 0:(0,Te.normalizeStructTag)(a)}function vu(a){if(a)return Array.isArray(a)?a.length!==0?a.map(e=>(0,Te.normalizeSuiAddress)(e)):void 0:(0,Te.normalizeSuiAddress)(a)}var da=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 kf=25;async function Au(a,e,t,n="0x2::sui::SUI",o=kf){let i=new ks(a,e,n,o),s=BigInt(0),c=[];for(;await i.hasNext()&&s<t;){let p=await i.next();p&&(c.push(p),s+=BigInt(p.balance))}if(s<t)throw new da(n,t,s);return c}var ks=class extends en{constructor(t,n,o,i){super(new vs(t,n,o,i));this.suiClient=t;this.owner=n;this.coinType=o;this.reqPageSize=i}},vs=class{constructor(e,t,n,o){this.suiClient=e;this.owner=t;this.coinType=n;this.reqPageSize=o;if(o<=0)throw new Ot("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 As=class{constructor(e){this.msafe=e}get type(){return"msafe"}async address(){return this.msafe.address()}async requestCoins(e){return this.msafe.requestCoins(e)}},fa=class{constructor(e){this.account=e}async address(){return this.account.address}},Ms=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(na(e.coinType,Ee.SUI_TYPE_ARG))return{primaryCoin:oa};if(e.amount<=0)throw new X("Invalid coin request","coinAmount",e.amount);let t=await Au(this.suiClient,await this.address(),e.amount,e.coinType);if(t.length===0)throw new Ot("no coins available");return{primaryCoin:t[0].coinObjectId,mergedCoins:t.slice(1).map(n=>n.coinObjectId)}}},ha=class{globals;helper;constructor(e,t){this.globals=Ge.new(e,t),this.helper=new ia(this.globals)}connectSingleWallet(e){let t=new Ms(e,this.globals.suiClient);this.globals.connectWallet(t)}connectMSafeAccount(e){let t=new As(e);this.globals.connectWallet(t)}async createStream(e){return this.builder().createStreams(e)}async getStream(e){return be.new(this.globals,e)}async getIncomingStreams(e,t=10){return En.newIncoming({globals:this.globals,query:e,pageSize:t})}async getOutgoingStreams(e,t=10){return En.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 Je(this.globals)}};var $t=class extends jt{application="mpay";getClient(e,t){let n=new ha(e==="sui:mainnet"?"prod":"dev");return n.connectSingleWallet(new fa(t)),n}};var Nn=class extends $t{constructor(t){super(t);this.data=t}txType=Mu.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 Ou=require("@msafe/sui3-utils");var Wn=class extends $t{constructor(t){super(t);this.data=t}txType=Ou.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 Pu=require("@msafe/sui3-utils");var _n=class extends $t{constructor(t){super(t);this.data=t}txType=Pu.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 Ru=require("@msafe/sui3-utils");var Ln=class extends $t{constructor(t){super(t);this.data=t}txType=Ru.TransactionType.Stream;txSubType="CreateStream";async build(t){let{network:n,account:o}=t;return this.getClient(n,o).createStream(this.data)}};var Os=require("@mysten/sui.js/bcs"),Se=require("@mysten/sui.js/utils"),nn=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,Se.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 Os.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,Se.normalizeSuiAddress)(e.value.Object.ImmOrOwned.objectId)}return(0,Se.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,Se.normalizeSuiAddress)(e.value);if(!("Object"in e.value)||!("Shared"in e.value.Object))throw new Error("not Shared");return(0,Se.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 Os.bcs.de(t,new Uint8Array(n))}typeArg(e){return(0,Se.normalizeStructTag)(this.moveCall.typeArguments[e])}txArg(e){return this.moveCall.arguments[e]}};var ga=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"&&ye(t.target,this.contract.createStreamTarget));if(e.length===0)throw new Ot("No create stream transactions");return e.map(t=>new nn(t,this.txb))}getCreationInfoFromMoveCall(e){let t=e.decodeInputString(4),{name:n,groupId:o}=Dn(t),i=e.decodeInputAddress(5),s=e.decodeInputU64(6),c=e.decodeInputU64(7),p=e.decodeInputU64(8),b=e.decodeInputU64(9),S=e.decodeInputU64(10),w=e.decodeInputBool(11),D=e.typeArg(0);return{name:n,groupId:o,recipient:i,timeStart:s,cliff:c,epochInterval:p,totalEpoch:b,amountPerEpoch:S,cancelable:w,coinType:D}}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 X("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 te(this.globals.envConfig.contract,this.globals)}get feeContract(){return new Ye(this.globals.envConfig.contract,this.globals)}createStreamHelper(){return new Be(this.globals,this.feeContract,this.contract)}getInputArg(e){if(e.kind!=="Input")throw new Error("not input type");return"value"in e?e:this.txb.blockData.inputs[e.index]}};var ya=class{constructor(e,t){this.globals=e;this.txb=t;this.contract=new te(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"&&ye(t.target,this.contract.createStreamTarget))!==-1}isSetAutoClaimTransaction(){return this.transactions.length===1&&this.transactions[0].kind==="MoveCall"&&ye(this.transactions[0].target,this.contract.setAutoClaimTarget)}isCancelStreamTransaction(){return this.transactions.length===1&&this.transactions[0].kind==="MoveCall"&&ye(this.transactions[0].target,this.contract.cancelStreamTarget)}isClaimStreamTransaction(){return this.transactions.length===1&&this.transactions[0].kind==="MoveCall"&&ye(this.transactions[0].target,this.contract.claimStreamTarget)}isClaimByProxyTransaction(){return this.transactions.length===1&&this.transactions[0].kind==="MoveCall"&&ye(this.transactions[0].target,this.contract.claimStreamByProxyTarget)}decodeCreateStreamTransaction(){return new ga(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 nn(e,this.txb)}};var Bu=require("@msafe/sui3-utils");var jn=class extends $t{constructor(t){super(t);this.data=t}txType=Bu.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 ba=class{application="mpay";supportSDK="@mysten/sui.js";async deserialize(e){let{network:t,transactionBlock:n}=e,o=Ge.new(t==="sui:mainnet"?"prod":"dev"),s=new ya(o,n).decode(),c;switch(s.type){case"CreateStream":c=new Ln(s.info);break;case"SetAutoClaim":c=new jn({streamId:s.streamId,enabled:s.enabled});break;case"Claim":c=new _n({streamId:s.streamId});break;case"ClaimByProxy":c=new Wn({streamId:s.streamId});break;case"Cancel":c=new Nn({streamId:s.streamId});break;default:throw new Error(`Unknown transaction type: ${s}`)}return{txType:c.txType,txSubType:c.txSubType,intentionData:c.data}}async build(e){let{intentionData:t}=e,n;switch(e.txSubType){case"CreateStream":n=new Ln(t);break;case"Claim":n=new _n(t);break;case"ClaimByProxy":n=new Wn(t);break;case"SetAutoClaim":n=new jn(t);break;case"Cancel":n=new Nn(t);break;default:throw new Error("not implemented")}return n.build({...e})}};var Un=require("@msafe/sui3-utils");var Eu=require("@msafe/sui3-utils");var Ta=class a extends jt{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 jt{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 Ia=class{application="msafe-core";supportSDK="@mysten/sui.js";constructor(){this.application=Un.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 Un.TransactionSubTypes.assets.coin.send:o=Ta.fromData(e.intentionData);break;case Un.TransactionSubTypes.assets.object.send:o=Sa.fromData(e.intentionData);break;default:throw new Error("not implemented")}return o.build({suiClient:t,account:n})}};var Xu=require("@msafe/sui3-utils");var Wu=!1,qn={ProtocolPackage:"0xee0041239b89564ce870a7dec5ddc5d114367ab94a1137e90aa0633cb76518e0",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 Ps(){if(!Wu)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&&(qn.ProtocolPackage=e),t&&(qn.borrowFee=t),n&&(qn.borrowFeeAddress=n),o&&(qn.pool=o),Wu=!0}catch(a){console.error(a.message)}}var zt=qn;var Ie=require("@msafe/sui3-utils"),we=require("@mysten/sui/utils"),Rs=require("@mysten/sui.js/bcs");var wa=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(`${zt.ProtocolPackage}::incentive_v3::entry_borrow_v2`)}isEntryBorrowWithFeeTransaction(){return!!this.getMoveCallTransaction(`${zt.ProtocolPackage}::incentive_v3::borrow_v2`)}isEntryMultiDepositTransaction(){let e=`${zt.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=`${zt.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(`${zt.ProtocolPackage}::incentive_v3::entry_deposit`)}isEntryRepayTransaction(){return!!this.getMoveCallTransaction(`${zt.ProtocolPackage}::incentive_v3::entry_repay`)}isEntryWithdrawTransaction(){return!!this.getMoveCallTransaction(`${zt.ProtocolPackage}::incentive_v3::withdraw_v2`)}findPoolByAssetId(e){let t=Object.values(zt.pool).find(n=>n.assetId===e);if(!t)throw new Error("Pool not found");return t}decodeEntryClaimAndDeposit(){return{txType:Ie.TransactionType.Other,type:"EntryClaimAndDeposit",intentionData:{type:"entry_claim_and_deposit"}}}decodeClaimReward(){return console.log("decode claims"),{txType:Ie.TransactionType.Other,type:"ClaimReward",intentionData:{type:"claim_reward"}}}decodeEntryBorrow(){let e=this.helper.decodeInputU8(4),t=this.helper.decodeInputU64(5);return{txType:Ie.TransactionType.Other,type:"EntryBorrow",intentionData:{amount:t,assetId:e}}}decodeEntryMultiDeposit(){let e=[],t=`${zt.ProtocolPackage}::incentive_v3::entry_deposit`;return this.transactions.forEach(n=>{if(n.kind==="MoveCall"&&n.target===t){let o=new Ca(n,this.txb),i=o.decodeInputU8(3),s=o.decodeInputU64(5);e.push({assetId:i,amount:s})}}),{txType:Ie.TransactionType.Other,type:"EntryMultiDeposit",intentionData:{list:e}}}decodeEntryDeposit(){let e=this.helper.decodeInputU8(3),t=this.helper.decodeInputU64(5);return{txType:Ie.TransactionType.Other,type:"EntryDeposit",intentionData:{amount:t,assetId:e}}}decodeEntryRepay(){let e=this.helper.decodeInputU8(4),t=this.helper.decodeInputU64(6);return{txType:Ie.TransactionType.Other,type:"EntryRepay",intentionData:{amount:t,assetId:e}}}decodeEntryWithdraw(){let e=this.helper.decodeInputU8(4),t=this.helper.decodeInputU64(5);return{txType:Ie.TransactionType.Other,type:"EntryWithdraw",intentionData:{amount:t,assetId:e}}}get helper(){let e=this.transactions.find(t=>t.kind==="MoveCall"&&t.target.startsWith(zt.ProtocolPackage));return new Ca(e,this.txb)}},Ca=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,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.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 Rs.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,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,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 Rs.bcs.de(t,new Uint8Array(n))}typeArg(e){return(0,we.normalizeStructTag)(this.moveCall.typeArguments[e])}txArg(e){return this.moveCall.arguments[e]}};var Bs=require("@mysten/sui/transactions"),Ut=require("@naviprotocol/lending");async function on(a,e,t,n){return await(0,Ut.depositCoinPTB)(a,e,t,{amount:n}),a}async function _u(a,e,t,n){let[o]=await(0,Ut.withdrawCoinPTB)(a,e,t);return a.transferObjects([o],a.pure.address(n)),a}async function Lu(a,e,t,n){let[o]=await(0,Ut.borrowCoinPTB)(a,e,t);return a.transferObjects([o],a.pure.address(n)),a}async function Es(a,e,t,n){return await(0,Ut.repayCoinPTB)(a,e,t,{amount:n}),a}async function ju(a,e){let t=new Bs.Transaction,n=await(0,Ut.getUserAvailableLendingRewards)(e,{client:a});return await(0,Ut.claimLendingRewardsPTB)(t,n),t}async function Uu(a,e){let t=new Bs.Transaction,n=await(0,Ut.getUserAvailableLendingRewards)(e,{client:a});return await(0,Ut.claimLendingRewardsPTB)(t,n,{customCoinReceive:{type:"depositNAVI",depositNAVI:{fallbackReceiveAddress:e}}}),t}var Da=class a extends I{constructor(t){super(t);this.data=t}txType;txSubType;async build(t){let{type:n}=this.data;return console.log("claim reward",n),await ju(t.suiClient,t.account.address)}static fromData(t){return new a(t)}};var xa=class a extends I{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 Uu(t.suiClient,t.account.address)}static fromData(t){return new a(t)}};var Fu=require("@mysten/sui/transactions");var qu=require("@naviprotocol/lending");async function ee(a){return(0,qu.getPool)(a)}var ka=class a extends I{constructor(t){super(t);this.data=t}txType;txSubType;async build(t){let{assetId:n,amount:o}=this.data,i=new Fu.Transaction;console.log("build",this.data);let s=await ee(n);return await Lu(i,s,o,t.account.address)}static fromData(t){return new a(t)}};var Ku=require("@mysten/sui/transactions");async function an(a,e,t){let n=await a.getCoins({owner:e,coinType:t});return console.log("getTokenObjs",e,n),n}var va=class a extends I{constructor(t){super(t);this.data=t}txType;txSubType;async build(t){let{suiClient:n,account:o}=t,{assetId:i,amount:s}=this.data,c=new Ku.Transaction;console.log("build",this.data);let p=await ee(i);if(i===0){let[D]=c.splitCoins(c.gas,[s]);return await on(c,p,D,s)}let b=await an(n,o.address,p.suiCoinType);if(!b.data[0])throw new Error(`Insufficient balance for ${p.suiCoinType} Token`);let S=b.data[0].coinObjectId;if(b.data.length>=2){let D=1;for(;D<b.data.length;)c.mergeCoins(S,[b.data[D].coinObjectId]),D++}return await on(c,p,c.object(S),s)}static fromData(t){return new a(t)}};var Vu=require("@mysten/sui/transactions");var Aa=class a extends I{constructor(t){super(t);this.data=t}txType;txSubType;async build(t){let{suiClient:n,account:o}=t,{assetId:i,amount:s}=this.data,c=new Vu.Transaction;console.log("build",this.data);let p=await ee(i);if(i===0){let[w]=c.splitCoins(c.gas,[s]);return Es(c,p,w,s)}let b=await an(n,o.address,p.suiCoinType);if(!b.data[0])throw new Error(`Insufficient balance for ${p.suiCoinType} Token`);let S=b.data[0].coinObjectId;if(b.data.length>=2){let w=1;for(;w<b.data.length;)c.mergeCoins(S,[b.data[w].coinObjectId]),w++}return Es(c,p,c.object(S),s)}static fromData(t){return new a(t)}};var $u=require("@mysten/sui/transactions");var Ma=class a extends I{constructor(t){super(t);this.data=t}txType;txSubType;async build(t){let{assetId:n,amount:o}=this.data,i=new $u.Transaction;console.log("build",this.data);let s=await ee(n);return await _u(i,s,o,t.account.address)}static fromData(t){return new a(t)}};var Hu=require("@mysten/sui/transactions");var Oa=class a extends I{constructor(t){super(t);this.data=t}txType;txSubType;async build(t){let{suiClient:n,account:o}=t,{list:i}=this.data,s=new Hu.Transaction;console.log("build",this.data);for(let c=0;c<i.length;c++){let{assetId:p,amount:b}=i[c],S=await ee(p);if(p===0){let[x]=s.splitCoins(s.gas,[b]);await on(s,S,x,b);continue}let w=await an(n,o.address,S.suiCoinType);if(!w.data[0])throw new Error(`Insufficient balance for ${S.suiCoinType} Token`);let D=w.data[0].coinObjectId;if(w.data.length>=2){let x=1;for(;x<w.data.length;)s.mergeCoins(D,[w.data[x].coinObjectId]),x++}await on(s,S,s.object(D),b)}return s}static fromData(t){return new a(t)}};var Pa=class{application="navi";supportSDK="@mysten/sui";async deserialize(e){await Ps();let{transaction:t}=e,o=new wa(t).decode();return{txType:Xu.TransactionType.Other,txSubType:o.type,intentionData:o.intentionData}}async build(e){let{suiClient:t,account:n}=e,o;switch(await Ps(),e.txSubType){case"EntryDeposit":o=va.fromData(e.intentionData);break;case"EntryBorrow":o=ka.fromData(e.intentionData);break;case"EntryRepay":o=Aa.fromData(e.intentionData);break;case"EntryWithdraw":o=Ma.fromData(e.intentionData);break;case"EntryMultiDeposit":o=Oa.fromData(e.intentionData);break;case"ClaimReward":o=Da.fromData(e.intentionData);break;case"EntryClaimAndDeposit":o=xa.fromData(e.intentionData);break;default:throw new Error("not implemented")}return o.build({suiClient:t,account:n})}};var Fn=require("@msafe/sui3-utils"),zu=require("@mysten/bcs"),Gu=require("@mysten/sui/transactions"),Qu=Ft(require("sort-keys-recursive")),Yu="msafe-plain-tx",Ju=Fn.TransactionSubTypes.others.plain,Ns=class a{constructor(e){this.data=e}application=Yu;txType=Fn.TransactionType.Other;txSubType=Ju;serialize(){return JSON.stringify((0,Qu.default)(this.data))}async build(e){return Gu.Transaction.from((0,zu.fromHex)(this.data.content))}static fromData(e){return new a(e)}},Ra=class{application;supportSDK="@mysten/sui";constructor(){this.application=Yu}async deserialize(e){let{content:t}=e.appContext;return{txType:Fn.TransactionType.Other,txSubType:Ju,intentionData:{content:t}}}async build(e){let{suiClient:t,network:n,account:o}=e;return Ns.fromData(e.intentionData).build({suiClient:t,network:n,account:o})}};var Ls=require("@mysten/sui/client"),Zu=require("@mysten/sui/transactions"),Na=require("@mysten/sui.js/client"),tm=require("@mysten/sui.js/transactions");var rn=require("@open-rpc/client-js");var Mf={"-32700":"ParseError","-32600":"InvalidRequest","-32601":"MethodNotFound","-32602":"InvalidParams","-32603":"InternalError"},Ws=class extends Error{},Ba=class extends Ws{code;type;constructor(e,t){super(e),this.code=t,this.type=Mf[t]??"ServerError"}};function Of(a){let e=new URL(a);return e.protocol=e.protocol.replace("http","ws"),e.toString()}var Pf={WebSocketConstructor:typeof WebSocket<"u"?WebSocket:void 0,callTimeout:3e4,reconnectTimeout:3e3,maxReconnects:5},Ea=class{endpoint;options;#n=0;#a=0;#t=null;#e=null;#i=new Set;#o=new Map;constructor(e,t={}){this.endpoint=e,this.options={...Pf,...t},this.endpoint&&this.endpoint.startsWith("http")&&(this.endpoint=Of(this.endpoint))}async makeRequest(e,t){let n=await this.#r();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 Ba(o.message,o.code);return i})}#r(){return this.#e?this.#e:(this.#e=new Promise(e=>{this.#t?.close(),this.#t=new this.options.WebSocketConstructor(this.endpoint),this.#t.addEventListener("open",()=>{this.#a=0,e(this.#t)}),this.#t.addEventListener("close",()=>{this.#a++,this.#a<=this.options.maxReconnects&&setTimeout(()=>{this.#s()},this.options.reconnectTimeout)}),this.#t.addEventListener("message",({data:t})=>{let n;try{n=JSON.parse(t)}catch(o){console.error(new Error(`Failed to parse RPC message: ${t}`,{cause:o}));return}if("id"in n&&n.id!=null&&this.#o.has(n.id)){let{resolve:o,timeout:i}=this.#o.get(n.id);clearTimeout(i),o(n)}else if("params"in n){let{params:o}=n;this.#i.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.#i].map(e=>e.subscribe(this)))}async subscribe(e){let t=new _s(e);return this.#i.add(t),await t.subscribe(this),()=>t.unsubscribe(this)}},_s=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 Ce=class{rpcClient;websocketClient;constructor({url:e,websocket:{url:t,...n}={},rpc:o}){let i=new rn.HTTPTransport(o?.url??e,{headers:{"Content-Type":"application/json",...o?.headers}});this.rpcClient=new rn.Client(new rn.RequestManager([i])),this.websocketClient=new Ea(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 Wa=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 Us(e))}addHelper(e){this.apps.set(e.application,new js(e))}getAppHelper(e){let t=this.apps.get(e);if(!t)throw new Error(`${e} not registered`);return t}},js=class{constructor(e){this.helper=e}async deserialize(e){let t=new Ls.SuiClient({transport:new Ce({url:e.clientUrl,rpc:{url:e.clientUrl}})}),n=new Na.SuiClient({transport:new Ce({url:e.clientUrl,rpc:{url:e.clientUrl}})}),o=await e.transactionBlock.build({client:n}),i=Zu.Transaction.from(o);return this.helper.deserialize({...e,suiClient:t,transaction:i})}async build(e){let t=new Ls.SuiClient({transport:new Ce({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 tm.TransactionBlock.from(i)}},Us=class{constructor(e){this.helper=e}async deserialize(e){let t=new Na.SuiClient({transport:new Ce({url:e.clientUrl,rpc:{url:e.clientUrl}})});return this.helper.deserialize({...e,transactionBlock:e.transactionBlock,suiClient:t})}async build(e){let t=new Na.SuiClient({transport:new Ce({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 um=require("@msafe/sui3-utils"),mm=require("@mysten/sui/client"),pm=require("@scallop-io/sui-scallop-sdk");var Pt=require("@msafe/sui3-utils"),Ks=require("@scallop-io/sui-scallop-sdk");var em=require("@mysten/sui/utils"),De=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:i}=(0,em.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,s,c)=>(i[s]=c,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 _a=require("@mysten/sui/bcs"),xe=require("@mysten/sui/utils"),qs=class a{constructor(e,t,n=0){this.moveCall=e;this.transaction=t;let o=[];e?.MoveCall&&t.getData().commands.filter((i,s)=>{if(i.$kind==="MoveCall"){let c=`${i.MoveCall.package}::${i.MoveCall.module}::${i.MoveCall.function}`,p=`${e.MoveCall.package}::${e.MoveCall.module}::${e.MoveCall.function}`;return c===p?(o.push(s),!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,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.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=_a.bcs[t];return _a.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,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){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 _a.bcs.U64.parse(new Uint8Array(t))}typeArg(e){return(0,xe.normalizeStructTag)(this.txBlockTransactions.typeArguments[e])}txArg(e){return this.transaction.blockData.inputs[e]}},N=qs;var Fs=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)}},Wt=Fs;var ke=require("@mysten/sui/utils"),nm=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 i=a.address.get("borrowIncentive.object");return o===`${i.slice(2)}::incentive_account::IncentiveProgramLockKey`},sn={id:"0xc63072e7f5f4983a2efaf5bdba1480d5e7d74d57948e1c7cc436f8e22cbeb410",incentivePools:"0x64972b713ccec45ec3964809e477cea6f97350c0c50ca3aec85bb631639266ec",incentiveAccounts:"0x3c0b707068bdcea8bb859d751ad3e2149a9f83c13fcf4054ef91372a00bccdd3"},Ht={unstakeObligation:(a,e,t)=>a.moveCall(`${sn.id}::user::unstake`,[sn.incentivePools,sn.incentiveAccounts,a.object(e),a.object(t),ke.SUI_CLOCK_OBJECT_ID],[(0,ke.normalizeStructTag)(ke.SUI_TYPE_ARG)]),redeem_rewards:(a,e,t,n)=>a.moveCall(`${sn.id}::user::redeem_rewards`,[sn.incentivePools,sn.incentiveAccounts,a.object(e),a.object(t),ke.SUI_CLOCK_OBJECT_ID],[(0,ke.normalizeStructTag)(n)])};var om=(a,e)=>{let t=[];for(let n=0;n<a.length;n+=e)t.push(a.slice(n,n+e));return t};var La=class extends De{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(`${Ks.OLD_BORROW_INCENTIVE_PROTOCOL_ID}::user::redeem_rewards`),t=this.hasMoveCallCommand(`${this.coreId.borrowIncentivePkg}::user::stake_with_ve_sca_v2`),n=this.hasMoveCallCommand(`${this.coreId.borrowIncentivePkg}::user::stake`);return e&&(t||n)}get helperClaimLendingReward(){return this.commands.filter(t=>this.filterMoveCallCommands(t,`${this.coreId.spoolPkg}::user::redeem_rewards`)).map(t=>new N(t,this.transaction))}get helperClaimBorrowV2Reward(){return this.commands.filter(t=>this.filterMoveCallCommands(t,`${this.coreId.borrowIncentivePkg}::user::redeem_rewards`)).map(t=>new N(t,this.transaction))}get helperStakeObligationWithVeSca(){let e=this.commands.find(t=>this.filterMoveCallCommands(t,`${this.coreId.borrowIncentivePkg}::user::stake_with_ve_sca_v2`));return new N(e,this.transaction)}get helperClaimBorrowReward(){return this.commands.filter(t=>this.filterMoveCallCommands(t,`${Ks.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:Pt.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:Pt.TransactionType.Other,type:"MigrateAndClaim",intentionData:{obligationKey:t,obligationId:n,rewardCoinName:o,veScaKey:e}}}decodeOpenObligation(){return{txType:Pt.TransactionType.Other,type:"OpenObligation",intentionData:{}}}decodeSupplyLending(){let e=this.utils.parseCoinNameFromType(this.helperMint.typeArg(0)),t=this.helperMint.getNestedInputParam(2),n=new Wt(t,this.transaction).getAmountInput().reduce((o,i)=>o+i,0);return{txType:Pt.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 Wt(t,this.transaction).getAmountInput().reduce((o,i)=>o+i,0);return{txType:Pt.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 Wt(t,this.transaction).getAmountInput().reduce((o,i)=>o+i,0);return{txType:Pt.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 Wt(t,this.transaction).getAmountInput().reduce((i,s)=>i+s,0),o=this.helperDepositCollateral.decodeSharedObjectId(1);return{txType:Pt.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:Pt.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:Pt.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:Pt.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:Pt.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 Wt(t,this.transaction).getAmountInput().reduce((i,s)=>i+s,0),o=this.helperRepay.decodeSharedObjectId(1);return{txType:Pt.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 Wt(n,this.transaction).getAmountInput().reduce((s,c)=>s+c,0),i=this.helperRepay.decodeSharedObjectId(1);return{txType:Pt.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 Wt(i,this.transaction).getAmountInput().reduce((s,c)=>s+c,0)}if(this.helperStake.moveCall&&t===0){let i=this.helperStake.getNestedInputParam(2);t=new Wt(i,this.transaction).getAmountInput().reduce((s,c)=>s+c,0)}let n=this.helperStake.typeArg(0),o=this.utils.parseCoinNameFromType(n);return{txType:Pt.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:Pt.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 Wt(t,this.transaction).getAmountInput().reduce((i,s)=>i+s,0),o;return this.isCreateStakeAccountTransaction()||(o=this.helperStake.decodeOwnedObjectId(1)),{txType:Pt.TransactionType.Other,type:"SupplyAndStakeLending",intentionData:{amount:n,coinName:e,stakeAccountId:o}}}decodeUnstakeAndWithdraw(){let e=[];this.helperUnstakes.forEach(o=>{let i=o.decodeOwnedObjectId(1),s=o.decodeInputU64(2);e.push({id:i,coin:s})});let t=this.utils.parseCoinNameFromType(this.helperRedeems[0].typeArg(0)),n=0;if(this.helperBurnScoin.moveCall){let o=this.helperBurnScoin.getNestedInputParam(1);n=new Wt(o,this.transaction).getAmountInput().reduce((i,s)=>i+s,0)}return{txType:Pt.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),s=o.typeArg(0),c=this.utils.parseCoinNameFromType(s);e.push({stakeMarketCoinName:c,stakeAccountId:i})}),this.helperClaimBorrowV2Reward.forEach(o=>{let i=o.decodeSharedObjectId(4),s=o.decodeOwnedObjectId(3),c=this.utils.parseCoinNameFromType(o.typeArg(0));t.push({obligationId:s,obligationKey:i,rewardCoinName:c})}),this.helperClaimBorrowReward.forEach(o=>{let i=o.decodeSharedObjectId(2),s=o.decodeOwnedObjectId(3),c=this.utils.parseCoinNameFromType(o.typeArg(0));n.push({obligationId:s,obligationKey:i,rewardCoinName:c})}),{txType:Pt.TransactionType.Other,type:"ClaimIncentiveReward",intentionData:{lendingIncentive:e,borrowIncentiveV2:t,borrowIncentive:n}}}};var ja=require("@msafe/sui3-utils");var Ua=class extends De{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:ja.TransactionType.Other,type:"CreateReferralLink",intentionData:{}}}decodeClaimRevenueReferral(){let e=this.helperClaimRevenueReferral[0].decodeOwnedObjectId(2),t=this.helperClaimRevenueReferral.map(n=>n.typeArg(0));return{txType:ja.TransactionType.Other,type:"ClaimRevenueReferral",intentionData:{veScaKey:e,coins:t}}}decodeBindReferral(){let e=this.helperBindReferral.decodePureArg(1,"Address");return{txType:ja.TransactionType.Other,type:"BindReferral",intentionData:{veScaKey:e}}}};var ne=require("@msafe/sui3-utils"),am=require("@scallop-io/sui-scallop-sdk");var qa=class extends De{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(c=>this.filterMoveCallCommands(c,`${this.coreId.borrowIncentivePkg}::user::unstake_v2`)),t=this.commands.filter(c=>this.filterMoveCallCommands(c,`${this.coreId.borrowIncentivePkg}::user::stake_with_ve_sca_v2`)),n=this.commands.filter(c=>this.filterMoveCallCommands(c,`${this.coreId.borrowIncentivePkg}::user::deactivate_boost_v2`)),o=e.length>0&&t.length>0&&e.length===t.length,i=n.length>0;return this.commands.length===e.length+t.length+n.length&&(o||i)}async isTransferVeScaKey(){let e=this.commands.filter(p=>p.$kind==="TransferObjects");if(e.length!==1)return!1;let{objects:t}=e[0].TransferObjects,n=t.filter(p=>p.$kind==="Input").map(({Input:p})=>p);if(n.length!==t.length)return!1;let o=new Set(n),i=this.inputs.filter((p,b)=>p.$kind==="Object"&&o.has(b)).map(p=>p.Object.ImmOrOwnedObject),s=`${this.coreId.veScaObjId}::ve_sca::VeScaKey`,c=om(i.map(({objectId:p})=>p),50);for(let p=0;p<c.length;p++){let b=c[p];if((await this.scallopClient.scallopSuiKit.queryGetObjects(b,{showType:!0})).some(w=>w.type!==s))return!1}return i.length>0}get helperStakeMoreSca(){let e=this.commands.find(t=>this.filterMoveCallCommands(t,`${this.coreId.veScaPkgId}::ve_sca::lock_more_sca`));return new N(e,this.transaction)}get helperStakeSca(){let e=this.commands.find(t=>this.filterMoveCallCommands(t,`${this.coreId.veScaPkgId}::ve_sca::mint_ve_sca_key`));return new N(e,this.transaction)}get helperExtendStakePeriod(){let e=this.commands.find(t=>this.filterMoveCallCommands(t,`${this.coreId.veScaPkgId}::ve_sca::extend_lock_period`));return new N(e,this.transaction)}get helperRedeemSca(){let e=this.commands.find(t=>this.filterMoveCallCommands(t,`${this.coreId.veScaPkgId}::ve_sca::redeem`));return new N(e,this.transaction)}get helperRenewExpired(){let e=this.commands.find(t=>this.filterMoveCallCommands(t,`${this.coreId.veScaPkgId}::ve_sca::renew_expired_ve_sca`));return new N(e,this.transaction)}get helperOldUnstakeObligation(){let e=this.commands.find(t=>this.filterMoveCallCommands(t,`${am.OLD_BORROW_INCENTIVE_PROTOCOL_ID}::user::unstake`));return new N(e,this.transaction)}get helperUnstakeObligation(){let e=this.commands.find(t=>this.filterMoveCallCommands(t,`${this.coreId.borrowIncentivePkg}::user::unstake_v2`));return new N(e,this.transaction)}get helperStakeObligationWithVeSca(){let e=this.commands.find(t=>this.filterMoveCallCommands(t,`${this.coreId.borrowIncentivePkg}::user::stake_with_ve_sca_v2`));return new N(e,this.transaction)}getMergeSplitVeScaHelper(e){let t=this.commands.find(n=>this.filterMoveCallCommands(n,`${this.coreId.veScaPkgId}::ve_sca::${e}`));return new N(t,this.transaction)}getVeScaObligationBindingHelpers(){let e=`${this.coreId.borrowIncentivePkg}::user::unstake_v2`,t=`${this.coreId.borrowIncentivePkg}::user::stake_with_ve_sca_v2`,n=`${this.coreId.borrowIncentivePkg}::user::deactivate_boost_v2`,o=[],i=0,s=0,c=0;return this.commands.forEach(p=>{this.filterMoveCallCommands(p,e)?(o.push({action:"unstake",helper:new N(p,this.transaction,i)}),i++):this.filterMoveCallCommands(p,t)?(o.push({action:"stake",helper:new N(p,this.transaction,s)}),s++):this.filterMoveCallCommands(p,n)&&(o.push({action:"deactivate",helper:new N(p,this.transaction,c)}),c++)}),o}decodeRedeemSca(){let e=this.helperRedeemSca.decodeOwnedObjectId(1);return{txType:ne.TransactionType.Other,type:"RedeemSca",intentionData:{veScaKey:e}}}decodeRenewExpiredVeSca(){let e=this.helperRenewExpired.getNestedInputParam(4),t=this.helperRenewExpired.decodeInputU64(5),n=new Wt(e,this.transaction).getAmountInput().reduce((k,M)=>k+M,0),o=this.helperRenewExpired.decodeOwnedObjectId(1),i=!!this.helperRedeemSca.moveCall,s=[],c=[],p=[];this.helperOldUnstakeObligation.moveCall&&(s=[this.helperOldUnstakeObligation.decodeOwnedObjectId(2),this.helperOldUnstakeObligation.decodeSharedObjectId(3)]),this.helperUnstakeObligation.moveCall&&(c=[this.helperUnstakeObligation.decodeOwnedObjectId(3),this.helperUnstakeObligation.decodeSharedObjectId(4)]),this.helperStakeObligationWithVeSca.moveCall&&(p=[this.helperStakeObligationWithVeSca.decodeOwnedObjectId(3),this.helperStakeObligationWithVeSca.decodeSharedObjectId(4)]);let b=!1,S=!1,w,D,x=[{condition:s,isOld:!0},{condition:c,isOld:!1},{condition:p,isOld:!1}];for(let k=0;k<x.length;k++)x[k].condition.length>1&&([D,w]=x[k].condition,b=!0,S=x[k].isOld);return{txType:ne.TransactionType.Other,type:"RenewExpStakePeriod",intentionData:{amount:n,unlockTime:t,obligationId:w,obligationKey:D,veScaKey:o,isHaveRedeem:i,isObligationLocked:b,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 s=!1,c=!1,p,b,S=[{condition:n,isOld:!0},{condition:o,isOld:!1},{condition:i,isOld:!1}];for(let w=0;w<S.length;w++)S[w].condition.length>1&&([b,p]=S[w].condition,s=!0,c=S[w].isOld);return{txType:ne.TransactionType.Other,type:"ExtendStakePeriod",intentionData:{unlockTime:e,obligationId:p,obligationKey:b,veScaKey:t,isObligationLocked:s,isOldBorrowIncentive:c}}}decodePeriodAndStakeMoreSca(){let e=this.helperStakeMoreSca.getNestedInputParam(4),t=this.helperExtendStakePeriod.decodeInputU64(4),n=new Wt(e,this.transaction).getAmountInput().reduce((x,k)=>x+k,0),o=[],i=[],s,c=[];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&&(s=this.helperStakeMoreSca.decodeOwnedObjectId(1)),this.helperStakeObligationWithVeSca.moveCall&&(c=[this.helperStakeObligationWithVeSca.decodeOwnedObjectId(3),this.helperStakeObligationWithVeSca.decodeSharedObjectId(4)]);let p=!1,b=!1,S,w,D=[{condition:o,isOld:!0},{condition:i,isOld:!1},{condition:c,isOld:!1}];for(let x=0;x<D.length;x++)D[x].condition.length>1&&([w,S]=D[x].condition,p=!0,b=D[x].isOld);return{txType:ne.TransactionType.Other,type:"ExtendPeriodAndStakeMore",intentionData:{amount:n,veScaKey:s,unlockTime:t,obligationId:S,obligationKey:w,isOldBorrowIncentive:b,isObligationLocked:p}}}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 Wt(e,this.transaction).getAmountInput().reduce((x,k)=>x+k,0),o=[],i=[],s,c=[];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&&(s=this.helperStakeMoreSca.decodeOwnedObjectId(1)),this.helperStakeObligationWithVeSca.moveCall&&(c=[this.helperStakeObligationWithVeSca.decodeOwnedObjectId(3),this.helperStakeObligationWithVeSca.decodeSharedObjectId(4)]);let p=!1,b=!1,S,w,D=[{condition:o,isOld:!0},{condition:i,isOld:!1},{condition:c,isOld:!1}];for(let x=0;x<D.length;x++)D[x].condition.length>1&&([w,S]=D[x].condition,p=!0,b=D[x].isOld);return{txType:ne.TransactionType.Other,type:"StakeSca",intentionData:{amount:n,unlockTime:t,obligationId:S,obligationKey:w,veScaKey:s,isObligationLocked:p,isOldBorrowIncentive:b}}}decodeMergeVesca(){let e=this.getMergeSplitVeScaHelper("merge"),t={targetVeScaKey:e.decodeOwnedObjectId(1),sourceVeScaKey:e.decodeOwnedObjectId(2)};return{txType:ne.TransactionType.Other,type:"MergeVeSca",intentionData:t}}decodeSplitVesca(){let e=this.getMergeSplitVeScaHelper("split"),t={targetVeScaKey:e.decodeOwnedObjectId(1),splitAmount:e.decodeInputU64(4)};return{txType:ne.TransactionType.Other,type:"SplitVeSca",intentionData:t}}decodeVeScaObligationBindings(){let e=this.getVeScaObligationBindingHelpers(),t=(o,i)=>{switch(o){case"stake":return{veScaKey:i.decodeOwnedObjectId(9),obligationId:i.decodeSharedObjectId(4),obligationKey:i.decodeOwnedObjectId(3)};case"unstake":return{obligationId:i.decodeSharedObjectId(4),obligationKey:i.decodeOwnedObjectId(3)};case"deactivate":return{veScaKey:i.decodeOwnedObjectId(4),obligationId:i.decodeSharedObjectId(3)};default:throw new Error(`Invalid action ${o}`)}},n=e.map(({action:o,helper:i})=>({action:o,args:t(o,i)}));return{txType:ne.TransactionType.Other,type:"VeScaObligationBindings",intentionData:{bindingDatas:n}}}decodeTransferVeScaKey(){let e=this.commands.filter(s=>s.$kind==="TransferObjects"),{objects:t}=e[0].TransferObjects,n=t.filter(s=>s.$kind==="Input").map(({Input:s})=>s);if(n.length!==t.length)return!1;let o=new Set(n),i=this.inputs.filter((s,c)=>s.$kind==="Object"&&o.has(c)).map(s=>s.Object.ImmOrOwnedObject);return{xType:ne.TransactionType.Other,type:"TransferVeScaKeys",intentionData:{veScaKeys:i}}}};var im=Ft(require("sort-keys-recursive")),A=class{constructor(e){this.data=e}get application(){return"msafe-core"}serialize(){return JSON.stringify((0,im.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:s}=t;return await this.isObligationLocked(e.scallopSuiKit.client,i)?(await o.unstakeObligationQuick(i,s),await n(e,o,t),await o.stakeObligationWithVeScaQuick(i,s,t.veScaKey)):await n(e,o,t),o}};var Fa=class a extends A{constructor(t){super(t);this.data=t}txType;txSubType;async borrow({account:t,scallopClient:n}){let{coinName:o,amount:i,obligationId:s,obligationKey:c}=this.data,p=t.address;return(await this.buildTxWithRefreshObligation(n,{walletAddress:p,obligationId:s,obligationKey:c},async(S,w)=>{let D=await w.borrowQuick(+i,o,s,c);w.transferObjects([D],p)})).txBlock}async build(t){return this.borrow(t)}static fromData(t){return new a(t)}};var Ka=class a extends A{constructor(t){super(t);this.data=t}txType;txSubType;async borrowWithBoost(t,n){let{obligationId:o,obligationKey:i,veScaKey:s,amount:c,coinName:p}=this.data;return(await this.buildTxWithRefreshObligation(t,{walletAddress:n,obligationId:o,obligationKey:i,veScaKey:s},async(S,w)=>{let D=await w.borrowQuick(+c,p,o,i);w.transferObjects([D],n)})).txBlock}async build(t){return this.borrowWithBoost(t.scallopClient,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 borrowWithReferral({account:t,scallopClient:n}){let o=t.address,{obligationId:i,obligationKey:s,veScaKey:c,coinName:p,amount:b}=this.data;return(await this.buildTxWithRefreshObligation(n,{walletAddress:o,obligationId:i,obligationKey:s,veScaKey:c},async(w,D)=>{let x=D.claimReferralTicket(p),k=await D.borrowWithReferralQuick(+b,p,x,i,s);D.burnReferralTicket(x,p),D.transferObjects([k],o)})).txBlock}async build(t){return this.borrowWithReferral(t)}static fromData(t){return new a(t)}};var rm=require("@mysten/sui/utils");var $a=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),i=await e.query.getLendings(void 0,t),s=await e.query.getObligations(t),c=Object.values(await e.query.getObligationAccounts(t)??[]),p=(()=>{let D=[...e.constants.whitelist.spool].map(x=>e.utils.parseCoinName(x));return Object.values(i??[]).filter(x=>!!x&&D.includes(x.coinName)).reduce((x,k)=>{let M=e.utils.parseMarketCoinName(k.coinName);return x[M]||(x[M]=0),x[M]+=k.availableClaimCoin,x},{})})(),b={};Object.entries(o).forEach(([D,x])=>{for(let k=0;k<x.length;k++){let M=x[k];if(!p[D])continue;let L=n.claim(M.id,D);b.sui?b.sui.push(L):b.sui=[L]}});let S=(()=>{let D={};return D.sui=Object.values(p).reduce((x,k)=>x+k,0),c.forEach(x=>{Object.values(x.borrowIncentives).forEach(k=>{k&&k.rewards.forEach(M=>{D[M.coinName]||(D[M.coinName]=0),D[M.coinName]?D[M.coinName]+=M.availableClaimCoin:D[M.coinName]=M.availableClaimCoin})})}),D})();if(s.length>0&&c.length>0)for(let D=0;D<c.length;D++){let x=c[D],k=!1,M=s.find(U=>U.id===x.obligationId)?.keyId,L={};if(M){if(Object.values(x.borrowIncentives).forEach(U=>{if(U){let q=U.rewards.filter(Mt=>{let W=Mt.coinName;return Mt.availableClaimCoin>0&&!L[W]});k=q.length>0,q.forEach(Mt=>{let W=n.claimBorrowIncentive(x.obligationId,M,Mt.coinName);L[Mt.coinName]=!0,b[Mt.coinName]?b[Mt.coinName].push(W):b[Mt.coinName]=[W]})}}),S.sui>0){let U=Ht.redeem_rewards(n,M,x.obligationId,rm.SUI_TYPE_ARG);b.sui?b.sui.push(U):b.sui=[U]}if(k&&await nm(e.query,x.obligationId)){n.unstakeObligation(x.obligationId,M);let q=await e.query.getBindedVeScaKey(x.obligationId);q?n.stakeObligationWithVesca(x.obligationId,M,q):n.stakeObligation(x.obligationId,M)}}}let w=(await Promise.all(Object.entries(b).map(async([D,x])=>{let k=x[0];if(x.length>1&&n.mergeCoins(k,x.slice(1)),D==="sui"){n.mergeCoins(n.gas,[k]);return}return await e.builder.utils.mergeSimilarCoins(n,k,e.utils.parseCoinType(D),t),k}))).filter(D=>!!D);return w.length>0&&n.transferObjects(w,t),n.txBlock}async build(e){return this.claimIncentiveRewards(e.scallopClient,e.account.address)}static fromData(e={}){return new a(e)}};var Ha=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 Xa=class a extends A{constructor(t){super(t);this.data=t}txType;txSubType;async migrateAndClaim({account:t,scallopClient:n}){let o=t.address,{obligationKey:i,obligationId:s,rewardCoinName:c,veScaKey:p}=this.data,b=n.builder.createTxBlock();b.setSender(o);let S=Ht.redeem_rewards(b,i,s,n.utils.parseCoinType(c));return b.transferObjects([S],o),await b.unstakeObligationQuick(s,i),p?await b.stakeObligationWithVeScaQuick(s,i,p):await b.stakeObligationQuick(s,i),b.txBlock}async build(t){return this.migrateAndClaim(t)}static fromData(t){return new a(t)}};var za=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 Ga=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 Qa=class a extends A{constructor(t){super(t);this.data=t}txType;txSubType;async repay({account:t,scallopClient:n}){let o=t.address,{coinName:i,amount:s,obligationId:c,obligationKey:p}=this.data;return(await this.buildTxWithRefreshObligation(n,{walletAddress:o,obligationId:c,obligationKey:p},async(S,w)=>{await w.repayQuick(+s,i,c)})).txBlock}async build(t){return this.repay(t)}static fromData(t){return new a(t)}};var Ya=class a extends A{constructor(t){super(t);this.data=t}txType;txSubType;async repayWithBoost({account:t,scallopClient:n}){let o=t.address,{coinName:i,amount:s,obligationId:c,veScaKey:p}=this.data,b=n.builder.createTxBlock();b.setSender(o);let S=n.constants.whitelist.borrowing.has(i);return S&&await b.unstakeObligationQuick(c,void 0),await b.repayQuick(+s,i,c),S&&await b.stakeObligationWithVeScaQuick(c,void 0,p),b.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 Za=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 ti=class a extends A{constructor(t){super(t);this.data=t}txType;txSubType;async unstakeAndWithdraw(t,n,o){let i=t.builder.createTxBlock();i.setSender(o);let{stakeAccountId:s,amount:c,coinName:p}=this.data,b=[];for(let S=0;S<s.length;S++){let{id:w,coin:D}=s[S],x=t.utils.parseMarketCoinName(p),[k]=await i.unstakeQuick(D,x,w);if(k){let M=i.withdraw(k,p);b.push(M)}}if(c>0){let S=await i.withdrawQuick(c,p);b.push(S)}return b.length>1&&i.mergeCoins(b[0],b.slice(1)),i.transferObjects(b,o),i.txBlock}async build(t){return this.unstakeAndWithdraw(t.scallopClient,this.data,t.account.address)}static fromData(t){return new a(t)}};var ei=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 ni=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 oi=class a extends A{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 ai=class a extends A{constructor(t){super(t);this.data=t}txType;txSubType;async claimRevenueReferral({account:t,scallopClient:n}){let{veScaKey:o,coins:i}=this.data,s=t.address,c=n.builder.createTxBlock();c.setSender(s);let p=i.map(b=>n.utils.parseCoinNameFromType(b));return await c.claimReferralRevenueQuick(o,p),c.txBlock}async build(t){return this.claimRevenueReferral(t)}static fromData(t){return new a(t)}};var ii=class a extends A{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 s=i.mintEmptyVeSca();return i.transferObjects([s],o),i.txBlock}async build(t){return this.createReferralLink(t)}static fromData(t){return new a(t)}};var sm=require("@scallop-io/sui-scallop-sdk");var ri=class a extends A{constructor(t){super(t);this.data=t}txType;txSubType;async extendPeriodAndStakeMoreSca({account:t,scallopClient:n}){let{amount:o,veScaKey:i,unlockTime:s,obligationId:c,obligationKey:p,isOldBorrowIncentive:b,isObligationLocked:S}=this.data,w=t.address,D=n.builder.createTxBlock();D.setSender(w);let x=await n.utils.selectCoins(o,sm.SCA_COIN_TYPE,w),[k,M]=D.takeAmountFromCoins(x,o);return D.extendLockPeriod(i,s),D.extendLockAmount(i,k),D.transferObjects([M],w),!c||!p||(S&&(b?Ht.unstakeObligation(D,c,p):D.unstakeObligation(c,p)),D.stakeObligationWithVesca(c,p,i)),D.txBlock}async build(t){return this.extendPeriodAndStakeMoreSca(t)}static fromData(t){return new a(t)}};var si=class a extends A{constructor(t){super(t);this.data=t}txType;txSubType;async extendStakeScaLockPeriod({account:t,scallopClient:n}){let o=t.address,{veScaKey:i,unlockTime:s,obligationId:c,obligationKey:p,isObligationLocked:b,isOldBorrowIncentive:S}=this.data,w=n.builder.createTxBlock();return w.setSender(o),w.extendLockPeriod(i,s),c&&p&&(b&&(S?Ht.unstakeObligation(w,p,c):w.unstakeObligation(c,p)),w.stakeObligationWithVesca(c,p,i)),w.txBlock}async build(t){return this.extendStakeScaLockPeriod(t)}static fromData(t){return new a(t)}};var ci=class a extends A{constructor(t){super(t);this.data=t}txType;txSubType;async handleUnsubForKeys(t,n,o){let{targetVeScaKey:i,sourceVeScaKey:s}=this.data,[c,p]=await Promise.all([n.getBindedObligationId(i),n.getBindedObligationId(s)]);c&&await t.unstakeObligationQuick(c),p&&await t.unstakeObligationQuick(p),o(t,i,s),c&&await t.stakeObligationWithVeScaQuick(c,void 0,i),p&&await t.stakeObligationWithVeScaQuick(p,void 0,s)}async build(t){let{scallopClient:n,account:{address:o}}=t,i=n.builder.createTxBlock();return i.setSender(o),await this.handleUnsubForKeys(i,n.query,async(s,c,p)=>{s.mergeVeSca(i.object(c),i.object(p))}),i.txBlock}static fromData(t){return new a(t)}};var li=class a extends A{constructor(t){super(t);this.data=t}txType;txSubType;async redeemSca({account:t,scallopClient:n}){let{veScaKey:o}=this.data,i=t.address,s=n.builder.createTxBlock();return s.setSender(i),await s.redeemScaQuick({veScaKey:o}),s.txBlock}async build(t){return this.redeemSca(t)}static fromData(t){return new a(t)}};var cm=require("@scallop-io/sui-scallop-sdk");var ui=class a extends A{constructor(t){super(t);this.data=t}txType;txSubType;async renewExpiredStakeSca({account:t,scallopClient:n}){let o=t.address,{amount:i,unlockTime:s,veScaKey:c,isHaveRedeem:p,obligation:b,obligationKey:S,isObligationLocked:w,isOldBorrowIncentive:D}=this.data,x=n.builder.createTxBlock();if(x.setSender(o),p){let U=x.redeemSca(c);x.transferObjects([U],o)}let k=await n.builder.utils.selectCoins(i,cm.SCA_COIN_TYPE,o),[M,L]=x.takeAmountFromCoins(k,i);return x.transferObjects([L],o),x.renewExpiredVeSca(c,M,s),!b||!S||(w&&(D?Ht.unstakeObligation(x,S,b):x.unstakeObligation(b,S)),x.stakeObligationWithVesca(b,S,c)),x.txBlock}async build(t){return this.renewExpiredStakeSca(t)}static fromData(t){return new a(t)}};var mi=class a extends A{constructor(t){super(t);this.data=t}txType;txSubType;async handleUnsubForKeys(t,n,o){let{targetVeScaKey:i,splitAmount:s}=this.data,c=await n.getBindedObligationId(i);c&&await t.unstakeObligationQuick(c),o(t,i,s.toString()),c&&await t.stakeObligationWithVeScaQuick(c,void 0,i)}async build(t){let{scallopClient:n,account:{address:o}}=t,i=n.builder.createTxBlock();return i.setSender(o),await this.handleUnsubForKeys(i,n.query,(s,c,p)=>{let b=s.splitVeSca(c,p.toString());s.transferObjects([b],o)}),i.txBlock}static fromData(t){return new a(t)}};var lm=require("@scallop-io/sui-scallop-sdk");var pi=class a extends A{constructor(t){super(t);this.data=t}txType;txSubType;async stakeSca({account:t,scallopClient:n}){let o=t.address,{amount:i,isObligationLocked:s,isOldBorrowIncentive:c,obligationId:p,obligationKey:b,unlockTime:S,veScaKey:w}=this.data,D=n.builder.createTxBlock();D.setSender(o);let x=await n.utils.selectCoins(i,lm.SCA_COIN_TYPE,o),[k,M]=D.takeAmountFromCoins(x,i),L;return w?D.extendLockAmount(w,k):L=D.lockSca(k,S),p&&b&&(s&&(c?Ht.unstakeObligation(D,b,p):D.unstakeObligation(p,b)),D.stakeObligationWithVesca(p,b,w||L)),w||D.transferObjects([L,M],o),D.txBlock}async build(t){return this.stakeSca(t)}static fromData(t){return new a(t)}};var di=class a extends A{constructor(t){super(t);this.data=t}txType;txSubType;async supplyAndStake({account:t,scallopClient:n}){let o=t.address,{amount:i,coinName:s,stakeAccountId:c}=this.data,p=n.builder.createTxBlock();p.setSender(o);let b=await p.depositQuick(+i,s),S=n.utils.parseMarketCoinName(s);if(n.constants.whitelist.spool.has(S))return p.txBlock;let w=await n.query.getStakeAccounts(S,o),D=c||(w.length>0?w[0].id:void 0);if(D)await p.stakeQuick(b,S,D);else{let x=p.createStakeAccount(S);await p.stakeQuick(b,S,x),p.transferObjects([x],o)}return p.txBlock}async build(t){return this.supplyAndStake(t)}static fromData(t){return new a(t)}};var fi=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,i=n.builder.createTxBlock();i.setSender(o);let{bindingDatas:s}=this.data;return s.forEach(c=>this.handleAction(i,c)),i.txBlock}static fromData(t){return new a(t)}};var hi=class a extends A{constructor(t){super(t);this.data=t}txType;txSubType;async build(t){let{scallopClient:n,account:{address:o}}=t,i=n.builder.createTxBlock();i.setSender(o);let{veScaKeys:s}=this.data;return i.transferObjects(s.map(c=>i.objectRef(c)),i.pure.address(o)),i.txBlock}static fromData(t){return new a(t)}};var gi=class a extends A{constructor(t){super(t);this.data=t}txType;txSubType;async withdrawUnlockedSca({account:t,scallopClient:n}){let{vescaKey:o}=this.data,i=t.address,s=n.builder.createTxBlock();return s.setSender(i),await s.redeemScaQuick({veScaKey:o}),s.txBlock}async build(t){return this.withdrawUnlockedSca(t)}static fromData(t){return new a(t)}};var yi=class{application="scallop";supportSDK="@mysten/sui";scallopClient;async initScallopClient(e,t){if(!this.scallopClient){let n=new pm.Scallop({addressId:"67c44a103fe1b8c454eb9699",walletAddress:e,suiClients:[t],fullnodeUrls:[t.transport.rpcClient.requestManager.transports[0]?.uri??(0,mm.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 i=new La(t,this.scallopClient),s=new Ua(t,this.scallopClient),c=new qa(t,this.scallopClient),p=i.decode()||s.decode()||await c.decode();if(!p)throw new Error("Unknown transaction type");return{txType:um.TransactionType.Other,txSubType:p.type,intentionData:p.intentionData}}async build(e){let{suiClient:t,account:n,network:o,txSubType:i,intentionData:s}=e;await this.initScallopClient(n.address,t);let c;switch(i){case"SupplyLending":c=Ja.fromData(s);break;case"WithdrawLending":c=ni.fromData(s);break;case"Borrow":c=Fa.fromData(s);break;case"Repay":c=Qa.fromData(s);break;case"DepositCollateral":c=Ha.fromData(s);break;case"WithdrawCollateral":c=ei.fromData(s);break;case"OpenObligation":c=Ga.fromData(s);break;case"UnstakeSpool":c=Za.fromData(s);break;case"ClaimIncentiveReward":c=$a.fromData(s);break;case"BorrowWithBoost":c=Ka.fromData(s);break;case"StakeSca":c=pi.fromData(s);break;case"ExtendStakePeriod":c=si.fromData(s);break;case"ExtendPeriodAndStakeMore":c=ri.fromData(s);break;case"RenewExpStakePeriod":c=ui.fromData(s);break;case"WithdrawStakedSca":c=gi.fromData(s);break;case"SupplyAndStakeLending":c=di.fromData(s);break;case"WithdrawAndUnstakeLending":c=ti.fromData(s);break;case"RedeemSca":c=li.fromData(s);break;case"MigrateAndClaim":c=Xa.fromData(s);break;case"BorrowWithReferral":c=Va.fromData(s);break;case"CreateReferralLink":c=ii.fromData(s);break;case"ClaimRevenueReferral":c=ai.fromData(s);break;case"BindReferral":c=oi.fromData(s);break;case"MigrateScoin":c=za.fromData(s);break;case"RepayWithBoost":c=Ya.fromData(s);break;case"MergeVeSca":c=ci.fromData(s);break;case"SplitVeSca":c=mi.fromData(s);break;case"VeScaObligationBindings":{c=fi.fromData(s);break}case"TransferVeScaKeys":{c=hi.fromData(s);break}default:throw new Error("not implemented")}return c.build({suiClient:t,account:n,network:o,scallopClient:this.scallopClient})}};var Em=require("@msafe/sui3-utils");var mn=require("@msafe/sui3-utils"),Ae=require("@mysten/sui/utils");var Dm=require("@suilend/sui-fe");var Cm=require("@msafe/sui3-utils"),ve=require("@suilend/sdk");var We=require("@msafe/sui3-utils"),ln=require("@mysten/bcs"),cn=require("@mysten/sui/utils"),_e=require("@suilend/sui-fe"),$s=Ft(require("bignumber.js"));var bi=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,cn.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(p=>p.type.includes("lending_market::RedeemEvent"))},n=(0,cn.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,s=new $s.default((0,ln.toHex)((0,ln.fromBase64)(this.inputs[i].Pure.bytes)),16).toString(),c=s===_e.MAX_U64.toString();return console.log("decodeWithdraw - isMax:",c,"inputIndex:",i,"inputValue:",s,"MAX_U64.toString():",_e.MAX_U64.toString()),c&&(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(p=>p.type.includes("lending_market::BorrowEvent"))},n=(0,cn.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,s=new $s.default((0,ln.toHex)((0,ln.fromBase64)(this.inputs[i].Pure.bytes)),16).toString(),c=s===_e.MAX_U64.toString();return console.log("decodeBorrow - isMax:",c,"inputIndex:",i,"inputValue:",s,"MAX_U64.toString():",_e.MAX_U64.toString()),c&&(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,cn.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],i=(0,cn.normalizeStructTag)(o.parsedJson.coin_type.name),s=o.parsedJson.liquidity_amount;t[i]=`${+(t[i]??"0")+ +s}`}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 fm=require("@mysten/sui/transactions");var dm=Ft(require("sort-keys-recursive")),qt=class{constructor(e){this.data=e}serialize(){return JSON.stringify((0,dm.default)(this.data))}};var Ti=class a extends qt{constructor(t){super(t);this.data=t}txType;txSubType;async build(t){let{suiClient:n,account:o,suilendClient:i,obligationOwnerCap:s,obligation:c}=t;if(console.log("BorrowIntention.build",n,o,i,s,c),!s||!c)throw new Error("Obligation not found");let p=new fm.Transaction;return await i.borrowAndSendToUser(o.address,s.id,c.id,this.data.coinType,this.data.value,p),p}static fromData(t){return console.log("BorrowIntention.fromData",t),new a(t)}};var bm=require("@mysten/sui/transactions");var hm=require("@mysten/sui/utils"),un=require("@suilend/sdk"),gm=require("@suilend/sui-fe"),ym=Ft(require("bignumber.js")),Bf=(a,e)=>{let t={[un.Side.DEPOSIT]:[],[un.Side.BORROW]:[]};return a.lendingMarket.reserves.forEach(n=>{[un.Side.DEPOSIT,un.Side.BORROW].forEach(o=>{let i=o===un.Side.DEPOSIT?n.depositsPoolRewardManager:n.borrowsPoolRewardManager,s=e.userRewardManagers.find(c=>c.poolRewardManagerId===i.id);s&&(t[o]=i.poolRewards.map((c,p)=>({reserveArrayIndex:n.arrayIndex,rewardIndex:BigInt(p),rewardCoinType:(0,hm.normalizeStructTag)(c.coinType.name),side:o})).filter(c=>!(0,gm.isSendPoints)(c.rewardCoinType)&&!!s.rewards[Number(c.rewardIndex)]&&new ym.default(s.rewards[Number(c.rewardIndex)].earnedRewards.value.toString()).gt(0)))})}),Object.values(t).flat()},Si=Bf;var Ii=class a extends qt{constructor(t){super(t);this.data=t}txType;txSubType;async build(t){let{suiClient:n,account:o,suilendClient:i,obligationOwnerCap:s,obligation:c}=t;if(console.log("ClaimIntention.build",n,o,i,s,c),!s||!c)throw new Error("Obligation not found");let p=new bm.Transaction;return i.claimRewardsAndSendToUser(o.address,s.id,Si(i,c),p),p}static fromData(t){return console.log("ClaimIntention.fromData",t),new a(t)}};var Tm=require("@mysten/sui/transactions");var wi=class a extends qt{constructor(t){super(t);this.data=t}txType;txSubType;async build(t){let{suiClient:n,account:o,suilendClient:i,obligationOwnerCap:s,obligation:c}=t;if(console.log("ClaimAndDepositIntention.build",n,o,i,s,c),!s||!c)throw new Error("Obligation not found");let p=new Tm.Transaction;return i.claimRewardsAndDeposit(o.address,s.id,Si(i,c),p),p}static fromData(t){return console.log("ClaimAndDepositIntention.fromData",t),new a(t)}};var Sm=require("@mysten/sui/transactions");var Ci=class a extends qt{constructor(t){super(t);this.data=t}txType;txSubType;async build(t){let{suiClient:n,account:o,suilendClient:i,obligationOwnerCap:s,obligation:c}=t;console.log("DepositIntention.build",n,o,i,s,c);let p=new Sm.Transaction;return await i.depositIntoObligation(o.address,this.data.coinType,this.data.value,p,s?.id),p}static fromData(t){return console.log("DepositIntention.fromData",t),new a(t)}};var Im=require("@mysten/sui/transactions");var Di=class a extends qt{constructor(t){super(t);this.data=t}txType;txSubType;async build(t){let{suiClient:n,account:o,suilendClient:i,obligationOwnerCap:s,obligation:c}=t;if(console.log("RepayIntention.build",n,o,i,s,c),!s||!c)throw new Error("Obligation not found");let p=new Im.Transaction;return await i.repayIntoObligation(o.address,c.id,this.data.coinType,this.data.value,p),p}static fromData(t){return console.log("RepayIntention.fromData",t),new a(t)}};var wm=require("@mysten/sui/transactions");var xi=class a extends qt{constructor(t){super(t);this.data=t}txType;txSubType;async build(t){let{suiClient:n,account:o,suilendClient:i,obligationOwnerCap:s,obligation:c}=t;if(console.log("WithdrawIntention.build",n,o,i,s,c),!s||!c)throw new Error("Obligation not found");let p=new wm.Transaction;return await i.withdrawAndSendToUser(o.address,s.id,c.id,this.data.coinType,this.data.value,p),p}static fromData(t){return console.log("WithdrawIntention.fromData",t),new a(t)}};var ki=async(a,e)=>{let t=await ve.SuilendClient.initialize(ve.LENDING_MARKET_ID,ve.LENDING_MARKET_TYPE,a),n=await ve.SuilendClient.getObligationOwnerCaps(e.address,t.lendingMarket.$typeArgs,a),o=await Promise.all(n.map(i=>ve.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}},vi=class{application="Suilend";supportSDK="@mysten/sui";utils;async deserialize(e){let{transaction:t,suiClient:n,account:o}=e;this.utils||(this.utils=await ki(n,o));let i=await n.devInspectTransactionBlock({sender:o.address,transactionBlock:t});console.log("SuilendAppHelper.deserialize - simResult:",i,"utils:",this.utils,"suiClient:",n);let c=new bi(t,i).decode();return{txType:Cm.TransactionType.Other,txSubType:c.type,intentionData:c.intentionData}}async build(e){let{network:t,txSubType:n,intentionData:o,suiClient:i,account:s}=e;this.utils||(this.utils=await ki(i,s));let c;switch(n){case"deposit":c=Ci.fromData(o);break;case"withdraw":c=xi.fromData(o);break;case"borrow":c=Ti.fromData(o);break;case"repay":c=Di.fromData(o);break;case"claim":c=Ii.fromData(o);break;case"claimAndDeposit":c=wi.fromData(o);break;default:throw new Error("not implemented")}let p=window.localStorage.getItem("obligationId"),b=this.utils.obligations?.find(w=>w.id===p)??this.utils.obligations?.[0],S=this.utils.obligationOwnerCaps?.find(w=>w.obligationId===b?.id);return c.build({network:t,suiClient:i,account:s,suilendClient:this.utils.suilendClient,obligationOwnerCap:S,obligation:b})}};var Hs=async(a,e)=>{let t=await ki(a,e),n=await fetch(`${Dm.API_URL}/springsui/lst-info`),o=await n.json();if(n?.statusCode===500)throw new Error("Failed to fetch SpringSui LST data");let s=Object.fromEntries(Object.values(o).map(c=>[c.LIQUID_STAKING_INFO.type,c.LIQUID_STAKING_INFO]));return{...t,LIQUID_STAKING_INFO_MAP:s}};var Ai=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,Ae.normalizeStructTag)(e.MintEvent.parsedJson.event.typename.name),n=e.MintEvent.parsedJson.event.sui_amount_in;return console.log("Decoder.decodeStake",n),{txType:mn.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,Ae.normalizeStructTag)(e.MintEvent.parsedJson.event.typename.name),n=e.MintEvent.parsedJson.event.sui_amount_in;return console.log("Decoder.decodeStakeAndDeposit",n),{txType:mn.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,Ae.normalizeStructTag)(e.RedeemEvent.parsedJson.event.typename.name),n=(0,Ae.normalizeStructTag)(e.MintEvent.parsedJson.event.typename.name),o=e.RedeemEvent.parsedJson.event.lst_amount_in;return console.log("Decoder.decodeConvert",o),{txType:mn.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,Ae.normalizeStructTag)(e.RedeemEvent.parsedJson.event.typename.name),n=(0,Ae.normalizeStructTag)(e.MintEvent.parsedJson.event.typename.name),o=e.RedeemEvent.parsedJson.event.lst_amount_in;return console.log("Decoder.decodeConvertAndDeposit",o),{txType:mn.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,Ae.normalizeStructTag)(e.RedeemEvent.parsedJson.event.typename.name),n=e.RedeemEvent.parsedJson.event.lst_amount_in;return console.log("Decoder.decodeUnstake",n),{txType:mn.TransactionType.Other,type:"unstake",intentionData:{amount:n,inCoinType:t}}}};var km=require("@mysten/sui/transactions"),Kn=require("@suilend/springsui-sdk");var xm=Ft(require("sort-keys-recursive")),Xt=class{constructor(e){this.data=e}serialize(){return JSON.stringify((0,xm.default)(this.data))}};var Mi=class a extends Xt{constructor(t){super(t);this.data=t}txType;txSubType;async build(t){let{suiClient:n,account:o,suilendClient:i,LIQUID_STAKING_INFO_MAP:s,obligationOwnerCap:c,obligation:p}=t;console.log("ConvertIntention.build",n,o,i,s,c,p);let b=await Kn.LstClient.initialize(n,Object.values(s).find(D=>D.type===this.data.inCoinType)),S=await Kn.LstClient.initialize(n,Object.values(s).find(D=>D.type===this.data.outCoinType)),w=new km.Transaction;return(0,Kn.convertLstsAndRebalanceAndSendToUser)(b,S,w,o.address,this.data.amount),w}static fromData(t){return console.log("ConvertIntention.fromData",t),new a(t)}};var vm=require("@mysten/sui/transactions"),Pi=require("@suilend/sdk"),Vn=require("@suilend/springsui-sdk");var Oi=class a extends Xt{constructor(t){super(t);this.data=t}txType;txSubType;async build(t){let{suiClient:n,account:o,suilendClient:i,LIQUID_STAKING_INFO_MAP:s,obligationOwnerCap:c,obligation:p}=t;console.log("ConvertAndDepositIntention.build",n,o,i,s,c,p);let b=await Vn.LstClient.initialize(n,Object.values(s).find(M=>M.type===this.data.inCoinType)),S=await Vn.LstClient.initialize(n,Object.values(s).find(M=>M.type===this.data.outCoinType)),w=new vm.Transaction,{obligationOwnerCapId:D,didCreate:x}=(0,Pi.createObligationIfNoneExists)(i,w,c),k=(0,Vn.convertLstsAndRebalance)(b,S,w,o.address,this.data.amount);return i.deposit(k,this.data.outCoinType,D,w),x&&(0,Pi.sendObligationToUser)(D,o.address,w),w}static fromData(t){return console.log("ConvertAndDepositIntention.fromData",t),new a(t)}};var Am=require("@mysten/sui/transactions"),Mm=require("@suilend/springsui-sdk");var Ri=class a extends Xt{constructor(t){super(t);this.data=t}txType;txSubType;async build(t){let{suiClient:n,account:o,suilendClient:i,LIQUID_STAKING_INFO_MAP:s,obligationOwnerCap:c,obligation:p}=t;console.log("StakeIntention.build",n,o,i,s,c,p);let b=await Mm.LstClient.initialize(n,Object.values(s).find(w=>w.type===this.data.outCoinType)),S=new Am.Transaction;return b.mintAmountAndRebalanceAndSendToUser(S,o.address,this.data.amount),S}static fromData(t){return console.log("StakeIntention.fromData",t),new a(t)}};var Om=require("@mysten/sui/transactions"),Ei=require("@suilend/sdk"),Pm=require("@suilend/springsui-sdk");var Bi=class a extends Xt{constructor(t){super(t);this.data=t}txType;txSubType;async build(t){let{suiClient:n,account:o,suilendClient:i,LIQUID_STAKING_INFO_MAP:s,obligationOwnerCap:c,obligation:p}=t;console.log("StakeAndDepositIntention.build",n,o,i,s,c,p);let b=await Pm.LstClient.initialize(n,Object.values(s).find(k=>k.type===this.data.outCoinType)),S=new Om.Transaction,{obligationOwnerCapId:w,didCreate:D}=(0,Ei.createObligationIfNoneExists)(i,S,c),x=b.mintAmountAndRebalance(S,o.address,this.data.amount);return i.deposit(x,this.data.outCoinType,w,S),D&&(0,Ei.sendObligationToUser)(w,o.address,S),S}static fromData(t){return console.log("StakeAndDepositIntention.fromData",t),new a(t)}};var Rm=require("@mysten/sui/transactions"),Bm=require("@suilend/springsui-sdk");var Ni=class a extends Xt{constructor(t){super(t);this.data=t}txType;txSubType;async build(t){let{suiClient:n,account:o,suilendClient:i,LIQUID_STAKING_INFO_MAP:s,obligationOwnerCap:c,obligation:p}=t;console.log("UnstakeIntention.build",n,o,i,s,c,p);let b=await Bm.LstClient.initialize(n,Object.values(s).find(w=>w.type===this.data.inCoinType)),S=new Rm.Transaction;return b.redeemAmountAndRebalanceAndSendToUser(S,o.address,this.data.amount),S}static fromData(t){return console.log("UnstakeIntention.fromData",t),new a(t)}};var Wi=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 c=new Ai(t,i).decode();return{txType:Em.TransactionType.Other,txSubType:c.type,intentionData:c.intentionData}}async build(e){let{network:t,txSubType:n,intentionData:o,suiClient:i,account:s}=e;this.utils||(this.utils=await Hs(i,s));let c;switch(n){case"stake":c=Ri.fromData(o);break;case"stakeAndDeposit":c=Bi.fromData(o);break;case"convert":c=Mi.fromData(o);break;case"convertAndDeposit":c=Oi.fromData(o);break;case"unstake":c=Ni.fromData(o);break;default:throw new Error("not implemented")}return c.build({network:t,suiClient:i,account:s,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 _m=require("@msafe/sui3-utils");var Xs=require("@msafe/sui3-utils");var _i=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:Xs.TransactionType.Other,type:"mint",intentionData:{amount:t}}}decodeRedeem(e){let{event:{lst_amount_in:t}}=e;return console.log("Decoder.decodeRedeem",t),{txType:Xs.TransactionType.Other,type:"redeem",intentionData:{amount:t}}}};var Nm=require("@alphafi/stsui-sdk");var Li=class a extends I{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"},c=await new Nm.LST(i).mint(o,n.address);return c.setGasBudget(1e8),c}static fromData(t){return console.log("MintIntention.fromData",t),new a(t)}};var Wm=require("@alphafi/stsui-sdk");var ji=class a extends I{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"},c=await new Wm.LST(i).redeem(o,n.address);return c.setGasBudget(1e8),c}static fromData(t){return console.log("RedeemIntention.fromData",t),new a(t)}};var Ui=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 s=new _i(t,o).decode();return{txType:_m.TransactionType.Other,txSubType:s.type,intentionData:s.intentionData}}async build(e){let{account:t}=e;console.log("StSui build transaction type",e.txSubType);let n;switch(e.txSubType){case"mint":n=Li.fromData(e.intentionData);break;case"redeem":n=ji.fromData(e.intentionData);break;default:throw new Error("build not implemented")}return n.build({account:t})}};var sp=require("@msafe/sui3-utils"),cp=require("turbos-clmm-sdk");var _t=require("@msafe/sui3-utils"),Le=require("@mysten/bcs"),je=require("@mysten/sui/bcs"),Lm=require("turbos-clmm-sdk");var Gt={PackageId:"0x02fe4933f4521250e55a15441096d1d4a38a7311195b0bca126fc0138c1f5a97",Claim:"0x0c822cec42f7ca703696b4232f1c47b348330c23580172a29aab465bc071d894",turbosCoinType:"0x5d1f47ea69bb0de31c313d7acf89b890dbb8991ea8e03c6c355171f84bb1ba4a::turbos::TURBOS"},Qt={PackageId:"0xdee9"};var _f=(a,e,t,n)=>{if(a===1)switch(n.findIndex(s=>s===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}`)}},qi=class{constructor(e,t,n){this.txb=e;this.turbosSdk=t;this.config=n}get transactions(){return this.txb.getData().commands}get swap1Layer(){return[`${this.config.PackageId}::swap_router::swap_a_b`,`${this.config.PackageId}::swap_router::swap_b_a`]}get swap2Layer(){return[`${this.config.PackageId}::swap_router::swap_a_b_b_c`,`${this.config.PackageId}::swap_router::swap_a_b_c_b`,`${this.config.PackageId}::swap_router::swap_b_a_b_c`,`${this.config.PackageId}::swap_router::swap_b_a_c_b`]}async decode(e){if(this.isSwapTransaction())return this.decodeSwap();if(this.isAddLiquidityTransaction())return this.decodeAddLiquidity();if(this.isIncreaseLiquidityTransaction())return this.decodeIncreaseLiquidity(e);if(this.isRemoveLiquidityTransaction())return this.decodeRemoveLiquidity(e);if(this.isDecreaseLiquidityTransaction())return this.decodeDecreaseLiquidity(e);if(this.isRemoveLiquidityWithReturnTransaction())return this.decodeRemoveLiquidityWithReturn(e);if(this.isDecreaseLiquidityWithReturnTransaction())return this.decodeDecreaseLiquidityWithReturn(e);if(this.isCollectFeeTransaction())return this.decodeCollectFee();if(this.isCollectRewardTransaction())return this.decodeCollectReward();if(this.isBurnTransaction())return this.decodeBurn();if(this.isPrixClaimTransaction())return this.decodePrixClaim();if(this.isPrixJoinTransaction())return this.decodePrixJoin();if(this.isSwapExactBaseForQuoteTransaction())return this.decodeSwapExactBaseForQuote();if(this.isSwapExactQuoteForBaseTransaction())return this.decodeSwapExactQuoteForBase();throw new Error("Unknown transaction type")}getMoveCallTransaction(e){return this.transactions.find(t=>t.$kind==="MoveCall"?`${t.MoveCall.package}::${t.MoveCall.module}::${t.MoveCall.function}`===e:!1)}getMoveCallsTransaction(e){return e.every(t=>this.transactions.find(n=>n.$kind==="MoveCall"?`${n.MoveCall.package}::${n.MoveCall.module}::${n.MoveCall.function}`===t:!1))}getSwapMoveCallTransaction(e){return this.transactions.find(t=>{if(t.$kind==="MoveCall"){let n=`${t.MoveCall.package}::${t.MoveCall.module}::${t.MoveCall.function}`;return!!e.includes(n)}return!1})}isSwapTransaction(){return!!this.getSwapMoveCallTransaction([...this.swap1Layer,...this.swap2Layer])}isAddLiquidityTransaction(){return!!this.getMoveCallTransaction(`${this.config.PackageId}::position_manager::mint`)}isIncreaseLiquidityTransaction(){return!!this.getMoveCallTransaction(`${this.config.PackageId}::position_manager::increase_liquidity`)}isDecreaseLiquidityTransaction(){return!!this.getMoveCallTransaction(`${this.config.PackageId}::position_manager::decrease_liquidity`)}isDecreaseLiquidityWithReturnTransaction(){return!!this.getMoveCallTransaction(`${this.config.PackageId}::position_manager::decrease_liquidity_with_return_`)}isCollectFeeTransaction(){return!!this.getMoveCallTransaction(`${this.config.PackageId}::position_manager::collect`)}isCollectRewardTransaction(){return!!this.getMoveCallTransaction(`${this.config.PackageId}::position_manager::collect_reward`)}isBurnTransaction(){return!!this.getMoveCallTransaction(`${this.config.PackageId}::position_manager::burn`)}isPrixJoinTransaction(){return!!this.getMoveCallTransaction(`${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`])}isRemoveLiquidityWithReturnTransaction(){return!!this.getMoveCallsTransaction([`${this.config.PackageId}::position_manager::decrease_liquidity_with_return_`,`${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(x=>x.$kind==="MoveCall"),t=0,n=`${e.MoveCall.package}::${e.MoveCall.module}::${e.MoveCall.function}`;console.log(n,"moveCallTarget"),this.swap2Layer.includes(n)&&(t=1);let o=_f(t,n,this.swap1Layer,this.swap2Layer),i=o.map((x,k)=>{let M=this.helper.decodeSharedObjectId(this.helper.getInputsIndex(k)),L=this.helper.decodeInputU128(this.helper.getInputsIndex(4+k+t)),U=this.turbosSdk.math.sqrtPriceX64ToTickIndex(new Lm.BN(L.toString()));return{pool:M,a2b:x,nextTickIndex:U}}),s=o[0]||t===1?e.MoveCall.typeArguments[0]:e.MoveCall.typeArguments[1],c=t===1?e.MoveCall.typeArguments[4]:o[0]?e.MoveCall.typeArguments[1]:e.MoveCall.typeArguments[0],p=this.helper.decodeInputAddress(this.helper.getInputsIndex(6+2*t)),b=this.helper.decodeInputU64(this.helper.getInputsIndex(7+2*t)),S=this.helper.decodeInputBool(this.helper.getInputsIndex(5+2*t)),w=this.helper.decodeInputU64(this.helper.getInputsIndex(2+t)),D=this.helper.decodeInputU64(this.helper.getInputsIndex(3+t));return{txType:_t.TransactionType.Other,type:"Swap",intentionData:{routes:i,coinTypeA:s,coinTypeB:c,address:p,amountA:S?w:D,amountB:S?D:w,amountSpecifiedIsInput:S,slippage:"0.1",deadline:b}}}decodeAddLiquidity(){console.log(this.helper,"decodeAddLiquidity this.helper");let e=this.helper.decodeSharedObjectId(this.helper.getInputsIndex(0)),t=this.helper.decodeInputAddress(this.helper.getInputsIndex(12)),n=this.helper.decodeInputU64(this.helper.getInputsIndex(8)),o=this.helper.decodeInputU64(this.helper.getInputsIndex(9)),i=this.helper.decodeInputU32(this.helper.getInputsIndex(4)),s=this.helper.decodeInputBool(this.helper.getInputsIndex(5)),c=this.helper.decodeInputU32(this.helper.getInputsIndex(6)),p=this.helper.decodeInputBool(this.helper.getInputsIndex(7)),b=this.helper.decodeInputU64(this.helper.getInputsIndex(13));return{txType:_t.TransactionType.Other,type:"AddLiquidity",intentionData:{pool:e,slippage:30,address:t,amountA:n,amountB:o,tickLower:s?-i:i,tickUpper:p?-c:c,deadline:b}}}decodeIncreaseLiquidity(e){console.log(this.helper,"decodeIncreaseLiquidity this.helper");let t=this.helper.decodeSharedObjectId(this.helper.getInputsIndex(0)),n=this.helper.decodeOwnedObjectId(this.helper.getInputsIndex(4)),o=this.helper.decodeInputU64(this.helper.getInputsIndex(5)),i=this.helper.decodeInputU64(this.helper.getInputsIndex(6)),s=this.helper.decodeInputU64(this.helper.getInputsIndex(9));return{txType:_t.TransactionType.Other,type:"IncreaseLiquidity",intentionData:{pool:t,slippage:30,address:e,amountA:o,amountB:i,nft:n,deadline:s}}}decodeDecreaseLiquidity(e){console.log(this.helper,"decodeDecreaseLiquidity this.helper");let t=this.helper.decodeSharedObjectId(this.helper.getInputsIndex(0)),n=this.helper.decodeOwnedObjectId(this.helper.getInputsIndex(2)),o=this.helper.decodeInputU64(this.helper.getInputsIndex(3)),i=this.helper.decodeInputU64(this.helper.getInputsIndex(4)),s=this.helper.decodeInputU64(this.helper.getInputsIndex(5)),c=this.helper.decodeInputU64(this.helper.getInputsIndex(6));return{txType:_t.TransactionType.Other,type:"DecreaseLiquidity",intentionData:{pool:t,decreaseLiquidity:o,nft:n,amountA:i,amountB:s,slippage:10,address:e,deadline:c}}}decodeDecreaseLiquidityWithReturn(e){console.log(this.helper,"decodeDecreaseLiquidityWithReturn this.helper");let t=this.helper.decodeSharedObjectId(0),n=this.helper.decodeOwnedObjectId(2),o=this.helper.decodeInputU64(3),i=this.helper.decodeInputU64(4),s=this.helper.decodeInputU64(5),c=this.helper.decodeInputU64(6);return{txType:_t.TransactionType.Other,type:"DecreaseLiquidityWithReturn",intentionData:{pool:t,decreaseLiquidity:o,nft:n,amountA:i,amountB:s,slippage:10,address:e,deadline:c}}}decodeCollectFee(){console.log(this.helper,"decodeCollectFee this.helper");let e=this.helper.decodeSharedObjectId(this.helper.getInputsIndex(0)),t=this.helper.decodeOwnedObjectId(this.helper.getInputsIndex(2)),n=this.helper.decodeInputAddress(this.helper.getInputsIndex(5)),o=this.helper.decodeInputU64(this.helper.getInputsIndex(3)),i=this.helper.decodeInputU64(this.helper.getInputsIndex(4)),s=this.helper.decodeInputU64(this.helper.getInputsIndex(6));return{txType:_t.TransactionType.Other,type:"CollectFee",intentionData:{pool:e,address:n,collectAmountA:o,collectAmountB:i,nft:t,deadline:s}}}decodeCollectReward(){console.log(this.helper,"decodeCollectReward this.helper");let e=this.helper.decodeSharedObjectId(this.helper.getInputsIndex(0)),t=this.helper.decodeOwnedObjectId(this.helper.getInputsIndex(2)),n=this.helper.decodeInputAddress(this.helper.getInputsIndex(6)),o=[0,0,0];this.collectRewardHelper.forEach(s=>{let c=s.decodeInputU64(s.getInputsIndex(4)),p=s.decodeInputU64(s.getInputsIndex(5));o[c]=p});let i=this.helper.decodeInputU64(7);return{txType:_t.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(this.helper.getInputsIndex(0)),t=this.helper.decodeOwnedObjectId(this.helper.getInputsIndex(2));return{txType:_t.TransactionType.Other,type:"Burn",intentionData:{pool:e,nft:t}}}decodeRemoveLiquidity(e){console.log(this.helper,"decodeRemoveLiquidity this.helper");let t=30,n=this.decreaseLiquidityHelper.decodeSharedObjectId(this.decreaseLiquidityHelper.getInputsIndex(0)),o=this.decreaseLiquidityHelper.decodeOwnedObjectId(this.decreaseLiquidityHelper.getInputsIndex(2)),i=this.decreaseLiquidityHelper.decodeInputU64(this.decreaseLiquidityHelper.getInputsIndex(3)),s=this.decreaseLiquidityHelper.decodeInputU64(this.decreaseLiquidityHelper.getInputsIndex(4)),c=this.decreaseLiquidityHelper.decodeInputU64(this.decreaseLiquidityHelper.getInputsIndex(5)),p=this.decreaseLiquidityHelper.decodeInputU64(this.decreaseLiquidityHelper.getInputsIndex(6)),b=[0,0,0];this.collectRewardHelper.forEach(D=>{let x=D.decodeInputU64(D.getInputsIndex(4)),k=D.decodeInputU64(D.getInputsIndex(5));b[x]=k});let S=this.collectFeeHelper.decodeInputU64(this.collectFeeHelper.getInputsIndex(3))||0,w=this.collectFeeHelper.decodeInputU64(this.collectFeeHelper.getInputsIndex(4))||0;return{txType:_t.TransactionType.Other,type:"RemoveLiquidity",intentionData:{pool:n,decreaseLiquidity:i,nft:o,amountA:(s/(100-t)*100).toFixed(0),amountB:(c/(100-t)*100).toFixed(0),slippage:t,address:e,collectAmountA:S,collectAmountB:w,rewardAmounts:b,deadline:p}}}decodeRemoveLiquidityWithReturn(e){console.log(this.helper,"decodeRemoveLiquidityWithReturn this.helper");let t=this.decreaseLiquidityHelper.decodeSharedObjectId(0),n=this.decreaseLiquidityHelper.decodeOwnedObjectId(2),o=this.decreaseLiquidityHelper.decodeInputU64(3),i=this.decreaseLiquidityHelper.decodeInputU64(4),s=this.decreaseLiquidityHelper.decodeInputU64(5),c=this.decreaseLiquidityHelper.decodeInputU64(6),p=this.collectRewardHelper.map(w=>w.decodeInputU64(5)),b=this.collectFeeHelper.decodeInputU64(3)||0,S=this.collectFeeHelper.decodeInputU64(4)||0;return{txType:_t.TransactionType.Other,type:"removeLiquidityWithReturn",intentionData:{pool:t,decreaseLiquidity:o,nft:n,amountA:i,amountB:s,slippage:10,address:e,collectAmountA:b,collectAmountB:S,rewardAmounts:p,deadline:c}}}decodePrixClaim(){return{txType:_t.TransactionType.Other,type:"PrixClaim",intentionData:{}}}decodePrixJoin(){return{txType:_t.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:_t.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:_t.TransactionType.Other,type:"SwapExactQuoteForBase",intentionData:{poolId:e,amountIn:t,token1:n,token2:o}}}get helper(){let e=this.transactions.find(t=>{if(t.$kind==="MoveCall"){let n=`${t.MoveCall.package}::${t.MoveCall.module}::${t.MoveCall.function}`;return n!=="0x2::coin::zero"&&n!=="0x0000000000000000000000000000000000000000000000000000000000000002::coin::zero"}return!1});return new Me(e,this.txb)}get collectRewardHelper(){return this.transactions.filter(t=>t.$kind==="MoveCall"?`${t.MoveCall.package}::${t.MoveCall.module}::${t.MoveCall.function}`===`${this.config.PackageId}::position_manager::collect_reward`:!1).map(t=>new Me(t,this.txb))}get collectFeeHelper(){let e=this.transactions.find(t=>t.$kind==="MoveCall"?`${t.MoveCall.package}::${t.MoveCall.module}::${t.MoveCall.function}`===`${this.config.PackageId}::position_manager::collect`:!1);return new Me(e,this.txb)}get decreaseLiquidityHelper(){let e=this.transactions.find(t=>t.$kind==="MoveCall"?`${t.MoveCall.package}::${t.MoveCall.module}::${t.MoveCall.function}`===`${this.config.PackageId}::position_manager::decrease_liquidity`:!1);return new Me(e,this.txb)}get swapExactBaseForQuoteHelper(){let e=this.transactions.find(t=>t.$kind==="MoveCall"?`${t.MoveCall.package}::${t.MoveCall.module}::${t.MoveCall.function}`===`${Qt.PackageId}::clob_v2::swap_exact_base_for_quote`:!1);return new Me(e,this.txb)}get swapExactQuoteForBaseHelper(){let e=this.transactions.find(t=>t.$kind==="MoveCall"?`${t.MoveCall.package}::${t.MoveCall.module}::${t.MoveCall.function}`===`${Qt.PackageId}::clob_v2::swap_exact_quote_for_base`:!1);return new Me(e,this.txb)}},Me=class{constructor(e,t){this.moveCall=e;this.txb=t}get inputs(){return this.txb.getData().inputs}getInputsIndex(e){return this.moveCall.MoveCall.arguments[e].Input}decodeSharedObjectId(e){return this.inputs[e].Object?.SharedObject?.objectId||this.inputs[e].UnresolvedObject.objectId}decodeOwnedObjectId(e){return this.inputs[e].Object?.ImmOrOwnedObject?.objectId||this.inputs[e].UnresolvedObject.objectId}decodeInputU128(e){return Number(je.bcs.u128().parse(Uint8Array.from((0,Le.fromBase64)(this.inputs[e].Pure.bytes))))}decodeInputU64(e){return Number(je.bcs.u64().parse(Uint8Array.from((0,Le.fromBase64)(this.inputs[e].Pure.bytes))))}decodeInputU32(e){return Number(je.bcs.u32().parse(Uint8Array.from((0,Le.fromBase64)(this.inputs[e].Pure.bytes))))}decodeInputU8(e){return Number(je.bcs.u8().parse(Uint8Array.from((0,Le.fromBase64)(this.inputs[e].Pure.bytes))))}decodeInputAddress(e){return je.bcs.Address.parse(Uint8Array.from((0,Le.fromBase64)(this.inputs[e].Pure.bytes)))}decodeInputBool(e){return je.bcs.bool().parse(Uint8Array.from((0,Le.fromBase64)(this.inputs[e].Pure.bytes)))}shortTypeArg(e){return this.moveCall.MoveCall.typeArguments[e]}txArg(e){return this.moveCall.MoveCall.arguments[e]}};var jm=require("turbos-clmm-sdk");var Fi=class a extends I{constructor(t){super(t);this.data=t}txType;txSubType;async build(t){let n=new jm.TurbosSdk(t.network.replace("sui:",""),t.suiClient),{pool:o,address:i,amountA:s,amountB:c,slippage:p,tickLower:b,tickUpper:S,deadline:w,txb:D}=this.data;return n.pool.addLiquidity({pool:o,slippage:p,address:i,amountA:s,amountB:c,tickLower:b,tickUpper:S,deadline:w,txb:D})}static fromData(t){return new a(t)}};var Um=require("turbos-clmm-sdk");var Ki=class a extends I{constructor(t){super(t);this.data=t}txType;txSubType;async build(t){let n=new Um.TurbosSdk(t.network.replace("sui:",""),t.suiClient),{pool:o,nft:i,txb:s}=this.data;return n.position.burn({pool:o,nft:i,txb:s})}static fromData(t){return new a(t)}};var qm=require("turbos-clmm-sdk");var Vi=class a extends I{constructor(t){super(t);this.data=t}txType;txSubType;async build(t){let n=new qm.TurbosSdk(t.network.replace("sui:",""),t.suiClient),{pool:o,address:i,nft:s,collectAmountA:c,collectAmountB:p,deadline:b,txb:S}=this.data;return n.pool.collectFee({pool:o,address:i,collectAmountA:c,collectAmountB:p,nft:s,deadline:b,txb:S})}static fromData(t){return new a(t)}};var Fm=require("turbos-clmm-sdk");var $i=class a extends I{constructor(t){super(t);this.data=t}txType;txSubType;async build(t){let n=new Fm.TurbosSdk(t.network.replace("sui:",""),t.suiClient),{pool:o,address:i,nft:s,rewardAmounts:c,deadline:p,txb:b}=this.data;return n.pool.collectReward({pool:o,address:i,rewardAmounts:c,nft:s,deadline:p,txb:b})}static fromData(t){return new a(t)}};var Km=require("turbos-clmm-sdk");var Hi=class a extends I{constructor(t){super(t);this.data=t}txType;txSubType;async build(t){let n=new Km.TurbosSdk(t.network.replace("sui:",""),t.suiClient),{fee:o,address:i,tickLower:s,tickUpper:c,sqrtPrice:p,slippage:b,coinTypeA:S,coinTypeB:w,amountA:D,amountB:x,deadline:k,txb:M}=this.data;return n.pool.createPool({fee:o,amountA:D,amountB:x,address:i,tickLower:s,tickUpper:c,sqrtPrice:p,slippage:b,coinTypeA:S,coinTypeB:w,deadline:k,txb:M})}static fromData(t){return new a(t)}};var Vm=require("turbos-clmm-sdk");var Xi=class a extends I{constructor(t){super(t);this.data=t}txType;txSubType;async build(t){let n=new Vm.TurbosSdk(t.network.replace("sui:",""),t.suiClient),{pool:o,address:i,amountA:s,amountB:c,slippage:p,nft:b,decreaseLiquidity:S,deadline:w,txb:D}=this.data;return n.pool.decreaseLiquidity({pool:o,slippage:p,address:i,amountA:s,amountB:c,nft:b,decreaseLiquidity:S,deadline:w,txb:D})}static fromData(t){return new a(t)}};var $m=require("turbos-clmm-sdk");var zi=class a extends I{constructor(t){super(t);this.data=t}txType;txSubType;async build(t){let n=new $m.TurbosSdk(t.network.replace("sui:",""),t.suiClient),{pool:o,address:i,amountA:s,amountB:c,slippage:p,nft:b,decreaseLiquidity:S,deadline:w}=this.data,{txb:D,coinA:x,coinB:k}=await n.pool.decreaseLiquidityWithReturn({pool:o,slippage:p,address:i,amountA:s,amountB:c,nft:b,decreaseLiquidity:S,deadline:w});return D.transferObjects([x,k],this.data.address),D}static fromData(t){return new a(t)}};var Hm=require("turbos-clmm-sdk");var Gi=class a extends I{constructor(t){super(t);this.data=t}txType;txSubType;async build(t){let n=new Hm.TurbosSdk(t.network.replace("sui:",""),t.suiClient),{pool:o,address:i,amountA:s,amountB:c,slippage:p,nft:b,deadline:S,txb:w}=this.data;return n.pool.increaseLiquidity({pool:o,slippage:p,address:i,amountA:s,amountB:c,nft:b,deadline:S,txb:w})}static fromData(t){return new a(t)}};var Xm=require("@mysten/sui/transactions"),zm=require("@mysten/sui/utils");var Qi=class a extends I{constructor(t){super(t);this.data=t}txType;txSubType;async build(t){let n=new Xm.Transaction;return n.moveCall({target:`${Gt.PackageId}::claim::claim`,typeArguments:[Gt.turbosCoinType],arguments:[n.object(Gt.Claim),n.object(zm.SUI_CLOCK_OBJECT_ID)]}),n}static fromData(t){return new a(t)}};var Gm=require("@mysten/sui/transactions");var Yi=class a extends I{constructor(t){super(t);this.data=t}txType;txSubType;async build(t){let n=new Gm.Transaction;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 Qm=require("@mysten/sui/transactions"),Ym=require("turbos-clmm-sdk");var Ji=class a extends I{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 Qm.Transaction;return o=await n.pool.collectFee({txb:o,...this.data}),o=await n.pool.collectReward({txb:o,...this.data}),o=await n.pool.decreaseLiquidity({txb:o,...this.data}),o=await n.position.burn({txb:o,nft:this.data.nft,pool:this.data.pool}),o}static fromData(t){return new a(t)}};var Jm=require("turbos-clmm-sdk");var Zi=class a extends I{constructor(t){super(t);this.data=t}txType;txSubType;async build(t){let n=new Jm.TurbosSdk(t.network.replace("sui:",""),t.suiClient),{txb:o,coinA:i,coinB:s}=await n.pool.removeLiquidityWithReturn({...this.data});return o.transferObjects([i,s],this.data.address),o}static fromData(t){return new a(t)}};var Zm=require("turbos-clmm-sdk");var tr=class a extends I{constructor(t){super(t);this.data=t}txType;txSubType;async build(t){console.log(this.data,"this.data");let n=new Zm.TurbosSdk(t.network.replace("sui:",""),t.suiClient),{routes:o,coinTypeA:i,coinTypeB:s,address:c,amountA:p,amountB:b,slippage:S,amountSpecifiedIsInput:w,deadline:D,txb:x}=this.data;return n.trade.swap({routes:o,coinTypeA:i,coinTypeB:s,address:c,amountA:p,amountB:b,amountSpecifiedIsInput:w,slippage:S,deadline:D,txb:x})}static fromData(t){return new a(t)}};var ip=require("turbos-clmm-sdk");var zs=require("@mysten/sui/transactions"),Gs=require("@mysten/sui/utils");var tp=require("turbos-clmm-sdk");var $n=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 s=[],c=0;return o.sort((p,b)=>Number(b.balance)-Number(p.balance)).some(p=>c>=n?!0:(c+=Number(p.balance),s.push(p),!1)),s}splitAndMergeCoin(e,t,n){if(!e||e.length<1)return[void 0,void 0];if(this.isSuiCoinAddress(e[0].coinType)){let[s]=n.splitCoins(n.gas,[n.pure.u64(t)]);return[s,void 0]}let o=n.object(e[0].coinObjectId);e.length>1&&n.mergeCoins(o,e.slice(1).map(s=>n.object(s.coinObjectId)));let[i]=n.splitCoins(o,[n.pure.u64(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:`${Qt.PackageId}::custodian_v2::AccountCap`}});return t.data[0]?.data?(0,tp.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 ep=89,np=1e6,op=async a=>{let{token1:e,token2:t,poolId:n,amountIn:o,currentAddress:i,turbosSdk:s}=a,c=new zs.Transaction,p=new $n(s),b=await p.getCoinsData(i,t,o),[S,w]=p.splitAndMergeCoin(b,o,c);if(!S)throw new Error(`Not enough balance: ${t}`);let D=await p.IsAccountCap(i),x=D?c.object(D):p.createAccount(c),[k,M,L]=c.moveCall({typeArguments:[e,t],target:`${Qt.PackageId}::clob_v2::swap_exact_quote_for_base`,arguments:[c.object(String(n)),c.pure.u64(ep),x,c.pure.u64(o),c.object((0,Gs.normalizeSuiObjectId)("0x6")),S]});return w&&c.transferObjects([w],c.pure.address(i)),c.transferObjects([k],c.pure.address(i)),c.transferObjects([M],c.pure.address(i)),D||c.transferObjects([x],c.pure.address(i)),c.setSenderIfNotSet(i),c.setGasBudget(np),c},ap=async a=>{let{token1:e,token2:t,poolId:n,amountIn:o,currentAddress:i,turbosSdk:s}=a,c=new zs.Transaction,p=new $n(s),b=await p.getCoinsData(i,e,o),[S,w]=p.splitAndMergeCoin(b,o,c);if(!S)throw new Error(`Not enough balance: ${e}`);let D=await p.IsAccountCap(i),x=D?c.object(D):p.createAccount(c),k=p.zero(t,c),[M,L,U]=c.moveCall({typeArguments:[e,t],target:`${Qt.PackageId}::clob_v2::swap_exact_base_for_quote`,arguments:[c.object(String(n)),c.pure.u64(ep),x,c.pure.u64(o),S,k,c.object((0,Gs.normalizeSuiObjectId)("0x6"))]});return w&&c.transferObjects([w],c.pure.address(i)),c.transferObjects([M],c.pure.address(i)),c.transferObjects([L],c.pure.address(i)),D||c.transferObjects([x],c.pure.address(i)),c.setSenderIfNotSet(i),c.setGasBudget(np),c};var er=class a extends I{constructor(t){super(t);this.data=t}txType;txSubType;async build(t){let n=new ip.TurbosSdk(t.network.replace("sui:",""),t.suiClient);return await ap({...this.data,turbosSdk:n,currentAddress:t.account.address})}static fromData(t){return new a(t)}};var rp=require("turbos-clmm-sdk");var nr=class a extends I{constructor(t){super(t);this.data=t}txType;txSubType;async build(t){let n=new rp.TurbosSdk(t.network.replace("sui:",""),t.suiClient);return await op({...this.data,turbosSdk:n,currentAddress:t.account.address})}static fromData(t){return new a(t)}};var or=class{application="turbos";supportSDK="@mysten/sui";async deserialize(e){console.log(e,"input");let t=new cp.TurbosSdk(e.network.replace("sui:","")),n=await t.contract.getConfig(),{transaction:o,account:i}=e,c=await new qi(o,t,n).decode(i.address);return{txType:sp.TransactionType.Other,txSubType:c.type,intentionData:c.intentionData}}async build(e){let{suiClient:t,account:n,network:o}=e;console.log(e.intentionData,"intentionData");let i;switch(e.txSubType){case"CreatePool":i=Hi.fromData(e.intentionData);break;case"AddLiquidity":i=Fi.fromData(e.intentionData);break;case"IncreaseLiquidity":i=Gi.fromData(e.intentionData);break;case"DecreaseLiquidity":i=Xi.fromData(e.intentionData);break;case"DecreaseLiquidityWithReturn":i=zi.fromData(e.intentionData);break;case"RemoveLiquidity":i=Ji.fromData(e.intentionData);break;case"removeLiquidityWithReturn":i=Zi.fromData(e.intentionData);break;case"CollectFee":i=Vi.fromData(e.intentionData);break;case"CollectReward":i=$i.fromData(e.intentionData);break;case"Burn":i=Ki.fromData(e.intentionData);break;case"Swap":i=tr.fromData(e.intentionData);break;case"PrixJoin":i=Yi.fromData(e.intentionData);break;case"PrixClaim":i=Qi.fromData(e.intentionData);break;case"SwapExactBaseForQuote":i=er.fromData(e.intentionData);break;case"SwapExactQuoteForBase":i=nr.fromData(e.intentionData);break;default:throw new Error("not implemented")}return i.build({suiClient:t,account:n,network:o})}};var pp=require("@msafe/sui3-utils");var ar=require("@msafe/sui3-utils"),Qs=require("@mysten/sui.js/bcs"),Oe=require("@mysten/sui.js/utils");var Lf={packageId:"0x549e8b69270defbfafd4f94e17ec44cdbdd99820b33bda2278dea3b9a32d3f55",poolObjectId:"0x7fa2faa111b8c65bea48a23049bfd81ca8f971a262d981dcd9a17c3825cb5baf",metadataObjectId:"0x680cd26af32b2bde8d3361e804c53ec1d1cfe24c7f039eb7f549e8dfde389a60",systemStateObjectId:"0x0000000000000000000000000000000000000000000000000000000000000005",certType:"0x549e8b69270defbfafd4f94e17ec44cdbdd99820b33bda2278dea3b9a32d3f55::cert::CERT",gasBudget:5e7},At=Lf;var ir=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(`${At.packageId}::native_pool::stake`)}isUnStakeTransaction(){return!!this.getMoveCallTransaction(`${At.packageId}::native_pool::unstake`)}isClaimTicketTransaction(){return!!this.getMoveCallTransaction(`${At.packageId}::native_pool::burn_ticket`)}decodeStake(){let e=this.transactions[0].amounts[0].value.toNumber();return{txType:ar.TransactionType.Other,type:"Stake",intentionData:{amount:e}}}decodeUnStake(){let t=this.transactions.find(n=>n.kind==="SplitCoins").amounts[0].value.toNumber();return{txType:ar.TransactionType.Other,type:"UnStake",intentionData:{amount:t}}}decodeClaimTicket(){let e=this.helper.decodeOwnedObjectId(2);return console.log(e),{txType:ar.TransactionType.Other,type:"ClaimTicket",intentionData:{ticketId:e}}}get helper(){let e=this.transactions.find(t=>t.kind==="MoveCall"&&t.target.startsWith(At.packageId));return new Ys(e,this.txb)}},Ys=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,Oe.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 Qs.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,Oe.normalizeSuiAddress)(e.value.Object.ImmOrOwned.objectId)}return(0,Oe.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,Oe.normalizeSuiAddress)(e.value);if(!("Object"in e.value)||!("Shared"in e.value.Object))throw new Error("not Shared");return(0,Oe.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 Qs.bcs.de(t,new Uint8Array(n))}typeArg(e){return(0,Oe.normalizeStructTag)(this.moveCall.typeArguments[e])}txArg(e){return this.moveCall.arguments[e]}};var lp=require("@mysten/sui.js/transactions");var rr=class a extends jt{constructor(t){super(t);this.data=t}txType;txSubType;async build(t){console.log(t);let n=new lp.TransactionBlock,{ticketId:o}=this.data;return n.moveCall({target:`${At.packageId}::native_pool::burn_ticket`,arguments:[n.object(At.poolObjectId),n.object(At.systemStateObjectId),n.object(o)]}),n}static fromData(t){return new a(t)}};var up=require("@mysten/sui.js/transactions");var sr=class a extends jt{constructor(t){super(t);this.data=t}txType;txSubType;async build(t){console.log(t);let n=new up.TransactionBlock,{amount:o}=this.data,[i]=n.splitCoins(n.gas,[n.pure(o)]);return n.moveCall({target:`${At.packageId}::native_pool::stake`,arguments:[n.object(At.poolObjectId),n.object(At.metadataObjectId),n.object(At.systemStateObjectId),i]}),n}static fromData(t){return new a(t)}};var mp=require("@mysten/sui.js/transactions");var cr=class a extends jt{constructor(t){super(t);this.data=t}txType;txSubType;async build(t){console.log(t);let n=new mp.TransactionBlock,{amount:o}=this.data,i=(await t.suiClient.getAllCoins({owner:t.account.address,limit:100})).data,[s,...c]=i.filter(S=>S.coinType.split("::")[0]===At.certType.split("::")[0]),p=n.object(s.coinObjectId);c.length&&n.mergeCoins(p,c.map(S=>n.object(S.coinObjectId)));let b=n.splitCoins(n.object(s.coinObjectId),[n.pure(o)]);return n.moveCall({target:`${At.packageId}::native_pool::unstake`,arguments:[n.object(At.poolObjectId),n.object(At.metadataObjectId),n.object(At.systemStateObjectId),b]}),n}static fromData(t){return new a(t)}};var lr=class{application="volo";supportSDK="@mysten/sui.js";async deserialize(e){let{transactionBlock:t}=e,o=new ir(t).decode();return{txType:pp.TransactionType.Other,txSubType:o.type,intentionData:o.intentionData}}async build(e){let{suiClient:t,account:n}=e,o;switch(e.txSubType){case"Stake":o=sr.fromData(e.intentionData);break;case"UnStake":o=cr.fromData(e.intentionData);break;case"ClaimTicket":o=rr.fromData(e.intentionData);break;default:throw new Error("not implemented")}return o.build({suiClient:t,account:n})}};var xp=require("@msafe/sui3-utils");var Js=require("@cetusprotocol/common-sdk"),ce=require("@msafe/sui3-utils"),pn=require("@mysten/bcs"),dn=require("@mysten/sui/bcs");var ur=class{constructor(e,t){this.transaction=e;this.appContext=t}async 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();if(this.isAggregator7KSwapTx())return this.decodeAggregator7KSwapTx();throw new Error("Unknown transaction type")}decodeOpenPositionTx(){let e=this.getMoveCallCommand("open_position"),t=this.getMoveCallCommand("provide_liquidity_with_fixed_amount");return{txType:ce.TransactionType.Other,type:"OpenPosition",intentionData:{pool:this.getSharedObjectID(this.getInputIndex(e,1)),lowerTick:Number((0,Js.asIntN)(BigInt(this.getU32(this.getInputIndex(e,2)))).toString()),upperTick:Number((0,Js.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:ce.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:ce.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:ce.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:ce.TransactionType.Other,type:"CollectRewards",intentionData:{pool:e[0].pool,position:e[0].position,collectRewardTokens:e.map(t=>t.rewardCoinType)}}}decodeCollectFeeTx(){return{txType:ce.TransactionType.Other,type:"CollectFee",intentionData:this.getFeeCallData()}}decodeCollectRewardsAndFeeTx(){let e=this.getFeeCallData();return{txType:ce.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}async decodeAggregator7KSwapTx(){let{appContext:e}=this;return console.log("appContext",e),{txType:ce.TransactionType.Other,type:"Aggregator7KSwap",intentionData:{tokenIn:e.txParams.tokenIn,tokenOut:e.txParams.tokenOut,amountIn:String(e.txParams.amountIn),maxSlippage:String(e.txParams.maxSlippage)}}}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")}isAggregator7KSwapTx(){return!!this.commands.find(e=>e.$kind==="MoveCall"&&e.MoveCall.function.toLowerCase().includes("settle"))}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(dn.bcs.u32().parse(Uint8Array.from((0,pn.fromBase64)(this.inputs[e].Pure.bytes))))}getU64(e){return dn.bcs.u64().parse(Uint8Array.from((0,pn.fromBase64)(this.inputs[e].Pure.bytes)))}getU128(e){return dn.bcs.u128().parse(Uint8Array.from((0,pn.fromBase64)(this.inputs[e].Pure.bytes)))}getBoolean(e){return dn.bcs.bool().parse(Uint8Array.from((0,pn.fromBase64)(this.inputs[e].Pure.bytes)))}getAddress(e){return dn.bcs.Address.parse(Uint8Array.from((0,pn.fromBase64)(this.inputs[e].Pure.bytes)))}getTypeArguments(e){return e.MoveCall.typeArguments||[]}getInputIndex(e,t){return e.MoveCall.arguments[t].Input}};var yp=require("@msafe/sui3-utils");var mr=require("@bluefin-exchange/bluefin7k-aggregator-sdk"),oe=require("@firefly-exchange/library-sui"),gp=require("turbos-clmm-sdk");var fp=require("@firefly-exchange/library-sui"),hp=require("@firefly-exchange/library-sui/spot"),dp={rpc:"https://fullnode.mainnet.sui.io/",objects:{GlobalConfig:"0x03db251ba509a8d5d8777b6338836082335d93eecbdd09a11e190a1cff51c352",BasePackage:"0x3492c874c1e3b3e2984e8c41b589e642d4d0a5d6459e5a9cfc2d52fd7c89c267",CurrentPackage:"0x67b34b728c4e28e704dcfecf7c5cf55c7fc593b6c65c20d1836d97c209c1928a"}},ue=(a,e)=>{if(a!=="sui:mainnet")throw new Error("Bluefin spot protocol is only available on sui::mainnet");let t=new fp.SuiClient({url:dp.rpc});return new hp.OnChainCalls(t,dp.objects,{address:e.address,isUIWallet:!1})};var Rt=class{static async OpenPosition(e,t,n){let o=ue(n,t),i=await o.queryChain.getPool(e.pool),s=this.prototype.buildLiqInput(i,{...e,slippage:0});return await o.openPositionWithFixedAmount(i,e.lowerTick,e.upperTick,s,{returnTx:!0,sender:t.address})}static async provideLiquidity(e,t,n){let o=ue(n,t),i=await o.queryChain.getPool(e.pool),s=this.prototype.buildLiqInput(i,e);return await o.provideLiquidityWithFixedAmount(i,e.position,s,{returnTx:!0,sender:t.address})}static async removeLiquidity(e,t,n){let o=ue(n,t),i=await o.queryChain.getPool(e.pool);return await o.removeLiquidity(i,e.position,{liquidityAmount:new oe.BN(e.liquidity),tokenMaxA:new oe.BN(e.maxAmountTokenA),tokenMaxB:new oe.BN(e.maxAmountTokenB)},{returnTx:!0,sender:t.address})}static async closePosition(e,t,n){let o=ue(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=ue(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=ue(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=ue(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})}static async aggregator7KSwap(e,t,n){let o=ue(n,t),i=await(0,mr.getQuote)({tokenIn:e.tokenIn.address,tokenOut:e.tokenOut.address,amountIn:new gp.Decimal(e.amountIn).mul(10**e.tokenIn.decimals).toString()}),s=await(0,mr.buildTx)({quoteResponse:i,accountAddress:t.address,slippage:e.maxSlippage,commission:{partner:"0x956d6ea2da156a037952964badc51f997cc5581c86a0e05f74049e6effab9347",commissionBps:0}});return s.tx.setSender(t.address),s.tx}buildLiqInput(e,t){return{...oe.ClmmPoolUtil.estLiquidityAndCoinAmountFromOneAmounts(t.lowerTick,t.upperTick,new oe.BN(t.tokenAmount),t.isTokenAFixed,!0,0,new oe.BN(e.current_sqrt_price)),tokenMaxA:new oe.BN(t.maxAmountTokenA),tokenMaxB:new oe.BN(t.maxAmountTokenB)}}};var pr=class a extends I{constructor(t){super(t);this.data=t}txType=yp.TransactionType.Other;txSubType="Aggregator7KSwap";async build(t){let{account:n,network:o}=t;return console.log(this.data),Rt.aggregator7KSwap(this.data,n,o)}static fromData(t){return new a(t)}};var bp=require("@msafe/sui3-utils");var dr=class a extends I{constructor(t){super(t);this.data=t}txType=bp.TransactionType.Other;txSubType="ClosePosition";async build(t){let{account:n,network:o}=t;return console.log(this.data),Rt.closePosition(this.data,n,o)}static fromData(t){return new a(t)}};var Tp=require("@msafe/sui3-utils");var fr=class a extends I{constructor(t){super(t);this.data=t}txType=Tp.TransactionType.Other;txSubType="CollectFee";async build(t){let{account:n,network:o}=t;return console.log(this.data),Rt.collectFee(this.data,n,o)}static fromData(t){return new a(t)}};var Sp=require("@msafe/sui3-utils");var hr=class a extends I{constructor(t){super(t);this.data=t}txType=Sp.TransactionType.Other;txSubType="CollectRewards";async build(t){let{account:n,network:o}=t;return console.log(this.data),Rt.collectRewards(this.data,n,o)}static fromData(t){return new a(t)}};var Ip=require("@msafe/sui3-utils");var gr=class a extends I{constructor(t){super(t);this.data=t}txType=Ip.TransactionType.Other;txSubType="CollectRewardsAndFee";async build(t){let{account:n,network:o}=t;return console.log(this.data),Rt.collectRewardsAndFee(this.data,n,o)}static fromData(t){return new a(t)}};var wp=require("@msafe/sui3-utils");var yr=class a extends I{constructor(t){super(t);this.data=t}txType=wp.TransactionType.Other;txSubType="OpenPosition";async build(t){let{account:n,network:o}=t;return console.log(this.data),Rt.OpenPosition(this.data,n,o)}static fromData(t){return new a(t)}};var Cp=require("@msafe/sui3-utils");var br=class a extends I{constructor(t){super(t);this.data=t}txType=Cp.TransactionType.Other;txSubType="ProvideLiquidity";async build(t){let{account:n,network:o}=t;return console.log(this.data),Rt.provideLiquidity(this.data,n,o)}static fromData(t){return new a(t)}};var Dp=require("@msafe/sui3-utils");var Tr=class a extends I{constructor(t){super(t);this.data=t}txType=Dp.TransactionType.Other;txSubType="RemoveLiquidity";async build(t){let{account:n,network:o}=t;return console.log(this.data),Rt.removeLiquidity(this.data,n,o)}static fromData(t){return new a(t)}};var Sr=class{application="bluefin";supportSDK="@mysten/sui";async deserialize(e){console.log("Bluefin helper deserialize input: ",e);let{transaction:t,appContext:n}=e,i=await new ur(t,n).decode();return{txType:xp.TransactionType.Other,txSubType:i.type,intentionData:{appContext:e.appContext,...i.intentionData}}}async build(e){let{suiClient:t,account:n,network:o}=e;console.log(e.txSubType);let i;switch(e.txSubType){case"OpenPosition":i=yr.fromData(e.intentionData);break;case"ProvideLiquidity":i=br.fromData(e.intentionData);break;case"RemoveLiquidity":i=Tr.fromData(e.intentionData);break;case"ClosePosition":i=dr.fromData(e.intentionData);break;case"CollectFee":i=fr.fromData(e.intentionData);break;case"CollectRewards":i=hr.fromData(e.intentionData);break;case"CollectRewardsAndFee":i=gr.fromData(e.intentionData);break;case"Aggregator7KSwap":i=pr.fromData(e.intentionData);break;default:throw new Error("not implemented")}return i.build({suiClient:t,account:n,network:o})}};var kd=require("@msafe/sui3-utils");var qp=require("@mmt-finance/clmm-sdk"),Fp=require("@mysten/sui/transactions");var qe=require("@mmt-finance/clmm-sdk/dist/utils/math/tickMath"),Pp=Ft(require("bignumber.js")),R=Ft(vp());var Uf="0x0000000000000000000000000000000000000000000000000000000000000002::sui::SUI",Nt=a=>a!=="0x2::sui::SUI"?a:"0x0000000000000000000000000000000000000000000000000000000000000002::sui::SUI",qf=async({suiClient:a,address:e,type:t})=>{let n,o=[],i=0;do{try{let s=await a.getCoins({owner:e,coinType:t,cursor:n,limit:50});o=o.concat(s.data),n=s.nextCursor,(!s.hasNextPage||i===8)&&(n=null)}catch(s){console.log(s),n=null}i++}while(n!==null);return o},Ff=(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")},Kf=(a,e,t,n)=>{if(a===Uf){let[o]=n.splitCoins(n.gas,[n.pure.u64(t)]);return o}else{let o=Ff(t,e);o.length>1&&n.mergeCoins(n.object(o[0]),o.slice(1).map(s=>n.object(s)));let[i]=n.splitCoins(n.object(o[0]),[n.pure.u64(t)]);return i}};async function Ap(a,e,t,n,o){let i=await qf({suiClient:a.rpcClient,address:e,type:t});return Kf(Nt(t),i.map(c=>({balance:BigInt(c.balance),objectId:c.coinObjectId})),n,o)}var Ue=(a,e,t,n,o)=>{let i={objectId:n.poolId,tokenXType:n.tokenXType,tokenYType:n.tokenYType};n?.rewarders&&n?.rewarders.length>0&&a.Pool.collectAllRewards(o,i,n.rewarders.map(s=>({coin_type:s.coinType,flow_rate:s.flowRate,reward_amount:s.rewardAmount,rewards_allocated:s.rewardsAllocated,hasEnded:s.hasEnded})),t.objectId,e),a.Pool.collectFee(o,{objectId:n.poolId,tokenXType:n.tokenXType,tokenYType:n.tokenYType,isStable:n.isStable,tickSpacing:n.tickSpacing},t.objectId,e)};async function Mp({sdk:a,address:e,positionId:t,pool:n,txb:o,targetCoinType:i,slippage:s}){let c={objectId:n.poolId,tokenXType:n.tokenXType,tokenYType:n.tokenYType},p=n.rewarders.map(S=>S.coinType);p.length>0&&(console.log("claimRewardsAsTargetCoin input",{pool:c,positionId:t,rewarderCoinTypes:p,targetCoinType:i,slippage:s,toAddress:e}),await a.Pool.claimRewardsAs({txb:o,pool:c,positionId:t,rewarderCoinTypes:p,targetCoinType:i,slippage:s,toAddress:e}));let b=await a.Pool.getAllPools();return await a.Pool.claimFeeAs({txb:o,pool:c,positionId:t,targetCoinType:i,slippage:s,toAddress:e,pools:b}),o}function E(a,e,t){let n=a.toTwos(t).shrn(e);return n.imaskn(t-e+1),n.fromTwos(t-e)}function Vf(a){let e;return(a&1)!==0?e=new R.default("79232123823359799118286999567"):e=new R.default("79228162514264337593543950336"),(a&2)!==0&&(e=E(e.mul(new R.default("79236085330515764027303304731")),96,256)),(a&4)!==0&&(e=E(e.mul(new R.default("79244008939048815603706035061")),96,256)),(a&8)!==0&&(e=E(e.mul(new R.default("79259858533276714757314932305")),96,256)),(a&16)!==0&&(e=E(e.mul(new R.default("79291567232598584799939703904")),96,256)),(a&32)!==0&&(e=E(e.mul(new R.default("79355022692464371645785046466")),96,256)),(a&64)!==0&&(e=E(e.mul(new R.default("79482085999252804386437311141")),96,256)),(a&128)!==0&&(e=E(e.mul(new R.default("79736823300114093921829183326")),96,256)),(a&256)!==0&&(e=E(e.mul(new R.default("80248749790819932309965073892")),96,256)),(a&512)!==0&&(e=E(e.mul(new R.default("81282483887344747381513967011")),96,256)),(a&1024)!==0&&(e=E(e.mul(new R.default("83390072131320151908154831281")),96,256)),(a&2048)!==0&&(e=E(e.mul(new R.default("87770609709833776024991924138")),96,256)),(a&4096)!==0&&(e=E(e.mul(new R.default("97234110755111693312479820773")),96,256)),(a&8192)!==0&&(e=E(e.mul(new R.default("119332217159966728226237229890")),96,256)),(a&16384)!==0&&(e=E(e.mul(new R.default("179736315981702064433883588727")),96,256)),(a&32768)!==0&&(e=E(e.mul(new R.default("407748233172238350107850275304")),96,256)),(a&65536)!==0&&(e=E(e.mul(new R.default("2098478828474011932436660412517")),96,256)),(a&131072)!==0&&(e=E(e.mul(new R.default("55581415166113811149459800483533")),96,256)),(a&262144)!==0&&(e=E(e.mul(new R.default("38992368544603139932233054999993551")),96,256)),E(e,32,256)}function $f(a){let e=Math.abs(a),t;return(e&1)!==0?t=new R.default("18445821805675392311"):t=new R.default("18446744073709551616"),(e&2)!==0&&(t=E(t.mul(new R.default("18444899583751176498")),64,256)),(e&4)!==0&&(t=E(t.mul(new R.default("18443055278223354162")),64,256)),(e&8)!==0&&(t=E(t.mul(new R.default("18439367220385604838")),64,256)),(e&16)!==0&&(t=E(t.mul(new R.default("18431993317065449817")),64,256)),(e&32)!==0&&(t=E(t.mul(new R.default("18417254355718160513")),64,256)),(e&64)!==0&&(t=E(t.mul(new R.default("18387811781193591352")),64,256)),(e&128)!==0&&(t=E(t.mul(new R.default("18329067761203520168")),64,256)),(e&256)!==0&&(t=E(t.mul(new R.default("18212142134806087854")),64,256)),(e&512)!==0&&(t=E(t.mul(new R.default("17980523815641551639")),64,256)),(e&1024)!==0&&(t=E(t.mul(new R.default("17526086738831147013")),64,256)),(e&2048)!==0&&(t=E(t.mul(new R.default("16651378430235024244")),64,256)),(e&4096)!==0&&(t=E(t.mul(new R.default("15030750278693429944")),64,256)),(e&8192)!==0&&(t=E(t.mul(new R.default("12247334978882834399")),64,256)),(e&16384)!==0&&(t=E(t.mul(new R.default("8131365268884726200")),64,256)),(e&32768)!==0&&(t=E(t.mul(new R.default("3584323654723342297")),64,256)),(e&65536)!==0&&(t=E(t.mul(new R.default("696457651847595233")),64,256)),(e&131072)!==0&&(t=E(t.mul(new R.default("26294789957452057")),64,256)),(e&262144)!==0&&(t=E(t.mul(new R.default("37481735321082")),64,256)),t}var Op=(a,e,t)=>{let n=(0,qe.convertI32ToSigned)(t?a+a%(e??1):a-a%(e??1));return n>0?new R.default(Vf(n)):new R.default($f(n))};function Rp(a,e){if(!/^(\d+)(\.\d+)?$/.test(a))return BigInt(0);let[t,n=""]=a.split("."),o=(n+"0".repeat(e)).slice(0,e),s=(t+o).replace(/^0+/,"")||"0";return BigInt(s)}async function ae({address:a,coinType:e,coinAmount:t,coinDecimals:n,tx:o,mmt:i}){let s=Rp(t,n),c;return Number(t)?c=await Ap(i,a,Nt(e),s,o):[c]=o.moveCall({target:"0x2::coin::zero",typeArguments:[e],arguments:[]}),c}function Bp({mmt:a,tx:e,poolModel:t,selectedLowTick:n,selectedHighTick:o}){let i=Op((0,qe.convertI32ToSigned)(n),t.tickSpacing),s=Op((0,qe.convertI32ToSigned)(o),t.tickSpacing);return a.Position.openPosition(e,t,i.toString(),s.toString())}var Hf=(a,e)=>{let n=1e4-Math.floor(e*100);return a*BigInt(n)/BigInt(1e4)};function Ir(a,e,t){let n=Rp(a,e);return Number(a)===0?BigInt(0):Hf(n,t)}async function Fe({poolId:a,currentSqrtPrice:e,tokenX:t,tokenY:n,slippagePercentage:o,isTokenX:i,suiClient:s}){let p=(await s.getObject({id:a,options:{showContent:!0}}))?.data?.content?.fields?.sqrt_price??e,b=qe.TickMath.sqrtPriceX64ToPrice(new R.default(p?.toString()),t.decimals,n.decimals),S=i?(100-o)/100:(100+o)/100,w=qe.TickMath.priceToSqrtPriceX64(b.mul(S),t.decimals,n.decimals);return BigInt(w.toString())}var Ep=async(a,e,t,n,o,i,s,c,p,b)=>{let S=await ae({mmt:a,address:t,coinType:i.tokenX.coinType,coinAmount:n,coinDecimals:i.tokenX.decimals,tx:e}),w=await ae({mmt:a,address:t,coinType:i.tokenY.coinType,coinAmount:o,coinDecimals:i.tokenY.decimals,tx:e}),D={objectId:s,tokenXType:i.tokenXType,tokenYType:i.tokenYType,tickSpacing:i.tickSpacing},x=Bp({mmt:a,tx:e,poolModel:D,selectedLowTick:c,selectedHighTick:p}),k=Ir(n,i.tokenX.decimals,b),M=Ir(o,i.tokenY.decimals,b);a.Pool.addLiquidity(e,D,x,S,w,k,M,t),e.transferObjects([x],e.pure.address(t))},Np=async(a,e,t,n,o,i,s,c,p,b,S)=>{try{let w=await ae({mmt:a,address:n,coinType:i?s.tokenX.coinType:s.tokenY.coinType,coinAmount:o,coinDecimals:i?s.tokenX.decimals:s.tokenY.decimals,tx:e}),D={objectId:s.poolId,tokenXType:Nt(s.tokenX.coinType),tokenYType:Nt(s.tokenY.coinType),tickSpacing:s.tickSpacing},x=Bp({mmt:a,tx:e,poolModel:D,selectedLowTick:c,selectedHighTick:p}),k=await Fe({suiClient:t,poolId:s.poolId,currentSqrtPrice:s.currentSqrtPrice,tokenX:s.tokenX,tokenY:s.tokenY,slippagePercentage:b,isTokenX:i});await a.Pool.addLiquiditySingleSidedV2({txb:e,pool:D,position:x,inputCoin:w,isXtoY:i,limitSqrtPrice:k,slippagePercentage:S,transferToAddress:n,useMvr:!0}),e.transferObjects([x],e.pure.address(n))}catch(w){console.error(w)}},Wp=async(a,e,t,n,o,i,s,c)=>{let p=await ae({mmt:a,address:t,coinType:i.tokenX.coinType,coinAmount:n,coinDecimals:i.tokenX.decimals,tx:e}),b=await ae({mmt:a,address:t,coinType:i.tokenY.coinType,coinAmount:o,coinDecimals:i.tokenY.decimals,tx:e}),S={objectId:i.poolId,tokenXType:i.tokenXType,tokenYType:i.tokenYType,tickSpacing:i.tickSpacing},w=Ir(n,i.tokenX.decimals,c),D=Ir(o,i.tokenY.decimals,c);a.Pool.addLiquidity(e,S,s,p,b,w,D,t)},_p=async(a,e,t,n,o,i,s,c,p)=>{try{let b=await ae({mmt:a,address:t,coinType:o?i.tokenX.coinType:i.tokenY.coinType,coinAmount:n,coinDecimals:o?i.tokenX.decimals:i.tokenY.decimals,tx:e}),S={objectId:i.poolId,tokenXType:i.tokenX.coinType,tokenYType:i.tokenY.coinType,tickSpacing:i.tickSpacing},w=await Fe({suiClient:a.rpcClient,poolId:i.poolId,currentSqrtPrice:i.currentSqrtPrice,tokenX:i.tokenX,tokenY:i.tokenY,slippagePercentage:c,isTokenX:o});await a.Pool.addLiquiditySingleSidedV2({txb:e,pool:S,position:s,inputCoin:b,isXtoY:o,limitSqrtPrice:w,slippagePercentage:p,transferToAddress:t})}catch(b){throw console.error(b),b}},Lp=(a,e)=>BigInt(e===100?a:new Pp.default(a).multipliedBy(e/100).toFixed(0)),jp=async(a,e,t,n,o,i)=>{let s=Lp(t.liquidity,o),c=n.tokenX.coinType,p=n.tokenY.coinType,b={objectId:n?.poolId,tokenXType:c,tokenYType:p};a.Pool.removeLiquidity(i,b,t.objectId,s,BigInt(0),BigInt(0),e),Ue(a,e,t,n,i),o===100&&a.Position.closePosition(i,t.objectId)},Up=async({sdk:a,address:e,position:t,pool:n,withdrawPercentage:o,txb:i,targetCoinType:s,slippage:c})=>{let p=Lp(t.liquidity,o),b=Nt(n.tokenX.coinType),S=Nt(n.tokenY.coinType),w=Nt(s)===S,D={objectId:n?.poolId,tokenXType:b,tokenYType:S},{removeLpCoinA:x,removeLpCoinB:k}=a.Pool.removeLiquidity(i,D,t.objectId,p,BigInt(0),BigInt(0)),M=await Fe({suiClient:a.rpcClient,poolId:n.poolId,currentSqrtPrice:n.currentSqrtPrice,tokenX:n.tokenX,tokenY:n.tokenY,isTokenX:w,slippagePercentage:c}),L=w?x:k,U=i.moveCall({target:"0x2::coin::value",arguments:[L],typeArguments:[w?b:S]});i.transferObjects([w?k:x],e),a.Pool.swapV2({txb:i,transferToAddress:e,pool:D,limitSqrtPrice:M,amount:U,inputCoin:L,isXtoY:w}),Ue(a,e,t,n,i),o===100&&a.Position.closePosition(i,t.objectId)};var wr=class a extends I{constructor(t){super(t);this.data=t}txType;txSubType;async build(){let t=qp.MmtSDK.NEW({network:"mainnet"}),{params:n}=this.data,{address:o,amountA:i,amountB:s,pool:c,selectedLowTick:p,selectedHighTick:b,slippage:S}=n,w=new Fp.Transaction;return await Ep(t,w,o,i,s,c,c.poolId,p,b,S),w}static fromData(t){return new a(t)}};var Kp=require("@mmt-finance/clmm-sdk"),Vp=require("@mysten/sui/transactions");var Cr=class a extends I{constructor(t){super(t);this.data=t}txType;txSubType;async build(){let t=Kp.MmtSDK.NEW({network:"mainnet"}),{params:n}=this.data,{address:o,amount:i,isTokenX:s,pool:c,selectedLowTick:p,selectedHighTick:b,swapSlippage:S,addLiquiditySlippage:w}=n,D=new Vp.Transaction;return await Np(t,D,t.rpcClient,o,i,s,c,p,b,S,w),D}static fromData(t){return new a(t)}};var Yp=require("@mmt-finance/clmm-sdk"),Jp=require("@mmt-finance/ve-sdk-v1"),Zp=require("@mysten/sui/transactions");var fn="0x35169bc93e1fddfcf3a82a9eae726d349689ed59e4b065369af8789fe59f8608::mmt::MMT";var Hn=async a=>{let e=await a.getSyncEpochInfo();if(!e)throw new Error("Failed to sync epoch");return e},$p=async(a,e,t,n,o,i,s,c)=>{let p=Number(n);if(!n||Number.isNaN(p)||p<=0)throw new Error(`Bond Failed: Invalid amount: ${n}. Amount must be greater than 0`);if(!i&&!s)throw new Error("Bond Failed: Failed to calculate unbond date");if(typeof s!="number"&&!i)throw new Error("Bond Failed: Invalid unbond date");let b=await ae({mmt:a,tx:c,address:o,coinType:t.coinType,coinAmount:n,coinDecimals:t.decimals});if(!b)throw new Error(`Bond Failed: Failed to get coin object for ${t.coinType}, amount: ${n}`);let S=await Hn(e);await e.syncOrAdvanceEpoch(c,S.currentEpoch,S.syncedEpoch);let w=c.getData().commands.length;i?await e.createMaxBond(c,b,o):await e.createBond(c,b,BigInt(s),o);let x=c.getData().commands.length;if(x===0)throw new Error(`Bond Failed: Transaction has no commands. enableAutoMaxBond: ${i}, unbondAt: ${s}, amount: ${n}`);if(x===w)throw new Error(`Bond Failed: No new commands were added by bond operation. Commands before: ${w}, after: ${x}`)},Hp=async(a,e,t,n,o,i,s,c)=>{let p=await Hn(a);if(await a.syncOrAdvanceEpoch(c,p.currentEpoch,p.syncedEpoch),await a.claimReward(c,t,e),o)i||await a.setNormal(c,t);else if(i)await a.setMaxBond(c,t);else{if(typeof s!="number")throw new Error("Extend Failed: Failed to calculate unbond date");if(s<n)throw new Error("Extend Failed: New duration cannot be less than current duration");await a.extend(c,t,s)}},Xp=async(a,e,t,n,o)=>{let i=await Hn(a);await a.syncOrAdvanceEpoch(o,i.currentEpoch,i.syncedEpoch),await a.claimReward(o,t,e),await n.reduce(async(s,c)=>{await s,await a.claimReward(o,c,e),await a.merge(o,t,c)},Promise.resolve())},zp=async(a,e,t,n)=>{let o=await Hn(a);await a.syncOrAdvanceEpoch(n,o.currentEpoch,o.syncedEpoch),await a.claimReward(n,t,e),await a.unbond(n,t,e)},Gp=async(a,e,t,n)=>{if(t.length>0&&t.some(o=>o.userRewardAmount>0)){let o=await Hn(a);await a.syncOrAdvanceEpoch(n,o.currentEpoch,o.syncedEpoch),await t.reduce(async(i,s)=>{await i,s.userRewardAmount>0&&await a.claimReward(n,s.veId,e)},Promise.resolve())}},Qp=async(a,e,t,n,o,i,s,c,p)=>{let b=Nt(i),S=[];for(let q of n)if(q.userRewardAmount>0){let Mt=await e.buildClaimRewardCoin(o,q.veId);S.push(Mt)}let w=[];for(let q of S)Array.isArray(q)?w.push(...q):w.push(q);if(w.length===0)return;if(i===Nt(fn)){o.transferObjects(w,o.pure.address(t));return}let D=c?.[i]?.[fn];if(!D||D.length===0)throw new Error(`No swap route found from ${fn} to ${i}`);let[x,...k]=w;k.length>0&&o.mergeCoins(x,k);let M=x,L=o.moveCall({target:"0x2::coin::value",arguments:[M],typeArguments:[fn]}),U=Nt(fn);for(let q=0;q<D.length;q++){let Mt=D[q],W=p.find(H=>H.poolId===Mt);if(!W)throw new Error(`Pool ${Mt} not found`);let Bt=Nt(W.tokenXType||W.tokenX?.coinType||"")===U,Ve={objectId:W.poolId,tokenXType:W.tokenXType||W.tokenX?.coinType||"",tokenYType:W.tokenYType||W.tokenY?.coinType||""},Xn=await Fe({suiClient:a.rpcClient,poolId:W.poolId,currentSqrtPrice:W.currentSqrtPrice,tokenX:W.tokenX,tokenY:W.tokenY,slippagePercentage:s,isTokenX:Bt}),{outputCoin:zn,leftoverCoin:hn}=a.Pool.swapV2({txb:o,pool:Ve,amount:L,inputCoin:M,isXtoY:Bt,limitSqrtPrice:Xn});if(o.transferObjects([hn],o.pure.address(t)),M=zn,U=Bt?Nt(W.tokenYType||W.tokenY?.coinType||""):Nt(W.tokenXType||W.tokenX?.coinType||""),U===i){o.transferObjects([M],o.pure.address(t));return}L=o.moveCall({target:"0x2::coin::value",arguments:[M],typeArguments:[U]})}o.transferObjects([M],o.pure.address(t))};var Dr=class a extends I{constructor(t){super(t);this.data=t}txType;txSubType;async build(t){let n=Yp.MmtSDK.NEW({network:"mainnet"}),o=new Jp.VeMMT(t.suiClient,"mainnet"),{params:i}=this.data,{address:s,positions:c,pools:p,veMMTs:b}=i,S=new Zp.Transaction;for(let w of c){let D=p.find(x=>x.poolId===w.poolId);D&&Ue(n,s,w,D,S)}return await Gp(o,s,b,S),S}static fromData(t){return new a(t)}};var td=require("@mmt-finance/clmm-sdk"),ed=require("@mmt-finance/ve-sdk-v1"),nd=require("@mysten/sui/transactions");var xr=class a extends I{constructor(t){super(t);this.data=t}txType;txSubType;async build(t){let n=td.MmtSDK.NEW({network:"mainnet"}),o=new ed.VeMMT(t.suiClient,"mainnet"),{params:i}=this.data,{claimVeMMTParams:s}=i,{address:c,veMMTs:p,targetCoinType:b,slippage:S,claimRoutes:w,pools:D}=s,x=new nd.Transaction;return await Promise.all(i.claimParams.map(k=>Mp({...k,sdk:n,txb:x}))),await Qp(n,o,c,p,x,b,S,w,D),x}static fromData(t){return new a(t)}};var od=require("@mmt-finance/clmm-sdk"),ad=require("@mysten/sui/transactions");var kr=class a extends I{constructor(t){super(t);this.data=t}txType;txSubType;async build(){let t=od.MmtSDK.NEW({network:"mainnet"}),{params:n}=this.data,{address:o,position:i,pool:s}=n,c=new ad.Transaction;return Ue(t,o,i,s,c),c}static fromData(t){return new a(t)}};var id=require("@mmt-finance/clmm-sdk"),rd=require("@mysten/sui/transactions");var vr=class a extends I{constructor(t){super(t);this.data=t}txType;txSubType;async build(){let t=id.MmtSDK.NEW({network:"mainnet"}),{params:n}=this.data,{address:o,amountA:i,amountB:s,pool:c,positionObjectId:p,slippage:b}=n,S=new rd.Transaction;return await Wp(t,S,o,i,s,c,p,b),S}static fromData(t){return new a(t)}};var sd=require("@mmt-finance/clmm-sdk"),cd=require("@mysten/sui/transactions");var Ar=class a extends I{constructor(t){super(t);this.data=t}txType;txSubType;async build(){let t=sd.MmtSDK.NEW({network:"mainnet"}),{params:n}=this.data,{address:o,amount:i,isTokenX:s,pool:c,positionObjectId:p,swapSlippage:b,addLiquiditySlippage:S}=n,w=new cd.Transaction;return await _p(t,w,o,i,s,c,p,b,S),w}static fromData(t){return new a(t)}};var ld=require("@mmt-finance/clmm-sdk"),ud=require("@mysten/sui/transactions");var Mr=class a extends I{constructor(t){super(t);this.data=t}txType;txSubType;async build(){let t=ld.MmtSDK.NEW({network:"mainnet"}),{params:n}=this.data,{pool:o,position:i,address:s,withdrawPercentage:c,zapOutOn:p,targetCoinType:b,slippage:S}=n,w=new ud.Transaction;return p?await Up({sdk:t,address:s,position:i,pool:o,withdrawPercentage:c,txb:w,targetCoinType:b,slippage:S}):await jp(t,s,i,o,c,w),w}static fromData(t){return new a(t)}};var ec=require("@mysten/sui/transactions"),nc=require("@suilend/springsui-sdk"),tc={id:"0x0431232199873db77a92aa645cd43521437e9cc5c6fff07fd03edb88afe0b25a",type:"0x2b6602099970374cf58a2a1b9d96f005fccceb81e92eb059873baf420eb6c717::x_sui::X_SUI",weightHookId:"0x9e35c13dbb0bc437e8ad5a95ec463622f58763e060552ae8d100db77f4904601"},md=async(a,e,t)=>{let n=await nc.LstClient.initialize(a,tc),o=new ec.Transaction,[i]=o.splitCoins(o.gas,[BigInt(t)]),s=n.mint(o,i);return o.transferObjects([s],e),o},pd=async(a,e,t)=>{let n=await nc.LstClient.initialize(a,tc),o=await a.getCoins({owner:e,coinType:tc.type,limit:1e3});if(o.data.length===0)throw new Error("No lst coins found");let i=new ec.Transaction,s=o.data[0];o.data.length>1&&i.mergeCoins(s.coinObjectId,o.data.slice(1).map(b=>b.coinObjectId));let[c]=i.splitCoins(s.coinObjectId,[BigInt(t)]),p=n.redeem(i,c);return i.transferObjects([p],e),i};var Or=class a extends I{constructor(t){super(t);this.data=t}txType;txSubType;async build(t){let{params:n}=this.data,{address:o,amount:i}=n;return await md(t.suiClient,o,i)}static fromData(t){return new a(t)}};var hd=require("@mmt-finance/clmm-sdk"),gd=require("@mysten/sui/transactions");var dd=require("@mmt-finance/clmm-sdk/dist/utils/poolUtils");var fd=async(a,e,t,n,o,i,s)=>{let c=await ae({mmt:a,tx:i,address:o,coinType:t.coinType,coinAmount:n,coinDecimals:t.decimals}),p=i.moveCall({target:"0x2::coin::value",typeArguments:[t.coinType],arguments:[c]}),b=t.coinType;for(let S=0;S<e.length;S+=1){let{poolId:w,tokenX:D,tokenY:x,isStable:k,currentSqrtPrice:M}=e[S],{id:L,isReverse:U}=dd.mappedMmtV3Pool[w]||{id:w,isReverse:!1},q=Nt(D.coinType)===Nt(b);q=U?!q:q;let Mt=U?x.coinType:D.coinType,W=U?D.coinType:x.coinType,Ke=await Fe({poolId:L,tokenX:D,tokenY:x,slippagePercentage:s,isTokenX:q,suiClient:a.rpcClient,currentSqrtPrice:M}),Bt=a.Pool.swap(i,{objectId:L,tokenXType:Mt,tokenYType:W,isStable:k},p,c,q,void 0,Ke,!1);i.transferObjects([c],i.pure.address(o)),c=Bt,b=q?W:Mt,p=i.moveCall({target:"0x2::coin::value",typeArguments:[b],arguments:[c]})}i.transferObjects([c],i.pure.address(o))};var Pr=class a extends I{constructor(t){super(t);this.data=t}txType;txSubType;async build(){let t=hd.MmtSDK.NEW({network:"mainnet"}),{params:n}=this.data,{route:o,tokenIn:i,amountIn:s,address:c,slippage:p}=n,b=new gd.Transaction;return await fd(t,o,i,s,c,b,p),b}static fromData(t){return new a(t)}};var Rr=class a extends I{constructor(t){super(t);this.data=t}txType;txSubType;async build(t){let{params:n}=this.data,{address:o,amount:i}=n;return await pd(t.suiClient,o,i)}static fromData(t){return new a(t)}};var yd=require("@mmt-finance/clmm-sdk"),bd=require("@mmt-finance/ve-sdk-v1"),Td=require("@mysten/sui/transactions");var Br=class a extends I{constructor(t){super(t);this.data=t}txType;txSubType;async build(t){let n=yd.MmtSDK.NEW({network:"mainnet"}),o=new bd.VeMMT(t.suiClient,"mainnet"),{params:i}=this.data,{token:s,amount:c,address:p,enableAutoMaxBond:b,unbondAt:S}=i,w=new Td.Transaction;return await $p(n,o,s,c,p,b,S,w),w}static fromData(t){return new a(t)}};var Sd=require("@mmt-finance/ve-sdk-v1"),Id=require("@mysten/sui/transactions");var Er=class a extends I{constructor(t){super(t);this.data=t}txType;txSubType;async build(t){let n=new Sd.VeMMT(t.suiClient,"mainnet"),{params:o}=this.data,{address:i,veId:s,currentUnbondAt:c,isCurrentlyMaxBond:p,enableAutoMaxBond:b,unbondAt:S}=o,w=new Id.Transaction;return await Hp(n,i,s,c,p,b,S,w),w}static fromData(t){return new a(t)}};var wd=require("@mmt-finance/ve-sdk-v1"),Cd=require("@mysten/sui/transactions");var Nr=class a extends I{constructor(t){super(t);this.data=t}txType;txSubType;async build(t){let n=new wd.VeMMT(t.suiClient,"mainnet"),{params:o}=this.data,{address:i,veId:s,selectedVeMMTIds:c}=o,p=new Cd.Transaction;return await Xp(n,i,s,c,p),p}static fromData(t){return new a(t)}};var Dd=require("@mmt-finance/ve-sdk-v1"),xd=require("@mysten/sui/transactions");var Wr=class a extends I{constructor(t){super(t);this.data=t}txType;txSubType;async build(t){let n=new Dd.VeMMT(t.suiClient,"mainnet"),{params:o}=this.data,{address:i,veId:s}=o,c=new xd.Transaction;return await zp(n,i,s,c),c}static fromData(t){return new a(t)}};var _r=class{application="mmt-dex";supportSDK="@mysten/sui";async deserialize(e){let{appContext:t}=e;return{txType:kd.TransactionType.Other,txSubType:t.action,intentionData:t}}async build(e){let t;switch(e.txSubType){case"Swap":t=Pr.fromData(e.intentionData);break;case"AddLiquidity":t=wr.fromData(e.intentionData);break;case"AddLiquiditySingleSide":t=Cr.fromData(e.intentionData);break;case"ClaimRewards":t=kr.fromData(e.intentionData);break;case"ClaimAllRewards":t=Dr.fromData(e.intentionData);break;case"ClaimRewardsAs":t=xr.fromData(e.intentionData);break;case"RemoveLiquidity":t=Mr.fromData(e.intentionData);break;case"StakeXSui":t=Or.fromData(e.intentionData);break;case"UnstakeXSui":t=Rr.fromData(e.intentionData);break;case"ManageLiquidity":t=vr.fromData(e.intentionData);break;case"ManageLiquiditySingleSide":t=Ar.fromData(e.intentionData);break;case"Bond":t=Br.fromData(e.intentionData);break;case"Extend":t=Er.fromData(e.intentionData);break;case"Merge":t=Nr.fromData(e.intentionData);break;case"Unbond":t=Wr.fromData(e.intentionData);break;default:throw new Error(`not implemented ${e.txSubType}`)}return t.build({suiClient:e.suiClient})}};var oc=require("@msafe/sui3-utils");var vd=require("@mysten/sui/transactions"),Ad=require("@nemoprotocol/vaults-sdk");var Lr=class a extends I{constructor(t){super(t);this.data=t}txType;txSubType;async build(t){let{suiClient:n,account:o}=t,i=Ad.Vaults.createSDK({client:n}),s=new vd.Transaction;return await i.deposit(this.data,o.address,s),s}static fromData(t){return new a(t)}};var Md=require("@mysten/sui/transactions"),Od=require("@nemoprotocol/vaults-sdk");var jr=class a extends I{constructor(t){super(t);this.data=t}txType;txSubType;async build(t){let{suiClient:n,account:o}=t,i=Od.Vaults.createSDK({client:n}),s=new Md.Transaction;return await i.withdraw(this.data,o.address,s),s}static fromData(t){return new a(t)}};var Ur=class{application="nemo";supportSDK="@mysten/sui";async deserialize(e){let t=e.transaction.blockData.transactions.find(o=>o.kind==="MoveCall"&&o.target.toString().toLowerCase().includes("deposit::deposit_non_entry")),n=e.transaction.blockData.transactions.find(o=>o.kind==="MoveCall"&&o.target.toString().toLowerCase().includes("withdraw::withdraw"));if(t)return{txType:oc.TransactionType.Other,txSubType:"VaultDeposit",intentionData:e.appContext};if(n)return{txType:oc.TransactionType.Other,txSubType:"VaultWithdraw",intentionData:e.appContext}}async build(e){let{suiClient:t,account:n}=e;console.log(e.txSubType);let o;switch(e.txSubType){case"VaultDeposit":o=Lr.fromData(e.intentionData);break;case"VaultWithdraw":o=jr.fromData(e.intentionData);break;default:throw new Error("not implemented")}return o.build({suiClient:t,account:n})}};var Xf=Wa.fromHelpers([new Ia,new Pa,new ba,new Ra,new Qo,new or,new _r,new yi,new lr,new wo,new vi,new Wi,new no,new Sr,new Ui,new Ur]);
2
2
  //# sourceMappingURL=index.js.map