ics20

package
v1.8.0 Latest Latest
Warning

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

Go to latest
Published: Sep 3, 2024 License: Apache-2.0 Imports: 27 Imported by: 0

Documentation

Index

Constants

View Source
const (
	// ErrInvalidSourcePort is raised when the source port is invalid.
	ErrInvalidSourcePort = "invalid source port"
	// ErrInvalidSourceChannel is raised when the source channel is invalid.
	ErrInvalidSourceChannel = "invalid source port"
	// ErrInvalidSender is raised when the sender is invalid.
	ErrInvalidSender = "invalid sender: %s"
	// ErrInvalidReceiver is raised when the receiver is invalid.
	ErrInvalidReceiver = "invalid receiver: %s"
	// ErrInvalidTimeoutTimestamp is raised when the timeout timestamp is invalid.
	ErrInvalidTimeoutTimestamp = "invalid timeout timestamp: %d"
	// ErrInvalidMemo is raised when the memo is invalid.
	ErrInvalidMemo = "invalid memo: %s"
	// ErrInvalidHash is raised when the hash is invalid.
	ErrInvalidHash = "invalid hash: %s"
	// ErrNoMatchingAllocation is raised when no matching allocation is found.
	ErrNoMatchingAllocation = "no matching allocation found for source port: %s, source channel: %s, and denom: %s"
	// ErrDifferentOriginFromSender is raised when the origin address is not the same as the sender address.
	ErrDifferentOriginFromSender = "origin address %s is not the same as sender address %s"
	// ErrTraceNotFound is raised when the denom trace for the specified request does not exist.
	ErrTraceNotFound = "denomination trace not found"
)
View Source
const (
	// DenomTraceMethod defines the ABI method name for the ICS20 DenomTrace
	// query.
	DenomTraceMethod = "denomTrace"
	// DenomTracesMethod defines the ABI method name for the ICS20 DenomTraces
	// query.
	DenomTracesMethod = "denomTraces"
	// DenomHashMethod defines the ABI method name for the ICS20 DenomHash
	// query.
	DenomHashMethod = "denomHash"
)
View Source
const (
	// DefaultTimeoutHeight is the default value used in the IBC timeout height for
	// the client.
	DefaultTimeoutHeight = 100

	// DefaultTimeoutTimestamp is the default value used in the IBC timeout
	// timestamp for the client.
	DefaultTimeoutTimestamp = 0
)
View Source
const (
	// EventTypeIBCTransfer defines the event type for the ICS20 Transfer transaction.
	EventTypeIBCTransfer = "IBCTransfer"
)
View Source
const (
	// TransferMethod defines the ABI method name for the ICS20 Transfer
	// transaction.
	TransferMethod = "transfer"
)

Variables

TransferMsgURL is the ICS20 transfer message URL string.

Functions

func AcceptGrant

func AcceptGrant(
	ctx sdk.Context,
	contractCaller, granter common.Address,
	msg *transfertypes.MsgTransfer,
	authzAuthorization authz.Authorization,
) (*authz.AcceptResponse, error)

AcceptGrant implements the ICS20 accept grant.

func Approve

func Approve(
	ctx sdk.Context,
	authzKeeper authzkeeper.Keeper,
	channelKeeper channelkeeper.Keeper,
	precompileAddr, grantee, origin common.Address,
	approvalExpiration time.Duration,
	transferAuthz *transfertypes.TransferAuthorization,
	event abi.Event,
	stateDB vm.StateDB,
) error

Approve implements the ICS20 Authorization approve transactions.

func CheckAndAcceptAuthorizationIfNeeded

func CheckAndAcceptAuthorizationIfNeeded(
	ctx sdk.Context,
	contract *vm.Contract,
	origin common.Address,
	authzKeeper authzkeeper.Keeper,
	msg *transfertypes.MsgTransfer,
) (*authz.AcceptResponse, *time.Time, error)

CheckAndAcceptAuthorizationIfNeeded checks if authorization exists and accepts the grant. In case the origin is the caller of the address, no authorization is required.

func CheckOriginAndSender

func CheckOriginAndSender(contract *vm.Contract, origin common.Address, sender common.Address) (common.Address, error)

CheckOriginAndSender ensures the correct sender is being used.

func CreateAndValidateMsgTransfer

