crosschain

package module
v0.0.0-...-d581f9c Latest Latest
Warning

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

Go to latest
Published: Jan 16, 2026 License: Apache-2.0, MIT Imports: 16 Imported by: 0

README ¶

Crosschain

Go Reference Coverage Status

A Go library to interact with multiple blockchains. This library is used by the Cordial Treasury custody product to interact with various blockchains securely. Cordial Treasury will be able to support any chain supported in this library.

Crosschain's main design principle is to isolate functionality into separate Client, Signer and TxBuilder interfaces.
In addition to providing unified interfaces, it allows blockchains to be safely used in secure contexts.

Example usage

First install the xc utility which will quickly demonstrate usage of the library.

go install -v ./cmd/xc/...

By default, xc, will using Cordial System's connector API to connect to blockchains. You will need an API key for this to work. Otherwise, you can easily override and supply your own standard RPC url for the target chain.

Manually interact with blockchains

Usage:
  xc [command]

Available Commands:
  address     Derive an address from the XC_PRIVATE_KEY environment variable.
  balance     Check balance of an asset.  Reported as big integer, not accounting for any decimals.
  chains      List information on all supported chains.
  completion  Generate the autocompletion script for the specified shell
  help        Help about any command
  staking     Staking commands
  transfer    Create and broadcast a new transaction transferring funds. The amount should be a decimal amount.
  tx-info     Check an existing transaction on chain.
  tx-input    Check inputs for a new transaction.

Flags:
      --api-key string    Api key to use for client (may set CORDIAL_API_KEY).
      --chain string      Chain to use. Required.
      --config string     Path to treasury.toml configuration file.
  -h, --help              help for xc
      --not-mainnet       Do not use mainnets, instead use a test or dev network.
      --provider string   Provider to use for chain client.  Only valid for BTC chains.
      --rpc string        RPC url to use. Optional.
  -v, --verbose count     Set verbosity.
Generate or import a wallet

Set XC_PRIVATE_KEY env and confirm you address is correct on the target chain you want to use.

# random 32-byte key
export XC_PRIVATE_KEY=$(cat /dev/urandom | head -c 32 | xxd -p -c100)
xc address --chain SOL
Send a transfer
xc transfer <destination-address> 0.1 -v --chain SOL

Add --contract for token transfers.

xc transfer <destination-address> 0.1 -v --chain SOL --contract EPjFWdd5AufqSSqeM2qN1xzybapC8G4wEGGkZwyTDt1v --decimals 6

Add --rpc to use your own RPC node or use a devnet or testnet network.

xc transfer <destination-address> 0.1 -v --chain SOL --rpc "https://api.devnet.solana.com"
Stake an asset

Stake 0.1 SOL on mainnet.

xc staking stake --amount 0.1 --chain SOL --rpc https://api.mainnet-beta.solana.com --validator he1iusunGwqrNtafDtLdhsUQDFvo13z9sUa36PauBtk
Download a transaction

Transactions are represented in a universal format across different chains.

xc tx-info --chain BTC b5734126a7b9f5a3a94491c7297959b74099c5c88d2f5f34ea3cb432abdf9c5e

Download another transaction from a difference chain.

xc tx-info --chain SOL 2NNSwe5ZCHx1SuYfgqy1pyWxDCfEcge3H4Eak1KyGCctjJictYtkQ4FFRH7CMJHM1W55FnyBmtKrxdZzkkThkjVL
Lookup a balance

Get ether balance (in wei).

xc balance 0x95222290DD7278Aa3Ddd389Cc1E1d165CC4BAfe5 --chain ETH

Add --contract to see a token balance.

xc balance 0x95222290DD7278Aa3Ddd389Cc1E1d165CC4BAfe5 --chain ETH --contract 0xa0b86991c6218b36c1d19d4a2e9eb0ce3606eb48
Lookup transaction input

This looks up all of the necessary inputs needed to serialize a transaction on a given blockchain. The values for the "input" depends on each chain. Normally this is providing account sequences, gas fees, or unspent outputs.

xc tx-input <from-address> --chain ETH
xc tx-input 0x95222290DD7278Aa3Ddd389Cc1E1d165CC4BAfe5 --chain ETH

Features

Blockchains
  • Aptos
  • Bitcoin
  • Bitcoin derived: Bitcoin Cash, Dogecoin
  • Bittensor
  • Cosmos
  • Cosmos derived: Terra, Injective, XPLA, ...
  • Ethereum
  • EVMs: Polygon, Binance Smart Chain, ...
  • Filecoin
  • Polkadot
  • Solana
  • Sui
  • TON
  • Tron
  • XRP
Assets
  • Native assets
  • Tokens
  • Staked assets
  • NFTs
  • Liquidity pools
Operations
  • Balances (native asset, tokens)
  • Transfers (native transfers, token transfers)
  • Transaction reporting
  • Wraps/unwraps: ETH, SOL (partial support)
  • Staking/unstaking
Devnet nodes

You can spin up your own devnet nodes + universal faucet API for testing.

Example on EVM:

# build and run container
cd chain/evm/node && docker build -t devnet-evm .
devnet-evm
docker run --name devnet-evm -p 10000:10000 -p 10001:10001 devnet-evm

Fund some asset onto an address using the faucet:

curl -X POST -d '{"amount": 1234, "address": "0x0000000000000000000000000000000000001234"}' localhost:10001/chains/ETH/assets/ETH

Query the devnet node:

curl localhost:10000 -X POST \
  --data '{"method":"eth_getBalance","params":["0x0000000000000000000000000000000000001234", "latest"],"id":1,"jsonrpc":"2.0"}'

Contribute

We welcome contribution, whether in form of bug fixed, documentation, new chains, new functionality.

To add a new chain, we recommend you first study existing implementations in chains/. Normally it's easiest to start with the client methods (reporting a balance), and then incrementally get to building a transaction and broadcasting it.

Just open an issue to discuss what you'd like to contribute and then submit a PR.

