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

Try to reduce controller bytecode size #434

Closed
wants to merge 7 commits into from
Closed
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
143 changes: 75 additions & 68 deletions contracts/core/Controller.sol

Large diffs are not rendered by default.

4 changes: 2 additions & 2 deletions docs/contracts-documentation/core/Controller.md
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ Contract that controls the Gamma Protocol and the interaction of all sub contrac

- `hasExpired(address _otoken) (external)`

- `getVault(address _owner, uint256 _vaultId) (public)`
- `getVaultWithDetails(address _owner, uint256 _vaultId) (public)`

- `_runActions(struct Actions.ActionArgs[] _actions) (internal)`

Expand Down Expand Up @@ -420,7 +420,7 @@ check if an oToken has expired

- True if the otoken has expired, False if not

### Function `getVault(address _owner, uint256 _vaultId) → struct MarginVault.Vault, uint256, uint256 public`
### Function `getVaultWithDetails(address _owner, uint256 _vaultId) → struct MarginVault.Vault, uint256, uint256 public`

return a specific vault

Expand Down
4 changes: 2 additions & 2 deletions docs/contracts-documentation/tests/MarginVaultTester.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

## Functions:

- `getVault(uint256 _vaultIndex) (external)`
- `getVaultWithDetails(uint256 _vaultIndex) (external)`

- `testAddShort(uint256 _vaultIndex, address _shortOtoken, uint256 _amount, uint256 _index) (external)`

Expand All @@ -16,7 +16,7 @@

- `testRemoveCollateral(uint256 _vaultIndex, address _collateralAsset, uint256 _amount, uint256 _index) (external)`

### Function `getVault(uint256 _vaultIndex) → struct MarginVault.Vault external`
### Function `getVaultWithDetails(uint256 _vaultIndex) → struct MarginVault.Vault external`

### Function `testAddShort(uint256 _vaultIndex, address _shortOtoken, uint256 _amount, uint256 _index) external`

