sui

package
v0.0.0-...-3f3ae68 Latest Latest
Warning

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

Go to latest
Published: Oct 17, 2023 License: MIT Imports: 24 Imported by: 0

Documentation

Index

Constants

View Source
const (
	MaxGasBudget = 90000000
	MinGasBudget = 1100000

	MaxGasForPay      = 10000000
	MaxGasForTransfer = 10000000

	TestNetFaucetUrl = client.TestNetFaucetUrl
	DevNetFaucetUrl  = client.DevNetFaucetUrl
)
View Source
const (
	SuiName    = "Sui"
	SuiSymbol  = "Sui"
	SuiDecimal = 0
)
View Source
const MAX_INPUT_COUNT_MERGE = types.MAX_INPUT_COUNT_MERGE

= 256-1

View Source
const MAX_INPUT_COUNT_STAKE = types.MAX_INPUT_COUNT_STAKE

= 512-1

View Source
const SUI_COIN_TYPE = types.SUI_COIN_TYPE

"0x2::sui::SUI"

View Source
const (
	SuiCatFuncMint = "mint"
)

Variables

View Source
var (
	ErrNoCoinsFound        = types.ErrNoCoinsFound
	ErrInsufficientBalance = types.ErrInsufficientBalance
	ErrNeedMergeCoin       = types.ErrNeedMergeCoin
	ErrNeedSplitGasCoin    = types.ErrNeedSplitGasCoin

	ErrNoNeedMergeCoin = errors.New("existing coins exceed the target amount, no need to merge coins")
	ErrMergeOneCoin    = errors.New("only one coin does not need to merge coins")
)
View Source
var SuiCatTestnetConfig = &SuiCatConfig{
	PackageId:  "0xc5b18811206c9ef35b516cd90f1736e7504f17fec147179298cc6851f2aa10a9",
	GlobalId:   "0x9876b64fad60ef76235f56c3221a4ee1aa891eaa3b86b10ed16195169c7c3e19",
	ModuleName: "suicat",
}

Functions

func AverageApyOfDelegatedStakes

func AverageApyOfDelegatedStakes(stakes *base.AnyArray) float64

func DecodeAddressToPublicKey

func DecodeAddressToPublicKey(address string) (string, error)

func EncodePublicKeyToAddress

func EncodePublicKeyToAddress(publicKey string) (string, error)

@param publicKey can start with 0x or not.

func FaucetFundAccount

func FaucetFundAccount(address string, faucetUrl string) (h *base.OptionalString, err error)

*

  • @param address Hex-encoded 16 bytes Sui account address wich mints tokens
  • @param faucetUrl default https://faucet.testnet.sui.io/gas
  • @return digest of the faucet transfer transaction.

func IsMergeError

func IsMergeError(err error) bool

func IsSplitError

func IsSplitError(err error) bool

func IsValidAddress

func IsValidAddress(address string) bool

@param chainnet chain name

func NewDelegatedStakeArrayWithJsonString

func NewDelegatedStakeArrayWithJsonString(str string) (*base.AnyArray, error)

func TransformNFT

func TransformNFT(nft *types.SuiObjectResponse) *base.NFT

Types

type Account

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

func AccountWithPrivateKey

func AccountWithPrivateKey(prikey string) (*Account, error)

rename for support android. Android cannot support both NewAccountWithMnemonic(string) and NewAccountWithPrivateKey(string)

func AsSuiAccount

func AsSuiAccount(account base.Account) *Account

func NewAccountWithMnemonic

func NewAccountWithMnemonic(mnemonic string) (*Account, error)

func (*Account) Address

func (a *Account) Address() string

func (*Account) DecodeAddressToPublicKey

func (a *Account) DecodeAddressToPublicKey(address string) (string, error)

@return publicKey that will start with 0x.

func (*Account) EncodePublicKeyToAddress

func (a *Account) EncodePublicKeyToAddress(publicKey string) (string, error)

@param publicKey can start with 0x or not.

func (*Account) IsValidAddress

func (a *Account) IsValidAddress(address string) bool

func (*Account) PrivateKey

func (a *Account) PrivateKey() ([]byte, error)

@return privateKey data

