Skip to content

Commit

Permalink
feat: add rpc url scraper option to config and environment file
Browse files Browse the repository at this point in the history
  • Loading branch information
SirTLB committed Apr 14, 2023
1 parent df9670f commit 440734e
Show file tree
Hide file tree
Showing 6 changed files with 22 additions and 7 deletions.
3 changes: 2 additions & 1 deletion .env.injective.example
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,8 @@ SKIP_URL="https://injective-1-api.skip.money"
SKIP_BID_WALLET="inj17yqtnk08ly94lgz3fzagfu2twsws33z7sfsv46"
SKIP_BID_RATE="0.1" #e.g. 20% of the profit is used as a bid to win the auction
CHAIN_PREFIX="inj"
RPC_URL="https://ww-juno-rpc.polkachu.com" #irrelevant overwritten by k8s frominjective
USE_RPC_URL_SCRAPER="0"
RPC_URL="" #change this
GAS_UNIT_PRICE="0.0004"
FLASHLOAN_ROUTER_ADDRESS="inj1hyja4uyjktpeh0fxzuw2fmjudr85rk2qxgqkvu"
FLASHLOAN_FEE="0.15"
1 change: 1 addition & 0 deletions .env.juno.example
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ IGNORE_ADDRESSES='[""]'
BASE_DENOM="ujuno" # The asset denom to be used as base asset. This should be the denom of a Native Token only.
GAS_DENOM="ujuno"
CHAIN_PREFIX="juno"
USE_RPC_URL_SCRAPER="0"
RPC_URL=["https://juno-rpc.reece.sh"] #change this
GAS_UNIT_PRICE="0.0025"
FLASHLOAN_ROUTER_ADDRESS="juno1qa7vdlm6zgq3radal5sltyl4t4qd32feug9qs50kcxda46q230pqzny48s"
Expand Down
1 change: 1 addition & 0 deletions .env.terra.example
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ SKIP_BID_RATE="0.1" #e.g. 10% of the profit is used as a bid to win the auction
BASE_DENOM="uluna"
GAS_DENOM="uluna"
CHAIN_PREFIX="terra"
USE_RPC_URL_SCRAPER="0"
RPC_URL=[""] ##change this
GAS_UNIT_PRICE="0.015"
FLASHLOAN_ROUTER_ADDRESS="terra1c8tpvta3umr4mpufvxmq39gyuw2knpyxyfgq8thpaeyw2r6a80qsg5wa00"
Expand Down
16 changes: 12 additions & 4 deletions src/core/types/base/botConfig.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ interface LoggerConfig {
export interface BotConfig {
chainPrefix: string;
rpcUrls: Array<string>;
useRpcUrlScraper: boolean;
ignoreAddresses: Set<string>;
poolEnvs: Array<{ pool: string; inputfee: number; outputfee: number; LPratio: number }>;
maxPathPools: number;
Expand Down Expand Up @@ -53,11 +54,17 @@ export interface BotConfig {
*/
export async function setBotConfig(envs: NodeJS.ProcessEnv): Promise<BotConfig> {
validateEnvs(envs);
let RPCURLS;
if (envs.RPC_URL) {
RPCURLS = await getRPCfromRegistry(envs.CHAIN_PREFIX, JSON.parse(envs.RPC_URL));
} else {
let RPCURLS: Array<string>;
if (envs.RPC_URL && envs.USE_RPC_URL_SCRAPER) {
const RPCURLS_PROVIDED = envs.RPC_URL.startsWith("[") ? JSON.parse(envs.RPC_URL) : [envs.RPC_URL];
RPCURLS = await getRPCfromRegistry(envs.CHAIN_PREFIX, RPCURLS_PROVIDED);
} else if (!envs.RPC_URL && envs.USE_RPC_URL_SCRAPER) {
RPCURLS = await getRPCfromRegistry(envs.CHAIN_PREFIX);
} else if (envs.RPC_URL) {
RPCURLS = envs.RPC_URL.startsWith("[") ? JSON.parse(envs.RPC_URL) : [envs.RPC_URL];
} else {
console.log("no RPC URL provided or USE_RPC_URL_SCRAPER not set correctly");
process.exit(1);
}
let pools = envs.POOLS.trim()
.replace(/\n|\r|\t/g, "")
Expand Down Expand Up @@ -129,6 +136,7 @@ export async function setBotConfig(envs: NodeJS.ProcessEnv): Promise<BotConfig>
const botConfig: BotConfig = {
chainPrefix: envs.CHAIN_PREFIX,
rpcUrls: RPCURLS,
useRpcUrlScraper: envs.USE_RPC_URL_SCRAPER == "1" ? true : false,
poolEnvs: POOLS_ENVS,
maxPathPools: MAX_PATH_HOPS,
mappingFactoryRouter: FACTORIES_TO_ROUTERS_MAPPING,
Expand Down
6 changes: 5 additions & 1 deletion src/core/types/modules.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,12 @@ declare namespace NodeJS {
/**
* The http endpoint to the RPC.
*/

RPC_URL: string;
/**
* Whether or not to use cosmos chainregistry for finding public endpoints and using them
* if necessary.
*/
USE_RPC_URL_SCRAPER: string;
/**
* A list of all the factories to map, separated by ", \n".
*
Expand Down
2 changes: 1 addition & 1 deletion src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,11 +25,11 @@ dotenv.config();
*/
async function main() {
const botConfig = await setBotConfig(process.env);

let startupMessage = "===".repeat(30);
startupMessage += "\n**White Whale Bot**\n";
startupMessage += "===".repeat(30);
startupMessage += `\nEnvironment Variables:\n
**RPC ENDPOINT SCRAPER: ** \t${botConfig.useRpcUrlScraper}
**RPC ENPDOINTS:** \t${botConfig.rpcUrls}
**OFFER DENOM:** \t${JSON.stringify(botConfig.offerAssetInfo)}
**FACTORIES_TO_ROUTERS_MAPPING:** \t${JSON.stringify(botConfig.mappingFactoryRouter)}
Expand Down

0 comments on commit 440734e

Please sign in to comment.