Skip to content
This repository has been archived by the owner on Jun 9, 2024. It is now read-only.

Commit

Permalink
Merge branch 'main' into logs-fix
Browse files Browse the repository at this point in the history
  • Loading branch information
itsdevbear authored Sep 18, 2023
2 parents c690147 + faec924 commit 6ba5467
Show file tree
Hide file tree
Showing 4 changed files with 97 additions and 46 deletions.
52 changes: 34 additions & 18 deletions contracts/src/cosmos/precompile/Bank.sol
Original file line number Diff line number Diff line change
Expand Up @@ -35,93 +35,109 @@ interface IBankModule {

/**
* @dev Emitted by the bank module when `amount` tokens are sent to `recipient`
* @param recipient The recipient address
* @param amount The amount of Cosmos coins sent
*/
event Transfer(address indexed recipient, Cosmos.Coin[] amount);

/**
* @dev Emitted by the bank module when `sender` sends some amount of tokens
* @param sender The sender address
*/
event Message(address indexed sender);

/**
* @dev Emitted by the bank module when `amount` tokens are spent by `spender`
* @param spender The spender address
* @param amount The amount of Cosmos coins spent
*/
event CoinSpent(address indexed spender, Cosmos.Coin[] amount);

/**
* @dev Emitted by the bank module when `amount` tokens are received by `receiver`
* @param receiver The receiver address
* @param amount The amount of Cosmos coins received
*/
event CoinReceived(address indexed receiver, Cosmos.Coin[] amount);

/**
* @dev Emitted by the bank module when `amount` tokens are minted by `minter`
*
* Note: "Coinbase" refers to the Cosmos event: EventTypeCoinMint. `minter` is a module
* address.
* @param minter The minter address
* @param amount The amount of Cosmos coins minted
* @notice "Coinbase" refers to the Cosmos event: `EventTypeCoinMint`
* @notice `minter` is always a module address
*/
event Coinbase(address indexed minter, Cosmos.Coin[] amount);

/**
* @dev Emitted by the bank module when `amount` tokens are burned by `burner`
*
* Note: `burner` is a module address
* @param burner The burner address
* @param amount The amount of Cosmos coins burned
* @notice `burner` is always a module address
*/
event Burn(address indexed burner, Cosmos.Coin[] amount);

/////////////////////////////////////// READ METHODS //////////////////////////////////////////

/**
* @dev Returns the `amount` of account balance by address for a given denomination.
* @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);

/**
* @dev Returns account balance by address for all denominations.
* @dev Returns account balance by address for all denominations
* @notice If the account address is not found, returns an empty array
*/
function getAllBalances(address accountAddress) external view returns (Cosmos.Coin[] memory);

/**
* @dev Returns the `amount` of account balance by address for a given denomination.
* @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);

/**
* @dev Returns account balance by address for all denominations.
* @dev Returns account balance by address for all coin denominations
* @notice If the account address is not found, returns an empty array
*/
function getAllSpendableBalances(address accountAddress) external view returns (Cosmos.Coin[] memory);

/**
* @dev Returns the total supply of a single coin.
* @dev Returns the total supply of a single coin
*/
function getSupply(string calldata denom) external view returns (uint256);

/**
* @dev Returns the total supply of a all coins.
* @dev Returns the total supply of a all coins
*/
function getAllSupply() external view returns (Cosmos.Coin[] memory);

/**
* @dev Returns the denomination's metadata.
* @dev Returns the coin denomination's metadata
*/
function getDenomMetadata(string calldata denom) external view returns (DenomMetadata memory);

/**
* @dev Returns if the denom is enabled to send
* @dev Returns if the coin is enabled to be sent (transfered)
*/
function getSendEnabled(string calldata denom) external view returns (bool);

////////////////////////////////////// WRITE METHODS //////////////////////////////////////////

/**
* @dev Send coins from msg.sender to another.
* @dev Send coins from msg.sender to another
* @param toAddress The recipient address
* @param amount The amount of Cosmos coins to send
* @notice If the sender does not have enough balance, returns false
*/
function send(address toAddress, Cosmos.Coin[] calldata amount) external payable returns (bool);

//////////////////////////////////////////// UTILS ////////////////////////////////////////////

/**
* @dev Represents a denom unit.
* Note: this struct is generated in generated/i_bank_module.abigen.go
* @dev Represents a denom unit in the bank module
* @notice this struct is generated in generated/i_bank_module.abigen.go
*/
struct DenomUnit {
string denom;
Expand All @@ -130,8 +146,8 @@ interface IBankModule {
}

/**
* @dev Represents a denom metadata.
* Note: this struct is generated in generated/i_bank_module.abigen.go
* @dev Represents a denom metadata in the bank module
* @notice this struct is generated in generated/i_bank_module.abigen.go
*/
struct DenomMetadata {
string description;
Expand Down
5 changes: 4 additions & 1 deletion contracts/src/cosmos/precompile/Distribution.sol
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ interface IDistributionModule {
/**
* @dev Withdraw the rewrads accumulated by the caller(msg.sender). Returns the rewards claimed.
* @param delegator The delegator to withdraw the rewards from.
* @param validator The validator to withdraw the rewards from.
* @param validator The validator (operator address) to withdraw the rewards from.
*/
function withdrawDelegatorReward(address delegator, address validator) external returns (Cosmos.Coin[] memory);

Expand Down Expand Up @@ -77,6 +77,9 @@ interface IDistributionModule {
*/
event SetWithdrawAddress(address indexed withdrawAddress);

/**
* @dev Represents a delegator's rewards for one particular validator.
*/
struct ValidatorReward {
address validator;
Cosmos.Coin[] rewards;
Expand Down
33 changes: 18 additions & 15 deletions contracts/src/cosmos/precompile/Governance.sol
Original file line number Diff line number Diff line change
Expand Up @@ -27,18 +27,23 @@ pragma solidity ^0.8.4;

import {Cosmos} from "../CosmosTypes.sol";

/**
* @dev Interface of the governance module's precompiled contract
*/
interface IGovernanceModule {
////////////////////////////////////////// Write Methods /////////////////////////////////////////////
/**
* @dev Submit a proposal to the governance module. Returns the proposal id.
* @param proposalMsg The proposal to submit.
* @dev Submit a proposal to the governance module.
* @param proposalMsg The proposal to submit (as marshaled bytes). NOTE: use the codec to
* marshal the proposal message.
* @return The id of the proposal.
*/
function submitProposal(bytes calldata proposalMsg) external returns (uint64);

/**
* @dev Cancel a proposal. Returns the cancled time and height.
* burned.
* @dev Cancel a proposal.
* @param proposalId The id of the proposal to cancel.
* @return The time and block height the proposal was canceled.
*/
function cancelProposal(uint64 proposalId) external returns (uint64, uint64);

Expand Down Expand Up @@ -82,6 +87,7 @@ interface IGovernanceModule {

/**
* @dev Get proposals with a given status.
* @notice Accepts pagination request (empty == no pagination returned).
* @param proposalStatus The status of the proposals to get.
*/
function getProposals(int32 proposalStatus, Cosmos.PageRequest calldata pagination)
Expand All @@ -90,12 +96,15 @@ interface IGovernanceModule {
returns (Proposal[] memory, Cosmos.PageResponse memory);

/**
* @dev Get the proposal tally result with the given id.
* @dev Get the proposal tally result for the given id.
* @param proposalId The id of the proposal to get the tally result for.
*/
function getProposalTallyResult(uint64 proposalId) external view returns (TallyResult memory);

/**
* @dev Get the proposal votes with the given id.
* @notice Accepts pagination request.
* @param proposalId The id of the proposal to get the votes for.
*/
function getProposalVotes(uint64 proposalId, Cosmos.PageRequest calldata pagination)
external
Expand All @@ -104,6 +113,8 @@ interface IGovernanceModule {

/**
* @dev Get the proposal vote information with the given id and voter.
* @param proposalId The id of the proposal to get the vote info for.
* @param voter The address of the voter to get the vote info for.
*/
function getProposalVotesByVoter(uint64 proposalId, address voter) external view returns (Vote memory);

Expand Down Expand Up @@ -135,7 +146,6 @@ interface IGovernanceModule {
////////////////////////////////////////// Structs ///////////////////////////////////////////////////
/**
* @dev Represents a governance module `WeightedVoteOption`.
* Note: this struct is generated in generated/i_staking_module.abigen.go
*/
struct WeightedVoteOption {
int32 voteOption;
Expand All @@ -144,7 +154,6 @@ interface IGovernanceModule {

/**
* @dev Represents a governance module `Vote`.
* Note: this struct is generated in generated/i_staking_module.abigen.go
*/
struct Vote {
uint64 proposalId;
Expand All @@ -155,7 +164,6 @@ interface IGovernanceModule {

/**
* @dev Represents a governance module `Proposal`.
* Note: this struct is generated in generated/i_staking_module.abigen.go
*/
struct Proposal {
uint64 id;
Expand All @@ -175,7 +183,6 @@ interface IGovernanceModule {

/**
* @dev Represents the governance module's parameters.
* Note: this struct is generated in generated/i_staking_module.abigen.go
*/
struct Params {
Cosmos.Coin[] minDeposit;
Expand All @@ -197,15 +204,13 @@ interface IGovernanceModule {

/**
* @dev Represents the governance module's `VotingParams`.
* Note: this struct is generated in generated/i_staking_module.abigen.go
*/
struct VotingParams {
uint64 votingPeriod;
}

/**
* @dev Represents the governance module's `DepositParams`.
* Note: this struct is generated in generated/i_staking_module.abigen.go
*/
struct DepositParams {
Cosmos.Coin[] minDeposit;
Expand All @@ -214,7 +219,6 @@ interface IGovernanceModule {

/**
* @dev Represents the governance module's `TallyParams`.
* Note: this struct is generated in generated/i_staking_module.abigen.go
*/
struct TallyParams {
string quorum;
Expand All @@ -224,7 +228,6 @@ interface IGovernanceModule {

/**
* @dev Represents a governance module `TallyResult`.
* Note: this struct is generated in generated/i_staking_module.abigen.go
*/
struct TallyResult {
string yesCount;
Expand All @@ -234,7 +237,7 @@ interface IGovernanceModule {
}

/**
* @dev Emitted by the governance module when `submitProposal` is called.
* @dev Emitted by the governance precompile when `submitProposal` is called.
* @param proposalId The id of the proposal.
* @param proposalSender The sender of the submit proposal.
*/
Expand All @@ -248,7 +251,7 @@ interface IGovernanceModule {
event ProposalDeposit(uint64 indexed proposalId, Cosmos.Coin[] amount);

/**
* @dev Emitted by the governance module when `AddVote` is called in the msg server.
* @dev Emitted by the governance precompile when a proposal is voted on.
* @param proposalVote The vote that was voted on for a proposal.
*/
event ProposalVoted(Vote proposalVote);
Expand Down
Loading

0 comments on commit 6ba5467

Please sign in to comment.