Skip to content

Commit

Permalink
Policy interface update (#287)
Browse files Browse the repository at this point in the history
* updated hh version

* added exchange rate and cpi getters on policy

* updated policy interface
  • Loading branch information
aalavandhan authored Oct 16, 2024
1 parent 3882d6f commit d2b6727
Show file tree
Hide file tree
Showing 5 changed files with 106 additions and 87 deletions.
24 changes: 16 additions & 8 deletions contracts/UFragmentsPolicy.sol
Original file line number Diff line number Diff line change
Expand Up @@ -124,22 +124,17 @@ contract UFragmentsPolicy is Ownable {

epoch = epoch.add(1);

uint256 targetRate;
bool targetRateValid;
(targetRate, targetRateValid) = cpiOracle.getData();
(uint256 targetRate, bool targetRateValid) = getTargetRate();
require(targetRateValid);

uint256 exchangeRate;
bool rateValid;
(exchangeRate, rateValid) = marketOracle.getData();
(uint256 exchangeRate, bool rateValid) = getExchangeRate();
require(rateValid);

if (exchangeRate > MAX_RATE) {
exchangeRate = MAX_RATE;
}

int256 supplyDelta = computeSupplyDelta(exchangeRate, targetRate);

if (supplyDelta > 0 && uFrags.totalSupply().add(uint256(supplyDelta)) > MAX_SUPPLY) {
supplyDelta = (MAX_SUPPLY.sub(uFrags.totalSupply())).toInt256Safe();
}
Expand Down Expand Up @@ -267,6 +262,20 @@ contract UFragmentsPolicy is Ownable {
uFrags = uFrags_;
}

/**
* @return The current price target and validity from the cpi oracle.
*/
function getTargetRate() public returns (uint256, bool) {
return cpiOracle.getData();
}

/**
* @return The current exchange rate and validity from the market oracle.
*/
function getExchangeRate() public returns (uint256, bool) {
return marketOracle.getData();
}

/**
* @return If the latest block timestamp is within the rebase time window it, returns true.
* Otherwise, returns false.
Expand Down Expand Up @@ -333,7 +342,6 @@ contract UFragmentsPolicy is Ownable {
rebaseFunctionUpperPercentage,
rebaseFunctionGrowth
);

return uFrags.totalSupply().toInt256Safe().mul(rebasePercentage).div(ONE);
}

Expand Down
2 changes: 2 additions & 0 deletions contracts/interfaces/IAmpleforth.sol
Original file line number Diff line number Diff line change
Expand Up @@ -7,4 +7,6 @@ interface IAmpleforth {
function inRebaseWindow() external view returns (bool);

function globalAmpleforthEpochAndAMPLSupply() external view returns (uint256, uint256);

function getTargetRate() external returns (uint256, bool);
}
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@
"eslint-plugin-promise": "^6.0.0",
"ethereum-waffle": "^3.4.4",
"ethers": "^5.6.9",
"hardhat": "^2.22.1",
"hardhat": "^2.22.13",
"hardhat-gas-reporter": "^1.0.8",
"prettier": "^2.7.1",
"prettier-plugin-solidity": "^1.0.0-dev.23",
Expand Down
8 changes: 4 additions & 4 deletions test/unit/UFragmentsPolicy.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,8 @@ const INITIAL_TARGET_RATE_25P_LESS = imul(INITIAL_TARGET_RATE, '0.75', 1)
const INITIAL_RATE = ethers.utils.parseUnits('1.05', 18)
const INITIAL_RATE_30P_MORE = imul(INITIAL_RATE, '1.3', 1)
const INITIAL_RATE_30P_LESS = imul(INITIAL_RATE, '0.7', 1)
const INITIAL_RATE_5P_MORE = imul(INITIAL_RATE, '1.05', 1)
const INITIAL_RATE_5P_LESS = imul(INITIAL_RATE, '0.95', 1)
const INITIAL_RATE_2P_MORE = imul(INITIAL_RATE, '1.02', 1)
const INITIAL_RATE_2P_LESS = imul(INITIAL_RATE, '0.98', 1)
const INITIAL_RATE_60P_MORE = imul(INITIAL_RATE, '1.6', 1)
const INITIAL_RATE_50P_LESS = imul(INITIAL_RATE, '0.5', 1)
const INITIAL_RATE_2X = INITIAL_RATE.mul(2)
Expand Down Expand Up @@ -702,7 +702,7 @@ describe('UFragmentsPolicy:Rebase', async function () {
await increaseTime(60)

await mockExternalData(
INITIAL_RATE_5P_MORE.sub(2),
INITIAL_RATE_2P_MORE.sub(2),
INITIAL_TARGET_RATE,
1000,
)
Expand All @@ -716,7 +716,7 @@ describe('UFragmentsPolicy:Rebase', async function () {
await increaseTime(60)

await mockExternalData(
INITIAL_RATE_5P_LESS.add(2),
INITIAL_RATE_2P_LESS.add(2),
INITIAL_TARGET_RATE,
1000,
)
Expand Down
157 changes: 83 additions & 74 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -576,65 +576,53 @@
"@nodelib/fs.scandir" "2.1.5"
fastq "^1.6.0"

"@nomicfoundation/[email protected]":
version "0.3.4"
resolved "https://registry.yarnpkg.com/@nomicfoundation/edr-darwin-arm64/-/edr-darwin-arm64-0.3.4.tgz#e5aac2b7726f44cffe120bdd7e25e1f120471591"
integrity sha512-tjavrUFLWnkn0PI+jk0D83hP2jjbmeXT1QLd5NtIleyGrJ00ZWVl+sfuA2Lle3kzfOceoI2VTR0n1pZB4KJGbQ==

"@nomicfoundation/[email protected]":
version "0.3.4"
resolved "https://registry.yarnpkg.com/@nomicfoundation/edr-darwin-x64/-/edr-darwin-x64-0.3.4.tgz#cbcc0a2dcda0a7c0a900a74efc6918cff134dc23"
integrity sha512-dXO0vlIoBosp8gf5/ah3dESMymjwit0Daef1E4Ew3gZ8q3LAdku0RC+YEQJi9f0I3QNfdgIrBTzibRZUoP+kVA==

"@nomicfoundation/[email protected]":
version "0.3.4"
resolved "https://registry.yarnpkg.com/@nomicfoundation/edr-linux-arm64-gnu/-/edr-linux-arm64-gnu-0.3.4.tgz#12073f97d310176bb24ad7d48c25128ea8eff093"
integrity sha512-dv38qmFUaqkkeeA9S0JjerqruytTfHav7gbPLpZUAEXPlJGo49R0+HQxd45I0msbm6NAXbkmKEchTLApp1ohaA==

"@nomicfoundation/[email protected]":
version "0.3.4"
resolved "https://registry.yarnpkg.com/@nomicfoundation/edr-linux-arm64-musl/-/edr-linux-arm64-musl-0.3.4.tgz#c9bc685d4d14bf21d9c3e326edd44e009e24492d"
integrity sha512-CfEsb6gdCMVIlRSpWYTxoongEKHB60V6alE/y8mkfjIo7tA95wyiuvCtyo3fpiia3wQV7XoMYgIJHObHiKLKtA==

"@nomicfoundation/[email protected]":
version "0.3.4"
resolved "https://registry.yarnpkg.com/@nomicfoundation/edr-linux-x64-gnu/-/edr-linux-x64-gnu-0.3.4.tgz#37486cbe317b8caf7961e500fc0150c45c895a56"
integrity sha512-V0CpJA2lYWulgTR+zP11ftBAEwkpMAAki/AuMu3vd7HoPfjwIDzWDQR5KFU17qFmqAVz0ICRxsxDlvvBZ/PUxA==

"@nomicfoundation/[email protected]":
version "0.3.4"
resolved "https://registry.yarnpkg.com/@nomicfoundation/edr-linux-x64-musl/-/edr-linux-x64-musl-0.3.4.tgz#399278807100a1833f6c8a39c17d5beaaf7a9223"
integrity sha512-0sgTrwZajarukerU/QSb+oRdlQLnJdd7of8OlXq2wtpeTNTqemgCOwY2l2qImbWboMpVrYgcmGbINXNVPCmuJw==

"@nomicfoundation/[email protected]":
version "0.3.4"
resolved "https://registry.yarnpkg.com/@nomicfoundation/edr-win32-arm64-msvc/-/edr-win32-arm64-msvc-0.3.4.tgz#879028e2708538fd54efc349c1a4de107a15abb4"
integrity sha512-bOl3vhMtV0W9ozUMF5AZRBWw1183hhhx+e1YJdDLMaqNkBUFYi2CZbMYefDylq2OKQtOQ0gPLhZvn+z2D21Ztw==

"@nomicfoundation/[email protected]":
version "0.3.4"
resolved "https://registry.yarnpkg.com/@nomicfoundation/edr-win32-ia32-msvc/-/edr-win32-ia32-msvc-0.3.4.tgz#97d54b8cfbbafa1cd2001bb115e583f1169bf9ae"
integrity sha512-yKQCpAX0uB2dalsSwOkau3yfNXkwBJa/Ks2OPl9AjHqJ+E8AqvBEB9jRpfQrdPzElMsgZuN4mqE+wh+JxY+0Aw==

"@nomicfoundation/[email protected]":
version "0.3.4"
resolved "https://registry.yarnpkg.com/@nomicfoundation/edr-win32-x64-msvc/-/edr-win32-x64-msvc-0.3.4.tgz#abfc447eb6bd1a9be868bec5c9d14546398ab609"
integrity sha512-fResvsL/fSucep1K5W6iOs8lqqKKovHLsAmigMzAYVovqkyZKgCGVS/D8IVxA0nxuGCOlNxFnVmwWtph3pbKWA==

"@nomicfoundation/edr@^0.3.1":
version "0.3.4"
resolved "https://registry.yarnpkg.com/@nomicfoundation/edr/-/edr-0.3.4.tgz#e8eaf41963460139c47b0785f1a6a2a1c1b24ae0"
integrity sha512-e4jzVeJ+VTKBFzNgKDbSVnGVbHYNZHIfMdgifQBugXPiIa6QEUzZqleh2+y4lhkXcCthnFyrTYe3jiEpUzr3cA==
optionalDependencies:
"@nomicfoundation/edr-darwin-arm64" "0.3.4"
"@nomicfoundation/edr-darwin-x64" "0.3.4"
"@nomicfoundation/edr-linux-arm64-gnu" "0.3.4"
"@nomicfoundation/edr-linux-arm64-musl" "0.3.4"
"@nomicfoundation/edr-linux-x64-gnu" "0.3.4"
"@nomicfoundation/edr-linux-x64-musl" "0.3.4"
"@nomicfoundation/edr-win32-arm64-msvc" "0.3.4"
"@nomicfoundation/edr-win32-ia32-msvc" "0.3.4"
"@nomicfoundation/edr-win32-x64-msvc" "0.3.4"
"@nomicfoundation/[email protected]":
version "0.6.3"
resolved "https://registry.yarnpkg.com/@nomicfoundation/edr-darwin-arm64/-/edr-darwin-arm64-0.6.3.tgz#7f94f80f25bbf8f15421aca0626b1e243c5b6fba"
integrity sha512-hqtI7tYDqKG5PDmZ//Z65EH5cgH8VL/SAAu50rpHP7WAVfJWkOCcYbecywwF6nhHdonJbRTDGAeG1/+VOy6zew==

"@nomicfoundation/[email protected]":
version "0.6.3"
resolved "https://registry.yarnpkg.com/@nomicfoundation/edr-darwin-x64/-/edr-darwin-x64-0.6.3.tgz#57cbbe09c70480e7eb79273ba5a497327d72347b"
integrity sha512-4fGi79/lyOlRUORhCYsYb3sWqRHuHT7qqzyZfZuNOn8llaxmT1k36xNmvpyg37R8SzjnhT/DzoukSJrs23Ip9Q==

"@nomicfoundation/[email protected]":
version "0.6.3"
resolved "https://registry.yarnpkg.com/@nomicfoundation/edr-linux-arm64-gnu/-/edr-linux-arm64-gnu-0.6.3.tgz#122f5ec8b00297e9ed0111405c8779a3c3ba26f3"
integrity sha512-yFFTvGFMhfAvQ1Z2itUh1jpoUA+mVROyVELcaxjIq8fyg602lQmbS+NXkhQ+oaeDgJ+06mSENrHBg4fcfRf9cw==

"@nomicfoundation/[email protected]":
version "0.6.3"
resolved "https://registry.yarnpkg.com/@nomicfoundation/edr-linux-arm64-musl/-/edr-linux-arm64-musl-0.6.3.tgz#2b0371371540373b10521ead4ffa70a2d9e6ac8e"
integrity sha512-pOKmd0Fa3a6BHg5qbjbl/jMRELVi9oazbfiuU7Bvgn/dpTK+ID3jwT0SXiuC2zxjmPByWgXL6G9XRf5BPAM2rQ==

"@nomicfoundation/[email protected]":
version "0.6.3"
resolved "https://registry.yarnpkg.com/@nomicfoundation/edr-linux-x64-gnu/-/edr-linux-x64-gnu-0.6.3.tgz#63849575eddbcd7a5da581d401fba6f5f9347644"
integrity sha512-3AUferhkLIXtLV63w5GjpHttzdxZ36i656XMy+pkBZbbiqnzIVeKWg6DJv1A94fQY16gB4gqj9CLq4CWvbNN6w==

"@nomicfoundation/[email protected]":
version "0.6.3"
resolved "https://registry.yarnpkg.com/@nomicfoundation/edr-linux-x64-musl/-/edr-linux-x64-musl-0.6.3.tgz#3b5e6462f47b40cde81bafc6da003c58b2eb9839"
integrity sha512-fr6bD872WIBXe9YnTDi0CzYepMcYRgSnkVqn0yK4wRnIvKrloWhxXNVY45GVIl51aNZguBnvoA4WEt6HIazs3A==

"@nomicfoundation/[email protected]":
version "0.6.3"
resolved "https://registry.yarnpkg.com/@nomicfoundation/edr-win32-x64-msvc/-/edr-win32-x64-msvc-0.6.3.tgz#45be7ba94b950e78e862cb3af0c320e070e0e452"
integrity sha512-sn34MvN1ajw2Oq1+Drpxej78Z0HfIzI4p4WlolupAV9dOZKzp2JAIQeLVfZpjIFbF3zuyxLPP4dUBrQoFPEqhA==

"@nomicfoundation/edr@^0.6.3":
version "0.6.3"
resolved "https://registry.yarnpkg.com/@nomicfoundation/edr/-/edr-0.6.3.tgz#47f1b217ce5eb09aef419d76a8488bb77cd88b94"
integrity sha512-hThe5ORR75WFYTXKL0K2AyLDxkTMrG+VQ1yL9BhQYsuh3OIH+3yNDxMz2LjfvrpOrMmJ4kk5NKdFewpqDojjXQ==
dependencies:
"@nomicfoundation/edr-darwin-arm64" "0.6.3"
"@nomicfoundation/edr-darwin-x64" "0.6.3"
"@nomicfoundation/edr-linux-arm64-gnu" "0.6.3"
"@nomicfoundation/edr-linux-arm64-musl" "0.6.3"
"@nomicfoundation/edr-linux-x64-gnu" "0.6.3"
"@nomicfoundation/edr-linux-x64-musl" "0.6.3"
"@nomicfoundation/edr-win32-x64-msvc" "0.6.3"

"@nomicfoundation/[email protected]":
version "4.0.4"
Expand Down Expand Up @@ -2804,7 +2792,7 @@ [email protected]:
optionalDependencies:
fsevents "~2.1.1"

[email protected], chokidar@^3.4.0:
[email protected]:
version "3.5.3"
resolved "https://registry.yarnpkg.com/chokidar/-/chokidar-3.5.3.tgz#1cf37c8707b932bd1af1ae22c0432e2acd1903bd"
integrity sha512-Dr3sfKRP6oTcjf2JmUmFJfeVMvXBdegxB0iVQ5eb2V10uFJUCAS8OByZdVAyVb8xXNz3GjjTgj9kLWsZTqE6kw==
Expand All @@ -2819,6 +2807,13 @@ [email protected], chokidar@^3.4.0:
optionalDependencies:
fsevents "~2.3.2"

chokidar@^4.0.0:
version "4.0.1"
resolved "https://registry.yarnpkg.com/chokidar/-/chokidar-4.0.1.tgz#4a6dff66798fb0f72a94f616abbd7e1a19f31d41"
integrity sha512-n8enUVCED/KVRQlab1hr3MVpcVMvxtZjmEa956u+4YijlmQED223XMSYj2tLuKvr4jcCTzNNMpQDUer72MMmzA==
dependencies:
readdirp "^4.0.1"

chownr@^1.1.4:
version "1.1.4"
resolved "https://registry.yarnpkg.com/chownr/-/chownr-1.1.4.tgz#6fc9d7b42d32a583596337666e7d08084da2cc6b"
Expand Down Expand Up @@ -3027,6 +3022,11 @@ [email protected]:
resolved "https://registry.yarnpkg.com/commander/-/commander-3.0.2.tgz#6837c3fb677ad9933d1cfba42dd14d5117d6b39e"
integrity sha512-Gar0ASD4BDyKC4hl4DwHqDrmvjoxWKZigVnAbn5H1owvm4CxCPdb0HQDehwNYMJpla5+M2tPmPARzhtYuwpHow==

commander@^8.1.0:
version "8.3.0"
resolved "https://registry.yarnpkg.com/commander/-/commander-8.3.0.tgz#4837ea1b2da67b9c616a67afbb0fafee567bca66"
integrity sha512-OkTL9umf+He2DZkUq8f8J9of7yL6RJKI24dVITBmNfZBmri9zYZQrKkuXiKhyfPSu8tUhnVBB1iKXevvnlR4Ww==

compare-versions@^5.0.0:
version "5.0.1"
resolved "https://registry.yarnpkg.com/compare-versions/-/compare-versions-5.0.1.tgz#14c6008436d994c3787aba38d4087fabe858555e"
Expand Down Expand Up @@ -5421,14 +5421,14 @@ hardhat-gas-reporter@^1.0.8:
eth-gas-reporter "^0.2.25"
sha1 "^1.1.1"

hardhat@^2.22.1:
version "2.22.2"
resolved "https://registry.yarnpkg.com/hardhat/-/hardhat-2.22.2.tgz#0cadd7ec93bf39bab09f81603e75bc5e92acea3d"
integrity sha512-0xZ7MdCZ5sJem4MrvpQWLR3R3zGDoHw5lsR+pBFimqwagimIOn3bWuZv69KA+veXClwI1s/zpqgwPwiFrd4Dxw==
hardhat@^2.22.13:
version "2.22.13"
resolved "https://registry.yarnpkg.com/hardhat/-/hardhat-2.22.13.tgz#1d2c7c4b640d060ae0f5b04757322118a003955a"
integrity sha512-psVJX4FSXDpSXwsU8OcKTJN04pQEj9cFBMX5OPko+OFwbIoiOpvRmafa954/UaA1934npTj8sV3gaTSdx9bPbA==
dependencies:
"@ethersproject/abi" "^5.1.2"
"@metamask/eth-sig-util" "^4.0.0"
"@nomicfoundation/edr" "^0.3.1"
"@nomicfoundation/edr" "^0.6.3"
"@nomicfoundation/ethereumjs-common" "4.0.4"
"@nomicfoundation/ethereumjs-tx" "5.0.4"
"@nomicfoundation/ethereumjs-util" "9.0.4"
Expand All @@ -5441,7 +5441,7 @@ hardhat@^2.22.1:
ansi-escapes "^4.3.0"
boxen "^5.1.2"
chalk "^2.4.2"
chokidar "^3.4.0"
chokidar "^4.0.0"
ci-info "^2.0.0"
debug "^4.1.1"
enquirer "^2.3.0"
Expand All @@ -5454,6 +5454,7 @@ hardhat@^2.22.1:
glob "7.2.0"
immutable "^4.0.0-rc.12"
io-ts "1.10.4"
json-stream-stringify "^3.1.4"
keccak "^3.0.2"
lodash "^4.17.11"
mnemonist "^0.38.0"
Expand All @@ -5462,7 +5463,7 @@ hardhat@^2.22.1:
raw-body "^2.4.1"
resolve "1.17.0"
semver "^6.3.0"
solc "0.7.3"
solc "0.8.26"
source-map-support "^0.5.13"
stacktrace-parser "^0.1.10"
tsort "0.0.1"
Expand Down Expand Up @@ -6321,6 +6322,11 @@ json-stable-stringify@^1.0.1:
dependencies:
jsonify "~0.0.0"

json-stream-stringify@^3.1.4:
version "3.1.6"
resolved "https://registry.yarnpkg.com/json-stream-stringify/-/json-stream-stringify-3.1.6.tgz#ebe32193876fb99d4ec9f612389a8d8e2b5d54d4"
integrity sha512-x7fpwxOkbhFCaJDJ8vb1fBY3DdSa4AlITaz+HHILQJzdPMnHEFjxPwVUi1ALIbcIxDE0PNe/0i7frnY8QnBQog==

json-stringify-safe@~5.0.1:
version "5.0.1"
resolved "https://registry.yarnpkg.com/json-stringify-safe/-/json-stringify-safe-5.0.1.tgz#1296a2d58fd45f19a0f6ce01d65701e2c735b6eb"
Expand Down Expand Up @@ -8139,6 +8145,11 @@ readable-stream@~1.0.15:
isarray "0.0.1"
string_decoder "~0.10.x"

readdirp@^4.0.1:
version "4.0.2"
resolved "https://registry.yarnpkg.com/readdirp/-/readdirp-4.0.2.tgz#388fccb8b75665da3abffe2d8f8ed59fe74c230a"
integrity sha512-yDMz9g+VaZkqBYS/ozoBJwaBhTbZo3UNYQHNRw1D3UFQB8oHB4uS/tAODO+ZLjGWmUbKnIlOWO+aaIiAxrUWHA==

readdirp@~3.2.0:
version "3.2.0"
resolved "https://registry.yarnpkg.com/readdirp/-/readdirp-3.2.0.tgz#c30c33352b12c96dfb4b895421a49fd5a9593839"
Expand Down Expand Up @@ -8842,18 +8853,16 @@ snapdragon@^0.8.1:
source-map-resolve "^0.5.0"
use "^3.1.0"

solc@0.7.3:
version "0.7.3"
resolved "https://registry.yarnpkg.com/solc/-/solc-0.7.3.tgz#04646961bd867a744f63d2b4e3c0701ffdc7d78a"
integrity sha512-GAsWNAjGzIDg7VxzP6mPjdurby3IkGCjQcM8GFYZT6RyaoUZKmMU6Y7YwG+tFGhv7dwZ8rmR4iwFDrrD99JwqA==
solc@0.8.26:
version "0.8.26"
resolved "https://registry.yarnpkg.com/solc/-/solc-0.8.26.tgz#afc78078953f6ab3e727c338a2fefcd80dd5b01a"
integrity sha512-yiPQNVf5rBFHwN6SIf3TUUvVAFKcQqmSUFeq+fb6pNRCo0ZCgpYOZDi3BVoezCPIAcKrVYd/qXlBLUP9wVrZ9g==
dependencies:
command-exists "^1.2.8"
commander "3.0.2"
commander "^8.1.0"
follow-redirects "^1.12.1"
fs-extra "^0.30.0"
js-sha3 "0.8.0"
memorystream "^0.3.1"
require-from-string "^2.0.0"
semver "^5.5.0"
tmp "0.0.33"

Expand Down

0 comments on commit d2b6727

Please sign in to comment.