-
Notifications
You must be signed in to change notification settings - Fork 11
DR based flash swap fees #241
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
Merged
Merged
Changes from 2 commits
Commits
Show all changes
36 commits
Select commit
Hold shift + click to select a range
b966a8e
DR based flash swap fees
aalavandhan 9ddef4d
comment updates
aalavandhan 54877f0
updated unit tests to use ethers v6, using custom mocking library
aalavandhan a7a5f41
updated tasks and deps
aalavandhan e8a35ed
updated perp mint fees to be paid to the vault
aalavandhan eff36d7
removed perp share of fees from flash swaps, all fees go to the vault
aalavandhan 433263f
added configurable dr soft bounds (curve cutoff point) to flash swap …
aalavandhan 28db923
updated unit tests
aalavandhan 293c25d
removed rollover fees from perp
aalavandhan 3d11ca3
Daily Rebalance
aalavandhan 061aaf9
updated unit tests
aalavandhan e11e203
constant rate enrichment/debasement
aalavandhan 0459829
mint2, redeem2
aalavandhan 2c6b1f2
added linked library to limit contract size
aalavandhan 5a28255
unit tests
aalavandhan 272be4a
melding perps immediately after rebalance
aalavandhan 8b7a29d
Apply suggestions from code review
aalavandhan f1ed255
Update spot-contracts/contracts/FeePolicy.sol
aalavandhan 0fc7733
code review fixes
aalavandhan 70ea8d1
code review fixes v2
aalavandhan 654d290
code review fixes v3
aalavandhan 68ad680
code review v4
aalavandhan 8e9f016
during rebalance, vault pays perps by transferring tranches into perp…
aalavandhan e461e1e
rebalance eql
aalavandhan 76f3831
configurable rebalance freq
aalavandhan f9fdff0
code review v5
aalavandhan 3ef2756
Apply suggestions from code review
aalavandhan b23ad28
code review fixes
aalavandhan 2403fb5
Code review fixes
aalavandhan 2c97ec7
Merge branch 'rollover-fee-removal' into rebal-param-update
aalavandhan 4a5ce29
Merge pull request #249 from ampleforth/rebal-param-update
aalavandhan 5bdecd3
Merge branch 'rollover-fee-removal' into pair-ops
aalavandhan 6779862
Merge pull request #247 from ampleforth/pair-ops
aalavandhan abc1164
Merge pull request #246 from ampleforth/rollover-fee-removal
aalavandhan eed0d39
Merge pull request #243 from ampleforth/fee-restructure
aalavandhan e6c9aea
Merge pull request #242 from ampleforth/ethers-update
aalavandhan File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,20 @@ | ||
| // SPDX-License-Identifier: GPL-3.0-or-later | ||
| pragma solidity ^0.8.20; | ||
|
|
||
| import { LineHelpers } from "../_utils/LineHelpers.sol"; | ||
| import { Line, Range } from "../_interfaces/CommonTypes.sol"; | ||
|
|
||
| contract LineHelpersTester { | ||
| function computePiecewiseAvgY( | ||
| Line memory fn1, | ||
| Line memory fn2, | ||
| Range memory xRange, | ||
| uint256 xBreakPt | ||
| ) public pure returns (int256) { | ||
| return LineHelpers.computePiecewiseAvgY(fn1, fn2, xRange, xBreakPt); | ||
| } | ||
|
|
||
| function avgY(Line memory fn, uint256 xL, uint256 xU) public pure returns (int256) { | ||
| return LineHelpers.avgY(fn, xL, xU); | ||
| } | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,85 @@ | ||
| // SPDX-License-Identifier: GPL-3.0-or-later | ||
| pragma solidity ^0.8.20; | ||
|
|
||
| import { MathUpgradeable } from "@openzeppelin/contracts-upgradeable/utils/math/MathUpgradeable.sol"; | ||
| import { SafeCastUpgradeable } from "@openzeppelin/contracts-upgradeable/utils/math/SafeCastUpgradeable.sol"; | ||
| import { Line, Range } from "../_interfaces/CommonTypes.sol"; | ||
| import { InvalidRange } from "../_interfaces/ProtocolErrors.sol"; | ||
|
|
||
| /** | ||
| * @title LineHelpers | ||
| * @notice Provides helper functions for working with linear functions and computing piecewise averages. | ||
| */ | ||
| library LineHelpers { | ||
| using MathUpgradeable for uint256; | ||
| using SafeCastUpgradeable for uint256; | ||
| using SafeCastUpgradeable for int256; | ||
|
|
||
| /** | ||
| * @notice Computes the weighted average y-value over a specified x-range for a piecewise linear function. | ||
| * @dev This function considers two linear segments—`fn1` for x-values below the breakpoint (`xBreakPt`) | ||
| * and `fn2` for x-values above or equal to the breakpoint. If the entire x-range lies on one side of | ||
| * `xBreakPt`, it returns the average y-value computed over that range using the appropriate function. | ||
| * If the x-range spans `xBreakPt`, it computes a weighted average of the two sub-ranges, weighted by their lengths. | ||
| * @param fn1 The linear function used for x-values below `xBreakPt`. | ||
| * @param fn2 The linear function used for x-values above or equal to `xBreakPt`. | ||
| * @param xRange The x-range over which to compute the average. | ||
| * @param xBreakPt The x-coordinate where the piecewise function transitions from `fn1` to `fn2`. | ||
| * @return yVal The computed weighted average y-value over the x-range. | ||
| */ | ||
| function computePiecewiseAvgY( | ||
| Line memory fn1, | ||
| Line memory fn2, | ||
| Range memory xRange, | ||
| uint256 xBreakPt | ||
| ) internal pure returns (int256 yVal) { | ||
| if (xRange.lower > xRange.upper) { | ||
| revert InvalidRange(); | ||
| } | ||
|
|
||
| if (xRange.upper <= xBreakPt) { | ||
| // Entire range is below the breakpoint. | ||
| yVal = avgY(fn1, xRange.lower, xRange.upper); | ||
| } else if (xRange.lower >= xBreakPt) { | ||
| // Entire range is above or equal to the breakpoint. | ||
| yVal = avgY(fn2, xRange.lower, xRange.upper); | ||
| } else { | ||
| // Range spans the breakpoint, so compute weighted average of both segments. | ||
| uint256 len1 = xBreakPt - xRange.lower; | ||
| uint256 len2 = xRange.upper - xBreakPt; | ||
| int256 avg1 = avgY(fn1, xRange.lower, xBreakPt); | ||
| int256 avg2 = avgY(fn2, xBreakPt, xRange.upper); | ||
| yVal = (avg1 * int256(len1) + avg2 * int256(len2)) / int256(xRange.upper - xRange.lower); | ||
| } | ||
| } | ||
|
|
||
| /** | ||
| * @notice Computes the average y-value of a linear function over the interval [xL, xU]. | ||
| * @dev For a linear function defined as f(x) = m*x + c, the average value over [xL, xU] is: | ||
| * (f(xL) + f(xU)) / 2, which can be rewritten as m*((xL + xU)/2) + c. | ||
| * This function calculates the slope m using the two endpoints of the line and then computes | ||
| * the y-intercept c (using c = y2 - m*x2). If the line is horizontal (zero slope), it returns the | ||
| * constant y-value. Note that precision loss may occur due to integer division and type casting. | ||
| * Also, it is assumed that fn.x1 and fn.x2 are distinct to avoid division by zero. | ||
| * @param fn The linear function defined by two points (with properties x1, y1, x2, y2). | ||
| * @param xL The lower bound of the x-interval. | ||
| * @param xU The upper bound of the x-interval. | ||
| * @return The average y-value over the interval [xL, xU]. | ||
| */ | ||
| function avgY(Line memory fn, uint256 xL, uint256 xU) internal pure returns (int256) { | ||
| // If the line is horizontal, return the constant y-value. | ||
| if (fn.y1 == fn.y2) { | ||
| return fn.y2.toInt256(); | ||
| } | ||
|
|
||
| // Calculate the slope (m = deltaY / deltaX). | ||
| int256 deltaY = fn.y2.toInt256() - fn.y1.toInt256(); | ||
| int256 deltaX = fn.x2.toInt256() - fn.x1.toInt256(); | ||
|
|
||
| // Calculate the y-intercept using one of the endpoints: c = y2 - m * x2. | ||
| int256 c = fn.y2.toInt256() - ((fn.x2.toInt256() * deltaY) / deltaX); | ||
|
|
||
| // Compute the average value over [xL, xU] as m*((xL + xU)/2) + c. | ||
| return ((((xL + xU).toInt256() * deltaY) / (2 * deltaX)) + c); | ||
| } | ||
| } |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.