func (*Account) PrivateKeyHex

func (a *Account) PrivateKeyHex() (string, error)

@return privateKey string that will start with 0x.

func (*Account) PublicKey

func (a *Account) PublicKey() []byte

@return publicKey data

func (*Account) PublicKeyHex

func (a *Account) PublicKeyHex() string

@return publicKey string that will start with 0x.

func (*Account) Sign

func (a *Account) Sign(message []byte, password string) ([]byte, error)

func (*Account) SignHex

func (a *Account) SignHex(messageHex string, password string) (*base.OptionalString, error)

type Chain

type Chain struct {
	RpcUrl string
	// contains filtered or unexported fields
}

func NewChainWithRpcUrl

func NewChainWithRpcUrl(rpcUrl string) *Chain

func (*Chain) AddDelegation

func (c *Chain) AddDelegation(owner, amount string, validatorAddress string) (txn *Transaction, err error)

func (*Chain) BalanceOfAccount

func (c *Chain) BalanceOfAccount(account base.Account) (*base.Balance, error)

func (*Chain) BalanceOfAddress

func (c *Chain) BalanceOfAddress(address string) (b *base.Balance, err error)

func (*Chain) BalanceOfPublicKey

func (c *Chain) BalanceOfPublicKey(publicKey string) (*base.Balance, error)

func (*Chain) BaseMoveCall

func (c *Chain) BaseMoveCall(address, packageId, module, funcName string, typArgs []string, arg []any, maxGasBudget uint64) (txn *Transaction, err error)

@param maxGasBudget Default `MinGasBudget` if is 0.

func (*Chain) BatchFetchTransactionStatus

func (c *Chain) BatchFetchTransactionStatus(hashListString string) string

func (*Chain) BuildMergeCoinPreview

func (c *Chain) BuildMergeCoinPreview(request *MergeCoinRequest) (preview *MergeCoinPreview, err error)

func (*Chain) BuildMergeCoinRequest

func (c *Chain) BuildMergeCoinRequest(owner, coinType, targetAmount string) (req *MergeCoinRequest, err error)

@param coinType Default is `SUI_COIN_TYPE`

func (*Chain) BuildSplitCoinTransaction

func (c *Chain) BuildSplitCoinTransaction(owner, coinType, targetAmount string) (txn *Transaction, err error)

@param coinType Default is `SUI_COIN_TYPE`

func (*Chain) CachedGasPrice

func (c *Chain) CachedGasPrice() (price uint64, err error)

func (*Chain) Client

func (c *Chain) Client() (*client.Client, error)

func (*Chain) EstimateTransactionFee

func (c *Chain) EstimateTransactionFee(transaction base.Transaction) (fee *base.OptionalString, err error)

func (*Chain) EstimateTransactionFeeAndRebuildTransaction

func (c *Chain) EstimateTransactionFeeAndRebuildTransaction(maxGasBudget uint64, buildTransaction func(gasBudget uint64) (*Transaction, error)) (*Transaction, error)

@param maxGasBudget: the firstly build required gas @param builer: the builder should build a transaction, it maybe will invoking twice, the firstly build gas pass the maxGasBudget, the second build will pass the estimate gas.

func (*Chain) EstimateTransactionFeeAndRebuildTransactionBCS

func (c *Chain) EstimateTransactionFeeAndRebuildTransactionBCS(maxGasBudget uint64, buildTransaction func(gasBudget uint64) (*Transaction, error)) (*Transaction, error)

func (*Chain) EstimateTransactionFeeUsePublicKey

func (c *Chain) EstimateTransactionFeeUsePublicKey(transaction base.Transaction, pubkey string) (fee *base.OptionalString, err error)

func (*Chain) FetchNFTs

func (c *Chain) FetchNFTs(owner string) (res map[string][]*base.NFT, err error)

func (*Chain) FetchNFTsJsonString

func (c *Chain) FetchNFTsJsonString(owner string) (*base.OptionalString, error)

func (*Chain) FetchSuiCatGlobalData

func (c *Chain) FetchSuiCatGlobalData() (data *SuiCatGlobalData, err error)

func (*Chain) FetchTransactionDetail

