aptos

package
v3.6.2 Latest Latest
Warning

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

Go to latest
Published: Feb 8, 2023 License: GPL-3.0 Imports: 22 Imported by: 0

README

aptos router

github

https://github.com/anyswap/CrossChain-Router/tree/feature/aptos

router contract

https://github.com/anyswap/router-aptos-contract/tree/use-table

router mechanism

atpos contract called Move

https://diem.github.io/move/modules-and-scripts.html

  1. Swapout from aptos to other chain

    call router contract function swapout

     public entry fun swapout<CoinType>(account: &signer, amount: u64, _receiver: string::String, _toChainID: u64) acquires RouterBurnCap, TokenInfo, SwapOutEventHolder {  
    
  2. Swapin from other chain to aptos

    map call router contract function swapin

    public entry fun swapin<CoinType, PoolCoin>(admin: &signer, receiver: address, amount: u64, _fromEvent: string::String, _fromChainID: u64) acquires RouterMintCap,TokenInfo,SwapInEventHolder
    

aptos tools

use -h option to get help info for each tool

# get chainid 
go run tokens/aptos/tools/getStubChainID/main.go -h
# convert publickey HexString to aptos address
go run tokens/aptos/tools/publicKeyToAddress/main.go -h
# deployed modules by mpc or privatekey signer
go run tokens/aptos/tools/deployModule/main.go -h
# register PoolCoin in pool contract to init LP
go run tokens/aptos/tools/registerPoolCoin/main.go -h
# config coin type in router contract
go run tokens/aptos/tools/configCoin/main.go -h
# copy mint MintCapability to router
go run tokens/aptos/tools/setPoolcoinCap/main.go -h
# issue token 
go run tokens/aptos/tools/issueToken/main.go -h

Example:
go run tokens/aptos/tools/publicKeyToAddress/main.go -p 0xedbe0d03d8022012a03d5535e8677681dbbd9bbd130a3593388a61454129f5c294
# output
address: 0x08129c35bfef3fd283da15a2f50c261a0ae3f1d1f500fa5829c3a40cf4dda15d

about aptos

API:https://fullnode.devnet.aptoslabs.com/v1/spec#/ explore: https://explorer.devnet.aptos.dev/

notice

aptos use ED25591 algorithm to create account

devnet
http: http://fullnode.devnet.aptoslabs.com chain_id: 1000004280406

testnet
http: https://api.testnet.aptos.com chain_id: 1000004280405

mainnet
http: TBA

scan Tx

See demo https://github.com/anyswap/CrossChain-Router/blob/feature/aptos/tokens/aptos/tools/eventlog/main.go

js sdk

web3: https://aptos.dev/sdks/typescript-sdk

calc tx hash script
yarn txhash '{"sender":"0x06da2b6027d581ded49b2314fa43016079e0277a17060437236f8009550961d6","sequence_number":"58","max_gas_amount":"100000","gas_unit_price":"1000","expiration_timestamp_secs":"1666244737","payload":{"type":"entry_function_payload","function":"0x06da2b6027d581ded49b2314fa43016079e0277a17060437236f8009550961d6::wETH::mint","type_arguments":[],"arguments":["0x10878abd3802be00d674709b1e5554488823f5f825bce8d1efaf370e9aaac777","100000000000000000"]},"signature":{"type":"ed25519_signature","public_key":"0x11e202042f518e9bd719296fa36007017948392f6557d2796c81677620e5a4a4","signature":"0xd3934d202a9de3178e9b280fdcfd614bb9f82d2ffd0e305898f483cdf48cf67c8350451147a5a6644d590f0a18892b12af37f47de46dd5c44ed7e2183865180b"}}' address,uint64 2 

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	API_VERSION                 = "/v1/"
	AccountPath                 = API_VERSION + "accounts/{address}"
	AccountResourcePath         = API_VERSION + "accounts/{address}/resource/{resource_type}"
	GetTransactionsPath         = API_VERSION + "transactions/by_hash/{txn_hash}"
	GetTransactionByVersionPath = API_VERSION + "transactions/by_version/{txn_version}"
	GetSigningMessagePath       = API_VERSION + "transactions/encode_submission"
	SubmitTranscationPath       = API_VERSION + "transactions"
	SimulateTranscationPath     = API_VERSION + "transactions/simulate"
	GetEventsByEventHandlePath  = API_VERSION + "accounts/{address}/events/{event_handle}/{field_name}"
	EstimateGasPricePath        = API_VERSION + "estimate_gas_price"

	SCRIPT_FUNCTION_PAYLOAD = "entry_function_payload"
	SCRIPT_PAYLOAD          = "script_payload"

	SPLIT_SYMBOL         = "::"
	CONTRACT_NAME_ROUTER = "Router"
	CONTRACT_NAME_POOL   = "Pool"

	CONTRACT_FUNC_SWAPIN             = "swapin"
	CONTRACT_FUNC_SWAPOUT            = "swapout"
	CONTRACT_FUNC_REGISTER_COIN      = "register_coin"
	CONTRACT_FUNC_SET_COIN           = "set_coin"
	CONTRACT_FUNC_SET_POOLCOIN_CAP   = "set_poolcoin_cap"
	CONTRACT_FUNC_SET_STATUS         = "set_status"
	CONTRACT_FUNC_SET_UNDERLYING_CAP = "copy_cap"

	CONTRACT_FUNC_DEPOSIT  = "deposit"
	CONTRACT_FUNC_WITHDRAW = "withdraw"

	NATIVE_COIN = "0x1::aptos_coin::AptosCoin"

	PUBLISH_PACKAGE = "0x1::code::publish_package_txn"

	COIN_INFO_PREFIX = "0x1::coin::CoinInfo<%s>"

	SUCCESS_HTTP_STATUS_CODE = map[int]bool{200: true, 202: true}
)

