diff --git a/.gitbook/developers/modules/injective/auction/img.png b/.gitbook/developers/modules/injective/auction/img.png deleted file mode 100644 index 10dad042..00000000 Binary files a/.gitbook/developers/modules/injective/auction/img.png and /dev/null differ diff --git a/.gitbook/developers/modules/injective/erc20/01_concepts.md b/.gitbook/developers/modules/injective/erc20/01_concepts.md deleted file mode 100644 index 89297693..00000000 --- a/.gitbook/developers/modules/injective/erc20/01_concepts.md +++ /dev/null @@ -1,12 +0,0 @@ ---- -sidebar_position: 1 -title: Concepts -updatedAt: "2025-10-03" ---- - -# Concepts - -The `ERC20` module is designed to introduce existing bank denoms (such as IBC-bridged tokens, USDC, tokenfactory, and peggy) into the Injective EVM. It achieves this by maintaining an association between token pairs in its storage. When creating a new token pair for an existing bank denom, the module uploads a fresh ERC20 contract that utilizes our bank precompile. This precompile then accesses the module's storage to locate the mapping between the newly created ERC20 address and the existing bank denom. We require this separate module for several reasons: - -1. storage: store mapping between bank denom ↔ erc20 address -2. new Msg type: allow users to create new token pairs in the mappings, which is done by issuing a chain Msg diff --git a/.gitbook/developers/modules/injective/erc20/02_state.md b/.gitbook/developers/modules/injective/erc20/02_state.md deleted file mode 100644 index 85bd5d08..00000000 --- a/.gitbook/developers/modules/injective/erc20/02_state.md +++ /dev/null @@ -1,18 +0,0 @@ ---- -sidebar_position: 2 -title: State -updatedAt: "2025-10-03" ---- - -# State - -The `erc20` module keeps state of the following primary objects: - -## ERC20 Tokens by Bank denoms - -- 0x02 + bank_denom ⇒ erc20_address - -## Bank Denoms by ERC20 Token - -- 0x03 + erc20_address ⇒ bank_denom - diff --git a/.gitbook/developers/modules/injective/erc20/03_messages.md b/.gitbook/developers/modules/injective/erc20/03_messages.md deleted file mode 100644 index 5d5e1336..00000000 --- a/.gitbook/developers/modules/injective/erc20/03_messages.md +++ /dev/null @@ -1,57 +0,0 @@ ---- -sidebar_position: 3 -updatedAt: "2025-10-03" ---- - -# Messages - -In this section we describe the processing of the `erc20` module messages and the corresponding updates to the state. - -### Create Token Pair: `MsgCreateTokenPair` - -Creates an association between existing bank denom and new or existing ERC20 smart contract. -If ERC20 address is empty, new ERC20 smart contract will be instantiated. Not all bank denoms are supported. - -Validation rules: - -- for tokenfactory denoms, only denom admin can create token pair -- for peggy and IBC denoms, anyone can create token pair (only with erc20 address being empty) - -```go -type MsgCreateTokenPair struct { - Sender string - TokenPair TokenPair -} - -type TokenPair struct { - BankDenom string - Erc20Address string -} -``` - -**State Modifications:** - -- Validation checks: - - Sender has permissions to create token pair for this denom (for tokenfactory denom it must be a denom admin) - - Provided bank denom exists and has non-zero supply - - If ERC20 address is provided: - - check that contract exists and is, in fact, an ERC-2o smart contract (by invoking `symbol()` method on it) - - check that existing contract does not have associated bank denom already with circulating supply -- Create the association depending on the bank denom type: - - tokenfactory denom: - - if no ERC-20 address is provided, instantiate new `MintBurnBankERC20` smart contract, otherwise use provided address - - store the association - - IBC and peggy denoms: - - instantiate new `FixedSupplyBankERC20` smart contract - - store the association - -### Delete Token Pair: `MsgDeleteTokenPair` - -Only authority can remove token pairs for now, by providing bank denom of the pair. - -```go -type MsgDeleteTokenPair struct { - Sender string - BankDenom string -} -``` diff --git a/.gitbook/developers/modules/injective/erc20/04_events.md b/.gitbook/developers/modules/injective/erc20/04_events.md deleted file mode 100644 index ba593114..00000000 --- a/.gitbook/developers/modules/injective/erc20/04_events.md +++ /dev/null @@ -1,20 +0,0 @@ ---- -sidebar_position: 4 -title: Events -updatedAt: "2025-10-03" ---- - -# Events - -The erc20 module emits the following events: - -```protobuf -message EventCreateTokenPair { - string bank_denom = 1; - string erc20_address = 2; -} - -message EventDeleteTokenPair { - string bank_denom = 1; -} -``` \ No newline at end of file diff --git a/.gitbook/developers/modules/injective/erc20/README.md b/.gitbook/developers/modules/injective/erc20/README.md deleted file mode 100644 index 033c3594..00000000 --- a/.gitbook/developers/modules/injective/erc20/README.md +++ /dev/null @@ -1,17 +0,0 @@ ---- -updatedAt: "2025-10-30" ---- - -# ERC20 - -## Abstract - -The erc20 module allows for the associations of existing bank denoms with ERC-20 tokens. - - -## Contents - -1. **[Concepts](./01_concepts/)** -2. **[State](./02_state/)** -3. **[Messages](./03_messages/)** -4. **[Events](./04_events/)** diff --git a/.gitbook/developers/modules/injective/evm/01_concepts.md b/.gitbook/developers/modules/injective/evm/01_concepts.md deleted file mode 100644 index f5b69d78..00000000 --- a/.gitbook/developers/modules/injective/evm/01_concepts.md +++ /dev/null @@ -1,111 +0,0 @@ ---- -updatedAt: "2025-10-29" ---- - -# Concepts - -## EVM - -The Ethereum Virtual Machine (EVM) is a computation engine which can be thought of as one single entity maintained by thousands of connected computers (nodes) running an Ethereum client. As a virtual machine ([VM](https://en.wikipedia.org/wiki/Virtual_machine)), the EVM is responisble for computing changes to the state deterministically regardless of its environment (hardware and OS). This means that every node has to get the exact same result given an identical starting state and transaction (tx). - -The EVM is considered to be the part of the Ethereum protocol that handles the deployment and execution of [smart contracts](https://ethereum.org/en/developers/docs/smart-contracts/). To make a clear distinction: - -* The Ethereum protocol describes a blockchain, in which all Ethereum accounts and smart contracts live. It has only one canonical state (a data structure, which keeps all accounts) at any given block in the chain. -* The EVM, however, is the [state machine](https://en.wikipedia.org/wiki/Finite-state_machine) that defines the rules for computing a new valid state from block to block. It is an isolated runtime, which means that code running inside the EVM has no access to network, filesystem, or other processes (not external APIs). - -The `x/evm` module implements the EVM as a Cosmos SDK module. It allows users to interact with the EVM by submitting Ethereum txs and executing their containing messages on the given state to evoke a state transition. - -### State - -The Ethereum state is a data structure, implemented as a [Merkle Patricia Trie](https://en.wikipedia.org/wiki/Merkle_tree), that keeps all accounts on the chain. The EVM makes changes to this data structure resulting in a new state with a different State Root. Ethereum can therefore be seen as a state chain that transitions from one state to another by executing transations in a block using the EVM. A new block of txs can be described through its Block header (parent hash, block number, time stamp, nonce, receipts,...). - -### Accounts - -There are two types of accounts that can be stored in state at a given address: - -* **Externally Owned Account (EOA)**: Has nonce (tx counter) and balance -* **Smart Contract**: Has nonce, balance, (immutable) code hash, storage root (another Merkle Patricia Trie) - -Smart contracts are just like regular accounts on the blockchain, which additionally store executable code in an Ethereum-specific binary format, known as **EVM bytecode**. They are typically written in an Ethereum high level language such as Solidity which is compiled down to EVM bytecode and deployed on the blockchain, by submitting a tx using an Ethereum client. - -### Architecture - -The EVM operates as a stack-based machine. It's main architecture components consist of: - -* Virtual ROM: contract code is pulled into this read only memory when processing txs -* Machine state (volatile): changes as the EVM runs and is wiped clean after processing each tx - * Program counter (PC) - * Gas: keeps track of how much gas is used - * Stack and Memory: compute state changes -* Access to account storage (persistent) - -### State Transitions with Smart Contracts - -Typically smart contracts expose a public ABI, which is a list of supported ways a user can interact with a contract. To interact with a contract and invoke a state transition, a user will submit a tx carrying any amount of gas and a data payload formatted according to the ABI, specifying the type of interaction and any additional parameters. When the tx is received, the EVM executes the smart contracts's EVM bytecode using the tx payload. - -### Executing EVM bytecode - -A contract's EVM bytecode consists of basic operations (add, multiply, store, etc...), called **Opcodes**. Each Opcode execution requires gas that needs to be payed with the tx. The EVM is therefore considered quasi-turing complete, as it allows any arbitrary computation, but the amount of computations during a contract execution is limited to the amount of gas provided in the tx. Each Opcode's [**gas cost**](https://www.evm.codes/) reflects the cost of running these operations on actual computer hardware (e.g. `ADD = 3gas` and `SSTORE = 100gas`). To calculate the gas consumption of a tx, the gas cost is multiplied by the **gas price**, which can change depending on the demand of the network at the time. If the network is under heavy load, you might have to pay a highter gas price to get your tx executed. If the gas limit is hit (out of gas execption) no changes to the Ethereum state are applied, except that the sender's nonce increments and their balance goes down to pay for wasting the EVM's time. - -Smart contracts can also call other smart contracts. Each call to a new contract creates a new instance of the EVM (including a new stack and memory). Each call passes the sandbox state to the next EVM. If the gas runs out, all state changes are discareded. Otherwise they are kept. - -For further reading, please refer to: - -* [EVM](https://eth.wiki/concepts/evm/evm) -* [EVM Architecture](https://cypherpunks-core.github.io/ethereumbook/13evm.html#evm_architecture) -* [What is Ethereum](https://ethdocs.org/en/latest/introduction/what-is-ethereum.html#what-is-ethereum) -* [Opcodes](https://www.ethervm.io/) - -## Ethermint as Geth implementation - -Ethermint is an implementation of the [Etherum protocal in Golang](https://geth.ethereum.org/docs/getting-started) (Geth) as a Cosmos SDK module. Geth includes an implementation of the EVM to compute state transitions. Have a look at the [go-etheruem source code](https://github.com/ethereum/go-ethereum/blob/master/core/vm/instructions.go) to see how the EVM opcodes are implemented. Just as Geth can be run as an Ethereum node, Ethermint can be run as a node to compute state transitions with the EVM. Ethermint supports Geth's standard [Ethereum JSON-RPC APIs](https://ethereum.org/en/developers/docs/apis/json-rpc/) in order to be Web3 and EVM compatible. - -### JSON-RPC - -JSON-RPC is a stateless, lightweight remote procedure call (RPC) protocol. Primarily this specification defines several data structures and the rules around their processing. It is transport agnostic in that the concepts can be used within the same process, over sockets, over HTTP, or in many various message passing environments. It uses JSON (RFC 4627) as a data format. - -#### JSON-RPC Example: `eth_call` - -The JSON-RPC method [`eth_call`](https://ethereum.org/en/developers/docs/apis/json-rpc/#eth_call) allows you to execute messages against contracts. Usually, you need to send a transaction to a Geth node to include it in the mempool, then nodes gossip between each other and eventually the transaction is included in a block and gets executed. `eth_call` however lets you send data to a contract and see what happens without commiting a transaction. - -In the Geth implementation, calling the endpoint roughly goes through the following steps: - -1. The `eth_call` request is transformed to call the `func (s *PublicBlockchainAPI) Call()` function using the `eth` namespace -2. [`Call()`](https://github.com/ethereum/go-ethereum/blob/master/internal/ethapi/api.go#L982) is given the transaction arguments, the block to call against and optional overides that modify the state to call against. It then calls `DoCall()` -3. [`DoCall()`](https://github.com/ethereum/go-ethereum/blob/d575a2d3bc76dfbdefdd68b6cffff115542faf75/internal/ethapi/api.go#L891) transforms the arguments into a `ethtypes.message`, instantiates an EVM and applies the message with `core.ApplyMessage` -4. [`ApplyMessage()`](https://github.com/ethereum/go-ethereum/blob/d575a2d3bc76dfbdefdd68b6cffff115542faf75/core/state_transition.go#L180) calls the state transition `TransitionDb()` -5. [`TransitionDb()`](https://github.com/ethereum/go-ethereum/blob/d575a2d3bc76dfbdefdd68b6cffff115542faf75/core/state_transition.go#L275) either `Create()`s a new contract or `Call()`s a contract -6. [`evm.Call()`](https://github.com/ethereum/go-ethereum/blob/d575a2d3bc76dfbdefdd68b6cffff115542faf75/core/vm/evm.go#L168) runs the interpreter `evm.interpreter.Run()` to execute the message. If the execution fails, the state is reverted to a snapshot taken before the execution and gas is consumed. -7. [`Run()`](https://github.com/ethereum/go-ethereum/blob/d575a2d3bc76dfbdefdd68b6cffff115542faf75/core/vm/interpreter.go#L116) performs a loop to execute the opcodes. - -The Injective implementation is similar and makes use of the gRPC query client which is included in the Cosmos SDK: - -1. `eth_call` request is transformed to call the `func (e *PublicAPI) Call` function using the `eth` namespace -2. [`Call()`](https://github.com/InjectiveLabs/injective-core/injective-chain/blob/main/rpc/namespaces/ethereum/eth/api.go#L639) calls `doCall()` -3. [`doCall()`](https://github.com/InjectiveLabs/injective-core/injective-chain/blob/main/rpc/namespaces/ethereum/eth/api.go#L656) transforms the arguments into a `EthCallRequest` and calls `EthCall()` using the query client of the evm module. -4. [`EthCall()`](https://github.com/InjectiveLabs/injective-core/injective-chain/blob/main/x/evm/keeper/grpc_query.go#L212) transforms the arguments into a `ethtypes.message` and calls `ApplyMessageWithConfig() -5. [`ApplyMessageWithConfig()`](https://github.com/InjectiveLabs/injective-core/injective-chain/blob/d5598932a7f06158b7a5e3aa031bbc94eaaae32c/x/evm/keeper/state_transition.go#L341) instantiates an EVM and either `Create()`s a new contract or `Call()`s a contract using the Geth implementation. - -### StateDB - -The `StateDB` interface from [go-ethereum](https://github.com/ethereum/go-ethereum/blob/master/core/vm/interface.go) represents an EVM database for full state querying. EVM state transitions are enabled by this interface, which in the `x/evm` module is implemented by the `Keeper`. The implementation of this interface is what makes Ethermint EVM compatible. - -## Consensus Engine - -The application using the `x/evm` module interacts with the Tendermint Core Consensus Engine over an Application Blockchain Interface (ABCI). Together, the application and Tendermint Core form the programs that run a complete blockchain and combine business logic with decentralized data storage. - -Ethereum transactions that are submitted to the `x/evm` module take part in a this consensus process before being executed and changing the application state. We encourage to understand the basics of the [Tendermint consensus engine](https://docs.tendermint.com/master/introduction/what-is-tendermint.html#intro-to-abci) in order to understand state transitions in detail. - -## Transaction Logs - -On every `x/evm` transaction, the result contains the Ethereum `Log`s from the state machine execution that are used by the JSON-RPC Web3 server for filter querying and for processing the EVM Hooks. - -The tx logs are stored in the transient store during tx execution and then emitted through cosmos events after the transaction has been processed. They can be queried via gRPC and JSON-RPC. - -## Block Bloom - -Bloom is the bloom filter value in bytes for each block that can be used for filter queries. The block bloom value is stored in the transient store and then emitted through a cosmos event during `EndBlock` processing. They can be queried via gRPC and JSON-RPC. - -::: tip -👉 **Note**: Since they are not stored on state, Transaction Logs and Block Blooms are not persisted after upgrades. A user must use an archival node after upgrades in order to obtain legacy chain events. -::: diff --git a/.gitbook/developers/modules/injective/evm/02_state.md b/.gitbook/developers/modules/injective/evm/02_state.md deleted file mode 100644 index 1306f2d8..00000000 --- a/.gitbook/developers/modules/injective/evm/02_state.md +++ /dev/null @@ -1,241 +0,0 @@ ---- -updatedAt: "2025-10-29" ---- - -# State - -This section gives you an overview of the objects stored in the `x/evm` module state, functionalities that are derived from the go-ethereum `StateDB` interface, and its implementation through the Keeper as well as the state implementation at genesis. - -## State Objects - -The `x/evm` module keeps the following objects in state: - -### State - -| | Description | Key | Value | Store | -| ----------- | ------------------------------------------------------------ | ----------------------------- | ------------------- | --------- | -| Code | Smart contract bytecode | `[]byte{1} + []byte(address)` | `[]byte{code}` | KV | -| Storage | Smart contract storage | `[]byte{2} + [32]byte{key}` | `[32]byte(value)` | KV | -| Block Bloom | Block bloom filter, used to accumulate the bloom filter of current block, emitted to events at end blocker. | `[]byte{1} + []byte(tx.Hash)` | `protobuf([]Log)` | Transient | -| Tx Index | Index of current transaction in current block. | `[]byte{2}` | `BigEndian(uint64)` | Transient | -| Log Size | Number of the logs emitted so far in current block. Used to decide the log index of following logs. | `[]byte{3}` | `BigEndian(uint64)` | Transient | -| Gas Used | Amount of gas used by ethereum messages of current cosmos-sdk tx, it's necessary when cosmos-sdk tx contains multiple ethereum messages. | `[]byte{4}` | `BigEndian(uint64)` | Transient | - -## StateDB - -The `StateDB` interface is implemented by the `StateDB` in the `x/evm/statedb` module to represent an EVM database for full state querying of both contracts and accounts. Within the Ethereum protocol, `StateDB`s are used to store anything within the IAVL tree and take care of caching and storing nested states. - -```go -// github.com/ethereum/go-ethereum/core/vm/interface.go -type StateDB interface { - CreateAccount(common.Address) - - SubBalance(common.Address, *big.Int) - AddBalance(common.Address, *big.Int) - GetBalance(common.Address) *big.Int - - GetNonce(common.Address) uint64 - SetNonce(common.Address, uint64) - - GetCodeHash(common.Address) common.Hash - GetCode(common.Address) []byte - SetCode(common.Address, []byte) - GetCodeSize(common.Address) int - - AddRefund(uint64) - SubRefund(uint64) - GetRefund() uint64 - - GetCommittedState(common.Address, common.Hash) common.Hash - GetState(common.Address, common.Hash) common.Hash - SetState(common.Address, common.Hash, common.Hash) - - Suicide(common.Address) bool - HasSuicided(common.Address) bool - - // Exist reports whether the given account exists in state. - // Notably this should also return true for suicided accounts. - Exist(common.Address) bool - // Empty returns whether the given account is empty. Empty - // is defined according to EIP161 (balance = nonce = code = 0). - Empty(common.Address) bool - - PrepareAccessList(sender common.Address, dest *common.Address, precompiles []common.Address, txAccesses types.AccessList) - AddressInAccessList(addr common.Address) bool - SlotInAccessList(addr common.Address, slot common.Hash) (addressOk bool, slotOk bool) - // AddAddressToAccessList adds the given address to the access list. This operation is safe to perform - // even if the feature/fork is not active yet - AddAddressToAccessList(addr common.Address) - // AddSlotToAccessList adds the given (address,slot) to the access list. This operation is safe to perform - // even if the feature/fork is not active yet - AddSlotToAccessList(addr common.Address, slot common.Hash) - - RevertToSnapshot(int) - Snapshot() int - - AddLog(*types.Log) - AddPreimage(common.Hash, []byte) - - ForEachStorage(common.Address, func(common.Hash, common.Hash) bool) error -} -``` - -The `StateDB` in the `x/evm` provides the following functionalities: - -### CRUD of Ethereum accounts - -You can create `EthAccount` instances from the provided address and set the value to store on the `AccountKeeper`with `createAccount()`. If an account with the given address already exists, this function also resets any preexisting code and storage associated with that address. - -An account's coin balance can be is managed through the `BankKeeper` and can be read with `GetBalance()` and updated with `AddBalance()` and `SubBalance()`. - -- `GetBalance()` returns the EVM denomination balance of the provided address. The denomination is obtained from the module parameters. -- `AddBalance()` adds the given amount to the address balance coin by minting new coins and transferring them to the address. The coin denomination is obtained from the module parameters. -- `SubBalance()` subtracts the given amount from the address balance by transferring the coins to an escrow account and then burning them. The coin denomination is obtained from the module parameters. This function performs a no-op if the amount is negative or the user doesn't have enough funds for the transfer. - -The nonce (or transaction sequence) can be obtained from the Account `Sequence` via the auth module `AccountKeeper`. - -- `GetNonce()` retrieves the account with the given address and returns the tx sequence (i.e nonce). The function performs a no-op if the account is not found. -- `SetNonce()` sets the given nonce as the sequence of the address' account. If the account doesn't exist, a new one will be created from the address. - -The smart contract bytecode containing arbitrary contract logic is stored on the `EVMKeeper` and it can be queried with `GetCodeHash()` ,`GetCode()` & `GetCodeSize()`and updated with `SetCode()`. - -- `GetCodeHash()` fetches the account from the store and returns its code hash. If the account doesn't exist or is not an EthAccount type, it returns the empty code hash value. -- `GetCode()` returns the code byte array associated with the given address. If the code hash from the account is empty, this function returns nil. -- `SetCode()` stores the code byte array to the application KVStore and sets the code hash to the given account. The code is deleted from the store if it is empty. -- `GetCodeSize()` returns the size of the contract code associated with this object, or zero if none. - -Gas refunded needs to be tracked and stored in a separate variable in -order to add it subtract/add it from/to the gas used value after the EVM -execution has finalized. The refund value is cleared on every transaction and at the end of every block. - -- `AddRefund()` adds the given amount of gas to the in-memory refund value. -- `SubRefund()` subtracts the given amount of gas from the in-memory refund value. This function will panic if gas amount is greater than the current refund. -- `GetRefund()` returns the amount of gas available for return after the tx execution finalizes. This value is reset to 0 on every transaction. - -The state is stored on the `EVMKeeper`. It can be queried with `GetCommittedState()`, `GetState()` and updated with `SetState()`. - -- `GetCommittedState()` returns the value set in store for the given key hash. If the key is not registered this function returns the empty hash. -- `GetState()` returns the in-memory dirty state for the given key hash, if not exist load the committed value from KVStore. -- `SetState()` sets the given hashes (key, value) to the state. If the value hash is empty, this function deletes the key from the state, the new value is kept in dirty state at first, and will be committed to KVStore in the end. - -Accounts can also be set to a suicide state. When a contract commits suicide, the account is marked as suicided, when committing the code, storage and account are deleted (from the next block and forward). - -- `Suicide()` marks the given account as suicided and clears the account balance of the EVM tokens. -- `HasSuicided()` queries the in-memory flag to check if the account has been marked as suicided in the current transaction. Accounts that are suicided will be returned as non-nil during queries and "cleared" after the block has been committed. - -To check account existence use `Exist()` and `Empty()`. - -- `Exist()` returns true if the given account exists in store or if it has been -marked as suicided. -- `Empty()` returns true if the address meets the following conditions: - - nonce is 0 - - balance amount for evm denom is 0 - - account code hash is empty - -### EIP2930 functionality - -Supports a transaction type that contains an [access list](https://eips.ethereum.org/EIPS/eip-2930), a list of addresses, and storage keys that the transaction plans to access. The access list state is kept in memory and discarded after the transaction committed. - -- `PrepareAccessList()` handles the preparatory steps for executing a state transition with regards to both EIP-2929 and EIP-2930. This method should only be called if Yolov3/Berlin/2929+2930 is applicable at the current number. - - Add sender to access list (EIP-2929) - - Add destination to access list (EIP-2929) - - Add precompiles to access list (EIP-2929) - - Add the contents of the optional tx access list (EIP-2930) -- `AddressInAccessList()` returns true if the address is registered. -- `SlotInAccessList()` checks if the address and the slots are registered. -- `AddAddressToAccessList()` adds the given address to the access list. If the address is already in the access list, this function performs a no-op. -- `AddSlotToAccessList()` adds the given (address, slot) to the access list. If the address and slot are already in the access list, this function performs a no-op. - -### Snapshot state and Revert functionality - -The EVM uses state-reverting exceptions to handle errors. Such an exception will undo all changes made to the state in the current call (and all its sub-calls), and the caller could handle the error and don't propagate. You can use `Snapshot()` to identify the current state with a revision and revert the state to a given revision with `RevertToSnapshot()` to support this feature. - -- `Snapshot()` creates a new snapshot and returns the identifier. -- `RevertToSnapshot(rev)` undo all the modifications up to the snapshot identified as `rev`. - -Ethermint adapted the [go-ethereum journal implementation](https://github.com/ethereum/go-ethereum/blob/master/core/state/journal.go#L39) to support this, it uses a list of journal logs to record all the state modification operations done so far, -snapshot is consists of a unique id and an index in the log list, and to revert to a snapshot it just undo the journal logs after the snapshot index in reversed order. - -### Ethereum Transaction logs - -With `AddLog()` you can append the given ethereum `Log` to the list of Logs associated with the transaction hash kept in the current state. This function also fills in the tx hash, block hash, tx index and log index fields before setting the log to store. - -## Keeper - -The EVM module `Keeper` grants access to the EVM module state and implements `statedb.Keeper` interface to support the `StateDB` implementation. The Keeper contains a store key that allows the DB to write to a concrete subtree of the multistore that is only accessible to the EVM module. Instead of using a trie and database for querying and persistence (the `StateDB` implementation on Ethermint), use the Cosmos `KVStore` (key-value store) and Cosmos SDK `Keeper` to facilitate state transitions. - -To support the interface functionality, it imports 4 module Keepers: - -- `auth`: CRUD accounts -- `bank`: accounting (supply) and CRUD of balances -- `staking`: query historical headers -- `fee market`: EIP1559 base fee for processing `DynamicFeeTx` after the `London` hard fork has been activated on the `ChainConfig` parameters - -```go -type Keeper struct { - // Protobuf codec - cdc codec.Codec - // Store key required for the EVM Prefix KVStore. It is required by: - // - storing account's Storage State - // - storing account's Code - // - storing module parameters - storeKey storetypes.StoreKey - - // key to access the object store, which is reset on every block during Commit - objectKey storetypes.StoreKey - - // the address capable of executing a MsgUpdateParams message. Typically, this should be the x/gov module account. - authority sdk.AccAddress - // access to account state - accountKeeper types.AccountKeeper - // update balance and accounting operations with coins - bankKeeper types.BankKeeper - // access historical headers for EVM state transition execution - stakingKeeper types.StakingKeeper - // fetch EIP1559 base fee and parameters - feeMarketKeeper types.FeeMarketKeeper - - // chain ID number obtained from the context's chain id - eip155ChainID *big.Int - - // Tracer used to collect execution traces from the EVM transaction execution - tracer string - - // EVM Hooks for tx post-processing - hooks types.EvmHooks - - customContractFns []CustomContractFn -} -``` - -## Genesis State - -The `x/evm` module `GenesisState` defines the state necessary for initializing the chain from a previous exported height. It contains the `GenesisAccounts` and the module parameters - -```go -type GenesisState struct { - // accounts is an array containing the ethereum genesis accounts. - Accounts []GenesisAccount `protobuf:"bytes,1,rep,name=accounts,proto3" json:"accounts"` - // params defines all the parameters of the module. - Params Params `protobuf:"bytes,2,opt,name=params,proto3" json:"params"` -} -``` - -## Genesis Accounts - -The `GenesisAccount` type corresponds to an adaptation of the Ethereum `GenesisAccount` type. It defines an account to be initialized in the genesis state. - -Its main difference is that the one on Ethermint uses a custom `Storage` type that uses a slice instead of maps for the evm `State` (due to non-determinism), and that it doesn't contain the private key field. - -It is also important to note that since the `auth` module on the Cosmos SDK manages the account state, the `Address` field must correspond to an existing `EthAccount` that is stored in the `auth`'s module `Keeper` (i.e `AccountKeeper`). - -```go -type GenesisAccount struct { - // address defines an ethereum hex formated address of an account - Address string `protobuf:"bytes,1,opt,name=address,proto3" json:"address,omitempty"` - // code defines the hex bytes of the account code. - Code string `protobuf:"bytes,2,opt,name=code,proto3" json:"code,omitempty"` - // storage defines the set of state key values for the account. - Storage Storage `protobuf:"bytes,3,rep,name=storage,proto3,castrepeated=Storage" json:"storage"` -} -``` diff --git a/.gitbook/developers/modules/injective/evm/03_state_transitions.md b/.gitbook/developers/modules/injective/evm/03_state_transitions.md deleted file mode 100644 index 7cfb0662..00000000 --- a/.gitbook/developers/modules/injective/evm/03_state_transitions.md +++ /dev/null @@ -1,77 +0,0 @@ ---- -updatedAt: "2025-10-29" ---- - -# State Transitions - -The `x/evm` module allows for users to submit Ethereum transactions (`Tx`) and execute their containing messages to evoke state transitions on the given state. - -Users submit transactions client-side to broadcast it to the network. When the transaction is included in a block during consensus, it is executed server-side. We highly recommend to understand the basics of the [Tendermint consensus engine](https://docs.tendermint.com/master/introduction/what-is-tendermint.html#intro-to-abci) to understand the State Transitions in detail. - -## Client-Side - -::: tip -👉 This is based on the `eth_sendTransaction` JSON-RPC -::: - -1. A user submits a transaction via one of the available JSON-RPC endpoints using an Ethereum-compatible client or wallet (eg Metamask, WalletConnect, Ledger, etc): - a. eth (public) namespace: - - `eth_sendTransaction` - - `eth_sendRawTransaction` - b. personal (private) namespace: - - `personal_sendTransaction` -2. An instance of `MsgEthereumTx` is created after populating the RPC transaction using `SetTxDefaults` to fill missing tx arguments with default values -3. The `Tx` fields are validated (stateless) using `ValidateBasic()` -4. The `Tx` is **signed** using the key associated with the sender address and the latest ethereum hard fork (`London`, `Berlin`, etc) from the `ChainConfig` -5. The `Tx` is **built** from the msg fields using the Cosmos Config builder -6. The `Tx` is **broadcasted** in [sync mode](https://docs.cosmos.network/master/run-node/txs.html#broadcasting-a-transaction) to ensure to wait for a [`CheckTx`](https://docs.tendermint.com/master/introduction/what-is-tendermint.html#intro-to-abci) execution response. Transactions are validated by the application using `CheckTx()`, before being added to the mempool of the consensus engine. -7. JSON-RPC user receives a response with the [`RLP`](https://eth.wiki/en/fundamentals/rlp) hash of the transaction fields. This hash is different from the default hash used by SDK Transactions that calculates the `sha256` hash of the transaction bytes. - -## Server-Side - -Once a block (containing the `Tx`) has been committed during consensus, it is applied to the application in a series of ABCI msgs server-side. - -Each `Tx` is handled by the application by calling [`RunTx`](https://docs.cosmos.network/master/core/baseapp.html#runtx). After a stateless validation on each `sdk.Msg` in the `Tx`, the `AnteHandler` confirms whether the `Tx` is an Ethereum or SDK transaction. As an Ethereum transaction it's containing msgs are then handled by the `x/evm` module to update the application's state. - -### AnteHandler - -The `anteHandler` is run for every transaction. It checks if the `Tx` is an Ethereum transaction and routes it to an internal ante handler. Here, `Tx`s are handled using EthereumTx extension options to process them differently than normal Cosmos SDK transactions. The `antehandler` runs through a series of options and their `AnteHandle` functions for each `Tx`: - -- `EthSetUpContextDecorator()` is adapted from SetUpContextDecorator from cosmos-sdk, it ignores gas consumption by setting the gas meter to infinite -- `EthValidateBasicDecorator(evmKeeper)` validates the fields of a Ethereum type Cosmos `Tx` msg -- `EthSigVerificationDecorator(evmKeeper)` validates that the registered chain id is the same as the one on the message, and that the signer address matches the one defined on the message. It's not skipped for RecheckTx, because it set `From` address which is critical from other ante handler to work. Failure in RecheckTx will prevent tx to be included into block, especially when CheckTx succeed, in which case user won't see the error message. -- `EthAccountVerificationDecorator(ak, bankKeeper, evmKeeper)` that the sender balance is greater than the total transaction cost. The account will be set to store if it doesn't exist, i.e cannot be found on store. This AnteHandler decorator will fail if: - - any of the msgs is not a MsgEthereumTx - - from address is empty - - account balance is lower than the transaction cost -- `EthNonceVerificationDecorator(ak)` validates that the transaction nonces are valid and equivalent to the sender account’s current nonce. -- `EthGasConsumeDecorator(evmKeeper)` validates that the Ethereum tx message has enough to cover intrinsic gas (during CheckTx only) and that the sender has enough balance to pay for the gas cost. Intrinsic gas for a transaction is the amount of gas that the transaction uses before the transaction is executed. The gas is a constant value plus any cost incurred by additional bytes of data supplied with the transaction. This AnteHandler decorator will fail if: - - the transaction contains more than one message - - the message is not a MsgEthereumTx - - sender account cannot be found - - transaction's gas limit is lower than the intrinsic gas - - user doesn't have enough balance to deduct the transaction fees (gas_limit * gas_price) - - transaction or block gas meter runs out of gas -- `CanTransferDecorator(evmKeeper, feeMarketKeeper)` creates an EVM from the message and calls the BlockContext CanTransfer function to see if the address can execute the transaction. -- `EthIncrementSenderSequenceDecorator(ak)` handles incrementing the sequence of the signer (i.e sender). If the transaction is a contract creation, the nonce will be incremented during the transaction execution and not within this AnteHandler decorator. - -The options `authante.NewMempoolFeeDecorator()`, `authante.NewTxTimeoutHeightDecorator()` and `authante.NewValidateMemoDecorator(ak)` are the same as for a Cosmos `Tx`. Click [here](https://docs.cosmos.network/master/basics/gas-fees.html#antehandler) for more on the `anteHandler`. - -### EVM module - -After authentication through the `antehandler`, each `sdk.Msg` (in this case `MsgEthereumTx`) in the `Tx` is delivered to the Msg Handler in the `x/evm` module and runs through the following the steps: - -1. Convert `Msg` to an ethereum `Tx` type -2. Apply `Tx` with `EVMConfig` and attempt to perform a state transition, that will only be persisted (committed) to the underlying KVStore if the transaction does not fail: - 1. Confirm that `EVMConfig` is created - 2. Create the ethereum signer using chain config value from `EVMConfig` - 3. Set the ethereum transaction hash to the (impermanent) transient store so that it's also available on the StateDB functions - 4. Generate a new EVM instance - 5. Confirm that EVM params for contract creation (`EnableCreate`) and contract execution (`EnableCall`) are enabled - 6. Apply message. If `To` address is `nil`, create new contract using code as deployment code. Else call contract at given address with the given input as parameters - 7. Calculate gas used by the evm operation -3. If `Tx` applied sucessfully - 1. Execute EVM `Tx` postprocessing hooks. If hooks return error, revert the whole `Tx` - 2. Refund gas according to Ethereum gas accounting rules - 3. Update block bloom filter value using the logs generated from the tx - 4. Emit SDK events for the transaction fields and tx logs diff --git a/.gitbook/developers/modules/injective/evm/04_transactions.md b/.gitbook/developers/modules/injective/evm/04_transactions.md deleted file mode 100644 index e577fd80..00000000 --- a/.gitbook/developers/modules/injective/evm/04_transactions.md +++ /dev/null @@ -1,237 +0,0 @@ ---- -updatedAt: "2025-10-29" ---- - -# Transactions - -This section defines the `sdk.Msg` concrete types that result in the state transitions defined on the previous section. - -## `MsgEthereumTx` - -An EVM state transition can be achieved by using the `MsgEthereumTx`. This message encapsulates an Ethereum transaction data (`TxData`) as a `sdk.Msg`. It contains the necessary transaction data fields. Note, that the `MsgEthereumTx` implements both the [`sdk.Msg`](https://github.com/cosmos/cosmos-sdk/blob/v0.39.2/types/tx_msg.go#L7-L29) and [`sdk.Tx`](https://github.com/cosmos/cosmos-sdk/blob/v0.39.2/types/tx_msg.go#L33-L41) interfaces. Normally, SDK messages only implement the former, while the latter is a group of messages bundled together. - -```go -type MsgEthereumTx struct { - // inner transaction data - Data *types.Any `protobuf:"bytes,1,opt,name=data,proto3" json:"data,omitempty"` - // DEPRECATED: encoded storage size of the transaction - Size_ float64 `protobuf:"fixed64,2,opt,name=size,proto3" json:"-"` - // transaction hash in hex format - Hash string `protobuf:"bytes,3,opt,name=hash,proto3" json:"hash,omitempty" rlp:"-"` - // ethereum signer address in hex format. This address value is checked - // against the address derived from the signature (V, R, S) using the - // secp256k1 elliptic curve - From string `protobuf:"bytes,4,opt,name=from,proto3" json:"from,omitempty"` -} -``` - -This message field validation is expected to fail if: - -- `From` field is defined and the address is invalid -- `TxData` stateless validation fails - -The transaction execution is expected to fail if: - -- Any of the custom `AnteHandler` Ethereum decorators checks fail: - - Minimum gas amount requirements for transaction - - Tx sender account doesn't exist or hasn't enough balance for fees - - Account sequence doesn't match the transaction `Data.AccountNonce` - - Message signature verification fails -- EVM contract creation (i.e `evm.Create`) fails, or `evm.Call` fails - -### Conversion - -The `MsgEthreumTx` can be converted to the go-ethereum `Transaction` and `Message` types in order to create and call evm contracts. - -```go -// AsTransaction creates an Ethereum Transaction type from the msg fields -func (msg MsgEthereumTx) AsTransaction() *ethtypes.Transaction { - txData, err := UnpackTxData(msg.Data) - if err != nil { - return nil - } - - return ethtypes.NewTx(txData.AsEthereumData()) -} - -// AsMessage returns the transaction as a core.Message. -func (tx *Transaction) AsMessage(s Signer, baseFee *big.Int) (Message, error) { - msg := Message{ - nonce: tx.Nonce(), - gasLimit: tx.Gas(), - gasPrice: new(big.Int).Set(tx.GasPrice()), - gasFeeCap: new(big.Int).Set(tx.GasFeeCap()), - gasTipCap: new(big.Int).Set(tx.GasTipCap()), - to: tx.To(), - amount: tx.Value(), - data: tx.Data(), - accessList: tx.AccessList(), - isFake: false, - } - // If baseFee provided, set gasPrice to effectiveGasPrice. - if baseFee != nil { - msg.gasPrice = math.BigMin(msg.gasPrice.Add(msg.gasTipCap, baseFee), msg.gasFeeCap) - } - var err error - msg.from, err = Sender(s, tx) - return msg, err -} -``` - -### Signing - -In order for the signature verification to be valid, the `TxData` must contain the `v | r | s` values from the `Signer`. Sign calculates a secp256k1 ECDSA signature and signs the transaction. It takes a keyring signer and the chainID to sign an Ethereum transaction according to EIP155 standard. This method mutates the transaction as it populates the V, R, S fields of the Transaction's Signature. The function will fail if the sender address is not defined for the msg or if the sender is not registered on the keyring. - -```go -// Sign calculates a secp256k1 ECDSA signature and signs the transaction. It -// takes a keyring signer and the chainID to sign an Ethereum transaction according to -// EIP155 standard. -// This method mutates the transaction as it populates the V, R, S -// fields of the Transaction's Signature. -// The function will fail if the sender address is not defined for the msg or if -// the sender is not registered on the keyring -func (msg *MsgEthereumTx) Sign(ethSigner ethtypes.Signer, keyringSigner keyring.Signer) error { - from := msg.GetFrom() - if from.Empty() { - return fmt.Errorf("sender address not defined for message") - } - - tx := msg.AsTransaction() - txHash := ethSigner.Hash(tx) - - sig, _, err := keyringSigner.SignByAddress(from, txHash.Bytes()) - if err != nil { - return err - } - - tx, err = tx.WithSignature(ethSigner, sig) - if err != nil { - return err - } - - msg.FromEthereumTx(tx) - return nil -} -``` - -## TxData - -The `MsgEthereumTx` supports the 3 valid Ethereum transaction data types from go-ethereum: `LegacyTx`, `AccessListTx` and `DynamicFeeTx`. These types are defined as protobuf messages and packed into a `proto.Any` interface type in the `MsgEthereumTx` field. - -- `LegacyTx`: [EIP-155](https://github.com/ethereum/EIPs/blob/master/EIPS/eip-155.md) transaction type -- `DynamicFeeTx`: [EIP-1559](https://eips.ethereum.org/EIPS/eip-1559) transaction type. Enabled by London hard fork block -- `AccessListTx`: [EIP-2930](https://eips.ethereum.org/EIPS/eip-2930) transaction type. Enabled by Berlin hard fork block - -### `LegacyTx` - -The transaction data of regular Ethereum transactions. - -```go -type LegacyTx struct { - // nonce corresponds to the account nonce (transaction sequence). - Nonce uint64 `protobuf:"varint,1,opt,name=nonce,proto3" json:"nonce,omitempty"` - // gas price defines the value for each gas unit - GasPrice *github_com_cosmos_cosmos_sdk_types.Int `protobuf:"bytes,2,opt,name=gas_price,json=gasPrice,proto3,customtype=github.com/cosmos/cosmos-sdk/types.Int" json:"gas_price,omitempty"` - // gas defines the gas limit defined for the transaction. - GasLimit uint64 `protobuf:"varint,3,opt,name=gas,proto3" json:"gas,omitempty"` - // hex formatted address of the recipient - To string `protobuf:"bytes,4,opt,name=to,proto3" json:"to,omitempty"` - // value defines the unsigned integer value of the transaction amount. - Amount *github_com_cosmos_cosmos_sdk_types.Int `protobuf:"bytes,5,opt,name=value,proto3,customtype=github.com/cosmos/cosmos-sdk/types.Int" json:"value,omitempty"` - // input defines the data payload bytes of the transaction. - Data []byte `protobuf:"bytes,6,opt,name=data,proto3" json:"data,omitempty"` - // v defines the signature value - V []byte `protobuf:"bytes,7,opt,name=v,proto3" json:"v,omitempty"` - // r defines the signature value - R []byte `protobuf:"bytes,8,opt,name=r,proto3" json:"r,omitempty"` - // s define the signature value - S []byte `protobuf:"bytes,9,opt,name=s,proto3" json:"s,omitempty"` -} -``` - -This message field validation is expected to fail if: - -- `GasPrice` is invalid (`nil` , negaitve or out of int256 bound) -- `Fee` (gasprice * gaslimit) is invalid -- `Amount` is invalid (negaitve or out of int256 bound) -- `To` address is invalid (non valid ethereum hex address) - -### `DynamicFeeTx` - -The transaction data of EIP-1559 dynamic fee transactions. - -```go -type DynamicFeeTx struct { - // destination EVM chain ID - ChainID *github_com_cosmos_cosmos_sdk_types.Int `protobuf:"bytes,1,opt,name=chain_id,json=chainId,proto3,customtype=github.com/cosmos/cosmos-sdk/types.Int" json:"chainID"` - // nonce corresponds to the account nonce (transaction sequence). - Nonce uint64 `protobuf:"varint,2,opt,name=nonce,proto3" json:"nonce,omitempty"` - // gas tip cap defines the max value for the gas tip - GasTipCap *github_com_cosmos_cosmos_sdk_types.Int `protobuf:"bytes,3,opt,name=gas_tip_cap,json=gasTipCap,proto3,customtype=github.com/cosmos/cosmos-sdk/types.Int" json:"gas_tip_cap,omitempty"` - // gas fee cap defines the max value for the gas fee - GasFeeCap *github_com_cosmos_cosmos_sdk_types.Int `protobuf:"bytes,4,opt,name=gas_fee_cap,json=gasFeeCap,proto3,customtype=github.com/cosmos/cosmos-sdk/types.Int" json:"gas_fee_cap,omitempty"` - // gas defines the gas limit defined for the transaction. - GasLimit uint64 `protobuf:"varint,5,opt,name=gas,proto3" json:"gas,omitempty"` - // hex formatted address of the recipient - To string `protobuf:"bytes,6,opt,name=to,proto3" json:"to,omitempty"` - // value defines the the transaction amount. - Amount *github_com_cosmos_cosmos_sdk_types.Int `protobuf:"bytes,7,opt,name=value,proto3,customtype=github.com/cosmos/cosmos-sdk/types.Int" json:"value,omitempty"` - // input defines the data payload bytes of the transaction. - Data []byte `protobuf:"bytes,8,opt,name=data,proto3" json:"data,omitempty"` - Accesses AccessList `protobuf:"bytes,9,rep,name=accesses,proto3,castrepeated=AccessList" json:"accessList"` - // v defines the signature value - V []byte `protobuf:"bytes,10,opt,name=v,proto3" json:"v,omitempty"` - // r defines the signature value - R []byte `protobuf:"bytes,11,opt,name=r,proto3" json:"r,omitempty"` - // s define the signature value - S []byte `protobuf:"bytes,12,opt,name=s,proto3" json:"s,omitempty"` -} -``` - -This message field validation is expected to fail if: - -- `GasTipCap` is invalid (`nil` , negative or overflows int256) -- `GasFeeCap` is invalid (`nil` , negative or overflows int256) -- `GasFeeCap` is less than `GasTipCap` -- `Fee` (gas price * gas limit) is invalid (overflows int256) -- `Amount` is invalid (negative or overflows int256) -- `To` address is invalid (non-valid ethereum hex address) -- `ChainID` is `nil` - -### `AccessListTx` - -The transaction data of EIP-2930 access list transactions. - -```go -type AccessListTx struct { - // destination EVM chain ID - ChainID *github_com_cosmos_cosmos_sdk_types.Int `protobuf:"bytes,1,opt,name=chain_id,json=chainId,proto3,customtype=github.com/cosmos/cosmos-sdk/types.Int" json:"chainID"` - // nonce corresponds to the account nonce (transaction sequence). - Nonce uint64 `protobuf:"varint,2,opt,name=nonce,proto3" json:"nonce,omitempty"` - // gas price defines the value for each gas unit - GasPrice *github_com_cosmos_cosmos_sdk_types.Int `protobuf:"bytes,3,opt,name=gas_price,json=gasPrice,proto3,customtype=github.com/cosmos/cosmos-sdk/types.Int" json:"gas_price,omitempty"` - // gas defines the gas limit defined for the transaction. - GasLimit uint64 `protobuf:"varint,4,opt,name=gas,proto3" json:"gas,omitempty"` - // hex formatted address of the recipient - To string `protobuf:"bytes,5,opt,name=to,proto3" json:"to,omitempty"` - // value defines the unsigned integer value of the transaction amount. - Amount *github_com_cosmos_cosmos_sdk_types.Int `protobuf:"bytes,6,opt,name=value,proto3,customtype=github.com/cosmos/cosmos-sdk/types.Int" json:"value,omitempty"` - // input defines the data payload bytes of the transaction. - Data []byte `protobuf:"bytes,7,opt,name=data,proto3" json:"data,omitempty"` - Accesses AccessList `protobuf:"bytes,8,rep,name=accesses,proto3,castrepeated=AccessList" json:"accessList"` - // v defines the signature value - V []byte `protobuf:"bytes,9,opt,name=v,proto3" json:"v,omitempty"` - // r defines the signature value - R []byte `protobuf:"bytes,10,opt,name=r,proto3" json:"r,omitempty"` - // s define the signature value - S []byte `protobuf:"bytes,11,opt,name=s,proto3" json:"s,omitempty"` -} -``` - -This message field validation is expected to fail if: - -- `GasPrice` is invalid (`nil` , negative or overflows int256) -- `Fee` (gas price * gas limit) is invalid (overflows int256) -- `Amount` is invalid (negative or overflows int256) -- `To` address is invalid (non-valid ethereum hex address) -- `ChainID` is `nil` diff --git a/.gitbook/developers/modules/injective/evm/05_abci.md b/.gitbook/developers/modules/injective/evm/05_abci.md deleted file mode 100644 index a1a22a71..00000000 --- a/.gitbook/developers/modules/injective/evm/05_abci.md +++ /dev/null @@ -1,30 +0,0 @@ ---- -updatedAt: "2025-10-29" ---- - -# ABCI - -The Application Blockchain Interface (ABCI) allows the application to interact with the Tendermint Consensus engine. The application maintains several separate ABCI connections with Tendermint. The most relevant for the `x/evm` is the [Consensus connection at Commit](https://docs.tendermint.com/v0.35/spec/abci/apps.html#consensus-connection). This connection is responsible for block execution and calls the fuctions `InitChain` (containing `InitGenesis`), `BeginBlock`, `DeliverTx`, `EndBlock`, `Commit` . `InitChain` is only called the first time a new blockchain is started and `DeliverTx` is called for each transaction in the block. - -## InitGenesis - -`InitGenesis` initializes the EVM module genesis state by setting the `GenesisState` fields to the store. In particular it sets the parameters and genesis accounts (state and code). - -## ExportGenesis - -The `ExportGenesis` ABCI function exports the genesis state of the EVM module. In particular, it retrieves all the accounts with their bytecode, balance and storage, the transaction logs, and the EVM parameters and chain configuration. - -## BeginBlock - -The EVM module `BeginBlock` logic is executed prior to handling the state transitions from the transactions. The main objective of this function is to: - -- Set the context for the current block so that the block header, store, gas meter, etc are available to the `Keeper` once one of the `StateDB` functions are called during EVM state transitions. -- Set the EIP155 `ChainID` number (obtained from the full chain-id), in case it hasn't been set before during `InitChain` - -## EndBlock - -The EVM module `EndBlock` logic occurs after executing all the state transitions from the transactions. The main objective of this function is to: - -- Emit Block bloom events - - This is due for Web3 compatibility as the Ethereum headers contain this type as a field. The JSON-RPC service uses this event query to construct an Ethereum Header from a Tendermint Header. - - The block Bloom filter value is obtained from the Transient Store and then emitted diff --git a/.gitbook/developers/modules/injective/evm/06_hooks.md b/.gitbook/developers/modules/injective/evm/06_hooks.md deleted file mode 100644 index 456c1edc..00000000 --- a/.gitbook/developers/modules/injective/evm/06_hooks.md +++ /dev/null @@ -1,194 +0,0 @@ ---- -updatedAt: "2025-10-29" ---- - -# Hooks - -The `x/evm` module implements an `EvmHooks` interface that extend and customize the `Tx` processing logic externally. - -This supports EVM contracts to call native cosmos modules by - -1. defining a log signature and emitting the specific log from the smart contract, -2. recognizing those logs in the native tx processing code, and -3. converting them to native module calls. - -To do this, the interface includes a `PostTxProcessing` hook that registers custom `Tx` hooks in the `EvmKeeper`. These `Tx` hooks are processed after the EVM state transition is finalized and doesn't fail. Note that there are no default hooks implemented in the EVM module. - -```go -type EvmHooks interface { - // Must be called after tx is processed successfully, if return an error, the whole transaction is reverted. - PostTxProcessing(ctx sdk.Context, msg core.Message, receipt *ethtypes.Receipt) error -} -``` - -## `PostTxProcessing` - - `PostTxProcessing` is only called after a EVM transaction finished successfully and delegates the call to underlying hooks. If no hook has been registered, this function returns with a `nil` error. - -```go -func (k *Keeper) PostTxProcessing(ctx sdk.Context, msg core.Message, receipt *ethtypes.Receipt) error { - if k.hooks == nil { - return nil - } - return k.hooks.PostTxProcessing(k.Ctx(), msg, receipt) -} -``` - -It's executed in the same cache context as the EVM transaction, if it returns an error, the whole EVM transaction is reverted, if the hook implementor doesn't want to revert the tx, they can always return `nil` instead. - -The error returned by the hooks is translated to a VM error `failed to process native logs`, the detailed error message is stored in the return value. The message is sent to native modules asynchronously, there's no way for the caller to catch and recover the error. - -## Use Case: Call Native ERC20 Module on Injective - -Here is an example taken from the Injective [erc20 module]() that shows how the `EVMHooks` supports a contract calling a native module to convert ERC-20 Tokens into Cosmos native Coins. Following the steps from above. - -You can define and emit a `Transfer` log signature in the smart contract like this: - -```solidity -event Transfer(address indexed from, address indexed to, uint256 value); - -function _transfer(address sender, address recipient, uint256 amount) internal virtual { - require(sender != address(0), "ERC20: transfer from the zero address"); - require(recipient != address(0), "ERC20: transfer to the zero address"); - - _beforeTokenTransfer(sender, recipient, amount); - - _balances[sender] = _balances[sender].sub(amount, "ERC20: transfer amount exceeds balance"); - _balances[recipient] = _balances[recipient].add(amount); - emit Transfer(sender, recipient, amount); -} -``` - -The application will register a `BankSendHook` to the `EvmKeeper`. It recognizes the ethereum tx `Log` and converts it to a call to the bank module's `SendCoinsFromAccountToAccount` method: - -```go - -const ERC20EventTransfer = "Transfer" - -// PostTxProcessing implements EvmHooks.PostTxProcessing -func (k Keeper) PostTxProcessing( - ctx sdk.Context, - msg core.Message, - receipt *ethtypes.Receipt, -) error { - params := h.k.GetParams(ctx) - if !params.EnableErc20 || !params.EnableEVMHook { - // no error is returned to allow for other post processing txs - // to pass - return nil - } - - erc20 := contracts.ERC20BurnableContract.ABI - - for i, log := range receipt.Logs { - if len(log.Topics) < 3 { - continue - } - - eventID := log.Topics[0] // event ID - - event, err := erc20.EventByID(eventID) - if err != nil { - // invalid event for ERC20 - continue - } - - if event.Name != types.ERC20EventTransfer { - h.k.Logger(ctx).Info("emitted event", "name", event.Name, "signature", event.Sig) - continue - } - - transferEvent, err := erc20.Unpack(event.Name, log.Data) - if err != nil { - h.k.Logger(ctx).Error("failed to unpack transfer event", "error", err.Error()) - continue - } - - if len(transferEvent) == 0 { - continue - } - - tokens, ok := transferEvent[0].(*big.Int) - // safety check and ignore if amount not positive - if !ok || tokens == nil || tokens.Sign() != 1 { - continue - } - - // check that the contract is a registered token pair - contractAddr := log.Address - - id := h.k.GetERC20Map(ctx, contractAddr) - - if len(id) == 0 { - // no token is registered for the caller contract - continue - } - - pair, found := h.k.GetTokenPair(ctx, id) - if !found { - continue - } - - // check that conversion for the pair is enabled - if !pair.Enabled { - // continue to allow transfers for the ERC20 in case the token pair is disabled - h.k.Logger(ctx).Debug( - "ERC20 token -> Cosmos coin conversion is disabled for pair", - "coin", pair.Denom, "contract", pair.Erc20Address, - ) - continue - } - - // ignore as the burning always transfers to the zero address - to := common.BytesToAddress(log.Topics[2].Bytes()) - if !bytes.Equal(to.Bytes(), types.ModuleAddress.Bytes()) { - continue - } - - // check that the event is Burn from the ERC20Burnable interface - // NOTE: assume that if they are burning the token that has been registered as a pair, they want to mint a Cosmos coin - - // create the corresponding sdk.Coin that is paired with ERC20 - coins := sdk.Coins{{Denom: pair.Denom, Amount: sdk.NewIntFromBigInt(tokens)}} - - // Mint the coin only if ERC20 is external - switch pair.ContractOwner { - case types.OWNER_MODULE: - _, err = h.k.CallEVM(ctx, erc20, types.ModuleAddress, contractAddr, true, "burn", tokens) - case types.OWNER_EXTERNAL: - err = h.k.bankKeeper.MintCoins(ctx, types.ModuleName, coins) - default: - err = types.ErrUndefinedOwner - } - - if err != nil { - h.k.Logger(ctx).Debug( - "failed to process EVM hook for ER20 -> coin conversion", - "coin", pair.Denom, "contract", pair.Erc20Address, "error", err.Error(), - ) - continue - } - - // Only need last 20 bytes from log.topics - from := common.BytesToAddress(log.Topics[1].Bytes()) - recipient := sdk.AccAddress(from.Bytes()) - - // transfer the tokens from ModuleAccount to sender address - if err := h.k.bankKeeper.SendCoinsFromModuleToAccount(ctx, types.ModuleName, recipient, coins); err != nil { - h.k.Logger(ctx).Debug( - "failed to process EVM hook for ER20 -> coin conversion", - "tx-hash", receipt.TxHash.Hex(), "log-idx", i, - "coin", pair.Denom, "contract", pair.Erc20Address, "error", err.Error(), - ) - continue - } - } - - return nil -``` - -Lastly, register the hook in `app.go`: - -```go -app.EvmKeeper = app.EvmKeeper.SetHooks(app.Erc20Keeper) -``` diff --git a/.gitbook/developers/modules/injective/evm/07_events.md b/.gitbook/developers/modules/injective/evm/07_events.md deleted file mode 100644 index db5f4e1e..00000000 --- a/.gitbook/developers/modules/injective/evm/07_events.md +++ /dev/null @@ -1,31 +0,0 @@ ---- -updatedAt: "2025-10-29" ---- - -# Events - -The `x/evm` module emits the Cosmos SDK events after a state execution. The EVM module emits events of the relevant transaction fields, as well as the transaction logs (ethereum events). - -## MsgEthereumTx - -| Type | Attribute Key | Attribute Value | -| ----------- | ------------------ | ----------------------- | -| ethereum_tx | `"amount"` | `{amount}` | -| ethereum_tx | `"recipient"` | `{hex_address}` | -| ethereum_tx | `"contract"` | `{hex_address}` | -| ethereum_tx | `"txHash"` | `{tendermint_hex_hash}` | -| ethereum_tx | `"ethereumTxHash"` | `{hex_hash}` | -| ethereum_tx | `"txIndex"` | `{tx_index}` | -| ethereum_tx | `"txGasUsed"` | `{gas_used}` | -| tx_log | `"txLog"` | `{tx_log}` | -| message | `"sender"` | `{eth_address}` | -| message | `"action"` | `"ethereum"` | -| message | `"module"` | `"evm"` | - -Additionally, the EVM module emits an event during `EndBlock` for the filter query block bloom. - -## ABCI - -| Type | Attribute Key | Attribute Value | -| ----------- | ------------- | -------------------- | -| block_bloom | `"bloom"` | `string(bloomBytes)` | diff --git a/.gitbook/developers/modules/injective/evm/08_params.md b/.gitbook/developers/modules/injective/evm/08_params.md deleted file mode 100644 index 563e4615..00000000 --- a/.gitbook/developers/modules/injective/evm/08_params.md +++ /dev/null @@ -1,81 +0,0 @@ ---- -updatedAt: "2025-10-29" ---- - -# Parameters - -The evm module contains the following parameters: - -## Params - -| Key | Type | Default Value | -| -------------- | ----------- |-----------------| -| `EVMDenom` | string | `"inj"` | -| `EnableCreate` | bool | `true` | -| `EnableCall` | bool | `true` | -| `ExtraEIPs` | []int | TBD | -| `ChainConfig` | ChainConfig | See ChainConfig | - -## EVM denom - -The evm denomination parameter defines the token denomination used on the EVM state transitions and gas consumption for EVM messages. - -For example, on Ethereum, the `evm_denom` would be `ETH`. To maintain parity with Ethereum, Injective uses Atto as its base denomination. In essence, 1 (atto) inj equals `1x10⁻¹⁸ INJ`, aligning with Ethereum’s denomination where one wei is equal to 1x10⁻¹⁸ ETH. In terms of precision, the `INJ` and `ETH` share the same value, *i.e* `1 INJ = 10^18 inj` and `1 ETH = 10^18 wei`. - -## Enable Create - -The enable create parameter toggles state transitions that use the `vm.Create` function. When the parameter is disabled, it will prevent all contract creation functionality. - -## Enable Transfer - -The enable transfer toggles state transitions that use the `vm.Call` function. When the parameter is disabled, it will prevent transfers between accounts and executing a smart contract call. - -## Extra EIPs - -The extra EIPs parameter defines the set of activateable Ethereum Improvement Proposals (**[EIPs](https://ethereum.org/en/eips/)**) -on the Ethereum VM `Config` that apply custom jump tables. - -::: tip -NOTE: some of these EIPs are already enabled by the chain configuration, depending on the hard fork number. -::: - -The supported activateable EIPS are: - -- **[EIP 1344](https://eips.ethereum.org/EIPS/eip-1344)** -- **[EIP 1884](https://eips.ethereum.org/EIPS/eip-1884)** -- **[EIP 2200](https://eips.ethereum.org/EIPS/eip-2200)** -- **[EIP 2315](https://eips.ethereum.org/EIPS/eip-2315)** -- **[EIP 2929](https://eips.ethereum.org/EIPS/eip-2929)** -- **[EIP 3198](https://eips.ethereum.org/EIPS/eip-3198)** -- **[EIP 3529](https://eips.ethereum.org/EIPS/eip-3529)** - -## Chain Config - -The `ChainConfig` is a protobuf wrapper type that contains the same fields as the go-ethereum `ChainConfig` parameters, but using `*sdk.Int` types instead of `*big.Int`. - -By default, all block configuration fields but `ConstantinopleBlock`, are enabled at genesis (height 0). - -### ChainConfig Defaults - -| Name | Default Value | -| ------------------- | -------------------------------------------------------------------- | -| HomesteadBlock | 0 | -| DAOForkBlock | 0 | -| DAOForkSupport | `true` | -| EIP150Block | 0 | -| EIP150Hash | `0x0000000000000000000000000000000000000000000000000000000000000000` | -| EIP155Block | 0 | -| EIP158Block | 0 | -| ByzantiumBlock | 0 | -| ConstantinopleBlock | 0 | -| PetersburgBlock | 0 | -| IstanbulBlock | 0 | -| MuirGlacierBlock | 0 | -| BerlinBlock | 0 | -| LondonBlock | 0 | -| ArrowGlacierBlock | 0 | -| GrayGlacierBlock | 0 | -| MergeNetsplitBlock | 0 | -| ShanghaiTime | 0 | -| CancunTime | 0 | -| PragueTime | 0 | diff --git a/.gitbook/developers/modules/injective/evm/09_client.md b/.gitbook/developers/modules/injective/evm/09_client.md deleted file mode 100644 index d47d7eb2..00000000 --- a/.gitbook/developers/modules/injective/evm/09_client.md +++ /dev/null @@ -1,107 +0,0 @@ ---- -updatedAt: "2025-10-29" ---- - -# Client - -A user can query and interact with the `evm` module using the CLI, JSON-RPC, gRPC or REST. - -## CLI - -Find below a list of `injectived` commands added with the `x/evm` module. You can obtain the full list by using the `injectived -h` command. - -### Queries - -The `query` commands allow users to query `evm` state. - -**`code`** - -Allows users to query the smart contract code at a given address. - -```go -injectived query evm code ADDRESS [flags] -``` - -```bash -# Example -$ injectived query evm code 0x7bf7b17da59880d9bcca24915679668db75f9397 - -# Output -code: "0xef616c92f3cfc9e92dc270d6acff9cea213cecc7020a76ee4395af09bdceb4837a1ebdb5735e11e7d3adb6104e0c3ac55180b4ddf5e54d022cc5e8837f6a4f971b" -``` - -**`storage`** - -Allows users to query storage for an account with a given key and height. - -```bash -injectived query evm storage ADDRESS KEY [flags] -``` - -```bash -# Example -$ injectived query evm storage 0x0f54f47bf9b8e317b214ccd6a7c3e38b893cd7f0 0 --height 0 - -# Output -value: "0x0000000000000000000000000000000000000000000000000000000000000000" -``` - -### Transactions - -The `tx` commands allow users to interact with the `evm` module. - -**`raw`** - -Allows users to build cosmos transactions from raw ethereum transaction. - -```bash -injectived tx evm raw TX_HEX [flags] -``` - -```bash -# Example -$ injectived tx evm raw 0xf9ff74c86aefeb5f6019d77280bbb44fb695b4d45cfe97e6eed7acd62905f4a85034d5c68ed25a2e7a8eeb9baf1b84 - -# Output -value: "0x0000000000000000000000000000000000000000000000000000000000000000" -``` - -## JSON-RPC - -For an overview on the JSON-RPC methods and namespaces supported on Ethermint, please refer to [https://docs.injective.zone/basics/json_rpc.html](https://docs.injective.zone/basics/json_rpc.html) - -## gRPC - -### Queries - -| Verb | Method | Description | -| ------ | ---------------------------------------------------- | -------------------------------------------------------------------------- | -| `gRPC` | `injective.evm.v1.Query/Account` | Get an Ethereum account | -| `gRPC` | `injective.evm.v1.Query/CosmosAccount` | Get an Ethereum account's Cosmos Address | -| `gRPC` | `injective.evm.v1.Query/ValidatorAccount` | Get an Ethereum account's from a validator consensus Address | -| `gRPC` | `injective.evm.v1.Query/Balance` | Get the balance of a the EVM denomination for a single EthAccount. | -| `gRPC` | `injective.evm.v1.Query/Storage` | Get the balance of all coins for a single account | -| `gRPC` | `injective.evm.v1.Query/Code` | Get the balance of all coins for a single account | -| `gRPC` | `injective.evm.v1.Query/Params` | Get the parameters of x/evm module | -| `gRPC` | `injective.evm.v1.Query/EthCall` | Implements the eth_call rpc api | -| `gRPC` | `injective.evm.v1.Query/EstimateGas` | Implements the eth_estimateGas rpc api | -| `gRPC` | `injective.evm.v1.Query/TraceTx` | Implements the debug_traceTransaction rpc api | -| `gRPC` | `injective.evm.v1.Query/TraceBlock` | Implements the debug_traceBlockByNumber and debug_traceBlockByHash rpc api | -| `GET` | `/injective/evm/v1/account/{address}` | Get an Ethereum account | -| `GET` | `/injective/evm/v1/cosmos_account/{address}` | Get an Ethereum account's Cosmos Address | -| `GET` | `/injective/evm/v1/validator_account/{cons_address}` | Get an Ethereum account's from a validator consensus Address | -| `GET` | `/injective/evm/v1/balances/{address}` | Get the balance of a the EVM denomination for a single EthAccount. | -| `GET` | `/injective/evm/v1/storage/{address}/{key}` | Get the balance of all coins for a single account | -| `GET` | `/injective/evm/v1/codes/{address}` | Get the balance of all coins for a single account | -| `GET` | `/injective/evm/v1/params` | Get the parameters of x/evm module | -| `GET` | `/injective/evm/v1/eth_call` | Implements the eth_call rpc api | -| `GET` | `/injective/evm/v1/estimate_gas` | Implements the eth_estimateGas rpc api | -| `GET` | `/injective/evm/v1/trace_tx` | Implements the debug_traceTransaction rpc api | -| `GET` | `/injective/evm/v1/trace_block` | Implements the debug_traceBlockByNumber and debug_traceBlockByHash rpc api | - -### Transactions - -| Verb | Method | Description | -| ------ | --------------------------------- | ------------------------------- | -| `gRPC` | `injective.evm.v1.Msg/EthereumTx` | Submit an Ethereum transactions | -| `POST` | `/injective/evm/v1/ethereum_tx` | Submit an Ethereum transactions | diff --git a/.gitbook/developers/modules/injective/exchange/12_gas_heuristics.md b/.gitbook/developers/modules/injective/exchange/12_gas_heuristics.md deleted file mode 100644 index 33350c4a..00000000 --- a/.gitbook/developers/modules/injective/exchange/12_gas_heuristics.md +++ /dev/null @@ -1,91 +0,0 @@ ---- -sidebar_position: 13 -title: Gas Heuristics -updatedAt: "2025-10-03" ---- - -This doc contains suggested `gasWanted` values for specific Exchange messages. Values were obtained heuristically -by observing gas consumption during MsgServer execution for a transaction containing a single Msg type. Conceptually, -for any transaction the following formula applies: - -``` - tx_gas = ante_gas + msg_gas (+ msg2_gas ...) -``` - -where `ante_gas` is the gas consumed during `AnteHandler` and the subsequent sum of `msg_gas` is gas consumed -by MsgServer of each particular msg (highest observed `ante_gas` is 120_000). - -With `fixed_gas_enabled` set to `true` in Exchange params, the following values can be used as `gasWanted` in order to -ensure a transaction does not run out of gas: - -> **Note**: It is assumed that the transaction contains a single message`. - -| Message Type | Gas Wanted | -|-------------------------------------------------|------------------------------| -| MsgCreateDerivativeLimitOrder | 240,000 (post-only: 260,000) | -| MsgCreateDerivativeMarketOrder | 235,000 | -| MsgCancelDerivativeOrder | 190,000 | -| MsgCreateSpotLimitOrder | 220,000 (post-only: 240,000) | -| MsgCreateSpotMarketOrder | 170,000 | -| MsgCancelSpotOrder | 185,000 | -| MsgCreateBinaryOptionsLimitOrder | 240,000 (post-only: 260,000) | -| MsgCreateBinaryOptionsMarketOrder | 225,000 | -| MsgCancelBinaryOptionsOrder | 190,000 | -| MsgDeposit | 158,000 | -| MsgWithdrawGas | 155,000 | -| MsgSubaccountTransferGas | 135,000 | -| MsgExternalTransferGas | 160,000 | -| MsgIncreasePositionMarginGas | 171,000 | -| MsgDecreasePositionMarginGas | 180,000 | - -If the order in question is also a GTB (Good-Till-Block) order, an amount of gas equal to 10% of the above values should be added on top. - -**Batch Msg types** - -Gas for batch message types varies based on the content of the message itself. Additionally, `ante_gas` scales with the -number of orders (noticeably around 3000 added gas, included in this formula).: - -`N` - is the number of orders - -- `MsgBatchCreateSpotLimitOrders`: `tx_gas = 120_000 + N x 103_000` (e.g. for 3 orders you get `329_000`) -- `MsgBatchCancelSpotOrders`: `tx_gas = 120_000 + N x 68_000` -- `MsgBatchCreateDerivativeLimitOrders`: `tx_gas = 120_000 + N x 123_000` -- `MsgBatchCancelDerivativeOrders`: `tx_gas = 120_000 + N x 73_000` -- `MsgBatchCancelBinaryOptionsOrders`: `tx_gas = 120_000 + N x 123_000` - -***MsgBatchUpdateOrders*** - -```go -type MsgBatchUpdateOrders struct { - Sender string - - SubaccountId string // used only with cancel-all ((M - number of markets, N number of orders in a market) - SpotMarketIdsToCancelAll []string // M x N x 65_000 - DerivativeMarketIdsToCancelAll []string // M x N x 70_000 - BinaryOptionsMarketIdsToCancelAll []string // M x N x 70_000 - - SpotOrdersToCancel []*OrderData // N x 65_000 + N x 3000 - DerivativeOrdersToCancel []*OrderData // N x 70_000 + N x 3000 - BinaryOptionsOrdersToCancel []*OrderData // N x 70_000 + N x 3000 - SpotOrdersToCreate []*SpotOrder // N x 100_000 (120_000 if post-only) + N x 3000 - DerivativeOrdersToCreate []*DerivativeOrder // N x 120_000 (140_000 if post-only) + N x 3000 - BinaryOptionsOrdersToCreate []*DerivativeOrder // N x 120_000 (140_000 if post-only) + N x 3000 -} -``` - -For example, let's suppose you want to: - -- cancel 3 spot orders in market A -- create 2 derivative orders in market B -- create 1 binary-options post-only order in market C -- cancel all orders in spot markets X and Y (2 orders in X and 2 orders in Y) - -The resulting gas would be computed as such: -``` - total_gas = 3 x 100_000 + 3 x 3000 // cancel 3x spot - + 2 x 120_000 + 2 x 3000 // create 2x derv - + 140_000 // create 1x post-only bo - + 4 x 65_000 // cancel-all 4x spot orders -``` - -which ends up being `955_000` gas. diff --git a/.gitbook/developers/modules/injective/peggy/images/SendToCosmos.png b/.gitbook/developers/modules/injective/peggy/images/SendToCosmos.png deleted file mode 100644 index c66908f6..00000000 Binary files a/.gitbook/developers/modules/injective/peggy/images/SendToCosmos.png and /dev/null differ diff --git a/.gitbook/developers/modules/injective/peggy/images/SendToEth.png b/.gitbook/developers/modules/injective/peggy/images/SendToEth.png deleted file mode 100644 index 914787ed..00000000 Binary files a/.gitbook/developers/modules/injective/peggy/images/SendToEth.png and /dev/null differ diff --git a/.gitbook/developers/modules/injective/peggy/images/valsetupdate.png b/.gitbook/developers/modules/injective/peggy/images/valsetupdate.png deleted file mode 100644 index 5592111f..00000000 Binary files a/.gitbook/developers/modules/injective/peggy/images/valsetupdate.png and /dev/null differ diff --git a/.gitbook/developers/modules/injective/permissions/04_launch_permissioned_asset.md b/.gitbook/developers/modules/injective/permissions/04_launch_permissioned_asset.md deleted file mode 100644 index a9c7d135..00000000 --- a/.gitbook/developers/modules/injective/permissions/04_launch_permissioned_asset.md +++ /dev/null @@ -1,205 +0,0 @@ ---- -sidebar_position: 4 -title: How to Launch Permissioned Assets -updatedAt: "2025-10-30" ---- - -# How to Launch Permissioned Assets - -Permissioned assets can be launched using [Injective APIs/SDKs](https://api.injective.exchange/#permissions) or the Injective CLI, `injectived`. See [injectived](https://docs.injective.network/developers/injectived) for more information on using the Injective CLI. - -```bash -injectived tx permissions [command] -``` - -- There are four transaction commands available through the CLI: - - `create-namespace` - - Used to create a permissioned namespace from a json file for a `TokenFactory` denom - - When creating a namespace, the address must be the admin of the same `TokenFactory` denom. Otherwise the namespace cannot be launched - - `update-namespace` - - Used to update the namespace parameters including: - - Contract hook - - Role permissions - - Role managers - - Policy statuses - - Policy managers - - Namespace updates are incremental, so unless a change is explicitly stated in the JSON, existing state will be untouched - - `update-namespace-roles` - - Used to assign roles to addresses and revoke roles from addresses - - Like with namespace updates, role updates are also incremental - - `claim-voucher` - - Mainly used when a user is not authorized to receive a permissioned asset but is sent funds from an Injective module. The funds will be held in an Injective module address until the user receives the correct permissions to receive the asset - -## `create-namespace` - -```bash -injectived tx permissions create-namespace [flags] -``` - -- The json file should have the following format (remove all comments before submitting): - -```json -{ // Remove all comments before submitting! - "denom": "factory/inj1address/myTokenDenom", - "contract_hook": "ContractHookAddress", - "role_permissions": [ // CAUTION: makes sure to set role permissions for all namespace management roles! - { - "name": "EVERYONE", - "role_id": 0, - "permissions": 10 // SEND (8) + RECEIVE (2); excludes MINT, SUPER_BURN, and management actions - }, - { - "name": "admin", - "role_id": 1, - "permissions": 2013265920 // MODIFY_ROLE_PERMISSIONS, MODIFY_ROLE_MANAGERS, etc. (all namespace management actions) - }, - { - "name": "user", - "role_id": 2, - "permissions": 15 // MINT (1), RECEIVE (2), BURN (4), SEND (8) - } - ], - "actor_roles": [ - { - "actor": "inj1specificactoraddress", - "roles": ["admin"] - }, - { - "actor": "inj1anotheractoraddress", - "roles": ["user"] - } - ], - "role_managers": [ // CAUTION: Make sure to set role managers for all namespace management roles! - { - "manager": "inj1manageraddress", - "roles": ["admin"] - } - ], - "policy_statuses": [ - { - "action": 1, // Action_MINT - "is_disabled": false, - "is_sealed": false - }, - { - "action": 4, // Action_BURN - "is_disabled": false, - "is_sealed": false - } - ], - "policy_manager_capabilities": [ - { - "manager": "inj1policymanageraddress", - "action": 268435456, // MODIFY_CONTRACT_HOOK - "can_disable": true, - "can_seal": false - } - ] -} - -``` - -## `update-namespace` - -```json -injectived tx permissions update-namespace [flags] -``` - -- Namespace updates are incremental, so unless a change is explicitly stated in the JSON, existing state will be untouched - -```json -{ // Remove all comments before submitting! - "denom": "factory/inj1address/myTokenDenom", - "contract_hook": { - "new_value": "newContractHookAddress" - }, - "role_permissions": [ - { - "name": "user", - "role_id": 2, - "permissions": 10 // RECEIVE (2) + SEND (8) - }, - { - "name": "EVERYONE", - "role_id": 0, - "permissions": 0 // Revoke all permissions - } - ], - "role_managers": [ - { - "manager": "inj1manageraddress", - "roles": ["admin", "user"] - } - ], - "policy_statuses": [ - { - "action": 1, // MINT - "is_disabled": true, - "is_sealed": false - }, - { - "action": 4, // BURN - "is_disabled": false, - "is_sealed": true - } - ], - "policy_manager_capabilities": [ - { - "manager": "inj1policymanageraddress", - "action": 536870912, // MODIFY_ROLE_PERMISSIONS - "can_disable": true, - "can_seal": false - } - ] -} - -``` - -## `update-namespace-roles` - -```json - injectived tx permissions update-namespace-roles [flags] -``` - -```json -{ - "denom": "factory/inj1address/myTokenDenom", - "role_actors_to_add": [ - { - "role": "admin", - "actors": [ - "inj1actoraddress1", - "inj1actoraddress2" - ] - }, - { - "role": "user", - "actors": [ - "inj1actoraddress3" - ] - } - ], - "role_actors_to_revoke": [ - { - "role": "user", - "actors": [ - "inj1actoraddress4" - ] - }, - { - "role": "admin", - "actors": [ - "inj1actoraddress5" - ] - } - ] -} -``` - -## `claim-voucher` - -```bash -injectived tx permissions claim-voucher -``` - -- No JSON is needed for this command since the only parameter needed is the denom diff --git a/.gitbook/developers/modules/injective/permissions/NamespaceRoleCreationPermissionsFlow.png b/.gitbook/developers/modules/injective/permissions/NamespaceRoleCreationPermissionsFlow.png deleted file mode 100644 index 8e80aef0..00000000 Binary files a/.gitbook/developers/modules/injective/permissions/NamespaceRoleCreationPermissionsFlow.png and /dev/null differ diff --git a/.gitbook/developers/modules/injective/permissions/PolicyManagers.png b/.gitbook/developers/modules/injective/permissions/PolicyManagers.png deleted file mode 100644 index ed0d4a26..00000000 Binary files a/.gitbook/developers/modules/injective/permissions/PolicyManagers.png and /dev/null differ