diff --git a/backend/CHANGELOG.md b/backend/CHANGELOG.md index 5738a4b..0167e1d 100644 --- a/backend/CHANGELOG.md +++ b/backend/CHANGELOG.md @@ -1,4 +1,8 @@ # Changelog +## [3.1.6] - 2025-04-02 +### Fixes +- Fixed bug in paymaster estimation for multiTokenPaymaster getERC20Quotes API + ## [3.1.5] - 2025-03-24 ### Fixes - Added all tokens used in multiTokenPaymaster to have decimals in constants rather than fetching from rpc diff --git a/backend/package.json b/backend/package.json index d10d2ac..e79a92e 100644 --- a/backend/package.json +++ b/backend/package.json @@ -1,6 +1,6 @@ { "name": "arka", - "version": "3.1.5", + "version": "3.1.6", "description": "ARKA - (Albanian for Cashier's case) is the first open source Paymaster as a service software", "type": "module", "directories": { diff --git a/backend/src/paymaster/index.ts b/backend/src/paymaster/index.ts index 3c303b4..3fba6fa 100644 --- a/backend/src/paymaster/index.ts +++ b/backend/src/paymaster/index.ts @@ -550,6 +550,7 @@ export class Paymaster { bundlerRpc: string, oracleName: string, nativeOracleAddress: string, + signer: Wallet, log?: FastifyBaseLogger ) { try { @@ -574,6 +575,23 @@ export class Paymaster { let ETHUSDPrice: any, ETHUSDPriceDecimal; const paymasterKey = Object.keys(multiTokenPaymasters[chainId])[0]; let response, unaccountedCost; + const validUntil = new Date(); + const validAfter = new Date(); + const hex = (Number((validUntil.valueOf() / 1000).toFixed(0)) + 600).toString(16); + const hex1 = (Number((validAfter.valueOf() / 1000).toFixed(0)) - 60).toString(16); + let str = '0x' + let str1 = '0x' + for (let i = 0; i < 14 - hex.length; i++) { + str += '0'; + } + for (let i = 0; i < 14 - hex1.length; i++) { + str1 += '0'; + } + str += hex; + str1 += hex1; + const paymasterContract = new ethers.Contract(multiTokenPaymasters[chainId][paymasterKey], MultiTokenPaymasterAbi, provider); + // Assuming the token price is 1 USD since this is just used for the gas estimation and the paymasterAndData generated will not be sent on response + userOp.paymasterAndData = await this.getPaymasterAndDataForMultiTokenPaymaster(userOp, str, str1, paymasterKey, '100000000', paymasterContract, signer, chainId); if (oracleName === "chainlink") { const res = await this.getEstimateUserOperationGasAndData( provider, diff --git a/backend/src/routes/paymaster-routes.ts b/backend/src/routes/paymaster-routes.ts index 2a8fa2b..9166b09 100644 --- a/backend/src/routes/paymaster-routes.ts +++ b/backend/src/routes/paymaster-routes.ts @@ -189,7 +189,9 @@ const paymasterRoutes: FastifyPluginAsync = async (server, if (!multiTokenPaymasters[chainId]) return reply.code(ReturnCode.FAILURE).send({ error: ErrorMessage.MULTI_NOT_DEPLOYED + chainId }) if (networkConfig.MultiTokenPaymasterOracleUsed == "chainlink" && !NativeOracles[chainId]) throw new Error("Native Oracle address not set for this chainId") - result = await paymaster.getQuotesMultiToken(userOp, entryPoint, chainId, multiTokenPaymasters, tokens_list, multiTokenOracles, bundlerUrl, networkConfig.MultiTokenPaymasterOracleUsed, NativeOracles[chainId], server.log); + const provider = new providers.JsonRpcProvider(bundlerUrl); + const signer = new Wallet(privateKey, provider) + result = await paymaster.getQuotesMultiToken(userOp, entryPoint, chainId, multiTokenPaymasters, tokens_list, multiTokenOracles, bundlerUrl, networkConfig.MultiTokenPaymasterOracleUsed, NativeOracles[chainId], signer, server.log); } else { if (gasToken && ethers.utils.isAddress(gasToken)) gasToken = ethers.utils.getAddress(gasToken)