Functions

func CurrentCallerDir

func CurrentCallerDir() string

func GetRouterFunctionId

func GetRouterFunctionId(address, modelname, function string) string

func GetRouterModelId

func GetRouterModelId(address, modelname string) string

func GetStubChainID

func GetStubChainID(network string) *big.Int

GetStubChainID get stub chainID

func InstallTsModules

func InstallTsModules()

func PublicKeyToAddress

func PublicKeyToAddress(pubKeyHex string) (string, error)

func RunTxHashScript

func RunTxHashScript(txbody, argTypes *string, chainId uint) (string, error)

func SupportsChainID

func SupportsChainID(chainID *big.Int) bool

SupportsChainID supports chainID

Types

type Account

type Account struct {
	KeyPair *tweetnacl.KeyPair
}

func NewAccount

func NewAccount() *Account

func NewAccountFromPubkey

func NewAccountFromPubkey(pubkeyHex string) *Account

func NewAccountFromSeed

func NewAccountFromSeed(seedHex string) *Account

func (*Account) GetHexAddress

func (account *Account) GetHexAddress() string

func (*Account) GetPublicKeyHex

func (account *Account) GetPublicKeyHex() string

func (*Account) SignBytes

func (account *Account) SignBytes(message []byte) (string, error)

func (*Account) SignString

func (account *Account) SignString(message string) (string, error)

type AccountInfo

type AccountInfo struct {
	SequenceNumber    string `json:"sequence_number"`
	AuthenticationKey string `json:"authentication_key"`
}

type AptosError

type AptosError struct {
	Message   string `json:"message"`
	ErrCode   string `json:"error_code"`
	VmErrCode int    `json:"vm_error_code,omitempty"`
}

type Bridge

type Bridge struct {
	*base.NonceSetterBase
	RPCClientTimeout int
}

Bridge block bridge inherit from btc bridge

func NewCrossChainBridge

func NewCrossChainBridge() *Bridge

NewCrossChainBridge new bridge

func (*Bridge) BuildCopyCapTransaction

func (b *Bridge) BuildCopyCapTransaction(address, coin string) (*Transaction, error)

func (*Bridge) BuildDeployModuleTransaction

