Skip to content

Commit

Permalink
Pro 2579 cron changes (#125)
Browse files Browse the repository at this point in the history
* adding changes for cron job and contracts for flare testnet

* updating .env.example, package.json

* adding new USDCe paymaster on flare, update .env-example

---------

Co-authored-by: nikhil kumar <[email protected]>
  • Loading branch information
nikhilkumar1612 and nikhil kumar authored Aug 20, 2024
1 parent 9a796de commit 9cce3fa
Show file tree
Hide file tree
Showing 5 changed files with 43 additions and 7 deletions.
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"],
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

0 comments on commit 9cce3fa

Please sign in to comment.