UNPKG

@etherspot/remote-signer

Version:

Etherspot Permissioned Signer SDK - signs the UserOp with SessionKey and sends it to the Bundler

1 lines 2.17 kB
{"version":3,"sources":["../../src/sdk/common/getGasFee.ts"],"sourcesContent":["import { BigNumber, BigNumberish } from '../types/bignumber';\nimport { bufferPercent } from './constants';\nimport { PublicClient } from 'viem';\n\nexport interface Gas {\n maxFeePerGas: BigNumberish;\n maxPriorityFeePerGas: BigNumberish;\n}\n\nexport async function getGasFee(publicClient: PublicClient): Promise<Gas> {\n try {\n //const [fee, block] = await provider.send('eth_maxPriorityFeePerGas', []);\n\n const gasFeeResponse : any = await publicClient.request(\n {\n method: 'eth_maxPriorityFeePerGas',\n params: [],\n }\n );\n\n if(!gasFeeResponse) {\n throw new Error('failed to get priorityFeePerGas');\n }\n\n const [fee, block] = gasFeeResponse;\n\n if (BigNumber.from(0).eq(fee)) {\n throw new Error('failed to get priorityFeePerGas');\n }\n const tip = BigNumber.from(fee);\n const buffer = tip.div(100).mul(bufferPercent);\n const maxPriorityFeePerGas = tip.add(buffer);\n const maxFeePerGas =\n block.baseFeePerGas != null ? block.baseFeePerGas.mul(2).add(maxPriorityFeePerGas) : maxPriorityFeePerGas;\n\n return { maxFeePerGas, maxPriorityFeePerGas };\n } catch (err) {\n console.warn(\n \"getGas: eth_maxPriorityFeePerGas failed, falling back to legacy gas price.\"\n );\n const gas = await publicClient.getGasPrice();\n return { maxFeePerGas: gas, maxPriorityFeePerGas: gas };\n }\n}\n"],"mappings":";;;;;;;;AASA,eAAsB,UAAU,cAA0C;AACxE,MAAI;AAGF,UAAM,iBAAuB,MAAM,aAAa;AAAA,MAC9C;AAAA,QACE,QAAQ;AAAA,QACR,QAAQ,CAAC;AAAA,MACX;AAAA,IACF;AAEA,QAAG,CAAC,gBAAgB;AAClB,YAAM,IAAI,MAAM,iCAAiC;AAAA,IACnD;AAEA,UAAM,CAAC,KAAK,KAAK,IAAI;AAErB,QAAI,UAAU,KAAK,CAAC,EAAE,GAAG,GAAG,GAAG;AAC7B,YAAM,IAAI,MAAM,iCAAiC;AAAA,IACnD;AACA,UAAM,MAAM,UAAU,KAAK,GAAG;AAC9B,UAAM,SAAS,IAAI,IAAI,GAAG,EAAE,IAAI,aAAa;AAC7C,UAAM,uBAAuB,IAAI,IAAI,MAAM;AAC3C,UAAM,eACJ,MAAM,iBAAiB,OAAO,MAAM,cAAc,IAAI,CAAC,EAAE,IAAI,oBAAoB,IAAI;AAEvF,WAAO,EAAE,cAAc,qBAAqB;AAAA,EAC9C,SAAS,KAAK;AACZ,YAAQ;AAAA,MACN;AAAA,IACF;AACA,UAAM,MAAM,MAAM,aAAa,YAAY;AAC3C,WAAO,EAAE,cAAc,KAAK,sBAAsB,IAAI;AAAA,EACxD;AACF;","names":[]}