Skip to content

Commit

Permalink
Add fee_pct alias for reward_pct (#1359)
Browse files Browse the repository at this point in the history
* Add fee_pct alias for reward_pct

* Fix tests

* Add DFIP2206-F test note

Co-authored-by: Prasanna Loganathar <[email protected]>
  • Loading branch information
Bushstar and prasannavl authored Jun 27, 2022
1 parent a73f92d commit 1a61692
Show file tree
Hide file tree
Showing 5 changed files with 29 additions and 2 deletions.
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

0 comments on commit 1a61692

Please sign in to comment.