Browse Source

Fix NFT currency pricing and import fees

pull/446/head
miketout 2 years ago
parent
commit
903ccea9c4
  1. 10
      src/pbaas/crosschainrpc.h
  2. 13
      src/pbaas/pbaas.cpp
  3. 16
      src/pbaas/reserves.cpp
  4. 6
      src/rpc/pbaasrpc.cpp

10
src/pbaas/crosschainrpc.h

@ -908,14 +908,22 @@ public:
{
return pbaasSystemLaunchFee;
}
else if (currencyOptions & OPTION_NFT_TOKEN)
{
return idImportFees;
}
else
{
return currencyRegistrationFee;
}
}
int64_t GetCurrencyImportFee() const
int64_t GetCurrencyImportFee(bool isTokenizedControlCurrency=false) const
{
if ((proofProtocol == PROOF_PBAASMMR || proofProtocol == PROOF_CHAINID) && isTokenizedControlCurrency)
{
return idImportFees;
}
return currencyImportFee;
}

13
src/pbaas/pbaas.cpp

@ -576,9 +576,18 @@ bool PrecheckCrossChainImport(const CTransaction &tx, int32_t outNum, CValidatio
}
else if (oneTransfer.IsCurrencyExport())
{
CCurrencyDefinition exportingDef = CCurrencyDefinition(oneTransfer.destination.destination);
if (!exportingDef.IsValid())
{
return state.Error(strprintf("%s: Invalid currency import", __func__));
}
// TODO: HARDENING - imported currencies do need to conform to type constraints in order
// to benefit from reduced import fees
if ((oneTransfer.HasNextLeg() && oneTransfer.destination.gatewayID != ASSETCHAINS_CHAINID ?
nextLegFeeEquiv :
feeEquivalent) < ConnectedChains.ThisChain().GetCurrencyImportFee())
feeEquivalent) < ConnectedChains.ThisChain().GetCurrencyImportFee(exportingDef.ChainOptions() & exportingDef.OPTION_NFT_TOKEN))
{
return state.Error("Insufficient fee for currency import: " + cci.ToUniValue().write(1,2));
}
@ -2561,7 +2570,7 @@ bool PrecheckReserveTransfer(const CTransaction &tx, int32_t outNum, CValidation
}
// ensure that we have enough fees for the currency definition import
if (feeEquivalentInNative < systemDest.GetCurrencyImportFee())
if (feeEquivalentInNative < systemDest.GetCurrencyImportFee(curToExport.ChainOptions() & curToExport.OPTION_NFT_TOKEN))
{
return state.Error("Not enough fee for currency import in reserve transfer " + rt.ToUniValue().write(1,2));
}

16
src/pbaas/reserves.cpp

@ -2825,6 +2825,7 @@ bool CReserveTransfer::GetTxOut(const CCurrencyDefinition &sourceSystem,
{
bool makeNormalOutput = true;
CTxDestination dest = TransferDestinationToDestination(destination);
CCurrencyDefinition exportCurDef;
if (HasNextLeg())
{
makeNormalOutput = false;
@ -2864,7 +2865,7 @@ bool CReserveTransfer::GetTxOut(const CCurrencyDefinition &sourceSystem,
// if this is a currency export, make the export
if (IsCurrencyExport())
{
CCurrencyDefinition exportCurDef = ConnectedChains.GetCachedCurrency(FirstCurrency());
exportCurDef = ConnectedChains.GetCachedCurrency(FirstCurrency());
if (exportCurDef.IsValid() &&
nextDest.IsMultiCurrency() &&
destination.gatewayID != ASSETCHAINS_CHAINID &&
@ -2872,7 +2873,6 @@ bool CReserveTransfer::GetTxOut(const CCurrencyDefinition &sourceSystem,
{
if (!IsValidExportCurrency(nextDest, FirstCurrency(), height))
{
CCurrencyDefinition exportCurDef = ConnectedChains.GetCachedCurrency(FirstCurrency());
lastLegDest.type = lastLegDest.DEST_REGISTERCURRENCY;
lastLegDest.destination = ::AsVector(exportCurDef);
newFlags |= CURRENCY_EXPORT;
@ -2984,7 +2984,7 @@ bool CReserveTransfer::GetTxOut(const CCurrencyDefinition &sourceSystem,
LogPrintf("%s: Invalid fee currency for next leg of transfer %s\n", __func__, nextLegTransfer.ToUniValue().write(1,2).c_str());
}
else if (nextLegTransfer.nFees < nextSys.GetTransactionImportFee() ||
(IsCurrencyExport() && nextLegTransfer.nFees < nextSys.GetCurrencyImportFee()) ||
(IsCurrencyExport() && nextLegTransfer.nFees < nextSys.GetCurrencyImportFee(exportCurDef.ChainOptions() & exportCurDef.OPTION_NFT_TOKEN)) ||
(IsIdentityExport() && nextLegTransfer.nFees < nextSys.IDImportFee()))
{
LogPrintf("%s: Insufficient fee currency for next leg of transfer %s\n", __func__, nextLegTransfer.ToUniValue().write(1,2).c_str());
@ -3065,15 +3065,7 @@ bool CReserveTransfer::GetTxOut(const CCurrencyDefinition &sourceSystem,
curHeight < height))
{
std::string qualifiedName = ConnectedChains.GetFriendlyCurrencyName(FirstCurrency());
if (nFees < ConnectedChains.ThisChain().GetCurrencyImportFee())
{
LogPrintf("%s: Currency already registered for %s\n", __func__, qualifiedName.c_str());
}
else
{
LogPrint("crosschain", "%s: Currency already registered for %s\n", __func__, qualifiedName.c_str());
}
LogPrint("crosschain", "%s: Currency already registered for %s\n", __func__, qualifiedName.c_str());
// drop through and make an output that will not be added
nativeAmount = -1;

6
src/rpc/pbaasrpc.cpp

@ -7495,7 +7495,9 @@ UniValue sendcurrency(const UniValue& params, bool fHelp)
if (exportCurrency)
{
// get source price for export and dest price for import to ensure we have enough fee currency
requiredFees = CCurrencyState::ReserveToNativeRaw(offChainDef.GetCurrencyImportFee(), reversePriceInFeeCur);
requiredFees =
CCurrencyState::ReserveToNativeRaw(offChainDef.GetCurrencyImportFee(sourceCurrencyDef.ChainOptions() & sourceCurrencyDef.OPTION_NFT_TOKEN),
reversePriceInFeeCur);
flags |= CReserveTransfer::CURRENCY_EXPORT;
}
else if (exportId)
@ -7598,7 +7600,7 @@ UniValue sendcurrency(const UniValue& params, bool fHelp)
if (exportCurrency)
{
// get source price for export and dest price for import to ensure we have enough fee currency
requiredFees = CCurrencyState::ReserveToNativeRaw(offChainDef.GetCurrencyImportFee(), reversePriceInFeeCur);
requiredFees = CCurrencyState::ReserveToNativeRaw(offChainDef.GetCurrencyImportFee(sourceCurrencyDef.ChainOptions() & sourceCurrencyDef.OPTION_NFT_TOKEN), reversePriceInFeeCur);
flags |= CReserveTransfer::CURRENCY_EXPORT;
}
else if (exportId)

Loading…
Cancel
Save