diff --git a/backend/CHANGELOG.md b/backend/CHANGELOG.md index 779368e..444fdd9 100644 --- a/backend/CHANGELOG.md +++ b/backend/CHANGELOG.md @@ -1,4 +1,9 @@ # Changelog +## [2.0.1] - 2025-01-17 +### Fixes +- Signing of MTP happens after estimation +- Updated supportedNetworks to use from default if apiKey specific config is not found + ## [1.8.0] - 2024-12-25 ### Breaking changes - removed `/whitelist/v1`, `/removeWhitelist/v1`, `/checkWhitelist/v1` endpoints. diff --git a/backend/demo.env b/backend/demo.env index f78986c..0a066dc 100644 --- a/backend/demo.env +++ b/backend/demo.env @@ -1,6 +1,7 @@ NODE_ENV=development LOG_LEVEL=debug UNSAFE_MODE=false +MTP_VGL_MARKUP=30000 API_HOST=127.0.0.1 API_PORT=5050 diff --git a/backend/package.json b/backend/package.json index 07868e5..a3cef18 100644 --- a/backend/package.json +++ b/backend/package.json @@ -1,6 +1,6 @@ { "name": "arka", - "version": "2.0.0", + "version": "2.0.1", "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 3632461..d309942 100644 --- a/backend/src/paymaster/index.ts +++ b/backend/src/paymaster/index.ts @@ -42,17 +42,19 @@ import { abi as verifyingPaymasterV2Abi, byteCode as verifyingPaymasterV2ByteCod export class Paymaster { feeMarkUp: BigNumber; multiTokenMarkUp: number; + MTP_VGL_MARKUP: string; EP7_TOKEN_VGL: string; EP7_TOKEN_PGL: string; priceAndMetadata: Map = new Map(); nativeCurrencyPrice: Map = new Map(); - constructor(feeMarkUp: string, multiTokenMarkUp: string, ep7TokenVGL: string, ep7TokenPGL: string) { + constructor(feeMarkUp: string, multiTokenMarkUp: string, ep7TokenVGL: string, ep7TokenPGL: string, mtpVglMarkup: string) { this.feeMarkUp = ethers.utils.parseUnits(feeMarkUp, 'gwei'); if (isNaN(Number(multiTokenMarkUp))) this.multiTokenMarkUp = 1150000 // 15% more of the actual cost. Can be anything between 1e6 to 2e6 else this.multiTokenMarkUp = Number(multiTokenMarkUp); this.EP7_TOKEN_PGL = ep7TokenPGL; this.EP7_TOKEN_VGL = ep7TokenVGL; + this.MTP_VGL_MARKUP = mtpVglMarkup; } packUint(high128: BigNumberish, low128: BigNumberish): string { @@ -646,20 +648,23 @@ export class Paymaster { const ETHprice = await ecContract.cachedPrice(); ethPrice = ETHprice } - const paymasterAndData = await this.getPaymasterAndDataForMultiTokenPaymaster(userOp, validUntil, validAfter, feeToken, ethPrice, paymasterContract, signer, chainId); + let paymasterAndData = await this.getPaymasterAndDataForMultiTokenPaymaster(userOp, validUntil, validAfter, feeToken, ethPrice, paymasterContract, signer, chainId); if (!userOp.signature) userOp.signature = '0x'; const response = await provider.send('eth_estimateUserOperationGas', [userOp, entryPoint]); - userOp.verificationGasLimit = response.verificationGasLimit; + userOp.verificationGasLimit = BigNumber.from(response.verificationGasLimit).add(this.MTP_VGL_MARKUP).toHexString(); userOp.preVerificationGas = response.preVerificationGas; userOp.callGasLimit = response.callGasLimit; userOp.paymasterAndData = paymasterAndData + // After estimating it with proper paymasterAndData value + paymasterAndData = await this.getPaymasterAndDataForMultiTokenPaymaster(userOp, validUntil, validAfter, feeToken, ethPrice, paymasterContract, signer, chainId); + const returnValue = { paymasterAndData, - verificationGasLimit: response.verificationGasLimit, - preVerificationGas: response.preVerificationGas, - callGasLimit: response.callGasLimit, + verificationGasLimit: userOp.verificationGasLimit, + preVerificationGas: userOp.preVerificationGas, + callGasLimit: userOp.callGasLimit, } return returnValue; } catch (err: any) { diff --git a/backend/src/plugins/config.ts b/backend/src/plugins/config.ts index 196f053..856af10 100644 --- a/backend/src/plugins/config.ts +++ b/backend/src/plugins/config.ts @@ -35,6 +35,7 @@ const ConfigSchema = Type.Strict( DEFAULT_BUNDLER_API_KEY: Type.String(), MULTI_TOKEN_PAYMASTERS: Type.String(), MULTI_TOKEN_ORACLES: Type.String(), + MTP_VGL_MARKUP: Type.String() || '30000', }) ); @@ -73,7 +74,8 @@ const configPlugin: FastifyPluginAsync = async (server) => { USE_KMS: process.env.USE_KMS, DEFAULT_BUNDLER_API_KEY: process.env.DEFAULT_BUNDLER_API_KEY, MULTI_TOKEN_PAYMASTERS: process.env.MULTI_TOKEN_PAYMASTERS, - MULTI_TOKEN_ORACLES: process.env.MULTI_TOKEN_ORACLES + MULTI_TOKEN_ORACLES: process.env.MULTI_TOKEN_ORACLES, + MTP_VGL_MARKUP: process.env.MTP_VGL_MARKUP } const valid = validate(envVar); @@ -109,6 +111,7 @@ const configPlugin: FastifyPluginAsync = async (server) => { DEFAULT_BUNDLER_API_KEY: process.env.DEFAULT_BUNDLER_API_KEY ?? '', MULTI_TOKEN_PAYMASTERS: process.env.MULTI_TOKEN_PAYMASTERS ?? '', MULTI_TOKEN_ORACLES: process.env.MULTI_TOKEN_ORACLES ?? '', + MTP_VGL_MARKUP: process.env.MTP_VGL_MARKUP ?? '30000' } server.log.info(config, "config:"); diff --git a/backend/src/routes/admin-routes.ts b/backend/src/routes/admin-routes.ts index 8fe76d5..1877502 100644 --- a/backend/src/routes/admin-routes.ts +++ b/backend/src/routes/admin-routes.ts @@ -18,7 +18,7 @@ import { getNetworkConfig } from "../utils/common.js"; import { Paymaster } from "../paymaster/index.js"; const adminRoutes: FastifyPluginAsync = async (server) => { - const paymaster = new Paymaster(server.config.FEE_MARKUP, server.config.MULTI_TOKEN_MARKUP, server.config.EP7_TOKEN_VGL, server.config.EP7_TOKEN_PGL); + const paymaster = new Paymaster(server.config.FEE_MARKUP, server.config.MULTI_TOKEN_MARKUP, server.config.EP7_TOKEN_VGL, server.config.EP7_TOKEN_PGL, server.config.MTP_VGL_MARKUP); const prefixSecretId = 'arka_'; diff --git a/backend/src/routes/deposit-route.ts b/backend/src/routes/deposit-route.ts index f987ca5..db34d52 100644 --- a/backend/src/routes/deposit-route.ts +++ b/backend/src/routes/deposit-route.ts @@ -11,7 +11,7 @@ import { printRequest, getNetworkConfig } from "../utils/common.js"; import { APIKey } from "../models/api-key.js"; const depositRoutes: FastifyPluginAsync = async (server) => { - const paymaster = new Paymaster(server.config.FEE_MARKUP, server.config.MULTI_TOKEN_MARKUP, server.config.EP7_TOKEN_VGL, server.config.EP7_TOKEN_PGL); + const paymaster = new Paymaster(server.config.FEE_MARKUP, server.config.MULTI_TOKEN_MARKUP, server.config.EP7_TOKEN_VGL, server.config.EP7_TOKEN_PGL, server.config.MTP_VGL_MARKUP); const SUPPORTED_ENTRYPOINTS = { EPV_06: server.config.EPV_06, diff --git a/backend/src/routes/metadata-routes.ts b/backend/src/routes/metadata-routes.ts index 8071e23..33f1e3a 100644 --- a/backend/src/routes/metadata-routes.ts +++ b/backend/src/routes/metadata-routes.ts @@ -117,17 +117,9 @@ const metadataRoutes: FastifyPluginAsync = async (server) => { } const chainsSupported: { chainId: number, entryPoint: string }[] = []; - if (supportedNetworks) { - const buffer = Buffer.from(supportedNetworks, 'base64'); - const SUPPORTED_NETWORKS = JSON.parse(buffer.toString()) - SUPPORTED_NETWORKS.map((element: { chainId: number, entryPoint: string }) => { - chainsSupported.push({ chainId: element.chainId, entryPoint: element.entryPoint }); - }) - } else { - SupportedNetworks.map(element => { - chainsSupported.push({ chainId: element.chainId, entryPoint: element.entryPoint }); - }) - } + SupportedNetworks.map(element => { + chainsSupported.push({ chainId: element.chainId, entryPoint: element.entryPoint }); + }) const tokenPaymasterAddresses = { ...PAYMASTER_ADDRESS, ...customPaymasters, diff --git a/backend/src/routes/whitelist-routes.ts b/backend/src/routes/whitelist-routes.ts index 4181112..f85847f 100644 --- a/backend/src/routes/whitelist-routes.ts +++ b/backend/src/routes/whitelist-routes.ts @@ -12,7 +12,7 @@ import { APIKey } from "../models/api-key.js"; import { ContractWhitelistDto } from "../types/contractWhitelist-dto.js"; const whitelistRoutes: FastifyPluginAsync = async (server) => { - const paymaster = new Paymaster(server.config.FEE_MARKUP, server.config.MULTI_TOKEN_MARKUP, server.config.EP7_TOKEN_VGL, server.config.EP7_TOKEN_PGL); + const paymaster = new Paymaster(server.config.FEE_MARKUP, server.config.MULTI_TOKEN_MARKUP, server.config.EP7_TOKEN_VGL, server.config.EP7_TOKEN_PGL, server.config.MTP_VGL_MARKUP); const SUPPORTED_ENTRYPOINTS = { EPV_06: server.config.EPV_06, diff --git a/backend/src/server.ts b/backend/src/server.ts index 4a7f03e..674b187 100644 --- a/backend/src/server.ts +++ b/backend/src/server.ts @@ -56,7 +56,7 @@ const initializeServer = async (): Promise => { logLevel: "warn" }); - const paymaster = new Paymaster(server.config.FEE_MARKUP, server.config.MULTI_TOKEN_MARKUP, server.config.EP7_TOKEN_VGL, server.config.EP7_TOKEN_PGL); + const paymaster = new Paymaster(server.config.FEE_MARKUP, server.config.MULTI_TOKEN_MARKUP, server.config.EP7_TOKEN_VGL, server.config.EP7_TOKEN_PGL, server.config.MTP_VGL_MARKUP); await server.register(paymasterRoutes, {paymaster}); diff --git a/backend/src/utils/common.ts b/backend/src/utils/common.ts index 5e1aeeb..290ac62 100644 --- a/backend/src/utils/common.ts +++ b/backend/src/utils/common.ts @@ -13,7 +13,11 @@ export function getNetworkConfig(key: any, supportedNetworks: any, entryPoint: s if (supportedNetworks !== '') { const buffer = Buffer.from(supportedNetworks, 'base64'); const SUPPORTED_NETWORKS = JSON.parse(buffer.toString()) - return SUPPORTED_NETWORKS.find((chain: any) => { return chain["chainId"] == key && entryPoint.includes(chain["entryPoint"]) }); + const result = SUPPORTED_NETWORKS.find((chain: any) => { return chain["chainId"] == key && entryPoint.includes(chain["entryPoint"]) }); + if (!result) { + return SupportedNetworks.find((chain) => chain.chainId == key && entryPoint.includes(chain.entryPoint)); + } + return result } else return SupportedNetworks.find((chain) => chain.chainId == key && entryPoint.includes(chain.entryPoint)); }