Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

refactor(irm): compile without IR #57

Merged
merged 2 commits into from
Oct 31, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 11 additions & 1 deletion foundry.toml
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,22 @@ src = "src"
out = "out"
test = "test"
libs = ["lib"]
via-ir = true

[profile.default.fuzz]
runs = 4096

[profile.default.fmt]
wrap_comments = true


[profile.build]
via-ir = true
test = "/dev/null"
script = "/dev/null"


[profile.test]
via-ir = false


# See more config options https://github.com/foundry-rs/foundry/blob/master/crates/config/README.md#all-options
12 changes: 7 additions & 5 deletions src/SpeedJumpIrm.sol
Original file line number Diff line number Diff line change
Expand Up @@ -114,13 +114,15 @@ contract AdaptativeCurveIRM is IIrm {

// Safe "unchecked" cast because ADJUSTMENT_SPEED <= type(int256).max.
int256 speed = int256(ADJUSTMENT_SPEED).wMulDown(err);
uint256 elapsed = (baseRate[id] > 0) ? block.timestamp - market.lastUpdate : 0;

uint256 prevBaseRate = baseRate[id];
uint256 elapsed = (prevBaseRate > 0) ? block.timestamp - market.lastUpdate : 0;
// Safe "unchecked" cast because elapsed <= block.timestamp.
int256 linearVariation = speed * int256(elapsed);
uint256 variationMultiplier = MathLib.wExp(linearVariation);
// newBaseRate is bounded between MIN_BASE_RATE, MAX_BASE_RATE.
uint256 newBaseRate = (baseRate[id] > 0)
? baseRate[id].wMulDown(variationMultiplier).bound(MIN_BASE_RATE, MAX_BASE_RATE)
uint256 newBaseRate = (prevBaseRate > 0)
? prevBaseRate.wMulDown(variationMultiplier).bound(MIN_BASE_RATE, MAX_BASE_RATE)
: INITIAL_BASE_RATE;
uint256 newBorrowRate = _curve(newBaseRate, err);

Expand All @@ -131,13 +133,13 @@ contract AdaptativeCurveIRM is IIrm {
// And avgBorrowRate ~ borrowRateStartOfThePeriod ~ newBorrowRate for linearVariation around zero.
// Also, when it is the first interaction (baseRate == 0).
uint256 avgBorrowRate;
if (linearVariation == 0 || baseRate[id] == 0) {
if (linearVariation == 0 || prevBaseRate == 0) {
avgBorrowRate = newBorrowRate;
} else {
// Safe "unchecked" cast to uint256 because linearVariation < 0 <=> newBorrowRate <=
// borrowRateStartOfThePeriod.
avgBorrowRate =
uint256((int256(newBorrowRate) - int256(_curve(baseRate[id], err))).wDivDown(linearVariation));
uint256((int256(newBorrowRate) - int256(_curve(prevBaseRate, err))).wDivDown(linearVariation));
}

return (avgBorrowRate, newBaseRate);
Expand Down