@lightprotocol/compressed-token 0.23.0-beta.10 → 0.23.0-beta.11

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.
@@ -1,2 +1,2 @@
1
- "use strict";var t=require("@solana/web3.js"),e=require("@lightprotocol/stateless.js"),n=require("@solana/spl-token"),r=require("@coral-xyz/borsh"),o="undefined"!=typeof global?global:"undefined"!=typeof self?self:"undefined"!=typeof window?window:{},i=[],s=[],a="undefined"!=typeof Uint8Array?Uint8Array:Array,u=0;function c(){u=1;for(var t="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/",e=0;e<64;++e)i[e]=t[e],s[t.charCodeAt(e)]=e;s["-".charCodeAt(0)]=62,s["_".charCodeAt(0)]=63}function l(t,e,n){for(var r,o,s=[],a=e;a<n;a+=3)r=(t[a]<<16)+(t[a+1]<<8)+t[a+2],s.push(i[(o=r)>>18&63]+i[o>>12&63]+i[o>>6&63]+i[63&o]);return s.join("")}function d(t){var e;u||c();for(var n=t.length,r=n%3,o="",s=[],a=16383,d=0,p=n-r;d<p;d+=a)s.push(l(t,d,d+a>p?p:d+a));return 1===r?(e=t[n-1],o+=i[e>>2],o+=i[e<<4&63],o+="=="):2===r&&(e=(t[n-2]<<8)+t[n-1],o+=i[e>>10],o+=i[e>>4&63],o+=i[e<<2&63],o+="="),s.push(o),s.join("")}function p(t,e,n,r,o){var i,s,a=8*o-r-1,u=(1<<a)-1,c=u>>1,l=-7,d=n?o-1:0,p=n?-1:1,m=t[e+d];for(d+=p,i=m&(1<<-l)-1,m>>=-l,l+=a;l>0;i=256*i+t[e+d],d+=p,l-=8);for(s=i&(1<<-l)-1,i>>=-l,l+=r;l>0;s=256*s+t[e+d],d+=p,l-=8);if(0===i)i=1-c;else{if(i===u)return s?NaN:Infinity*(m?-1:1);s+=Math.pow(2,r),i-=c}return(m?-1:1)*s*Math.pow(2,i-r)}function m(t,e,n,r,o,i){var s,a,u,c=8*i-o-1,l=(1<<c)-1,d=l>>1,p=23===o?Math.pow(2,-24)-Math.pow(2,-77):0,m=r?0:i-1,h=r?1:-1,f=e<0||0===e&&1/e<0?1:0;for(e=Math.abs(e),isNaN(e)||Infinity===e?(a=isNaN(e)?1:0,s=l):(s=Math.floor(Math.log(e)/Math.LN2),e*(u=Math.pow(2,-s))<1&&(s--,u*=2),(e+=s+d>=1?p/u:p*Math.pow(2,1-d))*u>=2&&(s++,u/=2),s+d>=l?(a=0,s=l):s+d>=1?(a=(e*u-1)*Math.pow(2,o),s+=d):(a=e*Math.pow(2,d-1)*Math.pow(2,o),s=0));o>=8;t[n+m]=255&a,m+=h,a/=256,o-=8);for(s=s<<o|a,c+=o;c>0;t[n+m]=255&s,m+=h,s/=256,c-=8);t[n+m-h]|=128*f}var h={}.toString,f=Array.isArray||function(t){return"[object Array]"==h.call(t)};w.TYPED_ARRAY_SUPPORT=void 0!==o.TYPED_ARRAY_SUPPORT?o.TYPED_ARRAY_SUPPORT:1;var g=y();function y(){return w.TYPED_ARRAY_SUPPORT?2147483647:1073741823}function b(t,e){if(y()<e)throw new RangeError("Invalid typed array length");return w.TYPED_ARRAY_SUPPORT?(t=new Uint8Array(e)).__proto__=w.prototype:(null===t&&(t=new w(e)),t.length=e),t}function w(t,e,n){if(!(w.TYPED_ARRAY_SUPPORT||this instanceof w))return new w(t,e,n);if("number"==typeof t){if("string"==typeof e)throw new Error("If encoding is specified then the first argument must be a string");return A(this,t)}return I(this,t,e,n)}function I(t,e,n,r){if("number"==typeof e)throw new TypeError('"value" argument must not be a number');return"undefined"!=typeof ArrayBuffer&&e instanceof ArrayBuffer?function(t,e,n,r){if(e.byteLength,n<0||e.byteLength<n)throw new RangeError("'offset' is out of bounds");if(e.byteLength<n+(r||0))throw new RangeError("'length' is out of bounds");return e=void 0===n&&void 0===r?new Uint8Array(e):void 0===r?new Uint8Array(e,n):new Uint8Array(e,n,r),w.TYPED_ARRAY_SUPPORT?(t=e).__proto__=w.prototype:t=T(t,e),t}(t,e,n,r):"string"==typeof e?function(t,e,n){if("string"==typeof n&&""!==n||(n="utf8"),!w.isEncoding(n))throw new TypeError('"encoding" must be a valid string encoding');var r=0|M(e,n),o=(t=b(t,r)).write(e,n);return o!==r&&(t=t.slice(0,o)),t}(t,e,n):function(t,e){if(P(e)){var n=0|k(e.length);return 0===(t=b(t,n)).length||e.copy(t,0,0,n),t}if(e){if("undefined"!=typeof ArrayBuffer&&e.buffer instanceof ArrayBuffer||"length"in e)return"number"!=typeof e.length||(r=e.length)!=r?b(t,0):T(t,e);if("Buffer"===e.type&&f(e.data))return T(t,e.data)}var r;throw new TypeError("First argument must be a string, Buffer, ArrayBuffer, Array, or array-like object.")}(t,e)}function v(t){if("number"!=typeof t)throw new TypeError('"size" argument must be a number');if(t<0)throw new RangeError('"size" argument must not be negative')}function A(t,e){if(v(e),t=b(t,e<0?0:0|k(e)),!w.TYPED_ARRAY_SUPPORT)for(var n=0;n<e;++n)t[n]=0;return t}function T(t,e){var n=e.length<0?0:0|k(e.length);t=b(t,n);for(var r=0;r<n;r+=1)t[r]=255&e[r];return t}function k(t){if(t>=y())throw new RangeError("Attempt to allocate Buffer larger than maximum size: 0x"+y().toString(16)+" bytes");return 0|t}function P(t){return!(null==t||!t._isBuffer)}function M(t,e){if(P(t))return t.length;if("undefined"!=typeof ArrayBuffer&&"function"==typeof ArrayBuffer.isView&&(ArrayBuffer.isView(t)||t instanceof ArrayBuffer))return t.byteLength;"string"!=typeof t&&(t=""+t);var n=t.length;if(0===n)return 0;for(var r=0;;)switch(e){case"ascii":case"latin1":case"binary":return n;case"utf8":case"utf-8":case void 0:return X(t).length;case"ucs2":case"ucs-2":case"utf16le":case"utf-16le":return 2*n;case"hex":return n>>>1;case"base64":return J(t).length;default:if(r)return X(t).length;e=(""+e).toLowerCase(),r=1}}function S(t,e,n){var r=0;if((void 0===e||e<0)&&(e=0),e>this.length)return"";if((void 0===n||n>this.length)&&(n=this.length),n<=0)return"";if((n>>>=0)<=(e>>>=0))return"";for(t||(t="utf8");;)switch(t){case"hex":return q(this,e,n);case"utf8":case"utf-8":return U(this,e,n);case"ascii":return W(this,e,n);case"latin1":case"binary":return G(this,e,n);case"base64":return K(this,e,n);case"ucs2":case"ucs-2":case"utf16le":case"utf-16le":return F(this,e,n);default:if(r)throw new TypeError("Unknown encoding: "+t);t=(t+"").toLowerCase(),r=1}}function x(t,e,n){var r=t[e];t[e]=t[n],t[n]=r}function C(t,e,n,r,o){if(0===t.length)return-1;if("string"==typeof n?(r=n,n=0):n>2147483647?n=2147483647:n<-2147483648&&(n=-2147483648),n=+n,isNaN(n)&&(n=o?0:t.length-1),n<0&&(n=t.length+n),n>=t.length){if(o)return-1;n=t.length-1}else if(n<0){if(!o)return-1;n=0}if("string"==typeof e&&(e=w.from(e,r)),P(e))return 0===e.length?-1:E(t,e,n,r,o);if("number"==typeof e)return e&=255,w.TYPED_ARRAY_SUPPORT&&"function"==typeof Uint8Array.prototype.indexOf?o?Uint8Array.prototype.indexOf.call(t,e,n):Uint8Array.prototype.lastIndexOf.call(t,e,n):E(t,[e],n,r,o);throw new TypeError("val must be string, number or Buffer")}function E(t,e,n,r,o){var i,s=1,a=t.length,u=e.length;if(void 0!==r&&("ucs2"===(r=String(r).toLowerCase())||"ucs-2"===r||"utf16le"===r||"utf-16le"===r)){if(t.length<2||e.length<2)return-1;s=2,a/=2,u/=2,n/=2}function c(t,e){return 1===s?t[e]:t.readUInt16BE(e*s)}if(o){var l=-1;for(i=n;i<a;i++)if(c(t,i)===c(e,-1===l?0:i-l)){if(-1===l&&(l=i),i-l+1===u)return l*s}else-1!==l&&(i-=i-l),l=-1}else for(n+u>a&&(n=a-u),i=n;i>=0;i--){for(var d=1,p=0;p<u;p++)if(c(t,i+p)!==c(e,p)){d=0;break}if(d)return i}return-1}function _(t,e,n,r){n=Number(n)||0;var o=t.length-n;r?(r=Number(r))>o&&(r=o):r=o;var i=e.length;if(i%2!=0)throw new TypeError("Invalid hex string");r>i/2&&(r=i/2);for(var s=0;s<r;++s){var a=parseInt(e.substr(2*s,2),16);if(isNaN(a))return s;t[n+s]=a}return s}function O(t,e,n,r){return tt(X(e,t.length-n),t,n,r)}function R(t,e,n,r){return tt(function(t){for(var e=[],n=0;n<t.length;++n)e.push(255&t.charCodeAt(n));return e}(e),t,n,r)}function B(t,e,n,r){return R(t,e,n,r)}function L(t,e,n,r){return tt(J(e),t,n,r)}function D(t,e,n,r){return tt(function(t,e){for(var n,r,o,i=[],s=0;s<t.length&&!((e-=2)<0);++s)r=(n=t.charCodeAt(s))>>8,o=n%256,i.push(o),i.push(r);return i}(e,t.length-n),t,n,r)}function K(t,e,n){return 0===e&&n===t.length?d(t):d(t.slice(e,n))}function U(t,e,n){n=Math.min(t.length,n);for(var r=[],o=e;o<n;){var i,s,a,u,c=t[o],l=null,d=c>239?4:c>223?3:c>191?2:1;if(o+d<=n)switch(d){case 1:c<128&&(l=c);break;case 2:128==(192&(i=t[o+1]))&&(u=(31&c)<<6|63&i)>127&&(l=u);break;case 3:i=t[o+1],s=t[o+2],128==(192&i)&&128==(192&s)&&(u=(15&c)<<12|(63&i)<<6|63&s)>2047&&(u<55296||u>57343)&&(l=u);break;case 4:i=t[o+1],s=t[o+2],a=t[o+3],128==(192&i)&&128==(192&s)&&128==(192&a)&&(u=(15&c)<<18|(63&i)<<12|(63&s)<<6|63&a)>65535&&u<1114112&&(l=u)}null===l?(l=65533,d=1):l>65535&&(l-=65536,r.push(l>>>10&1023|55296),l=56320|1023&l),r.push(l),o+=d}return function(t){var e=t.length;if(e<=N)return String.fromCharCode.apply(String,t);for(var n="",r=0;r<e;)n+=String.fromCharCode.apply(String,t.slice(r,r+=N));return n}(r)}w.poolSize=8192,w._augment=function(t){return t.__proto__=w.prototype,t},w.from=function(t,e,n){return I(null,t,e,n)},w.TYPED_ARRAY_SUPPORT&&(w.prototype.__proto__=Uint8Array.prototype,w.__proto__=Uint8Array,"undefined"!=typeof Symbol&&Symbol.species&&w[Symbol.species]),w.alloc=function(t,e,n){return function(t,e,n,r){return v(e),e<=0?b(t,e):void 0!==n?"string"==typeof r?b(t,e).fill(n,r):b(t,e).fill(n):b(t,e)}(null,t,e,n)},w.allocUnsafe=function(t){return A(null,t)},w.allocUnsafeSlow=function(t){return A(null,t)},w.isBuffer=et,w.compare=function(t,e){if(!P(t)||!P(e))throw new TypeError("Arguments must be Buffers");if(t===e)return 0;for(var n=t.length,r=e.length,o=0,i=Math.min(n,r);o<i;++o)if(t[o]!==e[o]){n=t[o],r=e[o];break}return n<r?-1:r<n?1:0},w.isEncoding=function(t){switch(String(t).toLowerCase()){case"hex":case"utf8":case"utf-8":case"ascii":case"latin1":case"binary":case"base64":case"ucs2":case"ucs-2":case"utf16le":case"utf-16le":return 1;default:return 0}},w.concat=function(t,e){if(!f(t))throw new TypeError('"list" argument must be an Array of Buffers');if(0===t.length)return w.alloc(0);var n;if(void 0===e)for(e=0,n=0;n<t.length;++n)e+=t[n].length;var r=w.allocUnsafe(e),o=0;for(n=0;n<t.length;++n){var i=t[n];if(!P(i))throw new TypeError('"list" argument must be an Array of Buffers');i.copy(r,o),o+=i.length}return r},w.byteLength=M,w.prototype._isBuffer=1,w.prototype.swap16=function(){var t=this.length;if(t%2!=0)throw new RangeError("Buffer size must be a multiple of 16-bits");for(var e=0;e<t;e+=2)x(this,e,e+1);return this},w.prototype.swap32=function(){var t=this.length;if(t%4!=0)throw new RangeError("Buffer size must be a multiple of 32-bits");for(var e=0;e<t;e+=4)x(this,e,e+3),x(this,e+1,e+2);return this},w.prototype.swap64=function(){var t=this.length;if(t%8!=0)throw new RangeError("Buffer size must be a multiple of 64-bits");for(var e=0;e<t;e+=8)x(this,e,e+7),x(this,e+1,e+6),x(this,e+2,e+5),x(this,e+3,e+4);return this},w.prototype.toString=function(){var t=0|this.length;return 0===t?"":0===arguments.length?U(this,0,t):S.apply(this,arguments)},w.prototype.equals=function(t){if(!P(t))throw new TypeError("Argument must be a Buffer");return this===t?1:0===w.compare(this,t)},w.prototype.inspect=function(){var t="";return this.length>0&&(t=this.toString("hex",0,50).match(/.{2}/g).join(" "),this.length>50&&(t+=" ... ")),"<Buffer "+t+">"},w.prototype.compare=function(t,e,n,r,o){if(!P(t))throw new TypeError("Argument must be a Buffer");if(void 0===e&&(e=0),void 0===n&&(n=t?t.length:0),void 0===r&&(r=0),void 0===o&&(o=this.length),e<0||n>t.length||r<0||o>this.length)throw new RangeError("out of range index");if(r>=o&&e>=n)return 0;if(r>=o)return-1;if(e>=n)return 1;if(this===t)return 0;for(var i=(o>>>=0)-(r>>>=0),s=(n>>>=0)-(e>>>=0),a=Math.min(i,s),u=this.slice(r,o),c=t.slice(e,n),l=0;l<a;++l)if(u[l]!==c[l]){i=u[l],s=c[l];break}return i<s?-1:s<i?1:0},w.prototype.includes=function(t,e,n){return-1!==this.indexOf(t,e,n)},w.prototype.indexOf=function(t,e,n){return C(this,t,e,n,1)},w.prototype.lastIndexOf=function(t,e,n){return C(this,t,e,n,0)},w.prototype.write=function(t,e,n,r){if(void 0===e)r="utf8",n=this.length,e=0;else if(void 0===n&&"string"==typeof e)r=e,n=this.length,e=0;else{if(!isFinite(e))throw new Error("Buffer.write(string, encoding, offset[, length]) is no longer supported");e|=0,isFinite(n)?(n|=0,void 0===r&&(r="utf8")):(r=n,n=void 0)}var o=this.length-e;if((void 0===n||n>o)&&(n=o),t.length>0&&(n<0||e<0)||e>this.length)throw new RangeError("Attempt to write outside buffer bounds");r||(r="utf8");for(var i=0;;)switch(r){case"hex":return _(this,t,e,n);case"utf8":case"utf-8":return O(this,t,e,n);case"ascii":return R(this,t,e,n);case"latin1":case"binary":return B(this,t,e,n);case"base64":return L(this,t,e,n);case"ucs2":case"ucs-2":case"utf16le":case"utf-16le":return D(this,t,e,n);default:if(i)throw new TypeError("Unknown encoding: "+r);r=(""+r).toLowerCase(),i=1}},w.prototype.toJSON=function(){return{type:"Buffer",data:Array.prototype.slice.call(this._arr||this,0)}};var N=4096;function W(t,e,n){var r="";n=Math.min(t.length,n);for(var o=e;o<n;++o)r+=String.fromCharCode(127&t[o]);return r}function G(t,e,n){var r="";n=Math.min(t.length,n);for(var o=e;o<n;++o)r+=String.fromCharCode(t[o]);return r}function q(t,e,n){var r,o=t.length;(!e||e<0)&&(e=0),(!n||n<0||n>o)&&(n=o);for(var i="",s=e;s<n;++s)i+=(r=t[s])<16?"0"+r.toString(16):r.toString(16);return i}function F(t,e,n){for(var r=t.slice(e,n),o="",i=0;i<r.length;i+=2)o+=String.fromCharCode(r[i]+256*r[i+1]);return o}function V(t,e,n){if(t%1!=0||t<0)throw new RangeError("offset is not uint");if(t+e>n)throw new RangeError("Trying to access beyond buffer length")}function H(t,e,n,r,o,i){if(!P(t))throw new TypeError('"buffer" argument must be a Buffer instance');if(e>o||e<i)throw new RangeError('"value" argument is out of bounds');if(n+r>t.length)throw new RangeError("Index out of range")}function z(t,e,n,r){e<0&&(e=65535+e+1);for(var o=0,i=Math.min(t.length-n,2);o<i;++o)t[n+o]=(e&255<<8*(r?o:1-o))>>>8*(r?o:1-o)}function j(t,e,n,r){e<0&&(e=4294967295+e+1);for(var o=0,i=Math.min(t.length-n,4);o<i;++o)t[n+o]=e>>>8*(r?o:3-o)&255}function $(t,e,n,r){if(n+r>t.length)throw new RangeError("Index out of range");if(n<0)throw new RangeError("Index out of range")}function Y(t,e,n,r,o){return o||$(t,0,n,4),m(t,e,n,r,23,4),n+4}function Z(t,e,n,r,o){return o||$(t,0,n,8),m(t,e,n,r,52,8),n+8}w.prototype.slice=function(t,e){var n,r=this.length;if((t=~~t)<0?(t+=r)<0&&(t=0):t>r&&(t=r),(e=void 0===e?r:~~e)<0?(e+=r)<0&&(e=0):e>r&&(e=r),e<t&&(e=t),w.TYPED_ARRAY_SUPPORT)(n=this.subarray(t,e)).__proto__=w.prototype;else{var o=e-t;n=new w(o,void 0);for(var i=0;i<o;++i)n[i]=this[i+t]}return n},w.prototype.readUIntLE=function(t,e,n){t|=0,e|=0,n||V(t,e,this.length);for(var r=this[t],o=1,i=0;++i<e&&(o*=256);)r+=this[t+i]*o;return r},w.prototype.readUIntBE=function(t,e,n){t|=0,e|=0,n||V(t,e,this.length);for(var r=this[t+--e],o=1;e>0&&(o*=256);)r+=this[t+--e]*o;return r},w.prototype.readUInt8=function(t,e){return e||V(t,1,this.length),this[t]},w.prototype.readUInt16LE=function(t,e){return e||V(t,2,this.length),this[t]|this[t+1]<<8},w.prototype.readUInt16BE=function(t,e){return e||V(t,2,this.length),this[t]<<8|this[t+1]},w.prototype.readUInt32LE=function(t,e){return e||V(t,4,this.length),(this[t]|this[t+1]<<8|this[t+2]<<16)+16777216*this[t+3]},w.prototype.readUInt32BE=function(t,e){return e||V(t,4,this.length),16777216*this[t]+(this[t+1]<<16|this[t+2]<<8|this[t+3])},w.prototype.readIntLE=function(t,e,n){t|=0,e|=0,n||V(t,e,this.length);for(var r=this[t],o=1,i=0;++i<e&&(o*=256);)r+=this[t+i]*o;return r>=(o*=128)&&(r-=Math.pow(2,8*e)),r},w.prototype.readIntBE=function(t,e,n){t|=0,e|=0,n||V(t,e,this.length);for(var r=e,o=1,i=this[t+--r];r>0&&(o*=256);)i+=this[t+--r]*o;return i>=(o*=128)&&(i-=Math.pow(2,8*e)),i},w.prototype.readInt8=function(t,e){return e||V(t,1,this.length),128&this[t]?-1*(255-this[t]+1):this[t]},w.prototype.readInt16LE=function(t,e){e||V(t,2,this.length);var n=this[t]|this[t+1]<<8;return 32768&n?4294901760|n:n},w.prototype.readInt16BE=function(t,e){e||V(t,2,this.length);var n=this[t+1]|this[t]<<8;return 32768&n?4294901760|n:n},w.prototype.readInt32LE=function(t,e){return e||V(t,4,this.length),this[t]|this[t+1]<<8|this[t+2]<<16|this[t+3]<<24},w.prototype.readInt32BE=function(t,e){return e||V(t,4,this.length),this[t]<<24|this[t+1]<<16|this[t+2]<<8|this[t+3]},w.prototype.readFloatLE=function(t,e){return e||V(t,4,this.length),p(this,t,1,23,4)},w.prototype.readFloatBE=function(t,e){return e||V(t,4,this.length),p(this,t,0,23,4)},w.prototype.readDoubleLE=function(t,e){return e||V(t,8,this.length),p(this,t,1,52,8)},w.prototype.readDoubleBE=function(t,e){return e||V(t,8,this.length),p(this,t,0,52,8)},w.prototype.writeUIntLE=function(t,e,n,r){t=+t,e|=0,n|=0,r||H(this,t,e,n,Math.pow(2,8*n)-1,0);var o=1,i=0;for(this[e]=255&t;++i<n&&(o*=256);)this[e+i]=t/o&255;return e+n},w.prototype.writeUIntBE=function(t,e,n,r){t=+t,e|=0,n|=0,r||H(this,t,e,n,Math.pow(2,8*n)-1,0);var o=n-1,i=1;for(this[e+o]=255&t;--o>=0&&(i*=256);)this[e+o]=t/i&255;return e+n},w.prototype.writeUInt8=function(t,e,n){return t=+t,e|=0,n||H(this,t,e,1,255,0),w.TYPED_ARRAY_SUPPORT||(t=Math.floor(t)),this[e]=255&t,e+1},w.prototype.writeUInt16LE=function(t,e,n){return t=+t,e|=0,n||H(this,t,e,2,65535,0),w.TYPED_ARRAY_SUPPORT?(this[e]=255&t,this[e+1]=t>>>8):z(this,t,e,1),e+2},w.prototype.writeUInt16BE=function(t,e,n){return t=+t,e|=0,n||H(this,t,e,2,65535,0),w.TYPED_ARRAY_SUPPORT?(this[e]=t>>>8,this[e+1]=255&t):z(this,t,e,0),e+2},w.prototype.writeUInt32LE=function(t,e,n){return t=+t,e|=0,n||H(this,t,e,4,4294967295,0),w.TYPED_ARRAY_SUPPORT?(this[e+3]=t>>>24,this[e+2]=t>>>16,this[e+1]=t>>>8,this[e]=255&t):j(this,t,e,1),e+4},w.prototype.writeUInt32BE=function(t,e,n){return t=+t,e|=0,n||H(this,t,e,4,4294967295,0),w.TYPED_ARRAY_SUPPORT?(this[e]=t>>>24,this[e+1]=t>>>16,this[e+2]=t>>>8,this[e+3]=255&t):j(this,t,e,0),e+4},w.prototype.writeIntLE=function(t,e,n,r){if(t=+t,e|=0,!r){var o=Math.pow(2,8*n-1);H(this,t,e,n,o-1,-o)}var i=0,s=1,a=0;for(this[e]=255&t;++i<n&&(s*=256);)t<0&&0===a&&0!==this[e+i-1]&&(a=1),this[e+i]=(t/s>>0)-a&255;return e+n},w.prototype.writeIntBE=function(t,e,n,r){if(t=+t,e|=0,!r){var o=Math.pow(2,8*n-1);H(this,t,e,n,o-1,-o)}var i=n-1,s=1,a=0;for(this[e+i]=255&t;--i>=0&&(s*=256);)t<0&&0===a&&0!==this[e+i+1]&&(a=1),this[e+i]=(t/s>>0)-a&255;return e+n},w.prototype.writeInt8=function(t,e,n){return t=+t,e|=0,n||H(this,t,e,1,127,-128),w.TYPED_ARRAY_SUPPORT||(t=Math.floor(t)),t<0&&(t=255+t+1),this[e]=255&t,e+1},w.prototype.writeInt16LE=function(t,e,n){return t=+t,e|=0,n||H(this,t,e,2,32767,-32768),w.TYPED_ARRAY_SUPPORT?(this[e]=255&t,this[e+1]=t>>>8):z(this,t,e,1),e+2},w.prototype.writeInt16BE=function(t,e,n){return t=+t,e|=0,n||H(this,t,e,2,32767,-32768),w.TYPED_ARRAY_SUPPORT?(this[e]=t>>>8,this[e+1]=255&t):z(this,t,e,0),e+2},w.prototype.writeInt32LE=function(t,e,n){return t=+t,e|=0,n||H(this,t,e,4,2147483647,-2147483648),w.TYPED_ARRAY_SUPPORT?(this[e]=255&t,this[e+1]=t>>>8,this[e+2]=t>>>16,this[e+3]=t>>>24):j(this,t,e,1),e+4},w.prototype.writeInt32BE=function(t,e,n){return t=+t,e|=0,n||H(this,t,e,4,2147483647,-2147483648),t<0&&(t=4294967295+t+1),w.TYPED_ARRAY_SUPPORT?(this[e]=t>>>24,this[e+1]=t>>>16,this[e+2]=t>>>8,this[e+3]=255&t):j(this,t,e,0),e+4},w.prototype.writeFloatLE=function(t,e,n){return Y(this,t,e,1,n)},w.prototype.writeFloatBE=function(t,e,n){return Y(this,t,e,0,n)},w.prototype.writeDoubleLE=function(t,e,n){return Z(this,t,e,1,n)},w.prototype.writeDoubleBE=function(t,e,n){return Z(this,t,e,0,n)},w.prototype.copy=function(t,e,n,r){if(n||(n=0),r||0===r||(r=this.length),e>=t.length&&(e=t.length),e||(e=0),r>0&&r<n&&(r=n),r===n)return 0;if(0===t.length||0===this.length)return 0;if(e<0)throw new RangeError("targetStart out of bounds");if(n<0||n>=this.length)throw new RangeError("sourceStart out of bounds");if(r<0)throw new RangeError("sourceEnd out of bounds");r>this.length&&(r=this.length),t.length-e<r-n&&(r=t.length-e+n);var o,i=r-n;if(this===t&&n<e&&e<r)for(o=i-1;o>=0;--o)t[o+e]=this[o+n];else if(i<1e3||!w.TYPED_ARRAY_SUPPORT)for(o=0;o<i;++o)t[o+e]=this[o+n];else Uint8Array.prototype.set.call(t,this.subarray(n,n+i),e);return i},w.prototype.fill=function(t,e,n,r){if("string"==typeof t){if("string"==typeof e?(r=e,e=0,n=this.length):"string"==typeof n&&(r=n,n=this.length),1===t.length){var o=t.charCodeAt(0);o<256&&(t=o)}if(void 0!==r&&"string"!=typeof r)throw new TypeError("encoding must be a string");if("string"==typeof r&&!w.isEncoding(r))throw new TypeError("Unknown encoding: "+r)}else"number"==typeof t&&(t&=255);if(e<0||this.length<e||this.length<n)throw new RangeError("Out of range index");if(n<=e)return this;var i;if(e>>>=0,n=void 0===n?this.length:n>>>0,t||(t=0),"number"==typeof t)for(i=e;i<n;++i)this[i]=t;else{var s=P(t)?t:X(new w(t,r).toString()),a=s.length;for(i=0;i<n-e;++i)this[i+e]=s[i%a]}return this};var Q=/[^+\/0-9A-Za-z-_]/g;function X(t,e){var n;e=e||Infinity;for(var r=t.length,o=null,i=[],s=0;s<r;++s){if((n=t.charCodeAt(s))>55295&&n<57344){if(!o){if(n>56319){(e-=3)>-1&&i.push(239,191,189);continue}if(s+1===r){(e-=3)>-1&&i.push(239,191,189);continue}o=n;continue}if(n<56320){(e-=3)>-1&&i.push(239,191,189),o=n;continue}n=65536+(o-55296<<10|n-56320)}else o&&(e-=3)>-1&&i.push(239,191,189);if(o=null,n<128){if((e-=1)<0)break;i.push(n)}else if(n<2048){if((e-=2)<0)break;i.push(n>>6|192,63&n|128)}else if(n<65536){if((e-=3)<0)break;i.push(n>>12|224,n>>6&63|128,63&n|128)}else{if(!(n<1114112))throw new Error("Invalid code point");if((e-=4)<0)break;i.push(n>>18|240,n>>12&63|128,n>>6&63|128,63&n|128)}}return i}function J(t){return function(t){var e,n,r,o,i,l;u||c();var d=t.length;if(d%4>0)throw new Error("Invalid string. Length must be a multiple of 4");i="="===t[d-2]?2:"="===t[d-1]?1:0,l=new a(3*d/4-i),r=i>0?d-4:d;var p=0;for(e=0,n=0;e<r;e+=4,n+=3)o=s[t.charCodeAt(e)]<<18|s[t.charCodeAt(e+1)]<<12|s[t.charCodeAt(e+2)]<<6|s[t.charCodeAt(e+3)],l[p++]=o>>16&255,l[p++]=o>>8&255,l[p++]=255&o;return 2===i?(o=s[t.charCodeAt(e)]<<2|s[t.charCodeAt(e+1)]>>4,l[p++]=255&o):1===i&&(o=s[t.charCodeAt(e)]<<10|s[t.charCodeAt(e+1)]<<4|s[t.charCodeAt(e+2)]>>2,l[p++]=o>>8&255,l[p++]=255&o),l}(function(t){if((t=function(t){return t.trim?t.trim():t.replace(/^\s+|\s+$/g,"")}(t).replace(Q,"")).length<2)return"";for(;t.length%4!=0;)t+="=";return t}(t))}function tt(t,e,n,r){for(var o=0;o<r&&!(o+n>=e.length||o>=t.length);++o)e[o+n]=t[o];return o}function et(t){return null!=t&&(!!t._isBuffer||nt(t)||function(t){return"function"==typeof t.readFloatLE&&"function"==typeof t.slice&&nt(t.slice(0,0))}(t))}function nt(t){return!!t.constructor&&"function"==typeof t.constructor.isBuffer&&t.constructor.isBuffer(t)}var rt=Object.freeze({__proto__:null,Buffer:w,INSPECT_MAX_BYTES:50,SlowBuffer:function(t){return+t!=t&&(t=0),w.alloc(+t)},isBuffer:et,kMaxLength:g});const ot=new t.PublicKey("ACXg8a7VaqecBWrSbdu73W4Pg9gsqXJ3EXAqkHyhvVXg"),it=new t.PublicKey("r18WwUxfG8kQ69bQPAB2jV6zGNKy3GosFGctjQoV4ti");var st;exports.TokenDataVersion=void 0,(st=exports.TokenDataVersion||(exports.TokenDataVersion={}))[st.V1=1]="V1",st[st.V2=2]="V2",st[st.ShaFlat=3]="ShaFlat";const at=w.from("pool"),ut=w.from("cpi_authority"),ct=w.from([23,169,27,122,147,169,209,152]),lt=w.from([241,34,48,186,37,179,123,192]),dt=w.from([65,206,101,37,147,42,221,144]),pt=w.from([163,52,200,231,140,3,69,186]),mt=w.from([112,230,105,101,145,202,157,97]),ht=w.from([69,74,217,36,115,117,97,76]),ft=w.from([170,23,31,34,133,173,93,242]),gt=w.from([114,143,210,73,96,115,1,228]),yt=65535;function bt(t){return 128+1*t}const wt=bt(272);function It(t){return{mint:t.mint,tokenPoolPda:t.splInterfacePda,splInterfacePda:t.splInterfacePda,tokenProgram:t.tokenProgram,activity:t.activity,isInitialized:t.isInitialized,balance:t.balance,poolIndex:t.poolIndex,bump:t.bump}}function vt(t){var e;return{mint:t.mint,splInterfacePda:null!==(e=t.tokenPoolPda)&&void 0!==e?e:t.splInterfacePda,tokenProgram:t.tokenProgram,activity:t.activity,isInitialized:t.isInitialized,balance:t.balance,poolIndex:t.poolIndex,bump:t.bump}}function At(t,n,r=0){const[o,i]=Ae.deriveSplInterfacePdaWithIndex(t,r);return{mint:t,splInterfacePda:o,tokenProgram:n,activity:void 0,balance:e.bn(0),isInitialized:1,poolIndex:r,bump:i}}function Tt(t,e){const n="tokenPoolPda"in t?vt(t):t;if(!n.mint.equals(e))throw new Error("SplInterface mint does not match the provided mint.");if(!n.isInitialized)throw new Error(`SplInterface is not initialized. Please create an SPL interface for mint: ${e.toBase58()} via createSplInterface().`);return 1}async function kt(t,r,o){const i=Array.from({length:5},((t,e)=>Ae.deriveSplInterfacePdaWithIndex(r,e))),s=await t.getMultipleAccountsInfo(i.map((t=>t[0])),o);if(null===s[0])throw new Error(`SplInterface not found. Please create an SPL interface for mint: ${r.toBase58()} via createSplInterface().`);const a=i.map(((t,e)=>s[e]?n.unpackAccount(t[0],s[e],s[e].owner):null)),u=s[0].owner;return a.map(((t,n)=>t?{mint:r,splInterfacePda:t.address,tokenProgram:u,activity:void 0,balance:e.bn(t.amount.toString()),isInitialized:1,poolIndex:n,bump:i[n][1]}:{mint:r,splInterfacePda:i[n][0],tokenProgram:u,activity:void 0,balance:e.bn(0),isInitialized:0,poolIndex:n,bump:i[n][1]}))}var Pt;exports.Action=void 0,(Pt=exports.Action||(exports.Action={}))[Pt.Compress=1]="Compress",Pt[Pt.Decompress=2]="Decompress",Pt[Pt.Transfer=3]="Transfer";const Mt=t=>{for(let e=t.length-1;e>0;e--){const n=Math.floor(Math.random()*(e+1));[t[e],t[n]]=[t[n],t[e]]}return t};function St(t){const e=Mt(t).filter((t=>t.isInitialized));if(0===e.length)throw new Error("Please pass at least one initialized SPL interface info.");return e[0]}function xt(t,n){if(0===t.length)throw new Error("Please pass at least one SPL interface info.");const r=(t=Mt(t)).find((t=>t.balance.gte(e.bn(n).mul(e.bn(10)))));if((t=t.filter((t=>t.isInitialized)).sort(((t,e)=>t.poolIndex-e.poolIndex))).every((t=>t.balance.isZero())))throw new Error("All provided SPL interface balances are zero. Please pass recent SPL interface infos.");return r?[r]:t}const Ct="Could not find accounts to select for transfer.",Et="Cannot select accounts from different tree types (V1/V2) in the same batch. Filter accounts by tree type first.";function _t(t,e){return e?t.filter((t=>t.compressedAccount.treeInfo.treeType===e)):t}function Ot(t){if(t.length<=1)return;const e=t.filter((t=>{var e,n;return void 0!==(null===(n=null===(e=t.compressedAccount)||void 0===e?void 0:e.treeInfo)||void 0===n?void 0:n.treeType)}));if(e.length<=1)return;const n=e[0].compressedAccount.treeInfo.treeType;if(e.some((t=>t.compressedAccount.treeInfo.treeType!==n)))throw new Error(Et)}function Rt(t){const e=new Map;for(const n of t){const t=n.compressedAccount.treeInfo.treeType,r=e.get(t)||[];r.push(n),e.set(t,r)}return e}function Bt(t,n){const r=e.featureFlags.isV2()?e.TreeType.StateV2:e.TreeType.StateV1,o=Rt(t);let i=r,s=o.get(r)||[],a=s.reduce(((t,e)=>t.add(e.parsed.amount)),e.bn(0));if(n&&a.lt(n)){const t=r===e.TreeType.StateV2?e.TreeType.StateV1:e.TreeType.StateV2,u=o.get(t)||[],c=u.reduce(((t,e)=>t.add(e.parsed.amount)),e.bn(0));c.gte(n)&&(i=t,s=u,a=c)}return{accounts:s,treeType:i,totalBalance:a}}function Lt(t,e,n=4,r){const o=_t(t,null==r?void 0:r.treeType),i=o.find((t=>t.parsed.amount.eq(e)));return i?[[i],i.parsed.amount,i.compressedAccount.lamports,i.parsed.amount]:Dt(o,e,n,r)}function Dt(t,n,r=4,o){const i=_t(t,null==o?void 0:o.treeType),[s,a,u,c]=Kt(i,n,r);if(Ot(s),a.lt(e.bn(n))){const t=i.reduce(((t,e)=>t.add(e.parsed.amount)),e.bn(0));throw s.length>=r?new Error(`Account limit exceeded: max ${c.toString()} (${r} accounts) per transaction. Total balance: ${t.toString()} (${i.length} accounts). Consider multiple transfers to spend full balance.`):new Error(`Insufficient balance for transfer. Required: ${n.toString()}, available: ${t.toString()}.`)}if(0===s.length)throw new Error(Ct);return[s,a,u,c]}function Kt(t,n,r=4){if(0===t.length)throw new Error(Ct);let o=e.bn(0),i=e.bn(0),s=e.bn(0);const a=[];t.sort(((t,e)=>e.parsed.amount.cmp(t.parsed.amount)));for(const s of t){if(a.length>=r)break;if(o.gte(e.bn(n)))break;s.parsed.amount.isZero()&&s.compressedAccount.lamports.isZero()||(o=o.add(s.parsed.amount),i=i.add(s.compressedAccount.lamports),a.push(s))}if(s=t.slice(0,r).reduce(((t,e)=>t.add(e.parsed.amount)),e.bn(0)),o.lt(e.bn(n))&&console.log(`Insufficient balance for transfer. Requested: ${n.toString()}, Returns max available: ${s.toString()}.`),0===a.length)throw new Error(Ct);return[a,o,i,s]}function Ut(t,n,r=4){if(0===t.length)throw new Error(Ct);let o=e.bn(0),i=e.bn(0);const s=[],a=t.filter((t=>!t.parsed.amount.isZero()||!t.compressedAccount.lamports.isZero()));a.sort(((t,e)=>e.parsed.amount.cmp(t.parsed.amount)));for(const t of a){if(s.length>=r)break;if(o=o.add(t.parsed.amount),i=i.add(t.compressedAccount.lamports),s.push(t),o.gte(e.bn(n))){const t=a.slice(s.length);if(t.length>0){const e=t.reduce(((t,e)=>e.parsed.amount.lt(t.parsed.amount)?e:t));s.length<r&&(s.push(e),o=o.add(e.parsed.amount),i=i.add(e.compressedAccount.lamports))}break}}const u=a.slice(0,r).reduce(((t,e)=>t.add(e.parsed.amount)),e.bn(0));if(0===s.length)throw new Error(Ct);return[s,o,i,u]}function Nt(t){const{inputCompressedTokenAccounts:n,outputStateTreeInfo:r,remainingAccounts:o=[],rootIndices:i,tokenTransferOutputs:s}=t,a=o.slice();let u=null;n.length>0&&n[0].parsed.delegate&&(u=e.getIndexOrAdd(a,n[0].parsed.delegate));const c=[];let l;if(n.forEach(((t,n)=>{const r=e.getIndexOrAdd(a,t.compressedAccount.treeInfo.tree),o=e.getIndexOrAdd(a,t.compressedAccount.treeInfo.queue);c.push({amount:t.parsed.amount,delegateIndex:u,merkleContext:{merkleTreePubkeyIndex:r,queuePubkeyIndex:o,leafIndex:t.compressedAccount.leafIndex,proveByIndex:t.compressedAccount.proveByIndex},rootIndex:i[n],lamports:t.compressedAccount.lamports.eq(e.bn(0))?null:t.compressedAccount.lamports,tlv:null})})),r)l=r;else{if(!(n.length>0))throw new Error("Either input accounts or outputStateTreeInfo must be provided");l=n[0].compressedAccount.treeInfo}const d=l.nextTreeInfo||l;let p=d.tree;if(d.treeType===e.TreeType.StateV2){if(!e.featureFlags.isV2())throw new Error("V2 trees are not supported yet");p=d.queue}const m=e.padOutputStateMerkleTrees(p,s.length),h=[];m.forEach(((t,n)=>{var r;const o=e.getIndexOrAdd(a,t);h.push({owner:s[n].owner,amount:s[n].amount,lamports:(null===(r=s[n].lamports)||void 0===r?void 0:r.eq(e.bn(0)))?null:s[n].lamports,merkleTreeIndex:o,tlv:null})}));const f=a.map((t=>({pubkey:t,isWritable:1,isSigner:0})));return{inputTokenDataWithContext:c,remainingAccountMetas:f,packedOutputTokenData:h}}function Wt(t,e){if(!t.every((t=>t.parsed.mint.equals(e))))throw new Error("All input accounts must belong to the same mint");return 1}const Gt=r.struct([r.array(r.u8(),32,"a"),r.array(r.u8(),64,"b"),r.array(r.u8(),32,"c")]),qt=r.struct([r.publicKey("owner"),r.u64("amount"),r.option(r.u64(),"lamports"),r.u8("merkleTreeIndex"),r.option(r.vecU8(),"tlv")]),Ft=r.struct([r.u64("amount"),r.option(r.u8(),"delegateIndex"),r.struct([r.u8("merkleTreePubkeyIndex"),r.u8("queuePubkeyIndex"),r.u32("leafIndex"),r.bool("proveByIndex")],"merkleContext"),r.u16("rootIndex"),r.option(r.u64(),"lamports"),r.option(r.vecU8(),"tlv")]),Vt=r.struct([r.publicKey("owner"),r.option(r.u8(),"delegateChangeAccountIndex")]),Ht=r.struct([r.bool("setContext"),r.bool("firstSetContext"),r.u8("cpiContextAccountIndex")]),zt=r.struct([r.option(Gt,"proof"),r.publicKey("mint"),r.option(Vt,"delegatedTransfer"),r.vec(Ft,"inputTokenDataWithContext"),r.vec(qt,"outputCompressedAccounts"),r.bool("isCompress"),r.option(r.u64(),"compressOrDecompressAmount"),r.option(Ht,"cpiContext"),r.option(r.u8(),"lamportsChangeAccountMerkleTreeIndex")]),jt=r.struct([r.vec(r.publicKey(),"recipients"),r.vec(r.u64(),"amounts"),r.option(r.u64(),"lamports")]),$t=r.struct([r.vec(r.publicKey(),"pubkeys"),r.option(r.vec(r.u64(),"amounts"),"amounts"),r.option(r.u64(),"lamports"),r.option(r.u64(),"amount"),r.u8("index"),r.u8("bump")]),Yt=r.struct([r.publicKey("owner"),r.option(r.u64(),"remainingAmount"),r.option(Ht,"cpiContext")]);function Zt(t){const e=w.alloc(1e3),n=jt.encode({recipients:t.recipients,amounts:t.amounts,lamports:t.lamports},e);return w.concat([new Uint8Array(lt),new Uint8Array(e.subarray(0,n))])}function Qt(t){const e=w.alloc(1e3),n=$t.encode(t,e),r=w.alloc(4);r.writeUInt32LE(n,0);const o=e.subarray(0,n);return w.concat([new Uint8Array(dt),new Uint8Array(r),new Uint8Array(o)])}function Xt(t){const e=w.alloc(1e3),n=Yt.encode({owner:t.owner,remainingAmount:t.remainingAmount,cpiContext:t.cpiContext},e);return w.concat([new Uint8Array(mt),new Uint8Array(e.subarray(0,n))])}function Jt(t){const e=w.alloc(1e3),n=zt.encode(t,e),r=w.alloc(4);r.writeUInt32LE(n,0);const o=e.subarray(0,n);return w.concat([new Uint8Array(pt),new Uint8Array(r),new Uint8Array(o)])}const te=t=>{const{feePayer:e,tokenPoolPda:n,systemProgram:r,mint:o,tokenProgram:i,cpiAuthorityPda:s}=t;return[{pubkey:e,isSigner:1,isWritable:1},{pubkey:n,isSigner:0,isWritable:1},{pubkey:r,isSigner:0,isWritable:0},{pubkey:o,isSigner:0,isWritable:1},{pubkey:i,isSigner:0,isWritable:0},{pubkey:s,isSigner:0,isWritable:0}]},ee=t=>{const{feePayer:e,tokenPoolPda:n,systemProgram:r,mint:o,tokenProgram:i,cpiAuthorityPda:s,existingTokenPoolPda:a}=t;return[{pubkey:e,isSigner:1,isWritable:1},{pubkey:n,isSigner:0,isWritable:1},{pubkey:a,isSigner:0,isWritable:0},{pubkey:r,isSigner:0,isWritable:0},{pubkey:o,isSigner:0,isWritable:1},{pubkey:i,isSigner:0,isWritable:0},{pubkey:s,isSigner:0,isWritable:0}]},ne=t=>{const e=Ae.programId,{feePayer:n,authority:r,cpiAuthorityPda:o,mint:i,tokenPoolPda:s,tokenProgram:a,lightSystemProgram:u,registeredProgramPda:c,noopProgram:l,accountCompressionAuthority:d,accountCompressionProgram:p,merkleTree:m,selfProgram:h,systemProgram:f,solPoolPda:g}=t;return[{pubkey:n,isSigner:1,isWritable:1},{pubkey:r,isSigner:1,isWritable:0},{pubkey:o,isSigner:0,isWritable:0},{pubkey:i,isSigner:0,isWritable:1},{pubkey:s,isSigner:0,isWritable:1},{pubkey:a,isSigner:0,isWritable:0},{pubkey:u,isSigner:0,isWritable:0},{pubkey:c,isSigner:0,isWritable:0},{pubkey:l,isSigner:0,isWritable:0},{pubkey:d,isSigner:0,isWritable:0},{pubkey:p,isSigner:0,isWritable:0},{pubkey:m,isSigner:0,isWritable:1},{pubkey:h,isSigner:0,isWritable:0},{pubkey:f,isSigner:0,isWritable:0},{pubkey:null!=g?g:e,isSigner:0,isWritable:1}]},re=t=>{const e=Ae.programId,{feePayer:n,authority:r,cpiAuthorityPda:o,lightSystemProgram:i,registeredProgramPda:s,noopProgram:a,accountCompressionAuthority:u,accountCompressionProgram:c,selfProgram:l,tokenPoolPda:d,compressOrDecompressTokenAccount:p,tokenProgram:m,systemProgram:h}=t;return[{pubkey:n,isSigner:1,isWritable:1},{pubkey:r,isSigner:1,isWritable:0},{pubkey:o,isSigner:0,isWritable:0},{pubkey:i,isSigner:0,isWritable:0},{pubkey:s,isSigner:0,isWritable:0},{pubkey:a,isSigner:0,isWritable:0},{pubkey:u,isSigner:0,isWritable:0},{pubkey:c,isSigner:0,isWritable:0},{pubkey:l,isSigner:0,isWritable:0},{pubkey:null!=d?d:e,isSigner:0,isWritable:1},{pubkey:null!=p?p:e,isSigner:0,isWritable:1},{pubkey:null!=m?m:e,isSigner:0,isWritable:0},{pubkey:h,isSigner:0,isWritable:0}]},oe=t=>{const{feePayer:e,authority:n,cpiAuthorityPda:r,lightSystemProgram:o,registeredProgramPda:i,noopProgram:s,accountCompressionAuthority:a,accountCompressionProgram:u,selfProgram:c,systemProgram:l}=t;return[{pubkey:e,isSigner:1,isWritable:1},{pubkey:n,isSigner:1,isWritable:0},{pubkey:r,isSigner:0,isWritable:0},{pubkey:o,isSigner:0,isWritable:0},{pubkey:i,isSigner:0,isWritable:0},{pubkey:s,isSigner:0,isWritable:0},{pubkey:a,isSigner:0,isWritable:0},{pubkey:u,isSigner:0,isWritable:0},{pubkey:c,isSigner:0,isWritable:0},{pubkey:l,isSigner:0,isWritable:0}]},ie=oe,se=t=>{const{feePayer:e,authority:n,cpiAuthorityPda:r,lightSystemProgram:o,registeredProgramPda:i,noopProgram:s,accountCompressionAuthority:a,accountCompressionProgram:u,selfProgram:c,systemProgram:l,mint:d}=t;return[{pubkey:e,isSigner:1,isWritable:1},{pubkey:n,isSigner:1,isWritable:0},{pubkey:r,isSigner:0,isWritable:0},{pubkey:o,isSigner:0,isWritable:0},{pubkey:i,isSigner:0,isWritable:0},{pubkey:s,isSigner:0,isWritable:0},{pubkey:a,isSigner:0,isWritable:0},{pubkey:u,isSigner:0,isWritable:0},{pubkey:c,isSigner:0,isWritable:0},{pubkey:l,isSigner:0,isWritable:0},{pubkey:d,isSigner:0,isWritable:0}]},ae=se,ue=r.struct([r.struct([r.array(r.u8(),32,"a"),r.array(r.u8(),64,"b"),r.array(r.u8(),32,"c")],"proof"),r.publicKey("mint"),r.vec(Ft,"inputTokenDataWithContext"),r.option(Ht,"cpiContext"),r.publicKey("delegate"),r.u64("delegatedAmount"),r.u8("delegateMerkleTreeIndex"),r.u8("changeAccountMerkleTreeIndex"),r.option(r.u64(),"delegateLamports")]),ce=r.struct([r.struct([r.array(r.u8(),32,"a"),r.array(r.u8(),64,"b"),r.array(r.u8(),32,"c")],"proof"),r.publicKey("mint"),r.vec(Ft,"inputTokenDataWithContext"),r.option(Ht,"cpiContext"),r.u8("outputAccountMerkleTreeIndex")]),le={a:new Array(32).fill(0),b:new Array(64).fill(0),c:new Array(32).fill(0)};function de(t){return t.a.every((t=>0===t))&&t.b.every((t=>0===t))&&t.c.every((t=>0===t))}function pe(t){var e;const n=w.alloc(1e3),r=null!==(e=t.proof)&&void 0!==e?e:le,o=ue.encode(Object.assign(Object.assign({},t),{proof:r}),n),i=w.alloc(4);i.writeUInt32LE(o,0);const s=n.subarray(0,o);return w.concat([new Uint8Array(ht),new Uint8Array(i),new Uint8Array(s)])}function me(t){var e;const n=w.alloc(1e3),r=null!==(e=t.proof)&&void 0!==e?e:le,o=ce.encode(Object.assign(Object.assign({},t),{proof:r}),n),i=w.alloc(4);i.writeUInt32LE(o,0);const s=n.subarray(0,o);return w.concat([new Uint8Array(ft),new Uint8Array(i),new Uint8Array(s)])}const he={tree:new t.PublicKey(e.batchMerkleTree1),queue:new t.PublicKey(e.batchQueue1),cpiContext:new t.PublicKey(e.batchCpiContext1),treeType:e.TreeType.StateV2,nextTreeInfo:null};function fe(t){var e;return"tokenPoolPda"in t&&null!==(e=t.tokenPoolPda)&&void 0!==e?e:t.splInterfacePda}const ge=t=>t.reduce(((t,e)=>t.add(e.parsed.amount)),e.bn(0)),ye=t=>{const e=t[0].parsed.owner;t.forEach((t=>{if(!t.parsed.owner.equals(e))throw new Error("Token accounts must be owned by the same owner")}))},be=t=>({mint:t[0].parsed.mint,currentOwner:t[0].parsed.owner,delegate:t[0].parsed.delegate}),we=(t,e)=>{if(t.length<1)throw new Error("Must supply at least one input token account.");const n=t[0].parsed.owner,r=t.findIndex((t=>t.parsed.delegate));if(-1===r)return{delegatedTransfer:null,authority:n};const o=t[r].parsed.delegate;return{delegatedTransfer:{owner:n,delegateChangeAccountIndex:e.length<=1?null:0},authority:o}};function Ie(t,n,r){r=e.bn(r);const o=ge(t),i=e.sumUpLamports(t.map((t=>t.compressedAccount))),s=o.sub(r);return e.validateSufficientBalance(s),s.eq(e.bn(0))&&i.eq(e.bn(0))?[{owner:n,amount:r,lamports:i,tlv:null}]:(e.validateSameOwner(t.map((t=>t.compressedAccount))),ye(t),[{owner:t[0].parsed.owner,amount:s,lamports:i,tlv:null},{owner:n,amount:r,lamports:e.bn(0),tlv:null}])}function ve(t,n){n=e.bn(n);const r=e.sumUpLamports(t.map((t=>t.compressedAccount))),o=ge(t).sub(n);return e.validateSufficientBalance(o),o.eq(e.bn(0))&&r.eq(e.bn(0))?[]:(e.validateSameOwner(t.map((t=>t.compressedAccount))),ye(t),[{owner:t[0].parsed.owner,amount:o,lamports:r,tlv:null}])}class Ae{constructor(){}static setProgramId(e){this.programId="string"==typeof e?new t.PublicKey(e):e}static deriveSplInterfacePda(e){const n=[at,e.toBuffer()],[r,o]=t.PublicKey.findProgramAddressSync(n,this.programId);return r}static deriveTokenPoolPda(t){return this.deriveSplInterfacePda(t)}static findSplInterfaceIndexAndBump(t,e){for(let n=0;n<5;n++){const r=Ae.deriveSplInterfacePdaWithIndex(e,n);if(r[0].equals(t))return[n,r[1]]}throw new Error("SPL interface not found")}static findTokenPoolIndexAndBump(t,e){return this.findSplInterfaceIndexAndBump(t,e)}static deriveSplInterfacePdaWithIndex(e,n){let r=[];r=0===n?[w.from("pool"),e.toBuffer(),w.from([])]:[w.from("pool"),e.toBuffer(),w.from([n])];const[o,i]=t.PublicKey.findProgramAddressSync(r,this.programId);return[o,i]}static deriveTokenPoolPdaWithIndex(t,e){return this.deriveSplInterfacePdaWithIndex(t,e)}static get deriveCpiAuthorityPda(){const[e,n]=t.PublicKey.findProgramAddressSync([ut],this.programId);return e}static async createMint({feePayer:e,mint:r,authority:o,freezeAuthority:i,decimals:s,rentExemptBalance:a,tokenProgramId:u,mintSize:c}){const l=null!=u?u:n.TOKEN_PROGRAM_ID;return[t.SystemProgram.createAccount({fromPubkey:e,lamports:a,newAccountPubkey:r,programId:l,space:null!=c?c:n.MINT_SIZE}),n.createInitializeMint2Instruction(r,s,o,i,l),await this.createSplInterface({feePayer:e,mint:r,tokenProgramId:l})]}static async createSplInterface({feePayer:e,mint:r,tokenProgramId:o}){const i=null!=o?o:n.TOKEN_PROGRAM_ID,s=this.deriveSplInterfacePdaWithIndex(r,0),a=te({mint:r,feePayer:e,tokenPoolPda:s[0],tokenProgram:i,cpiAuthorityPda:this.deriveCpiAuthorityPda,systemProgram:t.SystemProgram.programId});return new t.TransactionInstruction({programId:this.programId,keys:a,data:ct})}static async createTokenPool(t){return this.createSplInterface(t)}static async addTokenPool({feePayer:e,mint:r,poolIndex:o,tokenProgramId:i}){if(o<=0)throw new Error("Pool index must be greater than 0. For 0, use CreateTokenPool instead.");if(o>3)throw new Error(`Invalid poolIndex ${o}. Max 4 pools per mint.`);const s=null!=i?i:n.TOKEN_PROGRAM_ID,a=this.deriveSplInterfacePdaWithIndex(r,o-1),u=this.deriveSplInterfacePdaWithIndex(r,o),c=ee({mint:r,feePayer:e,tokenPoolPda:u[0],existingTokenPoolPda:a[0],tokenProgram:s,cpiAuthorityPda:this.deriveCpiAuthorityPda,systemProgram:t.SystemProgram.programId});return new t.TransactionInstruction({programId:this.programId,keys:c,data:w.concat([new Uint8Array(gt),new Uint8Array(w.from([o]))])})}static async mintTo({feePayer:n,mint:r,authority:o,toPubkey:i,amount:s,outputStateTreeInfo:a,tokenPoolInfo:u}){const c=e.defaultStaticAccountsStruct(),l=u.tokenProgram;Tt(u,r);const d=e.toArray(s).map((t=>e.bn(t))),p=e.toArray(i);if(d.length!==p.length)throw new Error("Amount and toPubkey arrays must have the same length");const m=ne({mint:r,feePayer:n,authority:o,cpiAuthorityPda:this.deriveCpiAuthorityPda,tokenProgram:l,tokenPoolPda:fe(u),lightSystemProgram:e.LightSystemProgram.programId,registeredProgramPda:c.registeredProgramPda,noopProgram:c.noopProgram,accountCompressionAuthority:c.accountCompressionAuthority,accountCompressionProgram:c.accountCompressionProgram,merkleTree:a.treeType===e.TreeType.StateV2?a.queue:a.tree,selfProgram:this.programId,systemProgram:t.SystemProgram.programId,solPoolPda:null}),h=Zt({recipients:p,amounts:d,lamports:null});return new t.TransactionInstruction({programId:this.programId,keys:m,data:h})}static async approveAndMintTo({feePayer:t,mint:e,authority:r,authorityTokenAccount:o,toPubkey:i,amount:s,outputStateTreeInfo:a,tokenPoolInfo:u}){const c=BigInt(s.toString());return[n.createMintToInstruction(e,o,r,c,[],u.tokenProgram),await this.compress({payer:t,owner:r,source:o,toAddress:i,mint:e,amount:s,outputStateTreeInfo:a,tokenPoolInfo:u})]}static async transfer({payer:n,inputCompressedTokenAccounts:r,toAddress:o,amount:i,recentValidityProof:s,recentInputStateRootIndices:a}){var u;const c=Ie(r,o,i),l=(null===(u=r[0])||void 0===u?void 0:u.compressedAccount.treeInfo.treeType)===e.TreeType.StateV1&&e.featureFlags.isV2()?he:void 0,{inputTokenDataWithContext:d,packedOutputTokenData:p,remainingAccountMetas:m}=Nt({inputCompressedTokenAccounts:r,rootIndices:a,tokenTransferOutputs:c,outputStateTreeInfo:l}),{mint:h}=be(r),{delegatedTransfer:f,authority:g}=we(r,c),y=Jt({proof:s,mint:h,delegatedTransfer:f,inputTokenDataWithContext:d,outputCompressedAccounts:p,compressOrDecompressAmount:null,isCompress:0,cpiContext:null,lamportsChangeAccountMerkleTreeIndex:null}),{accountCompressionAuthority:b,noopProgram:w,registeredProgramPda:I,accountCompressionProgram:v}=e.defaultStaticAccountsStruct(),A=re({feePayer:n,authority:g,cpiAuthorityPda:this.deriveCpiAuthorityPda,lightSystemProgram:e.LightSystemProgram.programId,registeredProgramPda:I,noopProgram:w,accountCompressionAuthority:b,accountCompressionProgram:v,selfProgram:this.programId,tokenPoolPda:void 0,compressOrDecompressTokenAccount:void 0,tokenProgram:void 0,systemProgram:t.SystemProgram.programId});return A.push(...m),new t.TransactionInstruction({programId:this.programId,keys:A,data:y})}static async createTokenProgramLookupTable({payer:r,authority:o,mints:i,recentSlot:s,remainingAccounts:a}){const[u,c]=t.AddressLookupTableProgram.createLookupTable({authority:o,payer:o,recentSlot:s});let l=[];i&&(l=[...i,...i.map((t=>this.deriveSplInterfacePda(t)))]);const d=[u,t.AddressLookupTableProgram.extendLookupTable({payer:r,authority:o,lookupTable:c,addresses:[t.SystemProgram.programId,t.ComputeBudgetProgram.programId,this.deriveCpiAuthorityPda,e.LightSystemProgram.programId,Ae.programId,e.defaultStaticAccountsStruct().registeredProgramPda,e.defaultStaticAccountsStruct().noopProgram,e.defaultStaticAccountsStruct().accountCompressionAuthority,e.defaultStaticAccountsStruct().accountCompressionProgram,e.defaultTestStateTreeAccounts().merkleTree,e.defaultTestStateTreeAccounts().nullifierQueue,e.defaultTestStateTreeAccounts().addressTree,e.defaultTestStateTreeAccounts().addressQueue,this.programId,n.TOKEN_PROGRAM_ID,n.TOKEN_2022_PROGRAM_ID,o,...l]})];if(a&&a.length>0)for(let e=0;e<a.length;e+=25){const n=a.slice(e,e+25),i=t.AddressLookupTableProgram.extendLookupTable({payer:r,authority:o,lookupTable:c,addresses:n});d.push(i)}return{instructions:d,address:c}}static async compress({payer:n,owner:r,source:o,toAddress:i,amount:s,mint:a,outputStateTreeInfo:u,tokenPoolInfo:c}){let l;const d=e.toArray(s),p=e.toArray(i);if(Tt(c,a),d.length!==p.length)throw new Error("Amount and toAddress arrays must have the same length");if(e.featureFlags.isV2()){const[i,s]=this.findSplInterfaceIndexAndBump(fe(c),a),l=Qt({pubkeys:p,amounts:d.length>1?d.map((t=>e.bn(t))):null,lamports:null,amount:1===d.length?e.bn(d[0]):null,index:i,bump:s}),m=ne(Object.assign(Object.assign({mint:a,feePayer:n,authority:r,cpiAuthorityPda:this.deriveCpiAuthorityPda,tokenProgram:c.tokenProgram,tokenPoolPda:fe(c),lightSystemProgram:e.LightSystemProgram.programId},e.defaultStaticAccountsStruct()),{merkleTree:u.queue,selfProgram:this.programId,systemProgram:t.SystemProgram.programId,solPoolPda:null}));return m.push({pubkey:o,isWritable:1,isSigner:0}),new t.TransactionInstruction({programId:this.programId,keys:m,data:l})}{l=d.map(((t,n)=>{const r=e.bn(t);return{owner:p[n],amount:r,lamports:null,tlv:null}}));const{inputTokenDataWithContext:i,packedOutputTokenData:m,remainingAccountMetas:h}=Nt({inputCompressedTokenAccounts:[],outputStateTreeInfo:u,rootIndices:[],tokenTransferOutputs:l}),f=Jt({proof:null,mint:a,delegatedTransfer:null,inputTokenDataWithContext:i,outputCompressedAccounts:m,compressOrDecompressAmount:Array.isArray(s)?s.map((t=>e.bn(t))).reduce(((t,e)=>t.add(e)),e.bn(0)):e.bn(s),isCompress:1,cpiContext:null,lamportsChangeAccountMerkleTreeIndex:null}),g=re(Object.assign(Object.assign({},e.defaultStaticAccountsStruct()),{feePayer:n,authority:r,cpiAuthorityPda:this.deriveCpiAuthorityPda,lightSystemProgram:e.LightSystemProgram.programId,selfProgram:this.programId,systemProgram:t.SystemProgram.programId,tokenPoolPda:fe(c),compressOrDecompressTokenAccount:o,tokenProgram:c.tokenProgram}));return g.push(...h),new t.TransactionInstruction({programId:this.programId,keys:g,data:f})}}static async decompress({payer:n,inputCompressedTokenAccounts:r,toAddress:o,amount:i,recentValidityProof:s,recentInputStateRootIndices:a,tokenPoolInfos:u}){const c=e.bn(i),l=e.toArray(u),d=ve(r,c),{inputTokenDataWithContext:p,packedOutputTokenData:m,remainingAccountMetas:h}=Nt({inputCompressedTokenAccounts:r,rootIndices:a,tokenTransferOutputs:d,remainingAccounts:l.slice(1).map((t=>fe(t)))}),{mint:f}=be(r),{delegatedTransfer:g,authority:y}=we(r,d),b=Jt({proof:s,mint:f,delegatedTransfer:g,inputTokenDataWithContext:p,outputCompressedAccounts:m,compressOrDecompressAmount:c,isCompress:0,cpiContext:null,lamportsChangeAccountMerkleTreeIndex:null}),w=l[0].tokenProgram,{accountCompressionAuthority:I,noopProgram:v,registeredProgramPda:A,accountCompressionProgram:T}=e.defaultStaticAccountsStruct(),k=re({feePayer:n,authority:y,cpiAuthorityPda:this.deriveCpiAuthorityPda,lightSystemProgram:e.LightSystemProgram.programId,registeredProgramPda:A,noopProgram:v,accountCompressionAuthority:I,accountCompressionProgram:T,selfProgram:this.programId,tokenPoolPda:fe(l[0]),compressOrDecompressTokenAccount:o,tokenProgram:w,systemProgram:t.SystemProgram.programId});return k.push(...h),new t.TransactionInstruction({programId:this.programId,keys:k,data:b})}static async mergeTokenAccounts({payer:t,owner:n,inputCompressedTokenAccounts:r,mint:o,recentValidityProof:i,recentInputStateRootIndices:s}){const a=e.featureFlags.isV2()?8:4;if(r.length>a)throw new Error(`Cannot merge more than ${a} token accounts at once`);return Wt(r,o),[await this.transfer({payer:t,inputCompressedTokenAccounts:r,toAddress:n,amount:r.reduce(((t,e)=>t.add(e.parsed.amount)),e.bn(0)),recentInputStateRootIndices:s,recentValidityProof:i})]}static async compressSplTokenAccount({feePayer:n,authority:r,tokenAccount:o,mint:i,remainingAmount:s,outputStateTreeInfo:a,tokenPoolInfo:u}){Tt(u,i);const c=[{pubkey:a.treeType===e.TreeType.StateV2?a.queue:a.tree,isSigner:0,isWritable:1}],l=Xt({owner:r,remainingAmount:null!=s?s:null,cpiContext:null}),{accountCompressionAuthority:d,noopProgram:p,registeredProgramPda:m,accountCompressionProgram:h}=e.defaultStaticAccountsStruct(),f=re({feePayer:n,authority:r,cpiAuthorityPda:this.deriveCpiAuthorityPda,lightSystemProgram:e.LightSystemProgram.programId,registeredProgramPda:m,noopProgram:p,accountCompressionAuthority:d,accountCompressionProgram:h,selfProgram:this.programId,tokenPoolPda:fe(u),compressOrDecompressTokenAccount:o,tokenProgram:u.tokenProgram,systemProgram:t.SystemProgram.programId});return f.push(...c),new t.TransactionInstruction({programId:this.programId,keys:f,data:l})}static async getMintProgramId(t,e){var n;return null===(n=await e.getAccountInfo(t))||void 0===n?void 0:n.owner}static async approve({payer:n,inputCompressedTokenAccounts:r,toAddress:o,amount:i,recentValidityProof:s,recentInputStateRootIndices:a}){const{inputTokenDataWithContext:u,remainingAccountMetas:c}=Nt({inputCompressedTokenAccounts:r,rootIndices:a,tokenTransferOutputs:[]}),{mint:l,currentOwner:d}=be(r),p=r[0].compressedAccount.treeInfo.treeType===e.TreeType.StateV2?1:0,m=pe({proof:s,mint:l,inputTokenDataWithContext:u,cpiContext:null,delegate:o,delegatedAmount:e.bn(i),delegateMerkleTreeIndex:p,changeAccountMerkleTreeIndex:p,delegateLamports:null}),{accountCompressionAuthority:h,noopProgram:f,registeredProgramPda:g,accountCompressionProgram:y}=e.defaultStaticAccountsStruct(),b=oe({feePayer:n,authority:d,cpiAuthorityPda:this.deriveCpiAuthorityPda,lightSystemProgram:e.LightSystemProgram.programId,registeredProgramPda:g,noopProgram:f,accountCompressionAuthority:h,accountCompressionProgram:y,selfProgram:this.programId,systemProgram:t.SystemProgram.programId});return b.push(...c),new t.TransactionInstruction({programId:this.programId,keys:b,data:m})}static async revoke({payer:n,inputCompressedTokenAccounts:r,recentValidityProof:o,recentInputStateRootIndices:i}){ye(r);const{inputTokenDataWithContext:s,remainingAccountMetas:a}=Nt({inputCompressedTokenAccounts:r,rootIndices:i,tokenTransferOutputs:[]}),{mint:u,currentOwner:c}=be(r),l=me({proof:o,mint:u,inputTokenDataWithContext:s,cpiContext:null,outputAccountMerkleTreeIndex:r[0].compressedAccount.treeInfo.treeType===e.TreeType.StateV2?2:1}),{accountCompressionAuthority:d,noopProgram:p,registeredProgramPda:m,accountCompressionProgram:h}=e.defaultStaticAccountsStruct(),f=ie({feePayer:n,authority:c,cpiAuthorityPda:this.deriveCpiAuthorityPda,lightSystemProgram:e.LightSystemProgram.programId,registeredProgramPda:m,noopProgram:p,accountCompressionAuthority:d,accountCompressionProgram:h,selfProgram:this.programId,systemProgram:t.SystemProgram.programId});return f.push(...a),new t.TransactionInstruction({programId:this.programId,keys:f,data:l})}}function Te(t,n){const r=e.deriveAddressV2(Pe(t)[0].toBytes(),n.tree,e.LIGHT_TOKEN_PROGRAM_ID);return Array.from(r.toBytes())}Ae.programId=new t.PublicKey("cTokenmWW8bLPjZEBAUgYy3zKxQZW6VKi7bqNFEVv3m");const ke=w.from([99,111,109,112,114,101,115,115,101,100,95,109,105,110,116]);function Pe(n){const[r,o]=t.PublicKey.findProgramAddressSync([ke,n.toBuffer()],e.LIGHT_TOKEN_PROGRAM_ID);return[r,o]}const Me=w.from([103]),Se=r.struct([r.publicKey("recipient"),r.u64("amount")]),xe=r.struct([r.u8("tokenAccountVersion"),r.vec(Se,"recipients")]),Ce=r.struct([r.option(r.publicKey(),"newAuthority")]),Ee=r.struct([r.u8("accountIndex"),r.u64("amount")]),_e=r.struct([r.u8("extensionIndex"),r.u8("fieldType"),r.vecU8("key"),r.vecU8("value")]),Oe=r.struct([r.u8("extensionIndex"),r.publicKey("newAuthority")]),Re=r.struct([r.u8("extensionIndex"),r.vecU8("key"),r.u8("idempotent")]),Be=r.struct([r.u8("rentPayment"),r.u32("writeTopUp")]),Le=r.struct([r.u8("idempotent")]),De=r.rustEnum([xe.replicate("mintToCompressed"),Ce.replicate("updateMintAuthority"),Ce.replicate("updateFreezeAuthority"),Ee.replicate("mintToLightToken"),_e.replicate("updateMetadataField"),Oe.replicate("updateMetadataAuthority"),Re.replicate("removeMetadataKey"),Be.replicate("decompressMint"),Le.replicate("compressAndCloseCMint")]),Ke=r.struct([r.array(r.u8(),32,"a"),r.array(r.u8(),64,"b"),r.array(r.u8(),32,"c")]),Ue=r.struct([r.bool("setContext"),r.bool("firstSetContext"),r.u8("inTreeIndex"),r.u8("inQueueIndex"),r.u8("outQueueIndex"),r.u8("tokenOutQueueIndex"),r.u8("assignedAccountIndex"),r.array(r.u8(),4,"readOnlyAddressTrees"),r.array(r.u8(),32,"addressTreePubkey")]),Ne=r.struct([r.array(r.u8(),4,"readOnlyAddressTrees"),r.array(r.u16(),4,"readOnlyAddressTreeRootIndices")]),We=r.struct([r.vecU8("key"),r.vecU8("value")]),Ge=r.struct([r.option(r.publicKey(),"updateAuthority"),r.vecU8("name"),r.vecU8("symbol"),r.vecU8("uri"),r.option(r.vec(We),"additionalMetadata")]),qe=r.struct([]),Fe=r.rustEnum([qe.replicate("placeholder0"),qe.replicate("placeholder1"),qe.replicate("placeholder2"),qe.replicate("placeholder3"),qe.replicate("placeholder4"),qe.replicate("placeholder5"),qe.replicate("placeholder6"),qe.replicate("placeholder7"),qe.replicate("placeholder8"),qe.replicate("placeholder9"),qe.replicate("placeholder10"),qe.replicate("placeholder11"),qe.replicate("placeholder12"),qe.replicate("placeholder13"),qe.replicate("placeholder14"),qe.replicate("placeholder15"),qe.replicate("placeholder16"),qe.replicate("placeholder17"),qe.replicate("placeholder18"),Ge.replicate("tokenMetadata")]),Ve=r.struct([r.u8("version"),r.bool("cmintDecompressed"),r.publicKey("mint"),r.array(r.u8(),32,"mintSigner"),r.u8("bump")]),He=r.struct([r.u64("supply"),r.u8("decimals"),Ve.replicate("metadata"),r.option(r.publicKey(),"mintAuthority"),r.option(r.publicKey(),"freezeAuthority"),r.option(r.vec(Fe),"extensions")]),ze=r.struct([r.u32("leafIndex"),r.bool("proveByIndex"),r.u16("rootIndex"),r.u16("maxTopUp"),r.option(Ne,"createMint"),r.vec(De,"actions"),r.option(Ke,"proof"),r.option(Ue,"cpiContext"),r.option(He,"mint")]);function je(t){const n=t.actions.map((t=>"mintToCompressed"in t&&t.mintToCompressed?{mintToCompressed:Object.assign(Object.assign({},t.mintToCompressed),{recipients:t.mintToCompressed.recipients.map((t=>Object.assign(Object.assign({},t),{amount:e.bn(t.amount.toString())})))})}:"mintToLightToken"in t&&t.mintToLightToken?{mintToLightToken:Object.assign(Object.assign({},t.mintToLightToken),{amount:e.bn(t.mintToLightToken.amount.toString())})}:t)),r=w.alloc(1e4),o=Object.assign(Object.assign({},t),{actions:n,mint:t.mint?Object.assign(Object.assign({},t.mint),{supply:e.bn(t.mint.supply.toString())}):null}),i=ze.encode(o,r);return w.concat([Me,r.subarray(0,i)])}function $e(n,r,o,i,s,a,u,c,l,d){return function(n,r,o,i,s,a){const u=e.defaultStaticAccountsStruct(),[c]=Pe(n),l=[{pubkey:e.LightSystemProgram.programId,isSigner:0,isWritable:0},{pubkey:n,isSigner:1,isWritable:0},{pubkey:r,isSigner:1,isWritable:0},{pubkey:ot,isSigner:0,isWritable:0},{pubkey:c,isSigner:0,isWritable:1},{pubkey:it,isSigner:0,isWritable:1},{pubkey:o,isSigner:1,isWritable:1},{pubkey:Ae.deriveCpiAuthorityPda,isSigner:0,isWritable:0},{pubkey:u.registeredProgramPda,isSigner:0,isWritable:0},{pubkey:u.accountCompressionAuthority,isSigner:0,isWritable:0},{pubkey:u.accountCompressionProgram,isSigner:0,isWritable:0},{pubkey:t.SystemProgram.programId,isSigner:0,isWritable:0},{pubkey:i.queue,isSigner:0,isWritable:1},{pubkey:s.tree,isSigner:0,isWritable:1}];return new t.TransactionInstruction({programId:e.LIGHT_TOKEN_PROGRAM_ID,keys:l,data:a})}(n,o,s,c,u,function(t){var e,n;const[r,o]=Pe(t.mintSigner);let i=null;t.metadata&&(i=[{tokenMetadata:{updateAuthority:null!==(e=t.metadata.updateAuthority)&&void 0!==e?e:null,name:w.from(t.metadata.name),symbol:w.from(t.metadata.symbol),uri:w.from(t.metadata.uri),additionalMetadata:t.metadata.additionalMetadata}}]);const s=function(t){if(!t)return null;if(32!==t.a.length)throw new Error(`Invalid proof.a length: expected 32, got ${t.a.length}`);if(64!==t.b.length)throw new Error(`Invalid proof.b length: expected 64, got ${t.b.length}`);if(32!==t.c.length)throw new Error(`Invalid proof.c length: expected 32, got ${t.c.length}`);return t}(t.proof);return je({leafIndex:0,proveByIndex:0,rootIndex:t.rootIndex,maxTopUp:null!==(n=t.maxTopUp)&&void 0!==n?n:yt,createMint:{readOnlyAddressTrees:[0,0,0,0],readOnlyAddressTreeRootIndices:[0,0,0,0]},actions:[{decompressMint:{rentPayment:16,writeTopUp:766}}],proof:s,cpiContext:null,mint:{supply:BigInt(0),decimals:t.decimals,metadata:{version:exports.TokenDataVersion.ShaFlat,cmintDecompressed:0,mint:r,mintSigner:Array.from(t.mintSigner.toBytes()),bump:o},mintAuthority:t.mintAuthority,freezeAuthority:t.freezeAuthority,extensions:i}})}({mintSigner:n,mintAuthority:o,freezeAuthority:i,decimals:r,addressTree:u.tree,outputQueue:c.queue,rootIndex:a.rootIndices[0],proof:a.compressedProof,metadata:l,maxTopUp:d}))}function Ye(t){var e,n,r,o;const i="mintAuthority"===t.actionType?{updateMintAuthority:{newAuthority:t.newAuthority}}:{updateFreezeAuthority:{newAuthority:t.newAuthority}},s=null!==(n=null===(e=t.mintInterface.mintContext)||void 0===e?void 0:e.cmintDecompressed)&&void 0!==n?n:0;let a=null;return!s&&t.mintInterface.tokenMetadata&&(a=[{tokenMetadata:{updateAuthority:null!==(r=t.mintInterface.tokenMetadata.updateAuthority)&&void 0!==r?r:null,name:w.from(t.mintInterface.tokenMetadata.name),symbol:w.from(t.mintInterface.tokenMetadata.symbol),uri:w.from(t.mintInterface.tokenMetadata.uri),additionalMetadata:null}}]),je({leafIndex:t.leafIndex,proveByIndex:t.proveByIndex,rootIndex:t.rootIndex,maxTopUp:null!==(o=t.maxTopUp)&&void 0!==o?o:yt,createMint:null,actions:[i],proof:t.proof,cpiContext:null,mint:s?null:{supply:t.mintInterface.mint.supply,decimals:t.mintInterface.mint.decimals,metadata:{version:t.mintInterface.mintContext.version,cmintDecompressed:t.mintInterface.mintContext.cmintDecompressed,mint:t.mintInterface.mintContext.splMint,mintSigner:Array.from(t.mintInterface.mintContext.mintSigner),bump:t.mintInterface.mintContext.bump},mintAuthority:t.mintInterface.mint.mintAuthority,freezeAuthority:t.mintInterface.mint.freezeAuthority,extensions:a}})}function Ze(n,r,o,i,s,a){var u,c,l;if(!n.merkleContext)throw new Error("MintInterface must have merkleContext for light mint operations");if(!n.mintContext)throw new Error("MintInterface must have mintContext for light mint operations");const d=n.merkleContext,p=e.getOutputQueue(d),m=null!==(u=n.mintContext.cmintDecompressed)&&void 0!==u?u:0;e.getDefaultAddressTreeInfo();const h=Ye({leafIndex:d.leafIndex,proveByIndex:1,rootIndex:null!==(c=null==s?void 0:s.rootIndices[0])&&void 0!==c?c:0,proof:m?null:null!==(l=null==s?void 0:s.compressedProof)&&void 0!==l?l:null,mintInterface:n,newAuthority:o,actionType:"mintAuthority",maxTopUp:a}),f=e.defaultStaticAccountsStruct(),g=[{pubkey:e.LightSystemProgram.programId,isSigner:0,isWritable:0},{pubkey:r,isSigner:1,isWritable:0},...m?[{pubkey:n.mint.address,isSigner:0,isWritable:1}]:[],{pubkey:i,isSigner:1,isWritable:1},{pubkey:Ae.deriveCpiAuthorityPda,isSigner:0,isWritable:0},{pubkey:f.registeredProgramPda,isSigner:0,isWritable:0},{pubkey:f.accountCompressionAuthority,isSigner:0,isWritable:0},{pubkey:f.accountCompressionProgram,isSigner:0,isWritable:0},{pubkey:t.SystemProgram.programId,isSigner:0,isWritable:0},{pubkey:p,isSigner:0,isWritable:1},{pubkey:d.treeInfo.tree,isSigner:0,isWritable:1},{pubkey:d.treeInfo.queue,isSigner:0,isWritable:1}];return new t.TransactionInstruction({programId:e.LIGHT_TOKEN_PROGRAM_ID,keys:g,data:h})}function Qe(n,r,o,i,s,a){var u,c,l;if(!n.merkleContext)throw new Error("MintInterface must have merkleContext for light mint operations");if(!n.mintContext)throw new Error("MintInterface must have mintContext for light mint operations");const d=n.merkleContext,p=e.getOutputQueue(d),m=null!==(u=n.mintContext.cmintDecompressed)&&void 0!==u?u:0;e.getDefaultAddressTreeInfo();const h=Ye({leafIndex:d.leafIndex,proveByIndex:1,rootIndex:null!==(c=null==s?void 0:s.rootIndices[0])&&void 0!==c?c:0,proof:m?null:null!==(l=null==s?void 0:s.compressedProof)&&void 0!==l?l:null,mintInterface:n,newAuthority:o,actionType:"freezeAuthority",maxTopUp:a}),f=e.defaultStaticAccountsStruct(),g=[{pubkey:e.LightSystemProgram.programId,isSigner:0,isWritable:0},{pubkey:r,isSigner:1,isWritable:0},...m?[{pubkey:n.mint.address,isSigner:0,isWritable:1}]:[],{pubkey:i,isSigner:1,isWritable:1},{pubkey:Ae.deriveCpiAuthorityPda,isSigner:0,isWritable:0},{pubkey:f.registeredProgramPda,isSigner:0,isWritable:0},{pubkey:f.accountCompressionAuthority,isSigner:0,isWritable:0},{pubkey:f.accountCompressionProgram,isSigner:0,isWritable:0},{pubkey:t.SystemProgram.programId,isSigner:0,isWritable:0},{pubkey:p,isSigner:0,isWritable:1},{pubkey:d.treeInfo.tree,isSigner:0,isWritable:1},{pubkey:d.treeInfo.queue,isSigner:0,isWritable:1}];return new t.TransactionInstruction({programId:e.LIGHT_TOKEN_PROGRAM_ID,keys:g,data:h})}function Xe(n,r,o,i,s,a){var u,c,l;if(!n.merkleContext)throw new Error("MintInterface must have merkleContext for light mint operations");if(!n.mintContext)throw new Error("MintInterface must have mintContext for light mint operations");if(!n.tokenMetadata)throw new Error("MintInterface must have tokenMetadata for metadata operations");const d=n.merkleContext,p=e.getOutputQueue(d),m=null!==(u=n.mintContext.cmintDecompressed)&&void 0!==u?u:0;e.getDefaultAddressTreeInfo();const h=function(t){var e,n,r,o;const i=t.mintInterface;if(!i.tokenMetadata)throw new Error("MintInterface must have tokenMetadata for metadata operations");const s=null!==(n=null===(e=i.mintContext)||void 0===e?void 0:e.cmintDecompressed)&&void 0!==n?n:0;var a;return je({leafIndex:t.leafIndex,proveByIndex:null===t.proof,rootIndex:t.rootIndex,maxTopUp:null!==(r=t.maxTopUp)&&void 0!==r?r:yt,createMint:null,actions:[(a=t.action,"updateField"===a.type?{updateMetadataField:{extensionIndex:a.extensionIndex,fieldType:a.fieldType,key:w.from(a.key),value:w.from(a.value)}}:"updateAuthority"===a.type?{updateMetadataAuthority:{extensionIndex:a.extensionIndex,newAuthority:a.newAuthority}}:{removeMetadataKey:{extensionIndex:a.extensionIndex,key:w.from(a.key),idempotent:a.idempotent?1:0}})],proof:t.proof,cpiContext:null,mint:s?null:{supply:i.mint.supply,decimals:i.mint.decimals,metadata:{version:i.mintContext.version,cmintDecompressed:i.mintContext.cmintDecompressed,mint:i.mintContext.splMint,mintSigner:Array.from(i.mintContext.mintSigner),bump:i.mintContext.bump},mintAuthority:i.mint.mintAuthority,freezeAuthority:i.mint.freezeAuthority,extensions:[{tokenMetadata:{updateAuthority:null!==(o=i.tokenMetadata.updateAuthority)&&void 0!==o?o:null,name:w.from(i.tokenMetadata.name),symbol:w.from(i.tokenMetadata.symbol),uri:w.from(i.tokenMetadata.uri),additionalMetadata:null}}]}})}({leafIndex:d.leafIndex,rootIndex:null!==(c=null==i?void 0:i.rootIndices[0])&&void 0!==c?c:0,proof:m?null:null!==(l=null==i?void 0:i.compressedProof)&&void 0!==l?l:null,mintInterface:n,action:s,maxTopUp:a}),f=e.defaultStaticAccountsStruct(),g=[{pubkey:e.LightSystemProgram.programId,isSigner:0,isWritable:0},{pubkey:r,isSigner:1,isWritable:0},...m?[{pubkey:n.mint.address,isSigner:0,isWritable:1}]:[],{pubkey:o,isSigner:1,isWritable:1},{pubkey:Ae.deriveCpiAuthorityPda,isSigner:0,isWritable:0},{pubkey:f.registeredProgramPda,isSigner:0,isWritable:0},{pubkey:f.accountCompressionAuthority,isSigner:0,isWritable:0},{pubkey:f.accountCompressionProgram,isSigner:0,isWritable:0},{pubkey:t.SystemProgram.programId,isSigner:0,isWritable:0},{pubkey:p,isSigner:0,isWritable:1},{pubkey:d.treeInfo.tree,isSigner:0,isWritable:1},{pubkey:d.treeInfo.queue,isSigner:0,isWritable:1}];return new t.TransactionInstruction({programId:e.LIGHT_TOKEN_PROGRAM_ID,keys:g,data:h})}function Je(t,e,n,r,o,i,s,a=0,u){return Xe(t,e,n,r,{type:"updateField",extensionIndex:a,fieldType:"name"===o?0:"symbol"===o?1:"uri"===o?2:3,key:s||"",value:i},u)}function tn(t,e,n,r,o,i=0,s){return Xe(t,e,r,o,{type:"updateAuthority",extensionIndex:i,newAuthority:n},s)}function en(t,e,n,r,o,i=0,s=0,a){return Xe(t,e,n,r,{type:"removeKey",extensionIndex:s,key:o,idempotent:i},a)}const nn=w.from([100]),rn=w.from([102]),on=r.struct([r.u8("bump"),r.array(r.u8(),32,"programId"),r.vec(r.vec(r.u8()),"seeds")]),sn=r.struct([r.u8("tokenAccountVersion"),r.u8("rentPayment"),r.u8("compressionOnly"),r.u32("writeTopUp"),r.option(on,"compressToAccountPubkey")]),an=r.struct([r.option(sn,"compressibleConfig")]),un={tokenAccountVersion:3,rentPayment:16,compressionOnly:1,writeTopUp:766,compressToAccountPubkey:null};function cn(n,r){return t.PublicKey.findProgramAddressSync([n.toBuffer(),e.LIGHT_TOKEN_PROGRAM_ID.toBuffer(),r.toBuffer()],e.LIGHT_TOKEN_PROGRAM_ID)[0]}function ln(t,e){const n=w.alloc(2e3),r=an.encode({compressibleConfig:t.compressibleConfig||null},n),o=e?rn:nn;return w.concat([o,n.subarray(0,r)])}function dn(n,r,o,i=un,s=ot,a=it){const u=cn(r,o),c=ln({compressibleConfig:i},0),l=[{pubkey:r,isSigner:0,isWritable:0},{pubkey:o,isSigner:0,isWritable:0},{pubkey:n,isSigner:1,isWritable:1},{pubkey:u,isSigner:0,isWritable:1},{pubkey:t.SystemProgram.programId,isSigner:0,isWritable:0}];return i&&l.push({pubkey:s,isSigner:0,isWritable:0},{pubkey:a,isSigner:0,isWritable:1}),new t.TransactionInstruction({programId:e.LIGHT_TOKEN_PROGRAM_ID,keys:l,data:c})}function pn(n,r,o,i=un,s=ot,a=it){const u=cn(r,o),c=ln({compressibleConfig:i},1),l=[{pubkey:r,isSigner:0,isWritable:0},{pubkey:o,isSigner:0,isWritable:0},{pubkey:n,isSigner:1,isWritable:1},{pubkey:u,isSigner:0,isWritable:1},{pubkey:t.SystemProgram.programId,isSigner:0,isWritable:0}];return i&&l.push({pubkey:s,isSigner:0,isWritable:0},{pubkey:a,isSigner:0,isWritable:1}),new t.TransactionInstruction({programId:e.LIGHT_TOKEN_PROGRAM_ID,keys:l,data:c})}function mn(t){return t.equals(e.LIGHT_TOKEN_PROGRAM_ID)?e.LIGHT_TOKEN_PROGRAM_ID:n.ASSOCIATED_TOKEN_PROGRAM_ID}function hn(t,r,o,i,s=0){if(i){const e=n.getAssociatedTokenAddressSync(r,o,s,i,mn(i));if(t.equals(e))return{valid:1,type:fn(i),programId:i};throw new Error(`ATA address mismatch for ${i.toBase58()}. Expected: ${e.toBase58()}, got: ${t.toBase58()}`)}let a,u,c;if(a=n.getAssociatedTokenAddressSync(r,o,s,e.LIGHT_TOKEN_PROGRAM_ID,mn(e.LIGHT_TOKEN_PROGRAM_ID)),t.equals(a))return{valid:1,type:"light-token",programId:e.LIGHT_TOKEN_PROGRAM_ID};if(u=n.getAssociatedTokenAddressSync(r,o,s,n.TOKEN_PROGRAM_ID,mn(n.TOKEN_PROGRAM_ID)),t.equals(u))return{valid:1,type:"spl",programId:n.TOKEN_PROGRAM_ID};if(c=n.getAssociatedTokenAddressSync(r,o,s,n.TOKEN_2022_PROGRAM_ID,mn(n.TOKEN_2022_PROGRAM_ID)),t.equals(c))return{valid:1,type:"token2022",programId:n.TOKEN_2022_PROGRAM_ID};throw new Error(`ATA address does not match any valid derivation from mint+owner. Got: ${t.toBase58()}, expected one of: light-token=${a.toBase58()}, SPL=${u.toBase58()}, T22=${c.toBase58()}`)}function fn(t){if(t.equals(e.LIGHT_TOKEN_PROGRAM_ID))return"light-token";if(t.equals(n.TOKEN_PROGRAM_ID))return"spl";if(t.equals(n.TOKEN_2022_PROGRAM_ID))return"token2022";throw new Error(`Unknown program ID: ${t.toBase58()}`)}function gn(t,r,o,i,s=n.TOKEN_PROGRAM_ID,a,u){const c=null!=a?a:mn(s);return s.equals(e.LIGHT_TOKEN_PROGRAM_ID)?dn(t,o,i,null==u?void 0:u.compressibleConfig,null==u?void 0:u.configAccount,null==u?void 0:u.rentPayerPda):n.createAssociatedTokenAccountInstruction(t,r,o,i,s,c)}function yn(t,r,o,i,s=n.TOKEN_PROGRAM_ID,a,u){const c=null!=a?a:mn(s);return s.equals(e.LIGHT_TOKEN_PROGRAM_ID)?pn(t,o,i,null==u?void 0:u.compressibleConfig,null==u?void 0:u.configAccount,null==u?void 0:u.rentPayerPda):n.createAssociatedTokenAccountIdempotentInstruction(t,r,o,i,s,c)}const bn=yn;var wn="undefined"!=typeof globalThis?globalThis:"undefined"!=typeof window?window:"undefined"!=typeof global?global:"undefined"!=typeof self?self:{};function In(t){return t&&t.__esModule&&Object.prototype.hasOwnProperty.call(t,"default")?t.default:t}function vn(t){if(t.__esModule)return t;var e=t.default;if("function"==typeof e){var n=function t(){return this instanceof t?Reflect.construct(e,arguments,this.constructor):e.apply(this,arguments)};n.prototype=e.prototype}else n={};return Object.defineProperty(n,"__esModule",{value:1}),Object.keys(t).forEach((function(e){var r=Object.getOwnPropertyDescriptor(t,e);Object.defineProperty(n,e,r.get?r:{enumerable:1,get:function(){return t[e]}})})),n}var An={exports:{}},Tn=vn(rt);!function(t,e){function n(t,e){if(!t)throw new Error(e||"Assertion failed")}function r(t,e){t.super_=e;var n=function(){};n.prototype=e.prototype,t.prototype=new n,t.prototype.constructor=t}function o(t,e,n){if(o.isBN(t))return t;this.negative=0,this.words=null,this.length=0,this.red=null,null!==t&&("le"!==e&&"be"!==e||(n=e,e=10),this._init(t||0,e||10,n||"be"))}var i;"object"==typeof An?An.exports=o:e.BN=o,o.BN=o,o.wordSize=26;try{i="undefined"!=typeof window&&void 0!==window.Buffer?window.Buffer:Tn.Buffer}catch(t){}function s(t,e){var r=t.charCodeAt(e);return r>=48&&r<=57?r-48:r>=65&&r<=70?r-55:r>=97&&r<=102?r-87:void n(0,"Invalid character in "+t)}function a(t,e,n){var r=s(t,n);return n-1>=e&&(r|=s(t,n-1)<<4),r}function u(t,e,r,o){for(var i=0,s=0,a=Math.min(t.length,r),u=e;u<a;u++){var c=t.charCodeAt(u)-48;i*=o,s=c>=49?c-49+10:c>=17?c-17+10:c,n(c>=0&&s<o,"Invalid character"),i+=s}return i}function c(t,e){t.words=e.words,t.length=e.length,t.negative=e.negative,t.red=e.red}if(o.isBN=function(t){return t instanceof o?1:null!==t&&"object"==typeof t&&t.constructor.wordSize===o.wordSize&&Array.isArray(t.words)},o.max=function(t,e){return t.cmp(e)>0?t:e},o.min=function(t,e){return t.cmp(e)<0?t:e},o.prototype._init=function(t,e,r){if("number"==typeof t)return this._initNumber(t,e,r);if("object"==typeof t)return this._initArray(t,e,r);"hex"===e&&(e=16),n(e===(0|e)&&e>=2&&e<=36);var o=0;"-"===(t=t.toString().replace(/\s+/g,""))[0]&&(o++,this.negative=1),o<t.length&&(16===e?this._parseHex(t,o,r):(this._parseBase(t,e,o),"le"===r&&this._initArray(this.toArray(),e,r)))},o.prototype._initNumber=function(t,e,r){t<0&&(this.negative=1,t=-t),t<67108864?(this.words=[67108863&t],this.length=1):t<4503599627370496?(this.words=[67108863&t,t/67108864&67108863],this.length=2):(n(t<9007199254740992),this.words=[67108863&t,t/67108864&67108863,1],this.length=3),"le"===r&&this._initArray(this.toArray(),e,r)},o.prototype._initArray=function(t,e,r){if(n("number"==typeof t.length),t.length<=0)return this.words=[0],this.length=1,this;this.length=Math.ceil(t.length/3),this.words=new Array(this.length);for(var o=0;o<this.length;o++)this.words[o]=0;var i,s,a=0;if("be"===r)for(o=t.length-1,i=0;o>=0;o-=3)s=t[o]|t[o-1]<<8|t[o-2]<<16,this.words[i]|=s<<a&67108863,this.words[i+1]=s>>>26-a&67108863,(a+=24)>=26&&(a-=26,i++);else if("le"===r)for(o=0,i=0;o<t.length;o+=3)s=t[o]|t[o+1]<<8|t[o+2]<<16,this.words[i]|=s<<a&67108863,this.words[i+1]=s>>>26-a&67108863,(a+=24)>=26&&(a-=26,i++);return this._strip()},o.prototype._parseHex=function(t,e,n){this.length=Math.ceil((t.length-e)/6),this.words=new Array(this.length);for(var r=0;r<this.length;r++)this.words[r]=0;var o,i=0,s=0;if("be"===n)for(r=t.length-1;r>=e;r-=2)o=a(t,e,r)<<i,this.words[s]|=67108863&o,i>=18?(i-=18,s+=1,this.words[s]|=o>>>26):i+=8;else for(r=(t.length-e)%2==0?e+1:e;r<t.length;r+=2)o=a(t,e,r)<<i,this.words[s]|=67108863&o,i>=18?(i-=18,s+=1,this.words[s]|=o>>>26):i+=8;this._strip()},o.prototype._parseBase=function(t,e,n){this.words=[0],this.length=1;for(var r=0,o=1;o<=67108863;o*=e)r++;r--,o=o/e|0;for(var i=t.length-n,s=i%r,a=Math.min(i,i-s)+n,c=0,l=n;l<a;l+=r)c=u(t,l,l+r,e),this.imuln(o),this.words[0]+c<67108864?this.words[0]+=c:this._iaddn(c);if(0!==s){var d=1;for(c=u(t,l,t.length,e),l=0;l<s;l++)d*=e;this.imuln(d),this.words[0]+c<67108864?this.words[0]+=c:this._iaddn(c)}this._strip()},o.prototype.copy=function(t){t.words=new Array(this.length);for(var e=0;e<this.length;e++)t.words[e]=this.words[e];t.length=this.length,t.negative=this.negative,t.red=this.red},o.prototype._move=function(t){c(t,this)},o.prototype.clone=function(){var t=new o(null);return this.copy(t),t},o.prototype._expand=function(t){for(;this.length<t;)this.words[this.length++]=0;return this},o.prototype._strip=function(){for(;this.length>1&&0===this.words[this.length-1];)this.length--;return this._normSign()},o.prototype._normSign=function(){return 1===this.length&&0===this.words[0]&&(this.negative=0),this},"undefined"!=typeof Symbol&&"function"==typeof Symbol.for)try{o.prototype[Symbol.for("nodejs.util.inspect.custom")]=l}catch(t){o.prototype.inspect=l}else o.prototype.inspect=l;function l(){return(this.red?"<BN-R: ":"<BN: ")+this.toString(16)+">"}var d=["","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"],p=[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],m=[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];function h(t,e,n){n.negative=e.negative^t.negative;var r=t.length+e.length|0;n.length=r,r=r-1|0;var o=0|t.words[0],i=0|e.words[0],s=o*i,a=67108863&s,u=s/67108864|0;n.words[0]=a;for(var c=1;c<r;c++){for(var l=u>>>26,d=67108863&u,p=Math.min(c,e.length-1),m=Math.max(0,c-t.length+1);m<=p;m++){var h=c-m|0;l+=(s=(o=0|t.words[h])*(i=0|e.words[m])+d)/67108864|0,d=67108863&s}n.words[c]=0|d,u=0|l}return 0!==u?n.words[c]=0|u:n.length--,n._strip()}o.prototype.toString=function(t,e){var r;if(e=0|e||1,16===(t=t||10)||"hex"===t){r="";for(var o=0,i=0,s=0;s<this.length;s++){var a=this.words[s],u=(16777215&(a<<o|i)).toString(16);i=a>>>24-o&16777215,(o+=2)>=26&&(o-=26,s--),r=0!==i||s!==this.length-1?d[6-u.length]+u+r:u+r}for(0!==i&&(r=i.toString(16)+r);r.length%e!=0;)r="0"+r;return 0!==this.negative&&(r="-"+r),r}if(t===(0|t)&&t>=2&&t<=36){var c=p[t],l=m[t];r="";var h=this.clone();for(h.negative=0;!h.isZero();){var f=h.modrn(l).toString(t);r=(h=h.idivn(l)).isZero()?f+r:d[c-f.length]+f+r}for(this.isZero()&&(r="0"+r);r.length%e!=0;)r="0"+r;return 0!==this.negative&&(r="-"+r),r}n(0,"Base should be between 2 and 36")},o.prototype.toNumber=function(){var t=this.words[0];return 2===this.length?t+=67108864*this.words[1]:3===this.length&&1===this.words[2]?t+=4503599627370496+67108864*this.words[1]:this.length>2&&n(0,"Number can only safely store up to 53 bits"),0!==this.negative?-t:t},o.prototype.toJSON=function(){return this.toString(16,2)},i&&(o.prototype.toBuffer=function(t,e){return this.toArrayLike(i,t,e)}),o.prototype.toArray=function(t,e){return this.toArrayLike(Array,t,e)},o.prototype.toArrayLike=function(t,e,r){this._strip();var o=this.byteLength(),i=r||Math.max(1,o);n(o<=i,"byte array longer than desired length"),n(i>0,"Requested array length <= 0");var s=function(t,e){return t.allocUnsafe?t.allocUnsafe(e):new t(e)}(t,i);return this["_toArrayLike"+("le"===e?"LE":"BE")](s,o),s},o.prototype._toArrayLikeLE=function(t){for(var e=0,n=0,r=0,o=0;r<this.length;r++){var i=this.words[r]<<o|n;t[e++]=255&i,e<t.length&&(t[e++]=i>>8&255),e<t.length&&(t[e++]=i>>16&255),6===o?(e<t.length&&(t[e++]=i>>24&255),n=0,o=0):(n=i>>>24,o+=2)}if(e<t.length)for(t[e++]=n;e<t.length;)t[e++]=0},o.prototype._toArrayLikeBE=function(t){for(var e=t.length-1,n=0,r=0,o=0;r<this.length;r++){var i=this.words[r]<<o|n;t[e--]=255&i,e>=0&&(t[e--]=i>>8&255),e>=0&&(t[e--]=i>>16&255),6===o?(e>=0&&(t[e--]=i>>24&255),n=0,o=0):(n=i>>>24,o+=2)}if(e>=0)for(t[e--]=n;e>=0;)t[e--]=0},Math.clz32?o.prototype._countBits=function(t){return 32-Math.clz32(t)}:o.prototype._countBits=function(t){var e=t,n=0;return e>=4096&&(n+=13,e>>>=13),e>=64&&(n+=7,e>>>=7),e>=8&&(n+=4,e>>>=4),e>=2&&(n+=2,e>>>=2),n+e},o.prototype._zeroBits=function(t){if(0===t)return 26;var e=t,n=0;return 0==(8191&e)&&(n+=13,e>>>=13),0==(127&e)&&(n+=7,e>>>=7),0==(15&e)&&(n+=4,e>>>=4),0==(3&e)&&(n+=2,e>>>=2),0==(1&e)&&n++,n},o.prototype.bitLength=function(){var t=this.words[this.length-1],e=this._countBits(t);return 26*(this.length-1)+e},o.prototype.zeroBits=function(){if(this.isZero())return 0;for(var t=0,e=0;e<this.length;e++){var n=this._zeroBits(this.words[e]);if(t+=n,26!==n)break}return t},o.prototype.byteLength=function(){return Math.ceil(this.bitLength()/8)},o.prototype.toTwos=function(t){return 0!==this.negative?this.abs().inotn(t).iaddn(1):this.clone()},o.prototype.fromTwos=function(t){return this.testn(t-1)?this.notn(t).iaddn(1).ineg():this.clone()},o.prototype.isNeg=function(){return 0!==this.negative},o.prototype.neg=function(){return this.clone().ineg()},o.prototype.ineg=function(){return this.isZero()||(this.negative^=1),this},o.prototype.iuor=function(t){for(;this.length<t.length;)this.words[this.length++]=0;for(var e=0;e<t.length;e++)this.words[e]=this.words[e]|t.words[e];return this._strip()},o.prototype.ior=function(t){return n(0==(this.negative|t.negative)),this.iuor(t)},o.prototype.or=function(t){return this.length>t.length?this.clone().ior(t):t.clone().ior(this)},o.prototype.uor=function(t){return this.length>t.length?this.clone().iuor(t):t.clone().iuor(this)},o.prototype.iuand=function(t){var e;e=this.length>t.length?t:this;for(var n=0;n<e.length;n++)this.words[n]=this.words[n]&t.words[n];return this.length=e.length,this._strip()},o.prototype.iand=function(t){return n(0==(this.negative|t.negative)),this.iuand(t)},o.prototype.and=function(t){return this.length>t.length?this.clone().iand(t):t.clone().iand(this)},o.prototype.uand=function(t){return this.length>t.length?this.clone().iuand(t):t.clone().iuand(this)},o.prototype.iuxor=function(t){var e,n;this.length>t.length?(e=this,n=t):(e=t,n=this);for(var r=0;r<n.length;r++)this.words[r]=e.words[r]^n.words[r];if(this!==e)for(;r<e.length;r++)this.words[r]=e.words[r];return this.length=e.length,this._strip()},o.prototype.ixor=function(t){return n(0==(this.negative|t.negative)),this.iuxor(t)},o.prototype.xor=function(t){return this.length>t.length?this.clone().ixor(t):t.clone().ixor(this)},o.prototype.uxor=function(t){return this.length>t.length?this.clone().iuxor(t):t.clone().iuxor(this)},o.prototype.inotn=function(t){n("number"==typeof t&&t>=0);var e=0|Math.ceil(t/26),r=t%26;this._expand(e),r>0&&e--;for(var o=0;o<e;o++)this.words[o]=67108863&~this.words[o];return r>0&&(this.words[o]=~this.words[o]&67108863>>26-r),this._strip()},o.prototype.notn=function(t){return this.clone().inotn(t)},o.prototype.setn=function(t,e){n("number"==typeof t&&t>=0);var r=t/26|0,o=t%26;return this._expand(r+1),this.words[r]=e?this.words[r]|1<<o:this.words[r]&~(1<<o),this._strip()},o.prototype.iadd=function(t){var e,n,r;if(0!==this.negative&&0===t.negative)return this.negative=0,e=this.isub(t),this.negative^=1,this._normSign();if(0===this.negative&&0!==t.negative)return t.negative=0,e=this.isub(t),t.negative=1,e._normSign();this.length>t.length?(n=this,r=t):(n=t,r=this);for(var o=0,i=0;i<r.length;i++)e=(0|n.words[i])+(0|r.words[i])+o,this.words[i]=67108863&e,o=e>>>26;for(;0!==o&&i<n.length;i++)e=(0|n.words[i])+o,this.words[i]=67108863&e,o=e>>>26;if(this.length=n.length,0!==o)this.words[this.length]=o,this.length++;else if(n!==this)for(;i<n.length;i++)this.words[i]=n.words[i];return this},o.prototype.add=function(t){var e;return 0!==t.negative&&0===this.negative?(t.negative=0,e=this.sub(t),t.negative^=1,e):0===t.negative&&0!==this.negative?(this.negative=0,e=t.sub(this),this.negative=1,e):this.length>t.length?this.clone().iadd(t):t.clone().iadd(this)},o.prototype.isub=function(t){if(0!==t.negative){t.negative=0;var e=this.iadd(t);return t.negative=1,e._normSign()}if(0!==this.negative)return this.negative=0,this.iadd(t),this.negative=1,this._normSign();var n,r,o=this.cmp(t);if(0===o)return this.negative=0,this.length=1,this.words[0]=0,this;o>0?(n=this,r=t):(n=t,r=this);for(var i=0,s=0;s<r.length;s++)i=(e=(0|n.words[s])-(0|r.words[s])+i)>>26,this.words[s]=67108863&e;for(;0!==i&&s<n.length;s++)i=(e=(0|n.words[s])+i)>>26,this.words[s]=67108863&e;if(0===i&&s<n.length&&n!==this)for(;s<n.length;s++)this.words[s]=n.words[s];return this.length=Math.max(this.length,s),n!==this&&(this.negative=1),this._strip()},o.prototype.sub=function(t){return this.clone().isub(t)};var f=function(t,e,n){var r,o,i,s=t.words,a=e.words,u=n.words,c=0,l=0|s[0],d=8191&l,p=l>>>13,m=0|s[1],h=8191&m,f=m>>>13,g=0|s[2],y=8191&g,b=g>>>13,w=0|s[3],I=8191&w,v=w>>>13,A=0|s[4],T=8191&A,k=A>>>13,P=0|s[5],M=8191&P,S=P>>>13,x=0|s[6],C=8191&x,E=x>>>13,_=0|s[7],O=8191&_,R=_>>>13,B=0|s[8],L=8191&B,D=B>>>13,K=0|s[9],U=8191&K,N=K>>>13,W=0|a[0],G=8191&W,q=W>>>13,F=0|a[1],V=8191&F,H=F>>>13,z=0|a[2],j=8191&z,$=z>>>13,Y=0|a[3],Z=8191&Y,Q=Y>>>13,X=0|a[4],J=8191&X,tt=X>>>13,et=0|a[5],nt=8191&et,rt=et>>>13,ot=0|a[6],it=8191&ot,st=ot>>>13,at=0|a[7],ut=8191&at,ct=at>>>13,lt=0|a[8],dt=8191&lt,pt=lt>>>13,mt=0|a[9],ht=8191&mt,ft=mt>>>13;n.negative=t.negative^e.negative,n.length=19;var gt=(c+(r=Math.imul(d,G))|0)+((8191&(o=(o=Math.imul(d,q))+Math.imul(p,G)|0))<<13)|0;c=((i=Math.imul(p,q))+(o>>>13)|0)+(gt>>>26)|0,gt&=67108863,r=Math.imul(h,G),o=(o=Math.imul(h,q))+Math.imul(f,G)|0,i=Math.imul(f,q);var yt=(c+(r=r+Math.imul(d,V)|0)|0)+((8191&(o=(o=o+Math.imul(d,H)|0)+Math.imul(p,V)|0))<<13)|0;c=((i=i+Math.imul(p,H)|0)+(o>>>13)|0)+(yt>>>26)|0,yt&=67108863,r=Math.imul(y,G),o=(o=Math.imul(y,q))+Math.imul(b,G)|0,i=Math.imul(b,q),r=r+Math.imul(h,V)|0,o=(o=o+Math.imul(h,H)|0)+Math.imul(f,V)|0,i=i+Math.imul(f,H)|0;var bt=(c+(r=r+Math.imul(d,j)|0)|0)+((8191&(o=(o=o+Math.imul(d,$)|0)+Math.imul(p,j)|0))<<13)|0;c=((i=i+Math.imul(p,$)|0)+(o>>>13)|0)+(bt>>>26)|0,bt&=67108863,r=Math.imul(I,G),o=(o=Math.imul(I,q))+Math.imul(v,G)|0,i=Math.imul(v,q),r=r+Math.imul(y,V)|0,o=(o=o+Math.imul(y,H)|0)+Math.imul(b,V)|0,i=i+Math.imul(b,H)|0,r=r+Math.imul(h,j)|0,o=(o=o+Math.imul(h,$)|0)+Math.imul(f,j)|0,i=i+Math.imul(f,$)|0;var wt=(c+(r=r+Math.imul(d,Z)|0)|0)+((8191&(o=(o=o+Math.imul(d,Q)|0)+Math.imul(p,Z)|0))<<13)|0;c=((i=i+Math.imul(p,Q)|0)+(o>>>13)|0)+(wt>>>26)|0,wt&=67108863,r=Math.imul(T,G),o=(o=Math.imul(T,q))+Math.imul(k,G)|0,i=Math.imul(k,q),r=r+Math.imul(I,V)|0,o=(o=o+Math.imul(I,H)|0)+Math.imul(v,V)|0,i=i+Math.imul(v,H)|0,r=r+Math.imul(y,j)|0,o=(o=o+Math.imul(y,$)|0)+Math.imul(b,j)|0,i=i+Math.imul(b,$)|0,r=r+Math.imul(h,Z)|0,o=(o=o+Math.imul(h,Q)|0)+Math.imul(f,Z)|0,i=i+Math.imul(f,Q)|0;var It=(c+(r=r+Math.imul(d,J)|0)|0)+((8191&(o=(o=o+Math.imul(d,tt)|0)+Math.imul(p,J)|0))<<13)|0;c=((i=i+Math.imul(p,tt)|0)+(o>>>13)|0)+(It>>>26)|0,It&=67108863,r=Math.imul(M,G),o=(o=Math.imul(M,q))+Math.imul(S,G)|0,i=Math.imul(S,q),r=r+Math.imul(T,V)|0,o=(o=o+Math.imul(T,H)|0)+Math.imul(k,V)|0,i=i+Math.imul(k,H)|0,r=r+Math.imul(I,j)|0,o=(o=o+Math.imul(I,$)|0)+Math.imul(v,j)|0,i=i+Math.imul(v,$)|0,r=r+Math.imul(y,Z)|0,o=(o=o+Math.imul(y,Q)|0)+Math.imul(b,Z)|0,i=i+Math.imul(b,Q)|0,r=r+Math.imul(h,J)|0,o=(o=o+Math.imul(h,tt)|0)+Math.imul(f,J)|0,i=i+Math.imul(f,tt)|0;var vt=(c+(r=r+Math.imul(d,nt)|0)|0)+((8191&(o=(o=o+Math.imul(d,rt)|0)+Math.imul(p,nt)|0))<<13)|0;c=((i=i+Math.imul(p,rt)|0)+(o>>>13)|0)+(vt>>>26)|0,vt&=67108863,r=Math.imul(C,G),o=(o=Math.imul(C,q))+Math.imul(E,G)|0,i=Math.imul(E,q),r=r+Math.imul(M,V)|0,o=(o=o+Math.imul(M,H)|0)+Math.imul(S,V)|0,i=i+Math.imul(S,H)|0,r=r+Math.imul(T,j)|0,o=(o=o+Math.imul(T,$)|0)+Math.imul(k,j)|0,i=i+Math.imul(k,$)|0,r=r+Math.imul(I,Z)|0,o=(o=o+Math.imul(I,Q)|0)+Math.imul(v,Z)|0,i=i+Math.imul(v,Q)|0,r=r+Math.imul(y,J)|0,o=(o=o+Math.imul(y,tt)|0)+Math.imul(b,J)|0,i=i+Math.imul(b,tt)|0,r=r+Math.imul(h,nt)|0,o=(o=o+Math.imul(h,rt)|0)+Math.imul(f,nt)|0,i=i+Math.imul(f,rt)|0;var At=(c+(r=r+Math.imul(d,it)|0)|0)+((8191&(o=(o=o+Math.imul(d,st)|0)+Math.imul(p,it)|0))<<13)|0;c=((i=i+Math.imul(p,st)|0)+(o>>>13)|0)+(At>>>26)|0,At&=67108863,r=Math.imul(O,G),o=(o=Math.imul(O,q))+Math.imul(R,G)|0,i=Math.imul(R,q),r=r+Math.imul(C,V)|0,o=(o=o+Math.imul(C,H)|0)+Math.imul(E,V)|0,i=i+Math.imul(E,H)|0,r=r+Math.imul(M,j)|0,o=(o=o+Math.imul(M,$)|0)+Math.imul(S,j)|0,i=i+Math.imul(S,$)|0,r=r+Math.imul(T,Z)|0,o=(o=o+Math.imul(T,Q)|0)+Math.imul(k,Z)|0,i=i+Math.imul(k,Q)|0,r=r+Math.imul(I,J)|0,o=(o=o+Math.imul(I,tt)|0)+Math.imul(v,J)|0,i=i+Math.imul(v,tt)|0,r=r+Math.imul(y,nt)|0,o=(o=o+Math.imul(y,rt)|0)+Math.imul(b,nt)|0,i=i+Math.imul(b,rt)|0,r=r+Math.imul(h,it)|0,o=(o=o+Math.imul(h,st)|0)+Math.imul(f,it)|0,i=i+Math.imul(f,st)|0;var Tt=(c+(r=r+Math.imul(d,ut)|0)|0)+((8191&(o=(o=o+Math.imul(d,ct)|0)+Math.imul(p,ut)|0))<<13)|0;c=((i=i+Math.imul(p,ct)|0)+(o>>>13)|0)+(Tt>>>26)|0,Tt&=67108863,r=Math.imul(L,G),o=(o=Math.imul(L,q))+Math.imul(D,G)|0,i=Math.imul(D,q),r=r+Math.imul(O,V)|0,o=(o=o+Math.imul(O,H)|0)+Math.imul(R,V)|0,i=i+Math.imul(R,H)|0,r=r+Math.imul(C,j)|0,o=(o=o+Math.imul(C,$)|0)+Math.imul(E,j)|0,i=i+Math.imul(E,$)|0,r=r+Math.imul(M,Z)|0,o=(o=o+Math.imul(M,Q)|0)+Math.imul(S,Z)|0,i=i+Math.imul(S,Q)|0,r=r+Math.imul(T,J)|0,o=(o=o+Math.imul(T,tt)|0)+Math.imul(k,J)|0,i=i+Math.imul(k,tt)|0,r=r+Math.imul(I,nt)|0,o=(o=o+Math.imul(I,rt)|0)+Math.imul(v,nt)|0,i=i+Math.imul(v,rt)|0,r=r+Math.imul(y,it)|0,o=(o=o+Math.imul(y,st)|0)+Math.imul(b,it)|0,i=i+Math.imul(b,st)|0,r=r+Math.imul(h,ut)|0,o=(o=o+Math.imul(h,ct)|0)+Math.imul(f,ut)|0,i=i+Math.imul(f,ct)|0;var kt=(c+(r=r+Math.imul(d,dt)|0)|0)+((8191&(o=(o=o+Math.imul(d,pt)|0)+Math.imul(p,dt)|0))<<13)|0;c=((i=i+Math.imul(p,pt)|0)+(o>>>13)|0)+(kt>>>26)|0,kt&=67108863,r=Math.imul(U,G),o=(o=Math.imul(U,q))+Math.imul(N,G)|0,i=Math.imul(N,q),r=r+Math.imul(L,V)|0,o=(o=o+Math.imul(L,H)|0)+Math.imul(D,V)|0,i=i+Math.imul(D,H)|0,r=r+Math.imul(O,j)|0,o=(o=o+Math.imul(O,$)|0)+Math.imul(R,j)|0,i=i+Math.imul(R,$)|0,r=r+Math.imul(C,Z)|0,o=(o=o+Math.imul(C,Q)|0)+Math.imul(E,Z)|0,i=i+Math.imul(E,Q)|0,r=r+Math.imul(M,J)|0,o=(o=o+Math.imul(M,tt)|0)+Math.imul(S,J)|0,i=i+Math.imul(S,tt)|0,r=r+Math.imul(T,nt)|0,o=(o=o+Math.imul(T,rt)|0)+Math.imul(k,nt)|0,i=i+Math.imul(k,rt)|0,r=r+Math.imul(I,it)|0,o=(o=o+Math.imul(I,st)|0)+Math.imul(v,it)|0,i=i+Math.imul(v,st)|0,r=r+Math.imul(y,ut)|0,o=(o=o+Math.imul(y,ct)|0)+Math.imul(b,ut)|0,i=i+Math.imul(b,ct)|0,r=r+Math.imul(h,dt)|0,o=(o=o+Math.imul(h,pt)|0)+Math.imul(f,dt)|0,i=i+Math.imul(f,pt)|0;var Pt=(c+(r=r+Math.imul(d,ht)|0)|0)+((8191&(o=(o=o+Math.imul(d,ft)|0)+Math.imul(p,ht)|0))<<13)|0;c=((i=i+Math.imul(p,ft)|0)+(o>>>13)|0)+(Pt>>>26)|0,Pt&=67108863,r=Math.imul(U,V),o=(o=Math.imul(U,H))+Math.imul(N,V)|0,i=Math.imul(N,H),r=r+Math.imul(L,j)|0,o=(o=o+Math.imul(L,$)|0)+Math.imul(D,j)|0,i=i+Math.imul(D,$)|0,r=r+Math.imul(O,Z)|0,o=(o=o+Math.imul(O,Q)|0)+Math.imul(R,Z)|0,i=i+Math.imul(R,Q)|0,r=r+Math.imul(C,J)|0,o=(o=o+Math.imul(C,tt)|0)+Math.imul(E,J)|0,i=i+Math.imul(E,tt)|0,r=r+Math.imul(M,nt)|0,o=(o=o+Math.imul(M,rt)|0)+Math.imul(S,nt)|0,i=i+Math.imul(S,rt)|0,r=r+Math.imul(T,it)|0,o=(o=o+Math.imul(T,st)|0)+Math.imul(k,it)|0,i=i+Math.imul(k,st)|0,r=r+Math.imul(I,ut)|0,o=(o=o+Math.imul(I,ct)|0)+Math.imul(v,ut)|0,i=i+Math.imul(v,ct)|0,r=r+Math.imul(y,dt)|0,o=(o=o+Math.imul(y,pt)|0)+Math.imul(b,dt)|0,i=i+Math.imul(b,pt)|0;var Mt=(c+(r=r+Math.imul(h,ht)|0)|0)+((8191&(o=(o=o+Math.imul(h,ft)|0)+Math.imul(f,ht)|0))<<13)|0;c=((i=i+Math.imul(f,ft)|0)+(o>>>13)|0)+(Mt>>>26)|0,Mt&=67108863,r=Math.imul(U,j),o=(o=Math.imul(U,$))+Math.imul(N,j)|0,i=Math.imul(N,$),r=r+Math.imul(L,Z)|0,o=(o=o+Math.imul(L,Q)|0)+Math.imul(D,Z)|0,i=i+Math.imul(D,Q)|0,r=r+Math.imul(O,J)|0,o=(o=o+Math.imul(O,tt)|0)+Math.imul(R,J)|0,i=i+Math.imul(R,tt)|0,r=r+Math.imul(C,nt)|0,o=(o=o+Math.imul(C,rt)|0)+Math.imul(E,nt)|0,i=i+Math.imul(E,rt)|0,r=r+Math.imul(M,it)|0,o=(o=o+Math.imul(M,st)|0)+Math.imul(S,it)|0,i=i+Math.imul(S,st)|0,r=r+Math.imul(T,ut)|0,o=(o=o+Math.imul(T,ct)|0)+Math.imul(k,ut)|0,i=i+Math.imul(k,ct)|0,r=r+Math.imul(I,dt)|0,o=(o=o+Math.imul(I,pt)|0)+Math.imul(v,dt)|0,i=i+Math.imul(v,pt)|0;var St=(c+(r=r+Math.imul(y,ht)|0)|0)+((8191&(o=(o=o+Math.imul(y,ft)|0)+Math.imul(b,ht)|0))<<13)|0;c=((i=i+Math.imul(b,ft)|0)+(o>>>13)|0)+(St>>>26)|0,St&=67108863,r=Math.imul(U,Z),o=(o=Math.imul(U,Q))+Math.imul(N,Z)|0,i=Math.imul(N,Q),r=r+Math.imul(L,J)|0,o=(o=o+Math.imul(L,tt)|0)+Math.imul(D,J)|0,i=i+Math.imul(D,tt)|0,r=r+Math.imul(O,nt)|0,o=(o=o+Math.imul(O,rt)|0)+Math.imul(R,nt)|0,i=i+Math.imul(R,rt)|0,r=r+Math.imul(C,it)|0,o=(o=o+Math.imul(C,st)|0)+Math.imul(E,it)|0,i=i+Math.imul(E,st)|0,r=r+Math.imul(M,ut)|0,o=(o=o+Math.imul(M,ct)|0)+Math.imul(S,ut)|0,i=i+Math.imul(S,ct)|0,r=r+Math.imul(T,dt)|0,o=(o=o+Math.imul(T,pt)|0)+Math.imul(k,dt)|0,i=i+Math.imul(k,pt)|0;var xt=(c+(r=r+Math.imul(I,ht)|0)|0)+((8191&(o=(o=o+Math.imul(I,ft)|0)+Math.imul(v,ht)|0))<<13)|0;c=((i=i+Math.imul(v,ft)|0)+(o>>>13)|0)+(xt>>>26)|0,xt&=67108863,r=Math.imul(U,J),o=(o=Math.imul(U,tt))+Math.imul(N,J)|0,i=Math.imul(N,tt),r=r+Math.imul(L,nt)|0,o=(o=o+Math.imul(L,rt)|0)+Math.imul(D,nt)|0,i=i+Math.imul(D,rt)|0,r=r+Math.imul(O,it)|0,o=(o=o+Math.imul(O,st)|0)+Math.imul(R,it)|0,i=i+Math.imul(R,st)|0,r=r+Math.imul(C,ut)|0,o=(o=o+Math.imul(C,ct)|0)+Math.imul(E,ut)|0,i=i+Math.imul(E,ct)|0,r=r+Math.imul(M,dt)|0,o=(o=o+Math.imul(M,pt)|0)+Math.imul(S,dt)|0,i=i+Math.imul(S,pt)|0;var Ct=(c+(r=r+Math.imul(T,ht)|0)|0)+((8191&(o=(o=o+Math.imul(T,ft)|0)+Math.imul(k,ht)|0))<<13)|0;c=((i=i+Math.imul(k,ft)|0)+(o>>>13)|0)+(Ct>>>26)|0,Ct&=67108863,r=Math.imul(U,nt),o=(o=Math.imul(U,rt))+Math.imul(N,nt)|0,i=Math.imul(N,rt),r=r+Math.imul(L,it)|0,o=(o=o+Math.imul(L,st)|0)+Math.imul(D,it)|0,i=i+Math.imul(D,st)|0,r=r+Math.imul(O,ut)|0,o=(o=o+Math.imul(O,ct)|0)+Math.imul(R,ut)|0,i=i+Math.imul(R,ct)|0,r=r+Math.imul(C,dt)|0,o=(o=o+Math.imul(C,pt)|0)+Math.imul(E,dt)|0,i=i+Math.imul(E,pt)|0;var Et=(c+(r=r+Math.imul(M,ht)|0)|0)+((8191&(o=(o=o+Math.imul(M,ft)|0)+Math.imul(S,ht)|0))<<13)|0;c=((i=i+Math.imul(S,ft)|0)+(o>>>13)|0)+(Et>>>26)|0,Et&=67108863,r=Math.imul(U,it),o=(o=Math.imul(U,st))+Math.imul(N,it)|0,i=Math.imul(N,st),r=r+Math.imul(L,ut)|0,o=(o=o+Math.imul(L,ct)|0)+Math.imul(D,ut)|0,i=i+Math.imul(D,ct)|0,r=r+Math.imul(O,dt)|0,o=(o=o+Math.imul(O,pt)|0)+Math.imul(R,dt)|0,i=i+Math.imul(R,pt)|0;var _t=(c+(r=r+Math.imul(C,ht)|0)|0)+((8191&(o=(o=o+Math.imul(C,ft)|0)+Math.imul(E,ht)|0))<<13)|0;c=((i=i+Math.imul(E,ft)|0)+(o>>>13)|0)+(_t>>>26)|0,_t&=67108863,r=Math.imul(U,ut),o=(o=Math.imul(U,ct))+Math.imul(N,ut)|0,i=Math.imul(N,ct),r=r+Math.imul(L,dt)|0,o=(o=o+Math.imul(L,pt)|0)+Math.imul(D,dt)|0,i=i+Math.imul(D,pt)|0;var Ot=(c+(r=r+Math.imul(O,ht)|0)|0)+((8191&(o=(o=o+Math.imul(O,ft)|0)+Math.imul(R,ht)|0))<<13)|0;c=((i=i+Math.imul(R,ft)|0)+(o>>>13)|0)+(Ot>>>26)|0,Ot&=67108863,r=Math.imul(U,dt),o=(o=Math.imul(U,pt))+Math.imul(N,dt)|0,i=Math.imul(N,pt);var Rt=(c+(r=r+Math.imul(L,ht)|0)|0)+((8191&(o=(o=o+Math.imul(L,ft)|0)+Math.imul(D,ht)|0))<<13)|0;c=((i=i+Math.imul(D,ft)|0)+(o>>>13)|0)+(Rt>>>26)|0,Rt&=67108863;var Bt=(c+(r=Math.imul(U,ht))|0)+((8191&(o=(o=Math.imul(U,ft))+Math.imul(N,ht)|0))<<13)|0;return c=((i=Math.imul(N,ft))+(o>>>13)|0)+(Bt>>>26)|0,Bt&=67108863,u[0]=gt,u[1]=yt,u[2]=bt,u[3]=wt,u[4]=It,u[5]=vt,u[6]=At,u[7]=Tt,u[8]=kt,u[9]=Pt,u[10]=Mt,u[11]=St,u[12]=xt,u[13]=Ct,u[14]=Et,u[15]=_t,u[16]=Ot,u[17]=Rt,u[18]=Bt,0!==c&&(u[19]=c,n.length++),n};function g(t,e,n){n.negative=e.negative^t.negative,n.length=t.length+e.length;for(var r=0,o=0,i=0;i<n.length-1;i++){var s=o;o=0;for(var a=67108863&r,u=Math.min(i,e.length-1),c=Math.max(0,i-t.length+1);c<=u;c++){var l=i-c,d=(0|t.words[l])*(0|e.words[c]),p=67108863&d;a=67108863&(p=p+a|0),o+=(s=(s=s+(d/67108864|0)|0)+(p>>>26)|0)>>>26,s&=67108863}n.words[i]=a,r=s,s=o}return 0!==r?n.words[i]=r:n.length--,n._strip()}function y(t,e,n){return g(t,e,n)}Math.imul||(f=h),o.prototype.mulTo=function(t,e){var n=this.length+t.length;return 10===this.length&&10===t.length?f(this,t,e):n<63?h(this,t,e):n<1024?g(this,t,e):y(this,t,e)},o.prototype.mul=function(t){var e=new o(null);return e.words=new Array(this.length+t.length),this.mulTo(t,e)},o.prototype.mulf=function(t){var e=new o(null);return e.words=new Array(this.length+t.length),y(this,t,e)},o.prototype.imul=function(t){return this.clone().mulTo(t,this)},o.prototype.imuln=function(t){var e=t<0;e&&(t=-t),n("number"==typeof t),n(t<67108864);for(var r=0,o=0;o<this.length;o++){var i=(0|this.words[o])*t,s=(67108863&i)+(67108863&r);r>>=26,r+=i/67108864|0,r+=s>>>26,this.words[o]=67108863&s}return 0!==r&&(this.words[o]=r,this.length++),e?this.ineg():this},o.prototype.muln=function(t){return this.clone().imuln(t)},o.prototype.sqr=function(){return this.mul(this)},o.prototype.isqr=function(){return this.imul(this.clone())},o.prototype.pow=function(t){var e=function(t){for(var e=new Array(t.bitLength()),n=0;n<e.length;n++){var r=n/26|0,o=n%26;e[n]=t.words[r]>>>o&1}return e}(t);if(0===e.length)return new o(1);for(var n=this,r=0;r<e.length&&0===e[r];r++,n=n.sqr());if(++r<e.length)for(var i=n.sqr();r<e.length;r++,i=i.sqr())0!==e[r]&&(n=n.mul(i));return n},o.prototype.iushln=function(t){n("number"==typeof t&&t>=0);var e,r=t%26,o=(t-r)/26,i=67108863>>>26-r<<26-r;if(0!==r){var s=0;for(e=0;e<this.length;e++){var a=this.words[e]&i,u=(0|this.words[e])-a<<r;this.words[e]=u|s,s=a>>>26-r}s&&(this.words[e]=s,this.length++)}if(0!==o){for(e=this.length-1;e>=0;e--)this.words[e+o]=this.words[e];for(e=0;e<o;e++)this.words[e]=0;this.length+=o}return this._strip()},o.prototype.ishln=function(t){return n(0===this.negative),this.iushln(t)},o.prototype.iushrn=function(t,e,r){var o;n("number"==typeof t&&t>=0),o=e?(e-e%26)/26:0;var i=t%26,s=Math.min((t-i)/26,this.length),a=67108863^67108863>>>i<<i,u=r;if(o-=s,o=Math.max(0,o),u){for(var c=0;c<s;c++)u.words[c]=this.words[c];u.length=s}if(0===s);else if(this.length>s)for(this.length-=s,c=0;c<this.length;c++)this.words[c]=this.words[c+s];else this.words[0]=0,this.length=1;var l=0;for(c=this.length-1;c>=0&&(0!==l||c>=o);c--){var d=0|this.words[c];this.words[c]=l<<26-i|d>>>i,l=d&a}return u&&0!==l&&(u.words[u.length++]=l),0===this.length&&(this.words[0]=0,this.length=1),this._strip()},o.prototype.ishrn=function(t,e,r){return n(0===this.negative),this.iushrn(t,e,r)},o.prototype.shln=function(t){return this.clone().ishln(t)},o.prototype.ushln=function(t){return this.clone().iushln(t)},o.prototype.shrn=function(t){return this.clone().ishrn(t)},o.prototype.ushrn=function(t){return this.clone().iushrn(t)},o.prototype.testn=function(t){n("number"==typeof t&&t>=0);var e=t%26,r=(t-e)/26,o=1<<e;return this.length<=r?0:!!(this.words[r]&o)},o.prototype.imaskn=function(t){n("number"==typeof t&&t>=0);var e=t%26,r=(t-e)/26;if(n(0===this.negative,"imaskn works only with positive numbers"),this.length<=r)return this;if(0!==e&&r++,this.length=Math.min(r,this.length),0!==e){var o=67108863^67108863>>>e<<e;this.words[this.length-1]&=o}return this._strip()},o.prototype.maskn=function(t){return this.clone().imaskn(t)},o.prototype.iaddn=function(t){return n("number"==typeof t),n(t<67108864),t<0?this.isubn(-t):0!==this.negative?1===this.length&&(0|this.words[0])<=t?(this.words[0]=t-(0|this.words[0]),this.negative=0,this):(this.negative=0,this.isubn(t),this.negative=1,this):this._iaddn(t)},o.prototype._iaddn=function(t){this.words[0]+=t;for(var e=0;e<this.length&&this.words[e]>=67108864;e++)this.words[e]-=67108864,e===this.length-1?this.words[e+1]=1:this.words[e+1]++;return this.length=Math.max(this.length,e+1),this},o.prototype.isubn=function(t){if(n("number"==typeof t),n(t<67108864),t<0)return this.iaddn(-t);if(0!==this.negative)return this.negative=0,this.iaddn(t),this.negative=1,this;if(this.words[0]-=t,1===this.length&&this.words[0]<0)this.words[0]=-this.words[0],this.negative=1;else for(var e=0;e<this.length&&this.words[e]<0;e++)this.words[e]+=67108864,this.words[e+1]-=1;return this._strip()},o.prototype.addn=function(t){return this.clone().iaddn(t)},o.prototype.subn=function(t){return this.clone().isubn(t)},o.prototype.iabs=function(){return this.negative=0,this},o.prototype.abs=function(){return this.clone().iabs()},o.prototype._ishlnsubmul=function(t,e,r){var o,i,s=t.length+r;this._expand(s);var a=0;for(o=0;o<t.length;o++){i=(0|this.words[o+r])+a;var u=(0|t.words[o])*e;a=((i-=67108863&u)>>26)-(u/67108864|0),this.words[o+r]=67108863&i}for(;o<this.length-r;o++)a=(i=(0|this.words[o+r])+a)>>26,this.words[o+r]=67108863&i;if(0===a)return this._strip();for(n(-1===a),a=0,o=0;o<this.length;o++)a=(i=-(0|this.words[o])+a)>>26,this.words[o]=67108863&i;return this.negative=1,this._strip()},o.prototype._wordDiv=function(t,e){var n=(this.length,t.length),r=this.clone(),i=t,s=0|i.words[i.length-1];0!=(n=26-this._countBits(s))&&(i=i.ushln(n),r.iushln(n),s=0|i.words[i.length-1]);var a,u=r.length-i.length;if("mod"!==e){(a=new o(null)).length=u+1,a.words=new Array(a.length);for(var c=0;c<a.length;c++)a.words[c]=0}var l=r.clone()._ishlnsubmul(i,1,u);0===l.negative&&(r=l,a&&(a.words[u]=1));for(var d=u-1;d>=0;d--){var p=67108864*(0|r.words[i.length+d])+(0|r.words[i.length+d-1]);for(p=Math.min(p/s|0,67108863),r._ishlnsubmul(i,p,d);0!==r.negative;)p--,r.negative=0,r._ishlnsubmul(i,1,d),r.isZero()||(r.negative^=1);a&&(a.words[d]=p)}return a&&a._strip(),r._strip(),"div"!==e&&0!==n&&r.iushrn(n),{div:a||null,mod:r}},o.prototype.divmod=function(t,e,r){return n(!t.isZero()),this.isZero()?{div:new o(0),mod:new o(0)}:0!==this.negative&&0===t.negative?(a=this.neg().divmod(t,e),"mod"!==e&&(i=a.div.neg()),"div"!==e&&(s=a.mod.neg(),r&&0!==s.negative&&s.iadd(t)),{div:i,mod:s}):0===this.negative&&0!==t.negative?(a=this.divmod(t.neg(),e),"mod"!==e&&(i=a.div.neg()),{div:i,mod:a.mod}):0!=(this.negative&t.negative)?(a=this.neg().divmod(t.neg(),e),"div"!==e&&(s=a.mod.neg(),r&&0!==s.negative&&s.isub(t)),{div:a.div,mod:s}):t.length>this.length||this.cmp(t)<0?{div:new o(0),mod:this}:1===t.length?"div"===e?{div:this.divn(t.words[0]),mod:null}:"mod"===e?{div:null,mod:new o(this.modrn(t.words[0]))}:{div:this.divn(t.words[0]),mod:new o(this.modrn(t.words[0]))}:this._wordDiv(t,e);var i,s,a},o.prototype.div=function(t){return this.divmod(t,"div",0).div},o.prototype.mod=function(t){return this.divmod(t,"mod",0).mod},o.prototype.umod=function(t){return this.divmod(t,"mod",1).mod},o.prototype.divRound=function(t){var e=this.divmod(t);if(e.mod.isZero())return e.div;var n=0!==e.div.negative?e.mod.isub(t):e.mod,r=t.ushrn(1),o=t.andln(1),i=n.cmp(r);return i<0||1===o&&0===i?e.div:0!==e.div.negative?e.div.isubn(1):e.div.iaddn(1)},o.prototype.modrn=function(t){var e=t<0;e&&(t=-t),n(t<=67108863);for(var r=(1<<26)%t,o=0,i=this.length-1;i>=0;i--)o=(r*o+(0|this.words[i]))%t;return e?-o:o},o.prototype.modn=function(t){return this.modrn(t)},o.prototype.idivn=function(t){var e=t<0;e&&(t=-t),n(t<=67108863);for(var r=0,o=this.length-1;o>=0;o--){var i=(0|this.words[o])+67108864*r;this.words[o]=i/t|0,r=i%t}return this._strip(),e?this.ineg():this},o.prototype.divn=function(t){return this.clone().idivn(t)},o.prototype.egcd=function(t){n(0===t.negative),n(!t.isZero());var e=this,r=t.clone();e=0!==e.negative?e.umod(t):e.clone();for(var i=new o(1),s=new o(0),a=new o(0),u=new o(1),c=0;e.isEven()&&r.isEven();)e.iushrn(1),r.iushrn(1),++c;for(var l=r.clone(),d=e.clone();!e.isZero();){for(var p=0,m=1;0==(e.words[0]&m)&&p<26;++p,m<<=1);if(p>0)for(e.iushrn(p);p-- >0;)(i.isOdd()||s.isOdd())&&(i.iadd(l),s.isub(d)),i.iushrn(1),s.iushrn(1);for(var h=0,f=1;0==(r.words[0]&f)&&h<26;++h,f<<=1);if(h>0)for(r.iushrn(h);h-- >0;)(a.isOdd()||u.isOdd())&&(a.iadd(l),u.isub(d)),a.iushrn(1),u.iushrn(1);e.cmp(r)>=0?(e.isub(r),i.isub(a),s.isub(u)):(r.isub(e),a.isub(i),u.isub(s))}return{a:a,b:u,gcd:r.iushln(c)}},o.prototype._invmp=function(t){n(0===t.negative),n(!t.isZero());var e=this,r=t.clone();e=0!==e.negative?e.umod(t):e.clone();for(var i,s=new o(1),a=new o(0),u=r.clone();e.cmpn(1)>0&&r.cmpn(1)>0;){for(var c=0,l=1;0==(e.words[0]&l)&&c<26;++c,l<<=1);if(c>0)for(e.iushrn(c);c-- >0;)s.isOdd()&&s.iadd(u),s.iushrn(1);for(var d=0,p=1;0==(r.words[0]&p)&&d<26;++d,p<<=1);if(d>0)for(r.iushrn(d);d-- >0;)a.isOdd()&&a.iadd(u),a.iushrn(1);e.cmp(r)>=0?(e.isub(r),s.isub(a)):(r.isub(e),a.isub(s))}return(i=0===e.cmpn(1)?s:a).cmpn(0)<0&&i.iadd(t),i},o.prototype.gcd=function(t){if(this.isZero())return t.abs();if(t.isZero())return this.abs();var e=this.clone(),n=t.clone();e.negative=0,n.negative=0;for(var r=0;e.isEven()&&n.isEven();r++)e.iushrn(1),n.iushrn(1);for(;;){for(;e.isEven();)e.iushrn(1);for(;n.isEven();)n.iushrn(1);var o=e.cmp(n);if(o<0){var i=e;e=n,n=i}else if(0===o||0===n.cmpn(1))break;e.isub(n)}return n.iushln(r)},o.prototype.invm=function(t){return this.egcd(t).a.umod(t)},o.prototype.isEven=function(){return 0==(1&this.words[0])},o.prototype.isOdd=function(){return 1==(1&this.words[0])},o.prototype.andln=function(t){return this.words[0]&t},o.prototype.bincn=function(t){n("number"==typeof t);var e=t%26,r=(t-e)/26,o=1<<e;if(this.length<=r)return this._expand(r+1),this.words[r]|=o,this;for(var i=o,s=r;0!==i&&s<this.length;s++){var a=0|this.words[s];i=(a+=i)>>>26,a&=67108863,this.words[s]=a}return 0!==i&&(this.words[s]=i,this.length++),this},o.prototype.isZero=function(){return 1===this.length&&0===this.words[0]},o.prototype.cmpn=function(t){var e,r=t<0;if(0!==this.negative&&!r)return-1;if(0===this.negative&&r)return 1;if(this._strip(),this.length>1)e=1;else{r&&(t=-t),n(t<=67108863,"Number is too big");var o=0|this.words[0];e=o===t?0:o<t?-1:1}return 0!==this.negative?0|-e:e},o.prototype.cmp=function(t){if(0!==this.negative&&0===t.negative)return-1;if(0===this.negative&&0!==t.negative)return 1;var e=this.ucmp(t);return 0!==this.negative?0|-e:e},o.prototype.ucmp=function(t){if(this.length>t.length)return 1;if(this.length<t.length)return-1;for(var e=0,n=this.length-1;n>=0;n--){var r=0|this.words[n],o=0|t.words[n];if(r!==o){r<o?e=-1:r>o&&(e=1);break}}return e},o.prototype.gtn=function(t){return 1===this.cmpn(t)},o.prototype.gt=function(t){return 1===this.cmp(t)},o.prototype.gten=function(t){return this.cmpn(t)>=0},o.prototype.gte=function(t){return this.cmp(t)>=0},o.prototype.ltn=function(t){return-1===this.cmpn(t)},o.prototype.lt=function(t){return-1===this.cmp(t)},o.prototype.lten=function(t){return this.cmpn(t)<=0},o.prototype.lte=function(t){return this.cmp(t)<=0},o.prototype.eqn=function(t){return 0===this.cmpn(t)},o.prototype.eq=function(t){return 0===this.cmp(t)},o.red=function(t){return new k(t)},o.prototype.toRed=function(t){return n(!this.red,"Already a number in reduction context"),n(0===this.negative,"red works only with positives"),t.convertTo(this)._forceRed(t)},o.prototype.fromRed=function(){return n(this.red,"fromRed works only with numbers in reduction context"),this.red.convertFrom(this)},o.prototype._forceRed=function(t){return this.red=t,this},o.prototype.forceRed=function(t){return n(!this.red,"Already a number in reduction context"),this._forceRed(t)},o.prototype.redAdd=function(t){return n(this.red,"redAdd works only with red numbers"),this.red.add(this,t)},o.prototype.redIAdd=function(t){return n(this.red,"redIAdd works only with red numbers"),this.red.iadd(this,t)},o.prototype.redSub=function(t){return n(this.red,"redSub works only with red numbers"),this.red.sub(this,t)},o.prototype.redISub=function(t){return n(this.red,"redISub works only with red numbers"),this.red.isub(this,t)},o.prototype.redShl=function(t){return n(this.red,"redShl works only with red numbers"),this.red.shl(this,t)},o.prototype.redMul=function(t){return n(this.red,"redMul works only with red numbers"),this.red._verify2(this,t),this.red.mul(this,t)},o.prototype.redIMul=function(t){return n(this.red,"redMul works only with red numbers"),this.red._verify2(this,t),this.red.imul(this,t)},o.prototype.redSqr=function(){return n(this.red,"redSqr works only with red numbers"),this.red._verify1(this),this.red.sqr(this)},o.prototype.redISqr=function(){return n(this.red,"redISqr works only with red numbers"),this.red._verify1(this),this.red.isqr(this)},o.prototype.redSqrt=function(){return n(this.red,"redSqrt works only with red numbers"),this.red._verify1(this),this.red.sqrt(this)},o.prototype.redInvm=function(){return n(this.red,"redInvm works only with red numbers"),this.red._verify1(this),this.red.invm(this)},o.prototype.redNeg=function(){return n(this.red,"redNeg works only with red numbers"),this.red._verify1(this),this.red.neg(this)},o.prototype.redPow=function(t){return n(this.red&&!t.red,"redPow(normalNum)"),this.red._verify1(this),this.red.pow(this,t)};var b={k256:null,p224:null,p192:null,p25519:null};function w(t,e){this.name=t,this.p=new o(e,16),this.n=this.p.bitLength(),this.k=new o(1).iushln(this.n).isub(this.p),this.tmp=this._tmp()}function I(){w.call(this,"k256","ffffffff ffffffff ffffffff ffffffff ffffffff ffffffff fffffffe fffffc2f")}function v(){w.call(this,"p224","ffffffff ffffffff ffffffff ffffffff 00000000 00000000 00000001")}function A(){w.call(this,"p192","ffffffff ffffffff ffffffff fffffffe ffffffff ffffffff")}function T(){w.call(this,"25519","7fffffffffffffff ffffffffffffffff ffffffffffffffff ffffffffffffffed")}function k(t){if("string"==typeof t){var e=o._prime(t);this.m=e.p,this.prime=e}else n(t.gtn(1),"modulus must be greater than 1"),this.m=t,this.prime=null}function P(t){k.call(this,t),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)}w.prototype._tmp=function(){var t=new o(null);return t.words=new Array(Math.ceil(this.n/13)),t},w.prototype.ireduce=function(t){var e,n=t;do{this.split(n,this.tmp),e=(n=(n=this.imulK(n)).iadd(this.tmp)).bitLength()}while(e>this.n);var r=e<this.n?-1:n.ucmp(this.p);return 0===r?(n.words[0]=0,n.length=1):r>0?n.isub(this.p):void 0!==n.strip?n.strip():n._strip(),n},w.prototype.split=function(t,e){t.iushrn(this.n,0,e)},w.prototype.imulK=function(t){return t.imul(this.k)},r(I,w),I.prototype.split=function(t,e){for(var n=4194303,r=Math.min(t.length,9),o=0;o<r;o++)e.words[o]=t.words[o];if(e.length=r,t.length<=9)return t.words[0]=0,void(t.length=1);var i=t.words[9];for(e.words[e.length++]=i&n,o=10;o<t.length;o++){var s=0|t.words[o];t.words[o-10]=(s&n)<<4|i>>>22,i=s}i>>>=22,t.words[o-10]=i,0===i&&t.length>10?t.length-=10:t.length-=9},I.prototype.imulK=function(t){t.words[t.length]=0,t.words[t.length+1]=0,t.length+=2;for(var e=0,n=0;n<t.length;n++){var r=0|t.words[n];e+=977*r,t.words[n]=67108863&e,e=64*r+(e/67108864|0)}return 0===t.words[t.length-1]&&(t.length--,0===t.words[t.length-1]&&t.length--),t},r(v,w),r(A,w),r(T,w),T.prototype.imulK=function(t){for(var e=0,n=0;n<t.length;n++){var r=19*(0|t.words[n])+e,o=67108863&r;r>>>=26,t.words[n]=o,e=r}return 0!==e&&(t.words[t.length++]=e),t},o._prime=function(t){if(b[t])return b[t];var e;if("k256"===t)e=new I;else if("p224"===t)e=new v;else if("p192"===t)e=new A;else{if("p25519"!==t)throw new Error("Unknown prime "+t);e=new T}return b[t]=e,e},k.prototype._verify1=function(t){n(0===t.negative,"red works only with positives"),n(t.red,"red works only with red numbers")},k.prototype._verify2=function(t,e){n(0==(t.negative|e.negative),"red works only with positives"),n(t.red&&t.red===e.red,"red works only with red numbers")},k.prototype.imod=function(t){return this.prime?this.prime.ireduce(t)._forceRed(this):(c(t,t.umod(this.m)._forceRed(this)),t)},k.prototype.neg=function(t){return t.isZero()?t.clone():this.m.sub(t)._forceRed(this)},k.prototype.add=function(t,e){this._verify2(t,e);var n=t.add(e);return n.cmp(this.m)>=0&&n.isub(this.m),n._forceRed(this)},k.prototype.iadd=function(t,e){this._verify2(t,e);var n=t.iadd(e);return n.cmp(this.m)>=0&&n.isub(this.m),n},k.prototype.sub=function(t,e){this._verify2(t,e);var n=t.sub(e);return n.cmpn(0)<0&&n.iadd(this.m),n._forceRed(this)},k.prototype.isub=function(t,e){this._verify2(t,e);var n=t.isub(e);return n.cmpn(0)<0&&n.iadd(this.m),n},k.prototype.shl=function(t,e){return this._verify1(t),this.imod(t.ushln(e))},k.prototype.imul=function(t,e){return this._verify2(t,e),this.imod(t.imul(e))},k.prototype.mul=function(t,e){return this._verify2(t,e),this.imod(t.mul(e))},k.prototype.isqr=function(t){return this.imul(t,t.clone())},k.prototype.sqr=function(t){return this.mul(t,t)},k.prototype.sqrt=function(t){if(t.isZero())return t.clone();var e=this.m.andln(3);if(n(e%2==1),3===e){var r=this.m.add(new o(1)).iushrn(2);return this.pow(t,r)}for(var i=this.m.subn(1),s=0;!i.isZero()&&0===i.andln(1);)s++,i.iushrn(1);n(!i.isZero());var a=new o(1).toRed(this),u=a.redNeg(),c=this.m.subn(1).iushrn(1),l=this.m.bitLength();for(l=new o(2*l*l).toRed(this);0!==this.pow(l,c).cmp(u);)l.redIAdd(u);for(var d=this.pow(l,i),p=this.pow(t,i.addn(1).iushrn(1)),m=this.pow(t,i),h=s;0!==m.cmp(a);){for(var f=m,g=0;0!==f.cmp(a);g++)f=f.redSqr();n(g<h);var y=this.pow(d,new o(1).iushln(h-g-1));p=p.redMul(y),d=y.redSqr(),m=m.redMul(d),h=g}return p},k.prototype.invm=function(t){var e=t._invmp(this.m);return 0!==e.negative?(e.negative=0,this.imod(e).redNeg()):this.imod(e)},k.prototype.pow=function(t,e){if(e.isZero())return new o(1).toRed(this);if(0===e.cmpn(1))return t.clone();var n=new Array(16);n[0]=new o(1).toRed(this),n[1]=t;for(var r=2;r<n.length;r++)n[r]=this.mul(n[r-1],t);var i=n[0],s=0,a=0,u=e.bitLength()%26;for(0===u&&(u=26),r=e.length-1;r>=0;r--){for(var c=e.words[r],l=u-1;l>=0;l--){var d=c>>l&1;i!==n[0]&&(i=this.sqr(i)),0!==d||0!==s?(s<<=1,s|=d,(4==++a||0===r&&0===l)&&(i=this.mul(i,n[s]),a=0,s=0)):a=0}u=26}return i},k.prototype.convertTo=function(t){var e=t.umod(this.m);return e===t?e.clone():e},k.prototype.convertFrom=function(t){var e=t.clone();return e.red=null,e},o.mont=function(t){return new P(t)},r(P,k),P.prototype.convertTo=function(t){return this.imod(t.ushln(this.shift))},P.prototype.convertFrom=function(t){var e=this.imod(t.mul(this.rinv));return e.red=null,e},P.prototype.imul=function(t,e){if(t.isZero()||e.isZero())return t.words[0]=0,t.length=1,t;var n=t.imul(e),r=n.maskn(this.shift).mul(this.minv).imaskn(this.shift).mul(this.m),o=n.isub(r).iushrn(this.shift),i=o;return o.cmp(this.m)>=0?i=o.isub(this.m):o.cmpn(0)<0&&(i=o.iadd(this.m)),i._forceRed(this)},P.prototype.mul=function(t,e){if(t.isZero()||e.isZero())return new o(0)._forceRed(this);var n=t.mul(e),r=n.maskn(this.shift).mul(this.minv).imaskn(this.shift).mul(this.m),i=n.isub(r).iushrn(this.shift),s=i;return i.cmp(this.m)>=0?s=i.isub(this.m):i.cmpn(0)<0&&(s=i.iadd(this.m)),s._forceRed(this)},P.prototype.invm=function(t){return this.imod(t._invmp(this.m).mul(this.r2))._forceRed(this)}}(0,wn);var kn=In(An.exports);const Pn="fetchByOwner is required",Mn="No light-token balance to unwrap",Sn="Mint does not have MerkleContext",xn={Spl:"spl",Token2022:"token2022",SplCold:"spl-cold",Token2022Cold:"token2022-cold",LightTokenHot:"light-token-hot",LightTokenCold:"light-token-cold"},Cn=new Set([xn.LightTokenCold,xn.SplCold,xn.Token2022Cold]);function En(t){return Cn.has(t)}function _n(t,e){e.length>0&&function(t,e){throw new Error(`${t}: ${function(t){return t instanceof Error?t.message:String(t)}(e)}`)}(t,e[0])}function On(t,e){if(t._anyFrozen)throw new Error(`Account is frozen. One or more sources (hot or cold) are frozen; ${e} is not allowed.`)}const Rn={0:0,1:0,2:0,3:0,4:0,5:0,6:0,7:0,8:0,9:0,10:0,11:0,12:0,13:0,14:0,15:0,16:0,17:0,18:0,19:void 0,20:0,21:0,22:0,23:0,24:0,25:0,26:0,27:0,28:0,29:8,30:1,31:17,32:void 0},Bn=31;function Ln(t,e){let r=BigInt(0);const o=function(t){if(!t||t.length<5)return null;try{let e=0;const n=t.readUInt32LE(e);e+=4;for(let r=0;r<n;r++){if(e>=t.length)return null;const n=t[e];if(e+=1,n===Bn)return e+8>t.length?null:BigInt(t.readUInt32LE(e))|BigInt(t.readUInt32LE(e+4))<<BigInt(32);const r=Rn[n];if(void 0===r)return null;e+=r}}catch(t){return null}return null}(e.tlv);return null!==o?r=o:e.delegate&&(r=BigInt(e.amount.toString())),{address:t,mint:e.mint,owner:e.owner,amount:BigInt(e.amount.toString()),delegate:e.delegate,delegatedAmount:r,isInitialized:e.state!==n.AccountState.Uninitialized,isFrozen:e.state===n.AccountState.Frozen,isNative:0,rentExemptReserve:null,closeAuthority:null,tlvData:e.tlv?w.from(e.tlv):w.alloc(0)}}function Dn(t){const e=w.from(t.data.discriminator),n=w.from(t.data.data),r=w.concat([e,n]);return{executable:0,owner:t.owner,lamports:t.lamports.toNumber(),data:r,rentEpoch:void 0}}function Kn(t,r){return{accountInfo:r,loadContext:void 0,parsed:n.unpackAccount(t,r,e.LIGHT_TOKEN_PROGRAM_ID),isCold:0}}function Un(e,n){const r=function(e){if(!e||0===e.length)return null;try{let n=0;const r=new t.PublicKey(e.slice(n,n+32));n+=32;const o=new t.PublicKey(e.slice(n,n+32));n+=32;const i=new kn(e.slice(n,n+8),"le");n+=8;const s=e[n];n+=1;const a=s?new t.PublicKey(e.slice(n,n+32)):null;n+=32;const u=e[n];n+=1;const c=e[n];return n+=1,{mint:r,owner:o,amount:i,delegate:a,state:u,tlv:c?e.slice(n):null}}catch(t){return console.error("Token data parsing error:",t),null}}(n.data.data);if(!r)throw new Error("Invalid token data");return{accountInfo:Dn(n),loadContext:{treeInfo:n.treeInfo,hash:n.hash,leafIndex:n.leafIndex,proveByIndex:n.proveByIndex},parsed:Ln(e,r),isCold:1}}async function Nn(t,n,r,o){return e.assertBetaEnabled(),Gn(t,n,r,o,void 0)}async function Wn(t,n,r,o,i,s,a=0,u=0){e.assertBetaEnabled();const c=hn(n,o,r,s,u);if(a&&"light-token"!==c.type)throw new Error(`For wrap=true, ata must be the light-token ATA. Got ${c.type} ATA instead.`);const l=await Gn(t,n,i,s,{owner:r,mint:o},a);return l._isAta=1,l._owner=r,l._mint=o,l}async function Gn(t,r,o,i,s,a=0){if(!r&&!s)throw new Error("One of address or fetchByOwner is required");if(!i)return async function(t,r,o,i,s){const a=null!=r?r:n.getAssociatedTokenAddressSync(i.mint,i.owner,0,e.LIGHT_TOKEN_PROGRAM_ID,mn(e.LIGHT_TOKEN_PROGRAM_ID)),u=[],c=[],l=[];if(u.push(async function(t,r,o){const i=await t.getAccountInfo(r,o);if(!i)return null;if(!i.owner.equals(e.LIGHT_TOKEN_PROGRAM_ID))throw new n.TokenInvalidAccountOwnerError;return Kn(r,i)}(t,a,o)),c.push(xn.LightTokenHot),l.push(a),s){if(!i)throw new Error("fetchByOwner is required for wrap=true to derive SPL/T22 addresses");const e=n.getAssociatedTokenAddressSync(i.mint,i.owner,0,n.TOKEN_PROGRAM_ID,mn(n.TOKEN_PROGRAM_ID)),r=n.getAssociatedTokenAddressSync(i.mint,i.owner,0,n.TOKEN_2022_PROGRAM_ID,mn(n.TOKEN_2022_PROGRAM_ID));u.push(async function(t,e,r){const o=await t.getAccountInfo(e,r);if(!o)return null;if(!o.owner.equals(n.TOKEN_PROGRAM_ID))throw new n.TokenInvalidAccountOwnerError;return{accountInfo:o,parsed:n.unpackAccount(e,o,n.TOKEN_PROGRAM_ID),isCold:0,loadContext:void 0}}(t,e,o)),c.push(xn.Spl),l.push(e),u.push(async function(t,e,r){const o=await t.getAccountInfo(e,r);if(!o)return null;if(!o.owner.equals(n.TOKEN_2022_PROGRAM_ID))throw new n.TokenInvalidAccountOwnerError;return{accountInfo:o,parsed:n.unpackAccount(e,o,n.TOKEN_2022_PROGRAM_ID),isCold:0,loadContext:void 0}}(t,r,o)),c.push(xn.Token2022),l.push(r)}const d=i?t.getCompressedTokenAccountsByOwner(i.owner,{mint:i.mint}):t.getCompressedTokenAccountsByOwner(r),p=await Promise.allSettled(u),m=[],h=[];let f=null;try{f=await d}catch(t){h.push(t)}const g=[];for(let t=0;t<p.length;t++){const e=p[t];if("fulfilled"===e.status){const n=e.value;if(!n)continue;g.push({type:c[t],address:l[t],amount:n.parsed.amount,accountInfo:n.accountInfo,loadContext:n.loadContext,parsed:n.parsed})}else e.reason instanceof n.TokenInvalidAccountOwnerError?m.push(e.reason):h.push(e.reason)}if(f)for(const t of f.items){const n=t.compressedAccount;if(n&&n.data&&n.data.data.length>0&&n.owner.equals(e.LIGHT_TOKEN_PROGRAM_ID)){const t=Un(a,n);g.push({type:xn.LightTokenCold,address:a,amount:t.parsed.amount,accountInfo:t.accountInfo,loadContext:t.loadContext,parsed:t.parsed})}}if(_n("Failed to fetch token account data from RPC",h),0===g.length){if(m.length>0)throw m[0];throw new n.TokenAccountNotFoundError}const y=[xn.LightTokenHot,xn.LightTokenCold,xn.Spl,xn.Token2022];return g.sort(((t,e)=>y.indexOf(t.type)-y.indexOf(e.type))),qn(g,a)}(t,r,o,s,a);if(i.equals(e.LIGHT_TOKEN_PROGRAM_ID))return async function(t,r,o,i){if(!r){if(!i)throw new Error(Pn);r=n.getAssociatedTokenAddressSync(i.mint,i.owner,0,e.LIGHT_TOKEN_PROGRAM_ID,mn(e.LIGHT_TOKEN_PROGRAM_ID))}const[s,a]=await Promise.allSettled([t.getAccountInfo(r,o),i?t.getCompressedTokenAccountsByOwner(i.owner,{mint:i.mint}):t.getCompressedTokenAccountsByOwner(r)]),u=[],c=[],l="fulfilled"===s.status?s.value:null;"rejected"===s.status&&u.push(s.reason);const d="fulfilled"===a.status?a.value.items.map((t=>t.compressedAccount)):[];"rejected"===a.status&&u.push(a.reason);const p=[];if(l)if(l.owner.equals(e.LIGHT_TOKEN_PROGRAM_ID)){const t=Kn(r,l);p.push({type:xn.LightTokenHot,address:r,amount:t.parsed.amount,accountInfo:l,parsed:t.parsed})}else c.push(new n.TokenInvalidAccountOwnerError);for(const t of d)if(t&&t.data&&t.data.data.length>0&&t.owner.equals(e.LIGHT_TOKEN_PROGRAM_ID)){const e=Un(r,t);p.push({type:xn.LightTokenCold,address:r,amount:e.parsed.amount,accountInfo:e.accountInfo,loadContext:e.loadContext,parsed:e.parsed})}if(_n("Failed to fetch token account data from RPC",u),0===p.length){if(c.length>0)throw c[0];throw new n.TokenAccountNotFoundError}return p.sort(((t,e)=>"light-token-hot"===t.type&&"light-token-cold"===e.type?-1:"light-token-cold"===t.type&&"light-token-hot"===e.type?1:0)),qn(p,r)}(t,r,o,s);if(i.equals(n.TOKEN_PROGRAM_ID)||i.equals(n.TOKEN_2022_PROGRAM_ID))return async function(t,r,o,i,s){if(!r){if(!s)throw new Error(Pn);r=n.getAssociatedTokenAddressSync(s.mint,s.owner,0,i,mn(i))}const a=i.equals(n.TOKEN_PROGRAM_ID)?xn.Spl:xn.Token2022,u=i.equals(n.TOKEN_PROGRAM_ID)?xn.SplCold:xn.Token2022Cold,[c,l]=await Promise.allSettled([t.getAccountInfo(r,o),s?t.getCompressedTokenAccountsByOwner(s.owner,{mint:s.mint}):Promise.resolve({items:[]})]),d=[],p=[],m=[],h="fulfilled"===c.status?c.value:null;"rejected"===c.status&&p.push(c.reason);const f="fulfilled"===l.status?l.value:{items:[]};if("rejected"===l.status&&p.push(l.reason),h)if(h.owner.equals(i))try{const t=n.unpackAccount(r,h,i);d.push({type:a,address:r,amount:t.amount,accountInfo:h,parsed:t})}catch(t){p.push(t)}else m.push(new n.TokenInvalidAccountOwnerError);for(const t of f.items){const n=t.compressedAccount;if(n&&n.data&&n.data.data.length>0&&n.owner.equals(e.LIGHT_TOKEN_PROGRAM_ID)){const t=Un(r,n);d.push({type:u,address:r,amount:t.parsed.amount,accountInfo:t.accountInfo,loadContext:t.loadContext,parsed:t.parsed})}}if(_n("Failed to fetch token account data from RPC",p),0===d.length){if(m.length>0)throw m[0];throw new n.TokenAccountNotFoundError}return qn(d,r)}(t,r,o,i,s);throw new Error(`Unsupported program ID: ${i.toBase58()}`)}function qn(t,e){const r=t.reduce(((t,e)=>t+e.amount),BigInt(0)),o=t[0],i=t.some((t=>null!==t.parsed.delegate)),s=t.some((t=>t.parsed.isFrozen)),a=t.some((t=>En(t.type))),u=t.length>1,c=(e,n)=>t.reduce(((t,r)=>{if(!n(r))return t;const o=r.parsed.delegate;return o&&o.equals(e)?t+(t=>{var e;const n=null!==(e=t.parsed.delegatedAmount)&&void 0!==e?e:t.amount;return t.amount<n?t.amount:n})(r):t}),BigInt(0)),l=t.find((t=>!En(t.type)&&null!==t.parsed.delegate)),d=t.filter((t=>En(t.type)&&null!==t.parsed.delegate));let p=null,m=BigInt(0);(null==l?void 0:l.parsed.delegate)?(p=l.parsed.delegate,m=c(p,(()=>1))):d.length>0&&(p=d[0].parsed.delegate,m=c(p,(t=>En(t.type))));const h=Object.assign(Object.assign(Object.assign({},o.parsed),{address:e,amount:r,isInitialized:o.parsed.isInitialized||a,delegate:p,delegatedAmount:m}),s?{state:n.AccountState.Frozen,isFrozen:1}:{});return{accountInfo:o.accountInfo,parsed:h,isCold:En(o.type),loadContext:o.loadContext,_sources:t,_needsConsolidation:u,_hasDelegate:i,_anyFrozen:s}}function Fn(t,e){var n;const r=t._owner;if(r&&e.equals(r))return t.parsed.amount;const o=t.parsed.delegate;if(o&&e.equals(o)){const e=null!==(n=t.parsed.delegatedAmount)&&void 0!==n?n:BigInt(0);return e<t.parsed.amount?e:t.parsed.amount}return BigInt(0)}function Vn(t,e){const n=t._owner;if(n&&e.equals(n))return 1;const r=t.parsed.delegate;return null!==r&&e.equals(r)}function Hn(t,e){var n;const r=t._owner;if(r&&e.equals(r))return t;const o=Fn(t,e),i=t.parsed.delegate;if(o===BigInt(0)||null===i||!e.equals(i))return Object.assign(Object.assign({},t),{_sources:[],_needsConsolidation:0,parsed:Object.assign(Object.assign({},t.parsed),{amount:BigInt(0)})});const s=(null!==(n=t._sources)&&void 0!==n?n:[]).filter((t=>null!==t.parsed.delegate&&t.parsed.delegate.equals(i))),a=s[0];return Object.assign(Object.assign(Object.assign({},t),a?{accountInfo:a.accountInfo,isCold:En(a.type),loadContext:a.loadContext}:{}),{_sources:s,_needsConsolidation:s.length>1,parsed:Object.assign(Object.assign({},t.parsed),{amount:o})})}function zn(t,r,o=0,i=e.LIGHT_TOKEN_PROGRAM_ID,s){const a=null!=s?s:mn(i);return n.getAssociatedTokenAddressSync(t,r,o,i,a)}const jn=w.from([101]),$n=19,Yn=31,Zn=32,Qn=0,Xn=1,Jn=r.struct([r.u64("delegatedAmount"),r.u64("withheldTransferFee"),r.bool("isFrozen"),r.u8("compressionIndex"),r.bool("isAta"),r.u8("bump"),r.u8("ownerIndex")]),tr=r.struct([r.u16("baseRent"),r.u16("compressionCost"),r.u8("lamportsPerBytePerEpoch"),r.u8("maxFundedEpochs"),r.u16("maxTopUp")]),er=r.struct([r.u16("configAccountVersion"),r.u8("compressToPubkey"),r.u8("accountVersion"),r.u32("lamportsPerWrite"),r.array(r.u8(),32,"compressionAuthority"),r.array(r.u8(),32,"rentSponsor"),r.u64("lastClaimedSlot"),r.u32("rentExemptionPaid"),r.u32("reserved"),tr.replicate("rentConfig")]);function nr(t){const n=w.alloc(1024);let r=0;if("TokenMetadata"===t.type){n.writeUInt8($n,r),r+=1;const e={updateAuthority:t.data.updateAuthority,name:t.data.name,symbol:t.data.symbol,uri:t.data.uri,additionalMetadata:t.data.additionalMetadata?t.data.additionalMetadata.map((t=>({key:w.from(t.key),value:w.from(t.value)}))):null};r+=Ge.encode(e,n,r)}else if("CompressedOnly"===t.type){n.writeUInt8(Yn,r),r+=1;const o={delegatedAmount:e.bn(t.data.delegatedAmount.toString()),withheldTransferFee:e.bn(t.data.withheldTransferFee.toString()),isFrozen:t.data.isFrozen,compressionIndex:t.data.compressionIndex,isAta:t.data.isAta,bump:t.data.bump,ownerIndex:t.data.ownerIndex};r+=Jn.encode(o,n,r)}else if("Compressible"===t.type){n.writeUInt8(Zn,r),r+=1;const o={configAccountVersion:t.data.configAccountVersion,compressToPubkey:t.data.compressToPubkey,accountVersion:t.data.accountVersion,lamportsPerWrite:t.data.lamportsPerWrite,compressionAuthority:Array.from(t.data.compressionAuthority.toBytes()),rentSponsor:Array.from(t.data.rentSponsor.toBytes()),lastClaimedSlot:e.bn(t.data.lastClaimedSlot.toString()),rentExemptionPaid:t.data.rentExemptionPaid,reserved:t.data.reserved,rentConfig:t.data.rentConfig};r+=er.encode(o,n,r)}return n.subarray(0,r)}function rr(t){if(null===t)return null;const e=[],n=w.alloc(4);n.writeUInt32LE(t.length,0),e.push(n);for(const n of t){const t=w.alloc(4);t.writeUInt32LE(n.length,0),e.push(t);for(const t of n)e.push(nr(t))}return w.concat(e)}const or=r.struct([r.u8("mode"),r.u64("amount"),r.u8("mint"),r.u8("sourceOrRecipient"),r.u8("authority"),r.u8("poolAccountIndex"),r.u8("poolIndex"),r.u8("bump"),r.u8("decimals")]),ir=r.struct([r.u8("merkleTreePubkeyIndex"),r.u8("queuePubkeyIndex"),r.u32("leafIndex"),r.bool("proveByIndex")]),sr=r.struct([r.u8("owner"),r.u64("amount"),r.bool("hasDelegate"),r.u8("delegate"),r.u8("mint"),r.u8("version"),ir.replicate("merkleContext"),r.u16("rootIndex")]),ar=r.struct([r.u8("owner"),r.u64("amount"),r.bool("hasDelegate"),r.u8("delegate"),r.u8("mint"),r.u8("version")]),ur=r.struct([r.bool("setContext"),r.bool("firstSetContext"),r.u8("cpiContextAccountIndex")]),cr=r.struct([r.bool("withTransactionHash"),r.bool("withLamportsChangeAccountMerkleTreeIndex"),r.u8("lamportsChangeAccountMerkleTreeIndex"),r.u8("lamportsChangeAccountOwnerIndex"),r.u8("outputQueue"),r.u16("maxTopUp"),r.option(ur,"cpiContext"),r.option(r.vec(or),"compressions"),r.option(Ke,"proof"),r.vec(sr,"inTokenData"),r.vec(ar,"outTokenData"),r.option(r.vec(r.u64()),"inLamports"),r.option(r.vec(r.u64()),"outLamports")]);function lr(t){var n,r,o,i,s,a;const u={withTransactionHash:t.withTransactionHash,withLamportsChangeAccountMerkleTreeIndex:t.withLamportsChangeAccountMerkleTreeIndex,lamportsChangeAccountMerkleTreeIndex:t.lamportsChangeAccountMerkleTreeIndex,lamportsChangeAccountOwnerIndex:t.lamportsChangeAccountOwnerIndex,outputQueue:t.outputQueue,maxTopUp:t.maxTopUp,cpiContext:t.cpiContext,compressions:null!==(r=null===(n=t.compressions)||void 0===n?void 0:n.map((t=>Object.assign(Object.assign({},t),{amount:e.bn(t.amount.toString())}))))&&void 0!==r?r:null,proof:t.proof,inTokenData:t.inTokenData.map((t=>Object.assign(Object.assign({},t),{amount:e.bn(t.amount.toString())}))),outTokenData:t.outTokenData.map((t=>Object.assign(Object.assign({},t),{amount:e.bn(t.amount.toString())}))),inLamports:null!==(i=null===(o=t.inLamports)||void 0===o?void 0:o.map((t=>e.bn(t.toString()))))&&void 0!==i?i:null,outLamports:null!==(a=null===(s=t.outLamports)||void 0===s?void 0:s.map((t=>e.bn(t.toString()))))&&void 0!==a?a:null},c=w.alloc(4e3),l=cr.encode(u,c),d=[jn,c.subarray(0,l)];if(null===t.inTlv)d.push(w.from([0]));else{d.push(w.from([1]));const e=rr(t.inTlv);e&&d.push(w.from(e))}if(null===t.outTlv)d.push(w.from([0]));else{d.push(w.from([1]));const e=rr(t.outTlv);e&&d.push(w.from(e))}return w.concat(d)}function dr(t,e,n,r,o,i,s,a){return{mode:Qn,amount:t,mint:e,sourceOrRecipient:n,authority:r,poolAccountIndex:o,poolIndex:i,bump:s,decimals:a}}function pr(t,e,n,r){return{mode:Xn,amount:t,mint:e,sourceOrRecipient:n,authority:0,poolAccountIndex:r,poolIndex:0,bump:0,decimals:0}}function mr(t,e,n,r,o){return{mode:Qn,amount:t,mint:e,sourceOrRecipient:n,authority:r,poolAccountIndex:o,poolIndex:0,bump:0,decimals:0}}function hr(t,e,n,r,o,i,s){return{mode:Xn,amount:t,mint:e,sourceOrRecipient:n,authority:0,poolAccountIndex:r,poolIndex:o,bump:i,decimals:s}}function fr(n,r,o,i,s,a,u,c=o,l){const d=[dr(s,0,2,1,4,a.poolIndex,a.bump,u),pr(s,0,3,6)],p=lr({withTransactionHash:0,withLamportsChangeAccountMerkleTreeIndex:0,lamportsChangeAccountMerkleTreeIndex:0,lamportsChangeAccountOwnerIndex:0,outputQueue:0,maxTopUp:null!=l?l:yt,cpiContext:null,compressions:d,proof:null,inTokenData:[],outTokenData:[],inLamports:null,outLamports:null,inTlv:null,outTlv:null}),m=[{pubkey:Ae.deriveCpiAuthorityPda,isSigner:0,isWritable:0},{pubkey:c,isSigner:1,isWritable:1},{pubkey:i,isSigner:0,isWritable:0},{pubkey:o,isSigner:1,isWritable:0},{pubkey:n,isSigner:0,isWritable:1},{pubkey:r,isSigner:0,isWritable:1},{pubkey:a.splInterfacePda,isSigner:0,isWritable:1},{pubkey:a.tokenProgram,isSigner:0,isWritable:0},{pubkey:e.LIGHT_TOKEN_PROGRAM_ID,isSigner:0,isWritable:0},{pubkey:t.SystemProgram.programId,isSigner:0,isWritable:0}];return new t.TransactionInstruction({programId:Ae.programId,keys:m,data:p})}const gr=31,yr=17;function br(t){if(!t||t.length<5)return null;try{let e=0;const n=t.readUInt32LE(e);e+=4;for(let r=0;r<n;r++){if(e>=t.length)return null;const n=t[e];if(e+=1,n===gr){if(e+yr>t.length)return null;const n=BigInt(t.readUInt32LE(e))|BigInt(t.readUInt32LE(e+4))<<BigInt(32);return{delegatedAmount:n,withheldTransferFee:BigInt(t.readUInt32LE(e+8))|BigInt(t.readUInt32LE(e+12))<<BigInt(32),isAta:0!==t[e+16]}}const r={29:8,30:1,31:17}[n];if(void 0===r)throw new Error(`parseCompressedOnlyFromTlv: unknown TLV extension discriminant ${n}`);e+=r}}catch(t){return null}return null}function wr(n,r,o,i){let s=0;const a=[];for(const u of n){const n=br(u.parsed.tlv);if(!n){a.push([]);continue}s=1;let c=0;if(n.isAta){const n=[o.toBuffer(),e.LIGHT_TOKEN_PROGRAM_ID.toBuffer(),i.toBuffer()],[,r]=t.PublicKey.findProgramAddressSync(n,e.LIGHT_TOKEN_PROGRAM_ID);c=r}const l=2===u.parsed.state;a.push([{type:"CompressedOnly",data:{delegatedAmount:n.delegatedAmount,withheldTransferFee:n.withheldTransferFee,isFrozen:l,compressionIndex:0,isAta:n.isAta,bump:c,ownerIndex:r}}])}return s?a:null}function Ir(t){return!t||t.length<8?exports.TokenDataVersion.ShaFlat:2===t[0]?exports.TokenDataVersion.V1:3===t[7]?exports.TokenDataVersion.V2:exports.TokenDataVersion.ShaFlat}function vr(n,r,o,i,s,a,u,c,l){var d;if(0===r.length)throw new Error("No input light-token accounts provided");const p=r[0].parsed.mint,m=r[0].parsed.owner,h=new Map,f=[],g=new Set,y=new Set;for(const t of r)g.add(t.compressedAccount.treeInfo.tree.toBase58()),y.add(t.compressedAccount.treeInfo.queue.toBase58());for(const e of g)h.set(e,f.length),f.push(new t.PublicKey(e));let b=0,w=1;for(const e of y)w&&(b=f.length,w=0),h.set(e,f.length),f.push(new t.PublicKey(e));const I=f.length;h.set(p.toBase58(),I),f.push(p);const v=f.length;h.set(m.toBase58(),v),f.push(m);const A=f.length;h.set(o.toBase58(),A),f.push(o);for(const t of r)if(t.parsed.delegate){const e=t.parsed.delegate.toBase58();h.has(e)||(h.set(e,f.length),f.push(t.parsed.delegate))}let T=0,k=0,P=0,M=0;a&&(T=f.length,h.set(a.splInterfacePda.toBase58(),T),f.push(a.splInterfacePda),M=f.length,h.set(a.tokenProgram.toBase58(),M),f.push(a.tokenProgram),k=a.poolIndex,P=a.bump);const S=function(t,e,n){return t.map(((t,r)=>{var o,i;const s=t.parsed.owner.toBase58(),a=t.parsed.mint.toBase58(),u=Ir(null===(o=t.compressedAccount.data)||void 0===o?void 0:o.discriminator);return{owner:n.get(s),amount:BigInt(t.parsed.amount.toString()),hasDelegate:null!==t.parsed.delegate,delegate:t.parsed.delegate&&null!==(i=n.get(t.parsed.delegate.toBase58()))&&void 0!==i?i:0,mint:n.get(a),version:u,merkleContext:{merkleTreePubkeyIndex:n.get(t.compressedAccount.treeInfo.tree.toBase58()),queuePubkeyIndex:n.get(t.compressedAccount.treeInfo.queue.toBase58()),leafIndex:t.compressedAccount.leafIndex,proveByIndex:t.compressedAccount.proveByIndex},rootIndex:e[r]}}))}(r,s.rootIndices,h),x=r.reduce(((t,e)=>t+BigInt(e.parsed.amount.toString())),BigInt(0))-i,C=[];if(x>0){const t=Ir(null===(d=r[0].compressedAccount.data)||void 0===d?void 0:d.discriminator);C.push({owner:v,amount:x,hasDelegate:0,delegate:0,mint:I,version:t})}const E=lr({withTransactionHash:0,withLamportsChangeAccountMerkleTreeIndex:0,lamportsChangeAccountMerkleTreeIndex:0,lamportsChangeAccountOwnerIndex:0,outputQueue:b,maxTopUp:yt,cpiContext:null,compressions:[{mode:Xn,amount:i,mint:I,sourceOrRecipient:A,authority:0,poolAccountIndex:a?T:0,poolIndex:a?k:0,bump:a?P:0,decimals:u}],proof:s.compressedProof?{a:Array.from(s.compressedProof.a),b:Array.from(s.compressedProof.b),c:Array.from(s.compressedProof.c)}:null,inTokenData:S,outTokenData:C,inLamports:null,outLamports:null,inTlv:wr(r,v,m,p),outTlv:null}),{accountCompressionAuthority:_,registeredProgramPda:O,accountCompressionProgram:R}=e.defaultStaticAccountsStruct(),B=(()=>{if(!l||l.equals(m))return v;const t=h.get(l.toBase58());if(void 0===t)throw new Error(`Authority ${l.toBase58()} is not present in packed accounts`);return t})(),L=[{pubkey:e.LightSystemProgram.programId,isSigner:0,isWritable:0},{pubkey:n,isSigner:1,isWritable:1},{pubkey:Ae.deriveCpiAuthorityPda,isSigner:0,isWritable:0},{pubkey:O,isSigner:0,isWritable:0},{pubkey:_,isSigner:0,isWritable:0},{pubkey:R,isSigner:0,isWritable:0},{pubkey:t.SystemProgram.programId,isSigner:0,isWritable:0},...f.map(((t,e)=>{const n=e<g.size+y.size,r=t.equals(o),i=void 0!==a&&t.equals(a.splInterfacePda);return{pubkey:t,isSigner:e===B,isWritable:n||r||i}}))];return new t.TransactionInstruction({programId:Ae.programId,keys:L,data:E})}const Ar=8;function Tr(t,e){if(0===t.length||e<=BigInt(0))return[];const n=[...t].sort(((t,e)=>{const n=BigInt(t.parsed.amount.toString()),r=BigInt(e.parsed.amount.toString());return r>n?1:r<n?-1:0}));let r=BigInt(0),o=0;for(const t of n)if(o++,r+=BigInt(t.parsed.amount.toString()),r>=e)break;const i=Math.min(Math.max(o,Ar),n.length);return n.slice(0,i)}async function kr(r,o,i,s,a,u,c,l=0){var d;e.assertBetaEnabled(),null!=u||(u=i);const p=null!==(d=null==c?void 0:c.owner)&&void 0!==d?d:i;let m;try{m=await Wn(r,o,p,s,void 0,void 0,l)}catch(t){if(t instanceof n.TokenAccountNotFoundError)return[];throw t}if(!p.equals(i)){if(!Vn(m,i))throw new Error("Signer is not the owner or a delegate of the account.");m=Hn(m,i)}return(await Dr(r,u,m,c,l,o,void 0,i,a)).map((e=>[t.ComputeBudgetProgram.setComputeUnitLimit({units:Lr(e)}),...e.instructions]))}const Pr=3e4,Mr=5e4,Sr=5e4,xr=1e5,Cr=1e4,Er=3e4,_r=1.3,Or=5e4,Rr=14e5;function Br(t){var e;let n=0;if(t.hasAtaCreation&&(n+=Pr),n+=t.wrapCount*Mr,t.compressedAccounts.length>0){n+=Sr;const r=t.compressedAccounts.some((t=>{var e;return!(null!==(e=t.compressedAccount.proveByIndex)&&void 0!==e&&e)}));r&&(n+=xr);for(const r of t.compressedAccounts)n+=null!==(e=r.compressedAccount.proveByIndex)&&void 0!==e&&e?Cr:Er}return n}function Lr(t){const e=Math.ceil(Br(t)*_r);return Math.max(Or,Math.min(Rr,e))}async function Dr(t,r,o,i,s,a,u,c,l){var d,p,m,h;if(!o._isAta||!o._owner||!o._mint)throw new Error("AccountInterface must be from getAtaInterface (requires _isAta, _owner, _mint)");On(o,"load");const f=o._owner,g=o._mint,y=null!==(d=o._sources)&&void 0!==d?d:[],b=function(t){return t.filter((t=>void 0!==t.loadContext)).filter((t=>Cn.has(t.type))).map((t=>{const n=t.accountInfo.data,r=n.subarray(0,Math.min(8,n.length)),o=n.length>8?n.subarray(8):Buffer.alloc(0),i={treeInfo:t.loadContext.treeInfo,hash:t.loadContext.hash,leafIndex:t.loadContext.leafIndex,proveByIndex:t.loadContext.proveByIndex,owner:t.accountInfo.owner,lamports:e.bn(t.accountInfo.lamports),address:null,data:0===n.length?null:{discriminator:Array.from(r),data:Buffer.from(o),dataHash:new Array(32).fill(0)},readOnly:0},s=t.parsed.isInitialized?t.parsed.isFrozen?2:1:0;return{compressedAccount:i,parsed:{mint:t.parsed.mint,owner:t.parsed.owner,amount:e.bn(t.parsed.amount.toString()),delegate:t.parsed.delegate,state:s,tlv:t.parsed.tlvData.length>0?t.parsed.tlvData:null}}}))}(y),w=zn(g,f),I=n.getAssociatedTokenAddressSync(g,f,0,n.TOKEN_PROGRAM_ID,mn(n.TOKEN_PROGRAM_ID)),v=n.getAssociatedTokenAddressSync(g,f,0,n.TOKEN_2022_PROGRAM_ID,mn(n.TOKEN_2022_PROGRAM_ID));let A="light-token";if(A=hn(a,g,f).type,s&&"light-token"!==A)throw new Error(`For wrap=true, targetAta must be light-token associated token account. Got ${A} associated token account.`);const T=y.find((t=>"spl"===t.type)),k=y.find((t=>"token2022"===t.type)),P=y.find((t=>"light-token-hot"===t.type)),M=y.filter((t=>Cn.has(t.type))),S=null!==(p=null==T?void 0:T.amount)&&void 0!==p?p:BigInt(0),x=null!==(m=null==k?void 0:k.amount)&&void 0!==m?m:BigInt(0),C=M.reduce(((t,e)=>t+e.amount),BigInt(0));if(S===BigInt(0)&&x===BigInt(0)&&C===BigInt(0))return[];let E;if(s||"spl"===A||"token2022"===A||S>BigInt(0)||x>BigInt(0))try{E=(null!==(h=null==i?void 0:i.splInterfaceInfos)&&void 0!==h?h:await kt(t,g)).find((t=>t.isInitialized))}catch(t){if(S>BigInt(0)||x>BigInt(0))throw t}const _=[];let O,R=0,B=0,L=w,D=0;s?(L=w,O=void 0,D=1,P||(B=1,_.push(yn(r,w,f,g,e.LIGHT_TOKEN_PROGRAM_ID))),S>BigInt(0)&&E&&(_.push(fr(I,w,f,g,S,E,l,r)),R++),x>BigInt(0)&&E&&(_.push(fr(v,w,f,g,x,E,l,r)),R++)):"light-token"===A?(L=w,O=void 0,D=1,P||(B=1,_.push(yn(r,w,f,g,e.LIGHT_TOKEN_PROGRAM_ID)))):"spl"===A&&E?(L=I,O=E,D=1,T||(B=1,_.push(n.createAssociatedTokenAccountIdempotentInstruction(r,I,f,g,n.TOKEN_PROGRAM_ID)))):"token2022"===A&&E&&(L=v,O=E,D=1,k||(B=1,_.push(n.createAssociatedTokenAccountIdempotentInstruction(r,v,f,g,n.TOKEN_2022_PROGRAM_ID))));let K=b;if(void 0!==u&&D&&b.length>0){const t=void 0!==c&&!c.equals(f),e=(()=>{var e;if(!P)return BigInt(0);if(t){const t=null!==(e=P.parsed.delegatedAmount)&&void 0!==e?e:BigInt(0);return t<P.amount?t:P.amount}return P.amount})();let n;n=s?e+S+x:"light-token"===A?e:"spl"===A?S:x;const r=u>n?u-n:BigInt(0);K=r===BigInt(0)?[]:Tr(b,r)}if(!D||0===K.length)return 0===_.length?[]:[{instructions:_,compressedAccounts:[],wrapCount:R,hasAtaCreation:B}];!function(t){const n=t.filter((t=>t.compressedAccount.treeInfo.treeType===e.TreeType.StateV1)).length;if(n>0)throw new Error(`v3 interface does not support V1 compressed accounts. Found ${n} V1 account(s). Use the main SDK actions (transfer, decompress, merge) to migrate V1 accounts to V2.`)}(K);const U=function(t,e){const n=[];for(let r=0;r<t.length;r+=e)n.push(t.slice(r,r+e));return n}(K,Ar);!function(t){const e=new Set;for(const n of t)for(const t of n){const n=t.compressedAccount.hash.toString();if(e.has(n))throw new Error(`Duplicate compressed account hash across chunks: ${n}. Each compressed account must appear in exactly one chunk.`);e.add(n)}}(U);const N=await Promise.all(U.map((async e=>{const n=e.map((t=>({hash:t.compressedAccount.hash,tree:t.compressedAccount.treeInfo.tree,queue:t.compressedAccount.treeInfo.queue})));return t.getValidityProofV0(n)}))),W=s||"light-token"===A?yn(r,w,f,g,e.LIGHT_TOKEN_PROGRAM_ID):"spl"===A?n.createAssociatedTokenAccountIdempotentInstruction(r,I,f,g,n.TOKEN_PROGRAM_ID):n.createAssociatedTokenAccountIdempotentInstruction(r,v,f,g,n.TOKEN_2022_PROGRAM_ID),G=[];for(let t=0;t<U.length;t++){const e=U[t],n=N[t],o=e.reduce(((t,e)=>t+BigInt(e.parsed.amount.toString())),BigInt(0)),i=[];let s=0,a=0;0===t?(i.push(..._),s=R,a=B):(i.push(W),a=1);const u=null!=c?c:f;i.push(vr(r,e,L,o,n,O,l,0,u)),G.push({instructions:i,compressedAccounts:e,wrapCount:s,hasAtaCreation:a})}return G}function Kr(n){const{mint:r,destination:o,amount:i,authority:s,maxTopUp:a,feePayer:u}=n,c=[{pubkey:r,isSigner:0,isWritable:1},{pubkey:o,isSigner:0,isWritable:1},{pubkey:s,isSigner:1,isWritable:void 0!==a&&!u},{pubkey:t.SystemProgram.programId,isSigner:0,isWritable:0}];u&&c.push({pubkey:u,isSigner:1,isWritable:1});const l=BigInt(i.toString()),d=void 0!==a?11:9,p=w.alloc(d);return p.writeUInt8(7,0),p.writeBigUInt64LE(l,1),void 0!==a&&p.writeUInt16LE(a,9),new t.TransactionInstruction({programId:e.LIGHT_TOKEN_PROGRAM_ID,keys:c,data:p})}function Ur(n,r,o,i,s,a,u,c=exports.TokenDataVersion.ShaFlat,l){var d;const p=s.cmintDecompressed;e.getDefaultAddressTreeInfo();const m=function(t){var e;if(t.mintData.metadata)throw new Error("TokenMetadata extension not supported in mintTo instruction");const n=t.mintData.cmintDecompressed;return je({leafIndex:t.leafIndex,proveByIndex:1,rootIndex:t.rootIndex,maxTopUp:null!==(e=t.maxTopUp)&&void 0!==e?e:yt,createMint:null,actions:[{mintToCompressed:{tokenAccountVersion:t.tokenAccountVersion,recipients:t.recipients.map((t=>({recipient:t.recipient,amount:BigInt(t.amount.toString())})))}}],proof:n?null:t.proof,cpiContext:null,mint:n?null:{supply:t.mintData.supply,decimals:t.mintData.decimals,metadata:{version:t.mintData.version,cmintDecompressed:t.mintData.cmintDecompressed,mint:t.mintData.splMint,mintSigner:Array.from(t.mintData.mintSigner),bump:t.mintData.bump},mintAuthority:t.mintData.mintAuthority,freezeAuthority:t.mintData.freezeAuthority,extensions:null}})}({leafIndex:i.leafIndex,rootIndex:o.rootIndices[0],proof:o.compressedProof,mintData:s,recipients:a,tokenAccountVersion:c,maxTopUp:l}),h=null!==(d=null==u?void 0:u.queue)&&void 0!==d?d:e.getOutputQueue(i),f=e.defaultStaticAccountsStruct(),g=[{pubkey:e.LightSystemProgram.programId,isSigner:0,isWritable:0},{pubkey:n,isSigner:1,isWritable:0},...p?[{pubkey:s.splMint,isSigner:0,isWritable:1}]:[],{pubkey:r,isSigner:1,isWritable:1},{pubkey:Ae.deriveCpiAuthorityPda,isSigner:0,isWritable:0},{pubkey:f.registeredProgramPda,isSigner:0,isWritable:0},{pubkey:f.accountCompressionAuthority,isSigner:0,isWritable:0},{pubkey:f.accountCompressionProgram,isSigner:0,isWritable:0},{pubkey:t.SystemProgram.programId,isSigner:0,isWritable:0},{pubkey:h,isSigner:0,isWritable:1},{pubkey:i.treeInfo.tree,isSigner:0,isWritable:1},{pubkey:i.treeInfo.queue,isSigner:0,isWritable:1},{pubkey:h,isSigner:0,isWritable:1}];return new t.TransactionInstruction({programId:e.LIGHT_TOKEN_PROGRAM_ID,keys:g,data:m})}function Nr(t,e,r,o,i,s,a=[]){const u=t.mint.address,c=t.programId;if(!t.merkleContext)return n.createMintToInstruction(u,e,r,BigInt(i.toString()),a,c);if(!t.mintContext)throw new Error("mintContext required for light-token mint-to");const l=r.equals(o)?void 0:o;return Kr({mint:u,destination:e,amount:i,authority:r,feePayer:l})}"function"==typeof SuppressedError&&SuppressedError;const Wr=1232;function Gr(t,e,n="Batch"){const r=Fr(t,e);if(r>Wr)throw new Error(`${n} exceeds max transaction size: ${r} > ${Wr}. This indicates a bug in batch assembly.`)}function qr(t){return t<128?1:t<16384?2:3}function Fr(t,e){const n=new Set;for(const e of t){n.add(e.programId.toBase58());for(const t of e.keys)n.add(t.pubkey.toBase58())}const r=n.size,o=qr(e)+64*e,i=qr(r)+32*r;let s=qr(t.length);for(const e of t)s+=1,s+=qr(e.keys.length),s+=e.keys.length,s+=qr(e.data.length),s+=e.data.length;return o+1+3+i+32+s+qr(0)}const Vr=1.3,Hr=5e4,zr=14e5;function jr(t,e){const n=e?Br(e):0,r=Math.ceil((t+n)*Vr);return Math.max(Hr,Math.min(zr,r))}const $r=12,Yr=1e4;function Zr(t){return jr(Yr,t)}function Qr(n,r,o,i,s,a,u){const c=Buffer.alloc(10);c.writeUInt8($r,0),c.writeBigUInt64LE(BigInt(s),1),c.writeUInt8(a,9);const l=[{pubkey:n,isSigner:0,isWritable:1},{pubkey:o,isSigner:0,isWritable:0},{pubkey:r,isSigner:0,isWritable:1},{pubkey:i,isSigner:1,isWritable:u.equals(i)},{pubkey:t.SystemProgram.programId,isSigner:0,isWritable:0},{pubkey:u,isSigner:!u.equals(i),isWritable:1}];return new t.TransactionInstruction({programId:e.LIGHT_TOKEN_PROGRAM_ID,keys:l,data:c})}async function Xr(r,o,i,s,a,u,c,l){e.assertBetaEnabled();const d=BigInt(s.toString());if(d<=BigInt(0))throw new Error("Transfer amount must be greater than zero.");const p=null!=l?l:{},{wrap:m=0,programId:h=e.LIGHT_TOKEN_PROGRAM_ID,owner:f}=p,g=function(t,e){var n={};for(var r in t)Object.prototype.hasOwnProperty.call(t,r)&&e.indexOf(r)<0&&(n[r]=t[r]);if(null!=t&&"function"==typeof Object.getOwnPropertySymbols){var o=0;for(r=Object.getOwnPropertySymbols(t);o<r.length;o++)e.indexOf(r[o])<0&&Object.prototype.propertyIsEnumerable.call(t,r[o])&&(n[r[o]]=t[r[o]])}return n}(p,["wrap","programId","owner"]),y=null!=f?f:a,b=h.equals(n.TOKEN_PROGRAM_ID)||h.equals(n.TOKEN_2022_PROGRAM_ID),w=zn(i,y,0,h);let I;try{I=await Wn(r,w,y,i,void 0,h.equals(e.LIGHT_TOKEN_PROGRAM_ID)?void 0:h,m)}catch(t){if(t instanceof n.TokenAccountNotFoundError)throw new Error("Sender has no token accounts for this mint.");throw t}if(On(I,"transfer"),y.equals(a)){if(I.parsed.amount<d)throw new Error(`Insufficient balance. Required: ${d}, Available: ${I.parsed.amount}`)}else{if(!Vn(I,a))throw new Error("Signer is not the owner or a delegate of the sender account.");const t=Fn(I,a);if(d>t)throw new Error(`Insufficient delegated balance. Required: ${d}, Available (delegate): ${t}`);I=Hn(I,a)}const v=await Dr(r,o,I,g,m,w,d,a,c);let A;A=b&&!m?n.createTransferCheckedInstruction(w,i,u,a,d,c,[],h):Qr(w,u,i,a,d,c,o);const T=o.equals(a)?1:2;if(0===v.length){const e=Zr(null),n=[t.ComputeBudgetProgram.setComputeUnitLimit({units:e}),A];return Gr(n,T,"Batch"),[n]}if(1===v.length){const e=v[0],n=Zr(e),r=[t.ComputeBudgetProgram.setComputeUnitLimit({units:n}),...e.instructions,A];return Gr(r,T,"Batch"),[r]}const k=[];for(let e=0;e<v.length-1;e++){const n=v[e],r=Lr(n),o=[t.ComputeBudgetProgram.setComputeUnitLimit({units:r}),...n.instructions];Gr(o,T,"Batch"),k.push(o)}const P=v[v.length-1],M=Zr(P),S=[t.ComputeBudgetProgram.setComputeUnitLimit({units:M}),...P.instructions,A];return Gr(S,T,"Batch"),k.push(S),k}function Jr(t){return jr(1e4,t)}function to(n,r,o,i,s,a,u,c=o,l){const d=[mr(s,0,2,1,6),hr(s,0,3,4,a.poolIndex,a.bump,u)],p=lr({withTransactionHash:0,withLamportsChangeAccountMerkleTreeIndex:0,lamportsChangeAccountMerkleTreeIndex:0,lamportsChangeAccountOwnerIndex:0,outputQueue:0,maxTopUp:null!=l?l:yt,cpiContext:null,compressions:d,proof:null,inTokenData:[],outTokenData:[],inLamports:null,outLamports:null,inTlv:null,outTlv:null}),m=[{pubkey:Ae.deriveCpiAuthorityPda,isSigner:0,isWritable:0},{pubkey:c,isSigner:1,isWritable:1},{pubkey:i,isSigner:0,isWritable:0},{pubkey:o,isSigner:1,isWritable:0},{pubkey:n,isSigner:0,isWritable:1},{pubkey:r,isSigner:0,isWritable:1},{pubkey:a.splInterfacePda,isSigner:0,isWritable:1},{pubkey:a.tokenProgram,isSigner:0,isWritable:0},{pubkey:e.LIGHT_TOKEN_PROGRAM_ID,isSigner:0,isWritable:0},{pubkey:t.SystemProgram.programId,isSigner:0,isWritable:0}];return new t.TransactionInstruction({programId:Ae.programId,keys:m,data:p})}const eo=w.from([10]),no=w.from([11]);async function ro(r,o,i,s,a=t.Keypair.generate(),u,c,l){const d=await r.getMinimumBalanceForRentExemption(n.MINT_SIZE),p=1==c?n.TOKEN_2022_PROGRAM_ID:c||n.TOKEN_PROGRAM_ID,m=await Ae.createMint({feePayer:o.publicKey,mint:a.publicKey,decimals:s,authority:"secretKey"in i?i.publicKey:i,freezeAuthority:l&&"secretKey"in l?l.publicKey:null!=l?l:null,rentExemptBalance:d,tokenProgramId:p}),{blockhash:h}=await r.getLatestBlockhash(),f=e.dedupeSigner(o,[i,null!=l?l:null].filter((t=>null!=t&&"secretKey"in t))),g=e.buildAndSignTx(m,o,h,[...f,a]),y=await e.sendAndConfirmTx(r,g,u);return{mint:a.publicKey,transactionSignature:y}}var oo={};Object.defineProperty(oo,"__esModule",{value:1}),oo.s16=oo.s8=oo.nu64be=oo.u48be=oo.u40be=oo.u32be=oo.u24be=oo.u16be=oo.nu64=oo.u48=oo.u40=oo.u32=oo.u24=oo.u16=Fo=oo.u8=oo.offset=oo.greedy=oo.Constant=oo.UTF8=oo.CString=oo.Blob=oo.Boolean=oo.BitField=oo.BitStructure=oo.VariantLayout=oo.Union=oo.UnionLayoutDiscriminator=oo.UnionDiscriminator=oo.Structure=oo.Sequence=oo.DoubleBE=oo.Double=oo.FloatBE=oo.Float=oo.NearInt64BE=oo.NearInt64=oo.NearUInt64BE=oo.NearUInt64=oo.IntBE=oo.Int=oo.UIntBE=oo.UInt=oo.OffsetLayout=oo.GreedyCount=oo.ExternalLayout=oo.bindConstructorLayout=oo.nameWithProperty=oo.Layout=oo.uint8ArrayToBuffer=oo.checkUint8Array=void 0,oo.constant=oo.utf8=oo.cstr=Ho=oo.blob=oo.unionLayoutDiscriminator=oo.union=oo.seq=oo.bits=Vo=oo.struct=oo.f64be=oo.f64=oo.f32be=oo.f32=oo.ns64be=oo.s48be=oo.s40be=oo.s32be=oo.s24be=oo.s16be=oo.ns64=oo.s48=oo.s40=oo.s32=oo.s24=void 0;const io=Tn;function so(t){if(!(t instanceof Uint8Array))throw new TypeError("b must be a Uint8Array")}function ao(t){return so(t),io.Buffer.from(t.buffer,t.byteOffset,t.length)}oo.checkUint8Array=so,oo.uint8ArrayToBuffer=ao;class uo{constructor(t,e){if(!Number.isInteger(t))throw new TypeError("span must be an integer");this.span=t,this.property=e}makeDestinationObject(){return{}}getSpan(t,e){if(0>this.span)throw new RangeError("indeterminate span");return this.span}replicate(t){const e=Object.create(this.constructor.prototype);return Object.assign(e,this),e.property=t,e}fromArray(t){}}function co(t,e){return e.property?t+"["+e.property+"]":t}oo.Layout=uo,oo.nameWithProperty=co,oo.bindConstructorLayout=function(t,e){if("function"!=typeof t)throw new TypeError("Class must be constructor");if(Object.prototype.hasOwnProperty.call(t,"layout_"))throw new Error("Class is already bound to a layout");if(!(e&&e instanceof uo))throw new TypeError("layout must be a Layout");if(Object.prototype.hasOwnProperty.call(e,"boundConstructor_"))throw new Error("layout is already bound to a constructor");t.layout_=e,e.boundConstructor_=t,e.makeDestinationObject=()=>new t,Object.defineProperty(t.prototype,"encode",{value(t,n){return e.encode(this,t,n)},writable:1}),Object.defineProperty(t,"decode",{value:(t,n)=>e.decode(t,n),writable:1})};class lo extends uo{isCount(){throw new Error("ExternalLayout is abstract")}}oo.ExternalLayout=lo;class po extends lo{constructor(t=1,e){if(!Number.isInteger(t)||0>=t)throw new TypeError("elementSpan must be a (positive) integer");super(-1,e),this.elementSpan=t}isCount(){return 1}decode(t,e=0){so(t);const n=t.length-e;return Math.floor(n/this.elementSpan)}encode(t,e,n){return 0}}oo.GreedyCount=po;class mo extends lo{constructor(t,e=0,n){if(!(t instanceof uo))throw new TypeError("layout must be a Layout");if(!Number.isInteger(e))throw new TypeError("offset must be integer or undefined");super(t.span,n||t.property),this.layout=t,this.offset=e}isCount(){return this.layout instanceof ho||this.layout instanceof fo}decode(t,e=0){return this.layout.decode(t,e+this.offset)}encode(t,e,n=0){return this.layout.encode(t,e,n+this.offset)}}oo.OffsetLayout=mo;class ho extends uo{constructor(t,e){if(super(t,e),6<this.span)throw new RangeError("span must not exceed 6 bytes")}decode(t,e=0){return ao(t).readUIntLE(e,this.span)}encode(t,e,n=0){return ao(e).writeUIntLE(t,n,this.span),this.span}}oo.UInt=ho;class fo extends uo{constructor(t,e){if(super(t,e),6<this.span)throw new RangeError("span must not exceed 6 bytes")}decode(t,e=0){return ao(t).readUIntBE(e,this.span)}encode(t,e,n=0){return ao(e).writeUIntBE(t,n,this.span),this.span}}oo.UIntBE=fo;class go extends uo{constructor(t,e){if(super(t,e),6<this.span)throw new RangeError("span must not exceed 6 bytes")}decode(t,e=0){return ao(t).readIntLE(e,this.span)}encode(t,e,n=0){return ao(e).writeIntLE(t,n,this.span),this.span}}oo.Int=go;class yo extends uo{constructor(t,e){if(super(t,e),6<this.span)throw new RangeError("span must not exceed 6 bytes")}decode(t,e=0){return ao(t).readIntBE(e,this.span)}encode(t,e,n=0){return ao(e).writeIntBE(t,n,this.span),this.span}}oo.IntBE=yo;const bo=Math.pow(2,32);function wo(t){const e=Math.floor(t/bo);return{hi32:e,lo32:t-e*bo}}function Io(t,e){return t*bo+e}class vo extends uo{constructor(t){super(8,t)}decode(t,e=0){const n=ao(t),r=n.readUInt32LE(e);return Io(n.readUInt32LE(e+4),r)}encode(t,e,n=0){const r=wo(t),o=ao(e);return o.writeUInt32LE(r.lo32,n),o.writeUInt32LE(r.hi32,n+4),8}}oo.NearUInt64=vo;class Ao extends uo{constructor(t){super(8,t)}decode(t,e=0){const n=ao(t);return Io(n.readUInt32BE(e),n.readUInt32BE(e+4))}encode(t,e,n=0){const r=wo(t),o=ao(e);return o.writeUInt32BE(r.hi32,n),o.writeUInt32BE(r.lo32,n+4),8}}oo.NearUInt64BE=Ao;class To extends uo{constructor(t){super(8,t)}decode(t,e=0){const n=ao(t),r=n.readUInt32LE(e);return Io(n.readInt32LE(e+4),r)}encode(t,e,n=0){const r=wo(t),o=ao(e);return o.writeUInt32LE(r.lo32,n),o.writeInt32LE(r.hi32,n+4),8}}oo.NearInt64=To;class ko extends uo{constructor(t){super(8,t)}decode(t,e=0){const n=ao(t);return Io(n.readInt32BE(e),n.readUInt32BE(e+4))}encode(t,e,n=0){const r=wo(t),o=ao(e);return o.writeInt32BE(r.hi32,n),o.writeUInt32BE(r.lo32,n+4),8}}oo.NearInt64BE=ko;class Po extends uo{constructor(t){super(4,t)}decode(t,e=0){return ao(t).readFloatLE(e)}encode(t,e,n=0){return ao(e).writeFloatLE(t,n),4}}oo.Float=Po;class Mo extends uo{constructor(t){super(4,t)}decode(t,e=0){return ao(t).readFloatBE(e)}encode(t,e,n=0){return ao(e).writeFloatBE(t,n),4}}oo.FloatBE=Mo;class So extends uo{constructor(t){super(8,t)}decode(t,e=0){return ao(t).readDoubleLE(e)}encode(t,e,n=0){return ao(e).writeDoubleLE(t,n),8}}oo.Double=So;class xo extends uo{constructor(t){super(8,t)}decode(t,e=0){return ao(t).readDoubleBE(e)}encode(t,e,n=0){return ao(e).writeDoubleBE(t,n),8}}oo.DoubleBE=xo;class Co extends uo{constructor(t,e,n){if(!(t instanceof uo))throw new TypeError("elementLayout must be a Layout");if(!(e instanceof lo&&e.isCount()||Number.isInteger(e)&&0<=e))throw new TypeError("count must be non-negative integer or an unsigned integer ExternalLayout");let r=-1;!(e instanceof lo)&&0<t.span&&(r=e*t.span),super(r,n),this.elementLayout=t,this.count=e}getSpan(t,e=0){if(0<=this.span)return this.span;let n=0,r=this.count;if(r instanceof lo&&(r=r.decode(t,e)),0<this.elementLayout.span)n=r*this.elementLayout.span;else{let o=0;for(;o<r;)n+=this.elementLayout.getSpan(t,e+n),++o}return n}decode(t,e=0){const n=[];let r=0,o=this.count;for(o instanceof lo&&(o=o.decode(t,e));r<o;)n.push(this.elementLayout.decode(t,e)),e+=this.elementLayout.getSpan(t,e),r+=1;return n}encode(t,e,n=0){const r=this.elementLayout,o=t.reduce(((t,o)=>t+r.encode(o,e,n+t)),0);return this.count instanceof lo&&this.count.encode(t.length,e,n),o}}oo.Sequence=Co;class Eo extends uo{constructor(t,e,n){if(!Array.isArray(t)||!t.reduce(((t,e)=>t&&e instanceof uo),1))throw new TypeError("fields must be array of Layout instances");"boolean"==typeof e&&void 0===n&&(n=e,e=void 0);for(const e of t)if(0>e.span&&void 0===e.property)throw new Error("fields cannot contain unnamed variable-length layout");let r=-1;try{r=t.reduce(((t,e)=>t+e.getSpan()),0)}catch(t){}super(r,e),this.fields=t,this.decodePrefixes=!!n}getSpan(t,e=0){if(0<=this.span)return this.span;let n=0;try{n=this.fields.reduce(((n,r)=>{const o=r.getSpan(t,e);return e+=o,n+o}),0)}catch(t){throw new RangeError("indeterminate span")}return n}decode(t,e=0){so(t);const n=this.makeDestinationObject();for(const r of this.fields)if(void 0!==r.property&&(n[r.property]=r.decode(t,e)),e+=r.getSpan(t,e),this.decodePrefixes&&t.length===e)break;return n}encode(t,e,n=0){const r=n;let o=0,i=0;for(const r of this.fields){let s=r.span;if(i=0<s?s:0,void 0!==r.property){const o=t[r.property];void 0!==o&&(i=r.encode(o,e,n),0>s&&(s=r.getSpan(e,n)))}o=n,n+=s}return o+i-r}fromArray(t){const e=this.makeDestinationObject();for(const n of this.fields)void 0!==n.property&&0<t.length&&(e[n.property]=t.shift());return e}layoutFor(t){if("string"!=typeof t)throw new TypeError("property must be string");for(const e of this.fields)if(e.property===t)return e}offsetOf(t){if("string"!=typeof t)throw new TypeError("property must be string");let e=0;for(const n of this.fields){if(n.property===t)return e;0>n.span?e=-1:0<=e&&(e+=n.span)}}}oo.Structure=Eo;class _o{constructor(t){this.property=t}decode(t,e){throw new Error("UnionDiscriminator is abstract")}encode(t,e,n){throw new Error("UnionDiscriminator is abstract")}}oo.UnionDiscriminator=_o;class Oo extends _o{constructor(t,e){if(!(t instanceof lo&&t.isCount()))throw new TypeError("layout must be an unsigned integer ExternalLayout");super(e||t.property||"variant"),this.layout=t}decode(t,e){return this.layout.decode(t,e)}encode(t,e,n){return this.layout.encode(t,e,n)}}oo.UnionLayoutDiscriminator=Oo;class Ro extends uo{constructor(t,e,n){let r;if(t instanceof ho||t instanceof fo)r=new Oo(new mo(t));else if(t instanceof lo&&t.isCount())r=new Oo(t);else{if(!(t instanceof _o))throw new TypeError("discr must be a UnionDiscriminator or an unsigned integer layout");r=t}if(void 0===e&&(e=null),!(null===e||e instanceof uo))throw new TypeError("defaultLayout must be null or a Layout");if(null!==e){if(0>e.span)throw new Error("defaultLayout must have constant span");void 0===e.property&&(e=e.replicate("content"))}let o=-1;e&&(o=e.span,0<=o&&(t instanceof ho||t instanceof fo)&&(o+=r.layout.span)),super(o,n),this.discriminator=r,this.usesPrefixDiscriminator=t instanceof ho||t instanceof fo,this.defaultLayout=e,this.registry={};let i=this.defaultGetSourceVariant.bind(this);this.getSourceVariant=function(t){return i(t)},this.configGetSourceVariant=function(t){i=t.bind(this)}}getSpan(t,e=0){if(0<=this.span)return this.span;const n=this.getVariant(t,e);if(!n)throw new Error("unable to determine span for unrecognized variant");return n.getSpan(t,e)}defaultGetSourceVariant(t){if(Object.prototype.hasOwnProperty.call(t,this.discriminator.property)){if(this.defaultLayout&&this.defaultLayout.property&&Object.prototype.hasOwnProperty.call(t,this.defaultLayout.property))return;const e=this.registry[t[this.discriminator.property]];if(e&&(!e.layout||e.property&&Object.prototype.hasOwnProperty.call(t,e.property)))return e}else for(const e in this.registry){const n=this.registry[e];if(n.property&&Object.prototype.hasOwnProperty.call(t,n.property))return n}throw new Error("unable to infer src variant")}decode(t,e=0){let n;const r=this.discriminator,o=r.decode(t,e),i=this.registry[o];if(void 0===i){const i=this.defaultLayout;let s=0;this.usesPrefixDiscriminator&&(s=r.layout.span),n=this.makeDestinationObject(),n[r.property]=o,n[i.property]=i.decode(t,e+s)}else n=i.decode(t,e);return n}encode(t,e,n=0){const r=this.getSourceVariant(t);if(void 0===r){const r=this.discriminator,o=this.defaultLayout;let i=0;return this.usesPrefixDiscriminator&&(i=r.layout.span),r.encode(t[r.property],e,n),i+o.encode(t[o.property],e,n+i)}return r.encode(t,e,n)}addVariant(t,e,n){const r=new Bo(this,t,e,n);return this.registry[t]=r,r}getVariant(t,e=0){let n;return n=t instanceof Uint8Array?this.discriminator.decode(t,e):t,this.registry[n]}}oo.Union=Ro;class Bo extends uo{constructor(t,e,n,r){if(!(t instanceof Ro))throw new TypeError("union must be a Union");if(!Number.isInteger(e)||0>e)throw new TypeError("variant must be a (non-negative) integer");if("string"==typeof n&&void 0===r&&(r=n,n=null),n){if(!(n instanceof uo))throw new TypeError("layout must be a Layout");if(null!==t.defaultLayout&&0<=n.span&&n.span>t.defaultLayout.span)throw new Error("variant span exceeds span of containing union");if("string"!=typeof r)throw new TypeError("variant must have a String property")}let o=t.span;0>t.span&&(o=n?n.span:0,0<=o&&t.usesPrefixDiscriminator&&(o+=t.discriminator.layout.span)),super(o,r),this.union=t,this.variant=e,this.layout=n||null}getSpan(t,e=0){if(0<=this.span)return this.span;let n=0;this.union.usesPrefixDiscriminator&&(n=this.union.discriminator.layout.span);let r=0;return this.layout&&(r=this.layout.getSpan(t,e+n)),n+r}decode(t,e=0){const n=this.makeDestinationObject();if(this!==this.union.getVariant(t,e))throw new Error("variant mismatch");let r=0;return this.union.usesPrefixDiscriminator&&(r=this.union.discriminator.layout.span),this.layout?n[this.property]=this.layout.decode(t,e+r):this.property?n[this.property]=1:this.union.usesPrefixDiscriminator&&(n[this.union.discriminator.property]=this.variant),n}encode(t,e,n=0){let r=0;if(this.union.usesPrefixDiscriminator&&(r=this.union.discriminator.layout.span),this.layout&&!Object.prototype.hasOwnProperty.call(t,this.property))throw new TypeError("variant lacks property "+this.property);this.union.discriminator.encode(this.variant,e,n);let o=r;if(this.layout&&(this.layout.encode(t[this.property],e,n+r),o+=this.layout.getSpan(e,n+r),0<=this.union.span&&o>this.union.span))throw new Error("encoded variant overruns containing union");return o}fromArray(t){if(this.layout)return this.layout.fromArray(t)}}function Lo(t){return 0>t&&(t+=4294967296),t}oo.VariantLayout=Bo;class Do extends uo{constructor(t,e,n){if(!(t instanceof ho||t instanceof fo))throw new TypeError("word must be a UInt or UIntBE layout");if("string"==typeof e&&void 0===n&&(n=e,e=0),4<t.span)throw new RangeError("word cannot exceed 32 bits");super(t.span,n),this.word=t,this.msb=!!e,this.fields=[];let r=0;this._packedSetValue=function(t){return r=Lo(t),this},this._packedGetValue=function(){return r}}decode(t,e=0){const n=this.makeDestinationObject(),r=this.word.decode(t,e);this._packedSetValue(r);for(const e of this.fields)void 0!==e.property&&(n[e.property]=e.decode(t));return n}encode(t,e,n=0){const r=this.word.decode(e,n);this._packedSetValue(r);for(const e of this.fields)if(void 0!==e.property){const n=t[e.property];void 0!==n&&e.encode(n)}return this.word.encode(this._packedGetValue(),e,n)}addField(t,e){const n=new Ko(this,t,e);return this.fields.push(n),n}addBoolean(t){const e=new Uo(this,t);return this.fields.push(e),e}fieldFor(t){if("string"!=typeof t)throw new TypeError("property must be string");for(const e of this.fields)if(e.property===t)return e}}oo.BitStructure=Do;class Ko{constructor(t,e,n){if(!(t instanceof Do))throw new TypeError("container must be a BitStructure");if(!Number.isInteger(e)||0>=e)throw new TypeError("bits must be positive integer");const r=8*t.span,o=t.fields.reduce(((t,e)=>t+e.bits),0);if(e+o>r)throw new Error("bits too long for span remainder ("+(r-o)+" of "+r+" remain)");this.container=t,this.bits=e,this.valueMask=(1<<e)-1,32===e&&(this.valueMask=4294967295),this.start=o,this.container.msb&&(this.start=r-o-e),this.wordMask=Lo(this.valueMask<<this.start),this.property=n}decode(t,e){return Lo(this.container._packedGetValue()&this.wordMask)>>>this.start}encode(t){if("number"!=typeof t||!Number.isInteger(t)||t!==Lo(t&this.valueMask))throw new TypeError(co("BitField.encode",this)+" value must be integer not exceeding "+this.valueMask);const e=this.container._packedGetValue(),n=Lo(t<<this.start);this.container._packedSetValue(Lo(e&~this.wordMask)|n)}}oo.BitField=Ko;class Uo extends Ko{constructor(t,e){super(t,1,e)}decode(t,e){return!!super.decode(t,e)}encode(t){"boolean"==typeof t&&(t=+t),super.encode(t)}}oo.Boolean=Uo;class No extends uo{constructor(t,e){if(!(t instanceof lo&&t.isCount()||Number.isInteger(t)&&0<=t))throw new TypeError("length must be positive integer or an unsigned integer ExternalLayout");let n=-1;t instanceof lo||(n=t),super(n,e),this.length=t}getSpan(t,e){let n=this.span;return 0>n&&(n=this.length.decode(t,e)),n}decode(t,e=0){let n=this.span;return 0>n&&(n=this.length.decode(t,e)),ao(t).slice(e,e+n)}encode(t,e,n){let r=this.length;if(this.length instanceof lo&&(r=t.length),!(t instanceof Uint8Array&&r===t.length))throw new TypeError(co("Blob.encode",this)+" requires (length "+r+") Uint8Array as src");if(n+r>e.length)throw new RangeError("encoding overruns Uint8Array");const o=ao(t);return ao(e).write(o.toString("hex"),n,r,"hex"),this.length instanceof lo&&this.length.encode(r,e,n),r}}oo.Blob=No;class Wo extends uo{constructor(t){super(-1,t)}getSpan(t,e=0){so(t);let n=e;for(;n<t.length&&0!==t[n];)n+=1;return 1+n-e}decode(t,e=0){const n=this.getSpan(t,e);return ao(t).slice(e,e+n-1).toString("utf-8")}encode(t,e,n=0){"string"!=typeof t&&(t=String(t));const r=io.Buffer.from(t,"utf8"),o=r.length;if(n+o>e.length)throw new RangeError("encoding overruns Buffer");const i=ao(e);return r.copy(i,n),i[n+o]=0,o+1}}oo.CString=Wo;class Go extends uo{constructor(t,e){if("string"==typeof t&&void 0===e&&(e=t,t=void 0),void 0===t)t=-1;else if(!Number.isInteger(t))throw new TypeError("maxSpan must be an integer");super(-1,e),this.maxSpan=t}getSpan(t,e=0){return so(t),t.length-e}decode(t,e=0){const n=this.getSpan(t,e);if(0<=this.maxSpan&&this.maxSpan<n)throw new RangeError("text length exceeds maxSpan");return ao(t).slice(e,e+n).toString("utf-8")}encode(t,e,n=0){"string"!=typeof t&&(t=String(t));const r=io.Buffer.from(t,"utf8"),o=r.length;if(0<=this.maxSpan&&this.maxSpan<o)throw new RangeError("text length exceeds maxSpan");if(n+o>e.length)throw new RangeError("encoding overruns Buffer");return r.copy(ao(e),n),o}}oo.UTF8=Go;class qo extends uo{constructor(t,e){super(0,e),this.value=t}decode(t,e){return this.value}encode(t,e,n){return 0}}oo.Constant=qo,oo.greedy=(t,e)=>new po(t,e),oo.offset=(t,e,n)=>new mo(t,e,n);var Fo=oo.u8=t=>new ho(1,t);oo.u16=t=>new ho(2,t),oo.u24=t=>new ho(3,t),oo.u32=t=>new ho(4,t),oo.u40=t=>new ho(5,t),oo.u48=t=>new ho(6,t),oo.nu64=t=>new vo(t),oo.u16be=t=>new fo(2,t),oo.u24be=t=>new fo(3,t),oo.u32be=t=>new fo(4,t),oo.u40be=t=>new fo(5,t),oo.u48be=t=>new fo(6,t),oo.nu64be=t=>new Ao(t),oo.s8=t=>new go(1,t),oo.s16=t=>new go(2,t),oo.s24=t=>new go(3,t),oo.s32=t=>new go(4,t),oo.s40=t=>new go(5,t),oo.s48=t=>new go(6,t),oo.ns64=t=>new To(t),oo.s16be=t=>new yo(2,t),oo.s24be=t=>new yo(3,t),oo.s32be=t=>new yo(4,t),oo.s40be=t=>new yo(5,t),oo.s48be=t=>new yo(6,t),oo.ns64be=t=>new ko(t),oo.f32=t=>new Po(t),oo.f32be=t=>new Mo(t),oo.f64=t=>new So(t),oo.f64be=t=>new xo(t);var Vo=oo.struct=(t,e,n)=>new Eo(t,e,n);oo.bits=(t,e,n)=>new Do(t,e,n),oo.seq=(t,e,n)=>new Co(t,e,n),oo.union=(t,e,n)=>new Ro(t,e,n),oo.unionLayoutDiscriminator=(t,e)=>new Oo(t,e);var Ho=oo.blob=(t,e)=>new No(t,e);oo.cstr=t=>new Wo(t),oo.utf8=(t,e)=>new Go(t,e),oo.constant=(t,e)=>new qo(t,e);const zo=r.struct([r.publicKey("updateAuthority"),r.publicKey("mint"),r.vecU8("name"),r.vecU8("symbol"),r.vecU8("uri"),r.vec(r.struct([r.vecU8("key"),r.vecU8("value")]),"additionalMetadata")]),jo=Vo([Fo("version"),Fo("cmintDecompressed"),(()=>{const e=Ho(32,"splMint"),{encode:n,decode:r}=(t=>({decode:t.decode.bind(t),encode:t.encode.bind(t)}))(e),o=e;return o.decode=(e,n)=>{const o=r(e,n);return new t.PublicKey(o)},o.encode=(t,e,r)=>{const o=t.toBuffer();return n(o,e,r)},o})()]),$o=jo.span,Yo=32,Zo=1,Qo=16,Xo=1;function Jo(t,e,n){return t===exports.ExtensionType.TokenMetadata?function(t,e){let n=e;n+=32,n+=32,n+=4+t.readUInt32LE(n),n+=4+t.readUInt32LE(n),n+=4+t.readUInt32LE(n);const r=t.readUInt32LE(n);n+=4;for(let e=0;e<r;e++)n+=4+t.readUInt32LE(n),n+=4+t.readUInt32LE(n);return n-e}(e,n):e.length-n}function ti(e){const r=e instanceof w?e:w.from(e);let o=0;const i=n.MintLayout.decode(r.slice(o,o+n.MINT_SIZE));o+=n.MINT_SIZE;const s=jo.decode(r.slice(o,o+$o));o+=$o;const a=r.slice(o,o+Yo);o+=Yo;const u=r.readUInt8(o);o+=Zo;const c=r.slice(o,o+Qo);o+=Qo;const l=r.readUInt8(o);o+=Xo;const[d,p]=function(e,n){const r=n,o=e.readUInt16LE(n);n+=2;const i=e.readUInt8(n);n+=1;const s=e.readUInt8(n);n+=1;const a=e.readUInt32LE(n);n+=4;const u=new t.PublicKey(e.slice(n,n+32));n+=32;const c=new t.PublicKey(e.slice(n,n+32));n+=32;const l=e.readBigUInt64LE(n);n+=8;const d=e.readUInt32LE(n);n+=4;const p=e.readUInt32LE(n);n+=4;const m=e.readUInt16LE(n);n+=2;const h=e.readUInt16LE(n);n+=2;const f=e.readUInt8(n);n+=1;const g=e.readUInt8(n);return n+=1,[{configAccountVersion:o,compressToPubkey:i,accountVersion:s,lamportsPerWrite:a,compressionAuthority:u,rentSponsor:c,lastClaimedSlot:l,rentExemptionPaid:d,reserved:p,rentConfig:{baseRent:m,compressionCost:h,lamportsPerBytePerEpoch:f,maxFundedEpochs:g,maxTopUp:e.readUInt16LE(n)}},(n+=2)-r]}(r,o);o+=p;const m=1===r.readUInt8(o);o+=1;let h=null;if(m){const t=r.readUInt32LE(o);o+=4,h=[];for(let e=0;e<t;e++){const t=r.readUInt8(o);o+=1;const e=Jo(t,r,o),n=r.slice(o,o+e);o+=e,h.push({extensionType:t,data:n})}}return{base:{mintAuthority:1===i.mintAuthorityOption?i.mintAuthority:null,supply:i.supply,decimals:i.decimals,isInitialized:i.isInitialized,freezeAuthority:1===i.freezeAuthorityOption?i.freezeAuthority:null},mintContext:{version:s.version,cmintDecompressed:0!==s.cmintDecompressed,splMint:s.splMint,mintSigner:a,bump:u},reserved:c,accountType:l,compression:d,extensions:h}}var ei;function ni(t){try{const e=w.from(t);if(e.length<80)return null;const n=zo.decode(e),r=n.updateAuthority.toBuffer().every((t=>0===t))?void 0:n.updateAuthority,o=w.from(n.name).toString("utf-8"),i=w.from(n.symbol).toString("utf-8"),s=w.from(n.uri).toString("utf-8");let a;return n.additionalMetadata&&n.additionalMetadata.length>0&&(a=n.additionalMetadata.map((t=>({key:w.from(t.key).toString("utf-8"),value:w.from(t.value).toString("utf-8")})))),{updateAuthority:r,mint:n.mint,name:o,symbol:i,uri:s,additionalMetadata:a}}catch(t){return console.error("Failed to decode TokenMetadata:",t),null}}exports.ExtensionType=void 0,(ei=exports.ExtensionType||(exports.ExtensionType={}))[ei.TokenMetadata=19]="TokenMetadata";const ri=ni;function oi(t){if(!t)return null;const e=t.find((t=>t.extensionType===exports.ExtensionType.TokenMetadata));return e?ri(e.data):null}async function ii(t,r,o,i){var s,a;if(e.assertBetaEnabled(),!i){const[i,s,u]=await Promise.allSettled([ii(t,r,o,n.TOKEN_PROGRAM_ID),ii(t,r,o,n.TOKEN_2022_PROGRAM_ID),ii(t,r,o,e.LIGHT_TOKEN_PROGRAM_ID)]);if("fulfilled"===i.status)return i.value;if("fulfilled"===s.status)return s.value;if("fulfilled"===u.status)return u.value;const c=[i,s,u].filter((t=>"rejected"===t.status)).map((t=>t.reason)),l=c.find((t=>t instanceof n.TokenInvalidAccountOwnerError));if(l)throw l;const d=c.length>0&&c.every((t=>t instanceof n.TokenAccountNotFoundError));if(d)throw new n.TokenAccountNotFoundError(`Mint not found: ${r.toString()}. Tried TOKEN_PROGRAM_ID, TOKEN_2022_PROGRAM_ID, and LIGHT_TOKEN_PROGRAM_ID.`);const p=c.find((t=>!(t instanceof n.TokenAccountNotFoundError||t instanceof n.TokenInvalidAccountOwnerError)));if(p)throw new Error(`Failed to fetch mint data from RPC: ${a=p,a instanceof Error?a.message:String(a)}`);throw new n.TokenAccountNotFoundError(`Mint not found: ${r.toString()}. Tried TOKEN_PROGRAM_ID, TOKEN_2022_PROGRAM_ID, and LIGHT_TOKEN_PROGRAM_ID.`)}if(i.equals(e.LIGHT_TOKEN_PROGRAM_ID)){const a=e.getDefaultAddressTreeInfo().tree,u=e.deriveAddressV2(r.toBytes(),a,e.LIGHT_TOKEN_PROGRAM_ID),c=await t.getCompressedAccount(e.bn(u.toBytes()));if(!(null===(s=null==c?void 0:c.data)||void 0===s?void 0:s.data))throw new n.TokenAccountNotFoundError(`Light mint not found for ${r.toString()}`);if(!c.owner.equals(e.LIGHT_TOKEN_PROGRAM_ID))throw new n.TokenInvalidAccountOwnerError;const l=w.from(c.data.data),d=64;let p;if(l.length<d){const i=await t.getAccountInfo(r,o);if(!(null==i?void 0:i.data))throw new n.TokenAccountNotFoundError(`Decompressed light mint account not found on-chain for ${r.toString()}`);if(!i.owner.equals(e.LIGHT_TOKEN_PROGRAM_ID))throw new n.TokenInvalidAccountOwnerError;p=ti(w.from(i.data))}else p=ti(l);const m={address:r,mintAuthority:p.base.mintAuthority,supply:p.base.supply,decimals:p.base.decimals,isInitialized:p.base.isInitialized,freezeAuthority:p.base.freezeAuthority,tlvData:w.alloc(0)},h={treeInfo:c.treeInfo,hash:c.hash,leafIndex:c.leafIndex,proveByIndex:c.proveByIndex},f=oi(p.extensions),g={mint:m,programId:i,merkleContext:h,mintContext:p.mintContext,tokenMetadata:f||void 0,extensions:p.extensions||void 0,compression:p.compression};if(!g.merkleContext)throw new Error("Invalid light mint: merkleContext is required for LIGHT_TOKEN_PROGRAM_ID");if(!g.mintContext)throw new Error("Invalid light mint: mintContext is required for LIGHT_TOKEN_PROGRAM_ID");return g}return{mint:await n.getMint(t,r,o,i),programId:i}}function si(t){if(!t.tokenMetadata)throw new Error("Mint does not have TokenMetadata extension");if(!t.merkleContext)throw new Error(Sn)}async function ai(t,n,r,o,i,s,a,u=0,c){e.assertBetaEnabled(),null!=i||(i=r);const l=null!=c?c:(await ii(t,o)).mint.decimals,d=await kr(t,n,r.publicKey,o,l,i.publicKey,a,u);if(0===d.length)return null;const p=e.dedupeSigner(i,[r]),m=d.map((async n=>{const{blockhash:r}=await t.getLatestBlockhash(),o=e.buildAndSignTx(n,i,r,p);return e.sendAndConfirmTx(t,o,s)})),h=await Promise.all(m);return h[h.length-1]}function ui(t){if(!("publicKey"in t)||!("secretKey"in t))return 0;const e=t;return e.secretKey instanceof Uint8Array&&e.secretKey.length>0}function ci(t){return ui(t)?t.publicKey:t}async function li(r,o,i,s,a,u,c,l,d,p){const m=ci(s),h=n.getAssociatedTokenAddressSync(i,m,a,l,d);return l.equals(e.LIGHT_TOKEN_PROGRAM_ID)?async function(t,r,o,i,s,a,u,c=0,l=0){var d,p,m;const h=ci(i);let f;ui(i);let g=0;try{f=await Wn(t,s,h,o,a,e.LIGHT_TOKEN_PROGRAM_ID,c,l),g=null!==(p=null===(d=f._sources)||void 0===d?void 0:d.some((t=>t.type===xn.LightTokenHot)))&&void 0!==p?p:0}catch(i){if(!(i instanceof n.TokenAccountNotFoundError||i instanceof n.TokenInvalidAccountOwnerError))throw i;await di(t,r,o,h,s,u),f=await Wn(t,s,h,o,a,e.LIGHT_TOKEN_PROGRAM_ID,c,l),g=1}g||await di(t,r,o,h,s,u);const y=ui(i)?i:r.publicKey.equals(h)?r:null;if(y){const n=null!==(m=f._sources)&&void 0!==m?m:[],i=n.some((t=>t.type===xn.LightTokenCold&&t.amount>BigInt(0))),d=c&&n.some((t=>(t.type===xn.Spl||t.type===xn.Token2022)&&t.amount>BigInt(0)));if(i||d){if(!(y.secretKey instanceof Uint8Array)||0===y.secretKey.length)throw new Error("Owner must be a valid Signer with secretKey to auto-load");await ai(t,s,y,o,r,u,void 0,c),f=await Wn(t,s,h,o,a,e.LIGHT_TOKEN_PROGRAM_ID,c,l)}}const b=f.parsed;if(!b.mint.equals(o))throw new n.TokenInvalidMintError;if(!b.owner.equals(h))throw new n.TokenInvalidOwnerError;return f}(r,o,i,s,h,u,c,p,a):async function(e,r,o,i,s,a,u,c,l){let d;try{d=await Nn(e,s,c,a)}catch(p){if(!(p instanceof n.TokenAccountNotFoundError||p instanceof n.TokenInvalidAccountOwnerError))throw p;try{const n=(new t.Transaction).add(gn(r.publicKey,s,i,o,a,u));await t.sendAndConfirmTransaction(e,n,[r],l)}catch(t){try{await Nn(e,s,c,a)}catch(e){throw t}}d=await Nn(e,s,c,a)}const p=d.parsed;if(!p.mint.equals(o))throw new n.TokenInvalidMintError;if(!p.owner.equals(i))throw new n.TokenInvalidOwnerError;return d}(r,o,i,m,h,l,d,u,c)}async function di(n,r,o,i,s,a){const u=yn(r.publicKey,s,i,o,e.LIGHT_TOKEN_PROGRAM_ID),{blockhash:c}=await n.getLatestBlockhash(),l=e.buildAndSignTx([t.ComputeBudgetProgram.setComputeUnitLimit({units:2e5}),u],r,c,[]);await e.sendAndConfirmTx(n,l,a)}function pi(t){if(0===t.length)throw new Error("sliceLast: array must not be empty");return{rest:t.slice(0,-1),last:t.at(-1)}}async function mi(t,n,r,o,i){i=i||await Ae.getMintProgramId(r,t);const s=await Ae.createSplInterface({feePayer:n.publicKey,mint:r,tokenProgramId:i}),{blockhash:a}=await t.getLatestBlockhash(),u=e.buildAndSignTx([s],n,a);return await e.sendAndConfirmTx(t,u,o)}const hi=mi;async function fi(t,n,r,o,i,s){s=s||await Ae.getMintProgramId(r,t);const a=[],u=(await kt(t,r)).slice(0,4),c=[];for(let t=0;t<u.length;t++)u[t].isInitialized||c.push(t);for(let t=0;t<o&&!(t>=c.length);t++)a.push(await Ae.addTokenPool({mint:r,feePayer:n.publicKey,tokenProgramId:s,poolIndex:c[t]}));const{blockhash:l}=await t.getLatestBlockhash(),d=e.buildAndSignTx(a,n,l);return await e.sendAndConfirmTx(t,d,i)}const gi=fi;function yi(t){return!Array.isArray(t)}const bi=yi;exports.ADD_TOKEN_POOL_DISCRIMINATOR=gt,exports.APPROVE_DISCRIMINATOR=ht,exports.BASE_RENT_PER_EPOCH=128,exports.BATCH_COMPRESS_DISCRIMINATOR=dt,exports.COMPRESSED_MINT_SEED=ke,exports.COMPRESSIBLE_LIGHT_TOKEN_ACCOUNT_SIZE=272,exports.COMPRESSIBLE_LIGHT_TOKEN_RENT_PER_EPOCH=wt,exports.COMPRESSION_COST=1e4,exports.COMPRESSION_INCENTIVE=1e3,exports.COMPRESS_SPL_TOKEN_ACCOUNT_DISCRIMINATOR=mt,exports.CPI_AUTHORITY_SEED=ut,exports.CREATE_TOKEN_POOL_DISCRIMINATOR=ct,exports.CompressedTokenInstructionDataApproveLayout=ue,exports.CompressedTokenInstructionDataRevokeLayout=ce,exports.CompressedTokenInstructionDataTransferLayout=zt,exports.CompressedTokenProgram=Ae,exports.CpiContextLayout=Ht,exports.DEFAULT_COMPRESSIBLE_CONFIG=un,exports.DEFAULT_PREPAY_EPOCHS=16,exports.DEFAULT_WRITE_TOP_UP=766,exports.DelegatedTransferLayout=Vt,exports.ERROR_MIXED_TREE_TYPES=Et,exports.ERROR_NO_ACCOUNTS_FOUND=Ct,exports.IDL={version:"1.2.0",name:"light_compressed_token",instructions:[{name:"createTokenPool",docs:["This instruction creates a token pool for a given mint. Every spl mint","can have one token pool. When a token is compressed the tokens are","transferrred to the token pool, and their compressed equivalent is","minted into a Merkle tree."],accounts:[{name:"feePayer",isMut:1,isSigner:1,docs:["UNCHECKED: only pays fees."]},{name:"tokenPoolPda",isMut:1,isSigner:0},{name:"systemProgram",isMut:0,isSigner:0},{name:"mint",isMut:1,isSigner:0},{name:"tokenProgram",isMut:0,isSigner:0},{name:"cpiAuthorityPda",isMut:0,isSigner:0}],args:[]},{name:"addTokenPool",docs:["This instruction creates an additional token pool for a given mint.","The maximum number of token pools per mint is 5."],accounts:[{name:"feePayer",isMut:1,isSigner:1,docs:["UNCHECKED: only pays fees."]},{name:"tokenPoolPda",isMut:1,isSigner:0},{name:"existingTokenPoolPda",isMut:0,isSigner:0},{name:"systemProgram",isMut:0,isSigner:0},{name:"mint",isMut:1,isSigner:0},{name:"tokenProgram",isMut:0,isSigner:0},{name:"cpiAuthorityPda",isMut:0,isSigner:0}],args:[{name:"tokenPoolIndex",type:"u8"}]},{name:"mintTo",docs:["Mints tokens from an spl token mint to a list of compressed accounts.","Minted tokens are transferred to a pool account owned by the compressed","token program. The instruction creates one compressed output account for","every amount and pubkey input pair. A constant amount of lamports can be","transferred to each output account to enable. A use case to add lamports","to a compressed token account is to prevent spam. This is the only way","to add lamports to a compressed token account."],accounts:[{name:"feePayer",isMut:1,isSigner:1,docs:["UNCHECKED: only pays fees."]},{name:"authority",isMut:0,isSigner:1},{name:"cpiAuthorityPda",isMut:0,isSigner:0},{name:"mint",isMut:1,isSigner:0},{name:"tokenPoolPda",isMut:1,isSigner:0},{name:"tokenProgram",isMut:0,isSigner:0},{name:"lightSystemProgram",isMut:0,isSigner:0},{name:"registeredProgramPda",isMut:0,isSigner:0},{name:"noopProgram",isMut:0,isSigner:0,docs:["programs"]},{name:"accountCompressionAuthority",isMut:0,isSigner:0},{name:"accountCompressionProgram",isMut:0,isSigner:0},{name:"merkleTree",isMut:1,isSigner:0},{name:"selfProgram",isMut:0,isSigner:0},{name:"systemProgram",isMut:0,isSigner:0},{name:"solPoolPda",isMut:1,isSigner:0,isOptional:1}],args:[{name:"publicKeys",type:{vec:"publicKey"}},{name:"amounts",type:{vec:"u64"}},{name:"lamports",type:{option:"u64"}}]},{name:"compressSplTokenAccount",docs:["Compresses the balance of an spl token account sub an optional remaining","amount. This instruction does not close the spl token account. To close","the account bundle a close spl account instruction in your transaction."],accounts:[{name:"feePayer",isMut:1,isSigner:1,docs:["UNCHECKED: only pays fees."]},{name:"authority",isMut:0,isSigner:1,docs:["Authority is verified through proof since both owner and delegate","are included in the token data hash, which is a public input to the","validity proof."]},{name:"cpiAuthorityPda",isMut:0,isSigner:0},{name:"lightSystemProgram",isMut:0,isSigner:0},{name:"registeredProgramPda",isMut:0,isSigner:0},{name:"noopProgram",isMut:0,isSigner:0},{name:"accountCompressionAuthority",isMut:0,isSigner:0},{name:"accountCompressionProgram",isMut:0,isSigner:0},{name:"selfProgram",isMut:0,isSigner:0,docs:["this program is the signer of the cpi."]},{name:"tokenPoolPda",isMut:1,isSigner:0,isOptional:1},{name:"compressOrDecompressTokenAccount",isMut:1,isSigner:0,isOptional:1},{name:"tokenProgram",isMut:0,isSigner:0,isOptional:1},{name:"systemProgram",isMut:0,isSigner:0}],args:[{name:"owner",type:"publicKey"},{name:"remainingAmount",type:{option:"u64"}},{name:"cpiContext",type:{option:{defined:"CompressedCpiContext"}}}]},{name:"transfer",docs:["Transfers compressed tokens from one account to another. All accounts","must be of the same mint. Additional spl tokens can be compressed or","decompressed. In one transaction only compression or decompression is","possible. Lamports can be transferred alongside tokens. If output token","accounts specify less lamports than inputs the remaining lamports are","transferred to an output compressed account. Signer must be owner or","delegate. If a delegated token account is transferred the delegate is","not preserved."],accounts:[{name:"feePayer",isMut:1,isSigner:1,docs:["UNCHECKED: only pays fees."]},{name:"authority",isMut:0,isSigner:1,docs:["Authority is verified through proof since both owner and delegate","are included in the token data hash, which is a public input to the","validity proof."]},{name:"cpiAuthorityPda",isMut:0,isSigner:0},{name:"lightSystemProgram",isMut:0,isSigner:0},{name:"registeredProgramPda",isMut:0,isSigner:0},{name:"noopProgram",isMut:0,isSigner:0},{name:"accountCompressionAuthority",isMut:0,isSigner:0},{name:"accountCompressionProgram",isMut:0,isSigner:0},{name:"selfProgram",isMut:0,isSigner:0,docs:["this program is the signer of the cpi."]},{name:"tokenPoolPda",isMut:1,isSigner:0,isOptional:1},{name:"compressOrDecompressTokenAccount",isMut:1,isSigner:0,isOptional:1},{name:"tokenProgram",isMut:0,isSigner:0,isOptional:1},{name:"systemProgram",isMut:0,isSigner:0}],args:[{name:"inputs",type:"bytes"}]},{name:"approve",docs:["Delegates an amount to a delegate. A compressed token account is either","completely delegated or not. Prior delegates are not preserved. Cannot","be called by a delegate.","The instruction creates two output accounts:","1. one account with delegated amount","2. one account with remaining(change) amount"],accounts:[{name:"feePayer",isMut:1,isSigner:1,docs:["UNCHECKED: only pays fees."]},{name:"authority",isMut:0,isSigner:1,docs:["Authority is verified through proof since both owner and delegate","are included in the token data hash, which is a public input to the","validity proof."]},{name:"cpiAuthorityPda",isMut:0,isSigner:0},{name:"lightSystemProgram",isMut:0,isSigner:0},{name:"registeredProgramPda",isMut:0,isSigner:0},{name:"noopProgram",isMut:0,isSigner:0},{name:"accountCompressionAuthority",isMut:0,isSigner:0},{name:"accountCompressionProgram",isMut:0,isSigner:0},{name:"selfProgram",isMut:0,isSigner:0,docs:["this program is the signer of the cpi."]},{name:"systemProgram",isMut:0,isSigner:0}],args:[{name:"inputs",type:"bytes"}]},{name:"revoke",docs:["Revokes a delegation. The instruction merges all inputs into one output","account. Cannot be called by a delegate. Delegates are not preserved."],accounts:[{name:"feePayer",isMut:1,isSigner:1,docs:["UNCHECKED: only pays fees."]},{name:"authority",isMut:0,isSigner:1,docs:["Authority is verified through proof since both owner and delegate","are included in the token data hash, which is a public input to the","validity proof."]},{name:"cpiAuthorityPda",isMut:0,isSigner:0},{name:"lightSystemProgram",isMut:0,isSigner:0},{name:"registeredProgramPda",isMut:0,isSigner:0},{name:"noopProgram",isMut:0,isSigner:0},{name:"accountCompressionAuthority",isMut:0,isSigner:0},{name:"accountCompressionProgram",isMut:0,isSigner:0},{name:"selfProgram",isMut:0,isSigner:0,docs:["this program is the signer of the cpi."]},{name:"systemProgram",isMut:0,isSigner:0}],args:[{name:"inputs",type:"bytes"}]},{name:"freeze",docs:["Freezes compressed token accounts. Inputs must not be frozen. Creates as","many outputs as inputs. Balances and delegates are preserved."],accounts:[{name:"feePayer",isMut:1,isSigner:1,docs:["UNCHECKED: only pays fees."]},{name:"authority",isMut:0,isSigner:1},{name:"cpiAuthorityPda",isMut:0,isSigner:0},{name:"lightSystemProgram",isMut:0,isSigner:0},{name:"registeredProgramPda",isMut:0,isSigner:0},{name:"noopProgram",isMut:0,isSigner:0},{name:"accountCompressionAuthority",isMut:0,isSigner:0},{name:"accountCompressionProgram",isMut:0,isSigner:0},{name:"selfProgram",isMut:0,isSigner:0,docs:["that this program is the signer of the cpi."]},{name:"systemProgram",isMut:0,isSigner:0},{name:"mint",isMut:0,isSigner:0}],args:[{name:"inputs",type:"bytes"}]},{name:"thaw",docs:["Thaws frozen compressed token accounts. Inputs must be frozen. Creates","as many outputs as inputs. Balances and delegates are preserved."],accounts:[{name:"feePayer",isMut:1,isSigner:1,docs:["UNCHECKED: only pays fees."]},{name:"authority",isMut:0,isSigner:1},{name:"cpiAuthorityPda",isMut:0,isSigner:0},{name:"lightSystemProgram",isMut:0,isSigner:0},{name:"registeredProgramPda",isMut:0,isSigner:0},{name:"noopProgram",isMut:0,isSigner:0},{name:"accountCompressionAuthority",isMut:0,isSigner:0},{name:"accountCompressionProgram",isMut:0,isSigner:0},{name:"selfProgram",isMut:0,isSigner:0,docs:["that this program is the signer of the cpi."]},{name:"systemProgram",isMut:0,isSigner:0},{name:"mint",isMut:0,isSigner:0}],args:[{name:"inputs",type:"bytes"}]},{name:"burn",docs:["Burns compressed tokens and spl tokens from the pool account. Delegates","can burn tokens. The output compressed token account remains delegated.","Creates one output compressed token account."],accounts:[{name:"feePayer",isMut:1,isSigner:1,docs:["UNCHECKED: only pays fees."]},{name:"authority",isMut:0,isSigner:1,docs:["Authority is verified through proof since both owner and delegate","are included in the token data hash, which is a public input to the","validity proof."]},{name:"cpiAuthorityPda",isMut:0,isSigner:0},{name:"mint",isMut:1,isSigner:0},{name:"tokenPoolPda",isMut:1,isSigner:0},{name:"tokenProgram",isMut:0,isSigner:0},{name:"lightSystemProgram",isMut:0,isSigner:0},{name:"registeredProgramPda",isMut:0,isSigner:0},{name:"noopProgram",isMut:0,isSigner:0},{name:"accountCompressionAuthority",isMut:0,isSigner:0},{name:"accountCompressionProgram",isMut:0,isSigner:0},{name:"selfProgram",isMut:0,isSigner:0},{name:"systemProgram",isMut:0,isSigner:0}],args:[{name:"inputs",type:"bytes"}]},{name:"stubIdlBuild",docs:["This function is a stub to allow Anchor to include the input types in","the IDL. It should not be included in production builds nor be called in","practice."],accounts:[{name:"feePayer",isMut:1,isSigner:1,docs:["UNCHECKED: only pays fees."]},{name:"authority",isMut:0,isSigner:1,docs:["Authority is verified through proof since both owner and delegate","are included in the token data hash, which is a public input to the","validity proof."]},{name:"cpiAuthorityPda",isMut:0,isSigner:0},{name:"lightSystemProgram",isMut:0,isSigner:0},{name:"registeredProgramPda",isMut:0,isSigner:0},{name:"noopProgram",isMut:0,isSigner:0},{name:"accountCompressionAuthority",isMut:0,isSigner:0},{name:"accountCompressionProgram",isMut:0,isSigner:0},{name:"selfProgram",isMut:0,isSigner:0,docs:["this program is the signer of the cpi."]},{name:"tokenPoolPda",isMut:1,isSigner:0,isOptional:1},{name:"compressOrDecompressTokenAccount",isMut:1,isSigner:0,isOptional:1},{name:"tokenProgram",isMut:0,isSigner:0,isOptional:1},{name:"systemProgram",isMut:0,isSigner:0}],args:[{name:"inputs1",type:{defined:"CompressedTokenInstructionDataTransfer"}},{name:"inputs2",type:{defined:"TokenData"}}]}],types:[{name:"AccountState",type:{kind:"enum",variants:[{name:"Initialized"},{name:"Frozen"}]}},{name:"CompressedAccount",type:{kind:"struct",fields:[{name:"owner",type:"publicKey"},{name:"lamports",type:"u64"},{name:"address",type:{option:{array:["u8",32]}}},{name:"data",type:{option:{defined:"CompressedAccountData"}}}]}},{name:"CompressedAccountData",type:{kind:"struct",fields:[{name:"discriminator",type:{array:["u8",8]}},{name:"data",type:"bytes"},{name:"dataHash",type:{array:["u8",32]}}]}},{name:"CompressedCpiContext",type:{kind:"struct",fields:[{name:"setContext",docs:["Is set by the program that is invoking the CPI to signal that is should","set the cpi context."],type:"bool"},{name:"firstSetContext",docs:["Is set to wipe the cpi context since someone could have set it before","with unrelated data."],type:"bool"},{name:"cpiContextAccountIndex",docs:["Index of cpi context account in remaining accounts."],type:"u8"}]}},{name:"CompressedProof",type:{kind:"struct",fields:[{name:"a",type:{array:["u8",32]}},{name:"b",type:{array:["u8",64]}},{name:"c",type:{array:["u8",32]}}]}},{name:"CompressedTokenInstructionDataTransfer",type:{kind:"struct",fields:[{name:"proof",type:{option:{defined:"CompressedProof"}}},{name:"mint",type:"publicKey"},{name:"delegatedTransfer",docs:["Is required if the signer is delegate,","-> delegate is authority account,","owner = Some(owner) is the owner of the token account."],type:{option:{defined:"DelegatedTransfer"}}},{name:"inputTokenDataWithContext",type:{vec:{defined:"InputTokenDataWithContext"}}},{name:"outputCompressedAccounts",type:{vec:{defined:"PackedTokenTransferOutputData"}}},{name:"isCompress",type:"bool"},{name:"compressOrDecompressAmount",type:{option:"u64"}},{name:"cpiContext",type:{option:{defined:"CompressedCpiContext"}}},{name:"lamportsChangeAccountMerkleTreeIndex",type:{option:"u8"}}]}},{name:"CompressedTokenInstructionDataRevoke",type:{kind:"struct",fields:[{name:"proof",type:{option:{defined:"CompressedProof"}}},{name:"mint",type:"publicKey"},{name:"inputTokenDataWithContext",type:{vec:{defined:"InputTokenDataWithContext"}}},{name:"cpiContext",type:{option:{defined:"CompressedCpiContext"}}},{name:"outputAccountMerkleTreeIndex",type:"u8"}]}},{name:"CompressedTokenInstructionDataApprove",type:{kind:"struct",fields:[{name:"proof",type:{option:{defined:"CompressedProof"}}},{name:"mint",type:"publicKey"},{name:"inputTokenDataWithContext",type:{vec:{defined:"InputTokenDataWithContext"}}},{name:"cpiContext",type:{option:{defined:"CompressedCpiContext"}}},{name:"delegate",type:"publicKey"},{name:"delegatedAmount",type:"u64"},{name:"delegateMerkleTreeIndex",type:"u8"},{name:"changeAccountMerkleTreeIndex",type:"u8"},{name:"delegateLamports",type:{option:"u64"}}]}},{name:"DelegatedTransfer",docs:["Struct to provide the owner when the delegate is signer of the transaction."],type:{kind:"struct",fields:[{name:"owner",type:"publicKey"},{name:"delegateChangeAccountIndex",docs:["Index of change compressed account in output compressed accounts. In","case that the delegate didn't spend the complete delegated compressed","account balance the change compressed account will be delegated to her","as well."],type:{option:"u8"}}]}},{name:"InputTokenDataWithContext",type:{kind:"struct",fields:[{name:"amount",type:"u64"},{name:"delegateIndex",type:{option:"u8"}},{name:"merkleContext",type:{defined:"PackedMerkleContext"}},{name:"rootIndex",type:"u16"},{name:"lamports",type:{option:"u64"}},{name:"tlv",docs:["Placeholder for TokenExtension tlv data (unimplemented)"],type:{option:"bytes"}}]}},{name:"InstructionDataInvoke",type:{kind:"struct",fields:[{name:"proof",type:{option:{defined:"CompressedProof"}}},{name:"inputCompressedAccountsWithMerkleContext",type:{vec:{defined:"PackedCompressedAccountWithMerkleContext"}}},{name:"outputCompressedAccounts",type:{vec:{defined:"OutputCompressedAccountWithPackedContext"}}},{name:"relayFee",type:{option:"u64"}},{name:"newAddressParams",type:{vec:{defined:"NewAddressParamsPacked"}}},{name:"compressOrDecompressLamports",type:{option:"u64"}},{name:"isCompress",type:"bool"}]}},{name:"InstructionDataInvokeCpi",type:{kind:"struct",fields:[{name:"proof",type:{option:{defined:"CompressedProof"}}},{name:"newAddressParams",type:{vec:{defined:"NewAddressParamsPacked"}}},{name:"inputCompressedAccountsWithMerkleContext",type:{vec:{defined:"PackedCompressedAccountWithMerkleContext"}}},{name:"outputCompressedAccounts",type:{vec:{defined:"OutputCompressedAccountWithPackedContext"}}},{name:"relayFee",type:{option:"u64"}},{name:"compressOrDecompressLamports",type:{option:"u64"}},{name:"isCompress",type:"bool"},{name:"cpiContext",type:{option:{defined:"CompressedCpiContext"}}}]}},{name:"MerkleTreeSequenceNumber",type:{kind:"struct",fields:[{name:"pubkey",type:"publicKey"},{name:"seq",type:"u64"}]}},{name:"NewAddressParamsPacked",type:{kind:"struct",fields:[{name:"seed",type:{array:["u8",32]}},{name:"addressQueueAccountIndex",type:"u8"},{name:"addressMerkleTreeAccountIndex",type:"u8"},{name:"addressMerkleTreeRootIndex",type:"u16"}]}},{name:"OutputCompressedAccountWithPackedContext",type:{kind:"struct",fields:[{name:"compressedAccount",type:{defined:"CompressedAccount"}},{name:"merkleTreeIndex",type:"u8"}]}},{name:"PackedCompressedAccountWithMerkleContext",type:{kind:"struct",fields:[{name:"compressedAccount",type:{defined:"CompressedAccount"}},{name:"merkleContext",type:{defined:"PackedMerkleContext"}},{name:"rootIndex",docs:["Index of root used in inclusion validity proof."],type:"u16"},{name:"readOnly",docs:["Placeholder to mark accounts read-only unimplemented set to false."],type:"bool"}]}},{name:"PackedMerkleContext",type:{kind:"struct",fields:[{name:"merkleTreePubkeyIndex",type:"u8"},{name:"queuePubkeyIndex",type:"u8"},{name:"leafIndex",type:"u32"},{name:"proveByIndex",type:"bool"}]}},{name:"PackedTokenTransferOutputData",type:{kind:"struct",fields:[{name:"owner",type:"publicKey"},{name:"amount",type:"u64"},{name:"lamports",type:{option:"u64"}},{name:"merkleTreeIndex",type:"u8"},{name:"tlv",docs:["Placeholder for TokenExtension tlv data (unimplemented)"],type:{option:"bytes"}}]}},{name:"PublicTransactionEvent",type:{kind:"struct",fields:[{name:"inputCompressedAccountHashes",type:{vec:{array:["u8",32]}}},{name:"outputCompressedAccountHashes",type:{vec:{array:["u8",32]}}},{name:"outputCompressedAccounts",type:{vec:{defined:"OutputCompressedAccountWithPackedContext"}}},{name:"outputLeafIndices",type:{vec:"u32"}},{name:"sequenceNumbers",type:{vec:{defined:"MerkleTreeSequenceNumber"}}},{name:"relayFee",type:{option:"u64"}},{name:"isCompress",type:"bool"},{name:"compressOrDecompressLamports",type:{option:"u64"}},{name:"pubkeyArray",type:{vec:"publicKey"}},{name:"message",type:{option:"bytes"}}]}},{name:"QueueIndex",type:{kind:"struct",fields:[{name:"queueId",docs:["Id of queue in queue account."],type:"u8"},{name:"index",docs:["Index of compressed account hash in queue."],type:"u16"}]}},{name:"TokenData",type:{kind:"struct",fields:[{name:"mint",docs:["The mint associated with this account"],type:"publicKey"},{name:"owner",docs:["The owner of this account."],type:"publicKey"},{name:"amount",docs:["The amount of tokens this account holds."],type:"u64"},{name:"delegate",docs:["If `delegate` is `Some` then `delegated_amount` represents","the amount authorized by the delegate"],type:{option:"publicKey"}},{name:"state",docs:["The account's state"],type:{defined:"AccountState"}},{name:"tlv",docs:["Placeholder for TokenExtension tlv data (unimplemented)"],type:{option:"bytes"}}]}}],errors:[{code:6e3,name:"PublicKeyAmountMissmatch",msg:"public keys and amounts must be of same length"},{code:6001,name:"ComputeInputSumFailed",msg:"ComputeInputSumFailed"},{code:6002,name:"ComputeOutputSumFailed",msg:"ComputeOutputSumFailed"},{code:6003,name:"ComputeCompressSumFailed",msg:"ComputeCompressSumFailed"},{code:6004,name:"ComputeDecompressSumFailed",msg:"ComputeDecompressSumFailed"},{code:6005,name:"SumCheckFailed",msg:"SumCheckFailed"},{code:6006,name:"DecompressRecipientUndefinedForDecompress",msg:"DecompressRecipientUndefinedForDecompress"},{code:6007,name:"CompressedPdaUndefinedForDecompress",msg:"CompressedPdaUndefinedForDecompress"},{code:6008,name:"DeCompressAmountUndefinedForDecompress",msg:"DeCompressAmountUndefinedForDecompress"},{code:6009,name:"CompressedPdaUndefinedForCompress",msg:"CompressedPdaUndefinedForCompress"},{code:6010,name:"DeCompressAmountUndefinedForCompress",msg:"DeCompressAmountUndefinedForCompress"},{code:6011,name:"DelegateSignerCheckFailed",msg:"DelegateSignerCheckFailed"},{code:6012,name:"MintTooLarge",msg:"Minted amount greater than u64::MAX"},{code:6013,name:"SplTokenSupplyMismatch",msg:"SplTokenSupplyMismatch"},{code:6014,name:"HeapMemoryCheckFailed",msg:"HeapMemoryCheckFailed"},{code:6015,name:"InstructionNotCallable",msg:"The instruction is not callable"},{code:6016,name:"ArithmeticUnderflow",msg:"ArithmeticUnderflow"},{code:6017,name:"HashToFieldError",msg:"HashToFieldError"},{code:6018,name:"InvalidAuthorityMint",msg:"Expected the authority to be also a mint authority"},{code:6019,name:"InvalidFreezeAuthority",msg:"Provided authority is not the freeze authority"},{code:6020,name:"InvalidDelegateIndex"},{code:6021,name:"TokenPoolPdaUndefined"},{code:6022,name:"IsTokenPoolPda",msg:"Compress or decompress recipient is the same account as the token pool pda."},{code:6023,name:"InvalidTokenPoolPda"},{code:6024,name:"NoInputTokenAccountsProvided"},{code:6025,name:"NoInputsProvided"},{code:6026,name:"MintHasNoFreezeAuthority"},{code:6027,name:"MintWithInvalidExtension"},{code:6028,name:"InsufficientTokenAccountBalance",msg:"The token account balance is less than the remaining amount."},{code:6029,name:"InvalidTokenPoolBump",msg:"Max number of token pools reached."},{code:6030,name:"FailedToDecompress"},{code:6031,name:"FailedToBurnSplTokensFromTokenPool"},{code:6032,name:"NoMatchingBumpFound"}]},exports.LIGHT_TOKEN_CONFIG=ot,exports.LIGHT_TOKEN_RENT_SPONSOR=it,exports.MAX_COMBINED_BATCH_BYTES=900,exports.MAX_LOAD_ONLY_BATCH_BYTES=1e3,exports.MAX_TOP_UP=yt,exports.MAX_TRANSACTION_SIZE=Wr,exports.MINT_TO_DISCRIMINATOR=lt,exports.POOL_SEED=at,exports.RENT_PER_BYTE_PER_EPOCH=1,exports.REVOKE_DISCRIMINATOR=ft,exports.SLOTS_PER_RENT_EPOCH=13500,exports.SPL_TOKEN_MINT_RENT_EXEMPT_BALANCE=1461600,exports.TOTAL_COMPRESSION_COST=11e3,exports.TRANSFER_DISCRIMINATOR=pt,exports._getOrCreateAtaInterface=li,exports.addSplInterfaces=fi,exports.addTokenPoolAccountsLayout=ee,exports.addTokenPools=gi,exports.approve=async function(n,r,o,i,s,a,u){i=e.bn(i);const c=await n.getCompressedTokenAccountsByOwner(s.publicKey,{mint:o}),{accounts:l}=Bt(c.items,i),[d]=Lt(l,i),p=await n.getValidityProofV0(d.map((t=>({hash:t.compressedAccount.hash,tree:t.compressedAccount.treeInfo.tree,queue:t.compressedAccount.treeInfo.queue})))),m=await Ae.approve({payer:r.publicKey,inputCompressedTokenAccounts:d,toAddress:a,amount:i,recentInputStateRootIndices:p.rootIndices,recentValidityProof:p.compressedProof}),{blockhash:h}=await n.getLatestBlockhash(),f=e.dedupeSigner(r,[s]),g=e.buildAndSignTx([t.ComputeBudgetProgram.setComputeUnitLimit({units:35e4}),m],r,h,f);return e.sendAndConfirmTx(n,g,u)},exports.approveAccountsLayout=oe,exports.approveAndMintTo=async function(r,o,i,s,a,u,c,l,d){c=null!=c?c:e.selectStateTreeInfo(await r.getStateTreeInfos()),l=null!=l?l:St(await kt(r,i));const p=await n.getOrCreateAssociatedTokenAccount(r,o,i,a.publicKey,void 0,void 0,d,l.tokenProgram),m=await Ae.approveAndMintTo({feePayer:o.publicKey,mint:i,authority:a.publicKey,authorityTokenAccount:p.address,amount:u,toPubkey:s,outputStateTreeInfo:c,tokenPoolInfo:l}),{blockhash:h}=await r.getLatestBlockhash(),f=e.dedupeSigner(o,[a]),g=e.buildAndSignTx([t.ComputeBudgetProgram.setComputeUnitLimit({units:15e4+2e4*e.toArray(u).length}),...m],o,h,f);return await e.sendAndConfirmTx(r,g,d)},exports.batchCompressLayout=$t,exports.calculateFeePayerCostAtCreation=function(t=16,e=272){return 11e3+t*bt(e)},exports.checkMint=Wt,exports.checkSplInterfaceInfo=Tt,exports.checkTokenPoolInfo=function(t,e){return Tt(vt(t),e)},exports.compress=async function(n,r,o,i,s,a,u,c,l,d){c=null!=c?c:e.selectStateTreeInfo(await n.getStateTreeInfos()),l=null!=l?l:St(await kt(n,o));const p=await Ae.compress({payer:r.publicKey,owner:s.publicKey,source:a,toAddress:u,amount:i,mint:o,outputStateTreeInfo:c,tokenPoolInfo:l}),m=await n.getLatestBlockhash(),h=e.dedupeSigner(r,[s]),f=e.buildAndSignTx([t.ComputeBudgetProgram.setComputeUnitLimit({units:13e4+2e4*e.toArray(i).length}),p],r,m.blockhash,h);return await e.sendAndConfirmTx(n,f,d,m)},exports.compressSplTokenAccount=async function(n,r,o,i,s,a,u,c,l){u=null!=u?u:e.selectStateTreeInfo(await n.getStateTreeInfos()),c=null!=c?c:St(await kt(n,o));const d=await Ae.compressSplTokenAccount({feePayer:r.publicKey,authority:i.publicKey,tokenAccount:s,mint:o,remainingAmount:a,outputStateTreeInfo:u,tokenPoolInfo:c}),p=await n.getLatestBlockhash(),m=e.dedupeSigner(r,[i]),h=e.buildAndSignTx([t.ComputeBudgetProgram.setComputeUnitLimit({units:15e4}),d],r,p.blockhash,m);return await e.sendAndConfirmTx(n,h,l,p)},exports.compressSplTokenAccountInstructionDataLayout=Yt,exports.convertTokenDataToAccount=Ln,exports.createAssociatedLightTokenAccountIdempotentInstruction=pn,exports.createAssociatedLightTokenAccountInstruction=dn,exports.createAssociatedTokenAccountInterfaceIdempotentInstruction=yn,exports.createAssociatedTokenAccountInterfaceInstruction=gn,exports.createAtaInterface=async function(n,r,o,i,s=0,a,u=e.LIGHT_TOKEN_PROGRAM_ID,c,l){e.assertBetaEnabled();const d=null!=c?c:mn(u),p=zn(o,i,s,u,d),m=gn(r.publicKey,p,i,o,u,d,l);if(u.equals(e.LIGHT_TOKEN_PROGRAM_ID)){const{blockhash:o}=await n.getLatestBlockhash(),i=e.buildAndSignTx([t.ComputeBudgetProgram.setComputeUnitLimit({units:3e4}),m],r,o,[]);await e.sendAndConfirmTx(n,i,a)}else{const e=(new t.Transaction).add(m);await t.sendAndConfirmTransaction(n,e,[r],a)}return p},exports.createAtaInterfaceIdempotent=async function(n,r,o,i,s=0,a,u=e.LIGHT_TOKEN_PROGRAM_ID,c,l){e.assertBetaEnabled();const d=null!=c?c:mn(u),p=zn(o,i,s,u,d),m=yn(r.publicKey,p,i,o,u,d,l);if(u.equals(e.LIGHT_TOKEN_PROGRAM_ID)){const{blockhash:o}=await n.getLatestBlockhash(),i=e.buildAndSignTx([t.ComputeBudgetProgram.setComputeUnitLimit({units:3e4}),m],r,o,[]);await e.sendAndConfirmTx(n,i,a)}else{const e=(new t.Transaction).add(m);await t.sendAndConfirmTransaction(n,e,[r],a)}return p},exports.createAtaInterfaceIdempotentInstruction=bn,exports.createDecompressOutputState=ve,exports.createLightTokenFreezeAccountInstruction=function(n,r,o){return new t.TransactionInstruction({programId:e.LIGHT_TOKEN_PROGRAM_ID,keys:[{pubkey:n,isSigner:0,isWritable:1},{pubkey:r,isSigner:0,isWritable:0},{pubkey:o,isSigner:1,isWritable:0}],data:eo})},exports.createLightTokenThawAccountInstruction=function(n,r,o){return new t.TransactionInstruction({programId:e.LIGHT_TOKEN_PROGRAM_ID,keys:[{pubkey:n,isSigner:0,isWritable:1},{pubkey:r,isSigner:0,isWritable:0},{pubkey:o,isSigner:1,isWritable:0}],data:no})},exports.createLightTokenTransferCheckedInstruction=Qr,exports.createLightTokenTransferInstruction=function(n,r,o,i,s){const a=Buffer.alloc(9);a.writeUInt8(3,0),a.writeBigUInt64LE(BigInt(i),1);const u=null!=s?s:o,c=[{pubkey:n,isSigner:0,isWritable:1},{pubkey:r,isSigner:0,isWritable:1},{pubkey:o,isSigner:1,isWritable:u.equals(o)},{pubkey:t.SystemProgram.programId,isSigner:0,isWritable:0},{pubkey:u,isSigner:!u.equals(o),isWritable:1}];return new t.TransactionInstruction({programId:e.LIGHT_TOKEN_PROGRAM_ID,keys:c,data:a})},exports.createLoadAtaInstructions=kr,exports.createMint=ro,exports.createMintInstruction=$e,exports.createMintInterface=async function(r,o,i,s,a,u=t.Keypair.generate(),c,l=e.LIGHT_TOKEN_PROGRAM_ID,d,p,m){if(e.assertBetaEnabled(),l.equals(n.TOKEN_PROGRAM_ID)||l.equals(n.TOKEN_2022_PROGRAM_ID))return ro(r,o,i,a,u,c,l,s);if(!("secretKey"in i))throw new Error("mintAuthority must be a Signer for light-token mints");if(m&&!m.tree.equals(e.getDefaultAddressTreeInfo().tree))throw new Error(`addressTreeInfo ${null==m?void 0:m.tree.toString()} must be the default address tree info: ${e.getDefaultAddressTreeInfo().tree.toString()}`);const h=s&&"secretKey"in s?s.publicKey:s;m=null!=m?m:e.getBatchAddressTreeInfo(),p=null!=p?p:e.selectStateTreeInfo(await r.getStateTreeInfos());const f=Te(u.publicKey,m),g=await r.getValidityProofV2([],[{address:Uint8Array.from(f),treeInfo:m}],e.DerivationMode.standard),y=$e(u.publicKey,a,i.publicKey,h,o.publicKey,g,m,p,d),b=e.dedupeSigner(o,[u,i]),{blockhash:w}=await r.getLatestBlockhash(),I=e.buildAndSignTx([t.ComputeBudgetProgram.setComputeUnitLimit({units:5e5}),y],o,w,b),v=await e.sendAndConfirmTx(r,I);return{mint:Pe(u.publicKey)[0],transactionSignature:v}},exports.createMintToCompressedInstruction=Ur,exports.createMintToInstruction=Kr,exports.createMintToInterfaceInstruction=Nr,exports.createRemoveMetadataKeyInstruction=en,exports.createSplInterface=mi,exports.createTokenMetadata=function(t,e,n,r,o=null){return{name:t,symbol:e,uri:n,updateAuthority:null!=r?r:null,additionalMetadata:null!=o?o:null}},exports.createTokenPool=hi,exports.createTokenPoolAccountsLayout=te,exports.createTokenProgramLookupTable=async function(t,n,r,o,i){const s=await t.getSlot("finalized"),{instructions:a,address:u}=await Ae.createTokenProgramLookupTable({payer:n.publicKey,authority:r.publicKey,mints:o,remainingAccounts:i,recentSlot:s}),c=e.dedupeSigner(n,[r]),l=[];for(const r of a){const o=await t.getLatestBlockhash(),i=e.buildAndSignTx([r],n,o.blockhash,c),s=await e.sendAndConfirmTx(t,i,{commitment:"finalized"},o);l.push(s)}return{txIds:l,address:u}},exports.createTransferInterfaceInstructions=Xr,exports.createTransferOutputState=Ie,exports.createUnwrapInstruction=to,exports.createUnwrapInstructions=async function(r,o,i,s,a,u,c,l,d,p,m=0){e.assertBetaEnabled(),null!=c||(c=i);let h=l;if(!h&&(h=(await kt(r,s)).find((t=>t.isInitialized)),!h))throw new Error(`No initialized SPL interface found for mint: ${s.toBase58()}. Please create an SPL interface via createSplInterface().`);if(!await r.getAccountInfo(o))throw new Error(`Destination account does not exist: ${o.toBase58()}. Create it first using getOrCreateAssociatedTokenAccount or createAssociatedTokenAccountIdempotentInstruction.`);const f=zn(s,i);let g;try{g=await Wn(r,f,i,s,void 0,void 0,m)}catch(t){if(t instanceof n.TokenAccountNotFoundError)throw new Error(Mn);throw t}On(g,"unwrap");const y=g.parsed.amount;if(y===BigInt(0))throw new Error(Mn);const b=null!=u?BigInt(u.toString()):y;if(b===BigInt(0))throw new Error("Unwrap amount must be greater than zero.");if(b>y)throw new Error(`Insufficient light-token balance. Requested: ${b}, Available: ${y}`);const w=await Dr(r,c,g,p,m,f,null!=u?b:void 0,void 0,a),I=to(f,o,i,s,b,h,a,c,d),v=c.equals(i)?1:2;if(0===w.length){const e=[t.ComputeBudgetProgram.setComputeUnitLimit({units:Jr(null)}),I];return Gr(e,v,"Unwrap batch"),[e]}if(1===w.length){const e=w[0],n=[t.ComputeBudgetProgram.setComputeUnitLimit({units:Jr(e)}),...e.instructions,I];return Gr(n,v,"Unwrap batch"),[n]}const A=[];for(let e=0;e<w.length-1;e++){const n=w[e],r=Lr(n),o=[t.ComputeBudgetProgram.setComputeUnitLimit({units:r}),...n.instructions];Gr(o,v,"Unwrap batch"),A.push(o)}const T=w[w.length-1],k=[t.ComputeBudgetProgram.setComputeUnitLimit({units:Jr(T)}),...T.instructions,I];return Gr(k,v,"Unwrap batch"),A.push(k),A},exports.createUpdateFreezeAuthorityInstruction=Qe,exports.createUpdateMetadataAuthorityInstruction=tn,exports.createUpdateMetadataFieldInstruction=Je,exports.createUpdateMintAuthorityInstruction=Ze,exports.createWrapInstruction=fr,exports.decodeApproveInstructionData=function(t){const e=ue.decode(t.subarray(ht.length));return Object.assign(Object.assign({},e),{proof:de(e.proof)?null:e.proof})},exports.decodeBatchCompressInstructionData=function(t){return $t.decode(t.subarray(dt.length+4))},exports.decodeCompressSplTokenAccountInstructionData=function(t){const e=Yt.decode(t.subarray(mt.length));return{owner:e.owner,remainingAmount:e.remainingAmount,cpiContext:e.cpiContext}},exports.decodeMintToInstructionData=function(t){return jt.decode(t.subarray(lt.length))},exports.decodeRevokeInstructionData=function(t){const e=ce.decode(t.subarray(ft.length));return Object.assign(Object.assign({},e),{proof:de(e.proof)?null:e.proof})},exports.decodeTokenMetadata=ni,exports.decodeTransferInstructionData=function(t){return zt.decode(t.slice(pt.length+4))},exports.decompress=async function(n,r,o,i,s,a,u,c){i=e.bn(i);const l=await n.getCompressedTokenAccountsByOwner(s.publicKey,{mint:o}),{accounts:d}=Bt(l.items,i),[p]=Dt(d,i),m=await n.getValidityProofV0(p.map((t=>({hash:t.compressedAccount.hash,tree:t.compressedAccount.treeInfo.tree,queue:t.compressedAccount.treeInfo.queue})))),h=xt(u=null!=u?u:await kt(n,o),i),f=await Ae.decompress({payer:r.publicKey,inputCompressedTokenAccounts:p,toAddress:a,amount:i,tokenPoolInfos:h,recentInputStateRootIndices:m.rootIndices,recentValidityProof:m.compressedProof}),{blockhash:g}=await n.getLatestBlockhash(),y=e.dedupeSigner(r,[s]),b=e.buildAndSignTx([t.ComputeBudgetProgram.setComputeUnitLimit({units:35e4}),f],r,g,y);return await e.sendAndConfirmTx(n,b,c)},exports.decompressDelegated=async function(n,r,o,i,s,a,u,c){i=e.bn(i);const l=await n.getCompressedTokenAccountsByDelegate(s.publicKey,{mint:o}),{accounts:d}=Bt(l.items,i),[p]=Dt(d,i),m=await n.getValidityProofV0(p.map((t=>({hash:t.compressedAccount.hash,tree:t.compressedAccount.treeInfo.tree,queue:t.compressedAccount.treeInfo.queue})))),h=null!=u?u:xt(await kt(n,o),i),f=await Ae.decompress({payer:r.publicKey,inputCompressedTokenAccounts:p,toAddress:a,amount:i,recentInputStateRootIndices:m.rootIndices,recentValidityProof:m.compressedProof,tokenPoolInfos:h}),{blockhash:g}=await n.getLatestBlockhash(),y=e.dedupeSigner(r,[s]),b=e.buildAndSignTx([t.ComputeBudgetProgram.setComputeUnitLimit({units:35e4}),f],r,g,y);return e.sendAndConfirmTx(n,b,c)},exports.deriveCMintAddress=Te,exports.deriveSplInterfaceInfo=At,exports.deriveTokenPoolInfo=function(t,e,n=0){return It(At(t,e,n))},exports.deserializeMint=ti,exports.encodeApproveInstructionData=pe,exports.encodeBatchCompressInstructionData=Qt,exports.encodeCompressSplTokenAccountInstructionData=Xt,exports.encodeMintToInstructionData=Zt,exports.encodeRevokeInstructionData=me,exports.encodeTokenMetadata=function(e){const n=w.alloc(2e3),r=e.updateAuthority||new t.PublicKey(0),o=zo.encode({updateAuthority:r,mint:e.mint,name:w.from(e.name),symbol:w.from(e.symbol),uri:w.from(e.uri),additionalMetadata:e.additionalMetadata?e.additionalMetadata.map((t=>({key:w.from(t.key),value:w.from(t.value)}))):[]},n);return n.subarray(0,o)},exports.encodeTransferInstructionData=Jt,exports.estimateTransactionSize=Fr,exports.extractTokenMetadata=oi,exports.findMintAddress=Pe,exports.freezeAccountsLayout=se,exports.getAccountInterface=Nn,exports.getAssociatedLightTokenAddress=function(n,r){return t.PublicKey.findProgramAddressSync([n.toBuffer(),e.LIGHT_TOKEN_PROGRAM_ID.toBuffer(),r.toBuffer()],e.LIGHT_TOKEN_PROGRAM_ID)[0]},exports.getAssociatedLightTokenAddressAndBump=function(n,r){return t.PublicKey.findProgramAddressSync([n.toBuffer(),e.LIGHT_TOKEN_PROGRAM_ID.toBuffer(),r.toBuffer()],e.LIGHT_TOKEN_PROGRAM_ID)},exports.getAssociatedTokenAddressInterface=zn,exports.getAtaInterface=Wn,exports.getAtaProgramId=mn,exports.getMintInterface=ii,exports.getOrCreateAtaInterface=async function(t,n,r,o,i=0,s,a,u=e.LIGHT_TOKEN_PROGRAM_ID,c=mn(u)){return e.assertBetaEnabled(),li(t,n,r,o,i,s,a,u,c,0)},exports.getSplInterfaceInfos=kt,exports.getTokenPoolInfos=async function(t,e,n){return(await kt(t,e,n)).map(It)},exports.groupAccountsByTreeType=Rt,exports.isSingleSplInterfaceInfo=yi,exports.isSingleTokenPoolInfo=bi,exports.loadAta=ai,exports.mergeTokenAccounts=async function(n,r,o,i,s){const a=await n.getCompressedTokenAccountsByOwner(i.publicKey,{mint:o});if(0===a.items.length)throw new Error(`No compressed token accounts found for mint ${o.toBase58()}`);if(1===a.items.length)throw new Error("Only one token account exists, nothing to merge");const{accounts:u,treeType:c}=Bt(a.items);let l=u,d=c;if(l.length<2){const t=c===e.TreeType.StateV2?e.TreeType.StateV1:e.TreeType.StateV2,n=a.items.filter((e=>e.compressedAccount.treeInfo.treeType===t));if(!(n.length>=2))throw 1===l.length&&1===n.length?new Error("Cannot merge accounts from different tree types (V1/V2). You have 1 V1 and 1 V2 account - nothing to merge within same type."):new Error(`Not enough accounts of the same tree type to merge. Found: ${l.length} ${d===e.TreeType.StateV1?"V1":"V2"} accounts.`);l=n,d=t}const p=l.slice(0,4),m=await n.getValidityProof(p.map((t=>e.bn(t.compressedAccount.hash)))),h=await Ae.mergeTokenAccounts({payer:r.publicKey,owner:i.publicKey,inputCompressedTokenAccounts:p,mint:o,recentValidityProof:m.compressedProof,recentInputStateRootIndices:m.rootIndices}),f=[t.ComputeBudgetProgram.setComputeUnitLimit({units:1e6}),...h],{blockhash:g}=await n.getLatestBlockhash(),y=e.dedupeSigner(r,[i]),b=e.buildAndSignTx(f,r,g,y);return e.sendAndConfirmTx(n,b,s)},exports.mintTo=async function(n,r,o,i,s,a,u,c){e.assertBetaEnabled();const l=s.publicKey.equals(r.publicKey)?void 0:r.publicKey,d=Kr({mint:o,destination:i,amount:a,authority:s.publicKey,maxTopUp:null!=u?u:yt,feePayer:l}),p=s.publicKey.equals(r.publicKey)?[]:[s],{blockhash:m}=await n.getLatestBlockhash(),h=e.buildAndSignTx([t.ComputeBudgetProgram.setComputeUnitLimit({units:2e5}),d],r,m,p);return await e.sendAndConfirmTx(n,h,c)},exports.mintTo$1=async function(n,r,o,i,s,a,u,c,l){u=null!=u?u:e.selectStateTreeInfo(await n.getStateTreeInfos()),c=null!=c?c:St(await kt(n,o));const d=await Ae.mintTo({feePayer:r.publicKey,mint:o,authority:s.publicKey,amount:a,toPubkey:i,outputStateTreeInfo:u,tokenPoolInfo:c}),{blockhash:p}=await n.getLatestBlockhash(),m=e.dedupeSigner(r,[s]),h=e.buildAndSignTx([t.ComputeBudgetProgram.setComputeUnitLimit({units:1e6}),d],r,p,m);return e.sendAndConfirmTx(n,h,l)},exports.mintToAccountsLayout=ne,exports.mintToCompressed=async function(n,r,o,i,s,a,u=3,c,l){e.assertBetaEnabled();const d=await ii(n,o,null==l?void 0:l.commitment,e.LIGHT_TOKEN_PROGRAM_ID);if(!d.merkleContext)throw new Error(Sn);if(!d.mintContext)throw new Error("Mint does not have MintContext");const p=d.merkleContext;if(!a){const t=await n.getStateTreeInfos();a=e.selectStateTreeInfo(t)}const m=await n.getValidityProofV2([{hash:e.bn(p.hash),leafIndex:p.leafIndex,treeInfo:p.treeInfo,proveByIndex:p.proveByIndex}],[],e.DerivationMode.compressible),h=Ur(i.publicKey,r.publicKey,m,p,{supply:d.mint.supply,decimals:d.mint.decimals,mintAuthority:d.mint.mintAuthority,freezeAuthority:d.mint.freezeAuthority,splMint:d.mintContext.splMint,cmintDecompressed:d.mintContext.cmintDecompressed,version:d.mintContext.version,mintSigner:d.mintContext.mintSigner,bump:d.mintContext.bump,metadata:d.tokenMetadata?{updateAuthority:d.tokenMetadata.updateAuthority||null,name:d.tokenMetadata.name,symbol:d.tokenMetadata.symbol,uri:d.tokenMetadata.uri}:void 0},s,a,u,c),f=i.publicKey.equals(r.publicKey)?[]:[i],{blockhash:g}=await n.getLatestBlockhash(),y=e.buildAndSignTx([t.ComputeBudgetProgram.setComputeUnitLimit({units:5e5}),h],r,g,f);return await e.sendAndConfirmTx(n,y,l)},exports.mintToInterface=async function(n,r,o,i,s,a,u=[],c,l){e.assertBetaEnabled();const d=await ii(n,o,null==c?void 0:c.commitment,l),p=s instanceof t.PublicKey?s:s.publicKey,m=u.map((t=>t.publicKey)),h=Nr(d,i,p,r.publicKey,a,0,m),f=[];s instanceof t.PublicKey||s.publicKey.equals(r.publicKey)||f.push(s),f.push(...u);const{blockhash:g}=await n.getLatestBlockhash(),y=e.buildAndSignTx([t.ComputeBudgetProgram.setComputeUnitLimit({units:2e5}),h],r,g,f);return await e.sendAndConfirmTx(n,y,c)},exports.mintToLayout=jt,exports.packCompressedTokenAccounts=Nt,exports.parseLightTokenCold=Un,exports.parseLightTokenHot=Kn,exports.parseMaybeDelegatedTransfer=we,exports.parseTokenData=be,exports.removeMetadataKey=async function(n,r,o,i,s,a=0,u=0,c){var l,d;e.assertBetaEnabled();const p=await ii(n,o,null==c?void 0:c.commitment,e.LIGHT_TOKEN_PROGRAM_ID);si(p);const m=p.merkleContext,h=null!==(d=null===(l=p.mintContext)||void 0===l?void 0:l.cmintDecompressed)&&void 0!==d&&d?null:await n.getValidityProofV2([{hash:e.bn(m.hash),leafIndex:m.leafIndex,treeInfo:m.treeInfo,proveByIndex:m.proveByIndex}],[],e.DerivationMode.compressible),f=en(p,i.publicKey,r.publicKey,h,s,a,u),g=i.publicKey.equals(r.publicKey)?[]:[i],{blockhash:y}=await n.getLatestBlockhash(),b=e.buildAndSignTx([t.ComputeBudgetProgram.setComputeUnitLimit({units:5e5}),f],r,y,g);return await e.sendAndConfirmTx(n,b,c)},exports.rentPerEpoch=bt,exports.revoke=async function(n,r,o,i,s){if(Rt(o).size>1)throw new Error("Cannot revoke accounts from different tree types (V1/V2) in the same transaction. Revoke V1 and V2 accounts separately.");const a=await n.getValidityProofV0(o.map((t=>({hash:t.compressedAccount.hash,tree:t.compressedAccount.treeInfo.tree,queue:t.compressedAccount.treeInfo.queue}))));!function(t,e){if(!t.publicKey.equals(e[0].parsed.owner))throw new Error(`Owner ${t.publicKey.toBase58()} does not match account ${e[0].parsed.owner.toBase58()}`)}(i,o),function(t){if(t.some((t=>null===t.parsed.delegate)))throw new Error("Account is not delegated")}(o);const u=await Ae.revoke({payer:r.publicKey,inputCompressedTokenAccounts:o,recentInputStateRootIndices:a.rootIndices,recentValidityProof:a.compressedProof}),{blockhash:c}=await n.getLatestBlockhash(),l=e.dedupeSigner(r,[i]),d=e.buildAndSignTx([t.ComputeBudgetProgram.setComputeUnitLimit({units:5e5}),u],r,c,l);return e.sendAndConfirmTx(n,d,s)},exports.revokeAccountsLayout=ie,exports.selectAccountsByPreferredTreeType=Bt,exports.selectInputsForAmount=Tr,exports.selectMinCompressedTokenAccountsForDecompression=function(t,e,n=4,r){const[o,i,s,a]=Dt(t,e,n,r);return{selectedAccounts:o,total:i,totalLamports:s,maxPossibleAmount:a}},exports.selectMinCompressedTokenAccountsForTransfer=Dt,exports.selectMinCompressedTokenAccountsForTransferOrPartial=Kt,exports.selectSmartCompressedTokenAccountsForTransfer=function(t,n,r=4,o){const i=_t(t,null==o?void 0:o.treeType),[s,a,u,c]=Ut(i,n,r);if(Ot(s),a.lt(e.bn(n))){const t=i.reduce(((t,e)=>t.add(e.parsed.amount)),e.bn(0));throw s.length>=r?new Error(`Account limit exceeded: max ${c.toString()} (${r} accounts) per transaction. Total balance: ${t.toString()} (${i.length} accounts). Consider multiple transfers to spend full balance.`):new Error(`Insufficient balance. Required: ${n.toString()}, available: ${t.toString()}.`)}if(0===s.length)throw new Error(Ct);return[s,a,u,c]},exports.selectSmartCompressedTokenAccountsForTransferOrPartial=Ut,exports.selectSplInterfaceInfo=St,exports.selectSplInterfaceInfosForDecompression=xt,exports.selectTokenAccountsForApprove=Lt,exports.selectTokenPoolInfo=function(t){return It(St(t.map(vt)))},exports.selectTokenPoolInfosForDecompression=function(t,e){return xt(t.map(vt),e).map(It)},exports.serializeMint=function(e){var r,o;const i=[],s=w.alloc(n.MINT_SIZE);n.MintLayout.encode({mintAuthorityOption:e.base.mintAuthority?1:0,mintAuthority:e.base.mintAuthority||new t.PublicKey(0),supply:e.base.supply,decimals:e.base.decimals,isInitialized:e.base.isInitialized,freezeAuthorityOption:e.base.freezeAuthority?1:0,freezeAuthority:e.base.freezeAuthority||new t.PublicKey(0)},s),i.push(s);const a=w.alloc($o);jo.encode({version:e.mintContext.version,cmintDecompressed:e.mintContext.cmintDecompressed?1:0,splMint:e.mintContext.splMint},a),i.push(a),i.push(w.from(e.mintContext.mintSigner)),i.push(w.from([e.mintContext.bump]));const u=null!==(r=e.reserved)&&void 0!==r?r:new Uint8Array(Qo);i.push(w.from(u));const c=null!==(o=e.accountType)&&void 0!==o?o:1;if(i.push(w.from([c])),e.compression?i.push(function(t){const e=w.alloc(96);let n=0;return e.writeUInt16LE(t.configAccountVersion,n),n+=2,e.writeUInt8(t.compressToPubkey,n),n+=1,e.writeUInt8(t.accountVersion,n),n+=1,e.writeUInt32LE(t.lamportsPerWrite,n),n+=4,t.compressionAuthority.toBuffer().copy(e,n),n+=32,t.rentSponsor.toBuffer().copy(e,n),n+=32,e.writeBigUInt64LE(t.lastClaimedSlot,n),n+=8,e.writeUInt32LE(t.rentExemptionPaid,n),n+=4,e.writeUInt32LE(t.reserved,n),n+=4,e.writeUInt16LE(t.rentConfig.baseRent,n),n+=2,e.writeUInt16LE(t.rentConfig.compressionCost,n),n+=2,e.writeUInt8(t.rentConfig.lamportsPerBytePerEpoch,n),n+=1,e.writeUInt8(t.rentConfig.maxFundedEpochs,n),n+=1,e.writeUInt16LE(t.rentConfig.maxTopUp,n),n+=2,e}(e.compression)):i.push(w.alloc(96)),e.extensions&&e.extensions.length>0){i.push(w.from([1]));const t=w.alloc(4);t.writeUInt32LE(e.extensions.length),i.push(t);for(const t of e.extensions)i.push(w.from([t.extensionType])),i.push(w.from(t.data))}else i.push(w.from([0]));return w.concat(i)},exports.sliceLast=pi,exports.sumUpTokenAmount=ge,exports.thawAccountsLayout=ae,exports.toAccountInfo=Dn,exports.toOffChainMetadataJson=function(t){const e={name:t.name,symbol:t.symbol};return void 0!==t.description&&(e.description=t.description),void 0!==t.image&&(e.image=t.image),void 0!==t.additionalMetadata&&t.additionalMetadata.length>0&&(e.additionalMetadata=t.additionalMetadata),e},exports.toTokenPoolInfo=It,exports.transfer=async function(n,r,o,i,s,a,u){i=e.bn(i);const c=await n.getCompressedTokenAccountsByOwner(s.publicKey,{mint:o}),{accounts:l}=Bt(c.items,i),[d]=Dt(l,i),p=await n.getValidityProofV0(d.map((t=>({hash:t.compressedAccount.hash,tree:t.compressedAccount.treeInfo.tree,queue:t.compressedAccount.treeInfo.queue})))),m=await Ae.transfer({payer:r.publicKey,inputCompressedTokenAccounts:d,toAddress:a,amount:i,recentInputStateRootIndices:p.rootIndices,recentValidityProof:p.compressedProof}),{blockhash:h}=await n.getLatestBlockhash(),f=e.dedupeSigner(r,[s]),g=e.buildAndSignTx([t.ComputeBudgetProgram.setComputeUnitLimit({units:5e5}),m],r,h,f);return e.sendAndConfirmTx(n,g,u)},exports.transferAccountsLayout=re,exports.transferDelegated=async function(n,r,o,i,s,a,u){i=e.bn(i);const c=await n.getCompressedTokenAccountsByDelegate(s.publicKey,{mint:o}),{accounts:l}=Bt(c.items,i),[d]=Dt(l,i),p=await n.getValidityProofV0(d.map((t=>({hash:t.compressedAccount.hash,tree:t.compressedAccount.treeInfo.tree,queue:t.compressedAccount.treeInfo.queue})))),m=await Ae.transfer({payer:r.publicKey,inputCompressedTokenAccounts:d,toAddress:a,amount:i,recentInputStateRootIndices:p.rootIndices,recentValidityProof:p.compressedProof}),{blockhash:h}=await n.getLatestBlockhash(),f=e.dedupeSigner(r,[s]),g=e.buildAndSignTx([t.ComputeBudgetProgram.setComputeUnitLimit({units:5e5}),m],r,h,f);return e.sendAndConfirmTx(n,g,u)},exports.transferInterface=async function(t,n,r,o,i,s,a,u=e.LIGHT_TOKEN_PROGRAM_ID,c,l,d=0,p){var m;e.assertBetaEnabled();const h=zn(o,null!==(m=null==l?void 0:l.owner)&&void 0!==m?m:s.publicKey,0,u);if(!r.equals(h))throw new Error(`Source mismatch. Expected ${h.toBase58()}, got ${r.toBase58()}`);const f=BigInt(a.toString()),g=null!=p?p:(await ii(t,o)).mint.decimals,y=await Xr(t,n.publicKey,o,f,s.publicKey,i,g,Object.assign(Object.assign({},l),{wrap:d,programId:u})),b=e.dedupeSigner(n,[s]),{rest:w,last:I}=pi(y);await Promise.all(w.map((async r=>{const{blockhash:o}=await t.getLatestBlockhash(),i=e.buildAndSignTx(r,n,o,b);return e.sendAndConfirmTx(t,i,c)})));const{blockhash:v}=await t.getLatestBlockhash(),A=e.buildAndSignTx(I,n,v,b);return e.sendAndConfirmTx(t,A,c)},exports.unpackMintData=function(t){const e=ti(t instanceof w?t:w.from(t)),n=oi(e.extensions);return{mintContext:e.mintContext,tokenMetadata:n||void 0,extensions:e.extensions||void 0}},exports.unpackMintInterface=function(t,r,o=n.TOKEN_PROGRAM_ID){const i=r instanceof w?r:r instanceof Uint8Array?w.from(r):r.data;if(o.equals(e.LIGHT_TOKEN_PROGRAM_ID)){const e=ti(i),n={address:t,mintAuthority:e.base.mintAuthority,supply:e.base.supply,decimals:e.base.decimals,isInitialized:e.base.isInitialized,freezeAuthority:e.base.freezeAuthority,tlvData:w.alloc(0)},r=oi(e.extensions),s={mint:n,programId:o,mintContext:e.mintContext,tokenMetadata:r||void 0,extensions:e.extensions||void 0,compression:e.compression};if(!s.mintContext)throw new Error("Invalid light mint: mintContext is required for LIGHT_TOKEN_PROGRAM_ID");return s}const s=r;return{mint:n.unpackMint(t,s,o),programId:o}},exports.updateFreezeAuthority=async function(n,r,o,i,s,a){var u,c;e.assertBetaEnabled();const l=await ii(n,o,null==a?void 0:a.commitment,e.LIGHT_TOKEN_PROGRAM_ID);if(!l.merkleContext)throw new Error(Sn);const d=l.merkleContext,p=null!==(c=null===(u=l.mintContext)||void 0===u?void 0:u.cmintDecompressed)&&void 0!==c&&c?null:await n.getValidityProofV2([{hash:e.bn(d.hash),leafIndex:d.leafIndex,treeInfo:d.treeInfo,proveByIndex:d.proveByIndex}],[],e.DerivationMode.compressible),m=Qe(l,i.publicKey,s,r.publicKey,p),h=i.publicKey.equals(r.publicKey)?[]:[i],{blockhash:f}=await n.getLatestBlockhash(),g=e.buildAndSignTx([t.ComputeBudgetProgram.setComputeUnitLimit({units:5e5}),m],r,f,h);return await e.sendAndConfirmTx(n,g,a)},exports.updateMetadataAuthority=async function(n,r,o,i,s,a=0,u){var c,l;e.assertBetaEnabled();const d=await ii(n,o,null==u?void 0:u.commitment,e.LIGHT_TOKEN_PROGRAM_ID);si(d);const p=d.merkleContext,m=null!==(l=null===(c=d.mintContext)||void 0===c?void 0:c.cmintDecompressed)&&void 0!==l&&l?null:await n.getValidityProofV2([{hash:e.bn(p.hash),leafIndex:p.leafIndex,treeInfo:p.treeInfo,proveByIndex:p.proveByIndex}],[],e.DerivationMode.compressible),h=tn(d,i.publicKey,s,r.publicKey,m,a),f=i.publicKey.equals(r.publicKey)?[]:[i],{blockhash:g}=await n.getLatestBlockhash(),y=e.buildAndSignTx([t.ComputeBudgetProgram.setComputeUnitLimit({units:5e5}),h],r,g,f);return await e.sendAndConfirmTx(n,y,u)},exports.updateMetadataField=async function(n,r,o,i,s,a,u,c=0,l){var d,p;e.assertBetaEnabled();const m=await ii(n,o,null==l?void 0:l.commitment,e.LIGHT_TOKEN_PROGRAM_ID);si(m);const h=m.merkleContext,f=null!==(p=null===(d=m.mintContext)||void 0===d?void 0:d.cmintDecompressed)&&void 0!==p&&p?null:await n.getValidityProofV2([{hash:e.bn(h.hash),leafIndex:h.leafIndex,treeInfo:h.treeInfo,proveByIndex:h.proveByIndex}],[],e.DerivationMode.compressible),g=Je(m,i.publicKey,r.publicKey,f,s,a,u,c),y=i.publicKey.equals(r.publicKey)?[]:[i],{blockhash:b}=await n.getLatestBlockhash(),w=e.buildAndSignTx([t.ComputeBudgetProgram.setComputeUnitLimit({units:5e5}),g],r,b,y);return await e.sendAndConfirmTx(n,w,l)},exports.updateMintAuthority=async function(n,r,o,i,s,a){var u,c;e.assertBetaEnabled();const l=await ii(n,o,null==a?void 0:a.commitment,e.LIGHT_TOKEN_PROGRAM_ID);if(!l.merkleContext)throw new Error(Sn);const d=l.merkleContext,p=null!==(c=null===(u=l.mintContext)||void 0===u?void 0:u.cmintDecompressed)&&void 0!==c&&c?null:await n.getValidityProofV2([{hash:e.bn(d.hash),leafIndex:d.leafIndex,treeInfo:d.treeInfo,proveByIndex:d.proveByIndex}],[],e.DerivationMode.compressible),m=Ze(l,i.publicKey,s,r.publicKey,p),h=i.publicKey.equals(r.publicKey)?[]:[i],{blockhash:f}=await n.getLatestBlockhash(),g=e.buildAndSignTx([t.ComputeBudgetProgram.setComputeUnitLimit({units:5e5}),m],r,f,h);return await e.sendAndConfirmTx(n,g,a)},exports.validateSameTokenOwner=ye,exports.wrap=async function(r,o,i,s,a,u,c,l,d,p){e.assertBetaEnabled();let m=l;if(!m&&(m=(await kt(r,u)).find((t=>t.isInitialized)),!m))throw new Error(`No initialized SPL interface found for mint: ${u.toBase58()}. Please create an SPL interface via createSplInterface().`);const h=await n.getMint(r,u,void 0,m.tokenProgram),f=fr(i,s,a.publicKey,u,c,m,h.decimals,o.publicKey,d),{blockhash:g}=await r.getLatestBlockhash(),y=e.dedupeSigner(o,[a]),b=e.buildAndSignTx([t.ComputeBudgetProgram.setComputeUnitLimit({units:2e5}),f],o,g,y);return await e.sendAndConfirmTx(r,b,p)};
2
- //# sourceMappingURL=types-Csty9bc2.cjs.map
1
+ "use strict";var t=require("@solana/web3.js"),e=require("@lightprotocol/stateless.js"),n=require("@solana/spl-token"),r=require("@coral-xyz/borsh"),o="undefined"!=typeof global?global:"undefined"!=typeof self?self:"undefined"!=typeof window?window:{},i=[],s=[],a="undefined"!=typeof Uint8Array?Uint8Array:Array,u=0;function c(){u=1;for(var t="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/",e=0;e<64;++e)i[e]=t[e],s[t.charCodeAt(e)]=e;s["-".charCodeAt(0)]=62,s["_".charCodeAt(0)]=63}function l(t,e,n){for(var r,o,s=[],a=e;a<n;a+=3)r=(t[a]<<16)+(t[a+1]<<8)+t[a+2],s.push(i[(o=r)>>18&63]+i[o>>12&63]+i[o>>6&63]+i[63&o]);return s.join("")}function d(t){var e;u||c();for(var n=t.length,r=n%3,o="",s=[],a=16383,d=0,p=n-r;d<p;d+=a)s.push(l(t,d,d+a>p?p:d+a));return 1===r?(e=t[n-1],o+=i[e>>2],o+=i[e<<4&63],o+="=="):2===r&&(e=(t[n-2]<<8)+t[n-1],o+=i[e>>10],o+=i[e>>4&63],o+=i[e<<2&63],o+="="),s.push(o),s.join("")}function p(t,e,n,r,o){var i,s,a=8*o-r-1,u=(1<<a)-1,c=u>>1,l=-7,d=n?o-1:0,p=n?-1:1,m=t[e+d];for(d+=p,i=m&(1<<-l)-1,m>>=-l,l+=a;l>0;i=256*i+t[e+d],d+=p,l-=8);for(s=i&(1<<-l)-1,i>>=-l,l+=r;l>0;s=256*s+t[e+d],d+=p,l-=8);if(0===i)i=1-c;else{if(i===u)return s?NaN:Infinity*(m?-1:1);s+=Math.pow(2,r),i-=c}return(m?-1:1)*s*Math.pow(2,i-r)}function m(t,e,n,r,o,i){var s,a,u,c=8*i-o-1,l=(1<<c)-1,d=l>>1,p=23===o?Math.pow(2,-24)-Math.pow(2,-77):0,m=r?0:i-1,h=r?1:-1,f=e<0||0===e&&1/e<0?1:0;for(e=Math.abs(e),isNaN(e)||Infinity===e?(a=isNaN(e)?1:0,s=l):(s=Math.floor(Math.log(e)/Math.LN2),e*(u=Math.pow(2,-s))<1&&(s--,u*=2),(e+=s+d>=1?p/u:p*Math.pow(2,1-d))*u>=2&&(s++,u/=2),s+d>=l?(a=0,s=l):s+d>=1?(a=(e*u-1)*Math.pow(2,o),s+=d):(a=e*Math.pow(2,d-1)*Math.pow(2,o),s=0));o>=8;t[n+m]=255&a,m+=h,a/=256,o-=8);for(s=s<<o|a,c+=o;c>0;t[n+m]=255&s,m+=h,s/=256,c-=8);t[n+m-h]|=128*f}var h={}.toString,f=Array.isArray||function(t){return"[object Array]"==h.call(t)};w.TYPED_ARRAY_SUPPORT=void 0!==o.TYPED_ARRAY_SUPPORT?o.TYPED_ARRAY_SUPPORT:1;var g=y();function y(){return w.TYPED_ARRAY_SUPPORT?2147483647:1073741823}function b(t,e){if(y()<e)throw new RangeError("Invalid typed array length");return w.TYPED_ARRAY_SUPPORT?(t=new Uint8Array(e)).__proto__=w.prototype:(null===t&&(t=new w(e)),t.length=e),t}function w(t,e,n){if(!(w.TYPED_ARRAY_SUPPORT||this instanceof w))return new w(t,e,n);if("number"==typeof t){if("string"==typeof e)throw new Error("If encoding is specified then the first argument must be a string");return v(this,t)}return I(this,t,e,n)}function I(t,e,n,r){if("number"==typeof e)throw new TypeError('"value" argument must not be a number');return"undefined"!=typeof ArrayBuffer&&e instanceof ArrayBuffer?function(t,e,n,r){if(e.byteLength,n<0||e.byteLength<n)throw new RangeError("'offset' is out of bounds");if(e.byteLength<n+(r||0))throw new RangeError("'length' is out of bounds");return e=void 0===n&&void 0===r?new Uint8Array(e):void 0===r?new Uint8Array(e,n):new Uint8Array(e,n,r),w.TYPED_ARRAY_SUPPORT?(t=e).__proto__=w.prototype:t=T(t,e),t}(t,e,n,r):"string"==typeof e?function(t,e,n){if("string"==typeof n&&""!==n||(n="utf8"),!w.isEncoding(n))throw new TypeError('"encoding" must be a valid string encoding');var r=0|M(e,n),o=(t=b(t,r)).write(e,n);return o!==r&&(t=t.slice(0,o)),t}(t,e,n):function(t,e){if(P(e)){var n=0|k(e.length);return 0===(t=b(t,n)).length||e.copy(t,0,0,n),t}if(e){if("undefined"!=typeof ArrayBuffer&&e.buffer instanceof ArrayBuffer||"length"in e)return"number"!=typeof e.length||(r=e.length)!=r?b(t,0):T(t,e);if("Buffer"===e.type&&f(e.data))return T(t,e.data)}var r;throw new TypeError("First argument must be a string, Buffer, ArrayBuffer, Array, or array-like object.")}(t,e)}function A(t){if("number"!=typeof t)throw new TypeError('"size" argument must be a number');if(t<0)throw new RangeError('"size" argument must not be negative')}function v(t,e){if(A(e),t=b(t,e<0?0:0|k(e)),!w.TYPED_ARRAY_SUPPORT)for(var n=0;n<e;++n)t[n]=0;return t}function T(t,e){var n=e.length<0?0:0|k(e.length);t=b(t,n);for(var r=0;r<n;r+=1)t[r]=255&e[r];return t}function k(t){if(t>=y())throw new RangeError("Attempt to allocate Buffer larger than maximum size: 0x"+y().toString(16)+" bytes");return 0|t}function P(t){return!(null==t||!t._isBuffer)}function M(t,e){if(P(t))return t.length;if("undefined"!=typeof ArrayBuffer&&"function"==typeof ArrayBuffer.isView&&(ArrayBuffer.isView(t)||t instanceof ArrayBuffer))return t.byteLength;"string"!=typeof t&&(t=""+t);var n=t.length;if(0===n)return 0;for(var r=0;;)switch(e){case"ascii":case"latin1":case"binary":return n;case"utf8":case"utf-8":case void 0:return X(t).length;case"ucs2":case"ucs-2":case"utf16le":case"utf-16le":return 2*n;case"hex":return n>>>1;case"base64":return J(t).length;default:if(r)return X(t).length;e=(""+e).toLowerCase(),r=1}}function S(t,e,n){var r=0;if((void 0===e||e<0)&&(e=0),e>this.length)return"";if((void 0===n||n>this.length)&&(n=this.length),n<=0)return"";if((n>>>=0)<=(e>>>=0))return"";for(t||(t="utf8");;)switch(t){case"hex":return q(this,e,n);case"utf8":case"utf-8":return U(this,e,n);case"ascii":return W(this,e,n);case"latin1":case"binary":return G(this,e,n);case"base64":return K(this,e,n);case"ucs2":case"ucs-2":case"utf16le":case"utf-16le":return F(this,e,n);default:if(r)throw new TypeError("Unknown encoding: "+t);t=(t+"").toLowerCase(),r=1}}function x(t,e,n){var r=t[e];t[e]=t[n],t[n]=r}function C(t,e,n,r,o){if(0===t.length)return-1;if("string"==typeof n?(r=n,n=0):n>2147483647?n=2147483647:n<-2147483648&&(n=-2147483648),n=+n,isNaN(n)&&(n=o?0:t.length-1),n<0&&(n=t.length+n),n>=t.length){if(o)return-1;n=t.length-1}else if(n<0){if(!o)return-1;n=0}if("string"==typeof e&&(e=w.from(e,r)),P(e))return 0===e.length?-1:_(t,e,n,r,o);if("number"==typeof e)return e&=255,w.TYPED_ARRAY_SUPPORT&&"function"==typeof Uint8Array.prototype.indexOf?o?Uint8Array.prototype.indexOf.call(t,e,n):Uint8Array.prototype.lastIndexOf.call(t,e,n):_(t,[e],n,r,o);throw new TypeError("val must be string, number or Buffer")}function _(t,e,n,r,o){var i,s=1,a=t.length,u=e.length;if(void 0!==r&&("ucs2"===(r=String(r).toLowerCase())||"ucs-2"===r||"utf16le"===r||"utf-16le"===r)){if(t.length<2||e.length<2)return-1;s=2,a/=2,u/=2,n/=2}function c(t,e){return 1===s?t[e]:t.readUInt16BE(e*s)}if(o){var l=-1;for(i=n;i<a;i++)if(c(t,i)===c(e,-1===l?0:i-l)){if(-1===l&&(l=i),i-l+1===u)return l*s}else-1!==l&&(i-=i-l),l=-1}else for(n+u>a&&(n=a-u),i=n;i>=0;i--){for(var d=1,p=0;p<u;p++)if(c(t,i+p)!==c(e,p)){d=0;break}if(d)return i}return-1}function E(t,e,n,r){n=Number(n)||0;var o=t.length-n;r?(r=Number(r))>o&&(r=o):r=o;var i=e.length;if(i%2!=0)throw new TypeError("Invalid hex string");r>i/2&&(r=i/2);for(var s=0;s<r;++s){var a=parseInt(e.substr(2*s,2),16);if(isNaN(a))return s;t[n+s]=a}return s}function O(t,e,n,r){return tt(X(e,t.length-n),t,n,r)}function R(t,e,n,r){return tt(function(t){for(var e=[],n=0;n<t.length;++n)e.push(255&t.charCodeAt(n));return e}(e),t,n,r)}function B(t,e,n,r){return R(t,e,n,r)}function L(t,e,n,r){return tt(J(e),t,n,r)}function D(t,e,n,r){return tt(function(t,e){for(var n,r,o,i=[],s=0;s<t.length&&!((e-=2)<0);++s)r=(n=t.charCodeAt(s))>>8,o=n%256,i.push(o),i.push(r);return i}(e,t.length-n),t,n,r)}function K(t,e,n){return 0===e&&n===t.length?d(t):d(t.slice(e,n))}function U(t,e,n){n=Math.min(t.length,n);for(var r=[],o=e;o<n;){var i,s,a,u,c=t[o],l=null,d=c>239?4:c>223?3:c>191?2:1;if(o+d<=n)switch(d){case 1:c<128&&(l=c);break;case 2:128==(192&(i=t[o+1]))&&(u=(31&c)<<6|63&i)>127&&(l=u);break;case 3:i=t[o+1],s=t[o+2],128==(192&i)&&128==(192&s)&&(u=(15&c)<<12|(63&i)<<6|63&s)>2047&&(u<55296||u>57343)&&(l=u);break;case 4:i=t[o+1],s=t[o+2],a=t[o+3],128==(192&i)&&128==(192&s)&&128==(192&a)&&(u=(15&c)<<18|(63&i)<<12|(63&s)<<6|63&a)>65535&&u<1114112&&(l=u)}null===l?(l=65533,d=1):l>65535&&(l-=65536,r.push(l>>>10&1023|55296),l=56320|1023&l),r.push(l),o+=d}return function(t){var e=t.length;if(e<=N)return String.fromCharCode.apply(String,t);for(var n="",r=0;r<e;)n+=String.fromCharCode.apply(String,t.slice(r,r+=N));return n}(r)}w.poolSize=8192,w._augment=function(t){return t.__proto__=w.prototype,t},w.from=function(t,e,n){return I(null,t,e,n)},w.TYPED_ARRAY_SUPPORT&&(w.prototype.__proto__=Uint8Array.prototype,w.__proto__=Uint8Array,"undefined"!=typeof Symbol&&Symbol.species&&w[Symbol.species]),w.alloc=function(t,e,n){return function(t,e,n,r){return A(e),e<=0?b(t,e):void 0!==n?"string"==typeof r?b(t,e).fill(n,r):b(t,e).fill(n):b(t,e)}(null,t,e,n)},w.allocUnsafe=function(t){return v(null,t)},w.allocUnsafeSlow=function(t){return v(null,t)},w.isBuffer=et,w.compare=function(t,e){if(!P(t)||!P(e))throw new TypeError("Arguments must be Buffers");if(t===e)return 0;for(var n=t.length,r=e.length,o=0,i=Math.min(n,r);o<i;++o)if(t[o]!==e[o]){n=t[o],r=e[o];break}return n<r?-1:r<n?1:0},w.isEncoding=function(t){switch(String(t).toLowerCase()){case"hex":case"utf8":case"utf-8":case"ascii":case"latin1":case"binary":case"base64":case"ucs2":case"ucs-2":case"utf16le":case"utf-16le":return 1;default:return 0}},w.concat=function(t,e){if(!f(t))throw new TypeError('"list" argument must be an Array of Buffers');if(0===t.length)return w.alloc(0);var n;if(void 0===e)for(e=0,n=0;n<t.length;++n)e+=t[n].length;var r=w.allocUnsafe(e),o=0;for(n=0;n<t.length;++n){var i=t[n];if(!P(i))throw new TypeError('"list" argument must be an Array of Buffers');i.copy(r,o),o+=i.length}return r},w.byteLength=M,w.prototype._isBuffer=1,w.prototype.swap16=function(){var t=this.length;if(t%2!=0)throw new RangeError("Buffer size must be a multiple of 16-bits");for(var e=0;e<t;e+=2)x(this,e,e+1);return this},w.prototype.swap32=function(){var t=this.length;if(t%4!=0)throw new RangeError("Buffer size must be a multiple of 32-bits");for(var e=0;e<t;e+=4)x(this,e,e+3),x(this,e+1,e+2);return this},w.prototype.swap64=function(){var t=this.length;if(t%8!=0)throw new RangeError("Buffer size must be a multiple of 64-bits");for(var e=0;e<t;e+=8)x(this,e,e+7),x(this,e+1,e+6),x(this,e+2,e+5),x(this,e+3,e+4);return this},w.prototype.toString=function(){var t=0|this.length;return 0===t?"":0===arguments.length?U(this,0,t):S.apply(this,arguments)},w.prototype.equals=function(t){if(!P(t))throw new TypeError("Argument must be a Buffer");return this===t?1:0===w.compare(this,t)},w.prototype.inspect=function(){var t="";return this.length>0&&(t=this.toString("hex",0,50).match(/.{2}/g).join(" "),this.length>50&&(t+=" ... ")),"<Buffer "+t+">"},w.prototype.compare=function(t,e,n,r,o){if(!P(t))throw new TypeError("Argument must be a Buffer");if(void 0===e&&(e=0),void 0===n&&(n=t?t.length:0),void 0===r&&(r=0),void 0===o&&(o=this.length),e<0||n>t.length||r<0||o>this.length)throw new RangeError("out of range index");if(r>=o&&e>=n)return 0;if(r>=o)return-1;if(e>=n)return 1;if(this===t)return 0;for(var i=(o>>>=0)-(r>>>=0),s=(n>>>=0)-(e>>>=0),a=Math.min(i,s),u=this.slice(r,o),c=t.slice(e,n),l=0;l<a;++l)if(u[l]!==c[l]){i=u[l],s=c[l];break}return i<s?-1:s<i?1:0},w.prototype.includes=function(t,e,n){return-1!==this.indexOf(t,e,n)},w.prototype.indexOf=function(t,e,n){return C(this,t,e,n,1)},w.prototype.lastIndexOf=function(t,e,n){return C(this,t,e,n,0)},w.prototype.write=function(t,e,n,r){if(void 0===e)r="utf8",n=this.length,e=0;else if(void 0===n&&"string"==typeof e)r=e,n=this.length,e=0;else{if(!isFinite(e))throw new Error("Buffer.write(string, encoding, offset[, length]) is no longer supported");e|=0,isFinite(n)?(n|=0,void 0===r&&(r="utf8")):(r=n,n=void 0)}var o=this.length-e;if((void 0===n||n>o)&&(n=o),t.length>0&&(n<0||e<0)||e>this.length)throw new RangeError("Attempt to write outside buffer bounds");r||(r="utf8");for(var i=0;;)switch(r){case"hex":return E(this,t,e,n);case"utf8":case"utf-8":return O(this,t,e,n);case"ascii":return R(this,t,e,n);case"latin1":case"binary":return B(this,t,e,n);case"base64":return L(this,t,e,n);case"ucs2":case"ucs-2":case"utf16le":case"utf-16le":return D(this,t,e,n);default:if(i)throw new TypeError("Unknown encoding: "+r);r=(""+r).toLowerCase(),i=1}},w.prototype.toJSON=function(){return{type:"Buffer",data:Array.prototype.slice.call(this._arr||this,0)}};var N=4096;function W(t,e,n){var r="";n=Math.min(t.length,n);for(var o=e;o<n;++o)r+=String.fromCharCode(127&t[o]);return r}function G(t,e,n){var r="";n=Math.min(t.length,n);for(var o=e;o<n;++o)r+=String.fromCharCode(t[o]);return r}function q(t,e,n){var r,o=t.length;(!e||e<0)&&(e=0),(!n||n<0||n>o)&&(n=o);for(var i="",s=e;s<n;++s)i+=(r=t[s])<16?"0"+r.toString(16):r.toString(16);return i}function F(t,e,n){for(var r=t.slice(e,n),o="",i=0;i<r.length;i+=2)o+=String.fromCharCode(r[i]+256*r[i+1]);return o}function V(t,e,n){if(t%1!=0||t<0)throw new RangeError("offset is not uint");if(t+e>n)throw new RangeError("Trying to access beyond buffer length")}function H(t,e,n,r,o,i){if(!P(t))throw new TypeError('"buffer" argument must be a Buffer instance');if(e>o||e<i)throw new RangeError('"value" argument is out of bounds');if(n+r>t.length)throw new RangeError("Index out of range")}function z(t,e,n,r){e<0&&(e=65535+e+1);for(var o=0,i=Math.min(t.length-n,2);o<i;++o)t[n+o]=(e&255<<8*(r?o:1-o))>>>8*(r?o:1-o)}function j(t,e,n,r){e<0&&(e=4294967295+e+1);for(var o=0,i=Math.min(t.length-n,4);o<i;++o)t[n+o]=e>>>8*(r?o:3-o)&255}function $(t,e,n,r){if(n+r>t.length)throw new RangeError("Index out of range");if(n<0)throw new RangeError("Index out of range")}function Y(t,e,n,r,o){return o||$(t,0,n,4),m(t,e,n,r,23,4),n+4}function Z(t,e,n,r,o){return o||$(t,0,n,8),m(t,e,n,r,52,8),n+8}w.prototype.slice=function(t,e){var n,r=this.length;if((t=~~t)<0?(t+=r)<0&&(t=0):t>r&&(t=r),(e=void 0===e?r:~~e)<0?(e+=r)<0&&(e=0):e>r&&(e=r),e<t&&(e=t),w.TYPED_ARRAY_SUPPORT)(n=this.subarray(t,e)).__proto__=w.prototype;else{var o=e-t;n=new w(o,void 0);for(var i=0;i<o;++i)n[i]=this[i+t]}return n},w.prototype.readUIntLE=function(t,e,n){t|=0,e|=0,n||V(t,e,this.length);for(var r=this[t],o=1,i=0;++i<e&&(o*=256);)r+=this[t+i]*o;return r},w.prototype.readUIntBE=function(t,e,n){t|=0,e|=0,n||V(t,e,this.length);for(var r=this[t+--e],o=1;e>0&&(o*=256);)r+=this[t+--e]*o;return r},w.prototype.readUInt8=function(t,e){return e||V(t,1,this.length),this[t]},w.prototype.readUInt16LE=function(t,e){return e||V(t,2,this.length),this[t]|this[t+1]<<8},w.prototype.readUInt16BE=function(t,e){return e||V(t,2,this.length),this[t]<<8|this[t+1]},w.prototype.readUInt32LE=function(t,e){return e||V(t,4,this.length),(this[t]|this[t+1]<<8|this[t+2]<<16)+16777216*this[t+3]},w.prototype.readUInt32BE=function(t,e){return e||V(t,4,this.length),16777216*this[t]+(this[t+1]<<16|this[t+2]<<8|this[t+3])},w.prototype.readIntLE=function(t,e,n){t|=0,e|=0,n||V(t,e,this.length);for(var r=this[t],o=1,i=0;++i<e&&(o*=256);)r+=this[t+i]*o;return r>=(o*=128)&&(r-=Math.pow(2,8*e)),r},w.prototype.readIntBE=function(t,e,n){t|=0,e|=0,n||V(t,e,this.length);for(var r=e,o=1,i=this[t+--r];r>0&&(o*=256);)i+=this[t+--r]*o;return i>=(o*=128)&&(i-=Math.pow(2,8*e)),i},w.prototype.readInt8=function(t,e){return e||V(t,1,this.length),128&this[t]?-1*(255-this[t]+1):this[t]},w.prototype.readInt16LE=function(t,e){e||V(t,2,this.length);var n=this[t]|this[t+1]<<8;return 32768&n?4294901760|n:n},w.prototype.readInt16BE=function(t,e){e||V(t,2,this.length);var n=this[t+1]|this[t]<<8;return 32768&n?4294901760|n:n},w.prototype.readInt32LE=function(t,e){return e||V(t,4,this.length),this[t]|this[t+1]<<8|this[t+2]<<16|this[t+3]<<24},w.prototype.readInt32BE=function(t,e){return e||V(t,4,this.length),this[t]<<24|this[t+1]<<16|this[t+2]<<8|this[t+3]},w.prototype.readFloatLE=function(t,e){return e||V(t,4,this.length),p(this,t,1,23,4)},w.prototype.readFloatBE=function(t,e){return e||V(t,4,this.length),p(this,t,0,23,4)},w.prototype.readDoubleLE=function(t,e){return e||V(t,8,this.length),p(this,t,1,52,8)},w.prototype.readDoubleBE=function(t,e){return e||V(t,8,this.length),p(this,t,0,52,8)},w.prototype.writeUIntLE=function(t,e,n,r){t=+t,e|=0,n|=0,r||H(this,t,e,n,Math.pow(2,8*n)-1,0);var o=1,i=0;for(this[e]=255&t;++i<n&&(o*=256);)this[e+i]=t/o&255;return e+n},w.prototype.writeUIntBE=function(t,e,n,r){t=+t,e|=0,n|=0,r||H(this,t,e,n,Math.pow(2,8*n)-1,0);var o=n-1,i=1;for(this[e+o]=255&t;--o>=0&&(i*=256);)this[e+o]=t/i&255;return e+n},w.prototype.writeUInt8=function(t,e,n){return t=+t,e|=0,n||H(this,t,e,1,255,0),w.TYPED_ARRAY_SUPPORT||(t=Math.floor(t)),this[e]=255&t,e+1},w.prototype.writeUInt16LE=function(t,e,n){return t=+t,e|=0,n||H(this,t,e,2,65535,0),w.TYPED_ARRAY_SUPPORT?(this[e]=255&t,this[e+1]=t>>>8):z(this,t,e,1),e+2},w.prototype.writeUInt16BE=function(t,e,n){return t=+t,e|=0,n||H(this,t,e,2,65535,0),w.TYPED_ARRAY_SUPPORT?(this[e]=t>>>8,this[e+1]=255&t):z(this,t,e,0),e+2},w.prototype.writeUInt32LE=function(t,e,n){return t=+t,e|=0,n||H(this,t,e,4,4294967295,0),w.TYPED_ARRAY_SUPPORT?(this[e+3]=t>>>24,this[e+2]=t>>>16,this[e+1]=t>>>8,this[e]=255&t):j(this,t,e,1),e+4},w.prototype.writeUInt32BE=function(t,e,n){return t=+t,e|=0,n||H(this,t,e,4,4294967295,0),w.TYPED_ARRAY_SUPPORT?(this[e]=t>>>24,this[e+1]=t>>>16,this[e+2]=t>>>8,this[e+3]=255&t):j(this,t,e,0),e+4},w.prototype.writeIntLE=function(t,e,n,r){if(t=+t,e|=0,!r){var o=Math.pow(2,8*n-1);H(this,t,e,n,o-1,-o)}var i=0,s=1,a=0;for(this[e]=255&t;++i<n&&(s*=256);)t<0&&0===a&&0!==this[e+i-1]&&(a=1),this[e+i]=(t/s>>0)-a&255;return e+n},w.prototype.writeIntBE=function(t,e,n,r){if(t=+t,e|=0,!r){var o=Math.pow(2,8*n-1);H(this,t,e,n,o-1,-o)}var i=n-1,s=1,a=0;for(this[e+i]=255&t;--i>=0&&(s*=256);)t<0&&0===a&&0!==this[e+i+1]&&(a=1),this[e+i]=(t/s>>0)-a&255;return e+n},w.prototype.writeInt8=function(t,e,n){return t=+t,e|=0,n||H(this,t,e,1,127,-128),w.TYPED_ARRAY_SUPPORT||(t=Math.floor(t)),t<0&&(t=255+t+1),this[e]=255&t,e+1},w.prototype.writeInt16LE=function(t,e,n){return t=+t,e|=0,n||H(this,t,e,2,32767,-32768),w.TYPED_ARRAY_SUPPORT?(this[e]=255&t,this[e+1]=t>>>8):z(this,t,e,1),e+2},w.prototype.writeInt16BE=function(t,e,n){return t=+t,e|=0,n||H(this,t,e,2,32767,-32768),w.TYPED_ARRAY_SUPPORT?(this[e]=t>>>8,this[e+1]=255&t):z(this,t,e,0),e+2},w.prototype.writeInt32LE=function(t,e,n){return t=+t,e|=0,n||H(this,t,e,4,2147483647,-2147483648),w.TYPED_ARRAY_SUPPORT?(this[e]=255&t,this[e+1]=t>>>8,this[e+2]=t>>>16,this[e+3]=t>>>24):j(this,t,e,1),e+4},w.prototype.writeInt32BE=function(t,e,n){return t=+t,e|=0,n||H(this,t,e,4,2147483647,-2147483648),t<0&&(t=4294967295+t+1),w.TYPED_ARRAY_SUPPORT?(this[e]=t>>>24,this[e+1]=t>>>16,this[e+2]=t>>>8,this[e+3]=255&t):j(this,t,e,0),e+4},w.prototype.writeFloatLE=function(t,e,n){return Y(this,t,e,1,n)},w.prototype.writeFloatBE=function(t,e,n){return Y(this,t,e,0,n)},w.prototype.writeDoubleLE=function(t,e,n){return Z(this,t,e,1,n)},w.prototype.writeDoubleBE=function(t,e,n){return Z(this,t,e,0,n)},w.prototype.copy=function(t,e,n,r){if(n||(n=0),r||0===r||(r=this.length),e>=t.length&&(e=t.length),e||(e=0),r>0&&r<n&&(r=n),r===n)return 0;if(0===t.length||0===this.length)return 0;if(e<0)throw new RangeError("targetStart out of bounds");if(n<0||n>=this.length)throw new RangeError("sourceStart out of bounds");if(r<0)throw new RangeError("sourceEnd out of bounds");r>this.length&&(r=this.length),t.length-e<r-n&&(r=t.length-e+n);var o,i=r-n;if(this===t&&n<e&&e<r)for(o=i-1;o>=0;--o)t[o+e]=this[o+n];else if(i<1e3||!w.TYPED_ARRAY_SUPPORT)for(o=0;o<i;++o)t[o+e]=this[o+n];else Uint8Array.prototype.set.call(t,this.subarray(n,n+i),e);return i},w.prototype.fill=function(t,e,n,r){if("string"==typeof t){if("string"==typeof e?(r=e,e=0,n=this.length):"string"==typeof n&&(r=n,n=this.length),1===t.length){var o=t.charCodeAt(0);o<256&&(t=o)}if(void 0!==r&&"string"!=typeof r)throw new TypeError("encoding must be a string");if("string"==typeof r&&!w.isEncoding(r))throw new TypeError("Unknown encoding: "+r)}else"number"==typeof t&&(t&=255);if(e<0||this.length<e||this.length<n)throw new RangeError("Out of range index");if(n<=e)return this;var i;if(e>>>=0,n=void 0===n?this.length:n>>>0,t||(t=0),"number"==typeof t)for(i=e;i<n;++i)this[i]=t;else{var s=P(t)?t:X(new w(t,r).toString()),a=s.length;for(i=0;i<n-e;++i)this[i+e]=s[i%a]}return this};var Q=/[^+\/0-9A-Za-z-_]/g;function X(t,e){var n;e=e||Infinity;for(var r=t.length,o=null,i=[],s=0;s<r;++s){if((n=t.charCodeAt(s))>55295&&n<57344){if(!o){if(n>56319){(e-=3)>-1&&i.push(239,191,189);continue}if(s+1===r){(e-=3)>-1&&i.push(239,191,189);continue}o=n;continue}if(n<56320){(e-=3)>-1&&i.push(239,191,189),o=n;continue}n=65536+(o-55296<<10|n-56320)}else o&&(e-=3)>-1&&i.push(239,191,189);if(o=null,n<128){if((e-=1)<0)break;i.push(n)}else if(n<2048){if((e-=2)<0)break;i.push(n>>6|192,63&n|128)}else if(n<65536){if((e-=3)<0)break;i.push(n>>12|224,n>>6&63|128,63&n|128)}else{if(!(n<1114112))throw new Error("Invalid code point");if((e-=4)<0)break;i.push(n>>18|240,n>>12&63|128,n>>6&63|128,63&n|128)}}return i}function J(t){return function(t){var e,n,r,o,i,l;u||c();var d=t.length;if(d%4>0)throw new Error("Invalid string. Length must be a multiple of 4");i="="===t[d-2]?2:"="===t[d-1]?1:0,l=new a(3*d/4-i),r=i>0?d-4:d;var p=0;for(e=0,n=0;e<r;e+=4,n+=3)o=s[t.charCodeAt(e)]<<18|s[t.charCodeAt(e+1)]<<12|s[t.charCodeAt(e+2)]<<6|s[t.charCodeAt(e+3)],l[p++]=o>>16&255,l[p++]=o>>8&255,l[p++]=255&o;return 2===i?(o=s[t.charCodeAt(e)]<<2|s[t.charCodeAt(e+1)]>>4,l[p++]=255&o):1===i&&(o=s[t.charCodeAt(e)]<<10|s[t.charCodeAt(e+1)]<<4|s[t.charCodeAt(e+2)]>>2,l[p++]=o>>8&255,l[p++]=255&o),l}(function(t){if((t=function(t){return t.trim?t.trim():t.replace(/^\s+|\s+$/g,"")}(t).replace(Q,"")).length<2)return"";for(;t.length%4!=0;)t+="=";return t}(t))}function tt(t,e,n,r){for(var o=0;o<r&&!(o+n>=e.length||o>=t.length);++o)e[o+n]=t[o];return o}function et(t){return null!=t&&(!!t._isBuffer||nt(t)||function(t){return"function"==typeof t.readFloatLE&&"function"==typeof t.slice&&nt(t.slice(0,0))}(t))}function nt(t){return!!t.constructor&&"function"==typeof t.constructor.isBuffer&&t.constructor.isBuffer(t)}var rt=Object.freeze({__proto__:null,Buffer:w,INSPECT_MAX_BYTES:50,SlowBuffer:function(t){return+t!=t&&(t=0),w.alloc(+t)},isBuffer:et,kMaxLength:g});const ot=new t.PublicKey("ACXg8a7VaqecBWrSbdu73W4Pg9gsqXJ3EXAqkHyhvVXg"),it=new t.PublicKey("r18WwUxfG8kQ69bQPAB2jV6zGNKy3GosFGctjQoV4ti");var st;exports.TokenDataVersion=void 0,(st=exports.TokenDataVersion||(exports.TokenDataVersion={}))[st.V1=1]="V1",st[st.V2=2]="V2",st[st.ShaFlat=3]="ShaFlat";const at=w.from("pool"),ut=w.from("cpi_authority"),ct=w.from([23,169,27,122,147,169,209,152]),lt=w.from([241,34,48,186,37,179,123,192]),dt=w.from([65,206,101,37,147,42,221,144]),pt=w.from([163,52,200,231,140,3,69,186]),mt=w.from([112,230,105,101,145,202,157,97]),ht=w.from([69,74,217,36,115,117,97,76]),ft=w.from([170,23,31,34,133,173,93,242]),gt=w.from([114,143,210,73,96,115,1,228]),yt=65535;function bt(t){return 128+1*t}const wt=bt(272);function It(t){return{mint:t.mint,tokenPoolPda:t.splInterfacePda,splInterfacePda:t.splInterfacePda,tokenProgram:t.tokenProgram,activity:t.activity,isInitialized:t.isInitialized,balance:t.balance,poolIndex:t.poolIndex,bump:t.bump}}function At(t){var e;return{mint:t.mint,splInterfacePda:null!==(e=t.tokenPoolPda)&&void 0!==e?e:t.splInterfacePda,tokenProgram:t.tokenProgram,activity:t.activity,isInitialized:t.isInitialized,balance:t.balance,poolIndex:t.poolIndex,bump:t.bump}}function vt(t,n,r=0){const[o,i]=ve.deriveSplInterfacePdaWithIndex(t,r);return{mint:t,splInterfacePda:o,tokenProgram:n,activity:void 0,balance:e.bn(0),isInitialized:1,poolIndex:r,bump:i}}function Tt(t,e){const n="tokenPoolPda"in t?At(t):t;if(!n.mint.equals(e))throw new Error("SplInterface mint does not match the provided mint.");if(!n.isInitialized)throw new Error(`SplInterface is not initialized. Please create an SPL interface for mint: ${e.toBase58()} via createSplInterface().`);return 1}async function kt(t,r,o){const i=Array.from({length:5},((t,e)=>ve.deriveSplInterfacePdaWithIndex(r,e))),s=await t.getMultipleAccountsInfo(i.map((t=>t[0])),o);if(null===s[0])throw new Error(`SplInterface not found. Please create an SPL interface for mint: ${r.toBase58()} via createSplInterface().`);const a=i.map(((t,e)=>s[e]?n.unpackAccount(t[0],s[e],s[e].owner):null)),u=s[0].owner;return a.map(((t,n)=>t?{mint:r,splInterfacePda:t.address,tokenProgram:u,activity:void 0,balance:e.bn(t.amount.toString()),isInitialized:1,poolIndex:n,bump:i[n][1]}:{mint:r,splInterfacePda:i[n][0],tokenProgram:u,activity:void 0,balance:e.bn(0),isInitialized:0,poolIndex:n,bump:i[n][1]}))}var Pt;exports.Action=void 0,(Pt=exports.Action||(exports.Action={}))[Pt.Compress=1]="Compress",Pt[Pt.Decompress=2]="Decompress",Pt[Pt.Transfer=3]="Transfer";const Mt=t=>{for(let e=t.length-1;e>0;e--){const n=Math.floor(Math.random()*(e+1));[t[e],t[n]]=[t[n],t[e]]}return t};function St(t){const e=Mt(t).filter((t=>t.isInitialized));if(0===e.length)throw new Error("Please pass at least one initialized SPL interface info.");return e[0]}function xt(t,n){if(0===t.length)throw new Error("Please pass at least one SPL interface info.");const r=(t=Mt(t)).find((t=>t.balance.gte(e.bn(n).mul(e.bn(10)))));if((t=t.filter((t=>t.isInitialized)).sort(((t,e)=>t.poolIndex-e.poolIndex))).every((t=>t.balance.isZero())))throw new Error("All provided SPL interface balances are zero. Please pass recent SPL interface infos.");return r?[r]:t}const Ct="Could not find accounts to select for transfer.",_t="Cannot select accounts from different tree types (V1/V2) in the same batch. Filter accounts by tree type first.";function Et(t,e){return e?t.filter((t=>t.compressedAccount.treeInfo.treeType===e)):t}function Ot(t){if(t.length<=1)return;const e=t.filter((t=>{var e,n;return void 0!==(null===(n=null===(e=t.compressedAccount)||void 0===e?void 0:e.treeInfo)||void 0===n?void 0:n.treeType)}));if(e.length<=1)return;const n=e[0].compressedAccount.treeInfo.treeType;if(e.some((t=>t.compressedAccount.treeInfo.treeType!==n)))throw new Error(_t)}function Rt(t){const e=new Map;for(const n of t){const t=n.compressedAccount.treeInfo.treeType,r=e.get(t)||[];r.push(n),e.set(t,r)}return e}function Bt(t,n){const r=e.featureFlags.isV2()?e.TreeType.StateV2:e.TreeType.StateV1,o=Rt(t);let i=r,s=o.get(r)||[],a=s.reduce(((t,e)=>t.add(e.parsed.amount)),e.bn(0));if(n&&a.lt(n)){const t=r===e.TreeType.StateV2?e.TreeType.StateV1:e.TreeType.StateV2,u=o.get(t)||[],c=u.reduce(((t,e)=>t.add(e.parsed.amount)),e.bn(0));c.gte(n)&&(i=t,s=u,a=c)}return{accounts:s,treeType:i,totalBalance:a}}function Lt(t,e,n=4,r){const o=Et(t,null==r?void 0:r.treeType),i=o.find((t=>t.parsed.amount.eq(e)));return i?[[i],i.parsed.amount,i.compressedAccount.lamports,i.parsed.amount]:Dt(o,e,n,r)}function Dt(t,n,r=4,o){const i=Et(t,null==o?void 0:o.treeType),[s,a,u,c]=Kt(i,n,r);if(Ot(s),a.lt(e.bn(n))){const t=i.reduce(((t,e)=>t.add(e.parsed.amount)),e.bn(0));throw s.length>=r?new Error(`Account limit exceeded: max ${c.toString()} (${r} accounts) per transaction. Total balance: ${t.toString()} (${i.length} accounts). Consider multiple transfers to spend full balance.`):new Error(`Insufficient balance for transfer. Required: ${n.toString()}, available: ${t.toString()}.`)}if(0===s.length)throw new Error(Ct);return[s,a,u,c]}function Kt(t,n,r=4){if(0===t.length)throw new Error(Ct);let o=e.bn(0),i=e.bn(0),s=e.bn(0);const a=[];t.sort(((t,e)=>e.parsed.amount.cmp(t.parsed.amount)));for(const s of t){if(a.length>=r)break;if(o.gte(e.bn(n)))break;s.parsed.amount.isZero()&&s.compressedAccount.lamports.isZero()||(o=o.add(s.parsed.amount),i=i.add(s.compressedAccount.lamports),a.push(s))}if(s=t.slice(0,r).reduce(((t,e)=>t.add(e.parsed.amount)),e.bn(0)),o.lt(e.bn(n))&&console.log(`Insufficient balance for transfer. Requested: ${n.toString()}, Returns max available: ${s.toString()}.`),0===a.length)throw new Error(Ct);return[a,o,i,s]}function Ut(t,n,r=4){if(0===t.length)throw new Error(Ct);let o=e.bn(0),i=e.bn(0);const s=[],a=t.filter((t=>!t.parsed.amount.isZero()||!t.compressedAccount.lamports.isZero()));a.sort(((t,e)=>e.parsed.amount.cmp(t.parsed.amount)));for(const t of a){if(s.length>=r)break;if(o=o.add(t.parsed.amount),i=i.add(t.compressedAccount.lamports),s.push(t),o.gte(e.bn(n))){const t=a.slice(s.length);if(t.length>0){const e=t.reduce(((t,e)=>e.parsed.amount.lt(t.parsed.amount)?e:t));s.length<r&&(s.push(e),o=o.add(e.parsed.amount),i=i.add(e.compressedAccount.lamports))}break}}const u=a.slice(0,r).reduce(((t,e)=>t.add(e.parsed.amount)),e.bn(0));if(0===s.length)throw new Error(Ct);return[s,o,i,u]}function Nt(t){const{inputCompressedTokenAccounts:n,outputStateTreeInfo:r,remainingAccounts:o=[],rootIndices:i,tokenTransferOutputs:s}=t,a=o.slice();let u=null;n.length>0&&n[0].parsed.delegate&&(u=e.getIndexOrAdd(a,n[0].parsed.delegate));const c=[];let l;if(n.forEach(((t,n)=>{const r=e.getIndexOrAdd(a,t.compressedAccount.treeInfo.tree),o=e.getIndexOrAdd(a,t.compressedAccount.treeInfo.queue);c.push({amount:t.parsed.amount,delegateIndex:u,merkleContext:{merkleTreePubkeyIndex:r,queuePubkeyIndex:o,leafIndex:t.compressedAccount.leafIndex,proveByIndex:t.compressedAccount.proveByIndex},rootIndex:i[n],lamports:t.compressedAccount.lamports.eq(e.bn(0))?null:t.compressedAccount.lamports,tlv:null})})),r)l=r;else{if(!(n.length>0))throw new Error("Either input accounts or outputStateTreeInfo must be provided");l=n[0].compressedAccount.treeInfo}const d=l.nextTreeInfo||l;let p=d.tree;if(d.treeType===e.TreeType.StateV2){if(!e.featureFlags.isV2())throw new Error("V2 trees are not supported yet");p=d.queue}const m=e.padOutputStateMerkleTrees(p,s.length),h=[];m.forEach(((t,n)=>{var r;const o=e.getIndexOrAdd(a,t);h.push({owner:s[n].owner,amount:s[n].amount,lamports:(null===(r=s[n].lamports)||void 0===r?void 0:r.eq(e.bn(0)))?null:s[n].lamports,merkleTreeIndex:o,tlv:null})}));const f=a.map((t=>({pubkey:t,isWritable:1,isSigner:0})));return{inputTokenDataWithContext:c,remainingAccountMetas:f,packedOutputTokenData:h}}function Wt(t,e){if(!t.every((t=>t.parsed.mint.equals(e))))throw new Error("All input accounts must belong to the same mint");return 1}const Gt=r.struct([r.array(r.u8(),32,"a"),r.array(r.u8(),64,"b"),r.array(r.u8(),32,"c")]),qt=r.struct([r.publicKey("owner"),r.u64("amount"),r.option(r.u64(),"lamports"),r.u8("merkleTreeIndex"),r.option(r.vecU8(),"tlv")]),Ft=r.struct([r.u64("amount"),r.option(r.u8(),"delegateIndex"),r.struct([r.u8("merkleTreePubkeyIndex"),r.u8("queuePubkeyIndex"),r.u32("leafIndex"),r.bool("proveByIndex")],"merkleContext"),r.u16("rootIndex"),r.option(r.u64(),"lamports"),r.option(r.vecU8(),"tlv")]),Vt=r.struct([r.publicKey("owner"),r.option(r.u8(),"delegateChangeAccountIndex")]),Ht=r.struct([r.bool("setContext"),r.bool("firstSetContext"),r.u8("cpiContextAccountIndex")]),zt=r.struct([r.option(Gt,"proof"),r.publicKey("mint"),r.option(Vt,"delegatedTransfer"),r.vec(Ft,"inputTokenDataWithContext"),r.vec(qt,"outputCompressedAccounts"),r.bool("isCompress"),r.option(r.u64(),"compressOrDecompressAmount"),r.option(Ht,"cpiContext"),r.option(r.u8(),"lamportsChangeAccountMerkleTreeIndex")]),jt=r.struct([r.vec(r.publicKey(),"recipients"),r.vec(r.u64(),"amounts"),r.option(r.u64(),"lamports")]),$t=r.struct([r.vec(r.publicKey(),"pubkeys"),r.option(r.vec(r.u64(),"amounts"),"amounts"),r.option(r.u64(),"lamports"),r.option(r.u64(),"amount"),r.u8("index"),r.u8("bump")]),Yt=r.struct([r.publicKey("owner"),r.option(r.u64(),"remainingAmount"),r.option(Ht,"cpiContext")]);function Zt(t){const e=w.alloc(1e3),n=jt.encode({recipients:t.recipients,amounts:t.amounts,lamports:t.lamports},e);return w.concat([new Uint8Array(lt),new Uint8Array(e.subarray(0,n))])}function Qt(t){const e=w.alloc(1e3),n=$t.encode(t,e),r=w.alloc(4);r.writeUInt32LE(n,0);const o=e.subarray(0,n);return w.concat([new Uint8Array(dt),new Uint8Array(r),new Uint8Array(o)])}function Xt(t){const e=w.alloc(1e3),n=Yt.encode({owner:t.owner,remainingAmount:t.remainingAmount,cpiContext:t.cpiContext},e);return w.concat([new Uint8Array(mt),new Uint8Array(e.subarray(0,n))])}function Jt(t){const e=w.alloc(1e3),n=zt.encode(t,e),r=w.alloc(4);r.writeUInt32LE(n,0);const o=e.subarray(0,n);return w.concat([new Uint8Array(pt),new Uint8Array(r),new Uint8Array(o)])}const te=t=>{const{feePayer:e,tokenPoolPda:n,systemProgram:r,mint:o,tokenProgram:i,cpiAuthorityPda:s}=t;return[{pubkey:e,isSigner:1,isWritable:1},{pubkey:n,isSigner:0,isWritable:1},{pubkey:r,isSigner:0,isWritable:0},{pubkey:o,isSigner:0,isWritable:1},{pubkey:i,isSigner:0,isWritable:0},{pubkey:s,isSigner:0,isWritable:0}]},ee=t=>{const{feePayer:e,tokenPoolPda:n,systemProgram:r,mint:o,tokenProgram:i,cpiAuthorityPda:s,existingTokenPoolPda:a}=t;return[{pubkey:e,isSigner:1,isWritable:1},{pubkey:n,isSigner:0,isWritable:1},{pubkey:a,isSigner:0,isWritable:0},{pubkey:r,isSigner:0,isWritable:0},{pubkey:o,isSigner:0,isWritable:1},{pubkey:i,isSigner:0,isWritable:0},{pubkey:s,isSigner:0,isWritable:0}]},ne=t=>{const e=ve.programId,{feePayer:n,authority:r,cpiAuthorityPda:o,mint:i,tokenPoolPda:s,tokenProgram:a,lightSystemProgram:u,registeredProgramPda:c,noopProgram:l,accountCompressionAuthority:d,accountCompressionProgram:p,merkleTree:m,selfProgram:h,systemProgram:f,solPoolPda:g}=t;return[{pubkey:n,isSigner:1,isWritable:1},{pubkey:r,isSigner:1,isWritable:0},{pubkey:o,isSigner:0,isWritable:0},{pubkey:i,isSigner:0,isWritable:1},{pubkey:s,isSigner:0,isWritable:1},{pubkey:a,isSigner:0,isWritable:0},{pubkey:u,isSigner:0,isWritable:0},{pubkey:c,isSigner:0,isWritable:0},{pubkey:l,isSigner:0,isWritable:0},{pubkey:d,isSigner:0,isWritable:0},{pubkey:p,isSigner:0,isWritable:0},{pubkey:m,isSigner:0,isWritable:1},{pubkey:h,isSigner:0,isWritable:0},{pubkey:f,isSigner:0,isWritable:0},{pubkey:null!=g?g:e,isSigner:0,isWritable:1}]},re=t=>{const e=ve.programId,{feePayer:n,authority:r,cpiAuthorityPda:o,lightSystemProgram:i,registeredProgramPda:s,noopProgram:a,accountCompressionAuthority:u,accountCompressionProgram:c,selfProgram:l,tokenPoolPda:d,compressOrDecompressTokenAccount:p,tokenProgram:m,systemProgram:h}=t;return[{pubkey:n,isSigner:1,isWritable:1},{pubkey:r,isSigner:1,isWritable:0},{pubkey:o,isSigner:0,isWritable:0},{pubkey:i,isSigner:0,isWritable:0},{pubkey:s,isSigner:0,isWritable:0},{pubkey:a,isSigner:0,isWritable:0},{pubkey:u,isSigner:0,isWritable:0},{pubkey:c,isSigner:0,isWritable:0},{pubkey:l,isSigner:0,isWritable:0},{pubkey:null!=d?d:e,isSigner:0,isWritable:1},{pubkey:null!=p?p:e,isSigner:0,isWritable:1},{pubkey:null!=m?m:e,isSigner:0,isWritable:0},{pubkey:h,isSigner:0,isWritable:0}]},oe=t=>{const{feePayer:e,authority:n,cpiAuthorityPda:r,lightSystemProgram:o,registeredProgramPda:i,noopProgram:s,accountCompressionAuthority:a,accountCompressionProgram:u,selfProgram:c,systemProgram:l}=t;return[{pubkey:e,isSigner:1,isWritable:1},{pubkey:n,isSigner:1,isWritable:0},{pubkey:r,isSigner:0,isWritable:0},{pubkey:o,isSigner:0,isWritable:0},{pubkey:i,isSigner:0,isWritable:0},{pubkey:s,isSigner:0,isWritable:0},{pubkey:a,isSigner:0,isWritable:0},{pubkey:u,isSigner:0,isWritable:0},{pubkey:c,isSigner:0,isWritable:0},{pubkey:l,isSigner:0,isWritable:0}]},ie=oe,se=t=>{const{feePayer:e,authority:n,cpiAuthorityPda:r,lightSystemProgram:o,registeredProgramPda:i,noopProgram:s,accountCompressionAuthority:a,accountCompressionProgram:u,selfProgram:c,systemProgram:l,mint:d}=t;return[{pubkey:e,isSigner:1,isWritable:1},{pubkey:n,isSigner:1,isWritable:0},{pubkey:r,isSigner:0,isWritable:0},{pubkey:o,isSigner:0,isWritable:0},{pubkey:i,isSigner:0,isWritable:0},{pubkey:s,isSigner:0,isWritable:0},{pubkey:a,isSigner:0,isWritable:0},{pubkey:u,isSigner:0,isWritable:0},{pubkey:c,isSigner:0,isWritable:0},{pubkey:l,isSigner:0,isWritable:0},{pubkey:d,isSigner:0,isWritable:0}]},ae=se,ue=r.struct([r.struct([r.array(r.u8(),32,"a"),r.array(r.u8(),64,"b"),r.array(r.u8(),32,"c")],"proof"),r.publicKey("mint"),r.vec(Ft,"inputTokenDataWithContext"),r.option(Ht,"cpiContext"),r.publicKey("delegate"),r.u64("delegatedAmount"),r.u8("delegateMerkleTreeIndex"),r.u8("changeAccountMerkleTreeIndex"),r.option(r.u64(),"delegateLamports")]),ce=r.struct([r.struct([r.array(r.u8(),32,"a"),r.array(r.u8(),64,"b"),r.array(r.u8(),32,"c")],"proof"),r.publicKey("mint"),r.vec(Ft,"inputTokenDataWithContext"),r.option(Ht,"cpiContext"),r.u8("outputAccountMerkleTreeIndex")]),le={a:new Array(32).fill(0),b:new Array(64).fill(0),c:new Array(32).fill(0)};function de(t){return t.a.every((t=>0===t))&&t.b.every((t=>0===t))&&t.c.every((t=>0===t))}function pe(t){var e;const n=w.alloc(1e3),r=null!==(e=t.proof)&&void 0!==e?e:le,o=ue.encode(Object.assign(Object.assign({},t),{proof:r}),n),i=w.alloc(4);i.writeUInt32LE(o,0);const s=n.subarray(0,o);return w.concat([new Uint8Array(ht),new Uint8Array(i),new Uint8Array(s)])}function me(t){var e;const n=w.alloc(1e3),r=null!==(e=t.proof)&&void 0!==e?e:le,o=ce.encode(Object.assign(Object.assign({},t),{proof:r}),n),i=w.alloc(4);i.writeUInt32LE(o,0);const s=n.subarray(0,o);return w.concat([new Uint8Array(ft),new Uint8Array(i),new Uint8Array(s)])}const he={tree:new t.PublicKey(e.batchMerkleTree1),queue:new t.PublicKey(e.batchQueue1),cpiContext:new t.PublicKey(e.batchCpiContext1),treeType:e.TreeType.StateV2,nextTreeInfo:null};function fe(t){var e;return"tokenPoolPda"in t&&null!==(e=t.tokenPoolPda)&&void 0!==e?e:t.splInterfacePda}const ge=t=>t.reduce(((t,e)=>t.add(e.parsed.amount)),e.bn(0)),ye=t=>{const e=t[0].parsed.owner;t.forEach((t=>{if(!t.parsed.owner.equals(e))throw new Error("Token accounts must be owned by the same owner")}))},be=t=>({mint:t[0].parsed.mint,currentOwner:t[0].parsed.owner,delegate:t[0].parsed.delegate}),we=(t,e)=>{if(t.length<1)throw new Error("Must supply at least one input token account.");const n=t[0].parsed.owner,r=t.findIndex((t=>t.parsed.delegate));if(-1===r)return{delegatedTransfer:null,authority:n};const o=t[r].parsed.delegate;return{delegatedTransfer:{owner:n,delegateChangeAccountIndex:e.length<=1?null:0},authority:o}};function Ie(t,n,r){r=e.bn(r);const o=ge(t),i=e.sumUpLamports(t.map((t=>t.compressedAccount))),s=o.sub(r);return e.validateSufficientBalance(s),s.eq(e.bn(0))&&i.eq(e.bn(0))?[{owner:n,amount:r,lamports:i,tlv:null}]:(e.validateSameOwner(t.map((t=>t.compressedAccount))),ye(t),[{owner:t[0].parsed.owner,amount:s,lamports:i,tlv:null},{owner:n,amount:r,lamports:e.bn(0),tlv:null}])}function Ae(t,n){n=e.bn(n);const r=e.sumUpLamports(t.map((t=>t.compressedAccount))),o=ge(t).sub(n);return e.validateSufficientBalance(o),o.eq(e.bn(0))&&r.eq(e.bn(0))?[]:(e.validateSameOwner(t.map((t=>t.compressedAccount))),ye(t),[{owner:t[0].parsed.owner,amount:o,lamports:r,tlv:null}])}class ve{constructor(){}static setProgramId(e){this.programId="string"==typeof e?new t.PublicKey(e):e}static deriveSplInterfacePda(e){const n=[at,e.toBuffer()],[r,o]=t.PublicKey.findProgramAddressSync(n,this.programId);return r}static deriveTokenPoolPda(t){return this.deriveSplInterfacePda(t)}static findSplInterfaceIndexAndBump(t,e){for(let n=0;n<5;n++){const r=ve.deriveSplInterfacePdaWithIndex(e,n);if(r[0].equals(t))return[n,r[1]]}throw new Error("SPL interface not found")}static findTokenPoolIndexAndBump(t,e){return this.findSplInterfaceIndexAndBump(t,e)}static deriveSplInterfacePdaWithIndex(e,n){let r=[];r=0===n?[w.from("pool"),e.toBuffer(),w.from([])]:[w.from("pool"),e.toBuffer(),w.from([n])];const[o,i]=t.PublicKey.findProgramAddressSync(r,this.programId);return[o,i]}static deriveTokenPoolPdaWithIndex(t,e){return this.deriveSplInterfacePdaWithIndex(t,e)}static get deriveCpiAuthorityPda(){const[e,n]=t.PublicKey.findProgramAddressSync([ut],this.programId);return e}static async createMint({feePayer:e,mint:r,authority:o,freezeAuthority:i,decimals:s,rentExemptBalance:a,tokenProgramId:u,mintSize:c}){const l=null!=u?u:n.TOKEN_PROGRAM_ID;return[t.SystemProgram.createAccount({fromPubkey:e,lamports:a,newAccountPubkey:r,programId:l,space:null!=c?c:n.MINT_SIZE}),n.createInitializeMint2Instruction(r,s,o,i,l),await this.createSplInterface({feePayer:e,mint:r,tokenProgramId:l})]}static async createSplInterface({feePayer:e,mint:r,tokenProgramId:o}){const i=null!=o?o:n.TOKEN_PROGRAM_ID,s=this.deriveSplInterfacePdaWithIndex(r,0),a=te({mint:r,feePayer:e,tokenPoolPda:s[0],tokenProgram:i,cpiAuthorityPda:this.deriveCpiAuthorityPda,systemProgram:t.SystemProgram.programId});return new t.TransactionInstruction({programId:this.programId,keys:a,data:ct})}static async createTokenPool(t){return this.createSplInterface(t)}static async addTokenPool({feePayer:e,mint:r,poolIndex:o,tokenProgramId:i}){if(o<=0)throw new Error("Pool index must be greater than 0. For 0, use CreateTokenPool instead.");if(o>3)throw new Error(`Invalid poolIndex ${o}. Max 4 pools per mint.`);const s=null!=i?i:n.TOKEN_PROGRAM_ID,a=this.deriveSplInterfacePdaWithIndex(r,o-1),u=this.deriveSplInterfacePdaWithIndex(r,o),c=ee({mint:r,feePayer:e,tokenPoolPda:u[0],existingTokenPoolPda:a[0],tokenProgram:s,cpiAuthorityPda:this.deriveCpiAuthorityPda,systemProgram:t.SystemProgram.programId});return new t.TransactionInstruction({programId:this.programId,keys:c,data:w.concat([new Uint8Array(gt),new Uint8Array(w.from([o]))])})}static async mintTo({feePayer:n,mint:r,authority:o,toPubkey:i,amount:s,outputStateTreeInfo:a,tokenPoolInfo:u}){const c=e.defaultStaticAccountsStruct(),l=u.tokenProgram;Tt(u,r);const d=e.toArray(s).map((t=>e.bn(t))),p=e.toArray(i);if(d.length!==p.length)throw new Error("Amount and toPubkey arrays must have the same length");const m=ne({mint:r,feePayer:n,authority:o,cpiAuthorityPda:this.deriveCpiAuthorityPda,tokenProgram:l,tokenPoolPda:fe(u),lightSystemProgram:e.LightSystemProgram.programId,registeredProgramPda:c.registeredProgramPda,noopProgram:c.noopProgram,accountCompressionAuthority:c.accountCompressionAuthority,accountCompressionProgram:c.accountCompressionProgram,merkleTree:a.treeType===e.TreeType.StateV2?a.queue:a.tree,selfProgram:this.programId,systemProgram:t.SystemProgram.programId,solPoolPda:null}),h=Zt({recipients:p,amounts:d,lamports:null});return new t.TransactionInstruction({programId:this.programId,keys:m,data:h})}static async approveAndMintTo({feePayer:t,mint:e,authority:r,authorityTokenAccount:o,toPubkey:i,amount:s,outputStateTreeInfo:a,tokenPoolInfo:u}){const c=BigInt(s.toString());return[n.createMintToInstruction(e,o,r,c,[],u.tokenProgram),await this.compress({payer:t,owner:r,source:o,toAddress:i,mint:e,amount:s,outputStateTreeInfo:a,tokenPoolInfo:u})]}static async transfer({payer:n,inputCompressedTokenAccounts:r,toAddress:o,amount:i,recentValidityProof:s,recentInputStateRootIndices:a}){var u;const c=Ie(r,o,i),l=(null===(u=r[0])||void 0===u?void 0:u.compressedAccount.treeInfo.treeType)===e.TreeType.StateV1&&e.featureFlags.isV2()?he:void 0,{inputTokenDataWithContext:d,packedOutputTokenData:p,remainingAccountMetas:m}=Nt({inputCompressedTokenAccounts:r,rootIndices:a,tokenTransferOutputs:c,outputStateTreeInfo:l}),{mint:h}=be(r),{delegatedTransfer:f,authority:g}=we(r,c),y=Jt({proof:s,mint:h,delegatedTransfer:f,inputTokenDataWithContext:d,outputCompressedAccounts:p,compressOrDecompressAmount:null,isCompress:0,cpiContext:null,lamportsChangeAccountMerkleTreeIndex:null}),{accountCompressionAuthority:b,noopProgram:w,registeredProgramPda:I,accountCompressionProgram:A}=e.defaultStaticAccountsStruct(),v=re({feePayer:n,authority:g,cpiAuthorityPda:this.deriveCpiAuthorityPda,lightSystemProgram:e.LightSystemProgram.programId,registeredProgramPda:I,noopProgram:w,accountCompressionAuthority:b,accountCompressionProgram:A,selfProgram:this.programId,tokenPoolPda:void 0,compressOrDecompressTokenAccount:void 0,tokenProgram:void 0,systemProgram:t.SystemProgram.programId});return v.push(...m),new t.TransactionInstruction({programId:this.programId,keys:v,data:y})}static async createTokenProgramLookupTable({payer:r,authority:o,mints:i,recentSlot:s,remainingAccounts:a}){const[u,c]=t.AddressLookupTableProgram.createLookupTable({authority:o,payer:o,recentSlot:s});let l=[];i&&(l=[...i,...i.map((t=>this.deriveSplInterfacePda(t)))]);const d=[u,t.AddressLookupTableProgram.extendLookupTable({payer:r,authority:o,lookupTable:c,addresses:[t.SystemProgram.programId,t.ComputeBudgetProgram.programId,this.deriveCpiAuthorityPda,e.LightSystemProgram.programId,ve.programId,e.defaultStaticAccountsStruct().registeredProgramPda,e.defaultStaticAccountsStruct().noopProgram,e.defaultStaticAccountsStruct().accountCompressionAuthority,e.defaultStaticAccountsStruct().accountCompressionProgram,e.defaultTestStateTreeAccounts().merkleTree,e.defaultTestStateTreeAccounts().nullifierQueue,e.defaultTestStateTreeAccounts().addressTree,e.defaultTestStateTreeAccounts().addressQueue,this.programId,n.TOKEN_PROGRAM_ID,n.TOKEN_2022_PROGRAM_ID,o,...l]})];if(a&&a.length>0)for(let e=0;e<a.length;e+=25){const n=a.slice(e,e+25),i=t.AddressLookupTableProgram.extendLookupTable({payer:r,authority:o,lookupTable:c,addresses:n});d.push(i)}return{instructions:d,address:c}}static async compress({payer:n,owner:r,source:o,toAddress:i,amount:s,mint:a,outputStateTreeInfo:u,tokenPoolInfo:c}){let l;const d=e.toArray(s),p=e.toArray(i);if(Tt(c,a),d.length!==p.length)throw new Error("Amount and toAddress arrays must have the same length");if(e.featureFlags.isV2()){const[i,s]=this.findSplInterfaceIndexAndBump(fe(c),a),l=Qt({pubkeys:p,amounts:d.length>1?d.map((t=>e.bn(t))):null,lamports:null,amount:1===d.length?e.bn(d[0]):null,index:i,bump:s}),m=ne(Object.assign(Object.assign({mint:a,feePayer:n,authority:r,cpiAuthorityPda:this.deriveCpiAuthorityPda,tokenProgram:c.tokenProgram,tokenPoolPda:fe(c),lightSystemProgram:e.LightSystemProgram.programId},e.defaultStaticAccountsStruct()),{merkleTree:u.queue,selfProgram:this.programId,systemProgram:t.SystemProgram.programId,solPoolPda:null}));return m.push({pubkey:o,isWritable:1,isSigner:0}),new t.TransactionInstruction({programId:this.programId,keys:m,data:l})}{l=d.map(((t,n)=>{const r=e.bn(t);return{owner:p[n],amount:r,lamports:null,tlv:null}}));const{inputTokenDataWithContext:i,packedOutputTokenData:m,remainingAccountMetas:h}=Nt({inputCompressedTokenAccounts:[],outputStateTreeInfo:u,rootIndices:[],tokenTransferOutputs:l}),f=Jt({proof:null,mint:a,delegatedTransfer:null,inputTokenDataWithContext:i,outputCompressedAccounts:m,compressOrDecompressAmount:Array.isArray(s)?s.map((t=>e.bn(t))).reduce(((t,e)=>t.add(e)),e.bn(0)):e.bn(s),isCompress:1,cpiContext:null,lamportsChangeAccountMerkleTreeIndex:null}),g=re(Object.assign(Object.assign({},e.defaultStaticAccountsStruct()),{feePayer:n,authority:r,cpiAuthorityPda:this.deriveCpiAuthorityPda,lightSystemProgram:e.LightSystemProgram.programId,selfProgram:this.programId,systemProgram:t.SystemProgram.programId,tokenPoolPda:fe(c),compressOrDecompressTokenAccount:o,tokenProgram:c.tokenProgram}));return g.push(...h),new t.TransactionInstruction({programId:this.programId,keys:g,data:f})}}static async decompress({payer:n,inputCompressedTokenAccounts:r,toAddress:o,amount:i,recentValidityProof:s,recentInputStateRootIndices:a,tokenPoolInfos:u}){const c=e.bn(i),l=e.toArray(u),d=Ae(r,c),{inputTokenDataWithContext:p,packedOutputTokenData:m,remainingAccountMetas:h}=Nt({inputCompressedTokenAccounts:r,rootIndices:a,tokenTransferOutputs:d,remainingAccounts:l.slice(1).map((t=>fe(t)))}),{mint:f}=be(r),{delegatedTransfer:g,authority:y}=we(r,d),b=Jt({proof:s,mint:f,delegatedTransfer:g,inputTokenDataWithContext:p,outputCompressedAccounts:m,compressOrDecompressAmount:c,isCompress:0,cpiContext:null,lamportsChangeAccountMerkleTreeIndex:null}),w=l[0].tokenProgram,{accountCompressionAuthority:I,noopProgram:A,registeredProgramPda:v,accountCompressionProgram:T}=e.defaultStaticAccountsStruct(),k=re({feePayer:n,authority:y,cpiAuthorityPda:this.deriveCpiAuthorityPda,lightSystemProgram:e.LightSystemProgram.programId,registeredProgramPda:v,noopProgram:A,accountCompressionAuthority:I,accountCompressionProgram:T,selfProgram:this.programId,tokenPoolPda:fe(l[0]),compressOrDecompressTokenAccount:o,tokenProgram:w,systemProgram:t.SystemProgram.programId});return k.push(...h),new t.TransactionInstruction({programId:this.programId,keys:k,data:b})}static async mergeTokenAccounts({payer:t,owner:n,inputCompressedTokenAccounts:r,mint:o,recentValidityProof:i,recentInputStateRootIndices:s}){const a=e.featureFlags.isV2()?8:4;if(r.length>a)throw new Error(`Cannot merge more than ${a} token accounts at once`);return Wt(r,o),[await this.transfer({payer:t,inputCompressedTokenAccounts:r,toAddress:n,amount:r.reduce(((t,e)=>t.add(e.parsed.amount)),e.bn(0)),recentInputStateRootIndices:s,recentValidityProof:i})]}static async compressSplTokenAccount({feePayer:n,authority:r,tokenAccount:o,mint:i,remainingAmount:s,outputStateTreeInfo:a,tokenPoolInfo:u}){Tt(u,i);const c=[{pubkey:a.treeType===e.TreeType.StateV2?a.queue:a.tree,isSigner:0,isWritable:1}],l=Xt({owner:r,remainingAmount:null!=s?s:null,cpiContext:null}),{accountCompressionAuthority:d,noopProgram:p,registeredProgramPda:m,accountCompressionProgram:h}=e.defaultStaticAccountsStruct(),f=re({feePayer:n,authority:r,cpiAuthorityPda:this.deriveCpiAuthorityPda,lightSystemProgram:e.LightSystemProgram.programId,registeredProgramPda:m,noopProgram:p,accountCompressionAuthority:d,accountCompressionProgram:h,selfProgram:this.programId,tokenPoolPda:fe(u),compressOrDecompressTokenAccount:o,tokenProgram:u.tokenProgram,systemProgram:t.SystemProgram.programId});return f.push(...c),new t.TransactionInstruction({programId:this.programId,keys:f,data:l})}static async getMintProgramId(t,e){var n;return null===(n=await e.getAccountInfo(t))||void 0===n?void 0:n.owner}static async approve({payer:n,inputCompressedTokenAccounts:r,toAddress:o,amount:i,recentValidityProof:s,recentInputStateRootIndices:a}){const{inputTokenDataWithContext:u,remainingAccountMetas:c}=Nt({inputCompressedTokenAccounts:r,rootIndices:a,tokenTransferOutputs:[]}),{mint:l,currentOwner:d}=be(r),p=r[0].compressedAccount.treeInfo.treeType===e.TreeType.StateV2?1:0,m=pe({proof:s,mint:l,inputTokenDataWithContext:u,cpiContext:null,delegate:o,delegatedAmount:e.bn(i),delegateMerkleTreeIndex:p,changeAccountMerkleTreeIndex:p,delegateLamports:null}),{accountCompressionAuthority:h,noopProgram:f,registeredProgramPda:g,accountCompressionProgram:y}=e.defaultStaticAccountsStruct(),b=oe({feePayer:n,authority:d,cpiAuthorityPda:this.deriveCpiAuthorityPda,lightSystemProgram:e.LightSystemProgram.programId,registeredProgramPda:g,noopProgram:f,accountCompressionAuthority:h,accountCompressionProgram:y,selfProgram:this.programId,systemProgram:t.SystemProgram.programId});return b.push(...c),new t.TransactionInstruction({programId:this.programId,keys:b,data:m})}static async revoke({payer:n,inputCompressedTokenAccounts:r,recentValidityProof:o,recentInputStateRootIndices:i}){ye(r);const{inputTokenDataWithContext:s,remainingAccountMetas:a}=Nt({inputCompressedTokenAccounts:r,rootIndices:i,tokenTransferOutputs:[]}),{mint:u,currentOwner:c}=be(r),l=me({proof:o,mint:u,inputTokenDataWithContext:s,cpiContext:null,outputAccountMerkleTreeIndex:r[0].compressedAccount.treeInfo.treeType===e.TreeType.StateV2?2:1}),{accountCompressionAuthority:d,noopProgram:p,registeredProgramPda:m,accountCompressionProgram:h}=e.defaultStaticAccountsStruct(),f=ie({feePayer:n,authority:c,cpiAuthorityPda:this.deriveCpiAuthorityPda,lightSystemProgram:e.LightSystemProgram.programId,registeredProgramPda:m,noopProgram:p,accountCompressionAuthority:d,accountCompressionProgram:h,selfProgram:this.programId,systemProgram:t.SystemProgram.programId});return f.push(...a),new t.TransactionInstruction({programId:this.programId,keys:f,data:l})}}function Te(t,n){const r=e.deriveAddressV2(Pe(t)[0].toBytes(),n.tree,e.LIGHT_TOKEN_PROGRAM_ID);return Array.from(r.toBytes())}ve.programId=new t.PublicKey("cTokenmWW8bLPjZEBAUgYy3zKxQZW6VKi7bqNFEVv3m");const ke=w.from([99,111,109,112,114,101,115,115,101,100,95,109,105,110,116]);function Pe(n){const[r,o]=t.PublicKey.findProgramAddressSync([ke,n.toBuffer()],e.LIGHT_TOKEN_PROGRAM_ID);return[r,o]}const Me=w.from([103]),Se=r.struct([r.publicKey("recipient"),r.u64("amount")]),xe=r.struct([r.u8("tokenAccountVersion"),r.vec(Se,"recipients")]),Ce=r.struct([r.option(r.publicKey(),"newAuthority")]),_e=r.struct([r.u8("accountIndex"),r.u64("amount")]),Ee=r.struct([r.u8("extensionIndex"),r.u8("fieldType"),r.vecU8("key"),r.vecU8("value")]),Oe=r.struct([r.u8("extensionIndex"),r.publicKey("newAuthority")]),Re=r.struct([r.u8("extensionIndex"),r.vecU8("key"),r.u8("idempotent")]),Be=r.struct([r.u8("rentPayment"),r.u32("writeTopUp")]),Le=r.struct([r.u8("idempotent")]),De=r.rustEnum([xe.replicate("mintToCompressed"),Ce.replicate("updateMintAuthority"),Ce.replicate("updateFreezeAuthority"),_e.replicate("mintToLightToken"),Ee.replicate("updateMetadataField"),Oe.replicate("updateMetadataAuthority"),Re.replicate("removeMetadataKey"),Be.replicate("decompressMint"),Le.replicate("compressAndCloseCMint")]),Ke=r.struct([r.array(r.u8(),32,"a"),r.array(r.u8(),64,"b"),r.array(r.u8(),32,"c")]),Ue=r.struct([r.bool("setContext"),r.bool("firstSetContext"),r.u8("inTreeIndex"),r.u8("inQueueIndex"),r.u8("outQueueIndex"),r.u8("tokenOutQueueIndex"),r.u8("assignedAccountIndex"),r.array(r.u8(),4,"readOnlyAddressTrees"),r.array(r.u8(),32,"addressTreePubkey")]),Ne=r.struct([r.array(r.u8(),4,"readOnlyAddressTrees"),r.array(r.u16(),4,"readOnlyAddressTreeRootIndices")]),We=r.struct([r.vecU8("key"),r.vecU8("value")]),Ge=r.struct([r.option(r.publicKey(),"updateAuthority"),r.vecU8("name"),r.vecU8("symbol"),r.vecU8("uri"),r.option(r.vec(We),"additionalMetadata")]),qe=r.struct([]),Fe=r.rustEnum([qe.replicate("placeholder0"),qe.replicate("placeholder1"),qe.replicate("placeholder2"),qe.replicate("placeholder3"),qe.replicate("placeholder4"),qe.replicate("placeholder5"),qe.replicate("placeholder6"),qe.replicate("placeholder7"),qe.replicate("placeholder8"),qe.replicate("placeholder9"),qe.replicate("placeholder10"),qe.replicate("placeholder11"),qe.replicate("placeholder12"),qe.replicate("placeholder13"),qe.replicate("placeholder14"),qe.replicate("placeholder15"),qe.replicate("placeholder16"),qe.replicate("placeholder17"),qe.replicate("placeholder18"),Ge.replicate("tokenMetadata")]),Ve=r.struct([r.u8("version"),r.bool("cmintDecompressed"),r.publicKey("mint"),r.array(r.u8(),32,"mintSigner"),r.u8("bump")]),He=r.struct([r.u64("supply"),r.u8("decimals"),Ve.replicate("metadata"),r.option(r.publicKey(),"mintAuthority"),r.option(r.publicKey(),"freezeAuthority"),r.option(r.vec(Fe),"extensions")]),ze=r.struct([r.u32("leafIndex"),r.bool("proveByIndex"),r.u16("rootIndex"),r.u16("maxTopUp"),r.option(Ne,"createMint"),r.vec(De,"actions"),r.option(Ke,"proof"),r.option(Ue,"cpiContext"),r.option(He,"mint")]);function je(t){const n=t.actions.map((t=>"mintToCompressed"in t&&t.mintToCompressed?{mintToCompressed:Object.assign(Object.assign({},t.mintToCompressed),{recipients:t.mintToCompressed.recipients.map((t=>Object.assign(Object.assign({},t),{amount:e.bn(t.amount.toString())})))})}:"mintToLightToken"in t&&t.mintToLightToken?{mintToLightToken:Object.assign(Object.assign({},t.mintToLightToken),{amount:e.bn(t.mintToLightToken.amount.toString())})}:t)),r=w.alloc(1e4),o=Object.assign(Object.assign({},t),{actions:n,mint:t.mint?Object.assign(Object.assign({},t.mint),{supply:e.bn(t.mint.supply.toString())}):null}),i=ze.encode(o,r);return w.concat([Me,r.subarray(0,i)])}function $e(n,r,o,i,s,a,u,c,l,d){return function(n,r,o,i,s,a){const u=e.defaultStaticAccountsStruct(),[c]=Pe(n),l=[{pubkey:e.LightSystemProgram.programId,isSigner:0,isWritable:0},{pubkey:n,isSigner:1,isWritable:0},{pubkey:r,isSigner:1,isWritable:0},{pubkey:ot,isSigner:0,isWritable:0},{pubkey:c,isSigner:0,isWritable:1},{pubkey:it,isSigner:0,isWritable:1},{pubkey:o,isSigner:1,isWritable:1},{pubkey:ve.deriveCpiAuthorityPda,isSigner:0,isWritable:0},{pubkey:u.registeredProgramPda,isSigner:0,isWritable:0},{pubkey:u.accountCompressionAuthority,isSigner:0,isWritable:0},{pubkey:u.accountCompressionProgram,isSigner:0,isWritable:0},{pubkey:t.SystemProgram.programId,isSigner:0,isWritable:0},{pubkey:i.queue,isSigner:0,isWritable:1},{pubkey:s.tree,isSigner:0,isWritable:1}];return new t.TransactionInstruction({programId:e.LIGHT_TOKEN_PROGRAM_ID,keys:l,data:a})}(n,o,s,c,u,function(t){var e,n;const[r,o]=Pe(t.mintSigner);let i=null;t.metadata&&(i=[{tokenMetadata:{updateAuthority:null!==(e=t.metadata.updateAuthority)&&void 0!==e?e:null,name:w.from(t.metadata.name),symbol:w.from(t.metadata.symbol),uri:w.from(t.metadata.uri),additionalMetadata:t.metadata.additionalMetadata}}]);const s=function(t){if(!t)return null;if(32!==t.a.length)throw new Error(`Invalid proof.a length: expected 32, got ${t.a.length}`);if(64!==t.b.length)throw new Error(`Invalid proof.b length: expected 64, got ${t.b.length}`);if(32!==t.c.length)throw new Error(`Invalid proof.c length: expected 32, got ${t.c.length}`);return t}(t.proof);return je({leafIndex:0,proveByIndex:0,rootIndex:t.rootIndex,maxTopUp:null!==(n=t.maxTopUp)&&void 0!==n?n:yt,createMint:{readOnlyAddressTrees:[0,0,0,0],readOnlyAddressTreeRootIndices:[0,0,0,0]},actions:[{decompressMint:{rentPayment:16,writeTopUp:766}}],proof:s,cpiContext:null,mint:{supply:BigInt(0),decimals:t.decimals,metadata:{version:exports.TokenDataVersion.ShaFlat,cmintDecompressed:0,mint:r,mintSigner:Array.from(t.mintSigner.toBytes()),bump:o},mintAuthority:t.mintAuthority,freezeAuthority:t.freezeAuthority,extensions:i}})}({mintSigner:n,mintAuthority:o,freezeAuthority:i,decimals:r,addressTree:u.tree,outputQueue:c.queue,rootIndex:a.rootIndices[0],proof:a.compressedProof,metadata:l,maxTopUp:d}))}function Ye(t){var e,n,r,o;const i="mintAuthority"===t.actionType?{updateMintAuthority:{newAuthority:t.newAuthority}}:{updateFreezeAuthority:{newAuthority:t.newAuthority}},s=null!==(n=null===(e=t.mintInterface.mintContext)||void 0===e?void 0:e.cmintDecompressed)&&void 0!==n?n:0;let a=null;return!s&&t.mintInterface.tokenMetadata&&(a=[{tokenMetadata:{updateAuthority:null!==(r=t.mintInterface.tokenMetadata.updateAuthority)&&void 0!==r?r:null,name:w.from(t.mintInterface.tokenMetadata.name),symbol:w.from(t.mintInterface.tokenMetadata.symbol),uri:w.from(t.mintInterface.tokenMetadata.uri),additionalMetadata:null}}]),je({leafIndex:t.leafIndex,proveByIndex:t.proveByIndex,rootIndex:t.rootIndex,maxTopUp:null!==(o=t.maxTopUp)&&void 0!==o?o:yt,createMint:null,actions:[i],proof:t.proof,cpiContext:null,mint:s?null:{supply:t.mintInterface.mint.supply,decimals:t.mintInterface.mint.decimals,metadata:{version:t.mintInterface.mintContext.version,cmintDecompressed:t.mintInterface.mintContext.cmintDecompressed,mint:t.mintInterface.mintContext.splMint,mintSigner:Array.from(t.mintInterface.mintContext.mintSigner),bump:t.mintInterface.mintContext.bump},mintAuthority:t.mintInterface.mint.mintAuthority,freezeAuthority:t.mintInterface.mint.freezeAuthority,extensions:a}})}function Ze(n,r,o,i,s,a){var u,c,l;if(!n.merkleContext)throw new Error("MintInterface must have merkleContext for light mint operations");if(!n.mintContext)throw new Error("MintInterface must have mintContext for light mint operations");const d=n.merkleContext,p=e.getOutputQueue(d),m=null!==(u=n.mintContext.cmintDecompressed)&&void 0!==u?u:0;e.getDefaultAddressTreeInfo();const h=Ye({leafIndex:d.leafIndex,proveByIndex:1,rootIndex:null!==(c=null==s?void 0:s.rootIndices[0])&&void 0!==c?c:0,proof:m?null:null!==(l=null==s?void 0:s.compressedProof)&&void 0!==l?l:null,mintInterface:n,newAuthority:o,actionType:"mintAuthority",maxTopUp:a}),f=e.defaultStaticAccountsStruct(),g=[{pubkey:e.LightSystemProgram.programId,isSigner:0,isWritable:0},{pubkey:r,isSigner:1,isWritable:0},...m?[{pubkey:n.mint.address,isSigner:0,isWritable:1}]:[],{pubkey:i,isSigner:1,isWritable:1},{pubkey:ve.deriveCpiAuthorityPda,isSigner:0,isWritable:0},{pubkey:f.registeredProgramPda,isSigner:0,isWritable:0},{pubkey:f.accountCompressionAuthority,isSigner:0,isWritable:0},{pubkey:f.accountCompressionProgram,isSigner:0,isWritable:0},{pubkey:t.SystemProgram.programId,isSigner:0,isWritable:0},{pubkey:p,isSigner:0,isWritable:1},{pubkey:d.treeInfo.tree,isSigner:0,isWritable:1},{pubkey:d.treeInfo.queue,isSigner:0,isWritable:1}];return new t.TransactionInstruction({programId:e.LIGHT_TOKEN_PROGRAM_ID,keys:g,data:h})}function Qe(n,r,o,i,s,a){var u,c,l;if(!n.merkleContext)throw new Error("MintInterface must have merkleContext for light mint operations");if(!n.mintContext)throw new Error("MintInterface must have mintContext for light mint operations");const d=n.merkleContext,p=e.getOutputQueue(d),m=null!==(u=n.mintContext.cmintDecompressed)&&void 0!==u?u:0;e.getDefaultAddressTreeInfo();const h=Ye({leafIndex:d.leafIndex,proveByIndex:1,rootIndex:null!==(c=null==s?void 0:s.rootIndices[0])&&void 0!==c?c:0,proof:m?null:null!==(l=null==s?void 0:s.compressedProof)&&void 0!==l?l:null,mintInterface:n,newAuthority:o,actionType:"freezeAuthority",maxTopUp:a}),f=e.defaultStaticAccountsStruct(),g=[{pubkey:e.LightSystemProgram.programId,isSigner:0,isWritable:0},{pubkey:r,isSigner:1,isWritable:0},...m?[{pubkey:n.mint.address,isSigner:0,isWritable:1}]:[],{pubkey:i,isSigner:1,isWritable:1},{pubkey:ve.deriveCpiAuthorityPda,isSigner:0,isWritable:0},{pubkey:f.registeredProgramPda,isSigner:0,isWritable:0},{pubkey:f.accountCompressionAuthority,isSigner:0,isWritable:0},{pubkey:f.accountCompressionProgram,isSigner:0,isWritable:0},{pubkey:t.SystemProgram.programId,isSigner:0,isWritable:0},{pubkey:p,isSigner:0,isWritable:1},{pubkey:d.treeInfo.tree,isSigner:0,isWritable:1},{pubkey:d.treeInfo.queue,isSigner:0,isWritable:1}];return new t.TransactionInstruction({programId:e.LIGHT_TOKEN_PROGRAM_ID,keys:g,data:h})}function Xe(n,r,o,i,s,a){var u,c,l;if(!n.merkleContext)throw new Error("MintInterface must have merkleContext for light mint operations");if(!n.mintContext)throw new Error("MintInterface must have mintContext for light mint operations");if(!n.tokenMetadata)throw new Error("MintInterface must have tokenMetadata for metadata operations");const d=n.merkleContext,p=e.getOutputQueue(d),m=null!==(u=n.mintContext.cmintDecompressed)&&void 0!==u?u:0;e.getDefaultAddressTreeInfo();const h=function(t){var e,n,r,o;const i=t.mintInterface;if(!i.tokenMetadata)throw new Error("MintInterface must have tokenMetadata for metadata operations");const s=null!==(n=null===(e=i.mintContext)||void 0===e?void 0:e.cmintDecompressed)&&void 0!==n?n:0;var a;return je({leafIndex:t.leafIndex,proveByIndex:null===t.proof,rootIndex:t.rootIndex,maxTopUp:null!==(r=t.maxTopUp)&&void 0!==r?r:yt,createMint:null,actions:[(a=t.action,"updateField"===a.type?{updateMetadataField:{extensionIndex:a.extensionIndex,fieldType:a.fieldType,key:w.from(a.key),value:w.from(a.value)}}:"updateAuthority"===a.type?{updateMetadataAuthority:{extensionIndex:a.extensionIndex,newAuthority:a.newAuthority}}:{removeMetadataKey:{extensionIndex:a.extensionIndex,key:w.from(a.key),idempotent:a.idempotent?1:0}})],proof:t.proof,cpiContext:null,mint:s?null:{supply:i.mint.supply,decimals:i.mint.decimals,metadata:{version:i.mintContext.version,cmintDecompressed:i.mintContext.cmintDecompressed,mint:i.mintContext.splMint,mintSigner:Array.from(i.mintContext.mintSigner),bump:i.mintContext.bump},mintAuthority:i.mint.mintAuthority,freezeAuthority:i.mint.freezeAuthority,extensions:[{tokenMetadata:{updateAuthority:null!==(o=i.tokenMetadata.updateAuthority)&&void 0!==o?o:null,name:w.from(i.tokenMetadata.name),symbol:w.from(i.tokenMetadata.symbol),uri:w.from(i.tokenMetadata.uri),additionalMetadata:null}}]}})}({leafIndex:d.leafIndex,rootIndex:null!==(c=null==i?void 0:i.rootIndices[0])&&void 0!==c?c:0,proof:m?null:null!==(l=null==i?void 0:i.compressedProof)&&void 0!==l?l:null,mintInterface:n,action:s,maxTopUp:a}),f=e.defaultStaticAccountsStruct(),g=[{pubkey:e.LightSystemProgram.programId,isSigner:0,isWritable:0},{pubkey:r,isSigner:1,isWritable:0},...m?[{pubkey:n.mint.address,isSigner:0,isWritable:1}]:[],{pubkey:o,isSigner:1,isWritable:1},{pubkey:ve.deriveCpiAuthorityPda,isSigner:0,isWritable:0},{pubkey:f.registeredProgramPda,isSigner:0,isWritable:0},{pubkey:f.accountCompressionAuthority,isSigner:0,isWritable:0},{pubkey:f.accountCompressionProgram,isSigner:0,isWritable:0},{pubkey:t.SystemProgram.programId,isSigner:0,isWritable:0},{pubkey:p,isSigner:0,isWritable:1},{pubkey:d.treeInfo.tree,isSigner:0,isWritable:1},{pubkey:d.treeInfo.queue,isSigner:0,isWritable:1}];return new t.TransactionInstruction({programId:e.LIGHT_TOKEN_PROGRAM_ID,keys:g,data:h})}function Je(t,e,n,r,o,i,s,a=0,u){return Xe(t,e,n,r,{type:"updateField",extensionIndex:a,fieldType:"name"===o?0:"symbol"===o?1:"uri"===o?2:3,key:s||"",value:i},u)}function tn(t,e,n,r,o,i=0,s){return Xe(t,e,r,o,{type:"updateAuthority",extensionIndex:i,newAuthority:n},s)}function en(t,e,n,r,o,i=0,s=0,a){return Xe(t,e,n,r,{type:"removeKey",extensionIndex:s,key:o,idempotent:i},a)}const nn=w.from([100]),rn=w.from([102]),on=r.struct([r.u8("bump"),r.array(r.u8(),32,"programId"),r.vec(r.vec(r.u8()),"seeds")]),sn=r.struct([r.u8("tokenAccountVersion"),r.u8("rentPayment"),r.u8("compressionOnly"),r.u32("writeTopUp"),r.option(on,"compressToAccountPubkey")]),an=r.struct([r.option(sn,"compressibleConfig")]),un={tokenAccountVersion:3,rentPayment:16,compressionOnly:1,writeTopUp:766,compressToAccountPubkey:null};function cn(n,r){return t.PublicKey.findProgramAddressSync([n.toBuffer(),e.LIGHT_TOKEN_PROGRAM_ID.toBuffer(),r.toBuffer()],e.LIGHT_TOKEN_PROGRAM_ID)[0]}function ln(t,e){const n=w.alloc(2e3),r=an.encode({compressibleConfig:t.compressibleConfig||null},n),o=e?rn:nn;return w.concat([o,n.subarray(0,r)])}function dn(n,r,o,i=un,s=ot,a=it){const u=cn(r,o),c=ln({compressibleConfig:i},0),l=[{pubkey:r,isSigner:0,isWritable:0},{pubkey:o,isSigner:0,isWritable:0},{pubkey:n,isSigner:1,isWritable:1},{pubkey:u,isSigner:0,isWritable:1},{pubkey:t.SystemProgram.programId,isSigner:0,isWritable:0}];return i&&l.push({pubkey:s,isSigner:0,isWritable:0},{pubkey:a,isSigner:0,isWritable:1}),new t.TransactionInstruction({programId:e.LIGHT_TOKEN_PROGRAM_ID,keys:l,data:c})}function pn(n,r,o,i=un,s=ot,a=it){const u=cn(r,o),c=ln({compressibleConfig:i},1),l=[{pubkey:r,isSigner:0,isWritable:0},{pubkey:o,isSigner:0,isWritable:0},{pubkey:n,isSigner:1,isWritable:1},{pubkey:u,isSigner:0,isWritable:1},{pubkey:t.SystemProgram.programId,isSigner:0,isWritable:0}];return i&&l.push({pubkey:s,isSigner:0,isWritable:0},{pubkey:a,isSigner:0,isWritable:1}),new t.TransactionInstruction({programId:e.LIGHT_TOKEN_PROGRAM_ID,keys:l,data:c})}function mn(t){return t.equals(e.LIGHT_TOKEN_PROGRAM_ID)?e.LIGHT_TOKEN_PROGRAM_ID:n.ASSOCIATED_TOKEN_PROGRAM_ID}function hn(t,r,o,i,s=0){if(i){const e=n.getAssociatedTokenAddressSync(r,o,s,i,mn(i));if(t.equals(e))return{valid:1,type:fn(i),programId:i};throw new Error(`ATA address mismatch for ${i.toBase58()}. Expected: ${e.toBase58()}, got: ${t.toBase58()}`)}let a,u,c;if(a=n.getAssociatedTokenAddressSync(r,o,s,e.LIGHT_TOKEN_PROGRAM_ID,mn(e.LIGHT_TOKEN_PROGRAM_ID)),t.equals(a))return{valid:1,type:"light-token",programId:e.LIGHT_TOKEN_PROGRAM_ID};if(u=n.getAssociatedTokenAddressSync(r,o,s,n.TOKEN_PROGRAM_ID,mn(n.TOKEN_PROGRAM_ID)),t.equals(u))return{valid:1,type:"spl",programId:n.TOKEN_PROGRAM_ID};if(c=n.getAssociatedTokenAddressSync(r,o,s,n.TOKEN_2022_PROGRAM_ID,mn(n.TOKEN_2022_PROGRAM_ID)),t.equals(c))return{valid:1,type:"token2022",programId:n.TOKEN_2022_PROGRAM_ID};throw new Error(`ATA address does not match any valid derivation from mint+owner. Got: ${t.toBase58()}, expected one of: light-token=${a.toBase58()}, SPL=${u.toBase58()}, T22=${c.toBase58()}`)}function fn(t){if(t.equals(e.LIGHT_TOKEN_PROGRAM_ID))return"light-token";if(t.equals(n.TOKEN_PROGRAM_ID))return"spl";if(t.equals(n.TOKEN_2022_PROGRAM_ID))return"token2022";throw new Error(`Unknown program ID: ${t.toBase58()}`)}function gn(t,r,o,i,s=n.TOKEN_PROGRAM_ID,a,u){const c=null!=a?a:mn(s);return s.equals(e.LIGHT_TOKEN_PROGRAM_ID)?dn(t,o,i,null==u?void 0:u.compressibleConfig,null==u?void 0:u.configAccount,null==u?void 0:u.rentPayerPda):n.createAssociatedTokenAccountInstruction(t,r,o,i,s,c)}function yn(t,r,o,i,s=n.TOKEN_PROGRAM_ID,a,u){const c=null!=a?a:mn(s);return s.equals(e.LIGHT_TOKEN_PROGRAM_ID)?pn(t,o,i,null==u?void 0:u.compressibleConfig,null==u?void 0:u.configAccount,null==u?void 0:u.rentPayerPda):n.createAssociatedTokenAccountIdempotentInstruction(t,r,o,i,s,c)}const bn=yn;var wn="undefined"!=typeof globalThis?globalThis:"undefined"!=typeof window?window:"undefined"!=typeof global?global:"undefined"!=typeof self?self:{};function In(t){return t&&t.__esModule&&Object.prototype.hasOwnProperty.call(t,"default")?t.default:t}function An(t){if(t.__esModule)return t;var e=t.default;if("function"==typeof e){var n=function t(){return this instanceof t?Reflect.construct(e,arguments,this.constructor):e.apply(this,arguments)};n.prototype=e.prototype}else n={};return Object.defineProperty(n,"__esModule",{value:1}),Object.keys(t).forEach((function(e){var r=Object.getOwnPropertyDescriptor(t,e);Object.defineProperty(n,e,r.get?r:{enumerable:1,get:function(){return t[e]}})})),n}var vn={exports:{}},Tn=An(rt);!function(t,e){function n(t,e){if(!t)throw new Error(e||"Assertion failed")}function r(t,e){t.super_=e;var n=function(){};n.prototype=e.prototype,t.prototype=new n,t.prototype.constructor=t}function o(t,e,n){if(o.isBN(t))return t;this.negative=0,this.words=null,this.length=0,this.red=null,null!==t&&("le"!==e&&"be"!==e||(n=e,e=10),this._init(t||0,e||10,n||"be"))}var i;"object"==typeof vn?vn.exports=o:e.BN=o,o.BN=o,o.wordSize=26;try{i="undefined"!=typeof window&&void 0!==window.Buffer?window.Buffer:Tn.Buffer}catch(t){}function s(t,e){var r=t.charCodeAt(e);return r>=48&&r<=57?r-48:r>=65&&r<=70?r-55:r>=97&&r<=102?r-87:void n(0,"Invalid character in "+t)}function a(t,e,n){var r=s(t,n);return n-1>=e&&(r|=s(t,n-1)<<4),r}function u(t,e,r,o){for(var i=0,s=0,a=Math.min(t.length,r),u=e;u<a;u++){var c=t.charCodeAt(u)-48;i*=o,s=c>=49?c-49+10:c>=17?c-17+10:c,n(c>=0&&s<o,"Invalid character"),i+=s}return i}function c(t,e){t.words=e.words,t.length=e.length,t.negative=e.negative,t.red=e.red}if(o.isBN=function(t){return t instanceof o?1:null!==t&&"object"==typeof t&&t.constructor.wordSize===o.wordSize&&Array.isArray(t.words)},o.max=function(t,e){return t.cmp(e)>0?t:e},o.min=function(t,e){return t.cmp(e)<0?t:e},o.prototype._init=function(t,e,r){if("number"==typeof t)return this._initNumber(t,e,r);if("object"==typeof t)return this._initArray(t,e,r);"hex"===e&&(e=16),n(e===(0|e)&&e>=2&&e<=36);var o=0;"-"===(t=t.toString().replace(/\s+/g,""))[0]&&(o++,this.negative=1),o<t.length&&(16===e?this._parseHex(t,o,r):(this._parseBase(t,e,o),"le"===r&&this._initArray(this.toArray(),e,r)))},o.prototype._initNumber=function(t,e,r){t<0&&(this.negative=1,t=-t),t<67108864?(this.words=[67108863&t],this.length=1):t<4503599627370496?(this.words=[67108863&t,t/67108864&67108863],this.length=2):(n(t<9007199254740992),this.words=[67108863&t,t/67108864&67108863,1],this.length=3),"le"===r&&this._initArray(this.toArray(),e,r)},o.prototype._initArray=function(t,e,r){if(n("number"==typeof t.length),t.length<=0)return this.words=[0],this.length=1,this;this.length=Math.ceil(t.length/3),this.words=new Array(this.length);for(var o=0;o<this.length;o++)this.words[o]=0;var i,s,a=0;if("be"===r)for(o=t.length-1,i=0;o>=0;o-=3)s=t[o]|t[o-1]<<8|t[o-2]<<16,this.words[i]|=s<<a&67108863,this.words[i+1]=s>>>26-a&67108863,(a+=24)>=26&&(a-=26,i++);else if("le"===r)for(o=0,i=0;o<t.length;o+=3)s=t[o]|t[o+1]<<8|t[o+2]<<16,this.words[i]|=s<<a&67108863,this.words[i+1]=s>>>26-a&67108863,(a+=24)>=26&&(a-=26,i++);return this._strip()},o.prototype._parseHex=function(t,e,n){this.length=Math.ceil((t.length-e)/6),this.words=new Array(this.length);for(var r=0;r<this.length;r++)this.words[r]=0;var o,i=0,s=0;if("be"===n)for(r=t.length-1;r>=e;r-=2)o=a(t,e,r)<<i,this.words[s]|=67108863&o,i>=18?(i-=18,s+=1,this.words[s]|=o>>>26):i+=8;else for(r=(t.length-e)%2==0?e+1:e;r<t.length;r+=2)o=a(t,e,r)<<i,this.words[s]|=67108863&o,i>=18?(i-=18,s+=1,this.words[s]|=o>>>26):i+=8;this._strip()},o.prototype._parseBase=function(t,e,n){this.words=[0],this.length=1;for(var r=0,o=1;o<=67108863;o*=e)r++;r--,o=o/e|0;for(var i=t.length-n,s=i%r,a=Math.min(i,i-s)+n,c=0,l=n;l<a;l+=r)c=u(t,l,l+r,e),this.imuln(o),this.words[0]+c<67108864?this.words[0]+=c:this._iaddn(c);if(0!==s){var d=1;for(c=u(t,l,t.length,e),l=0;l<s;l++)d*=e;this.imuln(d),this.words[0]+c<67108864?this.words[0]+=c:this._iaddn(c)}this._strip()},o.prototype.copy=function(t){t.words=new Array(this.length);for(var e=0;e<this.length;e++)t.words[e]=this.words[e];t.length=this.length,t.negative=this.negative,t.red=this.red},o.prototype._move=function(t){c(t,this)},o.prototype.clone=function(){var t=new o(null);return this.copy(t),t},o.prototype._expand=function(t){for(;this.length<t;)this.words[this.length++]=0;return this},o.prototype._strip=function(){for(;this.length>1&&0===this.words[this.length-1];)this.length--;return this._normSign()},o.prototype._normSign=function(){return 1===this.length&&0===this.words[0]&&(this.negative=0),this},"undefined"!=typeof Symbol&&"function"==typeof Symbol.for)try{o.prototype[Symbol.for("nodejs.util.inspect.custom")]=l}catch(t){o.prototype.inspect=l}else o.prototype.inspect=l;function l(){return(this.red?"<BN-R: ":"<BN: ")+this.toString(16)+">"}var d=["","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"],p=[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],m=[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];function h(t,e,n){n.negative=e.negative^t.negative;var r=t.length+e.length|0;n.length=r,r=r-1|0;var o=0|t.words[0],i=0|e.words[0],s=o*i,a=67108863&s,u=s/67108864|0;n.words[0]=a;for(var c=1;c<r;c++){for(var l=u>>>26,d=67108863&u,p=Math.min(c,e.length-1),m=Math.max(0,c-t.length+1);m<=p;m++){var h=c-m|0;l+=(s=(o=0|t.words[h])*(i=0|e.words[m])+d)/67108864|0,d=67108863&s}n.words[c]=0|d,u=0|l}return 0!==u?n.words[c]=0|u:n.length--,n._strip()}o.prototype.toString=function(t,e){var r;if(e=0|e||1,16===(t=t||10)||"hex"===t){r="";for(var o=0,i=0,s=0;s<this.length;s++){var a=this.words[s],u=(16777215&(a<<o|i)).toString(16);i=a>>>24-o&16777215,(o+=2)>=26&&(o-=26,s--),r=0!==i||s!==this.length-1?d[6-u.length]+u+r:u+r}for(0!==i&&(r=i.toString(16)+r);r.length%e!=0;)r="0"+r;return 0!==this.negative&&(r="-"+r),r}if(t===(0|t)&&t>=2&&t<=36){var c=p[t],l=m[t];r="";var h=this.clone();for(h.negative=0;!h.isZero();){var f=h.modrn(l).toString(t);r=(h=h.idivn(l)).isZero()?f+r:d[c-f.length]+f+r}for(this.isZero()&&(r="0"+r);r.length%e!=0;)r="0"+r;return 0!==this.negative&&(r="-"+r),r}n(0,"Base should be between 2 and 36")},o.prototype.toNumber=function(){var t=this.words[0];return 2===this.length?t+=67108864*this.words[1]:3===this.length&&1===this.words[2]?t+=4503599627370496+67108864*this.words[1]:this.length>2&&n(0,"Number can only safely store up to 53 bits"),0!==this.negative?-t:t},o.prototype.toJSON=function(){return this.toString(16,2)},i&&(o.prototype.toBuffer=function(t,e){return this.toArrayLike(i,t,e)}),o.prototype.toArray=function(t,e){return this.toArrayLike(Array,t,e)},o.prototype.toArrayLike=function(t,e,r){this._strip();var o=this.byteLength(),i=r||Math.max(1,o);n(o<=i,"byte array longer than desired length"),n(i>0,"Requested array length <= 0");var s=function(t,e){return t.allocUnsafe?t.allocUnsafe(e):new t(e)}(t,i);return this["_toArrayLike"+("le"===e?"LE":"BE")](s,o),s},o.prototype._toArrayLikeLE=function(t){for(var e=0,n=0,r=0,o=0;r<this.length;r++){var i=this.words[r]<<o|n;t[e++]=255&i,e<t.length&&(t[e++]=i>>8&255),e<t.length&&(t[e++]=i>>16&255),6===o?(e<t.length&&(t[e++]=i>>24&255),n=0,o=0):(n=i>>>24,o+=2)}if(e<t.length)for(t[e++]=n;e<t.length;)t[e++]=0},o.prototype._toArrayLikeBE=function(t){for(var e=t.length-1,n=0,r=0,o=0;r<this.length;r++){var i=this.words[r]<<o|n;t[e--]=255&i,e>=0&&(t[e--]=i>>8&255),e>=0&&(t[e--]=i>>16&255),6===o?(e>=0&&(t[e--]=i>>24&255),n=0,o=0):(n=i>>>24,o+=2)}if(e>=0)for(t[e--]=n;e>=0;)t[e--]=0},Math.clz32?o.prototype._countBits=function(t){return 32-Math.clz32(t)}:o.prototype._countBits=function(t){var e=t,n=0;return e>=4096&&(n+=13,e>>>=13),e>=64&&(n+=7,e>>>=7),e>=8&&(n+=4,e>>>=4),e>=2&&(n+=2,e>>>=2),n+e},o.prototype._zeroBits=function(t){if(0===t)return 26;var e=t,n=0;return 0==(8191&e)&&(n+=13,e>>>=13),0==(127&e)&&(n+=7,e>>>=7),0==(15&e)&&(n+=4,e>>>=4),0==(3&e)&&(n+=2,e>>>=2),0==(1&e)&&n++,n},o.prototype.bitLength=function(){var t=this.words[this.length-1],e=this._countBits(t);return 26*(this.length-1)+e},o.prototype.zeroBits=function(){if(this.isZero())return 0;for(var t=0,e=0;e<this.length;e++){var n=this._zeroBits(this.words[e]);if(t+=n,26!==n)break}return t},o.prototype.byteLength=function(){return Math.ceil(this.bitLength()/8)},o.prototype.toTwos=function(t){return 0!==this.negative?this.abs().inotn(t).iaddn(1):this.clone()},o.prototype.fromTwos=function(t){return this.testn(t-1)?this.notn(t).iaddn(1).ineg():this.clone()},o.prototype.isNeg=function(){return 0!==this.negative},o.prototype.neg=function(){return this.clone().ineg()},o.prototype.ineg=function(){return this.isZero()||(this.negative^=1),this},o.prototype.iuor=function(t){for(;this.length<t.length;)this.words[this.length++]=0;for(var e=0;e<t.length;e++)this.words[e]=this.words[e]|t.words[e];return this._strip()},o.prototype.ior=function(t){return n(0==(this.negative|t.negative)),this.iuor(t)},o.prototype.or=function(t){return this.length>t.length?this.clone().ior(t):t.clone().ior(this)},o.prototype.uor=function(t){return this.length>t.length?this.clone().iuor(t):t.clone().iuor(this)},o.prototype.iuand=function(t){var e;e=this.length>t.length?t:this;for(var n=0;n<e.length;n++)this.words[n]=this.words[n]&t.words[n];return this.length=e.length,this._strip()},o.prototype.iand=function(t){return n(0==(this.negative|t.negative)),this.iuand(t)},o.prototype.and=function(t){return this.length>t.length?this.clone().iand(t):t.clone().iand(this)},o.prototype.uand=function(t){return this.length>t.length?this.clone().iuand(t):t.clone().iuand(this)},o.prototype.iuxor=function(t){var e,n;this.length>t.length?(e=this,n=t):(e=t,n=this);for(var r=0;r<n.length;r++)this.words[r]=e.words[r]^n.words[r];if(this!==e)for(;r<e.length;r++)this.words[r]=e.words[r];return this.length=e.length,this._strip()},o.prototype.ixor=function(t){return n(0==(this.negative|t.negative)),this.iuxor(t)},o.prototype.xor=function(t){return this.length>t.length?this.clone().ixor(t):t.clone().ixor(this)},o.prototype.uxor=function(t){return this.length>t.length?this.clone().iuxor(t):t.clone().iuxor(this)},o.prototype.inotn=function(t){n("number"==typeof t&&t>=0);var e=0|Math.ceil(t/26),r=t%26;this._expand(e),r>0&&e--;for(var o=0;o<e;o++)this.words[o]=67108863&~this.words[o];return r>0&&(this.words[o]=~this.words[o]&67108863>>26-r),this._strip()},o.prototype.notn=function(t){return this.clone().inotn(t)},o.prototype.setn=function(t,e){n("number"==typeof t&&t>=0);var r=t/26|0,o=t%26;return this._expand(r+1),this.words[r]=e?this.words[r]|1<<o:this.words[r]&~(1<<o),this._strip()},o.prototype.iadd=function(t){var e,n,r;if(0!==this.negative&&0===t.negative)return this.negative=0,e=this.isub(t),this.negative^=1,this._normSign();if(0===this.negative&&0!==t.negative)return t.negative=0,e=this.isub(t),t.negative=1,e._normSign();this.length>t.length?(n=this,r=t):(n=t,r=this);for(var o=0,i=0;i<r.length;i++)e=(0|n.words[i])+(0|r.words[i])+o,this.words[i]=67108863&e,o=e>>>26;for(;0!==o&&i<n.length;i++)e=(0|n.words[i])+o,this.words[i]=67108863&e,o=e>>>26;if(this.length=n.length,0!==o)this.words[this.length]=o,this.length++;else if(n!==this)for(;i<n.length;i++)this.words[i]=n.words[i];return this},o.prototype.add=function(t){var e;return 0!==t.negative&&0===this.negative?(t.negative=0,e=this.sub(t),t.negative^=1,e):0===t.negative&&0!==this.negative?(this.negative=0,e=t.sub(this),this.negative=1,e):this.length>t.length?this.clone().iadd(t):t.clone().iadd(this)},o.prototype.isub=function(t){if(0!==t.negative){t.negative=0;var e=this.iadd(t);return t.negative=1,e._normSign()}if(0!==this.negative)return this.negative=0,this.iadd(t),this.negative=1,this._normSign();var n,r,o=this.cmp(t);if(0===o)return this.negative=0,this.length=1,this.words[0]=0,this;o>0?(n=this,r=t):(n=t,r=this);for(var i=0,s=0;s<r.length;s++)i=(e=(0|n.words[s])-(0|r.words[s])+i)>>26,this.words[s]=67108863&e;for(;0!==i&&s<n.length;s++)i=(e=(0|n.words[s])+i)>>26,this.words[s]=67108863&e;if(0===i&&s<n.length&&n!==this)for(;s<n.length;s++)this.words[s]=n.words[s];return this.length=Math.max(this.length,s),n!==this&&(this.negative=1),this._strip()},o.prototype.sub=function(t){return this.clone().isub(t)};var f=function(t,e,n){var r,o,i,s=t.words,a=e.words,u=n.words,c=0,l=0|s[0],d=8191&l,p=l>>>13,m=0|s[1],h=8191&m,f=m>>>13,g=0|s[2],y=8191&g,b=g>>>13,w=0|s[3],I=8191&w,A=w>>>13,v=0|s[4],T=8191&v,k=v>>>13,P=0|s[5],M=8191&P,S=P>>>13,x=0|s[6],C=8191&x,_=x>>>13,E=0|s[7],O=8191&E,R=E>>>13,B=0|s[8],L=8191&B,D=B>>>13,K=0|s[9],U=8191&K,N=K>>>13,W=0|a[0],G=8191&W,q=W>>>13,F=0|a[1],V=8191&F,H=F>>>13,z=0|a[2],j=8191&z,$=z>>>13,Y=0|a[3],Z=8191&Y,Q=Y>>>13,X=0|a[4],J=8191&X,tt=X>>>13,et=0|a[5],nt=8191&et,rt=et>>>13,ot=0|a[6],it=8191&ot,st=ot>>>13,at=0|a[7],ut=8191&at,ct=at>>>13,lt=0|a[8],dt=8191&lt,pt=lt>>>13,mt=0|a[9],ht=8191&mt,ft=mt>>>13;n.negative=t.negative^e.negative,n.length=19;var gt=(c+(r=Math.imul(d,G))|0)+((8191&(o=(o=Math.imul(d,q))+Math.imul(p,G)|0))<<13)|0;c=((i=Math.imul(p,q))+(o>>>13)|0)+(gt>>>26)|0,gt&=67108863,r=Math.imul(h,G),o=(o=Math.imul(h,q))+Math.imul(f,G)|0,i=Math.imul(f,q);var yt=(c+(r=r+Math.imul(d,V)|0)|0)+((8191&(o=(o=o+Math.imul(d,H)|0)+Math.imul(p,V)|0))<<13)|0;c=((i=i+Math.imul(p,H)|0)+(o>>>13)|0)+(yt>>>26)|0,yt&=67108863,r=Math.imul(y,G),o=(o=Math.imul(y,q))+Math.imul(b,G)|0,i=Math.imul(b,q),r=r+Math.imul(h,V)|0,o=(o=o+Math.imul(h,H)|0)+Math.imul(f,V)|0,i=i+Math.imul(f,H)|0;var bt=(c+(r=r+Math.imul(d,j)|0)|0)+((8191&(o=(o=o+Math.imul(d,$)|0)+Math.imul(p,j)|0))<<13)|0;c=((i=i+Math.imul(p,$)|0)+(o>>>13)|0)+(bt>>>26)|0,bt&=67108863,r=Math.imul(I,G),o=(o=Math.imul(I,q))+Math.imul(A,G)|0,i=Math.imul(A,q),r=r+Math.imul(y,V)|0,o=(o=o+Math.imul(y,H)|0)+Math.imul(b,V)|0,i=i+Math.imul(b,H)|0,r=r+Math.imul(h,j)|0,o=(o=o+Math.imul(h,$)|0)+Math.imul(f,j)|0,i=i+Math.imul(f,$)|0;var wt=(c+(r=r+Math.imul(d,Z)|0)|0)+((8191&(o=(o=o+Math.imul(d,Q)|0)+Math.imul(p,Z)|0))<<13)|0;c=((i=i+Math.imul(p,Q)|0)+(o>>>13)|0)+(wt>>>26)|0,wt&=67108863,r=Math.imul(T,G),o=(o=Math.imul(T,q))+Math.imul(k,G)|0,i=Math.imul(k,q),r=r+Math.imul(I,V)|0,o=(o=o+Math.imul(I,H)|0)+Math.imul(A,V)|0,i=i+Math.imul(A,H)|0,r=r+Math.imul(y,j)|0,o=(o=o+Math.imul(y,$)|0)+Math.imul(b,j)|0,i=i+Math.imul(b,$)|0,r=r+Math.imul(h,Z)|0,o=(o=o+Math.imul(h,Q)|0)+Math.imul(f,Z)|0,i=i+Math.imul(f,Q)|0;var It=(c+(r=r+Math.imul(d,J)|0)|0)+((8191&(o=(o=o+Math.imul(d,tt)|0)+Math.imul(p,J)|0))<<13)|0;c=((i=i+Math.imul(p,tt)|0)+(o>>>13)|0)+(It>>>26)|0,It&=67108863,r=Math.imul(M,G),o=(o=Math.imul(M,q))+Math.imul(S,G)|0,i=Math.imul(S,q),r=r+Math.imul(T,V)|0,o=(o=o+Math.imul(T,H)|0)+Math.imul(k,V)|0,i=i+Math.imul(k,H)|0,r=r+Math.imul(I,j)|0,o=(o=o+Math.imul(I,$)|0)+Math.imul(A,j)|0,i=i+Math.imul(A,$)|0,r=r+Math.imul(y,Z)|0,o=(o=o+Math.imul(y,Q)|0)+Math.imul(b,Z)|0,i=i+Math.imul(b,Q)|0,r=r+Math.imul(h,J)|0,o=(o=o+Math.imul(h,tt)|0)+Math.imul(f,J)|0,i=i+Math.imul(f,tt)|0;var At=(c+(r=r+Math.imul(d,nt)|0)|0)+((8191&(o=(o=o+Math.imul(d,rt)|0)+Math.imul(p,nt)|0))<<13)|0;c=((i=i+Math.imul(p,rt)|0)+(o>>>13)|0)+(At>>>26)|0,At&=67108863,r=Math.imul(C,G),o=(o=Math.imul(C,q))+Math.imul(_,G)|0,i=Math.imul(_,q),r=r+Math.imul(M,V)|0,o=(o=o+Math.imul(M,H)|0)+Math.imul(S,V)|0,i=i+Math.imul(S,H)|0,r=r+Math.imul(T,j)|0,o=(o=o+Math.imul(T,$)|0)+Math.imul(k,j)|0,i=i+Math.imul(k,$)|0,r=r+Math.imul(I,Z)|0,o=(o=o+Math.imul(I,Q)|0)+Math.imul(A,Z)|0,i=i+Math.imul(A,Q)|0,r=r+Math.imul(y,J)|0,o=(o=o+Math.imul(y,tt)|0)+Math.imul(b,J)|0,i=i+Math.imul(b,tt)|0,r=r+Math.imul(h,nt)|0,o=(o=o+Math.imul(h,rt)|0)+Math.imul(f,nt)|0,i=i+Math.imul(f,rt)|0;var vt=(c+(r=r+Math.imul(d,it)|0)|0)+((8191&(o=(o=o+Math.imul(d,st)|0)+Math.imul(p,it)|0))<<13)|0;c=((i=i+Math.imul(p,st)|0)+(o>>>13)|0)+(vt>>>26)|0,vt&=67108863,r=Math.imul(O,G),o=(o=Math.imul(O,q))+Math.imul(R,G)|0,i=Math.imul(R,q),r=r+Math.imul(C,V)|0,o=(o=o+Math.imul(C,H)|0)+Math.imul(_,V)|0,i=i+Math.imul(_,H)|0,r=r+Math.imul(M,j)|0,o=(o=o+Math.imul(M,$)|0)+Math.imul(S,j)|0,i=i+Math.imul(S,$)|0,r=r+Math.imul(T,Z)|0,o=(o=o+Math.imul(T,Q)|0)+Math.imul(k,Z)|0,i=i+Math.imul(k,Q)|0,r=r+Math.imul(I,J)|0,o=(o=o+Math.imul(I,tt)|0)+Math.imul(A,J)|0,i=i+Math.imul(A,tt)|0,r=r+Math.imul(y,nt)|0,o=(o=o+Math.imul(y,rt)|0)+Math.imul(b,nt)|0,i=i+Math.imul(b,rt)|0,r=r+Math.imul(h,it)|0,o=(o=o+Math.imul(h,st)|0)+Math.imul(f,it)|0,i=i+Math.imul(f,st)|0;var Tt=(c+(r=r+Math.imul(d,ut)|0)|0)+((8191&(o=(o=o+Math.imul(d,ct)|0)+Math.imul(p,ut)|0))<<13)|0;c=((i=i+Math.imul(p,ct)|0)+(o>>>13)|0)+(Tt>>>26)|0,Tt&=67108863,r=Math.imul(L,G),o=(o=Math.imul(L,q))+Math.imul(D,G)|0,i=Math.imul(D,q),r=r+Math.imul(O,V)|0,o=(o=o+Math.imul(O,H)|0)+Math.imul(R,V)|0,i=i+Math.imul(R,H)|0,r=r+Math.imul(C,j)|0,o=(o=o+Math.imul(C,$)|0)+Math.imul(_,j)|0,i=i+Math.imul(_,$)|0,r=r+Math.imul(M,Z)|0,o=(o=o+Math.imul(M,Q)|0)+Math.imul(S,Z)|0,i=i+Math.imul(S,Q)|0,r=r+Math.imul(T,J)|0,o=(o=o+Math.imul(T,tt)|0)+Math.imul(k,J)|0,i=i+Math.imul(k,tt)|0,r=r+Math.imul(I,nt)|0,o=(o=o+Math.imul(I,rt)|0)+Math.imul(A,nt)|0,i=i+Math.imul(A,rt)|0,r=r+Math.imul(y,it)|0,o=(o=o+Math.imul(y,st)|0)+Math.imul(b,it)|0,i=i+Math.imul(b,st)|0,r=r+Math.imul(h,ut)|0,o=(o=o+Math.imul(h,ct)|0)+Math.imul(f,ut)|0,i=i+Math.imul(f,ct)|0;var kt=(c+(r=r+Math.imul(d,dt)|0)|0)+((8191&(o=(o=o+Math.imul(d,pt)|0)+Math.imul(p,dt)|0))<<13)|0;c=((i=i+Math.imul(p,pt)|0)+(o>>>13)|0)+(kt>>>26)|0,kt&=67108863,r=Math.imul(U,G),o=(o=Math.imul(U,q))+Math.imul(N,G)|0,i=Math.imul(N,q),r=r+Math.imul(L,V)|0,o=(o=o+Math.imul(L,H)|0)+Math.imul(D,V)|0,i=i+Math.imul(D,H)|0,r=r+Math.imul(O,j)|0,o=(o=o+Math.imul(O,$)|0)+Math.imul(R,j)|0,i=i+Math.imul(R,$)|0,r=r+Math.imul(C,Z)|0,o=(o=o+Math.imul(C,Q)|0)+Math.imul(_,Z)|0,i=i+Math.imul(_,Q)|0,r=r+Math.imul(M,J)|0,o=(o=o+Math.imul(M,tt)|0)+Math.imul(S,J)|0,i=i+Math.imul(S,tt)|0,r=r+Math.imul(T,nt)|0,o=(o=o+Math.imul(T,rt)|0)+Math.imul(k,nt)|0,i=i+Math.imul(k,rt)|0,r=r+Math.imul(I,it)|0,o=(o=o+Math.imul(I,st)|0)+Math.imul(A,it)|0,i=i+Math.imul(A,st)|0,r=r+Math.imul(y,ut)|0,o=(o=o+Math.imul(y,ct)|0)+Math.imul(b,ut)|0,i=i+Math.imul(b,ct)|0,r=r+Math.imul(h,dt)|0,o=(o=o+Math.imul(h,pt)|0)+Math.imul(f,dt)|0,i=i+Math.imul(f,pt)|0;var Pt=(c+(r=r+Math.imul(d,ht)|0)|0)+((8191&(o=(o=o+Math.imul(d,ft)|0)+Math.imul(p,ht)|0))<<13)|0;c=((i=i+Math.imul(p,ft)|0)+(o>>>13)|0)+(Pt>>>26)|0,Pt&=67108863,r=Math.imul(U,V),o=(o=Math.imul(U,H))+Math.imul(N,V)|0,i=Math.imul(N,H),r=r+Math.imul(L,j)|0,o=(o=o+Math.imul(L,$)|0)+Math.imul(D,j)|0,i=i+Math.imul(D,$)|0,r=r+Math.imul(O,Z)|0,o=(o=o+Math.imul(O,Q)|0)+Math.imul(R,Z)|0,i=i+Math.imul(R,Q)|0,r=r+Math.imul(C,J)|0,o=(o=o+Math.imul(C,tt)|0)+Math.imul(_,J)|0,i=i+Math.imul(_,tt)|0,r=r+Math.imul(M,nt)|0,o=(o=o+Math.imul(M,rt)|0)+Math.imul(S,nt)|0,i=i+Math.imul(S,rt)|0,r=r+Math.imul(T,it)|0,o=(o=o+Math.imul(T,st)|0)+Math.imul(k,it)|0,i=i+Math.imul(k,st)|0,r=r+Math.imul(I,ut)|0,o=(o=o+Math.imul(I,ct)|0)+Math.imul(A,ut)|0,i=i+Math.imul(A,ct)|0,r=r+Math.imul(y,dt)|0,o=(o=o+Math.imul(y,pt)|0)+Math.imul(b,dt)|0,i=i+Math.imul(b,pt)|0;var Mt=(c+(r=r+Math.imul(h,ht)|0)|0)+((8191&(o=(o=o+Math.imul(h,ft)|0)+Math.imul(f,ht)|0))<<13)|0;c=((i=i+Math.imul(f,ft)|0)+(o>>>13)|0)+(Mt>>>26)|0,Mt&=67108863,r=Math.imul(U,j),o=(o=Math.imul(U,$))+Math.imul(N,j)|0,i=Math.imul(N,$),r=r+Math.imul(L,Z)|0,o=(o=o+Math.imul(L,Q)|0)+Math.imul(D,Z)|0,i=i+Math.imul(D,Q)|0,r=r+Math.imul(O,J)|0,o=(o=o+Math.imul(O,tt)|0)+Math.imul(R,J)|0,i=i+Math.imul(R,tt)|0,r=r+Math.imul(C,nt)|0,o=(o=o+Math.imul(C,rt)|0)+Math.imul(_,nt)|0,i=i+Math.imul(_,rt)|0,r=r+Math.imul(M,it)|0,o=(o=o+Math.imul(M,st)|0)+Math.imul(S,it)|0,i=i+Math.imul(S,st)|0,r=r+Math.imul(T,ut)|0,o=(o=o+Math.imul(T,ct)|0)+Math.imul(k,ut)|0,i=i+Math.imul(k,ct)|0,r=r+Math.imul(I,dt)|0,o=(o=o+Math.imul(I,pt)|0)+Math.imul(A,dt)|0,i=i+Math.imul(A,pt)|0;var St=(c+(r=r+Math.imul(y,ht)|0)|0)+((8191&(o=(o=o+Math.imul(y,ft)|0)+Math.imul(b,ht)|0))<<13)|0;c=((i=i+Math.imul(b,ft)|0)+(o>>>13)|0)+(St>>>26)|0,St&=67108863,r=Math.imul(U,Z),o=(o=Math.imul(U,Q))+Math.imul(N,Z)|0,i=Math.imul(N,Q),r=r+Math.imul(L,J)|0,o=(o=o+Math.imul(L,tt)|0)+Math.imul(D,J)|0,i=i+Math.imul(D,tt)|0,r=r+Math.imul(O,nt)|0,o=(o=o+Math.imul(O,rt)|0)+Math.imul(R,nt)|0,i=i+Math.imul(R,rt)|0,r=r+Math.imul(C,it)|0,o=(o=o+Math.imul(C,st)|0)+Math.imul(_,it)|0,i=i+Math.imul(_,st)|0,r=r+Math.imul(M,ut)|0,o=(o=o+Math.imul(M,ct)|0)+Math.imul(S,ut)|0,i=i+Math.imul(S,ct)|0,r=r+Math.imul(T,dt)|0,o=(o=o+Math.imul(T,pt)|0)+Math.imul(k,dt)|0,i=i+Math.imul(k,pt)|0;var xt=(c+(r=r+Math.imul(I,ht)|0)|0)+((8191&(o=(o=o+Math.imul(I,ft)|0)+Math.imul(A,ht)|0))<<13)|0;c=((i=i+Math.imul(A,ft)|0)+(o>>>13)|0)+(xt>>>26)|0,xt&=67108863,r=Math.imul(U,J),o=(o=Math.imul(U,tt))+Math.imul(N,J)|0,i=Math.imul(N,tt),r=r+Math.imul(L,nt)|0,o=(o=o+Math.imul(L,rt)|0)+Math.imul(D,nt)|0,i=i+Math.imul(D,rt)|0,r=r+Math.imul(O,it)|0,o=(o=o+Math.imul(O,st)|0)+Math.imul(R,it)|0,i=i+Math.imul(R,st)|0,r=r+Math.imul(C,ut)|0,o=(o=o+Math.imul(C,ct)|0)+Math.imul(_,ut)|0,i=i+Math.imul(_,ct)|0,r=r+Math.imul(M,dt)|0,o=(o=o+Math.imul(M,pt)|0)+Math.imul(S,dt)|0,i=i+Math.imul(S,pt)|0;var Ct=(c+(r=r+Math.imul(T,ht)|0)|0)+((8191&(o=(o=o+Math.imul(T,ft)|0)+Math.imul(k,ht)|0))<<13)|0;c=((i=i+Math.imul(k,ft)|0)+(o>>>13)|0)+(Ct>>>26)|0,Ct&=67108863,r=Math.imul(U,nt),o=(o=Math.imul(U,rt))+Math.imul(N,nt)|0,i=Math.imul(N,rt),r=r+Math.imul(L,it)|0,o=(o=o+Math.imul(L,st)|0)+Math.imul(D,it)|0,i=i+Math.imul(D,st)|0,r=r+Math.imul(O,ut)|0,o=(o=o+Math.imul(O,ct)|0)+Math.imul(R,ut)|0,i=i+Math.imul(R,ct)|0,r=r+Math.imul(C,dt)|0,o=(o=o+Math.imul(C,pt)|0)+Math.imul(_,dt)|0,i=i+Math.imul(_,pt)|0;var _t=(c+(r=r+Math.imul(M,ht)|0)|0)+((8191&(o=(o=o+Math.imul(M,ft)|0)+Math.imul(S,ht)|0))<<13)|0;c=((i=i+Math.imul(S,ft)|0)+(o>>>13)|0)+(_t>>>26)|0,_t&=67108863,r=Math.imul(U,it),o=(o=Math.imul(U,st))+Math.imul(N,it)|0,i=Math.imul(N,st),r=r+Math.imul(L,ut)|0,o=(o=o+Math.imul(L,ct)|0)+Math.imul(D,ut)|0,i=i+Math.imul(D,ct)|0,r=r+Math.imul(O,dt)|0,o=(o=o+Math.imul(O,pt)|0)+Math.imul(R,dt)|0,i=i+Math.imul(R,pt)|0;var Et=(c+(r=r+Math.imul(C,ht)|0)|0)+((8191&(o=(o=o+Math.imul(C,ft)|0)+Math.imul(_,ht)|0))<<13)|0;c=((i=i+Math.imul(_,ft)|0)+(o>>>13)|0)+(Et>>>26)|0,Et&=67108863,r=Math.imul(U,ut),o=(o=Math.imul(U,ct))+Math.imul(N,ut)|0,i=Math.imul(N,ct),r=r+Math.imul(L,dt)|0,o=(o=o+Math.imul(L,pt)|0)+Math.imul(D,dt)|0,i=i+Math.imul(D,pt)|0;var Ot=(c+(r=r+Math.imul(O,ht)|0)|0)+((8191&(o=(o=o+Math.imul(O,ft)|0)+Math.imul(R,ht)|0))<<13)|0;c=((i=i+Math.imul(R,ft)|0)+(o>>>13)|0)+(Ot>>>26)|0,Ot&=67108863,r=Math.imul(U,dt),o=(o=Math.imul(U,pt))+Math.imul(N,dt)|0,i=Math.imul(N,pt);var Rt=(c+(r=r+Math.imul(L,ht)|0)|0)+((8191&(o=(o=o+Math.imul(L,ft)|0)+Math.imul(D,ht)|0))<<13)|0;c=((i=i+Math.imul(D,ft)|0)+(o>>>13)|0)+(Rt>>>26)|0,Rt&=67108863;var Bt=(c+(r=Math.imul(U,ht))|0)+((8191&(o=(o=Math.imul(U,ft))+Math.imul(N,ht)|0))<<13)|0;return c=((i=Math.imul(N,ft))+(o>>>13)|0)+(Bt>>>26)|0,Bt&=67108863,u[0]=gt,u[1]=yt,u[2]=bt,u[3]=wt,u[4]=It,u[5]=At,u[6]=vt,u[7]=Tt,u[8]=kt,u[9]=Pt,u[10]=Mt,u[11]=St,u[12]=xt,u[13]=Ct,u[14]=_t,u[15]=Et,u[16]=Ot,u[17]=Rt,u[18]=Bt,0!==c&&(u[19]=c,n.length++),n};function g(t,e,n){n.negative=e.negative^t.negative,n.length=t.length+e.length;for(var r=0,o=0,i=0;i<n.length-1;i++){var s=o;o=0;for(var a=67108863&r,u=Math.min(i,e.length-1),c=Math.max(0,i-t.length+1);c<=u;c++){var l=i-c,d=(0|t.words[l])*(0|e.words[c]),p=67108863&d;a=67108863&(p=p+a|0),o+=(s=(s=s+(d/67108864|0)|0)+(p>>>26)|0)>>>26,s&=67108863}n.words[i]=a,r=s,s=o}return 0!==r?n.words[i]=r:n.length--,n._strip()}function y(t,e,n){return g(t,e,n)}Math.imul||(f=h),o.prototype.mulTo=function(t,e){var n=this.length+t.length;return 10===this.length&&10===t.length?f(this,t,e):n<63?h(this,t,e):n<1024?g(this,t,e):y(this,t,e)},o.prototype.mul=function(t){var e=new o(null);return e.words=new Array(this.length+t.length),this.mulTo(t,e)},o.prototype.mulf=function(t){var e=new o(null);return e.words=new Array(this.length+t.length),y(this,t,e)},o.prototype.imul=function(t){return this.clone().mulTo(t,this)},o.prototype.imuln=function(t){var e=t<0;e&&(t=-t),n("number"==typeof t),n(t<67108864);for(var r=0,o=0;o<this.length;o++){var i=(0|this.words[o])*t,s=(67108863&i)+(67108863&r);r>>=26,r+=i/67108864|0,r+=s>>>26,this.words[o]=67108863&s}return 0!==r&&(this.words[o]=r,this.length++),e?this.ineg():this},o.prototype.muln=function(t){return this.clone().imuln(t)},o.prototype.sqr=function(){return this.mul(this)},o.prototype.isqr=function(){return this.imul(this.clone())},o.prototype.pow=function(t){var e=function(t){for(var e=new Array(t.bitLength()),n=0;n<e.length;n++){var r=n/26|0,o=n%26;e[n]=t.words[r]>>>o&1}return e}(t);if(0===e.length)return new o(1);for(var n=this,r=0;r<e.length&&0===e[r];r++,n=n.sqr());if(++r<e.length)for(var i=n.sqr();r<e.length;r++,i=i.sqr())0!==e[r]&&(n=n.mul(i));return n},o.prototype.iushln=function(t){n("number"==typeof t&&t>=0);var e,r=t%26,o=(t-r)/26,i=67108863>>>26-r<<26-r;if(0!==r){var s=0;for(e=0;e<this.length;e++){var a=this.words[e]&i,u=(0|this.words[e])-a<<r;this.words[e]=u|s,s=a>>>26-r}s&&(this.words[e]=s,this.length++)}if(0!==o){for(e=this.length-1;e>=0;e--)this.words[e+o]=this.words[e];for(e=0;e<o;e++)this.words[e]=0;this.length+=o}return this._strip()},o.prototype.ishln=function(t){return n(0===this.negative),this.iushln(t)},o.prototype.iushrn=function(t,e,r){var o;n("number"==typeof t&&t>=0),o=e?(e-e%26)/26:0;var i=t%26,s=Math.min((t-i)/26,this.length),a=67108863^67108863>>>i<<i,u=r;if(o-=s,o=Math.max(0,o),u){for(var c=0;c<s;c++)u.words[c]=this.words[c];u.length=s}if(0===s);else if(this.length>s)for(this.length-=s,c=0;c<this.length;c++)this.words[c]=this.words[c+s];else this.words[0]=0,this.length=1;var l=0;for(c=this.length-1;c>=0&&(0!==l||c>=o);c--){var d=0|this.words[c];this.words[c]=l<<26-i|d>>>i,l=d&a}return u&&0!==l&&(u.words[u.length++]=l),0===this.length&&(this.words[0]=0,this.length=1),this._strip()},o.prototype.ishrn=function(t,e,r){return n(0===this.negative),this.iushrn(t,e,r)},o.prototype.shln=function(t){return this.clone().ishln(t)},o.prototype.ushln=function(t){return this.clone().iushln(t)},o.prototype.shrn=function(t){return this.clone().ishrn(t)},o.prototype.ushrn=function(t){return this.clone().iushrn(t)},o.prototype.testn=function(t){n("number"==typeof t&&t>=0);var e=t%26,r=(t-e)/26,o=1<<e;return this.length<=r?0:!!(this.words[r]&o)},o.prototype.imaskn=function(t){n("number"==typeof t&&t>=0);var e=t%26,r=(t-e)/26;if(n(0===this.negative,"imaskn works only with positive numbers"),this.length<=r)return this;if(0!==e&&r++,this.length=Math.min(r,this.length),0!==e){var o=67108863^67108863>>>e<<e;this.words[this.length-1]&=o}return this._strip()},o.prototype.maskn=function(t){return this.clone().imaskn(t)},o.prototype.iaddn=function(t){return n("number"==typeof t),n(t<67108864),t<0?this.isubn(-t):0!==this.negative?1===this.length&&(0|this.words[0])<=t?(this.words[0]=t-(0|this.words[0]),this.negative=0,this):(this.negative=0,this.isubn(t),this.negative=1,this):this._iaddn(t)},o.prototype._iaddn=function(t){this.words[0]+=t;for(var e=0;e<this.length&&this.words[e]>=67108864;e++)this.words[e]-=67108864,e===this.length-1?this.words[e+1]=1:this.words[e+1]++;return this.length=Math.max(this.length,e+1),this},o.prototype.isubn=function(t){if(n("number"==typeof t),n(t<67108864),t<0)return this.iaddn(-t);if(0!==this.negative)return this.negative=0,this.iaddn(t),this.negative=1,this;if(this.words[0]-=t,1===this.length&&this.words[0]<0)this.words[0]=-this.words[0],this.negative=1;else for(var e=0;e<this.length&&this.words[e]<0;e++)this.words[e]+=67108864,this.words[e+1]-=1;return this._strip()},o.prototype.addn=function(t){return this.clone().iaddn(t)},o.prototype.subn=function(t){return this.clone().isubn(t)},o.prototype.iabs=function(){return this.negative=0,this},o.prototype.abs=function(){return this.clone().iabs()},o.prototype._ishlnsubmul=function(t,e,r){var o,i,s=t.length+r;this._expand(s);var a=0;for(o=0;o<t.length;o++){i=(0|this.words[o+r])+a;var u=(0|t.words[o])*e;a=((i-=67108863&u)>>26)-(u/67108864|0),this.words[o+r]=67108863&i}for(;o<this.length-r;o++)a=(i=(0|this.words[o+r])+a)>>26,this.words[o+r]=67108863&i;if(0===a)return this._strip();for(n(-1===a),a=0,o=0;o<this.length;o++)a=(i=-(0|this.words[o])+a)>>26,this.words[o]=67108863&i;return this.negative=1,this._strip()},o.prototype._wordDiv=function(t,e){var n=(this.length,t.length),r=this.clone(),i=t,s=0|i.words[i.length-1];0!=(n=26-this._countBits(s))&&(i=i.ushln(n),r.iushln(n),s=0|i.words[i.length-1]);var a,u=r.length-i.length;if("mod"!==e){(a=new o(null)).length=u+1,a.words=new Array(a.length);for(var c=0;c<a.length;c++)a.words[c]=0}var l=r.clone()._ishlnsubmul(i,1,u);0===l.negative&&(r=l,a&&(a.words[u]=1));for(var d=u-1;d>=0;d--){var p=67108864*(0|r.words[i.length+d])+(0|r.words[i.length+d-1]);for(p=Math.min(p/s|0,67108863),r._ishlnsubmul(i,p,d);0!==r.negative;)p--,r.negative=0,r._ishlnsubmul(i,1,d),r.isZero()||(r.negative^=1);a&&(a.words[d]=p)}return a&&a._strip(),r._strip(),"div"!==e&&0!==n&&r.iushrn(n),{div:a||null,mod:r}},o.prototype.divmod=function(t,e,r){return n(!t.isZero()),this.isZero()?{div:new o(0),mod:new o(0)}:0!==this.negative&&0===t.negative?(a=this.neg().divmod(t,e),"mod"!==e&&(i=a.div.neg()),"div"!==e&&(s=a.mod.neg(),r&&0!==s.negative&&s.iadd(t)),{div:i,mod:s}):0===this.negative&&0!==t.negative?(a=this.divmod(t.neg(),e),"mod"!==e&&(i=a.div.neg()),{div:i,mod:a.mod}):0!=(this.negative&t.negative)?(a=this.neg().divmod(t.neg(),e),"div"!==e&&(s=a.mod.neg(),r&&0!==s.negative&&s.isub(t)),{div:a.div,mod:s}):t.length>this.length||this.cmp(t)<0?{div:new o(0),mod:this}:1===t.length?"div"===e?{div:this.divn(t.words[0]),mod:null}:"mod"===e?{div:null,mod:new o(this.modrn(t.words[0]))}:{div:this.divn(t.words[0]),mod:new o(this.modrn(t.words[0]))}:this._wordDiv(t,e);var i,s,a},o.prototype.div=function(t){return this.divmod(t,"div",0).div},o.prototype.mod=function(t){return this.divmod(t,"mod",0).mod},o.prototype.umod=function(t){return this.divmod(t,"mod",1).mod},o.prototype.divRound=function(t){var e=this.divmod(t);if(e.mod.isZero())return e.div;var n=0!==e.div.negative?e.mod.isub(t):e.mod,r=t.ushrn(1),o=t.andln(1),i=n.cmp(r);return i<0||1===o&&0===i?e.div:0!==e.div.negative?e.div.isubn(1):e.div.iaddn(1)},o.prototype.modrn=function(t){var e=t<0;e&&(t=-t),n(t<=67108863);for(var r=(1<<26)%t,o=0,i=this.length-1;i>=0;i--)o=(r*o+(0|this.words[i]))%t;return e?-o:o},o.prototype.modn=function(t){return this.modrn(t)},o.prototype.idivn=function(t){var e=t<0;e&&(t=-t),n(t<=67108863);for(var r=0,o=this.length-1;o>=0;o--){var i=(0|this.words[o])+67108864*r;this.words[o]=i/t|0,r=i%t}return this._strip(),e?this.ineg():this},o.prototype.divn=function(t){return this.clone().idivn(t)},o.prototype.egcd=function(t){n(0===t.negative),n(!t.isZero());var e=this,r=t.clone();e=0!==e.negative?e.umod(t):e.clone();for(var i=new o(1),s=new o(0),a=new o(0),u=new o(1),c=0;e.isEven()&&r.isEven();)e.iushrn(1),r.iushrn(1),++c;for(var l=r.clone(),d=e.clone();!e.isZero();){for(var p=0,m=1;0==(e.words[0]&m)&&p<26;++p,m<<=1);if(p>0)for(e.iushrn(p);p-- >0;)(i.isOdd()||s.isOdd())&&(i.iadd(l),s.isub(d)),i.iushrn(1),s.iushrn(1);for(var h=0,f=1;0==(r.words[0]&f)&&h<26;++h,f<<=1);if(h>0)for(r.iushrn(h);h-- >0;)(a.isOdd()||u.isOdd())&&(a.iadd(l),u.isub(d)),a.iushrn(1),u.iushrn(1);e.cmp(r)>=0?(e.isub(r),i.isub(a),s.isub(u)):(r.isub(e),a.isub(i),u.isub(s))}return{a:a,b:u,gcd:r.iushln(c)}},o.prototype._invmp=function(t){n(0===t.negative),n(!t.isZero());var e=this,r=t.clone();e=0!==e.negative?e.umod(t):e.clone();for(var i,s=new o(1),a=new o(0),u=r.clone();e.cmpn(1)>0&&r.cmpn(1)>0;){for(var c=0,l=1;0==(e.words[0]&l)&&c<26;++c,l<<=1);if(c>0)for(e.iushrn(c);c-- >0;)s.isOdd()&&s.iadd(u),s.iushrn(1);for(var d=0,p=1;0==(r.words[0]&p)&&d<26;++d,p<<=1);if(d>0)for(r.iushrn(d);d-- >0;)a.isOdd()&&a.iadd(u),a.iushrn(1);e.cmp(r)>=0?(e.isub(r),s.isub(a)):(r.isub(e),a.isub(s))}return(i=0===e.cmpn(1)?s:a).cmpn(0)<0&&i.iadd(t),i},o.prototype.gcd=function(t){if(this.isZero())return t.abs();if(t.isZero())return this.abs();var e=this.clone(),n=t.clone();e.negative=0,n.negative=0;for(var r=0;e.isEven()&&n.isEven();r++)e.iushrn(1),n.iushrn(1);for(;;){for(;e.isEven();)e.iushrn(1);for(;n.isEven();)n.iushrn(1);var o=e.cmp(n);if(o<0){var i=e;e=n,n=i}else if(0===o||0===n.cmpn(1))break;e.isub(n)}return n.iushln(r)},o.prototype.invm=function(t){return this.egcd(t).a.umod(t)},o.prototype.isEven=function(){return 0==(1&this.words[0])},o.prototype.isOdd=function(){return 1==(1&this.words[0])},o.prototype.andln=function(t){return this.words[0]&t},o.prototype.bincn=function(t){n("number"==typeof t);var e=t%26,r=(t-e)/26,o=1<<e;if(this.length<=r)return this._expand(r+1),this.words[r]|=o,this;for(var i=o,s=r;0!==i&&s<this.length;s++){var a=0|this.words[s];i=(a+=i)>>>26,a&=67108863,this.words[s]=a}return 0!==i&&(this.words[s]=i,this.length++),this},o.prototype.isZero=function(){return 1===this.length&&0===this.words[0]},o.prototype.cmpn=function(t){var e,r=t<0;if(0!==this.negative&&!r)return-1;if(0===this.negative&&r)return 1;if(this._strip(),this.length>1)e=1;else{r&&(t=-t),n(t<=67108863,"Number is too big");var o=0|this.words[0];e=o===t?0:o<t?-1:1}return 0!==this.negative?0|-e:e},o.prototype.cmp=function(t){if(0!==this.negative&&0===t.negative)return-1;if(0===this.negative&&0!==t.negative)return 1;var e=this.ucmp(t);return 0!==this.negative?0|-e:e},o.prototype.ucmp=function(t){if(this.length>t.length)return 1;if(this.length<t.length)return-1;for(var e=0,n=this.length-1;n>=0;n--){var r=0|this.words[n],o=0|t.words[n];if(r!==o){r<o?e=-1:r>o&&(e=1);break}}return e},o.prototype.gtn=function(t){return 1===this.cmpn(t)},o.prototype.gt=function(t){return 1===this.cmp(t)},o.prototype.gten=function(t){return this.cmpn(t)>=0},o.prototype.gte=function(t){return this.cmp(t)>=0},o.prototype.ltn=function(t){return-1===this.cmpn(t)},o.prototype.lt=function(t){return-1===this.cmp(t)},o.prototype.lten=function(t){return this.cmpn(t)<=0},o.prototype.lte=function(t){return this.cmp(t)<=0},o.prototype.eqn=function(t){return 0===this.cmpn(t)},o.prototype.eq=function(t){return 0===this.cmp(t)},o.red=function(t){return new k(t)},o.prototype.toRed=function(t){return n(!this.red,"Already a number in reduction context"),n(0===this.negative,"red works only with positives"),t.convertTo(this)._forceRed(t)},o.prototype.fromRed=function(){return n(this.red,"fromRed works only with numbers in reduction context"),this.red.convertFrom(this)},o.prototype._forceRed=function(t){return this.red=t,this},o.prototype.forceRed=function(t){return n(!this.red,"Already a number in reduction context"),this._forceRed(t)},o.prototype.redAdd=function(t){return n(this.red,"redAdd works only with red numbers"),this.red.add(this,t)},o.prototype.redIAdd=function(t){return n(this.red,"redIAdd works only with red numbers"),this.red.iadd(this,t)},o.prototype.redSub=function(t){return n(this.red,"redSub works only with red numbers"),this.red.sub(this,t)},o.prototype.redISub=function(t){return n(this.red,"redISub works only with red numbers"),this.red.isub(this,t)},o.prototype.redShl=function(t){return n(this.red,"redShl works only with red numbers"),this.red.shl(this,t)},o.prototype.redMul=function(t){return n(this.red,"redMul works only with red numbers"),this.red._verify2(this,t),this.red.mul(this,t)},o.prototype.redIMul=function(t){return n(this.red,"redMul works only with red numbers"),this.red._verify2(this,t),this.red.imul(this,t)},o.prototype.redSqr=function(){return n(this.red,"redSqr works only with red numbers"),this.red._verify1(this),this.red.sqr(this)},o.prototype.redISqr=function(){return n(this.red,"redISqr works only with red numbers"),this.red._verify1(this),this.red.isqr(this)},o.prototype.redSqrt=function(){return n(this.red,"redSqrt works only with red numbers"),this.red._verify1(this),this.red.sqrt(this)},o.prototype.redInvm=function(){return n(this.red,"redInvm works only with red numbers"),this.red._verify1(this),this.red.invm(this)},o.prototype.redNeg=function(){return n(this.red,"redNeg works only with red numbers"),this.red._verify1(this),this.red.neg(this)},o.prototype.redPow=function(t){return n(this.red&&!t.red,"redPow(normalNum)"),this.red._verify1(this),this.red.pow(this,t)};var b={k256:null,p224:null,p192:null,p25519:null};function w(t,e){this.name=t,this.p=new o(e,16),this.n=this.p.bitLength(),this.k=new o(1).iushln(this.n).isub(this.p),this.tmp=this._tmp()}function I(){w.call(this,"k256","ffffffff ffffffff ffffffff ffffffff ffffffff ffffffff fffffffe fffffc2f")}function A(){w.call(this,"p224","ffffffff ffffffff ffffffff ffffffff 00000000 00000000 00000001")}function v(){w.call(this,"p192","ffffffff ffffffff ffffffff fffffffe ffffffff ffffffff")}function T(){w.call(this,"25519","7fffffffffffffff ffffffffffffffff ffffffffffffffff ffffffffffffffed")}function k(t){if("string"==typeof t){var e=o._prime(t);this.m=e.p,this.prime=e}else n(t.gtn(1),"modulus must be greater than 1"),this.m=t,this.prime=null}function P(t){k.call(this,t),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)}w.prototype._tmp=function(){var t=new o(null);return t.words=new Array(Math.ceil(this.n/13)),t},w.prototype.ireduce=function(t){var e,n=t;do{this.split(n,this.tmp),e=(n=(n=this.imulK(n)).iadd(this.tmp)).bitLength()}while(e>this.n);var r=e<this.n?-1:n.ucmp(this.p);return 0===r?(n.words[0]=0,n.length=1):r>0?n.isub(this.p):void 0!==n.strip?n.strip():n._strip(),n},w.prototype.split=function(t,e){t.iushrn(this.n,0,e)},w.prototype.imulK=function(t){return t.imul(this.k)},r(I,w),I.prototype.split=function(t,e){for(var n=4194303,r=Math.min(t.length,9),o=0;o<r;o++)e.words[o]=t.words[o];if(e.length=r,t.length<=9)return t.words[0]=0,void(t.length=1);var i=t.words[9];for(e.words[e.length++]=i&n,o=10;o<t.length;o++){var s=0|t.words[o];t.words[o-10]=(s&n)<<4|i>>>22,i=s}i>>>=22,t.words[o-10]=i,0===i&&t.length>10?t.length-=10:t.length-=9},I.prototype.imulK=function(t){t.words[t.length]=0,t.words[t.length+1]=0,t.length+=2;for(var e=0,n=0;n<t.length;n++){var r=0|t.words[n];e+=977*r,t.words[n]=67108863&e,e=64*r+(e/67108864|0)}return 0===t.words[t.length-1]&&(t.length--,0===t.words[t.length-1]&&t.length--),t},r(A,w),r(v,w),r(T,w),T.prototype.imulK=function(t){for(var e=0,n=0;n<t.length;n++){var r=19*(0|t.words[n])+e,o=67108863&r;r>>>=26,t.words[n]=o,e=r}return 0!==e&&(t.words[t.length++]=e),t},o._prime=function(t){if(b[t])return b[t];var e;if("k256"===t)e=new I;else if("p224"===t)e=new A;else if("p192"===t)e=new v;else{if("p25519"!==t)throw new Error("Unknown prime "+t);e=new T}return b[t]=e,e},k.prototype._verify1=function(t){n(0===t.negative,"red works only with positives"),n(t.red,"red works only with red numbers")},k.prototype._verify2=function(t,e){n(0==(t.negative|e.negative),"red works only with positives"),n(t.red&&t.red===e.red,"red works only with red numbers")},k.prototype.imod=function(t){return this.prime?this.prime.ireduce(t)._forceRed(this):(c(t,t.umod(this.m)._forceRed(this)),t)},k.prototype.neg=function(t){return t.isZero()?t.clone():this.m.sub(t)._forceRed(this)},k.prototype.add=function(t,e){this._verify2(t,e);var n=t.add(e);return n.cmp(this.m)>=0&&n.isub(this.m),n._forceRed(this)},k.prototype.iadd=function(t,e){this._verify2(t,e);var n=t.iadd(e);return n.cmp(this.m)>=0&&n.isub(this.m),n},k.prototype.sub=function(t,e){this._verify2(t,e);var n=t.sub(e);return n.cmpn(0)<0&&n.iadd(this.m),n._forceRed(this)},k.prototype.isub=function(t,e){this._verify2(t,e);var n=t.isub(e);return n.cmpn(0)<0&&n.iadd(this.m),n},k.prototype.shl=function(t,e){return this._verify1(t),this.imod(t.ushln(e))},k.prototype.imul=function(t,e){return this._verify2(t,e),this.imod(t.imul(e))},k.prototype.mul=function(t,e){return this._verify2(t,e),this.imod(t.mul(e))},k.prototype.isqr=function(t){return this.imul(t,t.clone())},k.prototype.sqr=function(t){return this.mul(t,t)},k.prototype.sqrt=function(t){if(t.isZero())return t.clone();var e=this.m.andln(3);if(n(e%2==1),3===e){var r=this.m.add(new o(1)).iushrn(2);return this.pow(t,r)}for(var i=this.m.subn(1),s=0;!i.isZero()&&0===i.andln(1);)s++,i.iushrn(1);n(!i.isZero());var a=new o(1).toRed(this),u=a.redNeg(),c=this.m.subn(1).iushrn(1),l=this.m.bitLength();for(l=new o(2*l*l).toRed(this);0!==this.pow(l,c).cmp(u);)l.redIAdd(u);for(var d=this.pow(l,i),p=this.pow(t,i.addn(1).iushrn(1)),m=this.pow(t,i),h=s;0!==m.cmp(a);){for(var f=m,g=0;0!==f.cmp(a);g++)f=f.redSqr();n(g<h);var y=this.pow(d,new o(1).iushln(h-g-1));p=p.redMul(y),d=y.redSqr(),m=m.redMul(d),h=g}return p},k.prototype.invm=function(t){var e=t._invmp(this.m);return 0!==e.negative?(e.negative=0,this.imod(e).redNeg()):this.imod(e)},k.prototype.pow=function(t,e){if(e.isZero())return new o(1).toRed(this);if(0===e.cmpn(1))return t.clone();var n=new Array(16);n[0]=new o(1).toRed(this),n[1]=t;for(var r=2;r<n.length;r++)n[r]=this.mul(n[r-1],t);var i=n[0],s=0,a=0,u=e.bitLength()%26;for(0===u&&(u=26),r=e.length-1;r>=0;r--){for(var c=e.words[r],l=u-1;l>=0;l--){var d=c>>l&1;i!==n[0]&&(i=this.sqr(i)),0!==d||0!==s?(s<<=1,s|=d,(4==++a||0===r&&0===l)&&(i=this.mul(i,n[s]),a=0,s=0)):a=0}u=26}return i},k.prototype.convertTo=function(t){var e=t.umod(this.m);return e===t?e.clone():e},k.prototype.convertFrom=function(t){var e=t.clone();return e.red=null,e},o.mont=function(t){return new P(t)},r(P,k),P.prototype.convertTo=function(t){return this.imod(t.ushln(this.shift))},P.prototype.convertFrom=function(t){var e=this.imod(t.mul(this.rinv));return e.red=null,e},P.prototype.imul=function(t,e){if(t.isZero()||e.isZero())return t.words[0]=0,t.length=1,t;var n=t.imul(e),r=n.maskn(this.shift).mul(this.minv).imaskn(this.shift).mul(this.m),o=n.isub(r).iushrn(this.shift),i=o;return o.cmp(this.m)>=0?i=o.isub(this.m):o.cmpn(0)<0&&(i=o.iadd(this.m)),i._forceRed(this)},P.prototype.mul=function(t,e){if(t.isZero()||e.isZero())return new o(0)._forceRed(this);var n=t.mul(e),r=n.maskn(this.shift).mul(this.minv).imaskn(this.shift).mul(this.m),i=n.isub(r).iushrn(this.shift),s=i;return i.cmp(this.m)>=0?s=i.isub(this.m):i.cmpn(0)<0&&(s=i.iadd(this.m)),s._forceRed(this)},P.prototype.invm=function(t){return this.imod(t._invmp(this.m).mul(this.r2))._forceRed(this)}}(0,wn);var kn=In(vn.exports);const Pn="fetchByOwner is required",Mn="No light-token balance to unwrap",Sn="Mint does not have MerkleContext",xn={Spl:"spl",Token2022:"token2022",SplCold:"spl-cold",Token2022Cold:"token2022-cold",LightTokenHot:"light-token-hot",LightTokenCold:"light-token-cold"},Cn=new Set([xn.LightTokenCold,xn.SplCold,xn.Token2022Cold]);function _n(t){return Cn.has(t)}function En(t,e){e.length>0&&function(t,e){throw new Error(`${t}: ${function(t){return t instanceof Error?t.message:String(t)}(e)}`)}(t,e[0])}function On(t,e){if(t._anyFrozen)throw new Error(`Account is frozen. One or more sources (hot or cold) are frozen; ${e} is not allowed.`)}const Rn={0:0,1:0,2:0,3:0,4:0,5:0,6:0,7:0,8:0,9:0,10:0,11:0,12:0,13:0,14:0,15:0,16:0,17:0,18:0,19:void 0,20:0,21:0,22:0,23:0,24:0,25:0,26:0,27:0,28:0,29:8,30:1,31:17,32:void 0},Bn=31;function Ln(t,e){let r=BigInt(0);const o=function(t){if(!t||t.length<5)return null;try{let e=0;const n=t.readUInt32LE(e);e+=4;for(let r=0;r<n;r++){if(e>=t.length)return null;const n=t[e];if(e+=1,n===Bn)return e+8>t.length?null:BigInt(t.readUInt32LE(e))|BigInt(t.readUInt32LE(e+4))<<BigInt(32);const r=Rn[n];if(void 0===r)return null;e+=r}}catch(t){return null}return null}(e.tlv);return null!==o?r=o:e.delegate&&(r=BigInt(e.amount.toString())),{address:t,mint:e.mint,owner:e.owner,amount:BigInt(e.amount.toString()),delegate:e.delegate,delegatedAmount:r,isInitialized:e.state!==n.AccountState.Uninitialized,isFrozen:e.state===n.AccountState.Frozen,isNative:0,rentExemptReserve:null,closeAuthority:null,tlvData:e.tlv?w.from(e.tlv):w.alloc(0)}}function Dn(t){const e=w.from(t.data.discriminator),n=w.from(t.data.data),r=w.concat([e,n]);return{executable:0,owner:t.owner,lamports:t.lamports.toNumber(),data:r,rentEpoch:void 0}}function Kn(t,r){return{accountInfo:r,loadContext:void 0,parsed:n.unpackAccount(t,r,e.LIGHT_TOKEN_PROGRAM_ID),isCold:0}}function Un(e,n){const r=function(e){if(!e||0===e.length)return null;try{let n=0;const r=new t.PublicKey(e.slice(n,n+32));n+=32;const o=new t.PublicKey(e.slice(n,n+32));n+=32;const i=new kn(e.slice(n,n+8),"le");n+=8;const s=e[n];n+=1;const a=s?new t.PublicKey(e.slice(n,n+32)):null;n+=32;const u=e[n];n+=1;const c=e[n];return n+=1,{mint:r,owner:o,amount:i,delegate:a,state:u,tlv:c?e.slice(n):null}}catch(t){return console.error("Token data parsing error:",t),null}}(n.data.data);if(!r)throw new Error("Invalid token data");return{accountInfo:Dn(n),loadContext:{treeInfo:n.treeInfo,hash:n.hash,leafIndex:n.leafIndex,proveByIndex:n.proveByIndex},parsed:Ln(e,r),isCold:1}}async function Nn(t,n,r,o){return e.assertBetaEnabled(),Gn(t,n,r,o,void 0)}async function Wn(t,n,r,o,i,s,a=0,u=0){e.assertBetaEnabled();const c=hn(n,o,r,s,u);if(a&&"light-token"!==c.type)throw new Error(`For wrap=true, ata must be the light-token ATA. Got ${c.type} ATA instead.`);const l=await Gn(t,n,i,s,{owner:r,mint:o},a);return l._isAta=1,l._owner=r,l._mint=o,l}async function Gn(t,r,o,i,s,a=0){if(!r&&!s)throw new Error("One of address or fetchByOwner is required");if(!i)return async function(t,r,o,i,s){const a=null!=r?r:n.getAssociatedTokenAddressSync(i.mint,i.owner,0,e.LIGHT_TOKEN_PROGRAM_ID,mn(e.LIGHT_TOKEN_PROGRAM_ID)),u=[],c=[],l=[];if(u.push(async function(t,r,o){const i=await t.getAccountInfo(r,o);if(!i)return null;if(!i.owner.equals(e.LIGHT_TOKEN_PROGRAM_ID))throw new n.TokenInvalidAccountOwnerError;return Kn(r,i)}(t,a,o)),c.push(xn.LightTokenHot),l.push(a),s){if(!i)throw new Error("fetchByOwner is required for wrap=true to derive SPL/T22 addresses");const e=n.getAssociatedTokenAddressSync(i.mint,i.owner,0,n.TOKEN_PROGRAM_ID,mn(n.TOKEN_PROGRAM_ID)),r=n.getAssociatedTokenAddressSync(i.mint,i.owner,0,n.TOKEN_2022_PROGRAM_ID,mn(n.TOKEN_2022_PROGRAM_ID));u.push(async function(t,e,r){const o=await t.getAccountInfo(e,r);if(!o)return null;if(!o.owner.equals(n.TOKEN_PROGRAM_ID))throw new n.TokenInvalidAccountOwnerError;return{accountInfo:o,parsed:n.unpackAccount(e,o,n.TOKEN_PROGRAM_ID),isCold:0,loadContext:void 0}}(t,e,o)),c.push(xn.Spl),l.push(e),u.push(async function(t,e,r){const o=await t.getAccountInfo(e,r);if(!o)return null;if(!o.owner.equals(n.TOKEN_2022_PROGRAM_ID))throw new n.TokenInvalidAccountOwnerError;return{accountInfo:o,parsed:n.unpackAccount(e,o,n.TOKEN_2022_PROGRAM_ID),isCold:0,loadContext:void 0}}(t,r,o)),c.push(xn.Token2022),l.push(r)}const d=i?t.getCompressedTokenAccountsByOwner(i.owner,{mint:i.mint}):t.getCompressedTokenAccountsByOwner(r),p=await Promise.allSettled(u),m=[],h=[];let f=null;try{f=await d}catch(t){h.push(t)}const g=[];for(let t=0;t<p.length;t++){const e=p[t];if("fulfilled"===e.status){const n=e.value;if(!n)continue;g.push({type:c[t],address:l[t],amount:n.parsed.amount,accountInfo:n.accountInfo,loadContext:n.loadContext,parsed:n.parsed})}else e.reason instanceof n.TokenInvalidAccountOwnerError?m.push(e.reason):h.push(e.reason)}if(f)for(const t of f.items){const n=t.compressedAccount;if(n&&n.data&&n.data.data.length>0&&n.owner.equals(e.LIGHT_TOKEN_PROGRAM_ID)){const t=Un(a,n);g.push({type:xn.LightTokenCold,address:a,amount:t.parsed.amount,accountInfo:t.accountInfo,loadContext:t.loadContext,parsed:t.parsed})}}if(En("Failed to fetch token account data from RPC",h),0===g.length){if(m.length>0)throw m[0];throw new n.TokenAccountNotFoundError}const y=[xn.LightTokenHot,xn.LightTokenCold,xn.Spl,xn.Token2022];return g.sort(((t,e)=>y.indexOf(t.type)-y.indexOf(e.type))),qn(g,a)}(t,r,o,s,a);if(i.equals(e.LIGHT_TOKEN_PROGRAM_ID))return async function(t,r,o,i){if(!r){if(!i)throw new Error(Pn);r=n.getAssociatedTokenAddressSync(i.mint,i.owner,0,e.LIGHT_TOKEN_PROGRAM_ID,mn(e.LIGHT_TOKEN_PROGRAM_ID))}const[s,a]=await Promise.allSettled([t.getAccountInfo(r,o),i?t.getCompressedTokenAccountsByOwner(i.owner,{mint:i.mint}):t.getCompressedTokenAccountsByOwner(r)]),u=[],c=[],l="fulfilled"===s.status?s.value:null;"rejected"===s.status&&u.push(s.reason);const d="fulfilled"===a.status?a.value.items.map((t=>t.compressedAccount)):[];"rejected"===a.status&&u.push(a.reason);const p=[];if(l)if(l.owner.equals(e.LIGHT_TOKEN_PROGRAM_ID)){const t=Kn(r,l);p.push({type:xn.LightTokenHot,address:r,amount:t.parsed.amount,accountInfo:l,parsed:t.parsed})}else c.push(new n.TokenInvalidAccountOwnerError);for(const t of d)if(t&&t.data&&t.data.data.length>0&&t.owner.equals(e.LIGHT_TOKEN_PROGRAM_ID)){const e=Un(r,t);p.push({type:xn.LightTokenCold,address:r,amount:e.parsed.amount,accountInfo:e.accountInfo,loadContext:e.loadContext,parsed:e.parsed})}if(En("Failed to fetch token account data from RPC",u),0===p.length){if(c.length>0)throw c[0];throw new n.TokenAccountNotFoundError}return p.sort(((t,e)=>"light-token-hot"===t.type&&"light-token-cold"===e.type?-1:"light-token-cold"===t.type&&"light-token-hot"===e.type?1:0)),qn(p,r)}(t,r,o,s);if(i.equals(n.TOKEN_PROGRAM_ID)||i.equals(n.TOKEN_2022_PROGRAM_ID))return async function(t,r,o,i,s){if(!r){if(!s)throw new Error(Pn);r=n.getAssociatedTokenAddressSync(s.mint,s.owner,0,i,mn(i))}const a=i.equals(n.TOKEN_PROGRAM_ID)?xn.Spl:xn.Token2022,u=i.equals(n.TOKEN_PROGRAM_ID)?xn.SplCold:xn.Token2022Cold,[c,l]=await Promise.allSettled([t.getAccountInfo(r,o),s?t.getCompressedTokenAccountsByOwner(s.owner,{mint:s.mint}):Promise.resolve({items:[]})]),d=[],p=[],m=[],h="fulfilled"===c.status?c.value:null;"rejected"===c.status&&p.push(c.reason);const f="fulfilled"===l.status?l.value:{items:[]};if("rejected"===l.status&&p.push(l.reason),h)if(h.owner.equals(i))try{const t=n.unpackAccount(r,h,i);d.push({type:a,address:r,amount:t.amount,accountInfo:h,parsed:t})}catch(t){p.push(t)}else m.push(new n.TokenInvalidAccountOwnerError);for(const t of f.items){const n=t.compressedAccount;if(n&&n.data&&n.data.data.length>0&&n.owner.equals(e.LIGHT_TOKEN_PROGRAM_ID)){const t=Un(r,n);d.push({type:u,address:r,amount:t.parsed.amount,accountInfo:t.accountInfo,loadContext:t.loadContext,parsed:t.parsed})}}if(En("Failed to fetch token account data from RPC",p),0===d.length){if(m.length>0)throw m[0];throw new n.TokenAccountNotFoundError}return qn(d,r)}(t,r,o,i,s);throw new Error(`Unsupported program ID: ${i.toBase58()}`)}function qn(t,e){const r=t.reduce(((t,e)=>t+e.amount),BigInt(0)),o=t[0],i=t.some((t=>null!==t.parsed.delegate)),s=t.some((t=>t.parsed.isFrozen)),a=t.some((t=>_n(t.type))),u=t.length>1,c=(e,n)=>t.reduce(((t,r)=>{if(!n(r))return t;const o=r.parsed.delegate;return o&&o.equals(e)?t+(t=>{var e;const n=null!==(e=t.parsed.delegatedAmount)&&void 0!==e?e:t.amount;return t.amount<n?t.amount:n})(r):t}),BigInt(0)),l=t.find((t=>!_n(t.type)&&null!==t.parsed.delegate)),d=t.filter((t=>_n(t.type)&&null!==t.parsed.delegate));let p=null,m=BigInt(0);(null==l?void 0:l.parsed.delegate)?(p=l.parsed.delegate,m=c(p,(()=>1))):d.length>0&&(p=d[0].parsed.delegate,m=c(p,(t=>_n(t.type))));const h=Object.assign(Object.assign(Object.assign({},o.parsed),{address:e,amount:r,isInitialized:o.parsed.isInitialized||a,delegate:p,delegatedAmount:m}),s?{state:n.AccountState.Frozen,isFrozen:1}:{});return{accountInfo:o.accountInfo,parsed:h,isCold:_n(o.type),loadContext:o.loadContext,_sources:t,_needsConsolidation:u,_hasDelegate:i,_anyFrozen:s}}function Fn(t,e){var n;const r=t._owner;if(r&&e.equals(r))return t.parsed.amount;const o=t.parsed.delegate;if(o&&e.equals(o)){const e=null!==(n=t.parsed.delegatedAmount)&&void 0!==n?n:BigInt(0);return e<t.parsed.amount?e:t.parsed.amount}return BigInt(0)}function Vn(t,e){const n=t._owner;if(n&&e.equals(n))return 1;const r=t.parsed.delegate;return null!==r&&e.equals(r)}function Hn(t,e){var n;const r=t._owner;if(r&&e.equals(r))return t;const o=Fn(t,e),i=t.parsed.delegate;if(o===BigInt(0)||null===i||!e.equals(i))return Object.assign(Object.assign({},t),{_sources:[],_needsConsolidation:0,parsed:Object.assign(Object.assign({},t.parsed),{amount:BigInt(0)})});const s=(null!==(n=t._sources)&&void 0!==n?n:[]).filter((t=>null!==t.parsed.delegate&&t.parsed.delegate.equals(i))),a=s[0];return Object.assign(Object.assign(Object.assign({},t),a?{accountInfo:a.accountInfo,isCold:_n(a.type),loadContext:a.loadContext}:{}),{_sources:s,_needsConsolidation:s.length>1,parsed:Object.assign(Object.assign({},t.parsed),{amount:o})})}function zn(t,r,o=0,i=e.LIGHT_TOKEN_PROGRAM_ID,s){const a=null!=s?s:mn(i);return n.getAssociatedTokenAddressSync(t,r,o,i,a)}const jn=w.from([101]),$n=19,Yn=31,Zn=32,Qn=0,Xn=1,Jn=r.struct([r.u64("delegatedAmount"),r.u64("withheldTransferFee"),r.bool("isFrozen"),r.u8("compressionIndex"),r.bool("isAta"),r.u8("bump"),r.u8("ownerIndex")]),tr=r.struct([r.u16("baseRent"),r.u16("compressionCost"),r.u8("lamportsPerBytePerEpoch"),r.u8("maxFundedEpochs"),r.u16("maxTopUp")]),er=r.struct([r.u16("configAccountVersion"),r.u8("compressToPubkey"),r.u8("accountVersion"),r.u32("lamportsPerWrite"),r.array(r.u8(),32,"compressionAuthority"),r.array(r.u8(),32,"rentSponsor"),r.u64("lastClaimedSlot"),r.u32("rentExemptionPaid"),r.u32("reserved"),tr.replicate("rentConfig")]);function nr(t){const n=w.alloc(1024);let r=0;if("TokenMetadata"===t.type){n.writeUInt8($n,r),r+=1;const e={updateAuthority:t.data.updateAuthority,name:t.data.name,symbol:t.data.symbol,uri:t.data.uri,additionalMetadata:t.data.additionalMetadata?t.data.additionalMetadata.map((t=>({key:w.from(t.key),value:w.from(t.value)}))):null};r+=Ge.encode(e,n,r)}else if("CompressedOnly"===t.type){n.writeUInt8(Yn,r),r+=1;const o={delegatedAmount:e.bn(t.data.delegatedAmount.toString()),withheldTransferFee:e.bn(t.data.withheldTransferFee.toString()),isFrozen:t.data.isFrozen,compressionIndex:t.data.compressionIndex,isAta:t.data.isAta,bump:t.data.bump,ownerIndex:t.data.ownerIndex};r+=Jn.encode(o,n,r)}else if("Compressible"===t.type){n.writeUInt8(Zn,r),r+=1;const o={configAccountVersion:t.data.configAccountVersion,compressToPubkey:t.data.compressToPubkey,accountVersion:t.data.accountVersion,lamportsPerWrite:t.data.lamportsPerWrite,compressionAuthority:Array.from(t.data.compressionAuthority.toBytes()),rentSponsor:Array.from(t.data.rentSponsor.toBytes()),lastClaimedSlot:e.bn(t.data.lastClaimedSlot.toString()),rentExemptionPaid:t.data.rentExemptionPaid,reserved:t.data.reserved,rentConfig:t.data.rentConfig};r+=er.encode(o,n,r)}return n.subarray(0,r)}function rr(t){if(null===t)return null;const e=[],n=w.alloc(4);n.writeUInt32LE(t.length,0),e.push(n);for(const n of t){const t=w.alloc(4);t.writeUInt32LE(n.length,0),e.push(t);for(const t of n)e.push(nr(t))}return w.concat(e)}const or=r.struct([r.u8("mode"),r.u64("amount"),r.u8("mint"),r.u8("sourceOrRecipient"),r.u8("authority"),r.u8("poolAccountIndex"),r.u8("poolIndex"),r.u8("bump"),r.u8("decimals")]),ir=r.struct([r.u8("merkleTreePubkeyIndex"),r.u8("queuePubkeyIndex"),r.u32("leafIndex"),r.bool("proveByIndex")]),sr=r.struct([r.u8("owner"),r.u64("amount"),r.bool("hasDelegate"),r.u8("delegate"),r.u8("mint"),r.u8("version"),ir.replicate("merkleContext"),r.u16("rootIndex")]),ar=r.struct([r.u8("owner"),r.u64("amount"),r.bool("hasDelegate"),r.u8("delegate"),r.u8("mint"),r.u8("version")]),ur=r.struct([r.bool("setContext"),r.bool("firstSetContext"),r.u8("cpiContextAccountIndex")]),cr=r.struct([r.bool("withTransactionHash"),r.bool("withLamportsChangeAccountMerkleTreeIndex"),r.u8("lamportsChangeAccountMerkleTreeIndex"),r.u8("lamportsChangeAccountOwnerIndex"),r.u8("outputQueue"),r.u16("maxTopUp"),r.option(ur,"cpiContext"),r.option(r.vec(or),"compressions"),r.option(Ke,"proof"),r.vec(sr,"inTokenData"),r.vec(ar,"outTokenData"),r.option(r.vec(r.u64()),"inLamports"),r.option(r.vec(r.u64()),"outLamports")]);function lr(t){var n,r,o,i,s,a;const u={withTransactionHash:t.withTransactionHash,withLamportsChangeAccountMerkleTreeIndex:t.withLamportsChangeAccountMerkleTreeIndex,lamportsChangeAccountMerkleTreeIndex:t.lamportsChangeAccountMerkleTreeIndex,lamportsChangeAccountOwnerIndex:t.lamportsChangeAccountOwnerIndex,outputQueue:t.outputQueue,maxTopUp:t.maxTopUp,cpiContext:t.cpiContext,compressions:null!==(r=null===(n=t.compressions)||void 0===n?void 0:n.map((t=>Object.assign(Object.assign({},t),{amount:e.bn(t.amount.toString())}))))&&void 0!==r?r:null,proof:t.proof,inTokenData:t.inTokenData.map((t=>Object.assign(Object.assign({},t),{amount:e.bn(t.amount.toString())}))),outTokenData:t.outTokenData.map((t=>Object.assign(Object.assign({},t),{amount:e.bn(t.amount.toString())}))),inLamports:null!==(i=null===(o=t.inLamports)||void 0===o?void 0:o.map((t=>e.bn(t.toString()))))&&void 0!==i?i:null,outLamports:null!==(a=null===(s=t.outLamports)||void 0===s?void 0:s.map((t=>e.bn(t.toString()))))&&void 0!==a?a:null},c=w.alloc(4e3),l=cr.encode(u,c),d=[jn,c.subarray(0,l)];if(null===t.inTlv)d.push(w.from([0]));else{d.push(w.from([1]));const e=rr(t.inTlv);e&&d.push(w.from(e))}if(null===t.outTlv)d.push(w.from([0]));else{d.push(w.from([1]));const e=rr(t.outTlv);e&&d.push(w.from(e))}return w.concat(d)}function dr(t,e,n,r,o,i,s,a){return{mode:Qn,amount:t,mint:e,sourceOrRecipient:n,authority:r,poolAccountIndex:o,poolIndex:i,bump:s,decimals:a}}function pr(t,e,n,r){return{mode:Xn,amount:t,mint:e,sourceOrRecipient:n,authority:0,poolAccountIndex:r,poolIndex:0,bump:0,decimals:0}}function mr(t,e,n,r,o){return{mode:Qn,amount:t,mint:e,sourceOrRecipient:n,authority:r,poolAccountIndex:o,poolIndex:0,bump:0,decimals:0}}function hr(t,e,n,r,o,i,s){return{mode:Xn,amount:t,mint:e,sourceOrRecipient:n,authority:0,poolAccountIndex:r,poolIndex:o,bump:i,decimals:s}}function fr(n,r,o,i,s,a,u,c=o,l){const d=[dr(s,0,2,1,4,a.poolIndex,a.bump,u),pr(s,0,3,6)],p=lr({withTransactionHash:0,withLamportsChangeAccountMerkleTreeIndex:0,lamportsChangeAccountMerkleTreeIndex:0,lamportsChangeAccountOwnerIndex:0,outputQueue:0,maxTopUp:null!=l?l:yt,cpiContext:null,compressions:d,proof:null,inTokenData:[],outTokenData:[],inLamports:null,outLamports:null,inTlv:null,outTlv:null}),m=[{pubkey:ve.deriveCpiAuthorityPda,isSigner:0,isWritable:0},{pubkey:c,isSigner:1,isWritable:1},{pubkey:i,isSigner:0,isWritable:0},{pubkey:o,isSigner:1,isWritable:0},{pubkey:n,isSigner:0,isWritable:1},{pubkey:r,isSigner:0,isWritable:1},{pubkey:a.splInterfacePda,isSigner:0,isWritable:1},{pubkey:a.tokenProgram,isSigner:0,isWritable:0},{pubkey:e.LIGHT_TOKEN_PROGRAM_ID,isSigner:0,isWritable:0},{pubkey:t.SystemProgram.programId,isSigner:0,isWritable:0}];return new t.TransactionInstruction({programId:ve.programId,keys:m,data:p})}const gr=31,yr=17;function br(t){if(!t||t.length<5)return null;try{let e=0;const n=t.readUInt32LE(e);e+=4;for(let r=0;r<n;r++){if(e>=t.length)return null;const n=t[e];if(e+=1,n===gr){if(e+yr>t.length)return null;const n=BigInt(t.readUInt32LE(e))|BigInt(t.readUInt32LE(e+4))<<BigInt(32);return{delegatedAmount:n,withheldTransferFee:BigInt(t.readUInt32LE(e+8))|BigInt(t.readUInt32LE(e+12))<<BigInt(32),isAta:0!==t[e+16]}}const r={29:8,30:1,31:17}[n];if(void 0===r)throw new Error(`parseCompressedOnlyFromTlv: unknown TLV extension discriminant ${n}`);e+=r}}catch(t){return null}return null}function wr(n,r,o,i){let s=0;const a=[];for(const u of n){const n=br(u.parsed.tlv);if(!n){a.push([]);continue}s=1;let c=0;if(n.isAta){const n=[o.toBuffer(),e.LIGHT_TOKEN_PROGRAM_ID.toBuffer(),i.toBuffer()],[,r]=t.PublicKey.findProgramAddressSync(n,e.LIGHT_TOKEN_PROGRAM_ID);c=r}const l=2===u.parsed.state;a.push([{type:"CompressedOnly",data:{delegatedAmount:n.delegatedAmount,withheldTransferFee:n.withheldTransferFee,isFrozen:l,compressionIndex:0,isAta:n.isAta,bump:c,ownerIndex:r}}])}return s?a:null}function Ir(t){return!t||t.length<8?exports.TokenDataVersion.ShaFlat:2===t[0]?exports.TokenDataVersion.V1:3===t[7]?exports.TokenDataVersion.V2:exports.TokenDataVersion.ShaFlat}function Ar(n,r,o,i,s,a,u,c,l){var d;if(0===r.length)throw new Error("No input light-token accounts provided");const p=r[0].parsed.mint,m=r[0].parsed.owner,h=new Map,f=[],g=new Set,y=new Set;for(const t of r)g.add(t.compressedAccount.treeInfo.tree.toBase58()),y.add(t.compressedAccount.treeInfo.queue.toBase58());for(const e of g)h.set(e,f.length),f.push(new t.PublicKey(e));let b=0,w=1;for(const e of y)w&&(b=f.length,w=0),h.set(e,f.length),f.push(new t.PublicKey(e));const I=f.length;h.set(p.toBase58(),I),f.push(p);const A=f.length;h.set(m.toBase58(),A),f.push(m);const v=f.length;h.set(o.toBase58(),v),f.push(o);for(const t of r)if(t.parsed.delegate){const e=t.parsed.delegate.toBase58();h.has(e)||(h.set(e,f.length),f.push(t.parsed.delegate))}let T=0,k=0,P=0,M=0;a&&(T=f.length,h.set(a.splInterfacePda.toBase58(),T),f.push(a.splInterfacePda),M=f.length,h.set(a.tokenProgram.toBase58(),M),f.push(a.tokenProgram),k=a.poolIndex,P=a.bump);const S=function(t,e,n){return t.map(((t,r)=>{var o,i;const s=t.parsed.owner.toBase58(),a=t.parsed.mint.toBase58(),u=Ir(null===(o=t.compressedAccount.data)||void 0===o?void 0:o.discriminator);return{owner:n.get(s),amount:BigInt(t.parsed.amount.toString()),hasDelegate:null!==t.parsed.delegate,delegate:t.parsed.delegate&&null!==(i=n.get(t.parsed.delegate.toBase58()))&&void 0!==i?i:0,mint:n.get(a),version:u,merkleContext:{merkleTreePubkeyIndex:n.get(t.compressedAccount.treeInfo.tree.toBase58()),queuePubkeyIndex:n.get(t.compressedAccount.treeInfo.queue.toBase58()),leafIndex:t.compressedAccount.leafIndex,proveByIndex:t.compressedAccount.proveByIndex},rootIndex:e[r]}}))}(r,s.rootIndices,h),x=r.reduce(((t,e)=>t+BigInt(e.parsed.amount.toString())),BigInt(0))-i,C=[];if(x>0){const t=Ir(null===(d=r[0].compressedAccount.data)||void 0===d?void 0:d.discriminator);C.push({owner:A,amount:x,hasDelegate:0,delegate:0,mint:I,version:t})}const _=lr({withTransactionHash:0,withLamportsChangeAccountMerkleTreeIndex:0,lamportsChangeAccountMerkleTreeIndex:0,lamportsChangeAccountOwnerIndex:0,outputQueue:b,maxTopUp:yt,cpiContext:null,compressions:[{mode:Xn,amount:i,mint:I,sourceOrRecipient:v,authority:0,poolAccountIndex:a?T:0,poolIndex:a?k:0,bump:a?P:0,decimals:u}],proof:s.compressedProof?{a:Array.from(s.compressedProof.a),b:Array.from(s.compressedProof.b),c:Array.from(s.compressedProof.c)}:null,inTokenData:S,outTokenData:C,inLamports:null,outLamports:null,inTlv:wr(r,A,m,p),outTlv:null}),{accountCompressionAuthority:E,registeredProgramPda:O,accountCompressionProgram:R}=e.defaultStaticAccountsStruct(),B=(()=>{if(!l||l.equals(m))return A;const t=h.get(l.toBase58());if(void 0===t)throw new Error(`Authority ${l.toBase58()} is not present in packed accounts`);return t})(),L=[{pubkey:e.LightSystemProgram.programId,isSigner:0,isWritable:0},{pubkey:n,isSigner:1,isWritable:1},{pubkey:ve.deriveCpiAuthorityPda,isSigner:0,isWritable:0},{pubkey:O,isSigner:0,isWritable:0},{pubkey:E,isSigner:0,isWritable:0},{pubkey:R,isSigner:0,isWritable:0},{pubkey:t.SystemProgram.programId,isSigner:0,isWritable:0},...f.map(((t,e)=>{const n=e<g.size+y.size,r=t.equals(o),i=void 0!==a&&t.equals(a.splInterfacePda);return{pubkey:t,isSigner:e===B,isWritable:n||r||i}}))];return new t.TransactionInstruction({programId:ve.programId,keys:L,data:_})}const vr=8;function Tr(t,e){if(0===t.length||e<=BigInt(0))return[];const n=[...t].sort(((t,e)=>{const n=BigInt(t.parsed.amount.toString()),r=BigInt(e.parsed.amount.toString());return r>n?1:r<n?-1:0}));let r=BigInt(0),o=0;for(const t of n)if(o++,r+=BigInt(t.parsed.amount.toString()),r>=e)break;const i=Math.min(Math.max(o,vr),n.length);return n.slice(0,i)}async function kr(r,o,i,s,a,u,c,l=0){var d;e.assertBetaEnabled(),null!=u||(u=i);const p=null!==(d=null==c?void 0:c.owner)&&void 0!==d?d:i;let m;try{m=await Wn(r,o,p,s,void 0,void 0,l)}catch(t){if(t instanceof n.TokenAccountNotFoundError)return[];throw t}if(!p.equals(i)){if(!Vn(m,i))throw new Error("Signer is not the owner or a delegate of the account.");m=Hn(m,i)}return(await Dr(r,u,m,c,l,o,void 0,i,a)).map((e=>[t.ComputeBudgetProgram.setComputeUnitLimit({units:Lr(e)}),...e.instructions]))}const Pr=3e4,Mr=5e4,Sr=5e4,xr=1e5,Cr=1e4,_r=3e4,Er=1.3,Or=5e4,Rr=14e5;function Br(t){var e;let n=0;if(t.hasAtaCreation&&(n+=Pr),n+=t.wrapCount*Mr,t.compressedAccounts.length>0){n+=Sr;const r=t.compressedAccounts.some((t=>{var e;return!(null!==(e=t.compressedAccount.proveByIndex)&&void 0!==e&&e)}));r&&(n+=xr);for(const r of t.compressedAccounts)n+=null!==(e=r.compressedAccount.proveByIndex)&&void 0!==e&&e?Cr:_r}return n}function Lr(t){const e=Math.ceil(Br(t)*Er);return Math.max(Or,Math.min(Rr,e))}async function Dr(t,r,o,i,s,a,u,c,l){var d,p,m,h;if(!o._isAta||!o._owner||!o._mint)throw new Error("AccountInterface must be from getAtaInterface (requires _isAta, _owner, _mint)");On(o,"load");const f=o._owner,g=o._mint,y=null!==(d=o._sources)&&void 0!==d?d:[],b=function(t){return t.filter((t=>void 0!==t.loadContext)).filter((t=>Cn.has(t.type))).map((t=>{const n=t.accountInfo.data,r=n.subarray(0,Math.min(8,n.length)),o=n.length>8?n.subarray(8):Buffer.alloc(0),i={treeInfo:t.loadContext.treeInfo,hash:t.loadContext.hash,leafIndex:t.loadContext.leafIndex,proveByIndex:t.loadContext.proveByIndex,owner:t.accountInfo.owner,lamports:e.bn(t.accountInfo.lamports),address:null,data:0===n.length?null:{discriminator:Array.from(r),data:Buffer.from(o),dataHash:new Array(32).fill(0)},readOnly:0},s=t.parsed.isInitialized?t.parsed.isFrozen?2:1:0;return{compressedAccount:i,parsed:{mint:t.parsed.mint,owner:t.parsed.owner,amount:e.bn(t.parsed.amount.toString()),delegate:t.parsed.delegate,state:s,tlv:t.parsed.tlvData.length>0?t.parsed.tlvData:null}}}))}(y),w=zn(g,f),I=n.getAssociatedTokenAddressSync(g,f,0,n.TOKEN_PROGRAM_ID,mn(n.TOKEN_PROGRAM_ID)),A=n.getAssociatedTokenAddressSync(g,f,0,n.TOKEN_2022_PROGRAM_ID,mn(n.TOKEN_2022_PROGRAM_ID));let v="light-token";if(v=hn(a,g,f).type,s&&"light-token"!==v)throw new Error(`For wrap=true, targetAta must be light-token associated token account. Got ${v} associated token account.`);const T=y.find((t=>"spl"===t.type)),k=y.find((t=>"token2022"===t.type)),P=y.find((t=>"light-token-hot"===t.type)),M=y.filter((t=>Cn.has(t.type))),S=null!==(p=null==T?void 0:T.amount)&&void 0!==p?p:BigInt(0),x=null!==(m=null==k?void 0:k.amount)&&void 0!==m?m:BigInt(0),C=M.reduce(((t,e)=>t+e.amount),BigInt(0));if(S===BigInt(0)&&x===BigInt(0)&&C===BigInt(0))return[];let _;if(s||"spl"===v||"token2022"===v||S>BigInt(0)||x>BigInt(0))try{_=(null!==(h=null==i?void 0:i.splInterfaceInfos)&&void 0!==h?h:await kt(t,g)).find((t=>t.isInitialized))}catch(t){if(S>BigInt(0)||x>BigInt(0))throw t}const E=[];let O,R=0,B=0,L=w,D=0;s?(L=w,O=void 0,D=1,P||(B=1,E.push(yn(r,w,f,g,e.LIGHT_TOKEN_PROGRAM_ID))),S>BigInt(0)&&_&&(E.push(fr(I,w,f,g,S,_,l,r)),R++),x>BigInt(0)&&_&&(E.push(fr(A,w,f,g,x,_,l,r)),R++)):"light-token"===v?(L=w,O=void 0,D=1,P||(B=1,E.push(yn(r,w,f,g,e.LIGHT_TOKEN_PROGRAM_ID)))):"spl"===v&&_?(L=I,O=_,D=1,T||(B=1,E.push(n.createAssociatedTokenAccountIdempotentInstruction(r,I,f,g,n.TOKEN_PROGRAM_ID)))):"token2022"===v&&_&&(L=A,O=_,D=1,k||(B=1,E.push(n.createAssociatedTokenAccountIdempotentInstruction(r,A,f,g,n.TOKEN_2022_PROGRAM_ID))));let K=b;if(void 0!==u&&D&&b.length>0){const t=void 0!==c&&!c.equals(f),e=(()=>{var e;if(!P)return BigInt(0);if(t){const t=null!==(e=P.parsed.delegatedAmount)&&void 0!==e?e:BigInt(0);return t<P.amount?t:P.amount}return P.amount})();let n;n=s?e+S+x:"light-token"===v?e:"spl"===v?S:x;const r=u>n?u-n:BigInt(0);K=r===BigInt(0)?[]:Tr(b,r)}if(!D||0===K.length)return 0===E.length?[]:[{instructions:E,compressedAccounts:[],wrapCount:R,hasAtaCreation:B}];!function(t){const n=t.filter((t=>t.compressedAccount.treeInfo.treeType===e.TreeType.StateV1)).length;if(n>0)throw new Error(`v3 interface does not support V1 compressed accounts. Found ${n} V1 account(s). Use the main SDK actions (transfer, decompress, merge) to migrate V1 accounts to V2.`)}(K);const U=function(t,e){const n=[];for(let r=0;r<t.length;r+=e)n.push(t.slice(r,r+e));return n}(K,vr);!function(t){const e=new Set;for(const n of t)for(const t of n){const n=t.compressedAccount.hash.toString();if(e.has(n))throw new Error(`Duplicate compressed account hash across chunks: ${n}. Each compressed account must appear in exactly one chunk.`);e.add(n)}}(U);const N=await Promise.all(U.map((async e=>{const n=e.map((t=>({hash:t.compressedAccount.hash,tree:t.compressedAccount.treeInfo.tree,queue:t.compressedAccount.treeInfo.queue})));return t.getValidityProofV0(n)}))),W=s||"light-token"===v?yn(r,w,f,g,e.LIGHT_TOKEN_PROGRAM_ID):"spl"===v?n.createAssociatedTokenAccountIdempotentInstruction(r,I,f,g,n.TOKEN_PROGRAM_ID):n.createAssociatedTokenAccountIdempotentInstruction(r,A,f,g,n.TOKEN_2022_PROGRAM_ID),G=[];for(let t=0;t<U.length;t++){const e=U[t],n=N[t],o=e.reduce(((t,e)=>t+BigInt(e.parsed.amount.toString())),BigInt(0)),i=[];let s=0,a=0;0===t?(i.push(...E),s=R,a=B):(i.push(W),a=1);const u=null!=c?c:f;i.push(Ar(r,e,L,o,n,O,l,0,u)),G.push({instructions:i,compressedAccounts:e,wrapCount:s,hasAtaCreation:a})}return G}function Kr(n){const{mint:r,destination:o,amount:i,authority:s,maxTopUp:a,feePayer:u}=n,c=[{pubkey:r,isSigner:0,isWritable:1},{pubkey:o,isSigner:0,isWritable:1},{pubkey:s,isSigner:1,isWritable:void 0!==a&&!u},{pubkey:t.SystemProgram.programId,isSigner:0,isWritable:0}];u&&c.push({pubkey:u,isSigner:1,isWritable:1});const l=BigInt(i.toString()),d=void 0!==a?11:9,p=w.alloc(d);return p.writeUInt8(7,0),p.writeBigUInt64LE(l,1),void 0!==a&&p.writeUInt16LE(a,9),new t.TransactionInstruction({programId:e.LIGHT_TOKEN_PROGRAM_ID,keys:c,data:p})}function Ur(n,r,o,i,s,a,u,c=exports.TokenDataVersion.ShaFlat,l){var d;const p=s.cmintDecompressed;e.getDefaultAddressTreeInfo();const m=function(t){var e;if(t.mintData.metadata)throw new Error("TokenMetadata extension not supported in mintTo instruction");const n=t.mintData.cmintDecompressed;return je({leafIndex:t.leafIndex,proveByIndex:1,rootIndex:t.rootIndex,maxTopUp:null!==(e=t.maxTopUp)&&void 0!==e?e:yt,createMint:null,actions:[{mintToCompressed:{tokenAccountVersion:t.tokenAccountVersion,recipients:t.recipients.map((t=>({recipient:t.recipient,amount:BigInt(t.amount.toString())})))}}],proof:n?null:t.proof,cpiContext:null,mint:n?null:{supply:t.mintData.supply,decimals:t.mintData.decimals,metadata:{version:t.mintData.version,cmintDecompressed:t.mintData.cmintDecompressed,mint:t.mintData.splMint,mintSigner:Array.from(t.mintData.mintSigner),bump:t.mintData.bump},mintAuthority:t.mintData.mintAuthority,freezeAuthority:t.mintData.freezeAuthority,extensions:null}})}({leafIndex:i.leafIndex,rootIndex:o.rootIndices[0],proof:o.compressedProof,mintData:s,recipients:a,tokenAccountVersion:c,maxTopUp:l}),h=null!==(d=null==u?void 0:u.queue)&&void 0!==d?d:e.getOutputQueue(i),f=e.defaultStaticAccountsStruct(),g=[{pubkey:e.LightSystemProgram.programId,isSigner:0,isWritable:0},{pubkey:n,isSigner:1,isWritable:0},...p?[{pubkey:s.splMint,isSigner:0,isWritable:1}]:[],{pubkey:r,isSigner:1,isWritable:1},{pubkey:ve.deriveCpiAuthorityPda,isSigner:0,isWritable:0},{pubkey:f.registeredProgramPda,isSigner:0,isWritable:0},{pubkey:f.accountCompressionAuthority,isSigner:0,isWritable:0},{pubkey:f.accountCompressionProgram,isSigner:0,isWritable:0},{pubkey:t.SystemProgram.programId,isSigner:0,isWritable:0},{pubkey:h,isSigner:0,isWritable:1},{pubkey:i.treeInfo.tree,isSigner:0,isWritable:1},{pubkey:i.treeInfo.queue,isSigner:0,isWritable:1},{pubkey:h,isSigner:0,isWritable:1}];return new t.TransactionInstruction({programId:e.LIGHT_TOKEN_PROGRAM_ID,keys:g,data:m})}function Nr(t,e,r,o,i,s,a=[]){const u=t.mint.address,c=t.programId;if(!t.merkleContext)return n.createMintToInstruction(u,e,r,BigInt(i.toString()),a,c);if(!t.mintContext)throw new Error("mintContext required for light-token mint-to");const l=r.equals(o)?void 0:o;return Kr({mint:u,destination:e,amount:i,authority:r,feePayer:l})}"function"==typeof SuppressedError&&SuppressedError;const Wr=1232;function Gr(t,e,n="Batch"){const r=Fr(t,e);if(r>Wr)throw new Error(`${n} exceeds max transaction size: ${r} > ${Wr}. This indicates a bug in batch assembly.`)}function qr(t){return t<128?1:t<16384?2:3}function Fr(t,e){const n=new Set;for(const e of t){n.add(e.programId.toBase58());for(const t of e.keys)n.add(t.pubkey.toBase58())}const r=n.size,o=qr(e)+64*e,i=qr(r)+32*r;let s=qr(t.length);for(const e of t)s+=1,s+=qr(e.keys.length),s+=e.keys.length,s+=qr(e.data.length),s+=e.data.length;return o+1+3+i+32+s+qr(0)}const Vr=1.3,Hr=5e4,zr=14e5;function jr(t,e){const n=e?Br(e):0,r=Math.ceil((t+n)*Vr);return Math.max(Hr,Math.min(zr,r))}const $r=12,Yr=1e4,Zr=1e4;function Qr(t){return jr(Yr+Zr,t)}function Xr(n,r,o,i,s,a,u){const c=Buffer.alloc(10);c.writeUInt8($r,0),c.writeBigUInt64LE(BigInt(s),1),c.writeUInt8(a,9);const l=[{pubkey:n,isSigner:0,isWritable:1},{pubkey:o,isSigner:0,isWritable:0},{pubkey:r,isSigner:0,isWritable:1},{pubkey:i,isSigner:1,isWritable:u.equals(i)},{pubkey:t.SystemProgram.programId,isSigner:0,isWritable:0},{pubkey:u,isSigner:!u.equals(i),isWritable:1}];return new t.TransactionInstruction({programId:e.LIGHT_TOKEN_PROGRAM_ID,keys:l,data:c})}async function Jr(r,o,i,s,a,u,c,l){e.assertBetaEnabled();const d=BigInt(s.toString());if(d<=BigInt(0))throw new Error("Transfer amount must be greater than zero.");const p=null!=l?l:{},{wrap:m=0,programId:h=e.LIGHT_TOKEN_PROGRAM_ID,owner:f}=p,g=function(t,e){var n={};for(var r in t)Object.prototype.hasOwnProperty.call(t,r)&&e.indexOf(r)<0&&(n[r]=t[r]);if(null!=t&&"function"==typeof Object.getOwnPropertySymbols){var o=0;for(r=Object.getOwnPropertySymbols(t);o<r.length;o++)e.indexOf(r[o])<0&&Object.prototype.propertyIsEnumerable.call(t,r[o])&&(n[r[o]]=t[r[o]])}return n}(p,["wrap","programId","owner"]),y=null!=f?f:a,b=h.equals(n.TOKEN_PROGRAM_ID)||h.equals(n.TOKEN_2022_PROGRAM_ID),w=zn(i,y,0,h);let I;try{I=await Wn(r,w,y,i,void 0,h.equals(e.LIGHT_TOKEN_PROGRAM_ID)?void 0:h,m)}catch(t){if(t instanceof n.TokenAccountNotFoundError)throw new Error("Sender has no token accounts for this mint.");throw t}if(On(I,"transfer"),y.equals(a)){if(I.parsed.amount<d)throw new Error(`Insufficient balance. Required: ${d}, Available: ${I.parsed.amount}`)}else{if(!Vn(I,a))throw new Error("Signer is not the owner or a delegate of the sender account.");const t=Fn(I,a);if(d>t)throw new Error(`Insufficient delegated balance. Required: ${d}, Available (delegate): ${t}`);I=Hn(I,a)}const A=await Dr(r,o,I,g,m,w,d,a,c);let v;v=b&&!m?n.createTransferCheckedInstruction(w,i,u,a,d,c,[],h):Xr(w,u,i,a,d,c,o);const T=o.equals(a)?1:2;if(0===A.length){const e=Qr(null),n=[t.ComputeBudgetProgram.setComputeUnitLimit({units:e}),v];return Gr(n,T,"Batch"),[n]}if(1===A.length){const e=A[0],n=Qr(e),r=[t.ComputeBudgetProgram.setComputeUnitLimit({units:n}),...e.instructions,v];return Gr(r,T,"Batch"),[r]}const k=[];for(let e=0;e<A.length-1;e++){const n=A[e],r=Lr(n),o=[t.ComputeBudgetProgram.setComputeUnitLimit({units:r}),...n.instructions];Gr(o,T,"Batch"),k.push(o)}const P=A[A.length-1],M=Qr(P),S=[t.ComputeBudgetProgram.setComputeUnitLimit({units:M}),...P.instructions,v];return Gr(S,T,"Batch"),k.push(S),k}function to(t){return jr(1e4,t)}function eo(n,r,o,i,s,a,u,c=o,l){const d=[mr(s,0,2,1,6),hr(s,0,3,4,a.poolIndex,a.bump,u)],p=lr({withTransactionHash:0,withLamportsChangeAccountMerkleTreeIndex:0,lamportsChangeAccountMerkleTreeIndex:0,lamportsChangeAccountOwnerIndex:0,outputQueue:0,maxTopUp:null!=l?l:yt,cpiContext:null,compressions:d,proof:null,inTokenData:[],outTokenData:[],inLamports:null,outLamports:null,inTlv:null,outTlv:null}),m=[{pubkey:ve.deriveCpiAuthorityPda,isSigner:0,isWritable:0},{pubkey:c,isSigner:1,isWritable:1},{pubkey:i,isSigner:0,isWritable:0},{pubkey:o,isSigner:1,isWritable:0},{pubkey:n,isSigner:0,isWritable:1},{pubkey:r,isSigner:0,isWritable:1},{pubkey:a.splInterfacePda,isSigner:0,isWritable:1},{pubkey:a.tokenProgram,isSigner:0,isWritable:0},{pubkey:e.LIGHT_TOKEN_PROGRAM_ID,isSigner:0,isWritable:0},{pubkey:t.SystemProgram.programId,isSigner:0,isWritable:0}];return new t.TransactionInstruction({programId:ve.programId,keys:m,data:p})}const no=w.from([10]),ro=w.from([11]),oo=4,io=5;function so(n,r,o,i,s){const a=w.alloc(9);a.writeUInt8(oo,0),a.writeBigUInt64LE(BigInt(i),1);const u=null!=s?s:o,c=[{pubkey:n,isSigner:0,isWritable:1},{pubkey:r,isSigner:0,isWritable:0},{pubkey:o,isSigner:1,isWritable:u.equals(o)},{pubkey:t.SystemProgram.programId,isSigner:0,isWritable:0},{pubkey:u,isSigner:!u.equals(o),isWritable:1}];return new t.TransactionInstruction({programId:e.LIGHT_TOKEN_PROGRAM_ID,keys:c,data:a})}function ao(n,r,o){const i=null!=o?o:r,s=[{pubkey:n,isSigner:0,isWritable:1},{pubkey:r,isSigner:1,isWritable:i.equals(r)},{pubkey:t.SystemProgram.programId,isSigner:0,isWritable:0},{pubkey:i,isSigner:!i.equals(r),isWritable:1}];return new t.TransactionInstruction({programId:e.LIGHT_TOKEN_PROGRAM_ID,keys:s,data:w.from([io])})}const uo=1e4;function co(t){return jr(uo,t)}const lo=1e4;function po(t){return jr(lo,t)}async function mo(r,o,i,s,a,u,c,l,d=e.LIGHT_TOKEN_PROGRAM_ID,p=0,m){e.assertBetaEnabled();const h=BigInt(u.toString()),f=d.equals(n.TOKEN_PROGRAM_ID)||d.equals(n.TOKEN_2022_PROGRAM_ID),g=await Wn(r,s,c,i,void 0,d.equals(e.LIGHT_TOKEN_PROGRAM_ID)?void 0:d,p);if(On(g,"approve"),f&&!p){const e=n.createApproveInstruction(s,a,c,h,[],d),r=o.equals(c)?1:2,i=[t.ComputeBudgetProgram.setComputeUnitLimit({units:uo}),e];return Gr(i,r,"Batch"),[i]}const y=await Dr(r,o,g,m,p,s,void 0,c,l),b=so(s,a,c,h,o),w=o.equals(c)?1:2;if(0===y.length){const e=co(null),n=[t.ComputeBudgetProgram.setComputeUnitLimit({units:e}),b];return Gr(n,w,"Batch"),[n]}if(1===y.length){const e=y[0],n=co(e),r=[t.ComputeBudgetProgram.setComputeUnitLimit({units:n}),...e.instructions,b];return Gr(r,w,"Batch"),[r]}const I=[];for(let e=0;e<y.length-1;e++){const n=y[e],r=Lr(n),o=[t.ComputeBudgetProgram.setComputeUnitLimit({units:r}),...n.instructions];Gr(o,w,"Batch"),I.push(o)}const A=y[y.length-1],v=co(A),T=[t.ComputeBudgetProgram.setComputeUnitLimit({units:v}),...A.instructions,b];return Gr(T,w,"Batch"),I.push(T),I}async function ho(r,o,i,s,a,u,c=e.LIGHT_TOKEN_PROGRAM_ID,l=0,d){e.assertBetaEnabled();const p=c.equals(n.TOKEN_PROGRAM_ID)||c.equals(n.TOKEN_2022_PROGRAM_ID),m=await Wn(r,s,a,i,void 0,c.equals(e.LIGHT_TOKEN_PROGRAM_ID)?void 0:c,l);if(On(m,"revoke"),p&&!l){const e=n.createRevokeInstruction(s,a,[],c),r=o.equals(a)?1:2,i=[t.ComputeBudgetProgram.setComputeUnitLimit({units:lo}),e];return Gr(i,r,"Batch"),[i]}const h=await Dr(r,o,m,d,l,s,void 0,a,u),f=ao(s,a,o),g=o.equals(a)?1:2;if(0===h.length){const e=po(null),n=[t.ComputeBudgetProgram.setComputeUnitLimit({units:e}),f];return Gr(n,g,"Batch"),[n]}if(1===h.length){const e=h[0],n=po(e),r=[t.ComputeBudgetProgram.setComputeUnitLimit({units:n}),...e.instructions,f];return Gr(r,g,"Batch"),[r]}const y=[];for(let e=0;e<h.length-1;e++){const n=h[e],r=Lr(n),o=[t.ComputeBudgetProgram.setComputeUnitLimit({units:r}),...n.instructions];Gr(o,g,"Batch"),y.push(o)}const b=h[h.length-1],w=po(b),I=[t.ComputeBudgetProgram.setComputeUnitLimit({units:w}),...b.instructions,f];return Gr(I,g,"Batch"),y.push(I),y}async function fo(r,o,i,s,a=t.Keypair.generate(),u,c,l){const d=await r.getMinimumBalanceForRentExemption(n.MINT_SIZE),p=1==c?n.TOKEN_2022_PROGRAM_ID:c||n.TOKEN_PROGRAM_ID,m=await ve.createMint({feePayer:o.publicKey,mint:a.publicKey,decimals:s,authority:"secretKey"in i?i.publicKey:i,freezeAuthority:l&&"secretKey"in l?l.publicKey:null!=l?l:null,rentExemptBalance:d,tokenProgramId:p}),{blockhash:h}=await r.getLatestBlockhash(),f=e.dedupeSigner(o,[i,null!=l?l:null].filter((t=>null!=t&&"secretKey"in t))),g=e.buildAndSignTx(m,o,h,[...f,a]),y=await e.sendAndConfirmTx(r,g,u);return{mint:a.publicKey,transactionSignature:y}}var go={};Object.defineProperty(go,"__esModule",{value:1}),go.s16=go.s8=go.nu64be=go.u48be=go.u40be=go.u32be=go.u24be=go.u16be=go.nu64=go.u48=go.u40=go.u32=go.u24=go.u16=ti=go.u8=go.offset=go.greedy=go.Constant=go.UTF8=go.CString=go.Blob=go.Boolean=go.BitField=go.BitStructure=go.VariantLayout=go.Union=go.UnionLayoutDiscriminator=go.UnionDiscriminator=go.Structure=go.Sequence=go.DoubleBE=go.Double=go.FloatBE=go.Float=go.NearInt64BE=go.NearInt64=go.NearUInt64BE=go.NearUInt64=go.IntBE=go.Int=go.UIntBE=go.UInt=go.OffsetLayout=go.GreedyCount=go.ExternalLayout=go.bindConstructorLayout=go.nameWithProperty=go.Layout=go.uint8ArrayToBuffer=go.checkUint8Array=void 0,go.constant=go.utf8=go.cstr=ni=go.blob=go.unionLayoutDiscriminator=go.union=go.seq=go.bits=ei=go.struct=go.f64be=go.f64=go.f32be=go.f32=go.ns64be=go.s48be=go.s40be=go.s32be=go.s24be=go.s16be=go.ns64=go.s48=go.s40=go.s32=go.s24=void 0;const yo=Tn;function bo(t){if(!(t instanceof Uint8Array))throw new TypeError("b must be a Uint8Array")}function wo(t){return bo(t),yo.Buffer.from(t.buffer,t.byteOffset,t.length)}go.checkUint8Array=bo,go.uint8ArrayToBuffer=wo;class Io{constructor(t,e){if(!Number.isInteger(t))throw new TypeError("span must be an integer");this.span=t,this.property=e}makeDestinationObject(){return{}}getSpan(t,e){if(0>this.span)throw new RangeError("indeterminate span");return this.span}replicate(t){const e=Object.create(this.constructor.prototype);return Object.assign(e,this),e.property=t,e}fromArray(t){}}function Ao(t,e){return e.property?t+"["+e.property+"]":t}go.Layout=Io,go.nameWithProperty=Ao,go.bindConstructorLayout=function(t,e){if("function"!=typeof t)throw new TypeError("Class must be constructor");if(Object.prototype.hasOwnProperty.call(t,"layout_"))throw new Error("Class is already bound to a layout");if(!(e&&e instanceof Io))throw new TypeError("layout must be a Layout");if(Object.prototype.hasOwnProperty.call(e,"boundConstructor_"))throw new Error("layout is already bound to a constructor");t.layout_=e,e.boundConstructor_=t,e.makeDestinationObject=()=>new t,Object.defineProperty(t.prototype,"encode",{value(t,n){return e.encode(this,t,n)},writable:1}),Object.defineProperty(t,"decode",{value:(t,n)=>e.decode(t,n),writable:1})};class vo extends Io{isCount(){throw new Error("ExternalLayout is abstract")}}go.ExternalLayout=vo;class To extends vo{constructor(t=1,e){if(!Number.isInteger(t)||0>=t)throw new TypeError("elementSpan must be a (positive) integer");super(-1,e),this.elementSpan=t}isCount(){return 1}decode(t,e=0){bo(t);const n=t.length-e;return Math.floor(n/this.elementSpan)}encode(t,e,n){return 0}}go.GreedyCount=To;class ko extends vo{constructor(t,e=0,n){if(!(t instanceof Io))throw new TypeError("layout must be a Layout");if(!Number.isInteger(e))throw new TypeError("offset must be integer or undefined");super(t.span,n||t.property),this.layout=t,this.offset=e}isCount(){return this.layout instanceof Po||this.layout instanceof Mo}decode(t,e=0){return this.layout.decode(t,e+this.offset)}encode(t,e,n=0){return this.layout.encode(t,e,n+this.offset)}}go.OffsetLayout=ko;class Po extends Io{constructor(t,e){if(super(t,e),6<this.span)throw new RangeError("span must not exceed 6 bytes")}decode(t,e=0){return wo(t).readUIntLE(e,this.span)}encode(t,e,n=0){return wo(e).writeUIntLE(t,n,this.span),this.span}}go.UInt=Po;class Mo extends Io{constructor(t,e){if(super(t,e),6<this.span)throw new RangeError("span must not exceed 6 bytes")}decode(t,e=0){return wo(t).readUIntBE(e,this.span)}encode(t,e,n=0){return wo(e).writeUIntBE(t,n,this.span),this.span}}go.UIntBE=Mo;class So extends Io{constructor(t,e){if(super(t,e),6<this.span)throw new RangeError("span must not exceed 6 bytes")}decode(t,e=0){return wo(t).readIntLE(e,this.span)}encode(t,e,n=0){return wo(e).writeIntLE(t,n,this.span),this.span}}go.Int=So;class xo extends Io{constructor(t,e){if(super(t,e),6<this.span)throw new RangeError("span must not exceed 6 bytes")}decode(t,e=0){return wo(t).readIntBE(e,this.span)}encode(t,e,n=0){return wo(e).writeIntBE(t,n,this.span),this.span}}go.IntBE=xo;const Co=Math.pow(2,32);function _o(t){const e=Math.floor(t/Co);return{hi32:e,lo32:t-e*Co}}function Eo(t,e){return t*Co+e}class Oo extends Io{constructor(t){super(8,t)}decode(t,e=0){const n=wo(t),r=n.readUInt32LE(e);return Eo(n.readUInt32LE(e+4),r)}encode(t,e,n=0){const r=_o(t),o=wo(e);return o.writeUInt32LE(r.lo32,n),o.writeUInt32LE(r.hi32,n+4),8}}go.NearUInt64=Oo;class Ro extends Io{constructor(t){super(8,t)}decode(t,e=0){const n=wo(t);return Eo(n.readUInt32BE(e),n.readUInt32BE(e+4))}encode(t,e,n=0){const r=_o(t),o=wo(e);return o.writeUInt32BE(r.hi32,n),o.writeUInt32BE(r.lo32,n+4),8}}go.NearUInt64BE=Ro;class Bo extends Io{constructor(t){super(8,t)}decode(t,e=0){const n=wo(t),r=n.readUInt32LE(e);return Eo(n.readInt32LE(e+4),r)}encode(t,e,n=0){const r=_o(t),o=wo(e);return o.writeUInt32LE(r.lo32,n),o.writeInt32LE(r.hi32,n+4),8}}go.NearInt64=Bo;class Lo extends Io{constructor(t){super(8,t)}decode(t,e=0){const n=wo(t);return Eo(n.readInt32BE(e),n.readUInt32BE(e+4))}encode(t,e,n=0){const r=_o(t),o=wo(e);return o.writeInt32BE(r.hi32,n),o.writeUInt32BE(r.lo32,n+4),8}}go.NearInt64BE=Lo;class Do extends Io{constructor(t){super(4,t)}decode(t,e=0){return wo(t).readFloatLE(e)}encode(t,e,n=0){return wo(e).writeFloatLE(t,n),4}}go.Float=Do;class Ko extends Io{constructor(t){super(4,t)}decode(t,e=0){return wo(t).readFloatBE(e)}encode(t,e,n=0){return wo(e).writeFloatBE(t,n),4}}go.FloatBE=Ko;class Uo extends Io{constructor(t){super(8,t)}decode(t,e=0){return wo(t).readDoubleLE(e)}encode(t,e,n=0){return wo(e).writeDoubleLE(t,n),8}}go.Double=Uo;class No extends Io{constructor(t){super(8,t)}decode(t,e=0){return wo(t).readDoubleBE(e)}encode(t,e,n=0){return wo(e).writeDoubleBE(t,n),8}}go.DoubleBE=No;class Wo extends Io{constructor(t,e,n){if(!(t instanceof Io))throw new TypeError("elementLayout must be a Layout");if(!(e instanceof vo&&e.isCount()||Number.isInteger(e)&&0<=e))throw new TypeError("count must be non-negative integer or an unsigned integer ExternalLayout");let r=-1;!(e instanceof vo)&&0<t.span&&(r=e*t.span),super(r,n),this.elementLayout=t,this.count=e}getSpan(t,e=0){if(0<=this.span)return this.span;let n=0,r=this.count;if(r instanceof vo&&(r=r.decode(t,e)),0<this.elementLayout.span)n=r*this.elementLayout.span;else{let o=0;for(;o<r;)n+=this.elementLayout.getSpan(t,e+n),++o}return n}decode(t,e=0){const n=[];let r=0,o=this.count;for(o instanceof vo&&(o=o.decode(t,e));r<o;)n.push(this.elementLayout.decode(t,e)),e+=this.elementLayout.getSpan(t,e),r+=1;return n}encode(t,e,n=0){const r=this.elementLayout,o=t.reduce(((t,o)=>t+r.encode(o,e,n+t)),0);return this.count instanceof vo&&this.count.encode(t.length,e,n),o}}go.Sequence=Wo;class Go extends Io{constructor(t,e,n){if(!Array.isArray(t)||!t.reduce(((t,e)=>t&&e instanceof Io),1))throw new TypeError("fields must be array of Layout instances");"boolean"==typeof e&&void 0===n&&(n=e,e=void 0);for(const e of t)if(0>e.span&&void 0===e.property)throw new Error("fields cannot contain unnamed variable-length layout");let r=-1;try{r=t.reduce(((t,e)=>t+e.getSpan()),0)}catch(t){}super(r,e),this.fields=t,this.decodePrefixes=!!n}getSpan(t,e=0){if(0<=this.span)return this.span;let n=0;try{n=this.fields.reduce(((n,r)=>{const o=r.getSpan(t,e);return e+=o,n+o}),0)}catch(t){throw new RangeError("indeterminate span")}return n}decode(t,e=0){bo(t);const n=this.makeDestinationObject();for(const r of this.fields)if(void 0!==r.property&&(n[r.property]=r.decode(t,e)),e+=r.getSpan(t,e),this.decodePrefixes&&t.length===e)break;return n}encode(t,e,n=0){const r=n;let o=0,i=0;for(const r of this.fields){let s=r.span;if(i=0<s?s:0,void 0!==r.property){const o=t[r.property];void 0!==o&&(i=r.encode(o,e,n),0>s&&(s=r.getSpan(e,n)))}o=n,n+=s}return o+i-r}fromArray(t){const e=this.makeDestinationObject();for(const n of this.fields)void 0!==n.property&&0<t.length&&(e[n.property]=t.shift());return e}layoutFor(t){if("string"!=typeof t)throw new TypeError("property must be string");for(const e of this.fields)if(e.property===t)return e}offsetOf(t){if("string"!=typeof t)throw new TypeError("property must be string");let e=0;for(const n of this.fields){if(n.property===t)return e;0>n.span?e=-1:0<=e&&(e+=n.span)}}}go.Structure=Go;class qo{constructor(t){this.property=t}decode(t,e){throw new Error("UnionDiscriminator is abstract")}encode(t,e,n){throw new Error("UnionDiscriminator is abstract")}}go.UnionDiscriminator=qo;class Fo extends qo{constructor(t,e){if(!(t instanceof vo&&t.isCount()))throw new TypeError("layout must be an unsigned integer ExternalLayout");super(e||t.property||"variant"),this.layout=t}decode(t,e){return this.layout.decode(t,e)}encode(t,e,n){return this.layout.encode(t,e,n)}}go.UnionLayoutDiscriminator=Fo;class Vo extends Io{constructor(t,e,n){let r;if(t instanceof Po||t instanceof Mo)r=new Fo(new ko(t));else if(t instanceof vo&&t.isCount())r=new Fo(t);else{if(!(t instanceof qo))throw new TypeError("discr must be a UnionDiscriminator or an unsigned integer layout");r=t}if(void 0===e&&(e=null),!(null===e||e instanceof Io))throw new TypeError("defaultLayout must be null or a Layout");if(null!==e){if(0>e.span)throw new Error("defaultLayout must have constant span");void 0===e.property&&(e=e.replicate("content"))}let o=-1;e&&(o=e.span,0<=o&&(t instanceof Po||t instanceof Mo)&&(o+=r.layout.span)),super(o,n),this.discriminator=r,this.usesPrefixDiscriminator=t instanceof Po||t instanceof Mo,this.defaultLayout=e,this.registry={};let i=this.defaultGetSourceVariant.bind(this);this.getSourceVariant=function(t){return i(t)},this.configGetSourceVariant=function(t){i=t.bind(this)}}getSpan(t,e=0){if(0<=this.span)return this.span;const n=this.getVariant(t,e);if(!n)throw new Error("unable to determine span for unrecognized variant");return n.getSpan(t,e)}defaultGetSourceVariant(t){if(Object.prototype.hasOwnProperty.call(t,this.discriminator.property)){if(this.defaultLayout&&this.defaultLayout.property&&Object.prototype.hasOwnProperty.call(t,this.defaultLayout.property))return;const e=this.registry[t[this.discriminator.property]];if(e&&(!e.layout||e.property&&Object.prototype.hasOwnProperty.call(t,e.property)))return e}else for(const e in this.registry){const n=this.registry[e];if(n.property&&Object.prototype.hasOwnProperty.call(t,n.property))return n}throw new Error("unable to infer src variant")}decode(t,e=0){let n;const r=this.discriminator,o=r.decode(t,e),i=this.registry[o];if(void 0===i){const i=this.defaultLayout;let s=0;this.usesPrefixDiscriminator&&(s=r.layout.span),n=this.makeDestinationObject(),n[r.property]=o,n[i.property]=i.decode(t,e+s)}else n=i.decode(t,e);return n}encode(t,e,n=0){const r=this.getSourceVariant(t);if(void 0===r){const r=this.discriminator,o=this.defaultLayout;let i=0;return this.usesPrefixDiscriminator&&(i=r.layout.span),r.encode(t[r.property],e,n),i+o.encode(t[o.property],e,n+i)}return r.encode(t,e,n)}addVariant(t,e,n){const r=new Ho(this,t,e,n);return this.registry[t]=r,r}getVariant(t,e=0){let n;return n=t instanceof Uint8Array?this.discriminator.decode(t,e):t,this.registry[n]}}go.Union=Vo;class Ho extends Io{constructor(t,e,n,r){if(!(t instanceof Vo))throw new TypeError("union must be a Union");if(!Number.isInteger(e)||0>e)throw new TypeError("variant must be a (non-negative) integer");if("string"==typeof n&&void 0===r&&(r=n,n=null),n){if(!(n instanceof Io))throw new TypeError("layout must be a Layout");if(null!==t.defaultLayout&&0<=n.span&&n.span>t.defaultLayout.span)throw new Error("variant span exceeds span of containing union");if("string"!=typeof r)throw new TypeError("variant must have a String property")}let o=t.span;0>t.span&&(o=n?n.span:0,0<=o&&t.usesPrefixDiscriminator&&(o+=t.discriminator.layout.span)),super(o,r),this.union=t,this.variant=e,this.layout=n||null}getSpan(t,e=0){if(0<=this.span)return this.span;let n=0;this.union.usesPrefixDiscriminator&&(n=this.union.discriminator.layout.span);let r=0;return this.layout&&(r=this.layout.getSpan(t,e+n)),n+r}decode(t,e=0){const n=this.makeDestinationObject();if(this!==this.union.getVariant(t,e))throw new Error("variant mismatch");let r=0;return this.union.usesPrefixDiscriminator&&(r=this.union.discriminator.layout.span),this.layout?n[this.property]=this.layout.decode(t,e+r):this.property?n[this.property]=1:this.union.usesPrefixDiscriminator&&(n[this.union.discriminator.property]=this.variant),n}encode(t,e,n=0){let r=0;if(this.union.usesPrefixDiscriminator&&(r=this.union.discriminator.layout.span),this.layout&&!Object.prototype.hasOwnProperty.call(t,this.property))throw new TypeError("variant lacks property "+this.property);this.union.discriminator.encode(this.variant,e,n);let o=r;if(this.layout&&(this.layout.encode(t[this.property],e,n+r),o+=this.layout.getSpan(e,n+r),0<=this.union.span&&o>this.union.span))throw new Error("encoded variant overruns containing union");return o}fromArray(t){if(this.layout)return this.layout.fromArray(t)}}function zo(t){return 0>t&&(t+=4294967296),t}go.VariantLayout=Ho;class jo extends Io{constructor(t,e,n){if(!(t instanceof Po||t instanceof Mo))throw new TypeError("word must be a UInt or UIntBE layout");if("string"==typeof e&&void 0===n&&(n=e,e=0),4<t.span)throw new RangeError("word cannot exceed 32 bits");super(t.span,n),this.word=t,this.msb=!!e,this.fields=[];let r=0;this._packedSetValue=function(t){return r=zo(t),this},this._packedGetValue=function(){return r}}decode(t,e=0){const n=this.makeDestinationObject(),r=this.word.decode(t,e);this._packedSetValue(r);for(const e of this.fields)void 0!==e.property&&(n[e.property]=e.decode(t));return n}encode(t,e,n=0){const r=this.word.decode(e,n);this._packedSetValue(r);for(const e of this.fields)if(void 0!==e.property){const n=t[e.property];void 0!==n&&e.encode(n)}return this.word.encode(this._packedGetValue(),e,n)}addField(t,e){const n=new $o(this,t,e);return this.fields.push(n),n}addBoolean(t){const e=new Yo(this,t);return this.fields.push(e),e}fieldFor(t){if("string"!=typeof t)throw new TypeError("property must be string");for(const e of this.fields)if(e.property===t)return e}}go.BitStructure=jo;class $o{constructor(t,e,n){if(!(t instanceof jo))throw new TypeError("container must be a BitStructure");if(!Number.isInteger(e)||0>=e)throw new TypeError("bits must be positive integer");const r=8*t.span,o=t.fields.reduce(((t,e)=>t+e.bits),0);if(e+o>r)throw new Error("bits too long for span remainder ("+(r-o)+" of "+r+" remain)");this.container=t,this.bits=e,this.valueMask=(1<<e)-1,32===e&&(this.valueMask=4294967295),this.start=o,this.container.msb&&(this.start=r-o-e),this.wordMask=zo(this.valueMask<<this.start),this.property=n}decode(t,e){return zo(this.container._packedGetValue()&this.wordMask)>>>this.start}encode(t){if("number"!=typeof t||!Number.isInteger(t)||t!==zo(t&this.valueMask))throw new TypeError(Ao("BitField.encode",this)+" value must be integer not exceeding "+this.valueMask);const e=this.container._packedGetValue(),n=zo(t<<this.start);this.container._packedSetValue(zo(e&~this.wordMask)|n)}}go.BitField=$o;class Yo extends $o{constructor(t,e){super(t,1,e)}decode(t,e){return!!super.decode(t,e)}encode(t){"boolean"==typeof t&&(t=+t),super.encode(t)}}go.Boolean=Yo;class Zo extends Io{constructor(t,e){if(!(t instanceof vo&&t.isCount()||Number.isInteger(t)&&0<=t))throw new TypeError("length must be positive integer or an unsigned integer ExternalLayout");let n=-1;t instanceof vo||(n=t),super(n,e),this.length=t}getSpan(t,e){let n=this.span;return 0>n&&(n=this.length.decode(t,e)),n}decode(t,e=0){let n=this.span;return 0>n&&(n=this.length.decode(t,e)),wo(t).slice(e,e+n)}encode(t,e,n){let r=this.length;if(this.length instanceof vo&&(r=t.length),!(t instanceof Uint8Array&&r===t.length))throw new TypeError(Ao("Blob.encode",this)+" requires (length "+r+") Uint8Array as src");if(n+r>e.length)throw new RangeError("encoding overruns Uint8Array");const o=wo(t);return wo(e).write(o.toString("hex"),n,r,"hex"),this.length instanceof vo&&this.length.encode(r,e,n),r}}go.Blob=Zo;class Qo extends Io{constructor(t){super(-1,t)}getSpan(t,e=0){bo(t);let n=e;for(;n<t.length&&0!==t[n];)n+=1;return 1+n-e}decode(t,e=0){const n=this.getSpan(t,e);return wo(t).slice(e,e+n-1).toString("utf-8")}encode(t,e,n=0){"string"!=typeof t&&(t=String(t));const r=yo.Buffer.from(t,"utf8"),o=r.length;if(n+o>e.length)throw new RangeError("encoding overruns Buffer");const i=wo(e);return r.copy(i,n),i[n+o]=0,o+1}}go.CString=Qo;class Xo extends Io{constructor(t,e){if("string"==typeof t&&void 0===e&&(e=t,t=void 0),void 0===t)t=-1;else if(!Number.isInteger(t))throw new TypeError("maxSpan must be an integer");super(-1,e),this.maxSpan=t}getSpan(t,e=0){return bo(t),t.length-e}decode(t,e=0){const n=this.getSpan(t,e);if(0<=this.maxSpan&&this.maxSpan<n)throw new RangeError("text length exceeds maxSpan");return wo(t).slice(e,e+n).toString("utf-8")}encode(t,e,n=0){"string"!=typeof t&&(t=String(t));const r=yo.Buffer.from(t,"utf8"),o=r.length;if(0<=this.maxSpan&&this.maxSpan<o)throw new RangeError("text length exceeds maxSpan");if(n+o>e.length)throw new RangeError("encoding overruns Buffer");return r.copy(wo(e),n),o}}go.UTF8=Xo;class Jo extends Io{constructor(t,e){super(0,e),this.value=t}decode(t,e){return this.value}encode(t,e,n){return 0}}go.Constant=Jo,go.greedy=(t,e)=>new To(t,e),go.offset=(t,e,n)=>new ko(t,e,n);var ti=go.u8=t=>new Po(1,t);go.u16=t=>new Po(2,t),go.u24=t=>new Po(3,t),go.u32=t=>new Po(4,t),go.u40=t=>new Po(5,t),go.u48=t=>new Po(6,t),go.nu64=t=>new Oo(t),go.u16be=t=>new Mo(2,t),go.u24be=t=>new Mo(3,t),go.u32be=t=>new Mo(4,t),go.u40be=t=>new Mo(5,t),go.u48be=t=>new Mo(6,t),go.nu64be=t=>new Ro(t),go.s8=t=>new So(1,t),go.s16=t=>new So(2,t),go.s24=t=>new So(3,t),go.s32=t=>new So(4,t),go.s40=t=>new So(5,t),go.s48=t=>new So(6,t),go.ns64=t=>new Bo(t),go.s16be=t=>new xo(2,t),go.s24be=t=>new xo(3,t),go.s32be=t=>new xo(4,t),go.s40be=t=>new xo(5,t),go.s48be=t=>new xo(6,t),go.ns64be=t=>new Lo(t),go.f32=t=>new Do(t),go.f32be=t=>new Ko(t),go.f64=t=>new Uo(t),go.f64be=t=>new No(t);var ei=go.struct=(t,e,n)=>new Go(t,e,n);go.bits=(t,e,n)=>new jo(t,e,n),go.seq=(t,e,n)=>new Wo(t,e,n),go.union=(t,e,n)=>new Vo(t,e,n),go.unionLayoutDiscriminator=(t,e)=>new Fo(t,e);var ni=go.blob=(t,e)=>new Zo(t,e);go.cstr=t=>new Qo(t),go.utf8=(t,e)=>new Xo(t,e),go.constant=(t,e)=>new Jo(t,e);const ri=r.struct([r.publicKey("updateAuthority"),r.publicKey("mint"),r.vecU8("name"),r.vecU8("symbol"),r.vecU8("uri"),r.vec(r.struct([r.vecU8("key"),r.vecU8("value")]),"additionalMetadata")]),oi=ei([ti("version"),ti("cmintDecompressed"),(()=>{const e=ni(32,"splMint"),{encode:n,decode:r}=(t=>({decode:t.decode.bind(t),encode:t.encode.bind(t)}))(e),o=e;return o.decode=(e,n)=>{const o=r(e,n);return new t.PublicKey(o)},o.encode=(t,e,r)=>{const o=t.toBuffer();return n(o,e,r)},o})()]),ii=oi.span,si=32,ai=1,ui=16,ci=1;function li(t,e,n){return t===exports.ExtensionType.TokenMetadata?function(t,e){let n=e;n+=32,n+=32,n+=4+t.readUInt32LE(n),n+=4+t.readUInt32LE(n),n+=4+t.readUInt32LE(n);const r=t.readUInt32LE(n);n+=4;for(let e=0;e<r;e++)n+=4+t.readUInt32LE(n),n+=4+t.readUInt32LE(n);return n-e}(e,n):e.length-n}function di(e){const r=e instanceof w?e:w.from(e);let o=0;const i=n.MintLayout.decode(r.slice(o,o+n.MINT_SIZE));o+=n.MINT_SIZE;const s=oi.decode(r.slice(o,o+ii));o+=ii;const a=r.slice(o,o+si);o+=si;const u=r.readUInt8(o);o+=ai;const c=r.slice(o,o+ui);o+=ui;const l=r.readUInt8(o);o+=ci;const[d,p]=function(e,n){const r=n,o=e.readUInt16LE(n);n+=2;const i=e.readUInt8(n);n+=1;const s=e.readUInt8(n);n+=1;const a=e.readUInt32LE(n);n+=4;const u=new t.PublicKey(e.slice(n,n+32));n+=32;const c=new t.PublicKey(e.slice(n,n+32));n+=32;const l=e.readBigUInt64LE(n);n+=8;const d=e.readUInt32LE(n);n+=4;const p=e.readUInt32LE(n);n+=4;const m=e.readUInt16LE(n);n+=2;const h=e.readUInt16LE(n);n+=2;const f=e.readUInt8(n);n+=1;const g=e.readUInt8(n);return n+=1,[{configAccountVersion:o,compressToPubkey:i,accountVersion:s,lamportsPerWrite:a,compressionAuthority:u,rentSponsor:c,lastClaimedSlot:l,rentExemptionPaid:d,reserved:p,rentConfig:{baseRent:m,compressionCost:h,lamportsPerBytePerEpoch:f,maxFundedEpochs:g,maxTopUp:e.readUInt16LE(n)}},(n+=2)-r]}(r,o);o+=p;const m=1===r.readUInt8(o);o+=1;let h=null;if(m){const t=r.readUInt32LE(o);o+=4,h=[];for(let e=0;e<t;e++){const t=r.readUInt8(o);o+=1;const e=li(t,r,o),n=r.slice(o,o+e);o+=e,h.push({extensionType:t,data:n})}}return{base:{mintAuthority:1===i.mintAuthorityOption?i.mintAuthority:null,supply:i.supply,decimals:i.decimals,isInitialized:i.isInitialized,freezeAuthority:1===i.freezeAuthorityOption?i.freezeAuthority:null},mintContext:{version:s.version,cmintDecompressed:0!==s.cmintDecompressed,splMint:s.splMint,mintSigner:a,bump:u},reserved:c,accountType:l,compression:d,extensions:h}}var pi;function mi(t){try{const e=w.from(t);if(e.length<80)return null;const n=ri.decode(e),r=n.updateAuthority.toBuffer().every((t=>0===t))?void 0:n.updateAuthority,o=w.from(n.name).toString("utf-8"),i=w.from(n.symbol).toString("utf-8"),s=w.from(n.uri).toString("utf-8");let a;return n.additionalMetadata&&n.additionalMetadata.length>0&&(a=n.additionalMetadata.map((t=>({key:w.from(t.key).toString("utf-8"),value:w.from(t.value).toString("utf-8")})))),{updateAuthority:r,mint:n.mint,name:o,symbol:i,uri:s,additionalMetadata:a}}catch(t){return console.error("Failed to decode TokenMetadata:",t),null}}exports.ExtensionType=void 0,(pi=exports.ExtensionType||(exports.ExtensionType={}))[pi.TokenMetadata=19]="TokenMetadata";const hi=mi;function fi(t){if(!t)return null;const e=t.find((t=>t.extensionType===exports.ExtensionType.TokenMetadata));return e?hi(e.data):null}async function gi(t,r,o,i){var s,a;if(e.assertBetaEnabled(),!i){const[i,s,u]=await Promise.allSettled([gi(t,r,o,n.TOKEN_PROGRAM_ID),gi(t,r,o,n.TOKEN_2022_PROGRAM_ID),gi(t,r,o,e.LIGHT_TOKEN_PROGRAM_ID)]);if("fulfilled"===i.status)return i.value;if("fulfilled"===s.status)return s.value;if("fulfilled"===u.status)return u.value;const c=[i,s,u].filter((t=>"rejected"===t.status)).map((t=>t.reason)),l=c.find((t=>t instanceof n.TokenInvalidAccountOwnerError));if(l)throw l;const d=c.length>0&&c.every((t=>t instanceof n.TokenAccountNotFoundError));if(d)throw new n.TokenAccountNotFoundError(`Mint not found: ${r.toString()}. Tried TOKEN_PROGRAM_ID, TOKEN_2022_PROGRAM_ID, and LIGHT_TOKEN_PROGRAM_ID.`);const p=c.find((t=>!(t instanceof n.TokenAccountNotFoundError||t instanceof n.TokenInvalidAccountOwnerError)));if(p)throw new Error(`Failed to fetch mint data from RPC: ${a=p,a instanceof Error?a.message:String(a)}`);throw new n.TokenAccountNotFoundError(`Mint not found: ${r.toString()}. Tried TOKEN_PROGRAM_ID, TOKEN_2022_PROGRAM_ID, and LIGHT_TOKEN_PROGRAM_ID.`)}if(i.equals(e.LIGHT_TOKEN_PROGRAM_ID)){const a=e.getDefaultAddressTreeInfo().tree,u=e.deriveAddressV2(r.toBytes(),a,e.LIGHT_TOKEN_PROGRAM_ID),c=await t.getCompressedAccount(e.bn(u.toBytes()));if(!(null===(s=null==c?void 0:c.data)||void 0===s?void 0:s.data))throw new n.TokenAccountNotFoundError(`Light mint not found for ${r.toString()}`);if(!c.owner.equals(e.LIGHT_TOKEN_PROGRAM_ID))throw new n.TokenInvalidAccountOwnerError;const l=w.from(c.data.data),d=64;let p;if(l.length<d){const i=await t.getAccountInfo(r,o);if(!(null==i?void 0:i.data))throw new n.TokenAccountNotFoundError(`Decompressed light mint account not found on-chain for ${r.toString()}`);if(!i.owner.equals(e.LIGHT_TOKEN_PROGRAM_ID))throw new n.TokenInvalidAccountOwnerError;p=di(w.from(i.data))}else p=di(l);const m={address:r,mintAuthority:p.base.mintAuthority,supply:p.base.supply,decimals:p.base.decimals,isInitialized:p.base.isInitialized,freezeAuthority:p.base.freezeAuthority,tlvData:w.alloc(0)},h={treeInfo:c.treeInfo,hash:c.hash,leafIndex:c.leafIndex,proveByIndex:c.proveByIndex},f=fi(p.extensions),g={mint:m,programId:i,merkleContext:h,mintContext:p.mintContext,tokenMetadata:f||void 0,extensions:p.extensions||void 0,compression:p.compression};if(!g.merkleContext)throw new Error("Invalid light mint: merkleContext is required for LIGHT_TOKEN_PROGRAM_ID");if(!g.mintContext)throw new Error("Invalid light mint: mintContext is required for LIGHT_TOKEN_PROGRAM_ID");return g}return{mint:await n.getMint(t,r,o,i),programId:i}}function yi(t){if(!t.tokenMetadata)throw new Error("Mint does not have TokenMetadata extension");if(!t.merkleContext)throw new Error(Sn)}async function bi(t,n,r,o,i,s,a,u=0,c){e.assertBetaEnabled(),null!=i||(i=r);const l=null!=c?c:(await gi(t,o)).mint.decimals,d=await kr(t,n,r.publicKey,o,l,i.publicKey,a,u);if(0===d.length)return null;const p=e.dedupeSigner(i,[r]),m=d.map((async n=>{const{blockhash:r}=await t.getLatestBlockhash(),o=e.buildAndSignTx(n,i,r,p);return e.sendAndConfirmTx(t,o,s)})),h=await Promise.all(m);return h[h.length-1]}function wi(t){if(!("publicKey"in t)||!("secretKey"in t))return 0;const e=t;return e.secretKey instanceof Uint8Array&&e.secretKey.length>0}function Ii(t){return wi(t)?t.publicKey:t}async function Ai(r,o,i,s,a,u,c,l,d,p){const m=Ii(s),h=n.getAssociatedTokenAddressSync(i,m,a,l,d);return l.equals(e.LIGHT_TOKEN_PROGRAM_ID)?async function(t,r,o,i,s,a,u,c=0,l=0){var d,p,m;const h=Ii(i);let f;wi(i);let g=0;try{f=await Wn(t,s,h,o,a,e.LIGHT_TOKEN_PROGRAM_ID,c,l),g=null!==(p=null===(d=f._sources)||void 0===d?void 0:d.some((t=>t.type===xn.LightTokenHot)))&&void 0!==p?p:0}catch(i){if(!(i instanceof n.TokenAccountNotFoundError||i instanceof n.TokenInvalidAccountOwnerError))throw i;await vi(t,r,o,h,s,u),f=await Wn(t,s,h,o,a,e.LIGHT_TOKEN_PROGRAM_ID,c,l),g=1}g||await vi(t,r,o,h,s,u);const y=wi(i)?i:r.publicKey.equals(h)?r:null;if(y){const n=null!==(m=f._sources)&&void 0!==m?m:[],i=n.some((t=>t.type===xn.LightTokenCold&&t.amount>BigInt(0))),d=c&&n.some((t=>(t.type===xn.Spl||t.type===xn.Token2022)&&t.amount>BigInt(0)));if(i||d){if(!(y.secretKey instanceof Uint8Array)||0===y.secretKey.length)throw new Error("Owner must be a valid Signer with secretKey to auto-load");await bi(t,s,y,o,r,u,void 0,c),f=await Wn(t,s,h,o,a,e.LIGHT_TOKEN_PROGRAM_ID,c,l)}}const b=f.parsed;if(!b.mint.equals(o))throw new n.TokenInvalidMintError;if(!b.owner.equals(h))throw new n.TokenInvalidOwnerError;return f}(r,o,i,s,h,u,c,p,a):async function(e,r,o,i,s,a,u,c,l){let d;try{d=await Nn(e,s,c,a)}catch(p){if(!(p instanceof n.TokenAccountNotFoundError||p instanceof n.TokenInvalidAccountOwnerError))throw p;try{const n=(new t.Transaction).add(gn(r.publicKey,s,i,o,a,u));await t.sendAndConfirmTransaction(e,n,[r],l)}catch(t){try{await Nn(e,s,c,a)}catch(e){throw t}}d=await Nn(e,s,c,a)}const p=d.parsed;if(!p.mint.equals(o))throw new n.TokenInvalidMintError;if(!p.owner.equals(i))throw new n.TokenInvalidOwnerError;return d}(r,o,i,m,h,l,d,u,c)}async function vi(n,r,o,i,s,a){const u=yn(r.publicKey,s,i,o,e.LIGHT_TOKEN_PROGRAM_ID),{blockhash:c}=await n.getLatestBlockhash(),l=e.buildAndSignTx([t.ComputeBudgetProgram.setComputeUnitLimit({units:2e5}),u],r,c,[]);await e.sendAndConfirmTx(n,l,a)}function Ti(t){if(0===t.length)throw new Error("sliceLast: array must not be empty");return{rest:t.slice(0,-1),last:t.at(-1)}}async function ki(n,r,o,i,s,a,u,c){var l;const d=null!==(l=null==c?void 0:c.programId)&&void 0!==l?l:e.LIGHT_TOKEN_PROGRAM_ID,p=zn(o,a,0,d),m=await Jr(n,r,o,i,s,p,u,c),h=yn(r,p,a,o,d),f=m[m.length-1];let g=0;for(;g<f.length&&f[g].programId.equals(t.ComputeBudgetProgram.programId);)g+=1;const y=[...f.slice(0,g),h,...f.slice(g)];return Gr(y,r.equals(s)?1:2,"Final transfer batch"),[...m.slice(0,-1),y]}async function Pi(t,n,r,o,i){i=i||await ve.getMintProgramId(r,t);const s=await ve.createSplInterface({feePayer:n.publicKey,mint:r,tokenProgramId:i}),{blockhash:a}=await t.getLatestBlockhash(),u=e.buildAndSignTx([s],n,a);return await e.sendAndConfirmTx(t,u,o)}const Mi=Pi;async function Si(t,n,r,o,i,s){s=s||await ve.getMintProgramId(r,t);const a=[],u=(await kt(t,r)).slice(0,4),c=[];for(let t=0;t<u.length;t++)u[t].isInitialized||c.push(t);for(let t=0;t<o&&!(t>=c.length);t++)a.push(await ve.addTokenPool({mint:r,feePayer:n.publicKey,tokenProgramId:s,poolIndex:c[t]}));const{blockhash:l}=await t.getLatestBlockhash(),d=e.buildAndSignTx(a,n,l);return await e.sendAndConfirmTx(t,d,i)}const xi=Si;function Ci(t){return!Array.isArray(t)}const _i=Ci;exports.ADD_TOKEN_POOL_DISCRIMINATOR=gt,exports.APPROVE_DISCRIMINATOR=ht,exports.BASE_RENT_PER_EPOCH=128,exports.BATCH_COMPRESS_DISCRIMINATOR=dt,exports.COMPRESSED_MINT_SEED=ke,exports.COMPRESSIBLE_LIGHT_TOKEN_ACCOUNT_SIZE=272,exports.COMPRESSIBLE_LIGHT_TOKEN_RENT_PER_EPOCH=wt,exports.COMPRESSION_COST=1e4,exports.COMPRESSION_INCENTIVE=1e3,exports.COMPRESS_SPL_TOKEN_ACCOUNT_DISCRIMINATOR=mt,exports.CPI_AUTHORITY_SEED=ut,exports.CREATE_TOKEN_POOL_DISCRIMINATOR=ct,exports.CompressedTokenInstructionDataApproveLayout=ue,exports.CompressedTokenInstructionDataRevokeLayout=ce,exports.CompressedTokenInstructionDataTransferLayout=zt,exports.CompressedTokenProgram=ve,exports.CpiContextLayout=Ht,exports.DEFAULT_COMPRESSIBLE_CONFIG=un,exports.DEFAULT_PREPAY_EPOCHS=16,exports.DEFAULT_WRITE_TOP_UP=766,exports.DelegatedTransferLayout=Vt,exports.ERROR_MIXED_TREE_TYPES=_t,exports.ERROR_NO_ACCOUNTS_FOUND=Ct,exports.IDL={version:"1.2.0",name:"light_compressed_token",instructions:[{name:"createTokenPool",docs:["This instruction creates a token pool for a given mint. Every spl mint","can have one token pool. When a token is compressed the tokens are","transferrred to the token pool, and their compressed equivalent is","minted into a Merkle tree."],accounts:[{name:"feePayer",isMut:1,isSigner:1,docs:["UNCHECKED: only pays fees."]},{name:"tokenPoolPda",isMut:1,isSigner:0},{name:"systemProgram",isMut:0,isSigner:0},{name:"mint",isMut:1,isSigner:0},{name:"tokenProgram",isMut:0,isSigner:0},{name:"cpiAuthorityPda",isMut:0,isSigner:0}],args:[]},{name:"addTokenPool",docs:["This instruction creates an additional token pool for a given mint.","The maximum number of token pools per mint is 5."],accounts:[{name:"feePayer",isMut:1,isSigner:1,docs:["UNCHECKED: only pays fees."]},{name:"tokenPoolPda",isMut:1,isSigner:0},{name:"existingTokenPoolPda",isMut:0,isSigner:0},{name:"systemProgram",isMut:0,isSigner:0},{name:"mint",isMut:1,isSigner:0},{name:"tokenProgram",isMut:0,isSigner:0},{name:"cpiAuthorityPda",isMut:0,isSigner:0}],args:[{name:"tokenPoolIndex",type:"u8"}]},{name:"mintTo",docs:["Mints tokens from an spl token mint to a list of compressed accounts.","Minted tokens are transferred to a pool account owned by the compressed","token program. The instruction creates one compressed output account for","every amount and pubkey input pair. A constant amount of lamports can be","transferred to each output account to enable. A use case to add lamports","to a compressed token account is to prevent spam. This is the only way","to add lamports to a compressed token account."],accounts:[{name:"feePayer",isMut:1,isSigner:1,docs:["UNCHECKED: only pays fees."]},{name:"authority",isMut:0,isSigner:1},{name:"cpiAuthorityPda",isMut:0,isSigner:0},{name:"mint",isMut:1,isSigner:0},{name:"tokenPoolPda",isMut:1,isSigner:0},{name:"tokenProgram",isMut:0,isSigner:0},{name:"lightSystemProgram",isMut:0,isSigner:0},{name:"registeredProgramPda",isMut:0,isSigner:0},{name:"noopProgram",isMut:0,isSigner:0,docs:["programs"]},{name:"accountCompressionAuthority",isMut:0,isSigner:0},{name:"accountCompressionProgram",isMut:0,isSigner:0},{name:"merkleTree",isMut:1,isSigner:0},{name:"selfProgram",isMut:0,isSigner:0},{name:"systemProgram",isMut:0,isSigner:0},{name:"solPoolPda",isMut:1,isSigner:0,isOptional:1}],args:[{name:"publicKeys",type:{vec:"publicKey"}},{name:"amounts",type:{vec:"u64"}},{name:"lamports",type:{option:"u64"}}]},{name:"compressSplTokenAccount",docs:["Compresses the balance of an spl token account sub an optional remaining","amount. This instruction does not close the spl token account. To close","the account bundle a close spl account instruction in your transaction."],accounts:[{name:"feePayer",isMut:1,isSigner:1,docs:["UNCHECKED: only pays fees."]},{name:"authority",isMut:0,isSigner:1,docs:["Authority is verified through proof since both owner and delegate","are included in the token data hash, which is a public input to the","validity proof."]},{name:"cpiAuthorityPda",isMut:0,isSigner:0},{name:"lightSystemProgram",isMut:0,isSigner:0},{name:"registeredProgramPda",isMut:0,isSigner:0},{name:"noopProgram",isMut:0,isSigner:0},{name:"accountCompressionAuthority",isMut:0,isSigner:0},{name:"accountCompressionProgram",isMut:0,isSigner:0},{name:"selfProgram",isMut:0,isSigner:0,docs:["this program is the signer of the cpi."]},{name:"tokenPoolPda",isMut:1,isSigner:0,isOptional:1},{name:"compressOrDecompressTokenAccount",isMut:1,isSigner:0,isOptional:1},{name:"tokenProgram",isMut:0,isSigner:0,isOptional:1},{name:"systemProgram",isMut:0,isSigner:0}],args:[{name:"owner",type:"publicKey"},{name:"remainingAmount",type:{option:"u64"}},{name:"cpiContext",type:{option:{defined:"CompressedCpiContext"}}}]},{name:"transfer",docs:["Transfers compressed tokens from one account to another. All accounts","must be of the same mint. Additional spl tokens can be compressed or","decompressed. In one transaction only compression or decompression is","possible. Lamports can be transferred alongside tokens. If output token","accounts specify less lamports than inputs the remaining lamports are","transferred to an output compressed account. Signer must be owner or","delegate. If a delegated token account is transferred the delegate is","not preserved."],accounts:[{name:"feePayer",isMut:1,isSigner:1,docs:["UNCHECKED: only pays fees."]},{name:"authority",isMut:0,isSigner:1,docs:["Authority is verified through proof since both owner and delegate","are included in the token data hash, which is a public input to the","validity proof."]},{name:"cpiAuthorityPda",isMut:0,isSigner:0},{name:"lightSystemProgram",isMut:0,isSigner:0},{name:"registeredProgramPda",isMut:0,isSigner:0},{name:"noopProgram",isMut:0,isSigner:0},{name:"accountCompressionAuthority",isMut:0,isSigner:0},{name:"accountCompressionProgram",isMut:0,isSigner:0},{name:"selfProgram",isMut:0,isSigner:0,docs:["this program is the signer of the cpi."]},{name:"tokenPoolPda",isMut:1,isSigner:0,isOptional:1},{name:"compressOrDecompressTokenAccount",isMut:1,isSigner:0,isOptional:1},{name:"tokenProgram",isMut:0,isSigner:0,isOptional:1},{name:"systemProgram",isMut:0,isSigner:0}],args:[{name:"inputs",type:"bytes"}]},{name:"approve",docs:["Delegates an amount to a delegate. A compressed token account is either","completely delegated or not. Prior delegates are not preserved. Cannot","be called by a delegate.","The instruction creates two output accounts:","1. one account with delegated amount","2. one account with remaining(change) amount"],accounts:[{name:"feePayer",isMut:1,isSigner:1,docs:["UNCHECKED: only pays fees."]},{name:"authority",isMut:0,isSigner:1,docs:["Authority is verified through proof since both owner and delegate","are included in the token data hash, which is a public input to the","validity proof."]},{name:"cpiAuthorityPda",isMut:0,isSigner:0},{name:"lightSystemProgram",isMut:0,isSigner:0},{name:"registeredProgramPda",isMut:0,isSigner:0},{name:"noopProgram",isMut:0,isSigner:0},{name:"accountCompressionAuthority",isMut:0,isSigner:0},{name:"accountCompressionProgram",isMut:0,isSigner:0},{name:"selfProgram",isMut:0,isSigner:0,docs:["this program is the signer of the cpi."]},{name:"systemProgram",isMut:0,isSigner:0}],args:[{name:"inputs",type:"bytes"}]},{name:"revoke",docs:["Revokes a delegation. The instruction merges all inputs into one output","account. Cannot be called by a delegate. Delegates are not preserved."],accounts:[{name:"feePayer",isMut:1,isSigner:1,docs:["UNCHECKED: only pays fees."]},{name:"authority",isMut:0,isSigner:1,docs:["Authority is verified through proof since both owner and delegate","are included in the token data hash, which is a public input to the","validity proof."]},{name:"cpiAuthorityPda",isMut:0,isSigner:0},{name:"lightSystemProgram",isMut:0,isSigner:0},{name:"registeredProgramPda",isMut:0,isSigner:0},{name:"noopProgram",isMut:0,isSigner:0},{name:"accountCompressionAuthority",isMut:0,isSigner:0},{name:"accountCompressionProgram",isMut:0,isSigner:0},{name:"selfProgram",isMut:0,isSigner:0,docs:["this program is the signer of the cpi."]},{name:"systemProgram",isMut:0,isSigner:0}],args:[{name:"inputs",type:"bytes"}]},{name:"freeze",docs:["Freezes compressed token accounts. Inputs must not be frozen. Creates as","many outputs as inputs. Balances and delegates are preserved."],accounts:[{name:"feePayer",isMut:1,isSigner:1,docs:["UNCHECKED: only pays fees."]},{name:"authority",isMut:0,isSigner:1},{name:"cpiAuthorityPda",isMut:0,isSigner:0},{name:"lightSystemProgram",isMut:0,isSigner:0},{name:"registeredProgramPda",isMut:0,isSigner:0},{name:"noopProgram",isMut:0,isSigner:0},{name:"accountCompressionAuthority",isMut:0,isSigner:0},{name:"accountCompressionProgram",isMut:0,isSigner:0},{name:"selfProgram",isMut:0,isSigner:0,docs:["that this program is the signer of the cpi."]},{name:"systemProgram",isMut:0,isSigner:0},{name:"mint",isMut:0,isSigner:0}],args:[{name:"inputs",type:"bytes"}]},{name:"thaw",docs:["Thaws frozen compressed token accounts. Inputs must be frozen. Creates","as many outputs as inputs. Balances and delegates are preserved."],accounts:[{name:"feePayer",isMut:1,isSigner:1,docs:["UNCHECKED: only pays fees."]},{name:"authority",isMut:0,isSigner:1},{name:"cpiAuthorityPda",isMut:0,isSigner:0},{name:"lightSystemProgram",isMut:0,isSigner:0},{name:"registeredProgramPda",isMut:0,isSigner:0},{name:"noopProgram",isMut:0,isSigner:0},{name:"accountCompressionAuthority",isMut:0,isSigner:0},{name:"accountCompressionProgram",isMut:0,isSigner:0},{name:"selfProgram",isMut:0,isSigner:0,docs:["that this program is the signer of the cpi."]},{name:"systemProgram",isMut:0,isSigner:0},{name:"mint",isMut:0,isSigner:0}],args:[{name:"inputs",type:"bytes"}]},{name:"burn",docs:["Burns compressed tokens and spl tokens from the pool account. Delegates","can burn tokens. The output compressed token account remains delegated.","Creates one output compressed token account."],accounts:[{name:"feePayer",isMut:1,isSigner:1,docs:["UNCHECKED: only pays fees."]},{name:"authority",isMut:0,isSigner:1,docs:["Authority is verified through proof since both owner and delegate","are included in the token data hash, which is a public input to the","validity proof."]},{name:"cpiAuthorityPda",isMut:0,isSigner:0},{name:"mint",isMut:1,isSigner:0},{name:"tokenPoolPda",isMut:1,isSigner:0},{name:"tokenProgram",isMut:0,isSigner:0},{name:"lightSystemProgram",isMut:0,isSigner:0},{name:"registeredProgramPda",isMut:0,isSigner:0},{name:"noopProgram",isMut:0,isSigner:0},{name:"accountCompressionAuthority",isMut:0,isSigner:0},{name:"accountCompressionProgram",isMut:0,isSigner:0},{name:"selfProgram",isMut:0,isSigner:0},{name:"systemProgram",isMut:0,isSigner:0}],args:[{name:"inputs",type:"bytes"}]},{name:"stubIdlBuild",docs:["This function is a stub to allow Anchor to include the input types in","the IDL. It should not be included in production builds nor be called in","practice."],accounts:[{name:"feePayer",isMut:1,isSigner:1,docs:["UNCHECKED: only pays fees."]},{name:"authority",isMut:0,isSigner:1,docs:["Authority is verified through proof since both owner and delegate","are included in the token data hash, which is a public input to the","validity proof."]},{name:"cpiAuthorityPda",isMut:0,isSigner:0},{name:"lightSystemProgram",isMut:0,isSigner:0},{name:"registeredProgramPda",isMut:0,isSigner:0},{name:"noopProgram",isMut:0,isSigner:0},{name:"accountCompressionAuthority",isMut:0,isSigner:0},{name:"accountCompressionProgram",isMut:0,isSigner:0},{name:"selfProgram",isMut:0,isSigner:0,docs:["this program is the signer of the cpi."]},{name:"tokenPoolPda",isMut:1,isSigner:0,isOptional:1},{name:"compressOrDecompressTokenAccount",isMut:1,isSigner:0,isOptional:1},{name:"tokenProgram",isMut:0,isSigner:0,isOptional:1},{name:"systemProgram",isMut:0,isSigner:0}],args:[{name:"inputs1",type:{defined:"CompressedTokenInstructionDataTransfer"}},{name:"inputs2",type:{defined:"TokenData"}}]}],types:[{name:"AccountState",type:{kind:"enum",variants:[{name:"Initialized"},{name:"Frozen"}]}},{name:"CompressedAccount",type:{kind:"struct",fields:[{name:"owner",type:"publicKey"},{name:"lamports",type:"u64"},{name:"address",type:{option:{array:["u8",32]}}},{name:"data",type:{option:{defined:"CompressedAccountData"}}}]}},{name:"CompressedAccountData",type:{kind:"struct",fields:[{name:"discriminator",type:{array:["u8",8]}},{name:"data",type:"bytes"},{name:"dataHash",type:{array:["u8",32]}}]}},{name:"CompressedCpiContext",type:{kind:"struct",fields:[{name:"setContext",docs:["Is set by the program that is invoking the CPI to signal that is should","set the cpi context."],type:"bool"},{name:"firstSetContext",docs:["Is set to wipe the cpi context since someone could have set it before","with unrelated data."],type:"bool"},{name:"cpiContextAccountIndex",docs:["Index of cpi context account in remaining accounts."],type:"u8"}]}},{name:"CompressedProof",type:{kind:"struct",fields:[{name:"a",type:{array:["u8",32]}},{name:"b",type:{array:["u8",64]}},{name:"c",type:{array:["u8",32]}}]}},{name:"CompressedTokenInstructionDataTransfer",type:{kind:"struct",fields:[{name:"proof",type:{option:{defined:"CompressedProof"}}},{name:"mint",type:"publicKey"},{name:"delegatedTransfer",docs:["Is required if the signer is delegate,","-> delegate is authority account,","owner = Some(owner) is the owner of the token account."],type:{option:{defined:"DelegatedTransfer"}}},{name:"inputTokenDataWithContext",type:{vec:{defined:"InputTokenDataWithContext"}}},{name:"outputCompressedAccounts",type:{vec:{defined:"PackedTokenTransferOutputData"}}},{name:"isCompress",type:"bool"},{name:"compressOrDecompressAmount",type:{option:"u64"}},{name:"cpiContext",type:{option:{defined:"CompressedCpiContext"}}},{name:"lamportsChangeAccountMerkleTreeIndex",type:{option:"u8"}}]}},{name:"CompressedTokenInstructionDataRevoke",type:{kind:"struct",fields:[{name:"proof",type:{option:{defined:"CompressedProof"}}},{name:"mint",type:"publicKey"},{name:"inputTokenDataWithContext",type:{vec:{defined:"InputTokenDataWithContext"}}},{name:"cpiContext",type:{option:{defined:"CompressedCpiContext"}}},{name:"outputAccountMerkleTreeIndex",type:"u8"}]}},{name:"CompressedTokenInstructionDataApprove",type:{kind:"struct",fields:[{name:"proof",type:{option:{defined:"CompressedProof"}}},{name:"mint",type:"publicKey"},{name:"inputTokenDataWithContext",type:{vec:{defined:"InputTokenDataWithContext"}}},{name:"cpiContext",type:{option:{defined:"CompressedCpiContext"}}},{name:"delegate",type:"publicKey"},{name:"delegatedAmount",type:"u64"},{name:"delegateMerkleTreeIndex",type:"u8"},{name:"changeAccountMerkleTreeIndex",type:"u8"},{name:"delegateLamports",type:{option:"u64"}}]}},{name:"DelegatedTransfer",docs:["Struct to provide the owner when the delegate is signer of the transaction."],type:{kind:"struct",fields:[{name:"owner",type:"publicKey"},{name:"delegateChangeAccountIndex",docs:["Index of change compressed account in output compressed accounts. In","case that the delegate didn't spend the complete delegated compressed","account balance the change compressed account will be delegated to her","as well."],type:{option:"u8"}}]}},{name:"InputTokenDataWithContext",type:{kind:"struct",fields:[{name:"amount",type:"u64"},{name:"delegateIndex",type:{option:"u8"}},{name:"merkleContext",type:{defined:"PackedMerkleContext"}},{name:"rootIndex",type:"u16"},{name:"lamports",type:{option:"u64"}},{name:"tlv",docs:["Placeholder for TokenExtension tlv data (unimplemented)"],type:{option:"bytes"}}]}},{name:"InstructionDataInvoke",type:{kind:"struct",fields:[{name:"proof",type:{option:{defined:"CompressedProof"}}},{name:"inputCompressedAccountsWithMerkleContext",type:{vec:{defined:"PackedCompressedAccountWithMerkleContext"}}},{name:"outputCompressedAccounts",type:{vec:{defined:"OutputCompressedAccountWithPackedContext"}}},{name:"relayFee",type:{option:"u64"}},{name:"newAddressParams",type:{vec:{defined:"NewAddressParamsPacked"}}},{name:"compressOrDecompressLamports",type:{option:"u64"}},{name:"isCompress",type:"bool"}]}},{name:"InstructionDataInvokeCpi",type:{kind:"struct",fields:[{name:"proof",type:{option:{defined:"CompressedProof"}}},{name:"newAddressParams",type:{vec:{defined:"NewAddressParamsPacked"}}},{name:"inputCompressedAccountsWithMerkleContext",type:{vec:{defined:"PackedCompressedAccountWithMerkleContext"}}},{name:"outputCompressedAccounts",type:{vec:{defined:"OutputCompressedAccountWithPackedContext"}}},{name:"relayFee",type:{option:"u64"}},{name:"compressOrDecompressLamports",type:{option:"u64"}},{name:"isCompress",type:"bool"},{name:"cpiContext",type:{option:{defined:"CompressedCpiContext"}}}]}},{name:"MerkleTreeSequenceNumber",type:{kind:"struct",fields:[{name:"pubkey",type:"publicKey"},{name:"seq",type:"u64"}]}},{name:"NewAddressParamsPacked",type:{kind:"struct",fields:[{name:"seed",type:{array:["u8",32]}},{name:"addressQueueAccountIndex",type:"u8"},{name:"addressMerkleTreeAccountIndex",type:"u8"},{name:"addressMerkleTreeRootIndex",type:"u16"}]}},{name:"OutputCompressedAccountWithPackedContext",type:{kind:"struct",fields:[{name:"compressedAccount",type:{defined:"CompressedAccount"}},{name:"merkleTreeIndex",type:"u8"}]}},{name:"PackedCompressedAccountWithMerkleContext",type:{kind:"struct",fields:[{name:"compressedAccount",type:{defined:"CompressedAccount"}},{name:"merkleContext",type:{defined:"PackedMerkleContext"}},{name:"rootIndex",docs:["Index of root used in inclusion validity proof."],type:"u16"},{name:"readOnly",docs:["Placeholder to mark accounts read-only unimplemented set to false."],type:"bool"}]}},{name:"PackedMerkleContext",type:{kind:"struct",fields:[{name:"merkleTreePubkeyIndex",type:"u8"},{name:"queuePubkeyIndex",type:"u8"},{name:"leafIndex",type:"u32"},{name:"proveByIndex",type:"bool"}]}},{name:"PackedTokenTransferOutputData",type:{kind:"struct",fields:[{name:"owner",type:"publicKey"},{name:"amount",type:"u64"},{name:"lamports",type:{option:"u64"}},{name:"merkleTreeIndex",type:"u8"},{name:"tlv",docs:["Placeholder for TokenExtension tlv data (unimplemented)"],type:{option:"bytes"}}]}},{name:"PublicTransactionEvent",type:{kind:"struct",fields:[{name:"inputCompressedAccountHashes",type:{vec:{array:["u8",32]}}},{name:"outputCompressedAccountHashes",type:{vec:{array:["u8",32]}}},{name:"outputCompressedAccounts",type:{vec:{defined:"OutputCompressedAccountWithPackedContext"}}},{name:"outputLeafIndices",type:{vec:"u32"}},{name:"sequenceNumbers",type:{vec:{defined:"MerkleTreeSequenceNumber"}}},{name:"relayFee",type:{option:"u64"}},{name:"isCompress",type:"bool"},{name:"compressOrDecompressLamports",type:{option:"u64"}},{name:"pubkeyArray",type:{vec:"publicKey"}},{name:"message",type:{option:"bytes"}}]}},{name:"QueueIndex",type:{kind:"struct",fields:[{name:"queueId",docs:["Id of queue in queue account."],type:"u8"},{name:"index",docs:["Index of compressed account hash in queue."],type:"u16"}]}},{name:"TokenData",type:{kind:"struct",fields:[{name:"mint",docs:["The mint associated with this account"],type:"publicKey"},{name:"owner",docs:["The owner of this account."],type:"publicKey"},{name:"amount",docs:["The amount of tokens this account holds."],type:"u64"},{name:"delegate",docs:["If `delegate` is `Some` then `delegated_amount` represents","the amount authorized by the delegate"],type:{option:"publicKey"}},{name:"state",docs:["The account's state"],type:{defined:"AccountState"}},{name:"tlv",docs:["Placeholder for TokenExtension tlv data (unimplemented)"],type:{option:"bytes"}}]}}],errors:[{code:6e3,name:"PublicKeyAmountMissmatch",msg:"public keys and amounts must be of same length"},{code:6001,name:"ComputeInputSumFailed",msg:"ComputeInputSumFailed"},{code:6002,name:"ComputeOutputSumFailed",msg:"ComputeOutputSumFailed"},{code:6003,name:"ComputeCompressSumFailed",msg:"ComputeCompressSumFailed"},{code:6004,name:"ComputeDecompressSumFailed",msg:"ComputeDecompressSumFailed"},{code:6005,name:"SumCheckFailed",msg:"SumCheckFailed"},{code:6006,name:"DecompressRecipientUndefinedForDecompress",msg:"DecompressRecipientUndefinedForDecompress"},{code:6007,name:"CompressedPdaUndefinedForDecompress",msg:"CompressedPdaUndefinedForDecompress"},{code:6008,name:"DeCompressAmountUndefinedForDecompress",msg:"DeCompressAmountUndefinedForDecompress"},{code:6009,name:"CompressedPdaUndefinedForCompress",msg:"CompressedPdaUndefinedForCompress"},{code:6010,name:"DeCompressAmountUndefinedForCompress",msg:"DeCompressAmountUndefinedForCompress"},{code:6011,name:"DelegateSignerCheckFailed",msg:"DelegateSignerCheckFailed"},{code:6012,name:"MintTooLarge",msg:"Minted amount greater than u64::MAX"},{code:6013,name:"SplTokenSupplyMismatch",msg:"SplTokenSupplyMismatch"},{code:6014,name:"HeapMemoryCheckFailed",msg:"HeapMemoryCheckFailed"},{code:6015,name:"InstructionNotCallable",msg:"The instruction is not callable"},{code:6016,name:"ArithmeticUnderflow",msg:"ArithmeticUnderflow"},{code:6017,name:"HashToFieldError",msg:"HashToFieldError"},{code:6018,name:"InvalidAuthorityMint",msg:"Expected the authority to be also a mint authority"},{code:6019,name:"InvalidFreezeAuthority",msg:"Provided authority is not the freeze authority"},{code:6020,name:"InvalidDelegateIndex"},{code:6021,name:"TokenPoolPdaUndefined"},{code:6022,name:"IsTokenPoolPda",msg:"Compress or decompress recipient is the same account as the token pool pda."},{code:6023,name:"InvalidTokenPoolPda"},{code:6024,name:"NoInputTokenAccountsProvided"},{code:6025,name:"NoInputsProvided"},{code:6026,name:"MintHasNoFreezeAuthority"},{code:6027,name:"MintWithInvalidExtension"},{code:6028,name:"InsufficientTokenAccountBalance",msg:"The token account balance is less than the remaining amount."},{code:6029,name:"InvalidTokenPoolBump",msg:"Max number of token pools reached."},{code:6030,name:"FailedToDecompress"},{code:6031,name:"FailedToBurnSplTokensFromTokenPool"},{code:6032,name:"NoMatchingBumpFound"}]},exports.LIGHT_TOKEN_CONFIG=ot,exports.LIGHT_TOKEN_RENT_SPONSOR=it,exports.MAX_COMBINED_BATCH_BYTES=900,exports.MAX_LOAD_ONLY_BATCH_BYTES=1e3,exports.MAX_TOP_UP=yt,exports.MAX_TRANSACTION_SIZE=Wr,exports.MINT_TO_DISCRIMINATOR=lt,exports.POOL_SEED=at,exports.RENT_PER_BYTE_PER_EPOCH=1,exports.REVOKE_DISCRIMINATOR=ft,exports.SLOTS_PER_RENT_EPOCH=13500,exports.SPL_TOKEN_MINT_RENT_EXEMPT_BALANCE=1461600,exports.TOTAL_COMPRESSION_COST=11e3,exports.TRANSFER_DISCRIMINATOR=pt,exports._getOrCreateAtaInterface=Ai,exports.addSplInterfaces=Si,exports.addTokenPoolAccountsLayout=ee,exports.addTokenPools=xi,exports.approve=async function(n,r,o,i,s,a,u){i=e.bn(i);const c=await n.getCompressedTokenAccountsByOwner(s.publicKey,{mint:o}),{accounts:l}=Bt(c.items,i),[d]=Lt(l,i),p=await n.getValidityProofV0(d.map((t=>({hash:t.compressedAccount.hash,tree:t.compressedAccount.treeInfo.tree,queue:t.compressedAccount.treeInfo.queue})))),m=await ve.approve({payer:r.publicKey,inputCompressedTokenAccounts:d,toAddress:a,amount:i,recentInputStateRootIndices:p.rootIndices,recentValidityProof:p.compressedProof}),{blockhash:h}=await n.getLatestBlockhash(),f=e.dedupeSigner(r,[s]),g=e.buildAndSignTx([t.ComputeBudgetProgram.setComputeUnitLimit({units:35e4}),m],r,h,f);return e.sendAndConfirmTx(n,g,u)},exports.approveAccountsLayout=oe,exports.approveAndMintTo=async function(r,o,i,s,a,u,c,l,d){c=null!=c?c:e.selectStateTreeInfo(await r.getStateTreeInfos()),l=null!=l?l:St(await kt(r,i));const p=await n.getOrCreateAssociatedTokenAccount(r,o,i,a.publicKey,void 0,void 0,d,l.tokenProgram),m=await ve.approveAndMintTo({feePayer:o.publicKey,mint:i,authority:a.publicKey,authorityTokenAccount:p.address,amount:u,toPubkey:s,outputStateTreeInfo:c,tokenPoolInfo:l}),{blockhash:h}=await r.getLatestBlockhash(),f=e.dedupeSigner(o,[a]),g=e.buildAndSignTx([t.ComputeBudgetProgram.setComputeUnitLimit({units:15e4+2e4*e.toArray(u).length}),...m],o,h,f);return await e.sendAndConfirmTx(r,g,d)},exports.approveInterface=async function(t,r,o,i,s,a,u,c,l=e.LIGHT_TOKEN_PROGRAM_ID,d=0,p,m){e.assertBetaEnabled();const h=zn(i,u.publicKey,0,l);if(!o.equals(h))throw new Error(`Token account mismatch. Expected ${h.toBase58()}, got ${o.toBase58()}`);const f=l.equals(n.TOKEN_PROGRAM_ID)||l.equals(n.TOKEN_2022_PROGRAM_ID),g=null!=m?m:f&&!d?0:(await gi(t,i)).mint.decimals,y=await mo(t,r.publicKey,i,o,s,a,u.publicKey,g,l,d,p),b=e.dedupeSigner(r,[u]),{rest:w,last:I}=Ti(y);await Promise.all(w.map((async n=>{const{blockhash:o}=await t.getLatestBlockhash(),i=e.buildAndSignTx(n,r,o,b);return e.sendAndConfirmTx(t,i,c)})));const{blockhash:A}=await t.getLatestBlockhash(),v=e.buildAndSignTx(I,r,A,b);return e.sendAndConfirmTx(t,v,c)},exports.batchCompressLayout=$t,exports.calculateFeePayerCostAtCreation=function(t=16,e=272){return 11e3+t*bt(e)},exports.checkMint=Wt,exports.checkSplInterfaceInfo=Tt,exports.checkTokenPoolInfo=function(t,e){return Tt(At(t),e)},exports.compress=async function(n,r,o,i,s,a,u,c,l,d){c=null!=c?c:e.selectStateTreeInfo(await n.getStateTreeInfos()),l=null!=l?l:St(await kt(n,o));const p=await ve.compress({payer:r.publicKey,owner:s.publicKey,source:a,toAddress:u,amount:i,mint:o,outputStateTreeInfo:c,tokenPoolInfo:l}),m=await n.getLatestBlockhash(),h=e.dedupeSigner(r,[s]),f=e.buildAndSignTx([t.ComputeBudgetProgram.setComputeUnitLimit({units:13e4+2e4*e.toArray(i).length}),p],r,m.blockhash,h);return await e.sendAndConfirmTx(n,f,d,m)},exports.compressSplTokenAccount=async function(n,r,o,i,s,a,u,c,l){u=null!=u?u:e.selectStateTreeInfo(await n.getStateTreeInfos()),c=null!=c?c:St(await kt(n,o));const d=await ve.compressSplTokenAccount({feePayer:r.publicKey,authority:i.publicKey,tokenAccount:s,mint:o,remainingAmount:a,outputStateTreeInfo:u,tokenPoolInfo:c}),p=await n.getLatestBlockhash(),m=e.dedupeSigner(r,[i]),h=e.buildAndSignTx([t.ComputeBudgetProgram.setComputeUnitLimit({units:15e4}),d],r,p.blockhash,m);return await e.sendAndConfirmTx(n,h,l,p)},exports.compressSplTokenAccountInstructionDataLayout=Yt,exports.convertTokenDataToAccount=Ln,exports.createApproveInterfaceInstructions=mo,exports.createAssociatedLightTokenAccountIdempotentInstruction=pn,exports.createAssociatedLightTokenAccountInstruction=dn,exports.createAssociatedTokenAccountInterfaceIdempotentInstruction=yn,exports.createAssociatedTokenAccountInterfaceInstruction=gn,exports.createAtaInterface=async function(n,r,o,i,s=0,a,u=e.LIGHT_TOKEN_PROGRAM_ID,c,l){e.assertBetaEnabled();const d=null!=c?c:mn(u),p=zn(o,i,s,u,d),m=gn(r.publicKey,p,i,o,u,d,l);if(u.equals(e.LIGHT_TOKEN_PROGRAM_ID)){const{blockhash:o}=await n.getLatestBlockhash(),i=e.buildAndSignTx([t.ComputeBudgetProgram.setComputeUnitLimit({units:3e4}),m],r,o,[]);await e.sendAndConfirmTx(n,i,a)}else{const e=(new t.Transaction).add(m);await t.sendAndConfirmTransaction(n,e,[r],a)}return p},exports.createAtaInterfaceIdempotent=async function(n,r,o,i,s=0,a,u=e.LIGHT_TOKEN_PROGRAM_ID,c,l){e.assertBetaEnabled();const d=null!=c?c:mn(u),p=zn(o,i,s,u,d),m=yn(r.publicKey,p,i,o,u,d,l);if(u.equals(e.LIGHT_TOKEN_PROGRAM_ID)){const{blockhash:o}=await n.getLatestBlockhash(),i=e.buildAndSignTx([t.ComputeBudgetProgram.setComputeUnitLimit({units:3e4}),m],r,o,[]);await e.sendAndConfirmTx(n,i,a)}else{const e=(new t.Transaction).add(m);await t.sendAndConfirmTransaction(n,e,[r],a)}return p},exports.createAtaInterfaceIdempotentInstruction=bn,exports.createDecompressOutputState=Ae,exports.createLightTokenApproveInstruction=so,exports.createLightTokenFreezeAccountInstruction=function(n,r,o){return new t.TransactionInstruction({programId:e.LIGHT_TOKEN_PROGRAM_ID,keys:[{pubkey:n,isSigner:0,isWritable:1},{pubkey:r,isSigner:0,isWritable:0},{pubkey:o,isSigner:1,isWritable:0}],data:no})},exports.createLightTokenRevokeInstruction=ao,exports.createLightTokenThawAccountInstruction=function(n,r,o){return new t.TransactionInstruction({programId:e.LIGHT_TOKEN_PROGRAM_ID,keys:[{pubkey:n,isSigner:0,isWritable:1},{pubkey:r,isSigner:0,isWritable:0},{pubkey:o,isSigner:1,isWritable:0}],data:ro})},exports.createLightTokenTransferCheckedInstruction=Xr,exports.createLightTokenTransferInstruction=function(n,r,o,i,s){const a=Buffer.alloc(9);a.writeUInt8(3,0),a.writeBigUInt64LE(BigInt(i),1);const u=null!=s?s:o,c=[{pubkey:n,isSigner:0,isWritable:1},{pubkey:r,isSigner:0,isWritable:1},{pubkey:o,isSigner:1,isWritable:u.equals(o)},{pubkey:t.SystemProgram.programId,isSigner:0,isWritable:0},{pubkey:u,isSigner:!u.equals(o),isWritable:1}];return new t.TransactionInstruction({programId:e.LIGHT_TOKEN_PROGRAM_ID,keys:c,data:a})},exports.createLoadAtaInstructions=kr,exports.createMint=fo,exports.createMintInstruction=$e,exports.createMintInterface=async function(r,o,i,s,a,u=t.Keypair.generate(),c,l=e.LIGHT_TOKEN_PROGRAM_ID,d,p,m){if(e.assertBetaEnabled(),l.equals(n.TOKEN_PROGRAM_ID)||l.equals(n.TOKEN_2022_PROGRAM_ID))return fo(r,o,i,a,u,c,l,s);if(!("secretKey"in i))throw new Error("mintAuthority must be a Signer for light-token mints");if(m&&!m.tree.equals(e.getDefaultAddressTreeInfo().tree))throw new Error(`addressTreeInfo ${null==m?void 0:m.tree.toString()} must be the default address tree info: ${e.getDefaultAddressTreeInfo().tree.toString()}`);const h=s&&"secretKey"in s?s.publicKey:s;m=null!=m?m:e.getBatchAddressTreeInfo(),p=null!=p?p:e.selectStateTreeInfo(await r.getStateTreeInfos());const f=Te(u.publicKey,m),g=await r.getValidityProofV2([],[{address:Uint8Array.from(f),treeInfo:m}],e.DerivationMode.standard),y=$e(u.publicKey,a,i.publicKey,h,o.publicKey,g,m,p,d),b=e.dedupeSigner(o,[u,i]),{blockhash:w}=await r.getLatestBlockhash(),I=e.buildAndSignTx([t.ComputeBudgetProgram.setComputeUnitLimit({units:5e5}),y],o,w,b),A=await e.sendAndConfirmTx(r,I);return{mint:Pe(u.publicKey)[0],transactionSignature:A}},exports.createMintToCompressedInstruction=Ur,exports.createMintToInstruction=Kr,exports.createMintToInterfaceInstruction=Nr,exports.createRemoveMetadataKeyInstruction=en,exports.createRevokeInterfaceInstructions=ho,exports.createSplInterface=Pi,exports.createTokenMetadata=function(t,e,n,r,o=null){return{name:t,symbol:e,uri:n,updateAuthority:null!=r?r:null,additionalMetadata:null!=o?o:null}},exports.createTokenPool=Mi,exports.createTokenPoolAccountsLayout=te,exports.createTokenProgramLookupTable=async function(t,n,r,o,i){const s=await t.getSlot("finalized"),{instructions:a,address:u}=await ve.createTokenProgramLookupTable({payer:n.publicKey,authority:r.publicKey,mints:o,remainingAccounts:i,recentSlot:s}),c=e.dedupeSigner(n,[r]),l=[];for(const r of a){const o=await t.getLatestBlockhash(),i=e.buildAndSignTx([r],n,o.blockhash,c),s=await e.sendAndConfirmTx(t,i,{commitment:"finalized"},o);l.push(s)}return{txIds:l,address:u}},exports.createTransferInterfaceInstructions=ki,exports.createTransferOutputState=Ie,exports.createTransferToAccountInterfaceInstructions=Jr,exports.createUnwrapInstruction=eo,exports.createUnwrapInstructions=async function(r,o,i,s,a,u,c,l,d,p,m=0){e.assertBetaEnabled(),null!=c||(c=i);let h=l;if(!h&&(h=(await kt(r,s)).find((t=>t.isInitialized)),!h))throw new Error(`No initialized SPL interface found for mint: ${s.toBase58()}. Please create an SPL interface via createSplInterface().`);if(!await r.getAccountInfo(o))throw new Error(`Destination account does not exist: ${o.toBase58()}. Create it first using getOrCreateAssociatedTokenAccount or createAssociatedTokenAccountIdempotentInstruction.`);const f=zn(s,i);let g;try{g=await Wn(r,f,i,s,void 0,void 0,m)}catch(t){if(t instanceof n.TokenAccountNotFoundError)throw new Error(Mn);throw t}On(g,"unwrap");const y=g.parsed.amount;if(y===BigInt(0))throw new Error(Mn);const b=null!=u?BigInt(u.toString()):y;if(b===BigInt(0))throw new Error("Unwrap amount must be greater than zero.");if(b>y)throw new Error(`Insufficient light-token balance. Requested: ${b}, Available: ${y}`);const w=await Dr(r,c,g,p,m,f,null!=u?b:void 0,void 0,a),I=eo(f,o,i,s,b,h,a,c,d),A=c.equals(i)?1:2;if(0===w.length){const e=[t.ComputeBudgetProgram.setComputeUnitLimit({units:to(null)}),I];return Gr(e,A,"Unwrap batch"),[e]}if(1===w.length){const e=w[0],n=[t.ComputeBudgetProgram.setComputeUnitLimit({units:to(e)}),...e.instructions,I];return Gr(n,A,"Unwrap batch"),[n]}const v=[];for(let e=0;e<w.length-1;e++){const n=w[e],r=Lr(n),o=[t.ComputeBudgetProgram.setComputeUnitLimit({units:r}),...n.instructions];Gr(o,A,"Unwrap batch"),v.push(o)}const T=w[w.length-1],k=[t.ComputeBudgetProgram.setComputeUnitLimit({units:to(T)}),...T.instructions,I];return Gr(k,A,"Unwrap batch"),v.push(k),v},exports.createUpdateFreezeAuthorityInstruction=Qe,exports.createUpdateMetadataAuthorityInstruction=tn,exports.createUpdateMetadataFieldInstruction=Je,exports.createUpdateMintAuthorityInstruction=Ze,exports.createWrapInstruction=fr,exports.decodeApproveInstructionData=function(t){const e=ue.decode(t.subarray(ht.length));return Object.assign(Object.assign({},e),{proof:de(e.proof)?null:e.proof})},exports.decodeBatchCompressInstructionData=function(t){return $t.decode(t.subarray(dt.length+4))},exports.decodeCompressSplTokenAccountInstructionData=function(t){const e=Yt.decode(t.subarray(mt.length));return{owner:e.owner,remainingAmount:e.remainingAmount,cpiContext:e.cpiContext}},exports.decodeMintToInstructionData=function(t){return jt.decode(t.subarray(lt.length))},exports.decodeRevokeInstructionData=function(t){const e=ce.decode(t.subarray(ft.length));return Object.assign(Object.assign({},e),{proof:de(e.proof)?null:e.proof})},exports.decodeTokenMetadata=mi,exports.decodeTransferInstructionData=function(t){return zt.decode(t.slice(pt.length+4))},exports.decompress=async function(n,r,o,i,s,a,u,c){i=e.bn(i);const l=await n.getCompressedTokenAccountsByOwner(s.publicKey,{mint:o}),{accounts:d}=Bt(l.items,i),[p]=Dt(d,i),m=await n.getValidityProofV0(p.map((t=>({hash:t.compressedAccount.hash,tree:t.compressedAccount.treeInfo.tree,queue:t.compressedAccount.treeInfo.queue})))),h=xt(u=null!=u?u:await kt(n,o),i),f=await ve.decompress({payer:r.publicKey,inputCompressedTokenAccounts:p,toAddress:a,amount:i,tokenPoolInfos:h,recentInputStateRootIndices:m.rootIndices,recentValidityProof:m.compressedProof}),{blockhash:g}=await n.getLatestBlockhash(),y=e.dedupeSigner(r,[s]),b=e.buildAndSignTx([t.ComputeBudgetProgram.setComputeUnitLimit({units:35e4}),f],r,g,y);return await e.sendAndConfirmTx(n,b,c)},exports.decompressDelegated=async function(n,r,o,i,s,a,u,c){i=e.bn(i);const l=await n.getCompressedTokenAccountsByDelegate(s.publicKey,{mint:o}),{accounts:d}=Bt(l.items,i),[p]=Dt(d,i),m=await n.getValidityProofV0(p.map((t=>({hash:t.compressedAccount.hash,tree:t.compressedAccount.treeInfo.tree,queue:t.compressedAccount.treeInfo.queue})))),h=null!=u?u:xt(await kt(n,o),i),f=await ve.decompress({payer:r.publicKey,inputCompressedTokenAccounts:p,toAddress:a,amount:i,recentInputStateRootIndices:m.rootIndices,recentValidityProof:m.compressedProof,tokenPoolInfos:h}),{blockhash:g}=await n.getLatestBlockhash(),y=e.dedupeSigner(r,[s]),b=e.buildAndSignTx([t.ComputeBudgetProgram.setComputeUnitLimit({units:35e4}),f],r,g,y);return e.sendAndConfirmTx(n,b,c)},exports.deriveCMintAddress=Te,exports.deriveSplInterfaceInfo=vt,exports.deriveTokenPoolInfo=function(t,e,n=0){return It(vt(t,e,n))},exports.deserializeMint=di,exports.encodeApproveInstructionData=pe,exports.encodeBatchCompressInstructionData=Qt,exports.encodeCompressSplTokenAccountInstructionData=Xt,exports.encodeMintToInstructionData=Zt,exports.encodeRevokeInstructionData=me,exports.encodeTokenMetadata=function(e){const n=w.alloc(2e3),r=e.updateAuthority||new t.PublicKey(0),o=ri.encode({updateAuthority:r,mint:e.mint,name:w.from(e.name),symbol:w.from(e.symbol),uri:w.from(e.uri),additionalMetadata:e.additionalMetadata?e.additionalMetadata.map((t=>({key:w.from(t.key),value:w.from(t.value)}))):[]},n);return n.subarray(0,o)},exports.encodeTransferInstructionData=Jt,exports.estimateTransactionSize=Fr,exports.extractTokenMetadata=fi,exports.findMintAddress=Pe,exports.freezeAccountsLayout=se,exports.getAccountInterface=Nn,exports.getAssociatedLightTokenAddress=function(n,r){return t.PublicKey.findProgramAddressSync([n.toBuffer(),e.LIGHT_TOKEN_PROGRAM_ID.toBuffer(),r.toBuffer()],e.LIGHT_TOKEN_PROGRAM_ID)[0]},exports.getAssociatedLightTokenAddressAndBump=function(n,r){return t.PublicKey.findProgramAddressSync([n.toBuffer(),e.LIGHT_TOKEN_PROGRAM_ID.toBuffer(),r.toBuffer()],e.LIGHT_TOKEN_PROGRAM_ID)},exports.getAssociatedTokenAddressInterface=zn,exports.getAtaInterface=Wn,exports.getAtaProgramId=mn,exports.getMintInterface=gi,exports.getOrCreateAtaInterface=async function(t,n,r,o,i=0,s,a,u=e.LIGHT_TOKEN_PROGRAM_ID,c=mn(u)){return e.assertBetaEnabled(),Ai(t,n,r,o,i,s,a,u,c,0)},exports.getSplInterfaceInfos=kt,exports.getTokenPoolInfos=async function(t,e,n){return(await kt(t,e,n)).map(It)},exports.groupAccountsByTreeType=Rt,exports.isSingleSplInterfaceInfo=Ci,exports.isSingleTokenPoolInfo=_i,exports.loadAta=bi,exports.mergeTokenAccounts=async function(n,r,o,i,s){const a=await n.getCompressedTokenAccountsByOwner(i.publicKey,{mint:o});if(0===a.items.length)throw new Error(`No compressed token accounts found for mint ${o.toBase58()}`);if(1===a.items.length)throw new Error("Only one token account exists, nothing to merge");const{accounts:u,treeType:c}=Bt(a.items);let l=u,d=c;if(l.length<2){const t=c===e.TreeType.StateV2?e.TreeType.StateV1:e.TreeType.StateV2,n=a.items.filter((e=>e.compressedAccount.treeInfo.treeType===t));if(!(n.length>=2))throw 1===l.length&&1===n.length?new Error("Cannot merge accounts from different tree types (V1/V2). You have 1 V1 and 1 V2 account - nothing to merge within same type."):new Error(`Not enough accounts of the same tree type to merge. Found: ${l.length} ${d===e.TreeType.StateV1?"V1":"V2"} accounts.`);l=n,d=t}const p=l.slice(0,4),m=await n.getValidityProof(p.map((t=>e.bn(t.compressedAccount.hash)))),h=await ve.mergeTokenAccounts({payer:r.publicKey,owner:i.publicKey,inputCompressedTokenAccounts:p,mint:o,recentValidityProof:m.compressedProof,recentInputStateRootIndices:m.rootIndices}),f=[t.ComputeBudgetProgram.setComputeUnitLimit({units:1e6}),...h],{blockhash:g}=await n.getLatestBlockhash(),y=e.dedupeSigner(r,[i]),b=e.buildAndSignTx(f,r,g,y);return e.sendAndConfirmTx(n,b,s)},exports.mintTo=async function(n,r,o,i,s,a,u,c){e.assertBetaEnabled();const l=s.publicKey.equals(r.publicKey)?void 0:r.publicKey,d=Kr({mint:o,destination:i,amount:a,authority:s.publicKey,maxTopUp:null!=u?u:yt,feePayer:l}),p=s.publicKey.equals(r.publicKey)?[]:[s],{blockhash:m}=await n.getLatestBlockhash(),h=e.buildAndSignTx([t.ComputeBudgetProgram.setComputeUnitLimit({units:2e5}),d],r,m,p);return await e.sendAndConfirmTx(n,h,c)},exports.mintTo$1=async function(n,r,o,i,s,a,u,c,l){u=null!=u?u:e.selectStateTreeInfo(await n.getStateTreeInfos()),c=null!=c?c:St(await kt(n,o));const d=await ve.mintTo({feePayer:r.publicKey,mint:o,authority:s.publicKey,amount:a,toPubkey:i,outputStateTreeInfo:u,tokenPoolInfo:c}),{blockhash:p}=await n.getLatestBlockhash(),m=e.dedupeSigner(r,[s]),h=e.buildAndSignTx([t.ComputeBudgetProgram.setComputeUnitLimit({units:1e6}),d],r,p,m);return e.sendAndConfirmTx(n,h,l)},exports.mintToAccountsLayout=ne,exports.mintToCompressed=async function(n,r,o,i,s,a,u=3,c,l){e.assertBetaEnabled();const d=await gi(n,o,null==l?void 0:l.commitment,e.LIGHT_TOKEN_PROGRAM_ID);if(!d.merkleContext)throw new Error(Sn);if(!d.mintContext)throw new Error("Mint does not have MintContext");const p=d.merkleContext;if(!a){const t=await n.getStateTreeInfos();a=e.selectStateTreeInfo(t)}const m=await n.getValidityProofV2([{hash:e.bn(p.hash),leafIndex:p.leafIndex,treeInfo:p.treeInfo,proveByIndex:p.proveByIndex}],[],e.DerivationMode.compressible),h=Ur(i.publicKey,r.publicKey,m,p,{supply:d.mint.supply,decimals:d.mint.decimals,mintAuthority:d.mint.mintAuthority,freezeAuthority:d.mint.freezeAuthority,splMint:d.mintContext.splMint,cmintDecompressed:d.mintContext.cmintDecompressed,version:d.mintContext.version,mintSigner:d.mintContext.mintSigner,bump:d.mintContext.bump,metadata:d.tokenMetadata?{updateAuthority:d.tokenMetadata.updateAuthority||null,name:d.tokenMetadata.name,symbol:d.tokenMetadata.symbol,uri:d.tokenMetadata.uri}:void 0},s,a,u,c),f=i.publicKey.equals(r.publicKey)?[]:[i],{blockhash:g}=await n.getLatestBlockhash(),y=e.buildAndSignTx([t.ComputeBudgetProgram.setComputeUnitLimit({units:5e5}),h],r,g,f);return await e.sendAndConfirmTx(n,y,l)},exports.mintToInterface=async function(n,r,o,i,s,a,u=[],c,l){e.assertBetaEnabled();const d=await gi(n,o,null==c?void 0:c.commitment,l),p=s instanceof t.PublicKey?s:s.publicKey,m=u.map((t=>t.publicKey)),h=Nr(d,i,p,r.publicKey,a,0,m),f=[];s instanceof t.PublicKey||s.publicKey.equals(r.publicKey)||f.push(s),f.push(...u);const{blockhash:g}=await n.getLatestBlockhash(),y=e.buildAndSignTx([t.ComputeBudgetProgram.setComputeUnitLimit({units:2e5}),h],r,g,f);return await e.sendAndConfirmTx(n,y,c)},exports.mintToLayout=jt,exports.packCompressedTokenAccounts=Nt,exports.parseLightTokenCold=Un,exports.parseLightTokenHot=Kn,exports.parseMaybeDelegatedTransfer=we,exports.parseTokenData=be,exports.removeMetadataKey=async function(n,r,o,i,s,a=0,u=0,c){var l,d;e.assertBetaEnabled();const p=await gi(n,o,null==c?void 0:c.commitment,e.LIGHT_TOKEN_PROGRAM_ID);yi(p);const m=p.merkleContext,h=null!==(d=null===(l=p.mintContext)||void 0===l?void 0:l.cmintDecompressed)&&void 0!==d&&d?null:await n.getValidityProofV2([{hash:e.bn(m.hash),leafIndex:m.leafIndex,treeInfo:m.treeInfo,proveByIndex:m.proveByIndex}],[],e.DerivationMode.compressible),f=en(p,i.publicKey,r.publicKey,h,s,a,u),g=i.publicKey.equals(r.publicKey)?[]:[i],{blockhash:y}=await n.getLatestBlockhash(),b=e.buildAndSignTx([t.ComputeBudgetProgram.setComputeUnitLimit({units:5e5}),f],r,y,g);return await e.sendAndConfirmTx(n,b,c)},exports.rentPerEpoch=bt,exports.revoke=async function(n,r,o,i,s){if(Rt(o).size>1)throw new Error("Cannot revoke accounts from different tree types (V1/V2) in the same transaction. Revoke V1 and V2 accounts separately.");const a=await n.getValidityProofV0(o.map((t=>({hash:t.compressedAccount.hash,tree:t.compressedAccount.treeInfo.tree,queue:t.compressedAccount.treeInfo.queue}))));!function(t,e){if(!t.publicKey.equals(e[0].parsed.owner))throw new Error(`Owner ${t.publicKey.toBase58()} does not match account ${e[0].parsed.owner.toBase58()}`)}(i,o),function(t){if(t.some((t=>null===t.parsed.delegate)))throw new Error("Account is not delegated")}(o);const u=await ve.revoke({payer:r.publicKey,inputCompressedTokenAccounts:o,recentInputStateRootIndices:a.rootIndices,recentValidityProof:a.compressedProof}),{blockhash:c}=await n.getLatestBlockhash(),l=e.dedupeSigner(r,[i]),d=e.buildAndSignTx([t.ComputeBudgetProgram.setComputeUnitLimit({units:5e5}),u],r,c,l);return e.sendAndConfirmTx(n,d,s)},exports.revokeAccountsLayout=ie,exports.revokeInterface=async function(t,r,o,i,s,a,u=e.LIGHT_TOKEN_PROGRAM_ID,c=0,l,d){e.assertBetaEnabled();const p=zn(i,s.publicKey,0,u);if(!o.equals(p))throw new Error(`Token account mismatch. Expected ${p.toBase58()}, got ${o.toBase58()}`);const m=u.equals(n.TOKEN_PROGRAM_ID)||u.equals(n.TOKEN_2022_PROGRAM_ID),h=null!=d?d:m&&!c?0:(await gi(t,i)).mint.decimals,f=await ho(t,r.publicKey,i,o,s.publicKey,h,u,c,l),g=e.dedupeSigner(r,[s]),{rest:y,last:b}=Ti(f);await Promise.all(y.map((async n=>{const{blockhash:o}=await t.getLatestBlockhash(),i=e.buildAndSignTx(n,r,o,g);return e.sendAndConfirmTx(t,i,a)})));const{blockhash:w}=await t.getLatestBlockhash(),I=e.buildAndSignTx(b,r,w,g);return e.sendAndConfirmTx(t,I,a)},exports.selectAccountsByPreferredTreeType=Bt,exports.selectInputsForAmount=Tr,exports.selectMinCompressedTokenAccountsForDecompression=function(t,e,n=4,r){const[o,i,s,a]=Dt(t,e,n,r);return{selectedAccounts:o,total:i,totalLamports:s,maxPossibleAmount:a}},exports.selectMinCompressedTokenAccountsForTransfer=Dt,exports.selectMinCompressedTokenAccountsForTransferOrPartial=Kt,exports.selectSmartCompressedTokenAccountsForTransfer=function(t,n,r=4,o){const i=Et(t,null==o?void 0:o.treeType),[s,a,u,c]=Ut(i,n,r);if(Ot(s),a.lt(e.bn(n))){const t=i.reduce(((t,e)=>t.add(e.parsed.amount)),e.bn(0));throw s.length>=r?new Error(`Account limit exceeded: max ${c.toString()} (${r} accounts) per transaction. Total balance: ${t.toString()} (${i.length} accounts). Consider multiple transfers to spend full balance.`):new Error(`Insufficient balance. Required: ${n.toString()}, available: ${t.toString()}.`)}if(0===s.length)throw new Error(Ct);return[s,a,u,c]},exports.selectSmartCompressedTokenAccountsForTransferOrPartial=Ut,exports.selectSplInterfaceInfo=St,exports.selectSplInterfaceInfosForDecompression=xt,exports.selectTokenAccountsForApprove=Lt,exports.selectTokenPoolInfo=function(t){return It(St(t.map(At)))},exports.selectTokenPoolInfosForDecompression=function(t,e){return xt(t.map(At),e).map(It)},exports.serializeMint=function(e){var r,o;const i=[],s=w.alloc(n.MINT_SIZE);n.MintLayout.encode({mintAuthorityOption:e.base.mintAuthority?1:0,mintAuthority:e.base.mintAuthority||new t.PublicKey(0),supply:e.base.supply,decimals:e.base.decimals,isInitialized:e.base.isInitialized,freezeAuthorityOption:e.base.freezeAuthority?1:0,freezeAuthority:e.base.freezeAuthority||new t.PublicKey(0)},s),i.push(s);const a=w.alloc(ii);oi.encode({version:e.mintContext.version,cmintDecompressed:e.mintContext.cmintDecompressed?1:0,splMint:e.mintContext.splMint},a),i.push(a),i.push(w.from(e.mintContext.mintSigner)),i.push(w.from([e.mintContext.bump]));const u=null!==(r=e.reserved)&&void 0!==r?r:new Uint8Array(ui);i.push(w.from(u));const c=null!==(o=e.accountType)&&void 0!==o?o:1;if(i.push(w.from([c])),e.compression?i.push(function(t){const e=w.alloc(96);let n=0;return e.writeUInt16LE(t.configAccountVersion,n),n+=2,e.writeUInt8(t.compressToPubkey,n),n+=1,e.writeUInt8(t.accountVersion,n),n+=1,e.writeUInt32LE(t.lamportsPerWrite,n),n+=4,t.compressionAuthority.toBuffer().copy(e,n),n+=32,t.rentSponsor.toBuffer().copy(e,n),n+=32,e.writeBigUInt64LE(t.lastClaimedSlot,n),n+=8,e.writeUInt32LE(t.rentExemptionPaid,n),n+=4,e.writeUInt32LE(t.reserved,n),n+=4,e.writeUInt16LE(t.rentConfig.baseRent,n),n+=2,e.writeUInt16LE(t.rentConfig.compressionCost,n),n+=2,e.writeUInt8(t.rentConfig.lamportsPerBytePerEpoch,n),n+=1,e.writeUInt8(t.rentConfig.maxFundedEpochs,n),n+=1,e.writeUInt16LE(t.rentConfig.maxTopUp,n),n+=2,e}(e.compression)):i.push(w.alloc(96)),e.extensions&&e.extensions.length>0){i.push(w.from([1]));const t=w.alloc(4);t.writeUInt32LE(e.extensions.length),i.push(t);for(const t of e.extensions)i.push(w.from([t.extensionType])),i.push(w.from(t.data))}else i.push(w.from([0]));return w.concat(i)},exports.sliceLast=Ti,exports.sumUpTokenAmount=ge,exports.thawAccountsLayout=ae,exports.toAccountInfo=Dn,exports.toOffChainMetadataJson=function(t){const e={name:t.name,symbol:t.symbol};return void 0!==t.description&&(e.description=t.description),void 0!==t.image&&(e.image=t.image),void 0!==t.additionalMetadata&&t.additionalMetadata.length>0&&(e.additionalMetadata=t.additionalMetadata),e},exports.toTokenPoolInfo=It,exports.transfer=async function(n,r,o,i,s,a,u){i=e.bn(i);const c=await n.getCompressedTokenAccountsByOwner(s.publicKey,{mint:o}),{accounts:l}=Bt(c.items,i),[d]=Dt(l,i),p=await n.getValidityProofV0(d.map((t=>({hash:t.compressedAccount.hash,tree:t.compressedAccount.treeInfo.tree,queue:t.compressedAccount.treeInfo.queue})))),m=await ve.transfer({payer:r.publicKey,inputCompressedTokenAccounts:d,toAddress:a,amount:i,recentInputStateRootIndices:p.rootIndices,recentValidityProof:p.compressedProof}),{blockhash:h}=await n.getLatestBlockhash(),f=e.dedupeSigner(r,[s]),g=e.buildAndSignTx([t.ComputeBudgetProgram.setComputeUnitLimit({units:5e5}),m],r,h,f);return e.sendAndConfirmTx(n,g,u)},exports.transferAccountsLayout=re,exports.transferDelegated=async function(n,r,o,i,s,a,u){i=e.bn(i);const c=await n.getCompressedTokenAccountsByDelegate(s.publicKey,{mint:o}),{accounts:l}=Bt(c.items,i),[d]=Dt(l,i),p=await n.getValidityProofV0(d.map((t=>({hash:t.compressedAccount.hash,tree:t.compressedAccount.treeInfo.tree,queue:t.compressedAccount.treeInfo.queue})))),m=await ve.transfer({payer:r.publicKey,inputCompressedTokenAccounts:d,toAddress:a,amount:i,recentInputStateRootIndices:p.rootIndices,recentValidityProof:p.compressedProof}),{blockhash:h}=await n.getLatestBlockhash(),f=e.dedupeSigner(r,[s]),g=e.buildAndSignTx([t.ComputeBudgetProgram.setComputeUnitLimit({units:5e5}),m],r,h,f);return e.sendAndConfirmTx(n,g,u)},exports.transferInterface=async function(t,n,r,o,i,s,a,u=e.LIGHT_TOKEN_PROGRAM_ID,c,l,d=0,p){var m;e.assertBetaEnabled();const h=zn(o,null!==(m=null==l?void 0:l.owner)&&void 0!==m?m:s.publicKey,0,u);if(!r.equals(h))throw new Error(`Source mismatch. Expected ${h.toBase58()}, got ${r.toBase58()}`);const f=null!=p?p:(await gi(t,o)).mint.decimals,g=await ki(t,n.publicKey,o,a,s.publicKey,i,f,Object.assign(Object.assign({},l),{wrap:d,programId:u})),y=e.dedupeSigner(n,[s]),{rest:b,last:w}=Ti(g);await Promise.all(b.map((async r=>{const{blockhash:o}=await t.getLatestBlockhash(),i=e.buildAndSignTx(r,n,o,y);return e.sendAndConfirmTx(t,i,c)})));const{blockhash:I}=await t.getLatestBlockhash(),A=e.buildAndSignTx(w,n,I,y);return e.sendAndConfirmTx(t,A,c)},exports.transferToAccountInterface=async function(t,n,r,o,i,s,a,u=e.LIGHT_TOKEN_PROGRAM_ID,c,l,d=0,p){var m;e.assertBetaEnabled();const h=zn(o,null!==(m=null==l?void 0:l.owner)&&void 0!==m?m:s.publicKey,0,u);if(!r.equals(h))throw new Error(`Source mismatch. Expected ${h.toBase58()}, got ${r.toBase58()}`);const f=BigInt(a.toString()),g=null!=p?p:(await gi(t,o)).mint.decimals,y=await Jr(t,n.publicKey,o,f,s.publicKey,i,g,Object.assign(Object.assign({},l),{wrap:d,programId:u})),b=e.dedupeSigner(n,[s]),{rest:w,last:I}=Ti(y);await Promise.all(w.map((async r=>{const{blockhash:o}=await t.getLatestBlockhash(),i=e.buildAndSignTx(r,n,o,b);return e.sendAndConfirmTx(t,i,c)})));const{blockhash:A}=await t.getLatestBlockhash(),v=e.buildAndSignTx(I,n,A,b);return e.sendAndConfirmTx(t,v,c)},exports.unpackMintData=function(t){const e=di(t instanceof w?t:w.from(t)),n=fi(e.extensions);return{mintContext:e.mintContext,tokenMetadata:n||void 0,extensions:e.extensions||void 0}},exports.unpackMintInterface=function(t,r,o=n.TOKEN_PROGRAM_ID){const i=r instanceof w?r:r instanceof Uint8Array?w.from(r):r.data;if(o.equals(e.LIGHT_TOKEN_PROGRAM_ID)){const e=di(i),n={address:t,mintAuthority:e.base.mintAuthority,supply:e.base.supply,decimals:e.base.decimals,isInitialized:e.base.isInitialized,freezeAuthority:e.base.freezeAuthority,tlvData:w.alloc(0)},r=fi(e.extensions),s={mint:n,programId:o,mintContext:e.mintContext,tokenMetadata:r||void 0,extensions:e.extensions||void 0,compression:e.compression};if(!s.mintContext)throw new Error("Invalid light mint: mintContext is required for LIGHT_TOKEN_PROGRAM_ID");return s}const s=r;return{mint:n.unpackMint(t,s,o),programId:o}},exports.updateFreezeAuthority=async function(n,r,o,i,s,a){var u,c;e.assertBetaEnabled();const l=await gi(n,o,null==a?void 0:a.commitment,e.LIGHT_TOKEN_PROGRAM_ID);if(!l.merkleContext)throw new Error(Sn);const d=l.merkleContext,p=null!==(c=null===(u=l.mintContext)||void 0===u?void 0:u.cmintDecompressed)&&void 0!==c&&c?null:await n.getValidityProofV2([{hash:e.bn(d.hash),leafIndex:d.leafIndex,treeInfo:d.treeInfo,proveByIndex:d.proveByIndex}],[],e.DerivationMode.compressible),m=Qe(l,i.publicKey,s,r.publicKey,p),h=i.publicKey.equals(r.publicKey)?[]:[i],{blockhash:f}=await n.getLatestBlockhash(),g=e.buildAndSignTx([t.ComputeBudgetProgram.setComputeUnitLimit({units:5e5}),m],r,f,h);return await e.sendAndConfirmTx(n,g,a)},exports.updateMetadataAuthority=async function(n,r,o,i,s,a=0,u){var c,l;e.assertBetaEnabled();const d=await gi(n,o,null==u?void 0:u.commitment,e.LIGHT_TOKEN_PROGRAM_ID);yi(d);const p=d.merkleContext,m=null!==(l=null===(c=d.mintContext)||void 0===c?void 0:c.cmintDecompressed)&&void 0!==l&&l?null:await n.getValidityProofV2([{hash:e.bn(p.hash),leafIndex:p.leafIndex,treeInfo:p.treeInfo,proveByIndex:p.proveByIndex}],[],e.DerivationMode.compressible),h=tn(d,i.publicKey,s,r.publicKey,m,a),f=i.publicKey.equals(r.publicKey)?[]:[i],{blockhash:g}=await n.getLatestBlockhash(),y=e.buildAndSignTx([t.ComputeBudgetProgram.setComputeUnitLimit({units:5e5}),h],r,g,f);return await e.sendAndConfirmTx(n,y,u)},exports.updateMetadataField=async function(n,r,o,i,s,a,u,c=0,l){var d,p;e.assertBetaEnabled();const m=await gi(n,o,null==l?void 0:l.commitment,e.LIGHT_TOKEN_PROGRAM_ID);yi(m);const h=m.merkleContext,f=null!==(p=null===(d=m.mintContext)||void 0===d?void 0:d.cmintDecompressed)&&void 0!==p&&p?null:await n.getValidityProofV2([{hash:e.bn(h.hash),leafIndex:h.leafIndex,treeInfo:h.treeInfo,proveByIndex:h.proveByIndex}],[],e.DerivationMode.compressible),g=Je(m,i.publicKey,r.publicKey,f,s,a,u,c),y=i.publicKey.equals(r.publicKey)?[]:[i],{blockhash:b}=await n.getLatestBlockhash(),w=e.buildAndSignTx([t.ComputeBudgetProgram.setComputeUnitLimit({units:5e5}),g],r,b,y);return await e.sendAndConfirmTx(n,w,l)},exports.updateMintAuthority=async function(n,r,o,i,s,a){var u,c;e.assertBetaEnabled();const l=await gi(n,o,null==a?void 0:a.commitment,e.LIGHT_TOKEN_PROGRAM_ID);if(!l.merkleContext)throw new Error(Sn);const d=l.merkleContext,p=null!==(c=null===(u=l.mintContext)||void 0===u?void 0:u.cmintDecompressed)&&void 0!==c&&c?null:await n.getValidityProofV2([{hash:e.bn(d.hash),leafIndex:d.leafIndex,treeInfo:d.treeInfo,proveByIndex:d.proveByIndex}],[],e.DerivationMode.compressible),m=Ze(l,i.publicKey,s,r.publicKey,p),h=i.publicKey.equals(r.publicKey)?[]:[i],{blockhash:f}=await n.getLatestBlockhash(),g=e.buildAndSignTx([t.ComputeBudgetProgram.setComputeUnitLimit({units:5e5}),m],r,f,h);return await e.sendAndConfirmTx(n,g,a)},exports.validateSameTokenOwner=ye,exports.wrap=async function(r,o,i,s,a,u,c,l,d,p){e.assertBetaEnabled();let m=l;if(!m&&(m=(await kt(r,u)).find((t=>t.isInitialized)),!m))throw new Error(`No initialized SPL interface found for mint: ${u.toBase58()}. Please create an SPL interface via createSplInterface().`);const h=await n.getMint(r,u,void 0,m.tokenProgram),f=fr(i,s,a.publicKey,u,c,m,h.decimals,o.publicKey,d),{blockhash:g}=await r.getLatestBlockhash(),y=e.dedupeSigner(o,[a]),b=e.buildAndSignTx([t.ComputeBudgetProgram.setComputeUnitLimit({units:2e5}),f],o,g,y);return await e.sendAndConfirmTx(r,b,p)};
2
+ //# sourceMappingURL=types-C1QDyKdh.cjs.map