zcnbridge

package
v1.18.6 Latest Latest
Warning

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

Go to latest
Published: Nov 21, 2024 License: MIT Imports: 45 Imported by: 1

README

zcnbridge

import "github.com/0chain/gosdk/zcnbridge"

Index

Constants

const (
    TenderlyProvider = iota
    AlchemyProvider
    UnknownProvider
)

const (
    UniswapRouterAddress = "0x7a250d5630B4cF539739dF2C5dAcb4c659F2488D"
    UsdcTokenAddress     = "0xA0b86991c6218b36c1d19D4a2e9Eb0cE3606eB48"
    WethTokenAddress     = "0xC02aaA39b223FE8D0A0e5C4F27eAD9083C756Cc2"
)

const (
    EthereumWalletStorageDir = "wallets"
)

Variables

var (
    DefaultClientIDEncoder = func(id string) []byte {
        result, err := hex.DecodeString(id)
        if err != nil {
            Logger.Fatal(err)
        }
        return result
    }
)

var Logger logger.Logger

func AccountExists

func AccountExists(homedir, address string) bool

AccountExists checks if account exists

func ConfirmEthereumTransaction

func ConfirmEthereumTransaction(hash string, times int, duration time.Duration) (int, error)

func ConvertIntToHex

func ConvertIntToHex(value int64) string

ConvertIntToHex converts given int value to hex string.

func CreateKeyStorage

func CreateKeyStorage(homedir, password string) error

CreateKeyStorage create, restore or unlock key storage

func DeleteAccount

func DeleteAccount(homedir, address string) bool

DeleteAccount deletes account from wallet

func EncodePackInt64

func EncodePackInt64(key string, param int64) common.Hash

EncodePackInt do abi.encodedPack(string, int), it is used for setting plan id for royalty

func GetAuthorizer

func GetAuthorizer(id string, cb zcncore.GetInfoCallback) (err error)

GetAuthorizer returned authorizer by ID

func GetAuthorizers

func GetAuthorizers(active bool, cb zcncore.GetInfoCallback) (err error)

GetAuthorizers Returns all or only active authorizers

func GetGlobalConfig

func GetGlobalConfig(cb zcncore.GetInfoCallback) (err error)

GetGlobalConfig Returns global config

func GetTransactionStatus

func GetTransactionStatus(hash string) (int, error)

func ImportAccount

func ImportAccount(homedir, mnemonic, password string, accountAddrIndex ...AccountAddressIndex) (string, error)

ImportAccount imports account using mnemonic

func ListStorageAccounts

func ListStorageAccounts(homedir string) []common.Address

ListStorageAccounts List available accounts

type AccountAddressIndex

type AccountAddressIndex struct {
    AccountIndex int
    AddressIndex int
    Bip32        bool
}

type AlchemyGasEstimationRequest

AlchemyGasEstimationRequest describes request used for Alchemy enhanced JSON-RPC API.

type AlchemyGasEstimationRequest struct {
    From  string `json:"from"`
    To    string `json:"to"`
    Value string `json:"value"`
    Data  string `json:"data"`
}

type AuthorizerNode

type AuthorizerNode struct {
    ID  string `json:"id"`
    URL string `json:"url"`
}

type AuthorizerNodesResponse

type AuthorizerNodesResponse struct {
    Nodes []*AuthorizerNode `json:"nodes"`
}

type AuthorizerResponse

type AuthorizerResponse struct {
    AuthorizerID string `json:"id"`
    URL          string `json:"url"`

    // Configuration
    Fee common.Balance `json:"fee"`

    // Geolocation
    Latitude  float64 `json:"latitude"`
    Longitude float64 `json:"longitude"`

    // Stats
    LastHealthCheck int64 `json:"last_health_check"`

    // stake_pool_settings
    DelegateWallet string         `json:"delegate_wallet"`
    MinStake       common.Balance `json:"min_stake"`
    MaxStake       common.Balance `json:"max_stake"`
    NumDelegates   int            `json:"num_delegates"`
    ServiceCharge  float64        `json:"service_charge"`
}

type BancorTokenDetails

BancorTokenDetails describes Bancor ZCN zcntoken pool details

type BancorTokenDetails struct {
    Data struct {
        Rate struct {
            ETH  string `json:"eth"`
            BNT  string `json:"bnt"`
            USDC string `json:"usd"`
            EURC string `json:"eur"`
        }
    } `json:"data"`
}

type BridgeClient

type BridgeClient struct {
    BridgeAddress,
    TokenAddress,
    AuthorizersAddress,
    UniswapAddress,
    NFTConfigAddress,
    EthereumAddress,
    EthereumNodeURL,
    Password string

    BancorAPIURL string

    ConsensusThreshold float64
    GasLimit           uint64
    // contains filtered or unexported fields
}

func NewBridgeClient
func NewBridgeClient(bridgeAddress, tokenAddress, authorizersAddress, uniswapAddress, ethereumAddress, ethereumNodeURL, password string, gasLimit uint64, consensusThreshold float64, ethereumClient EthereumClient, transactionProvider transaction.TransactionProvider, keyStore KeyStore) *BridgeClient

NewBridgeClient creates BridgeClient with the given parameters.

func SetupBridgeClientSDK
func SetupBridgeClientSDK(cfg *BridgeSDKConfig) *BridgeClient

SetupBridgeClientSDK initializes new bridge client. Meant to be used from standalone application with 0chain SDK initialized.

func (*BridgeClient) AddEthereumAuthorizer
func (b *BridgeClient) AddEthereumAuthorizer(ctx context.Context, address common.Address) (*types.Transaction, error)