Notes

Ed25519 Signing

To support compatibility with recovered Ed25519 keys from MPC products like Cordial Treasury, signing can be configured to treat the key as a raw scalar, rather than a standard ed25519 "seed".

To enable this, set env XC_SIGN_WITH_SCALAR=1.

# The scalar must be 32 bytes
export XC_PRIVATE_KEY=$(cat scalar.bin | xxd -p -c 512)
export XC_SIGN_WITH_SCALAR=1

xc transfer ...
Cross-platform builds

OrbStack has been used to build cross-platform images (make build-push-images), as Docker Desktop as some issues.

Documentation ¶

Overview ¶

Package crosschain is a Go library to interact with multiple blockchains.

Crosschain main design principle is to isolate network Client, Signer and tx Builder. This way you can build applications or micro services using just what you need and with the convenience of a unified interface.

Index ¶

Constants ¶

View Source
const (
	K256Keccak        = SignatureType("k256-keccak")
	K256Sha256        = SignatureType("k256-sha256")
	Ed255             = SignatureType("ed255")
	Schnorr           = SignatureType("schnorr")
	Bls12_381G2Blake2 = SignatureType("bls12-381-g2-blake2")
)
View Source
const (
	ACA      = NativeAsset("ACA")      // Acala
	ADA      = NativeAsset("ADA")      // Cardano
	AKT      = NativeAsset("AKT")      // Akash
	APTOS    = NativeAsset("APTOS")    // APTOS
	ArbETH   = NativeAsset("ArbETH")   // Arbitrum
	ASTR     = NativeAsset("ASTR")     // Astar
	ATOM     = NativeAsset("ATOM")     // Cosmos
	AurETH   = NativeAsset("AurETH")   // Aurora
	AVAX     = NativeAsset("AVAX")     // Avalanche
	BAND     = NativeAsset("BAND")     // Band
	BASE     = NativeAsset("BASE")     // BASE
	BABY     = NativeAsset("BABY")     // Babylon
	BERA     = NativeAsset("BERA")     // Berachain
	BCH      = NativeAsset("BCH")      // Bitcoin Cash
	BNB      = NativeAsset("BNB")      // Binance Coin
	BTC      = NativeAsset("BTC")      // Bitcoin
	CELO     = NativeAsset("CELO")     // Celo
	CHZ      = NativeAsset("CHZ")      // Chiliz
	CHZ2     = NativeAsset("CHZ2")     // Chiliz 2.0
	DASH     = NativeAsset("DASH")     // Dash
	DOGE     = NativeAsset("DOGE")     // Dogecoin
	DOT      = NativeAsset("DOT")      // Polkadot
	DUSK     = NativeAsset("DUSK")     // Dusk
	ENJ      = NativeAsset("ENJ")      // Enjin
	EOS      = NativeAsset("EOS")      // EOS
	ES       = NativeAsset("ES")       // Eclipse
	ETC      = NativeAsset("ETC")      // Ethereum Classic
	ETH      = NativeAsset("ETH")      // Ethereum
	ETHW     = NativeAsset("ETHW")     // Ethereum PoW
	FIL      = NativeAsset("FIL")      // Filecoin
	FLUX     = NativeAsset("FLUX")     // Flux
	FOGO     = NativeAsset("FOGO")     // Fogo
	FTM      = NativeAsset("FTM")      // Fantom
	FRAX     = NativeAsset("FRAX")     // Frax
	GUSDT    = NativeAsset("GUSDT")    // Stable
	HASH     = NativeAsset("HASH")     // Provenance
	HBAR     = NativeAsset("HBAR")     // Hedera
	HyperEVM = NativeAsset("HyperEVM") // HyperEVM (Hyperliquid)
	HYPE     = NativeAsset("HYPE")     // Hyperliquid
	INJ      = NativeAsset("INJ")      // Injective
	LinETH   = NativeAsset("LinETH")   // Linea
	LTC      = NativeAsset("LTC")      // Litecoin
	LUNA     = NativeAsset("LUNA")     // Terra V2
	LUNC     = NativeAsset("LUNC")     // Terra Classic
	KAR      = NativeAsset("KAR")      // Karura
	KAS      = NativeAsset("KAS")      // Kaspa
	KAVA     = NativeAsset("KAVA")     // Kava
	KLAY     = NativeAsset("KLAY")     // Klaytn
	KSM      = NativeAsset("KSM")      // Kusama
	MATIC    = NativeAsset("MATIC")    // Polygon
	MON      = NativeAsset("MON")      // MONAD
	NEAR     = NativeAsset("NEAR")     // Near
	NOBLE    = NativeAsset("NOBLE")    // Noble Chain
	OAS      = NativeAsset("OAS")      // Oasys (not Oasis!)
	OptETH   = NativeAsset("OptETH")   // Optimism
	EmROSE   = NativeAsset("EmROSE")   // Rose (Oasis EVM-compat "Emerald" parachain)
	SOL      = NativeAsset("SOL")      // Solana
	SUI      = NativeAsset("SUI")      // SUI
	XPLA     = NativeAsset("XPLA")     // XPLA
	TAO      = NativeAsset("TAO")      // Bittensor
	TEMPO    = NativeAsset("TEMPO")    // Tempo
	TIA      = NativeAsset("TIA")      // celestia
	TON      = NativeAsset("TON")      // TON
	TRX      = NativeAsset("TRX")      // TRON
	SEI      = NativeAsset("SEI")      // Sei
	SeiEVM   = NativeAsset("SeiEVM")   // SeiEVM
	XDC      = NativeAsset("XDC")      // XinFin
	XPL      = NativeAsset("XPL")      // Plasma
	XRP      = NativeAsset("XRP")      // XRP
	XLM      = NativeAsset("XLM")      // XLM
	ZETA     = NativeAsset("ZETA")     // ZetaChain
	NIL      = NativeAsset("NIL")      // Nillion
	ICP      = NativeAsset("ICP")      // Internet Computer Protocol
	ZEC      = NativeAsset("ZEC")      // Zcash
	ZeroG    = NativeAsset("0G")       // 0g
)

