From 570a2b2c0a593a05be288635656207d1117f200c Mon Sep 17 00:00:00 2001 From: Dzmitry Lahunouski Date: Fri, 26 Jul 2024 20:13:34 +0100 Subject: [PATCH] simplify compose --- Makefile | 6 +-- docker-compose.yml | 57 +---------------------- src/cli/distributeNative.ts | 12 +++++ src/core/distribution/distributeERC.ts | 2 +- src/core/distribution/distributeNative.ts | 53 +++++++++++++++++++++ src/core/distribution/index.ts | 1 + 6 files changed, 70 insertions(+), 61 deletions(-) create mode 100644 src/cli/distributeNative.ts create mode 100644 src/core/distribution/distributeNative.ts diff --git a/Makefile b/Makefile index 6c86c9e..7d4b40e 100644 --- a/Makefile +++ b/Makefile @@ -30,9 +30,7 @@ encrypt-secrets :; export FILE=.secretsrc && export OUTPUT=.secrets && npx tsx s service?=fuel -up :; read -s -r -e -p "MASTER_KEY: " && echo $$REPLY > master_key && docker compose up -d $(service) && unset REPLY && docker compose logs -f $(service); rm -rf master_key - -up-all :; read -s -r -e -p "MASTER_KEY: " && echo $$REPLY > master_key && docker compose up -d && unset REPLY && docker compose logs -f; rm -rf master_key +up :; read -s -r -e -p "MASTER_KEY: " && echo $$REPLY > master_key && docker compose run --rm mono make $(cmd) && unset REPLY && docker compose logs -f; rm -rf master_key # cli list :; npx tsx src/cli/list.ts @@ -57,6 +55,6 @@ recover :; npx tsx src/cli/profiles.ts distributeERC :; npx tsx src/cli/distributeERC.ts -cli :; npx tsx src/cli/$(c).ts +distributeNative :; npx tsx src/cli/distributeNative.ts -include ${FCT_PLUGIN_PATH}/makefile-external \ No newline at end of file diff --git a/docker-compose.yml b/docker-compose.yml index a2609a0..6f2ae9d 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -1,12 +1,11 @@ version: "3.7" services: - funding: + mono: image: mono restart: always build: context: . - command: ["make", "funding"] secrets: - master_key logging: &loggin @@ -14,60 +13,6 @@ services: options: max-file: "5" max-size: "100m" - fuel: - image: mono - restart: always - build: - context: . - command: ["make", "fuel"] - logging: *loggin - secrets: - - master_key - scroll-kelp: - image: mono - restart: always - build: - context: . - command: ["make", "scroll-kelp"] - logging: *loggin - secrets: - - master_key - scroll-canvas: - image: mono - restart: always - build: - context: . - command: ["make", "scroll-canvas"] - logging: *loggin - secrets: - - master_key - symbioticYT2: - image: mono - restart: always - build: - context: . - command: ["make", "distributeERC"] - logging: *loggin - secrets: - - master_key - karakYT: - image: mono - restart: always - build: - context: . - command: ["make", "distributeERC"] - logging: *loggin - secrets: - - master_key - fuelDust: - image: mono - restart: always - build: - context: . - command: ["make", "distributeERC"] - logging: *loggin - secrets: - - master_key secrets: master_key: file: ./master_key diff --git a/src/cli/distributeNative.ts b/src/cli/distributeNative.ts new file mode 100644 index 0000000..5c93d1e --- /dev/null +++ b/src/cli/distributeNative.ts @@ -0,0 +1,12 @@ +import * as chains from "viem/chains"; +import { distributeNative } from "src/core/distribution"; +import { getAppConf } from "src/libs/configs"; +import { logger } from "src/logger"; + +(async function main() { + logger.info("initiated", { label: "CLI::distributeNative" }); + const conf = await getAppConf(); + const { chain } = conf.cli.distribute; + await distributeNative(chains[chain]); + logger.info("finished", { label: "CLI::distributeNative" }); +})(); diff --git a/src/core/distribution/distributeERC.ts b/src/core/distribution/distributeERC.ts index db49547..c5a0e83 100644 --- a/src/core/distribution/distributeERC.ts +++ b/src/core/distribution/distributeERC.ts @@ -34,7 +34,7 @@ export const distributeERC = async (chain: Chain, tokenAddress: Hex) => { } for (const item of config) { - transfer({ + await transfer({ wallet: wallets[0], tokenAddress: tokenAddress, receiverAddress: item.to, diff --git a/src/core/distribution/distributeNative.ts b/src/core/distribution/distributeNative.ts new file mode 100644 index 0000000..b389e6b --- /dev/null +++ b/src/core/distribution/distributeNative.ts @@ -0,0 +1,53 @@ +import { privateKeyToAccount } from "viem/accounts"; +import { Chain } from "viem/chains"; +import { getClient } from "src/libs/clients"; +import { getEVMWallets } from "src/libs/configs"; +// import { refreshProxy } from "src/libs/proxify"; +import { sleep, getRandomArbitrary } from "src/libs/shared"; +import { logger } from "src/logger"; + +export const distributeNative = async (chain: Chain) => { + const wallets = await getEVMWallets(); + + const client = await getClient(chain); + + const value = await client.getBalance({ + address: wallets[0].address, + }); + + logger.debug(`balance of ${wallets[0].address} is ${value}`, { label: "core/distributeNative" }); + + let valueLeft = value; + + const config = wallets.slice(1).map(({ address }, index) => { + const amount = (valueLeft / 100n) * BigInt(index + 1); + valueLeft -= amount; + return { + to: address, + amount, + }; + }); + + if (value - valueLeft !== config.reduce((acc, { amount }) => acc + amount, 0n)) { + logger.error(`config creation error`, { + label: "core/distributeNative", + }); + } + + for (const item of config) { + const tx = await client.sendTransaction({ + account: privateKeyToAccount(wallets[0].pkᵻ), + to: item.to, + value: item.amount, + chain, + }); + logger.info(`tx send ${tx}`, { + label: "core/distributeNative", + }); + const time = getRandomArbitrary(2 * 3.6e6, 3 * 3.6e6); + logger.info(`sleep for ${time}`, { + label: "core/distributeNative", + }); + await sleep(time); + } +}; diff --git a/src/core/distribution/index.ts b/src/core/distribution/index.ts index a97a738..1bed6a5 100644 --- a/src/core/distribution/index.ts +++ b/src/core/distribution/index.ts @@ -1,2 +1,3 @@ export { mill } from "./miller"; export { distributeERC } from "./distributeERC"; +export { distributeNative } from "./distributeNative";