Skip to content

Commit

Permalink
Packages Updated (#38)
Browse files Browse the repository at this point in the history
* updated all packages and added cron time to env

* updated package lock file

* added network config check in cron job
  • Loading branch information
vignesha22 authored Dec 1, 2023
1 parent b635cd2 commit 99397c3
Show file tree
Hide file tree
Showing 5 changed files with 1,778 additions and 409 deletions.
10 changes: 5 additions & 5 deletions backend/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -29,16 +29,16 @@
"@account-abstraction/contracts": "0.6.0",
"@account-abstraction/utils": "0.5.0",
"@aws-sdk/client-secrets-manager": "3.410.0",
"@fastify/cors": "^8.4.0",
"@sinclair/typebox": "0.23.5",
"@fastify/cors": "8.4.1",
"@sinclair/typebox": "0.31.28",
"ajv": "8.11.2",
"dotenv": "16.0.3",
"env-schema": "5.1.1",
"ethers": "5.7.2",
"fastify": "4.10.2",
"fastify-cron": "^1.3.1",
"fastify": "4.24.3",
"fastify-cron": "1.3.1",
"fastify-plugin": "3.0.1",
"node-fetch": "^3.3.2"
"node-fetch": "3.3.2"
},
"devDependencies": {
"@babel/core": "7.23.2",
Expand Down
71 changes: 38 additions & 33 deletions backend/src/routes/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -384,42 +384,47 @@ export async function cronJob() {
const DEPLOYED_ERC20_PAYMASTERS = JSON.parse(buffer.toString());
Object.keys(DEPLOYED_ERC20_PAYMASTERS).forEach(async (chain) => {
const networkConfig = getNetworkConfig(chain, '');
const deployedPaymasters: string[] = DEPLOYED_ERC20_PAYMASTERS[chain];
const provider = new providers.JsonRpcProvider(networkConfig.bundler);
const signer = new ethers.Wallet(process.env.CRON_PRIVATE_KEY ?? '', provider);
deployedPaymasters.forEach(async (depolyedPaymaster) => {
const paymasterContract = new ethers.Contract(depolyedPaymaster, PimlicoAbi, signer)
const pythMainnetChains = process.env.PYTH_MAINNET_CHAIN_IDS;
const pythTestnetChains = process.env.PYTH_TESTNET_CHAIN_IDS;
if (pythMainnetChains?.includes(chain) || pythTestnetChains?.includes(chain)) {
if (networkConfig) {
const deployedPaymasters: string[] = DEPLOYED_ERC20_PAYMASTERS[chain];
const provider = new providers.JsonRpcProvider(networkConfig.bundler);
const signer = new ethers.Wallet(process.env.CRON_PRIVATE_KEY ?? '', provider);
deployedPaymasters.forEach(async (deployedPaymaster) => {
const paymasterContract = new ethers.Contract(deployedPaymaster, PimlicoAbi, signer)
const pythMainnetChains = process.env.PYTH_MAINNET_CHAIN_IDS;
const pythTestnetChains = process.env.PYTH_TESTNET_CHAIN_IDS;
if (pythMainnetChains?.includes(chain) || pythTestnetChains?.includes(chain)) {
try {
const oracleAddress = await paymasterContract.tokenOracle();
const oracleContract = new ethers.Contract(oracleAddress, PythOracleAbi, provider)
const priceId = await oracleContract.priceLocator();
const TESTNET_API_URL = process.env.PYTH_TESTNET_URL;
const MAINNET_API_URL = process.env.PYTH_MAINNET_URL;
const requestURL = `${chain === '5000' ? MAINNET_API_URL : TESTNET_API_URL}${priceId}`;
const response = await fetch(requestURL);
const vaa: any = await response.json();
const priceData = '0x' + Buffer.from(vaa[0], 'base64').toString('hex');
const updateFee = await oracleContract.getUpdateFee([priceData]);
const data = oracleContract.interface.encodeFunctionData('updatePrice', [[priceData]])
const tx = await signer.sendTransaction({
to: oracleAddress,
data: data,
value: updateFee
});
await tx.wait();
} catch (err) {
logger.error(err);
}
}
try {
const oracleAddress = await paymasterContract.tokenOracle();
const oracleContract = new ethers.Contract(oracleAddress, PythOracleAbi, provider)
const priceId = await oracleContract.priceLocator();
const TESTNET_API_URL = process.env.PYTH_TESTNET_URL;
const MAINNET_API_URL = process.env.PYTH_MAINNET_URL;
const requestURL = `${chain === '5000' ? MAINNET_API_URL : TESTNET_API_URL}${priceId}`;
const response = await fetch(requestURL);
const vaa: any = await response.json();
const priceData = '0x' + Buffer.from(vaa[0], 'base64').toString('hex');
const updateFee = await oracleContract.getUpdateFee([priceData]);
const data = oracleContract.interface.encodeFunctionData('updatePrice', [[priceData]])
const tx = await signer.sendTransaction({
to: oracleAddress,
data: data,
value: updateFee
});
await tx.wait();
await paymasterContract.updatePrice();
logger.info('Price Updated for ' + chain);
} catch (err) {
logger.error(err);
logger.error('Err on updating Price on paymaster' + err);
}
}
try {
await paymasterContract.updatePrice();
} catch (err) {
logger.error('Err on updating Price on paymaster' + err);
}
});
});
} else {
logger.info('Network config for ' + chain + ' is not added to default');
}
});
}
}
Expand Down
2 changes: 1 addition & 1 deletion backend/src/server.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ await server.register(fastifyCron, {
// Only these two properties are required,
// the rest is from the node-cron API:
// https://github.com/kelektiv/node-cron#api
cronTime: '0 0 * * *', // Everyday at midnight UTC
cronTime: process.env.CRON_TIME ?? '0 0 * * *', // Default: Everyday at midnight UTC

// Note: the callbacks (onTick & onComplete) take the server
// as an argument, as opposed to nothing in the node-cron API:
Expand Down
Loading

0 comments on commit 99397c3

Please sign in to comment.