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

PRO-2967 - Emergency Fix for MTP #163

Closed
wants to merge 1 commit into from
Closed
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
5 changes: 5 additions & 0 deletions backend/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -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.
Expand Down
1 change: 1 addition & 0 deletions backend/demo.env
Original file line number Diff line number Diff line change
@@ -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
Expand Down
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": "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": {
Expand Down
17 changes: 11 additions & 6 deletions backend/src/paymaster/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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<string, TokenPriceAndMetadataCache> = new Map();
nativeCurrencyPrice: Map<string, NativeCurrencyPricyCache> = 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 {
Expand Down Expand Up @@ -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) {
Expand Down
5 changes: 4 additions & 1 deletion backend/src/plugins/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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',
})
);

Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -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:");
Expand Down
2 changes: 1 addition & 1 deletion backend/src/routes/admin-routes.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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_';

Expand Down
2 changes: 1 addition & 1 deletion backend/src/routes/deposit-route.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
14 changes: 3 additions & 11 deletions backend/src/routes/metadata-routes.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
2 changes: 1 addition & 1 deletion backend/src/routes/whitelist-routes.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
2 changes: 1 addition & 1 deletion backend/src/server.ts
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ const initializeServer = async (): Promise<void> => {
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});

Expand Down
6 changes: 5 additions & 1 deletion backend/src/utils/common.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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));
}
Expand Down
Loading