AddEthereumAuthorizer Adds authorizer to Ethereum bridge. Only contract deployer can call this method

func (*BridgeClient) AddEthereumAuthorizers
func (b *BridgeClient) AddEthereumAuthorizers(configDir string)

func (*BridgeClient) ApproveUSDCSwap
func (b *BridgeClient) ApproveUSDCSwap(ctx context.Context, source uint64) (*types.Transaction, error)

ApproveUSDCSwap provides opportunity to approve swap operation for ERC20 tokens

func (*BridgeClient) BurnWZCN
func (b *BridgeClient) BurnWZCN(ctx context.Context, amountTokens uint64) (*types.Transaction, error)

BurnWZCN Burns WZCN tokens on behalf of the 0ZCN client amountTokens - ZCN tokens clientID - 0ZCN client ERC20 signature: "burn(uint256,bytes)"

func (*BridgeClient) BurnZCN
func (b *BridgeClient) BurnZCN(ctx context.Context, amount, txnfee uint64) (transaction.Transaction, error)

BurnZCN burns ZCN tokens before conversion from ZCN to WZCN as a first step

func (*BridgeClient) CreateSignedTransactionFromKeyStore
func (b *BridgeClient) CreateSignedTransactionFromKeyStore(client EthereumClient, gasLimitUnits uint64) *bind.TransactOpts

func (*BridgeClient) EstimateBurnWZCNGasAmount
func (b *BridgeClient) EstimateBurnWZCNGasAmount(ctx context.Context, from, to, amountTokens string) (float64, error)

EstimateBurnWZCNGasAmount performs gas amount estimation for the given wzcn burn transaction.

func (*BridgeClient) EstimateGasPrice
func (b *BridgeClient) EstimateGasPrice(ctx context.Context) (float64, error)

EstimateGasPrice performs gas estimation for the given transaction.

func (*BridgeClient) EstimateMintWZCNGasAmount
func (b *BridgeClient) EstimateMintWZCNGasAmount(ctx context.Context, from, to, zcnTransactionRaw, amountToken string, nonceRaw int64, signaturesRaw [][]byte) (float64, error)

EstimateMintWZCNGasAmount performs gas amount estimation for the given wzcn mint transaction.

func (*BridgeClient) GetETHSwapAmount
func (b *BridgeClient) GetETHSwapAmount(ctx context.Context, source uint64) (*big.Int, error)

GetETHSwapAmount retrieves ETH swap amount from the given source.

func (*BridgeClient) GetTokenBalance
func (b *BridgeClient) GetTokenBalance() (*big.Int, error)

GetTokenBalance returns balance of the current client for the zcntoken address

func (*BridgeClient) GetUserNonceMinted
func (b *BridgeClient) GetUserNonceMinted(ctx context.Context, rawEthereumAddress string) (*big.Int, error)

GetUserNonceMinted Returns nonce for a specified Ethereum address

func (*BridgeClient) IncreaseBurnerAllowance
func (b *BridgeClient) IncreaseBurnerAllowance(ctx context.Context, allowanceAmount uint64) (*types.Transaction, error)

IncreaseBurnerAllowance Increases allowance for bridge contract address to transfer ERC-20 tokens on behalf of the zcntoken owner to the Burn TokenPool During the burn the script transfers amount from zcntoken owner to the bridge burn zcntoken pool Example: owner wants to burn some amount. The contract will transfer some amount from owner address to the pool. So the owner must call IncreaseAllowance of the WZCN zcntoken with 2 parameters: spender address which is the bridge contract and amount to be burned (transferred) Token signature: "increaseApproval(address,uint256)"

func (*BridgeClient) MintWZCN
func (b *BridgeClient) MintWZCN(ctx context.Context, payload *ethereum.MintPayload) (*types.Transaction, error)

MintWZCN Mint ZCN tokens on behalf of the 0ZCN client payload: received from authorizers

func (*BridgeClient) MintZCN
func (b *BridgeClient) MintZCN(ctx context.Context, payload *zcnsc.MintPayload) (string, error)

MintZCN mints ZCN tokens after receiving proof-of-burn of WZCN tokens

func (*BridgeClient) NFTConfigGetAddress
func (b *BridgeClient) NFTConfigGetAddress(ctx context.Context, key string) (string, string, error)

func (*BridgeClient) NFTConfigGetUint256
func (b *BridgeClient) NFTConfigGetUint256(ctx context.Context, key string, keyParam ...int64) (string, int64, error)

func (*BridgeClient) NFTConfigSetAddress
func (b *BridgeClient) NFTConfigSetAddress(ctx context.Context, key, address string) (*types.Transaction, error)

func (*BridgeClient) NFTConfigSetUint256
func (b *BridgeClient) NFTConfigSetUint256(ctx context.Context, key string, value int64) (*types.Transaction, error)

NFTConfigSetUint256 call setUint256 method of NFTConfig contract

func (*BridgeClient) NFTConfigSetUint256Raw
func (b *BridgeClient) NFTConfigSetUint256Raw(ctx context.Context, key common.Hash, value int64) (*types.Transaction, error)

func (*BridgeClient) QueryEthereumBurnEvents
func (b *BridgeClient) QueryEthereumBurnEvents(startNonce string) ([]*ethereum.BurnEvent, error)

QueryEthereumBurnEvents gets ethereum burn events

func (*BridgeClient) QueryEthereumMintPayload
func (b *BridgeClient) QueryEthereumMintPayload(zchainBurnHash string) (*ethereum.MintPayload, error)

