Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Draft etherbase #32

Merged
merged 5 commits into from
Apr 19, 2022
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
79 changes: 78 additions & 1 deletion components/develop/modules/ROOT/pages/sfuel-gas-token.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -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].
== 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.
cstrangedk marked this conversation as resolved.
Show resolved Hide resolved


```
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].