reef

package
v3.0.0-...-e8b7a4c Latest Latest
Warning

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

Go to latest
Published: Jul 24, 2023 License: GPL-3.0 Imports: 29 Imported by: 0

README

Reef

Reef Docs

https://docs.reef.io/docs/users/introduction/

Router Github

https://github.com/deltaswapio/swaprouter/tree/feature/reef-substrate

Router Contract

Reef support evm contract https://github.com/deltaswapio/anyswap-v1-core

Account Mechanism

graph TB
    begin(mpc public key)--> IsRemaining{"generate"}
    IsRemaining --sr25519-->reefAddr[ss58Address]--> sign(sign tx)
    IsRemaining --> |ecdsa|evmAddr[evmAddr]--> interaction(evm calls)

Class Diagram

classDiagram

class IMPCSign  {
	VerifyMsgHash(rawTx interface, msgHash []string) error
	MPCSignTransaction(rawTx interface, args *BuildTxArgs) (signedTx interface, txHash string, err error)
}
class IBridgeConfg {
	GetGatewayConfig() *GatewayConfig
	GetChainConfig() *ChainConfig
	GetTokenConfig(tokenAddr string) *TokenConfig
	GetRouterContract(token string) string

	SetChainConfig(chainCfg *ChainConfig)
	SetGatewayConfig(gatewayCfg *GatewayConfig)
	SetTokenConfig(token string, tokenCfg *TokenConfig)
}
class NonceSetter {
	InitSwapNonce(br NonceSetter, address string, nonce uint64)

	GetPoolNonce(address, height string) (uint64, error)
	SetNonce(address string, value uint64)
	AdjustNonce(address string, value uint64) (nonce uint64)

	AllocateNonce(args *BuildTxArgs) (nonce uint64, err error)
	RecycleSwapNonce(sender string, nonce uint64)
}

class IBridge{
    InitRouterInfo(routerContract string) error
	InitAfterConfig()
	RegisterSwap(txHash string, args *RegisterArgs) ([]*SwapTxInfo, []error)
	VerifyTransaction(txHash string, ars *VerifyArgs) (*SwapTxInfo, error)
	BuildRawTransaction(args *BuildTxArgs) (rawTx interface, err error)
	SendTransaction(signedTx interface) (txHash string, err error)
	GetTransaction(txHash string) (interface, error)
	GetTransactionStatus(txHash string) (*TxStatus, error)
	GetLatestBlockNumber() (uint64, error)
	GetLatestBlockNumberOf(url string) (uint64, error)
	IsValidAddress(address string) bool
	PublicKeyToAddress(pubKeyHex string) (string, error)
	GetBalance(account string) (*big.Int, error)
}

class CustomConfig {
	RPCClientTimeout int
	DontCheckAddressMixedCase bool
}

class EvmContractBridge {
	CallContract(contract string, data hexutil.Bytes, blockNumber string) (string, error)
	VerifyMPCPubKey(mpcAddress, mpcPubkey string) error
	GetTransactionReceipt(txHash string) (receipt *types.RPCTxReceipt, err error)
	GetLatestBlockNumberOf(url string) (latest uint64, err error)
	GetTransactionByHash(txHash string) (tx *types.RPCTransaction, err error)
}

class NonceSetterBase {
	*tokens.CrossChainBridgeBase
	swapNonce    map[string]*uint64
	recycleNonce map[string]*recycleNonceRecord
	swapNonceLock        sync.RWMutex
	recycleSwapNonceLock sync.RWMutex
}

class EthBridge{
    Signer        types.Signer
	SignerChainID *big.Int
	latestGasPrice  *big.Int
	autoMaxGasPrice *big.Int
}

class ReefBridge{
    WS            []*WebSocket
	SubstrateAPIs []*gsrpc.SubstrateAPI
	MetaData      *types.Metadata
}

    IMPCSign *-- IBridge
    IBridgeConfg *-- IBridge
    IBridge <.. EthBridge
    NonceSetter <.. EthBridge
    EvmContractBridge <.. EthBridge
    CustomConfig *-- EthBridge
    NonceSetterBase *-- EthBridge
    EthBridge *-- ReefBridge
    EvmContractBridge <.. ReefBridge

Sequence Diagram