QueryEthereumMintPayload gets burn ticket and creates mint payload to be minted in the Ethereum chain zchainBurnHash - Ethereum burn transaction hash

func (*BridgeClient) QueryZChainMintPayload
func (b *BridgeClient) QueryZChainMintPayload(ethBurnHash string) (*zcnsc.MintPayload, error)

QueryZChainMintPayload gets burn ticket and creates mint payload to be minted in the ZChain ethBurnHash - Ethereum burn transaction hash

func (*BridgeClient) RemoveEthereumAuthorizer
func (b *BridgeClient) RemoveEthereumAuthorizer(ctx context.Context, address common.Address) (*types.Transaction, error)

RemoveEthereumAuthorizer Removes authorizer from Ethereum bridge. Only contract deployer can call this method

func (*BridgeClient) ResetUserNonceMinted
func (b *BridgeClient) ResetUserNonceMinted(ctx context.Context) (*types.Transaction, error)

ResetUserNonceMinted Resets nonce for a specified Ethereum address

func (*BridgeClient) SignWithEthereumChain
func (b *BridgeClient) SignWithEthereumChain(message string) ([]byte, error)

SignWithEthereumChain signs the digest with Ethereum chain signer taking key from the current user key storage

func (*BridgeClient) SwapETH
func (b *BridgeClient) SwapETH(ctx context.Context, source uint64, target uint64) (*types.Transaction, error)

SwapETH provides opportunity to perform zcn token swap operation using ETH as source token.

func (*BridgeClient) SwapUSDC
func (b *BridgeClient) SwapUSDC(ctx context.Context, source uint64, target uint64) (*types.Transaction, error)

SwapUSDC provides opportunity to perform zcn token swap operation using USDC as source token.

func (*BridgeClient) VerifyZCNTransaction
func (b *BridgeClient) VerifyZCNTransaction(ctx context.Context, hash string) (transaction.Transaction, error)

VerifyZCNTransaction verifies 0CHain transaction

type BridgeSDKConfig

type BridgeSDKConfig struct {
    LogLevel        *string
    LogPath         *string
    ConfigChainFile *string
    ConfigDir       *string
    Development     *bool
}

type DetailedAccount

DetailedAccount describes detailed account

type DetailedAccount struct {
    EthereumAddress,
    PublicKey,
    PrivateKey accounts.Account
}

type EthereumBurnEvents

EthereumBurnEvents represents burn events returned by authorizers

type EthereumBurnEvents struct {
    AuthorizerID string `json:"authorizer_id,omitempty"`
    BurnEvents   []struct {
        Nonce           int64  `json:"nonce"`
        Amount          int64  `json:"amount"`
        TransactionHash string `json:"transaction_hash"`
    }   `json:"burn_events"`
}

func (*EthereumBurnEvents) Data
func (r *EthereumBurnEvents) Data() interface{}

func (*EthereumBurnEvents) Error
func (r *EthereumBurnEvents) Error() error

func (*EthereumBurnEvents) GetAuthorizerID
func (r *EthereumBurnEvents) GetAuthorizerID() string

func (*EthereumBurnEvents) SetAuthorizerID
func (r *EthereumBurnEvents) SetAuthorizerID(id string)

type EthereumClient

EthereumClient describes Ethereum JSON-RPC client generealized interface

type EthereumClient interface {
    bind.ContractBackend

    ChainID(ctx context.Context) (*big.Int, error)
}

type GasEstimationRequest

GasEstimationRequest describes request used for Alchemy enhanced JSON-RPC API.

type GasEstimationRequest struct {
    From  string `json:"from"`
    To    string `json:"to"`
    Value string `json:"value"`
}

type GasPriceEstimationResult

GasPriceEstimationResult represents result of the gas price estimation operation execution.

type GasPriceEstimationResult struct {
    Value float64 `json:"value"`
}

type JobError

JobError result of internal request wrapped in authorizer job

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

func (*JobError) MarshalJSON
func (e *JobError) MarshalJSON() ([]byte, error)

func (*JobError) UnmarshalJSON
func (e *JobError) UnmarshalJSON(buf []byte) error

type JobResult

JobResult = Authorizer task result, it wraps actual result of the query inside authorizer

type JobResult interface {
    // Error = Status of Authorizer job on authorizer server
    Error() error
    // Data returns the actual result
    Data() interface{}
    // SetAuthorizerID Assigns authorizer ID to the Job
    SetAuthorizerID(ID string)
    // GetAuthorizerID returns authorizer ID
    GetAuthorizerID() string
}

type JobStatus

JobStatus = Ethereum transaction status

type JobStatus uint

type KeyStore

KeyStore is a wrapper, which exposes Ethereum KeyStore methods used by DEX bridge.

type KeyStore interface {
    Find(accounts.Account) (accounts.Account, error)
    TimedUnlock(accounts.Account, string, time.Duration) error
    SignHash(account accounts.Account, hash []byte) ([]byte, error)
    GetEthereumKeyStore() *keystore.KeyStore
}

func NewKeyStore
func NewKeyStore(path string) KeyStore

NewKeyStore creates new KeyStore wrapper instance

type ProofEthereumBurn

ProofEthereumBurn Authorizer returns this type for Ethereum transaction

type ProofEthereumBurn struct {
    TxnID             string `json:"ethereum_txn_id"`
    Nonce             int64  `json:"nonce"`
    Amount            int64  `json:"amount"`
    ReceivingClientID string `json:"receiving_client_id"` // 0ZCN address
    Signature         string `json:"signature"`
}

