From 7f00e2891338f69637d55513f76fcf4e62dad857 Mon Sep 17 00:00:00 2001 From: Raj Ranjan Date: Fri, 29 Dec 2023 02:52:13 +0530 Subject: [PATCH] simplify mainnet balance check config --- config.json | 3 ++- server.ts | 13 +++++++------ types.ts | 4 ++-- 3 files changed, 11 insertions(+), 9 deletions(-) diff --git a/config.json b/config.json index a426136..644cc0e 100644 --- a/config.json +++ b/config.json @@ -15,6 +15,7 @@ "IS_ENABLED": true, "MAX_LIMIT_CAP": 5000 }, + "MAINNET_BALANCE_CHECK_RPC": "https://api.avax.network/ext/C/rpc", "evmchains": [ { "ID": "C", @@ -30,7 +31,7 @@ "DECIMALS": 18, "RECALIBRATE": 30, "COUPON_REQUIRED": true, - "MAINNET_BALANCE_CHECK_RPC": "https://api.avax.network/ext/C/rpc", + "MAINNET_BALANCE_CHECK_ENABLED": true, "RATELIMIT": { "MAX_LIMIT": 5, "WINDOW_SIZE": 60 diff --git a/server.ts b/server.ts index f128a44..286a196 100644 --- a/server.ts +++ b/server.ts @@ -19,6 +19,7 @@ import { GLOBAL_RL, NATIVE_CLIENT, DEBUG, + MAINNET_BALANCE_CHECK_RPC, } from './config.json' import { CouponService } from './CouponService/couponService' import { @@ -78,7 +79,7 @@ const getChainByID = (chains: ChainType[], id: string): ChainType | undefined => return reply } -const separateConfigFields = ['COUPON_REQUIRED', 'MAINNET_BALANCE_CHECK_RPC'] +const separateConfigFields = ['COUPON_REQUIRED', 'MAINNET_BALANCE_CHECK_ENABLED'] // Populates the missing config keys of the child using the parent's config const populateConfig = (child: any, parent: any): any => { @@ -143,21 +144,21 @@ router.post('/sendToken', captcha.middleware, async (req: any, res: any) => { * 3. If no pipeline check is required for a token, then directly process the request * 4. Currently, we have 2 pipeline checks: Coupon Check & Mainnet Balance Check */ - const mainnetCheckEnabledRPC = (erc20Instance ? erc20Instance.config.MAINNET_BALANCE_CHECK_RPC : evm.config.MAINNET_BALANCE_CHECK_RPC) ?? false + const mainnetCheckEnabled = (erc20Instance ? erc20Instance.config.MAINNET_BALANCE_CHECK_ENABLED : evm.config.MAINNET_BALANCE_CHECK_ENABLED) ?? false const couponCheckEnabled = couponConfig.IS_ENABLED && ((erc20Instance ? erc20Instance.config.COUPON_REQUIRED : evm.config.COUPON_REQUIRED) ?? false) let pipelineValidity: PipelineCheckValidity = {isValid: false, dripAmount} !pipelineValidity.isValid && couponCheckEnabled && await checkCouponPipeline(couponService, pipelineValidity, faucetConfigId, coupon) // don't check mainnet balance, if coupon is provided - !pipelineValidity.isValid && !coupon && mainnetCheckEnabledRPC && await checkMainnetBalancePipeline(pipelineValidity, mainnetCheckEnabledRPC, address) + !pipelineValidity.isValid && !coupon && mainnetCheckEnabled && await checkMainnetBalancePipeline(pipelineValidity, MAINNET_BALANCE_CHECK_RPC, address) if ( - (mainnetCheckEnabledRPC || couponCheckEnabled) && + (mainnetCheckEnabled || couponCheckEnabled) && !pipelineValidity.isValid ) { // failed - res.status(400).send({message: pipelineValidity.errorMessage + pipelineFailureMessage(mainnetCheckEnabledRPC, couponCheckEnabled)}) + res.status(400).send({message: pipelineValidity.errorMessage + pipelineFailureMessage(MAINNET_BALANCE_CHECK_RPC, couponCheckEnabled)}) return } @@ -189,7 +190,7 @@ router.post('/sendToken', captcha.middleware, async (req: any, res: any) => { // GET request for fetching all the chain and token configurations router.get('/getChainConfigs', (req: any, res: any) => { const configs: any = [...evmchains, ...erc20tokens] - res.send({ configs }) + res.send({ configs, MAINNET_BALANCE_CHECK_RPC }) }) // GET request for fetching faucet address for the specified chain diff --git a/types.ts b/types.ts index 71bba96..f5cd3f2 100644 --- a/types.ts +++ b/types.ts @@ -37,7 +37,7 @@ export type ChainType = { DRIP_AMOUNT: number, RECALIBRATE?: number, COUPON_REQUIRED?: boolean, - MAINNET_BALANCE_CHECK_RPC?: string, + MAINNET_BALANCE_CHECK_ENABLED?: boolean, RATELIMIT: { WINDOW_SIZE: number, MAX_LIMIT: number @@ -65,7 +65,7 @@ export type ERC20Type = { MAX_PRIORITY_FEE?: string, MAX_FEE?: string, COUPON_REQUIRED?: boolean, - MAINNET_BALANCE_CHECK_RPC?: string, + MAINNET_BALANCE_CHECK_ENABLED?: boolean, } export type CouponValidity = {