UNPKG

@privy-io/js-sdk-core

Version:

Vanilla JS client for the Privy Auth API

2 lines (1 loc) 2.09 kB
import{BigNumber as e}from"@ethersproject/bignumber";import{Contract as r}from"@ethersproject/contracts";import{serialize as a}from"@ethersproject/transactions";import{base as t,baseSepolia as i,optimism as o,optimismSepolia as s,zora as n,zoraTestnet as c,zoraSepolia as m}from"@privy-io/chains";import{convertBigNumberish as P,toEthersUnsignedTransaction as d}from"../utils/ethers.mjs";const l="0x420000000000000000000000000000000000000F",f=["function getL1Fee(bytes memory _data) external view returns (uint256)"],h=e=>[t.id,i.id,o.id,s.id,n.id,c.id,m.id,81457,168587773].includes(e),F=async(r,a)=>{if(!h(r.chainId))throw Error("Invalid chain ID for OP Stack gas estimation.");if(void 0===r.type&&(r.type=2),r.gasPrice&&(console.warn("`gasPrice` is not supported on this chain and will be ignored. Use `maxPriorityFeePerGas` and/or `maxFeePerGas` instead."),delete r.gasPrice),r.maxPriorityFeePerGas&&r.maxFeePerGas)return r;try{if(!r.maxPriorityFeePerGas){let e=await a.send("eth_maxPriorityFeePerGas",[]);r.maxPriorityFeePerGas=e}if(r.maxFeePerGas&&(console.warn("maxFeePerGas is specified without maxPriorityFeePerGas - this can result in hung transactions."),r.maxPriorityFeePerGas>=r.maxFeePerGas))throw Error("Overridden maxFeePerGas is less than or equal to the calculated maxPriorityFeePerGas. Please set both values or maxPriorityFeePerGas alone for correct gas estimation.");if(!r.maxFeePerGas){let{lastBaseFeePerGas:t}=await a.getFeeData();if(!t)throw Error("Unable to fetch baseFee for last block.");let i=e.from(t).mul(e.from(126)).div(e.from(100)).add(e.from(r.maxPriorityFeePerGas));r.maxFeePerGas=P(i)}}catch(e){throw Error(`Failed to set gas price for OP stack transaction: ${e}.`)}return r};async function x(t,i){if(!t.chainId||t.chainId&&!h(t.chainId))return e.from(0);let o=e.from(0);try{let e=new r("0x420000000000000000000000000000000000000F",f,i),s=d(t),n=a(s);o=await e.getL1Fee(n)}catch(e){}return o}export{f as OPTIMISM_STACK_GAS_PRICE_ORACLE_ABI,l as OPTIMISM_STACK_GAS_PRICE_ORACLE_ADDRESS,F as defaultGasForOpStack,x as estimateOpStackL1Gas,h as isOpStack};