List of supported NativeAsset

View Source
const (
	DriverAptos                    = Driver("aptos")
	DriverBitcoin                  = Driver("bitcoin")
	DriverBitcoinCash              = Driver("bitcoin-cash")
	DriverBitcoinLegacy            = Driver("bitcoin-legacy")
	DriverCardano                  = Driver("cardano")
	DriverCosmos                   = Driver("cosmos")
	DriverCosmosEvmos              = Driver("evmos")
	DriverDusk                     = Driver("dusk")
	DriverEOS                      = Driver("eos")
	DriverEVM                      = Driver("evm")
	DriverEVMLegacy                = Driver("evm-legacy")
	DriverFilecoin                 = Driver("filecoin")
	DriverHedera                   = Driver("hedera")
	DriverHyperliquid              = Driver("hyperliquid")
	DriverInternetComputerProtocol = Driver("icp")
	DriverKaspa                    = Driver("kaspa")
	DriverNear                     = Driver("near")
	DriverSubstrate                = Driver("substrate")
	DriverSolana                   = Driver("solana")
	DriverSui                      = Driver("sui")
	DriverTron                     = Driver("tron")
	DriverTon                      = Driver("ton")
	DriverXrp                      = Driver("xrp")
	DriverXlm                      = Driver("xlm")
	DriverZcash                    = Driver("zcash")
	// Crosschain is a client-only driver
	DriverCrosschain = Driver("crosschain")
)

List of supported Driver

View Source
const FLOAT_PRECISION = 6

Variables ¶

View Source
var SupportedStakingProviders = []StakingProvider{
	Native,
	Kiln,
	Figment,
	Twinstake,
}

Functions ¶

func CheckFeeLimit ¶

func CheckFeeLimit(input TxInput, chainConfig *ChainConfig) error

Check against the max-fee defaults in the configuration. Custody products should have a way to override max-fee limits.

func IsTypeOf ¶

func IsTypeOf(input TxInput, validTypes ...any) bool

Types ¶

type AdditionalNativeAsset ¶

type AdditionalNativeAsset struct {
	// The asset ID of the asset to use
	AssetId string `yaml:"asset_id,omitempty"`
	// The native asset that this bridged asset corresponds to or settles in (e.g., "chains/ETH/assets/ETH" for OptEth or Eclipse)
	BridgedAsset string `yaml:"bridged_asset,omitempty"`
	// The on-chain contract ID of the asset
	ContractId ContractAddress `yaml:"contract_id,omitempty"`
	// Decimals for the asset
	Decimals int32 `yaml:"decimals,omitempty"`
	// Maximum fee limit
	FeeLimit AmountHumanReadable `yaml:"fee_limit"`
	Aliases  []string            `yaml:"aliases,omitempty"`
}

func NewAdditionalNativeAsset ¶

func NewAdditionalNativeAsset(assetId, bridgedAsset string, contractId ContractAddress, decimals int32, feeLimit AmountHumanReadable, aliases ...string) *AdditionalNativeAsset

func (*AdditionalNativeAsset) HasAlias ¶

func (na *AdditionalNativeAsset) HasAlias(alias string) bool

type Address ¶

type Address string

Address is an address on the blockchain, either sender or recipient

type AddressBuilder ¶

type AddressBuilder interface {
	GetAddressFromPublicKey(publicKeyBytes []byte) (Address, error)
}

AddressBuilder is the interface for building addresses

type AddressBuilderWithFormats ¶

type AddressBuilderWithFormats interface {
	// Returns the signature algorithm to be used for a given address format
	GetSignatureAlgorithm() SignatureType
}

type AddressConfig ¶

type AddressConfig struct {
	// All formats supported by chain, including default
	Formats []AddressFormat `yaml:"formats,omitempty"`
}

Optional address configuration

type AddressFormat ¶

type AddressFormat string

Address format is a format of an addres, in case the chain support multiple formats

type AmountBlockchain ¶

type AmountBlockchain big.Int

AmountBlockchain is a big integer amount as blockchain expects it for tx.

func MultiplyByFloat ¶

func MultiplyByFloat(amount AmountBlockchain, multiplier float64) AmountBlockchain

func NewAmountBlockchainFromInt64 ¶

func NewAmountBlockchainFromInt64(i64 int64) (AmountBlockchain, bool)

NewAmountBlockchainFromUint64 creates a new AmountBlockchain from a uint64

func NewAmountBlockchainFromStr ¶

func NewAmountBlockchainFromStr(str string) AmountBlockchain

NewAmountBlockchainFromStr creates a new AmountBlockchain from a string

func NewAmountBlockchainFromUint64 ¶

func NewAmountBlockchainFromUint64(u64 uint64) AmountBlockchain

NewAmountBlockchainFromUint64 creates a new AmountBlockchain from a uint64

func NewAmountBlockchainToMaskFloat64 ¶

func NewAmountBlockchainToMaskFloat64(f64 float64) AmountBlockchain

NewAmountBlockchainToMaskFloat64 creates a new AmountBlockchain as a float64 times 10^FLOAT_PRECISION

func (*AmountBlockchain) Abs ¶

func (amount *AmountBlockchain) Abs() AmountBlockchain

func (*AmountBlockchain) Add ¶

Use the underlying big.Int.Add()

func (AmountBlockchain) ApplyGasPriceMultiplier ¶

func (amount AmountBlockchain) ApplyGasPriceMultiplier(chain *ChainClientConfig) AmountBlockchain

func (AmountBlockchain) ApplySecondaryGasPriceMultiplier ¶

func (amount AmountBlockchain) ApplySecondaryGasPriceMultiplier(chain *ChainClientConfig) AmountBlockchain

func (AmountBlockchain) Bytes ¶

