The Swap feature allows users to instantly exchange between the internal Token and supported Cryptocurrencies, or between different Cryptocurrencies.
- Token to Coin: Convert earnings to crypto (e.g., Token -> BTC).
- Coin to Token: Convert crypto deposits to internal tokens (e.g., for purchasing Mining Plans).
- Coin to Coin: Exchange between distinct cryptocurrencies (e.g., BTC -> LTC).
- Rate Source: Real-time prices fetched via
PriceService(CoinGecko/Binance API) and stored incoinstable. - Fee: Fixed 2.0% protocol fee on all swaps.
- Minimum: Transactions must have a value of at least $1.00 USD.
ValueUSD = Amount * SourcePrice
FeeUSD = ValueUSD * 0.02
NetValueUSD = ValueUSD - FeeUSD
TargetAmount = NetValueUSD / TargetPrice
-
Atomic Swaps:
- Uses a single database transaction to Deduct Source and Credit Target.
- Ensures funds are never lost in transit; if one step fails, the entire swap rolls back.
-
Validation:
- Checks:
isActiveandisSwapEnabledflags on coins. - Balance checks using
FOR UPDATE(implicit in scalar updates) or pre-checks.
- Checks:
- Action:
app/(protected)/swap/actions.ts->performSwap. - Models:
swaps(History),wallets,coins.