type ProofZCNBurn

ProofZCNBurn Authorizer returns this type for ZCN transaction

type ProofZCNBurn struct {
    AuthorizerID string `json:"authorizer_id,omitempty"`
    TxnID        string `json:"0chain_txn_id"`
    To           string `json:"to"`
    Nonce        int64  `json:"nonce"`
    Amount       int64  `json:"amount"`
    Signature    []byte `json:"signature"`
}

func (*ProofZCNBurn) Data
func (r *ProofZCNBurn) Data() interface{}

func (*ProofZCNBurn) Error
func (r *ProofZCNBurn) Error() error

func (*ProofZCNBurn) GetAuthorizerID
func (r *ProofZCNBurn) GetAuthorizerID() string

func (*ProofZCNBurn) SetAuthorizerID
func (r *ProofZCNBurn) SetAuthorizerID(id string)

type WZCNBurnEvent

WZCNBurnEvent returned from burn ticket handler of: /v1/ether/burnticket/get

type WZCNBurnEvent struct {
    // 	AuthorizerID Authorizer ID
    AuthorizerID string `json:"authorizer_id,omitempty"`
    // BurnTicket Returns burn ticket
    BurnTicket *ProofEthereumBurn `json:"ticket,omitempty"`
    // Err gives error of job on server side
    Err *JobError `json:"err,omitempty"`
    // Status gives job status on server side (authoriser)
    Status JobStatus `json:"status,omitempty"`
}

func (*WZCNBurnEvent) Data
func (r *WZCNBurnEvent) Data() interface{}

func (*WZCNBurnEvent) Error
func (r *WZCNBurnEvent) Error() error

func (*WZCNBurnEvent) GetAuthorizerID
func (r *WZCNBurnEvent) GetAuthorizerID() string

func (*WZCNBurnEvent) SetAuthorizerID
func (r *WZCNBurnEvent) SetAuthorizerID(id string)

Generated by gomarkdoc

Documentation

Overview

Methods and types to interact with the Bridge protocol. Bridge protocol defines how clients can exchange tokens between 0chain and Ethereum blockchains. It defines the functionality to Mint/Burn native or ERC20 Züs tokens.

Index

Constants

View Source
const (
	TenderlyProvider = iota
	AlchemyProvider
	UnknownProvider
)
View Source
const (
	UniswapRouterAddress = "0x7a250d5630B4cF539739dF2C5dAcb4c659F2488D"
	UsdcTokenAddress     = "0xA0b86991c6218b36c1d19D4a2e9Eb0cE3606eB48"
	WethTokenAddress     = "0xC02aaA39b223FE8D0A0e5C4F27eAD9083C756Cc2"
)
View Source
const (
	// SCRestAPIPrefix represents base URL path to execute smart contract rest points.
	SCRestAPIPrefix        = "v1/screst/"
	RestPrefix             = SCRestAPIPrefix + zcncore.ZCNSCSmartContractAddress
	PathGetAuthorizerNodes = "/getAuthorizerNodes?active=%t"
	PathGetGlobalConfig    = "/getGlobalConfig"
	PathGetAuthorizer      = "/getAuthorizer"
)
View Source
const (
	EthereumWalletStorageDir = "wallets"
)

Variables

View Source
var (
	DefaultClientIDEncoder = func(id string) []byte {
		result, err := hex.DecodeString(id)
		if err != nil {
			Logger.Fatal(err)
		}
		return result
	}
)

Functions

func AccountExists added in v1.3.5

func AccountExists(homedir, address string) bool

AccountExists checks if account exists

  • homedir is the home directory
  • address is the account address

func ConfirmEthereumTransaction

func ConfirmEthereumTransaction(hash string, times int, duration time.Duration) (int, error)

ConfirmEthereumTransaction confirms Ethereum transaction by hash.

  • hash is the transaction hash to confirm.
  • times is the number of times to try confirming the transaction.
  • duration is the duration to wait between each confirmation attempt.

func ConvertIntToHex added in v1.13.4

func ConvertIntToHex(value int64) string

ConvertIntToHex converts given int value to hex string.

func CreateKeyStorage added in v1.3.5

func CreateKeyStorage(homedir, password string) error

CreateKeyStorage create, restore or unlock key storage

  • homedir is the home directory
  • password is the password

func DeleteAccount added in v1.4.7

func DeleteAccount(homedir, address string) bool

DeleteAccount deletes account from wallet

  • homedir is the home directory
  • address is the account address

func EncodePackInt64 added in v1.11.0

func EncodePackInt64(key string, param int64) common.Hash

EncodePackInt do abi.encodedPack(string, int), it is used for setting plan id for royalty

  • key key for the plan
  • param plan id

func GetAuthorizer added in v1.7.1

func GetAuthorizer(id string) (res []byte, err error)

GetAuthorizer returned authorizer information from Züs Blockchain by the ID

  • id is the authorizer ID
  • cb is the callback function to handle the response asynchronously

func GetAuthorizers

func GetAuthorizers(active bool) (res []byte, err error)

GetAuthorizers Returns all or only active authorizers

  • active is the flag to get only active authorizers
  • cb is the callback function to handle the response asynchronously

func GetGlobalConfig added in v1.7.1

func GetGlobalConfig() (res []byte, err error)

GetGlobalConfig Returns global config

  • cb is the callback function to handle the response asynchronously

func GetTransactionStatus

func GetTransactionStatus(hash string) (int, error)

func ImportAccount added in v1.3.5

