system

package
v1.0.3 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Sep 26, 2024 License: GPL-3.0 Imports: 28 Imported by: 0

Documentation

Index

Constants

View Source
const (
	EnumRebalanceStatus_Initialized uint8 = iota
	EnumRebalanceStatus_Registered
	EnumRebalanceStatus_Approved
	EnumRebalanceStatus_Finalized
)

Solidity enums are not generated by abigen. Add them manually.

Variables

View Source
var (

	// Canonical system contract names registered in Registry.
	AddressBookName = "AddressBook"
	GovParamName    = "GovParam"
	Kip103Name      = "KIP103"
	Kip113Name      = "KIP113"
	Kip160Name      = "KIP160"

	AllContractNames = []string{
		AddressBookName,
		GovParamName,
		Kip103Name,
		Kip113Name,
		Kip160Name,
	}

	// This is the keccak-256 hash of "eip1967.proxy.implementation" subtracted by 1 used in the
	// EIP-1967 proxy contract. See https://eips.ethereum.org/EIPS/eip-1967#implementation-slot
	ImplementationSlot = common.Hex2Bytes("360894a13ba1a3210667c828492db98dca3e2076cc3735a920a3ca505d382bbc")

	// Some system contracts are allocated at special addresses.
	MainnetCreditAddr = common.HexToAddress("0x0000000000000000000000000000000000000000")
	AddressBookAddr   = common.HexToAddress("0x0000000000000000000000000000000000000400")
	RegistryAddr      = common.HexToAddress("0x0000000000000000000000000000000000000401")
	MultiCallAddr     = common.HexToAddress("0x0000000000000000000000000000000000000402")
	// The following addresses are only used for testing.
	Kip113ProxyAddrMock = common.HexToAddress("0x0000000000000000000000000000000000000402")
	Kip113LogicAddrMock = common.HexToAddress("0x0000000000000000000000000000000000000403")

	// System contract binaries to be injected at hardfork or used in testing.
	MainnetCreditCode   = hexutil.MustDecode("0x" + misccontract.CypressCreditBinRuntime)
	MainnetCreditV2Code = hexutil.MustDecode("0x" + misccontract.CypressCreditV2BinRuntime)
	RegistryCode        = hexutil.MustDecode("0x" + kip149contract.RegistryBinRuntime)
	RegistryMockCode    = hexutil.MustDecode("0x" + testcontract.RegistryMockBinRuntime)
	Kip160MockCode      = hexutil.MustDecode("0x" + testcontract.TreasuryRebalanceMockV2BinRuntime)
	Kip103MockCode      = hexutil.MustDecode("0x" + testcontract.TreasuryRebalanceMockBinRuntime)
	Kip113Code          = hexutil.MustDecode("0x" + kip113contract.SimpleBlsRegistryBinRuntime)
	Kip113MockCode      = hexutil.MustDecode("0x" + testcontract.KIP113MockBinRuntime)

	ERC1967ProxyCode = hexutil.MustDecode("0x" + proxycontract.ERC1967ProxyBinRuntime)

	AddressBookMockTwoCNCode = hexutil.MustDecode("0x" + reward.AddressBookMockTwoCNBinRuntime)

	MultiCallCode     = hexutil.MustDecode("0x" + multicall.MultiCallContractBinRuntime)
	MultiCallMockCode = hexutil.MustDecode("0x" + testcontract.MultiCallContractMockBinRuntime)

	// Errors
	ErrRegistryNotInstalled      = errors.New("Registry contract not installed")
	ErrRebalanceIncorrectBlock   = errors.New("cannot find a proper target block number")
	ErrRebalanceNotEnoughBalance = errors.New("the sum of zeroed balances are less than the sum of allocated balances")
	ErrRebalanceBadStatus        = errors.New("rebalance contract is not in proper status")
	ErrKip113BadResult           = errors.New("KIP113 call returned bad data")
	ErrKip113BadPop              = errors.New("KIP113 PoP verification failed")
)

Functions

func AllocKip113Logic

func AllocKip113Logic() map[common.Hash]common.Hash

func AllocKip113Proxy

func AllocKip113Proxy(init AllocKip113Init) map[common.Hash]common.Hash

func AllocProxy

func AllocProxy(impl common.Address) map[common.Hash]common.Hash

func AllocRegistry

func AllocRegistry(init *params.RegistryConfig) map[common.Hash]common.Hash

Create storage state from the given initial values. The storage slots are calculated according to the solidity layout rule. https://docs.soliditylang.org/en/v0.8.20/internals/layout_in_storage.html

func GetRegistryCaller

func GetRegistryCaller(backend bind.ContractCaller, num *big.Int) (*contracts.RegistryCaller, error)

func InstallRegistry

func InstallRegistry(state *state.StateDB, init *params.RegistryConfig) error

func MergeGenesisAlloc

func MergeGenesisAlloc(aa ...blockchain.GenesisAlloc) blockchain.GenesisAlloc

func MergeStorage

func MergeStorage(ss ...map[common.Hash]common.Hash) map[common.Hash]common.Hash

MergeStorage merges multiple storage maps into one.

