Skip to content

Commit

Permalink
fuel with alchemy
Browse files Browse the repository at this point in the history
  • Loading branch information
killroy192 committed Jul 10, 2024
1 parent 74bcf71 commit dc38ca5
Show file tree
Hide file tree
Showing 10 changed files with 85 additions and 57 deletions.
3 changes: 2 additions & 1 deletion .env.example
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,5 @@ PROXY_USER=FFFFFF
PROXY_PASS=AAAAAAAAAAAA
PROXY_HOST=xproxy.site
PROXY_PORT=11111
PROXY_REBOOT=https://changeip.mobileproxy.space/?proxy_key=
PROXY_REBOOT=https://changeip.mobileproxy.space/?proxy_key=
ALCHEMY_RPC_KEY=
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ profiles :; node --import tsx/esm src/cli/profiles.ts

recover :; node --import tsx/esm src/cli/recover.ts

tx :; node --import tsx/esm src/cli/tx.ts
fuel :; node --import tsx/esm src/cli/fuel.ts

report :; node --import tsx/esm src/cli/report.ts

Expand Down
8 changes: 0 additions & 8 deletions src/cli/tx.ts

This file was deleted.

30 changes: 30 additions & 0 deletions src/libs/alchemy.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
/*
* The supported networks by Alchemy. Note that some functions are not available
* on all networks. Please refer to the Alchemy documentation for which APIs are
* available on which networks
* {@link https://docs.alchemy.com/alchemy/apis/feature-support-by-chain}
*
* @public
*/
export enum Network {
ETH_MAINNET = "eth-mainnet",
ETH_GOERLI = "eth-goerli",
ETH_SEPOLIA = "eth-sepolia",
OPT_MAINNET = "opt-mainnet",
OPT_GOERLI = "opt-goerli",
OPT_SEPOLIA = "opt-sepolia",
ARB_MAINNET = "arb-mainnet",
ARB_GOERLI = "arb-goerli",
ARB_SEPOLIA = "arb-sepolia",
MATIC_MAINNET = "polygon-mainnet",
MATIC_MUMBAI = "polygon-mumbai",
MATIC_AMOY = "polygon-amoy",
ASTAR_MAINNET = "astar-mainnet",
POLYGONZKEVM_MAINNET = "polygonzkevm-mainnet",
POLYGONZKEVM_TESTNET = "polygonzkevm-testnet",
BASE_MAINNET = "base-mainnet",
BASE_GOERLI = "base-goerli",
BASE_SEPOLIA = "base-sepolia",
ZKSYNC_MAINNET = "zksync-mainnet",
ZKSYNC_SEPOLIA = "zksync-sepolia",
}
41 changes: 41 additions & 0 deletions src/libs/clients.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
import { AxiosInstance } from "axios";
import { createWalletClient, http, publicActions, custom, createPublicClient } from "viem";
import * as chains from "viem/chains";
import getEnv from "src/env";
import { Network as AlchemyNetwork } from "src/libs/alchemy";

type ChainIdToAlchemyNetworksMap = {
[prop: number]: AlchemyNetwork;
};

const chainIdToAlchemyNetworksMap: ChainIdToAlchemyNetworksMap = {
[chains.mainnet.id]: AlchemyNetwork.ETH_MAINNET,
};

const transport = (chain: chains.Chain, proxy?: AxiosInstance) => {
if (!proxy) {
return http();
}

return custom({
async request(body: { method: string; params: any[] }) {
const response = await proxy.post(
`https://${chainIdToAlchemyNetworksMap[chain.id]}.g.alchemy.com/v2/${getEnv("ALCHEMY_RPC_KEY")}`,
body,
);
return response.data;
},
});
};

export const getPublicClient = (chain: chains.Chain) =>
createPublicClient({
chain,
transport: http(),
});

export const getClient = (chain: chains.Chain, proxy: AxiosInstance) =>
createWalletClient({
chain,
transport: transport(chain, proxy),
}).extend(publicActions);
21 changes: 0 additions & 21 deletions src/libs/local-evm-client.ts

This file was deleted.

2 changes: 1 addition & 1 deletion src/libs/validations.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import Joi from "joi";
export const validateMKey = (input: string) => {
Joi.attempt(
input,
Joi.string().pattern(new RegExp("^(?=.*?[A-Z])(?=.*?[a-z])(?=.*?[0-9])(?=.*?[#?!@$%^&*-]).{8,}$")).required(),
Joi.string().pattern(new RegExp("^(?=.*?[A-Z])(?=.*?[a-z])(?=.*?[0-9])(?=.*?[#?!@$%^&*-.]).{8,}$")).required(),
"minimum eight characters, at least one uppercase letter, one lowercase letter, one number and one special character",
);
return input;
Expand Down
14 changes: 9 additions & 5 deletions src/packages/fuel/deposit/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,9 @@ import { getContract, zeroAddress } from "viem";
import { privateKeyToAccount } from "viem/accounts";
import * as chains from "viem/chains";
import { abi } from "./abi";
import { getClient, getPublicClient } from "src/libs/clients";
import { decryptMarkedFields } from "src/libs/crypt";
import { getClient } from "src/libs/local-evm-client";
import { refreshProxy } from "src/libs/proxify";
import { Profile } from "src/types/profile";

// export async function tx(network: string) {
Expand All @@ -30,14 +31,18 @@ function getDecodedEVM(profiles: Profile, masterKey: string) {

type EVMWallet = Profile["string"]["wallets"]["evm"];

const checkAndDeposit = (client: ReturnType<typeof getClient>, evmWallet: EVMWallet) => async () => {
const checkAndDeposit = (evmWallet: EVMWallet) => async () => {
const pk = evmWallet.pkᵻ as `0x${string}`;
const account = privateKeyToAccount(pk);

const axiosInstance = await refreshProxy();
const publicClient = getPublicClient(chains.mainnet);
const walletClient = getClient(chains.mainnet, axiosInstance);

const contract = getContract({
address: "0x19b5cc75846BF6286d599ec116536a333C4C2c14",
abi,
client,
client: { public: publicClient, wallet: walletClient },
});

const userBalance = await contract.read.getBalance([account.address, zeroAddress]);
Expand All @@ -54,9 +59,8 @@ const checkAndDeposit = (client: ReturnType<typeof getClient>, evmWallet: EVMWal

export function deposit(masterKey: string) {
const profiles = JSON.parse(readFileSync(resolve(".", ".profiles.json"), "utf-8")) as Profile;
const client = getClient(chains.mainnet);

return [getDecodedEVM(profiles, masterKey)[0]].reduce((promise, accountData) => {
return promise.then(checkAndDeposit(client, accountData));
return promise.then(checkAndDeposit(accountData));
}, Promise.resolve());
}
2 changes: 1 addition & 1 deletion src/packages/scroll/report/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import { Profile } from "src/types/profile";

const refreshAndCall = (index: string, address: string) => async (report: any) => {
try {
const axiosInstance = await refreshProxy(20000);
const axiosInstance = await refreshProxy();

axiosRetry(axiosInstance, {
retries: 3,
Expand Down
19 changes: 0 additions & 19 deletions src/packages/tx/index.ts

This file was deleted.

0 comments on commit dc38ca5

Please sign in to comment.