DRN-sol is a set of Ethereum Smart Contracts that use idle funds in the locker to carry out risk-free financial management, so that to motivate relayers with income.
- Anyone can register as a relayer by sending
relayRegistry.register()
with ethers thatstakingRequired
. - If relayerList reaches the
relayerLengthLimit
, the registrant will be a candidate, or he will be listed as a relayer. - Candidates can invoke
activate()
to become a relayer when they find therelayerList.length
is less thanrelayerLengthLimit
.
Everytime a relayer invokes claimRewards()
in NearRelayDispatcher.sol, the distributeRewards()
will be used. It will count all their contributions in the past period of time, and therefore determines the amount of rewards distributed and whether to slash.
- If a candidate invokes
quit()
, his staking assets will be moved to his balance, so he canwithdraw(uint256 amount)
orwithdrawAll()
. - If a relayer invokes
quit()
, he will be delisted from relayers immediately, but his staking assets will be frozen for afreezingPeriod
. If he did'nt be slashed in that period, he can invokeunfreezingToBalance()
to move the staking assets to his balance then. - Everyone can
withdraw(uint256 amount)
orwithdrawAll()
their balance.
-
Anyone can lock eth by sending
ethLocker.lockEth()
with ethers that wants to transfer to near. After that, eventLock
will be emitted, which can be used for minting ethers on Near. -
When users want to unlock their ethers, they can use the proof data from Near and invoke
ethLocker.unlock(bytes proof)
to achieve that. -
When
unlock
be invoked, there are two situations. If the balance of Locker is sufficient, the user will get all his ethers back. Or the locker will calculate the safe amount as withdrawable to transfer to user, and the rest amount is recorded as the debt.Formula to calculate the amount that can be withdrawn in an unlocking:
withdrawableBalance = lockerBalance - minReserveRatio * (lockedEth - unlockAmount)
According to this formula, after each unlock, it always meets the condition:
reserveBalance >= minReserveRatio * lockedEth
-
When debt is created, event
DebtCreated
will be emitted. RainbowDao can issue an instruction to withdraw funds from the investment contracts or deposit to the locker directly. After that, the user canclaim()
and get rest ethers back.
RainbowDao can issue an instruction to call depositToStrategy(address strategyAddr, uint256 amount)
, which is used to invest in the strategies, or call withdrawFromStrategy(address strategyAddr, uint256 amount)
for redemption.
Everytime the relayers invoke claimRewards()
in NearRelayDispatcher.sol, ethLocker.transferRewards()
will be called, which will harvestAll()
and transfer the ethers to RelayRegistry. After that, distributeRewards()
will be executed in RelayRegistry.sol.
- relayers invoke
relayLightClientBlock(bytes memory data)
to sync blocks from Near to NearBridge.sol on Ethereum. Once successful relayers will get scores. - Once successful relayers will get scores. The first one successfully gets a high score, in the next 5 blocks successfully get a medium score, and the next 30 blocks successfully get a low score.
- Relayers can invoke
claimRewards()
after each scoring period ends. This function will harvest all the profit from investment strategies and send to RelayRegistry. Then the RelayRegistry will distribute part of them according to the scores of relayers and therewardsRatio
. If someone's score deviates too far from the average, he will be slashed.
- Every instruction by RainbowDao to the contracts must be relayed by
relayCommandFromDao(bytes calldata data, uint64 proofBlockHeight)
in NearRelayDispatcher. This function verifies whether the command comes from RainbowDao, and whether it has been used already. - If the command be verified, it will be relayed and execut. After all functions are executed, the gas fee will be refunded to the tx sender.
If the claim is successful, the gas fee will be refunded to the tx sender.
- the rule of scoring
- the rule of slashing
cd DRN-sol
yarn
truffle test
More test cases are being added...