func (b *Bridge) BuildDeployModuleTransaction(address, packagemetadata string, moduleHexs []string) (*Transaction, error)

func (*Bridge) BuildDepositTransaction

func (b *Bridge) BuildDepositTransaction(sender, pool, underlying, anycoin string, amount uint64) (*Transaction, error)

func (*Bridge) BuildManagedCoinInitializeTransaction

func (b *Bridge) BuildManagedCoinInitializeTransaction(address, coin, poolCoinName, poolCoinSymbol string, decimals uint8, monitor_supply bool) (*Transaction, error)

func (*Bridge) BuildMintCoinTransaction

func (b *Bridge) BuildMintCoinTransaction(minter, toaddress, coin string, amount uint64) (*Transaction, error)

func (*Bridge) BuildRawTransaction

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

BuildRawTransaction impl

func (*Bridge) BuildRegisterCoinTransaction

func (b *Bridge) BuildRegisterCoinTransaction(address, coin string) (*Transaction, error)

func (*Bridge) BuildRegisterPoolCoinTransaction

func (b *Bridge) BuildRegisterPoolCoinTransaction(address, underlyingCoin, poolCoin, poolCoinName, poolCoinSymbol string, decimals uint8) (*Transaction, error)

func (*Bridge) BuildSetCoinTransaction

func (b *Bridge) BuildSetCoinTransaction(address, coin string, coinType uint8) (*Transaction, error)

func (*Bridge) BuildSetPoolcoinCapTransaction

func (b *Bridge) BuildSetPoolcoinCapTransaction(address, coin string) (*Transaction, error)

func (*Bridge) BuildSetStatusTransaction

func (b *Bridge) BuildSetStatusTransaction(address string, status uint8) (*Transaction, error)

func (*Bridge) BuildSwapinTransferTransaction

func (b *Bridge) BuildSwapinTransferTransaction(args *tokens.BuildTxArgs, tokenCfg *tokens.TokenConfig) (*Transaction, error)

BuildSwapinTransferTransaction build swapin transfer tx

func (*Bridge) BuildSwapinTransferTransactionForScript

func (b *Bridge) BuildSwapinTransferTransactionForScript(router, coin, poolcoin, receiver, amount, swapID, FromChainID string) (*Transaction, error)

func (*Bridge) BuildSwapoutTransaction

func (b *Bridge) BuildSwapoutTransaction(sender, router, coin, toAddress, tochainId string, amount uint64) (*Transaction, error)

func (*Bridge) BuildTestUnderlyingCoinMintTransaction

func (b *Bridge) BuildTestUnderlyingCoinMintTransaction(minter, toaddress, coin string, amount uint64) (*Transaction, error)

func (*Bridge) BuildTransferTransaction

func (b *Bridge) BuildTransferTransaction(sender, coin, receiver, amount string) (*Transaction, error)

func (*Bridge) BuildWithdrawTransaction

func (b *Bridge) BuildWithdrawTransaction(sender, pool, underlying, anycoin string, amount uint64) (*Transaction, error)

func (*Bridge) CalcTxHashByTSScirpt

func (b *Bridge) CalcTxHashByTSScirpt(rawTx interface{}, argTypes string) (txHash string, err error)

func (*Bridge) EstimateGasPrice

func (b *Bridge) EstimateGasPrice() (result *GasEstimate, err error)

EstimateGasPrice estimate gas price

func (*Bridge) GetAccount

func (b *Bridge) GetAccount(address string) (result *AccountInfo, err error)

GetAccount get account info

func (*Bridge) GetAccountBalance

func (b *Bridge) GetAccountBalance(address, resourceType string) (result *CoinStoreResource, err error)

func (*Bridge) GetAccountResource

func (b *Bridge) GetAccountResource(address, resourceType string, resp interface{}) (err error)

GetAccountResource get account resource

func (*Bridge) GetLatestBlockNumber

func (b *Bridge) GetLatestBlockNumber() (num uint64, err error)

func (*Bridge) GetLatestBlockNumberOf

func (b *Bridge) GetLatestBlockNumberOf(apiAddress string) (num uint64, err error)

