skipgo

package
v0.6.2 Latest Latest
Warning

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

Go to latest
Published: Jul 16, 2025 License: Apache-2.0, MIT Imports: 12 Imported by: 0

README

Skip Go Client

Example usage

package main

import (
	"context"
	"fmt"
	"math/big"

	"github.com/margined-protocol/locust/core/pkg/skip-go"
)

func main() {
	ctx := context.Background()

	skipgo, err := skipgo.NewClient("https://api.skip.build")
	if err != nil {
		panic(err)
	}

	amount := big.NewInt(1000000)
	route, err := skipgo.Route(
    	ctx, 
	    "uusdc", 
	    "axelar-dojo-1", 
	    "uatom", 
	    "cosmoshub-4", 
	    amount,
  )
	if err != nil {
		panic(err)
	}

	fmt.Printf("Route: %v\n", route)
}

Documentation

Index

Constants

View Source
const (
	// MaxPositionAmount6dp represents maximum allowed position value in USDC (10M)
	MaxPositionAmount6dp = 10_000_000
)

Variables

This section is empty.

Functions

func ProcessSwapEvent

func ProcessSwapEvent(events []abcitypes.Event, expectedSender, denom string) (string, error)

ProcessSwapEvent processes the incoming event, extracts the transaction hash, finds the matching recipient, and retrieves the associated amount.

Types

type AxelarTransfer

type AxelarTransfer struct {
	FromChainID    string       `json:"from_chain_id"`
	ToChainID      string       `json:"to_chain_id"`
	Type           string       `json:"type"`
	State          string       `json:"state"`
	Txs            SendTokenTxs `json:"txs"`
	AxelarScanLink string       `json:"axelar_scan_link"`
}

AxelarTransfer represents an Axelar transfer.

type BalancesRequest

type BalancesRequest struct {
	Chains map[string]ChainRequest `json:"chains"`
}

BalancesRequest represents a request for balances.

type BalancesResponse

type BalancesResponse struct {
	Chains map[string]ChainResponse `json:"chains"`
}

BalancesResponse represents the response for a balance request.

type ChainRequest

type ChainRequest struct {
	Address string   `json:"address"`
	Denoms  []string `json:"denoms"`
}

ChainRequest represents a single chain's balance request.

type ChainResponse

type ChainResponse struct {
	Address string                 `json:"address"`
	Denoms  map[string]DenomDetail `json:"denoms"`
}

ChainResponse represents a single chain's balance response.

type Client

type Client interface {
	Balance(ctx context.Context, request *BalancesRequest) (*BalancesResponse, error)
	Route(ctx context.Context, sourceAssetDenom, sourceAssetChainID, destAssetDenom, destAssetChainID string, amountIn *big.Int) (*RouteResponse, error)
	SwapRoute(ctx context.Context, tokenIn, tokenOut, chainID string, amountIn *big.Int) (*RouteResponse, error)
	FindOptimalSwapRoute(
		ctx context.Context, logger *zap.Logger, tokenIn, tokenOut, chainID string, amountIn *big.Int, maxPriceImpact float64,
	) (*big.Int, *RouteResponse, error)
	Msgs(ctx context.Context, route RouteResponse, addressList []string, slippage string) ([]Tx, error)
	SubmitTx(ctx context.Context, tx []byte, chainID string) (TxHash, error)
	TrackTx(ctx context.Context, txHash, chainID string) (TxHash, error)
	Status(ctx context.Context, tx TxHash, chainID string) (*StatusResponse, error)
}

SkipGoClient defines the interface for SkipGo operations.

func NewClient

func NewClient(baseURL string) (Client, error)

NewClient creates a new instance of SkipGoClient.

type CosmosMessage

type CosmosMessage struct {
	Msg        string `json:"msg"`
	MsgTypeURL string `json:"msg_type_url"`
}

CosmosMessage represents a Cosmos SDK message.

type CosmosTx

type CosmosTx struct {
	ChainID       string          `json:"chain_id"`
	Path          []string        `json:"path"`
	SignerAddress string          `json:"signer_address"`
	Msgs          []CosmosMessage `json:"msgs"`
}

CosmosTx represents a Cosmos SDK transaction.

type DenomDetail

type DenomDetail struct {
	Amount          string `json:"amount"`
	Decimals        uint8  `json:"decimals"`
	FormattedAmount string `json:"formatted_amount"`
	Price           string `json:"price"`
	ValueUSD        string `json:"value_usd"`
}

DenomDetail provides details about a specific denomination.

