Skip to content

Commit

Permalink
ICX Orderbook (#335)
Browse files Browse the repository at this point in the history
* Initial ICX orderbook development

* Inital development of ICX Orderbook

* Fixes and changes.

* Remove prints and small fix.

* Fix seed to hash calculation

* Optimize data structures.

* Fix searching HTLCs.

* Refactor data structures and flow, fixed PR issues

* Refactor data structures and flow, fixed PR issues

* Fix issues.

* Added incentives and fees. Fixed issue with CAmount multiply overflow. Fix tests and clean code. (#5)

* Add incentives and fees. Fix multiply overflow.

* Fix lint rpc mapping check

* Add poolpair id to governance variable for DFI/BTC price used in takerFee, minimum timeout for 2nd HTLC, added initial unit test, various fixes and code clean.

* Fix calculation of takerFee. Clean code.

* Get poolpair id from governance variable.

* Adding expiration for minimum timeout to EXT HTLC.

* Remove locking funds on makeoffer, fixes.

* Add initial test that add creation of poolpair.

* Added takerFeePerBTC gov var, adapted timeouts for htlcs, check in rpc for correct htlc timeouts, added more checks in test.

* Added key for ext htlc closed, addapted test and rpcs.

* Fill partial offer to complete order

* Test burn. Wip burn map in ConnectBlock. Tally tokens.

* ICX Set order owner on creation

* Fix regressions, reproducible crashes
Polish

Fixes: #374

Signed-off-by: Anthony Fieroni <[email protected]>

* Remove chain data from DB, refactor address storing only in order/offer, fix auth, polish and clean code.

* Add warning disclaimer

* Add creation fee for devnet

* Fixed HTLC timout check, refund partial takerFee on partial offer accept, added test case for BTC/DFI flow, added error test cases, polished code.

* Fixed expiration of offer and htlcs,  added check for open offer on submit htlc, added more test cases.

* Fix order expiration refund, add checkin rpc for htlc if order expires first, fixed and added tests.

* Fix findng poolpair and calculating DFI per BTC, adapted test,  rpc fix.

* Remove unnecessary check in GetBTCDFIPoolPair(), make BTC isDAT in error tests, change BTC blocks in DFI to 20.

* Masternode creation requires authorization (#386)

Signed-off-by: Anthony Fieroni <[email protected]>

* Polish correct offer prices in blockchain layer

Signed-off-by: Anthony Fieroni <[email protected]>

* Moving more checks from RPC to mn_checks, cleanup code

* Small fixes.

* Follow getburninfo at all steps. Set correct amounts.

* Fix lint

* Fix lint

* Fix typo.

Co-authored-by: Peter Bushnell <[email protected]>
Co-authored-by: monstrobishi <[email protected]>
Co-authored-by: Anthony Fieroni <[email protected]>
  • Loading branch information
4 people authored May 17, 2021
1 parent 8ec5263 commit f73e9a2
Show file tree
Hide file tree
Showing 24 changed files with 4,675 additions and 36 deletions.
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -129,3 +129,6 @@ dist/

# spv
!src/spv/Makefile

# VSCode extension LocalHistory
.history
9 changes: 7 additions & 2 deletions src/Makefile.am
Original file line number Diff line number Diff line change
Expand Up @@ -157,9 +157,11 @@ DEFI_CORE_H = \
masternodes/communityaccounttypes.h \
masternodes/criminals.h \
masternodes/factory.h \
masternodes/govvariables/icx_takerfee_per_btc.h \
masternodes/govvariables/lp_daily_dfi_reward.h \
masternodes/govvariables/lp_splits.h \
masternodes/gv.h \
masternodes/icxorder.h \
masternodes/incentivefunding.h \
masternodes/masternodes.h \
masternodes/mn_checks.h \
Expand Down Expand Up @@ -366,19 +368,22 @@ libdefi_server_a_SOURCES = \
masternodes/anchors.cpp \
masternodes/criminals.cpp \
masternodes/oracles.cpp \
masternodes/govvariables/icx_takerfee_per_btc.cpp \
masternodes/govvariables/lp_daily_dfi_reward.cpp \
masternodes/govvariables/lp_splits.cpp \
masternodes/gv.cpp \
masternodes/icxorder.cpp \
masternodes/incentivefunding.cpp \
masternodes/masternodes.cpp \
masternodes/mn_checks.cpp \
masternodes/mn_rpc.cpp \
masternodes/rpc_accounts.cpp \
masternodes/rpc_customtx.cpp \
masternodes/rpc_masternodes.cpp \
masternodes/rpc_tokens.cpp \
masternodes/rpc_poolpair.cpp \
masternodes/rpc_icxorderbook.cpp \
masternodes/rpc_oracles.cpp \
masternodes/rpc_poolpair.cpp \
masternodes/rpc_tokens.cpp \
masternodes/tokens.cpp \
masternodes/poolpairs.cpp \
masternodes/undos.cpp \
Expand Down
31 changes: 31 additions & 0 deletions src/masternodes/govvariables/icx_takerfee_per_btc.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
// Copyright (c) 2020 The DeFi Foundation
// Distributed under the MIT software license, see the accompanying
// file LICENSE or http://www.opensource.org/licenses/mit-license.php.

#include <masternodes/govvariables/icx_takerfee_per_btc.h>
#include <core_io.h> /// ValueFromAmount
#include <masternodes/masternodes.h> /// CCustomCSView
#include <rpc/util.h> /// AmountFromValue

Res ICX_TAKERFEE_PER_BTC::Import(const UniValue & val) {
takerFeePerBTC = AmountFromValue(val);
return Res::Ok();
}

UniValue ICX_TAKERFEE_PER_BTC::Export() const {
UniValue res(UniValue::VOBJ);

return ValueFromAmount(takerFeePerBTC);
}

Res ICX_TAKERFEE_PER_BTC::Validate(const CCustomCSView &mnview) const
{
if (takerFeePerBTC <= 0)
return Res::Err("takerFeePerBTC cannot be 0 or less");
return Res::Ok();
}

Res ICX_TAKERFEE_PER_BTC::Apply(CCustomCSView & mnview, uint32_t)
{
return mnview.ICXSetTakerFeePerBTC(takerFeePerBTC);
}
35 changes: 35 additions & 0 deletions src/masternodes/govvariables/icx_takerfee_per_btc.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
#ifndef DEFI_MASTERNODES_GOVVARIABLES_ICX_TAKERFEE_PER_BTC_H
#define DEFI_MASTERNODES_GOVVARIABLES_ICX_TAKERFEE_PER_BTC_H

#include <masternodes/gv.h>
#include <amount.h>

class ICX_TAKERFEE_PER_BTC : public GovVariable, public AutoRegistrator<GovVariable, ICX_TAKERFEE_PER_BTC>
{
public:
virtual ~ICX_TAKERFEE_PER_BTC() override {}

std::string GetName() const override {
return TypeName();
}

Res Import(UniValue const &val) override;
UniValue Export() const override;
Res Validate(CCustomCSView const &mnview) const override;
Res Apply(CCustomCSView &mnview, uint32_t height) override;

static constexpr char const * TypeName() { return "ICX_TAKERFEE_PER_BTC"; }
static GovVariable * Create() { return new ICX_TAKERFEE_PER_BTC(); }

ADD_OVERRIDE_VECTOR_SERIALIZE_METHODS
ADD_OVERRIDE_SERIALIZE_METHODS(CDataStream)

template <typename Stream, typename Operation>
inline void SerializationOp(Stream& s, Operation ser_action) {
READWRITE(takerFeePerBTC);
}

CAmount takerFeePerBTC;
};

#endif // DEFI_MASTERNODES_GOVVARIABLES_ICX_TAKERFEE_PER_BTC_H
1 change: 1 addition & 0 deletions src/masternodes/gv.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
// file LICENSE or http://www.opensource.org/licenses/mit-license.php.

#include <masternodes/gv.h>
#include <masternodes/govvariables/icx_takerfee_per_btc.h>
#include <masternodes/govvariables/lp_daily_dfi_reward.h>
#include <masternodes/govvariables/lp_splits.h>

Expand Down
Loading

0 comments on commit f73e9a2

Please sign in to comment.