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 1 commit
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: 14 additions & 0 deletions src/masternodes/govvariables/attributes.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -478,6 +478,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 +798,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