crosschain

package
v5.0.0 Latest Latest
Warning

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

Go to latest
Published: Aug 18, 2023 License: Apache-2.0 Imports: 26 Imported by: 0

Documentation

Index

Constants

View Source
const (
	FIP20CrossChainGas      = 40_000 // 80000 - 160000
	CrossChainGas           = 40_000 // 70000 - 155000
	CancelSendToExternalGas = 30_000 // 70000 - 126000
	IncreaseBridgeFeeGas    = 40_000 // 70000 - 140000
	BridgeCoinAmountFeeGas  = 10_000 // 9000

	FIP20CrossChainMethodName      = "fip20CrossChain"
	CrossChainMethodName           = "crossChain"
	CancelSendToExternalMethodName = "cancelSendToExternal"
	IncreaseBridgeFeeMethodName    = "increaseBridgeFee"
	BridgeCoinAmountMethodName     = "bridgeCoinAmount"

	CrossChainEventName           = "CrossChain"
	CancelSendToExternalEventName = "CancelSendToExternal"
	IncreaseBridgeFeeEventName    = "IncreaseBridgeFee"
)
View Source
const (
	// EventTypeRelayTransferCrossChain
	// Deprecated
	EventTypeRelayTransferCrossChain = "relay_transfer_cross_chain"
	// EventTypeCrossChain new cross chain event type
	EventTypeCrossChain = "cross_chain"

	AttributeKeyDenom        = "coin"
	AttributeKeyTokenAddress = "token_address"
	AttributeKeyFrom         = "from"
	AttributeKeyRecipient    = "recipient"
	AttributeKeyTarget       = "target"
	AttributeKeyMemo         = "memo"
)

Variables

View Source
var (
	CancelSendToExternalEvent = abi.NewEvent(
		CancelSendToExternalEventName,
		CancelSendToExternalEventName,
		false,
		abi.Arguments{
			abi.Argument{Name: "sender", Type: types.TypeAddress, Indexed: true},
			abi.Argument{Name: "chain", Type: types.TypeString, Indexed: false},
			abi.Argument{Name: "txID", Type: types.TypeUint256, Indexed: false},
		})

	CrossChainEvent = abi.NewEvent(
		CrossChainEventName,
		CrossChainEventName,
		false,
		abi.Arguments{
			abi.Argument{Name: "sender", Type: types.TypeAddress, Indexed: true},
			abi.Argument{Name: "token", Type: types.TypeAddress, Indexed: true},
			abi.Argument{Name: "denom", Type: types.TypeString, Indexed: false},
			abi.Argument{Name: "receipt", Type: types.TypeString, Indexed: false},
			abi.Argument{Name: "amount", Type: types.TypeUint256, Indexed: false},
			abi.Argument{Name: "fee", Type: types.TypeUint256, Indexed: false},
			abi.Argument{Name: "target", Type: types.TypeBytes32, Indexed: false},
			abi.Argument{Name: "memo", Type: types.TypeString, Indexed: false},
		})

	IncreaseBridgeFeeEvent = abi.NewEvent(
		IncreaseBridgeFeeEventName,
		IncreaseBridgeFeeEventName,
		false,
		abi.Arguments{
			abi.Argument{Name: "sender", Type: types.TypeAddress, Indexed: true},
			abi.Argument{Name: "token", Type: types.TypeAddress, Indexed: true},
			abi.Argument{Name: "chain", Type: types.TypeString, Indexed: false},
			abi.Argument{Name: "txID", Type: types.TypeUint256, Indexed: false},
			abi.Argument{Name: "fee", Type: types.TypeUint256, Indexed: false},
		})
)
View Source
var (
	// CancelSendToExternalMethod cancel send to external tx
	CancelSendToExternalMethod = abi.NewMethod(
		CancelSendToExternalMethodName,
		CancelSendToExternalMethodName,
		abi.Function, "nonpayable", false, false,
		abi.Arguments{
			abi.Argument{Name: "_chain", Type: types.TypeString},
			abi.Argument{Name: "_txID", Type: types.TypeUint256},
		},
		abi.Arguments{
			abi.Argument{Name: "_result", Type: types.TypeBool},
		},
	)

	// FIP20CrossChainMethod cross chain with FIP20 token, only for FIP20 token
	// Deprecated: use CrossChainMethod instead
	FIP20CrossChainMethod = abi.NewMethod(
		FIP20CrossChainMethodName,
		FIP20CrossChainMethodName,
		abi.Function, "nonpayable", false, false,
		abi.Arguments{
			abi.Argument{Name: "_sender", Type: types.TypeAddress},
			abi.Argument{Name: "_receipt", Type: types.TypeString},
			abi.Argument{Name: "_amount", Type: types.TypeUint256},
			abi.Argument{Name: "_fee", Type: types.TypeUint256},
			abi.Argument{Name: "_target", Type: types.TypeBytes32},
			abi.Argument{Name: "_memo", Type: types.TypeString},
		},
		abi.Arguments{
			abi.Argument{Name: "_result", Type: types.TypeBool},
		},
	)
	// CrossChainMethod cross chain with FIP20 token
	CrossChainMethod = abi.NewMethod(
		CrossChainMethodName,
		CrossChainMethodName,
		abi.Function, "payable", false, false,
		abi.Arguments{
			abi.Argument{Name: "_token", Type: types.TypeAddress},
			abi.Argument{Name: "_receipt", Type: types.TypeString},
			abi.Argument{Name: "_amount", Type: types.TypeUint256},
			abi.Argument{Name: "_fee", Type: types.TypeUint256},
			abi.Argument{Name: "_target", Type: types.TypeBytes32},
			abi.Argument{Name: "_memo", Type: types.TypeString},
		},
		abi.Arguments{
			abi.Argument{Name: "_result", Type: types.TypeBool},
		},
	)

	// IncreaseBridgeFeeMethod increase bridge fee
	IncreaseBridgeFeeMethod = abi.NewMethod(
		IncreaseBridgeFeeMethodName,
		IncreaseBridgeFeeMethodName,
		abi.Function, "payable", false, false,
		abi.Arguments{
			abi.Argument{Name: "_chain", Type: types.TypeString},
			abi.Argument{Name: "_txID", Type: types.TypeUint256},
			abi.Argument{Name: "_token", Type: types.TypeAddress},
			abi.Argument{Name: "_fee", Type: types.TypeUint256},
		},
		abi.Arguments{
			abi.Argument{Name: "_result", Type: types.TypeBool},
		},
	)
)
View Source
var BridgeCoinAmountMethod = abi.NewMethod(
	BridgeCoinAmountMethodName,
	BridgeCoinAmountMethodName,
	abi.Function, "view", false, false,
	abi.Arguments{
		abi.Argument{Name: "_token", Type: types.TypeAddress},
		abi.Argument{Name: "_target", Type: types.TypeBytes32},
	},
	abi.Arguments{
		abi.Argument{Name: "_amount", Type: types.TypeUint256},
	},
)

