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 2579 cron changes #125

Merged
merged 3 commits into from
Aug 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
1 change: 1 addition & 0 deletions .env.example
Original file line number Diff line number Diff line change
Expand Up @@ -19,3 +19,4 @@ DATABASE_NAME=
DATABASE_SCHEMA_NAME=arka
DATABASE_SSL_ENABLED=false
DATABASE_SSL_REJECT_UNAUTHORIZED=false
PRICE_UPDATE_CRON_EXP="0 0 * * *"
2 changes: 2 additions & 0 deletions backend/.env.example
Original file line number Diff line number Diff line change
Expand Up @@ -20,3 +20,5 @@ DATABASE_SSL_REJECT_UNAUTHORIZED="false"
DATABASE_USER=""
DATABASE_PASSWORD=""
DATABASE_NAME=""

PRICE_UPDATE_CRON_EXP="0 0 * * *"
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.0",
"version": "1.4.1",
"description": "ARKA - (Albanian for Cashier's case) is the first open source Paymaster as a service software",
"type": "module",
"directories": {
Expand Down
12 changes: 10 additions & 2 deletions backend/src/constants/Pimlico.ts
Original file line number Diff line number Diff line change
Expand Up @@ -127,10 +127,12 @@ export const CustomDeployedPaymasters: Record<number, Record<string, string>> =
"FRAX": "0xE0221Db5bF2F3C22d6639a749B764f52f5B05dfb"
},
"114": {
"USDC": "0x8b067387ec0B922483Eadb771bc9290194685522"
"USDC": "0x8b067387ec0B922483Eadb771bc9290194685522",
"USDT": "0xED35f8fa422Ba95A52A000236F1EAFd7e4fA4D52"
},
"14": {
"eUSDT": "0x6Bb048981E67f1a0aD41c0BD05635244d3ADaA2c"
"eUSDT": "0x6Bb048981E67f1a0aD41c0BD05635244d3ADaA2c",
"eUSDC": "0xA5589D278778Eaae346383dD710D7913d8A6a2aA"
},
"5001": {
"USDCT": "0x6Ea25cbb60360243E871dD935225A293a78704a8"
Expand Down Expand Up @@ -176,6 +178,12 @@ export const PAYMASTER_ADDRESS: Record<number, Record<string, string>> = {
80001: {
USDC: "0x000000000009B901DeC1aaB9389285965F49D387"
},
114: {
USDT: "0xED35f8fa422Ba95A52A000236F1EAFd7e4fA4D52"
},
14: {
eUSDC: "0xA5589D278778Eaae346383dD710D7913d8A6a2aA"
}
}

/**
Expand Down
33 changes: 29 additions & 4 deletions backend/src/server.ts
Original file line number Diff line number Diff line change
Expand Up @@ -77,23 +77,48 @@ const initializeServer = async (): Promise<void> => {
server.log.info('registered sequelizePlugin...')

const arkaConfigRepository = new ArkaConfigRepository(server.sequelize);
const configDatas = await arkaConfigRepository.findAll();
const configData: ArkaConfig | null = configDatas.length > 0 ? configDatas[0] : null;

await server.register(fastifyCron, {
jobs: [
{
// Only these two properties are required,
// the rest is from the node-cron API:
// https://github.com/kelektiv/node-cron#api
cronTime: configData?.cronTime ?? '0 0 * * *', // Default: Everyday at midnight UTC,
cronTime: process.env.PRICE_UPDATE_CRON_EXP ?? '0 0 * * *', // Default: Everyday at midnight UTC,
name: 'PriceUpdate',

// Note: the callbacks (onTick & onComplete) take the server
// as an argument, as opposed to nothing in the node-cron API:
onTick: async () => {
let configData: any
if (process.env.CRON_PRIVATE_KEY) {
const paymastersAdrbase64 = configData?.deployedErc20Paymasters ?? ''
const unsafeMode = process.env.UNSAFE_MODE === "true" ? true : false;
if(!unsafeMode) {
const client = new SecretsManagerClient();
const api_key = process.env.DEFAULT_API_KEY;
const prefixSecretId = "arka_";
const AWSresponse = await client.send(
new GetSecretValueCommand({
SecretId: prefixSecretId + api_key,
})
);
const secrets = JSON.parse(AWSresponse.SecretString ?? '{}');
configData = {
coingeckoApiUrl: secrets["COINGECKO_API_URL"],
Copy link
Contributor Author

@nikhilkumar1612 nikhilkumar1612 Aug 19, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

i need someone to verify if the keys which i have used are valid on secrets manager:
COINGECKO_API_URL, COINGECKO_IDS, CUSTOM_CHAINLINK_DEPLOYED, DEPLOYED_ERC20_PAYMASTERS, PYTH_MAINNET_CHAINIDS, PYTH_MAINNET_URL, PYTH_TESTNET_CHAINIDS, PYTH_TESTNET_URL

cc: @kanthgithub @ch4r10t33r @sarthakprp

coingeckoIds: secrets["COINGECKO_IDS"],
customChainlinkDeployed: secrets["CUSTOM_CHAINLINK_DEPLOYED"],
deployedErc20Paymasters: secrets["DEPLOYED_ERC20_PAYMASTERS"],
pythMainnetChainIds: secrets["PYTH_MAINNET_CHAINIDS"],
pythMainnetUrl: secrets["PYTH_MAINNET_URL"],
pythTestnetChainIds: secrets["PYTH_TESTNET_CHAINIDS"],
pythTestnetUrl: secrets["PYTH_TESTNET_URL"]
}
client.destroy();
} else {
const configDatas = await arkaConfigRepository.findAll();
configData = configDatas.length > 0 ? configDatas[0] : null;
}
const paymastersAdrbase64 = configData?.deployedErc20Paymasters ?? '';
if (paymastersAdrbase64) {
const buffer = Buffer.from(paymastersAdrbase64, 'base64');
const DEPLOYED_ERC20_PAYMASTERS = JSON.parse(buffer.toString());
Expand Down
Loading