func NewMultiCallContractCaller

func NewMultiCallContractCaller(state *state.StateDB, chain backends.BlockChainForCaller, header *types.Header) (*multicall.MultiCallContractCaller, error)

NewMultiCallContractCaller creates a new instance of ContractCaller for MultiCall contract.

func ReadActiveAddressFromRegistry

func ReadActiveAddressFromRegistry(backend bind.ContractCaller, name string, num *big.Int) (common.Address, error)

func ReadAllRecordsFromRegistry

func ReadAllRecordsFromRegistry(backend bind.ContractCaller, name string, num *big.Int) ([]contracts.IRegistryRecord, error)

func RebalanceTreasury

func RebalanceTreasury(state *state.StateDB, chain backends.BlockChainForCaller, header *types.Header) (*rebalanceResult, error)

RebalanceTreasury reads data from a contract, validates stored values, and executes treasury rebalancing (KIP-103, KIP-160). It can change the global state by removing old treasury balances and allocating new treasury balances. The new allocation can be larger than the removed amount, and the difference between two amounts will be burnt.

Types

type AllocKip113Init

type AllocKip113Init struct {
	Infos BlsPublicKeyInfos
	Owner common.Address
}

type BlsPublicKeyInfo

type BlsPublicKeyInfo struct {
	PublicKey []byte
	Pop       []byte
	VerifyErr error // Nil if valid. Must check before use.
}

type BlsPublicKeyInfos

type BlsPublicKeyInfos map[common.Address]BlsPublicKeyInfo

func ReadKip113All

func ReadKip113All(backend bind.ContractCaller, contractAddr common.Address, num *big.Int) (BlsPublicKeyInfos, error)

func (BlsPublicKeyInfos) String

func (infos BlsPublicKeyInfos) String() string

type ContractCallerForMultiCall

type ContractCallerForMultiCall struct {
	// contains filtered or unexported fields
}

ContractCallerForMultiCall is an implementation of ContractCaller only for MultiCall contract. The caller interacts with a multicall contract on a read only basis.

func (*ContractCallerForMultiCall) CallContract

func (caller *ContractCallerForMultiCall) CallContract(ctx context.Context, call kaia.CallMsg, blockNumber *big.Int) ([]byte, error)

CallContract injects a multicall contract code into the state and executes the call.

func (*ContractCallerForMultiCall) CodeAt

func (caller *ContractCallerForMultiCall) CodeAt(ctx context.Context, contract common.Address, blockNumber *big.Int) ([]byte, error)

type Kip103ContractCaller

type Kip103ContractCaller struct {
	*rebalance.TreasuryRebalanceCaller // Assuming TreasuryRebalance is the contract ABI wrapper
	// contains filtered or unexported fields
}

Kip103ContractCaller implements RebalanceCaller interface for Treasury rebalance contract.

func NewKip103ContractCaller

func NewKip103ContractCaller(state *state.StateDB, chain backends.BlockChainForCaller, header *types.Header,
) (*Kip103ContractCaller, error)

NewKip103ContractCaller creates a new instance of TreasuryRebalanceCaller.

func (*Kip103ContractCaller) Allocateds

func (caller *Kip103ContractCaller) Allocateds(opts *bind.CallOpts, arg0 *big.Int) (
	struct {
		Addr   common.Address
		Amount *big.Int
	}, error,
)

func (*Kip103ContractCaller) CallContract

func (caller *Kip103ContractCaller) CallContract(ctx context.Context, call kaia.CallMsg, blockNumber *big.Int) ([]byte, error)

func (*Kip103ContractCaller) CheckZeroedsApproved

func (caller *Kip103ContractCaller) CheckZeroedsApproved(opts *bind.CallOpts) error

func (*Kip103ContractCaller) CodeAt

func (caller *Kip103ContractCaller) CodeAt(ctx context.Context, contract common.Address, blockNumber *big.Int) ([]byte, error)

func (*Kip103ContractCaller) GetAllocatedCount

func (caller *Kip103ContractCaller) GetAllocatedCount(opts *bind.CallOpts) (*big.Int, error)

func (*Kip103ContractCaller) GetZeroedCount

func (caller *Kip103ContractCaller) GetZeroedCount(opts *bind.CallOpts) (*big.Int, error)

func (*Kip103ContractCaller) Zeroeds

func (caller *Kip103ContractCaller) Zeroeds(opts *bind.CallOpts, arg0 *big.Int) (common.Address, error)

type RebalanceCaller

type RebalanceCaller interface {
	RebalanceBlockNumber(opts *bind.CallOpts) (*big.Int, error)
	Status(opts *bind.CallOpts) (uint8, error)

	GetZeroedCount(opts *bind.CallOpts) (*big.Int, error)
	Zeroeds(opts *bind.CallOpts, index *big.Int) (common.Address, error)
	GetAllocatedCount(opts *bind.CallOpts) (*big.Int, error)
	Allocateds(opts *bind.CallOpts, arg0 *big.Int) (struct {
		Addr   common.Address
		Amount *big.Int
	}, error)

	CheckZeroedsApproved(opts *bind.CallOpts) error
}

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL