README ¶
Reef
Reef Docs
https://docs.reef.io/docs/users/introduction/
- Metamask https://docs.reef.io/docs/users/extension/
- web3 https://github.com/reef-defi/evm-provider.js
- Truffle/Hardhat https://github.com/reef-defi/hardhat-reef
- Remix IDE https://remix.reefscan.com/
- Etherscan https://reefscan.com/
- GraphQL https://github.com/reef-defi/reef-explorer/tree/develop/db/hasura/metadata/databases/reefexplorer/tables
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
- func AddressToPubkey(base58Address string) []byte
- func BindEvmAddr(publicKey, evmPrivateKey string) ([]string, error)
- func BuildSigningMessage(params []interface{}) (string, error)
- func CurrentCallerDir() string
- func GetSignInfo(rawTx, evmAddress, substrateAddress, toAddr string) ([]string, error)
- func GetStubChainID(network string) *big.Int
- func GetTxHash(params []interface{}) (string, error)
- func InstallJSModules(path, url string)
- func PubkeyToReefAddress(publicKey string) string
- func Public2address(algorithmType, publicKey string) (string, error)
- func SendBindEvm(publicKey, evmPrivateKey, blockHash, blockNumber, nonce, signature string) (string, error)
- func SendSignedTx(params []interface{}) (string, error)
- func SignMessageWithPrivate(params []interface{}) ([]string, error)
- func SupportsChainID(chainID *big.Int) bool
- type Account
- type BaseData
- type Bridge
- func (b *Bridge) BuildRawTransaction(args *tokens.BuildTxArgs) (rawTx interface{}, err error)
- func (b *Bridge) CallContract(contract string, data hexutil.Bytes, blockNumber string) (string, error)
- func (b *Bridge) GetBalance(account string) (balance *big.Int, err error)
- func (b *Bridge) GetGetBlockHash(blockNumber uint64) (blockHash string, err error)
- func (b *Bridge) GetLatestBlockNumberOf(url string) (latest uint64, err error)
- func (b *Bridge) GetPoolNonce(reefAddress, _height string) (nonce uint64, err error)
- func (b *Bridge) GetSignedTxHashOfKeyID(sender, keyID string, rawTx interface{}) (txHash string, err error)
- func (b *Bridge) GetTransactionByHash(txHash string) (tx *types.RPCTransaction, err error)
- func (b *Bridge) GetTransactionReceipt(txHash string) (result *types.RPCTxReceipt, err error)
- func (b *Bridge) InitAfterConfig()
- func (b *Bridge) InitWS()
- func (b *Bridge) IsValidAddress(address string) bool
- func (b *Bridge) MPCSignTransaction(rawTx interface{}, args *tokens.BuildTxArgs) (signTx interface{}, txHash string, err error)
- func (b *Bridge) PublicKeyToAddress(pubKey string) (string, error)
- func (b *Bridge) QueryEvmAddress(ss58address string) (addr *common.Address, err error)
- func (b *Bridge) QueryReefAddress(evmAddress string) (addr *string, err error)
- func (b *Bridge) SendTransaction(signedTx interface{}) (txHash string, err error)
- func (b *Bridge) SignTransactionWithPrivateKey(rawTx interface{}, priKey string) (signTx interface{}, txHash string, err error)
- func (b *Bridge) VerifyMPCPubKey(mpcAddress, mpcPubkey string) error
- func (b *Bridge) VerifyMsgHash(rawTx interface{}, msgHashes []string) (err error)
- func (b *Bridge) VerifyTransaction(txHash string, args *tokens.VerifyArgs) (*tokens.SwapTxInfo, error)
- type Command
- type EventLog
- type Extrinsic
- type Fee
- type Log
- type ReefGraphQLAccountData
- type ReefGraphQLBaseResponse
- type ReefGraphQLEventLogsData
- type ReefGraphQLPayLoad
- type ReefGraphQLRequest
- type ReefGraphQLResponse
- type ReefGraphQLResponsePayload
- type ReefGraphQLTxData
- type ReefTransaction
- type SignedData
- type Syncer
- type WebSocket
- func (r *WebSocket) Close()
- func (r *WebSocket) InitConn() error
- func (r *WebSocket) QueryAccountByReefAddr(ss58address string) (*Account, error)
- func (r *WebSocket) QueryEventLogs(extrinsicId uint64) (*[]EventLog, error)
- func (r *WebSocket) QueryEvmAddress(ss58address string) (*common.Address, error)
- func (r *WebSocket) QueryReefAddress(evmAddress string) (*string, error)
- func (r *WebSocket) QueryTx(hash string) (*Extrinsic, error)
- func (r *WebSocket) ReConn()
- func (r *WebSocket) Read(inbound chan<- []byte)
- func (r *WebSocket) Run()
- func (r *WebSocket) SendCommond(cmd *ReefGraphQLRequest) error
- func (r *WebSocket) Write(outbound <-chan interface{})
Constants ¶
const EventLog_GQL = "" /* 352-byte string literal not displayed */
const EvmAddress_GQL = "" /* 163-byte string literal not displayed */
const MPC_PUBLICKEY_TYPE = "SR25519"
const ReefAddress_GQL = "" /* 166-byte string literal not displayed */
const TxHash_GQL = "" /* 284-byte string literal not displayed */
Variables ¶
This section is empty.
Functions ¶
func BindEvmAddr ¶
func BuildSigningMessage ¶
func CurrentCallerDir ¶
func CurrentCallerDir() string
func GetSignInfo ¶
func GetStubChainID ¶
GetStubChainID get stub chainID mainnet: 1001380271430 testnet: 1001380271431 devnet: 1001380271432
func InstallJSModules ¶
func InstallJSModules(path, url string)
func Public2address ¶
func SendBindEvm ¶
func SendSignedTx ¶
func SignMessageWithPrivate ¶
Types ¶
type Bridge ¶
type Bridge struct { eth.Bridge WS []*WebSocket SubstrateAPIs []*gsrpc.SubstrateAPI MetaData *types.Metadata }
Reef Bridge extends eth 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 ¶
GetBalance call eth_getBalance
func (*Bridge) GetGetBlockHash ¶
func (*Bridge) GetLatestBlockNumberOf ¶
func (*Bridge) GetPoolNonce ¶
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) IsValidAddress ¶
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 ¶
publicKey to evmAddress by reef default
func (*Bridge) QueryEvmAddress ¶
func (*Bridge) QueryReefAddress ¶
func (*Bridge) SendTransaction ¶
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 ¶
implement EvmContractBridge VerifyMPCPubKey mpcAddress maybe is pair of mpcPubkey or just calc by reef algorithem
func (*Bridge) VerifyMsgHash ¶
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 ¶
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 ReefGraphQLAccountData ¶
type ReefGraphQLAccountData struct {
Accounts []Account `json:"account,omitempty"`
}
type ReefGraphQLBaseResponse ¶
type ReefGraphQLEventLogsData ¶
type ReefGraphQLEventLogsData struct {
Events []EventLog `json:"event,omitempty"`
}
type ReefGraphQLPayLoad ¶
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 SignedData ¶
type SignedData struct {
Fee *Fee `json:"fee,omitempty"`
}
type WebSocket ¶
type WebSocket struct { IsClose bool // contains filtered or unexported fields }
func NewWebSocket ¶
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) QueryAccountByReefAddr ¶
func (*WebSocket) QueryEventLogs ¶
func (*WebSocket) QueryEvmAddress ¶
func (*WebSocket) QueryReefAddress ¶
func (*WebSocket) Read ¶
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