OpChan/dist/assets/index-sYri9oP4.js

2 lines
5.7 KiB
JavaScript
Raw Permalink Normal View History

2025-09-09 17:41:33 +05:30
import{ag as _,ah as b,ai as k}from"./index-Cr5N_0pd.js";import{e as S}from"./index-Cl4M8jG7.js";function v(n,i){for(var c=0;c<i.length;c++){const e=i[c];if(typeof e!="string"&&!Array.isArray(e)){for(const r in e)if(r!=="default"&&!(r in n)){const u=Object.getOwnPropertyDescriptor(e,r);u&&Object.defineProperty(n,r,u.get?u:{enumerable:!0,get:()=>e[r]})}}}return Object.freeze(Object.defineProperty(n,Symbol.toStringTag,{value:"Module"}))}var w={},m={};const H=_(S);var p={};Object.defineProperty(p,"__esModule",{value:!0});p.numberToHex=p.getLowerCase=void 0;function y(n){return n&&n.toLowerCase()}p.getLowerCase=y;function C(n){return`0x${n.toString(16)}`}p.numberToHex=C;Object.defineProperty(m,"__esModule",{value:!0});m.SafeAppProvider=void 0;const f=H,A=b,o=p;class I extends A.EventEmitter{constructor(i,c){super(),this.submittedTxs=new Map,this.safe=i,this.sdk=c}async connect(){this.emit("connect",{chainId:this.chainId})}async disconnect(){}get chainId(){return this.safe.chainId}async request(i){const{method:c,params:e=[]}=i;switch(c){case"eth_accounts":return[this.safe.safeAddress];case"net_version":case"eth_chainId":return(0,o.numberToHex)(this.chainId);case"personal_sign":{const[t,s]=e;if(this.safe.safeAddress.toLowerCase()!==s.toLowerCase())throw new Error("The address or message hash is invalid");const a=await this.sdk.txs.signMessage(t);return("signature"in a?a.signature:void 0)||"0x"}case"eth_sign":{const[t,s]=e;if(this.safe.safeAddress.toLowerCase()!==t.toLowerCase()||!s.startsWith("0x"))throw new Error("The address or message hash is invalid");const a=await this.sdk.txs.signMessage(s);return("signature"in a?a.signature:void 0)||"0x"}case"eth_signTypedData":case"eth_signTypedData_v4":{const[t,s]=e,a=typeof s=="string"?JSON.parse(s):s;if(this.safe.safeAddress.toLowerCase()!==t.toLowerCase())throw new Error("The address is invalid");const d=await this.sdk.txs.signTypedMessage(a);return("signature"in d?d.signature:void 0)||"0x"}case"eth_sendTransaction":const r={...e[0],value:e[0].value||"0",data:e[0].data||"0x"};typeof r.gas=="string"&&r.gas.startsWith("0x")&&(r.gas=parseInt(r.gas,16));const u=await this.sdk.txs.send({txs:[r],params:{safeTxGas:r.gas}});return this.submittedTxs.set(u.safeTxHash,{from:this.safe.safeAddress,hash:u.safeTxHash,gas:0,gasPrice:"0x00",nonce:0,input:r.data,value:r.value,to:r.to,blockHash:null,blockNumber:null,transactionIndex:null}),u.safeTxHash;case"eth_blockNumber":return(await this.sdk.eth.getBlockByNumber(["latest"])).number;case"eth_getBalance":return this.sdk.eth.getBalance([(0,o.getLowerCase)(e[0]),e[1]]);case"eth_getCode":return this.sdk.eth.getCode([(0,o.getLowerCase)(e[0]),e[1]]);case"eth_getTransactionCount":return this.sdk.eth.getTransactionCount([(0,o.getLowerCase)(e[0]),e[1]]);case"eth_getStorageAt":return this.sdk.eth.getStorageAt([(0,o.getLowerCase)(e[0]),e[1],e[2]]);case"eth_getBlockByNumber":return this.sdk.eth.getBlockByNumber([e[0],e[1]]);case"eth_getBlockByHash":return this.sdk.eth.getBlockByHash([e[0],e[1]]);case"eth_getTransactionByHash":let g=e[0];try{g=(await this.sdk.txs.getBySafeTxHash(g)).txHash||g}catch{}return this.submittedTxs.has(g)?this.submittedTxs.get(g):this.sdk.eth.getTransactionByHash([g]).then(t=>(t&&(t.hash=e[0]),t));case"eth_getTransactionReceipt":{let t=e[0];try{t=(await this.sdk.txs.getBySafeTxHash(t)).txHash||t}catch{}return this.sdk.eth.getTransactionReceipt([t]).then(s=>(s&&(s.transactionHash=e[0]),s))}case"eth_estimateGas":return this.sdk.eth.getEstimateGas(e[0]);case"eth_call":return this.sdk.eth.call([e[0],e[1]]);case"eth_getLogs":return this.sdk.eth.getPastLogs([e[0]]);case"eth_gasPrice":return this.sdk.eth.getGasPrice();case"wallet_getPermissions":return this.sdk.wallet.getPermissions();case"wallet_requestPermissions":return this.sdk.wallet.requestPermissions(e[0]);case"safe_setSettings":return this.sdk.eth.setSafeSettings([e[0]]);case"wallet_sendCalls":{const{from:t,calls:s,chainId:a}=e[0];if(a!==(0,o.numberToHex)(this.chainId))throw new Error(`Safe is not on chain ${a}`);if(t!==this.safe.safeAddress)throw Error("Invalid from address");const