Skip to content

Commit

Permalink
Support for fractional token migration (#2204)
Browse files Browse the repository at this point in the history
* Use CAmount for split amount

* Complete fractional merge

* Feature guard fractional split

* Formatting

* Update test

* Update error messages and tests

* Do not allow fractional splits less than 1

* Remove random. Mint direct to addresses.

* Add more fractional split or merge tests

* Test pool reserve after migration

* Test vault loans after split

* Add 64bit OracleSplits

* Do not use from_chars, clang does not support it with FP.

* Create and validate token migration creation TXs based on type.

* Update expected error strings

* Template token splits

* Changes after merge

---------

Co-authored-by: Prasanna Loganathar <[email protected]>
  • Loading branch information
Bushstar and prasannavl authored Mar 21, 2024
1 parent cd853b6 commit 2dea1cc
Show file tree
Hide file tree
Showing 11 changed files with 1,020 additions and 235 deletions.
10 changes: 10 additions & 0 deletions src/amount.h
Original file line number Diff line number Diff line change
Expand Up @@ -121,6 +121,16 @@ inline CAmount DivideAmounts(CAmount a, CAmount b)
return (arith_uint256(a) * arith_uint256(COIN) / arith_uint256(b)).GetLow64();
}

inline base_uint<128> MultiplyAmounts(base_uint<128> a, CAmount b)
{
return (arith_uint256(a) * arith_uint256(b) / arith_uint256(COIN)).GetLow64();
}

inline base_uint<128> DivideAmounts(base_uint<128> a, CAmount b)
{
return (arith_uint256(a) * arith_uint256(COIN) / arith_uint256(b)).GetLow64();
}

struct CTokenAmount { // simple std::pair is less informative
DCT_ID nTokenId;
CAmount nValue;
Expand Down
1 change: 1 addition & 0 deletions src/arith_uint256.h
Original file line number Diff line number Diff line change
Expand Up @@ -292,6 +292,7 @@ class arith_uint256 : public base_uint<256> {
arith_uint256() {}
arith_uint256(const base_uint<256>& b) : base_uint<256>(b) {}
arith_uint256(uint64_t b) : base_uint<256>(b) {}
arith_uint256(base_uint<128> b) : base_uint<256>(b) {}
explicit arith_uint256(const std::string& str) : base_uint<256>(str) {}

/**
Expand Down
12 changes: 12 additions & 0 deletions src/dfi/errors.h
Original file line number Diff line number Diff line change
Expand Up @@ -196,6 +196,14 @@ class DeFiErrors {
return Res::Err(error);
}

static Res GovVarOracleInvalidKey(const std::map<std::string, uint8_t> &keys) {
std::string error{"Unrecognised key, valid keys are either block height or:"};
for (const auto &pair : keys) {
error += ' ' + pair.first + ',';
}
return Res::Err(error);
}

static Res GovVarVariableUnsupportedType(const unsigned char type) {
return Res::Err("Unsupported type {%d}", type);
}
Expand Down Expand Up @@ -260,6 +268,10 @@ class DeFiErrors {

static Res GovVarValidateLoanTokenID(const uint32_t token) { return Res::Err("No loan token with id (%d)", token); }

static Res GovVarVerifySplitFractional() { return Res::Err("Fractional split not currently supported"); }

static Res GovVarVerifySplitFractionalTooSmall() { return Res::Err("Fractional split cannot be less than 1"); }

static Res GovVarValidateExcessAmount() { return Res::Err("Percentage exceeds 100%%"); }

static Res GovVarTokenAsString() { return Res::Err("Token should be defined as numeric ID"); }
Expand Down
Loading

0 comments on commit 2dea1cc

Please sign in to comment.