sequenceDiagram

    participant R as Router 
    participant J as JS Scirpt
    participant W as Reef WebSocket(GraphQL)
    participant H as Reef Rpc
    
    R ->> W: connect ws
    loop 
        W->>W: Send and Receive
        Note over W: QueryTx QueryEventLogs QueryEvmAddress QueryReefAddress
    end

    R ->>+ J: exec js
    Note over J: GetSignInfo BuildSigningMessage GetTxHash SendSignedTx SignMessageWithPrivate 
    J ->>+ H: request
    H ->>- J: response
    J ->>- R: result

    R ->>+ H: request
     Note right of R: others
    H ->>- R: response

Tools

  • GetReefChainID
    go run tokens/reef/tools/getStubChainID/main.go -h
    
  • GetReefAddress
    go run tokens/reef/tools/getReefAddress/main.go -h
    

Documentation

Index

Constants

View Source
const EventLog_GQL = "" /* 352-byte string literal not displayed */
View Source
const EvmAddress_GQL = "" /* 163-byte string literal not displayed */
View Source
const MPC_PUBLICKEY_TYPE = "SR25519"
View Source
const ReefAddress_GQL = "" /* 166-byte string literal not displayed */
View Source
const TxHash_GQL = "" /* 284-byte string literal not displayed */

Variables

This section is empty.

Functions

func AddressToPubkey

func AddressToPubkey(base58Address string) []byte

reef address to pubkey

func BindEvmAddr

func BindEvmAddr(publicKey, evmPrivateKey string) ([]string, error)

func BuildSigningMessage

func BuildSigningMessage(params []interface{}) (string, error)

func CurrentCallerDir

func CurrentCallerDir() string

func GetSignInfo

func GetSignInfo(rawTx, evmAddress, substrateAddress, toAddr string) ([]string, error)

func GetStubChainID

func GetStubChainID(network string) *big.Int

GetStubChainID get stub chainID mainnet: 1001380271430 testnet: 1001380271431 devnet: 1001380271432

func GetTxHash

func GetTxHash(params []interface{}) (string, error)

func InstallJSModules

func InstallJSModules(path, url string)

func PubkeyToReefAddress

func PubkeyToReefAddress(publicKey string) string

pubkey to reef address

func Public2address

func Public2address(algorithmType, publicKey string) (string, error)

func SendBindEvm

func SendBindEvm(publicKey, evmPrivateKey, blockHash, blockNumber, nonce, signature string) (string, error)

func SendSignedTx

func SendSignedTx(params []interface{}) (string, error)

func SignMessageWithPrivate

func SignMessageWithPrivate(params []interface{}) ([]string, error)

func SupportsChainID

func SupportsChainID(chainID *big.Int) bool

SupportsChainID supports chainID

Types

type Account

type Account struct {
	EvmAddress  string `json:"evm_address,omitempty"`
	ReefAddress string `json:"address,omitempty"`
	Nonce       uint64 `json:"nonce,omitempty"`
	EvmNonce    uint64 `json:"evm_nonce,omitempty"`
	BaseData
}

type BaseData

type BaseData struct {
	Index    uint64 `json:"index,omitempty"`
	Method   string `json:"method,omitempty"`
	Section  string `json:"section,omitempty"`
	Typename string `json:"__typename,omitempty"`
}

type Bridge

type Bridge struct {
	eth.Bridge
	WS            []*WebSocket
	SubstrateAPIs []*gsrpc.SubstrateAPI
	MetaData      *types.Metadata
}

Reef Bridge extends eth bridge

func NewCrossChainBridge

func NewCrossChainBridge() *Bridge

NewCrossChainBridge new bridge

func (*Bridge) BuildRawTransaction

func (b *Bridge) BuildRawTransaction(args *tokens.BuildTxArgs) (rawTx interface{}, err error)

BuildRawTransaction build raw tx

func (*Bridge) CallContract

func (b *Bridge) CallContract(contract string, data hexutil.Bytes, blockNumber string) (string, error)

CallContract call eth_call

func (*Bridge) GetBalance

func (b *Bridge) GetBalance(account string) (balance *big.Int, err error)

GetBalance call eth_getBalance

func (*Bridge) GetGetBlockHash

func (b *Bridge) GetGetBlockHash(blockNumber uint64) (blockHash string, err error)

func (*Bridge) GetLatestBlockNumberOf

func (b *Bridge) GetLatestBlockNumberOf(url string) (latest uint64, err error)

func (*Bridge) GetPoolNonce