func (amount AmountBlockchain) Bytes() []byte

func (*AmountBlockchain) Cmp ¶

func (amount *AmountBlockchain) Cmp(other *AmountBlockchain) int

Use the underlying big.Int.Cmp()

func (*AmountBlockchain) Div ¶

Use the underlying big.Int.Div()

func (AmountBlockchain) Int ¶

func (amount AmountBlockchain) Int() *big.Int

Int converts an AmountBlockchain into *bit.Int

func (*AmountBlockchain) IsZero ¶

func (amount *AmountBlockchain) IsZero() bool

func (AmountBlockchain) MarshalJSON ¶

func (b AmountBlockchain) MarshalJSON() ([]byte, error)

func (*AmountBlockchain) Mul ¶

Use the underlying big.Int.Mul()

func (AmountBlockchain) Sign ¶

func (amount AmountBlockchain) Sign() int

func (AmountBlockchain) String ¶

func (amount AmountBlockchain) String() string

func (*AmountBlockchain) Sub ¶

Use the underlying big.Int.Sub()

func (*AmountBlockchain) ToHuman ¶

func (amount *AmountBlockchain) ToHuman(decimals int32) AmountHumanReadable

func (AmountBlockchain) Uint64 ¶

func (amount AmountBlockchain) Uint64() uint64

Uint64 converts an AmountBlockchain into uint64

func (*AmountBlockchain) UnmarshalJSON ¶

func (b *AmountBlockchain) UnmarshalJSON(p []byte) error

func (AmountBlockchain) UnmaskFloat64 ¶

func (amount AmountBlockchain) UnmaskFloat64() float64

UnmaskFloat64 converts an AmountBlockchain into float64 given the number of decimals

type AmountHumanReadable ¶

type AmountHumanReadable decimal.Decimal

AmountHumanReadable is a decimal amount as a human expects it for readability.

func NewAmountHumanReadableFromBlockchain ¶

func NewAmountHumanReadableFromBlockchain(amt AmountBlockchain) AmountHumanReadable

NewAmountHumanReadableFromBlockchain creates a new AmountHumanReadable from an AmountBlockchain

func NewAmountHumanReadableFromFloat ¶

func NewAmountHumanReadableFromFloat(float float64) AmountHumanReadable

NewAmountHumanReadableFromFloat creates a new AmountHumanReadable from a float

func NewAmountHumanReadableFromStr ¶

func NewAmountHumanReadableFromStr(str string) (AmountHumanReadable, error)

NewAmountHumanReadableFromStr creates a new AmountHumanReadable from a string

func (AmountHumanReadable) Cmp ¶

func (AmountHumanReadable) Decimal ¶

func (amount AmountHumanReadable) Decimal() decimal.Decimal

func (AmountHumanReadable) Div ¶

func (AmountHumanReadable) IsZero ¶

func (b AmountHumanReadable) IsZero() bool

func (AmountHumanReadable) MarshalJSON ¶

func (b AmountHumanReadable) MarshalJSON() ([]byte, error)

func (AmountHumanReadable) MarshalYAML ¶

func (b AmountHumanReadable) MarshalYAML() (interface{}, error)

func (AmountHumanReadable) Mul ¶

func (AmountHumanReadable) String ¶

func (amount AmountHumanReadable) String() string

func (AmountHumanReadable) ToBlockchain ¶

func (amount AmountHumanReadable) ToBlockchain(decimals int32) AmountBlockchain

func (*AmountHumanReadable) UnmarshalJSON ¶

func (b *AmountHumanReadable) UnmarshalJSON(p []byte) error

func (*AmountHumanReadable) UnmarshalYAML ¶

func (b *AmountHumanReadable) UnmarshalYAML(node *yaml.Node) error

type CallTxInput ¶

type CallTxInput interface {
	TxVariantInput
	Calling()
}

type ChainBaseConfig ¶

type ChainBaseConfig struct {
	// The crosschain symbol of the chain
	Chain NativeAsset `yaml:"chain,omitempty"`
	// The driver to use for the chain
	Driver Driver `yaml:"driver,omitempty"`
	// The network selector, if necessary (e.g. select mainnet, testnet, or devnet for bitcoin chains)
	Network string `yaml:"net,omitempty"`
	// Decimals for the chain's native asset (if it has one).
	Decimals int32 `yaml:"decimals,omitempty"`

	// The ChainID of the chain, either in integer or string format
	ChainID StringOrInt `yaml:"chain_id,omitempty"`

	// Human readable name of the chain, e.g. "Bitcoin"
	ChainName string `yaml:"chain_name,omitempty"`

	// Does the chain use a special prefix for it's address?
	// E.g. most cosmos chains do this.
	ChainPrefix StringOrInt `yaml:"chain_prefix,omitempty"`

	// If the chain has a native asset, and it has an actual contract address, it should be set here.
	// This is also referred to as the "ContractID".
	// E.g.
	// - APTOS has 0x1::aptos_coin::AptosCoin
	// - INJ has inj
	// - HASH has nhash
	// - LUNA has uluna
	ChainCoin string `yaml:"chain_coin,omitempty"`
	// Additional native assets that may be used to pay fees on the chain.
	NativeAssets []*AdditionalNativeAsset `yaml:"native_assets,omitempty"`
	// If true, then the `.Chain` does not represent any native asset (i.e. no chain-coin, no decimals).
	NoNativeAsset bool `yaml:"no_native_asset,omitempty"`

	// If necessary, specific which asset to use to spend for gas.
	GasCoin string `yaml:"gas_coin,omitempty"`

	// Indicate if this chain should not be included.
	Disabled *bool `yaml:"disabled,omitempty"`

	// Staking configuration
	Staking StakingConfig `yaml:"staking,omitempty"`

	// Maximum total fee limit: required for caller to make use of with `TxInput.GetFeeLimit()`
	FeeLimit AmountHumanReadable `yaml:"fee_limit,omitempty"`

	// Transfer tax is percentage that the network takes from every transfer .. only used so far for Terra Classic
	ChainTransferTax float64 `yaml:"chain_transfer_tax,omitempty"`

	// Used only for deriving private keys from mnemonic phrases in local testing
	ChainCoinHDPath uint32 `yaml:"chain_coin_hd_path,omitempty"`

	// Should use `ChainID` instead
	XChainIDStr string `yaml:"chain_id_str,omitempty"`

	// Optional address configuration
	Address AddressConfig `yaml:"address,omitempty"`
}

