Guides/EVM/Precompiles

Gamma

Reference for the deployed GammaPrecompile.

View as Markdown
PropertyValue
Rust implementationGammaPrecompile
Solidity interfaceIGamma
Address0x0000000000000000000000000000000000000814
StatusDeployed

Mints, holds, moves, sends and spends gamma, and lists services. Every state-changing function dispatches its extrinsic as the caller's mapped account and is non-payable. TAO amounts are in rao, alpha amounts in alpha rao, and gamma amounts in gamma units (10^9 per US dollar). An optional argument is a has… flag and its value; the value is ignored when the flag is false.

Operations

FunctionSource extrinsicThe caller is
mintGamma(bytes32,uint16,uint64,uint64,bool,uint64)SubtensorModule.mint_gammathe coldkey paying the TAO
mintGammaWithStake(bytes32,bytes32,uint16,uint64,uint64,bool,uint64)SubtensorModule.mint_gamma_with_stakethe coldkey owning the stake
moveGamma(bytes32,bytes32,uint16,uint64)SubtensorModule.move_gammathe deposit's coldkey
closeGammaDeposit(bytes32,uint16)SubtensorModule.close_gamma_depositthe deposit's coldkey
setGammaDepositDailySpendCap(bytes32,uint16,bool,uint64)SubtensorModule.set_gamma_deposit_daily_spend_capthe deposit's coldkey
depositGamma(bytes32,uint16,uint64,bool,uint64)SubtensorModule.deposit_gammathe coldkey holding the balance
withdrawGamma(bytes32,uint16,uint64)SubtensorModule.withdraw_gammathe deposit's coldkey
transferGamma(bytes32,bool,bytes32,bool,bytes32,uint16,uint64)SubtensorModule.transfer_gammathe sending coldkey
spendGamma(bytes32,uint16,uint64)SubtensorModule.spend_gammathe deposit's hotkey
setService(uint16,bytes32,string)SubtensorModule.set_servicethe hotkey's coldkey

A mint gives at least 0.1 gamma or fails. moveGamma, depositGamma and withdrawGamma take up to the amount given: the whole source, or at least 0.1 gamma leaving at least as much. transferGamma sends exactly the amount, to another coldkey: at least 0.1 gamma, leaving none or at least as much. Emptying a deposit this way closes it; a spend that empties it leaves it open at 0. These functions return nothing; read what a call credited with getGammaDeposit or getGammaBalance.

A daily spend cap is 0, which pauses the deposit, or at least 0.1 gamma. A move to a hotkey with no deposit opens one with the origin's cap, and a move from a capped deposit into one with a looser cap, or with none, fails with GammaDepositDailySpendCapMismatch. A transfer to a hotkey with no deposit opens one for the receiver, with no cap. A spend is at least 0.1 gamma unless it empties the deposit, within what the daily spend cap allows now, at a hotkey that has a service on the subnet. A spend from the EVM costs gas, while the native spend_gamma pays no fee; it emits the same GammaSpent event, so services credit it like any other spend, to the caller's mapped account. A refused runtime dispatch reverts with no return data, so a contract cannot read which error it was, and consumes the gas forwarded to the precompile.

Minting for a user

A contract mints into its own deposit and sends what the deposit holds to the user's deposit. If the transfer fails, the revert undoes the mint as well. Use a pool hotkey owned on-chain by the contract's mapped account. Transferring the full balance closes the deposit, and hotkey ownership keeps the slot reserved for the contract when it reopens. If the pool hotkey is unowned, fund the deposit first, keep at least 0.1 gamma in it across calls, and send only what the mint added.

IGamma gamma = IGamma(IGAMMA_ADDRESS);
gamma.mintGamma(poolHotkey, netuid, amountRao, minGammaOut, false, 0);
(, , uint64 minted, , , ) = gamma.getGammaDeposit(netuid, poolHotkey);
gamma.transferGamma(user, true, poolHotkey, true, userHotkey, netuid, minted);

The deposit opens with no daily spend cap if the user has none at that hotkey, unless another coldkey owns the hotkey or holds a deposit there. A contract can open one for a user only while the user holds fewer than 32 deposits across subnets, and not while the user's coldkey swap is announced or disputed, or while the user is the reserved destination of one; sending to an open deposit, or with no hotkey to the user's balance, is not limited.

Hashed account aliases

Registering a hashed account's EVM alias moves the gamma balances of the address's previous mapped account to the registered account. It is refused while that mapped account owns a deposit, as while it holds stake, so register a hashed key before sharing its address. Gamma credited to the previous mapped account after registration is not moved.

Views

FunctionReturns
getGammaDeposit(uint16,bytes32)(exists, coldkey, balance, hasDailySpendCap, dailySpendCap, spendable) of the deposit at a hotkey
getGammaDepositHotkeys(uint16,bytes32)the hotkeys holding a coldkey's deposits, at most 64
getGammaBalance(uint16,bytes32)a coldkey's gamma held at no hotkey
getGammaSpent(uint16,bytes32,bytes32)the gamma a hotkey has spent at a service
getService(uint16,bytes32)(exists, url) of a hotkey's service
getGammaEnabled()whether gamma is on network-wide
simMintGamma(uint16,uint64)(alpha, value, gamma) a mint of an amount of TAO would give now
simMintGammaWithStake(uint16,uint64)(alpha, value, gamma) a mint of an amount of alpha would give now

spendable is what the hotkey can spend now: the balance within what the daily spend cap allows, or 0 when that is below the 0.1 gamma spend minimum and short of the balance. Whether gamma is on for a subnet is ISubnet.getSubnetGammaEnabled.

A simulation quotes the amount at the subnet's current pool and fails where the mint would, except that only the mint checks the caller's TAO or stake, the deposit and minAmountOut, and mintGammaWithStake prices the stake it actually burns, at most the caller's. A simulation is charged the mint's dispatch weight; the mint from the EVM also pays for the caller mapping.

The oracle's feed_tao_usd_price and the Root-only gamma settings are not exposed.

Source: gamma.sol