func (b *Bridge) GetPoolNonce(reefAddress, _height string) (nonce uint64, err error)

func (*Bridge) GetSignedTxHashOfKeyID

func (b *Bridge) GetSignedTxHashOfKeyID(sender, keyID string, rawTx interface{}) (txHash string, err error)

GetSignedTxHashOfKeyID get signed tx hash by keyID (called by oracle)

func (*Bridge) GetTransactionByHash

func (b *Bridge) GetTransactionByHash(txHash string) (tx *types.RPCTransaction, err error)

func (*Bridge) GetTransactionReceipt

func (b *Bridge) GetTransactionReceipt(txHash string) (result *types.RPCTxReceipt, err error)

func (*Bridge) InitAfterConfig

func (b *Bridge) InitAfterConfig()

InitAfterConfig init variables (ie. extra members) after loading config

func (*Bridge) InitWS

func (b *Bridge) InitWS()

func (*Bridge) IsValidAddress

func (b *Bridge) IsValidAddress(address string) bool

IsValidAddress check address

func (*Bridge) MPCSignTransaction

func (b *Bridge) MPCSignTransaction(rawTx interface{}, args *tokens.BuildTxArgs) (signTx interface{}, txHash string, err error)

MPCSignTransaction mpc sign raw tx

func (*Bridge) PublicKeyToAddress

func (b *Bridge) PublicKeyToAddress(pubKey string) (string, error)

publicKey to evmAddress by reef default

func (*Bridge) QueryEvmAddress

func (b *Bridge) QueryEvmAddress(ss58address string) (addr *common.Address, err error)

func (*Bridge) QueryReefAddress

func (b *Bridge) QueryReefAddress(evmAddress string) (addr *string, err error)

func (*Bridge) SendTransaction

func (b *Bridge) SendTransaction(signedTx interface{}) (txHash string, err error)

func (*Bridge) SignTransactionWithPrivateKey

func (b *Bridge) SignTransactionWithPrivateKey(rawTx interface{}, priKey string) (signTx interface{}, txHash string, err error)

SignTransactionWithPrivateKey sign tx with private key (use for testing)

func (*Bridge) VerifyMPCPubKey

func (b *Bridge) VerifyMPCPubKey(mpcAddress, mpcPubkey string) error

implement EvmContractBridge VerifyMPCPubKey mpcAddress maybe is pair of mpcPubkey or just calc by reef algorithem

func (*Bridge) VerifyMsgHash

func (b *Bridge) VerifyMsgHash(rawTx interface{}, msgHashes []string) (err error)

VerifyMsgHash verify msg hash

func (*Bridge) VerifyTransaction

func (b *Bridge) VerifyTransaction(txHash string, args *tokens.VerifyArgs) (*tokens.SwapTxInfo, error)

VerifyTransaction api

type Command

type Command struct {
	ID     string        `json:"id,omitempty"`
	Name   string        `json:"-"`
	Error  *string       `json:"-"`
	Ready  chan struct{} `json:"-"`
	Result interface{}   `json:"-"`
}

func (*Command) CommandName

func (c *Command) CommandName() string

func (*Command) Done

func (c *Command) Done()

func (*Command) Fail

func (c *Command) Fail(message string)

func (*Command) SetResult

func (c *Command) SetResult(data interface{})

type EventLog

type EventLog struct {
	Data      []Log     `json:"data,omitempty"`
	Extrinsic Extrinsic `json:"extrinsic,omitempty"`
	BaseData
}

type Extrinsic

type Extrinsic struct {
	Args         []*hexutil.Bytes `json:"args,omitempty"`
	BlockID      *uint64          `json:"block_id,omitempty"`
	ID           *uint64          `json:"id,omitempty"`
	Signer       string           `json:"signer,omitempty"`
	ErrorMessage string           `json:"error_message,omitempty"`
	Hash         *string          `json:"hash,omitempty"`
	Timestamp    string           `json:"timestamp,omitempty"`
	Status       string           `json:"status,omitempty"`
	Type         string           `json:"type,omitempty"`
	SignedData   *SignedData      `json:"signed_data,omitempty"`
	BaseData
}

type Fee

type Fee struct {
	Class      string  `json:"class,omitempty"`
	PartialFee string  `json:"partialFee,omitempty"`
	Weight     *uint64 `json:"weight,omitempty"`
}

type Log

