Skip to content

Commit

Permalink
Merge remote-tracking branch 'origin/master_candidate'
Browse files Browse the repository at this point in the history
  • Loading branch information
216k155 committed Feb 3, 2019
2 parents 854cba2 + 65e3103 commit 23c261e
Show file tree
Hide file tree
Showing 55 changed files with 361 additions and 13,578 deletions.
106 changes: 106 additions & 0 deletions doc/Perpetual-Futures-contracts-and-Leverage-Margin-trading.md
@@ -0,0 +1,106 @@
![LUX Logo](../src/qt/res/images/lux_logo_horizontal.png)

"FIRST OF ITS KIND"

Luxcore is GNU AGPLv3 licensed.

LUXGATE Perpetual & Futures contracts - Leverage & Margin trading.
==================================================================

Luxgate is a decentralized exchange, so all orders will be listed on LUX explorer and all transactions are stored in the LUX blockchain.

## Perpetual & Futures contracts.

Futures are a derivative tool or agreement to buy or sell a primary asset at a predetermined price at a specified time in the future. With Luxgate you can trade using the futures contracts that cannot be delivered, which means that the difference between the perpetual contracts price and the spot price will be automatically calculated at the time specified in the contract.

## Leverage & Margin trading.

Financial leverage is the expression of the level of loan use in the total capital of the enterprise to increase the rate of equity return (ROE) or the income per ordinary share of the company.

Financial leverage refers to the combination of liabilities and owners' equity in regulating corporate financial policies. Financial leverage will be considerable in businesses with a higher proportion of liabilities than equity. Conversely, financial leverage will be low when the proportion of liabilities is smaller than the proportion of equity.

Financial leverage is both a tool to promote after-tax profits on an owner's equity and a tool to curb that increase. High profitability is the desire of the owners, in which financial leverage is a tool used by managers.


* Below is a basic example of using leverage, also known as simple leverage.


A and B are currently trading LUX/USD in their locality.
A used the amount of USD 100,000,000 to buy 10 LUX for USD 10,000,000 / LUX. The total amount A currently uses is 100,000,000 USD. He only uses his existing capital to do business without using financial leverage, not borrowing more.
B also used the capital of USD 100,000,000 and borrowed more than USD 50,000,000 to buy 15 LUX for USD 10,000,000 / LUX. The total amount B currently uses is 150,000,000 USD. Currently, B borrowed more money from his friends, which is B's use of financial leverage. B is controlling 15 LUX with only USD 100,000,000.
If LUX is favorable, the total ROE value of B and A increases by 25%, they sell then:
* A profit USD 100,000,000 x 0.25 = USD 25,000,000, from the initial capital of USD 100,000,000. 25% profit
* B earns USD 150,000,000 x 0.25 = USD 37,500,000, from it initial capital of USD 100,000,000. Profit of 37.5%.
If LUX is unstable, the total ROE value of B and A decreases by 10%, they sell then:
* A lost USD 100,000,000 x 10% = USD 10,000,000. Damage 10% of it capital.
* B lost USD 150,000,000 x 10% = USD 15,000,000. Damage 15% of it capital.
Through this, we see that when using financial leverage effectively, the profit margin is much higher than not using financial leverage. But it is also necessary to carefully consider the business plans to minimize the risks that lead to losses.

* Formula to calculate financial leverage

DFL = (% change in EPS) / (% change in EBIT)

DFL is a leverage ratio that shows the effect of a specific debt on the company's earnings per share.

* Leverage

Luxgate offers leverage on operations with derivatives with the maximum of `x100 leverage`. `Note: high leverage increases trading risks`.

* Masternode Collateral System & Open Position

To open a position, you need to have a sufficient initial margin level which is holding by our `masternode collateral` function. It is a 100% `decentralised collateral system` that Luxcore specially implemented to serves as collateral for your order. It is calculated in proportion to the leverage you choose.

Example:

Initial margin for leverage x2 is 50% of the order amount; initial margin for leverage x10 is 10% of the order amount; for leverage x 25 you need to deposit only 4% of the order amount. After your order is executed, 30% of the initial margin will be transferred to you Margin Balance. This amount will be automatically used to maintain your positions, or you can use it to place new orders or transfer it to your account.

* Liquidation

You need to have a sufficient level of maintenance margin balance for your current position, otherwise, your position will be liquidated

70% of the initial margin for your postion

Margin Balance, including 30% of the initial margin for your position

If your position exceeds maintenance margin, it will be liquidated.

* Cross Margin

