@privy-io/js-sdk-core
Version:
Vanilla JS client for the Privy Auth API
2 lines (1 loc) • 1.52 kB
JavaScript
var e=require("@ethersproject/units"),t=require("fetch-retry"),r=require("@privy-io/chains");function a(e){return e&&"object"==typeof e&&"default"in e?e:{default:e}}let o=/*#__PURE__*/a(t).default(fetch,{retries:3,retryDelay:500});const i=e=>[r.polygon.id,r.polygonAmoy.id].includes(e);let s=t=>({maxPriorityFee:e.parseUnits(t.maxPriorityFee.toFixed(9),"gwei").toHexString(),maxFee:e.parseUnits(t.maxFee.toFixed(9),"gwei").toHexString()}),n=e=>({safeLow:s(e.safeLow),standard:s(e.standard),fast:s(e.fast)});const y=async e=>{let t="";switch(e){case r.polygon.id:t="https://gasstation.polygon.technology/v2";break;case r.polygonAmoy.id:t="https://gasstation.polygon.technology/amoy";break;default:throw Error(`chainId ${e} does not support polygon gas stations`)}let a=await o(t),i=await a.json();if(a.status>399)throw i;return n(i)};exports.defaultGasForPolygon=async function(e){if(!i(e.chainId))throw Error("Invalid chain ID for Polygon gas estimation.");if(void 0===e.type&&(e.type=2),e.maxPriorityFeePerGas&&e.maxFeePerGas)return e;try{let{standard:t}=await y(e.chainId);e.maxPriorityFeePerGas||(e.maxPriorityFeePerGas=t.maxPriorityFee),e.maxFeePerGas||(e.maxFeePerGas=t.maxFee),e.gasPrice&&(console.warn("`gasPrice` is not supported on this chain and will be ignored. Use `maxPriorityFeePerGas` and/or `maxFeePerGas` instead."),delete e.gasPrice)}catch(e){throw Error(`Failed to set gas prices from Polygon gas station with error: ${e}.`)}return e},exports.getPolygonGasStationFees=y,exports.isPolygon=i;
;