diff --git a/components/develop/modules/ROOT/pages/sfuel-gas-token.adoc b/components/develop/modules/ROOT/pages/sfuel-gas-token.adoc index 34c81ff8..876fb346 100644 --- a/components/develop/modules/ROOT/pages/sfuel-gas-token.adoc +++ b/components/develop/modules/ROOT/pages/sfuel-gas-token.adoc @@ -6,4 +6,81 @@ Getting sFUEL on a SKALE chain is done through a number of ways. Again because s The SKALE chain owner is allocated a massive amount of sFUEL and is responsible for distributing sFUEL to users in a way that's best served for their users' experience. Some SKALE chain owners choose to send sFUEL to each user who completes an onboarding event. Other owners choose to provide a sFUEL faucet, and others allow users to mine gas natively in a browser. See https://github.com/skalenetwork/pow-demo for an example of mining gas on SKALE. -For further develop details on distributing and developing with sFUEL, see xref:skale-chain-access-control.adoc[Access Control]. \ No newline at end of file +== Etherbase contract + +For SKALE chains launched after April 2022, the Etherbase predeployed contract stores and manages sFUEL received from block rewards and spent gas fees. At deployment, the SKALE Chain owner is assigned as the `DEFAULT_ADMIN_ROLE` and `ETHER_MANAGER_ROLE`. The owner can transfer these roles to other accounts, multisigs, or contracts. + +The contract is predeployed at: `0xd2bA3e0000000000000000000000000000000000` with ABIs available here: https://github.com/skalenetwork/etherbase/releases/download/1.0.0-stable.0/etherbase-1.0.0-stable.0-abi.json. + +Initial sFUEL allocation: + +* **Etherbase**: 5.79e+58 sFUEL +* **SKALE Chain Owner**: 1e+12 sFUEL + +Two methods are available: + +* *retrieve(receiver)* - Retrieve the entire sFUEL balance in Etherbase to receiver address. +* *partiallyRetrieve(receiver, amount)* - retrieve an amount of sFUEL in Etherbase to the receiver address. + +== Etherbase Solidity usage example + +The following example illustrates how you can incorporate an automatic top-up modifier to ensure users have sufficient sFUEL to transact. + +NOTE: Example assumes that users have already been provisioned some initial sFUEL. + + +``` +pragma solidity ^0.8.0; + +interface IEtherbase { + receive() external payable; + function retrieve(address payable receiver) external; + function partiallyRetrieve(address payable receiver, uint amount) external; +} + +contract EtherbaseUsage { + + uint256 MIN_AMOUNT = 1000000000000000; + + modifier topUp { + if (msg.sender.balance < MIN_AMOUNT) { + partiallyRetrieve(payable(msg.sender), MIN_AMOUNT); + } + _; + } + + function retrieve(address payable receiver) public { + getEtherbase().retrieve(receiver); + } + + function partiallyRetrieve(address payable receiver, uint amount) public { + getEtherbase().partiallyRetrieve(receiver, amount); + } + + function sendToEtherbase() public payable { + getEtherbaseAddress().transfer(msg.value); + } + + function getEtherbase() public pure returns (IEtherbase) { + return IEtherbase(getEtherbaseAddress()); + } + + function getEtherbaseAddress() public pure returns (address payable) { + return payable(0xd2bA3e0000000000000000000000000000000000); + } +} + +contract YourContract is EtherbaseUsage { + + function yourFunction(address payable receiver, uint amount) external payable topUp { + partiallyRetrieve(receiver, amount); + retrieve(receiver); + sendToEtherbase(); + } +} + +``` + +NOTE: YourContract example above must be granted with ETHER_MANAGER_ROLE. + +For further develop details on distributing and developing with sFUEL, see xref:skale-chain-access-control.adoc[Access Control].