aelf Tech Talks — aelf Profit Contract Interpretation Pt 3

aelf Developer
aelf
Published in
9 min readMay 5, 2020

Token Holder contract: Lock in designated Tokens to share DApp profits

To achieve profit from DApp contracts for general users, developers will enter into the profit scheme. The scenario is set as follows: DApp releases its tokens in some way. For example, a token is called APP and can create a profit scheme through the Token Holder contract, contributing a certain portion of the profits to the profit scheme when the contract is profitable. Users holding APP Tokens can participate in the profit distribution of DApp developers during the locking period by locking app tokens based on token holder contract.

DApp developer interface: creating and managing profit schemes

Create and Manage profit schemes

In essence, the scheme directly uses the CreateScheme method in the profit contract. Considering that the scheme is to distribute profit to the holders and has the context of ‘the holders invest to obtain corresponding profit’, some parameter values are fixed, such as:

  • Is it the default to distribute profits on the General Ledger of all profit schemes each time you distribute profits? Yes.
  • Is it allowed to remove a profit beneficiary directly? Yes. (because the holder is not required to declare the length of the lock)

In addition to the creation of the corresponding profit scheme, in order to prevent the holders from knowing the profit distribution time in advance, they will be required to carry out a speculative lock up. The DApp contract is allowed to set the minimum lock in time of the holder and the value of automatic distribution when the General Ledger quota of the profit scheme triggers.

profit management plan

The implementation of the above interfaces is the application of the interface with the same name of the profile contract.

When managing profit beneficiaries, only one profit detail list of each beneficiary is reserved, that is to say, multiple lock positions of beneficiaries can be consolidated.

Interface used by the holder: lock up and receive profits

The name of the lock interface: Register For Profits。The only way to unlock is to provide DApp contract address.

As mentioned above, “when the General Ledger quota of the profit scheme triggers automatic distribution”, it is judged when the user locks the warehouse. The ‘DistributeProfits’ triggered here belongs to the inline transaction and does not require the holder to pay extra transaction fees.

When the holder unlocks, it will judge whether it has passed the minimum lock time set for the profit project.

Treasury contract:aelf main-chain profit pool

Construction of main chain profit pool

In the aelf main chain, the Treasury contract maintains these seven profit items, which are divided into three levels.

Level 1:Treasury

Treasury profit scheme:

  • Manager: Treasury contract
  • profit income source: the node produced blocks bonus
  • Revenue arrival and distribution time: when the main chain is successfully replaced, that is, at any time, the general ledger of the profit scheme is 0.
  • profit scheme beneficiary: none
  • sub-profit scheme:Miner Reward, Citizen Welfare, Backup Subsidy, 3 in total
  • shares:N/A

Level 2:Miner Reward,Citizen Welfare,Backup Subsidy

Miner Reward profit scheme:

  • Manager: Treasury contract
  • profit income source: Treasury profit scheme
  • Revenue arrival time and distribution time: every time the main chain is replaced successfully
  • profit scheme beneficiary: none
  • sub-profit scheme: Miner Reward, Citizen Welfare, Backup Subsidy, 3 in total
  • shares: 1/5 (accounting for the Treasury profit scheme)

Citizen Welfare profit scheme:

  • Manager: Election contract
  • profit income source: Treasury profit scheme
  • Revenue arrival time and distribution time: every time the main chain is replaced successfully
  • profit scheme beneficiary: Voters participating in node election and voting over a time period
  • sub-profit scheme: none
  • shares: 3/4 (accounting for the Treasury profit scheme)

Backup Subsidy profit scheme:

  • Manager: Election contract
  • profit income source: Treasury profit scheme;
  • Revenue arrival time and distribution time: every time the main chain is replaced successfully
  • profit scheme beneficiary: Candidate nodes whose votes are five times the number of current production nodes.
  • sub-profit scheme: none
  • shares: 1/20 (accounting for the Treasury profit scheme)

Level 3:Miner Basic Reward,Miner Votes Weight Reward,Re-Election Miner Reward

Miner Basic Reward profit scheme:

  • Manager: Treasury contract
  • profit income source: Miner Reward profit scheme
  • Revenue arrival time and distribution time: every time the main chain is replaced successfully
  • profit scheme beneficiary: All production nodes just finished this session
  • sub-profit scheme: none
  • shares: 2/4 (accounting for the Miner Reward profit scheme)

