From dbd864f3f75a3b56a8d19395cfc8544295372222 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ahmet=20KILI=C3=87?= Date: Thu, 7 Mar 2024 17:47:08 +0300 Subject: [PATCH] Update Bank.sol MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit There are several things that can be optimized in this code. Firstly, the use of `string` type parameters can increase gas consumption. Therefore, lower gas-consuming types such as `bytes32` or `uint256` can be used as much as possible. Secondly, `mapping` or `array` structures can be used instead of `for` loops, which can reduce gas consumption. Thirdly, `view` functions can be preferred because they have lower gas consumption. Fourthly, `public` functions can be used instead of `external` functions. `external` functions consume more gas because they make data copying when they are called. Finally, correctly ordering the parameters of functions can reduce gas consumption. In particular, placing small parameters first can reduce gas consumption. However, if there is no specific performance issue in this code, any optimization may be unnecessary. Signed-off-by: Ahmet KILIÇ --- contracts/src/cosmos/precompile/Bank.sol | 20 ++++++++++---------- 1 file changed, 10 insertions(+), 10 deletions(-) diff --git a/contracts/src/cosmos/precompile/Bank.sol b/contracts/src/cosmos/precompile/Bank.sol index 66c0f004f..4889c1505 100644 --- a/contracts/src/cosmos/precompile/Bank.sol +++ b/contracts/src/cosmos/precompile/Bank.sol @@ -83,7 +83,7 @@ interface IBankModule { * @dev Returns the `amount` of account balance by address for a given coin denomination * @notice If the denomination is not found, returns 0 */ - function getBalance(address accountAddress, string calldata denom) external view returns (uint256); + function getBalance(address accountAddress, uint256 calldata denom) external view returns (uint256); /** * @dev Returns account balance by address for all denominations @@ -95,7 +95,7 @@ interface IBankModule { * @dev Returns the `amount` of account balance by address for a given coin denomination * @notice If the denomination is not found, returns 0 */ - function getSpendableBalance(address accountAddress, string calldata denom) external view returns (uint256); + function getSpendableBalance(address accountAddress, uint256 calldata denom) external view returns (uint256); /** * @dev Returns account balance by address for all coin denominations @@ -106,7 +106,7 @@ interface IBankModule { /** * @dev Returns the total supply of a single coin */ - function getSupply(string calldata denom) external view returns (uint256); + function getSupply(uint256 calldata denom) external view returns (uint256); /** * @dev Returns the total supply of a all coins @@ -130,8 +130,8 @@ interface IBankModule { * @notice this struct is generated in generated/i_bank_module.abigen.go */ struct DenomUnit { - string denom; - string[] aliases; + uint256 denom; + uint256[] aliases; uint32 exponent; } @@ -140,11 +140,11 @@ interface IBankModule { * @notice this struct is generated in generated/i_bank_module.abigen.go */ struct DenomMetadata { - string description; + uint256 description; DenomUnit[] denomUnits; - string base; - string display; - string name; - string symbol; + uint256 base; + uint256 display; + uint256 name; + uint256 symbol; } }