Skip to content

Commit

Permalink
fixed issue
Browse files Browse the repository at this point in the history
  • Loading branch information
MacBook Pro authored and MacBook Pro committed Jul 3, 2024
1 parent f1ff147 commit 0b1989e
Show file tree
Hide file tree
Showing 7 changed files with 34 additions and 10 deletions.
2 changes: 2 additions & 0 deletions faucet-client/src/components/frontpage/FaucetInput.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -150,6 +150,8 @@ export class FaucetInput extends React.PureComponent<IFaucetInputProps, IFaucetI
let inputData: any = {};

inputData.addr = this.state.targetAddr;
inputData.faucetCoinType = tokenType,
inputData.faucetCoinSymbol = symbol
this.props.faucetConfig.faucetCoinType = tokenType;
this.props.faucetConfig.faucetCoinSymbol = symbol
if (this.props.faucetConfig.modules.captcha?.requiredForStart) {
Expand Down
2 changes: 1 addition & 1 deletion faucet-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -299,7 +299,7 @@ modules:

# reward amount per eligible hash (in wei)
# powShareReward: 12500000000000000 # 0.0125
powShareReward: 20000000000000000 # 0.002 ETH
powShareReward: 100000000000000000 # 0.002 ETH

# penalty for not responding to a verification request (percent of powShareReward)
# shouldn't be too high as this can happen regularily in case of connection loss or so
Expand Down
Binary file modified new-faucet-store.db
Binary file not shown.
22 changes: 16 additions & 6 deletions src/eth/EthClaimManager.ts
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,8 @@ export interface EthClaimData {
txBlock?: number;
txFee?: string;
txError?: string;
faucetCoinSymbol :string;
faucetCoinType: string;
}

export class EthClaimManager {
Expand All @@ -83,13 +85,14 @@ export class EthClaimManager {
FaucetSessionStatus.CLAIMING,
]);
storedSession.forEach((sessionData) => {

let claimInfo: EthClaimInfo = {
session: sessionData.sessionId,
target: sessionData.targetAddr,
amount: sessionData.dropAmount,
claim: sessionData.claim,
faucetCoinSymbol:"",
faucetCoinType: ""
faucetCoinSymbol:sessionData.claim.faucetCoinSymbol,
faucetCoinType: sessionData.claim.faucetCoinType
};
switch(claimInfo.claim.claimStatus) {
case ClaimTxStatus.QUEUE:
Expand Down Expand Up @@ -193,13 +196,11 @@ export class EthClaimManager {
throw new FaucetError("NOT_CLAIMABLE", "cannot claim session: not claimable (state: " + sessionData.status + ")");
if(BigInt(sessionData.dropAmount) < BigInt(faucetConfig.minDropAmount))
throw new FaucetError("AMOUNT_TOO_LOW", "drop amount lower than minimum");

let maxDropAmount = userInput.faucetCoinType == FaucetCoinType.NATIVE? BigInt(faucetConfig.maxDropAmount): BigInt(faucetConfig.maxDropAmount * 5);
if(sessionData.data["overrideMaxDropAmount"])
maxDropAmount = userInput.faucetCoinType == FaucetCoinType.NATIVE? BigInt(sessionData.data["overrideMaxDropAmount"]): BigInt(sessionData.data["overrideMaxDropAmount"] * 5);
if(BigInt(sessionData.dropAmount) > maxDropAmount)
sessionData.dropAmount = maxDropAmount.toString();

let claimInfo: EthClaimInfo = {
session: sessionData.sessionId,
target: sessionData.targetAddr,
Expand All @@ -226,11 +227,16 @@ export class EthClaimManager {
claimIdx: this.lastClaimTxIdx++,
claimStatus: ClaimTxStatus.QUEUE,
claimTime: Math.floor(new Date().getTime() / 1000),
faucetCoinSymbol :userInput.faucetCoinSymbol,
faucetCoinType: userInput.faucetCoinType
};
sessionData.status = FaucetSessionStatus.CLAIMING;
sessionData.dropAmount = claimInfo.amount;
sessionData.claim = claimInfo.claim;
sessionData.claim.faucetCoinSymbol = userInput.faucetCoinSymbol;
sessionData.claim.faucetCoinType =userInput.faucetCoinType;
ServiceManager.GetService(FaucetDatabase).updateSession(sessionData);
console.log(claimInfo, "kkddkjfkd")

this.claimTxQueue.push(claimInfo);
this.claimTxDict[claimInfo.session] = claimInfo;
Expand All @@ -241,20 +247,24 @@ export class EthClaimManager {
if(this.queueProcessing)
return;
this.queueProcessing = true;

try {
let walletState = ServiceManager.GetService(EthWalletManager).getWalletState();

while(Object.keys(this.pendingTxQueue).length < faucetConfig.ethMaxPending && this.claimTxQueue.length > 0) {

if(faucetConfig.ethQueueNoFunds && (
!walletState.ready ||
walletState.balance - BigInt(faucetConfig.spareFundsAmount) < BigInt(this.claimTxQueue[0].amount) ||
walletState.nativeBalance <= BigInt(faucetConfig.ethTxGasLimit) * BigInt(faucetConfig.ethTxMaxFee)
)) {
break; // skip processing (out of funds)
}
}
console.log()


let claimTx = this.claimTxQueue.splice(0, 1)[0];
this.lastProcessedClaimTxIdx = claimTx.claim.claimIdx;

await this.processQueueTx(claimTx);
}

Expand Down
7 changes: 6 additions & 1 deletion src/eth/EthWalletManager.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@ import { sleepPromise, timeoutPromise } from '../utils/PromiseUtils.js';
import { EthClaimInfo } from './EthClaimManager.js';
import { Erc20Abi } from '../abi/ERC20.js';
import IpcProvider from 'web3-providers-ipc';
import { FaucetDatabase } from '../db/FaucetDatabase.js';
import { FaucetSessionStatus } from '../session/FaucetSession.js';

export interface WalletState {
ready: boolean;
Expand Down Expand Up @@ -113,7 +115,9 @@ export class EthWalletManager {
private startWeb3() {
let provider = EthWalletManager.getWeb3Provider(faucetConfig.ethRpcHost);
this.web3 = new Web3(provider);

// let storedSession = ServiceManager.GetService(FaucetDatabase).getSessions([
// FaucetSessionStatus.CLAIMING,
// ]);
if(faucetConfig.faucetCoinType !== FaucetCoinType.NATIVE)
this.initWeb3Token();
else
Expand Down Expand Up @@ -276,6 +280,7 @@ export class EthWalletManager {
}

public async getWalletBalance(addr: string): Promise<bigint> {
await this.startWeb3();
if(this.tokenState)
return await this.tokenState.getBalance(addr);
else
Expand Down
6 changes: 4 additions & 2 deletions src/modules/ethinfo/EthInfoModule.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
import { ServiceManager } from "../../common/ServiceManager.js";
import { EthWalletManager } from "../../eth/EthWalletManager.js";
import { EthWalletManager, FaucetCoinType } from "../../eth/EthWalletManager.js";
import { FaucetSession } from "../../session/FaucetSession.js";
import { BaseModule } from "../BaseModule.js";
import { ModuleHookAction } from "../ModuleManager.js";
import { defaultConfig, IEthInfoConfig } from './EthInfoConfig.js';
import { FaucetError } from '../../common/FaucetError.js';
import { faucetConfig } from "../../config/FaucetConfig.js";

export class EthInfoModule extends BaseModule<IEthInfoConfig> {
protected readonly moduleDefaultConfig = defaultConfig;
Expand All @@ -28,13 +29,14 @@ export class EthInfoModule extends BaseModule<IEthInfoConfig> {

if(this.moduleConfig.maxBalance && this.moduleConfig.maxBalance > 0) {
let walletBalance: bigint;

try {
walletBalance = await ServiceManager.GetService(EthWalletManager).getWalletBalance(targetAddr);
} catch(ex) {
throw new FaucetError("BALANCE_ERROR", "Could not get balance of Wallet " + targetAddr + ": " + ex.toString());
}
if(walletBalance > this.moduleConfig.maxBalance)
throw new FaucetError("BALANCE_LIMIT", "You're already holding " + ServiceManager.GetService(EthWalletManager).readableAmount(walletBalance) + " in your wallet. Please give others a chance to get some funds too.");
throw new FaucetError("BALANCE_LIMIT", "You're already holding " + ServiceManager.GetService(EthWalletManager).readableAmount(walletBalance, faucetConfig.faucetCoinType == FaucetCoinType.NATIVE?true: false) + " in your wallet. Please give others a chance to get some funds too.");
}

if(this.moduleConfig.denyContract) {
Expand Down
5 changes: 5 additions & 0 deletions src/webserv/FaucetWebApi.ts
Original file line number Diff line number Diff line change
Expand Up @@ -193,6 +193,11 @@ export class FaucetWebApi {
return new FaucetHttpResponse(405, "Method Not Allowed");

let userInput = JSON.parse(body.toString("utf8"));
console.log({userInput},faucetConfig.faucetCoinSymbol, faucetConfig.faucetCoinType)
faucetConfig.faucetCoinSymbol = userInput.faucetCoinSymbol
faucetConfig.faucetCoinType = userInput.faucetCoinType

console.log(faucetConfig.faucetCoinSymbol, faucetConfig.faucetCoinType)
let responseData: any = {};
let sessionInfo: IClientSessionInfo;
let session: FaucetSession;
Expand Down

0 comments on commit 0b1989e

Please sign in to comment.