From f80c8c06cadeacc99e0c2feb75c43699828c0a57 Mon Sep 17 00:00:00 2001 From: Vitaly Galaichuk Date: Thu, 5 Oct 2023 22:49:03 +0700 Subject: [PATCH] chore: add tests to burn short in account (#25) --- .gas-snapshot | 394 +++++++++--------- src/settled-cash/AccountCashEngine.sol | 1 - src/settled-cash/CrossMarginCashEngine.sol | 2 - .../AccountPhysicalEngine.sol | 3 +- test/integrations-cash/BurnToken.t.sol | 161 +++++++ test/integrations-physical/BurnToken.t.sol | 161 +++++++ 6 files changed, 518 insertions(+), 204 deletions(-) diff --git a/.gas-snapshot b/.gas-snapshot index 1c992c6..43958cb 100644 --- a/.gas-snapshot +++ b/.gas-snapshot @@ -5,11 +5,10 @@ CashEngineProxyTest:testImplementationContractOwnerIsZero() (gas: 7690) CashEngineProxyTest:testImplementationIsInitialized() (gas: 10956) CashEngineProxyTest:testProxyIsInitialized() (gas: 15850) CashEngineProxyTest:testProxyOwnerIsSelf() (gas: 12572) -CrossMarginCashEngineAccessTest:test() (gas: 164) +CrossMarginCashEngineAccessTest:test() (gas: 186) CrossMarginCashEngineAccessTest:testCannotTransferToOverrideAnotherAccount() (gas: 118158) CrossMarginCashEngineAccessTest:testCannotTransferUnAuthorizedAccount() (gas: 15536) -CrossMarginCashEngineAccessTest:testForgeCoverageIgnoreThis() (gas: 208) -CrossMarginCashEngineAccessTest:testTransferCMAccount() (gas: 131166) +CrossMarginCashEngineAccessTest:testTransferCMAccount() (gas: 131143) CrossMarginCashEngineAccessTest:testUtils() (gas: 144) CrossMarginPhysicalEngineAccessTest:test() (gas: 164) CrossMarginPhysicalEngineAccessTest:testCannotTransferToOverrideAnotherAccount() (gas: 118166) @@ -21,36 +20,34 @@ Deploy:testChill() (gas: 143) Deploy:testUtils() (gas: 121) DeployPhysicalMarginEngine:testChill() (gas: 165) DeployPhysicalMarginEngine:testUtils() (gas: 121) -General_CMC:test() (gas: 164) -General_CMC:testCannotCallAddLongWithExpiredToken() (gas: 26112) -General_CMC:testCannotCallAddLongWithNotAuthorizedEngine() (gas: 56005) +General_CMC:test() (gas: 186) +General_CMC:testCannotCallAddLongWithExpiredToken() (gas: 26422) +General_CMC:testCannotCallAddLongWithNotAuthorizedEngine() (gas: 56315) General_CMC:testCannotCallPayoutFromAnybody() (gas: 17858) -General_CMC:testCannotCallRemoveLongNotInAccount() (gas: 31902) -General_CMC:testForgeCoverageIgnoreThis() (gas: 208) -General_CMC:testGetMinCollateral() (gas: 282012) +General_CMC:testCannotCallRemoveLongNotInAccount() (gas: 32212) +General_CMC:testGetMinCollateral() (gas: 281967) General_CMC:testUtils() (gas: 167) General_CMP:test() (gas: 164) -General_CMP:testCannotCallAddLongWithExpiredOption() (gas: 26155) -General_CMP:testCannotCallAddLongWithNotAuthorizedEngine() (gas: 51671) +General_CMP:testCannotCallAddLongWithExpiredOption() (gas: 26465) +General_CMP:testCannotCallAddLongWithNotAuthorizedEngine() (gas: 51981) General_CMP:testCannotCallPayoutFromAnybody() (gas: 17872) -General_CMP:testCannotCallRemoveLongNotInAccount() (gas: 31922) +General_CMP:testCannotCallRemoveLongNotInAccount() (gas: 32232) General_CMP:testForgeCoverageIgnoreThis() (gas: 208) General_CMP:testGetMinCollateral() (gas: 300004) General_CMP:testUtils() (gas: 167) MockEngineV2:test() (gas: 162) MockWhitelist:test() (gas: 186) Permissioned_CMC:test() (gas: 186) -Permissioned_CMC:testAliceCanSettleOption() (gas: 386925) +Permissioned_CMC:testAliceCanSettleOption() (gas: 386924) Permissioned_CMC:testCanExecute() (gas: 157627) Permissioned_CMC:testCannotExecute() (gas: 30042) -Permissioned_CMC:testCannotSettleOption() (gas: 359728) -Permissioned_CMC:testForgeCoverageIgnoreThis() (gas: 230) +Permissioned_CMC:testCannotSettleOption() (gas: 359727) Permissioned_CMC:testUtils() (gas: 167) Permissioned_CMP:test() (gas: 186) -Permissioned_CMP:testAliceCanSettleOption() (gas: 417988) +Permissioned_CMP:testAliceCanSettleOption() (gas: 417957) Permissioned_CMP:testCanExecute() (gas: 157683) Permissioned_CMP:testCannotExecute() (gas: 30056) -Permissioned_CMP:testCannotSettleOption() (gas: 348024) +Permissioned_CMP:testCannotSettleOption() (gas: 347993) Permissioned_CMP:testForgeCoverageIgnoreThis() (gas: 230) Permissioned_CMP:testUtils() (gas: 167) PhysicalEngineProxyTest:testCanUpgradeToAnotherUUPSContract() (gas: 753669) @@ -60,91 +57,88 @@ PhysicalEngineProxyTest:testImplementationContractOwnerIsZero() (gas: 7635) PhysicalEngineProxyTest:testImplementationIsInitialized() (gas: 11000) PhysicalEngineProxyTest:testProxyIsInitialized() (gas: 15894) PhysicalEngineProxyTest:testProxyOwnerIsSelf() (gas: 12517) -PreviewCollateralReqBase_CMC:test() (gas: 164) -PreviewCollateralReqBase_CMC:testForgeCoverageIgnoreThis() (gas: 208) +PreviewCollateralReqBase_CMC:test() (gas: 186) PreviewCollateralReqBase_CMC:testIgnore() (gas: 188) PreviewCollateralReqBase_CMC:testUtils() (gas: 144) PreviewCollateralReqBase_CMP:test() (gas: 164) PreviewCollateralReqBase_CMP:testForgeCoverageIgnoreThis() (gas: 208) PreviewCollateralReqBase_CMP:testIgnore() (gas: 188) PreviewCollateralReqBase_CMP:testUtils() (gas: 144) -PreviewCollateralReq_CMCM:test() (gas: 208) +PreviewCollateralReq_CMCM:test() (gas: 230) PreviewCollateralReq_CMCM:testConversion() (gas: 115336) -PreviewCollateralReq_CMCM:testForgeCoverageIgnoreThis() (gas: 252) PreviewCollateralReq_CMCM:testIgnore() (gas: 232) PreviewCollateralReq_CMCM:testIronCondor() (gas: 117092) -PreviewCollateralReq_CMCM:testLongPutSpread() (gas: 65867) +PreviewCollateralReq_CMCM:testLongPutSpread() (gas: 65889) PreviewCollateralReq_CMCM:testLongStrangleSpread2() (gas: 112472) PreviewCollateralReq_CMCM:testLongStrangles() (gas: 72469) PreviewCollateralReq_CMCM:testMarginBinaryCallOption() (gas: 65265) PreviewCollateralReq_CMCM:testMarginCallSpreadSameUnderlyingCollateral() (gas: 70061) -PreviewCollateralReq_CMCM:testMarginCallSpreadSameUnderlyingCollateralBiggerNumbers() (gas: 70058) -PreviewCollateralReq_CMCM:testMarginLongBinaryPut() (gas: 65839) -PreviewCollateralReq_CMCM:testMarginRequirement1() (gas: 155376) +PreviewCollateralReq_CMCM:testMarginCallSpreadSameUnderlyingCollateralBiggerNumbers() (gas: 70080) +PreviewCollateralReq_CMCM:testMarginLongBinaryPut() (gas: 65775) +PreviewCollateralReq_CMCM:testMarginRequirement1() (gas: 155398) PreviewCollateralReq_CMCM:testMarginRequirement2() (gas: 155378) -PreviewCollateralReq_CMCM:testMarginRequirement3() (gas: 157868) -PreviewCollateralReq_CMCM:testMarginRequirement4() (gas: 155370) -PreviewCollateralReq_CMCM:testMarginRequirementsVanillaCall() (gas: 56362) -PreviewCollateralReq_CMCM:testMarginRequirementsVanillaPut() (gas: 56736) -PreviewCollateralReq_CMCM:testMarginShortBinaryPut() (gas: 67668) -PreviewCollateralReq_CMCM:testMarginSimpleITMCall() (gas: 56383) +PreviewCollateralReq_CMCM:testMarginRequirement3() (gas: 157890) +PreviewCollateralReq_CMCM:testMarginRequirement4() (gas: 155392) +PreviewCollateralReq_CMCM:testMarginRequirementsVanillaCall() (gas: 56384) +PreviewCollateralReq_CMCM:testMarginRequirementsVanillaPut() (gas: 56758) +PreviewCollateralReq_CMCM:testMarginShortBinaryPut() (gas: 67690) +PreviewCollateralReq_CMCM:testMarginSimpleITMCall() (gas: 56340) PreviewCollateralReq_CMCM:testMarginSimpleITMPut() (gas: 56738) -PreviewCollateralReq_CMCM:testMarginSimpleOTMCall() (gas: 56361) -PreviewCollateralReq_CMCM:testMarginSimplePut() (gas: 56737) +PreviewCollateralReq_CMCM:testMarginSimpleOTMCall() (gas: 56383) +PreviewCollateralReq_CMCM:testMarginSimplePut() (gas: 56759) PreviewCollateralReq_CMCM:testMarginUnsortedStrikes() (gas: 155526) PreviewCollateralReq_CMCM:testOneByTwoCall() (gas: 83955) -PreviewCollateralReq_CMCM:testOneByTwoPut() (gas: 89582) -PreviewCollateralReq_CMCM:testPutGreaterThanCalls() (gas: 115517) +PreviewCollateralReq_CMCM:testOneByTwoPut() (gas: 89604) +PreviewCollateralReq_CMCM:testPutGreaterThanCalls() (gas: 115472) PreviewCollateralReq_CMCM:testShortPutSpread() (gas: 67902) PreviewCollateralReq_CMCM:testShortStrangles() (gas: 77295) PreviewCollateralReq_CMCM:testStrangleSpread() (gas: 114801) PreviewCollateralReq_CMCM:testStrangleSpread2() (gas: 114645) PreviewCollateralReq_CMCM:testUpAndDown1() (gas: 65862) -PreviewCollateralReq_CMCM:testUpAndDown2() (gas: 68046) +PreviewCollateralReq_CMCM:testUpAndDown2() (gas: 68068) PreviewCollateralReq_CMCM:testUpAndDown3() (gas: 91154) -PreviewCollateralReq_CMCM:testUpAndDown4() (gas: 114530) +PreviewCollateralReq_CMCM:testUpAndDown4() (gas: 114485) PreviewCollateralReq_CMCM:testUtils() (gas: 234) PreviewCollateralReq_CMPM:test() (gas: 186) PreviewCollateralReq_CMPM:testConversion() (gas: 107850) PreviewCollateralReq_CMPM:testForgeCoverageIgnoreThis() (gas: 230) PreviewCollateralReq_CMPM:testIgnore() (gas: 210) -PreviewCollateralReq_CMPM:testIronCondor() (gas: 109568) -PreviewCollateralReq_CMPM:testLongPutSpread() (gas: 62654) -PreviewCollateralReq_CMPM:testLongStrangles() (gas: 67703) -PreviewCollateralReq_CMPM:testMarginBinaryCallOption() (gas: 61995) -PreviewCollateralReq_CMPM:testMarginCallSpreadSameUnderlyingCollateral() (gas: 66897) -PreviewCollateralReq_CMPM:testMarginCallSpreadSameUnderlyingCollateralBiggerNumbers() (gas: 66872) -PreviewCollateralReq_CMPM:testMarginLongBinaryPut() (gas: 62560) -PreviewCollateralReq_CMPM:testMarginRequirement1() (gas: 149464) -PreviewCollateralReq_CMPM:testMarginRequirement2() (gas: 148121) -PreviewCollateralReq_CMPM:testMarginRequirement3() (gas: 150636) -PreviewCollateralReq_CMPM:testMarginRequirement4() (gas: 148111) +PreviewCollateralReq_CMPM:testIronCondor() (gas: 109596) +PreviewCollateralReq_CMPM:testLongPutSpread() (gas: 62668) +PreviewCollateralReq_CMPM:testLongStrangles() (gas: 67731) +PreviewCollateralReq_CMPM:testMarginBinaryCallOption() (gas: 62009) +PreviewCollateralReq_CMPM:testMarginCallSpreadSameUnderlyingCollateral() (gas: 66911) +PreviewCollateralReq_CMPM:testMarginCallSpreadSameUnderlyingCollateralBiggerNumbers() (gas: 66886) +PreviewCollateralReq_CMPM:testMarginLongBinaryPut() (gas: 62574) +PreviewCollateralReq_CMPM:testMarginRequirement1() (gas: 149492) +PreviewCollateralReq_CMPM:testMarginRequirement2() (gas: 148149) +PreviewCollateralReq_CMPM:testMarginRequirement3() (gas: 150664) +PreviewCollateralReq_CMPM:testMarginRequirement4() (gas: 148139) PreviewCollateralReq_CMPM:testMarginRequirementsVanillaCall() (gas: 53018) PreviewCollateralReq_CMPM:testMarginRequirementsVanillaPut() (gas: 53348) -PreviewCollateralReq_CMPM:testMarginShortBinaryPut() (gas: 64481) +PreviewCollateralReq_CMPM:testMarginShortBinaryPut() (gas: 64495) PreviewCollateralReq_CMPM:testMarginSimpleCall() (gas: 53019) PreviewCollateralReq_CMPM:testMarginSimplePut() (gas: 53349) -PreviewCollateralReq_CMPM:testMarginUnsortedStrikes() (gas: 148202) -PreviewCollateralReq_CMPM:testOneByTwoCall() (gas: 79499) -PreviewCollateralReq_CMPM:testOneByTwoPut() (gas: 83652) -PreviewCollateralReq_CMPM:testPutGreaterThanCalls() (gas: 107945) -PreviewCollateralReq_CMPM:testShortPutSpread() (gas: 64693) +PreviewCollateralReq_CMPM:testMarginUnsortedStrikes() (gas: 148230) +PreviewCollateralReq_CMPM:testOneByTwoCall() (gas: 79541) +PreviewCollateralReq_CMPM:testOneByTwoPut() (gas: 83694) +PreviewCollateralReq_CMPM:testPutGreaterThanCalls() (gas: 107973) +PreviewCollateralReq_CMPM:testShortPutSpread() (gas: 64707) PreviewCollateralReq_CMPM:testShortStrangles() (gas: 72541) -PreviewCollateralReq_CMPM:testStrangleSpread() (gas: 107229) -PreviewCollateralReq_CMPM:testStrangleSpread2() (gas: 107095) -PreviewCollateralReq_CMPM:testUpAndDown1() (gas: 62605) -PreviewCollateralReq_CMPM:testUpAndDown2() (gas: 64837) -PreviewCollateralReq_CMPM:testUpAndDown3() (gas: 85018) -PreviewCollateralReq_CMPM:testUpAndDown4() (gas: 106935) +PreviewCollateralReq_CMPM:testStrangleSpread() (gas: 107257) +PreviewCollateralReq_CMPM:testStrangleSpread2() (gas: 107123) +PreviewCollateralReq_CMPM:testUpAndDown1() (gas: 62619) +PreviewCollateralReq_CMPM:testUpAndDown2() (gas: 64851) +PreviewCollateralReq_CMPM:testUpAndDown3() (gas: 85046) +PreviewCollateralReq_CMPM:testUpAndDown4() (gas: 106963) PreviewCollateralReq_CMPM:testUtils() (gas: 212) -TestAddCollateral_CMC:test() (gas: 209) -TestAddCollateral_CMC:testAddCollateralChangeStorage() (gas: 126902) +TestAddCollateral_CMC:test() (gas: 164) +TestAddCollateral_CMC:testAddCollateralChangeStorage() (gas: 126924) TestAddCollateral_CMC:testAddCollateralLoopMoveBalances() (gas: 141341) -TestAddCollateral_CMC:testAddCollateralMoveBalance() (gas: 128290) +TestAddCollateral_CMC:testAddCollateralMoveBalance() (gas: 128247) TestAddCollateral_CMC:testAddMultipleCollateralHasNoSideEffects() (gas: 213599) -TestAddCollateral_CMC:testCanAddDifferentCollateralToSameAccount() (gas: 196368) -TestAddCollateral_CMC:testCannotAddCollatFromOthers() (gas: 27606) -TestAddCollateral_CMC:testForgeCoverageIgnoreThis() (gas: 186) +TestAddCollateral_CMC:testCanAddDifferentCollateralToSameAccount() (gas: 196323) +TestAddCollateral_CMC:testCannotAddCollatFromOthers() (gas: 27628) TestAddCollateral_CMC:testUtils() (gas: 167) TestAddCollateral_CMP:test() (gas: 209) TestAddCollateral_CMP:testAddCollateralChangeStorage() (gas: 126939) @@ -155,38 +149,52 @@ TestAddCollateral_CMP:testCanAddDifferentCollateralToSameAccount() (gas: 196376) TestAddCollateral_CMP:testCannotAddCollatFromOthers() (gas: 27649) TestAddCollateral_CMP:testForgeCoverageIgnoreThis() (gas: 186) TestAddCollateral_CMP:testUtils() (gas: 167) -TestAddLong_CMC:test() (gas: 164) -TestAddLong_CMC:testAddLongCallToken() (gas: 518718) -TestAddLong_CMC:testAddLongPutToken() (gas: 519293) -TestAddLong_CMC:testForgeCoverageIgnoreThis() (gas: 208) +TestAddLong_CMC:test() (gas: 186) +TestAddLong_CMC:testAddLongCallToken() (gas: 518982) +TestAddLong_CMC:testAddLongPutToken() (gas: 519557) TestAddLong_CMC:testUtils() (gas: 144) TestAddLong_CMP:test() (gas: 164) -TestAddLong_CMP:testAddLongCallToken() (gas: 560142) -TestAddLong_CMP:testAddLongPutToken() (gas: 560563) +TestAddLong_CMP:testAddLongCallToken() (gas: 560477) +TestAddLong_CMP:testAddLongPutToken() (gas: 560898) TestAddLong_CMP:testForgeCoverageIgnoreThis() (gas: 208) TestAddLong_CMP:testUtils() (gas: 144) TestBatchExecute_CMC:test() (gas: 186) -TestBatchExecute_CMC:testForgeCoverageIgnoreThis() (gas: 230) TestBatchExecute_CMC:testMintSpreadChecksCollateralAfterBatch() (gas: 590026) TestBatchExecute_CMC:testMintTwoSidedStructure() (gas: 637423) TestBatchExecute_CMC:testMintTwoSidesSameOption() (gas: 585184) TestBatchExecute_CMC:testUtils() (gas: 167) TestBatchExecute_CMP:test() (gas: 186) TestBatchExecute_CMP:testForgeCoverageIgnoreThis() (gas: 230) -TestBatchExecute_CMP:testMintSpreadChecksCollateralAfterBatch() (gas: 631363) -TestBatchExecute_CMP:testMintTwoSidedStructure() (gas: 678759) -TestBatchExecute_CMP:testMintTwoSidesSameOption() (gas: 604574) +TestBatchExecute_CMP:testMintSpreadChecksCollateralAfterBatch() (gas: 631391) +TestBatchExecute_CMP:testMintTwoSidedStructure() (gas: 678787) +TestBatchExecute_CMP:testMintTwoSidesSameOption() (gas: 604602) TestBatchExecute_CMP:testUtils() (gas: 167) -TestBurnOption_CMC:test() (gas: 164) -TestBurnOption_CMC:testBurn() (gas: 64134) +TestBurnOptionFromAccount_CMC:test() (gas: 164) +TestBurnOptionFromAccount_CMC:testBurnFromAccount() (gas: 102329) +TestBurnOptionFromAccount_CMC:testCanBurnFromSubAccount() (gas: 260592) +TestBurnOptionFromAccount_CMC:testCannotBurnFromEmptySubAccount() (gas: 54703) +TestBurnOptionFromAccount_CMC:testCannotBurnFromUnAuthorizedAccount() (gas: 31106) +TestBurnOptionFromAccount_CMC:testCannotBurnFromWithWrongTokenId() (gas: 44045) +TestBurnOptionFromAccount_CMC:testCannotBurnWhenOptionTokenBalanceIsLow() (gas: 123669) +TestBurnOptionFromAccount_CMC:testUtils() (gas: 167) +TestBurnOptionFromAccount_CMP:test() (gas: 164) +TestBurnOptionFromAccount_CMP:testBurnFromAccount() (gas: 102445) +TestBurnOptionFromAccount_CMP:testCanBurnFromSubAccount() (gas: 258078) +TestBurnOptionFromAccount_CMP:testCannotBurnFromEmptySubAccount() (gas: 54767) +TestBurnOptionFromAccount_CMP:testCannotBurnFromUnAuthorizedAccount() (gas: 31149) +TestBurnOptionFromAccount_CMP:testCannotBurnFromWithWrongTokenId() (gas: 44065) +TestBurnOptionFromAccount_CMP:testCannotBurnWhenOptionTokenBalanceIsLow() (gas: 123722) +TestBurnOptionFromAccount_CMP:testForgeCoverageIgnoreThis() (gas: 230) +TestBurnOptionFromAccount_CMP:testUtils() (gas: 167) +TestBurnOption_CMC:test() (gas: 186) +TestBurnOption_CMC:testBurn() (gas: 68083) TestBurnOption_CMC:testCannotBurnForEmptyAccount() (gas: 34737) -TestBurnOption_CMC:testCannotBurnFromUnAuthorizedAccount() (gas: 65148) +TestBurnOption_CMC:testCannotBurnFromUnAuthorizedAccount() (gas: 65170) TestBurnOption_CMC:testCannotBurnWhenOptionTokenBalanceIsLow() (gas: 104226) TestBurnOption_CMC:testCannotBurnWithWrongTokenId() (gas: 39264) -TestBurnOption_CMC:testForgeCoverageIgnoreThis() (gas: 230) TestBurnOption_CMC:testUtils() (gas: 167) TestBurnOption_CMP:test() (gas: 164) -TestBurnOption_CMP:testBurn() (gas: 68792) +TestBurnOption_CMP:testBurn() (gas: 72547) TestBurnOption_CMP:testCannotBurnForEmptyAccount() (gas: 34848) TestBurnOption_CMP:testCannotBurnFromUnAuthorizedAccount() (gas: 65215) TestBurnOption_CMP:testCannotBurnWhenOptionTokenBalanceIsLow() (gas: 104337) @@ -214,42 +222,39 @@ TestCornerCases_CMPM:testUpAndDown2() (gas: 52291) TestCornerCases_CMPM:testUpAndDown3() (gas: 67639) TestCornerCases_CMPM:testUpAndDown4() (gas: 73968) TestExerciseLongPositions_CMP:test() (gas: 164) -TestExerciseLongPositions_CMP:testCanClearLongCallAfterExpiryBeforeWindowClosed() (gas: 425572) -TestExerciseLongPositions_CMP:testCanClearLongPastExerciseWindow() (gas: 329871) -TestExerciseLongPositions_CMP:testCanClearLongPortion() (gas: 468758) -TestExerciseLongPositions_CMP:testCanClearMultipleLongCallAfterExpiryBeforeWindowClosed() (gas: 620275) -TestExerciseLongPositions_CMP:testCanClearPortionPut() (gas: 425874) -TestExerciseLongPositions_CMP:testCanClearPutBeforeWindowClosed() (gas: 425939) -TestExerciseLongPositions_CMP:testCannotClearLongCallAfterWindowClosed() (gas: 323595) -TestExerciseLongPositions_CMP:testCannotClearLongPutAfterWindowClosed() (gas: 323874) -TestExerciseLongPositions_CMP:testCannotClearLongWithExceededAmount() (gas: 378270) +TestExerciseLongPositions_CMP:testCanClearLongCallAfterExpiryBeforeWindowClosed() (gas: 425851) +TestExerciseLongPositions_CMP:testCanClearLongPastExerciseWindow() (gas: 330181) +TestExerciseLongPositions_CMP:testCanClearLongPortion() (gas: 469347) +TestExerciseLongPositions_CMP:testCanClearMultipleLongCallAfterExpiryBeforeWindowClosed() (gas: 620721) +TestExerciseLongPositions_CMP:testCanClearPortionPut() (gas: 426153) +TestExerciseLongPositions_CMP:testCanClearPutBeforeWindowClosed() (gas: 426218) +TestExerciseLongPositions_CMP:testCannotClearLongCallAfterWindowClosed() (gas: 323818) +TestExerciseLongPositions_CMP:testCannotClearLongPutAfterWindowClosed() (gas: 324097) +TestExerciseLongPositions_CMP:testCannotClearLongWithExceededAmount() (gas: 378580) TestExerciseLongPositions_CMP:testForgeCoverageIgnoreThis() (gas: 208) TestExerciseLongPositions_CMP:testUtils() (gas: 167) -TestLongShortSettlement:test() (gas: 164) -TestLongShortSettlement:testForgeCoverageIgnoreThis() (gas: 208) -TestLongShortSettlement:testShortsAreSettledBeforeLongs() (gas: 590557) +TestLongShortSettlement:test() (gas: 186) +TestLongShortSettlement:testShortsAreSettledBeforeLongs() (gas: 591016) TestLongShortSettlement:testUtils() (gas: 144) -TestMintIntoAccount_CMC:test() (gas: 164) -TestMintIntoAccount_CMC:testForgeCoverageIgnoreThis() (gas: 208) -TestMintIntoAccount_CMC:testMintIntoAccountCall() (gas: 337511) +TestMintIntoAccount_CMC:test() (gas: 186) +TestMintIntoAccount_CMC:testMintIntoAccountCall() (gas: 337488) TestMintIntoAccount_CMC:testUtils() (gas: 144) TestMintIntoAccount_CMP:test() (gas: 164) TestMintIntoAccount_CMP:testForgeCoverageIgnoreThis() (gas: 208) -TestMintIntoAccount_CMP:testMintIntoAccountCall() (gas: 359277) +TestMintIntoAccount_CMP:testMintIntoAccountCall() (gas: 359291) TestMintIntoAccount_CMP:testUtils() (gas: 144) -TestMintWithPartialMarginBeta_CMC:test() (gas: 186) -TestMintWithPartialMarginBeta_CMC:testCannotMintTooLittleCollateral() (gas: 459475) -TestMintWithPartialMarginBeta_CMC:testForgeCoverageIgnoreThis() (gas: 230) -TestMintWithPartialMarginBeta_CMC:testMintCall() (gas: 280825) -TestMintWithPartialMarginBeta_CMC:testMintCallWithHigherValueCollateral() (gas: 288895) -TestMintWithPartialMarginBeta_CMC:testMintCallWithSimilarCollateral() (gas: 373847) -TestMintWithPartialMarginBeta_CMC:testMintMixedBag() (gas: 644962) -TestMintWithPartialMarginBeta_CMC:testMintMixedBagWithVariableValueCollateral() (gas: 653883) -TestMintWithPartialMarginBeta_CMC:testMintPut() (gas: 281197) +TestMintWithPartialMarginBeta_CMC:test() (gas: 208) +TestMintWithPartialMarginBeta_CMC:testCannotMintTooLittleCollateral() (gas: 459607) +TestMintWithPartialMarginBeta_CMC:testMintCall() (gas: 280869) +TestMintWithPartialMarginBeta_CMC:testMintCallWithHigherValueCollateral() (gas: 288850) +TestMintWithPartialMarginBeta_CMC:testMintCallWithSimilarCollateral() (gas: 373935) +TestMintWithPartialMarginBeta_CMC:testMintMixedBag() (gas: 645138) +TestMintWithPartialMarginBeta_CMC:testMintMixedBagWithVariableValueCollateral() (gas: 653905) +TestMintWithPartialMarginBeta_CMC:testMintPut() (gas: 281263) TestMintWithPartialMarginBeta_CMC:testMintPutWithHigherValueCollateral() (gas: 289285) -TestMintWithPartialMarginBeta_CMC:testMintPutWithSimilarCollateral() (gas: 374365) -TestMintWithPartialMarginBeta_CMC:testRemovePartialMarginMask() (gas: 106653) -TestMintWithPartialMarginBeta_CMC:testSameAssetPartialMarginMask() (gas: 24802) +TestMintWithPartialMarginBeta_CMC:testMintPutWithSimilarCollateral() (gas: 374453) +TestMintWithPartialMarginBeta_CMC:testRemovePartialMarginMask() (gas: 106675) +TestMintWithPartialMarginBeta_CMC:testSameAssetPartialMarginMask() (gas: 24824) TestMintWithPartialMarginBeta_CMC:testUtils() (gas: 167) TestMintWithPartialMarginBeta_CMP:test() (gas: 186) TestMintWithPartialMarginBeta_CMP:testCannotMintTooLittleCollateral() (gas: 506323) @@ -263,17 +268,16 @@ TestMintWithPartialMarginBeta_CMP:testMintPut() (gas: 303694) TestMintWithPartialMarginBeta_CMP:testMintPutWithHigherValueCollateral() (gas: 311717) TestMintWithPartialMarginBeta_CMP:testMintPutWithSimilarCollateral() (gas: 418297) TestMintWithPartialMarginBeta_CMP:testUtils() (gas: 167) -TestMint_CMC:test() (gas: 186) -TestMint_CMC:testCannotMintCallSpread() (gas: 128978) -TestMint_CMC:testCannotMintCallWithLittleCollateral() (gas: 267257) +TestMint_CMC:test() (gas: 208) +TestMint_CMC:testCannotMintCallSpread() (gas: 129000) +TestMint_CMC:testCannotMintCallWithLittleCollateral() (gas: 267234) TestMint_CMC:testCannotMintExpiredOption() (gas: 110523) -TestMint_CMC:testCannotMintPutSpread() (gas: 128959) -TestMint_CMC:testCannotMintPutWithLittleCollateral() (gas: 265386) -TestMint_CMC:testCannotMintWithoutCollateral() (gas: 176683) -TestMint_CMC:testForgeCoverageIgnoreThis() (gas: 230) -TestMint_CMC:testMintCall() (gas: 268854) -TestMint_CMC:testMintCallAndPutInSameAccount() (gas: 448330) -TestMint_CMC:testMintPut() (gas: 269200) +TestMint_CMC:testCannotMintPutSpread() (gas: 128981) +TestMint_CMC:testCannotMintPutWithLittleCollateral() (gas: 265363) +TestMint_CMC:testCannotMintWithoutCollateral() (gas: 176705) +TestMint_CMC:testMintCall() (gas: 268876) +TestMint_CMC:testMintCallAndPutInSameAccount() (gas: 448309) +TestMint_CMC:testMintPut() (gas: 269222) TestMint_CMC:testUtils() (gas: 167) TestMint_CMP:test() (gas: 186) TestMint_CMP:testCannotMintCallWithLittleCollateral() (gas: 290285) @@ -285,47 +289,42 @@ TestMint_CMP:testMintCall() (gas: 290498) TestMint_CMP:testMintCallAndPutInSameAccount() (gas: 494310) TestMint_CMP:testMintPut() (gas: 290767) TestMint_CMP:testUtils() (gas: 167) -TestPMRemoveCollateral_CMC:test() (gas: 164) -TestPMRemoveCollateral_CMC:testEqualCallSpreadCollateralWithdraw() (gas: 714646) -TestPMRemoveCollateral_CMC:testEqualPutSpreadCollateralWithdraw() (gas: 710291) -TestPMRemoveCollateral_CMC:testEqualShortLongAllowCollateralWithdraw() (gas: 637934) -TestPMRemoveCollateral_CMC:testForgeCoverageIgnoreThis() (gas: 208) -TestPMRemoveCollateral_CMC:testUtils() (gas: 167) +TestPMRemoveCollateral_CMC:test() (gas: 186) +TestPMRemoveCollateral_CMC:testEqualCallSpreadCollateralWithdraw() (gas: 714890) +TestPMRemoveCollateral_CMC:testEqualPutSpreadCollateralWithdraw() (gas: 710600) +TestPMRemoveCollateral_CMC:testEqualShortLongAllowCollateralWithdraw() (gas: 638243) +TestPMRemoveCollateral_CMC:testUtils() (gas: 144) TestPMRemoveCollateral_CMP:test() (gas: 164) -TestPMRemoveCollateral_CMP:testEqualCallSpreadCollateralWithdraw() (gas: 754166) -TestPMRemoveCollateral_CMP:testEqualPutSpreadCollateralWithdraw() (gas: 749676) -TestPMRemoveCollateral_CMP:testEqualShortLongAllowCollateralWithdraw() (gas: 653963) +TestPMRemoveCollateral_CMP:testEqualCallSpreadCollateralWithdraw() (gas: 754529) +TestPMRemoveCollateral_CMP:testEqualPutSpreadCollateralWithdraw() (gas: 750039) +TestPMRemoveCollateral_CMP:testEqualShortLongAllowCollateralWithdraw() (gas: 654340) TestPMRemoveCollateral_CMP:testForgeCoverageIgnoreThis() (gas: 208) TestPMRemoveCollateral_CMP:testUtils() (gas: 167) -TestPMSettleLongCalls_CMC:test() (gas: 164) -TestPMSettleLongCalls_CMC:testForgeCoverageIgnoreThis() (gas: 230) -TestPMSettleLongCalls_CMC:testSettleLongCallITMIncreasesCollateral() (gas: 172909) -TestPMSettleLongCalls_CMC:testSettleLongCallOTMNoIncreaseInCollateral() (gas: 122571) -TestPMSettleLongCalls_CMC:testSettleMultipleLongCallsITMIncreasesCollateral() (gas: 357923) -TestPMSettleLongCalls_CMC:testSettleMultipleLongCallsOTMNoIncreaseInCollateral() (gas: 315760) -TestPMSettleLongCalls_CMC:testSettleOnlyExpiredLongCallOTMNoIncreaseInCollateral() (gas: 328334) +TestPMSettleLongCalls_CMC:test() (gas: 186) +TestPMSettleLongCalls_CMC:testSettleLongCallITMIncreasesCollateral() (gas: 173218) +TestPMSettleLongCalls_CMC:testSettleLongCallOTMNoIncreaseInCollateral() (gas: 122880) +TestPMSettleLongCalls_CMC:testSettleMultipleLongCallsITMIncreasesCollateral() (gas: 358209) +TestPMSettleLongCalls_CMC:testSettleMultipleLongCallsOTMNoIncreaseInCollateral() (gas: 316007) +TestPMSettleLongCalls_CMC:testSettleOnlyExpiredLongCallOTMNoIncreaseInCollateral() (gas: 328665) TestPMSettleLongCalls_CMC:testUtils() (gas: 167) -TestPMSettleLongPutsCM:test() (gas: 164) -TestPMSettleLongPutsCM:testForgeCoverageIgnoreThis() (gas: 208) -TestPMSettleLongPutsCM:testSettleLongCallITMIncreasesCollateral() (gas: 172375) -TestPMSettleLongPutsCM:testSettleLongCallOTMNoIncreaseInCollateral() (gas: 122059) +TestPMSettleLongPutsCM:test() (gas: 186) +TestPMSettleLongPutsCM:testSettleLongCallITMIncreasesCollateral() (gas: 172684) +TestPMSettleLongPutsCM:testSettleLongCallOTMNoIncreaseInCollateral() (gas: 122368) TestPMSettleLongPutsCM:testUtils() (gas: 167) -TestPMSettleLongStrangleSpreadCM:test() (gas: 164) -TestPMSettleLongStrangleSpreadCM:testForgeCoverageIgnoreThis() (gas: 208) -TestPMSettleLongStrangleSpreadCM:testSettleLongCallInnerITM() (gas: 335179) -TestPMSettleLongStrangleSpreadCM:testSettleLongCallOuterITM() (gas: 341088) -TestPMSettleLongStrangleSpreadCM:testSettleLongPutInnerITM() (gas: 333156) -TestPMSettleLongStrangleSpreadCM:testSettleLongPutOuterITM() (gas: 341106) -TestPMSettleLongStrangleSpreadCM:testSettleShortPutOTM() (gas: 290853) +TestPMSettleLongStrangleSpreadCM:test() (gas: 186) +TestPMSettleLongStrangleSpreadCM:testSettleLongCallInnerITM() (gas: 335563) +TestPMSettleLongStrangleSpreadCM:testSettleLongCallOuterITM() (gas: 341472) +TestPMSettleLongStrangleSpreadCM:testSettleLongPutInnerITM() (gas: 333540) +TestPMSettleLongStrangleSpreadCM:testSettleLongPutOuterITM() (gas: 341490) +TestPMSettleLongStrangleSpreadCM:testSettleShortPutOTM() (gas: 291184) TestPMSettleLongStrangleSpreadCM:testUtils() (gas: 167) -TestRemoveCollateral_CMC:test() (gas: 164) +TestRemoveCollateral_CMC:test() (gas: 186) TestRemoveCollateral_CMC:testCannotRemoveDifferentCollateral() (gas: 36241) TestRemoveCollateral_CMC:testCannotRemoveMoreThanOwn() (gas: 36899) -TestRemoveCollateral_CMC:testForgeCoverageIgnoreThis() (gas: 208) -TestRemoveCollateral_CMC:testMultipleCollateralsAddRemove() (gas: 288420) -TestRemoveCollateral_CMC:testRemoveCollateralChangeStorage() (gas: 61671) -TestRemoveCollateral_CMC:testRemoveCollateralMoveBalance() (gas: 64255) -TestRemoveCollateral_CMC:testRemoveCollateralRetainBalances() (gas: 118455) +TestRemoveCollateral_CMC:testMultipleCollateralsAddRemove() (gas: 288442) +TestRemoveCollateral_CMC:testRemoveCollateralChangeStorage() (gas: 61626) +TestRemoveCollateral_CMC:testRemoveCollateralMoveBalance() (gas: 64277) +TestRemoveCollateral_CMC:testRemoveCollateralRetainBalances() (gas: 118411) TestRemoveCollateral_CMC:testUtils() (gas: 167) TestRemoveCollateral_CMP:test() (gas: 164) TestRemoveCollateral_CMP:testCannotRemoveDifferentCollateral() (gas: 36284) @@ -336,66 +335,62 @@ TestRemoveCollateral_CMP:testRemoveCollateralChangeStorage() (gas: 61708) TestRemoveCollateral_CMP:testRemoveCollateralMoveBalance() (gas: 64269) TestRemoveCollateral_CMP:testRemoveCollateralRetainBalances() (gas: 118463) TestRemoveCollateral_CMP:testUtils() (gas: 167) -TestRemoveLong_CMC:test() (gas: 164) -TestRemoveLong_CMC:testForgeCoverageIgnoreThis() (gas: 208) -TestRemoveLong_CMC:testRemoveLongToken() (gas: 386405) +TestRemoveLong_CMC:test() (gas: 186) +TestRemoveLong_CMC:testRemoveLongToken() (gas: 386882) TestRemoveLong_CMC:testUtils() (gas: 144) TestRemoveLong_CMP:test() (gas: 164) TestRemoveLong_CMP:testForgeCoverageIgnoreThis() (gas: 208) -TestRemoveLong_CMP:testRemoveLongToken() (gas: 401568) +TestRemoveLong_CMP:testRemoveLongToken() (gas: 402084) TestRemoveLong_CMP:testUtils() (gas: 144) -TestSettleCollateralizedPut_CMC:test() (gas: 164) -TestSettleCollateralizedPut_CMC:testForgeCoverageIgnoreThis() (gas: 208) -TestSettleCollateralizedPut_CMC:testSellerCanClearOnlyExpiredOptions() (gas: 269915) -TestSettleCollateralizedPut_CMC:testSellerCollateralIsReducedIfExpiresITM() (gas: 113052) -TestSettleCollateralizedPut_CMC:testShouldGetNothingIfExpiresOTM() (gas: 103329) -TestSettleCollateralizedPut_CMC:testShouldGetPayoutIfExpiresIMT() (gas: 109066) +TestSettleCollateralizedPut_CMC:test() (gas: 186) +TestSettleCollateralizedPut_CMC:testSellerCanClearOnlyExpiredOptions() (gas: 270224) +TestSettleCollateralizedPut_CMC:testSellerCollateralIsReducedIfExpiresITM() (gas: 113361) +TestSettleCollateralizedPut_CMC:testShouldGetNothingIfExpiresOTM() (gas: 103283) +TestSettleCollateralizedPut_CMC:testShouldGetPayoutIfExpiresIMT() (gas: 109065) TestSettleCollateralizedPut_CMC:testUtils() (gas: 167) TestSettleCollateralizedPut_CMP:test() (gas: 164) TestSettleCollateralizedPut_CMP:testForgeCoverageIgnoreThis() (gas: 208) -TestSettleCollateralizedPut_CMP:testShouldGetPutPayoutAndDeductedDebt() (gas: 195438) -TestSettleCollateralizedPut_CMP:testShouldGetPutPayoutAndDeductedDebtFromSender() (gas: 219401) +TestSettleCollateralizedPut_CMP:testShouldGetPutPayoutAndDeductedDebt() (gas: 195407) +TestSettleCollateralizedPut_CMP:testShouldGetPutPayoutAndDeductedDebtFromSender() (gas: 219370) TestSettleCollateralizedPut_CMP:testUtils() (gas: 167) -TestSettleCoveredCall_CMC:test() (gas: 164) -TestSettleCoveredCall_CMC:testForgeCoverageIgnoreThis() (gas: 208) -TestSettleCoveredCall_CMC:testSellerCanClearDebtIfExpiresOTM() (gas: 106605) -TestSettleCoveredCall_CMC:testSellerCanClearMultipleExpiredOptions() (gas: 249113) -TestSettleCoveredCall_CMC:testSellerCanClearOnlyExpiredOptions() (gas: 273090) -TestSettleCoveredCall_CMC:testSellerCollateralIsReducedIfExpiresITM() (gas: 114153) -TestSettleCoveredCall_CMC:testShouldGetNothingIfExpiresOTM() (gas: 103854) -TestSettleCoveredCall_CMC:testShouldGetPayoutIfExpiresIMT() (gas: 127324) +TestSettleCoveredCall_CMC:test() (gas: 186) +TestSettleCoveredCall_CMC:testSellerCanClearDebtIfExpiresOTM() (gas: 106870) +TestSettleCoveredCall_CMC:testSellerCanClearMultipleExpiredOptions() (gas: 249399) +TestSettleCoveredCall_CMC:testSellerCanClearOnlyExpiredOptions() (gas: 273399) +TestSettleCoveredCall_CMC:testSellerCollateralIsReducedIfExpiresITM() (gas: 114484) +TestSettleCoveredCall_CMC:testShouldGetNothingIfExpiresOTM() (gas: 103808) +TestSettleCoveredCall_CMC:testShouldGetPayoutIfExpiresIMT() (gas: 127278) TestSettleCoveredCall_CMC:testUtils() (gas: 189) TestSettleCoveredCall_CMP:test() (gas: 164) TestSettleCoveredCall_CMP:testForgeCoverageIgnoreThis() (gas: 208) -TestSettleCoveredCall_CMP:testShouldGetCallPayoutAndDeductedDebt() (gas: 178268) -TestSettleCoveredCall_CMP:testShouldGetCallPayoutAndDeductedDebtFromSender() (gas: 219422) +TestSettleCoveredCall_CMP:testShouldGetCallPayoutAndDeductedDebt() (gas: 178237) +TestSettleCoveredCall_CMP:testShouldGetCallPayoutAndDeductedDebtFromSender() (gas: 219391) TestSettleCoveredCall_CMP:testUtils() (gas: 167) -TestSettleOptionPartialMargin_CMC:test() (gas: 164) -TestSettleOptionPartialMargin_CMC:testCallITM() (gas: 336109) -TestSettleOptionPartialMargin_CMC:testForgeCoverageIgnoreThis() (gas: 208) -TestSettleOptionPartialMargin_CMC:testPutITM() (gas: 333289) +TestSettleOptionPartialMargin_CMC:test() (gas: 186) +TestSettleOptionPartialMargin_CMC:testCallITM() (gas: 336415) +TestSettleOptionPartialMargin_CMC:testPutITM() (gas: 333595) TestSettleOptionPartialMargin_CMC:testUtils() (gas: 144) TestSettleOptionPartialMargin_CMP:test() (gas: 164) -TestSettleOptionPartialMargin_CMP:testCall() (gas: 404720) +TestSettleOptionPartialMargin_CMP:testCall() (gas: 404968) TestSettleOptionPartialMargin_CMP:testForgeCoverageIgnoreThis() (gas: 208) -TestSettleOptionPartialMargin_CMP:testPut() (gas: 428080) +TestSettleOptionPartialMargin_CMP:testPut() (gas: 428328) TestSettleOptionPartialMargin_CMP:testUtils() (gas: 167) TestSettleOption_CMP:test() (gas: 164) TestSettleOption_CMP:testForgeCoverageIgnoreThis() (gas: 208) -TestSettleOption_CMP:testGetsNothingFromOptionPastExerciseWindow() (gas: 59087) +TestSettleOption_CMP:testGetsNothingFromOptionPastExerciseWindow() (gas: 59025) TestSettleOption_CMP:testUtils() (gas: 144) TestSettleShortPositions_CMP:test() (gas: 164) TestSettleShortPositions_CMP:testForgeCoverageIgnoreThis() (gas: 208) -TestSettleShortPositions_CMP:testSellerCanClearCallDebtAfterWindowClosed() (gas: 267878) -TestSettleShortPositions_CMP:testSellerCanClearPartialCallDebtAfterWindowClosed() (gas: 419174) -TestSettleShortPositions_CMP:testSellerCanClearPartialPutDebtAfterWindowClosed() (gas: 419542) -TestSettleShortPositions_CMP:testSellerCanClearPutDebtAfterWindowClosed() (gas: 268126) -TestSettleShortPositions_CMP:testSellerCannotClearCallDebtAfterExpiryBeforeWindowClosed() (gas: 339636) -TestSettleShortPositions_CMP:testSellerCannotClearPutDebtAfterExpiryBeforeWindowClosed() (gas: 340154) +TestSettleShortPositions_CMP:testSellerCanClearCallDebtAfterWindowClosed() (gas: 268157) +TestSettleShortPositions_CMP:testSellerCanClearPartialCallDebtAfterWindowClosed() (gas: 419422) +TestSettleShortPositions_CMP:testSellerCanClearPartialPutDebtAfterWindowClosed() (gas: 419790) +TestSettleShortPositions_CMP:testSellerCanClearPutDebtAfterWindowClosed() (gas: 268405) +TestSettleShortPositions_CMP:testSellerCannotClearCallDebtAfterExpiryBeforeWindowClosed() (gas: 339946) +TestSettleShortPositions_CMP:testSellerCannotClearPutDebtAfterExpiryBeforeWindowClosed() (gas: 340464) TestSettleShortPositions_CMP:testUtils() (gas: 167) TestSettleSocializedLosses_CMP:test() (gas: 164) TestSettleSocializedLosses_CMP:testForgeCoverageIgnoreThis() (gas: 208) -TestSettleSocializedLosses_CMP:testSocializeLoss() (gas: 540229) +TestSettleSocializedLosses_CMP:testSocializeLoss() (gas: 540756) TestSettleSocializedLosses_CMP:testUtils() (gas: 144) TestStrangles_CMCM:testLongStrangle() (gas: 44468) TestStrangles_CMCM:testShortStrangles() (gas: 38483) @@ -439,21 +434,20 @@ TestStructures_CMPM:testMarginUnsortedStrikes() (gas: 141178) TestStructures_CMPM:testVerifyInputs2() (gas: 45961) TestStructures_CMPM:testVerifyInputs3() (gas: 74469) TestStructures_CMPM:testVerifyInputs4() (gas: 55744) -TestTransfer_CMC:test() (gas: 186) -TestTransfer_CMC:testCannotTransferCollateralWhenShortExists() (gas: 122620) -TestTransfer_CMC:testCannotTransferLongWhenTooLittleCollateral() (gas: 174998) -TestTransfer_CMC:testCannotTransferShortWhenReceiverHasTooLittleCollateral() (gas: 170659) -TestTransfer_CMC:testCannotTransferShortWithNoAccess() (gas: 33910) -TestTransfer_CMC:testForgeCoverageIgnoreThis() (gas: 230) -TestTransfer_CMC:testTransferCollateral() (gas: 262246) +TestTransfer_CMC:test() (gas: 208) +TestTransfer_CMC:testCannotTransferCollateralWhenShortExists() (gas: 122930) +TestTransfer_CMC:testCannotTransferLongWhenTooLittleCollateral() (gas: 175330) +TestTransfer_CMC:testCannotTransferShortWhenReceiverHasTooLittleCollateral() (gas: 170991) +TestTransfer_CMC:testCannotTransferShortWithNoAccess() (gas: 34220) +TestTransfer_CMC:testTransferCollateral() (gas: 263198) TestTransfer_CMC:testUtils() (gas: 189) TestTransfer_CMP:test() (gas: 186) -TestTransfer_CMP:testCannotTransferCollateralWhenShortExists() (gas: 119417) -TestTransfer_CMP:testCannotTransferLongWhenTooLittleCollateral() (gas: 171614) -TestTransfer_CMP:testCannotTransferShortWhenReceiverHasTooLittleCollateral() (gas: 167507) -TestTransfer_CMP:testCannotTransferShortWithNoAccess() (gas: 33953) +TestTransfer_CMP:testCannotTransferCollateralWhenShortExists() (gas: 119741) +TestTransfer_CMP:testCannotTransferLongWhenTooLittleCollateral() (gas: 171924) +TestTransfer_CMP:testCannotTransferShortWhenReceiverHasTooLittleCollateral() (gas: 167817) +TestTransfer_CMP:testCannotTransferShortWithNoAccess() (gas: 34263) TestTransfer_CMP:testForgeCoverageIgnoreThis() (gas: 230) -TestTransfer_CMP:testTransferCollateral() (gas: 259297) +TestTransfer_CMP:testTransferCollateral() (gas: 260241) TestTransfer_CMP:testUtils() (gas: 189) TestVanillaCall_CMM:testMarginRequirementVanillaCall1() (gas: 25527) TestVanillaCall_CMPM:testMarginRequirementVanillaCall1() (gas: 25527) diff --git a/src/settled-cash/AccountCashEngine.sol b/src/settled-cash/AccountCashEngine.sol index e7eb814..e5e859e 100644 --- a/src/settled-cash/AccountCashEngine.sol +++ b/src/settled-cash/AccountCashEngine.sol @@ -101,7 +101,6 @@ abstract contract AccountCashEngine is BaseEngine { * @param _data bytes data to decode */ function _burnOptionFromAccount(address _subAccount, bytes calldata _data) internal virtual { - // decode parameters // decode parameters (uint256 tokenId, address from, uint64 amount) = abi.decode(_data, (uint256, address, uint64)); diff --git a/src/settled-cash/CrossMarginCashEngine.sol b/src/settled-cash/CrossMarginCashEngine.sol index 3a61fac..2f65066 100644 --- a/src/settled-cash/CrossMarginCashEngine.sol +++ b/src/settled-cash/CrossMarginCashEngine.sol @@ -27,8 +27,6 @@ import {AccountUtil} from "../libraries/AccountUtil.sol"; import {CrossMarginCashMath} from "./CrossMarginCashMath.sol"; import {CrossMarginCashLib} from "./CrossMarginCashLib.sol"; - - // Cross margin types import "./types.sol"; import "../config/errors.sol"; diff --git a/src/settled-physical/AccountPhysicalEngine.sol b/src/settled-physical/AccountPhysicalEngine.sol index 70af06e..bcf3837 100644 --- a/src/settled-physical/AccountPhysicalEngine.sol +++ b/src/settled-physical/AccountPhysicalEngine.sol @@ -101,7 +101,6 @@ abstract contract AccountPhysicalEngine is BaseEngine { * @param _data bytes data to decode */ function _burnOptionFromAccount(address _subAccount, bytes calldata _data) internal virtual { - // decode parameters // decode parameters (uint256 tokenId, address from, uint64 amount) = abi.decode(_data, (uint256, address, uint64)); @@ -111,6 +110,8 @@ abstract contract AccountPhysicalEngine is BaseEngine { // update the account in state _decreaseLongInAccount(from, tokenId, amount); + emit PhysicalOptionTokenBurned(from, tokenId, amount); + // update the account in state _decreaseShortInAccount(_subAccount, tokenId, amount); diff --git a/test/integrations-cash/BurnToken.t.sol b/test/integrations-cash/BurnToken.t.sol index 8e16ed7..0909d5e 100644 --- a/test/integrations-cash/BurnToken.t.sol +++ b/test/integrations-cash/BurnToken.t.sol @@ -21,6 +21,8 @@ contract TestBurnOption_CMC is CrossMarginCashFixture { uint256 public amount = 1 * UNIT; uint256 public tokenId; + event CashOptionTokenBurned(address subAccount, uint256 tokenId, uint256 amount); + function setUp() public { weth.mint(address(this), depositAmount); weth.approve(address(engine), type(uint256).max); @@ -43,6 +45,9 @@ contract TestBurnOption_CMC is CrossMarginCashFixture { ActionArgs[] memory actions = new ActionArgs[](1); actions[0] = createBurnAction(tokenId, address(this), amount); + vm.expectEmit(true, true, true, true); + emit CashOptionTokenBurned(address(this), tokenId, amount); + // action engine.execute(address(this), actions); (Position[] memory shorts,,) = engine.marginAccounts(address(this)); @@ -105,3 +110,159 @@ contract TestBurnOption_CMC is CrossMarginCashFixture { engine.execute(address(this), actions); } } + +// solhint-disable-next-line contract-name-camelcase +contract TestBurnOptionFromAccount_CMC is CrossMarginCashFixture { + uint256 public depositAmount = 1 ether; + uint256 public amount = 1 * UNIT; + uint256 public tokenId; + + event CashOptionTokenBurned(address subAccount, uint256 tokenId, uint256 amount); + + function setUp() public { + weth.mint(address(this), 1 * 1e18); + weth.approve(address(engine), type(uint256).max); + + weth.mint(alice, 1 * 1e18); + + vm.startPrank(alice); + weth.approve(address(engine), type(uint256).max); + engine.setAccountAccess(address(this), type(uint256).max); + vm.stopPrank(); + + oracle.setSpotPrice(address(weth), 1900 * UNIT); + + tokenId = getTokenId(TokenType.CALL, pidEthCollat, block.timestamp + 1 days, 4000 * 1e6, 0); + + ActionArgs[] memory actions = new ActionArgs[](2); + actions[0] = createAddCollateralAction(wethId, alice, depositAmount); + actions[1] = createMintIntoAccountAction(tokenId, address(this), amount); + engine.execute(alice, actions); + + option.setApprovalForAll(address(engine), true); + } + + function testBurnFromAccount() public { + Position[] memory shorts; + Position[] memory longs; + + (shorts, longs,) = engine.marginAccounts(address(this)); + + assertEq(shorts.length, 0); + assertEq(longs.length, 1); + assertEq(longs[0].tokenId, tokenId); + + (shorts, longs,) = engine.marginAccounts(alice); + + assertEq(shorts.length, 1); + assertEq(shorts[0].tokenId, tokenId); + assertEq(longs.length, 0); + + ActionArgs[] memory actions = new ActionArgs[](1); + actions[0] = ActionArgs({action: ActionType.BurnShortInAccount, data: abi.encode(tokenId, address(this), uint64(amount))}); + + // decreases longs + vm.expectEmit(true, true, true, true); + emit CashOptionTokenBurned(address(this), tokenId, amount); + + // decreases shorts + vm.expectEmit(true, true, true, true); + emit CashOptionTokenBurned(alice, tokenId, amount); + + engine.execute(alice, actions); + + (shorts, longs,) = engine.marginAccounts(address(this)); + + assertEq(shorts.length, 0); + assertEq(longs.length, 0); + + (shorts, longs,) = engine.marginAccounts(alice); + + assertEq(shorts.length, 0); + assertEq(longs.length, 0); + } + + function testCanBurnFromSubAccount() public { + address subAccount = address(uint160(address(this)) ^ uint160(1)); + + ActionArgs[] memory actions = new ActionArgs[](1); + actions[0] = createAddCollateralAction(wethId, address(this), depositAmount); + engine.execute(subAccount, actions); + + actions[0] = createTransferShortAction(tokenId, subAccount, amount); + engine.execute(alice, actions); + + Position[] memory shorts; + Position[] memory longs; + + (shorts, longs,) = engine.marginAccounts(address(this)); + + assertEq(shorts.length, 0); + assertEq(longs.length, 1); + assertEq(longs[0].tokenId, tokenId); + + (shorts, longs,) = engine.marginAccounts(subAccount); + + assertEq(shorts.length, 1); + assertEq(shorts[0].tokenId, tokenId); + assertEq(longs.length, 0); + + (shorts, longs,) = engine.marginAccounts(alice); + + assertEq(shorts.length, 0); + assertEq(longs.length, 0); + + actions[0] = ActionArgs({action: ActionType.BurnShortInAccount, data: abi.encode(tokenId, address(this), uint64(amount))}); + + // decreases longs + vm.expectEmit(true, true, true, true); + emit CashOptionTokenBurned(address(this), tokenId, amount); + + // decreases shorts + vm.expectEmit(true, true, true, true); + emit CashOptionTokenBurned(subAccount, tokenId, amount); + + engine.execute(subAccount, actions); + } + + function testCannotBurnFromEmptySubAccount() public { + address subAccount = address(uint160(address(this)) ^ uint160(1)); + + ActionArgs[] memory actions = new ActionArgs[](1); + actions[0] = ActionArgs({action: ActionType.BurnShortInAccount, data: abi.encode(tokenId, address(this), uint64(amount))}); + + vm.expectRevert(CM_InvalidToken.selector); + engine.execute(subAccount, actions); + } + + function testCannotBurnFromWithWrongTokenId() public { + uint256 badTokenId = getTokenId(TokenType.CALL, pidUsdcCollat, block.timestamp + 1 days, 4000 * 1e6, 0); + + ActionArgs[] memory actions = new ActionArgs[](1); + actions[0] = + ActionArgs({action: ActionType.BurnShortInAccount, data: abi.encode(badTokenId, address(this), uint64(amount))}); + + vm.expectRevert(CM_InvalidToken.selector); + engine.execute(alice, actions); + } + + function testCannotBurnWhenOptionTokenBalanceIsLow() public { + vm.prank(address(engine)); + option.safeTransferFrom(address(engine), address(this), tokenId, 1, ""); + + ActionArgs[] memory actions = new ActionArgs[](1); + actions[0] = ActionArgs({action: ActionType.BurnShortInAccount, data: abi.encode(tokenId, address(this), uint64(amount))}); + + vm.expectRevert(stdError.arithmeticError); + engine.execute(alice, actions); + } + + function testCannotBurnFromUnAuthorizedAccount() public { + ActionArgs[] memory actions = new ActionArgs[](1); + actions[0] = ActionArgs({action: ActionType.BurnShortInAccount, data: abi.encode(tokenId, alice, uint64(amount))}); + + // expect error + vm.expectRevert(BM_InvalidFromAddress.selector); + engine.execute(address(this), actions); + } +} diff --git a/test/integrations-physical/BurnToken.t.sol b/test/integrations-physical/BurnToken.t.sol index 896783a..7d663f9 100644 --- a/test/integrations-physical/BurnToken.t.sol +++ b/test/integrations-physical/BurnToken.t.sol @@ -22,6 +22,8 @@ contract TestBurnOption_CMP is CrossMarginPhysicalFixture { uint256 public amount = 1 * UNIT; uint256 public tokenId; + event PhysicalOptionTokenBurned(address subAccount, uint256 tokenId, uint256 amount); + function setUp() public { weth.mint(address(this), depositAmount); weth.approve(address(engine), type(uint256).max); @@ -42,6 +44,9 @@ contract TestBurnOption_CMP is CrossMarginPhysicalFixture { ActionArgs[] memory actions = new ActionArgs[](1); actions[0] = createBurnAction(tokenId, address(this), amount); + vm.expectEmit(true, true, true, true); + emit PhysicalOptionTokenBurned(address(this), tokenId, amount); + // action engine.execute(address(this), actions); (Position[] memory shorts,,) = engine.marginAccounts(address(this)); @@ -104,3 +109,159 @@ contract TestBurnOption_CMP is CrossMarginPhysicalFixture { engine.execute(address(this), actions); } } + +// solhint-disable-next-line contract-name-camelcase +contract TestBurnOptionFromAccount_CMP is CrossMarginPhysicalFixture { + uint256 public depositAmount = 1 ether; + uint256 public amount = 1 * UNIT; + uint256 public tokenId; + + event PhysicalOptionTokenBurned(address subAccount, uint256 tokenId, uint256 amount); + + function setUp() public { + weth.mint(address(this), 1 * 1e18); + weth.approve(address(engine), type(uint256).max); + + weth.mint(alice, 1 * 1e18); + + vm.startPrank(alice); + weth.approve(address(engine), type(uint256).max); + engine.setAccountAccess(address(this), type(uint256).max); + vm.stopPrank(); + + oracle.setSpotPrice(address(weth), 1900 * UNIT); + + tokenId = getTokenId(TokenType.CALL, pidEthCollat, block.timestamp + 1 days, 4000 * 1e6, 30 minutes); + + ActionArgs[] memory actions = new ActionArgs[](2); + actions[0] = createAddCollateralAction(wethId, alice, depositAmount); + actions[1] = createMintIntoAccountAction(tokenId, address(this), amount); + engine.execute(alice, actions); + + option.setApprovalForAll(address(engine), true); + } + + function testBurnFromAccount() public { + Position[] memory shorts; + Position[] memory longs; + + (shorts, longs,) = engine.marginAccounts(address(this)); + + assertEq(shorts.length, 0); + assertEq(longs.length, 1); + assertEq(longs[0].tokenId, tokenId); + + (shorts, longs,) = engine.marginAccounts(alice); + + assertEq(shorts.length, 1); + assertEq(shorts[0].tokenId, tokenId); + assertEq(longs.length, 0); + + ActionArgs[] memory actions = new ActionArgs[](1); + actions[0] = ActionArgs({action: ActionType.BurnShortInAccount, data: abi.encode(tokenId, address(this), uint64(amount))}); + + // decreases longs + vm.expectEmit(true, true, true, true); + emit PhysicalOptionTokenBurned(address(this), tokenId, amount); + + // decreases shorts + vm.expectEmit(true, true, true, true); + emit PhysicalOptionTokenBurned(alice, tokenId, amount); + + engine.execute(alice, actions); + + (shorts, longs,) = engine.marginAccounts(address(this)); + + assertEq(shorts.length, 0); + assertEq(longs.length, 0); + + (shorts, longs,) = engine.marginAccounts(alice); + + assertEq(shorts.length, 0); + assertEq(longs.length, 0); + } + + function testCanBurnFromSubAccount() public { + address subAccount = address(uint160(address(this)) ^ uint160(1)); + + ActionArgs[] memory actions = new ActionArgs[](1); + actions[0] = createAddCollateralAction(wethId, address(this), depositAmount); + engine.execute(subAccount, actions); + + actions[0] = createTransferShortAction(tokenId, subAccount, amount); + engine.execute(alice, actions); + + Position[] memory shorts; + Position[] memory longs; + + (shorts, longs,) = engine.marginAccounts(address(this)); + + assertEq(shorts.length, 0); + assertEq(longs.length, 1); + assertEq(longs[0].tokenId, tokenId); + + (shorts, longs,) = engine.marginAccounts(subAccount); + + assertEq(shorts.length, 1); + assertEq(shorts[0].tokenId, tokenId); + assertEq(longs.length, 0); + + (shorts, longs,) = engine.marginAccounts(alice); + + assertEq(shorts.length, 0); + assertEq(longs.length, 0); + + actions[0] = ActionArgs({action: ActionType.BurnShortInAccount, data: abi.encode(tokenId, address(this), uint64(amount))}); + + // decreases longs + vm.expectEmit(true, true, true, true); + emit PhysicalOptionTokenBurned(address(this), tokenId, amount); + + // decreases shorts + vm.expectEmit(true, true, true, true); + emit PhysicalOptionTokenBurned(subAccount, tokenId, amount); + + engine.execute(subAccount, actions); + } + + function testCannotBurnFromEmptySubAccount() public { + address subAccount = address(uint160(address(this)) ^ uint160(1)); + + ActionArgs[] memory actions = new ActionArgs[](1); + actions[0] = ActionArgs({action: ActionType.BurnShortInAccount, data: abi.encode(tokenId, address(this), uint64(amount))}); + + vm.expectRevert(CM_InvalidToken.selector); + engine.execute(subAccount, actions); + } + + function testCannotBurnFromWithWrongTokenId() public { + uint256 badTokenId = getTokenId(TokenType.CALL, pidUsdcCollat, block.timestamp + 1 days, 4000 * 1e6, 30 minutes); + + ActionArgs[] memory actions = new ActionArgs[](1); + actions[0] = + ActionArgs({action: ActionType.BurnShortInAccount, data: abi.encode(badTokenId, address(this), uint64(amount))}); + + vm.expectRevert(CM_InvalidToken.selector); + engine.execute(alice, actions); + } + + function testCannotBurnWhenOptionTokenBalanceIsLow() public { + vm.prank(address(engine)); + option.safeTransferFrom(address(engine), address(this), tokenId, 1, ""); + + ActionArgs[] memory actions = new ActionArgs[](1); + actions[0] = ActionArgs({action: ActionType.BurnShortInAccount, data: abi.encode(tokenId, address(this), uint64(amount))}); + + vm.expectRevert(stdError.arithmeticError); + engine.execute(alice, actions); + } + + function testCannotBurnFromUnAuthorizedAccount() public { + ActionArgs[] memory actions = new ActionArgs[](1); + actions[0] = ActionArgs({action: ActionType.BurnShortInAccount, data: abi.encode(tokenId, alice, uint64(amount))}); + + // expect error + vm.expectRevert(BM_InvalidFromAddress.selector); + engine.execute(address(this), actions); + } +}