func (c *Chain) FetchTransactionDetail(hash string) (detail *base.TransactionDetail, err error)

Fetch transaction details through transaction hash

func (*Chain) FetchTransactionStatus

func (c *Chain) FetchTransactionStatus(hash string) base.TransactionStatus

func (*Chain) GasPrice

func (c *Chain) GasPrice() (gasprice *base.OptionalString, err error)

func (*Chain) GetDelegatedStakes

func (c *Chain) GetDelegatedStakes(owner string) (arr *base.AnyArray, err error)

@return Array of `DelegatedStake` elements

func (*Chain) GetValidator

func (c *Chain) GetValidator(address string, useCache bool) (v *Validator, err error)

func (*Chain) GetValidatorState

func (c *Chain) GetValidatorState() (s *ValidatorState, err error)

func (*Chain) MainToken

func (c *Chain) MainToken() base.Token

func (*Chain) MintNFT

func (c *Chain) MintNFT(creator, name, description, uri string) (txn *Transaction, err error)

func (*Chain) MintSuiCatNFT

func (c *Chain) MintSuiCatNFT(signer string, amount string) (txn *Transaction, err error)

func (*Chain) PickGasCoins

func (c *Chain) PickGasCoins(owner sui_types.SuiAddress, maxGasBudget uint64) (picked *types.PickedCoins, err error)

func (*Chain) QueryIsInSuiCatWhiteList

func (c *Chain) QueryIsInSuiCatWhiteList(address string) (b *base.OptionalBool, err error)

func (*Chain) SendRawTransaction

func (c *Chain) SendRawTransaction(signedTx string) (hash string, err error)

Send the raw transaction on-chain @return the hex hash string

func (*Chain) SendSignedTransaction

func (c *Chain) SendSignedTransaction(signedTxn base.SignedTransaction) (hash *base.OptionalString, err error)

func (*Chain) TotalStakedSuiAtValidator

func (c *Chain) TotalStakedSuiAtValidator(validator, owner string, useCache bool) (sui *base.OptionalString, err error)

@useCache If true, when there is cached data, the result will be returned directly without requesting data on the chain.

func (*Chain) TransferNFT

func (c *Chain) TransferNFT(sender, receiver, nftId string) (txn *Transaction, err error)

Just encapsulation and callbacks to method `TransferObject`. @param gasId gas object to be used in this transaction, the gateway will pick one from the signer's possession if not provided

func (*Chain) TransferObject

func (c *Chain) TransferObject(sender, receiver, objectId string, gasBudget int64) (txn *Transaction, err error)

func (*Chain) WithdrawDelegation

func (c *Chain) WithdrawDelegation(owner, stakeId string) (txn *Transaction, err error)

type DelegatedStake

type DelegatedStake struct {
	StakeId          string `json:"stakeId"`
	ValidatorAddress string `json:"validatorAddress"`
	Principal        string `json:"principal"`
	RequestEpoch     int64  `json:"requestEpoch"`

	Status       DelegationStatus `json:"status"`
	DelegationId string           `json:"delegationId"`
	EarnedAmount string           `json:"earnedAmount"`
	Validator    *Validator       `json:"validator"`
}

func AsDelegatedStake

func AsDelegatedStake(a *base.Any) *DelegatedStake

func NewDelegatedStake

func NewDelegatedStake() *DelegatedStake

func NewDelegatedStakeWithJsonString

func NewDelegatedStakeWithJsonString(str string) (*DelegatedStake, error)

func (*DelegatedStake) AsAny

func (o *DelegatedStake) AsAny() *base.Any

func (*DelegatedStake) EarningAmountTimeAfterNowMs

func (s *DelegatedStake) EarningAmountTimeAfterNowMs(stateInfo *ValidatorState) int64

@return if time > 0 indicates how long it will take to get the reward; if time < 0 indicates how much time has passed since the reward was earned;

func (*DelegatedStake) EarningAmountTimeAfterTimestampMs

func (s *DelegatedStake) EarningAmountTimeAfterTimestampMs(timestamp int64, stateInfo *ValidatorState) int64

func (*DelegatedStake) JsonString

func (s *DelegatedStake) JsonString() (*base.OptionalString, error)