func (*Bridge) GetLedger

func (b *Bridge) GetLedger() (result *LedgerInfo, err error)

GetLedger get ledger info

func (*Bridge) GetPoolNonce

func (b *Bridge) GetPoolNonce(address, _height string) (uint64, error)

GetPoolNonce impl NonceSetter interface

func (*Bridge) GetSigningMessage

func (b *Bridge) GetSigningMessage(request interface{}) (result *string, err error)

GetSigningMessage get signing message

func (*Bridge) GetTokenDecimals

func (b *Bridge) GetTokenDecimals(resource string) (uint8, error)

GetTokenDecimals query

func (*Bridge) GetTransaction

func (b *Bridge) GetTransaction(txHash string) (tx interface{}, err error)

GetTransaction impl

func (*Bridge) GetTransactionInfo

func (b *Bridge) GetTransactionInfo(txHash string, allowUnstable bool) (*TransactionInfo, error)

GetTransactionInfo get tx info (verify tx status and check stable)

func (*Bridge) GetTransactionStatus

func (b *Bridge) GetTransactionStatus(txHash string) (status *tokens.TxStatus, err error)

GetTransactionStatus impl

func (*Bridge) GetTransactions

func (b *Bridge) GetTransactions(txHash string) (result *TransactionInfo, err error)

GetTransactions get tx by hash

func (*Bridge) GetTransactionsNotPending

func (b *Bridge) GetTransactionsNotPending(txHash string) (result *TransactionInfo, err error)

GetTransactionsNotPending get non pending tx by hash

func (*Bridge) GetTxBlockInfo

func (b *Bridge) GetTxBlockInfo(txHash string) (blockHeight, blockTime uint64)

GetTxBlockInfo impl NonceSetter interface

func (*Bridge) HasRegisterAptosCoin

func (b *Bridge) HasRegisterAptosCoin(address string, tokenCfg *tokens.TokenConfig) error

func (*Bridge) InitAfterConfig

func (b *Bridge) InitAfterConfig()

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

func (*Bridge) InitRouterInfo

func (b *Bridge) InitRouterInfo(routerContract, routerVersion string) (err error)

func (*Bridge) IsNative

func (b *Bridge) IsNative(resource string) bool

func (*Bridge) IsValidAddress

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

IsValidAddress check address

func (*Bridge) MPCSignTransaction

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

MPCSignTransaction impl

func (*Bridge) PublicKeyToAddress

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

PublicKeyToAddress impl

func (*Bridge) RegisterSwap

func (b *Bridge) RegisterSwap(txHash string, args *tokens.RegisterArgs) ([]*tokens.SwapTxInfo, []error)

RegisterSwap api

func (*Bridge) SendTransaction

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

SendTransaction impl

func (*Bridge) SetExtraArgs

func (b *Bridge) SetExtraArgs(args *tokens.BuildTxArgs, tokenCfg *tokens.TokenConfig) error

func (*Bridge) SetTokenConfig

func (b *Bridge) SetTokenConfig(tokenAddr string, tokenCfg *tokens.TokenConfig)

SetTokenConfig set token config

func (*Bridge) SignTransactionWithPrivateKey

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

SignTransactionWithPrivateKey sign tx with ECDSA private key

func (*Bridge) SimulateTranscation

func (b *Bridge) SimulateTranscation(request interface{}, publikKey string) (err error)

SimulateTranscation simulate tx

func (*Bridge) SubmitTranscation

func (b *Bridge) SubmitTranscation(tx interface{}) (result *TransactionInfo, err error)

SubmitTranscation submit to all urls

func (*Bridge) VerifyMsgHash

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

VerifyMsgHash verify msg hash

func (*Bridge) VerifyTransaction

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

VerifyTransaction impl

type CoinCoinInfoData

type CoinCoinInfoData struct {
	Decimals uint8  `json:"decimals"`
	Name     string `json:"name"`
	Symbol   string `json:"symbol"`
}

type CoinEvent

type CoinEvent struct {
	EventData
	Data CoinEventData `json:"data"`
}

