Skip to content

Commit

Permalink
simplify compose
Browse files Browse the repository at this point in the history
  • Loading branch information
killroy192 committed Jul 26, 2024
1 parent e52a252 commit 570a2b2
Show file tree
Hide file tree
Showing 6 changed files with 70 additions and 61 deletions.
6 changes: 2 additions & 4 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
57 changes: 1 addition & 56 deletions docker-compose.yml
Original file line number Diff line number Diff line change
@@ -1,73 +1,18 @@
version: "3.7"

services:
funding:
mono:
image: mono
restart: always
build:
context: .
command: ["make", "funding"]
secrets:
- master_key
logging: &loggin
driver: "json-file"
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
12 changes: 12 additions & 0 deletions src/cli/distributeNative.ts
Original file line number Diff line number Diff line change
@@ -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" });
})();
2 changes: 1 addition & 1 deletion src/core/distribution/distributeERC.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
53 changes: 53 additions & 0 deletions src/core/distribution/distributeNative.ts
Original file line number Diff line number Diff line change
@@ -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);
}
};
1 change: 1 addition & 0 deletions src/core/distribution/index.ts
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
export { mill } from "./miller";
export { distributeERC } from "./distributeERC";
export { distributeNative } from "./distributeNative";

0 comments on commit 570a2b2

Please sign in to comment.