type ERC20Approval

type ERC20Approval struct {
	TokenContract string `json:"token_contract"`
	Spender       string `json:"spender"`
	Amount        string `json:"amount"`
}

ERC20Approval represents an ERC20 token approval.

type EVMTx

type EVMTx struct {
	ChainID                string          `json:"chain_id"`
	To                     string          `json:"to"`
	Value                  string          `json:"value"`
	Data                   string          `json:"data"`
	SignerAddress          string          `json:"signer_address"`
	RequiredERC20Approvals []ERC20Approval `json:"required_erc20_approvals"`
}

EVMTx represents an Ethereum transaction.

type Error

type Error struct {
	Code    int    `json:"code"`
	Message string `json:"message"`
	Details any    `json:"details"`
}

SkipGoError represents an error response from SkipGo.

func (Error) Error

func (e Error) Error() string

Error implements the error interface for SkipGoError.

type GenericTransfer

type GenericTransfer struct {
	ToChain   string           `json:"to_chain"`
	FromChain string           `json:"from_chain"`
	State     string           `json:"state"`
	SendTx    StatusTrackingTx `json:"send_tx"`
	ReceiveTx StatusTrackingTx `json:"receive_tx"`
}

GenericTransfer represents a generic transfer.

type IBCTransfer

type IBCTransfer struct {
	FromChainID string    `json:"from_chain_id"`
	ToChainID   string    `json:"to_chain_id"`
	State       string    `json:"state"`
	PacketTxs   PacketTxs `json:"packet_txs"`
}

IBCTransfer represents an IBC transfer.

type MsgsRequest

type MsgsRequest struct {
	SourceAssetDenom         string   `json:"source_asset_denom"`
	SourceAssetChainID       string   `json:"source_asset_chain_id"`
	DestAssetDenom           string   `json:"dest_asset_denom"`
	DestAssetChainID         string   `json:"dest_asset_chain_id"`
	AmountIn                 string   `json:"amount_in"`
	AmountOut                string   `json:"amount_out"`
	SlippageTolerancePercent string   `json:"slippage_tolerance_percent"`
	AddressList              []string `json:"address_list"`
	Operations               []any    `json:"operations"`
}

MsgsRequest represents a request to fetch messages for a transaction.

type MsgsResponse

type MsgsResponse struct {
	Txs []Tx `json:"txs"`
}

MsgsResponse represents the response from a Msgs request.

type PacketTxs

type PacketTxs struct {
	SendTx        *StatusTrackingTx `json:"send_tx"`
	ReceiveTx     *StatusTrackingTx `json:"receive_tx"`
	AcknowledgeTx *StatusTrackingTx `json:"acknowledge_tx"`
	TimeoutTx     *StatusTrackingTx `json:"timeout_tx,omitempty"`
	Error         *string           `json:"error,omitempty"`
}

PacketTxs represents the transactions involved in a packet.

type PricePoint

type PricePoint struct {
	Amount         *big.Int
	ExecutionPrice *big.Float
	PriceImpact    *big.Float
	Route          *RouteResponse
}

PricePoint represents a point on the price curve

type RouteRequest

type RouteRequest struct {
	SourceAssetDenom   string           `json:"source_asset_denom"`
	SourceAssetChainID string           `json:"source_asset_chain_id"`
	DestAssetDenom     string           `json:"dest_asset_denom"`
	DestAssetChainID   string           `json:"dest_asset_chain_id"`
	AmountIn           string           `json:"amount_in"`
	AllowMultiTx       bool             `json:"allow_multi_tx"`
	Bridges            []string         `json:"bridges"`
	AllowUnsafe        bool             `json:"allow_unsafe"`
	SmartSwapOptions   SmartSwapOptions `json:"smart_swap_options"`
}

RouteResponse represents the the request for a route.

type RouteResponse

type RouteResponse struct {
	AmountIn               string   `json:"amount_in"`
	AmountOut              string   `json:"amount_out"`
	SourceAssetDenom       string   `json:"source_asset_denom"`
	SourceAssetChainID     string   `json:"source_asset_chain_id"`
	DestAssetDenom         string   `json:"dest_asset_denom"`
	DestAssetChainID       string   `json:"dest_asset_chain_id"`
	Operations             []any    `json:"operations"`
	ChainIDs               []string `json:"chain_ids"`
	RequiredChainAddresses []string `json:"required_chain_addresses"`
	DoesSwap               bool     `json:"does_swap"`
	EstimatedAmountOut     string   `json:"estimated_amount_out"`
	TxsRequired            int      `json:"txs_required"`
	USDAmountIn            string   `json:"usd_amount_in"`
	USDAmountOut           string   `json:"usd_amount_out"`
	SwapPriceImpactPercent string   `json:"swap_price_impact_percent"`
}

