Skip to content

Commit

Permalink
Token splits, token lock and move loan and collateral token to Gov va…
Browse files Browse the repository at this point in the history
…rs (#1243)

* Token Lock

* Token Split

* Fix setting ATTRIBUTES by Gov height

* Move loan and collateral token to Gov var

* Move FCR to GW

* tests: remove redundant line

* Set time in attrs when applying by height

* Token split support multiple pool and pool created in the block

* Migrate all keys on token split

* Do not fail when vault has interest but no loan tokens

* Return false on error from get internal price

* tests: Update error text

* Add SetValue and EraseKey to attrs

* Remove split entries from Gov var. Only split loan tokens.

* Set rate height

Co-authored-by: Prasanna Loganathar <[email protected]>
  • Loading branch information
Bushstar and prasannavl authored May 23, 2022
1 parent 8c27ac3 commit e17245f
Show file tree
Hide file tree
Showing 39 changed files with 3,130 additions and 371 deletions.
7 changes: 6 additions & 1 deletion src/chainparams.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -129,7 +129,8 @@ class CMainParams : public CChainParams {
consensus.FortCanningMuseumHeight = 1430640;
consensus.FortCanningParkHeight = 1503143;
consensus.FortCanningHillHeight = 1604999; // Feb 7, 2022.
consensus.FortCanningRoadHeight = 1786000; // April 11, 2022.
consensus.FortCanningRoadHeight = 1786000; // April 11, 2022.
consensus.GreatWorldHeight = std::numeric_limits<int>::max();

consensus.pos.diffLimit = uint256S("00000fffffffffffffffffffffffffffffffffffffffffffffffffffffffffff");
// consensus.pos.nTargetTimespan = 14 * 24 * 60 * 60; // two weeks
Expand Down Expand Up @@ -358,6 +359,7 @@ class CTestNetParams : public CChainParams {
consensus.FortCanningParkHeight = 828800;
consensus.FortCanningHillHeight = 828900;
consensus.FortCanningRoadHeight = 893700;
consensus.GreatWorldHeight = std::numeric_limits<int>::max();

consensus.pos.diffLimit = uint256S("00000fffffffffffffffffffffffffffffffffffffffffffffffffffffffffff");
// consensus.pos.nTargetTimespan = 14 * 24 * 60 * 60; // two weeks
Expand Down Expand Up @@ -547,6 +549,7 @@ class CDevNetParams : public CChainParams {
consensus.FortCanningParkHeight = std::numeric_limits<int>::max();
consensus.FortCanningHillHeight = std::numeric_limits<int>::max();
consensus.FortCanningRoadHeight = std::numeric_limits<int>::max();
consensus.GreatWorldHeight = std::numeric_limits<int>::max();

consensus.pos.diffLimit = uint256S("00000fffffffffffffffffffffffffffffffffffffffffffffffffffffffffff");
consensus.pos.nTargetTimespan = 5 * 60; // 5 min == 10 blocks
Expand Down Expand Up @@ -728,6 +731,7 @@ class CRegTestParams : public CChainParams {
consensus.FortCanningParkHeight = 10000000;
consensus.FortCanningHillHeight = 10000000;
consensus.FortCanningRoadHeight = 10000000;
consensus.GreatWorldHeight = 10000000;

consensus.pos.diffLimit = uint256S("00000fffffffffffffffffffffffffffffffffffffffffffffffffffffffffff");
consensus.pos.nTargetTimespan = 14 * 24 * 60 * 60; // two weeks
Expand Down Expand Up @@ -948,6 +952,7 @@ void CRegTestParams::UpdateActivationParametersFromArgs()
UpdateHeightValidation("Fort Canning Park", "-fortcanningparkheight", consensus.FortCanningParkHeight);
UpdateHeightValidation("Fort Canning Hill", "-fortcanninghillheight", consensus.FortCanningHillHeight);
UpdateHeightValidation("Fort Canning Road", "-fortcanningroadheight", consensus.FortCanningRoadHeight);
UpdateHeightValidation("Great World", "-greatworldheight", consensus.GreatWorldHeight);

if (gArgs.GetBoolArg("-simulatemainnet", false)) {
consensus.pos.nTargetTimespan = 5 * 60; // 5 min == 10 blocks
Expand Down
1 change: 1 addition & 0 deletions src/consensus/params.h
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,7 @@ struct Params {
int FortCanningParkHeight;
int FortCanningHillHeight;
int FortCanningRoadHeight;
int GreatWorldHeight;

/** Foundation share after AMK, normalized to COIN = 100% */
CAmount foundationShareDFIP1;
Expand Down
21 changes: 19 additions & 2 deletions src/consensus/tx_check.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,10 @@
#include <primitives/transaction.h>
#include <consensus/validation.h>

/// @todo refactor it to unify txs!!! (need to restart blockchain)
const std::vector<unsigned char> DfTxMarker = {'D', 'f', 'T', 'x'};
const std::vector<unsigned char> DfAnchorFinalizeTxMarker = {'D', 'f', 'A', 'f'};
const std::vector<unsigned char> DfAnchorFinalizeTxMarkerPlus = {'D', 'f', 'A', 'P'};
const std::vector<unsigned char> DfTokenSplitMarker = {'D', 'f', 'T', 'S'};

bool CheckTransaction(const CTransaction& tx, CValidationState &state, bool fCheckDuplicateInputs)
{
Expand Down Expand Up @@ -49,7 +50,7 @@ bool CheckTransaction(const CTransaction& tx, CValidationState &state, bool fChe
if (tx.IsCoinBase())
{
std::vector<unsigned char> dummy;
if (IsAnchorRewardTx(tx, dummy) || IsAnchorRewardTxPlus(tx, dummy))
if (IsAnchorRewardTx(tx, dummy) || IsAnchorRewardTxPlus(tx, dummy) || IsTokenSplitTx(tx, dummy))
return true;
if (tx.vin[0].scriptSig.size() < 2 || (tx.vin[0].scriptSig.size() > 100))
return state.Invalid(ValidationInvalidReason::CONSENSUS, false, REJECT_INVALID, "bad-cb-length");
Expand Down Expand Up @@ -115,3 +116,19 @@ bool IsAnchorRewardTxPlus(CTransaction const & tx, std::vector<unsigned char> &
}
return result;
}

bool IsTokenSplitTx(CTransaction const & tx, std::vector<unsigned char> & metadata, bool fortCanningGreen)
{
if (!fortCanningGreen) {
return false;
}
if (!tx.IsCoinBase() || tx.vout.size() != 1 || tx.vout[0].nValue != 0) {
return false;
}
bool hasAdditionalOpcodes{false};
const auto result = ParseScriptByMarker(tx.vout[0].scriptPubKey, DfTokenSplitMarker, metadata, hasAdditionalOpcodes);
if (hasAdditionalOpcodes) {
return false;
}
return result;
}
4 changes: 3 additions & 1 deletion src/consensus/tx_check.h
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,10 @@

#include <vector>

/// moved here (!!) due to strange linker errors under mac/win builds
extern const std::vector<unsigned char> DfTxMarker;
extern const std::vector<unsigned char> DfAnchorFinalizeTxMarker;
extern const std::vector<unsigned char> DfAnchorFinalizeTxMarkerPlus;
extern const std::vector<unsigned char> DfTokenSplitMarker;

class CScript;
class CTransaction;
Expand All @@ -30,5 +31,6 @@ bool ParseScriptByMarker(CScript const & script,
bool& hasAdditionalOpcodes);
bool IsAnchorRewardTx(CTransaction const & tx, std::vector<unsigned char> & metadata, bool fortCanning = false);
bool IsAnchorRewardTxPlus(CTransaction const & tx, std::vector<unsigned char> & metadata, bool fortCanning = false);
bool IsTokenSplitTx(CTransaction const & tx, std::vector<unsigned char> & metadata, bool fortCanningGreen = true);

#endif // DEFI_CONSENSUS_TX_CHECK_H
1 change: 1 addition & 0 deletions src/init.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -477,6 +477,7 @@ void SetupServerArgs()
gArgs.AddArg("-fortcanningparkheight", "Fort Canning Park fork activation height (regtest only)", ArgsManager::ALLOW_ANY | ArgsManager::DEBUG_ONLY, OptionsCategory::CHAINPARAMS);
gArgs.AddArg("-fortcanninghillheight", "Fort Canning Hill fork activation height (regtest only)", ArgsManager::ALLOW_ANY | ArgsManager::DEBUG_ONLY, OptionsCategory::CHAINPARAMS);
gArgs.AddArg("-fortcanningroadheight", "Fort Canning Road fork activation height (regtest only)", ArgsManager::ALLOW_ANY | ArgsManager::DEBUG_ONLY, OptionsCategory::CHAINPARAMS);
gArgs.AddArg("-greatworldheight", "Great World fork activation height (regtest only)", ArgsManager::ALLOW_ANY | ArgsManager::DEBUG_ONLY, OptionsCategory::CHAINPARAMS);
gArgs.AddArg("-jellyfish_regtest", "Configure the regtest network for jellyfish testing", ArgsManager::ALLOW_ANY | ArgsManager::DEBUG_ONLY, OptionsCategory::OPTIONS);
gArgs.AddArg("-simulatemainnet", "Configure the regtest network to mainnet target timespan and spacing ", ArgsManager::ALLOW_ANY | ArgsManager::DEBUG_ONLY, OptionsCategory::OPTIONS);
#ifdef USE_UPNP
Expand Down
Loading

0 comments on commit e17245f

Please sign in to comment.