Skip to content

Commit 0f59545

Browse files
committed
Update require checks
1 parent a28ff34 commit 0f59545

File tree

2 files changed

+13
-12
lines changed

2 files changed

+13
-12
lines changed

contracts/extensions/PerpV2LeverageStrategyExtension.sol

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -233,7 +233,9 @@ contract PerpV2LeverageStrategyExtension is BaseExtension {
233233
function engage() external onlyOperator {
234234
ActionInfo memory engageInfo = _createActionInfo();
235235

236-
require(engageInfo.baseBalance == 0, "Must not have existing base token position");
236+
// Assert currentLeverageRatio is 0. Since currentLeverageRatio = baseBalance * basePrice / accountValue,
237+
// asserting baseBalance is 0 is equivalent to asserting currentLeverageRatio is 0.
238+
require(engageInfo.baseBalance == 0, "Current leverage ratio must be 0");
237239
require(engageInfo.accountInfo.collateralBalance > 0, "Collateral balance must be > 0");
238240

239241
LeverageInfo memory leverageInfo = LeverageInfo({
@@ -707,15 +709,14 @@ contract PerpV2LeverageStrategyExtension is BaseExtension {
707709
ActionInfo memory actionInfo = _createActionInfo();
708710

709711
require(actionInfo.setTotalSupply > 0, "SetToken must have > 0 supply");
710-
711-
// This function is called during rebalance, iterateRebalance, ripcord and disengage.
712-
// |baseBalance| > 0, shows the position exists, and the Set has been engaged. We should not
713-
// check for |quoteBalance| > 0, as it is redundant.
714-
require(actionInfo.baseBalance.absUint256() > 0, "Base asset balance must be > 0");
715712

716713
// Get current leverage ratio
717714
int256 currentLeverageRatio = _calculateCurrentLeverageRatio(actionInfo);
718715

716+
// This function is called during rebalance, iterateRebalance, ripcord and disengage.
717+
// Assert currentLeverageRatio is 0 as the set should be engaged before this function is called.
718+
require(currentLeverageRatio.absUint256() > 0, "Current leverage ratio must NOT be 0");
719+
719720
return LeverageInfo({
720721
action: actionInfo,
721722
currentLeverageRatio: currentLeverageRatio,

test/extensions/perpV2LeverageStrategyExtension.spec.ts

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -658,7 +658,7 @@ describe("PerpV2LeverageStrategyExtension", () => {
658658
});
659659

660660
it("should revert", async () => {
661-
await expect(subject()).to.be.revertedWith("Must not have existing base token position");
661+
await expect(subject()).to.be.revertedWith("Current leverage ratio must be 0");
662662
});
663663
});
664664

@@ -1737,7 +1737,7 @@ describe("PerpV2LeverageStrategyExtension", () => {
17371737

17381738
describe("when not engaged", async () => {
17391739
it("should revert", async () => {
1740-
await expect(subject()).to.be.revertedWith("Base asset balance must be > 0");
1740+
await expect(subject()).to.be.revertedWith("Current leverage ratio must NOT be 0");
17411741
});
17421742
});
17431743
});
@@ -2547,7 +2547,7 @@ describe("PerpV2LeverageStrategyExtension", () => {
25472547

25482548
describe("when not engaged", async () => {
25492549
it("should revert", async () => {
2550-
await expect(subject()).to.be.revertedWith("Base asset balance must be > 0");
2550+
await expect(subject()).to.be.revertedWith("Current leverage ratio must NOT be 0 asset balance must be > 0");
25512551
});
25522552
});
25532553
});
@@ -3064,7 +3064,7 @@ describe("PerpV2LeverageStrategyExtension", () => {
30643064

30653065
describe("when not engaged", async () => {
30663066
it("should revert", async () => {
3067-
await expect(subject()).to.be.revertedWith("Base asset balance must be > 0");
3067+
await expect(subject()).to.be.revertedWith("Current leverage ratio must NOT be 0 asset balance must be > 0");
30683068
});
30693069
});
30703070
});
@@ -3145,7 +3145,7 @@ describe("PerpV2LeverageStrategyExtension", () => {
31453145
});
31463146

31473147
it("should revert", async () => {
3148-
await expect(subject()).to.be.revertedWith("Base asset balance must be > 0");
3148+
await expect(subject()).to.be.revertedWith("Current leverage ratio must NOT be 0 asset balance must be > 0");
31493149
});
31503150
});
31513151
});
@@ -3228,7 +3228,7 @@ describe("PerpV2LeverageStrategyExtension", () => {
32283228
});
32293229

32303230
it("should revert", async () => {
3231-
await expect(subject()).to.be.revertedWith("Base asset balance must be > 0");
3231+
await expect(subject()).to.be.revertedWith("Current leverage ratio must NOT be 0 asset balance must be > 0");
32323232
});
32333233
});
32343234
});

0 commit comments

Comments
 (0)