type ChainClientConfig ¶

type ChainClientConfig struct {
	URL          string `yaml:"url,omitempty"`
	SecondaryURL string `yaml:"secondary_url,omitempty"`

	// Set a secret reference, see config/secret.go.  Used for setting an API keys.
	Auth2 config.Secret `yaml:"auth,omitempty"`

	// Optional configuration of the Driver.  Some chains support different kinds of RPC.
	Provider         string                 `yaml:"provider,omitempty"`
	CrosschainClient CrosschainClientConfig `yaml:"crosschain_client"`

	// Does the chain rely on an indexer in addition to RPC?  If so, the URL and type
	// may be set here.
	IndexerUrl  string `yaml:"indexer_url,omitempty"`
	IndexerType string `yaml:"indexer_type,omitempty"`
	// Maximun depth to scan for transaction, if there is no index to use (substrate...)
	MaxScanDepth int `yaml:"max_scan_depth,omitempty"`

	NoGasFees bool `yaml:"no_gas_fees,omitempty"`

	// Default gas budget to use for client gas estimation
	GasBudgetDefault AmountHumanReadable `yaml:"gas_budget_default,omitempty"`
	// Gas budget that cannot be exceeded below
	GasBudgetMinimum AmountHumanReadable `yaml:"gas_budget_min,omitempty"`
	// A remainder balance (e.g. rent threshold) that must be maintained after a transfer.
	ReserveAmount AmountHumanReadable `yaml:"reserve_amount,omitempty"`
	// A default for clients to gas price if there's not better way to estimate.
	ChainGasPriceDefault float64 `yaml:"chain_gas_price_default,omitempty"`
	// A local multiplier for client to apply to gas estimation, if it's important/needed.
	ChainGasMultiplier          float64 `yaml:"chain_gas_multiplier,omitempty"`
	SecondaryChainGasMultiplier float64 `yaml:"secondary_chain_gas_multiplier,omitempty"`
	// for gas estimation of gas limit, for somechains the simulation may be flaky and need a multiplier
	ChainGasLimitMultiplier float64 `yaml:"chain_gas_limit_multiplier,omitempty"`
	// The multiplier to apply to gas when there is a minimum replacement increase.
	// This is used for EVM chains, to avoid the "replacement transaction underpriced" message.
	// Normally it is 10%, but on chains like Base and Optimism, it seems to be at least 25% in practice.
	ReplacementTransactionMultiplier float64 `yaml:"replacement_transaction_multiplier,omitempty"`
	// The max/min prices can be set to provide sanity limits for what a gas price (per gas or per byte) should be.
	// This should be in the blockchain amount.
	ChainMaxGasPrice float64 `yaml:"chain_max_gas_price,omitempty"`
	ChainMinGasPrice float64 `yaml:"chain_min_gas_price,omitempty"`
	// Default gas limit for transactions
	GasLimitDefault int `yaml:"gas_limit_default,omitempty"`
	// TransactionActiveTime specifies the duration for which a transaction remains valid after being submitted.
	// The value is represented as a `time.Duration` string.
	// This field is currently used only by the Stellar network.
	//
	// Example format: "30s" (30 seconds), "2m" (2 minutes), "1h" (1 hour).
	TransactionActiveTime time.Duration `yaml:"transaction_active_time,omitempty"`
	// How many confirmations is considered "final" for this chain?
	XConfirmationsFinal int                 `yaml:"confirmations_final,omitempty"`
	Confirmations       ConfirmationsConfig `yaml:"confirmations,omitempty"`

	// Gas price oracle address
	// Currently this is used for EVM L2 chains that have an additional "l1" fee.
	GasPriceOracleAddress string `yaml:"gas_price_oracle_address,omitempty"`

	// Rate limit setting on RPC requests for client, in requests/second.
	RateLimit rate.Limit `yaml:"rate_limit,omitempty"`
	// Period between requests (alternative to `rate_limit`)
	PeriodLimit time.Duration `yaml:"period_limit,omitempty"`
	// Number of requests to permit in burst
	Burst int `yaml:"burst,omitempty"`

	// Rate limiter configured from `rate_limit`, `period_limit`, `burst` (requires calling .Configure after loading from config)
	Limiter *rate.Limiter `yaml:"-" mapstructure:"-"`
	// HTTP timeout for the client (will default to global factory configuration)
	HttpTimeout time.Duration `yaml:"http_timeout,omitempty"`

	// Additional metadata.  Not Used in crosschain itself, but helpful to enrich API endpoints.
	External External `yaml:"external,omitempty"`
	// Informational URLs for the chain explorers.
	ExplorerUrls ExplorerUrls `yaml:"explorer_urls,omitempty"`
	// If true, this means that the chain is not intended for future use and
	// is only maintained for legacy purposes (by the upstream community).
	// E.g. "Terra Classic" or "Fantom" are legacy chains that each have replacements.
	Legacy bool `yaml:"legacy,omitempty"`
	// Indicate to the driver if additional information should be included for older crosschain clients.
	IncludeLegacyInformation bool `yaml:"include_legacy_information,omitempty"`
	// If true, the client will only use confirmed UTXOs for unspent output queries.
	ConfirmedUtxo bool `yaml:"confirmed_utxo,omitempty"`
}

func (*ChainClientConfig) Configure ¶

func (chain *ChainClientConfig) Configure()

func (*ChainClientConfig) NewClientLimiter ¶

