diff --git a/src/masternodes/govvariables/lp_splits.cpp b/src/masternodes/govvariables/lp_splits.cpp index a91d5ae1d57..f5c4c9b9127 100644 --- a/src/masternodes/govvariables/lp_splits.cpp +++ b/src/masternodes/govvariables/lp_splits.cpp @@ -33,9 +33,7 @@ UniValue LP_SPLITS::Export() const { Res LP_SPLITS::Validate(const CCustomCSView & mnview) const { CAmount total{0}; for (auto const & kv : splits) { - auto pool = mnview.GetPoolPair(kv.first); - - if (!pool) + if (!mnview.HasPoolPair(kv.first)) return Res::Err("pool with id=%s not found", kv.first.ToString()); if (kv.second < 0 || kv.second > COIN) @@ -50,15 +48,15 @@ Res LP_SPLITS::Validate(const CCustomCSView & mnview) const { } Res LP_SPLITS::Apply(CCustomCSView & mnview, uint32_t height) { - mnview.ForEachPoolPair([&] (const DCT_ID poolId, CPoolPair pool) { + mnview.ForEachPoolId([&] (DCT_ID poolId) { // we ought to reset previous value: - pool.rewardPct = 0; + CAmount rewardPct = 0; auto it = splits.find(poolId); if (it != splits.end()) { - pool.rewardPct = it->second; + rewardPct = it->second; } - mnview.SetPoolPair(poolId, height, pool); + mnview.SetRewardPct(poolId, height, rewardPct); return true; }); return Res::Ok(); diff --git a/src/masternodes/masternodes.cpp b/src/masternodes/masternodes.cpp index 0c80e5a3203..ab0d30ae419 100644 --- a/src/masternodes/masternodes.cpp +++ b/src/masternodes/masternodes.cpp @@ -745,7 +745,7 @@ bool CCustomCSView::CalculateOwnerRewards(CScript const & owner, uint32_t target if (balanceHeight >= targetHeight) { return false; } - ForEachPoolPair([&] (DCT_ID const & poolId, CLazySerialize) { + ForEachPoolId([&] (DCT_ID const & poolId) { auto height = GetShare(poolId, owner); if (!height || *height >= targetHeight) { return true; // no share or target height is before a pool share' one diff --git a/src/masternodes/poolpairs.cpp b/src/masternodes/poolpairs.cpp index 382e776dfb6..28ad9fa0be2 100644 --- a/src/masternodes/poolpairs.cpp +++ b/src/masternodes/poolpairs.cpp @@ -7,17 +7,20 @@ #include #include -const unsigned char CPoolPairView::ByID ::prefix = 'i'; -const unsigned char CPoolPairView::ByPair ::prefix = 'j'; -const unsigned char CPoolPairView::ByShare ::prefix = 'k'; -const unsigned char CPoolPairView::ByIDPair ::prefix = 'C'; -const unsigned char CPoolPairView::ByPoolSwap ::prefix = 'P'; -const unsigned char CPoolPairView::ByPoolReward ::prefix = 'I'; -const unsigned char CPoolPairView::ByDailyReward ::prefix = 'B'; -const unsigned char CPoolPairView::ByCustomReward ::prefix = 'A'; -const unsigned char CPoolPairView::ByTotalLiquidity ::prefix = 'f'; +const unsigned char CPoolPairView::ByID ::prefix = 'i'; +const unsigned char CPoolPairView::ByPair ::prefix = 'j'; +const unsigned char CPoolPairView::ByShare ::prefix = 'k'; +const unsigned char CPoolPairView::ByIDPair ::prefix = 'C'; +const unsigned char CPoolPairView::ByPoolSwap ::prefix = 'P'; +const unsigned char CPoolPairView::ByReserves ::prefix = 'R'; +const unsigned char CPoolPairView::ByRewardPct ::prefix = 'Q'; +const unsigned char CPoolPairView::ByPoolReward ::prefix = 'I'; +const unsigned char CPoolPairView::ByDailyReward ::prefix = 'B'; +const unsigned char CPoolPairView::ByCustomReward ::prefix = 'A'; +const unsigned char CPoolPairView::ByTotalLiquidity ::prefix = 'f'; struct PoolSwapValue { + bool swapEvent; CAmount blockCommissionA; CAmount blockCommissionB; @@ -25,14 +28,24 @@ struct PoolSwapValue { template inline void SerializationOp(Stream& s, Operation ser_action) { + READWRITE(swapEvent); READWRITE(blockCommissionA); READWRITE(blockCommissionB); } }; -CAmount PoolRewardPerBlock(CAmount dailyReward, CAmount rewardPct) { - return dailyReward / Params().GetConsensus().blocksPerDay() * rewardPct / COIN; -} +struct PoolReservesValue { + CAmount reserveA; + CAmount reserveB; + + ADD_SERIALIZE_METHODS; + + template + inline void SerializationOp(Stream& s, Operation ser_action) { + READWRITE(reserveA); + READWRITE(reserveB); + } +}; template ReturnType ReadValueAt(CPoolPairView * poolView, PoolHeightKey const & poolKey) { @@ -50,14 +63,15 @@ Res CPoolPairView::SetPoolPair(DCT_ID const & poolId, uint32_t height, CPoolPair } auto poolPairByID = GetPoolPair(poolId); - auto poolPairByTokens = GetPoolPair(pool.idTokenA, pool.idTokenB); + auto poolIdByTokens = ReadBy(ByPairKey{pool.idTokenA, pool.idTokenB}); - if (!poolPairByID && poolPairByTokens) { - return Res::Err("Error, there is already a poolpairwith same tokens, but different poolId"); + if ((!poolPairByID && poolIdByTokens) + || (poolPairByID && !poolIdByTokens)) { + return Res::Err("Error, there is already a poolpair with same tokens, but different poolId"); } // create new - if (!poolPairByID && !poolPairByTokens) { + if (!poolPairByID && !poolIdByTokens) { WriteBy(poolId, pool); WriteBy(ByPairKey{pool.idTokenA, pool.idTokenB}, poolId); WriteBy(ByPairKey{pool.idTokenB, pool.idTokenA}, poolId); @@ -65,36 +79,33 @@ Res CPoolPairView::SetPoolPair(DCT_ID const & poolId, uint32_t height, CPoolPair return Res::Ok(); } + if (poolId != *poolIdByTokens) { + return Res::Err("Error, PoolID is incorrect"); + } + + auto poolPairByTokens = ReadBy(poolId); + assert(poolPairByTokens); + // update - if(poolPairByTokens && poolId == poolPairByTokens->first - && poolPairByTokens->second.idTokenA == pool.idTokenA - && poolPairByTokens->second.idTokenB == pool.idTokenB) { - WriteBy(poolId, pool); - if (height < UINT_MAX) { - PoolHeightKey poolKey = {poolId, height}; - if (pool.swapEvent) { - WriteBy(poolKey, PoolSwapValue{pool.blockCommissionA, pool.blockCommissionB}); - } - if (poolPairByID->rewardPct != pool.rewardPct) { - auto dailyReward = ReadValueAt(this, {{}, height}); - WriteBy(poolKey, PoolRewardPerBlock(dailyReward, pool.rewardPct)); - } - if (poolPairByID->totalLiquidity != pool.totalLiquidity) { - WriteBy(poolKey, pool.totalLiquidity); - } + if(poolPairByID->idTokenA == pool.idTokenA + && poolPairByID->idTokenB == pool.idTokenB + && poolPairByTokens->idTokenA == pool.idTokenA + && poolPairByTokens->idTokenB == pool.idTokenB) { + if (poolPairByID->reserveA != pool.reserveA + || poolPairByID->reserveB != pool.reserveB) { + WriteBy(poolId, PoolReservesValue{pool.reserveA, pool.reserveB}); + } + PoolHeightKey poolKey = {poolId, height}; + if (pool.swapEvent) { + WriteBy(poolKey, PoolSwapValue{true, pool.blockCommissionA, pool.blockCommissionB}); + } + if (poolPairByID->totalLiquidity != pool.totalLiquidity) { + WriteBy(poolKey, pool.totalLiquidity); } return Res::Ok(); } - // errors - if (poolPairByTokens && poolId != poolPairByTokens->first) { - return Res::Err("Error, PoolID is incorrect"); - } - if (poolPairByTokens && (poolPairByTokens->second.idTokenA != pool.idTokenA - || poolPairByTokens->second.idTokenB == pool.idTokenB)) { - return Res::Err("Error, idTokenA or idTokenB is incorrect."); - } - return Res::Err("Error: Couldn't create/update pool pair."); + return Res::Err("Error, idTokenA or idTokenB is incorrect."); } Res CPoolPairView::UpdatePoolPair(DCT_ID const & poolId, uint32_t height, bool status, CAmount const & commission, CScript const & ownerAddress, CBalances const & rewards) @@ -109,12 +120,14 @@ Res CPoolPairView::UpdatePoolPair(DCT_ID const & poolId, uint32_t height, bool s if (pool.status != status) { pool.status = status; } + if (commission >= 0) { // default/not set is -1 if (commission > COIN) { return Res::Err("commission > 100%%"); } pool.commission = commission; } + if (!ownerAddress.empty()) { pool.ownerAddress = ownerAddress; } @@ -132,16 +145,32 @@ Res CPoolPairView::UpdatePoolPair(DCT_ID const & poolId, uint32_t height, bool s } } - auto res = SetPoolPair(poolId, UINT_MAX, pool); - if (!res.ok) { - return Res::Err("Update poolpair: %s" , res.msg); - } + WriteBy(poolId, pool); return Res::Ok(); } boost::optional CPoolPairView::GetPoolPair(const DCT_ID &poolId) const { - return ReadBy(poolId); + auto pool = ReadBy(poolId); + if (!pool) { + return {}; + } + if (auto reserves = ReadBy(poolId)) { + pool->reserveA = reserves->reserveA; + pool->reserveB = reserves->reserveB; + } + if (auto rewardPct = ReadBy(poolId)) { + pool->rewardPct = *rewardPct; + } + PoolHeightKey poolKey = {poolId, UINT_MAX}; + // it's safe needed by iterator creation + auto view = const_cast(this); + auto swapValue = ReadValueAt(view, poolKey); + /// @Note swapEvent isn't restored + pool->blockCommissionA = swapValue.blockCommissionA; + pool->blockCommissionB = swapValue.blockCommissionB; + pool->totalLiquidity = ReadValueAt(view, poolKey); + return pool; } boost::optional > CPoolPairView::GetPoolPair(const DCT_ID &tokenA, const DCT_ID &tokenB) const @@ -202,13 +231,12 @@ void CPoolPairView::CalculatePoolRewards(DCT_ID const & poolId, std::function(poolKey); - bool swapEvent = false; PoolSwapValue poolSwap; auto nextPoolSwap = UINT_MAX; + auto poolSwapHeight = UINT_MAX; auto itPoolSwap = LowerBound(poolKey); if (itPoolSwap.Valid() && itPoolSwap.Key().poolID == poolId) { - swapEvent = begin == itPoolSwap.Key().height; - ReadValueMoveToNext(itPoolSwap, poolId, poolSwap, nextPoolSwap); + nextPoolSwap = itPoolSwap.Key().height; } for (auto height = begin; height < end;) { @@ -223,7 +251,7 @@ void CPoolPairView::CalculatePoolRewards(DCT_ID const & poolId, std::function= nextPoolSwap) { - swapEvent = height == nextPoolSwap; + poolSwapHeight = nextPoolSwap; ReadValueMoveToNext(itPoolSwap, poolId, poolSwap, nextPoolSwap); } while (height >= nextCustomRewards) { @@ -242,7 +270,7 @@ void CPoolPairView::CalculatePoolRewards(DCT_ID const & poolId, std::functionidTokenA, feeA}, height); onReward(uint8_t(RewardType::Commission), {tokenIds->idTokenB, feeB}, height); } @@ -420,47 +447,58 @@ CAmount CPoolPairView::UpdatePoolRewards(std::function= Params().GetConsensus().BayfrontGardensHeight; bool newRewardLogic = nHeight >= Params().GetConsensus().EunosHeight; + bool newCustomRewards = nHeight >= Params().GetConsensus().ClarkeQuayHeight; constexpr uint32_t const PRECISION = 10000; // (== 100%) just searching the way to avoid arith256 inflating CAmount totalDistributed = 0; - ForEachPoolPair([&] (DCT_ID const & poolId, CPoolPair pool) { + ForEachPoolId([&] (DCT_ID const & poolId) { CAmount distributedFeeA = 0; CAmount distributedFeeB = 0; + boost::optional ownerAddress; - auto rewards = pool.rewards; - for (auto it = rewards.balances.begin(), next_it = it; it != rewards.balances.end(); it = next_it) { - ++next_it; - - // Get token balance - const auto balance = onGetBalance(pool.ownerAddress, it->first).nValue; + PoolHeightKey poolKey = {poolId, uint32_t(nHeight)}; - // Make there's enough to pay reward otherwise remove it - if (balance < it->second) { - rewards.balances.erase(it); + CBalances rewards; + if (newCustomRewards) { + if (auto pool = ReadBy(poolId)) { + rewards = std::move(pool->rewards); + ownerAddress = std::move(pool->ownerAddress); } - } - PoolHeightKey poolKey = {poolId, uint32_t(nHeight)}; - auto customRewards = ReadValueAt(this, poolKey); + for (auto it = rewards.balances.begin(), next_it = it; it != rewards.balances.end(); it = next_it) { + ++next_it; + + // Get token balance + const auto balance = onGetBalance(*ownerAddress, it->first).nValue; - if (rewards != customRewards) { - WriteBy(poolKey, rewards); + // Make there's enough to pay reward otherwise remove it + if (balance < it->second) { + rewards.balances.erase(it); + } + } + + if (rewards != ReadValueAt(this, poolKey)) { + WriteBy(poolKey, rewards); + } } - if (!pool.totalLiquidity) { + auto totalLiquidity = ReadValueAt(this, poolKey); + if (!totalLiquidity) { return true; } + auto swapValue = ReadBy(poolKey); + const auto swapEvent = swapValue && swapValue->swapEvent; auto poolReward = ReadValueAt(this, poolKey); if (newRewardLogic) { - if (pool.swapEvent) { + if (swapEvent) { // it clears block commission - distributedFeeA = pool.blockCommissionA; - distributedFeeB = pool.blockCommissionB; + distributedFeeA = swapValue->blockCommissionA; + distributedFeeB = swapValue->blockCommissionB; } // increase by pool block reward @@ -468,11 +506,11 @@ CAmount CPoolPairView::UpdatePoolRewards(std::functionblockCommissionA, liquidity, totalLiquidity); + feeB = liquidityReward(swapValue->blockCommissionB, liquidity, totalLiquidity); } else { - feeA = pool.blockCommissionA * liqWeight / PRECISION; - feeB = pool.blockCommissionB * liqWeight / PRECISION; + feeA = swapValue->blockCommissionA * liqWeight / PRECISION; + feeB = swapValue->blockCommissionB * liqWeight / PRECISION; } - if (onTransfer({}, provider, {pool.idTokenA, feeA})) { + auto tokenIds = ReadBy(poolId); + assert(tokenIds); + if (onTransfer({}, provider, {tokenIds->idTokenA, feeA})) { distributedFeeA += feeA; } - if (onTransfer({}, provider, {pool.idTokenB, feeB})) { + if (onTransfer({}, provider, {tokenIds->idTokenB, feeB})) { distributedFeeB += feeB; } } @@ -507,7 +547,7 @@ CAmount CPoolPairView::UpdatePoolRewards(std::functionblockCommissionA -= distributedFeeA; + swapValue->blockCommissionB -= distributedFeeB; + poolKey.height++; // block commissions to next block + WriteBy(poolKey, PoolSwapValue{false, swapValue->blockCommissionA, swapValue->blockCommissionB}); } return true; }); @@ -555,19 +591,46 @@ boost::optional CPoolPairView::GetShare(DCT_ID const & poolId, CScript return ReadBy(PoolShareKey{poolId, provider}); } +inline CAmount PoolRewardPerBlock(CAmount dailyReward, CAmount rewardPct) { + return dailyReward / Params().GetConsensus().blocksPerDay() * rewardPct / COIN; +} + +Res CPoolPairView::SetRewardPct(DCT_ID const & poolId, uint32_t height, CAmount rewardPct) { + if (!HasPoolPair(poolId)) { + return Res::Err("No such pool pair"); + } + WriteBy(poolId, rewardPct); + if (auto dailyReward = ReadBy(DCT_ID{})) { + WriteBy(PoolHeightKey{poolId, height}, PoolRewardPerBlock(*dailyReward, rewardPct)); + } + return Res::Ok(); +} + Res CPoolPairView::SetDailyReward(uint32_t height, CAmount reward) { - ForEachPoolPair([&](DCT_ID const & id, CPoolPair pool) { - if (pool.rewardPct != 0) { - WriteBy(PoolHeightKey{id, height}, PoolRewardPerBlock(reward, pool.rewardPct)); + ForEachPoolId([&](DCT_ID const & poolId) { + if (auto rewardPct = ReadBy(poolId)) { + WriteBy(PoolHeightKey{poolId, height}, PoolRewardPerBlock(reward, *rewardPct)); } return true; }); - WriteBy(PoolHeightKey{{}, height}, reward); + WriteBy(DCT_ID{}, reward); return Res::Ok(); } -void CPoolPairView::ForEachPoolPair(std::function)> callback, DCT_ID const & start) { - ForEach(callback, start); +bool CPoolPairView::HasPoolPair(DCT_ID const & poolId) const { + return ExistsBy(poolId); +} + +void CPoolPairView::ForEachPoolId(std::function callback, DCT_ID const & start) { + ForEach([&callback](const DCT_ID & poolId, CLazySerialize) { + return callback(poolId); + }, start); +} + +void CPoolPairView::ForEachPoolPair(std::function callback, DCT_ID const & start) { + ForEach([&](const DCT_ID & poolId, CLazySerialize) { + return callback(poolId, *GetPoolPair(poolId)); + }, start); } void CPoolPairView::ForEachPoolShare(std::function callback, const PoolShareKey &startKey) { diff --git a/src/masternodes/poolpairs.h b/src/masternodes/poolpairs.h index d185bdb1e60..67afb448d0a 100644 --- a/src/masternodes/poolpairs.h +++ b/src/masternodes/poolpairs.h @@ -91,13 +91,18 @@ class CPoolPair : public CPoolPairMessage CPoolPair(CPoolPairMessage const & msg = {}) : CPoolPairMessage(msg) {} virtual ~CPoolPair() = default; - CBalances rewards; - CAmount reserveA = 0, reserveB = 0, totalLiquidity = 0; - CAmount blockCommissionA = 0, blockCommissionB = 0; + // temporary values, not serialized + CAmount reserveA = 0; + CAmount reserveB = 0; + CAmount totalLiquidity = 0; + CAmount blockCommissionA = 0; + CAmount blockCommissionB = 0; CAmount rewardPct = 0; // pool yield farming reward %% bool swapEvent = false; + // serialized + CBalances rewards; uint256 creationTx; uint32_t creationHeight = -1; @@ -130,16 +135,9 @@ class CPoolPair : public CPoolPairMessage if (!ser_action.ForRead()) ioProofer(); READWRITEAS(CPoolPairMessage, *this); - READWRITE(reserveA); - READWRITE(reserveB); - READWRITE(totalLiquidity); - READWRITE(blockCommissionA); - READWRITE(blockCommissionB); - READWRITE(rewardPct); - READWRITE(swapEvent); + READWRITE(rewards); READWRITE(creationTx); READWRITE(creationHeight); - READWRITE(rewards); if (ser_action.ForRead()) ioProofer(); } @@ -202,7 +200,8 @@ class CPoolPairView : public virtual CStorageView boost::optional GetPoolPair(const DCT_ID &poolId) const; boost::optional > GetPoolPair(DCT_ID const & tokenA, DCT_ID const & tokenB) const; - void ForEachPoolPair(std::function)> callback, DCT_ID const & start = DCT_ID{0}); + void ForEachPoolId(std::function callback, DCT_ID const & start = DCT_ID{0}); + void ForEachPoolPair(std::function callback, DCT_ID const & start = DCT_ID{0}); void ForEachPoolShare(std::function callback, PoolShareKey const &startKey = {}); Res SetShare(DCT_ID const & poolId, CScript const & provider, uint32_t height); @@ -213,6 +212,8 @@ class CPoolPairView : public virtual CStorageView void CalculatePoolRewards(DCT_ID const & poolId, std::function onLiquidity, uint32_t begin, uint32_t end, std::function onReward); Res SetDailyReward(uint32_t height, CAmount reward); + Res SetRewardPct(DCT_ID const & poolId, uint32_t height, CAmount rewardPct); + bool HasPoolPair(DCT_ID const & poolId) const; CAmount UpdatePoolRewards(std::function onGetBalance, std::function onTransfer, int nHeight = 0); @@ -222,6 +223,8 @@ class CPoolPairView : public virtual CStorageView struct ByShare { static const unsigned char prefix; }; // lsTokenID+accountID -> {} struct ByIDPair { static const unsigned char prefix; }; // lsTokenID -> tokenA+tokenB struct ByPoolSwap { static const unsigned char prefix; }; + struct ByReserves { static const unsigned char prefix; }; + struct ByRewardPct { static const unsigned char prefix; }; struct ByPoolReward { static const unsigned char prefix; }; struct ByDailyReward { static const unsigned char prefix; }; struct ByCustomReward { static const unsigned char prefix; }; diff --git a/src/masternodes/rpc_accounts.cpp b/src/masternodes/rpc_accounts.cpp index 2f5b1706a5c..a33bf88bf92 100644 --- a/src/masternodes/rpc_accounts.cpp +++ b/src/masternodes/rpc_accounts.cpp @@ -96,7 +96,7 @@ UniValue outputEntryToJSON(COutputEntry const & entry, CBlockIndex const * index static void onPoolRewards(CCustomCSView & view, CScript const & owner, uint32_t begin, uint32_t end, std::function onReward) { CCustomCSView mnview(view); - view.ForEachPoolPair([&] (DCT_ID const & poolId, CLazySerialize) { + view.ForEachPoolId([&] (DCT_ID const & poolId) { auto height = view.GetShare(poolId, owner); if (!height || *height >= end) { return true; // no share or target height is before a pool share' one diff --git a/src/masternodes/rpc_poolpair.cpp b/src/masternodes/rpc_poolpair.cpp index 3044ff79f41..a5db2c09850 100644 --- a/src/masternodes/rpc_poolpair.cpp +++ b/src/masternodes/rpc_poolpair.cpp @@ -185,10 +185,10 @@ UniValue listpoolpairs(const JSONRPCRequest& request) { LOCK(cs_main); UniValue ret(UniValue::VOBJ); - pcustomcsview->ForEachPoolPair([&](DCT_ID const & id, CLazySerialize pool) { + pcustomcsview->ForEachPoolPair([&](DCT_ID const & id, CPoolPair pool) { const auto token = pcustomcsview->GetToken(id); if (token) { - ret.pushKVs(poolToJSON(id, pool.get(), *token, verbose)); + ret.pushKVs(poolToJSON(id, pool, *token, verbose)); } limit--; diff --git a/src/test/liquidity_tests.cpp b/src/test/liquidity_tests.cpp index 4b723b4c69c..947f5531d65 100644 --- a/src/test/liquidity_tests.cpp +++ b/src/test/liquidity_tests.cpp @@ -242,10 +242,7 @@ BOOST_AUTO_TEST_CASE(math_liquidity_and_trade) void SetPoolRewardPct(CCustomCSView & mnview, DCT_ID idPool, CAmount pct) { - auto optPool = mnview.GetPoolPair(idPool); - BOOST_REQUIRE(optPool); - optPool->rewardPct = pct; - mnview.SetPoolPair(idPool, 1, *optPool); + BOOST_REQUIRE(mnview.SetRewardPct(idPool, 1, pct)); } void SetPoolTradeFees(CCustomCSView & mnview, DCT_ID idPool, CAmount A, CAmount B) @@ -274,7 +271,7 @@ BOOST_AUTO_TEST_CASE(math_rewards) } // create shares - mnview.ForEachPoolPair([&] (DCT_ID const & idPool, CLazySerialize) { + mnview.ForEachPoolId([&] (DCT_ID const & idPool) { // printf("pool id = %s\n", idPool.ToString().c_str()); for (int i = 0; i < ProvidersCount; ++i) { CScript shareAddress = CScript(idPool.v * ProvidersCount + i); @@ -303,7 +300,7 @@ BOOST_AUTO_TEST_CASE(math_rewards) /// DCT_ID{10} - 0 // set "traded fees" here too, just to estimate proc.load - cache.ForEachPoolPair([&] (DCT_ID const & idPool, CLazySerialize) { + cache.ForEachPoolId([&] (DCT_ID const & idPool) { SetPoolTradeFees(cache, idPool, idPool.v * COIN, idPool.v * COIN*2); return true; }); @@ -373,7 +370,7 @@ BOOST_AUTO_TEST_CASE(owner_rewards) } // create shares - mnview.ForEachPoolPair([&] (DCT_ID const & idPool, CLazySerialize) { + mnview.ForEachPoolId([&] (DCT_ID const & idPool) { for (int i = 0; i < PoolCount; ++i) { Res res = AddPoolLiquidity(mnview, idPool, idPool.v*COIN, idPool.v*COIN, shareAddress[i]); BOOST_CHECK(res.ok); @@ -382,12 +379,12 @@ BOOST_AUTO_TEST_CASE(owner_rewards) }); mnview.ForEachPoolPair([&] (DCT_ID const & idPool, CPoolPair pool) { - pool.rewardPct = COIN/(idPool.v + 1); pool.blockCommissionA = idPool.v * COIN; pool.blockCommissionB = idPool.v * COIN * 2; pool.swapEvent = true; pool.ownerAddress = shareAddress[0]; mnview.SetPoolPair(idPool, 1, pool); + mnview.SetRewardPct(idPool, 1, COIN/(idPool.v + 1)); return true; }); diff --git a/test/functional/feature_poolpair.py b/test/functional/feature_poolpair.py index bd71f0f1fa7..f5715506657 100755 --- a/test/functional/feature_poolpair.py +++ b/test/functional/feature_poolpair.py @@ -102,7 +102,7 @@ def run_test(self): }, []) except JSONRPCException as e: errorString = e.error['message'] - assert("Error, there is already a poolpairwith same tokens, but different poolId" in errorString) + assert("Error, there is already a poolpair with same tokens, but different poolId" in errorString) # Creating another one trPP = self.nodes[0].createpoolpair({