turnley.dev

PHP and MySQL code for faucet operators

Tools & Calculators

PRC-004

Keep rewards worth the same in dollars as the coin moves

Store the reward in USD, convert at claim time, and clamp the movement so a price spike cannot empty the faucet in an afternoon.

A reward fixed in satoshi is a reward whose real value drifts with the market. Users notice when it falls and your budget notices when it rises.

Storing the target in dollars and converting at claim time holds the value steady. The risk is the other direction: a sudden price move recalculates every reward at once, and a faucet configured for a quiet market can drain fast.

Clamping the conversion against a floor and ceiling keeps the intent while capping the damage. The reward tracks the dollar target within a band and stops outside it.

PHP
function claim_reward_units(float $targetUsd, string $coinId, int $unitsPerCoin): array
{
    $feed = coin_price($coinId);
    if ($feed['price'] <= 0 || $feed['age'] > 900) {
        // No trustworthy price: fall back to the configured unit floor rather
        // than guessing, and flag it so the operator can see it happening.
        return ['units' => setting_int('reward_units_floor', 1), 'pegged' => false, 'reason' => 'stale price'];
    }

    $units = (int) floor(($targetUsd / $feed['price']) * $unitsPerCoin);

    $floor = setting_int('reward_units_floor', 1);
    $ceil  = setting_int('reward_units_ceiling', PHP_INT_MAX);

    $clamped = max($floor, min($ceil, $units));

    return [
        'units'   => $clamped,
        'pegged'  => $clamped === $units,
        'price'   => $feed['price'],
        'reason'  => $clamped === $units ? 'on target' : ($clamped === $ceil ? 'capped at ceiling' : 'raised to floor'),
    ];
}

Using it

Show the dollar value next to the coin amount in the interface. It is what makes a shrinking satoshi figure understandable rather than alarming.

Set the ceiling from what the faucet can afford per day divided by expected claims, not from a round number.

Record the price used on each claim. Without it, a week of unusual payouts cannot be explained afterwards.

What bites people

Clamping silently is worse than clamping visibly. Log it and surface it in admin, or a capped reward looks like a bug to whoever is watching the numbers.

The floor must be at least one unit. A reward that rounds to zero is a claim that appears to succeed and pays nothing.

This one touches real money. Point it at a throwaway wallet and watch a full cycle before you trust it with a live balance.

Also in Price Feeds