mirror of
https://github.com/XRPLF/rippled.git
synced 2025-12-06 17:27:55 +00:00
Compare commits
8 Commits
ximinez/le
...
ripple/was
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
8a403f1241 | ||
|
|
6d2640871d | ||
|
|
500bb68831 | ||
|
|
16087c9680 | ||
|
|
25c3060fef | ||
|
|
ce9f0b38a4 | ||
|
|
35f7cbf772 | ||
|
|
0db564d261 |
1
.github/actions/build-deps/action.yml
vendored
1
.github/actions/build-deps/action.yml
vendored
@@ -35,6 +35,7 @@ runs:
|
|||||||
LOG_VERBOSITY: ${{ inputs.log_verbosity }}
|
LOG_VERBOSITY: ${{ inputs.log_verbosity }}
|
||||||
run: |
|
run: |
|
||||||
echo 'Installing dependencies.'
|
echo 'Installing dependencies.'
|
||||||
|
conan export --version 0.42.1 external/wasmi #TODO Switch to conan package
|
||||||
mkdir -p "${BUILD_DIR}"
|
mkdir -p "${BUILD_DIR}"
|
||||||
cd "${BUILD_DIR}"
|
cd "${BUILD_DIR}"
|
||||||
conan install \
|
conan install \
|
||||||
|
|||||||
56
.github/scripts/strategy-matrix/linux.json
vendored
56
.github/scripts/strategy-matrix/linux.json
vendored
@@ -15,196 +15,196 @@
|
|||||||
"distro_version": "bookworm",
|
"distro_version": "bookworm",
|
||||||
"compiler_name": "gcc",
|
"compiler_name": "gcc",
|
||||||
"compiler_version": "12",
|
"compiler_version": "12",
|
||||||
"image_sha": "0525eae"
|
"image_sha": "ca4517d"
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"distro_name": "debian",
|
"distro_name": "debian",
|
||||||
"distro_version": "bookworm",
|
"distro_version": "bookworm",
|
||||||
"compiler_name": "gcc",
|
"compiler_name": "gcc",
|
||||||
"compiler_version": "13",
|
"compiler_version": "13",
|
||||||
"image_sha": "0525eae"
|
"image_sha": "ca4517d"
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"distro_name": "debian",
|
"distro_name": "debian",
|
||||||
"distro_version": "bookworm",
|
"distro_version": "bookworm",
|
||||||
"compiler_name": "gcc",
|
"compiler_name": "gcc",
|
||||||
"compiler_version": "14",
|
"compiler_version": "14",
|
||||||
"image_sha": "0525eae"
|
"image_sha": "ca4517d"
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"distro_name": "debian",
|
"distro_name": "debian",
|
||||||
"distro_version": "bookworm",
|
"distro_version": "bookworm",
|
||||||
"compiler_name": "gcc",
|
"compiler_name": "gcc",
|
||||||
"compiler_version": "15",
|
"compiler_version": "15",
|
||||||
"image_sha": "0525eae"
|
"image_sha": "ca4517d"
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"distro_name": "debian",
|
"distro_name": "debian",
|
||||||
"distro_version": "bookworm",
|
"distro_version": "bookworm",
|
||||||
"compiler_name": "clang",
|
"compiler_name": "clang",
|
||||||
"compiler_version": "16",
|
"compiler_version": "16",
|
||||||
"image_sha": "0525eae"
|
"image_sha": "ca4517d"
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"distro_name": "debian",
|
"distro_name": "debian",
|
||||||
"distro_version": "bookworm",
|
"distro_version": "bookworm",
|
||||||
"compiler_name": "clang",
|
"compiler_name": "clang",
|
||||||
"compiler_version": "17",
|
"compiler_version": "17",
|
||||||
"image_sha": "0525eae"
|
"image_sha": "ca4517d"
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"distro_name": "debian",
|
"distro_name": "debian",
|
||||||
"distro_version": "bookworm",
|
"distro_version": "bookworm",
|
||||||
"compiler_name": "clang",
|
"compiler_name": "clang",
|
||||||
"compiler_version": "18",
|
"compiler_version": "18",
|
||||||
"image_sha": "0525eae"
|
"image_sha": "ca4517d"
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"distro_name": "debian",
|
"distro_name": "debian",
|
||||||
"distro_version": "bookworm",
|
"distro_version": "bookworm",
|
||||||
"compiler_name": "clang",
|
"compiler_name": "clang",
|
||||||
"compiler_version": "19",
|
"compiler_version": "19",
|
||||||
"image_sha": "0525eae"
|
"image_sha": "ca4517d"
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"distro_name": "debian",
|
"distro_name": "debian",
|
||||||
"distro_version": "bookworm",
|
"distro_version": "bookworm",
|
||||||
"compiler_name": "clang",
|
"compiler_name": "clang",
|
||||||
"compiler_version": "20",
|
"compiler_version": "20",
|
||||||
"image_sha": "0525eae"
|
"image_sha": "ca4517d"
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"distro_name": "debian",
|
"distro_name": "debian",
|
||||||
"distro_version": "trixie",
|
"distro_version": "trixie",
|
||||||
"compiler_name": "gcc",
|
"compiler_name": "gcc",
|
||||||
"compiler_version": "14",
|
"compiler_version": "14",
|
||||||
"image_sha": "0525eae"
|
"image_sha": "ca4517d"
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"distro_name": "debian",
|
"distro_name": "debian",
|
||||||
"distro_version": "trixie",
|
"distro_version": "trixie",
|
||||||
"compiler_name": "gcc",
|
"compiler_name": "gcc",
|
||||||
"compiler_version": "15",
|
"compiler_version": "15",
|
||||||
"image_sha": "0525eae"
|
"image_sha": "ca4517d"
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"distro_name": "debian",
|
"distro_name": "debian",
|
||||||
"distro_version": "trixie",
|
"distro_version": "trixie",
|
||||||
"compiler_name": "clang",
|
"compiler_name": "clang",
|
||||||
"compiler_version": "20",
|
"compiler_version": "20",
|
||||||
"image_sha": "0525eae"
|
"image_sha": "ca4517d"
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"distro_name": "debian",
|
"distro_name": "debian",
|
||||||
"distro_version": "trixie",
|
"distro_version": "trixie",
|
||||||
"compiler_name": "clang",
|
"compiler_name": "clang",
|
||||||
"compiler_version": "21",
|
"compiler_version": "21",
|
||||||
"image_sha": "0525eae"
|
"image_sha": "ca4517d"
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"distro_name": "rhel",
|
"distro_name": "rhel",
|
||||||
"distro_version": "8",
|
"distro_version": "8",
|
||||||
"compiler_name": "gcc",
|
"compiler_name": "gcc",
|
||||||
"compiler_version": "14",
|
"compiler_version": "14",
|
||||||
"image_sha": "e1782cd"
|
"image_sha": "ca4517d"
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"distro_name": "rhel",
|
"distro_name": "rhel",
|
||||||
"distro_version": "8",
|
"distro_version": "8",
|
||||||
"compiler_name": "clang",
|
"compiler_name": "clang",
|
||||||
"compiler_version": "any",
|
"compiler_version": "any",
|
||||||
"image_sha": "e1782cd"
|
"image_sha": "ca4517d"
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"distro_name": "rhel",
|
"distro_name": "rhel",
|
||||||
"distro_version": "9",
|
"distro_version": "9",
|
||||||
"compiler_name": "gcc",
|
"compiler_name": "gcc",
|
||||||
"compiler_version": "12",
|
"compiler_version": "12",
|
||||||
"image_sha": "e1782cd"
|
"image_sha": "ca4517d"
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"distro_name": "rhel",
|
"distro_name": "rhel",
|
||||||
"distro_version": "9",
|
"distro_version": "9",
|
||||||
"compiler_name": "gcc",
|
"compiler_name": "gcc",
|
||||||
"compiler_version": "13",
|
"compiler_version": "13",
|
||||||
"image_sha": "e1782cd"
|
"image_sha": "ca4517d"
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"distro_name": "rhel",
|
"distro_name": "rhel",
|
||||||
"distro_version": "9",
|
"distro_version": "9",
|
||||||
"compiler_name": "gcc",
|
"compiler_name": "gcc",
|
||||||
"compiler_version": "14",
|
"compiler_version": "14",
|
||||||
"image_sha": "e1782cd"
|
"image_sha": "ca4517d"
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"distro_name": "rhel",
|
"distro_name": "rhel",
|
||||||
"distro_version": "9",
|
"distro_version": "9",
|
||||||
"compiler_name": "clang",
|
"compiler_name": "clang",
|
||||||
"compiler_version": "any",
|
"compiler_version": "any",
|
||||||
"image_sha": "e1782cd"
|
"image_sha": "ca4517d"
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"distro_name": "rhel",
|
"distro_name": "rhel",
|
||||||
"distro_version": "10",
|
"distro_version": "10",
|
||||||
"compiler_name": "gcc",
|
"compiler_name": "gcc",
|
||||||
"compiler_version": "14",
|
"compiler_version": "14",
|
||||||
"image_sha": "e1782cd"
|
"image_sha": "ca4517d"
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"distro_name": "rhel",
|
"distro_name": "rhel",
|
||||||
"distro_version": "10",
|
"distro_version": "10",
|
||||||
"compiler_name": "clang",
|
"compiler_name": "clang",
|
||||||
"compiler_version": "any",
|
"compiler_version": "any",
|
||||||
"image_sha": "e1782cd"
|
"image_sha": "ca4517d"
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"distro_name": "ubuntu",
|
"distro_name": "ubuntu",
|
||||||
"distro_version": "jammy",
|
"distro_version": "jammy",
|
||||||
"compiler_name": "gcc",
|
"compiler_name": "gcc",
|
||||||
"compiler_version": "12",
|
"compiler_version": "12",
|
||||||
"image_sha": "e1782cd"
|
"image_sha": "ca4517d"
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"distro_name": "ubuntu",
|
"distro_name": "ubuntu",
|
||||||
"distro_version": "noble",
|
"distro_version": "noble",
|
||||||
"compiler_name": "gcc",
|
"compiler_name": "gcc",
|
||||||
"compiler_version": "13",
|
"compiler_version": "13",
|
||||||
"image_sha": "e1782cd"
|
"image_sha": "ca4517d"
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"distro_name": "ubuntu",
|
"distro_name": "ubuntu",
|
||||||
"distro_version": "noble",
|
"distro_version": "noble",
|
||||||
"compiler_name": "gcc",
|
"compiler_name": "gcc",
|
||||||
"compiler_version": "14",
|
"compiler_version": "14",
|
||||||
"image_sha": "e1782cd"
|
"image_sha": "ca4517d"
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"distro_name": "ubuntu",
|
"distro_name": "ubuntu",
|
||||||
"distro_version": "noble",
|
"distro_version": "noble",
|
||||||
"compiler_name": "clang",
|
"compiler_name": "clang",
|
||||||
"compiler_version": "16",
|
"compiler_version": "16",
|
||||||
"image_sha": "e1782cd"
|
"image_sha": "ca4517d"
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"distro_name": "ubuntu",
|
"distro_name": "ubuntu",
|
||||||
"distro_version": "noble",
|
"distro_version": "noble",
|
||||||
"compiler_name": "clang",
|
"compiler_name": "clang",
|
||||||
"compiler_version": "17",
|
"compiler_version": "17",
|
||||||
"image_sha": "e1782cd"
|
"image_sha": "ca4517d"
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"distro_name": "ubuntu",
|
"distro_name": "ubuntu",
|
||||||
"distro_version": "noble",
|
"distro_version": "noble",
|
||||||
"compiler_name": "clang",
|
"compiler_name": "clang",
|
||||||
"compiler_version": "18",
|
"compiler_version": "18",
|
||||||
"image_sha": "e1782cd"
|
"image_sha": "ca4517d"
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"distro_name": "ubuntu",
|
"distro_name": "ubuntu",
|
||||||
"distro_version": "noble",
|
"distro_version": "noble",
|
||||||
"compiler_name": "clang",
|
"compiler_name": "clang",
|
||||||
"compiler_version": "19",
|
"compiler_version": "19",
|
||||||
"image_sha": "e1782cd"
|
"image_sha": "ca4517d"
|
||||||
}
|
}
|
||||||
],
|
],
|
||||||
"build_type": ["Debug", "Release"],
|
"build_type": ["Debug", "Release"],
|
||||||
|
|||||||
@@ -77,7 +77,7 @@ jobs:
|
|||||||
uses: actions/checkout@08eba0b27e820071cde6df949e0beb9ba4906955 # v4.3.0
|
uses: actions/checkout@08eba0b27e820071cde6df949e0beb9ba4906955 # v4.3.0
|
||||||
|
|
||||||
- name: Prepare runner
|
- name: Prepare runner
|
||||||
uses: XRPLF/actions/.github/actions/prepare-runner@99685816bb60a95a66852f212f382580e180df3a
|
uses: XRPLF/actions/.github/actions/prepare-runner@ff9f8f649df5855ffe1a1ae715df43e51807f2e0
|
||||||
with:
|
with:
|
||||||
disable_ccache: false
|
disable_ccache: false
|
||||||
|
|
||||||
|
|||||||
2
.github/workflows/upload-conan-deps.yml
vendored
2
.github/workflows/upload-conan-deps.yml
vendored
@@ -70,7 +70,7 @@ jobs:
|
|||||||
uses: actions/checkout@08eba0b27e820071cde6df949e0beb9ba4906955 # v4.3.0
|
uses: actions/checkout@08eba0b27e820071cde6df949e0beb9ba4906955 # v4.3.0
|
||||||
|
|
||||||
- name: Prepare runner
|
- name: Prepare runner
|
||||||
uses: XRPLF/actions/.github/actions/prepare-runner@99685816bb60a95a66852f212f382580e180df3a
|
uses: XRPLF/actions/.github/actions/prepare-runner@ff9f8f649df5855ffe1a1ae715df43e51807f2e0
|
||||||
with:
|
with:
|
||||||
disable_ccache: false
|
disable_ccache: false
|
||||||
|
|
||||||
|
|||||||
@@ -113,6 +113,7 @@ find_package(date REQUIRED)
|
|||||||
find_package(ed25519 REQUIRED)
|
find_package(ed25519 REQUIRED)
|
||||||
find_package(nudb REQUIRED)
|
find_package(nudb REQUIRED)
|
||||||
find_package(secp256k1 REQUIRED)
|
find_package(secp256k1 REQUIRED)
|
||||||
|
find_package(wasmi REQUIRED)
|
||||||
find_package(xxHash REQUIRED)
|
find_package(xxHash REQUIRED)
|
||||||
|
|
||||||
target_link_libraries(xrpl_libs INTERFACE
|
target_link_libraries(xrpl_libs INTERFACE
|
||||||
|
|||||||
@@ -63,6 +63,7 @@ target_link_libraries(xrpl.imports.main
|
|||||||
Xrpl::opts
|
Xrpl::opts
|
||||||
Xrpl::syslibs
|
Xrpl::syslibs
|
||||||
secp256k1::secp256k1
|
secp256k1::secp256k1
|
||||||
|
wasmi::wasmi
|
||||||
xrpl.libpb
|
xrpl.libpb
|
||||||
xxHash::xxhash
|
xxHash::xxhash
|
||||||
$<$<BOOL:${voidstar}>:antithesis-sdk-cpp>
|
$<$<BOOL:${voidstar}>:antithesis-sdk-cpp>
|
||||||
|
|||||||
62
conan.lock
62
conan.lock
@@ -1,62 +0,0 @@
|
|||||||
{
|
|
||||||
"version": "0.5",
|
|
||||||
"requires": [
|
|
||||||
"zlib/1.3.1#b8bc2603263cf7eccbd6e17e66b0ed76%1756234269.497",
|
|
||||||
"xxhash/0.8.3#681d36a0a6111fc56e5e45ea182c19cc%1756234289.683",
|
|
||||||
"sqlite3/3.49.1#8631739a4c9b93bd3d6b753bac548a63%1756234266.869",
|
|
||||||
"soci/4.0.3#a9f8d773cd33e356b5879a4b0564f287%1756234262.318",
|
|
||||||
"snappy/1.1.10#968fef506ff261592ec30c574d4a7809%1756234314.246",
|
|
||||||
"secp256k1/0.7.0#9210e4c655d0a665400378a663960d17%1764261276.764",
|
|
||||||
"rocksdb/10.5.1#4a197eca381a3e5ae8adf8cffa5aacd0%1762797952.535",
|
|
||||||
"re2/20230301#ca3b241baec15bd31ea9187150e0b333%1764175362.029",
|
|
||||||
"protobuf/6.32.1#f481fd276fc23a33b85a3ed1e898b693%1759134873.45",
|
|
||||||
"openssl/3.5.4#a1d5835cc6ed5c5b8f3cd5b9b5d24205%1760106486.594",
|
|
||||||
"nudb/2.0.9#fb8dfd1a5557f5e0528114c2da17721e%1763150366.909",
|
|
||||||
"lz4/1.10.0#59fc63cac7f10fbe8e05c7e62c2f3504%1756234228.999",
|
|
||||||
"libiconv/1.17#1e65319e945f2d31941a9d28cc13c058%1756223727.64",
|
|
||||||
"libbacktrace/cci.20210118#a7691bfccd8caaf66309df196790a5a1%1756230911.03",
|
|
||||||
"libarchive/3.8.1#ffee18995c706e02bf96e7a2f7042e0d%1764175360.142",
|
|
||||||
"jemalloc/5.3.0#e951da9cf599e956cebc117880d2d9f8%1729241615.244",
|
|
||||||
"grpc/1.72.0#f244a57bff01e708c55a1100b12e1589%1763158050.628",
|
|
||||||
"ed25519/2015.03#ae761bdc52730a843f0809bdf6c1b1f6%1764270189.893",
|
|
||||||
"doctest/2.4.12#eb9fb352fb2fdfc8abb17ec270945165%1762797941.757",
|
|
||||||
"date/3.0.4#862e11e80030356b53c2c38599ceb32b%1763584497.32",
|
|
||||||
"c-ares/1.34.5#5581c2b62a608b40bb85d965ab3ec7c8%1764175359.429",
|
|
||||||
"bzip2/1.0.8#c470882369c2d95c5c77e970c0c7e321%1764175359.429",
|
|
||||||
"boost/1.88.0#8852c0b72ce8271fb8ff7c53456d4983%1756223752.326",
|
|
||||||
"abseil/20250127.0#9e8e8cfc89a1324139fc0ee3bd4d8c8c%1753819045.301"
|
|
||||||
],
|
|
||||||
"build_requires": [
|
|
||||||
"zlib/1.3.1#b8bc2603263cf7eccbd6e17e66b0ed76%1756234269.497",
|
|
||||||
"strawberryperl/5.32.1.1#707032463aa0620fa17ec0d887f5fe41%1756234281.733",
|
|
||||||
"protobuf/6.32.1#f481fd276fc23a33b85a3ed1e898b693%1759134873.45",
|
|
||||||
"nasm/2.16.01#31e26f2ee3c4346ecd347911bd126904%1756234232.901",
|
|
||||||
"msys2/cci.latest#5b73b10144f73cc5bfe0572ed9be39e1%1751977009.857",
|
|
||||||
"m4/1.4.19#70dc8bbb33e981d119d2acc0175cf381%1763158052.846",
|
|
||||||
"cmake/4.2.0#ae0a44f44a1ef9ab68fd4b3e9a1f8671%1764175359.44",
|
|
||||||
"cmake/3.31.10#313d16a1aa16bbdb2ca0792467214b76%1764175359.429",
|
|
||||||
"b2/5.3.3#107c15377719889654eb9a162a673975%1756234226.28",
|
|
||||||
"automake/1.16.5#b91b7c384c3deaa9d535be02da14d04f%1755524470.56",
|
|
||||||
"autoconf/2.71#51077f068e61700d65bb05541ea1e4b0%1731054366.86",
|
|
||||||
"abseil/20250127.0#9e8e8cfc89a1324139fc0ee3bd4d8c8c%1753819045.301"
|
|
||||||
],
|
|
||||||
"python_requires": [],
|
|
||||||
"overrides": {
|
|
||||||
"protobuf/5.27.0": [
|
|
||||||
"protobuf/6.32.1"
|
|
||||||
],
|
|
||||||
"lz4/1.9.4": [
|
|
||||||
"lz4/1.10.0"
|
|
||||||
],
|
|
||||||
"boost/1.83.0": [
|
|
||||||
"boost/1.88.0"
|
|
||||||
],
|
|
||||||
"sqlite3/3.44.2": [
|
|
||||||
"sqlite3/3.49.1"
|
|
||||||
],
|
|
||||||
"lz4/[>=1.9.4 <2]": [
|
|
||||||
"lz4/1.10.0#59fc63cac7f10fbe8e05c7e62c2f3504"
|
|
||||||
]
|
|
||||||
},
|
|
||||||
"config_requires": []
|
|
||||||
}
|
|
||||||
@@ -35,6 +35,7 @@ class Xrpl(ConanFile):
|
|||||||
"openssl/3.5.4",
|
"openssl/3.5.4",
|
||||||
"secp256k1/0.7.0",
|
"secp256k1/0.7.0",
|
||||||
"soci/4.0.3",
|
"soci/4.0.3",
|
||||||
|
"wasmi/0.42.1",
|
||||||
"zlib/1.3.1",
|
"zlib/1.3.1",
|
||||||
]
|
]
|
||||||
|
|
||||||
@@ -212,6 +213,7 @@ class Xrpl(ConanFile):
|
|||||||
"soci::soci",
|
"soci::soci",
|
||||||
"secp256k1::secp256k1",
|
"secp256k1::secp256k1",
|
||||||
"sqlite3::sqlite",
|
"sqlite3::sqlite",
|
||||||
|
"wasmi::wasmi",
|
||||||
"xxhash::xxhash",
|
"xxhash::xxhash",
|
||||||
"zlib::zlib",
|
"zlib::zlib",
|
||||||
]
|
]
|
||||||
|
|||||||
11
external/wasmi/conandata.yml
vendored
Normal file
11
external/wasmi/conandata.yml
vendored
Normal file
@@ -0,0 +1,11 @@
|
|||||||
|
# Do not update. Maintained by programmability team.
|
||||||
|
|
||||||
|
sources:
|
||||||
|
"0.42.1":
|
||||||
|
sha256: 2a5697be33c7afce8f671af4a5a3621d9e93ce55d253d31bd8201458e465fbb8
|
||||||
|
url: https://github.com/wasmi-labs/wasmi/archive/refs/tags/v0.42.1.tar.gz
|
||||||
|
patches:
|
||||||
|
"0.42.1":
|
||||||
|
- patch_file: "patches/0001-xrplf-0.42.1.patch"
|
||||||
|
patch_type: conan
|
||||||
|
patch_description: Integration patch. Make wasmi lib to be able to build with existing smart-escrow branch.
|
||||||
48
external/wasmi/conanfile.py
vendored
Normal file
48
external/wasmi/conanfile.py
vendored
Normal file
@@ -0,0 +1,48 @@
|
|||||||
|
from conan import ConanFile, tools
|
||||||
|
from conan.tools.cmake import CMake, CMakeToolchain, CMakeDeps, cmake_layout
|
||||||
|
from conan.tools.files import apply_conandata_patches, export_conandata_patches, get
|
||||||
|
import os
|
||||||
|
|
||||||
|
required_conan_version = ">=2.0.0"
|
||||||
|
|
||||||
|
class WasmiConan(ConanFile):
|
||||||
|
name = "wasmi"
|
||||||
|
license = "Apache License v2.0"
|
||||||
|
url = "https://github.com/wasmi-labs/wasmi.git"
|
||||||
|
description = "WebAssembly (Wasm) interpreter"
|
||||||
|
package_type = "library"
|
||||||
|
settings = "os", "arch", "compiler", "build_type"
|
||||||
|
options = {"shared": [False]}
|
||||||
|
default_options = {"shared": False}
|
||||||
|
|
||||||
|
def export_sources(self):
|
||||||
|
export_conandata_patches(self)
|
||||||
|
|
||||||
|
def layout(self):
|
||||||
|
cmake_layout(self, src_folder="src")
|
||||||
|
|
||||||
|
def source(self):
|
||||||
|
get(self, **self.conan_data["sources"][self.version], strip_root=True)
|
||||||
|
apply_conandata_patches(self)
|
||||||
|
|
||||||
|
def generate(self):
|
||||||
|
tc = CMakeToolchain(self)
|
||||||
|
tc.variables["BUILD_SHARED_LIBS"] = self.options.shared
|
||||||
|
tc.generate()
|
||||||
|
|
||||||
|
deps = CMakeDeps(self)
|
||||||
|
deps.generate()
|
||||||
|
|
||||||
|
def build(self):
|
||||||
|
cmake = CMake(self)
|
||||||
|
cmake.configure(build_script_folder=os.path.join(self.source_folder, "crates", "c_api"))
|
||||||
|
cmake.build()
|
||||||
|
|
||||||
|
def package(self):
|
||||||
|
cmake = CMake(self)
|
||||||
|
cmake.install()
|
||||||
|
|
||||||
|
def package_info(self):
|
||||||
|
self.cpp_info.libs = ["wasmi"]
|
||||||
|
self.cpp_info.names["cmake_find_package"] = "wasmi"
|
||||||
|
self.cpp_info.names["cmake_find_package_multi"] = "wasmi"
|
||||||
180
external/wasmi/patches/0001-xrplf-0.42.1.patch
vendored
Normal file
180
external/wasmi/patches/0001-xrplf-0.42.1.patch
vendored
Normal file
@@ -0,0 +1,180 @@
|
|||||||
|
diff --git a/crates/c_api/CMakeLists.txt b/crates/c_api/CMakeLists.txt
|
||||||
|
index b15c787a..54eaed2d 100644
|
||||||
|
--- a/crates/c_api/CMakeLists.txt
|
||||||
|
+++ b/crates/c_api/CMakeLists.txt
|
||||||
|
@@ -6,6 +6,8 @@ option(BUILD_SHARED_LIBS "Build using shared libraries" OFF)
|
||||||
|
option(WASMI_ALWAYS_BUILD "If cmake should always invoke cargo to build Wasmi" ON)
|
||||||
|
set(WASMI_TARGET "" CACHE STRING "Rust target to build for")
|
||||||
|
|
||||||
|
+add_compile_definitions(COMPILING_WASM_RUNTIME_API=1)
|
||||||
|
+
|
||||||
|
if(NOT WASMI_TARGET)
|
||||||
|
execute_process(
|
||||||
|
COMMAND rustc -vV
|
||||||
|
@@ -43,6 +45,10 @@ endif()
|
||||||
|
list(TRANSFORM WASMI_SHARED_FILES PREPEND ${WASMI_TARGET_DIR}/)
|
||||||
|
list(TRANSFORM WASMI_STATIC_FILES PREPEND ${WASMI_TARGET_DIR}/)
|
||||||
|
|
||||||
|
+if(NOT BUILD_SHARED_LIBS)
|
||||||
|
+ set(WASMI_SHARED_FILES)
|
||||||
|
+endif()
|
||||||
|
+
|
||||||
|
# Instructions on how to build and install the Wasmi Rust crate.
|
||||||
|
find_program(WASMI_CARGO_BINARY cargo REQUIRED)
|
||||||
|
include(ExternalProject)
|
||||||
|
@@ -79,7 +85,6 @@ else()
|
||||||
|
target_link_libraries(wasmi INTERFACE ${WASMI_STATIC_FILES})
|
||||||
|
|
||||||
|
if(WASMI_TARGET MATCHES "windows")
|
||||||
|
- target_compile_options(wasmi INTERFACE -DWASM_API_EXTERN= -DWASI_API_EXTERN=)
|
||||||
|
target_link_libraries(wasmi INTERFACE ws2_32 advapi32 userenv ntdll shell32 ole32 bcrypt)
|
||||||
|
elseif(NOT WASMI_TARGET MATCHES "darwin")
|
||||||
|
target_link_libraries(wasmi INTERFACE pthread dl m)
|
||||||
|
@@ -112,6 +117,7 @@ install(
|
||||||
|
DESTINATION ${CMAKE_INSTALL_LIBDIR}
|
||||||
|
)
|
||||||
|
|
||||||
|
+if(BUILD_SHARED_LIBS)
|
||||||
|
if(WASMI_TARGET MATCHES "darwin")
|
||||||
|
set(INSTALLED_LIB "${CMAKE_INSTALL_PREFIX}/${CMAKE_INSTALL_LIBDIR}/libwasmi.dylib")
|
||||||
|
install(
|
||||||
|
@@ -131,6 +137,7 @@ if(WASMI_TARGET MATCHES "darwin")
|
||||||
|
install(CODE "execute_process(COMMAND ${install_name_tool_cmd})")
|
||||||
|
endif()
|
||||||
|
endif()
|
||||||
|
+endif()
|
||||||
|
|
||||||
|
# Documentation Generation via Doxygen:
|
||||||
|
set(DOXYGEN_CONF_IN ${CMAKE_CURRENT_SOURCE_DIR}/doxygen.conf.in)
|
||||||
|
@@ -141,19 +148,3 @@ add_custom_target(doc
|
||||||
|
DEPENDS ${WASMI_GENERATED_CONF_H} ${DOXYGEN_CONF_OUT}
|
||||||
|
WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}
|
||||||
|
)
|
||||||
|
-
|
||||||
|
-# C-Header Formatting via clang-format:
|
||||||
|
-find_program(CLANG_FORMAT clang-format REQUIRED)
|
||||||
|
-file(GLOB_RECURSE HEADER_FILES
|
||||||
|
- ${CMAKE_CURRENT_SOURCE_DIR}/include/wasmi.h
|
||||||
|
- ${CMAKE_CURRENT_SOURCE_DIR}/include/wasmi/*.h
|
||||||
|
- ${CMAKE_CURRENT_SOURCE_DIR}/include/wasmi/*.hh
|
||||||
|
-)
|
||||||
|
-add_custom_target(check-format
|
||||||
|
- COMMAND ${CLANG_FORMAT} -style=llvm -Werror --dry-run ${HEADER_FILES}
|
||||||
|
- COMMENT "clang-format: Check formatting for Wasmi C-API header files"
|
||||||
|
-)
|
||||||
|
-add_custom_target(format
|
||||||
|
- COMMAND ${CLANG_FORMAT} -style=llvm -i ${HEADER_FILES}
|
||||||
|
- COMMENT "clang-format: Apply formatting rules for Wasmi C-API header files"
|
||||||
|
-)
|
||||||
|
diff --git a/crates/c_api/include/wasm.h b/crates/c_api/include/wasm.h
|
||||||
|
index 5ee617ff..37809a6f 100644
|
||||||
|
--- a/crates/c_api/include/wasm.h
|
||||||
|
+++ b/crates/c_api/include/wasm.h
|
||||||
|
@@ -13,11 +13,17 @@
|
||||||
|
#include <assert.h>
|
||||||
|
|
||||||
|
#ifndef WASM_API_EXTERN
|
||||||
|
-#if defined(_WIN32) && !defined(__MINGW32__) && !defined(LIBWASM_STATIC)
|
||||||
|
+#if defined(_MSC_BUILD)
|
||||||
|
+#if defined(COMPILING_WASM_RUNTIME_API)
|
||||||
|
+#define WASM_API_EXTERN __declspec(dllexport)
|
||||||
|
+#elif defined(_DLL)
|
||||||
|
#define WASM_API_EXTERN __declspec(dllimport)
|
||||||
|
#else
|
||||||
|
#define WASM_API_EXTERN
|
||||||
|
#endif
|
||||||
|
+#else
|
||||||
|
+#define WASM_API_EXTERN
|
||||||
|
+#endif
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#ifdef __cplusplus
|
||||||
|
@@ -146,6 +152,13 @@ WASM_DECLARE_OWN(store)
|
||||||
|
|
||||||
|
WASM_API_EXTERN own wasm_store_t* wasm_store_new(wasm_engine_t*);
|
||||||
|
|
||||||
|
+// Store fuel functions (forward declarations)
|
||||||
|
+struct wasmi_error;
|
||||||
|
+
|
||||||
|
+WASM_API_EXTERN struct wasmi_error* wasm_store_get_fuel(const wasm_store_t*, uint64_t* fuel);
|
||||||
|
+WASM_API_EXTERN struct wasmi_error* wasm_store_set_fuel(wasm_store_t*, uint64_t fuel);
|
||||||
|
+//WASM_API_EXTERN void *wasm_store_get_data(const wasm_store_t*);
|
||||||
|
+//WASM_API_EXTERN void wasm_store_set_data(wasm_store_t*, void *data);
|
||||||
|
|
||||||
|
///////////////////////////////////////////////////////////////////////////////
|
||||||
|
// Type Representations
|
||||||
|
diff --git a/crates/c_api/include/wasmi.h b/crates/c_api/include/wasmi.h
|
||||||
|
index 2caffa37..0c0584ec 100644
|
||||||
|
--- a/crates/c_api/include/wasmi.h
|
||||||
|
+++ b/crates/c_api/include/wasmi.h
|
||||||
|
@@ -10,7 +10,7 @@
|
||||||
|
/**
|
||||||
|
* \brief Wasmi version string.
|
||||||
|
*/
|
||||||
|
-#define WASMI_VERSION "0.35.0"
|
||||||
|
+#define WASMI_VERSION "0.42.1"
|
||||||
|
/**
|
||||||
|
* \brief Wasmi major version number.
|
||||||
|
*/
|
||||||
|
@@ -18,10 +18,10 @@
|
||||||
|
/**
|
||||||
|
* \brief Wasmi minor version number.
|
||||||
|
*/
|
||||||
|
-#define WASMI_VERSION_MINOR 35
|
||||||
|
+#define WASMI_VERSION_MINOR 42
|
||||||
|
/**
|
||||||
|
* \brief Wasmi patch version number.
|
||||||
|
*/
|
||||||
|
-#define WASMI_VERSION_PATCH 0
|
||||||
|
+#define WASMI_VERSION_PATCH 1
|
||||||
|
|
||||||
|
#endif // WASMI_H
|
||||||
|
diff --git a/crates/c_api/src/store.rs b/crates/c_api/src/store.rs
|
||||||
|
index 56d4898f..543dbff8 100644
|
||||||
|
--- a/crates/c_api/src/store.rs
|
||||||
|
+++ b/crates/c_api/src/store.rs
|
||||||
|
@@ -175,3 +175,44 @@ pub extern "C" fn wasmi_context_set_fuel(
|
||||||
|
) -> Option<Box<wasmi_error_t>> {
|
||||||
|
crate::handle_result(store.set_fuel(fuel), |()| {})
|
||||||
|
}
|
||||||
|
+
|
||||||
|
+////////////////////////////////////////////////////////////////////////////////////////
|
||||||
|
+////////////////////////////////////////////////////////////////////////////////////////
|
||||||
|
+////////////////////////////////////////////////////////////////////////////////////////
|
||||||
|
+////////////////////////////////////////////////////////////////////////////////////////
|
||||||
|
+
|
||||||
|
+/// Returns the current fuel of the wasm store context in `fuel`.
|
||||||
|
+///
|
||||||
|
+/// Wraps [`Store::get_fuel`].
|
||||||
|
+///
|
||||||
|
+/// # Errors
|
||||||
|
+///
|
||||||
|
+/// If [`Store::get_fuel`] errors.
|
||||||
|
+#[no_mangle]
|
||||||
|
+pub extern "C" fn wasm_store_get_fuel(
|
||||||
|
+ store: &wasm_store_t,
|
||||||
|
+ fuel: &mut u64,
|
||||||
|
+) -> Option<Box<wasmi_error_t>> {
|
||||||
|
+ let context = unsafe { store.inner.context() };
|
||||||
|
+ crate::handle_result(context.get_fuel(), |amt| {
|
||||||
|
+ *fuel = amt;
|
||||||
|
+ })
|
||||||
|
+}
|
||||||
|
+
|
||||||
|
+/// Sets the current fuel of the wasm store context to `fuel`.
|
||||||
|
+///
|
||||||
|
+/// Wraps [`Store::set_fuel`].
|
||||||
|
+///
|
||||||
|
+/// # Errors
|
||||||
|
+///
|
||||||
|
+/// If [`Store::set_fuel`] errors.
|
||||||
|
+#[no_mangle]
|
||||||
|
+pub extern "C" fn wasm_store_set_fuel(
|
||||||
|
+ store: &mut wasm_store_t,
|
||||||
|
+ fuel: u64,
|
||||||
|
+) -> Option<Box<wasmi_error_t>> {
|
||||||
|
+
|
||||||
|
+ let mut context = unsafe { store.inner.context_mut() };
|
||||||
|
+ crate::handle_result(context.set_fuel(fuel), |()| {})
|
||||||
|
+}
|
||||||
|
+
|
||||||
@@ -1,642 +0,0 @@
|
|||||||
#include <xrpl/beast/unit_test/suite.h>
|
|
||||||
// DO NOT REMOVE
|
|
||||||
#include <test/jtx.h>
|
|
||||||
#include <test/jtx/Account.h>
|
|
||||||
#include <test/jtx/amount.h>
|
|
||||||
#include <test/jtx/mpt.h>
|
|
||||||
|
|
||||||
#include <xrpld/app/misc/LendingHelpers.h>
|
|
||||||
#include <xrpld/app/misc/LoadFeeTrack.h>
|
|
||||||
#include <xrpld/app/tx/detail/Batch.h>
|
|
||||||
#include <xrpld/app/tx/detail/LoanSet.h>
|
|
||||||
|
|
||||||
#include <xrpl/beast/xor_shift_engine.h>
|
|
||||||
#include <xrpl/protocol/SField.h>
|
|
||||||
|
|
||||||
#include <string>
|
|
||||||
#include <vector>
|
|
||||||
|
|
||||||
namespace ripple {
|
|
||||||
namespace test {
|
|
||||||
|
|
||||||
class LendingHelpers_test : public beast::unit_test::suite
|
|
||||||
{
|
|
||||||
void
|
|
||||||
testComputeRaisedRate()
|
|
||||||
{
|
|
||||||
using namespace jtx;
|
|
||||||
using namespace ripple::detail;
|
|
||||||
struct TestCase
|
|
||||||
{
|
|
||||||
std::string name;
|
|
||||||
Number periodicRate;
|
|
||||||
std::uint32_t paymentsRemaining;
|
|
||||||
Number expectedRaisedRate;
|
|
||||||
};
|
|
||||||
|
|
||||||
auto const testCases = std::vector<TestCase>{
|
|
||||||
{
|
|
||||||
.name = "Zero payments remaining",
|
|
||||||
.periodicRate = Number{5, -2},
|
|
||||||
.paymentsRemaining = 0,
|
|
||||||
.expectedRaisedRate = Number{1}, // (1 + r)^0 = 1
|
|
||||||
},
|
|
||||||
{
|
|
||||||
.name = "One payment remaining",
|
|
||||||
.periodicRate = Number{5, -2},
|
|
||||||
.paymentsRemaining = 1,
|
|
||||||
.expectedRaisedRate = Number{105, -2},
|
|
||||||
}, // 1.05^1
|
|
||||||
{
|
|
||||||
.name = "Multiple payments remaining",
|
|
||||||
.periodicRate = Number{5, -2},
|
|
||||||
.paymentsRemaining = 3,
|
|
||||||
.expectedRaisedRate = Number{1157625, -6},
|
|
||||||
}, // 1.05^3
|
|
||||||
{
|
|
||||||
.name = "Zero periodic rate",
|
|
||||||
.periodicRate = Number{0},
|
|
||||||
.paymentsRemaining = 5,
|
|
||||||
.expectedRaisedRate = Number{1}, // (1 + 0)^5 = 1
|
|
||||||
}};
|
|
||||||
|
|
||||||
for (auto const& tc : testCases)
|
|
||||||
{
|
|
||||||
testcase("computeRaisedRate: " + tc.name);
|
|
||||||
|
|
||||||
auto const computedRaisedRate =
|
|
||||||
computeRaisedRate(tc.periodicRate, tc.paymentsRemaining);
|
|
||||||
BEAST_EXPECTS(
|
|
||||||
computedRaisedRate == tc.expectedRaisedRate,
|
|
||||||
"Raised rate mismatch: expected " +
|
|
||||||
to_string(tc.expectedRaisedRate) + ", got " +
|
|
||||||
to_string(computedRaisedRate));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
void
|
|
||||||
testComputePaymentFactor()
|
|
||||||
{
|
|
||||||
using namespace jtx;
|
|
||||||
using namespace ripple::detail;
|
|
||||||
struct TestCase
|
|
||||||
{
|
|
||||||
std::string name;
|
|
||||||
Number periodicRate;
|
|
||||||
std::uint32_t paymentsRemaining;
|
|
||||||
Number expectedPaymentFactor;
|
|
||||||
};
|
|
||||||
|
|
||||||
auto const testCases = std::vector<TestCase>{
|
|
||||||
{
|
|
||||||
.name = "Zero periodic rate",
|
|
||||||
.periodicRate = Number{0},
|
|
||||||
.paymentsRemaining = 4,
|
|
||||||
.expectedPaymentFactor = Number{25, -2},
|
|
||||||
}, // 1/4 = 0.25
|
|
||||||
{
|
|
||||||
.name = "One payment remaining",
|
|
||||||
.periodicRate = Number{5, -2},
|
|
||||||
.paymentsRemaining = 1,
|
|
||||||
.expectedPaymentFactor = Number{105, -2},
|
|
||||||
}, // 0.05/1 = 1.05
|
|
||||||
{
|
|
||||||
.name = "Multiple payments remaining",
|
|
||||||
.periodicRate = Number{5, -2},
|
|
||||||
.paymentsRemaining = 3,
|
|
||||||
.expectedPaymentFactor = Number{367208564631245, -15},
|
|
||||||
}, // from calc
|
|
||||||
{
|
|
||||||
.name = "Zero payments remaining",
|
|
||||||
.periodicRate = Number{5, -2},
|
|
||||||
.paymentsRemaining = 0,
|
|
||||||
.expectedPaymentFactor = Number{0},
|
|
||||||
} // edge case
|
|
||||||
};
|
|
||||||
|
|
||||||
for (auto const& tc : testCases)
|
|
||||||
{
|
|
||||||
testcase("computePaymentFactor: " + tc.name);
|
|
||||||
|
|
||||||
auto const computedPaymentFactor =
|
|
||||||
computePaymentFactor(tc.periodicRate, tc.paymentsRemaining);
|
|
||||||
BEAST_EXPECTS(
|
|
||||||
computedPaymentFactor == tc.expectedPaymentFactor,
|
|
||||||
"Payment factor mismatch: expected " +
|
|
||||||
to_string(tc.expectedPaymentFactor) + ", got " +
|
|
||||||
to_string(computedPaymentFactor));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
void
|
|
||||||
testLoanPeriodicPayment()
|
|
||||||
{
|
|
||||||
using namespace jtx;
|
|
||||||
using namespace ripple::detail;
|
|
||||||
|
|
||||||
struct TestCase
|
|
||||||
{
|
|
||||||
std::string name;
|
|
||||||
Number principalOutstanding;
|
|
||||||
Number periodicRate;
|
|
||||||
std::uint32_t paymentsRemaining;
|
|
||||||
Number expectedPeriodicPayment;
|
|
||||||
};
|
|
||||||
|
|
||||||
auto const testCases = std::vector<TestCase>{
|
|
||||||
{
|
|
||||||
.name = "Zero principal outstanding",
|
|
||||||
.principalOutstanding = Number{0},
|
|
||||||
.periodicRate = Number{5, -2},
|
|
||||||
.paymentsRemaining = 5,
|
|
||||||
.expectedPeriodicPayment = Number{0},
|
|
||||||
},
|
|
||||||
{
|
|
||||||
.name = "Zero payments remaining",
|
|
||||||
.principalOutstanding = Number{1'000},
|
|
||||||
.periodicRate = Number{5, -2},
|
|
||||||
.paymentsRemaining = 0,
|
|
||||||
.expectedPeriodicPayment = Number{0},
|
|
||||||
},
|
|
||||||
{
|
|
||||||
.name = "Zero periodic rate",
|
|
||||||
.principalOutstanding = Number{1'000},
|
|
||||||
.periodicRate = Number{0},
|
|
||||||
.paymentsRemaining = 4,
|
|
||||||
.expectedPeriodicPayment = Number{250},
|
|
||||||
},
|
|
||||||
{
|
|
||||||
.name = "Standard case",
|
|
||||||
.principalOutstanding = Number{1'000},
|
|
||||||
.periodicRate =
|
|
||||||
loanPeriodicRate(TenthBips32(100'000), 30 * 24 * 60 * 60),
|
|
||||||
.paymentsRemaining = 3,
|
|
||||||
.expectedPeriodicPayment =
|
|
||||||
Number{3895690663961231, -13}, // from calc
|
|
||||||
},
|
|
||||||
};
|
|
||||||
|
|
||||||
for (auto const& tc : testCases)
|
|
||||||
{
|
|
||||||
testcase("loanPeriodicPayment: " + tc.name);
|
|
||||||
|
|
||||||
auto const computedPeriodicPayment = loanPeriodicPayment(
|
|
||||||
tc.principalOutstanding, tc.periodicRate, tc.paymentsRemaining);
|
|
||||||
BEAST_EXPECTS(
|
|
||||||
computedPeriodicPayment == tc.expectedPeriodicPayment,
|
|
||||||
"Periodic payment mismatch: expected " +
|
|
||||||
to_string(tc.expectedPeriodicPayment) + ", got " +
|
|
||||||
to_string(computedPeriodicPayment));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
void
|
|
||||||
testLoanPrincipalFromPeriodicPayment()
|
|
||||||
{
|
|
||||||
using namespace jtx;
|
|
||||||
using namespace ripple::detail;
|
|
||||||
|
|
||||||
struct TestCase
|
|
||||||
{
|
|
||||||
std::string name;
|
|
||||||
Number periodicPayment;
|
|
||||||
Number periodicRate;
|
|
||||||
std::uint32_t paymentsRemaining;
|
|
||||||
Number expectedPrincipalOutstanding;
|
|
||||||
};
|
|
||||||
|
|
||||||
auto const testCases = std::vector<TestCase>{
|
|
||||||
{
|
|
||||||
.name = "Zero periodic payment",
|
|
||||||
.periodicPayment = Number{0},
|
|
||||||
.periodicRate = Number{5, -2},
|
|
||||||
.paymentsRemaining = 5,
|
|
||||||
.expectedPrincipalOutstanding = Number{0},
|
|
||||||
},
|
|
||||||
{
|
|
||||||
.name = "Zero payments remaining",
|
|
||||||
.periodicPayment = Number{1'000},
|
|
||||||
.periodicRate = Number{5, -2},
|
|
||||||
.paymentsRemaining = 0,
|
|
||||||
.expectedPrincipalOutstanding = Number{0},
|
|
||||||
},
|
|
||||||
{
|
|
||||||
.name = "Zero periodic rate",
|
|
||||||
.periodicPayment = Number{250},
|
|
||||||
.periodicRate = Number{0},
|
|
||||||
.paymentsRemaining = 4,
|
|
||||||
.expectedPrincipalOutstanding = Number{1'000},
|
|
||||||
},
|
|
||||||
{
|
|
||||||
.name = "Standard case",
|
|
||||||
.periodicPayment = Number{3895690663961231, -13}, // from calc
|
|
||||||
.periodicRate =
|
|
||||||
loanPeriodicRate(TenthBips32(100'000), 30 * 24 * 60 * 60),
|
|
||||||
.paymentsRemaining = 3,
|
|
||||||
.expectedPrincipalOutstanding = Number{1'000},
|
|
||||||
},
|
|
||||||
};
|
|
||||||
|
|
||||||
for (auto const& tc : testCases)
|
|
||||||
{
|
|
||||||
testcase("loanPrincipalFromPeriodicPayment: " + tc.name);
|
|
||||||
|
|
||||||
auto const computedPrincipalOutstanding =
|
|
||||||
loanPrincipalFromPeriodicPayment(
|
|
||||||
tc.periodicPayment, tc.periodicRate, tc.paymentsRemaining);
|
|
||||||
BEAST_EXPECTS(
|
|
||||||
computedPrincipalOutstanding == tc.expectedPrincipalOutstanding,
|
|
||||||
"Principal outstanding mismatch: expected " +
|
|
||||||
to_string(tc.expectedPrincipalOutstanding) + ", got " +
|
|
||||||
to_string(computedPrincipalOutstanding));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
void
|
|
||||||
testComputeOverpaymentComponents()
|
|
||||||
{
|
|
||||||
testcase("computeOverpaymentComponents");
|
|
||||||
using namespace jtx;
|
|
||||||
using namespace ripple::detail;
|
|
||||||
|
|
||||||
Account const issuer{"issuer"};
|
|
||||||
PrettyAsset const IOU = issuer["IOU"];
|
|
||||||
int32_t const loanScale = 1;
|
|
||||||
auto const overpayment = Number{1'000};
|
|
||||||
auto const overpaymentInterestRate = TenthBips32{10'000}; // 10%
|
|
||||||
auto const overpaymentFeeRate = TenthBips32{50'000}; // 50%
|
|
||||||
auto const managementFeeRate = TenthBips16{10'000}; // 10%
|
|
||||||
|
|
||||||
auto const expectedOverpaymentFee = Number{500}; // 50% of 1,000
|
|
||||||
auto const expectedOverpaymentInterestGross =
|
|
||||||
Number{100}; // 10% of 1,000
|
|
||||||
auto const expectedOverpaymentInterestNet =
|
|
||||||
Number{90}; // 100 - 10% of 100
|
|
||||||
auto const expectedOverpaymentManagementFee = Number{10}; // 10% of 100
|
|
||||||
auto const expectedPrincipalPortion = Number{400}; // 1,000 - 100 - 500
|
|
||||||
|
|
||||||
auto const components = detail::computeOverpaymentComponents(
|
|
||||||
IOU,
|
|
||||||
loanScale,
|
|
||||||
overpayment,
|
|
||||||
overpaymentInterestRate,
|
|
||||||
overpaymentFeeRate,
|
|
||||||
managementFeeRate);
|
|
||||||
|
|
||||||
BEAST_EXPECT(
|
|
||||||
components.untrackedManagementFee == expectedOverpaymentFee);
|
|
||||||
|
|
||||||
BEAST_EXPECT(
|
|
||||||
components.untrackedInterest == expectedOverpaymentInterestNet);
|
|
||||||
BEAST_EXPECT(
|
|
||||||
components.trackedManagementFeeDelta ==
|
|
||||||
expectedOverpaymentManagementFee);
|
|
||||||
BEAST_EXPECT(
|
|
||||||
components.trackedPrincipalDelta == expectedPrincipalPortion);
|
|
||||||
BEAST_EXPECT(
|
|
||||||
components.trackedManagementFeeDelta +
|
|
||||||
components.untrackedInterest ==
|
|
||||||
expectedOverpaymentInterestGross);
|
|
||||||
|
|
||||||
BEAST_EXPECT(
|
|
||||||
components.trackedManagementFeeDelta +
|
|
||||||
components.untrackedInterest +
|
|
||||||
components.trackedPrincipalDelta +
|
|
||||||
components.untrackedManagementFee ==
|
|
||||||
overpayment);
|
|
||||||
}
|
|
||||||
|
|
||||||
void
|
|
||||||
testComputeInterestAndFeeParts()
|
|
||||||
{
|
|
||||||
using namespace jtx;
|
|
||||||
using namespace ripple::detail;
|
|
||||||
|
|
||||||
struct TestCase
|
|
||||||
{
|
|
||||||
std::string name;
|
|
||||||
Number interest;
|
|
||||||
TenthBips16 managementFeeRate;
|
|
||||||
Number expectedInterestPart;
|
|
||||||
Number expectedFeePart;
|
|
||||||
};
|
|
||||||
|
|
||||||
Account const issuer{"issuer"};
|
|
||||||
PrettyAsset const IOU = issuer["IOU"];
|
|
||||||
std::int32_t const loanScale = 1;
|
|
||||||
|
|
||||||
auto const testCases = std::vector<TestCase>{
|
|
||||||
{.name = "Zero interest",
|
|
||||||
.interest = Number{0},
|
|
||||||
.managementFeeRate = TenthBips16{10'000},
|
|
||||||
.expectedInterestPart = Number{0},
|
|
||||||
.expectedFeePart = Number{0}},
|
|
||||||
{.name = "Zero fee rate",
|
|
||||||
.interest = Number{1'000},
|
|
||||||
.managementFeeRate = TenthBips16{0},
|
|
||||||
.expectedInterestPart = Number{1'000},
|
|
||||||
.expectedFeePart = Number{0}},
|
|
||||||
{.name = "10% fee rate",
|
|
||||||
.interest = Number{1'000},
|
|
||||||
.managementFeeRate = TenthBips16{10'000},
|
|
||||||
.expectedInterestPart = Number{900},
|
|
||||||
.expectedFeePart = Number{100}},
|
|
||||||
};
|
|
||||||
|
|
||||||
for (auto const& tc : testCases)
|
|
||||||
{
|
|
||||||
testcase("computeInterestAndFeeParts: " + tc.name);
|
|
||||||
|
|
||||||
auto const [computedInterestPart, computedFeePart] =
|
|
||||||
computeInterestAndFeeParts(
|
|
||||||
IOU, tc.interest, tc.managementFeeRate, loanScale);
|
|
||||||
BEAST_EXPECTS(
|
|
||||||
computedInterestPart == tc.expectedInterestPart,
|
|
||||||
"Interest part mismatch: expected " +
|
|
||||||
to_string(tc.expectedInterestPart) + ", got " +
|
|
||||||
to_string(computedInterestPart));
|
|
||||||
BEAST_EXPECTS(
|
|
||||||
computedFeePart == tc.expectedFeePart,
|
|
||||||
"Fee part mismatch: expected " + to_string(tc.expectedFeePart) +
|
|
||||||
", got " + to_string(computedFeePart));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
void
|
|
||||||
testLoanLatePaymentInterest()
|
|
||||||
{
|
|
||||||
using namespace jtx;
|
|
||||||
using namespace ripple::detail;
|
|
||||||
struct TestCase
|
|
||||||
{
|
|
||||||
std::string name;
|
|
||||||
Number principalOutstanding;
|
|
||||||
TenthBips32 lateInterestRate;
|
|
||||||
NetClock::time_point parentCloseTime;
|
|
||||||
std::uint32_t nextPaymentDueDate;
|
|
||||||
Number expectedLateInterest;
|
|
||||||
};
|
|
||||||
|
|
||||||
auto const testCases = std::vector<TestCase>{
|
|
||||||
{
|
|
||||||
.name = "On-time payment",
|
|
||||||
.principalOutstanding = Number{1'000},
|
|
||||||
.lateInterestRate = TenthBips32{10'000}, // 10%
|
|
||||||
.parentCloseTime =
|
|
||||||
NetClock::time_point{NetClock::duration{3'000}},
|
|
||||||
.nextPaymentDueDate = 3'000,
|
|
||||||
.expectedLateInterest = Number{0},
|
|
||||||
},
|
|
||||||
{
|
|
||||||
.name = "Early payment",
|
|
||||||
.principalOutstanding = Number{1'000},
|
|
||||||
.lateInterestRate = TenthBips32{10'000}, // 10%
|
|
||||||
.parentCloseTime =
|
|
||||||
NetClock::time_point{NetClock::duration{3'000}},
|
|
||||||
.nextPaymentDueDate = 4'000,
|
|
||||||
.expectedLateInterest = Number{0},
|
|
||||||
},
|
|
||||||
{
|
|
||||||
.name = "No principal outstanding",
|
|
||||||
.principalOutstanding = Number{0},
|
|
||||||
.lateInterestRate = TenthBips32{10'000}, // 10%
|
|
||||||
.parentCloseTime =
|
|
||||||
NetClock::time_point{NetClock::duration{3'000}},
|
|
||||||
.nextPaymentDueDate = 2'000,
|
|
||||||
.expectedLateInterest = Number{0},
|
|
||||||
},
|
|
||||||
{
|
|
||||||
.name = "No late interest rate",
|
|
||||||
.principalOutstanding = Number{1'000},
|
|
||||||
.lateInterestRate = TenthBips32{0}, // 0%
|
|
||||||
.parentCloseTime =
|
|
||||||
NetClock::time_point{NetClock::duration{3'000}},
|
|
||||||
.nextPaymentDueDate = 2'000,
|
|
||||||
.expectedLateInterest = Number{0},
|
|
||||||
},
|
|
||||||
{
|
|
||||||
.name = "Late payment",
|
|
||||||
.principalOutstanding = Number{1'000},
|
|
||||||
.lateInterestRate = TenthBips32{100'000}, // 100%
|
|
||||||
.parentCloseTime =
|
|
||||||
NetClock::time_point{NetClock::duration{3'000}},
|
|
||||||
.nextPaymentDueDate = 2'000,
|
|
||||||
.expectedLateInterest =
|
|
||||||
Number{3170979198376459, -17}, // from calc
|
|
||||||
},
|
|
||||||
};
|
|
||||||
|
|
||||||
for (auto const& tc : testCases)
|
|
||||||
{
|
|
||||||
testcase("loanLatePaymentInterest: " + tc.name);
|
|
||||||
|
|
||||||
auto const computedLateInterest = loanLatePaymentInterest(
|
|
||||||
tc.principalOutstanding,
|
|
||||||
tc.lateInterestRate,
|
|
||||||
tc.parentCloseTime,
|
|
||||||
tc.nextPaymentDueDate);
|
|
||||||
BEAST_EXPECTS(
|
|
||||||
computedLateInterest == tc.expectedLateInterest,
|
|
||||||
"Late interest mismatch: expected " +
|
|
||||||
to_string(tc.expectedLateInterest) + ", got " +
|
|
||||||
to_string(computedLateInterest));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
void
|
|
||||||
testLoanAccruedInterest()
|
|
||||||
{
|
|
||||||
using namespace jtx;
|
|
||||||
using namespace ripple::detail;
|
|
||||||
struct TestCase
|
|
||||||
{
|
|
||||||
std::string name;
|
|
||||||
Number principalOutstanding;
|
|
||||||
Number periodicRate;
|
|
||||||
NetClock::time_point parentCloseTime;
|
|
||||||
std::uint32_t startDate;
|
|
||||||
std::uint32_t prevPaymentDate;
|
|
||||||
std::uint32_t paymentInterval;
|
|
||||||
Number expectedAccruedInterest;
|
|
||||||
};
|
|
||||||
|
|
||||||
auto const testCases = std::vector<TestCase>{
|
|
||||||
{
|
|
||||||
.name = "Zero principal outstanding",
|
|
||||||
.principalOutstanding = Number{0},
|
|
||||||
.periodicRate = Number{5, -2},
|
|
||||||
.parentCloseTime =
|
|
||||||
NetClock::time_point{NetClock::duration{3'000}},
|
|
||||||
.startDate = 2'000,
|
|
||||||
.prevPaymentDate = 2'500,
|
|
||||||
.paymentInterval = 30 * 24 * 60 * 60,
|
|
||||||
.expectedAccruedInterest = Number{0},
|
|
||||||
},
|
|
||||||
{
|
|
||||||
.name = "Before start date",
|
|
||||||
.principalOutstanding = Number{1'000},
|
|
||||||
.periodicRate = Number{5, -2},
|
|
||||||
.parentCloseTime =
|
|
||||||
NetClock::time_point{NetClock::duration{1'000}},
|
|
||||||
.startDate = 2'000,
|
|
||||||
.prevPaymentDate = 1'500,
|
|
||||||
.paymentInterval = 30 * 24 * 60 * 60,
|
|
||||||
.expectedAccruedInterest = Number{0},
|
|
||||||
},
|
|
||||||
{
|
|
||||||
.name = "Zero periodic rate",
|
|
||||||
.principalOutstanding = Number{1'000},
|
|
||||||
.periodicRate = Number{0},
|
|
||||||
.parentCloseTime =
|
|
||||||
NetClock::time_point{NetClock::duration{3'000}},
|
|
||||||
.startDate = 2'000,
|
|
||||||
.prevPaymentDate = 2'500,
|
|
||||||
.paymentInterval = 30 * 24 * 60 * 60,
|
|
||||||
.expectedAccruedInterest = Number{0},
|
|
||||||
},
|
|
||||||
{
|
|
||||||
.name = "Zero payment interval",
|
|
||||||
.principalOutstanding = Number{1'000},
|
|
||||||
.periodicRate = Number{5, -2},
|
|
||||||
.parentCloseTime =
|
|
||||||
NetClock::time_point{NetClock::duration{3'000}},
|
|
||||||
.startDate = 2'000,
|
|
||||||
.prevPaymentDate = 2'500,
|
|
||||||
.paymentInterval = 0,
|
|
||||||
.expectedAccruedInterest = Number{0},
|
|
||||||
},
|
|
||||||
{
|
|
||||||
.name = "Standard case",
|
|
||||||
.principalOutstanding = Number{1'000},
|
|
||||||
.periodicRate = Number{5, -2},
|
|
||||||
.parentCloseTime =
|
|
||||||
NetClock::time_point{NetClock::duration{3'000}},
|
|
||||||
.startDate = 1'000,
|
|
||||||
.prevPaymentDate = 2'000,
|
|
||||||
.paymentInterval = 30 * 24 * 60 * 60,
|
|
||||||
.expectedAccruedInterest =
|
|
||||||
Number{1929012345679012, -17}, // from calc
|
|
||||||
},
|
|
||||||
};
|
|
||||||
|
|
||||||
for (auto const& tc : testCases)
|
|
||||||
{
|
|
||||||
testcase("loanAccruedInterest: " + tc.name);
|
|
||||||
|
|
||||||
auto const computedAccruedInterest = loanAccruedInterest(
|
|
||||||
tc.principalOutstanding,
|
|
||||||
tc.periodicRate,
|
|
||||||
tc.parentCloseTime,
|
|
||||||
tc.startDate,
|
|
||||||
tc.prevPaymentDate,
|
|
||||||
tc.paymentInterval);
|
|
||||||
BEAST_EXPECTS(
|
|
||||||
computedAccruedInterest == tc.expectedAccruedInterest,
|
|
||||||
"Accrued interest mismatch: expected " +
|
|
||||||
to_string(tc.expectedAccruedInterest) + ", got " +
|
|
||||||
to_string(computedAccruedInterest));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// This test overlaps with testLoanAccruedInterest, the test cases only
|
|
||||||
// exercise the computeFullPaymentInterest parts unique to it.
|
|
||||||
void
|
|
||||||
testComputeFullPaymentInterest()
|
|
||||||
{
|
|
||||||
using namespace jtx;
|
|
||||||
using namespace ripple::detail;
|
|
||||||
|
|
||||||
struct TestCase
|
|
||||||
{
|
|
||||||
std::string name;
|
|
||||||
Number rawPrincipalOutstanding;
|
|
||||||
Number periodicRate;
|
|
||||||
NetClock::time_point parentCloseTime;
|
|
||||||
std::uint32_t paymentInterval;
|
|
||||||
std::uint32_t prevPaymentDate;
|
|
||||||
std::uint32_t startDate;
|
|
||||||
TenthBips32 closeInterestRate;
|
|
||||||
Number expectedFullPaymentInterest;
|
|
||||||
};
|
|
||||||
|
|
||||||
auto const testCases = std::vector<TestCase>{
|
|
||||||
{
|
|
||||||
.name = "Zero principal outstanding",
|
|
||||||
.rawPrincipalOutstanding = Number{0},
|
|
||||||
.periodicRate = Number{5, -2},
|
|
||||||
.parentCloseTime =
|
|
||||||
NetClock::time_point{NetClock::duration{3'000}},
|
|
||||||
.paymentInterval = 30 * 24 * 60 * 60,
|
|
||||||
.prevPaymentDate = 2'000,
|
|
||||||
.startDate = 1'000,
|
|
||||||
.closeInterestRate = TenthBips32{10'000},
|
|
||||||
.expectedFullPaymentInterest = Number{0},
|
|
||||||
},
|
|
||||||
{
|
|
||||||
.name = "Zero close interest rate",
|
|
||||||
.rawPrincipalOutstanding = Number{1'000},
|
|
||||||
.periodicRate = Number{5, -2},
|
|
||||||
.parentCloseTime =
|
|
||||||
NetClock::time_point{NetClock::duration{3'000}},
|
|
||||||
.paymentInterval = 30 * 24 * 60 * 60,
|
|
||||||
.prevPaymentDate = 2'000,
|
|
||||||
.startDate = 1'000,
|
|
||||||
.closeInterestRate = TenthBips32{0},
|
|
||||||
.expectedFullPaymentInterest =
|
|
||||||
Number{1929012345679012, -17}, // from calc
|
|
||||||
},
|
|
||||||
{
|
|
||||||
.name = "Standard case",
|
|
||||||
.rawPrincipalOutstanding = Number{1'000},
|
|
||||||
.periodicRate = Number{5, -2},
|
|
||||||
.parentCloseTime =
|
|
||||||
NetClock::time_point{NetClock::duration{3'000}},
|
|
||||||
.paymentInterval = 30 * 24 * 60 * 60,
|
|
||||||
.prevPaymentDate = 2'000,
|
|
||||||
.startDate = 1'000,
|
|
||||||
.closeInterestRate = TenthBips32{10'000},
|
|
||||||
.expectedFullPaymentInterest =
|
|
||||||
Number{1000192901234568, -13}, // from calc
|
|
||||||
},
|
|
||||||
};
|
|
||||||
|
|
||||||
for (auto const& tc : testCases)
|
|
||||||
{
|
|
||||||
testcase("computeFullPaymentInterest: " + tc.name);
|
|
||||||
|
|
||||||
auto const computedFullPaymentInterest = computeFullPaymentInterest(
|
|
||||||
tc.rawPrincipalOutstanding,
|
|
||||||
tc.periodicRate,
|
|
||||||
tc.parentCloseTime,
|
|
||||||
tc.paymentInterval,
|
|
||||||
tc.prevPaymentDate,
|
|
||||||
tc.startDate,
|
|
||||||
tc.closeInterestRate);
|
|
||||||
BEAST_EXPECTS(
|
|
||||||
computedFullPaymentInterest == tc.expectedFullPaymentInterest,
|
|
||||||
"Full payment interest mismatch: expected " +
|
|
||||||
to_string(tc.expectedFullPaymentInterest) + ", got " +
|
|
||||||
to_string(computedFullPaymentInterest));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
public:
|
|
||||||
void
|
|
||||||
run() override
|
|
||||||
{
|
|
||||||
testComputeFullPaymentInterest();
|
|
||||||
testLoanAccruedInterest();
|
|
||||||
testLoanLatePaymentInterest();
|
|
||||||
testLoanPeriodicPayment();
|
|
||||||
testLoanPrincipalFromPeriodicPayment();
|
|
||||||
testComputeRaisedRate();
|
|
||||||
testComputePaymentFactor();
|
|
||||||
testComputeOverpaymentComponents();
|
|
||||||
testComputeInterestAndFeeParts();
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
BEAST_DEFINE_TESTSUITE(LendingHelpers, app, ripple);
|
|
||||||
|
|
||||||
} // namespace test
|
|
||||||
} // namespace ripple
|
|
||||||
@@ -141,7 +141,7 @@ protected:
|
|||||||
using namespace jtx;
|
using namespace jtx;
|
||||||
|
|
||||||
auto const vaultSle = env.le(keylet::vault(vaultID));
|
auto const vaultSle = env.le(keylet::vault(vaultID));
|
||||||
return getAssetsTotalScale(vaultSle);
|
return getVaultScale(vaultSle);
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
@@ -551,15 +551,12 @@ protected:
|
|||||||
broker.vaultScale(env),
|
broker.vaultScale(env),
|
||||||
state.principalOutstanding.exponent())));
|
state.principalOutstanding.exponent())));
|
||||||
BEAST_EXPECT(state.paymentInterval == 600);
|
BEAST_EXPECT(state.paymentInterval == 600);
|
||||||
{
|
BEAST_EXPECT(
|
||||||
NumberRoundModeGuard mg(Number::upward);
|
state.totalValue ==
|
||||||
BEAST_EXPECT(
|
roundToAsset(
|
||||||
state.totalValue ==
|
broker.asset,
|
||||||
roundToAsset(
|
state.periodicPayment * state.paymentRemaining,
|
||||||
broker.asset,
|
state.loanScale));
|
||||||
state.periodicPayment * state.paymentRemaining,
|
|
||||||
state.loanScale));
|
|
||||||
}
|
|
||||||
BEAST_EXPECT(
|
BEAST_EXPECT(
|
||||||
state.managementFeeOutstanding ==
|
state.managementFeeOutstanding ==
|
||||||
computeManagementFee(
|
computeManagementFee(
|
||||||
@@ -700,8 +697,7 @@ protected:
|
|||||||
interval,
|
interval,
|
||||||
total,
|
total,
|
||||||
feeRate,
|
feeRate,
|
||||||
asset(brokerParams.vaultDeposit).number().exponent(),
|
asset(brokerParams.vaultDeposit).number().exponent());
|
||||||
env.journal);
|
|
||||||
log << "Loan properties:\n"
|
log << "Loan properties:\n"
|
||||||
<< "\tPrincipal: " << principal << std::endl
|
<< "\tPrincipal: " << principal << std::endl
|
||||||
<< "\tInterest rate: " << interest << std::endl
|
<< "\tInterest rate: " << interest << std::endl
|
||||||
@@ -1275,8 +1271,7 @@ protected:
|
|||||||
verifyLoanStatus,
|
verifyLoanStatus,
|
||||||
issuer,
|
issuer,
|
||||||
lender,
|
lender,
|
||||||
borrower,
|
borrower);
|
||||||
PaymentParameters{.showStepBalances = true});
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/** Runs through the complete lifecycle of a loan
|
/** Runs through the complete lifecycle of a loan
|
||||||
@@ -1482,8 +1477,7 @@ protected:
|
|||||||
state.paymentInterval,
|
state.paymentInterval,
|
||||||
state.paymentRemaining,
|
state.paymentRemaining,
|
||||||
broker.params.managementFeeRate,
|
broker.params.managementFeeRate,
|
||||||
state.loanScale,
|
state.loanScale);
|
||||||
env.journal);
|
|
||||||
|
|
||||||
verifyLoanStatus(
|
verifyLoanStatus(
|
||||||
0,
|
0,
|
||||||
@@ -2454,18 +2448,13 @@ protected:
|
|||||||
// Make all the payments in one transaction
|
// Make all the payments in one transaction
|
||||||
// service fee is 2
|
// service fee is 2
|
||||||
auto const startingPayments = state.paymentRemaining;
|
auto const startingPayments = state.paymentRemaining;
|
||||||
STAmount const payoffAmount = [&]() {
|
auto const rawPayoff = startingPayments *
|
||||||
NumberRoundModeGuard mg(Number::upward);
|
(state.periodicPayment + broker.asset(2).value());
|
||||||
auto const rawPayoff = startingPayments *
|
STAmount const payoffAmount{broker.asset, rawPayoff};
|
||||||
(state.periodicPayment + broker.asset(2).value());
|
BEAST_EXPECT(
|
||||||
STAmount const payoffAmount{broker.asset, rawPayoff};
|
payoffAmount ==
|
||||||
BEAST_EXPECTS(
|
broker.asset(Number(1024014840139457, -12)));
|
||||||
payoffAmount ==
|
BEAST_EXPECT(payoffAmount > state.principalOutstanding);
|
||||||
broker.asset(Number(1024014840139457, -12)),
|
|
||||||
to_string(payoffAmount));
|
|
||||||
BEAST_EXPECT(payoffAmount > state.principalOutstanding);
|
|
||||||
return payoffAmount;
|
|
||||||
}();
|
|
||||||
|
|
||||||
singlePayment(
|
singlePayment(
|
||||||
loanKeylet,
|
loanKeylet,
|
||||||
@@ -4020,7 +4009,7 @@ protected:
|
|||||||
createJson = env.json(createJson, sig(sfCounterpartySignature, lender));
|
createJson = env.json(createJson, sig(sfCounterpartySignature, lender));
|
||||||
// Fails in preclaim because principal requested can't be
|
// Fails in preclaim because principal requested can't be
|
||||||
// represented as XRP
|
// represented as XRP
|
||||||
env(createJson, ter(tecPRECISION_LOSS), THISLINE);
|
env(createJson, ter(tecPRECISION_LOSS));
|
||||||
env.close();
|
env.close();
|
||||||
|
|
||||||
BEAST_EXPECT(!env.le(keylet));
|
BEAST_EXPECT(!env.le(keylet));
|
||||||
@@ -4032,7 +4021,7 @@ protected:
|
|||||||
createJson = env.json(createJson, sig(sfCounterpartySignature, lender));
|
createJson = env.json(createJson, sig(sfCounterpartySignature, lender));
|
||||||
// Fails in doApply because the payment is too small to be
|
// Fails in doApply because the payment is too small to be
|
||||||
// represented as XRP.
|
// represented as XRP.
|
||||||
env(createJson, ter(tecPRECISION_LOSS), THISLINE);
|
env(createJson, ter(tecPRECISION_LOSS));
|
||||||
env.close();
|
env.close();
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -5007,7 +4996,7 @@ protected:
|
|||||||
auto const keylet = keylet::loan(broker.brokerID, loanSequence);
|
auto const keylet = keylet::loan(broker.brokerID, loanSequence);
|
||||||
|
|
||||||
createJson = env.json(createJson, sig(sfCounterpartySignature, lender));
|
createJson = env.json(createJson, sig(sfCounterpartySignature, lender));
|
||||||
env(createJson, ter(tecPRECISION_LOSS), THISLINE);
|
env(createJson, ter(tecPRECISION_LOSS));
|
||||||
env.close(startDate);
|
env.close(startDate);
|
||||||
|
|
||||||
auto loanPayTx = env.json(
|
auto loanPayTx = env.json(
|
||||||
@@ -6155,16 +6144,15 @@ protected:
|
|||||||
// Accrued + prepayment-penalty interest based on current periodic
|
// Accrued + prepayment-penalty interest based on current periodic
|
||||||
// schedule
|
// schedule
|
||||||
auto const fullPaymentInterest = computeFullPaymentInterest(
|
auto const fullPaymentInterest = computeFullPaymentInterest(
|
||||||
detail::loanPrincipalFromPeriodicPayment(
|
after.periodicPayment,
|
||||||
after.periodicPayment, periodicRate2, after.paymentRemaining),
|
|
||||||
periodicRate2,
|
periodicRate2,
|
||||||
|
after.paymentRemaining,
|
||||||
env.current()->parentCloseTime(),
|
env.current()->parentCloseTime(),
|
||||||
after.paymentInterval,
|
after.paymentInterval,
|
||||||
after.previousPaymentDate,
|
after.previousPaymentDate,
|
||||||
static_cast<std::uint32_t>(
|
static_cast<std::uint32_t>(
|
||||||
after.startDate.time_since_epoch().count()),
|
after.startDate.time_since_epoch().count()),
|
||||||
closeInterestRate);
|
closeInterestRate);
|
||||||
|
|
||||||
// Round to asset scale and split interest/fee parts
|
// Round to asset scale and split interest/fee parts
|
||||||
auto const roundedInterest =
|
auto const roundedInterest =
|
||||||
roundToAsset(asset.raw(), fullPaymentInterest, after.loanScale);
|
roundToAsset(asset.raw(), fullPaymentInterest, after.loanScale);
|
||||||
@@ -6192,9 +6180,9 @@ protected:
|
|||||||
// window by clamping prevPaymentDate to 'now' for the full-pay path.
|
// window by clamping prevPaymentDate to 'now' for the full-pay path.
|
||||||
auto const prevClamped = std::min(after.previousPaymentDate, nowSecs);
|
auto const prevClamped = std::min(after.previousPaymentDate, nowSecs);
|
||||||
auto const fullPaymentInterestClamped = computeFullPaymentInterest(
|
auto const fullPaymentInterestClamped = computeFullPaymentInterest(
|
||||||
detail::loanPrincipalFromPeriodicPayment(
|
after.periodicPayment,
|
||||||
after.periodicPayment, periodicRate2, after.paymentRemaining),
|
|
||||||
periodicRate2,
|
periodicRate2,
|
||||||
|
after.paymentRemaining,
|
||||||
env.current()->parentCloseTime(),
|
env.current()->parentCloseTime(),
|
||||||
after.paymentInterval,
|
after.paymentInterval,
|
||||||
prevClamped,
|
prevClamped,
|
||||||
@@ -7205,15 +7193,15 @@ class LoanArbitrary_test : public LoanBatch_test
|
|||||||
.vaultDeposit = 10000,
|
.vaultDeposit = 10000,
|
||||||
.debtMax = 0,
|
.debtMax = 0,
|
||||||
.coverRateMin = TenthBips32{0},
|
.coverRateMin = TenthBips32{0},
|
||||||
.managementFeeRate = TenthBips16{0},
|
// .managementFeeRate = TenthBips16{5919},
|
||||||
.coverRateLiquidation = TenthBips32{0}};
|
.coverRateLiquidation = TenthBips32{0}};
|
||||||
LoanParameters const loanParams{
|
LoanParameters const loanParams{
|
||||||
.account = Account("lender"),
|
.account = Account("lender"),
|
||||||
.counter = Account("borrower"),
|
.counter = Account("borrower"),
|
||||||
.principalRequest = Number{200000, -6},
|
.principalRequest = Number{10000, 0},
|
||||||
.interest = TenthBips32{50000},
|
// .interest = TenthBips32{0},
|
||||||
.payTotal = 2,
|
// .payTotal = 5816,
|
||||||
.payInterval = 200};
|
.payInterval = 150};
|
||||||
|
|
||||||
runLoan(AssetType::XRP, brokerParams, loanParams);
|
runLoan(AssetType::XRP, brokerParams, loanParams);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -644,7 +644,7 @@ MPTTester::operator[](std::string const& name) const
|
|||||||
}
|
}
|
||||||
|
|
||||||
PrettyAmount
|
PrettyAmount
|
||||||
MPTTester::operator()(std::int64_t amount) const
|
MPTTester::operator()(std::uint64_t amount) const
|
||||||
{
|
{
|
||||||
return MPT("", issuanceID())(amount);
|
return MPT("", issuanceID())(amount);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -272,7 +272,7 @@ public:
|
|||||||
operator[](std::string const& name) const;
|
operator[](std::string const& name) const;
|
||||||
|
|
||||||
PrettyAmount
|
PrettyAmount
|
||||||
operator()(std::int64_t amount) const;
|
operator()(std::uint64_t amount) const;
|
||||||
|
|
||||||
operator Asset() const;
|
operator Asset() const;
|
||||||
|
|
||||||
|
|||||||
@@ -179,12 +179,11 @@ adjustImpreciseNumber(
|
|||||||
}
|
}
|
||||||
|
|
||||||
inline int
|
inline int
|
||||||
getAssetsTotalScale(SLE::const_ref vaultSle)
|
getVaultScale(SLE::const_ref vaultSle)
|
||||||
{
|
{
|
||||||
if (!vaultSle)
|
if (!vaultSle)
|
||||||
return Number::minExponent - 1; // LCOV_EXCL_LINE
|
return Number::minExponent - 1; // LCOV_EXCL_LINE
|
||||||
return STAmount{vaultSle->at(sfAsset), vaultSle->at(sfAssetsTotal)}
|
return vaultSle->at(sfAssetsTotal).exponent();
|
||||||
.exponent();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
TER
|
TER
|
||||||
@@ -203,6 +202,14 @@ computeRawLoanState(
|
|||||||
std::uint32_t const paymentRemaining,
|
std::uint32_t const paymentRemaining,
|
||||||
TenthBips32 const managementFeeRate);
|
TenthBips32 const managementFeeRate);
|
||||||
|
|
||||||
|
LoanState
|
||||||
|
computeRawLoanState(
|
||||||
|
Number const& periodicPayment,
|
||||||
|
TenthBips32 interestRate,
|
||||||
|
std::uint32_t paymentInterval,
|
||||||
|
std::uint32_t const paymentRemaining,
|
||||||
|
TenthBips32 const managementFeeRate);
|
||||||
|
|
||||||
// Constructs a valid LoanState object from arbitrary inputs
|
// Constructs a valid LoanState object from arbitrary inputs
|
||||||
LoanState
|
LoanState
|
||||||
constructLoanState(
|
constructLoanState(
|
||||||
@@ -232,6 +239,17 @@ computeFullPaymentInterest(
|
|||||||
std::uint32_t startDate,
|
std::uint32_t startDate,
|
||||||
TenthBips32 closeInterestRate);
|
TenthBips32 closeInterestRate);
|
||||||
|
|
||||||
|
Number
|
||||||
|
computeFullPaymentInterest(
|
||||||
|
Number const& periodicPayment,
|
||||||
|
Number const& periodicRate,
|
||||||
|
std::uint32_t paymentRemaining,
|
||||||
|
NetClock::time_point parentCloseTime,
|
||||||
|
std::uint32_t paymentInterval,
|
||||||
|
std::uint32_t prevPaymentDate,
|
||||||
|
std::uint32_t startDate,
|
||||||
|
TenthBips32 closeInterestRate);
|
||||||
|
|
||||||
namespace detail {
|
namespace detail {
|
||||||
// These classes and functions should only be accessed by LendingHelper
|
// These classes and functions should only be accessed by LendingHelper
|
||||||
// functions and unit tests
|
// functions and unit tests
|
||||||
@@ -369,58 +387,6 @@ struct LoanStateDeltas
|
|||||||
nonNegative();
|
nonNegative();
|
||||||
};
|
};
|
||||||
|
|
||||||
Number
|
|
||||||
computeRaisedRate(Number const& periodicRate, std::uint32_t paymentsRemaining);
|
|
||||||
|
|
||||||
Number
|
|
||||||
computePaymentFactor(
|
|
||||||
Number const& periodicRate,
|
|
||||||
std::uint32_t paymentsRemaining);
|
|
||||||
|
|
||||||
std::pair<Number, Number>
|
|
||||||
computeInterestAndFeeParts(
|
|
||||||
Asset const& asset,
|
|
||||||
Number const& interest,
|
|
||||||
TenthBips16 managementFeeRate,
|
|
||||||
std::int32_t loanScale);
|
|
||||||
|
|
||||||
Number
|
|
||||||
loanPeriodicPayment(
|
|
||||||
Number const& principalOutstanding,
|
|
||||||
Number const& periodicRate,
|
|
||||||
std::uint32_t paymentsRemaining);
|
|
||||||
|
|
||||||
Number
|
|
||||||
loanPrincipalFromPeriodicPayment(
|
|
||||||
Number const& periodicPayment,
|
|
||||||
Number const& periodicRate,
|
|
||||||
std::uint32_t paymentsRemaining);
|
|
||||||
|
|
||||||
Number
|
|
||||||
loanLatePaymentInterest(
|
|
||||||
Number const& principalOutstanding,
|
|
||||||
TenthBips32 lateInterestRate,
|
|
||||||
NetClock::time_point parentCloseTime,
|
|
||||||
std::uint32_t nextPaymentDueDate);
|
|
||||||
|
|
||||||
Number
|
|
||||||
loanAccruedInterest(
|
|
||||||
Number const& principalOutstanding,
|
|
||||||
Number const& periodicRate,
|
|
||||||
NetClock::time_point parentCloseTime,
|
|
||||||
std::uint32_t startDate,
|
|
||||||
std::uint32_t prevPaymentDate,
|
|
||||||
std::uint32_t paymentInterval);
|
|
||||||
|
|
||||||
ExtendedPaymentComponents
|
|
||||||
computeOverpaymentComponents(
|
|
||||||
Asset const& asset,
|
|
||||||
int32_t const loanScale,
|
|
||||||
Number const& overpayment,
|
|
||||||
TenthBips32 const overpaymentInterestRate,
|
|
||||||
TenthBips32 const overpaymentFeeRate,
|
|
||||||
TenthBips16 const managementFeeRate);
|
|
||||||
|
|
||||||
PaymentComponents
|
PaymentComponents
|
||||||
computePaymentComponents(
|
computePaymentComponents(
|
||||||
Asset const& asset,
|
Asset const& asset,
|
||||||
@@ -452,8 +418,7 @@ computeLoanProperties(
|
|||||||
std::uint32_t paymentInterval,
|
std::uint32_t paymentInterval,
|
||||||
std::uint32_t paymentsRemaining,
|
std::uint32_t paymentsRemaining,
|
||||||
TenthBips32 managementFeeRate,
|
TenthBips32 managementFeeRate,
|
||||||
std::int32_t minimumScale,
|
std::int32_t minimumScale);
|
||||||
beast::Journal j);
|
|
||||||
|
|
||||||
bool
|
bool
|
||||||
isRounded(Asset const& asset, Number const& value, std::int32_t scale);
|
isRounded(Asset const& asset, Number const& value, std::int32_t scale);
|
||||||
|
|||||||
@@ -100,9 +100,6 @@ computePaymentFactor(
|
|||||||
Number const& periodicRate,
|
Number const& periodicRate,
|
||||||
std::uint32_t paymentsRemaining)
|
std::uint32_t paymentsRemaining)
|
||||||
{
|
{
|
||||||
if (paymentsRemaining == 0)
|
|
||||||
return numZero;
|
|
||||||
|
|
||||||
// For zero interest, payment factor is simply 1/paymentsRemaining
|
// For zero interest, payment factor is simply 1/paymentsRemaining
|
||||||
if (periodicRate == beast::zero)
|
if (periodicRate == beast::zero)
|
||||||
return Number{1} / paymentsRemaining;
|
return Number{1} / paymentsRemaining;
|
||||||
@@ -135,6 +132,27 @@ loanPeriodicPayment(
|
|||||||
computePaymentFactor(periodicRate, paymentsRemaining);
|
computePaymentFactor(periodicRate, paymentsRemaining);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/* Calculates the periodic payment amount from annualized interest rate.
|
||||||
|
* Converts the annual rate to periodic rate before computing payment.
|
||||||
|
*
|
||||||
|
* Equation (7) from XLS-66 spec, Section A-2 Equation Glossary
|
||||||
|
*/
|
||||||
|
Number
|
||||||
|
loanPeriodicPayment(
|
||||||
|
Number const& principalOutstanding,
|
||||||
|
TenthBips32 interestRate,
|
||||||
|
std::uint32_t paymentInterval,
|
||||||
|
std::uint32_t paymentsRemaining)
|
||||||
|
{
|
||||||
|
if (principalOutstanding == 0 || paymentsRemaining == 0)
|
||||||
|
return 0;
|
||||||
|
|
||||||
|
Number const periodicRate = loanPeriodicRate(interestRate, paymentInterval);
|
||||||
|
|
||||||
|
return loanPeriodicPayment(
|
||||||
|
principalOutstanding, periodicRate, paymentsRemaining);
|
||||||
|
}
|
||||||
|
|
||||||
/* Reverse-calculates principal from periodic payment amount.
|
/* Reverse-calculates principal from periodic payment amount.
|
||||||
* Used to determine theoretical principal at any point in the schedule.
|
* Used to determine theoretical principal at any point in the schedule.
|
||||||
*
|
*
|
||||||
@@ -146,9 +164,6 @@ loanPrincipalFromPeriodicPayment(
|
|||||||
Number const& periodicRate,
|
Number const& periodicRate,
|
||||||
std::uint32_t paymentsRemaining)
|
std::uint32_t paymentsRemaining)
|
||||||
{
|
{
|
||||||
if (paymentsRemaining == 0)
|
|
||||||
return numZero;
|
|
||||||
|
|
||||||
if (periodicRate == 0)
|
if (periodicRate == 0)
|
||||||
return periodicPayment * paymentsRemaining;
|
return periodicPayment * paymentsRemaining;
|
||||||
|
|
||||||
@@ -156,6 +171,21 @@ loanPrincipalFromPeriodicPayment(
|
|||||||
computePaymentFactor(periodicRate, paymentsRemaining);
|
computePaymentFactor(periodicRate, paymentsRemaining);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/* Splits gross interest into net interest (to vault) and management fee (to
|
||||||
|
* broker). Returns pair of (net interest, management fee).
|
||||||
|
*
|
||||||
|
* Equation (33) from XLS-66 spec, Section A-2 Equation Glossary
|
||||||
|
*/
|
||||||
|
std::pair<Number, Number>
|
||||||
|
computeInterestAndFeeParts(
|
||||||
|
Number const& interest,
|
||||||
|
TenthBips16 managementFeeRate)
|
||||||
|
{
|
||||||
|
auto const fee = tenthBipsOfValue(interest, managementFeeRate);
|
||||||
|
|
||||||
|
return std::make_pair(interest - fee, fee);
|
||||||
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Computes the interest and management fee parts from interest amount.
|
* Computes the interest and management fee parts from interest amount.
|
||||||
*
|
*
|
||||||
@@ -186,12 +216,6 @@ loanLatePaymentInterest(
|
|||||||
NetClock::time_point parentCloseTime,
|
NetClock::time_point parentCloseTime,
|
||||||
std::uint32_t nextPaymentDueDate)
|
std::uint32_t nextPaymentDueDate)
|
||||||
{
|
{
|
||||||
if (principalOutstanding == beast::zero)
|
|
||||||
return numZero;
|
|
||||||
|
|
||||||
if (lateInterestRate == TenthBips32{0})
|
|
||||||
return numZero;
|
|
||||||
|
|
||||||
auto const now = parentCloseTime.time_since_epoch().count();
|
auto const now = parentCloseTime.time_since_epoch().count();
|
||||||
|
|
||||||
// If the payment is not late by any amount of time, then there's no late
|
// If the payment is not late by any amount of time, then there's no late
|
||||||
@@ -224,9 +248,6 @@ loanAccruedInterest(
|
|||||||
if (periodicRate == beast::zero)
|
if (periodicRate == beast::zero)
|
||||||
return numZero;
|
return numZero;
|
||||||
|
|
||||||
if (paymentInterval == 0)
|
|
||||||
return numZero;
|
|
||||||
|
|
||||||
auto const lastPaymentDate = std::max(prevPaymentDate, startDate);
|
auto const lastPaymentDate = std::max(prevPaymentDate, startDate);
|
||||||
auto const now = parentCloseTime.time_since_epoch().count();
|
auto const now = parentCloseTime.time_since_epoch().count();
|
||||||
|
|
||||||
@@ -430,8 +451,7 @@ tryOverpayment(
|
|||||||
paymentInterval,
|
paymentInterval,
|
||||||
paymentRemaining,
|
paymentRemaining,
|
||||||
managementFeeRate,
|
managementFeeRate,
|
||||||
loanScale,
|
loanScale);
|
||||||
j);
|
|
||||||
|
|
||||||
JLOG(j.debug()) << "new periodic payment: "
|
JLOG(j.debug()) << "new periodic payment: "
|
||||||
<< newLoanProperties.periodicPayment
|
<< newLoanProperties.periodicPayment
|
||||||
@@ -527,28 +547,21 @@ tryOverpayment(
|
|||||||
|
|
||||||
auto const deltas = rounded - newRounded;
|
auto const deltas = rounded - newRounded;
|
||||||
|
|
||||||
// The change in loan management fee is equal to the change between the old
|
|
||||||
// and the new outstanding management fees
|
|
||||||
XRPL_ASSERT_PARTS(
|
|
||||||
deltas.managementFee ==
|
|
||||||
rounded.managementFeeDue - managementFeeOutstanding,
|
|
||||||
"ripple::detail::tryOverpayment",
|
|
||||||
"no fee change");
|
|
||||||
|
|
||||||
auto const hypotheticalValueOutstanding =
|
auto const hypotheticalValueOutstanding =
|
||||||
rounded.valueOutstanding - deltas.principal;
|
rounded.valueOutstanding - deltas.principal;
|
||||||
|
|
||||||
// Calculate how the loan's value changed due to the overpayment.
|
// Calculate how the loan's value changed due to the overpayment.
|
||||||
// This should be negative (value decreased) or zero. A principal
|
// This should be negative (value decreased) or zero. A principal
|
||||||
// overpayment should never increase the loan's value.
|
// overpayment should never increase the loan's value.
|
||||||
auto const valueChange = newRounded.valueOutstanding -
|
auto const valueChange =
|
||||||
hypotheticalValueOutstanding - deltas.managementFee;
|
newRounded.valueOutstanding - hypotheticalValueOutstanding;
|
||||||
if (valueChange > 0)
|
if (valueChange > 0)
|
||||||
{
|
{
|
||||||
JLOG(j.warn()) << "Principal overpayment would increase the value of "
|
JLOG(j.warn()) << "Principal overpayment would increase the value of "
|
||||||
"the loan. Ignore the overpayment";
|
"the loan. Ignore the overpayment";
|
||||||
return Unexpected(tesSUCCESS);
|
return Unexpected(tesSUCCESS);
|
||||||
}
|
}
|
||||||
|
|
||||||
return LoanPaymentParts{
|
return LoanPaymentParts{
|
||||||
// Principal paid is the reduction in principal outstanding
|
// Principal paid is the reduction in principal outstanding
|
||||||
.principalPaid = deltas.principal,
|
.principalPaid = deltas.principal,
|
||||||
@@ -663,6 +676,12 @@ doOverpayment(
|
|||||||
"ripple::detail::doOverpayment",
|
"ripple::detail::doOverpayment",
|
||||||
"principal change agrees");
|
"principal change agrees");
|
||||||
|
|
||||||
|
XRPL_ASSERT_PARTS(
|
||||||
|
overpaymentComponents.trackedManagementFeeDelta ==
|
||||||
|
managementFeeOutstandingProxy - managementFeeOutstanding,
|
||||||
|
"ripple::detail::doOverpayment",
|
||||||
|
"no fee change");
|
||||||
|
|
||||||
// I'm not 100% sure the following asserts are correct. If in doubt, and
|
// I'm not 100% sure the following asserts are correct. If in doubt, and
|
||||||
// everything else works, remove any that cause trouble.
|
// everything else works, remove any that cause trouble.
|
||||||
|
|
||||||
@@ -693,6 +712,13 @@ doOverpayment(
|
|||||||
"ripple::detail::doOverpayment",
|
"ripple::detail::doOverpayment",
|
||||||
"principal payment matches");
|
"principal payment matches");
|
||||||
|
|
||||||
|
XRPL_ASSERT_PARTS(
|
||||||
|
loanPaymentParts.feePaid ==
|
||||||
|
overpaymentComponents.untrackedManagementFee +
|
||||||
|
overpaymentComponents.trackedManagementFeeDelta,
|
||||||
|
"ripple::detail::doOverpayment",
|
||||||
|
"fee payment matches");
|
||||||
|
|
||||||
// All validations passed, so update the proxy objects (which will
|
// All validations passed, so update the proxy objects (which will
|
||||||
// modify the actual Loan ledger object)
|
// modify the actual Loan ledger object)
|
||||||
totalValueOutstandingProxy = totalValueOutstanding;
|
totalValueOutstandingProxy = totalValueOutstanding;
|
||||||
@@ -1205,12 +1231,17 @@ computeOverpaymentComponents(
|
|||||||
// This interest doesn't follow the normal amortization schedule - it's
|
// This interest doesn't follow the normal amortization schedule - it's
|
||||||
// a one-time charge for paying early.
|
// a one-time charge for paying early.
|
||||||
// Equation (20) and (21) from XLS-66 spec, Section A-2 Equation Glossary
|
// Equation (20) and (21) from XLS-66 spec, Section A-2 Equation Glossary
|
||||||
|
auto const [rawOverpaymentInterest, _] = [&]() {
|
||||||
|
Number const interest =
|
||||||
|
tenthBipsOfValue(overpayment, overpaymentInterestRate);
|
||||||
|
return detail::computeInterestAndFeeParts(interest, managementFeeRate);
|
||||||
|
}();
|
||||||
|
|
||||||
|
// Round the penalty interest components to the loan scale
|
||||||
auto const [roundedOverpaymentInterest, roundedOverpaymentManagementFee] =
|
auto const [roundedOverpaymentInterest, roundedOverpaymentManagementFee] =
|
||||||
[&]() {
|
[&]() {
|
||||||
auto const interest = roundToAsset(
|
Number const interest =
|
||||||
asset,
|
roundToAsset(asset, rawOverpaymentInterest, loanScale);
|
||||||
tenthBipsOfValue(overpayment, overpaymentInterestRate),
|
|
||||||
loanScale);
|
|
||||||
return detail::computeInterestAndFeeParts(
|
return detail::computeInterestAndFeeParts(
|
||||||
asset, interest, managementFeeRate, loanScale);
|
asset, interest, managementFeeRate, loanScale);
|
||||||
}();
|
}();
|
||||||
@@ -1404,6 +1435,31 @@ computeFullPaymentInterest(
|
|||||||
return accruedInterest + prepaymentPenalty;
|
return accruedInterest + prepaymentPenalty;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Number
|
||||||
|
computeFullPaymentInterest(
|
||||||
|
Number const& periodicPayment,
|
||||||
|
Number const& periodicRate,
|
||||||
|
std::uint32_t paymentRemaining,
|
||||||
|
NetClock::time_point parentCloseTime,
|
||||||
|
std::uint32_t paymentInterval,
|
||||||
|
std::uint32_t prevPaymentDate,
|
||||||
|
std::uint32_t startDate,
|
||||||
|
TenthBips32 closeInterestRate)
|
||||||
|
{
|
||||||
|
Number const rawPrincipalOutstanding =
|
||||||
|
detail::loanPrincipalFromPeriodicPayment(
|
||||||
|
periodicPayment, periodicRate, paymentRemaining);
|
||||||
|
|
||||||
|
return computeFullPaymentInterest(
|
||||||
|
rawPrincipalOutstanding,
|
||||||
|
periodicRate,
|
||||||
|
parentCloseTime,
|
||||||
|
paymentInterval,
|
||||||
|
prevPaymentDate,
|
||||||
|
startDate,
|
||||||
|
closeInterestRate);
|
||||||
|
}
|
||||||
|
|
||||||
/* Calculates the theoretical loan state at maximum precision for a given point
|
/* Calculates the theoretical loan state at maximum precision for a given point
|
||||||
* in the amortization schedule.
|
* in the amortization schedule.
|
||||||
*
|
*
|
||||||
@@ -1465,6 +1521,21 @@ computeRawLoanState(
|
|||||||
.managementFeeDue = rawManagementFeeOutstanding};
|
.managementFeeDue = rawManagementFeeOutstanding};
|
||||||
};
|
};
|
||||||
|
|
||||||
|
LoanState
|
||||||
|
computeRawLoanState(
|
||||||
|
Number const& periodicPayment,
|
||||||
|
TenthBips32 interestRate,
|
||||||
|
std::uint32_t paymentInterval,
|
||||||
|
std::uint32_t const paymentRemaining,
|
||||||
|
TenthBips32 const managementFeeRate)
|
||||||
|
{
|
||||||
|
return computeRawLoanState(
|
||||||
|
periodicPayment,
|
||||||
|
loanPeriodicRate(interestRate, paymentInterval),
|
||||||
|
paymentRemaining,
|
||||||
|
managementFeeRate);
|
||||||
|
}
|
||||||
|
|
||||||
/* Constructs a LoanState from rounded Loan ledger object values.
|
/* Constructs a LoanState from rounded Loan ledger object values.
|
||||||
*
|
*
|
||||||
* This function creates a LoanState structure from the three tracked values
|
* This function creates a LoanState structure from the three tracked values
|
||||||
@@ -1540,8 +1611,7 @@ computeLoanProperties(
|
|||||||
std::uint32_t paymentInterval,
|
std::uint32_t paymentInterval,
|
||||||
std::uint32_t paymentsRemaining,
|
std::uint32_t paymentsRemaining,
|
||||||
TenthBips32 managementFeeRate,
|
TenthBips32 managementFeeRate,
|
||||||
std::int32_t minimumScale,
|
std::int32_t minimumScale)
|
||||||
beast::Journal j)
|
|
||||||
{
|
{
|
||||||
auto const periodicRate = loanPeriodicRate(interestRate, paymentInterval);
|
auto const periodicRate = loanPeriodicRate(interestRate, paymentInterval);
|
||||||
XRPL_ASSERT(
|
XRPL_ASSERT(
|
||||||
@@ -1552,22 +1622,13 @@ computeLoanProperties(
|
|||||||
principalOutstanding, periodicRate, paymentsRemaining);
|
principalOutstanding, periodicRate, paymentsRemaining);
|
||||||
|
|
||||||
auto const [totalValueOutstanding, loanScale] = [&]() {
|
auto const [totalValueOutstanding, loanScale] = [&]() {
|
||||||
// only round up if there should be interest
|
NumberRoundModeGuard mg(Number::to_nearest);
|
||||||
NumberRoundModeGuard mg(
|
|
||||||
periodicRate == 0 ? Number::to_nearest : Number::upward);
|
|
||||||
// Use STAmount's internal rounding instead of roundToAsset, because
|
// Use STAmount's internal rounding instead of roundToAsset, because
|
||||||
// we're going to use this result to determine the scale for all the
|
// we're going to use this result to determine the scale for all the
|
||||||
// other rounding.
|
// other rounding.
|
||||||
|
|
||||||
// Equation (30) from XLS-66 spec, Section A-2 Equation Glossary
|
// Equation (30) from XLS-66 spec, Section A-2 Equation Glossary
|
||||||
STAmount amount{asset, periodicPayment * paymentsRemaining};
|
STAmount amount{asset, periodicPayment * paymentsRemaining};
|
||||||
JLOG(j.debug()) << "computeLoanProperties:" << " Principal requested: "
|
|
||||||
<< principalOutstanding
|
|
||||||
<< ". Periodic payment: " << periodicPayment
|
|
||||||
<< ". Payments remaining: " << paymentsRemaining
|
|
||||||
<< ". Raw total value: "
|
|
||||||
<< periodicPayment * paymentsRemaining
|
|
||||||
<< ". Candidate total value: " << amount << std::endl;
|
|
||||||
|
|
||||||
// Base the loan scale on the total value, since that's going to be
|
// Base the loan scale on the total value, since that's going to be
|
||||||
// the biggest number involved (barring unusual parameters for late,
|
// the biggest number involved (barring unusual parameters for late,
|
||||||
@@ -1582,10 +1643,7 @@ computeLoanProperties(
|
|||||||
|
|
||||||
// We may need to truncate the total value because of the minimum
|
// We may need to truncate the total value because of the minimum
|
||||||
// scale
|
// scale
|
||||||
amount = roundToAsset(asset, amount, loanScale);
|
amount = roundToAsset(asset, amount, loanScale, Number::to_nearest);
|
||||||
|
|
||||||
JLOG(j.debug()) << "computeLoanProperties: Loan scale:" << loanScale
|
|
||||||
<< ". Actual total value: " << amount << std::endl;
|
|
||||||
|
|
||||||
return std::make_pair(amount, loanScale);
|
return std::make_pair(amount, loanScale);
|
||||||
}();
|
}();
|
||||||
|
|||||||
@@ -56,7 +56,7 @@ LoanBrokerDelete::preclaim(PreclaimContext const& ctx)
|
|||||||
if (!vault)
|
if (!vault)
|
||||||
return tefINTERNAL; // LCOV_EXCL_LINE
|
return tefINTERNAL; // LCOV_EXCL_LINE
|
||||||
auto const asset = vault->at(sfAsset);
|
auto const asset = vault->at(sfAsset);
|
||||||
auto const scale = getAssetsTotalScale(vault);
|
auto const scale = getVaultScale(vault);
|
||||||
|
|
||||||
auto const rounded =
|
auto const rounded =
|
||||||
roundToAsset(asset, debtTotal, scale, Number::towards_zero);
|
roundToAsset(asset, debtTotal, scale, Number::towards_zero);
|
||||||
@@ -67,7 +67,7 @@ LoanBrokerDelete::preclaim(PreclaimContext const& ctx)
|
|||||||
JLOG(ctx.j.warn()) << "LoanBrokerDelete: Debt total is "
|
JLOG(ctx.j.warn()) << "LoanBrokerDelete: Debt total is "
|
||||||
<< debtTotal << ", which rounds to " << rounded;
|
<< debtTotal << ", which rounds to " << rounded;
|
||||||
return tecHAS_OBLIGATIONS;
|
return tecHAS_OBLIGATIONS;
|
||||||
// LCOV_EXCL_STOP
|
// LCOV_EXCL_START
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -115,7 +115,7 @@ LoanDelete::doApply()
|
|||||||
roundToAsset(
|
roundToAsset(
|
||||||
vaultSle->at(sfAsset),
|
vaultSle->at(sfAsset),
|
||||||
debtTotalProxy,
|
debtTotalProxy,
|
||||||
getAssetsTotalScale(vaultSle),
|
getVaultScale(vaultSle),
|
||||||
Number::towards_zero) == beast::zero,
|
Number::towards_zero) == beast::zero,
|
||||||
"ripple::LoanDelete::doApply",
|
"ripple::LoanDelete::doApply",
|
||||||
"last loan, remaining debt rounds to zero");
|
"last loan, remaining debt rounds to zero");
|
||||||
|
|||||||
@@ -106,7 +106,7 @@ LoanManage::preclaim(PreclaimContext const& ctx)
|
|||||||
if (loanBrokerSle->at(sfOwner) != account)
|
if (loanBrokerSle->at(sfOwner) != account)
|
||||||
{
|
{
|
||||||
JLOG(ctx.j.warn())
|
JLOG(ctx.j.warn())
|
||||||
<< "LoanBroker for Loan does not belong to the account. LoanManage "
|
<< "LoanBroker for Loan does not belong to the account. LoanModify "
|
||||||
"can only be submitted by the Loan Broker.";
|
"can only be submitted by the Loan Broker.";
|
||||||
return tecNO_PERMISSION;
|
return tecNO_PERMISSION;
|
||||||
}
|
}
|
||||||
@@ -178,7 +178,7 @@ LoanManage::defaultLoan(
|
|||||||
// The vault may be at a different scale than the loan. Reduce rounding
|
// The vault may be at a different scale than the loan. Reduce rounding
|
||||||
// errors during the accounting by rounding some of the values to that
|
// errors during the accounting by rounding some of the values to that
|
||||||
// scale.
|
// scale.
|
||||||
auto const vaultScale = getAssetsTotalScale(vaultSle);
|
auto const vaultScale = getVaultScale(vaultSle);
|
||||||
|
|
||||||
{
|
{
|
||||||
// Decrease the Total Value of the Vault:
|
// Decrease the Total Value of the Vault:
|
||||||
@@ -242,11 +242,7 @@ LoanManage::defaultLoan(
|
|||||||
return tefBAD_LEDGER;
|
return tefBAD_LEDGER;
|
||||||
// LCOV_EXCL_STOP
|
// LCOV_EXCL_STOP
|
||||||
}
|
}
|
||||||
adjustImpreciseNumber(
|
vaultLossUnrealizedProxy -= totalDefaultAmount;
|
||||||
vaultLossUnrealizedProxy,
|
|
||||||
-totalDefaultAmount,
|
|
||||||
vaultAsset,
|
|
||||||
vaultScale);
|
|
||||||
}
|
}
|
||||||
view.update(vaultSle);
|
view.update(vaultSle);
|
||||||
}
|
}
|
||||||
@@ -254,9 +250,11 @@ LoanManage::defaultLoan(
|
|||||||
// Update the LoanBroker object:
|
// Update the LoanBroker object:
|
||||||
|
|
||||||
{
|
{
|
||||||
|
auto const asset = *vaultSle->at(sfAsset);
|
||||||
|
|
||||||
// Decrease the Debt of the LoanBroker:
|
// Decrease the Debt of the LoanBroker:
|
||||||
adjustImpreciseNumber(
|
adjustImpreciseNumber(
|
||||||
brokerDebtTotalProxy, -totalDefaultAmount, vaultAsset, vaultScale);
|
brokerDebtTotalProxy, -totalDefaultAmount, asset, vaultScale);
|
||||||
// Decrease the First-Loss Capital Cover Available:
|
// Decrease the First-Loss Capital Cover Available:
|
||||||
auto coverAvailableProxy = brokerSle->at(sfCoverAvailable);
|
auto coverAvailableProxy = brokerSle->at(sfCoverAvailable);
|
||||||
if (coverAvailableProxy < defaultCovered)
|
if (coverAvailableProxy < defaultCovered)
|
||||||
@@ -299,20 +297,13 @@ LoanManage::impairLoan(
|
|||||||
ApplyView& view,
|
ApplyView& view,
|
||||||
SLE::ref loanSle,
|
SLE::ref loanSle,
|
||||||
SLE::ref vaultSle,
|
SLE::ref vaultSle,
|
||||||
Asset const& vaultAsset,
|
|
||||||
beast::Journal j)
|
beast::Journal j)
|
||||||
{
|
{
|
||||||
Number const lossUnrealized = owedToVault(loanSle);
|
Number const lossUnrealized = owedToVault(loanSle);
|
||||||
|
|
||||||
// The vault may be at a different scale than the loan. Reduce rounding
|
|
||||||
// errors during the accounting by rounding some of the values to that
|
|
||||||
// scale.
|
|
||||||
auto const vaultScale = getAssetsTotalScale(vaultSle);
|
|
||||||
|
|
||||||
// Update the Vault object(set "paper loss")
|
// Update the Vault object(set "paper loss")
|
||||||
auto vaultLossUnrealizedProxy = vaultSle->at(sfLossUnrealized);
|
auto vaultLossUnrealizedProxy = vaultSle->at(sfLossUnrealized);
|
||||||
adjustImpreciseNumber(
|
vaultLossUnrealizedProxy += lossUnrealized;
|
||||||
vaultLossUnrealizedProxy, lossUnrealized, vaultAsset, vaultScale);
|
|
||||||
if (vaultLossUnrealizedProxy >
|
if (vaultLossUnrealizedProxy >
|
||||||
vaultSle->at(sfAssetsTotal) - vaultSle->at(sfAssetsAvailable))
|
vaultSle->at(sfAssetsTotal) - vaultSle->at(sfAssetsAvailable))
|
||||||
{
|
{
|
||||||
@@ -343,14 +334,8 @@ LoanManage::unimpairLoan(
|
|||||||
ApplyView& view,
|
ApplyView& view,
|
||||||
SLE::ref loanSle,
|
SLE::ref loanSle,
|
||||||
SLE::ref vaultSle,
|
SLE::ref vaultSle,
|
||||||
Asset const& vaultAsset,
|
|
||||||
beast::Journal j)
|
beast::Journal j)
|
||||||
{
|
{
|
||||||
// The vault may be at a different scale than the loan. Reduce rounding
|
|
||||||
// errors during the accounting by rounding some of the values to that
|
|
||||||
// scale.
|
|
||||||
auto const vaultScale = getAssetsTotalScale(vaultSle);
|
|
||||||
|
|
||||||
// Update the Vault object(clear "paper loss")
|
// Update the Vault object(clear "paper loss")
|
||||||
auto vaultLossUnrealizedProxy = vaultSle->at(sfLossUnrealized);
|
auto vaultLossUnrealizedProxy = vaultSle->at(sfLossUnrealized);
|
||||||
Number const lossReversed = owedToVault(loanSle);
|
Number const lossReversed = owedToVault(loanSle);
|
||||||
@@ -362,10 +347,7 @@ LoanManage::unimpairLoan(
|
|||||||
return tefBAD_LEDGER;
|
return tefBAD_LEDGER;
|
||||||
// LCOV_EXCL_STOP
|
// LCOV_EXCL_STOP
|
||||||
}
|
}
|
||||||
// Reverse the "paper loss"
|
vaultLossUnrealizedProxy -= lossReversed;
|
||||||
adjustImpreciseNumber(
|
|
||||||
vaultLossUnrealizedProxy, -lossReversed, vaultAsset, vaultScale);
|
|
||||||
|
|
||||||
view.update(vaultSle);
|
view.update(vaultSle);
|
||||||
|
|
||||||
// Update the Loan object
|
// Update the Loan object
|
||||||
@@ -421,14 +403,12 @@ LoanManage::doApply()
|
|||||||
}
|
}
|
||||||
else if (tx.isFlag(tfLoanImpair))
|
else if (tx.isFlag(tfLoanImpair))
|
||||||
{
|
{
|
||||||
if (auto const ter =
|
if (auto const ter = impairLoan(view, loanSle, vaultSle, j_))
|
||||||
impairLoan(view, loanSle, vaultSle, vaultAsset, j_))
|
|
||||||
return ter;
|
return ter;
|
||||||
}
|
}
|
||||||
else if (tx.isFlag(tfLoanUnimpair))
|
else if (tx.isFlag(tfLoanUnimpair))
|
||||||
{
|
{
|
||||||
if (auto const ter =
|
if (auto const ter = unimpairLoan(view, loanSle, vaultSle, j_))
|
||||||
unimpairLoan(view, loanSle, vaultSle, vaultAsset, j_))
|
|
||||||
return ter;
|
return ter;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -44,7 +44,6 @@ public:
|
|||||||
ApplyView& view,
|
ApplyView& view,
|
||||||
SLE::ref loanSle,
|
SLE::ref loanSle,
|
||||||
SLE::ref vaultSle,
|
SLE::ref vaultSle,
|
||||||
Asset const& vaultAsset,
|
|
||||||
beast::Journal j);
|
beast::Journal j);
|
||||||
|
|
||||||
/** Helper function that might be needed by other transactors
|
/** Helper function that might be needed by other transactors
|
||||||
@@ -54,7 +53,6 @@ public:
|
|||||||
ApplyView& view,
|
ApplyView& view,
|
||||||
SLE::ref loanSle,
|
SLE::ref loanSle,
|
||||||
SLE::ref vaultSle,
|
SLE::ref vaultSle,
|
||||||
Asset const& vaultAsset,
|
|
||||||
beast::Journal j);
|
beast::Journal j);
|
||||||
|
|
||||||
TER
|
TER
|
||||||
|
|||||||
@@ -305,7 +305,7 @@ LoanPay::doApply()
|
|||||||
// change will be discarded.
|
// change will be discarded.
|
||||||
if (loanSle->isFlag(lsfLoanImpaired))
|
if (loanSle->isFlag(lsfLoanImpaired))
|
||||||
{
|
{
|
||||||
LoanManage::unimpairLoan(view, loanSle, vaultSle, asset, j_);
|
LoanManage::unimpairLoan(view, loanSle, vaultSle, j_);
|
||||||
}
|
}
|
||||||
|
|
||||||
LoanPaymentType const paymentType = [&tx]() {
|
LoanPaymentType const paymentType = [&tx]() {
|
||||||
@@ -379,7 +379,7 @@ LoanPay::doApply()
|
|||||||
|
|
||||||
// The vault may be at a different scale than the loan. Reduce rounding
|
// The vault may be at a different scale than the loan. Reduce rounding
|
||||||
// errors during the payment by rounding some of the values to that scale.
|
// errors during the payment by rounding some of the values to that scale.
|
||||||
auto const vaultScale = getAssetsTotalScale(vaultSle);
|
auto const vaultScale = assetsTotalProxy.value().exponent();
|
||||||
|
|
||||||
auto const totalPaidToVaultRaw =
|
auto const totalPaidToVaultRaw =
|
||||||
paymentParts->principalPaid + paymentParts->interestPaid;
|
paymentParts->principalPaid + paymentParts->interestPaid;
|
||||||
|
|||||||
@@ -383,7 +383,7 @@ LoanSet::doApply()
|
|||||||
|
|
||||||
auto vaultAvailableProxy = vaultSle->at(sfAssetsAvailable);
|
auto vaultAvailableProxy = vaultSle->at(sfAssetsAvailable);
|
||||||
auto vaultTotalProxy = vaultSle->at(sfAssetsTotal);
|
auto vaultTotalProxy = vaultSle->at(sfAssetsTotal);
|
||||||
auto const vaultScale = getAssetsTotalScale(vaultSle);
|
auto const vaultScale = getVaultScale(vaultSle);
|
||||||
if (vaultAvailableProxy < principalRequested)
|
if (vaultAvailableProxy < principalRequested)
|
||||||
{
|
{
|
||||||
JLOG(j_.warn())
|
JLOG(j_.warn())
|
||||||
@@ -404,8 +404,7 @@ LoanSet::doApply()
|
|||||||
paymentInterval,
|
paymentInterval,
|
||||||
paymentTotal,
|
paymentTotal,
|
||||||
TenthBips16{brokerSle->at(sfManagementFeeRate)},
|
TenthBips16{brokerSle->at(sfManagementFeeRate)},
|
||||||
vaultScale,
|
vaultScale);
|
||||||
j_);
|
|
||||||
|
|
||||||
// Check that relevant values won't lose precision. This is mostly only
|
// Check that relevant values won't lose precision. This is mostly only
|
||||||
// relevant for IOU assets.
|
// relevant for IOU assets.
|
||||||
@@ -441,10 +440,7 @@ LoanSet::doApply()
|
|||||||
{
|
{
|
||||||
// LCOV_EXCL_START
|
// LCOV_EXCL_START
|
||||||
JLOG(j_.warn())
|
JLOG(j_.warn())
|
||||||
<< "Computed loan properties are invalid. Does not compute."
|
<< "Computed loan properties are invalid. Does not compute.";
|
||||||
<< " Management fee: " << properties.managementFeeOwedToBroker
|
|
||||||
<< ". Total Value: " << properties.totalValueOutstanding
|
|
||||||
<< ". PeriodicPayment: " << properties.periodicPayment;
|
|
||||||
return tecINTERNAL;
|
return tecINTERNAL;
|
||||||
// LCOV_EXCL_STOP
|
// LCOV_EXCL_STOP
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user