type CoinEventData

type CoinEventData struct {
	Amount string `json:"amount"`
}

type CoinInfoResource

type CoinInfoResource struct {
	Type string           `json:"type"`
	Data CoinCoinInfoData `json:"data"`
}

type CoinStoreData

type CoinStoreData struct {
	Coin           CoinValue              `json:"coin"`
	DepositEvents  map[string]interface{} `json:"deposit_events,omitempty"`
	WithdrawEvents map[string]interface{} `json:"withdraw_events,omitempty"`
}

type CoinStoreResource

type CoinStoreResource struct {
	Type string         `json:"type"`
	Data *CoinStoreData `json:"data,omitempty"`
}

type CoinValue

type CoinValue struct {
	Value string `json:"value"`
}

type Event

type Event struct {
	Key            string            `json:"key,omitempty"`
	SequenceNumber string            `json:"sequence_number,omitempty"`
	Type           string            `json:"type,omitempty"`
	Data           map[string]string `json:"data,omitempty"` // TODO map[string]interface{}
}

type EventData

type EventData struct {
	Version         string `json:"version"`
	Key             string `json:"key"`
	Sequence_number string `json:"sequence_number"`
	Type            string `json:"type"`
}

type GasEstimate

type GasEstimate struct {
	GasPrice int `json:"gas_estimate"`
}

type LedgerInfo

type LedgerInfo struct {
	ChainId             uint   `json:"chain_id"`
	Epoch               string `json:"epoch"`
	LedgerVersion       string `json:"ledger_version"`
	OldestLedgerVersion string `json:"oldest_ledger_version"`
	BlockHeight         string `json:"block_height"`
	OldestBlockHeight   string `json:"oldest_block_height"`
	LedgerTimestamp     string `json:"ledger_timestamp"`
	NodeRole            string `json:"node_role"`
}

type RestClient

type RestClient struct {
	Url     string
	Timeout int
}

func (*RestClient) EstimateGasPrice

func (c *RestClient) EstimateGasPrice() (*GasEstimate, error)

func (*RestClient) GetAccount

func (c *RestClient) GetAccount(address string) (*AccountInfo, error)

func (*RestClient) GetAccountCoin

func (c *RestClient) GetAccountCoin(address, coinType string) (*CoinStoreResource, error)

func (*RestClient) GetAccountResource

func (c *RestClient) GetAccountResource(address, resourceType string, resp interface{}) error

func (*RestClient) GetEventsByEventHandle

func (c *RestClient) GetEventsByEventHandle(request interface{}, target, struct_resource, field_name string, start, limit int) error

func (*RestClient) GetLedger

func (c *RestClient) GetLedger() (*LedgerInfo, error)

func (*RestClient) GetRequest

func (c *RestClient) GetRequest(result interface{}, uri string, params map[string]string) error

func (*RestClient) GetSigningMessage

func (c *RestClient) GetSigningMessage(request interface{}) (*string, error)

func (*RestClient) GetTransactionByVersion

func (c *RestClient) GetTransactionByVersion(version string) (*TransactionInfo, error)

func (*RestClient) GetTransactions

func (c *RestClient) GetTransactions(txHash string) (*TransactionInfo, error)

func (*RestClient) GetTransactionsNotPending

func (c *RestClient) GetTransactionsNotPending(txHash string) (*TransactionInfo, error)

func (*RestClient) PostRequest

func (c *RestClient) PostRequest(result interface{}, uri string, body interface{}) error

func (*RestClient) SimulateTranscation

func (c *RestClient) SimulateTranscation(request interface{}, publikKey string) error

func (*RestClient) SubmitTranscation

func (c *RestClient) SubmitTranscation(request interface{}) (*TransactionInfo, error)

type ScriptPayload

type ScriptPayload struct {
	Type          string            `json:"type"`
	Code          ScriptPayloadCode `json:"code"`
	TypeArguments []string          `json:"type_arguments"`
	Arguments     []interface{}     `json:"arguments"`
}

type ScriptPayloadCode

