Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

@mayanfinance/swap-sdk

Package Overview
Dependencies
Maintainers
1
Versions
63
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@mayanfinance/swap-sdk - npm Package Compare versions

Comparing version 2.6.0 to 2.7.0

dist/main.amd.js

929

dist/main.umd.js

@@ -1,2 +0,927 @@

!function(e,t){"object"==typeof exports&&"undefined"!=typeof module?t(exports,require("cross-fetch"),require("ethers"),require("@solana/web3.js"),require("js-sha3"),require("@solana/buffer-layout")):"function"==typeof define&&define.amd?define(["exports","cross-fetch","ethers","@solana/web3.js","js-sha3","@solana/buffer-layout"],t):t((e||self).swapSdk={},e.crossFetch,e.ethers,e.web3_js,e.jsSha3,e.bufferLayout)}(this,function(e,t,n,r,i,o){function s(e){return e&&"object"==typeof e&&"default"in e?e:{default:e}}var a=/*#__PURE__*/s(t),u="8LPjGDbxhW4G2Q8S6FvdvUdfGWssgtqmvsc63bwNFA7E",f="4U6MNAMRbYeTD4HumavhJ1ah9NQ5pNPhTNxcFdeybXFy",l="TokenkegQfeZyiNwAJbNbGKPFXCWuBvf9Ss623VQ5DA",c="ATokenGPvbdGVxr1b2hvZbsiqW5xWH25efTNsLJA8knL",p="https://price-api.mayan.finance/v1",h=function(){try{return Promise.resolve(a.default(p+"/clock/solana")).then(function(e){return Promise.resolve(e.json()).then(function(t){if(200!==e.status)throw t;return t.clock})})}catch(e){return Promise.reject(e)}};function y(){return y=Object.assign?Object.assign.bind():function(e){for(var t=1;t<arguments.length;t++){var n=arguments[t];for(var r in n)Object.prototype.hasOwnProperty.call(n,r)&&(e[r]=n[r])}return e},y.apply(this,arguments)}let d=!1,g=!1;const m={debug:1,default:2,info:2,warning:3,error:4,off:5};let b=m.default,w=null;const E=function(){try{const e=[];if(["NFD","NFC","NFKD","NFKC"].forEach(t=>{try{if("test"!=="test".normalize(t))throw new Error("bad normalize")}catch(n){e.push(t)}}),e.length)throw new Error("missing "+e.join(", "));if(String.fromCharCode(233).normalize("NFD")!==String.fromCharCode(101,769))throw new Error("broken implementation")}catch(e){return e.message}return null}();var T,I;!function(e){e.DEBUG="DEBUG",e.INFO="INFO",e.WARNING="WARNING",e.ERROR="ERROR",e.OFF="OFF"}(T||(T={})),function(e){e.UNKNOWN_ERROR="UNKNOWN_ERROR",e.NOT_IMPLEMENTED="NOT_IMPLEMENTED",e.UNSUPPORTED_OPERATION="UNSUPPORTED_OPERATION",e.NETWORK_ERROR="NETWORK_ERROR",e.SERVER_ERROR="SERVER_ERROR",e.TIMEOUT="TIMEOUT",e.BUFFER_OVERRUN="BUFFER_OVERRUN",e.NUMERIC_FAULT="NUMERIC_FAULT",e.MISSING_NEW="MISSING_NEW",e.INVALID_ARGUMENT="INVALID_ARGUMENT",e.MISSING_ARGUMENT="MISSING_ARGUMENT",e.UNEXPECTED_ARGUMENT="UNEXPECTED_ARGUMENT",e.CALL_EXCEPTION="CALL_EXCEPTION",e.INSUFFICIENT_FUNDS="INSUFFICIENT_FUNDS",e.NONCE_EXPIRED="NONCE_EXPIRED",e.REPLACEMENT_UNDERPRICED="REPLACEMENT_UNDERPRICED",e.UNPREDICTABLE_GAS_LIMIT="UNPREDICTABLE_GAS_LIMIT",e.TRANSACTION_REPLACED="TRANSACTION_REPLACED",e.ACTION_REJECTED="ACTION_REJECTED"}(I||(I={}));const A="0123456789abcdef";class v{constructor(e){Object.defineProperty(this,"version",{enumerable:!0,value:e,writable:!1})}_log(e,t){const n=e.toLowerCase();null==m[n]&&this.throwArgumentError("invalid log level name","logLevel",e),b>m[n]||console.log.apply(console,t)}debug(...e){this._log(v.levels.DEBUG,e)}info(...e){this._log(v.levels.INFO,e)}warn(...e){this._log(v.levels.WARNING,e)}makeError(e,t,n){if(g)return this.makeError("censored error",t,{});t||(t=v.errors.UNKNOWN_ERROR),n||(n={});const r=[];Object.keys(n).forEach(e=>{const t=n[e];try{if(t instanceof Uint8Array){let n="";for(let e=0;e<t.length;e++)n+=A[t[e]>>4],n+=A[15&t[e]];r.push(e+"=Uint8Array(0x"+n+")")}else r.push(e+"="+JSON.stringify(t))}catch(t){r.push(e+"="+JSON.stringify(n[e].toString()))}}),r.push(`code=${t}`),r.push(`version=${this.version}`);const i=e;let o="";switch(t){case I.NUMERIC_FAULT:{o="NUMERIC_FAULT";const t=e;switch(t){case"overflow":case"underflow":case"division-by-zero":o+="-"+t;break;case"negative-power":case"negative-width":o+="-unsupported";break;case"unbound-bitwise-result":o+="-unbound-result"}break}case I.CALL_EXCEPTION:case I.INSUFFICIENT_FUNDS:case I.MISSING_NEW:case I.NONCE_EXPIRED:case I.REPLACEMENT_UNDERPRICED:case I.TRANSACTION_REPLACED:case I.UNPREDICTABLE_GAS_LIMIT:o=t}o&&(e+=" [ See: https://links.ethers.org/v5-errors-"+o+" ]"),r.length&&(e+=" ("+r.join(", ")+")");const s=new Error(e);return s.reason=i,s.code=t,Object.keys(n).forEach(function(e){s[e]=n[e]}),s}throwError(e,t,n){throw this.makeError(e,t,n)}throwArgumentError(e,t,n){return this.throwError(e,v.errors.INVALID_ARGUMENT,{argument:t,value:n})}assert(e,t,n,r){e||this.throwError(t,n,r)}assertArgument(e,t,n,r){e||this.throwArgumentError(t,n,r)}checkNormalize(e){E&&this.throwError("platform missing String.prototype.normalize",v.errors.UNSUPPORTED_OPERATION,{operation:"String.prototype.normalize",form:E})}checkSafeUint53(e,t){"number"==typeof e&&(null==t&&(t="value not safe"),(e<0||e>=9007199254740991)&&this.throwError(t,v.errors.NUMERIC_FAULT,{operation:"checkSafeInteger",fault:"out-of-safe-range",value:e}),e%1&&this.throwError(t,v.errors.NUMERIC_FAULT,{operation:"checkSafeInteger",fault:"non-integer",value:e}))}checkArgumentCount(e,t,n){n=n?": "+n:"",e<t&&this.throwError("missing argument"+n,v.errors.MISSING_ARGUMENT,{count:e,expectedCount:t}),e>t&&this.throwError("too many arguments"+n,v.errors.UNEXPECTED_ARGUMENT,{count:e,expectedCount:t})}checkNew(e,t){e!==Object&&null!=e||this.throwError("missing new",v.errors.MISSING_NEW,{name:t.name})}checkAbstract(e,t){e===t?this.throwError("cannot instantiate abstract class "+JSON.stringify(t.name)+" directly; use a sub-class",v.errors.UNSUPPORTED_OPERATION,{name:e.name,operation:"new"}):e!==Object&&null!=e||this.throwError("missing new",v.errors.MISSING_NEW,{name:t.name})}static globalLogger(){return w||(w=new v("logger/5.7.0")),w}static setCensorship(e,t){if(!e&&t&&this.globalLogger().throwError("cannot permanently disable censorship",v.errors.UNSUPPORTED_OPERATION,{operation:"setCensorship"}),d){if(!e)return;this.globalLogger().throwError("error censorship permanent",v.errors.UNSUPPORTED_OPERATION,{operation:"setCensorship"})}g=!!e,d=!!t}static setLogLevel(e){const t=m[e.toLowerCase()];null!=t?b=t:v.globalLogger().warn("invalid log level - "+e)}static from(e){return new v(e)}}v.errors=I,v.levels=T;const R=new v("bytes/5.7.0");function B(e){return e.slice||(e.slice=function(){const t=Array.prototype.slice.call(arguments);return B(new Uint8Array(Array.prototype.slice.apply(e,t)))}),e}function S(e){return"number"==typeof e&&e==e&&e%1==0}function N(e,t){if(t||(t={}),"number"==typeof e){R.checkSafeUint53(e,"invalid arrayify value");const t=[];for(;e;)t.unshift(255&e),e=parseInt(String(e/256));return 0===t.length&&t.push(0),B(new Uint8Array(t))}if(t.allowMissingPrefix&&"string"==typeof e&&"0x"!==e.substring(0,2)&&(e="0x"+e),function(e){return!!e.toHexString}(e)&&(e=e.toHexString()),function(e,t){return!("string"!=typeof e||!e.match(/^0x[0-9A-Fa-f]*$/))}(e)){let n=e.substring(2);n.length%2&&("left"===t.hexPad?n="0"+n:"right"===t.hexPad?n+="0":R.throwArgumentError("hex data is odd-length","value",e));const r=[];for(let e=0;e<n.length;e+=2)r.push(parseInt(n.substring(e,e+2),16));return B(new Uint8Array(r))}return function(e){if(null==e)return!1;if(e.constructor===Uint8Array)return!0;if("string"==typeof e)return!1;if(!S(e.length)||e.length<0)return!1;for(let t=0;t<e.length;t++){const n=e[t];if(!S(n)||n<0||n>=256)return!1}return!0}(e)?B(new Uint8Array(e)):R.throwArgumentError("invalid arrayify value","value",e)}function P(e,t){(e=N(e)).length>t&&R.throwArgumentError("value out of range","value",arguments[0]);const n=new Uint8Array(t);return n.set(e,t-e.length),B(n)}for(var U=[],k=[],O="undefined"!=typeof Uint8Array?Uint8Array:Array,C="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/",_=0,M=C.length;_<M;++_)U[_]=C[_],k[C.charCodeAt(_)]=_;function F(e,t,n){for(var r,i=[],o=t;o<n;o+=3)i.push(U[(r=(e[o]<<16&16711680)+(e[o+1]<<8&65280)+(255&e[o+2]))>>18&63]+U[r>>12&63]+U[r>>6&63]+U[63&r]);return i.join("")}k["-".charCodeAt(0)]=62,k["_".charCodeAt(0)]=63;var L,D=function(e,t,n,r,i){var o,s,a=8*i-r-1,u=(1<<a)-1,f=u>>1,l=-7,c=n?i-1:0,p=n?-1:1,h=e[t+c];for(c+=p,o=h&(1<<-l)-1,h>>=-l,l+=a;l>0;o=256*o+e[t+c],c+=p,l-=8);for(s=o&(1<<-l)-1,o>>=-l,l+=r;l>0;s=256*s+e[t+c],c+=p,l-=8);if(0===o)o=1-f;else{if(o===u)return s?NaN:Infinity*(h?-1:1);s+=Math.pow(2,r),o-=f}return(h?-1:1)*s*Math.pow(2,o-r)},x=function(e,t,n,r,i,o){var s,a,u,f=8*o-i-1,l=(1<<f)-1,c=l>>1,p=23===i?Math.pow(2,-24)-Math.pow(2,-77):0,h=r?0:o-1,y=r?1:-1,d=t<0||0===t&&1/t<0?1:0;for(t=Math.abs(t),isNaN(t)||Infinity===t?(a=isNaN(t)?1:0,s=l):(s=Math.floor(Math.log(t)/Math.LN2),t*(u=Math.pow(2,-s))<1&&(s--,u*=2),(t+=s+c>=1?p/u:p*Math.pow(2,1-c))*u>=2&&(s++,u/=2),s+c>=l?(a=0,s=l):s+c>=1?(a=(t*u-1)*Math.pow(2,i),s+=c):(a=t*Math.pow(2,c-1)*Math.pow(2,i),s=0));i>=8;e[n+h]=255&a,h+=y,a/=256,i-=8);for(s=s<<i|a,f+=i;f>0;e[n+h]=255&s,h+=y,s/=256,f-=8);e[n+h-y]|=128*d},W=function(e){var t={exports:{}};return function(e,t){const n="function"==typeof Symbol&&"function"==typeof Symbol.for?Symbol.for("nodejs.util.inspect.custom"):null;t.Buffer=o,t.SlowBuffer=function(e){return+e!=e&&(e=0),o.alloc(+e)},t.INSPECT_MAX_BYTES=50;const r=2147483647;function i(e){if(e>r)throw new RangeError('The value "'+e+'" is invalid for option "size"');const t=new Uint8Array(e);return Object.setPrototypeOf(t,o.prototype),t}function o(e,t,n){if("number"==typeof e){if("string"==typeof t)throw new TypeError('The "string" argument must be of type string. Received type number');return u(e)}return s(e,t,n)}function s(e,t,n){if("string"==typeof e)return function(e,t){if("string"==typeof t&&""!==t||(t="utf8"),!o.isEncoding(t))throw new TypeError("Unknown encoding: "+t);const n=0|p(e,t);let r=i(n);const s=r.write(e,t);return s!==n&&(r=r.slice(0,s)),r}(e,t);if(ArrayBuffer.isView(e))return function(e){if(H(e,Uint8Array)){const t=new Uint8Array(e);return l(t.buffer,t.byteOffset,t.byteLength)}return f(e)}(e);if(null==e)throw new TypeError("The first argument must be one of type string, Buffer, ArrayBuffer, Array, or Array-like Object. Received type "+typeof e);if(H(e,ArrayBuffer)||e&&H(e.buffer,ArrayBuffer))return l(e,t,n);if("undefined"!=typeof SharedArrayBuffer&&(H(e,SharedArrayBuffer)||e&&H(e.buffer,SharedArrayBuffer)))return l(e,t,n);if("number"==typeof e)throw new TypeError('The "value" argument must not be of type number. Received type number');const r=e.valueOf&&e.valueOf();if(null!=r&&r!==e)return o.from(r,t,n);const s=function(e){if(o.isBuffer(e)){const t=0|c(e.length),n=i(t);return 0===n.length||e.copy(n,0,0,t),n}return void 0!==e.length?"number"!=typeof e.length||Q(e.length)?i(0):f(e):"Buffer"===e.type&&Array.isArray(e.data)?f(e.data):void 0}(e);if(s)return s;if("undefined"!=typeof Symbol&&null!=Symbol.toPrimitive&&"function"==typeof e[Symbol.toPrimitive])return o.from(e[Symbol.toPrimitive]("string"),t,n);throw new TypeError("The first argument must be one of type string, Buffer, ArrayBuffer, Array, or Array-like Object. Received type "+typeof e)}function a(e){if("number"!=typeof e)throw new TypeError('"size" argument must be of type number');if(e<0)throw new RangeError('The value "'+e+'" is invalid for option "size"')}function u(e){return a(e),i(e<0?0:0|c(e))}function f(e){const t=e.length<0?0:0|c(e.length),n=i(t);for(let r=0;r<t;r+=1)n[r]=255&e[r];return n}function l(e,t,n){if(t<0||e.byteLength<t)throw new RangeError('"offset" is outside of buffer bounds');if(e.byteLength<t+(n||0))throw new RangeError('"length" is outside of buffer bounds');let r;return r=void 0===t&&void 0===n?new Uint8Array(e):void 0===n?new Uint8Array(e,t):new Uint8Array(e,t,n),Object.setPrototypeOf(r,o.prototype),r}function c(e){if(e>=r)throw new RangeError("Attempt to allocate Buffer larger than maximum size: 0x"+r.toString(16)+" bytes");return 0|e}function p(e,t){if(o.isBuffer(e))return e.length;if(ArrayBuffer.isView(e)||H(e,ArrayBuffer))return e.byteLength;if("string"!=typeof e)throw new TypeError('The "string" argument must be one of type string, Buffer, or ArrayBuffer. Received type '+typeof e);const n=e.length,r=arguments.length>2&&!0===arguments[2];if(!r&&0===n)return 0;let i=!1;for(;;)switch(t){case"ascii":case"latin1":case"binary":return n;case"utf8":case"utf-8":return Y(e).length;case"ucs2":case"ucs-2":case"utf16le":case"utf-16le":return 2*n;case"hex":return n>>>1;case"base64":return J(e).length;default:if(i)return r?-1:Y(e).length;t=(""+t).toLowerCase(),i=!0}}function h(e,t,n){let r=!1;if((void 0===t||t<0)&&(t=0),t>this.length)return"";if((void 0===n||n>this.length)&&(n=this.length),n<=0)return"";if((n>>>=0)<=(t>>>=0))return"";for(e||(e="utf8");;)switch(e){case"hex":return S(this,t,n);case"utf8":case"utf-8":return A(this,t,n);case"ascii":return R(this,t,n);case"latin1":case"binary":return B(this,t,n);case"base64":return I(this,t,n);case"ucs2":case"ucs-2":case"utf16le":case"utf-16le":return N(this,t,n);default:if(r)throw new TypeError("Unknown encoding: "+e);e=(e+"").toLowerCase(),r=!0}}function y(e,t,n){const r=e[t];e[t]=e[n],e[n]=r}function d(e,t,n,r,i){if(0===e.length)return-1;if("string"==typeof n?(r=n,n=0):n>2147483647?n=2147483647:n<-2147483648&&(n=-2147483648),Q(n=+n)&&(n=i?0:e.length-1),n<0&&(n=e.length+n),n>=e.length){if(i)return-1;n=e.length-1}else if(n<0){if(!i)return-1;n=0}if("string"==typeof t&&(t=o.from(t,r)),o.isBuffer(t))return 0===t.length?-1:g(e,t,n,r,i);if("number"==typeof t)return t&=255,"function"==typeof Uint8Array.prototype.indexOf?i?Uint8Array.prototype.indexOf.call(e,t,n):Uint8Array.prototype.lastIndexOf.call(e,t,n):g(e,[t],n,r,i);throw new TypeError("val must be string, number or Buffer")}function g(e,t,n,r,i){let o,s=1,a=e.length,u=t.length;if(void 0!==r&&("ucs2"===(r=String(r).toLowerCase())||"ucs-2"===r||"utf16le"===r||"utf-16le"===r)){if(e.length<2||t.length<2)return-1;s=2,a/=2,u/=2,n/=2}function f(e,t){return 1===s?e[t]:e.readUInt16BE(t*s)}if(i){let r=-1;for(o=n;o<a;o++)if(f(e,o)===f(t,-1===r?0:o-r)){if(-1===r&&(r=o),o-r+1===u)return r*s}else-1!==r&&(o-=o-r),r=-1}else for(n+u>a&&(n=a-u),o=n;o>=0;o--){let n=!0;for(let r=0;r<u;r++)if(f(e,o+r)!==f(t,r)){n=!1;break}if(n)return o}return-1}function m(e,t,n,r){n=Number(n)||0;const i=e.length-n;r?(r=Number(r))>i&&(r=i):r=i;const o=t.length;let s;for(r>o/2&&(r=o/2),s=0;s<r;++s){const r=parseInt(t.substr(2*s,2),16);if(Q(r))return s;e[n+s]=r}return s}function b(e,t,n,r){return Z(Y(t,e.length-n),e,n,r)}function w(e,t,n,r){return Z(function(e){const t=[];for(let n=0;n<e.length;++n)t.push(255&e.charCodeAt(n));return t}(t),e,n,r)}function E(e,t,n,r){return Z(J(t),e,n,r)}function T(e,t,n,r){return Z(function(e,t){let n,r,i;const o=[];for(let s=0;s<e.length&&!((t-=2)<0);++s)n=e.charCodeAt(s),r=n>>8,i=n%256,o.push(i),o.push(r);return o}(t,e.length-n),e,n,r)}function I(e,t,n){return function(e){for(var t,n=e.length,r=n%3,i=[],o=16383,s=0,a=n-r;s<a;s+=o)i.push(F(e,s,s+o>a?a:s+o));return 1===r?i.push(U[(t=e[n-1])>>2]+U[t<<4&63]+"=="):2===r&&i.push(U[(t=(e[n-2]<<8)+e[n-1])>>10]+U[t>>4&63]+U[t<<2&63]+"="),i.join("")}(0===t&&n===e.length?e:e.slice(t,n))}function A(e,t,n){n=Math.min(e.length,n);const r=[];let i=t;for(;i<n;){const t=e[i];let o=null,s=t>239?4:t>223?3:t>191?2:1;if(i+s<=n){let n,r,a,u;switch(s){case 1:t<128&&(o=t);break;case 2:n=e[i+1],128==(192&n)&&(u=(31&t)<<6|63&n,u>127&&(o=u));break;case 3:n=e[i+1],r=e[i+2],128==(192&n)&&128==(192&r)&&(u=(15&t)<<12|(63&n)<<6|63&r,u>2047&&(u<55296||u>57343)&&(o=u));break;case 4:n=e[i+1],r=e[i+2],a=e[i+3],128==(192&n)&&128==(192&r)&&128==(192&a)&&(u=(15&t)<<18|(63&n)<<12|(63&r)<<6|63&a,u>65535&&u<1114112&&(o=u))}}null===o?(o=65533,s=1):o>65535&&(o-=65536,r.push(o>>>10&1023|55296),o=56320|1023&o),r.push(o),i+=s}return function(e){const t=e.length;if(t<=v)return String.fromCharCode.apply(String,e);let n="",r=0;for(;r<t;)n+=String.fromCharCode.apply(String,e.slice(r,r+=v));return n}(r)}t.kMaxLength=r,(o.TYPED_ARRAY_SUPPORT=function(){try{const e=new Uint8Array(1),t={foo:function(){return 42}};return Object.setPrototypeOf(t,Uint8Array.prototype),Object.setPrototypeOf(e,t),42===e.foo()}catch(e){return!1}}())||"undefined"==typeof console||"function"!=typeof console.error||console.error("This browser lacks typed array (Uint8Array) support which is required by `buffer` v5.x. Use `buffer` v4.x if you require old browser support."),Object.defineProperty(o.prototype,"parent",{enumerable:!0,get:function(){if(o.isBuffer(this))return this.buffer}}),Object.defineProperty(o.prototype,"offset",{enumerable:!0,get:function(){if(o.isBuffer(this))return this.byteOffset}}),o.poolSize=8192,o.from=function(e,t,n){return s(e,t,n)},Object.setPrototypeOf(o.prototype,Uint8Array.prototype),Object.setPrototypeOf(o,Uint8Array),o.alloc=function(e,t,n){return function(e,t,n){return a(e),e<=0?i(e):void 0!==t?"string"==typeof n?i(e).fill(t,n):i(e).fill(t):i(e)}(e,t,n)},o.allocUnsafe=function(e){return u(e)},o.allocUnsafeSlow=function(e){return u(e)},o.isBuffer=function(e){return null!=e&&!0===e._isBuffer&&e!==o.prototype},o.compare=function(e,t){if(H(e,Uint8Array)&&(e=o.from(e,e.offset,e.byteLength)),H(t,Uint8Array)&&(t=o.from(t,t.offset,t.byteLength)),!o.isBuffer(e)||!o.isBuffer(t))throw new TypeError('The "buf1", "buf2" arguments must be one of type Buffer or Uint8Array');if(e===t)return 0;let n=e.length,r=t.length;for(let i=0,o=Math.min(n,r);i<o;++i)if(e[i]!==t[i]){n=e[i],r=t[i];break}return n<r?-1:r<n?1:0},o.isEncoding=function(e){switch(String(e).toLowerCase()){case"hex":case"utf8":case"utf-8":case"ascii":case"latin1":case"binary":case"base64":case"ucs2":case"ucs-2":case"utf16le":case"utf-16le":return!0;default:return!1}},o.concat=function(e,t){if(!Array.isArray(e))throw new TypeError('"list" argument must be an Array of Buffers');if(0===e.length)return o.alloc(0);let n;if(void 0===t)for(t=0,n=0;n<e.length;++n)t+=e[n].length;const r=o.allocUnsafe(t);let i=0;for(n=0;n<e.length;++n){let t=e[n];if(H(t,Uint8Array))i+t.length>r.length?(o.isBuffer(t)||(t=o.from(t)),t.copy(r,i)):Uint8Array.prototype.set.call(r,t,i);else{if(!o.isBuffer(t))throw new TypeError('"list" argument must be an Array of Buffers');t.copy(r,i)}i+=t.length}return r},o.byteLength=p,o.prototype._isBuffer=!0,o.prototype.swap16=function(){const e=this.length;if(e%2!=0)throw new RangeError("Buffer size must be a multiple of 16-bits");for(let t=0;t<e;t+=2)y(this,t,t+1);return this},o.prototype.swap32=function(){const e=this.length;if(e%4!=0)throw new RangeError("Buffer size must be a multiple of 32-bits");for(let t=0;t<e;t+=4)y(this,t,t+3),y(this,t+1,t+2);return this},o.prototype.swap64=function(){const e=this.length;if(e%8!=0)throw new RangeError("Buffer size must be a multiple of 64-bits");for(let t=0;t<e;t+=8)y(this,t,t+7),y(this,t+1,t+6),y(this,t+2,t+5),y(this,t+3,t+4);return this},o.prototype.toLocaleString=o.prototype.toString=function(){const e=this.length;return 0===e?"":0===arguments.length?A(this,0,e):h.apply(this,arguments)},o.prototype.equals=function(e){if(!o.isBuffer(e))throw new TypeError("Argument must be a Buffer");return this===e||0===o.compare(this,e)},o.prototype.inspect=function(){let e="";const n=t.INSPECT_MAX_BYTES;return e=this.toString("hex",0,n).replace(/(.{2})/g,"$1 ").trim(),this.length>n&&(e+=" ... "),"<Buffer "+e+">"},n&&(o.prototype[n]=o.prototype.inspect),o.prototype.compare=function(e,t,n,r,i){if(H(e,Uint8Array)&&(e=o.from(e,e.offset,e.byteLength)),!o.isBuffer(e))throw new TypeError('The "target" argument must be one of type Buffer or Uint8Array. Received type '+typeof e);if(void 0===t&&(t=0),void 0===n&&(n=e?e.length:0),void 0===r&&(r=0),void 0===i&&(i=this.length),t<0||n>e.length||r<0||i>this.length)throw new RangeError("out of range index");if(r>=i&&t>=n)return 0;if(r>=i)return-1;if(t>=n)return 1;if(this===e)return 0;let s=(i>>>=0)-(r>>>=0),a=(n>>>=0)-(t>>>=0);const u=Math.min(s,a),f=this.slice(r,i),l=e.slice(t,n);for(let e=0;e<u;++e)if(f[e]!==l[e]){s=f[e],a=l[e];break}return s<a?-1:a<s?1:0},o.prototype.includes=function(e,t,n){return-1!==this.indexOf(e,t,n)},o.prototype.indexOf=function(e,t,n){return d(this,e,t,n,!0)},o.prototype.lastIndexOf=function(e,t,n){return d(this,e,t,n,!1)},o.prototype.write=function(e,t,n,r){if(void 0===t)r="utf8",n=this.length,t=0;else if(void 0===n&&"string"==typeof t)r=t,n=this.length,t=0;else{if(!isFinite(t))throw new Error("Buffer.write(string, encoding, offset[, length]) is no longer supported");t>>>=0,isFinite(n)?(n>>>=0,void 0===r&&(r="utf8")):(r=n,n=void 0)}const i=this.length-t;if((void 0===n||n>i)&&(n=i),e.length>0&&(n<0||t<0)||t>this.length)throw new RangeError("Attempt to write outside buffer bounds");r||(r="utf8");let o=!1;for(;;)switch(r){case"hex":return m(this,e,t,n);case"utf8":case"utf-8":return b(this,e,t,n);case"ascii":case"latin1":case"binary":return w(this,e,t,n);case"base64":return E(this,e,t,n);case"ucs2":case"ucs-2":case"utf16le":case"utf-16le":return T(this,e,t,n);default:if(o)throw new TypeError("Unknown encoding: "+r);r=(""+r).toLowerCase(),o=!0}},o.prototype.toJSON=function(){return{type:"Buffer",data:Array.prototype.slice.call(this._arr||this,0)}};const v=4096;function R(e,t,n){let r="";n=Math.min(e.length,n);for(let i=t;i<n;++i)r+=String.fromCharCode(127&e[i]);return r}function B(e,t,n){let r="";n=Math.min(e.length,n);for(let i=t;i<n;++i)r+=String.fromCharCode(e[i]);return r}function S(e,t,n){const r=e.length;(!t||t<0)&&(t=0),(!n||n<0||n>r)&&(n=r);let i="";for(let r=t;r<n;++r)i+=ee[e[r]];return i}function N(e,t,n){const r=e.slice(t,n);let i="";for(let e=0;e<r.length-1;e+=2)i+=String.fromCharCode(r[e]+256*r[e+1]);return i}function P(e,t,n){if(e%1!=0||e<0)throw new RangeError("offset is not uint");if(e+t>n)throw new RangeError("Trying to access beyond buffer length")}function C(e,t,n,r,i,s){if(!o.isBuffer(e))throw new TypeError('"buffer" argument must be a Buffer instance');if(t>i||t<s)throw new RangeError('"value" argument is out of bounds');if(n+r>e.length)throw new RangeError("Index out of range")}function _(e,t,n,r,i){z(t,r,i,e,n,7);let o=Number(t&BigInt(4294967295));e[n++]=o,o>>=8,e[n++]=o,o>>=8,e[n++]=o,o>>=8,e[n++]=o;let s=Number(t>>BigInt(32)&BigInt(4294967295));return e[n++]=s,s>>=8,e[n++]=s,s>>=8,e[n++]=s,s>>=8,e[n++]=s,n}function M(e,t,n,r,i){z(t,r,i,e,n,7);let o=Number(t&BigInt(4294967295));e[n+7]=o,o>>=8,e[n+6]=o,o>>=8,e[n+5]=o,o>>=8,e[n+4]=o;let s=Number(t>>BigInt(32)&BigInt(4294967295));return e[n+3]=s,s>>=8,e[n+2]=s,s>>=8,e[n+1]=s,s>>=8,e[n]=s,n+8}function L(e,t,n,r,i,o){if(n+r>e.length)throw new RangeError("Index out of range");if(n<0)throw new RangeError("Index out of range")}function W(e,t,n,r,i){return t=+t,n>>>=0,i||L(e,0,n,4),x(e,t,n,r,23,4),n+4}function K(e,t,n,r,i){return t=+t,n>>>=0,i||L(e,0,n,8),x(e,t,n,r,52,8),n+8}o.prototype.slice=function(e,t){const n=this.length;(e=~~e)<0?(e+=n)<0&&(e=0):e>n&&(e=n),(t=void 0===t?n:~~t)<0?(t+=n)<0&&(t=0):t>n&&(t=n),t<e&&(t=e);const r=this.subarray(e,t);return Object.setPrototypeOf(r,o.prototype),r},o.prototype.readUintLE=o.prototype.readUIntLE=function(e,t,n){e>>>=0,t>>>=0,n||P(e,t,this.length);let r=this[e],i=1,o=0;for(;++o<t&&(i*=256);)r+=this[e+o]*i;return r},o.prototype.readUintBE=o.prototype.readUIntBE=function(e,t,n){e>>>=0,t>>>=0,n||P(e,t,this.length);let r=this[e+--t],i=1;for(;t>0&&(i*=256);)r+=this[e+--t]*i;return r},o.prototype.readUint8=o.prototype.readUInt8=function(e,t){return e>>>=0,t||P(e,1,this.length),this[e]},o.prototype.readUint16LE=o.prototype.readUInt16LE=function(e,t){return e>>>=0,t||P(e,2,this.length),this[e]|this[e+1]<<8},o.prototype.readUint16BE=o.prototype.readUInt16BE=function(e,t){return e>>>=0,t||P(e,2,this.length),this[e]<<8|this[e+1]},o.prototype.readUint32LE=o.prototype.readUInt32LE=function(e,t){return e>>>=0,t||P(e,4,this.length),(this[e]|this[e+1]<<8|this[e+2]<<16)+16777216*this[e+3]},o.prototype.readUint32BE=o.prototype.readUInt32BE=function(e,t){return e>>>=0,t||P(e,4,this.length),16777216*this[e]+(this[e+1]<<16|this[e+2]<<8|this[e+3])},o.prototype.readBigUInt64LE=te(function(e){V(e>>>=0,"offset");const t=this[e],n=this[e+7];void 0!==t&&void 0!==n||q(e,this.length-8);const r=t+256*this[++e]+65536*this[++e]+this[++e]*2**24,i=this[++e]+256*this[++e]+65536*this[++e]+n*2**24;return BigInt(r)+(BigInt(i)<<BigInt(32))}),o.prototype.readBigUInt64BE=te(function(e){V(e>>>=0,"offset");const t=this[e],n=this[e+7];void 0!==t&&void 0!==n||q(e,this.length-8);const r=t*2**24+65536*this[++e]+256*this[++e]+this[++e],i=this[++e]*2**24+65536*this[++e]+256*this[++e]+n;return(BigInt(r)<<BigInt(32))+BigInt(i)}),o.prototype.readIntLE=function(e,t,n){e>>>=0,t>>>=0,n||P(e,t,this.length);let r=this[e],i=1,o=0;for(;++o<t&&(i*=256);)r+=this[e+o]*i;return i*=128,r>=i&&(r-=Math.pow(2,8*t)),r},o.prototype.readIntBE=function(e,t,n){e>>>=0,t>>>=0,n||P(e,t,this.length);let r=t,i=1,o=this[e+--r];for(;r>0&&(i*=256);)o+=this[e+--r]*i;return i*=128,o>=i&&(o-=Math.pow(2,8*t)),o},o.prototype.readInt8=function(e,t){return e>>>=0,t||P(e,1,this.length),128&this[e]?-1*(255-this[e]+1):this[e]},o.prototype.readInt16LE=function(e,t){e>>>=0,t||P(e,2,this.length);const n=this[e]|this[e+1]<<8;return 32768&n?4294901760|n:n},o.prototype.readInt16BE=function(e,t){e>>>=0,t||P(e,2,this.length);const n=this[e+1]|this[e]<<8;return 32768&n?4294901760|n:n},o.prototype.readInt32LE=function(e,t){return e>>>=0,t||P(e,4,this.length),this[e]|this[e+1]<<8|this[e+2]<<16|this[e+3]<<24},o.prototype.readInt32BE=function(e,t){return e>>>=0,t||P(e,4,this.length),this[e]<<24|this[e+1]<<16|this[e+2]<<8|this[e+3]},o.prototype.readBigInt64LE=te(function(e){V(e>>>=0,"offset");const t=this[e],n=this[e+7];return void 0!==t&&void 0!==n||q(e,this.length-8),(BigInt(this[e+4]+256*this[e+5]+65536*this[e+6]+(n<<24))<<BigInt(32))+BigInt(t+256*this[++e]+65536*this[++e]+this[++e]*2**24)}),o.prototype.readBigInt64BE=te(function(e){V(e>>>=0,"offset");const t=this[e],n=this[e+7];void 0!==t&&void 0!==n||q(e,this.length-8);const r=(t<<24)+65536*this[++e]+256*this[++e]+this[++e];return(BigInt(r)<<BigInt(32))+BigInt(this[++e]*2**24+65536*this[++e]+256*this[++e]+n)}),o.prototype.readFloatLE=function(e,t){return e>>>=0,t||P(e,4,this.length),D(this,e,!0,23,4)},o.prototype.readFloatBE=function(e,t){return e>>>=0,t||P(e,4,this.length),D(this,e,!1,23,4)},o.prototype.readDoubleLE=function(e,t){return e>>>=0,t||P(e,8,this.length),D(this,e,!0,52,8)},o.prototype.readDoubleBE=function(e,t){return e>>>=0,t||P(e,8,this.length),D(this,e,!1,52,8)},o.prototype.writeUintLE=o.prototype.writeUIntLE=function(e,t,n,r){e=+e,t>>>=0,n>>>=0,r||C(this,e,t,n,Math.pow(2,8*n)-1,0);let i=1,o=0;for(this[t]=255&e;++o<n&&(i*=256);)this[t+o]=e/i&255;return t+n},o.prototype.writeUintBE=o.prototype.writeUIntBE=function(e,t,n,r){e=+e,t>>>=0,n>>>=0,r||C(this,e,t,n,Math.pow(2,8*n)-1,0);let i=n-1,o=1;for(this[t+i]=255&e;--i>=0&&(o*=256);)this[t+i]=e/o&255;return t+n},o.prototype.writeUint8=o.prototype.writeUInt8=function(e,t,n){return e=+e,t>>>=0,n||C(this,e,t,1,255,0),this[t]=255&e,t+1},o.prototype.writeUint16LE=o.prototype.writeUInt16LE=function(e,t,n){return e=+e,t>>>=0,n||C(this,e,t,2,65535,0),this[t]=255&e,this[t+1]=e>>>8,t+2},o.prototype.writeUint16BE=o.prototype.writeUInt16BE=function(e,t,n){return e=+e,t>>>=0,n||C(this,e,t,2,65535,0),this[t]=e>>>8,this[t+1]=255&e,t+2},o.prototype.writeUint32LE=o.prototype.writeUInt32LE=function(e,t,n){return e=+e,t>>>=0,n||C(this,e,t,4,4294967295,0),this[t+3]=e>>>24,this[t+2]=e>>>16,this[t+1]=e>>>8,this[t]=255&e,t+4},o.prototype.writeUint32BE=o.prototype.writeUInt32BE=function(e,t,n){return e=+e,t>>>=0,n||C(this,e,t,4,4294967295,0),this[t]=e>>>24,this[t+1]=e>>>16,this[t+2]=e>>>8,this[t+3]=255&e,t+4},o.prototype.writeBigUInt64LE=te(function(e,t=0){return _(this,e,t,BigInt(0),BigInt("0xffffffffffffffff"))}),o.prototype.writeBigUInt64BE=te(function(e,t=0){return M(this,e,t,BigInt(0),BigInt("0xffffffffffffffff"))}),o.prototype.writeIntLE=function(e,t,n,r){if(e=+e,t>>>=0,!r){const r=Math.pow(2,8*n-1);C(this,e,t,n,r-1,-r)}let i=0,o=1,s=0;for(this[t]=255&e;++i<n&&(o*=256);)e<0&&0===s&&0!==this[t+i-1]&&(s=1),this[t+i]=(e/o>>0)-s&255;return t+n},o.prototype.writeIntBE=function(e,t,n,r){if(e=+e,t>>>=0,!r){const r=Math.pow(2,8*n-1);C(this,e,t,n,r-1,-r)}let i=n-1,o=1,s=0;for(this[t+i]=255&e;--i>=0&&(o*=256);)e<0&&0===s&&0!==this[t+i+1]&&(s=1),this[t+i]=(e/o>>0)-s&255;return t+n},o.prototype.writeInt8=function(e,t,n){return e=+e,t>>>=0,n||C(this,e,t,1,127,-128),e<0&&(e=255+e+1),this[t]=255&e,t+1},o.prototype.writeInt16LE=function(e,t,n){return e=+e,t>>>=0,n||C(this,e,t,2,32767,-32768),this[t]=255&e,this[t+1]=e>>>8,t+2},o.prototype.writeInt16BE=function(e,t,n){return e=+e,t>>>=0,n||C(this,e,t,2,32767,-32768),this[t]=e>>>8,this[t+1]=255&e,t+2},o.prototype.writeInt32LE=function(e,t,n){return e=+e,t>>>=0,n||C(this,e,t,4,2147483647,-2147483648),this[t]=255&e,this[t+1]=e>>>8,this[t+2]=e>>>16,this[t+3]=e>>>24,t+4},o.prototype.writeInt32BE=function(e,t,n){return e=+e,t>>>=0,n||C(this,e,t,4,2147483647,-2147483648),e<0&&(e=4294967295+e+1),this[t]=e>>>24,this[t+1]=e>>>16,this[t+2]=e>>>8,this[t+3]=255&e,t+4},o.prototype.writeBigInt64LE=te(function(e,t=0){return _(this,e,t,-BigInt("0x8000000000000000"),BigInt("0x7fffffffffffffff"))}),o.prototype.writeBigInt64BE=te(function(e,t=0){return M(this,e,t,-BigInt("0x8000000000000000"),BigInt("0x7fffffffffffffff"))}),o.prototype.writeFloatLE=function(e,t,n){return W(this,e,t,!0,n)},o.prototype.writeFloatBE=function(e,t,n){return W(this,e,t,!1,n)},o.prototype.writeDoubleLE=function(e,t,n){return K(this,e,t,!0,n)},o.prototype.writeDoubleBE=function(e,t,n){return K(this,e,t,!1,n)},o.prototype.copy=function(e,t,n,r){if(!o.isBuffer(e))throw new TypeError("argument should be a Buffer");if(n||(n=0),r||0===r||(r=this.length),t>=e.length&&(t=e.length),t||(t=0),r>0&&r<n&&(r=n),r===n)return 0;if(0===e.length||0===this.length)return 0;if(t<0)throw new RangeError("targetStart out of bounds");if(n<0||n>=this.length)throw new RangeError("Index out of range");if(r<0)throw new RangeError("sourceEnd out of bounds");r>this.length&&(r=this.length),e.length-t<r-n&&(r=e.length-t+n);const i=r-n;return this===e&&"function"==typeof Uint8Array.prototype.copyWithin?this.copyWithin(t,n,r):Uint8Array.prototype.set.call(e,this.subarray(n,r),t),i},o.prototype.fill=function(e,t,n,r){if("string"==typeof e){if("string"==typeof t?(r=t,t=0,n=this.length):"string"==typeof n&&(r=n,n=this.length),void 0!==r&&"string"!=typeof r)throw new TypeError("encoding must be a string");if("string"==typeof r&&!o.isEncoding(r))throw new TypeError("Unknown encoding: "+r);if(1===e.length){const t=e.charCodeAt(0);("utf8"===r&&t<128||"latin1"===r)&&(e=t)}}else"number"==typeof e?e&=255:"boolean"==typeof e&&(e=Number(e));if(t<0||this.length<t||this.length<n)throw new RangeError("Out of range index");if(n<=t)return this;let i;if(t>>>=0,n=void 0===n?this.length:n>>>0,e||(e=0),"number"==typeof e)for(i=t;i<n;++i)this[i]=e;else{const s=o.isBuffer(e)?e:o.from(e,r),a=s.length;if(0===a)throw new TypeError('The value "'+e+'" is invalid for argument "value"');for(i=0;i<n-t;++i)this[i+t]=s[i%a]}return this};const j={};function G(e,t,n){j[e]=class extends n{constructor(){super(),Object.defineProperty(this,"message",{value:t.apply(this,arguments),writable:!0,configurable:!0}),this.name=`${this.name} [${e}]`,delete this.name}get code(){return e}set code(e){Object.defineProperty(this,"code",{configurable:!0,enumerable:!0,value:e,writable:!0})}toString(){return`${this.name} [${e}]: ${this.message}`}}}function $(e){let t="",n=e.length;const r="-"===e[0]?1:0;for(;n>=r+4;n-=3)t=`_${e.slice(n-3,n)}${t}`;return`${e.slice(0,n)}${t}`}function z(e,t,n,r,i,o){if(e>n||e<t){const r="bigint"==typeof t?"n":"";let i;throw i=o>3?0===t||t===BigInt(0)?`>= 0${r} and < 2${r} ** ${8*(o+1)}${r}`:`>= -(2${r} ** ${8*(o+1)-1}${r}) and < 2 ** ${8*(o+1)-1}${r}`:`>= ${t}${r} and <= ${n}${r}`,new j.ERR_OUT_OF_RANGE("value",i,e)}!function(e,t,n){V(t,"offset"),void 0!==e[t]&&void 0!==e[t+n]||q(t,e.length-(n+1))}(r,i,o)}function V(e,t){if("number"!=typeof e)throw new j.ERR_INVALID_ARG_TYPE(t,"number",e)}function q(e,t,n){if(Math.floor(e)!==e)throw V(e,n),new j.ERR_OUT_OF_RANGE(n||"offset","an integer",e);if(t<0)throw new j.ERR_BUFFER_OUT_OF_BOUNDS;throw new j.ERR_OUT_OF_RANGE(n||"offset",`>= ${n?1:0} and <= ${t}`,e)}G("ERR_BUFFER_OUT_OF_BOUNDS",function(e){return e?`${e} is outside of buffer bounds`:"Attempt to access memory outside buffer bounds"},RangeError),G("ERR_INVALID_ARG_TYPE",function(e,t){return`The "${e}" argument must be of type number. Received type ${typeof t}`},TypeError),G("ERR_OUT_OF_RANGE",function(e,t,n){let r=`The value of "${e}" is out of range.`,i=n;return Number.isInteger(n)&&Math.abs(n)>2**32?i=$(String(n)):"bigint"==typeof n&&(i=String(n),(n>BigInt(2)**BigInt(32)||n<-(BigInt(2)**BigInt(32)))&&(i=$(i)),i+="n"),r+=` It must be ${t}. Received ${i}`,r},RangeError);const X=/[^+/0-9A-Za-z-_]/g;function Y(e,t){let n;t=t||Infinity;const r=e.length;let i=null;const o=[];for(let s=0;s<r;++s){if(n=e.charCodeAt(s),n>55295&&n<57344){if(!i){if(n>56319){(t-=3)>-1&&o.push(239,191,189);continue}if(s+1===r){(t-=3)>-1&&o.push(239,191,189);continue}i=n;continue}if(n<56320){(t-=3)>-1&&o.push(239,191,189),i=n;continue}n=65536+(i-55296<<10|n-56320)}else i&&(t-=3)>-1&&o.push(239,191,189);if(i=null,n<128){if((t-=1)<0)break;o.push(n)}else if(n<2048){if((t-=2)<0)break;o.push(n>>6|192,63&n|128)}else if(n<65536){if((t-=3)<0)break;o.push(n>>12|224,n>>6&63|128,63&n|128)}else{if(!(n<1114112))throw new Error("Invalid code point");if((t-=4)<0)break;o.push(n>>18|240,n>>12&63|128,n>>6&63|128,63&n|128)}}return o}function J(e){return function(e){var t,n,r=function(e){var t=e.length;if(t%4>0)throw new Error("Invalid string. Length must be a multiple of 4");var n=e.indexOf("=");return-1===n&&(n=t),[n,n===t?0:4-n%4]}(e),i=r[0],o=r[1],s=new O(function(e,t,n){return 3*(t+n)/4-n}(0,i,o)),a=0,u=o>0?i-4:i;for(n=0;n<u;n+=4)t=k[e.charCodeAt(n)]<<18|k[e.charCodeAt(n+1)]<<12|k[e.charCodeAt(n+2)]<<6|k[e.charCodeAt(n+3)],s[a++]=t>>16&255,s[a++]=t>>8&255,s[a++]=255&t;return 2===o&&(t=k[e.charCodeAt(n)]<<2|k[e.charCodeAt(n+1)]>>4,s[a++]=255&t),1===o&&(t=k[e.charCodeAt(n)]<<10|k[e.charCodeAt(n+1)]<<4|k[e.charCodeAt(n+2)]>>2,s[a++]=t>>8&255,s[a++]=255&t),s}(function(e){if((e=(e=e.split("=")[0]).trim().replace(X,"")).length<2)return"";for(;e.length%4!=0;)e+="=";return e}(e))}function Z(e,t,n,r){let i;for(i=0;i<r&&!(i+n>=t.length||i>=e.length);++i)t[i+n]=e[i];return i}function H(e,t){return e instanceof t||null!=e&&null!=e.constructor&&null!=e.constructor.name&&e.constructor.name===t.name}function Q(e){return e!=e}const ee=function(){const e="0123456789abcdef",t=new Array(256);for(let n=0;n<16;++n){const r=16*n;for(let i=0;i<16;++i)t[r+i]=e[n]+e[i]}return t}();function te(e){return"undefined"==typeof BigInt?ne:e}function ne(){throw new Error("BigInt not supported")}}(0,t.exports),t.exports}();function K(e,t){var n;if(1===t)n=P(new r.PublicKey(e).toBytes(),32);else{if(2!==t&&4!==t&&5!==t&&6!==t&&22!==t)throw new Error("Unsupported token chain");if(22===t&&/^(0x)?[0-9a-fA-F]+::\w+::\w+$/.test(e))return"0x"+i.sha3_256(e);for(var o=e.substring(2),s=[],a=0;a<o.length;a+=2)s.push(parseInt(o.substring(a,a+2),16));n=P(new Uint8Array(s),32)}return"0x"+W.Buffer.from(n).toString("hex")}function j(e,t,n,i,o){if(void 0===n&&(n=!1),void 0===i&&(i=new r.PublicKey(l)),void 0===o&&(o=new r.PublicKey(c)),!n&&!r.PublicKey.isOnCurve(t.toBuffer()))throw new Error("TokenOwnerOffCurveError");return r.PublicKey.findProgramAddressSync([t.toBuffer(),i.toBuffer(),e.toBuffer()],o)[0]}function G(e,t){var r=Number(e).toFixed(Math.min(8,Number(t)));return n.ethers.utils.parseUnits(r,Number(t))}var $={solana:1,ethereum:2,bsc:4,polygon:5,avalanche:6,aptos:22};function z(e){return $[e]}var V=((L={})[1]=2,L[56]=4,L[137]=5,L[43114]=6,L),q=[{inputs:[{internalType:"address",name:"_tokenBridge",type:"address"}],stateMutability:"nonpayable",type:"constructor"},{anonymous:!1,inputs:[{indexed:!0,internalType:"uint16",name:"emitterChainId",type:"uint16"},{indexed:!0,internalType:"bytes32",name:"emitterAddress",type:"bytes32"},{indexed:!0,internalType:"uint64",name:"sequence",type:"uint64"}],name:"Redeemed",type:"event"},{inputs:[{internalType:"address",name:"newGuardian",type:"address"}],name:"changeGuardian",outputs:[],stateMutability:"nonpayable",type:"function"},{inputs:[],name:"claimGuardian",outputs:[],stateMutability:"nonpayable",type:"function"},{inputs:[{components:[{internalType:"uint8",name:"payloadID",type:"uint8"},{internalType:"bytes32",name:"tokenAddr",type:"bytes32"},{internalType:"uint16",name:"tokenChainId",type:"uint16"},{internalType:"bytes32",name:"destAddr",type:"bytes32"},{internalType:"uint16",name:"destChainId",type:"uint16"},{internalType:"bytes32",name:"sourceAddr",type:"bytes32"},{internalType:"uint16",name:"sourceChainId",type:"uint16"},{internalType:"uint64",name:"sequence",type:"uint64"},{internalType:"uint64",name:"amountOutMin",type:"uint64"},{internalType:"uint64",name:"deadline",type:"uint64"},{internalType:"uint64",name:"swapFee",type:"uint64"},{internalType:"uint64",name:"redeemFee",type:"uint64"},{internalType:"uint64",name:"refundFee",type:"uint64"},{internalType:"bytes32",name:"auctionAddr",type:"bytes32"},{internalType:"bool",name:"unwrapRedeem",type:"bool"},{internalType:"bool",name:"unwrapRefund",type:"bool"}],internalType:"struct MayanStructs.Swap",name:"s",type:"tuple"}],name:"encodeSwap",outputs:[{internalType:"bytes",name:"encoded",type:"bytes"}],stateMutability:"pure",type:"function"},{inputs:[],name:"isPaused",outputs:[{internalType:"bool",name:"",type:"bool"}],stateMutability:"view",type:"function"},{inputs:[{internalType:"bytes",name:"encoded",type:"bytes"}],name:"parseRedeemPayload",outputs:[{components:[{internalType:"bytes32",name:"recepient",type:"bytes32"},{internalType:"uint64",name:"relayerFee",type:"uint64"},{internalType:"bool",name:"unwrap",type:"bool"}],internalType:"struct MayanStructs.Redeem",name:"r",type:"tuple"}],stateMutability:"pure",type:"function"},{inputs:[{internalType:"bytes",name:"encodedVm",type:"bytes"}],name:"redeem",outputs:[],stateMutability:"nonpayable",type:"function"},{inputs:[{internalType:"bool",name:"_pause",type:"bool"}],name:"setPause",outputs:[],stateMutability:"nonpayable",type:"function"},{inputs:[{components:[{internalType:"uint64",name:"swapFee",type:"uint64"},{internalType:"uint64",name:"redeemFee",type:"uint64"},{internalType:"uint64",name:"refundFee",type:"uint64"}],internalType:"struct MayanSwap.RelayerFees",name:"relayerFees",type:"tuple"},{components:[{internalType:"bytes32",name:"mayanAddr",type:"bytes32"},{internalType:"uint16",name:"mayanChainId",type:"uint16"},{internalType:"bytes32",name:"auctionAddr",type:"bytes32"},{internalType:"bytes32",name:"destAddr",type:"bytes32"},{internalType:"uint16",name:"destChainId",type:"uint16"}],internalType:"struct MayanSwap.Recepient",name:"recepient",type:"tuple"},{internalType:"bytes32",name:"tokenOutAddr",type:"bytes32"},{internalType:"uint16",name:"tokenOutChainId",type:"uint16"},{components:[{internalType:"uint256",name:"transferDeadline",type:"uint256"},{internalType:"uint64",name:"swapDeadline",type:"uint64"},{internalType:"uint64",name:"amountOutMin",type:"uint64"},{internalType:"bool",name:"unwrap",type:"bool"},{internalType:"uint32",name:"nonce",type:"uint32"}],internalType:"struct MayanSwap.Criteria",name:"criteria",type:"tuple"},{internalType:"address",name:"tokenIn",type:"address"},{internalType:"uint256",name:"amountIn",type:"uint256"}],name:"swap",outputs:[{internalType:"uint64",name:"sequence",type:"uint64"}],stateMutability:"payable",type:"function"},{inputs:[{internalType:"uint256",name:"amount",type:"uint256"},{internalType:"address payable",name:"to",type:"address"}],name:"sweepEth",outputs:[],stateMutability:"nonpayable",type:"function"},{inputs:[{internalType:"address",name:"token",type:"address"},{internalType:"uint256",name:"amount",type:"uint256"},{internalType:"address",name:"to",type:"address"}],name:"sweepToken",outputs:[],stateMutability:"nonpayable",type:"function"},{inputs:[{components:[{internalType:"uint64",name:"swapFee",type:"uint64"},{internalType:"uint64",name:"redeemFee",type:"uint64"},{internalType:"uint64",name:"refundFee",type:"uint64"}],internalType:"struct MayanSwap.RelayerFees",name:"relayerFees",type:"tuple"},{components:[{internalType:"bytes32",name:"mayanAddr",type:"bytes32"},{internalType:"uint16",name:"mayanChainId",type:"uint16"},{internalType:"bytes32",name:"auctionAddr",type:"bytes32"},{internalType:"bytes32",name:"destAddr",type:"bytes32"},{internalType:"uint16",name:"destChainId",type:"uint16"}],internalType:"struct MayanSwap.Recepient",name:"recepient",type:"tuple"},{internalType:"bytes32",name:"tokenOutAddr",type:"bytes32"},{internalType:"uint16",name:"tokenOutChainId",type:"uint16"},{components:[{internalType:"uint256",name:"transferDeadline",type:"uint256"},{internalType:"uint64",name:"swapDeadline",type:"uint64"},{internalType:"uint64",name:"amountOutMin",type:"uint64"},{internalType:"bool",name:"unwrap",type:"bool"},{internalType:"uint32",name:"nonce",type:"uint32"}],internalType:"struct MayanSwap.Criteria",name:"criteria",type:"tuple"}],name:"wrapAndSwapETH",outputs:[{internalType:"uint64",name:"sequence",type:"uint64"}],stateMutability:"payable",type:"function"},{stateMutability:"payable",type:"receive"}];function X(e,t,n,i,o,s){return void 0===o&&(o=new r.PublicKey(l)),void 0===s&&(s=new r.PublicKey(c)),new r.TransactionInstruction({keys:[{pubkey:e,isSigner:!0,isWritable:!0},{pubkey:t,isSigner:!1,isWritable:!0},{pubkey:n,isSigner:!1,isWritable:!1},{pubkey:i,isSigner:!1,isWritable:!1},{pubkey:r.SystemProgram.programId,isSigner:!1,isWritable:!1},{pubkey:o,isSigner:!1,isWritable:!1},{pubkey:r.SYSVAR_RENT_PUBKEY,isSigner:!1,isWritable:!1}],programId:s,data:W.Buffer.alloc(0)})}var Y=o.struct([o.u8("instruction"),o.nu64("amount")]),J=o.struct([o.u8("instruction")]);function Z(e){var t=[{pubkey:e,isSigner:!1,isWritable:!0}],n=W.Buffer.alloc(J.span);return J.encode({instruction:17},n),new r.TransactionInstruction({keys:t,programId:new r.PublicKey(l),data:n})}var H=o.struct([o.u8("instruction")]),Q=o.struct([o.u8("instruction"),o.nu64("amount")]),ee=o.struct([o.u8("instruction"),o.u8("mainNonce"),o.u8("stateNonce"),o.nu64("amount"),o.nu64("minAmountOut"),o.nu64("deadline"),o.nu64("feeSwap"),o.nu64("feeReturn"),o.nu64("feeCancel"),o.u16("destinationChain"),o.blob(32,"destinationAddress"),o.u8("unwrapRedeem"),o.u8("unwrapRefund")]),te=new r.PublicKey("So11111111111111111111111111111111111111112");e.fetchAllTokenList=function(){try{return Promise.resolve(a.default(p+"/tokens")).then(function(e){var t;function n(e){if(t)return e;throw new Error("Cannot fetch Mayan tokens!")}var r=function(){if(200===e.status)return Promise.resolve(e.json()).then(function(e){return t=1,e})}();return r&&r.then?r.then(n):n(r)})}catch(e){return Promise.reject(e)}},e.fetchQuote=function(e){try{var t=e.customRelayerFees;return Promise.resolve(a.default(p+"/quote?amountIn="+e.amount+"&fromToken="+e.fromToken+"&fromChain="+e.fromChain+"&toToken="+e.toToken+"&toChain="+e.toChain+"&slippage="+e.slippage/100+(t?"&swapRelayerFee="+t.swapRelayerFee+"&redeemRelayerFee="+t.redeemRelayerFee+"&refundRelayerFee="+t.refundRelayerFee:""))).then(function(e){return Promise.resolve(e.json()).then(function(t){if(200!==e.status)throw{code:(null==t?void 0:t.code)||0,message:(null==t?void 0:t.msg)||"Route not found"};return t})})}catch(e){return Promise.reject(e)}},e.fetchTokenList=function(e){try{return Promise.resolve(a.default(p+"/tokens?chain="+e)).then(function(t){var n;function r(e){if(n)return e;throw new Error("Cannot fetch Mayan tokens!")}var i=function(){if(200===t.status)return Promise.resolve(t.json()).then(function(t){return n=1,t[e]})}();return i&&i.then?i.then(r):r(i)})}catch(e){return Promise.reject(e)}},e.getCurrentSolanaTime=h,e.swapFromEvm=function(e,t,i,o,s,a){try{var l=new r.PublicKey(u);return Promise.resolve(r.PublicKey.findProgramAddress([Buffer.from("MAIN")],l)).then(function(u){var l=u[0],c=j(new r.PublicKey(e.fromToken.mint),l,!0),p=G(e.effectiveAmountIn,e.fromToken.decimals),d=K(c.toString(),1),g=K(new r.PublicKey(f).toString(),1);return Promise.resolve(s.getChainId()).then(function(r){var u=V[r],f=z(e.fromChain),l=z(e.toChain);if(f!==u)throw new Error("Signer chain id and quote from chain are not same!");var c={mayanAddr:d,mayanChainId:1,destAddr:K(t,l),destChainId:l,auctionAddr:g};return Promise.resolve(function(e){try{return Promise.resolve(e.getBlock("latest")).then(function(e){return e.timestamp})}catch(e){return Promise.reject(e)}}(o)).then(function(t){return Promise.resolve(h()).then(function(r){var o,u,f=e.toToken.contract===n.ethers.constants.AddressZero,l={transferDeadline:n.ethers.BigNumber.from(t+i),swapDeadline:n.ethers.BigNumber.from(r+i),amountOutMin:G(e.minAmountOut,Math.min(8,e.toToken.decimals)),nonce:(o=1e5*Math.random(),u=Buffer.alloc(4),u.writeUInt32LE(o,0),u).readUInt32LE(0),unwrap:f},h={swapFee:G(e.swapRelayerFee,Math.min(8,e.fromToken.decimals)),redeemFee:G(e.redeemRelayerFee,Math.min(8,e.toToken.decimals)),refundFee:G(e.refundRelayerFee,Math.min(8,e.fromToken.decimals))},d=K(e.toToken.realOriginContractAddress,e.toToken.realOriginChainId);return e.fromToken.contract===n.ethers.constants.AddressZero?function(e,t,r,i,o,s,a,u,f){try{var l=new n.ethers.Contract("0x05B70Fb5477A93bE33822bfB31fDAF2c171970dF",q,u);return Promise.resolve(l.wrapAndSwapETH(t,r,i,o,s,f?y({value:a},f):{value:a}))}catch(e){return Promise.reject(e)}}(0,h,c,d,e.toToken.realOriginChainId,l,p,s,a):function(e,t,r,i,o,s,a,u,f,l){try{var c=new n.ethers.Contract("0x05B70Fb5477A93bE33822bfB31fDAF2c171970dF",q,f);return Promise.resolve(l?c.swap(t,r,i,o,s,a,u,l):c.swap(t,r,i,o,s,a,u))}catch(e){return Promise.reject(e)}}(0,h,c,d,e.toToken.realOriginChainId,l,e.fromToken.contract,p,s,a)})})})})}catch(e){return Promise.reject(e)}},e.swapFromSolana=function(e,t,i,o,s,a){try{var c=null!=a?a:new r.Connection("https://rpc.ankr.com/solana"),p=new r.PublicKey(u),y=new r.PublicKey(l),d=new r.PublicKey(t),g=new r.PublicKey(f),m=r.PublicKey.findProgramAddressSync([W.Buffer.from("MAIN")],p),b=m[0],w=m[1],E=r.Keypair.generate(),T=r.Keypair.generate(),I=r.PublicKey.findProgramAddressSync([W.Buffer.from("V2STATE"),W.Buffer.from(E.publicKey.toBytes()),W.Buffer.from(T.publicKey.toBytes())],p),A=I[0],v=I[1],R=new r.PublicKey(e.fromToken.mint),B=new r.PublicKey(e.toToken.mint),S=j(R,d),N=j(R,b,!0),P=new r.Transaction({feePayer:d});return Promise.resolve(c.getAccountInfo(S,"finalized")).then(function(t){return t&&0!==t.data.length||P.add(X(d,S,d,R)),Promise.resolve(c.getAccountInfo(N,"finalized")).then(function(t){t&&0!==t.data.length||P.add(X(d,N,b,R)),e.fromToken.contract===n.ethers.constants.AddressZero&&(P.add(r.SystemProgram.transfer({fromPubkey:d,toPubkey:S,lamports:G(e.effectiveAmountIn,9).toBigInt()})),P.add(Z(S)));var a=G(e.effectiveAmountIn,e.mintDecimals.from),u=r.Keypair.generate();return P.add(function(e,t,n,i,o){void 0===o&&(o=new r.PublicKey(l));var s=[{pubkey:e,isSigner:!1,isWritable:!0},{pubkey:t,isSigner:!1,isWritable:!1},{pubkey:n,isSigner:!0,isWritable:!1}],a=W.Buffer.alloc(Y.span);return Y.encode({instruction:4,amount:i},a),new r.TransactionInstruction({keys:s,programId:o,data:a})}(S,u.publicKey,d,a)),Promise.resolve(c.getMinimumBalanceForRentExemption(308)).then(function(t){P.add(r.SystemProgram.transfer({fromPubkey:d,toPubkey:u.publicKey,lamports:t}));var f=[{pubkey:u.publicKey,isWritable:!1,isSigner:!0},{pubkey:b,isWritable:!1,isSigner:!1},{pubkey:E.publicKey,isWritable:!1,isSigner:!0},{pubkey:T.publicKey,isWritable:!1,isSigner:!0},{pubkey:A,isWritable:!0,isSigner:!1},{pubkey:S,isWritable:!0,isSigner:!1},{pubkey:d,isWritable:!1,isSigner:!1},{pubkey:N,isWritable:!0,isSigner:!1},{pubkey:R,isWritable:!1,isSigner:!1},{pubkey:B,isWritable:!1,isSigner:!1},{pubkey:g,isWritable:!1,isSigner:!1},{pubkey:u.publicKey,isWritable:!1,isSigner:!0},{pubkey:r.SYSVAR_CLOCK_PUBKEY,isWritable:!1,isSigner:!1},{pubkey:r.SYSVAR_RENT_PUBKEY,isWritable:!1,isSigner:!1},{pubkey:y,isWritable:!1,isSigner:!1},{pubkey:r.SystemProgram.programId,isWritable:!1,isSigner:!1}];return Promise.resolve(h()).then(function(t){function l(l){var y,d=W.Buffer.from((y=K(i,h),new Uint8Array(W.Buffer.from(y.substring(2),"hex")))),g=G(e.minAmountOut,e.mintDecimals.to),m=G(e.swapRelayerFee,e.mintDecimals.from),b=G(e.redeemRelayerFee,e.mintDecimals.to),I=G(e.refundRelayerFee,e.mintDecimals.from),A=e.toToken.contract===n.ethers.constants.AddressZero,R=e.fromToken.contract===n.ethers.constants.AddressZero,B=W.Buffer.alloc(ee.span);ee.encode({instruction:101,mainNonce:w,stateNonce:v,amount:a,minAmountOut:g,deadline:t+o,feeSwap:m,feeReturn:b,feeCancel:I,destinationChain:h,destinationAddress:d,unwrapRedeem:A?1:0,unwrapRefund:R?1:0},B);var S=new r.TransactionInstruction({keys:f,data:B,programId:p});return P.add(S),Promise.resolve(c.getLatestBlockhash()).then(function(e){return P.recentBlockhash=e.blockhash,P.partialSign(u),P.partialSign(E),P.partialSign(T),Promise.resolve(s(P)).then(function(e){return Promise.resolve(c.sendRawTransaction(e.serialize()))})})}var h=z(e.toChain),d=function(){if(1===h)return Promise.resolve(c.getAccountInfo(new r.PublicKey(i))).then(function(e){if(e&&e.owner&&e.owner.equals(y))throw new Error("Destination address is not about token account. It should be a owner address")})}();return d&&d.then?d.then(l):l()})})})})}catch(e){return Promise.reject(e)}},e.unwrapSol=function(e,t,n,i){try{var o=null!=i?i:new r.Connection("https://rpc.ankr.com/solana"),s=j(te,e,!1),a=r.Keypair.generate(),u=new r.Transaction({feePayer:e}),f=j(te,a.publicKey,!1);return u.add(X(e,f,a.publicKey,te)),u.add(function(e,t,n,i,o){void 0===o&&(o=new r.PublicKey(l));var s=[{pubkey:e,isSigner:!1,isWritable:!0},{pubkey:t,isSigner:!1,isWritable:!0},{pubkey:n,isSigner:!0,isWritable:!1}],a=W.Buffer.alloc(Q.span);return Q.encode({instruction:3,amount:i},a),new r.TransactionInstruction({keys:s,programId:o,data:a})}(s,f,e,G(t,9))),u.add(function(e,t,n,i){void 0===i&&(i=new r.PublicKey(l));var o=[{pubkey:e,isSigner:!1,isWritable:!0},{pubkey:t,isSigner:!1,isWritable:!0},{pubkey:n,isSigner:!0,isWritable:!1}],s=W.Buffer.alloc(H.span);return H.encode({instruction:9},s),new r.TransactionInstruction({keys:o,programId:i,data:s})}(f,e,a.publicKey)),Promise.resolve(o.getLatestBlockhash()).then(function(e){return u.recentBlockhash=e.blockhash,u.partialSign(a),Promise.resolve(n(u)).then(function(e){return Promise.resolve(o.sendRawTransaction(e.serialize()))})})}catch(e){return Promise.reject(e)}},e.wrapSol=function(e,t,n,i){try{var o=null!=i?i:new r.Connection("https://rpc.ankr.com/solana"),s=j(te,e,!1),a=new r.Transaction({feePayer:e});return Promise.resolve(o.getAccountInfo(s,"finalized")).then(function(i){return i&&0!==i.data.length||a.add(X(e,s,e,te)),a.add(r.SystemProgram.transfer({fromPubkey:e,toPubkey:s,lamports:G(t,9).toBigInt()})),a.add(Z(s)),Promise.resolve(o.getLatestBlockhash()).then(function(e){return a.recentBlockhash=e.blockhash,Promise.resolve(n(a)).then(function(e){return Promise.resolve(o.sendRawTransaction(e.serialize()))})})})}catch(e){return Promise.reject(e)}}});
//# sourceMappingURL=main.umd.js.map
(function(g,f){typeof exports==='object'&&typeof module!=='undefined'?f(exports,require('cross-fetch'),require('ethers'),require('@solana/web3.js'),require('@ethersproject/bytes'),require('buffer'),require('js-sha3'),require('@solana/buffer-layout')):typeof define==='function'&&define.amd?define(['exports','cross-fetch','ethers','@solana/web3.js','@ethersproject/bytes','buffer','js-sha3','@solana/buffer-layout'],f):(g=typeof globalThis!=='undefined'?globalThis:g||self,f(g.MAYAN={},g.fetch,g.ethers,g.web3_js,g.bytes,g.buffer,g.jsSha3,g.bufferLayout));})(this,(function(exports,fetch,ethers,web3_js,bytes,buffer,jsSha3,bufferLayout){'use strict';var addresses = {
"MAYAN_PROGRAM_ID": "8LPjGDbxhW4G2Q8S6FvdvUdfGWssgtqmvsc63bwNFA7E",
"AUCTION_PROGRAM_ID": "4U6MNAMRbYeTD4HumavhJ1ah9NQ5pNPhTNxcFdeybXFy",
"MAYAN_EVM_CONTRACT": "0x05B70Fb5477A93bE33822bfB31fDAF2c171970dF",
"TOKEN_PROGRAM_ID": "TokenkegQfeZyiNwAJbNbGKPFXCWuBvf9Ss623VQ5DA",
"ASSOCIATED_TOKEN_PROGRAM_ID": "ATokenGPvbdGVxr1b2hvZbsiqW5xWH25efTNsLJA8knL",
"EXPLORER_URL": "https://price-api.mayan.finance/v1",
"PRICE_URL": "https://price-api.mayan.finance/v1"
};async function fetchAllTokenList() {
const res = await fetch(`${addresses.PRICE_URL}/tokens`);
if (res.status === 200) {
const result = await res.json();
return result;
}
throw new Error('Cannot fetch Mayan tokens!');
}
async function fetchTokenList(chain) {
const res = await fetch(`${addresses.PRICE_URL}/tokens?chain=${chain}`);
if (res.status === 200) {
const result = await res.json();
return result[chain];
}
throw new Error('Cannot fetch Mayan tokens!');
}
async function fetchQuote(params) {
const { customRelayerFees: relayerFees } = params;
const normalizedSlippage = params.slippage / 100;
const baseUrl = `${addresses.PRICE_URL}/quote?`;
const basicQueries = `amountIn=${params.amount}&fromToken=${params.fromToken}&fromChain=${params.fromChain}&toToken=${params.toToken}&toChain=${params.toChain}`;
const criteriaQueries = `&slippage=${normalizedSlippage}` + (relayerFees ?
`&swapRelayerFee=${relayerFees.swapRelayerFee}&redeemRelayerFee=${relayerFees.redeemRelayerFee}&refundRelayerFee=${relayerFees.refundRelayerFee}` :
'');
const url = baseUrl + basicQueries + criteriaQueries;
const res = await fetch(url);
const result = await res.json();
if (res.status !== 200) {
throw {
code: (result === null || result === void 0 ? void 0 : result.code) || 0,
message: (result === null || result === void 0 ? void 0 : result.msg) || 'Route not found',
};
}
return result;
}
async function getCurrentSolanaTime() {
const res = await fetch(`${addresses.PRICE_URL}/clock/solana`);
const result = await res.json();
if (res.status !== 200) {
throw result;
}
return result.clock;
}const isValidAptosType = (str) => /^(0x)?[0-9a-fA-F]+::\w+::\w+$/.test(str);
function nativeAddressToHexString(address, wChainId) {
let padded;
if (wChainId === 1) {
padded = bytes.zeroPad(new web3_js.PublicKey(address).toBytes(), 32);
}
else if (wChainId === 2 || wChainId === 4 || wChainId === 5 || wChainId === 6 || wChainId === 22) {
if (wChainId === 22 && isValidAptosType(address)) {
return `0x${jsSha3.sha3_256(address)}`;
}
let hex = address.substring(2);
const result = [];
for (let i = 0; i < hex.length; i += 2) {
result.push(parseInt(hex.substring(i, i + 2), 16));
}
padded = bytes.zeroPad(new Uint8Array(result), 32);
}
else {
throw new Error('Unsupported token chain');
}
const hex = buffer.Buffer.from(padded).toString("hex");
return `0x${hex}`;
}
function hexToUint8Array(input) {
return new Uint8Array(buffer.Buffer.from(input.substring(2), "hex"));
}
async function getCurrentEvmTime(provider) {
const latestBlock = await provider.getBlock('latest');
return latestBlock.timestamp;
}
function getAssociatedTokenAddress(mint, owner, allowOwnerOffCurve = false, programId = new web3_js.PublicKey(addresses.TOKEN_PROGRAM_ID), associatedTokenProgramId = new web3_js.PublicKey(addresses.ASSOCIATED_TOKEN_PROGRAM_ID)) {
if (!allowOwnerOffCurve && !web3_js.PublicKey.isOnCurve(owner.toBuffer())) {
throw new Error('TokenOwnerOffCurveError');
}
const [address] = web3_js.PublicKey.findProgramAddressSync([owner.toBuffer(), programId.toBuffer(), mint.toBuffer()], associatedTokenProgramId);
return address;
}
function getAmountOfFractionalAmount(amount, decimals) {
const fixedAmount = Number(amount).toFixed(Math.min(8, Number(decimals)));
return ethers.ethers.utils.parseUnits(fixedAmount, Number(decimals));
}
const chains = {
solana: 1,
ethereum: 2,
bsc: 4,
polygon: 5,
avalanche: 6,
aptos: 22,
};
function getWormholeChainIdByName(chain) {
return chains[chain];
}
const evmChainIdMap = {
[1]: 2,
[56]: 4,
[137]: 5,
[43114]: 6,
};
function getWormholeChainIdById(chainId) {
return evmChainIdMap[chainId];
}var MayanSwapArtifact = {
"_format": "hh-sol-artifact-1",
"contractName": "MayanSwap",
"sourceName": "src/MayanSwap.sol",
"abi": [
{
"inputs": [
{
"internalType": "address",
"name": "_tokenBridge",
"type": "address"
}
],
"stateMutability": "nonpayable",
"type": "constructor"
},
{
"anonymous": false,
"inputs": [
{
"indexed": true,
"internalType": "uint16",
"name": "emitterChainId",
"type": "uint16"
},
{
"indexed": true,
"internalType": "bytes32",
"name": "emitterAddress",
"type": "bytes32"
},
{
"indexed": true,
"internalType": "uint64",
"name": "sequence",
"type": "uint64"
}
],
"name": "Redeemed",
"type": "event"
},
{
"inputs": [
{
"internalType": "address",
"name": "newGuardian",
"type": "address"
}
],
"name": "changeGuardian",
"outputs": [],
"stateMutability": "nonpayable",
"type": "function"
},
{
"inputs": [],
"name": "claimGuardian",
"outputs": [],
"stateMutability": "nonpayable",
"type": "function"
},
{
"inputs": [
{
"components": [
{
"internalType": "uint8",
"name": "payloadID",
"type": "uint8"
},
{
"internalType": "bytes32",
"name": "tokenAddr",
"type": "bytes32"
},
{
"internalType": "uint16",
"name": "tokenChainId",
"type": "uint16"
},
{
"internalType": "bytes32",
"name": "destAddr",
"type": "bytes32"
},
{
"internalType": "uint16",
"name": "destChainId",
"type": "uint16"
},
{
"internalType": "bytes32",
"name": "sourceAddr",
"type": "bytes32"
},
{
"internalType": "uint16",
"name": "sourceChainId",
"type": "uint16"
},
{
"internalType": "uint64",
"name": "sequence",
"type": "uint64"
},
{
"internalType": "uint64",
"name": "amountOutMin",
"type": "uint64"
},
{
"internalType": "uint64",
"name": "deadline",
"type": "uint64"
},
{
"internalType": "uint64",
"name": "swapFee",
"type": "uint64"
},
{
"internalType": "uint64",
"name": "redeemFee",
"type": "uint64"
},
{
"internalType": "uint64",
"name": "refundFee",
"type": "uint64"
},
{
"internalType": "bytes32",
"name": "auctionAddr",
"type": "bytes32"
},
{
"internalType": "bool",
"name": "unwrapRedeem",
"type": "bool"
},
{
"internalType": "bool",
"name": "unwrapRefund",
"type": "bool"
}
],
"internalType": "struct MayanStructs.Swap",
"name": "s",
"type": "tuple"
}
],
"name": "encodeSwap",
"outputs": [
{
"internalType": "bytes",
"name": "encoded",
"type": "bytes"
}
],
"stateMutability": "pure",
"type": "function"
},
{
"inputs": [],
"name": "isPaused",
"outputs": [
{
"internalType": "bool",
"name": "",
"type": "bool"
}
],
"stateMutability": "view",
"type": "function"
},
{
"inputs": [
{
"internalType": "bytes",
"name": "encoded",
"type": "bytes"
}
],
"name": "parseRedeemPayload",
"outputs": [
{
"components": [
{
"internalType": "bytes32",
"name": "recepient",
"type": "bytes32"
},
{
"internalType": "uint64",
"name": "relayerFee",
"type": "uint64"
},
{
"internalType": "bool",
"name": "unwrap",
"type": "bool"
}
],
"internalType": "struct MayanStructs.Redeem",
"name": "r",
"type": "tuple"
}
],
"stateMutability": "pure",
"type": "function"
},
{
"inputs": [
{
"internalType": "bytes",
"name": "encodedVm",
"type": "bytes"
}
],
"name": "redeem",
"outputs": [],
"stateMutability": "nonpayable",
"type": "function"
},
{
"inputs": [
{
"internalType": "bool",
"name": "_pause",
"type": "bool"
}
],
"name": "setPause",
"outputs": [],
"stateMutability": "nonpayable",
"type": "function"
},
{
"inputs": [
{
"components": [
{
"internalType": "uint64",
"name": "swapFee",
"type": "uint64"
},
{
"internalType": "uint64",
"name": "redeemFee",
"type": "uint64"
},
{
"internalType": "uint64",
"name": "refundFee",
"type": "uint64"
}
],
"internalType": "struct MayanSwap.RelayerFees",
"name": "relayerFees",
"type": "tuple"
},
{
"components": [
{
"internalType": "bytes32",
"name": "mayanAddr",
"type": "bytes32"
},
{
"internalType": "uint16",
"name": "mayanChainId",
"type": "uint16"
},
{
"internalType": "bytes32",
"name": "auctionAddr",
"type": "bytes32"
},
{
"internalType": "bytes32",
"name": "destAddr",
"type": "bytes32"
},
{
"internalType": "uint16",
"name": "destChainId",
"type": "uint16"
}
],
"internalType": "struct MayanSwap.Recepient",
"name": "recepient",
"type": "tuple"
},
{
"internalType": "bytes32",
"name": "tokenOutAddr",
"type": "bytes32"
},
{
"internalType": "uint16",
"name": "tokenOutChainId",
"type": "uint16"
},
{
"components": [
{
"internalType": "uint256",
"name": "transferDeadline",
"type": "uint256"
},
{
"internalType": "uint64",
"name": "swapDeadline",
"type": "uint64"
},
{
"internalType": "uint64",
"name": "amountOutMin",
"type": "uint64"
},
{
"internalType": "bool",
"name": "unwrap",
"type": "bool"
},
{
"internalType": "uint32",
"name": "nonce",
"type": "uint32"
}
],
"internalType": "struct MayanSwap.Criteria",
"name": "criteria",
"type": "tuple"
},
{
"internalType": "address",
"name": "tokenIn",
"type": "address"
},
{
"internalType": "uint256",
"name": "amountIn",
"type": "uint256"
}
],
"name": "swap",
"outputs": [
{
"internalType": "uint64",
"name": "sequence",
"type": "uint64"
}
],
"stateMutability": "payable",
"type": "function"
},
{
"inputs": [
{
"internalType": "uint256",
"name": "amount",
"type": "uint256"
},
{
"internalType": "address payable",
"name": "to",
"type": "address"
}
],
"name": "sweepEth",
"outputs": [],
"stateMutability": "nonpayable",
"type": "function"
},
{
"inputs": [
{
"internalType": "address",
"name": "token",
"type": "address"
},
{
"internalType": "uint256",
"name": "amount",
"type": "uint256"
},
{
"internalType": "address",
"name": "to",
"type": "address"
}
],
"name": "sweepToken",
"outputs": [],
"stateMutability": "nonpayable",
"type": "function"
},
{
"inputs": [
{
"components": [
{
"internalType": "uint64",
"name": "swapFee",
"type": "uint64"
},
{
"internalType": "uint64",
"name": "redeemFee",
"type": "uint64"
},
{
"internalType": "uint64",
"name": "refundFee",
"type": "uint64"
}
],
"internalType": "struct MayanSwap.RelayerFees",
"name": "relayerFees",
"type": "tuple"
},
{
"components": [
{
"internalType": "bytes32",
"name": "mayanAddr",
"type": "bytes32"
},
{
"internalType": "uint16",
"name": "mayanChainId",
"type": "uint16"
},
{
"internalType": "bytes32",
"name": "auctionAddr",
"type": "bytes32"
},
{
"internalType": "bytes32",
"name": "destAddr",
"type": "bytes32"
},
{
"internalType": "uint16",
"name": "destChainId",
"type": "uint16"
}
],
"internalType": "struct MayanSwap.Recepient",
"name": "recepient",
"type": "tuple"
},
{
"internalType": "bytes32",
"name": "tokenOutAddr",
"type": "bytes32"
},
{
"internalType": "uint16",
"name": "tokenOutChainId",
"type": "uint16"
},
{
"components": [
{
"internalType": "uint256",
"name": "transferDeadline",
"type": "uint256"
},
{
"internalType": "uint64",
"name": "swapDeadline",
"type": "uint64"
},
{
"internalType": "uint64",
"name": "amountOutMin",
"type": "uint64"
},
{
"internalType": "bool",
"name": "unwrap",
"type": "bool"
},
{
"internalType": "uint32",
"name": "nonce",
"type": "uint32"
}
],
"internalType": "struct MayanSwap.Criteria",
"name": "criteria",
"type": "tuple"
}
],
"name": "wrapAndSwapETH",
"outputs": [
{
"internalType": "uint64",
"name": "sequence",
"type": "uint64"
}
],
"stateMutability": "payable",
"type": "function"
},
{
"stateMutability": "payable",
"type": "receive"
}
]
};async function swapFromEvm(quote, destinationAddress, timeout, provider, signer, overrides) {
const mayanProgram = new web3_js.PublicKey(addresses.MAYAN_PROGRAM_ID);
const [mayanMainAccount] = await web3_js.PublicKey.findProgramAddress([Buffer.from('MAIN')], mayanProgram);
const recipient = getAssociatedTokenAddress(new web3_js.PublicKey(quote.fromToken.mint), mayanMainAccount, true);
const amountIn = getAmountOfFractionalAmount(quote.effectiveAmountIn, quote.fromToken.decimals);
const recipientHex = nativeAddressToHexString(recipient.toString(), 1);
const auctionHex = nativeAddressToHexString(new web3_js.PublicKey(addresses.AUCTION_PROGRAM_ID).toString(), 1);
const signerChainId = await signer.getChainId();
const signerWormholeChainId = getWormholeChainIdById(signerChainId);
const fromChainId = getWormholeChainIdByName(quote.fromChain);
const destinationChainId = getWormholeChainIdByName(quote.toChain);
if (fromChainId !== signerWormholeChainId) {
throw new Error('Signer chain id and quote from chain are not same!');
}
const recipientStruct = {
mayanAddr: recipientHex,
mayanChainId: 1,
destAddr: nativeAddressToHexString(destinationAddress, destinationChainId),
destChainId: destinationChainId,
auctionAddr: auctionHex,
};
// Times are in seconds
const currentEvmTime = await getCurrentEvmTime(provider);
const currentSolanaTime = await getCurrentSolanaTime();
const unwrapRedeem = quote.toToken.contract === ethers.ethers.constants.AddressZero;
const criteria = {
transferDeadline: ethers.ethers.BigNumber.from(currentEvmTime + timeout),
swapDeadline: ethers.ethers.BigNumber.from(currentSolanaTime + timeout),
amountOutMin: getAmountOfFractionalAmount(quote.minAmountOut, Math.min(8, quote.toToken.decimals)),
nonce: createNonce().readUInt32LE(0),
unwrap: unwrapRedeem,
};
const contractRelayerFees = {
swapFee: getAmountOfFractionalAmount(quote.swapRelayerFee, Math.min(8, quote.fromToken.decimals)),
redeemFee: getAmountOfFractionalAmount(quote.redeemRelayerFee, Math.min(8, quote.toToken.decimals)),
refundFee: getAmountOfFractionalAmount(quote.refundRelayerFee, Math.min(8, quote.fromToken.decimals)),
};
const tokenOut = nativeAddressToHexString(quote.toToken.realOriginContractAddress, quote.toToken.realOriginChainId);
if (quote.fromToken.contract === ethers.ethers.constants.AddressZero) {
return wrapAndSwapETH(addresses.MAYAN_EVM_CONTRACT, contractRelayerFees, recipientStruct, tokenOut, quote.toToken.realOriginChainId, criteria, amountIn, signer, overrides);
}
else {
return swap(addresses.MAYAN_EVM_CONTRACT, contractRelayerFees, recipientStruct, tokenOut, quote.toToken.realOriginChainId, criteria, quote.fromToken.contract, amountIn, signer, overrides);
}
}
async function swap(contractAddress, relayerFees, recipient, tokenOut, tokenOutWChainId, criteria, tokenIn, amountIn, signer, overrides) {
const mayanSwap = new ethers.ethers.Contract(contractAddress, MayanSwapArtifact.abi, signer);
if (overrides) {
return mayanSwap.swap(relayerFees, recipient, tokenOut, tokenOutWChainId, criteria, tokenIn, amountIn, overrides);
}
else {
return mayanSwap.swap(relayerFees, recipient, tokenOut, tokenOutWChainId, criteria, tokenIn, amountIn);
}
}
async function wrapAndSwapETH(contractAddress, relayerFees, recipient, tokenOut, tokenOutWChainId, criteria, amountIn, signer, overrides) {
const mayanSwap = new ethers.ethers.Contract(contractAddress, MayanSwapArtifact.abi, signer);
return mayanSwap.wrapAndSwapETH(relayerFees, recipient, tokenOut, tokenOutWChainId, criteria, overrides ? { value: amountIn, ...overrides } : { value: amountIn });
}
function createNonce() {
const nonceConst = Math.random() * 100000;
const nonceBuffer = Buffer.alloc(4);
nonceBuffer.writeUInt32LE(nonceConst, 0);
return nonceBuffer;
}const STATE_SIZE = 308;
function createAssociatedTokenAccountInstruction(payer, associatedToken, owner, mint, programId = new web3_js.PublicKey(addresses.TOKEN_PROGRAM_ID), associatedTokenProgramId = new web3_js.PublicKey(addresses.ASSOCIATED_TOKEN_PROGRAM_ID)) {
const keys = [
{ pubkey: payer, isSigner: true, isWritable: true },
{ pubkey: associatedToken, isSigner: false, isWritable: true },
{ pubkey: owner, isSigner: false, isWritable: false },
{ pubkey: mint, isSigner: false, isWritable: false },
{ pubkey: web3_js.SystemProgram.programId, isSigner: false, isWritable: false },
{ pubkey: programId, isSigner: false, isWritable: false },
{ pubkey: web3_js.SYSVAR_RENT_PUBKEY, isSigner: false, isWritable: false },
];
return new web3_js.TransactionInstruction({
keys,
programId: associatedTokenProgramId,
data: buffer.Buffer.alloc(0),
});
}
const ApproveInstructionData = bufferLayout.struct([
bufferLayout.u8('instruction'), bufferLayout.nu64('amount')
]);
function createApproveInstruction(account, delegate, owner, amount, programId = new web3_js.PublicKey(addresses.TOKEN_PROGRAM_ID)) {
const keys = [
{ pubkey: account, isSigner: false, isWritable: true },
{ pubkey: delegate, isSigner: false, isWritable: false },
{ pubkey: owner, isSigner: true, isWritable: false },
];
const data = buffer.Buffer.alloc(ApproveInstructionData.span);
ApproveInstructionData.encode({
instruction: 4,
amount,
}, data);
return new web3_js.TransactionInstruction({ keys, programId, data });
}
const SyncNativeInstructionData = bufferLayout.struct([bufferLayout.u8('instruction')]);
function createSyncNativeInstruction(account) {
const keys = [{ pubkey: account, isSigner: false, isWritable: true }];
const data = buffer.Buffer.alloc(SyncNativeInstructionData.span);
SyncNativeInstructionData.encode({ instruction: 17 }, data);
return new web3_js.TransactionInstruction({
keys,
programId: new web3_js.PublicKey(addresses.TOKEN_PROGRAM_ID),
data
});
}
const CloseAccountInstructionData = bufferLayout.struct([
bufferLayout.u8('instruction')
]);
function createCloseAccountInstruction(account, destination, owner, programId = new web3_js.PublicKey(addresses.TOKEN_PROGRAM_ID)) {
const keys = [
{ pubkey: account, isSigner: false, isWritable: true },
{ pubkey: destination, isSigner: false, isWritable: true },
{ pubkey: owner, isSigner: true, isWritable: false },
];
const data = buffer.Buffer.alloc(CloseAccountInstructionData.span);
CloseAccountInstructionData.encode({
instruction: 9,
}, data);
return new web3_js.TransactionInstruction({ keys, programId, data });
}
const SplTransferInstructionData = bufferLayout.struct([
bufferLayout.u8('instruction'), bufferLayout.nu64('amount')
]);
function createSplTransferInstruction(source, destination, owner, amount, programId = new web3_js.PublicKey(addresses.TOKEN_PROGRAM_ID)) {
const keys = [
{ pubkey: source, isSigner: false, isWritable: true },
{ pubkey: destination, isSigner: false, isWritable: true },
{ pubkey: owner, isSigner: true, isWritable: false },
];
const data = buffer.Buffer.alloc(SplTransferInstructionData.span);
SplTransferInstructionData.encode({
instruction: 3,
amount,
}, data);
return new web3_js.TransactionInstruction({ keys, programId, data });
}
const SwapLayout = bufferLayout.struct([
bufferLayout.u8('instruction'),
bufferLayout.u8('mainNonce'),
bufferLayout.u8('stateNonce'),
bufferLayout.nu64('amount'),
bufferLayout.nu64('minAmountOut'),
bufferLayout.nu64('deadline'),
bufferLayout.nu64('feeSwap'),
bufferLayout.nu64('feeReturn'),
bufferLayout.nu64('feeCancel'),
bufferLayout.u16('destinationChain'),
bufferLayout.blob(32, 'destinationAddress'),
bufferLayout.u8('unwrapRedeem'),
bufferLayout.u8('unwrapRefund'),
]);
async function swapFromSolana(quote, swapperWalletAddress, destinationAddress, timeout, signTransaction, connection) {
const solanaConnection = connection !== null && connection !== void 0 ? connection : new web3_js.Connection('https://rpc.ankr.com/solana');
const mayanProgram = new web3_js.PublicKey(addresses.MAYAN_PROGRAM_ID);
const tokenProgram = new web3_js.PublicKey(addresses.TOKEN_PROGRAM_ID);
const swapper = new web3_js.PublicKey(swapperWalletAddress);
const auctionAddr = new web3_js.PublicKey(addresses.AUCTION_PROGRAM_ID);
const [main, mainNonce] = web3_js.PublicKey.findProgramAddressSync([buffer.Buffer.from('MAIN')], mayanProgram);
const msg1 = web3_js.Keypair.generate();
const msg2 = web3_js.Keypair.generate();
const [state, stateNonce] = web3_js.PublicKey.findProgramAddressSync([
buffer.Buffer.from('V2STATE'),
buffer.Buffer.from(msg1.publicKey.toBytes()),
buffer.Buffer.from(msg2.publicKey.toBytes()),
], mayanProgram);
const fromMint = new web3_js.PublicKey(quote.fromToken.mint);
const toMint = new web3_js.PublicKey(quote.toToken.mint);
const fromAccount = getAssociatedTokenAddress(fromMint, swapper);
const toAccount = getAssociatedTokenAddress(fromMint, main, true);
const trx = new web3_js.Transaction({
feePayer: swapper,
});
const fromAccountData = await solanaConnection.getAccountInfo(fromAccount, 'finalized');
if (!fromAccountData || fromAccountData.data.length === 0) {
trx.add(createAssociatedTokenAccountInstruction(swapper, fromAccount, swapper, fromMint));
}
const toAccountData = await solanaConnection.getAccountInfo(toAccount, 'finalized');
if (!toAccountData || toAccountData.data.length === 0) {
trx.add(createAssociatedTokenAccountInstruction(swapper, toAccount, main, fromMint));
}
if (quote.fromToken.contract === ethers.ethers.constants.AddressZero) {
trx.add(web3_js.SystemProgram.transfer({
fromPubkey: swapper,
toPubkey: fromAccount,
lamports: getAmountOfFractionalAmount(quote.effectiveAmountIn, 9).toBigInt(),
}));
trx.add(createSyncNativeInstruction(fromAccount));
}
const amount = getAmountOfFractionalAmount(quote.effectiveAmountIn, quote.mintDecimals.from);
const delegate = web3_js.Keypair.generate();
trx.add(createApproveInstruction(fromAccount, delegate.publicKey, swapper, amount));
const stateRent = await solanaConnection.getMinimumBalanceForRentExemption(STATE_SIZE);
trx.add(web3_js.SystemProgram.transfer({
fromPubkey: swapper,
toPubkey: delegate.publicKey,
lamports: stateRent,
}));
const swapKeys = [
{ pubkey: delegate.publicKey, isWritable: false, isSigner: true },
{ pubkey: main, isWritable: false, isSigner: false },
{ pubkey: msg1.publicKey, isWritable: false, isSigner: true },
{ pubkey: msg2.publicKey, isWritable: false, isSigner: true },
{ pubkey: state, isWritable: true, isSigner: false },
{ pubkey: fromAccount, isWritable: true, isSigner: false },
{ pubkey: swapper, isWritable: false, isSigner: false },
{ pubkey: toAccount, isWritable: true, isSigner: false },
{ pubkey: fromMint, isWritable: false, isSigner: false },
{ pubkey: toMint, isWritable: false, isSigner: false },
{ pubkey: auctionAddr, isWritable: false, isSigner: false },
{ pubkey: delegate.publicKey, isWritable: false, isSigner: true },
{ pubkey: web3_js.SYSVAR_CLOCK_PUBKEY, isWritable: false, isSigner: false },
{ pubkey: web3_js.SYSVAR_RENT_PUBKEY, isWritable: false, isSigner: false },
{ pubkey: tokenProgram, isWritable: false, isSigner: false },
{ pubkey: web3_js.SystemProgram.programId, isWritable: false, isSigner: false },
];
const solanaTime = await getCurrentSolanaTime();
const destinationChainId = getWormholeChainIdByName(quote.toChain);
if (destinationChainId === 1) { //destination address safety check!
const destinationAccount = await solanaConnection.getAccountInfo(new web3_js.PublicKey(destinationAddress));
if (destinationAccount && destinationAccount.owner &&
destinationAccount.owner.equals(tokenProgram)) {
throw new Error('Destination address is not about token account.' +
' It should be a owner address');
}
}
const destAddress = buffer.Buffer.from(hexToUint8Array(nativeAddressToHexString(destinationAddress, destinationChainId)));
const minAmountOut = getAmountOfFractionalAmount(quote.minAmountOut, quote.mintDecimals.to);
const feeSwap = getAmountOfFractionalAmount(quote.swapRelayerFee, quote.mintDecimals.from);
const feeReturn = getAmountOfFractionalAmount(quote.redeemRelayerFee, quote.mintDecimals.to);
const feeCancel = getAmountOfFractionalAmount(quote.refundRelayerFee, quote.mintDecimals.from);
const unwrapRedeem = quote.toToken.contract === ethers.ethers.constants.AddressZero;
const unwrapRefund = quote.fromToken.contract === ethers.ethers.constants.AddressZero;
const swapData = buffer.Buffer.alloc(SwapLayout.span);
const swapFields = {
instruction: 101,
mainNonce,
stateNonce,
amount,
minAmountOut,
deadline: solanaTime + timeout,
feeSwap,
feeReturn,
feeCancel,
destinationChain: destinationChainId,
destinationAddress: destAddress,
unwrapRedeem: unwrapRedeem ? 1 : 0,
unwrapRefund: unwrapRefund ? 1 : 0,
};
SwapLayout.encode(swapFields, swapData);
const swapInstruction = new web3_js.TransactionInstruction({
keys: swapKeys,
data: swapData,
programId: mayanProgram,
});
trx.add(swapInstruction);
const { blockhash } = await solanaConnection.getLatestBlockhash();
trx.recentBlockhash = blockhash;
trx.partialSign(delegate);
trx.partialSign(msg1);
trx.partialSign(msg2);
const signedTrx = await signTransaction(trx);
return await solanaConnection.sendRawTransaction(signedTrx.serialize());
}
const solMint = new web3_js.PublicKey('So11111111111111111111111111111111111111112');
async function wrapSol(owner, amount, signTransaction, connection) {
const solanaConnection = connection !== null && connection !== void 0 ? connection : new web3_js.Connection('https://rpc.ankr.com/solana');
const toAccount = getAssociatedTokenAddress(solMint, owner, false);
const trx = new web3_js.Transaction({
feePayer: owner,
});
const toAccountData = await solanaConnection.getAccountInfo(toAccount, 'finalized');
if (!toAccountData || toAccountData.data.length === 0) {
trx.add(createAssociatedTokenAccountInstruction(owner, toAccount, owner, solMint));
}
trx.add(web3_js.SystemProgram.transfer({
fromPubkey: owner,
toPubkey: toAccount,
lamports: getAmountOfFractionalAmount(amount, 9).toBigInt(),
}));
trx.add(createSyncNativeInstruction(toAccount));
const { blockhash } = await solanaConnection.getLatestBlockhash();
trx.recentBlockhash = blockhash;
const signedTrx = await signTransaction(trx);
return await solanaConnection.sendRawTransaction(signedTrx.serialize());
}
async function unwrapSol(owner, amount, signTransaction, connection) {
const solanaConnection = connection !== null && connection !== void 0 ? connection : new web3_js.Connection('https://rpc.ankr.com/solana');
const fromAccount = getAssociatedTokenAddress(solMint, owner, false);
const delegate = web3_js.Keypair.generate();
const trx = new web3_js.Transaction({
feePayer: owner,
});
const toAccount = getAssociatedTokenAddress(solMint, delegate.publicKey, false);
trx.add(createAssociatedTokenAccountInstruction(owner, toAccount, delegate.publicKey, solMint));
trx.add(createSplTransferInstruction(fromAccount, toAccount, owner, getAmountOfFractionalAmount(amount, 9)));
trx.add(createCloseAccountInstruction(toAccount, owner, delegate.publicKey));
const { blockhash } = await solanaConnection.getLatestBlockhash();
trx.recentBlockhash = blockhash;
trx.partialSign(delegate);
const signedTrx = await signTransaction(trx);
return await solanaConnection.sendRawTransaction(signedTrx.serialize());
}exports.fetchAllTokenList=fetchAllTokenList;exports.fetchQuote=fetchQuote;exports.fetchTokenList=fetchTokenList;exports.getCurrentSolanaTime=getCurrentSolanaTime;exports.swapFromEvm=swapFromEvm;exports.swapFromSolana=swapFromSolana;exports.unwrapSol=unwrapSol;exports.wrapSol=wrapSol;}));

