Skip to content

Commit

Permalink
Merge pull request ubiquity#708 from molecula451/new-warnings-fix
Browse files Browse the repository at this point in the history
New warnings fix Solidity
  • Loading branch information
rndquu authored Jun 27, 2023
2 parents 2a330ba + c4c0295 commit 9e19bc0
Show file tree
Hide file tree
Showing 19 changed files with 57 additions and 94 deletions.
4 changes: 3 additions & 1 deletion .github/workflows/build-and-test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ jobs:
- name: Setup Foundry
uses: foundry-rs/foundry-toolchain@v1
with:
version: nightly-87bc53fc6c874bd4c92d97ed180b949e3a36d78c
version: nightly-ed5eb9796aefe8cccc8d56676aa90ff68d7edfd4

- name: Yarn Install
run: yarn install --mode=skip-build && yarn allow-scripts
Expand All @@ -43,6 +43,8 @@ jobs:
run: yarn workspace @ubiquity/contracts forge:install

- name: Build All
env:
FOUNDRY_DENY_WARNINGS: true
run: yarn build

- name: Test All
Expand Down
1 change: 1 addition & 0 deletions packages/contracts/foundry.toml
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ out = 'out'
libs = ['lib']
script = 'scripts'
solc_version = '0.8.19'
evm_version = 'shanghai'
extra_output = [
"abi",
"evm.bytecode",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -145,7 +145,7 @@ contract DiamondScript is Constants {
vm.stopBroadcast();
}

function setFacet(IDiamondCut.FacetCut[] memory cuts) internal {
function setFacet(IDiamondCut.FacetCut[] memory cuts) internal view {
cuts[0] = (
IDiamondCut.FacetCut({
facetAddress: address(dCutFacet),
Expand Down
10 changes: 5 additions & 5 deletions packages/contracts/src/dollar/DirectGovernanceFarmer.sol
Original file line number Diff line number Diff line change
Expand Up @@ -73,11 +73,11 @@ contract DirectGovernanceFarmer is ReentrancyGuard {
//TODO create updateConfig method
/// Needs to check that Operator is Authorized, From is Valid, ID exists
function onERC1155Received(
address operator,
address from,
uint256 id,
uint256 value,
bytes calldata data
address /* operator */,
address /* from */,
uint256 /* id */,
uint256 /* value */,
bytes calldata /* data */
) public virtual returns (bytes4) {
// Called when receiving ERC1155 token at staking.
// operator: Staking contract
Expand Down
1 change: 0 additions & 1 deletion packages/contracts/src/dollar/core/CreditNft.sol
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,6 @@ contract CreditNft is ERC1155Ubiquity, ICreditNft {
bool reachedEndOfExpiredKeys = false;
uint256 currentBlockNumber = _sortedBlockNumbers.popFront();
uint256 outstandingDebt = _totalOutstandingDebt;
uint256 localTotalOutstandingDebt = outstandingDebt;
//if list is empty, currentBlockNumber will be 0
while (!reachedEndOfExpiredKeys && currentBlockNumber != 0) {
if (currentBlockNumber > block.number) {
Expand Down
4 changes: 2 additions & 2 deletions packages/contracts/src/dollar/core/StakingShare.sol
Original file line number Diff line number Diff line change
Expand Up @@ -60,8 +60,8 @@ contract StakingShare is ERC1155Ubiquity, ERC1155URIStorage {
*/
constructor(
address _manager,
string memory uri
) ERC1155Ubiquity(_manager, uri) {}
string memory _uri
) ERC1155Ubiquity(_manager, _uri) {}

/// @dev update stake LP amount , LP rewards debt and end block.
/// @param _stakeId staking share id
Expand Down
12 changes: 6 additions & 6 deletions packages/contracts/src/dollar/facets/BondingCurveFacet.sol
Original file line number Diff line number Diff line change
Expand Up @@ -21,15 +21,15 @@ contract BondingCurveFacet is Modifiers, IBondingCurve {
LibBondingCurve.setParams(_connectorWeight, _baseY);
}

function connectorWeight() external returns (uint32) {
function connectorWeight() external view returns (uint32) {
return LibBondingCurve.connectorWeight();
}

function baseY() external returns (uint256) {
function baseY() external view returns (uint256) {
return LibBondingCurve.baseY();
}

function poolBalance() external returns (uint256) {
function poolBalance() external view returns (uint256) {
return LibBondingCurve.poolBalance();
}

Expand All @@ -44,7 +44,7 @@ contract BondingCurveFacet is Modifiers, IBondingCurve {
LibBondingCurve.deposit(_collateralDeposited, _recipient);
}

function getShare(address _recipient) external returns (uint256) {
function getShare(address _recipient) external view returns (uint256) {
return LibBondingCurve.getShare(_recipient);
}

Expand All @@ -70,7 +70,7 @@ contract BondingCurveFacet is Modifiers, IBondingCurve {
uint32 _connectorWeight,
uint256 _supply,
uint256 _connectorBalance
) external returns (uint256) {
) external pure returns (uint256) {
return
LibBondingCurve.purchaseTargetAmount(
_tokensDeposited,
Expand Down Expand Up @@ -98,7 +98,7 @@ contract BondingCurveFacet is Modifiers, IBondingCurve {
uint256 _connectorWeight,
uint256 _baseX,
uint256 _baseY
) external returns (uint256) {
) external pure returns (uint256) {
return
LibBondingCurve.purchaseTargetAmountFromZero(
_tokensDeposited,
Expand Down
14 changes: 7 additions & 7 deletions packages/contracts/src/dollar/libraries/LibBondingCurve.sol
Original file line number Diff line number Diff line change
Expand Up @@ -53,15 +53,15 @@ library LibBondingCurve {
emit ParamsSet(_connectorWeight, _baseY);
}

function connectorWeight() internal returns (uint32) {
function connectorWeight() internal view returns (uint32) {
return bondingCurveStorage().connectorWeight;
}

function baseY() internal returns (uint256) {
function baseY() internal view returns (uint256) {
return bondingCurveStorage().baseY;
}

function poolBalance() internal returns (uint256) {
function poolBalance() internal view returns (uint256) {
return bondingCurveStorage().poolBalance;
}

Expand Down Expand Up @@ -106,7 +106,7 @@ library LibBondingCurve {
emit Deposit(_recipient, _collateralDeposited);
}

function getShare(address _recipient) internal returns (uint256) {
function getShare(address _recipient) internal view returns (uint256) {
BondingCurveData storage ss = bondingCurveStorage();
return ss.share[_recipient];
}
Expand All @@ -126,7 +126,7 @@ library LibBondingCurve {
uint256 toTransfer = _amount;
dollar.safeTransfer(
LibAppStorage.appStorage().treasuryAddress,
_amount
toTransfer
);

ss.poolBalance -= _amount;
Expand All @@ -152,7 +152,7 @@ library LibBondingCurve {
uint32 _connectorWeight,
uint256 _supply,
uint256 _connectorBalance
) internal view returns (uint256) {
) internal pure returns (uint256) {
// validate input
require(_connectorBalance > 0, "ERR_INVALID_SUPPLY");
require(
Expand Down Expand Up @@ -202,7 +202,7 @@ library LibBondingCurve {
uint256 _connectorWeight,
uint256 _baseX,
uint256 _baseY
) internal view returns (uint256) {
) internal pure returns (uint256) {
// (MAX_WEIGHT/reserveWeight -1)
bytes16 _one = uintToBytes16(ONE);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -150,7 +150,7 @@ library LibCurveDollarIncentive {
// when Ubiquity Dollar is <1$
function _getPercentDeviationFromUnderPeg(
uint256 amount
) internal returns (uint256) {
) internal view returns (uint256) {
uint256 curPrice = _getTWAPPrice();
if (curPrice >= 1 ether) {
return 0;
Expand Down
12 changes: 6 additions & 6 deletions packages/contracts/src/dollar/libraries/LibStakingFormulas.sol
Original file line number Diff line number Diff line change
Expand Up @@ -53,29 +53,29 @@ library LibStakingFormulas {
}

/// @dev formula may add a decreasing rewards if locking end is near when removing liquidity
/// @param _stake , staking share
/// @param /* _stake */ , staking share
/// @param _amount , amount of LP tokens
/// @notice rewards = _amount;
// solhint-disable-block no-unused-vars
/* solhint-disable no-unused-vars */
function lpRewardsRemoveLiquidityNormalization(
StakingShare.Stake memory _stake,
uint256[2] memory _shareInfo,
StakingShare.Stake memory /* _stake */,
uint256[2] memory /* _shareInfo */,
uint256 _amount
) internal pure returns (uint256) {
return _amount;
}

/* solhint-enable no-unused-vars */
/// @dev formula may add a decreasing rewards if locking end is near when adding liquidity
/// @param _stake , staking share
/// @param /* _stake */ , staking share
/// @param _amount , amount of LP tokens
/// @notice rewards = _amount;
// solhint-disable-block no-unused-vars
/* solhint-disable no-unused-vars */
function lpRewardsAddLiquidityNormalization(
StakingShare.Stake memory _stake,
uint256[2] memory _shareInfo,
StakingShare.Stake memory /* _stake */,
uint256[2] memory /* _shareInfo */,
uint256 _amount
) internal pure returns (uint256) {
return _amount;
Expand Down
8 changes: 4 additions & 4 deletions packages/contracts/src/dollar/mocks/MockCurveFactory.sol
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,11 @@ contract MockCurveFactory is ICurveFactory {
// solhint-disable-next-line no-empty-blocks
function deploy_metapool(
address _base_pool,
string memory _name,
string memory _symbol,
string memory /* _name */,
string memory /* _symbol */,
address _coin,
uint256 _A,
uint256 _fee
uint256 /* _A */,
uint256 /* _fee */
) external returns (address) {
MockMetaPool metaPoolAddress = new MockMetaPool(
_coin,
Expand Down
15 changes: 8 additions & 7 deletions packages/contracts/src/dollar/mocks/MockMetaPool.sol
Original file line number Diff line number Diff line change
Expand Up @@ -31,18 +31,18 @@ contract MockMetaPool is MockERC20 {
}

function get_twap_balances(
uint256[2] memory _first_balances,
uint256[2] memory _last_balances,
uint256 _time_elapsed
uint256[2] memory /* _first_balances */,
uint256[2] memory /* _last_balances */,
uint256 /* _time_elapsed */
) external view returns (uint256[2] memory) {
return balances;
}

function get_dy(
int128 i,
int128 j,
uint256 dx,
uint256[2] memory _balances
uint256 /* dx */,
uint256[2] memory /* _balances */
) external view returns (uint256) {
if (i == 0 && j == 1) {
return dy_values[1];
Expand All @@ -69,18 +69,19 @@ contract MockMetaPool is MockERC20 {
uint256[2] memory _amounts,
uint256 _min_mint_amount,
address _receiver
) external returns (uint256) {
) external returns (uint256 result) {
mint(
_receiver,
_min_mint_amount == 0
? _amounts[0] > _amounts[1] ? _amounts[0] : _amounts[1]
: _min_mint_amount
);
return result;
}

function calc_token_amount(
uint256[2] memory _amounts,
bool _is_deposit
bool /* _is_deposit */
) external pure returns (uint256) {
return _amounts[0] > _amounts[1] ? _amounts[0] : _amounts[1];
}
Expand Down
4 changes: 2 additions & 2 deletions packages/contracts/src/ubiquistick/UbiquiStick.sol
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,7 @@ contract UbiquiStick is
uint256(
keccak256(
abi.encodePacked(
block.difficulty,
block.prevrandao,
block.timestamp,
msg.sender,
tokenIdNext
Expand All @@ -131,7 +131,7 @@ contract UbiquiStick is
address,
uint256,
uint96
) internal {
) internal pure {
revert("ERC721Enumerable: consecutive transfers not supported");
}

Expand Down
12 changes: 3 additions & 9 deletions packages/contracts/test/diamond/facets/BondingCurveFacet.t.sol
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,9 @@ contract BondingCurveFacetTest is DiamondSetup {
address fourthAccount = address(0x6);
address fifthAccount = address(0x7);

uint256 constant ACCURACY = 10e18;
uint32 constant MAX_WEIGHT = 1e6;
bytes32 constant ONE = keccak256(abi.encodePacked(uint256(1)));
uint256 constant _ACCURACY = 10e18;
uint32 constant _MAX_WEIGHT = 1e6;
bytes32 constant _ONE = keccak256(abi.encodePacked(uint256(1)));

mapping(address => uint256) public share;

Expand Down Expand Up @@ -70,7 +70,6 @@ contract ZeroStateBonding is BondingCurveFacetTest {
uint256 connWeight;
connectorWeight = uint32(bound(connWeight, 1, 1000000));
baseY = bound(baseY, 1, 1000000);
uint256 tokenIds;

vm.prank(admin);
IBondingCurveFacet.setParams(connectorWeight, baseY);
Expand Down Expand Up @@ -102,8 +101,6 @@ contract ZeroStateBonding is BondingCurveFacetTest {
assertEq(tokReturned, result);
assertEq(tokReturned, IBondingCurveFacet.getShare(secondAccount));
assertEq(tokReturned, IUbiquityNFT.balanceOf(secondAccount, 1));

uint256 newDeposit;
}

function testWithdraw(uint32 connectorWeight, uint256 baseY) public {
Expand Down Expand Up @@ -135,7 +132,6 @@ contract ZeroStateBonding is BondingCurveFacetTest {
function testPurchaseTargetAmountShouldRevertIfSupplyZero() public {
uint256 collateralDeposited;
uint256 connWeight;
uint256 poolBalance;
uint32 connectorWeight = uint32(bound(connWeight, 1, MAX_WEIGHT));

vm.expectRevert("ERR_INVALID_SUPPLY");
Expand All @@ -151,8 +147,6 @@ contract ZeroStateBonding is BondingCurveFacetTest {
uint256 collateralDeposited;
uint256 bal;
uint256 poolBalance = bound(bal, 1, 1000000);
uint256 connWeight;
uint32 connectorWeight = uint32(bound(connWeight, 1, MAX_WEIGHT));

vm.expectRevert("ERR_INVALID_WEIGHT");
IBondingCurveFacet.purchaseTargetAmount(
Expand Down
1 change: 0 additions & 1 deletion packages/contracts/test/diamond/facets/ManagerFacet.t.sol
Original file line number Diff line number Diff line change
Expand Up @@ -138,7 +138,6 @@ contract ManagerFacetTest is DiamondSetup {

IDollar.mint(admin, 10000);

IERC20 crvToken = IERC20(0x6c3F90f043a72FA612cbac8115EE7e52BDe6E490);
MockERC20 curve3CrvToken = new MockERC20("3 CRV", "3CRV", 18);
address secondAccount = address(0x3);
address stakingZeroAccount = address(0x4);
Expand Down
Loading

0 comments on commit 9e19bc0

Please sign in to comment.