Skip to content

Commit fb6b2df

Browse files
committed
added dr eq range
1 parent aafe6f6 commit fb6b2df

2 files changed

Lines changed: 54 additions & 11 deletions

File tree

spot-contracts/contracts/FeePolicy.sol

Lines changed: 16 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,11 @@ contract FeePolicy is IFeePolicy, OwnableUpgradeable {
6868
/// is *different* from button-wood's tranche ratios.
6969
uint256 public override targetSystemRatio;
7070

71+
/// @notice The range of deviation ratios which define the equilibrium zone.
72+
/// @dev When the system's dr is within the equilibrium zone, no value is transferred
73+
/// during a rebalance operation.
74+
Range public equilibriumDR;
75+
7176
//-----------------------------------------------------------------------------
7277
// Fee parameters
7378

@@ -113,6 +118,7 @@ contract FeePolicy is IFeePolicy, OwnableUpgradeable {
113118
__Ownable_init();
114119

115120
targetSystemRatio = 3 * ONE; // 3.0
121+
equilibriumDR = Range({ lower: (ONE * 95) / 100, upper: (ONE * 105) / 100 });
116122

117123
// initializing fees
118124
feeFnDRDown = Line({
@@ -153,6 +159,15 @@ contract FeePolicy is IFeePolicy, OwnableUpgradeable {
153159
targetSystemRatio = targetSystemRatio_;
154160
}
155161

162+
/// @notice Updates the equilibrium DR range.
163+
/// @param equilibriumDR_ The new equilibrium DR range as tuple of a fixed point numbers with {DECIMALS} places.
164+
function updateEquilibriumDR(Range memory equilibriumDR_) external onlyOwner {
165+
if (equilibriumDR_.lower > equilibriumDR_.upper || equilibriumDR_.lower > ONE || equilibriumDR_.upper < ONE) {
166+
revert InvalidRange();
167+
}
168+
equilibriumDR = equilibriumDR_;
169+
}
170+
156171
/// @notice Updates the system fee functions.
157172
/// @param feeFnDRDown_ The new fee function for operations that decrease DR.
158173
/// @param feeFnDRUp_ The new fee function for operations that increase DR.
@@ -261,8 +276,7 @@ contract FeePolicy is IFeePolicy, OwnableUpgradeable {
261276
function computeRebalanceAmount(SystemTVL memory s) external view override returns (int256 underlyingAmtIntoPerp) {
262277
// We skip rebalancing if dr is close to 1.0
263278
uint256 dr = computeDeviationRatio(s);
264-
Range memory drEq = drEqZone();
265-
if (dr >= drEq.lower && dr <= drEq.upper) {
279+
if (dr >= equilibriumDR.lower && dr <= equilibriumDR.upper) {
266280
return 0;
267281
}
268282

@@ -305,11 +319,4 @@ contract FeePolicy is IFeePolicy, OwnableUpgradeable {
305319
// NOTE: We assume that perp's TVL and vault's TVL values have the same base denomination.
306320
return s.vaultTVL.mulDiv(ONE, s.perpTVL).mulDiv(ONE, targetSystemRatio);
307321
}
308-
309-
/// @return The range of deviation ratios which define the equilibrium zone.
310-
/// @dev We infer the equilibrium from the fee function definitions, i.e) the upperDR in `feeFnDRDown`
311-
/// and lowerDR in `feeFnDRUp`.
312-
function drEqZone() public view returns (Range memory) {
313-
return Range({ lower: feeFnDRDown.x2, upper: feeFnDRUp.x1 });
314-
}
315322
}

spot-contracts/test/FeePolicy.ts

Lines changed: 38 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ describe("FeePolicy", function () {
4646
expect(f2[2]).to.eq(toPerc("1.5"));
4747
expect(f2[3]).to.eq(toPerc("0.25"));
4848

49-
const drEq = await feePolicy.drEqZone();
49+
const drEq = await feePolicy.equilibriumDR();
5050
expect(drEq[0]).to.eq(toPerc("0.95"));
5151
expect(drEq[1]).to.eq(toPerc("1.05"));
5252

@@ -91,6 +91,42 @@ describe("FeePolicy", function () {
9191
});
9292
});
9393

94+
describe("#updateEquilibriumDR", function () {
95+
describe("when triggered by non-owner", function () {
96+
it("should revert", async function () {
97+
await expect(
98+
feePolicy.connect(otherUser).updateEquilibriumDR([toPerc("0.9"), toPerc("1.1")]),
99+
).to.be.revertedWith("Ownable: caller is not the owner");
100+
});
101+
});
102+
103+
describe("when range is invalid", function () {
104+
it("should revert", async function () {
105+
await expect(feePolicy.updateEquilibriumDR([toPerc("1.2"), toPerc("1.1")])).to.be.revertedWithCustomError(
106+
feePolicy,
107+
"InvalidRange",
108+
);
109+
await expect(feePolicy.updateEquilibriumDR([toPerc("1.01"), toPerc("1.1")])).to.be.revertedWithCustomError(
110+
feePolicy,
111+
"InvalidRange",
112+
);
113+
await expect(feePolicy.updateEquilibriumDR([toPerc("0.9"), toPerc("0.99")])).to.be.revertedWithCustomError(
114+
feePolicy,
115+
"InvalidRange",
116+
);
117+
});
118+
});
119+
120+
describe("when triggered by owner", function () {
121+
it("should update the target sr", async function () {
122+
await feePolicy.connect(deployer).updateEquilibriumDR([toPerc("0.9"), toPerc("1.1")]);
123+
const eq = await feePolicy.equilibriumDR();
124+
expect(eq[0]).to.eq(toPerc("0.9"));
125+
expect(eq[1]).to.eq(toPerc("1.1"));
126+
});
127+
});
128+
});
129+
94130
describe("#updateFees", function () {
95131
const VALID_DOWN = toLine("0.0", "1.0", "0.99", "0.0");
96132
const VALID_UP = toLine("1.01", "0.0", "2.0", "1.0");
@@ -333,7 +369,7 @@ describe("FeePolicy", function () {
333369

334370
describe("when deviation is within eq range", function () {
335371
it("should compute rebalance data", async function () {
336-
await feePolicy.updateFees(toLine("0", "0.5", "0.5", "0"), toLine("2", "0", "10", "0.5"));
372+
await feePolicy.updateEquilibriumDR([toPerc("0.5"), toPerc("2")]);
337373
const r1 = await feePolicy.computeRebalanceAmount({
338374
perpTVL: toAmt("120"),
339375
vaultTVL: toAmt("500"),

0 commit comments

Comments
 (0)