Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Implementation of DFIP-2208-C #1531

Merged
merged 1 commit into from
Oct 31, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 9 additions & 5 deletions src/masternodes/govvariables/attributes.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -182,6 +182,7 @@ const std::map<uint8_t, std::map<std::string, uint8_t>>& ATTRIBUTES::allowedKeys
AttributeTypes::Governance, {
{"enabled", GovernanceKeys::Enabled},
{"payout", GovernanceKeys::CFPPayout},
{"fee_redistribution", GovernanceKeys::CFPFeeRedistribution},
}
},
};
Expand Down Expand Up @@ -246,8 +247,9 @@ const std::map<uint8_t, std::map<uint8_t, std::string>>& ATTRIBUTES::displayKeys
},
{
AttributeTypes::Governance, {
{GovernanceKeys::Enabled, "enabled"},
{GovernanceKeys::CFPPayout, "payout"},
{GovernanceKeys::Enabled, "enabled"},
{GovernanceKeys::CFPPayout, "payout"},
{GovernanceKeys::CFPFeeRedistribution, "fee_redistribution"},
}
},
};
Expand Down Expand Up @@ -422,8 +424,9 @@ const std::map<uint8_t, std::map<uint8_t,
},
{
AttributeTypes::Governance, {
{GovernanceKeys::Enabled, VerifyBool},
{GovernanceKeys::CFPPayout, VerifyBool},
{GovernanceKeys::Enabled, VerifyBool},
{GovernanceKeys::CFPPayout, VerifyBool},
{GovernanceKeys::CFPFeeRedistribution, VerifyBool},
}
},
};
Expand Down Expand Up @@ -596,7 +599,8 @@ Res ATTRIBUTES::ProcessVariable(const std::string& key, const std::string& value
if (typeKey != GovernanceKeys::Enabled)
return Res::Err("Unsupported key for Governance global section - {%d}", typeKey);
} else if (typeId == GovernanceIDs::CFP) {
if (typeKey != GovernanceKeys::CFPPayout)
if (typeKey != GovernanceKeys::CFPPayout
&& typeKey != GovernanceKeys::CFPFeeRedistribution)
return Res::Err("Unsupported key for Governance CFP section - {%d}", typeKey);
}
}
Expand Down
5 changes: 3 additions & 2 deletions src/masternodes/govvariables/attributes.h
Original file line number Diff line number Diff line change
Expand Up @@ -68,8 +68,9 @@ enum DFIPKeys : uint8_t {
};

enum GovernanceKeys : uint8_t {
Enabled = 'a',
CFPPayout = 'b',
Enabled = 'a',
CFPPayout = 'b',
CFPFeeRedistribution = 'c',
};

enum TokenKeys : uint8_t {
Expand Down
10 changes: 7 additions & 3 deletions src/masternodes/masternodes.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -76,11 +76,15 @@ CAmount GetTokenCreationFee(int)
return Params().GetConsensus().token.creationFee;
}

