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

Hot Fix #128

Merged
merged 1 commit into from
Aug 22, 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.4.3",
"version": "1.4.4",
"description": "ARKA - (Albanian for Cashier's case) is the first open source Paymaster as a service software",
"type": "module",
"directories": {
Expand Down
10 changes: 6 additions & 4 deletions backend/src/routes/deposit-route.ts
Original file line number Diff line number Diff line change
Expand Up @@ -90,8 +90,9 @@ const depositRoutes: FastifyPluginAsync = async (server) => {
}
const networkConfig = getNetworkConfig(chainId, supportedNetworks ?? '', SUPPORTED_ENTRYPOINTS.EPV_06);
if (!networkConfig) return reply.code(ReturnCode.FAILURE).send({ error: ErrorMessage.UNSUPPORTED_NETWORK });
if (networkConfig.bundler.includes('etherspot.io')) networkConfig.bundler = `${networkConfig.bundler}?api-key=${bundlerApiKey}`;
return await paymaster.deposit(amount, networkConfig.contracts.etherspotPaymasterAddress, networkConfig.bundler, privateKey, chainId, true, server.log);
let bundlerUrl = networkConfig.bundler;
if (networkConfig.bundler.includes('etherspot.io')) bundlerUrl = `${networkConfig.bundler}?api-key=${bundlerApiKey}`;
return await paymaster.deposit(amount, networkConfig.contracts.etherspotPaymasterAddress, bundlerUrl, privateKey, chainId, true, server.log);
} catch (err: any) {
request.log.error(err);
if (err.name == "ResourceNotFoundException")
Expand Down Expand Up @@ -150,8 +151,9 @@ const depositRoutes: FastifyPluginAsync = async (server) => {
}
const networkConfig = getNetworkConfig(chainId, supportedNetworks ?? '', SUPPORTED_ENTRYPOINTS.EPV_07);
if (!networkConfig) return reply.code(ReturnCode.FAILURE).send({ error: ErrorMessage.UNSUPPORTED_NETWORK });
if (networkConfig.bundler.includes('etherspot.io')) networkConfig.bundler = `${networkConfig.bundler}?api-key=${bundlerApiKey}`;
return await paymaster.deposit(amount, networkConfig.contracts.etherspotPaymasterAddress, networkConfig.bundler, privateKey, chainId, false, server.log);
let bundlerUrl = networkConfig.bundler;
if (networkConfig.bundler.includes('etherspot.io')) bundlerUrl = `${networkConfig.bundler}?api-key=${bundlerApiKey}`;
return await paymaster.deposit(amount, networkConfig.contracts.etherspotPaymasterAddress, bundlerUrl, privateKey, chainId, false, server.log);
} catch (err: any) {
request.log.error(err);
if (err.name == "ResourceNotFoundException")
Expand Down
17 changes: 9 additions & 8 deletions backend/src/routes/paymaster-routes.ts
Original file line number Diff line number Diff line change
Expand Up @@ -201,14 +201,15 @@ const paymasterRoutes: FastifyPluginAsync = async (server) => {

const networkConfig = getNetworkConfig(chainId, supportedNetworks ?? '', entryPoint);
if (!networkConfig) return reply.code(ReturnCode.FAILURE).send({ error: ErrorMessage.UNSUPPORTED_NETWORK });
if (networkConfig.bundler.includes('etherspot.io')) networkConfig.bundler = `${networkConfig.bundler}?api-key=${bundlerApiKey}`;
let bundlerUrl = networkConfig.bundler;
if (networkConfig.bundler.includes('etherspot.io')) bundlerUrl = `${networkConfig.bundler}?api-key=${bundlerApiKey}`;
server.log.warn(networkConfig, `Network Config fetched for ${api_key}: `);

let result: any;
switch (mode.toLowerCase()) {
case 'sponsor': {
const date = new Date();
const provider = new providers.JsonRpcProvider(networkConfig.bundler);
const provider = new providers.JsonRpcProvider(bundlerUrl);
const signer = new Wallet(privateKey, provider)

// get chainid from provider
Expand Down Expand Up @@ -258,14 +259,14 @@ const paymasterRoutes: FastifyPluginAsync = async (server) => {
if (!contractWhitelistResult) throw new Error('Contract Method not whitelisted');
}
if (entryPoint == SUPPORTED_ENTRYPOINTS.EPV_06)
result = await paymaster.signV06(userOp, str, str1, entryPoint, networkConfig.contracts.etherspotPaymasterAddress, networkConfig.bundler, signer, estimate, server.log);
result = await paymaster.signV06(userOp, str, str1, entryPoint, networkConfig.contracts.etherspotPaymasterAddress, bundlerUrl, signer, estimate, server.log);
else {
const globalWhitelistRecord = await server.whitelistRepository.findOneByApiKeyAndPolicyId(api_key);
if (!globalWhitelistRecord?.addresses.includes(userOp.sender)) {
const existingWhitelistRecord = await server.whitelistRepository.findOneByApiKeyAndPolicyId(api_key, sponsorshipPolicy.id);
if (!existingWhitelistRecord?.addresses.includes(userOp.sender)) throw new Error('This sender address has not been whitelisted yet');
}
result = await paymaster.signV07(userOp, str, str1, entryPoint, networkConfig.contracts.etherspotPaymasterAddress, networkConfig.bundler, signer, estimate, server.log);
result = await paymaster.signV07(userOp, str, str1, entryPoint, networkConfig.contracts.etherspotPaymasterAddress, bundlerUrl, signer, estimate, server.log);
}
break;
}
Expand All @@ -278,13 +279,13 @@ const paymasterRoutes: FastifyPluginAsync = async (server) => {
let paymasterAddress: string;
if (customPaymasters[chainId] && customPaymasters[chainId][gasToken]) paymasterAddress = customPaymasters[chainId][gasToken];
else paymasterAddress = PAYMASTER_ADDRESS[chainId][gasToken]
result = await paymaster.pimlico(userOp, networkConfig.bundler, entryPoint, paymasterAddress, server.log);
result = await paymaster.pimlico(userOp, bundlerUrl, entryPoint, paymasterAddress, server.log);
} else if (entryPoint === SUPPORTED_ENTRYPOINTS.EPV_07) {
if (
!(customPaymastersV2[chainId] && customPaymastersV2[chainId][gasToken])
) return reply.code(ReturnCode.FAILURE).send({ error: ErrorMessage.UNSUPPORTED_NETWORK_TOKEN })
const paymasterAddress = customPaymastersV2[chainId][gasToken];
result = await paymaster.ERC20PaymasterV07(userOp, networkConfig.bundler, entryPoint, paymasterAddress, estimate, server.log);
result = await paymaster.ERC20PaymasterV07(userOp, bundlerUrl, entryPoint, paymasterAddress, estimate, server.log);
} else {
throw new Error(`Currently only ${SUPPORTED_ENTRYPOINTS.EPV_06} & ${SUPPORTED_ENTRYPOINTS.EPV_07} entryPoint addresses are supported`)
}
Expand All @@ -294,7 +295,7 @@ const paymasterRoutes: FastifyPluginAsync = async (server) => {
if (entryPoint !== SUPPORTED_ENTRYPOINTS.EPV_06)
throw new Error('Currently only 0x5FF137D4b0FDCD49DcA30c7CF57E578a026d2789 entryPoint address is supported')
const date = new Date();
const provider = new providers.JsonRpcProvider(networkConfig.bundler);
const provider = new providers.JsonRpcProvider(bundlerUrl);
const signer = new Wallet(privateKey, provider)
const validUntil = context.validUntil ? new Date(context.validUntil) : date;
const validAfter = context.validAfter ? new Date(context.validAfter) : date;
Expand All @@ -313,7 +314,7 @@ const paymasterRoutes: FastifyPluginAsync = async (server) => {
if (!networkConfig.MultiTokenPaymasterOracleUsed ||
!(networkConfig.MultiTokenPaymasterOracleUsed == "orochi" || networkConfig.MultiTokenPaymasterOracleUsed == "chainlink"))
throw new Error("Oracle is not Defined/Invalid");
result = await paymaster.signMultiTokenPaymaster(userOp, str, str1, entryPoint, multiTokenPaymasters[chainId][gasToken], gasToken, multiTokenOracles[chainId][gasToken], networkConfig.bundler, signer, networkConfig.MultiTokenPaymasterOracleUsed, server.log);
result = await paymaster.signMultiTokenPaymaster(userOp, str, str1, entryPoint, multiTokenPaymasters[chainId][gasToken], gasToken, multiTokenOracles[chainId][gasToken], bundlerUrl, signer, networkConfig.MultiTokenPaymasterOracleUsed, server.log);
break;
}
default: {
Expand Down
8 changes: 0 additions & 8 deletions backend/src/routes/pimlico-routes.ts
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,6 @@ const pimlicoRoutes: FastifyPluginAsync = async (server) => {
let customPaymasters = [];
let privateKey = '';
let supportedNetworks;
let bundlerApiKey = api_key;
if (!unsafeMode) {
const AWSresponse = await client.send(
new GetSecretValueCommand({
Expand All @@ -65,9 +64,6 @@ const pimlicoRoutes: FastifyPluginAsync = async (server) => {
const buffer = Buffer.from(secrets['ERC20_PAYMASTERS'], 'base64');
customPaymasters = JSON.parse(buffer.toString());
}
if (secrets['BUNDLER_API_KEY']) {
bundlerApiKey = secrets['BUNDLER_API_KEY'];
}
privateKey = secrets['PRIVATE_KEY'];
supportedNetworks = secrets['SUPPORTED_NETWORKS'];
} else {
Expand All @@ -82,9 +78,6 @@ const pimlicoRoutes: FastifyPluginAsync = async (server) => {
privateKey = decode(apiKeyEntity.privateKey, server.config.HMAC_SECRET);

supportedNetworks = apiKeyEntity.supportedNetworks;
if (apiKeyEntity.bundlerApiKey) {
bundlerApiKey = apiKeyEntity.bundlerApiKey;
}
}
if (!privateKey) return reply.code(ReturnCode.FAILURE).send({ error: ErrorMessage.INVALID_API_KEY })
if (
Expand All @@ -100,7 +93,6 @@ const pimlicoRoutes: FastifyPluginAsync = async (server) => {
}
const networkConfig = getNetworkConfig(chainId, supportedNetworks ?? '', entryPoint);
if (!networkConfig) return reply.code(ReturnCode.FAILURE).send({ error: ErrorMessage.UNSUPPORTED_NETWORK });
if (networkConfig.bundler.includes('etherspot.io')) networkConfig.bundler = `${networkConfig.bundler}?api-key=${bundlerApiKey}`;
let result;
if (customPaymasters[chainId] && customPaymasters[chainId][gasToken]) result = { message: customPaymasters[chainId][gasToken] }
else {
Expand Down
Loading
Loading