Skip to content

Commit

Permalink
Add whitelist referrer config
Browse files Browse the repository at this point in the history
  • Loading branch information
mrlotfi authored and mrlotfi committed Oct 10, 2024
1 parent 2687aec commit 8afd701
Show file tree
Hide file tree
Showing 5 changed files with 21 additions and 2 deletions.
1 change: 1 addition & 0 deletions .env.sample
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ POLYGON_2ND_RPC="https://polygon-rpc.com/"

DISABLE_UNLOCKER="false"
BLACKLISTED_REFERRERS=""
WHITELISTED_REFERRERS=""

SOLANA_TX_MODE="NORMAL" # [NORMAL | JITO]
JITO_ENDPOINT="https://frankfurt.mainnet.block-engine.jito.wtf"
Expand Down
1 change: 1 addition & 0 deletions src/config/global.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ export interface SwiftFeeParams {
export type GlobalConfig = {
ignoreReferrers: Set<string>;
blackListedReferrerAddresses: Set<string>;
whiteListedReferrerAddresses: Set<string>;
auctionTimeSeconds: number;
batchUnlockThreshold: number; // Optimal Number of swaps to select for unlocking
singleBatchChainIds: number[]; // Expensive chain-ids that use direct vaa post instead of batch (e.g ethereum)
Expand Down
4 changes: 2 additions & 2 deletions src/driver/evm.ts
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ export class EvmFulfiller {
this.contractsConfig.contracts[chainId],
);

if (current < ethers.MaxUint256 - 1_000_000_000_000_000_000n) {
if (current < ethers.MaxUint256 - 1_000_000_000_000_000_000_000_000_000n) {
logger.info(`Setting allowance for ${driverToken.contract} on chain ${chainId}`);
await giveErc20Allowance(
this.walletHelper.getDriverWallet(chainId),
Expand Down Expand Up @@ -104,7 +104,7 @@ export class EvmFulfiller {
this.contractsConfig.evmFulfillHelpers[chainId],
);

if (current < ethers.MaxUint256 - 1_000_000_000_000_000_000n) {
if (current < ethers.MaxUint256 - 1_000_000_000_000_000_000_000_000_000n) {
logger.info(`Setting allowance for helper ${driverToken.contract} on chain ${chainId}`);
await giveErc20Allowance(
this.walletHelper.getDriverWallet(chainId),
Expand Down
7 changes: 7 additions & 0 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,11 @@ export async function main() {
const initialDynamicConfig = await fetchDynamicSdkParams();
rpcConfig.wormholeGuardianRpcs = initialDynamicConfig.wormholeGuardianRpcs.split(',');

let whiteListedReferrerAddresses: Set<string> = new Set();
if (process.env.WHITELISTED_REFERRERS) {
whiteListedReferrerAddresses = new Set(process.env.WHITELISTED_REFERRERS.split(','));
}

const globalConfig: GlobalConfig = {
ignoreReferrers: new Set(initialDynamicConfig.ignoreReferrers),
auctionTimeSeconds: initialDynamicConfig.auctionTimeSeconds,
Expand All @@ -59,6 +64,8 @@ export async function main() {
acc.add(x);
return acc;
}, new Set<string>()),

whiteListedReferrerAddresses: whiteListedReferrerAddresses,
};

const contracts: ContractsConfig = {
Expand Down
10 changes: 10 additions & 0 deletions src/relayer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -124,6 +124,16 @@ export class Relayer {
return;
}

if (
this.gConf.whiteListedReferrerAddresses.size > 0 &&
!this.gConf.whiteListedReferrerAddresses.has(swap.referrerAddress)
) {
logger.warn(
`Whitelist enabled and referrer address ${swap.referrerAddress} is not whitelisted for ${swap.sourceTxHash}. discarding...`,
);
return;
}

if (
this.gConf.ignoreReferrers.has(swap.referrerAddress) ||
this.gConf.blackListedReferrerAddresses.has(swap.referrerAddress)
Expand Down

0 comments on commit 8afd701

Please sign in to comment.