From de61f094435803ba3acb0a26e21b5e5c0547acb3 Mon Sep 17 00:00:00 2001 From: 0xRizwan Date: Tue, 13 Feb 2024 17:11:47 +0530 Subject: [PATCH 1/4] gas optimization --- packages/contracts/.gas-snapshot | 344 ++++++++++++++++++ .../contracts/src/dollar/core/CreditNft.sol | 14 +- .../src/dollar/core/ERC1155Ubiquity.sol | 43 ++- .../src/dollar/core/ERC20Ubiquity.sol | 12 +- .../src/dollar/core/StakingShare.sol | 22 +- .../src/dollar/core/UbiquityCreditToken.sol | 12 +- .../src/dollar/core/UbiquityDollarToken.sol | 12 +- .../dollar/core/UbiquityGovernanceToken.sol | 12 +- .../src/dollar/facets/DiamondLoupeFacet.sol | 4 +- .../src/dollar/facets/OwnershipFacet.sol | 2 +- .../src/dollar/libraries/Constants.sol | 2 +- .../src/dollar/libraries/LibAppStorage.sol | 72 +++- .../src/dollar/libraries/LibChef.sol | 5 +- .../src/dollar/libraries/LibDiamond.sol | 16 +- .../libraries/LibDirectGovernanceFarmer.sol | 6 +- .../src/dollar/libraries/LibUbiquityPool.sol | 29 +- .../src/dollar/libraries/UintUtils.sol | 2 +- .../src/dollar/utils/SafeAddArray.sol | 10 +- .../contracts/src/ubiquistick/SimpleBond.sol | 28 +- .../contracts/src/ubiquistick/UbiquiStick.sol | 11 +- .../src/ubiquistick/UbiquiStickSale.sol | 17 +- .../test/diamond/facets/OwnershipFacet.t.sol | 2 +- .../test/dollar/core/CreditNft.t.sol | 4 +- .../test/ubiquistick/UbiquiStickSale.t.sol | 6 +- 24 files changed, 601 insertions(+), 86 deletions(-) create mode 100644 packages/contracts/.gas-snapshot diff --git a/packages/contracts/.gas-snapshot b/packages/contracts/.gas-snapshot new file mode 100644 index 000000000..aa0e9b2d2 --- /dev/null +++ b/packages/contracts/.gas-snapshot @@ -0,0 +1,344 @@ +AccessControlFacetTest:testGetRoleAdmin_ShouldReturnAdminRole() (gas: 12860) +AccessControlFacetTest:testGrantRole_ShouldRevertWhenNotAdmin() (gas: 64969) +AccessControlFacetTest:testGrantRole_ShouldWork() (gas: 76801) +AccessControlFacetTest:testHasRole_ShouldReturnTrue() (gas: 78349) +AccessControlFacetTest:testRenounceRole_ShouldWork() (gas: 64776) +AccessControlFacetTest:testRevokeRole_ShouldRevertWhenNotAdmin() (gas: 65033) +AccessControlFacetTest:testRevokeRole_ShouldWork() (gas: 65462) +BondedStateTest:testBondsCount_ShouldReturnCorrectCount() (gas: 19376) +BondedStateTest:testClaimBond_ShouldEmitLogClaimAndClaimBondRewards(uint256) (runs: 256, μ: 39474, ~: 39225) +BondedStateTest:testClaim_ShouldClaimRewards(uint256) (runs: 256, μ: 79835, ~: 79586) +BondedStateTest:testRewardsBondOf_ShouldReturnCorrectValues(uint256,uint256) (runs: 256, μ: 35467, ~: 35379) +BondedStateTest:testRewardsOf_ShouldReturnRewardsOfBond(uint256) (runs: 256, μ: 430178, ~: 429929) +BondedStateTest:testWithdraw_ShouldWithdrawBondTokens(uint256) (runs: 256, μ: 62535, ~: 62489) +CollectableDustFacetTest:testSendDust_ShouldRevertWhenPartOfTheProtocol() (gas: 173094) +CollectableDustFacetTest:testSendDust_ShouldWork() (gas: 61823) +CollectableDustFacetTest:testSendDust_ShouldWorkWhenNotPartOfTheProtocol() (gas: 173164) +CreditClockFacetTest:testGetManager_ShouldGet() (gas: 12829) +CreditClockFacetTest:testGetRate_ShouldRevert_WhenBlockIsInThePast() (gas: 14093) +CreditClockFacetTest:testSetManager_ShouldRevert_WhenNotAdmin() (gas: 16307) +CreditClockFacetTest:testSetManager_ShouldSetDiamond() (gas: 43832) +CreditClockFacetTest:testSetRatePerBlock_Default() (gas: 68668) +CreditClockFacetTest:testSetRatePerBlock_ShouldRevert_WhenNotAdmin() (gas: 16724) +CreditNftManagerFacetTest:test_burnCreditNftForCreditRevertsIfExpired() (gas: 19018) +CreditNftManagerFacetTest:test_burnCreditNftForCreditRevertsIfNotEnoughBalance() (gas: 29484) +CreditNftManagerFacetTest:test_burnCreditNftForCreditWorks() (gas: 399164) +CreditNftManagerFacetTest:test_burnCreditTokensForDollarsIfNotEnoughBalance() (gas: 47015) +CreditNftManagerFacetTest:test_burnCreditTokensForDollarsRevertsIfPriceLowerThan1Ether() (gas: 32261) +CreditNftManagerFacetTest:test_burnCreditTokensForDollarsWorks() (gas: 228998) +CreditNftManagerFacetTest:test_burnExpiredCreditNftForGovernanceRevertsIfNotEnoughBalance() (gas: 264114) +CreditNftManagerFacetTest:test_burnExpiredCreditNftForGovernanceRevertsIfNotExpired() (gas: 18956) +CreditNftManagerFacetTest:test_burnExpiredCreditNftForGovernanceWorks() (gas: 391775) +CreditNftManagerFacetTest:test_exchangeDollarsForCreditNft() (gas: 460214) +CreditNftManagerFacetTest:test_exchangeDollarsForCreditRevertsIfPriceHigherThan1Ether() (gas: 29305) +CreditNftManagerFacetTest:test_exchangeDollarsForCreditWorks() (gas: 278587) +CreditNftManagerFacetTest:test_mintClaimableDollars() (gas: 145197) +CreditNftManagerFacetTest:test_redeemCreditNftRevertsIfCreditNftExpired() (gas: 37011) +CreditNftManagerFacetTest:test_redeemCreditNftRevertsIfNotEnoughBalance() (gas: 398981) +CreditNftManagerFacetTest:test_redeemCreditNftRevertsIfNotEnoughDollars() (gas: 631739) +CreditNftManagerFacetTest:test_redeemCreditNftRevertsIfPriceLowerThan1Ether() (gas: 32296) +CreditNftManagerFacetTest:test_redeemCreditNftRevertsIfZeroAmountOfDollars() (gas: 522302) +CreditNftManagerFacetTest:test_redeemCreditNftWorks() (gas: 582306) +CreditNftManagerFacetTest:test_setCreditNftLength() (gas: 34084) +CreditNftManagerFacetTest:test_setExpiredCreditNftConversionRate() (gas: 36873) +CreditNftRedemptionCalculatorFacetTest:test_getCreditNftAmount() (gas: 282704) +CreditNftRedemptionCalculatorFacetTest:test_getCreditNftAmount_revertsIfDebtTooHigh() (gas: 273946) +CreditNftTest:testBurnCreditNft_ShouldBurnCreditNft() (gas: 290948) +CreditNftTest:testBurnCreditNft_ShouldRevert_WhenNotCreditNftManager() (gas: 26533) +CreditNftTest:testGetTotalOutstandingDebt_ReturnTotalDebt() (gas: 499531) +CreditNftTest:testMintCreditNft_ShouldMintCreditNft() (gas: 256463) +CreditNftTest:testMintCreditNft_ShouldRevert_WhenNotCreditNftManager() (gas: 26491) +CreditNftTest:testSetManager_ShouldRevert_WhenNotAdmin() (gas: 26706) +CreditNftTest:testSetManager_ShouldSetDiamond() (gas: 32747) +CreditNftTest:testUUPS_AdminAuth() (gas: 4251511) +CreditNftTest:testUUPS_ImplChanges() (gas: 4232727) +CreditNftTest:testUUPS_InitializedVersion() (gas: 8435061) +CreditNftTest:testUUPS_ShouldUpgradeAndCall() (gas: 4244335) +CreditNftTest:testUUPS_initialization() (gas: 4256064) +CreditNftTest:testUpdateTotalDebt_ShouldUpdateTotalDebt() (gas: 481012) +CreditRedemptionCalculatorFacetTest:testGetCreditAmount_ShouldReturnAmount() (gas: 73909) +CreditRedemptionCalculatorFacetTest:testGetCreditAmount_ShouldRevert_IfDebtIsTooHigh() (gas: 47371) +CreditRedemptionCalculatorFacetTest:testSetConstant_ShouldRevert_IfCalledNotByAdmin() (gas: 18307) +CreditRedemptionCalculatorFacetTest:testSetConstant_ShouldUpdateCoef() (gas: 26529) +CurveDollarIncentiveTest:testIncentivizeBuy() (gas: 95243) +CurveDollarIncentiveTest:testIncentivizeSell() (gas: 155277) +CurveDollarIncentiveTest:testIncentivizeShouldRevertIfSenderEqualToReceiver() (gas: 18653) +CurveDollarIncentiveTest:testIncentivizeShouldRevertWhenCallerNotUAD() (gas: 16169) +CurveDollarIncentiveTest:testSetExemptAddress_ShouldRevertOrSet_IfAdmin() (gas: 58163) +CurveDollarIncentiveTest:testSwitchBuyIncentive_ShouldRevertOrSwitch_IfAdmin() (gas: 54085) +CurveDollarIncentiveTest:testSwitchSellPenalty_ShouldRevertOrSwitch_IfAdmin() (gas: 53820) +DepositStateChefTest:testCannotGetRewardsOtherAccount() (gas: 28529) +DepositStateChefTest:testGetRewards(uint256) (runs: 256, μ: 255147, ~: 254897) +DepositStateChefTest:testGetStakingShareInfo() (gas: 18230) +DepositStateChefTest:testPendingGovernance(uint256) (runs: 256, μ: 40830, ~: 40578) +DepositStateChefTest:testRemoveLiquidity(uint256,uint256) (runs: 256, μ: 445665, ~: 447653) +DepositStateChefTest:testTotalShares() (gas: 14908) +DepositStateTest:testCannotGetRewardsOtherAccount() (gas: 28529) +DepositStateTest:testGetRewards(uint256) (runs: 256, μ: 255082, ~: 254897) +DepositStateTest:testGetStakingShareInfo() (gas: 18230) +DepositStateTest:testPendingGovernance(uint256) (runs: 256, μ: 40855, ~: 40578) +DepositStateTest:testRemoveLiquidity(uint256,uint256) (runs: 256, μ: 445686, ~: 447653) +DepositStateTest:testTotalShares() (gas: 14908) +DiamondInitTest:test_Init() (gas: 1219549) +DiamondInitTest:test_NonReentrant() (gas: 2216114) +DirectGovernanceFarmerFacetTest:testDepositMultipleTokens_ShouldDepositTokens() (gas: 527804) +DirectGovernanceFarmerFacetTest:testDepositMultipleTokens_ShouldRevert_IfAmountsIsNotPositive() (gas: 19757) +DirectGovernanceFarmerFacetTest:testDepositMultipleTokens_ShouldRevert_IfDurationIsNotValid() (gas: 19787) +DirectGovernanceFarmerFacetTest:testDeposit_ShouldDepositTokens() (gas: 228062) +DirectGovernanceFarmerFacetTest:testDeposit_ShouldRevert_IfAmountIsNotPositive() (gas: 36560) +DirectGovernanceFarmerFacetTest:testDeposit_ShouldRevert_IfDurationIsNotValid() (gas: 36598) +DirectGovernanceFarmerFacetTest:testDeposit_ShouldRevert_IfTokenIsNotInMetapool() (gas: 34529) +DirectGovernanceFarmerFacetTest:testIsIdIncludedReturnFalseIfIdIsNotInTheList() (gas: 269775) +DirectGovernanceFarmerFacetTest:testIsIdIncludedReturnTrueIfIdIsInTheList() (gas: 269724) +DirectGovernanceFarmerFacetTest:testIsMetaPoolCoinReturnFalseIfTokenAddressIsNotInMetaPool() (gas: 26048) +DirectGovernanceFarmerFacetTest:testIsMetaPoolCoinReturnTrueIfToken0IsPassed() (gas: 28123) +DirectGovernanceFarmerFacetTest:testIsMetaPoolCoinReturnTrueIfToken1IsPassed() (gas: 28070) +DirectGovernanceFarmerFacetTest:testIsMetaPoolCoinReturnTrueIfToken2IsPassed() (gas: 27992) +DirectGovernanceFarmerFacetTest:testIsMetaPoolCoinReturnTrueIfUbiquityDollarTokenIsPassed() (gas: 28167) +DirectGovernanceFarmerFacetTest:testWithdrawMultiple_ShouldRevert_IfSenderIsNotBondOwner() (gas: 51400) +DirectGovernanceFarmerFacetTest:testWithdrawMultiple_ShouldWithdraw() (gas: 604954) +DirectGovernanceFarmerFacetTest:testWithdrawShouldRevertIfSenderIsNotBondOwner() (gas: 65295) +DirectGovernanceFarmerFacetTest:testWithdrawShouldRevertIfTokenIsNotInMetaPool() (gas: 34450) +DirectGovernanceFarmerFacetTest:test_IsMetaPoolCoin() (gas: 26020) +DirectGovernanceFarmerFacetTest:test_ShouldMint() (gas: 80978) +DirectGovernanceFarmerFacetTest:test_Should_DebugMockCall_And_Return_Selector() (gas: 8104) +DirectGovernanceFarmerFacetTest:test_WithdrawShouldWithdraw() (gas: 284127) +DollarMintCalculatorFacetTest:test_getDollarsToMintRevertsIfPriceLowerThan1USD() (gas: 29116) +DollarMintCalculatorFacetTest:test_getDollarsToMintWorks() (gas: 45178) +DollarMintExcessFacetTest:testFails_distributeDollarsWorks() (gas: 74024) +ERC20UbiquityDollarTest:testAllowance_ShouldReturnAllowance() (gas: 140983) +ERC20UbiquityDollarTest:testApprove_ShouldApproveAddressToTransferTokens() (gas: 139589) +ERC20UbiquityDollarTest:testBurnFrom_ShouldBurnTokensFromAddress() (gas: 157043) +ERC20UbiquityDollarTest:testBurnFrom_ShouldRevert_IfCalledNotByTheBurnerRole() (gas: 27999) +ERC20UbiquityDollarTest:testBurnFrom_ShouldRevert_IfContractIsPaused() (gas: 176974) +ERC20UbiquityDollarTest:testBurn_ShouldBurnTokens() (gas: 90967) +ERC20UbiquityDollarTest:testBurn_ShouldRevert_IfContractIsPaused() (gas: 53390) +ERC20UbiquityDollarTest:testMint_ShouldMintTokens() (gas: 85722) +ERC20UbiquityDollarTest:testMint_ShouldRevert_IfCalledNotByTheMinterRole() (gas: 28052) +ERC20UbiquityDollarTest:testMint_ShouldRevert_IfContractIsPaused() (gas: 59352) +ERC20UbiquityDollarTest:testName_ShouldReturnTokenName() (gas: 14705) +ERC20UbiquityDollarTest:testPause_ShouldPauseContract() (gas: 54319) +ERC20UbiquityDollarTest:testPause_ShouldRevert_IfCalledNotByThePauserRole() (gas: 26264) +ERC20UbiquityDollarTest:testPermit_ShouldIncreaseSpenderAllowance() (gas: 88157) +ERC20UbiquityDollarTest:testPermit_ShouldRevert_IfDeadlineExpired() (gas: 32619) +ERC20UbiquityDollarTest:testPermit_ShouldRevert_IfSignatureIsInvalid() (gas: 59194) +ERC20UbiquityDollarTest:testSetSymbol_ShouldRevert_IfMethodIsCalledNotByAdmin() (gas: 26676) +ERC20UbiquityDollarTest:testSetSymbol_ShouldSetSymbol() (gas: 37558) +ERC20UbiquityDollarTest:testSymbol_ShouldReturnSymbolName() (gas: 14747) +ERC20UbiquityDollarTest:testTransferFrom_ShouldRevert_IfContractIsPaused() (gas: 143494) +ERC20UbiquityDollarTest:testTransferFrom_ShouldTransferTokensFromAddress() (gas: 139606) +ERC20UbiquityDollarTest:testTransfer_ShouldRevert_IfContractIsPaused() (gas: 55673) +ERC20UbiquityDollarTest:testTransfer_ShouldTransferTokens() (gas: 117148) +ERC20UbiquityDollarTest:testUnpause_ShouldRevert_IfCalledNotByThePauserRole() (gas: 57131) +ERC20UbiquityDollarTest:testUnpause_ShouldUnpauseContract() (gas: 37026) +ManagerFacetTest:testCanCallGeneralFunctions_ShouldSucceed() (gas: 14938) +ManagerFacetTest:testDeployStableSwapPool_ShouldSucceed() (gas: 6516992) +ManagerFacetTest:testInitializeDollarTokenAddress_ShouldSucceed() (gas: 20213) +ManagerFacetTest:testSetCreditNftAddress_ShouldSucceed() (gas: 29163) +ManagerFacetTest:testSetCreditTokenAddress_ShouldSucceed() (gas: 29163) +ManagerFacetTest:testSetDollarMintCalculatorAddress_ShouldSucceed() (gas: 46219) +ManagerFacetTest:testSetDollarTokenAddress_ShouldSucceed() (gas: 20169) +ManagerFacetTest:testSetExcessDollarsDistributor_ShouldSucceed() (gas: 48822) +ManagerFacetTest:testSetFormulasAddress_ShouldSucceed() (gas: 46286) +ManagerFacetTest:testSetGovernanceTokenAddress_ShouldSucceed() (gas: 29140) +ManagerFacetTest:testSetIncentiveToDollar_ShouldSucceed() (gas: 77276) +ManagerFacetTest:testSetMasterChefAddress_ShouldSucceed() (gas: 46264) +ManagerFacetTest:testSetMinterRoleWhenInitializing_ShouldSucceed() (gas: 18635) +ManagerFacetTest:testSetStableSwapMetaPoolAddress_ShouldSucceed() (gas: 46265) +ManagerFacetTest:testSetStakingContractAddress_ShouldSucceed() (gas: 46241) +ManagerFacetTest:testSetStakingShareAddress_ShouldSucceed() (gas: 29143) +ManagerFacetTest:testSetSushiSwapPoolAddress_ShouldSucceed() (gas: 46308) +ManagerFacetTest:testSetTreasuryAddress_ShouldSucceed() (gas: 29143) +ManagerFacetTest:testSetTwapOracleAddress_ShouldSucceed() (gas: 18085) +OwnershipFacetTest:testTransferOwnership_ShouldRevertWhenNewOwnerIsZeroAddress() (gas: 23744) +OwnershipFacetTest:testTransferOwnership_ShouldRevertWhenNotOwner() (gas: 28175) +OwnershipFacetTest:testTransferOwnership_ShouldWorkWhenNewOwnerIsNotContract() (gas: 30393) +StakingFormulasFacetTest:testDurationMultiply_ShouldReturnAmount() (gas: 17469) +StakingFormulasFacetTest:test_correctedAmountToWithdraw_calcSharedAmount() (gas: 13737) +StakingFormulasFacetTest:test_correctedAmountToWithdraw_returnAmount() (gas: 10753) +StakingFormulasFacetTest:test_lpRewardsAddLiquidityNormalization((address,uint256,uint256,uint256,uint256,uint256),uint256[2],uint256) (runs: 256, μ: 12620, ~: 12620) +StakingFormulasFacetTest:test_lpRewardsRemoveLiquidityNormalization((address,uint256,uint256,uint256,uint256,uint256),uint256[2],uint256) (runs: 256, μ: 12619, ~: 12619) +StakingFormulasFacetTest:test_sharesForLP() (gas: 14997) +StakingShareTest:testGetStake_ShouldReturnStake() (gas: 64806) +StakingShareTest:testMint_ShouldMint(uint128,uint128,uint256) (runs: 256, μ: 324469, ~: 327423) +StakingShareTest:testMint_ShouldRevert_IfMintingToZeroAddress(uint128,uint128,uint256) (runs: 256, μ: 29236, ~: 29236) +StakingShareTest:testMint_ShouldRevert_IfNotMinter(uint128,uint128,uint256) (runs: 256, μ: 29237, ~: 29237) +StakingShareTest:testMint_ShouldRevert_IfPaused(uint128,uint128,uint256) (runs: 256, μ: 58034, ~: 58034) +StakingShareTest:testPause_ShouldPause() (gas: 42717) +StakingShareTest:testPause_ShouldRevert_IfNotPauser() (gas: 20428) +StakingShareTest:testSafeBatchTransferFrom_ShouldRevert_IfPaused() (gas: 64411) +StakingShareTest:testSafeBatchTransferFrom_ShouldTransferTokenIds() (gas: 308746) +StakingShareTest:testSafeTransferFrom_ShouldRevert_IfInsufficientBalance() (gas: 52786) +StakingShareTest:testSafeTransferFrom_ShouldRevert_IfPaused() (gas: 58983) +StakingShareTest:testSafeTransferFrom_ShouldRevert_IfToAddressZero() (gas: 47706) +StakingShareTest:testSafeTransferFrom_ShouldTransferTokenId() (gas: 168375) +StakingShareTest:testSetBaseUri_ShouldSetUri() (gas: 407162) +StakingShareTest:testSetUriSingle_ShouldSetUri() (gas: 186113) +StakingShareTest:testSetUri_ShouldRevert_IfGovernanceTokenNotStakingManager() (gas: 29596) +StakingShareTest:testSetUri_ShouldSetUri() (gas: 261424) +StakingShareTest:testTotalSupply_ShouldReturn_TotalSupply() (gas: 12560) +StakingShareTest:testUUPS_AdminAuth() (gas: 4413232) +StakingShareTest:testUUPS_ImplChanges() (gas: 4394360) +StakingShareTest:testUUPS_InitializedVersion() (gas: 8758239) +StakingShareTest:testUUPS_ShouldUpgradeAndCall() (gas: 4407024) +StakingShareTest:testUUPS_initialization() (gas: 4419554) +StakingShareTest:testUnpause_ShouldRevert_IfNotPauser() (gas: 49948) +StakingShareTest:testUnpause_ShouldUnpause() (gas: 34424) +StakingShareTest:testUpdateStake_ShouldRevert_IfNotMinter(uint128,uint128,uint256) (runs: 256, μ: 29136, ~: 29136) +StakingShareTest:testUpdateStake_ShouldRevert_IfPaused(uint128,uint128,uint256) (runs: 256, μ: 58041, ~: 58041) +StakingShareTest:testUpdateStake_ShouldUpdateStake(uint128,uint128,uint256) (runs: 256, μ: 169373, ~: 171896) +StickerStateTest:testBond(uint256) (runs: 256, μ: 216048, ~: 233190) +StickerStateTest:testBond_ShouldRevert_IfTokenNotAllowed() (gas: 25107) +TWAPOracleDollar3poolFacetTest:test_overall() (gas: 100698) +TWAPOracleDollar3poolFacetTest:test_setPoolRevertsWhenFirstAddressIsNotDollarToken() (gas: 1394475) +TestDiamond:testCutFacetAddSimplePureFacet() (gas: 174628) +TestDiamond:testCutFacetAddSimpleWriteFacet() (gas: 196782) +TestDiamond:testCutFacetAddWriteFacetWithInitializer() (gas: 225047) +TestDiamond:testCutFacetRemoveFacetFunctions() (gas: 169384) +TestDiamond:testCutFacetReplaceFacet() (gas: 278069) +TestDiamond:testCutFacetShouldRevertWhenAddToZeroAddress() (gas: 27297) +TestDiamond:testCutFacetShouldRevertWhenFacetInitializerReverts() (gas: 184092) +TestDiamond:testCutFacetShouldRevertWhenFunctionAlreadyExists() (gas: 33989) +TestDiamond:testCutFacetShouldRevertWhenNoSelectorsProvidedForFacetForCut() (gas: 23499) +TestDiamond:testCutFacetShouldRevertWhenNotOwner() (gas: 27327) +TestDiamond:testCutFacetShouldRevertWithMessageWhenFacetInitializerWithMessageReverts() (gas: 183915) +TestDiamond:testFacetsHaveCorrectSelectors() (gas: 505837) +TestDiamond:testHasMultipleFacets() (gas: 2372) +TestDiamond:testLoupeFacetAddressesEqualsTheListOfAvailableFacets() (gas: 297846) +TestDiamond:testSelectors_ShouldBeAssociatedWithCorrectFacet() (gas: 441622) +TestDiamond:test_ShouldSupportInspectingFacetsAndFunctions() (gas: 12937) +UbiquiStickSaleTest:testAllowance_ShouldReturnAllowance() (gas: 60675) +UbiquiStickSaleTest:testBatchSetAllowance_ShouldBatchSetAllowance() (gas: 112262) +UbiquiStickSaleTest:testBatchSetAllowance_ShouldRevert_IfCalledNotByOwner() (gas: 14242) +UbiquiStickSaleTest:testReceive_ShouldRevert_IfAllowanceIsInsufficient() (gas: 39370) +UbiquiStickSaleTest:testReceive_ShouldRevert_IfMaxSupplyIsReached() (gas: 119215412) +UbiquiStickSaleTest:testSetAllowance_ShouldRevert_IfAddressIsZero() (gas: 13142) +UbiquiStickSaleTest:testSetAllowance_ShouldRevert_IfCalledNotByOwner() (gas: 13267) +UbiquiStickSaleTest:testSetAllowance_ShouldSetAllowance() (gas: 60631) +UbiquiStickSaleTest:testSetFundsAddress_ShouldRevert_IfAddressIsZero() (gas: 13079) +UbiquiStickSaleTest:testSetFundsAddress_ShouldRevert_IfCalledNotByOwner() (gas: 13129) +UbiquiStickSaleTest:testSetFundsAddress_ShouldSetFundsAddress() (gas: 35745) +UbiquiStickSaleTest:testSetTokenContract_ShouldRevert_IfAddressIsZero() (gas: 13132) +UbiquiStickSaleTest:testSetTokenContract_ShouldRevert_IfCalledNotByOwner() (gas: 15190) +UbiquiStickSaleTest:testSetTokenContract_ShouldSetTokenContract() (gas: 37978) +UbiquiStickSaleTest:testWithdraw_ShouldRevert_IfCalledNotByOwner() (gas: 18004) +UbiquiStickSaleTest:testWithdraw_ShouldWithdraw() (gas: 69308) +UbiquiStickTest:testApprove_ShouldApprove() (gas: 169292) +UbiquiStickTest:testApprove_ShouldRevert_IfOperatorIsNotAllowed() (gas: 16151) +UbiquiStickTest:testBatchSafeMint_ShouldMintMultipleTokens() (gas: 257478) +UbiquiStickTest:testBatchSafeMint_ShouldRevert_IfCalledNotByMinter() (gas: 13244) +UbiquiStickTest:testBeforeConsecutiveTokenTransfer_ShouldRevert() (gas: 8818) +UbiquiStickTest:testConstructor_ShouldInitContract() (gas: 9871) +UbiquiStickTest:testRandom_ShouldReturnRandomValue() (gas: 7887) +UbiquiStickTest:testSafeMint_ShouldMint() (gas: 141192) +UbiquiStickTest:testSafeMint_ShouldMintGoldToken() (gas: 6808007) +UbiquiStickTest:testSafeMint_ShouldRevert_IfCalledNotByMinter() (gas: 13274) +UbiquiStickTest:testSafeTransferFromWith4Params_ShouldRevert_IfOperatorIsNotAllowed() (gas: 173382) +UbiquiStickTest:testSafeTransferFromWith4Params_ShouldTransferToken() (gas: 175109) +UbiquiStickTest:testSafeTransferFrom_ShouldRevert_IfOperatorIsNotAllowed() (gas: 172945) +UbiquiStickTest:testSafeTransferFrom_ShouldTransferToken() (gas: 174980) +UbiquiStickTest:testSetApprovalForAll_ShouldApproveOperatorToSpendAllTokens() (gas: 168854) +UbiquiStickTest:testSetApprovalForAll_ShouldRevert_IfOperatorIsNotAllowed() (gas: 143926) +UbiquiStickTest:testSetMinter_ShouldRevert_IfCalledNotByOwner() (gas: 13292) +UbiquiStickTest:testSetMinter_ShouldUpdateMinter() (gas: 18836) +UbiquiStickTest:testSetTokenURI_ShouldRevert_IfCalledNotByMinter() (gas: 13541) +UbiquiStickTest:testSupportsInterface_ShouldReturnFalse_IfInterfaceIsNotSupported() (gas: 5902) +UbiquiStickTest:testSupportsInterface_ShouldReturnTrue_IfInterfaceIsSupported() (gas: 5868) +UbiquiStickTest:testTokenURI_ShouldReturnTokenURIForTokenTypeGold() (gas: 6832847) +UbiquiStickTest:testTokenURI_ShouldReturnTokenURIForTokenTypeInvisible() (gas: 4967062) +UbiquiStickTest:testTokenURI_ShouldReturnTokenURIForTokenTypeStandard() (gas: 168668) +UbiquiStickTest:testTokenURI_ShouldRevert_IfTokenDoesNotExist() (gas: 12661) +UbiquiStickTest:testTransferFrom_ShouldRevert_IfOperatorIsNotAllowed() (gas: 172924) +UbiquiStickTest:testTransferFrom_ShouldTransferToken() (gas: 174578) +UbiquityCreditTokenTest:testRaiseCapital_ShouldMintTokens() (gas: 91771) +UbiquityCreditTokenTest:testSetManager_ShouldRevert_WhenNotAdmin() (gas: 26618) +UbiquityCreditTokenTest:testSetManager_ShouldSetManager() (gas: 32691) +UbiquityCreditTokenTest:testUUPS_AdminAuth() (gas: 3040241) +UbiquityCreditTokenTest:testUUPS_ImplChanges() (gas: 3023487) +UbiquityCreditTokenTest:testUUPS_InitializedVersion() (gas: 6013500) +UbiquityCreditTokenTest:testUUPS_ShouldUpgradeAndCall() (gas: 3032672) +UbiquityCreditTokenTest:testUUPS_initialization() (gas: 3046692) +UbiquityDollarTokenTest:testSetIncentiveContract_ShouldRevert_IfNotAdmin() (gas: 78389) +UbiquityDollarTokenTest:testSetManager_ShouldRevert_WhenNotAdmin() (gas: 26625) +UbiquityDollarTokenTest:testSetManager_ShouldSetManager() (gas: 32719) +UbiquityDollarTokenTest:testTransfer_ShouldCallIncentivize_IfValidTransfer() (gas: 291699) +UbiquityDollarTokenTest:testUUPS_AdminAuth() (gas: 3309713) +UbiquityDollarTokenTest:testUUPS_ImplChanges() (gas: 3291019) +UbiquityDollarTokenTest:testUUPS_InitializedVersion() (gas: 6552357) +UbiquityDollarTokenTest:testUUPS_ShouldUpgradeAndCall() (gas: 3302255) +UbiquityDollarTokenTest:testUUPS_initialization() (gas: 3305562) +UbiquityGovernanceTokenTest:testSetManager_ShouldRevert_WhenNotAdmin() (gas: 26646) +UbiquityGovernanceTokenTest:testSetManager_ShouldSetManager() (gas: 32719) +UbiquityGovernanceTokenTest:testUUPS_AdminAuth() (gas: 2987468) +UbiquityGovernanceTokenTest:testUUPS_ImplChanges() (gas: 2968752) +UbiquityGovernanceTokenTest:testUUPS_InitializedVersion() (gas: 5908190) +UbiquityGovernanceTokenTest:testUUPS_ShouldUpgradeAndCall() (gas: 2980294) +UbiquityGovernanceTokenTest:testUUPS_initialization() (gas: 2983228) +UbiquityPoolFacetTest:testAddAmoMinter_ShouldAddAmoMinter() (gas: 28622) +UbiquityPoolFacetTest:testAddAmoMinter_ShouldRevert_IfAmoMinterHasInvalidInterface() (gas: 22052) +UbiquityPoolFacetTest:testAddAmoMinter_ShouldRevert_IfAmoMinterIsZeroAddress() (gas: 18859) +UbiquityPoolFacetTest:testAddCollateralToken_ShouldAddNewTokenAsCollateral() (gas: 73204) +UbiquityPoolFacetTest:testAllCollaterals_ShouldReturnAllCollateralTokenAddresses() (gas: 18216) +UbiquityPoolFacetTest:testAmoMinterBorrow_ShouldBorrowCollateral() (gas: 75429) +UbiquityPoolFacetTest:testAmoMinterBorrow_ShouldRevert_IfBorrowingIsPaused() (gas: 53897) +UbiquityPoolFacetTest:testAmoMinterBorrow_ShouldRevert_IfCollateralIsDisabled() (gas: 38116) +UbiquityPoolFacetTest:testCollateralEnabled_ShouldRevert_IfCollateralIsDisabled() (gas: 31123) +UbiquityPoolFacetTest:testCollateralInformation_ShouldReturnCollateralInformation() (gas: 73184) +UbiquityPoolFacetTest:testCollateralInformation_ShouldRevert_IfCollateralIsDisabled() (gas: 34221) +UbiquityPoolFacetTest:testCollateralUsdBalance_ShouldReturnTotalAmountOfCollateralInUsd() (gas: 231170) +UbiquityPoolFacetTest:testCollectRedemption_ShouldCollectRedemption() (gas: 282896) +UbiquityPoolFacetTest:testCollectRedemption_ShouldRevert_IfNotEnoughBlocksHaveBeenMined() (gas: 24951) +UbiquityPoolFacetTest:testCollectRedemption_ShouldRevert_IfRedeemingIsPaused() (gas: 51124) +UbiquityPoolFacetTest:testFreeCollateralBalance_ShouldReturnCollateralAmountAvailableForBorrowingByAmoMinters() (gas: 294542) +UbiquityPoolFacetTest:testGetDollarInCollateral_ShouldReturnAmountOfDollarsWhichShouldBeMintedForInputCollateral() (gas: 19890) +UbiquityPoolFacetTest:testGetDollarPriceUsd_ShouldReturnDollarPriceInUsd() (gas: 28320) +UbiquityPoolFacetTest:testMintDollar_ShouldMintDollars() (gas: 234222) +UbiquityPoolFacetTest:testMintDollar_ShouldRevert_IfDollarPriceUsdIsTooLow() (gas: 58883) +UbiquityPoolFacetTest:testMintDollar_ShouldRevert_IfMintingIsPaused() (gas: 57822) +UbiquityPoolFacetTest:testMintDollar_ShouldRevert_OnCollateralAmountSlippage() (gas: 113771) +UbiquityPoolFacetTest:testMintDollar_ShouldRevert_OnDollarAmountSlippage() (gas: 113751) +UbiquityPoolFacetTest:testMintDollar_ShouldRevert_OnReachingPoolCeiling() (gas: 128498) +UbiquityPoolFacetTest:testOnlyAmoMinter_ShouldRevert_IfCalledNoByAmoMinter() (gas: 18315) +UbiquityPoolFacetTest:testRedeemDollar_ShouldRedeemCollateral() (gas: 294607) +UbiquityPoolFacetTest:testRedeemDollar_ShouldRevert_IfDollarPriceUsdIsTooHigh() (gas: 58827) +UbiquityPoolFacetTest:testRedeemDollar_ShouldRevert_IfRedeemingIsPaused() (gas: 57831) +UbiquityPoolFacetTest:testRedeemDollar_ShouldRevert_OnCollateralSlippage() (gas: 254835) +UbiquityPoolFacetTest:testRedeemDollar_ShouldRevert_OnInsufficientPoolCollateral() (gas: 126655) +UbiquityPoolFacetTest:testRemoveAmoMinter_ShouldRemoveAmoMinter() (gas: 23666) +UbiquityPoolFacetTest:testSetCollateralChainLinkPriceFeed_ShouldSetPriceFeed() (gas: 103379) +UbiquityPoolFacetTest:testSetFees_ShouldSetMintAndRedeemFees() (gas: 36637) +UbiquityPoolFacetTest:testSetPoolCeiling_ShouldSetMaxAmountOfTokensAllowedForCollateral() (gas: 96727) +UbiquityPoolFacetTest:testSetPriceThresholds_ShouldSetPriceThresholds() (gas: 26046) +UbiquityPoolFacetTest:testSetRedemptionDelayBlocks_ShouldSetRedemptionDelayInBlocks() (gas: 23266) +UbiquityPoolFacetTest:testToggleCollateral_ShouldToggleCollateral() (gas: 92448) +UbiquityPoolFacetTest:testToggleMintRedeemBorrow_ShouldToggleBorrowingByAmoMinter() (gas: 114544) +UbiquityPoolFacetTest:testToggleMintRedeemBorrow_ShouldToggleMinting() (gas: 114520) +UbiquityPoolFacetTest:testToggleMintRedeemBorrow_ShouldToggleRedeeming() (gas: 114570) +UbiquityPoolFacetTest:testUpdateChainLinkCollateralPrice_ShouldRevert_IfChainlinkAnswerIsInvalid() (gas: 34832) +UbiquityPoolFacetTest:testUpdateChainLinkCollateralPrice_ShouldRevert_IfChainlinkAnswerIsStale() (gas: 41693) +UbiquityPoolFacetTest:testUpdateChainLinkCollateralPrice_ShouldUpdateCollateralPrice() (gas: 110094) +ZeroStateBonding:testDeposit(uint32,uint256) (runs: 256, μ: 216387, ~: 219383) +ZeroStateBonding:testPurchaseTargetAmount(uint32,uint256) (runs: 256, μ: 26411, ~: 26459) +ZeroStateBonding:testPurchaseTargetAmountShouldRevertIfParamsNotSet() (gas: 17933) +ZeroStateBonding:testPurchaseTargetAmountShouldRevertIfSupplyZero() (gas: 17897) +ZeroStateBonding:testSetParams(uint32,uint256) (runs: 256, μ: 79023, ~: 79224) +ZeroStateBonding:testSetParamsShouldRevertNotAdmin() (gas: 24467) +ZeroStateBonding:testWithdraw(uint32,uint256) (runs: 256, μ: 203901, ~: 205489) +ZeroStateChefTest:testDepositFromZeroState(uint256) (runs: 256, μ: 454886, ~: 455877) +ZeroStateChefTest:testGetInitialGovernanceMul() (gas: 17707) +ZeroStateChefTest:testSetGovernanceDiv(uint256) (runs: 256, μ: 26475, ~: 26738) +ZeroStateChefTest:testSetGovernancePerBlock(uint256) (runs: 256, μ: 29301, ~: 29564) +ZeroStateChefTest:testSetGovernancePerBlock_ShouldRevertWhenNotAdmin() (gas: 18420) +ZeroStateChefTest:testSetGovernanceShareForTreasury_ShouldRevertWhenNotAdmin() (gas: 18444) +ZeroStateChefTest:testSetMinPriceDiff(uint256) (runs: 256, μ: 29204, ~: 29467) +ZeroStateChefTest:testSetMinPriceDiffToUpdateMultiplier_ShouldRevertWhenNotAdmin() (gas: 18387) +ZeroStateStakingTest:testCannotDepositZeroWeeks() (gas: 18230) +ZeroStateStakingTest:testCannotStakeMoreThan4Years(uint256) (runs: 256, μ: 22299, ~: 22246) +ZeroStateStakingTest:testDeposit_Staking(uint256,uint256) (runs: 256, μ: 442733, ~: 442786) +ZeroStateStakingTest:testLockupMultiplier() (gas: 749618) +ZeroStateStakingTest:testSetBlockCountInAWeek(uint256) (runs: 256, μ: 28921, ~: 29184) +ZeroStateStakingTest:testSetStakingDiscountMultiplier(uint256) (runs: 256, μ: 28941, ~: 29204) +ZeroStateTest:testSetRewards_ShouldSetRewards(uint256) (runs: 256, μ: 38477, ~: 39566) +ZeroStateTest:testSetSticker_ShouldSetSticker() (gas: 37850) +ZeroStateTest:testSetTreasury_ShouldSetTreasury() (gas: 18793) +ZeroStateTest:testSetVestingBlocks_ShouldSetVestingBlocks(uint256) (runs: 256, μ: 22549, ~: 22534) \ No newline at end of file diff --git a/packages/contracts/src/dollar/core/CreditNft.sol b/packages/contracts/src/dollar/core/CreditNft.sol index 729c77e2f..5771cecdb 100644 --- a/packages/contracts/src/dollar/core/CreditNft.sol +++ b/packages/contracts/src/dollar/core/CreditNft.sol @@ -45,11 +45,15 @@ contract CreditNft is ERC1155Ubiquity, ICreditNft { /// @notice Modifier checks that the method is called by a user with the "CreditNft manager" role modifier onlyCreditNftManager() { + _onlyCreditNftManager(); + _; + } + + function _onlyCreditNftManager() internal view { require( accessControl.hasRole(CREDIT_NFT_MANAGER_ROLE, _msgSender()), - "Caller is not a CreditNft manager" + "CreditNft: not CreditNft manager" ); - _; } /// @notice Ensures initialize cannot be called on the implementation contract @@ -61,7 +65,7 @@ contract CreditNft is ERC1155Ubiquity, ICreditNft { /// @param _manager Address of the manager of the contract function initialize(address _manager) public initializer { __ERC1155Ubiquity_init(_manager, "URI"); - _totalOutstandingDebt = 0; + _totalOutstandingDebt; } /** @@ -120,7 +124,7 @@ contract CreditNft is ERC1155Ubiquity, ICreditNft { * @dev Should be called prior to any state changing functions */ function updateTotalDebt() public { - bool reachedEndOfExpiredKeys = false; + bool reachedEndOfExpiredKeys; uint256 currentBlockNumber = _sortedBlockNumbers.popFront(); uint256 outstandingDebt = _totalOutstandingDebt; //if list is empty, currentBlockNumber will be 0 @@ -146,7 +150,7 @@ contract CreditNft is ERC1155Ubiquity, ICreditNft { /// @notice Returns outstanding debt by fetching current tally and removing any expired debt function getTotalOutstandingDebt() public view returns (uint256) { uint256 outstandingDebt = _totalOutstandingDebt; - bool reachedEndOfExpiredKeys = false; + bool reachedEndOfExpiredKeys; (, uint256 currentBlockNumber) = _sortedBlockNumbers.getNextNode(0); while (!reachedEndOfExpiredKeys && currentBlockNumber != 0) { diff --git a/packages/contracts/src/dollar/core/ERC1155Ubiquity.sol b/packages/contracts/src/dollar/core/ERC1155Ubiquity.sol index 6c211deb5..41d9c94e7 100644 --- a/packages/contracts/src/dollar/core/ERC1155Ubiquity.sol +++ b/packages/contracts/src/dollar/core/ERC1155Ubiquity.sol @@ -39,38 +39,54 @@ abstract contract ERC1155Ubiquity is /// @notice Modifier checks that the method is called by a user with the "Governance minter" role modifier onlyMinter() virtual { + _onlyMinter(); + _; + } + + function _onlyMinter() virtual internal view { require( accessControl.hasRole(GOVERNANCE_TOKEN_MINTER_ROLE, _msgSender()), "ERC1155Ubiquity: not minter" ); - _; - } + } /// @notice Modifier checks that the method is called by a user with the "Governance burner" role modifier onlyBurner() virtual { + _onlyBurner(); + _; + } + + function _onlyBurner() virtual internal view { require( accessControl.hasRole(GOVERNANCE_TOKEN_BURNER_ROLE, _msgSender()), "ERC1155Ubiquity: not burner" ); - _; } /// @notice Modifier checks that the method is called by a user with the "Pauser" role modifier onlyPauser() virtual { + _onlyPauser(); + _; + } + + function _onlyPauser() virtual internal view { require( accessControl.hasRole(PAUSER_ROLE, _msgSender()), "ERC1155Ubiquity: not pauser" ); - _; } /// @notice Modifier checks that the method is called by a user with the "Admin" role modifier onlyAdmin() { + _onlyAdmin(); + _; + } + + function _onlyAdmin() internal view { require( accessControl.hasRole(DEFAULT_ADMIN_ROLE, _msgSender()), "ERC20Ubiquity: not admin" ); - _; } /// @notice Ensures __ERC1155Ubiquity_init cannot be called on the implementation contract @@ -140,7 +156,7 @@ abstract contract ERC1155Ubiquity is bytes memory data ) public virtual onlyMinter { _mint(to, id, amount, data); - totalSupply += amount; + totalSupply = totalSupply + amount; holderBalances[to].add(id); } @@ -159,8 +175,12 @@ abstract contract ERC1155Ubiquity is ) public virtual onlyMinter whenNotPaused { _mintBatch(to, ids, amounts, data); uint256 localTotalSupply = totalSupply; - for (uint256 i = 0; i < ids.length; ++i) { + uint256 idsLength = ids.length; + for (uint256 i; i < idsLength;) { localTotalSupply += amounts[i]; + unchecked{ + ++i; + } } totalSupply = localTotalSupply; holderBalances[to].add(ids); @@ -249,7 +269,7 @@ abstract contract ERC1155Ubiquity is uint256 amount ) internal virtual override whenNotPaused { super._burn(account, id, amount); - totalSupply -= amount; + totalSupply = totalSupply - amount; } /** @@ -267,8 +287,11 @@ abstract contract ERC1155Ubiquity is uint256[] memory amounts ) internal virtual override whenNotPaused { super._burnBatch(account, ids, amounts); - for (uint256 i = 0; i < ids.length; ++i) { - totalSupply -= amounts[i]; + for (uint256 i; i < ids.length;) { + totalSupply = totalSupply - amounts[i]; + unchecked { + ++i; + } } } diff --git a/packages/contracts/src/dollar/core/ERC20Ubiquity.sol b/packages/contracts/src/dollar/core/ERC20Ubiquity.sol index e005cc262..db96cea0f 100644 --- a/packages/contracts/src/dollar/core/ERC20Ubiquity.sol +++ b/packages/contracts/src/dollar/core/ERC20Ubiquity.sol @@ -43,20 +43,28 @@ abstract contract ERC20Ubiquity is /// @notice Modifier checks that the method is called by a user with the "pauser" role modifier onlyPauser() { + _onlyPauser(); + _; + } + + function _onlyPauser() internal view { require( accessControl.hasRole(PAUSER_ROLE, msg.sender), "ERC20Ubiquity: not pauser" ); - _; } /// @notice Modifier checks that the method is called by a user with the "admin" role modifier onlyAdmin() { + _onlyAdmin(); + _; + } + + function _onlyAdmin() internal view { require( accessControl.hasRole(DEFAULT_ADMIN_ROLE, msg.sender), "ERC20Ubiquity: not admin" ); - _; } /// @notice Ensures __ERC20Ubiquity_init cannot be called on the implementation contract diff --git a/packages/contracts/src/dollar/core/StakingShare.sol b/packages/contracts/src/dollar/core/StakingShare.sol index 98482a8b4..bdf9f48c8 100644 --- a/packages/contracts/src/dollar/core/StakingShare.sol +++ b/packages/contracts/src/dollar/core/StakingShare.sol @@ -41,29 +41,41 @@ contract StakingShare is ERC1155Ubiquity, ERC1155URIStorageUpgradeable { /// @notice Modifier checks that the method is called by a user with the "Staking share minter" role modifier onlyMinter() override { + _onlyMinter(); + _; + } + + function _onlyMinter() internal override view { require( accessControl.hasRole(STAKING_SHARE_MINTER_ROLE, msg.sender), "Staking Share: not minter" ); - _; } /// @notice Modifier checks that the method is called by a user with the "Staking share burner" role modifier onlyBurner() override { + _onlyBurner(); + _; + } + + function _onlyBurner() internal override view { require( accessControl.hasRole(STAKING_SHARE_BURNER_ROLE, msg.sender), "Staking Share: not burner" ); - _; } /// @notice Modifier checks that the method is called by a user with the "Pauser" role modifier onlyPauser() override { + _onlyPauser(); + _; + } + + function _onlyPauser() internal override view { require( accessControl.hasRole(PAUSER_ROLE, msg.sender), "Staking Share: not pauser" ); - _; } /// @notice Ensures initialize cannot be called on the implementation contract @@ -124,7 +136,7 @@ contract StakingShare is ERC1155Ubiquity, ERC1155URIStorageUpgradeable { ) public virtual onlyMinter whenNotPaused returns (uint256 id) { id = totalSupply + 1; _mint(to, id, 1, bytes("")); - totalSupply += 1; + totalSupply = totalSupply + 1; holderBalances[to].add(id); Stake storage _stake = _stakes[id]; _stake.minter = to; @@ -250,7 +262,7 @@ contract StakingShare is ERC1155Ubiquity, ERC1155URIStorageUpgradeable { super._burn(account, id, 1); Stake storage _stake = _stakes[id]; require(_stake.lpAmount == 0, "LP <> 0"); - totalSupply -= 1; + totalSupply = totalSupply - 1; } /** diff --git a/packages/contracts/src/dollar/core/UbiquityCreditToken.sol b/packages/contracts/src/dollar/core/UbiquityCreditToken.sol index 021438b08..3ab047fe9 100644 --- a/packages/contracts/src/dollar/core/UbiquityCreditToken.sol +++ b/packages/contracts/src/dollar/core/UbiquityCreditToken.sol @@ -27,20 +27,28 @@ contract UbiquityCreditToken is ERC20Ubiquity { /// @notice Modifier checks that the method is called by a user with the "Credit minter" role modifier onlyCreditMinter() { + _onlyCreditMinter(); + _; + } + + function _onlyCreditMinter() internal view { require( accessControl.hasRole(CREDIT_TOKEN_MINTER_ROLE, _msgSender()), "Credit token: not minter" ); - _; } /// @notice Modifier checks that the method is called by a user with the "Credit burner" role modifier onlyCreditBurner() { + _onlyCreditBurner(); + _; + } + + function _onlyCreditBurner() internal view { require( accessControl.hasRole(CREDIT_TOKEN_BURNER_ROLE, _msgSender()), "Credit token: not burner" ); - _; } /** diff --git a/packages/contracts/src/dollar/core/UbiquityDollarToken.sol b/packages/contracts/src/dollar/core/UbiquityDollarToken.sol index 0c157185d..bcd77186c 100644 --- a/packages/contracts/src/dollar/core/UbiquityDollarToken.sol +++ b/packages/contracts/src/dollar/core/UbiquityDollarToken.sol @@ -39,20 +39,28 @@ contract UbiquityDollarToken is ERC20Ubiquity { /// @notice Modifier checks that the method is called by a user with the "Dollar minter" role modifier onlyDollarMinter() { + _onlyDollarMinter(); + _; + } + + function _onlyDollarMinter() internal view { require( accessControl.hasRole(DOLLAR_TOKEN_MINTER_ROLE, _msgSender()), "Dollar token: not minter" ); - _; } /// @notice Modifier checks that the method is called by a user with the "Dollar burner" role modifier onlyDollarBurner() { + _onlyDollarBurner(); + _; + } + + function _onlyDollarBurner() internal view { require( accessControl.hasRole(DOLLAR_TOKEN_BURNER_ROLE, _msgSender()), "Dollar token: not burner" ); - _; } /** diff --git a/packages/contracts/src/dollar/core/UbiquityGovernanceToken.sol b/packages/contracts/src/dollar/core/UbiquityGovernanceToken.sol index 65184eb82..645cdd1eb 100644 --- a/packages/contracts/src/dollar/core/UbiquityGovernanceToken.sol +++ b/packages/contracts/src/dollar/core/UbiquityGovernanceToken.sol @@ -27,20 +27,28 @@ contract UbiquityGovernanceToken is ERC20Ubiquity { /// @notice Modifier checks that the method is called by a user with the "Governance minter" role modifier onlyGovernanceMinter() { + _onlyGovernanceMinter(); + _; + } + + function _onlyGovernanceMinter() internal view { require( accessControl.hasRole(GOVERNANCE_TOKEN_MINTER_ROLE, _msgSender()), "Governance token: not minter" ); - _; } /// @notice Modifier checks that the method is called by a user with the "Governance burner" role modifier onlyGovernanceBurner() { + _onlyGovernanceBurner(); + _; + } + + function _onlyGovernanceBurner() internal view { require( accessControl.hasRole(GOVERNANCE_TOKEN_BURNER_ROLE, _msgSender()), "Governance token: not burner" ); - _; } /** diff --git a/packages/contracts/src/dollar/facets/DiamondLoupeFacet.sol b/packages/contracts/src/dollar/facets/DiamondLoupeFacet.sol index 2045060a8..152472488 100644 --- a/packages/contracts/src/dollar/facets/DiamondLoupeFacet.sol +++ b/packages/contracts/src/dollar/facets/DiamondLoupeFacet.sol @@ -18,14 +18,14 @@ contract DiamondLoupeFacet is IDiamondLoupe, IERC165 { LibDiamond.DiamondStorage storage ds = LibDiamond.diamondStorage(); uint256 numFacets = ds.facetAddresses.length; facets_ = new Facet[](numFacets); - for (uint256 i = 0; i < numFacets; ) { + for (uint256 i; i < numFacets; ) { address facetAddress_ = ds.facetAddresses[i]; facets_[i].facetAddress = facetAddress_; facets_[i].functionSelectors = ds .facetFunctionSelectors[facetAddress_] .functionSelectors; unchecked { - i++; + ++i; } } } diff --git a/packages/contracts/src/dollar/facets/OwnershipFacet.sol b/packages/contracts/src/dollar/facets/OwnershipFacet.sol index f41d47dc9..c07ba8615 100644 --- a/packages/contracts/src/dollar/facets/OwnershipFacet.sol +++ b/packages/contracts/src/dollar/facets/OwnershipFacet.sol @@ -10,7 +10,7 @@ contract OwnershipFacet is IERC173 { function transferOwnership(address _newOwner) external override { require( (_newOwner != address(0)), - "OwnershipFacet: New owner cannot be the zero address" + "OwnershipFacet: Can't address(0)" ); LibDiamond.enforceIsContractOwner(); LibDiamond.setContractOwner(_newOwner); diff --git a/packages/contracts/src/dollar/libraries/Constants.sol b/packages/contracts/src/dollar/libraries/Constants.sol index 006e1e9c4..21a03fb12 100644 --- a/packages/contracts/src/dollar/libraries/Constants.sol +++ b/packages/contracts/src/dollar/libraries/Constants.sol @@ -61,7 +61,7 @@ bytes32 constant CREDIT_NFT_MANAGER_ROLE = keccak256("CREDIT_NFT_MANAGER_ROLE"); bytes32 constant STAKING_MANAGER_ROLE = keccak256("STAKING_MANAGER_ROLE"); /// @dev Role name for inventive manager -bytes32 constant INCENTIVE_MANAGER_ROLE = keccak256("INCENTIVE_MANAGER"); +bytes32 constant INCENTIVE_MANAGER_ROLE = keccak256("INCENTIVE_MANAGER_ROLE"); /// @dev Role name for Governance token manager bytes32 constant GOVERNANCE_TOKEN_MANAGER_ROLE = keccak256( diff --git a/packages/contracts/src/dollar/libraries/LibAppStorage.sol b/packages/contracts/src/dollar/libraries/LibAppStorage.sol index 6bd153c67..e30cf929d 100644 --- a/packages/contracts/src/dollar/libraries/LibAppStorage.sol +++ b/packages/contracts/src/dollar/libraries/LibAppStorage.sol @@ -80,101 +80,149 @@ contract Modifiers { /// @notice Checks that method is called by a contract owner modifier onlyOwner() { - LibDiamond.enforceIsContractOwner(); + _onlyOwner(); _; } + function _onlyOwner() internal view { + LibDiamond.enforceIsContractOwner(); + } + /// @notice Checks that method is called by address with the `CREDIT_NFT_MANAGER_ROLE` role modifier onlyCreditNftManager() { + _onlyCreditNftManager(); + _; + } + + function _onlyCreditNftManager() internal view { require( LibAccessControl.hasRole(CREDIT_NFT_MANAGER_ROLE, msg.sender), "Caller is not a Credit NFT manager" ); - _; } /// @notice Checks that method is called by address with the `DEFAULT_ADMIN_ROLE` role modifier onlyAdmin() { + _onlyAdmin(); + _; + } + + function _onlyAdmin() internal view { require( LibAccessControl.hasRole(DEFAULT_ADMIN_ROLE, msg.sender), "Manager: Caller is not admin" ); - _; } /// @notice Checks that method is called by address with the `GOVERNANCE_TOKEN_MINTER_ROLE` role modifier onlyMinter() { + _onlyMinter(); + _; + } + + function _onlyMinter() internal view { require( LibAccessControl.hasRole(GOVERNANCE_TOKEN_MINTER_ROLE, msg.sender), "Governance token: not minter" ); - _; } /// @notice Checks that method is called by address with the `GOVERNANCE_TOKEN_BURNER_ROLE` role modifier onlyBurner() { + _onlyBurner(); + _; + } + + function _onlyBurner() internal view { require( LibAccessControl.hasRole(GOVERNANCE_TOKEN_BURNER_ROLE, msg.sender), "Governance token: not burner" ); - _; } /// @notice Modifier to make a function callable only when the contract is not paused modifier whenNotPaused() { - require(!LibAccessControl.paused(), "Pausable: paused"); + _whenNotPaused(); _; } + function _whenNotPaused() internal view { + require(!LibAccessControl.paused(), "Pausable: paused"); + } + /// @notice Modifier to make a function callable only when the contract is paused modifier whenPaused() { - require(LibAccessControl.paused(), "Pausable: not paused"); + _whenPaused(); _; } + function _whenPaused() internal view { + require(LibAccessControl.paused(), "Pausable: not paused"); + } + /// @notice Checks that method is called by address with the `STAKING_MANAGER_ROLE` role modifier onlyStakingManager() { + _onlyStakingManager(); + _; + } + + function _onlyStakingManager() internal view { require( LibAccessControl.hasRole(STAKING_MANAGER_ROLE, msg.sender), "not manager" ); - _; } /// @notice Checks that method is called by address with the `PAUSER_ROLE` role modifier onlyPauser() { + _onlyPauser(); + _; + } + + function _onlyPauser() internal view { require( LibAccessControl.hasRole(PAUSER_ROLE, msg.sender), "not pauser" ); - _; } /// @notice Checks that method is called by address with the `GOVERNANCE_TOKEN_MANAGER_ROLE` role modifier onlyTokenManager() { + _onlyTokenManager(); + _; + } + + function _onlyTokenManager() internal view { require( LibAccessControl.hasRole(GOVERNANCE_TOKEN_MANAGER_ROLE, msg.sender), "MasterChef: not Governance Token manager" ); - _; } /// @notice Checks that method is called by address with the `INCENTIVE_MANAGER_ROLE` role modifier onlyIncentiveAdmin() { + _onlyIncentiveAdmin(); + _; + } + + function _onlyIncentiveAdmin() internal view { require( LibAccessControl.hasRole(INCENTIVE_MANAGER_ROLE, msg.sender), "CreditCalc: not admin" ); - _; } /// @notice Checks that method is called by address with the `CURVE_DOLLAR_MANAGER_ROLE` role modifier onlyDollarManager() { + _onlyDollarManager(); + _; + } + + function _onlyDollarManager() internal view { require( LibAccessControl.hasRole(CURVE_DOLLAR_MANAGER_ROLE, msg.sender), "CurveIncentive: Caller is not Ubiquity Dollar" ); - _; } /// @notice Initializes reentrancy guard on contract deployment diff --git a/packages/contracts/src/dollar/libraries/LibChef.sol b/packages/contracts/src/dollar/libraries/LibChef.sol index 0d2a07003..c600e72e3 100644 --- a/packages/contracts/src/dollar/libraries/LibChef.sol +++ b/packages/contracts/src/dollar/libraries/LibChef.sol @@ -123,8 +123,11 @@ library LibChef { "_stakingShareIDs array not same length" ); - for (uint256 i = 0; i < lgt; ++i) { + for (uint256 i; i < lgt;) { deposit(_tos[i], _amounts[i], _stakingShareIDs[i]); + unchecked { + ++i; + } } } diff --git a/packages/contracts/src/dollar/libraries/LibDiamond.sol b/packages/contracts/src/dollar/libraries/LibDiamond.sol index 9a2546e15..4f3493acf 100644 --- a/packages/contracts/src/dollar/libraries/LibDiamond.sol +++ b/packages/contracts/src/dollar/libraries/LibDiamond.sol @@ -120,7 +120,6 @@ library LibDiamond { for ( uint256 facetIndex; facetIndex < _diamondCut.length; - facetIndex++ ) { IDiamondCut.FacetCutAction action = _diamondCut[facetIndex].action; if (action == IDiamondCut.FacetCutAction.Add) { @@ -141,6 +140,9 @@ library LibDiamond { } else { revert("LibDiamondCut: Incorrect FacetCutAction"); } + unchecked { + ++facetIndex; + } } emit DiamondCut(_diamondCut, _init, _calldata); initializeDiamondCut(_init, _calldata); @@ -174,7 +176,6 @@ library LibDiamond { for ( uint256 selectorIndex; selectorIndex < _functionSelectors.length; - selectorIndex++ ) { bytes4 selector = _functionSelectors[selectorIndex]; address oldFacetAddress = ds @@ -186,6 +187,9 @@ library LibDiamond { ); addFunction(ds, selector, selectorPosition, _facetAddress); selectorPosition++; + unchecked { + ++selectorIndex; + } } } @@ -217,7 +221,6 @@ library LibDiamond { for ( uint256 selectorIndex; selectorIndex < _functionSelectors.length; - selectorIndex++ ) { bytes4 selector = _functionSelectors[selectorIndex]; address oldFacetAddress = ds @@ -230,6 +233,9 @@ library LibDiamond { removeFunction(ds, oldFacetAddress, selector); addFunction(ds, selector, selectorPosition, _facetAddress); selectorPosition++; + unchecked { + ++selectorIndex; + } } } @@ -255,13 +261,15 @@ library LibDiamond { for ( uint256 selectorIndex; selectorIndex < _functionSelectors.length; - selectorIndex++ ) { bytes4 selector = _functionSelectors[selectorIndex]; address oldFacetAddress = ds .selectorToFacetAndPosition[selector] .facetAddress; removeFunction(ds, oldFacetAddress, selector); + unchecked { + ++selectorIndex; + } } } diff --git a/packages/contracts/src/dollar/libraries/LibDirectGovernanceFarmer.sol b/packages/contracts/src/dollar/libraries/LibDirectGovernanceFarmer.sol index 102c86aca..7fed3f2fa 100644 --- a/packages/contracts/src/dollar/libraries/LibDirectGovernanceFarmer.sol +++ b/packages/contracts/src/dollar/libraries/LibDirectGovernanceFarmer.sol @@ -454,10 +454,14 @@ library LibDirectGovernanceFarmer { uint256[] memory idList, uint256 id ) internal pure returns (bool) { - for (uint256 i = 0; i < idList.length; i++) { + uint256 length = idList.length; + for (uint256 i; i < length;) { if (idList[i] == id) { return true; } + unchecked { + ++i; + } } return false; } diff --git a/packages/contracts/src/dollar/libraries/LibUbiquityPool.sol b/packages/contracts/src/dollar/libraries/LibUbiquityPool.sol index 2f2a90a35..c1ac8e206 100644 --- a/packages/contracts/src/dollar/libraries/LibUbiquityPool.sol +++ b/packages/contracts/src/dollar/libraries/LibUbiquityPool.sol @@ -167,6 +167,11 @@ library LibUbiquityPool { * @param collateralIndex Collateral token index */ modifier collateralEnabled(uint256 collateralIndex) { + _collateralEnabled(collateralIndex); + _; + } + + function _collateralEnabled(uint256 collateralIndex) internal view { UbiquityPoolStorage storage poolStorage = ubiquityPoolStorage(); require( poolStorage.isCollateralEnabled[ @@ -174,19 +179,22 @@ library LibUbiquityPool { ], "Collateral disabled" ); - _; } /** * @notice Checks whether a caller is the AMO minter address */ modifier onlyAmoMinter() { + _onlyAmoMinter(); + _; + } + + function _onlyAmoMinter() internal view { UbiquityPoolStorage storage poolStorage = ubiquityPoolStorage(); require( poolStorage.isAmoMinterEnabled[msg.sender], "Not an AMO Minter" ); - _; } //===================== @@ -252,11 +260,14 @@ library LibUbiquityPool { UbiquityPoolStorage storage poolStorage = ubiquityPoolStorage(); uint256 collateralTokensCount = poolStorage.collateralAddresses.length; balanceTally = 0; - for (uint256 i = 0; i < collateralTokensCount; i++) { + for (uint256 i; i < collateralTokensCount;) { balanceTally += freeCollateralBalance(i) .mul(10 ** poolStorage.missingDecimals[i]) .mul(poolStorage.collateralPrices[i]) .div(UBIQUITY_POOL_PRICE_PRECISION); + unchecked { + ++i; + } } } @@ -336,7 +347,7 @@ library LibUbiquityPool { UbiquityPoolStorage storage poolStorage = ubiquityPoolStorage(); require( - poolStorage.isMintPaused[collateralIndex] == false, + !poolStorage.isMintPaused[collateralIndex], "Minting is paused" ); @@ -408,7 +419,7 @@ library LibUbiquityPool { UbiquityPoolStorage storage poolStorage = ubiquityPoolStorage(); require( - poolStorage.isRedeemPaused[collateralIndex] == false, + !poolStorage.isRedeemPaused[collateralIndex], "Redeeming is paused" ); @@ -479,7 +490,7 @@ library LibUbiquityPool { UbiquityPoolStorage storage poolStorage = ubiquityPoolStorage(); require( - poolStorage.isRedeemPaused[collateralIndex] == false, + !poolStorage.isRedeemPaused[collateralIndex], "Redeeming is paused" ); require( @@ -491,7 +502,7 @@ library LibUbiquityPool { "Too soon to collect redemption" ); - bool sendCollateral = false; + bool sendCollateral; if ( poolStorage.redeemCollateralBalances[msg.sender][collateralIndex] > @@ -542,7 +553,7 @@ library LibUbiquityPool { uint256 priceFeedDecimals = priceFeed.decimals(); // validation - require(answer > 0, "Invalid price"); + require(answer != 0, "Invalid price"); require( block.timestamp - updatedAt < poolStorage.collateralPriceFeedStalenessThresholds[ @@ -580,7 +591,7 @@ library LibUbiquityPool { // checks to see if borrowing is paused require( - poolStorage.isBorrowPaused[minterCollateralIndex] == false, + !poolStorage.isBorrowPaused[minterCollateralIndex], "Borrowing is paused" ); diff --git a/packages/contracts/src/dollar/libraries/UintUtils.sol b/packages/contracts/src/dollar/libraries/UintUtils.sol index 63702794a..2bad00005 100644 --- a/packages/contracts/src/dollar/libraries/UintUtils.sol +++ b/packages/contracts/src/dollar/libraries/UintUtils.sol @@ -77,7 +77,7 @@ library UintUtils { return "0x00"; } - uint256 length = 0; + uint256 length; for (uint256 temp = value; temp != 0; temp >>= 8) { unchecked { diff --git a/packages/contracts/src/dollar/utils/SafeAddArray.sol b/packages/contracts/src/dollar/utils/SafeAddArray.sol index 5f5b14246..4151b17b6 100644 --- a/packages/contracts/src/dollar/utils/SafeAddArray.sol +++ b/packages/contracts/src/dollar/utils/SafeAddArray.sol @@ -13,10 +13,14 @@ library SafeAddArray { */ function add(uint256[] storage array, uint256 value) internal { // slither-disable-next-line uninitialized-local - for (uint256 i; i < array.length; i++) { + uint256 length = array.length; + for (uint256 i; i < length;) { if (array[i] == value) { return; } + unchecked { + ++i; + } } array.push(value); } @@ -29,8 +33,8 @@ library SafeAddArray { function add(uint256[] storage array, uint256[] memory values) internal { // slither-disable-next-line uninitialized-local for (uint256 i; i < values.length; ) { - bool exist = false; - for (uint256 j = 0; j < array.length; j++) { + bool exist; + for (uint256 j; j < array.length; j++) { if (array[j] == values[i]) { exist = true; break; diff --git a/packages/contracts/src/ubiquistick/SimpleBond.sol b/packages/contracts/src/ubiquistick/SimpleBond.sol index 759ec85e8..c77ede055 100644 --- a/packages/contracts/src/ubiquistick/SimpleBond.sol +++ b/packages/contracts/src/ubiquistick/SimpleBond.sol @@ -55,11 +55,19 @@ contract SimpleBond is ISimpleBond, Ownable, Pausable { /// @notice onlySticker : no NFT stick address defined OR sender has at least one NFT Stick modifier onlySticker() { + _onlySticker(); + _; + } + + function _onlySticker() internal view { require( sticker == address(0) || IERC721(sticker).balanceOf(msg.sender) > 0, "Not NFT Stick owner" ); - _; + } + + function _NotZeroAddress(address _address) internal pure{ + require(_address != address(0), "Invalid address"); } /// @notice Set sticker @@ -76,7 +84,7 @@ contract SimpleBond is ISimpleBond, Ownable, Pausable { uint256 vestingBlocks_, address treasury_ ) { - require(tokenRewards_ != address(0), "Invalid Reward token"); + _NotZeroAddress(tokenRewards_); tokenRewards = tokenRewards_; setVestingBlocks(vestingBlocks_); setTreasury(treasury_); @@ -89,7 +97,7 @@ contract SimpleBond is ISimpleBond, Ownable, Pausable { address token, uint256 tokenRewardsRatio ) public override onlyOwner { - require(token != address(0), "Invalid Reward token"); + _NotZeroAddress(token); rewardsRatio[token] = tokenRewardsRatio; emit LogSetRewards(token, tokenRewardsRatio); @@ -100,14 +108,14 @@ contract SimpleBond is ISimpleBond, Ownable, Pausable { function setVestingBlocks( uint256 vestingBlocks_ ) public override onlyOwner { - require(vestingBlocks_ > 0, "Invalid Vesting blocks number"); + require(vestingBlocks_ != 0, "Invalid Vesting blocks number"); vestingBlocks = vestingBlocks_; } /// @notice Set treasury address /// @param treasury_ treasury address function setTreasury(address treasury_) public override onlyOwner { - require(treasury_ != address(0), "Invalid Treasury address"); + _NotZeroAddress(treasury_); treasury = treasury_; } @@ -129,7 +137,7 @@ contract SimpleBond is ISimpleBond, Ownable, Pausable { address token, uint256 amount ) public override whenNotPaused onlySticker returns (uint256 bondId) { - require(rewardsRatio[token] > 0, "Token not allowed"); + require(rewardsRatio[token] != 0, "Token not allowed"); // @dev throws if not enough allowance or tokens for address // @dev must set token allowance for this smart contract previously @@ -145,7 +153,7 @@ contract SimpleBond is ISimpleBond, Ownable, Pausable { uint256 rewards = (amount * rewardsRatio[token]) / 1_000_000_000; bondState.rewards = rewards; - totalRewards += rewards; + totalRewards = totalRewards + rewards; bondId = bonds[msg.sender].length; bonds[msg.sender].push(bondState); @@ -164,7 +172,7 @@ contract SimpleBond is ISimpleBond, Ownable, Pausable { /// @return claimed Rewards claimed successfully function claim() public override whenNotPaused returns (uint256 claimed) { for ( - uint256 index = 0; + uint256 index; (index < bonds[msg.sender].length); index += 1 ) { @@ -182,7 +190,7 @@ contract SimpleBond is ISimpleBond, Ownable, Pausable { if (claimAmount > 0) { bondState.claimed += claimAmount; - totalClaimedRewards += claimAmount; + totalClaimedRewards = totalClaimedRewards + claimAmount; assert(bondState.claimed <= bondState.rewards); IUAR(tokenRewards).raiseCapital(claimAmount); @@ -220,7 +228,7 @@ contract SimpleBond is ISimpleBond, Ownable, Pausable { uint256 rewardsClaimable ) { - for (uint256 index = 0; index < bonds[addr].length; index += 1) { + for (uint256 index; index < bonds[addr].length; index += 1) { ( uint256 bondRewards, uint256 bondClaimedRewards, diff --git a/packages/contracts/src/ubiquistick/UbiquiStick.sol b/packages/contracts/src/ubiquistick/UbiquiStick.sol index 9f4e7b8ad..5fc5e900e 100644 --- a/packages/contracts/src/ubiquistick/UbiquiStick.sol +++ b/packages/contracts/src/ubiquistick/UbiquiStick.sol @@ -45,10 +45,14 @@ contract UbiquiStick is uint256 private constant _INVISIBLE_TYPE = 2; modifier onlyMinter() { - require(msg.sender == minter, "Not minter"); + _onlyMinter(); _; } + function _onlyMinter() internal view { + require(msg.sender == minter, "Not minter"); + } + constructor() ERC721("The UbiquiStick", "KEY") { setMinter(msg.sender); } @@ -99,8 +103,11 @@ contract UbiquiStick is } function batchSafeMint(address to, uint256 count) public onlyMinter { - for (uint256 i = 0; i < count; i++) { + for (uint256 i; i < count;) { safeMint(to); + unchecked { + ++i; + } } } diff --git a/packages/contracts/src/ubiquistick/UbiquiStickSale.sol b/packages/contracts/src/ubiquistick/UbiquiStickSale.sol index 9a2069223..181ea4fce 100644 --- a/packages/contracts/src/ubiquistick/UbiquiStickSale.sol +++ b/packages/contracts/src/ubiquistick/UbiquiStickSale.sol @@ -38,13 +38,17 @@ contract UbiquiStickSale is Ownable, ReentrancyGuard { constructor() {} + function _NotZeroAddress(address _address) internal pure{ + require(_address != address(0), "Invalid address"); + } + function setTokenContract(address _newTokenContract) external onlyOwner { - require(_newTokenContract != address(0), "Invalid Address"); + _NotZeroAddress(_newTokenContract); tokenContract = IUbiquiStick(_newTokenContract); } function setFundsAddress(address _address) external onlyOwner { - require(_address != address(0), "Invalid Address"); + _NotZeroAddress(_address); fundsAddress = _address; } @@ -54,7 +58,7 @@ contract UbiquiStickSale is Ownable, ReentrancyGuard { uint256 _count, uint256 _price ) public onlyOwner { - require(_address != address(0), "Invalid Address"); + _NotZeroAddress(_address); _allowances[_address] = Purchase(_count, _price); } @@ -66,8 +70,11 @@ contract UbiquiStickSale is Ownable, ReentrancyGuard { ) external onlyOwner { uint256 count = _addresses.length; - for (uint16 i = 0; i < count; i++) { + for (uint16 i; i < count;) { setAllowance(_addresses[i], _counts[i], _prices[i]); + unchecked { + ++i; + } } } @@ -92,7 +99,7 @@ contract UbiquiStickSale is Ownable, ReentrancyGuard { // and had enough allowance with enough funds uint256 count; uint256 price; - uint256 paid = 0; + uint256 paid; (count, price) = allowance(msg.sender); require( count > 0, diff --git a/packages/contracts/test/diamond/facets/OwnershipFacet.t.sol b/packages/contracts/test/diamond/facets/OwnershipFacet.t.sol index abb518fa7..579dfbf40 100644 --- a/packages/contracts/test/diamond/facets/OwnershipFacet.t.sol +++ b/packages/contracts/test/diamond/facets/OwnershipFacet.t.sol @@ -38,7 +38,7 @@ contract OwnershipFacetTest is DiamondTestSetup { vm.prank(owner); vm.expectRevert( abi.encodePacked( - "OwnershipFacet: New owner cannot be the zero address" + "OwnershipFacet: Can't address(0)" ) ); ownershipFacet.transferOwnership(address(0)); diff --git a/packages/contracts/test/dollar/core/CreditNft.t.sol b/packages/contracts/test/dollar/core/CreditNft.t.sol index c8cc5f9df..acb1f5ea6 100644 --- a/packages/contracts/test/dollar/core/CreditNft.t.sol +++ b/packages/contracts/test/dollar/core/CreditNft.t.sol @@ -45,7 +45,7 @@ contract CreditNftTest is LocalTestHelper { } function testMintCreditNft_ShouldRevert_WhenNotCreditNftManager() public { - vm.expectRevert("Caller is not a CreditNft manager"); + vm.expectRevert("CreditNft: not CreditNft manager"); creditNft.mintCreditNft(address(0x123), 1, 100); } @@ -67,7 +67,7 @@ contract CreditNftTest is LocalTestHelper { } function testBurnCreditNft_ShouldRevert_WhenNotCreditNftManager() public { - vm.expectRevert("Caller is not a CreditNft manager"); + vm.expectRevert("CreditNft: not CreditNft manager"); creditNft.burnCreditNft(address(0x123), 1, 100); } diff --git a/packages/contracts/test/ubiquistick/UbiquiStickSale.t.sol b/packages/contracts/test/ubiquistick/UbiquiStickSale.t.sol index dabfd25eb..c539623e0 100644 --- a/packages/contracts/test/ubiquistick/UbiquiStickSale.t.sol +++ b/packages/contracts/test/ubiquistick/UbiquiStickSale.t.sol @@ -34,7 +34,7 @@ contract UbiquiStickSaleTest is Test { function testSetTokenContract_ShouldRevert_IfAddressIsZero() public { vm.prank(owner); - vm.expectRevert("Invalid Address"); + vm.expectRevert("Invalid address"); ubiquiStickSale.setTokenContract(address(0)); } @@ -55,7 +55,7 @@ contract UbiquiStickSaleTest is Test { function testSetFundsAddress_ShouldRevert_IfAddressIsZero() public { vm.prank(owner); - vm.expectRevert("Invalid Address"); + vm.expectRevert("Invalid address"); ubiquiStickSale.setFundsAddress(address(0)); } @@ -73,7 +73,7 @@ contract UbiquiStickSaleTest is Test { function testSetAllowance_ShouldRevert_IfAddressIsZero() public { vm.prank(owner); - vm.expectRevert("Invalid Address"); + vm.expectRevert("Invalid address"); ubiquiStickSale.setAllowance(address(0), 1, 1); } From e24ddbd366448ae353ba53444a0a12e9168640df Mon Sep 17 00:00:00 2001 From: 0xRizwan Date: Tue, 13 Feb 2024 17:50:15 +0530 Subject: [PATCH 2/4] gas optimization --- packages/contracts/src/dollar/core/CreditNft.sol | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/contracts/src/dollar/core/CreditNft.sol b/packages/contracts/src/dollar/core/CreditNft.sol index 5771cecdb..d0f50546d 100644 --- a/packages/contracts/src/dollar/core/CreditNft.sol +++ b/packages/contracts/src/dollar/core/CreditNft.sol @@ -65,7 +65,7 @@ contract CreditNft is ERC1155Ubiquity, ICreditNft { /// @param _manager Address of the manager of the contract function initialize(address _manager) public initializer { __ERC1155Ubiquity_init(_manager, "URI"); - _totalOutstandingDebt; + _totalOutstandingDebt = 0; } /** From 6b48390b7a2e3854a49a8dd226e87187435a45bf Mon Sep 17 00:00:00 2001 From: 0xRizwan Date: Tue, 13 Feb 2024 20:21:06 +0530 Subject: [PATCH 3/4] fix: gas optimization --- packages/contracts/.gas-snapshot | 344 ------------------------------- 1 file changed, 344 deletions(-) delete mode 100644 packages/contracts/.gas-snapshot diff --git a/packages/contracts/.gas-snapshot b/packages/contracts/.gas-snapshot deleted file mode 100644 index aa0e9b2d2..000000000 --- a/packages/contracts/.gas-snapshot +++ /dev/null @@ -1,344 +0,0 @@ -AccessControlFacetTest:testGetRoleAdmin_ShouldReturnAdminRole() (gas: 12860) -AccessControlFacetTest:testGrantRole_ShouldRevertWhenNotAdmin() (gas: 64969) -AccessControlFacetTest:testGrantRole_ShouldWork() (gas: 76801) -AccessControlFacetTest:testHasRole_ShouldReturnTrue() (gas: 78349) -AccessControlFacetTest:testRenounceRole_ShouldWork() (gas: 64776) -AccessControlFacetTest:testRevokeRole_ShouldRevertWhenNotAdmin() (gas: 65033) -AccessControlFacetTest:testRevokeRole_ShouldWork() (gas: 65462) -BondedStateTest:testBondsCount_ShouldReturnCorrectCount() (gas: 19376) -BondedStateTest:testClaimBond_ShouldEmitLogClaimAndClaimBondRewards(uint256) (runs: 256, μ: 39474, ~: 39225) -BondedStateTest:testClaim_ShouldClaimRewards(uint256) (runs: 256, μ: 79835, ~: 79586) -BondedStateTest:testRewardsBondOf_ShouldReturnCorrectValues(uint256,uint256) (runs: 256, μ: 35467, ~: 35379) -BondedStateTest:testRewardsOf_ShouldReturnRewardsOfBond(uint256) (runs: 256, μ: 430178, ~: 429929) -BondedStateTest:testWithdraw_ShouldWithdrawBondTokens(uint256) (runs: 256, μ: 62535, ~: 62489) -CollectableDustFacetTest:testSendDust_ShouldRevertWhenPartOfTheProtocol() (gas: 173094) -CollectableDustFacetTest:testSendDust_ShouldWork() (gas: 61823) -CollectableDustFacetTest:testSendDust_ShouldWorkWhenNotPartOfTheProtocol() (gas: 173164) -CreditClockFacetTest:testGetManager_ShouldGet() (gas: 12829) -CreditClockFacetTest:testGetRate_ShouldRevert_WhenBlockIsInThePast() (gas: 14093) -CreditClockFacetTest:testSetManager_ShouldRevert_WhenNotAdmin() (gas: 16307) -CreditClockFacetTest:testSetManager_ShouldSetDiamond() (gas: 43832) -CreditClockFacetTest:testSetRatePerBlock_Default() (gas: 68668) -CreditClockFacetTest:testSetRatePerBlock_ShouldRevert_WhenNotAdmin() (gas: 16724) -CreditNftManagerFacetTest:test_burnCreditNftForCreditRevertsIfExpired() (gas: 19018) -CreditNftManagerFacetTest:test_burnCreditNftForCreditRevertsIfNotEnoughBalance() (gas: 29484) -CreditNftManagerFacetTest:test_burnCreditNftForCreditWorks() (gas: 399164) -CreditNftManagerFacetTest:test_burnCreditTokensForDollarsIfNotEnoughBalance() (gas: 47015) -CreditNftManagerFacetTest:test_burnCreditTokensForDollarsRevertsIfPriceLowerThan1Ether() (gas: 32261) -CreditNftManagerFacetTest:test_burnCreditTokensForDollarsWorks() (gas: 228998) -CreditNftManagerFacetTest:test_burnExpiredCreditNftForGovernanceRevertsIfNotEnoughBalance() (gas: 264114) -CreditNftManagerFacetTest:test_burnExpiredCreditNftForGovernanceRevertsIfNotExpired() (gas: 18956) -CreditNftManagerFacetTest:test_burnExpiredCreditNftForGovernanceWorks() (gas: 391775) -CreditNftManagerFacetTest:test_exchangeDollarsForCreditNft() (gas: 460214) -CreditNftManagerFacetTest:test_exchangeDollarsForCreditRevertsIfPriceHigherThan1Ether() (gas: 29305) -CreditNftManagerFacetTest:test_exchangeDollarsForCreditWorks() (gas: 278587) -CreditNftManagerFacetTest:test_mintClaimableDollars() (gas: 145197) -CreditNftManagerFacetTest:test_redeemCreditNftRevertsIfCreditNftExpired() (gas: 37011) -CreditNftManagerFacetTest:test_redeemCreditNftRevertsIfNotEnoughBalance() (gas: 398981) -CreditNftManagerFacetTest:test_redeemCreditNftRevertsIfNotEnoughDollars() (gas: 631739) -CreditNftManagerFacetTest:test_redeemCreditNftRevertsIfPriceLowerThan1Ether() (gas: 32296) -CreditNftManagerFacetTest:test_redeemCreditNftRevertsIfZeroAmountOfDollars() (gas: 522302) -CreditNftManagerFacetTest:test_redeemCreditNftWorks() (gas: 582306) -CreditNftManagerFacetTest:test_setCreditNftLength() (gas: 34084) -CreditNftManagerFacetTest:test_setExpiredCreditNftConversionRate() (gas: 36873) -CreditNftRedemptionCalculatorFacetTest:test_getCreditNftAmount() (gas: 282704) -CreditNftRedemptionCalculatorFacetTest:test_getCreditNftAmount_revertsIfDebtTooHigh() (gas: 273946) -CreditNftTest:testBurnCreditNft_ShouldBurnCreditNft() (gas: 290948) -CreditNftTest:testBurnCreditNft_ShouldRevert_WhenNotCreditNftManager() (gas: 26533) -CreditNftTest:testGetTotalOutstandingDebt_ReturnTotalDebt() (gas: 499531) -CreditNftTest:testMintCreditNft_ShouldMintCreditNft() (gas: 256463) -CreditNftTest:testMintCreditNft_ShouldRevert_WhenNotCreditNftManager() (gas: 26491) -CreditNftTest:testSetManager_ShouldRevert_WhenNotAdmin() (gas: 26706) -CreditNftTest:testSetManager_ShouldSetDiamond() (gas: 32747) -CreditNftTest:testUUPS_AdminAuth() (gas: 4251511) -CreditNftTest:testUUPS_ImplChanges() (gas: 4232727) -CreditNftTest:testUUPS_InitializedVersion() (gas: 8435061) -CreditNftTest:testUUPS_ShouldUpgradeAndCall() (gas: 4244335) -CreditNftTest:testUUPS_initialization() (gas: 4256064) -CreditNftTest:testUpdateTotalDebt_ShouldUpdateTotalDebt() (gas: 481012) -CreditRedemptionCalculatorFacetTest:testGetCreditAmount_ShouldReturnAmount() (gas: 73909) -CreditRedemptionCalculatorFacetTest:testGetCreditAmount_ShouldRevert_IfDebtIsTooHigh() (gas: 47371) -CreditRedemptionCalculatorFacetTest:testSetConstant_ShouldRevert_IfCalledNotByAdmin() (gas: 18307) -CreditRedemptionCalculatorFacetTest:testSetConstant_ShouldUpdateCoef() (gas: 26529) -CurveDollarIncentiveTest:testIncentivizeBuy() (gas: 95243) -CurveDollarIncentiveTest:testIncentivizeSell() (gas: 155277) -CurveDollarIncentiveTest:testIncentivizeShouldRevertIfSenderEqualToReceiver() (gas: 18653) -CurveDollarIncentiveTest:testIncentivizeShouldRevertWhenCallerNotUAD() (gas: 16169) -CurveDollarIncentiveTest:testSetExemptAddress_ShouldRevertOrSet_IfAdmin() (gas: 58163) -CurveDollarIncentiveTest:testSwitchBuyIncentive_ShouldRevertOrSwitch_IfAdmin() (gas: 54085) -CurveDollarIncentiveTest:testSwitchSellPenalty_ShouldRevertOrSwitch_IfAdmin() (gas: 53820) -DepositStateChefTest:testCannotGetRewardsOtherAccount() (gas: 28529) -DepositStateChefTest:testGetRewards(uint256) (runs: 256, μ: 255147, ~: 254897) -DepositStateChefTest:testGetStakingShareInfo() (gas: 18230) -DepositStateChefTest:testPendingGovernance(uint256) (runs: 256, μ: 40830, ~: 40578) -DepositStateChefTest:testRemoveLiquidity(uint256,uint256) (runs: 256, μ: 445665, ~: 447653) -DepositStateChefTest:testTotalShares() (gas: 14908) -DepositStateTest:testCannotGetRewardsOtherAccount() (gas: 28529) -DepositStateTest:testGetRewards(uint256) (runs: 256, μ: 255082, ~: 254897) -DepositStateTest:testGetStakingShareInfo() (gas: 18230) -DepositStateTest:testPendingGovernance(uint256) (runs: 256, μ: 40855, ~: 40578) -DepositStateTest:testRemoveLiquidity(uint256,uint256) (runs: 256, μ: 445686, ~: 447653) -DepositStateTest:testTotalShares() (gas: 14908) -DiamondInitTest:test_Init() (gas: 1219549) -DiamondInitTest:test_NonReentrant() (gas: 2216114) -DirectGovernanceFarmerFacetTest:testDepositMultipleTokens_ShouldDepositTokens() (gas: 527804) -DirectGovernanceFarmerFacetTest:testDepositMultipleTokens_ShouldRevert_IfAmountsIsNotPositive() (gas: 19757) -DirectGovernanceFarmerFacetTest:testDepositMultipleTokens_ShouldRevert_IfDurationIsNotValid() (gas: 19787) -DirectGovernanceFarmerFacetTest:testDeposit_ShouldDepositTokens() (gas: 228062) -DirectGovernanceFarmerFacetTest:testDeposit_ShouldRevert_IfAmountIsNotPositive() (gas: 36560) -DirectGovernanceFarmerFacetTest:testDeposit_ShouldRevert_IfDurationIsNotValid() (gas: 36598) -DirectGovernanceFarmerFacetTest:testDeposit_ShouldRevert_IfTokenIsNotInMetapool() (gas: 34529) -DirectGovernanceFarmerFacetTest:testIsIdIncludedReturnFalseIfIdIsNotInTheList() (gas: 269775) -DirectGovernanceFarmerFacetTest:testIsIdIncludedReturnTrueIfIdIsInTheList() (gas: 269724) -DirectGovernanceFarmerFacetTest:testIsMetaPoolCoinReturnFalseIfTokenAddressIsNotInMetaPool() (gas: 26048) -DirectGovernanceFarmerFacetTest:testIsMetaPoolCoinReturnTrueIfToken0IsPassed() (gas: 28123) -DirectGovernanceFarmerFacetTest:testIsMetaPoolCoinReturnTrueIfToken1IsPassed() (gas: 28070) -DirectGovernanceFarmerFacetTest:testIsMetaPoolCoinReturnTrueIfToken2IsPassed() (gas: 27992) -DirectGovernanceFarmerFacetTest:testIsMetaPoolCoinReturnTrueIfUbiquityDollarTokenIsPassed() (gas: 28167) -DirectGovernanceFarmerFacetTest:testWithdrawMultiple_ShouldRevert_IfSenderIsNotBondOwner() (gas: 51400) -DirectGovernanceFarmerFacetTest:testWithdrawMultiple_ShouldWithdraw() (gas: 604954) -DirectGovernanceFarmerFacetTest:testWithdrawShouldRevertIfSenderIsNotBondOwner() (gas: 65295) -DirectGovernanceFarmerFacetTest:testWithdrawShouldRevertIfTokenIsNotInMetaPool() (gas: 34450) -DirectGovernanceFarmerFacetTest:test_IsMetaPoolCoin() (gas: 26020) -DirectGovernanceFarmerFacetTest:test_ShouldMint() (gas: 80978) -DirectGovernanceFarmerFacetTest:test_Should_DebugMockCall_And_Return_Selector() (gas: 8104) -DirectGovernanceFarmerFacetTest:test_WithdrawShouldWithdraw() (gas: 284127) -DollarMintCalculatorFacetTest:test_getDollarsToMintRevertsIfPriceLowerThan1USD() (gas: 29116) -DollarMintCalculatorFacetTest:test_getDollarsToMintWorks() (gas: 45178) -DollarMintExcessFacetTest:testFails_distributeDollarsWorks() (gas: 74024) -ERC20UbiquityDollarTest:testAllowance_ShouldReturnAllowance() (gas: 140983) -ERC20UbiquityDollarTest:testApprove_ShouldApproveAddressToTransferTokens() (gas: 139589) -ERC20UbiquityDollarTest:testBurnFrom_ShouldBurnTokensFromAddress() (gas: 157043) -ERC20UbiquityDollarTest:testBurnFrom_ShouldRevert_IfCalledNotByTheBurnerRole() (gas: 27999) -ERC20UbiquityDollarTest:testBurnFrom_ShouldRevert_IfContractIsPaused() (gas: 176974) -ERC20UbiquityDollarTest:testBurn_ShouldBurnTokens() (gas: 90967) -ERC20UbiquityDollarTest:testBurn_ShouldRevert_IfContractIsPaused() (gas: 53390) -ERC20UbiquityDollarTest:testMint_ShouldMintTokens() (gas: 85722) -ERC20UbiquityDollarTest:testMint_ShouldRevert_IfCalledNotByTheMinterRole() (gas: 28052) -ERC20UbiquityDollarTest:testMint_ShouldRevert_IfContractIsPaused() (gas: 59352) -ERC20UbiquityDollarTest:testName_ShouldReturnTokenName() (gas: 14705) -ERC20UbiquityDollarTest:testPause_ShouldPauseContract() (gas: 54319) -ERC20UbiquityDollarTest:testPause_ShouldRevert_IfCalledNotByThePauserRole() (gas: 26264) -ERC20UbiquityDollarTest:testPermit_ShouldIncreaseSpenderAllowance() (gas: 88157) -ERC20UbiquityDollarTest:testPermit_ShouldRevert_IfDeadlineExpired() (gas: 32619) -ERC20UbiquityDollarTest:testPermit_ShouldRevert_IfSignatureIsInvalid() (gas: 59194) -ERC20UbiquityDollarTest:testSetSymbol_ShouldRevert_IfMethodIsCalledNotByAdmin() (gas: 26676) -ERC20UbiquityDollarTest:testSetSymbol_ShouldSetSymbol() (gas: 37558) -ERC20UbiquityDollarTest:testSymbol_ShouldReturnSymbolName() (gas: 14747) -ERC20UbiquityDollarTest:testTransferFrom_ShouldRevert_IfContractIsPaused() (gas: 143494) -ERC20UbiquityDollarTest:testTransferFrom_ShouldTransferTokensFromAddress() (gas: 139606) -ERC20UbiquityDollarTest:testTransfer_ShouldRevert_IfContractIsPaused() (gas: 55673) -ERC20UbiquityDollarTest:testTransfer_ShouldTransferTokens() (gas: 117148) -ERC20UbiquityDollarTest:testUnpause_ShouldRevert_IfCalledNotByThePauserRole() (gas: 57131) -ERC20UbiquityDollarTest:testUnpause_ShouldUnpauseContract() (gas: 37026) -ManagerFacetTest:testCanCallGeneralFunctions_ShouldSucceed() (gas: 14938) -ManagerFacetTest:testDeployStableSwapPool_ShouldSucceed() (gas: 6516992) -ManagerFacetTest:testInitializeDollarTokenAddress_ShouldSucceed() (gas: 20213) -ManagerFacetTest:testSetCreditNftAddress_ShouldSucceed() (gas: 29163) -ManagerFacetTest:testSetCreditTokenAddress_ShouldSucceed() (gas: 29163) -ManagerFacetTest:testSetDollarMintCalculatorAddress_ShouldSucceed() (gas: 46219) -ManagerFacetTest:testSetDollarTokenAddress_ShouldSucceed() (gas: 20169) -ManagerFacetTest:testSetExcessDollarsDistributor_ShouldSucceed() (gas: 48822) -ManagerFacetTest:testSetFormulasAddress_ShouldSucceed() (gas: 46286) -ManagerFacetTest:testSetGovernanceTokenAddress_ShouldSucceed() (gas: 29140) -ManagerFacetTest:testSetIncentiveToDollar_ShouldSucceed() (gas: 77276) -ManagerFacetTest:testSetMasterChefAddress_ShouldSucceed() (gas: 46264) -ManagerFacetTest:testSetMinterRoleWhenInitializing_ShouldSucceed() (gas: 18635) -ManagerFacetTest:testSetStableSwapMetaPoolAddress_ShouldSucceed() (gas: 46265) -ManagerFacetTest:testSetStakingContractAddress_ShouldSucceed() (gas: 46241) -ManagerFacetTest:testSetStakingShareAddress_ShouldSucceed() (gas: 29143) -ManagerFacetTest:testSetSushiSwapPoolAddress_ShouldSucceed() (gas: 46308) -ManagerFacetTest:testSetTreasuryAddress_ShouldSucceed() (gas: 29143) -ManagerFacetTest:testSetTwapOracleAddress_ShouldSucceed() (gas: 18085) -OwnershipFacetTest:testTransferOwnership_ShouldRevertWhenNewOwnerIsZeroAddress() (gas: 23744) -OwnershipFacetTest:testTransferOwnership_ShouldRevertWhenNotOwner() (gas: 28175) -OwnershipFacetTest:testTransferOwnership_ShouldWorkWhenNewOwnerIsNotContract() (gas: 30393) -StakingFormulasFacetTest:testDurationMultiply_ShouldReturnAmount() (gas: 17469) -StakingFormulasFacetTest:test_correctedAmountToWithdraw_calcSharedAmount() (gas: 13737) -StakingFormulasFacetTest:test_correctedAmountToWithdraw_returnAmount() (gas: 10753) -StakingFormulasFacetTest:test_lpRewardsAddLiquidityNormalization((address,uint256,uint256,uint256,uint256,uint256),uint256[2],uint256) (runs: 256, μ: 12620, ~: 12620) -StakingFormulasFacetTest:test_lpRewardsRemoveLiquidityNormalization((address,uint256,uint256,uint256,uint256,uint256),uint256[2],uint256) (runs: 256, μ: 12619, ~: 12619) -StakingFormulasFacetTest:test_sharesForLP() (gas: 14997) -StakingShareTest:testGetStake_ShouldReturnStake() (gas: 64806) -StakingShareTest:testMint_ShouldMint(uint128,uint128,uint256) (runs: 256, μ: 324469, ~: 327423) -StakingShareTest:testMint_ShouldRevert_IfMintingToZeroAddress(uint128,uint128,uint256) (runs: 256, μ: 29236, ~: 29236) -StakingShareTest:testMint_ShouldRevert_IfNotMinter(uint128,uint128,uint256) (runs: 256, μ: 29237, ~: 29237) -StakingShareTest:testMint_ShouldRevert_IfPaused(uint128,uint128,uint256) (runs: 256, μ: 58034, ~: 58034) -StakingShareTest:testPause_ShouldPause() (gas: 42717) -StakingShareTest:testPause_ShouldRevert_IfNotPauser() (gas: 20428) -StakingShareTest:testSafeBatchTransferFrom_ShouldRevert_IfPaused() (gas: 64411) -StakingShareTest:testSafeBatchTransferFrom_ShouldTransferTokenIds() (gas: 308746) -StakingShareTest:testSafeTransferFrom_ShouldRevert_IfInsufficientBalance() (gas: 52786) -StakingShareTest:testSafeTransferFrom_ShouldRevert_IfPaused() (gas: 58983) -StakingShareTest:testSafeTransferFrom_ShouldRevert_IfToAddressZero() (gas: 47706) -StakingShareTest:testSafeTransferFrom_ShouldTransferTokenId() (gas: 168375) -StakingShareTest:testSetBaseUri_ShouldSetUri() (gas: 407162) -StakingShareTest:testSetUriSingle_ShouldSetUri() (gas: 186113) -StakingShareTest:testSetUri_ShouldRevert_IfGovernanceTokenNotStakingManager() (gas: 29596) -StakingShareTest:testSetUri_ShouldSetUri() (gas: 261424) -StakingShareTest:testTotalSupply_ShouldReturn_TotalSupply() (gas: 12560) -StakingShareTest:testUUPS_AdminAuth() (gas: 4413232) -StakingShareTest:testUUPS_ImplChanges() (gas: 4394360) -StakingShareTest:testUUPS_InitializedVersion() (gas: 8758239) -StakingShareTest:testUUPS_ShouldUpgradeAndCall() (gas: 4407024) -StakingShareTest:testUUPS_initialization() (gas: 4419554) -StakingShareTest:testUnpause_ShouldRevert_IfNotPauser() (gas: 49948) -StakingShareTest:testUnpause_ShouldUnpause() (gas: 34424) -StakingShareTest:testUpdateStake_ShouldRevert_IfNotMinter(uint128,uint128,uint256) (runs: 256, μ: 29136, ~: 29136) -StakingShareTest:testUpdateStake_ShouldRevert_IfPaused(uint128,uint128,uint256) (runs: 256, μ: 58041, ~: 58041) -StakingShareTest:testUpdateStake_ShouldUpdateStake(uint128,uint128,uint256) (runs: 256, μ: 169373, ~: 171896) -StickerStateTest:testBond(uint256) (runs: 256, μ: 216048, ~: 233190) -StickerStateTest:testBond_ShouldRevert_IfTokenNotAllowed() (gas: 25107) -TWAPOracleDollar3poolFacetTest:test_overall() (gas: 100698) -TWAPOracleDollar3poolFacetTest:test_setPoolRevertsWhenFirstAddressIsNotDollarToken() (gas: 1394475) -TestDiamond:testCutFacetAddSimplePureFacet() (gas: 174628) -TestDiamond:testCutFacetAddSimpleWriteFacet() (gas: 196782) -TestDiamond:testCutFacetAddWriteFacetWithInitializer() (gas: 225047) -TestDiamond:testCutFacetRemoveFacetFunctions() (gas: 169384) -TestDiamond:testCutFacetReplaceFacet() (gas: 278069) -TestDiamond:testCutFacetShouldRevertWhenAddToZeroAddress() (gas: 27297) -TestDiamond:testCutFacetShouldRevertWhenFacetInitializerReverts() (gas: 184092) -TestDiamond:testCutFacetShouldRevertWhenFunctionAlreadyExists() (gas: 33989) -TestDiamond:testCutFacetShouldRevertWhenNoSelectorsProvidedForFacetForCut() (gas: 23499) -TestDiamond:testCutFacetShouldRevertWhenNotOwner() (gas: 27327) -TestDiamond:testCutFacetShouldRevertWithMessageWhenFacetInitializerWithMessageReverts() (gas: 183915) -TestDiamond:testFacetsHaveCorrectSelectors() (gas: 505837) -TestDiamond:testHasMultipleFacets() (gas: 2372) -TestDiamond:testLoupeFacetAddressesEqualsTheListOfAvailableFacets() (gas: 297846) -TestDiamond:testSelectors_ShouldBeAssociatedWithCorrectFacet() (gas: 441622) -TestDiamond:test_ShouldSupportInspectingFacetsAndFunctions() (gas: 12937) -UbiquiStickSaleTest:testAllowance_ShouldReturnAllowance() (gas: 60675) -UbiquiStickSaleTest:testBatchSetAllowance_ShouldBatchSetAllowance() (gas: 112262) -UbiquiStickSaleTest:testBatchSetAllowance_ShouldRevert_IfCalledNotByOwner() (gas: 14242) -UbiquiStickSaleTest:testReceive_ShouldRevert_IfAllowanceIsInsufficient() (gas: 39370) -UbiquiStickSaleTest:testReceive_ShouldRevert_IfMaxSupplyIsReached() (gas: 119215412) -UbiquiStickSaleTest:testSetAllowance_ShouldRevert_IfAddressIsZero() (gas: 13142) -UbiquiStickSaleTest:testSetAllowance_ShouldRevert_IfCalledNotByOwner() (gas: 13267) -UbiquiStickSaleTest:testSetAllowance_ShouldSetAllowance() (gas: 60631) -UbiquiStickSaleTest:testSetFundsAddress_ShouldRevert_IfAddressIsZero() (gas: 13079) -UbiquiStickSaleTest:testSetFundsAddress_ShouldRevert_IfCalledNotByOwner() (gas: 13129) -UbiquiStickSaleTest:testSetFundsAddress_ShouldSetFundsAddress() (gas: 35745) -UbiquiStickSaleTest:testSetTokenContract_ShouldRevert_IfAddressIsZero() (gas: 13132) -UbiquiStickSaleTest:testSetTokenContract_ShouldRevert_IfCalledNotByOwner() (gas: 15190) -UbiquiStickSaleTest:testSetTokenContract_ShouldSetTokenContract() (gas: 37978) -UbiquiStickSaleTest:testWithdraw_ShouldRevert_IfCalledNotByOwner() (gas: 18004) -UbiquiStickSaleTest:testWithdraw_ShouldWithdraw() (gas: 69308) -UbiquiStickTest:testApprove_ShouldApprove() (gas: 169292) -UbiquiStickTest:testApprove_ShouldRevert_IfOperatorIsNotAllowed() (gas: 16151) -UbiquiStickTest:testBatchSafeMint_ShouldMintMultipleTokens() (gas: 257478) -UbiquiStickTest:testBatchSafeMint_ShouldRevert_IfCalledNotByMinter() (gas: 13244) -UbiquiStickTest:testBeforeConsecutiveTokenTransfer_ShouldRevert() (gas: 8818) -UbiquiStickTest:testConstructor_ShouldInitContract() (gas: 9871) -UbiquiStickTest:testRandom_ShouldReturnRandomValue() (gas: 7887) -UbiquiStickTest:testSafeMint_ShouldMint() (gas: 141192) -UbiquiStickTest:testSafeMint_ShouldMintGoldToken() (gas: 6808007) -UbiquiStickTest:testSafeMint_ShouldRevert_IfCalledNotByMinter() (gas: 13274) -UbiquiStickTest:testSafeTransferFromWith4Params_ShouldRevert_IfOperatorIsNotAllowed() (gas: 173382) -UbiquiStickTest:testSafeTransferFromWith4Params_ShouldTransferToken() (gas: 175109) -UbiquiStickTest:testSafeTransferFrom_ShouldRevert_IfOperatorIsNotAllowed() (gas: 172945) -UbiquiStickTest:testSafeTransferFrom_ShouldTransferToken() (gas: 174980) -UbiquiStickTest:testSetApprovalForAll_ShouldApproveOperatorToSpendAllTokens() (gas: 168854) -UbiquiStickTest:testSetApprovalForAll_ShouldRevert_IfOperatorIsNotAllowed() (gas: 143926) -UbiquiStickTest:testSetMinter_ShouldRevert_IfCalledNotByOwner() (gas: 13292) -UbiquiStickTest:testSetMinter_ShouldUpdateMinter() (gas: 18836) -UbiquiStickTest:testSetTokenURI_ShouldRevert_IfCalledNotByMinter() (gas: 13541) -UbiquiStickTest:testSupportsInterface_ShouldReturnFalse_IfInterfaceIsNotSupported() (gas: 5902) -UbiquiStickTest:testSupportsInterface_ShouldReturnTrue_IfInterfaceIsSupported() (gas: 5868) -UbiquiStickTest:testTokenURI_ShouldReturnTokenURIForTokenTypeGold() (gas: 6832847) -UbiquiStickTest:testTokenURI_ShouldReturnTokenURIForTokenTypeInvisible() (gas: 4967062) -UbiquiStickTest:testTokenURI_ShouldReturnTokenURIForTokenTypeStandard() (gas: 168668) -UbiquiStickTest:testTokenURI_ShouldRevert_IfTokenDoesNotExist() (gas: 12661) -UbiquiStickTest:testTransferFrom_ShouldRevert_IfOperatorIsNotAllowed() (gas: 172924) -UbiquiStickTest:testTransferFrom_ShouldTransferToken() (gas: 174578) -UbiquityCreditTokenTest:testRaiseCapital_ShouldMintTokens() (gas: 91771) -UbiquityCreditTokenTest:testSetManager_ShouldRevert_WhenNotAdmin() (gas: 26618) -UbiquityCreditTokenTest:testSetManager_ShouldSetManager() (gas: 32691) -UbiquityCreditTokenTest:testUUPS_AdminAuth() (gas: 3040241) -UbiquityCreditTokenTest:testUUPS_ImplChanges() (gas: 3023487) -UbiquityCreditTokenTest:testUUPS_InitializedVersion() (gas: 6013500) -UbiquityCreditTokenTest:testUUPS_ShouldUpgradeAndCall() (gas: 3032672) -UbiquityCreditTokenTest:testUUPS_initialization() (gas: 3046692) -UbiquityDollarTokenTest:testSetIncentiveContract_ShouldRevert_IfNotAdmin() (gas: 78389) -UbiquityDollarTokenTest:testSetManager_ShouldRevert_WhenNotAdmin() (gas: 26625) -UbiquityDollarTokenTest:testSetManager_ShouldSetManager() (gas: 32719) -UbiquityDollarTokenTest:testTransfer_ShouldCallIncentivize_IfValidTransfer() (gas: 291699) -UbiquityDollarTokenTest:testUUPS_AdminAuth() (gas: 3309713) -UbiquityDollarTokenTest:testUUPS_ImplChanges() (gas: 3291019) -UbiquityDollarTokenTest:testUUPS_InitializedVersion() (gas: 6552357) -UbiquityDollarTokenTest:testUUPS_ShouldUpgradeAndCall() (gas: 3302255) -UbiquityDollarTokenTest:testUUPS_initialization() (gas: 3305562) -UbiquityGovernanceTokenTest:testSetManager_ShouldRevert_WhenNotAdmin() (gas: 26646) -UbiquityGovernanceTokenTest:testSetManager_ShouldSetManager() (gas: 32719) -UbiquityGovernanceTokenTest:testUUPS_AdminAuth() (gas: 2987468) -UbiquityGovernanceTokenTest:testUUPS_ImplChanges() (gas: 2968752) -UbiquityGovernanceTokenTest:testUUPS_InitializedVersion() (gas: 5908190) -UbiquityGovernanceTokenTest:testUUPS_ShouldUpgradeAndCall() (gas: 2980294) -UbiquityGovernanceTokenTest:testUUPS_initialization() (gas: 2983228) -UbiquityPoolFacetTest:testAddAmoMinter_ShouldAddAmoMinter() (gas: 28622) -UbiquityPoolFacetTest:testAddAmoMinter_ShouldRevert_IfAmoMinterHasInvalidInterface() (gas: 22052) -UbiquityPoolFacetTest:testAddAmoMinter_ShouldRevert_IfAmoMinterIsZeroAddress() (gas: 18859) -UbiquityPoolFacetTest:testAddCollateralToken_ShouldAddNewTokenAsCollateral() (gas: 73204) -UbiquityPoolFacetTest:testAllCollaterals_ShouldReturnAllCollateralTokenAddresses() (gas: 18216) -UbiquityPoolFacetTest:testAmoMinterBorrow_ShouldBorrowCollateral() (gas: 75429) -UbiquityPoolFacetTest:testAmoMinterBorrow_ShouldRevert_IfBorrowingIsPaused() (gas: 53897) -UbiquityPoolFacetTest:testAmoMinterBorrow_ShouldRevert_IfCollateralIsDisabled() (gas: 38116) -UbiquityPoolFacetTest:testCollateralEnabled_ShouldRevert_IfCollateralIsDisabled() (gas: 31123) -UbiquityPoolFacetTest:testCollateralInformation_ShouldReturnCollateralInformation() (gas: 73184) -UbiquityPoolFacetTest:testCollateralInformation_ShouldRevert_IfCollateralIsDisabled() (gas: 34221) -UbiquityPoolFacetTest:testCollateralUsdBalance_ShouldReturnTotalAmountOfCollateralInUsd() (gas: 231170) -UbiquityPoolFacetTest:testCollectRedemption_ShouldCollectRedemption() (gas: 282896) -UbiquityPoolFacetTest:testCollectRedemption_ShouldRevert_IfNotEnoughBlocksHaveBeenMined() (gas: 24951) -UbiquityPoolFacetTest:testCollectRedemption_ShouldRevert_IfRedeemingIsPaused() (gas: 51124) -UbiquityPoolFacetTest:testFreeCollateralBalance_ShouldReturnCollateralAmountAvailableForBorrowingByAmoMinters() (gas: 294542) -UbiquityPoolFacetTest:testGetDollarInCollateral_ShouldReturnAmountOfDollarsWhichShouldBeMintedForInputCollateral() (gas: 19890) -UbiquityPoolFacetTest:testGetDollarPriceUsd_ShouldReturnDollarPriceInUsd() (gas: 28320) -UbiquityPoolFacetTest:testMintDollar_ShouldMintDollars() (gas: 234222) -UbiquityPoolFacetTest:testMintDollar_ShouldRevert_IfDollarPriceUsdIsTooLow() (gas: 58883) -UbiquityPoolFacetTest:testMintDollar_ShouldRevert_IfMintingIsPaused() (gas: 57822) -UbiquityPoolFacetTest:testMintDollar_ShouldRevert_OnCollateralAmountSlippage() (gas: 113771) -UbiquityPoolFacetTest:testMintDollar_ShouldRevert_OnDollarAmountSlippage() (gas: 113751) -UbiquityPoolFacetTest:testMintDollar_ShouldRevert_OnReachingPoolCeiling() (gas: 128498) -UbiquityPoolFacetTest:testOnlyAmoMinter_ShouldRevert_IfCalledNoByAmoMinter() (gas: 18315) -UbiquityPoolFacetTest:testRedeemDollar_ShouldRedeemCollateral() (gas: 294607) -UbiquityPoolFacetTest:testRedeemDollar_ShouldRevert_IfDollarPriceUsdIsTooHigh() (gas: 58827) -UbiquityPoolFacetTest:testRedeemDollar_ShouldRevert_IfRedeemingIsPaused() (gas: 57831) -UbiquityPoolFacetTest:testRedeemDollar_ShouldRevert_OnCollateralSlippage() (gas: 254835) -UbiquityPoolFacetTest:testRedeemDollar_ShouldRevert_OnInsufficientPoolCollateral() (gas: 126655) -UbiquityPoolFacetTest:testRemoveAmoMinter_ShouldRemoveAmoMinter() (gas: 23666) -UbiquityPoolFacetTest:testSetCollateralChainLinkPriceFeed_ShouldSetPriceFeed() (gas: 103379) -UbiquityPoolFacetTest:testSetFees_ShouldSetMintAndRedeemFees() (gas: 36637) -UbiquityPoolFacetTest:testSetPoolCeiling_ShouldSetMaxAmountOfTokensAllowedForCollateral() (gas: 96727) -UbiquityPoolFacetTest:testSetPriceThresholds_ShouldSetPriceThresholds() (gas: 26046) -UbiquityPoolFacetTest:testSetRedemptionDelayBlocks_ShouldSetRedemptionDelayInBlocks() (gas: 23266) -UbiquityPoolFacetTest:testToggleCollateral_ShouldToggleCollateral() (gas: 92448) -UbiquityPoolFacetTest:testToggleMintRedeemBorrow_ShouldToggleBorrowingByAmoMinter() (gas: 114544) -UbiquityPoolFacetTest:testToggleMintRedeemBorrow_ShouldToggleMinting() (gas: 114520) -UbiquityPoolFacetTest:testToggleMintRedeemBorrow_ShouldToggleRedeeming() (gas: 114570) -UbiquityPoolFacetTest:testUpdateChainLinkCollateralPrice_ShouldRevert_IfChainlinkAnswerIsInvalid() (gas: 34832) -UbiquityPoolFacetTest:testUpdateChainLinkCollateralPrice_ShouldRevert_IfChainlinkAnswerIsStale() (gas: 41693) -UbiquityPoolFacetTest:testUpdateChainLinkCollateralPrice_ShouldUpdateCollateralPrice() (gas: 110094) -ZeroStateBonding:testDeposit(uint32,uint256) (runs: 256, μ: 216387, ~: 219383) -ZeroStateBonding:testPurchaseTargetAmount(uint32,uint256) (runs: 256, μ: 26411, ~: 26459) -ZeroStateBonding:testPurchaseTargetAmountShouldRevertIfParamsNotSet() (gas: 17933) -ZeroStateBonding:testPurchaseTargetAmountShouldRevertIfSupplyZero() (gas: 17897) -ZeroStateBonding:testSetParams(uint32,uint256) (runs: 256, μ: 79023, ~: 79224) -ZeroStateBonding:testSetParamsShouldRevertNotAdmin() (gas: 24467) -ZeroStateBonding:testWithdraw(uint32,uint256) (runs: 256, μ: 203901, ~: 205489) -ZeroStateChefTest:testDepositFromZeroState(uint256) (runs: 256, μ: 454886, ~: 455877) -ZeroStateChefTest:testGetInitialGovernanceMul() (gas: 17707) -ZeroStateChefTest:testSetGovernanceDiv(uint256) (runs: 256, μ: 26475, ~: 26738) -ZeroStateChefTest:testSetGovernancePerBlock(uint256) (runs: 256, μ: 29301, ~: 29564) -ZeroStateChefTest:testSetGovernancePerBlock_ShouldRevertWhenNotAdmin() (gas: 18420) -ZeroStateChefTest:testSetGovernanceShareForTreasury_ShouldRevertWhenNotAdmin() (gas: 18444) -ZeroStateChefTest:testSetMinPriceDiff(uint256) (runs: 256, μ: 29204, ~: 29467) -ZeroStateChefTest:testSetMinPriceDiffToUpdateMultiplier_ShouldRevertWhenNotAdmin() (gas: 18387) -ZeroStateStakingTest:testCannotDepositZeroWeeks() (gas: 18230) -ZeroStateStakingTest:testCannotStakeMoreThan4Years(uint256) (runs: 256, μ: 22299, ~: 22246) -ZeroStateStakingTest:testDeposit_Staking(uint256,uint256) (runs: 256, μ: 442733, ~: 442786) -ZeroStateStakingTest:testLockupMultiplier() (gas: 749618) -ZeroStateStakingTest:testSetBlockCountInAWeek(uint256) (runs: 256, μ: 28921, ~: 29184) -ZeroStateStakingTest:testSetStakingDiscountMultiplier(uint256) (runs: 256, μ: 28941, ~: 29204) -ZeroStateTest:testSetRewards_ShouldSetRewards(uint256) (runs: 256, μ: 38477, ~: 39566) -ZeroStateTest:testSetSticker_ShouldSetSticker() (gas: 37850) -ZeroStateTest:testSetTreasury_ShouldSetTreasury() (gas: 18793) -ZeroStateTest:testSetVestingBlocks_ShouldSetVestingBlocks(uint256) (runs: 256, μ: 22549, ~: 22534) \ No newline at end of file From fcd09809821599437ffda3ca9dfe7231c40317a1 Mon Sep 17 00:00:00 2001 From: 0xRizwan Date: Tue, 13 Feb 2024 20:45:17 +0530 Subject: [PATCH 4/4] fix: gas optimization --- packages/contracts/src/dollar/core/CreditNft.sol | 4 ++-- packages/contracts/src/dollar/utils/SafeAddArray.sol | 6 +++--- packages/contracts/src/ubiquistick/UbiquiStickSale.sol | 2 +- 3 files changed, 6 insertions(+), 6 deletions(-) diff --git a/packages/contracts/src/dollar/core/CreditNft.sol b/packages/contracts/src/dollar/core/CreditNft.sol index d0f50546d..f500a17c0 100644 --- a/packages/contracts/src/dollar/core/CreditNft.sol +++ b/packages/contracts/src/dollar/core/CreditNft.sol @@ -124,7 +124,7 @@ contract CreditNft is ERC1155Ubiquity, ICreditNft { * @dev Should be called prior to any state changing functions */ function updateTotalDebt() public { - bool reachedEndOfExpiredKeys; + bool reachedEndOfExpiredKeys=false; uint256 currentBlockNumber = _sortedBlockNumbers.popFront(); uint256 outstandingDebt = _totalOutstandingDebt; //if list is empty, currentBlockNumber will be 0 @@ -150,7 +150,7 @@ contract CreditNft is ERC1155Ubiquity, ICreditNft { /// @notice Returns outstanding debt by fetching current tally and removing any expired debt function getTotalOutstandingDebt() public view returns (uint256) { uint256 outstandingDebt = _totalOutstandingDebt; - bool reachedEndOfExpiredKeys; + bool reachedEndOfExpiredKeys = false; (, uint256 currentBlockNumber) = _sortedBlockNumbers.getNextNode(0); while (!reachedEndOfExpiredKeys && currentBlockNumber != 0) { diff --git a/packages/contracts/src/dollar/utils/SafeAddArray.sol b/packages/contracts/src/dollar/utils/SafeAddArray.sol index 4151b17b6..9e330803e 100644 --- a/packages/contracts/src/dollar/utils/SafeAddArray.sol +++ b/packages/contracts/src/dollar/utils/SafeAddArray.sol @@ -14,7 +14,7 @@ library SafeAddArray { function add(uint256[] storage array, uint256 value) internal { // slither-disable-next-line uninitialized-local uint256 length = array.length; - for (uint256 i; i < length;) { + for (uint256 i=0; i < length;) { if (array[i] == value) { return; } @@ -32,8 +32,8 @@ library SafeAddArray { */ function add(uint256[] storage array, uint256[] memory values) internal { // slither-disable-next-line uninitialized-local - for (uint256 i; i < values.length; ) { - bool exist; + for (uint256 i=0; i < values.length; ) { + bool exist=false; for (uint256 j; j < array.length; j++) { if (array[j] == values[i]) { exist = true; diff --git a/packages/contracts/src/ubiquistick/UbiquiStickSale.sol b/packages/contracts/src/ubiquistick/UbiquiStickSale.sol index 181ea4fce..adccd0a6f 100644 --- a/packages/contracts/src/ubiquistick/UbiquiStickSale.sol +++ b/packages/contracts/src/ubiquistick/UbiquiStickSale.sol @@ -99,7 +99,7 @@ contract UbiquiStickSale is Ownable, ReentrancyGuard { // and had enough allowance with enough funds uint256 count; uint256 price; - uint256 paid; + uint256 paid = 0; (count, price) = allowance(msg.sender); require( count > 0,