func ImportAccount(homedir, mnemonic, password string, accountAddrIndex ...AccountAddressIndex) (string, error)

ImportAccount imports account using mnemonic

  • homedir is the home directory
  • mnemonic is the mnemonic phrase
  • password is the password
  • accountAddrIndex is the account and address indexes used for the derivation of the ethereum account

func ListStorageAccounts added in v1.3.5

func ListStorageAccounts(homedir string) []common.Address

ListStorageAccounts List available accounts

  • homedir is the home directory

Types

type AccountAddressIndex added in v1.11.0

type AccountAddressIndex struct {
	AccountIndex int
	AddressIndex int

	// Bip32 flag indicates if the account is derived using BIP32 derivation path.
	Bip32 bool
}

AccountAddressIndex represents client account and address indexes for multi-key wallet. Used to derive ethereum account.

type AlchemyGasEstimationRequest added in v1.13.8

type AlchemyGasEstimationRequest struct {
	From  string `json:"from"`
	To    string `json:"to"`
	Value string `json:"value"`
	Data  string `json:"data"`
}

AlchemyGasEstimationRequest describes request used for Alchemy enhanced JSON-RPC API.

type AuthorizerNode

type AuthorizerNode struct {
	ID  string `json:"id"`
	URL string `json:"url"`
}

AuthorizerNode represents an authorizer node

type AuthorizerNodesResponse added in v1.7.1

type AuthorizerNodesResponse struct {
	Nodes []*AuthorizerNode `json:"nodes"`
}

AuthorizerNodesResponse represents the response of the request to get authorizers

type AuthorizerResponse added in v1.7.1

type AuthorizerResponse struct {
	AuthorizerID string `json:"id"`
	URL          string `json:"url"`

	// Configuration
	Fee common.Balance `json:"fee"`

	// Geolocation
	Latitude  float64 `json:"latitude"`
	Longitude float64 `json:"longitude"`

	// Stats
	LastHealthCheck int64 `json:"last_health_check"`

	// stake_pool_settings
	DelegateWallet string         `json:"delegate_wallet"`
	MinStake       common.Balance `json:"min_stake"`
	MaxStake       common.Balance `json:"max_stake"`
	NumDelegates   int            `json:"num_delegates"`
	ServiceCharge  float64        `json:"service_charge"`
}

AuthorizerResponse represents the response of the request to get authorizer info from the sharders.

type BancorTokenDetails added in v1.11.0

type BancorTokenDetails struct {
	Data struct {
		Rate struct {
			ETH  string `json:"eth"`
			BNT  string `json:"bnt"`
			USDC string `json:"usd"`
			EURC string `json:"eur"`
		}
	} `json:"data"`
}

BancorTokenDetails describes Bancor ZCN zcntoken pool details

type BridgeClient added in v1.3.5

type BridgeClient struct {
	BridgeAddress,
	TokenAddress,
	AuthorizersAddress,
	UniswapAddress,
	NFTConfigAddress,
	EthereumAddress,
	EthereumNodeURL,
	Password string

	BancorAPIURL string

	ConsensusThreshold float64
	GasLimit           uint64
	// contains filtered or unexported fields
}

BridgeClient is a wrapper, which exposes Ethereum KeyStore methods used by DEX bridge.

func NewBridgeClient added in v1.11.0

func NewBridgeClient(
	bridgeAddress,
	tokenAddress,
	authorizersAddress,
	uniswapAddress,
	ethereumAddress,
	ethereumNodeURL,
	password string,
	gasLimit uint64,
	consensusThreshold float64,
	ethereumClient EthereumClient,
	keyStore KeyStore) *BridgeClient

NewBridgeClient creates BridgeClient with the given parameters.

  • bridgeAddress is the address of the bridge smart contract on the Ethereum network.
  • tokenAddress is the address of the token smart contract on the Ethereum network.
  • authorizersAddress is the address of the authorizers smart contract on the Ethereum network.
  • authorizersAddress is the address of the authorizers smart contract on the Ethereum network.
  • uniswapAddress is the address of the user's ethereum wallet (on UniSwap).
  • ethereumAddress is the address of the user's ethereum wallet.
  • ethereumNodeURL is the URL of the Ethereum node.
  • password is the password for the user's ethereum wallet.
  • gasLimit is the gas limit for the transactions.
  • consensusThreshold is the consensus threshold, the minimum percentage of authorizers that need to agree on a transaction.
  • ethereumClient is the Ethereum JSON-RPC client.
  • transactionProvider provider interface for the transaction entity.
  • keyStore is the Ethereum KeyStore instance.

func SetupBridgeClientSDK added in v1.3.5

func SetupBridgeClientSDK(cfg *BridgeSDKConfig) *BridgeClient

SetupBridgeClientSDK initializes new bridge client. Meant to be used from standalone application with 0chain SDK initialized.

  • cfg is the configuration for the bridge SDK.

func (*BridgeClient) AddEthereumAuthorizer added in v1.8.17

func (b *BridgeClient) AddEthereumAuthorizer(ctx context.Context, address common.Address) (*types.Transaction, error)

AddEthereumAuthorizer Adds authorizer to Ethereum bridge. Only contract deployer can call this method

  • ctx go context instance to run the transaction
  • address Ethereum address of the authorizer

func (*BridgeClient) AddEthereumAuthorizers added in v1.8.17

func (b *BridgeClient) AddEthereumAuthorizers(configDir string)

AddEthereumAuthorizers add bridge authorizers to the Ethereum authorizers contract

  • configDir - configuration directory