CAmount GetPropsCreationFee(int, CPropType prop)
CAmount GetPropsCreationFee(int, const CCreatePropMessage& msg)
{
switch(prop) {
auto type = static_cast<CPropType>(msg.type);
switch(type) {
case CPropType::CommunityFundProposal:
return Params().GetConsensus().props.cfp.fee;
{
auto fee = msg.nAmount / 100;
return fee < Params().GetConsensus().props.cfp.fee ? Params().GetConsensus().props.cfp.fee : fee;
}
case CPropType::BlockRewardReallocation:
return Params().GetConsensus().props.brp.fee;
case CPropType::VoteOfConfidence:
Expand Down
2 changes: 1 addition & 1 deletion src/masternodes/masternodes.h
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ CAmount GetTokenCollateralAmount();
CAmount GetMnCreationFee(int height);
CAmount GetTokenCreationFee(int height);
CAmount GetMnCollateralAmount(int height);
CAmount GetPropsCreationFee(int height, CPropType prop);
CAmount GetPropsCreationFee(int height, const CCreatePropMessage& msg);

enum class UpdateMasternodeType : uint8_t
{
Expand Down
130 changes: 69 additions & 61 deletions src/masternodes/mn_checks.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -32,63 +32,64 @@ constexpr std::string_view ERR_STRING_MIN_COLLATERAL_DFI_DUSD_PCT = "At least 50
std::string ToString(CustomTxType type) {
switch (type)
{
case CustomTxType::CreateMasternode: return "CreateMasternode";
case CustomTxType::ResignMasternode: return "ResignMasternode";
case CustomTxType::UpdateMasternode: return "UpdateMasternode";
case CustomTxType::CreateToken: return "CreateToken";
case CustomTxType::UpdateToken: return "UpdateToken";
case CustomTxType::UpdateTokenAny: return "UpdateTokenAny";
case CustomTxType::MintToken: return "MintToken";
case CustomTxType::CreatePoolPair: return "CreatePoolPair";
case CustomTxType::UpdatePoolPair: return "UpdatePoolPair";
case CustomTxType::PoolSwap: return "PoolSwap";
case CustomTxType::PoolSwapV2: return "PoolSwap";
case CustomTxType::AddPoolLiquidity: return "AddPoolLiquidity";
case CustomTxType::RemovePoolLiquidity: return "RemovePoolLiquidity";
case CustomTxType::UtxosToAccount: return "UtxosToAccount";
case CustomTxType::AccountToUtxos: return "AccountToUtxos";
case CustomTxType::AccountToAccount: return "AccountToAccount";
case CustomTxType::CreateMasternode: return "CreateMasternode";
case CustomTxType::ResignMasternode: return "ResignMasternode";
case CustomTxType::UpdateMasternode: return "UpdateMasternode";
case CustomTxType::CreateToken: return "CreateToken";
case CustomTxType::UpdateToken: return "UpdateToken";
case CustomTxType::UpdateTokenAny: return "UpdateTokenAny";
case CustomTxType::MintToken: return "MintToken";
case CustomTxType::CreatePoolPair: return "CreatePoolPair";
case CustomTxType::UpdatePoolPair: return "UpdatePoolPair";
case CustomTxType::PoolSwap: return "PoolSwap";
case CustomTxType::PoolSwapV2: return "PoolSwap";
case CustomTxType::AddPoolLiquidity: return "AddPoolLiquidity";
case CustomTxType::RemovePoolLiquidity: return "RemovePoolLiquidity";
case CustomTxType::UtxosToAccount: return "UtxosToAccount";
case CustomTxType::AccountToUtxos: return "AccountToUtxos";
case CustomTxType::AccountToAccount: return "AccountToAccount";
case CustomTxType::AnyAccountsToAccounts: return "AnyAccountsToAccounts";
case CustomTxType::SmartContract: return "SmartContract";
case CustomTxType::FutureSwap: return "DFIP2203";
case CustomTxType::SetGovVariable: return "SetGovVariable";
case CustomTxType::SetGovVariableHeight:return "SetGovVariableHeight";
case CustomTxType::AppointOracle: return "AppointOracle";
case CustomTxType::RemoveOracleAppoint: return "RemoveOracleAppoint";
case CustomTxType::UpdateOracleAppoint: return "UpdateOracleAppoint";
case CustomTxType::SetOracleData: return "SetOracleData";
case CustomTxType::AutoAuthPrep: return "AutoAuth";
case CustomTxType::ICXCreateOrder: return "ICXCreateOrder";
case CustomTxType::ICXMakeOffer: return "ICXMakeOffer";
case CustomTxType::ICXSubmitDFCHTLC: return "ICXSubmitDFCHTLC";
case CustomTxType::ICXSubmitEXTHTLC: return "ICXSubmitEXTHTLC";
case CustomTxType::ICXClaimDFCHTLC: return "ICXClaimDFCHTLC";
case CustomTxType::ICXCloseOrder: return "ICXCloseOrder";
case CustomTxType::ICXCloseOffer: return "ICXCloseOffer";
case CustomTxType::SetLoanCollateralToken: return "SetLoanCollateralToken";
case CustomTxType::SetLoanToken: return "SetLoanToken";
case CustomTxType::UpdateLoanToken: return "UpdateLoanToken";
case CustomTxType::LoanScheme: return "LoanScheme";
case CustomTxType::DefaultLoanScheme: return "DefaultLoanScheme";
case CustomTxType::DestroyLoanScheme: return "DestroyLoanScheme";
case CustomTxType::Vault: return "Vault";
case CustomTxType::CloseVault: return "CloseVault";
case CustomTxType::UpdateVault: return "UpdateVault";
case CustomTxType::DepositToVault: return "DepositToVault";
case CustomTxType::WithdrawFromVault: return "WithdrawFromVault";
case CustomTxType::PaybackWithCollateral: return "PaybackWithCollateral";
case CustomTxType::TakeLoan: return "TakeLoan";
case CustomTxType::PaybackLoan: return "PaybackLoan";
case CustomTxType::PaybackLoanV2: return "PaybackLoan";
case CustomTxType::AuctionBid: return "AuctionBid";
case CustomTxType::FutureSwapExecution: return "FutureSwapExecution";
case CustomTxType::FutureSwapRefund: return "FutureSwapRefund";
case CustomTxType::TokenSplit: return "TokenSplit";
case CustomTxType::Reject: return "Reject";
case CustomTxType::CreateCfp: return "CreateCfp";
case CustomTxType::CreateVoc: return "CreateVoc";
case CustomTxType::Vote: return "Vote";
case CustomTxType::None: return "None";
case CustomTxType::SmartContract: return "SmartContract";
case CustomTxType::FutureSwap: return "DFIP2203";
case CustomTxType::SetGovVariable: return "SetGovVariable";
case CustomTxType::SetGovVariableHeight: return "SetGovVariableHeight";
case CustomTxType::AppointOracle: return "AppointOracle";
case CustomTxType::RemoveOracleAppoint: return "RemoveOracleAppoint";
case CustomTxType::UpdateOracleAppoint: return "UpdateOracleAppoint";
case CustomTxType::SetOracleData: return "SetOracleData";
case CustomTxType::AutoAuthPrep: return "AutoAuth";
case CustomTxType::ICXCreateOrder: return "ICXCreateOrder";
case CustomTxType::ICXMakeOffer: return "ICXMakeOffer";
case CustomTxType::ICXSubmitDFCHTLC: return "ICXSubmitDFCHTLC";
case CustomTxType::ICXSubmitEXTHTLC: return "ICXSubmitEXTHTLC";
case CustomTxType::ICXClaimDFCHTLC: return "ICXClaimDFCHTLC";
case CustomTxType::ICXCloseOrder: return "ICXCloseOrder";
case CustomTxType::ICXCloseOffer: return "ICXCloseOffer";
case CustomTxType::SetLoanCollateralToken: return "SetLoanCollateralToken";
case CustomTxType::SetLoanToken: return "SetLoanToken";
case CustomTxType::UpdateLoanToken: return "UpdateLoanToken";
case CustomTxType::LoanScheme: return "LoanScheme";
case CustomTxType::DefaultLoanScheme: return "DefaultLoanScheme";
case CustomTxType::DestroyLoanScheme: return "DestroyLoanScheme";
case CustomTxType::Vault: return "Vault";
case CustomTxType::CloseVault: return "CloseVault";
case CustomTxType::UpdateVault: return "UpdateVault";
case CustomTxType::DepositToVault: return "DepositToVault";
case CustomTxType::WithdrawFromVault: return "WithdrawFromVault";
case CustomTxType::PaybackWithCollateral: return "PaybackWithCollateral";
case CustomTxType::TakeLoan: return "TakeLoan";
case CustomTxType::PaybackLoan: return "PaybackLoan";
case CustomTxType::PaybackLoanV2: return "PaybackLoan";
case CustomTxType::AuctionBid: return "AuctionBid";
case CustomTxType::FutureSwapExecution: return "FutureSwapExecution";
case CustomTxType::FutureSwapRefund: return "FutureSwapRefund";
case CustomTxType::TokenSplit: return "TokenSplit";
case CustomTxType::Reject: return "Reject";
case CustomTxType::CreateCfp: return "CreateCfp";
case CustomTxType::CFPFeeRedistribution: return "CFPFeeRedistribution";
case CustomTxType::CreateVoc: return "CreateVoc";
case CustomTxType::Vote: return "Vote";
case CustomTxType::None: return "None";
}
return "None";
}
Expand Down Expand Up @@ -675,10 +676,9 @@ Res CCustomTxVisitor::CheckCustomTx() const
return Res::Ok();
}

Res CCustomTxVisitor::CheckProposalTx(uint8_t type) const
Res CCustomTxVisitor::CheckProposalTx(const CCreatePropMessage& msg) const
{
auto propType = static_cast<CPropType>(type);
if (tx.vout[0].nValue != GetPropsCreationFee(height, propType) || tx.vout[0].nTokenId != DCT_ID{0})
if (tx.vout[0].nValue != GetPropsCreationFee(height, msg) || tx.vout[0].nTokenId != DCT_ID{0})
return Res::Err("malformed tx vouts (wrong creation fee)");

return Res::Ok();
Expand Down Expand Up @@ -3855,7 +3855,7 @@ class CCustomTxApplyVisitor : public CCustomTxVisitor
return Res::Err("unsupported proposal type");
}

res = CheckProposalTx(obj.type);
res = CheckProposalTx(obj);
if (!res)
return res;

Expand Down Expand Up @@ -4108,12 +4108,20 @@ Res ApplyCustomTx(CCustomCSView& mnview, const CCoinsViewCache& coins, const CTr
// Track burn fee
if (txType == CustomTxType::CreateToken
|| txType == CustomTxType::CreateMasternode
|| txType == CustomTxType::CreateCfp
|| txType == CustomTxType::CreateVoc) {
if (writers) {
writers->AddFeeBurn(tx.vout[0].scriptPubKey, tx.vout[0].nValue);
}
}

if (txType == CustomTxType::CreateCfp) {
// burn half of creation fee, the rest is distributed among voting masternodes
auto burnFee = tx.vout[0].nValue / 2;
if (writers) {
writers->AddFeeBurn(tx.vout[0].scriptPubKey, burnFee);
}
}

if (txType == CustomTxType::Vault) {
// burn the half, the rest is returned on close vault
auto burnFee = tx.vout[0].nValue / 2;
Expand Down
70 changes: 36 additions & 34 deletions src/masternodes/mn_checks.h
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ class CCustomTxVisitor
Res HasCollateralAuth(const uint256& collateralTx) const;
Res HasFoundationAuth() const;
Res CheckMasternodeCreationTx() const;
Res CheckProposalTx(uint8_t type) const;
Res CheckProposalTx(const CCreatePropMessage& msg) const;
Res CheckTokenCreationTx() const;
Res CheckCustomTx() const;
Res TransferTokenBalance(DCT_ID id, CAmount amount, CScript const& from, CScript const& to) const;
Expand Down Expand Up @@ -78,46 +78,46 @@ enum class CustomTxType : uint8_t
Reject = 1, // Invalid TX type. Returned by GuessCustomTxType on invalid custom TX.

// masternodes:
CreateMasternode = 'C',
ResignMasternode = 'R',
UpdateMasternode = 'm',
CreateMasternode = 'C',
ResignMasternode = 'R',
UpdateMasternode = 'm',
// custom tokens:
CreateToken = 'T',
MintToken = 'M',
UpdateToken = 'N', // previous type, only DAT flag triggers
UpdateTokenAny = 'n', // new type of token's update with any flags/fields possible
CreateToken = 'T',
MintToken = 'M',
UpdateToken = 'N', // previous type, only DAT flag triggers
UpdateTokenAny = 'n', // new type of token's update with any flags/fields possible
//poolpair
CreatePoolPair = 'p',
UpdatePoolPair = 'u',
PoolSwap = 's',
PoolSwapV2 = 'i',
AddPoolLiquidity = 'l',
RemovePoolLiquidity = 'r',
CreatePoolPair = 'p',
UpdatePoolPair = 'u',
PoolSwap = 's',
PoolSwapV2 = 'i',
AddPoolLiquidity = 'l',
RemovePoolLiquidity = 'r',
// accounts
UtxosToAccount = 'U',
AccountToUtxos = 'b',
AccountToAccount = 'B',
AnyAccountsToAccounts = 'a',
SmartContract = 'K',
FutureSwap = 'Q',
UtxosToAccount = 'U',
AccountToUtxos = 'b',
AccountToAccount = 'B',
AnyAccountsToAccounts = 'a',
SmartContract = 'K',
FutureSwap = 'Q',
//set governance variable
SetGovVariable = 'G',
SetGovVariableHeight = 'j',
SetGovVariable = 'G',
SetGovVariableHeight = 'j',
// Auto auth TX
AutoAuthPrep = 'A',
AutoAuthPrep = 'A',
// oracles
AppointOracle = 'o',
RemoveOracleAppoint = 'h',
UpdateOracleAppoint = 't',
SetOracleData = 'y',
AppointOracle = 'o',
RemoveOracleAppoint = 'h',
UpdateOracleAppoint = 't',
SetOracleData = 'y',
// ICX
ICXCreateOrder = '1',
ICXMakeOffer = '2',
ICXSubmitDFCHTLC = '3',
ICXSubmitEXTHTLC = '4',
ICXClaimDFCHTLC = '5',
ICXCloseOrder = '6',
ICXCloseOffer = '7',
ICXCreateOrder = '1',
ICXMakeOffer = '2',
ICXSubmitDFCHTLC = '3',
ICXSubmitEXTHTLC = '4',
ICXClaimDFCHTLC = '5',
ICXCloseOrder = '6',
ICXCloseOffer = '7',
// Loans
SetLoanCollateralToken = 'c',
SetLoanToken = 'g',
Expand All @@ -143,6 +143,7 @@ enum class CustomTxType : uint8_t
CreateCfp = 'z',
Vote = 'O', // NOTE: Check whether this overlapping with CreateOrder above is fine
CreateVoc = 'E', // NOTE: Check whether this overlapping with DestroyOrder above is fine
CFPFeeRedistribution = 'Y'
};

inline CustomTxType CustomTxCodeToType(uint8_t ch) {
Expand Down Expand Up @@ -202,6 +203,7 @@ inline CustomTxType CustomTxCodeToType(uint8_t ch) {
case CustomTxType::TokenSplit:
case CustomTxType::Reject:
case CustomTxType::CreateCfp:
case CustomTxType::CFPFeeRedistribution:
case CustomTxType::Vote:
case CustomTxType::CreateVoc:
case CustomTxType::None:
Expand Down
4 changes: 2 additions & 2 deletions src/masternodes/rpc_proposals.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -150,7 +150,7 @@ UniValue creategovcfp(const JSONRPCRequest& request)
std::set<CScript> auths{pm.address};
rawTx.vin = GetAuthInputsSmart(pwallet, rawTx.nVersion, auths, false /*needFoundersAuth*/, optAuthTx, request.params[1]);

CAmount cfpFee = GetPropsCreationFee(targetHeight, static_cast<CPropType>(pm.type));
CAmount cfpFee = GetPropsCreationFee(targetHeight, pm);
rawTx.vout.emplace_back(CTxOut(cfpFee, scriptMeta));

CCoinControl coinControl;
Expand Down Expand Up @@ -235,7 +235,7 @@ UniValue creategovvoc(const JSONRPCRequest& request)
std::set<CScript> auths;
rawTx.vin = GetAuthInputsSmart(pwallet, rawTx.nVersion, auths, false /*needFoundersAuth*/, optAuthTx, request.params[2]);

CAmount cfpFee = GetPropsCreationFee(targetHeight, static_cast<CPropType>(pm.type));
CAmount cfpFee = GetPropsCreationFee(targetHeight, pm);
rawTx.vout.emplace_back(CTxOut(cfpFee, scriptMeta));

CCoinControl coinControl;
Expand Down
Loading