lziface.gno
2.34 Kb · 86 lines
1package lziface
2
3import (
4 "crypto/sha256"
5 "encoding/binary"
6 "chain/runtime"
7
8 "gno.land/p/samcrew/deps/onbloc/uint256"
9)
10
11var EMPTY_PAYLOAD_HASH = [32]byte{}
12
13type Origin struct {
14 SrcEID uint32
15 Sender [32]byte
16 Nonce uint64
17}
18
19type OApp interface {
20 AllowInitializePath(origin *Origin) bool
21 LZReceive(cur realm, origin *Origin, guid [32]byte, message []byte, executor runtime.Realm, extraData []byte)
22}
23
24// MessagingParams contains all parameters needed for LayerZero message quoting/sending
25type MessagingParams struct {
26 DstEID uint32 // Destination endpoint ID (uint32 in Solidity)
27 Receiver [32]byte // bytes32 in Solidity (fixed-size 32 byte array)
28 Message []byte // bytes in Solidity (dynamic byte array)
29 Options []byte // bytes in Solidity (dynamic byte array)
30 PayInLzToken bool // bool in Solidity
31}
32
33// MessagingFee represents the fee structure for LayerZero messages
34type MessagingFee struct {
35 NativeFee *uint256.Uint // uint256 in Solidity
36 LzTokenFee *uint256.Uint // uint256 in Solidity
37}
38
39// MessagingReceipt contains the result of a message send operation
40type MessagingReceipt struct {
41 Guid [32]byte // bytes32 in Solidity
42 Nonce uint64 // uint64 in Solidity
43 Fee *MessagingFee // Nested struct
44}
45
46func GenerateGUID(
47 nonce uint64,
48 srcEID uint32,
49 senderAddr address,
50 dstEID uint32,
51 receiver [32]byte,
52) [32]byte {
53 packed := make([]byte, 8+4+32+4+32)
54
55 binary.BigEndian.PutUint64(packed, nonce)
56
57 binary.BigEndian.PutUint32(packed[8:], srcEID)
58
59 lzAddr := AddressToBytes32(senderAddr)
60 copy(packed[8+4:], lzAddr[:])
61
62 binary.BigEndian.PutUint32(packed[8+4+32:], dstEID)
63
64 copy(packed[8+4+32+4:], receiver[:])
65
66 return sha256.Sum256(packed)
67}
68
69type SendLib interface {
70 MessageLib // Embed the base interface
71
72 // Send transmits a packet and returns fee and encoded packet
73 Send(cur realm, packet *GnoPacket, options []byte, payInLzToken bool) (*MessagingFee, []byte)
74
75 // Quote calculates the fee for sending a packet
76 Quote(packet *GnoPacket, options []byte, payInLzToken bool) *MessagingFee
77
78 // SetTreasury sets the treasury address
79 // SetTreasury(treasury string)
80
81 // WithdrawFee withdraws native tokens to the specified address
82 // WithdrawFee(to address, amount *uint256.Uint)
83
84 // WithdrawLzTokenFee withdraws LZ tokens to the specified address
85 // WithdrawLzTokenFee(lzToken, to address, amount *uint256.Uint)
86}