func (chain *ChainClientConfig) NewClientLimiter() *rate.Limiter

type ChainConfig ¶

type ChainConfig struct {
	*ChainBaseConfig   `yaml:",inline"`
	*ChainClientConfig `yaml:",inline"`
}

func NewChainConfig ¶

func NewChainConfig(nativeAsset NativeAsset, driverMaybe ...Driver) *ChainConfig

func (*ChainConfig) Base ¶

func (chain *ChainConfig) Base() *ChainBaseConfig

func (*ChainConfig) Client ¶

func (chain *ChainConfig) Client() *ChainClientConfig

func (*ChainConfig) ClientURL ¶

func (native *ChainConfig) ClientURL() (string, Driver)

Returns URL and driver used for the client. This will either Be the chain driver, or the 'special' crosschain driver.

func (*ChainConfig) Configure ¶

func (chain *ChainConfig) Configure(httpTimeout time.Duration)

func (*ChainConfig) DefaultHttpClient ¶

func (chain *ChainConfig) DefaultHttpClient() *http.Client

func (*ChainConfig) FindAdditionalNativeAsset ¶

func (native *ChainConfig) FindAdditionalNativeAsset(contract ContractAddress) (*AdditionalNativeAsset, bool)

func (*ChainConfig) GetAssetSymbol ¶

func (native *ChainConfig) GetAssetSymbol() string

func (*ChainConfig) GetChain ¶

func (asset *ChainConfig) GetChain() *ChainConfig

func (*ChainConfig) GetContract ¶

func (native *ChainConfig) GetContract() string

func (*ChainConfig) GetDecimals ¶

func (asset *ChainConfig) GetDecimals() int32

func (*ChainConfig) IsChain ¶

func (native *ChainConfig) IsChain(contract ContractAddress) bool

func (ChainConfig) String ¶

func (c ChainConfig) String() string

func (*ChainConfig) WithAuth ¶

func (chain *ChainConfig) WithAuth(auth config.Secret) *ChainConfig

func (*ChainConfig) WithChainCoin ¶

func (chain *ChainConfig) WithChainCoin(chainCoin string) *ChainConfig

func (*ChainConfig) WithChainID ¶

func (chain *ChainConfig) WithChainID(chainID string) *ChainConfig

func (*ChainConfig) WithChainPrefix ¶

func (chain *ChainConfig) WithChainPrefix(chainPrefix string) *ChainConfig

func (*ChainConfig) WithDecimals ¶

func (chain *ChainConfig) WithDecimals(decimals int32) *ChainConfig

func (*ChainConfig) WithDriver ¶

func (chain *ChainConfig) WithDriver(driver Driver) *ChainConfig

func (*ChainConfig) WithFeeLimit ¶

func (chain *ChainConfig) WithFeeLimit(feeLimit AmountHumanReadable) *ChainConfig

func (*ChainConfig) WithGasBudgetDefault ¶

func (chain *ChainConfig) WithGasBudgetDefault(gasBudgetDefault AmountHumanReadable) *ChainConfig

func (*ChainConfig) WithGasPriceMultiplier ¶

func (chain *ChainConfig) WithGasPriceMultiplier(multiplier float64) *ChainConfig

func (*ChainConfig) WithHttpTimeout ¶

func (chain *ChainConfig) WithHttpTimeout(httpTimeout time.Duration) *ChainConfig

func (*ChainConfig) WithIndexer ¶

func (chain *ChainConfig) WithIndexer(indexerType string, url string) *ChainConfig

func (*ChainConfig) WithMaxGasPrice ¶

func (chain *ChainConfig) WithMaxGasPrice(maxGasPrice float64) *ChainConfig

func (*ChainConfig) WithMinGasPrice ¶

func (chain *ChainConfig) WithMinGasPrice(minGasPrice float64) *ChainConfig

func (*ChainConfig) WithNet ¶

func (chain *ChainConfig) WithNet(net string) *ChainConfig

func (*ChainConfig) WithProvider ¶

func (chain *ChainConfig) WithProvider(provider string) *ChainConfig

func (*ChainConfig) WithTransactionActiveTime ¶

func (chain *ChainConfig) WithTransactionActiveTime(transactionActiveTime time.Duration) *ChainConfig

func (*ChainConfig) WithUrl ¶

func (chain *ChainConfig) WithUrl(url string) *ChainConfig

type ClientConfig ¶

type ClientConfig struct {
	Driver   Driver          `yaml:"driver"`
	URL      string          `yaml:"url,omitempty"`
	Auth     string          `yaml:"auth,omitempty"`
	Provider string          `yaml:"provider,omitempty"`
	Network  NetworkSelector `yaml:"network,omitempty"`
}

ClientConfig is the model used to represent a client inside an AssetConfig

type ConfirmationsConfig ¶

type ConfirmationsConfig struct {
	Final   int `yaml:"final,omitempty"`
	Tracked int `yaml:"tracked,omitempty"`
}

type ContractAddress ¶

type ContractAddress Address

ContractAddress is a smart contract address

type CrosschainClientConfig ¶

type CrosschainClientConfig struct {
	Url     string          `yaml:"url"`
	Network NetworkSelector `yaml:"network,omitempty"`
}

type Driver ¶

type Driver string

Driver is the type of a chain

func (Driver) PublicKeyFormat ¶

func (driver Driver) PublicKeyFormat() PublicKeyFormat

func (Driver) SignatureAlgorithms ¶

func (driver Driver) SignatureAlgorithms() []SignatureType

Returns the signature algorithms supported by the driver The first algorithm will be used as the default.

type ExplorerUrls ¶

type ExplorerUrls struct {
	Tx      string `yaml:"tx"`
	Address string `yaml:"address"`
	Token   string `yaml:"token"`
}

type External ¶

