Reference
StageSale API
Key read and write methods exposed by the on-chain StageSale contract used by the BATACoin dApp.
Read functions
quoteTokensByUSDT(stage, usdtAmount)→ returns the token amount for a given USDT (18 decimals) input. Rounding: floor.quoteCostUSDT(stage, tokenAmount)→ returns the USDT (18 decimals) cost for a token amount. Rounding: ceil.price(stage)→ stage price in 18 decimals.perWalletCap(stage)→ max purchasable tokens per wallet for the stage (18 decimals).minPurchase(stage)→ minimum purchasable tokens for the stage (18 decimals).purchased(stage, account)→ tokens already purchased by an account for the stage (18 decimals).startAt(stage)/endAt(stage)→ UNIX seconds window.stagePaused(stage)→ returns whether the stage is paused.
Write functions
buyByUSDT(stage, usdtAmount, minTokens, proof)→ buys tokens for a USDT amount. Requires prior USDT approval to the sale contract.buyExactTokens(stage, tokenAmount, maxUsdt, proof)→ buys an exact token amount, spending up to maxUsdt.
Notes: USDT must have 18 decimals. Whitelist proofs may be required depending on the stage. Reverts outside of the stage window or when paused.
Rounding rules
- Cost (USDT) is rounded up (ceil) to ensure sufficient allowance.
- Quoted tokens are rounded down (floor) to avoid over-allocation.
Integration tips
- Approve USDT to the sale contract for at least the quoted cost before calling a buy function.
- Respect perWalletCap and minPurchase from the contract to avoid unnecessary reverts.
- Use the quote helpers for user previews; rely on transaction receipts to confirm purchases.