Expand Down
2 changes: 1 addition & 1 deletion docs/uml/GammaController.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
2 changes: 1 addition & 1 deletion docs/uml/GammaUML.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
8 changes: 4 additions & 4 deletions test/integration-tests/longCallSpreadExpireItm.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -268,7 +268,7 @@ contract('Long Call Spread Option expires Itm flow', ([accountOwner1, nakedBuyer
const longOtokenSupplyBefore = new BigNumber(await lowerStrikeCall.totalSupply())

// Check that we start at a valid state
const vaultBefore = await controllerProxy.getVault(accountOwner1, vaultCounter1)
const vaultBefore = await controllerProxy.getVaultWithDetails(accountOwner1, vaultCounter1)
const vaultStateBefore = await calculator.getExcessCollateral(vaultBefore[0], vaultBefore[1])
assert.equal(vaultStateBefore[0].toString(), '0')
assert.equal(vaultStateBefore[1], true)
Expand Down Expand Up @@ -336,7 +336,7 @@ contract('Long Call Spread Option expires Itm flow', ([accountOwner1, nakedBuyer
assert.equal(longOtokenSupplyBefore.minus(scaledOptionsAmount).toString(), longOtokenSupplyAfter.toString())

// Check that we end at a valid state
const vaultAfter = await controllerProxy.getVault(accountOwner1, vaultCounter1)
const vaultAfter = await controllerProxy.getVaultWithDetails(accountOwner1, vaultCounter1)
const vaultStateAfter = await calculator.getExcessCollateral(vaultAfter[0], vaultAfter[1])
assert.equal(vaultStateAfter[0].toString(), '0')
assert.equal(vaultStateAfter[1], true)
Expand Down Expand Up @@ -430,7 +430,7 @@ contract('Long Call Spread Option expires Itm flow', ([accountOwner1, nakedBuyer
const lowerStrikeCallSupplyBefore = new BigNumber(await lowerStrikeCall.totalSupply())

// Check that we start at a valid state
const vaultBefore = await controllerProxy.getVault(accountOwner2, vaultCounter2)
const vaultBefore = await controllerProxy.getVaultWithDetails(accountOwner2, vaultCounter2)
const vaultStateBefore = await calculator.getExcessCollateral(vaultBefore[0], vaultBefore[1])
assert.equal(vaultStateBefore[0].toString(), scaledCollateralAmount)
assert.equal(vaultStateBefore[1], true)
Expand Down Expand Up @@ -471,7 +471,7 @@ contract('Long Call Spread Option expires Itm flow', ([accountOwner1, nakedBuyer
assert.equal(lowerStrikeCallSupplyBefore.toString(), lowerStrikeCallSupplyAfter.toString())

// Check that we end at a valid state
const vaultAfter = await controllerProxy.getVault(accountOwner2, vaultCounter2)
const vaultAfter = await controllerProxy.getVaultWithDetails(accountOwner2, vaultCounter2)
const vaultStateAfter = await calculator.getExcessCollateral(vaultAfter[0], vaultAfter[1])
assert.equal(vaultStateAfter[0].toString(), '0')
assert.equal(vaultStateAfter[1], true)
Expand Down
8 changes: 4 additions & 4 deletions test/integration-tests/longCallSpreadExpireOtm.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -267,7 +267,7 @@ contract('Long Call Spread Option expires Otm flow', ([accountOwner1, nakedBuyer
const lowerStrikeCallSupplyBefore = new BigNumber(await lowerStrikeCall.totalSupply())

// Check that we start at a valid state
const vaultBefore = await controllerProxy.getVault(accountOwner1, vaultCounter1)
const vaultBefore = await controllerProxy.getVaultWithDetails(accountOwner1, vaultCounter1)
const vaultStateBefore = await calculator.getExcessCollateral(vaultBefore[0], vaultBefore[1])
assert.equal(vaultStateBefore[0].toString(), '0')
assert.equal(vaultStateBefore[1], true)
Expand Down Expand Up @@ -322,7 +322,7 @@ contract('Long Call Spread Option expires Otm flow', ([accountOwner1, nakedBuyer
)

// Check that we end at a valid state
const vaultAfter = await controllerProxy.getVault(accountOwner1, vaultCounter1)
const vaultAfter = await controllerProxy.getVaultWithDetails(accountOwner1, vaultCounter1)
const vaultStateAfter = await calculator.getExcessCollateral(vaultAfter[0], vaultAfter[1])
assert.equal(vaultStateAfter[0].toString(), '0')
assert.equal(vaultStateAfter[1], true)
Expand Down Expand Up @@ -397,7 +397,7 @@ contract('Long Call Spread Option expires Otm flow', ([accountOwner1, nakedBuyer
const lowerStrikeCallSupplyBefore = new BigNumber(await lowerStrikeCall.totalSupply())

// Check that we start at a valid state
const vaultBefore = await controllerProxy.getVault(accountOwner2, vaultCounter2)
const vaultBefore = await controllerProxy.getVaultWithDetails(accountOwner2, vaultCounter2)
const vaultStateBefore = await calculator.getExcessCollateral(vaultBefore[0], vaultBefore[1])
assert.equal(vaultStateBefore[0].toString(), scaledCollateralAmount)
assert.equal(vaultStateBefore[1], true)
Expand Down Expand Up @@ -438,7 +438,7 @@ contract('Long Call Spread Option expires Otm flow', ([accountOwner1, nakedBuyer
assert.equal(lowerStrikeCallSupplyBefore.toString(), lowerStrikeCallSupplyAfter.toString())

// Check that we end at a valid state
const vaultAfter = await controllerProxy.getVault(accountOwner2, vaultCounter2)
const vaultAfter = await controllerProxy.getVaultWithDetails(accountOwner2, vaultCounter2)
const vaultStateAfter = await calculator.getExcessCollateral(vaultAfter[0], vaultAfter[1])
assert.equal(vaultStateAfter[0].toString(), '0')
assert.equal(vaultStateAfter[1], true)
Expand Down
12 changes: 6 additions & 6 deletions test/integration-tests/longCallSpreadPreExpiry.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -232,7 +232,7 @@ contract('Long Call Spread Option closed before expiry flow', ([accountOwner1, n
const marginPoolLongOtokenBalanceBefore = new BigNumber(await lowerStrikeCall.balanceOf(marginPool.address))

// Check that we start at a valid state
const vaultBefore = await controllerProxy.getVault(accountOwner1, vaultCounter1)
const vaultBefore = await controllerProxy.getVaultWithDetails(accountOwner1, vaultCounter1)
const vaultStateBefore = await calculator.getExcessCollateral(vaultBefore[0], vaultBefore[1])
assert.equal(vaultStateBefore[0].toString(), '0')
assert.equal(vaultStateBefore[1], true)
Expand Down Expand Up @@ -324,7 +324,7 @@ contract('Long Call Spread Option closed before expiry flow', ([accountOwner1, n
)

// Check that we end at a valid state
const vaultAfter = await controllerProxy.getVault(accountOwner1, vaultCounter1)
const vaultAfter = await controllerProxy.getVaultWithDetails(accountOwner1, vaultCounter1)
const vaultStateAfter = await calculator.getExcessCollateral(vaultAfter[0], vaultAfter[1])
assert.equal(vaultStateAfter[0].toString(), '0')
assert.equal(vaultStateAfter[1], true)
Expand Down Expand Up @@ -370,7 +370,7 @@ contract('Long Call Spread Option closed before expiry flow', ([accountOwner1, n
const marginPoolLongOtokenBalanceBefore = new BigNumber(await lowerStrikeCall.balanceOf(marginPool.address))

// Check that we start at a valid state
const vaultBefore = await controllerProxy.getVault(accountOwner1, vaultCounter1)
const vaultBefore = await controllerProxy.getVaultWithDetails(accountOwner1, vaultCounter1)
const vaultStateBefore = await calculator.getExcessCollateral(vaultBefore[0], vaultBefore[1])
assert.equal(vaultStateBefore[0].toString(), '0')
assert.equal(vaultStateBefore[1], true)
Expand Down Expand Up @@ -434,7 +434,7 @@ contract('Long Call Spread Option closed before expiry flow', ([accountOwner1, n
)

// Check that we end at a valid state
const vaultAfter = await controllerProxy.getVault(accountOwner1, vaultCounter1)
const vaultAfter = await controllerProxy.getVaultWithDetails(accountOwner1, vaultCounter1)
const vaultStateAfter = await calculator.getExcessCollateral(vaultAfter[0], vaultAfter[1])
assert.equal(vaultStateAfter[0].toString(), '0')
assert.equal(vaultStateAfter[1], true)
Expand Down Expand Up @@ -472,7 +472,7 @@ contract('Long Call Spread Option closed before expiry flow', ([accountOwner1, n
const marginPoolLowerStrikeCallBalanceBefore = new BigNumber(await lowerStrikeCall.balanceOf(marginPool.address))

// Check that we start at a valid state
const vaultBefore = await controllerProxy.getVault(accountOwner2, vaultCounter2)
const vaultBefore = await controllerProxy.getVaultWithDetails(accountOwner2, vaultCounter2)
const vaultStateBefore = await calculator.getExcessCollateral(vaultBefore[0], vaultBefore[1])
assert.equal(vaultStateBefore[0].toString(), '0')
assert.equal(vaultStateBefore[1], true)
Expand Down Expand Up @@ -527,7 +527,7 @@ contract('Long Call Spread Option closed before expiry flow', ([accountOwner1, n
assert.equal(marginPoolLowerStrikeCallBalanceBefore.toString(), marginPoolLowerStrikeCallBalanceAfter.toString())

// Check that we end at a valid state
const vaultAfter = await controllerProxy.getVault(accountOwner2, vaultCounter2)
const vaultAfter = await controllerProxy.getVaultWithDetails(accountOwner2, vaultCounter2)
const vaultStateAfter = await calculator.getExcessCollateral(vaultAfter[0], vaultAfter[1])
assert.equal(vaultStateAfter[0].toString(), '0')
assert.equal(vaultStateAfter[1], true)
Expand Down
12 changes: 6 additions & 6 deletions test/integration-tests/longPutExpireItm.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -228,7 +228,7 @@ contract('Long Put Spread Option closed ITM flow', ([accountOwner1, accountOwner
const marginPoolLongOtokenBalanceBefore = new BigNumber(await higherStrikePut.balanceOf(marginPool.address))

// Check that we start at a valid state
const vaultBefore = await controllerProxy.getVault(accountOwner1, vaultCounter1)
const vaultBefore = await controllerProxy.getVaultWithDetails(accountOwner1, vaultCounter1)
const vaultStateBefore = await calculator.getExcessCollateral(vaultBefore[0], vaultBefore[1])
assert.equal(vaultStateBefore[0].toString(), '0')
assert.equal(vaultStateBefore[1], true)
Expand Down Expand Up @@ -320,7 +320,7 @@ contract('Long Put Spread Option closed ITM flow', ([accountOwner1, accountOwner
)

// Check that we end at a valid state
const vaultAfter = await controllerProxy.getVault(accountOwner1, vaultCounter1)
const vaultAfter = await controllerProxy.getVaultWithDetails(accountOwner1, vaultCounter1)
const vaultStateAfter = await calculator.getExcessCollateral(vaultAfter[0], vaultAfter[1])
assert.equal(vaultStateAfter[0].toString(), '0')
assert.equal(vaultStateAfter[1], true)
Expand Down Expand Up @@ -365,7 +365,7 @@ contract('Long Put Spread Option closed ITM flow', ([accountOwner1, accountOwner
const marginPoolLongOtokenBalanceBefore = new BigNumber(await higherStrikePut.balanceOf(marginPool.address))

// Check that we start at a valid state
const vaultBefore = await controllerProxy.getVault(accountOwner1, vaultCounter1)
const vaultBefore = await controllerProxy.getVaultWithDetails(accountOwner1, vaultCounter1)
const vaultStateBefore = await calculator.getExcessCollateral(vaultBefore[0], vaultBefore[1])
assert.equal(vaultStateBefore[0].toString(), '0')
assert.equal(vaultStateBefore[1], true)
Expand Down Expand Up @@ -429,7 +429,7 @@ contract('Long Put Spread Option closed ITM flow', ([accountOwner1, accountOwner
)

// Check that we end at a valid state
const vaultAfter = await controllerProxy.getVault(accountOwner1, vaultCounter1)
const vaultAfter = await controllerProxy.getVaultWithDetails(accountOwner1, vaultCounter1)
const vaultStateAfter = await calculator.getExcessCollateral(vaultAfter[0], vaultAfter[1])
assert.equal(vaultStateAfter[0].toString(), '0')
assert.equal(vaultStateAfter[1], true)
Expand Down Expand Up @@ -466,7 +466,7 @@ contract('Long Put Spread Option closed ITM flow', ([accountOwner1, accountOwner
const higherStrikePutSupplyBefore = new BigNumber(await higherStrikePut.totalSupply())

// Check that we start at a valid state
const vaultBefore = await controllerProxy.getVault(accountOwner2, vaultCounter2)
const vaultBefore = await controllerProxy.getVaultWithDetails(accountOwner2, vaultCounter2)
const vaultStateBefore = await calculator.getExcessCollateral(vaultBefore[0], vaultBefore[1])
assert.equal(vaultStateBefore[0].toString(), '0')
assert.equal(vaultStateBefore[1], true)
Expand Down Expand Up @@ -519,7 +519,7 @@ contract('Long Put Spread Option closed ITM flow', ([accountOwner1, accountOwner
)

// Check that we end at a valid state
const vaultAfter = await controllerProxy.getVault(accountOwner2, vaultCounter2)
const vaultAfter = await controllerProxy.getVaultWithDetails(accountOwner2, vaultCounter2)
const vaultStateAfter = await calculator.getExcessCollateral(vaultAfter[0], vaultAfter[1])
assert.equal(vaultStateAfter[0].toString(), '0')
assert.equal(vaultStateAfter[1], true)
Expand Down
8 changes: 4 additions & 4 deletions test/integration-tests/longPutExpireOtm.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -269,7 +269,7 @@ contract('Long Put Spread Option expires Otm flow', ([accountOwner1, nakedBuyer,
const longOtokenSupplyBefore = new BigNumber(await higherStrikePut.totalSupply())

// Check that we start at a valid state
const vaultBefore = await controllerProxy.getVault(accountOwner1, vaultCounter1)
const vaultBefore = await controllerProxy.getVaultWithDetails(accountOwner1, vaultCounter1)
const vaultStateBefore = await calculator.getExcessCollateral(vaultBefore[0], vaultBefore[1])
assert.equal(vaultStateBefore[0].toString(), '0')
assert.equal(vaultStateBefore[1], true)
Expand Down Expand Up @@ -328,7 +328,7 @@ contract('Long Put Spread Option expires Otm flow', ([accountOwner1, nakedBuyer,
)

// Check that we end at a valid state
const vaultAfter = await controllerProxy.getVault(accountOwner1, vaultCounter1)
const vaultAfter = await controllerProxy.getVaultWithDetails(accountOwner1, vaultCounter1)
const vaultStateAfter = await calculator.getExcessCollateral(vaultAfter[0], vaultAfter[1])
assert.equal(vaultStateAfter[0].toString(), '0')
assert.equal(vaultStateAfter[1], true)
Expand Down Expand Up @@ -400,7 +400,7 @@ contract('Long Put Spread Option expires Otm flow', ([accountOwner1, nakedBuyer,
const scaledPayoutAmount = createTokenAmount(collateralPayout, usdcDecimals)

// Check that after expiry, the vault excess balance has updated as expected
const vaultBefore = await controllerProxy.getVault(accountOwner2, vaultCounter2)
const vaultBefore = await controllerProxy.getVaultWithDetails(accountOwner2, vaultCounter2)
const vaultStateBeforeSettlement = await calculator.getExcessCollateral(vaultBefore[0], vaultBefore[1])
assert.equal(vaultStateBeforeSettlement[0].toString(), scaledPayoutAmount)
assert.equal(vaultStateBeforeSettlement[1], true)
Expand Down Expand Up @@ -438,7 +438,7 @@ contract('Long Put Spread Option expires Otm flow', ([accountOwner1, nakedBuyer,
assert.equal(shortOtokenSupplyBefore.toString(), shortOtokenSupplyAfter.toString())

// Check that we end at a valid state
const vaultAfter = await controllerProxy.getVault(accountOwner2, vaultCounter2)
const vaultAfter = await controllerProxy.getVaultWithDetails(accountOwner2, vaultCounter2)
const vaultStateAfter = await calculator.getExcessCollateral(vaultAfter[0], vaultAfter[1])
assert.equal(vaultStateAfter[0].toString(), '0')
assert.equal(vaultStateAfter[1], true)
Expand Down
Loading