type ScriptPayloadCode struct {
	Bytecode string `json:"bytecode"`
}

type ScriptTransaction

type ScriptTransaction struct {
	Sender                  string                `json:"sender"`
	SequenceNumber          string                `json:"sequence_number"`
	MaxGasAmount            string                `json:"max_gas_amount"`
	GasUnitPrice            string                `json:"gas_unit_price"`
	GasCurrencyCode         string                `json:"gas_currency_code,omitempty"`
	ExpirationTimestampSecs string                `json:"expiration_timestamp_secs"`
	Payload                 *ScriptPayload        `json:"payload"`
	Signature               *TransactionSignature `json:"signature,omitempty"`
}

type SwapinData

type SwapinData struct {
	SwapID      string `json:"swapid"`
	Token       string `json:"token"`
	To          string `json:"to"`
	Amount      string `json:"amount"`
	FromChainId string `json:"from_chain_id"`
}

type SwapinEvent

type SwapinEvent struct {
	EventData
	Data SwapinData `json:"data"`
}

type SwapoutData

type SwapoutData struct {
	Token     string `json:"token"`
	From      string `json:"from"`
	To        string `json:"to"`
	Amount    string `json:"amount"`
	ToChainId string `json:"to_chain_id"`
}

type SwapoutEvent

type SwapoutEvent struct {
	EventData
	Data SwapoutData `json:"data"`
}

type Transaction

type Transaction struct {
	Sender                  string                `json:"sender"`
	SequenceNumber          string                `json:"sequence_number"`
	MaxGasAmount            string                `json:"max_gas_amount"`
	GasUnitPrice            string                `json:"gas_unit_price"`
	GasCurrencyCode         string                `json:"gas_currency_code,omitempty"`
	ExpirationTimestampSecs string                `json:"expiration_timestamp_secs"`
	Payload                 *TransactionPayload   `json:"payload"`
	Signature               *TransactionSignature `json:"signature,omitempty"`
}

type TransactionInfo

type TransactionInfo struct {
	Type                    string             `json:"type"`
	Version                 string             `json:"version,omitempty"`
	Hash                    string             `json:"hash"`
	StateRootHash           string             `json:"state_root_hash,omitempty"`
	EventRootHash           string             `json:"event_root_hash,omitempty"`
	GasUsed                 string             `json:"gas_used,omitempty"`
	Success                 bool               `json:"success,omitempty"`
	VmStatus                string             `json:"vm_status,omitempty"`
	AccumulatorRootHash     string             `json:"accumulator_root_hash,omitempty"`
	Sender                  string             `json:"sender"`
	SequenceNumber          string             `json:"sequence_number"`
	MaxGasAmount            string             `json:"max_gas_amount"`
	GasUnitPrice            string             `json:"gas_unit_price"`
	ExpirationTimestampSecs string             `json:"expiration_timestamp_secs"`
	Timestamp               string             `json:"timestamp,omitempty"`
	PayLoad                 TransactionPayload `json:"payload,omitempty"`
	Events                  []Event            `json:"events,omitempty"`
}

type TransactionPayload

type TransactionPayload struct {
	Type          string        `json:"type"`
	Function      string        `json:"function"`
	TypeArguments []string      `json:"type_arguments"`
	Arguments     []interface{} `json:"arguments"`
}

type TransactionSignature

type TransactionSignature struct {
	Type      string `json:"type,omitempty"`
	PublicKey string `json:"public_key,omitempty"`
	Signature string `json:"signature,omitempty"`
}

Directories

Path Synopsis
tools
calcTxhashTest command
configCoin command
deployModule command
deposit command
eventlog command
getStubChainID command
issueCoin command
mintCoin command
registerCoin command
setPoolcoinCap command
setStatus command
setupAnyCoin command
swapin command
swapout command
transfer command
withdraw command
tweetnacl-go is a port of Dan Bernstein's "crypto library in a 100 tweets" code to the Go language.
tweetnacl-go is a port of Dan Bernstein's "crypto library in a 100 tweets" code to the Go language.

Jump to

Keyboard shortcuts

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