brahma-trade-widget
Version:
A React component for trade automation within the Brahma ecosystem.
1 lines • 32.9 kB
JavaScript
;(self.webpackChunkbrahma_trade_widget=self.webpackChunkbrahma_trade_widget||[]).push([[1182],{91182:(e,t,n)=>{n.d(t,{default:()=>qt});const s=e=>e.toString(16).padStart(2,"0"),i=()=>"undefined"!=typeof window?(e=>{const t=new Uint8Array((e||40)/2);return window.crypto.getRandomValues(t),Array.from(t,s).join("")})(10):(new Date).getTime().toString(36);class r{}var a,o;r.makeRequest=(e,t)=>({id:i(),method:e,params:t,env:{sdkVersion:"9.1.0"}}),r.makeResponse=(e,t,n)=>({id:e,success:!0,version:n,data:t}),r.makeErrorResponse=(e,t,n)=>({id:e,success:!1,error:t,version:n}),function(e){e.sendTransactions="sendTransactions",e.rpcCall="rpcCall",e.getChainInfo="getChainInfo",e.getSafeInfo="getSafeInfo",e.getTxBySafeTxHash="getTxBySafeTxHash",e.getSafeBalances="getSafeBalances",e.signMessage="signMessage",e.signTypedMessage="signTypedMessage",e.getEnvironmentInfo="getEnvironmentInfo",e.getOffChainSignature="getOffChainSignature",e.requestAddressBook="requestAddressBook",e.wallet_getPermissions="wallet_getPermissions",e.wallet_requestPermissions="wallet_requestPermissions"}(a||(a={})),function(e){e.requestAddressBook="requestAddressBook"}(o||(o={}));const c=class{constructor(e=null,t=!1){this.allowedOrigins=null,this.callbacks=new Map,this.debugMode=!1,this.isServer="undefined"==typeof window,this.isValidMessage=({origin:e,data:t,source:n})=>{const s=!t,i=!this.isServer&&n===window.parent,r=void 0!==t.version&&parseInt(t.version.split(".")[0]),a="number"==typeof r&&r>=1;let o=!0;return Array.isArray(this.allowedOrigins)&&(o=void 0!==this.allowedOrigins.find((t=>t.test(e)))),!s&&i&&a&&o},this.logIncomingMessage=e=>{console.info(`Safe Apps SDK v1: A message was received from origin ${e.origin}. `,e.data)},this.onParentMessage=e=>{this.isValidMessage(e)&&(this.debugMode&&this.logIncomingMessage(e),this.handleIncomingMessage(e.data))},this.handleIncomingMessage=e=>{const{id:t}=e,n=this.callbacks.get(t);n&&(n(e),this.callbacks.delete(t))},this.send=(e,t)=>{const n=r.makeRequest(e,t);if(this.isServer)throw new Error("Window doesn't exist");return window.parent.postMessage(n,"*"),new Promise(((e,t)=>{this.callbacks.set(n.id,(n=>{n.success?e(n):t(new Error(n.error))}))}))},this.allowedOrigins=e,this.debugMode=t,this.isServer||window.addEventListener("message",this.onParentMessage)}},u=e=>"object"==typeof e&&null!=e&&"domain"in e&&"types"in e&&"message"in e;n(81611);class l{constructor(e){this.communicator=e}async getBySafeTxHash(e){if(!e)throw new Error("Invalid safeTxHash");return(await this.communicator.send(a.getTxBySafeTxHash,{safeTxHash:e})).data}async signMessage(e){const t={message:e};return(await this.communicator.send(a.signMessage,t)).data}async signTypedMessage(e){if(!u(e))throw new Error("Invalid typed data");return(await this.communicator.send(a.signTypedMessage,{typedData:e})).data}async send({txs:e,params:t}){if(!e||!e.length)throw new Error("No transactions were passed");const n={txs:e,params:t};return(await this.communicator.send(a.sendTransactions,n)).data}}const d="eth_call",h="eth_gasPrice",p="eth_getLogs",f="eth_getBalance",y="eth_getCode",m="eth_getBlockByHash",g="eth_getBlockByNumber",b="eth_getStorageAt",w="eth_getTransactionByHash",v="eth_getTransactionReceipt",$="eth_getTransactionCount",x="eth_estimateGas",I="safe_setSettings",S={defaultBlockParam:(e="latest")=>e,returnFullTxObjectParam:(e=!1)=>e,blockNumberToHex:e=>Number.isInteger(e)?`0x${e.toString(16)}`:e};class z{constructor(e){this.communicator=e,this.call=this.buildRequest({call:d,formatters:[null,S.defaultBlockParam]}),this.getBalance=this.buildRequest({call:f,formatters:[null,S.defaultBlockParam]}),this.getCode=this.buildRequest({call:y,formatters:[null,S.defaultBlockParam]}),this.getStorageAt=this.buildRequest({call:b,formatters:[null,S.blockNumberToHex,S.defaultBlockParam]}),this.getPastLogs=this.buildRequest({call:p}),this.getBlockByHash=this.buildRequest({call:m,formatters:[null,S.returnFullTxObjectParam]}),this.getBlockByNumber=this.buildRequest({call:g,formatters:[S.blockNumberToHex,S.returnFullTxObjectParam]}),this.getTransactionByHash=this.buildRequest({call:w}),this.getTransactionReceipt=this.buildRequest({call:v}),this.getTransactionCount=this.buildRequest({call:$,formatters:[null,S.defaultBlockParam]}),this.getGasPrice=this.buildRequest({call:h}),this.getEstimateGas=e=>this.buildRequest({call:x})([e]),this.setSafeSettings=this.buildRequest({call:I})}buildRequest(e){const{call:t,formatters:n}=e;return async e=>{n&&Array.isArray(e)&&n.forEach(((t,n)=>{t&&(e[n]=t(e[n]))}));const s={call:t,params:e||[]};return(await this.communicator.send(a.rpcCall,s)).data}}}function A(e){return"string"==typeof e[0]?k(e):function(e){let t=0;for(const n of e)t+=n.length;const n=new Uint8Array(t);let s=0;for(const t of e)n.set(t,s),s+=t.length;return n}(e)}function k(e){return`0x${e.reduce(((e,t)=>e+t.replace("0x","")),"")}`}function E(e,{includeName:t=!1}={}){if("function"!==e.type&&"event"!==e.type&&"error"!==e.type)throw new D(e.type);return`${e.name}(${P(e.inputs,{includeName:t})})`}function P(e,{includeName:t=!1}={}){return e?e.map((e=>function(e,{includeName:t}){if(e.type.startsWith("tuple"))return`(${P(e.components,{includeName:t})})${e.type.slice(5)}`;return e.type+(t&&e.name?` ${e.name}`:"")}(e,{includeName:t}))).join(t?", ":","):""}function B(e,{strict:t=!0}={}){return!!e&&("string"==typeof e&&(t?/^0x[0-9a-fA-F]*$/.test(e):e.startsWith("0x")))}function M(e){return B(e,{strict:!1})?Math.ceil((e.length-2)/2):e.length}const T="2.21.51";let O={getDocsUrl:({docsBaseUrl:e,docsPath:t="",docsSlug:n})=>t?`${e??"https://viem.sh"}${t}${n?`#${n}`:""}`:void 0,version:`viem@${T}`};class j extends Error{constructor(e,t={}){const n=t.cause instanceof j?t.cause.details:t.cause?.message?t.cause.message:t.details,s=t.cause instanceof j&&t.cause.docsPath||t.docsPath,i=O.getDocsUrl?.({...t,docsPath:s});super([e||"An error occurred.","",...t.metaMessages?[...t.metaMessages,""]:[],...i?[`Docs: ${i}`]:[],...n?[`Details: ${n}`]:[],...O.version?[`Version: ${O.version}`]:[]].join("\n"),t.cause?{cause:t.cause}:void 0),Object.defineProperty(this,"details",{enumerable:!0,configurable:!0,writable:!0,value:void 0}),Object.defineProperty(this,"docsPath",{enumerable:!0,configurable:!0,writable:!0,value:void 0}),Object.defineProperty(this,"metaMessages",{enumerable:!0,configurable:!0,writable:!0,value:void 0}),Object.defineProperty(this,"shortMessage",{enumerable:!0,configurable:!0,writable:!0,value:void 0}),Object.defineProperty(this,"version",{enumerable:!0,configurable:!0,writable:!0,value:void 0}),Object.defineProperty(this,"name",{enumerable:!0,configurable:!0,writable:!0,value:"BaseError"}),this.details=n,this.docsPath=s,this.metaMessages=t.metaMessages,this.name=t.name??this.name,this.shortMessage=e,this.version=T}walk(e){return N(this,e)}}function N(e,t){return t?.(e)?e:e&&"object"==typeof e&&"cause"in e&&void 0!==e.cause?N(e.cause,t):t?null:e}class C extends j{constructor({expectedLength:e,givenLength:t,type:n}){super([`ABI encoding array length mismatch for type ${n}.`,`Expected length: ${e}`,`Given length: ${t}`].join("\n"),{name:"AbiEncodingArrayLengthMismatchError"})}}class L extends j{constructor({expectedSize:e,value:t}){super(`Size of bytes "${t}" (bytes${M(t)}) does not match expected size (bytes${e}).`,{name:"AbiEncodingBytesSizeMismatchError"})}}class q extends j{constructor({expectedLength:e,givenLength:t}){super(["ABI encoding params/values length mismatch.",`Expected length (params): ${e}`,`Given length (values): ${t}`].join("\n"),{name:"AbiEncodingLengthMismatchError"})}}class _ extends j{constructor(e,{docsPath:t}={}){super([`Function ${e?`"${e}" `:""}not found on ABI.`,"Make sure you are using the correct ABI and that the function exists on it."].join("\n"),{docsPath:t,name:"AbiFunctionNotFoundError"})}}class R extends j{constructor(e,t){super("Found ambiguous types in overloaded ABI items.",{metaMessages:[`\`${e.type}\` in \`${E(e.abiItem)}\`, and`,`\`${t.type}\` in \`${E(t.abiItem)}\``,"","These types encode differently and cannot be distinguished at runtime.","Remove one of the ambiguous items in the ABI."],name:"AbiItemAmbiguityError"})}}class U extends j{constructor({expectedSize:e,givenSize:t}){super(`Expected bytes${e}, got bytes${t}.`,{name:"BytesSizeMismatchError"})}}class H extends j{constructor(e,{docsPath:t}){super([`Type "${e}" is not a valid encoding type.`,"Please provide a valid ABI type."].join("\n"),{docsPath:t,name:"InvalidAbiEncodingType"})}}class F extends j{constructor(e){super([`Value "${e}" is not a valid array.`].join("\n"),{name:"InvalidArrayError"})}}class D extends j{constructor(e){super([`"${e}" is not a valid definition type.`,'Valid types: "function", "event", "error"'].join("\n"),{name:"InvalidDefinitionTypeError"})}}class V extends j{constructor({address:e}){super(`Address "${e}" is invalid.`,{metaMessages:["- Address must be a hex value of 20 bytes (40 hex characters).","- Address must match its checksum counterpart."],name:"InvalidAddressError"})}}class W extends Map{constructor(e){super(),Object.defineProperty(this,"maxSize",{enumerable:!0,configurable:!0,writable:!0,value:void 0}),this.maxSize=e}get(e){const t=super.get(e);return super.has(e)&&void 0!==t&&(this.delete(e),super.set(e,t)),t}set(e,t){if(super.set(e,t),this.maxSize&&this.size>this.maxSize){const e=this.keys().next().value;e&&this.delete(e)}return this}}class G extends j{constructor({offset:e,position:t,size:n}){super(`Slice ${"start"===t?"starting":"ending"} at offset "${e}" is out-of-bounds (size: ${n}).`,{name:"SliceOffsetOutOfBoundsError"})}}class X extends j{constructor({size:e,targetSize:t,type:n}){super(`${n.charAt(0).toUpperCase()}${n.slice(1).toLowerCase()} size (${e}) exceeds padding size (${t}).`,{name:"SizeExceedsPaddingSizeError"})}}function J(e,{dir:t,size:n=32}={}){return"string"==typeof e?K(e,{dir:t,size:n}):function(e,{dir:t,size:n=32}={}){if(null===n)return e;if(e.length>n)throw new X({size:e.length,targetSize:n,type:"bytes"});const s=new Uint8Array(n);for(let i=0;i<n;i++){const r="right"===t;s[r?i:n-i-1]=e[r?i:e.length-i-1]}return s}(e,{dir:t,size:n})}function K(e,{dir:t,size:n=32}={}){if(null===n)return e;const s=e.replace("0x","");if(s.length>2*n)throw new X({size:Math.ceil(s.length/2),targetSize:n,type:"hex"});return`0x${s["right"===t?"padEnd":"padStart"](2*n,"0")}`}class Q extends j{constructor({max:e,min:t,signed:n,size:s,value:i}){super(`Number "${i}" is not in safe ${s?`${8*s}-bit ${n?"signed":"unsigned"} `:""}integer range ${e?`(${t} to ${e})`:`(above ${t})`}`,{name:"IntegerOutOfRangeError"})}}class Y extends j{constructor({givenSize:e,maxSize:t}){super(`Size cannot exceed ${t} bytes. Given size: ${e} bytes.`,{name:"SizeOverflowError"})}}function Z(e,{size:t}){if(M(e)>t)throw new Y({givenSize:M(e),maxSize:t})}const ee=Array.from({length:256},((e,t)=>t.toString(16).padStart(2,"0")));function te(e,t={}){return"number"==typeof e||"bigint"==typeof e?ie(e,t):"string"==typeof e?ae(e,t):"boolean"==typeof e?ne(e,t):se(e,t)}function ne(e,t={}){const n=`0x${Number(e)}`;return"number"==typeof t.size?(Z(n,{size:t.size}),J(n,{size:t.size})):n}function se(e,t={}){let n="";for(let t=0;t<e.length;t++)n+=ee[e[t]];const s=`0x${n}`;return"number"==typeof t.size?(Z(s,{size:t.size}),J(s,{dir:"right",size:t.size})):s}function ie(e,t={}){const{signed:n,size:s}=t,i=BigInt(e);let r;s?r=n?(1n<<8n*BigInt(s)-1n)-1n:2n**(8n*BigInt(s))-1n:"number"==typeof e&&(r=BigInt(Number.MAX_SAFE_INTEGER));const a="bigint"==typeof r&&n?-r-1n:0;if(r&&i>r||i<a){const t="bigint"==typeof e?"n":"";throw new Q({max:r?`${r}${t}`:void 0,min:`${a}${t}`,signed:n,size:s,value:`${e}${t}`})}const o=`0x${(n&&i<0?(1n<<BigInt(8*s))+BigInt(i):i).toString(16)}`;return s?J(o,{size:s}):o}const re=new TextEncoder;function ae(e,t={}){return se(re.encode(e),t)}const oe=new TextEncoder;function ce(e,t={}){return"number"==typeof e||"bigint"==typeof e?function(e,t){const n=ie(e,t);return de(n)}(e,t):"boolean"==typeof e?function(e,t={}){const n=new Uint8Array(1);if(n[0]=Number(e),"number"==typeof t.size)return Z(n,{size:t.size}),J(n,{size:t.size});return n}(e,t):B(e)?de(e,t):he(e,t)}const ue={zero:48,nine:57,A:65,F:70,a:97,f:102};function le(e){return e>=ue.zero&&e<=ue.nine?e-ue.zero:e>=ue.A&&e<=ue.F?e-(ue.A-10):e>=ue.a&&e<=ue.f?e-(ue.a-10):void 0}function de(e,t={}){let n=e;t.size&&(Z(n,{size:t.size}),n=J(n,{dir:"right",size:t.size}));let s=n.slice(2);s.length%2&&(s=`0${s}`);const i=s.length/2,r=new Uint8Array(i);for(let e=0,t=0;e<i;e++){const n=le(s.charCodeAt(t++)),i=le(s.charCodeAt(t++));if(void 0===n||void 0===i)throw new j(`Invalid byte sequence ("${s[t-2]}${s[t-1]}" in "${s}").`);r[e]=16*n+i}return r}function he(e,t={}){const n=oe.encode(e);return"number"==typeof t.size?(Z(n,{size:t.size}),J(n,{dir:"right",size:t.size})):n}function pe(e){if(!Number.isSafeInteger(e)||e<0)throw new Error(`positive integer expected, not ${e}`)}function fe(e,...t){if(!((n=e)instanceof Uint8Array||null!=n&&"object"==typeof n&&"Uint8Array"===n.constructor.name))throw new Error("Uint8Array expected");var n;if(t.length>0&&!t.includes(e.length))throw new Error(`Uint8Array expected of length ${t}, not of length=${e.length}`)}function ye(e,t=!0){if(e.destroyed)throw new Error("Hash instance has been destroyed");if(t&&e.finished)throw new Error("Hash#digest() has already been called")}function me(e,t){fe(e);const n=t.outputLen;if(e.length<n)throw new Error(`digestInto() expects output buffer of length at least ${n}`)}const ge=BigInt(2**32-1),be=BigInt(32);function we(e,t=!1){return t?{h:Number(e&ge),l:Number(e>>be&ge)}:{h:0|Number(e>>be&ge),l:0|Number(e&ge)}}function ve(e,t=!1){let n=new Uint32Array(e.length),s=new Uint32Array(e.length);for(let i=0;i<e.length;i++){const{h:r,l:a}=we(e[i],t);[n[i],s[i]]=[r,a]}return[n,s]}const $e=(e,t,n)=>e<<n|t>>>32-n,xe=(e,t,n)=>t<<n|e>>>32-n,Ie=(e,t,n)=>t<<n-32|e>>>64-n,Se=(e,t,n)=>e<<n-32|t>>>64-n;const ze=68===new Uint8Array(new Uint32Array([287454020]).buffer)[0],Ae=e=>e<<24&4278190080|e<<8&16711680|e>>>8&65280|e>>>24&255;function ke(e){for(let t=0;t<e.length;t++)e[t]=Ae(e[t])}function Ee(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)),fe(e),e}class Pe{clone(){return this._cloneInto()}}const Be=[],Me=[],Te=[],Oe=BigInt(0),je=BigInt(1),Ne=BigInt(2),Ce=BigInt(7),Le=BigInt(256),qe=BigInt(113);for(let e=0,t=je,n=1,s=0;e<24;e++){[n,s]=[s,(2*n+3*s)%5],Be.push(2*(5*s+n)),Me.push((e+1)*(e+2)/2%64);let i=Oe;for(let e=0;e<7;e++)t=(t<<je^(t>>Ce)*qe)%Le,t&Ne&&(i^=je<<(je<<BigInt(e))-je);Te.push(i)}const[_e,Re]=ve(Te,!0),Ue=(e,t,n)=>n>32?Ie(e,t,n):$e(e,t,n),He=(e,t,n)=>n>32?Se(e,t,n):xe(e,t,n);class Fe extends Pe{constructor(e,t,n,s=!1,i=24){if(super(),this.blockLen=e,this.suffix=t,this.outputLen=n,this.enableXOF=s,this.rounds=i,this.pos=0,this.posOut=0,this.finished=!1,this.destroyed=!1,pe(n),0>=this.blockLen||this.blockLen>=200)throw new Error("Sha3 supports only keccak-f1600 function");var r;this.state=new Uint8Array(200),this.state32=(r=this.state,new Uint32Array(r.buffer,r.byteOffset,Math.floor(r.byteLength/4)))}keccak(){ze||ke(this.state32),function(e,t=24){const n=new Uint32Array(10);for(let s=24-t;s<24;s++){for(let t=0;t<10;t++)n[t]=e[t]^e[t+10]^e[t+20]^e[t+30]^e[t+40];for(let t=0;t<10;t+=2){const s=(t+8)%10,i=(t+2)%10,r=n[i],a=n[i+1],o=Ue(r,a,1)^n[s],c=He(r,a,1)^n[s+1];for(let n=0;n<50;n+=10)e[t+n]^=o,e[t+n+1]^=c}let t=e[2],i=e[3];for(let n=0;n<24;n++){const s=Me[n],r=Ue(t,i,s),a=He(t,i,s),o=Be[n];t=e[o],i=e[o+1],e[o]=r,e[o+1]=a}for(let t=0;t<50;t+=10){for(let s=0;s<10;s++)n[s]=e[t+s];for(let s=0;s<10;s++)e[t+s]^=~n[(s+2)%10]&n[(s+4)%10]}e[0]^=_e[s],e[1]^=Re[s]}n.fill(0)}(this.state32,this.rounds),ze||ke(this.state32),this.posOut=0,this.pos=0}update(e){ye(this);const{blockLen:t,state:n}=this,s=(e=Ee(e)).length;for(let i=0;i<s;){const r=Math.min(t-this.pos,s-i);for(let t=0;t<r;t++)n[this.pos++]^=e[i++];this.pos===t&&this.keccak()}return this}finish(){if(this.finished)return;this.finished=!0;const{state:e,suffix:t,pos:n,blockLen:s}=this;e[n]^=t,128&t&&n===s-1&&this.keccak(),e[s-1]^=128,this.keccak()}writeInto(e){ye(this,!1),fe(e),this.finish();const t=this.state,{blockLen:n}=this;for(let s=0,i=e.length;s<i;){this.posOut>=n&&this.keccak();const r=Math.min(n-this.posOut,i-s);e.set(t.subarray(this.posOut,this.posOut+r),s),this.posOut+=r,s+=r}return e}xofInto(e){if(!this.enableXOF)throw new Error("XOF is not possible for this instance");return this.writeInto(e)}xof(e){return pe(e),this.xofInto(new Uint8Array(e))}digestInto(e){if(me(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=!0,this.state.fill(0)}_cloneInto(e){const{blockLen:t,suffix:n,outputLen:s,rounds:i,enableXOF:r}=this;return e||(e=new Fe(t,n,s,r,i)),e.state32.set(this.state32),e.pos=this.pos,e.posOut=this.posOut,e.finished=this.finished,e.rounds=i,e.suffix=n,e.outputLen=s,e.enableXOF=r,e.destroyed=this.destroyed,e}}const De=(e,t,n)=>function(e){const t=t=>e().update(Ee(t)).digest(),n=e();return t.outputLen=n.outputLen,t.blockLen=n.blockLen,t.create=()=>e(),t}((()=>new Fe(t,e,n))),Ve=De(1,136,32);function We(e,t){const n=t||"hex",s=Ve(B(e,{strict:!1})?ce(e):e);return"bytes"===n?s:te(s)}const Ge=new W(8192);function Xe(e,t){if(Ge.has(`${e}.${t}`))return Ge.get(`${e}.${t}`);const n=t?`${t}${e.toLowerCase()}`:e.substring(2).toLowerCase(),s=We(he(n),"bytes"),i=(t?n.substring(`${t}0x`.length):n).split("");for(let e=0;e<40;e+=2)s[e>>1]>>4>=8&&i[e]&&(i[e]=i[e].toUpperCase()),(15&s[e>>1])>=8&&i[e+1]&&(i[e+1]=i[e+1].toUpperCase());const r=`0x${i.join("")}`;return Ge.set(`${e}.${t}`,r),r}const Je=/^0x[a-fA-F0-9]{40}$/,Ke=new W(8192);function Qe(e,t){const{strict:n=!0}=t??{},s=`${e}.${n}`;if(Ke.has(s))return Ke.get(s);const i=!(!Je.test(e)||e.toLowerCase()!==e&&n&&Xe(e)!==e);return Ke.set(s,i),i}function Ye(e,t,n,{strict:s}={}){return B(e,{strict:!1})?function(e,t,n,{strict:s}={}){Ze(e,t);const i=`0x${e.replace("0x","").slice(2*(t??0),2*(n??e.length))}`;s&&et(i,t,n);return i}(e,t,n,{strict:s}):function(e,t,n,{strict:s}={}){Ze(e,t);const i=e.slice(t,n);s&&et(i,t,n);return i}(e,t,n,{strict:s})}function Ze(e,t){if("number"==typeof t&&t>0&&t>M(e)-1)throw new G({offset:t,position:"start",size:M(e)})}function et(e,t,n){if("number"==typeof t&&"number"==typeof n&&M(e)!==n-t)throw new G({offset:n,position:"end",size:M(e)})}function tt(e,t){if(e.length!==t.length)throw new q({expectedLength:e.length,givenLength:t.length});const n=function({params:e,values:t}){const n=[];for(let s=0;s<e.length;s++)n.push(nt({param:e[s],value:t[s]}));return n}({params:e,values:t}),s=st(n);return 0===s.length?"0x":s}function nt({param:e,value:t}){const n=function(e){const t=e.match(/^(.*)\[(\d+)?\]$/);return t?[t[2]?Number(t[2]):null,t[1]]:void 0}(e.type);if(n){const[s,i]=n;return function(e,{length:t,param:n}){const s=null===t;if(!Array.isArray(e))throw new F(e);if(!s&&e.length!==t)throw new C({expectedLength:t,givenLength:e.length,type:`${n.type}[${t}]`});let i=!1;const r=[];for(let t=0;t<e.length;t++){const s=nt({param:n,value:e[t]});s.dynamic&&(i=!0),r.push(s)}if(s||i){const e=st(r);if(s){const t=ie(r.length,{size:32});return{dynamic:!0,encoded:r.length>0?A([t,e]):t}}if(i)return{dynamic:!0,encoded:e}}return{dynamic:!1,encoded:A(r.map((({encoded:e})=>e)))}}(t,{length:s,param:{...e,type:i}})}if("tuple"===e.type)return function(e,{param:t}){let n=!1;const s=[];for(let i=0;i<t.components.length;i++){const r=t.components[i],a=nt({param:r,value:e[Array.isArray(e)?i:r.name]});s.push(a),a.dynamic&&(n=!0)}return{dynamic:n,encoded:n?st(s):A(s.map((({encoded:e})=>e)))}}(t,{param:e});if("address"===e.type)return function(e){if(!Qe(e))throw new V({address:e});return{dynamic:!1,encoded:K(e.toLowerCase())}}(t);if("bool"===e.type)return function(e){if("boolean"!=typeof e)throw new j(`Invalid boolean value: "${e}" (type: ${typeof e}). Expected: \`true\` or \`false\`.`);return{dynamic:!1,encoded:K(ne(e))}}(t);if(e.type.startsWith("uint")||e.type.startsWith("int")){return function(e,{signed:t}){return{dynamic:!1,encoded:ie(e,{size:32,signed:t})}}(t,{signed:e.type.startsWith("int")})}if(e.type.startsWith("bytes"))return function(e,{param:t}){const[,n]=t.type.split("bytes"),s=M(e);if(!n){let t=e;return s%32!=0&&(t=K(t,{dir:"right",size:32*Math.ceil((e.length-2)/2/32)})),{dynamic:!0,encoded:A([K(ie(s,{size:32})),t])}}if(s!==Number.parseInt(n))throw new L({expectedSize:Number.parseInt(n),value:e});return{dynamic:!1,encoded:K(e,{dir:"right"})}}(t,{param:e});if("string"===e.type)return function(e){const t=ae(e),n=Math.ceil(M(t)/32),s=[];for(let e=0;e<n;e++)s.push(K(Ye(t,32*e,32*(e+1)),{dir:"right"}));return{dynamic:!0,encoded:A([K(ie(M(t),{size:32})),...s])}}(t);throw new H(e.type,{docsPath:"/docs/contract/encodeAbiParameters"})}function st(e){let t=0;for(let n=0;n<e.length;n++){const{dynamic:s,encoded:i}=e[n];t+=s?32:M(i)}const n=[],s=[];let i=0;for(let r=0;r<e.length;r++){const{dynamic:a,encoded:o}=e[r];a?(n.push(ie(t+i,{size:32})),s.push(o),i+=M(o)):n.push(o)}return A([...n,...s])}function it(e){return We(ce(e))}const rt=/^tuple(?<array>(\[(\d*)\])*)$/;function at(e){let t=e.type;if(rt.test(e.type)&&"components"in e){t="(";const n=e.components.length;for(let s=0;s<n;s++){t+=at(e.components[s]),s<n-1&&(t+=", ")}const s=function(e,t){const n=e.exec(t);return n?.groups}(rt,e.type);return t+=`)${s?.array??""}`,at({...e,type:t})}return"indexed"in e&&e.indexed&&(t=`${t} indexed`),e.name?`${t} ${e.name}`:t}function ot(e){let t="";const n=e.length;for(let s=0;s<n;s++){t+=at(e[s]),s!==n-1&&(t+=", ")}return t}const ct=e=>{var t;return function(e){let t=!0,n="",s=0,i="",r=!1;for(let a=0;a<e.length;a++){const o=e[a];if(["(",")",","].includes(o)&&(t=!0),"("===o&&s++,")"===o&&s--,t)if(0!==s)" "!==o?(i+=o,n+=o):","!==e[a-1]&&","!==n&&",("!==n&&(n="",t=!1);else if(" "===o&&["event","function",""].includes(i))i="";else if(i+=o,")"===o){r=!0;break}}if(!r)throw new j("Unable to normalize signature.");return i}("string"==typeof e?e:"function"===(t=e).type?`function ${t.name}(${ot(t.inputs)})${t.stateMutability&&"nonpayable"!==t.stateMutability?` ${t.stateMutability}`:""}${t.outputs.length?` returns (${ot(t.outputs)})`:""}`:"event"===t.type?`event ${t.name}(${ot(t.inputs)})`:"error"===t.type?`error ${t.name}(${ot(t.inputs)})`:"constructor"===t.type?`constructor(${ot(t.inputs)})${"payable"===t.stateMutability?" payable":""}`:"fallback"===t.type?"fallback()":"receive() external payable")};function ut(e){return it(ct(e))}const lt=e=>Ye(ut(e),0,4),dt=ut;function ht(e,t){const n=typeof e,s=t.type;switch(s){case"address":return Qe(e,{strict:!1});case"bool":return"boolean"===n;case"function":case"string":return"string"===n;default:return"tuple"===s&&"components"in t?Object.values(t.components).every(((t,n)=>ht(Object.values(e)[n],t))):/^u?int(8|16|24|32|40|48|56|64|72|80|88|96|104|112|120|128|136|144|152|160|168|176|184|192|200|208|216|224|232|240|248|256)?$/.test(s)?"number"===n||"bigint"===n:/^bytes([1-9]|1[0-9]|2[0-9]|3[0-2])?$/.test(s)?"string"===n||e instanceof Uint8Array:!!/[a-z]+[1-9]{0,3}(\[[0-9]{0,}\])+$/.test(s)&&(Array.isArray(e)&&e.every((e=>ht(e,{...t,type:s.replace(/(\[[0-9]{0,}\])$/,"")}))))}}function pt(e,t,n){for(const s in e){const i=e[s],r=t[s];if("tuple"===i.type&&"tuple"===r.type&&"components"in i&&"components"in r)return pt(i.components,r.components,n[s]);const a=[i.type,r.type];if(!(!a.includes("address")||!a.includes("bytes20"))||(a.includes("address")&&a.includes("string")||!(!a.includes("address")||!a.includes("bytes")))&&Qe(n[s],{strict:!1}))return a}}const ft="/docs/contract/encodeFunctionData";function yt(e){const{abi:t,args:n,functionName:s}=e;let i=t[0];if(s){const e=function(e){const{abi:t,args:n=[],name:s}=e,i=B(s,{strict:!1}),r=t.filter((e=>i?"function"===e.type?lt(e)===s:"event"===e.type&&dt(e)===s:"name"in e&&e.name===s));if(0===r.length)return;if(1===r.length)return r[0];let a;for(const e of r)if("inputs"in e)if(n&&0!==n.length){if(e.inputs&&0!==e.inputs.length&&e.inputs.length===n.length&&n.every(((t,n)=>{const s="inputs"in e&&e.inputs[n];return!!s&&ht(t,s)}))){if(a&&"inputs"in a&&a.inputs){const t=pt(e.inputs,a.inputs,n);if(t)throw new R({abiItem:e,type:t[0]},{abiItem:a,type:t[1]})}a=e}}else if(!e.inputs||0===e.inputs.length)return e;return a||r[0]}({abi:t,args:n,name:s});if(!e)throw new _(s,{docsPath:ft});i=e}if("function"!==i.type)throw new _(void 0,{docsPath:ft});return{abi:[i],functionName:lt(E(i))}}function mt(e){const{args:t}=e,{abi:n,functionName:s}=1===e.abi.length&&e.functionName?.startsWith("0x")?e:yt(e),i=n[0];return k([s,("inputs"in i&&i.inputs?tt(i.inputs,t??[]):void 0)??"0x"])}function gt(e,t){return We(function(e){const t="string"==typeof e?ae(e):"string"==typeof e.raw?e.raw:se(e.raw);return A([ae(`Ethereum Signed Message:\n${M(t)}`),t])}(e),t)}class bt extends j{constructor({domain:e}){var t,n,s;super(`Invalid domain "${t=e,JSON.stringify(t,((e,t)=>{const s="bigint"==typeof t?t.toString():t;return"function"==typeof n?n(e,s):s}),s)}".`,{metaMessages:["Must be a valid EIP-712 domain."]})}}class wt extends j{constructor({primaryType:e,types:t}){super(`Invalid primary type \`${e}\` must be one of \`${JSON.stringify(Object.keys(t))}\`.`,{docsPath:"/api/glossary/Errors#typeddatainvalidprimarytypeerror",metaMessages:["Check that the primary type is a key in `types`."]})}}class vt extends j{constructor({type:e}){super(`Struct type "${e}" is invalid.`,{metaMessages:["Struct type must not be a Solidity type."],name:"InvalidStructTypeError"})}}const $t=/^bytes([1-9]|1[0-9]|2[0-9]|3[0-2])?$/,xt=/^(u?int)(8|16|24|32|40|48|56|64|72|80|88|96|104|112|120|128|136|144|152|160|168|176|184|192|200|208|216|224|232|240|248|256)?$/;function It({domain:e}){return["string"==typeof e?.name&&{name:"name",type:"string"},e?.version&&{name:"version",type:"string"},"number"==typeof e?.chainId&&{name:"chainId",type:"uint256"},e?.verifyingContract&&{name:"verifyingContract",type:"address"},e?.salt&&{name:"salt",type:"bytes32"}].filter(Boolean)}function St(e){if("address"===e||"bool"===e||"string"===e||e.startsWith("bytes")||e.startsWith("uint")||e.startsWith("int"))throw new vt({type:e})}function zt(e){const{domain:t={},message:n,primaryType:s}=e,i={EIP712Domain:It({domain:t}),...e.types};!function(e){const{domain:t,message:n,primaryType:s,types:i}=e,r=(e,t)=>{for(const n of e){const{name:e,type:s}=n,a=t[e],o=s.match(xt);if(o&&("number"==typeof a||"bigint"==typeof a)){const[e,t,n]=o;ie(a,{signed:"int"===t,size:Number.parseInt(n)/8})}if("address"===s&&"string"==typeof a&&!Qe(a))throw new V({address:a});const c=s.match($t);if(c){const[e,t]=c;if(t&&M(a)!==Number.parseInt(t))throw new U({expectedSize:Number.parseInt(t),givenSize:M(a)})}const u=i[s];u&&(St(s),r(u,a))}};if(i.EIP712Domain&&t){if("object"!=typeof t)throw new bt({domain:t});r(i.EIP712Domain,t)}if("EIP712Domain"!==s){if(!i[s])throw new wt({primaryType:s,types:i});r(i[s],n)}}({domain:t,message:n,primaryType:s,types:i});const r=["0x1901"];return t&&r.push(function({domain:e,types:t}){return At({data:e,primaryType:"EIP712Domain",types:t})}({domain:t,types:i})),"EIP712Domain"!==s&&r.push(At({data:n,primaryType:s,types:i})),We(A(r))}function At({data:e,primaryType:t,types:n}){return We(kt({data:e,primaryType:t,types:n}))}function kt({data:e,primaryType:t,types:n}){const s=[{type:"bytes32"}],i=[Et({primaryType:t,types:n})];for(const r of n[t]){const[t,a]=Bt({types:n,name:r.name,type:r.type,value:e[r.name]});s.push(t),i.push(a)}return tt(s,i)}function Et({primaryType:e,types:t}){const n=te(function({primaryType:e,types:t}){let n="";const s=Pt({primaryType:e,types:t});s.delete(e);const i=[e,...Array.from(s).sort()];for(const e of i)n+=`${e}(${t[e].map((({name:e,type:t})=>`${t} ${e}`)).join(",")})`;return n}({primaryType:e,types:t}));return We(n)}function Pt({primaryType:e,types:t},n=new Set){const s=e.match(/^\w*/u),i=s?.[0];if(n.has(i)||void 0===t[i])return n;n.add(i);for(const e of t[i])Pt({primaryType:e.type,types:t},n);return n}function Bt({types:e,name:t,type:n,value:s}){if(void 0!==e[n])return[{type:"bytes32"},We(kt({data:s,primaryType:n,types:e}))];if("bytes"===n){return[{type:"bytes32"},We(s=`0x${(s.length%2?"0":"")+s.slice(2)}`)]}if("string"===n)return[{type:"bytes32"},We(te(s))];if(n.lastIndexOf("]")===n.length-1){const i=n.slice(0,n.lastIndexOf("[")),r=s.map((n=>Bt({name:t,type:i,types:e,value:n})));return[{type:"bytes32"},We(tt(r.map((([e])=>e)),r.map((([,e])=>e))))]}return[{type:n},s]}const Mt=4001;class Tt extends Error{constructor(e,t,n){super(e),this.code=t,this.data=n,Object.setPrototypeOf(this,Tt.prototype)}}class Ot{constructor(e){this.communicator=e}async getPermissions(){return(await this.communicator.send(a.wallet_getPermissions,void 0)).data}async requestPermissions(e){if(!this.isPermissionRequestValid(e))throw new Tt("Permissions request is invalid",Mt);try{return(await this.communicator.send(a.wallet_requestPermissions,e)).data}catch{throw new Tt("Permissions rejected",Mt)}}isPermissionRequestValid(e){return e.every((e=>"object"==typeof e&&Object.keys(e).every((e=>!!Object.values(o).includes(e)))))}}const jt=(e,t)=>t.some((t=>t.parentCapability===e)),Nt=()=>(e,t,n)=>{const s=n.value;return n.value=async function(){const e=new Ot(this.communicator);let n=await e.getPermissions();if(jt(t,n)||(n=await e.requestPermissions([{[t]:{}}])),!jt(t,n))throw new Tt("Permissions rejected",Mt);return s.apply(this)},n};var Ct=function(e,t,n,s){var i,r=arguments.length,a=r<3?t:null===s?s=Object.getOwnPropertyDescriptor(t,n):s;if("object"==typeof Reflect&&"function"==typeof Reflect.decorate)a=Reflect.decorate(e,t,n,s);else for(var o=e.length-1;o>=0;o--)(i=e[o])&&(a=(r<3?i(a):r>3?i(t,n,a):i(t,n))||a);return r>3&&a&&Object.defineProperty(t,n,a),a};class Lt{constructor(e){this.communicator=e}async getChainInfo(){return(await this.communicator.send(a.getChainInfo,void 0)).data}async getInfo(){return(await this.communicator.send(a.getSafeInfo,void 0)).data}async experimental_getBalances({currency:e="usd"}={}){return(await this.communicator.send(a.getSafeBalances,{currency:e})).data}async check1271Signature(e,t="0x"){const n=await this.getInfo(),s=mt({abi:[{constant:!1,inputs:[{name:"_dataHash",type:"bytes32"},{name:"_signature",type:"bytes"}],name:"isValidSignature",outputs:[{name:"",type:"bytes4"}],payable:!1,stateMutability:"nonpayable",type:"function"}],functionName:"isValidSignature",args:[e,t]}),i={call:d,params:[{to:n.safeAddress,data:s},"latest"]};try{return"0x1626ba7e"===(await this.communicator.send(a.rpcCall,i)).data.slice(0,10).toLowerCase()}catch(e){return!1}}async check1271SignatureBytes(e,t="0x"){const n=await this.getInfo(),s=mt({abi:[{constant:!1,inputs:[{name:"_data",type:"bytes"},{name:"_signature",type:"bytes"}],name:"isValidSignature",outputs:[{name:"",type:"bytes4"}],payable:!1,stateMutability:"nonpayable",type:"function"}],functionName:"isValidSignature",args:[e,t]}),i={call:d,params:[{to:n.safeAddress,data:s},"latest"]};try{return"0x20c13b0b"===(await this.communicator.send(a.rpcCall,i)).data.slice(0,10).toLowerCase()}catch(e){return!1}}calculateMessageHash(e){return gt(e)}calculateTypedMessageHash(e){const t="object"==typeof e.domain.chainId?e.domain.chainId.toNumber():Number(e.domain.chainId);let n=e.primaryType;if(!n){const t=Object.values(e.types),s=Object.keys(e.types).filter((e=>t.every((t=>t.every((({type:t})=>t.replace("[","").replace("]","")!==e))))));if(0===s.length||s.length>1)throw new Error("Please specify primaryType");n=s[0]}return zt({message:e.message,domain:{...e.domain,chainId:t,verifyingContract:e.domain.verifyingContract,salt:e.domain.salt},types:e.types,primaryType:n})}async getOffChainSignature(e){return(await this.communicator.send(a.getOffChainSignature,e)).data}async isMessageSigned(e,t="0x"){let n;if("string"==typeof e&&(n=async()=>{const n=this.calculateMessageHash(e);return await this.isMessageHashSigned(n,t)}),u(e)&&(n=async()=>{const n=this.calculateTypedMessageHash(e);return await this.isMessageHashSigned(n,t)}),n){return await n()}throw new Error("Invalid message type")}async isMessageHashSigned(e,t="0x"){const n=[this.check1271Signature.bind(this),this.check1271SignatureBytes.bind(this)];for(const s of n){if(await s(e,t))return!0}return!1}async getEnvironmentInfo(){return(await this.communicator.send(a.getEnvironmentInfo,void 0)).data}async requestAddressBook(){return(await this.communicator.send(a.requestAddressBook,void 0)).data}}Ct([Nt()],Lt.prototype,"requestAddressBook",null);const qt=class{constructor(e={}){const{allowedDomains:t=null,debug:n=!1}=e;this.communicator=new c(t,n),this.eth=new z(this.communicator),this.txs=new l(this.communicator),this.safe=new Lt(this.communicator),this.wallet=new Ot(this.communicator)}}}}]);