Skip to content

Commit

Permalink
lint lint lint
Browse files Browse the repository at this point in the history
  • Loading branch information
parodime committed Feb 22, 2025
1 parent e763d86 commit 95302c3
Show file tree
Hide file tree
Showing 4 changed files with 111 additions and 101 deletions.
4 changes: 4 additions & 0 deletions packages/rfq-indexer/indexer/.eslintignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@

abis/FastBridgeV2.ts
FastBridgeV2.ts
indexer/FastBridgeV2.ts
5 changes: 3 additions & 2 deletions packages/rfq-indexer/indexer/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
"start": "ponder start",
"codegen": "ponder codegen",
"lint": "eslint .",
"ci:lint": "eslint .",
"ci:lint": "eslint . --ignore-path .eslintignore",
"typecheck": "tsc",
"test:coverage": "echo 'No tests defined.'",
"build:go": " ",
Expand All @@ -23,7 +23,8 @@
"license": "ISC",
"dependencies": {
"@ponder/core": "^0.4.41",
"viem": "^1.19.3"
"viem": "^1.19.3",
"dotenv": "^16.0.3"
},
"engines": {
"node": ">=18.17.0"
Expand Down
82 changes: 42 additions & 40 deletions packages/rfq-indexer/indexer/ponder.config.ts
Original file line number Diff line number Diff line change
@@ -1,91 +1,95 @@
import { privateEncrypt } from 'crypto'

import { createConfig, loadBalance, rateLimit } from '@ponder/core'
import { http } from 'viem'
import dotenv from 'dotenv';
import dotenv from 'dotenv'

import { ABI_FastBridgeV1 } from '@/abis/FastBridgeV1'
import { ABI_FastBridgeV2 } from '@/abis/FastBridgeV2';
import { privateEncrypt } from 'crypto';

import { ABI_FastBridgeV2 } from '@/abis/FastBridgeV2'

dotenv.config();
dotenv.config()

const getContractNetwork = (chainId: number, contractLabel: string) => {
contractLabel=contractLabel.toUpperCase()
const startBlockEnvVar = `CONTRACT_${contractLabel}_STARTBLOCK_${chainId}`;
const addressEnvVar = `CONTRACT_${contractLabel}_ADDRESS_${chainId}`;
contractLabel = contractLabel.toUpperCase()
const startBlockEnvVar = `CONTRACT_${contractLabel}_STARTBLOCK_${chainId}`
const addressEnvVar = `CONTRACT_${contractLabel}_ADDRESS_${chainId}`

const startBlock = process.env[startBlockEnvVar];
const contractAddr = process.env[addressEnvVar];
const startBlock = process.env[startBlockEnvVar]
const contractAddr = process.env[addressEnvVar]

// if no env vars found, assume this chain+contract is legitimately not applicable & return nothing
if (!startBlock && !contractAddr) {
return {};
return {}
}

if (!startBlock) {
throw new Error(`Environment variable ${startBlockEnvVar} must be defined`);
throw new Error(`Environment variable ${startBlockEnvVar} must be defined`)
}

if (!contractAddr) {
throw new Error(`Environment variable ${addressEnvVar} must be defined`);
throw new Error(`Environment variable ${addressEnvVar} must be defined`)
}

console.log(`Including ${contractLabel} ${chainId.toString().padStart(10)}:${contractAddr.slice(0,6)} blocks ${startBlock.toString().padStart(10)} - <CURRENT>`);
console.log(
`Including ${contractLabel} ${chainId
.toString()
.padStart(10)}:${contractAddr.slice(0, 6)} blocks ${startBlock
.toString()
.padStart(10)} - <CURRENT>`
)

return {
[chainId]: {
contractAddr,
startBlock: parseInt(startBlock, 10),
}
};
};
},
}
}

const getConfigNetwork = (chainId: number) => {
const transportEnvVarName = `RPC_URL_${chainId}`;
const url = process.env[transportEnvVarName];
const transportEnvVarName = `RPC_URL_${chainId}`
const url = process.env[transportEnvVarName]

if (!url) {
throw new Error(`RPC_URL_${chainId} must be defined`);
throw new Error(`RPC_URL_${chainId} must be defined`)
}

if (!url.startsWith('http')) {
throw new Error(`RPC_URL_${chainId} must be an HTTP/S URL`);
throw new Error(`RPC_URL_${chainId} must be an HTTP/S URL`)
}

// conditionally apply rate limits to RPCs
// const requestsPerSecond = process.env[`RPC_LIMIT_RPS_${chainId}`] ? parseInt(process.env[`RPC_LIMIT_RPS_${chainId}`]!, 10) : 9999;
// const transport = rateLimit(http(url), { requestsPerSecond });

const transport = http(url);
const transport = http(url)

return {
chainId,
transport,
};
};

}
}

// infer chain ID list from RPC_URL_ env vars that are configured
const chainIds = Object.keys(process.env)
.filter(key => key.startsWith('RPC_URL_'))
.map(key => parseInt(key.replace('RPC_URL_', ''), 10));
.filter((key) => key.startsWith('RPC_URL_'))
.map((key) => parseInt(key.replace('RPC_URL_', ''), 10))

// generate contract network records
export const contractNetworks_FastBridgeV1 = chainIds.reduce((acc, chainId) => {
return { ...acc, ...getContractNetwork(chainId, "FASTBRIDGEV1") };
}, {});
return { ...acc, ...getContractNetwork(chainId, 'FASTBRIDGEV1') }
}, {})

export const contractNetworks_FastBridgeV2 = chainIds.reduce((acc, chainId) => {
return { ...acc, ...getContractNetwork(chainId, "FASTBRIDGEV2") };
}, {});
return { ...acc, ...getContractNetwork(chainId, 'FASTBRIDGEV2') }
}, {})

const configNetworks = chainIds.reduce((acc, chainId) => {
return {
...acc,
[chainId]: getConfigNetwork(chainId)
};
}, {});

return {
...acc,
[chainId]: getConfigNetwork(chainId),
}
}, {})

console.log(contractNetworks_FastBridgeV2)

Expand All @@ -101,6 +105,4 @@ export default createConfig({
network: contractNetworks_FastBridgeV1,
},
},
});


})
Loading

0 comments on commit 95302c3

Please sign in to comment.