Luxgate also has cross margin method. This means that the maintenance margin of your Margin Balance will be shared among all your open positions. Therefore, when a trader has several open positions, the maintenance margin also includes:

Unrealized positive PNL on all open positions

Example:

(.....)

### Margin Balance

Margin balances are designed to maintain existing positions with leverage. Margin balances automatically maintain positions close to liquidation.

### Liquidation Process

If your total balance is not enough to maintain your position, they can be liquidated. The Fair price marking system is used to calculate the liquidation price. It allows avoiding spurious liquidation when price exceptions occur due to market manipulation. If traders cannot meet their maintenance requirements, they will be liquidated.

### Fees

To record information about opening an order and add information about a completed transaction to the LUX blockchain, you need to spend a particular amount of TX fee.


* Luxgate fees, Makers and Takers fees.

Fee for makers is 0% + blockchain fee (TX fee) for placing an order.

Fee for takers is 0,1% + blockchain fee (TX fee) for placing an order.
TX fee is used for all the transaction within the LUX blockchain system.
5 changes: 0 additions & 5 deletions src/Makefile.qt.include
Expand Up @@ -55,7 +55,6 @@ QT_FORMS_UI = \
qt/forms/openuridialog.ui \
qt/forms/optionsdialog.ui \
qt/forms/overviewpage.ui \
qt/forms/tradingdialog.ui \
qt/forms/receivecoinsdialog.ui \
qt/forms/receivetokenpage.ui \
qt/forms/receiverequestdialog.ui \
Expand Down Expand Up @@ -123,7 +122,6 @@ QT_MOC_CPP = \
qt/moc_optionsdialog.cpp \
qt/moc_optionsmodel.cpp \
qt/moc_overviewpage.cpp \
qt/moc_tradingdialog.cpp \
qt/moc_tokenamountfield.cpp \
qt/moc_qcustomplot.cpp \
qt/moc_peertablemodel.cpp \
Expand Down Expand Up @@ -252,7 +250,6 @@ BITCOIN_QT_H = \
qt/optionsdialog.h \
qt/optionsmodel.h \
qt/overviewpage.h \
qt/tradingdialog.h \
qt/paymentrequestplus.h \
qt/paymentserver.h \
qt/peertablemodel.h \
Expand Down Expand Up @@ -376,7 +373,6 @@ RES_ICONS = \
qt/res/icons/staking_inactive.png \
qt/res/icons/synced.png \
qt/res/icons/stake.png \
qt/res/icons/trade.png \
qt/res/icons/transaction0.png \
qt/res/icons/transaction2.png \
qt/res/icons/transaction_abandoned.png \
Expand Down Expand Up @@ -472,7 +468,6 @@ BITCOIN_QT_CPP += \
qt/openuridialog.cpp \
qt/overviewpage.cpp \
qt/qcustomplot.cpp \
qt/tradingdialog.cpp \
qt/paymentrequestplus.cpp \
qt/paymentserver.cpp \
qt/lsrtoken.cpp \
Expand Down
38 changes: 4 additions & 34 deletions src/darksend.cpp
Expand Up @@ -411,6 +411,7 @@ int randomizeList(int i) { return std::rand() % i; }
// Recursively determine the rounds of a given input (How deep is the darksend chain for a given input)
int GetInputDarksendRounds(CTxIn in, int rounds) {
if (rounds >= 17) return rounds;
if (rounds > nDarksendRounds || nDarksendRounds <= 0 || !fEnableDarksend) return rounds; // once we hit the max rounds setting, there's no point going further back (this func is only used for selecting qualifying txs)

std::string padding = "";
padding.insert(0, ((rounds + 1) * 5) + 3, ' ');
Expand Down Expand Up @@ -2114,57 +2115,26 @@ void ThreadCheckDarkSendPool() {
darkSendPool.CheckTimeout();

if (c % 60 == 0) {
// LOCK(cs_main);
/*
cs_main is required for doing masternode.Check because something
is modifying the coins view without a mempool lock. It causes
segfaults from this code without the cs_main lock.
*/
{

{
LOCK(cs_masternodes);
vector<CMasterNode>::iterator it = vecMasternodes.begin();
//check them separately
while (it != vecMasternodes.end()) {
(*it).Check();
++it;
}

int count = vecMasternodes.size();
int i = 0;

for (CMasterNode mn : vecMasternodes) {

if (mn.addr.IsRFC1918()) continue; //local network
if (mn.IsEnabled()) {
if (fDebug) LogPrintf("Sending masternode entry - %s \n", mn.addr.ToString().c_str());
for (CNode * pnode : vNodes) {
if (pnode)
pnode->PushMessage("dsee", mn.vin, mn.addr, mn.sig, mn.now, mn.pubkey, mn.pubkey2, count, i, mn.lastTimeSeen, mn.protocolVersion);
}
}
i++;
}

//remove inactive
it = vecMasternodes.begin();
while (it != vecMasternodes.end()) {
if ((*it).enabled == 4 || (*it).enabled == 3) {
LogPrintf("Removing inactive masternode %s\n", (*it).addr.ToString().c_str());
it = vecMasternodes.erase(it);
} else {
++it;
}
}

}

masternodePayments.CleanPaymentList();
CleanTransactionLocksList();
}

//try to sync the masternode list and payment list every 5 seconds from at least 3 nodes
if (c % 5 == 0 && RequestedMasterNodeList < 3) {
//try to sync the masternode list and payment list every 5 seconds from at least 5 nodes
if (c % 5 == 0 && RequestedMasterNodeList < 5) {
bool fIsInitialDownload = IsInitialBlockDownload();
if (!fIsInitialDownload) {
LOCK(cs_vNodes);
Expand Down
24 changes: 22 additions & 2 deletions src/init.cpp
Expand Up @@ -821,6 +821,7 @@ bool AppInit2()
fPrintToConsole = GetBoolArg("-printtoconsole", false);
fLogTimestamps = GetBoolArg("-logtimestamps", true);
fLogIPs = GetBoolArg("-logips", false);
int nIndexNum;

if (mapArgs.count("-bind") || mapArgs.count("-whitebind")) {
// when specifying an explicit binding address, you want to listen on it
Expand Down Expand Up @@ -919,8 +920,27 @@ bool AppInit2()
nMaxConnections = nFD - MIN_CORE_FILEDESCRIPTORS;

if (GetArg("-prune", 0)) {
if (GetBoolArg("-txindex", DEFAULT_TXINDEX))
return InitError(_("Prune mode is incompatible with -txindex."));
std::string strLoadError;
if (GetBoolArg("-txindex", DEFAULT_TXINDEX)) {
strLoadError = _("You need to add txindex=0 to start pruning");
bool fRetPrune = uiInterface.ThreadSafeQuestion(
strLoadError + ".\n\n" + _("Do you want to add automatically add it to the configuration file and close the wallet?"),
strLoadError + ".\nPlease restart with txindex=0 to prune.",
"", CClientUIInterface::MSG_ERROR | CClientUIInterface::BTN_ABORT);
if (fRetPrune){
nIndexNum = 0;
WriteConfigToFile("txindex", std::to_string(nIndexNum));
fReindex = true;
fRequestRestart = true;
} else {
LogPrintf("Aborted configuration changes. Exiting.\n");
return false;
}
}
}
if (fRequestRestart) {
LogPrintf("Restart requested. Exiting.\n");
return false;
}

// ********************************************************* Step 3: parameter-to-internal-flags
Expand Down
2 changes: 1 addition & 1 deletion src/lux-cli.cpp
Expand Up @@ -260,7 +260,7 @@ int CommandLineRPC(int argc, char* argv[])
throw CConnectionFailed("server in warmup");
strPrint = "error: " + error.write();
nRet = abs(code);
if (error.isObject())
if (error.isObject() && GetBoolArg("-printstringerror", false))
{
UniValue errCode = find_value(error, "code");
UniValue errMsg = find_value(error, "message");
Expand Down
22 changes: 18 additions & 4 deletions src/masternode.cpp
Expand Up @@ -166,8 +166,13 @@ void ProcessMasternode(CNode* pfrom, const std::string& strCommand, CDataStream&
tx.vin.push_back(vin);
tx.vout.push_back(vout);
//if(AcceptableInputs(mempool, state, tx)){
bool pfMissingInputs;
if (AcceptableInputs(mempool, state, CTransaction(tx), false, &pfMissingInputs)) {
bool inputsAcceptable;
{
LOCK(cs_main);
bool pfMissingInputs;
inputsAcceptable = AcceptableInputs(mempool, state, CTransaction(tx), false, &pfMissingInputs);
}
if (inputsAcceptable) {
if (fDebug) LogPrintf("dsee - Accepted masternode entry %i %i\n", count, current);

if (GetInputAge(vin) < MASTERNODE_MIN_CONFIRMATIONS) {
Expand Down Expand Up @@ -579,7 +584,9 @@ uint256 CMasterNode::CalculateScore(int mod, int64_t nBlockHeight) {
return r;
}

void CMasterNode::Check() {
void CMasterNode::Check(bool forceCheck) {
if(!forceCheck && (GetTime() - lastTimeChecked < MASTERNODE_CHECK_SECONDS)) return;
lastTimeChecked = GetTime();
//once spent, stop doing the checks
if (enabled == 3) return;

Expand All @@ -599,11 +606,18 @@ void CMasterNode::Check() {
CTxOut vout = CTxOut((GetMNCollateral(chainActive.Height()) - 1) * COIN, darkSendPool.collateralPubKey);
tx.vin.push_back(vin);
tx.vout.push_back(vout);

bool pfMissingInputs;
{
LOCK(cs_main);
/*
cs_main is required for doing masternode.Check because something
is modifying the coins view without a mempool lock. It causes
segfaults from this code without the cs_main lock.
*/
if (!AcceptableInputs(mempool, state, CTransaction(tx), false, &pfMissingInputs)) {
enabled = 3;
return;
}
}
}

Expand Down
5 changes: 4 additions & 1 deletion src/masternode.h
Expand Up @@ -38,6 +38,7 @@ class uint256;
#define MASTERNODE_PING_WAIT_SECONDS (5*60)
#define MASTERNODE_EXPIRATION_SECONDS (65*60) //Old 65*60
#define MASTERNODE_REMOVAL_SECONDS (70*60) //Old 70*60
#define MASTERNODE_CHECK_SECONDS 60

using namespace std;

Expand Down Expand Up @@ -77,6 +78,7 @@ class CMasterNode
std::vector<unsigned char> sig;
int64_t now; //dsee message times
int64_t lastDseep;
int64_t lastTimeChecked;
int cacheInputAge;
int cacheInputAgeBlock;
int enabled;
Expand All @@ -103,6 +105,7 @@ class CMasterNode
lastDseep = 0;
allowFreeTx = true;
protocolVersion = protocolVersionIn;
lastTimeChecked = GetTime() + GetRand(60); // set random check time
}

uint256 CalculateScore(int mod=1, int64_t nBlockHeight=0);
Expand All @@ -123,7 +126,7 @@ class CMasterNode
return n;
}

void Check();
void Check(bool forceCheck = false);

bool UpdatedWithin(int seconds)
{
Expand Down
3 changes: 3 additions & 0 deletions src/qt/addressfield.cpp
Expand Up @@ -9,6 +9,7 @@
#include "base58.h"
#include "qvalidatedlineedit.h"
#include "bitcoinaddressvalidator.h"
#include "../main.h"
#include <QLineEdit>
#include <QCompleter>

Expand Down Expand Up @@ -79,6 +80,8 @@ void AddressField::on_refresh()
// Initialize variables
QString currentAddress = currentText();
m_stringList.clear();
if (GetTime() < lastRefreshTime + 30) return; //only do this once every 30 secs
lastRefreshTime = GetTime();
vector<COutput> vecOutputs;
assert(pwalletMain != NULL);

Expand Down
1 change: 1 addition & 0 deletions src/qt/addressfield.h
Expand Up @@ -100,6 +100,7 @@ public Q_SLOTS:
QAbstractItemModel* m_addressTableModel;
int m_addressColumn;
int m_typeRole;
int64_t lastRefreshTime;
QString m_receive;
};

Expand Down
11 changes: 7 additions & 4 deletions src/qt/addtokenpage.cpp
Expand Up @@ -55,8 +55,8 @@ void AddTokenPage::setClientModel(ClientModel *clientModel)
m_clientModel = clientModel;
if (m_clientModel)
{
connect(m_clientModel, SIGNAL(numBlocksChanged()), this, SLOT(on_numBlocksChanged()));
on_numBlocksChanged();
connect(m_clientModel, SIGNAL(numBlocksChanged(int)), this, SLOT(on_numBlocksChanged(int)));
on_numBlocksChanged(1);
}
}

Expand Down Expand Up @@ -138,9 +138,12 @@ void AddTokenPage::on_addressChanged()
ui->confirmButton->setEnabled(m_validTokenAddress);
}

void AddTokenPage::on_numBlocksChanged()
void AddTokenPage::on_numBlocksChanged(int newHeight)
{
ui->lineEditSenderAddress->on_refresh();
if (lastUpdatedHeight < newHeight) {
ui->lineEditSenderAddress->on_refresh();
lastUpdatedHeight = newHeight;
}
}

void AddTokenPage::on_updateConfirmButton()
Expand Down

0 comments on commit 23c261e

Please sign in to comment.