BridgeCoinAmountMethod query the amount of bridge coin

Functions

func GetABI

func GetABI() abi.ABI

func GetAddress

func GetAddress() common.Address

Types

type AccountKeeper

type AccountKeeper interface {
	GetModuleAddress(moduleName string) sdk.AccAddress
}

type BankKeeper

type BankKeeper interface {
	GetSupply(ctx sdk.Context, denom string) sdk.Coin
	GetBalance(ctx sdk.Context, addr sdk.AccAddress, denom string) sdk.Coin
	GetAllBalances(ctx sdk.Context, addr sdk.AccAddress) sdk.Coins
	MintCoins(ctx sdk.Context, moduleName string, amounts sdk.Coins) error
	BurnCoins(ctx sdk.Context, moduleName string, amounts sdk.Coins) error
	SendCoinsFromAccountToModule(ctx sdk.Context, senderAddr sdk.AccAddress, recipientModule string, amt sdk.Coins) error
	SendCoinsFromModuleToAccount(ctx sdk.Context, senderModule string, recipientAddr sdk.AccAddress, amt sdk.Coins) error
	SendCoins(ctx sdk.Context, fromAddr sdk.AccAddress, toAddr sdk.AccAddress, amt sdk.Coins) error
	GetDenomMetaData(ctx sdk.Context, denom string) (bank.Metadata, bool)
}

type BridgeCoinAmountArgs

type BridgeCoinAmountArgs struct {
	Token  common.Address `abi:"_token"`
	Target [32]byte       `abi:"_target"`
}

func (*BridgeCoinAmountArgs) Validate

func (args *BridgeCoinAmountArgs) Validate() error

Validate validates the args

type CallerRef

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

func (CallerRef) Address

func (cr CallerRef) Address() common.Address

type CancelSendToExternalArgs

type CancelSendToExternalArgs struct {
	Chain string   `abi:"_chain"`
	TxID  *big.Int `abi:"_txID"`
}

func (*CancelSendToExternalArgs) Validate

func (args *CancelSendToExternalArgs) Validate() error

Validate validates the args

type Contract

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

func NewPrecompiledContract

func NewPrecompiledContract(
	ctx sdk.Context,
	bankKeeper BankKeeper,
	evmKeeper EvmKeeper,
	erc20Keeper Erc20Keeper,
	ibcTransferKeeper IBCTransferKeeper,
	accountKeeper AccountKeeper,
	router *fxtypes.Router,
) *Contract

func (*Contract) AddLog

func (c *Contract) AddLog(evm *vm.EVM, event abi.Event, topics []common.Hash, args ...interface{}) error

func (*Contract) Address

func (c *Contract) Address() common.Address

func (*Contract) BridgeCoinAmount

func (c *Contract) BridgeCoinAmount(ctx sdk.Context, evm *vm.EVM, contract *vm.Contract, _ bool) ([]byte, error)

func (*Contract) CancelSendToExternal

func (c *Contract) CancelSendToExternal(ctx sdk.Context, evm *vm.EVM, contract *vm.Contract, readonly bool) ([]byte, error)

func (*Contract) CrossChain

func (c *Contract) CrossChain(ctx sdk.Context, evm *vm.EVM, contract *vm.Contract, readonly bool) ([]byte, error)

CrossChain called at any address(account or contract)

func (*Contract) FIP20CrossChain

func (c *Contract) FIP20CrossChain(ctx sdk.Context, evm *vm.EVM, contract *vm.Contract, readonly bool) ([]byte, error)

FIP20CrossChain only for fip20 contract transferCrossChain called

func (*Contract) IncreaseBridgeFee

func (c *Contract) IncreaseBridgeFee(ctx sdk.Context, evm *vm.EVM, contract *vm.Contract, readonly bool) ([]byte, error)

IncreaseBridgeFee add bridge fee to unbatched tx

func (*Contract) IsStateful

func (c *Contract) IsStateful() bool

func (*Contract) RequiredGas

func (c *Contract) RequiredGas(input []byte) uint64

func (*Contract) Run

func (c *Contract) Run(evm *vm.EVM, contract *vm.Contract, readonly bool) (ret []byte, err error)

type ContractCall

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

func NewContractCall

func NewContractCall(ctx sdk.Context, evm *vm.EVM, caller, contract common.Address) *ContractCall

func (*ContractCall) ERC20Burn

func (cc *ContractCall) ERC20Burn(amount *big.Int) error

func (*ContractCall) ERC20TotalSupply

func (cc *ContractCall) ERC20TotalSupply() (*big.Int, error)

func (*ContractCall) ERC20TransferFrom

func (cc *ContractCall) ERC20TransferFrom(from, to common.Address, amount *big.Int) error

type CrossChainArgs

type CrossChainArgs struct {
	Token   common.Address `abi:"_token"`
	Receipt string         `abi:"_receipt"`
	Amount  *big.Int       `abi:"_amount"`
	Fee     *big.Int       `abi:"_fee"`
	Target  [32]byte       `abi:"_target"`
	Memo    string         `abi:"_memo"`
}

func (*CrossChainArgs) Validate

func (args *CrossChainArgs) Validate() error

Validate validates the args

type Erc20Keeper

type Erc20Keeper interface {
	ModuleAddress() common.Address
	GetTokenPairByAddress(ctx sdk.Context, address common.Address) (types.TokenPair, bool)
	ConvertDenomToTarget(ctx sdk.Context, from sdk.AccAddress, coin sdk.Coin, fxTarget fxtypes.FxTarget) (sdk.Coin, error)
	ConvertERC20NativeCoin(ctx sdk.Context, pair types.TokenPair, sender common.Address, receiver sdk.AccAddress, amount sdkmath.Int) error
	GetIbcTimeout(ctx sdk.Context) time.Duration
	SetIBCTransferRelation(ctx sdk.Context, channel string, sequence uint64)
	HasOutgoingTransferRelation(ctx sdk.Context, moduleName string, txID uint64) bool
	ToTargetDenom(ctx sdk.Context, denom, base string, aliases []string, fxTarget fxtypes.FxTarget) string
	GetTokenPair(ctx sdk.Context, tokenOrDenom string) (types.TokenPair, bool)
	IsOriginDenom(ctx sdk.Context, denom string) bool
	HasDenomAlias(ctx sdk.Context, denom string) (bank.Metadata, bool)
}

type EvmKeeper

type EvmKeeper interface {
	GetParams(ctx sdk.Context) (params evmtypes.Params)
}

type FIP20CrossChainArgs

type FIP20CrossChainArgs struct {
	Sender  common.Address `abi:"_sender"`
	Receipt string         `abi:"_receipt"`
	Amount  *big.Int       `abi:"_amount"`
	Fee     *big.Int       `abi:"_fee"`
	Target  [32]byte       `abi:"_target"`
	Memo    string         `abi:"_memo"`
}

func (*FIP20CrossChainArgs) Validate

func (args *FIP20CrossChainArgs) Validate() error

Validate validates the args

type IBCTransferKeeper

type IBCTransferKeeper interface {
	Transfer(goCtx context.Context, msg *ibctransfertypes.MsgTransfer) (*ibctransfertypes.MsgTransferResponse, error)
	GetDenomTrace(ctx sdk.Context, denomTraceHash tmbytes.HexBytes) (ibctransfertypes.DenomTrace, bool)
}

type IncreaseBridgeFeeArgs

type IncreaseBridgeFeeArgs struct {
	Chain string         `abi:"_chain"`
	TxID  *big.Int       `abi:"_txID"`
	Token common.Address `abi:"_token"`
	Fee   *big.Int       `abi:"_fee"`
}

func (*IncreaseBridgeFeeArgs) Validate

func (args *IncreaseBridgeFeeArgs) Validate() error

Validate validates the args

Jump to

Keyboard shortcuts

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