type DelegationStatus

type DelegationStatus = base.SDKEnumInt
const (
	DelegationStatusPending DelegationStatus = 0
	DelegationStatusActived DelegationStatus = 1
)

type MergeCoinPreview

type MergeCoinPreview struct {
	// The original request
	Request *MergeCoinRequest

	// The merge coins transaction
	Transaction *Transaction
	// Did the simulated transaction execute successfully?
	SimulateSuccess bool
	EstimateGasFee  int64

	// If the transaction is executed, owner will receive a coin amount that is not less than this.
	EstimateAmount string
	// Due to the results obtained through simulated execution, we may know that the balance may increase and the value of this state may be inconsistent with the value in the request.
	WillBeAchieved bool
}

type MergeCoinRequest

type MergeCoinRequest struct {
	Owner        string
	CoinType     string
	TargetAmount string

	// queried coins
	Coins      types.PickedCoins
	CoinsCount int
	// If the transaction is executed, owner will receive a coin amount that is not less than this.
	EstimateAmount string
	// Will the goal of merging coins of a specified amount be achieved?
	WillBeAchieved bool
}

type RestReachability

type RestReachability struct {
}

func NewRestReachability

func NewRestReachability() *RestReachability

func (*RestReachability) LatencyOf

func (r *RestReachability) LatencyOf(rpc string, timeout int64) (l *base.RpcLatency, err error)

@return latency (ms) of rpc query blockNumber. -1 means the connection failed.

type SignedTransaction

type SignedTransaction struct {
	// transaction data bytes
	TxBytes *lib.Base64Data `json:"tx_bytes"`

	// transaction signature
	Signature *sui_types.Signature `json:"signature"`
}

func AsSignedTransaction

func AsSignedTransaction(txn base.SignedTransaction) *SignedTransaction

func (*SignedTransaction) HexString

func (txn *SignedTransaction) HexString() (res *base.OptionalString, err error)

type SuiCatConfig

type SuiCatConfig struct {
	PackageId  string
	GlobalId   string
	ModuleName string
	// contains filtered or unexported fields
}

type SuiCatGlobalData

type SuiCatGlobalData struct {
	TotalMinted    int64  `json:"total_minted"`
	Supply         int64  `json:"supply"`
	PricePublic    string `json:"price_public"`
	PriceWhitelist string `json:"price_whitelist"`
	StartTimeMs    int64  `json:"start_time"`
	DurationMs     int64  `json:"duration"`
}

func NewSuiCatGlobalDataWithJsonString

func NewSuiCatGlobalDataWithJsonString(str string) (*SuiCatGlobalData, error)

func (*SuiCatGlobalData) JsonString

func (j *SuiCatGlobalData) JsonString() (*base.OptionalString, error)

type Token

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

func NewToken

func NewToken(chain *Chain, tag string) (*Token, error)

@param tag format `address::module_name::name`, e.g. "0x2::sui::SUI"

func NewTokenMain

func NewTokenMain(chain *Chain) *Token

func (*Token) BalanceOfAccount

func (t *Token) BalanceOfAccount(account base.Account) (*base.Balance, error)

func (*Token) BalanceOfAddress

func (t *Token) BalanceOfAddress(address string) (b *base.Balance, err error)

func (*Token) BalanceOfPublicKey

func (t *Token) BalanceOfPublicKey(publicKey string) (*base.Balance, error)

func (*Token) BuildTransfer

func (t *Token) BuildTransfer(sender, receiver, amount string) (txn base.Transaction, err error)

func (*Token) BuildTransferAll

func (t *Token) BuildTransferAll(sender, receiver string) (txn base.Transaction, err error)

Before invoking this method, it is best to check `CanTransferAll()`

func (*Token) BuildTransferTransaction

func (t *Token) BuildTransferTransaction(account *Account, receiverAddress, amount string) (s *Transaction, err error)

func (*Token) BuildTransferTx

func (t *Token) BuildTransferTx(privateKey, receiverAddress, amount string) (*base.OptionalString, error)

func (*Token) BuildTransferTxWithAccount

func (t *Token) BuildTransferTxWithAccount(account *Account, receiverAddress, amount string) (s *base.OptionalString, err error)

