@lightprotocol/compressed-token 0.18.0 → 0.19.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/cjs/node/index.cjs
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
"use strict";var t=require("@lightprotocol/stateless.js"),e=require("@solana/web3.js"),i=require("@solana/spl-token"),n=require("@coral-xyz/borsh"),r=require("buffer");function o(e){const{inputCompressedTokenAccounts:i,outputStateTrees:n,remainingAccounts:r=[],rootIndices:o,tokenTransferOutputs:s}=e,a=r.slice();let u=null;i.length>0&&i[0].parsed.delegate&&(u=t.getIndexOrAdd(a,i[0].parsed.delegate));const m=[];i.forEach(((e,i)=>{const n=t.getIndexOrAdd(a,e.compressedAccount.merkleTree),r=t.getIndexOrAdd(a,e.compressedAccount.nullifierQueue);m.push({amount:e.parsed.amount,delegateIndex:u,merkleContext:{merkleTreePubkeyIndex:n,nullifierQueuePubkeyIndex:r,leafIndex:e.compressedAccount.leafIndex,queueIndex:null},rootIndex:o[i],lamports:e.compressedAccount.lamports.eq(t.bn(0))?null:e.compressedAccount.lamports,tlv:null})}));const h=t.padOutputStateMerkleTrees(n,s.length,i.map((t=>t.compressedAccount))),l=[];h.forEach(((e,i)=>{var n;const r=t.getIndexOrAdd(a,e);l.push({owner:s[i].owner,amount:s[i].amount,lamports:(null===(n=s[i].lamports)||void 0===n?void 0:n.eq(t.bn(0)))?null:s[i].lamports,merkleTreeIndex:r,tlv:null})}));const d=a.map((t=>({pubkey:t,isWritable:1,isSigner:0})));return{inputTokenDataWithContext:m,remainingAccountMetas:d,packedOutputTokenData:l}}const s=Buffer.from("pool"),a=Buffer.from("cpi_authority"),u=Buffer.from([23,169,27,122,147,169,209,152]),m=Buffer.from([241,34,48,186,37,179,123,192]),h=Buffer.from([163,52,200,231,140,3,69,186]),l=Buffer.from([112,230,105,101,145,202,157,97]);var d="undefined"!=typeof globalThis?globalThis:"undefined"!=typeof window?window:"undefined"!=typeof global?global:"undefined"!=typeof self?self:{};function c(t){return t&&t.__esModule&&Object.prototype.hasOwnProperty.call(t,"default")?t.default:t}function p(t){if(t.__esModule)return t;var e=t.default;if("function"==typeof e){var i=function t(){return this instanceof t?Reflect.construct(e,arguments,this.constructor):e.apply(this,arguments)};i.prototype=e.prototype}else i={};return Object.defineProperty(i,"__esModule",{value:1}),Object.keys(t).forEach((function(e){var n=Object.getOwnPropertyDescriptor(t,e);Object.defineProperty(i,e,n.get?n:{enumerable:1,get:function(){return t[e]}})})),i}var g={exports:{}},f=p(Object.freeze({__proto__:null,default:{}}));!function(t,e){function i(t,e){if(!t)throw new Error(e||"Assertion failed")}function n(t,e){t.super_=e;var i=function(){};i.prototype=e.prototype,t.prototype=new i,t.prototype.constructor=t}function r(t,e,i){if(r.isBN(t))return t;this.negative=0,this.words=null,this.length=0,this.red=null,null!==t&&("le"!==e&&"be"!==e||(i=e,e=10),this._init(t||0,e||10,i||"be"))}var o;"object"==typeof g?g.exports=r:e.BN=r,r.BN=r,r.wordSize=26;try{o="undefined"!=typeof window&&void 0!==window.Buffer?window.Buffer:f.Buffer}catch(t){}function s(t,e){var n=t.charCodeAt(e);return n>=48&&n<=57?n-48:n>=65&&n<=70?n-55:n>=97&&n<=102?n-87:void i(0,"Invalid character in "+t)}function a(t,e,i){var n=s(t,i);return i-1>=e&&(n|=s(t,i-1)<<4),n}function u(t,e,n,r){for(var o=0,s=0,a=Math.min(t.length,n),u=e;u<a;u++){var m=t.charCodeAt(u)-48;o*=r,s=m>=49?m-49+10:m>=17?m-17+10:m,i(m>=0&&s<r,"Invalid character"),o+=s}return o}function m(t,e){t.words=e.words,t.length=e.length,t.negative=e.negative,t.red=e.red}if(r.isBN=function(t){return t instanceof r?1:null!==t&&"object"==typeof t&&t.constructor.wordSize===r.wordSize&&Array.isArray(t.words)},r.max=function(t,e){return t.cmp(e)>0?t:e},r.min=function(t,e){return t.cmp(e)<0?t:e},r.prototype._init=function(t,e,n){if("number"==typeof t)return this._initNumber(t,e,n);if("object"==typeof t)return this._initArray(t,e,n);"hex"===e&&(e=16),i(e===(0|e)&&e>=2&&e<=36);var r=0;"-"===(t=t.toString().replace(/\s+/g,""))[0]&&(r++,this.negative=1),r<t.length&&(16===e?this._parseHex(t,r,n):(this._parseBase(t,e,r),"le"===n&&this._initArray(this.toArray(),e,n)))},r.prototype._initNumber=function(t,e,n){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):(i(t<9007199254740992),this.words=[67108863&t,t/67108864&67108863,1],this.length=3),"le"===n&&this._initArray(this.toArray(),e,n)},r.prototype._initArray=function(t,e,n){if(i("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 r=0;r<this.length;r++)this.words[r]=0;var o,s,a=0;if("be"===n)for(r=t.length-1,o=0;r>=0;r-=3)s=t[r]|t[r-1]<<8|t[r-2]<<16,this.words[o]|=s<<a&67108863,this.words[o+1]=s>>>26-a&67108863,(a+=24)>=26&&(a-=26,o++);else if("le"===n)for(r=0,o=0;r<t.length;r+=3)s=t[r]|t[r+1]<<8|t[r+2]<<16,this.words[o]|=s<<a&67108863,this.words[o+1]=s>>>26-a&67108863,(a+=24)>=26&&(a-=26,o++);return this._strip()},r.prototype._parseHex=function(t,e,i){this.length=Math.ceil((t.length-e)/6),this.words=new Array(this.length);for(var n=0;n<this.length;n++)this.words[n]=0;var r,o=0,s=0;if("be"===i)for(n=t.length-1;n>=e;n-=2)r=a(t,e,n)<<o,this.words[s]|=67108863&r,o>=18?(o-=18,s+=1,this.words[s]|=r>>>26):o+=8;else for(n=(t.length-e)%2==0?e+1:e;n<t.length;n+=2)r=a(t,e,n)<<o,this.words[s]|=67108863&r,o>=18?(o-=18,s+=1,this.words[s]|=r>>>26):o+=8;this._strip()},r.prototype._parseBase=function(t,e,i){this.words=[0],this.length=1;for(var n=0,r=1;r<=67108863;r*=e)n++;n--,r=r/e|0;for(var o=t.length-i,s=o%n,a=Math.min(o,o-s)+i,m=0,h=i;h<a;h+=n)m=u(t,h,h+n,e),this.imuln(r),this.words[0]+m<67108864?this.words[0]+=m:this._iaddn(m);if(0!==s){var l=1;for(m=u(t,h,t.length,e),h=0;h<s;h++)l*=e;this.imuln(l),this.words[0]+m<67108864?this.words[0]+=m:this._iaddn(m)}this._strip()},r.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},r.prototype._move=function(t){m(t,this)},r.prototype.clone=function(){var t=new r(null);return this.copy(t),t},r.prototype._expand=function(t){for(;this.length<t;)this.words[this.length++]=0;return this},r.prototype._strip=function(){for(;this.length>1&&0===this.words[this.length-1];)this.length--;return this._normSign()},r.prototype._normSign=function(){return 1===this.length&&0===this.words[0]&&(this.negative=0),this},"undefined"!=typeof Symbol&&"function"==typeof Symbol.for)try{r.prototype[Symbol.for("nodejs.util.inspect.custom")]=h}catch(t){r.prototype.inspect=h}else r.prototype.inspect=h;function h(){return(this.red?"<BN-R: ":"<BN: ")+this.toString(16)+">"}var l=["","0","00","000","0000","00000","000000","0000000","00000000","000000000","0000000000","00000000000","000000000000","0000000000000","00000000000000","000000000000000","0000000000000000","00000000000000000","000000000000000000","0000000000000000000","00000000000000000000","000000000000000000000","0000000000000000000000","00000000000000000000000","000000000000000000000000","0000000000000000000000000"],d=[0,0,25,16,12,11,10,9,8,8,7,7,7,7,6,6,6,6,6,6,6,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5],c=[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 p(t,e,i){i.negative=e.negative^t.negative;var n=t.length+e.length|0;i.length=n,n=n-1|0;var r=0|t.words[0],o=0|e.words[0],s=r*o,a=67108863&s,u=s/67108864|0;i.words[0]=a;for(var m=1;m<n;m++){for(var h=u>>>26,l=67108863&u,d=Math.min(m,e.length-1),c=Math.max(0,m-t.length+1);c<=d;c++){var p=m-c|0;h+=(s=(r=0|t.words[p])*(o=0|e.words[c])+l)/67108864|0,l=67108863&s}i.words[m]=0|l,u=0|h}return 0!==u?i.words[m]=0|u:i.length--,i._strip()}r.prototype.toString=function(t,e){var n;if(e=0|e||1,16===(t=t||10)||"hex"===t){n="";for(var r=0,o=0,s=0;s<this.length;s++){var a=this.words[s],u=(16777215&(a<<r|o)).toString(16);o=a>>>24-r&16777215,(r+=2)>=26&&(r-=26,s--),n=0!==o||s!==this.length-1?l[6-u.length]+u+n:u+n}for(0!==o&&(n=o.toString(16)+n);n.length%e!=0;)n="0"+n;return 0!==this.negative&&(n="-"+n),n}if(t===(0|t)&&t>=2&&t<=36){var m=d[t],h=c[t];n="";var p=this.clone();for(p.negative=0;!p.isZero();){var g=p.modrn(h).toString(t);n=(p=p.idivn(h)).isZero()?g+n:l[m-g.length]+g+n}for(this.isZero()&&(n="0"+n);n.length%e!=0;)n="0"+n;return 0!==this.negative&&(n="-"+n),n}i(0,"Base should be between 2 and 36")},r.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&&i(0,"Number can only safely store up to 53 bits"),0!==this.negative?-t:t},r.prototype.toJSON=function(){return this.toString(16,2)},o&&(r.prototype.toBuffer=function(t,e){return this.toArrayLike(o,t,e)}),r.prototype.toArray=function(t,e){return this.toArrayLike(Array,t,e)},r.prototype.toArrayLike=function(t,e,n){this._strip();var r=this.byteLength(),o=n||Math.max(1,r);i(r<=o,"byte array longer than desired length"),i(o>0,"Requested array length <= 0");var s=function(t,e){return t.allocUnsafe?t.allocUnsafe(e):new t(e)}(t,o);return this["_toArrayLike"+("le"===e?"LE":"BE")](s,r),s},r.prototype._toArrayLikeLE=function(t){for(var e=0,i=0,n=0,r=0;n<this.length;n++){var o=this.words[n]<<r|i;t[e++]=255&o,e<t.length&&(t[e++]=o>>8&255),e<t.length&&(t[e++]=o>>16&255),6===r?(e<t.length&&(t[e++]=o>>24&255),i=0,r=0):(i=o>>>24,r+=2)}if(e<t.length)for(t[e++]=i;e<t.length;)t[e++]=0},r.prototype._toArrayLikeBE=function(t){for(var e=t.length-1,i=0,n=0,r=0;n<this.length;n++){var o=this.words[n]<<r|i;t[e--]=255&o,e>=0&&(t[e--]=o>>8&255),e>=0&&(t[e--]=o>>16&255),6===r?(e>=0&&(t[e--]=o>>24&255),i=0,r=0):(i=o>>>24,r+=2)}if(e>=0)for(t[e--]=i;e>=0;)t[e--]=0},Math.clz32?r.prototype._countBits=function(t){return 32-Math.clz32(t)}:r.prototype._countBits=function(t){var e=t,i=0;return e>=4096&&(i+=13,e>>>=13),e>=64&&(i+=7,e>>>=7),e>=8&&(i+=4,e>>>=4),e>=2&&(i+=2,e>>>=2),i+e},r.prototype._zeroBits=function(t){if(0===t)return 26;var e=t,i=0;return 0==(8191&e)&&(i+=13,e>>>=13),0==(127&e)&&(i+=7,e>>>=7),0==(15&e)&&(i+=4,e>>>=4),0==(3&e)&&(i+=2,e>>>=2),0==(1&e)&&i++,i},r.prototype.bitLength=function(){var t=this.words[this.length-1],e=this._countBits(t);return 26*(this.length-1)+e},r.prototype.zeroBits=function(){if(this.isZero())return 0;for(var t=0,e=0;e<this.length;e++){var i=this._zeroBits(this.words[e]);if(t+=i,26!==i)break}return t},r.prototype.byteLength=function(){return Math.ceil(this.bitLength()/8)},r.prototype.toTwos=function(t){return 0!==this.negative?this.abs().inotn(t).iaddn(1):this.clone()},r.prototype.fromTwos=function(t){return this.testn(t-1)?this.notn(t).iaddn(1).ineg():this.clone()},r.prototype.isNeg=function(){return 0!==this.negative},r.prototype.neg=function(){return this.clone().ineg()},r.prototype.ineg=function(){return this.isZero()||(this.negative^=1),this},r.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()},r.prototype.ior=function(t){return i(0==(this.negative|t.negative)),this.iuor(t)},r.prototype.or=function(t){return this.length>t.length?this.clone().ior(t):t.clone().ior(this)},r.prototype.uor=function(t){return this.length>t.length?this.clone().iuor(t):t.clone().iuor(this)},r.prototype.iuand=function(t){var e;e=this.length>t.length?t:this;for(var i=0;i<e.length;i++)this.words[i]=this.words[i]&t.words[i];return this.length=e.length,this._strip()},r.prototype.iand=function(t){return i(0==(this.negative|t.negative)),this.iuand(t)},r.prototype.and=function(t){return this.length>t.length?this.clone().iand(t):t.clone().iand(this)},r.prototype.uand=function(t){return this.length>t.length?this.clone().iuand(t):t.clone().iuand(this)},r.prototype.iuxor=function(t){var e,i;this.length>t.length?(e=this,i=t):(e=t,i=this);for(var n=0;n<i.length;n++)this.words[n]=e.words[n]^i.words[n];if(this!==e)for(;n<e.length;n++)this.words[n]=e.words[n];return this.length=e.length,this._strip()},r.prototype.ixor=function(t){return i(0==(this.negative|t.negative)),this.iuxor(t)},r.prototype.xor=function(t){return this.length>t.length?this.clone().ixor(t):t.clone().ixor(this)},r.prototype.uxor=function(t){return this.length>t.length?this.clone().iuxor(t):t.clone().iuxor(this)},r.prototype.inotn=function(t){i("number"==typeof t&&t>=0);var e=0|Math.ceil(t/26),n=t%26;this._expand(e),n>0&&e--;for(var r=0;r<e;r++)this.words[r]=67108863&~this.words[r];return n>0&&(this.words[r]=~this.words[r]&67108863>>26-n),this._strip()},r.prototype.notn=function(t){return this.clone().inotn(t)},r.prototype.setn=function(t,e){i("number"==typeof t&&t>=0);var n=t/26|0,r=t%26;return this._expand(n+1),this.words[n]=e?this.words[n]|1<<r:this.words[n]&~(1<<r),this._strip()},r.prototype.iadd=function(t){var e,i,n;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?(i=this,n=t):(i=t,n=this);for(var r=0,o=0;o<n.length;o++)e=(0|i.words[o])+(0|n.words[o])+r,this.words[o]=67108863&e,r=e>>>26;for(;0!==r&&o<i.length;o++)e=(0|i.words[o])+r,this.words[o]=67108863&e,r=e>>>26;if(this.length=i.length,0!==r)this.words[this.length]=r,this.length++;else if(i!==this)for(;o<i.length;o++)this.words[o]=i.words[o];return this},r.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)},r.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 i,n,r=this.cmp(t);if(0===r)return this.negative=0,this.length=1,this.words[0]=0,this;r>0?(i=this,n=t):(i=t,n=this);for(var o=0,s=0;s<n.length;s++)o=(e=(0|i.words[s])-(0|n.words[s])+o)>>26,this.words[s]=67108863&e;for(;0!==o&&s<i.length;s++)o=(e=(0|i.words[s])+o)>>26,this.words[s]=67108863&e;if(0===o&&s<i.length&&i!==this)for(;s<i.length;s++)this.words[s]=i.words[s];return this.length=Math.max(this.length,s),i!==this&&(this.negative=1),this._strip()},r.prototype.sub=function(t){return this.clone().isub(t)};var y=function(t,e,i){var n,r,o,s=t.words,a=e.words,u=i.words,m=0,h=0|s[0],l=8191&h,d=h>>>13,c=0|s[1],p=8191&c,g=c>>>13,f=0|s[2],y=8191&f,M=f>>>13,v=0|s[3],w=8191&v,b=v>>>13,k=0|s[4],P=8191&k,S=k>>>13,A=0|s[5],T=8191&A,C=A>>>13,I=0|s[6],x=8191&I,_=I>>>13,O=0|s[7],D=8191&O,E=O>>>13,B=0|s[8],K=8191&B,L=B>>>13,R=0|s[9],N=8191&R,W=R>>>13,q=0|a[0],F=8191&q,U=q>>>13,z=0|a[1],Z=8191&z,H=z>>>13,j=0|a[2],V=8191&j,G=j>>>13,Q=0|a[3],$=8191&Q,X=Q>>>13,Y=0|a[4],J=8191&Y,tt=Y>>>13,et=0|a[5],it=8191&et,nt=et>>>13,rt=0|a[6],ot=8191&rt,st=rt>>>13,at=0|a[7],ut=8191&at,mt=at>>>13,ht=0|a[8],lt=8191&ht,dt=ht>>>13,ct=0|a[9],pt=8191&ct,gt=ct>>>13;i.negative=t.negative^e.negative,i.length=19;var ft=(m+(n=Math.imul(l,F))|0)+((8191&(r=(r=Math.imul(l,U))+Math.imul(d,F)|0))<<13)|0;m=((o=Math.imul(d,U))+(r>>>13)|0)+(ft>>>26)|0,ft&=67108863,n=Math.imul(p,F),r=(r=Math.imul(p,U))+Math.imul(g,F)|0,o=Math.imul(g,U);var yt=(m+(n=n+Math.imul(l,Z)|0)|0)+((8191&(r=(r=r+Math.imul(l,H)|0)+Math.imul(d,Z)|0))<<13)|0;m=((o=o+Math.imul(d,H)|0)+(r>>>13)|0)+(yt>>>26)|0,yt&=67108863,n=Math.imul(y,F),r=(r=Math.imul(y,U))+Math.imul(M,F)|0,o=Math.imul(M,U),n=n+Math.imul(p,Z)|0,r=(r=r+Math.imul(p,H)|0)+Math.imul(g,Z)|0,o=o+Math.imul(g,H)|0;var Mt=(m+(n=n+Math.imul(l,V)|0)|0)+((8191&(r=(r=r+Math.imul(l,G)|0)+Math.imul(d,V)|0))<<13)|0;m=((o=o+Math.imul(d,G)|0)+(r>>>13)|0)+(Mt>>>26)|0,Mt&=67108863,n=Math.imul(w,F),r=(r=Math.imul(w,U))+Math.imul(b,F)|0,o=Math.imul(b,U),n=n+Math.imul(y,Z)|0,r=(r=r+Math.imul(y,H)|0)+Math.imul(M,Z)|0,o=o+Math.imul(M,H)|0,n=n+Math.imul(p,V)|0,r=(r=r+Math.imul(p,G)|0)+Math.imul(g,V)|0,o=o+Math.imul(g,G)|0;var vt=(m+(n=n+Math.imul(l,$)|0)|0)+((8191&(r=(r=r+Math.imul(l,X)|0)+Math.imul(d,$)|0))<<13)|0;m=((o=o+Math.imul(d,X)|0)+(r>>>13)|0)+(vt>>>26)|0,vt&=67108863,n=Math.imul(P,F),r=(r=Math.imul(P,U))+Math.imul(S,F)|0,o=Math.imul(S,U),n=n+Math.imul(w,Z)|0,r=(r=r+Math.imul(w,H)|0)+Math.imul(b,Z)|0,o=o+Math.imul(b,H)|0,n=n+Math.imul(y,V)|0,r=(r=r+Math.imul(y,G)|0)+Math.imul(M,V)|0,o=o+Math.imul(M,G)|0,n=n+Math.imul(p,$)|0,r=(r=r+Math.imul(p,X)|0)+Math.imul(g,$)|0,o=o+Math.imul(g,X)|0;var wt=(m+(n=n+Math.imul(l,J)|0)|0)+((8191&(r=(r=r+Math.imul(l,tt)|0)+Math.imul(d,J)|0))<<13)|0;m=((o=o+Math.imul(d,tt)|0)+(r>>>13)|0)+(wt>>>26)|0,wt&=67108863,n=Math.imul(T,F),r=(r=Math.imul(T,U))+Math.imul(C,F)|0,o=Math.imul(C,U),n=n+Math.imul(P,Z)|0,r=(r=r+Math.imul(P,H)|0)+Math.imul(S,Z)|0,o=o+Math.imul(S,H)|0,n=n+Math.imul(w,V)|0,r=(r=r+Math.imul(w,G)|0)+Math.imul(b,V)|0,o=o+Math.imul(b,G)|0,n=n+Math.imul(y,$)|0,r=(r=r+Math.imul(y,X)|0)+Math.imul(M,$)|0,o=o+Math.imul(M,X)|0,n=n+Math.imul(p,J)|0,r=(r=r+Math.imul(p,tt)|0)+Math.imul(g,J)|0,o=o+Math.imul(g,tt)|0;var bt=(m+(n=n+Math.imul(l,it)|0)|0)+((8191&(r=(r=r+Math.imul(l,nt)|0)+Math.imul(d,it)|0))<<13)|0;m=((o=o+Math.imul(d,nt)|0)+(r>>>13)|0)+(bt>>>26)|0,bt&=67108863,n=Math.imul(x,F),r=(r=Math.imul(x,U))+Math.imul(_,F)|0,o=Math.imul(_,U),n=n+Math.imul(T,Z)|0,r=(r=r+Math.imul(T,H)|0)+Math.imul(C,Z)|0,o=o+Math.imul(C,H)|0,n=n+Math.imul(P,V)|0,r=(r=r+Math.imul(P,G)|0)+Math.imul(S,V)|0,o=o+Math.imul(S,G)|0,n=n+Math.imul(w,$)|0,r=(r=r+Math.imul(w,X)|0)+Math.imul(b,$)|0,o=o+Math.imul(b,X)|0,n=n+Math.imul(y,J)|0,r=(r=r+Math.imul(y,tt)|0)+Math.imul(M,J)|0,o=o+Math.imul(M,tt)|0,n=n+Math.imul(p,it)|0,r=(r=r+Math.imul(p,nt)|0)+Math.imul(g,it)|0,o=o+Math.imul(g,nt)|0;var kt=(m+(n=n+Math.imul(l,ot)|0)|0)+((8191&(r=(r=r+Math.imul(l,st)|0)+Math.imul(d,ot)|0))<<13)|0;m=((o=o+Math.imul(d,st)|0)+(r>>>13)|0)+(kt>>>26)|0,kt&=67108863,n=Math.imul(D,F),r=(r=Math.imul(D,U))+Math.imul(E,F)|0,o=Math.imul(E,U),n=n+Math.imul(x,Z)|0,r=(r=r+Math.imul(x,H)|0)+Math.imul(_,Z)|0,o=o+Math.imul(_,H)|0,n=n+Math.imul(T,V)|0,r=(r=r+Math.imul(T,G)|0)+Math.imul(C,V)|0,o=o+Math.imul(C,G)|0,n=n+Math.imul(P,$)|0,r=(r=r+Math.imul(P,X)|0)+Math.imul(S,$)|0,o=o+Math.imul(S,X)|0,n=n+Math.imul(w,J)|0,r=(r=r+Math.imul(w,tt)|0)+Math.imul(b,J)|0,o=o+Math.imul(b,tt)|0,n=n+Math.imul(y,it)|0,r=(r=r+Math.imul(y,nt)|0)+Math.imul(M,it)|0,o=o+Math.imul(M,nt)|0,n=n+Math.imul(p,ot)|0,r=(r=r+Math.imul(p,st)|0)+Math.imul(g,ot)|0,o=o+Math.imul(g,st)|0;var Pt=(m+(n=n+Math.imul(l,ut)|0)|0)+((8191&(r=(r=r+Math.imul(l,mt)|0)+Math.imul(d,ut)|0))<<13)|0;m=((o=o+Math.imul(d,mt)|0)+(r>>>13)|0)+(Pt>>>26)|0,Pt&=67108863,n=Math.imul(K,F),r=(r=Math.imul(K,U))+Math.imul(L,F)|0,o=Math.imul(L,U),n=n+Math.imul(D,Z)|0,r=(r=r+Math.imul(D,H)|0)+Math.imul(E,Z)|0,o=o+Math.imul(E,H)|0,n=n+Math.imul(x,V)|0,r=(r=r+Math.imul(x,G)|0)+Math.imul(_,V)|0,o=o+Math.imul(_,G)|0,n=n+Math.imul(T,$)|0,r=(r=r+Math.imul(T,X)|0)+Math.imul(C,$)|0,o=o+Math.imul(C,X)|0,n=n+Math.imul(P,J)|0,r=(r=r+Math.imul(P,tt)|0)+Math.imul(S,J)|0,o=o+Math.imul(S,tt)|0,n=n+Math.imul(w,it)|0,r=(r=r+Math.imul(w,nt)|0)+Math.imul(b,it)|0,o=o+Math.imul(b,nt)|0,n=n+Math.imul(y,ot)|0,r=(r=r+Math.imul(y,st)|0)+Math.imul(M,ot)|0,o=o+Math.imul(M,st)|0,n=n+Math.imul(p,ut)|0,r=(r=r+Math.imul(p,mt)|0)+Math.imul(g,ut)|0,o=o+Math.imul(g,mt)|0;var St=(m+(n=n+Math.imul(l,lt)|0)|0)+((8191&(r=(r=r+Math.imul(l,dt)|0)+Math.imul(d,lt)|0))<<13)|0;m=((o=o+Math.imul(d,dt)|0)+(r>>>13)|0)+(St>>>26)|0,St&=67108863,n=Math.imul(N,F),r=(r=Math.imul(N,U))+Math.imul(W,F)|0,o=Math.imul(W,U),n=n+Math.imul(K,Z)|0,r=(r=r+Math.imul(K,H)|0)+Math.imul(L,Z)|0,o=o+Math.imul(L,H)|0,n=n+Math.imul(D,V)|0,r=(r=r+Math.imul(D,G)|0)+Math.imul(E,V)|0,o=o+Math.imul(E,G)|0,n=n+Math.imul(x,$)|0,r=(r=r+Math.imul(x,X)|0)+Math.imul(_,$)|0,o=o+Math.imul(_,X)|0,n=n+Math.imul(T,J)|0,r=(r=r+Math.imul(T,tt)|0)+Math.imul(C,J)|0,o=o+Math.imul(C,tt)|0,n=n+Math.imul(P,it)|0,r=(r=r+Math.imul(P,nt)|0)+Math.imul(S,it)|0,o=o+Math.imul(S,nt)|0,n=n+Math.imul(w,ot)|0,r=(r=r+Math.imul(w,st)|0)+Math.imul(b,ot)|0,o=o+Math.imul(b,st)|0,n=n+Math.imul(y,ut)|0,r=(r=r+Math.imul(y,mt)|0)+Math.imul(M,ut)|0,o=o+Math.imul(M,mt)|0,n=n+Math.imul(p,lt)|0,r=(r=r+Math.imul(p,dt)|0)+Math.imul(g,lt)|0,o=o+Math.imul(g,dt)|0;var At=(m+(n=n+Math.imul(l,pt)|0)|0)+((8191&(r=(r=r+Math.imul(l,gt)|0)+Math.imul(d,pt)|0))<<13)|0;m=((o=o+Math.imul(d,gt)|0)+(r>>>13)|0)+(At>>>26)|0,At&=67108863,n=Math.imul(N,Z),r=(r=Math.imul(N,H))+Math.imul(W,Z)|0,o=Math.imul(W,H),n=n+Math.imul(K,V)|0,r=(r=r+Math.imul(K,G)|0)+Math.imul(L,V)|0,o=o+Math.imul(L,G)|0,n=n+Math.imul(D,$)|0,r=(r=r+Math.imul(D,X)|0)+Math.imul(E,$)|0,o=o+Math.imul(E,X)|0,n=n+Math.imul(x,J)|0,r=(r=r+Math.imul(x,tt)|0)+Math.imul(_,J)|0,o=o+Math.imul(_,tt)|0,n=n+Math.imul(T,it)|0,r=(r=r+Math.imul(T,nt)|0)+Math.imul(C,it)|0,o=o+Math.imul(C,nt)|0,n=n+Math.imul(P,ot)|0,r=(r=r+Math.imul(P,st)|0)+Math.imul(S,ot)|0,o=o+Math.imul(S,st)|0,n=n+Math.imul(w,ut)|0,r=(r=r+Math.imul(w,mt)|0)+Math.imul(b,ut)|0,o=o+Math.imul(b,mt)|0,n=n+Math.imul(y,lt)|0,r=(r=r+Math.imul(y,dt)|0)+Math.imul(M,lt)|0,o=o+Math.imul(M,dt)|0;var Tt=(m+(n=n+Math.imul(p,pt)|0)|0)+((8191&(r=(r=r+Math.imul(p,gt)|0)+Math.imul(g,pt)|0))<<13)|0;m=((o=o+Math.imul(g,gt)|0)+(r>>>13)|0)+(Tt>>>26)|0,Tt&=67108863,n=Math.imul(N,V),r=(r=Math.imul(N,G))+Math.imul(W,V)|0,o=Math.imul(W,G),n=n+Math.imul(K,$)|0,r=(r=r+Math.imul(K,X)|0)+Math.imul(L,$)|0,o=o+Math.imul(L,X)|0,n=n+Math.imul(D,J)|0,r=(r=r+Math.imul(D,tt)|0)+Math.imul(E,J)|0,o=o+Math.imul(E,tt)|0,n=n+Math.imul(x,it)|0,r=(r=r+Math.imul(x,nt)|0)+Math.imul(_,it)|0,o=o+Math.imul(_,nt)|0,n=n+Math.imul(T,ot)|0,r=(r=r+Math.imul(T,st)|0)+Math.imul(C,ot)|0,o=o+Math.imul(C,st)|0,n=n+Math.imul(P,ut)|0,r=(r=r+Math.imul(P,mt)|0)+Math.imul(S,ut)|0,o=o+Math.imul(S,mt)|0,n=n+Math.imul(w,lt)|0,r=(r=r+Math.imul(w,dt)|0)+Math.imul(b,lt)|0,o=o+Math.imul(b,dt)|0;var Ct=(m+(n=n+Math.imul(y,pt)|0)|0)+((8191&(r=(r=r+Math.imul(y,gt)|0)+Math.imul(M,pt)|0))<<13)|0;m=((o=o+Math.imul(M,gt)|0)+(r>>>13)|0)+(Ct>>>26)|0,Ct&=67108863,n=Math.imul(N,$),r=(r=Math.imul(N,X))+Math.imul(W,$)|0,o=Math.imul(W,X),n=n+Math.imul(K,J)|0,r=(r=r+Math.imul(K,tt)|0)+Math.imul(L,J)|0,o=o+Math.imul(L,tt)|0,n=n+Math.imul(D,it)|0,r=(r=r+Math.imul(D,nt)|0)+Math.imul(E,it)|0,o=o+Math.imul(E,nt)|0,n=n+Math.imul(x,ot)|0,r=(r=r+Math.imul(x,st)|0)+Math.imul(_,ot)|0,o=o+Math.imul(_,st)|0,n=n+Math.imul(T,ut)|0,r=(r=r+Math.imul(T,mt)|0)+Math.imul(C,ut)|0,o=o+Math.imul(C,mt)|0,n=n+Math.imul(P,lt)|0,r=(r=r+Math.imul(P,dt)|0)+Math.imul(S,lt)|0,o=o+Math.imul(S,dt)|0;var It=(m+(n=n+Math.imul(w,pt)|0)|0)+((8191&(r=(r=r+Math.imul(w,gt)|0)+Math.imul(b,pt)|0))<<13)|0;m=((o=o+Math.imul(b,gt)|0)+(r>>>13)|0)+(It>>>26)|0,It&=67108863,n=Math.imul(N,J),r=(r=Math.imul(N,tt))+Math.imul(W,J)|0,o=Math.imul(W,tt),n=n+Math.imul(K,it)|0,r=(r=r+Math.imul(K,nt)|0)+Math.imul(L,it)|0,o=o+Math.imul(L,nt)|0,n=n+Math.imul(D,ot)|0,r=(r=r+Math.imul(D,st)|0)+Math.imul(E,ot)|0,o=o+Math.imul(E,st)|0,n=n+Math.imul(x,ut)|0,r=(r=r+Math.imul(x,mt)|0)+Math.imul(_,ut)|0,o=o+Math.imul(_,mt)|0,n=n+Math.imul(T,lt)|0,r=(r=r+Math.imul(T,dt)|0)+Math.imul(C,lt)|0,o=o+Math.imul(C,dt)|0;var xt=(m+(n=n+Math.imul(P,pt)|0)|0)+((8191&(r=(r=r+Math.imul(P,gt)|0)+Math.imul(S,pt)|0))<<13)|0;m=((o=o+Math.imul(S,gt)|0)+(r>>>13)|0)+(xt>>>26)|0,xt&=67108863,n=Math.imul(N,it),r=(r=Math.imul(N,nt))+Math.imul(W,it)|0,o=Math.imul(W,nt),n=n+Math.imul(K,ot)|0,r=(r=r+Math.imul(K,st)|0)+Math.imul(L,ot)|0,o=o+Math.imul(L,st)|0,n=n+Math.imul(D,ut)|0,r=(r=r+Math.imul(D,mt)|0)+Math.imul(E,ut)|0,o=o+Math.imul(E,mt)|0,n=n+Math.imul(x,lt)|0,r=(r=r+Math.imul(x,dt)|0)+Math.imul(_,lt)|0,o=o+Math.imul(_,dt)|0;var _t=(m+(n=n+Math.imul(T,pt)|0)|0)+((8191&(r=(r=r+Math.imul(T,gt)|0)+Math.imul(C,pt)|0))<<13)|0;m=((o=o+Math.imul(C,gt)|0)+(r>>>13)|0)+(_t>>>26)|0,_t&=67108863,n=Math.imul(N,ot),r=(r=Math.imul(N,st))+Math.imul(W,ot)|0,o=Math.imul(W,st),n=n+Math.imul(K,ut)|0,r=(r=r+Math.imul(K,mt)|0)+Math.imul(L,ut)|0,o=o+Math.imul(L,mt)|0,n=n+Math.imul(D,lt)|0,r=(r=r+Math.imul(D,dt)|0)+Math.imul(E,lt)|0,o=o+Math.imul(E,dt)|0;var Ot=(m+(n=n+Math.imul(x,pt)|0)|0)+((8191&(r=(r=r+Math.imul(x,gt)|0)+Math.imul(_,pt)|0))<<13)|0;m=((o=o+Math.imul(_,gt)|0)+(r>>>13)|0)+(Ot>>>26)|0,Ot&=67108863,n=Math.imul(N,ut),r=(r=Math.imul(N,mt))+Math.imul(W,ut)|0,o=Math.imul(W,mt),n=n+Math.imul(K,lt)|0,r=(r=r+Math.imul(K,dt)|0)+Math.imul(L,lt)|0,o=o+Math.imul(L,dt)|0;var Dt=(m+(n=n+Math.imul(D,pt)|0)|0)+((8191&(r=(r=r+Math.imul(D,gt)|0)+Math.imul(E,pt)|0))<<13)|0;m=((o=o+Math.imul(E,gt)|0)+(r>>>13)|0)+(Dt>>>26)|0,Dt&=67108863,n=Math.imul(N,lt),r=(r=Math.imul(N,dt))+Math.imul(W,lt)|0,o=Math.imul(W,dt);var Et=(m+(n=n+Math.imul(K,pt)|0)|0)+((8191&(r=(r=r+Math.imul(K,gt)|0)+Math.imul(L,pt)|0))<<13)|0;m=((o=o+Math.imul(L,gt)|0)+(r>>>13)|0)+(Et>>>26)|0,Et&=67108863;var Bt=(m+(n=Math.imul(N,pt))|0)+((8191&(r=(r=Math.imul(N,gt))+Math.imul(W,pt)|0))<<13)|0;return m=((o=Math.imul(W,gt))+(r>>>13)|0)+(Bt>>>26)|0,Bt&=67108863,u[0]=ft,u[1]=yt,u[2]=Mt,u[3]=vt,u[4]=wt,u[5]=bt,u[6]=kt,u[7]=Pt,u[8]=St,u[9]=At,u[10]=Tt,u[11]=Ct,u[12]=It,u[13]=xt,u[14]=_t,u[15]=Ot,u[16]=Dt,u[17]=Et,u[18]=Bt,0!==m&&(u[19]=m,i.length++),i};function M(t,e,i){i.negative=e.negative^t.negative,i.length=t.length+e.length;for(var n=0,r=0,o=0;o<i.length-1;o++){var s=r;r=0;for(var a=67108863&n,u=Math.min(o,e.length-1),m=Math.max(0,o-t.length+1);m<=u;m++){var h=o-m,l=(0|t.words[h])*(0|e.words[m]),d=67108863&l;a=67108863&(d=d+a|0),r+=(s=(s=s+(l/67108864|0)|0)+(d>>>26)|0)>>>26,s&=67108863}i.words[o]=a,n=s,s=r}return 0!==n?i.words[o]=n:i.length--,i._strip()}function v(t,e,i){return M(t,e,i)}Math.imul||(y=p),r.prototype.mulTo=function(t,e){var i=this.length+t.length;return 10===this.length&&10===t.length?y(this,t,e):i<63?p(this,t,e):i<1024?M(this,t,e):v(this,t,e)},r.prototype.mul=function(t){var e=new r(null);return e.words=new Array(this.length+t.length),this.mulTo(t,e)},r.prototype.mulf=function(t){var e=new r(null);return e.words=new Array(this.length+t.length),v(this,t,e)},r.prototype.imul=function(t){return this.clone().mulTo(t,this)},r.prototype.imuln=function(t){var e=t<0;e&&(t=-t),i("number"==typeof t),i(t<67108864);for(var n=0,r=0;r<this.length;r++){var o=(0|this.words[r])*t,s=(67108863&o)+(67108863&n);n>>=26,n+=o/67108864|0,n+=s>>>26,this.words[r]=67108863&s}return 0!==n&&(this.words[r]=n,this.length++),e?this.ineg():this},r.prototype.muln=function(t){return this.clone().imuln(t)},r.prototype.sqr=function(){return this.mul(this)},r.prototype.isqr=function(){return this.imul(this.clone())},r.prototype.pow=function(t){var e=function(t){for(var e=new Array(t.bitLength()),i=0;i<e.length;i++){var n=i/26|0,r=i%26;e[i]=t.words[n]>>>r&1}return e}(t);if(0===e.length)return new r(1);for(var i=this,n=0;n<e.length&&0===e[n];n++,i=i.sqr());if(++n<e.length)for(var o=i.sqr();n<e.length;n++,o=o.sqr())0!==e[n]&&(i=i.mul(o));return i},r.prototype.iushln=function(t){i("number"==typeof t&&t>=0);var e,n=t%26,r=(t-n)/26,o=67108863>>>26-n<<26-n;if(0!==n){var s=0;for(e=0;e<this.length;e++){var a=this.words[e]&o,u=(0|this.words[e])-a<<n;this.words[e]=u|s,s=a>>>26-n}s&&(this.words[e]=s,this.length++)}if(0!==r){for(e=this.length-1;e>=0;e--)this.words[e+r]=this.words[e];for(e=0;e<r;e++)this.words[e]=0;this.length+=r}return this._strip()},r.prototype.ishln=function(t){return i(0===this.negative),this.iushln(t)},r.prototype.iushrn=function(t,e,n){var r;i("number"==typeof t&&t>=0),r=e?(e-e%26)/26:0;var o=t%26,s=Math.min((t-o)/26,this.length),a=67108863^67108863>>>o<<o,u=n;if(r-=s,r=Math.max(0,r),u){for(var m=0;m<s;m++)u.words[m]=this.words[m];u.length=s}if(0===s);else if(this.length>s)for(this.length-=s,m=0;m<this.length;m++)this.words[m]=this.words[m+s];else this.words[0]=0,this.length=1;var h=0;for(m=this.length-1;m>=0&&(0!==h||m>=r);m--){var l=0|this.words[m];this.words[m]=h<<26-o|l>>>o,h=l&a}return u&&0!==h&&(u.words[u.length++]=h),0===this.length&&(this.words[0]=0,this.length=1),this._strip()},r.prototype.ishrn=function(t,e,n){return i(0===this.negative),this.iushrn(t,e,n)},r.prototype.shln=function(t){return this.clone().ishln(t)},r.prototype.ushln=function(t){return this.clone().iushln(t)},r.prototype.shrn=function(t){return this.clone().ishrn(t)},r.prototype.ushrn=function(t){return this.clone().iushrn(t)},r.prototype.testn=function(t){i("number"==typeof t&&t>=0);var e=t%26,n=(t-e)/26,r=1<<e;return this.length<=n?0:!!(this.words[n]&r)},r.prototype.imaskn=function(t){i("number"==typeof t&&t>=0);var e=t%26,n=(t-e)/26;if(i(0===this.negative,"imaskn works only with positive numbers"),this.length<=n)return this;if(0!==e&&n++,this.length=Math.min(n,this.length),0!==e){var r=67108863^67108863>>>e<<e;this.words[this.length-1]&=r}return this._strip()},r.prototype.maskn=function(t){return this.clone().imaskn(t)},r.prototype.iaddn=function(t){return i("number"==typeof t),i(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)},r.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},r.prototype.isubn=function(t){if(i("number"==typeof t),i(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()},r.prototype.addn=function(t){return this.clone().iaddn(t)},r.prototype.subn=function(t){return this.clone().isubn(t)},r.prototype.iabs=function(){return this.negative=0,this},r.prototype.abs=function(){return this.clone().iabs()},r.prototype._ishlnsubmul=function(t,e,n){var r,o,s=t.length+n;this._expand(s);var a=0;for(r=0;r<t.length;r++){o=(0|this.words[r+n])+a;var u=(0|t.words[r])*e;a=((o-=67108863&u)>>26)-(u/67108864|0),this.words[r+n]=67108863&o}for(;r<this.length-n;r++)a=(o=(0|this.words[r+n])+a)>>26,this.words[r+n]=67108863&o;if(0===a)return this._strip();for(i(-1===a),a=0,r=0;r<this.length;r++)a=(o=-(0|this.words[r])+a)>>26,this.words[r]=67108863&o;return this.negative=1,this._strip()},r.prototype._wordDiv=function(t,e){var i=(this.length,t.length),n=this.clone(),o=t,s=0|o.words[o.length-1];0!=(i=26-this._countBits(s))&&(o=o.ushln(i),n.iushln(i),s=0|o.words[o.length-1]);var a,u=n.length-o.length;if("mod"!==e){(a=new r(null)).length=u+1,a.words=new Array(a.length);for(var m=0;m<a.length;m++)a.words[m]=0}var h=n.clone()._ishlnsubmul(o,1,u);0===h.negative&&(n=h,a&&(a.words[u]=1));for(var l=u-1;l>=0;l--){var d=67108864*(0|n.words[o.length+l])+(0|n.words[o.length+l-1]);for(d=Math.min(d/s|0,67108863),n._ishlnsubmul(o,d,l);0!==n.negative;)d--,n.negative=0,n._ishlnsubmul(o,1,l),n.isZero()||(n.negative^=1);a&&(a.words[l]=d)}return a&&a._strip(),n._strip(),"div"!==e&&0!==i&&n.iushrn(i),{div:a||null,mod:n}},r.prototype.divmod=function(t,e,n){return i(!t.isZero()),this.isZero()?{div:new r(0),mod:new r(0)}:0!==this.negative&&0===t.negative?(a=this.neg().divmod(t,e),"mod"!==e&&(o=a.div.neg()),"div"!==e&&(s=a.mod.neg(),n&&0!==s.negative&&s.iadd(t)),{div:o,mod:s}):0===this.negative&&0!==t.negative?(a=this.divmod(t.neg(),e),"mod"!==e&&(o=a.div.neg()),{div:o,mod:a.mod}):0!=(this.negative&t.negative)?(a=this.neg().divmod(t.neg(),e),"div"!==e&&(s=a.mod.neg(),n&&0!==s.negative&&s.isub(t)),{div:a.div,mod:s}):t.length>this.length||this.cmp(t)<0?{div:new r(0),mod:this}:1===t.length?"div"===e?{div:this.divn(t.words[0]),mod:null}:"mod"===e?{div:null,mod:new r(this.modrn(t.words[0]))}:{div:this.divn(t.words[0]),mod:new r(this.modrn(t.words[0]))}:this._wordDiv(t,e);var o,s,a},r.prototype.div=function(t){return this.divmod(t,"div",0).div},r.prototype.mod=function(t){return this.divmod(t,"mod",0).mod},r.prototype.umod=function(t){return this.divmod(t,"mod",1).mod},r.prototype.divRound=function(t){var e=this.divmod(t);if(e.mod.isZero())return e.div;var i=0!==e.div.negative?e.mod.isub(t):e.mod,n=t.ushrn(1),r=t.andln(1),o=i.cmp(n);return o<0||1===r&&0===o?e.div:0!==e.div.negative?e.div.isubn(1):e.div.iaddn(1)},r.prototype.modrn=function(t){var e=t<0;e&&(t=-t),i(t<=67108863);for(var n=(1<<26)%t,r=0,o=this.length-1;o>=0;o--)r=(n*r+(0|this.words[o]))%t;return e?-r:r},r.prototype.modn=function(t){return this.modrn(t)},r.prototype.idivn=function(t){var e=t<0;e&&(t=-t),i(t<=67108863);for(var n=0,r=this.length-1;r>=0;r--){var o=(0|this.words[r])+67108864*n;this.words[r]=o/t|0,n=o%t}return this._strip(),e?this.ineg():this},r.prototype.divn=function(t){return this.clone().idivn(t)},r.prototype.egcd=function(t){i(0===t.negative),i(!t.isZero());var e=this,n=t.clone();e=0!==e.negative?e.umod(t):e.clone();for(var o=new r(1),s=new r(0),a=new r(0),u=new r(1),m=0;e.isEven()&&n.isEven();)e.iushrn(1),n.iushrn(1),++m;for(var h=n.clone(),l=e.clone();!e.isZero();){for(var d=0,c=1;0==(e.words[0]&c)&&d<26;++d,c<<=1);if(d>0)for(e.iushrn(d);d-- >0;)(o.isOdd()||s.isOdd())&&(o.iadd(h),s.isub(l)),o.iushrn(1),s.iushrn(1);for(var p=0,g=1;0==(n.words[0]&g)&&p<26;++p,g<<=1);if(p>0)for(n.iushrn(p);p-- >0;)(a.isOdd()||u.isOdd())&&(a.iadd(h),u.isub(l)),a.iushrn(1),u.iushrn(1);e.cmp(n)>=0?(e.isub(n),o.isub(a),s.isub(u)):(n.isub(e),a.isub(o),u.isub(s))}return{a:a,b:u,gcd:n.iushln(m)}},r.prototype._invmp=function(t){i(0===t.negative),i(!t.isZero());var e=this,n=t.clone();e=0!==e.negative?e.umod(t):e.clone();for(var o,s=new r(1),a=new r(0),u=n.clone();e.cmpn(1)>0&&n.cmpn(1)>0;){for(var m=0,h=1;0==(e.words[0]&h)&&m<26;++m,h<<=1);if(m>0)for(e.iushrn(m);m-- >0;)s.isOdd()&&s.iadd(u),s.iushrn(1);for(var l=0,d=1;0==(n.words[0]&d)&&l<26;++l,d<<=1);if(l>0)for(n.iushrn(l);l-- >0;)a.isOdd()&&a.iadd(u),a.iushrn(1);e.cmp(n)>=0?(e.isub(n),s.isub(a)):(n.isub(e),a.isub(s))}return(o=0===e.cmpn(1)?s:a).cmpn(0)<0&&o.iadd(t),o},r.prototype.gcd=function(t){if(this.isZero())return t.abs();if(t.isZero())return this.abs();var e=this.clone(),i=t.clone();e.negative=0,i.negative=0;for(var n=0;e.isEven()&&i.isEven();n++)e.iushrn(1),i.iushrn(1);for(;;){for(;e.isEven();)e.iushrn(1);for(;i.isEven();)i.iushrn(1);var r=e.cmp(i);if(r<0){var o=e;e=i,i=o}else if(0===r||0===i.cmpn(1))break;e.isub(i)}return i.iushln(n)},r.prototype.invm=function(t){return this.egcd(t).a.umod(t)},r.prototype.isEven=function(){return 0==(1&this.words[0])},r.prototype.isOdd=function(){return 1==(1&this.words[0])},r.prototype.andln=function(t){return this.words[0]&t},r.prototype.bincn=function(t){i("number"==typeof t);var e=t%26,n=(t-e)/26,r=1<<e;if(this.length<=n)return this._expand(n+1),this.words[n]|=r,this;for(var o=r,s=n;0!==o&&s<this.length;s++){var a=0|this.words[s];o=(a+=o)>>>26,a&=67108863,this.words[s]=a}return 0!==o&&(this.words[s]=o,this.length++),this},r.prototype.isZero=function(){return 1===this.length&&0===this.words[0]},r.prototype.cmpn=function(t){var e,n=t<0;if(0!==this.negative&&!n)return-1;if(0===this.negative&&n)return 1;if(this._strip(),this.length>1)e=1;else{n&&(t=-t),i(t<=67108863,"Number is too big");var r=0|this.words[0];e=r===t?0:r<t?-1:1}return 0!==this.negative?0|-e:e},r.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},r.prototype.ucmp=function(t){if(this.length>t.length)return 1;if(this.length<t.length)return-1;for(var e=0,i=this.length-1;i>=0;i--){var n=0|this.words[i],r=0|t.words[i];if(n!==r){n<r?e=-1:n>r&&(e=1);break}}return e},r.prototype.gtn=function(t){return 1===this.cmpn(t)},r.prototype.gt=function(t){return 1===this.cmp(t)},r.prototype.gten=function(t){return this.cmpn(t)>=0},r.prototype.gte=function(t){return this.cmp(t)>=0},r.prototype.ltn=function(t){return-1===this.cmpn(t)},r.prototype.lt=function(t){return-1===this.cmp(t)},r.prototype.lten=function(t){return this.cmpn(t)<=0},r.prototype.lte=function(t){return this.cmp(t)<=0},r.prototype.eqn=function(t){return 0===this.cmpn(t)},r.prototype.eq=function(t){return 0===this.cmp(t)},r.red=function(t){return new T(t)},r.prototype.toRed=function(t){return i(!this.red,"Already a number in reduction context"),i(0===this.negative,"red works only with positives"),t.convertTo(this)._forceRed(t)},r.prototype.fromRed=function(){return i(this.red,"fromRed works only with numbers in reduction context"),this.red.convertFrom(this)},r.prototype._forceRed=function(t){return this.red=t,this},r.prototype.forceRed=function(t){return i(!this.red,"Already a number in reduction context"),this._forceRed(t)},r.prototype.redAdd=function(t){return i(this.red,"redAdd works only with red numbers"),this.red.add(this,t)},r.prototype.redIAdd=function(t){return i(this.red,"redIAdd works only with red numbers"),this.red.iadd(this,t)},r.prototype.redSub=function(t){return i(this.red,"redSub works only with red numbers"),this.red.sub(this,t)},r.prototype.redISub=function(t){return i(this.red,"redISub works only with red numbers"),this.red.isub(this,t)},r.prototype.redShl=function(t){return i(this.red,"redShl works only with red numbers"),this.red.shl(this,t)},r.prototype.redMul=function(t){return i(this.red,"redMul works only with red numbers"),this.red._verify2(this,t),this.red.mul(this,t)},r.prototype.redIMul=function(t){return i(this.red,"redMul works only with red numbers"),this.red._verify2(this,t),this.red.imul(this,t)},r.prototype.redSqr=function(){return i(this.red,"redSqr works only with red numbers"),this.red._verify1(this),this.red.sqr(this)},r.prototype.redISqr=function(){return i(this.red,"redISqr works only with red numbers"),this.red._verify1(this),this.red.isqr(this)},r.prototype.redSqrt=function(){return i(this.red,"redSqrt works only with red numbers"),this.red._verify1(this),this.red.sqrt(this)},r.prototype.redInvm=function(){return i(this.red,"redInvm works only with red numbers"),this.red._verify1(this),this.red.invm(this)},r.prototype.redNeg=function(){return i(this.red,"redNeg works only with red numbers"),this.red._verify1(this),this.red.neg(this)},r.prototype.redPow=function(t){return i(this.red&&!t.red,"redPow(normalNum)"),this.red._verify1(this),this.red.pow(this,t)};var w={k256:null,p224:null,p192:null,p25519:null};function b(t,e){this.name=t,this.p=new r(e,16),this.n=this.p.bitLength(),this.k=new r(1).iushln(this.n).isub(this.p),this.tmp=this._tmp()}function k(){b.call(this,"k256","ffffffff ffffffff ffffffff ffffffff ffffffff ffffffff fffffffe fffffc2f")}function P(){b.call(this,"p224","ffffffff ffffffff ffffffff ffffffff 00000000 00000000 00000001")}function S(){b.call(this,"p192","ffffffff ffffffff ffffffff fffffffe ffffffff ffffffff")}function A(){b.call(this,"25519","7fffffffffffffff ffffffffffffffff ffffffffffffffff ffffffffffffffed")}function T(t){if("string"==typeof t){var e=r._prime(t);this.m=e.p,this.prime=e}else i(t.gtn(1),"modulus must be greater than 1"),this.m=t,this.prime=null}function C(t){T.call(this,t),this.shift=this.m.bitLength(),this.shift%26!=0&&(this.shift+=26-this.shift%26),this.r=new r(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)}b.prototype._tmp=function(){var t=new r(null);return t.words=new Array(Math.ceil(this.n/13)),t},b.prototype.ireduce=function(t){var e,i=t;do{this.split(i,this.tmp),e=(i=(i=this.imulK(i)).iadd(this.tmp)).bitLength()}while(e>this.n);var n=e<this.n?-1:i.ucmp(this.p);return 0===n?(i.words[0]=0,i.length=1):n>0?i.isub(this.p):void 0!==i.strip?i.strip():i._strip(),i},b.prototype.split=function(t,e){t.iushrn(this.n,0,e)},b.prototype.imulK=function(t){return t.imul(this.k)},n(k,b),k.prototype.split=function(t,e){for(var i=4194303,n=Math.min(t.length,9),r=0;r<n;r++)e.words[r]=t.words[r];if(e.length=n,t.length<=9)return t.words[0]=0,void(t.length=1);var o=t.words[9];for(e.words[e.length++]=o&i,r=10;r<t.length;r++){var s=0|t.words[r];t.words[r-10]=(s&i)<<4|o>>>22,o=s}o>>>=22,t.words[r-10]=o,0===o&&t.length>10?t.length-=10:t.length-=9},k.prototype.imulK=function(t){t.words[t.length]=0,t.words[t.length+1]=0,t.length+=2;for(var e=0,i=0;i<t.length;i++){var n=0|t.words[i];e+=977*n,t.words[i]=67108863&e,e=64*n+(e/67108864|0)}return 0===t.words[t.length-1]&&(t.length--,0===t.words[t.length-1]&&t.length--),t},n(P,b),n(S,b),n(A,b),A.prototype.imulK=function(t){for(var e=0,i=0;i<t.length;i++){var n=19*(0|t.words[i])+e,r=67108863&n;n>>>=26,t.words[i]=r,e=n}return 0!==e&&(t.words[t.length++]=e),t},r._prime=function(t){if(w[t])return w[t];var e;if("k256"===t)e=new k;else if("p224"===t)e=new P;else if("p192"===t)e=new S;else{if("p25519"!==t)throw new Error("Unknown prime "+t);e=new A}return w[t]=e,e},T.prototype._verify1=function(t){i(0===t.negative,"red works only with positives"),i(t.red,"red works only with red numbers")},T.prototype._verify2=function(t,e){i(0==(t.negative|e.negative),"red works only with positives"),i(t.red&&t.red===e.red,"red works only with red numbers")},T.prototype.imod=function(t){return this.prime?this.prime.ireduce(t)._forceRed(this):(m(t,t.umod(this.m)._forceRed(this)),t)},T.prototype.neg=function(t){return t.isZero()?t.clone():this.m.sub(t)._forceRed(this)},T.prototype.add=function(t,e){this._verify2(t,e);var i=t.add(e);return i.cmp(this.m)>=0&&i.isub(this.m),i._forceRed(this)},T.prototype.iadd=function(t,e){this._verify2(t,e);var i=t.iadd(e);return i.cmp(this.m)>=0&&i.isub(this.m),i},T.prototype.sub=function(t,e){this._verify2(t,e);var i=t.sub(e);return i.cmpn(0)<0&&i.iadd(this.m),i._forceRed(this)},T.prototype.isub=function(t,e){this._verify2(t,e);var i=t.isub(e);return i.cmpn(0)<0&&i.iadd(this.m),i},T.prototype.shl=function(t,e){return this._verify1(t),this.imod(t.ushln(e))},T.prototype.imul=function(t,e){return this._verify2(t,e),this.imod(t.imul(e))},T.prototype.mul=function(t,e){return this._verify2(t,e),this.imod(t.mul(e))},T.prototype.isqr=function(t){return this.imul(t,t.clone())},T.prototype.sqr=function(t){return this.mul(t,t)},T.prototype.sqrt=function(t){if(t.isZero())return t.clone();var e=this.m.andln(3);if(i(e%2==1),3===e){var n=this.m.add(new r(1)).iushrn(2);return this.pow(t,n)}for(var o=this.m.subn(1),s=0;!o.isZero()&&0===o.andln(1);)s++,o.iushrn(1);i(!o.isZero());var a=new r(1).toRed(this),u=a.redNeg(),m=this.m.subn(1).iushrn(1),h=this.m.bitLength();for(h=new r(2*h*h).toRed(this);0!==this.pow(h,m).cmp(u);)h.redIAdd(u);for(var l=this.pow(h,o),d=this.pow(t,o.addn(1).iushrn(1)),c=this.pow(t,o),p=s;0!==c.cmp(a);){for(var g=c,f=0;0!==g.cmp(a);f++)g=g.redSqr();i(f<p);var y=this.pow(l,new r(1).iushln(p-f-1));d=d.redMul(y),l=y.redSqr(),c=c.redMul(l),p=f}return d},T.prototype.invm=function(t){var e=t._invmp(this.m);return 0!==e.negative?(e.negative=0,this.imod(e).redNeg()):this.imod(e)},T.prototype.pow=function(t,e){if(e.isZero())return new r(1).toRed(this);if(0===e.cmpn(1))return t.clone();var i=new Array(16);i[0]=new r(1).toRed(this),i[1]=t;for(var n=2;n<i.length;n++)i[n]=this.mul(i[n-1],t);var o=i[0],s=0,a=0,u=e.bitLength()%26;for(0===u&&(u=26),n=e.length-1;n>=0;n--){for(var m=e.words[n],h=u-1;h>=0;h--){var l=m>>h&1;o!==i[0]&&(o=this.sqr(o)),0!==l||0!==s?(s<<=1,s|=l,(4==++a||0===n&&0===h)&&(o=this.mul(o,i[s]),a=0,s=0)):a=0}u=26}return o},T.prototype.convertTo=function(t){var e=t.umod(this.m);return e===t?e.clone():e},T.prototype.convertFrom=function(t){var e=t.clone();return e.red=null,e},r.mont=function(t){return new C(t)},n(C,T),C.prototype.convertTo=function(t){return this.imod(t.ushln(this.shift))},C.prototype.convertFrom=function(t){var e=this.imod(t.mul(this.rinv));return e.red=null,e},C.prototype.imul=function(t,e){if(t.isZero()||e.isZero())return t.words[0]=0,t.length=1,t;var i=t.imul(e),n=i.maskn(this.shift).mul(this.minv).imaskn(this.shift).mul(this.m),r=i.isub(n).iushrn(this.shift),o=r;return r.cmp(this.m)>=0?o=r.isub(this.m):r.cmpn(0)<0&&(o=r.iadd(this.m)),o._forceRed(this)},C.prototype.mul=function(t,e){if(t.isZero()||e.isZero())return new r(0)._forceRed(this);var i=t.mul(e),n=i.maskn(this.shift).mul(this.minv).imaskn(this.shift).mul(this.m),o=i.isub(n).iushrn(this.shift),s=o;return o.cmp(this.m)>=0?s=o.isub(this.m):o.cmpn(0)<0&&(s=o.iadd(this.m)),s._forceRed(this)},C.prototype.invm=function(t){return this.imod(t._invmp(this.m).mul(this.r2))._forceRed(this)}}(0,d);var y=c(g.exports);const M=n.struct([n.array(n.u8(),32,"a"),n.array(n.u8(),64,"b"),n.array(n.u8(),32,"c")]),v=n.struct([n.publicKey("owner"),n.u64("amount"),n.option(n.u64(),"lamports"),n.u8("merkleTreeIndex"),n.option(n.vecU8(),"tlv")]),w=n.struct([n.u8("queueId"),n.u16("index")]),b=n.struct([n.u64("amount"),n.option(n.u8(),"delegateIndex"),n.struct([n.u8("merkleTreePubkeyIndex"),n.u8("nullifierQueuePubkeyIndex"),n.u32("leafIndex"),n.option(w,"queueIndex")],"merkleContext"),n.u16("rootIndex"),n.option(n.u64(),"lamports"),n.option(n.vecU8(),"tlv")]),k=n.struct([n.publicKey("owner"),n.option(n.u8(),"delegateChangeAccountIndex")]),P=n.struct([n.bool("setContext"),n.bool("firstSetContext"),n.u8("cpiContextAccountIndex")]),S=n.struct([n.option(M,"proof"),n.publicKey("mint"),n.option(k,"delegatedTransfer"),n.vec(b,"inputTokenDataWithContext"),n.vec(v,"outputCompressedAccounts"),n.bool("isCompress"),n.option(n.u64(),"compressOrDecompressAmount"),n.option(P,"cpiContext"),n.option(n.u8(),"lamportsChangeAccountMerkleTreeIndex")]),A=n.struct([n.vec(n.publicKey(),"recipients"),n.vec(n.u64(),"amounts"),n.option(n.u64(),"lamports")]),T=n.struct([n.publicKey("owner"),n.option(n.u64(),"remainingAmount"),n.option(P,"cpiContext")]);function C(t){const e=r.Buffer.alloc(1e3),i=A.encode({recipients:t.recipients,amounts:t.amounts,lamports:t.lamports},e);return r.Buffer.concat([m,e.slice(0,i)])}function I(t){const e=r.Buffer.alloc(1e3),i=T.encode({owner:t.owner,remainingAmount:t.remainingAmount,cpiContext:t.cpiContext},e);return r.Buffer.concat([l,e.slice(0,i)])}function x(t){const e=r.Buffer.alloc(1e3),i=S.encode(t,e),n=r.Buffer.alloc(4);return n.writeUInt32LE(i,0),r.Buffer.concat([h,n,e.slice(0,i)])}const _=t=>{const{feePayer:e,tokenPoolPda:i,systemProgram:n,mint:r,tokenProgram:o,cpiAuthorityPda:s}=t;return[{pubkey:e,isSigner:1,isWritable:1},{pubkey:i,isSigner:0,isWritable:1},{pubkey:n,isSigner:0,isWritable:0},{pubkey:r,isSigner:0,isWritable:1},{pubkey:o,isSigner:0,isWritable:0},{pubkey:s,isSigner:0,isWritable:0}]},O=t=>{const e=N.programId,{feePayer:i,authority:n,cpiAuthorityPda:r,mint:o,tokenPoolPda:s,tokenProgram:a,lightSystemProgram:u,registeredProgramPda:m,noopProgram:h,accountCompressionAuthority:l,accountCompressionProgram:d,merkleTree:c,selfProgram:p,systemProgram:g,solPoolPda:f}=t;return[{pubkey:i,isSigner:1,isWritable:1},{pubkey:n,isSigner:1,isWritable:0},{pubkey:r,isSigner:0,isWritable:0},{pubkey:o,isSigner:0,isWritable:1},{pubkey:s,isSigner:0,isWritable:1},{pubkey:a,isSigner:0,isWritable:0},{pubkey:u,isSigner:0,isWritable:0},{pubkey:m,isSigner:0,isWritable:0},{pubkey:h,isSigner:0,isWritable:0},{pubkey:l,isSigner:0,isWritable:0},{pubkey:d,isSigner:0,isWritable:0},{pubkey:c,isSigner:0,isWritable:1},{pubkey:p,isSigner:0,isWritable:0},{pubkey:g,isSigner:0,isWritable:0},{pubkey:null!=f?f:e,isSigner:0,isWritable:1}]},D=t=>{const e=N.programId,{feePayer:i,authority:n,cpiAuthorityPda:r,lightSystemProgram:o,registeredProgramPda:s,noopProgram:a,accountCompressionAuthority:u,accountCompressionProgram:m,selfProgram:h,tokenPoolPda:l,compressOrDecompressTokenAccount:d,tokenProgram:c,systemProgram:p}=t;return[{pubkey:i,isSigner:1,isWritable:1},{pubkey:n,isSigner:1,isWritable:0},{pubkey:r,isSigner:0,isWritable:0},{pubkey:o,isSigner:0,isWritable:0},{pubkey:s,isSigner:0,isWritable:0},{pubkey:a,isSigner:0,isWritable:0},{pubkey:u,isSigner:0,isWritable:0},{pubkey:m,isSigner:0,isWritable:0},{pubkey:h,isSigner:0,isWritable:0},{pubkey:null!=l?l:e,isSigner:0,isWritable:1},{pubkey:null!=d?d:e,isSigner:0,isWritable:1},{pubkey:null!=c?c:e,isSigner:0,isWritable:0},{pubkey:p,isSigner:0,isWritable:0}]},E=e=>e.reduce(((t,e)=>t.add(e.parsed.amount)),t.bn(0)),B=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")}))},K=t=>({mint:t[0].parsed.mint,currentOwner:t[0].parsed.owner,delegate:t[0].parsed.delegate});function L(e,i,n){n=t.bn(n);const r=E(e),o=t.sumUpLamports(e.map((t=>t.compressedAccount))),s=r.sub(n);return t.validateSufficientBalance(s),s.eq(t.bn(0))&&o.eq(t.bn(0))?[{owner:i,amount:n,lamports:o,tlv:null}]:(t.validateSameOwner(e.map((t=>t.compressedAccount))),B(e),[{owner:e[0].parsed.owner,amount:s,lamports:o,tlv:null},{owner:i,amount:n,lamports:t.bn(0),tlv:null}])}function R(e,i){i=t.bn(i);const n=t.sumUpLamports(e.map((t=>t.compressedAccount))),r=E(e).sub(i);return t.validateSufficientBalance(r),r.eq(t.bn(0))&&n.eq(t.bn(0))?[]:(t.validateSameOwner(e.map((t=>t.compressedAccount))),B(e),[{owner:e[0].parsed.owner,amount:r,lamports:n,tlv:null}])}class N{constructor(){}static setProgramId(t){this.programId="string"==typeof t?new e.PublicKey(t):t}static deriveTokenPoolPda(t){const i=[s,t.toBuffer()],[n,r]=e.PublicKey.findProgramAddressSync(i,this.programId);return n}static get deriveCpiAuthorityPda(){const[t,i]=e.PublicKey.findProgramAddressSync([a],this.programId);return t}static async createMint(t){const{mint:n,authority:r,feePayer:o,rentExemptBalance:s,tokenProgramId:a,freezeAuthority:u,mintSize:m}=t,h=null!=a?a:i.TOKEN_PROGRAM_ID;return[e.SystemProgram.createAccount({fromPubkey:o,lamports:s,newAccountPubkey:n,programId:h,space:null!=m?m:i.MINT_SIZE}),i.createInitializeMint2Instruction(n,t.decimals,r,u,h),await this.createTokenPool({feePayer:o,mint:n,tokenProgramId:h})]}static async createTokenPool(t){const{mint:n,feePayer:r,tokenProgramId:o}=t,s=null!=o?o:i.TOKEN_PROGRAM_ID,a=this.deriveTokenPoolPda(n),m=_({mint:n,feePayer:r,tokenPoolPda:a,tokenProgram:s,cpiAuthorityPda:this.deriveCpiAuthorityPda,systemProgram:e.SystemProgram.programId});return new e.TransactionInstruction({programId:this.programId,keys:m,data:u})}static async mintTo(n){const r=t.defaultStaticAccountsStruct(),{mint:o,feePayer:s,authority:a,merkleTree:u,toPubkey:m,amount:h,tokenProgramId:l}=n,d=null!=l?l:i.TOKEN_PROGRAM_ID,c=this.deriveTokenPoolPda(o),p=t.toArray(h).map((e=>t.bn(e))),g=t.toArray(m);if(p.length!==g.length)throw new Error("Amount and toPubkey arrays must have the same length");const f=O({mint:o,feePayer:s,authority:a,cpiAuthorityPda:this.deriveCpiAuthorityPda,tokenProgram:d,tokenPoolPda:c,lightSystemProgram:t.LightSystemProgram.programId,registeredProgramPda:r.registeredProgramPda,noopProgram:r.noopProgram,accountCompressionAuthority:r.accountCompressionAuthority,accountCompressionProgram:r.accountCompressionProgram,merkleTree:null!=u?u:t.defaultTestStateTreeAccounts().merkleTree,selfProgram:this.programId,systemProgram:e.SystemProgram.programId,solPoolPda:null}),y=C({recipients:g,amounts:p,lamports:null});return new e.TransactionInstruction({programId:this.programId,keys:f,data:y})}static async approveAndMintTo(t){const{mint:e,feePayer:n,authorityTokenAccount:r,authority:o,merkleTree:s,toPubkey:a,tokenProgramId:u}=t,m=BigInt(t.amount.toString());return[i.createMintToInstruction(e,r,o,m,[],u),await this.compress({payer:n,owner:o,source:r,toAddress:a,mint:e,amount:t.amount,outputStateTree:s,tokenProgramId:u})]}static async transfer(i){const{payer:n,inputCompressedTokenAccounts:r,recentInputStateRootIndices:s,recentValidityProof:a,amount:u,outputStateTrees:m,toAddress:h}=i,l=L(r,h,u),{inputTokenDataWithContext:d,packedOutputTokenData:c,remainingAccountMetas:p}=o({inputCompressedTokenAccounts:r,outputStateTrees:m,rootIndices:s,tokenTransferOutputs:l}),{mint:g,currentOwner:f}=K(r),y=x({proof:a,mint:g,delegatedTransfer:null,inputTokenDataWithContext:d,outputCompressedAccounts:c,compressOrDecompressAmount:null,isCompress:0,cpiContext:null,lamportsChangeAccountMerkleTreeIndex:null}),{accountCompressionAuthority:M,noopProgram:v,registeredProgramPda:w,accountCompressionProgram:b}=t.defaultStaticAccountsStruct(),k=D({feePayer:n,authority:f,cpiAuthorityPda:this.deriveCpiAuthorityPda,lightSystemProgram:t.LightSystemProgram.programId,registeredProgramPda:w,noopProgram:v,accountCompressionAuthority:M,accountCompressionProgram:b,selfProgram:this.programId,tokenPoolPda:void 0,compressOrDecompressTokenAccount:void 0,tokenProgram:void 0,systemProgram:e.SystemProgram.programId});return k.push(...p),new e.TransactionInstruction({programId:this.programId,keys:k,data:y})}static async createTokenProgramLookupTable(n){const{authority:r,mints:o,recentSlot:s,payer:a,remainingAccounts:u}=n,[m,h]=e.AddressLookupTableProgram.createLookupTable({authority:r,payer:r,recentSlot:s});let l=[];return o&&(l=[...o,...o.map((t=>this.deriveTokenPoolPda(t)))]),{instructions:[m,e.AddressLookupTableProgram.extendLookupTable({payer:a,authority:r,lookupTable:h,addresses:[this.deriveCpiAuthorityPda,t.LightSystemProgram.programId,t.defaultStaticAccountsStruct().registeredProgramPda,t.defaultStaticAccountsStruct().noopProgram,t.defaultStaticAccountsStruct().accountCompressionAuthority,t.defaultStaticAccountsStruct().accountCompressionProgram,t.defaultTestStateTreeAccounts().merkleTree,t.defaultTestStateTreeAccounts().nullifierQueue,t.defaultTestStateTreeAccounts().addressTree,t.defaultTestStateTreeAccounts().addressQueue,this.programId,i.TOKEN_PROGRAM_ID,i.TOKEN_2022_PROGRAM_ID,r,...l,...null!=u?u:[]]})],address:h}}static async compress(n){const{payer:r,owner:s,source:a,toAddress:u,mint:m,outputStateTree:h,tokenProgramId:l}=n;if(Array.isArray(n.amount)!==Array.isArray(n.toAddress))throw new Error("Both amount and toAddress must be arrays or both must be single values");let d;if(Array.isArray(n.amount)&&Array.isArray(n.toAddress)){if(n.amount.length!==n.toAddress.length)throw new Error("Amount and toAddress arrays must have the same length");d=n.amount.map(((e,i)=>{const r=t.bn(e);return{owner:n.toAddress[i],amount:r,lamports:t.bn(0),tlv:null}}))}else d=[{owner:u,amount:t.bn(n.amount),lamports:t.bn(0),tlv:null}];const{inputTokenDataWithContext:c,packedOutputTokenData:p,remainingAccountMetas:g}=o({inputCompressedTokenAccounts:[],outputStateTrees:h,rootIndices:[],tokenTransferOutputs:d}),f=x({proof:null,mint:m,delegatedTransfer:null,inputTokenDataWithContext:c,outputCompressedAccounts:p,compressOrDecompressAmount:Array.isArray(n.amount)?n.amount.map((t=>new y(t))).reduce(((t,e)=>t.add(e)),new y(0)):new y(n.amount),isCompress:1,cpiContext:null,lamportsChangeAccountMerkleTreeIndex:null}),M=null!=l?l:i.TOKEN_PROGRAM_ID,v=D(Object.assign(Object.assign({},t.defaultStaticAccountsStruct()),{feePayer:r,authority:s,cpiAuthorityPda:this.deriveCpiAuthorityPda,lightSystemProgram:t.LightSystemProgram.programId,selfProgram:this.programId,systemProgram:e.SystemProgram.programId,tokenPoolPda:this.deriveTokenPoolPda(m),compressOrDecompressTokenAccount:a,tokenProgram:M}));return v.push(...g),new e.TransactionInstruction({programId:this.programId,keys:v,data:f})}static async decompress(n){const{payer:r,inputCompressedTokenAccounts:s,toAddress:a,outputStateTree:u,recentValidityProof:m,recentInputStateRootIndices:h,tokenProgramId:l}=n,d=t.bn(n.amount),c=R(s,d),{inputTokenDataWithContext:p,packedOutputTokenData:g,remainingAccountMetas:f}=o({inputCompressedTokenAccounts:s,outputStateTrees:u,rootIndices:h,tokenTransferOutputs:c}),{mint:y,currentOwner:M}=K(s),v=x({proof:m,mint:y,delegatedTransfer:null,inputTokenDataWithContext:p,outputCompressedAccounts:g,compressOrDecompressAmount:d,isCompress:0,cpiContext:null,lamportsChangeAccountMerkleTreeIndex:null}),w=null!=l?l:i.TOKEN_PROGRAM_ID,{accountCompressionAuthority:b,noopProgram:k,registeredProgramPda:P,accountCompressionProgram:S}=t.defaultStaticAccountsStruct(),A=D({feePayer:r,authority:M,cpiAuthorityPda:this.deriveCpiAuthorityPda,lightSystemProgram:t.LightSystemProgram.programId,registeredProgramPda:P,noopProgram:k,accountCompressionAuthority:b,accountCompressionProgram:S,selfProgram:this.programId,tokenPoolPda:this.deriveTokenPoolPda(y),compressOrDecompressTokenAccount:a,tokenProgram:w,systemProgram:e.SystemProgram.programId});return A.push(...f),new e.TransactionInstruction({programId:this.programId,keys:A,data:v})}static async mergeTokenAccounts(t){const{payer:e,owner:i,inputCompressedTokenAccounts:n,outputStateTree:r,recentValidityProof:o,recentInputStateRootIndices:s}=t;if(n.length>3)throw new Error("Cannot merge more than 3 token accounts at once");return[await this.transfer({payer:e,inputCompressedTokenAccounts:n,toAddress:i,amount:n.reduce(((t,e)=>t.add(e.parsed.amount)),new y(0)),outputStateTrees:r,recentInputStateRootIndices:s,recentValidityProof:o})]}static async compressSplTokenAccount(n){const{feePayer:r,authority:o,tokenAccount:s,mint:a,remainingAmount:u,outputStateTree:m,tokenProgramId:h}=n,l=null!=h?h:i.TOKEN_PROGRAM_ID,d=[{pubkey:m,isSigner:0,isWritable:1}],c=I({owner:o,remainingAmount:null!=u?u:null,cpiContext:null}),{accountCompressionAuthority:p,noopProgram:g,registeredProgramPda:f,accountCompressionProgram:y}=t.defaultStaticAccountsStruct(),M=D({feePayer:r,authority:o,cpiAuthorityPda:this.deriveCpiAuthorityPda,lightSystemProgram:t.LightSystemProgram.programId,registeredProgramPda:f,noopProgram:g,accountCompressionAuthority:p,accountCompressionProgram:y,selfProgram:this.programId,tokenPoolPda:this.deriveTokenPoolPda(a),compressOrDecompressTokenAccount:s,tokenProgram:l,systemProgram:e.SystemProgram.programId});return M.push(...d),new e.TransactionInstruction({programId:this.programId,keys:M,data:c})}static async get_mint_program_id(t,e){var i;return null===(i=await e.getAccountInfo(t))||void 0===i?void 0:i.owner}}function W(e,i){let n=t.bn(0),r=t.bn(0);const o=[];e.sort(((t,e)=>e.parsed.amount.cmp(t.parsed.amount)));for(const s of e){if(n.gte(t.bn(i)))break;n=n.add(s.parsed.amount),r=r.add(s.compressedAccount.lamports),o.push(s)}if(n.lt(t.bn(i)))throw new Error(`Not enough balance for transfer. Required: ${i.toString()}, available: ${n.toString()}`);return[o,n,r.lt(t.bn(0))?r:null]}N.programId=new e.PublicKey("cTokenmWW8bLPjZEBAUgYy3zKxQZW6VKi7bqNFEVv3m"),exports.COMPRESS_SPL_TOKEN_ACCOUNT_DISCRIMINATOR=l,exports.CPI_AUTHORITY_SEED=a,exports.CREATE_TOKEN_POOL_DISCRIMINATOR=u,exports.CompressedTokenInstructionDataTransferLayout=S,exports.CompressedTokenProgram=N,exports.CpiContextLayout=P,exports.DelegatedTransferLayout=k,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:"tokenPoolBump",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:"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:"nullifierQueuePubkeyIndex",type:"u8"},{name:"leafIndex",type:"u32"},{name:"queueIndex",type:{option:{defined:"QueueIndex"}}}]}},{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.MINT_TO_DISCRIMINATOR=m,exports.POOL_SEED=s,exports.SPL_TOKEN_MINT_RENT_EXEMPT_BALANCE=1461600,exports.TRANSFER_DISCRIMINATOR=h,exports.approveAndMintTo=async function(n,r,o,s,a,u,m,h,l){l=l||await N.get_mint_program_id(o,n);const d=await i.getOrCreateAssociatedTokenAccount(n,r,o,a.publicKey,void 0,void 0,h,l),c=await N.approveAndMintTo({feePayer:r.publicKey,mint:o,authority:a.publicKey,authorityTokenAccount:d.address,amount:u,toPubkey:s,merkleTree:m,tokenProgramId:l}),{blockhash:p}=await n.getLatestBlockhash(),g=t.dedupeSigner(r,[a]),f=t.buildAndSignTx([e.ComputeBudgetProgram.setComputeUnitLimit({units:1e6}),...c],r,p,g);return await t.sendAndConfirmTx(n,f,h)},exports.compress=async function(i,n,r,o,s,a,u,m,h,l){l=l||await N.get_mint_program_id(r,i);const d=await N.compress({payer:n.publicKey,owner:s.publicKey,source:a,toAddress:u,amount:o,mint:r,outputStateTree:m,tokenProgramId:l}),c=await i.getLatestBlockhash(),p=t.dedupeSigner(n,[s]),g=t.buildAndSignTx([e.ComputeBudgetProgram.setComputeUnitLimit({units:1e6}),d],n,c.blockhash,p);return await t.sendAndConfirmTx(i,g,h,c)},exports.compressSplTokenAccount=async function(i,n,r,o,s,a,u,m,h){h=h||await N.get_mint_program_id(r,i);const l=await N.compressSplTokenAccount({feePayer:n.publicKey,authority:o.publicKey,tokenAccount:s,mint:r,remainingAmount:u,outputStateTree:a,tokenProgramId:h}),d=await i.getLatestBlockhash(),c=t.dedupeSigner(n,[o]),p=t.buildAndSignTx([e.ComputeBudgetProgram.setComputeUnitLimit({units:1e6}),l],n,d.blockhash,c);return await t.sendAndConfirmTx(i,p,m,d)},exports.compressSplTokenAccountInstructionDataLayout=T,exports.createDecompressOutputState=R,exports.createMint=async function(n,r,o,s,a=e.Keypair.generate(),u,m=0){const h=await n.getMinimumBalanceForRentExemption(i.MINT_SIZE),l=m?i.TOKEN_2022_PROGRAM_ID:i.TOKEN_PROGRAM_ID,d=await N.createMint({feePayer:r.publicKey,mint:a.publicKey,decimals:s,authority:o,freezeAuthority:null,rentExemptBalance:h,tokenProgramId:l}),{blockhash:c}=await n.getLatestBlockhash(),p=t.dedupeSigner(r,[a]),g=t.buildAndSignTx(d,r,c,p),f=await t.sendAndConfirmTx(n,g,u);return{mint:a.publicKey,transactionSignature:f}},exports.createTokenPool=async function(e,i,n,r,o){o=o||await N.get_mint_program_id(n,e);const s=await N.createTokenPool({feePayer:i.publicKey,mint:n,tokenProgramId:o}),{blockhash:a}=await e.getLatestBlockhash(),u=t.buildAndSignTx([s],i,a);return await t.sendAndConfirmTx(e,u,r)},exports.createTokenPoolAccountsLayout=_,exports.createTokenProgramLookupTable=async function(e,i,n,r,o){const s=await e.getSlot("finalized"),{instructions:a,address:u}=await N.createTokenProgramLookupTable({payer:i.publicKey,authority:n.publicKey,mints:r,remainingAccounts:o,recentSlot:s}),m=t.dedupeSigner(i,[n]),h=await e.getLatestBlockhash(),l=t.buildAndSignTx([a[0]],i,h.blockhash,m),d=await t.sendAndConfirmTx(e,l,{commitment:"finalized"},h),c=await e.getLatestBlockhash(),p=t.buildAndSignTx([a[1]],i,c.blockhash,m);return{txIds:[d,await t.sendAndConfirmTx(e,p,{commitment:"finalized"},c)],address:u}},exports.createTransferOutputState=L,exports.decodeCompressSplTokenAccountInstructionData=function(t){const e=T.decode(t.slice(l.length));return{owner:e.owner,remainingAmount:e.remainingAmount,cpiContext:e.cpiContext}},exports.decodeMintToInstructionData=function(t){const e=A.decode(t.slice(m.length));return{recipients:e.recipients,amounts:e.amounts,lamports:e.lamports}},exports.decodeTransferInstructionData=function(t){return S.decode(t.slice(h.length+4))},exports.decompress=async function(i,n,r,o,s,a,u,m,h){h=h||await N.get_mint_program_id(r,i),o=t.bn(o);const l=await i.getCompressedTokenAccountsByOwner(s.publicKey,{mint:r}),[d]=W(l.items,o),c=await i.getValidityProof(d.map((e=>t.bn(e.compressedAccount.hash)))),p=await N.decompress({payer:n.publicKey,inputCompressedTokenAccounts:d,toAddress:a,amount:o,outputStateTree:u,recentInputStateRootIndices:c.rootIndices,recentValidityProof:c.compressedProof,tokenProgramId:h}),{blockhash:g}=await i.getLatestBlockhash(),f=t.dedupeSigner(n,[s]),y=t.buildAndSignTx([e.ComputeBudgetProgram.setComputeUnitLimit({units:1e6}),p],n,g,f);return await t.sendAndConfirmTx(i,y,m)},exports.encodeCompressSplTokenAccountInstructionData=I,exports.encodeMintToInstructionData=C,exports.encodeTransferInstructionData=x,exports.mergeTokenAccounts=async function(i,n,r,o,s,a){const u=await i.getCompressedTokenAccountsByOwner(o.publicKey,{mint:r});if(0===u.items.length)throw new Error(`No compressed token accounts found for mint ${r.toBase58()}`);if(u.items.length>=6)throw new Error(`Too many compressed token accounts used for mint ${r.toBase58()}`);const m=[e.ComputeBudgetProgram.setComputeUnitLimit({units:1e6})];for(let e=0;e<u.items.slice(0,6).length;e+=3){const a=u.items.slice(e,e+3),h=await i.getValidityProof(a.map((e=>t.bn(e.compressedAccount.hash)))),l=await N.mergeTokenAccounts({payer:n.publicKey,owner:o.publicKey,mint:r,inputCompressedTokenAccounts:a,outputStateTree:s,recentValidityProof:h.compressedProof,recentInputStateRootIndices:h.rootIndices});m.push(...l)}const{blockhash:h}=await i.getLatestBlockhash(),l=t.dedupeSigner(n,[o]),d=t.buildAndSignTx(m,n,h,l);return await t.sendAndConfirmTx(i,d,a)},exports.mintTo=async function(i,n,r,o,s,a,u,m,h){h=h||await N.get_mint_program_id(r,i);const l=t.dedupeSigner(n,[s]),d=await N.mintTo({feePayer:n.publicKey,mint:r,authority:s.publicKey,amount:a,toPubkey:o,merkleTree:u,tokenProgramId:h}),{blockhash:c}=await i.getLatestBlockhash(),p=t.buildAndSignTx([e.ComputeBudgetProgram.setComputeUnitLimit({units:1e6}),d],n,c,l);return await t.sendAndConfirmTx(i,p,m)},exports.mintToAccountsLayout=O,exports.mintToLayout=A,exports.packCompressedTokenAccounts=o,exports.parseTokenData=K,exports.selectMinCompressedTokenAccountsForTransfer=W,exports.sumUpTokenAmount=E,exports.transfer=async function(i,n,r,o,s,a,u,m){o=t.bn(o);const h=await i.getCompressedTokenAccountsByOwner(s.publicKey,{mint:r}),[l]=W(h.items,o),d=await i.getValidityProof(l.map((e=>t.bn(e.compressedAccount.hash)))),c=await N.transfer({payer:n.publicKey,inputCompressedTokenAccounts:l,toAddress:a,amount:o,recentInputStateRootIndices:d.rootIndices,recentValidityProof:d.compressedProof,outputStateTrees:u}),{blockhash:p}=await i.getLatestBlockhash(),g=t.dedupeSigner(n,[s]),f=t.buildAndSignTx([e.ComputeBudgetProgram.setComputeUnitLimit({units:1e6}),c],n,p,g);return await t.sendAndConfirmTx(i,f,m)},exports.transferAccountsLayout=D,exports.validateSameTokenOwner=B;
|
|
1
|
+
"use strict";var t=require("@lightprotocol/stateless.js"),e=require("@solana/web3.js"),i=require("@solana/spl-token"),n=require("@coral-xyz/borsh"),r=require("buffer");function o(e){const{inputCompressedTokenAccounts:i,outputStateTrees:n,remainingAccounts:r=[],rootIndices:o,tokenTransferOutputs:s}=e,a=r.slice();let u=null;i.length>0&&i[0].parsed.delegate&&(u=t.getIndexOrAdd(a,i[0].parsed.delegate));const m=[];i.forEach(((e,i)=>{const n=t.getIndexOrAdd(a,e.compressedAccount.merkleTree),r=t.getIndexOrAdd(a,e.compressedAccount.nullifierQueue);m.push({amount:e.parsed.amount,delegateIndex:u,merkleContext:{merkleTreePubkeyIndex:n,nullifierQueuePubkeyIndex:r,leafIndex:e.compressedAccount.leafIndex,queueIndex:null},rootIndex:o[i],lamports:e.compressedAccount.lamports.eq(t.bn(0))?null:e.compressedAccount.lamports,tlv:null})}));const h=t.padOutputStateMerkleTrees(n,s.length,i.map((t=>t.compressedAccount))),l=[];h.forEach(((e,i)=>{var n;const r=t.getIndexOrAdd(a,e);l.push({owner:s[i].owner,amount:s[i].amount,lamports:(null===(n=s[i].lamports)||void 0===n?void 0:n.eq(t.bn(0)))?null:s[i].lamports,merkleTreeIndex:r,tlv:null})}));const d=a.map((t=>({pubkey:t,isWritable:1,isSigner:0})));return{inputTokenDataWithContext:m,remainingAccountMetas:d,packedOutputTokenData:l}}const s=Buffer.from("pool"),a=Buffer.from("cpi_authority"),u=Buffer.from([23,169,27,122,147,169,209,152]),m=Buffer.from([241,34,48,186,37,179,123,192]),h=Buffer.from([163,52,200,231,140,3,69,186]),l=Buffer.from([112,230,105,101,145,202,157,97]);var d="undefined"!=typeof globalThis?globalThis:"undefined"!=typeof window?window:"undefined"!=typeof global?global:"undefined"!=typeof self?self:{};function c(t){return t&&t.__esModule&&Object.prototype.hasOwnProperty.call(t,"default")?t.default:t}function p(t){if(t.__esModule)return t;var e=t.default;if("function"==typeof e){var i=function t(){return this instanceof t?Reflect.construct(e,arguments,this.constructor):e.apply(this,arguments)};i.prototype=e.prototype}else i={};return Object.defineProperty(i,"__esModule",{value:1}),Object.keys(t).forEach((function(e){var n=Object.getOwnPropertyDescriptor(t,e);Object.defineProperty(i,e,n.get?n:{enumerable:1,get:function(){return t[e]}})})),i}var g={exports:{}},f=p(Object.freeze({__proto__:null,default:{}}));!function(t,e){function i(t,e){if(!t)throw new Error(e||"Assertion failed")}function n(t,e){t.super_=e;var i=function(){};i.prototype=e.prototype,t.prototype=new i,t.prototype.constructor=t}function r(t,e,i){if(r.isBN(t))return t;this.negative=0,this.words=null,this.length=0,this.red=null,null!==t&&("le"!==e&&"be"!==e||(i=e,e=10),this._init(t||0,e||10,i||"be"))}var o;"object"==typeof g?g.exports=r:e.BN=r,r.BN=r,r.wordSize=26;try{o="undefined"!=typeof window&&void 0!==window.Buffer?window.Buffer:f.Buffer}catch(t){}function s(t,e){var n=t.charCodeAt(e);return n>=48&&n<=57?n-48:n>=65&&n<=70?n-55:n>=97&&n<=102?n-87:void i(0,"Invalid character in "+t)}function a(t,e,i){var n=s(t,i);return i-1>=e&&(n|=s(t,i-1)<<4),n}function u(t,e,n,r){for(var o=0,s=0,a=Math.min(t.length,n),u=e;u<a;u++){var m=t.charCodeAt(u)-48;o*=r,s=m>=49?m-49+10:m>=17?m-17+10:m,i(m>=0&&s<r,"Invalid character"),o+=s}return o}function m(t,e){t.words=e.words,t.length=e.length,t.negative=e.negative,t.red=e.red}if(r.isBN=function(t){return t instanceof r?1:null!==t&&"object"==typeof t&&t.constructor.wordSize===r.wordSize&&Array.isArray(t.words)},r.max=function(t,e){return t.cmp(e)>0?t:e},r.min=function(t,e){return t.cmp(e)<0?t:e},r.prototype._init=function(t,e,n){if("number"==typeof t)return this._initNumber(t,e,n);if("object"==typeof t)return this._initArray(t,e,n);"hex"===e&&(e=16),i(e===(0|e)&&e>=2&&e<=36);var r=0;"-"===(t=t.toString().replace(/\s+/g,""))[0]&&(r++,this.negative=1),r<t.length&&(16===e?this._parseHex(t,r,n):(this._parseBase(t,e,r),"le"===n&&this._initArray(this.toArray(),e,n)))},r.prototype._initNumber=function(t,e,n){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):(i(t<9007199254740992),this.words=[67108863&t,t/67108864&67108863,1],this.length=3),"le"===n&&this._initArray(this.toArray(),e,n)},r.prototype._initArray=function(t,e,n){if(i("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 r=0;r<this.length;r++)this.words[r]=0;var o,s,a=0;if("be"===n)for(r=t.length-1,o=0;r>=0;r-=3)s=t[r]|t[r-1]<<8|t[r-2]<<16,this.words[o]|=s<<a&67108863,this.words[o+1]=s>>>26-a&67108863,(a+=24)>=26&&(a-=26,o++);else if("le"===n)for(r=0,o=0;r<t.length;r+=3)s=t[r]|t[r+1]<<8|t[r+2]<<16,this.words[o]|=s<<a&67108863,this.words[o+1]=s>>>26-a&67108863,(a+=24)>=26&&(a-=26,o++);return this._strip()},r.prototype._parseHex=function(t,e,i){this.length=Math.ceil((t.length-e)/6),this.words=new Array(this.length);for(var n=0;n<this.length;n++)this.words[n]=0;var r,o=0,s=0;if("be"===i)for(n=t.length-1;n>=e;n-=2)r=a(t,e,n)<<o,this.words[s]|=67108863&r,o>=18?(o-=18,s+=1,this.words[s]|=r>>>26):o+=8;else for(n=(t.length-e)%2==0?e+1:e;n<t.length;n+=2)r=a(t,e,n)<<o,this.words[s]|=67108863&r,o>=18?(o-=18,s+=1,this.words[s]|=r>>>26):o+=8;this._strip()},r.prototype._parseBase=function(t,e,i){this.words=[0],this.length=1;for(var n=0,r=1;r<=67108863;r*=e)n++;n--,r=r/e|0;for(var o=t.length-i,s=o%n,a=Math.min(o,o-s)+i,m=0,h=i;h<a;h+=n)m=u(t,h,h+n,e),this.imuln(r),this.words[0]+m<67108864?this.words[0]+=m:this._iaddn(m);if(0!==s){var l=1;for(m=u(t,h,t.length,e),h=0;h<s;h++)l*=e;this.imuln(l),this.words[0]+m<67108864?this.words[0]+=m:this._iaddn(m)}this._strip()},r.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},r.prototype._move=function(t){m(t,this)},r.prototype.clone=function(){var t=new r(null);return this.copy(t),t},r.prototype._expand=function(t){for(;this.length<t;)this.words[this.length++]=0;return this},r.prototype._strip=function(){for(;this.length>1&&0===this.words[this.length-1];)this.length--;return this._normSign()},r.prototype._normSign=function(){return 1===this.length&&0===this.words[0]&&(this.negative=0),this},"undefined"!=typeof Symbol&&"function"==typeof Symbol.for)try{r.prototype[Symbol.for("nodejs.util.inspect.custom")]=h}catch(t){r.prototype.inspect=h}else r.prototype.inspect=h;function h(){return(this.red?"<BN-R: ":"<BN: ")+this.toString(16)+">"}var l=["","0","00","000","0000","00000","000000","0000000","00000000","000000000","0000000000","00000000000","000000000000","0000000000000","00000000000000","000000000000000","0000000000000000","00000000000000000","000000000000000000","0000000000000000000","00000000000000000000","000000000000000000000","0000000000000000000000","00000000000000000000000","000000000000000000000000","0000000000000000000000000"],d=[0,0,25,16,12,11,10,9,8,8,7,7,7,7,6,6,6,6,6,6,6,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5],c=[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 p(t,e,i){i.negative=e.negative^t.negative;var n=t.length+e.length|0;i.length=n,n=n-1|0;var r=0|t.words[0],o=0|e.words[0],s=r*o,a=67108863&s,u=s/67108864|0;i.words[0]=a;for(var m=1;m<n;m++){for(var h=u>>>26,l=67108863&u,d=Math.min(m,e.length-1),c=Math.max(0,m-t.length+1);c<=d;c++){var p=m-c|0;h+=(s=(r=0|t.words[p])*(o=0|e.words[c])+l)/67108864|0,l=67108863&s}i.words[m]=0|l,u=0|h}return 0!==u?i.words[m]=0|u:i.length--,i._strip()}r.prototype.toString=function(t,e){var n;if(e=0|e||1,16===(t=t||10)||"hex"===t){n="";for(var r=0,o=0,s=0;s<this.length;s++){var a=this.words[s],u=(16777215&(a<<r|o)).toString(16);o=a>>>24-r&16777215,(r+=2)>=26&&(r-=26,s--),n=0!==o||s!==this.length-1?l[6-u.length]+u+n:u+n}for(0!==o&&(n=o.toString(16)+n);n.length%e!=0;)n="0"+n;return 0!==this.negative&&(n="-"+n),n}if(t===(0|t)&&t>=2&&t<=36){var m=d[t],h=c[t];n="";var p=this.clone();for(p.negative=0;!p.isZero();){var g=p.modrn(h).toString(t);n=(p=p.idivn(h)).isZero()?g+n:l[m-g.length]+g+n}for(this.isZero()&&(n="0"+n);n.length%e!=0;)n="0"+n;return 0!==this.negative&&(n="-"+n),n}i(0,"Base should be between 2 and 36")},r.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&&i(0,"Number can only safely store up to 53 bits"),0!==this.negative?-t:t},r.prototype.toJSON=function(){return this.toString(16,2)},o&&(r.prototype.toBuffer=function(t,e){return this.toArrayLike(o,t,e)}),r.prototype.toArray=function(t,e){return this.toArrayLike(Array,t,e)},r.prototype.toArrayLike=function(t,e,n){this._strip();var r=this.byteLength(),o=n||Math.max(1,r);i(r<=o,"byte array longer than desired length"),i(o>0,"Requested array length <= 0");var s=function(t,e){return t.allocUnsafe?t.allocUnsafe(e):new t(e)}(t,o);return this["_toArrayLike"+("le"===e?"LE":"BE")](s,r),s},r.prototype._toArrayLikeLE=function(t){for(var e=0,i=0,n=0,r=0;n<this.length;n++){var o=this.words[n]<<r|i;t[e++]=255&o,e<t.length&&(t[e++]=o>>8&255),e<t.length&&(t[e++]=o>>16&255),6===r?(e<t.length&&(t[e++]=o>>24&255),i=0,r=0):(i=o>>>24,r+=2)}if(e<t.length)for(t[e++]=i;e<t.length;)t[e++]=0},r.prototype._toArrayLikeBE=function(t){for(var e=t.length-1,i=0,n=0,r=0;n<this.length;n++){var o=this.words[n]<<r|i;t[e--]=255&o,e>=0&&(t[e--]=o>>8&255),e>=0&&(t[e--]=o>>16&255),6===r?(e>=0&&(t[e--]=o>>24&255),i=0,r=0):(i=o>>>24,r+=2)}if(e>=0)for(t[e--]=i;e>=0;)t[e--]=0},Math.clz32?r.prototype._countBits=function(t){return 32-Math.clz32(t)}:r.prototype._countBits=function(t){var e=t,i=0;return e>=4096&&(i+=13,e>>>=13),e>=64&&(i+=7,e>>>=7),e>=8&&(i+=4,e>>>=4),e>=2&&(i+=2,e>>>=2),i+e},r.prototype._zeroBits=function(t){if(0===t)return 26;var e=t,i=0;return 0==(8191&e)&&(i+=13,e>>>=13),0==(127&e)&&(i+=7,e>>>=7),0==(15&e)&&(i+=4,e>>>=4),0==(3&e)&&(i+=2,e>>>=2),0==(1&e)&&i++,i},r.prototype.bitLength=function(){var t=this.words[this.length-1],e=this._countBits(t);return 26*(this.length-1)+e},r.prototype.zeroBits=function(){if(this.isZero())return 0;for(var t=0,e=0;e<this.length;e++){var i=this._zeroBits(this.words[e]);if(t+=i,26!==i)break}return t},r.prototype.byteLength=function(){return Math.ceil(this.bitLength()/8)},r.prototype.toTwos=function(t){return 0!==this.negative?this.abs().inotn(t).iaddn(1):this.clone()},r.prototype.fromTwos=function(t){return this.testn(t-1)?this.notn(t).iaddn(1).ineg():this.clone()},r.prototype.isNeg=function(){return 0!==this.negative},r.prototype.neg=function(){return this.clone().ineg()},r.prototype.ineg=function(){return this.isZero()||(this.negative^=1),this},r.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()},r.prototype.ior=function(t){return i(0==(this.negative|t.negative)),this.iuor(t)},r.prototype.or=function(t){return this.length>t.length?this.clone().ior(t):t.clone().ior(this)},r.prototype.uor=function(t){return this.length>t.length?this.clone().iuor(t):t.clone().iuor(this)},r.prototype.iuand=function(t){var e;e=this.length>t.length?t:this;for(var i=0;i<e.length;i++)this.words[i]=this.words[i]&t.words[i];return this.length=e.length,this._strip()},r.prototype.iand=function(t){return i(0==(this.negative|t.negative)),this.iuand(t)},r.prototype.and=function(t){return this.length>t.length?this.clone().iand(t):t.clone().iand(this)},r.prototype.uand=function(t){return this.length>t.length?this.clone().iuand(t):t.clone().iuand(this)},r.prototype.iuxor=function(t){var e,i;this.length>t.length?(e=this,i=t):(e=t,i=this);for(var n=0;n<i.length;n++)this.words[n]=e.words[n]^i.words[n];if(this!==e)for(;n<e.length;n++)this.words[n]=e.words[n];return this.length=e.length,this._strip()},r.prototype.ixor=function(t){return i(0==(this.negative|t.negative)),this.iuxor(t)},r.prototype.xor=function(t){return this.length>t.length?this.clone().ixor(t):t.clone().ixor(this)},r.prototype.uxor=function(t){return this.length>t.length?this.clone().iuxor(t):t.clone().iuxor(this)},r.prototype.inotn=function(t){i("number"==typeof t&&t>=0);var e=0|Math.ceil(t/26),n=t%26;this._expand(e),n>0&&e--;for(var r=0;r<e;r++)this.words[r]=67108863&~this.words[r];return n>0&&(this.words[r]=~this.words[r]&67108863>>26-n),this._strip()},r.prototype.notn=function(t){return this.clone().inotn(t)},r.prototype.setn=function(t,e){i("number"==typeof t&&t>=0);var n=t/26|0,r=t%26;return this._expand(n+1),this.words[n]=e?this.words[n]|1<<r:this.words[n]&~(1<<r),this._strip()},r.prototype.iadd=function(t){var e,i,n;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?(i=this,n=t):(i=t,n=this);for(var r=0,o=0;o<n.length;o++)e=(0|i.words[o])+(0|n.words[o])+r,this.words[o]=67108863&e,r=e>>>26;for(;0!==r&&o<i.length;o++)e=(0|i.words[o])+r,this.words[o]=67108863&e,r=e>>>26;if(this.length=i.length,0!==r)this.words[this.length]=r,this.length++;else if(i!==this)for(;o<i.length;o++)this.words[o]=i.words[o];return this},r.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)},r.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 i,n,r=this.cmp(t);if(0===r)return this.negative=0,this.length=1,this.words[0]=0,this;r>0?(i=this,n=t):(i=t,n=this);for(var o=0,s=0;s<n.length;s++)o=(e=(0|i.words[s])-(0|n.words[s])+o)>>26,this.words[s]=67108863&e;for(;0!==o&&s<i.length;s++)o=(e=(0|i.words[s])+o)>>26,this.words[s]=67108863&e;if(0===o&&s<i.length&&i!==this)for(;s<i.length;s++)this.words[s]=i.words[s];return this.length=Math.max(this.length,s),i!==this&&(this.negative=1),this._strip()},r.prototype.sub=function(t){return this.clone().isub(t)};var y=function(t,e,i){var n,r,o,s=t.words,a=e.words,u=i.words,m=0,h=0|s[0],l=8191&h,d=h>>>13,c=0|s[1],p=8191&c,g=c>>>13,f=0|s[2],y=8191&f,M=f>>>13,v=0|s[3],w=8191&v,k=v>>>13,b=0|s[4],P=8191&b,S=b>>>13,A=0|s[5],T=8191&A,C=A>>>13,I=0|s[6],x=8191&I,_=I>>>13,O=0|s[7],D=8191&O,E=O>>>13,B=0|s[8],K=8191&B,L=B>>>13,R=0|s[9],N=8191&R,W=R>>>13,q=0|a[0],F=8191&q,U=q>>>13,z=0|a[1],Z=8191&z,H=z>>>13,j=0|a[2],Q=8191&j,V=j>>>13,G=0|a[3],$=8191&G,X=G>>>13,Y=0|a[4],J=8191&Y,tt=Y>>>13,et=0|a[5],it=8191&et,nt=et>>>13,rt=0|a[6],ot=8191&rt,st=rt>>>13,at=0|a[7],ut=8191&at,mt=at>>>13,ht=0|a[8],lt=8191&ht,dt=ht>>>13,ct=0|a[9],pt=8191&ct,gt=ct>>>13;i.negative=t.negative^e.negative,i.length=19;var ft=(m+(n=Math.imul(l,F))|0)+((8191&(r=(r=Math.imul(l,U))+Math.imul(d,F)|0))<<13)|0;m=((o=Math.imul(d,U))+(r>>>13)|0)+(ft>>>26)|0,ft&=67108863,n=Math.imul(p,F),r=(r=Math.imul(p,U))+Math.imul(g,F)|0,o=Math.imul(g,U);var yt=(m+(n=n+Math.imul(l,Z)|0)|0)+((8191&(r=(r=r+Math.imul(l,H)|0)+Math.imul(d,Z)|0))<<13)|0;m=((o=o+Math.imul(d,H)|0)+(r>>>13)|0)+(yt>>>26)|0,yt&=67108863,n=Math.imul(y,F),r=(r=Math.imul(y,U))+Math.imul(M,F)|0,o=Math.imul(M,U),n=n+Math.imul(p,Z)|0,r=(r=r+Math.imul(p,H)|0)+Math.imul(g,Z)|0,o=o+Math.imul(g,H)|0;var Mt=(m+(n=n+Math.imul(l,Q)|0)|0)+((8191&(r=(r=r+Math.imul(l,V)|0)+Math.imul(d,Q)|0))<<13)|0;m=((o=o+Math.imul(d,V)|0)+(r>>>13)|0)+(Mt>>>26)|0,Mt&=67108863,n=Math.imul(w,F),r=(r=Math.imul(w,U))+Math.imul(k,F)|0,o=Math.imul(k,U),n=n+Math.imul(y,Z)|0,r=(r=r+Math.imul(y,H)|0)+Math.imul(M,Z)|0,o=o+Math.imul(M,H)|0,n=n+Math.imul(p,Q)|0,r=(r=r+Math.imul(p,V)|0)+Math.imul(g,Q)|0,o=o+Math.imul(g,V)|0;var vt=(m+(n=n+Math.imul(l,$)|0)|0)+((8191&(r=(r=r+Math.imul(l,X)|0)+Math.imul(d,$)|0))<<13)|0;m=((o=o+Math.imul(d,X)|0)+(r>>>13)|0)+(vt>>>26)|0,vt&=67108863,n=Math.imul(P,F),r=(r=Math.imul(P,U))+Math.imul(S,F)|0,o=Math.imul(S,U),n=n+Math.imul(w,Z)|0,r=(r=r+Math.imul(w,H)|0)+Math.imul(k,Z)|0,o=o+Math.imul(k,H)|0,n=n+Math.imul(y,Q)|0,r=(r=r+Math.imul(y,V)|0)+Math.imul(M,Q)|0,o=o+Math.imul(M,V)|0,n=n+Math.imul(p,$)|0,r=(r=r+Math.imul(p,X)|0)+Math.imul(g,$)|0,o=o+Math.imul(g,X)|0;var wt=(m+(n=n+Math.imul(l,J)|0)|0)+((8191&(r=(r=r+Math.imul(l,tt)|0)+Math.imul(d,J)|0))<<13)|0;m=((o=o+Math.imul(d,tt)|0)+(r>>>13)|0)+(wt>>>26)|0,wt&=67108863,n=Math.imul(T,F),r=(r=Math.imul(T,U))+Math.imul(C,F)|0,o=Math.imul(C,U),n=n+Math.imul(P,Z)|0,r=(r=r+Math.imul(P,H)|0)+Math.imul(S,Z)|0,o=o+Math.imul(S,H)|0,n=n+Math.imul(w,Q)|0,r=(r=r+Math.imul(w,V)|0)+Math.imul(k,Q)|0,o=o+Math.imul(k,V)|0,n=n+Math.imul(y,$)|0,r=(r=r+Math.imul(y,X)|0)+Math.imul(M,$)|0,o=o+Math.imul(M,X)|0,n=n+Math.imul(p,J)|0,r=(r=r+Math.imul(p,tt)|0)+Math.imul(g,J)|0,o=o+Math.imul(g,tt)|0;var kt=(m+(n=n+Math.imul(l,it)|0)|0)+((8191&(r=(r=r+Math.imul(l,nt)|0)+Math.imul(d,it)|0))<<13)|0;m=((o=o+Math.imul(d,nt)|0)+(r>>>13)|0)+(kt>>>26)|0,kt&=67108863,n=Math.imul(x,F),r=(r=Math.imul(x,U))+Math.imul(_,F)|0,o=Math.imul(_,U),n=n+Math.imul(T,Z)|0,r=(r=r+Math.imul(T,H)|0)+Math.imul(C,Z)|0,o=o+Math.imul(C,H)|0,n=n+Math.imul(P,Q)|0,r=(r=r+Math.imul(P,V)|0)+Math.imul(S,Q)|0,o=o+Math.imul(S,V)|0,n=n+Math.imul(w,$)|0,r=(r=r+Math.imul(w,X)|0)+Math.imul(k,$)|0,o=o+Math.imul(k,X)|0,n=n+Math.imul(y,J)|0,r=(r=r+Math.imul(y,tt)|0)+Math.imul(M,J)|0,o=o+Math.imul(M,tt)|0,n=n+Math.imul(p,it)|0,r=(r=r+Math.imul(p,nt)|0)+Math.imul(g,it)|0,o=o+Math.imul(g,nt)|0;var bt=(m+(n=n+Math.imul(l,ot)|0)|0)+((8191&(r=(r=r+Math.imul(l,st)|0)+Math.imul(d,ot)|0))<<13)|0;m=((o=o+Math.imul(d,st)|0)+(r>>>13)|0)+(bt>>>26)|0,bt&=67108863,n=Math.imul(D,F),r=(r=Math.imul(D,U))+Math.imul(E,F)|0,o=Math.imul(E,U),n=n+Math.imul(x,Z)|0,r=(r=r+Math.imul(x,H)|0)+Math.imul(_,Z)|0,o=o+Math.imul(_,H)|0,n=n+Math.imul(T,Q)|0,r=(r=r+Math.imul(T,V)|0)+Math.imul(C,Q)|0,o=o+Math.imul(C,V)|0,n=n+Math.imul(P,$)|0,r=(r=r+Math.imul(P,X)|0)+Math.imul(S,$)|0,o=o+Math.imul(S,X)|0,n=n+Math.imul(w,J)|0,r=(r=r+Math.imul(w,tt)|0)+Math.imul(k,J)|0,o=o+Math.imul(k,tt)|0,n=n+Math.imul(y,it)|0,r=(r=r+Math.imul(y,nt)|0)+Math.imul(M,it)|0,o=o+Math.imul(M,nt)|0,n=n+Math.imul(p,ot)|0,r=(r=r+Math.imul(p,st)|0)+Math.imul(g,ot)|0,o=o+Math.imul(g,st)|0;var Pt=(m+(n=n+Math.imul(l,ut)|0)|0)+((8191&(r=(r=r+Math.imul(l,mt)|0)+Math.imul(d,ut)|0))<<13)|0;m=((o=o+Math.imul(d,mt)|0)+(r>>>13)|0)+(Pt>>>26)|0,Pt&=67108863,n=Math.imul(K,F),r=(r=Math.imul(K,U))+Math.imul(L,F)|0,o=Math.imul(L,U),n=n+Math.imul(D,Z)|0,r=(r=r+Math.imul(D,H)|0)+Math.imul(E,Z)|0,o=o+Math.imul(E,H)|0,n=n+Math.imul(x,Q)|0,r=(r=r+Math.imul(x,V)|0)+Math.imul(_,Q)|0,o=o+Math.imul(_,V)|0,n=n+Math.imul(T,$)|0,r=(r=r+Math.imul(T,X)|0)+Math.imul(C,$)|0,o=o+Math.imul(C,X)|0,n=n+Math.imul(P,J)|0,r=(r=r+Math.imul(P,tt)|0)+Math.imul(S,J)|0,o=o+Math.imul(S,tt)|0,n=n+Math.imul(w,it)|0,r=(r=r+Math.imul(w,nt)|0)+Math.imul(k,it)|0,o=o+Math.imul(k,nt)|0,n=n+Math.imul(y,ot)|0,r=(r=r+Math.imul(y,st)|0)+Math.imul(M,ot)|0,o=o+Math.imul(M,st)|0,n=n+Math.imul(p,ut)|0,r=(r=r+Math.imul(p,mt)|0)+Math.imul(g,ut)|0,o=o+Math.imul(g,mt)|0;var St=(m+(n=n+Math.imul(l,lt)|0)|0)+((8191&(r=(r=r+Math.imul(l,dt)|0)+Math.imul(d,lt)|0))<<13)|0;m=((o=o+Math.imul(d,dt)|0)+(r>>>13)|0)+(St>>>26)|0,St&=67108863,n=Math.imul(N,F),r=(r=Math.imul(N,U))+Math.imul(W,F)|0,o=Math.imul(W,U),n=n+Math.imul(K,Z)|0,r=(r=r+Math.imul(K,H)|0)+Math.imul(L,Z)|0,o=o+Math.imul(L,H)|0,n=n+Math.imul(D,Q)|0,r=(r=r+Math.imul(D,V)|0)+Math.imul(E,Q)|0,o=o+Math.imul(E,V)|0,n=n+Math.imul(x,$)|0,r=(r=r+Math.imul(x,X)|0)+Math.imul(_,$)|0,o=o+Math.imul(_,X)|0,n=n+Math.imul(T,J)|0,r=(r=r+Math.imul(T,tt)|0)+Math.imul(C,J)|0,o=o+Math.imul(C,tt)|0,n=n+Math.imul(P,it)|0,r=(r=r+Math.imul(P,nt)|0)+Math.imul(S,it)|0,o=o+Math.imul(S,nt)|0,n=n+Math.imul(w,ot)|0,r=(r=r+Math.imul(w,st)|0)+Math.imul(k,ot)|0,o=o+Math.imul(k,st)|0,n=n+Math.imul(y,ut)|0,r=(r=r+Math.imul(y,mt)|0)+Math.imul(M,ut)|0,o=o+Math.imul(M,mt)|0,n=n+Math.imul(p,lt)|0,r=(r=r+Math.imul(p,dt)|0)+Math.imul(g,lt)|0,o=o+Math.imul(g,dt)|0;var At=(m+(n=n+Math.imul(l,pt)|0)|0)+((8191&(r=(r=r+Math.imul(l,gt)|0)+Math.imul(d,pt)|0))<<13)|0;m=((o=o+Math.imul(d,gt)|0)+(r>>>13)|0)+(At>>>26)|0,At&=67108863,n=Math.imul(N,Z),r=(r=Math.imul(N,H))+Math.imul(W,Z)|0,o=Math.imul(W,H),n=n+Math.imul(K,Q)|0,r=(r=r+Math.imul(K,V)|0)+Math.imul(L,Q)|0,o=o+Math.imul(L,V)|0,n=n+Math.imul(D,$)|0,r=(r=r+Math.imul(D,X)|0)+Math.imul(E,$)|0,o=o+Math.imul(E,X)|0,n=n+Math.imul(x,J)|0,r=(r=r+Math.imul(x,tt)|0)+Math.imul(_,J)|0,o=o+Math.imul(_,tt)|0,n=n+Math.imul(T,it)|0,r=(r=r+Math.imul(T,nt)|0)+Math.imul(C,it)|0,o=o+Math.imul(C,nt)|0,n=n+Math.imul(P,ot)|0,r=(r=r+Math.imul(P,st)|0)+Math.imul(S,ot)|0,o=o+Math.imul(S,st)|0,n=n+Math.imul(w,ut)|0,r=(r=r+Math.imul(w,mt)|0)+Math.imul(k,ut)|0,o=o+Math.imul(k,mt)|0,n=n+Math.imul(y,lt)|0,r=(r=r+Math.imul(y,dt)|0)+Math.imul(M,lt)|0,o=o+Math.imul(M,dt)|0;var Tt=(m+(n=n+Math.imul(p,pt)|0)|0)+((8191&(r=(r=r+Math.imul(p,gt)|0)+Math.imul(g,pt)|0))<<13)|0;m=((o=o+Math.imul(g,gt)|0)+(r>>>13)|0)+(Tt>>>26)|0,Tt&=67108863,n=Math.imul(N,Q),r=(r=Math.imul(N,V))+Math.imul(W,Q)|0,o=Math.imul(W,V),n=n+Math.imul(K,$)|0,r=(r=r+Math.imul(K,X)|0)+Math.imul(L,$)|0,o=o+Math.imul(L,X)|0,n=n+Math.imul(D,J)|0,r=(r=r+Math.imul(D,tt)|0)+Math.imul(E,J)|0,o=o+Math.imul(E,tt)|0,n=n+Math.imul(x,it)|0,r=(r=r+Math.imul(x,nt)|0)+Math.imul(_,it)|0,o=o+Math.imul(_,nt)|0,n=n+Math.imul(T,ot)|0,r=(r=r+Math.imul(T,st)|0)+Math.imul(C,ot)|0,o=o+Math.imul(C,st)|0,n=n+Math.imul(P,ut)|0,r=(r=r+Math.imul(P,mt)|0)+Math.imul(S,ut)|0,o=o+Math.imul(S,mt)|0,n=n+Math.imul(w,lt)|0,r=(r=r+Math.imul(w,dt)|0)+Math.imul(k,lt)|0,o=o+Math.imul(k,dt)|0;var Ct=(m+(n=n+Math.imul(y,pt)|0)|0)+((8191&(r=(r=r+Math.imul(y,gt)|0)+Math.imul(M,pt)|0))<<13)|0;m=((o=o+Math.imul(M,gt)|0)+(r>>>13)|0)+(Ct>>>26)|0,Ct&=67108863,n=Math.imul(N,$),r=(r=Math.imul(N,X))+Math.imul(W,$)|0,o=Math.imul(W,X),n=n+Math.imul(K,J)|0,r=(r=r+Math.imul(K,tt)|0)+Math.imul(L,J)|0,o=o+Math.imul(L,tt)|0,n=n+Math.imul(D,it)|0,r=(r=r+Math.imul(D,nt)|0)+Math.imul(E,it)|0,o=o+Math.imul(E,nt)|0,n=n+Math.imul(x,ot)|0,r=(r=r+Math.imul(x,st)|0)+Math.imul(_,ot)|0,o=o+Math.imul(_,st)|0,n=n+Math.imul(T,ut)|0,r=(r=r+Math.imul(T,mt)|0)+Math.imul(C,ut)|0,o=o+Math.imul(C,mt)|0,n=n+Math.imul(P,lt)|0,r=(r=r+Math.imul(P,dt)|0)+Math.imul(S,lt)|0,o=o+Math.imul(S,dt)|0;var It=(m+(n=n+Math.imul(w,pt)|0)|0)+((8191&(r=(r=r+Math.imul(w,gt)|0)+Math.imul(k,pt)|0))<<13)|0;m=((o=o+Math.imul(k,gt)|0)+(r>>>13)|0)+(It>>>26)|0,It&=67108863,n=Math.imul(N,J),r=(r=Math.imul(N,tt))+Math.imul(W,J)|0,o=Math.imul(W,tt),n=n+Math.imul(K,it)|0,r=(r=r+Math.imul(K,nt)|0)+Math.imul(L,it)|0,o=o+Math.imul(L,nt)|0,n=n+Math.imul(D,ot)|0,r=(r=r+Math.imul(D,st)|0)+Math.imul(E,ot)|0,o=o+Math.imul(E,st)|0,n=n+Math.imul(x,ut)|0,r=(r=r+Math.imul(x,mt)|0)+Math.imul(_,ut)|0,o=o+Math.imul(_,mt)|0,n=n+Math.imul(T,lt)|0,r=(r=r+Math.imul(T,dt)|0)+Math.imul(C,lt)|0,o=o+Math.imul(C,dt)|0;var xt=(m+(n=n+Math.imul(P,pt)|0)|0)+((8191&(r=(r=r+Math.imul(P,gt)|0)+Math.imul(S,pt)|0))<<13)|0;m=((o=o+Math.imul(S,gt)|0)+(r>>>13)|0)+(xt>>>26)|0,xt&=67108863,n=Math.imul(N,it),r=(r=Math.imul(N,nt))+Math.imul(W,it)|0,o=Math.imul(W,nt),n=n+Math.imul(K,ot)|0,r=(r=r+Math.imul(K,st)|0)+Math.imul(L,ot)|0,o=o+Math.imul(L,st)|0,n=n+Math.imul(D,ut)|0,r=(r=r+Math.imul(D,mt)|0)+Math.imul(E,ut)|0,o=o+Math.imul(E,mt)|0,n=n+Math.imul(x,lt)|0,r=(r=r+Math.imul(x,dt)|0)+Math.imul(_,lt)|0,o=o+Math.imul(_,dt)|0;var _t=(m+(n=n+Math.imul(T,pt)|0)|0)+((8191&(r=(r=r+Math.imul(T,gt)|0)+Math.imul(C,pt)|0))<<13)|0;m=((o=o+Math.imul(C,gt)|0)+(r>>>13)|0)+(_t>>>26)|0,_t&=67108863,n=Math.imul(N,ot),r=(r=Math.imul(N,st))+Math.imul(W,ot)|0,o=Math.imul(W,st),n=n+Math.imul(K,ut)|0,r=(r=r+Math.imul(K,mt)|0)+Math.imul(L,ut)|0,o=o+Math.imul(L,mt)|0,n=n+Math.imul(D,lt)|0,r=(r=r+Math.imul(D,dt)|0)+Math.imul(E,lt)|0,o=o+Math.imul(E,dt)|0;var Ot=(m+(n=n+Math.imul(x,pt)|0)|0)+((8191&(r=(r=r+Math.imul(x,gt)|0)+Math.imul(_,pt)|0))<<13)|0;m=((o=o+Math.imul(_,gt)|0)+(r>>>13)|0)+(Ot>>>26)|0,Ot&=67108863,n=Math.imul(N,ut),r=(r=Math.imul(N,mt))+Math.imul(W,ut)|0,o=Math.imul(W,mt),n=n+Math.imul(K,lt)|0,r=(r=r+Math.imul(K,dt)|0)+Math.imul(L,lt)|0,o=o+Math.imul(L,dt)|0;var Dt=(m+(n=n+Math.imul(D,pt)|0)|0)+((8191&(r=(r=r+Math.imul(D,gt)|0)+Math.imul(E,pt)|0))<<13)|0;m=((o=o+Math.imul(E,gt)|0)+(r>>>13)|0)+(Dt>>>26)|0,Dt&=67108863,n=Math.imul(N,lt),r=(r=Math.imul(N,dt))+Math.imul(W,lt)|0,o=Math.imul(W,dt);var Et=(m+(n=n+Math.imul(K,pt)|0)|0)+((8191&(r=(r=r+Math.imul(K,gt)|0)+Math.imul(L,pt)|0))<<13)|0;m=((o=o+Math.imul(L,gt)|0)+(r>>>13)|0)+(Et>>>26)|0,Et&=67108863;var Bt=(m+(n=Math.imul(N,pt))|0)+((8191&(r=(r=Math.imul(N,gt))+Math.imul(W,pt)|0))<<13)|0;return m=((o=Math.imul(W,gt))+(r>>>13)|0)+(Bt>>>26)|0,Bt&=67108863,u[0]=ft,u[1]=yt,u[2]=Mt,u[3]=vt,u[4]=wt,u[5]=kt,u[6]=bt,u[7]=Pt,u[8]=St,u[9]=At,u[10]=Tt,u[11]=Ct,u[12]=It,u[13]=xt,u[14]=_t,u[15]=Ot,u[16]=Dt,u[17]=Et,u[18]=Bt,0!==m&&(u[19]=m,i.length++),i};function M(t,e,i){i.negative=e.negative^t.negative,i.length=t.length+e.length;for(var n=0,r=0,o=0;o<i.length-1;o++){var s=r;r=0;for(var a=67108863&n,u=Math.min(o,e.length-1),m=Math.max(0,o-t.length+1);m<=u;m++){var h=o-m,l=(0|t.words[h])*(0|e.words[m]),d=67108863&l;a=67108863&(d=d+a|0),r+=(s=(s=s+(l/67108864|0)|0)+(d>>>26)|0)>>>26,s&=67108863}i.words[o]=a,n=s,s=r}return 0!==n?i.words[o]=n:i.length--,i._strip()}function v(t,e,i){return M(t,e,i)}Math.imul||(y=p),r.prototype.mulTo=function(t,e){var i=this.length+t.length;return 10===this.length&&10===t.length?y(this,t,e):i<63?p(this,t,e):i<1024?M(this,t,e):v(this,t,e)},r.prototype.mul=function(t){var e=new r(null);return e.words=new Array(this.length+t.length),this.mulTo(t,e)},r.prototype.mulf=function(t){var e=new r(null);return e.words=new Array(this.length+t.length),v(this,t,e)},r.prototype.imul=function(t){return this.clone().mulTo(t,this)},r.prototype.imuln=function(t){var e=t<0;e&&(t=-t),i("number"==typeof t),i(t<67108864);for(var n=0,r=0;r<this.length;r++){var o=(0|this.words[r])*t,s=(67108863&o)+(67108863&n);n>>=26,n+=o/67108864|0,n+=s>>>26,this.words[r]=67108863&s}return 0!==n&&(this.words[r]=n,this.length++),e?this.ineg():this},r.prototype.muln=function(t){return this.clone().imuln(t)},r.prototype.sqr=function(){return this.mul(this)},r.prototype.isqr=function(){return this.imul(this.clone())},r.prototype.pow=function(t){var e=function(t){for(var e=new Array(t.bitLength()),i=0;i<e.length;i++){var n=i/26|0,r=i%26;e[i]=t.words[n]>>>r&1}return e}(t);if(0===e.length)return new r(1);for(var i=this,n=0;n<e.length&&0===e[n];n++,i=i.sqr());if(++n<e.length)for(var o=i.sqr();n<e.length;n++,o=o.sqr())0!==e[n]&&(i=i.mul(o));return i},r.prototype.iushln=function(t){i("number"==typeof t&&t>=0);var e,n=t%26,r=(t-n)/26,o=67108863>>>26-n<<26-n;if(0!==n){var s=0;for(e=0;e<this.length;e++){var a=this.words[e]&o,u=(0|this.words[e])-a<<n;this.words[e]=u|s,s=a>>>26-n}s&&(this.words[e]=s,this.length++)}if(0!==r){for(e=this.length-1;e>=0;e--)this.words[e+r]=this.words[e];for(e=0;e<r;e++)this.words[e]=0;this.length+=r}return this._strip()},r.prototype.ishln=function(t){return i(0===this.negative),this.iushln(t)},r.prototype.iushrn=function(t,e,n){var r;i("number"==typeof t&&t>=0),r=e?(e-e%26)/26:0;var o=t%26,s=Math.min((t-o)/26,this.length),a=67108863^67108863>>>o<<o,u=n;if(r-=s,r=Math.max(0,r),u){for(var m=0;m<s;m++)u.words[m]=this.words[m];u.length=s}if(0===s);else if(this.length>s)for(this.length-=s,m=0;m<this.length;m++)this.words[m]=this.words[m+s];else this.words[0]=0,this.length=1;var h=0;for(m=this.length-1;m>=0&&(0!==h||m>=r);m--){var l=0|this.words[m];this.words[m]=h<<26-o|l>>>o,h=l&a}return u&&0!==h&&(u.words[u.length++]=h),0===this.length&&(this.words[0]=0,this.length=1),this._strip()},r.prototype.ishrn=function(t,e,n){return i(0===this.negative),this.iushrn(t,e,n)},r.prototype.shln=function(t){return this.clone().ishln(t)},r.prototype.ushln=function(t){return this.clone().iushln(t)},r.prototype.shrn=function(t){return this.clone().ishrn(t)},r.prototype.ushrn=function(t){return this.clone().iushrn(t)},r.prototype.testn=function(t){i("number"==typeof t&&t>=0);var e=t%26,n=(t-e)/26,r=1<<e;return this.length<=n?0:!!(this.words[n]&r)},r.prototype.imaskn=function(t){i("number"==typeof t&&t>=0);var e=t%26,n=(t-e)/26;if(i(0===this.negative,"imaskn works only with positive numbers"),this.length<=n)return this;if(0!==e&&n++,this.length=Math.min(n,this.length),0!==e){var r=67108863^67108863>>>e<<e;this.words[this.length-1]&=r}return this._strip()},r.prototype.maskn=function(t){return this.clone().imaskn(t)},r.prototype.iaddn=function(t){return i("number"==typeof t),i(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)},r.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},r.prototype.isubn=function(t){if(i("number"==typeof t),i(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()},r.prototype.addn=function(t){return this.clone().iaddn(t)},r.prototype.subn=function(t){return this.clone().isubn(t)},r.prototype.iabs=function(){return this.negative=0,this},r.prototype.abs=function(){return this.clone().iabs()},r.prototype._ishlnsubmul=function(t,e,n){var r,o,s=t.length+n;this._expand(s);var a=0;for(r=0;r<t.length;r++){o=(0|this.words[r+n])+a;var u=(0|t.words[r])*e;a=((o-=67108863&u)>>26)-(u/67108864|0),this.words[r+n]=67108863&o}for(;r<this.length-n;r++)a=(o=(0|this.words[r+n])+a)>>26,this.words[r+n]=67108863&o;if(0===a)return this._strip();for(i(-1===a),a=0,r=0;r<this.length;r++)a=(o=-(0|this.words[r])+a)>>26,this.words[r]=67108863&o;return this.negative=1,this._strip()},r.prototype._wordDiv=function(t,e){var i=(this.length,t.length),n=this.clone(),o=t,s=0|o.words[o.length-1];0!=(i=26-this._countBits(s))&&(o=o.ushln(i),n.iushln(i),s=0|o.words[o.length-1]);var a,u=n.length-o.length;if("mod"!==e){(a=new r(null)).length=u+1,a.words=new Array(a.length);for(var m=0;m<a.length;m++)a.words[m]=0}var h=n.clone()._ishlnsubmul(o,1,u);0===h.negative&&(n=h,a&&(a.words[u]=1));for(var l=u-1;l>=0;l--){var d=67108864*(0|n.words[o.length+l])+(0|n.words[o.length+l-1]);for(d=Math.min(d/s|0,67108863),n._ishlnsubmul(o,d,l);0!==n.negative;)d--,n.negative=0,n._ishlnsubmul(o,1,l),n.isZero()||(n.negative^=1);a&&(a.words[l]=d)}return a&&a._strip(),n._strip(),"div"!==e&&0!==i&&n.iushrn(i),{div:a||null,mod:n}},r.prototype.divmod=function(t,e,n){return i(!t.isZero()),this.isZero()?{div:new r(0),mod:new r(0)}:0!==this.negative&&0===t.negative?(a=this.neg().divmod(t,e),"mod"!==e&&(o=a.div.neg()),"div"!==e&&(s=a.mod.neg(),n&&0!==s.negative&&s.iadd(t)),{div:o,mod:s}):0===this.negative&&0!==t.negative?(a=this.divmod(t.neg(),e),"mod"!==e&&(o=a.div.neg()),{div:o,mod:a.mod}):0!=(this.negative&t.negative)?(a=this.neg().divmod(t.neg(),e),"div"!==e&&(s=a.mod.neg(),n&&0!==s.negative&&s.isub(t)),{div:a.div,mod:s}):t.length>this.length||this.cmp(t)<0?{div:new r(0),mod:this}:1===t.length?"div"===e?{div:this.divn(t.words[0]),mod:null}:"mod"===e?{div:null,mod:new r(this.modrn(t.words[0]))}:{div:this.divn(t.words[0]),mod:new r(this.modrn(t.words[0]))}:this._wordDiv(t,e);var o,s,a},r.prototype.div=function(t){return this.divmod(t,"div",0).div},r.prototype.mod=function(t){return this.divmod(t,"mod",0).mod},r.prototype.umod=function(t){return this.divmod(t,"mod",1).mod},r.prototype.divRound=function(t){var e=this.divmod(t);if(e.mod.isZero())return e.div;var i=0!==e.div.negative?e.mod.isub(t):e.mod,n=t.ushrn(1),r=t.andln(1),o=i.cmp(n);return o<0||1===r&&0===o?e.div:0!==e.div.negative?e.div.isubn(1):e.div.iaddn(1)},r.prototype.modrn=function(t){var e=t<0;e&&(t=-t),i(t<=67108863);for(var n=(1<<26)%t,r=0,o=this.length-1;o>=0;o--)r=(n*r+(0|this.words[o]))%t;return e?-r:r},r.prototype.modn=function(t){return this.modrn(t)},r.prototype.idivn=function(t){var e=t<0;e&&(t=-t),i(t<=67108863);for(var n=0,r=this.length-1;r>=0;r--){var o=(0|this.words[r])+67108864*n;this.words[r]=o/t|0,n=o%t}return this._strip(),e?this.ineg():this},r.prototype.divn=function(t){return this.clone().idivn(t)},r.prototype.egcd=function(t){i(0===t.negative),i(!t.isZero());var e=this,n=t.clone();e=0!==e.negative?e.umod(t):e.clone();for(var o=new r(1),s=new r(0),a=new r(0),u=new r(1),m=0;e.isEven()&&n.isEven();)e.iushrn(1),n.iushrn(1),++m;for(var h=n.clone(),l=e.clone();!e.isZero();){for(var d=0,c=1;0==(e.words[0]&c)&&d<26;++d,c<<=1);if(d>0)for(e.iushrn(d);d-- >0;)(o.isOdd()||s.isOdd())&&(o.iadd(h),s.isub(l)),o.iushrn(1),s.iushrn(1);for(var p=0,g=1;0==(n.words[0]&g)&&p<26;++p,g<<=1);if(p>0)for(n.iushrn(p);p-- >0;)(a.isOdd()||u.isOdd())&&(a.iadd(h),u.isub(l)),a.iushrn(1),u.iushrn(1);e.cmp(n)>=0?(e.isub(n),o.isub(a),s.isub(u)):(n.isub(e),a.isub(o),u.isub(s))}return{a:a,b:u,gcd:n.iushln(m)}},r.prototype._invmp=function(t){i(0===t.negative),i(!t.isZero());var e=this,n=t.clone();e=0!==e.negative?e.umod(t):e.clone();for(var o,s=new r(1),a=new r(0),u=n.clone();e.cmpn(1)>0&&n.cmpn(1)>0;){for(var m=0,h=1;0==(e.words[0]&h)&&m<26;++m,h<<=1);if(m>0)for(e.iushrn(m);m-- >0;)s.isOdd()&&s.iadd(u),s.iushrn(1);for(var l=0,d=1;0==(n.words[0]&d)&&l<26;++l,d<<=1);if(l>0)for(n.iushrn(l);l-- >0;)a.isOdd()&&a.iadd(u),a.iushrn(1);e.cmp(n)>=0?(e.isub(n),s.isub(a)):(n.isub(e),a.isub(s))}return(o=0===e.cmpn(1)?s:a).cmpn(0)<0&&o.iadd(t),o},r.prototype.gcd=function(t){if(this.isZero())return t.abs();if(t.isZero())return this.abs();var e=this.clone(),i=t.clone();e.negative=0,i.negative=0;for(var n=0;e.isEven()&&i.isEven();n++)e.iushrn(1),i.iushrn(1);for(;;){for(;e.isEven();)e.iushrn(1);for(;i.isEven();)i.iushrn(1);var r=e.cmp(i);if(r<0){var o=e;e=i,i=o}else if(0===r||0===i.cmpn(1))break;e.isub(i)}return i.iushln(n)},r.prototype.invm=function(t){return this.egcd(t).a.umod(t)},r.prototype.isEven=function(){return 0==(1&this.words[0])},r.prototype.isOdd=function(){return 1==(1&this.words[0])},r.prototype.andln=function(t){return this.words[0]&t},r.prototype.bincn=function(t){i("number"==typeof t);var e=t%26,n=(t-e)/26,r=1<<e;if(this.length<=n)return this._expand(n+1),this.words[n]|=r,this;for(var o=r,s=n;0!==o&&s<this.length;s++){var a=0|this.words[s];o=(a+=o)>>>26,a&=67108863,this.words[s]=a}return 0!==o&&(this.words[s]=o,this.length++),this},r.prototype.isZero=function(){return 1===this.length&&0===this.words[0]},r.prototype.cmpn=function(t){var e,n=t<0;if(0!==this.negative&&!n)return-1;if(0===this.negative&&n)return 1;if(this._strip(),this.length>1)e=1;else{n&&(t=-t),i(t<=67108863,"Number is too big");var r=0|this.words[0];e=r===t?0:r<t?-1:1}return 0!==this.negative?0|-e:e},r.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},r.prototype.ucmp=function(t){if(this.length>t.length)return 1;if(this.length<t.length)return-1;for(var e=0,i=this.length-1;i>=0;i--){var n=0|this.words[i],r=0|t.words[i];if(n!==r){n<r?e=-1:n>r&&(e=1);break}}return e},r.prototype.gtn=function(t){return 1===this.cmpn(t)},r.prototype.gt=function(t){return 1===this.cmp(t)},r.prototype.gten=function(t){return this.cmpn(t)>=0},r.prototype.gte=function(t){return this.cmp(t)>=0},r.prototype.ltn=function(t){return-1===this.cmpn(t)},r.prototype.lt=function(t){return-1===this.cmp(t)},r.prototype.lten=function(t){return this.cmpn(t)<=0},r.prototype.lte=function(t){return this.cmp(t)<=0},r.prototype.eqn=function(t){return 0===this.cmpn(t)},r.prototype.eq=function(t){return 0===this.cmp(t)},r.red=function(t){return new T(t)},r.prototype.toRed=function(t){return i(!this.red,"Already a number in reduction context"),i(0===this.negative,"red works only with positives"),t.convertTo(this)._forceRed(t)},r.prototype.fromRed=function(){return i(this.red,"fromRed works only with numbers in reduction context"),this.red.convertFrom(this)},r.prototype._forceRed=function(t){return this.red=t,this},r.prototype.forceRed=function(t){return i(!this.red,"Already a number in reduction context"),this._forceRed(t)},r.prototype.redAdd=function(t){return i(this.red,"redAdd works only with red numbers"),this.red.add(this,t)},r.prototype.redIAdd=function(t){return i(this.red,"redIAdd works only with red numbers"),this.red.iadd(this,t)},r.prototype.redSub=function(t){return i(this.red,"redSub works only with red numbers"),this.red.sub(this,t)},r.prototype.redISub=function(t){return i(this.red,"redISub works only with red numbers"),this.red.isub(this,t)},r.prototype.redShl=function(t){return i(this.red,"redShl works only with red numbers"),this.red.shl(this,t)},r.prototype.redMul=function(t){return i(this.red,"redMul works only with red numbers"),this.red._verify2(this,t),this.red.mul(this,t)},r.prototype.redIMul=function(t){return i(this.red,"redMul works only with red numbers"),this.red._verify2(this,t),this.red.imul(this,t)},r.prototype.redSqr=function(){return i(this.red,"redSqr works only with red numbers"),this.red._verify1(this),this.red.sqr(this)},r.prototype.redISqr=function(){return i(this.red,"redISqr works only with red numbers"),this.red._verify1(this),this.red.isqr(this)},r.prototype.redSqrt=function(){return i(this.red,"redSqrt works only with red numbers"),this.red._verify1(this),this.red.sqrt(this)},r.prototype.redInvm=function(){return i(this.red,"redInvm works only with red numbers"),this.red._verify1(this),this.red.invm(this)},r.prototype.redNeg=function(){return i(this.red,"redNeg works only with red numbers"),this.red._verify1(this),this.red.neg(this)},r.prototype.redPow=function(t){return i(this.red&&!t.red,"redPow(normalNum)"),this.red._verify1(this),this.red.pow(this,t)};var w={k256:null,p224:null,p192:null,p25519:null};function k(t,e){this.name=t,this.p=new r(e,16),this.n=this.p.bitLength(),this.k=new r(1).iushln(this.n).isub(this.p),this.tmp=this._tmp()}function b(){k.call(this,"k256","ffffffff ffffffff ffffffff ffffffff ffffffff ffffffff fffffffe fffffc2f")}function P(){k.call(this,"p224","ffffffff ffffffff ffffffff ffffffff 00000000 00000000 00000001")}function S(){k.call(this,"p192","ffffffff ffffffff ffffffff fffffffe ffffffff ffffffff")}function A(){k.call(this,"25519","7fffffffffffffff ffffffffffffffff ffffffffffffffff ffffffffffffffed")}function T(t){if("string"==typeof t){var e=r._prime(t);this.m=e.p,this.prime=e}else i(t.gtn(1),"modulus must be greater than 1"),this.m=t,this.prime=null}function C(t){T.call(this,t),this.shift=this.m.bitLength(),this.shift%26!=0&&(this.shift+=26-this.shift%26),this.r=new r(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)}k.prototype._tmp=function(){var t=new r(null);return t.words=new Array(Math.ceil(this.n/13)),t},k.prototype.ireduce=function(t){var e,i=t;do{this.split(i,this.tmp),e=(i=(i=this.imulK(i)).iadd(this.tmp)).bitLength()}while(e>this.n);var n=e<this.n?-1:i.ucmp(this.p);return 0===n?(i.words[0]=0,i.length=1):n>0?i.isub(this.p):void 0!==i.strip?i.strip():i._strip(),i},k.prototype.split=function(t,e){t.iushrn(this.n,0,e)},k.prototype.imulK=function(t){return t.imul(this.k)},n(b,k),b.prototype.split=function(t,e){for(var i=4194303,n=Math.min(t.length,9),r=0;r<n;r++)e.words[r]=t.words[r];if(e.length=n,t.length<=9)return t.words[0]=0,void(t.length=1);var o=t.words[9];for(e.words[e.length++]=o&i,r=10;r<t.length;r++){var s=0|t.words[r];t.words[r-10]=(s&i)<<4|o>>>22,o=s}o>>>=22,t.words[r-10]=o,0===o&&t.length>10?t.length-=10:t.length-=9},b.prototype.imulK=function(t){t.words[t.length]=0,t.words[t.length+1]=0,t.length+=2;for(var e=0,i=0;i<t.length;i++){var n=0|t.words[i];e+=977*n,t.words[i]=67108863&e,e=64*n+(e/67108864|0)}return 0===t.words[t.length-1]&&(t.length--,0===t.words[t.length-1]&&t.length--),t},n(P,k),n(S,k),n(A,k),A.prototype.imulK=function(t){for(var e=0,i=0;i<t.length;i++){var n=19*(0|t.words[i])+e,r=67108863&n;n>>>=26,t.words[i]=r,e=n}return 0!==e&&(t.words[t.length++]=e),t},r._prime=function(t){if(w[t])return w[t];var e;if("k256"===t)e=new b;else if("p224"===t)e=new P;else if("p192"===t)e=new S;else{if("p25519"!==t)throw new Error("Unknown prime "+t);e=new A}return w[t]=e,e},T.prototype._verify1=function(t){i(0===t.negative,"red works only with positives"),i(t.red,"red works only with red numbers")},T.prototype._verify2=function(t,e){i(0==(t.negative|e.negative),"red works only with positives"),i(t.red&&t.red===e.red,"red works only with red numbers")},T.prototype.imod=function(t){return this.prime?this.prime.ireduce(t)._forceRed(this):(m(t,t.umod(this.m)._forceRed(this)),t)},T.prototype.neg=function(t){return t.isZero()?t.clone():this.m.sub(t)._forceRed(this)},T.prototype.add=function(t,e){this._verify2(t,e);var i=t.add(e);return i.cmp(this.m)>=0&&i.isub(this.m),i._forceRed(this)},T.prototype.iadd=function(t,e){this._verify2(t,e);var i=t.iadd(e);return i.cmp(this.m)>=0&&i.isub(this.m),i},T.prototype.sub=function(t,e){this._verify2(t,e);var i=t.sub(e);return i.cmpn(0)<0&&i.iadd(this.m),i._forceRed(this)},T.prototype.isub=function(t,e){this._verify2(t,e);var i=t.isub(e);return i.cmpn(0)<0&&i.iadd(this.m),i},T.prototype.shl=function(t,e){return this._verify1(t),this.imod(t.ushln(e))},T.prototype.imul=function(t,e){return this._verify2(t,e),this.imod(t.imul(e))},T.prototype.mul=function(t,e){return this._verify2(t,e),this.imod(t.mul(e))},T.prototype.isqr=function(t){return this.imul(t,t.clone())},T.prototype.sqr=function(t){return this.mul(t,t)},T.prototype.sqrt=function(t){if(t.isZero())return t.clone();var e=this.m.andln(3);if(i(e%2==1),3===e){var n=this.m.add(new r(1)).iushrn(2);return this.pow(t,n)}for(var o=this.m.subn(1),s=0;!o.isZero()&&0===o.andln(1);)s++,o.iushrn(1);i(!o.isZero());var a=new r(1).toRed(this),u=a.redNeg(),m=this.m.subn(1).iushrn(1),h=this.m.bitLength();for(h=new r(2*h*h).toRed(this);0!==this.pow(h,m).cmp(u);)h.redIAdd(u);for(var l=this.pow(h,o),d=this.pow(t,o.addn(1).iushrn(1)),c=this.pow(t,o),p=s;0!==c.cmp(a);){for(var g=c,f=0;0!==g.cmp(a);f++)g=g.redSqr();i(f<p);var y=this.pow(l,new r(1).iushln(p-f-1));d=d.redMul(y),l=y.redSqr(),c=c.redMul(l),p=f}return d},T.prototype.invm=function(t){var e=t._invmp(this.m);return 0!==e.negative?(e.negative=0,this.imod(e).redNeg()):this.imod(e)},T.prototype.pow=function(t,e){if(e.isZero())return new r(1).toRed(this);if(0===e.cmpn(1))return t.clone();var i=new Array(16);i[0]=new r(1).toRed(this),i[1]=t;for(var n=2;n<i.length;n++)i[n]=this.mul(i[n-1],t);var o=i[0],s=0,a=0,u=e.bitLength()%26;for(0===u&&(u=26),n=e.length-1;n>=0;n--){for(var m=e.words[n],h=u-1;h>=0;h--){var l=m>>h&1;o!==i[0]&&(o=this.sqr(o)),0!==l||0!==s?(s<<=1,s|=l,(4==++a||0===n&&0===h)&&(o=this.mul(o,i[s]),a=0,s=0)):a=0}u=26}return o},T.prototype.convertTo=function(t){var e=t.umod(this.m);return e===t?e.clone():e},T.prototype.convertFrom=function(t){var e=t.clone();return e.red=null,e},r.mont=function(t){return new C(t)},n(C,T),C.prototype.convertTo=function(t){return this.imod(t.ushln(this.shift))},C.prototype.convertFrom=function(t){var e=this.imod(t.mul(this.rinv));return e.red=null,e},C.prototype.imul=function(t,e){if(t.isZero()||e.isZero())return t.words[0]=0,t.length=1,t;var i=t.imul(e),n=i.maskn(this.shift).mul(this.minv).imaskn(this.shift).mul(this.m),r=i.isub(n).iushrn(this.shift),o=r;return r.cmp(this.m)>=0?o=r.isub(this.m):r.cmpn(0)<0&&(o=r.iadd(this.m)),o._forceRed(this)},C.prototype.mul=function(t,e){if(t.isZero()||e.isZero())return new r(0)._forceRed(this);var i=t.mul(e),n=i.maskn(this.shift).mul(this.minv).imaskn(this.shift).mul(this.m),o=i.isub(n).iushrn(this.shift),s=o;return o.cmp(this.m)>=0?s=o.isub(this.m):o.cmpn(0)<0&&(s=o.iadd(this.m)),s._forceRed(this)},C.prototype.invm=function(t){return this.imod(t._invmp(this.m).mul(this.r2))._forceRed(this)}}(0,d);var y=c(g.exports);const M=n.struct([n.array(n.u8(),32,"a"),n.array(n.u8(),64,"b"),n.array(n.u8(),32,"c")]),v=n.struct([n.publicKey("owner"),n.u64("amount"),n.option(n.u64(),"lamports"),n.u8("merkleTreeIndex"),n.option(n.vecU8(),"tlv")]),w=n.struct([n.u8("queueId"),n.u16("index")]),k=n.struct([n.u64("amount"),n.option(n.u8(),"delegateIndex"),n.struct([n.u8("merkleTreePubkeyIndex"),n.u8("nullifierQueuePubkeyIndex"),n.u32("leafIndex"),n.option(w,"queueIndex")],"merkleContext"),n.u16("rootIndex"),n.option(n.u64(),"lamports"),n.option(n.vecU8(),"tlv")]),b=n.struct([n.publicKey("owner"),n.option(n.u8(),"delegateChangeAccountIndex")]),P=n.struct([n.bool("setContext"),n.bool("firstSetContext"),n.u8("cpiContextAccountIndex")]),S=n.struct([n.option(M,"proof"),n.publicKey("mint"),n.option(b,"delegatedTransfer"),n.vec(k,"inputTokenDataWithContext"),n.vec(v,"outputCompressedAccounts"),n.bool("isCompress"),n.option(n.u64(),"compressOrDecompressAmount"),n.option(P,"cpiContext"),n.option(n.u8(),"lamportsChangeAccountMerkleTreeIndex")]),A=n.struct([n.vec(n.publicKey(),"recipients"),n.vec(n.u64(),"amounts"),n.option(n.u64(),"lamports")]),T=n.struct([n.publicKey("owner"),n.option(n.u64(),"remainingAmount"),n.option(P,"cpiContext")]);function C(t){const e=r.Buffer.alloc(1e3),i=A.encode({recipients:t.recipients,amounts:t.amounts,lamports:t.lamports},e);return r.Buffer.concat([m,e.slice(0,i)])}function I(t){const e=r.Buffer.alloc(1e3),i=T.encode({owner:t.owner,remainingAmount:t.remainingAmount,cpiContext:t.cpiContext},e);return r.Buffer.concat([l,e.slice(0,i)])}function x(t){const e=r.Buffer.alloc(1e3),i=S.encode(t,e),n=r.Buffer.alloc(4);return n.writeUInt32LE(i,0),r.Buffer.concat([h,n,e.slice(0,i)])}const _=t=>{const{feePayer:e,tokenPoolPda:i,systemProgram:n,mint:r,tokenProgram:o,cpiAuthorityPda:s}=t;return[{pubkey:e,isSigner:1,isWritable:1},{pubkey:i,isSigner:0,isWritable:1},{pubkey:n,isSigner:0,isWritable:0},{pubkey:r,isSigner:0,isWritable:1},{pubkey:o,isSigner:0,isWritable:0},{pubkey:s,isSigner:0,isWritable:0}]},O=t=>{const e=N.programId,{feePayer:i,authority:n,cpiAuthorityPda:r,mint:o,tokenPoolPda:s,tokenProgram:a,lightSystemProgram:u,registeredProgramPda:m,noopProgram:h,accountCompressionAuthority:l,accountCompressionProgram:d,merkleTree:c,selfProgram:p,systemProgram:g,solPoolPda:f}=t;return[{pubkey:i,isSigner:1,isWritable:1},{pubkey:n,isSigner:1,isWritable:0},{pubkey:r,isSigner:0,isWritable:0},{pubkey:o,isSigner:0,isWritable:1},{pubkey:s,isSigner:0,isWritable:1},{pubkey:a,isSigner:0,isWritable:0},{pubkey:u,isSigner:0,isWritable:0},{pubkey:m,isSigner:0,isWritable:0},{pubkey:h,isSigner:0,isWritable:0},{pubkey:l,isSigner:0,isWritable:0},{pubkey:d,isSigner:0,isWritable:0},{pubkey:c,isSigner:0,isWritable:1},{pubkey:p,isSigner:0,isWritable:0},{pubkey:g,isSigner:0,isWritable:0},{pubkey:null!=f?f:e,isSigner:0,isWritable:1}]},D=t=>{const e=N.programId,{feePayer:i,authority:n,cpiAuthorityPda:r,lightSystemProgram:o,registeredProgramPda:s,noopProgram:a,accountCompressionAuthority:u,accountCompressionProgram:m,selfProgram:h,tokenPoolPda:l,compressOrDecompressTokenAccount:d,tokenProgram:c,systemProgram:p}=t;return[{pubkey:i,isSigner:1,isWritable:1},{pubkey:n,isSigner:1,isWritable:0},{pubkey:r,isSigner:0,isWritable:0},{pubkey:o,isSigner:0,isWritable:0},{pubkey:s,isSigner:0,isWritable:0},{pubkey:a,isSigner:0,isWritable:0},{pubkey:u,isSigner:0,isWritable:0},{pubkey:m,isSigner:0,isWritable:0},{pubkey:h,isSigner:0,isWritable:0},{pubkey:null!=l?l:e,isSigner:0,isWritable:1},{pubkey:null!=d?d:e,isSigner:0,isWritable:1},{pubkey:null!=c?c:e,isSigner:0,isWritable:0},{pubkey:p,isSigner:0,isWritable:0}]},E=e=>e.reduce(((t,e)=>t.add(e.parsed.amount)),t.bn(0)),B=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")}))},K=t=>({mint:t[0].parsed.mint,currentOwner:t[0].parsed.owner,delegate:t[0].parsed.delegate});function L(e,i,n){n=t.bn(n);const r=E(e),o=t.sumUpLamports(e.map((t=>t.compressedAccount))),s=r.sub(n);return t.validateSufficientBalance(s),s.eq(t.bn(0))&&o.eq(t.bn(0))?[{owner:i,amount:n,lamports:o,tlv:null}]:(t.validateSameOwner(e.map((t=>t.compressedAccount))),B(e),[{owner:e[0].parsed.owner,amount:s,lamports:o,tlv:null},{owner:i,amount:n,lamports:t.bn(0),tlv:null}])}function R(e,i){i=t.bn(i);const n=t.sumUpLamports(e.map((t=>t.compressedAccount))),r=E(e).sub(i);return t.validateSufficientBalance(r),r.eq(t.bn(0))&&n.eq(t.bn(0))?[]:(t.validateSameOwner(e.map((t=>t.compressedAccount))),B(e),[{owner:e[0].parsed.owner,amount:r,lamports:n,tlv:null}])}class N{constructor(){}static setProgramId(t){this.programId="string"==typeof t?new e.PublicKey(t):t}static deriveTokenPoolPda(t){const i=[s,t.toBuffer()],[n,r]=e.PublicKey.findProgramAddressSync(i,this.programId);return n}static get deriveCpiAuthorityPda(){const[t,i]=e.PublicKey.findProgramAddressSync([a],this.programId);return t}static async createMint(t){const{mint:n,authority:r,feePayer:o,rentExemptBalance:s,tokenProgramId:a,freezeAuthority:u,mintSize:m}=t,h=null!=a?a:i.TOKEN_PROGRAM_ID;return[e.SystemProgram.createAccount({fromPubkey:o,lamports:s,newAccountPubkey:n,programId:h,space:null!=m?m:i.MINT_SIZE}),i.createInitializeMint2Instruction(n,t.decimals,r,u,h),await this.createTokenPool({feePayer:o,mint:n,tokenProgramId:h})]}static async createTokenPool(t){const{mint:n,feePayer:r,tokenProgramId:o}=t,s=null!=o?o:i.TOKEN_PROGRAM_ID,a=this.deriveTokenPoolPda(n),m=_({mint:n,feePayer:r,tokenPoolPda:a,tokenProgram:s,cpiAuthorityPda:this.deriveCpiAuthorityPda,systemProgram:e.SystemProgram.programId});return new e.TransactionInstruction({programId:this.programId,keys:m,data:u})}static async mintTo(n){const r=t.defaultStaticAccountsStruct(),{mint:o,feePayer:s,authority:a,merkleTree:u,toPubkey:m,amount:h,tokenProgramId:l}=n,d=null!=l?l:i.TOKEN_PROGRAM_ID,c=this.deriveTokenPoolPda(o),p=t.toArray(h).map((e=>t.bn(e))),g=t.toArray(m);if(p.length!==g.length)throw new Error("Amount and toPubkey arrays must have the same length");const f=O({mint:o,feePayer:s,authority:a,cpiAuthorityPda:this.deriveCpiAuthorityPda,tokenProgram:d,tokenPoolPda:c,lightSystemProgram:t.LightSystemProgram.programId,registeredProgramPda:r.registeredProgramPda,noopProgram:r.noopProgram,accountCompressionAuthority:r.accountCompressionAuthority,accountCompressionProgram:r.accountCompressionProgram,merkleTree:null!=u?u:t.defaultTestStateTreeAccounts().merkleTree,selfProgram:this.programId,systemProgram:e.SystemProgram.programId,solPoolPda:null}),y=C({recipients:g,amounts:p,lamports:null});return new e.TransactionInstruction({programId:this.programId,keys:f,data:y})}static async approveAndMintTo(t){const{mint:e,feePayer:n,authorityTokenAccount:r,authority:o,merkleTree:s,toPubkey:a,tokenProgramId:u}=t,m=BigInt(t.amount.toString());return[i.createMintToInstruction(e,r,o,m,[],u),await this.compress({payer:n,owner:o,source:r,toAddress:a,mint:e,amount:t.amount,outputStateTree:s,tokenProgramId:u})]}static async transfer(i){const{payer:n,inputCompressedTokenAccounts:r,recentInputStateRootIndices:s,recentValidityProof:a,amount:u,outputStateTrees:m,toAddress:h}=i,l=L(r,h,u),{inputTokenDataWithContext:d,packedOutputTokenData:c,remainingAccountMetas:p}=o({inputCompressedTokenAccounts:r,outputStateTrees:m,rootIndices:s,tokenTransferOutputs:l}),{mint:g,currentOwner:f}=K(r),y=x({proof:a,mint:g,delegatedTransfer:null,inputTokenDataWithContext:d,outputCompressedAccounts:c,compressOrDecompressAmount:null,isCompress:0,cpiContext:null,lamportsChangeAccountMerkleTreeIndex:null}),{accountCompressionAuthority:M,noopProgram:v,registeredProgramPda:w,accountCompressionProgram:k}=t.defaultStaticAccountsStruct(),b=D({feePayer:n,authority:f,cpiAuthorityPda:this.deriveCpiAuthorityPda,lightSystemProgram:t.LightSystemProgram.programId,registeredProgramPda:w,noopProgram:v,accountCompressionAuthority:M,accountCompressionProgram:k,selfProgram:this.programId,tokenPoolPda:void 0,compressOrDecompressTokenAccount:void 0,tokenProgram:void 0,systemProgram:e.SystemProgram.programId});return b.push(...p),new e.TransactionInstruction({programId:this.programId,keys:b,data:y})}static async createTokenProgramLookupTable(n){const{authority:r,mints:o,recentSlot:s,payer:a,remainingAccounts:u}=n,[m,h]=e.AddressLookupTableProgram.createLookupTable({authority:r,payer:r,recentSlot:s});let l=[];return o&&(l=[...o,...o.map((t=>this.deriveTokenPoolPda(t)))]),{instructions:[m,e.AddressLookupTableProgram.extendLookupTable({payer:a,authority:r,lookupTable:h,addresses:[this.deriveCpiAuthorityPda,t.LightSystemProgram.programId,t.defaultStaticAccountsStruct().registeredProgramPda,t.defaultStaticAccountsStruct().noopProgram,t.defaultStaticAccountsStruct().accountCompressionAuthority,t.defaultStaticAccountsStruct().accountCompressionProgram,t.defaultTestStateTreeAccounts().merkleTree,t.defaultTestStateTreeAccounts().nullifierQueue,t.defaultTestStateTreeAccounts().addressTree,t.defaultTestStateTreeAccounts().addressQueue,this.programId,i.TOKEN_PROGRAM_ID,i.TOKEN_2022_PROGRAM_ID,r,...l,...null!=u?u:[]]})],address:h}}static async compress(n){const{payer:r,owner:s,source:a,toAddress:u,mint:m,outputStateTree:h,tokenProgramId:l}=n;if(Array.isArray(n.amount)!==Array.isArray(n.toAddress))throw new Error("Both amount and toAddress must be arrays or both must be single values");let d;if(Array.isArray(n.amount)&&Array.isArray(n.toAddress)){if(n.amount.length!==n.toAddress.length)throw new Error("Amount and toAddress arrays must have the same length");d=n.amount.map(((e,i)=>{const r=t.bn(e);return{owner:n.toAddress[i],amount:r,lamports:t.bn(0),tlv:null}}))}else d=[{owner:u,amount:t.bn(n.amount),lamports:t.bn(0),tlv:null}];const{inputTokenDataWithContext:c,packedOutputTokenData:p,remainingAccountMetas:g}=o({inputCompressedTokenAccounts:[],outputStateTrees:h,rootIndices:[],tokenTransferOutputs:d}),f=x({proof:null,mint:m,delegatedTransfer:null,inputTokenDataWithContext:c,outputCompressedAccounts:p,compressOrDecompressAmount:Array.isArray(n.amount)?n.amount.map((t=>new y(t))).reduce(((t,e)=>t.add(e)),new y(0)):new y(n.amount),isCompress:1,cpiContext:null,lamportsChangeAccountMerkleTreeIndex:null}),M=null!=l?l:i.TOKEN_PROGRAM_ID,v=D(Object.assign(Object.assign({},t.defaultStaticAccountsStruct()),{feePayer:r,authority:s,cpiAuthorityPda:this.deriveCpiAuthorityPda,lightSystemProgram:t.LightSystemProgram.programId,selfProgram:this.programId,systemProgram:e.SystemProgram.programId,tokenPoolPda:this.deriveTokenPoolPda(m),compressOrDecompressTokenAccount:a,tokenProgram:M}));return v.push(...g),new e.TransactionInstruction({programId:this.programId,keys:v,data:f})}static async decompress(n){const{payer:r,inputCompressedTokenAccounts:s,toAddress:a,outputStateTree:u,recentValidityProof:m,recentInputStateRootIndices:h,tokenProgramId:l}=n,d=t.bn(n.amount),c=R(s,d),{inputTokenDataWithContext:p,packedOutputTokenData:g,remainingAccountMetas:f}=o({inputCompressedTokenAccounts:s,outputStateTrees:u,rootIndices:h,tokenTransferOutputs:c}),{mint:y,currentOwner:M}=K(s),v=x({proof:m,mint:y,delegatedTransfer:null,inputTokenDataWithContext:p,outputCompressedAccounts:g,compressOrDecompressAmount:d,isCompress:0,cpiContext:null,lamportsChangeAccountMerkleTreeIndex:null}),w=null!=l?l:i.TOKEN_PROGRAM_ID,{accountCompressionAuthority:k,noopProgram:b,registeredProgramPda:P,accountCompressionProgram:S}=t.defaultStaticAccountsStruct(),A=D({feePayer:r,authority:M,cpiAuthorityPda:this.deriveCpiAuthorityPda,lightSystemProgram:t.LightSystemProgram.programId,registeredProgramPda:P,noopProgram:b,accountCompressionAuthority:k,accountCompressionProgram:S,selfProgram:this.programId,tokenPoolPda:this.deriveTokenPoolPda(y),compressOrDecompressTokenAccount:a,tokenProgram:w,systemProgram:e.SystemProgram.programId});return A.push(...f),new e.TransactionInstruction({programId:this.programId,keys:A,data:v})}static async mergeTokenAccounts(t){const{payer:e,owner:i,inputCompressedTokenAccounts:n,outputStateTree:r,recentValidityProof:o,recentInputStateRootIndices:s}=t;if(n.length>3)throw new Error("Cannot merge more than 3 token accounts at once");return[await this.transfer({payer:e,inputCompressedTokenAccounts:n,toAddress:i,amount:n.reduce(((t,e)=>t.add(e.parsed.amount)),new y(0)),outputStateTrees:r,recentInputStateRootIndices:s,recentValidityProof:o})]}static async compressSplTokenAccount(n){const{feePayer:r,authority:o,tokenAccount:s,mint:a,remainingAmount:u,outputStateTree:m,tokenProgramId:h}=n,l=null!=h?h:i.TOKEN_PROGRAM_ID,d=[{pubkey:m,isSigner:0,isWritable:1}],c=I({owner:o,remainingAmount:null!=u?u:null,cpiContext:null}),{accountCompressionAuthority:p,noopProgram:g,registeredProgramPda:f,accountCompressionProgram:y}=t.defaultStaticAccountsStruct(),M=D({feePayer:r,authority:o,cpiAuthorityPda:this.deriveCpiAuthorityPda,lightSystemProgram:t.LightSystemProgram.programId,registeredProgramPda:f,noopProgram:g,accountCompressionAuthority:p,accountCompressionProgram:y,selfProgram:this.programId,tokenPoolPda:this.deriveTokenPoolPda(a),compressOrDecompressTokenAccount:s,tokenProgram:l,systemProgram:e.SystemProgram.programId});return M.push(...d),new e.TransactionInstruction({programId:this.programId,keys:M,data:c})}static async get_mint_program_id(t,e){var i;return null===(i=await e.getAccountInfo(t))||void 0===i?void 0:i.owner}}function W(e,i){let n=t.bn(0),r=t.bn(0);const o=[];e.sort(((t,e)=>e.parsed.amount.cmp(t.parsed.amount)));for(const s of e){if(n.gte(t.bn(i)))break;n=n.add(s.parsed.amount),r=r.add(s.compressedAccount.lamports),o.push(s)}if(n.lt(t.bn(i)))throw new Error(`Not enough balance for transfer. Required: ${i.toString()}, available: ${n.toString()}`);return[o,n,r.lt(t.bn(0))?r:null]}N.programId=new e.PublicKey("cTokenmWW8bLPjZEBAUgYy3zKxQZW6VKi7bqNFEVv3m"),exports.COMPRESS_SPL_TOKEN_ACCOUNT_DISCRIMINATOR=l,exports.CPI_AUTHORITY_SEED=a,exports.CREATE_TOKEN_POOL_DISCRIMINATOR=u,exports.CompressedTokenInstructionDataTransferLayout=S,exports.CompressedTokenProgram=N,exports.CpiContextLayout=P,exports.DelegatedTransferLayout=b,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:"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:"nullifierQueuePubkeyIndex",type:"u8"},{name:"leafIndex",type:"u32"},{name:"queueIndex",type:{option:{defined:"QueueIndex"}}}]}},{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.MINT_TO_DISCRIMINATOR=m,exports.POOL_SEED=s,exports.SPL_TOKEN_MINT_RENT_EXEMPT_BALANCE=1461600,exports.TRANSFER_DISCRIMINATOR=h,exports.approveAndMintTo=async function(n,r,o,s,a,u,m,h,l){l=l||await N.get_mint_program_id(o,n);const d=await i.getOrCreateAssociatedTokenAccount(n,r,o,a.publicKey,void 0,void 0,h,l);if(!m){const e=await n.getCachedActiveStateTreeInfo(),{tree:i}=t.pickRandomTreeAndQueue(e);m=i}const c=await N.approveAndMintTo({feePayer:r.publicKey,mint:o,authority:a.publicKey,authorityTokenAccount:d.address,amount:u,toPubkey:s,merkleTree:m,tokenProgramId:l}),{blockhash:p}=await n.getLatestBlockhash(),g=t.dedupeSigner(r,[a]),f=t.buildAndSignTx([e.ComputeBudgetProgram.setComputeUnitLimit({units:1e6}),...c],r,p,g);return await t.sendAndConfirmTx(n,f,h)},exports.compress=async function(i,n,r,o,s,a,u,m,h,l){if(l=l||await N.get_mint_program_id(r,i),!m){const e=await i.getCachedActiveStateTreeInfo(),{tree:n}=t.pickRandomTreeAndQueue(e);m=n}const d=await N.compress({payer:n.publicKey,owner:s.publicKey,source:a,toAddress:u,amount:o,mint:r,outputStateTree:m,tokenProgramId:l}),c=await i.getLatestBlockhash(),p=t.dedupeSigner(n,[s]),g=t.buildAndSignTx([e.ComputeBudgetProgram.setComputeUnitLimit({units:1e6}),d],n,c.blockhash,p);return await t.sendAndConfirmTx(i,g,h,c)},exports.compressSplTokenAccount=async function(i,n,r,o,s,a,u,m,h){h=h||await N.get_mint_program_id(r,i);const l=await N.compressSplTokenAccount({feePayer:n.publicKey,authority:o.publicKey,tokenAccount:s,mint:r,remainingAmount:u,outputStateTree:a,tokenProgramId:h}),d=await i.getLatestBlockhash(),c=t.dedupeSigner(n,[o]),p=t.buildAndSignTx([e.ComputeBudgetProgram.setComputeUnitLimit({units:1e6}),l],n,d.blockhash,c);return await t.sendAndConfirmTx(i,p,m,d)},exports.compressSplTokenAccountInstructionDataLayout=T,exports.createDecompressOutputState=R,exports.createMint=async function(n,r,o,s,a=e.Keypair.generate(),u,m,h){const l=await n.getMinimumBalanceForRentExemption(i.MINT_SIZE),d=1==m?i.TOKEN_2022_PROGRAM_ID:m||i.TOKEN_PROGRAM_ID,c=await N.createMint({feePayer:r.publicKey,mint:a.publicKey,decimals:s,authority:o,freezeAuthority:h||null,rentExemptBalance:l,tokenProgramId:d}),{blockhash:p}=await n.getLatestBlockhash(),g=t.dedupeSigner(r,[a]),f=t.buildAndSignTx(c,r,p,g),y=await t.sendAndConfirmTx(n,f,u);return{mint:a.publicKey,transactionSignature:y}},exports.createTokenPool=async function(e,i,n,r,o){o=o||await N.get_mint_program_id(n,e);const s=await N.createTokenPool({feePayer:i.publicKey,mint:n,tokenProgramId:o}),{blockhash:a}=await e.getLatestBlockhash(),u=t.buildAndSignTx([s],i,a);return await t.sendAndConfirmTx(e,u,r)},exports.createTokenPoolAccountsLayout=_,exports.createTokenProgramLookupTable=async function(e,i,n,r,o){const s=await e.getSlot("finalized"),{instructions:a,address:u}=await N.createTokenProgramLookupTable({payer:i.publicKey,authority:n.publicKey,mints:r,remainingAccounts:o,recentSlot:s}),m=t.dedupeSigner(i,[n]),h=await e.getLatestBlockhash(),l=t.buildAndSignTx([a[0]],i,h.blockhash,m),d=await t.sendAndConfirmTx(e,l,{commitment:"finalized"},h),c=await e.getLatestBlockhash(),p=t.buildAndSignTx([a[1]],i,c.blockhash,m);return{txIds:[d,await t.sendAndConfirmTx(e,p,{commitment:"finalized"},c)],address:u}},exports.createTransferOutputState=L,exports.decodeCompressSplTokenAccountInstructionData=function(t){const e=T.decode(t.slice(l.length));return{owner:e.owner,remainingAmount:e.remainingAmount,cpiContext:e.cpiContext}},exports.decodeMintToInstructionData=function(t){const e=A.decode(t.slice(m.length));return{recipients:e.recipients,amounts:e.amounts,lamports:e.lamports}},exports.decodeTransferInstructionData=function(t){return S.decode(t.slice(h.length+4))},exports.decompress=async function(i,n,r,o,s,a,u,m,h){h=h||await N.get_mint_program_id(r,i),o=t.bn(o);const l=await i.getCompressedTokenAccountsByOwner(s.publicKey,{mint:r}),[d]=W(l.items,o),c=await i.getValidityProof(d.map((e=>t.bn(e.compressedAccount.hash)))),p=await N.decompress({payer:n.publicKey,inputCompressedTokenAccounts:d,toAddress:a,amount:o,outputStateTree:u,recentInputStateRootIndices:c.rootIndices,recentValidityProof:c.compressedProof,tokenProgramId:h}),{blockhash:g}=await i.getLatestBlockhash(),f=t.dedupeSigner(n,[s]),y=t.buildAndSignTx([e.ComputeBudgetProgram.setComputeUnitLimit({units:1e6}),p],n,g,f);return await t.sendAndConfirmTx(i,y,m)},exports.encodeCompressSplTokenAccountInstructionData=I,exports.encodeMintToInstructionData=C,exports.encodeTransferInstructionData=x,exports.mergeTokenAccounts=async function(i,n,r,o,s,a){const u=await i.getCompressedTokenAccountsByOwner(o.publicKey,{mint:r});if(0===u.items.length)throw new Error(`No compressed token accounts found for mint ${r.toBase58()}`);if(u.items.length>=6)throw new Error(`Too many compressed token accounts used for mint ${r.toBase58()}`);const m=[e.ComputeBudgetProgram.setComputeUnitLimit({units:1e6})];for(let e=0;e<u.items.slice(0,6).length;e+=3){const a=u.items.slice(e,e+3),h=await i.getValidityProof(a.map((e=>t.bn(e.compressedAccount.hash)))),l=await N.mergeTokenAccounts({payer:n.publicKey,owner:o.publicKey,mint:r,inputCompressedTokenAccounts:a,outputStateTree:s,recentValidityProof:h.compressedProof,recentInputStateRootIndices:h.rootIndices});m.push(...l)}const{blockhash:h}=await i.getLatestBlockhash(),l=t.dedupeSigner(n,[o]),d=t.buildAndSignTx(m,n,h,l);return await t.sendAndConfirmTx(i,d,a)},exports.mintTo=async function(i,n,r,o,s,a,u,m,h){h=h||await N.get_mint_program_id(r,i);const l=t.dedupeSigner(n,[s]);if(!u){const e=await i.getCachedActiveStateTreeInfo(),{tree:n}=t.pickRandomTreeAndQueue(e);u=n}const d=await N.mintTo({feePayer:n.publicKey,mint:r,authority:s.publicKey,amount:a,toPubkey:o,merkleTree:u,tokenProgramId:h}),{blockhash:c}=await i.getLatestBlockhash(),p=t.buildAndSignTx([e.ComputeBudgetProgram.setComputeUnitLimit({units:1e6}),d],n,c,l);return await t.sendAndConfirmTx(i,p,m)},exports.mintToAccountsLayout=O,exports.mintToLayout=A,exports.packCompressedTokenAccounts=o,exports.parseTokenData=K,exports.selectMinCompressedTokenAccountsForTransfer=W,exports.sumUpTokenAmount=E,exports.transfer=async function(i,n,r,o,s,a,u,m){o=t.bn(o);const h=await i.getCompressedTokenAccountsByOwner(s.publicKey,{mint:r}),[l]=W(h.items,o),d=await i.getValidityProof(l.map((e=>t.bn(e.compressedAccount.hash)))),c=await N.transfer({payer:n.publicKey,inputCompressedTokenAccounts:l,toAddress:a,amount:o,recentInputStateRootIndices:d.rootIndices,recentValidityProof:d.compressedProof,outputStateTrees:u}),{blockhash:p}=await i.getLatestBlockhash(),g=t.dedupeSigner(n,[s]),f=t.buildAndSignTx([e.ComputeBudgetProgram.setComputeUnitLimit({units:1e6}),c],n,p,g);return await t.sendAndConfirmTx(i,f,m)},exports.transferAccountsLayout=D,exports.validateSameTokenOwner=B;
|
|
2
2
|
//# sourceMappingURL=index.cjs.map
|