func CreateAndValidateMsgTransfer(
	sourcePort, sourceChannel string,
	coin sdk.Coin, senderAddress, receiverAddress string,
	timeoutHeight clienttypes.Height,
	timeoutTimestamp uint64,
	memo string,
) (*transfertypes.MsgTransfer, error)

CreateAndValidateMsgTransfer creates a new MsgTransfer message and run validate basic.

func DecreaseAllowance

func DecreaseAllowance(
	ctx sdk.Context,
	authzKeeper authzkeeper.Keeper,
	precompileAddr, grantee, granter common.Address,
	sourcePort, sourceChannel, denom string,
	amount *big.Int,
	event abi.Event,
	stateDB vm.StateDB,
) error

DecreaseAllowance implements the ICS20 Authorization decrease allowance transactions.

func EmitIBCTransferEvent

func EmitIBCTransferEvent(
	ctx sdk.Context,
	stateDB vm.StateDB,
	event abi.Event,
	precompileAddr, senderAddr common.Address,
	receiver string,
	sourcePort, sourceChannel string,
	token sdk.Coin,
	memo string,
) error

EmitIBCTransferEvent creates a new IBC transfer event emitted on a Transfer transaction.

func IncreaseAllowance

func IncreaseAllowance(
	ctx sdk.Context,
	authzKeeper authzkeeper.Keeper,
	precompileAddr, grantee, granter common.Address,
	sourcePort, sourceChannel, denom string,
	amount *big.Int,
	event abi.Event,
	stateDB vm.StateDB,
) error

IncreaseAllowance implements the ICS20 Authorization increase allowance transactions.

func NewDenomHashRequest

func NewDenomHashRequest(args []interface{}) (*transfertypes.QueryDenomHashRequest, error)

NewDenomHashRequest returns a new denom hash request from the given arguments.

func NewDenomTraceRequest

func NewDenomTraceRequest(args []interface{}) (*transfertypes.QueryDenomTraceRequest, error)

NewDenomTraceRequest returns a new denom trace request from the given arguments.

func NewDenomTracesRequest

func NewDenomTracesRequest(method *abi.Method, args []interface{}) (*transfertypes.QueryDenomTracesRequest, error)

NewDenomTracesRequest returns a new denom traces request from the given arguments.

func NewMsgTransfer

func NewMsgTransfer(method *abi.Method, args []interface{}) (*transfertypes.MsgTransfer, common.Address, error)

NewMsgTransfer returns a new transfer message from the given arguments.

func NewTransferAuthorization

func NewTransferAuthorization(method *abi.Method, args []interface{}) (common.Address, *transfertypes.TransferAuthorization, error)

NewTransferAuthorization returns a new transfer authorization authz type from the given arguments.

func Revoke

func Revoke(
	ctx sdk.Context,
	authzKeeper authzkeeper.Keeper,
	precompileAddr, grantee, origin common.Address,
	event abi.Event,
	stateDB vm.StateDB,
) error

Revoke implements the ICS20 Authorization revoke transactions.

func UpdateGrant

func UpdateGrant(
	ctx sdk.Context,
	authzKeeper authzkeeper.Keeper,
	grantee, granter common.Address,
	expiration *time.Time,
	resp *authz.AcceptResponse,
) (err error)

UpdateGrant implements the ICS20 authz update grant.

func UpdateGrantIfNeeded

func UpdateGrantIfNeeded(ctx sdk.Context, contract *vm.Contract, authzKeeper authzkeeper.Keeper, origin common.Address, expiration *time.Time, resp *authz.AcceptResponse) error

UpdateGrantIfNeeded updates the grant in case the contract caller is not the origin of the message.

Types

type DenomTraceResponse

type DenomTraceResponse struct {
	DenomTrace transfertypes.DenomTrace
}

DenomTraceResponse defines the data for the denom trace response.

type DenomTracesResponse

type DenomTracesResponse struct {
	DenomTraces  []transfertypes.DenomTrace
	PageResponse query.PageResponse
}

DenomTracesResponse defines the data for the denom traces response.

type EventIBCTransfer

type EventIBCTransfer struct {
	Sender        common.Address
	Receiver      common.Hash
	SourcePort    string
	SourceChannel string
	Denom         string
	Amount        *big.Int
	Memo          string
}

EventIBCTransfer is the event type emitted when a transfer is executed.

