hubiinetwork / nahmii-contracts Goto Github PK
View Code? Open in Web Editor NEWSmart contracts for 1st generation Nahmii 2nd layer scaling solution for Ethereum
Smart contracts for 1st generation Nahmii 2nd layer scaling solution for Ethereum
Both Exchange and AntiFraud work with operational mode, a property that is more global than those two contracts. Configuration contract should thus manage this property rather than Exchange and AntiFraud. The latter will eventually set operational mode to Exit after which operation it may not be reset to Normal. The former will read operational mode.
This issue is currently not represented in the Omphalos specification.
Implement challenge of fraudulent deal by trade in Exchange smart contract according to section ChallengeFraudulentDealByTrade.
The DSC challenge functions (challengeByOrder()
, unchallengeOrderCandidateByTrade()
, challengeByTrade()
and challengeByPayment()
) should check whether the provided challenge candidate is deemed fraudulent in the FC. If deemed fraudulent the challenge attempt should revert.
Implement initial pieces of Reserve fund smart contract according to section Reserve fund fund in specification (v0.12).
The initial pieces required are the ones that deal with updating balance blocks (Fallback function and DepositToken()) and calculation of aggregate balance blocks in range of block numbers (BalanceBlocksIn()).
The Reserve fund is where clients may make deposits and earn share of revenue relative to their contribution.
There will likely be 2 instances deployed of this smart contract, one for trade reserves and one for payment reserves. If this were to happen there will also be two instances deployed of the Revenue fund (#8), one for trade revenues and one for payment revenue. Each of the two reserve fund instances of this issue will then be a beneficiary of the revenue fund corresponding to the same deal type.
The amount to be staged after a settlement is closely bound to the amount settled and the balance of the driip settled. Thus the amount to be staged should be introduced into the driip settlement challenge.
Also settlement functions only should call ClientFund.stage
function. Wallets should be prevented from calling this function directly.
Based on Slack conversation with Mark where he stated:
Thinking about this thing we missed about settlement. I guess we were guilty of assuming that it would always be the person with a positive net balance settling. However, obviously that's not the case. I can't help but think it might be a very simple fix though. I may be missing something though. My suggestion would be simply to make SettleDeal() always move funds for the caller, for that currency to the staged balance... No matter which direction the net change is in. I feel like there would be no problem with this... Security would still function exactly the same way.
Current exchange contract is getting too big, requiring more than 6m gas to deploy. Anti-fraud logics should be factored out into separate AntiFraud contract.
This issue is currently not represented in the Omphalos specification.
ClaimAccrual()
in ReserveFund must have a boolean parameter for compounding earned accrual (i.e. add to active balance) or not (i.e. add to staged balance). Currently ClaimAccrual()
does not allow compounding. It is suggested that the parameter be named compoundAccrual
. A value of true
will thus increment active balance and false
will increment staged balance.
This issue is currently not represented in the Omphalos specification.
Implement Community vote smart contract according to section Community vote in specification (v0.12).
The Community vote smart contract is an oracle for relevant decisions made by the community.
The great number of contracts that external clients (e.g. Hubii Core) will be able to interact with should be presented to clients in a consistent manner. This is particularly relevant for all fraud challenge contracts.
Configuration contract may be updated with functionality to host overview of deployed contracts. Alternatively Migrations contract may be augmented with the required features.
@mxmauro had some thoughts on this
yes but we have two options here:
- if the dapp only calls 1 or 2 fraud SCs, they can be configured by a call to something like
setFraudChallengeXXXAddress
- if the dapp needs to call any fraud SC based on some logic, then we need to implement something like
getFraudChallengeXXXAddress(string typeOfFraudChallegeRequested)
to get the address dynamically and do the call. But this logic can be also added to the configuration SC
With the advent of AntiFraud contract that relies on many of the same compound data structures, enums and hash functions these should be factored out of Exchange and AntiFraud into separate library to be imported into both contracts.
This issue is currently not represented in the Omphalos specification.
RevenueToken smart contract should have properties for name
and symbol
. Also totalSupply
should be public. All these properties should be adjustable.
Finally the token contract also needs to allow for subdivisions and subdenominations by having decimals
. Like HBT contract it should have 15 decimals, thus one unit of the token should equal 10^15 subunits.
When RevenueToken has the mentioned public and adjustable properties.
Replace the use of uintX
by intX
in monetary values in Exchange contract.
It is beneficial to a allow partners to charge extra fees on top of Hubii's fees applied to trades and payments.
The suggested first half of the implementation describes the implementation of a new contract called PartnerFund with the following main features:
DepositTokens()
function will receive fees from Exchange and ReserveFund contracts, each transfer identified by partnerTag
value.SetPartnerAddress()
function will update mapping of partnerTag
to partner address.Stage()
function will be callable by partner to stage their active balance (of revenue) in preparation for withdrawal.WithdrawEther()
/WithdrawTokens()
function will be callable by partner to transfer from staged balance to partner's address.This issues does not include the implemention of interaction with PartnerFund during settlement of driips, the description which is found in #175.
This issue was created based on the following description by @markbkk:
The ability for us to add an "additional partner specified fee" over and above the based striim fee. I believe this should be expressed as an additional % over the main fee combined with volume discounts. So if partner P wants to charge double the fee as Striim itself does, then they would set a figure of 200%. If striim was charging "0.1% - volume discount" for a payment of 1,000 ETH, then partner P would add on 200% and so the overall fee would be "(1 + 200%) * (0.1% - volume discount)".
Complete implementation of Reserve fund smart contract according to section Reserve fund fund in specification (v0.12).
The Reserve fund is where clients may make deposits and earn share of revenue relative to their contribution.
There will likely be 2 instances deployed of this smart contract, one for trade reserves and one for payment reserves. If this were to happen there will also be two instances deployed of the Revenue fund (#8), one for trade revenues and one for payment revenue. Each of the two reserve fund instances of this issue will then be a beneficiary of the revenue fund corresponding to the same deal type.
The current code base is geared towards ERC20. Additional non-ERC20 tokens, non-fungible ones such as ERC721 and ERC1155 as well as fungible ones, may be of interest in the future.
The outcome of this issue is to suggest changes needed in the code base to be able to support new tokens smart contracts. Such a support naturally suggests modularity in the way striim contracts interfaces token contracts.
Currently if driip settlement challenge result is Disqualified
the funds of the settling wallet (msg.sender
of settleDriipAsTrade()
/settleDriipAsPayment()
or wallet
if called by owner) is seized, even if the settling wallet was not the driip party causing overrun and thus Disqualified
challenge result.
Rather settleDriipAsTrade()
/settleDriipAsPayment()
should only seize funds of the settling wallet if the driip causes overrun for that particular wallet.
A driip settlement challenge may indeed find overrun for both driip parties, but if only one party is settling this settlement should not seize the funds of the other party.
Exchange.settleDriipAsTrade()
and Exchange.settleDriipAsPayment()
only triggers fund seizure when settling wallet was found to overrun by DSC.Import features from DexTrade that are useful according to Exchange specification (v0.12).
Implement challenge of fraudulent deal by trade order residual in Exchange smart contract according to section ChallengeFraudulentDealByTradeOrderResidual.
Replace the use of uintX
by intX
in monetary values in ReserveFund contract.
Implement the following features:
Current implementation has one revenue fund for trades and payments combined. The use of this one revenue fund will have to be split in two.
Fee setters will only accept block number larger than the current block number on the network.
In client fund smart contract add functions Withdrawal(wallet: w, index: i)
and WithdrawalCount(wallet: w)
. These are complementary to Deposit(wallet: w, index: i)
and DepositCount(wallet: w)
.
Withdrawal(wallet: w, index: i)
returns stats about withdrawal at index i
from the staged balance of wallet w
.
WithdrawalCount(wallet: w)
returns the number of withdrawals by wallet w
.
Withdrawal(wallet: w, index: i)
and WithdrawalCount(wallet: w)
are implementedWithdrawal(wallet: w, index: i)
and WithdrawalCount(wallet: w)
are implementedThis implementation is not included in the Omphalos specification.
Implement Configuration smart contract according to section Configuration in specification (v0.12).
The Configuration smart contract is an oracle for configuration values such as fees, challenge timeouts, stake size and possibly more.
Implement challenge of double spent order in Exchange smart contract according to section ChallengeDoubleSpentOrder.
Implement Exchange smart contract according to section Revenue fund in specification (v0.12).
The Exchange smart contract is the orchestrator of trades and payments on-chain including a.o. settlements and challenges.
The bulk of code for this smart contract can be factored out from previous Trade smart contract.
Implement Security bond smart contract according to section Security bond fund in specification (v0.12).
The Security bond contains crypto incentive for function specified as UnchallengeDealSettlementOrderByTrade()
.
Implement settle deal in Exchange smart contract according to section SettleDeal.
Implement challenge of fraudulent deal by payment in Exchange smart contract according to section ChallengeFraudulentDealByPayment.
The 6 fee block number arrays are currently not sorted. Although naturally the addition of new fees values are likely to happen in block number incremental order it is not required. Thus the update of fee values should assure that the corresponding fee block number array is kept sorted.
This is a left-over from #44.
Payments fees need to be defined per currency. Thus getters and setters of payment fees in Configuration contract need the address of currency as parameter. And Exchange contract's retrieval of payment fees need to pass currency address as argument. (Currency address 0 is ETH.)
This issue is currently not represented in the Omphalos specification.
A new instance of SecurityBond contract must be created. This contract will act as data availability bond with higher beneficiary fraction than SecurityBond.
A certain number of features in FraudChallenge
contract have been left commented out in order to prevent out-of-gas exception when deploying. Pieces of code that needs to be uncommented are labeled // TODO Enable when deployment out-of-gas is solved
.
This is left-over from #75.
Implement Token holder revenue fund smart contract according to section Token holder revenue fund fund in specification (v0.12).
The Token holder revenue fund manages the revenue earned by revenue token holders.
Exchange contract's settleDriipAsTrade()
and settleDriipAsPayment()
should check that (hash of) driip that is being settled has not been flagged as fraudulent by FraudChallenge contract.
settleDriipAsTrade()
and settleDriipAsPayment()
in Exchange does no settle fraudulent driipIt should be possible to transfer funds from ReserveFund to ClientFund. This implementation is close to identical to the one of #55. A suggested implementation goes as follows:
StageTo()
to ReserveFund. Albeit very similar to existing Stage()
function StageTo()
will take an additional parameter of target address. When called in order to transfer to ClientFund the target address argument will have the value of the address of (trade or payment) ClientFund instance.Beneficiary
interface Beneficiary {
function DepositEther(address: b, amount: a) public payable;
function DepositTokens(address: b, amount: a, token: t) public;
}
DepositTokens()
already does. The new DepositEther()
will be very much identical to the ClientFund fallback function. Only where fallback function works with balances of msg.sender the new function will rather work with balances of address b. Core logics of fallback function should be factored out into new internal function that can be called both by fallback function as well as by DepositEther()
function.This issue is currently not represented in the Omphalos specification.
Functional support in ClientFund needed that takes all deposited and settled funds of one wallet and moves it to staged wallet of another. This function will be used to seize balances from wallets whose deals are deemed fraudulent by Exchange contract challenge functions.
Essentially the required functionality is similar to stage()
. But where source and destination of balance movements in the current implementation of stage()
is the same wallet, it is necessary that source and destination be different wallets in this new use case. Also this use case only happens when triggered from registered service (here the Exchange contract).
It thus seems most reasonable to implement a new function, e.g. named seizeDepositedAndSettledBalances()
in ClientFund.
Implement Exchange smart contract according to section Exchange in specification (v0.12).
The Exchange smart contract is the orchestrator of trades and payments on-chain including a.o. settlements and challenges.
Implement Client fund smart contract according to section Client fund in specification (v0.12).
The Client fund is where clients’ crypto assets are deposited into, staged and withdrawn from.
The bulk of code for this smart contract can be factored out from previous Trade smart contract.
Implement challenge of fraudulent deal by balance in Exchange smart contract according to section ChallengeFraudulentDealBySuccession.
It should be possible to transfer funds from ClientFund to ReserveFund. Thus ClientFund can serve as single entry point for funds from wallets that are inbound to Omphalos. A suggested implementation goes as follows:
StageTo()
to client fund. Albeit very similar to existing Stage()
function StageTo()
will take an additional parameter of target address. When called in order to transfer to ReserveFund the target address argument will have the value of the address of (trade or payment) ReserveFund instance.Beneficiary
interface Beneficiary {
function DepositEther(address: b, amount: a) public payable;
function DepositTokens(address: b, amount: a, token: t) public;
}
DepositTokens()
already does. The new DepositEther()
will be very much identical to the ReserveFund fallback function. Only where fallback function works with balances of msg.sender the new function will rather work with balances of address b. Core logics of fallback function should be factored out into new internal function that can be called both by fallback function as well as by DepositEther()
function.This issue is currently not represented in the Omphalos specification.
In order to support future new driip types it may be worthwhile to split current contracts by driip types. Candidate contracts include a.o. DriipSettlementChallenge
, DriipSettlementChallenger
, Configuration
and Exchange
. The intention of splitting contracts is to minimize the impact and need to redeploy existing features with the introduction of new driip types.
The outcome of this issue is an outline of the work required and possible effect in terms of altered gas costs related to deployment and execution.
Replace the use of uintX
by intX
in monetary values in Configuration contract.
Export of state of a number of contracts is needed for the possible redeployment of updated contracts. The concerned contracts include but is not limited to CancelOrdersChallenge
, DriipSettlementChallenge
, FraudChallenge
, Exchange
, RevenueFund
, ReserveFund
and SecurityBond
. Contracts containing ETH and token balances have to be able to transfer funds to new contract instance.
ClientFund
and ReserveFund
already have mechanism in place from their stageTo()
functions that can be used to transfer user balances. However, aggregate balances are not covered by this function.
When wallets deals are deemed fraudulent the deposited and settled balances of the wallet must be seized by calling ClientFund's seizeDepositedAndSettledBalances()
from Exchange's challengeFraudulentDealByTrade()
and challengeFraudulentDealByPayment()
(and possibly other function implemented by #26).
challengeFraudulentDealByTrade()
in Exchange calls seizeDepositedAndSettledBalances()
in ClientFund when trade is deemed fraudulent and fraud attributed to particular wallet.challengeFraudulentDealByPayment()
in Exchange calls seizeDepositedAndSettledBalances()
in ClientFund when payment is deemed fraudulent and fraud attributed to particular wallet.This issue is left-over of #14.
Set up build config in TeamCity with automated testing in place.
red/green status for each commit/branch in TeamCity.
The stakes managed by Configuration contract should be fractional (in units of PARTS_PER
) and not absolute as they are today. The staging of fund in SecurityBond contract will also have to be modified accordingly, either by stage()
function having fraction
and partsPer
parameters rather than the current amount
, or by calculating the fractional amount in function that calls stage()
.
Replace the use of uintX
by intX
in monetary values in ClientFund contract.
ReserveFund contract needs to allow registered services in similar manner as SecurityBond contract. It will need function RegisterService()
that adds address to array of registered service addresses if not already present. It will also need function DeregisterService()
that removes an address from that array of registered service addresses if it has previously been registered.
Also, where it in fallback, DepositTokens()
and CloseAccrualPeriod()
functions is indicated that msg.sender
should be owner it should rather be required that msg.sender
is found amongst registered service addresses. The canonical registered service will be the RevenueFund contract.
The client fund does not allow funds to be explicitly staged. Thus at present the only way that a wallet can withdraw funds from the client fund is if its active balance is for deals and settlements increment the wallet's staged balance.
The new concepts for the client fund was exemplified in Slack message from @jijordre to @markbkk.
--
First, let’s rename client fund 1 balance and introduce 1 more balance. The active balance in the current spec we rename to deposited balance. The concept of staged balance is unchanged. We then introduce the concept of settled balance. (In name this matches what L&B suggested, although semantically it may be different.:smile:). This means that a wallet will have 3 balances (i.e. balance values) per currency.
Also we (re)introduce function Stage()
in the client fund. Details about its implementation are below.
Then, we look at some actions.
Wallet a makes an initial deposit of 10 ETH. This increments his deposited balance of ETH.
Wallet a places a payment of 2 ETH to wallet b.
Wallet a then wants to withdraw its ETH. It is successful in running the deal settlement challenge for the payment deal.
Wallet a settles the payment deal on-chain by calling exchange contract’s SettleDeal()
(Let’s assume immediate settlement is requested and/or discarding the reserve fund for now.) According to the net transfer of the payment it increments wallet b’s settled balance of ETH by an amount of 2 and decrements wallet a’s settled balance of ETH by the same amount of 2.
Wallet a continues towards withdrawal by calling client fund contract’s Stage()
. The increment to its staged balance of ETH is the sum of deposited balance (10) and settled balance (-2) of ETH, with the total value of 8 ETH. This action also zeros out the deposited balance and settled balance of wallet a.
Wallet b then wants to withdraw its ETH and starts off by calling client fund’s Stage()
. The increment to its staged balance of ETH is the sum of deposited balance (0) and settled balance (+2) of ETH, with the total value of 2 ETH. This action also zeros out the deposited balance and settled balance of wallet b.
Wallet a choses to not withdraw after all but rather wants to reengage with orders and payments. It calls Unstage()
which increments the deposited balance of ETH to 8 and zeros out the staged balance of ETH.
Wallet b choses to withdraw by calling Withdraw()
and zeros the staged balance of ETH.
I believe this scenario can be easily extended to trades as well. In addition we should bake into it the possibility of partial withdrawal and partial unstage. Partial stage may or may not make sense. I can’t quite decide yet.
Stage()
has been implemented in client fund.TransferFromActiveToStagedBalance()
has been renamed to TransferFromDepositedToSettledBalance()
and implementation updated to deal with updated balances.WithdrawFromActiveBalance()
has been renamed to WithdrawFromDepositedBalance()
and implementation updated to deal with deposited balance instead of active balance.DepositEtherToStagedBalance()
has been renamed to DepositEtherToSettledBalance()
and implementation updated to deal with settled balance instead of staged balance.DepositTokenToStagedBalance()
has been renamed to DepositTokenToSettledBalance()
and implementation updated to deal with settled balance instead of staged balance.This implementation is not included in the Omphalos specification.
A declarative, efficient, and flexible JavaScript library for building user interfaces.
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google ❤️ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.