func (*BridgeClient) ApproveUSDCSwap added in v1.15.0

func (b *BridgeClient) ApproveUSDCSwap(ctx context.Context, source uint64) (*types.Transaction, error)

ApproveUSDCSwap provides opportunity to approve swap operation for ERC20 tokens

  • ctx go context instance to run the transaction
  • source source amount

func (*BridgeClient) BurnWZCN added in v1.3.5

func (b *BridgeClient) BurnWZCN(ctx context.Context, amountTokens uint64) (*types.Transaction, error)

BurnWZCN Burns WZCN tokens on behalf of the 0ZCN client

  • ctx go context instance to run the transaction
  • amountTokens amount of tokens to burn

ERC20 signature: "burn(uint256,bytes)"

func (*BridgeClient) BurnZCN added in v1.3.5

func (b *BridgeClient) BurnZCN(amount uint64) (string, string, error)

BurnZCN burns ZCN tokens before conversion from ZCN to WZCN as a first step

  • ctx go context instance to run the transaction
  • amount amount of tokens to burn
  • txnfee transaction fee

func (*BridgeClient) CreateSignedTransactionFromKeyStore added in v1.8.17

func (b *BridgeClient) CreateSignedTransactionFromKeyStore(client EthereumClient, gasLimitUnits uint64) *bind.TransactOpts

CreateSignedTransactionFromKeyStore creates signed transaction from key store - client - Ethereum client - gasLimitUnits - gas limit in units

func (*BridgeClient) EstimateBurnWZCNGasAmount added in v1.13.8

func (b *BridgeClient) EstimateBurnWZCNGasAmount(ctx context.Context, from, to, amountTokens string) (float64, error)

EstimateBurnWZCNGasAmount performs gas amount estimation for the given wzcn burn transaction.

  • ctx go context instance to run the transaction
  • from source address
  • to target address
  • amountTokens amount of tokens to burn

func (*BridgeClient) EstimateGasPrice added in v1.13.4

func (b *BridgeClient) EstimateGasPrice(ctx context.Context) (float64, error)

EstimateGasPrice performs gas estimation for the given transaction.

  • ctx go context instance to run the transaction

func (*BridgeClient) EstimateMintWZCNGasAmount added in v1.13.8

func (b *BridgeClient) EstimateMintWZCNGasAmount(
	ctx context.Context, from, to, zcnTransactionRaw, amountToken string, nonceRaw int64, signaturesRaw [][]byte) (float64, error)

EstimateMintWZCNGasAmount performs gas amount estimation for the given wzcn mint transaction.

  • ctx go context instance to run the transaction
  • from source address
  • to target address
  • zcnTransactionRaw zcn transaction (hashed)
  • amountToken amount of tokens to mint
  • nonceRaw nonce
  • signaturesRaw authorizer signatures

func (*BridgeClient) GetETHSwapAmount added in v1.15.0

func (b *BridgeClient) GetETHSwapAmount(ctx context.Context, source uint64) (*big.Int, error)

GetETHSwapAmount retrieves ETH swap amount from the given source.

  • ctx go context instance to run the transaction
  • source source amount

func (*BridgeClient) GetTokenBalance added in v1.11.0

func (b *BridgeClient) GetTokenBalance() (*big.Int, error)

GetTokenBalance returns balance of the current client for the zcntoken address

func (*BridgeClient) GetUserNonceMinted added in v1.8.11

func (b *BridgeClient) GetUserNonceMinted(ctx context.Context, rawEthereumAddress string) (*big.Int, error)

GetUserNonceMinted Returns nonce for a specified Ethereum address

  • ctx go context instance to run the transaction
  • rawEthereumAddress Ethereum address

func (*BridgeClient) IncreaseBurnerAllowance added in v1.3.5

func (b *BridgeClient) IncreaseBurnerAllowance(ctx context.Context, allowanceAmount uint64) (*types.Transaction, error)

IncreaseBurnerAllowance Increases allowance for bridge contract address to transfer ERC-20 tokens on behalf of the zcntoken owner to the Burn TokenPool During the burn the script transfers amount from zcntoken owner to the bridge burn zcntoken pool Example: owner wants to burn some amount. The contract will transfer some amount from owner address to the pool. So the owner must call IncreaseAllowance of the WZCN zcntoken with 2 parameters: spender address which is the bridge contract and amount to be burned (transferred) Token signature: "increaseApproval(address,uint256)"

  • ctx go context instance to run the transaction
  • allowanceAmount amount to increase

func (*BridgeClient) MintWZCN added in v1.3.5

func (b *BridgeClient) MintWZCN(ctx context.Context, payload *ethereum.MintPayload) (*types.Transaction, error)

MintWZCN Mint ZCN tokens on behalf of the 0ZCN client

  • ctx go context instance to run the transaction
  • payload received from authorizers

ERC20 signature: "mint(address,uint256,bytes,uint256,bytes[])"

func (*BridgeClient) MintZCN added in v1.3.5

func (b *BridgeClient) MintZCN(payload *zcnsc.MintPayload) (string, error)

MintZCN mints ZCN tokens after receiving proof-of-burn of WZCN tokens

  • ctx go context instance to run the transaction
  • payload received from authorizers

func (*BridgeClient) NFTConfigGetAddress added in v1.11.0

func (b *BridgeClient) NFTConfigGetAddress(ctx context.Context, key string) (string, string, error)

NFTConfigGetAddress retrieves an address field in the NFT config, given the key as a string

  • ctx go context instance to run the transaction
  • key key for this field

func (*BridgeClient) NFTConfigGetUint256 added in v1.11.0

