@lightprotocol/stateless.js 0.21.0 → 0.22.1-alpha.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.
Files changed (77) hide show
  1. package/README.md +10 -10
  2. package/dist/cjs/browser/actions/compress.d.ts +2 -2
  3. package/dist/cjs/browser/actions/create-account.d.ts +3 -3
  4. package/dist/cjs/browser/actions/transfer.d.ts +1 -2
  5. package/dist/cjs/browser/compressible/action.d.ts +77 -0
  6. package/dist/cjs/browser/compressible/index.d.ts +13 -0
  7. package/dist/cjs/browser/compressible/instruction.d.ts +177 -0
  8. package/dist/cjs/browser/compressible/layout.d.ts +47 -0
  9. package/dist/cjs/browser/compressible/types.d.ts +112 -0
  10. package/dist/cjs/browser/compressible/utils.d.ts +16 -0
  11. package/dist/cjs/browser/constants.d.ts +31 -6
  12. package/dist/cjs/browser/index.cjs +1 -1
  13. package/dist/cjs/browser/index.cjs.map +1 -1
  14. package/dist/cjs/browser/index.d.ts +1 -2
  15. package/dist/cjs/browser/programs/index.d.ts +0 -1
  16. package/dist/cjs/browser/{idl.d.ts → programs/system/idl.d.ts} +5 -27
  17. package/dist/cjs/browser/programs/system/index.d.ts +5 -0
  18. package/dist/cjs/{node/programs → browser/programs/system}/layout.d.ts +10 -1
  19. package/dist/cjs/browser/programs/system/pack.d.ts +143 -0
  20. package/dist/cjs/browser/programs/{system.d.ts → system/program.d.ts} +13 -28
  21. package/dist/cjs/browser/programs/system/select-compressed-accounts.d.ts +10 -0
  22. package/dist/cjs/browser/rpc-interface.d.ts +1593 -51
  23. package/dist/cjs/browser/rpc.d.ts +31 -37
  24. package/dist/cjs/browser/state/compressed-account.d.ts +140 -6
  25. package/dist/cjs/browser/state/types.d.ts +265 -26
  26. package/dist/cjs/browser/test-helpers/test-rpc/get-compressed-accounts.d.ts +1 -10
  27. package/dist/cjs/browser/test-helpers/test-rpc/get-compressed-token-accounts.d.ts +2 -2
  28. package/dist/cjs/browser/test-helpers/test-rpc/test-rpc.d.ts +20 -40
  29. package/dist/cjs/browser/utils/address.d.ts +13 -0
  30. package/dist/cjs/browser/utils/calculate-compute-unit-price.d.ts +1 -1
  31. package/dist/cjs/browser/utils/conversion.d.ts +3 -0
  32. package/dist/cjs/browser/utils/get-state-tree-infos.d.ts +16 -9
  33. package/dist/cjs/browser/utils/index.d.ts +2 -2
  34. package/dist/cjs/browser/utils/packed-accounts.d.ts +161 -0
  35. package/dist/cjs/browser/utils/send-and-confirm.d.ts +1 -1
  36. package/dist/cjs/browser/utils/validation.d.ts +2 -2
  37. package/dist/cjs/node/actions/compress.d.ts +2 -2
  38. package/dist/cjs/node/actions/create-account.d.ts +3 -3
  39. package/dist/cjs/node/actions/transfer.d.ts +1 -2
  40. package/dist/cjs/node/compressible/action.d.ts +77 -0
  41. package/dist/cjs/node/compressible/index.d.ts +13 -0
  42. package/dist/cjs/node/compressible/instruction.d.ts +177 -0
  43. package/dist/cjs/node/compressible/layout.d.ts +47 -0
  44. package/dist/cjs/node/compressible/types.d.ts +112 -0
  45. package/dist/cjs/node/compressible/utils.d.ts +16 -0
  46. package/dist/cjs/node/constants.d.ts +31 -6
  47. package/dist/cjs/node/index.cjs +1 -1
  48. package/dist/cjs/node/index.cjs.map +1 -1
  49. package/dist/cjs/node/index.d.ts +1 -2
  50. package/dist/cjs/node/programs/index.d.ts +0 -1
  51. package/dist/cjs/node/{idl.d.ts → programs/system/idl.d.ts} +5 -27
  52. package/dist/cjs/node/programs/system/index.d.ts +5 -0
  53. package/dist/cjs/{browser/programs → node/programs/system}/layout.d.ts +10 -1
  54. package/dist/cjs/node/programs/system/pack.d.ts +143 -0
  55. package/dist/cjs/node/programs/{system.d.ts → system/program.d.ts} +13 -28
  56. package/dist/cjs/node/programs/system/select-compressed-accounts.d.ts +10 -0
  57. package/dist/cjs/node/rpc-interface.d.ts +1593 -51
  58. package/dist/cjs/node/rpc.d.ts +31 -37
  59. package/dist/cjs/node/state/compressed-account.d.ts +140 -6
  60. package/dist/cjs/node/state/types.d.ts +265 -26
  61. package/dist/cjs/node/test-helpers/test-rpc/get-compressed-accounts.d.ts +1 -10
  62. package/dist/cjs/node/test-helpers/test-rpc/get-compressed-token-accounts.d.ts +2 -2
  63. package/dist/cjs/node/test-helpers/test-rpc/test-rpc.d.ts +20 -40
  64. package/dist/cjs/node/utils/address.d.ts +13 -0
  65. package/dist/cjs/node/utils/calculate-compute-unit-price.d.ts +1 -1
  66. package/dist/cjs/node/utils/conversion.d.ts +3 -0
  67. package/dist/cjs/node/utils/get-state-tree-infos.d.ts +16 -9
  68. package/dist/cjs/node/utils/index.d.ts +2 -2
  69. package/dist/cjs/node/utils/packed-accounts.d.ts +161 -0
  70. package/dist/cjs/node/utils/send-and-confirm.d.ts +1 -1
  71. package/dist/cjs/node/utils/validation.d.ts +2 -2
  72. package/dist/types/index.d.ts +3391 -864
  73. package/package.json +13 -6
  74. package/dist/cjs/browser/instruction/index.d.ts +0 -1
  75. package/dist/cjs/browser/instruction/pack-compressed-accounts.d.ts +0 -49
  76. package/dist/cjs/node/instruction/index.d.ts +0 -1
  77. package/dist/cjs/node/instruction/pack-compressed-accounts.d.ts +0 -49
@@ -1,2 +1,2 @@
1
- "use strict";var e=require("@solana/web3.js"),t=require("buffer"),r="undefined"!=typeof globalThis?globalThis:"undefined"!=typeof window?window:"undefined"!=typeof global?global:"undefined"!=typeof self?self:{};function n(e){return e&&e.__esModule&&Object.prototype.hasOwnProperty.call(e,"default")?e.default:e}var o={exports:{}};!function(e,t){function r(e,t){if(!e)throw new Error(t||"Assertion failed")}function n(e,t){e.super_=t;var r=function(){};r.prototype=t.prototype,e.prototype=new r,e.prototype.constructor=e}function s(e,t,r){if(s.isBN(e))return e;this.negative=0,this.words=null,this.length=0,this.red=null,null!==e&&("le"!==t&&"be"!==t||(r=t,t=10),this._init(e||0,t||10,r||"be"))}var i;"object"==typeof o?o.exports=s:t.BN=s,s.BN=s,s.wordSize=26;try{i="undefined"!=typeof window&&void 0!==window.Buffer?window.Buffer:require("buffer").Buffer}catch(e){}function a(e,t){var n=e.charCodeAt(t);return n>=48&&n<=57?n-48:n>=65&&n<=70?n-55:n>=97&&n<=102?n-87:void r(0,"Invalid character in "+e)}function u(e,t,r){var n=a(e,r);return r-1>=t&&(n|=a(e,r-1)<<4),n}function c(e,t,n,o){for(var s=0,i=0,a=Math.min(e.length,n),u=t;u<a;u++){var c=e.charCodeAt(u)-48;s*=o,i=c>=49?c-49+10:c>=17?c-17+10:c,r(c>=0&&i<o,"Invalid character"),s+=i}return s}function l(e,t){e.words=t.words,e.length=t.length,e.negative=t.negative,e.red=t.red}if(s.isBN=function(e){return e instanceof s?1:null!==e&&"object"==typeof e&&e.constructor.wordSize===s.wordSize&&Array.isArray(e.words)},s.max=function(e,t){return e.cmp(t)>0?e:t},s.min=function(e,t){return e.cmp(t)<0?e:t},s.prototype._init=function(e,t,n){if("number"==typeof e)return this._initNumber(e,t,n);if("object"==typeof e)return this._initArray(e,t,n);"hex"===t&&(t=16),r(t===(0|t)&&t>=2&&t<=36);var o=0;"-"===(e=e.toString().replace(/\s+/g,""))[0]&&(o++,this.negative=1),o<e.length&&(16===t?this._parseHex(e,o,n):(this._parseBase(e,t,o),"le"===n&&this._initArray(this.toArray(),t,n)))},s.prototype._initNumber=function(e,t,n){e<0&&(this.negative=1,e=-e),e<67108864?(this.words=[67108863&e],this.length=1):e<4503599627370496?(this.words=[67108863&e,e/67108864&67108863],this.length=2):(r(e<9007199254740992),this.words=[67108863&e,e/67108864&67108863,1],this.length=3),"le"===n&&this._initArray(this.toArray(),t,n)},s.prototype._initArray=function(e,t,n){if(r("number"==typeof e.length),e.length<=0)return this.words=[0],this.length=1,this;this.length=Math.ceil(e.length/3),this.words=new Array(this.length);for(var o=0;o<this.length;o++)this.words[o]=0;var s,i,a=0;if("be"===n)for(o=e.length-1,s=0;o>=0;o-=3)i=e[o]|e[o-1]<<8|e[o-2]<<16,this.words[s]|=i<<a&67108863,this.words[s+1]=i>>>26-a&67108863,(a+=24)>=26&&(a-=26,s++);else if("le"===n)for(o=0,s=0;o<e.length;o+=3)i=e[o]|e[o+1]<<8|e[o+2]<<16,this.words[s]|=i<<a&67108863,this.words[s+1]=i>>>26-a&67108863,(a+=24)>=26&&(a-=26,s++);return this._strip()},s.prototype._parseHex=function(e,t,r){this.length=Math.ceil((e.length-t)/6),this.words=new Array(this.length);for(var n=0;n<this.length;n++)this.words[n]=0;var o,s=0,i=0;if("be"===r)for(n=e.length-1;n>=t;n-=2)o=u(e,t,n)<<s,this.words[i]|=67108863&o,s>=18?(s-=18,i+=1,this.words[i]|=o>>>26):s+=8;else for(n=(e.length-t)%2==0?t+1:t;n<e.length;n+=2)o=u(e,t,n)<<s,this.words[i]|=67108863&o,s>=18?(s-=18,i+=1,this.words[i]|=o>>>26):s+=8;this._strip()},s.prototype._parseBase=function(e,t,r){this.words=[0],this.length=1;for(var n=0,o=1;o<=67108863;o*=t)n++;n--,o=o/t|0;for(var s=e.length-r,i=s%n,a=Math.min(s,s-i)+r,u=0,l=r;l<a;l+=n)u=c(e,l,l+n,t),this.imuln(o),this.words[0]+u<67108864?this.words[0]+=u:this._iaddn(u);if(0!==i){var d=1;for(u=c(e,l,e.length,t),l=0;l<i;l++)d*=t;this.imuln(d),this.words[0]+u<67108864?this.words[0]+=u:this._iaddn(u)}this._strip()},s.prototype.copy=function(e){e.words=new Array(this.length);for(var t=0;t<this.length;t++)e.words[t]=this.words[t];e.length=this.length,e.negative=this.negative,e.red=this.red},s.prototype._move=function(e){l(e,this)},s.prototype.clone=function(){var e=new s(null);return this.copy(e),e},s.prototype._expand=function(e){for(;this.length<e;)this.words[this.length++]=0;return this},s.prototype._strip=function(){for(;this.length>1&&0===this.words[this.length-1];)this.length--;return this._normSign()},s.prototype._normSign=function(){return 1===this.length&&0===this.words[0]&&(this.negative=0),this},"undefined"!=typeof Symbol&&"function"==typeof Symbol.for)try{s.prototype[Symbol.for("nodejs.util.inspect.custom")]=d}catch(e){s.prototype.inspect=d}else s.prototype.inspect=d;function d(){return(this.red?"<BN-R: ":"<BN: ")+this.toString(16)+">"}var h=["","0","00","000","0000","00000","000000","0000000","00000000","000000000","0000000000","00000000000","000000000000","0000000000000","00000000000000","000000000000000","0000000000000000","00000000000000000","000000000000000000","0000000000000000000","00000000000000000000","000000000000000000000","0000000000000000000000","00000000000000000000000","000000000000000000000000","0000000000000000000000000"],p=[0,0,25,16,12,11,10,9,8,8,7,7,7,7,6,6,6,6,6,6,6,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5],f=[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 m(e,t,r){r.negative=t.negative^e.negative;var n=e.length+t.length|0;r.length=n,n=n-1|0;var o=0|e.words[0],s=0|t.words[0],i=o*s,a=67108863&i,u=i/67108864|0;r.words[0]=a;for(var c=1;c<n;c++){for(var l=u>>>26,d=67108863&u,h=Math.min(c,t.length-1),p=Math.max(0,c-e.length+1);p<=h;p++){var f=c-p|0;l+=(i=(o=0|e.words[f])*(s=0|t.words[p])+d)/67108864|0,d=67108863&i}r.words[c]=0|d,u=0|l}return 0!==u?r.words[c]=0|u:r.length--,r._strip()}s.prototype.toString=function(e,t){var n;if(t=0|t||1,16===(e=e||10)||"hex"===e){n="";for(var o=0,s=0,i=0;i<this.length;i++){var a=this.words[i],u=(16777215&(a<<o|s)).toString(16);s=a>>>24-o&16777215,(o+=2)>=26&&(o-=26,i--),n=0!==s||i!==this.length-1?h[6-u.length]+u+n:u+n}for(0!==s&&(n=s.toString(16)+n);n.length%t!=0;)n="0"+n;return 0!==this.negative&&(n="-"+n),n}if(e===(0|e)&&e>=2&&e<=36){var c=p[e],l=f[e];n="";var d=this.clone();for(d.negative=0;!d.isZero();){var m=d.modrn(l).toString(e);n=(d=d.idivn(l)).isZero()?m+n:h[c-m.length]+m+n}for(this.isZero()&&(n="0"+n);n.length%t!=0;)n="0"+n;return 0!==this.negative&&(n="-"+n),n}r(0,"Base should be between 2 and 36")},s.prototype.toNumber=function(){var e=this.words[0];return 2===this.length?e+=67108864*this.words[1]:3===this.length&&1===this.words[2]?e+=4503599627370496+67108864*this.words[1]:this.length>2&&r(0,"Number can only safely store up to 53 bits"),0!==this.negative?-e:e},s.prototype.toJSON=function(){return this.toString(16,2)},i&&(s.prototype.toBuffer=function(e,t){return this.toArrayLike(i,e,t)}),s.prototype.toArray=function(e,t){return this.toArrayLike(Array,e,t)},s.prototype.toArrayLike=function(e,t,n){this._strip();var o=this.byteLength(),s=n||Math.max(1,o);r(o<=s,"byte array longer than desired length"),r(s>0,"Requested array length <= 0");var i=function(e,t){return e.allocUnsafe?e.allocUnsafe(t):new e(t)}(e,s);return this["_toArrayLike"+("le"===t?"LE":"BE")](i,o),i},s.prototype._toArrayLikeLE=function(e){for(var t=0,r=0,n=0,o=0;n<this.length;n++){var s=this.words[n]<<o|r;e[t++]=255&s,t<e.length&&(e[t++]=s>>8&255),t<e.length&&(e[t++]=s>>16&255),6===o?(t<e.length&&(e[t++]=s>>24&255),r=0,o=0):(r=s>>>24,o+=2)}if(t<e.length)for(e[t++]=r;t<e.length;)e[t++]=0},s.prototype._toArrayLikeBE=function(e){for(var t=e.length-1,r=0,n=0,o=0;n<this.length;n++){var s=this.words[n]<<o|r;e[t--]=255&s,t>=0&&(e[t--]=s>>8&255),t>=0&&(e[t--]=s>>16&255),6===o?(t>=0&&(e[t--]=s>>24&255),r=0,o=0):(r=s>>>24,o+=2)}if(t>=0)for(e[t--]=r;t>=0;)e[t--]=0},Math.clz32?s.prototype._countBits=function(e){return 32-Math.clz32(e)}:s.prototype._countBits=function(e){var t=e,r=0;return t>=4096&&(r+=13,t>>>=13),t>=64&&(r+=7,t>>>=7),t>=8&&(r+=4,t>>>=4),t>=2&&(r+=2,t>>>=2),r+t},s.prototype._zeroBits=function(e){if(0===e)return 26;var t=e,r=0;return 0==(8191&t)&&(r+=13,t>>>=13),0==(127&t)&&(r+=7,t>>>=7),0==(15&t)&&(r+=4,t>>>=4),0==(3&t)&&(r+=2,t>>>=2),0==(1&t)&&r++,r},s.prototype.bitLength=function(){var e=this.words[this.length-1],t=this._countBits(e);return 26*(this.length-1)+t},s.prototype.zeroBits=function(){if(this.isZero())return 0;for(var e=0,t=0;t<this.length;t++){var r=this._zeroBits(this.words[t]);if(e+=r,26!==r)break}return e},s.prototype.byteLength=function(){return Math.ceil(this.bitLength()/8)},s.prototype.toTwos=function(e){return 0!==this.negative?this.abs().inotn(e).iaddn(1):this.clone()},s.prototype.fromTwos=function(e){return this.testn(e-1)?this.notn(e).iaddn(1).ineg():this.clone()},s.prototype.isNeg=function(){return 0!==this.negative},s.prototype.neg=function(){return this.clone().ineg()},s.prototype.ineg=function(){return this.isZero()||(this.negative^=1),this},s.prototype.iuor=function(e){for(;this.length<e.length;)this.words[this.length++]=0;for(var t=0;t<e.length;t++)this.words[t]=this.words[t]|e.words[t];return this._strip()},s.prototype.ior=function(e){return r(0==(this.negative|e.negative)),this.iuor(e)},s.prototype.or=function(e){return this.length>e.length?this.clone().ior(e):e.clone().ior(this)},s.prototype.uor=function(e){return this.length>e.length?this.clone().iuor(e):e.clone().iuor(this)},s.prototype.iuand=function(e){var t;t=this.length>e.length?e:this;for(var r=0;r<t.length;r++)this.words[r]=this.words[r]&e.words[r];return this.length=t.length,this._strip()},s.prototype.iand=function(e){return r(0==(this.negative|e.negative)),this.iuand(e)},s.prototype.and=function(e){return this.length>e.length?this.clone().iand(e):e.clone().iand(this)},s.prototype.uand=function(e){return this.length>e.length?this.clone().iuand(e):e.clone().iuand(this)},s.prototype.iuxor=function(e){var t,r;this.length>e.length?(t=this,r=e):(t=e,r=this);for(var n=0;n<r.length;n++)this.words[n]=t.words[n]^r.words[n];if(this!==t)for(;n<t.length;n++)this.words[n]=t.words[n];return this.length=t.length,this._strip()},s.prototype.ixor=function(e){return r(0==(this.negative|e.negative)),this.iuxor(e)},s.prototype.xor=function(e){return this.length>e.length?this.clone().ixor(e):e.clone().ixor(this)},s.prototype.uxor=function(e){return this.length>e.length?this.clone().iuxor(e):e.clone().iuxor(this)},s.prototype.inotn=function(e){r("number"==typeof e&&e>=0);var t=0|Math.ceil(e/26),n=e%26;this._expand(t),n>0&&t--;for(var o=0;o<t;o++)this.words[o]=67108863&~this.words[o];return n>0&&(this.words[o]=~this.words[o]&67108863>>26-n),this._strip()},s.prototype.notn=function(e){return this.clone().inotn(e)},s.prototype.setn=function(e,t){r("number"==typeof e&&e>=0);var n=e/26|0,o=e%26;return this._expand(n+1),this.words[n]=t?this.words[n]|1<<o:this.words[n]&~(1<<o),this._strip()},s.prototype.iadd=function(e){var t,r,n;if(0!==this.negative&&0===e.negative)return this.negative=0,t=this.isub(e),this.negative^=1,this._normSign();if(0===this.negative&&0!==e.negative)return e.negative=0,t=this.isub(e),e.negative=1,t._normSign();this.length>e.length?(r=this,n=e):(r=e,n=this);for(var o=0,s=0;s<n.length;s++)t=(0|r.words[s])+(0|n.words[s])+o,this.words[s]=67108863&t,o=t>>>26;for(;0!==o&&s<r.length;s++)t=(0|r.words[s])+o,this.words[s]=67108863&t,o=t>>>26;if(this.length=r.length,0!==o)this.words[this.length]=o,this.length++;else if(r!==this)for(;s<r.length;s++)this.words[s]=r.words[s];return this},s.prototype.add=function(e){var t;return 0!==e.negative&&0===this.negative?(e.negative=0,t=this.sub(e),e.negative^=1,t):0===e.negative&&0!==this.negative?(this.negative=0,t=e.sub(this),this.negative=1,t):this.length>e.length?this.clone().iadd(e):e.clone().iadd(this)},s.prototype.isub=function(e){if(0!==e.negative){e.negative=0;var t=this.iadd(e);return e.negative=1,t._normSign()}if(0!==this.negative)return this.negative=0,this.iadd(e),this.negative=1,this._normSign();var r,n,o=this.cmp(e);if(0===o)return this.negative=0,this.length=1,this.words[0]=0,this;o>0?(r=this,n=e):(r=e,n=this);for(var s=0,i=0;i<n.length;i++)s=(t=(0|r.words[i])-(0|n.words[i])+s)>>26,this.words[i]=67108863&t;for(;0!==s&&i<r.length;i++)s=(t=(0|r.words[i])+s)>>26,this.words[i]=67108863&t;if(0===s&&i<r.length&&r!==this)for(;i<r.length;i++)this.words[i]=r.words[i];return this.length=Math.max(this.length,i),r!==this&&(this.negative=1),this._strip()},s.prototype.sub=function(e){return this.clone().isub(e)};var g=function(e,t,r){var n,o,s,i=e.words,a=t.words,u=r.words,c=0,l=0|i[0],d=8191&l,h=l>>>13,p=0|i[1],f=8191&p,m=p>>>13,g=0|i[2],y=8191&g,w=g>>>13,v=0|i[3],x=8191&v,b=v>>>13,E=0|i[4],I=8191&E,M=E>>>13,A=0|i[5],T=8191&A,S=A>>>13,C=0|i[6],k=8191&C,_=C>>>13,P=0|i[7],L=8191&P,N=P>>>13,O=0|i[8],B=8191&O,R=O>>>13,D=0|i[9],U=8191&D,F=D>>>13,q=0|a[0],V=8191&q,K=q>>>13,H=0|a[1],$=8191&H,j=H>>>13,z=0|a[2],W=8191&z,Z=z>>>13,J=0|a[3],Q=8191&J,G=J>>>13,X=0|a[4],Y=8191&X,ee=X>>>13,te=0|a[5],re=8191&te,ne=te>>>13,oe=0|a[6],se=8191&oe,ie=oe>>>13,ae=0|a[7],ue=8191&ae,ce=ae>>>13,le=0|a[8],de=8191&le,he=le>>>13,pe=0|a[9],fe=8191&pe,me=pe>>>13;r.negative=e.negative^t.negative,r.length=19;var ge=(c+(n=Math.imul(d,V))|0)+((8191&(o=(o=Math.imul(d,K))+Math.imul(h,V)|0))<<13)|0;c=((s=Math.imul(h,K))+(o>>>13)|0)+(ge>>>26)|0,ge&=67108863,n=Math.imul(f,V),o=(o=Math.imul(f,K))+Math.imul(m,V)|0,s=Math.imul(m,K);var ye=(c+(n=n+Math.imul(d,$)|0)|0)+((8191&(o=(o=o+Math.imul(d,j)|0)+Math.imul(h,$)|0))<<13)|0;c=((s=s+Math.imul(h,j)|0)+(o>>>13)|0)+(ye>>>26)|0,ye&=67108863,n=Math.imul(y,V),o=(o=Math.imul(y,K))+Math.imul(w,V)|0,s=Math.imul(w,K),n=n+Math.imul(f,$)|0,o=(o=o+Math.imul(f,j)|0)+Math.imul(m,$)|0,s=s+Math.imul(m,j)|0;var we=(c+(n=n+Math.imul(d,W)|0)|0)+((8191&(o=(o=o+Math.imul(d,Z)|0)+Math.imul(h,W)|0))<<13)|0;c=((s=s+Math.imul(h,Z)|0)+(o>>>13)|0)+(we>>>26)|0,we&=67108863,n=Math.imul(x,V),o=(o=Math.imul(x,K))+Math.imul(b,V)|0,s=Math.imul(b,K),n=n+Math.imul(y,$)|0,o=(o=o+Math.imul(y,j)|0)+Math.imul(w,$)|0,s=s+Math.imul(w,j)|0,n=n+Math.imul(f,W)|0,o=(o=o+Math.imul(f,Z)|0)+Math.imul(m,W)|0,s=s+Math.imul(m,Z)|0;var ve=(c+(n=n+Math.imul(d,Q)|0)|0)+((8191&(o=(o=o+Math.imul(d,G)|0)+Math.imul(h,Q)|0))<<13)|0;c=((s=s+Math.imul(h,G)|0)+(o>>>13)|0)+(ve>>>26)|0,ve&=67108863,n=Math.imul(I,V),o=(o=Math.imul(I,K))+Math.imul(M,V)|0,s=Math.imul(M,K),n=n+Math.imul(x,$)|0,o=(o=o+Math.imul(x,j)|0)+Math.imul(b,$)|0,s=s+Math.imul(b,j)|0,n=n+Math.imul(y,W)|0,o=(o=o+Math.imul(y,Z)|0)+Math.imul(w,W)|0,s=s+Math.imul(w,Z)|0,n=n+Math.imul(f,Q)|0,o=(o=o+Math.imul(f,G)|0)+Math.imul(m,Q)|0,s=s+Math.imul(m,G)|0;var xe=(c+(n=n+Math.imul(d,Y)|0)|0)+((8191&(o=(o=o+Math.imul(d,ee)|0)+Math.imul(h,Y)|0))<<13)|0;c=((s=s+Math.imul(h,ee)|0)+(o>>>13)|0)+(xe>>>26)|0,xe&=67108863,n=Math.imul(T,V),o=(o=Math.imul(T,K))+Math.imul(S,V)|0,s=Math.imul(S,K),n=n+Math.imul(I,$)|0,o=(o=o+Math.imul(I,j)|0)+Math.imul(M,$)|0,s=s+Math.imul(M,j)|0,n=n+Math.imul(x,W)|0,o=(o=o+Math.imul(x,Z)|0)+Math.imul(b,W)|0,s=s+Math.imul(b,Z)|0,n=n+Math.imul(y,Q)|0,o=(o=o+Math.imul(y,G)|0)+Math.imul(w,Q)|0,s=s+Math.imul(w,G)|0,n=n+Math.imul(f,Y)|0,o=(o=o+Math.imul(f,ee)|0)+Math.imul(m,Y)|0,s=s+Math.imul(m,ee)|0;var be=(c+(n=n+Math.imul(d,re)|0)|0)+((8191&(o=(o=o+Math.imul(d,ne)|0)+Math.imul(h,re)|0))<<13)|0;c=((s=s+Math.imul(h,ne)|0)+(o>>>13)|0)+(be>>>26)|0,be&=67108863,n=Math.imul(k,V),o=(o=Math.imul(k,K))+Math.imul(_,V)|0,s=Math.imul(_,K),n=n+Math.imul(T,$)|0,o=(o=o+Math.imul(T,j)|0)+Math.imul(S,$)|0,s=s+Math.imul(S,j)|0,n=n+Math.imul(I,W)|0,o=(o=o+Math.imul(I,Z)|0)+Math.imul(M,W)|0,s=s+Math.imul(M,Z)|0,n=n+Math.imul(x,Q)|0,o=(o=o+Math.imul(x,G)|0)+Math.imul(b,Q)|0,s=s+Math.imul(b,G)|0,n=n+Math.imul(y,Y)|0,o=(o=o+Math.imul(y,ee)|0)+Math.imul(w,Y)|0,s=s+Math.imul(w,ee)|0,n=n+Math.imul(f,re)|0,o=(o=o+Math.imul(f,ne)|0)+Math.imul(m,re)|0,s=s+Math.imul(m,ne)|0;var Ee=(c+(n=n+Math.imul(d,se)|0)|0)+((8191&(o=(o=o+Math.imul(d,ie)|0)+Math.imul(h,se)|0))<<13)|0;c=((s=s+Math.imul(h,ie)|0)+(o>>>13)|0)+(Ee>>>26)|0,Ee&=67108863,n=Math.imul(L,V),o=(o=Math.imul(L,K))+Math.imul(N,V)|0,s=Math.imul(N,K),n=n+Math.imul(k,$)|0,o=(o=o+Math.imul(k,j)|0)+Math.imul(_,$)|0,s=s+Math.imul(_,j)|0,n=n+Math.imul(T,W)|0,o=(o=o+Math.imul(T,Z)|0)+Math.imul(S,W)|0,s=s+Math.imul(S,Z)|0,n=n+Math.imul(I,Q)|0,o=(o=o+Math.imul(I,G)|0)+Math.imul(M,Q)|0,s=s+Math.imul(M,G)|0,n=n+Math.imul(x,Y)|0,o=(o=o+Math.imul(x,ee)|0)+Math.imul(b,Y)|0,s=s+Math.imul(b,ee)|0,n=n+Math.imul(y,re)|0,o=(o=o+Math.imul(y,ne)|0)+Math.imul(w,re)|0,s=s+Math.imul(w,ne)|0,n=n+Math.imul(f,se)|0,o=(o=o+Math.imul(f,ie)|0)+Math.imul(m,se)|0,s=s+Math.imul(m,ie)|0;var Ie=(c+(n=n+Math.imul(d,ue)|0)|0)+((8191&(o=(o=o+Math.imul(d,ce)|0)+Math.imul(h,ue)|0))<<13)|0;c=((s=s+Math.imul(h,ce)|0)+(o>>>13)|0)+(Ie>>>26)|0,Ie&=67108863,n=Math.imul(B,V),o=(o=Math.imul(B,K))+Math.imul(R,V)|0,s=Math.imul(R,K),n=n+Math.imul(L,$)|0,o=(o=o+Math.imul(L,j)|0)+Math.imul(N,$)|0,s=s+Math.imul(N,j)|0,n=n+Math.imul(k,W)|0,o=(o=o+Math.imul(k,Z)|0)+Math.imul(_,W)|0,s=s+Math.imul(_,Z)|0,n=n+Math.imul(T,Q)|0,o=(o=o+Math.imul(T,G)|0)+Math.imul(S,Q)|0,s=s+Math.imul(S,G)|0,n=n+Math.imul(I,Y)|0,o=(o=o+Math.imul(I,ee)|0)+Math.imul(M,Y)|0,s=s+Math.imul(M,ee)|0,n=n+Math.imul(x,re)|0,o=(o=o+Math.imul(x,ne)|0)+Math.imul(b,re)|0,s=s+Math.imul(b,ne)|0,n=n+Math.imul(y,se)|0,o=(o=o+Math.imul(y,ie)|0)+Math.imul(w,se)|0,s=s+Math.imul(w,ie)|0,n=n+Math.imul(f,ue)|0,o=(o=o+Math.imul(f,ce)|0)+Math.imul(m,ue)|0,s=s+Math.imul(m,ce)|0;var Me=(c+(n=n+Math.imul(d,de)|0)|0)+((8191&(o=(o=o+Math.imul(d,he)|0)+Math.imul(h,de)|0))<<13)|0;c=((s=s+Math.imul(h,he)|0)+(o>>>13)|0)+(Me>>>26)|0,Me&=67108863,n=Math.imul(U,V),o=(o=Math.imul(U,K))+Math.imul(F,V)|0,s=Math.imul(F,K),n=n+Math.imul(B,$)|0,o=(o=o+Math.imul(B,j)|0)+Math.imul(R,$)|0,s=s+Math.imul(R,j)|0,n=n+Math.imul(L,W)|0,o=(o=o+Math.imul(L,Z)|0)+Math.imul(N,W)|0,s=s+Math.imul(N,Z)|0,n=n+Math.imul(k,Q)|0,o=(o=o+Math.imul(k,G)|0)+Math.imul(_,Q)|0,s=s+Math.imul(_,G)|0,n=n+Math.imul(T,Y)|0,o=(o=o+Math.imul(T,ee)|0)+Math.imul(S,Y)|0,s=s+Math.imul(S,ee)|0,n=n+Math.imul(I,re)|0,o=(o=o+Math.imul(I,ne)|0)+Math.imul(M,re)|0,s=s+Math.imul(M,ne)|0,n=n+Math.imul(x,se)|0,o=(o=o+Math.imul(x,ie)|0)+Math.imul(b,se)|0,s=s+Math.imul(b,ie)|0,n=n+Math.imul(y,ue)|0,o=(o=o+Math.imul(y,ce)|0)+Math.imul(w,ue)|0,s=s+Math.imul(w,ce)|0,n=n+Math.imul(f,de)|0,o=(o=o+Math.imul(f,he)|0)+Math.imul(m,de)|0,s=s+Math.imul(m,he)|0;var Ae=(c+(n=n+Math.imul(d,fe)|0)|0)+((8191&(o=(o=o+Math.imul(d,me)|0)+Math.imul(h,fe)|0))<<13)|0;c=((s=s+Math.imul(h,me)|0)+(o>>>13)|0)+(Ae>>>26)|0,Ae&=67108863,n=Math.imul(U,$),o=(o=Math.imul(U,j))+Math.imul(F,$)|0,s=Math.imul(F,j),n=n+Math.imul(B,W)|0,o=(o=o+Math.imul(B,Z)|0)+Math.imul(R,W)|0,s=s+Math.imul(R,Z)|0,n=n+Math.imul(L,Q)|0,o=(o=o+Math.imul(L,G)|0)+Math.imul(N,Q)|0,s=s+Math.imul(N,G)|0,n=n+Math.imul(k,Y)|0,o=(o=o+Math.imul(k,ee)|0)+Math.imul(_,Y)|0,s=s+Math.imul(_,ee)|0,n=n+Math.imul(T,re)|0,o=(o=o+Math.imul(T,ne)|0)+Math.imul(S,re)|0,s=s+Math.imul(S,ne)|0,n=n+Math.imul(I,se)|0,o=(o=o+Math.imul(I,ie)|0)+Math.imul(M,se)|0,s=s+Math.imul(M,ie)|0,n=n+Math.imul(x,ue)|0,o=(o=o+Math.imul(x,ce)|0)+Math.imul(b,ue)|0,s=s+Math.imul(b,ce)|0,n=n+Math.imul(y,de)|0,o=(o=o+Math.imul(y,he)|0)+Math.imul(w,de)|0,s=s+Math.imul(w,he)|0;var Te=(c+(n=n+Math.imul(f,fe)|0)|0)+((8191&(o=(o=o+Math.imul(f,me)|0)+Math.imul(m,fe)|0))<<13)|0;c=((s=s+Math.imul(m,me)|0)+(o>>>13)|0)+(Te>>>26)|0,Te&=67108863,n=Math.imul(U,W),o=(o=Math.imul(U,Z))+Math.imul(F,W)|0,s=Math.imul(F,Z),n=n+Math.imul(B,Q)|0,o=(o=o+Math.imul(B,G)|0)+Math.imul(R,Q)|0,s=s+Math.imul(R,G)|0,n=n+Math.imul(L,Y)|0,o=(o=o+Math.imul(L,ee)|0)+Math.imul(N,Y)|0,s=s+Math.imul(N,ee)|0,n=n+Math.imul(k,re)|0,o=(o=o+Math.imul(k,ne)|0)+Math.imul(_,re)|0,s=s+Math.imul(_,ne)|0,n=n+Math.imul(T,se)|0,o=(o=o+Math.imul(T,ie)|0)+Math.imul(S,se)|0,s=s+Math.imul(S,ie)|0,n=n+Math.imul(I,ue)|0,o=(o=o+Math.imul(I,ce)|0)+Math.imul(M,ue)|0,s=s+Math.imul(M,ce)|0,n=n+Math.imul(x,de)|0,o=(o=o+Math.imul(x,he)|0)+Math.imul(b,de)|0,s=s+Math.imul(b,he)|0;var Se=(c+(n=n+Math.imul(y,fe)|0)|0)+((8191&(o=(o=o+Math.imul(y,me)|0)+Math.imul(w,fe)|0))<<13)|0;c=((s=s+Math.imul(w,me)|0)+(o>>>13)|0)+(Se>>>26)|0,Se&=67108863,n=Math.imul(U,Q),o=(o=Math.imul(U,G))+Math.imul(F,Q)|0,s=Math.imul(F,G),n=n+Math.imul(B,Y)|0,o=(o=o+Math.imul(B,ee)|0)+Math.imul(R,Y)|0,s=s+Math.imul(R,ee)|0,n=n+Math.imul(L,re)|0,o=(o=o+Math.imul(L,ne)|0)+Math.imul(N,re)|0,s=s+Math.imul(N,ne)|0,n=n+Math.imul(k,se)|0,o=(o=o+Math.imul(k,ie)|0)+Math.imul(_,se)|0,s=s+Math.imul(_,ie)|0,n=n+Math.imul(T,ue)|0,o=(o=o+Math.imul(T,ce)|0)+Math.imul(S,ue)|0,s=s+Math.imul(S,ce)|0,n=n+Math.imul(I,de)|0,o=(o=o+Math.imul(I,he)|0)+Math.imul(M,de)|0,s=s+Math.imul(M,he)|0;var Ce=(c+(n=n+Math.imul(x,fe)|0)|0)+((8191&(o=(o=o+Math.imul(x,me)|0)+Math.imul(b,fe)|0))<<13)|0;c=((s=s+Math.imul(b,me)|0)+(o>>>13)|0)+(Ce>>>26)|0,Ce&=67108863,n=Math.imul(U,Y),o=(o=Math.imul(U,ee))+Math.imul(F,Y)|0,s=Math.imul(F,ee),n=n+Math.imul(B,re)|0,o=(o=o+Math.imul(B,ne)|0)+Math.imul(R,re)|0,s=s+Math.imul(R,ne)|0,n=n+Math.imul(L,se)|0,o=(o=o+Math.imul(L,ie)|0)+Math.imul(N,se)|0,s=s+Math.imul(N,ie)|0,n=n+Math.imul(k,ue)|0,o=(o=o+Math.imul(k,ce)|0)+Math.imul(_,ue)|0,s=s+Math.imul(_,ce)|0,n=n+Math.imul(T,de)|0,o=(o=o+Math.imul(T,he)|0)+Math.imul(S,de)|0,s=s+Math.imul(S,he)|0;var ke=(c+(n=n+Math.imul(I,fe)|0)|0)+((8191&(o=(o=o+Math.imul(I,me)|0)+Math.imul(M,fe)|0))<<13)|0;c=((s=s+Math.imul(M,me)|0)+(o>>>13)|0)+(ke>>>26)|0,ke&=67108863,n=Math.imul(U,re),o=(o=Math.imul(U,ne))+Math.imul(F,re)|0,s=Math.imul(F,ne),n=n+Math.imul(B,se)|0,o=(o=o+Math.imul(B,ie)|0)+Math.imul(R,se)|0,s=s+Math.imul(R,ie)|0,n=n+Math.imul(L,ue)|0,o=(o=o+Math.imul(L,ce)|0)+Math.imul(N,ue)|0,s=s+Math.imul(N,ce)|0,n=n+Math.imul(k,de)|0,o=(o=o+Math.imul(k,he)|0)+Math.imul(_,de)|0,s=s+Math.imul(_,he)|0;var _e=(c+(n=n+Math.imul(T,fe)|0)|0)+((8191&(o=(o=o+Math.imul(T,me)|0)+Math.imul(S,fe)|0))<<13)|0;c=((s=s+Math.imul(S,me)|0)+(o>>>13)|0)+(_e>>>26)|0,_e&=67108863,n=Math.imul(U,se),o=(o=Math.imul(U,ie))+Math.imul(F,se)|0,s=Math.imul(F,ie),n=n+Math.imul(B,ue)|0,o=(o=o+Math.imul(B,ce)|0)+Math.imul(R,ue)|0,s=s+Math.imul(R,ce)|0,n=n+Math.imul(L,de)|0,o=(o=o+Math.imul(L,he)|0)+Math.imul(N,de)|0,s=s+Math.imul(N,he)|0;var Pe=(c+(n=n+Math.imul(k,fe)|0)|0)+((8191&(o=(o=o+Math.imul(k,me)|0)+Math.imul(_,fe)|0))<<13)|0;c=((s=s+Math.imul(_,me)|0)+(o>>>13)|0)+(Pe>>>26)|0,Pe&=67108863,n=Math.imul(U,ue),o=(o=Math.imul(U,ce))+Math.imul(F,ue)|0,s=Math.imul(F,ce),n=n+Math.imul(B,de)|0,o=(o=o+Math.imul(B,he)|0)+Math.imul(R,de)|0,s=s+Math.imul(R,he)|0;var Le=(c+(n=n+Math.imul(L,fe)|0)|0)+((8191&(o=(o=o+Math.imul(L,me)|0)+Math.imul(N,fe)|0))<<13)|0;c=((s=s+Math.imul(N,me)|0)+(o>>>13)|0)+(Le>>>26)|0,Le&=67108863,n=Math.imul(U,de),o=(o=Math.imul(U,he))+Math.imul(F,de)|0,s=Math.imul(F,he);var Ne=(c+(n=n+Math.imul(B,fe)|0)|0)+((8191&(o=(o=o+Math.imul(B,me)|0)+Math.imul(R,fe)|0))<<13)|0;c=((s=s+Math.imul(R,me)|0)+(o>>>13)|0)+(Ne>>>26)|0,Ne&=67108863;var Oe=(c+(n=Math.imul(U,fe))|0)+((8191&(o=(o=Math.imul(U,me))+Math.imul(F,fe)|0))<<13)|0;return c=((s=Math.imul(F,me))+(o>>>13)|0)+(Oe>>>26)|0,Oe&=67108863,u[0]=ge,u[1]=ye,u[2]=we,u[3]=ve,u[4]=xe,u[5]=be,u[6]=Ee,u[7]=Ie,u[8]=Me,u[9]=Ae,u[10]=Te,u[11]=Se,u[12]=Ce,u[13]=ke,u[14]=_e,u[15]=Pe,u[16]=Le,u[17]=Ne,u[18]=Oe,0!==c&&(u[19]=c,r.length++),r};function y(e,t,r){r.negative=t.negative^e.negative,r.length=e.length+t.length;for(var n=0,o=0,s=0;s<r.length-1;s++){var i=o;o=0;for(var a=67108863&n,u=Math.min(s,t.length-1),c=Math.max(0,s-e.length+1);c<=u;c++){var l=s-c,d=(0|e.words[l])*(0|t.words[c]),h=67108863&d;a=67108863&(h=h+a|0),o+=(i=(i=i+(d/67108864|0)|0)+(h>>>26)|0)>>>26,i&=67108863}r.words[s]=a,n=i,i=o}return 0!==n?r.words[s]=n:r.length--,r._strip()}function w(e,t,r){return y(e,t,r)}Math.imul||(g=m),s.prototype.mulTo=function(e,t){var r=this.length+e.length;return 10===this.length&&10===e.length?g(this,e,t):r<63?m(this,e,t):r<1024?y(this,e,t):w(this,e,t)},s.prototype.mul=function(e){var t=new s(null);return t.words=new Array(this.length+e.length),this.mulTo(e,t)},s.prototype.mulf=function(e){var t=new s(null);return t.words=new Array(this.length+e.length),w(this,e,t)},s.prototype.imul=function(e){return this.clone().mulTo(e,this)},s.prototype.imuln=function(e){var t=e<0;t&&(e=-e),r("number"==typeof e),r(e<67108864);for(var n=0,o=0;o<this.length;o++){var s=(0|this.words[o])*e,i=(67108863&s)+(67108863&n);n>>=26,n+=s/67108864|0,n+=i>>>26,this.words[o]=67108863&i}return 0!==n&&(this.words[o]=n,this.length++),t?this.ineg():this},s.prototype.muln=function(e){return this.clone().imuln(e)},s.prototype.sqr=function(){return this.mul(this)},s.prototype.isqr=function(){return this.imul(this.clone())},s.prototype.pow=function(e){var t=function(e){for(var t=new Array(e.bitLength()),r=0;r<t.length;r++){var n=r/26|0,o=r%26;t[r]=e.words[n]>>>o&1}return t}(e);if(0===t.length)return new s(1);for(var r=this,n=0;n<t.length&&0===t[n];n++,r=r.sqr());if(++n<t.length)for(var o=r.sqr();n<t.length;n++,o=o.sqr())0!==t[n]&&(r=r.mul(o));return r},s.prototype.iushln=function(e){r("number"==typeof e&&e>=0);var t,n=e%26,o=(e-n)/26,s=67108863>>>26-n<<26-n;if(0!==n){var i=0;for(t=0;t<this.length;t++){var a=this.words[t]&s,u=(0|this.words[t])-a<<n;this.words[t]=u|i,i=a>>>26-n}i&&(this.words[t]=i,this.length++)}if(0!==o){for(t=this.length-1;t>=0;t--)this.words[t+o]=this.words[t];for(t=0;t<o;t++)this.words[t]=0;this.length+=o}return this._strip()},s.prototype.ishln=function(e){return r(0===this.negative),this.iushln(e)},s.prototype.iushrn=function(e,t,n){var o;r("number"==typeof e&&e>=0),o=t?(t-t%26)/26:0;var s=e%26,i=Math.min((e-s)/26,this.length),a=67108863^67108863>>>s<<s,u=n;if(o-=i,o=Math.max(0,o),u){for(var c=0;c<i;c++)u.words[c]=this.words[c];u.length=i}if(0===i);else if(this.length>i)for(this.length-=i,c=0;c<this.length;c++)this.words[c]=this.words[c+i];else this.words[0]=0,this.length=1;var l=0;for(c=this.length-1;c>=0&&(0!==l||c>=o);c--){var d=0|this.words[c];this.words[c]=l<<26-s|d>>>s,l=d&a}return u&&0!==l&&(u.words[u.length++]=l),0===this.length&&(this.words[0]=0,this.length=1),this._strip()},s.prototype.ishrn=function(e,t,n){return r(0===this.negative),this.iushrn(e,t,n)},s.prototype.shln=function(e){return this.clone().ishln(e)},s.prototype.ushln=function(e){return this.clone().iushln(e)},s.prototype.shrn=function(e){return this.clone().ishrn(e)},s.prototype.ushrn=function(e){return this.clone().iushrn(e)},s.prototype.testn=function(e){r("number"==typeof e&&e>=0);var t=e%26,n=(e-t)/26,o=1<<t;return this.length<=n?0:!!(this.words[n]&o)},s.prototype.imaskn=function(e){r("number"==typeof e&&e>=0);var t=e%26,n=(e-t)/26;if(r(0===this.negative,"imaskn works only with positive numbers"),this.length<=n)return this;if(0!==t&&n++,this.length=Math.min(n,this.length),0!==t){var o=67108863^67108863>>>t<<t;this.words[this.length-1]&=o}return this._strip()},s.prototype.maskn=function(e){return this.clone().imaskn(e)},s.prototype.iaddn=function(e){return r("number"==typeof e),r(e<67108864),e<0?this.isubn(-e):0!==this.negative?1===this.length&&(0|this.words[0])<=e?(this.words[0]=e-(0|this.words[0]),this.negative=0,this):(this.negative=0,this.isubn(e),this.negative=1,this):this._iaddn(e)},s.prototype._iaddn=function(e){this.words[0]+=e;for(var t=0;t<this.length&&this.words[t]>=67108864;t++)this.words[t]-=67108864,t===this.length-1?this.words[t+1]=1:this.words[t+1]++;return this.length=Math.max(this.length,t+1),this},s.prototype.isubn=function(e){if(r("number"==typeof e),r(e<67108864),e<0)return this.iaddn(-e);if(0!==this.negative)return this.negative=0,this.iaddn(e),this.negative=1,this;if(this.words[0]-=e,1===this.length&&this.words[0]<0)this.words[0]=-this.words[0],this.negative=1;else for(var t=0;t<this.length&&this.words[t]<0;t++)this.words[t]+=67108864,this.words[t+1]-=1;return this._strip()},s.prototype.addn=function(e){return this.clone().iaddn(e)},s.prototype.subn=function(e){return this.clone().isubn(e)},s.prototype.iabs=function(){return this.negative=0,this},s.prototype.abs=function(){return this.clone().iabs()},s.prototype._ishlnsubmul=function(e,t,n){var o,s,i=e.length+n;this._expand(i);var a=0;for(o=0;o<e.length;o++){s=(0|this.words[o+n])+a;var u=(0|e.words[o])*t;a=((s-=67108863&u)>>26)-(u/67108864|0),this.words[o+n]=67108863&s}for(;o<this.length-n;o++)a=(s=(0|this.words[o+n])+a)>>26,this.words[o+n]=67108863&s;if(0===a)return this._strip();for(r(-1===a),a=0,o=0;o<this.length;o++)a=(s=-(0|this.words[o])+a)>>26,this.words[o]=67108863&s;return this.negative=1,this._strip()},s.prototype._wordDiv=function(e,t){var r=(this.length,e.length),n=this.clone(),o=e,i=0|o.words[o.length-1];0!=(r=26-this._countBits(i))&&(o=o.ushln(r),n.iushln(r),i=0|o.words[o.length-1]);var a,u=n.length-o.length;if("mod"!==t){(a=new s(null)).length=u+1,a.words=new Array(a.length);for(var c=0;c<a.length;c++)a.words[c]=0}var l=n.clone()._ishlnsubmul(o,1,u);0===l.negative&&(n=l,a&&(a.words[u]=1));for(var d=u-1;d>=0;d--){var h=67108864*(0|n.words[o.length+d])+(0|n.words[o.length+d-1]);for(h=Math.min(h/i|0,67108863),n._ishlnsubmul(o,h,d);0!==n.negative;)h--,n.negative=0,n._ishlnsubmul(o,1,d),n.isZero()||(n.negative^=1);a&&(a.words[d]=h)}return a&&a._strip(),n._strip(),"div"!==t&&0!==r&&n.iushrn(r),{div:a||null,mod:n}},s.prototype.divmod=function(e,t,n){return r(!e.isZero()),this.isZero()?{div:new s(0),mod:new s(0)}:0!==this.negative&&0===e.negative?(a=this.neg().divmod(e,t),"mod"!==t&&(o=a.div.neg()),"div"!==t&&(i=a.mod.neg(),n&&0!==i.negative&&i.iadd(e)),{div:o,mod:i}):0===this.negative&&0!==e.negative?(a=this.divmod(e.neg(),t),"mod"!==t&&(o=a.div.neg()),{div:o,mod:a.mod}):0!=(this.negative&e.negative)?(a=this.neg().divmod(e.neg(),t),"div"!==t&&(i=a.mod.neg(),n&&0!==i.negative&&i.isub(e)),{div:a.div,mod:i}):e.length>this.length||this.cmp(e)<0?{div:new s(0),mod:this}:1===e.length?"div"===t?{div:this.divn(e.words[0]),mod:null}:"mod"===t?{div:null,mod:new s(this.modrn(e.words[0]))}:{div:this.divn(e.words[0]),mod:new s(this.modrn(e.words[0]))}:this._wordDiv(e,t);var o,i,a},s.prototype.div=function(e){return this.divmod(e,"div",0).div},s.prototype.mod=function(e){return this.divmod(e,"mod",0).mod},s.prototype.umod=function(e){return this.divmod(e,"mod",1).mod},s.prototype.divRound=function(e){var t=this.divmod(e);if(t.mod.isZero())return t.div;var r=0!==t.div.negative?t.mod.isub(e):t.mod,n=e.ushrn(1),o=e.andln(1),s=r.cmp(n);return s<0||1===o&&0===s?t.div:0!==t.div.negative?t.div.isubn(1):t.div.iaddn(1)},s.prototype.modrn=function(e){var t=e<0;t&&(e=-e),r(e<=67108863);for(var n=(1<<26)%e,o=0,s=this.length-1;s>=0;s--)o=(n*o+(0|this.words[s]))%e;return t?-o:o},s.prototype.modn=function(e){return this.modrn(e)},s.prototype.idivn=function(e){var t=e<0;t&&(e=-e),r(e<=67108863);for(var n=0,o=this.length-1;o>=0;o--){var s=(0|this.words[o])+67108864*n;this.words[o]=s/e|0,n=s%e}return this._strip(),t?this.ineg():this},s.prototype.divn=function(e){return this.clone().idivn(e)},s.prototype.egcd=function(e){r(0===e.negative),r(!e.isZero());var t=this,n=e.clone();t=0!==t.negative?t.umod(e):t.clone();for(var o=new s(1),i=new s(0),a=new s(0),u=new s(1),c=0;t.isEven()&&n.isEven();)t.iushrn(1),n.iushrn(1),++c;for(var l=n.clone(),d=t.clone();!t.isZero();){for(var h=0,p=1;0==(t.words[0]&p)&&h<26;++h,p<<=1);if(h>0)for(t.iushrn(h);h-- >0;)(o.isOdd()||i.isOdd())&&(o.iadd(l),i.isub(d)),o.iushrn(1),i.iushrn(1);for(var f=0,m=1;0==(n.words[0]&m)&&f<26;++f,m<<=1);if(f>0)for(n.iushrn(f);f-- >0;)(a.isOdd()||u.isOdd())&&(a.iadd(l),u.isub(d)),a.iushrn(1),u.iushrn(1);t.cmp(n)>=0?(t.isub(n),o.isub(a),i.isub(u)):(n.isub(t),a.isub(o),u.isub(i))}return{a:a,b:u,gcd:n.iushln(c)}},s.prototype._invmp=function(e){r(0===e.negative),r(!e.isZero());var t=this,n=e.clone();t=0!==t.negative?t.umod(e):t.clone();for(var o,i=new s(1),a=new s(0),u=n.clone();t.cmpn(1)>0&&n.cmpn(1)>0;){for(var c=0,l=1;0==(t.words[0]&l)&&c<26;++c,l<<=1);if(c>0)for(t.iushrn(c);c-- >0;)i.isOdd()&&i.iadd(u),i.iushrn(1);for(var d=0,h=1;0==(n.words[0]&h)&&d<26;++d,h<<=1);if(d>0)for(n.iushrn(d);d-- >0;)a.isOdd()&&a.iadd(u),a.iushrn(1);t.cmp(n)>=0?(t.isub(n),i.isub(a)):(n.isub(t),a.isub(i))}return(o=0===t.cmpn(1)?i:a).cmpn(0)<0&&o.iadd(e),o},s.prototype.gcd=function(e){if(this.isZero())return e.abs();if(e.isZero())return this.abs();var t=this.clone(),r=e.clone();t.negative=0,r.negative=0;for(var n=0;t.isEven()&&r.isEven();n++)t.iushrn(1),r.iushrn(1);for(;;){for(;t.isEven();)t.iushrn(1);for(;r.isEven();)r.iushrn(1);var o=t.cmp(r);if(o<0){var s=t;t=r,r=s}else if(0===o||0===r.cmpn(1))break;t.isub(r)}return r.iushln(n)},s.prototype.invm=function(e){return this.egcd(e).a.umod(e)},s.prototype.isEven=function(){return 0==(1&this.words[0])},s.prototype.isOdd=function(){return 1==(1&this.words[0])},s.prototype.andln=function(e){return this.words[0]&e},s.prototype.bincn=function(e){r("number"==typeof e);var t=e%26,n=(e-t)/26,o=1<<t;if(this.length<=n)return this._expand(n+1),this.words[n]|=o,this;for(var s=o,i=n;0!==s&&i<this.length;i++){var a=0|this.words[i];s=(a+=s)>>>26,a&=67108863,this.words[i]=a}return 0!==s&&(this.words[i]=s,this.length++),this},s.prototype.isZero=function(){return 1===this.length&&0===this.words[0]},s.prototype.cmpn=function(e){var t,n=e<0;if(0!==this.negative&&!n)return-1;if(0===this.negative&&n)return 1;if(this._strip(),this.length>1)t=1;else{n&&(e=-e),r(e<=67108863,"Number is too big");var o=0|this.words[0];t=o===e?0:o<e?-1:1}return 0!==this.negative?0|-t:t},s.prototype.cmp=function(e){if(0!==this.negative&&0===e.negative)return-1;if(0===this.negative&&0!==e.negative)return 1;var t=this.ucmp(e);return 0!==this.negative?0|-t:t},s.prototype.ucmp=function(e){if(this.length>e.length)return 1;if(this.length<e.length)return-1;for(var t=0,r=this.length-1;r>=0;r--){var n=0|this.words[r],o=0|e.words[r];if(n!==o){n<o?t=-1:n>o&&(t=1);break}}return t},s.prototype.gtn=function(e){return 1===this.cmpn(e)},s.prototype.gt=function(e){return 1===this.cmp(e)},s.prototype.gten=function(e){return this.cmpn(e)>=0},s.prototype.gte=function(e){return this.cmp(e)>=0},s.prototype.ltn=function(e){return-1===this.cmpn(e)},s.prototype.lt=function(e){return-1===this.cmp(e)},s.prototype.lten=function(e){return this.cmpn(e)<=0},s.prototype.lte=function(e){return this.cmp(e)<=0},s.prototype.eqn=function(e){return 0===this.cmpn(e)},s.prototype.eq=function(e){return 0===this.cmp(e)},s.red=function(e){return new A(e)},s.prototype.toRed=function(e){return r(!this.red,"Already a number in reduction context"),r(0===this.negative,"red works only with positives"),e.convertTo(this)._forceRed(e)},s.prototype.fromRed=function(){return r(this.red,"fromRed works only with numbers in reduction context"),this.red.convertFrom(this)},s.prototype._forceRed=function(e){return this.red=e,this},s.prototype.forceRed=function(e){return r(!this.red,"Already a number in reduction context"),this._forceRed(e)},s.prototype.redAdd=function(e){return r(this.red,"redAdd works only with red numbers"),this.red.add(this,e)},s.prototype.redIAdd=function(e){return r(this.red,"redIAdd works only with red numbers"),this.red.iadd(this,e)},s.prototype.redSub=function(e){return r(this.red,"redSub works only with red numbers"),this.red.sub(this,e)},s.prototype.redISub=function(e){return r(this.red,"redISub works only with red numbers"),this.red.isub(this,e)},s.prototype.redShl=function(e){return r(this.red,"redShl works only with red numbers"),this.red.shl(this,e)},s.prototype.redMul=function(e){return r(this.red,"redMul works only with red numbers"),this.red._verify2(this,e),this.red.mul(this,e)},s.prototype.redIMul=function(e){return r(this.red,"redMul works only with red numbers"),this.red._verify2(this,e),this.red.imul(this,e)},s.prototype.redSqr=function(){return r(this.red,"redSqr works only with red numbers"),this.red._verify1(this),this.red.sqr(this)},s.prototype.redISqr=function(){return r(this.red,"redISqr works only with red numbers"),this.red._verify1(this),this.red.isqr(this)},s.prototype.redSqrt=function(){return r(this.red,"redSqrt works only with red numbers"),this.red._verify1(this),this.red.sqrt(this)},s.prototype.redInvm=function(){return r(this.red,"redInvm works only with red numbers"),this.red._verify1(this),this.red.invm(this)},s.prototype.redNeg=function(){return r(this.red,"redNeg works only with red numbers"),this.red._verify1(this),this.red.neg(this)},s.prototype.redPow=function(e){return r(this.red&&!e.red,"redPow(normalNum)"),this.red._verify1(this),this.red.pow(this,e)};var v={k256:null,p224:null,p192:null,p25519:null};function x(e,t){this.name=e,this.p=new s(t,16),this.n=this.p.bitLength(),this.k=new s(1).iushln(this.n).isub(this.p),this.tmp=this._tmp()}function b(){x.call(this,"k256","ffffffff ffffffff ffffffff ffffffff ffffffff ffffffff fffffffe fffffc2f")}function E(){x.call(this,"p224","ffffffff ffffffff ffffffff ffffffff 00000000 00000000 00000001")}function I(){x.call(this,"p192","ffffffff ffffffff ffffffff fffffffe ffffffff ffffffff")}function M(){x.call(this,"25519","7fffffffffffffff ffffffffffffffff ffffffffffffffff ffffffffffffffed")}function A(e){if("string"==typeof e){var t=s._prime(e);this.m=t.p,this.prime=t}else r(e.gtn(1),"modulus must be greater than 1"),this.m=e,this.prime=null}function T(e){A.call(this,e),this.shift=this.m.bitLength(),this.shift%26!=0&&(this.shift+=26-this.shift%26),this.r=new s(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)}x.prototype._tmp=function(){var e=new s(null);return e.words=new Array(Math.ceil(this.n/13)),e},x.prototype.ireduce=function(e){var t,r=e;do{this.split(r,this.tmp),t=(r=(r=this.imulK(r)).iadd(this.tmp)).bitLength()}while(t>this.n);var n=t<this.n?-1:r.ucmp(this.p);return 0===n?(r.words[0]=0,r.length=1):n>0?r.isub(this.p):void 0!==r.strip?r.strip():r._strip(),r},x.prototype.split=function(e,t){e.iushrn(this.n,0,t)},x.prototype.imulK=function(e){return e.imul(this.k)},n(b,x),b.prototype.split=function(e,t){for(var r=4194303,n=Math.min(e.length,9),o=0;o<n;o++)t.words[o]=e.words[o];if(t.length=n,e.length<=9)return e.words[0]=0,void(e.length=1);var s=e.words[9];for(t.words[t.length++]=s&r,o=10;o<e.length;o++){var i=0|e.words[o];e.words[o-10]=(i&r)<<4|s>>>22,s=i}s>>>=22,e.words[o-10]=s,0===s&&e.length>10?e.length-=10:e.length-=9},b.prototype.imulK=function(e){e.words[e.length]=0,e.words[e.length+1]=0,e.length+=2;for(var t=0,r=0;r<e.length;r++){var n=0|e.words[r];t+=977*n,e.words[r]=67108863&t,t=64*n+(t/67108864|0)}return 0===e.words[e.length-1]&&(e.length--,0===e.words[e.length-1]&&e.length--),e},n(E,x),n(I,x),n(M,x),M.prototype.imulK=function(e){for(var t=0,r=0;r<e.length;r++){var n=19*(0|e.words[r])+t,o=67108863&n;n>>>=26,e.words[r]=o,t=n}return 0!==t&&(e.words[e.length++]=t),e},s._prime=function(e){if(v[e])return v[e];var t;if("k256"===e)t=new b;else if("p224"===e)t=new E;else if("p192"===e)t=new I;else{if("p25519"!==e)throw new Error("Unknown prime "+e);t=new M}return v[e]=t,t},A.prototype._verify1=function(e){r(0===e.negative,"red works only with positives"),r(e.red,"red works only with red numbers")},A.prototype._verify2=function(e,t){r(0==(e.negative|t.negative),"red works only with positives"),r(e.red&&e.red===t.red,"red works only with red numbers")},A.prototype.imod=function(e){return this.prime?this.prime.ireduce(e)._forceRed(this):(l(e,e.umod(this.m)._forceRed(this)),e)},A.prototype.neg=function(e){return e.isZero()?e.clone():this.m.sub(e)._forceRed(this)},A.prototype.add=function(e,t){this._verify2(e,t);var r=e.add(t);return r.cmp(this.m)>=0&&r.isub(this.m),r._forceRed(this)},A.prototype.iadd=function(e,t){this._verify2(e,t);var r=e.iadd(t);return r.cmp(this.m)>=0&&r.isub(this.m),r},A.prototype.sub=function(e,t){this._verify2(e,t);var r=e.sub(t);return r.cmpn(0)<0&&r.iadd(this.m),r._forceRed(this)},A.prototype.isub=function(e,t){this._verify2(e,t);var r=e.isub(t);return r.cmpn(0)<0&&r.iadd(this.m),r},A.prototype.shl=function(e,t){return this._verify1(e),this.imod(e.ushln(t))},A.prototype.imul=function(e,t){return this._verify2(e,t),this.imod(e.imul(t))},A.prototype.mul=function(e,t){return this._verify2(e,t),this.imod(e.mul(t))},A.prototype.isqr=function(e){return this.imul(e,e.clone())},A.prototype.sqr=function(e){return this.mul(e,e)},A.prototype.sqrt=function(e){if(e.isZero())return e.clone();var t=this.m.andln(3);if(r(t%2==1),3===t){var n=this.m.add(new s(1)).iushrn(2);return this.pow(e,n)}for(var o=this.m.subn(1),i=0;!o.isZero()&&0===o.andln(1);)i++,o.iushrn(1);r(!o.isZero());var a=new s(1).toRed(this),u=a.redNeg(),c=this.m.subn(1).iushrn(1),l=this.m.bitLength();for(l=new s(2*l*l).toRed(this);0!==this.pow(l,c).cmp(u);)l.redIAdd(u);for(var d=this.pow(l,o),h=this.pow(e,o.addn(1).iushrn(1)),p=this.pow(e,o),f=i;0!==p.cmp(a);){for(var m=p,g=0;0!==m.cmp(a);g++)m=m.redSqr();r(g<f);var y=this.pow(d,new s(1).iushln(f-g-1));h=h.redMul(y),d=y.redSqr(),p=p.redMul(d),f=g}return h},A.prototype.invm=function(e){var t=e._invmp(this.m);return 0!==t.negative?(t.negative=0,this.imod(t).redNeg()):this.imod(t)},A.prototype.pow=function(e,t){if(t.isZero())return new s(1).toRed(this);if(0===t.cmpn(1))return e.clone();var r=new Array(16);r[0]=new s(1).toRed(this),r[1]=e;for(var n=2;n<r.length;n++)r[n]=this.mul(r[n-1],e);var o=r[0],i=0,a=0,u=t.bitLength()%26;for(0===u&&(u=26),n=t.length-1;n>=0;n--){for(var c=t.words[n],l=u-1;l>=0;l--){var d=c>>l&1;o!==r[0]&&(o=this.sqr(o)),0!==d||0!==i?(i<<=1,i|=d,(4==++a||0===n&&0===l)&&(o=this.mul(o,r[i]),a=0,i=0)):a=0}u=26}return o},A.prototype.convertTo=function(e){var t=e.umod(this.m);return t===e?t.clone():t},A.prototype.convertFrom=function(e){var t=e.clone();return t.red=null,t},s.mont=function(e){return new T(e)},n(T,A),T.prototype.convertTo=function(e){return this.imod(e.ushln(this.shift))},T.prototype.convertFrom=function(e){var t=this.imod(e.mul(this.rinv));return t.red=null,t},T.prototype.imul=function(e,t){if(e.isZero()||t.isZero())return e.words[0]=0,e.length=1,e;var r=e.imul(t),n=r.maskn(this.shift).mul(this.minv).imaskn(this.shift).mul(this.m),o=r.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)},T.prototype.mul=function(e,t){if(e.isZero()||t.isZero())return new s(0)._forceRed(this);var r=e.mul(t),n=r.maskn(this.shift).mul(this.minv).imaskn(this.shift).mul(this.m),o=r.isub(n).iushrn(this.shift),i=o;return o.cmp(this.m)>=0?i=o.isub(this.m):o.cmpn(0)<0&&(i=o.iadd(this.m)),i._forceRed(this)},T.prototype.invm=function(e){return this.imod(e._invmp(this.m).mul(this.r2))._forceRed(this)}}(0,r);var s,i=o.exports,a=n(i);exports.TreeType=void 0,(s=exports.TreeType||(exports.TreeType={}))[s.StateV1=1]="StateV1",s[s.AddressV1=2]="AddressV1",s[s.StateV2=3]="StateV2",s[s.AddressV2=4]="AddressV2";const u=new a("21888242871839275222246405745257275088548364400416034343698204186575808495617"),c=new a("452312848583266388373324160190187140051835877600158453279131187530910662655"),l=[2,64,66,15,0],d=t.Buffer.from([26,16,169,7,21,202,242,25]),h=t.Buffer.from([49,212,191,129,39,194,43,196]),p=t.Buffer.from([180,143,159,153,35,46,248,163]),f="noopb9bkMVfRPU8AsbpTUg8AQkHtKwMYZiFUjNRtMmV",m="SySTEM1eSU2p4BGQfQpimFEWWSC1XDFeun3Nqzz3rT7",g="compr6CUsB5m2jS4Y3831ztGSTnDpnKJTKS95d64XVq",y=()=>new e.PublicKey("35hkDgaAKwMCaxRz2ocSZ6NaUrtKkyNqU6c4RV3tYJRh"),w=()=>e.PublicKey.findProgramAddressSync([t.Buffer.from("cpi_authority")],new e.PublicKey(m))[0],v=()=>({registeredProgramPda:new e.PublicKey(y()),noopProgram:new e.PublicKey(f),accountCompressionProgram:new e.PublicKey(g),accountCompressionAuthority:new e.PublicKey(w()),cpiSignatureAccount:null}),x=()=>({mainnet:[{stateTreeLookupTable:new e.PublicKey(T),nullifyLookupTable:new e.PublicKey(S)}],devnet:[{stateTreeLookupTable:new e.PublicKey(C),nullifyLookupTable:new e.PublicKey(k)}]}),b=e=>e.includes("localhost")||e.includes("127.0.0.1"),E=()=>[{tree:new e.PublicKey(L),queue:new e.PublicKey(_),cpiContext:new e.PublicKey(P),treeType:exports.TreeType.StateV1,nextTreeInfo:null},{tree:new e.PublicKey(B),queue:new e.PublicKey(R),cpiContext:new e.PublicKey(D),treeType:exports.TreeType.StateV1,nextTreeInfo:null}],I=()=>({tree:new e.PublicKey(N),queue:new e.PublicKey(O),cpiContext:null,treeType:exports.TreeType.AddressV1,nextTreeInfo:null}),M=()=>({nullifierQueue:new e.PublicKey(_),merkleTree:new e.PublicKey(L),merkleTreeHeight:U,addressTree:new e.PublicKey(N),addressQueue:new e.PublicKey(O)}),A=new e.PublicKey("cTokenmWW8bLPjZEBAUgYy3zKxQZW6VKi7bqNFEVv3m"),T="7i86eQs3GSqHjN47WdWLTCGMW6gde1q96G2EVnUyK2st",S="H9QD4u1fG7KmkAzn2tDXhheushxFe1EcrjGGyEFXeMqT",C="Dk9mNkbiZXJZ4By8DfSP6HEE4ojZzRvucwpawLeuwq8q",k="AXbHzp1NgjLvpfnD6JRTTovXZ7APUCdtWZFCRr5tCxse",_="nfq1NvQDJ2GEgnS8zt9prAe8rjjpAW1zFkrvZoBR148",P="cpi1uHzrEhBG733DoEJNgHCyRS3XmmyVNZx5fonubE4",L="smt1NamzXdq4AMqS2fS2F1i5KTYPZRhoHgWx38d8WsT",N="amt1Ayt45jfbdw5YSo7iz6WZxUmnZsQTYXy82hVwyC2",O="aq1S9z4reTSQAdgWHGD2zDaS39sjGrAxbR31vxJ2F4F",B="smt2rJAFdyJJupwMKAqTNAJwvjhmiZ4JYGZmbVRw1Ho",R="nfq2hgS7NYemXsFaFUCe3EMXSDSfnZnAe27jC6aPP1X",D="cpi2cdhkH5roePvcudTgUL8ppEBfTay1desGh8G8QxK",U=26,F=new a(Math.floor(2**U*.95)),q=new a(300),V=new a(392),K=new a(5e3),H=new a(5e3);var $=function(e){const t=new Uint8Array(256);for(let e=0;e<t.length;e++)t[e]=255;for(let r=0;r<58;r++){const n=e.charAt(r),o=n.charCodeAt(0);if(255!==t[o])throw new TypeError(n+" is ambiguous");t[o]=r}const r=e.charAt(0),n=Math.log(58)/Math.log(256),o=Math.log(256)/Math.log(58);function s(e){if("string"!=typeof e)throw new TypeError("Expected String");if(0===e.length)return new Uint8Array;let o=0,s=0,i=0;for(;e[o]===r;)s++,o++;const a=(e.length-o)*n+1>>>0,u=new Uint8Array(a);for(;e[o];){let r=t[e.charCodeAt(o)];if(255===r)return;let n=0;for(let e=a-1;(0!==r||n<i)&&-1!==e;e--,n++)r+=58*u[e]>>>0,u[e]=r%256>>>0,r=r/256>>>0;if(0!==r)throw new Error("Non-zero carry");i=n,o++}let c=a-i;for(;c!==a&&0===u[c];)c++;const l=new Uint8Array(s+(a-c));let d=s;for(;c!==a;)l[d++]=u[c++];return l}return{encode:function(t){if(t instanceof Uint8Array||(ArrayBuffer.isView(t)?t=new Uint8Array(t.buffer,t.byteOffset,t.byteLength):Array.isArray(t)&&(t=Uint8Array.from(t))),!(t instanceof Uint8Array))throw new TypeError("Expected Uint8Array");if(0===t.length)return"";let n=0,s=0,i=0;const a=t.length;for(;i!==a&&0===t[i];)i++,n++;const u=(a-i)*o+1>>>0,c=new Uint8Array(u);for(;i!==a;){let e=t[i],r=0;for(let t=u-1;(0!==e||r<s)&&-1!==t;t--,r++)e+=256*c[t]>>>0,c[t]=e%58>>>0,e=e/58>>>0;if(0!==e)throw new Error("Non-zero carry");s=r,i++}let l=u-s;for(;l!==u&&0===c[l];)l++;let d=r.repeat(n);for(;l<u;++l)d+=e.charAt(c[l]);return d},decodeUnsafe:s,decode:function(e){const t=s(e);if(t)return t;throw new Error("Non-base58 character")}}}("123456789ABCDEFGHJKLMNPQRSTUVWXYZabcdefghijkmnopqrstuvwxyz");const j=(e,t)=>{if("base58"===t){if("string"!=typeof e)throw new Error("Must be a base58 string");return j($.decode(e))}return function(e){if(e.gte(u))throw new Error("Value is too large. Max <254 bits");return e}(new a(e,t))};function z(e){const r=j(e).toArrayLike(t.Buffer,void 0,32);return $.encode(new Uint8Array(r))}const W=(e,r,n)=>e instanceof Uint8Array&&!(e instanceof t.Buffer)?new a(t.Buffer.from(e),r,n):new a(e,r,n),Z=(e,t,r,n)=>({owner:e,lamports:null!=t?t:W(0),address:null!=n?n:null,data:null!=r?r:null}),J=(e,t,r,n,o)=>Object.assign(Object.assign(Object.assign({},Z(t,r,n,o)),e),{readOnly:0}),Q=(e,t,r,n=0)=>({treeInfo:e,hash:t,leafIndex:r,proveByIndex:n});function G(e,t){const r=e.findIndex((e=>e.equals(t)));return-1===r?(e.push(t),e.length-1):r}function X(e,t){return t<=0?[]:new Array(t).fill(e)}function Y(e){return e.map((e=>({pubkey:e,isWritable:1,isSigner:0})))}function ee(e,t,r,n,o=[]){const s=o.slice(),i=[],a=[];if(e.forEach(((e,r)=>{const n=G(s,e.treeInfo.tree),o=G(s,e.treeInfo.queue);i.push({compressedAccount:{owner:e.owner,lamports:e.lamports,address:e.address,data:e.data},merkleContext:{merkleTreePubkeyIndex:n,nullifierQueuePubkeyIndex:o,leafIndex:e.leafIndex,queueIndex:null},rootIndex:t[r],readOnly:0})})),e.length>0&&n)throw new Error("Cannot specify both input accounts and outputStateTreeInfo");let u;if(e.length>0)u=e[0].treeInfo;else{if(!n)throw new Error("Neither input accounts nor outputStateTreeInfo are available");u=n}const c=u.nextTreeInfo||u,l=c.tree;if(c.treeType===exports.TreeType.StateV2)throw new Error("V2 trees are not supported yet");const d=X(l,r.length);return r.forEach(((e,t)=>{const r=G(s,d[t]);a.push({compressedAccount:{owner:e.owner,lamports:e.lamports,address:e.address,data:e.data},merkleTreeIndex:r})})),{packedInputCompressedAccounts:i,packedOutputCompressedAccounts:a,remainingAccounts:s}}const te=e=>{if(e.lt(W(0)))throw new Error("Insufficient balance for transfer")},re=e=>{if(0===e.length)throw new Error("No accounts provided for validation");const t=e[0].owner;if(!e.every((e=>e.owner.equals(t))))throw new Error("All input accounts must have the same owner")},ne=(e,t)=>{if(e>0&&t>0){if(8===e)throw new Error(`Invalid number of compressed accounts for proof: ${e}. Allowed numbers: ${[1,2,3,4].join(", ")}`);ie(e,[1,2,3,4],"compressed accounts"),se(t)}else e>0?oe(e):se(t)},oe=e=>{ie(e,[1,2,3,4,8],"compressed accounts")},se=e=>{ie(e,[1,2],"new addresses")},ie=(e,t,r)=>{if(!t.includes(e))throw new Error(`Invalid number of ${r}: ${e}. Allowed numbers: ${t.join(", ")}`)};function ae(e){if(!Number.isSafeInteger(e)||e<0)throw new Error(`positive integer expected, not ${e}`)}function ue(e,...t){if(!((r=e)instanceof Uint8Array||null!=r&&"object"==typeof r&&"Uint8Array"===r.constructor.name))throw new Error("Uint8Array expected");var r;if(t.length>0&&!t.includes(e.length))throw new Error(`Uint8Array expected of length ${t}, not of length=${e.length}`)}function ce(e,t=1){if(e.destroyed)throw new Error("Hash instance has been destroyed");if(t&&e.finished)throw new Error("Hash#digest() has already been called")}const le=BigInt(2**32-1),de=BigInt(32);function he(e,t=0){return t?{h:Number(e&le),l:Number(e>>de&le)}:{h:0|Number(e>>de&le),l:0|Number(e&le)}}function pe(e,t=0){let r=new Uint32Array(e.length),n=new Uint32Array(e.length);for(let o=0;o<e.length;o++){const{h:s,l:i}=he(e[o],t);[r[o],n[o]]=[s,i]}return[r,n]}const fe=68===new Uint8Array(new Uint32Array([287454020]).buffer)[0];function me(e){for(let r=0;r<e.length;r++)e[r]=(t=e[r])<<24&4278190080|t<<8&16711680|t>>>8&65280|t>>>24&255;var t}function ge(e){return"string"==typeof e&&(e=function(e){if("string"!=typeof e)throw new Error("utf8ToBytes expected string, got "+typeof e);return new Uint8Array((new TextEncoder).encode(e))}(e)),ue(e),e}class ye{clone(){return this._cloneInto()}}const we=[],ve=[],xe=[],be=BigInt(0),Ee=BigInt(1),Ie=BigInt(2),Me=BigInt(7),Ae=BigInt(256),Te=BigInt(113);for(let e=0,t=Ee,r=1,n=0;e<24;e++){[r,n]=[n,(2*r+3*n)%5],we.push(2*(5*n+r)),ve.push((e+1)*(e+2)/2%64);let o=be;for(let e=0;e<7;e++)t=(t<<Ee^(t>>Me)*Te)%Ae,t&Ie&&(o^=Ee<<(Ee<<BigInt(e))-Ee);xe.push(o)}const[Se,Ce]=pe(xe,1),ke=(e,t,r)=>r>32?((e,t,r)=>t<<r-32|e>>>64-r)(e,t,r):((e,t,r)=>e<<r|t>>>32-r)(e,t,r),_e=(e,t,r)=>r>32?((e,t,r)=>e<<r-32|t>>>64-r)(e,t,r):((e,t,r)=>t<<r|e>>>32-r)(e,t,r);class Pe extends ye{constructor(e,t,r,n=0,o=24){if(super(),this.blockLen=e,this.suffix=t,this.outputLen=r,this.enableXOF=n,this.rounds=o,this.pos=0,this.posOut=0,this.finished=0,this.destroyed=0,ae(r),0>=this.blockLen||this.blockLen>=200)throw new Error("Sha3 supports only keccak-f1600 function");var s;this.state=new Uint8Array(200),this.state32=(s=this.state,new Uint32Array(s.buffer,s.byteOffset,Math.floor(s.byteLength/4)))}keccak(){fe||me(this.state32),function(e,t=24){const r=new Uint32Array(10);for(let n=24-t;n<24;n++){for(let t=0;t<10;t++)r[t]=e[t]^e[t+10]^e[t+20]^e[t+30]^e[t+40];for(let t=0;t<10;t+=2){const n=(t+8)%10,o=(t+2)%10,s=r[o],i=r[o+1],a=ke(s,i,1)^r[n],u=_e(s,i,1)^r[n+1];for(let r=0;r<50;r+=10)e[t+r]^=a,e[t+r+1]^=u}let t=e[2],o=e[3];for(let r=0;r<24;r++){const n=ve[r],s=ke(t,o,n),i=_e(t,o,n),a=we[r];t=e[a],o=e[a+1],e[a]=s,e[a+1]=i}for(let t=0;t<50;t+=10){for(let n=0;n<10;n++)r[n]=e[t+n];for(let n=0;n<10;n++)e[t+n]^=~r[(n+2)%10]&r[(n+4)%10]}e[0]^=Se[n],e[1]^=Ce[n]}r.fill(0)}(this.state32,this.rounds),fe||me(this.state32),this.posOut=0,this.pos=0}update(e){ce(this);const{blockLen:t,state:r}=this,n=(e=ge(e)).length;for(let o=0;o<n;){const s=Math.min(t-this.pos,n-o);for(let t=0;t<s;t++)r[this.pos++]^=e[o++];this.pos===t&&this.keccak()}return this}finish(){if(this.finished)return;this.finished=1;const{state:e,suffix:t,pos:r,blockLen:n}=this;e[r]^=t,0!=(128&t)&&r===n-1&&this.keccak(),e[n-1]^=128,this.keccak()}writeInto(e){ce(this,0),ue(e),this.finish();const t=this.state,{blockLen:r}=this;for(let n=0,o=e.length;n<o;){this.posOut>=r&&this.keccak();const s=Math.min(r-this.posOut,o-n);e.set(t.subarray(this.posOut,this.posOut+s),n),this.posOut+=s,n+=s}return e}xofInto(e){if(!this.enableXOF)throw new Error("XOF is not possible for this instance");return this.writeInto(e)}xof(e){return ae(e),this.xofInto(new Uint8Array(e))}digestInto(e){if(function(e,t){ue(e);const r=t.outputLen;if(e.length<r)throw new Error(`digestInto() expects output buffer of length at least ${r}`)}(e,this),this.finished)throw new Error("digest() was already called");return this.writeInto(e),this.destroy(),e}digest(){return this.digestInto(new Uint8Array(this.outputLen))}destroy(){this.destroyed=1,this.state.fill(0)}_cloneInto(e){const{blockLen:t,suffix:r,outputLen:n,rounds:o,enableXOF:s}=this;return e||(e=new Pe(t,r,n,s,o)),e.state32.set(this.state32),e.pos=this.pos,e.posOut=this.posOut,e.finished=this.finished,e.rounds=o,e.suffix=r,e.outputLen=n,e.enableXOF=s,e.destroyed=this.destroyed,e}}const Le=(()=>function(e){const t=t=>e().update(ge(t)).digest(),r=e();return t.outputLen=r.outputLen,t.blockLen=r.blockLen,t.create=()=>e(),t}((()=>new Pe(136,1,32))))(),Ne=e=>"object"==typeof e&&null!==e,Oe=e=>Ne(e)&&!(e instanceof RegExp)&&!(e instanceof Error)&&!(e instanceof Date),Be=Symbol("mapObjectSkip"),Re=(e,t,r,n=new WeakMap)=>{if(r={deep:0,target:{},...r},n.has(e))return n.get(e);n.set(e,r.target);const{target:o}=r;delete r.target;const s=e=>e.map((e=>Oe(e)?Re(e,t,r,n):e));if(Array.isArray(e))return s(e);for(const[i,a]of Object.entries(e)){const u=t(i,a,e);if(u===Be)continue;let[c,l,{shouldRecurse:d=1}={}]=u;"__proto__"!==c&&(r.deep&&d&&Oe(l)&&(l=Array.isArray(l)?s(l):Re(l,t,r,n)),o[c]=l)}return o};function De(e,t,r){if(!Ne(e))throw new TypeError(`Expected an object, got \`${e}\` (${typeof e})`);return Re(e,t,r)}const Ue=/[\p{Lu}]/u,Fe=/[\p{Ll}]/u,qe=/^[\p{Lu}](?![\p{Lu}])/gu,Ve=/([\p{Alpha}\p{N}_]|$)/u,Ke=/[_.\- ]+/,He=new RegExp("^"+Ke.source),$e=new RegExp(Ke.source+Ve.source,"gu"),je=new RegExp("\\d+"+Ve.source,"gu");class ze extends Map{constructor(e={}){if(super(),!(e.maxSize&&e.maxSize>0))throw new TypeError("`maxSize` must be a number greater than 0");if("number"==typeof e.maxAge&&0===e.maxAge)throw new TypeError("`maxAge` must be a number greater than 0");this.maxSize=e.maxSize,this.maxAge=e.maxAge||Number.POSITIVE_INFINITY,this.onEviction=e.onEviction,this.cache=new Map,this.oldCache=new Map,this._size=0}_emitEvictions(e){if("function"==typeof this.onEviction)for(const[t,r]of e)this.onEviction(t,r.value)}_deleteIfExpired(e,t){return"number"==typeof t.expiry&&t.expiry<=Date.now()?("function"==typeof this.onEviction&&this.onEviction(e,t.value),this.delete(e)):0}_getOrDeleteIfExpired(e,t){if(0==this._deleteIfExpired(e,t))return t.value}_getItemValue(e,t){return t.expiry?this._getOrDeleteIfExpired(e,t):t.value}_peek(e,t){const r=t.get(e);return this._getItemValue(e,r)}_set(e,t){this.cache.set(e,t),this._size++,this._size>=this.maxSize&&(this._size=0,this._emitEvictions(this.oldCache),this.oldCache=this.cache,this.cache=new Map)}_moveToRecent(e,t){this.oldCache.delete(e),this._set(e,t)}*_entriesAscending(){for(const e of this.oldCache){const[t,r]=e;this.cache.has(t)||0==this._deleteIfExpired(t,r)&&(yield e)}for(const e of this.cache){const[t,r]=e;0==this._deleteIfExpired(t,r)&&(yield e)}}get(e){if(this.cache.has(e)){const t=this.cache.get(e);return this._getItemValue(e,t)}if(this.oldCache.has(e)){const t=this.oldCache.get(e);if(0==this._deleteIfExpired(e,t))return this._moveToRecent(e,t),t.value}}set(e,t,{maxAge:r=this.maxAge}={}){const n="number"==typeof r&&r!==Number.POSITIVE_INFINITY?Date.now()+r:void 0;return this.cache.has(e)?this.cache.set(e,{value:t,expiry:n}):this._set(e,{value:t,expiry:n}),this}has(e){return this.cache.has(e)?!this._deleteIfExpired(e,this.cache.get(e)):this.oldCache.has(e)?!this._deleteIfExpired(e,this.oldCache.get(e)):0}peek(e){return this.cache.has(e)?this._peek(e,this.cache):this.oldCache.has(e)?this._peek(e,this.oldCache):void 0}delete(e){const t=this.cache.delete(e);return t&&this._size--,this.oldCache.delete(e)||t}clear(){this.cache.clear(),this.oldCache.clear(),this._size=0}resize(e){if(!(e&&e>0))throw new TypeError("`maxSize` must be a number greater than 0");const t=[...this._entriesAscending()],r=t.length-e;r<0?(this.cache=new Map(t),this.oldCache=new Map,this._size=t.length):(r>0&&this._emitEvictions(t.slice(0,r)),this.oldCache=new Map(t.slice(r)),this.cache=new Map,this._size=0),this.maxSize=e}*keys(){for(const[e]of this)yield e}*values(){for(const[,e]of this)yield e}*[Symbol.iterator](){for(const e of this.cache){const[t,r]=e;0==this._deleteIfExpired(t,r)&&(yield[t,r.value])}for(const e of this.oldCache){const[t,r]=e;this.cache.has(t)||0==this._deleteIfExpired(t,r)&&(yield[t,r.value])}}*entriesDescending(){let e=[...this.cache];for(let t=e.length-1;t>=0;--t){const r=e[t],[n,o]=r;0==this._deleteIfExpired(n,o)&&(yield[n,o.value])}e=[...this.oldCache];for(let t=e.length-1;t>=0;--t){const r=e[t],[n,o]=r;this.cache.has(n)||0==this._deleteIfExpired(n,o)&&(yield[n,o.value])}}*entriesAscending(){for(const[e,t]of this._entriesAscending())yield[e,t.value]}get size(){if(!this._size)return this.oldCache.size;let e=0;for(const t of this.oldCache.keys())this.cache.has(t)||e++;return Math.min(this._size+e,this.maxSize)}entries(){return this.entriesAscending()}forEach(e,t=this){for(const[r,n]of this.entriesAscending())e.call(t,n,r,this)}get[Symbol.toStringTag](){return JSON.stringify([...this.entriesAscending()])}}const We=new ze({maxSize:1e5}),Ze=e=>!("object"!=typeof e||null===e||e instanceof RegExp||e instanceof Error||e instanceof Date),Je=(e,t={})=>{if(!Ze(e))return e;const{exclude:r,pascalCase:n=0,stopPaths:o,deep:s=0,preserveConsecutiveUppercase:i=0}=t,a=new Set(o),u=e=>(t,o)=>{if(s&&Ze(o)){const r=void 0===e?t:`${e}.${t}`;a.has(r)||(o=De(o,u(r)))}if(!r||!((e,t)=>e.some((e=>"string"==typeof e?e===t:(e.lastIndex=0,e.test(t)))))(r,t)){const e=n?`${t}_`:t;if(We.has(e))t=We.get(e);else{const r=function(e,t){if("string"!=typeof e&&!Array.isArray(e))throw new TypeError("Expected the input to be `string | string[]`");if(t={pascalCase:0,preserveConsecutiveUppercase:0,...t},0===(e=Array.isArray(e)?e.map((e=>e.trim())).filter((e=>e.length)).join("-"):e.trim()).length)return"";const r=0==t.locale?e=>e.toLowerCase():e=>e.toLocaleLowerCase(t.locale),n=0==t.locale?e=>e.toUpperCase():e=>e.toLocaleUpperCase(t.locale);return 1===e.length?Ke.test(e)?"":t.pascalCase?n(e):r(e):(e!==r(e)&&(e=((e,t,r,n)=>{let o=0,s=0,i=0,a=0;for(let u=0;u<e.length;u++){const c=e[u];a=u>2?"-"===e[u-3]:1,o&&Ue.test(c)?(e=e.slice(0,u)+"-"+e.slice(u),o=0,i=s,s=1,u++):s&&i&&Fe.test(c)&&(!a||n)?(e=e.slice(0,u-1)+"-"+e.slice(u-1),i=s,s=0,o=1):(o=t(c)===c&&r(c)!==c,i=s,s=r(c)===c&&t(c)!==c)}return e})(e,r,n,t.preserveConsecutiveUppercase)),e=e.replace(He,""),e=t.preserveConsecutiveUppercase?((e,t)=>(qe.lastIndex=0,e.replaceAll(qe,(e=>t(e)))))(e,r):r(e),t.pascalCase&&(e=n(e.charAt(0))+e.slice(1)),((e,t)=>($e.lastIndex=0,je.lastIndex=0,e.replaceAll(je,((r,n,o)=>["_","-"].includes(e.charAt(o+r.length))?r:t(r))).replaceAll($e,((e,r)=>t(r)))))(e,n))}(t,{pascalCase:n,locale:0,preserveConsecutiveUppercase:i});t.length<100&&We.set(e,r),t=r}}return[t,o]};return De(e,u(void 0))};function Qe(e){return"0x"+e.toString("hex")}function Ge(e){return W(e,void 0,"be").lt(u)}const Xe=e=>{return t=e,r={deep:1},Array.isArray(t)?Object.keys(t).map((e=>Je(t[e],r))):Je(t,r);var t,r};function Ye(e){let r=255;for(;r>=0;){const n=t.Buffer.concat([e,t.Buffer.from([r])]),o=Le(n);if(32!==o.length)throw new Error("Invalid hash length");if(o[0]=0,Ge(t.Buffer.from(o)))return[t.Buffer.from(o),r];r-=1}return null}function et(e){const t=Le.create();for(const r of e)t.update(r);const r=t.digest();return r[0]=0,r}function tt(e,t){return et([t.toBytes(),...e])}function rt(t,r=M().addressTree){if(32!=t.length)throw new Error("Seed length is not 32 bytes.");const n=r.toBytes(),o=Ye(Buffer.from([...n,...t]));if(null===o)throw new Error("DeriveAddressError");const s=o[0];return new e.PublicKey(s)}function nt(e,t){const r=t.slice(),n=e.map((e=>({seed:Array.from(e.seed),addressMerkleTreeRootIndex:e.addressMerkleTreeRootIndex,addressMerkleTreeAccountIndex:0,addressQueueAccountIndex:0})));return e.forEach(((e,t)=>{n[t].addressMerkleTreeAccountIndex=G(r,e.addressMerkleTreePubkey)})),e.forEach(((e,t)=>{n[t].addressQueueAccountIndex=G(r,e.addressQueuePubkey)})),{newAddressParamsPacked:n,remainingAccounts:r}}async function ot(e,t,r="confirmed"){const n=await e.getLatestBlockhash(r),o={signature:t.toString(),lastValidBlockHeight:n.lastValidBlockHeight,blockhash:n.blockhash};return await e.confirmTransaction(o,r)}function st(e,t){return t.includes(e)?t.filter((t=>t.publicKey.toString()!==e.publicKey.toString())):t}function it(e,t=exports.TreeType.StateV1,r=0){const n=e.filter((e=>!e.nextTreeInfo)).filter((e=>e.treeType===t));if(0===n.length)throw new Error("No active state tree infos found for the specified tree type");const o=r?n.length:Math.min(5,n.length),s=Math.floor(Math.random()*o);if(!n[s].queue)throw new Error("Queue must not be null for state tree");return n[s]}async function at({connection:t,stateTreeLUTPairs:r}){var n;const o=await Promise.all(r.map((async e=>({stateTreeLookupTable:await t.getAddressLookupTable(e.stateTreeLookupTable),nullifyLookupTable:await t.getAddressLookupTable(e.nullifyLookupTable)})))),s=[];for(const{stateTreeLookupTable:t,nullifyLookupTable:r}of o){if(!t.value)throw new Error("State tree lookup table not found");if(!r.value)throw new Error("Nullify table not found");const o=t.value.state.addresses,i=r.value.state.addresses;if(o.length%3!=0)throw new Error("State tree lookup table must have a multiple of 3 addresses");for(let t=0;t<o.length;t+=3){const r=o[t],n=o[t+1],a=o[t+2];let u=null;if(!r||!n||!a)throw new Error("Invalid state tree pubkeys structure");i.map((e=>e.toBase58())).includes(r.toBase58())&&(u={tree:e.PublicKey.default,queue:e.PublicKey.default,cpiContext:e.PublicKey.default,treeType:exports.TreeType.StateV1,nextTreeInfo:null}),s.push({tree:r,queue:n,cpiContext:a,treeType:exports.TreeType.StateV1,nextTreeInfo:u})}for(const t of s)if(null===(n=t.nextTreeInfo)||void 0===n?void 0:n.tree.equals(e.PublicKey.default)){const e=s.find((e=>!e.nextTreeInfo));if(!e)throw new Error("No available tree info found to assign as next tree");t.nextTreeInfo=e}}return s}function ut(e){const t=lt(e.ar[0]),r=lt(e.ar[1]),n=new Uint8Array([...t,...r]),o=lt(e.bs[0][0]),s=lt(e.bs[0][1]),i=lt(e.bs[1][0]),a=lt(e.bs[1][1]),u=new Uint8Array([...o,...s,...i,...a]),c=lt(e.krs[0]),l=lt(e.krs[1]);return{a:n,b:u,c:new Uint8Array([...c,...l])}}function ct(e){const t=e.a,r=e.b,n=e.c,o=t.slice(0,32),s=dt(W(t.slice(32,64),32,"be"))?0:1;o[0]=ht(o[0],s);const i=r.slice(0,64),a=r.slice(64,128),c=function(e,t){const r=u.div(W(2));return e.lt(r)?1:e.gt(r)?0:t.lt(r)}(W(a.slice(0,32),32,"be"),W(a.slice(32,64),32,"be"));i[0]=ht(i[0],c);const l=n.slice(0,32),d=n.slice(32,64),h=dt(W(d,32,"be"));return l[0]=ht(l[0],h),{a:Array.from(o),b:Array.from(i),c:Array.from(l)}}function lt(e){const t=W(e.startsWith("0x")?e.substring(2):e,"hex");return new Uint8Array(t.toArray("be",32))}function dt(e){return e.lte(u.sub(e))}function ht(e,t){return t?e:128|e}function pt(t,r,n,o){const s=new e.TransactionMessage({payerKey:r,recentBlockhash:n,instructions:t}).compileToV0Message(o);return new e.VersionedTransaction(s)}async function ft(e,t,r,n){const o=await e.sendTransaction(t,r);n||(n=await e.getLatestBlockhash());const s={signature:o,blockhash:n.blockhash,lastValidBlockHeight:n.lastValidBlockHeight},i=(await e.confirmTransaction(s,(null==r?void 0:r.commitment)||e.commitment||"confirmed")).context.slot;return await e.confirmTransactionIndexed(i),o}async function mt(e,t,r,n){n||(n=await e.getLatestBlockhash());const o={signature:t,blockhash:n.blockhash,lastValidBlockHeight:n.lastValidBlockHeight},s=await e.confirmTransaction(o,(null==r?void 0:r.commitment)||e.commitment||"confirmed"),i=s.context.slot;return await e.confirmTransactionIndexed(i),s}function gt(e,t,r,n=[],o){if(n.includes(t))throw new Error("payer must not be in additionalSigners");const s=[t,...n],i=pt(e,t.publicKey,r,o);return i.sign(s),i}var yt={},wt={};class vt{constructor(e,t){if(!Number.isInteger(e))throw new TypeError("span must be an integer");this.span=e,this.property=t}makeDestinationObject(){return{}}decode(e,t){throw new Error("Layout is abstract")}encode(e,t,r){throw new Error("Layout is abstract")}getSpan(e,t){if(0>this.span)throw new RangeError("indeterminate span");return this.span}replicate(e){const t=Object.create(this.constructor.prototype);return Object.assign(t,this),t.property=e,t}fromArray(e){}}function xt(e,t){return t.property?e+"["+t.property+"]":e}wt.Layout=vt,wt.nameWithProperty=xt,wt.bindConstructorLayout=function(e,t){if("function"!=typeof e)throw new TypeError("Class must be constructor");if(e.hasOwnProperty("layout_"))throw new Error("Class is already bound to a layout");if(!(t&&t instanceof vt))throw new TypeError("layout must be a Layout");if(t.hasOwnProperty("boundConstructor_"))throw new Error("layout is already bound to a constructor");e.layout_=t,t.boundConstructor_=e,t.makeDestinationObject=()=>new e,Object.defineProperty(e.prototype,"encode",{value:function(e,r){return t.encode(this,e,r)},writable:1}),Object.defineProperty(e,"decode",{value:function(e,r){return t.decode(e,r)},writable:1})};class bt extends vt{isCount(){throw new Error("ExternalLayout is abstract")}}class Et extends bt{constructor(e,t){if(void 0===e&&(e=1),!Number.isInteger(e)||0>=e)throw new TypeError("elementSpan must be a (positive) integer");super(-1,t),this.elementSpan=e}isCount(){return 1}decode(e,t){void 0===t&&(t=0);const r=e.length-t;return Math.floor(r/this.elementSpan)}encode(e,t,r){return 0}}class It extends bt{constructor(e,t,r){if(!(e instanceof vt))throw new TypeError("layout must be a Layout");if(void 0===t)t=0;else if(!Number.isInteger(t))throw new TypeError("offset must be integer or undefined");super(e.span,r||e.property),this.layout=e,this.offset=t}isCount(){return this.layout instanceof Mt||this.layout instanceof At}decode(e,t){return void 0===t&&(t=0),this.layout.decode(e,t+this.offset)}encode(e,t,r){return void 0===r&&(r=0),this.layout.encode(e,t,r+this.offset)}}class Mt extends vt{constructor(e,t){if(super(e,t),6<this.span)throw new RangeError("span must not exceed 6 bytes")}decode(e,t){return void 0===t&&(t=0),e.readUIntLE(t,this.span)}encode(e,t,r){return void 0===r&&(r=0),t.writeUIntLE(e,r,this.span),this.span}}class At extends vt{constructor(e,t){if(super(e,t),6<this.span)throw new RangeError("span must not exceed 6 bytes")}decode(e,t){return void 0===t&&(t=0),e.readUIntBE(t,this.span)}encode(e,t,r){return void 0===r&&(r=0),t.writeUIntBE(e,r,this.span),this.span}}class Tt extends vt{constructor(e,t){if(super(e,t),6<this.span)throw new RangeError("span must not exceed 6 bytes")}decode(e,t){return void 0===t&&(t=0),e.readIntLE(t,this.span)}encode(e,t,r){return void 0===r&&(r=0),t.writeIntLE(e,r,this.span),this.span}}class St extends vt{constructor(e,t){if(super(e,t),6<this.span)throw new RangeError("span must not exceed 6 bytes")}decode(e,t){return void 0===t&&(t=0),e.readIntBE(t,this.span)}encode(e,t,r){return void 0===r&&(r=0),t.writeIntBE(e,r,this.span),this.span}}const Ct=Math.pow(2,32);function kt(e){const t=Math.floor(e/Ct);return{hi32:t,lo32:e-t*Ct}}function _t(e,t){return e*Ct+t}class Pt extends vt{constructor(e){super(8,e)}decode(e,t){void 0===t&&(t=0);const r=e.readUInt32LE(t);return _t(e.readUInt32LE(t+4),r)}encode(e,t,r){void 0===r&&(r=0);const n=kt(e);return t.writeUInt32LE(n.lo32,r),t.writeUInt32LE(n.hi32,r+4),8}}class Lt extends vt{constructor(e){super(8,e)}decode(e,t){return void 0===t&&(t=0),_t(e.readUInt32BE(t),e.readUInt32BE(t+4))}encode(e,t,r){void 0===r&&(r=0);const n=kt(e);return t.writeUInt32BE(n.hi32,r),t.writeUInt32BE(n.lo32,r+4),8}}class Nt extends vt{constructor(e){super(8,e)}decode(e,t){void 0===t&&(t=0);const r=e.readUInt32LE(t);return _t(e.readInt32LE(t+4),r)}encode(e,t,r){void 0===r&&(r=0);const n=kt(e);return t.writeUInt32LE(n.lo32,r),t.writeInt32LE(n.hi32,r+4),8}}class Ot extends vt{constructor(e){super(8,e)}decode(e,t){return void 0===t&&(t=0),_t(e.readInt32BE(t),e.readUInt32BE(t+4))}encode(e,t,r){void 0===r&&(r=0);const n=kt(e);return t.writeInt32BE(n.hi32,r),t.writeUInt32BE(n.lo32,r+4),8}}class Bt extends vt{constructor(e){super(4,e)}decode(e,t){return void 0===t&&(t=0),e.readFloatLE(t)}encode(e,t,r){return void 0===r&&(r=0),t.writeFloatLE(e,r),4}}class Rt extends vt{constructor(e){super(4,e)}decode(e,t){return void 0===t&&(t=0),e.readFloatBE(t)}encode(e,t,r){return void 0===r&&(r=0),t.writeFloatBE(e,r),4}}class Dt extends vt{constructor(e){super(8,e)}decode(e,t){return void 0===t&&(t=0),e.readDoubleLE(t)}encode(e,t,r){return void 0===r&&(r=0),t.writeDoubleLE(e,r),8}}class Ut extends vt{constructor(e){super(8,e)}decode(e,t){return void 0===t&&(t=0),e.readDoubleBE(t)}encode(e,t,r){return void 0===r&&(r=0),t.writeDoubleBE(e,r),8}}class Ft extends vt{constructor(e,t,r){if(!(e instanceof vt))throw new TypeError("elementLayout must be a Layout");if(!(t instanceof bt&&t.isCount()||Number.isInteger(t)&&0<=t))throw new TypeError("count must be non-negative integer or an unsigned integer ExternalLayout");let n=-1;!(t instanceof bt)&&0<e.span&&(n=t*e.span),super(n,r),this.elementLayout=e,this.count=t}getSpan(e,t){if(0<=this.span)return this.span;void 0===t&&(t=0);let r=0,n=this.count;if(n instanceof bt&&(n=n.decode(e,t)),0<this.elementLayout.span)r=n*this.elementLayout.span;else{let o=0;for(;o<n;)r+=this.elementLayout.getSpan(e,t+r),++o}return r}decode(e,t){void 0===t&&(t=0);const r=[];let n=0,o=this.count;for(o instanceof bt&&(o=o.decode(e,t));n<o;)r.push(this.elementLayout.decode(e,t)),t+=this.elementLayout.getSpan(e,t),n+=1;return r}encode(e,t,r){void 0===r&&(r=0);const n=this.elementLayout,o=e.reduce(((e,o)=>e+n.encode(o,t,r+e)),0);return this.count instanceof bt&&this.count.encode(e.length,t,r),o}}class qt extends vt{constructor(e,t,r){if(!Array.isArray(e)||!e.reduce(((e,t)=>e&&t instanceof vt),1))throw new TypeError("fields must be array of Layout instances");"boolean"==typeof t&&void 0===r&&(r=t,t=void 0);for(const t of e)if(0>t.span&&void 0===t.property)throw new Error("fields cannot contain unnamed variable-length layout");let n=-1;try{n=e.reduce(((e,t)=>e+t.getSpan()),0)}catch(e){}super(n,t),this.fields=e,this.decodePrefixes=!!r}getSpan(e,t){if(0<=this.span)return this.span;void 0===t&&(t=0);let r=0;try{r=this.fields.reduce(((r,n)=>{const o=n.getSpan(e,t);return t+=o,r+o}),0)}catch(e){throw new RangeError("indeterminate span")}return r}decode(e,t){void 0===t&&(t=0);const r=this.makeDestinationObject();for(const n of this.fields)if(void 0!==n.property&&(r[n.property]=n.decode(e,t)),t+=n.getSpan(e,t),this.decodePrefixes&&e.length===t)break;return r}encode(e,t,r){void 0===r&&(r=0);const n=r;let o=0,s=0;for(const n of this.fields){let i=n.span;if(s=0<i?i:0,void 0!==n.property){const o=e[n.property];void 0!==o&&(s=n.encode(o,t,r),0>i&&(i=n.getSpan(t,r)))}o=r,r+=i}return o+s-n}fromArray(e){const t=this.makeDestinationObject();for(const r of this.fields)void 0!==r.property&&0<e.length&&(t[r.property]=e.shift());return t}layoutFor(e){if("string"!=typeof e)throw new TypeError("property must be string");for(const t of this.fields)if(t.property===e)return t}offsetOf(e){if("string"!=typeof e)throw new TypeError("property must be string");let t=0;for(const r of this.fields){if(r.property===e)return t;0>r.span?t=-1:0<=t&&(t+=r.span)}}}class Vt{constructor(e){this.property=e}decode(){throw new Error("UnionDiscriminator is abstract")}encode(){throw new Error("UnionDiscriminator is abstract")}}class Kt extends Vt{constructor(e,t){if(!(e instanceof bt&&e.isCount()))throw new TypeError("layout must be an unsigned integer ExternalLayout");super(t||e.property||"variant"),this.layout=e}decode(e,t){return this.layout.decode(e,t)}encode(e,t,r){return this.layout.encode(e,t,r)}}class Ht extends vt{constructor(e,t,r){const n=e instanceof Mt||e instanceof At;if(n)e=new Kt(new It(e));else if(e instanceof bt&&e.isCount())e=new Kt(e);else if(!(e instanceof Vt))throw new TypeError("discr must be a UnionDiscriminator or an unsigned integer layout");if(void 0===t&&(t=null),!(null===t||t instanceof vt))throw new TypeError("defaultLayout must be null or a Layout");if(null!==t){if(0>t.span)throw new Error("defaultLayout must have constant span");void 0===t.property&&(t=t.replicate("content"))}let o=-1;t&&(o=t.span,0<=o&&n&&(o+=e.layout.span)),super(o,r),this.discriminator=e,this.usesPrefixDiscriminator=n,this.defaultLayout=t,this.registry={};let s=this.defaultGetSourceVariant.bind(this);this.getSourceVariant=function(e){return s(e)},this.configGetSourceVariant=function(e){s=e.bind(this)}}getSpan(e,t){if(0<=this.span)return this.span;void 0===t&&(t=0);const r=this.getVariant(e,t);if(!r)throw new Error("unable to determine span for unrecognized variant");return r.getSpan(e,t)}defaultGetSourceVariant(e){if(e.hasOwnProperty(this.discriminator.property)){if(this.defaultLayout&&e.hasOwnProperty(this.defaultLayout.property))return;const t=this.registry[e[this.discriminator.property]];if(t&&(!t.layout||e.hasOwnProperty(t.property)))return t}else for(const t in this.registry){const r=this.registry[t];if(e.hasOwnProperty(r.property))return r}throw new Error("unable to infer src variant")}decode(e,t){let r;void 0===t&&(t=0);const n=this.discriminator,o=n.decode(e,t);let s=this.registry[o];if(void 0===s){let i=0;s=this.defaultLayout,this.usesPrefixDiscriminator&&(i=n.layout.span),r=this.makeDestinationObject(),r[n.property]=o,r[s.property]=this.defaultLayout.decode(e,t+i)}else r=s.decode(e,t);return r}encode(e,t,r){void 0===r&&(r=0);const n=this.getSourceVariant(e);if(void 0===n){const n=this.discriminator,o=this.defaultLayout;let s=0;return this.usesPrefixDiscriminator&&(s=n.layout.span),n.encode(e[n.property],t,r),s+o.encode(e[o.property],t,r+s)}return n.encode(e,t,r)}addVariant(e,t,r){const n=new $t(this,e,t,r);return this.registry[e]=n,n}getVariant(e,t){let r=e;return Buffer.isBuffer(e)&&(void 0===t&&(t=0),r=this.discriminator.decode(e,t)),this.registry[r]}}class $t extends vt{constructor(e,t,r,n){if(!(e instanceof Ht))throw new TypeError("union must be a Union");if(!Number.isInteger(t)||0>t)throw new TypeError("variant must be a (non-negative) integer");if("string"==typeof r&&void 0===n&&(n=r,r=null),r){if(!(r instanceof vt))throw new TypeError("layout must be a Layout");if(null!==e.defaultLayout&&0<=r.span&&r.span>e.defaultLayout.span)throw new Error("variant span exceeds span of containing union");if("string"!=typeof n)throw new TypeError("variant must have a String property")}let o=e.span;0>e.span&&(o=r?r.span:0,0<=o&&e.usesPrefixDiscriminator&&(o+=e.discriminator.layout.span)),super(o,n),this.union=e,this.variant=t,this.layout=r||null}getSpan(e,t){if(0<=this.span)return this.span;void 0===t&&(t=0);let r=0;return this.union.usesPrefixDiscriminator&&(r=this.union.discriminator.layout.span),r+this.layout.getSpan(e,t+r)}decode(e,t){const r=this.makeDestinationObject();if(void 0===t&&(t=0),this!==this.union.getVariant(e,t))throw new Error("variant mismatch");let n=0;return this.union.usesPrefixDiscriminator&&(n=this.union.discriminator.layout.span),this.layout?r[this.property]=this.layout.decode(e,t+n):this.property?r[this.property]=1:this.union.usesPrefixDiscriminator&&(r[this.union.discriminator.property]=this.variant),r}encode(e,t,r){void 0===r&&(r=0);let n=0;if(this.union.usesPrefixDiscriminator&&(n=this.union.discriminator.layout.span),this.layout&&!e.hasOwnProperty(this.property))throw new TypeError("variant lacks property "+this.property);this.union.discriminator.encode(this.variant,t,r);let o=n;if(this.layout&&(this.layout.encode(e[this.property],t,r+n),o+=this.layout.getSpan(t,r+n),0<=this.union.span&&o>this.union.span))throw new Error("encoded variant overruns containing union");return o}fromArray(e){if(this.layout)return this.layout.fromArray(e)}}function jt(e){return 0>e&&(e+=4294967296),e}class zt extends vt{constructor(e,t,r){if(!(e instanceof Mt||e instanceof At))throw new TypeError("word must be a UInt or UIntBE layout");if("string"==typeof t&&void 0===r&&(r=t,t=void 0),4<e.span)throw new RangeError("word cannot exceed 32 bits");super(e.span,r),this.word=e,this.msb=!!t,this.fields=[];let n=0;this._packedSetValue=function(e){return n=jt(e),this},this._packedGetValue=function(){return n}}decode(e,t){const r=this.makeDestinationObject();void 0===t&&(t=0);const n=this.word.decode(e,t);this._packedSetValue(n);for(const e of this.fields)void 0!==e.property&&(r[e.property]=e.decode(n));return r}encode(e,t,r){void 0===r&&(r=0);const n=this.word.decode(t,r);this._packedSetValue(n);for(const t of this.fields)if(void 0!==t.property){const r=e[t.property];void 0!==r&&t.encode(r)}return this.word.encode(this._packedGetValue(),t,r)}addField(e,t){const r=new Wt(this,e,t);return this.fields.push(r),r}addBoolean(e){const t=new Zt(this,e);return this.fields.push(t),t}fieldFor(e){if("string"!=typeof e)throw new TypeError("property must be string");for(const t of this.fields)if(t.property===e)return t}}class Wt{constructor(e,t,r){if(!(e instanceof zt))throw new TypeError("container must be a BitStructure");if(!Number.isInteger(t)||0>=t)throw new TypeError("bits must be positive integer");const n=8*e.span,o=e.fields.reduce(((e,t)=>e+t.bits),0);if(t+o>n)throw new Error("bits too long for span remainder ("+(n-o)+" of "+n+" remain)");this.container=e,this.bits=t,this.valueMask=(1<<t)-1,32===t&&(this.valueMask=4294967295),this.start=o,this.container.msb&&(this.start=n-o-t),this.wordMask=jt(this.valueMask<<this.start),this.property=r}decode(){return jt(this.container._packedGetValue()&this.wordMask)>>>this.start}encode(e){if(!Number.isInteger(e)||e!==jt(e&this.valueMask))throw new TypeError(xt("BitField.encode",this)+" value must be integer not exceeding "+this.valueMask);const t=this.container._packedGetValue(),r=jt(e<<this.start);this.container._packedSetValue(jt(t&~this.wordMask)|r)}}class Zt extends Wt{constructor(e,t){super(e,1,t)}decode(e,t){return!!Wt.prototype.decode.call(this,e,t)}encode(e){return"boolean"==typeof e&&(e=+e),Wt.prototype.encode.call(this,e)}}class Jt extends vt{constructor(e,t){if(!(e instanceof bt&&e.isCount()||Number.isInteger(e)&&0<=e))throw new TypeError("length must be positive integer or an unsigned integer ExternalLayout");let r=-1;e instanceof bt||(r=e),super(r,t),this.length=e}getSpan(e,t){let r=this.span;return 0>r&&(r=this.length.decode(e,t)),r}decode(e,t){void 0===t&&(t=0);let r=this.span;return 0>r&&(r=this.length.decode(e,t)),e.slice(t,t+r)}encode(e,t,r){let n=this.length;if(this.length instanceof bt&&(n=e.length),!Buffer.isBuffer(e)||n!==e.length)throw new TypeError(xt("Blob.encode",this)+" requires (length "+n+") Buffer as src");if(r+n>t.length)throw new RangeError("encoding overruns Buffer");return t.write(e.toString("hex"),r,n,"hex"),this.length instanceof bt&&this.length.encode(n,t,r),n}}class Qt extends vt{constructor(e){super(-1,e)}getSpan(e,t){if(!Buffer.isBuffer(e))throw new TypeError("b must be a Buffer");void 0===t&&(t=0);let r=t;for(;r<e.length&&0!==e[r];)r+=1;return 1+r-t}decode(e,t,r){void 0===t&&(t=0);let n=this.getSpan(e,t);return e.slice(t,t+n-1).toString("utf-8")}encode(e,t,r){void 0===r&&(r=0),"string"!=typeof e&&(e=e.toString());const n=new Buffer(e,"utf8"),o=n.length;if(r+o>t.length)throw new RangeError("encoding overruns Buffer");return n.copy(t,r),t[r+o]=0,o+1}}class Gt extends vt{constructor(e,t){if("string"==typeof e&&void 0===t&&(t=e,e=void 0),void 0===e)e=-1;else if(!Number.isInteger(e))throw new TypeError("maxSpan must be an integer");super(-1,t),this.maxSpan=e}getSpan(e,t){if(!Buffer.isBuffer(e))throw new TypeError("b must be a Buffer");return void 0===t&&(t=0),e.length-t}decode(e,t,r){void 0===t&&(t=0);let n=this.getSpan(e,t);if(0<=this.maxSpan&&this.maxSpan<n)throw new RangeError("text length exceeds maxSpan");return e.slice(t,t+n).toString("utf-8")}encode(e,t,r){void 0===r&&(r=0),"string"!=typeof e&&(e=e.toString());const n=new Buffer(e,"utf8"),o=n.length;if(0<=this.maxSpan&&this.maxSpan<o)throw new RangeError("text length exceeds maxSpan");if(r+o>t.length)throw new RangeError("encoding overruns Buffer");return n.copy(t,r),o}}class Xt extends vt{constructor(e,t){super(0,t),this.value=e}decode(e,t,r){return this.value}encode(e,t,r){return 0}}wt.ExternalLayout=bt,wt.GreedyCount=Et,wt.OffsetLayout=It,wt.UInt=Mt,wt.UIntBE=At,wt.Int=Tt,wt.IntBE=St,wt.Float=Bt,wt.FloatBE=Rt,wt.Double=Dt,wt.DoubleBE=Ut,wt.Sequence=Ft,wt.Structure=qt,wt.UnionDiscriminator=Vt,wt.UnionLayoutDiscriminator=Kt,wt.Union=Ht,wt.VariantLayout=$t,wt.BitStructure=zt,wt.BitField=Wt,wt.Boolean=Zt,wt.Blob=Jt,wt.CString=Qt,wt.UTF8=Gt,wt.Constant=Xt,wt.greedy=(e,t)=>new Et(e,t),wt.offset=(e,t,r)=>new It(e,t,r),wt.u8=e=>new Mt(1,e),wt.u16=e=>new Mt(2,e),wt.u24=e=>new Mt(3,e),wt.u32=e=>new Mt(4,e),wt.u40=e=>new Mt(5,e),wt.u48=e=>new Mt(6,e),wt.nu64=e=>new Pt(e),wt.u16be=e=>new At(2,e),wt.u24be=e=>new At(3,e),wt.u32be=e=>new At(4,e),wt.u40be=e=>new At(5,e),wt.u48be=e=>new At(6,e),wt.nu64be=e=>new Lt(e),wt.s8=e=>new Tt(1,e),wt.s16=e=>new Tt(2,e),wt.s24=e=>new Tt(3,e),wt.s32=e=>new Tt(4,e),wt.s40=e=>new Tt(5,e),wt.s48=e=>new Tt(6,e),wt.ns64=e=>new Nt(e),wt.s16be=e=>new St(2,e),wt.s24be=e=>new St(3,e),wt.s32be=e=>new St(4,e),wt.s40be=e=>new St(5,e),wt.s48be=e=>new St(6,e),wt.ns64be=e=>new Ot(e),wt.f32=e=>new Bt(e),wt.f32be=e=>new Rt(e),wt.f64=e=>new Dt(e),wt.f64be=e=>new Ut(e),wt.struct=(e,t,r)=>new qt(e,t,r),wt.bits=(e,t,r)=>new zt(e,t,r),wt.seq=(e,t,r)=>new Ft(e,t,r),wt.union=(e,t,r)=>new Ht(e,t,r),wt.unionLayoutDiscriminator=(e,t)=>new Kt(e,t),wt.blob=(e,t)=>new Jt(e,t),wt.cstr=e=>new Qt(e),wt.utf8=(e,t)=>new Gt(e,t),wt.const=(e,t)=>new Xt(e,t),function(t){var n=r&&r.__importDefault||function(e){return e&&e.__esModule?e:{default:e}};Object.defineProperty(t,"__esModule",{value:1}),t.map=t.array=t.rustEnum=t.str=t.vecU8=t.tagged=t.vec=t.bool=t.option=t.publicKey=t.i256=t.u256=t.i128=t.u128=t.i64=t.u64=t.struct=t.f64=t.f32=t.i32=t.u32=t.i16=t.u16=t.i8=t.u8=void 0;const o=wt,s=e,a=n(i);var u=wt;Object.defineProperty(t,"u8",{enumerable:1,get:function(){return u.u8}}),Object.defineProperty(t,"i8",{enumerable:1,get:function(){return u.s8}}),Object.defineProperty(t,"u16",{enumerable:1,get:function(){return u.u16}}),Object.defineProperty(t,"i16",{enumerable:1,get:function(){return u.s16}}),Object.defineProperty(t,"u32",{enumerable:1,get:function(){return u.u32}}),Object.defineProperty(t,"i32",{enumerable:1,get:function(){return u.s32}}),Object.defineProperty(t,"f32",{enumerable:1,get:function(){return u.f32}}),Object.defineProperty(t,"f64",{enumerable:1,get:function(){return u.f64}}),Object.defineProperty(t,"struct",{enumerable:1,get:function(){return u.struct}});class c extends o.Layout{constructor(e,t,r){super(e,r),this.blob=(0,o.blob)(e),this.signed=t}decode(e,t=0){const r=new a.default(this.blob.decode(e,t),10,"le");return this.signed?r.fromTwos(8*this.span).clone():r}encode(e,t,r=0){return this.signed&&(e=e.toTwos(8*this.span)),this.blob.encode(e.toArrayLike(Buffer,"le",this.span),t,r)}}function l(e){return new c(8,0,e)}t.u64=l,t.i64=function(e){return new c(8,1,e)},t.u128=function(e){return new c(16,0,e)},t.i128=function(e){return new c(16,1,e)},t.u256=function(e){return new c(32,0,e)},t.i256=function(e){return new c(32,1,e)};class d extends o.Layout{constructor(e,t,r,n){super(e.span,n),this.layout=e,this.decoder=t,this.encoder=r}decode(e,t){return this.decoder(this.layout.decode(e,t))}encode(e,t,r){return this.layout.encode(this.encoder(e),t,r)}getSpan(e,t){return this.layout.getSpan(e,t)}}t.publicKey=function(e){return new d((0,o.blob)(32),(e=>new s.PublicKey(e)),(e=>e.toBuffer()),e)};class h extends o.Layout{constructor(e,t){super(-1,t),this.layout=e,this.discriminator=(0,o.u8)()}encode(e,t,r=0){return null==e?this.discriminator.encode(0,t,r):(this.discriminator.encode(1,t,r),this.layout.encode(e,t,r+1)+1)}decode(e,t=0){const r=this.discriminator.decode(e,t);if(0===r)return null;if(1===r)return this.layout.decode(e,t+1);throw new Error("Invalid option "+this.property)}getSpan(e,t=0){const r=this.discriminator.decode(e,t);if(0===r)return 1;if(1===r)return this.layout.getSpan(e,t+1)+1;throw new Error("Invalid option "+this.property)}}function p(e){if(0===e)return 0;if(1===e)return 1;throw new Error("Invalid bool: "+e)}function f(e){return e?1:0}function m(e){const t=(0,o.u32)("length"),r=(0,o.struct)([t,(0,o.blob)((0,o.offset)(t,-t.span),"data")]);return new d(r,(({data:e})=>e),(e=>({data:e})),e)}t.option=function(e,t){return new h(e,t)},t.bool=function(e){return new d((0,o.u8)(),p,f,e)},t.vec=function(e,t){const r=(0,o.u32)("length"),n=(0,o.struct)([r,(0,o.seq)(e,(0,o.offset)(r,-r.span),"values")]);return new d(n,(({values:e})=>e),(e=>({values:e})),t)},t.tagged=function(e,t,r){const n=(0,o.struct)([l("tag"),t.replicate("data")]);return new d(n,(function({tag:t,data:r}){if(!t.eq(e))throw new Error("Invalid tag, expected: "+e.toString("hex")+", got: "+t.toString("hex"));return r}),(t=>({tag:e,data:t})),r)},t.vecU8=m,t.str=function(e){return new d(m(),(e=>e.toString("utf-8")),(e=>Buffer.from(e,"utf-8")),e)},t.rustEnum=function(e,t,r){const n=(0,o.union)(null!=r?r:(0,o.u8)(),t);return e.forEach(((e,t)=>n.addVariant(t,e,e.property))),n},t.array=function(e,t,r){const n=(0,o.struct)([(0,o.seq)(e,t,"values")]);return new d(n,(({values:e})=>e),(e=>({values:e})),r)};class g extends o.Layout{constructor(e,t,r){super(e.span+t.span,r),this.keyLayout=e,this.valueLayout=t}decode(e,t){return t=t||0,[this.keyLayout.decode(e,t),this.valueLayout.decode(e,t+this.keyLayout.getSpan(e,t))]}encode(e,t,r){r=r||0;const n=this.keyLayout.encode(e[0],t,r);return n+this.valueLayout.encode(e[1],t,r+n)}getSpan(e,t){return this.keyLayout.getSpan(e,t)+this.valueLayout.getSpan(e,t)}}t.map=function(e,t,r){const n=(0,o.u32)("length"),s=(0,o.struct)([n,(0,o.seq)(new g(e,t),(0,o.offset)(n,-n.span),"values")]);return new d(s,(({values:e})=>new Map(e)),(e=>({values:Array.from(e.entries())})),r)}}(yt);const Yt=yt.struct([yt.publicKey("owner"),yt.u64("lamports"),yt.option(yt.array(yt.u8(),32),"address"),yt.option(yt.struct([yt.array(yt.u8(),8,"discriminator"),yt.vecU8("data"),yt.array(yt.u8(),32,"dataHash")]),"data")],"compressedAccount"),er=yt.struct([yt.u8("merkleTreePubkeyIndex"),yt.u8("nullifierQueuePubkeyIndex"),yt.u32("leafIndex"),yt.option(yt.struct([yt.u8("queueId"),yt.u16("index")]),"queueIndex")],"merkleContext"),tr=yt.struct([yt.array(yt.u8(),32,"seed"),yt.u8("addressQueueAccountIndex"),yt.u8("addressMerkleTreeAccountIndex"),yt.u16("addressMerkleTreeRootIndex")],"newAddressParams"),rr=yt.struct([yt.option(yt.struct([yt.array(yt.u8(),32,"a"),yt.array(yt.u8(),64,"b"),yt.array(yt.u8(),32,"c")]),"proof"),yt.vec(yt.struct([Yt,er,yt.u16("rootIndex"),yt.bool("readOnly")]),"inputCompressedAccountsWithMerkleContext"),yt.vec(yt.struct([Yt,yt.u8("merkleTreeIndex")]),"outputCompressedAccounts"),yt.option(yt.u64(),"relayFee"),yt.vec(tr,"newAddressParams"),yt.option(yt.u64(),"compressOrDecompressLamports"),yt.bool("isCompress")]);function nr(e){const r=t.Buffer.alloc(1e3),n=rr.encode(e,r),o=t.Buffer.from(new Uint8Array(r.slice(0,n))),s=t.Buffer.alloc(4);return s.writeUInt32LE(n,0),t.Buffer.concat([new Uint8Array(d),new Uint8Array(s),new Uint8Array(o)])}const or=yt.struct([yt.option(yt.struct([yt.array(yt.u8(),32,"a"),yt.array(yt.u8(),64,"b"),yt.array(yt.u8(),32,"c")]),"proof"),yt.vec(tr,"newAddressParams"),yt.vec(yt.struct([Yt,er,yt.u16("rootIndex"),yt.bool("readOnly")]),"inputCompressedAccountsWithMerkleContext"),yt.vec(yt.struct([Yt,yt.u8("merkleTreeIndex")]),"outputCompressedAccounts"),yt.option(yt.u64(),"relayFee"),yt.option(yt.u64(),"compressOrDecompressLamports"),yt.bool("isCompress"),yt.option(yt.struct([yt.bool("set_context"),yt.bool("first_set_context"),yt.u8("cpi_context_account_index")]),"compressedCpiContext")]);function sr(e){return rr.decode(e.slice(d.length+4))}function ir(e){return or.decode(e.slice(h.length+4))}const ar=e=>{const t=vr.programId,{feePayer:r,authority:n,registeredProgramPda:o,noopProgram:s,accountCompressionAuthority:i,accountCompressionProgram:a,solPoolPda:u,decompressionRecipient:c,systemProgram:l}=e;return[{pubkey:r,isSigner:1,isWritable:1},{pubkey:n,isSigner:1,isWritable:0},{pubkey:o,isSigner:0,isWritable:0},{pubkey:s,isSigner:0,isWritable:0},{pubkey:i,isSigner:0,isWritable:0},{pubkey:a,isSigner:0,isWritable:0},{pubkey:null!=u?u:t,isSigner:0,isWritable:null!==u},{pubkey:null!=c?c:t,isSigner:0,isWritable:1},{pubkey:l,isSigner:0,isWritable:0}]},ur=yt.struct([yt.vec(yt.array(yt.u8(),32),"inputCompressedAccountHashes"),yt.vec(yt.array(yt.u8(),32),"outputCompressedAccountHashes"),yt.vec(yt.struct([yt.struct([yt.publicKey("owner"),yt.u64("lamports"),yt.option(yt.array(yt.u8(),32),"address"),yt.option(yt.struct([yt.array(yt.u8(),8,"discriminator"),yt.vecU8("data"),yt.array(yt.u8(),32,"dataHash")]),"data")],"compressedAccount"),yt.u8("merkleTreeIndex")]),"outputCompressedAccounts"),yt.vec(yt.u32(),"outputLeafIndices"),yt.vec(yt.struct([yt.publicKey("pubkey"),yt.u64("seq")]),"sequenceNumbers"),yt.option(yt.u64(),"relayFee"),yt.bool("isCompress"),yt.option(yt.u64(),"compressOrDecompressLamports"),yt.vec(yt.publicKey(),"pubkeyArray"),yt.option(yt.vecU8(),"message")]);function cr(e){return ur.decode(e)}const lr=yt.struct([yt.u8("is_invoked_by_program"),yt.u8("bump"),yt.u8("num_queues"),yt.u8("num_output_queues"),yt.u8("start_output_appends"),yt.u8("num_address_queues"),yt.array(yt.u8(),32,"tx_hash")],"appendNullifyCreateAddressInputsMeta"),dr=yt.struct([yt.u8("index"),yt.array(yt.u8(),32,"leaf")],"appendLeavesInput"),hr=yt.struct([yt.array(yt.u8(),32,"account_hash"),yt.u32("leaf_index"),yt.u8("prove_by_index"),yt.u8("tree_index"),yt.u8("queue_index")],"insertNullifierInput"),pr=yt.struct([yt.array(yt.u8(),32,"address"),yt.u8("tree_index"),yt.u8("queue_index")],"insertAddressInput"),fr=yt.struct([yt.publicKey("pubkey"),yt.u64("seq")],"merkleTreeSequenceNumber");function mr(e){let t=0;const r=lr.decode(e,t);t+=lr.span;const n=e.readUInt8(t);t+=1;const o=[];for(let r=0;r<n;r++){const r=dr.decode(e,t);o.push(r),t+=dr.span}const s=e.readUInt8(t);t+=1;const i=[];for(let r=0;r<s;r++){const r=hr.decode(e,t);i.push(r),t+=hr.span}const a=e.readUInt8(t);t+=1;const u=[];for(let r=0;r<a;r++){const r=pr.decode(e,t);u.push(r),t+=pr.span}const c=e.readUInt8(t);t+=1;const l=[];for(let r=0;r<c;r++){const r=fr.decode(e,t);l.push(r),t+=fr.span}const d=e.readUInt8(t);t+=1;for(let r=0;r<d;r++)fr.decode(e,t),t+=fr.span;const h=e.readUInt8(t);t+=1;for(let r=0;r<h;r++)fr.decode(e,t),t+=fr.span;const p=e.readUInt8(t);t+=1;const f=[];for(let r=0;r<p;r++){const r=yt.u32().decode(e,t);f.push(r),t+=4}return{meta:r,leaves:o,nullifiers:i,addresses:u,sequence_numbers:l,output_leaf_indices:f}}function gr(r,n,o){const s=e=>Array.from(e instanceof t.Buffer?new Uint8Array(e):e);return{inputCompressedAccountHashes:r.nullifiers.map((e=>s(e.account_hash))),outputCompressedAccountHashes:r.leaves.map((e=>s(e.leaf))),outputCompressedAccounts:r.leaves.map(((r,n)=>{var i,a,u,c,l,d;return{compressedAccount:{owner:new e.PublicKey((null===(i=null==o?void 0:o.outputCompressedAccounts[n])||void 0===i?void 0:i.compressedAccount.owner)||e.PublicKey.default),lamports:W((null===(a=null==o?void 0:o.outputCompressedAccounts[n])||void 0===a?void 0:a.compressedAccount.lamports)||0),address:null==o?void 0:o.outputCompressedAccounts[n].compressedAccount.address,data:(null===(u=null==o?void 0:o.outputCompressedAccounts[n])||void 0===u?void 0:u.compressedAccount.data)?{discriminator:s(t.Buffer.from(null===(c=o.outputCompressedAccounts[n].compressedAccount.data)||void 0===c?void 0:c.discriminator)),data:null!==(l=s(t.Buffer.from(new Uint8Array(o.outputCompressedAccounts[n].compressedAccount.data.data))))&&void 0!==l?l:[],dataHash:s(t.Buffer.from(null===(d=o.outputCompressedAccounts[n].compressedAccount.data)||void 0===d?void 0:d.dataHash))}:null},merkleTreeIndex:r.index}})),outputLeafIndices:r.output_leaf_indices,sequenceNumbers:r.sequence_numbers.map((t=>({pubkey:new e.PublicKey(t.pubkey),seq:W(t.seq)}))),pubkeyArray:n.slice(2).filter((t=>!t.equals(e.PublicKey.default))),isCompress:(null==o?void 0:o.isCompress)||0,relayFee:(null==o?void 0:o.relayFee)?W(o.relayFee):null,compressOrDecompressLamports:(null==o?void 0:o.compressOrDecompressLamports)?W(o.compressOrDecompressLamports):null,message:null}}const yr=e=>e.reduce(((e,t)=>e.add(W(t.lamports))),W(0)),wr=t.Buffer.from("sol_pool_pda");class vr{constructor(){}static deriveCompressedSolPda(){const t=[wr],[r,n]=e.PublicKey.findProgramAddressSync(t,this.programId);return r}static createTransferOutputState(e,t,r){r=W(r);const n=yr(e).sub(r);return te(n),n.eq(W(0))?[Z(t,r)]:(re(e),[Z(e[0].owner,n),Z(t,r)])}static createDecompressOutputState(e,t){t=W(t);const r=yr(e).sub(t);return te(r),r.eq(W(0))?[]:(re(e),[Z(e[0].owner,r)])}static createNewAddressOutputState(e,t,r,n){r=W(null!=r?r:0);const o=yr(null!=n?n:[]).sub(r);return te(o),o.eq(W(0))||!n?[Z(t,r,void 0,e)]:(re(n),[Z(n[0].owner,o),Z(t,r,void 0,e)])}static async createAccount({payer:t,newAddressParams:r,newAddress:n,recentValidityProof:o,outputStateTreeInfo:s,inputCompressedAccounts:i,inputStateRootIndices:a,lamports:u}){const c=this.createNewAddressOutputState(n,t,u,i),{packedInputCompressedAccounts:l,packedOutputCompressedAccounts:d,remainingAccounts:h}=ee(null!=i?i:[],null!=a?a:[],c,i&&0!==i.length?void 0:s),{newAddressParamsPacked:p,remainingAccounts:f}=nt([r],h),m=nr({proof:o,inputCompressedAccountsWithMerkleContext:l,outputCompressedAccounts:d,relayFee:null,newAddressParams:p,compressOrDecompressLamports:null,isCompress:0}),g=[...ar(Object.assign(Object.assign({},v()),{feePayer:t,authority:t,solPoolPda:null,decompressionRecipient:null,systemProgram:e.SystemProgram.programId})),...Y(f)];return new e.TransactionInstruction({programId:this.programId,keys:g,data:m})}static async transfer({payer:t,inputCompressedAccounts:r,toAddress:n,lamports:o,recentInputStateRootIndices:s,recentValidityProof:i}){const a=this.createTransferOutputState(r,n,o),{packedInputCompressedAccounts:u,packedOutputCompressedAccounts:c,remainingAccounts:l}=ee(r,s,a),d=nr({proof:i,inputCompressedAccountsWithMerkleContext:u,outputCompressedAccounts:c,relayFee:null,newAddressParams:[],compressOrDecompressLamports:null,isCompress:0}),h=[...ar(Object.assign(Object.assign({},v()),{feePayer:t,authority:t,solPoolPda:null,decompressionRecipient:null,systemProgram:e.SystemProgram.programId})),...Y(l)];return new e.TransactionInstruction({programId:this.programId,keys:h,data:d})}static async compress({payer:t,toAddress:r,lamports:n,outputStateTreeInfo:o}){n=W(n);const s=Z(r,n),{packedInputCompressedAccounts:i,packedOutputCompressedAccounts:a,remainingAccounts:u}=ee([],[],[s],o),c=nr({proof:null,inputCompressedAccountsWithMerkleContext:i,outputCompressedAccounts:a,relayFee:null,newAddressParams:[],compressOrDecompressLamports:n,isCompress:1}),l=[...ar(Object.assign(Object.assign({},v()),{feePayer:t,authority:t,solPoolPda:vr.deriveCompressedSolPda(),decompressionRecipient:null,systemProgram:e.SystemProgram.programId})),...Y(u)];return new e.TransactionInstruction({programId:this.programId,keys:l,data:c})}static async decompress({payer:t,inputCompressedAccounts:r,toAddress:n,lamports:o,recentInputStateRootIndices:s,recentValidityProof:i}){o=W(o);const a=this.createDecompressOutputState(r,o),{packedInputCompressedAccounts:u,packedOutputCompressedAccounts:c,remainingAccounts:l}=ee(r,s,a),d=nr({proof:i,inputCompressedAccountsWithMerkleContext:u,outputCompressedAccounts:c,relayFee:null,newAddressParams:[],compressOrDecompressLamports:o,isCompress:0}),h=[...ar(Object.assign(Object.assign({},v()),{feePayer:t,authority:t,solPoolPda:vr.deriveCompressedSolPda(),decompressionRecipient:n,systemProgram:e.SystemProgram.programId})),...Y(l)];return new e.TransactionInstruction({programId:this.programId,keys:h,data:d})}}function xr(e,t){let r=W(0);t=W(t);const n=[];e.sort(((e,t)=>t.lamports.cmp(e.lamports)));for(const o of e){if(r.gte(W(t)))break;r=r.add(o.lamports),n.push(o)}if(r.lt(W(t)))throw new Error(`Insufficient balance for transfer. Required: ${t.toString()}, available: ${r.toString()}`);return[n,r]}vr.programId=new e.PublicKey("SySTEM1eSU2p4BGQfQpimFEWWSC1XDFeun3Nqzz3rT7");class br{constructor(e,t,r){this.index=e,this.value=t,this.nextIndex=r}equals(e){return this.value.eq(e.value)}compareTo(e){return this.value.cmp(e.value)}hash(e,t){try{return e.poseidonHash([W(this.value.toArray("be",32)).toString(),W(this.nextIndex).toString(),W(t.toArray("be",32)).toString()])}catch(e){throw new Error("Hashing failed")}}}class Er{constructor(e,t,r){this.newLowElement=e,this.newElement=t,this.newElementNextValue=r}}class Ir{constructor(e,t,r){this.elements=e,this.currentNodeIndex=t,this.highestElementIndex=r}static default(){return new Ir([new br(0,W(0),0)],0,0)}get(e){return this.elements[e]}length(){return Number(this.currentNodeIndex)}isEmpty(){return 0===this.currentNodeIndex}findElement(e){return this.elements.slice(0,this.length()+1).find((t=>t.value===e))}init(){try{const e=c;return this.append(e)}catch(e){throw new Error(`Failed to initialize IndexedArray: ${e}`)}}findLowElementIndex(e){for(let t=0;t<=this.length();t++){const r=this.elements[t];if(this.elements[r.nextIndex].value.gt(e)&&r.value.lt(e))return t;if(r.value.eq(e))throw new Error("Element already exists in the array")}return this.highestElementIndex}findLowElement(e){const t=this.findLowElementIndex(e);if(void 0===t)return[void 0,void 0];const r=this.elements[t];return[r,this.elements[r.nextIndex].value]}hashElement(e,t){const r=this.elements[t];if(!r)return;const n=this.elements[r.nextIndex];return n?e.poseidonHash([W(r.value.toArray("be",32)).toString(),W(r.nextIndex).toString(),W(n.value.toArray("be",32)).toString()]):void 0}append(e){const t=this.findLowElementIndex(e);if(void 0===t)throw new Error("Low element index not found.");return this.appendWithLowElementIndex(t,e)}appendWithLowElementIndex(e,t){const r=this.elements[e];if(0===r.nextIndex){if(t.lte(r.value))throw new Error("New element value must be greater than the low element value.")}else{const e=this.elements[r.nextIndex];if(t.lte(r.value))throw new Error("New element value must be greater than the low element value.");if(t.gte(e.value))throw new Error("New element value must be less than the next element value.")}const n=this.newElementWithLowElementIndex(e,t);return 0===r.nextIndex&&(this.highestElementIndex=n.newElement.index),this.currentNodeIndex=n.newElement.index,this.elements[this.length()]=n.newElement,this.elements[e]=n.newLowElement,n}lowest(){return this.elements.length>0?this.elements[0]:void 0}newElementWithLowElementIndex(e,t){const r=this.elements[e],n=this.currentNodeIndex+1,o=new br(n,t,r.nextIndex);r.nextIndex=n;const s=this.elements[o.nextIndex].value;return new Er(r,o,s)}newElement(e){const t=this.findLowElementIndex(e);if(void 0===t)throw new Error("Low element index not found.");return this.newElementWithLowElementIndex(t,e)}}class Mr{constructor(e,t,r=[],{zeroElement:n="0"}={}){if(this.levels=e,this.capacity=2**e,this.zeroElement=n,this._lightWasm=t,r.length>this.capacity)throw new Error("Tree is full");this._zeros=[],this._layers=[],this._layers[0]=r,this._zeros[0]=this.zeroElement;for(let t=1;t<=e;t++)this._zeros[t]=this._lightWasm.poseidonHashString([this._zeros[t-1],this._zeros[t-1]]);this._rebuild()}_rebuild(){for(let e=1;e<=this.levels;e++){this._layers[e]=[];for(let t=0;t<Math.ceil(this._layers[e-1].length/2);t++)this._layers[e][t]=this._lightWasm.poseidonHashString([this._layers[e-1][2*t],2*t+1<this._layers[e-1].length?this._layers[e-1][2*t+1]:this._zeros[e-1]])}}root(){return this._layers[this.levels].length>0?this._layers[this.levels][0]:this._zeros[this.levels]}insert(e){if(this._layers[0].length>=this.capacity)throw new Error("Tree is full");this.update(this._layers[0].length,e)}bulkInsert(e){if(this._layers[0].length+e.length>this.capacity)throw new Error("Tree is full");this._layers[0].push(...e),this._rebuild()}update(e,t){if(isNaN(Number(e))||e<0||e>this._layers[0].length||e>=this.capacity)throw new Error("Insert index out of bounds: "+e);this._layers[0][e]=t;for(let t=1;t<=this.levels;t++)e>>=1,this._layers[t][e]=this._lightWasm.poseidonHashString([this._layers[t-1][2*e],2*e+1<this._layers[t-1].length?this._layers[t-1][2*e+1]:this._zeros[t-1]])}path(e){if(isNaN(Number(e))||e<0||e>=this._layers[0].length)throw new Error("Index out of bounds: "+e);const t=[],r=[];for(let n=0;n<this.levels;n++)r[n]=e%2,t[n]=(1^e)<this._layers[n].length?this._layers[n][1^e]:this._zeros[n],e>>=1;return{pathElements:t,pathIndices:r}}indexOf(e,t=null){return t?this._layers[0].findIndex((r=>t(e,r))):this._layers[0].indexOf(e)}elements(){return this._layers[0].slice()}serialize(){return{levels:this.levels,_zeros:this._zeros,_layers:this._layers}}static deserialize(e,t){const r=Object.assign(Object.create(this.prototype),e);return r._hash=t,r.capacity=2**r.levels,r.zeroElement=r._zeros[0],r}}async function Ar(e){const t=[],{noopProgram:r,accountCompressionProgram:n}=v(),o=(await e.getConfirmedSignaturesForAddress2(n,void 0,"confirmed")).map((e=>e.signature)),s=await e.getParsedTransactions(o,{maxSupportedTransactionVersion:0,commitment:"confirmed"});for(const r of s){if(!r||!r.transaction||!r.meta)continue;if(!r.meta.innerInstructions||0==r.meta.innerInstructions.length)continue;const n=r.transaction.message.accountKeys.map((e=>e.pubkey)),o=[],s=await e.getTransaction(r.transaction.signatures[0],{commitment:"confirmed",maxSupportedTransactionVersion:0});for(const e of(null==s?void 0:s.transaction.message.compiledInstructions)||[])if(e.data&&e.data.length>0){const t=Uint8Array.from(e.data);if(t.length===l.length&&l.every(((e,r)=>e===t[r])))continue;o.push(t)}const i=[];if(s.meta.innerInstructions&&s.meta.innerInstructions.length>0)for(const e of s.meta.innerInstructions)for(const t of e.instructions){const e=t.accounts.map((e=>n[e]));if(i.push(e),t.data&&t.data.length>0){const e=$.decode(t.data);o.push(e)}}const a=Cr(o,i);a&&t.push(a)}if(t.length>0)return t;const i=s.filter((e=>e?e.transaction.message.accountKeys.some((e=>("string"==typeof e?e:e.pubkey.toBase58())===r.toBase58())):0));return Tr(i,Sr)}const Tr=(e,r)=>{const{noopProgram:n}=v(),o=[];return e.forEach((e=>{!e||!e.meta||e.meta.err||!e.meta.innerInstructions||e.meta.innerInstructions.length<=0||e.meta.innerInstructions.forEach((s=>{if(s.instructions.length>0){const i=s.instructions[s.instructions.length-1];if("data"in i&&i.data&&i.programId.toBase58()===n.toBase58()){const n=$.decode(i.data),s=r(t.Buffer.from(n),e);null!=s&&o.push(s)}}}))})),o},Sr=e=>{const r=t.Buffer.from(e.map((e=>e)));try{return cr(r)}catch(e){return console.error("Error deserializing event:",e),null}};function Cr(e,r){let n=0,o=null,s=null;for(const r of e){const e=r.slice(0,8),s=$.encode(e),i=$.encode(d),a=$.encode(h);if(s===i){o=sr(t.Buffer.from(r)),n=1;break}if(s==a){o=ir(t.Buffer.from(r)),n=1;break}}if(!n)return null;for(const r of e){const e=r.slice(0,8);if($.encode(e)===$.encode(p)){const e=r.slice(12);s=mr(t.Buffer.from(e))}}return o?gr(s,r[r.length-1],o):null}function kr(e,t){if(e.some((e=>e.queue.equals(t))))throw new Error("Checking by queue not supported yet");const r=e.findIndex((e=>e.tree.equals(t)));if(-1!==r){const{queue:t,treeType:n}=e[r];if(!t)throw new Error("Queue must not be null for state tree");return{queue:t,treeType:n,tree:e[r].tree,cpiContext:e[r].cpiContext,nextTreeInfo:e[r].nextTreeInfo}}throw new Error(`No associated StateTreeInfo found for tree or queue. Please set activeStateTreeInfos with latest Tree accounts. If you use custom state trees, set manually. Pubkey: ${t.toBase58()}`)}async function _r(e,t){return(await Pr(e)).find((e=>W(e.hash).eq(t)))}async function Pr(t){var r,n;const o=(await Ar(t)).reverse(),s=[],i=[],a=await t.getStateTreeInfos();for(const t of o){for(let o=0;o<t.outputCompressedAccounts.length;o++){const i=t.pubkeyArray[t.outputCompressedAccounts[o].merkleTreeIndex],u=kr(a,new e.PublicKey(i)),c=t.outputCompressedAccounts[o],l={treeInfo:u,hash:W(t.outputCompressedAccountHashes[o]),leafIndex:t.outputLeafIndices[o],proveByIndex:0},d=J(l,c.compressedAccount.owner,c.compressedAccount.lamports,null!==(r=c.compressedAccount.data)&&void 0!==r?r:void 0,null!==(n=c.compressedAccount.address)&&void 0!==n?n:void 0);s.push(d)}for(let e=0;e<t.inputCompressedAccountHashes.length;e++){const r=t.inputCompressedAccountHashes[e];i.push(W(r))}}const u=s.filter((e=>!i.some((t=>t.eq(W(e.hash))))));return u.sort(((e,t)=>t.leafIndex-e.leafIndex)),u}const Lr=yt.struct([yt.publicKey("mint"),yt.publicKey("owner"),yt.u64("amount"),yt.option(yt.publicKey(),"delegate"),yt.u8("state"),yt.option(yt.vecU8(),"tlv")]);function Nr(e,t=A){if(null===e.data)return null;const{data:r}=e.data;if(0===r.length)return null;if(e.owner.toBase58()!==t.toBase58())throw new Error(`Invalid owner ${e.owner.toBase58()} for token layout`);try{return Lr.decode(Buffer.from(r))}catch(e){throw console.error("Decoding error:",e),e}}async function Or(e,t){const r=await Promise.all(e.map((e=>async function(e,t){const r=e.pubkeyArray,n=await t.getStateTreeInfos(),o=e.outputCompressedAccountHashes,s=e.outputCompressedAccounts.map(((t,s)=>{var i;const a=r[e.outputCompressedAccounts[s].merkleTreeIndex],u=kr(n,a);if(!u.tree.equals(r[e.outputCompressedAccounts[s].merkleTreeIndex]))throw new Error("Invalid tree");const c={treeInfo:u,hash:W(o[s]),leafIndex:e.outputLeafIndices[s],proveByIndex:0};if(!t.compressedAccount.data)throw new Error("No data");const l=Nr(t.compressedAccount);if(!l)throw new Error("Invalid token data");return{compressedAccount:J(c,t.compressedAccount.owner,t.compressedAccount.lamports,t.compressedAccount.data,null!==(i=t.compressedAccount.address)&&void 0!==i?i:void 0),parsed:l}}));return{inputCompressedAccountHashes:e.inputCompressedAccountHashes,outputCompressedAccounts:s}}(e,t)))),n=r.flatMap((e=>e.outputCompressedAccounts)),o=r.flatMap((e=>e.inputCompressedAccountHashes));return n.filter((e=>!o.some((t=>W(t).eq(e.compressedAccount.hash)))))}async function Br(e,t,r){const n=await Ar(e);return{items:(await Or(n,e)).filter((e=>e.parsed.owner.equals(t)&&e.parsed.mint.equals(r))).sort(((e,t)=>e.compressedAccount.leafIndex-t.compressedAccount.leafIndex)),cursor:null}}async function Rr(e,t,r){const n=await Ar(e);return{items:(await Or(n,e)).filter((e=>{var n;return(null===(n=e.parsed.delegate)||void 0===n?void 0:n.equals(t))&&e.parsed.mint.equals(r)})),cursor:null}}async function Dr(e,t){const r=await Ar(e),n=(await Or(r,e)).filter((e=>W(e.compressedAccount.hash).eq(t)));if(0===n.length)throw new Error("No compressed account found");return n[0]}class Ur extends TypeError{constructor(e,t){let r;const{message:n,explanation:o,...s}=e,{path:i}=e,a=0===i.length?n:`At path: ${i.join(".")} -- ${n}`;super(o??a),null!=o&&(this.cause=a),Object.assign(this,s),this.name=this.constructor.name,this.failures=()=>r??(r=[e,...t()])}}function Fr(e){return"object"==typeof e&&null!=e}function qr(e){return Fr(e)&&!Array.isArray(e)}function Vr(e){return"symbol"==typeof e?e.toString():"string"==typeof e?JSON.stringify(e):`${e}`}function Kr(e,t,r,n){if(1==e)return;0==e?e={}:"string"==typeof e&&(e={message:e});const{path:o,branch:s}=t,{type:i}=r,{refinement:a,message:u=`Expected a value of type \`${i}\`${a?` with refinement \`${a}\``:""}, but received: \`${Vr(n)}\``}=e;return{value:n,type:i,refinement:a,key:o[o.length-1],path:o,branch:s,...e,message:u}}function*Hr(e,t,r,n){var o;Fr(o=e)&&"function"==typeof o[Symbol.iterator]||(e=[e]);for(const o of e){const e=Kr(o,t,r,n);e&&(yield e)}}function*$r(e,t,r={}){const{path:n=[],branch:o=[e],coerce:s=0,mask:i=0}=r,a={path:n,branch:o,mask:i};s&&(e=t.coercer(e,a));let u="valid";for(const n of t.validator(e,a))n.explanation=r.message,u="not_valid",yield[n,void 0];for(let[c,l,d]of t.entries(e,a)){const t=$r(l,d,{path:void 0===c?n:[...n,c],branch:void 0===c?o:[...o,l],coerce:s,mask:i,message:r.message});for(const r of t)r[0]?(u=null!=r[0].refinement?"not_refined":"not_valid",yield[r[0],void 0]):s&&(l=r[1],void 0===c?e=l:e instanceof Map?e.set(c,l):e instanceof Set?e.add(l):Fr(e)&&(void 0!==l||c in e)&&(e[c]=l))}if("not_valid"!==u)for(const n of t.refiner(e,a))n.explanation=r.message,u="not_refined",yield[n,void 0];"valid"===u&&(yield[void 0,e])}class jr{constructor(e){const{type:t,schema:r,validator:n,refiner:o,coercer:s=(e=>e),entries:i=function*(){}}=e;this.type=t,this.schema=r,this.entries=i,this.coercer=s,this.validator=n?(e,t)=>Hr(n(e,t),t,this,e):()=>[],this.refiner=o?(e,t)=>Hr(o(e,t),t,this,e):()=>[]}assert(e,t){return function(e,t,r){const n=Zr(e,t,{message:r});if(n[0])throw n[0]}(e,this,t)}create(e,t){return zr(e,this,t)}is(e){return Wr(e,this)}mask(e,t){return function(e,t,r){const n=Zr(e,t,{coerce:1,mask:1,message:r});if(n[0])throw n[0];return n[1]}(e,this,t)}validate(e,t={}){return Zr(e,this,t)}}function zr(e,t,r){const n=Zr(e,t,{coerce:1,message:r});if(n[0])throw n[0];return n[1]}function Wr(e,t){return!Zr(e,t)[0]}function Zr(e,t,r={}){const n=$r(e,t,r),o=function(e){const{done:t,value:r}=e.next();return t?void 0:r}(n);return o[0]?[new Ur(o[0],(function*(){for(const e of n)e[0]&&(yield e[0])})),void 0]:[void 0,o[1]]}function Jr(e,t){return new jr({type:e,schema:null,validator:t})}function Qr(){return Jr("any",(()=>1))}function Gr(e){return new jr({type:"array",schema:e,*entries(t){if(e&&Array.isArray(t))for(const[r,n]of t.entries())yield[r,n,e]},coercer:e=>Array.isArray(e)?e.slice():e,validator:e=>Array.isArray(e)||`Expected an array value, but received: ${Vr(e)}`})}function Xr(e){return Jr("instance",(t=>t instanceof e||`Expected a \`${e.name}\` instance, but received: ${Vr(t)}`))}function Yr(e){const t=Vr(e);return new jr({type:"literal",schema:e,validator:r=>r===e||`Expected the literal \`${t}\`, but received: ${Vr(r)}`})}function en(e){return new jr({...e,validator:(t,r)=>null===t||e.validator(t,r),refiner:(t,r)=>null===t||e.refiner(t,r)})}function tn(){return Jr("number",(e=>"number"==typeof e&&!isNaN(e)||`Expected a number, but received: ${Vr(e)}`))}function rn(){return Jr("string",(e=>"string"==typeof e||`Expected a string, but received: ${Vr(e)}`))}function nn(e){const t=Object.keys(e);return new jr({type:"type",schema:e,*entries(r){if(Fr(r))for(const n of t)yield[n,r[n],e[n]]},validator:e=>qr(e)||`Expected an object, but received: ${Vr(e)}`,coercer:e=>qr(e)?{...e}:e})}function on(e){const t=e.map((e=>e.type)).join(" | ");return new jr({type:"union",schema:null,coercer(t,r){for(const n of e){const[e,o]=n.validate(t,{coerce:1,mask:r.mask});if(!e)return o}return t},validator(r,n){const o=[];for(const t of e){const[...e]=$r(r,t,n),[s]=e;if(!s[0])return[];for(const[t]of e)t&&o.push(t)}return[`Expected the value to satisfy a union of \`${t}\`, but received: ${Vr(r)}`,...o]}})}function sn(){return Jr("unknown",(()=>1))}function an(e,t,r){return new jr({...e,coercer:(n,o)=>Wr(n,t)?e.coercer(r(n,o),o):e.coercer(n,o)})}const un=an(Xr(e.PublicKey),rn(),(t=>new e.PublicKey(t))),cn=an(Xr(Array),rn(),(t=>Array.from(new e.PublicKey(t).toBytes()))),ln=an(Xr(a),rn(),(e=>j(e,"base58"))),dn=an(Xr(a),on([rn(),tn()]),(e=>{if("number"==typeof e){if(!Number.isSafeInteger(e))throw new Error(`Unsafe integer. Precision loss: ${e}`);return W(e)}return W(e,10)})),hn=an(rn(),rn(),(e=>""===e?null:e));function pn(e){return on([nn({jsonrpc:Yr("2.0"),id:rn(),result:e}),nn({jsonrpc:Yr("2.0"),id:rn(),error:nn({code:sn(),message:rn(),data:en(Qr())})})])}const fn=pn(sn());function mn(e){return an(pn(e),fn,(t=>"error"in t?t:Object.assign(Object.assign({},t),{result:zr(t.result,e)})))}function gn(e){return mn(nn({context:nn({slot:tn()}),value:e}))}const yn=nn({address:en(cn),hash:ln,data:en(nn({data:hn,dataHash:ln,discriminator:dn})),lamports:dn,owner:un,leafIndex:tn(),tree:un,seq:en(dn),slotCreated:dn}),wn=nn({mint:un,owner:un,amount:dn,delegate:en(un),state:rn()}),vn=nn({tokenData:wn,account:yn}),xn=nn({items:Gr(yn)}),bn=nn({items:Gr(yn),cursor:en(rn())}),En=nn({items:Gr(vn),cursor:en(rn())}),In=tn(),Mn=rn(),An=nn({items:Gr(nn({signature:rn(),slot:tn(),blockTime:tn(),error:en(rn())}))}),Tn=nn({items:Gr(nn({signature:rn(),slot:tn(),blockTime:tn()})),cursor:en(rn())}),Sn=nn({hash:ln,leafIndex:tn(),merkleTree:un,proof:Gr(ln),rootSeq:tn(),root:ln}),Cn=nn({address:ln,nextIndex:tn(),merkleTree:un,proof:Gr(ln),rootSeq:tn(),root:ln,lowerRangeAddress:ln,higherRangeAddress:ln,lowElementLeafIndex:tn()}),kn=nn({a:Gr(tn()),b:Gr(tn()),c:Gr(tn())}),_n=nn({compressedProof:kn,leafIndices:Gr(tn()),leaves:Gr(ln),rootIndices:Gr(tn()),roots:Gr(ln),merkleTrees:Gr(un)}),Pn=Gr(Sn),Ln=nn({amount:dn}),Nn=dn,On=nn({balance:dn,mint:un}),Bn=nn({tokenBalances:Gr(On),cursor:en(rn())}),Rn=nn({items:Gr(On),cursor:en(rn())}),Dn=nn({cursor:en(rn()),items:Gr(nn({balance:dn,owner:un}))}),Un=nn({hash:Gr(tn()),root:Gr(tn()),proof:Gr(Gr(tn()))}),Fn=nn({items:Gr(nn({blockTime:tn(),signature:rn(),slot:tn()}))}),qn=nn({items:Gr(nn({blockTime:tn(),signature:rn(),slot:tn()})),cursor:en(rn())}),Vn=nn({compressionInfo:nn({closedAccounts:Gr(nn({account:yn,optionalTokenData:en(wn)})),openedAccounts:Gr(nn({account:yn,optionalTokenData:en(wn)}))}),transaction:Qr()});function Kn({discriminator:e,data:r,dataHash:n}){return{discriminator:e.toArray("le",8),data:t.Buffer.from(r,"base64"),dataHash:n.toArray("le",32)}}async function Hn(t,r,n,o=0){var s,i;const a=o?"getCompressedTokenAccountsByDelegate":"getCompressedTokenAccountsByOwner",u=o?"delegate":"owner",c=zr(await zn(t.compressionApiEndpoint,a,{[u]:r.toBase58(),mint:null===(s=n.mint)||void 0===s?void 0:s.toBase58(),limit:null===(i=n.limit)||void 0===i?void 0:i.toNumber(),cursor:n.cursor}),gn(En));if("error"in c)throw new e.SolanaJSONRPCError(c.error,`failed to get info for compressed accounts by ${u} ${r.toBase58()}`);if(null===c.result.value)throw new Error("not implemented: NULL result");const l=[],d=await t.getStateTreeInfos();return c.result.value.items.map((e=>{var t;const n=e.account,o=e.tokenData,s=kr(d,n.tree),i=J(Q(s,n.hash,n.leafIndex),n.owner,W(n.lamports),n.data?Kn(n.data):void 0,n.address||void 0),a={mint:o.mint,owner:o.owner,amount:o.amount,delegate:o.delegate,state:["uninitialized","initialized","frozen"].indexOf(o.state),tlv:null};if((null===(t=a[u])||void 0===t?void 0:t.toBase58())!==r.toBase58())throw new Error(`RPC returned token account with ${u} different from requested ${u}`);l.push({compressedAccount:i,parsed:a})})),{items:l.sort(((e,t)=>t.compressedAccount.leafIndex-e.compressedAccount.leafIndex)),cursor:c.result.value.cursor}}function $n(e,t){const r=e.account,n=e.optionalTokenData,o=kr(t,r.tree),s=J(Q(o,r.hash,r.leafIndex),r.owner,W(r.lamports),r.data?Kn(r.data):void 0,r.address||void 0);return null===n?{account:s,maybeTokenData:null}:{account:s,maybeTokenData:{mint:n.mint,owner:n.owner,amount:n.amount,delegate:n.delegate,state:["uninitialized","initialized","frozen"].indexOf(n.state),tlv:null}}}function jn(e){return e.replace(/(":\s*)(-?\d+)(\s*[},])/g,((e,t,r,n)=>{const o=Number(r);return!Number.isNaN(o)&&(o>Number.MAX_SAFE_INTEGER||o<Number.MIN_SAFE_INTEGER)?`${t}"${r}"${n}`:e}))}const zn=async(e,t,r=[],n=1,o=0)=>{const s=JSON.stringify({jsonrpc:"2.0",id:"test-account",method:t,params:r});if(o){const t=()=>{const t=s.replace(/"/g,'\\"');return`curl -X POST ${e} \\\n -H "Content-Type: application/json" \\\n -d "${t}"`};console.log("Debug: Stack trace:"),console.log((new Error).stack),console.log("\nDebug: curl:"),console.log(t()),console.log("\n")}const i=await fetch(e,{method:"POST",headers:{"Content-Type":"application/json"},body:s});if(!i.ok)throw new Error(`HTTP error! status: ${i.status}`);const a=jn(await i.text());return n?Xe(JSON.parse(a)):JSON.parse(a)},Wn=async(e,t,r=[],n=0)=>{let o,s="";n&&(s=`Proof generation for method:${t}`,console.time(s)),"inclusion"===t?o=JSON.stringify({circuitType:"inclusion",stateTreeHeight:26,inputCompressedAccounts:r}):"new-address"===t?o=JSON.stringify({circuitType:"non-inclusion",addressTreeHeight:26,newAddresses:r}):"combined"===t&&(o=JSON.stringify({circuitType:"combined",stateTreeHeight:26,addressTreeHeight:26,inputCompressedAccounts:r[0],newAddresses:r[1]}));const i=await fetch(`${e}/prove`,{method:"POST",headers:{"Content-Type":"application/json"},body:o});if(!i.ok)throw new Error(`Error fetching proof: ${i.statusText}`);const a=ct(ut(await i.json()));return n&&console.timeEnd(s),a};function Zn(e){const t=[];for(let r=0;r<e.length;r++){const n={root:Qe(e[r].root),pathIndex:e[r].leafIndex,pathElements:e[r].merkleProof.map((e=>Qe(e))),leaf:Qe(W(e[r].hash))};t.push(n)}return t}function Jn(e){const t=[];for(let r=0;r<e.length;r++){const n={root:Qe(e[r].root),value:Qe(e[r].value),pathIndex:e[r].indexHashedIndexedElementLeaf.toNumber(),pathElements:e[r].merkleProofHashedIndexedElementLeaf.map((e=>Qe(e))),nextIndex:e[r].nextIndex.toNumber(),leafLowerRangeValue:Qe(e[r].leafLowerRangeValue),leafHigherRangeValue:Qe(e[r].leafHigherRangeValue)};t.push(n)}return t}function Qn(e,t,r){if(e.length!==t.length)throw new Error("Input lengths must match.");if(0===e.length)return W(0);let n=r.poseidonHashBN([e[0].toString(),t[0].toString()]);for(let o=1;o<e.length;o++)n=r.poseidonHashBN([n.toString(),e[o].toString(),t[o].toString()]);return n}class Gn extends e.Connection{constructor(e,t,r,n){super(e,n||"confirmed"),this.allStateTreeInfos=null,this.lastStateTreeFetchTime=null,this.CACHE_TTL=36e5,this.fetchPromise=null,this.compressionApiEndpoint=t,this.proverEndpoint=r}async getCachedActiveStateTreeInfos(){}async getStateTreeInfos(){if(b(this.rpcEndpoint))return E();if(this.allStateTreeInfos&&this.lastStateTreeFetchTime&&Date.now()-this.lastStateTreeFetchTime<=this.CACHE_TTL)return this.allStateTreeInfos;if(this.fetchPromise)return this.fetchPromise;let e;try{return this.fetchPromise=this.doFetch(),e=await this.fetchPromise,this.allStateTreeInfos=e,this.lastStateTreeFetchTime=Date.now(),e}finally{this.fetchPromise=null}}async doFetch(){const{mainnet:e,devnet:t}=x();try{return await at({connection:this,stateTreeLUTPairs:[e[0]]})}catch(e){try{return await at({connection:this,stateTreeLUTPairs:[t[0]]})}catch(t){throw new Error(`Failed to fetch state tree infos from both mainnet and devnet. Mainnet error: ${e}. Devnet error: ${t}`)}}}async getCompressedAccount(t,r){if(!r&&!t)throw new Error("Either hash or address must be provided");if(r&&t)throw new Error("Only one of hash or address must be provided");const n=zr(await zn(this.compressionApiEndpoint,"getCompressedAccount",{hash:r?z(r):void 0,address:t?z(t):void 0}),gn(en(yn)));if("error"in n)throw new e.SolanaJSONRPCError(n.error,`failed to get info for compressed account ${r?r.toString():t?t.toString():""}`);if(null===n.result.value)return null;const o=kr(await this.getStateTreeInfos(),n.result.value.tree),s=n.result.value;return J(Q(o,s.hash,s.leafIndex),s.owner,W(s.lamports),s.data?Kn(s.data):void 0,s.address||void 0)}async getCompressedBalance(t,r){if(!r&&!t)throw new Error("Either hash or address must be provided");if(r&&t)throw new Error("Only one of hash or address must be provided");const n=zr(await zn(this.compressionApiEndpoint,"getCompressedBalance",{hash:r?z(r):void 0,address:t?z(t):void 0}),gn(Nn));if("error"in n)throw new e.SolanaJSONRPCError(n.error,`failed to get balance for compressed account ${r?r.toString():t?t.toString():""}`);return null===n.result.value?W(0):W(n.result.value)}async getCompressedBalanceByOwner(t){const r=zr(await zn(this.compressionApiEndpoint,"getCompressedBalanceByOwner",{owner:t.toBase58()}),gn(Nn));if("error"in r)throw new e.SolanaJSONRPCError(r.error,`failed to get balance for compressed account ${t.toBase58()}`);return null===r.result.value?W(0):W(r.result.value)}async getCompressedAccountProof(t){const r=zr(await zn(this.compressionApiEndpoint,"getCompressedAccountProof",{hash:z(t)}),gn(Sn));if("error"in r)throw new e.SolanaJSONRPCError(r.error,`failed to get proof for compressed account ${t.toString()}`);if(null===r.result.value)throw new Error(`failed to get proof for compressed account ${t.toString()}`);const n=kr(await this.getStateTreeInfos(),r.result.value.merkleTree);return{hash:W(r.result.value.hash.toArray("be",32)),treeInfo:n,leafIndex:r.result.value.leafIndex,merkleProof:r.result.value.proof,rootIndex:r.result.value.rootSeq%2400,root:r.result.value.root,proveByIndex:0}}async getMultipleCompressedAccounts(t){const r=zr(await zn(this.compressionApiEndpoint,"getMultipleCompressedAccounts",{hashes:t.map((e=>z(e)))}),gn(xn));if("error"in r)throw new e.SolanaJSONRPCError(r.error,`failed to get info for compressed accounts ${t.map((e=>z(e))).join(", ")}`);if(null===r.result.value)throw new Error(`failed to get info for compressed accounts ${t.map((e=>z(e))).join(", ")}`);const n=await this.getStateTreeInfos(),o=[];return r.result.value.items.map((e=>{const t=kr(n,e.tree),r=J(Q(t,W(e.hash.toArray("be",32)),e.leafIndex),e.owner,W(e.lamports),e.data?Kn(e.data):void 0,e.address||void 0);o.push(r)})),o.sort(((e,t)=>t.leafIndex-e.leafIndex))}async getMultipleCompressedAccountProofs(t){const r=zr(await zn(this.compressionApiEndpoint,"getMultipleCompressedAccountProofs",t.map((e=>z(e)))),gn(Gr(Sn)));if("error"in r)throw new e.SolanaJSONRPCError(r.error,`failed to get proofs for compressed accounts ${t.map((e=>z(e))).join(", ")}`);if(null===r.result.value)throw new Error(`failed to get proofs for compressed accounts ${t.map((e=>z(e))).join(", ")}`);const n=[],o=await this.getStateTreeInfos();for(const e of r.result.value){const t=kr(o,e.merkleTree),r={hash:W(e.hash.toArray("be",32)),treeInfo:t,leafIndex:e.leafIndex,merkleProof:e.proof,rootIndex:e.rootSeq%2400,root:e.root,proveByIndex:0};n.push(r)}return n}async getCompressedAccountsByOwner(t,r){var n;const o=zr(await zn(this.compressionApiEndpoint,"getCompressedAccountsByOwner",{owner:t.toBase58(),filters:(null==r?void 0:r.filters)||[],dataSlice:null==r?void 0:r.dataSlice,cursor:null==r?void 0:r.cursor,limit:null===(n=null==r?void 0:r.limit)||void 0===n?void 0:n.toNumber()}),gn(bn));if("error"in o)throw new e.SolanaJSONRPCError(o.error,`failed to get info for compressed accounts owned by ${t.toBase58()}`);if(null===o.result.value)return{items:[],cursor:null};const s=[],i=await this.getStateTreeInfos();return o.result.value.items.map((e=>{const t=kr(i,e.tree),r=J(Q(t,W(e.hash.toArray("be",32)),e.leafIndex),e.owner,W(e.lamports),e.data?Kn(e.data):void 0,e.address||void 0);s.push(r)})),{items:s.sort(((e,t)=>t.leafIndex-e.leafIndex)),cursor:o.result.value.cursor}}async getCompressedTokenAccountsByOwner(e,t){return t||(t={}),await Hn(this,e,t,0)}async getCompressedTokenAccountsByDelegate(e,t){return t||(t={}),await Hn(this,e,t,1)}async getCompressedTokenAccountBalance(t){const r=zr(await zn(this.compressionApiEndpoint,"getCompressedTokenAccountBalance",{hash:z(t)}),gn(Ln));if("error"in r)throw new e.SolanaJSONRPCError(r.error,`failed to get balance for compressed token account ${t.toString()}`);if(null===r.result.value)throw new Error(`failed to get balance for compressed token account ${t.toString()}`);return{amount:W(r.result.value.amount)}}async getCompressedTokenBalancesByOwner(t,r){var n,o;r||(r={});const s=zr(await zn(this.compressionApiEndpoint,"getCompressedTokenBalancesByOwner",{owner:t.toBase58(),mint:null===(n=r.mint)||void 0===n?void 0:n.toBase58(),limit:null===(o=r.limit)||void 0===o?void 0:o.toNumber(),cursor:r.cursor}),gn(Bn));if("error"in s)throw new e.SolanaJSONRPCError(s.error,`failed to get compressed token balances for owner ${t.toBase58()}`);if(null===s.result.value)throw new Error(`failed to get compressed token balances for owner ${t.toBase58()}`);return{items:r.mint?s.result.value.tokenBalances.filter((e=>e.mint.toBase58()===r.mint.toBase58())):s.result.value.tokenBalances,cursor:s.result.value.cursor}}async getCompressedTokenBalancesByOwnerV2(t,r){var n,o;r||(r={});const s=zr(await zn(this.compressionApiEndpoint,"getCompressedTokenBalancesByOwnerV2",{owner:t.toBase58(),mint:null===(n=r.mint)||void 0===n?void 0:n.toBase58(),limit:null===(o=r.limit)||void 0===o?void 0:o.toNumber(),cursor:r.cursor}),gn(Rn));if("error"in s)throw new e.SolanaJSONRPCError(s.error,`failed to get compressed token balances for owner ${t.toBase58()}`);if(null===s.result.value)throw new Error(`failed to get compressed token balances for owner ${t.toBase58()}`);const i=r.mint?s.result.value.items.filter((e=>e.mint.toBase58()===r.mint.toBase58())):s.result.value.items;return{context:s.result.context,value:{items:i,cursor:s.result.value.cursor}}}async getCompressionSignaturesForAccount(t){const r=zr(await zn(this.compressionApiEndpoint,"getCompressionSignaturesForAccount",{hash:z(t)}),gn(Fn));if("error"in r)throw new e.SolanaJSONRPCError(r.error,`failed to get signatures for compressed account ${t.toString()}`);return r.result.value.items}async getTransactionWithCompressionInfo(t){const r=zr(await zn(this.compressionApiEndpoint,"getTransactionWithCompressionInfo",{signature:t}),mn(Vn));if("error"in r)throw new e.SolanaJSONRPCError(r.error,"failed to get slot");if(null===r.result.transaction)return null;const n=[],o=[],s=await this.getStateTreeInfos();r.result.compressionInfo.closedAccounts.map((e=>{n.push($n(e,s))})),r.result.compressionInfo.openedAccounts.map((e=>{o.push($n(e,s))}));const i=e=>{const t=Object.values(e.reduce(((e,{maybeTokenData:t})=>{if(t){const{owner:r,mint:n,amount:o}=t,s=`${r.toBase58()}_${n.toBase58()}`;s in e?e[s].amount=e[s].amount.add(o):e[s]={owner:r,mint:n,amount:o}}return e}),{}));return t.length>0?t:void 0},a=i(n),u=i(o);return{compressionInfo:{closedAccounts:n,openedAccounts:o,preTokenBalances:a,postTokenBalances:u},transaction:r.result.transaction}}async getCompressionSignaturesForAddress(t,r){var n;const o=zr(await zn(this.compressionApiEndpoint,"getCompressionSignaturesForAddress",{address:t.toBase58(),cursor:null==r?void 0:r.cursor,limit:null===(n=null==r?void 0:r.limit)||void 0===n?void 0:n.toNumber()}),gn(qn));if("error"in o)throw new e.SolanaJSONRPCError(o.error,`failed to get signatures for address ${t.toBase58()}`);if(null===o.result.value)throw new Error(`failed to get signatures for address ${t.toBase58()}`);return o.result.value}async getCompressionSignaturesForOwner(t,r){var n;const o=zr(await zn(this.compressionApiEndpoint,"getCompressionSignaturesForOwner",{owner:t.toBase58(),cursor:null==r?void 0:r.cursor,limit:null===(n=null==r?void 0:r.limit)||void 0===n?void 0:n.toNumber()}),gn(qn));if("error"in o)throw new e.SolanaJSONRPCError(o.error,`failed to get signatures for owner ${t.toBase58()}`);if(null===o.result.value)throw new Error(`failed to get signatures for owner ${t.toBase58()}`);return o.result.value}async getCompressionSignaturesForTokenOwner(t,r){var n;const o=zr(await zn(this.compressionApiEndpoint,"getCompressionSignaturesForTokenOwner",{owner:t.toBase58(),cursor:null==r?void 0:r.cursor,limit:null===(n=null==r?void 0:r.limit)||void 0===n?void 0:n.toNumber()}),gn(qn));if("error"in o)throw new e.SolanaJSONRPCError(o.error,`failed to get signatures for owner ${t.toBase58()}`);if(null===o.result.value)throw new Error(`failed to get signatures for owner ${t.toBase58()}`);return o.result.value}async getIndexerHealth(){const t=zr(await zn(this.compressionApiEndpoint,"getIndexerHealth"),mn(Mn));if("error"in t)throw new e.SolanaJSONRPCError(t.error,"failed to get health");return t.result}async confirmTransactionIndexed(e){const t=Date.now();for(;;){if(await this.getIndexerSlot()>=e)return 1;if(Date.now()-t>2e4)throw new Error("Timeout: Indexer slot did not reach the required slot within 20 seconds");await new Promise((e=>setTimeout(e,200)))}}async getIndexerSlot(){const t=zr(await zn(this.compressionApiEndpoint,"getIndexerSlot"),mn(In));if("error"in t)throw new e.SolanaJSONRPCError(t.error,"failed to get slot");return t.result}async getCompressedMintTokenHolders(t,r){var n;const o=zr(await zn(this.compressionApiEndpoint,"getCompressedMintTokenHolders",{mint:t.toBase58(),cursor:null==r?void 0:r.cursor,limit:null===(n=null==r?void 0:r.limit)||void 0===n?void 0:n.toNumber()}),gn(Dn));if("error"in o)throw new e.SolanaJSONRPCError(o.error,"failed to get mint token holders");return o.result}async getLatestCompressionSignatures(t,r){const n=zr(await zn(this.compressionApiEndpoint,"getLatestCompressionSignatures",{limit:r,cursor:t}),gn(Tn));if("error"in n)throw new e.SolanaJSONRPCError(n.error,"failed to get latest non-voting signatures");return n.result}async getLatestNonVotingSignatures(t,r){const n=zr(await zn(this.compressionApiEndpoint,"getLatestNonVotingSignatures",{limit:t,cursor:r}),gn(An));if("error"in n)throw new e.SolanaJSONRPCError(n.error,"failed to get latest non-voting signatures");return n.result}async getMultipleNewAddressProofs(t){const r=zr(await zn(this.compressionApiEndpoint,"getMultipleNewAddressProofs",t.map((e=>z(e)))),gn(Gr(Cn)));if("error"in r)throw new e.SolanaJSONRPCError(r.error,`failed to get proofs for new addresses ${t.map((e=>z(e))).join(", ")}`);if(null===r.result.value)throw new Error(`failed to get proofs for new addresses ${t.map((e=>z(e))).join(", ")}`);const n=[];for(const e of r.result.value){const t={root:e.root,rootIndex:e.rootSeq%2400,value:e.address,leafLowerRangeValue:e.lowerRangeAddress,leafHigherRangeValue:e.higherRangeAddress,nextIndex:W(e.nextIndex),merkleProofHashedIndexedElementLeaf:e.proof,indexHashedIndexedElementLeaf:W(e.lowElementLeafIndex),treeInfo:{tree:e.merkleTree,queue:M().addressQueue,treeType:exports.TreeType.AddressV1,nextTreeInfo:null}};n.push(t)}return n}async getValidityProofDirect(e=[],t=[]){let r;if(0===e.length&&0===t.length)throw new Error("Empty input. Provide hashes and/or new addresses.");if(e.length>0&&0===t.length){const t=await this.getMultipleCompressedAccountProofs(e),n=Zn(t);r={compressedProof:await Wn(this.proverEndpoint,"inclusion",n,0),roots:t.map((e=>e.root)),rootIndices:t.map((e=>e.rootIndex)),leafIndices:t.map((e=>e.leafIndex)),leaves:t.map((e=>W(e.hash))),treeInfos:t.map((e=>e.treeInfo))}}else if(0===e.length&&t.length>0){const e=await this.getMultipleNewAddressProofs(t),n=Jn(e);r={compressedProof:await Wn(this.proverEndpoint,"new-address",n,0),roots:e.map((e=>e.root)),rootIndices:e.map((e=>e.rootIndex)),leafIndices:e.map((e=>e.nextIndex.toNumber())),leaves:e.map((e=>W(e.value))),treeInfos:e.map((e=>e.treeInfo))}}else{if(!(e.length>0&&t.length>0))throw new Error("Invalid input");{const n=await this.getMultipleCompressedAccountProofs(e),o=Zn(n),s=await this.getMultipleNewAddressProofs(t),i=Jn(s),a=await Wn(this.proverEndpoint,"combined",[o,i],0),u=[...n.map((e=>e.treeInfo)),...s.map((e=>e.treeInfo))];r={compressedProof:a,roots:n.map((e=>e.root)).concat(s.map((e=>e.root))),rootIndices:n.map((e=>e.rootIndex)).concat(s.map((e=>e.rootIndex))),leafIndices:n.map((e=>e.leafIndex)).concat(s.map((e=>e.nextIndex.toNumber()))),leaves:n.map((e=>W(e.hash))).concat(s.map((e=>W(e.value)))),treeInfos:u}}}return r}async getValidityProof(e=[],t=[]){const r=await this.getMultipleCompressedAccounts(e),n=r.map((e=>e.treeInfo.tree)),o=r.map((e=>e.treeInfo.queue)),s=M().addressTree,i=M().addressQueue,a=e.map(((e,t)=>({hash:e,tree:n[t],queue:o[t]}))),u=t.map((e=>({address:e,tree:s,queue:i})));return this.getValidityProofV0(a,u)}async getValidityProofV0(e=[],t=[]){const{value:r}=await this.getValidityProofAndRpcContext(e,t);return r}async getValidityProofAndRpcContext(t=[],r=[]){ne(t.length,r.length);const n=await this.getStateTreeInfos(),o=zr(await zn(this.compressionApiEndpoint,"getValidityProof",{hashes:t.map((({hash:e})=>z(e))),newAddressesWithTrees:r.map((({address:e,tree:t})=>({address:z(e),tree:t.toBase58()})))}),gn(_n));if("error"in o)throw new e.SolanaJSONRPCError(o.error,`failed to get ValidityProof for compressed accounts ${t.map((e=>e.toString()))}`);const s=o.result.value;if(null===s)throw new Error(`failed to get ValidityProof for compressed accounts ${t.map((e=>e.toString()))}`);const i=[...t.map((({tree:e})=>{const t=kr(n,e);return{tree:e,queue:t.queue,treeType:t.treeType,nextTreeInfo:t.nextTreeInfo}})),...r.map((({tree:e,queue:t})=>({tree:e,queue:t,treeType:exports.TreeType.AddressV1,nextTreeInfo:null})))];return{value:{compressedProof:s.compressedProof,treeInfos:i,leafIndices:s.leafIndices,rootIndices:s.rootIndices,roots:s.roots,leaves:s.leaves},context:o.result.context}}}class Xn extends e.Connection{constructor(e,t,r,n,o,s){super(e,o||"confirmed"),this.log=0,this.allStateTreeInfos=null,this.lastStateTreeFetchTime=null,this.fetchPromise=null,this.CACHE_TTL=36e5,this.compressionApiEndpoint=r,this.proverEndpoint=n;const{depth:i,log:a}=null!=s?s:{},{merkleTreeHeight:u}=M();this.lightWasm=t,this.depth=null!=i?i:u,this.log=null!=a?a:0}async getCachedActiveStateTreeInfos(){}async getStateTreeInfos(){return E()}async doFetch(){throw new Error("doFetch not supported in test-rpc")}async getCompressedAccount(e,t){if(e)throw new Error("address is not supported in test-rpc");if(!t)throw new Error("hash is required");const r=await _r(this,t);return null!=r?r:null}async getCompressedBalance(e,t){if(e)throw new Error("address is not supported in test-rpc");if(!t)throw new Error("hash is required");const r=await _r(this,t);if(!r)throw new Error("Account not found");return W(r.lamports)}async getCompressedBalanceByOwner(e){return(await this.getCompressedAccountsByOwner(e)).items.reduce(((e,t)=>e.add(t.lamports)),W(0))}async getCompressedAccountProof(e){return(await this.getMultipleCompressedAccountProofs([e]))[0]}async getMultipleCompressedAccounts(e){return await async function(e,t){return(await Pr(e)).filter((e=>t.some((t=>W(e.hash).eq(t))))).sort(((e,t)=>t.leafIndex-e.leafIndex))}(this,e)}async confirmTransactionIndexed(e){return 1}async getMultipleCompressedAccountProofs(t){const r=await Ar(this).then((e=>e.reverse())),n=new Map,o=await this.getStateTreeInfos();for(const e of r)for(let t=0;t<e.outputCompressedAccounts.length;t++){const r=e.outputCompressedAccountHashes[t],s=kr(o,e.pubkeyArray[e.outputCompressedAccounts[t].merkleTreeIndex]);n.has(s.tree.toBase58())||n.set(s.tree.toBase58(),{leaves:[],leafIndices:[],treeType:s.treeType,queue:s.queue});const i=n.get(s.tree.toBase58());if(!i)throw new Error(`Tree not found: ${s.tree.toBase58()}`);i.leaves.push(r),i.leafIndices.push(e.outputLeafIndices[t])}const s=new Map;for(const[r,{leaves:i,treeType:a,queue:u}]of n.entries()){const n=new e.PublicKey(r);let u;if(a!==exports.TreeType.StateV1)throw new Error(`Unsupported tree type: ${a} in test-rpc.ts`);u=new Mr(this.depth,this.lightWasm,i.map((e=>W(e).toString())));for(let e=0;e<t.length;e++){const r=i.findIndex((r=>W(r).eq(t[e]))),c=kr(o,n);if(-1!==r&&a===exports.TreeType.StateV1){const n=u.path(r).pathElements.map((e=>W(e))),o=W(u.root()),a={hash:W(t[e].toArray("be",32)),treeInfo:c,leafIndex:r,merkleProof:n,proveByIndex:0,rootIndex:i.length,root:o};s.set(t[e].toString(),a)}}}return s.forEach(((e,t)=>{const r=e.leafIndex,o=n.get(e.treeInfo.tree.toBase58()).leaves[r],s=W(o);if(!s.eq(e.hash))throw new Error(`Mismatch at index ${t}: expected ${e.hash.toString()}, got ${s.toString()}`)})),t.map((e=>{const t=s.get(e.toString());if(!t)throw new Error(`No proof found for hash: ${e.toString()}`);return t}))}async getCompressedAccountsByOwner(e,t){const r=await async function(e,t){return(await Pr(e)).filter((e=>e.owner.equals(t)))}(this,e);return{items:r,cursor:null}}async getLatestCompressionSignatures(e,t){throw new Error("getLatestNonVotingSignaturesWithContext not supported in test-rpc")}async getLatestNonVotingSignatures(e){throw new Error("getLatestNonVotingSignaturesWithContext not supported in test-rpc")}async getCompressedTokenAccountsByOwner(e,t){return await Br(this,e,t.mint)}async getCompressedTokenAccountsByDelegate(e,t){return await Rr(this,e,t.mint)}async getCompressedTokenAccountBalance(e){const t=await Dr(this,e);return{amount:W(t.parsed.amount)}}async getCompressedTokenBalancesByOwner(e,t){return{items:(await Br(this,e,t.mint)).items.map((e=>({balance:W(e.parsed.amount),mint:e.parsed.mint}))),cursor:null}}async getCompressedTokenBalancesByOwnerV2(e,t){return{context:{slot:1},value:{items:(await Br(this,e,t.mint)).items.map((e=>({balance:W(e.parsed.amount),mint:e.parsed.mint}))),cursor:null}}}async getCompressionSignaturesForAccount(e){throw new Error("getCompressionSignaturesForAccount not implemented in test-rpc")}async getTransactionWithCompressionInfo(e){throw new Error("getCompressedTransaction not implemented in test-rpc")}async getCompressionSignaturesForAddress(e,t){throw new Error("getSignaturesForAddress3 not implemented")}async getCompressionSignaturesForOwner(e,t){throw new Error("getSignaturesForOwner not implemented")}async getCompressionSignaturesForTokenOwner(e,t){throw new Error("getSignaturesForTokenOwner not implemented")}async getIndexerHealth(){return"ok"}async getIndexerSlot(){return 1}async getMultipleNewAddressProofs(e){const t=Ir.default(),r=[];t.init();const n=[];for(let e=0;e<r.length;e++)t.append(W(r[e]));for(let e=0;e<t.elements.length;e++){const r=t.hashElement(this.lightWasm,e);n.push(W(r))}const o=new Mr(this.depth,this.lightWasm,n.map((e=>W(e).toString()))),s=[];for(let r=0;r<e.length;r++){const[n]=t.findLowElement(e[r]);if(!n)throw new Error("Address not found");const i=n.index,a=o.path(i).pathElements.map((e=>W(e))),u=t.get(n.nextIndex).value,c={root:W(o.root()),rootIndex:3,value:e[r],leafLowerRangeValue:n.value,leafHigherRangeValue:u,nextIndex:W(n.nextIndex),merkleProofHashedIndexedElementLeaf:a,indexHashedIndexedElementLeaf:W(n.index),treeInfo:{tree:M().addressTree,queue:M().addressQueue,treeType:exports.TreeType.AddressV1,nextTreeInfo:null}};s.push(c)}return s}async getCompressedMintTokenHolders(e,t){throw new Error("getCompressedMintTokenHolders not implemented in test-rpc")}async getValidityProofDirect(e=[],t=[]){return this.getValidityProof(e,t)}async getValidityProofAndRpcContext(e=[],t=[]){if(t.some((e=>!(e instanceof a))))throw new Error("AddressWithTree is not supported in test-rpc");return{value:await this.getValidityProofV0(e,t),context:{slot:1}}}async getValidityProof(e=[],t=[]){if(t.some((e=>!(e instanceof a))))throw new Error("AddressWithTree is not supported in test-rpc");let r;if(0===e.length&&0===t.length)throw new Error("Empty input. Provide hashes and/or new addresses.");if(e.length>0&&0===t.length){const t=await this.getMultipleCompressedAccountProofs(e),n=Zn(t);r={compressedProof:await Wn(this.proverEndpoint,"inclusion",n,this.log),roots:t.map((e=>e.root)),rootIndices:t.map((e=>e.rootIndex)),leafIndices:t.map((e=>e.leafIndex)),leaves:t.map((e=>W(e.hash))),treeInfos:t.map((e=>e.treeInfo))}}else if(0===e.length&&t.length>0){const e=await this.getMultipleNewAddressProofs(t),n=Jn(e);r={compressedProof:await Wn(this.proverEndpoint,"new-address",n,this.log),roots:e.map((e=>e.root)),rootIndices:e.map((()=>3)),leafIndices:e.map((e=>e.indexHashedIndexedElementLeaf.toNumber())),leaves:e.map((e=>W(e.value))),treeInfos:e.map((e=>e.treeInfo))}}else{if(!(e.length>0&&t.length>0))throw new Error("Invalid input");{const n=await this.getMultipleCompressedAccountProofs(e),o=Zn(n),s=await this.getMultipleNewAddressProofs(t),i=Jn(s);r={compressedProof:await Wn(this.proverEndpoint,"combined",[o,i],this.log),roots:n.map((e=>e.root)).concat(s.map((e=>e.root))),rootIndices:n.map((e=>e.rootIndex)).concat(s.map((()=>3))),leafIndices:n.map((e=>e.leafIndex)).concat(s.map((e=>e.indexHashedIndexedElementLeaf.toNumber()))),leaves:n.map((e=>W(e.hash))).concat(s.map((e=>W(e.value)))),treeInfos:n.map((e=>e.treeInfo)).concat(s.map((e=>e.treeInfo)))}}}return r}async getValidityProofV0(e=[],t=[]){return this.getValidityProof(e.map((e=>e.hash)),t.map((e=>e.address)))}}let Yn=1;const eo=oo(255),to=oo(254),ro=oo(253),no=oo(252);function oo(t){if(t||(t=Yn,Yn++),t>255)return e.Keypair.generate();const r=new Uint8Array(32);return r[31]=t,e.Keypair.fromSeed(r)}var so,io,ao,uo,co,lo,ho,po;exports.UtxoErrorCode=void 0,(so=exports.UtxoErrorCode||(exports.UtxoErrorCode={})).NEGATIVE_LAMPORTS="NEGATIVE_LAMPORTS",so.NOT_U64="NOT_U64",so.BLINDING_EXCEEDS_FIELD_SIZE="BLINDING_EXCEEDS_FIELD_SIZE",exports.SelectInUtxosErrorCode=void 0,(io=exports.SelectInUtxosErrorCode||(exports.SelectInUtxosErrorCode={})).FAILED_TO_FIND_UTXO_COMBINATION="FAILED_TO_FIND_UTXO_COMBINATION",io.INVALID_NUMBER_OF_IN_UTXOS="INVALID_NUMBER_OF_IN_UTXOS",exports.CreateUtxoErrorCode=void 0,(ao=exports.CreateUtxoErrorCode||(exports.CreateUtxoErrorCode={})).OWNER_UNDEFINED="OWNER_UNDEFINED",ao.INVALID_OUTPUT_UTXO_LENGTH="INVALID_OUTPUT_UTXO_LENGTH",ao.UTXO_DATA_UNDEFINED="UTXO_DATA_UNDEFINED",exports.RpcErrorCode=void 0,(uo=exports.RpcErrorCode||(exports.RpcErrorCode={})).CONNECTION_UNDEFINED="CONNECTION_UNDEFINED",uo.RPC_PUBKEY_UNDEFINED="RPC_PUBKEY_UNDEFINED",uo.RPC_METHOD_NOT_IMPLEMENTED="RPC_METHOD_NOT_IMPLEMENTED",uo.RPC_INVALID="RPC_INVALID",exports.LookupTableErrorCode=void 0,(co=exports.LookupTableErrorCode||(exports.LookupTableErrorCode={})).LOOK_UP_TABLE_UNDEFINED="LOOK_UP_TABLE_UNDEFINED",co.LOOK_UP_TABLE_NOT_INITIALIZED="LOOK_UP_TABLE_NOT_INITIALIZED",exports.HashErrorCode=void 0,(exports.HashErrorCode||(exports.HashErrorCode={})).NO_POSEIDON_HASHER_PROVIDED="NO_POSEIDON_HASHER_PROVIDED",exports.ProofErrorCode=void 0,(lo=exports.ProofErrorCode||(exports.ProofErrorCode={})).INVALID_PROOF="INVALID_PROOF",lo.PROOF_INPUT_UNDEFINED="PROOF_INPUT_UNDEFINED",lo.PROOF_GENERATION_FAILED="PROOF_GENERATION_FAILED",exports.MerkleTreeErrorCode=void 0,(ho=exports.MerkleTreeErrorCode||(exports.MerkleTreeErrorCode={})).MERKLE_TREE_NOT_INITIALIZED="MERKLE_TREE_NOT_INITIALIZED",ho.SOL_MERKLE_TREE_UNDEFINED="SOL_MERKLE_TREE_UNDEFINED",ho.MERKLE_TREE_UNDEFINED="MERKLE_TREE_UNDEFINED",ho.INPUT_UTXO_NOT_INSERTED_IN_MERKLE_TREE="INPUT_UTXO_NOT_INSERTED_IN_MERKLE_TREE",ho.MERKLE_TREE_INDEX_UNDEFINED="MERKLE_TREE_INDEX_UNDEFINED",ho.MERKLE_TREE_SET_SPACE_UNDEFINED="MERKLE_TREE_SET_SPACE_UNDEFINED",exports.UtilsErrorCode=void 0,(po=exports.UtilsErrorCode||(exports.UtilsErrorCode={})).ACCOUNT_NAME_UNDEFINED_IN_IDL="ACCOUNT_NAME_UNDEFINED_IN_IDL",po.PROPERTY_UNDEFINED="PROPERTY_UNDEFINED",po.LOOK_UP_TABLE_CREATION_FAILED="LOOK_UP_TABLE_CREATION_FAILED",po.UNSUPPORTED_ARCHITECTURE="UNSUPPORTED_ARCHITECTURE",po.UNSUPPORTED_PLATFORM="UNSUPPORTED_PLATFORM",po.ACCOUNTS_UNDEFINED="ACCOUNTS_UNDEFINED",po.INVALID_NUMBER="INVALID_NUMBER";class fo extends Error{constructor(e,t,r){super(`${e}: ${r}`),this.code=e,this.functionName=t,this.codeMessage=r}}exports.ADDRESS_QUEUE_ROLLOVER_FEE=V,exports.ADDRESS_TREE_NETWORK_FEE=H,exports.ALICE=eo,exports.AccountProofResult=Un,exports.AppendLeavesInputLayout=dr,exports.AppendNullifyCreateAddressInputsMetaLayout=lr,exports.BOB=to,exports.BalanceResult=Ln,exports.CHARLIE=ro,exports.COMPRESSED_TOKEN_PROGRAM_ID=A,exports.COMPUTE_BUDGET_PATTERN=l,exports.CompressedAccountLayout=Yt,exports.CompressedAccountResult=yn,exports.CompressedAccountsByOwnerResult=bn,exports.CompressedMintTokenHoldersResult=Dn,exports.CompressedTokenAccountResult=vn,exports.CompressedTokenAccountsByOwnerOrDelegateResult=En,exports.CompressedTransactionResult=Vn,exports.CreateUtxoError=class extends fo{},exports.DAVE=no,exports.DEFAULT_MERKLE_TREE_HEIGHT=U,exports.DEFAULT_MERKLE_TREE_ROOTS=2800,exports.DEFAULT_ZERO="0",exports.FIELD_SIZE=u,exports.HIGHEST_ADDRESS_PLUS_ONE=c,exports.HashError=class extends fo{},exports.HealthResult=Mn,exports.IDL={version:"1.2.0",name:"light_system_program",constants:[{name:"SOL_POOL_PDA_SEED",type:"bytes",value:"[115, 111, 108, 95, 112, 111, 111, 108, 95, 112, 100, 97]"}],instructions:[{name:"initCpiContextAccount",accounts:[{name:"feePayer",isMut:1,isSigner:1},{name:"cpiContextAccount",isMut:1,isSigner:0},{name:"associatedMerkleTree",isMut:0,isSigner:0}],args:[]},{name:"invoke",accounts:[{name:"feePayer",isMut:1,isSigner:1,docs:["Fee payer needs to be mutable to pay rollover and protocol fees."]},{name:"authority",isMut:0,isSigner:1},{name:"registeredProgramPda",isMut:0,isSigner:0},{name:"noopProgram",isMut:0,isSigner:0},{name:"accountCompressionAuthority",isMut:0,isSigner:0,docs:["This pda is used to invoke the account compression program."]},{name:"accountCompressionProgram",isMut:0,isSigner:0,docs:["Merkle trees."]},{name:"solPoolPda",isMut:1,isSigner:0,isOptional:1,docs:["Sol pool pda is used to store the native sol that has been compressed.","It's only required when compressing or decompressing sol."]},{name:"decompressionRecipient",isMut:1,isSigner:0,isOptional:1,docs:["Only needs to be provided for decompression as a recipient for the","decompressed sol.","Compressed sol originate from authority."]},{name:"systemProgram",isMut:0,isSigner:0}],args:[{name:"inputs",type:"bytes"}]},{name:"invokeCpi",accounts:[{name:"feePayer",isMut:1,isSigner:1,docs:["Fee payer needs to be mutable to pay rollover and protocol fees."]},{name:"authority",isMut:0,isSigner:1},{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:"invokingProgram",isMut:0,isSigner:0},{name:"solPoolPda",isMut:1,isSigner:0,isOptional:1},{name:"decompressionRecipient",isMut:1,isSigner:0,isOptional:1},{name:"systemProgram",isMut:0,isSigner:0},{name:"cpiContextAccount",isMut:1,isSigner:0,isOptional:1}],args:[{name:"inputs",type:"bytes"}]},{name:"invokeCpiWithReadOnly",accounts:[{name:"feePayer",isMut:1,isSigner:1,docs:["Fee payer needs to be mutable to pay rollover and protocol fees."]},{name:"authority",isMut:0,isSigner:1},{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:"invokingProgram",isMut:0,isSigner:0},{name:"solPoolPda",isMut:1,isSigner:0,isOptional:1},{name:"decompressionRecipient",isMut:1,isSigner:0,isOptional:1},{name:"systemProgram",isMut:0,isSigner:0},{name:"cpiContextAccount",isMut:1,isSigner:0,isOptional:1}],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:["Fee payer needs to be mutable to pay rollover and protocol fees."]},{name:"authority",isMut:0,isSigner:1},{name:"registeredProgramPda",isMut:0,isSigner:0},{name:"noopProgram",isMut:0,isSigner:0},{name:"accountCompressionAuthority",isMut:0,isSigner:0,docs:["This pda is used to invoke the account compression program."]},{name:"accountCompressionProgram",isMut:0,isSigner:0,docs:["Merkle trees."]},{name:"solPoolPda",isMut:1,isSigner:0,isOptional:1,docs:["Sol pool pda is used to store the native sol that has been compressed.","It's only required when compressing or decompressing sol."]},{name:"decompressionRecipient",isMut:1,isSigner:0,isOptional:1,docs:["Only needs to be provided for decompression as a recipient for the","decompressed sol.","Compressed sol originate from authority."]},{name:"systemProgram",isMut:0,isSigner:0}],args:[{name:"inputs1",type:{defined:"InstructionDataInvoke"}},{name:"inputs2",type:{defined:"InstructionDataInvokeCpi"}},{name:"inputs3",type:{defined:"PublicTransactionEvent"}}]}],accounts:[{name:"cpiContextAccount",docs:["Collects instruction data without executing a compressed transaction.","Signer checks are performed on instruction data.","Collected instruction data is combined with the instruction data of the executing cpi,","and executed as a single transaction.","This enables to use input compressed accounts that are owned by multiple programs,","with one zero-knowledge proof."],type:{kind:"struct",fields:[{name:"feePayer",type:"publicKey"},{name:"associatedMerkleTree",type:"publicKey"},{name:"context",type:{vec:{defined:"InstructionDataInvokeCpi"}}}]}}],types:[{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:"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:"CompressedProof",type:{kind:"struct",fields:[{name:"a",type:{array:["u8",32]}},{name:"b",type:{array:["u8",64]}},{name:"c",type:{array:["u8",32]}}]}},{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:"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:"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:"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:"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:"MerkleTreeSequenceNumber",type:{kind:"struct",fields:[{name:"pubkey",type:"publicKey"},{name:"seq",type:"u64"}]}},{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"}}]}}],errors:[{code:6e3,name:"SumCheckFailed",msg:"Sum check failed"},{code:6001,name:"SignerCheckFailed",msg:"Signer check failed"},{code:6002,name:"CpiSignerCheckFailed",msg:"Cpi signer check failed"},{code:6003,name:"ComputeInputSumFailed",msg:"Computing input sum failed."},{code:6004,name:"ComputeOutputSumFailed",msg:"Computing output sum failed."},{code:6005,name:"ComputeRpcSumFailed",msg:"Computing rpc sum failed."},{code:6006,name:"InvalidAddress",msg:"InvalidAddress"},{code:6007,name:"DeriveAddressError",msg:"DeriveAddressError"},{code:6008,name:"CompressedSolPdaUndefinedForCompressSol",msg:"CompressedSolPdaUndefinedForCompressSol"},{code:6009,name:"DeCompressLamportsUndefinedForCompressSol",msg:"DeCompressLamportsUndefinedForCompressSol"},{code:6010,name:"CompressedSolPdaUndefinedForDecompressSol",msg:"CompressedSolPdaUndefinedForDecompressSol"},{code:6011,name:"DeCompressLamportsUndefinedForDecompressSol",msg:"DeCompressLamportsUndefinedForDecompressSol"},{code:6012,name:"DecompressRecipientUndefinedForDecompressSol",msg:"DecompressRecipientUndefinedForDecompressSol"},{code:6013,name:"WriteAccessCheckFailed",msg:"WriteAccessCheckFailed"},{code:6014,name:"InvokingProgramNotProvided",msg:"InvokingProgramNotProvided"},{code:6015,name:"InvalidCapacity",msg:"InvalidCapacity"},{code:6016,name:"InvalidMerkleTreeOwner",msg:"InvalidMerkleTreeOwner"},{code:6017,name:"ProofIsNone",msg:"ProofIsNone"},{code:6018,name:"ProofIsSome",msg:"Proof is some but no input compressed accounts or new addresses provided."},{code:6019,name:"EmptyInputs",msg:"EmptyInputs"},{code:6020,name:"CpiContextAccountUndefined",msg:"CpiContextAccountUndefined"},{code:6021,name:"CpiContextEmpty",msg:"CpiContextEmpty"},{code:6022,name:"CpiContextMissing",msg:"CpiContextMissing"},{code:6023,name:"DecompressionRecipientDefined",msg:"DecompressionRecipientDefined"},{code:6024,name:"SolPoolPdaDefined",msg:"SolPoolPdaDefined"},{code:6025,name:"AppendStateFailed",msg:"AppendStateFailed"},{code:6026,name:"InstructionNotCallable",msg:"The instruction is not callable"},{code:6027,name:"CpiContextFeePayerMismatch",msg:"CpiContextFeePayerMismatch"},{code:6028,name:"CpiContextAssociatedMerkleTreeMismatch",msg:"CpiContextAssociatedMerkleTreeMismatch"},{code:6029,name:"NoInputs",msg:"NoInputs"},{code:6030,name:"InputMerkleTreeIndicesNotInOrder",msg:"Input merkle tree indices are not in ascending order."},{code:6031,name:"OutputMerkleTreeIndicesNotInOrder",msg:"Output merkle tree indices are not in ascending order."},{code:6032,name:"OutputMerkleTreeNotUnique"},{code:6033,name:"DataFieldUndefined"},{code:6034,name:"ReadOnlyAddressAlreadyExists"},{code:6035,name:"ReadOnlyAccountDoesNotExist"},{code:6036,name:"HashChainInputsLenghtInconsistent"},{code:6037,name:"InvalidAddressTreeHeight"},{code:6038,name:"InvalidStateTreeHeight"}]},exports.INSERT_INTO_QUEUES_DISCRIMINATOR=p,exports.INVOKE_CPI_DISCRIMINATOR=h,exports.INVOKE_DISCRIMINATOR=d,exports.IndexedArray=Ir,exports.IndexedElement=br,exports.IndexedElementBundle=Er,exports.InsertAddressInputLayout=pr,exports.InsertNullifierInputLayout=hr,exports.InstructionDataInvokeCpiLayout=or,exports.InstructionDataInvokeLayout=rr,exports.LatestNonVotingSignaturesResult=An,exports.LatestNonVotingSignaturesResultPaginated=Tn,exports.LightSystemProgram=vr,exports.LookupTableError=class extends fo{},exports.MerkeProofResult=Sn,exports.MerkleContextLayout=er,exports.MerkleTree=Mr,exports.MerkleTreeError=class extends fo{},exports.MerkleTreeSequenceNumberLayout=fr,exports.MultipleCompressedAccountsResult=xn,exports.MultipleMerkleProofsResult=Pn,exports.NativeBalanceResult=Nn,exports.NewAddressParamsLayout=tr,exports.NewAddressProofResult=Cn,exports.ProofError=class extends fo{},exports.PublicTransactionEventLayout=ur,exports.Rpc=Gn,exports.RpcError=class extends fo{},exports.STATE_MERKLE_TREE_NETWORK_FEE=K,exports.STATE_MERKLE_TREE_ROLLOVER_FEE=q,exports.SelectInUtxosError=class extends fo{},exports.SignatureListResult=Fn,exports.SignatureListWithCursorResult=qn,exports.SlotResult=In,exports.TRANSACTION_MERKLE_TREE_ROLLOVER_THRESHOLD=F,exports.TestRpc=Xn,exports.TokenBalanceListResult=Bn,exports.TokenBalanceListResultV2=Rn,exports.TokenBalanceResult=On,exports.TokenDataLayout=Lr,exports.TokenDataResult=wn,exports.UTXO_MERGE_MAXIMUM=10,exports.UTXO_MERGE_THRESHOLD=20,exports.UtilsError=class extends fo{},exports.UtxoError=class extends fo{},exports.ValidityProofResult=_n,exports.accountCompressionProgram=g,exports.addressQueue=O,exports.addressTree=N,exports.airdropSol=async function({connection:e,lamports:t,recipientPublicKey:r}){const n=await e.requestAirdrop(r,t);return await ot(e,n),n},exports.bn=W,exports.bufToDecStr=e=>j(e).toString(),exports.buildAndSignTx=gt,exports.buildTx=pt,exports.byteArrayToKeypair=function(t){return e.Keypair.fromSecretKey(Uint8Array.from(t))},exports.calculateComputeUnitPrice=function(e,t){return Math.ceil(1e6*e/t)},exports.checkValidityProofShape=e=>{if(32!==e.a.length||64!==e.b.length||32!==e.c.length)throw new Error("ValidityProof has invalid shape")},exports.compress=async function(t,r,n,o,s,i){const{blockhash:a}=await t.getLatestBlockhash();s||(s=it(await t.getStateTreeInfos()));const u=await vr.compress({payer:r.publicKey,toAddress:o,lamports:n,outputStateTreeInfo:s}),c=gt([e.ComputeBudgetProgram.setComputeUnitLimit({units:1e6}),u],r,a,[]);return await ft(t,c,i)},exports.confirmConfig={commitment:"confirmed",preflightCommitment:"confirmed"},exports.confirmTransaction=ot,exports.confirmTx=mt,exports.convertMerkleProofsWithContextToHex=Zn,exports.convertNonInclusionMerkleProofInputsToHex=Jn,exports.convertToPublicTransactionEvent=gr,exports.cpiContext2Pubkey=D,exports.cpiContextPubkey=P,exports.createAccount=async function(t,r,n,o,s,i,a){const{blockhash:u}=await t.getLatestBlockhash(),{tree:c,queue:l}=null!=s?s:I(),d=tt(n,o),h=rt(d,c);i||(i=it(await t.getStateTreeInfos()));const p=await t.getValidityProofV0(void 0,[{address:W(h.toBytes()),tree:c,queue:l}]),f={seed:d,addressMerkleTreeRootIndex:p.rootIndices[0],addressMerkleTreePubkey:p.treeInfos[0].tree,addressQueuePubkey:p.treeInfos[0].queue},m=await vr.createAccount({payer:r.publicKey,newAddressParams:f,newAddress:Array.from(h.toBytes()),recentValidityProof:p.compressedProof,programId:o,outputStateTreeInfo:i}),g=gt([e.ComputeBudgetProgram.setComputeUnitLimit({units:1e6}),m],r,u,[]);return await ft(t,g,a)},exports.createAccountWithLamports=async function(t,r,n,o,s,i,a,u){o=W(o);const c=await t.getCompressedAccountsByOwner(r.publicKey),[l]=xr(c.items,o),{blockhash:d}=await t.getLatestBlockhash(),{tree:h}=null!=i?i:I(),p=tt(n,s),f=rt(p,h),m=await t.getValidityProof(l.map((e=>e.hash)),[W(f.toBytes())]),g={seed:p,addressMerkleTreeRootIndex:m.rootIndices[m.rootIndices.length-1],addressMerkleTreePubkey:m.treeInfos[m.treeInfos.length-1].tree,addressQueuePubkey:m.treeInfos[m.treeInfos.length-1].queue},y=await vr.createAccount({payer:r.publicKey,newAddressParams:g,newAddress:Array.from(f.toBytes()),recentValidityProof:m.compressedProof,inputCompressedAccounts:l,inputStateRootIndices:m.rootIndices,outputStateTreeInfo:a}),w=gt([e.ComputeBudgetProgram.setComputeUnitLimit({units:1e6}),y],r,d,[]);return await ft(t,w,u)},exports.createBN254=j,exports.createCompressedAccount=Z,exports.createCompressedAccountWithMerkleContext=J,exports.createMerkleContext=Q,exports.createRpc=function(t,r,n,o){let s;if(t)if("string"==typeof t)s=t,r=r||s,n=n||s;else{if(!(t instanceof e.Connection))throw new Error("Invalid endpoint or connection type");s=t.rpcEndpoint,r=r||s,n=n||s}else s="http://127.0.0.1:8899",r=r||"http://127.0.0.1:8784",n=n||"http://127.0.0.1:3001";return new Gn(s,r,n,o)},exports.createRpcResult=pn,exports.createStateTreeLookupTable=async function({connection:t,payer:r,authority:n,recentSlot:o}){const[s,i]=e.AddressLookupTableProgram.createLookupTable({payer:r.publicKey,authority:n.publicKey,recentSlot:o}),a=gt([s],r,(await t.getLatestBlockhash()).blockhash,st(r,[n]));return{address:i,txId:await ft(t,a)}},exports.decodeInstructionDataInvoke=sr,exports.decodeInstructionDataInvokeCpi=ir,exports.decodePublicTransactionEvent=cr,exports.decompress=async function(t,r,n,o,s){const i=(await t.getCompressedAccountsByOwner(r.publicKey)).items;n=W(n);const a=yr(i);if(n.gt(a))throw new Error(`Not enough compressed lamports. Expected ${n}, got ${a}`);const u=await t.getValidityProof(i.map((e=>W(e.hash)))),{blockhash:c}=await t.getLatestBlockhash(),l=await vr.decompress({payer:r.publicKey,toAddress:o,inputCompressedAccounts:i,recentValidityProof:u.compressedProof,recentInputStateRootIndices:u.rootIndices,lamports:n}),d=gt([e.ComputeBudgetProgram.setComputeUnitLimit({units:1e6}),l],r,c,[]);return await ft(t,d,s)},exports.dedupeSigner=st,exports.deepEqual=function e(t,r){if(typeof t!=typeof r)return console.log(`Type mismatch: ${typeof t} !== ${typeof r}`),0;if(t instanceof a&&r instanceof a)return t.eq(r);if("object"==typeof t&&null!==t&&null!==r){const n=Object.keys(t),o=Object.keys(r);if(n.length!==o.length)return console.log(`Key length mismatch: ${n.length} !== ${o.length}`),0;for(const s of n){if(!o.includes(s))return console.log(`Key ${s} not found in value`),0;if(!e(t[s],r[s]))return console.log(`Value mismatch at key ${s}`),0}return 1}return t!==r&&console.log(`Value mismatch: ${t} !== ${r}`),t===r},exports.defaultStateTreeLookupTables=x,exports.defaultStaticAccounts=()=>[new e.PublicKey(y()),new e.PublicKey(f),new e.PublicKey(g),new e.PublicKey(w())],exports.defaultStaticAccountsStruct=v,exports.defaultTestStateTreeAccounts=M,exports.defaultTestStateTreeAccounts2=()=>({nullifierQueue2:new e.PublicKey(R),merkleTree2:new e.PublicKey(B)}),exports.deriveAddress=rt,exports.deriveAddressSeed=tt,exports.deserializeAppendNullifyCreateAddressInputsIndexer=mr,exports.encodeBN254toBase58=z,exports.encodeInstructionDataInvoke=nr,exports.encodePublicTransactionEvent=function(e){const r=t.Buffer.alloc(1e3),n=ur.encode(e,r);return r.slice(0,n)},exports.extendStateTreeLookupTable=async function({connection:t,tableAddress:r,newStateTreeAddresses:n,newQueueAddresses:o,newCpiContextAddresses:s,payer:i,authority:a}){const u=await t.getAddressLookupTable(r);if(!u.value)throw new Error("Lookup table not found");if(u.value.state.addresses.length%3!=0)throw new Error("Lookup table must have a multiple of 3 addresses");if(n.length!==o.length||n.length!==s.length)throw new Error("Same number of newStateTreeAddresses, newQueueAddresses, and newCpiContextAddresses required");const c=gt([e.AddressLookupTableProgram.extendLookupTable({payer:i.publicKey,authority:a.publicKey,lookupTable:r,addresses:n.flatMap(((e,t)=>[e,o[t],s[t]]))})],i,(await t.getLatestBlockhash()).blockhash,st(i,[a]));return{tableAddress:r,txId:await ft(t,c)}},exports.getAccountCompressionAuthority=w,exports.getAllStateTreeInfos=at,exports.getCompressedTokenAccountByHashTest=Dr,exports.getCompressedTokenAccounts=Or,exports.getCompressedTokenAccountsByDelegateTest=Rr,exports.getCompressedTokenAccountsByOwnerTest=Br,exports.getConnection=function(){return new e.Connection("http://127.0.0.1:8899","confirmed")},exports.getDefaultAddressTreeInfo=I,exports.getIndexOrAdd=G,exports.getParsedEvents=Ar,exports.getPublicInputHash=function(e,t,r,n){const o=Qn(e.map((e=>e.root)),t,n),s=r.map((e=>e.value)),i=Qn(r.map((e=>e.root)),s,n);return i.isZero()?o.isZero()?Qn([o],[i],n):o:i},exports.getRegisteredProgramPda=y,exports.getTestKeypair=oo,exports.getTestRpc=async function(e,t="http://127.0.0.1:8899",r="http://127.0.0.1:8784",n="http://127.0.0.1:3001",o,s=0){return new Xn(t,e,r,n,void 0,{depth:o||M().merkleTreeHeight,log:s})},exports.getTreeForQueue=function(e,t){const r=e.findIndex((e=>{var r;return null===(r=e.queue)||void 0===r?void 0:r.equals(t)}));if(-1===r)throw new Error("No associated tree found for queue. Please set activeStateTreeInfo with latest Tree accounts. If you use custom state trees, set manually.");if(!e[r].tree)throw new Error("Tree must not be null for state tree");return e[r].tree},exports.hashToBn254FieldSizeBe=Ye,exports.hashvToBn254FieldSizeBe=et,exports.invokeAccountsLayout=ar,exports.isLocalTest=b,exports.isSmallerThanBn254FieldSizeBe=Ge,exports.jsonRpcResult=mn,exports.jsonRpcResultAndContext=gn,exports.lightProgram=m,exports.localTestActiveStateTreeInfo=E,exports.merkleTree2Pubkey=B,exports.merkletreePubkey=L,exports.negateAndCompressProof=ct,exports.newAccountWithLamports=async function(e,t=1e9,r){(void 0===r||r>255)&&(r=256);const n=oo(r),o=await e.requestAirdrop(n.publicKey,t);return await mt(e,o),n},exports.noopProgram=f,exports.nullifiedStateTreeLookupTableDevnet=k,exports.nullifiedStateTreeLookupTableMainnet=S,exports.nullifierQueue2Pubkey=R,exports.nullifierQueuePubkey=_,exports.nullifyLookupTable=async function({connection:t,fullStateTreeAddress:r,nullifyLookupTableAddress:n,stateTreeLookupTableAddress:o,payer:s,authority:i}){const a=await t.getAddressLookupTable(o);if(!a.value)throw console.log("stateTreeLookupTable",a),new Error("State tree lookup table not found");if(!a.value.state.addresses.map((e=>e.toBase58())).includes(r.toBase58()))throw console.log("fullStateTreeAddress",r),console.log("stateTreeLookupTable.value.state.addresses",a.value.state.addresses),new Error("State tree address not found in lookup table. Pass correct address or stateTreeLookupTable");const u=await t.getAddressLookupTable(n);if(!u.value)throw new Error("Nullify table not found");if(u.value.state.addresses.map((e=>e.toBase58())).includes(r.toBase58()))throw new Error("Address already exists in nullify lookup table");const c=gt([e.AddressLookupTableProgram.extendLookupTable({payer:s.publicKey,authority:i.publicKey,lookupTable:n,addresses:[r]})],s,(await t.getLatestBlockhash()).blockhash,st(s,[i]));return{txId:await ft(t,c)}},exports.packCompressedAccounts=ee,exports.packNewAddressParams=nt,exports.padOutputStateMerkleTrees=X,exports.parseAccountData=Kn,exports.parseEvents=Tr,exports.parseLightTransaction=Cr,exports.parsePublicTransactionEventWithIdl=Sr,exports.parseTokenLayoutWithIdl=Nr,exports.pickRandomTreeAndQueue=function(e){const t=e.length,r=Math.floor(Math.random()*t);if(!e[r].queue)throw new Error("Queue must not be null for state tree");return{tree:e[r].tree,queue:e[r].queue}},exports.pipe=function(e,...t){return r=>t.reduce(((e,t)=>t(e)),e(r))},exports.placeholderValidityProof=()=>({a:Array.from({length:32},((e,t)=>t+1)),b:Array.from({length:64},((e,t)=>t+1)),c:Array.from({length:32},((e,t)=>t+1))}),exports.proofFromJsonStruct=ut,exports.proverRequest=Wn,exports.pushUniqueItems=function(e,t){e.forEach((e=>{t.includes(e)||t.push(e)}))},exports.rpcRequest=zn,exports.selectMinCompressedSolAccountsForTransfer=xr,exports.selectStateTreeInfo=it,exports.sendAndConfirmTx=ft,exports.sleep=function(e){return new Promise((t=>setTimeout(t,e)))},exports.stateTreeLookupTableDevnet=C,exports.stateTreeLookupTableMainnet=T,exports.sumUpLamports=yr,exports.toAccountMetas=Y,exports.toArray=e=>Array.isArray(e)?e:[e],exports.toCamelCase=Xe,exports.toHex=Qe,exports.toUnixTimestamp=e=>new Date(e).getTime(),exports.transfer=async function(t,r,n,o,s,i,a){var u;let c=W(0);const l=[];let d;for(n=W(n);c.lt(n);){const e={filters:void 0,dataSlice:void 0,cursor:d,limit:W(1e3)},r=await t.getCompressedAccountsByOwner(o.publicKey,e);for(const e of r.items)e.lamports.gt(W(0))&&(l.push(e),c=c.add(e.lamports));if(d=null!==(u=r.cursor)&&void 0!==u?u:void 0,r.items.length<1e3||c.gte(n))break}if(c.lt(n))throw new Error(`Insufficient balance for transfer. Required: ${n.toString()}, available: ${c.toString()}`);const[h]=xr(l,n),p=await t.getValidityProof(h.map((e=>W(e.hash)))),f=await vr.transfer({payer:r.publicKey,inputCompressedAccounts:h,toAddress:s,lamports:n,recentInputStateRootIndices:p.rootIndices,recentValidityProof:p.compressedProof}),{blockhash:m}=await t.getLatestBlockhash(),g=gt([e.ComputeBudgetProgram.setComputeUnitLimit({units:1e6}),f],r,m);return await ft(t,g,a)},exports.validateNumbers=ie,exports.validateNumbersForInclusionProof=oe,exports.validateNumbersForNonInclusionProof=se,exports.validateNumbersForProof=ne,exports.validateSameOwner=re,exports.validateSufficientBalance=te,exports.wrapBigNumbersAsStrings=jn;
1
+ "use strict";var e=require("@solana/web3.js"),t=require("buffer"),r="undefined"!=typeof globalThis?globalThis:"undefined"!=typeof window?window:"undefined"!=typeof global?global:"undefined"!=typeof self?self:{};function o(e){return e&&e.__esModule&&Object.prototype.hasOwnProperty.call(e,"default")?e.default:e}var n={},s={};class i{constructor(e,t){if(!Number.isInteger(e))throw new TypeError("span must be an integer");this.span=e,this.property=t}makeDestinationObject(){return{}}decode(e,t){throw new Error("Layout is abstract")}encode(e,t,r){throw new Error("Layout is abstract")}getSpan(e,t){if(0>this.span)throw new RangeError("indeterminate span");return this.span}replicate(e){const t=Object.create(this.constructor.prototype);return Object.assign(t,this),t.property=e,t}fromArray(e){}}function a(e,t){return t.property?e+"["+t.property+"]":e}s.Layout=i,s.nameWithProperty=a,s.bindConstructorLayout=function(e,t){if("function"!=typeof e)throw new TypeError("Class must be constructor");if(e.hasOwnProperty("layout_"))throw new Error("Class is already bound to a layout");if(!(t&&t instanceof i))throw new TypeError("layout must be a Layout");if(t.hasOwnProperty("boundConstructor_"))throw new Error("layout is already bound to a constructor");e.layout_=t,t.boundConstructor_=e,t.makeDestinationObject=()=>new e,Object.defineProperty(e.prototype,"encode",{value:function(e,r){return t.encode(this,e,r)},writable:1}),Object.defineProperty(e,"decode",{value:function(e,r){return t.decode(e,r)},writable:1})};class u extends i{isCount(){throw new Error("ExternalLayout is abstract")}}class c extends u{constructor(e,t){if(void 0===e&&(e=1),!Number.isInteger(e)||0>=e)throw new TypeError("elementSpan must be a (positive) integer");super(-1,t),this.elementSpan=e}isCount(){return 1}decode(e,t){void 0===t&&(t=0);const r=e.length-t;return Math.floor(r/this.elementSpan)}encode(e,t,r){return 0}}class l extends u{constructor(e,t,r){if(!(e instanceof i))throw new TypeError("layout must be a Layout");if(void 0===t)t=0;else if(!Number.isInteger(t))throw new TypeError("offset must be integer or undefined");super(e.span,r||e.property),this.layout=e,this.offset=t}isCount(){return this.layout instanceof d||this.layout instanceof p}decode(e,t){return void 0===t&&(t=0),this.layout.decode(e,t+this.offset)}encode(e,t,r){return void 0===r&&(r=0),this.layout.encode(e,t,r+this.offset)}}class d extends i{constructor(e,t){if(super(e,t),6<this.span)throw new RangeError("span must not exceed 6 bytes")}decode(e,t){return void 0===t&&(t=0),e.readUIntLE(t,this.span)}encode(e,t,r){return void 0===r&&(r=0),t.writeUIntLE(e,r,this.span),this.span}}class p extends i{constructor(e,t){if(super(e,t),6<this.span)throw new RangeError("span must not exceed 6 bytes")}decode(e,t){return void 0===t&&(t=0),e.readUIntBE(t,this.span)}encode(e,t,r){return void 0===r&&(r=0),t.writeUIntBE(e,r,this.span),this.span}}class h extends i{constructor(e,t){if(super(e,t),6<this.span)throw new RangeError("span must not exceed 6 bytes")}decode(e,t){return void 0===t&&(t=0),e.readIntLE(t,this.span)}encode(e,t,r){return void 0===r&&(r=0),t.writeIntLE(e,r,this.span),this.span}}class m extends i{constructor(e,t){if(super(e,t),6<this.span)throw new RangeError("span must not exceed 6 bytes")}decode(e,t){return void 0===t&&(t=0),e.readIntBE(t,this.span)}encode(e,t,r){return void 0===r&&(r=0),t.writeIntBE(e,r,this.span),this.span}}const f=Math.pow(2,32);function y(e){const t=Math.floor(e/f);return{hi32:t,lo32:e-t*f}}function g(e,t){return e*f+t}class w extends i{constructor(e){super(8,e)}decode(e,t){void 0===t&&(t=0);const r=e.readUInt32LE(t);return g(e.readUInt32LE(t+4),r)}encode(e,t,r){void 0===r&&(r=0);const o=y(e);return t.writeUInt32LE(o.lo32,r),t.writeUInt32LE(o.hi32,r+4),8}}class v extends i{constructor(e){super(8,e)}decode(e,t){return void 0===t&&(t=0),g(e.readUInt32BE(t),e.readUInt32BE(t+4))}encode(e,t,r){void 0===r&&(r=0);const o=y(e);return t.writeUInt32BE(o.hi32,r),t.writeUInt32BE(o.lo32,r+4),8}}class x extends i{constructor(e){super(8,e)}decode(e,t){void 0===t&&(t=0);const r=e.readUInt32LE(t);return g(e.readInt32LE(t+4),r)}encode(e,t,r){void 0===r&&(r=0);const o=y(e);return t.writeUInt32LE(o.lo32,r),t.writeInt32LE(o.hi32,r+4),8}}class b extends i{constructor(e){super(8,e)}decode(e,t){return void 0===t&&(t=0),g(e.readInt32BE(t),e.readUInt32BE(t+4))}encode(e,t,r){void 0===r&&(r=0);const o=y(e);return t.writeInt32BE(o.hi32,r),t.writeUInt32BE(o.lo32,r+4),8}}class I extends i{constructor(e){super(4,e)}decode(e,t){return void 0===t&&(t=0),e.readFloatLE(t)}encode(e,t,r){return void 0===r&&(r=0),t.writeFloatLE(e,r),4}}class A extends i{constructor(e){super(4,e)}decode(e,t){return void 0===t&&(t=0),e.readFloatBE(t)}encode(e,t,r){return void 0===r&&(r=0),t.writeFloatBE(e,r),4}}class E extends i{constructor(e){super(8,e)}decode(e,t){return void 0===t&&(t=0),e.readDoubleLE(t)}encode(e,t,r){return void 0===r&&(r=0),t.writeDoubleLE(e,r),8}}class T extends i{constructor(e){super(8,e)}decode(e,t){return void 0===t&&(t=0),e.readDoubleBE(t)}encode(e,t,r){return void 0===r&&(r=0),t.writeDoubleBE(e,r),8}}class M extends i{constructor(e,t,r){if(!(e instanceof i))throw new TypeError("elementLayout must be a Layout");if(!(t instanceof u&&t.isCount()||Number.isInteger(t)&&0<=t))throw new TypeError("count must be non-negative integer or an unsigned integer ExternalLayout");let o=-1;!(t instanceof u)&&0<e.span&&(o=t*e.span),super(o,r),this.elementLayout=e,this.count=t}getSpan(e,t){if(0<=this.span)return this.span;void 0===t&&(t=0);let r=0,o=this.count;if(o instanceof u&&(o=o.decode(e,t)),0<this.elementLayout.span)r=o*this.elementLayout.span;else{let n=0;for(;n<o;)r+=this.elementLayout.getSpan(e,t+r),++n}return r}decode(e,t){void 0===t&&(t=0);const r=[];let o=0,n=this.count;for(n instanceof u&&(n=n.decode(e,t));o<n;)r.push(this.elementLayout.decode(e,t)),t+=this.elementLayout.getSpan(e,t),o+=1;return r}encode(e,t,r){void 0===r&&(r=0);const o=this.elementLayout,n=e.reduce(((e,n)=>e+o.encode(n,t,r+e)),0);return this.count instanceof u&&this.count.encode(e.length,t,r),n}}class S extends i{constructor(e,t,r){if(!Array.isArray(e)||!e.reduce(((e,t)=>e&&t instanceof i),1))throw new TypeError("fields must be array of Layout instances");"boolean"==typeof t&&void 0===r&&(r=t,t=void 0);for(const t of e)if(0>t.span&&void 0===t.property)throw new Error("fields cannot contain unnamed variable-length layout");let o=-1;try{o=e.reduce(((e,t)=>e+t.getSpan()),0)}catch(e){}super(o,t),this.fields=e,this.decodePrefixes=!!r}getSpan(e,t){if(0<=this.span)return this.span;void 0===t&&(t=0);let r=0;try{r=this.fields.reduce(((r,o)=>{const n=o.getSpan(e,t);return t+=n,r+n}),0)}catch(e){throw new RangeError("indeterminate span")}return r}decode(e,t){void 0===t&&(t=0);const r=this.makeDestinationObject();for(const o of this.fields)if(void 0!==o.property&&(r[o.property]=o.decode(e,t)),t+=o.getSpan(e,t),this.decodePrefixes&&e.length===t)break;return r}encode(e,t,r){void 0===r&&(r=0);const o=r;let n=0,s=0;for(const o of this.fields){let i=o.span;if(s=0<i?i:0,void 0!==o.property){const n=e[o.property];void 0!==n&&(s=o.encode(n,t,r),0>i&&(i=o.getSpan(t,r)))}n=r,r+=i}return n+s-o}fromArray(e){const t=this.makeDestinationObject();for(const r of this.fields)void 0!==r.property&&0<e.length&&(t[r.property]=e.shift());return t}layoutFor(e){if("string"!=typeof e)throw new TypeError("property must be string");for(const t of this.fields)if(t.property===e)return t}offsetOf(e){if("string"!=typeof e)throw new TypeError("property must be string");let t=0;for(const r of this.fields){if(r.property===e)return t;0>r.span?t=-1:0<=t&&(t+=r.span)}}}class C{constructor(e){this.property=e}decode(){throw new Error("UnionDiscriminator is abstract")}encode(){throw new Error("UnionDiscriminator is abstract")}}class k extends C{constructor(e,t){if(!(e instanceof u&&e.isCount()))throw new TypeError("layout must be an unsigned integer ExternalLayout");super(t||e.property||"variant"),this.layout=e}decode(e,t){return this.layout.decode(e,t)}encode(e,t,r){return this.layout.encode(e,t,r)}}class _ extends i{constructor(e,t,r){const o=e instanceof d||e instanceof p;if(o)e=new k(new l(e));else if(e instanceof u&&e.isCount())e=new k(e);else if(!(e instanceof C))throw new TypeError("discr must be a UnionDiscriminator or an unsigned integer layout");if(void 0===t&&(t=null),!(null===t||t instanceof i))throw new TypeError("defaultLayout must be null or a Layout");if(null!==t){if(0>t.span)throw new Error("defaultLayout must have constant span");void 0===t.property&&(t=t.replicate("content"))}let n=-1;t&&(n=t.span,0<=n&&o&&(n+=e.layout.span)),super(n,r),this.discriminator=e,this.usesPrefixDiscriminator=o,this.defaultLayout=t,this.registry={};let s=this.defaultGetSourceVariant.bind(this);this.getSourceVariant=function(e){return s(e)},this.configGetSourceVariant=function(e){s=e.bind(this)}}getSpan(e,t){if(0<=this.span)return this.span;void 0===t&&(t=0);const r=this.getVariant(e,t);if(!r)throw new Error("unable to determine span for unrecognized variant");return r.getSpan(e,t)}defaultGetSourceVariant(e){if(e.hasOwnProperty(this.discriminator.property)){if(this.defaultLayout&&e.hasOwnProperty(this.defaultLayout.property))return;const t=this.registry[e[this.discriminator.property]];if(t&&(!t.layout||e.hasOwnProperty(t.property)))return t}else for(const t in this.registry){const r=this.registry[t];if(e.hasOwnProperty(r.property))return r}throw new Error("unable to infer src variant")}decode(e,t){let r;void 0===t&&(t=0);const o=this.discriminator,n=o.decode(e,t);let s=this.registry[n];if(void 0===s){let i=0;s=this.defaultLayout,this.usesPrefixDiscriminator&&(i=o.layout.span),r=this.makeDestinationObject(),r[o.property]=n,r[s.property]=this.defaultLayout.decode(e,t+i)}else r=s.decode(e,t);return r}encode(e,t,r){void 0===r&&(r=0);const o=this.getSourceVariant(e);if(void 0===o){const o=this.discriminator,n=this.defaultLayout;let s=0;return this.usesPrefixDiscriminator&&(s=o.layout.span),o.encode(e[o.property],t,r),s+n.encode(e[n.property],t,r+s)}return o.encode(e,t,r)}addVariant(e,t,r){const o=new P(this,e,t,r);return this.registry[e]=o,o}getVariant(e,t){let r=e;return Buffer.isBuffer(e)&&(void 0===t&&(t=0),r=this.discriminator.decode(e,t)),this.registry[r]}}class P extends i{constructor(e,t,r,o){if(!(e instanceof _))throw new TypeError("union must be a Union");if(!Number.isInteger(t)||0>t)throw new TypeError("variant must be a (non-negative) integer");if("string"==typeof r&&void 0===o&&(o=r,r=null),r){if(!(r instanceof i))throw new TypeError("layout must be a Layout");if(null!==e.defaultLayout&&0<=r.span&&r.span>e.defaultLayout.span)throw new Error("variant span exceeds span of containing union");if("string"!=typeof o)throw new TypeError("variant must have a String property")}let n=e.span;0>e.span&&(n=r?r.span:0,0<=n&&e.usesPrefixDiscriminator&&(n+=e.discriminator.layout.span)),super(n,o),this.union=e,this.variant=t,this.layout=r||null}getSpan(e,t){if(0<=this.span)return this.span;void 0===t&&(t=0);let r=0;return this.union.usesPrefixDiscriminator&&(r=this.union.discriminator.layout.span),r+this.layout.getSpan(e,t+r)}decode(e,t){const r=this.makeDestinationObject();if(void 0===t&&(t=0),this!==this.union.getVariant(e,t))throw new Error("variant mismatch");let o=0;return this.union.usesPrefixDiscriminator&&(o=this.union.discriminator.layout.span),this.layout?r[this.property]=this.layout.decode(e,t+o):this.property?r[this.property]=1:this.union.usesPrefixDiscriminator&&(r[this.union.discriminator.property]=this.variant),r}encode(e,t,r){void 0===r&&(r=0);let o=0;if(this.union.usesPrefixDiscriminator&&(o=this.union.discriminator.layout.span),this.layout&&!e.hasOwnProperty(this.property))throw new TypeError("variant lacks property "+this.property);this.union.discriminator.encode(this.variant,t,r);let n=o;if(this.layout&&(this.layout.encode(e[this.property],t,r+o),n+=this.layout.getSpan(t,r+o),0<=this.union.span&&n>this.union.span))throw new Error("encoded variant overruns containing union");return n}fromArray(e){if(this.layout)return this.layout.fromArray(e)}}function O(e){return 0>e&&(e+=4294967296),e}class L extends i{constructor(e,t,r){if(!(e instanceof d||e instanceof p))throw new TypeError("word must be a UInt or UIntBE layout");if("string"==typeof t&&void 0===r&&(r=t,t=void 0),4<e.span)throw new RangeError("word cannot exceed 32 bits");super(e.span,r),this.word=e,this.msb=!!t,this.fields=[];let o=0;this._packedSetValue=function(e){return o=O(e),this},this._packedGetValue=function(){return o}}decode(e,t){const r=this.makeDestinationObject();void 0===t&&(t=0);const o=this.word.decode(e,t);this._packedSetValue(o);for(const e of this.fields)void 0!==e.property&&(r[e.property]=e.decode(o));return r}encode(e,t,r){void 0===r&&(r=0);const o=this.word.decode(t,r);this._packedSetValue(o);for(const t of this.fields)if(void 0!==t.property){const r=e[t.property];void 0!==r&&t.encode(r)}return this.word.encode(this._packedGetValue(),t,r)}addField(e,t){const r=new N(this,e,t);return this.fields.push(r),r}addBoolean(e){const t=new B(this,e);return this.fields.push(t),t}fieldFor(e){if("string"!=typeof e)throw new TypeError("property must be string");for(const t of this.fields)if(t.property===e)return t}}class N{constructor(e,t,r){if(!(e instanceof L))throw new TypeError("container must be a BitStructure");if(!Number.isInteger(t)||0>=t)throw new TypeError("bits must be positive integer");const o=8*e.span,n=e.fields.reduce(((e,t)=>e+t.bits),0);if(t+n>o)throw new Error("bits too long for span remainder ("+(o-n)+" of "+o+" remain)");this.container=e,this.bits=t,this.valueMask=(1<<t)-1,32===t&&(this.valueMask=4294967295),this.start=n,this.container.msb&&(this.start=o-n-t),this.wordMask=O(this.valueMask<<this.start),this.property=r}decode(){return O(this.container._packedGetValue()&this.wordMask)>>>this.start}encode(e){if(!Number.isInteger(e)||e!==O(e&this.valueMask))throw new TypeError(a("BitField.encode",this)+" value must be integer not exceeding "+this.valueMask);const t=this.container._packedGetValue(),r=O(e<<this.start);this.container._packedSetValue(O(t&~this.wordMask)|r)}}class B extends N{constructor(e,t){super(e,1,t)}decode(e,t){return!!N.prototype.decode.call(this,e,t)}encode(e){return"boolean"==typeof e&&(e=+e),N.prototype.encode.call(this,e)}}class R extends i{constructor(e,t){if(!(e instanceof u&&e.isCount()||Number.isInteger(e)&&0<=e))throw new TypeError("length must be positive integer or an unsigned integer ExternalLayout");let r=-1;e instanceof u||(r=e),super(r,t),this.length=e}getSpan(e,t){let r=this.span;return 0>r&&(r=this.length.decode(e,t)),r}decode(e,t){void 0===t&&(t=0);let r=this.span;return 0>r&&(r=this.length.decode(e,t)),e.slice(t,t+r)}encode(e,t,r){let o=this.length;if(this.length instanceof u&&(o=e.length),!Buffer.isBuffer(e)||o!==e.length)throw new TypeError(a("Blob.encode",this)+" requires (length "+o+") Buffer as src");if(r+o>t.length)throw new RangeError("encoding overruns Buffer");return t.write(e.toString("hex"),r,o,"hex"),this.length instanceof u&&this.length.encode(o,t,r),o}}class D extends i{constructor(e){super(-1,e)}getSpan(e,t){if(!Buffer.isBuffer(e))throw new TypeError("b must be a Buffer");void 0===t&&(t=0);let r=t;for(;r<e.length&&0!==e[r];)r+=1;return 1+r-t}decode(e,t,r){void 0===t&&(t=0);let o=this.getSpan(e,t);return e.slice(t,t+o-1).toString("utf-8")}encode(e,t,r){void 0===r&&(r=0),"string"!=typeof e&&(e=e.toString());const o=new Buffer(e,"utf8"),n=o.length;if(r+n>t.length)throw new RangeError("encoding overruns Buffer");return o.copy(t,r),t[r+n]=0,n+1}}class U extends i{constructor(e,t){if("string"==typeof e&&void 0===t&&(t=e,e=void 0),void 0===e)e=-1;else if(!Number.isInteger(e))throw new TypeError("maxSpan must be an integer");super(-1,t),this.maxSpan=e}getSpan(e,t){if(!Buffer.isBuffer(e))throw new TypeError("b must be a Buffer");return void 0===t&&(t=0),e.length-t}decode(e,t,r){void 0===t&&(t=0);let o=this.getSpan(e,t);if(0<=this.maxSpan&&this.maxSpan<o)throw new RangeError("text length exceeds maxSpan");return e.slice(t,t+o).toString("utf-8")}encode(e,t,r){void 0===r&&(r=0),"string"!=typeof e&&(e=e.toString());const o=new Buffer(e,"utf8"),n=o.length;if(0<=this.maxSpan&&this.maxSpan<n)throw new RangeError("text length exceeds maxSpan");if(r+n>t.length)throw new RangeError("encoding overruns Buffer");return o.copy(t,r),n}}class V extends i{constructor(e,t){super(0,t),this.value=e}decode(e,t,r){return this.value}encode(e,t,r){return 0}}s.ExternalLayout=u,s.GreedyCount=c,s.OffsetLayout=l,s.UInt=d,s.UIntBE=p,s.Int=h,s.IntBE=m,s.Float=I,s.FloatBE=A,s.Double=E,s.DoubleBE=T,s.Sequence=M,s.Structure=S,s.UnionDiscriminator=C,s.UnionLayoutDiscriminator=k,s.Union=_,s.VariantLayout=P,s.BitStructure=L,s.BitField=N,s.Boolean=B,s.Blob=R,s.CString=D,s.UTF8=U,s.Constant=V,s.greedy=(e,t)=>new c(e,t),s.offset=(e,t,r)=>new l(e,t,r),s.u8=e=>new d(1,e),s.u16=e=>new d(2,e),s.u24=e=>new d(3,e),s.u32=e=>new d(4,e),s.u40=e=>new d(5,e),s.u48=e=>new d(6,e),s.nu64=e=>new w(e),s.u16be=e=>new p(2,e),s.u24be=e=>new p(3,e),s.u32be=e=>new p(4,e),s.u40be=e=>new p(5,e),s.u48be=e=>new p(6,e),s.nu64be=e=>new v(e),s.s8=e=>new h(1,e),s.s16=e=>new h(2,e),s.s24=e=>new h(3,e),s.s32=e=>new h(4,e),s.s40=e=>new h(5,e),s.s48=e=>new h(6,e),s.ns64=e=>new x(e),s.s16be=e=>new m(2,e),s.s24be=e=>new m(3,e),s.s32be=e=>new m(4,e),s.s40be=e=>new m(5,e),s.s48be=e=>new m(6,e),s.ns64be=e=>new b(e),s.f32=e=>new I(e),s.f32be=e=>new A(e),s.f64=e=>new E(e),s.f64be=e=>new T(e),s.struct=(e,t,r)=>new S(e,t,r),s.bits=(e,t,r)=>new L(e,t,r),s.seq=(e,t,r)=>new M(e,t,r),s.union=(e,t,r)=>new _(e,t,r),s.unionLayoutDiscriminator=(e,t)=>new k(e,t),s.blob=(e,t)=>new R(e,t),s.cstr=e=>new D(e),s.utf8=(e,t)=>new U(e,t),s.const=(e,t)=>new V(e,t);var F={exports:{}};!function(e,t){function r(e,t){if(!e)throw new Error(t||"Assertion failed")}function o(e,t){e.super_=t;var r=function(){};r.prototype=t.prototype,e.prototype=new r,e.prototype.constructor=e}function n(e,t,r){if(n.isBN(e))return e;this.negative=0,this.words=null,this.length=0,this.red=null,null!==e&&("le"!==t&&"be"!==t||(r=t,t=10),this._init(e||0,t||10,r||"be"))}var s;"object"==typeof F?F.exports=n:t.BN=n,n.BN=n,n.wordSize=26;try{s="undefined"!=typeof window&&void 0!==window.Buffer?window.Buffer:require("buffer").Buffer}catch(e){}function i(e,t){var o=e.charCodeAt(t);return o>=48&&o<=57?o-48:o>=65&&o<=70?o-55:o>=97&&o<=102?o-87:void r(0,"Invalid character in "+e)}function a(e,t,r){var o=i(e,r);return r-1>=t&&(o|=i(e,r-1)<<4),o}function u(e,t,o,n){for(var s=0,i=0,a=Math.min(e.length,o),u=t;u<a;u++){var c=e.charCodeAt(u)-48;s*=n,i=c>=49?c-49+10:c>=17?c-17+10:c,r(c>=0&&i<n,"Invalid character"),s+=i}return s}function c(e,t){e.words=t.words,e.length=t.length,e.negative=t.negative,e.red=t.red}if(n.isBN=function(e){return e instanceof n?1:null!==e&&"object"==typeof e&&e.constructor.wordSize===n.wordSize&&Array.isArray(e.words)},n.max=function(e,t){return e.cmp(t)>0?e:t},n.min=function(e,t){return e.cmp(t)<0?e:t},n.prototype._init=function(e,t,o){if("number"==typeof e)return this._initNumber(e,t,o);if("object"==typeof e)return this._initArray(e,t,o);"hex"===t&&(t=16),r(t===(0|t)&&t>=2&&t<=36);var n=0;"-"===(e=e.toString().replace(/\s+/g,""))[0]&&(n++,this.negative=1),n<e.length&&(16===t?this._parseHex(e,n,o):(this._parseBase(e,t,n),"le"===o&&this._initArray(this.toArray(),t,o)))},n.prototype._initNumber=function(e,t,o){e<0&&(this.negative=1,e=-e),e<67108864?(this.words=[67108863&e],this.length=1):e<4503599627370496?(this.words=[67108863&e,e/67108864&67108863],this.length=2):(r(e<9007199254740992),this.words=[67108863&e,e/67108864&67108863,1],this.length=3),"le"===o&&this._initArray(this.toArray(),t,o)},n.prototype._initArray=function(e,t,o){if(r("number"==typeof e.length),e.length<=0)return this.words=[0],this.length=1,this;this.length=Math.ceil(e.length/3),this.words=new Array(this.length);for(var n=0;n<this.length;n++)this.words[n]=0;var s,i,a=0;if("be"===o)for(n=e.length-1,s=0;n>=0;n-=3)i=e[n]|e[n-1]<<8|e[n-2]<<16,this.words[s]|=i<<a&67108863,this.words[s+1]=i>>>26-a&67108863,(a+=24)>=26&&(a-=26,s++);else if("le"===o)for(n=0,s=0;n<e.length;n+=3)i=e[n]|e[n+1]<<8|e[n+2]<<16,this.words[s]|=i<<a&67108863,this.words[s+1]=i>>>26-a&67108863,(a+=24)>=26&&(a-=26,s++);return this._strip()},n.prototype._parseHex=function(e,t,r){this.length=Math.ceil((e.length-t)/6),this.words=new Array(this.length);for(var o=0;o<this.length;o++)this.words[o]=0;var n,s=0,i=0;if("be"===r)for(o=e.length-1;o>=t;o-=2)n=a(e,t,o)<<s,this.words[i]|=67108863&n,s>=18?(s-=18,i+=1,this.words[i]|=n>>>26):s+=8;else for(o=(e.length-t)%2==0?t+1:t;o<e.length;o+=2)n=a(e,t,o)<<s,this.words[i]|=67108863&n,s>=18?(s-=18,i+=1,this.words[i]|=n>>>26):s+=8;this._strip()},n.prototype._parseBase=function(e,t,r){this.words=[0],this.length=1;for(var o=0,n=1;n<=67108863;n*=t)o++;o--,n=n/t|0;for(var s=e.length-r,i=s%o,a=Math.min(s,s-i)+r,c=0,l=r;l<a;l+=o)c=u(e,l,l+o,t),this.imuln(n),this.words[0]+c<67108864?this.words[0]+=c:this._iaddn(c);if(0!==i){var d=1;for(c=u(e,l,e.length,t),l=0;l<i;l++)d*=t;this.imuln(d),this.words[0]+c<67108864?this.words[0]+=c:this._iaddn(c)}this._strip()},n.prototype.copy=function(e){e.words=new Array(this.length);for(var t=0;t<this.length;t++)e.words[t]=this.words[t];e.length=this.length,e.negative=this.negative,e.red=this.red},n.prototype._move=function(e){c(e,this)},n.prototype.clone=function(){var e=new n(null);return this.copy(e),e},n.prototype._expand=function(e){for(;this.length<e;)this.words[this.length++]=0;return this},n.prototype._strip=function(){for(;this.length>1&&0===this.words[this.length-1];)this.length--;return this._normSign()},n.prototype._normSign=function(){return 1===this.length&&0===this.words[0]&&(this.negative=0),this},"undefined"!=typeof Symbol&&"function"==typeof Symbol.for)try{n.prototype[Symbol.for("nodejs.util.inspect.custom")]=l}catch(e){n.prototype.inspect=l}else n.prototype.inspect=l;function l(){return(this.red?"<BN-R: ":"<BN: ")+this.toString(16)+">"}var d=["","0","00","000","0000","00000","000000","0000000","00000000","000000000","0000000000","00000000000","000000000000","0000000000000","00000000000000","000000000000000","0000000000000000","00000000000000000","000000000000000000","0000000000000000000","00000000000000000000","000000000000000000000","0000000000000000000000","00000000000000000000000","000000000000000000000000","0000000000000000000000000"],p=[0,0,25,16,12,11,10,9,8,8,7,7,7,7,6,6,6,6,6,6,6,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5],h=[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 m(e,t,r){r.negative=t.negative^e.negative;var o=e.length+t.length|0;r.length=o,o=o-1|0;var n=0|e.words[0],s=0|t.words[0],i=n*s,a=67108863&i,u=i/67108864|0;r.words[0]=a;for(var c=1;c<o;c++){for(var l=u>>>26,d=67108863&u,p=Math.min(c,t.length-1),h=Math.max(0,c-e.length+1);h<=p;h++){var m=c-h|0;l+=(i=(n=0|e.words[m])*(s=0|t.words[h])+d)/67108864|0,d=67108863&i}r.words[c]=0|d,u=0|l}return 0!==u?r.words[c]=0|u:r.length--,r._strip()}n.prototype.toString=function(e,t){var o;if(t=0|t||1,16===(e=e||10)||"hex"===e){o="";for(var n=0,s=0,i=0;i<this.length;i++){var a=this.words[i],u=(16777215&(a<<n|s)).toString(16);s=a>>>24-n&16777215,(n+=2)>=26&&(n-=26,i--),o=0!==s||i!==this.length-1?d[6-u.length]+u+o:u+o}for(0!==s&&(o=s.toString(16)+o);o.length%t!=0;)o="0"+o;return 0!==this.negative&&(o="-"+o),o}if(e===(0|e)&&e>=2&&e<=36){var c=p[e],l=h[e];o="";var m=this.clone();for(m.negative=0;!m.isZero();){var f=m.modrn(l).toString(e);o=(m=m.idivn(l)).isZero()?f+o:d[c-f.length]+f+o}for(this.isZero()&&(o="0"+o);o.length%t!=0;)o="0"+o;return 0!==this.negative&&(o="-"+o),o}r(0,"Base should be between 2 and 36")},n.prototype.toNumber=function(){var e=this.words[0];return 2===this.length?e+=67108864*this.words[1]:3===this.length&&1===this.words[2]?e+=4503599627370496+67108864*this.words[1]:this.length>2&&r(0,"Number can only safely store up to 53 bits"),0!==this.negative?-e:e},n.prototype.toJSON=function(){return this.toString(16,2)},s&&(n.prototype.toBuffer=function(e,t){return this.toArrayLike(s,e,t)}),n.prototype.toArray=function(e,t){return this.toArrayLike(Array,e,t)},n.prototype.toArrayLike=function(e,t,o){this._strip();var n=this.byteLength(),s=o||Math.max(1,n);r(n<=s,"byte array longer than desired length"),r(s>0,"Requested array length <= 0");var i=function(e,t){return e.allocUnsafe?e.allocUnsafe(t):new e(t)}(e,s);return this["_toArrayLike"+("le"===t?"LE":"BE")](i,n),i},n.prototype._toArrayLikeLE=function(e){for(var t=0,r=0,o=0,n=0;o<this.length;o++){var s=this.words[o]<<n|r;e[t++]=255&s,t<e.length&&(e[t++]=s>>8&255),t<e.length&&(e[t++]=s>>16&255),6===n?(t<e.length&&(e[t++]=s>>24&255),r=0,n=0):(r=s>>>24,n+=2)}if(t<e.length)for(e[t++]=r;t<e.length;)e[t++]=0},n.prototype._toArrayLikeBE=function(e){for(var t=e.length-1,r=0,o=0,n=0;o<this.length;o++){var s=this.words[o]<<n|r;e[t--]=255&s,t>=0&&(e[t--]=s>>8&255),t>=0&&(e[t--]=s>>16&255),6===n?(t>=0&&(e[t--]=s>>24&255),r=0,n=0):(r=s>>>24,n+=2)}if(t>=0)for(e[t--]=r;t>=0;)e[t--]=0},Math.clz32?n.prototype._countBits=function(e){return 32-Math.clz32(e)}:n.prototype._countBits=function(e){var t=e,r=0;return t>=4096&&(r+=13,t>>>=13),t>=64&&(r+=7,t>>>=7),t>=8&&(r+=4,t>>>=4),t>=2&&(r+=2,t>>>=2),r+t},n.prototype._zeroBits=function(e){if(0===e)return 26;var t=e,r=0;return 0==(8191&t)&&(r+=13,t>>>=13),0==(127&t)&&(r+=7,t>>>=7),0==(15&t)&&(r+=4,t>>>=4),0==(3&t)&&(r+=2,t>>>=2),0==(1&t)&&r++,r},n.prototype.bitLength=function(){var e=this.words[this.length-1],t=this._countBits(e);return 26*(this.length-1)+t},n.prototype.zeroBits=function(){if(this.isZero())return 0;for(var e=0,t=0;t<this.length;t++){var r=this._zeroBits(this.words[t]);if(e+=r,26!==r)break}return e},n.prototype.byteLength=function(){return Math.ceil(this.bitLength()/8)},n.prototype.toTwos=function(e){return 0!==this.negative?this.abs().inotn(e).iaddn(1):this.clone()},n.prototype.fromTwos=function(e){return this.testn(e-1)?this.notn(e).iaddn(1).ineg():this.clone()},n.prototype.isNeg=function(){return 0!==this.negative},n.prototype.neg=function(){return this.clone().ineg()},n.prototype.ineg=function(){return this.isZero()||(this.negative^=1),this},n.prototype.iuor=function(e){for(;this.length<e.length;)this.words[this.length++]=0;for(var t=0;t<e.length;t++)this.words[t]=this.words[t]|e.words[t];return this._strip()},n.prototype.ior=function(e){return r(0==(this.negative|e.negative)),this.iuor(e)},n.prototype.or=function(e){return this.length>e.length?this.clone().ior(e):e.clone().ior(this)},n.prototype.uor=function(e){return this.length>e.length?this.clone().iuor(e):e.clone().iuor(this)},n.prototype.iuand=function(e){var t;t=this.length>e.length?e:this;for(var r=0;r<t.length;r++)this.words[r]=this.words[r]&e.words[r];return this.length=t.length,this._strip()},n.prototype.iand=function(e){return r(0==(this.negative|e.negative)),this.iuand(e)},n.prototype.and=function(e){return this.length>e.length?this.clone().iand(e):e.clone().iand(this)},n.prototype.uand=function(e){return this.length>e.length?this.clone().iuand(e):e.clone().iuand(this)},n.prototype.iuxor=function(e){var t,r;this.length>e.length?(t=this,r=e):(t=e,r=this);for(var o=0;o<r.length;o++)this.words[o]=t.words[o]^r.words[o];if(this!==t)for(;o<t.length;o++)this.words[o]=t.words[o];return this.length=t.length,this._strip()},n.prototype.ixor=function(e){return r(0==(this.negative|e.negative)),this.iuxor(e)},n.prototype.xor=function(e){return this.length>e.length?this.clone().ixor(e):e.clone().ixor(this)},n.prototype.uxor=function(e){return this.length>e.length?this.clone().iuxor(e):e.clone().iuxor(this)},n.prototype.inotn=function(e){r("number"==typeof e&&e>=0);var t=0|Math.ceil(e/26),o=e%26;this._expand(t),o>0&&t--;for(var n=0;n<t;n++)this.words[n]=67108863&~this.words[n];return o>0&&(this.words[n]=~this.words[n]&67108863>>26-o),this._strip()},n.prototype.notn=function(e){return this.clone().inotn(e)},n.prototype.setn=function(e,t){r("number"==typeof e&&e>=0);var o=e/26|0,n=e%26;return this._expand(o+1),this.words[o]=t?this.words[o]|1<<n:this.words[o]&~(1<<n),this._strip()},n.prototype.iadd=function(e){var t,r,o;if(0!==this.negative&&0===e.negative)return this.negative=0,t=this.isub(e),this.negative^=1,this._normSign();if(0===this.negative&&0!==e.negative)return e.negative=0,t=this.isub(e),e.negative=1,t._normSign();this.length>e.length?(r=this,o=e):(r=e,o=this);for(var n=0,s=0;s<o.length;s++)t=(0|r.words[s])+(0|o.words[s])+n,this.words[s]=67108863&t,n=t>>>26;for(;0!==n&&s<r.length;s++)t=(0|r.words[s])+n,this.words[s]=67108863&t,n=t>>>26;if(this.length=r.length,0!==n)this.words[this.length]=n,this.length++;else if(r!==this)for(;s<r.length;s++)this.words[s]=r.words[s];return this},n.prototype.add=function(e){var t;return 0!==e.negative&&0===this.negative?(e.negative=0,t=this.sub(e),e.negative^=1,t):0===e.negative&&0!==this.negative?(this.negative=0,t=e.sub(this),this.negative=1,t):this.length>e.length?this.clone().iadd(e):e.clone().iadd(this)},n.prototype.isub=function(e){if(0!==e.negative){e.negative=0;var t=this.iadd(e);return e.negative=1,t._normSign()}if(0!==this.negative)return this.negative=0,this.iadd(e),this.negative=1,this._normSign();var r,o,n=this.cmp(e);if(0===n)return this.negative=0,this.length=1,this.words[0]=0,this;n>0?(r=this,o=e):(r=e,o=this);for(var s=0,i=0;i<o.length;i++)s=(t=(0|r.words[i])-(0|o.words[i])+s)>>26,this.words[i]=67108863&t;for(;0!==s&&i<r.length;i++)s=(t=(0|r.words[i])+s)>>26,this.words[i]=67108863&t;if(0===s&&i<r.length&&r!==this)for(;i<r.length;i++)this.words[i]=r.words[i];return this.length=Math.max(this.length,i),r!==this&&(this.negative=1),this._strip()},n.prototype.sub=function(e){return this.clone().isub(e)};var f=function(e,t,r){var o,n,s,i=e.words,a=t.words,u=r.words,c=0,l=0|i[0],d=8191&l,p=l>>>13,h=0|i[1],m=8191&h,f=h>>>13,y=0|i[2],g=8191&y,w=y>>>13,v=0|i[3],x=8191&v,b=v>>>13,I=0|i[4],A=8191&I,E=I>>>13,T=0|i[5],M=8191&T,S=T>>>13,C=0|i[6],k=8191&C,_=C>>>13,P=0|i[7],O=8191&P,L=P>>>13,N=0|i[8],B=8191&N,R=N>>>13,D=0|i[9],U=8191&D,V=D>>>13,F=0|a[0],q=8191&F,K=F>>>13,W=0|a[1],H=8191&W,$=W>>>13,z=0|a[2],j=8191&z,G=z>>>13,Z=0|a[3],J=8191&Z,Q=Z>>>13,X=0|a[4],Y=8191&X,ee=X>>>13,te=0|a[5],re=8191&te,oe=te>>>13,ne=0|a[6],se=8191&ne,ie=ne>>>13,ae=0|a[7],ue=8191&ae,ce=ae>>>13,le=0|a[8],de=8191&le,pe=le>>>13,he=0|a[9],me=8191&he,fe=he>>>13;r.negative=e.negative^t.negative,r.length=19;var ye=(c+(o=Math.imul(d,q))|0)+((8191&(n=(n=Math.imul(d,K))+Math.imul(p,q)|0))<<13)|0;c=((s=Math.imul(p,K))+(n>>>13)|0)+(ye>>>26)|0,ye&=67108863,o=Math.imul(m,q),n=(n=Math.imul(m,K))+Math.imul(f,q)|0,s=Math.imul(f,K);var ge=(c+(o=o+Math.imul(d,H)|0)|0)+((8191&(n=(n=n+Math.imul(d,$)|0)+Math.imul(p,H)|0))<<13)|0;c=((s=s+Math.imul(p,$)|0)+(n>>>13)|0)+(ge>>>26)|0,ge&=67108863,o=Math.imul(g,q),n=(n=Math.imul(g,K))+Math.imul(w,q)|0,s=Math.imul(w,K),o=o+Math.imul(m,H)|0,n=(n=n+Math.imul(m,$)|0)+Math.imul(f,H)|0,s=s+Math.imul(f,$)|0;var we=(c+(o=o+Math.imul(d,j)|0)|0)+((8191&(n=(n=n+Math.imul(d,G)|0)+Math.imul(p,j)|0))<<13)|0;c=((s=s+Math.imul(p,G)|0)+(n>>>13)|0)+(we>>>26)|0,we&=67108863,o=Math.imul(x,q),n=(n=Math.imul(x,K))+Math.imul(b,q)|0,s=Math.imul(b,K),o=o+Math.imul(g,H)|0,n=(n=n+Math.imul(g,$)|0)+Math.imul(w,H)|0,s=s+Math.imul(w,$)|0,o=o+Math.imul(m,j)|0,n=(n=n+Math.imul(m,G)|0)+Math.imul(f,j)|0,s=s+Math.imul(f,G)|0;var ve=(c+(o=o+Math.imul(d,J)|0)|0)+((8191&(n=(n=n+Math.imul(d,Q)|0)+Math.imul(p,J)|0))<<13)|0;c=((s=s+Math.imul(p,Q)|0)+(n>>>13)|0)+(ve>>>26)|0,ve&=67108863,o=Math.imul(A,q),n=(n=Math.imul(A,K))+Math.imul(E,q)|0,s=Math.imul(E,K),o=o+Math.imul(x,H)|0,n=(n=n+Math.imul(x,$)|0)+Math.imul(b,H)|0,s=s+Math.imul(b,$)|0,o=o+Math.imul(g,j)|0,n=(n=n+Math.imul(g,G)|0)+Math.imul(w,j)|0,s=s+Math.imul(w,G)|0,o=o+Math.imul(m,J)|0,n=(n=n+Math.imul(m,Q)|0)+Math.imul(f,J)|0,s=s+Math.imul(f,Q)|0;var xe=(c+(o=o+Math.imul(d,Y)|0)|0)+((8191&(n=(n=n+Math.imul(d,ee)|0)+Math.imul(p,Y)|0))<<13)|0;c=((s=s+Math.imul(p,ee)|0)+(n>>>13)|0)+(xe>>>26)|0,xe&=67108863,o=Math.imul(M,q),n=(n=Math.imul(M,K))+Math.imul(S,q)|0,s=Math.imul(S,K),o=o+Math.imul(A,H)|0,n=(n=n+Math.imul(A,$)|0)+Math.imul(E,H)|0,s=s+Math.imul(E,$)|0,o=o+Math.imul(x,j)|0,n=(n=n+Math.imul(x,G)|0)+Math.imul(b,j)|0,s=s+Math.imul(b,G)|0,o=o+Math.imul(g,J)|0,n=(n=n+Math.imul(g,Q)|0)+Math.imul(w,J)|0,s=s+Math.imul(w,Q)|0,o=o+Math.imul(m,Y)|0,n=(n=n+Math.imul(m,ee)|0)+Math.imul(f,Y)|0,s=s+Math.imul(f,ee)|0;var be=(c+(o=o+Math.imul(d,re)|0)|0)+((8191&(n=(n=n+Math.imul(d,oe)|0)+Math.imul(p,re)|0))<<13)|0;c=((s=s+Math.imul(p,oe)|0)+(n>>>13)|0)+(be>>>26)|0,be&=67108863,o=Math.imul(k,q),n=(n=Math.imul(k,K))+Math.imul(_,q)|0,s=Math.imul(_,K),o=o+Math.imul(M,H)|0,n=(n=n+Math.imul(M,$)|0)+Math.imul(S,H)|0,s=s+Math.imul(S,$)|0,o=o+Math.imul(A,j)|0,n=(n=n+Math.imul(A,G)|0)+Math.imul(E,j)|0,s=s+Math.imul(E,G)|0,o=o+Math.imul(x,J)|0,n=(n=n+Math.imul(x,Q)|0)+Math.imul(b,J)|0,s=s+Math.imul(b,Q)|0,o=o+Math.imul(g,Y)|0,n=(n=n+Math.imul(g,ee)|0)+Math.imul(w,Y)|0,s=s+Math.imul(w,ee)|0,o=o+Math.imul(m,re)|0,n=(n=n+Math.imul(m,oe)|0)+Math.imul(f,re)|0,s=s+Math.imul(f,oe)|0;var Ie=(c+(o=o+Math.imul(d,se)|0)|0)+((8191&(n=(n=n+Math.imul(d,ie)|0)+Math.imul(p,se)|0))<<13)|0;c=((s=s+Math.imul(p,ie)|0)+(n>>>13)|0)+(Ie>>>26)|0,Ie&=67108863,o=Math.imul(O,q),n=(n=Math.imul(O,K))+Math.imul(L,q)|0,s=Math.imul(L,K),o=o+Math.imul(k,H)|0,n=(n=n+Math.imul(k,$)|0)+Math.imul(_,H)|0,s=s+Math.imul(_,$)|0,o=o+Math.imul(M,j)|0,n=(n=n+Math.imul(M,G)|0)+Math.imul(S,j)|0,s=s+Math.imul(S,G)|0,o=o+Math.imul(A,J)|0,n=(n=n+Math.imul(A,Q)|0)+Math.imul(E,J)|0,s=s+Math.imul(E,Q)|0,o=o+Math.imul(x,Y)|0,n=(n=n+Math.imul(x,ee)|0)+Math.imul(b,Y)|0,s=s+Math.imul(b,ee)|0,o=o+Math.imul(g,re)|0,n=(n=n+Math.imul(g,oe)|0)+Math.imul(w,re)|0,s=s+Math.imul(w,oe)|0,o=o+Math.imul(m,se)|0,n=(n=n+Math.imul(m,ie)|0)+Math.imul(f,se)|0,s=s+Math.imul(f,ie)|0;var Ae=(c+(o=o+Math.imul(d,ue)|0)|0)+((8191&(n=(n=n+Math.imul(d,ce)|0)+Math.imul(p,ue)|0))<<13)|0;c=((s=s+Math.imul(p,ce)|0)+(n>>>13)|0)+(Ae>>>26)|0,Ae&=67108863,o=Math.imul(B,q),n=(n=Math.imul(B,K))+Math.imul(R,q)|0,s=Math.imul(R,K),o=o+Math.imul(O,H)|0,n=(n=n+Math.imul(O,$)|0)+Math.imul(L,H)|0,s=s+Math.imul(L,$)|0,o=o+Math.imul(k,j)|0,n=(n=n+Math.imul(k,G)|0)+Math.imul(_,j)|0,s=s+Math.imul(_,G)|0,o=o+Math.imul(M,J)|0,n=(n=n+Math.imul(M,Q)|0)+Math.imul(S,J)|0,s=s+Math.imul(S,Q)|0,o=o+Math.imul(A,Y)|0,n=(n=n+Math.imul(A,ee)|0)+Math.imul(E,Y)|0,s=s+Math.imul(E,ee)|0,o=o+Math.imul(x,re)|0,n=(n=n+Math.imul(x,oe)|0)+Math.imul(b,re)|0,s=s+Math.imul(b,oe)|0,o=o+Math.imul(g,se)|0,n=(n=n+Math.imul(g,ie)|0)+Math.imul(w,se)|0,s=s+Math.imul(w,ie)|0,o=o+Math.imul(m,ue)|0,n=(n=n+Math.imul(m,ce)|0)+Math.imul(f,ue)|0,s=s+Math.imul(f,ce)|0;var Ee=(c+(o=o+Math.imul(d,de)|0)|0)+((8191&(n=(n=n+Math.imul(d,pe)|0)+Math.imul(p,de)|0))<<13)|0;c=((s=s+Math.imul(p,pe)|0)+(n>>>13)|0)+(Ee>>>26)|0,Ee&=67108863,o=Math.imul(U,q),n=(n=Math.imul(U,K))+Math.imul(V,q)|0,s=Math.imul(V,K),o=o+Math.imul(B,H)|0,n=(n=n+Math.imul(B,$)|0)+Math.imul(R,H)|0,s=s+Math.imul(R,$)|0,o=o+Math.imul(O,j)|0,n=(n=n+Math.imul(O,G)|0)+Math.imul(L,j)|0,s=s+Math.imul(L,G)|0,o=o+Math.imul(k,J)|0,n=(n=n+Math.imul(k,Q)|0)+Math.imul(_,J)|0,s=s+Math.imul(_,Q)|0,o=o+Math.imul(M,Y)|0,n=(n=n+Math.imul(M,ee)|0)+Math.imul(S,Y)|0,s=s+Math.imul(S,ee)|0,o=o+Math.imul(A,re)|0,n=(n=n+Math.imul(A,oe)|0)+Math.imul(E,re)|0,s=s+Math.imul(E,oe)|0,o=o+Math.imul(x,se)|0,n=(n=n+Math.imul(x,ie)|0)+Math.imul(b,se)|0,s=s+Math.imul(b,ie)|0,o=o+Math.imul(g,ue)|0,n=(n=n+Math.imul(g,ce)|0)+Math.imul(w,ue)|0,s=s+Math.imul(w,ce)|0,o=o+Math.imul(m,de)|0,n=(n=n+Math.imul(m,pe)|0)+Math.imul(f,de)|0,s=s+Math.imul(f,pe)|0;var Te=(c+(o=o+Math.imul(d,me)|0)|0)+((8191&(n=(n=n+Math.imul(d,fe)|0)+Math.imul(p,me)|0))<<13)|0;c=((s=s+Math.imul(p,fe)|0)+(n>>>13)|0)+(Te>>>26)|0,Te&=67108863,o=Math.imul(U,H),n=(n=Math.imul(U,$))+Math.imul(V,H)|0,s=Math.imul(V,$),o=o+Math.imul(B,j)|0,n=(n=n+Math.imul(B,G)|0)+Math.imul(R,j)|0,s=s+Math.imul(R,G)|0,o=o+Math.imul(O,J)|0,n=(n=n+Math.imul(O,Q)|0)+Math.imul(L,J)|0,s=s+Math.imul(L,Q)|0,o=o+Math.imul(k,Y)|0,n=(n=n+Math.imul(k,ee)|0)+Math.imul(_,Y)|0,s=s+Math.imul(_,ee)|0,o=o+Math.imul(M,re)|0,n=(n=n+Math.imul(M,oe)|0)+Math.imul(S,re)|0,s=s+Math.imul(S,oe)|0,o=o+Math.imul(A,se)|0,n=(n=n+Math.imul(A,ie)|0)+Math.imul(E,se)|0,s=s+Math.imul(E,ie)|0,o=o+Math.imul(x,ue)|0,n=(n=n+Math.imul(x,ce)|0)+Math.imul(b,ue)|0,s=s+Math.imul(b,ce)|0,o=o+Math.imul(g,de)|0,n=(n=n+Math.imul(g,pe)|0)+Math.imul(w,de)|0,s=s+Math.imul(w,pe)|0;var Me=(c+(o=o+Math.imul(m,me)|0)|0)+((8191&(n=(n=n+Math.imul(m,fe)|0)+Math.imul(f,me)|0))<<13)|0;c=((s=s+Math.imul(f,fe)|0)+(n>>>13)|0)+(Me>>>26)|0,Me&=67108863,o=Math.imul(U,j),n=(n=Math.imul(U,G))+Math.imul(V,j)|0,s=Math.imul(V,G),o=o+Math.imul(B,J)|0,n=(n=n+Math.imul(B,Q)|0)+Math.imul(R,J)|0,s=s+Math.imul(R,Q)|0,o=o+Math.imul(O,Y)|0,n=(n=n+Math.imul(O,ee)|0)+Math.imul(L,Y)|0,s=s+Math.imul(L,ee)|0,o=o+Math.imul(k,re)|0,n=(n=n+Math.imul(k,oe)|0)+Math.imul(_,re)|0,s=s+Math.imul(_,oe)|0,o=o+Math.imul(M,se)|0,n=(n=n+Math.imul(M,ie)|0)+Math.imul(S,se)|0,s=s+Math.imul(S,ie)|0,o=o+Math.imul(A,ue)|0,n=(n=n+Math.imul(A,ce)|0)+Math.imul(E,ue)|0,s=s+Math.imul(E,ce)|0,o=o+Math.imul(x,de)|0,n=(n=n+Math.imul(x,pe)|0)+Math.imul(b,de)|0,s=s+Math.imul(b,pe)|0;var Se=(c+(o=o+Math.imul(g,me)|0)|0)+((8191&(n=(n=n+Math.imul(g,fe)|0)+Math.imul(w,me)|0))<<13)|0;c=((s=s+Math.imul(w,fe)|0)+(n>>>13)|0)+(Se>>>26)|0,Se&=67108863,o=Math.imul(U,J),n=(n=Math.imul(U,Q))+Math.imul(V,J)|0,s=Math.imul(V,Q),o=o+Math.imul(B,Y)|0,n=(n=n+Math.imul(B,ee)|0)+Math.imul(R,Y)|0,s=s+Math.imul(R,ee)|0,o=o+Math.imul(O,re)|0,n=(n=n+Math.imul(O,oe)|0)+Math.imul(L,re)|0,s=s+Math.imul(L,oe)|0,o=o+Math.imul(k,se)|0,n=(n=n+Math.imul(k,ie)|0)+Math.imul(_,se)|0,s=s+Math.imul(_,ie)|0,o=o+Math.imul(M,ue)|0,n=(n=n+Math.imul(M,ce)|0)+Math.imul(S,ue)|0,s=s+Math.imul(S,ce)|0,o=o+Math.imul(A,de)|0,n=(n=n+Math.imul(A,pe)|0)+Math.imul(E,de)|0,s=s+Math.imul(E,pe)|0;var Ce=(c+(o=o+Math.imul(x,me)|0)|0)+((8191&(n=(n=n+Math.imul(x,fe)|0)+Math.imul(b,me)|0))<<13)|0;c=((s=s+Math.imul(b,fe)|0)+(n>>>13)|0)+(Ce>>>26)|0,Ce&=67108863,o=Math.imul(U,Y),n=(n=Math.imul(U,ee))+Math.imul(V,Y)|0,s=Math.imul(V,ee),o=o+Math.imul(B,re)|0,n=(n=n+Math.imul(B,oe)|0)+Math.imul(R,re)|0,s=s+Math.imul(R,oe)|0,o=o+Math.imul(O,se)|0,n=(n=n+Math.imul(O,ie)|0)+Math.imul(L,se)|0,s=s+Math.imul(L,ie)|0,o=o+Math.imul(k,ue)|0,n=(n=n+Math.imul(k,ce)|0)+Math.imul(_,ue)|0,s=s+Math.imul(_,ce)|0,o=o+Math.imul(M,de)|0,n=(n=n+Math.imul(M,pe)|0)+Math.imul(S,de)|0,s=s+Math.imul(S,pe)|0;var ke=(c+(o=o+Math.imul(A,me)|0)|0)+((8191&(n=(n=n+Math.imul(A,fe)|0)+Math.imul(E,me)|0))<<13)|0;c=((s=s+Math.imul(E,fe)|0)+(n>>>13)|0)+(ke>>>26)|0,ke&=67108863,o=Math.imul(U,re),n=(n=Math.imul(U,oe))+Math.imul(V,re)|0,s=Math.imul(V,oe),o=o+Math.imul(B,se)|0,n=(n=n+Math.imul(B,ie)|0)+Math.imul(R,se)|0,s=s+Math.imul(R,ie)|0,o=o+Math.imul(O,ue)|0,n=(n=n+Math.imul(O,ce)|0)+Math.imul(L,ue)|0,s=s+Math.imul(L,ce)|0,o=o+Math.imul(k,de)|0,n=(n=n+Math.imul(k,pe)|0)+Math.imul(_,de)|0,s=s+Math.imul(_,pe)|0;var _e=(c+(o=o+Math.imul(M,me)|0)|0)+((8191&(n=(n=n+Math.imul(M,fe)|0)+Math.imul(S,me)|0))<<13)|0;c=((s=s+Math.imul(S,fe)|0)+(n>>>13)|0)+(_e>>>26)|0,_e&=67108863,o=Math.imul(U,se),n=(n=Math.imul(U,ie))+Math.imul(V,se)|0,s=Math.imul(V,ie),o=o+Math.imul(B,ue)|0,n=(n=n+Math.imul(B,ce)|0)+Math.imul(R,ue)|0,s=s+Math.imul(R,ce)|0,o=o+Math.imul(O,de)|0,n=(n=n+Math.imul(O,pe)|0)+Math.imul(L,de)|0,s=s+Math.imul(L,pe)|0;var Pe=(c+(o=o+Math.imul(k,me)|0)|0)+((8191&(n=(n=n+Math.imul(k,fe)|0)+Math.imul(_,me)|0))<<13)|0;c=((s=s+Math.imul(_,fe)|0)+(n>>>13)|0)+(Pe>>>26)|0,Pe&=67108863,o=Math.imul(U,ue),n=(n=Math.imul(U,ce))+Math.imul(V,ue)|0,s=Math.imul(V,ce),o=o+Math.imul(B,de)|0,n=(n=n+Math.imul(B,pe)|0)+Math.imul(R,de)|0,s=s+Math.imul(R,pe)|0;var Oe=(c+(o=o+Math.imul(O,me)|0)|0)+((8191&(n=(n=n+Math.imul(O,fe)|0)+Math.imul(L,me)|0))<<13)|0;c=((s=s+Math.imul(L,fe)|0)+(n>>>13)|0)+(Oe>>>26)|0,Oe&=67108863,o=Math.imul(U,de),n=(n=Math.imul(U,pe))+Math.imul(V,de)|0,s=Math.imul(V,pe);var Le=(c+(o=o+Math.imul(B,me)|0)|0)+((8191&(n=(n=n+Math.imul(B,fe)|0)+Math.imul(R,me)|0))<<13)|0;c=((s=s+Math.imul(R,fe)|0)+(n>>>13)|0)+(Le>>>26)|0,Le&=67108863;var Ne=(c+(o=Math.imul(U,me))|0)+((8191&(n=(n=Math.imul(U,fe))+Math.imul(V,me)|0))<<13)|0;return c=((s=Math.imul(V,fe))+(n>>>13)|0)+(Ne>>>26)|0,Ne&=67108863,u[0]=ye,u[1]=ge,u[2]=we,u[3]=ve,u[4]=xe,u[5]=be,u[6]=Ie,u[7]=Ae,u[8]=Ee,u[9]=Te,u[10]=Me,u[11]=Se,u[12]=Ce,u[13]=ke,u[14]=_e,u[15]=Pe,u[16]=Oe,u[17]=Le,u[18]=Ne,0!==c&&(u[19]=c,r.length++),r};function y(e,t,r){r.negative=t.negative^e.negative,r.length=e.length+t.length;for(var o=0,n=0,s=0;s<r.length-1;s++){var i=n;n=0;for(var a=67108863&o,u=Math.min(s,t.length-1),c=Math.max(0,s-e.length+1);c<=u;c++){var l=s-c,d=(0|e.words[l])*(0|t.words[c]),p=67108863&d;a=67108863&(p=p+a|0),n+=(i=(i=i+(d/67108864|0)|0)+(p>>>26)|0)>>>26,i&=67108863}r.words[s]=a,o=i,i=n}return 0!==o?r.words[s]=o:r.length--,r._strip()}function g(e,t,r){return y(e,t,r)}Math.imul||(f=m),n.prototype.mulTo=function(e,t){var r=this.length+e.length;return 10===this.length&&10===e.length?f(this,e,t):r<63?m(this,e,t):r<1024?y(this,e,t):g(this,e,t)},n.prototype.mul=function(e){var t=new n(null);return t.words=new Array(this.length+e.length),this.mulTo(e,t)},n.prototype.mulf=function(e){var t=new n(null);return t.words=new Array(this.length+e.length),g(this,e,t)},n.prototype.imul=function(e){return this.clone().mulTo(e,this)},n.prototype.imuln=function(e){var t=e<0;t&&(e=-e),r("number"==typeof e),r(e<67108864);for(var o=0,n=0;n<this.length;n++){var s=(0|this.words[n])*e,i=(67108863&s)+(67108863&o);o>>=26,o+=s/67108864|0,o+=i>>>26,this.words[n]=67108863&i}return 0!==o&&(this.words[n]=o,this.length++),t?this.ineg():this},n.prototype.muln=function(e){return this.clone().imuln(e)},n.prototype.sqr=function(){return this.mul(this)},n.prototype.isqr=function(){return this.imul(this.clone())},n.prototype.pow=function(e){var t=function(e){for(var t=new Array(e.bitLength()),r=0;r<t.length;r++){var o=r/26|0,n=r%26;t[r]=e.words[o]>>>n&1}return t}(e);if(0===t.length)return new n(1);for(var r=this,o=0;o<t.length&&0===t[o];o++,r=r.sqr());if(++o<t.length)for(var s=r.sqr();o<t.length;o++,s=s.sqr())0!==t[o]&&(r=r.mul(s));return r},n.prototype.iushln=function(e){r("number"==typeof e&&e>=0);var t,o=e%26,n=(e-o)/26,s=67108863>>>26-o<<26-o;if(0!==o){var i=0;for(t=0;t<this.length;t++){var a=this.words[t]&s,u=(0|this.words[t])-a<<o;this.words[t]=u|i,i=a>>>26-o}i&&(this.words[t]=i,this.length++)}if(0!==n){for(t=this.length-1;t>=0;t--)this.words[t+n]=this.words[t];for(t=0;t<n;t++)this.words[t]=0;this.length+=n}return this._strip()},n.prototype.ishln=function(e){return r(0===this.negative),this.iushln(e)},n.prototype.iushrn=function(e,t,o){var n;r("number"==typeof e&&e>=0),n=t?(t-t%26)/26:0;var s=e%26,i=Math.min((e-s)/26,this.length),a=67108863^67108863>>>s<<s,u=o;if(n-=i,n=Math.max(0,n),u){for(var c=0;c<i;c++)u.words[c]=this.words[c];u.length=i}if(0===i);else if(this.length>i)for(this.length-=i,c=0;c<this.length;c++)this.words[c]=this.words[c+i];else this.words[0]=0,this.length=1;var l=0;for(c=this.length-1;c>=0&&(0!==l||c>=n);c--){var d=0|this.words[c];this.words[c]=l<<26-s|d>>>s,l=d&a}return u&&0!==l&&(u.words[u.length++]=l),0===this.length&&(this.words[0]=0,this.length=1),this._strip()},n.prototype.ishrn=function(e,t,o){return r(0===this.negative),this.iushrn(e,t,o)},n.prototype.shln=function(e){return this.clone().ishln(e)},n.prototype.ushln=function(e){return this.clone().iushln(e)},n.prototype.shrn=function(e){return this.clone().ishrn(e)},n.prototype.ushrn=function(e){return this.clone().iushrn(e)},n.prototype.testn=function(e){r("number"==typeof e&&e>=0);var t=e%26,o=(e-t)/26,n=1<<t;return this.length<=o?0:!!(this.words[o]&n)},n.prototype.imaskn=function(e){r("number"==typeof e&&e>=0);var t=e%26,o=(e-t)/26;if(r(0===this.negative,"imaskn works only with positive numbers"),this.length<=o)return this;if(0!==t&&o++,this.length=Math.min(o,this.length),0!==t){var n=67108863^67108863>>>t<<t;this.words[this.length-1]&=n}return this._strip()},n.prototype.maskn=function(e){return this.clone().imaskn(e)},n.prototype.iaddn=function(e){return r("number"==typeof e),r(e<67108864),e<0?this.isubn(-e):0!==this.negative?1===this.length&&(0|this.words[0])<=e?(this.words[0]=e-(0|this.words[0]),this.negative=0,this):(this.negative=0,this.isubn(e),this.negative=1,this):this._iaddn(e)},n.prototype._iaddn=function(e){this.words[0]+=e;for(var t=0;t<this.length&&this.words[t]>=67108864;t++)this.words[t]-=67108864,t===this.length-1?this.words[t+1]=1:this.words[t+1]++;return this.length=Math.max(this.length,t+1),this},n.prototype.isubn=function(e){if(r("number"==typeof e),r(e<67108864),e<0)return this.iaddn(-e);if(0!==this.negative)return this.negative=0,this.iaddn(e),this.negative=1,this;if(this.words[0]-=e,1===this.length&&this.words[0]<0)this.words[0]=-this.words[0],this.negative=1;else for(var t=0;t<this.length&&this.words[t]<0;t++)this.words[t]+=67108864,this.words[t+1]-=1;return this._strip()},n.prototype.addn=function(e){return this.clone().iaddn(e)},n.prototype.subn=function(e){return this.clone().isubn(e)},n.prototype.iabs=function(){return this.negative=0,this},n.prototype.abs=function(){return this.clone().iabs()},n.prototype._ishlnsubmul=function(e,t,o){var n,s,i=e.length+o;this._expand(i);var a=0;for(n=0;n<e.length;n++){s=(0|this.words[n+o])+a;var u=(0|e.words[n])*t;a=((s-=67108863&u)>>26)-(u/67108864|0),this.words[n+o]=67108863&s}for(;n<this.length-o;n++)a=(s=(0|this.words[n+o])+a)>>26,this.words[n+o]=67108863&s;if(0===a)return this._strip();for(r(-1===a),a=0,n=0;n<this.length;n++)a=(s=-(0|this.words[n])+a)>>26,this.words[n]=67108863&s;return this.negative=1,this._strip()},n.prototype._wordDiv=function(e,t){var r=(this.length,e.length),o=this.clone(),s=e,i=0|s.words[s.length-1];0!=(r=26-this._countBits(i))&&(s=s.ushln(r),o.iushln(r),i=0|s.words[s.length-1]);var a,u=o.length-s.length;if("mod"!==t){(a=new n(null)).length=u+1,a.words=new Array(a.length);for(var c=0;c<a.length;c++)a.words[c]=0}var l=o.clone()._ishlnsubmul(s,1,u);0===l.negative&&(o=l,a&&(a.words[u]=1));for(var d=u-1;d>=0;d--){var p=67108864*(0|o.words[s.length+d])+(0|o.words[s.length+d-1]);for(p=Math.min(p/i|0,67108863),o._ishlnsubmul(s,p,d);0!==o.negative;)p--,o.negative=0,o._ishlnsubmul(s,1,d),o.isZero()||(o.negative^=1);a&&(a.words[d]=p)}return a&&a._strip(),o._strip(),"div"!==t&&0!==r&&o.iushrn(r),{div:a||null,mod:o}},n.prototype.divmod=function(e,t,o){return r(!e.isZero()),this.isZero()?{div:new n(0),mod:new n(0)}:0!==this.negative&&0===e.negative?(a=this.neg().divmod(e,t),"mod"!==t&&(s=a.div.neg()),"div"!==t&&(i=a.mod.neg(),o&&0!==i.negative&&i.iadd(e)),{div:s,mod:i}):0===this.negative&&0!==e.negative?(a=this.divmod(e.neg(),t),"mod"!==t&&(s=a.div.neg()),{div:s,mod:a.mod}):0!=(this.negative&e.negative)?(a=this.neg().divmod(e.neg(),t),"div"!==t&&(i=a.mod.neg(),o&&0!==i.negative&&i.isub(e)),{div:a.div,mod:i}):e.length>this.length||this.cmp(e)<0?{div:new n(0),mod:this}:1===e.length?"div"===t?{div:this.divn(e.words[0]),mod:null}:"mod"===t?{div:null,mod:new n(this.modrn(e.words[0]))}:{div:this.divn(e.words[0]),mod:new n(this.modrn(e.words[0]))}:this._wordDiv(e,t);var s,i,a},n.prototype.div=function(e){return this.divmod(e,"div",0).div},n.prototype.mod=function(e){return this.divmod(e,"mod",0).mod},n.prototype.umod=function(e){return this.divmod(e,"mod",1).mod},n.prototype.divRound=function(e){var t=this.divmod(e);if(t.mod.isZero())return t.div;var r=0!==t.div.negative?t.mod.isub(e):t.mod,o=e.ushrn(1),n=e.andln(1),s=r.cmp(o);return s<0||1===n&&0===s?t.div:0!==t.div.negative?t.div.isubn(1):t.div.iaddn(1)},n.prototype.modrn=function(e){var t=e<0;t&&(e=-e),r(e<=67108863);for(var o=(1<<26)%e,n=0,s=this.length-1;s>=0;s--)n=(o*n+(0|this.words[s]))%e;return t?-n:n},n.prototype.modn=function(e){return this.modrn(e)},n.prototype.idivn=function(e){var t=e<0;t&&(e=-e),r(e<=67108863);for(var o=0,n=this.length-1;n>=0;n--){var s=(0|this.words[n])+67108864*o;this.words[n]=s/e|0,o=s%e}return this._strip(),t?this.ineg():this},n.prototype.divn=function(e){return this.clone().idivn(e)},n.prototype.egcd=function(e){r(0===e.negative),r(!e.isZero());var t=this,o=e.clone();t=0!==t.negative?t.umod(e):t.clone();for(var s=new n(1),i=new n(0),a=new n(0),u=new n(1),c=0;t.isEven()&&o.isEven();)t.iushrn(1),o.iushrn(1),++c;for(var l=o.clone(),d=t.clone();!t.isZero();){for(var p=0,h=1;0==(t.words[0]&h)&&p<26;++p,h<<=1);if(p>0)for(t.iushrn(p);p-- >0;)(s.isOdd()||i.isOdd())&&(s.iadd(l),i.isub(d)),s.iushrn(1),i.iushrn(1);for(var m=0,f=1;0==(o.words[0]&f)&&m<26;++m,f<<=1);if(m>0)for(o.iushrn(m);m-- >0;)(a.isOdd()||u.isOdd())&&(a.iadd(l),u.isub(d)),a.iushrn(1),u.iushrn(1);t.cmp(o)>=0?(t.isub(o),s.isub(a),i.isub(u)):(o.isub(t),a.isub(s),u.isub(i))}return{a:a,b:u,gcd:o.iushln(c)}},n.prototype._invmp=function(e){r(0===e.negative),r(!e.isZero());var t=this,o=e.clone();t=0!==t.negative?t.umod(e):t.clone();for(var s,i=new n(1),a=new n(0),u=o.clone();t.cmpn(1)>0&&o.cmpn(1)>0;){for(var c=0,l=1;0==(t.words[0]&l)&&c<26;++c,l<<=1);if(c>0)for(t.iushrn(c);c-- >0;)i.isOdd()&&i.iadd(u),i.iushrn(1);for(var d=0,p=1;0==(o.words[0]&p)&&d<26;++d,p<<=1);if(d>0)for(o.iushrn(d);d-- >0;)a.isOdd()&&a.iadd(u),a.iushrn(1);t.cmp(o)>=0?(t.isub(o),i.isub(a)):(o.isub(t),a.isub(i))}return(s=0===t.cmpn(1)?i:a).cmpn(0)<0&&s.iadd(e),s},n.prototype.gcd=function(e){if(this.isZero())return e.abs();if(e.isZero())return this.abs();var t=this.clone(),r=e.clone();t.negative=0,r.negative=0;for(var o=0;t.isEven()&&r.isEven();o++)t.iushrn(1),r.iushrn(1);for(;;){for(;t.isEven();)t.iushrn(1);for(;r.isEven();)r.iushrn(1);var n=t.cmp(r);if(n<0){var s=t;t=r,r=s}else if(0===n||0===r.cmpn(1))break;t.isub(r)}return r.iushln(o)},n.prototype.invm=function(e){return this.egcd(e).a.umod(e)},n.prototype.isEven=function(){return 0==(1&this.words[0])},n.prototype.isOdd=function(){return 1==(1&this.words[0])},n.prototype.andln=function(e){return this.words[0]&e},n.prototype.bincn=function(e){r("number"==typeof e);var t=e%26,o=(e-t)/26,n=1<<t;if(this.length<=o)return this._expand(o+1),this.words[o]|=n,this;for(var s=n,i=o;0!==s&&i<this.length;i++){var a=0|this.words[i];s=(a+=s)>>>26,a&=67108863,this.words[i]=a}return 0!==s&&(this.words[i]=s,this.length++),this},n.prototype.isZero=function(){return 1===this.length&&0===this.words[0]},n.prototype.cmpn=function(e){var t,o=e<0;if(0!==this.negative&&!o)return-1;if(0===this.negative&&o)return 1;if(this._strip(),this.length>1)t=1;else{o&&(e=-e),r(e<=67108863,"Number is too big");var n=0|this.words[0];t=n===e?0:n<e?-1:1}return 0!==this.negative?0|-t:t},n.prototype.cmp=function(e){if(0!==this.negative&&0===e.negative)return-1;if(0===this.negative&&0!==e.negative)return 1;var t=this.ucmp(e);return 0!==this.negative?0|-t:t},n.prototype.ucmp=function(e){if(this.length>e.length)return 1;if(this.length<e.length)return-1;for(var t=0,r=this.length-1;r>=0;r--){var o=0|this.words[r],n=0|e.words[r];if(o!==n){o<n?t=-1:o>n&&(t=1);break}}return t},n.prototype.gtn=function(e){return 1===this.cmpn(e)},n.prototype.gt=function(e){return 1===this.cmp(e)},n.prototype.gten=function(e){return this.cmpn(e)>=0},n.prototype.gte=function(e){return this.cmp(e)>=0},n.prototype.ltn=function(e){return-1===this.cmpn(e)},n.prototype.lt=function(e){return-1===this.cmp(e)},n.prototype.lten=function(e){return this.cmpn(e)<=0},n.prototype.lte=function(e){return this.cmp(e)<=0},n.prototype.eqn=function(e){return 0===this.cmpn(e)},n.prototype.eq=function(e){return 0===this.cmp(e)},n.red=function(e){return new E(e)},n.prototype.toRed=function(e){return r(!this.red,"Already a number in reduction context"),r(0===this.negative,"red works only with positives"),e.convertTo(this)._forceRed(e)},n.prototype.fromRed=function(){return r(this.red,"fromRed works only with numbers in reduction context"),this.red.convertFrom(this)},n.prototype._forceRed=function(e){return this.red=e,this},n.prototype.forceRed=function(e){return r(!this.red,"Already a number in reduction context"),this._forceRed(e)},n.prototype.redAdd=function(e){return r(this.red,"redAdd works only with red numbers"),this.red.add(this,e)},n.prototype.redIAdd=function(e){return r(this.red,"redIAdd works only with red numbers"),this.red.iadd(this,e)},n.prototype.redSub=function(e){return r(this.red,"redSub works only with red numbers"),this.red.sub(this,e)},n.prototype.redISub=function(e){return r(this.red,"redISub works only with red numbers"),this.red.isub(this,e)},n.prototype.redShl=function(e){return r(this.red,"redShl works only with red numbers"),this.red.shl(this,e)},n.prototype.redMul=function(e){return r(this.red,"redMul works only with red numbers"),this.red._verify2(this,e),this.red.mul(this,e)},n.prototype.redIMul=function(e){return r(this.red,"redMul works only with red numbers"),this.red._verify2(this,e),this.red.imul(this,e)},n.prototype.redSqr=function(){return r(this.red,"redSqr works only with red numbers"),this.red._verify1(this),this.red.sqr(this)},n.prototype.redISqr=function(){return r(this.red,"redISqr works only with red numbers"),this.red._verify1(this),this.red.isqr(this)},n.prototype.redSqrt=function(){return r(this.red,"redSqrt works only with red numbers"),this.red._verify1(this),this.red.sqrt(this)},n.prototype.redInvm=function(){return r(this.red,"redInvm works only with red numbers"),this.red._verify1(this),this.red.invm(this)},n.prototype.redNeg=function(){return r(this.red,"redNeg works only with red numbers"),this.red._verify1(this),this.red.neg(this)},n.prototype.redPow=function(e){return r(this.red&&!e.red,"redPow(normalNum)"),this.red._verify1(this),this.red.pow(this,e)};var w={k256:null,p224:null,p192:null,p25519:null};function v(e,t){this.name=e,this.p=new n(t,16),this.n=this.p.bitLength(),this.k=new n(1).iushln(this.n).isub(this.p),this.tmp=this._tmp()}function x(){v.call(this,"k256","ffffffff ffffffff ffffffff ffffffff ffffffff ffffffff fffffffe fffffc2f")}function b(){v.call(this,"p224","ffffffff ffffffff ffffffff ffffffff 00000000 00000000 00000001")}function I(){v.call(this,"p192","ffffffff ffffffff ffffffff fffffffe ffffffff ffffffff")}function A(){v.call(this,"25519","7fffffffffffffff ffffffffffffffff ffffffffffffffff ffffffffffffffed")}function E(e){if("string"==typeof e){var t=n._prime(e);this.m=t.p,this.prime=t}else r(e.gtn(1),"modulus must be greater than 1"),this.m=e,this.prime=null}function T(e){E.call(this,e),this.shift=this.m.bitLength(),this.shift%26!=0&&(this.shift+=26-this.shift%26),this.r=new n(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)}v.prototype._tmp=function(){var e=new n(null);return e.words=new Array(Math.ceil(this.n/13)),e},v.prototype.ireduce=function(e){var t,r=e;do{this.split(r,this.tmp),t=(r=(r=this.imulK(r)).iadd(this.tmp)).bitLength()}while(t>this.n);var o=t<this.n?-1:r.ucmp(this.p);return 0===o?(r.words[0]=0,r.length=1):o>0?r.isub(this.p):void 0!==r.strip?r.strip():r._strip(),r},v.prototype.split=function(e,t){e.iushrn(this.n,0,t)},v.prototype.imulK=function(e){return e.imul(this.k)},o(x,v),x.prototype.split=function(e,t){for(var r=4194303,o=Math.min(e.length,9),n=0;n<o;n++)t.words[n]=e.words[n];if(t.length=o,e.length<=9)return e.words[0]=0,void(e.length=1);var s=e.words[9];for(t.words[t.length++]=s&r,n=10;n<e.length;n++){var i=0|e.words[n];e.words[n-10]=(i&r)<<4|s>>>22,s=i}s>>>=22,e.words[n-10]=s,0===s&&e.length>10?e.length-=10:e.length-=9},x.prototype.imulK=function(e){e.words[e.length]=0,e.words[e.length+1]=0,e.length+=2;for(var t=0,r=0;r<e.length;r++){var o=0|e.words[r];t+=977*o,e.words[r]=67108863&t,t=64*o+(t/67108864|0)}return 0===e.words[e.length-1]&&(e.length--,0===e.words[e.length-1]&&e.length--),e},o(b,v),o(I,v),o(A,v),A.prototype.imulK=function(e){for(var t=0,r=0;r<e.length;r++){var o=19*(0|e.words[r])+t,n=67108863&o;o>>>=26,e.words[r]=n,t=o}return 0!==t&&(e.words[e.length++]=t),e},n._prime=function(e){if(w[e])return w[e];var t;if("k256"===e)t=new x;else if("p224"===e)t=new b;else if("p192"===e)t=new I;else{if("p25519"!==e)throw new Error("Unknown prime "+e);t=new A}return w[e]=t,t},E.prototype._verify1=function(e){r(0===e.negative,"red works only with positives"),r(e.red,"red works only with red numbers")},E.prototype._verify2=function(e,t){r(0==(e.negative|t.negative),"red works only with positives"),r(e.red&&e.red===t.red,"red works only with red numbers")},E.prototype.imod=function(e){return this.prime?this.prime.ireduce(e)._forceRed(this):(c(e,e.umod(this.m)._forceRed(this)),e)},E.prototype.neg=function(e){return e.isZero()?e.clone():this.m.sub(e)._forceRed(this)},E.prototype.add=function(e,t){this._verify2(e,t);var r=e.add(t);return r.cmp(this.m)>=0&&r.isub(this.m),r._forceRed(this)},E.prototype.iadd=function(e,t){this._verify2(e,t);var r=e.iadd(t);return r.cmp(this.m)>=0&&r.isub(this.m),r},E.prototype.sub=function(e,t){this._verify2(e,t);var r=e.sub(t);return r.cmpn(0)<0&&r.iadd(this.m),r._forceRed(this)},E.prototype.isub=function(e,t){this._verify2(e,t);var r=e.isub(t);return r.cmpn(0)<0&&r.iadd(this.m),r},E.prototype.shl=function(e,t){return this._verify1(e),this.imod(e.ushln(t))},E.prototype.imul=function(e,t){return this._verify2(e,t),this.imod(e.imul(t))},E.prototype.mul=function(e,t){return this._verify2(e,t),this.imod(e.mul(t))},E.prototype.isqr=function(e){return this.imul(e,e.clone())},E.prototype.sqr=function(e){return this.mul(e,e)},E.prototype.sqrt=function(e){if(e.isZero())return e.clone();var t=this.m.andln(3);if(r(t%2==1),3===t){var o=this.m.add(new n(1)).iushrn(2);return this.pow(e,o)}for(var s=this.m.subn(1),i=0;!s.isZero()&&0===s.andln(1);)i++,s.iushrn(1);r(!s.isZero());var a=new n(1).toRed(this),u=a.redNeg(),c=this.m.subn(1).iushrn(1),l=this.m.bitLength();for(l=new n(2*l*l).toRed(this);0!==this.pow(l,c).cmp(u);)l.redIAdd(u);for(var d=this.pow(l,s),p=this.pow(e,s.addn(1).iushrn(1)),h=this.pow(e,s),m=i;0!==h.cmp(a);){for(var f=h,y=0;0!==f.cmp(a);y++)f=f.redSqr();r(y<m);var g=this.pow(d,new n(1).iushln(m-y-1));p=p.redMul(g),d=g.redSqr(),h=h.redMul(d),m=y}return p},E.prototype.invm=function(e){var t=e._invmp(this.m);return 0!==t.negative?(t.negative=0,this.imod(t).redNeg()):this.imod(t)},E.prototype.pow=function(e,t){if(t.isZero())return new n(1).toRed(this);if(0===t.cmpn(1))return e.clone();var r=new Array(16);r[0]=new n(1).toRed(this),r[1]=e;for(var o=2;o<r.length;o++)r[o]=this.mul(r[o-1],e);var s=r[0],i=0,a=0,u=t.bitLength()%26;for(0===u&&(u=26),o=t.length-1;o>=0;o--){for(var c=t.words[o],l=u-1;l>=0;l--){var d=c>>l&1;s!==r[0]&&(s=this.sqr(s)),0!==d||0!==i?(i<<=1,i|=d,(4==++a||0===o&&0===l)&&(s=this.mul(s,r[i]),a=0,i=0)):a=0}u=26}return s},E.prototype.convertTo=function(e){var t=e.umod(this.m);return t===e?t.clone():t},E.prototype.convertFrom=function(e){var t=e.clone();return t.red=null,t},n.mont=function(e){return new T(e)},o(T,E),T.prototype.convertTo=function(e){return this.imod(e.ushln(this.shift))},T.prototype.convertFrom=function(e){var t=this.imod(e.mul(this.rinv));return t.red=null,t},T.prototype.imul=function(e,t){if(e.isZero()||t.isZero())return e.words[0]=0,e.length=1,e;var r=e.imul(t),o=r.maskn(this.shift).mul(this.minv).imaskn(this.shift).mul(this.m),n=r.isub(o).iushrn(this.shift),s=n;return n.cmp(this.m)>=0?s=n.isub(this.m):n.cmpn(0)<0&&(s=n.iadd(this.m)),s._forceRed(this)},T.prototype.mul=function(e,t){if(e.isZero()||t.isZero())return new n(0)._forceRed(this);var r=e.mul(t),o=r.maskn(this.shift).mul(this.minv).imaskn(this.shift).mul(this.m),s=r.isub(o).iushrn(this.shift),i=s;return s.cmp(this.m)>=0?i=s.isub(this.m):s.cmpn(0)<0&&(i=s.iadd(this.m)),i._forceRed(this)},T.prototype.invm=function(e){return this.imod(e._invmp(this.m).mul(this.r2))._forceRed(this)}}(0,r);var q,K,W=F.exports,H=o(W);!function(t){var o=r&&r.__importDefault||function(e){return e&&e.__esModule?e:{default:e}};Object.defineProperty(t,"__esModule",{value:1}),t.map=t.array=t.rustEnum=t.str=t.vecU8=t.tagged=t.vec=t.bool=t.option=t.publicKey=t.i256=t.u256=t.i128=t.u128=t.i64=t.u64=t.struct=t.f64=t.f32=t.i32=t.u32=t.i16=t.u16=t.i8=t.u8=void 0;const n=s,i=e,a=o(W);var u=s;Object.defineProperty(t,"u8",{enumerable:1,get:function(){return u.u8}}),Object.defineProperty(t,"i8",{enumerable:1,get:function(){return u.s8}}),Object.defineProperty(t,"u16",{enumerable:1,get:function(){return u.u16}}),Object.defineProperty(t,"i16",{enumerable:1,get:function(){return u.s16}}),Object.defineProperty(t,"u32",{enumerable:1,get:function(){return u.u32}}),Object.defineProperty(t,"i32",{enumerable:1,get:function(){return u.s32}}),Object.defineProperty(t,"f32",{enumerable:1,get:function(){return u.f32}}),Object.defineProperty(t,"f64",{enumerable:1,get:function(){return u.f64}}),Object.defineProperty(t,"struct",{enumerable:1,get:function(){return u.struct}});class c extends n.Layout{constructor(e,t,r){super(e,r),this.blob=(0,n.blob)(e),this.signed=t}decode(e,t=0){const r=new a.default(this.blob.decode(e,t),10,"le");return this.signed?r.fromTwos(8*this.span).clone():r}encode(e,t,r=0){return this.signed&&(e=e.toTwos(8*this.span)),this.blob.encode(e.toArrayLike(Buffer,"le",this.span),t,r)}}function l(e){return new c(8,0,e)}t.u64=l,t.i64=function(e){return new c(8,1,e)},t.u128=function(e){return new c(16,0,e)},t.i128=function(e){return new c(16,1,e)},t.u256=function(e){return new c(32,0,e)},t.i256=function(e){return new c(32,1,e)};class d extends n.Layout{constructor(e,t,r,o){super(e.span,o),this.layout=e,this.decoder=t,this.encoder=r}decode(e,t){return this.decoder(this.layout.decode(e,t))}encode(e,t,r){return this.layout.encode(this.encoder(e),t,r)}getSpan(e,t){return this.layout.getSpan(e,t)}}t.publicKey=function(e){return new d((0,n.blob)(32),(e=>new i.PublicKey(e)),(e=>e.toBuffer()),e)};class p extends n.Layout{constructor(e,t){super(-1,t),this.layout=e,this.discriminator=(0,n.u8)()}encode(e,t,r=0){return null==e?this.discriminator.encode(0,t,r):(this.discriminator.encode(1,t,r),this.layout.encode(e,t,r+1)+1)}decode(e,t=0){const r=this.discriminator.decode(e,t);if(0===r)return null;if(1===r)return this.layout.decode(e,t+1);throw new Error("Invalid option "+this.property)}getSpan(e,t=0){const r=this.discriminator.decode(e,t);if(0===r)return 1;if(1===r)return this.layout.getSpan(e,t+1)+1;throw new Error("Invalid option "+this.property)}}function h(e){if(0===e)return 0;if(1===e)return 1;throw new Error("Invalid bool: "+e)}function m(e){return e?1:0}function f(e){const t=(0,n.u32)("length"),r=(0,n.struct)([t,(0,n.blob)((0,n.offset)(t,-t.span),"data")]);return new d(r,(({data:e})=>e),(e=>({data:e})),e)}t.option=function(e,t){return new p(e,t)},t.bool=function(e){return new d((0,n.u8)(),h,m,e)},t.vec=function(e,t){const r=(0,n.u32)("length"),o=(0,n.struct)([r,(0,n.seq)(e,(0,n.offset)(r,-r.span),"values")]);return new d(o,(({values:e})=>e),(e=>({values:e})),t)},t.tagged=function(e,t,r){const o=(0,n.struct)([l("tag"),t.replicate("data")]);return new d(o,(function({tag:t,data:r}){if(!t.eq(e))throw new Error("Invalid tag, expected: "+e.toString("hex")+", got: "+t.toString("hex"));return r}),(t=>({tag:e,data:t})),r)},t.vecU8=f,t.str=function(e){return new d(f(),(e=>e.toString("utf-8")),(e=>Buffer.from(e,"utf-8")),e)},t.rustEnum=function(e,t,r){const o=(0,n.union)(null!=r?r:(0,n.u8)(),t);return e.forEach(((e,t)=>o.addVariant(t,e,e.property))),o},t.array=function(e,t,r){const o=(0,n.struct)([(0,n.seq)(e,t,"values")]);return new d(o,(({values:e})=>e),(e=>({values:e})),r)};class y extends n.Layout{constructor(e,t,r){super(e.span+t.span,r),this.keyLayout=e,this.valueLayout=t}decode(e,t){return t=t||0,[this.keyLayout.decode(e,t),this.valueLayout.decode(e,t+this.keyLayout.getSpan(e,t))]}encode(e,t,r){r=r||0;const o=this.keyLayout.encode(e[0],t,r);return o+this.valueLayout.encode(e[1],t,r+o)}getSpan(e,t){return this.keyLayout.getSpan(e,t)+this.valueLayout.getSpan(e,t)}}t.map=function(e,t,r){const o=(0,n.u32)("length"),s=(0,n.struct)([o,(0,n.seq)(new y(e,t),(0,n.offset)(o,-o.span),"values")]);return new d(s,(({values:e})=>new Map(e)),(e=>({values:Array.from(e.entries())})),r)}}(n),exports.TreeType=void 0,(q=exports.TreeType||(exports.TreeType={}))[q.StateV1=1]="StateV1",q[q.AddressV1=2]="AddressV1",q[q.StateV2=3]="StateV2",q[q.AddressV2=4]="AddressV2",exports.VERSION=void 0,(K=exports.VERSION||(exports.VERSION={})).V1="V1",K.V2="V2";const $={version:'"V1"',isV2:()=>"V2"===$.version.replace(/['"]/g,"").toUpperCase()},z=e=>$.isV2()?`${e}V2`:e,j=new H("21888242871839275222246405745257275088548364400416034343698204186575808495617"),G=new H("452312848583266388373324160190187140051835877600158453279131187530910662655"),Z=[2,64,66,15,0],J=t.Buffer.from([26,16,169,7,21,202,242,25]),Q=t.Buffer.from([49,212,191,129,39,194,43,196]),X=t.Buffer.from([86,47,163,166,21,223,92,8]),Y=t.Buffer.from([228,34,128,84,47,139,86,240]),ee=t.Buffer.from([180,143,159,153,35,46,248,163]),te="noopb9bkMVfRPU8AsbpTUg8AQkHtKwMYZiFUjNRtMmV",re="SySTEM1eSU2p4BGQfQpimFEWWSC1XDFeun3Nqzz3rT7",oe="compr6CUsB5m2jS4Y3831ztGSTnDpnKJTKS95d64XVq",ne=()=>new e.PublicKey("35hkDgaAKwMCaxRz2ocSZ6NaUrtKkyNqU6c4RV3tYJRh"),se=()=>e.PublicKey.findProgramAddressSync([t.Buffer.from("cpi_authority")],new e.PublicKey(re))[0],ie=()=>({registeredProgramPda:new e.PublicKey(ne()),noopProgram:new e.PublicKey(te),accountCompressionProgram:new e.PublicKey(oe),accountCompressionAuthority:new e.PublicKey(se()),cpiSignatureAccount:null}),ae=()=>({mainnet:[{stateTreeLookupTable:new e.PublicKey(he),nullifyLookupTable:new e.PublicKey(me)}],devnet:[{stateTreeLookupTable:new e.PublicKey(fe),nullifyLookupTable:new e.PublicKey(ye)}]}),ue=e=>e.includes("localhost")||e.includes("127.0.0.1"),ce=()=>[{tree:new e.PublicKey(ve),queue:new e.PublicKey(ge),cpiContext:new e.PublicKey(we),treeType:exports.TreeType.StateV1,nextTreeInfo:null},{tree:new e.PublicKey(Ae),queue:new e.PublicKey(Ee),cpiContext:new e.PublicKey(Te),treeType:exports.TreeType.StateV1,nextTreeInfo:null},{tree:new e.PublicKey(Me),queue:new e.PublicKey(Se),cpiContext:new e.PublicKey(Ce),treeType:exports.TreeType.StateV2,nextTreeInfo:null}].filter((e=>$.isV2()?e.treeType===exports.TreeType.StateV2:e.treeType===exports.TreeType.StateV1)),le=()=>$.isV2()?{tree:Ie,queue:Ie,cpiContext:null,treeType:exports.TreeType.AddressV2,nextTreeInfo:null}:{tree:new e.PublicKey(xe),queue:new e.PublicKey(be),cpiContext:null,treeType:exports.TreeType.AddressV1,nextTreeInfo:null},de=()=>({nullifierQueue:new e.PublicKey(ge),merkleTree:new e.PublicKey(ve),merkleTreeHeight:ke,addressTree:new e.PublicKey(xe),addressQueue:new e.PublicKey(be)}),pe=new e.PublicKey("cTokenmWW8bLPjZEBAUgYy3zKxQZW6VKi7bqNFEVv3m"),he="7i86eQs3GSqHjN47WdWLTCGMW6gde1q96G2EVnUyK2st",me="H9QD4u1fG7KmkAzn2tDXhheushxFe1EcrjGGyEFXeMqT",fe="Dk9mNkbiZXJZ4By8DfSP6HEE4ojZzRvucwpawLeuwq8q",ye="AXbHzp1NgjLvpfnD6JRTTovXZ7APUCdtWZFCRr5tCxse",ge="nfq1NvQDJ2GEgnS8zt9prAe8rjjpAW1zFkrvZoBR148",we="cpi1uHzrEhBG733DoEJNgHCyRS3XmmyVNZx5fonubE4",ve="smt1NamzXdq4AMqS2fS2F1i5KTYPZRhoHgWx38d8WsT",xe="amt1Ayt45jfbdw5YSo7iz6WZxUmnZsQTYXy82hVwyC2",be="aq1S9z4reTSQAdgWHGD2zDaS39sjGrAxbR31vxJ2F4F",Ie=new e.PublicKey("EzKE84aVTkCUhDHLELqyJaq1Y7UVVmqxXqZjVHwHY3rK"),Ae="smt2rJAFdyJJupwMKAqTNAJwvjhmiZ4JYGZmbVRw1Ho",Ee="nfq2hgS7NYemXsFaFUCe3EMXSDSfnZnAe27jC6aPP1X",Te="cpi2cdhkH5roePvcudTgUL8ppEBfTay1desGh8G8QxK",Me="HLKs5NJ8FXkJg8BrzJt56adFYYuwg5etzDtBbQYTsixu",Se="6L7SzhYB3anwEQ9cphpJ1U7Scwj57bx2xueReg7R9cKU",Ce="7Hp52chxaew8bW1ApR4fck2bh6Y8qA1pu3qwH6N9zaLj",ke=26,_e=new H(Math.floor(2**ke*.95)),Pe=$.isV2()?new H(1):new H(300),Oe=($.isV2(),new H(392)),Le=new H(5e3),Ne=new H(5e3);var Be=function(e){const t=new Uint8Array(256);for(let e=0;e<t.length;e++)t[e]=255;for(let r=0;r<58;r++){const o=e.charAt(r),n=o.charCodeAt(0);if(255!==t[n])throw new TypeError(o+" is ambiguous");t[n]=r}const r=e.charAt(0),o=Math.log(58)/Math.log(256),n=Math.log(256)/Math.log(58);function s(e){if("string"!=typeof e)throw new TypeError("Expected String");if(0===e.length)return new Uint8Array;let n=0,s=0,i=0;for(;e[n]===r;)s++,n++;const a=(e.length-n)*o+1>>>0,u=new Uint8Array(a);for(;e[n];){let r=t[e.charCodeAt(n)];if(255===r)return;let o=0;for(let e=a-1;(0!==r||o<i)&&-1!==e;e--,o++)r+=58*u[e]>>>0,u[e]=r%256>>>0,r=r/256>>>0;if(0!==r)throw new Error("Non-zero carry");i=o,n++}let c=a-i;for(;c!==a&&0===u[c];)c++;const l=new Uint8Array(s+(a-c));let d=s;for(;c!==a;)l[d++]=u[c++];return l}return{encode:function(t){if(t instanceof Uint8Array||(ArrayBuffer.isView(t)?t=new Uint8Array(t.buffer,t.byteOffset,t.byteLength):Array.isArray(t)&&(t=Uint8Array.from(t))),!(t instanceof Uint8Array))throw new TypeError("Expected Uint8Array");if(0===t.length)return"";let o=0,s=0,i=0;const a=t.length;for(;i!==a&&0===t[i];)i++,o++;const u=(a-i)*n+1>>>0,c=new Uint8Array(u);for(;i!==a;){let e=t[i],r=0;for(let t=u-1;(0!==e||r<s)&&-1!==t;t--,r++)e+=256*c[t]>>>0,c[t]=e%58>>>0,e=e/58>>>0;if(0!==e)throw new Error("Non-zero carry");s=r,i++}let l=u-s;for(;l!==u&&0===c[l];)l++;let d=r.repeat(o);for(;l<u;++l)d+=e.charAt(c[l]);return d},decodeUnsafe:s,decode:function(e){const t=s(e);if(t)return t;throw new Error("Non-base58 character")}}}("123456789ABCDEFGHJKLMNPQRSTUVWXYZabcdefghijkmnopqrstuvwxyz");const Re=(e,t)=>{if("base58"===t){if("string"!=typeof e)throw new Error("Must be a base58 string");return Re(Be.decode(e))}return function(e){if(e.gte(j))throw new Error("Value is too large. Max <254 bits");return e}(new H(e,t))};function De(e){const r=Re(e).toArrayLike(t.Buffer,void 0,32);return Be.encode(new Uint8Array(r))}const Ue=(e,r,o)=>e instanceof Uint8Array&&!(e instanceof t.Buffer)?new H(t.Buffer.from(e),r,o):new H(e,r,o),Ve=(e,t,r,o)=>({owner:e,lamports:null!=t?t:new H(0),address:null!=o?o:null,data:null!=r?r:null}),Fe=(e,t,r,o,n)=>Object.assign(Object.assign({},e),{owner:t,lamports:null!=r?r:new H(0),address:null!=n?n:null,data:null!=o?o:null,readOnly:0}),qe=(e,t,r,o=0)=>({treeInfo:e,hash:t,leafIndex:r,proveByIndex:o}),Ke=n.struct([n.publicKey("owner"),n.u64("lamports"),n.option(n.array(n.u8(),32),"address"),n.option(n.struct([n.array(n.u8(),8,"discriminator"),n.vecU8("data"),n.array(n.u8(),32,"dataHash")]),"data")],"compressedAccount"),We=n.struct([n.u8("merkleTreePubkeyIndex"),n.u8("queuePubkeyIndex"),n.u32("leafIndex"),n.bool("proveByIndex")],"merkleContext"),He=n.struct([n.array(n.u8(),32,"seed"),n.u8("addressQueueAccountIndex"),n.u8("addressMerkleTreeAccountIndex"),n.u16("addressMerkleTreeRootIndex")],"newAddressParams"),$e=n.struct([n.option(n.struct([n.array(n.u8(),32,"a"),n.array(n.u8(),64,"b"),n.array(n.u8(),32,"c")]),"proof"),n.vec(n.struct([Ke,We,n.u16("rootIndex"),n.bool("readOnly")]),"inputCompressedAccountsWithMerkleContext"),n.vec(n.struct([Ke,n.u8("merkleTreeIndex")]),"outputCompressedAccounts"),n.option(n.u64(),"relayFee"),n.vec(He,"newAddressParams"),n.option(n.u64(),"compressOrDecompressLamports"),n.bool("isCompress")]);function ze(e){const r=t.Buffer.alloc(1e3),o=$e.encode(e,r),n=t.Buffer.from(new Uint8Array(r.slice(0,o))),s=t.Buffer.alloc(4);return s.writeUInt32LE(o,0),t.Buffer.concat([new Uint8Array(J),new Uint8Array(s),new Uint8Array(n)])}const je=n.struct([n.option(n.struct([n.array(n.u8(),32,"a"),n.array(n.u8(),64,"b"),n.array(n.u8(),32,"c")]),"proof"),n.vec(He,"newAddressParams"),n.vec(n.struct([Ke,We,n.u16("rootIndex"),n.bool("readOnly")]),"inputCompressedAccountsWithMerkleContext"),n.vec(n.struct([Ke,n.u8("merkleTreeIndex")]),"outputCompressedAccounts"),n.option(n.u64(),"relayFee"),n.option(n.u64(),"compressOrDecompressLamports"),n.bool("isCompress"),n.option(n.struct([n.bool("set_context"),n.bool("first_set_context"),n.u8("cpi_context_account_index")]),"compressedCpiContext")]),Ge=n.struct([n.array(n.u8(),32,"a"),n.array(n.u8(),64,"b"),n.array(n.u8(),32,"c")],"compressedProof"),Ze=n.struct([n.bool("set_context"),n.bool("first_set_context"),n.u8("cpi_context_account_index")],"compressedCpiContext"),Je=n.struct([n.array(n.u8(),32,"seed"),n.u8("address_queue_account_index"),n.u8("address_merkle_tree_account_index"),n.u16("address_merkle_tree_root_index"),n.bool("assigned_to_account"),n.u8("assigned_account_index")],"newAddressParamsAssignedPacked"),Qe=n.struct([n.u8("merkle_tree_pubkey_index"),n.u8("queue_pubkey_index"),n.u32("leaf_index"),n.bool("prove_by_index")],"packedMerkleContext"),Xe=n.struct([n.array(n.u8(),8,"discriminator"),n.array(n.u8(),32,"data_hash"),Qe,n.u16("root_index"),n.u64("lamports"),n.option(n.array(n.u8(),32),"address")],"inAccount"),Ye=n.struct([n.array(n.u8(),32,"address"),n.u16("address_merkle_tree_root_index"),n.u8("address_merkle_tree_account_index")],"packedReadOnlyAddress"),et=n.struct([n.array(n.u8(),32,"account_hash"),Qe,n.u16("root_index")],"packedReadOnlyCompressedAccount"),tt=n.struct([n.u8("mode"),n.u8("bump"),n.publicKey("invoking_program_id"),n.u64("compress_or_decompress_lamports"),n.bool("is_compress"),n.bool("with_cpi_context"),n.bool("with_transaction_hash"),Ze,n.option(Ge,"proof"),n.vec(Je,"new_address_params"),n.vec(Xe,"input_compressed_accounts"),n.vec(n.struct([Ke,n.u8("merkleTreeIndex")]),"output_compressed_accounts"),n.vec(Ye,"read_only_addresses"),n.vec(et,"read_only_accounts")]);function rt(e){return tt.decode(e.slice(X.length))}function ot(e){return $e.decode(e.slice(J.length+4))}function nt(e){return je.decode(e.slice(Q.length+4))}const st=e=>{const t=Zr.programId,{feePayer:r,authority:o,registeredProgramPda:n,noopProgram:s,accountCompressionAuthority:i,accountCompressionProgram:a,solPoolPda:u,decompressionRecipient:c,systemProgram:l}=e;return[{pubkey:r,isSigner:1,isWritable:1},{pubkey:o,isSigner:1,isWritable:0},{pubkey:n,isSigner:0,isWritable:0},{pubkey:s,isSigner:0,isWritable:0},{pubkey:i,isSigner:0,isWritable:0},{pubkey:a,isSigner:0,isWritable:0},{pubkey:null!=u?u:t,isSigner:0,isWritable:null!==u},{pubkey:null!=c?c:t,isSigner:0,isWritable:1},{pubkey:l,isSigner:0,isWritable:0}]},it=n.struct([n.vec(n.array(n.u8(),32),"inputCompressedAccountHashes"),n.vec(n.array(n.u8(),32),"outputCompressedAccountHashes"),n.vec(n.struct([n.struct([n.publicKey("owner"),n.u64("lamports"),n.option(n.array(n.u8(),32),"address"),n.option(n.struct([n.array(n.u8(),8,"discriminator"),n.vecU8("data"),n.array(n.u8(),32,"dataHash")]),"data")],"compressedAccount"),n.u8("merkleTreeIndex")]),"outputCompressedAccounts"),n.vec(n.u32(),"outputLeafIndices"),n.vec(n.struct([n.publicKey("tree_pubkey"),n.publicKey("queue_pubkey"),n.u64("tree_type"),n.u64("seq")]),"sequenceNumbers"),n.option(n.u64(),"relayFee"),n.bool("isCompress"),n.option(n.u64(),"compressOrDecompressLamports"),n.vec(n.publicKey(),"pubkeyArray"),n.option(n.vecU8(),"message")]);function at(e){return it.decode(e)}const ut=n.struct([n.u8("is_invoked_by_program"),n.u8("bump"),n.u8("num_queues"),n.u8("num_output_queues"),n.u8("start_output_appends"),n.u8("num_address_queues"),n.array(n.u8(),32,"tx_hash")],"appendNullifyCreateAddressInputsMeta"),ct=n.struct([n.u8("index"),n.array(n.u8(),32,"leaf")],"appendLeavesInput"),lt=n.struct([n.array(n.u8(),32,"account_hash"),n.u32("leaf_index"),n.u8("prove_by_index"),n.u8("tree_index"),n.u8("queue_index")],"insertNullifierInput"),dt=n.struct([n.array(n.u8(),32,"address"),n.u8("tree_index"),n.u8("queue_index")],"insertAddressInput"),pt=n.struct([n.publicKey("tree_pubkey"),n.publicKey("queue_pubkey"),n.u64("tree_type"),n.u64("seq")],"merkleTreeSequenceNumber");function ht(e){let t=0;const r=ut.decode(e,t);t+=ut.span;const o=e.readUInt8(t);t+=1;const s=[];for(let r=0;r<o;r++){const r=ct.decode(e,t);s.push(r),t+=ct.span}const i=e.readUInt8(t);t+=1;const a=[];for(let r=0;r<i;r++){const r=lt.decode(e,t);a.push(r),t+=lt.span}const u=e.readUInt8(t);t+=1;const c=[];for(let r=0;r<u;r++){const r=dt.decode(e,t);c.push(r),t+=dt.span}const l=e.readUInt8(t);t+=1;const d=[];for(let r=0;r<l;r++){const r=pt.decode(e,t);d.push(r),t+=pt.span}const p=e.readUInt8(t);t+=1;for(let r=0;r<p;r++)pt.decode(e,t),t+=pt.span;const h=e.readUInt8(t);t+=1;for(let r=0;r<h;r++)pt.decode(e,t),t+=pt.span;const m=e.readUInt8(t);t+=1;const f=[];for(let r=0;r<m;r++){const r=n.u32().decode(e,t);f.push(r),t+=4}return{meta:r,leaves:s,nullifiers:a,addresses:c,sequence_numbers:d,output_leaf_indices:f}}function mt(r,o,n){const s=e=>Array.from(e instanceof t.Buffer?new Uint8Array(e):e);return{inputCompressedAccountHashes:r.nullifiers.map((e=>s(e.account_hash))),outputCompressedAccountHashes:r.leaves.map((e=>s(e.leaf))),outputCompressedAccounts:r.leaves.map(((r,o)=>{var i,a,u,c,l,d;return{compressedAccount:{owner:new e.PublicKey((null===(i=null==n?void 0:n.outputCompressedAccounts[o])||void 0===i?void 0:i.compressedAccount.owner)||e.PublicKey.default),lamports:Ue((null===(a=null==n?void 0:n.outputCompressedAccounts[o])||void 0===a?void 0:a.compressedAccount.lamports)||0),address:null==n?void 0:n.outputCompressedAccounts[o].compressedAccount.address,data:(null===(u=null==n?void 0:n.outputCompressedAccounts[o])||void 0===u?void 0:u.compressedAccount.data)?{discriminator:s(t.Buffer.from(null===(c=n.outputCompressedAccounts[o].compressedAccount.data)||void 0===c?void 0:c.discriminator)),data:null!==(l=s(t.Buffer.from(new Uint8Array(n.outputCompressedAccounts[o].compressedAccount.data.data))))&&void 0!==l?l:[],dataHash:s(t.Buffer.from(null===(d=n.outputCompressedAccounts[o].compressedAccount.data)||void 0===d?void 0:d.dataHash))}:null},merkleTreeIndex:r.index}})),outputLeafIndices:r.output_leaf_indices,sequenceNumbers:r.sequence_numbers.map((e=>({tree_pubkey:e.tree_pubkey,queue_pubkey:e.queue_pubkey,tree_type:e.tree_type,seq:e.seq}))),pubkeyArray:o.slice(2).filter((t=>!t.equals(e.PublicKey.default))),isCompress:(null==n?void 0:n.isCompress)||0,relayFee:(null==n?void 0:n.relayFee)?Ue(n.relayFee):null,compressOrDecompressLamports:(null==n?void 0:n.compressOrDecompressLamports)?Ue(n.compressOrDecompressLamports):null,message:null}}function ft(e,t){const r=e.findIndex((e=>e.equals(t)));return-1===r?(e.push(t),e.length-1):r}function yt(e,t){return t<=0?[]:new Array(t).fill(e)}function gt(e){return e.map((e=>({pubkey:e,isWritable:1,isSigner:0})))}function wt(e,t,r,o,n=[]){const s=n.slice(),i=[],a=[];if(e.forEach(((e,r)=>{const o=ft(s,e.treeInfo.tree),n=ft(s,e.treeInfo.queue);i.push({compressedAccount:{owner:e.owner,lamports:e.lamports,address:e.address,data:e.data},merkleContext:{merkleTreePubkeyIndex:o,queuePubkeyIndex:n,leafIndex:e.leafIndex,proveByIndex:e.proveByIndex},rootIndex:t[r],readOnly:0})})),e.length>0&&o)throw new Error("Cannot specify both input accounts and outputStateTreeInfo");let u;if(e.length>0)u=e[0].treeInfo;else{if(!o)throw new Error("Neither input accounts nor outputStateTreeInfo are available");u=o}const c=u.nextTreeInfo||u;let l=c.tree;if(c.treeType===exports.TreeType.StateV2){if(!$.isV2())throw new Error("V2 trees are not supported yet");l=c.queue}const d=yt(l,r.length);return r.forEach(((e,t)=>{const r=ft(s,d[t]);a.push({compressedAccount:{owner:e.owner,lamports:e.lamports,address:e.address,data:e.data},merkleTreeIndex:r})})),{packedInputCompressedAccounts:i,packedOutputCompressedAccounts:a,remainingAccounts:s}}function vt(e,t){switch(e.treeType){case exports.TreeType.StateV1:return t.insertOrGet(e.tree);case exports.TreeType.StateV2:return t.insertOrGet(e.queue);default:throw new Error("Invalid tree type for packing output tree index")}}const xt=e=>{if(e.lt(Ue(0)))throw new Error("Insufficient balance for transfer")},bt=e=>{if(0===e.length)throw new Error("No accounts provided for validation");const t=e[0].owner;if(!e.every((e=>e.owner.equals(t))))throw new Error("All input accounts must have the same owner")},It=(e,t)=>{if(e>0&&t>0){if(8===e)throw new Error(`Invalid number of compressed accounts for proof: ${e}. Allowed numbers: ${[1,2,3,4].join(", ")}`);$.isV2()?Tt(e,[1,2,3,4,8],"compressed accounts"):Tt(e,[1,2,3,4],"compressed accounts"),Et(t)}else e>0?At(e):Et(t)},At=e=>{$.isV2()?Tt(e,[1,2,3,4,8],"compressed accounts"):Tt(e,[1,2,3,4],"compressed accounts")},Et=e=>{$.isV2()?Tt(e,[1,2,3,4],"new addresses"):Tt(e,[1,2],"new addresses")},Tt=(e,t,r)=>{if(!t.includes(e))throw new Error(`Invalid number of ${r}: ${e}. Allowed numbers: ${t.join(", ")}`)};function Mt(e){if(!Number.isSafeInteger(e)||e<0)throw new Error(`positive integer expected, not ${e}`)}function St(e,...t){if(!((r=e)instanceof Uint8Array||null!=r&&"object"==typeof r&&"Uint8Array"===r.constructor.name))throw new Error("Uint8Array expected");var r;if(t.length>0&&!t.includes(e.length))throw new Error(`Uint8Array expected of length ${t}, not of length=${e.length}`)}function Ct(e,t=1){if(e.destroyed)throw new Error("Hash instance has been destroyed");if(t&&e.finished)throw new Error("Hash#digest() has already been called")}const kt=BigInt(2**32-1),_t=BigInt(32);function Pt(e,t=0){return t?{h:Number(e&kt),l:Number(e>>_t&kt)}:{h:0|Number(e>>_t&kt),l:0|Number(e&kt)}}function Ot(e,t=0){let r=new Uint32Array(e.length),o=new Uint32Array(e.length);for(let n=0;n<e.length;n++){const{h:s,l:i}=Pt(e[n],t);[r[n],o[n]]=[s,i]}return[r,o]}const Lt=68===new Uint8Array(new Uint32Array([287454020]).buffer)[0];function Nt(e){for(let r=0;r<e.length;r++)e[r]=(t=e[r])<<24&4278190080|t<<8&16711680|t>>>8&65280|t>>>24&255;var t}function Bt(e){return"string"==typeof e&&(e=function(e){if("string"!=typeof e)throw new Error("utf8ToBytes expected string, got "+typeof e);return new Uint8Array((new TextEncoder).encode(e))}(e)),St(e),e}class Rt{clone(){return this._cloneInto()}}const Dt=[],Ut=[],Vt=[],Ft=BigInt(0),qt=BigInt(1),Kt=BigInt(2),Wt=BigInt(7),Ht=BigInt(256),$t=BigInt(113);for(let e=0,t=qt,r=1,o=0;e<24;e++){[r,o]=[o,(2*r+3*o)%5],Dt.push(2*(5*o+r)),Ut.push((e+1)*(e+2)/2%64);let n=Ft;for(let e=0;e<7;e++)t=(t<<qt^(t>>Wt)*$t)%Ht,t&Kt&&(n^=qt<<(qt<<BigInt(e))-qt);Vt.push(n)}const[zt,jt]=Ot(Vt,1),Gt=(e,t,r)=>r>32?((e,t,r)=>t<<r-32|e>>>64-r)(e,t,r):((e,t,r)=>e<<r|t>>>32-r)(e,t,r),Zt=(e,t,r)=>r>32?((e,t,r)=>e<<r-32|t>>>64-r)(e,t,r):((e,t,r)=>t<<r|e>>>32-r)(e,t,r);class Jt extends Rt{constructor(e,t,r,o=0,n=24){if(super(),this.blockLen=e,this.suffix=t,this.outputLen=r,this.enableXOF=o,this.rounds=n,this.pos=0,this.posOut=0,this.finished=0,this.destroyed=0,Mt(r),0>=this.blockLen||this.blockLen>=200)throw new Error("Sha3 supports only keccak-f1600 function");var s;this.state=new Uint8Array(200),this.state32=(s=this.state,new Uint32Array(s.buffer,s.byteOffset,Math.floor(s.byteLength/4)))}keccak(){Lt||Nt(this.state32),function(e,t=24){const r=new Uint32Array(10);for(let o=24-t;o<24;o++){for(let t=0;t<10;t++)r[t]=e[t]^e[t+10]^e[t+20]^e[t+30]^e[t+40];for(let t=0;t<10;t+=2){const o=(t+8)%10,n=(t+2)%10,s=r[n],i=r[n+1],a=Gt(s,i,1)^r[o],u=Zt(s,i,1)^r[o+1];for(let r=0;r<50;r+=10)e[t+r]^=a,e[t+r+1]^=u}let t=e[2],n=e[3];for(let r=0;r<24;r++){const o=Ut[r],s=Gt(t,n,o),i=Zt(t,n,o),a=Dt[r];t=e[a],n=e[a+1],e[a]=s,e[a+1]=i}for(let t=0;t<50;t+=10){for(let o=0;o<10;o++)r[o]=e[t+o];for(let o=0;o<10;o++)e[t+o]^=~r[(o+2)%10]&r[(o+4)%10]}e[0]^=zt[o],e[1]^=jt[o]}r.fill(0)}(this.state32,this.rounds),Lt||Nt(this.state32),this.posOut=0,this.pos=0}update(e){Ct(this);const{blockLen:t,state:r}=this,o=(e=Bt(e)).length;for(let n=0;n<o;){const s=Math.min(t-this.pos,o-n);for(let t=0;t<s;t++)r[this.pos++]^=e[n++];this.pos===t&&this.keccak()}return this}finish(){if(this.finished)return;this.finished=1;const{state:e,suffix:t,pos:r,blockLen:o}=this;e[r]^=t,0!=(128&t)&&r===o-1&&this.keccak(),e[o-1]^=128,this.keccak()}writeInto(e){Ct(this,0),St(e),this.finish();const t=this.state,{blockLen:r}=this;for(let o=0,n=e.length;o<n;){this.posOut>=r&&this.keccak();const s=Math.min(r-this.posOut,n-o);e.set(t.subarray(this.posOut,this.posOut+s),o),this.posOut+=s,o+=s}return e}xofInto(e){if(!this.enableXOF)throw new Error("XOF is not possible for this instance");return this.writeInto(e)}xof(e){return Mt(e),this.xofInto(new Uint8Array(e))}digestInto(e){if(function(e,t){St(e);const r=t.outputLen;if(e.length<r)throw new Error(`digestInto() expects output buffer of length at least ${r}`)}(e,this),this.finished)throw new Error("digest() was already called");return this.writeInto(e),this.destroy(),e}digest(){return this.digestInto(new Uint8Array(this.outputLen))}destroy(){this.destroyed=1,this.state.fill(0)}_cloneInto(e){const{blockLen:t,suffix:r,outputLen:o,rounds:n,enableXOF:s}=this;return e||(e=new Jt(t,r,o,s,n)),e.state32.set(this.state32),e.pos=this.pos,e.posOut=this.posOut,e.finished=this.finished,e.rounds=n,e.suffix=r,e.outputLen=o,e.enableXOF=s,e.destroyed=this.destroyed,e}}const Qt=(()=>function(e){const t=t=>e().update(Bt(t)).digest(),r=e();return t.outputLen=r.outputLen,t.blockLen=r.blockLen,t.create=()=>e(),t}((()=>new Jt(136,1,32))))(),Xt=e=>"object"==typeof e&&null!==e,Yt=e=>Xt(e)&&!(e instanceof RegExp)&&!(e instanceof Error)&&!(e instanceof Date),er=Symbol("mapObjectSkip"),tr=(e,t,r,o=new WeakMap)=>{if(r={deep:0,target:{},...r},o.has(e))return o.get(e);o.set(e,r.target);const{target:n}=r;delete r.target;const s=e=>e.map((e=>Yt(e)?tr(e,t,r,o):e));if(Array.isArray(e))return s(e);for(const[i,a]of Object.entries(e)){const u=t(i,a,e);if(u===er)continue;let[c,l,{shouldRecurse:d=1}={}]=u;"__proto__"!==c&&(r.deep&&d&&Yt(l)&&(l=Array.isArray(l)?s(l):tr(l,t,r,o)),n[c]=l)}return n};function rr(e,t,r){if(!Xt(e))throw new TypeError(`Expected an object, got \`${e}\` (${typeof e})`);return tr(e,t,r)}const or=/[\p{Lu}]/u,nr=/[\p{Ll}]/u,sr=/^[\p{Lu}](?![\p{Lu}])/gu,ir=/([\p{Alpha}\p{N}_]|$)/u,ar=/[_.\- ]+/,ur=new RegExp("^"+ar.source),cr=new RegExp(ar.source+ir.source,"gu"),lr=new RegExp("\\d+"+ir.source,"gu");class dr extends Map{constructor(e={}){if(super(),!(e.maxSize&&e.maxSize>0))throw new TypeError("`maxSize` must be a number greater than 0");if("number"==typeof e.maxAge&&0===e.maxAge)throw new TypeError("`maxAge` must be a number greater than 0");this.maxSize=e.maxSize,this.maxAge=e.maxAge||Number.POSITIVE_INFINITY,this.onEviction=e.onEviction,this.cache=new Map,this.oldCache=new Map,this._size=0}_emitEvictions(e){if("function"==typeof this.onEviction)for(const[t,r]of e)this.onEviction(t,r.value)}_deleteIfExpired(e,t){return"number"==typeof t.expiry&&t.expiry<=Date.now()?("function"==typeof this.onEviction&&this.onEviction(e,t.value),this.delete(e)):0}_getOrDeleteIfExpired(e,t){if(0==this._deleteIfExpired(e,t))return t.value}_getItemValue(e,t){return t.expiry?this._getOrDeleteIfExpired(e,t):t.value}_peek(e,t){const r=t.get(e);return this._getItemValue(e,r)}_set(e,t){this.cache.set(e,t),this._size++,this._size>=this.maxSize&&(this._size=0,this._emitEvictions(this.oldCache),this.oldCache=this.cache,this.cache=new Map)}_moveToRecent(e,t){this.oldCache.delete(e),this._set(e,t)}*_entriesAscending(){for(const e of this.oldCache){const[t,r]=e;this.cache.has(t)||0==this._deleteIfExpired(t,r)&&(yield e)}for(const e of this.cache){const[t,r]=e;0==this._deleteIfExpired(t,r)&&(yield e)}}get(e){if(this.cache.has(e)){const t=this.cache.get(e);return this._getItemValue(e,t)}if(this.oldCache.has(e)){const t=this.oldCache.get(e);if(0==this._deleteIfExpired(e,t))return this._moveToRecent(e,t),t.value}}set(e,t,{maxAge:r=this.maxAge}={}){const o="number"==typeof r&&r!==Number.POSITIVE_INFINITY?Date.now()+r:void 0;return this.cache.has(e)?this.cache.set(e,{value:t,expiry:o}):this._set(e,{value:t,expiry:o}),this}has(e){return this.cache.has(e)?!this._deleteIfExpired(e,this.cache.get(e)):this.oldCache.has(e)?!this._deleteIfExpired(e,this.oldCache.get(e)):0}peek(e){return this.cache.has(e)?this._peek(e,this.cache):this.oldCache.has(e)?this._peek(e,this.oldCache):void 0}delete(e){const t=this.cache.delete(e);return t&&this._size--,this.oldCache.delete(e)||t}clear(){this.cache.clear(),this.oldCache.clear(),this._size=0}resize(e){if(!(e&&e>0))throw new TypeError("`maxSize` must be a number greater than 0");const t=[...this._entriesAscending()],r=t.length-e;r<0?(this.cache=new Map(t),this.oldCache=new Map,this._size=t.length):(r>0&&this._emitEvictions(t.slice(0,r)),this.oldCache=new Map(t.slice(r)),this.cache=new Map,this._size=0),this.maxSize=e}*keys(){for(const[e]of this)yield e}*values(){for(const[,e]of this)yield e}*[Symbol.iterator](){for(const e of this.cache){const[t,r]=e;0==this._deleteIfExpired(t,r)&&(yield[t,r.value])}for(const e of this.oldCache){const[t,r]=e;this.cache.has(t)||0==this._deleteIfExpired(t,r)&&(yield[t,r.value])}}*entriesDescending(){let e=[...this.cache];for(let t=e.length-1;t>=0;--t){const r=e[t],[o,n]=r;0==this._deleteIfExpired(o,n)&&(yield[o,n.value])}e=[...this.oldCache];for(let t=e.length-1;t>=0;--t){const r=e[t],[o,n]=r;this.cache.has(o)||0==this._deleteIfExpired(o,n)&&(yield[o,n.value])}}*entriesAscending(){for(const[e,t]of this._entriesAscending())yield[e,t.value]}get size(){if(!this._size)return this.oldCache.size;let e=0;for(const t of this.oldCache.keys())this.cache.has(t)||e++;return Math.min(this._size+e,this.maxSize)}entries(){return this.entriesAscending()}forEach(e,t=this){for(const[r,o]of this.entriesAscending())e.call(t,o,r,this)}get[Symbol.toStringTag](){return JSON.stringify([...this.entriesAscending()])}}const pr=new dr({maxSize:1e5}),hr=e=>!("object"!=typeof e||null===e||e instanceof RegExp||e instanceof Error||e instanceof Date),mr=(e,t={})=>{if(!hr(e))return e;const{exclude:r,pascalCase:o=0,stopPaths:n,deep:s=0,preserveConsecutiveUppercase:i=0}=t,a=new Set(n),u=e=>(t,n)=>{if(s&&hr(n)){const r=void 0===e?t:`${e}.${t}`;a.has(r)||(n=rr(n,u(r)))}if(!r||!((e,t)=>e.some((e=>"string"==typeof e?e===t:(e.lastIndex=0,e.test(t)))))(r,t)){const e=o?`${t}_`:t;if(pr.has(e))t=pr.get(e);else{const r=function(e,t){if("string"!=typeof e&&!Array.isArray(e))throw new TypeError("Expected the input to be `string | string[]`");if(t={pascalCase:0,preserveConsecutiveUppercase:0,...t},0===(e=Array.isArray(e)?e.map((e=>e.trim())).filter((e=>e.length)).join("-"):e.trim()).length)return"";const r=0==t.locale?e=>e.toLowerCase():e=>e.toLocaleLowerCase(t.locale),o=0==t.locale?e=>e.toUpperCase():e=>e.toLocaleUpperCase(t.locale);return 1===e.length?ar.test(e)?"":t.pascalCase?o(e):r(e):(e!==r(e)&&(e=((e,t,r,o)=>{let n=0,s=0,i=0,a=0;for(let u=0;u<e.length;u++){const c=e[u];a=u>2?"-"===e[u-3]:1,n&&or.test(c)?(e=e.slice(0,u)+"-"+e.slice(u),n=0,i=s,s=1,u++):s&&i&&nr.test(c)&&(!a||o)?(e=e.slice(0,u-1)+"-"+e.slice(u-1),i=s,s=0,n=1):(n=t(c)===c&&r(c)!==c,i=s,s=r(c)===c&&t(c)!==c)}return e})(e,r,o,t.preserveConsecutiveUppercase)),e=e.replace(ur,""),e=t.preserveConsecutiveUppercase?((e,t)=>(sr.lastIndex=0,e.replaceAll(sr,(e=>t(e)))))(e,r):r(e),t.pascalCase&&(e=o(e.charAt(0))+e.slice(1)),((e,t)=>(cr.lastIndex=0,lr.lastIndex=0,e.replaceAll(lr,((r,o,n)=>["_","-"].includes(e.charAt(n+r.length))?r:t(r))).replaceAll(cr,((e,r)=>t(r)))))(e,o))}(t,{pascalCase:o,locale:0,preserveConsecutiveUppercase:i});t.length<100&&pr.set(e,r),t=r}}return[t,n]};return rr(e,u(void 0))};function fr(e){return"0x"+e.toString("hex")}function yr(e){return Ue(e,void 0,"be").lt(j)}const gr=e=>{return t=e,r={deep:1},Array.isArray(t)?Object.keys(t).map((e=>mr(t[e],r))):mr(t,r);var t,r};function wr(e){let r=255;for(;r>=0;){const o=t.Buffer.concat([e,t.Buffer.from([r])]),n=Qt(o);if(32!==n.length)throw new Error("Invalid hash length");if(n[0]=0,yr(t.Buffer.from(n)))return[t.Buffer.from(n),r];r-=1}return null}function vr(e){const t=Qt.create();for(const r of e)t.update(r);const r=t.digest();return r[0]=0,r}function xr(r){const o=r.proof?{a:r.proof.a,b:r.proof.b,c:r.proof.c}:null,n=r.new_address_params.map((e=>({seed:e.seed,addressMerkleTreeRootIndex:e.address_merkle_tree_root_index,addressMerkleTreeAccountIndex:e.address_merkle_tree_account_index,addressQueueAccountIndex:e.address_queue_account_index})));return{proof:o,inputCompressedAccountsWithMerkleContext:r.input_compressed_accounts.map((r=>({compressedAccount:{owner:new e.PublicKey(t.Buffer.alloc(32)),lamports:Ue(r.lamports),address:r.address,data:null},merkleContext:{merkleTreePubkeyIndex:r.packedMerkleContext.merkle_tree_pubkey_index,queuePubkeyIndex:r.packedMerkleContext.queue_pubkey_index,leafIndex:r.packedMerkleContext.leaf_index,proveByIndex:r.packedMerkleContext.prove_by_index},rootIndex:r.root_index,readOnly:0}))),outputCompressedAccounts:r.output_compressed_accounts.map((e=>({compressedAccount:{owner:e.compressedAccount.owner,lamports:e.compressedAccount.lamports,address:e.compressedAccount.address,data:e.compressedAccount.data},merkleTreeIndex:e.merkleTreeIndex}))),relayFee:null,newAddressParams:n,compressOrDecompressLamports:r.compress_or_decompress_lamports,isCompress:r.is_compress}}function br(e,t,r){return Ir([e,t,r])}function Ir(e){const t=Qt.create();for(const r of e)t.update(r);t.update(new Uint8Array([255]));const r=t.digest();return r[0]=0,r}function Ar(e,t){return vr([t.toBytes(),...e])}function Er(t,r=de().addressTree){if(32!=t.length)throw new Error("Seed length is not 32 bytes.");const o=r.toBytes(),n=wr(Buffer.from([...o,...t]));if(null===n)throw new Error("DeriveAddressError");const s=n[0];return new e.PublicKey(s)}function Tr(e,t){const r=t.slice(),o=e.map((e=>({seed:Array.from(e.seed),addressMerkleTreeRootIndex:e.addressMerkleTreeRootIndex,addressMerkleTreeAccountIndex:0,addressQueueAccountIndex:0})));return e.forEach(((e,t)=>{o[t].addressMerkleTreeAccountIndex=ft(r,e.addressMerkleTreePubkey)})),e.forEach(((e,t)=>{o[t].addressQueueAccountIndex=ft(r,e.addressQueuePubkey)})),{newAddressParamsPacked:o,remainingAccounts:r}}async function Mr(e,t,r="confirmed"){const o=await e.getLatestBlockhash(r),n={signature:t.toString(),lastValidBlockHeight:o.lastValidBlockHeight,blockhash:o.blockhash};return await e.confirmTransaction(n,r)}function Sr(e,t){return t.includes(e)?t.filter((t=>t.publicKey.toString()!==e.publicKey.toString())):t}function Cr(e){const t=_r(e.ar[0]),r=_r(e.ar[1]),o=new Uint8Array([...t,...r]),n=_r(e.bs[0][0]),s=_r(e.bs[0][1]),i=_r(e.bs[1][0]),a=_r(e.bs[1][1]),u=new Uint8Array([...n,...s,...i,...a]),c=_r(e.krs[0]),l=_r(e.krs[1]);return{a:o,b:u,c:new Uint8Array([...c,...l])}}function kr(e){const t=e.a,r=e.b,o=e.c,n=t.slice(0,32),s=Pr(Ue(t.slice(32,64),32,"be"))?0:1;n[0]=Or(n[0],s);const i=r.slice(0,64),a=r.slice(64,128),u=function(e,t){const r=j.div(Ue(2));return e.lt(r)?1:e.gt(r)?0:t.lt(r)}(Ue(a.slice(0,32),32,"be"),Ue(a.slice(32,64),32,"be"));i[0]=Or(i[0],u);const c=o.slice(0,32),l=o.slice(32,64),d=Pr(Ue(l,32,"be"));return c[0]=Or(c[0],d),{a:Array.from(n),b:Array.from(i),c:Array.from(c)}}function _r(e){const t=Ue(e.startsWith("0x")?e.substring(2):e,"hex");return new Uint8Array(t.toArray("be",32))}function Pr(e){return e.lte(j.sub(e))}function Or(e,t){return t?e:128|e}function Lr(t,r,o,n){const s=new e.TransactionMessage({payerKey:r,recentBlockhash:o,instructions:t}).compileToV0Message(n);return new e.VersionedTransaction(s)}async function Nr(e,t,r){const o=await e.sendTransaction(t,r);return await Br(e,o,r),o}async function Br(e,t,r){const o=(null==r?void 0:r.commitment)||e.commitment||"confirmed",n=ue(e.rpcEndpoint)?200:1e3;let s=0;await new Promise(((r,i)=>{const a=setInterval((async()=>{var u;s+=n,s>=8e4&&(clearInterval(a),i(new Error(`Transaction ${t}'s confirmation timed out`)));const c=await e.getSignatureStatuses([t]);(null===(u=null==c?void 0:c.value[0])||void 0===u?void 0:u.confirmationStatus)===o&&(clearInterval(a),r(t))}),n)}));const i=await e.getSlot();return await e.confirmTransactionIndexed(i),{context:{slot:i},value:{err:null}}}function Rr(e,t,r,o=[],n){if(o.includes(t))throw new Error("payer must not be in additionalSigners");const s=[t,...o],i=Lr(e,t.publicKey,r,n);return i.sign(s),i}function Dr(e,t){return Ur(e,t)}function Ur(e,t){const r=e.find((e=>e.tree.equals(t)||e.queue.equals(t)));if(!r)throw new Error(`No associated TreeInfo found for tree or queue. Please set activeStateTreeInfos with latest Tree accounts. If you use custom state trees, set manually. Pubkey: ${t.toBase58()}`);if(!r.queue)throw new Error("Queue must not be null for state tree. Please set activeStateTreeInfos with latest Tree accounts. If you use custom state trees, set manually. Pubkey: "+t.toBase58());return r}function Vr(e,t=($.isV2()?exports.TreeType.StateV2:exports.TreeType.StateV1),r=0){const o=e.filter((e=>!e.nextTreeInfo)).filter((e=>e.treeType===t));if(0===o.length)throw new Error("No active state tree infos found for the specified tree type");const n=r?o.length:Math.min(5,o.length),s=Math.floor(Math.random()*n);if(!o[s].queue)throw new Error("Queue must not be null for state tree");return o[s]}async function Fr({connection:t,stateTreeLUTPairs:r}){var o;const n=await Promise.all(r.map((async e=>({stateTreeLookupTable:await t.getAddressLookupTable(e.stateTreeLookupTable),nullifyLookupTable:await t.getAddressLookupTable(e.nullifyLookupTable)})))),s=[];for(const{stateTreeLookupTable:t,nullifyLookupTable:r}of n){if(!t.value)throw new Error("State tree lookup table not found");if(!r.value)throw new Error("Nullify table not found");const n=t.value.state.addresses,i=r.value.state.addresses;if(n.length%3!=0)throw new Error("State tree lookup table must have a multiple of 3 addresses");for(let t=0;t<n.length;t+=3){const r=n[t],o=n[t+1],a=n[t+2];let u=null;if(!r||!o||!a)throw new Error("Invalid state tree pubkeys structure");i.map((e=>e.toBase58())).includes(r.toBase58())&&(u={tree:e.PublicKey.default,queue:e.PublicKey.default,cpiContext:e.PublicKey.default,treeType:exports.TreeType.StateV1,nextTreeInfo:null}),s.push({tree:r,queue:o,cpiContext:a,treeType:exports.TreeType.StateV1,nextTreeInfo:u})}for(const t of s)if(null===(o=t.nextTreeInfo)||void 0===o?void 0:o.tree.equals(e.PublicKey.default)){const e=s.find((e=>!e.nextTreeInfo));if(!e)throw new Error("No available tree info found to assign as next tree");t.nextTreeInfo=e}}return s}class qr{constructor(){this.preAccounts=[],this.systemAccounts=[],this.nextIndex=0,this.map=new Map}static newWithSystemAccounts(e){const t=new qr;return t.addSystemAccounts(e),t}addPreAccountsSigner(e){this.preAccounts.push({pubkey:e,isSigner:1,isWritable:0})}addPreAccountsSignerMut(e){this.preAccounts.push({pubkey:e,isSigner:1,isWritable:1})}addPreAccountsMeta(e){this.preAccounts.push(e)}addSystemAccounts(e){this.systemAccounts.push(...Wr(e))}insertOrGet(e){return this.insertOrGetConfig(e,0,1)}insertOrGetReadOnly(e){return this.insertOrGetConfig(e,0,0)}insertOrGetConfig(e,t,r){const o=e.toString(),n=this.map.get(o);if(n)return n[0];const s=this.nextIndex++,i={pubkey:e,isSigner:t,isWritable:r};return this.map.set(o,[s,i]),s}hashSetAccountsToMetas(){const e=Array.from(this.map.entries());return e.sort(((e,t)=>e[1][0]-t[1][0])),e.map((([,[,e]])=>e))}getOffsets(){const e=this.preAccounts.length;return[e,e+this.systemAccounts.length]}toAccountMetas(){const e=this.hashSetAccountsToMetas(),[t,r]=this.getOffsets();return{remainingAccounts:[...this.preAccounts,...this.systemAccounts,...e],systemStart:t,packedStart:r}}}class Kr{constructor(e,t,r,o){this.selfProgram=e,this.cpiContext=t,this.solCompressionRecipient=r,this.solPoolPda=o}static new(e){return new Kr(e)}static newWithCpiContext(e,t){return new Kr(e,t)}}function Wr(t){let r=(new TextEncoder).encode("cpi_authority");const o=e.PublicKey.findProgramAddressSync([r],t.selfProgram)[0],n=zr.default(),s=[{pubkey:n.lightSystemProgram,isSigner:0,isWritable:0},{pubkey:o,isSigner:0,isWritable:0},{pubkey:n.registeredProgramPda,isSigner:0,isWritable:0},{pubkey:n.noopProgram,isSigner:0,isWritable:0},{pubkey:n.accountCompressionAuthority,isSigner:0,isWritable:0},{pubkey:n.accountCompressionProgram,isSigner:0,isWritable:0},{pubkey:t.selfProgram,isSigner:0,isWritable:0}];return t.solPoolPda&&s.push({pubkey:t.solPoolPda,isSigner:0,isWritable:1}),t.solCompressionRecipient&&s.push({pubkey:t.solCompressionRecipient,isSigner:0,isWritable:1}),s.push({pubkey:n.systemProgram,isSigner:0,isWritable:0}),t.cpiContext&&s.push({pubkey:t.cpiContext,isSigner:0,isWritable:1}),s}class Hr{constructor(){this.preAccounts=[],this.systemAccounts=[],this.nextIndex=0,this.map=new Map}static newWithSystemAccounts(e){const t=new Hr;return t.addSystemAccounts(e),t}getNamedMetas(){return this.map}addPreAccountsSigner(e){this.preAccounts.push({pubkey:e,isSigner:1,isWritable:0})}addPreAccountsSignerMut(e){this.preAccounts.push({pubkey:e,isSigner:1,isWritable:1})}addPreAccountsMeta(e){this.preAccounts.push(e)}addSystemAccounts(e){this.systemAccounts.push(...$r(e))}insertOrGet(e){return this.insertOrGetConfig(e,0,1)}insertOrGetReadOnly(e){return this.insertOrGetConfig(e,0,0)}insertOrGetConfig(e,t,r){const o=e.toString(),n=this.map.get(o);if(n)return n[0];const s=this.nextIndex++,i={pubkey:e,isSigner:t,isWritable:r};return this.map.set(o,[s,i]),s}hashSetAccountsToMetas(){const e=Array.from(this.map.entries());return e.sort(((e,t)=>e[1][0]-t[1][0])),e.map((([,[,e]])=>e))}getOffsets(){const e=this.preAccounts.length;return[e,e+this.systemAccounts.length]}toAccountMetas(){const e=this.hashSetAccountsToMetas(),[t,r]=this.getOffsets();return{remainingAccounts:[...this.preAccounts,...this.systemAccounts,...e],systemStart:t,packedStart:r}}}function $r(t){let r=(new TextEncoder).encode("cpi_authority");const o=e.PublicKey.findProgramAddressSync([r],t.selfProgram)[0],n=zr.default(),s=[{pubkey:n.lightSystemProgram,isSigner:0,isWritable:0},{pubkey:o,isSigner:0,isWritable:0},{pubkey:n.registeredProgramPda,isSigner:0,isWritable:0},{pubkey:n.accountCompressionAuthority,isSigner:0,isWritable:0},{pubkey:n.accountCompressionProgram,isSigner:0,isWritable:0},{pubkey:n.systemProgram,isSigner:0,isWritable:0}];return t.solPoolPda&&s.push({pubkey:t.solPoolPda,isSigner:0,isWritable:1}),t.solCompressionRecipient&&s.push({pubkey:t.solCompressionRecipient,isSigner:0,isWritable:1}),t.cpiContext&&s.push({pubkey:t.cpiContext,isSigner:0,isWritable:1}),s}class zr{constructor(e,t,r,o,n,s,i){this.lightSystemProgram=e,this.systemProgram=t,this.accountCompressionProgram=r,this.accountCompressionAuthority=o,this.registeredProgramPda=n,this.noopProgram=s,this.solPoolPda=i}static default(){return new zr(Zr.programId,e.SystemProgram.programId,ie().accountCompressionProgram,ie().accountCompressionAuthority,ie().registeredProgramPda,ie().noopProgram,e.PublicKey.default)}}const jr=e=>e.reduce(((e,t)=>e.add(Ue(t.lamports))),Ue(0)),Gr=t.Buffer.from("sol_pool_pda");class Zr{constructor(){}static deriveCompressedSolPda(){const t=[Gr],[r,o]=e.PublicKey.findProgramAddressSync(t,this.programId);return r}static createTransferOutputState(e,t,r){r=Ue(r);const o=jr(e).sub(r);return xt(o),o.eq(Ue(0))?[Ve(t,r)]:(bt(e),[Ve(e[0].owner,o),Ve(t,r)])}static createDecompressOutputState(e,t){t=Ue(t);const r=jr(e).sub(t);return xt(r),r.eq(Ue(0))?[]:(bt(e),[Ve(e[0].owner,r)])}static createNewAddressOutputState(e,t,r,o){r=Ue(null!=r?r:0);const n=jr(null!=o?o:[]).sub(r);return xt(n),n.eq(Ue(0))||!o?[Ve(t,r,void 0,e)]:(bt(o),[Ve(o[0].owner,n),Ve(t,r,void 0,e)])}static async createAccount({payer:t,newAddressParams:r,newAddress:o,recentValidityProof:n,outputStateTreeInfo:s,inputCompressedAccounts:i,inputStateRootIndices:a,lamports:u}){const c=this.createNewAddressOutputState(o,t,u,i),{packedInputCompressedAccounts:l,packedOutputCompressedAccounts:d,remainingAccounts:p}=wt(null!=i?i:[],null!=a?a:[],c,i&&0!==i.length?void 0:s),{newAddressParamsPacked:h,remainingAccounts:m}=Tr([r],p),f=ze({proof:n,inputCompressedAccountsWithMerkleContext:l,outputCompressedAccounts:d,relayFee:null,newAddressParams:h,compressOrDecompressLamports:null,isCompress:0}),y=[...st(Object.assign(Object.assign({},ie()),{feePayer:t,authority:t,solPoolPda:null,decompressionRecipient:null,systemProgram:e.SystemProgram.programId})),...gt(m)];return new e.TransactionInstruction({programId:this.programId,keys:y,data:f})}static async transfer({payer:t,inputCompressedAccounts:r,toAddress:o,lamports:n,recentInputStateRootIndices:s,recentValidityProof:i}){const a=this.createTransferOutputState(r,o,n),{packedInputCompressedAccounts:u,packedOutputCompressedAccounts:c,remainingAccounts:l}=wt(r,s,a),d=ze({proof:i,inputCompressedAccountsWithMerkleContext:u,outputCompressedAccounts:c,relayFee:null,newAddressParams:[],compressOrDecompressLamports:null,isCompress:0}),p=[...st(Object.assign(Object.assign({},ie()),{feePayer:t,authority:t,solPoolPda:null,decompressionRecipient:null,systemProgram:e.SystemProgram.programId})),...gt(l)];return new e.TransactionInstruction({programId:this.programId,keys:p,data:d})}static async compress({payer:t,toAddress:r,lamports:o,outputStateTreeInfo:n}){o=Ue(o);const s=Ve(r,o),{packedInputCompressedAccounts:i,packedOutputCompressedAccounts:a,remainingAccounts:u}=wt([],[],[s],n),c=ze({proof:null,inputCompressedAccountsWithMerkleContext:i,outputCompressedAccounts:a,relayFee:null,newAddressParams:[],compressOrDecompressLamports:o,isCompress:1}),l=[...st(Object.assign(Object.assign({},ie()),{feePayer:t,authority:t,solPoolPda:Zr.deriveCompressedSolPda(),decompressionRecipient:null,systemProgram:e.SystemProgram.programId})),...gt(u)];return new e.TransactionInstruction({programId:this.programId,keys:l,data:c})}static async decompress({payer:t,inputCompressedAccounts:r,toAddress:o,lamports:n,recentInputStateRootIndices:s,recentValidityProof:i}){n=Ue(n);const a=this.createDecompressOutputState(r,n),{packedInputCompressedAccounts:u,packedOutputCompressedAccounts:c,remainingAccounts:l}=wt(r,s,a),d=ze({proof:i,inputCompressedAccountsWithMerkleContext:u,outputCompressedAccounts:c,relayFee:null,newAddressParams:[],compressOrDecompressLamports:n,isCompress:0}),p=[...st(Object.assign(Object.assign({},ie()),{feePayer:t,authority:t,solPoolPda:Zr.deriveCompressedSolPda(),decompressionRecipient:o,systemProgram:e.SystemProgram.programId})),...gt(l)];return new e.TransactionInstruction({programId:this.programId,keys:p,data:d})}}function Jr(e,t){let r=Ue(0);t=Ue(t);const o=[];e.sort(((e,t)=>t.lamports.cmp(e.lamports)));for(const n of e){if(r.gte(Ue(t)))break;r=r.add(n.lamports),o.push(n)}if(r.lt(Ue(t)))throw new Error(`Insufficient balance for transfer. Required: ${t.toString()}, available: ${r.toString()}`);return[o,r]}Zr.programId=new e.PublicKey("SySTEM1eSU2p4BGQfQpimFEWWSC1XDFeun3Nqzz3rT7");class Qr{constructor(e,t,r){this.index=e,this.value=t,this.nextIndex=r}equals(e){return this.value.eq(e.value)}compareTo(e){return this.value.cmp(e.value)}hash(e,t){try{return e.poseidonHash([Ue(this.value.toArray("be",32)).toString(),Ue(this.nextIndex).toString(),Ue(t.toArray("be",32)).toString()])}catch(e){throw new Error("Hashing failed")}}}class Xr{constructor(e,t,r){this.newLowElement=e,this.newElement=t,this.newElementNextValue=r}}class Yr{constructor(e,t,r){this.elements=e,this.currentNodeIndex=t,this.highestElementIndex=r}static default(){return new Yr([new Qr(0,Ue(0),0)],0,0)}get(e){return this.elements[e]}length(){return Number(this.currentNodeIndex)}isEmpty(){return 0===this.currentNodeIndex}findElement(e){return this.elements.slice(0,this.length()+1).find((t=>t.value===e))}init(){try{const e=G;return this.append(e)}catch(e){throw new Error(`Failed to initialize IndexedArray: ${e}`)}}findLowElementIndex(e){for(let t=0;t<=this.length();t++){const r=this.elements[t];if(this.elements[r.nextIndex].value.gt(e)&&r.value.lt(e))return t;if(r.value.eq(e))throw new Error("Element already exists in the array")}return this.highestElementIndex}findLowElement(e){const t=this.findLowElementIndex(e);if(void 0===t)return[void 0,void 0];const r=this.elements[t];return[r,this.elements[r.nextIndex].value]}hashElement(e,t){const r=this.elements[t];if(!r)return;const o=this.elements[r.nextIndex];return o?e.poseidonHash([Ue(r.value.toArray("be",32)).toString(),Ue(r.nextIndex).toString(),Ue(o.value.toArray("be",32)).toString()]):void 0}append(e){const t=this.findLowElementIndex(e);if(void 0===t)throw new Error("Low element index not found.");return this.appendWithLowElementIndex(t,e)}appendWithLowElementIndex(e,t){const r=this.elements[e];if(0===r.nextIndex){if(t.lte(r.value))throw new Error("New element value must be greater than the low element value.")}else{const e=this.elements[r.nextIndex];if(t.lte(r.value))throw new Error("New element value must be greater than the low element value.");if(t.gte(e.value))throw new Error("New element value must be less than the next element value.")}const o=this.newElementWithLowElementIndex(e,t);return 0===r.nextIndex&&(this.highestElementIndex=o.newElement.index),this.currentNodeIndex=o.newElement.index,this.elements[this.length()]=o.newElement,this.elements[e]=o.newLowElement,o}lowest(){return this.elements.length>0?this.elements[0]:void 0}newElementWithLowElementIndex(e,t){const r=this.elements[e],o=this.currentNodeIndex+1,n=new Qr(o,t,r.nextIndex);r.nextIndex=o;const s=this.elements[n.nextIndex].value;return new Xr(r,n,s)}newElement(e){const t=this.findLowElementIndex(e);if(void 0===t)throw new Error("Low element index not found.");return this.newElementWithLowElementIndex(t,e)}}class eo{constructor(e,t,r=[],{zeroElement:o="0"}={}){if(this.levels=e,this.capacity=2**e,this.zeroElement=o,this._lightWasm=t,r.length>this.capacity)throw new Error("Tree is full");this._zeros=[],this._layers=[],this._layers[0]=r,this._zeros[0]=this.zeroElement;for(let t=1;t<=e;t++)this._zeros[t]=this._lightWasm.poseidonHashString([this._zeros[t-1],this._zeros[t-1]]);this._rebuild()}_rebuild(){for(let e=1;e<=this.levels;e++){this._layers[e]=[];for(let t=0;t<Math.ceil(this._layers[e-1].length/2);t++)this._layers[e][t]=this._lightWasm.poseidonHashString([this._layers[e-1][2*t],2*t+1<this._layers[e-1].length?this._layers[e-1][2*t+1]:this._zeros[e-1]])}}root(){return this._layers[this.levels].length>0?this._layers[this.levels][0]:this._zeros[this.levels]}insert(e){if(this._layers[0].length>=this.capacity)throw new Error("Tree is full");this.update(this._layers[0].length,e)}bulkInsert(e){if(this._layers[0].length+e.length>this.capacity)throw new Error("Tree is full");this._layers[0].push(...e),this._rebuild()}update(e,t){if(isNaN(Number(e))||e<0||e>this._layers[0].length||e>=this.capacity)throw new Error("Insert index out of bounds: "+e);this._layers[0][e]=t;for(let t=1;t<=this.levels;t++)e>>=1,this._layers[t][e]=this._lightWasm.poseidonHashString([this._layers[t-1][2*e],2*e+1<this._layers[t-1].length?this._layers[t-1][2*e+1]:this._zeros[t-1]])}path(e){if(isNaN(Number(e))||e<0||e>=this._layers[0].length)throw new Error("Index out of bounds: "+e);const t=[],r=[];for(let o=0;o<this.levels;o++)r[o]=e%2,t[o]=(1^e)<this._layers[o].length?this._layers[o][1^e]:this._zeros[o],e>>=1;return{pathElements:t,pathIndices:r}}indexOf(e,t=null){return t?this._layers[0].findIndex((r=>t(e,r))):this._layers[0].indexOf(e)}elements(){return this._layers[0].slice()}serialize(){return{levels:this.levels,_zeros:this._zeros,_layers:this._layers}}static deserialize(e,t){const r=Object.assign(Object.create(this.prototype),e);return r._hash=t,r.capacity=2**r.levels,r.zeroElement=r._zeros[0],r}}async function to(e){const t=[],{noopProgram:r,accountCompressionProgram:o}=ie(),n=(await e.getSignaturesForAddress(o,void 0,"confirmed")).map((e=>e.signature)),s=await e.getParsedTransactions(n,{maxSupportedTransactionVersion:0,commitment:"confirmed"});for(const r of s){if(!r||!r.transaction||!r.meta)continue;if(!r.meta.innerInstructions||0==r.meta.innerInstructions.length)continue;const o=r.transaction.message.accountKeys.map((e=>e.pubkey)),n=[],s=await e.getTransaction(r.transaction.signatures[0],{commitment:"confirmed",maxSupportedTransactionVersion:0});for(const e of(null==s?void 0:s.transaction.message.compiledInstructions)||[])if(e.data&&e.data.length>0){const t=Uint8Array.from(e.data);if(t.length===Z.length&&Z.every(((e,r)=>e===t[r])))continue;n.push(t)}const i=[];if(s.meta.innerInstructions&&s.meta.innerInstructions.length>0)for(const e of s.meta.innerInstructions)for(const t of e.instructions){const e=t.accounts.map((e=>o[e]));if(i.push(e),t.data&&t.data.length>0){const e=Be.decode(t.data);n.push(e)}}const a=no(n,i);a&&t.push(a)}if(t.length>0)return t;const i=s.filter((e=>e?e.transaction.message.accountKeys.some((e=>("string"==typeof e?e:e.pubkey.toBase58())===r.toBase58())):0));return ro(i,oo)}const ro=(e,r)=>{const{noopProgram:o}=ie(),n=[];return e.forEach((e=>{!e||!e.meta||e.meta.err||!e.meta.innerInstructions||e.meta.innerInstructions.length<=0||e.meta.innerInstructions.forEach((s=>{if(s.instructions.length>0){const i=s.instructions[s.instructions.length-1];if("data"in i&&i.data&&i.programId.toBase58()===o.toBase58()){const o=Be.decode(i.data),s=r(t.Buffer.from(o),e);null!=s&&n.push(s)}}}))})),n},oo=e=>{const r=t.Buffer.from(e.map((e=>e)));try{return at(r)}catch(e){return console.error("Error deserializing event:",e),null}};function no(e,r){let o=0,n=null,s=null;for(const r of e){const e=r.slice(0,8),s=Be.encode(e),i=Be.encode(J),a=Be.encode(Q),u=Be.encode(X);if(s===i){n=ot(t.Buffer.from(r)),o=1;break}if(s==a){n=nt(t.Buffer.from(r)),o=1;break}if(s==u){n=xr(rt(t.Buffer.from(r))),o=1;break}}if(!o)return null;for(const r of e){const e=r.slice(0,8);if(Be.encode(e)===Be.encode(ee)){const e=r.slice(12);s=ht(t.Buffer.from(e))}}return n?mt(s,r[r.length-1],n):null}async function so(e,t){return(await io(e)).find((e=>Ue(e.hash).eq(t)))}async function io(e){var t,r;const o=(await to(e)).reverse(),n=[],s=[],i=await e.getStateTreeInfos();for(const e of o){for(let o=0;o<e.outputCompressedAccounts.length;o++){const s=Dr(i,e.pubkeyArray[e.outputCompressedAccounts[o].merkleTreeIndex]),a=e.outputCompressedAccounts[o],u={treeInfo:s,hash:Ue(e.outputCompressedAccountHashes[o]),leafIndex:e.outputLeafIndices[o],proveByIndex:s.treeType===exports.TreeType.StateV2},c=Fe(u,a.compressedAccount.owner,a.compressedAccount.lamports,null!==(t=a.compressedAccount.data)&&void 0!==t?t:void 0,null!==(r=a.compressedAccount.address)&&void 0!==r?r:void 0);n.push(c)}for(let t=0;t<e.inputCompressedAccountHashes.length;t++){const r=e.inputCompressedAccountHashes[t];s.push(Ue(r))}}const a=n.filter((e=>!s.some((t=>t.eq(Ue(e.hash))))));return a.sort(((e,t)=>t.leafIndex-e.leafIndex)),a}const ao=n.struct([n.publicKey("mint"),n.publicKey("owner"),n.u64("amount"),n.option(n.publicKey(),"delegate"),n.u8("state"),n.option(n.vecU8(),"tlv")]);function uo(e,t=pe){if(null===e.data)return null;const{data:r}=e.data;if(0===r.length)return null;if(e.owner.toBase58()!==t.toBase58())throw new Error(`Invalid owner ${e.owner.toBase58()} for token layout`);try{return ao.decode(Buffer.from(r))}catch(e){throw console.error("Decoding error:",e),e}}async function co(e,t){const r=await Promise.all(e.map((e=>async function(e,t){const r=e.pubkeyArray,o=await t.getStateTreeInfos(),n=e.outputCompressedAccountHashes,s=e.outputCompressedAccounts.map(((t,s)=>{var i;const a=r[e.outputCompressedAccounts[s].merkleTreeIndex],u=Dr(o,a);if(!(u.tree.equals(r[e.outputCompressedAccounts[s].merkleTreeIndex])||$.isV2()&&u.queue.equals(r[e.outputCompressedAccounts[s].merkleTreeIndex])))throw new Error("Invalid tree");const c={treeInfo:u,hash:Ue(n[s]),leafIndex:e.outputLeafIndices[s],proveByIndex:u.treeType===exports.TreeType.StateV2};if(!t.compressedAccount.data)throw new Error("No data");const l=uo(t.compressedAccount);if(!l)throw new Error("Invalid token data");return{compressedAccount:Fe(c,t.compressedAccount.owner,t.compressedAccount.lamports,t.compressedAccount.data,null!==(i=t.compressedAccount.address)&&void 0!==i?i:void 0),parsed:l}}));return{inputCompressedAccountHashes:e.inputCompressedAccountHashes,outputCompressedAccounts:s}}(e,t)))),o=r.flatMap((e=>e.outputCompressedAccounts)),n=r.flatMap((e=>e.inputCompressedAccountHashes));return o.filter((e=>!n.some((t=>Ue(t).eq(e.compressedAccount.hash)))))}async function lo(e,t,r){const o=await to(e);return{items:(await co(o,e)).filter((e=>e.parsed.owner.equals(t)&&e.parsed.mint.equals(r))).sort(((e,t)=>e.compressedAccount.leafIndex-t.compressedAccount.leafIndex)),cursor:null}}async function po(e,t,r){const o=await to(e);return{items:(await co(o,e)).filter((e=>{var o;return(null===(o=e.parsed.delegate)||void 0===o?void 0:o.equals(t))&&e.parsed.mint.equals(r)})),cursor:null}}async function ho(e,t){const r=await to(e),o=(await co(r,e)).filter((e=>Ue(e.compressedAccount.hash).eq(t)));if(0===o.length)throw new Error("No compressed account found");return o[0]}class mo extends TypeError{constructor(e,t){let r;const{message:o,explanation:n,...s}=e,{path:i}=e,a=0===i.length?o:`At path: ${i.join(".")} -- ${o}`;super(n??a),null!=n&&(this.cause=a),Object.assign(this,s),this.name=this.constructor.name,this.failures=()=>r??(r=[e,...t()])}}function fo(e){return"object"==typeof e&&null!=e}function yo(e){return fo(e)&&!Array.isArray(e)}function go(e){return"symbol"==typeof e?e.toString():"string"==typeof e?JSON.stringify(e):`${e}`}function wo(e,t,r,o){if(1==e)return;0==e?e={}:"string"==typeof e&&(e={message:e});const{path:n,branch:s}=t,{type:i}=r,{refinement:a,message:u=`Expected a value of type \`${i}\`${a?` with refinement \`${a}\``:""}, but received: \`${go(o)}\``}=e;return{value:o,type:i,refinement:a,key:n[n.length-1],path:n,branch:s,...e,message:u}}function*vo(e,t,r,o){var n;fo(n=e)&&"function"==typeof n[Symbol.iterator]||(e=[e]);for(const n of e){const e=wo(n,t,r,o);e&&(yield e)}}function*xo(e,t,r={}){const{path:o=[],branch:n=[e],coerce:s=0,mask:i=0}=r,a={path:o,branch:n,mask:i};s&&(e=t.coercer(e,a));let u="valid";for(const o of t.validator(e,a))o.explanation=r.message,u="not_valid",yield[o,void 0];for(let[c,l,d]of t.entries(e,a)){const t=xo(l,d,{path:void 0===c?o:[...o,c],branch:void 0===c?n:[...n,l],coerce:s,mask:i,message:r.message});for(const r of t)r[0]?(u=null!=r[0].refinement?"not_refined":"not_valid",yield[r[0],void 0]):s&&(l=r[1],void 0===c?e=l:e instanceof Map?e.set(c,l):e instanceof Set?e.add(l):fo(e)&&(void 0!==l||c in e)&&(e[c]=l))}if("not_valid"!==u)for(const o of t.refiner(e,a))o.explanation=r.message,u="not_refined",yield[o,void 0];"valid"===u&&(yield[void 0,e])}class bo{constructor(e){const{type:t,schema:r,validator:o,refiner:n,coercer:s=(e=>e),entries:i=function*(){}}=e;this.type=t,this.schema=r,this.entries=i,this.coercer=s,this.validator=o?(e,t)=>vo(o(e,t),t,this,e):()=>[],this.refiner=n?(e,t)=>vo(n(e,t),t,this,e):()=>[]}assert(e,t){return function(e,t,r){const o=Eo(e,t,{message:r});if(o[0])throw o[0]}(e,this,t)}create(e,t){return Io(e,this,t)}is(e){return Ao(e,this)}mask(e,t){return function(e,t,r){const o=Eo(e,t,{coerce:1,mask:1,message:r});if(o[0])throw o[0];return o[1]}(e,this,t)}validate(e,t={}){return Eo(e,this,t)}}function Io(e,t,r){const o=Eo(e,t,{coerce:1,message:r});if(o[0])throw o[0];return o[1]}function Ao(e,t){return!Eo(e,t)[0]}function Eo(e,t,r={}){const o=xo(e,t,r),n=function(e){const{done:t,value:r}=e.next();return t?void 0:r}(o);return n[0]?[new mo(n[0],(function*(){for(const e of o)e[0]&&(yield e[0])})),void 0]:[void 0,n[1]]}function To(e,t){return new bo({type:e,schema:null,validator:t})}function Mo(){return To("any",(()=>1))}function So(e){return new bo({type:"array",schema:e,*entries(t){if(e&&Array.isArray(t))for(const[r,o]of t.entries())yield[r,o,e]},coercer:e=>Array.isArray(e)?e.slice():e,validator:e=>Array.isArray(e)||`Expected an array value, but received: ${go(e)}`})}function Co(){return To("boolean",(e=>"boolean"==typeof e))}function ko(e){return To("instance",(t=>t instanceof e||`Expected a \`${e.name}\` instance, but received: ${go(t)}`))}function _o(e){const t=go(e);return new bo({type:"literal",schema:e,validator:r=>r===e||`Expected the literal \`${t}\`, but received: ${go(r)}`})}function Po(e){return new bo({...e,validator:(t,r)=>null===t||e.validator(t,r),refiner:(t,r)=>null===t||e.refiner(t,r)})}function Oo(){return To("number",(e=>"number"==typeof e&&!isNaN(e)||`Expected a number, but received: ${go(e)}`))}function Lo(){return To("string",(e=>"string"==typeof e||`Expected a string, but received: ${go(e)}`))}function No(e){const t=Object.keys(e);return new bo({type:"type",schema:e,*entries(r){if(fo(r))for(const o of t)yield[o,r[o],e[o]]},validator:e=>yo(e)||`Expected an object, but received: ${go(e)}`,coercer:e=>yo(e)?{...e}:e})}function Bo(e){const t=e.map((e=>e.type)).join(" | ");return new bo({type:"union",schema:null,coercer(t,r){for(const o of e){const[e,n]=o.validate(t,{coerce:1,mask:r.mask});if(!e)return n}return t},validator(r,o){const n=[];for(const t of e){const[...e]=xo(r,t,o),[s]=e;if(!s[0])return[];for(const[t]of e)t&&n.push(t)}return[`Expected the value to satisfy a union of \`${t}\`, but received: ${go(r)}`,...n]}})}function Ro(){return To("unknown",(()=>1))}function Do(e,t,r){return new bo({...e,coercer:(o,n)=>Ao(o,t)?e.coercer(r(o,n),n):e.coercer(o,n)})}const Uo=Do(ko(e.PublicKey),Lo(),(t=>new e.PublicKey(t))),Vo=Do(ko(Array),Lo(),(t=>Array.from(new e.PublicKey(t).toBytes()))),Fo=Do(ko(H),Lo(),(e=>Re(e,"base58"))),qo=Do(ko(H),Bo([Lo(),Oo()]),(e=>{if("number"==typeof e){if(!Number.isSafeInteger(e))throw new Error(`Unsafe integer. Precision loss: ${e}`);return Ue(e)}return Ue(e,10)})),Ko=Do(Lo(),Lo(),(e=>""===e?null:e));function Wo(e){return Bo([No({jsonrpc:_o("2.0"),id:Lo(),result:e}),No({jsonrpc:_o("2.0"),id:Lo(),error:No({code:Ro(),message:Lo(),data:Po(Mo())})})])}Do(Lo(),Lo(),(e=>""===e?null:e));const Ho=Wo(Ro());function $o(e){return Do(Wo(e),Ho,(t=>"error"in t?t:Object.assign(Object.assign({},t),{result:Io(t.result,e)})))}function zo(e){return $o(No({context:No({slot:Oo()}),value:e}))}const jo=No({treeType:Oo(),tree:Uo,queue:Uo,cpiContext:Po(Uo)}),Go=No({treeType:Oo(),tree:Uo,queue:Uo,cpiContext:Po(Uo),nextTreeContext:(Zo=Po(jo),new bo({...Zo,validator:(e,t)=>void 0===e||Zo.validator(e,t),refiner:(e,t)=>void 0===e||Zo.refiner(e,t)}))});var Zo;const Jo=No({address:Po(Vo),hash:Fo,data:Po(No({data:Ko,dataHash:Fo,discriminator:qo})),lamports:qo,owner:Uo,leafIndex:Oo(),tree:Uo,seq:Po(qo),slotCreated:qo}),Qo=No({address:Po(Vo),hash:Fo,data:Po(No({data:Ko,dataHash:Fo,discriminator:qo})),lamports:qo,owner:Uo,leafIndex:Oo(),seq:Po(qo),slotCreated:qo,merkleContext:Go,proveByIndex:Co()}),Xo=No({mint:Uo,owner:Uo,amount:qo,delegate:Po(Uo),state:Lo()}),Yo=No({tokenData:Xo,account:Jo}),en=No({tokenData:Xo,account:Qo}),tn=No({items:So(Jo)}),rn=No({items:So(Qo)}),on=No({items:So(Jo),cursor:Po(Lo())}),nn=No({items:So(Qo),cursor:Po(Lo())}),sn=No({items:So(Yo),cursor:Po(Lo())}),an=No({items:So(en),cursor:Po(Lo())}),un=Oo(),cn=Lo(),ln=No({items:So(No({signature:Lo(),slot:Oo(),blockTime:Oo(),error:Po(Lo())}))}),dn=No({items:So(No({signature:Lo(),slot:Oo(),blockTime:Oo()})),cursor:Po(Lo())}),pn=No({hash:Fo,leafIndex:Oo(),merkleTree:Uo,proof:So(Fo),rootSeq:Oo(),root:Fo}),hn=No({hash:Fo,leafIndex:Oo(),proof:So(Fo),root:Fo,rootSeq:Oo(),proveByIndex:Co(),treeContext:Go}),mn=No({address:Fo,nextIndex:Oo(),merkleTree:Uo,proof:So(Fo),rootSeq:Oo(),root:Fo,lowerRangeAddress:Fo,higherRangeAddress:Fo,lowElementLeafIndex:Oo()}),fn=No({a:So(Oo()),b:So(Oo()),c:So(Oo())}),yn=No({rootIndex:Oo(),proveByIndex:Co()}),gn=No({compressedProof:fn,leafIndices:So(Oo()),leaves:So(Fo),rootIndices:So(Oo()),roots:So(Fo),merkleTrees:So(Uo)}),wn=No({hash:Fo,root:Fo,rootIndex:yn,merkleContext:Go,leafIndex:Oo()}),vn=No({address:Fo,root:Fo,rootIndex:Oo(),merkleContext:Go}),xn=No({compressedProof:Po(fn),accounts:So(wn),addresses:So(vn)}),bn=So(pn),In=So(hn),An=No({amount:qo}),En=qo,Tn=No({balance:qo,mint:Uo}),Mn=No({tokenBalances:So(Tn),cursor:Po(Lo())}),Sn=No({items:So(Tn),cursor:Po(Lo())}),Cn=No({cursor:Po(Lo()),items:So(No({balance:qo,owner:Uo}))}),kn=No({hash:So(Oo()),root:So(Oo()),proof:So(So(Oo()))}),_n=No({items:So(No({blockTime:Oo(),signature:Lo(),slot:Oo()}))}),Pn=No({items:So(No({blockTime:Oo(),signature:Lo(),slot:Oo()})),cursor:Po(Lo())}),On=No({account:Qo,txHash:Fo,nullifier:Fo}),Ln=No({compressionInfo:No({closedAccounts:So(No({account:Jo,optionalTokenData:Po(Xo)})),openedAccounts:So(No({account:Jo,optionalTokenData:Po(Xo)}))}),transaction:Mo()}),Nn=No({compressionInfo:No({closedAccounts:So(No({account:On,optionalTokenData:Po(Xo)})),openedAccounts:So(No({account:Qo,optionalTokenData:Po(Xo)}))}),transaction:Mo()});function Bn({discriminator:e,data:r,dataHash:o}){const n=t.Buffer.from(e.toArray("le",8));return{discriminator:Array.from(n),data:t.Buffer.from(r,"base64"),dataHash:o.toArray("be",32)}}async function Rn(t,r,o,n=0){var s,i;const a=z(n?"getCompressedTokenAccountsByDelegate":"getCompressedTokenAccountsByOwner"),u=n?"delegate":"owner",c=await Un(t.compressionApiEndpoint,a,{[u]:r.toBase58(),mint:null===(s=o.mint)||void 0===s?void 0:s.toBase58(),limit:null===(i=o.limit)||void 0===i?void 0:i.toNumber(),cursor:o.cursor});let l;if(l=$.isV2()?Io(c,zo(an)):Io(c,zo(sn)),"error"in l)throw new e.SolanaJSONRPCError(l.error,`failed to get info for compressed accounts by ${u} ${r.toBase58()}`);if(null===l.result.value)throw new Error("not implemented: NULL result");const d=[],p=await t.getStateTreeInfos();return l.result.value.items.map((e=>{var t;const o=e.account,n=e.tokenData,s=$.isV2()?o.merkleContext.tree:o.tree,i=$.isV2()?o.proveByIndex:0,a=Dr(p,s),c=Fe(qe(a,o.hash,o.leafIndex,i),o.owner,Ue(o.lamports),o.data?Bn(o.data):void 0,o.address||void 0),l={mint:n.mint,owner:n.owner,amount:n.amount,delegate:n.delegate,state:["uninitialized","initialized","frozen"].indexOf(n.state),tlv:null};if((null===(t=l[u])||void 0===t?void 0:t.toBase58())!==r.toBase58())throw new Error(`RPC returned token account with ${u} different from requested ${u}`);d.push({compressedAccount:c,parsed:l})})),{items:d.sort(((e,t)=>t.compressedAccount.leafIndex-e.compressedAccount.leafIndex)),cursor:l.result.value.cursor}}function Dn(e){return e.replace(/(":\s*)(-?\d+)(\s*[},])/g,((e,t,r,o)=>{const n=Number(r);return!Number.isNaN(n)&&(n>Number.MAX_SAFE_INTEGER||n<Number.MIN_SAFE_INTEGER)?`${t}"${r}"${o}`:e}))}const Un=async(e,t,r=[],o=1,n=0)=>{const s=JSON.stringify({jsonrpc:"2.0",id:"test-account",method:t,params:r});if(n){const t=()=>{const t=s.replace(/"/g,'\\"');return`curl -X POST ${e} \\\n -H "Content-Type: application/json" \\\n -d "${t}"`};console.log("Debug: Stack trace:"),console.log((new Error).stack),console.log("\nDebug: curl:"),console.log(t()),console.log("\n")}const i=await fetch(e,{method:"POST",headers:{"Content-Type":"application/json"},body:s});if(!i.ok)throw new Error(`HTTP error! status: ${i.status}`);const a=Dn(await i.text());return o?gr(JSON.parse(a)):JSON.parse(a)},Vn=async(e,t,r=[],o=0)=>{let n,s="";o&&(s=`Proof generation for method:${t}`,console.time(s)),"inclusion"===t?n=JSON.stringify({circuitType:"inclusion",stateTreeHeight:26,inputCompressedAccounts:r}):"new-address"===t?n=JSON.stringify({circuitType:"non-inclusion",addressTreeHeight:26,newAddresses:r}):"combined"===t&&(n=JSON.stringify({circuitType:"combined",stateTreeHeight:26,addressTreeHeight:26,inputCompressedAccounts:r[0],newAddresses:r[1]}));const i=await fetch(`${e}/prove`,{method:"POST",headers:{"Content-Type":"application/json"},body:n});if(!i.ok)throw new Error(`Error fetching proof: ${i.statusText}`);const a=kr(Cr(await i.json()));return o&&console.timeEnd(s),a};function Fn(e){const t=[];for(let r=0;r<e.length;r++){const o={root:fr(e[r].root),pathIndex:e[r].leafIndex,pathElements:e[r].merkleProof.map((e=>fr(e))),leaf:fr(Ue(e[r].hash))};t.push(o)}return t}function qn(e){const t=[];for(let r=0;r<e.length;r++){const o={root:fr(e[r].root),value:fr(e[r].value),pathIndex:e[r].indexHashedIndexedElementLeaf.toNumber(),pathElements:e[r].merkleProofHashedIndexedElementLeaf.map((e=>fr(e))),nextIndex:e[r].nextIndex.toNumber(),leafLowerRangeValue:fr(e[r].leafLowerRangeValue),leafHigherRangeValue:fr(e[r].leafHigherRangeValue)};t.push(o)}return t}function Kn(e,t,r){if(e.length!==t.length)throw new Error("Input lengths must match.");if(0===e.length)return Ue(0);let o=r.poseidonHashBN([e[0].toString(),t[0].toString()]);for(let n=1;n<e.length;n++)o=r.poseidonHashBN([o.toString(),e[n].toString(),t[n].toString()]);return o}function Wn(e){const t=e.account,r=e.optionalTokenData,o=Fe(qe(t.treeInfo,t.hash.toArray("be",32),t.leafIndex,t.proveByIndex),t.owner,Ue(t.lamports),t.data?Bn(t.data):void 0,t.address||void 0);return null===r?{account:o,maybeTokenData:null}:{account:o,maybeTokenData:{mint:r.mint,owner:r.owner,amount:r.amount,delegate:r.delegate,state:["uninitialized","initialized","frozen"].indexOf(r.state),tlv:null}}}class Hn extends e.Connection{constructor(e,t,r,o){super(e,o||"confirmed"),this.allStateTreeInfos=null,this.lastStateTreeFetchTime=null,this.CACHE_TTL=36e5,this.fetchPromise=null,this.compressionApiEndpoint=t,this.proverEndpoint=r}async getCachedActiveStateTreeInfo(){}async getCachedActiveStateTreeInfos(){}async getStateTreeInfos(){if(ue(this.rpcEndpoint))return ce();if(this.allStateTreeInfos&&this.lastStateTreeFetchTime&&Date.now()-this.lastStateTreeFetchTime<=this.CACHE_TTL)return this.allStateTreeInfos;if(this.fetchPromise)return this.fetchPromise;let e;try{return this.fetchPromise=this.doFetch(),e=await this.fetchPromise,this.allStateTreeInfos=e,this.lastStateTreeFetchTime=Date.now(),e}finally{this.fetchPromise=null}}async doFetch(){const{mainnet:e,devnet:t}=ae();try{return await Fr({connection:this,stateTreeLUTPairs:[e[0]]})}catch(e){try{return await Fr({connection:this,stateTreeLUTPairs:[t[0]]})}catch(t){throw new Error(`Failed to fetch state tree infos from both mainnet and devnet. Mainnet error: ${e}. Devnet error: ${t}`)}}}async getCompressedAccount(t,r){if(!r&&!t)throw new Error("Either hash or address must be provided");if(r&&t)throw new Error("Only one of hash or address must be provided");const o=await this.getStateTreeInfos(),n=await Un(this.compressionApiEndpoint,z("getCompressedAccount"),{hash:r?De(r):void 0,address:t?De(t):void 0});let s;if(s=$.isV2()?Io(n,zo(Po(Qo))):Io(n,zo(Po(Jo))),"error"in s)throw new e.SolanaJSONRPCError(s.error,`failed to get info for compressed account ${r?r.toString():t?t.toString():""}`);if(null===s.result.value)return null;const i=Dr(o,$.isV2()?s.result.value.merkleContext.tree:s.result.value.tree),a=s.result.value;return Fe(qe(i,a.hash,a.leafIndex),a.owner,Ue(a.lamports),a.data?Bn(a.data):void 0,a.address||void 0)}async getCompressedBalance(t,r){if(!r&&!t)throw new Error("Either hash or address must be provided");if(r&&t)throw new Error("Only one of hash or address must be provided");const o=Io(await Un(this.compressionApiEndpoint,"getCompressedBalance",{hash:r?De(r):void 0,address:t?De(t):void 0}),zo(En));if("error"in o)throw new e.SolanaJSONRPCError(o.error,`failed to get balance for compressed account ${r?r.toString():t?t.toString():""}`);return null===o.result.value?Ue(0):Ue(o.result.value)}async getCompressedBalanceByOwner(t){const r=Io(await Un(this.compressionApiEndpoint,"getCompressedBalanceByOwner",{owner:t.toBase58()}),zo(En));if("error"in r)throw new e.SolanaJSONRPCError(r.error,`failed to get balance for compressed account ${t.toBase58()}`);return null===r.result.value?Ue(0):Ue(r.result.value)}async getCompressedAccountProof(t){const r=await Un(this.compressionApiEndpoint,z("getCompressedAccountProof"),{hash:De(t)});let o;if(o=$.isV2()?Io(r,zo(hn)):Io(r,zo(pn)),"error"in o)throw new e.SolanaJSONRPCError(o.error,`failed to get proof for compressed account ${t.toString()}`);if(null===o.result.value)throw new Error(`failed to get proof for compressed account ${t.toString()}`);const n=Dr(await this.getStateTreeInfos(),$.isV2()?o.result.value.treeContext.tree:o.result.value.tree);return{hash:Ue(o.result.value.hash.toArray("be",32)),treeInfo:n,leafIndex:o.result.value.leafIndex,merkleProof:o.result.value.proof,rootIndex:o.result.value.rootSeq%2400,root:o.result.value.root,proveByIndex:$.isV2()?o.result.value.proveByIndex:0}}async getMultipleCompressedAccounts(t){const r=await Un(this.compressionApiEndpoint,z("getMultipleCompressedAccounts"),{hashes:t.map((e=>De(e)))});let o;if(o=$.isV2()?Io(r,zo(rn)):Io(r,zo(tn)),"error"in o)throw new e.SolanaJSONRPCError(o.error,`failed to get info for compressed accounts ${t.map((e=>De(e))).join(", ")}`);if(null===o.result.value)throw new Error(`failed to get info for compressed accounts ${t.map((e=>De(e))).join(", ")}`);const n=await this.getStateTreeInfos(),s=[];return o.result.value.items.map((e=>{const t=$.isV2()?e.merkleContext.tree:e.tree,r=Dr(n,t),o=Fe(qe(r,Ue(e.hash.toArray("be",32)),e.leafIndex),e.owner,Ue(e.lamports),e.data?Bn(e.data):void 0,e.address||void 0);s.push(o)})),s.sort(((e,t)=>t.leafIndex-e.leafIndex))}async getMultipleCompressedAccountProofs(t){const r=await Un(this.compressionApiEndpoint,z("getMultipleCompressedAccountProofs"),t.map((e=>De(e))));let o;if(o=$.isV2()?Io(r,zo(So(hn))):Io(r,zo(So(pn))),"error"in o)throw new e.SolanaJSONRPCError(o.error,`failed to get proofs for compressed accounts ${t.map((e=>De(e))).join(", ")}`);if(null===o.result.value)throw new Error(`failed to get proofs for compressed accounts ${t.map((e=>De(e))).join(", ")}`);const n=[],s=await this.getStateTreeInfos();for(const e of o.result.value){const t=Dr(s,$.isV2()?e.treeContext.tree:e.merkleTree),r={hash:Ue(e.hash.toArray("be",32)),treeInfo:t,leafIndex:e.leafIndex,merkleProof:e.proof,rootIndex:e.rootSeq%2400,root:e.root,proveByIndex:$.isV2()?e.proveByIndex:0};n.push(r)}return n}async getCompressedAccountsByOwner(t,r){var o;const n=await Un(this.compressionApiEndpoint,z("getCompressedAccountsByOwner"),{owner:t.toBase58(),filters:(null==r?void 0:r.filters)||[],dataSlice:null==r?void 0:r.dataSlice,cursor:null==r?void 0:r.cursor,limit:null===(o=null==r?void 0:r.limit)||void 0===o?void 0:o.toNumber()});let s;if(s=$.isV2()?Io(n,zo(nn)):Io(n,zo(on)),"error"in s)throw new e.SolanaJSONRPCError(s.error,`failed to get info for compressed accounts owned by ${t.toBase58()}`);if(null===s.result.value)return{items:[],cursor:null};const i=[],a=await this.getStateTreeInfos();return s.result.value.items.map((e=>{const t=Dr(a,$.isV2()?e.merkleContext.tree:e.tree),r=Fe(qe(t,Ue(e.hash.toArray("be",32)),e.leafIndex,$.isV2()?e.proveByIndex:0),e.owner,Ue(e.lamports),e.data?Bn(e.data):void 0,e.address||void 0);i.push(r)})),{items:i.sort(((e,t)=>t.leafIndex-e.leafIndex)),cursor:s.result.value.cursor}}async getCompressedTokenAccountsByOwner(e,t){return t||(t={}),await Rn(this,e,t,0)}async getCompressedTokenAccountsByDelegate(e,t){return t||(t={}),await Rn(this,e,t,1)}async getCompressedTokenAccountBalance(t){const r=Io(await Un(this.compressionApiEndpoint,"getCompressedTokenAccountBalance",{hash:De(t)}),zo(An));if("error"in r)throw new e.SolanaJSONRPCError(r.error,`failed to get balance for compressed token account ${t.toString()}`);if(null===r.result.value)throw new Error(`failed to get balance for compressed token account ${t.toString()}`);return{amount:Ue(r.result.value.amount)}}async getCompressedTokenBalancesByOwner(t,r){var o,n;r||(r={});const s=Io(await Un(this.compressionApiEndpoint,"getCompressedTokenBalancesByOwner",{owner:t.toBase58(),mint:null===(o=r.mint)||void 0===o?void 0:o.toBase58(),limit:null===(n=r.limit)||void 0===n?void 0:n.toNumber(),cursor:r.cursor}),zo(Mn));if("error"in s)throw new e.SolanaJSONRPCError(s.error,`failed to get compressed token balances for owner ${t.toBase58()}`);if(null===s.result.value)throw new Error(`failed to get compressed token balances for owner ${t.toBase58()}`);return{items:r.mint?s.result.value.tokenBalances.filter((e=>e.mint.toBase58()===r.mint.toBase58())):s.result.value.tokenBalances,cursor:s.result.value.cursor}}async getCompressedTokenBalancesByOwnerV2(t,r){var o,n;r||(r={});const s=Io(await Un(this.compressionApiEndpoint,"getCompressedTokenBalancesByOwnerV2",{owner:t.toBase58(),mint:null===(o=r.mint)||void 0===o?void 0:o.toBase58(),limit:null===(n=r.limit)||void 0===n?void 0:n.toNumber(),cursor:r.cursor}),zo(Sn));if("error"in s)throw new e.SolanaJSONRPCError(s.error,`failed to get compressed token balances for owner ${t.toBase58()}`);if(null===s.result.value)throw new Error(`failed to get compressed token balances for owner ${t.toBase58()}`);const i=r.mint?s.result.value.items.filter((e=>e.mint.toBase58()===r.mint.toBase58())):s.result.value.items;return{context:s.result.context,value:{items:i,cursor:s.result.value.cursor}}}async getCompressionSignaturesForAccount(t){const r=Io(await Un(this.compressionApiEndpoint,"getCompressionSignaturesForAccount",{hash:De(t)}),zo(_n));if("error"in r)throw new e.SolanaJSONRPCError(r.error,`failed to get signatures for compressed account ${t.toString()}`);return r.result.value.items}async getTransactionWithCompressionInfo(t){const r=await Un(this.compressionApiEndpoint,z("getTransactionWithCompressionInfo"),{signature:t});let o;if(o=$.isV2()?Io(r,$o(Nn)):Io(r,$o(Ln)),"error"in o)throw new e.SolanaJSONRPCError(o.error,"failed to get slot");if(null===o.result.transaction)return null;const n=[],s=[],i=await this.getStateTreeInfos();$.isV2()?(o.result.compressionInfo.closedAccounts.map((e=>{n.push(function(e){const t={account:e.account.account,optionalTokenData:e.optionalTokenData},r={nullifier:e.account.nullifier,txHash:e.account.txHash},o=Wn(t);return{account:o.account,maybeTokenData:o.maybeTokenData,maybeNullifierMetadata:r}}(e))})),o.result.compressionInfo.openedAccounts.map((e=>{s.push(Wn(e))}))):(o.result.compressionInfo.closedAccounts.map((e=>{const t=Dr(i,e.account.tree),r=Fe(qe(t,Ue(e.account.hash.toArray("be",32)),e.account.leafIndex),e.account.owner,Ue(e.account.lamports),e.account.data?Bn(e.account.data):void 0,e.account.address||void 0);n.push({account:r,maybeTokenData:e.optionalTokenData})})),o.result.compressionInfo.openedAccounts.map((e=>{const t=Dr(i,e.account.tree),r=Fe(qe(t,Ue(e.account.hash.toArray("be",32)),e.account.leafIndex),e.account.owner,Ue(e.account.lamports),e.account.data?Bn(e.account.data):void 0,e.account.address||void 0);s.push({account:r,maybeTokenData:e.optionalTokenData})})));const a=e=>{const t=Object.values(e.reduce(((e,{maybeTokenData:t})=>{if(t){const{owner:r,mint:o,amount:n}=t,s=`${r.toBase58()}_${o.toBase58()}`;s in e?e[s].amount=e[s].amount.add(n):e[s]={owner:r,mint:o,amount:n}}return e}),{}));return t.length>0?t:void 0},u=a(n),c=a(s);return{compressionInfo:{closedAccounts:n,openedAccounts:s,preTokenBalances:u,postTokenBalances:c},transaction:o.result.transaction}}async getCompressionSignaturesForAddress(t,r){var o;const n=Io(await Un(this.compressionApiEndpoint,"getCompressionSignaturesForAddress",{address:t.toBase58(),cursor:null==r?void 0:r.cursor,limit:null===(o=null==r?void 0:r.limit)||void 0===o?void 0:o.toNumber()}),zo(Pn));if("error"in n)throw new e.SolanaJSONRPCError(n.error,`failed to get signatures for address ${t.toBase58()}`);if(null===n.result.value)throw new Error(`failed to get signatures for address ${t.toBase58()}`);return n.result.value}async getCompressionSignaturesForOwner(t,r){var o;const n=Io(await Un(this.compressionApiEndpoint,"getCompressionSignaturesForOwner",{owner:t.toBase58(),cursor:null==r?void 0:r.cursor,limit:null===(o=null==r?void 0:r.limit)||void 0===o?void 0:o.toNumber()}),zo(Pn));if("error"in n)throw new e.SolanaJSONRPCError(n.error,`failed to get signatures for owner ${t.toBase58()}`);if(null===n.result.value)throw new Error(`failed to get signatures for owner ${t.toBase58()}`);return n.result.value}async getCompressionSignaturesForTokenOwner(t,r){var o;const n=Io(await Un(this.compressionApiEndpoint,"getCompressionSignaturesForTokenOwner",{owner:t.toBase58(),cursor:null==r?void 0:r.cursor,limit:null===(o=null==r?void 0:r.limit)||void 0===o?void 0:o.toNumber()}),zo(Pn));if("error"in n)throw new e.SolanaJSONRPCError(n.error,`failed to get signatures for owner ${t.toBase58()}`);if(null===n.result.value)throw new Error(`failed to get signatures for owner ${t.toBase58()}`);return n.result.value}async getIndexerHealth(){const t=Io(await Un(this.compressionApiEndpoint,"getIndexerHealth"),$o(cn));if("error"in t)throw new e.SolanaJSONRPCError(t.error,"failed to get health");return t.result}async confirmTransactionIndexed(e){const t=ue(this.rpcEndpoint)?1e4:2e4,r=ue(this.rpcEndpoint)?100:200,o=Date.now();for(;;){if(await this.getIndexerSlot()>=e)return 1;if(Date.now()-o>t)throw new Error(`Timeout: Indexer slot did not reach the required slot within ${t/1e3}s`);await new Promise((e=>setTimeout(e,r)))}}async getIndexerSlot(){const t=Io(await Un(this.compressionApiEndpoint,"getIndexerSlot"),$o(un));if("error"in t)throw new e.SolanaJSONRPCError(t.error,"failed to get slot");return t.result}async getCompressedMintTokenHolders(t,r){var o;const n=Io(await Un(this.compressionApiEndpoint,"getCompressedMintTokenHolders",{mint:t.toBase58(),cursor:null==r?void 0:r.cursor,limit:null===(o=null==r?void 0:r.limit)||void 0===o?void 0:o.toNumber()}),zo(Cn));if("error"in n)throw new e.SolanaJSONRPCError(n.error,"failed to get mint token holders");return n.result}async getLatestCompressionSignatures(t,r){const o=Io(await Un(this.compressionApiEndpoint,"getLatestCompressionSignatures",{limit:r,cursor:t}),zo(dn));if("error"in o)throw new e.SolanaJSONRPCError(o.error,"failed to get latest non-voting signatures");return o.result}async getLatestNonVotingSignatures(t,r){const o=Io(await Un(this.compressionApiEndpoint,"getLatestNonVotingSignatures",{limit:t,cursor:r}),zo(ln));if("error"in o)throw new e.SolanaJSONRPCError(o.error,"failed to get latest non-voting signatures");return o.result}async getMultipleNewAddressProofs(t){const r=Io(await Un(this.compressionApiEndpoint,"getMultipleNewAddressProofs",t.map((e=>De(e)))),zo(So(mn)));if("error"in r)throw new e.SolanaJSONRPCError(r.error,`failed to get proofs for new addresses ${t.map((e=>De(e))).join(", ")}`);if(null===r.result.value)throw new Error(`failed to get proofs for new addresses ${t.map((e=>De(e))).join(", ")}`);const o=[];for(const e of r.result.value){const t={root:e.root,rootIndex:e.rootSeq%2400,value:e.address,leafLowerRangeValue:e.lowerRangeAddress,leafHigherRangeValue:e.higherRangeAddress,nextIndex:Ue(e.nextIndex),merkleProofHashedIndexedElementLeaf:e.proof,indexHashedIndexedElementLeaf:Ue(e.lowElementLeafIndex),treeInfo:{tree:e.merkleTree,queue:de().addressQueue,treeType:exports.TreeType.AddressV1,nextTreeInfo:null}};o.push(t)}return o}async getValidityProof(e=[],t=[]){const r=await this.getMultipleCompressedAccounts(e),o=r.map((e=>e.treeInfo.tree)),n=r.map((e=>e.treeInfo.queue)),s=de().addressTree,i=de().addressQueue,a=e.map(((e,t)=>({hash:e,tree:o[t],queue:n[t]}))),u=t.map((e=>({address:e,tree:s,queue:i})));return this.getValidityProofV0(a,u)}async getValidityProofV0(e=[],t=[]){const{value:r}=await this.getValidityProofAndRpcContext(e,t);return r}async getValidityProofAndRpcContext(t=[],r=[]){It(t.length,r.length);const o=await Un(this.compressionApiEndpoint,z("getValidityProof"),{hashes:t.map((({hash:e})=>De(e))),newAddressesWithTrees:r.map((({address:e,tree:t})=>({address:De(e),tree:t.toBase58()})))});let n;if(n=$.isV2()?Io(o,zo(xn)):Io(o,zo(gn)),"error"in n)throw new e.SolanaJSONRPCError(n.error,`failed to get validity proof for hashes ${t.map((e=>e.hash.toString())).join(", ")}`);if(null===n.result.value)throw new Error(`failed to get validity proof for hashes ${t.map((e=>e.hash.toString())).join(", ")}`);const s=n.result.value;if($.isV2())return{value:{compressedProof:s.compressedProof,leaves:s.accounts.map((e=>e.hash)).concat(s.addresses.map((e=>e.address))),roots:s.accounts.map((e=>e.root)).concat(s.addresses.map((e=>e.root))),rootIndices:s.accounts.map((e=>e.rootIndex.rootIndex)).concat(s.addresses.map((e=>e.rootIndex))),proveByIndices:s.accounts.map((e=>e.rootIndex.proveByIndex)).concat(s.addresses.map((()=>0))),treeInfos:s.accounts.map((e=>e.merkleContext)).concat(s.addresses.map((e=>e.merkleContext))),leafIndices:s.accounts.map((e=>e.leafIndex)).concat(s.addresses.map((()=>0)))},context:n.result.context};{const e=await this.getStateTreeInfos(),t=s.merkleTrees.map((t=>t.equals(de().addressTree)?{tree:t,queue:de().addressQueue,treeType:exports.TreeType.AddressV1,nextTreeInfo:null}:Ur(e,t)));return{value:{compressedProof:s.compressedProof,roots:s.roots,rootIndices:s.rootIndices.map((e=>e)),leafIndices:s.leafIndices,leaves:s.leaves,treeInfos:t,proveByIndices:s.rootIndices.map((e=>e.proveByIndex))},context:n.result.context}}}async getCompressibleAccountInfo(e,r,o,n){const s=br(e.toBytes(),o.tree.toBytes(),r.toBytes()),[i,a]=await Promise.allSettled([n.getAccountInfo(e),n.getCompressedAccount(Ue(Array.from(s)))]),u="fulfilled"===i.status?i.value:null,c="fulfilled"===a.status?a.value:null;return u?{accountInfo:u,merkleContext:void 0}:c&&c.data&&c.data.data.length>0?{accountInfo:{executable:0,owner:c.owner,lamports:c.lamports.toNumber(),data:t.Buffer.concat([t.Buffer.from(c.data.discriminator),c.data.data])},merkleContext:{treeInfo:o,hash:c.hash,leafIndex:c.leafIndex,proveByIndex:c.proveByIndex}}:null}}class $n extends e.Connection{constructor(e,t,r,o,n,s){super(e,n||"confirmed"),this.log=0,this.allStateTreeInfos=null,this.lastStateTreeFetchTime=null,this.fetchPromise=null,this.CACHE_TTL=36e5,this.compressionApiEndpoint=r,this.proverEndpoint=o;const{depth:i,log:a}=null!=s?s:{},{merkleTreeHeight:u}=de();this.lightWasm=t,this.depth=null!=i?i:u,this.log=null!=a?a:0}async getCachedActiveStateTreeInfo(){}async getCachedActiveStateTreeInfos(){}async getStateTreeInfos(){return ce()}async doFetch(){throw new Error("doFetch not supported in test-rpc")}async getCompressedAccount(e,t){if(e)throw new Error("address is not supported in test-rpc");if(!t)throw new Error("hash is required");const r=await so(this,t);return null!=r?r:null}async getCompressedBalance(e,t){if(e)throw new Error("address is not supported in test-rpc");if(!t)throw new Error("hash is required");const r=await so(this,t);if(!r)throw new Error("Account not found");return Ue(r.lamports)}async getCompressedBalanceByOwner(e){return(await this.getCompressedAccountsByOwner(e)).items.reduce(((e,t)=>e.add(t.lamports)),Ue(0))}async getCompressedAccountProof(e){return(await this.getMultipleCompressedAccountProofs([e]))[0]}async getMultipleCompressedAccounts(e){return await async function(e,t){return(await io(e)).filter((e=>t.some((t=>Ue(e.hash).eq(t))))).sort(((e,t)=>t.leafIndex-e.leafIndex))}(this,e)}async confirmTransactionIndexed(e){return 1}async getMultipleCompressedAccountProofs(t){const r=await to(this).then((e=>e.reverse())),o=new Map,n=await this.getStateTreeInfos();for(const e of r)for(let t=0;t<e.outputCompressedAccounts.length;t++){const r=e.outputCompressedAccountHashes[t],s=Dr(n,e.pubkeyArray[e.outputCompressedAccounts[t].merkleTreeIndex]);o.has(s.tree.toBase58())||o.set(s.tree.toBase58(),{leaves:[],leafIndices:[],treeInfo:s});const i=o.get(s.tree.toBase58());if(!i)throw new Error(`Tree not found: ${s.tree.toBase58()}`);i.leaves.push(r),i.leafIndices.push(e.outputLeafIndices[t])}const s=new Map;for(const[r,{leaves:n,treeInfo:i}]of o.entries()){const a=new e.PublicKey(r);let u;if(i.treeType===exports.TreeType.StateV1)u=new eo(this.depth,this.lightWasm,n.map((e=>Ue(e).toString())));else{if(i.treeType!==exports.TreeType.StateV2)throw new Error(`Invalid tree type: ${i.treeType} in test-rpc.ts`);u=new eo(32,this.lightWasm,[])}for(let e=0;e<t.length;e++){const r=n.findIndex((r=>Ue(r).eq(t[e])));if(-1!==r)if(i.treeType===exports.TreeType.StateV1){const o=u.path(r).pathElements.map((e=>Ue(e))),a=Ue(u.root()),c={hash:Ue(t[e].toArray("be",32)),treeInfo:i,leafIndex:r,merkleProof:o,proveByIndex:0,rootIndex:n.length,root:a};s.set(t[e].toString(),c)}else if(i.treeType===exports.TreeType.StateV2){const r=u._zeros.slice(0,-1).map((e=>Ue(e))),n=Ue(u.root()),c=o.get(a.toBase58()).leafIndices.findIndex((r=>t[e].eq(Ue(o.get(a.toBase58()).leaves[r])))),l={hash:Ue(t[e].toArray("be",32)),treeInfo:i,leafIndex:c,merkleProof:r,proveByIndex:1,rootIndex:0,root:n};s.set(t[e].toString(),l)}}}if(s.forEach(((e,t)=>{if(e.treeInfo.treeType===exports.TreeType.StateV1){const r=e.leafIndex,n=o.get(e.treeInfo.tree.toBase58()).leaves[r],s=Ue(n);if(!s.eq(e.hash))throw new Error(`Mismatch at index ${t}: expected ${e.hash.toString()}, got ${s.toString()}`)}})),new Set(t.map((e=>{const t=s.get(e.toString());if(!t)throw new Error(`Proof not found for hash: ${e.toString()}`);return t.treeInfo.treeType}))).size>1)throw new Error("Requested hashes belong to different tree types (V1/V2)");return t.map((e=>{const t=s.get(e.toString());if(!t)throw new Error(`No proof found for hash: ${e.toString()}`);return t}))}async getCompressedAccountsByOwner(e,t){const r=await async function(e,t){return(await io(e)).filter((e=>e.owner.equals(t)))}(this,e);return{items:r,cursor:null}}async getLatestCompressionSignatures(e,t){throw new Error("getLatestNonVotingSignaturesWithContext not supported in test-rpc")}async getLatestNonVotingSignatures(e){throw new Error("getLatestNonVotingSignaturesWithContext not supported in test-rpc")}async getCompressedTokenAccountsByOwner(e,t){return await lo(this,e,t.mint)}async getCompressedTokenAccountsByDelegate(e,t){return await po(this,e,t.mint)}async getCompressedTokenAccountBalance(e){const t=await ho(this,e);return{amount:Ue(t.parsed.amount)}}async getCompressedTokenBalancesByOwner(e,t){return{items:(await lo(this,e,t.mint)).items.map((e=>({balance:Ue(e.parsed.amount),mint:e.parsed.mint}))),cursor:null}}async getCompressedTokenBalancesByOwnerV2(e,t){return{context:{slot:1},value:{items:(await lo(this,e,t.mint)).items.map((e=>({balance:Ue(e.parsed.amount),mint:e.parsed.mint}))),cursor:null}}}async getCompressionSignaturesForAccount(e){throw new Error("getCompressionSignaturesForAccount not implemented in test-rpc")}async getTransactionWithCompressionInfo(e){throw new Error("getCompressedTransaction not implemented in test-rpc")}async getCompressionSignaturesForAddress(e,t){throw new Error("getSignaturesForAddress3 not implemented")}async getCompressionSignaturesForOwner(e,t){throw new Error("getSignaturesForOwner not implemented")}async getCompressionSignaturesForTokenOwner(e,t){throw new Error("getSignaturesForTokenOwner not implemented")}async getIndexerHealth(){return"ok"}async getIndexerSlot(){return 1}async getMultipleNewAddressProofs(e){const t=Yr.default(),r=[];t.init();const o=[];for(let e=0;e<r.length;e++)t.append(Ue(r[e]));for(let e=0;e<t.elements.length;e++){const r=t.hashElement(this.lightWasm,e);o.push(Ue(r))}const n=new eo(this.depth,this.lightWasm,o.map((e=>Ue(e).toString()))),s=[];for(let r=0;r<e.length;r++){const[o]=t.findLowElement(e[r]);if(!o)throw new Error("Address not found");const i=o.index,a=n.path(i).pathElements.map((e=>Ue(e))),u=t.get(o.nextIndex).value,c={root:Ue(n.root()),rootIndex:3,value:e[r],leafLowerRangeValue:o.value,leafHigherRangeValue:u,nextIndex:Ue(o.nextIndex),merkleProofHashedIndexedElementLeaf:a,indexHashedIndexedElementLeaf:Ue(o.index),treeInfo:{tree:de().addressTree,queue:de().addressQueue,treeType:exports.TreeType.AddressV1,nextTreeInfo:null}};s.push(c)}return s}async getCompressedMintTokenHolders(e,t){throw new Error("getCompressedMintTokenHolders not implemented in test-rpc")}async getValidityProofAndRpcContext(e=[],t=[]){if(t.some((e=>!(e instanceof H))))throw new Error("AddressWithTree is not supported in test-rpc");return{value:await this.getValidityProofV0(e,t),context:{slot:1}}}async getValidityProof(e=[],t=[]){if(t.some((e=>!(e instanceof H))))throw new Error("AddressWithTree is not supported in test-rpc");let r;const o=[];if(0===e.length&&0===t.length)throw new Error("Empty input. Provide hashes and/or new addresses.");if(e.length>0&&0===t.length){for(const t of e){const e=await this.getCompressedAccount(void 0,t);if(!e)throw new Error("Account not found");o.push(e.treeInfo)}const t=o.some((e=>e.treeType===exports.TreeType.StateV1)),n=await this.getMultipleCompressedAccountProofs(e);if(t){const e=Fn(n);r={compressedProof:await Vn(this.proverEndpoint,"inclusion",e,this.log),roots:n.map((e=>e.root)),rootIndices:n.map((e=>e.rootIndex)),leafIndices:n.map((e=>e.leafIndex)),leaves:n.map((e=>Ue(e.hash))),treeInfos:n.map((e=>e.treeInfo)),proveByIndices:n.map((e=>e.proveByIndex))}}else r={compressedProof:null,roots:n.map((()=>Ue(0))),rootIndices:n.map((e=>e.rootIndex)),leafIndices:n.map((e=>e.leafIndex)),leaves:n.map((e=>Ue(e.hash))),treeInfos:n.map((e=>e.treeInfo)),proveByIndices:n.map((e=>e.proveByIndex))}}else if(0===e.length&&t.length>0){const e=await this.getMultipleNewAddressProofs(t),o=qn(e);r={compressedProof:await Vn(this.proverEndpoint,"new-address",o,this.log),roots:e.map((e=>e.root)),rootIndices:e.map((()=>3)),leafIndices:e.map((e=>e.indexHashedIndexedElementLeaf.toNumber())),leaves:e.map((e=>Ue(e.value))),treeInfos:e.map((e=>e.treeInfo)),proveByIndices:e.map((()=>0))}}else{if(!(e.length>0&&t.length>0))throw new Error("Invalid input");{const o=await this.getMultipleCompressedAccountProofs(e),n=await this.getMultipleNewAddressProofs(t),s=o.map((e=>e.treeInfo)).some((e=>e.treeType===exports.TreeType.StateV1)),i=qn(n);let a;if(s){const e=Fn(o);a=await Vn(this.proverEndpoint,"combined",[e,i],1)}else a=await Vn(this.proverEndpoint,"new-address",i,1);r={compressedProof:a,roots:o.map((e=>s?e.root:Ue(0))).concat(n.map((e=>e.root))),rootIndices:o.map((e=>e.rootIndex)).concat(n.map((()=>3))),leafIndices:o.map((e=>e.leafIndex)).concat(n.map((e=>e.indexHashedIndexedElementLeaf.toNumber()))),leaves:o.map((e=>Ue(e.hash))).concat(n.map((e=>Ue(e.value)))),treeInfos:o.map((e=>e.treeInfo)).concat(n.map((e=>e.treeInfo))),proveByIndices:o.map((e=>e.proveByIndex)).concat(n.map((()=>0)))}}}return r}async getValidityProofV0(e=[],t=[]){return this.getValidityProof(e.map((e=>e.hash)),t.map((e=>e.address)))}async getCompressibleAccountInfo(e,t,r,o){throw new Error("getCompressibleAccountInfo not implemented in test-rpc")}}let zn=1;const jn=Qn(255),Gn=Qn(254),Zn=Qn(253),Jn=Qn(252);function Qn(t){if(t||(t=zn,zn++),t>255)return e.Keypair.generate();const r=new Uint8Array(32);return r[31]=t,e.Keypair.fromSeed(r)}var Xn,Yn,es,ts,rs,os,ns,ss;exports.UtxoErrorCode=void 0,(Xn=exports.UtxoErrorCode||(exports.UtxoErrorCode={})).NEGATIVE_LAMPORTS="NEGATIVE_LAMPORTS",Xn.NOT_U64="NOT_U64",Xn.BLINDING_EXCEEDS_FIELD_SIZE="BLINDING_EXCEEDS_FIELD_SIZE",exports.SelectInUtxosErrorCode=void 0,(Yn=exports.SelectInUtxosErrorCode||(exports.SelectInUtxosErrorCode={})).FAILED_TO_FIND_UTXO_COMBINATION="FAILED_TO_FIND_UTXO_COMBINATION",Yn.INVALID_NUMBER_OF_IN_UTXOS="INVALID_NUMBER_OF_IN_UTXOS",exports.CreateUtxoErrorCode=void 0,(es=exports.CreateUtxoErrorCode||(exports.CreateUtxoErrorCode={})).OWNER_UNDEFINED="OWNER_UNDEFINED",es.INVALID_OUTPUT_UTXO_LENGTH="INVALID_OUTPUT_UTXO_LENGTH",es.UTXO_DATA_UNDEFINED="UTXO_DATA_UNDEFINED",exports.RpcErrorCode=void 0,(ts=exports.RpcErrorCode||(exports.RpcErrorCode={})).CONNECTION_UNDEFINED="CONNECTION_UNDEFINED",ts.RPC_PUBKEY_UNDEFINED="RPC_PUBKEY_UNDEFINED",ts.RPC_METHOD_NOT_IMPLEMENTED="RPC_METHOD_NOT_IMPLEMENTED",ts.RPC_INVALID="RPC_INVALID",exports.LookupTableErrorCode=void 0,(rs=exports.LookupTableErrorCode||(exports.LookupTableErrorCode={})).LOOK_UP_TABLE_UNDEFINED="LOOK_UP_TABLE_UNDEFINED",rs.LOOK_UP_TABLE_NOT_INITIALIZED="LOOK_UP_TABLE_NOT_INITIALIZED",exports.HashErrorCode=void 0,(exports.HashErrorCode||(exports.HashErrorCode={})).NO_POSEIDON_HASHER_PROVIDED="NO_POSEIDON_HASHER_PROVIDED",exports.ProofErrorCode=void 0,(os=exports.ProofErrorCode||(exports.ProofErrorCode={})).INVALID_PROOF="INVALID_PROOF",os.PROOF_INPUT_UNDEFINED="PROOF_INPUT_UNDEFINED",os.PROOF_GENERATION_FAILED="PROOF_GENERATION_FAILED",exports.MerkleTreeErrorCode=void 0,(ns=exports.MerkleTreeErrorCode||(exports.MerkleTreeErrorCode={})).MERKLE_TREE_NOT_INITIALIZED="MERKLE_TREE_NOT_INITIALIZED",ns.SOL_MERKLE_TREE_UNDEFINED="SOL_MERKLE_TREE_UNDEFINED",ns.MERKLE_TREE_UNDEFINED="MERKLE_TREE_UNDEFINED",ns.INPUT_UTXO_NOT_INSERTED_IN_MERKLE_TREE="INPUT_UTXO_NOT_INSERTED_IN_MERKLE_TREE",ns.MERKLE_TREE_INDEX_UNDEFINED="MERKLE_TREE_INDEX_UNDEFINED",ns.MERKLE_TREE_SET_SPACE_UNDEFINED="MERKLE_TREE_SET_SPACE_UNDEFINED",exports.UtilsErrorCode=void 0,(ss=exports.UtilsErrorCode||(exports.UtilsErrorCode={})).ACCOUNT_NAME_UNDEFINED_IN_IDL="ACCOUNT_NAME_UNDEFINED_IN_IDL",ss.PROPERTY_UNDEFINED="PROPERTY_UNDEFINED",ss.LOOK_UP_TABLE_CREATION_FAILED="LOOK_UP_TABLE_CREATION_FAILED",ss.UNSUPPORTED_ARCHITECTURE="UNSUPPORTED_ARCHITECTURE",ss.UNSUPPORTED_PLATFORM="UNSUPPORTED_PLATFORM",ss.ACCOUNTS_UNDEFINED="ACCOUNTS_UNDEFINED",ss.INVALID_NUMBER="INVALID_NUMBER";class is extends Error{constructor(e,t,r){super(`${e}: ${r}`),this.code=e,this.functionName=t,this.codeMessage=r}}const as={INITIALIZE_COMPRESSION_CONFIG:[133,228,12,169,56,76,222,61],UPDATE_COMPRESSION_CONFIG:[135,215,243,81,163,146,33,70],DECOMPRESS_ACCOUNTS_IDEMPOTENT:[114,67,61,123,234,31,1,112]},us=n.struct([n.u32("compressionDelay"),n.publicKey("rentRecipient"),n.vec(n.publicKey(),"addressSpace"),n.option(n.u8(),"configBump")]),cs=n.struct([n.option(n.u32(),"newCompressionDelay"),n.option(n.publicKey(),"newRentRecipient"),n.option(n.vec(n.publicKey()),"newAddressSpace"),n.option(n.publicKey(),"newUpdateAuthority")]),ls=n.struct([n.array(n.u8(),32,"a"),n.array(n.u8(),64,"b"),n.array(n.u8(),32,"c")]),ds=n.struct([n.u16("rootIndex"),n.bool("proveByIndex"),n.u8("merkleTreePubkeyIndex"),n.u8("queuePubkeyIndex"),n.u32("leafIndex")]),ps=n.struct([ds.replicate("treeInfo"),n.option(n.array(n.u8(),32),"address"),n.option(n.u64(),"lamports"),n.u8("outputStateTreeIndex")]),hs=n.struct([ls.replicate("proof"),ps.replicate("compressedAccountMeta")]);function ms(e){return n.struct([ps.replicate("meta"),e.replicate("data"),n.vec(n.vec(n.u8()),"seeds")])}function fs(e,t,r){const o=Buffer.alloc(2e3),n=e.encode(t,o),s=Buffer.from(new Uint8Array(o.slice(0,n)));return Buffer.concat([Buffer.from(r),s])}function ys(e,t,r,o){const n=Buffer.from([133,228,12,169,56,76,222,61]),s={compressionDelay:e,rentRecipient:t,addressSpace:r,configBump:o},i=Buffer.alloc(1e3),a=us.encode(s,i),u=Buffer.from(new Uint8Array(i.slice(0,a)));return Buffer.concat([new Uint8Array(n),new Uint8Array(u)])}function gs(t,r=0){const[o,n]=e.PublicKey.findProgramAddressSync([Buffer.from("compressible_config"),Buffer.from([r])],t);return[o,n]}async function ws(t,r){const o=await r.getAccountInfo(t);if(!o)throw new Error("Program account does not exist");const n=new e.PublicKey(o.data.slice(4,36)),s=await r.getAccountInfo(n);if(!s)throw new Error("Program data account does not exist");return{programDataAddress:n,programDataAccountInfo:s}}function vs(t,r){if(3!==t.data.readUInt32LE(0))throw new Error("Invalid program data discriminator");if(1!==t.data[12])throw new Error("Program has no upgrade authority");const o=t.data.slice(13,45),n=new e.PublicKey(o);if(!n.equals(r))throw new Error(`Provided authority ${r.toBase58()} does not match program's upgrade authority ${n.toBase58()}`)}function xs(t,r,o,n,s,i,a,u=null){const c=null!=u?u:0,[l]=gs(t,c),d=new e.PublicKey("BPFLoaderUpgradeab1e11111111111111111111111"),[p]=e.PublicKey.findProgramAddressSync([t.toBuffer()],d),h=[{pubkey:o,isSigner:1,isWritable:1},{pubkey:l,isSigner:0,isWritable:1},{pubkey:p,isSigner:0,isWritable:0},{pubkey:n,isSigner:1,isWritable:0},{pubkey:e.SystemProgram.programId,isSigner:0,isWritable:0}],m=fs(us,{compressionDelay:s,rentRecipient:i,addressSpace:a,configBump:c},r);return new e.TransactionInstruction({programId:t,keys:h,data:m})}function bs(t,r,o,n=null,s=null,i=null,a=null){const[u]=gs(t,0),c=[{pubkey:u,isSigner:0,isWritable:1},{pubkey:o,isSigner:1,isWritable:0}],l=fs(cs,{newCompressionDelay:n,newRentRecipient:s,newAddressSpace:i,newUpdateAuthority:a},r);return new e.TransactionInstruction({programId:t,keys:c,data:l})}function Is(t,r,o,n,s,i,a,u=[]){const[c]=gs(t,0),l=[{pubkey:o,isSigner:1,isWritable:1},{pubkey:n,isSigner:0,isWritable:1},{pubkey:c,isSigner:0,isWritable:0},{pubkey:s,isSigner:0,isWritable:1},...u],d=fs(hs,{proof:a,compressedAccountMeta:i},r);return new e.TransactionInstruction({programId:t,keys:l,data:d})}function As(t,r,o,n,s,i,a,u,c=[],l){if(s.length!==i.length)throw new Error("PDA accounts and compressed accounts must have the same length");if(s.length!==a.length)throw new Error("PDA accounts and bumps must have the same length");const[d]=gs(t,0),p=[{pubkey:o,isSigner:1,isWritable:1},{pubkey:n,isSigner:1,isWritable:1},{pubkey:d,isSigner:0,isWritable:0},...c],h=l({proof:u,compressedAccounts:i,bumps:a,systemAccountsOffset:s.length});return new e.TransactionInstruction({programId:t,keys:p,data:h})}class Es{static initializeCompressionConfig(e,t,r,o,n,s,i,a=null){return xs(e,t,r,o,n,s,i,a)}static updateCompressionConfig(e,t,r,o=null,n=null,s=null,i=null){return bs(e,t,r,o,n,s,i)}static compressAccount(e,t,r,o,n,s,i,a=[]){return Is(e,t,r,o,n,s,i,a)}static decompressAccountsIdempotent(e,t,r,o,n,s,i,a,u=[],c){return As(e,0,r,o,n,s,i,a,u,c)}static deriveCompressionConfigAddress(e,t=0){return gs(e,t)}static async getProgramDataAccount(e,t){return await ws(e,t)}static checkProgramUpdateAuthority(e,t){vs(e,t)}static serializeInitializeCompressionConfigData(e,t,r,o){return ys(e,t,r,o)}static createCompressedAccountData(e,t,r,o){return{meta:{treeInfo:{rootIndex:0,proveByIndex:e.proveByIndex,merkleTreePubkeyIndex:0,queuePubkeyIndex:0,leafIndex:e.leafIndex},address:e.address?Array.from(e.address):null,lamports:e.lamports,outputStateTreeIndex:o},data:t,seeds:r}}}Es.DISCRIMINATORS=as,exports.ADDRESS_QUEUE_ROLLOVER_FEE=Oe,exports.ADDRESS_TREE_NETWORK_FEE=Ne,exports.ALICE=jn,exports.AccountProofResult=kn,exports.AppendLeavesInputLayout=ct,exports.AppendNullifyCreateAddressInputsMetaLayout=ut,exports.BOB=Gn,exports.BalanceResult=An,exports.CHARLIE=Zn,exports.COMPRESSED_TOKEN_PROGRAM_ID=pe,exports.COMPRESSIBLE_DISCRIMINATORS=as,exports.COMPUTE_BUDGET_PATTERN=Z,exports.CompressedAccountLayout=Ke,exports.CompressedAccountMetaSchema=ps,exports.CompressedAccountResult=Jo,exports.CompressedAccountResultV2=Qo,exports.CompressedAccountsByOwnerResult=on,exports.CompressedAccountsByOwnerResultV2=nn,exports.CompressedCpiContextLayout=Ze,exports.CompressedMintTokenHoldersResult=Cn,exports.CompressedProofLayout=Ge,exports.CompressedTokenAccountResult=Yo,exports.CompressedTokenAccountResultV2=en,exports.CompressedTokenAccountsByOwnerOrDelegateResult=sn,exports.CompressedTokenAccountsByOwnerOrDelegateResultV2=an,exports.CompressedTransactionResult=Ln,exports.CompressedTransactionResultV2=Nn,exports.CompressibleInstruction=Es,exports.CreateUtxoError=class extends is{},exports.DAVE=Jn,exports.DEFAULT_MERKLE_TREE_HEIGHT=ke,exports.DEFAULT_MERKLE_TREE_ROOTS=2800,exports.DEFAULT_ZERO="0",exports.FIELD_SIZE=j,exports.GenericCompressAccountInstructionSchema=hs,exports.HIGHEST_ADDRESS_PLUS_ONE=G,exports.HashError=class extends is{},exports.HealthResult=cn,exports.IDL={version:"1.2.0",name:"light_system_program",constants:[{name:"SOL_POOL_PDA_SEED",type:"bytes",value:"[115, 111, 108, 95, 112, 111, 111, 108, 95, 112, 100, 97]"}],instructions:[{name:"initCpiContextAccount",accounts:[{name:"feePayer",isMut:1,isSigner:1},{name:"cpiContextAccount",isMut:1,isSigner:0},{name:"associatedMerkleTree",isMut:0,isSigner:0}],args:[]},{name:"invoke",accounts:[{name:"feePayer",isMut:1,isSigner:1,docs:["Fee payer needs to be mutable to pay rollover and protocol fees."]},{name:"authority",isMut:0,isSigner:1},{name:"registeredProgramPda",isMut:0,isSigner:0},{name:"noopProgram",isMut:0,isSigner:0},{name:"accountCompressionAuthority",isMut:0,isSigner:0,docs:["This pda is used to invoke the account compression program."]},{name:"accountCompressionProgram",isMut:0,isSigner:0,docs:["Merkle trees."]},{name:"solPoolPda",isMut:1,isSigner:0,isOptional:1,docs:["Sol pool pda is used to store the native sol that has been compressed.","It's only required when compressing or decompressing sol."]},{name:"decompressionRecipient",isMut:1,isSigner:0,isOptional:1,docs:["Only needs to be provided for decompression as a recipient for the","decompressed sol.","Compressed sol originate from authority."]},{name:"systemProgram",isMut:0,isSigner:0}],args:[{name:"inputs",type:"bytes"}]},{name:"invokeCpi",accounts:[{name:"feePayer",isMut:1,isSigner:1,docs:["Fee payer needs to be mutable to pay rollover and protocol fees."]},{name:"authority",isMut:0,isSigner:1},{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:"invokingProgram",isMut:0,isSigner:0},{name:"solPoolPda",isMut:1,isSigner:0,isOptional:1},{name:"decompressionRecipient",isMut:1,isSigner:0,isOptional:1},{name:"systemProgram",isMut:0,isSigner:0},{name:"cpiContextAccount",isMut:1,isSigner:0,isOptional:1}],args:[{name:"inputs",type:"bytes"}]},{name:"invokeCpiWithReadOnly",accounts:[{name:"feePayer",isMut:1,isSigner:1,docs:["Fee payer needs to be mutable to pay rollover and protocol fees."]},{name:"authority",isMut:0,isSigner:1},{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:"invokingProgram",isMut:0,isSigner:0},{name:"solPoolPda",isMut:1,isSigner:0,isOptional:1},{name:"decompressionRecipient",isMut:1,isSigner:0,isOptional:1},{name:"systemProgram",isMut:0,isSigner:0},{name:"cpiContextAccount",isMut:1,isSigner:0,isOptional:1}],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:["Fee payer needs to be mutable to pay rollover and protocol fees."]},{name:"authority",isMut:0,isSigner:1},{name:"registeredProgramPda",isMut:0,isSigner:0},{name:"noopProgram",isMut:0,isSigner:0},{name:"accountCompressionAuthority",isMut:0,isSigner:0,docs:["This pda is used to invoke the account compression program."]},{name:"accountCompressionProgram",isMut:0,isSigner:0,docs:["Merkle trees."]},{name:"solPoolPda",isMut:1,isSigner:0,isOptional:1,docs:["Sol pool pda is used to store the native sol that has been compressed.","It's only required when compressing or decompressing sol."]},{name:"decompressionRecipient",isMut:1,isSigner:0,isOptional:1,docs:["Only needs to be provided for decompression as a recipient for the","decompressed sol.","Compressed sol originate from authority."]},{name:"systemProgram",isMut:0,isSigner:0}],args:[{name:"inputs1",type:{defined:"InstructionDataInvoke"}},{name:"inputs2",type:{defined:"InstructionDataInvokeCpi"}},{name:"inputs3",type:{defined:"PublicTransactionEvent"}}]}],accounts:[{name:"cpiContextAccount",docs:["Collects instruction data without executing a compressed transaction.","Signer checks are performed on instruction data.","Collected instruction data is combined with the instruction data of the executing cpi,","and executed as a single transaction.","This enables to use input compressed accounts that are owned by multiple programs,","with one zero-knowledge proof."],type:{kind:"struct",fields:[{name:"feePayer",type:"publicKey"},{name:"associatedMerkleTree",type:"publicKey"},{name:"context",type:{vec:{defined:"InstructionDataInvokeCpi"}}}]}}],types:[{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:"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:"CompressedProof",type:{kind:"struct",fields:[{name:"a",type:{array:["u8",32]}},{name:"b",type:{array:["u8",64]}},{name:"c",type:{array:["u8",32]}}]}},{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:"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:"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:"PackedCompressedAccountWithMerkleContext",type:{kind:"struct",fields:[{name:"compressedAccount",type:{defined:"CompressedAccount"}},{name:"merkleContext",type:{defined:"PackedMerkleContext"}},{name:"rootIndex",docs:["Index of root used in inclusion validity proof."],type:"u16"},{name:"readOnly",docs:["Placeholder to mark accounts read-only unimplemented set to false."],type:"bool"}]}},{name:"PackedMerkleContext",type:{kind:"struct",fields:[{name:"merkleTreePubkeyIndex",type:"u8"},{name:"queuePubkeyIndex",type:"u8"},{name:"leafIndex",type:"u32"},{name:"proveByIndex",type:"bool"}]}},{name:"MerkleTreeSequenceNumber",type:{kind:"struct",fields:[{name:"pubkey",type:"publicKey"},{name:"seq",type:"u64"}]}},{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"}}]}}],errors:[{code:6e3,name:"SumCheckFailed",msg:"Sum check failed"},{code:6001,name:"SignerCheckFailed",msg:"Signer check failed"},{code:6002,name:"CpiSignerCheckFailed",msg:"Cpi signer check failed"},{code:6003,name:"ComputeInputSumFailed",msg:"Computing input sum failed."},{code:6004,name:"ComputeOutputSumFailed",msg:"Computing output sum failed."},{code:6005,name:"ComputeRpcSumFailed",msg:"Computing rpc sum failed."},{code:6006,name:"InvalidAddress",msg:"InvalidAddress"},{code:6007,name:"DeriveAddressError",msg:"DeriveAddressError"},{code:6008,name:"CompressedSolPdaUndefinedForCompressSol",msg:"CompressedSolPdaUndefinedForCompressSol"},{code:6009,name:"DecompressLamportsUndefinedForCompressSol",msg:"DecompressLamportsUndefinedForCompressSol"},{code:6010,name:"CompressedSolPdaUndefinedForDecompressSol",msg:"CompressedSolPdaUndefinedForDecompressSol"},{code:6011,name:"DeCompressLamportsUndefinedForDecompressSol",msg:"DeCompressLamportsUndefinedForDecompressSol"},{code:6012,name:"DecompressRecipientUndefinedForDecompressSol",msg:"DecompressRecipientUndefinedForDecompressSol"},{code:6013,name:"WriteAccessCheckFailed",msg:"WriteAccessCheckFailed"},{code:6014,name:"InvokingProgramNotProvided",msg:"InvokingProgramNotProvided"},{code:6015,name:"InvalidCapacity",msg:"InvalidCapacity"},{code:6016,name:"InvalidMerkleTreeOwner",msg:"InvalidMerkleTreeOwner"},{code:6017,name:"ProofIsNone",msg:"ProofIsNone"},{code:6018,name:"ProofIsSome",msg:"Proof is some but no input compressed accounts or new addresses provided."},{code:6019,name:"EmptyInputs",msg:"EmptyInputs"},{code:6020,name:"CpiContextAccountUndefined",msg:"CpiContextAccountUndefined"},{code:6021,name:"CpiContextEmpty",msg:"CpiContextEmpty"},{code:6022,name:"CpiContextMissing",msg:"CpiContextMissing"},{code:6023,name:"DecompressionRecipientDefined",msg:"DecompressionRecipientDefined"},{code:6024,name:"SolPoolPdaDefined",msg:"SolPoolPdaDefined"},{code:6025,name:"AppendStateFailed",msg:"AppendStateFailed"},{code:6026,name:"InstructionNotCallable",msg:"The instruction is not callable"},{code:6027,name:"CpiContextFeePayerMismatch",msg:"CpiContextFeePayerMismatch"},{code:6028,name:"CpiContextAssociatedMerkleTreeMismatch",msg:"CpiContextAssociatedMerkleTreeMismatch"},{code:6029,name:"NoInputs",msg:"NoInputs"},{code:6030,name:"InputMerkleTreeIndicesNotInOrder",msg:"Input merkle tree indices are not in ascending order."},{code:6031,name:"OutputMerkleTreeIndicesNotInOrder",msg:"Output merkle tree indices are not in ascending order."},{code:6032,name:"OutputMerkleTreeNotUnique"},{code:6033,name:"DataFieldUndefined"},{code:6034,name:"ReadOnlyAddressAlreadyExists"},{code:6035,name:"ReadOnlyAccountDoesNotExist"},{code:6036,name:"HashChainInputsLenghtInconsistent"},{code:6037,name:"InvalidAddressTreeHeight"},{code:6038,name:"InvalidStateTreeHeight"}]},exports.INSERT_INTO_QUEUES_DISCRIMINATOR=ee,exports.INVOKE_CPI_DISCRIMINATOR=Q,exports.INVOKE_CPI_WITH_ACCOUNT_INFO_DISCRIMINATOR=Y,exports.INVOKE_CPI_WITH_READ_ONLY_DISCRIMINATOR=X,exports.INVOKE_DISCRIMINATOR=J,exports.InAccountLayout=Xe,exports.IndexedArray=Yr,exports.IndexedElement=Qr,exports.IndexedElementBundle=Xr,exports.InsertAddressInputLayout=dt,exports.InsertNullifierInputLayout=lt,exports.InstructionDataInvokeCpiLayout=je,exports.InstructionDataInvokeCpiWithReadOnlyLayout=tt,exports.InstructionDataInvokeLayout=$e,exports.LatestNonVotingSignaturesResult=ln,exports.LatestNonVotingSignaturesResultPaginated=dn,exports.LightSystemProgram=Zr,exports.LookupTableError=class extends is{},exports.MerkleContextLayout=We,exports.MerkleProofResult=pn,exports.MerkleProofResultV2=hn,exports.MerkleTree=eo,exports.MerkleTreeError=class extends is{},exports.MerkleTreeSequenceNumberLayout=pt,exports.MultipleCompressedAccountsResult=tn,exports.MultipleCompressedAccountsResultV2=rn,exports.MultipleMerkleProofsResult=bn,exports.MultipleMerkleProofsResultV2=In,exports.NativeBalanceResult=En,exports.NewAddressParamsAssignedPackedLayout=Je,exports.NewAddressParamsLayout=He,exports.NewAddressProofResult=mn,exports.PackedAccounts=qr,exports.PackedAccountsSmall=Hr,exports.PackedMerkleContextLayout=Qe,exports.PackedReadOnlyAddressLayout=Ye,exports.PackedReadOnlyCompressedAccountLayout=et,exports.PackedStateTreeInfoSchema=ds,exports.ProofError=class extends is{},exports.PublicTransactionEventLayout=it,exports.RootIndexResultV2=yn,exports.Rpc=Hn,exports.RpcError=class extends is{},exports.STATE_MERKLE_TREE_NETWORK_FEE=Le,exports.STATE_MERKLE_TREE_ROLLOVER_FEE=Pe,exports.SelectInUtxosError=class extends is{},exports.SignatureListResult=_n,exports.SignatureListWithCursorResult=Pn,exports.SlotResult=un,exports.SystemAccountMetaConfig=Kr,exports.SystemAccountPubkeys=zr,exports.TRANSACTION_MERKLE_TREE_ROLLOVER_THRESHOLD=_e,exports.TestRpc=$n,exports.TokenBalanceListResult=Mn,exports.TokenBalanceListResultV2=Sn,exports.TokenBalanceResult=Tn,exports.TokenDataLayout=ao,exports.TokenDataResult=Xo,exports.UTXO_MERGE_MAXIMUM=10,exports.UTXO_MERGE_THRESHOLD=20,exports.UpdateCompressionConfigSchema=cs,exports.UtilsError=class extends is{},exports.UtxoError=class extends is{},exports.ValidityProofResult=gn,exports.ValidityProofResultV2=xn,exports.ValidityProofSchema=ls,exports.accountCompressionProgram=oe,exports.addressQueue=be,exports.addressTree=xe,exports.addressTreeV2=Ie,exports.airdropSol=async function({connection:e,lamports:t,recipientPublicKey:r}){const o=await e.requestAirdrop(r,t);return await Mr(e,o),o},exports.batchCpiContext=Ce,exports.batchMerkleTree=Me,exports.batchQueue=Se,exports.bn=Ue,exports.bufToDecStr=e=>Re(e).toString(),exports.buildAndSignTx=Rr,exports.buildTx=Lr,exports.byteArrayToKeypair=function(t){return e.Keypair.fromSecretKey(Uint8Array.from(t))},exports.calculateComputeUnitPrice=function(e,t){return Math.ceil(1e6*e/t)},exports.checkProgramUpdateAuthority=vs,exports.checkValidityProofShape=e=>{if(32!==e.a.length||64!==e.b.length||32!==e.c.length)throw new Error("ValidityProof has invalid shape")},exports.compress=async function(t,r,o,n,s,i){const{blockhash:a}=await t.getLatestBlockhash();s||(s=Vr(await t.getStateTreeInfos()));const u=await Zr.compress({payer:r.publicKey,toAddress:n,lamports:o,outputStateTreeInfo:s}),c=Rr([e.ComputeBudgetProgram.setComputeUnitLimit({units:1e6}),u],r,a,[]);return await Nr(t,c,i)},exports.compressAccount=async function(t,r,o,n,s,i,a,u,c,l){const d=Is(o,c,r.publicKey,n,s,i,a,u),{blockhash:p}=await t.getLatestBlockhash(),h=Rr([e.ComputeBudgetProgram.setComputeUnitLimit({units:3e5}),d],r,p);return await Nr(t,h,l)},exports.compressibleInstruction=Es,exports.confirmConfig={commitment:"confirmed",preflightCommitment:"confirmed"},exports.confirmTransaction=Mr,exports.confirmTx=Br,exports.convertInvokeCpiWithReadOnlyToInvoke=xr,exports.convertMerkleProofsWithContextToHex=Fn,exports.convertNonInclusionMerkleProofInputsToHex=qn,exports.convertToPublicTransactionEvent=mt,exports.cpiContext2Pubkey=Te,exports.cpiContextPubkey=we,exports.createAccount=async function(t,r,o,n,s,i,a){const{blockhash:u}=await t.getLatestBlockhash(),{tree:c,queue:l}=null!=s?s:le(),d=Ar(o,n),p=Er(d,c);i||(i=Vr(await t.getStateTreeInfos()));const h=await t.getValidityProofV0(void 0,[{address:Ue(p.toBytes()),tree:c,queue:l}]),m={seed:d,addressMerkleTreeRootIndex:h.rootIndices[0],addressMerkleTreePubkey:h.treeInfos[0].tree,addressQueuePubkey:h.treeInfos[0].queue},f=await Zr.createAccount({payer:r.publicKey,newAddressParams:m,newAddress:Array.from(p.toBytes()),recentValidityProof:h.compressedProof,programId:n,outputStateTreeInfo:i}),y=Rr([e.ComputeBudgetProgram.setComputeUnitLimit({units:1e6}),f],r,u,[]);return await Nr(t,y,a)},exports.createAccountWithLamports=async function(t,r,o,n,s,i,a,u){n=Ue(n);const c=await t.getCompressedAccountsByOwner(r.publicKey),[l]=Jr(c.items,n),{blockhash:d}=await t.getLatestBlockhash(),{tree:p}=null!=i?i:le(),h=Ar(o,s),m=Er(h,p),f=await t.getValidityProof(l.map((e=>e.hash)),[Ue(m.toBytes())]),y={seed:h,addressMerkleTreeRootIndex:f.rootIndices[f.rootIndices.length-1],addressMerkleTreePubkey:f.treeInfos[f.treeInfos.length-1].tree,addressQueuePubkey:f.treeInfos[f.treeInfos.length-1].queue},g=await Zr.createAccount({payer:r.publicKey,newAddressParams:y,newAddress:Array.from(m.toBytes()),recentValidityProof:f.compressedProof,inputCompressedAccounts:l,inputStateRootIndices:f.rootIndices,outputStateTreeInfo:a}),w=Rr([e.ComputeBudgetProgram.setComputeUnitLimit({units:1e6}),g],r,d,[]);return await Nr(t,w,u)},exports.createBN254=Re,exports.createCompressAccountInstruction=Is,exports.createCompressedAccountData=function(e,t,r,o){return{meta:{treeInfo:{rootIndex:0,proveByIndex:e.proveByIndex,merkleTreePubkeyIndex:0,queuePubkeyIndex:0,leafIndex:e.leafIndex},address:e.address?Array.from(e.address):null,lamports:e.lamports,outputStateTreeIndex:o},data:t,seeds:r}},exports.createCompressedAccountDataSchema=ms,exports.createCompressedAccountLegacy=Ve,exports.createCompressedAccountMeta=(e,t,r,o)=>({treeInfo:e,outputStateTreeIndex:t,address:null!=r?r:null,lamports:null!=o?o:null}),exports.createCompressedAccountWithMerkleContextLegacy=Fe,exports.createDecompressAccountsIdempotentInstruction=As,exports.createDecompressMultipleAccountsIdempotentDataSchema=function(e){return n.struct([ls.replicate("proof"),n.vec(ms(e),"compressedAccounts"),n.vec(n.u8(),"bumps"),n.u8("systemAccountsOffset")])},exports.createInitializeCompressionConfigInstruction=xs,exports.createMerkleContextLegacy=qe,exports.createPackedAccounts=function(e){const t=Kr.new(e);return qr.newWithSystemAccounts(t)},exports.createPackedAccountsSmall=function(e){const t=Kr.new(e);return Hr.newWithSystemAccounts(t)},exports.createPackedAccountsSmallWithCpiContext=function(e,t){const r=Kr.newWithCpiContext(e,t);return Hr.newWithSystemAccounts(r)},exports.createPackedAccountsWithCpiContext=function(e,t){const r=Kr.newWithCpiContext(e,t);return qr.newWithSystemAccounts(r)},exports.createRootIndex=function(e){return{proofByIndex:0,rootIndex:e}},exports.createRootIndexByIndex=function(){return{proofByIndex:1,rootIndex:0}},exports.createRpc=function(t,r,o,n){let s;if(t)if("string"==typeof t)s=t,r=r||s,o=o||s;else{if(!(t instanceof e.Connection))throw new Error("Invalid endpoint or connection type");s=t.rpcEndpoint,r=r||s,o=o||s}else s="http://127.0.0.1:8899",r=r||"http://127.0.0.1:8784",o=o||"http://127.0.0.1:3001";return new Hn(s,r,o,n)},exports.createRpcResult=Wo,exports.createStateTreeLookupTable=async function({connection:t,payer:r,authority:o,recentSlot:n}){const[s,i]=e.AddressLookupTableProgram.createLookupTable({payer:r.publicKey,authority:o.publicKey,recentSlot:n}),a=Rr([s],r,(await t.getLatestBlockhash()).blockhash,Sr(r,[o]));return{address:i,txId:await Nr(t,a)}},exports.createUpdateCompressionConfigInstruction=bs,exports.decodeInstructionDataInvoke=ot,exports.decodeInstructionDataInvokeCpi=nt,exports.decodeInstructionDataInvokeCpiWithReadOnly=rt,exports.decodePublicTransactionEvent=at,exports.decompress=async function(t,r,o,n,s){const i=(await t.getCompressedAccountsByOwner(r.publicKey)).items;o=Ue(o);const a=jr(i);if(o.gt(a))throw new Error(`Not enough compressed lamports. Expected ${o}, got ${a}`);const u=await t.getValidityProof(i.map((e=>Ue(e.hash)))),{blockhash:c}=await t.getLatestBlockhash(),l=await Zr.decompress({payer:r.publicKey,toAddress:n,inputCompressedAccounts:i,recentValidityProof:u.compressedProof,recentInputStateRootIndices:u.rootIndices,lamports:o}),d=Rr([e.ComputeBudgetProgram.setComputeUnitLimit({units:1e6}),l],r,c,[]);return await Nr(t,d,s)},exports.decompressAccountsIdempotent=async function(t,r,o,n,s,i,a,u,c,l,d,p=as.DECOMPRESS_ACCOUNTS_IDEMPOTENT,h){const m=As(o,0,n.publicKey,s.publicKey,i,a,u,c,l,d),{blockhash:f}=await t.getLatestBlockhash(),y=Sr(r,[n,s]),g=Rr([e.ComputeBudgetProgram.setComputeUnitLimit({units:4e5+5e4*a.length}),m],r,f,y);return await Nr(t,g,h)},exports.dedupeSigner=Sr,exports.deepEqual=function e(t,r){if(typeof t!=typeof r)return console.log(`Type mismatch: ${typeof t} !== ${typeof r}`),0;if(t instanceof H&&r instanceof H)return t.eq(r);if("object"==typeof t&&null!==t&&null!==r){const o=Object.keys(t),n=Object.keys(r);if(o.length!==n.length)return console.log(`Key length mismatch: ${o.length} !== ${n.length}`),0;for(const s of o){if(!n.includes(s))return console.log(`Key ${s} not found in value`),0;if(!e(t[s],r[s]))return console.log(`Value mismatch at key ${s}`),0}return 1}return t!==r&&console.log(`Value mismatch: ${t} !== ${r}`),t===r},exports.defaultStateTreeLookupTables=ae,exports.defaultStaticAccounts=()=>[new e.PublicKey(ne()),new e.PublicKey(te),new e.PublicKey(oe),new e.PublicKey(se())],exports.defaultStaticAccountsStruct=ie,exports.defaultTestStateTreeAccounts=de,exports.defaultTestStateTreeAccounts2=()=>({nullifierQueue2:new e.PublicKey(Ee),merkleTree2:new e.PublicKey(Ae)}),exports.deriveAddress=Er,exports.deriveAddressSeed=Ar,exports.deriveAddressV2=br,exports.deriveCompressionConfigAddress=gs,exports.deserializeAppendNullifyCreateAddressInputsIndexer=ht,exports.encodeBN254toBase58=De,exports.encodeInstructionDataInvoke=ze,exports.encodePublicTransactionEvent=function(e){const r=t.Buffer.alloc(1e3),o=it.encode(e,r);return r.slice(0,o)},exports.extendStateTreeLookupTable=async function({connection:t,tableAddress:r,newStateTreeAddresses:o,newQueueAddresses:n,newCpiContextAddresses:s,payer:i,authority:a}){const u=await t.getAddressLookupTable(r);if(!u.value)throw new Error("Lookup table not found");if(u.value.state.addresses.length%3!=0)throw new Error("Lookup table must have a multiple of 3 addresses");if(o.length!==n.length||o.length!==s.length)throw new Error("Same number of newStateTreeAddresses, newQueueAddresses, and newCpiContextAddresses required");const c=Rr([e.AddressLookupTableProgram.extendLookupTable({payer:i.publicKey,authority:a.publicKey,lookupTable:r,addresses:o.flatMap(((e,t)=>[e,n[t],s[t]]))})],i,(await t.getLatestBlockhash()).blockhash,Sr(i,[a]));return{tableAddress:r,txId:await Nr(t,c)}},exports.featureFlags=$,exports.getAccountCompressionAuthority=se,exports.getAllStateTreeInfos=Fr,exports.getCompressedTokenAccountByHashTest=ho,exports.getCompressedTokenAccounts=co,exports.getCompressedTokenAccountsByDelegateTest=po,exports.getCompressedTokenAccountsByOwnerTest=lo,exports.getConnection=function(){return new e.Connection("http://127.0.0.1:8899","confirmed")},exports.getDefaultAddressTreeInfo=le,exports.getIndexOrAdd=ft,exports.getLightSystemAccountMetas=Wr,exports.getLightSystemAccountMetasSmall=$r,exports.getParsedEvents=to,exports.getProgramDataAccount=ws,exports.getPublicInputHash=function(e,t,r,o){const n=Kn(e.map((e=>e.root)),t,o),s=r.map((e=>e.value)),i=Kn(r.map((e=>e.root)),s,o);return i.isZero()?n.isZero()?Kn([n],[i],o):n:i},exports.getRegisteredProgramPda=ne,exports.getStateTreeInfoByPubkey=Dr,exports.getTestKeypair=Qn,exports.getTestRpc=async function(e,t="http://127.0.0.1:8899",r="http://127.0.0.1:8784",o="http://127.0.0.1:3001",n,s=0){return new $n(t,e,r,o,void 0,{depth:n||de().merkleTreeHeight,log:s})},exports.getTreeInfoByPubkey=Ur,exports.hashToBn254FieldSizeBe=wr,exports.hashVWithBumpSeed=Ir,exports.hashvToBn254FieldSizeBe=vr,exports.initializeCompressionConfig=async function(t,r,o,n,s,i,a,u=null,c=as.INITIALIZE_COMPRESSION_CONFIG,l){const d=xs(o,c,r.publicKey,n.publicKey,s,i,a,u),{blockhash:p}=await t.getLatestBlockhash(),h=Sr(r,[n]),m=Rr([e.ComputeBudgetProgram.setComputeUnitLimit({units:2e5}),d],r,p,h);return await Nr(t,m,l)},exports.invokeAccountsLayout=st,exports.isLocalTest=ue,exports.isSmallerThanBn254FieldSizeBe=yr,exports.jsonRpcResult=$o,exports.jsonRpcResultAndContext=zo,exports.lightSystemProgram=re,exports.localTestActiveStateTreeInfos=ce,exports.merkleTree2Pubkey=Ae,exports.merkletreePubkey=ve,exports.negateAndCompressProof=kr,exports.newAccountWithLamports=async function(e,t=1e9,r){(void 0===r||r>255)&&(r=256);const o=Qn(r),n=await e.requestAirdrop(o.publicKey,t);return await Br(e,n),o},exports.noopProgram=te,exports.nullifiedStateTreeLookupTableDevnet=ye,exports.nullifiedStateTreeLookupTableMainnet=me,exports.nullifierQueue2Pubkey=Ee,exports.nullifierQueuePubkey=ge,exports.nullifyLookupTable=async function({connection:t,fullStateTreeAddress:r,nullifyLookupTableAddress:o,stateTreeLookupTableAddress:n,payer:s,authority:i}){const a=await t.getAddressLookupTable(n);if(!a.value)throw console.log("stateTreeLookupTable",a),new Error("State tree lookup table not found");if(!a.value.state.addresses.map((e=>e.toBase58())).includes(r.toBase58()))throw console.log("fullStateTreeAddress",r),console.log("stateTreeLookupTable.value.state.addresses",a.value.state.addresses),new Error("State tree address not found in lookup table. Pass correct address or stateTreeLookupTable");const u=await t.getAddressLookupTable(o);if(!u.value)throw new Error("Nullify table not found");if(u.value.state.addresses.map((e=>e.toBase58())).includes(r.toBase58()))throw new Error("Address already exists in nullify lookup table");const c=Rr([e.AddressLookupTableProgram.extendLookupTable({payer:s.publicKey,authority:i.publicKey,lookupTable:o,addresses:[r]})],s,(await t.getLatestBlockhash()).blockhash,Sr(s,[i]));return{txId:await Nr(t,c)}},exports.packCompressedAccounts=wt,exports.packNewAddressParams=Tr,exports.packTreeInfos=function(e,t){const r="accounts"in e?e:function(e){const t=[],r=[];for(let o=0;o<e.treeInfos.length;o++){const n=e.treeInfos[o];n.treeType===exports.TreeType.StateV1||n.treeType===exports.TreeType.StateV2?t.push({hash:new Uint8Array(e.leaves[o].toArray("le",32)),root:new Uint8Array(e.roots[o].toArray("le",32)),rootIndex:{proofByIndex:e.proveByIndices[o],rootIndex:e.rootIndices[o]},leafIndex:e.leafIndices[o],treeInfo:n}):r.push({address:new Uint8Array(e.leaves[o].toArray("le",32)),root:new Uint8Array(e.roots[o].toArray("le",32)),rootIndex:e.rootIndices[o],treeInfo:n})}return{proof:e.compressedProof,accounts:t,addresses:r}}(e),o=[],n=[];let s=null;for(const e of r.accounts){const r=t.insertOrGet(e.treeInfo.tree),n=t.insertOrGet(e.treeInfo.queue),i={rootIndex:e.rootIndex.rootIndex,merkleTreePubkeyIndex:r,queuePubkeyIndex:n,leafIndex:e.leafIndex,proveByIndex:e.rootIndex.proofByIndex};if(o.push(i),e.treeInfo.nextTreeInfo){const r=vt(e.treeInfo.nextTreeInfo,t);null===s&&(s=r)}else{const r=vt(e.treeInfo,t);null===s&&(s=r)}}for(const e of r.addresses){const r=t.insertOrGet(e.treeInfo.tree),o=t.insertOrGet(e.treeInfo.queue);n.push({addressMerkleTreePubkeyIndex:r,addressQueuePubkeyIndex:o,rootIndex:e.rootIndex})}return{stateTrees:0===o.length?null:{packedTreeInfos:o,outputTreeIndex:s},addressTrees:n}},exports.packTreeInfosWithPubkeys=function(e,t,r){const o=e.slice(),n=[],s=[];let i=-1;if(0===t.length&&0===r.length)return{stateTrees:null,addressTrees:s};if(t.forEach((e=>{const t=ft(o,e.treeInfo.tree),r=ft(o,e.treeInfo.queue);n.push({rootIndex:e.rootIndex,merkleTreePubkeyIndex:t,queuePubkeyIndex:r,leafIndex:e.leafIndex,proveByIndex:e.proveByIndex})})),n.length>0){const e=t[0].treeInfo.nextTreeInfo||t[0].treeInfo;let r=e.tree;if(e.treeType===exports.TreeType.StateV2){if(!$.isV2())throw new Error("V2 trees are not supported yet");r=e.queue}i=ft(o,r)}return r.forEach((e=>{const t=ft(o,e.treeInfo.tree),r=ft(o,e.treeInfo.queue);s.push({rootIndex:e.rootIndex,addressMerkleTreePubkeyIndex:t,addressQueuePubkeyIndex:r})})),{stateTrees:n.length>0?{packedTreeInfos:n,outputTreeIndex:i}:null,addressTrees:s}},exports.padOutputStateMerkleTrees=yt,exports.parseAccountData=Bn,exports.parseEvents=ro,exports.parseLightTransaction=no,exports.parsePublicTransactionEventWithIdl=oo,exports.parseTokenLayoutWithIdl=uo,exports.pickRandomTreeAndQueue=function(e){const t=e.length,r=Math.floor(Math.random()*t);let o;if(void 0!==r){if(r<0||r>=e.length)throw new Error(`Index ${r} out of bounds for infos array of length ${e.length}`);o=r}else o=Math.floor(Math.random()*e.length);return e[o]},exports.pipe=function(e,...t){return r=>t.reduce(((e,t)=>t(e)),e(r))},exports.placeholderValidityProof=()=>({a:Array.from({length:32},((e,t)=>t+1)),b:Array.from({length:64},((e,t)=>t+1)),c:Array.from({length:32},((e,t)=>t+1))}),exports.proofFromJsonStruct=Cr,exports.proverRequest=Vn,exports.pushUniqueItems=function(e,t){e.forEach((e=>{t.includes(e)||t.push(e)}))},exports.rpcRequest=Un,exports.selectMinCompressedSolAccountsForTransfer=Jr,exports.selectStateTreeInfo=Vr,exports.sendAndConfirmTx=Nr,exports.serializeInitializeCompressionConfigData=ys,exports.serializeInstructionData=fs,exports.sleep=function(e){return new Promise((t=>setTimeout(t,e)))},exports.stateTreeLookupTableDevnet=fe,exports.stateTreeLookupTableMainnet=he,exports.sumUpLamports=jr,exports.toAccountMetas=gt,exports.toArray=e=>Array.isArray(e)?e:[e],exports.toCamelCase=gr,exports.toHex=fr,exports.toUnixTimestamp=e=>new Date(e).getTime(),exports.transfer=async function(t,r,o,n,s,i){var a;let u=Ue(0);const c=[];let l;for(o=Ue(o);u.lt(o);){const e={filters:void 0,dataSlice:void 0,cursor:l,limit:Ue(1e3)},r=await t.getCompressedAccountsByOwner(n.publicKey,e);for(const e of r.items)e.lamports.gt(Ue(0))&&(c.push(e),u=u.add(e.lamports));if(l=null!==(a=r.cursor)&&void 0!==a?a:void 0,r.items.length<1e3||u.gte(o))break}if(u.lt(o))throw new Error(`Insufficient balance for transfer. Required: ${o.toString()}, available: ${u.toString()}`);const[d]=Jr(c,o),p=await t.getValidityProof(d.map((e=>Ue(e.hash)))),h=await Zr.transfer({payer:r.publicKey,inputCompressedAccounts:d,toAddress:s,lamports:o,recentInputStateRootIndices:p.rootIndices,recentValidityProof:p.compressedProof}),{blockhash:m}=await t.getLatestBlockhash(),f=Rr([e.ComputeBudgetProgram.setComputeUnitLimit({units:35e4}),h],r,m);return await Nr(t,f,i)},exports.updateCompressionConfig=async function(t,r,o,n,s=null,i=null,a=null,u=null,c=as.UPDATE_COMPRESSION_CONFIG,l){const d=bs(o,c,n.publicKey,s,i,a,u),{blockhash:p}=await t.getLatestBlockhash(),h=Sr(r,[n]),m=Rr([e.ComputeBudgetProgram.setComputeUnitLimit({units:15e4}),d],r,p,h);return await Nr(t,m,l)},exports.validateNumbers=Tt,exports.validateNumbersForInclusionProof=At,exports.validateNumbersForNonInclusionProof=Et,exports.validateNumbersForProof=It,exports.validateSameOwner=bt,exports.validateSufficientBalance=xt,exports.versionedEndpoint=z,exports.wrapBigNumbersAsStrings=Dn;
2
2
  //# sourceMappingURL=index.cjs.map