@msafe/sui-app-store 0.0.340 → 0.0.342
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 +1 -1
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +1 -1
- package/dist/index.mjs.map +1 -1
- package/package.json +1 -1
package/dist/index.js
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
"use strict";var jd=Object.create;var no=Object.defineProperty;var Ud=Object.getOwnPropertyDescriptor;var qd=Object.getOwnPropertyNames;var Fd=Object.getPrototypeOf,Kd=Object.prototype.hasOwnProperty;var Vd=(a,e)=>()=>(e||a((e={exports:{}}).exports,e),e.exports),hs=(a,e)=>{for(var t in e)no(a,t,{get:e[t],enumerable:!0})},kc=(a,e,t,n)=>{if(e&&typeof e=="object"||typeof e=="function")for(let o of qd(e))!Kd.call(a,o)&&o!==t&&no(a,o,{get:()=>e[o],enumerable:!(n=Ud(e,o))||n.enumerable});return a};var Mt=(a,e,t)=>(t=a!=null?jd(Fd(a)):{},kc(e||!a||!a.__esModule?no(t,"default",{value:a,enumerable:!0}):t,a)),$d=a=>kc(no({},"__esModule",{value:!0}),a);var jm=Vd((Lm,ic)=>{"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,p){if(typeof r=="number")return this._initNumber(r,u,p);if(typeof r=="object")return this._initArray(r,u,p);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,p):(this._parseBase(r,u,d),p==="le"&&this._initArray(this.toArray(),u,p)))},o.prototype._initNumber=function(r,u,p){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),p==="le"&&this._initArray(this.toArray(),u,p)},o.prototype._initArray=function(r,u,p){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(p==="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(p==="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 p=s(y,u);return u-1>=r&&(p|=s(y,u-1)<<4),p}o.prototype._parseHex=function(r,u,p){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(p==="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 m(y,r,u,p){for(var d=0,h=0,T=Math.min(y.length,u),C=r;C<T;C++){var f=y.charCodeAt(C)-48;d*=p,f>=49?h=f-49+10:f>=17?h=f-17+10:h=f,t(f>=0&&h<p,"Invalid character"),d+=h}return d}o.prototype._parseBase=function(r,u,p){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-p,C=T%d,f=Math.min(T,T-C)+p,l=0,g=p;g<f;g+=d)l=m(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=m(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 I=["","0","00","000","0000","00000","000000","0000000","00000000","000000000","0000000000","00000000000","000000000000","0000000000000","00000000000000","000000000000000","0000000000000000","00000000000000000","000000000000000000","0000000000000000000","00000000000000000000","000000000000000000000","0000000000000000000000","00000000000000000000000","000000000000000000000000","0000000000000000000000000"],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 p;if(r===16||r==="hex"){p="";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?p=I[6-f.length]+f+p:p=f+p}for(h!==0&&(p=h.toString(16)+p);p.length%u!==0;)p="0"+p;return this.negative!==0&&(p="-"+p),p}if(r===(r|0)&&r>=2&&r<=36){var l=x[r],g=D[r];p="";var v=this.clone();for(v.negative=0;!v.isZero();){var O=v.modrn(g).toString(r);v=v.idivn(g),v.isZero()?p=O+p:p=I[l-O.length]+O+p}for(this.isZero()&&(p="0"+p);p.length%u!==0;)p="0"+p;return this.negative!==0&&(p="-"+p),p}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,p){this._strip();var d=this.byteLength(),h=p||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 p=0,d=0,h=0,T=0;h<this.length;h++){var C=this.words[h]<<T|d;r[p++]=C&255,p<r.length&&(r[p++]=C>>8&255),p<r.length&&(r[p++]=C>>16&255),T===6?(p<r.length&&(r[p++]=C>>24&255),d=0,T=0):(d=C>>>24,T+=2)}if(p<r.length)for(r[p++]=d;p<r.length;)r[p++]=0},o.prototype._toArrayLikeBE=function(r,u){for(var p=r.length-1,d=0,h=0,T=0;h<this.length;h++){var C=this.words[h]<<T|d;r[p--]=C&255,p>=0&&(r[p--]=C>>8&255),p>=0&&(r[p--]=C>>16&255),T===6?(p>=0&&(r[p--]=C>>24&255),d=0,T=0):(d=C>>>24,T+=2)}if(p>=0)for(r[p--]=d;p>=0;)r[p--]=0},Math.clz32?o.prototype._countBits=function(r){return 32-Math.clz32(r)}:o.prototype._countBits=function(r){var u=r,p=0;return u>=4096&&(p+=13,u>>>=13),u>=64&&(p+=7,u>>>=7),u>=8&&(p+=4,u>>>=4),u>=2&&(p+=2,u>>>=2),p+u},o.prototype._zeroBits=function(r){if(r===0)return 26;var u=r,p=0;return(u&8191)===0&&(p+=13,u>>>=13),(u&127)===0&&(p+=7,u>>>=7),(u&15)===0&&(p+=4,u>>>=4),(u&3)===0&&(p+=2,u>>>=2),(u&1)===0&&p++,p},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 p=u/26|0,d=u%26;r[u]=y.words[p]>>>d&1}return r}o.prototype.zeroBits=function(){if(this.isZero())return 0;for(var r=0,u=0;u<this.length;u++){var p=this._zeroBits(this.words[u]);if(r+=p,p!==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 p=0;p<u.length;p++)this.words[p]=this.words[p]&r.words[p];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,p;this.length>r.length?(u=this,p=r):(u=r,p=this);for(var d=0;d<p.length;d++)this.words[d]=u.words[d]^p.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,p=r%26;this._expand(u),p>0&&u--;for(var d=0;d<u;d++)this.words[d]=~this.words[d]&67108863;return p>0&&(this.words[d]=~this.words[d]&67108863>>26-p),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 p=r/26|0,d=r%26;return this._expand(p+1),u?this.words[p]=this.words[p]|1<<d:this.words[p]=this.words[p]&~(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 p,d;this.length>r.length?(p=this,d=r):(p=r,d=this);for(var h=0,T=0;T<d.length;T++)u=(p.words[T]|0)+(d.words[T]|0)+h,this.words[T]=u&67108863,h=u>>>26;for(;h!==0&&T<p.length;T++)u=(p.words[T]|0)+h,this.words[T]=u&67108863,h=u>>>26;if(this.length=p.length,h!==0)this.words[this.length]=h,this.length++;else if(p!==this)for(;T<p.length;T++)this.words[T]=p.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 p=this.cmp(r);if(p===0)return this.negative=0,this.length=1,this.words[0]=0,this;var d,h;p>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 p=y.length+r.length|0;u.length=p,p=p-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<p;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,p){var d=r.words,h=u.words,T=p.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,fe=d[2]|0,K=fe&8191,$=fe>>>13,lc=d[3]|0,z=lc&8191,Q=lc>>>13,uc=d[4]|0,J=uc&8191,Y=uc>>>13,pc=d[5]|0,Z=pc&8191,tt=pc>>>13,mc=d[6]|0,et=mc&8191,nt=mc>>>13,dc=d[7]|0,ot=dc&8191,at=dc>>>13,fc=d[8]|0,it=fc&8191,rt=fc>>>13,hc=d[9]|0,st=hc&8191,ct=hc>>>13,gc=h[0]|0,lt=gc&8191,ut=gc>>>13,yc=h[1]|0,pt=yc&8191,mt=yc>>>13,bc=h[2]|0,dt=bc&8191,ft=bc>>>13,Tc=h[3]|0,ht=Tc&8191,gt=Tc>>>13,Sc=h[4]|0,yt=Sc&8191,bt=Sc>>>13,wc=h[5]|0,Tt=wc&8191,St=wc>>>13,Ic=h[6]|0,wt=Ic&8191,It=Ic>>>13,Cc=h[7]|0,Ct=Cc&8191,xt=Cc>>>13,xc=h[8]|0,Dt=xc&8191,kt=xc>>>13,Dc=h[9]|0,vt=Dc&8191,At=Dc>>>13;p.negative=r.negative^u.negative,p.length=19,f=Math.imul(O,lt),l=Math.imul(O,ut),l=l+Math.imul(P,lt)|0,g=Math.imul(P,ut);var Qr=(C+f|0)+((l&8191)<<13)|0;C=(g+(l>>>13)|0)+(Qr>>>26)|0,Qr&=67108863,f=Math.imul(_,lt),l=Math.imul(_,ut),l=l+Math.imul(F,lt)|0,g=Math.imul(F,ut),f=f+Math.imul(O,pt)|0,l=l+Math.imul(O,mt)|0,l=l+Math.imul(P,pt)|0,g=g+Math.imul(P,mt)|0;var Jr=(C+f|0)+((l&8191)<<13)|0;C=(g+(l>>>13)|0)+(Jr>>>26)|0,Jr&=67108863,f=Math.imul(K,lt),l=Math.imul(K,ut),l=l+Math.imul($,lt)|0,g=Math.imul($,ut),f=f+Math.imul(_,pt)|0,l=l+Math.imul(_,mt)|0,l=l+Math.imul(F,pt)|0,g=g+Math.imul(F,mt)|0,f=f+Math.imul(O,dt)|0,l=l+Math.imul(O,ft)|0,l=l+Math.imul(P,dt)|0,g=g+Math.imul(P,ft)|0;var Yr=(C+f|0)+((l&8191)<<13)|0;C=(g+(l>>>13)|0)+(Yr>>>26)|0,Yr&=67108863,f=Math.imul(z,lt),l=Math.imul(z,ut),l=l+Math.imul(Q,lt)|0,g=Math.imul(Q,ut),f=f+Math.imul(K,pt)|0,l=l+Math.imul(K,mt)|0,l=l+Math.imul($,pt)|0,g=g+Math.imul($,mt)|0,f=f+Math.imul(_,dt)|0,l=l+Math.imul(_,ft)|0,l=l+Math.imul(F,dt)|0,g=g+Math.imul(F,ft)|0,f=f+Math.imul(O,ht)|0,l=l+Math.imul(O,gt)|0,l=l+Math.imul(P,ht)|0,g=g+Math.imul(P,gt)|0;var Zr=(C+f|0)+((l&8191)<<13)|0;C=(g+(l>>>13)|0)+(Zr>>>26)|0,Zr&=67108863,f=Math.imul(J,lt),l=Math.imul(J,ut),l=l+Math.imul(Y,lt)|0,g=Math.imul(Y,ut),f=f+Math.imul(z,pt)|0,l=l+Math.imul(z,mt)|0,l=l+Math.imul(Q,pt)|0,g=g+Math.imul(Q,mt)|0,f=f+Math.imul(K,dt)|0,l=l+Math.imul(K,ft)|0,l=l+Math.imul($,dt)|0,g=g+Math.imul($,ft)|0,f=f+Math.imul(_,ht)|0,l=l+Math.imul(_,gt)|0,l=l+Math.imul(F,ht)|0,g=g+Math.imul(F,gt)|0,f=f+Math.imul(O,yt)|0,l=l+Math.imul(O,bt)|0,l=l+Math.imul(P,yt)|0,g=g+Math.imul(P,bt)|0;var ts=(C+f|0)+((l&8191)<<13)|0;C=(g+(l>>>13)|0)+(ts>>>26)|0,ts&=67108863,f=Math.imul(Z,lt),l=Math.imul(Z,ut),l=l+Math.imul(tt,lt)|0,g=Math.imul(tt,ut),f=f+Math.imul(J,pt)|0,l=l+Math.imul(J,mt)|0,l=l+Math.imul(Y,pt)|0,g=g+Math.imul(Y,mt)|0,f=f+Math.imul(z,dt)|0,l=l+Math.imul(z,ft)|0,l=l+Math.imul(Q,dt)|0,g=g+Math.imul(Q,ft)|0,f=f+Math.imul(K,ht)|0,l=l+Math.imul(K,gt)|0,l=l+Math.imul($,ht)|0,g=g+Math.imul($,gt)|0,f=f+Math.imul(_,yt)|0,l=l+Math.imul(_,bt)|0,l=l+Math.imul(F,yt)|0,g=g+Math.imul(F,bt)|0,f=f+Math.imul(O,Tt)|0,l=l+Math.imul(O,St)|0,l=l+Math.imul(P,Tt)|0,g=g+Math.imul(P,St)|0;var es=(C+f|0)+((l&8191)<<13)|0;C=(g+(l>>>13)|0)+(es>>>26)|0,es&=67108863,f=Math.imul(et,lt),l=Math.imul(et,ut),l=l+Math.imul(nt,lt)|0,g=Math.imul(nt,ut),f=f+Math.imul(Z,pt)|0,l=l+Math.imul(Z,mt)|0,l=l+Math.imul(tt,pt)|0,g=g+Math.imul(tt,mt)|0,f=f+Math.imul(J,dt)|0,l=l+Math.imul(J,ft)|0,l=l+Math.imul(Y,dt)|0,g=g+Math.imul(Y,ft)|0,f=f+Math.imul(z,ht)|0,l=l+Math.imul(z,gt)|0,l=l+Math.imul(Q,ht)|0,g=g+Math.imul(Q,gt)|0,f=f+Math.imul(K,yt)|0,l=l+Math.imul(K,bt)|0,l=l+Math.imul($,yt)|0,g=g+Math.imul($,bt)|0,f=f+Math.imul(_,Tt)|0,l=l+Math.imul(_,St)|0,l=l+Math.imul(F,Tt)|0,g=g+Math.imul(F,St)|0,f=f+Math.imul(O,wt)|0,l=l+Math.imul(O,It)|0,l=l+Math.imul(P,wt)|0,g=g+Math.imul(P,It)|0;var ns=(C+f|0)+((l&8191)<<13)|0;C=(g+(l>>>13)|0)+(ns>>>26)|0,ns&=67108863,f=Math.imul(ot,lt),l=Math.imul(ot,ut),l=l+Math.imul(at,lt)|0,g=Math.imul(at,ut),f=f+Math.imul(et,pt)|0,l=l+Math.imul(et,mt)|0,l=l+Math.imul(nt,pt)|0,g=g+Math.imul(nt,mt)|0,f=f+Math.imul(Z,dt)|0,l=l+Math.imul(Z,ft)|0,l=l+Math.imul(tt,dt)|0,g=g+Math.imul(tt,ft)|0,f=f+Math.imul(J,ht)|0,l=l+Math.imul(J,gt)|0,l=l+Math.imul(Y,ht)|0,g=g+Math.imul(Y,gt)|0,f=f+Math.imul(z,yt)|0,l=l+Math.imul(z,bt)|0,l=l+Math.imul(Q,yt)|0,g=g+Math.imul(Q,bt)|0,f=f+Math.imul(K,Tt)|0,l=l+Math.imul(K,St)|0,l=l+Math.imul($,Tt)|0,g=g+Math.imul($,St)|0,f=f+Math.imul(_,wt)|0,l=l+Math.imul(_,It)|0,l=l+Math.imul(F,wt)|0,g=g+Math.imul(F,It)|0,f=f+Math.imul(O,Ct)|0,l=l+Math.imul(O,xt)|0,l=l+Math.imul(P,Ct)|0,g=g+Math.imul(P,xt)|0;var os=(C+f|0)+((l&8191)<<13)|0;C=(g+(l>>>13)|0)+(os>>>26)|0,os&=67108863,f=Math.imul(it,lt),l=Math.imul(it,ut),l=l+Math.imul(rt,lt)|0,g=Math.imul(rt,ut),f=f+Math.imul(ot,pt)|0,l=l+Math.imul(ot,mt)|0,l=l+Math.imul(at,pt)|0,g=g+Math.imul(at,mt)|0,f=f+Math.imul(et,dt)|0,l=l+Math.imul(et,ft)|0,l=l+Math.imul(nt,dt)|0,g=g+Math.imul(nt,ft)|0,f=f+Math.imul(Z,ht)|0,l=l+Math.imul(Z,gt)|0,l=l+Math.imul(tt,ht)|0,g=g+Math.imul(tt,gt)|0,f=f+Math.imul(J,yt)|0,l=l+Math.imul(J,bt)|0,l=l+Math.imul(Y,yt)|0,g=g+Math.imul(Y,bt)|0,f=f+Math.imul(z,Tt)|0,l=l+Math.imul(z,St)|0,l=l+Math.imul(Q,Tt)|0,g=g+Math.imul(Q,St)|0,f=f+Math.imul(K,wt)|0,l=l+Math.imul(K,It)|0,l=l+Math.imul($,wt)|0,g=g+Math.imul($,It)|0,f=f+Math.imul(_,Ct)|0,l=l+Math.imul(_,xt)|0,l=l+Math.imul(F,Ct)|0,g=g+Math.imul(F,xt)|0,f=f+Math.imul(O,Dt)|0,l=l+Math.imul(O,kt)|0,l=l+Math.imul(P,Dt)|0,g=g+Math.imul(P,kt)|0;var as=(C+f|0)+((l&8191)<<13)|0;C=(g+(l>>>13)|0)+(as>>>26)|0,as&=67108863,f=Math.imul(st,lt),l=Math.imul(st,ut),l=l+Math.imul(ct,lt)|0,g=Math.imul(ct,ut),f=f+Math.imul(it,pt)|0,l=l+Math.imul(it,mt)|0,l=l+Math.imul(rt,pt)|0,g=g+Math.imul(rt,mt)|0,f=f+Math.imul(ot,dt)|0,l=l+Math.imul(ot,ft)|0,l=l+Math.imul(at,dt)|0,g=g+Math.imul(at,ft)|0,f=f+Math.imul(et,ht)|0,l=l+Math.imul(et,gt)|0,l=l+Math.imul(nt,ht)|0,g=g+Math.imul(nt,gt)|0,f=f+Math.imul(Z,yt)|0,l=l+Math.imul(Z,bt)|0,l=l+Math.imul(tt,yt)|0,g=g+Math.imul(tt,bt)|0,f=f+Math.imul(J,Tt)|0,l=l+Math.imul(J,St)|0,l=l+Math.imul(Y,Tt)|0,g=g+Math.imul(Y,St)|0,f=f+Math.imul(z,wt)|0,l=l+Math.imul(z,It)|0,l=l+Math.imul(Q,wt)|0,g=g+Math.imul(Q,It)|0,f=f+Math.imul(K,Ct)|0,l=l+Math.imul(K,xt)|0,l=l+Math.imul($,Ct)|0,g=g+Math.imul($,xt)|0,f=f+Math.imul(_,Dt)|0,l=l+Math.imul(_,kt)|0,l=l+Math.imul(F,Dt)|0,g=g+Math.imul(F,kt)|0,f=f+Math.imul(O,vt)|0,l=l+Math.imul(O,At)|0,l=l+Math.imul(P,vt)|0,g=g+Math.imul(P,At)|0;var is=(C+f|0)+((l&8191)<<13)|0;C=(g+(l>>>13)|0)+(is>>>26)|0,is&=67108863,f=Math.imul(st,pt),l=Math.imul(st,mt),l=l+Math.imul(ct,pt)|0,g=Math.imul(ct,mt),f=f+Math.imul(it,dt)|0,l=l+Math.imul(it,ft)|0,l=l+Math.imul(rt,dt)|0,g=g+Math.imul(rt,ft)|0,f=f+Math.imul(ot,ht)|0,l=l+Math.imul(ot,gt)|0,l=l+Math.imul(at,ht)|0,g=g+Math.imul(at,gt)|0,f=f+Math.imul(et,yt)|0,l=l+Math.imul(et,bt)|0,l=l+Math.imul(nt,yt)|0,g=g+Math.imul(nt,bt)|0,f=f+Math.imul(Z,Tt)|0,l=l+Math.imul(Z,St)|0,l=l+Math.imul(tt,Tt)|0,g=g+Math.imul(tt,St)|0,f=f+Math.imul(J,wt)|0,l=l+Math.imul(J,It)|0,l=l+Math.imul(Y,wt)|0,g=g+Math.imul(Y,It)|0,f=f+Math.imul(z,Ct)|0,l=l+Math.imul(z,xt)|0,l=l+Math.imul(Q,Ct)|0,g=g+Math.imul(Q,xt)|0,f=f+Math.imul(K,Dt)|0,l=l+Math.imul(K,kt)|0,l=l+Math.imul($,Dt)|0,g=g+Math.imul($,kt)|0,f=f+Math.imul(_,vt)|0,l=l+Math.imul(_,At)|0,l=l+Math.imul(F,vt)|0,g=g+Math.imul(F,At)|0;var rs=(C+f|0)+((l&8191)<<13)|0;C=(g+(l>>>13)|0)+(rs>>>26)|0,rs&=67108863,f=Math.imul(st,dt),l=Math.imul(st,ft),l=l+Math.imul(ct,dt)|0,g=Math.imul(ct,ft),f=f+Math.imul(it,ht)|0,l=l+Math.imul(it,gt)|0,l=l+Math.imul(rt,ht)|0,g=g+Math.imul(rt,gt)|0,f=f+Math.imul(ot,yt)|0,l=l+Math.imul(ot,bt)|0,l=l+Math.imul(at,yt)|0,g=g+Math.imul(at,bt)|0,f=f+Math.imul(et,Tt)|0,l=l+Math.imul(et,St)|0,l=l+Math.imul(nt,Tt)|0,g=g+Math.imul(nt,St)|0,f=f+Math.imul(Z,wt)|0,l=l+Math.imul(Z,It)|0,l=l+Math.imul(tt,wt)|0,g=g+Math.imul(tt,It)|0,f=f+Math.imul(J,Ct)|0,l=l+Math.imul(J,xt)|0,l=l+Math.imul(Y,Ct)|0,g=g+Math.imul(Y,xt)|0,f=f+Math.imul(z,Dt)|0,l=l+Math.imul(z,kt)|0,l=l+Math.imul(Q,Dt)|0,g=g+Math.imul(Q,kt)|0,f=f+Math.imul(K,vt)|0,l=l+Math.imul(K,At)|0,l=l+Math.imul($,vt)|0,g=g+Math.imul($,At)|0;var ss=(C+f|0)+((l&8191)<<13)|0;C=(g+(l>>>13)|0)+(ss>>>26)|0,ss&=67108863,f=Math.imul(st,ht),l=Math.imul(st,gt),l=l+Math.imul(ct,ht)|0,g=Math.imul(ct,gt),f=f+Math.imul(it,yt)|0,l=l+Math.imul(it,bt)|0,l=l+Math.imul(rt,yt)|0,g=g+Math.imul(rt,bt)|0,f=f+Math.imul(ot,Tt)|0,l=l+Math.imul(ot,St)|0,l=l+Math.imul(at,Tt)|0,g=g+Math.imul(at,St)|0,f=f+Math.imul(et,wt)|0,l=l+Math.imul(et,It)|0,l=l+Math.imul(nt,wt)|0,g=g+Math.imul(nt,It)|0,f=f+Math.imul(Z,Ct)|0,l=l+Math.imul(Z,xt)|0,l=l+Math.imul(tt,Ct)|0,g=g+Math.imul(tt,xt)|0,f=f+Math.imul(J,Dt)|0,l=l+Math.imul(J,kt)|0,l=l+Math.imul(Y,Dt)|0,g=g+Math.imul(Y,kt)|0,f=f+Math.imul(z,vt)|0,l=l+Math.imul(z,At)|0,l=l+Math.imul(Q,vt)|0,g=g+Math.imul(Q,At)|0;var cs=(C+f|0)+((l&8191)<<13)|0;C=(g+(l>>>13)|0)+(cs>>>26)|0,cs&=67108863,f=Math.imul(st,yt),l=Math.imul(st,bt),l=l+Math.imul(ct,yt)|0,g=Math.imul(ct,bt),f=f+Math.imul(it,Tt)|0,l=l+Math.imul(it,St)|0,l=l+Math.imul(rt,Tt)|0,g=g+Math.imul(rt,St)|0,f=f+Math.imul(ot,wt)|0,l=l+Math.imul(ot,It)|0,l=l+Math.imul(at,wt)|0,g=g+Math.imul(at,It)|0,f=f+Math.imul(et,Ct)|0,l=l+Math.imul(et,xt)|0,l=l+Math.imul(nt,Ct)|0,g=g+Math.imul(nt,xt)|0,f=f+Math.imul(Z,Dt)|0,l=l+Math.imul(Z,kt)|0,l=l+Math.imul(tt,Dt)|0,g=g+Math.imul(tt,kt)|0,f=f+Math.imul(J,vt)|0,l=l+Math.imul(J,At)|0,l=l+Math.imul(Y,vt)|0,g=g+Math.imul(Y,At)|0;var ls=(C+f|0)+((l&8191)<<13)|0;C=(g+(l>>>13)|0)+(ls>>>26)|0,ls&=67108863,f=Math.imul(st,Tt),l=Math.imul(st,St),l=l+Math.imul(ct,Tt)|0,g=Math.imul(ct,St),f=f+Math.imul(it,wt)|0,l=l+Math.imul(it,It)|0,l=l+Math.imul(rt,wt)|0,g=g+Math.imul(rt,It)|0,f=f+Math.imul(ot,Ct)|0,l=l+Math.imul(ot,xt)|0,l=l+Math.imul(at,Ct)|0,g=g+Math.imul(at,xt)|0,f=f+Math.imul(et,Dt)|0,l=l+Math.imul(et,kt)|0,l=l+Math.imul(nt,Dt)|0,g=g+Math.imul(nt,kt)|0,f=f+Math.imul(Z,vt)|0,l=l+Math.imul(Z,At)|0,l=l+Math.imul(tt,vt)|0,g=g+Math.imul(tt,At)|0;var us=(C+f|0)+((l&8191)<<13)|0;C=(g+(l>>>13)|0)+(us>>>26)|0,us&=67108863,f=Math.imul(st,wt),l=Math.imul(st,It),l=l+Math.imul(ct,wt)|0,g=Math.imul(ct,It),f=f+Math.imul(it,Ct)|0,l=l+Math.imul(it,xt)|0,l=l+Math.imul(rt,Ct)|0,g=g+Math.imul(rt,xt)|0,f=f+Math.imul(ot,Dt)|0,l=l+Math.imul(ot,kt)|0,l=l+Math.imul(at,Dt)|0,g=g+Math.imul(at,kt)|0,f=f+Math.imul(et,vt)|0,l=l+Math.imul(et,At)|0,l=l+Math.imul(nt,vt)|0,g=g+Math.imul(nt,At)|0;var ps=(C+f|0)+((l&8191)<<13)|0;C=(g+(l>>>13)|0)+(ps>>>26)|0,ps&=67108863,f=Math.imul(st,Ct),l=Math.imul(st,xt),l=l+Math.imul(ct,Ct)|0,g=Math.imul(ct,xt),f=f+Math.imul(it,Dt)|0,l=l+Math.imul(it,kt)|0,l=l+Math.imul(rt,Dt)|0,g=g+Math.imul(rt,kt)|0,f=f+Math.imul(ot,vt)|0,l=l+Math.imul(ot,At)|0,l=l+Math.imul(at,vt)|0,g=g+Math.imul(at,At)|0;var ms=(C+f|0)+((l&8191)<<13)|0;C=(g+(l>>>13)|0)+(ms>>>26)|0,ms&=67108863,f=Math.imul(st,Dt),l=Math.imul(st,kt),l=l+Math.imul(ct,Dt)|0,g=Math.imul(ct,kt),f=f+Math.imul(it,vt)|0,l=l+Math.imul(it,At)|0,l=l+Math.imul(rt,vt)|0,g=g+Math.imul(rt,At)|0;var ds=(C+f|0)+((l&8191)<<13)|0;C=(g+(l>>>13)|0)+(ds>>>26)|0,ds&=67108863,f=Math.imul(st,vt),l=Math.imul(st,At),l=l+Math.imul(ct,vt)|0,g=Math.imul(ct,At);var fs=(C+f|0)+((l&8191)<<13)|0;return C=(g+(l>>>13)|0)+(fs>>>26)|0,fs&=67108863,T[0]=Qr,T[1]=Jr,T[2]=Yr,T[3]=Zr,T[4]=ts,T[5]=es,T[6]=ns,T[7]=os,T[8]=as,T[9]=is,T[10]=rs,T[11]=ss,T[12]=cs,T[13]=ls,T[14]=us,T[15]=ps,T[16]=ms,T[17]=ds,T[18]=fs,C!==0&&(T[19]=C,p.length++),p};Math.imul||(U=L);function q(y,r,u){u.negative=r.negative^y.negative,u.length=y.length+r.length;for(var p=0,d=0,h=0;h<u.length-1;h++){var T=d;d=0;for(var C=p&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,p=T,T=d}return p!==0?u.words[h]=p:u.length--,u._strip()}function Pt(y,r,u){return q(y,r,u)}o.prototype.mulTo=function(r,u){var p,d=this.length+r.length;return this.length===10&&r.length===10?p=U(this,r,u):d<63?p=L(this,r,u):d<1024?p=q(this,r,u):p=Pt(this,r,u),p};function W(y,r){this.x=y,this.y=r}W.prototype.makeRBT=function(r){for(var u=new Array(r),p=o.prototype._countBits(r)-1,d=0;d<r;d++)u[d]=this.revBin(d,p,r);return u},W.prototype.revBin=function(r,u,p){if(r===0||r===p-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,p,d,h,T){for(var C=0;C<T;C++)d[C]=u[r[C]],h[C]=p[r[C]]},W.prototype.transform=function(r,u,p,d,h,T){this.permute(T,r,u,p,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 _=p[v+B],F=d[v+B],fe=p[v+B+C],K=d[v+B+C],$=O*fe-P*K;K=O*K+P*fe,fe=$,p[v+B]=_+fe,d[v+B]=F+K,p[v+B+C]=_-fe,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 p=Math.max(u,r)|1,d=p&1,h=0;for(p=p/2|0;p;p=p>>>1)h++;return 1<<h+1+d},W.prototype.conjugate=function(r,u,p){if(!(p<=1))for(var d=0;d<p/2;d++){var h=r[d];r[d]=r[p-d-1],r[p-d-1]=h,h=u[d],u[d]=-u[p-d-1],u[p-d-1]=-h}},W.prototype.normalize13b=function(r,u){for(var p=0,d=0;d<u/2;d++){var h=Math.round(r[2*d+1]/u)*8192+Math.round(r[2*d]/u)+p;r[d]=h&67108863,h<67108864?p=0:p=h/67108864|0}return r},W.prototype.convert13b=function(r,u,p,d){for(var h=0,T=0;T<u;T++)h=h+(r[T]|0),p[2*T]=h&8191,h=h>>>13,p[2*T+1]=h&8191,h=h>>>13;for(T=2*u;T<d;++T)p[T]=0;t(h===0),t((h&-8192)===0)},W.prototype.stub=function(r){for(var u=new Array(r),p=0;p<r;p++)u[p]=0;return u},W.prototype.mulp=function(r,u,p){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=p.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),p.negative=r.negative^u.negative,p.length=r.length+u.length,p._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),Pt(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 p=0,d=0;d<this.length;d++){var h=(this.words[d]|0)*r,T=(h&67108863)+(p&67108863);p>>=26,p+=h/67108864|0,p+=T>>>26,this.words[d]=T&67108863}return p!==0&&(this.words[d]=p,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 p=this,d=0;d<u.length&&u[d]===0;d++,p=p.sqr());if(++d<u.length)for(var h=p.sqr();d<u.length;d++,h=h.sqr())u[d]!==0&&(p=p.mul(h));return p},o.prototype.iushln=function(r){t(typeof r=="number"&&r>=0);var u=r%26,p=(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(p!==0){for(h=this.length-1;h>=0;h--)this.words[h+p]=this.words[h];for(h=0;h<p;h++)this.words[h]=0;this.length+=p}return this._strip()},o.prototype.ishln=function(r){return t(this.negative===0),this.iushln(r)},o.prototype.iushrn=function(r,u,p){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=p;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,p){return t(this.negative===0),this.iushrn(r,u,p)},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,p=(r-u)/26,d=1<<u;if(this.length<=p)return!1;var h=this.words[p];return!!(h&d)},o.prototype.imaskn=function(r){t(typeof r=="number"&&r>=0);var u=r%26,p=(r-u)/26;if(t(this.negative===0,"imaskn works only with positive numbers"),this.length<=p)return this;if(u!==0&&p++,this.length=Math.min(p,this.length),u!==0){var d=67108863^67108863>>>u<<u;this.words[this.length-1]&=d}return this.length===0&&(this.words[0]=0,this.length=1),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,p){var d=r.length+p,h;this._expand(d);var T,C=0;for(h=0;h<r.length;h++){T=(this.words[h+p]|0)+C;var f=(r.words[h]|0)*u;T-=f&67108863,C=(T>>26)-(f/67108864|0),this.words[h+p]=T&67108863}for(;h<this.length-p;h++)T=(this.words[h+p]|0)+C,C=T>>26,this.words[h+p]=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 p=this.length-r.length,d=this.clone(),h=r,T=h.words[h.length-1]|0,C=this._countBits(T);p=26-C,p!==0&&(h=h.ushln(p),d.iushln(p),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"&&p!==0&&d.iushrn(p),{div:l||null,mod:d}},o.prototype.divmod=function(r,u,p){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(),p&&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(),p&&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 p=u.div.negative!==0?u.mod.isub(r):u.mod,d=r.ushrn(1),h=r.andln(1),T=p.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 p=(1<<26)%r,d=0,h=this.length-1;h>=0;h--)d=(p*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 p=0,d=this.length-1;d>=0;d--){var h=(this.words[d]|0)+p*67108864;this.words[d]=h/r|0,p=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,p=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()&&p.isEven();)u.iushrn(1),p.iushrn(1),++f;for(var l=p.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;(p.words[0]&B)===0&&P<26;++P,B<<=1);if(P>0)for(p.iushrn(P);P-- >0;)(T.isOdd()||C.isOdd())&&(T.iadd(l),C.isub(g)),T.iushrn(1),C.iushrn(1);u.cmp(p)>=0?(u.isub(p),d.isub(T),h.isub(C)):(p.isub(u),T.isub(d),C.isub(h))}return{a:T,b:C,gcd:p.iushln(f)}},o.prototype._invmp=function(r){t(r.negative===0),t(!r.isZero());var u=this,p=r.clone();u.negative!==0?u=u.umod(r):u=u.clone();for(var d=new o(1),h=new o(0),T=p.clone();u.cmpn(1)>0&&p.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;(p.words[0]&g)===0&&l<26;++l,g<<=1);if(l>0)for(p.iushrn(l);l-- >0;)h.isOdd()&&h.iadd(T),h.iushrn(1);u.cmp(p)>=0?(u.isub(p),d.isub(h)):(p.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(),p=r.clone();u.negative=0,p.negative=0;for(var d=0;u.isEven()&&p.isEven();d++)u.iushrn(1),p.iushrn(1);do{for(;u.isEven();)u.iushrn(1);for(;p.isEven();)p.iushrn(1);var h=u.cmp(p);if(h<0){var T=u;u=p,p=T}else if(h===0||p.cmpn(1)===0)break;u.isub(p)}while(!0);return p.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,p=(r-u)/26,d=1<<u;if(this.length<=p)return this._expand(p+1),this.words[p]|=d,this;for(var h=d,T=p;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 p;if(this.length>1)p=1;else{u&&(r=-r),t(r<=67108863,"Number is too big");var d=this.words[0]|0;p=d===r?0:d<r?-1:1}return this.negative!==0?-p|0:p},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,p=this.length-1;p>=0;p--){var d=this.words[p]|0,h=r.words[p]|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 G(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 Ge={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,p;do this.split(u,this.tmp),u=this.imulK(u),u=u.iadd(this.tmp),p=u.bitLength();while(p>this.n);var d=p<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},Nt.prototype.split=function(r,u){r.iushrn(this.n,0,u)},Nt.prototype.imulK=function(r){return r.imul(this.k)};function He(){Nt.call(this,"k256","ffffffff ffffffff ffffffff ffffffff ffffffff ffffffff fffffffe fffffc2f")}n(He,Nt),He.prototype.split=function(r,u){for(var p=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&p,h=10;h<r.length;h++){var C=r.words[h]|0;r.words[h-10]=(C&p)<<4|T>>>22,T=C}T>>>=22,r.words[h-10]=T,T===0&&r.length>10?r.length-=10:r.length-=9},He.prototype.imulK=function(r){r.words[r.length]=0,r.words[r.length+1]=0,r.length+=2;for(var u=0,p=0;p<r.length;p++){var d=r.words[p]|0;u+=d*977,r.words[p]=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 to(){Nt.call(this,"p224","ffffffff ffffffff ffffffff ffffffff 00000000 00000000 00000001")}n(to,Nt);function eo(){Nt.call(this,"p192","ffffffff ffffffff ffffffff fffffffe ffffffff ffffffff")}n(eo,Nt);function In(){Nt.call(this,"25519","7fffffffffffffff ffffffffffffffff ffffffffffffffff ffffffffffffffed")}n(In,Nt),In.prototype.imulK=function(r){for(var u=0,p=0;p<r.length;p++){var d=(r.words[p]|0)*19+u,h=d&67108863;d>>>=26,r.words[p]=h,u=d}return u!==0&&(r.words[r.length++]=u),r},o._prime=function(r){if(Ge[r])return Ge[r];var u;if(r==="k256")u=new He;else if(r==="p224")u=new to;else if(r==="p192")u=new eo;else if(r==="p25519")u=new In;else throw new Error("Unknown prime "+r);return Ge[r]=u,u};function G(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}G.prototype._verify1=function(r){t(r.negative===0,"red works only with positives"),t(r.red,"red works only with red numbers")},G.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")},G.prototype.imod=function(r){return this.prime?this.prime.ireduce(r)._forceRed(this):(b(r,r.umod(this.m)._forceRed(this)),r)},G.prototype.neg=function(r){return r.isZero()?r.clone():this.m.sub(r)._forceRed(this)},G.prototype.add=function(r,u){this._verify2(r,u);var p=r.add(u);return p.cmp(this.m)>=0&&p.isub(this.m),p._forceRed(this)},G.prototype.iadd=function(r,u){this._verify2(r,u);var p=r.iadd(u);return p.cmp(this.m)>=0&&p.isub(this.m),p},G.prototype.sub=function(r,u){this._verify2(r,u);var p=r.sub(u);return p.cmpn(0)<0&&p.iadd(this.m),p._forceRed(this)},G.prototype.isub=function(r,u){this._verify2(r,u);var p=r.isub(u);return p.cmpn(0)<0&&p.iadd(this.m),p},G.prototype.shl=function(r,u){return this._verify1(r),this.imod(r.ushln(u))},G.prototype.imul=function(r,u){return this._verify2(r,u),this.imod(r.imul(u))},G.prototype.mul=function(r,u){return this._verify2(r,u),this.imod(r.mul(u))},G.prototype.isqr=function(r){return this.imul(r,r.clone())},G.prototype.sqr=function(r){return this.mul(r,r)},G.prototype.sqrt=function(r){if(r.isZero())return r.clone();var u=this.m.andln(3);if(t(u%2===1),u===3){var p=this.m.add(new o(1)).iushrn(2);return this.pow(r,p)}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},G.prototype.invm=function(r){var u=r._invmp(this.m);return u.negative!==0?(u.negative=0,this.imod(u).redNeg()):this.imod(u)},G.prototype.pow=function(r,u){if(u.isZero())return new o(1).toRed(this);if(u.cmpn(1)===0)return r.clone();var p=4,d=new Array(1<<p);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!==p&&(h!==0||v!==0))&&(T=this.mul(T,d[C]),f=0,C=0)}l=26}return T},G.prototype.convertTo=function(r){var u=r.umod(this.m);return u===r?u.clone():u},G.prototype.convertFrom=function(r){var u=r.clone();return u.red=null,u},o.mont=function(r){return new Be(r)};function Be(y){G.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(Be,G),Be.prototype.convertTo=function(r){return this.imod(r.ushln(this.shift))},Be.prototype.convertFrom=function(r){var u=this.imod(r.mul(this.rinv));return u.red=null,u},Be.prototype.imul=function(r,u){if(r.isZero()||u.isZero())return r.words[0]=0,r.length=1,r;var p=r.imul(u),d=p.maskn(this.shift).mul(this.minv).imaskn(this.shift).mul(this.m),h=p.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)},Be.prototype.mul=function(r,u){if(r.isZero()||u.isZero())return new o(0)._forceRed(this);var p=r.mul(u),d=p.maskn(this.shift).mul(this.minv).imaskn(this.shift).mul(this.m),h=p.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)},Be.prototype.invm=function(r){var u=this.imod(r._invmp(this.m).mul(this.r2));return u._forceRed(this)}})(typeof ic>"u"||ic,Lm)});var rh={};hs(rh,{appHelpers:()=>ih});module.exports=$d(rh);var Bc=require("@msafe/sui3-utils");var re=require("@alphafi/alphafi-sdk"),Xe=require("@msafe/sui3-utils"),Jt=require("@mysten/bcs");var oo=class{constructor(e,t){this.transaction=e;this.simResult=t}transaction;simResult;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=re.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&&re.poolInfo[t].assetTypes.length===2}isSingleAssetDepositEvent(e,t){return e.event_type===0&&re.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:Xe.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}=re.singleAssetPoolCoinMap[e],{expo:s}=re.coinsList[i];n=Math.floor(Number(n)/10**(9-s)).toString()}return{txType:Xe.TransactionType.Other,type:"depositSingleAsset",intentionData:{poolName:e,amount:n}}}decodeWithdraw(e){let t=this.extractXTokensAmount();return console.log("Decoder.decodeWithdraw",t),{txType:Xe.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:Xe.TransactionType.Other,type:"withdrawAlpha",intentionData:{withdrawFromLocked:Number(n)>0,xTokensAmount:t}}}decodeClaimReward(){return{txType:Xe.TransactionType.Other,type:"claimReward",intentionData:{}}}};var Ac=require("@alphafi/alphafi-sdk");var vc=Mt(require("sort-keys-recursive")),w=class{constructor(e){this.data=e}data;serialize(){return JSON.stringify((0,vc.default)(this.data))}};var ao=class a extends w{constructor(t){super(t);this.data=t}data;txType;txSubType;async build(t){let{account:n}=t;return await(0,Ac.claimRewardTxb)(n.address)}static fromData(t){return new a(t)}};var Mc=require("@alphafi/alphafi-sdk");var io=class a extends w{constructor(t){super(t);this.data=t}data;txType;txSubType;async build(t){let{account:n}=t,{poolName:o,amount:i,isAmountA:s}=this.data;return await(0,Mc.depositDoubleAssetTxb)(o,n.address,i,s)}static fromData(t){return console.log("DepositDoubleAssetIntention.fromData",t),new a(t)}};var Oc=require("@alphafi/alphafi-sdk");var ro=class a extends w{constructor(t){super(t);this.data=t}data;txType;txSubType;async build(t){let{account:n}=t,{poolName:o,amount:i}=this.data;return await(0,Oc.depositSingleAssetTxb)(o,n.address,i)}static fromData(t){return console.log("DepositSingleAssetIntention.fromData",t),new a(t)}};var Pc=require("@alphafi/alphafi-sdk");var so=class a extends w{constructor(t){super(t);this.data=t}data;txType;txSubType;async build(t){let{account:n}=t,{poolName:o,xTokensAmount:i}=this.data;return await(0,Pc.withdrawTxb)(i,o,n.address)}static fromData(t){return console.log("WithdrawIntention.fromData",t),new a(t)}};var Rc=require("@alphafi/alphafi-sdk");var co=class a extends w{constructor(t){super(t);this.data=t}data;txType;txSubType;async build(t){let{account:n}=t,{withdrawFromLocked:o,xTokensAmount:i}=this.data;return await(0,Rc.withdrawAlphaTxb)(i,o,n.address)}static fromData(t){return console.log("WithdrawAlphaIntention.fromData",t),new a(t)}};var lo=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 oo(t,i).decode();return{txType:Bc.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=ro.fromData(e.intentionData);break;case"depositDoubleAsset":n=io.fromData(e.intentionData);break;case"withdraw":n=so.fromData(e.intentionData);break;case"withdrawAlpha":n=co.fromData(e.intentionData);break;case"claimReward":n=ao.fromData(e.intentionData);break;default:throw new Error("not implemented")}return n.build({account:t})}};var al=require("@msafe/sui3-utils");var Ut=require("@msafe/sui3-utils"),uo=require("@mysten/sui/bcs"),po=require("bucket-protocol-sdk");var mo=class{constructor(e){this.transaction=e}transaction;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(po.SBUCK_FOUNTAIN_PACKAGE_ID,"fountain_core","stake")}isSBUCKUnstakeTransaction(){return!!this.getMoveCallPackageModuleCommand(po.SBUCK_FOUNTAIN_PACKAGE_ID,"fountain_core","force_unstake")}isSBUCKClaimTransaction(){return!!this.getMoveCallPackageModuleCommand(po.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:Ut.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 m=c.arguments[1];m.$kind==="Input"&&(t=this.getPureInputU64(m.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 m=c.arguments[4];m.$kind==="Input"&&(t=this.getPureInputU64(m.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 m=c.arguments[5];m.$kind==="Input"&&(t=this.getPureInputU64(m.Input));let b=c.arguments[6];if(b.$kind==="Input"){let S=this.getPureAddresses(b.Input);S.length===1&&([n]=S)}}return{txType:Ut.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 m=c.arguments[4];m.$kind==="Input"&&(n=this.getPureInputU64(m.Input));let b=c.arguments[5];if(b.$kind==="Input"){let I=this.getPureAddresses(b.Input);I.length===1&&([i]=I)}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 m=c.arguments[5];m.$kind==="Input"&&(n=this.getPureInputU64(m.Input));let b=c.arguments[6];if(b.$kind==="Input"){let I=this.getPureAddresses(b.Input);I.length===1&&([i]=I)}let S=this.getSplitCoinsCommands()[0].SplitCoins.amounts[0];S.$kind==="Input"&&(t=this.getPureInputU64(S.Input))}return{txType:Ut.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 m=this.getPureAddresses(c.Input);m.length===1&&([n]=m)}}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 m=this.getPureAddresses(c.Input);m.length===1&&([n]=m)}}return{txType:Ut.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:Ut.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:Ut.TransactionType.Other,type:"sbuck-deposit",intentionData:{coinType:t,amount:n,isStake:s}}}decodeSBUCKUnstake(){let e="0",t=this.isSBUCKStakeTransaction();if(t){let m=this.getSplitCoinsCommands()[0].SplitCoins.amounts[0];m.$kind==="Input"&&(e=this.getPureInputU64(m.Input))}let n=[],o=this.getMoveCallModuleCommands("proof_rule","unlock");if(o.length>0)for(let c=0;c<o.length;c++){let m=o[c];n.push("")}else{let c=this.getMoveCallModuleCommands("fountain_core","force_unstake");for(let m=0;m<c.length;m++){let S=c[m].MoveCall.arguments[2];if(S.$kind==="Input"){let{objectId:I}=this.inputs[S.Input].UnresolvedObject;n.push(I)}}}let i=this.isSBUCKWithdrawTransaction(),s={stakeProofs:n,amount:e,isStake:t,toBuck:i};return console.log("Decoder.decodeSBUCKUnstake",s),{txType:Ut.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:Ut.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:Ut.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:Ut.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:Ut.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:Ut.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:Ut.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 uo.bcs.U64.fromBase64(t.Pure.bytes)}getPureAddresses(e){let t=this.inputs[e];if(t.$kind!=="Pure")throw new Error("not pure argument");return uo.bcs.vector(uo.bcs.Address).fromBase64(t.Pure.bytes)}};var Lc=require("@msafe/sui3-utils");var Nc=require("@mysten/sui/transactions"),Wc=require("bucket-protocol-sdk");var Ec=require("bucket-protocol-sdk"),Wt=(a,e)=>{let t=a==="sui:mainnet"?"mainnet":"testnet";return new Ec.BucketClient(t,e.address)};var _c=async(a,e,t)=>{let{coinType:n,amount:o,buckToCoin:i}=a,s=new Nc.Transaction,c=Wt(t,e);return await(0,Wc.buildPsmTx)(c,s,n,o,i,e.address),s};var ho=class a extends w{constructor(t){super(t);this.data=t}data;txType=Lc.TransactionType.Other;txSubType="psm";async build(t){let{account:n,network:o}=t;return await _c(this.data,n,o)}static fromData(t){return new a(t)}};var Kc=require("@msafe/sui3-utils");var Cn=require("@mysten/sui/transactions"),he=require("bucket-protocol-sdk");var jc=async(a,e,t)=>{let{collateralType:n,collateralAmount:o,borrowAmount:i,insertionPlace:s,strapId:c}=a,m=new Cn.Transaction,b=Wt(t,e);return await(0,he.buildBorrowTx)(b,m,n,o,i,e.address,s,c),m},Uc=async(a,e,t)=>{let{collateralType:n,withdrawAmount:o,insertionPlace:i,strapId:s}=a,c=new Cn.Transaction,m=Wt(t,e);return await(0,he.buildWithdrawTx)(m,c,n,o,e.address,i,s),c},qc=async(a,e,t)=>{let{collateralType:n,repayAmount:o,withdrawAmount:i,isSurplus:s,insertionPlace:c,strapId:m}=a,b=new Cn.Transaction,S=Wt(t,e);return await(0,he.buildRepayTx)(S,b,n,o,i,e.address,s,c,m),b},Fc=async(a,e,t)=>{let{collateralType:n,recipient:o,strapId:i}=a,s=new Cn.Transaction,c=Wt(t,e);return await(0,he.buildCloseTx)(c,s,n,o,i),s};var go=class a extends w{constructor(t){super(t);this.data=t}data;txType=Kc.TransactionType.Other;txSubType="borrow";async build(t){let{account:n,network:o}=t;return await jc(this.data,n,o)}static fromData(t){return new a(t)}};var Vc=require("@msafe/sui3-utils");var yo=class a extends w{constructor(t){super(t);this.data=t}data;txType=Vc.TransactionType.Other;txSubType="repay";async build(t){let{account:n,network:o}=t;return await qc(this.data,n,o)}static fromData(t){return new a(t)}};var $c=require("@msafe/sui3-utils");var bo=class a extends w{constructor(t){super(t);this.data=t}data;txType=$c.TransactionType.Other;txSubType="withdraw";async build(t){let{account:n,network:o}=t;return await Uc(this.data,n,o)}static fromData(t){return new a(t)}};var Gc=require("@msafe/sui3-utils");var To=class a extends w{constructor(t){super(t);this.data=t}data;txType=Gc.TransactionType.Other;txSubType="close";async build(t){let{account:n,network:o}=t;return await Fc(this.data,n,o)}static fromData(t){return new a(t)}};var Dn=require("@msafe/sui3-utils");var xn=require("@mysten/sui/transactions"),ge=require("bucket-protocol-sdk");var Hc=async(a,e,t)=>{let{coinType:n,amount:o,isStake:i}=a,s=new xn.Transaction,c=Wt(t,e);return await(0,ge.buildSBUCKDepositTx)(c,s,n,o,e.address,i),s},Xc=async(a,e,t)=>{let{stakeProofs:n,amount:o,isStake:i,toBuck:s}=a,c=new xn.Transaction,m=Wt(t,e);return await(0,ge.buildSBUCKUnstakeTx)(m,c,n,o,e.address,i,s),c},zc=async(a,e,t)=>{let{amount:n}=a,o=new xn.Transaction,i=Wt(t,e);return await(0,ge.buildSBUCKWithdrawTx)(i,o,n,e.address),o},Qc=async(a,e,t)=>{let{stakeProofs:n}=a,o=new xn.Transaction,i=Wt(t,e);return await(0,ge.buildSBUCKClaimTx)(i,o,n,e.address),o};var So=class a extends w{constructor(t){super(t);this.data=t}data;txType=Dn.TransactionType.Other;txSubType="sbuck-deposit";async build(t){let{account:n,network:o}=t;return await Hc(this.data,n,o)}static fromData(t){return new a(t)}},wo=class a extends w{constructor(t){super(t);this.data=t}data;txType=Dn.TransactionType.Other;txSubType="sbuck-unstake";async build(t){let{account:n,network:o}=t;return await Xc(this.data,n,o)}static fromData(t){return new a(t)}},Io=class a extends w{constructor(t){super(t);this.data=t}data;txType=Dn.TransactionType.Other;txSubType="sbuck-withdraw";async build(t){let{account:n,network:o}=t;return await zc(this.data,n,o)}static fromData(t){return new a(t)}},Co=class a extends w{constructor(t){super(t);this.data=t}data;txType=Dn.TransactionType.Other;txSubType="sbuck-claim";async build(t){let{account:n,network:o}=t;return await Qc(this.data,n,o)}static fromData(t){return new a(t)}};var Ao=require("@msafe/sui3-utils");var xo=require("@mysten/sui/transactions"),ze=require("bucket-protocol-sdk");var Jc=async(a,e,t)=>{let{coinType:n,amount:o}=a,i=new xo.Transaction,s=Wt(t,e);return await(0,ze.buildTankDepositTx)(s,i,n,o,e.address),i},Yc=async(a,e,t)=>{let{coinType:n,amount:o}=a,i=new xo.Transaction,s=Wt(t,e);return await(0,ze.buildTankWithdrawTx)(s,i,n,o,e.address),i},Zc=async(a,e,t)=>{let{coinType:n}=a,o=new xo.Transaction,i=Wt(t,e);return await(0,ze.buildTankClaimTx)(i,o,n,e.address),o};var tl=require("@mysten/sui/transactions"),el=require("bucket-protocol-sdk");var nl=async(a,e,t)=>{let{coinType:n,proofCount:o}=a,i=new tl.Transaction,s=Wt(t,e);return await(0,el.buildLockedClaimTx)(s,i,n,o,e.address),i};var Do=class a extends w{constructor(t){super(t);this.data=t}data;txType=Ao.TransactionType.Other;txSubType="tank-deposit";async build(t){let{account:n,network:o}=t;return await Jc(this.data,n,o)}static fromData(t){return new a(t)}},ko=class a extends w{constructor(t){super(t);this.data=t}data;txType=Ao.TransactionType.Other;txSubType="tank-withdraw";async build(t){let{account:n,network:o}=t;return await Yc(this.data,n,o)}static fromData(t){return new a(t)}},vo=class a extends w{constructor(t){super(t);this.data=t}data;txType=Ao.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 ol=require("@msafe/sui3-utils");var Mo=class a extends w{constructor(t){super(t);this.data=t}data;txType=ol.TransactionType.Other;txSubType="lock-claim";async build(t){let{account:n,network:o}=t;return await nl(this.data,n,o)}static fromData(t){return new a(t)}};var Oo=class{application="bucket";supportSDK="@mysten/sui";async deserialize(e){console.log("Bucket helper deserialize input: ",e);let{transaction:t}=e,o=new mo(t).decode();return{txType:al.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=ho.fromData(e.intentionData);break;case"borrow":i=go.fromData(e.intentionData);break;case"withdraw":i=bo.fromData(e.intentionData);break;case"repay":i=yo.fromData(e.intentionData);break;case"close":i=To.fromData(e.intentionData);break;case"tank-deposit":i=Do.fromData(e.intentionData);break;case"tank-withdraw":i=ko.fromData(e.intentionData);break;case"tank-claim":i=vo.fromData(e.intentionData);break;case"sbuck-deposit":i=So.fromData(e.intentionData);break;case"sbuck-unstake":i=wo.fromData(e.intentionData);break;case"sbuck-withdraw":i=Io.fromData(e.intentionData);break;case"sbuck-claim":i=Co.fromData(e.intentionData);break;case"lock-claim":i=Mo.fromData(e.intentionData);break;default:throw new Error("not implemented")}return i.build({suiClient:t,account:n,network:o})}};var ru=require("@msafe/sui3-utils");var ml=require("@msafe/sui3-utils");var H=require("@mysten/sui/jsonRpc"),Hd={"sui:mainnet":"mainnet","sui:testnet":"testnet","sui:devnet":"devnet","sui:localnet":"localnet"};function kn(a){return Hd[a]}var Yt=async(a,e)=>{let{CetusClmmSDK:t}=await import("@cetusprotocol/sui-clmm-sdk"),n=t.createSDK({env:"mainnet",sui_client:new H.SuiJsonRpcClient({url:(0,H.getJsonRpcFullnodeUrl)("mainnet"),network:"mainnet"})});return n.setSenderAddress(e.address),n},Kt=async(a,e)=>{let{CetusFarmsSDK:t}=await import("@cetusprotocol/farms-sdk"),n=t.createSDK({env:"mainnet",sui_client:new H.SuiJsonRpcClient({url:(0,H.getJsonRpcFullnodeUrl)("mainnet"),network:"mainnet"})});return n.setSenderAddress(e.address),n},Xd="https://api-sui.cetus.zone/router_v2/find_routes",il=async(a,e)=>{let{AggregatorClient:t,Env:n}=await import("@cetusprotocol/aggregator-sdk"),o=new H.SuiJsonRpcClient({url:"https://fullnode.mainnet.sui.io/",network:"mainnet"});return new t({endpoint:Xd,signer:e.address,client:o,env:n.Mainnet})},vn=async(a,e)=>{let{CetusVaultsSDK:t}=await import("@cetusprotocol/vaults-sdk"),n=t.createSDK({env:"mainnet"});return n.setSenderAddress(e.address),n},Qe=async(a,e)=>{let{CetusXcetusSDK:t}=await import("@cetusprotocol/xcetus-sdk"),n=t.createSDK({env:"mainnet"});return n.setSenderAddress(e.address),n};var rl=async(a,e,t)=>await(await Yt(t,e)).Pool.createPoolPayload(a),sl=async(a,e,t)=>await(await Yt(t,e)).Position.createAddLiquidityFixTokenPayload(a?.parameter,a?.gasEstimateArg),cl=async(a,e,t)=>await(await Yt(t,e)).Position.createAddLiquidityFixTokenPayload(a?.parameter,a?.gasEstimateArg),ll=async(a,e,t)=>await(await Yt(t,e)).Position.closePositionPayload(a),ul=async(a,e,t)=>await(await Yt(t,e)).Position.removeLiquidityPayload(a),pl=async(a,e,t)=>await(await Yt(t,e)).Rewarder.collectRewarderPayload(a);var Po=class a extends w{constructor(t){super(t);this.data=t}data;txType=ml.TransactionType.Other;txSubType="OpenAndAddLiquidity";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 dl=require("@msafe/sui3-utils");var Ro=class a extends w{constructor(t){super(t);this.data=t}data;txType=dl.TransactionType.Other;txSubType="ClaimFeeAndMining";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 fl=require("@msafe/sui3-utils");var Bo=class a extends w{constructor(t){super(t);this.data=t}data;txType=fl.TransactionType.Other;txSubType="CreatePool";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 hl=require("@msafe/sui3-utils");var Eo=class a extends w{constructor(t){super(t);this.data=t}data;txType=hl.TransactionType.Other;txSubType="DecreaseLiquidity";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 gl=async(a,e,t)=>await(await Kt(t,e)).Farms.openPositionAddLiquidityStakePayload(a),yl=async(a,e,t)=>await(await Kt(t,e)).Farms.addLiquidityFixCoinPayload(a),bl=async(a,e,t)=>await(await Kt(t,e)).Farms.removeLiquidityPayload(a);var Tl=async(a,e,t)=>await(await Kt(t,e)).Farms.removeLiquidityPayload(a),Sl=async(a,e,t)=>await(await Kt(t,e)).Farms.claimFeeAndClmmReward(a),wl=async(a,e,t)=>await(await Kt(t,e)).Farms.harvestPayload(a),Il=async(a,e,t)=>{let n=await Kt(t,e),o=Object.values(a);return await n.Farms.batchHarvestPayload(o)},Cl=async(a,e,t)=>await(await Kt(t,e)).Farms.depositPayload(a),xl=async(a,e,t)=>await(await Kt(t,e)).Farms.withdrawPayload(a);var No=class a extends w{constructor(t){super(t);this.data=t}data;txType=Dl.TransactionType.Other;txSubType="FarmingOpenAndAddLiquidity";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 Wo=class a extends w{constructor(t){super(t);this.data=t}data;txType=kl.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 vl=require("@msafe/sui3-utils");var _o=class a extends w{constructor(t){super(t);this.data=t}data;txType=vl.TransactionType.Other;txSubType="FarmingClaimFeeAndReward";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 Al=require("@msafe/sui3-utils");var Lo=class a extends w{constructor(t){super(t);this.data=t}data;txType=Al.TransactionType.Other;txSubType="FarmingDecreaseLiquidity";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 Ml=require("@msafe/sui3-utils");var jo=class a extends w{constructor(t){super(t);this.data=t}data;txType=Ml.TransactionType.Other;txSubType="FarmingHarvest";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 Ol=require("@msafe/sui3-utils");var Uo=class a extends w{constructor(t){super(t);this.data=t}data;txType=Ol.TransactionType.Other;txSubType="FarmingIncreaseLiquidity";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 Pl=require("@msafe/sui3-utils");var qo=class a extends w{constructor(t){super(t);this.data=t}data;txType=Pl.TransactionType.Other;txSubType="FarmingRemoveLiquidity";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 Fo=class a extends w{constructor(t){super(t);this.data=t}data;txType=Rl.TransactionType.Other;txSubType="FarmingStake";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 Ko=class a extends w{constructor(t){super(t);this.data=t}data;txType=Bl.TransactionType.Other;txSubType="FarmingUnstake";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 El=require("@msafe/sui3-utils");var Vo=class a extends w{constructor(t){super(t);this.data=t}data;txType=El.TransactionType.Other;txSubType="IncreaseLiquidity";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 _l=require("@msafe/sui3-utils");var $o=async()=>{let{Transaction:a}=await import("@mysten/sui/transactions");return new a},zd=async(a,e,t)=>{let n=await vn(t,e),o=await $o();return o.setSender(e.address),n.Vest.buildRedeemPayload(a.params,o),o},Qd=async(a,e)=>{let{default:t,vaults_mainnet:n}=await import("haedal-vault-sdk"),o=new t(n);o.senderAddress=e.address;let i=await $o();return i.setSender(e.address),await o?.Vest.buildRedeemPayload(a.params,i),i},Nl=async(a,e,t)=>{let n=await Yt(t,e),o=await $o();return n?.Vest.buildRedeemPayload(a.params,o),o},Jd=async(a,e,t)=>{let n=await Yt(t,e),o=await Kt(t,e),i=await $o(),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},Wl=async(a,e,t)=>a.type==="clmm"?Nl(a,e,t):a.type==="farms"?Jd(a,e,t):a.type==="vaults"?zd(a,e,t):a.type==="haedalVaults"?Qd(a,e):Nl(a,e,t);var Go=class a extends w{constructor(t){super(t);this.data=t}data;txType=_l.TransactionType.Other;txSubType="PosVestingRedeem";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 Ll=require("@msafe/sui3-utils");var Ho=class a extends w{constructor(t){super(t);this.data=t}data;txType=Ll.TransactionType.Other;txSubType="RemoveLiquidity";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 ql=require("@msafe/sui3-utils");var jl=require("@mysten/sui/transactions");var Ul=async(a,e,t)=>{let{restituteMsafeFastRouterSwapParams:n}=await import("@cetusprotocol/aggregator-sdk"),o=await il(t,e),i=new jl.Transaction;return await o.fastRouterSwap({...a,router:n(a.router),txb:i}),i};var Xo=class a extends w{constructor(t){super(t);this.data=t}data;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 gs=require("@mysten/sui/transactions");var Fl=async(a,e,t)=>{let n=await vn(t,e),o=new gs.Transaction;return o.setSender(e.address),await n.Vaults.deposit(a,o),o},Kl=async(a,e,t)=>{let n=await vn(t,e),o=new gs.Transaction;return await n.Vaults.withdraw(a,o),o};var zo=class a extends w{constructor(t){super(t);this.data=t}data;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 Qo=class a extends w{constructor(t){super(t);this.data=t}data;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 zl=require("@msafe/sui3-utils");var Hl=require("@mysten/sui/transactions"),Gl={package_id:"0x355714a1eeb7ab1d80902da6c92001170cda1212edf524c32aa308a3ac177c31",published_at:"0x355714a1eeb7ab1d80902da6c92001170cda1212edf524c32aa308a3ac177c31",cetus_coin_type:"0x06864a6f921804860930db6ddbe2e16acdf8504495ea7481637a1c8b9a8fe54b::cetus::CETUS"},Xl=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 Hl.Transaction;return i.forEach(m=>{c.moveCall({target:`${Gl.published_at}::router::redeem`,typeArguments:[Gl.cetus_coin_type],arguments:[c.object(n),c.object(o),c.pure(m),c.object(s)]})}),c};var Jo=class a extends w{constructor(t){super(t);this.data=t}data;txType=zl.TransactionType.Other;txSubType="VestingRedeem";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 eu=require("@msafe/sui3-utils");var Ql=async(a,e,t)=>await(await Qe(t,e)).XCetusModule.convertPayload(a),Jl=async(a,e,t)=>await(await Qe(t,e)).XCetusModule.redeemLockPayload(a),Yl=async(a,e,t)=>await(await Qe(t,e)).XCetusModule.redeemDividendV3Payload(a.veNftId,a.rewardList),Zl=async(a,e,t)=>await(await Qe(t,e)).XCetusModule.cancelRedeemPayload(a),tu=async(a,e,t)=>await(await Qe(t,e)).XCetusModule.redeemPayload(a);var Yo=class a extends w{constructor(t){super(t);this.data=t}data;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 Zo=class a extends w{constructor(t){super(t);this.data=t}data;txType=nu.TransactionType.Other;txSubType="xCETUSClaimStakingRwewards";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 ou=require("@msafe/sui3-utils");var ta=class a extends w{constructor(t){super(t);this.data=t}data;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 ea=class a extends w{constructor(t){super(t);this.data=t}data;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 na=class a extends w{constructor(t){super(t);this.data=t}data;txType=iu.TransactionType.Other;txSubType="xCETUSRedeemLock";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 oa=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=Po.fromData(e.intentionData);break;case"IncreaseLiquidity":i=Vo.fromData(e.intentionData);break;case"DecreaseLiquidity":i=Eo.fromData(e.intentionData);break;case"RemoveLiquidity":i=Ho.fromData(e.intentionData);break;case"ClaimFeeAndMining":i=Ro.fromData(e.intentionData);break;case"FarmingOpenAndAddLiquidity":i=No.fromData(e.intentionData);break;case"FarmingIncreaseLiquidity":i=Uo.fromData(e.intentionData);break;case"FarmingDecreaseLiquidity":i=Lo.fromData(e.intentionData);break;case"FarmingRemoveLiquidity":i=qo.fromData(e.intentionData);break;case"FarmingClaimFeeAndReward":i=_o.fromData(e.intentionData);break;case"FarmingHarvest":i=jo.fromData(e.intentionData);break;case"FarmingBatchHarvest":i=Wo.fromData(e.intentionData);break;case"FarmingStake":i=Fo.fromData(e.intentionData);break;case"FarmingUnstake":i=Ko.fromData(e.intentionData);break;case"xCETUSConvert":i=ta.fromData(e.intentionData);break;case"xCETUSRedeemLock":i=na.fromData(e.intentionData);break;case"xCETUSClaimStakingRwewards":i=Zo.fromData(e.intentionData);break;case"xCETUSCancelRedeem":i=Yo.fromData(e.intentionData);break;case"xCETUSRedeem":i=ea.fromData(e.intentionData);break;case"VestingRedeem":i=Jo.fromData(e.intentionData);break;case"AggregatorSwap":i=Xo.fromData(e.intentionData);break;case"AddVaultsPosition":i=zo.fromData(e.intentionData);break;case"RemoveVaultsPosition":i=Qo.fromData(e.intentionData);break;case"PosVestingRedeem":i=Go.fromData(e.intentionData);break;case"CreatePool":i=Bo.fromData(e.intentionData);break;default:throw new Error("not implemented")}return i.build({suiClient:t,account:n,network:o})}};var Fu=require("@msafe/sui3-utils");var su=Mt(require("sort-keys-recursive")),ye=class{constructor(e){this.data=e}data;serialize(){return JSON.stringify((0,su.default)(this.data))}};var ys={};hs(ys,{contractId:()=>tf,default:()=>rf,feeObjId:()=>of,roleObjId:()=>ef,status:()=>Zd,transaction:()=>Yd,upgradeCapObjId:()=>af,vaultObjId:()=>nf});var Yd="DiBZq4UmVVYiRL6ZJmFKYoHcxtxqrhsCXSkFyT7wUr3j",Zd="success",tf="0x81c960dc653975fbd0072deca8afb92d322898c911622898ba1b2e3ad0c4bd8d",ef="0xc6ec0bdee0bb59a72077e9acd2f42457043cf47080b3d3fad4d39abf28bba63a",nf="0xbc4021387fbac149119fd24e92be9e58f745774292f3a2a12e2ac6daf5363e1d",of="0x4178f63970fe2daeb256dc5730ad172e82b3e8eb45f31b33e0daae72cd35e1e1",af="0xe1e9aa7d222d151bfe6dd83358b0d7fdcb11260f710800cfaf7ccc1b1e245115",rf={transaction:Yd,status:Zd,contractId:tf,roleObjId:ef,vaultObjId:nf,feeObjId:of,upgradeCapObjId:af};var bs={};hs(bs,{contractId:()=>lf,default:()=>ff,feeObjId:()=>mf,roleObjId:()=>uf,status:()=>cf,transaction:()=>sf,upgradeCapObjId:()=>df,vaultObjId:()=>pf});var sf="855FNDV8o8Z3fWULPnQo9qdhLJpsg7wZrkCpNyfw9KfB",cf="success",lf="0xc357c3985e8fb875d6b37141497af660779aa1bab0ec489b2213efd74067d1fa",uf="0x5ab49bdf9fd1413e328ef242b3f8d83dde791b38a0b627bfc87fb25c010d34f1",pf="0xb483558770d8eb26007f193b75db40f0a45f2e36863a687625885d4de6993378",mf="0x48453fc4d7cde3fe35aad89e5dfb496608a6a55ea529a1c0274681a808627f94",df="0x34279779a0d0d36bd5044b04830d607fa1b0ecf316548c8ac3a44151e4f1a42a",ff={transaction:sf,status:cf,contractId:lf,roleObjId:uf,vaultObjId:pf,feeObjId:mf,upgradeCapObjId:df};var hf=(0,H.getJsonRpcFullnodeUrl)("testnet"),gf=(0,H.getJsonRpcFullnodeUrl)("testnet"),yf=(0,H.getJsonRpcFullnodeUrl)("mainnet"),bf=(0,H.getJsonRpcFullnodeUrl)("mainnet"),Tf="https://bc3p6l5unl.execute-api.us-west-1.amazonaws.com/prod",Sf="https://rolsbkota7.execute-api.us-west-1.amazonaws.com/prod",wf="https://6p6mkx33ne.execute-api.us-west-1.amazonaws.com/prod",If="https://xrae3mrjv5.execute-api.us-west-1.amazonaws.com/prod",cu=ys,lu=bs,Cf=new Map([["dev",{env:"dev",rpc:{url:hf},backend:{url:Tf},contract:cu}],["stg",{env:"stg",rpc:{url:gf},backend:{url:Sf},contract:cu}],["prev",{env:"prev",rpc:{url:yf},backend:{url:wf},contract:lu}],["prod",{env:"prod",rpc:{url:bf},backend:{url:If},contract:lu}]]);function uu(a,e){let t=Cf.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 pu=require("@mysten/sui/grpc");function xf(a){return Object.assign(a,{getObject(e){return a.core.getObject(e)},async listCoins(e){let t=await a.core.listCoins({owner:e.owner,coinType:e.coinType,cursor:e.cursor??void 0});return{objects:t.objects.map(n=>({coinType:e.coinType??"",objectId:n.objectId,version:n.version,digest:n.digest,balance:n.balance??"0"})),hasNextPage:t.hasNextPage,cursor:t.cursor}}})}function An(a,e){let t=kn(a),n=new pu.SuiGrpcClient({network:t,baseUrl:e??(0,H.getJsonRpcFullnodeUrl)(t)});return xf(n)}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 aa=class extends j{constructor(){super(11,"Backend is not specified")}};var ia=class extends j{constructor(){super(1,"Wallet not connected")}};var ce=Mt(require("axios"));var Je=class extends j{constructor(e,t){super(10,e,{context:t})}};var ra=class a{constructor(e){this.apiURL=e}apiURL;static parseResponseData(e){if(e instanceof ce.AxiosError)throw new Je(e.response?.statusText);if(e.status===200){if(e.data.success)return e.data.data;throw new Je(e.data.code)}throw new Je(e.status.toString())}async getIncomingStreams(e,t){let n=await ce.default.post(`${this.apiURL}/stream`,{recipient:e,...t});return a.parseResponseData(n)}async getOutgoingStreams(e,t){let n=await ce.default.post(`${this.apiURL}/stream`,{sender:e,...t});return a.parseResponseData(n)}async getStreamHistory(e){let t=await ce.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 ce.default.post(`${this.apiURL}/stream-info`,{address:e});return a.parseResponseData(t)}async getAllRecipients(e,t){let n=await ce.default.post(`${this.apiURL}/stream-info`,{sender:e,status:t});return a.parseResponseData(n)}async getAllSenders(e,t){let n=await ce.default.post(`${this.apiURL}/stream-info`,{recipient:e,status:t});return a.parseResponseData(n)}};var Df={dev:"sui:testnet",stg:"sui:testnet",prev:"sui:mainnet",prod:"sui:mainnet"},Ye=class a{signer;suiClient;envConfig;_backend;constructor(e,t){this.envConfig=e,this.suiClient=t??An(Df[e.env],e.rpc.url),e.backend&&(this._backend=new ra(e.backend.url))}static new(e,t){let n=uu(e,t);return new a(n,t?.suiGrpcClient)}get walletType(){return this.wallet?this.wallet.type:"disconnected"}get backend(){if(!this._backend)throw new aa;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 ia;return this.signer}async walletAddress(){return this.wallet.address()}};var We=require("@mysten/sui/utils");var Bn=require("@mysten/sui/transactions");var ws=require("@mysten/sui/transactions"),Rn=require("@mysten/sui/utils");var Ts=50n,sa=10000n,du=25n,Ss=100000000n;var le=class{constructor(e){this.object=e}object;moveArg(e){return e.object(this.object)}},ca=class{constructor(e){this.objects=e}objects;moveArgs(e){return e.makeMoveVec({elements:this.objects.map(t=>e.object(t))})}},Ee=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)}})}result;moveArg(){return this.result}};function fu(a,e){if(typeof e=="bigint"||typeof e=="number")return a.pure.u64(e);if(typeof e=="boolean")return a.pure.bool(e);if(typeof e=="string")return/^0x[0-9a-fA-F]+$/.test(e)?a.pure.address(e):a.pure.string(e);throw new Error(`Unsupported pure argument type: ${typeof e}`)}var ku=require("@mysten/bcs");var Mn=class extends j{constructor(e,t){super(3,e,{context:t})}};var yu=require("@mysten/bcs");var Zt=class extends j{constructor(e,t){super(6,e,{context:t})}};function la(a){if(a==null)throw new Zt("Missing move object field");if(typeof a=="object"&&"fields"in a){let e=a.fields;if(e&&typeof e=="object")return e}if(typeof a=="object")return a;throw new Zt("Unexpected move object field shape",{value:String(a)})}function hu(a){return a.fields&&typeof a.fields=="object"&&!("balance"in a)&&!("config"in a)&&!("status"in a)?a.fields:a}function gu(a,e="balance"){if(a==null)throw new Zt(`Stream object missing ${e} field`);if(typeof a=="string"||typeof a=="number"||typeof a=="bigint")return BigInt(a);let t=la(a),n=t.balance??t.value;if(n==null)throw new Zt(`Stream object ${e} field has unexpected shape`,{value:JSON.stringify(a)});return BigInt(String(n))}async function bu(a,e){let t=await a.listCoins({owner:e.owner,coinType:e.coinType,cursor:e.cursor??void 0,limit:e.limit});return{data:t.objects.map(n=>({coinObjectId:n.objectId,balance:n.balance,coinType:n.type})),hasNextPage:t.hasNextPage,nextCursor:t.cursor}}function kf(a){return a.core?.getObject?a.core.getObject.bind(a.core):a.getObject.bind(a)}function Tu(a){return a.json&&typeof a.json=="object"?hu(a.json):null}async function Su(a,e){try{let t=kf(a),{object:n}=await t({objectId:e,include:{json:!0,type:!0}}),o=Tu(n);return o?{data:{objectId:n.objectId,type:n.type,content:{dataType:"moveObject",type:n.type,fields:o}}}:{error:{code:"notExists"}}}catch{return{error:{code:"notExists"}}}}async function wu(a,e){if(e.length===0)return[];let{objects:t}=await a.getObjects({objectIds:e,include:{json:!0,type:!0}});return t.map(n=>{if(!("objectId"in n))return{error:{code:String(n.code??"unknown")}};let o=Tu(n);if(o)return{data:{objectId:n.objectId,type:n.type,content:{dataType:"moveObject",type:n.type,fields:o}}}})}async function Iu(a,e){let{balance:t}=await a.getBalance({owner:e.owner,coinType:e.coinType??void 0});return{coinType:t.coinType,totalBalance:t.balance}}async function Cu(a,e){return(await a.listBalances({owner:e})).balances.map(n=>({coinType:n.coinType,totalBalance:n.balance}))}async function xu(a,e){let{coinMetadata:t}=await a.getCoinMetadata({coinType:e});return t}async function ua(a,e){e.transaction.setSenderIfNotSet(e.sender);let t=await a.simulateTransaction({transaction:e.transaction,include:{effects:!0,commandResults:!0}}),n=t.$kind==="Transaction"?t.Transaction:t.FailedTransaction;return{effects:n.effects?{status:{status:n.effects.status.success?"success":"failure",error:n.effects.status.error?.message}}:void 0,commandResults:t.commandResults,results:t.commandResults?.map(o=>({returnValues:o.returnValues.map(i=>[Array.from(i.bcs),"u64"])}))}}function Du(a,e=0,t=0){let n=a.commandResults?.[e]?.returnValues?.[t];if(!n)throw new Error("Missing command result");return BigInt(yu.bcs.u64().parse(n.bcs))}var pa=class{constructor(e){this.results=e}results;getU64(e=0,t=0){try{return Du(this.results,e,t)}catch{let[n,o]=this.getLegacyValue(e,t);if(o!=="u64")throw new Mn("Invalid contract return type.",{ctx:{expectType:"u64",gotType:o}});return ku.bcs.u64().parse(Uint8Array.from(n))}}getLegacyValue(e=0,t=0){let o=this.results.results?.[e]?.returnValues;if(!o?.[t])throw new Mn("Invalid contract return type.",{ctx:{expectType:"u64",gotType:"missing"}});return o[t]}};var ma=require("@mysten/bcs");var X=class extends j{constructor(e,t,n){super(2,`Invalid input: ${e}`,{context:{fieldKey:t,fieldValue:n}})}};var Au=ma.bcs.struct("StreamMetadata",{groupId:ma.bcs.string(),name:ma.bcs.string()}),vf=64;function Mu(a){return Ou(a),Au.serialize(a).toBase64()}function On(a){let e=Au.fromBase64(a);return Ou(e),e}function Ou(a){if(!vu(a.name))throw new X("Invalid metadata: Name contains unknown character");if(!vu(a.groupId))throw new X("Invalid metadata: Group ID contains unknown character");if(a.name.length>vf)throw new X("Invalid metadata: Name exceed max length 64")}function vu(a){return/^[\x00-\x7F]+$/.test(a)}var Pn=require("@mysten/sui/utils");function da(a,e){return(0,Pn.normalizeStructTag)(a)===(0,Pn.normalizeStructTag)(e)}function Se(a,e){return(0,Pn.normalizeStructTag)(a)===(0,Pn.normalizeStructTag)(e)}function we(a){if(a.$kind!=="MoveCall"||!a.MoveCall)return null;let{package:e,module:t,function:n}=a.MoveCall;return`${e}::${t}::${n}`}var fa="txn.gas";var Pu=require("nanoid");function Ru(){return(0,Pu.nanoid)()}var Ne=class a{constructor(e,t,n){this.globals=e;this.feeContract=t;this.streamContract=n}globals;feeContract;streamContract;static convertCreateStreamInfoToInternal(e){return{metadata:Mu({name:e.name,groupId:Ru()}),coinType:(0,Rn.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 ws.Transaction,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 m=0;m<e.recipients.length;m++){let b=e.recipients[m],S=this.amountForRecipient(b,e.numberEpoch),I=this.getStreamFeeLocal(S),[x]=t.splitCoins(s,[t.pure.u64(S+I)]),[D]=t.splitCoins(c,[t.pure.u64(this.flatSuiFee)]);this.streamContract.createStream(t,{paymentCoin:new Ee(x),flatFeeCoin:new Ee(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:Ts,denominator:sa},claimFeePercent:{numerator:du,denominator:sa},flatFeePerStream:Ss}}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===fa?n=e.gas:n=e.object(t.primaryCoin),n}getCreateStreamCoinRequests(e,t){let n=e.coinType;return da(n,Rn.SUI_TYPE_ARG)?[{coinType:n,amount:t.totalAmount+t.streamFeeAmount+t.flatFeeAmount}]:[{coinType:n,amount:t.totalAmount+t.streamFeeAmount},{coinType:Rn.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 Ss}getStreamFeeLocal(e){return e*Ts/sa}async getStreamFeeRemote(e){let t=this.feeContract.streamingFee(new ws.Transaction,e),n=await ua(this.globals.suiClient,{sender:await this.globals.walletAddress(),transaction:t});return new pa(n).getU64()}get wallet(){return this.globals.wallet}};var Bu="0x0000000000000000000000000000000000000000000000000000000000000006";var Ze=class{constructor(e,t,n){this.moduleName=e;this.config=t;this.globals=n}moduleName;config;globals;addContractCall(e,t){let n=`${this.config.contractId}::${this.moduleName}::${t.method}`;return e.moveCall({target:n,arguments:t.arguments.map(o=>o instanceof ca?o.moveArgs(e):o instanceof le?o.moveArg(e):o instanceof Ee?o.moveArg():fu(e,o)),typeArguments:t.typeArgs}),e}makeObject(e){return typeof e=="string"?new le(e):e}vaultObject(){return new le(this.config.vaultObjId)}roleObject(){return new le(this.config.roleObjId)}feeObject(){return new le(this.config.feeObjId)}clockObject(){return new le(Bu)}};var tn=class a extends Ze{constructor(t,n){super(a.ModuleName,t,n);this.config=t;this.globals=n}config;globals;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 Ze{constructor(t,n){super(a.ModuleName,t,n);this.config=t;this.globals=n}config;globals;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),m=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,m],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 en=class{constructor(e){this.globals=e;let t=e.envConfig.contract;this.feeContract=new tn(t,e),this.streamContract=new te(t,e)}globals;feeContract;streamContract;async createStreams(e){let t=Ne.convertCreateStreamInfoToInternal(e);return this.createStreamHelper().buildCreateStreamTransactionBlock(t)}createStreamHelper(){return new Ne(this.globals,this.feeContract,this.streamContract)}setAutoClaim(e,t,n){let o=new Bn.Transaction;return this.streamContract.setAutoClaim(o,{streamId:e,enabled:t,coinType:n})}claimStream(e,t){let n=new Bn.Transaction;return this.streamContract.claimStream(n,{streamId:e,coinType:t})}claimStreamByProxy(e,t){let n=new Bn.Transaction;return this.streamContract.claimStreamByProxy(n,{streamId:e,coinType:t})}cancelStream(e,t){let n=new Bn.Transaction;return this.streamContract.cancelStream(n,{streamId:e,coinType:t}),n}};var nn=require("@mysten/sui/utils"),Is=require("luxon");var ha=class extends j{constructor(e,t){super(12,`Transaction failed: ${t}`,{context:{status:e,msg:t}})}};var Af=1e3,ga=class{constructor(e){this.globals=e;this.coinMetaHelper=new Cs(e.suiClient),this.createStreamHelper=new en(e).createStreamHelper()}globals;coinMetaHelper;createStreamHelper;getStreamIdsFromCreateStreamResponse(e){if(e.effects?.status.status!=="success")throw new ha(e.effects?.status.status,e.effects?.status.error);return Object.entries(e.objectTypes??{}).filter(([,t])=>t.startsWith(`${this.globals.envConfig.contract.contractId}::stream::Stream`)).map(([t])=>t)}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(Is.Duration.fromMillis(Number(t*e.steps))),o={timeStart:e.timeStart,timeEnd:n,interval:Is.Duration.fromMillis(Number(t)),steps:e.steps};return this.validateTimeline(o),o}async getBalance(e,t){let n=await Iu(this.globals.suiClient,{owner:e,coinType:t}),o=await this.getCoinMeta(t);return{...n,coinType:(0,nn.normalizeStructTag)(n.coinType),coinMeta:o}}async getAllBalance(e){let t=await Cu(this.globals.suiClient,e),n=await Promise.all(t.map(o=>this.getCoinMeta(o.coinType)));return t.map((o,i)=>({...o,coinType:(0,nn.normalizeStructTag)(o.coinType),coinMeta:n[i]}))}async getCoinMeta(e){return this.coinMetaHelper.getCoinMeta(e)}async simulateTransactionBlock(e){return ua(this.globals.suiClient,{transaction: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()<Af)throw new X("Interval shall be at least 1 second","interval",e.interval)}},Cs=class{constructor(e){this.suiClient=e;this.coinMetaReg=new Map}suiClient;coinMetaReg;async getCoinMeta(e){let t=(0,nn.normalizeStructTag)(e||nn.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??void 0}async queryCoinMeta(e){return xu(this.suiClient,e)}};var Ce=require("@mysten/sui/utils"),Os=require("luxon");var Nn=require("@mysten/sui/transactions"),Wn=require("@mysten/sui/utils"),Nu=require("luxon");var ya=class extends j{constructor(){super(7,"Connected wallet is not creator")}};var En=class extends j{constructor(){super(8,"Connected wallet is not recipient")}};var Rt=class extends j{constructor(e,t={}){super(0,e,t)}};var ba=class extends j{constructor(e){super(5,"Stream not found",{context:{streamId:e}})}};var Sa=require("luxon"),Eu=(1n<<64n)-1n,Ta=1e3;function xs(a){let e;typeof a=="number"?e=a:typeof a=="bigint"?e=Number(a):e=a.toMillis();let t=Math.round(e/Ta);return Sa.DateTime.fromMillis(t*Ta)}function Ds(a){let e;typeof a=="number"?e=a:typeof a=="bigint"?e=Number(a):e=a.toMillis();let t=Math.round(e/Ta);return Sa.Duration.fromMillis(t*Ta)}var Ie=class a{constructor(e,t,n){this.globals=e;this.streamId=t;this.rawData=n;this.streamContract=new te(e.envConfig.contract,e)}globals;streamId;rawData;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 Rt("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 ya;let e=new Nn.Transaction;return this.streamContract.cancelStream(e,{streamId:this.streamId,coinType:this.coinType}),e}async claim(){if(await this.globals.walletAddress()!==this.recipient)throw new En;let e=new Nn.Transaction;return this.streamContract.claimStream(e,{streamId:this.streamId,coinType:this.coinType}),e}async setAutoClaim(e){if(await this.globals.walletAddress()!==this.recipient)throw new En;let t=new Nn.Transaction;return this.streamContract.setAutoClaim(t,{streamId:this.streamId,coinType:this.coinType,enabled:e}),t}async claimByProxy(){let e=new Nn.Transaction;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,Wn.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 Ds(this.rawData.config.epochInterval)}get groupId(){let{metadata:e}=this.rawData.config;return On(e).groupId}get name(){let{metadata:e}=this.rawData.config;return On(e).name}get recipient(){return this.rawData.config.recipient}get timeStart(){return xs(this.rawData.config.timeStart)}get duration(){let e=this.rawData.config,t=e.epochInterval*e.totalEpoch;return Ds(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:xs((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===Eu?0n:this.rawData.status.epochClaimed*this.amountPerEpoch+this.cliff}get currentEpoch(){let e=Nu.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 Su(e.suiClient,t);return a.parseRawStreamData(t,n)}static parseRawStreamData(e,t){if(t.error)throw t.error.code==="notExists"?new ba(e):new Zt(`get stream data: ${t.error.code}`,{streamId:e,...t.error});let n=t.data?.content;if(!n||n.dataType!=="moveObject")throw new Zt("Unexpected object type",{gotType:n?.dataType});let{typeParams:o}=(0,Wn.parseStructTag)(n.type),i=(0,Wn.normalizeStructTag)(o[0]),s=n.fields,c=la(s.config),m=la(s.status);return{coinType:i,autoClaim:s.auto_claim,balance:gu(s.balance),config:{amountPerEpoch:BigInt(String(c.amount_per_epoch)),cancelable:c.cancelable,cliff:BigInt(String(c.cliff)),creator:String(c.creator),epochInterval:BigInt(String(c.epoch_interval)),metadata:String(c.metadata),recipient:String(c.recipient),timeStart:BigInt(String(c.time_start)),totalEpoch:BigInt(String(c.total_epoch))},status:{status:m.status,epochCanceled:BigInt(String(m.epoch_canceled)),epochClaimed:BigInt(String(m.epoch_claimed))}}}};var on=class extends j{constructor(e,t){super(9,`Invalid stream group: ${e}`,{context:t})}};async function vs(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 ks=class{constructor(e){this.requester=e;this.curPage=void 0,this.init=!0}requester;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)}},an=class{constructor(e){this.requester=e;this.pager=new ks(e),this.curData=[],this.cursor=0}requester;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 Mf=25;async function Ms(a,e,t){let n=new _n(e),o=new Ln(a,n,t);return await vs(o)}var _n=class{constructor(e){this.ids=e;this.cursor=-1}ids;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]}},Ln=class extends an{constructor(t,n,o){super(new As(t,n,o));this.suiClient=t;this.idIter=n;this.options=o}suiClient;idIter;options},As=class{constructor(e,t,n){this.suiClient=e;this.stringIter=t;this.options=n;this.filter=n?.filter,this.pageSize=n?.pageSize||Mf,this.objectOptions=n?.objectOptions||{showType:!0,showContent:!0}}suiClient;stringIter;options;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 wu(this.suiClient,e),n;if(this.filter){let{filter:o}=this;n=t.filter(i=>!!i&&o(i))}else n=t.filter(o=>!!o);return{data:n,hasNext:await this.stringIter.hasNext()}}};var wa=class a{constructor(e,t){this.globals=e;this.streams=t;if(t.length===0)throw new on("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")}globals;streams;type="StreamGroup";static async new(e,t){let n=await Ms(e.suiClient,t);return n.forEach(o=>{if(!o)throw new Rt("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=>{Of(n,i)||(o=!1)}),o}async refresh(){let e=await Ms(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)=>Ie.fromObjectData(e,t[s],i)).filter(i=>!!i);if(new Set(o.map(i=>i.groupId)).size!==1)throw new on("Not same group ID");if(!this.checkStreamGroup(o))throw new on("Not same stream settings");return o}};function Of(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 jn=class a{constructor(e,t){this.it=e;this.pageSize=t}it;pageSize;static async newIncoming(e){let t=await Ia.newIncoming(e);return new a(t,e.pageSize)}static async newOutgoing(e){let t=await Ia.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}},Ia=class a{constructor(e){this.requester=e}requester;cachedNext;static async newIncoming(e){let t=await Ca.newIncomingQuery(e);return new a(t)}static async newOutgoing(e){let t=await Ca.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 Rt("No more results");return t}let e=this.cachedNext;if(this.cachedNext=void 0,e===null)throw new Rt("No more results");return e}},Ca=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 _n(n.flat().map(s=>s.streamId));this.objectIter=new Ln(e.suiClient,i)}globals;recipient;groupRefs;query;current=0;objectIter;static async newIncomingQuery(e){let t=Nf(e.query),n=await e.globals.walletAddress(),i=(await e.globals.backend.getIncomingStreams(n,t)).filter(c=>(0,Ce.normalizeSuiAddress)(c.recipient)===(0,Ce.normalizeSuiAddress)(n)),s=Wu(i);return new a(e.globals,n,s,e.query)}static async newOutgoingQuery(e){let t=Wf(e.query),n=await e.globals.walletAddress(),o=await e.globals.backend.getOutgoingStreams(n,t),i=Wu(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 Bf(this.globals,e[0].streamId,this.objectIter);return this.current++,_u(t,this.query)?t:this.doNextRequest()}if(e.length>1){let t=await Ef(this.globals,e.map(n=>n.streamId),this.objectIter);return this.current++,Rf(t,this.query)?t:this.doNextRequest()}throw new Rt("Stream group with no stream")}};function Wu(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)=>Os.DateTime.fromISO(n[0].createDate).toMillis()-Os.DateTime.fromISO(t[0].createDate).toMillis())}function _u(a,e){if(e===void 0)return!0;let t=Pf(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 Pf(a,e){return e===void 0?!0:Array.isArray(e)?e.includes(a.progress.status):a.progress.status===e}function Rf(a,e){if(!e)return!0;let t=!1;return a.streams.forEach(n=>{_u(n,e)&&(t=!0)}),t}async function Bf(a,e,t){let n=await Lu(t,e);return Ie.fromObjectData(a,e,n)}async function Ef(a,e,t){let n=[];for(;n.length<e.length;){let o=await Lu(t,e[n.length]);n.push(o)}return wa.newFromObjectResponse(a,e,n)}async function Lu(a,e){if(!await a.hasNext())throw new Rt("object iterator has been consumed");let t=await a.next();if(!t||t.error||t.data===void 0||t.data===null)throw new Rt("object iterator undefined response",{cause:t?.error});if(t?.data?.objectId!==e)throw new Rt("stream id not aligned");return t}function Nf(a){return{status:Ps(a?.status),coinType:ju(a?.coinType),sender:Uu(a?.sender)}}function Wf(a){return{status:Ps(a?.status),coinType:ju(a?.coinType),recipient:Uu(a?.recipient)}}function Ps(a){return a===void 0||a.length===0?"all":Array.isArray(a)?a.reduce((e,t)=>{let n=Ps(t);return!e||e===n?n:"all"},void 0):_f(a)}function _f(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 ju(a){if(a)return Array.isArray(a)?a.length!==0?a.map(e=>(0,Ce.normalizeStructTag)(e)):void 0:(0,Ce.normalizeStructTag)(a)}function Uu(a){if(a)return Array.isArray(a)?a.length!==0?a.map(e=>(0,Ce.normalizeSuiAddress)(e)):void 0:(0,Ce.normalizeSuiAddress)(a)}var xa=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}coinType;requestAmount;gotAmount};var Lf=25;async function qu(a,e,t,n="0x2::sui::SUI",o=Lf){let i=new Rs(a,e,n,o),s=BigInt(0),c=[];for(;await i.hasNext()&&s<t;){let m=await i.next();m&&(c.push(m),s+=BigInt(m.balance))}if(s<t)throw new xa(n,t,s);return c}var Rs=class extends an{constructor(t,n,o,i){super(new Bs(t,n,o,i));this.suiClient=t;this.owner=n;this.coinType=o;this.reqPageSize=i}suiClient;owner;coinType;reqPageSize},Bs=class{constructor(e,t,n,o){this.suiClient=e;this.owner=t;this.coinType=n;this.reqPageSize=o;if(o<=0)throw new Rt("Invalid reqPageSize")}suiClient;owner;coinType;reqPageSize;nextCursor;async doNextRequest(){let e=await bu(this.suiClient,{owner:this.owner,coinType:this.coinType,cursor:this.nextCursor,limit:this.reqPageSize});return this.nextCursor=e.nextCursor,{data:e.data,hasNext:e.hasNextPage}}};var Es=class{constructor(e){this.msafe=e}msafe;get type(){return"msafe"}async address(){return this.msafe.address()}async requestCoins(e){return this.msafe.requestCoins(e)}},Da=class{constructor(e){this.account=e}account;async address(){return this.account.address}},Ns=class{constructor(e,t){this.singleWallet=e;this.suiClient=t}singleWallet;suiClient;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(da(e.coinType,We.SUI_TYPE_ARG))return{primaryCoin:fa};if(e.amount<=0)throw new X("Invalid coin request","coinAmount",e.amount);let t=await qu(this.suiClient,await this.address(),e.amount,e.coinType);if(t.length===0)throw new Rt("no coins available");return{primaryCoin:t[0].coinObjectId,mergedCoins:t.slice(1).map(n=>n.coinObjectId)}}},ka=class{globals;helper;constructor(e,t){this.globals=Ye.new(e,t),this.helper=new ga(this.globals)}connectSingleWallet(e){let t=new Ns(e,this.globals.suiClient);this.globals.connectWallet(t)}connectMSafeAccount(e){let t=new Es(e);this.globals.connectWallet(t)}async createStream(e){return this.builder().createStreams(e)}async getStream(e){return Ie.new(this.globals,e)}async getIncomingStreams(e,t=10){return jn.newIncoming({globals:this.globals,query:e,pageSize:t})}async getOutgoingStreams(e,t=10){return jn.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,We.normalizeStructTag)(n))}async getRecipientsForStreamFilter(e){let t=await this.wallet.address();return(await this.globals.backend.getAllRecipients(t,e)).map(o=>(0,We.normalizeSuiAddress)(o))}async getCreatorsForStreamFilter(e){let t=await this.wallet.address();return(await this.globals.backend.getAllSenders(t,e)).map(o=>(0,We.normalizeSuiAddress)(o))}get wallet(){return this.globals.wallet}builder(){return new en(this.globals)}};var $t=class extends ye{application="mpay";getClient(e,t,n){let o=new ka(e==="sui:mainnet"?"prod":"dev",{suiGrpcClient:n});return o.connectSingleWallet(new Da(t)),o}};var Un=class extends $t{constructor(t){super(t);this.data=t}data;txType=Fu.TransactionType.Stream;txSubType="Cancel";async build(t){let{network:n,account:o,suiGrpcClient:i}=t;return(await this.getClient(n,o,i).getStream(this.data.streamId)).cancel()}};var Ku=require("@msafe/sui3-utils");var qn=class extends $t{constructor(t){super(t);this.data=t}data;txType=Ku.TransactionType.Stream;txSubType="ClaimByProxy";async build(t){let{network:n,account:o,suiGrpcClient:i}=t;return(await this.getClient(n,o,i).getStream(this.data.streamId)).claimByProxy()}};var Vu=require("@msafe/sui3-utils");var Fn=class extends $t{constructor(t){super(t);this.data=t}data;txType=Vu.TransactionType.Stream;txSubType="Claim";async build(t){let{network:n,account:o,suiGrpcClient:i}=t;return(await this.getClient(n,o,i).getStream(this.data.streamId)).claim()}};var $u=require("@msafe/sui3-utils");var Kn=class extends $t{constructor(t){super(t);this.data=t}data;txType=$u.TransactionType.Stream;txSubType="CreateStream";async build(t){let{network:n,account:o,suiGrpcClient:i}=t;return this.getClient(n,o,i).createStream(this.data)}};var Le=require("@mysten/sui/bcs"),Gu=require("@mysten/bcs"),rn=require("@mysten/sui/utils");function Vn(a){if(!a.Pure)throw new Error("not pure argument");return(0,Gu.fromBase64)(a.Pure.bytes)}var sn=class a{constructor(e,t){this.moveCall=e;this.txb=t}moveCall;txb;get moveCallData(){if(this.moveCall.$kind!=="MoveCall")throw new Error("not move call command");return this.moveCall.MoveCall}get inputs(){return this.txb.getData().inputs}getInputIndex(e){let t=this.moveCallData.arguments[e];if(t.$kind!=="Input")throw new Error("not input type");return t.Input}getInputParam(e){return this.inputs[this.getInputIndex(e)]}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.getInputParam(e);return BigInt(Le.bcs.U64.parse(Vn(t)))}decodeInputAddress(e){let t=this.getInputParam(e);return(0,rn.normalizeSuiAddress)(Le.bcs.Address.parse(Vn(t)))}decodeInputString(e){let t=this.getInputParam(e);return Le.bcs.String.parse(Vn(t))}decodeInputBool(e){let t=this.getInputParam(e);return Le.bcs.Bool.parse(Vn(t))}decodePureArg(e,t){let n=this.getInputParam(e);return a.getPureInputValue(n,t)}static getPureInputValue(e,t){return a.getPureInput(e,t)}static getOwnedObjectId(e){let t=e.Object?.ImmOrOwnedObject?.objectId??e.Object?.Receiving?.objectId??e.UnresolvedObject?.objectId;if(!t)throw new Error(`not object argument: ${JSON.stringify(e)}`);return(0,rn.normalizeSuiAddress)(t)}static getSharedObjectId(e){let t=e.Object?.SharedObject?.objectId??e.UnresolvedObject?.objectId;if(!t)throw new Error(`not shared object argument: ${JSON.stringify(e)}`);return(0,rn.normalizeSuiAddress)(t)}static getPureInput(e,t){return(0,Le.pureBcsSchemaFromTypeName)(t).parse(Vn(e))}typeArg(e){return(0,rn.normalizeStructTag)(this.moveCallData.typeArguments[e])}txArg(e){return this.moveCallData.arguments[e]}};var va=class{constructor(e,t){this.globals=e;this.txb=t}globals;txb;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.commands.filter(t=>t.$kind==="MoveCall"&&Se(we(t),this.contract.createStreamTarget));if(e.length===0)throw new Rt("No create stream transactions");return e.map(t=>new sn(t,this.txb))}getCreationInfoFromMoveCall(e){let t=e.decodeInputString(4),{name:n,groupId:o}=On(t),i=e.decodeInputAddress(5),s=e.decodeInputU64(6),c=e.decodeInputU64(7),m=e.decodeInputU64(8),b=e.decodeInputU64(9),S=e.decodeInputU64(10),I=e.decodeInputBool(11),x=e.typeArg(0);return{name:n,groupId:o,recipient:i,timeStart:s,cliff:c,epochInterval:m,totalEpoch:b,amountPerEpoch:S,cancelable:I,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 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}}get commands(){return this.txb.getData().commands}get contract(){return new te(this.globals.envConfig.contract,this.globals)}get feeContract(){return new tn(this.globals.envConfig.contract,this.globals)}createStreamHelper(){return new Ne(this.globals,this.feeContract,this.contract)}};var Aa=class{constructor(e,t){this.globals=e;this.txb=t;this.contract=new te(e.envConfig.contract,e)}globals;txb;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 commands(){return this.txb.getData().commands}isCreateStreamTransaction(){return this.commands.findIndex(t=>t.$kind==="MoveCall"&&Se(we(t),this.contract.createStreamTarget))!==-1}isSetAutoClaimTransaction(){return this.commands.length===1&&this.commands[0].$kind==="MoveCall"&&Se(we(this.commands[0]),this.contract.setAutoClaimTarget)}isCancelStreamTransaction(){return this.commands.length===1&&this.commands[0].$kind==="MoveCall"&&Se(we(this.commands[0]),this.contract.cancelStreamTarget)}isClaimStreamTransaction(){return this.commands.length===1&&this.commands[0].$kind==="MoveCall"&&Se(we(this.commands[0]),this.contract.claimStreamTarget)}isClaimByProxyTransaction(){return this.commands.length===1&&this.commands[0].$kind==="MoveCall"&&Se(we(this.commands[0]),this.contract.claimStreamByProxyTarget)}decodeCreateStreamTransaction(){return new va(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.commands[0];if(e.$kind!=="MoveCall")throw new Error("MoveCall not found");return new sn(e,this.txb)}};var Hu=require("@msafe/sui3-utils");var $n=class extends $t{constructor(t){super(t);this.data=t}data;txType=Hu.TransactionType.Stream;txSubType="SetAutoClaim";async build(t){let{network:n,account:o,suiGrpcClient:i}=t;return(await this.getClient(n,o,i).getStream(this.data.streamId)).setAutoClaim(this.data.enabled)}};var Ma=class{application="mpay";supportSDK="@mysten/sui-v2";async deserialize(e){let{network:t,transaction:n,suiGrpcClient:o}=e,i=Ye.new(t==="sui:mainnet"?"prod":"dev",{suiGrpcClient:o}),c=new Aa(i,n).decode(),m;switch(c.type){case"CreateStream":m=new Kn(c.info);break;case"SetAutoClaim":m=new $n({streamId:c.streamId,enabled:c.enabled});break;case"Claim":m=new Fn({streamId:c.streamId});break;case"ClaimByProxy":m=new qn({streamId:c.streamId});break;case"Cancel":m=new Un({streamId:c.streamId});break;default:throw new Error(`Unknown transaction type: ${c}`)}return{txType:m.txType,txSubType:m.txSubType,intentionData:m.data}}async build(e){let{intentionData:t}=e,n;switch(e.txSubType){case"CreateStream":n=new Kn(t);break;case"Claim":n=new Fn(t);break;case"ClaimByProxy":n=new qn(t);break;case"SetAutoClaim":n=new $n(t);break;case"Cancel":n=new Un(t);break;default:throw new Error("not implemented")}return n.build({...e})}};var Gn=require("@msafe/sui3-utils");var Xu=require("@msafe/sui3-utils");var Oa=class a extends ye{constructor(t){super(t);this.data=t}data;txType;txSubType;async build(t){let{suiGrpcClient:n,account:o}=t;return(0,Xu.buildCoinTransferTxb)(n,this.data,o.address)}static fromData(t){return new a(t)}};var zu=require("@msafe/sui3-utils");var Pa=class a extends ye{constructor(t){super(t);this.data=t}data;txType;txSubType;async build(t){let{suiGrpcClient:n,account:o}=t;return(0,zu.buildObjectTransferTxb)(n,this.data,o.address)}static fromData(t){return new a(t)}};var Ra=class{application="msafe-core";supportSDK="@mysten/sui-v2";constructor(){this.application=Gn.TransactionDefaultApplication}deserialize(){throw new Error("MSafe core transaction intention should be build from API")}async build(e){let{account:t,network:n,suiGrpcClient:o}=e,i;switch(e.txSubType){case Gn.TransactionSubTypes.assets.coin.send:i=Oa.fromData(e.intentionData);break;case Gn.TransactionSubTypes.assets.object.send:i=Pa.fromData(e.intentionData);break;default:throw new Error("not implemented")}return i.build({suiGrpcClient:o,account:t,network:n})}};var js=require("@msafe/sui3-utils");var Qu=!1,Hn={ProtocolPackage:"0x1e4a13a0494d5facdbe8473e74127b838c2d446ecec0ce262e2eddafa77259cb",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 Ws(){if(!Qu)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&&(Hn.ProtocolPackage=e),t&&(Hn.borrowFee=t),n&&(Hn.borrowFeeAddress=n),o&&(Hn.pool=o),Qu=!0}catch(a){console.error(a.message)}}var ee=Hn;var xe=require("@msafe/sui3-utils"),Gt=require("@mysten/bcs"),cn=require("@mysten/sui/utils");function Ba(a){if(a.$kind!=="MoveCall")return null;let{package:e,module:t,function:n}=a.MoveCall;return`${e}::${t}::${n}`}var Ea=class{constructor(e){this.txb=e}txb;decode(){if(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 commands(){return this.txb.getData().commands}getMoveCallCommand(e){return this.commands.find(t=>Ba(t)===e)}isClaimRewardTransaction(){return this.commands.some(e=>e.$kind==="MoveCall"&&e.MoveCall.function.includes("claim_reward"))}isEntryBorrowTransaction(){return!!this.getMoveCallCommand(`${ee.ProtocolPackage}::incentive_v3::entry_borrow_v2`)}isEntryBorrowWithFeeTransaction(){return!!this.getMoveCallCommand(`${ee.ProtocolPackage}::incentive_v3::borrow_v2`)}isEntryMultiDepositTransaction(){let e=`${ee.ProtocolPackage}::incentive_v3::entry_deposit`,t=this.commands.filter(o=>Ba(o)===e);return this.commands.find(o=>o.$kind==="MoveCall"&&o.MoveCall.function.includes("claim_reward"))?!1:t.length>1}isEntryClaimAndDepositTransaction(){let e=`${ee.ProtocolPackage}::incentive_v3::entry_deposit`,t=this.commands.filter(o=>Ba(o)===e);return!!(this.commands.find(o=>o.$kind==="MoveCall"&&o.MoveCall.function.includes("claim_reward"))&&t.length>0)}isEntryDepositTransaction(){return!!this.getMoveCallCommand(`${ee.ProtocolPackage}::incentive_v3::entry_deposit`)}isEntryRepayTransaction(){return!!this.getMoveCallCommand(`${ee.ProtocolPackage}::incentive_v3::entry_repay`)}isEntryWithdrawTransaction(){return!!this.getMoveCallCommand(`${ee.ProtocolPackage}::incentive_v3::withdraw_v2`)}decodeEntryClaimAndDeposit(){return{txType:xe.TransactionType.Other,type:"EntryClaimAndDeposit",intentionData:{type:"entry_claim_and_deposit"}}}decodeClaimReward(){return{txType:xe.TransactionType.Other,type:"ClaimReward",intentionData:{type:"claim_reward"}}}decodeEntryBorrow(){let e=this.helper.decodeInputU8(4),t=this.helper.decodeInputU64(5);return{txType:xe.TransactionType.Other,type:"EntryBorrow",intentionData:{amount:t,assetId:e}}}decodeEntryMultiDeposit(){let e=[],t=`${ee.ProtocolPackage}::incentive_v3::entry_deposit`;return this.commands.forEach(n=>{if(Ba(n)===t){let o=new Na(n,this.txb),i=o.decodeInputU8(3),s=o.decodeInputU64(5);e.push({assetId:i,amount:s})}}),{txType:xe.TransactionType.Other,type:"EntryMultiDeposit",intentionData:{list:e}}}decodeEntryDeposit(){let e=this.helper.decodeInputU8(3),t=this.helper.decodeInputU64(5);return{txType:xe.TransactionType.Other,type:"EntryDeposit",intentionData:{amount:t,assetId:e}}}decodeEntryRepay(){let e=this.helper.decodeInputU8(4),t=this.helper.decodeInputU64(6);return{txType:xe.TransactionType.Other,type:"EntryRepay",intentionData:{amount:t,assetId:e}}}decodeEntryWithdraw(){let e=this.helper.decodeInputU8(4),t=this.helper.decodeInputU64(5);return{txType:xe.TransactionType.Other,type:"EntryWithdraw",intentionData:{amount:t,assetId:e}}}get helper(){let e=this.commands.find(t=>t.$kind==="MoveCall"&&t.MoveCall.package===ee.ProtocolPackage);if(!e)throw new Error("MoveCall not found");return new Na(e,this.txb)}},Na=class a{constructor(e,t){this.moveCall=e;this.txb=t}moveCall;txb;get moveCallData(){if(this.moveCall.$kind!=="MoveCall")throw new Error("not move call command");return this.moveCall.MoveCall}get inputs(){return this.txb.getData().inputs}getInputIndex(e){let t=this.moveCallData.arguments[e];if(t.$kind!=="Input")throw new Error("not input type");return t.Input}getInputParam(e){return this.inputs[this.getInputIndex(e)]}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.getInputParam(e);return Number(Gt.bcs.u64().parse(Uint8Array.from((0,Gt.fromBase64)(t.Pure.bytes))))}decodeInputU8(e){let t=this.getInputParam(e);return Number(Gt.bcs.u8().parse(Uint8Array.from((0,Gt.fromBase64)(t.Pure.bytes))))}decodeInputAddress(e){let t=this.getInputParam(e);return(0,cn.normalizeSuiAddress)(Gt.bcs.Address.parse(Uint8Array.from((0,Gt.fromBase64)(t.Pure.bytes))))}decodeInputString(e){let t=this.getInputParam(e);return Gt.bcs.string().parse(Uint8Array.from((0,Gt.fromBase64)(t.Pure.bytes)))}decodeInputBool(e){let t=this.getInputParam(e);return Gt.bcs.bool().parse(Uint8Array.from((0,Gt.fromBase64)(t.Pure.bytes)))}static getOwnedObjectId(e){let t=e.Object?.ImmOrOwnedObject?.objectId??e.Object?.Receiving?.objectId??e.UnresolvedObject?.objectId;if(!t)throw new Error(`not object argument: ${JSON.stringify(e)}`);return(0,cn.normalizeSuiAddress)(t)}static getSharedObjectId(e){let t=e.Object?.SharedObject?.objectId??e.UnresolvedObject?.objectId;if(!t)throw new Error(`not shared object argument: ${JSON.stringify(e)}`);return(0,cn.normalizeSuiAddress)(t)}typeArg(e){return(0,cn.normalizeStructTag)(this.moveCallData.typeArguments[e])}txArg(e){return this.moveCallData.arguments[e]}};var _s=require("@mysten/sui/transactions"),qt=require("@naviprotocol/lending");async function ln(a,e,t,n){return await(0,qt.depositCoinPTB)(a,e,t,{amount:n}),a}async function Ju(a,e,t,n){let[o]=await(0,qt.withdrawCoinPTB)(a,e,t);return a.transferObjects([o],a.pure.address(n)),a}async function Yu(a,e,t,n){let[o]=await(0,qt.borrowCoinPTB)(a,e,t);return a.transferObjects([o],a.pure.address(n)),a}async function Ls(a,e,t,n){return await(0,qt.repayCoinPTB)(a,e,t,{amount:n}),a}async function Zu(a,e){let t=new _s.Transaction,n=await(0,qt.getUserAvailableLendingRewards)(e,{client:a});return await(0,qt.claimLendingRewardsPTB)(t,n),t}async function tp(a,e){let t=new _s.Transaction,n=await(0,qt.getUserAvailableLendingRewards)(e,{client:a});return await(0,qt.claimLendingRewardsPTB)(t,n,{customCoinReceive:{type:"depositNAVI",depositNAVI:{fallbackReceiveAddress:e}}}),t}var Wa=class a extends w{constructor(t){super(t);this.data=t}data;txType;txSubType;async build(t){let{type:n}=this.data;return console.log("claim reward",n),await Zu(t.suiClient,t.account.address)}static fromData(t){return new a(t)}};var _a=class a extends w{constructor(t){super(t);this.data=t}data;txType;txSubType;async build(t){let{type:n}=this.data;return console.log("claim reward and supply",n),await tp(t.suiClient,t.account.address)}static fromData(t){return new a(t)}};var np=require("@mysten/sui/transactions");var ep=require("@naviprotocol/lending");async function ne(a){return(0,ep.getPool)(a)}var La=class a extends w{constructor(t){super(t);this.data=t}data;txType;txSubType;async build(t){let{assetId:n,amount:o}=this.data,i=new np.Transaction;console.log("build",this.data);let s=await ne(n);return await Yu(i,s,o,t.account.address)}static fromData(t){return new a(t)}};var op=require("@mysten/sui/transactions");async function un(a,e,t){let n=await a.getCoins({owner:e,coinType:t});return console.log("getTokenObjs",e,n),n}var ja=class a extends w{constructor(t){super(t);this.data=t}data;txType;txSubType;async build(t){let{suiClient:n,account:o}=t,{assetId:i,amount:s}=this.data,c=new op.Transaction;console.log("build",this.data);let m=await ne(i);if(i===0){let[x]=c.splitCoins(c.gas,[s]);return await ln(c,m,x,s)}let b=await un(n,o.address,m.suiCoinType);if(!b.data[0])throw new Error(`Insufficient balance for ${m.suiCoinType} Token`);let S=b.data[0].coinObjectId;if(b.data.length>=2){let x=1;for(;x<b.data.length;)c.mergeCoins(S,[b.data[x].coinObjectId]),x++}return await ln(c,m,c.object(S),s)}static fromData(t){return new a(t)}};var ap=require("@mysten/sui/transactions");var Ua=class a extends w{constructor(t){super(t);this.data=t}data;txType;txSubType;async build(t){let{suiClient:n,account:o}=t,{assetId:i,amount:s}=this.data,c=new ap.Transaction;console.log("build",this.data);let m=await ne(i);if(i===0){let[I]=c.splitCoins(c.gas,[s]);return Ls(c,m,I,s)}let b=await un(n,o.address,m.suiCoinType);if(!b.data[0])throw new Error(`Insufficient balance for ${m.suiCoinType} Token`);let S=b.data[0].coinObjectId;if(b.data.length>=2){let I=1;for(;I<b.data.length;)c.mergeCoins(S,[b.data[I].coinObjectId]),I++}return Ls(c,m,c.object(S),s)}static fromData(t){return new a(t)}};var ip=require("@mysten/sui/transactions");var qa=class a extends w{constructor(t){super(t);this.data=t}data;txType;txSubType;async build(t){let{assetId:n,amount:o}=this.data,i=new ip.Transaction;console.log("build",this.data);let s=await ne(n);return await Ju(i,s,o,t.account.address)}static fromData(t){return new a(t)}};var rp=require("@mysten/sui/transactions");var Fa=class a extends w{constructor(t){super(t);this.data=t}data;txType;txSubType;async build(t){let{suiClient:n,account:o}=t,{list:i}=this.data,s=new rp.Transaction;console.log("build",this.data);for(let c=0;c<i.length;c++){let{assetId:m,amount:b}=i[c],S=await ne(m);if(m===0){let[D]=s.splitCoins(s.gas,[b]);await ln(s,S,D,b);continue}let I=await un(n,o.address,S.suiCoinType);if(!I.data[0])throw new Error(`Insufficient balance for ${S.suiCoinType} Token`);let x=I.data[0].coinObjectId;if(I.data.length>=2){let D=1;for(;D<I.data.length;)s.mergeCoins(x,[I.data[D].coinObjectId]),D++}await ln(s,S,s.object(x),b)}return s}static fromData(t){return new a(t)}};var sp=require("@mysten/sui/transactions");var Ka=class a extends w{constructor(t){super(t);this.data=t}data;txType;txSubType;async build(t){return console.log("build",this.data),sp.Transaction.from(this.data.content)}static fromData(t){return new a(t)}};var Va=class{application="navi";supportSDK="@mysten/sui";async deserialize(e){if(await Ws(),e.appContext?.content)return{txType:js.TransactionType.Other,txSubType:"PlainTransaction",intentionData:{content:e.appContext.content,scene:e.appContext.scene||"unknown"}};let{transaction:t}=e,o=new Ea(t).decode();return{txType:js.TransactionType.Other,txSubType:o.type,intentionData:o.intentionData}}async build(e){let{suiClient:t,account:n}=e,o;switch(await Ws(),e.txSubType){case"EntryDeposit":o=ja.fromData(e.intentionData);break;case"EntryBorrow":o=La.fromData(e.intentionData);break;case"EntryRepay":o=Ua.fromData(e.intentionData);break;case"EntryWithdraw":o=qa.fromData(e.intentionData);break;case"EntryMultiDeposit":o=Fa.fromData(e.intentionData);break;case"ClaimReward":o=Wa.fromData(e.intentionData);break;case"EntryClaimAndDeposit":o=_a.fromData(e.intentionData);break;case"PlainTransaction":o=Ka.fromData(e.intentionData);break;default:throw new Error("not implemented")}return o.build({suiClient:t,account:n})}};var Xn=require("@msafe/sui3-utils"),cp=require("@mysten/bcs"),lp=require("@mysten/sui/transactions"),up=Mt(require("sort-keys-recursive")),pp="msafe-plain-tx",mp=Xn.TransactionSubTypes.others.plain,Us=class a{constructor(e){this.data=e}data;application=pp;txType=Xn.TransactionType.Other;txSubType=mp;serialize(){return JSON.stringify((0,up.default)(this.data))}async build(e){return lp.Transaction.from((0,cp.fromHex)(this.data.content))}static fromData(e){return new a(e)}},$a=class{application;supportSDK="@mysten/sui";constructor(){this.application=pp}async deserialize(e){let{content:t}=e.appContext;return{txType:Xn.TransactionType.Other,txSubType:mp,intentionData:{content:t}}}async build(e){let{suiClient:t,network:n,account:o}=e;return Us.fromData(e.intentionData).build({suiClient:t,network:n,account:o})}};var mn=require("@mysten/sui/transactions"),zn=require("@mysten/sui.js/client");var pn=require("@open-rpc/client-js");var Uf={"-32700":"ParseError","-32600":"InvalidRequest","-32601":"MethodNotFound","-32602":"InvalidParams","-32603":"InternalError"},qs=class extends Error{},Ga=class extends qs{code;type;constructor(e,t){super(e),this.code=t,this.type=Uf[t]??"ServerError"}};function qf(a){let e=new URL(a);return e.protocol=e.protocol.replace("http","ws"),e.toString()}var Ff={WebSocketConstructor:typeof WebSocket<"u"?WebSocket:void 0,callTimeout:3e4,reconnectTimeout:3e3,maxReconnects:5},Ha=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={...Ff,...t},this.endpoint&&this.endpoint.startsWith("http")&&(this.endpoint=qf(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 Ga(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 Fs(e);return this.#i.add(t),await t.subscribe(this),()=>t.unsubscribe(this)}},Fs=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 ue=class{rpcClient;websocketClient;constructor({url:e,websocket:{url:t,...n}={},rpc:o}){let i=new pn.HTTPTransport(o?.url??e,{headers:{"Content-Type":"application/json",...o?.headers}});this.rpcClient=new pn.Client(new pn.RequestManager([i])),this.websocketClient=new Ha(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 Kf="0x2::sui::SUI",Gs=1e8,Xa=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;case"@mysten/sui-v2":t.addGrpcHelper(o);break;default:{let i=o;throw new Error(`${i.application}: ${i.supportSDK} SDK not supported`)}}}return t}addLegacyHelper(e){this.setApp(e.application,new $s(e))}addHelper(e){this.setApp(e.application,new Ks(e))}addGrpcHelper(e){this.setApp(e.application,new Vs(e))}getAppHelper(e){let t=this.apps.get(e);if(!t)throw new Error(`${e} not registered`);return t}setApp(e,t){this.apps.set(e,t)}},Ks=class{constructor(e){this.helper=e}helper;async deserialize(e){let t=new H.SuiJsonRpcClient({network:kn(e.network),transport:new ue({url:e.clientUrl,rpc:{url:e.clientUrl}})}),n=new zn.SuiClient({transport:new ue({url:e.clientUrl,rpc:{url:e.clientUrl}})}),o=await e.transactionBlock.build({client:n}),i=mn.Transaction.from(o);return this.helper.deserialize({...e,suiClient:t,transaction:i})}async build(e){let t=new H.SuiJsonRpcClient({network:kn(e.network),transport:new ue({url:e.clientUrl,rpc:{url:e.clientUrl}})}),n=await t.getBalance({owner:e.account.address});if(Number(n.totalBalance)<Gs)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 mn.Transaction.from(i)}},Vs=class{constructor(e){this.helper=e}helper;async deserialize(e){let t=An(e.network,e.clientUrl),n=new zn.SuiClient({transport:new ue({url:e.clientUrl,rpc:{url:e.clientUrl}})}),o=await e.transactionBlock.build({client:n}),i=mn.Transaction.from(o);return this.helper.deserialize({...e,suiGrpcClient:t,transaction:i})}async build(e){let t=An(e.network,e.clientUrl),{balance:n}=await t.core.getBalance({owner:e.account.address,coinType:Kf});if(Number(n.balance)<Gs)throw new Error("Insufficient gas fee");let o=await this.helper.build({...e,suiGrpcClient:t});o.setSender(e.account.address);let i=await o.build({client:t});return mn.Transaction.from(i)}},$s=class{constructor(e){this.helper=e}helper;async deserialize(e){let t=new zn.SuiClient({transport:new ue({url:e.clientUrl,rpc:{url:e.clientUrl}})});return this.helper.deserialize({...e,transactionBlock:e.transactionBlock,suiClient:t})}async build(e){let t=new zn.SuiClient({transport:new ue({url:e.clientUrl,rpc:{url:e.clientUrl}})}),n=await t.getBalance({owner:e.account.address});if(Number(n.totalBalance)<Gs)throw new Error("Insufficient gas fee");let i=await(await this.helper.build({...e,suiClient:t})).build({client:t});return mn.Transaction.from(i)}};var Ip=require("@msafe/sui3-utils"),Cp=require("@scallop-io/sui-scallop-sdk");var Bt=require("@msafe/sui3-utils"),zs=require("@scallop-io/sui-scallop-sdk");var dp=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}`))}transaction;scallopClient;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,dp.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 za=require("@mysten/sui/bcs"),ke=require("@mysten/sui/utils"),Hs=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}`,m=`${e.MoveCall.package}::${e.MoveCall.module}::${e.MoveCall.function}`;return c===m?(o.push(s),!0):!1}return!1}),this.cmdIdx=o[n]}moveCall;transaction;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,ke.normalizeSuiAddress)(t)}decodeInputString(e){return this.decodePureArg(e,"String")}decodeInputBool(e){return this.decodePureArg(e,"Bool")}decodePureArg(e,t){let n=this.getInputParam(e);return a.getPureInputValue(n,t)}getInputParam(e){let t=this.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"&&t.kind!=="Result")throw new Error("not nested or result 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=za.bcs[t];return za.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,ke.normalizeSuiAddress)(e.value.Object.ImmOrOwned.objectId)}return(0,ke.normalizeSuiAddress)(e.value)}static getSharedObjectId(e){if(e.type!=="object")throw new Error(`not object argument: ${JSON.stringify(e)}`);if(typeof e.value!="object")return(0,ke.normalizeSuiAddress)(e.value);if(!("Object"in e.value)||!("Shared"in e.value.Object))throw new Error("not Shared");return(0,ke.normalizeSuiAddress)(e.value.Object.Shared.objectId)}static getPureInput(e){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 za.bcs.U64.parse(new Uint8Array(t))}typeArg(e){return(0,ke.normalizeStructTag)(this.txBlockTransactions.typeArguments[e])}txArg(e){return this.transaction.blockData.inputs[e]}},N=Hs;var Xs=class{constructor(e,t){this.splitCoin=e;this.txb=t}splitCoin;txb;getAmountInput(){return this.splitCoin.amounts.map(e=>{if(e.kind==="Input")return Number(N.getPureInputValue(e,"U64"))}).filter(e=>e!==void 0)}},Lt=Xs;var ve=require("@mysten/sui/utils"),fp=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`},dn={id:"0xc63072e7f5f4983a2efaf5bdba1480d5e7d74d57948e1c7cc436f8e22cbeb410",incentivePools:"0x64972b713ccec45ec3964809e477cea6f97350c0c50ca3aec85bb631639266ec",incentiveAccounts:"0x3c0b707068bdcea8bb859d751ad3e2149a9f83c13fcf4054ef91372a00bccdd3"},Ht={unstakeObligation:(a,e,t)=>a.moveCall(`${dn.id}::user::unstake`,[dn.incentivePools,dn.incentiveAccounts,a.object(e),a.object(t),ve.SUI_CLOCK_OBJECT_ID],[(0,ve.normalizeStructTag)(ve.SUI_TYPE_ARG)]),redeem_rewards:(a,e,t,n)=>a.moveCall(`${dn.id}::user::redeem_rewards`,[dn.incentivePools,dn.incentiveAccounts,a.object(e),a.object(t),ve.SUI_CLOCK_OBJECT_ID],[(0,ve.normalizeStructTag)(n)])};var hp=(a,e)=>{let t=[];for(let n=0;n<a.length;n+=e)t.push(a.slice(n,n+e));return t};var Qa=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(`${zs.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,`${zs.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:Bt.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:Bt.TransactionType.Other,type:"MigrateAndClaim",intentionData:{obligationKey:t,obligationId:n,rewardCoinName:o,veScaKey:e}}}decodeOpenObligation(){return{txType:Bt.TransactionType.Other,type:"OpenObligation",intentionData:{}}}decodeSupplyLending(){let e=this.utils.parseCoinNameFromType(this.helperMint.typeArg(0)),t=this.helperMint.getNestedInputParam(2),n=new Lt(t,this.transaction).getAmountInput().reduce((o,i)=>o+i,0);return{txType:Bt.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 Lt(t,this.transaction).getAmountInput().reduce((o,i)=>o+i,0);return{txType:Bt.TransactionType.Other,type:"WithdrawLending",intentionData:{amount:n,coinName:e}}}decodeWithdrawLendingScoin(){let e=this.utils.parseCoinNameFromType(this.helperRedeem.typeArg(0)),t=this.helperBurnScoin.getNestedInputParam(1),n=new Lt(t,this.transaction).getAmountInput().reduce((o,i)=>o+i,0);return{txType:Bt.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 Lt(t,this.transaction).getAmountInput().reduce((i,s)=>i+s,0),o=this.helperDepositCollateral.decodeSharedObjectId(1);return{txType:Bt.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:Bt.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:Bt.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:Bt.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:Bt.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 Lt(t,this.transaction).getAmountInput().reduce((i,s)=>i+s,0),o=this.helperRepay.decodeSharedObjectId(1);return{txType:Bt.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 Lt(n,this.transaction).getAmountInput().reduce((s,c)=>s+c,0),i=this.helperRepay.decodeSharedObjectId(1);return{txType:Bt.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 Lt(i,this.transaction).getAmountInput().reduce((s,c)=>s+c,0)}if(this.helperStake.moveCall&&t===0){let i=this.helperStake.getNestedInputParam(2);t=new Lt(i,this.transaction).getAmountInput().reduce((s,c)=>s+c,0)}let n=this.helperStake.typeArg(0),o=this.utils.parseCoinNameFromType(n);return{txType:Bt.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:Bt.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 Lt(t,this.transaction).getAmountInput().reduce((i,s)=>i+s,0),o;return this.isCreateStakeAccountTransaction()||(o=this.helperStake.decodeOwnedObjectId(1)),{txType:Bt.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 Lt(o,this.transaction).getAmountInput().reduce((i,s)=>i+s,0)}return{txType:Bt.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:Bt.TransactionType.Other,type:"ClaimIncentiveReward",intentionData:{lendingIncentive:e,borrowIncentiveV2:t,borrowIncentive:n}}}};var Ja=require("@msafe/sui3-utils");var Ya=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 oe=require("@msafe/sui3-utils"),gp=require("@scallop-io/sui-scallop-sdk");var Za=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(m=>m.$kind==="TransferObjects");if(e.length!==1)return!1;let{objects:t}=e[0].TransferObjects,n=t.filter(m=>m.$kind==="Input").map(({Input:m})=>m);if(n.length!==t.length)return!1;let o=new Set(n),i=this.inputs.filter((m,b)=>m.$kind==="Object"&&o.has(b)).map(m=>m.Object.ImmOrOwnedObject),s=`${this.coreId.veScaObjId}::ve_sca::VeScaKey`,c=hp(i.map(({objectId:m})=>m),50);for(let m=0;m<c.length;m++){let b=c[m];if((await this.scallopClient.scallopSuiKit.queryGetObjects(b,{showType:!0})).some(I=>I.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,`${gp.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(m=>{this.filterMoveCallCommands(m,e)?(o.push({action:"unstake",helper:new N(m,this.transaction,i)}),i++):this.filterMoveCallCommands(m,t)?(o.push({action:"stake",helper:new N(m,this.transaction,s)}),s++):this.filterMoveCallCommands(m,n)&&(o.push({action:"deactivate",helper:new N(m,this.transaction,c)}),c++)}),o}decodeRedeemSca(){let e=this.helperRedeemSca.decodeOwnedObjectId(1);return{txType:oe.TransactionType.Other,type:"RedeemSca",intentionData:{veScaKey:e}}}decodeRenewExpiredVeSca(){let e=this.helperRenewExpired.getNestedInputParam(4),t=this.helperRenewExpired.decodeInputU64(5),n=new Lt(e,this.transaction).getAmountInput().reduce((k,M)=>k+M,0),o=this.helperRenewExpired.decodeOwnedObjectId(1),i=!!this.helperRedeemSca.moveCall,s=[],c=[],m=[];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&&(m=[this.helperStakeObligationWithVeSca.decodeOwnedObjectId(3),this.helperStakeObligationWithVeSca.decodeSharedObjectId(4)]);let b=!1,S=!1,I,x,D=[{condition:s,isOld:!0},{condition:c,isOld:!1},{condition:m,isOld:!1}];for(let k=0;k<D.length;k++)D[k].condition.length>1&&([x,I]=D[k].condition,b=!0,S=D[k].isOld);return{txType:oe.TransactionType.Other,type:"RenewExpStakePeriod",intentionData:{amount:n,unlockTime:t,obligationId:I,obligationKey:x,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,m,b,S=[{condition:n,isOld:!0},{condition:o,isOld:!1},{condition:i,isOld:!1}];for(let I=0;I<S.length;I++)S[I].condition.length>1&&([b,m]=S[I].condition,s=!0,c=S[I].isOld);return{txType:oe.TransactionType.Other,type:"ExtendStakePeriod",intentionData:{unlockTime:e,obligationId:m,obligationKey:b,veScaKey:t,isObligationLocked:s,isOldBorrowIncentive:c}}}decodePeriodAndStakeMoreSca(){let e=this.helperStakeMoreSca.getNestedInputParam(4),t=this.helperExtendStakePeriod.decodeInputU64(4),n=new Lt(e,this.transaction).getAmountInput().reduce((D,k)=>D+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 m=!1,b=!1,S,I,x=[{condition:o,isOld:!0},{condition:i,isOld:!1},{condition:c,isOld:!1}];for(let D=0;D<x.length;D++)x[D].condition.length>1&&([I,S]=x[D].condition,m=!0,b=x[D].isOld);return{txType:oe.TransactionType.Other,type:"ExtendPeriodAndStakeMore",intentionData:{amount:n,veScaKey:s,unlockTime:t,obligationId:S,obligationKey:I,isOldBorrowIncentive:b,isObligationLocked:m}}}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 Lt(e,this.transaction).getAmountInput().reduce((D,k)=>D+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 m=!1,b=!1,S,I,x=[{condition:o,isOld:!0},{condition:i,isOld:!1},{condition:c,isOld:!1}];for(let D=0;D<x.length;D++)x[D].condition.length>1&&([I,S]=x[D].condition,m=!0,b=x[D].isOld);return{txType:oe.TransactionType.Other,type:"StakeSca",intentionData:{amount:n,unlockTime:t,obligationId:S,obligationKey:I,veScaKey:s,isObligationLocked:m,isOldBorrowIncentive:b}}}decodeMergeVesca(){let e=this.getMergeSplitVeScaHelper("merge"),t={targetVeScaKey:e.decodeOwnedObjectId(1),sourceVeScaKey:e.decodeOwnedObjectId(2)};return{txType:oe.TransactionType.Other,type:"MergeVeSca",intentionData:t}}decodeSplitVesca(){let e=this.getMergeSplitVeScaHelper("split"),t={targetVeScaKey:e.decodeOwnedObjectId(1),splitAmount:e.decodeInputU64(4)};return{txType:oe.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:oe.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:oe.TransactionType.Other,type:"TransferVeScaKeys",intentionData:{veScaKeys:i}}}};var yp=Mt(require("sort-keys-recursive")),A=class{constructor(e){this.data=e}data;get application(){return"msafe-core"}serialize(){return JSON.stringify((0,yp.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 ti=class a extends A{constructor(t){super(t);this.data=t}data;txType;txSubType;async borrow({account:t,scallopClient:n}){let{coinName:o,amount:i,obligationId:s,obligationKey:c}=this.data,m=t.address;return(await this.buildTxWithRefreshObligation(n,{walletAddress:m,obligationId:s,obligationKey:c},async(S,I)=>{let x=await I.borrowQuick(+i,o,s,c);I.transferObjects([x],m)})).txBlock}async build(t){return this.borrow(t)}static fromData(t){return new a(t)}};var ei=class a extends A{constructor(t){super(t);this.data=t}data;txType;txSubType;async borrowWithBoost(t,n){let{obligationId:o,obligationKey:i,veScaKey:s,amount:c,coinName:m}=this.data;return(await this.buildTxWithRefreshObligation(t,{walletAddress:n,obligationId:o,obligationKey:i,veScaKey:s},async(S,I)=>{let x=await I.borrowQuick(+c,m,o,i);I.transferObjects([x],n)})).txBlock}async build(t){return this.borrowWithBoost(t.scallopClient,t.account.address)}static fromData(t){return new a(t)}};var ni=class a extends A{constructor(t){super(t);this.data=t}data;txType;txSubType;async borrowWithReferral({account:t,scallopClient:n}){let o=t.address,{obligationId:i,obligationKey:s,veScaKey:c,coinName:m,amount:b}=this.data;return(await this.buildTxWithRefreshObligation(n,{walletAddress:o,obligationId:i,obligationKey:s,veScaKey:c},async(I,x)=>{let D=x.claimReferralTicket(m),k=await x.borrowWithReferralQuick(+b,m,D,i,s);x.burnReferralTicket(D,m),x.transferObjects([k],o)})).txBlock}async build(t){return this.borrowWithReferral(t)}static fromData(t){return new a(t)}};var bp=require("@mysten/sui/utils");var oi=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)??[]),m=(()=>{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 M=e.utils.parseMarketCoinName(k.coinName);return D[M]||(D[M]=0),D[M]+=k.availableClaimCoin,D},{})})(),b={};Object.entries(o).forEach(([x,D])=>{for(let k=0;k<D.length;k++){let M=D[k];if(!m[x])continue;let L=n.claim(M.id,x);b.sui?b.sui.push(L):b.sui=[L]}});let S=(()=>{let x={};return x.sui=Object.values(m).reduce((D,k)=>D+k,0),c.forEach(D=>{Object.values(D.borrowIncentives).forEach(k=>{k&&k.rewards.forEach(M=>{x[M.coinName]||(x[M.coinName]=0),x[M.coinName]?x[M.coinName]+=M.availableClaimCoin:x[M.coinName]=M.availableClaimCoin})})}),x})();if(s.length>0&&c.length>0)for(let x=0;x<c.length;x++){let D=c[x],k=!1,M=s.find(U=>U.id===D.obligationId)?.keyId,L={};if(M){if(Object.values(D.borrowIncentives).forEach(U=>{if(U){let q=U.rewards.filter(Pt=>{let W=Pt.coinName;return Pt.availableClaimCoin>0&&!L[W]});k=q.length>0,q.forEach(Pt=>{let W=n.claimBorrowIncentive(D.obligationId,M,Pt.coinName);L[Pt.coinName]=!0,b[Pt.coinName]?b[Pt.coinName].push(W):b[Pt.coinName]=[W]})}}),S.sui>0){let U=Ht.redeem_rewards(n,M,D.obligationId,bp.SUI_TYPE_ARG);b.sui?b.sui.push(U):b.sui=[U]}if(k&&await fp(e.query,D.obligationId)){n.unstakeObligation(D.obligationId,M);let q=await e.query.getBindedVeScaKey(D.obligationId);q?n.stakeObligationWithVesca(D.obligationId,M,q):n.stakeObligation(D.obligationId,M)}}}let I=(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 I.length>0&&n.transferObjects(I,t),n.txBlock}async build(e){return this.claimIncentiveRewards(e.scallopClient,e.account.address)}static fromData(e={}){return new a(e)}};var ai=class a extends A{constructor(t){super(t);this.data=t}data;txType;txSubType;async build(t){return await t.scallopClient.depositCollateral(this.data.collateralCoinName,+this.data.amount,!1,this.data.obligationId)}static fromData(t){return new a(t)}};var ii=class a extends A{constructor(t){super(t);this.data=t}data;txType;txSubType;async migrateAndClaim({account:t,scallopClient:n}){let o=t.address,{obligationKey:i,obligationId:s,rewardCoinName:c,veScaKey:m}=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),m?await b.stakeObligationWithVeScaQuick(s,i,m):await b.stakeObligationQuick(s,i),b.txBlock}async build(t){return this.migrateAndClaim(t)}static fromData(t){return new a(t)}};var ri=class a extends A{constructor(t){super(t);this.data=t}data;txType;txSubType;async build(t){return await t.scallopClient.migrateAllMarketCoin(!1,!1)}static fromData(t){return new a(t)}};var si=class a extends A{constructor(t){super(t);this.data=t}data;txType;txSubType;async build(t){return await t.scallopClient.openObligation(!1)}static fromData(t){return new a(t)}};var ci=class a extends A{constructor(t){super(t);this.data=t}data;txType;txSubType;async repay({account:t,scallopClient:n}){let o=t.address,{coinName:i,amount:s,obligationId:c,obligationKey:m}=this.data;return(await this.buildTxWithRefreshObligation(n,{walletAddress:o,obligationId:c,obligationKey:m},async(S,I)=>{await I.repayQuick(+s,i,c)})).txBlock}async build(t){return this.repay(t)}static fromData(t){return new a(t)}};var li=class a extends A{constructor(t){super(t);this.data=t}data;txType;txSubType;async repayWithBoost({account:t,scallopClient:n}){let o=t.address,{coinName:i,amount:s,obligationId:c,veScaKey:m}=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,m),b.txBlock}async build(t){return this.repayWithBoost(t)}static fromData(t){return new a(t)}};var ui=class a extends A{constructor(t){super(t);this.data=t}data;txType;txSubType;async build(t){return await t.scallopClient.deposit(this.data.coinName,+this.data.amount,!1,t.account.address)}static fromData(t){return new a(t)}};var pi=class a extends A{constructor(t){super(t);this.data=t}data;txType;txSubType;async build(t){return await t.scallopClient.unstake(this.data.marketCoinName,+this.data.amount,!1)}static fromData(t){return new a(t)}};var mi=class a extends A{constructor(t){super(t);this.data=t}data;txType;txSubType;async unstakeAndWithdraw(t,n,o){let i=t.builder.createTxBlock();i.setSender(o);let{stakeAccountId:s,amount:c,coinName:m}=this.data,b=[];for(let S=0;S<s.length;S++){let{id:I,coin:x}=s[S],D=t.utils.parseMarketCoinName(m),[k]=await i.unstakeQuick(x,D,I,!1);if(k){let M=i.withdraw(k,m);b.push(M)}}if(c>0){let S=await i.withdrawQuick(c,m);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 di=class a extends A{constructor(t){super(t);this.data=t}data;txType;txSubType;async build(t){return await 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 fi=class a extends A{constructor(t){super(t);this.data=t}data;txType;txSubType;async build(t){return await t.scallopClient.withdraw(this.data.coinName,Number(this.data.amount),!1,t.account.address)}static fromData(t){return new a(t)}};var hi=class a extends A{constructor(t){super(t);this.data=t}data;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 gi=class a extends A{constructor(t){super(t);this.data=t}data;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 m=i.map(b=>n.utils.parseCoinNameFromType(b));return await c.claimReferralRevenueQuick(o,m),c.txBlock}async build(t){return this.claimRevenueReferral(t)}static fromData(t){return new a(t)}};var yi=class a extends A{constructor(t){super(t);this.data=t}data;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 Tp=require("@scallop-io/sui-scallop-sdk");var bi=class a extends A{constructor(t){super(t);this.data=t}data;txType;txSubType;async extendPeriodAndStakeMoreSca({account:t,scallopClient:n}){let{amount:o,veScaKey:i,unlockTime:s,obligationId:c,obligationKey:m,isOldBorrowIncentive:b,isObligationLocked:S}=this.data,I=t.address,x=n.builder.createTxBlock();x.setSender(I);let D=await n.utils.selectCoins(o,Tp.SCA_COIN_TYPE,I),[k,M]=x.takeAmountFromCoins(D,o);return x.extendLockPeriod(i,s),x.extendLockAmount(i,k),x.transferObjects([M],I),!c||!m||(S&&(b?Ht.unstakeObligation(x,c,m):x.unstakeObligation(c,m)),x.stakeObligationWithVesca(c,m,i)),x.txBlock}async build(t){return this.extendPeriodAndStakeMoreSca(t)}static fromData(t){return new a(t)}};var Ti=class a extends A{constructor(t){super(t);this.data=t}data;txType;txSubType;async extendStakeScaLockPeriod({account:t,scallopClient:n}){let o=t.address,{veScaKey:i,unlockTime:s,obligationId:c,obligationKey:m,isObligationLocked:b,isOldBorrowIncentive:S}=this.data,I=n.builder.createTxBlock();return I.setSender(o),I.extendLockPeriod(i,s),c&&m&&(b&&(S?Ht.unstakeObligation(I,m,c):I.unstakeObligation(c,m)),I.stakeObligationWithVesca(c,m,i)),I.txBlock}async build(t){return this.extendStakeScaLockPeriod(t)}static fromData(t){return new a(t)}};var Si=class a extends A{constructor(t){super(t);this.data=t}data;txType;txSubType;async handleUnsubForKeys(t,n,o){let{targetVeScaKey:i,sourceVeScaKey:s}=this.data,[c,m]=await Promise.all([n.getBindedObligationId(i),n.getBindedObligationId(s)]);c&&await t.unstakeObligationQuick(c),m&&await t.unstakeObligationQuick(m),o(t,i,s),c&&await t.stakeObligationWithVeScaQuick(c,void 0,i),m&&await t.stakeObligationWithVeScaQuick(m,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,m)=>{s.mergeVeSca(i.object(c),i.object(m))}),i.txBlock}static fromData(t){return new a(t)}};var wi=class a extends A{constructor(t){super(t);this.data=t}data;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 Sp=require("@scallop-io/sui-scallop-sdk");var Ii=class a extends A{constructor(t){super(t);this.data=t}data;txType;txSubType;async renewExpiredStakeSca({account:t,scallopClient:n}){let o=t.address,{amount:i,unlockTime:s,veScaKey:c,isHaveRedeem:m,obligation:b,obligationKey:S,isObligationLocked:I,isOldBorrowIncentive:x}=this.data,D=n.builder.createTxBlock();if(D.setSender(o),m){let U=D.redeemSca(c);D.transferObjects([U],o)}let k=await n.builder.utils.selectCoins(i,Sp.SCA_COIN_TYPE,o),[M,L]=D.takeAmountFromCoins(k,i);return D.transferObjects([L],o),D.renewExpiredVeSca(c,M,s),!b||!S||(I&&(x?Ht.unstakeObligation(D,S,b):D.unstakeObligation(b,S)),D.stakeObligationWithVesca(b,S,c)),D.txBlock}async build(t){return this.renewExpiredStakeSca(t)}static fromData(t){return new a(t)}};var Ci=class a extends A{constructor(t){super(t);this.data=t}data;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,m)=>{let b=s.splitVeSca(c,m.toString());s.transferObjects([b],o)}),i.txBlock}static fromData(t){return new a(t)}};var wp=require("@scallop-io/sui-scallop-sdk");var xi=class a extends A{constructor(t){super(t);this.data=t}data;txType;txSubType;async stakeSca({account:t,scallopClient:n}){let o=t.address,{amount:i,isObligationLocked:s,isOldBorrowIncentive:c,obligationId:m,obligationKey:b,unlockTime:S,veScaKey:I}=this.data,x=n.builder.createTxBlock();x.setSender(o);let D=await n.utils.selectCoins(i,wp.SCA_COIN_TYPE,o),[k,M]=x.takeAmountFromCoins(D,i),L;return I?x.extendLockAmount(I,k):L=x.lockSca(k,S),m&&b&&(s&&(c?Ht.unstakeObligation(x,b,m):x.unstakeObligation(m,b)),x.stakeObligationWithVesca(m,b,I||L)),I||x.transferObjects([L,M],o),x.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}data;txType;txSubType;async supplyAndStake({account:t,scallopClient:n}){let o=t.address,{amount:i,coinName:s,stakeAccountId:c}=this.data,m=n.builder.createTxBlock();m.setSender(o);let b=await m.depositQuick(+i,s),S=n.utils.parseMarketCoinName(s);if(n.constants.whitelist.spool.has(S))return m.txBlock;let I=await n.query.getStakeAccounts(S,o),x=c||(I.length>0?I[0].id:void 0);if(x)await m.stakeQuick(b,S,x);else{let D=m.createStakeAccount(S);await m.stakeQuick(b,S,D),m.transferObjects([D],o)}return m.txBlock}async build(t){return this.supplyAndStake(t)}static fromData(t){return new a(t)}};var ki=class a extends A{constructor(t){super(t);this.data=t}data;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 vi=class a extends A{constructor(t){super(t);this.data=t}data;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 Ai=class a extends A{constructor(t){super(t);this.data=t}data;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 Mi=class{application="scallop";supportSDK="@mysten/sui";scallopClient;async initScallopClient(e,t){if(!this.scallopClient){let n=new Cp.Scallop({addressId:"695fcdc084f790c04eb068dc",walletAddress:e,suiClients:[t],fullnodeUrls:[t.transport.rpcClient.requestManager.transports[0]?.uri??(0,H.getJsonRpcFullnodeUrl)("mainnet")]});this.scallopClient=await n.createScallopClient()}}async deserialize(e){let{transaction:t,suiClient:n,account:o}=e;await this.initScallopClient(o.address,n);let i=new Qa(t,this.scallopClient),s=new Ya(t,this.scallopClient),c=new Za(t,this.scallopClient),m=i.decode()||s.decode()||await c.decode();if(!m)throw new Error("Unknown transaction type");return{txType:Ip.TransactionType.Other,txSubType:m.type,intentionData:m.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=ui.fromData(s);break;case"WithdrawLending":c=fi.fromData(s);break;case"Borrow":c=ti.fromData(s);break;case"Repay":c=ci.fromData(s);break;case"DepositCollateral":c=ai.fromData(s);break;case"WithdrawCollateral":c=di.fromData(s);break;case"OpenObligation":c=si.fromData(s);break;case"UnstakeSpool":c=pi.fromData(s);break;case"ClaimIncentiveReward":c=oi.fromData(s);break;case"BorrowWithBoost":c=ei.fromData(s);break;case"StakeSca":c=xi.fromData(s);break;case"ExtendStakePeriod":c=Ti.fromData(s);break;case"ExtendPeriodAndStakeMore":c=bi.fromData(s);break;case"RenewExpStakePeriod":c=Ii.fromData(s);break;case"WithdrawStakedSca":c=Ai.fromData(s);break;case"SupplyAndStakeLending":c=Di.fromData(s);break;case"WithdrawAndUnstakeLending":c=mi.fromData(s);break;case"RedeemSca":c=wi.fromData(s);break;case"MigrateAndClaim":c=ii.fromData(s);break;case"BorrowWithReferral":c=ni.fromData(s);break;case"CreateReferralLink":c=yi.fromData(s);break;case"ClaimRevenueReferral":c=gi.fromData(s);break;case"BindReferral":c=hi.fromData(s);break;case"MigrateScoin":c=ri.fromData(s);break;case"RepayWithBoost":c=li.fromData(s);break;case"MergeVeSca":c=Si.fromData(s);break;case"SplitVeSca":c=Ci.fromData(s);break;case"VeScaObligationBindings":{c=ki.fromData(s);break}case"TransferVeScaKeys":{c=vi.fromData(s);break}default:throw new Error("not implemented")}return c.build({suiClient:t,account:n,network:o,scallopClient:this.scallopClient})}};var $p=require("@msafe/sui3-utils");var bn=require("@msafe/sui3-utils"),Me=require("@mysten/sui/utils");var Np=require("@suilend/sui-fe");var Ep=require("@msafe/sui3-utils"),Ae=require("@suilend/sdk");var je=require("@msafe/sui3-utils"),gn=require("@mysten/bcs"),hn=require("@mysten/sui/utils"),Ue=require("@suilend/sui-fe"),Js=Mt(require("bignumber.js"));var Oi=class{constructor(e,t){this.transaction=e;this.simResult=t}transaction;simResult;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,hn.normalizeStructTag)(e.MintEvent.parsedJson.coin_type.name),n=e.MintEvent.parsedJson.liquidity_amount;return console.log("Decoder.decodeDeposit",t,n),{txType:je.TransactionType.Other,type:"deposit",intentionData:{coinType:t,value:n}}}decodeWithdraw(){let e={withdraw_ctokens:this.getMoveCallCommand("withdraw_ctokens")},t={RedeemEvent:this.simResult.events.find(m=>m.type.includes("lending_market::RedeemEvent"))},n=(0,hn.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 Js.default((0,gn.toHex)((0,gn.fromBase64)(this.inputs[i].Pure.bytes)),16).toString(),c=s===Ue.MAX_U64.toString();return console.log("decodeWithdraw - isMax:",c,"inputIndex:",i,"inputValue:",s,"MAX_U64.toString():",Ue.MAX_U64.toString()),c&&(o=Ue.MAX_U64.toString()),{txType:je.TransactionType.Other,type:"withdraw",intentionData:{coinType:n,value:o}}}decodeBorrow(){let e={borrow_request:this.getMoveCallCommand("borrow_request")},t={BorrowEvent:this.simResult.events.find(m=>m.type.includes("lending_market::BorrowEvent"))},n=(0,hn.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 Js.default((0,gn.toHex)((0,gn.fromBase64)(this.inputs[i].Pure.bytes)),16).toString(),c=s===Ue.MAX_U64.toString();return console.log("decodeBorrow - isMax:",c,"inputIndex:",i,"inputValue:",s,"MAX_U64.toString():",Ue.MAX_U64.toString()),c&&(o=Ue.MAX_U64.toString()),{txType:je.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,hn.normalizeStructTag)(e.RepayEvent.parsedJson.coin_type.name),n=e.RepayEvent.parsedJson.liquidity_amount;return console.log("Decoder.decodeRepay",t,n),{txType:je.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,hn.normalizeStructTag)(o.parsedJson.coin_type.name),s=o.parsedJson.liquidity_amount;t[i]=`${+(t[i]??"0")+ +s}`}return console.log("Decoder.decodeClaimRewards",t),{txType:je.TransactionType.Other,type:"claim",intentionData:{value:t}}}decodeClaimAndDeposit(){return{txType:je.TransactionType.Other,type:"claimAndDeposit",intentionData:this.decodeClaim().intentionData}}};var Dp=require("@mysten/sui/transactions");var xp=Mt(require("sort-keys-recursive")),Ft=class{constructor(e){this.data=e}data;serialize(){return JSON.stringify((0,xp.default)(this.data))}};var Pi=class a extends Ft{constructor(t){super(t);this.data=t}data;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 m=new Dp.Transaction;return await i.borrowAndSendToUser(o.address,s.id,c.id,this.data.coinType,this.data.value,m),m}static fromData(t){return console.log("BorrowIntention.fromData",t),new a(t)}};var Mp=require("@mysten/sui/transactions");var kp=require("@mysten/sui/utils"),yn=require("@suilend/sdk"),vp=require("@suilend/sui-fe"),Ap=Mt(require("bignumber.js")),$f=(a,e)=>{let t={[yn.Side.DEPOSIT]:[],[yn.Side.BORROW]:[]};return a.lendingMarket.reserves.forEach(n=>{[yn.Side.DEPOSIT,yn.Side.BORROW].forEach(o=>{let i=o===yn.Side.DEPOSIT?n.depositsPoolRewardManager:n.borrowsPoolRewardManager,s=e.userRewardManagers.find(c=>c.poolRewardManagerId===i.id);s&&(t[o]=i.poolRewards.map((c,m)=>({reserveArrayIndex:n.arrayIndex,rewardIndex:BigInt(m),rewardCoinType:(0,kp.normalizeStructTag)(c.coinType.name),side:o})).filter(c=>!(0,vp.isSendPoints)(c.rewardCoinType)&&!!s.rewards[Number(c.rewardIndex)]&&new Ap.default(s.rewards[Number(c.rewardIndex)].earnedRewards.value.toString()).gt(0)))})}),Object.values(t).flat()},Ri=$f;var Bi=class a extends Ft{constructor(t){super(t);this.data=t}data;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 m=new Mp.Transaction;return i.claimRewardsAndSendToUser(o.address,s.id,Ri(i,c),m),m}static fromData(t){return console.log("ClaimIntention.fromData",t),new a(t)}};var Op=require("@mysten/sui/transactions");var Ei=class a extends Ft{constructor(t){super(t);this.data=t}data;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 m=new Op.Transaction;return i.claimRewardsAndDeposit(o.address,s.id,Ri(i,c),m),m}static fromData(t){return console.log("ClaimAndDepositIntention.fromData",t),new a(t)}};var Pp=require("@mysten/sui/transactions");var Ni=class a extends Ft{constructor(t){super(t);this.data=t}data;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 m=new Pp.Transaction;return await i.depositIntoObligation(o.address,this.data.coinType,this.data.value,m,s?.id),m}static fromData(t){return console.log("DepositIntention.fromData",t),new a(t)}};var Rp=require("@mysten/sui/transactions");var Wi=class a extends Ft{constructor(t){super(t);this.data=t}data;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 m=new Rp.Transaction;return await i.repayIntoObligation(o.address,c.id,this.data.coinType,this.data.value,m),m}static fromData(t){return console.log("RepayIntention.fromData",t),new a(t)}};var Bp=require("@mysten/sui/transactions");var _i=class a extends Ft{constructor(t){super(t);this.data=t}data;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 m=new Bp.Transaction;return await i.withdrawAndSendToUser(o.address,s.id,c.id,this.data.coinType,this.data.value,m),m}static fromData(t){return console.log("WithdrawIntention.fromData",t),new a(t)}};var Li=async(a,e)=>{let t=await Ae.SuilendClient.initialize(Ae.LENDING_MARKET_ID,Ae.LENDING_MARKET_TYPE,a),n=await Ae.SuilendClient.getObligationOwnerCaps(e.address,t.lendingMarket.$typeArgs,a),o=await Promise.all(n.map(i=>Ae.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}},ji=class{application="Suilend";supportSDK="@mysten/sui";utils;async deserialize(e){let{transaction:t,suiClient:n,account:o}=e;this.utils||(this.utils=await Li(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 Oi(t,i).decode();return{txType:Ep.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 Li(i,s));let c;switch(n){case"deposit":c=Ni.fromData(o);break;case"withdraw":c=_i.fromData(o);break;case"borrow":c=Pi.fromData(o);break;case"repay":c=Wi.fromData(o);break;case"claim":c=Bi.fromData(o);break;case"claimAndDeposit":c=Ei.fromData(o);break;default:throw new Error("not implemented")}let m=window.localStorage.getItem("obligationId"),b=this.utils.obligations?.find(I=>I.id===m)??this.utils.obligations?.[0],S=this.utils.obligationOwnerCaps?.find(I=>I.obligationId===b?.id);return c.build({network:t,suiClient:i,account:s,suilendClient:this.utils.suilendClient,obligationOwnerCap:S,obligation:b})}};var Ys=async(a,e)=>{let t=await Li(a,e),n=await fetch(`${Np.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 Ui=class{constructor(e,t){this.transaction=e;this.simResult=t}transaction;simResult;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,Me.normalizeStructTag)(e.MintEvent.parsedJson.event.typename.name),n=e.MintEvent.parsedJson.event.sui_amount_in;return console.log("Decoder.decodeStake",n),{txType:bn.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,Me.normalizeStructTag)(e.MintEvent.parsedJson.event.typename.name),n=e.MintEvent.parsedJson.event.sui_amount_in;return console.log("Decoder.decodeStakeAndDeposit",n),{txType:bn.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,Me.normalizeStructTag)(e.RedeemEvent.parsedJson.event.typename.name),n=(0,Me.normalizeStructTag)(e.MintEvent.parsedJson.event.typename.name),o=e.RedeemEvent.parsedJson.event.lst_amount_in;return console.log("Decoder.decodeConvert",o),{txType:bn.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,Me.normalizeStructTag)(e.RedeemEvent.parsedJson.event.typename.name),n=(0,Me.normalizeStructTag)(e.MintEvent.parsedJson.event.typename.name),o=e.RedeemEvent.parsedJson.event.lst_amount_in;return console.log("Decoder.decodeConvertAndDeposit",o),{txType:bn.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,Me.normalizeStructTag)(e.RedeemEvent.parsedJson.event.typename.name),n=e.RedeemEvent.parsedJson.event.lst_amount_in;return console.log("Decoder.decodeUnstake",n),{txType:bn.TransactionType.Other,type:"unstake",intentionData:{amount:n,inCoinType:t}}}};var _p=require("@mysten/sui/transactions"),Qn=require("@suilend/springsui-sdk");var Wp=Mt(require("sort-keys-recursive")),Xt=class{constructor(e){this.data=e}data;serialize(){return JSON.stringify((0,Wp.default)(this.data))}};var qi=class a extends Xt{constructor(t){super(t);this.data=t}data;txType;txSubType;async build(t){let{suiClient:n,account:o,suilendClient:i,LIQUID_STAKING_INFO_MAP:s,obligationOwnerCap:c,obligation:m}=t;console.log("ConvertIntention.build",n,o,i,s,c,m);let b=await Qn.LstClient.initialize(n,Object.values(s).find(x=>x.type===this.data.inCoinType)),S=await Qn.LstClient.initialize(n,Object.values(s).find(x=>x.type===this.data.outCoinType)),I=new _p.Transaction;return(0,Qn.convertLstsAndRebalanceAndSendToUser)(b,S,I,o.address,this.data.amount),I}static fromData(t){return console.log("ConvertIntention.fromData",t),new a(t)}};var Lp=require("@mysten/sui/transactions"),Ki=require("@suilend/sdk"),Jn=require("@suilend/springsui-sdk");var Fi=class a extends Xt{constructor(t){super(t);this.data=t}data;txType;txSubType;async build(t){let{suiClient:n,account:o,suilendClient:i,LIQUID_STAKING_INFO_MAP:s,obligationOwnerCap:c,obligation:m}=t;console.log("ConvertAndDepositIntention.build",n,o,i,s,c,m);let b=await Jn.LstClient.initialize(n,Object.values(s).find(M=>M.type===this.data.inCoinType)),S=await Jn.LstClient.initialize(n,Object.values(s).find(M=>M.type===this.data.outCoinType)),I=new Lp.Transaction,{obligationOwnerCapId:x,didCreate:D}=(0,Ki.createObligationIfNoneExists)(i,I,c),k=(0,Jn.convertLstsAndRebalance)(b,S,I,o.address,this.data.amount);return i.deposit(k,this.data.outCoinType,x,I),D&&(0,Ki.sendObligationToUser)(x,o.address,I),I}static fromData(t){return console.log("ConvertAndDepositIntention.fromData",t),new a(t)}};var jp=require("@mysten/sui/transactions"),Up=require("@suilend/springsui-sdk");var Vi=class a extends Xt{constructor(t){super(t);this.data=t}data;txType;txSubType;async build(t){let{suiClient:n,account:o,suilendClient:i,LIQUID_STAKING_INFO_MAP:s,obligationOwnerCap:c,obligation:m}=t;console.log("StakeIntention.build",n,o,i,s,c,m);let b=await Up.LstClient.initialize(n,Object.values(s).find(I=>I.type===this.data.outCoinType)),S=new jp.Transaction;return b.mintAmountAndRebalanceAndSendToUser(S,o.address,this.data.amount),S}static fromData(t){return console.log("StakeIntention.fromData",t),new a(t)}};var qp=require("@mysten/sui/transactions"),Gi=require("@suilend/sdk"),Fp=require("@suilend/springsui-sdk");var $i=class a extends Xt{constructor(t){super(t);this.data=t}data;txType;txSubType;async build(t){let{suiClient:n,account:o,suilendClient:i,LIQUID_STAKING_INFO_MAP:s,obligationOwnerCap:c,obligation:m}=t;console.log("StakeAndDepositIntention.build",n,o,i,s,c,m);let b=await Fp.LstClient.initialize(n,Object.values(s).find(k=>k.type===this.data.outCoinType)),S=new qp.Transaction,{obligationOwnerCapId:I,didCreate:x}=(0,Gi.createObligationIfNoneExists)(i,S,c),D=b.mintAmountAndRebalance(S,o.address,this.data.amount);return i.deposit(D,this.data.outCoinType,I,S),x&&(0,Gi.sendObligationToUser)(I,o.address,S),S}static fromData(t){return console.log("StakeAndDepositIntention.fromData",t),new a(t)}};var Kp=require("@mysten/sui/transactions"),Vp=require("@suilend/springsui-sdk");var Hi=class a extends Xt{constructor(t){super(t);this.data=t}data;txType;txSubType;async build(t){let{suiClient:n,account:o,suilendClient:i,LIQUID_STAKING_INFO_MAP:s,obligationOwnerCap:c,obligation:m}=t;console.log("UnstakeIntention.build",n,o,i,s,c,m);let b=await Vp.LstClient.initialize(n,Object.values(s).find(I=>I.type===this.data.inCoinType)),S=new Kp.Transaction;return b.redeemAmountAndRebalanceAndSendToUser(S,o.address,this.data.amount),S}static fromData(t){return console.log("UnstakeIntention.fromData",t),new a(t)}};var Xi=class{application="SpringSui";supportSDK="@mysten/sui";utils;async deserialize(e){let{transaction:t,suiClient:n,account:o}=e;this.utils||(this.utils=await Ys(n,o));let i=await n.devInspectTransactionBlock({sender:o.address,transactionBlock:t});console.log("SpringSuiAppHelper.deserialize",i);let c=new Ui(t,i).decode();return{txType:$p.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 Ys(i,s));let c;switch(n){case"stake":c=Vi.fromData(o);break;case"stakeAndDeposit":c=$i.fromData(o);break;case"convert":c=qi.fromData(o);break;case"convertAndDeposit":c=Fi.fromData(o);break;case"unstake":c=Hi.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 Xp=require("@msafe/sui3-utils");var Zs=require("@msafe/sui3-utils");var zi=class{constructor(e,t){this.transaction=e;this.simResult=t}transaction;simResult;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:Zs.TransactionType.Other,type:"mint",intentionData:{amount:t}}}decodeRedeem(e){let{event:{lst_amount_in:t}}=e;return console.log("Decoder.decodeRedeem",t),{txType:Zs.TransactionType.Other,type:"redeem",intentionData:{amount:t}}}};var Gp=require("@alphafi/stsui-sdk");var Qi=class a extends w{constructor(t){super(t);this.data=t}data;txType;txSubType;async build(t){let{account:n}=t,{amount:o}=this.data,i={lstInfo:"0x1adb343ab351458e151bc392fbf1558b3332467f23bda45ae67cd355a57fd5f5",lstCointype:"0xd1b72982e40348d069bb1ff701e634c117bb5f741f44dff91e472d3b01461e55::stsui::STSUI"},c=await new Gp.LST(i).mint(o,n.address);return c.setGasBudget(1e8),c}static fromData(t){return console.log("MintIntention.fromData",t),new a(t)}};var Hp=require("@alphafi/stsui-sdk");var Ji=class a extends w{constructor(t){super(t);this.data=t}data;txType;txSubType;async build(t){let{account:n}=t,{amount:o}=this.data,i={lstInfo:"0x1adb343ab351458e151bc392fbf1558b3332467f23bda45ae67cd355a57fd5f5",lstCointype:"0xd1b72982e40348d069bb1ff701e634c117bb5f741f44dff91e472d3b01461e55::stsui::STSUI"},c=await new Hp.LST(i).redeem(o,n.address);return c.setGasBudget(1e8),c}static fromData(t){return console.log("RedeemIntention.fromData",t),new a(t)}};var Yi=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 zi(t,o).decode();return{txType:Xp.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=Qi.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 bm=require("@msafe/sui3-utils"),Tm=require("turbos-clmm-sdk");var jt=require("@msafe/sui3-utils"),qe=require("@mysten/bcs"),Fe=require("@mysten/sui/bcs"),zp=require("turbos-clmm-sdk");var zt={PackageId:"0x02fe4933f4521250e55a15441096d1d4a38a7311195b0bca126fc0138c1f5a97",Claim:"0x0c822cec42f7ca703696b4232f1c47b348330c23580172a29aab465bc071d894",turbosCoinType:"0x5d1f47ea69bb0de31c313d7acf89b890dbb8991ea8e03c6c355171f84bb1ba4a::turbos::TURBOS"},Qt={PackageId:"0xdee9"};var zf=(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}`)}},Zi=class{constructor(e,t,n){this.txb=e;this.turbosSdk=t;this.config=n}txb;turbosSdk;config;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(`${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(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=zf(t,n,this.swap1Layer,this.swap2Layer),i=o.map((D,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 zp.BN(L.toString()));return{pool:M,a2b:D,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],m=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)),I=this.helper.decodeInputU64(this.helper.getInputsIndex(2+t)),x=this.helper.decodeInputU64(this.helper.getInputsIndex(3+t));return{txType:jt.TransactionType.Other,type:"Swap",intentionData:{routes:i,coinTypeA:s,coinTypeB:c,address:m,amountA:S?I:x,amountB:S?x:I,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)),m=this.helper.decodeInputBool(this.helper.getInputsIndex(7)),b=this.helper.decodeInputU64(this.helper.getInputsIndex(13));return{txType:jt.TransactionType.Other,type:"AddLiquidity",intentionData:{pool:e,slippage:30,address:t,amountA:n,amountB:o,tickLower:s?-i:i,tickUpper:m?-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:jt.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:jt.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:jt.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:jt.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)),m=s.decodeInputU64(s.getInputsIndex(5));o[c]=m});let i=this.helper.decodeInputU64(7);return{txType:jt.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:jt.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)),m=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 S=this.collectFeeHelper.decodeInputU64(this.collectFeeHelper.getInputsIndex(3))||0,I=this.collectFeeHelper.decodeInputU64(this.collectFeeHelper.getInputsIndex(4))||0;return{txType:jt.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:I,rewardAmounts:b,deadline:m}}}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),m=this.collectRewardHelper.map(I=>I.decodeInputU64(5)),b=this.collectFeeHelper.decodeInputU64(3)||0,S=this.collectFeeHelper.decodeInputU64(4)||0;return{txType:jt.TransactionType.Other,type:"removeLiquidityWithReturn",intentionData:{pool:t,decreaseLiquidity:o,nft:n,amountA:i,amountB:s,slippage:10,address:e,collectAmountA:b,collectAmountB:S,rewardAmounts:m,deadline:c}}}decodePrixClaim(){return{txType:jt.TransactionType.Other,type:"PrixClaim",intentionData:{}}}decodePrixJoin(){return{txType:jt.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:jt.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:jt.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 Oe(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 Oe(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 Oe(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 Oe(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 Oe(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 Oe(e,this.txb)}},Oe=class{constructor(e,t){this.moveCall=e;this.txb=t}moveCall;txb;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(Fe.bcs.u128().parse(Uint8Array.from((0,qe.fromBase64)(this.inputs[e].Pure.bytes))))}decodeInputU64(e){return Number(Fe.bcs.u64().parse(Uint8Array.from((0,qe.fromBase64)(this.inputs[e].Pure.bytes))))}decodeInputU32(e){return Number(Fe.bcs.u32().parse(Uint8Array.from((0,qe.fromBase64)(this.inputs[e].Pure.bytes))))}decodeInputU8(e){return Number(Fe.bcs.u8().parse(Uint8Array.from((0,qe.fromBase64)(this.inputs[e].Pure.bytes))))}decodeInputAddress(e){return Fe.bcs.Address.parse(Uint8Array.from((0,qe.fromBase64)(this.inputs[e].Pure.bytes)))}decodeInputBool(e){return Fe.bcs.bool().parse(Uint8Array.from((0,qe.fromBase64)(this.inputs[e].Pure.bytes)))}shortTypeArg(e){return this.moveCall.MoveCall.typeArguments[e]}txArg(e){return this.moveCall.MoveCall.arguments[e]}};var Qp=require("turbos-clmm-sdk");var tr=class a extends w{constructor(t){super(t);this.data=t}data;txType;txSubType;async build(t){let n=new Qp.TurbosSdk(t.network.replace("sui:",""),t.suiClient),{pool:o,address:i,amountA:s,amountB:c,slippage:m,tickLower:b,tickUpper:S,deadline:I,txb:x}=this.data;return n.pool.addLiquidity({pool:o,slippage:m,address:i,amountA:s,amountB:c,tickLower:b,tickUpper:S,deadline:I,txb:x})}static fromData(t){return new a(t)}};var Jp=require("turbos-clmm-sdk");var er=class a extends w{constructor(t){super(t);this.data=t}data;txType;txSubType;async build(t){let n=new Jp.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 Yp=require("turbos-clmm-sdk");var nr=class a extends w{constructor(t){super(t);this.data=t}data;txType;txSubType;async build(t){let n=new Yp.TurbosSdk(t.network.replace("sui:",""),t.suiClient),{pool:o,address:i,nft:s,collectAmountA:c,collectAmountB:m,deadline:b,txb:S}=this.data;return n.pool.collectFee({pool:o,address:i,collectAmountA:c,collectAmountB:m,nft:s,deadline:b,txb:S})}static fromData(t){return new a(t)}};var Zp=require("turbos-clmm-sdk");var or=class a extends w{constructor(t){super(t);this.data=t}data;txType;txSubType;async build(t){let n=new Zp.TurbosSdk(t.network.replace("sui:",""),t.suiClient),{pool:o,address:i,nft:s,rewardAmounts:c,deadline:m,txb:b}=this.data;return n.pool.collectReward({pool:o,address:i,rewardAmounts:c,nft:s,deadline:m,txb:b})}static fromData(t){return new a(t)}};var tm=require("turbos-clmm-sdk");var ar=class a extends w{constructor(t){super(t);this.data=t}data;txType;txSubType;async build(t){let n=new tm.TurbosSdk(t.network.replace("sui:",""),t.suiClient),{fee:o,address:i,tickLower:s,tickUpper:c,sqrtPrice:m,slippage:b,coinTypeA:S,coinTypeB:I,amountA:x,amountB:D,deadline:k,txb:M}=this.data;return n.pool.createPool({fee:o,amountA:x,amountB:D,address:i,tickLower:s,tickUpper:c,sqrtPrice:m,slippage:b,coinTypeA:S,coinTypeB:I,deadline:k,txb:M})}static fromData(t){return new a(t)}};var em=require("turbos-clmm-sdk");var ir=class a extends w{constructor(t){super(t);this.data=t}data;txType;txSubType;async build(t){let n=new em.TurbosSdk(t.network.replace("sui:",""),t.suiClient),{pool:o,address:i,amountA:s,amountB:c,slippage:m,nft:b,decreaseLiquidity:S,deadline:I,txb:x}=this.data;return n.pool.decreaseLiquidity({pool:o,slippage:m,address:i,amountA:s,amountB:c,nft:b,decreaseLiquidity:S,deadline:I,txb:x})}static fromData(t){return new a(t)}};var nm=require("turbos-clmm-sdk");var rr=class a extends w{constructor(t){super(t);this.data=t}data;txType;txSubType;async build(t){let n=new nm.TurbosSdk(t.network.replace("sui:",""),t.suiClient),{pool:o,address:i,amountA:s,amountB:c,slippage:m,nft:b,decreaseLiquidity:S,deadline:I}=this.data,{txb:x,coinA:D,coinB:k}=await n.pool.decreaseLiquidityWithReturn({pool:o,slippage:m,address:i,amountA:s,amountB:c,nft:b,decreaseLiquidity:S,deadline:I});return x.transferObjects([D,k],this.data.address),x}static fromData(t){return new a(t)}};var om=require("turbos-clmm-sdk");var sr=class a extends w{constructor(t){super(t);this.data=t}data;txType;txSubType;async build(t){let n=new om.TurbosSdk(t.network.replace("sui:",""),t.suiClient),{pool:o,address:i,amountA:s,amountB:c,slippage:m,nft:b,deadline:S,txb:I}=this.data;return n.pool.increaseLiquidity({pool:o,slippage:m,address:i,amountA:s,amountB:c,nft:b,deadline:S,txb:I})}static fromData(t){return new a(t)}};var am=require("@mysten/sui/transactions"),im=require("@mysten/sui/utils");var cr=class a extends w{constructor(t){super(t);this.data=t}data;txType;txSubType;async build(t){let n=new am.Transaction;return n.moveCall({target:`${zt.PackageId}::claim::claim`,typeArguments:[zt.turbosCoinType],arguments:[n.object(zt.Claim),n.object(im.SUI_CLOCK_OBJECT_ID)]}),n}static fromData(t){return new a(t)}};var rm=require("@mysten/sui/transactions");var lr=class a extends w{constructor(t){super(t);this.data=t}data;txType;txSubType;async build(t){let n=new rm.Transaction;return n.moveCall({target:`${zt.PackageId}::claim::join`,typeArguments:[zt.turbosCoinType],arguments:[n.object(zt.Claim)]}),n}static fromData(t){return new a(t)}};var sm=require("@mysten/sui/transactions"),cm=require("turbos-clmm-sdk");var ur=class a extends w{constructor(t){super(t);this.data=t}data;txType;txSubType;async build(t){let n=new cm.TurbosSdk(t.network.replace("sui:",""),t.suiClient),o=new sm.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 lm=require("turbos-clmm-sdk");var pr=class a extends w{constructor(t){super(t);this.data=t}data;txType;txSubType;async build(t){let n=new lm.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 um=require("turbos-clmm-sdk");var mr=class a extends w{constructor(t){super(t);this.data=t}data;txType;txSubType;async build(t){console.log(this.data,"this.data");let n=new um.TurbosSdk(t.network.replace("sui:",""),t.suiClient),{routes:o,coinTypeA:i,coinTypeB:s,address:c,amountA:m,amountB:b,slippage:S,amountSpecifiedIsInput:I,deadline:x,txb:D}=this.data;return n.trade.swap({routes:o,coinTypeA:i,coinTypeB:s,address:c,amountA:m,amountB:b,amountSpecifiedIsInput:I,slippage:S,deadline:x,txb:D})}static fromData(t){return new a(t)}};var gm=require("turbos-clmm-sdk");var tc=require("@mysten/sui/transactions"),ec=require("@mysten/sui/utils");var pm=require("turbos-clmm-sdk");var Yn=class{constructor(e){this.turbosSdk=e}turbosSdk;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((m,b)=>Number(b.balance)-Number(m.balance)).some(m=>c>=n?!0:(c+=Number(m.balance),s.push(m),!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,pm.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 mm=89,dm=1e6,fm=async a=>{let{token1:e,token2:t,poolId:n,amountIn:o,currentAddress:i,turbosSdk:s}=a,c=new tc.Transaction,m=new Yn(s),b=await m.getCoinsData(i,t,o),[S,I]=m.splitAndMergeCoin(b,o,c);if(!S)throw new Error(`Not enough balance: ${t}`);let x=await m.IsAccountCap(i),D=x?c.object(x):m.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(mm),D,c.pure.u64(o),c.object((0,ec.normalizeSuiObjectId)("0x6")),S]});return I&&c.transferObjects([I],c.pure.address(i)),c.transferObjects([k],c.pure.address(i)),c.transferObjects([M],c.pure.address(i)),x||c.transferObjects([D],c.pure.address(i)),c.setSenderIfNotSet(i),c.setGasBudget(dm),c},hm=async a=>{let{token1:e,token2:t,poolId:n,amountIn:o,currentAddress:i,turbosSdk:s}=a,c=new tc.Transaction,m=new Yn(s),b=await m.getCoinsData(i,e,o),[S,I]=m.splitAndMergeCoin(b,o,c);if(!S)throw new Error(`Not enough balance: ${e}`);let x=await m.IsAccountCap(i),D=x?c.object(x):m.createAccount(c),k=m.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(mm),D,c.pure.u64(o),S,k,c.object((0,ec.normalizeSuiObjectId)("0x6"))]});return I&&c.transferObjects([I],c.pure.address(i)),c.transferObjects([M],c.pure.address(i)),c.transferObjects([L],c.pure.address(i)),x||c.transferObjects([D],c.pure.address(i)),c.setSenderIfNotSet(i),c.setGasBudget(dm),c};var dr=class a extends w{constructor(t){super(t);this.data=t}data;txType;txSubType;async build(t){let n=new gm.TurbosSdk(t.network.replace("sui:",""),t.suiClient);return await hm({...this.data,turbosSdk:n,currentAddress:t.account.address})}static fromData(t){return new a(t)}};var ym=require("turbos-clmm-sdk");var fr=class a extends w{constructor(t){super(t);this.data=t}data;txType;txSubType;async build(t){let n=new ym.TurbosSdk(t.network.replace("sui:",""),t.suiClient);return await fm({...this.data,turbosSdk:n,currentAddress:t.account.address})}static fromData(t){return new a(t)}};var hr=class{application="turbos";supportSDK="@mysten/sui";async deserialize(e){console.log(e,"input");let t=new Tm.TurbosSdk(e.network.replace("sui:","")),n=await t.contract.getConfig(),{transaction:o,account:i}=e,c=await new Zi(o,t,n).decode(i.address);return{txType:bm.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=ar.fromData(e.intentionData);break;case"AddLiquidity":i=tr.fromData(e.intentionData);break;case"IncreaseLiquidity":i=sr.fromData(e.intentionData);break;case"DecreaseLiquidity":i=ir.fromData(e.intentionData);break;case"DecreaseLiquidityWithReturn":i=rr.fromData(e.intentionData);break;case"RemoveLiquidity":i=ur.fromData(e.intentionData);break;case"removeLiquidityWithReturn":i=pr.fromData(e.intentionData);break;case"CollectFee":i=nr.fromData(e.intentionData);break;case"CollectReward":i=or.fromData(e.intentionData);break;case"Burn":i=er.fromData(e.intentionData);break;case"Swap":i=mr.fromData(e.intentionData);break;case"PrixJoin":i=lr.fromData(e.intentionData);break;case"PrixClaim":i=cr.fromData(e.intentionData);break;case"SwapExactBaseForQuote":i=dr.fromData(e.intentionData);break;case"SwapExactQuoteForBase":i=fr.fromData(e.intentionData);break;default:throw new Error("not implemented")}return i.build({suiClient:t,account:n,network:o})}};var xm=require("@msafe/sui3-utils");var gr=require("@msafe/sui3-utils"),nc=require("@mysten/sui.js/bcs"),Pe=require("@mysten/sui.js/utils");var Qf={packageId:"0x549e8b69270defbfafd4f94e17ec44cdbdd99820b33bda2278dea3b9a32d3f55",poolObjectId:"0x7fa2faa111b8c65bea48a23049bfd81ca8f971a262d981dcd9a17c3825cb5baf",metadataObjectId:"0x680cd26af32b2bde8d3361e804c53ec1d1cfe24c7f039eb7f549e8dfde389a60",systemStateObjectId:"0x0000000000000000000000000000000000000000000000000000000000000005",certType:"0x549e8b69270defbfafd4f94e17ec44cdbdd99820b33bda2278dea3b9a32d3f55::cert::CERT",gasBudget:5e7},Ot=Qf;var yr=class{constructor(e){this.txb=e}txb;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(`${Ot.packageId}::native_pool::stake`)}isUnStakeTransaction(){return!!this.getMoveCallTransaction(`${Ot.packageId}::native_pool::unstake`)}isClaimTicketTransaction(){return!!this.getMoveCallTransaction(`${Ot.packageId}::native_pool::burn_ticket`)}decodeStake(){let e=this.transactions[0].amounts[0].value.toNumber();return{txType:gr.TransactionType.Other,type:"Stake",intentionData:{amount:e}}}decodeUnStake(){let t=this.transactions.find(n=>n.kind==="SplitCoins").amounts[0].value.toNumber();return{txType:gr.TransactionType.Other,type:"UnStake",intentionData:{amount:t}}}decodeClaimTicket(){let e=this.helper.decodeOwnedObjectId(2);return console.log(e),{txType:gr.TransactionType.Other,type:"ClaimTicket",intentionData:{ticketId:e}}}get helper(){let e=this.transactions.find(t=>t.kind==="MoveCall"&&t.target.startsWith(Ot.packageId));return new oc(e,this.txb)}},oc=class a{constructor(e,t){this.moveCall=e;this.txb=t}moveCall;txb;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,Pe.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 nc.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,Pe.normalizeSuiAddress)(e.value.Object.ImmOrOwned.objectId)}return(0,Pe.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,Pe.normalizeSuiAddress)(e.value);if(!("Object"in e.value)||!("Shared"in e.value.Object))throw new Error("not Shared");return(0,Pe.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 nc.bcs.de(t,new Uint8Array(n))}typeArg(e){return(0,Pe.normalizeStructTag)(this.moveCall.typeArguments[e])}txArg(e){return this.moveCall.arguments[e]}};var wm=require("@mysten/sui.js/transactions");var Sm=Mt(require("sort-keys-recursive")),Re=class{constructor(e){this.data=e}data;serialize(){return JSON.stringify((0,Sm.default)(this.data))}};var br=class a extends Re{constructor(t){super(t);this.data=t}data;txType;txSubType;async build(t){console.log(t);let n=new wm.TransactionBlock,{ticketId:o}=this.data;return n.moveCall({target:`${Ot.packageId}::native_pool::burn_ticket`,arguments:[n.object(Ot.poolObjectId),n.object(Ot.systemStateObjectId),n.object(o)]}),n}static fromData(t){return new a(t)}};var Im=require("@mysten/sui.js/transactions");var Tr=class a extends Re{constructor(t){super(t);this.data=t}data;txType;txSubType;async build(t){console.log(t);let n=new Im.TransactionBlock,{amount:o}=this.data,[i]=n.splitCoins(n.gas,[n.pure(o)]);return n.moveCall({target:`${Ot.packageId}::native_pool::stake`,arguments:[n.object(Ot.poolObjectId),n.object(Ot.metadataObjectId),n.object(Ot.systemStateObjectId),i]}),n}static fromData(t){return new a(t)}};var Cm=require("@mysten/sui.js/transactions");var Sr=class a extends Re{constructor(t){super(t);this.data=t}data;txType;txSubType;async build(t){console.log(t);let n=new Cm.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]===Ot.certType.split("::")[0]),m=n.object(s.coinObjectId);c.length&&n.mergeCoins(m,c.map(S=>n.object(S.coinObjectId)));let b=n.splitCoins(n.object(s.coinObjectId),[n.pure(o)]);return n.moveCall({target:`${Ot.packageId}::native_pool::unstake`,arguments:[n.object(Ot.poolObjectId),n.object(Ot.metadataObjectId),n.object(Ot.systemStateObjectId),b]}),n}static fromData(t){return new a(t)}};var wr=class{application="volo";supportSDK="@mysten/sui.js";async deserialize(e){let{transactionBlock:t}=e,o=new yr(t).decode();return{txType:xm.TransactionType.Other,txSubType:o.type,intentionData:o.intentionData}}async build(e){let{suiClient:t,account:n}=e,o;switch(e.txSubType){case"Stake":o=Tr.fromData(e.intentionData);break;case"UnStake":o=Sr.fromData(e.intentionData);break;case"ClaimTicket":o=br.fromData(e.intentionData);break;default:throw new Error("not implemented")}return o.build({suiClient:t,account:n})}};var _m=require("@msafe/sui3-utils");var ac=require("@cetusprotocol/common-sdk"),pe=require("@msafe/sui3-utils"),Tn=require("@mysten/bcs"),Sn=require("@mysten/sui/bcs");var Ir=class{constructor(e,t){this.transaction=e;this.appContext=t}transaction;appContext;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:pe.TransactionType.Other,type:"OpenPosition",intentionData:{pool:this.getSharedObjectID(this.getInputIndex(e,1)),lowerTick:Number((0,ac.asIntN)(BigInt(this.getU32(this.getInputIndex(e,2)))).toString()),upperTick:Number((0,ac.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:pe.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:pe.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:pe.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:pe.TransactionType.Other,type:"CollectRewards",intentionData:{pool:e[0].pool,position:e[0].position,collectRewardTokens:e.map(t=>t.rewardCoinType)}}}decodeCollectFeeTx(){return{txType:pe.TransactionType.Other,type:"CollectFee",intentionData:this.getFeeCallData()}}decodeCollectRewardsAndFeeTx(){let e=this.getFeeCallData();return{txType:pe.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:pe.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(Sn.bcs.u32().parse(Uint8Array.from((0,Tn.fromBase64)(this.inputs[e].Pure.bytes))))}getU64(e){return Sn.bcs.u64().parse(Uint8Array.from((0,Tn.fromBase64)(this.inputs[e].Pure.bytes)))}getU128(e){return Sn.bcs.u128().parse(Uint8Array.from((0,Tn.fromBase64)(this.inputs[e].Pure.bytes)))}getBoolean(e){return Sn.bcs.bool().parse(Uint8Array.from((0,Tn.fromBase64)(this.inputs[e].Pure.bytes)))}getAddress(e){return Sn.bcs.Address.parse(Uint8Array.from((0,Tn.fromBase64)(this.inputs[e].Pure.bytes)))}getTypeArguments(e){return e.MoveCall.typeArguments||[]}getInputIndex(e,t){return e.MoveCall.arguments[t].Input}};var Mm=require("@msafe/sui3-utils");var Cr=require("@bluefin-exchange/bluefin7k-aggregator-sdk"),ae=require("@firefly-exchange/library-sui"),Am=require("turbos-clmm-sdk");var km=require("@firefly-exchange/library-sui"),vm=require("@firefly-exchange/library-sui/spot"),Dm={rpc:"https://fullnode.mainnet.sui.io/",objects:{GlobalConfig:"0x03db251ba509a8d5d8777b6338836082335d93eecbdd09a11e190a1cff51c352",BasePackage:"0x3492c874c1e3b3e2984e8c41b589e642d4d0a5d6459e5a9cfc2d52fd7c89c267",CurrentPackage:"0x67b34b728c4e28e704dcfecf7c5cf55c7fc593b6c65c20d1836d97c209c1928a"}},de=(a,e)=>{if(a!=="sui:mainnet")throw new Error("Bluefin spot protocol is only available on sui::mainnet");let t=new km.SuiClient({url:Dm.rpc});return new vm.OnChainCalls(t,Dm.objects,{address:e.address,isUIWallet:!1})};var Et=class{static async OpenPosition(e,t,n){let o=de(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=de(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=de(n,t),i=await o.queryChain.getPool(e.pool);return await o.removeLiquidity(i,e.position,{liquidityAmount:new ae.BN(e.liquidity),tokenMaxA:new ae.BN(e.maxAmountTokenA),tokenMaxB:new ae.BN(e.maxAmountTokenB)},{returnTx:!0,sender:t.address})}static async closePosition(e,t,n){let o=de(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=de(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=de(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=de(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=de(n,t),i=await(0,Cr.getQuote)({tokenIn:e.tokenIn.address,tokenOut:e.tokenOut.address,amountIn:new Am.Decimal(e.amountIn).mul(10**e.tokenIn.decimals).toString()}),s=await(0,Cr.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{...ae.ClmmPoolUtil.estLiquidityAndCoinAmountFromOneAmounts(t.lowerTick,t.upperTick,new ae.BN(t.tokenAmount),t.isTokenAFixed,!0,0,new ae.BN(e.current_sqrt_price)),tokenMaxA:new ae.BN(t.maxAmountTokenA),tokenMaxB:new ae.BN(t.maxAmountTokenB)}}};var xr=class a extends w{constructor(t){super(t);this.data=t}data;txType=Mm.TransactionType.Other;txSubType="Aggregator7KSwap";async build(t){let{account:n,network:o}=t;return console.log(this.data),Et.aggregator7KSwap(this.data,n,o)}static fromData(t){return new a(t)}};var Om=require("@msafe/sui3-utils");var Dr=class a extends w{constructor(t){super(t);this.data=t}data;txType=Om.TransactionType.Other;txSubType="ClosePosition";async build(t){let{account:n,network:o}=t;return console.log(this.data),Et.closePosition(this.data,n,o)}static fromData(t){return new a(t)}};var Pm=require("@msafe/sui3-utils");var kr=class a extends w{constructor(t){super(t);this.data=t}data;txType=Pm.TransactionType.Other;txSubType="CollectFee";async build(t){let{account:n,network:o}=t;return console.log(this.data),Et.collectFee(this.data,n,o)}static fromData(t){return new a(t)}};var Rm=require("@msafe/sui3-utils");var vr=class a extends w{constructor(t){super(t);this.data=t}data;txType=Rm.TransactionType.Other;txSubType="CollectRewards";async build(t){let{account:n,network:o}=t;return console.log(this.data),Et.collectRewards(this.data,n,o)}static fromData(t){return new a(t)}};var Bm=require("@msafe/sui3-utils");var Ar=class a extends w{constructor(t){super(t);this.data=t}data;txType=Bm.TransactionType.Other;txSubType="CollectRewardsAndFee";async build(t){let{account:n,network:o}=t;return console.log(this.data),Et.collectRewardsAndFee(this.data,n,o)}static fromData(t){return new a(t)}};var Em=require("@msafe/sui3-utils");var Mr=class a extends w{constructor(t){super(t);this.data=t}data;txType=Em.TransactionType.Other;txSubType="OpenPosition";async build(t){let{account:n,network:o}=t;return console.log(this.data),Et.OpenPosition(this.data,n,o)}static fromData(t){return new a(t)}};var Nm=require("@msafe/sui3-utils");var Or=class a extends w{constructor(t){super(t);this.data=t}data;txType=Nm.TransactionType.Other;txSubType="ProvideLiquidity";async build(t){let{account:n,network:o}=t;return console.log(this.data),Et.provideLiquidity(this.data,n,o)}static fromData(t){return new a(t)}};var Wm=require("@msafe/sui3-utils");var Pr=class a extends w{constructor(t){super(t);this.data=t}data;txType=Wm.TransactionType.Other;txSubType="RemoveLiquidity";async build(t){let{account:n,network:o}=t;return console.log(this.data),Et.removeLiquidity(this.data,n,o)}static fromData(t){return new a(t)}};var Rr=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:_m.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=Mr.fromData(e.intentionData);break;case"ProvideLiquidity":i=Or.fromData(e.intentionData);break;case"RemoveLiquidity":i=Pr.fromData(e.intentionData);break;case"ClosePosition":i=Dr.fromData(e.intentionData);break;case"CollectFee":i=kr.fromData(e.intentionData);break;case"CollectRewards":i=vr.fromData(e.intentionData);break;case"CollectRewardsAndFee":i=Ar.fromData(e.intentionData);break;case"Aggregator7KSwap":i=xr.fromData(e.intentionData);break;default:throw new Error("not implemented")}return i.build({suiClient:t,account:n,network:o})}};var Ld=require("@msafe/sui3-utils");var Zm=require("@mmt-finance/clmm-sdk"),td=require("@mysten/sui/transactions");var Ve=require("@mmt-finance/clmm-sdk/dist/utils/math/tickMath"),Km=Mt(require("bignumber.js")),R=Mt(jm());var Yf="0x0000000000000000000000000000000000000000000000000000000000000002::sui::SUI",_t=a=>a!=="0x2::sui::SUI"?a:"0x0000000000000000000000000000000000000000000000000000000000000002::sui::SUI",Zf=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},th=(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")},eh=(a,e,t,n)=>{if(a===Yf){let[o]=n.splitCoins(n.gas,[n.pure.u64(t)]);return o}else{let o=th(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 Um(a,e,t,n,o){let i=await Zf({suiClient:a.rpcClient,address:e,type:t});return eh(_t(t),i.map(c=>({balance:BigInt(c.balance),objectId:c.coinObjectId})),n,o)}var Ke=(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 qm({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},m=n.rewarders.map(S=>S.coinType);m.length>0&&(console.log("claimRewardsAsTargetCoin input",{pool:c,positionId:t,rewarderCoinTypes:m,targetCoinType:i,slippage:s,toAddress:e}),await a.Pool.claimRewardsAs({txb:o,pool:c,positionId:t,rewarderCoinTypes:m,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 nh(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 oh(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 Fm=(a,e,t)=>{let n=(0,Ve.convertI32ToSigned)(t?a+a%(e??1):a-a%(e??1));return n>0?new R.default(nh(n)):new R.default(oh(n))};function Vm(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 ie({address:a,coinType:e,coinAmount:t,coinDecimals:n,tx:o,mmt:i}){let s=Vm(t,n),c;return Number(t)?c=await Um(i,a,_t(e),s,o):[c]=o.moveCall({target:"0x2::coin::zero",typeArguments:[e],arguments:[]}),c}function $m({mmt:a,tx:e,poolModel:t,selectedLowTick:n,selectedHighTick:o}){let i=Fm((0,Ve.convertI32ToSigned)(n),t.tickSpacing),s=Fm((0,Ve.convertI32ToSigned)(o),t.tickSpacing);return a.Position.openPosition(e,t,i.toString(),s.toString())}var ah=(a,e)=>{let n=1e4-Math.floor(e*100);return a*BigInt(n)/BigInt(1e4)};function Br(a,e,t){let n=Vm(a,e);return Number(a)===0?BigInt(0):ah(n,t)}async function $e({poolId:a,currentSqrtPrice:e,tokenX:t,tokenY:n,slippagePercentage:o,isTokenX:i,suiClient:s}){let m=(await s.getObject({id:a,options:{showContent:!0}}))?.data?.content?.fields?.sqrt_price??e,b=Ve.TickMath.sqrtPriceX64ToPrice(new R.default(m?.toString()),t.decimals,n.decimals),S=i?(100-o)/100:(100+o)/100,I=Ve.TickMath.priceToSqrtPriceX64(b.mul(S),t.decimals,n.decimals);return BigInt(I.toString())}var Gm=async(a,e,t,n,o,i,s,c,m,b)=>{let S=await ie({mmt:a,address:t,coinType:i.tokenX.coinType,coinAmount:n,coinDecimals:i.tokenX.decimals,tx:e}),I=await ie({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=$m({mmt:a,tx:e,poolModel:x,selectedLowTick:c,selectedHighTick:m}),k=Br(n,i.tokenX.decimals,b),M=Br(o,i.tokenY.decimals,b);a.Pool.addLiquidity(e,x,D,S,I,k,M,t),e.transferObjects([D],e.pure.address(t))},Hm=async(a,e,t,n,o,i,s,c,m,b,S)=>{try{let I=await ie({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:_t(s.tokenX.coinType),tokenYType:_t(s.tokenY.coinType),tickSpacing:s.tickSpacing},D=$m({mmt:a,tx:e,poolModel:x,selectedLowTick:c,selectedHighTick:m}),k=await $e({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:I,isXtoY:i,limitSqrtPrice:k,slippagePercentage:S,transferToAddress:n,useMvr:!0}),e.transferObjects([D],e.pure.address(n))}catch(I){console.error(I)}},Xm=async(a,e,t,n,o,i,s,c)=>{let m=await ie({mmt:a,address:t,coinType:i.tokenX.coinType,coinAmount:n,coinDecimals:i.tokenX.decimals,tx:e}),b=await ie({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},I=Br(n,i.tokenX.decimals,c),x=Br(o,i.tokenY.decimals,c);a.Pool.addLiquidity(e,S,s,m,b,I,x,t)},zm=async(a,e,t,n,o,i,s,c,m)=>{try{let b=await ie({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},I=await $e({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:I,slippagePercentage:m,transferToAddress:t})}catch(b){throw console.error(b),b}},Qm=(a,e)=>BigInt(e===100?a:new Km.default(a).multipliedBy(e/100).toFixed(0)),Jm=async(a,e,t,n,o,i)=>{let s=Qm(t.liquidity,o),c=n.tokenX.coinType,m=n.tokenY.coinType,b={objectId:n?.poolId,tokenXType:c,tokenYType:m};a.Pool.removeLiquidity(i,b,t.objectId,s,BigInt(0),BigInt(0),e),Ke(a,e,t,n,i),o===100&&a.Position.closePosition(i,t.objectId)},Ym=async({sdk:a,address:e,position:t,pool:n,withdrawPercentage:o,txb:i,targetCoinType:s,slippage:c})=>{let m=Qm(t.liquidity,o),b=_t(n.tokenX.coinType),S=_t(n.tokenY.coinType),I=_t(s)===S,x={objectId:n?.poolId,tokenXType:b,tokenYType:S},{removeLpCoinA:D,removeLpCoinB:k}=a.Pool.removeLiquidity(i,x,t.objectId,m,BigInt(0),BigInt(0)),M=await $e({suiClient:a.rpcClient,poolId:n.poolId,currentSqrtPrice:n.currentSqrtPrice,tokenX:n.tokenX,tokenY:n.tokenY,isTokenX:I,slippagePercentage:c}),L=I?D:k,U=i.moveCall({target:"0x2::coin::value",arguments:[L],typeArguments:[I?b:S]});i.transferObjects([I?k:D],e),a.Pool.swapV2({txb:i,transferToAddress:e,pool:x,limitSqrtPrice:M,amount:U,inputCoin:L,isXtoY:I}),Ke(a,e,t,n,i),o===100&&a.Position.closePosition(i,t.objectId)};var Er=class a extends w{constructor(t){super(t);this.data=t}data;txType;txSubType;async build(){let t=Zm.MmtSDK.NEW({network:"mainnet"}),{params:n}=this.data,{address:o,amountA:i,amountB:s,pool:c,selectedLowTick:m,selectedHighTick:b,slippage:S}=n,I=new td.Transaction;return await Gm(t,I,o,i,s,c,c.poolId,m,b,S),I}static fromData(t){return new a(t)}};var ed=require("@mmt-finance/clmm-sdk"),nd=require("@mysten/sui/transactions");var Nr=class a extends w{constructor(t){super(t);this.data=t}data;txType;txSubType;async build(){let t=ed.MmtSDK.NEW({network:"mainnet"}),{params:n}=this.data,{address:o,amount:i,isTokenX:s,pool:c,selectedLowTick:m,selectedHighTick:b,swapSlippage:S,addLiquiditySlippage:I}=n,x=new nd.Transaction;return await Hm(t,x,t.rpcClient,o,i,s,c,m,b,S,I),x}static fromData(t){return new a(t)}};var ld=require("@mmt-finance/clmm-sdk"),ud=require("@mmt-finance/ve-sdk-v1"),pd=require("@mysten/sui/transactions");var wn="0x35169bc93e1fddfcf3a82a9eae726d349689ed59e4b065369af8789fe59f8608::mmt::MMT";var Zn=async a=>{let e=await a.getSyncEpochInfo();if(!e)throw new Error("Failed to sync epoch");return e},od=async(a,e,t,n,o,i,s,c)=>{let m=Number(n);if(!n||Number.isNaN(m)||m<=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 ie({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 Zn(e);await e.syncOrAdvanceEpoch(c,S.currentEpoch,S.syncedEpoch);let I=c.getData().commands.length;i?await e.createMaxBond(c,b,o):await e.createBond(c,b,BigInt(s),o);let D=c.getData().commands.length;if(D===0)throw new Error(`Bond Failed: Transaction has no commands. enableAutoMaxBond: ${i}, unbondAt: ${s}, amount: ${n}`);if(D===I)throw new Error(`Bond Failed: No new commands were added by bond operation. Commands before: ${I}, after: ${D}`)},ad=async(a,e,t,n,o,i,s,c)=>{let m=await Zn(a);if(await a.syncOrAdvanceEpoch(c,m.currentEpoch,m.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)}},id=async(a,e,t,n,o)=>{let i=await Zn(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())},rd=async(a,e,t,n)=>{let o=await Zn(a);await a.syncOrAdvanceEpoch(n,o.currentEpoch,o.syncedEpoch),await a.claimReward(n,t,e),await a.unbond(n,t,e)},sd=async(a,e,t,n)=>{if(t.length>0&&t.some(o=>o.userRewardAmount>0)){let o=await Zn(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())}},cd=async(a,e,t,n,o,i,s,c,m)=>{let b=_t(i),S=[];for(let q of n)if(q.userRewardAmount>0){let Pt=await e.buildClaimRewardCoin(o,q.veId);S.push(Pt)}let I=[];for(let q of S)Array.isArray(q)?I.push(...q):I.push(q);if(I.length===0)return;if(i===_t(wn)){o.transferObjects(I,o.pure.address(t));return}let x=c?.[i]?.[wn];if(!x||x.length===0)throw new Error(`No swap route found from ${wn} to ${i}`);let[D,...k]=I;k.length>0&&o.mergeCoins(D,k);let M=D,L=o.moveCall({target:"0x2::coin::value",arguments:[M],typeArguments:[wn]}),U=_t(wn);for(let q=0;q<x.length;q++){let Pt=x[q],W=m.find(G=>G.poolId===Pt);if(!W)throw new Error(`Pool ${Pt} not found`);let Nt=_t(W.tokenXType||W.tokenX?.coinType||"")===U,He={objectId:W.poolId,tokenXType:W.tokenXType||W.tokenX?.coinType||"",tokenYType:W.tokenYType||W.tokenY?.coinType||""},to=await $e({suiClient:a.rpcClient,poolId:W.poolId,currentSqrtPrice:W.currentSqrtPrice,tokenX:W.tokenX,tokenY:W.tokenY,slippagePercentage:s,isTokenX:Nt}),{outputCoin:eo,leftoverCoin:In}=a.Pool.swapV2({txb:o,pool:He,amount:L,inputCoin:M,isXtoY:Nt,limitSqrtPrice:to});if(o.transferObjects([In],o.pure.address(t)),M=eo,U=Nt?_t(W.tokenYType||W.tokenY?.coinType||""):_t(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 Wr=class a extends w{constructor(t){super(t);this.data=t}data;txType;txSubType;async build(t){let n=ld.MmtSDK.NEW({network:"mainnet"}),o=new ud.VeMMT(t.suiClient,"mainnet"),{params:i}=this.data,{address:s,positions:c,pools:m,veMMTs:b}=i,S=new pd.Transaction;for(let I of c){let x=m.find(D=>D.poolId===I.poolId);x&&Ke(n,s,I,x,S)}return await sd(o,s,b,S),S}static fromData(t){return new a(t)}};var md=require("@mmt-finance/clmm-sdk"),dd=require("@mmt-finance/ve-sdk-v1"),fd=require("@mysten/sui/transactions");var _r=class a extends w{constructor(t){super(t);this.data=t}data;txType;txSubType;async build(t){let n=md.MmtSDK.NEW({network:"mainnet"}),o=new dd.VeMMT(t.suiClient,"mainnet"),{params:i}=this.data,{claimVeMMTParams:s}=i,{address:c,veMMTs:m,targetCoinType:b,slippage:S,claimRoutes:I,pools:x}=s,D=new fd.Transaction;return await Promise.all(i.claimParams.map(k=>qm({...k,sdk:n,txb:D}))),await cd(n,o,c,m,D,b,S,I,x),D}static fromData(t){return new a(t)}};var hd=require("@mmt-finance/clmm-sdk"),gd=require("@mysten/sui/transactions");var Lr=class a extends w{constructor(t){super(t);this.data=t}data;txType;txSubType;async build(){let t=hd.MmtSDK.NEW({network:"mainnet"}),{params:n}=this.data,{address:o,position:i,pool:s}=n,c=new gd.Transaction;return Ke(t,o,i,s,c),c}static fromData(t){return new a(t)}};var yd=require("@mmt-finance/clmm-sdk"),bd=require("@mysten/sui/transactions");var jr=class a extends w{constructor(t){super(t);this.data=t}data;txType;txSubType;async build(){let t=yd.MmtSDK.NEW({network:"mainnet"}),{params:n}=this.data,{address:o,amountA:i,amountB:s,pool:c,positionObjectId:m,slippage:b}=n,S=new bd.Transaction;return await Xm(t,S,o,i,s,c,m,b),S}static fromData(t){return new a(t)}};var Td=require("@mmt-finance/clmm-sdk"),Sd=require("@mysten/sui/transactions");var Ur=class a extends w{constructor(t){super(t);this.data=t}data;txType;txSubType;async build(){let t=Td.MmtSDK.NEW({network:"mainnet"}),{params:n}=this.data,{address:o,amount:i,isTokenX:s,pool:c,positionObjectId:m,swapSlippage:b,addLiquiditySlippage:S}=n,I=new Sd.Transaction;return await zm(t,I,o,i,s,c,m,b,S),I}static fromData(t){return new a(t)}};var wd=require("@mmt-finance/clmm-sdk"),Id=require("@mysten/sui/transactions");var qr=class a extends w{constructor(t){super(t);this.data=t}data;txType;txSubType;async build(){let t=wd.MmtSDK.NEW({network:"mainnet"}),{params:n}=this.data,{pool:o,position:i,address:s,withdrawPercentage:c,zapOutOn:m,targetCoinType:b,slippage:S}=n,I=new Id.Transaction;return m?await Ym({sdk:t,address:s,position:i,pool:o,withdrawPercentage:c,txb:I,targetCoinType:b,slippage:S}):await Jm(t,s,i,o,c,I),I}static fromData(t){return new a(t)}};var sc=require("@mysten/sui/transactions"),cc=require("@suilend/springsui-sdk"),rc={id:"0x0431232199873db77a92aa645cd43521437e9cc5c6fff07fd03edb88afe0b25a",type:"0x2b6602099970374cf58a2a1b9d96f005fccceb81e92eb059873baf420eb6c717::x_sui::X_SUI",weightHookId:"0x9e35c13dbb0bc437e8ad5a95ec463622f58763e060552ae8d100db77f4904601"},Cd=async(a,e,t)=>{let n=await cc.LstClient.initialize(a,rc),o=new sc.Transaction,[i]=o.splitCoins(o.gas,[BigInt(t)]),s=n.mint(o,i);return o.transferObjects([s],e),o},xd=async(a,e,t)=>{let n=await cc.LstClient.initialize(a,rc),o=await a.getCoins({owner:e,coinType:rc.type,limit:1e3});if(o.data.length===0)throw new Error("No lst coins found");let i=new sc.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)]),m=n.redeem(i,c);return i.transferObjects([m],e),i};var Fr=class a extends w{constructor(t){super(t);this.data=t}data;txType;txSubType;async build(t){let{params:n}=this.data,{address:o,amount:i}=n;return await Cd(t.suiClient,o,i)}static fromData(t){return new a(t)}};var vd=require("@mmt-finance/clmm-sdk"),Ad=require("@mysten/sui/transactions");var Dd=require("@mmt-finance/clmm-sdk/dist/utils/poolUtils");var kd=async(a,e,t,n,o,i,s)=>{let c=await ie({mmt:a,tx:i,address:o,coinType:t.coinType,coinAmount:n,coinDecimals:t.decimals}),m=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:I,tokenX:x,tokenY:D,isStable:k,currentSqrtPrice:M}=e[S],{id:L,isReverse:U}=Dd.mappedMmtV3Pool[I]||{id:I,isReverse:!1},q=_t(x.coinType)===_t(b);q=U?!q:q;let Pt=U?D.coinType:x.coinType,W=U?x.coinType:D.coinType,Ge=await $e({poolId:L,tokenX:x,tokenY:D,slippagePercentage:s,isTokenX:q,suiClient:a.rpcClient,currentSqrtPrice:M}),Nt=a.Pool.swap(i,{objectId:L,tokenXType:Pt,tokenYType:W,isStable:k},m,c,q,void 0,Ge,!1);i.transferObjects([c],i.pure.address(o)),c=Nt,b=q?W:Pt,m=i.moveCall({target:"0x2::coin::value",typeArguments:[b],arguments:[c]})}i.transferObjects([c],i.pure.address(o))};var Kr=class a extends w{constructor(t){super(t);this.data=t}data;txType;txSubType;async build(){let t=vd.MmtSDK.NEW({network:"mainnet"}),{params:n}=this.data,{route:o,tokenIn:i,amountIn:s,address:c,slippage:m}=n,b=new Ad.Transaction;return await kd(t,o,i,s,c,b,m),b}static fromData(t){return new a(t)}};var Vr=class a extends w{constructor(t){super(t);this.data=t}data;txType;txSubType;async build(t){let{params:n}=this.data,{address:o,amount:i}=n;return await xd(t.suiClient,o,i)}static fromData(t){return new a(t)}};var Md=require("@mmt-finance/clmm-sdk"),Od=require("@mmt-finance/ve-sdk-v1"),Pd=require("@mysten/sui/transactions");var $r=class a extends w{constructor(t){super(t);this.data=t}data;txType;txSubType;async build(t){let n=Md.MmtSDK.NEW({network:"mainnet"}),o=new Od.VeMMT(t.suiClient,"mainnet"),{params:i}=this.data,{token:s,amount:c,address:m,enableAutoMaxBond:b,unbondAt:S}=i,I=new Pd.Transaction;return await od(n,o,s,c,m,b,S,I),I}static fromData(t){return new a(t)}};var Rd=require("@mmt-finance/ve-sdk-v1"),Bd=require("@mysten/sui/transactions");var Gr=class a extends w{constructor(t){super(t);this.data=t}data;txType;txSubType;async build(t){let n=new Rd.VeMMT(t.suiClient,"mainnet"),{params:o}=this.data,{address:i,veId:s,currentUnbondAt:c,isCurrentlyMaxBond:m,enableAutoMaxBond:b,unbondAt:S}=o,I=new Bd.Transaction;return await ad(n,i,s,c,m,b,S,I),I}static fromData(t){return new a(t)}};var Ed=require("@mmt-finance/ve-sdk-v1"),Nd=require("@mysten/sui/transactions");var Hr=class a extends w{constructor(t){super(t);this.data=t}data;txType;txSubType;async build(t){let n=new Ed.VeMMT(t.suiClient,"mainnet"),{params:o}=this.data,{address:i,veId:s,selectedVeMMTIds:c}=o,m=new Nd.Transaction;return await id(n,i,s,c,m),m}static fromData(t){return new a(t)}};var Wd=require("@mmt-finance/ve-sdk-v1"),_d=require("@mysten/sui/transactions");var Xr=class a extends w{constructor(t){super(t);this.data=t}data;txType;txSubType;async build(t){let n=new Wd.VeMMT(t.suiClient,"mainnet"),{params:o}=this.data,{address:i,veId:s}=o,c=new _d.Transaction;return await rd(n,i,s,c),c}static fromData(t){return new a(t)}};var zr=class{application="mmt-dex";supportSDK="@mysten/sui";async deserialize(e){let{appContext:t}=e;return{txType:Ld.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=Er.fromData(e.intentionData);break;case"AddLiquiditySingleSide":t=Nr.fromData(e.intentionData);break;case"ClaimRewards":t=Lr.fromData(e.intentionData);break;case"ClaimAllRewards":t=Wr.fromData(e.intentionData);break;case"ClaimRewardsAs":t=_r.fromData(e.intentionData);break;case"RemoveLiquidity":t=qr.fromData(e.intentionData);break;case"StakeXSui":t=Fr.fromData(e.intentionData);break;case"UnstakeXSui":t=Vr.fromData(e.intentionData);break;case"ManageLiquidity":t=jr.fromData(e.intentionData);break;case"ManageLiquiditySingleSide":t=Ur.fromData(e.intentionData);break;case"Bond":t=$r.fromData(e.intentionData);break;case"Extend":t=Gr.fromData(e.intentionData);break;case"Merge":t=Hr.fromData(e.intentionData);break;case"Unbond":t=Xr.fromData(e.intentionData);break;default:throw new Error(`not implemented ${e.txSubType}`)}return t.build({suiClient:e.suiClient})}};var ih=Xa.fromHelpers([new Ra,new Va,new Ma,new $a,new oa,new hr,new zr,new Mi,new wr,new Oo,new ji,new Xi,new lo,new Rr,new Yi]);
|
|
1
|
+
"use strict";var qd=Object.create;var eo=Object.defineProperty;var Fd=Object.getOwnPropertyDescriptor;var Kd=Object.getOwnPropertyNames;var Vd=Object.getPrototypeOf,$d=Object.prototype.hasOwnProperty;var Gd=(a,e)=>()=>(e||a((e={exports:{}}).exports,e),e.exports),fs=(a,e)=>{for(var t in e)eo(a,t,{get:e[t],enumerable:!0})},kc=(a,e,t,n)=>{if(e&&typeof e=="object"||typeof e=="function")for(let o of Kd(e))!$d.call(a,o)&&o!==t&&eo(a,o,{get:()=>e[o],enumerable:!(n=Fd(e,o))||n.enumerable});return a};var Mt=(a,e,t)=>(t=a!=null?qd(Vd(a)):{},kc(e||!a||!a.__esModule?eo(t,"default",{value:a,enumerable:!0}):t,a)),Hd=a=>kc(eo({},"__esModule",{value:!0}),a);var qm=Gd((Um,ic)=>{"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,p){if(typeof r=="number")return this._initNumber(r,u,p);if(typeof r=="object")return this._initArray(r,u,p);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,p):(this._parseBase(r,u,d),p==="le"&&this._initArray(this.toArray(),u,p)))},o.prototype._initNumber=function(r,u,p){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),p==="le"&&this._initArray(this.toArray(),u,p)},o.prototype._initArray=function(r,u,p){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(p==="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(p==="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 p=s(y,u);return u-1>=r&&(p|=s(y,u-1)<<4),p}o.prototype._parseHex=function(r,u,p){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(p==="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 m(y,r,u,p){for(var d=0,h=0,T=Math.min(y.length,u),C=r;C<T;C++){var f=y.charCodeAt(C)-48;d*=p,f>=49?h=f-49+10:f>=17?h=f-17+10:h=f,t(f>=0&&h<p,"Invalid character"),d+=h}return d}o.prototype._parseBase=function(r,u,p){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-p,C=T%d,f=Math.min(T,T-C)+p,l=0,g=p;g<f;g+=d)l=m(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=m(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 I=["","0","00","000","0000","00000","000000","0000000","00000000","000000000","0000000000","00000000000","000000000000","0000000000000","00000000000000","000000000000000","0000000000000000","00000000000000000","000000000000000000","0000000000000000000","00000000000000000000","000000000000000000000","0000000000000000000000","00000000000000000000000","000000000000000000000000","0000000000000000000000000"],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 p;if(r===16||r==="hex"){p="";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?p=I[6-f.length]+f+p:p=f+p}for(h!==0&&(p=h.toString(16)+p);p.length%u!==0;)p="0"+p;return this.negative!==0&&(p="-"+p),p}if(r===(r|0)&&r>=2&&r<=36){var l=x[r],g=D[r];p="";var v=this.clone();for(v.negative=0;!v.isZero();){var O=v.modrn(g).toString(r);v=v.idivn(g),v.isZero()?p=O+p:p=I[l-O.length]+O+p}for(this.isZero()&&(p="0"+p);p.length%u!==0;)p="0"+p;return this.negative!==0&&(p="-"+p),p}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,p){this._strip();var d=this.byteLength(),h=p||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 p=0,d=0,h=0,T=0;h<this.length;h++){var C=this.words[h]<<T|d;r[p++]=C&255,p<r.length&&(r[p++]=C>>8&255),p<r.length&&(r[p++]=C>>16&255),T===6?(p<r.length&&(r[p++]=C>>24&255),d=0,T=0):(d=C>>>24,T+=2)}if(p<r.length)for(r[p++]=d;p<r.length;)r[p++]=0},o.prototype._toArrayLikeBE=function(r,u){for(var p=r.length-1,d=0,h=0,T=0;h<this.length;h++){var C=this.words[h]<<T|d;r[p--]=C&255,p>=0&&(r[p--]=C>>8&255),p>=0&&(r[p--]=C>>16&255),T===6?(p>=0&&(r[p--]=C>>24&255),d=0,T=0):(d=C>>>24,T+=2)}if(p>=0)for(r[p--]=d;p>=0;)r[p--]=0},Math.clz32?o.prototype._countBits=function(r){return 32-Math.clz32(r)}:o.prototype._countBits=function(r){var u=r,p=0;return u>=4096&&(p+=13,u>>>=13),u>=64&&(p+=7,u>>>=7),u>=8&&(p+=4,u>>>=4),u>=2&&(p+=2,u>>>=2),p+u},o.prototype._zeroBits=function(r){if(r===0)return 26;var u=r,p=0;return(u&8191)===0&&(p+=13,u>>>=13),(u&127)===0&&(p+=7,u>>>=7),(u&15)===0&&(p+=4,u>>>=4),(u&3)===0&&(p+=2,u>>>=2),(u&1)===0&&p++,p},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 p=u/26|0,d=u%26;r[u]=y.words[p]>>>d&1}return r}o.prototype.zeroBits=function(){if(this.isZero())return 0;for(var r=0,u=0;u<this.length;u++){var p=this._zeroBits(this.words[u]);if(r+=p,p!==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 p=0;p<u.length;p++)this.words[p]=this.words[p]&r.words[p];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,p;this.length>r.length?(u=this,p=r):(u=r,p=this);for(var d=0;d<p.length;d++)this.words[d]=u.words[d]^p.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,p=r%26;this._expand(u),p>0&&u--;for(var d=0;d<u;d++)this.words[d]=~this.words[d]&67108863;return p>0&&(this.words[d]=~this.words[d]&67108863>>26-p),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 p=r/26|0,d=r%26;return this._expand(p+1),u?this.words[p]=this.words[p]|1<<d:this.words[p]=this.words[p]&~(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 p,d;this.length>r.length?(p=this,d=r):(p=r,d=this);for(var h=0,T=0;T<d.length;T++)u=(p.words[T]|0)+(d.words[T]|0)+h,this.words[T]=u&67108863,h=u>>>26;for(;h!==0&&T<p.length;T++)u=(p.words[T]|0)+h,this.words[T]=u&67108863,h=u>>>26;if(this.length=p.length,h!==0)this.words[this.length]=h,this.length++;else if(p!==this)for(;T<p.length;T++)this.words[T]=p.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 p=this.cmp(r);if(p===0)return this.negative=0,this.length=1,this.words[0]=0,this;var d,h;p>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 p=y.length+r.length|0;u.length=p,p=p-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<p;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,p){var d=r.words,h=u.words,T=p.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,de=d[2]|0,K=de&8191,$=de>>>13,lc=d[3]|0,z=lc&8191,Q=lc>>>13,uc=d[4]|0,J=uc&8191,Y=uc>>>13,pc=d[5]|0,Z=pc&8191,tt=pc>>>13,mc=d[6]|0,et=mc&8191,nt=mc>>>13,dc=d[7]|0,ot=dc&8191,at=dc>>>13,fc=d[8]|0,it=fc&8191,rt=fc>>>13,hc=d[9]|0,st=hc&8191,ct=hc>>>13,gc=h[0]|0,lt=gc&8191,ut=gc>>>13,yc=h[1]|0,pt=yc&8191,mt=yc>>>13,bc=h[2]|0,dt=bc&8191,ft=bc>>>13,Tc=h[3]|0,ht=Tc&8191,gt=Tc>>>13,Sc=h[4]|0,yt=Sc&8191,bt=Sc>>>13,wc=h[5]|0,Tt=wc&8191,St=wc>>>13,Ic=h[6]|0,wt=Ic&8191,It=Ic>>>13,Cc=h[7]|0,Ct=Cc&8191,xt=Cc>>>13,xc=h[8]|0,Dt=xc&8191,kt=xc>>>13,Dc=h[9]|0,vt=Dc&8191,At=Dc>>>13;p.negative=r.negative^u.negative,p.length=19,f=Math.imul(O,lt),l=Math.imul(O,ut),l=l+Math.imul(P,lt)|0,g=Math.imul(P,ut);var zr=(C+f|0)+((l&8191)<<13)|0;C=(g+(l>>>13)|0)+(zr>>>26)|0,zr&=67108863,f=Math.imul(_,lt),l=Math.imul(_,ut),l=l+Math.imul(F,lt)|0,g=Math.imul(F,ut),f=f+Math.imul(O,pt)|0,l=l+Math.imul(O,mt)|0,l=l+Math.imul(P,pt)|0,g=g+Math.imul(P,mt)|0;var Qr=(C+f|0)+((l&8191)<<13)|0;C=(g+(l>>>13)|0)+(Qr>>>26)|0,Qr&=67108863,f=Math.imul(K,lt),l=Math.imul(K,ut),l=l+Math.imul($,lt)|0,g=Math.imul($,ut),f=f+Math.imul(_,pt)|0,l=l+Math.imul(_,mt)|0,l=l+Math.imul(F,pt)|0,g=g+Math.imul(F,mt)|0,f=f+Math.imul(O,dt)|0,l=l+Math.imul(O,ft)|0,l=l+Math.imul(P,dt)|0,g=g+Math.imul(P,ft)|0;var Jr=(C+f|0)+((l&8191)<<13)|0;C=(g+(l>>>13)|0)+(Jr>>>26)|0,Jr&=67108863,f=Math.imul(z,lt),l=Math.imul(z,ut),l=l+Math.imul(Q,lt)|0,g=Math.imul(Q,ut),f=f+Math.imul(K,pt)|0,l=l+Math.imul(K,mt)|0,l=l+Math.imul($,pt)|0,g=g+Math.imul($,mt)|0,f=f+Math.imul(_,dt)|0,l=l+Math.imul(_,ft)|0,l=l+Math.imul(F,dt)|0,g=g+Math.imul(F,ft)|0,f=f+Math.imul(O,ht)|0,l=l+Math.imul(O,gt)|0,l=l+Math.imul(P,ht)|0,g=g+Math.imul(P,gt)|0;var Yr=(C+f|0)+((l&8191)<<13)|0;C=(g+(l>>>13)|0)+(Yr>>>26)|0,Yr&=67108863,f=Math.imul(J,lt),l=Math.imul(J,ut),l=l+Math.imul(Y,lt)|0,g=Math.imul(Y,ut),f=f+Math.imul(z,pt)|0,l=l+Math.imul(z,mt)|0,l=l+Math.imul(Q,pt)|0,g=g+Math.imul(Q,mt)|0,f=f+Math.imul(K,dt)|0,l=l+Math.imul(K,ft)|0,l=l+Math.imul($,dt)|0,g=g+Math.imul($,ft)|0,f=f+Math.imul(_,ht)|0,l=l+Math.imul(_,gt)|0,l=l+Math.imul(F,ht)|0,g=g+Math.imul(F,gt)|0,f=f+Math.imul(O,yt)|0,l=l+Math.imul(O,bt)|0,l=l+Math.imul(P,yt)|0,g=g+Math.imul(P,bt)|0;var Zr=(C+f|0)+((l&8191)<<13)|0;C=(g+(l>>>13)|0)+(Zr>>>26)|0,Zr&=67108863,f=Math.imul(Z,lt),l=Math.imul(Z,ut),l=l+Math.imul(tt,lt)|0,g=Math.imul(tt,ut),f=f+Math.imul(J,pt)|0,l=l+Math.imul(J,mt)|0,l=l+Math.imul(Y,pt)|0,g=g+Math.imul(Y,mt)|0,f=f+Math.imul(z,dt)|0,l=l+Math.imul(z,ft)|0,l=l+Math.imul(Q,dt)|0,g=g+Math.imul(Q,ft)|0,f=f+Math.imul(K,ht)|0,l=l+Math.imul(K,gt)|0,l=l+Math.imul($,ht)|0,g=g+Math.imul($,gt)|0,f=f+Math.imul(_,yt)|0,l=l+Math.imul(_,bt)|0,l=l+Math.imul(F,yt)|0,g=g+Math.imul(F,bt)|0,f=f+Math.imul(O,Tt)|0,l=l+Math.imul(O,St)|0,l=l+Math.imul(P,Tt)|0,g=g+Math.imul(P,St)|0;var ts=(C+f|0)+((l&8191)<<13)|0;C=(g+(l>>>13)|0)+(ts>>>26)|0,ts&=67108863,f=Math.imul(et,lt),l=Math.imul(et,ut),l=l+Math.imul(nt,lt)|0,g=Math.imul(nt,ut),f=f+Math.imul(Z,pt)|0,l=l+Math.imul(Z,mt)|0,l=l+Math.imul(tt,pt)|0,g=g+Math.imul(tt,mt)|0,f=f+Math.imul(J,dt)|0,l=l+Math.imul(J,ft)|0,l=l+Math.imul(Y,dt)|0,g=g+Math.imul(Y,ft)|0,f=f+Math.imul(z,ht)|0,l=l+Math.imul(z,gt)|0,l=l+Math.imul(Q,ht)|0,g=g+Math.imul(Q,gt)|0,f=f+Math.imul(K,yt)|0,l=l+Math.imul(K,bt)|0,l=l+Math.imul($,yt)|0,g=g+Math.imul($,bt)|0,f=f+Math.imul(_,Tt)|0,l=l+Math.imul(_,St)|0,l=l+Math.imul(F,Tt)|0,g=g+Math.imul(F,St)|0,f=f+Math.imul(O,wt)|0,l=l+Math.imul(O,It)|0,l=l+Math.imul(P,wt)|0,g=g+Math.imul(P,It)|0;var es=(C+f|0)+((l&8191)<<13)|0;C=(g+(l>>>13)|0)+(es>>>26)|0,es&=67108863,f=Math.imul(ot,lt),l=Math.imul(ot,ut),l=l+Math.imul(at,lt)|0,g=Math.imul(at,ut),f=f+Math.imul(et,pt)|0,l=l+Math.imul(et,mt)|0,l=l+Math.imul(nt,pt)|0,g=g+Math.imul(nt,mt)|0,f=f+Math.imul(Z,dt)|0,l=l+Math.imul(Z,ft)|0,l=l+Math.imul(tt,dt)|0,g=g+Math.imul(tt,ft)|0,f=f+Math.imul(J,ht)|0,l=l+Math.imul(J,gt)|0,l=l+Math.imul(Y,ht)|0,g=g+Math.imul(Y,gt)|0,f=f+Math.imul(z,yt)|0,l=l+Math.imul(z,bt)|0,l=l+Math.imul(Q,yt)|0,g=g+Math.imul(Q,bt)|0,f=f+Math.imul(K,Tt)|0,l=l+Math.imul(K,St)|0,l=l+Math.imul($,Tt)|0,g=g+Math.imul($,St)|0,f=f+Math.imul(_,wt)|0,l=l+Math.imul(_,It)|0,l=l+Math.imul(F,wt)|0,g=g+Math.imul(F,It)|0,f=f+Math.imul(O,Ct)|0,l=l+Math.imul(O,xt)|0,l=l+Math.imul(P,Ct)|0,g=g+Math.imul(P,xt)|0;var ns=(C+f|0)+((l&8191)<<13)|0;C=(g+(l>>>13)|0)+(ns>>>26)|0,ns&=67108863,f=Math.imul(it,lt),l=Math.imul(it,ut),l=l+Math.imul(rt,lt)|0,g=Math.imul(rt,ut),f=f+Math.imul(ot,pt)|0,l=l+Math.imul(ot,mt)|0,l=l+Math.imul(at,pt)|0,g=g+Math.imul(at,mt)|0,f=f+Math.imul(et,dt)|0,l=l+Math.imul(et,ft)|0,l=l+Math.imul(nt,dt)|0,g=g+Math.imul(nt,ft)|0,f=f+Math.imul(Z,ht)|0,l=l+Math.imul(Z,gt)|0,l=l+Math.imul(tt,ht)|0,g=g+Math.imul(tt,gt)|0,f=f+Math.imul(J,yt)|0,l=l+Math.imul(J,bt)|0,l=l+Math.imul(Y,yt)|0,g=g+Math.imul(Y,bt)|0,f=f+Math.imul(z,Tt)|0,l=l+Math.imul(z,St)|0,l=l+Math.imul(Q,Tt)|0,g=g+Math.imul(Q,St)|0,f=f+Math.imul(K,wt)|0,l=l+Math.imul(K,It)|0,l=l+Math.imul($,wt)|0,g=g+Math.imul($,It)|0,f=f+Math.imul(_,Ct)|0,l=l+Math.imul(_,xt)|0,l=l+Math.imul(F,Ct)|0,g=g+Math.imul(F,xt)|0,f=f+Math.imul(O,Dt)|0,l=l+Math.imul(O,kt)|0,l=l+Math.imul(P,Dt)|0,g=g+Math.imul(P,kt)|0;var os=(C+f|0)+((l&8191)<<13)|0;C=(g+(l>>>13)|0)+(os>>>26)|0,os&=67108863,f=Math.imul(st,lt),l=Math.imul(st,ut),l=l+Math.imul(ct,lt)|0,g=Math.imul(ct,ut),f=f+Math.imul(it,pt)|0,l=l+Math.imul(it,mt)|0,l=l+Math.imul(rt,pt)|0,g=g+Math.imul(rt,mt)|0,f=f+Math.imul(ot,dt)|0,l=l+Math.imul(ot,ft)|0,l=l+Math.imul(at,dt)|0,g=g+Math.imul(at,ft)|0,f=f+Math.imul(et,ht)|0,l=l+Math.imul(et,gt)|0,l=l+Math.imul(nt,ht)|0,g=g+Math.imul(nt,gt)|0,f=f+Math.imul(Z,yt)|0,l=l+Math.imul(Z,bt)|0,l=l+Math.imul(tt,yt)|0,g=g+Math.imul(tt,bt)|0,f=f+Math.imul(J,Tt)|0,l=l+Math.imul(J,St)|0,l=l+Math.imul(Y,Tt)|0,g=g+Math.imul(Y,St)|0,f=f+Math.imul(z,wt)|0,l=l+Math.imul(z,It)|0,l=l+Math.imul(Q,wt)|0,g=g+Math.imul(Q,It)|0,f=f+Math.imul(K,Ct)|0,l=l+Math.imul(K,xt)|0,l=l+Math.imul($,Ct)|0,g=g+Math.imul($,xt)|0,f=f+Math.imul(_,Dt)|0,l=l+Math.imul(_,kt)|0,l=l+Math.imul(F,Dt)|0,g=g+Math.imul(F,kt)|0,f=f+Math.imul(O,vt)|0,l=l+Math.imul(O,At)|0,l=l+Math.imul(P,vt)|0,g=g+Math.imul(P,At)|0;var as=(C+f|0)+((l&8191)<<13)|0;C=(g+(l>>>13)|0)+(as>>>26)|0,as&=67108863,f=Math.imul(st,pt),l=Math.imul(st,mt),l=l+Math.imul(ct,pt)|0,g=Math.imul(ct,mt),f=f+Math.imul(it,dt)|0,l=l+Math.imul(it,ft)|0,l=l+Math.imul(rt,dt)|0,g=g+Math.imul(rt,ft)|0,f=f+Math.imul(ot,ht)|0,l=l+Math.imul(ot,gt)|0,l=l+Math.imul(at,ht)|0,g=g+Math.imul(at,gt)|0,f=f+Math.imul(et,yt)|0,l=l+Math.imul(et,bt)|0,l=l+Math.imul(nt,yt)|0,g=g+Math.imul(nt,bt)|0,f=f+Math.imul(Z,Tt)|0,l=l+Math.imul(Z,St)|0,l=l+Math.imul(tt,Tt)|0,g=g+Math.imul(tt,St)|0,f=f+Math.imul(J,wt)|0,l=l+Math.imul(J,It)|0,l=l+Math.imul(Y,wt)|0,g=g+Math.imul(Y,It)|0,f=f+Math.imul(z,Ct)|0,l=l+Math.imul(z,xt)|0,l=l+Math.imul(Q,Ct)|0,g=g+Math.imul(Q,xt)|0,f=f+Math.imul(K,Dt)|0,l=l+Math.imul(K,kt)|0,l=l+Math.imul($,Dt)|0,g=g+Math.imul($,kt)|0,f=f+Math.imul(_,vt)|0,l=l+Math.imul(_,At)|0,l=l+Math.imul(F,vt)|0,g=g+Math.imul(F,At)|0;var is=(C+f|0)+((l&8191)<<13)|0;C=(g+(l>>>13)|0)+(is>>>26)|0,is&=67108863,f=Math.imul(st,dt),l=Math.imul(st,ft),l=l+Math.imul(ct,dt)|0,g=Math.imul(ct,ft),f=f+Math.imul(it,ht)|0,l=l+Math.imul(it,gt)|0,l=l+Math.imul(rt,ht)|0,g=g+Math.imul(rt,gt)|0,f=f+Math.imul(ot,yt)|0,l=l+Math.imul(ot,bt)|0,l=l+Math.imul(at,yt)|0,g=g+Math.imul(at,bt)|0,f=f+Math.imul(et,Tt)|0,l=l+Math.imul(et,St)|0,l=l+Math.imul(nt,Tt)|0,g=g+Math.imul(nt,St)|0,f=f+Math.imul(Z,wt)|0,l=l+Math.imul(Z,It)|0,l=l+Math.imul(tt,wt)|0,g=g+Math.imul(tt,It)|0,f=f+Math.imul(J,Ct)|0,l=l+Math.imul(J,xt)|0,l=l+Math.imul(Y,Ct)|0,g=g+Math.imul(Y,xt)|0,f=f+Math.imul(z,Dt)|0,l=l+Math.imul(z,kt)|0,l=l+Math.imul(Q,Dt)|0,g=g+Math.imul(Q,kt)|0,f=f+Math.imul(K,vt)|0,l=l+Math.imul(K,At)|0,l=l+Math.imul($,vt)|0,g=g+Math.imul($,At)|0;var rs=(C+f|0)+((l&8191)<<13)|0;C=(g+(l>>>13)|0)+(rs>>>26)|0,rs&=67108863,f=Math.imul(st,ht),l=Math.imul(st,gt),l=l+Math.imul(ct,ht)|0,g=Math.imul(ct,gt),f=f+Math.imul(it,yt)|0,l=l+Math.imul(it,bt)|0,l=l+Math.imul(rt,yt)|0,g=g+Math.imul(rt,bt)|0,f=f+Math.imul(ot,Tt)|0,l=l+Math.imul(ot,St)|0,l=l+Math.imul(at,Tt)|0,g=g+Math.imul(at,St)|0,f=f+Math.imul(et,wt)|0,l=l+Math.imul(et,It)|0,l=l+Math.imul(nt,wt)|0,g=g+Math.imul(nt,It)|0,f=f+Math.imul(Z,Ct)|0,l=l+Math.imul(Z,xt)|0,l=l+Math.imul(tt,Ct)|0,g=g+Math.imul(tt,xt)|0,f=f+Math.imul(J,Dt)|0,l=l+Math.imul(J,kt)|0,l=l+Math.imul(Y,Dt)|0,g=g+Math.imul(Y,kt)|0,f=f+Math.imul(z,vt)|0,l=l+Math.imul(z,At)|0,l=l+Math.imul(Q,vt)|0,g=g+Math.imul(Q,At)|0;var ss=(C+f|0)+((l&8191)<<13)|0;C=(g+(l>>>13)|0)+(ss>>>26)|0,ss&=67108863,f=Math.imul(st,yt),l=Math.imul(st,bt),l=l+Math.imul(ct,yt)|0,g=Math.imul(ct,bt),f=f+Math.imul(it,Tt)|0,l=l+Math.imul(it,St)|0,l=l+Math.imul(rt,Tt)|0,g=g+Math.imul(rt,St)|0,f=f+Math.imul(ot,wt)|0,l=l+Math.imul(ot,It)|0,l=l+Math.imul(at,wt)|0,g=g+Math.imul(at,It)|0,f=f+Math.imul(et,Ct)|0,l=l+Math.imul(et,xt)|0,l=l+Math.imul(nt,Ct)|0,g=g+Math.imul(nt,xt)|0,f=f+Math.imul(Z,Dt)|0,l=l+Math.imul(Z,kt)|0,l=l+Math.imul(tt,Dt)|0,g=g+Math.imul(tt,kt)|0,f=f+Math.imul(J,vt)|0,l=l+Math.imul(J,At)|0,l=l+Math.imul(Y,vt)|0,g=g+Math.imul(Y,At)|0;var cs=(C+f|0)+((l&8191)<<13)|0;C=(g+(l>>>13)|0)+(cs>>>26)|0,cs&=67108863,f=Math.imul(st,Tt),l=Math.imul(st,St),l=l+Math.imul(ct,Tt)|0,g=Math.imul(ct,St),f=f+Math.imul(it,wt)|0,l=l+Math.imul(it,It)|0,l=l+Math.imul(rt,wt)|0,g=g+Math.imul(rt,It)|0,f=f+Math.imul(ot,Ct)|0,l=l+Math.imul(ot,xt)|0,l=l+Math.imul(at,Ct)|0,g=g+Math.imul(at,xt)|0,f=f+Math.imul(et,Dt)|0,l=l+Math.imul(et,kt)|0,l=l+Math.imul(nt,Dt)|0,g=g+Math.imul(nt,kt)|0,f=f+Math.imul(Z,vt)|0,l=l+Math.imul(Z,At)|0,l=l+Math.imul(tt,vt)|0,g=g+Math.imul(tt,At)|0;var ls=(C+f|0)+((l&8191)<<13)|0;C=(g+(l>>>13)|0)+(ls>>>26)|0,ls&=67108863,f=Math.imul(st,wt),l=Math.imul(st,It),l=l+Math.imul(ct,wt)|0,g=Math.imul(ct,It),f=f+Math.imul(it,Ct)|0,l=l+Math.imul(it,xt)|0,l=l+Math.imul(rt,Ct)|0,g=g+Math.imul(rt,xt)|0,f=f+Math.imul(ot,Dt)|0,l=l+Math.imul(ot,kt)|0,l=l+Math.imul(at,Dt)|0,g=g+Math.imul(at,kt)|0,f=f+Math.imul(et,vt)|0,l=l+Math.imul(et,At)|0,l=l+Math.imul(nt,vt)|0,g=g+Math.imul(nt,At)|0;var us=(C+f|0)+((l&8191)<<13)|0;C=(g+(l>>>13)|0)+(us>>>26)|0,us&=67108863,f=Math.imul(st,Ct),l=Math.imul(st,xt),l=l+Math.imul(ct,Ct)|0,g=Math.imul(ct,xt),f=f+Math.imul(it,Dt)|0,l=l+Math.imul(it,kt)|0,l=l+Math.imul(rt,Dt)|0,g=g+Math.imul(rt,kt)|0,f=f+Math.imul(ot,vt)|0,l=l+Math.imul(ot,At)|0,l=l+Math.imul(at,vt)|0,g=g+Math.imul(at,At)|0;var ps=(C+f|0)+((l&8191)<<13)|0;C=(g+(l>>>13)|0)+(ps>>>26)|0,ps&=67108863,f=Math.imul(st,Dt),l=Math.imul(st,kt),l=l+Math.imul(ct,Dt)|0,g=Math.imul(ct,kt),f=f+Math.imul(it,vt)|0,l=l+Math.imul(it,At)|0,l=l+Math.imul(rt,vt)|0,g=g+Math.imul(rt,At)|0;var ms=(C+f|0)+((l&8191)<<13)|0;C=(g+(l>>>13)|0)+(ms>>>26)|0,ms&=67108863,f=Math.imul(st,vt),l=Math.imul(st,At),l=l+Math.imul(ct,vt)|0,g=Math.imul(ct,At);var ds=(C+f|0)+((l&8191)<<13)|0;return C=(g+(l>>>13)|0)+(ds>>>26)|0,ds&=67108863,T[0]=zr,T[1]=Qr,T[2]=Jr,T[3]=Yr,T[4]=Zr,T[5]=ts,T[6]=es,T[7]=ns,T[8]=os,T[9]=as,T[10]=is,T[11]=rs,T[12]=ss,T[13]=cs,T[14]=ls,T[15]=us,T[16]=ps,T[17]=ms,T[18]=ds,C!==0&&(T[19]=C,p.length++),p};Math.imul||(U=L);function q(y,r,u){u.negative=r.negative^y.negative,u.length=y.length+r.length;for(var p=0,d=0,h=0;h<u.length-1;h++){var T=d;d=0;for(var C=p&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,p=T,T=d}return p!==0?u.words[h]=p:u.length--,u._strip()}function Pt(y,r,u){return q(y,r,u)}o.prototype.mulTo=function(r,u){var p,d=this.length+r.length;return this.length===10&&r.length===10?p=U(this,r,u):d<63?p=L(this,r,u):d<1024?p=q(this,r,u):p=Pt(this,r,u),p};function W(y,r){this.x=y,this.y=r}W.prototype.makeRBT=function(r){for(var u=new Array(r),p=o.prototype._countBits(r)-1,d=0;d<r;d++)u[d]=this.revBin(d,p,r);return u},W.prototype.revBin=function(r,u,p){if(r===0||r===p-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,p,d,h,T){for(var C=0;C<T;C++)d[C]=u[r[C]],h[C]=p[r[C]]},W.prototype.transform=function(r,u,p,d,h,T){this.permute(T,r,u,p,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 _=p[v+B],F=d[v+B],de=p[v+B+C],K=d[v+B+C],$=O*de-P*K;K=O*K+P*de,de=$,p[v+B]=_+de,d[v+B]=F+K,p[v+B+C]=_-de,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 p=Math.max(u,r)|1,d=p&1,h=0;for(p=p/2|0;p;p=p>>>1)h++;return 1<<h+1+d},W.prototype.conjugate=function(r,u,p){if(!(p<=1))for(var d=0;d<p/2;d++){var h=r[d];r[d]=r[p-d-1],r[p-d-1]=h,h=u[d],u[d]=-u[p-d-1],u[p-d-1]=-h}},W.prototype.normalize13b=function(r,u){for(var p=0,d=0;d<u/2;d++){var h=Math.round(r[2*d+1]/u)*8192+Math.round(r[2*d]/u)+p;r[d]=h&67108863,h<67108864?p=0:p=h/67108864|0}return r},W.prototype.convert13b=function(r,u,p,d){for(var h=0,T=0;T<u;T++)h=h+(r[T]|0),p[2*T]=h&8191,h=h>>>13,p[2*T+1]=h&8191,h=h>>>13;for(T=2*u;T<d;++T)p[T]=0;t(h===0),t((h&-8192)===0)},W.prototype.stub=function(r){for(var u=new Array(r),p=0;p<r;p++)u[p]=0;return u},W.prototype.mulp=function(r,u,p){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=p.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),p.negative=r.negative^u.negative,p.length=r.length+u.length,p._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),Pt(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 p=0,d=0;d<this.length;d++){var h=(this.words[d]|0)*r,T=(h&67108863)+(p&67108863);p>>=26,p+=h/67108864|0,p+=T>>>26,this.words[d]=T&67108863}return p!==0&&(this.words[d]=p,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 p=this,d=0;d<u.length&&u[d]===0;d++,p=p.sqr());if(++d<u.length)for(var h=p.sqr();d<u.length;d++,h=h.sqr())u[d]!==0&&(p=p.mul(h));return p},o.prototype.iushln=function(r){t(typeof r=="number"&&r>=0);var u=r%26,p=(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(p!==0){for(h=this.length-1;h>=0;h--)this.words[h+p]=this.words[h];for(h=0;h<p;h++)this.words[h]=0;this.length+=p}return this._strip()},o.prototype.ishln=function(r){return t(this.negative===0),this.iushln(r)},o.prototype.iushrn=function(r,u,p){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=p;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,p){return t(this.negative===0),this.iushrn(r,u,p)},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,p=(r-u)/26,d=1<<u;if(this.length<=p)return!1;var h=this.words[p];return!!(h&d)},o.prototype.imaskn=function(r){t(typeof r=="number"&&r>=0);var u=r%26,p=(r-u)/26;if(t(this.negative===0,"imaskn works only with positive numbers"),this.length<=p)return this;if(u!==0&&p++,this.length=Math.min(p,this.length),u!==0){var d=67108863^67108863>>>u<<u;this.words[this.length-1]&=d}return this.length===0&&(this.words[0]=0,this.length=1),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,p){var d=r.length+p,h;this._expand(d);var T,C=0;for(h=0;h<r.length;h++){T=(this.words[h+p]|0)+C;var f=(r.words[h]|0)*u;T-=f&67108863,C=(T>>26)-(f/67108864|0),this.words[h+p]=T&67108863}for(;h<this.length-p;h++)T=(this.words[h+p]|0)+C,C=T>>26,this.words[h+p]=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 p=this.length-r.length,d=this.clone(),h=r,T=h.words[h.length-1]|0,C=this._countBits(T);p=26-C,p!==0&&(h=h.ushln(p),d.iushln(p),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"&&p!==0&&d.iushrn(p),{div:l||null,mod:d}},o.prototype.divmod=function(r,u,p){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(),p&&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(),p&&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 p=u.div.negative!==0?u.mod.isub(r):u.mod,d=r.ushrn(1),h=r.andln(1),T=p.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 p=(1<<26)%r,d=0,h=this.length-1;h>=0;h--)d=(p*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 p=0,d=this.length-1;d>=0;d--){var h=(this.words[d]|0)+p*67108864;this.words[d]=h/r|0,p=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,p=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()&&p.isEven();)u.iushrn(1),p.iushrn(1),++f;for(var l=p.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;(p.words[0]&B)===0&&P<26;++P,B<<=1);if(P>0)for(p.iushrn(P);P-- >0;)(T.isOdd()||C.isOdd())&&(T.iadd(l),C.isub(g)),T.iushrn(1),C.iushrn(1);u.cmp(p)>=0?(u.isub(p),d.isub(T),h.isub(C)):(p.isub(u),T.isub(d),C.isub(h))}return{a:T,b:C,gcd:p.iushln(f)}},o.prototype._invmp=function(r){t(r.negative===0),t(!r.isZero());var u=this,p=r.clone();u.negative!==0?u=u.umod(r):u=u.clone();for(var d=new o(1),h=new o(0),T=p.clone();u.cmpn(1)>0&&p.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;(p.words[0]&g)===0&&l<26;++l,g<<=1);if(l>0)for(p.iushrn(l);l-- >0;)h.isOdd()&&h.iadd(T),h.iushrn(1);u.cmp(p)>=0?(u.isub(p),d.isub(h)):(p.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(),p=r.clone();u.negative=0,p.negative=0;for(var d=0;u.isEven()&&p.isEven();d++)u.iushrn(1),p.iushrn(1);do{for(;u.isEven();)u.iushrn(1);for(;p.isEven();)p.iushrn(1);var h=u.cmp(p);if(h<0){var T=u;u=p,p=T}else if(h===0||p.cmpn(1)===0)break;u.isub(p)}while(!0);return p.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,p=(r-u)/26,d=1<<u;if(this.length<=p)return this._expand(p+1),this.words[p]|=d,this;for(var h=d,T=p;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 p;if(this.length>1)p=1;else{u&&(r=-r),t(r<=67108863,"Number is too big");var d=this.words[0]|0;p=d===r?0:d<r?-1:1}return this.negative!==0?-p|0:p},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,p=this.length-1;p>=0;p--){var d=this.words[p]|0,h=r.words[p]|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 G(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 Ge={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,p;do this.split(u,this.tmp),u=this.imulK(u),u=u.iadd(this.tmp),p=u.bitLength();while(p>this.n);var d=p<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},Nt.prototype.split=function(r,u){r.iushrn(this.n,0,u)},Nt.prototype.imulK=function(r){return r.imul(this.k)};function He(){Nt.call(this,"k256","ffffffff ffffffff ffffffff ffffffff ffffffff ffffffff fffffffe fffffc2f")}n(He,Nt),He.prototype.split=function(r,u){for(var p=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&p,h=10;h<r.length;h++){var C=r.words[h]|0;r.words[h-10]=(C&p)<<4|T>>>22,T=C}T>>>=22,r.words[h-10]=T,T===0&&r.length>10?r.length-=10:r.length-=9},He.prototype.imulK=function(r){r.words[r.length]=0,r.words[r.length+1]=0,r.length+=2;for(var u=0,p=0;p<r.length;p++){var d=r.words[p]|0;u+=d*977,r.words[p]=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 Zn(){Nt.call(this,"p224","ffffffff ffffffff ffffffff ffffffff 00000000 00000000 00000001")}n(Zn,Nt);function to(){Nt.call(this,"p192","ffffffff ffffffff ffffffff fffffffe ffffffff ffffffff")}n(to,Nt);function In(){Nt.call(this,"25519","7fffffffffffffff ffffffffffffffff ffffffffffffffff ffffffffffffffed")}n(In,Nt),In.prototype.imulK=function(r){for(var u=0,p=0;p<r.length;p++){var d=(r.words[p]|0)*19+u,h=d&67108863;d>>>=26,r.words[p]=h,u=d}return u!==0&&(r.words[r.length++]=u),r},o._prime=function(r){if(Ge[r])return Ge[r];var u;if(r==="k256")u=new He;else if(r==="p224")u=new Zn;else if(r==="p192")u=new to;else if(r==="p25519")u=new In;else throw new Error("Unknown prime "+r);return Ge[r]=u,u};function G(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}G.prototype._verify1=function(r){t(r.negative===0,"red works only with positives"),t(r.red,"red works only with red numbers")},G.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")},G.prototype.imod=function(r){return this.prime?this.prime.ireduce(r)._forceRed(this):(b(r,r.umod(this.m)._forceRed(this)),r)},G.prototype.neg=function(r){return r.isZero()?r.clone():this.m.sub(r)._forceRed(this)},G.prototype.add=function(r,u){this._verify2(r,u);var p=r.add(u);return p.cmp(this.m)>=0&&p.isub(this.m),p._forceRed(this)},G.prototype.iadd=function(r,u){this._verify2(r,u);var p=r.iadd(u);return p.cmp(this.m)>=0&&p.isub(this.m),p},G.prototype.sub=function(r,u){this._verify2(r,u);var p=r.sub(u);return p.cmpn(0)<0&&p.iadd(this.m),p._forceRed(this)},G.prototype.isub=function(r,u){this._verify2(r,u);var p=r.isub(u);return p.cmpn(0)<0&&p.iadd(this.m),p},G.prototype.shl=function(r,u){return this._verify1(r),this.imod(r.ushln(u))},G.prototype.imul=function(r,u){return this._verify2(r,u),this.imod(r.imul(u))},G.prototype.mul=function(r,u){return this._verify2(r,u),this.imod(r.mul(u))},G.prototype.isqr=function(r){return this.imul(r,r.clone())},G.prototype.sqr=function(r){return this.mul(r,r)},G.prototype.sqrt=function(r){if(r.isZero())return r.clone();var u=this.m.andln(3);if(t(u%2===1),u===3){var p=this.m.add(new o(1)).iushrn(2);return this.pow(r,p)}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},G.prototype.invm=function(r){var u=r._invmp(this.m);return u.negative!==0?(u.negative=0,this.imod(u).redNeg()):this.imod(u)},G.prototype.pow=function(r,u){if(u.isZero())return new o(1).toRed(this);if(u.cmpn(1)===0)return r.clone();var p=4,d=new Array(1<<p);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!==p&&(h!==0||v!==0))&&(T=this.mul(T,d[C]),f=0,C=0)}l=26}return T},G.prototype.convertTo=function(r){var u=r.umod(this.m);return u===r?u.clone():u},G.prototype.convertFrom=function(r){var u=r.clone();return u.red=null,u},o.mont=function(r){return new Re(r)};function Re(y){G.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(Re,G),Re.prototype.convertTo=function(r){return this.imod(r.ushln(this.shift))},Re.prototype.convertFrom=function(r){var u=this.imod(r.mul(this.rinv));return u.red=null,u},Re.prototype.imul=function(r,u){if(r.isZero()||u.isZero())return r.words[0]=0,r.length=1,r;var p=r.imul(u),d=p.maskn(this.shift).mul(this.minv).imaskn(this.shift).mul(this.m),h=p.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)},Re.prototype.mul=function(r,u){if(r.isZero()||u.isZero())return new o(0)._forceRed(this);var p=r.mul(u),d=p.maskn(this.shift).mul(this.minv).imaskn(this.shift).mul(this.m),h=p.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)},Re.prototype.invm=function(r){var u=this.imod(r._invmp(this.m).mul(this.r2));return u._forceRed(this)}})(typeof ic>"u"||ic,Um)});var ch={};fs(ch,{appHelpers:()=>sh});module.exports=Hd(ch);var Bc=require("@msafe/sui3-utils");var re=require("@alphafi/alphafi-sdk"),Xe=require("@msafe/sui3-utils"),Jt=require("@mysten/bcs");var no=class{constructor(e,t){this.transaction=e;this.simResult=t}transaction;simResult;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=re.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&&re.poolInfo[t].assetTypes.length===2}isSingleAssetDepositEvent(e,t){return e.event_type===0&&re.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:Xe.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}=re.singleAssetPoolCoinMap[e],{expo:s}=re.coinsList[i];n=Math.floor(Number(n)/10**(9-s)).toString()}return{txType:Xe.TransactionType.Other,type:"depositSingleAsset",intentionData:{poolName:e,amount:n}}}decodeWithdraw(e){let t=this.extractXTokensAmount();return console.log("Decoder.decodeWithdraw",t),{txType:Xe.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:Xe.TransactionType.Other,type:"withdrawAlpha",intentionData:{withdrawFromLocked:Number(n)>0,xTokensAmount:t}}}decodeClaimReward(){return{txType:Xe.TransactionType.Other,type:"claimReward",intentionData:{}}}};var Ac=require("@alphafi/alphafi-sdk");var vc=Mt(require("sort-keys-recursive")),w=class{constructor(e){this.data=e}data;serialize(){return JSON.stringify((0,vc.default)(this.data))}};var oo=class a extends w{constructor(t){super(t);this.data=t}data;txType;txSubType;async build(t){let{account:n}=t;return await(0,Ac.claimRewardTxb)(n.address)}static fromData(t){return new a(t)}};var Mc=require("@alphafi/alphafi-sdk");var ao=class a extends w{constructor(t){super(t);this.data=t}data;txType;txSubType;async build(t){let{account:n}=t,{poolName:o,amount:i,isAmountA:s}=this.data;return await(0,Mc.depositDoubleAssetTxb)(o,n.address,i,s)}static fromData(t){return console.log("DepositDoubleAssetIntention.fromData",t),new a(t)}};var Oc=require("@alphafi/alphafi-sdk");var io=class a extends w{constructor(t){super(t);this.data=t}data;txType;txSubType;async build(t){let{account:n}=t,{poolName:o,amount:i}=this.data;return await(0,Oc.depositSingleAssetTxb)(o,n.address,i)}static fromData(t){return console.log("DepositSingleAssetIntention.fromData",t),new a(t)}};var Pc=require("@alphafi/alphafi-sdk");var ro=class a extends w{constructor(t){super(t);this.data=t}data;txType;txSubType;async build(t){let{account:n}=t,{poolName:o,xTokensAmount:i}=this.data;return await(0,Pc.withdrawTxb)(i,o,n.address)}static fromData(t){return console.log("WithdrawIntention.fromData",t),new a(t)}};var Rc=require("@alphafi/alphafi-sdk");var so=class a extends w{constructor(t){super(t);this.data=t}data;txType;txSubType;async build(t){let{account:n}=t,{withdrawFromLocked:o,xTokensAmount:i}=this.data;return await(0,Rc.withdrawAlphaTxb)(i,o,n.address)}static fromData(t){return console.log("WithdrawAlphaIntention.fromData",t),new a(t)}};var co=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 no(t,i).decode();return{txType:Bc.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=io.fromData(e.intentionData);break;case"depositDoubleAsset":n=ao.fromData(e.intentionData);break;case"withdraw":n=ro.fromData(e.intentionData);break;case"withdrawAlpha":n=so.fromData(e.intentionData);break;case"claimReward":n=oo.fromData(e.intentionData);break;default:throw new Error("not implemented")}return n.build({account:t})}};var al=require("@msafe/sui3-utils");var Ut=require("@msafe/sui3-utils"),lo=require("@mysten/sui/bcs"),uo=require("bucket-protocol-sdk");var po=class{constructor(e){this.transaction=e}transaction;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(uo.SBUCK_FOUNTAIN_PACKAGE_ID,"fountain_core","stake")}isSBUCKUnstakeTransaction(){return!!this.getMoveCallPackageModuleCommand(uo.SBUCK_FOUNTAIN_PACKAGE_ID,"fountain_core","force_unstake")}isSBUCKClaimTransaction(){return!!this.getMoveCallPackageModuleCommand(uo.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:Ut.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 m=c.arguments[1];m.$kind==="Input"&&(t=this.getPureInputU64(m.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 m=c.arguments[4];m.$kind==="Input"&&(t=this.getPureInputU64(m.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 m=c.arguments[5];m.$kind==="Input"&&(t=this.getPureInputU64(m.Input));let b=c.arguments[6];if(b.$kind==="Input"){let S=this.getPureAddresses(b.Input);S.length===1&&([n]=S)}}return{txType:Ut.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 m=c.arguments[4];m.$kind==="Input"&&(n=this.getPureInputU64(m.Input));let b=c.arguments[5];if(b.$kind==="Input"){let I=this.getPureAddresses(b.Input);I.length===1&&([i]=I)}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 m=c.arguments[5];m.$kind==="Input"&&(n=this.getPureInputU64(m.Input));let b=c.arguments[6];if(b.$kind==="Input"){let I=this.getPureAddresses(b.Input);I.length===1&&([i]=I)}let S=this.getSplitCoinsCommands()[0].SplitCoins.amounts[0];S.$kind==="Input"&&(t=this.getPureInputU64(S.Input))}return{txType:Ut.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 m=this.getPureAddresses(c.Input);m.length===1&&([n]=m)}}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 m=this.getPureAddresses(c.Input);m.length===1&&([n]=m)}}return{txType:Ut.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:Ut.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:Ut.TransactionType.Other,type:"sbuck-deposit",intentionData:{coinType:t,amount:n,isStake:s}}}decodeSBUCKUnstake(){let e="0",t=this.isSBUCKStakeTransaction();if(t){let m=this.getSplitCoinsCommands()[0].SplitCoins.amounts[0];m.$kind==="Input"&&(e=this.getPureInputU64(m.Input))}let n=[],o=this.getMoveCallModuleCommands("proof_rule","unlock");if(o.length>0)for(let c=0;c<o.length;c++){let m=o[c];n.push("")}else{let c=this.getMoveCallModuleCommands("fountain_core","force_unstake");for(let m=0;m<c.length;m++){let S=c[m].MoveCall.arguments[2];if(S.$kind==="Input"){let{objectId:I}=this.inputs[S.Input].UnresolvedObject;n.push(I)}}}let i=this.isSBUCKWithdrawTransaction(),s={stakeProofs:n,amount:e,isStake:t,toBuck:i};return console.log("Decoder.decodeSBUCKUnstake",s),{txType:Ut.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:Ut.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:Ut.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:Ut.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:Ut.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:Ut.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:Ut.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 lo.bcs.U64.fromBase64(t.Pure.bytes)}getPureAddresses(e){let t=this.inputs[e];if(t.$kind!=="Pure")throw new Error("not pure argument");return lo.bcs.vector(lo.bcs.Address).fromBase64(t.Pure.bytes)}};var Lc=require("@msafe/sui3-utils");var Nc=require("@mysten/sui/transactions"),Wc=require("bucket-protocol-sdk");var Ec=require("bucket-protocol-sdk"),Wt=(a,e)=>{let t=a==="sui:mainnet"?"mainnet":"testnet";return new Ec.BucketClient(t,e.address)};var _c=async(a,e,t)=>{let{coinType:n,amount:o,buckToCoin:i}=a,s=new Nc.Transaction,c=Wt(t,e);return await(0,Wc.buildPsmTx)(c,s,n,o,i,e.address),s};var fo=class a extends w{constructor(t){super(t);this.data=t}data;txType=Lc.TransactionType.Other;txSubType="psm";async build(t){let{account:n,network:o}=t;return await _c(this.data,n,o)}static fromData(t){return new a(t)}};var Kc=require("@msafe/sui3-utils");var Cn=require("@mysten/sui/transactions"),fe=require("bucket-protocol-sdk");var jc=async(a,e,t)=>{let{collateralType:n,collateralAmount:o,borrowAmount:i,insertionPlace:s,strapId:c}=a,m=new Cn.Transaction,b=Wt(t,e);return await(0,fe.buildBorrowTx)(b,m,n,o,i,e.address,s,c),m},Uc=async(a,e,t)=>{let{collateralType:n,withdrawAmount:o,insertionPlace:i,strapId:s}=a,c=new Cn.Transaction,m=Wt(t,e);return await(0,fe.buildWithdrawTx)(m,c,n,o,e.address,i,s),c},qc=async(a,e,t)=>{let{collateralType:n,repayAmount:o,withdrawAmount:i,isSurplus:s,insertionPlace:c,strapId:m}=a,b=new Cn.Transaction,S=Wt(t,e);return await(0,fe.buildRepayTx)(S,b,n,o,i,e.address,s,c,m),b},Fc=async(a,e,t)=>{let{collateralType:n,recipient:o,strapId:i}=a,s=new Cn.Transaction,c=Wt(t,e);return await(0,fe.buildCloseTx)(c,s,n,o,i),s};var ho=class a extends w{constructor(t){super(t);this.data=t}data;txType=Kc.TransactionType.Other;txSubType="borrow";async build(t){let{account:n,network:o}=t;return await jc(this.data,n,o)}static fromData(t){return new a(t)}};var Vc=require("@msafe/sui3-utils");var go=class a extends w{constructor(t){super(t);this.data=t}data;txType=Vc.TransactionType.Other;txSubType="repay";async build(t){let{account:n,network:o}=t;return await qc(this.data,n,o)}static fromData(t){return new a(t)}};var $c=require("@msafe/sui3-utils");var yo=class a extends w{constructor(t){super(t);this.data=t}data;txType=$c.TransactionType.Other;txSubType="withdraw";async build(t){let{account:n,network:o}=t;return await Uc(this.data,n,o)}static fromData(t){return new a(t)}};var Gc=require("@msafe/sui3-utils");var bo=class a extends w{constructor(t){super(t);this.data=t}data;txType=Gc.TransactionType.Other;txSubType="close";async build(t){let{account:n,network:o}=t;return await Fc(this.data,n,o)}static fromData(t){return new a(t)}};var Dn=require("@msafe/sui3-utils");var xn=require("@mysten/sui/transactions"),he=require("bucket-protocol-sdk");var Hc=async(a,e,t)=>{let{coinType:n,amount:o,isStake:i}=a,s=new xn.Transaction,c=Wt(t,e);return await(0,he.buildSBUCKDepositTx)(c,s,n,o,e.address,i),s},Xc=async(a,e,t)=>{let{stakeProofs:n,amount:o,isStake:i,toBuck:s}=a,c=new xn.Transaction,m=Wt(t,e);return await(0,he.buildSBUCKUnstakeTx)(m,c,n,o,e.address,i,s),c},zc=async(a,e,t)=>{let{amount:n}=a,o=new xn.Transaction,i=Wt(t,e);return await(0,he.buildSBUCKWithdrawTx)(i,o,n,e.address),o},Qc=async(a,e,t)=>{let{stakeProofs:n}=a,o=new xn.Transaction,i=Wt(t,e);return await(0,he.buildSBUCKClaimTx)(i,o,n,e.address),o};var To=class a extends w{constructor(t){super(t);this.data=t}data;txType=Dn.TransactionType.Other;txSubType="sbuck-deposit";async build(t){let{account:n,network:o}=t;return await Hc(this.data,n,o)}static fromData(t){return new a(t)}},So=class a extends w{constructor(t){super(t);this.data=t}data;txType=Dn.TransactionType.Other;txSubType="sbuck-unstake";async build(t){let{account:n,network:o}=t;return await Xc(this.data,n,o)}static fromData(t){return new a(t)}},wo=class a extends w{constructor(t){super(t);this.data=t}data;txType=Dn.TransactionType.Other;txSubType="sbuck-withdraw";async build(t){let{account:n,network:o}=t;return await zc(this.data,n,o)}static fromData(t){return new a(t)}},Io=class a extends w{constructor(t){super(t);this.data=t}data;txType=Dn.TransactionType.Other;txSubType="sbuck-claim";async build(t){let{account:n,network:o}=t;return await Qc(this.data,n,o)}static fromData(t){return new a(t)}};var vo=require("@msafe/sui3-utils");var Co=require("@mysten/sui/transactions"),ze=require("bucket-protocol-sdk");var Jc=async(a,e,t)=>{let{coinType:n,amount:o}=a,i=new Co.Transaction,s=Wt(t,e);return await(0,ze.buildTankDepositTx)(s,i,n,o,e.address),i},Yc=async(a,e,t)=>{let{coinType:n,amount:o}=a,i=new Co.Transaction,s=Wt(t,e);return await(0,ze.buildTankWithdrawTx)(s,i,n,o,e.address),i},Zc=async(a,e,t)=>{let{coinType:n}=a,o=new Co.Transaction,i=Wt(t,e);return await(0,ze.buildTankClaimTx)(i,o,n,e.address),o};var tl=require("@mysten/sui/transactions"),el=require("bucket-protocol-sdk");var nl=async(a,e,t)=>{let{coinType:n,proofCount:o}=a,i=new tl.Transaction,s=Wt(t,e);return await(0,el.buildLockedClaimTx)(s,i,n,o,e.address),i};var xo=class a extends w{constructor(t){super(t);this.data=t}data;txType=vo.TransactionType.Other;txSubType="tank-deposit";async build(t){let{account:n,network:o}=t;return await Jc(this.data,n,o)}static fromData(t){return new a(t)}},Do=class a extends w{constructor(t){super(t);this.data=t}data;txType=vo.TransactionType.Other;txSubType="tank-withdraw";async build(t){let{account:n,network:o}=t;return await Yc(this.data,n,o)}static fromData(t){return new a(t)}},ko=class a extends w{constructor(t){super(t);this.data=t}data;txType=vo.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 ol=require("@msafe/sui3-utils");var Ao=class a extends w{constructor(t){super(t);this.data=t}data;txType=ol.TransactionType.Other;txSubType="lock-claim";async build(t){let{account:n,network:o}=t;return await nl(this.data,n,o)}static fromData(t){return new a(t)}};var Mo=class{application="bucket";supportSDK="@mysten/sui";async deserialize(e){console.log("Bucket helper deserialize input: ",e);let{transaction:t}=e,o=new po(t).decode();return{txType:al.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=fo.fromData(e.intentionData);break;case"borrow":i=ho.fromData(e.intentionData);break;case"withdraw":i=yo.fromData(e.intentionData);break;case"repay":i=go.fromData(e.intentionData);break;case"close":i=bo.fromData(e.intentionData);break;case"tank-deposit":i=xo.fromData(e.intentionData);break;case"tank-withdraw":i=Do.fromData(e.intentionData);break;case"tank-claim":i=ko.fromData(e.intentionData);break;case"sbuck-deposit":i=To.fromData(e.intentionData);break;case"sbuck-unstake":i=So.fromData(e.intentionData);break;case"sbuck-withdraw":i=wo.fromData(e.intentionData);break;case"sbuck-claim":i=Io.fromData(e.intentionData);break;case"lock-claim":i=Ao.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 H=require("@mysten/sui/jsonRpc"),zd={"sui:mainnet":"mainnet","sui:testnet":"testnet","sui:devnet":"devnet","sui:localnet":"localnet"};function kn(a){return zd[a]}var Yt=async(a,e)=>{let{CetusClmmSDK:t}=await import("@cetusprotocol/sui-clmm-sdk"),n=t.createSDK({env:"mainnet",sui_client:new H.SuiJsonRpcClient({url:(0,H.getJsonRpcFullnodeUrl)("mainnet"),network:"mainnet"})});return n.setSenderAddress(e.address),n},Kt=async(a,e)=>{let{CetusFarmsSDK:t}=await import("@cetusprotocol/farms-sdk"),n=t.createSDK({env:"mainnet",sui_client:new H.SuiJsonRpcClient({url:(0,H.getJsonRpcFullnodeUrl)("mainnet"),network:"mainnet"})});return n.setSenderAddress(e.address),n},Qd="https://api-sui.cetus.zone/router_v2/find_routes",il=async(a,e)=>{let{AggregatorClient:t,Env:n}=await import("@cetusprotocol/aggregator-sdk"),o=new H.SuiJsonRpcClient({url:"https://fullnode.mainnet.sui.io/",network:"mainnet"});return new t({endpoint:Qd,signer:e.address,client:o,env:n.Mainnet})},vn=async(a,e)=>{let{CetusVaultsSDK:t}=await import("@cetusprotocol/vaults-sdk"),n=t.createSDK({env:"mainnet"});return n.setSenderAddress(e.address),n},Qe=async(a,e)=>{let{CetusXcetusSDK:t}=await import("@cetusprotocol/xcetus-sdk"),n=t.createSDK({env:"mainnet"});return n.setSenderAddress(e.address),n};var rl=async(a,e,t)=>await(await Yt(t,e)).Pool.createPoolPayload(a),sl=async(a,e,t)=>await(await Yt(t,e)).Position.createAddLiquidityFixTokenPayload(a?.parameter,a?.gasEstimateArg),cl=async(a,e,t)=>await(await Yt(t,e)).Position.createAddLiquidityFixTokenPayload(a?.parameter,a?.gasEstimateArg),ll=async(a,e,t)=>await(await Yt(t,e)).Position.closePositionPayload(a),ul=async(a,e,t)=>await(await Yt(t,e)).Position.removeLiquidityPayload(a),pl=async(a,e,t)=>await(await Yt(t,e)).Rewarder.collectRewarderPayload(a);var Oo=class a extends w{constructor(t){super(t);this.data=t}data;txType=ml.TransactionType.Other;txSubType="OpenAndAddLiquidity";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 dl=require("@msafe/sui3-utils");var Po=class a extends w{constructor(t){super(t);this.data=t}data;txType=dl.TransactionType.Other;txSubType="ClaimFeeAndMining";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 fl=require("@msafe/sui3-utils");var Ro=class a extends w{constructor(t){super(t);this.data=t}data;txType=fl.TransactionType.Other;txSubType="CreatePool";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 hl=require("@msafe/sui3-utils");var Bo=class a extends w{constructor(t){super(t);this.data=t}data;txType=hl.TransactionType.Other;txSubType="DecreaseLiquidity";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 gl=async(a,e,t)=>await(await Kt(t,e)).Farms.openPositionAddLiquidityStakePayload(a),yl=async(a,e,t)=>await(await Kt(t,e)).Farms.addLiquidityFixCoinPayload(a),bl=async(a,e,t)=>await(await Kt(t,e)).Farms.removeLiquidityPayload(a);var Tl=async(a,e,t)=>await(await Kt(t,e)).Farms.removeLiquidityPayload(a),Sl=async(a,e,t)=>await(await Kt(t,e)).Farms.claimFeeAndClmmReward(a),wl=async(a,e,t)=>await(await Kt(t,e)).Farms.harvestPayload(a),Il=async(a,e,t)=>{let n=await Kt(t,e),o=Object.values(a);return await n.Farms.batchHarvestPayload(o)},Cl=async(a,e,t)=>await(await Kt(t,e)).Farms.depositPayload(a),xl=async(a,e,t)=>await(await Kt(t,e)).Farms.withdrawPayload(a);var Eo=class a extends w{constructor(t){super(t);this.data=t}data;txType=Dl.TransactionType.Other;txSubType="FarmingOpenAndAddLiquidity";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 No=class a extends w{constructor(t){super(t);this.data=t}data;txType=kl.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 vl=require("@msafe/sui3-utils");var Wo=class a extends w{constructor(t){super(t);this.data=t}data;txType=vl.TransactionType.Other;txSubType="FarmingClaimFeeAndReward";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 Al=require("@msafe/sui3-utils");var _o=class a extends w{constructor(t){super(t);this.data=t}data;txType=Al.TransactionType.Other;txSubType="FarmingDecreaseLiquidity";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 Ml=require("@msafe/sui3-utils");var Lo=class a extends w{constructor(t){super(t);this.data=t}data;txType=Ml.TransactionType.Other;txSubType="FarmingHarvest";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 Ol=require("@msafe/sui3-utils");var jo=class a extends w{constructor(t){super(t);this.data=t}data;txType=Ol.TransactionType.Other;txSubType="FarmingIncreaseLiquidity";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 Pl=require("@msafe/sui3-utils");var Uo=class a extends w{constructor(t){super(t);this.data=t}data;txType=Pl.TransactionType.Other;txSubType="FarmingRemoveLiquidity";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 qo=class a extends w{constructor(t){super(t);this.data=t}data;txType=Rl.TransactionType.Other;txSubType="FarmingStake";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 Fo=class a extends w{constructor(t){super(t);this.data=t}data;txType=Bl.TransactionType.Other;txSubType="FarmingUnstake";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 El=require("@msafe/sui3-utils");var Ko=class a extends w{constructor(t){super(t);this.data=t}data;txType=El.TransactionType.Other;txSubType="IncreaseLiquidity";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 _l=require("@msafe/sui3-utils");var Vo=async()=>{let{Transaction:a}=await import("@mysten/sui/transactions");return new a},Jd=async(a,e,t)=>{let n=await vn(t,e),o=await Vo();return o.setSender(e.address),n.Vest.buildRedeemPayload(a.params,o),o},Yd=async(a,e)=>{let{default:t,vaults_mainnet:n}=await import("haedal-vault-sdk"),o=new t(n);o.senderAddress=e.address;let i=await Vo();return i.setSender(e.address),await o?.Vest.buildRedeemPayload(a.params,i),i},Nl=async(a,e,t)=>{let n=await Yt(t,e),o=await Vo();return n?.Vest.buildRedeemPayload(a.params,o),o},Zd=async(a,e,t)=>{let n=await Yt(t,e),o=await Kt(t,e),i=await Vo(),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},Wl=async(a,e,t)=>a.type==="clmm"?Nl(a,e,t):a.type==="farms"?Zd(a,e,t):a.type==="vaults"?Jd(a,e,t):a.type==="haedalVaults"?Yd(a,e):Nl(a,e,t);var $o=class a extends w{constructor(t){super(t);this.data=t}data;txType=_l.TransactionType.Other;txSubType="PosVestingRedeem";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 Ll=require("@msafe/sui3-utils");var Go=class a extends w{constructor(t){super(t);this.data=t}data;txType=Ll.TransactionType.Other;txSubType="RemoveLiquidity";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 ql=require("@msafe/sui3-utils");var jl=require("@mysten/sui/transactions");var Ul=async(a,e,t)=>{let{restituteMsafeFastRouterSwapParams:n}=await import("@cetusprotocol/aggregator-sdk"),o=await il(t,e),i=new jl.Transaction;return await o.fastRouterSwap({...a,router:n(a.router),txb:i}),i};var Ho=class a extends w{constructor(t){super(t);this.data=t}data;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 hs=require("@mysten/sui/transactions");var Fl=async(a,e,t)=>{let n=await vn(t,e),o=new hs.Transaction;return o.setSender(e.address),await n.Vaults.deposit(a,o),o},Kl=async(a,e,t)=>{let n=await vn(t,e),o=new hs.Transaction;return await n.Vaults.withdraw(a,o),o};var Xo=class a extends w{constructor(t){super(t);this.data=t}data;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 zo=class a extends w{constructor(t){super(t);this.data=t}data;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 zl=require("@msafe/sui3-utils");var Hl=require("@mysten/sui/transactions"),Gl={package_id:"0x355714a1eeb7ab1d80902da6c92001170cda1212edf524c32aa308a3ac177c31",published_at:"0x355714a1eeb7ab1d80902da6c92001170cda1212edf524c32aa308a3ac177c31",cetus_coin_type:"0x06864a6f921804860930db6ddbe2e16acdf8504495ea7481637a1c8b9a8fe54b::cetus::CETUS"},Xl=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 Hl.Transaction;return i.forEach(m=>{c.moveCall({target:`${Gl.published_at}::router::redeem`,typeArguments:[Gl.cetus_coin_type],arguments:[c.object(n),c.object(o),c.pure(m),c.object(s)]})}),c};var Qo=class a extends w{constructor(t){super(t);this.data=t}data;txType=zl.TransactionType.Other;txSubType="VestingRedeem";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 eu=require("@msafe/sui3-utils");var Ql=async(a,e,t)=>await(await Qe(t,e)).XCetusModule.convertPayload(a),Jl=async(a,e,t)=>await(await Qe(t,e)).XCetusModule.redeemLockPayload(a),Yl=async(a,e,t)=>await(await Qe(t,e)).XCetusModule.redeemDividendV3Payload(a.veNftId,a.rewardList),Zl=async(a,e,t)=>await(await Qe(t,e)).XCetusModule.cancelRedeemPayload(a),tu=async(a,e,t)=>await(await Qe(t,e)).XCetusModule.redeemPayload(a);var Jo=class a extends w{constructor(t){super(t);this.data=t}data;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 Yo=class a extends w{constructor(t){super(t);this.data=t}data;txType=nu.TransactionType.Other;txSubType="xCETUSClaimStakingRwewards";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 ou=require("@msafe/sui3-utils");var Zo=class a extends w{constructor(t){super(t);this.data=t}data;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 ta=class a extends w{constructor(t){super(t);this.data=t}data;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 ea=class a extends w{constructor(t){super(t);this.data=t}data;txType=iu.TransactionType.Other;txSubType="xCETUSRedeemLock";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 na=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=Oo.fromData(e.intentionData);break;case"IncreaseLiquidity":i=Ko.fromData(e.intentionData);break;case"DecreaseLiquidity":i=Bo.fromData(e.intentionData);break;case"RemoveLiquidity":i=Go.fromData(e.intentionData);break;case"ClaimFeeAndMining":i=Po.fromData(e.intentionData);break;case"FarmingOpenAndAddLiquidity":i=Eo.fromData(e.intentionData);break;case"FarmingIncreaseLiquidity":i=jo.fromData(e.intentionData);break;case"FarmingDecreaseLiquidity":i=_o.fromData(e.intentionData);break;case"FarmingRemoveLiquidity":i=Uo.fromData(e.intentionData);break;case"FarmingClaimFeeAndReward":i=Wo.fromData(e.intentionData);break;case"FarmingHarvest":i=Lo.fromData(e.intentionData);break;case"FarmingBatchHarvest":i=No.fromData(e.intentionData);break;case"FarmingStake":i=qo.fromData(e.intentionData);break;case"FarmingUnstake":i=Fo.fromData(e.intentionData);break;case"xCETUSConvert":i=Zo.fromData(e.intentionData);break;case"xCETUSRedeemLock":i=ea.fromData(e.intentionData);break;case"xCETUSClaimStakingRwewards":i=Yo.fromData(e.intentionData);break;case"xCETUSCancelRedeem":i=Jo.fromData(e.intentionData);break;case"xCETUSRedeem":i=ta.fromData(e.intentionData);break;case"VestingRedeem":i=Qo.fromData(e.intentionData);break;case"AggregatorSwap":i=Ho.fromData(e.intentionData);break;case"AddVaultsPosition":i=Xo.fromData(e.intentionData);break;case"RemoveVaultsPosition":i=zo.fromData(e.intentionData);break;case"PosVestingRedeem":i=$o.fromData(e.intentionData);break;case"CreatePool":i=Ro.fromData(e.intentionData);break;default:throw new Error("not implemented")}return i.build({suiClient:t,account:n,network:o})}};var Fu=require("@msafe/sui3-utils");var su=Mt(require("sort-keys-recursive")),ge=class{constructor(e){this.data=e}data;serialize(){return JSON.stringify((0,su.default)(this.data))}};var gs={};fs(gs,{contractId:()=>nf,default:()=>cf,feeObjId:()=>rf,roleObjId:()=>of,status:()=>ef,transaction:()=>tf,upgradeCapObjId:()=>sf,vaultObjId:()=>af});var tf="DiBZq4UmVVYiRL6ZJmFKYoHcxtxqrhsCXSkFyT7wUr3j",ef="success",nf="0x81c960dc653975fbd0072deca8afb92d322898c911622898ba1b2e3ad0c4bd8d",of="0xc6ec0bdee0bb59a72077e9acd2f42457043cf47080b3d3fad4d39abf28bba63a",af="0xbc4021387fbac149119fd24e92be9e58f745774292f3a2a12e2ac6daf5363e1d",rf="0x4178f63970fe2daeb256dc5730ad172e82b3e8eb45f31b33e0daae72cd35e1e1",sf="0xe1e9aa7d222d151bfe6dd83358b0d7fdcb11260f710800cfaf7ccc1b1e245115",cf={transaction:tf,status:ef,contractId:nf,roleObjId:of,vaultObjId:af,feeObjId:rf,upgradeCapObjId:sf};var ys={};fs(ys,{contractId:()=>pf,default:()=>gf,feeObjId:()=>ff,roleObjId:()=>mf,status:()=>uf,transaction:()=>lf,upgradeCapObjId:()=>hf,vaultObjId:()=>df});var lf="855FNDV8o8Z3fWULPnQo9qdhLJpsg7wZrkCpNyfw9KfB",uf="success",pf="0xc357c3985e8fb875d6b37141497af660779aa1bab0ec489b2213efd74067d1fa",mf="0x5ab49bdf9fd1413e328ef242b3f8d83dde791b38a0b627bfc87fb25c010d34f1",df="0xb483558770d8eb26007f193b75db40f0a45f2e36863a687625885d4de6993378",ff="0x48453fc4d7cde3fe35aad89e5dfb496608a6a55ea529a1c0274681a808627f94",hf="0x34279779a0d0d36bd5044b04830d607fa1b0ecf316548c8ac3a44151e4f1a42a",gf={transaction:lf,status:uf,contractId:pf,roleObjId:mf,vaultObjId:df,feeObjId:ff,upgradeCapObjId:hf};var yf=(0,H.getJsonRpcFullnodeUrl)("testnet"),bf=(0,H.getJsonRpcFullnodeUrl)("testnet"),Tf=(0,H.getJsonRpcFullnodeUrl)("mainnet"),Sf=(0,H.getJsonRpcFullnodeUrl)("mainnet"),wf="https://bc3p6l5unl.execute-api.us-west-1.amazonaws.com/prod",If="https://rolsbkota7.execute-api.us-west-1.amazonaws.com/prod",Cf="https://6p6mkx33ne.execute-api.us-west-1.amazonaws.com/prod",xf="https://xrae3mrjv5.execute-api.us-west-1.amazonaws.com/prod",cu=gs,lu=ys,Df=new Map([["dev",{env:"dev",rpc:{url:yf},backend:{url:wf},contract:cu}],["stg",{env:"stg",rpc:{url:bf},backend:{url:If},contract:cu}],["prev",{env:"prev",rpc:{url:Tf},backend:{url:Cf},contract:lu}],["prod",{env:"prod",rpc:{url:Sf},backend:{url:xf},contract:lu}]]);function uu(a,e){let t=Df.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 pu=require("@mysten/sui/grpc");function kf(a){return Object.assign(a,{getObject(e){return a.core.getObject(e)},async listCoins(e){let t=await a.core.listCoins({owner:e.owner,coinType:e.coinType,cursor:e.cursor??void 0});return{objects:t.objects.map(n=>({coinType:e.coinType??"",objectId:n.objectId,version:n.version,digest:n.digest,balance:n.balance??"0"})),hasNextPage:t.hasNextPage,cursor:t.cursor}}})}function An(a,e){let t=kn(a),n=new pu.SuiGrpcClient({network:t,baseUrl:e??(0,H.getJsonRpcFullnodeUrl)(t)});return kf(n)}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 oa=class extends j{constructor(){super(11,"Backend is not specified")}};var aa=class extends j{constructor(){super(1,"Wallet not connected")}};var ce=Mt(require("axios"));var Je=class extends j{constructor(e,t){super(10,e,{context:t})}};var ia=class a{constructor(e){this.apiURL=e}apiURL;static parseResponseData(e){if(e instanceof ce.AxiosError)throw new Je(e.response?.statusText);if(e.status===200){if(e.data.success)return e.data.data;throw new Je(e.data.code)}throw new Je(e.status.toString())}async getIncomingStreams(e,t){let n=await ce.default.post(`${this.apiURL}/stream`,{recipient:e,...t});return a.parseResponseData(n)}async getOutgoingStreams(e,t){let n=await ce.default.post(`${this.apiURL}/stream`,{sender:e,...t});return a.parseResponseData(n)}async getStreamHistory(e){let t=await ce.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 ce.default.post(`${this.apiURL}/stream-info`,{address:e});return a.parseResponseData(t)}async getAllRecipients(e,t){let n=await ce.default.post(`${this.apiURL}/stream-info`,{sender:e,status:t});return a.parseResponseData(n)}async getAllSenders(e,t){let n=await ce.default.post(`${this.apiURL}/stream-info`,{recipient:e,status:t});return a.parseResponseData(n)}};var vf={dev:"sui:testnet",stg:"sui:testnet",prev:"sui:mainnet",prod:"sui:mainnet"},Ye=class a{signer;suiClient;envConfig;_backend;constructor(e,t){this.envConfig=e,this.suiClient=t??An(vf[e.env],e.rpc.url),e.backend&&(this._backend=new ia(e.backend.url))}static new(e,t){let n=uu(e,t);return new a(n,t?.suiGrpcClient)}get walletType(){return this.wallet?this.wallet.type:"disconnected"}get backend(){if(!this._backend)throw new oa;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 aa;return this.signer}async walletAddress(){return this.wallet.address()}};var Ne=require("@mysten/sui/utils");var Bn=require("@mysten/sui/transactions");var Ss=require("@mysten/sui/transactions"),Rn=require("@mysten/sui/utils");var bs=50n,ra=10000n,du=25n,Ts=100000000n;var le=class{constructor(e){this.object=e}object;moveArg(e){return e.object(this.object)}},sa=class{constructor(e){this.objects=e}objects;moveArgs(e){return e.makeMoveVec({elements:this.objects.map(t=>e.object(t))})}},Be=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)}})}result;moveArg(){return this.result}};function fu(a,e){if(typeof e=="bigint"||typeof e=="number")return a.pure.u64(e);if(typeof e=="boolean")return a.pure.bool(e);if(typeof e=="string")return/^0x[0-9a-fA-F]+$/.test(e)?a.pure.address(e):a.pure.string(e);throw new Error(`Unsupported pure argument type: ${typeof e}`)}var ku=require("@mysten/bcs");var Mn=class extends j{constructor(e,t){super(3,e,{context:t})}};var yu=require("@mysten/bcs");var Zt=class extends j{constructor(e,t){super(6,e,{context:t})}};function ca(a){if(a==null)throw new Zt("Missing move object field");if(typeof a=="object"&&"fields"in a){let e=a.fields;if(e&&typeof e=="object")return e}if(typeof a=="object")return a;throw new Zt("Unexpected move object field shape",{value:String(a)})}function hu(a){return a.fields&&typeof a.fields=="object"&&!("balance"in a)&&!("config"in a)&&!("status"in a)?a.fields:a}function gu(a,e="balance"){if(a==null)throw new Zt(`Stream object missing ${e} field`);if(typeof a=="string"||typeof a=="number"||typeof a=="bigint")return BigInt(a);let t=ca(a),n=t.balance??t.value;if(n==null)throw new Zt(`Stream object ${e} field has unexpected shape`,{value:JSON.stringify(a)});return BigInt(String(n))}async function bu(a,e){let t=await a.listCoins({owner:e.owner,coinType:e.coinType,cursor:e.cursor??void 0,limit:e.limit});return{data:t.objects.map(n=>({coinObjectId:n.objectId,balance:n.balance,coinType:n.type})),hasNextPage:t.hasNextPage,nextCursor:t.cursor}}function Af(a){return a.core?.getObject?a.core.getObject.bind(a.core):a.getObject.bind(a)}function Tu(a){return a.json&&typeof a.json=="object"?hu(a.json):null}async function Su(a,e){try{let t=Af(a),{object:n}=await t({objectId:e,include:{json:!0,type:!0}}),o=Tu(n);return o?{data:{objectId:n.objectId,type:n.type,content:{dataType:"moveObject",type:n.type,fields:o}}}:{error:{code:"notExists"}}}catch{return{error:{code:"notExists"}}}}async function wu(a,e){if(e.length===0)return[];let{objects:t}=await a.getObjects({objectIds:e,include:{json:!0,type:!0}});return t.map(n=>{if(!("objectId"in n))return{error:{code:String(n.code??"unknown")}};let o=Tu(n);if(o)return{data:{objectId:n.objectId,type:n.type,content:{dataType:"moveObject",type:n.type,fields:o}}}})}async function Iu(a,e){let{balance:t}=await a.getBalance({owner:e.owner,coinType:e.coinType??void 0});return{coinType:t.coinType,totalBalance:t.balance}}async function Cu(a,e){return(await a.listBalances({owner:e})).balances.map(n=>({coinType:n.coinType,totalBalance:n.balance}))}async function xu(a,e){let{coinMetadata:t}=await a.getCoinMetadata({coinType:e});return t}async function la(a,e){e.transaction.setSenderIfNotSet(e.sender);let t=await a.simulateTransaction({transaction:e.transaction,include:{effects:!0,commandResults:!0}}),n=t.$kind==="Transaction"?t.Transaction:t.FailedTransaction;return{effects:n.effects?{status:{status:n.effects.status.success?"success":"failure",error:n.effects.status.error?.message}}:void 0,commandResults:t.commandResults,results:t.commandResults?.map(o=>({returnValues:o.returnValues.map(i=>[Array.from(i.bcs),"u64"])}))}}function Du(a,e=0,t=0){let n=a.commandResults?.[e]?.returnValues?.[t];if(!n)throw new Error("Missing command result");return BigInt(yu.bcs.u64().parse(n.bcs))}var ua=class{constructor(e){this.results=e}results;getU64(e=0,t=0){try{return Du(this.results,e,t)}catch{let[n,o]=this.getLegacyValue(e,t);if(o!=="u64")throw new Mn("Invalid contract return type.",{ctx:{expectType:"u64",gotType:o}});return ku.bcs.u64().parse(Uint8Array.from(n))}}getLegacyValue(e=0,t=0){let o=this.results.results?.[e]?.returnValues;if(!o?.[t])throw new Mn("Invalid contract return type.",{ctx:{expectType:"u64",gotType:"missing"}});return o[t]}};var pa=require("@mysten/bcs");var X=class extends j{constructor(e,t,n){super(2,`Invalid input: ${e}`,{context:{fieldKey:t,fieldValue:n}})}};var Au=pa.bcs.struct("StreamMetadata",{groupId:pa.bcs.string(),name:pa.bcs.string()}),Mf=64;function Mu(a){return Ou(a),Au.serialize(a).toBase64()}function On(a){let e=Au.fromBase64(a);return Ou(e),e}function Ou(a){if(!vu(a.name))throw new X("Invalid metadata: Name contains unknown character");if(!vu(a.groupId))throw new X("Invalid metadata: Group ID contains unknown character");if(a.name.length>Mf)throw new X("Invalid metadata: Name exceed max length 64")}function vu(a){return/^[\x00-\x7F]+$/.test(a)}var Pn=require("@mysten/sui/utils");function ma(a,e){return(0,Pn.normalizeStructTag)(a)===(0,Pn.normalizeStructTag)(e)}function Te(a,e){return(0,Pn.normalizeStructTag)(a)===(0,Pn.normalizeStructTag)(e)}function Se(a){if(a.$kind!=="MoveCall"||!a.MoveCall)return null;let{package:e,module:t,function:n}=a.MoveCall;return`${e}::${t}::${n}`}var da="txn.gas";var Pu=require("nanoid");function Ru(){return(0,Pu.nanoid)()}var Ee=class a{constructor(e,t,n){this.globals=e;this.feeContract=t;this.streamContract=n}globals;feeContract;streamContract;static convertCreateStreamInfoToInternal(e){return{metadata:Mu({name:e.name,groupId:Ru()}),coinType:(0,Rn.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 Ss.Transaction,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 m=0;m<e.recipients.length;m++){let b=e.recipients[m],S=this.amountForRecipient(b,e.numberEpoch),I=this.getStreamFeeLocal(S),[x]=t.splitCoins(s,[t.pure.u64(S+I)]),[D]=t.splitCoins(c,[t.pure.u64(this.flatSuiFee)]);this.streamContract.createStream(t,{paymentCoin:new Be(x),flatFeeCoin:new Be(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:bs,denominator:ra},claimFeePercent:{numerator:du,denominator:ra},flatFeePerStream:Ts}}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===da?n=e.gas:n=e.object(t.primaryCoin),n}getCreateStreamCoinRequests(e,t){let n=e.coinType;return ma(n,Rn.SUI_TYPE_ARG)?[{coinType:n,amount:t.totalAmount+t.streamFeeAmount+t.flatFeeAmount}]:[{coinType:n,amount:t.totalAmount+t.streamFeeAmount},{coinType:Rn.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 Ts}getStreamFeeLocal(e){return e*bs/ra}async getStreamFeeRemote(e){let t=this.feeContract.streamingFee(new Ss.Transaction,e),n=await la(this.globals.suiClient,{sender:await this.globals.walletAddress(),transaction:t});return new ua(n).getU64()}get wallet(){return this.globals.wallet}};var Bu="0x0000000000000000000000000000000000000000000000000000000000000006";var Ze=class{constructor(e,t,n){this.moduleName=e;this.config=t;this.globals=n}moduleName;config;globals;addContractCall(e,t){let n=`${this.config.contractId}::${this.moduleName}::${t.method}`;return e.moveCall({target:n,arguments:t.arguments.map(o=>o instanceof sa?o.moveArgs(e):o instanceof le?o.moveArg(e):o instanceof Be?o.moveArg():fu(e,o)),typeArguments:t.typeArgs}),e}makeObject(e){return typeof e=="string"?new le(e):e}vaultObject(){return new le(this.config.vaultObjId)}roleObject(){return new le(this.config.roleObjId)}feeObject(){return new le(this.config.feeObjId)}clockObject(){return new le(Bu)}};var tn=class a extends Ze{constructor(t,n){super(a.ModuleName,t,n);this.config=t;this.globals=n}config;globals;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 Ze{constructor(t,n){super(a.ModuleName,t,n);this.config=t;this.globals=n}config;globals;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),m=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,m],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 en=class{constructor(e){this.globals=e;let t=e.envConfig.contract;this.feeContract=new tn(t,e),this.streamContract=new te(t,e)}globals;feeContract;streamContract;async createStreams(e){let t=Ee.convertCreateStreamInfoToInternal(e);return this.createStreamHelper().buildCreateStreamTransactionBlock(t)}createStreamHelper(){return new Ee(this.globals,this.feeContract,this.streamContract)}setAutoClaim(e,t,n){let o=new Bn.Transaction;return this.streamContract.setAutoClaim(o,{streamId:e,enabled:t,coinType:n})}claimStream(e,t){let n=new Bn.Transaction;return this.streamContract.claimStream(n,{streamId:e,coinType:t})}claimStreamByProxy(e,t){let n=new Bn.Transaction;return this.streamContract.claimStreamByProxy(n,{streamId:e,coinType:t})}cancelStream(e,t){let n=new Bn.Transaction;return this.streamContract.cancelStream(n,{streamId:e,coinType:t}),n}};var nn=require("@mysten/sui/utils"),ws=require("luxon");var fa=class extends j{constructor(e,t){super(12,`Transaction failed: ${t}`,{context:{status:e,msg:t}})}};var Of=1e3,ha=class{constructor(e){this.globals=e;this.coinMetaHelper=new Is(e.suiClient),this.createStreamHelper=new en(e).createStreamHelper()}globals;coinMetaHelper;createStreamHelper;getStreamIdsFromCreateStreamResponse(e){if(e.effects?.status.status!=="success")throw new fa(e.effects?.status.status,e.effects?.status.error);return Object.entries(e.objectTypes??{}).filter(([,t])=>t.startsWith(`${this.globals.envConfig.contract.contractId}::stream::Stream`)).map(([t])=>t)}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(ws.Duration.fromMillis(Number(t*e.steps))),o={timeStart:e.timeStart,timeEnd:n,interval:ws.Duration.fromMillis(Number(t)),steps:e.steps};return this.validateTimeline(o),o}async getBalance(e,t){let n=await Iu(this.globals.suiClient,{owner:e,coinType:t}),o=await this.getCoinMeta(t);return{...n,coinType:(0,nn.normalizeStructTag)(n.coinType),coinMeta:o}}async getAllBalance(e){let t=await Cu(this.globals.suiClient,e),n=await Promise.all(t.map(o=>this.getCoinMeta(o.coinType)));return t.map((o,i)=>({...o,coinType:(0,nn.normalizeStructTag)(o.coinType),coinMeta:n[i]}))}async getCoinMeta(e){return this.coinMetaHelper.getCoinMeta(e)}async simulateTransactionBlock(e){return la(this.globals.suiClient,{transaction: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()<Of)throw new X("Interval shall be at least 1 second","interval",e.interval)}},Is=class{constructor(e){this.suiClient=e;this.coinMetaReg=new Map}suiClient;coinMetaReg;async getCoinMeta(e){let t=(0,nn.normalizeStructTag)(e||nn.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??void 0}async queryCoinMeta(e){return xu(this.suiClient,e)}};var Ie=require("@mysten/sui/utils"),Ms=require("luxon");var Nn=require("@mysten/sui/transactions"),Wn=require("@mysten/sui/utils"),Nu=require("luxon");var ga=class extends j{constructor(){super(7,"Connected wallet is not creator")}};var En=class extends j{constructor(){super(8,"Connected wallet is not recipient")}};var Rt=class extends j{constructor(e,t={}){super(0,e,t)}};var ya=class extends j{constructor(e){super(5,"Stream not found",{context:{streamId:e}})}};var Ta=require("luxon"),Eu=(1n<<64n)-1n,ba=1e3;function Cs(a){let e;typeof a=="number"?e=a:typeof a=="bigint"?e=Number(a):e=a.toMillis();let t=Math.round(e/ba);return Ta.DateTime.fromMillis(t*ba)}function xs(a){let e;typeof a=="number"?e=a:typeof a=="bigint"?e=Number(a):e=a.toMillis();let t=Math.round(e/ba);return Ta.Duration.fromMillis(t*ba)}var we=class a{constructor(e,t,n){this.globals=e;this.streamId=t;this.rawData=n;this.streamContract=new te(e.envConfig.contract,e)}globals;streamId;rawData;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 Rt("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 ga;let e=new Nn.Transaction;return this.streamContract.cancelStream(e,{streamId:this.streamId,coinType:this.coinType}),e}async claim(){if(await this.globals.walletAddress()!==this.recipient)throw new En;let e=new Nn.Transaction;return this.streamContract.claimStream(e,{streamId:this.streamId,coinType:this.coinType}),e}async setAutoClaim(e){if(await this.globals.walletAddress()!==this.recipient)throw new En;let t=new Nn.Transaction;return this.streamContract.setAutoClaim(t,{streamId:this.streamId,coinType:this.coinType,enabled:e}),t}async claimByProxy(){let e=new Nn.Transaction;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,Wn.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 xs(this.rawData.config.epochInterval)}get groupId(){let{metadata:e}=this.rawData.config;return On(e).groupId}get name(){let{metadata:e}=this.rawData.config;return On(e).name}get recipient(){return this.rawData.config.recipient}get timeStart(){return Cs(this.rawData.config.timeStart)}get duration(){let e=this.rawData.config,t=e.epochInterval*e.totalEpoch;return xs(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:Cs((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===Eu?0n:this.rawData.status.epochClaimed*this.amountPerEpoch+this.cliff}get currentEpoch(){let e=Nu.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 Su(e.suiClient,t);return a.parseRawStreamData(t,n)}static parseRawStreamData(e,t){if(t.error)throw t.error.code==="notExists"?new ya(e):new Zt(`get stream data: ${t.error.code}`,{streamId:e,...t.error});let n=t.data?.content;if(!n||n.dataType!=="moveObject")throw new Zt("Unexpected object type",{gotType:n?.dataType});let{typeParams:o}=(0,Wn.parseStructTag)(n.type),i=(0,Wn.normalizeStructTag)(o[0]),s=n.fields,c=ca(s.config),m=ca(s.status);return{coinType:i,autoClaim:s.auto_claim,balance:gu(s.balance),config:{amountPerEpoch:BigInt(String(c.amount_per_epoch)),cancelable:c.cancelable,cliff:BigInt(String(c.cliff)),creator:String(c.creator),epochInterval:BigInt(String(c.epoch_interval)),metadata:String(c.metadata),recipient:String(c.recipient),timeStart:BigInt(String(c.time_start)),totalEpoch:BigInt(String(c.total_epoch))},status:{status:m.status,epochCanceled:BigInt(String(m.epoch_canceled)),epochClaimed:BigInt(String(m.epoch_claimed))}}}};var on=class extends j{constructor(e,t){super(9,`Invalid stream group: ${e}`,{context:t})}};async function ks(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 Ds=class{constructor(e){this.requester=e;this.curPage=void 0,this.init=!0}requester;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)}},an=class{constructor(e){this.requester=e;this.pager=new Ds(e),this.curData=[],this.cursor=0}requester;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 Pf=25;async function As(a,e,t){let n=new _n(e),o=new Ln(a,n,t);return await ks(o)}var _n=class{constructor(e){this.ids=e;this.cursor=-1}ids;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]}},Ln=class extends an{constructor(t,n,o){super(new vs(t,n,o));this.suiClient=t;this.idIter=n;this.options=o}suiClient;idIter;options},vs=class{constructor(e,t,n){this.suiClient=e;this.stringIter=t;this.options=n;this.filter=n?.filter,this.pageSize=n?.pageSize||Pf,this.objectOptions=n?.objectOptions||{showType:!0,showContent:!0}}suiClient;stringIter;options;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 wu(this.suiClient,e),n;if(this.filter){let{filter:o}=this;n=t.filter(i=>!!i&&o(i))}else n=t.filter(o=>!!o);return{data:n,hasNext:await this.stringIter.hasNext()}}};var Sa=class a{constructor(e,t){this.globals=e;this.streams=t;if(t.length===0)throw new on("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")}globals;streams;type="StreamGroup";static async new(e,t){let n=await As(e.suiClient,t);return n.forEach(o=>{if(!o)throw new Rt("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=>{Rf(n,i)||(o=!1)}),o}async refresh(){let e=await As(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)=>we.fromObjectData(e,t[s],i)).filter(i=>!!i);if(new Set(o.map(i=>i.groupId)).size!==1)throw new on("Not same group ID");if(!this.checkStreamGroup(o))throw new on("Not same stream settings");return o}};function Rf(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 jn=class a{constructor(e,t){this.it=e;this.pageSize=t}it;pageSize;static async newIncoming(e){let t=await wa.newIncoming(e);return new a(t,e.pageSize)}static async newOutgoing(e){let t=await wa.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}},wa=class a{constructor(e){this.requester=e}requester;cachedNext;static async newIncoming(e){let t=await Ia.newIncomingQuery(e);return new a(t)}static async newOutgoing(e){let t=await Ia.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 Rt("No more results");return t}let e=this.cachedNext;if(this.cachedNext=void 0,e===null)throw new Rt("No more results");return e}},Ia=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 _n(n.flat().map(s=>s.streamId));this.objectIter=new Ln(e.suiClient,i)}globals;recipient;groupRefs;query;current=0;objectIter;static async newIncomingQuery(e){let t=_f(e.query),n=await e.globals.walletAddress(),i=(await e.globals.backend.getIncomingStreams(n,t)).filter(c=>(0,Ie.normalizeSuiAddress)(c.recipient)===(0,Ie.normalizeSuiAddress)(n)),s=Wu(i);return new a(e.globals,n,s,e.query)}static async newOutgoingQuery(e){let t=Lf(e.query),n=await e.globals.walletAddress(),o=await e.globals.backend.getOutgoingStreams(n,t),i=Wu(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 Nf(this.globals,e[0].streamId,this.objectIter);return this.current++,_u(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++,Ef(t,this.query)?t:this.doNextRequest()}throw new Rt("Stream group with no stream")}};function Wu(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)=>Ms.DateTime.fromISO(n[0].createDate).toMillis()-Ms.DateTime.fromISO(t[0].createDate).toMillis())}function _u(a,e){if(e===void 0)return!0;let t=Bf(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 Bf(a,e){return e===void 0?!0:Array.isArray(e)?e.includes(a.progress.status):a.progress.status===e}function Ef(a,e){if(!e)return!0;let t=!1;return a.streams.forEach(n=>{_u(n,e)&&(t=!0)}),t}async function Nf(a,e,t){let n=await Lu(t,e);return we.fromObjectData(a,e,n)}async function Wf(a,e,t){let n=[];for(;n.length<e.length;){let o=await Lu(t,e[n.length]);n.push(o)}return Sa.newFromObjectResponse(a,e,n)}async function Lu(a,e){if(!await a.hasNext())throw new Rt("object iterator has been consumed");let t=await a.next();if(!t||t.error||t.data===void 0||t.data===null)throw new Rt("object iterator undefined response",{cause:t?.error});if(t?.data?.objectId!==e)throw new Rt("stream id not aligned");return t}function _f(a){return{status:Os(a?.status),coinType:ju(a?.coinType),sender:Uu(a?.sender)}}function Lf(a){return{status:Os(a?.status),coinType:ju(a?.coinType),recipient:Uu(a?.recipient)}}function Os(a){return a===void 0||a.length===0?"all":Array.isArray(a)?a.reduce((e,t)=>{let n=Os(t);return!e||e===n?n:"all"},void 0):jf(a)}function jf(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 ju(a){if(a)return Array.isArray(a)?a.length!==0?a.map(e=>(0,Ie.normalizeStructTag)(e)):void 0:(0,Ie.normalizeStructTag)(a)}function Uu(a){if(a)return Array.isArray(a)?a.length!==0?a.map(e=>(0,Ie.normalizeSuiAddress)(e)):void 0:(0,Ie.normalizeSuiAddress)(a)}var Ca=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}coinType;requestAmount;gotAmount};var Uf=25;async function qu(a,e,t,n="0x2::sui::SUI",o=Uf){let i=new Ps(a,e,n,o),s=BigInt(0),c=[];for(;await i.hasNext()&&s<t;){let m=await i.next();m&&(c.push(m),s+=BigInt(m.balance))}if(s<t)throw new Ca(n,t,s);return c}var Ps=class extends an{constructor(t,n,o,i){super(new Rs(t,n,o,i));this.suiClient=t;this.owner=n;this.coinType=o;this.reqPageSize=i}suiClient;owner;coinType;reqPageSize},Rs=class{constructor(e,t,n,o){this.suiClient=e;this.owner=t;this.coinType=n;this.reqPageSize=o;if(o<=0)throw new Rt("Invalid reqPageSize")}suiClient;owner;coinType;reqPageSize;nextCursor;async doNextRequest(){let e=await bu(this.suiClient,{owner:this.owner,coinType:this.coinType,cursor:this.nextCursor,limit:this.reqPageSize});return this.nextCursor=e.nextCursor,{data:e.data,hasNext:e.hasNextPage}}};var Bs=class{constructor(e){this.msafe=e}msafe;get type(){return"msafe"}async address(){return this.msafe.address()}async requestCoins(e){return this.msafe.requestCoins(e)}},xa=class{constructor(e){this.account=e}account;async address(){return this.account.address}},Es=class{constructor(e,t){this.singleWallet=e;this.suiClient=t}singleWallet;suiClient;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(ma(e.coinType,Ne.SUI_TYPE_ARG))return{primaryCoin:da};if(e.amount<=0)throw new X("Invalid coin request","coinAmount",e.amount);let t=await qu(this.suiClient,await this.address(),e.amount,e.coinType);if(t.length===0)throw new Rt("no coins available");return{primaryCoin:t[0].coinObjectId,mergedCoins:t.slice(1).map(n=>n.coinObjectId)}}},Da=class{globals;helper;constructor(e,t){this.globals=Ye.new(e,t),this.helper=new ha(this.globals)}connectSingleWallet(e){let t=new Es(e,this.globals.suiClient);this.globals.connectWallet(t)}connectMSafeAccount(e){let t=new Bs(e);this.globals.connectWallet(t)}async createStream(e){return this.builder().createStreams(e)}async getStream(e){return we.new(this.globals,e)}async getIncomingStreams(e,t=10){return jn.newIncoming({globals:this.globals,query:e,pageSize:t})}async getOutgoingStreams(e,t=10){return jn.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,Ne.normalizeStructTag)(n))}async getRecipientsForStreamFilter(e){let t=await this.wallet.address();return(await this.globals.backend.getAllRecipients(t,e)).map(o=>(0,Ne.normalizeSuiAddress)(o))}async getCreatorsForStreamFilter(e){let t=await this.wallet.address();return(await this.globals.backend.getAllSenders(t,e)).map(o=>(0,Ne.normalizeSuiAddress)(o))}get wallet(){return this.globals.wallet}builder(){return new en(this.globals)}};var $t=class extends ge{application="mpay";getClient(e,t,n){let o=new Da(e==="sui:mainnet"?"prod":"dev",{suiGrpcClient:n});return o.connectSingleWallet(new xa(t)),o}};var Un=class extends $t{constructor(t){super(t);this.data=t}data;txType=Fu.TransactionType.Stream;txSubType="Cancel";async build(t){let{network:n,account:o,suiGrpcClient:i}=t;return(await this.getClient(n,o,i).getStream(this.data.streamId)).cancel()}};var Ku=require("@msafe/sui3-utils");var qn=class extends $t{constructor(t){super(t);this.data=t}data;txType=Ku.TransactionType.Stream;txSubType="ClaimByProxy";async build(t){let{network:n,account:o,suiGrpcClient:i}=t;return(await this.getClient(n,o,i).getStream(this.data.streamId)).claimByProxy()}};var Vu=require("@msafe/sui3-utils");var Fn=class extends $t{constructor(t){super(t);this.data=t}data;txType=Vu.TransactionType.Stream;txSubType="Claim";async build(t){let{network:n,account:o,suiGrpcClient:i}=t;return(await this.getClient(n,o,i).getStream(this.data.streamId)).claim()}};var $u=require("@msafe/sui3-utils");var Kn=class extends $t{constructor(t){super(t);this.data=t}data;txType=$u.TransactionType.Stream;txSubType="CreateStream";async build(t){let{network:n,account:o,suiGrpcClient:i}=t;return this.getClient(n,o,i).createStream(this.data)}};var _e=require("@mysten/sui/bcs"),Gu=require("@mysten/bcs"),rn=require("@mysten/sui/utils");function Vn(a){if(!a.Pure)throw new Error("not pure argument");return(0,Gu.fromBase64)(a.Pure.bytes)}var sn=class a{constructor(e,t){this.moveCall=e;this.txb=t}moveCall;txb;get moveCallData(){if(this.moveCall.$kind!=="MoveCall")throw new Error("not move call command");return this.moveCall.MoveCall}get inputs(){return this.txb.getData().inputs}getInputIndex(e){let t=this.moveCallData.arguments[e];if(t.$kind!=="Input")throw new Error("not input type");return t.Input}getInputParam(e){return this.inputs[this.getInputIndex(e)]}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.getInputParam(e);return BigInt(_e.bcs.U64.parse(Vn(t)))}decodeInputAddress(e){let t=this.getInputParam(e);return(0,rn.normalizeSuiAddress)(_e.bcs.Address.parse(Vn(t)))}decodeInputString(e){let t=this.getInputParam(e);return _e.bcs.String.parse(Vn(t))}decodeInputBool(e){let t=this.getInputParam(e);return _e.bcs.Bool.parse(Vn(t))}decodePureArg(e,t){let n=this.getInputParam(e);return a.getPureInputValue(n,t)}static getPureInputValue(e,t){return a.getPureInput(e,t)}static getOwnedObjectId(e){let t=e.Object?.ImmOrOwnedObject?.objectId??e.Object?.Receiving?.objectId??e.UnresolvedObject?.objectId;if(!t)throw new Error(`not object argument: ${JSON.stringify(e)}`);return(0,rn.normalizeSuiAddress)(t)}static getSharedObjectId(e){let t=e.Object?.SharedObject?.objectId??e.UnresolvedObject?.objectId;if(!t)throw new Error(`not shared object argument: ${JSON.stringify(e)}`);return(0,rn.normalizeSuiAddress)(t)}static getPureInput(e,t){return(0,_e.pureBcsSchemaFromTypeName)(t).parse(Vn(e))}typeArg(e){return(0,rn.normalizeStructTag)(this.moveCallData.typeArguments[e])}txArg(e){return this.moveCallData.arguments[e]}};var ka=class{constructor(e,t){this.globals=e;this.txb=t}globals;txb;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.commands.filter(t=>t.$kind==="MoveCall"&&Te(Se(t),this.contract.createStreamTarget));if(e.length===0)throw new Rt("No create stream transactions");return e.map(t=>new sn(t,this.txb))}getCreationInfoFromMoveCall(e){let t=e.decodeInputString(4),{name:n,groupId:o}=On(t),i=e.decodeInputAddress(5),s=e.decodeInputU64(6),c=e.decodeInputU64(7),m=e.decodeInputU64(8),b=e.decodeInputU64(9),S=e.decodeInputU64(10),I=e.decodeInputBool(11),x=e.typeArg(0);return{name:n,groupId:o,recipient:i,timeStart:s,cliff:c,epochInterval:m,totalEpoch:b,amountPerEpoch:S,cancelable:I,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 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}}get commands(){return this.txb.getData().commands}get contract(){return new te(this.globals.envConfig.contract,this.globals)}get feeContract(){return new tn(this.globals.envConfig.contract,this.globals)}createStreamHelper(){return new Ee(this.globals,this.feeContract,this.contract)}};var va=class{constructor(e,t){this.globals=e;this.txb=t;this.contract=new te(e.envConfig.contract,e)}globals;txb;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 commands(){return this.txb.getData().commands}isCreateStreamTransaction(){return this.commands.findIndex(t=>t.$kind==="MoveCall"&&Te(Se(t),this.contract.createStreamTarget))!==-1}isSetAutoClaimTransaction(){return this.commands.length===1&&this.commands[0].$kind==="MoveCall"&&Te(Se(this.commands[0]),this.contract.setAutoClaimTarget)}isCancelStreamTransaction(){return this.commands.length===1&&this.commands[0].$kind==="MoveCall"&&Te(Se(this.commands[0]),this.contract.cancelStreamTarget)}isClaimStreamTransaction(){return this.commands.length===1&&this.commands[0].$kind==="MoveCall"&&Te(Se(this.commands[0]),this.contract.claimStreamTarget)}isClaimByProxyTransaction(){return this.commands.length===1&&this.commands[0].$kind==="MoveCall"&&Te(Se(this.commands[0]),this.contract.claimStreamByProxyTarget)}decodeCreateStreamTransaction(){return new ka(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.commands[0];if(e.$kind!=="MoveCall")throw new Error("MoveCall not found");return new sn(e,this.txb)}};var Hu=require("@msafe/sui3-utils");var $n=class extends $t{constructor(t){super(t);this.data=t}data;txType=Hu.TransactionType.Stream;txSubType="SetAutoClaim";async build(t){let{network:n,account:o,suiGrpcClient:i}=t;return(await this.getClient(n,o,i).getStream(this.data.streamId)).setAutoClaim(this.data.enabled)}};var Aa=class{application="mpay";supportSDK="@mysten/sui-v2";async deserialize(e){let{network:t,transaction:n,suiGrpcClient:o}=e,i=Ye.new(t==="sui:mainnet"?"prod":"dev",{suiGrpcClient:o}),c=new va(i,n).decode(),m;switch(c.type){case"CreateStream":m=new Kn(c.info);break;case"SetAutoClaim":m=new $n({streamId:c.streamId,enabled:c.enabled});break;case"Claim":m=new Fn({streamId:c.streamId});break;case"ClaimByProxy":m=new qn({streamId:c.streamId});break;case"Cancel":m=new Un({streamId:c.streamId});break;default:throw new Error(`Unknown transaction type: ${c}`)}return{txType:m.txType,txSubType:m.txSubType,intentionData:m.data}}async build(e){let{intentionData:t}=e,n;switch(e.txSubType){case"CreateStream":n=new Kn(t);break;case"Claim":n=new Fn(t);break;case"ClaimByProxy":n=new qn(t);break;case"SetAutoClaim":n=new $n(t);break;case"Cancel":n=new Un(t);break;default:throw new Error("not implemented")}return n.build({...e})}};var Gn=require("@msafe/sui3-utils");var Xu=require("@msafe/sui3-utils");var Ma=class a extends ge{constructor(t){super(t);this.data=t}data;txType;txSubType;async build(t){let{suiGrpcClient:n,account:o}=t;return(0,Xu.buildCoinTransferTxb)(n,this.data,o.address)}static fromData(t){return new a(t)}};var zu=require("@msafe/sui3-utils");var Oa=class a extends ge{constructor(t){super(t);this.data=t}data;txType;txSubType;async build(t){let{suiGrpcClient:n,account:o}=t;return(0,zu.buildObjectTransferTxb)(n,this.data,o.address)}static fromData(t){return new a(t)}};var Pa=class{application="msafe-core";supportSDK="@mysten/sui-v2";constructor(){this.application=Gn.TransactionDefaultApplication}deserialize(){throw new Error("MSafe core transaction intention should be build from API")}async build(e){let{account:t,network:n,suiGrpcClient:o}=e,i;switch(e.txSubType){case Gn.TransactionSubTypes.assets.coin.send:i=Ma.fromData(e.intentionData);break;case Gn.TransactionSubTypes.assets.object.send:i=Oa.fromData(e.intentionData);break;default:throw new Error("not implemented")}return i.build({suiGrpcClient:o,account:t,network:n})}};var Ls=require("@msafe/sui3-utils");var Qu=!1,Hn={ProtocolPackage:"0x1e4a13a0494d5facdbe8473e74127b838c2d446ecec0ce262e2eddafa77259cb",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 Ns(){if(!Qu)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&&(Hn.ProtocolPackage=e),t&&(Hn.borrowFee=t),n&&(Hn.borrowFeeAddress=n),o&&(Hn.pool=o),Qu=!0}catch(a){console.error(a.message)}}var ee=Hn;var Ce=require("@msafe/sui3-utils"),Gt=require("@mysten/bcs"),cn=require("@mysten/sui/utils");function Ra(a){if(a.$kind!=="MoveCall")return null;let{package:e,module:t,function:n}=a.MoveCall;return`${e}::${t}::${n}`}var Ba=class{constructor(e){this.txb=e}txb;decode(){if(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 commands(){return this.txb.getData().commands}getMoveCallCommand(e){return this.commands.find(t=>Ra(t)===e)}isClaimRewardTransaction(){return this.commands.some(e=>e.$kind==="MoveCall"&&e.MoveCall.function.includes("claim_reward"))}isEntryBorrowTransaction(){return!!this.getMoveCallCommand(`${ee.ProtocolPackage}::incentive_v3::entry_borrow_v2`)}isEntryBorrowWithFeeTransaction(){return!!this.getMoveCallCommand(`${ee.ProtocolPackage}::incentive_v3::borrow_v2`)}isEntryMultiDepositTransaction(){let e=`${ee.ProtocolPackage}::incentive_v3::entry_deposit`,t=this.commands.filter(o=>Ra(o)===e);return this.commands.find(o=>o.$kind==="MoveCall"&&o.MoveCall.function.includes("claim_reward"))?!1:t.length>1}isEntryClaimAndDepositTransaction(){let e=`${ee.ProtocolPackage}::incentive_v3::entry_deposit`,t=this.commands.filter(o=>Ra(o)===e);return!!(this.commands.find(o=>o.$kind==="MoveCall"&&o.MoveCall.function.includes("claim_reward"))&&t.length>0)}isEntryDepositTransaction(){return!!this.getMoveCallCommand(`${ee.ProtocolPackage}::incentive_v3::entry_deposit`)}isEntryRepayTransaction(){return!!this.getMoveCallCommand(`${ee.ProtocolPackage}::incentive_v3::entry_repay`)}isEntryWithdrawTransaction(){return!!this.getMoveCallCommand(`${ee.ProtocolPackage}::incentive_v3::withdraw_v2`)}decodeEntryClaimAndDeposit(){return{txType:Ce.TransactionType.Other,type:"EntryClaimAndDeposit",intentionData:{type:"entry_claim_and_deposit"}}}decodeClaimReward(){return{txType:Ce.TransactionType.Other,type:"ClaimReward",intentionData:{type:"claim_reward"}}}decodeEntryBorrow(){let e=this.helper.decodeInputU8(4),t=this.helper.decodeInputU64(5);return{txType:Ce.TransactionType.Other,type:"EntryBorrow",intentionData:{amount:t,assetId:e}}}decodeEntryMultiDeposit(){let e=[],t=`${ee.ProtocolPackage}::incentive_v3::entry_deposit`;return this.commands.forEach(n=>{if(Ra(n)===t){let o=new Ea(n,this.txb),i=o.decodeInputU8(3),s=o.decodeInputU64(5);e.push({assetId:i,amount:s})}}),{txType:Ce.TransactionType.Other,type:"EntryMultiDeposit",intentionData:{list:e}}}decodeEntryDeposit(){let e=this.helper.decodeInputU8(3),t=this.helper.decodeInputU64(5);return{txType:Ce.TransactionType.Other,type:"EntryDeposit",intentionData:{amount:t,assetId:e}}}decodeEntryRepay(){let e=this.helper.decodeInputU8(4),t=this.helper.decodeInputU64(6);return{txType:Ce.TransactionType.Other,type:"EntryRepay",intentionData:{amount:t,assetId:e}}}decodeEntryWithdraw(){let e=this.helper.decodeInputU8(4),t=this.helper.decodeInputU64(5);return{txType:Ce.TransactionType.Other,type:"EntryWithdraw",intentionData:{amount:t,assetId:e}}}get helper(){let e=this.commands.find(t=>t.$kind==="MoveCall"&&t.MoveCall.package===ee.ProtocolPackage);if(!e)throw new Error("MoveCall not found");return new Ea(e,this.txb)}},Ea=class a{constructor(e,t){this.moveCall=e;this.txb=t}moveCall;txb;get moveCallData(){if(this.moveCall.$kind!=="MoveCall")throw new Error("not move call command");return this.moveCall.MoveCall}get inputs(){return this.txb.getData().inputs}getInputIndex(e){let t=this.moveCallData.arguments[e];if(t.$kind!=="Input")throw new Error("not input type");return t.Input}getInputParam(e){return this.inputs[this.getInputIndex(e)]}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.getInputParam(e);return Number(Gt.bcs.u64().parse(Uint8Array.from((0,Gt.fromBase64)(t.Pure.bytes))))}decodeInputU8(e){let t=this.getInputParam(e);return Number(Gt.bcs.u8().parse(Uint8Array.from((0,Gt.fromBase64)(t.Pure.bytes))))}decodeInputAddress(e){let t=this.getInputParam(e);return(0,cn.normalizeSuiAddress)(Gt.bcs.Address.parse(Uint8Array.from((0,Gt.fromBase64)(t.Pure.bytes))))}decodeInputString(e){let t=this.getInputParam(e);return Gt.bcs.string().parse(Uint8Array.from((0,Gt.fromBase64)(t.Pure.bytes)))}decodeInputBool(e){let t=this.getInputParam(e);return Gt.bcs.bool().parse(Uint8Array.from((0,Gt.fromBase64)(t.Pure.bytes)))}static getOwnedObjectId(e){let t=e.Object?.ImmOrOwnedObject?.objectId??e.Object?.Receiving?.objectId??e.UnresolvedObject?.objectId;if(!t)throw new Error(`not object argument: ${JSON.stringify(e)}`);return(0,cn.normalizeSuiAddress)(t)}static getSharedObjectId(e){let t=e.Object?.SharedObject?.objectId??e.UnresolvedObject?.objectId;if(!t)throw new Error(`not shared object argument: ${JSON.stringify(e)}`);return(0,cn.normalizeSuiAddress)(t)}typeArg(e){return(0,cn.normalizeStructTag)(this.moveCallData.typeArguments[e])}txArg(e){return this.moveCallData.arguments[e]}};var Ws=require("@mysten/sui/transactions"),qt=require("@naviprotocol/lending");async function ln(a,e,t,n){return await(0,qt.depositCoinPTB)(a,e,t,{amount:n}),a}async function Ju(a,e,t,n){let[o]=await(0,qt.withdrawCoinPTB)(a,e,t);return a.transferObjects([o],a.pure.address(n)),a}async function Yu(a,e,t,n){let[o]=await(0,qt.borrowCoinPTB)(a,e,t);return a.transferObjects([o],a.pure.address(n)),a}async function _s(a,e,t,n){return await(0,qt.repayCoinPTB)(a,e,t,{amount:n}),a}async function Zu(a,e){let t=new Ws.Transaction,n=await(0,qt.getUserAvailableLendingRewards)(e,{client:a});return await(0,qt.claimLendingRewardsPTB)(t,n),t}async function tp(a,e){let t=new Ws.Transaction,n=await(0,qt.getUserAvailableLendingRewards)(e,{client:a});return await(0,qt.claimLendingRewardsPTB)(t,n,{customCoinReceive:{type:"depositNAVI",depositNAVI:{fallbackReceiveAddress:e}}}),t}var Na=class a extends w{constructor(t){super(t);this.data=t}data;txType;txSubType;async build(t){let{type:n}=this.data;return console.log("claim reward",n),await Zu(t.suiClient,t.account.address)}static fromData(t){return new a(t)}};var Wa=class a extends w{constructor(t){super(t);this.data=t}data;txType;txSubType;async build(t){let{type:n}=this.data;return console.log("claim reward and supply",n),await tp(t.suiClient,t.account.address)}static fromData(t){return new a(t)}};var np=require("@mysten/sui/transactions");var ep=require("@naviprotocol/lending");async function ne(a){return(0,ep.getPool)(a)}var _a=class a extends w{constructor(t){super(t);this.data=t}data;txType;txSubType;async build(t){let{assetId:n,amount:o}=this.data,i=new np.Transaction;console.log("build",this.data);let s=await ne(n);return await Yu(i,s,o,t.account.address)}static fromData(t){return new a(t)}};var op=require("@mysten/sui/transactions");async function un(a,e,t){let n=await a.getCoins({owner:e,coinType:t});return console.log("getTokenObjs",e,n),n}var La=class a extends w{constructor(t){super(t);this.data=t}data;txType;txSubType;async build(t){let{suiClient:n,account:o}=t,{assetId:i,amount:s}=this.data,c=new op.Transaction;console.log("build",this.data);let m=await ne(i);if(i===0){let[x]=c.splitCoins(c.gas,[s]);return await ln(c,m,x,s)}let b=await un(n,o.address,m.suiCoinType);if(!b.data[0])throw new Error(`Insufficient balance for ${m.suiCoinType} Token`);let S=b.data[0].coinObjectId;if(b.data.length>=2){let x=1;for(;x<b.data.length;)c.mergeCoins(S,[b.data[x].coinObjectId]),x++}return await ln(c,m,c.object(S),s)}static fromData(t){return new a(t)}};var ap=require("@mysten/sui/transactions");var ja=class a extends w{constructor(t){super(t);this.data=t}data;txType;txSubType;async build(t){let{suiClient:n,account:o}=t,{assetId:i,amount:s}=this.data,c=new ap.Transaction;console.log("build",this.data);let m=await ne(i);if(i===0){let[I]=c.splitCoins(c.gas,[s]);return _s(c,m,I,s)}let b=await un(n,o.address,m.suiCoinType);if(!b.data[0])throw new Error(`Insufficient balance for ${m.suiCoinType} Token`);let S=b.data[0].coinObjectId;if(b.data.length>=2){let I=1;for(;I<b.data.length;)c.mergeCoins(S,[b.data[I].coinObjectId]),I++}return _s(c,m,c.object(S),s)}static fromData(t){return new a(t)}};var ip=require("@mysten/sui/transactions");var Ua=class a extends w{constructor(t){super(t);this.data=t}data;txType;txSubType;async build(t){let{assetId:n,amount:o}=this.data,i=new ip.Transaction;console.log("build",this.data);let s=await ne(n);return await Ju(i,s,o,t.account.address)}static fromData(t){return new a(t)}};var rp=require("@mysten/sui/transactions");var qa=class a extends w{constructor(t){super(t);this.data=t}data;txType;txSubType;async build(t){let{suiClient:n,account:o}=t,{list:i}=this.data,s=new rp.Transaction;console.log("build",this.data);for(let c=0;c<i.length;c++){let{assetId:m,amount:b}=i[c],S=await ne(m);if(m===0){let[D]=s.splitCoins(s.gas,[b]);await ln(s,S,D,b);continue}let I=await un(n,o.address,S.suiCoinType);if(!I.data[0])throw new Error(`Insufficient balance for ${S.suiCoinType} Token`);let x=I.data[0].coinObjectId;if(I.data.length>=2){let D=1;for(;D<I.data.length;)s.mergeCoins(x,[I.data[D].coinObjectId]),D++}await ln(s,S,s.object(x),b)}return s}static fromData(t){return new a(t)}};var sp=require("@mysten/sui/transactions");var Fa=class a extends w{constructor(t){super(t);this.data=t}data;txType;txSubType;async build(t){return console.log("build",this.data),sp.Transaction.from(this.data.content)}static fromData(t){return new a(t)}};var Ka=class{application="navi";supportSDK="@mysten/sui";async deserialize(e){if(await Ns(),e.appContext?.content)return{txType:Ls.TransactionType.Other,txSubType:"PlainTransaction",intentionData:{content:e.appContext.content,scene:e.appContext.scene||"unknown"}};let{transaction:t}=e,o=new Ba(t).decode();return{txType:Ls.TransactionType.Other,txSubType:o.type,intentionData:o.intentionData}}async build(e){let{suiClient:t,account:n}=e,o;switch(await Ns(),e.txSubType){case"EntryDeposit":o=La.fromData(e.intentionData);break;case"EntryBorrow":o=_a.fromData(e.intentionData);break;case"EntryRepay":o=ja.fromData(e.intentionData);break;case"EntryWithdraw":o=Ua.fromData(e.intentionData);break;case"EntryMultiDeposit":o=qa.fromData(e.intentionData);break;case"ClaimReward":o=Na.fromData(e.intentionData);break;case"EntryClaimAndDeposit":o=Wa.fromData(e.intentionData);break;case"PlainTransaction":o=Fa.fromData(e.intentionData);break;default:throw new Error("not implemented")}return o.build({suiClient:t,account:n})}};var Xn=require("@msafe/sui3-utils"),cp=require("@mysten/bcs"),lp=require("@mysten/sui/transactions"),up=Mt(require("sort-keys-recursive")),pp="msafe-plain-tx",mp=Xn.TransactionSubTypes.others.plain,js=class a{constructor(e){this.data=e}data;application=pp;txType=Xn.TransactionType.Other;txSubType=mp;serialize(){return JSON.stringify((0,up.default)(this.data))}async build(e){return lp.Transaction.from((0,cp.fromHex)(this.data.content))}static fromData(e){return new a(e)}},Va=class{application;supportSDK="@mysten/sui";constructor(){this.application=pp}async deserialize(e){let{content:t}=e.appContext;return{txType:Xn.TransactionType.Other,txSubType:mp,intentionData:{content:t}}}async build(e){let{suiClient:t,network:n,account:o}=e;return js.fromData(e.intentionData).build({suiClient:t,network:n,account:o})}};var Le=require("@mysten/sui/transactions"),dp=require("@mysten/sui.js/client");var mn=require("@open-rpc/client-js");var Ff={"-32700":"ParseError","-32600":"InvalidRequest","-32601":"MethodNotFound","-32602":"InvalidParams","-32603":"InternalError"},Us=class extends Error{},$a=class extends Us{code;type;constructor(e,t){super(e),this.code=t,this.type=Ff[t]??"ServerError"}};function Kf(a){let e=new URL(a);return e.protocol=e.protocol.replace("http","ws"),e.toString()}var Vf={WebSocketConstructor:typeof WebSocket<"u"?WebSocket:void 0,callTimeout:3e4,reconnectTimeout:3e3,maxReconnects:5},Ga=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={...Vf,...t},this.endpoint&&this.endpoint.startsWith("http")&&(this.endpoint=Kf(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 $a(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 qs(e);return this.#i.add(t),await t.subscribe(this),()=>t.unsubscribe(this)}},qs=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 pn=class{rpcClient;websocketClient;constructor({url:e,websocket:{url:t,...n}={},rpc:o}){let i=new mn.HTTPTransport(o?.url??e,{headers:{"Content-Type":"application/json",...o?.headers}});this.rpcClient=new mn.Client(new mn.RequestManager([i])),this.websocketClient=new Ga(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 $f="0x2::sui::SUI",Gs=1e8;function Fs(a){return new dp.SuiClient({transport:new pn({url:a,rpc:{url:a}})})}async function fp(a,e){if((0,Le.isTransaction)(a))return a;let t=Fs(e),n=await a.build({client:t});return Le.Transaction.from(n)}var Ha=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;case"@mysten/sui-v2":t.addGrpcHelper(o);break;default:{let i=o;throw new Error(`${i.application}: ${i.supportSDK} SDK not supported`)}}}return t}addLegacyHelper(e){this.setApp(e.application,new $s(e))}addHelper(e){this.setApp(e.application,new Ks(e))}addGrpcHelper(e){this.setApp(e.application,new Vs(e))}getAppHelper(e){let t=this.apps.get(e);if(!t)throw new Error(`${e} not registered`);return t}setApp(e,t){this.apps.set(e,t)}},Ks=class{constructor(e){this.helper=e}helper;async deserialize(e){let t=new H.SuiJsonRpcClient({network:kn(e.network),transport:new pn({url:e.clientUrl,rpc:{url:e.clientUrl}})}),n=await fp(e.transactionBlock,e.clientUrl);return this.helper.deserialize({...e,suiClient:t,transaction:n})}async build(e){let t=new H.SuiJsonRpcClient({network:kn(e.network),transport:new pn({url:e.clientUrl,rpc:{url:e.clientUrl}})}),n=await t.getBalance({owner:e.account.address});if(Number(n.totalBalance)<Gs)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 Le.Transaction.from(i)}},Vs=class{constructor(e){this.helper=e}helper;async deserialize(e){let t=An(e.network,e.clientUrl),n=await fp(e.transactionBlock,e.clientUrl);return this.helper.deserialize({...e,suiGrpcClient:t,transaction:n})}async build(e){let t=An(e.network,e.clientUrl),{balance:n}=await t.core.getBalance({owner:e.account.address,coinType:$f});if(Number(n.balance)<Gs)throw new Error("Insufficient gas fee");let o=await this.helper.build({...e,suiGrpcClient:t});o.setSender(e.account.address);let i=await o.build({client:t});return Le.Transaction.from(i)}},$s=class{constructor(e){this.helper=e}helper;async deserialize(e){let t=Fs(e.clientUrl);return this.helper.deserialize({...e,transactionBlock:e.transactionBlock,suiClient:t})}async build(e){let t=Fs(e.clientUrl),n=await t.getBalance({owner:e.account.address});if(Number(n.totalBalance)<Gs)throw new Error("Insufficient gas fee");let i=await(await this.helper.build({...e,suiClient:t})).build({client:t});return Le.Transaction.from(i)}};var xp=require("@msafe/sui3-utils"),Dp=require("@scallop-io/sui-scallop-sdk");var Bt=require("@msafe/sui3-utils"),zs=require("@scallop-io/sui-scallop-sdk");var hp=require("@mysten/sui/utils"),xe=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}`))}transaction;scallopClient;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,hp.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 Xa=require("@mysten/sui/bcs"),De=require("@mysten/sui/utils"),Hs=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}`,m=`${e.MoveCall.package}::${e.MoveCall.module}::${e.MoveCall.function}`;return c===m?(o.push(s),!0):!1}return!1}),this.cmdIdx=o[n]}moveCall;transaction;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,De.normalizeSuiAddress)(t)}decodeInputString(e){return this.decodePureArg(e,"String")}decodeInputBool(e){return this.decodePureArg(e,"Bool")}decodePureArg(e,t){let n=this.getInputParam(e);return a.getPureInputValue(n,t)}getInputParam(e){let t=this.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"&&t.kind!=="Result")throw new Error("not nested or result type");return this.transaction.blockData.transactions[t.index]}static getPureInputValue(e,t){if(e.type!=="pure")throw new Error("not pure argument");if(typeof e.value=="object"&&"Pure"in e.value){let n=e.value.Pure,o=Xa.bcs[t];return Xa.bcs[t].parse(new Uint8Array(n))}return e.value}static getOwnedObjectId(e){if(e.type!=="object")throw new Error(`not object argument: ${JSON.stringify(e)}`);if(typeof e.value=="object"){if(!("Object"in e.value)||!("ImmOrOwned"in e.value.Object))throw new Error("not ImmOrOwned");return(0,De.normalizeSuiAddress)(e.value.Object.ImmOrOwned.objectId)}return(0,De.normalizeSuiAddress)(e.value)}static getSharedObjectId(e){if(e.type!=="object")throw new Error(`not object argument: ${JSON.stringify(e)}`);if(typeof e.value!="object")return(0,De.normalizeSuiAddress)(e.value);if(!("Object"in e.value)||!("Shared"in e.value.Object))throw new Error("not Shared");return(0,De.normalizeSuiAddress)(e.value.Object.Shared.objectId)}static getPureInput(e){if(e.type!=="pure")throw new Error("not pure argument");if(typeof e.value!="object")return e.value;if(!("Pure"in e.value))throw new Error("Pure not in value");let t=e.value.Pure;return Xa.bcs.U64.parse(new Uint8Array(t))}typeArg(e){return(0,De.normalizeStructTag)(this.txBlockTransactions.typeArguments[e])}txArg(e){return this.transaction.blockData.inputs[e]}},N=Hs;var Xs=class{constructor(e,t){this.splitCoin=e;this.txb=t}splitCoin;txb;getAmountInput(){return this.splitCoin.amounts.map(e=>{if(e.kind==="Input")return Number(N.getPureInputValue(e,"U64"))}).filter(e=>e!==void 0)}},Lt=Xs;var ke=require("@mysten/sui/utils"),gp=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`},dn={id:"0xc63072e7f5f4983a2efaf5bdba1480d5e7d74d57948e1c7cc436f8e22cbeb410",incentivePools:"0x64972b713ccec45ec3964809e477cea6f97350c0c50ca3aec85bb631639266ec",incentiveAccounts:"0x3c0b707068bdcea8bb859d751ad3e2149a9f83c13fcf4054ef91372a00bccdd3"},Ht={unstakeObligation:(a,e,t)=>a.moveCall(`${dn.id}::user::unstake`,[dn.incentivePools,dn.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(`${dn.id}::user::redeem_rewards`,[dn.incentivePools,dn.incentiveAccounts,a.object(e),a.object(t),ke.SUI_CLOCK_OBJECT_ID],[(0,ke.normalizeStructTag)(n)])};var yp=(a,e)=>{let t=[];for(let n=0;n<a.length;n+=e)t.push(a.slice(n,n+e));return t};var za=class extends xe{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(`${zs.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,`${zs.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:Bt.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:Bt.TransactionType.Other,type:"MigrateAndClaim",intentionData:{obligationKey:t,obligationId:n,rewardCoinName:o,veScaKey:e}}}decodeOpenObligation(){return{txType:Bt.TransactionType.Other,type:"OpenObligation",intentionData:{}}}decodeSupplyLending(){let e=this.utils.parseCoinNameFromType(this.helperMint.typeArg(0)),t=this.helperMint.getNestedInputParam(2),n=new Lt(t,this.transaction).getAmountInput().reduce((o,i)=>o+i,0);return{txType:Bt.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 Lt(t,this.transaction).getAmountInput().reduce((o,i)=>o+i,0);return{txType:Bt.TransactionType.Other,type:"WithdrawLending",intentionData:{amount:n,coinName:e}}}decodeWithdrawLendingScoin(){let e=this.utils.parseCoinNameFromType(this.helperRedeem.typeArg(0)),t=this.helperBurnScoin.getNestedInputParam(1),n=new Lt(t,this.transaction).getAmountInput().reduce((o,i)=>o+i,0);return{txType:Bt.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 Lt(t,this.transaction).getAmountInput().reduce((i,s)=>i+s,0),o=this.helperDepositCollateral.decodeSharedObjectId(1);return{txType:Bt.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:Bt.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:Bt.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:Bt.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:Bt.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 Lt(t,this.transaction).getAmountInput().reduce((i,s)=>i+s,0),o=this.helperRepay.decodeSharedObjectId(1);return{txType:Bt.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 Lt(n,this.transaction).getAmountInput().reduce((s,c)=>s+c,0),i=this.helperRepay.decodeSharedObjectId(1);return{txType:Bt.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 Lt(i,this.transaction).getAmountInput().reduce((s,c)=>s+c,0)}if(this.helperStake.moveCall&&t===0){let i=this.helperStake.getNestedInputParam(2);t=new Lt(i,this.transaction).getAmountInput().reduce((s,c)=>s+c,0)}let n=this.helperStake.typeArg(0),o=this.utils.parseCoinNameFromType(n);return{txType:Bt.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:Bt.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 Lt(t,this.transaction).getAmountInput().reduce((i,s)=>i+s,0),o;return this.isCreateStakeAccountTransaction()||(o=this.helperStake.decodeOwnedObjectId(1)),{txType:Bt.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 Lt(o,this.transaction).getAmountInput().reduce((i,s)=>i+s,0)}return{txType:Bt.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:Bt.TransactionType.Other,type:"ClaimIncentiveReward",intentionData:{lendingIncentive:e,borrowIncentiveV2:t,borrowIncentive:n}}}};var Qa=require("@msafe/sui3-utils");var Ja=class extends xe{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:Qa.TransactionType.Other,type:"CreateReferralLink",intentionData:{}}}decodeClaimRevenueReferral(){let e=this.helperClaimRevenueReferral[0].decodeOwnedObjectId(2),t=this.helperClaimRevenueReferral.map(n=>n.typeArg(0));return{txType:Qa.TransactionType.Other,type:"ClaimRevenueReferral",intentionData:{veScaKey:e,coins:t}}}decodeBindReferral(){let e=this.helperBindReferral.decodePureArg(1,"Address");return{txType:Qa.TransactionType.Other,type:"BindReferral",intentionData:{veScaKey:e}}}};var oe=require("@msafe/sui3-utils"),bp=require("@scallop-io/sui-scallop-sdk");var Ya=class extends xe{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(m=>m.$kind==="TransferObjects");if(e.length!==1)return!1;let{objects:t}=e[0].TransferObjects,n=t.filter(m=>m.$kind==="Input").map(({Input:m})=>m);if(n.length!==t.length)return!1;let o=new Set(n),i=this.inputs.filter((m,b)=>m.$kind==="Object"&&o.has(b)).map(m=>m.Object.ImmOrOwnedObject),s=`${this.coreId.veScaObjId}::ve_sca::VeScaKey`,c=yp(i.map(({objectId:m})=>m),50);for(let m=0;m<c.length;m++){let b=c[m];if((await this.scallopClient.scallopSuiKit.queryGetObjects(b,{showType:!0})).some(I=>I.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,`${bp.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(m=>{this.filterMoveCallCommands(m,e)?(o.push({action:"unstake",helper:new N(m,this.transaction,i)}),i++):this.filterMoveCallCommands(m,t)?(o.push({action:"stake",helper:new N(m,this.transaction,s)}),s++):this.filterMoveCallCommands(m,n)&&(o.push({action:"deactivate",helper:new N(m,this.transaction,c)}),c++)}),o}decodeRedeemSca(){let e=this.helperRedeemSca.decodeOwnedObjectId(1);return{txType:oe.TransactionType.Other,type:"RedeemSca",intentionData:{veScaKey:e}}}decodeRenewExpiredVeSca(){let e=this.helperRenewExpired.getNestedInputParam(4),t=this.helperRenewExpired.decodeInputU64(5),n=new Lt(e,this.transaction).getAmountInput().reduce((k,M)=>k+M,0),o=this.helperRenewExpired.decodeOwnedObjectId(1),i=!!this.helperRedeemSca.moveCall,s=[],c=[],m=[];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&&(m=[this.helperStakeObligationWithVeSca.decodeOwnedObjectId(3),this.helperStakeObligationWithVeSca.decodeSharedObjectId(4)]);let b=!1,S=!1,I,x,D=[{condition:s,isOld:!0},{condition:c,isOld:!1},{condition:m,isOld:!1}];for(let k=0;k<D.length;k++)D[k].condition.length>1&&([x,I]=D[k].condition,b=!0,S=D[k].isOld);return{txType:oe.TransactionType.Other,type:"RenewExpStakePeriod",intentionData:{amount:n,unlockTime:t,obligationId:I,obligationKey:x,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,m,b,S=[{condition:n,isOld:!0},{condition:o,isOld:!1},{condition:i,isOld:!1}];for(let I=0;I<S.length;I++)S[I].condition.length>1&&([b,m]=S[I].condition,s=!0,c=S[I].isOld);return{txType:oe.TransactionType.Other,type:"ExtendStakePeriod",intentionData:{unlockTime:e,obligationId:m,obligationKey:b,veScaKey:t,isObligationLocked:s,isOldBorrowIncentive:c}}}decodePeriodAndStakeMoreSca(){let e=this.helperStakeMoreSca.getNestedInputParam(4),t=this.helperExtendStakePeriod.decodeInputU64(4),n=new Lt(e,this.transaction).getAmountInput().reduce((D,k)=>D+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 m=!1,b=!1,S,I,x=[{condition:o,isOld:!0},{condition:i,isOld:!1},{condition:c,isOld:!1}];for(let D=0;D<x.length;D++)x[D].condition.length>1&&([I,S]=x[D].condition,m=!0,b=x[D].isOld);return{txType:oe.TransactionType.Other,type:"ExtendPeriodAndStakeMore",intentionData:{amount:n,veScaKey:s,unlockTime:t,obligationId:S,obligationKey:I,isOldBorrowIncentive:b,isObligationLocked:m}}}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 Lt(e,this.transaction).getAmountInput().reduce((D,k)=>D+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 m=!1,b=!1,S,I,x=[{condition:o,isOld:!0},{condition:i,isOld:!1},{condition:c,isOld:!1}];for(let D=0;D<x.length;D++)x[D].condition.length>1&&([I,S]=x[D].condition,m=!0,b=x[D].isOld);return{txType:oe.TransactionType.Other,type:"StakeSca",intentionData:{amount:n,unlockTime:t,obligationId:S,obligationKey:I,veScaKey:s,isObligationLocked:m,isOldBorrowIncentive:b}}}decodeMergeVesca(){let e=this.getMergeSplitVeScaHelper("merge"),t={targetVeScaKey:e.decodeOwnedObjectId(1),sourceVeScaKey:e.decodeOwnedObjectId(2)};return{txType:oe.TransactionType.Other,type:"MergeVeSca",intentionData:t}}decodeSplitVesca(){let e=this.getMergeSplitVeScaHelper("split"),t={targetVeScaKey:e.decodeOwnedObjectId(1),splitAmount:e.decodeInputU64(4)};return{txType:oe.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:oe.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:oe.TransactionType.Other,type:"TransferVeScaKeys",intentionData:{veScaKeys:i}}}};var Tp=Mt(require("sort-keys-recursive")),A=class{constructor(e){this.data=e}data;get application(){return"msafe-core"}serialize(){return JSON.stringify((0,Tp.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 Za=class a extends A{constructor(t){super(t);this.data=t}data;txType;txSubType;async borrow({account:t,scallopClient:n}){let{coinName:o,amount:i,obligationId:s,obligationKey:c}=this.data,m=t.address;return(await this.buildTxWithRefreshObligation(n,{walletAddress:m,obligationId:s,obligationKey:c},async(S,I)=>{let x=await I.borrowQuick(+i,o,s,c);I.transferObjects([x],m)})).txBlock}async build(t){return this.borrow(t)}static fromData(t){return new a(t)}};var ti=class a extends A{constructor(t){super(t);this.data=t}data;txType;txSubType;async borrowWithBoost(t,n){let{obligationId:o,obligationKey:i,veScaKey:s,amount:c,coinName:m}=this.data;return(await this.buildTxWithRefreshObligation(t,{walletAddress:n,obligationId:o,obligationKey:i,veScaKey:s},async(S,I)=>{let x=await I.borrowQuick(+c,m,o,i);I.transferObjects([x],n)})).txBlock}async build(t){return this.borrowWithBoost(t.scallopClient,t.account.address)}static fromData(t){return new a(t)}};var ei=class a extends A{constructor(t){super(t);this.data=t}data;txType;txSubType;async borrowWithReferral({account:t,scallopClient:n}){let o=t.address,{obligationId:i,obligationKey:s,veScaKey:c,coinName:m,amount:b}=this.data;return(await this.buildTxWithRefreshObligation(n,{walletAddress:o,obligationId:i,obligationKey:s,veScaKey:c},async(I,x)=>{let D=x.claimReferralTicket(m),k=await x.borrowWithReferralQuick(+b,m,D,i,s);x.burnReferralTicket(D,m),x.transferObjects([k],o)})).txBlock}async build(t){return this.borrowWithReferral(t)}static fromData(t){return new a(t)}};var Sp=require("@mysten/sui/utils");var ni=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)??[]),m=(()=>{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 M=e.utils.parseMarketCoinName(k.coinName);return D[M]||(D[M]=0),D[M]+=k.availableClaimCoin,D},{})})(),b={};Object.entries(o).forEach(([x,D])=>{for(let k=0;k<D.length;k++){let M=D[k];if(!m[x])continue;let L=n.claim(M.id,x);b.sui?b.sui.push(L):b.sui=[L]}});let S=(()=>{let x={};return x.sui=Object.values(m).reduce((D,k)=>D+k,0),c.forEach(D=>{Object.values(D.borrowIncentives).forEach(k=>{k&&k.rewards.forEach(M=>{x[M.coinName]||(x[M.coinName]=0),x[M.coinName]?x[M.coinName]+=M.availableClaimCoin:x[M.coinName]=M.availableClaimCoin})})}),x})();if(s.length>0&&c.length>0)for(let x=0;x<c.length;x++){let D=c[x],k=!1,M=s.find(U=>U.id===D.obligationId)?.keyId,L={};if(M){if(Object.values(D.borrowIncentives).forEach(U=>{if(U){let q=U.rewards.filter(Pt=>{let W=Pt.coinName;return Pt.availableClaimCoin>0&&!L[W]});k=q.length>0,q.forEach(Pt=>{let W=n.claimBorrowIncentive(D.obligationId,M,Pt.coinName);L[Pt.coinName]=!0,b[Pt.coinName]?b[Pt.coinName].push(W):b[Pt.coinName]=[W]})}}),S.sui>0){let U=Ht.redeem_rewards(n,M,D.obligationId,Sp.SUI_TYPE_ARG);b.sui?b.sui.push(U):b.sui=[U]}if(k&&await gp(e.query,D.obligationId)){n.unstakeObligation(D.obligationId,M);let q=await e.query.getBindedVeScaKey(D.obligationId);q?n.stakeObligationWithVesca(D.obligationId,M,q):n.stakeObligation(D.obligationId,M)}}}let I=(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 I.length>0&&n.transferObjects(I,t),n.txBlock}async build(e){return this.claimIncentiveRewards(e.scallopClient,e.account.address)}static fromData(e={}){return new a(e)}};var oi=class a extends A{constructor(t){super(t);this.data=t}data;txType;txSubType;async build(t){return await t.scallopClient.depositCollateral(this.data.collateralCoinName,+this.data.amount,!1,this.data.obligationId)}static fromData(t){return new a(t)}};var ai=class a extends A{constructor(t){super(t);this.data=t}data;txType;txSubType;async migrateAndClaim({account:t,scallopClient:n}){let o=t.address,{obligationKey:i,obligationId:s,rewardCoinName:c,veScaKey:m}=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),m?await b.stakeObligationWithVeScaQuick(s,i,m):await b.stakeObligationQuick(s,i),b.txBlock}async build(t){return this.migrateAndClaim(t)}static fromData(t){return new a(t)}};var ii=class a extends A{constructor(t){super(t);this.data=t}data;txType;txSubType;async build(t){return await t.scallopClient.migrateAllMarketCoin(!1,!1)}static fromData(t){return new a(t)}};var ri=class a extends A{constructor(t){super(t);this.data=t}data;txType;txSubType;async build(t){return await t.scallopClient.openObligation(!1)}static fromData(t){return new a(t)}};var si=class a extends A{constructor(t){super(t);this.data=t}data;txType;txSubType;async repay({account:t,scallopClient:n}){let o=t.address,{coinName:i,amount:s,obligationId:c,obligationKey:m}=this.data;return(await this.buildTxWithRefreshObligation(n,{walletAddress:o,obligationId:c,obligationKey:m},async(S,I)=>{await I.repayQuick(+s,i,c)})).txBlock}async build(t){return this.repay(t)}static fromData(t){return new a(t)}};var ci=class a extends A{constructor(t){super(t);this.data=t}data;txType;txSubType;async repayWithBoost({account:t,scallopClient:n}){let o=t.address,{coinName:i,amount:s,obligationId:c,veScaKey:m}=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,m),b.txBlock}async build(t){return this.repayWithBoost(t)}static fromData(t){return new a(t)}};var li=class a extends A{constructor(t){super(t);this.data=t}data;txType;txSubType;async build(t){return await t.scallopClient.deposit(this.data.coinName,+this.data.amount,!1,t.account.address)}static fromData(t){return new a(t)}};var ui=class a extends A{constructor(t){super(t);this.data=t}data;txType;txSubType;async build(t){return await t.scallopClient.unstake(this.data.marketCoinName,+this.data.amount,!1)}static fromData(t){return new a(t)}};var pi=class a extends A{constructor(t){super(t);this.data=t}data;txType;txSubType;async unstakeAndWithdraw(t,n,o){let i=t.builder.createTxBlock();i.setSender(o);let{stakeAccountId:s,amount:c,coinName:m}=this.data,b=[];for(let S=0;S<s.length;S++){let{id:I,coin:x}=s[S],D=t.utils.parseMarketCoinName(m),[k]=await i.unstakeQuick(x,D,I,!1);if(k){let M=i.withdraw(k,m);b.push(M)}}if(c>0){let S=await i.withdrawQuick(c,m);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 mi=class a extends A{constructor(t){super(t);this.data=t}data;txType;txSubType;async build(t){return await 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 di=class a extends A{constructor(t){super(t);this.data=t}data;txType;txSubType;async build(t){return await t.scallopClient.withdraw(this.data.coinName,Number(this.data.amount),!1,t.account.address)}static fromData(t){return new a(t)}};var fi=class a extends A{constructor(t){super(t);this.data=t}data;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 hi=class a extends A{constructor(t){super(t);this.data=t}data;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 m=i.map(b=>n.utils.parseCoinNameFromType(b));return await c.claimReferralRevenueQuick(o,m),c.txBlock}async build(t){return this.claimRevenueReferral(t)}static fromData(t){return new a(t)}};var gi=class a extends A{constructor(t){super(t);this.data=t}data;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 wp=require("@scallop-io/sui-scallop-sdk");var yi=class a extends A{constructor(t){super(t);this.data=t}data;txType;txSubType;async extendPeriodAndStakeMoreSca({account:t,scallopClient:n}){let{amount:o,veScaKey:i,unlockTime:s,obligationId:c,obligationKey:m,isOldBorrowIncentive:b,isObligationLocked:S}=this.data,I=t.address,x=n.builder.createTxBlock();x.setSender(I);let D=await n.utils.selectCoins(o,wp.SCA_COIN_TYPE,I),[k,M]=x.takeAmountFromCoins(D,o);return x.extendLockPeriod(i,s),x.extendLockAmount(i,k),x.transferObjects([M],I),!c||!m||(S&&(b?Ht.unstakeObligation(x,c,m):x.unstakeObligation(c,m)),x.stakeObligationWithVesca(c,m,i)),x.txBlock}async build(t){return this.extendPeriodAndStakeMoreSca(t)}static fromData(t){return new a(t)}};var bi=class a extends A{constructor(t){super(t);this.data=t}data;txType;txSubType;async extendStakeScaLockPeriod({account:t,scallopClient:n}){let o=t.address,{veScaKey:i,unlockTime:s,obligationId:c,obligationKey:m,isObligationLocked:b,isOldBorrowIncentive:S}=this.data,I=n.builder.createTxBlock();return I.setSender(o),I.extendLockPeriod(i,s),c&&m&&(b&&(S?Ht.unstakeObligation(I,m,c):I.unstakeObligation(c,m)),I.stakeObligationWithVesca(c,m,i)),I.txBlock}async build(t){return this.extendStakeScaLockPeriod(t)}static fromData(t){return new a(t)}};var Ti=class a extends A{constructor(t){super(t);this.data=t}data;txType;txSubType;async handleUnsubForKeys(t,n,o){let{targetVeScaKey:i,sourceVeScaKey:s}=this.data,[c,m]=await Promise.all([n.getBindedObligationId(i),n.getBindedObligationId(s)]);c&&await t.unstakeObligationQuick(c),m&&await t.unstakeObligationQuick(m),o(t,i,s),c&&await t.stakeObligationWithVeScaQuick(c,void 0,i),m&&await t.stakeObligationWithVeScaQuick(m,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,m)=>{s.mergeVeSca(i.object(c),i.object(m))}),i.txBlock}static fromData(t){return new a(t)}};var Si=class a extends A{constructor(t){super(t);this.data=t}data;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 Ip=require("@scallop-io/sui-scallop-sdk");var wi=class a extends A{constructor(t){super(t);this.data=t}data;txType;txSubType;async renewExpiredStakeSca({account:t,scallopClient:n}){let o=t.address,{amount:i,unlockTime:s,veScaKey:c,isHaveRedeem:m,obligation:b,obligationKey:S,isObligationLocked:I,isOldBorrowIncentive:x}=this.data,D=n.builder.createTxBlock();if(D.setSender(o),m){let U=D.redeemSca(c);D.transferObjects([U],o)}let k=await n.builder.utils.selectCoins(i,Ip.SCA_COIN_TYPE,o),[M,L]=D.takeAmountFromCoins(k,i);return D.transferObjects([L],o),D.renewExpiredVeSca(c,M,s),!b||!S||(I&&(x?Ht.unstakeObligation(D,S,b):D.unstakeObligation(b,S)),D.stakeObligationWithVesca(b,S,c)),D.txBlock}async build(t){return this.renewExpiredStakeSca(t)}static fromData(t){return new a(t)}};var Ii=class a extends A{constructor(t){super(t);this.data=t}data;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,m)=>{let b=s.splitVeSca(c,m.toString());s.transferObjects([b],o)}),i.txBlock}static fromData(t){return new a(t)}};var Cp=require("@scallop-io/sui-scallop-sdk");var Ci=class a extends A{constructor(t){super(t);this.data=t}data;txType;txSubType;async stakeSca({account:t,scallopClient:n}){let o=t.address,{amount:i,isObligationLocked:s,isOldBorrowIncentive:c,obligationId:m,obligationKey:b,unlockTime:S,veScaKey:I}=this.data,x=n.builder.createTxBlock();x.setSender(o);let D=await n.utils.selectCoins(i,Cp.SCA_COIN_TYPE,o),[k,M]=x.takeAmountFromCoins(D,i),L;return I?x.extendLockAmount(I,k):L=x.lockSca(k,S),m&&b&&(s&&(c?Ht.unstakeObligation(x,b,m):x.unstakeObligation(m,b)),x.stakeObligationWithVesca(m,b,I||L)),I||x.transferObjects([L,M],o),x.txBlock}async build(t){return this.stakeSca(t)}static fromData(t){return new a(t)}};var xi=class a extends A{constructor(t){super(t);this.data=t}data;txType;txSubType;async supplyAndStake({account:t,scallopClient:n}){let o=t.address,{amount:i,coinName:s,stakeAccountId:c}=this.data,m=n.builder.createTxBlock();m.setSender(o);let b=await m.depositQuick(+i,s),S=n.utils.parseMarketCoinName(s);if(n.constants.whitelist.spool.has(S))return m.txBlock;let I=await n.query.getStakeAccounts(S,o),x=c||(I.length>0?I[0].id:void 0);if(x)await m.stakeQuick(b,S,x);else{let D=m.createStakeAccount(S);await m.stakeQuick(b,S,D),m.transferObjects([D],o)}return m.txBlock}async build(t){return this.supplyAndStake(t)}static fromData(t){return new a(t)}};var Di=class a extends A{constructor(t){super(t);this.data=t}data;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 ki=class a extends A{constructor(t){super(t);this.data=t}data;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 vi=class a extends A{constructor(t){super(t);this.data=t}data;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 Ai=class{application="scallop";supportSDK="@mysten/sui";scallopClient;async initScallopClient(e,t){if(!this.scallopClient){let n=new Dp.Scallop({addressId:"695fcdc084f790c04eb068dc",walletAddress:e,suiClients:[t],fullnodeUrls:[t.transport.rpcClient.requestManager.transports[0]?.uri??(0,H.getJsonRpcFullnodeUrl)("mainnet")]});this.scallopClient=await n.createScallopClient()}}async deserialize(e){let{transaction:t,suiClient:n,account:o}=e;await this.initScallopClient(o.address,n);let i=new za(t,this.scallopClient),s=new Ja(t,this.scallopClient),c=new Ya(t,this.scallopClient),m=i.decode()||s.decode()||await c.decode();if(!m)throw new Error("Unknown transaction type");return{txType:xp.TransactionType.Other,txSubType:m.type,intentionData:m.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=li.fromData(s);break;case"WithdrawLending":c=di.fromData(s);break;case"Borrow":c=Za.fromData(s);break;case"Repay":c=si.fromData(s);break;case"DepositCollateral":c=oi.fromData(s);break;case"WithdrawCollateral":c=mi.fromData(s);break;case"OpenObligation":c=ri.fromData(s);break;case"UnstakeSpool":c=ui.fromData(s);break;case"ClaimIncentiveReward":c=ni.fromData(s);break;case"BorrowWithBoost":c=ti.fromData(s);break;case"StakeSca":c=Ci.fromData(s);break;case"ExtendStakePeriod":c=bi.fromData(s);break;case"ExtendPeriodAndStakeMore":c=yi.fromData(s);break;case"RenewExpStakePeriod":c=wi.fromData(s);break;case"WithdrawStakedSca":c=vi.fromData(s);break;case"SupplyAndStakeLending":c=xi.fromData(s);break;case"WithdrawAndUnstakeLending":c=pi.fromData(s);break;case"RedeemSca":c=Si.fromData(s);break;case"MigrateAndClaim":c=ai.fromData(s);break;case"BorrowWithReferral":c=ei.fromData(s);break;case"CreateReferralLink":c=gi.fromData(s);break;case"ClaimRevenueReferral":c=hi.fromData(s);break;case"BindReferral":c=fi.fromData(s);break;case"MigrateScoin":c=ii.fromData(s);break;case"RepayWithBoost":c=ci.fromData(s);break;case"MergeVeSca":c=Ti.fromData(s);break;case"SplitVeSca":c=Ii.fromData(s);break;case"VeScaObligationBindings":{c=Di.fromData(s);break}case"TransferVeScaKeys":{c=ki.fromData(s);break}default:throw new Error("not implemented")}return c.build({suiClient:t,account:n,network:o,scallopClient:this.scallopClient})}};var Hp=require("@msafe/sui3-utils");var bn=require("@msafe/sui3-utils"),Ae=require("@mysten/sui/utils");var _p=require("@suilend/sui-fe");var Wp=require("@msafe/sui3-utils"),ve=require("@suilend/sdk");var je=require("@msafe/sui3-utils"),gn=require("@mysten/bcs"),hn=require("@mysten/sui/utils"),Ue=require("@suilend/sui-fe"),Js=Mt(require("bignumber.js"));var Mi=class{constructor(e,t){this.transaction=e;this.simResult=t}transaction;simResult;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,hn.normalizeStructTag)(e.MintEvent.parsedJson.coin_type.name),n=e.MintEvent.parsedJson.liquidity_amount;return console.log("Decoder.decodeDeposit",t,n),{txType:je.TransactionType.Other,type:"deposit",intentionData:{coinType:t,value:n}}}decodeWithdraw(){let e={withdraw_ctokens:this.getMoveCallCommand("withdraw_ctokens")},t={RedeemEvent:this.simResult.events.find(m=>m.type.includes("lending_market::RedeemEvent"))},n=(0,hn.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 Js.default((0,gn.toHex)((0,gn.fromBase64)(this.inputs[i].Pure.bytes)),16).toString(),c=s===Ue.MAX_U64.toString();return console.log("decodeWithdraw - isMax:",c,"inputIndex:",i,"inputValue:",s,"MAX_U64.toString():",Ue.MAX_U64.toString()),c&&(o=Ue.MAX_U64.toString()),{txType:je.TransactionType.Other,type:"withdraw",intentionData:{coinType:n,value:o}}}decodeBorrow(){let e={borrow_request:this.getMoveCallCommand("borrow_request")},t={BorrowEvent:this.simResult.events.find(m=>m.type.includes("lending_market::BorrowEvent"))},n=(0,hn.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 Js.default((0,gn.toHex)((0,gn.fromBase64)(this.inputs[i].Pure.bytes)),16).toString(),c=s===Ue.MAX_U64.toString();return console.log("decodeBorrow - isMax:",c,"inputIndex:",i,"inputValue:",s,"MAX_U64.toString():",Ue.MAX_U64.toString()),c&&(o=Ue.MAX_U64.toString()),{txType:je.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,hn.normalizeStructTag)(e.RepayEvent.parsedJson.coin_type.name),n=e.RepayEvent.parsedJson.liquidity_amount;return console.log("Decoder.decodeRepay",t,n),{txType:je.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,hn.normalizeStructTag)(o.parsedJson.coin_type.name),s=o.parsedJson.liquidity_amount;t[i]=`${+(t[i]??"0")+ +s}`}return console.log("Decoder.decodeClaimRewards",t),{txType:je.TransactionType.Other,type:"claim",intentionData:{value:t}}}decodeClaimAndDeposit(){return{txType:je.TransactionType.Other,type:"claimAndDeposit",intentionData:this.decodeClaim().intentionData}}};var vp=require("@mysten/sui/transactions");var kp=Mt(require("sort-keys-recursive")),Ft=class{constructor(e){this.data=e}data;serialize(){return JSON.stringify((0,kp.default)(this.data))}};var Oi=class a extends Ft{constructor(t){super(t);this.data=t}data;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 m=new vp.Transaction;return await i.borrowAndSendToUser(o.address,s.id,c.id,this.data.coinType,this.data.value,m),m}static fromData(t){return console.log("BorrowIntention.fromData",t),new a(t)}};var Pp=require("@mysten/sui/transactions");var Ap=require("@mysten/sui/utils"),yn=require("@suilend/sdk"),Mp=require("@suilend/sui-fe"),Op=Mt(require("bignumber.js")),Hf=(a,e)=>{let t={[yn.Side.DEPOSIT]:[],[yn.Side.BORROW]:[]};return a.lendingMarket.reserves.forEach(n=>{[yn.Side.DEPOSIT,yn.Side.BORROW].forEach(o=>{let i=o===yn.Side.DEPOSIT?n.depositsPoolRewardManager:n.borrowsPoolRewardManager,s=e.userRewardManagers.find(c=>c.poolRewardManagerId===i.id);s&&(t[o]=i.poolRewards.map((c,m)=>({reserveArrayIndex:n.arrayIndex,rewardIndex:BigInt(m),rewardCoinType:(0,Ap.normalizeStructTag)(c.coinType.name),side:o})).filter(c=>!(0,Mp.isSendPoints)(c.rewardCoinType)&&!!s.rewards[Number(c.rewardIndex)]&&new Op.default(s.rewards[Number(c.rewardIndex)].earnedRewards.value.toString()).gt(0)))})}),Object.values(t).flat()},Pi=Hf;var Ri=class a extends Ft{constructor(t){super(t);this.data=t}data;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 m=new Pp.Transaction;return i.claimRewardsAndSendToUser(o.address,s.id,Pi(i,c),m),m}static fromData(t){return console.log("ClaimIntention.fromData",t),new a(t)}};var Rp=require("@mysten/sui/transactions");var Bi=class a extends Ft{constructor(t){super(t);this.data=t}data;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 m=new Rp.Transaction;return i.claimRewardsAndDeposit(o.address,s.id,Pi(i,c),m),m}static fromData(t){return console.log("ClaimAndDepositIntention.fromData",t),new a(t)}};var Bp=require("@mysten/sui/transactions");var Ei=class a extends Ft{constructor(t){super(t);this.data=t}data;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 m=new Bp.Transaction;return await i.depositIntoObligation(o.address,this.data.coinType,this.data.value,m,s?.id),m}static fromData(t){return console.log("DepositIntention.fromData",t),new a(t)}};var Ep=require("@mysten/sui/transactions");var Ni=class a extends Ft{constructor(t){super(t);this.data=t}data;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 m=new Ep.Transaction;return await i.repayIntoObligation(o.address,c.id,this.data.coinType,this.data.value,m),m}static fromData(t){return console.log("RepayIntention.fromData",t),new a(t)}};var Np=require("@mysten/sui/transactions");var Wi=class a extends Ft{constructor(t){super(t);this.data=t}data;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 m=new Np.Transaction;return await i.withdrawAndSendToUser(o.address,s.id,c.id,this.data.coinType,this.data.value,m),m}static fromData(t){return console.log("WithdrawIntention.fromData",t),new a(t)}};var _i=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}},Li=class{application="Suilend";supportSDK="@mysten/sui";utils;async deserialize(e){let{transaction:t,suiClient:n,account:o}=e;this.utils||(this.utils=await _i(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 Mi(t,i).decode();return{txType:Wp.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 _i(i,s));let c;switch(n){case"deposit":c=Ei.fromData(o);break;case"withdraw":c=Wi.fromData(o);break;case"borrow":c=Oi.fromData(o);break;case"repay":c=Ni.fromData(o);break;case"claim":c=Ri.fromData(o);break;case"claimAndDeposit":c=Bi.fromData(o);break;default:throw new Error("not implemented")}let m=window.localStorage.getItem("obligationId"),b=this.utils.obligations?.find(I=>I.id===m)??this.utils.obligations?.[0],S=this.utils.obligationOwnerCaps?.find(I=>I.obligationId===b?.id);return c.build({network:t,suiClient:i,account:s,suilendClient:this.utils.suilendClient,obligationOwnerCap:S,obligation:b})}};var Ys=async(a,e)=>{let t=await _i(a,e),n=await fetch(`${_p.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 ji=class{constructor(e,t){this.transaction=e;this.simResult=t}transaction;simResult;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:bn.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:bn.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:bn.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:bn.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:bn.TransactionType.Other,type:"unstake",intentionData:{amount:n,inCoinType:t}}}};var jp=require("@mysten/sui/transactions"),zn=require("@suilend/springsui-sdk");var Lp=Mt(require("sort-keys-recursive")),Xt=class{constructor(e){this.data=e}data;serialize(){return JSON.stringify((0,Lp.default)(this.data))}};var Ui=class a extends Xt{constructor(t){super(t);this.data=t}data;txType;txSubType;async build(t){let{suiClient:n,account:o,suilendClient:i,LIQUID_STAKING_INFO_MAP:s,obligationOwnerCap:c,obligation:m}=t;console.log("ConvertIntention.build",n,o,i,s,c,m);let b=await zn.LstClient.initialize(n,Object.values(s).find(x=>x.type===this.data.inCoinType)),S=await zn.LstClient.initialize(n,Object.values(s).find(x=>x.type===this.data.outCoinType)),I=new jp.Transaction;return(0,zn.convertLstsAndRebalanceAndSendToUser)(b,S,I,o.address,this.data.amount),I}static fromData(t){return console.log("ConvertIntention.fromData",t),new a(t)}};var Up=require("@mysten/sui/transactions"),Fi=require("@suilend/sdk"),Qn=require("@suilend/springsui-sdk");var qi=class a extends Xt{constructor(t){super(t);this.data=t}data;txType;txSubType;async build(t){let{suiClient:n,account:o,suilendClient:i,LIQUID_STAKING_INFO_MAP:s,obligationOwnerCap:c,obligation:m}=t;console.log("ConvertAndDepositIntention.build",n,o,i,s,c,m);let b=await Qn.LstClient.initialize(n,Object.values(s).find(M=>M.type===this.data.inCoinType)),S=await Qn.LstClient.initialize(n,Object.values(s).find(M=>M.type===this.data.outCoinType)),I=new Up.Transaction,{obligationOwnerCapId:x,didCreate:D}=(0,Fi.createObligationIfNoneExists)(i,I,c),k=(0,Qn.convertLstsAndRebalance)(b,S,I,o.address,this.data.amount);return i.deposit(k,this.data.outCoinType,x,I),D&&(0,Fi.sendObligationToUser)(x,o.address,I),I}static fromData(t){return console.log("ConvertAndDepositIntention.fromData",t),new a(t)}};var qp=require("@mysten/sui/transactions"),Fp=require("@suilend/springsui-sdk");var Ki=class a extends Xt{constructor(t){super(t);this.data=t}data;txType;txSubType;async build(t){let{suiClient:n,account:o,suilendClient:i,LIQUID_STAKING_INFO_MAP:s,obligationOwnerCap:c,obligation:m}=t;console.log("StakeIntention.build",n,o,i,s,c,m);let b=await Fp.LstClient.initialize(n,Object.values(s).find(I=>I.type===this.data.outCoinType)),S=new qp.Transaction;return b.mintAmountAndRebalanceAndSendToUser(S,o.address,this.data.amount),S}static fromData(t){return console.log("StakeIntention.fromData",t),new a(t)}};var Kp=require("@mysten/sui/transactions"),$i=require("@suilend/sdk"),Vp=require("@suilend/springsui-sdk");var Vi=class a extends Xt{constructor(t){super(t);this.data=t}data;txType;txSubType;async build(t){let{suiClient:n,account:o,suilendClient:i,LIQUID_STAKING_INFO_MAP:s,obligationOwnerCap:c,obligation:m}=t;console.log("StakeAndDepositIntention.build",n,o,i,s,c,m);let b=await Vp.LstClient.initialize(n,Object.values(s).find(k=>k.type===this.data.outCoinType)),S=new Kp.Transaction,{obligationOwnerCapId:I,didCreate:x}=(0,$i.createObligationIfNoneExists)(i,S,c),D=b.mintAmountAndRebalance(S,o.address,this.data.amount);return i.deposit(D,this.data.outCoinType,I,S),x&&(0,$i.sendObligationToUser)(I,o.address,S),S}static fromData(t){return console.log("StakeAndDepositIntention.fromData",t),new a(t)}};var $p=require("@mysten/sui/transactions"),Gp=require("@suilend/springsui-sdk");var Gi=class a extends Xt{constructor(t){super(t);this.data=t}data;txType;txSubType;async build(t){let{suiClient:n,account:o,suilendClient:i,LIQUID_STAKING_INFO_MAP:s,obligationOwnerCap:c,obligation:m}=t;console.log("UnstakeIntention.build",n,o,i,s,c,m);let b=await Gp.LstClient.initialize(n,Object.values(s).find(I=>I.type===this.data.inCoinType)),S=new $p.Transaction;return b.redeemAmountAndRebalanceAndSendToUser(S,o.address,this.data.amount),S}static fromData(t){return console.log("UnstakeIntention.fromData",t),new a(t)}};var Hi=class{application="SpringSui";supportSDK="@mysten/sui";utils;async deserialize(e){let{transaction:t,suiClient:n,account:o}=e;this.utils||(this.utils=await Ys(n,o));let i=await n.devInspectTransactionBlock({sender:o.address,transactionBlock:t});console.log("SpringSuiAppHelper.deserialize",i);let c=new ji(t,i).decode();return{txType:Hp.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 Ys(i,s));let c;switch(n){case"stake":c=Ki.fromData(o);break;case"stakeAndDeposit":c=Vi.fromData(o);break;case"convert":c=Ui.fromData(o);break;case"convertAndDeposit":c=qi.fromData(o);break;case"unstake":c=Gi.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 Qp=require("@msafe/sui3-utils");var Zs=require("@msafe/sui3-utils");var Xi=class{constructor(e,t){this.transaction=e;this.simResult=t}transaction;simResult;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:Zs.TransactionType.Other,type:"mint",intentionData:{amount:t}}}decodeRedeem(e){let{event:{lst_amount_in:t}}=e;return console.log("Decoder.decodeRedeem",t),{txType:Zs.TransactionType.Other,type:"redeem",intentionData:{amount:t}}}};var Xp=require("@alphafi/stsui-sdk");var zi=class a extends w{constructor(t){super(t);this.data=t}data;txType;txSubType;async build(t){let{account:n}=t,{amount:o}=this.data,i={lstInfo:"0x1adb343ab351458e151bc392fbf1558b3332467f23bda45ae67cd355a57fd5f5",lstCointype:"0xd1b72982e40348d069bb1ff701e634c117bb5f741f44dff91e472d3b01461e55::stsui::STSUI"},c=await new Xp.LST(i).mint(o,n.address);return c.setGasBudget(1e8),c}static fromData(t){return console.log("MintIntention.fromData",t),new a(t)}};var zp=require("@alphafi/stsui-sdk");var Qi=class a extends w{constructor(t){super(t);this.data=t}data;txType;txSubType;async build(t){let{account:n}=t,{amount:o}=this.data,i={lstInfo:"0x1adb343ab351458e151bc392fbf1558b3332467f23bda45ae67cd355a57fd5f5",lstCointype:"0xd1b72982e40348d069bb1ff701e634c117bb5f741f44dff91e472d3b01461e55::stsui::STSUI"},c=await new zp.LST(i).redeem(o,n.address);return c.setGasBudget(1e8),c}static fromData(t){return console.log("RedeemIntention.fromData",t),new a(t)}};var Ji=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 Xi(t,o).decode();return{txType:Qp.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=zi.fromData(e.intentionData);break;case"redeem":n=Qi.fromData(e.intentionData);break;default:throw new Error("build not implemented")}return n.build({account:t})}};var Sm=require("@msafe/sui3-utils"),wm=require("turbos-clmm-sdk");var jt=require("@msafe/sui3-utils"),qe=require("@mysten/bcs"),Fe=require("@mysten/sui/bcs"),Jp=require("turbos-clmm-sdk");var zt={PackageId:"0x02fe4933f4521250e55a15441096d1d4a38a7311195b0bca126fc0138c1f5a97",Claim:"0x0c822cec42f7ca703696b4232f1c47b348330c23580172a29aab465bc071d894",turbosCoinType:"0x5d1f47ea69bb0de31c313d7acf89b890dbb8991ea8e03c6c355171f84bb1ba4a::turbos::TURBOS"},Qt={PackageId:"0xdee9"};var Jf=(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}`)}},Yi=class{constructor(e,t,n){this.txb=e;this.turbosSdk=t;this.config=n}txb;turbosSdk;config;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(`${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(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=Jf(t,n,this.swap1Layer,this.swap2Layer),i=o.map((D,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 Jp.BN(L.toString()));return{pool:M,a2b:D,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],m=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)),I=this.helper.decodeInputU64(this.helper.getInputsIndex(2+t)),x=this.helper.decodeInputU64(this.helper.getInputsIndex(3+t));return{txType:jt.TransactionType.Other,type:"Swap",intentionData:{routes:i,coinTypeA:s,coinTypeB:c,address:m,amountA:S?I:x,amountB:S?x:I,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)),m=this.helper.decodeInputBool(this.helper.getInputsIndex(7)),b=this.helper.decodeInputU64(this.helper.getInputsIndex(13));return{txType:jt.TransactionType.Other,type:"AddLiquidity",intentionData:{pool:e,slippage:30,address:t,amountA:n,amountB:o,tickLower:s?-i:i,tickUpper:m?-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:jt.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:jt.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:jt.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:jt.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)),m=s.decodeInputU64(s.getInputsIndex(5));o[c]=m});let i=this.helper.decodeInputU64(7);return{txType:jt.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:jt.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)),m=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 S=this.collectFeeHelper.decodeInputU64(this.collectFeeHelper.getInputsIndex(3))||0,I=this.collectFeeHelper.decodeInputU64(this.collectFeeHelper.getInputsIndex(4))||0;return{txType:jt.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:I,rewardAmounts:b,deadline:m}}}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),m=this.collectRewardHelper.map(I=>I.decodeInputU64(5)),b=this.collectFeeHelper.decodeInputU64(3)||0,S=this.collectFeeHelper.decodeInputU64(4)||0;return{txType:jt.TransactionType.Other,type:"removeLiquidityWithReturn",intentionData:{pool:t,decreaseLiquidity:o,nft:n,amountA:i,amountB:s,slippage:10,address:e,collectAmountA:b,collectAmountB:S,rewardAmounts:m,deadline:c}}}decodePrixClaim(){return{txType:jt.TransactionType.Other,type:"PrixClaim",intentionData:{}}}decodePrixJoin(){return{txType:jt.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:jt.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:jt.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}moveCall;txb;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(Fe.bcs.u128().parse(Uint8Array.from((0,qe.fromBase64)(this.inputs[e].Pure.bytes))))}decodeInputU64(e){return Number(Fe.bcs.u64().parse(Uint8Array.from((0,qe.fromBase64)(this.inputs[e].Pure.bytes))))}decodeInputU32(e){return Number(Fe.bcs.u32().parse(Uint8Array.from((0,qe.fromBase64)(this.inputs[e].Pure.bytes))))}decodeInputU8(e){return Number(Fe.bcs.u8().parse(Uint8Array.from((0,qe.fromBase64)(this.inputs[e].Pure.bytes))))}decodeInputAddress(e){return Fe.bcs.Address.parse(Uint8Array.from((0,qe.fromBase64)(this.inputs[e].Pure.bytes)))}decodeInputBool(e){return Fe.bcs.bool().parse(Uint8Array.from((0,qe.fromBase64)(this.inputs[e].Pure.bytes)))}shortTypeArg(e){return this.moveCall.MoveCall.typeArguments[e]}txArg(e){return this.moveCall.MoveCall.arguments[e]}};var Yp=require("turbos-clmm-sdk");var Zi=class a extends w{constructor(t){super(t);this.data=t}data;txType;txSubType;async build(t){let n=new Yp.TurbosSdk(t.network.replace("sui:",""),t.suiClient),{pool:o,address:i,amountA:s,amountB:c,slippage:m,tickLower:b,tickUpper:S,deadline:I,txb:x}=this.data;return n.pool.addLiquidity({pool:o,slippage:m,address:i,amountA:s,amountB:c,tickLower:b,tickUpper:S,deadline:I,txb:x})}static fromData(t){return new a(t)}};var Zp=require("turbos-clmm-sdk");var tr=class a extends w{constructor(t){super(t);this.data=t}data;txType;txSubType;async build(t){let n=new Zp.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 tm=require("turbos-clmm-sdk");var er=class a extends w{constructor(t){super(t);this.data=t}data;txType;txSubType;async build(t){let n=new tm.TurbosSdk(t.network.replace("sui:",""),t.suiClient),{pool:o,address:i,nft:s,collectAmountA:c,collectAmountB:m,deadline:b,txb:S}=this.data;return n.pool.collectFee({pool:o,address:i,collectAmountA:c,collectAmountB:m,nft:s,deadline:b,txb:S})}static fromData(t){return new a(t)}};var em=require("turbos-clmm-sdk");var nr=class a extends w{constructor(t){super(t);this.data=t}data;txType;txSubType;async build(t){let n=new em.TurbosSdk(t.network.replace("sui:",""),t.suiClient),{pool:o,address:i,nft:s,rewardAmounts:c,deadline:m,txb:b}=this.data;return n.pool.collectReward({pool:o,address:i,rewardAmounts:c,nft:s,deadline:m,txb:b})}static fromData(t){return new a(t)}};var nm=require("turbos-clmm-sdk");var or=class a extends w{constructor(t){super(t);this.data=t}data;txType;txSubType;async build(t){let n=new nm.TurbosSdk(t.network.replace("sui:",""),t.suiClient),{fee:o,address:i,tickLower:s,tickUpper:c,sqrtPrice:m,slippage:b,coinTypeA:S,coinTypeB:I,amountA:x,amountB:D,deadline:k,txb:M}=this.data;return n.pool.createPool({fee:o,amountA:x,amountB:D,address:i,tickLower:s,tickUpper:c,sqrtPrice:m,slippage:b,coinTypeA:S,coinTypeB:I,deadline:k,txb:M})}static fromData(t){return new a(t)}};var om=require("turbos-clmm-sdk");var ar=class a extends w{constructor(t){super(t);this.data=t}data;txType;txSubType;async build(t){let n=new om.TurbosSdk(t.network.replace("sui:",""),t.suiClient),{pool:o,address:i,amountA:s,amountB:c,slippage:m,nft:b,decreaseLiquidity:S,deadline:I,txb:x}=this.data;return n.pool.decreaseLiquidity({pool:o,slippage:m,address:i,amountA:s,amountB:c,nft:b,decreaseLiquidity:S,deadline:I,txb:x})}static fromData(t){return new a(t)}};var am=require("turbos-clmm-sdk");var ir=class a extends w{constructor(t){super(t);this.data=t}data;txType;txSubType;async build(t){let n=new am.TurbosSdk(t.network.replace("sui:",""),t.suiClient),{pool:o,address:i,amountA:s,amountB:c,slippage:m,nft:b,decreaseLiquidity:S,deadline:I}=this.data,{txb:x,coinA:D,coinB:k}=await n.pool.decreaseLiquidityWithReturn({pool:o,slippage:m,address:i,amountA:s,amountB:c,nft:b,decreaseLiquidity:S,deadline:I});return x.transferObjects([D,k],this.data.address),x}static fromData(t){return new a(t)}};var im=require("turbos-clmm-sdk");var rr=class a extends w{constructor(t){super(t);this.data=t}data;txType;txSubType;async build(t){let n=new im.TurbosSdk(t.network.replace("sui:",""),t.suiClient),{pool:o,address:i,amountA:s,amountB:c,slippage:m,nft:b,deadline:S,txb:I}=this.data;return n.pool.increaseLiquidity({pool:o,slippage:m,address:i,amountA:s,amountB:c,nft:b,deadline:S,txb:I})}static fromData(t){return new a(t)}};var rm=require("@mysten/sui/transactions"),sm=require("@mysten/sui/utils");var sr=class a extends w{constructor(t){super(t);this.data=t}data;txType;txSubType;async build(t){let n=new rm.Transaction;return n.moveCall({target:`${zt.PackageId}::claim::claim`,typeArguments:[zt.turbosCoinType],arguments:[n.object(zt.Claim),n.object(sm.SUI_CLOCK_OBJECT_ID)]}),n}static fromData(t){return new a(t)}};var cm=require("@mysten/sui/transactions");var cr=class a extends w{constructor(t){super(t);this.data=t}data;txType;txSubType;async build(t){let n=new cm.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 lm=require("@mysten/sui/transactions"),um=require("turbos-clmm-sdk");var lr=class a extends w{constructor(t){super(t);this.data=t}data;txType;txSubType;async build(t){let n=new um.TurbosSdk(t.network.replace("sui:",""),t.suiClient),o=new lm.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 pm=require("turbos-clmm-sdk");var ur=class a extends w{constructor(t){super(t);this.data=t}data;txType;txSubType;async build(t){let n=new pm.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 mm=require("turbos-clmm-sdk");var pr=class a extends w{constructor(t){super(t);this.data=t}data;txType;txSubType;async build(t){console.log(this.data,"this.data");let n=new mm.TurbosSdk(t.network.replace("sui:",""),t.suiClient),{routes:o,coinTypeA:i,coinTypeB:s,address:c,amountA:m,amountB:b,slippage:S,amountSpecifiedIsInput:I,deadline:x,txb:D}=this.data;return n.trade.swap({routes:o,coinTypeA:i,coinTypeB:s,address:c,amountA:m,amountB:b,amountSpecifiedIsInput:I,slippage:S,deadline:x,txb:D})}static fromData(t){return new a(t)}};var bm=require("turbos-clmm-sdk");var tc=require("@mysten/sui/transactions"),ec=require("@mysten/sui/utils");var dm=require("turbos-clmm-sdk");var Jn=class{constructor(e){this.turbosSdk=e}turbosSdk;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((m,b)=>Number(b.balance)-Number(m.balance)).some(m=>c>=n?!0:(c+=Number(m.balance),s.push(m),!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,dm.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 fm=89,hm=1e6,gm=async a=>{let{token1:e,token2:t,poolId:n,amountIn:o,currentAddress:i,turbosSdk:s}=a,c=new tc.Transaction,m=new Jn(s),b=await m.getCoinsData(i,t,o),[S,I]=m.splitAndMergeCoin(b,o,c);if(!S)throw new Error(`Not enough balance: ${t}`);let x=await m.IsAccountCap(i),D=x?c.object(x):m.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(fm),D,c.pure.u64(o),c.object((0,ec.normalizeSuiObjectId)("0x6")),S]});return I&&c.transferObjects([I],c.pure.address(i)),c.transferObjects([k],c.pure.address(i)),c.transferObjects([M],c.pure.address(i)),x||c.transferObjects([D],c.pure.address(i)),c.setSenderIfNotSet(i),c.setGasBudget(hm),c},ym=async a=>{let{token1:e,token2:t,poolId:n,amountIn:o,currentAddress:i,turbosSdk:s}=a,c=new tc.Transaction,m=new Jn(s),b=await m.getCoinsData(i,e,o),[S,I]=m.splitAndMergeCoin(b,o,c);if(!S)throw new Error(`Not enough balance: ${e}`);let x=await m.IsAccountCap(i),D=x?c.object(x):m.createAccount(c),k=m.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(fm),D,c.pure.u64(o),S,k,c.object((0,ec.normalizeSuiObjectId)("0x6"))]});return I&&c.transferObjects([I],c.pure.address(i)),c.transferObjects([M],c.pure.address(i)),c.transferObjects([L],c.pure.address(i)),x||c.transferObjects([D],c.pure.address(i)),c.setSenderIfNotSet(i),c.setGasBudget(hm),c};var mr=class a extends w{constructor(t){super(t);this.data=t}data;txType;txSubType;async build(t){let n=new bm.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 Tm=require("turbos-clmm-sdk");var dr=class a extends w{constructor(t){super(t);this.data=t}data;txType;txSubType;async build(t){let n=new Tm.TurbosSdk(t.network.replace("sui:",""),t.suiClient);return await gm({...this.data,turbosSdk:n,currentAddress:t.account.address})}static fromData(t){return new a(t)}};var fr=class{application="turbos";supportSDK="@mysten/sui";async deserialize(e){console.log(e,"input");let t=new wm.TurbosSdk(e.network.replace("sui:","")),n=await t.contract.getConfig(),{transaction:o,account:i}=e,c=await new Yi(o,t,n).decode(i.address);return{txType:Sm.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=or.fromData(e.intentionData);break;case"AddLiquidity":i=Zi.fromData(e.intentionData);break;case"IncreaseLiquidity":i=rr.fromData(e.intentionData);break;case"DecreaseLiquidity":i=ar.fromData(e.intentionData);break;case"DecreaseLiquidityWithReturn":i=ir.fromData(e.intentionData);break;case"RemoveLiquidity":i=lr.fromData(e.intentionData);break;case"removeLiquidityWithReturn":i=ur.fromData(e.intentionData);break;case"CollectFee":i=er.fromData(e.intentionData);break;case"CollectReward":i=nr.fromData(e.intentionData);break;case"Burn":i=tr.fromData(e.intentionData);break;case"Swap":i=pr.fromData(e.intentionData);break;case"PrixJoin":i=cr.fromData(e.intentionData);break;case"PrixClaim":i=sr.fromData(e.intentionData);break;case"SwapExactBaseForQuote":i=mr.fromData(e.intentionData);break;case"SwapExactQuoteForBase":i=dr.fromData(e.intentionData);break;default:throw new Error("not implemented")}return i.build({suiClient:t,account:n,network:o})}};var km=require("@msafe/sui3-utils");var hr=require("@msafe/sui3-utils"),nc=require("@mysten/sui.js/bcs"),Oe=require("@mysten/sui.js/utils");var Yf={packageId:"0x549e8b69270defbfafd4f94e17ec44cdbdd99820b33bda2278dea3b9a32d3f55",poolObjectId:"0x7fa2faa111b8c65bea48a23049bfd81ca8f971a262d981dcd9a17c3825cb5baf",metadataObjectId:"0x680cd26af32b2bde8d3361e804c53ec1d1cfe24c7f039eb7f549e8dfde389a60",systemStateObjectId:"0x0000000000000000000000000000000000000000000000000000000000000005",certType:"0x549e8b69270defbfafd4f94e17ec44cdbdd99820b33bda2278dea3b9a32d3f55::cert::CERT",gasBudget:5e7},Ot=Yf;var gr=class{constructor(e){this.txb=e}txb;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(`${Ot.packageId}::native_pool::stake`)}isUnStakeTransaction(){return!!this.getMoveCallTransaction(`${Ot.packageId}::native_pool::unstake`)}isClaimTicketTransaction(){return!!this.getMoveCallTransaction(`${Ot.packageId}::native_pool::burn_ticket`)}decodeStake(){let e=this.transactions[0].amounts[0].value.toNumber();return{txType:hr.TransactionType.Other,type:"Stake",intentionData:{amount:e}}}decodeUnStake(){let t=this.transactions.find(n=>n.kind==="SplitCoins").amounts[0].value.toNumber();return{txType:hr.TransactionType.Other,type:"UnStake",intentionData:{amount:t}}}decodeClaimTicket(){let e=this.helper.decodeOwnedObjectId(2);return console.log(e),{txType:hr.TransactionType.Other,type:"ClaimTicket",intentionData:{ticketId:e}}}get helper(){let e=this.transactions.find(t=>t.kind==="MoveCall"&&t.target.startsWith(Ot.packageId));return new oc(e,this.txb)}},oc=class a{constructor(e,t){this.moveCall=e;this.txb=t}moveCall;txb;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 nc.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 nc.bcs.de(t,new Uint8Array(n))}typeArg(e){return(0,Oe.normalizeStructTag)(this.moveCall.typeArguments[e])}txArg(e){return this.moveCall.arguments[e]}};var Cm=require("@mysten/sui.js/transactions");var Im=Mt(require("sort-keys-recursive")),Pe=class{constructor(e){this.data=e}data;serialize(){return JSON.stringify((0,Im.default)(this.data))}};var yr=class a extends Pe{constructor(t){super(t);this.data=t}data;txType;txSubType;async build(t){console.log(t);let n=new Cm.TransactionBlock,{ticketId:o}=this.data;return n.moveCall({target:`${Ot.packageId}::native_pool::burn_ticket`,arguments:[n.object(Ot.poolObjectId),n.object(Ot.systemStateObjectId),n.object(o)]}),n}static fromData(t){return new a(t)}};var xm=require("@mysten/sui.js/transactions");var br=class a extends Pe{constructor(t){super(t);this.data=t}data;txType;txSubType;async build(t){console.log(t);let n=new xm.TransactionBlock,{amount:o}=this.data,[i]=n.splitCoins(n.gas,[n.pure(o)]);return n.moveCall({target:`${Ot.packageId}::native_pool::stake`,arguments:[n.object(Ot.poolObjectId),n.object(Ot.metadataObjectId),n.object(Ot.systemStateObjectId),i]}),n}static fromData(t){return new a(t)}};var Dm=require("@mysten/sui.js/transactions");var Tr=class a extends Pe{constructor(t){super(t);this.data=t}data;txType;txSubType;async build(t){console.log(t);let n=new Dm.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]===Ot.certType.split("::")[0]),m=n.object(s.coinObjectId);c.length&&n.mergeCoins(m,c.map(S=>n.object(S.coinObjectId)));let b=n.splitCoins(n.object(s.coinObjectId),[n.pure(o)]);return n.moveCall({target:`${Ot.packageId}::native_pool::unstake`,arguments:[n.object(Ot.poolObjectId),n.object(Ot.metadataObjectId),n.object(Ot.systemStateObjectId),b]}),n}static fromData(t){return new a(t)}};var Sr=class{application="volo";supportSDK="@mysten/sui.js";async deserialize(e){let{transactionBlock:t}=e,o=new gr(t).decode();return{txType:km.TransactionType.Other,txSubType:o.type,intentionData:o.intentionData}}async build(e){let{suiClient:t,account:n}=e,o;switch(e.txSubType){case"Stake":o=br.fromData(e.intentionData);break;case"UnStake":o=Tr.fromData(e.intentionData);break;case"ClaimTicket":o=yr.fromData(e.intentionData);break;default:throw new Error("not implemented")}return o.build({suiClient:t,account:n})}};var jm=require("@msafe/sui3-utils");var ac=require("@cetusprotocol/common-sdk"),ue=require("@msafe/sui3-utils"),Tn=require("@mysten/bcs"),Sn=require("@mysten/sui/bcs");var wr=class{constructor(e,t){this.transaction=e;this.appContext=t}transaction;appContext;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:ue.TransactionType.Other,type:"OpenPosition",intentionData:{pool:this.getSharedObjectID(this.getInputIndex(e,1)),lowerTick:Number((0,ac.asIntN)(BigInt(this.getU32(this.getInputIndex(e,2)))).toString()),upperTick:Number((0,ac.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:ue.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:ue.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:ue.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:ue.TransactionType.Other,type:"CollectRewards",intentionData:{pool:e[0].pool,position:e[0].position,collectRewardTokens:e.map(t=>t.rewardCoinType)}}}decodeCollectFeeTx(){return{txType:ue.TransactionType.Other,type:"CollectFee",intentionData:this.getFeeCallData()}}decodeCollectRewardsAndFeeTx(){let e=this.getFeeCallData();return{txType:ue.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:ue.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(Sn.bcs.u32().parse(Uint8Array.from((0,Tn.fromBase64)(this.inputs[e].Pure.bytes))))}getU64(e){return Sn.bcs.u64().parse(Uint8Array.from((0,Tn.fromBase64)(this.inputs[e].Pure.bytes)))}getU128(e){return Sn.bcs.u128().parse(Uint8Array.from((0,Tn.fromBase64)(this.inputs[e].Pure.bytes)))}getBoolean(e){return Sn.bcs.bool().parse(Uint8Array.from((0,Tn.fromBase64)(this.inputs[e].Pure.bytes)))}getAddress(e){return Sn.bcs.Address.parse(Uint8Array.from((0,Tn.fromBase64)(this.inputs[e].Pure.bytes)))}getTypeArguments(e){return e.MoveCall.typeArguments||[]}getInputIndex(e,t){return e.MoveCall.arguments[t].Input}};var Pm=require("@msafe/sui3-utils");var Ir=require("@bluefin-exchange/bluefin7k-aggregator-sdk"),ae=require("@firefly-exchange/library-sui"),Om=require("turbos-clmm-sdk");var Am=require("@firefly-exchange/library-sui"),Mm=require("@firefly-exchange/library-sui/spot"),vm={rpc:"https://fullnode.mainnet.sui.io/",objects:{GlobalConfig:"0x03db251ba509a8d5d8777b6338836082335d93eecbdd09a11e190a1cff51c352",BasePackage:"0x3492c874c1e3b3e2984e8c41b589e642d4d0a5d6459e5a9cfc2d52fd7c89c267",CurrentPackage:"0x67b34b728c4e28e704dcfecf7c5cf55c7fc593b6c65c20d1836d97c209c1928a"}},me=(a,e)=>{if(a!=="sui:mainnet")throw new Error("Bluefin spot protocol is only available on sui::mainnet");let t=new Am.SuiClient({url:vm.rpc});return new Mm.OnChainCalls(t,vm.objects,{address:e.address,isUIWallet:!1})};var Et=class{static async OpenPosition(e,t,n){let o=me(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=me(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=me(n,t),i=await o.queryChain.getPool(e.pool);return await o.removeLiquidity(i,e.position,{liquidityAmount:new ae.BN(e.liquidity),tokenMaxA:new ae.BN(e.maxAmountTokenA),tokenMaxB:new ae.BN(e.maxAmountTokenB)},{returnTx:!0,sender:t.address})}static async closePosition(e,t,n){let o=me(n,t),i=await o.queryChain.getPool(e.pool);return await o.closePosition(i,e.position,{returnTx:!0,sender:t.address})}static async collectRewards(e,t,n){let o=me(n,t),i=await o.queryChain.getPool(e.pool);return await o.collectRewards(i,e.position,{rewardCoinsType:e.collectRewardTokens,returnTx:!0,sender:t.address})}static async collectFee(e,t,n){let o=me(n,t),i=await o.queryChain.getPool(e.pool);return await o.collectFee(i,e.position,{returnTx:!0,sender:t.address})}static async collectRewardsAndFee(e,t,n){let o=me(n,t),i=await o.queryChain.getPool(e.pool);return console.log(e.position),await o.collectFeeAndRewards(i,e.position,{returnTx:!0,sender:t.address})}static async aggregator7KSwap(e,t,n){let o=me(n,t),i=await(0,Ir.getQuote)({tokenIn:e.tokenIn.address,tokenOut:e.tokenOut.address,amountIn:new Om.Decimal(e.amountIn).mul(10**e.tokenIn.decimals).toString()}),s=await(0,Ir.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{...ae.ClmmPoolUtil.estLiquidityAndCoinAmountFromOneAmounts(t.lowerTick,t.upperTick,new ae.BN(t.tokenAmount),t.isTokenAFixed,!0,0,new ae.BN(e.current_sqrt_price)),tokenMaxA:new ae.BN(t.maxAmountTokenA),tokenMaxB:new ae.BN(t.maxAmountTokenB)}}};var Cr=class a extends w{constructor(t){super(t);this.data=t}data;txType=Pm.TransactionType.Other;txSubType="Aggregator7KSwap";async build(t){let{account:n,network:o}=t;return console.log(this.data),Et.aggregator7KSwap(this.data,n,o)}static fromData(t){return new a(t)}};var Rm=require("@msafe/sui3-utils");var xr=class a extends w{constructor(t){super(t);this.data=t}data;txType=Rm.TransactionType.Other;txSubType="ClosePosition";async build(t){let{account:n,network:o}=t;return console.log(this.data),Et.closePosition(this.data,n,o)}static fromData(t){return new a(t)}};var Bm=require("@msafe/sui3-utils");var Dr=class a extends w{constructor(t){super(t);this.data=t}data;txType=Bm.TransactionType.Other;txSubType="CollectFee";async build(t){let{account:n,network:o}=t;return console.log(this.data),Et.collectFee(this.data,n,o)}static fromData(t){return new a(t)}};var Em=require("@msafe/sui3-utils");var kr=class a extends w{constructor(t){super(t);this.data=t}data;txType=Em.TransactionType.Other;txSubType="CollectRewards";async build(t){let{account:n,network:o}=t;return console.log(this.data),Et.collectRewards(this.data,n,o)}static fromData(t){return new a(t)}};var Nm=require("@msafe/sui3-utils");var vr=class a extends w{constructor(t){super(t);this.data=t}data;txType=Nm.TransactionType.Other;txSubType="CollectRewardsAndFee";async build(t){let{account:n,network:o}=t;return console.log(this.data),Et.collectRewardsAndFee(this.data,n,o)}static fromData(t){return new a(t)}};var Wm=require("@msafe/sui3-utils");var Ar=class a extends w{constructor(t){super(t);this.data=t}data;txType=Wm.TransactionType.Other;txSubType="OpenPosition";async build(t){let{account:n,network:o}=t;return console.log(this.data),Et.OpenPosition(this.data,n,o)}static fromData(t){return new a(t)}};var _m=require("@msafe/sui3-utils");var Mr=class a extends w{constructor(t){super(t);this.data=t}data;txType=_m.TransactionType.Other;txSubType="ProvideLiquidity";async build(t){let{account:n,network:o}=t;return console.log(this.data),Et.provideLiquidity(this.data,n,o)}static fromData(t){return new a(t)}};var Lm=require("@msafe/sui3-utils");var Or=class a extends w{constructor(t){super(t);this.data=t}data;txType=Lm.TransactionType.Other;txSubType="RemoveLiquidity";async build(t){let{account:n,network:o}=t;return console.log(this.data),Et.removeLiquidity(this.data,n,o)}static fromData(t){return new a(t)}};var Pr=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 wr(t,n).decode();return{txType:jm.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=Ar.fromData(e.intentionData);break;case"ProvideLiquidity":i=Mr.fromData(e.intentionData);break;case"RemoveLiquidity":i=Or.fromData(e.intentionData);break;case"ClosePosition":i=xr.fromData(e.intentionData);break;case"CollectFee":i=Dr.fromData(e.intentionData);break;case"CollectRewards":i=kr.fromData(e.intentionData);break;case"CollectRewardsAndFee":i=vr.fromData(e.intentionData);break;case"Aggregator7KSwap":i=Cr.fromData(e.intentionData);break;default:throw new Error("not implemented")}return i.build({suiClient:t,account:n,network:o})}};var Ud=require("@msafe/sui3-utils");var ed=require("@mmt-finance/clmm-sdk"),nd=require("@mysten/sui/transactions");var Ve=require("@mmt-finance/clmm-sdk/dist/utils/math/tickMath"),$m=Mt(require("bignumber.js")),R=Mt(qm());var th="0x0000000000000000000000000000000000000000000000000000000000000002::sui::SUI",_t=a=>a!=="0x2::sui::SUI"?a:"0x0000000000000000000000000000000000000000000000000000000000000002::sui::SUI",eh=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},nh=(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")},oh=(a,e,t,n)=>{if(a===th){let[o]=n.splitCoins(n.gas,[n.pure.u64(t)]);return o}else{let o=nh(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 Fm(a,e,t,n,o){let i=await eh({suiClient:a.rpcClient,address:e,type:t});return oh(_t(t),i.map(c=>({balance:BigInt(c.balance),objectId:c.coinObjectId})),n,o)}var Ke=(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 Km({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},m=n.rewarders.map(S=>S.coinType);m.length>0&&(console.log("claimRewardsAsTargetCoin input",{pool:c,positionId:t,rewarderCoinTypes:m,targetCoinType:i,slippage:s,toAddress:e}),await a.Pool.claimRewardsAs({txb:o,pool:c,positionId:t,rewarderCoinTypes:m,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 ah(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 ih(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 Vm=(a,e,t)=>{let n=(0,Ve.convertI32ToSigned)(t?a+a%(e??1):a-a%(e??1));return n>0?new R.default(ah(n)):new R.default(ih(n))};function Gm(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 ie({address:a,coinType:e,coinAmount:t,coinDecimals:n,tx:o,mmt:i}){let s=Gm(t,n),c;return Number(t)?c=await Fm(i,a,_t(e),s,o):[c]=o.moveCall({target:"0x2::coin::zero",typeArguments:[e],arguments:[]}),c}function Hm({mmt:a,tx:e,poolModel:t,selectedLowTick:n,selectedHighTick:o}){let i=Vm((0,Ve.convertI32ToSigned)(n),t.tickSpacing),s=Vm((0,Ve.convertI32ToSigned)(o),t.tickSpacing);return a.Position.openPosition(e,t,i.toString(),s.toString())}var rh=(a,e)=>{let n=1e4-Math.floor(e*100);return a*BigInt(n)/BigInt(1e4)};function Rr(a,e,t){let n=Gm(a,e);return Number(a)===0?BigInt(0):rh(n,t)}async function $e({poolId:a,currentSqrtPrice:e,tokenX:t,tokenY:n,slippagePercentage:o,isTokenX:i,suiClient:s}){let m=(await s.getObject({id:a,options:{showContent:!0}}))?.data?.content?.fields?.sqrt_price??e,b=Ve.TickMath.sqrtPriceX64ToPrice(new R.default(m?.toString()),t.decimals,n.decimals),S=i?(100-o)/100:(100+o)/100,I=Ve.TickMath.priceToSqrtPriceX64(b.mul(S),t.decimals,n.decimals);return BigInt(I.toString())}var Xm=async(a,e,t,n,o,i,s,c,m,b)=>{let S=await ie({mmt:a,address:t,coinType:i.tokenX.coinType,coinAmount:n,coinDecimals:i.tokenX.decimals,tx:e}),I=await ie({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=Hm({mmt:a,tx:e,poolModel:x,selectedLowTick:c,selectedHighTick:m}),k=Rr(n,i.tokenX.decimals,b),M=Rr(o,i.tokenY.decimals,b);a.Pool.addLiquidity(e,x,D,S,I,k,M,t),e.transferObjects([D],e.pure.address(t))},zm=async(a,e,t,n,o,i,s,c,m,b,S)=>{try{let I=await ie({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:_t(s.tokenX.coinType),tokenYType:_t(s.tokenY.coinType),tickSpacing:s.tickSpacing},D=Hm({mmt:a,tx:e,poolModel:x,selectedLowTick:c,selectedHighTick:m}),k=await $e({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:I,isXtoY:i,limitSqrtPrice:k,slippagePercentage:S,transferToAddress:n,useMvr:!0}),e.transferObjects([D],e.pure.address(n))}catch(I){console.error(I)}},Qm=async(a,e,t,n,o,i,s,c)=>{let m=await ie({mmt:a,address:t,coinType:i.tokenX.coinType,coinAmount:n,coinDecimals:i.tokenX.decimals,tx:e}),b=await ie({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},I=Rr(n,i.tokenX.decimals,c),x=Rr(o,i.tokenY.decimals,c);a.Pool.addLiquidity(e,S,s,m,b,I,x,t)},Jm=async(a,e,t,n,o,i,s,c,m)=>{try{let b=await ie({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},I=await $e({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:I,slippagePercentage:m,transferToAddress:t})}catch(b){throw console.error(b),b}},Ym=(a,e)=>BigInt(e===100?a:new $m.default(a).multipliedBy(e/100).toFixed(0)),Zm=async(a,e,t,n,o,i)=>{let s=Ym(t.liquidity,o),c=n.tokenX.coinType,m=n.tokenY.coinType,b={objectId:n?.poolId,tokenXType:c,tokenYType:m};a.Pool.removeLiquidity(i,b,t.objectId,s,BigInt(0),BigInt(0),e),Ke(a,e,t,n,i),o===100&&a.Position.closePosition(i,t.objectId)},td=async({sdk:a,address:e,position:t,pool:n,withdrawPercentage:o,txb:i,targetCoinType:s,slippage:c})=>{let m=Ym(t.liquidity,o),b=_t(n.tokenX.coinType),S=_t(n.tokenY.coinType),I=_t(s)===S,x={objectId:n?.poolId,tokenXType:b,tokenYType:S},{removeLpCoinA:D,removeLpCoinB:k}=a.Pool.removeLiquidity(i,x,t.objectId,m,BigInt(0),BigInt(0)),M=await $e({suiClient:a.rpcClient,poolId:n.poolId,currentSqrtPrice:n.currentSqrtPrice,tokenX:n.tokenX,tokenY:n.tokenY,isTokenX:I,slippagePercentage:c}),L=I?D:k,U=i.moveCall({target:"0x2::coin::value",arguments:[L],typeArguments:[I?b:S]});i.transferObjects([I?k:D],e),a.Pool.swapV2({txb:i,transferToAddress:e,pool:x,limitSqrtPrice:M,amount:U,inputCoin:L,isXtoY:I}),Ke(a,e,t,n,i),o===100&&a.Position.closePosition(i,t.objectId)};var Br=class a extends w{constructor(t){super(t);this.data=t}data;txType;txSubType;async build(){let t=ed.MmtSDK.NEW({network:"mainnet"}),{params:n}=this.data,{address:o,amountA:i,amountB:s,pool:c,selectedLowTick:m,selectedHighTick:b,slippage:S}=n,I=new nd.Transaction;return await Xm(t,I,o,i,s,c,c.poolId,m,b,S),I}static fromData(t){return new a(t)}};var od=require("@mmt-finance/clmm-sdk"),ad=require("@mysten/sui/transactions");var Er=class a extends w{constructor(t){super(t);this.data=t}data;txType;txSubType;async build(){let t=od.MmtSDK.NEW({network:"mainnet"}),{params:n}=this.data,{address:o,amount:i,isTokenX:s,pool:c,selectedLowTick:m,selectedHighTick:b,swapSlippage:S,addLiquiditySlippage:I}=n,x=new ad.Transaction;return await zm(t,x,t.rpcClient,o,i,s,c,m,b,S,I),x}static fromData(t){return new a(t)}};var pd=require("@mmt-finance/clmm-sdk"),md=require("@mmt-finance/ve-sdk-v1"),dd=require("@mysten/sui/transactions");var wn="0x35169bc93e1fddfcf3a82a9eae726d349689ed59e4b065369af8789fe59f8608::mmt::MMT";var Yn=async a=>{let e=await a.getSyncEpochInfo();if(!e)throw new Error("Failed to sync epoch");return e},id=async(a,e,t,n,o,i,s,c)=>{let m=Number(n);if(!n||Number.isNaN(m)||m<=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 ie({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 Yn(e);await e.syncOrAdvanceEpoch(c,S.currentEpoch,S.syncedEpoch);let I=c.getData().commands.length;i?await e.createMaxBond(c,b,o):await e.createBond(c,b,BigInt(s),o);let D=c.getData().commands.length;if(D===0)throw new Error(`Bond Failed: Transaction has no commands. enableAutoMaxBond: ${i}, unbondAt: ${s}, amount: ${n}`);if(D===I)throw new Error(`Bond Failed: No new commands were added by bond operation. Commands before: ${I}, after: ${D}`)},rd=async(a,e,t,n,o,i,s,c)=>{let m=await Yn(a);if(await a.syncOrAdvanceEpoch(c,m.currentEpoch,m.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)}},sd=async(a,e,t,n,o)=>{let i=await Yn(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())},cd=async(a,e,t,n)=>{let o=await Yn(a);await a.syncOrAdvanceEpoch(n,o.currentEpoch,o.syncedEpoch),await a.claimReward(n,t,e),await a.unbond(n,t,e)},ld=async(a,e,t,n)=>{if(t.length>0&&t.some(o=>o.userRewardAmount>0)){let o=await Yn(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())}},ud=async(a,e,t,n,o,i,s,c,m)=>{let b=_t(i),S=[];for(let q of n)if(q.userRewardAmount>0){let Pt=await e.buildClaimRewardCoin(o,q.veId);S.push(Pt)}let I=[];for(let q of S)Array.isArray(q)?I.push(...q):I.push(q);if(I.length===0)return;if(i===_t(wn)){o.transferObjects(I,o.pure.address(t));return}let x=c?.[i]?.[wn];if(!x||x.length===0)throw new Error(`No swap route found from ${wn} to ${i}`);let[D,...k]=I;k.length>0&&o.mergeCoins(D,k);let M=D,L=o.moveCall({target:"0x2::coin::value",arguments:[M],typeArguments:[wn]}),U=_t(wn);for(let q=0;q<x.length;q++){let Pt=x[q],W=m.find(G=>G.poolId===Pt);if(!W)throw new Error(`Pool ${Pt} not found`);let Nt=_t(W.tokenXType||W.tokenX?.coinType||"")===U,He={objectId:W.poolId,tokenXType:W.tokenXType||W.tokenX?.coinType||"",tokenYType:W.tokenYType||W.tokenY?.coinType||""},Zn=await $e({suiClient:a.rpcClient,poolId:W.poolId,currentSqrtPrice:W.currentSqrtPrice,tokenX:W.tokenX,tokenY:W.tokenY,slippagePercentage:s,isTokenX:Nt}),{outputCoin:to,leftoverCoin:In}=a.Pool.swapV2({txb:o,pool:He,amount:L,inputCoin:M,isXtoY:Nt,limitSqrtPrice:Zn});if(o.transferObjects([In],o.pure.address(t)),M=to,U=Nt?_t(W.tokenYType||W.tokenY?.coinType||""):_t(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 Nr=class a extends w{constructor(t){super(t);this.data=t}data;txType;txSubType;async build(t){let n=pd.MmtSDK.NEW({network:"mainnet"}),o=new md.VeMMT(t.suiClient,"mainnet"),{params:i}=this.data,{address:s,positions:c,pools:m,veMMTs:b}=i,S=new dd.Transaction;for(let I of c){let x=m.find(D=>D.poolId===I.poolId);x&&Ke(n,s,I,x,S)}return await ld(o,s,b,S),S}static fromData(t){return new a(t)}};var fd=require("@mmt-finance/clmm-sdk"),hd=require("@mmt-finance/ve-sdk-v1"),gd=require("@mysten/sui/transactions");var Wr=class a extends w{constructor(t){super(t);this.data=t}data;txType;txSubType;async build(t){let n=fd.MmtSDK.NEW({network:"mainnet"}),o=new hd.VeMMT(t.suiClient,"mainnet"),{params:i}=this.data,{claimVeMMTParams:s}=i,{address:c,veMMTs:m,targetCoinType:b,slippage:S,claimRoutes:I,pools:x}=s,D=new gd.Transaction;return await Promise.all(i.claimParams.map(k=>Km({...k,sdk:n,txb:D}))),await ud(n,o,c,m,D,b,S,I,x),D}static fromData(t){return new a(t)}};var yd=require("@mmt-finance/clmm-sdk"),bd=require("@mysten/sui/transactions");var _r=class a extends w{constructor(t){super(t);this.data=t}data;txType;txSubType;async build(){let t=yd.MmtSDK.NEW({network:"mainnet"}),{params:n}=this.data,{address:o,position:i,pool:s}=n,c=new bd.Transaction;return Ke(t,o,i,s,c),c}static fromData(t){return new a(t)}};var Td=require("@mmt-finance/clmm-sdk"),Sd=require("@mysten/sui/transactions");var Lr=class a extends w{constructor(t){super(t);this.data=t}data;txType;txSubType;async build(){let t=Td.MmtSDK.NEW({network:"mainnet"}),{params:n}=this.data,{address:o,amountA:i,amountB:s,pool:c,positionObjectId:m,slippage:b}=n,S=new Sd.Transaction;return await Qm(t,S,o,i,s,c,m,b),S}static fromData(t){return new a(t)}};var wd=require("@mmt-finance/clmm-sdk"),Id=require("@mysten/sui/transactions");var jr=class a extends w{constructor(t){super(t);this.data=t}data;txType;txSubType;async build(){let t=wd.MmtSDK.NEW({network:"mainnet"}),{params:n}=this.data,{address:o,amount:i,isTokenX:s,pool:c,positionObjectId:m,swapSlippage:b,addLiquiditySlippage:S}=n,I=new Id.Transaction;return await Jm(t,I,o,i,s,c,m,b,S),I}static fromData(t){return new a(t)}};var Cd=require("@mmt-finance/clmm-sdk"),xd=require("@mysten/sui/transactions");var Ur=class a extends w{constructor(t){super(t);this.data=t}data;txType;txSubType;async build(){let t=Cd.MmtSDK.NEW({network:"mainnet"}),{params:n}=this.data,{pool:o,position:i,address:s,withdrawPercentage:c,zapOutOn:m,targetCoinType:b,slippage:S}=n,I=new xd.Transaction;return m?await td({sdk:t,address:s,position:i,pool:o,withdrawPercentage:c,txb:I,targetCoinType:b,slippage:S}):await Zm(t,s,i,o,c,I),I}static fromData(t){return new a(t)}};var sc=require("@mysten/sui/transactions"),cc=require("@suilend/springsui-sdk"),rc={id:"0x0431232199873db77a92aa645cd43521437e9cc5c6fff07fd03edb88afe0b25a",type:"0x2b6602099970374cf58a2a1b9d96f005fccceb81e92eb059873baf420eb6c717::x_sui::X_SUI",weightHookId:"0x9e35c13dbb0bc437e8ad5a95ec463622f58763e060552ae8d100db77f4904601"},Dd=async(a,e,t)=>{let n=await cc.LstClient.initialize(a,rc),o=new sc.Transaction,[i]=o.splitCoins(o.gas,[BigInt(t)]),s=n.mint(o,i);return o.transferObjects([s],e),o},kd=async(a,e,t)=>{let n=await cc.LstClient.initialize(a,rc),o=await a.getCoins({owner:e,coinType:rc.type,limit:1e3});if(o.data.length===0)throw new Error("No lst coins found");let i=new sc.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)]),m=n.redeem(i,c);return i.transferObjects([m],e),i};var qr=class a extends w{constructor(t){super(t);this.data=t}data;txType;txSubType;async build(t){let{params:n}=this.data,{address:o,amount:i}=n;return await Dd(t.suiClient,o,i)}static fromData(t){return new a(t)}};var Md=require("@mmt-finance/clmm-sdk"),Od=require("@mysten/sui/transactions");var vd=require("@mmt-finance/clmm-sdk/dist/utils/poolUtils");var Ad=async(a,e,t,n,o,i,s)=>{let c=await ie({mmt:a,tx:i,address:o,coinType:t.coinType,coinAmount:n,coinDecimals:t.decimals}),m=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:I,tokenX:x,tokenY:D,isStable:k,currentSqrtPrice:M}=e[S],{id:L,isReverse:U}=vd.mappedMmtV3Pool[I]||{id:I,isReverse:!1},q=_t(x.coinType)===_t(b);q=U?!q:q;let Pt=U?D.coinType:x.coinType,W=U?x.coinType:D.coinType,Ge=await $e({poolId:L,tokenX:x,tokenY:D,slippagePercentage:s,isTokenX:q,suiClient:a.rpcClient,currentSqrtPrice:M}),Nt=a.Pool.swap(i,{objectId:L,tokenXType:Pt,tokenYType:W,isStable:k},m,c,q,void 0,Ge,!1);i.transferObjects([c],i.pure.address(o)),c=Nt,b=q?W:Pt,m=i.moveCall({target:"0x2::coin::value",typeArguments:[b],arguments:[c]})}i.transferObjects([c],i.pure.address(o))};var Fr=class a extends w{constructor(t){super(t);this.data=t}data;txType;txSubType;async build(){let t=Md.MmtSDK.NEW({network:"mainnet"}),{params:n}=this.data,{route:o,tokenIn:i,amountIn:s,address:c,slippage:m}=n,b=new Od.Transaction;return await Ad(t,o,i,s,c,b,m),b}static fromData(t){return new a(t)}};var Kr=class a extends w{constructor(t){super(t);this.data=t}data;txType;txSubType;async build(t){let{params:n}=this.data,{address:o,amount:i}=n;return await kd(t.suiClient,o,i)}static fromData(t){return new a(t)}};var Pd=require("@mmt-finance/clmm-sdk"),Rd=require("@mmt-finance/ve-sdk-v1"),Bd=require("@mysten/sui/transactions");var Vr=class a extends w{constructor(t){super(t);this.data=t}data;txType;txSubType;async build(t){let n=Pd.MmtSDK.NEW({network:"mainnet"}),o=new Rd.VeMMT(t.suiClient,"mainnet"),{params:i}=this.data,{token:s,amount:c,address:m,enableAutoMaxBond:b,unbondAt:S}=i,I=new Bd.Transaction;return await id(n,o,s,c,m,b,S,I),I}static fromData(t){return new a(t)}};var Ed=require("@mmt-finance/ve-sdk-v1"),Nd=require("@mysten/sui/transactions");var $r=class a extends w{constructor(t){super(t);this.data=t}data;txType;txSubType;async build(t){let n=new Ed.VeMMT(t.suiClient,"mainnet"),{params:o}=this.data,{address:i,veId:s,currentUnbondAt:c,isCurrentlyMaxBond:m,enableAutoMaxBond:b,unbondAt:S}=o,I=new Nd.Transaction;return await rd(n,i,s,c,m,b,S,I),I}static fromData(t){return new a(t)}};var Wd=require("@mmt-finance/ve-sdk-v1"),_d=require("@mysten/sui/transactions");var Gr=class a extends w{constructor(t){super(t);this.data=t}data;txType;txSubType;async build(t){let n=new Wd.VeMMT(t.suiClient,"mainnet"),{params:o}=this.data,{address:i,veId:s,selectedVeMMTIds:c}=o,m=new _d.Transaction;return await sd(n,i,s,c,m),m}static fromData(t){return new a(t)}};var Ld=require("@mmt-finance/ve-sdk-v1"),jd=require("@mysten/sui/transactions");var Hr=class a extends w{constructor(t){super(t);this.data=t}data;txType;txSubType;async build(t){let n=new Ld.VeMMT(t.suiClient,"mainnet"),{params:o}=this.data,{address:i,veId:s}=o,c=new jd.Transaction;return await cd(n,i,s,c),c}static fromData(t){return new a(t)}};var Xr=class{application="mmt-dex";supportSDK="@mysten/sui";async deserialize(e){let{appContext:t}=e;return{txType:Ud.TransactionType.Other,txSubType:t.action,intentionData:t}}async build(e){let t;switch(e.txSubType){case"Swap":t=Fr.fromData(e.intentionData);break;case"AddLiquidity":t=Br.fromData(e.intentionData);break;case"AddLiquiditySingleSide":t=Er.fromData(e.intentionData);break;case"ClaimRewards":t=_r.fromData(e.intentionData);break;case"ClaimAllRewards":t=Nr.fromData(e.intentionData);break;case"ClaimRewardsAs":t=Wr.fromData(e.intentionData);break;case"RemoveLiquidity":t=Ur.fromData(e.intentionData);break;case"StakeXSui":t=qr.fromData(e.intentionData);break;case"UnstakeXSui":t=Kr.fromData(e.intentionData);break;case"ManageLiquidity":t=Lr.fromData(e.intentionData);break;case"ManageLiquiditySingleSide":t=jr.fromData(e.intentionData);break;case"Bond":t=Vr.fromData(e.intentionData);break;case"Extend":t=$r.fromData(e.intentionData);break;case"Merge":t=Gr.fromData(e.intentionData);break;case"Unbond":t=Hr.fromData(e.intentionData);break;default:throw new Error(`not implemented ${e.txSubType}`)}return t.build({suiClient:e.suiClient})}};var sh=Ha.fromHelpers([new Pa,new Ka,new Aa,new Va,new na,new fr,new Xr,new Ai,new Sr,new Mo,new Li,new Hi,new co,new Pr,new Ji]);
|
|
2
2
|
//# sourceMappingURL=index.js.map
|