RouteResponse represents the response from a route request.

type SendTokenTxs

type SendTokenTxs struct {
	SendTx    *StatusTrackingTx `json:"send_tx"`
	ConfirmTx *StatusTrackingTx `json:"confirm_tx,omitempty"`
	ExecuteTx *StatusTrackingTx `json:"execute_tx"`
	Error     *string           `json:"error,omitempty"`
}

SendTokenTxs represents the token transactions in an Axelar transfer.

type SmartSwapOptions

type SmartSwapOptions struct {
	EVMSwaps    bool `json:"evm_swaps"`
	SplitRoutes bool `json:"split_routes"`
}

type StatusResponse

type StatusResponse struct {
	Transfers []Transfer `json:"transfers"`
}

StatusResponse represents the status of a transaction.

type StatusTrackingTx

type StatusTrackingTx struct {
	ChainID      string `json:"chain_id"`
	ExplorerLink string `json:"explorer_link"`
	TxHash       string `json:"tx_hash"`
}

StatusTrackingTx represents a transaction being tracked.

type SubmitRequest

type SubmitRequest struct {
	Tx      string `json:"tx"`
	ChainID string `json:"chain_id"`
}

SubmitRequest represents a request to submit a transaction.

type SubmitResponse

type SubmitResponse struct {
	TxHash string `json:"tx_hash"`
}

SubmitResponse represents the response after submitting a transaction.

type TrackRequest

type TrackRequest struct {
	TxHash  string `json:"tx_hash"`
	ChainID string `json:"chain_id"`
}

TrackRequest represents a request to track a transaction.

type TrackResponse

type TrackResponse struct {
	TxHash string `json:"tx_hash"`
}

TrackResponse represents the response after tracking a transaction.

type TransactionState

type TransactionState string

TransactionState represents the state of a transaction.

const (
	StateSubmitted        TransactionState = "STATE_SUBMITTED"
	StatePending          TransactionState = "STATE_PENDING"
	StateCompletedSuccess TransactionState = "STATE_COMPLETED_SUCCESS"
	StateCompletedError   TransactionState = "STATE_COMPLETED_ERROR"
	StateAbandoned        TransactionState = "STATE_ABANDONED"
	StatePendingError     TransactionState = "STATE_PENDING_ERROR"
)

func (TransactionState) IsCompleted

func (s TransactionState) IsCompleted() bool

IsCompleted checks if the transaction is completed.

func (TransactionState) IsCompletedError

func (s TransactionState) IsCompletedError() bool

IsCompletedError checks if the transaction completed with an error.

type Transfer

type Transfer struct {
	State                TransactionState     `json:"state"`
	TransferSequence     []TransferSequence   `json:"transfer_sequence"`
	NextBlockingTransfer *TransferSequence    `json:"next_blocking_transfer,omitempty"`
	TransferAssetRelease TransferAssetRelease `json:"transfer_asset_release,omitempty"`
	Error                *string              `json:"error,omitempty"`
}

Transfer represents a single transfer within a transaction.

type TransferAssetRelease

type TransferAssetRelease struct {
	ChainID  string `json:"chain_id"`
	Denom    string `json:"denom"`
	Released bool   `json:"released"`
}

TransferAssetRelease represents the release of transfer assets.

type TransferSequence

type TransferSequence struct {
	IBCTransfer       *IBCTransfer     `json:"ibc_transfer,omitempty"`
	AxelarTransfer    *AxelarTransfer  `json:"axelar_transfer,omitempty"`
	CCTPTransfer      *GenericTransfer `json:"cctp_transfer,omitempty"`
	HyperlaneTransfer *GenericTransfer `json:"hyperlane_transfer,omitempty"`
	OpinitTransfer    *GenericTransfer `json:"opinit_transfer,omitempty"`
}

TransferSequence represents the sequence of transfers.

type Tx

type Tx struct {
	EVMTx             *EVMTx    `json:"evm_tx,omitempty"`
	CosmosTx          *CosmosTx `json:"cosmos_tx,omitempty"`
	OperationsIndices []int     `json:"operations_indices"`
}

Tx represents a generic transaction that can be either EVM or Cosmos.

type TxHash

type TxHash string

TxHash represents a transaction hash.

Jump to

Keyboard shortcuts

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