Skip to content

Commit

Permalink
PRO-2862 - Coingecko Changes (#161)
Browse files Browse the repository at this point in the history
* coingecko database addition

* ft: adding cron jobs to increase cache hit ratio for oracle data (#157)

* ft: adding cron jobs to increase cache hit ratio for oracle data

* update version

* changes to make native oracle calls only for chainlink

* Fix/arb token (#158)

* fix for arb token in multi token paymaster

* update cron expression for erc20 oracle update cron

* comment and version update

* Pro 2857 (#153) (#159)

* Pro 2857 (#153)

* ft: adding support for verifying paymaster

* update: package.json version

* fix: changing names for mode, minor fix for entry point error message

* changes: common whitelist endpoints for v1/v2, removed v2 endpoints for whitelist

* adding changelog for backend

* chnages: version change, minor response changes for metadata and add stake routes

* coingecko database addition

* merge bug fixes

* updated version

* added required env vars to demo env

* changed to pro key

* changes done as requested

* changes to retain v2 endpoints, minor changes for change log

* updated changelog

---------

Co-authored-by: Nikhil Kumar <[email protected]>
Co-authored-by: nikhil kumar <[email protected]>
  • Loading branch information
3 people committed Jan 24, 2025
1 parent 9eeac4c commit ba0aec2
Show file tree
Hide file tree
Showing 4 changed files with 84 additions and 1 deletion.
2 changes: 1 addition & 1 deletion backend/demo.env
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,8 @@ MULTI_TOKEN_MARKUP=1150000
ETHERSCAN_GAS_ORACLES=
DEFAULT_API_KEY=
WEBHOOK_URL=
MTP_VGL_MARKUP=30000

# coingecko
COINGECKO_URL=
COINGECKO_API_KEY=
MTP_VGL_MARKUP=30000
1 change: 1 addition & 0 deletions backend/src/paymaster/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,7 @@ export class Paymaster {
this.EP7_TOKEN_VGL = ep7TokenVGL;
this.sequelize = sequelize;
this.MTP_VGL_MARKUP = mtpVglMarkup;
this.sequelize = sequelize;
}

packUint(high128: BigNumberish, low128: BigNumberish): string {
Expand Down
79 changes: 79 additions & 0 deletions backend/src/routes/paymaster-routes.ts
Original file line number Diff line number Diff line change
Expand Up @@ -390,6 +390,85 @@ const paymasterRoutes: FastifyPluginAsync<PaymasterRoutesOpts> = async (server,
}
break;
}
case 'vps': {
const date = new Date();
const provider = new providers.JsonRpcProvider(bundlerUrl);
const signer = new Wallet(privateKey, provider);

// get chainid from provider
const chainId = await provider.getNetwork();

// get wallet_address from api_key
const apiKeyData = await server.apiKeyRepository.findOneByApiKey(api_key);
if (!apiKeyData) return reply.code(ReturnCode.FAILURE).send({ error: ErrorMessage.API_KEY_NOT_CONFIGURED_IN_DATABASE });

const sponsorshipPolicy: SponsorshipPolicy | null = await server.sponsorshipPolicyRepository.findOneByWalletAddressAndSupportedEPVersion(apiKeyData?.walletAddress, getEPVersion(epVersion));
if (!sponsorshipPolicy) {
const errorMessage: string = generateErrorMessage(ErrorMessage.ACTIVE_SPONSORSHIP_POLICY_NOT_FOUND, { walletAddress: apiKeyData?.walletAddress, epVersion: epVersion, chainId: chainId.chainId });
return reply.code(ReturnCode.FAILURE).send({ error: errorMessage });
}

if (!Object.assign(new SponsorshipPolicy(), sponsorshipPolicy).isApplicable) {
const errorMessage: string = generateErrorMessage(ErrorMessage.NO_ACTIVE_SPONSORSHIP_POLICY_FOR_CURRENT_TIME, { walletAddress: apiKeyData?.walletAddress, epVersion: epVersion, chainId: chainId.chainId });
return reply.code(ReturnCode.FAILURE).send({ error: errorMessage });
}

// get supported networks from sponsorshipPolicy
const supportedNetworks: number[] | undefined | null = sponsorshipPolicy.enabledChains;
if (!supportedNetworks || !supportedNetworks.includes(chainId.chainId)) return reply.code(ReturnCode.FAILURE).send({ error: ErrorMessage.UNSUPPORTED_NETWORK });

if (txnMode) {
const signerAddress = await signer.getAddress();
const IndexerData = await getIndexerData(signerAddress, userOp.sender, date.getMonth(), date.getFullYear(), noOfTxns, indexerEndpoint ?? '');
if (IndexerData.length >= noOfTxns) return reply.code(ReturnCode.FAILURE).send({ error: ErrorMessage.QUOTA_EXCEEDED })
}
const validUntil = context?.validUntil ? new Date(context.validUntil) : date;
const validAfter = context?.validAfter ? new Date(context.validAfter) : date;
const hex = (Number((validUntil.valueOf() / 1000).toFixed(0)) + 600).toString(16);
const hex1 = (Number((validAfter.valueOf() / 1000).toFixed(0)) - 60).toString(16);
let str = '0x'
let str1 = '0x'
for (let i = 0; i < 14 - hex.length; i++) {
str += '0';
}
for (let i = 0; i < 14 - hex1.length; i++) {
str1 += '0';
}
str += hex;
str1 += hex1;
if (contractWhitelistMode) {
const contractWhitelistResult = await checkContractWhitelist(userOp.callData, chainId.chainId, signer.address);
if (!contractWhitelistResult) throw new Error('Contract Method not whitelisted');
}

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');
}

if (epVersion === EPVersions.EPV_06) {
if(!apiKeyEntity.verifyingPaymasters) {
return reply.code(ReturnCode.FAILURE).send({error: ErrorMessage.VP_NOT_DEPLOYED});
}
const paymasterAddr = JSON.parse(apiKeyEntity.verifyingPaymasters)[chainId.chainId];
if(!paymasterAddr) {
return reply.code(ReturnCode.FAILURE).send({error: ErrorMessage.VP_NOT_DEPLOYED});
}
result = await paymaster.signV06(userOp, str, str1, entryPoint, paymasterAddr, bundlerUrl, signer, estimate, server.log);
}
else {
if(!apiKeyEntity.verifyingPaymastersV2) {
return reply.code(ReturnCode.FAILURE).send({error: ErrorMessage.VP_NOT_DEPLOYED});
}
const paymasterAddr = JSON.parse(apiKeyEntity.verifyingPaymastersV2)[chainId.chainId];
if(!paymasterAddr) {
return reply.code(ReturnCode.FAILURE).send({error: ErrorMessage.VP_NOT_DEPLOYED});
}
result = await paymaster.signV07(userOp, str, str1, entryPoint, paymasterAddr, bundlerUrl, signer, estimate, server.log);
}
break;
}
default: {
return reply.code(ReturnCode.FAILURE).send({ error: ErrorMessage.INVALID_MODE });
}
Expand Down
3 changes: 3 additions & 0 deletions backend/src/server.ts
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,9 @@ const initializeServer = async (): Promise<void> => {
healthcheckUrl: "/healthcheck",
logLevel: "warn"
});

// Register the sequelizePlugin
await server.register(sequelizePlugin);

// Register the sequelizePlugin
await server.register(sequelizePlugin);
Expand Down

0 comments on commit ba0aec2

Please sign in to comment.