Skip to content

Commit

Permalink
DFI to DUSD FutureSwap (#1355)
Browse files Browse the repository at this point in the history
* DFI-to-DUSD FutureSwap

* Change commission fix fork

* Rename interest burn attribute keys

Co-authored-by: Prasanna Loganathar <[email protected]>
  • Loading branch information
Bushstar and prasannavl authored Jun 25, 2022
1 parent 53575a4 commit 89fa3a7
Show file tree
Hide file tree
Showing 20 changed files with 1,035 additions and 219 deletions.
4 changes: 4 additions & 0 deletions src/chainparams.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -253,6 +253,7 @@ class CMainParams : public CChainParams {
consensus.smartContracts.clear();
consensus.smartContracts[SMART_CONTRACT_DFIP_2201] = GetScriptForDestination(CTxDestination(WitnessV0KeyHash(std::vector<unsigned char>{0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0})));
consensus.smartContracts[SMART_CONTRACT_DFIP_2203] = GetScriptForDestination(CTxDestination(WitnessV0KeyHash(std::vector<unsigned char>{0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1})));
consensus.smartContracts[SMART_CONTRACT_DFIP2206F] = GetScriptForDestination(CTxDestination(WitnessV0KeyHash(std::vector<unsigned char>{0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,2})));

// owner base58, operator base58
vMasternodes.push_back({"8PuErAcazqccCVzRcc8vJ3wFaZGm4vFbLe", "8J846CKFF83Jcj5m4EReJmxiaJ6Jy1Y6Ea"});
Expand Down Expand Up @@ -480,6 +481,7 @@ class CTestNetParams : public CChainParams {
consensus.smartContracts.clear();
consensus.smartContracts[SMART_CONTRACT_DFIP_2201] = GetScriptForDestination(CTxDestination(WitnessV0KeyHash(std::vector<unsigned char>{0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0})));
consensus.smartContracts[SMART_CONTRACT_DFIP_2203] = GetScriptForDestination(CTxDestination(WitnessV0KeyHash(std::vector<unsigned char>{0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1})));
consensus.smartContracts[SMART_CONTRACT_DFIP2206F] = GetScriptForDestination(CTxDestination(WitnessV0KeyHash(std::vector<unsigned char>{0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,2})));

// owner base58, operator base58
vMasternodes.push_back({"7LMorkhKTDjbES6DfRxX2RiNMbeemUkxmp", "7KEu9JMKCx6aJ9wyg138W3p42rjg19DR5D"});
Expand Down Expand Up @@ -666,6 +668,7 @@ class CDevNetParams : public CChainParams {
consensus.smartContracts.clear();
consensus.smartContracts[SMART_CONTRACT_DFIP_2201] = GetScriptForDestination(CTxDestination(WitnessV0KeyHash(std::vector<unsigned char>{0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0})));
consensus.smartContracts[SMART_CONTRACT_DFIP_2203] = GetScriptForDestination(CTxDestination(WitnessV0KeyHash(std::vector<unsigned char>{0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1})));
consensus.smartContracts[SMART_CONTRACT_DFIP2206F] = GetScriptForDestination(CTxDestination(WitnessV0KeyHash(std::vector<unsigned char>{0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,2})));

// owner base58, operator base58
vMasternodes.push_back({"7M3g9CSERjLdXisE5pv2qryDbURUj9Vpi1", "7Grgx69MZJ4wDKRx1bBxLqTnU9T3quKW7n"});
Expand Down Expand Up @@ -858,6 +861,7 @@ class CRegTestParams : public CChainParams {
consensus.smartContracts.clear();
consensus.smartContracts[SMART_CONTRACT_DFIP_2201] = GetScriptForDestination(CTxDestination(WitnessV0KeyHash(std::vector<unsigned char>{0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0})));
consensus.smartContracts[SMART_CONTRACT_DFIP_2203] = GetScriptForDestination(CTxDestination(WitnessV0KeyHash(std::vector<unsigned char>{0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1})));
consensus.smartContracts[SMART_CONTRACT_DFIP2206F] = GetScriptForDestination(CTxDestination(WitnessV0KeyHash(std::vector<unsigned char>{0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,2})));

// owner base58, operator base58
vMasternodes.push_back({"mwsZw8nF7pKxWH8eoKL9tPxTpaFkz7QeLU", "mswsMVsyGMj1FzDMbbxw2QW3KvQAv2FKiy"});
Expand Down
1 change: 1 addition & 0 deletions src/chainparams.h
Original file line number Diff line number Diff line change
Expand Up @@ -128,6 +128,7 @@ class CChainParams

const auto SMART_CONTRACT_DFIP_2201 = "DFIP2201";
const auto SMART_CONTRACT_DFIP_2203 = "DFIP2203";
const auto SMART_CONTRACT_DFIP2206F = "DFIP2206F";

/**
* Creates and returns a std::unique_ptr<CChainParams> of the chosen chain.
Expand Down
25 changes: 14 additions & 11 deletions src/masternodes/accounts.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -122,22 +122,25 @@ Res CAccountsView::EraseFuturesUserValues(const CFuturesUserKey& key)
return Res::Ok();
}

std::optional<uint32_t> CAccountsView::GetMostRecentFuturesHeight()
Res CAccountsView::StoreFuturesDUSD(const CFuturesUserKey& key, const CAmount& amount)
{
const CFuturesUserKey key{std::numeric_limits<uint32_t>::max(), {}, std::numeric_limits<uint32_t>::max()};
auto it = LowerBound<ByFuturesSwapKey>(key);
if (it.Valid()) {
return it.Key().height;
if (!WriteBy<ByFuturesDUSDKey>(key, amount)) {
return Res::Err("Failed to store futures");
}

return {};
return Res::Ok();
}

void CAccountsView::ForEachFuturesDUSD(std::function<bool(const CFuturesUserKey&, const CAmount&)> callback, const CFuturesUserKey& start)
{
ForEach<ByFuturesDUSDKey, CFuturesUserKey, CAmount>(callback, start);
}

ResVal<CFuturesUserValue> CAccountsView::GetFuturesUserValues(const CFuturesUserKey& key) {
CFuturesUserValue source;
if (!ReadBy<ByFuturesSwapKey>(key, source)) {
return Res::Err("Failed to read futures source");
Res CAccountsView::EraseFuturesDUSD(const CFuturesUserKey& key)
{
if (!EraseBy<ByFuturesDUSDKey>(key)) {
return Res::Err("Failed to erase futures");
}

return {source, Res::Ok()};
return Res::Ok();
}
8 changes: 6 additions & 2 deletions src/masternodes/accounts.h
Original file line number Diff line number Diff line change
Expand Up @@ -70,16 +70,20 @@ class CAccountsView : public virtual CStorageView
Res UpdateBalancesHeight(CScript const & owner, uint32_t height);

Res StoreFuturesUserValues(const CFuturesUserKey& key, const CFuturesUserValue& futures);
ResVal<CFuturesUserValue> GetFuturesUserValues(const CFuturesUserKey& key);
Res EraseFuturesUserValues(const CFuturesUserKey& key);
std::optional<uint32_t> GetMostRecentFuturesHeight();
void ForEachFuturesUserValues(std::function<bool(const CFuturesUserKey&, const CFuturesUserValue&)> callback, const CFuturesUserKey& start =
{std::numeric_limits<uint32_t>::max(), {}, std::numeric_limits<uint32_t>::max()});

Res StoreFuturesDUSD(const CFuturesUserKey& key, const CAmount& amount);
Res EraseFuturesDUSD(const CFuturesUserKey& key);
void ForEachFuturesDUSD(std::function<bool(const CFuturesUserKey&, const CAmount&)> callback, const CFuturesUserKey& start =
{std::numeric_limits<uint32_t>::max(), {}, std::numeric_limits<uint32_t>::max()});

// tags
struct ByBalanceKey { static constexpr uint8_t prefix() { return 'a'; } };
struct ByHeightKey { static constexpr uint8_t prefix() { return 'b'; } };
struct ByFuturesSwapKey { static constexpr uint8_t prefix() { return 'J'; } };
struct ByFuturesDUSDKey { static constexpr uint8_t prefix() { return 'm'; } };

private:
Res SetBalance(CScript const & owner, CTokenAmount amount);
Expand Down
Loading

0 comments on commit 89fa3a7

Please sign in to comment.