Skip to content

Commit

Permalink
Change NetworkConfig (#127)
Browse files Browse the repository at this point in the history
  • Loading branch information
vignesha22 authored Aug 22, 2024
1 parent 6285eef commit fc3e800
Show file tree
Hide file tree
Showing 16 changed files with 150 additions and 39 deletions.
4 changes: 2 additions & 2 deletions admin_frontend/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion admin_frontend/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "admin_frontend",
"version": "1.4.0",
"version": "1.4.3",
"private": true,
"dependencies": {
"@emotion/react": "11.11.3",
Expand Down
50 changes: 25 additions & 25 deletions backend/config.json.default
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
[
{
"chainId": 1,
"bundler": "https://ethereum-bundler.etherspot.io/",
"bundler": "https://rpc.etherspot.io/ethereum",
"contracts": {
"etherspotPaymasterAddress": "0x7F690e93CecFca5A31E6e1dF50A33F6d3059048c"
},
Expand All @@ -11,7 +11,7 @@
},
{
"chainId": 10,
"bundler": "https://optimism-bundler.etherspot.io",
"bundler": "https://rpc.etherspot.io/optimism",
"contracts": {
"etherspotPaymasterAddress": "0x805650ce74561C85baA44a8Bd13E19633Fd0F79d"
},
Expand All @@ -21,7 +21,7 @@
},
{
"chainId": 14,
"bundler": "https://flare-bundler.etherspot.io",
"bundler": "https://rpc.etherspot.io/flare",
"contracts": {
"etherspotPaymasterAddress": "0x8A41594e5c6Fe492e437414c24eA6f401186b8d2"
},
Expand All @@ -31,7 +31,7 @@
},
{
"chainId": 30,
"bundler": "https://rootstock-bundler.etherspot.io",
"bundler": "https://rpc.etherspot.io/rootstock",
"contracts": {
"etherspotPaymasterAddress": "0xe893A26dD53b325bFFaACdFA224692EFF4C448C4"
},
Expand Down Expand Up @@ -59,6 +59,16 @@
"MultiTokenPaymasterOracleUsed": "chainlink",
"entryPoint": "0x0000000071727De22E5E9d8BAf0edAc6f37da032"
},
{
"chainId": 50,
"bundler": "https://rpc.etherspot.io/v2/50",
"contracts": {
"etherspotPaymasterAddress": "0xABA00E929d66119A4A7F4B2E27150fC387ee801c"
},
"thresholdValue": "0.01",
"MultiTokenPaymasterOracleUsed": "chainlink",
"entryPoint": "0x0000000071727De22E5E9d8BAf0edAc6f37da032"
},
{
"chainId": 51,
"bundler": "https://testnet-rpc.etherspot.io/v2/51",
Expand All @@ -71,7 +81,7 @@
},
{
"chainId": 56,
"bundler": "https://bnb-bundler.etherspot.io/",
"bundler": "https://rpc.etherspot.io/bnb",
"contracts": {
"etherspotPaymasterAddress": "0xEA5ecE95D3A28f9faB161779d20128b449F9EC9C"
},
Expand Down Expand Up @@ -101,7 +111,7 @@
},
{
"chainId": 100,
"bundler": "https://gnosis-bundler.etherspot.io/",
"bundler": "https://rpc.etherspot.io/gnosis",
"contracts": {
"etherspotPaymasterAddress": "0x373aBcF1EA9e5802778E32870e7f72C8A6a90349"
},
Expand Down Expand Up @@ -131,7 +141,7 @@
},
{
"chainId": 122,
"bundler": "https://fuse-bundler.etherspot.io",
"bundler": "https://rpc.etherspot.io/fuse",
"contracts": {
"etherspotPaymasterAddress": "0xEC2EE24E79C73DB13Dd9bC782856a5296626b7eb"
},
Expand Down Expand Up @@ -161,7 +171,7 @@
},
{
"chainId": 137,
"bundler": "https://polygon-bundler.etherspot.io",
"bundler": "https://rpc.etherspot.io/polygon",
"contracts": {
"etherspotPaymasterAddress": "0x26FeC24b0D467C9de105217B483931e8f944ff50"
},
Expand All @@ -181,7 +191,7 @@
},
{
"chainId": 5000,
"bundler": "https://mantle-bundler.etherspot.io/",
"bundler": "https://rpc.etherspot.io/mantle",
"contracts": {
"etherspotPaymasterAddress": "0x8A41594e5c6Fe492e437414c24eA6f401186b8d2"
},
Expand Down Expand Up @@ -209,19 +219,9 @@
"MultiTokenPaymasterOracleUsed": "chainlink",
"entryPoint": "0x0000000071727De22E5E9d8BAf0edAc6f37da032"
},
{
"chainId": 8217,
"bundler": "https://klaytn-bundler.etherspot.io/",
"contracts": {
"etherspotPaymasterAddress": "0x4ebd86AAF89151b5303DB072e0205C668e31E5E7"
},
"thresholdValue": "275.2",
"MultiTokenPaymasterOracleUsed": "chainlink",
"entryPoint": "0x5FF137D4b0FDCD49DcA30c7CF57E578a026d2789"
},
{
"chainId": 8453,
"bundler": "https://base-bundler.etherspot.io/",
"bundler": "https://rpc.etherspot.io/base",
"contracts": {
"etherspotPaymasterAddress": "0x810FA4C915015b703db0878CF2B9344bEB254a40"
},
Expand All @@ -241,7 +241,7 @@
},
{
"chainId": 42161,
"bundler": "https://arbitrum-bundler.etherspot.io",
"bundler": "https://rpc.etherspot.io/arbitrum",
"contracts": {
"etherspotPaymasterAddress": "0xEC2EE24E79C73DB13Dd9bC782856a5296626b7eb"
},
Expand All @@ -261,7 +261,7 @@
},
{
"chainId": 43114,
"bundler": "https://avalanche-bundler.etherspot.io/",
"bundler": "https://rpc.etherspot.io/avalanche",
"contracts": {
"etherspotPaymasterAddress": "0x527569794781671319f20374A050BDbef4181aB3"
},
Expand All @@ -271,7 +271,7 @@
},
{
"chainId": 59144,
"bundler": "https://linea-bundler.etherspot.io/",
"bundler": "https://rpc.etherspot.io/linea",
"contracts": {
"etherspotPaymasterAddress": "0xB3AD9B9B06c6016f81404ee8FcCD0526F018Cf0C"
},
Expand Down Expand Up @@ -361,7 +361,7 @@
},
{
"chainId": 534352,
"bundler": "https://scroll-bundler.etherspot.io",
"bundler": "https://rpc.etherspot.io/scroll",
"contracts": {
"etherspotPaymasterAddress": "0xB3AD9B9B06c6016f81404ee8FcCD0526F018Cf0C"
},
Expand Down Expand Up @@ -431,7 +431,7 @@
},
{
"chainId": 888888888,
"bundler": "https://ancient8-bundler.etherspot.io",
"bundler": "https://rpc.etherspot.io/ancient8",
"contracts": {
"etherspotPaymasterAddress": "0x810FA4C915015b703db0878CF2B9344bEB254a40"
},
Expand Down
11 changes: 11 additions & 0 deletions backend/migrations/2024082200001-update-api-keys.cjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
require('dotenv').config();

async function up({ context: queryInterface }) {
await queryInterface.sequelize.query(`ALTER TABLE IF EXISTS "${process.env.DATABASE_SCHEMA_NAME}".api_keys ADD COLUMN "BUNDLER_API_KEY" text default null`);
}

async function down({ context: queryInterface }) {
await queryInterface.sequelize.query(`ALTER TABLE "${process.env.DATABASE_SCHEMA_NAME}".api_keys DROP COLUMN BUNDLER_API_KEY;`);
}

module.exports = { up, 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": "1.4.2",
"version": "1.4.3",
"description": "ARKA - (Albanian for Cashier's case) is the first open source Paymaster as a service software",
"type": "module",
"directories": {
Expand Down
7 changes: 7 additions & 0 deletions backend/src/models/api-key.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ export class APIKey extends Model {
public multiTokenOracles?: string | null;
public sponsorName?: string | null;
public logoUrl?: string | null;
public bundlerApiKey?: string | null;
public transactionLimit!: number;
public noOfTransactionsInAMonth?: number | null;
public indexerEndpoint?: string | null;
Expand Down Expand Up @@ -53,6 +54,12 @@ export function initializeAPIKeyModel(sequelize: Sequelize, schema: string) {
allowNull: true,
field: 'ERC20_PAYMASTERS_V2'
},
bundlerApiKey: {
type: DataTypes.TEXT,
allowNull: true,
field: 'BUNDLER_API_KEY',
defaultValue: null
},
multiTokenPaymasters: {
type: DataTypes.TEXT,
allowNull: true,
Expand Down
3 changes: 2 additions & 1 deletion backend/src/repository/api-key-repository.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,8 @@ export class APIKeyRepository {
logoUrl: apiKey.logoUrl,
transactionLimit: apiKey.transactionLimit,
noOfTransactionsInAMonth: apiKey.noOfTransactionsInAMonth,
indexerEndpoint: apiKey.indexerEndpoint
indexerEndpoint: apiKey.indexerEndpoint,
bundlerApiKey: apiKey.bundlerApiKey,
}) as APIKey;


Expand Down
6 changes: 4 additions & 2 deletions backend/src/routes/admin-routes.ts
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,8 @@ const adminRoutes: FastifyPluginAsync = async (server) => {
logoUrl: body.logoUrl ?? null,
transactionLimit: body.transactionLimit ?? 0,
noOfTransactionsInAMonth: body.noOfTransactionsInAMonth ?? 10,
indexerEndpoint: body.indexerEndpoint ?? process.env.DEFAULT_INDEXER_ENDPOINT
indexerEndpoint: body.indexerEndpoint ?? process.env.DEFAULT_INDEXER_ENDPOINT,
bundlerApiKey: body.bundlerApiKey ?? null,
});

return reply.code(ReturnCode.SUCCESS).send({ error: null, message: 'Successfully saved' });
Expand Down Expand Up @@ -141,7 +142,8 @@ const adminRoutes: FastifyPluginAsync = async (server) => {
erc20Paymasters: body.erc20Paymasters,
transactionLimit: body.transactionLimit ?? 0,
noOfTransactionsInAMonth: body.noOfTransactionsInAMonth ?? 10,
indexerEndpoint: body.indexerEndpoint ?? process.env.DEFAULT_INDEXER_ENDPOINT
indexerEndpoint: body.indexerEndpoint ?? process.env.DEFAULT_INDEXER_ENDPOINT,
bundlerApiKey: body.bundlerApiKey ?? null,
});

return reply.code(ReturnCode.SUCCESS).send({ error: null, message: 'Successfully updated' });
Expand Down
18 changes: 17 additions & 1 deletion backend/src/routes/deposit-route.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ const SUPPORTED_ENTRYPOINTS = {
}

const depositRoutes: FastifyPluginAsync = async (server) => {
const paymaster = new Paymaster(server.config.FEE_MARKUP, server.config.MULTI_TOKEN_MARKUP);
const paymaster = new Paymaster(server.config.FEE_MARKUP, server.config.MULTI_TOKEN_MARKUP, server.config.EP7_TOKEN_VGL, server.config.EP7_TOKEN_PGL);

const prefixSecretId = 'arka_';

Expand Down Expand Up @@ -55,6 +55,7 @@ const depositRoutes: FastifyPluginAsync = async (server) => {
return reply.code(ReturnCode.FAILURE).send({ error: ErrorMessage.INVALID_API_KEY })
let privateKey = '';
let supportedNetworks;
let bundlerApiKey = api_key;
if (!unsafeMode) {
const AWSresponse = await client.send(
new GetSecretValueCommand({
Expand All @@ -63,13 +64,19 @@ const depositRoutes: FastifyPluginAsync = async (server) => {
);
const secrets = JSON.parse(AWSresponse.SecretString ?? '{}');
if (!secrets['PRIVATE_KEY']) return reply.code(ReturnCode.FAILURE).send({ error: ErrorMessage.INVALID_API_KEY })
if (secrets['BUNDLER_API_KEY']) {
bundlerApiKey = secrets['BUNDLER_API_KEY'];
}
privateKey = secrets['PRIVATE_KEY'];
supportedNetworks = secrets['SUPPORTED_NETWORKS'];
} else {
const apiKeyEntity: APIKey | null = await server.apiKeyRepository.findOneByApiKey(api_key);
if (!apiKeyEntity) return reply.code(ReturnCode.FAILURE).send({ error: ErrorMessage.INVALID_API_KEY })
privateKey = decode(apiKeyEntity.privateKey, server.config.HMAC_SECRET);
supportedNetworks = apiKeyEntity.supportedNetworks;
if (apiKeyEntity.bundlerApiKey) {
bundlerApiKey = apiKeyEntity.bundlerApiKey;
}
}
if (
isNaN(amount) ||
Expand All @@ -83,6 +90,7 @@ 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);
} catch (err: any) {
request.log.error(err);
Expand All @@ -107,6 +115,7 @@ const depositRoutes: FastifyPluginAsync = async (server) => {
return reply.code(ReturnCode.FAILURE).send({ error: ErrorMessage.INVALID_API_KEY })
let privateKey = '';
let supportedNetworks;
let bundlerApiKey = api_key;
if (!unsafeMode) {
const AWSresponse = await client.send(
new GetSecretValueCommand({
Expand All @@ -115,13 +124,19 @@ const depositRoutes: FastifyPluginAsync = async (server) => {
);
const secrets = JSON.parse(AWSresponse.SecretString ?? '{}');
if (!secrets['PRIVATE_KEY']) return reply.code(ReturnCode.FAILURE).send({ error: ErrorMessage.INVALID_API_KEY })
if (secrets['BUNDLER_API_KEY']) {
bundlerApiKey = secrets['BUNDLER_API_KEY'];
}
privateKey = secrets['PRIVATE_KEY'];
supportedNetworks = secrets['SUPPORTED_NETWORKS'];
} else {
const apiKeyEntity: APIKey | null = await server.apiKeyRepository.findOneByApiKey(api_key);
if (!apiKeyEntity) return reply.code(ReturnCode.FAILURE).send({ error: ErrorMessage.INVALID_API_KEY })
privateKey = decode(apiKeyEntity.privateKey, server.config.HMAC_SECRET);
supportedNetworks = apiKeyEntity.supportedNetworks;
if (apiKeyEntity.bundlerApiKey) {
bundlerApiKey = apiKeyEntity.bundlerApiKey;
}
}
if (
isNaN(amount) ||
Expand All @@ -135,6 +150,7 @@ 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);
} catch (err: any) {
request.log.error(err);
Expand Down
11 changes: 10 additions & 1 deletion backend/src/routes/metadata-routes.ts
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ const metadataRoutes: FastifyPluginAsync = async (server) => {
let privateKey = '';
let supportedNetworks;
let sponsorName = '', sponsorImage = '';
let bundlerApiKey = api_key;
if (!unsafeMode) {
const AWSresponse = await client.send(
new GetSecretValueCommand({
Expand All @@ -57,6 +58,9 @@ const metadataRoutes: FastifyPluginAsync = async (server) => {
const buffer = Buffer.from(secrets['MULTI_TOKEN_PAYMASTERS'], 'base64');
multiTokenPaymasters = JSON.parse(buffer.toString());
}
if (secrets['BUNDLER_API_KEY']) {
bundlerApiKey = secrets['BUNDLER_API_KEY'];
}
sponsorName = secrets['SPONSOR_NAME'];
sponsorImage = secrets['LOGO_URL'];
privateKey = secrets['PRIVATE_KEY'];
Expand All @@ -75,6 +79,9 @@ const metadataRoutes: FastifyPluginAsync = async (server) => {
const buffer = Buffer.from(apiKeyEntity.multiTokenPaymasters, 'base64');
multiTokenPaymasters = JSON.parse(buffer.toString());
}
if (apiKeyEntity.bundlerApiKey) {
bundlerApiKey = apiKeyEntity.bundlerApiKey;
}
sponsorName = apiKeyEntity.sponsorName ? apiKeyEntity.sponsorName : "";
sponsorImage = apiKeyEntity.logoUrl ? apiKeyEntity.logoUrl : "";
privateKey = decode(apiKeyEntity.privateKey, server.config.HMAC_SECRET);
Expand All @@ -85,7 +92,9 @@ const metadataRoutes: FastifyPluginAsync = async (server) => {
}
const networkConfig = getNetworkConfig(chainId, supportedNetworks ?? '', "0x5FF137D4b0FDCD49DcA30c7CF57E578a026d2789");
if (!networkConfig) return reply.code(ReturnCode.FAILURE).send({ error: ErrorMessage.UNSUPPORTED_NETWORK });
const provider = new providers.JsonRpcProvider(networkConfig.bundler);
let bundlerUrl = networkConfig.bundler;
if (bundlerUrl.includes('etherspot.io')) bundlerUrl = `${networkConfig.bundler}?api-key=${bundlerApiKey}`;
const provider = new providers.JsonRpcProvider(bundlerUrl);
const signer = new Wallet(privateKey, provider)
const sponsorWalletBalance = await signer.getBalance();
const sponsorAddress = await signer.getAddress();
Expand Down
Loading

0 comments on commit fc3e800

Please sign in to comment.