type External struct {
	Dti string `yaml:"dti,omitempty"`

	CoinMarketCap struct {
		// CoinMarketCap's ID for the chain
		ChainId string `yaml:"chain_id,omitempty"`
		// CoinMarketCap's ID for the chain's native asset, also called "UCID"
		AssetId string `yaml:"asset_id,omitempty"`
	} `yaml:"coin_market_cap,omitempty"`
	CoinGecko struct {
		// TODO: is there a chain ID for coingecko?
		ChainId string `yaml:"chain_id,omitempty"`
		// Coingecko's asset ID, if relevant
		AssetId string `yaml:"asset_id,omitempty"`
	} `yaml:"coin_gecko,omitempty"`
	IndexingCo struct {
		ChainId  string `yaml:"chain_id,omitempty"`
		Disabled bool   `yaml:"disabled,omitempty"`
	} `yaml:"indexing_co,omitempty"`
}

External ID's used by other vendors for the given chain

type GasFeePriority ¶

type GasFeePriority string
var Aggressive GasFeePriority = "aggressive"
var Low GasFeePriority = "low"
var Market GasFeePriority = "market"
var VeryAggressive GasFeePriority = "very-aggressive"

func NewPriority ¶

func NewPriority(input string) (GasFeePriority, error)

func (GasFeePriority) AsCustom ¶

func (p GasFeePriority) AsCustom() (decimal.Decimal, error)

func (GasFeePriority) GetDefault ¶

func (p GasFeePriority) GetDefault() (decimal.Decimal, error)

func (GasFeePriority) IsEnum ¶

func (p GasFeePriority) IsEnum() bool

type ITask ¶

type ITask interface {
	GetChain() *ChainConfig
	GetDecimals() int32

	// Informational / debugging
	String() string
}

type MultiTransferInput ¶

type MultiTransferInput interface {
	TxVariantInput
	MultiTransfer()
}

Markers for each type of Variant Tx

type NativeAsset ¶

type NativeAsset string

NativeAsset is an asset on a blockchain used to pay gas fees. In Crosschain, for simplicity, a NativeAsset represents a chain.

func (NativeAsset) Driver ¶

func (native NativeAsset) Driver() Driver

func (NativeAsset) IsValid ¶

func (native NativeAsset) IsValid() bool

type NetworkSelector ¶

type NetworkSelector string

Network selector is used by crosschain client to select which network of a blockchain to select.

const Mainnets NetworkSelector = ""
const NotMainnets NetworkSelector = "!mainnet"

type PublicKeyFormat ¶

type PublicKeyFormat string
var Compressed PublicKeyFormat = "compressed"
var Raw PublicKeyFormat = "raw"
var Uncompressed PublicKeyFormat = "uncompressed"

type SignatureRequest ¶

type SignatureRequest struct {
	// Required: The payload to sign
	Payload []byte
	// May be optionally set, if different from the from-address.
	Signer Address
}

func NewSignatureRequest ¶

func NewSignatureRequest(payload []byte, signerMaybe ...Address) *SignatureRequest

type SignatureResponse ¶

type SignatureResponse struct {
	// Signaure of the payload
	Signature TxSignature
	// Address + public key of the signer
	PublicKey []byte
	Address   Address
}

type SignatureType ¶

type SignatureType string

type StakeTxInput ¶

type StakeTxInput interface {
	TxVariantInput
	Staking()
}

type StakingConfig ¶

type StakingConfig struct {
	// the contract used for staking, if relevant
	StakeContract string `yaml:"stake_contract,omitempty"`
	// the contract used for unstaking, if relevant
	UnstakeContract string `yaml:"unstake_contract,omitempty"`
	// Compatible providers for staking
	Providers []StakingProvider `yaml:"providers,omitempty"`
}

func (*StakingConfig) Enabled ¶

func (staking *StakingConfig) Enabled() bool

type StakingProvider ¶

type StakingProvider string
const Figment StakingProvider = "figment"
const Kiln StakingProvider = "kiln"
const Native StakingProvider = "native"
const Twinstake StakingProvider = "twinstake"

func (StakingProvider) Valid ¶

func (stakingProvider StakingProvider) Valid() bool

type StringOrInt ¶

type StringOrInt string

func (StringOrInt) AsInt ¶

func (s StringOrInt) AsInt() (uint64, bool)

func (StringOrInt) AsString ¶

func (s StringOrInt) AsString() string

type Tx ¶

type Tx interface {
	Hash() TxHash
	Sighashes() ([]*SignatureRequest, error)
	SetSignatures(...*SignatureResponse) error
	Serialize() ([]byte, error)
}

Tx is a transaction

type TxAdditionalSighashes ¶

type TxAdditionalSighashes interface {
	// This is available in case a transaction needs to make signatures-over-signatures.
	// This should return any _remaining_ signatures requests left to fill.
	// The caller will always call .SetSignatures() after this with all of the signature made so far.
	AdditionalSighashes() ([]*SignatureRequest, error)
}

type TxCall ¶

type TxCall interface {
	Tx
	// Set transaction input.  This may not be needed, but could be used to adjust:
	// * fees
	// * other dynamic chain information not included in the origin Call message
	SetInput(input CallTxInput) error

	// List of addresses that may be needed to sign
	SigningAddresses() []Address

	// List of 3rd party contract addresses that this Call resource interacts with
	// (omit native system contracts)
	ContractAddresses() []ContractAddress

	// Get original serialized message that Call was constructed with
	GetMsg() json.RawMessage
}

type TxHash ¶

type TxHash string

TxHash is a tx hash or id

type TxInput ¶

TxInput is input data to a tx. Depending on the blockchain it can include nonce, recent block hash, account id, ...

type TxInputConflicts ¶

