Skip to content

Commit

Permalink
add GetGasStabilityPoolBalance as prototype contract function
Browse files Browse the repository at this point in the history
  • Loading branch information
fbac committed Aug 19, 2024
1 parent bb69a61 commit 53098a1
Show file tree
Hide file tree
Showing 8 changed files with 132 additions and 119 deletions.
12 changes: 8 additions & 4 deletions e2e/e2etests/test_precompiles_prototype.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,19 +11,23 @@ import (
func TestPrecompilesRegular(r *runner.E2ERunner, args []string) {
require.Len(r, args, 0, "No arguments expected")

caller, err := prototype.NewIPrototypeCaller(prototype.ContractAddress, r.ZEVMClient)
require.NoError(r, err, "Failed to create precompiled contract caller")
iPrototype, err := prototype.NewIPrototype(prototype.ContractAddress, r.ZEVMClient)
require.NoError(r, err, "Failed to create prototype contract caller")

res, err := caller.Bech32ify(nil, "zeta", common.HexToAddress("0xB9Dbc229Bf588A613C00BEE8e662727AB8121cfE"))
res, err := iPrototype.Bech32ify(nil, "zeta", common.HexToAddress("0xB9Dbc229Bf588A613C00BEE8e662727AB8121cfE"))
require.NoError(r, err, "Error calling Bech32ify")
require.Equal(r, "zeta1h8duy2dltz9xz0qqhm5wvcnj02upy887fyn43u", res, "Failed to validate Bech32ify result")

addr, err := caller.Bech32ToHexAddr(nil, "zeta1h8duy2dltz9xz0qqhm5wvcnj02upy887fyn43u")
addr, err := iPrototype.Bech32ToHexAddr(nil, "zeta1h8duy2dltz9xz0qqhm5wvcnj02upy887fyn43u")
require.NoError(r, err, "Error calling Bech32ToHexAddr")
require.Equal(
r,
"0xB9Dbc229Bf588A613C00BEE8e662727AB8121cfE",
addr.String(),
"Failed to validate Bech32ToHexAddr result",
)

balance, err := iPrototype.GetGasStabilityPoolBalance(nil, int64(101))
require.NoError(r, err, err.Error())
require.NotNil(r, balance, "GetGasStabilityPoolBalance returned balance is nil")
}
5 changes: 4 additions & 1 deletion precompiles/precompiles.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,9 @@ import (
"github.com/zeta-chain/zetacore/x/fungible/keeper"
)

// EnabledStatefulContracts contains the list of all enabled stateful precompiles.
// This is useful for listing and reading from other packages, such as BlockedAddrs() function.
// Setting to false a contract here will disable it, not being included in the blockchain.
var EnabledStatefulContracts = map[common.Address]bool{
prototype.ContractAddress: true,
}
Expand All @@ -29,7 +32,7 @@ func StatefulContracts(
// Define the regular contract function.
if EnabledStatefulContracts[prototype.ContractAddress] {
regularContract := func(_ sdktypes.Context, _ ethparams.Rules) vm.PrecompiledContract {
return prototype.NewRegularContract(fungibleKeeper, cdc, gasConfig)
return prototype.NewIPrototypeContract(fungibleKeeper, cdc, gasConfig)

Check warning on line 35 in precompiles/precompiles.go

View check run for this annotation

Codecov / codecov/patch

precompiles/precompiles.go#L35

Added line #L35 was not covered by tests
}

// Append the regular contract to the precompiledContracts slice.
Expand Down
15 changes: 5 additions & 10 deletions precompiles/prototype/IPrototype.abi
Original file line number Diff line number Diff line change
Expand Up @@ -45,25 +45,20 @@
{
"inputs": [
{
"internalType": "string",
"name": "method",
"type": "string"
},
{
"internalType": "address",
"name": "addr",
"type": "address"
"internalType": "int64",
"name": "chainID",
"type": "int64"
}
],
"name": "regularCall",
"name": "getGasStabilityPoolBalance",
"outputs": [
{
"internalType": "uint256",
"name": "result",
"type": "uint256"
}
],
"stateMutability": "nonpayable",
"stateMutability": "view",
"type": "function"
}
]
36 changes: 23 additions & 13 deletions precompiles/prototype/IPrototype.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

15 changes: 5 additions & 10 deletions precompiles/prototype/IPrototype.json
Original file line number Diff line number Diff line change
Expand Up @@ -46,25 +46,20 @@
{
"inputs": [
{
"internalType": "string",
"name": "method",
"type": "string"
},
{
"internalType": "address",
"name": "addr",
"type": "address"
"internalType": "int64",
"name": "chainID",
"type": "int64"
}
],
"name": "regularCall",
"name": "getGasStabilityPoolBalance",
"outputs": [
{
"internalType": "uint256",
"name": "result",
"type": "uint256"
}
],
"stateMutability": "nonpayable",
"stateMutability": "view",
"type": "function"
}
]
Expand Down
12 changes: 5 additions & 7 deletions precompiles/prototype/IPrototype.sol
Original file line number Diff line number Diff line change
Expand Up @@ -26,12 +26,10 @@ interface IPrototype {
address addr
) external view returns (string memory bech32);

/// @dev Function to verify calling regular contact through precompiled contact
/// @param method to call, e.g. bar.
/// @param addr of deployed regular contract.
/// @dev returns the balance of the gas stability pool
/// @param chainID to query gas.
/// @return result of the call.
function regularCall(
string memory method,
address addr
) external returns (uint256 result);
function getGasStabilityPoolBalance(
int64 chainID
) external view returns (uint256 result);
}
Loading

0 comments on commit 53098a1

Please sign in to comment.