func (b *BridgeClient) NFTConfigGetUint256(ctx context.Context, key string, keyParam ...int64) (string, int64, error)

NFTConfigGetUint256 retrieves a uint256 field in the NFT config, given the key as a string

  • ctx go context instance to run the transaction
  • key key for this field
  • keyParam additional key parameter, only the first item is used

func (*BridgeClient) NFTConfigSetAddress added in v1.11.0

func (b *BridgeClient) NFTConfigSetAddress(ctx context.Context, key, address string) (*types.Transaction, error)

NFTConfigSetAddress sets an address field in the NFT config, given the key as a string

  • ctx go context instance to run the transaction
  • key key for this field
  • address address to set

func (*BridgeClient) NFTConfigSetUint256 added in v1.11.0

func (b *BridgeClient) NFTConfigSetUint256(ctx context.Context, key string, value int64) (*types.Transaction, error)

NFTConfigSetUint256 sets a uint256 field in the NFT config, given the key as a string

  • ctx go context instance to run the transaction
  • key key for this field
  • value value to set

func (*BridgeClient) NFTConfigSetUint256Raw added in v1.11.0

func (b *BridgeClient) NFTConfigSetUint256Raw(ctx context.Context, key common.Hash, value int64) (*types.Transaction, error)

NFTConfigSetUint256Raw sets a uint256 field in the NFT config, given the key as a Keccak256 hash

  • ctx go context instance to run the transaction
  • key key for this field (hased)
  • value value to set

func (*BridgeClient) QueryEthereumBurnEvents added in v1.8.16

func (b *BridgeClient) QueryEthereumBurnEvents(startNonce string) ([]*ethereum.BurnEvent, error)

QueryEthereumBurnEvents gets ethereum burn events

func (*BridgeClient) QueryEthereumMintPayload added in v1.3.5

func (b *BridgeClient) QueryEthereumMintPayload(zchainBurnHash string) (*ethereum.MintPayload, error)

QueryEthereumMintPayload gets burn ticket and creates mint payload to be minted in the Ethereum chain zchainBurnHash - Ethereum burn transaction hash

func (*BridgeClient) QueryZChainMintPayload added in v1.3.5

func (b *BridgeClient) QueryZChainMintPayload(ethBurnHash string) (*zcnsc.MintPayload, error)

QueryZChainMintPayload gets burn ticket and creates mint payload to be minted in the ZChain ethBurnHash - Ethereum burn transaction hash

func (*BridgeClient) RemoveEthereumAuthorizer added in v1.8.17

func (b *BridgeClient) RemoveEthereumAuthorizer(ctx context.Context, address common.Address) (*types.Transaction, error)

RemoveEthereumAuthorizer Removes authorizer from Ethereum bridge. Only contract deployer can call this method

  • ctx go context instance to run the transaction
  • address Ethereum address of the authorizer

func (*BridgeClient) ResetUserNonceMinted added in v1.11.0

func (b *BridgeClient) ResetUserNonceMinted(ctx context.Context) (*types.Transaction, error)

ResetUserNonceMinted Resets nonce for a specified Ethereum address

  • ctx go context instance to run the transaction

func (*BridgeClient) SignWithEthereumChain added in v1.3.5

func (b *BridgeClient) SignWithEthereumChain(message string) ([]byte, error)

SignWithEthereumChain signs the digest with Ethereum chain signer taking key from the current user key storage

  • message message to sign

func (*BridgeClient) SwapETH added in v1.15.0

func (b *BridgeClient) SwapETH(ctx context.Context, source uint64, target uint64) (*types.Transaction, error)

SwapETH provides opportunity to perform zcn token swap operation using ETH as source token.

  • ctx go context instance to run the transaction
  • source source amount
  • target target amount

func (*BridgeClient) SwapUSDC added in v1.15.0

func (b *BridgeClient) SwapUSDC(ctx context.Context, source uint64, target uint64) (*types.Transaction, error)

SwapUSDC provides opportunity to perform zcn token swap operation using USDC as source token.

  • ctx go context instance to run the transaction
  • source source amount
  • target target amount

type BridgeSDKConfig added in v1.3.5

type BridgeSDKConfig struct {
	LogLevel        *string
	LogPath         *string
	ConfigChainFile *string
	ConfigDir       *string
	Development     *bool
}

BridgeSDKConfig describes the configuration for the bridge SDK.

type DetailedAccount added in v1.11.0

type DetailedAccount struct {
	EthereumAddress,
	PublicKey,
	PrivateKey accounts.Account
}

DetailedAccount describes detailed account

type EthereumBurnEvents added in v1.8.16

type EthereumBurnEvents struct {
	AuthorizerID string `json:"authorizer_id,omitempty"`
	BurnEvents   []struct {
		Nonce           int64  `json:"nonce"`
		Amount          int64  `json:"amount"`
		TransactionHash string `json:"transaction_hash"`
	} `json:"burn_events"`
}

EthereumBurnEvents represents burn events returned by authorizers

func (*EthereumBurnEvents) Data added in v1.8.16

func (r *EthereumBurnEvents) Data() interface{}

func (*EthereumBurnEvents) Error added in v1.8.16

func (r *EthereumBurnEvents) Error() error

func (*EthereumBurnEvents) GetAuthorizerID added in v1.8.16

func (r *EthereumBurnEvents) GetAuthorizerID() string

func (*EthereumBurnEvents) SetAuthorizerID added in v1.8.16

func (r *EthereumBurnEvents) SetAuthorizerID(id string)