type EventTransferAuthorization

type EventTransferAuthorization struct {
	Grantee     common.Address
	Granter     common.Address
	Allocations []cmn.ICS20Allocation
}

EventTransferAuthorization is the event type emitted when a transfer authorization is created.

type PageRequest

type PageRequest struct {
	PageRequest query.PageRequest
}

PageRequest defines the data for the page request.

type Precompile

type Precompile struct {
	cmn.Precompile
	// contains filtered or unexported fields
}

func NewPrecompile

func NewPrecompile(
	stakingKeeper stakingkeeper.Keeper,
	transferKeeper transferkeeper.Keeper,
	channelKeeper channelkeeper.Keeper,
	authzKeeper authzkeeper.Keeper,
) (*Precompile, error)

NewPrecompile creates a new ICS-20 Precompile instance as a PrecompiledContract interface.

func (Precompile) Address

func (Precompile) Address() common.Address

Address defines the address of the ICS-20 compile contract. address: 0x0000000000000000000000000000000000000802

func (Precompile) Allowance

func (p Precompile) Allowance(
	ctx sdk.Context,
	method *abi.Method,
	args []interface{},
) ([]byte, error)

Allowance returns the remaining allowance of for a combination of grantee - granter. The grantee is the smart contract that was authorized by the granter to spend.

func (Precompile) Approve

func (p Precompile) Approve(
	ctx sdk.Context,
	origin common.Address,
	stateDB vm.StateDB,
	method *abi.Method,
	args []interface{},
) ([]byte, error)

Approve implements the ICS20 approve transactions.

func (Precompile) DecreaseAllowance

func (p Precompile) DecreaseAllowance(
	ctx sdk.Context,
	origin common.Address,
	stateDB vm.StateDB,
	method *abi.Method,
	args []interface{},
) ([]byte, error)

DecreaseAllowance implements the ICS20 decrease allowance transactions.

func (Precompile) DenomHash

func (p Precompile) DenomHash(
	ctx sdk.Context,
	_ *vm.Contract,
	method *abi.Method,
	args []interface{},
) ([]byte, error)

DenomHash returns the denom hash (in hex format) of the denomination trace information.

func (Precompile) DenomTrace

func (p Precompile) DenomTrace(
	ctx sdk.Context,
	_ *vm.Contract,
	method *abi.Method,
	args []interface{},
) ([]byte, error)

DenomTrace returns the requested denomination trace information.

func (Precompile) DenomTraces

func (p Precompile) DenomTraces(
	ctx sdk.Context,
	_ *vm.Contract,
	method *abi.Method,
	args []interface{},
) ([]byte, error)

DenomTraces returns the requested denomination traces information.

func (Precompile) IncreaseAllowance

func (p Precompile) IncreaseAllowance(
	ctx sdk.Context,
	origin common.Address,
	stateDB vm.StateDB,
	method *abi.Method,
	args []interface{},
) ([]byte, error)

IncreaseAllowance implements the ICS20 increase allowance transactions.

func (Precompile) IsTransaction

func (Precompile) IsTransaction(method string) bool

IsTransaction checks if the given method name corresponds to a transaction or query.

Available ics20 transactions are:

  • Transfer

Available authorization transactions are:

  • Approve
  • Revoke
  • IncreaseAllowance
  • DecreaseAllowance

func (Precompile) RequiredGas

func (p Precompile) RequiredGas(input []byte) uint64

RequiredGas calculates the precompiled contract's base gas rate.

func (Precompile) Revoke

func (p Precompile) Revoke(
	ctx sdk.Context,
	origin common.Address,
	stateDB vm.StateDB,
	method *abi.Method,
	args []interface{},
) ([]byte, error)

Revoke implements the ICS20 authorization revoke transactions.

func (Precompile) Run

func (p Precompile) Run(evm *vm.EVM, contract *vm.Contract, readOnly bool) (bz []byte, err error)

Run executes the precompiled contract IBC transfer methods defined in the ABI.

func (Precompile) Transfer

func (p Precompile) Transfer(
	ctx sdk.Context,
	origin common.Address,
	contract *vm.Contract,
	stateDB vm.StateDB,
	method *abi.Method,
	args []interface{},
) ([]byte, error)

Transfer implements the ICS20 transfer transactions.

Jump to

Keyboard shortcuts

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