Skip to content

Commit

Permalink
Add logging for token splits
Browse files Browse the repository at this point in the history
  • Loading branch information
wafflespeanut committed May 24, 2022
1 parent b0a9e04 commit b941457
Showing 1 changed file with 13 additions and 3 deletions.
16 changes: 13 additions & 3 deletions src/validation.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3711,6 +3711,8 @@ void CChainState::ProcessTokenToGovVar(const CBlockIndex* pindex, CCustomCSView&
cache.EraseLoanCollateralToken(token);
}
}

LogPrintf("Migrated %d loan tokens and %d collateral tokens (height: %d)\n", loanCount, collateralCount, pindex->nHeight);
} catch(std::out_of_range&) {
LogPrintf("Non-existant map entry referenced in loan/collateral token to Gov var migration\n");
}
Expand Down Expand Up @@ -3824,6 +3826,9 @@ static Res PoolSplits(CCustomCSView& view, CAmount& totalBalance, ATTRIBUTES& at
throw std::runtime_error(strprintf("Failed to get related pool: %d", oldPoolId.v));
}

LogPrintf("Old pool pair (a: %d / b: %d), reserve (a: %d, b: %d), liquidity: %d\n",
oldPoolPair->idTokenA.v, oldPoolPair->idTokenB.v, oldPoolPair->reserveA, oldPoolPair->reserveB, oldPoolPair->totalLiquidity);

CPoolPair newPoolPair{*oldPoolPair};
if (oldPoolPair->idTokenA == oldTokenId) {
newPoolPair.idTokenA = newTokenId;
Expand All @@ -3849,6 +3854,8 @@ static Res PoolSplits(CCustomCSView& view, CAmount& totalBalance, ATTRIBUTES& at
return true;
});

LogPrintf("Migrating %d balances from old pool\n", balancesToMigrate.size());

// Largest first to make sure we are over MINIMUM_LIQUIDITY on first call to AddLiquidity
std::sort(balancesToMigrate.begin(), balancesToMigrate.end(), [](const std::pair<CScript, CAmount>&a, const std::pair<CScript, CAmount>& b){
return a.second > b.second;
Expand Down Expand Up @@ -3956,6 +3963,9 @@ static Res PoolSplits(CCustomCSView& view, CAmount& totalBalance, ATTRIBUTES& at
throw std::runtime_error(strprintf("totalLiquidity should be zero. Remainder: %d", oldPoolPair->totalLiquidity));
}

LogPrintf("New pool pair (a: %d / b: %d), reserve (a: %d, b: %d), liquidity: %d\n",
newPoolPair.idTokenA.v, newPoolPair.idTokenB.v, newPoolPair.reserveA, newPoolPair.reserveB, newPoolPair.totalLiquidity);

res = view.SetPoolPair(newPoolId, pindex->nHeight, newPoolPair);
if (!res) {
throw std::runtime_error(strprintf("SetPoolPair on new pool pair: %s", res.msg));
Expand Down Expand Up @@ -3993,8 +4003,6 @@ static Res PoolSplits(CCustomCSView& view, CAmount& totalBalance, ATTRIBUTES& at
if (!res) {
throw std::runtime_error(res.msg);
}


}
} catch (const std::runtime_error& e) {
return Res::Err(e.what());
Expand Down Expand Up @@ -4163,6 +4171,7 @@ void CChainState::ProcessTokenSplits(const CBlock& block, const CBlockIndex* pin
}

const DCT_ID newTokenId{resVal.val->v};
LogPrintf("Token split %d (symbol: %s, old token id: %d, new token id: %d)\n", id, token->symbol, oldTokenId.v, newTokenId.v);

std::vector<CDataStructureV0> eraseKeys;
for (const auto& [key, value] : attributes->GetAttributesMap()) {
Expand Down Expand Up @@ -4204,7 +4213,7 @@ void CChainState::ProcessTokenSplits(const CBlock& block, const CBlockIndex* pin
CAccounts addAccounts;
CAccounts subAccounts;

view.ForEachBalance([&, multiplier = multiplier](CScript const & owner, const CTokenAmount& balance) {
view.ForEachBalance([&, multiplier = multiplier](CScript const& owner, const CTokenAmount& balance) {
if (oldTokenId.v == balance.nTokenId.v) {
const auto newBalance = CalculateNewAmount(multiplier, balance.nValue);
addAccounts[owner].Add({newTokenId, newBalance});
Expand All @@ -4214,6 +4223,7 @@ void CChainState::ProcessTokenSplits(const CBlock& block, const CBlockIndex* pin
return true;
});

LogPrintf("Token split %d (symbol: %s, add: %d, sub: %d, balance: %d)\n", id, token->symbol, newTokenId.v, addAccounts.size(), subAccounts.size(), totalBalance);
res = view.AddMintedTokens(newTokenId, totalBalance);
if (!res) {
LogPrintf("%s: Token split failed. %s\n", __func__, res.msg);
Expand Down

0 comments on commit b941457

Please sign in to comment.