Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix/arb token #158

Merged
merged 3 commits into from
Dec 20, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion backend/package.json
Original file line number Diff line number Diff line change
@@ -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": {
Expand Down
16 changes: 15 additions & 1 deletion backend/src/constants/MultitokenPaymaster.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,17 @@
import { BigNumber } from "ethers";

export const UnaccountedCost = BigNumber.from("45000").toHexString();
export const UnaccountedCost = BigNumber.from("45000").toHexString();

interface TokenInfo {
decimals: number;
symbol: string;
}

export const TokenDecimalsAndSymbol: Record<number, Record<string, TokenInfo>> = {
42161: {
"0xEeeeeEeeeEeEeeEeEeEeeEEEeeeeEeeeeeeeEEeE": {
decimals: 18,
symbol: "ETH"
}
}
}
33 changes: 23 additions & 10 deletions backend/src/paymaster/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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");
Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -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'))
];

Expand Down Expand Up @@ -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()
];
Expand Down Expand Up @@ -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()
];

Expand Down
2 changes: 1 addition & 1 deletion backend/src/server.ts
Original file line number Diff line number Diff line change
Expand Up @@ -341,7 +341,7 @@ const initializeServer = async (): Promise<void> => {
},
{
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());
Expand Down
Loading