diff --git a/backend/package.json b/backend/package.json index c132096..ec3b1f1 100644 --- a/backend/package.json +++ b/backend/package.json @@ -1,6 +1,6 @@ { "name": "arka", - "version": "1.7.3", + "version": "1.7.4", "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/constants/MultitokenPaymaster.ts b/backend/src/constants/MultitokenPaymaster.ts index aa57e79..2d3a25c 100644 --- a/backend/src/constants/MultitokenPaymaster.ts +++ b/backend/src/constants/MultitokenPaymaster.ts @@ -1,3 +1,17 @@ import { BigNumber } from "ethers"; -export const UnaccountedCost = BigNumber.from("45000").toHexString(); \ No newline at end of file +export const UnaccountedCost = BigNumber.from("45000").toHexString(); + +interface TokenInfo { + decimals: number; + symbol: string; +} + +export const TokenDecimalsAndSymbol: Record> = { + 42161: { + "0xEeeeeEeeeEeEeeEeEeEeeEEEeeeeEeeeeeeeEEeE": { + decimals: 18, + symbol: "ETH" + } + } +} \ No newline at end of file diff --git a/backend/src/paymaster/index.ts b/backend/src/paymaster/index.ts index 58be5b6..d5a7892 100644 --- a/backend/src/paymaster/index.ts +++ b/backend/src/paymaster/index.ts @@ -14,7 +14,7 @@ import ChainlinkOracleAbi from '../abi/ChainlinkOracleAbi.js'; import ERC20PaymasterV07Abi from '../abi/ERC20PaymasterV07Abi.js'; import ERC20Abi from '../abi/ERC20Abi.js'; import EtherspotChainlinkOracleAbi from '../abi/EtherspotChainlinkOracleAbi.js'; -import { UnaccountedCost } from '../constants/MultitokenPaymaster.js'; +import { TokenDecimalsAndSymbol, UnaccountedCost } from '../constants/MultitokenPaymaster.js'; import { NativeOracleDecimals } from '../constants/ChainlinkOracles.js'; const ttl = parseInt(process.env.CACHE_TTL || "600000"); const nativePriceCacheTtl = parseInt(process.env.NATIVE_PRICE_CACHE_TTL || "60000"); @@ -265,6 +265,22 @@ export class Paymaster { return paymasterAndData; } + private async getTokenDecimals(token: string, chainId: number, provider: providers.JsonRpcProvider) { + if(TokenDecimalsAndSymbol[chainId]?.[token]) { + return TokenDecimalsAndSymbol[chainId][token]?.decimals; + } + const tokenContract = new ethers.Contract(token, ERC20Abi, provider); + return tokenContract.decimals(); + } + + private async getTokenSymbol(token: string, chainId: number, provider: providers.JsonRpcProvider) { + if(TokenDecimalsAndSymbol[chainId]?.[token]) { + return TokenDecimalsAndSymbol[chainId][token]?.symbol; + } + const tokenContract = new Contract(token, ERC20Abi, provider); + return tokenContract.symbol(); + } + private async getEstimateUserOperationGas( provider: providers.JsonRpcProvider, userOp: any, @@ -352,10 +368,9 @@ export class Paymaster { } const oracleContract = new ethers.Contract(oracleAddress, OrochiOracleAbi, provider); - const tokenContract = new ethers.Contract(gasToken, ERC20Abi, provider); const promises = [ - tokenContract.decimals(), - tokenContract.symbol(), + this.getTokenDecimals(gasToken, chainId, provider), + this.getTokenSymbol(gasToken, chainId, provider), oracleContract.getLatestData(1, ethers.utils.hexlify(ethers.utils.toUtf8Bytes('ETH')).padEnd(42, '0')) ]; @@ -404,11 +419,10 @@ export class Paymaster { } const chainlinkContract = new ethers.Contract(oracleAddress, ChainlinkOracleAbi, provider); - const tokenContract = new ethers.Contract(gasToken, ERC20Abi, provider); const promises = [ - tokenContract.decimals(), - tokenContract.symbol(), + this.getTokenDecimals(gasToken, chainId, provider), + this.getTokenSymbol(gasToken, chainId, provider), chainlinkContract.decimals(), chainlinkContract.latestAnswer() ]; @@ -461,11 +475,10 @@ export class Paymaster { return cache.data; } const ecContract = new ethers.Contract(oracleAddress, EtherspotChainlinkOracleAbi, provider); - const tokenContract = new ethers.Contract(gasToken, ERC20Abi, provider); const promises = [ - tokenContract.decimals(), - tokenContract.symbol(), + this.getTokenDecimals(gasToken, chainId, provider), + this.getTokenSymbol(gasToken, chainId, provider), ecContract.cachedPrice() ]; diff --git a/backend/src/server.ts b/backend/src/server.ts index 4134899..4a7f03e 100644 --- a/backend/src/server.ts +++ b/backend/src/server.ts @@ -341,7 +341,7 @@ const initializeServer = async (): Promise => { }, { name: 'updateTokenOracleData', - cronTime: process.env.TOKEN_ORACLE_UPDATE_CRON_EXP || '*/5 * * * *', // every 5 mins. + cronTime: process.env.TOKEN_ORACLE_UPDATE_CRON_EXP || '*/7 * * * *', // every 7 mins. onTick: async () => { let buffer = Buffer.from(server.config.MULTI_TOKEN_PAYMASTERS, 'base64'); const multiTokenPaymasters = JSON.parse(buffer.toString());