func (*Token) CanTransferAll

func (t *Token) CanTransferAll() bool

func (*Token) Chain

func (t *Token) Chain() base.Chain

func (*Token) CoinType

func (t *Token) CoinType() string

func (*Token) EstimateFees

func (t *Token) EstimateFees(account *Account, receiverAddress, amount string) (f *base.OptionalString, err error)

func (*Token) IsSUI

func (t *Token) IsSUI() bool

func (*Token) TokenInfo

func (t *Token) TokenInfo() (info *base.TokenInfo, err error)

type Transaction

type Transaction struct {
	Txn types.TransactionBytes

	TxnBytes lib.Base64Data

	EstimateGasFee int64
}

func (*Transaction) SignWithAccount

func (t *Transaction) SignWithAccount(account base.Account) (signedTx *base.OptionalString, err error)

func (*Transaction) SignedTransactionWithAccount

func (t *Transaction) SignedTransactionWithAccount(account base.Account) (signedTx base.SignedTransaction, err error)

func (*Transaction) TransactionBytes

func (t *Transaction) TransactionBytes() []byte

type Util

type Util struct {
}

func NewUtil

func NewUtil() (*Util, error)

func (*Util) DecodeAddressToPublicKey

func (u *Util) DecodeAddressToPublicKey(address string) (string, error)

Warning: Sui cannot support decode address to public key

func (*Util) EncodePublicKeyToAddress

func (u *Util) EncodePublicKeyToAddress(publicKey string) (string, error)

@param publicKey can start with 0x or not.

func (*Util) IsValidAddress

func (u *Util) IsValidAddress(address string) bool

type Validator

type Validator struct {
	Address    string  `json:"address"`
	Name       string  `json:"name"`
	Desc       string  `json:"desc"`
	ImageUrl   string  `json:"imageUrl"`
	ProjectUrl string  `json:"projectUrl"`
	APY        float64 `json:"apy"`

	Commission      int64  `json:"commission"`
	TotalStaked     string `json:"totalStaked"`
	DelegatedStaked string `json:"delegatedStaked"`
	SelfStaked      string `json:"selfStaked"`
	TotalRewards    string `json:"totalRewards"`
	GasPrice        int64  `json:"gasPrice"`

	PoolShare float64 `json:"poolShare"`
}

func AsValidator

func AsValidator(a *base.Any) *Validator

func NewValidator

func NewValidator() *Validator

func NewValidatorWithJsonString

func NewValidatorWithJsonString(str string) (*Validator, error)

func (*Validator) AsAny

func (o *Validator) AsAny() *base.Any

func (*Validator) JsonString

func (s *Validator) JsonString() (*base.OptionalString, error)

type ValidatorState

type ValidatorState struct {
	// The current epoch in Sui. An epoch takes approximately 24 hours and runs in checkpoints.
	Epoch int64 `json:"epoch"`
	// Array of `Validator` elements
	Validators *base.AnyArray `json:"validators"`

	// The amount of all tokens staked in the Sui Network.
	TotalStaked string `json:"totalStaked"`
	// The amount of rewards won by all Sui validators in the last epoch.
	TotalRewards string `json:"lastEpochReward"`

	EpochStartTimestampMs int64 `json:"epochStartTimestampMs"`
	EpochDurationMs       int64 `json:"epochDurationMs"`
}

func NewValidatorState

func NewValidatorState() *ValidatorState

func NewValidatorStateWithJsonString

func NewValidatorStateWithJsonString(str string) (*ValidatorState, error)

func (*ValidatorState) EarningAmountTimeAfterNowMs

func (s *ValidatorState) EarningAmountTimeAfterNowMs() int64

@return if time > 0 indicates how long it will take to get the reward; if time < 0 indicates how much time has passed since the reward was earned;

func (*ValidatorState) EarningAmountTimeAfterTimestampMs

func (s *ValidatorState) EarningAmountTimeAfterTimestampMs(timestamp int64) int64

func (*ValidatorState) JsonString

func (s *ValidatorState) JsonString() (*base.OptionalString, error)

Jump to

Keyboard shortcuts

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