type TxInputConflicts interface {
	// Test independence of two tx-inputs, assuming the same address is used.
	// Examples:
	// - using the same nonce or sequence is NOT independent
	// - spending the same resources or utxo's is NOT independent
	// - solana (using recent_block_hash) is pretty much always independent
	// This is used to determine if a transaction needs to be queued or if it can be immediately signed & broadcasted.
	IndependentOf(other TxInput) (independent bool)

	// Test if tx-input could possibly result in a "double-send" given the history of past attempts.
	// A double send is a user re-signing their transaction (to overcome a timeout or use new fees), but then risk multiple transactions
	// landing on chain.  A valid re-sign should only occur if it's only possible for one transaction to land out of the total set of attempts.
	// Examples:
	// - Solana typically has no conflicts, but need to ensure (a) new blockhash is used, and (b) sufficient time has passed
	//   to be sure a double send won't occur (return `true`).
	// - If tx-inputs are not independent (spending same resources), then typically double-sends are impossible (and should return `true` here).
	// - If there exists tx-inputs that are fully independent (and not timed out), then a double-send is possible and this should return false.
	SafeFromDoubleSend(previousAttempts TxInput) (safe bool)
}

This interface determines whether if different tx inputs conflict with one another.

type TxInputEnvelope ¶

type TxInputEnvelope struct {
	Type Driver `json:"type"`
}

func NewTxInputEnvelope ¶

func NewTxInputEnvelope(envType Driver) *TxInputEnvelope

type TxInputGasFeeMultiplier ¶

type TxInputGasFeeMultiplier interface {
	SetGasFeePriority(priority GasFeePriority) error
}

type TxInputGetMaxPossibleFee ¶

type TxInputGetMaxPossibleFee interface {
	// Get the maximum possible fee that could occur for this transaction.
	// This is used to guard against "griefing" attacks where a user is charged way more than they intended.
	// The contract address may be "" when the fee is for the native asset, as is often the case..
	//
	// Note: The caller/user should check this after TxInput has been populated with all other fields, as they can influence
	// what the ultimate max fee is.
	GetFeeLimit() (AmountBlockchain, ContractAddress)
}

type TxInputWithUnix ¶

type TxInputWithUnix interface {
	SetUnix(int64)
}

For chains/transactions that can benefit from knowing the timestamp

type TxLegacyGetSignatures ¶

type TxLegacyGetSignatures interface {
	// Replaced by TxWithMetadata.GetMetadata()
	GetSignatures() []TxSignature
}

type TxSignature ¶

type TxSignature []byte

TxSignature is a tx signature

func NewTxSignatures ¶

func NewTxSignatures(data [][]byte) []TxSignature

NewTxSignatures creates a new array of TxSignature, useful to cast [][]byte into []TxSignature

type TxStatus ¶

type TxStatus uint8

TxStatus is the status of a tx on chain, currently success or failure.

const (
	TxStatusSuccess TxStatus = 0
	TxStatusFailure TxStatus = 1
)

TxStatus values

type TxVariantInput ¶

type TxVariantInput interface {
	TxInput
	GetVariant() TxVariantInputType
}

type TxVariantInputType ¶

type TxVariantInputType string

func NewCallingInputType ¶

func NewCallingInputType(driver Driver) TxVariantInputType

func NewMultiTransferInputType ¶

func NewMultiTransferInputType(driver Driver, variant string) TxVariantInputType

func NewStakingInputType ¶

func NewStakingInputType(driver Driver, variant string) TxVariantInputType

func NewUnstakingInputType ¶

func NewUnstakingInputType(driver Driver, variant string) TxVariantInputType

func NewWithdrawingInputType ¶

func NewWithdrawingInputType(driver Driver, variant string) TxVariantInputType

func (TxVariantInputType) Driver ¶

func (variant TxVariantInputType) Driver() Driver

func (TxVariantInputType) Validate ¶

func (variant TxVariantInputType) Validate() error

func (TxVariantInputType) Variant ¶

func (variant TxVariantInputType) Variant() string

type TxWithMetadata ¶

type TxWithMetadata interface {
	// If the client SubmitTx needs additional metadata, this can be used to define it.
	GetMetadata() ([]byte, bool, error)
}

type UnstakeTxInput ¶

type UnstakeTxInput interface {
	TxVariantInput
	Unstaking()
}

type WithdrawTxInput ¶

type WithdrawTxInput interface {
	TxVariantInput
	Withdrawing()
}

Directories ¶

Path Synopsis
chain
cosmos/types/CosmWasm/wasmd/x/wasm/types
Package types is a reverse proxy.
Package types is a reverse proxy.
Package types is a reverse proxy.
Package types is a reverse proxy.
Package types is a reverse proxy.
Package types is a reverse proxy.
Package types is a reverse proxy.
Package types is a reverse proxy.
Package types is a reverse proxy.
Package types is a reverse proxy.
Package types is a reverse proxy.
cosmos/types/evmos/evmos/v20/x/evm/types
Package types is a reverse proxy.
Package types is a reverse proxy.
cosmos/types/evmos/evmos/v20/x/feemarket/types
Package types is a reverse proxy.
Package types is a reverse proxy.
eos
evm
internet_computer/candid/internal/candid
Package candid is autogenerated by https://github.com/cordialsys/crosschain/chain/internet_computer/candid/upeg.
Package candid is autogenerated by https://github.com/cordialsys/crosschain/chain/internet_computer/candid/upeg.
internet_computer/candid/internal/ctest
Package ctest is autogenerated by https://github.com/cordialsys/crosschain/chain/internet_computer/candid/upeg.
Package ctest is autogenerated by https://github.com/cordialsys/crosschain/chain/internet_computer/candid/upeg.
internet_computer/candid/internal/cvalue
Package cvalue is autogenerated by https://github.com/cordialsys/crosschain/chain/internet_computer/candid/upeg.
Package cvalue is autogenerated by https://github.com/cordialsys/crosschain/chain/internet_computer/candid/upeg.
kaspa/client/rest
Package rest provides primitives to interact with the openapi HTTP API.
Package rest provides primitives to interact with the openapi HTTP API.
sui
ton
xlm
xrp
cmd
xc command
examples
bitcoin command
staking command
ton command
txinfo command
pkg
hex

Jump to

Keyboard shortcuts

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