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

Add fee_pct alias for reward_pct #1359

Merged
merged 3 commits into from
Jun 27, 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
18 changes: 18 additions & 0 deletions src/masternodes/govvariables/attributes.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,8 @@ const std::map<std::string, uint8_t>& ATTRIBUTES::allowedParamIDs() {
{"dfip2201", ParamIDs::DFIP2201},
{"dfip2203", ParamIDs::DFIP2203},
{"dfip2206a", ParamIDs::DFIP2206A},
// Note: DFIP2206F is currently in beta testing
// for testnet. May not be enabled on mainnet until testing is complete.
{"dfip2206f", ParamIDs::DFIP2206F},
};
return params;
Expand All @@ -96,6 +98,8 @@ const std::map<uint8_t, std::string>& ATTRIBUTES::displayParamsIDs() {
{ParamIDs::DFIP2201, "dfip2201"},
{ParamIDs::DFIP2203, "dfip2203"},
{ParamIDs::DFIP2206A, "dfip2206a"},
// Note: DFIP2206F is currently in beta testing
// for testnet. May not be enabled on mainnet until testing is complete.
{ParamIDs::DFIP2206F, "dfip2206f"},
{ParamIDs::TokenID, "token"},
{ParamIDs::Economy, "economy"},
Expand Down Expand Up @@ -478,6 +482,11 @@ Res ATTRIBUTES::ProcessVariable(const std::string& key, const std::string& value
return Res::Err("Unsupported type {%d}", type);
}

// Alias of reward_pct in Export.
if (keys[3] == "fee_pct") {
return Res::Ok();
}

itype = ikey->second.find(keys[3]);
if (itype == ikey->second.end()) {
return ::ShowError("key", ikey->second);
Expand Down Expand Up @@ -793,6 +802,15 @@ UniValue ATTRIBUTES::ExportFiltered(GovVarsFilter filter, const std::string &pre
decimalStr.pop_back();
}
ret.pushKV(key, decimalStr);

// Create fee_pct alias of reward_pct.
if (v0Key == "reward_pct") {
const auto newKey = KeyBuilder(displayVersions().at(VersionTypes::v0),
displayTypes().at(attrV0->type),
id,
"fee_pct");
ret.pushKV(newKey, decimalStr);
}
}
} else if (const auto balances = std::get_if<CBalances>(&attribute.second)) {
ret.pushKV(key, AmountsToJSON(balances->balances));
Expand Down
11 changes: 10 additions & 1 deletion test/functional/feature_futures.py
Original file line number Diff line number Diff line change
Expand Up @@ -243,6 +243,7 @@ def futures_setup(self):
result = self.nodes[0].getgov('ATTRIBUTES')['ATTRIBUTES']
assert_equal(result['v0/params/dfip2203/active'], 'true')
assert_equal(result['v0/params/dfip2203/reward_pct'], '0.05')
assert_equal(result['v0/params/dfip2203/fee_pct'], '0.05')
assert_equal(result['v0/params/dfip2203/block_period'], str(self.futures_interval))

# Disable DUSD
Expand Down Expand Up @@ -1129,7 +1130,7 @@ def dfi_to_dusd(self):
# Set DFI-to-DUSD Gov vars
self.nodes[0].setgov({"ATTRIBUTES":{
'v0/params/dfip2206f/reward_pct': '0.01',
'v0/params/dfip2206f/block_period': str(self.futures_interval_dusd),
'v0/params/dfip2206f/block_period': f'{self.futures_interval_dusd}',
'v0/params/dfip2206f/start_block': f'{self.start_block_dusd}'
}})
self.nodes[0].generate(1)
Expand All @@ -1138,6 +1139,14 @@ def dfi_to_dusd(self):
self.nodes[0].setgov({"ATTRIBUTES":{'v0/params/dfip2206f/active':'true'}})
self.nodes[0].generate(1)

# Verify Gov vars
result = self.nodes[0].getgov('ATTRIBUTES')['ATTRIBUTES']
assert_equal(result['v0/params/dfip2206f/active'], 'true')
assert_equal(result['v0/params/dfip2206f/reward_pct'], '0.01')
assert_equal(result['v0/params/dfip2206f/fee_pct'], '0.01')
assert_equal(result['v0/params/dfip2206f/block_period'], f'{self.futures_interval_dusd}')
assert_equal(result['v0/params/dfip2206f/start_block'], f'{self.start_block_dusd}')

# Test cannot create a future swap until active
assert_raises_rpc_error(-32600, f'DFIP2206F not active until block {self.start_block_dusd}', self.nodes[0].futureswap, address, f'1@{self.symbolDFI}', f'{self.symbolDUSD}')

Expand Down
Empty file modified test/functional/feature_loan_get_interest.py
100644 → 100755
Empty file.
Empty file modified test/functional/feature_rpcstats.py
100644 → 100755
Empty file.
2 changes: 1 addition & 1 deletion test/functional/feature_setgov.py
Original file line number Diff line number Diff line change
Expand Up @@ -628,7 +628,7 @@ def run_test(self):
assert_equal(result, result_27)
assert_equal(result, result_all)

assert_equal(result, [[{'ICX_TAKERFEE_PER_BTC': Decimal('0.00200000')}], [{'LP_DAILY_LOAN_TOKEN_REWARD': Decimal('13020.86331792')}], [{'LP_LOAN_TOKEN_SPLITS': {'1': Decimal('0.10000000'), '2': Decimal('0.20000000'), '3': Decimal('0.70000000')}}], [{'LP_DAILY_DFI_REWARD': Decimal('13427.10581184')}], [{'LOAN_LIQUIDATION_PENALTY': Decimal('0.01000000')}], [{'LP_SPLITS': {'1': Decimal('0.70000000'), '2': Decimal('0.20000000'), '3': Decimal('0.10000000')}}], [{'ORACLE_BLOCK_INTERVAL': 30}], [{'ORACLE_DEVIATION': Decimal('0.07000000')}], [{'ATTRIBUTES': {'v0/params/dfip2201/active': 'true', 'v0/params/dfip2201/premium': '0.025', 'v0/params/dfip2201/minswap': '0.001', 'v0/params/dfip2203/active': 'true', 'v0/params/dfip2203/reward_pct': '0.05', 'v0/params/dfip2203/block_period': '20160', 'v0/token/5/payback_dfi': 'true', 'v0/token/5/payback_dfi_fee_pct': '0.33', 'v0/token/5/loan_payback/1': 'true', 'v0/token/5/loan_payback/2': 'true', 'v0/token/5/loan_payback_fee_pct/1': '0.25', 'v0/token/5/dex_in_fee_pct': '0.6', 'v0/token/5/dex_out_fee_pct': '0.12', 'v0/token/5/dfip2203': 'true'}}]])
assert_equal(result, [[{'ICX_TAKERFEE_PER_BTC': Decimal('0.00200000')}], [{'LP_DAILY_LOAN_TOKEN_REWARD': Decimal('13020.86331792')}], [{'LP_LOAN_TOKEN_SPLITS': {'1': Decimal('0.10000000'), '2': Decimal('0.20000000'), '3': Decimal('0.70000000')}}], [{'LP_DAILY_DFI_REWARD': Decimal('13427.10581184')}], [{'LOAN_LIQUIDATION_PENALTY': Decimal('0.01000000')}], [{'LP_SPLITS': {'1': Decimal('0.70000000'), '2': Decimal('0.20000000'), '3': Decimal('0.10000000')}}], [{'ORACLE_BLOCK_INTERVAL': 30}], [{'ORACLE_DEVIATION': Decimal('0.07000000')}], [{'ATTRIBUTES': {'v0/params/dfip2201/active': 'true', 'v0/params/dfip2201/premium': '0.025', 'v0/params/dfip2201/minswap': '0.001', 'v0/params/dfip2203/active': 'true', 'v0/params/dfip2203/reward_pct': '0.05', 'v0/params/dfip2203/fee_pct': '0.05', 'v0/params/dfip2203/block_period': '20160', 'v0/token/5/payback_dfi': 'true', 'v0/token/5/payback_dfi_fee_pct': '0.33', 'v0/token/5/loan_payback/1': 'true', 'v0/token/5/loan_payback/2': 'true', 'v0/token/5/loan_payback_fee_pct/1': '0.25', 'v0/token/5/dex_in_fee_pct': '0.6', 'v0/token/5/dex_out_fee_pct': '0.12', 'v0/token/5/dfip2203': 'true'}}]])

# Check errors
assert_raises_rpc_error(-32600, "ATTRIBUTES: Cannot be set before FortCanningCrunch", self.nodes[0].setgov, {"ATTRIBUTES":{'v0/locks/token/5':'true'}})
Expand Down