@privy-io/js-sdk-core
Version:
Vanilla JS client for the Privy Auth API
2 lines (1 loc) • 2.1 kB
JavaScript
var e=require("@ethersproject/bignumber"),r=require("@ethersproject/contracts"),a=require("@ethersproject/transactions"),t=require("@privy-io/chains"),i=require("../utils/ethers.js");const s=["function getL1Fee(bytes memory _data) external view returns (uint256)"],o=e=>[t.base.id,t.baseSepolia.id,t.optimism.id,t.optimismSepolia.id,t.zora.id,t.zoraTestnet.id,t.zoraSepolia.id,81457,168587773].includes(e);exports.OPTIMISM_STACK_GAS_PRICE_ORACLE_ABI=s,exports.OPTIMISM_STACK_GAS_PRICE_ORACLE_ADDRESS="0x420000000000000000000000000000000000000F",exports.defaultGasForOpStack=async(r,a)=>{if(!o(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 s=e.BigNumber.from(t).mul(e.BigNumber.from(126)).div(e.BigNumber.from(100)).add(e.BigNumber.from(r.maxPriorityFeePerGas));r.maxFeePerGas=i.convertBigNumberish(s)}}catch(e){throw Error(`Failed to set gas price for OP stack transaction: ${e}.`)}return r},exports.estimateOpStackL1Gas=async function(t,n){if(!t.chainId||t.chainId&&!o(t.chainId))return e.BigNumber.from(0);let c=e.BigNumber.from(0);try{let e=new r.Contract("0x420000000000000000000000000000000000000F",s,n),o=i.toEthersUnsignedTransaction(t),m=a.serialize(o);c=await e.getL1Fee(m)}catch(e){}return c},exports.isOpStack=o;
;