type Log struct {
	Data    *hexutil.Bytes `json:"data,omitempty"`
	Topics  []string       `json:"topics,omitempty"`
	Address string         `json:"address,omitempty"`
}

type ReefGraphQLAccountData

type ReefGraphQLAccountData struct {
	Accounts []Account `json:"account,omitempty"`
}

type ReefGraphQLBaseResponse

type ReefGraphQLBaseResponse struct {
	ID      string `json:"id"`
	Type    string `json:"type"`
	Message string `json:"message,omitempty"`
}

type ReefGraphQLEventLogsData

type ReefGraphQLEventLogsData struct {
	Events []EventLog `json:"event,omitempty"`
}

type ReefGraphQLPayLoad

type ReefGraphQLPayLoad struct {
	Extensions    interface{}            `json:"extensions,omitempty"`
	OperationName string                 `json:"operationName,omitempty"`
	Query         string                 `json:"query,omitempty"`
	Variables     map[string]interface{} `json:"variables,omitempty"`
}

type ReefGraphQLRequest

type ReefGraphQLRequest struct {
	*Command
	// ID      string             `json:"id,omitempty"`
	Type    string             `json:"type"`
	Payload ReefGraphQLPayLoad `json:"payload"`
}

type ReefGraphQLResponse

type ReefGraphQLResponse struct {
	ReefGraphQLBaseResponse
	Payload ReefGraphQLResponsePayload `json:"payload,omitempty"`
}

type ReefGraphQLResponsePayload

type ReefGraphQLResponsePayload struct {
	Data interface{} `json:"data,omitempty"`
}

type ReefGraphQLTxData

type ReefGraphQLTxData struct {
	Extrinsic []Extrinsic `json:"extrinsic,omitempty"`
}

type ReefTransaction

type ReefTransaction struct {
	From         *string
	EvmAddress   *string
	ReefAddress  *string
	To           *string
	Data         *hexutil.Bytes
	AccountNonce *uint64
	Amount       *big.Int
	GasLimit     *uint64
	StorageGas   *uint64
	BlockHash    *string
	BlockNumber  *uint64
	Signature    *string
	TxHash       *string
}

type SignedData

type SignedData struct {
	Fee *Fee `json:"fee,omitempty"`
}

type Syncer

type Syncer interface {
	CommandName() string
	Done()
	Fail(message string)
	SetResult(data interface{})
}

type WebSocket

type WebSocket struct {
	IsClose bool
	// contains filtered or unexported fields
}

func NewWebSocket

func NewWebSocket(_endpoint string) (*WebSocket, error)

func (*WebSocket) Close

func (r *WebSocket) Close()

Close shuts down the Remote session and blocks until all internal goroutines have been cleaned up. Any commands that are pending a response will return with an error.

func (*WebSocket) InitConn

func (r *WebSocket) InitConn() error

func (*WebSocket) QueryAccountByReefAddr

func (r *WebSocket) QueryAccountByReefAddr(ss58address string) (*Account, error)

func (*WebSocket) QueryEventLogs

func (r *WebSocket) QueryEventLogs(extrinsicId uint64) (*[]EventLog, error)

func (*WebSocket) QueryEvmAddress

func (r *WebSocket) QueryEvmAddress(ss58address string) (*common.Address, error)

func (*WebSocket) QueryReefAddress

func (r *WebSocket) QueryReefAddress(evmAddress string) (*string, error)

func (*WebSocket) QueryTx

func (r *WebSocket) QueryTx(hash string) (*Extrinsic, error)

Synchronously get a single transaction

func (*WebSocket) ReConn

func (r *WebSocket) ReConn()

func (*WebSocket) Read

func (r *WebSocket) Read(inbound chan<- []byte)

readPump reads from the websocket and sends to inbound channel. Expects to receive PONGs at specified interval, or logs an error and returns.

func (*WebSocket) Run

func (r *WebSocket) Run()

run spawns the read/write pumps and then runs until Close() is called.

func (*WebSocket) SendCommond

func (r *WebSocket) SendCommond(cmd *ReefGraphQLRequest) error

func (*WebSocket) Write

func (r *WebSocket) Write(outbound <-chan interface{})

Consumes from the outbound channel and sends them over the websocket. Also sends PING messages at the specified interval. Returns when outbound channel is closed, or an error is encountered.

Directories

Path Synopsis
tools

Jump to

Keyboard shortcuts

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