28

package.json
{
"name": "@mayanfinance/swap-sdk",
"description": "A SDK to swap with Mayan",
"version": "2.6.0",
"version": "2.7.0",
"source": "src/main.ts",
"main": "dist/main.umd.js",
"module": "dist/main.modern.module.js",
"main": "lib/index.js",
"module": "dist/main.esm.js",
"unpkg": "dist/main.umd.js",

@@ -18,6 +18,11 @@ "types": "dist/main.d.ts",

"dist/**.js*",
"dist/**/*.ts"
"lib/**/*",
"LICENSE",
"README.md"
],
"scripts": {
"build": "microbundle --define PKG_VERSION=$npm_package_version",
"clean": "rimraf dist lib",
"build": "npm run clean && npm run tsc && npm run rollup-build",
"rollup-build": "rollup -c rollup.config.js",
"tsc": "tsc",
"watch": "microbundle watch --define PKG_VERSION=$npm_package_version",

@@ -30,4 +35,7 @@ "lint": "prettier src -c",

"devDependencies": {
"microbundle": "^0.15.0",
"prettier": "^2.6.2"
"prettier": "^2.6.2",
"rimraf": "^4.1.1",
"rollup": "^3.10.0",
"rollup-plugin-dts": "^5.1.1",
"typescript": "^4.9.4"
},

@@ -44,8 +52,8 @@ "prettier": {

"dependencies": {
"@solana/buffer-layout": "^4.0.0",
"@solana/web3.js": "^1.66.0",
"@solana/buffer-layout": "^4 || ^3",
"@solana/web3.js": "^1.22.0",
"cross-fetch": "^3.1.5",
"ethers": "^5.7.2",
"ethers": "^5",
"js-sha3": "^0.8.0"
}
}
SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc