ton

package
v0.0.0-...-1329066 Latest Latest
Warning

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

Go to latest
Published: Dec 9, 2024 License: MIT Imports: 15 Imported by: 0

Documentation

Overview

Package ton provider bindings for TON blockchain including Gateway contract wrapper.

Index

Constants

View Source
const (
	SendFlagSeparateFees = uint8(1)
	SendFlagIgnoreErrors = uint8(2)
)

see https://docs.ton.org/develop/smart-contracts/messages#message-modes

Variables

View Source
var (
	ErrParse     = errors.New("unable to parse tx")
	ErrUnknownOp = errors.New("unknown op")
	ErrCast      = errors.New("unable to cast tx content")
)

Functions

func Coins

func Coins(amount uint64) math.Uint

Coins takes amount in TON and returns it in nano tons. Example Coins(5) return math.Uint(5 * 10^9) nano tons.

func ErrCollect

func ErrCollect(errs ...error) error

func FilterInbounds

func FilterInbounds(tx *Transaction) bool

FilterInbounds filters transactions with deposit operations

func FormatCoins

func FormatCoins(v math.Uint) string

func GatewayCode

func GatewayCode() *boc.Cell

GatewayCode returns Gateway's code as cell

func GatewayStateInit

func GatewayStateInit(authority ton.AccountID, tss eth.Address, depositsEnabled bool) *boc.Cell

GatewayStateInit returns Gateway's stateInit as cell

func GramsToUint

func GramsToUint(g tlb.Grams) math.Uint

func MarshalSnakeCell

func MarshalSnakeCell(data []byte) (*boc.Cell, error)

MarshalSnakeCell encodes []byte to TLB using snake-cell encoding

func MarshalTLB

func MarshalTLB(v tlb.MarshalerTLB) (*boc.Cell, error)

MarshalTLB encodes entity to BOC

func UintToCoins

func UintToCoins(v math.Uint) tlb.Coins

func UnmarshalEVMAddress

func UnmarshalEVMAddress(cell *boc.Cell) (eth.Address, error)

UnmarshalEVMAddress decodes eth.Address from BOC

func UnmarshalSnakeCell

func UnmarshalSnakeCell(cell *boc.Cell) ([]byte, error)

UnmarshalSnakeCell decodes TLB cell to []byte using snake-cell encoding

func UnmarshalTLB

func UnmarshalTLB(t tlb.UnmarshalerTLB, cell *boc.Cell) error

UnmarshalTLB decodes entity from BOC

Types

type Client

type Client interface {
	SendMessage(ctx context.Context, payload []byte) (uint32, error)
}

Client represents a sender that allows sending an arbitrary external message to the network.

type Deposit

type Deposit struct {
	Sender    ton.AccountID
	Amount    math.Uint
	Recipient eth.Address
}

Deposit represents a deposit operation

func (Deposit) AsBody

func (d Deposit) AsBody() (*boc.Cell, error)

AsBody casts struct as internal message body.

func (Deposit) Memo

func (d Deposit) Memo() []byte

Memo casts deposit to memo bytes

type DepositAndCall

type DepositAndCall struct {
	Deposit
	CallData []byte
}

DepositAndCall represents a deposit and call operation

func (DepositAndCall) AsBody

func (d DepositAndCall) AsBody() (*boc.Cell, error)

AsBody casts struct to internal message body.

func (DepositAndCall) Memo

func (d DepositAndCall) Memo() []byte

Memo casts deposit to call to memo bytes

type Donation

type Donation struct {
	Sender ton.AccountID
	Amount math.Uint
}

Donation represents a donation operation

func (Donation) AsBody

func (d Donation) AsBody() (*boc.Cell, error)

AsBody casts struct as internal message body.

type ExitCode

type ExitCode uint32

ExitCode represents an error code. Might be TVM or custom. TVM: https://docs.ton.org/v3/documentation/tvm/tvm-exit-codes Zeta: https://github.com/zeta-chain/protocol-contracts-ton/blob/main/contracts/common/errors.fc

const (
	ExitCodeInvalidSeqno ExitCode = 109
)

type ExternalMsg

type ExternalMsg interface {
	AsBody() (*boc.Cell, error)
	// contains filtered or unexported methods
}

type Filter

type Filter func(*Transaction) bool

type Gateway

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

Gateway represents bindings for Zeta Gateway contract on TON

Gateway.ParseTransaction parses Gateway transaction. The parser reads tx body cell and decodes it based on Operation code (op)

  • inbound transactions: deposit, donate, depositAndCall
  • outbound transactions: not implemented yet
  • errors for all other transactions

`Send*` methods work the same way by constructing (& signing) tx body cell that is expected by the contract

@see https://github.com/zeta-chain/protocol-contracts-ton/blob/main/contracts/gateway.fc

func NewGateway

func NewGateway(accountID ton.AccountID) *Gateway

NewGateway Gateway constructor

func (*Gateway) AccountID

func (gw *Gateway) AccountID() ton.AccountID

AccountID returns gateway address

func (*Gateway) GetTxFee

func (gw *Gateway) GetTxFee(ctx context.Context, client MethodRunner, op Op) (math.Uint, error)

GetTxFee returns maximum transaction fee for the given operation. Real fee may be lower.

func (*Gateway) ParseAndFilter

func (gw *Gateway) ParseAndFilter(tx ton.Transaction, filter Filter) (*Transaction, bool, error)

ParseAndFilter parses transaction and applies filter to it. Returns (tx, skip?, error) If parse fails due to known error, skip is set to true

func (*Gateway) ParseAndFilterMany

func (gw *Gateway) ParseAndFilterMany(txs []ton.Transaction, filter Filter) []*Transaction

ParseAndFilterMany parses and filters many txs.

func (*Gateway) ParseTransaction

func (gw *Gateway) ParseTransaction(tx ton.Transaction) (*Transaction, error)

ParseTransaction parses transaction to Transaction

func (*Gateway) SendDeposit

func (gw *Gateway) SendDeposit(
	ctx context.Context,
	s Sender,
	amount math.Uint,
	zevmRecipient eth.Address,
	sendMode uint8,
) error

SendDeposit sends a deposit operation to the gateway on behalf of the sender.

func (*Gateway) SendDepositAndCall

func (gw *Gateway) SendDepositAndCall(
	ctx context.Context,
	s Sender,
	amount math.Uint,
	zevmRecipient eth.Address,
	callData []byte,
	sendMode uint8,
) error

SendDepositAndCall sends a deposit operation to the gateway on behalf of the sender with a callData to the recipient.

func (*Gateway) SendExternalMessage

func (gw *Gateway) SendExternalMessage(ctx context.Context, s Client, msg ExternalMsg) (uint32, error)

SendExternalMessage sends an external message to the Gateway.

type MethodRunner

type MethodRunner interface {
	RunSmcMethod(ctx context.Context, acc ton.AccountID, method string, params tlb.VmStack) (uint32, tlb.VmStack, error)
}

type Op

type Op uint32

Op operation code

const (
	OpDonate Op = 100 + iota
	OpDeposit
	OpDepositAndCall
)

github.com/zeta-chain/protocol-contracts-ton/blob/main/contracts/gateway.fc Inbound operations

const OpWithdraw Op = 200

type Sender

type Sender interface {
	Send(ctx context.Context, messages ...wallet.Sendable) error
}

Sender TON tx sender. Usually an interface to a wallet.

type Transaction

type Transaction struct {
	ton.Transaction
	Operation Op
	ExitCode  int32
	// contains filtered or unexported fields
}

Transaction represents a Gateway transaction.

func (*Transaction) Deposit

func (tx *Transaction) Deposit() (Deposit, error)

Deposit casts the transaction content to a Deposit.

func (*Transaction) DepositAndCall

func (tx *Transaction) DepositAndCall() (DepositAndCall, error)

DepositAndCall casts the transaction content to a DepositAndCall.

func (*Transaction) Donation

func (tx *Transaction) Donation() (Donation, error)

Donation casts the transaction content to a Donation.

func (*Transaction) GasUsed

func (tx *Transaction) GasUsed() math.Uint

GasUsed returns the amount of gas used by the transaction.

func (*Transaction) IsInbound

func (tx *Transaction) IsInbound() bool

IsInbound returns true if the transaction is inbound.

func (*Transaction) IsOutbound

func (tx *Transaction) IsOutbound() bool

IsOutbound returns true if the transaction is outbound.

func (*Transaction) Withdrawal

func (tx *Transaction) Withdrawal() (Withdrawal, error)

Withdrawal casts the transaction content to a Withdrawal.

type Withdrawal

type Withdrawal struct {
	Recipient ton.AccountID
	Amount    math.Uint
	Seqno     uint32
	Sig       [65]byte
}

Withdrawal represents a withdrawal external message

func (*Withdrawal) AsBody

func (w *Withdrawal) AsBody() (*boc.Cell, error)

func (*Withdrawal) Hash

func (w *Withdrawal) Hash() ([32]byte, error)

Hash returns hash of the withdrawal message. (used for signing)

func (*Withdrawal) SetSignature

func (w *Withdrawal) SetSignature(sig [65]byte)

SetSignature sets signature to the withdrawal message. Note that signature has the following order: [R, S, V (recovery ID)]

func (*Withdrawal) Signer

func (w *Withdrawal) Signer() (eth.Address, error)

Signer returns EVM address of the signer (e.g. TSS)

Jump to

Keyboard shortcuts

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