type EthereumClient added in v1.11.0

type EthereumClient interface {
	bind.ContractBackend

	ChainID(ctx context.Context) (*big.Int, error)
}

EthereumClient describes Ethereum JSON-RPC client generealized interface

type GasEstimationRequest added in v1.13.4

type GasEstimationRequest struct {
	From  string `json:"from"`
	To    string `json:"to"`
	Value string `json:"value"`
}

GasEstimationRequest describes request used for Alchemy enhanced JSON-RPC API.

type GasPriceEstimationResult added in v1.13.4

type GasPriceEstimationResult struct {
	Value float64 `json:"value"`
}

GasPriceEstimationResult represents result of the gas price estimation operation execution.

type JobError

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

JobError result of internal request wrapped in authorizer job

func (*JobError) MarshalJSON

func (e *JobError) MarshalJSON() ([]byte, error)

func (*JobError) UnmarshalJSON

func (e *JobError) UnmarshalJSON(buf []byte) error

type JobResult

type JobResult interface {
	// Error = Status of Authorizer job on authorizer server
	Error() error
	// Data returns the actual result
	Data() interface{}
	// SetAuthorizerID Assigns authorizer ID to the Job
	SetAuthorizerID(ID string)
	// GetAuthorizerID returns authorizer ID
	GetAuthorizerID() string
}

JobResult = Authorizer task result, it wraps actual result of the query inside authorizer

type JobStatus

type JobStatus uint

JobStatus = Ethereum transaction status

type KeyStore added in v1.11.0

type KeyStore interface {
	Find(accounts.Account) (accounts.Account, error)
	TimedUnlock(accounts.Account, string, time.Duration) error
	SignHash(account accounts.Account, hash []byte) ([]byte, error)
	GetEthereumKeyStore() *keystore.KeyStore
}

KeyStore is a wrapper, which exposes Ethereum KeyStore methods used by DEX bridge.

func NewKeyStore added in v1.11.0

func NewKeyStore(path string) KeyStore

NewKeyStore creates new KeyStore wrapper instance

type ProofEthereumBurn

type ProofEthereumBurn struct {
	TxnID             string `json:"ethereum_txn_id"`
	Nonce             int64  `json:"nonce"`
	Amount            int64  `json:"amount"`
	ReceivingClientID string `json:"receiving_client_id"` // 0ZCN address
	Signature         string `json:"signature"`
}

ProofEthereumBurn Authorizer returns this type for Ethereum transaction

type ProofZCNBurn

type ProofZCNBurn struct {
	AuthorizerID string `json:"authorizer_id,omitempty"`
	TxnID        string `json:"0chain_txn_id"`
	To           string `json:"to"`
	Nonce        int64  `json:"nonce"`
	Amount       int64  `json:"amount"`
	Signature    []byte `json:"signature"`
}

ProofZCNBurn Authorizer returns this type for ZCN transaction

func (*ProofZCNBurn) Data

func (r *ProofZCNBurn) Data() interface{}

func (*ProofZCNBurn) Error

func (r *ProofZCNBurn) Error() error

func (*ProofZCNBurn) GetAuthorizerID

func (r *ProofZCNBurn) GetAuthorizerID() string

func (*ProofZCNBurn) SetAuthorizerID

func (r *ProofZCNBurn) SetAuthorizerID(id string)

type WZCNBurnEvent

type WZCNBurnEvent struct {
	// 	AuthorizerID Authorizer ID
	AuthorizerID string `json:"authorizer_id,omitempty"`
	// BurnTicket Returns burn ticket
	BurnTicket *ProofEthereumBurn `json:"ticket,omitempty"`
	// Err gives error of job on server side
	Err *JobError `json:"err,omitempty"`
	// Status gives job status on server side (authoriser)
	Status JobStatus `json:"status,omitempty"`
}

WZCNBurnEvent returned from burn ticket handler of: /v1/ether/burnticket/get

func (*WZCNBurnEvent) Data

func (r *WZCNBurnEvent) Data() interface{}

func (*WZCNBurnEvent) Error

func (r *WZCNBurnEvent) Error() error

func (*WZCNBurnEvent) GetAuthorizerID

func (r *WZCNBurnEvent) GetAuthorizerID() string

func (*WZCNBurnEvent) SetAuthorizerID

func (r *WZCNBurnEvent) SetAuthorizerID(id string)

Directories

Path Synopsis
Methods and types to interact with the authorizer nodes.
Methods and types to interact with the authorizer nodes.
Methods and types to support cryptographic operations.
Methods and types to support cryptographic operations.
Error struct and functions.
Error struct and functions.
Methods and types to interact with Züs smart contracts on the Ethereum blockchain (Züs ERC20 tokens).
Methods and types to interact with Züs smart contracts on the Ethereum blockchain (Züs ERC20 tokens).
Utility methods and types to work with HTTP requests and responses.
Utility methods and types to work with HTTP requests and responses.
Logging methods and types for the ZCN bridge SDK.
Logging methods and types for the ZCN bridge SDK.
AUTOGENERATED! Do not use.
AUTOGENERATED! Do not use.
Utility functions to handle the time.
Utility functions to handle the time.
Methods and types to interact with native Züs transactions.
Methods and types to interact with native Züs transactions.
Miscellaneous utility functions.
Miscellaneous utility functions.
Methods and types to represent client's wallet.
Methods and types to represent client's wallet.
Utilities to interact with native ZCN smart contract functions.
Utilities to interact with native ZCN smart contract functions.

Jump to

Keyboard shortcuts

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