Miner Votes Weight Reward profit scheme:

  • Manager: Treasury contract
  • profit income source: Miner Reward profit scheme
  • Revenue arrival time and distribution time: every time the main chain is replaced successfully
  • profit scheme beneficiary: All production nodes just finished this session
  • sub-profit scheme: none
  • shares: 1/4 (accounting for the Miner Reward profit scheme)

Re-Election Miner Reward profit scheme:

  • Manager: Treasury contract
  • profit income source: Miner Reward profit scheme
  • Revenue arrival time and distribution time: every time the main chain is replaced successfull
  • profit scheme beneficiary: A production node that has a continuous record in the current production node
  • sub-profit scheme: none
  • shares: 1/4 (accounting for the Miner Reward profit scheme)

Note: the above shares can be changed later by using the SetDividendPoolWeightSetting and SetMinerRewardWeightSetting methods of the Treasury contract.

Construction and implementation of main chain profit pool

The construction process of the above three-level profit scheme in the Treasury contract is as follows:

Maintenance of related profit schemes of main chain profit pool

Increase Profit

Use The Treasury contract’s Donate method to add profit to the main chain bonus pool:

It is implemented in two steps:

  1. Transfer the specified number of tokens from the Sender to the Treasury contract through the token contract TransferFrom method. At this time, the Treasury contract has a certain balance.
  2. If the token is specified as ELF, the ELF balance (the balance added in the first step) of the Treasury will be directly transferred to the General Ledger of the Treasury Profit Scheme. Otherwise, the Token must be transferred to ELF through the Token Converter Contract before entering into the General Ledger of the Treasury Profit Scheme. However, if the designated Token has not been configured with a connector in the Token Converter, the designated Token will be transferred directly to the General Ledger of the Treasury Profit Scheme.

In order to realize the “transfer token to ELF through Token Converter Contract and then enter into the General Ledger of the Treasufy Profit Scheme”, the Donateall method is added:

So the implementation of ConvertToNativeToken is divided into two steps:

  1. Sell the non-ELF token;
  2. Use an inline transaction to call DonateAll, and fill in the ELF parameter.

The implementation of DonateAll also includes two steps:

  1. Check ELF balance
  2. Call the Donate method directly and fill in ELF and ELF balance.

Configure Sub Prefit Scheme and Beneficiary

For the second level of the profit pool, there are three profit schemes:

The beneficiary of Citizen Welfare is all voters. The shares of voters are determined by the number of votes and the lock-in time when they vote. They are maintained through the Election contract. The specific opportunities are Vote and Withdraw. For example, this is the code for adding corresponding shares to voters in the vote method:

The beneficiary of Backup Subsidy is all candidate nodes that claim to participate in the production node election (100000 elf needs to be mortgaged). Similar to Citizen Welfare, it is maintained in the AnnounceElection method and QuitElection method of the Election contract, and the shares of each candidate are fixed to 1:

There is no beneficiary in Miner Reward’s profit scheme, and the profit will be distributed to the three sub-profit schemes under the Treasury Contract immediately after it is received. That is to say, the three profit schemes of the third-level of the main-chain profit pool are maintained before and after each profit pool release: Before release, according to the actual number of blocks produced in the previous session, the shares that can receive profits under the Basic Miner Reward profit scheme of the previous production node will be configured. After release, the Miner Votes Weight Reward and Re-Election Miner Reward will be maintained according to the current number of votes and re-election of the new production node.

Before release:

After release:

Main-chain profit pool release

When the distribution time of the main-chain profit pool is changing, that is to say, the NextTerm method based on the AEDPoS Contract. The releasing logic lies in the release method of the Treasury Contract:

Of course, only the AEDPoS Contract can invoke this method:

— Join the Community:

· Get on our Telegram Discord Slack and Kakao channel

· Follow us on Twitter Reddit and Facebook

· Read weekly articles on the aelf blog

· Catch up with the develop progress on Github

· Telegram community in 한국, 日本 語, русский, العربية, Deutsch, Italiano and Tiếng Việt

· Instagram: aelfblockchain

· YouTube Channel: aelf

For more information, visit aelf.io

--

--