Skip to content

router-protocol/xplore-types-go

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

2 Commits
 
 
 
 
 
 
 
 

Repository files navigation

Xplore Types GO

Official Go client for the Router Protocol Xplore API, providing Go definitions and client implementations for the Xplore Aggregator service.

Installation

go get github.com/router-protocol/xplore-types-go

For a specific version:

go get github.com/router-protocol/[email protected]

Usage

Basic Example

package main

import (
	"context"
	"fmt"
	"log"
	"time"
	
	"google.golang.org/grpc"
	"google.golang.org/grpc/credentials/insecure"
	
	client "github.com/router-protocol/xplore-types-go"
)

func main() {
	// Set up a connection to the server
	conn, err := grpc.Dial("your-grpc-server.com:50051", grpc.WithTransportCredentials(insecure.NewCredentials()))
	if err != nil {
		log.Fatalf("Failed to connect: %v", err)
	}
	defer conn.Close()
	
	// Create a client using the connection
	xploreClient := client.NewAggregatorClient(conn)

	// Create a request
	req := &client.XploreRequest{
		InputToken: &client.ChainToken{
			ChainId:  "chain-1",
			Address:  "0x123...",
			Decimals: 18,
		},
		OutputToken: &client.ChainToken{
			ChainId:  "chain-2",
			Address:  "0x456...",
			Decimals: 18,
		},
		AmountIn:          "1000000000000000000", // 1 token with 18 decimals
		AmountOutMin:      "900000000000000000",  // 0.9 token with 18 decimals
		SlippageTolerance: 50,                    // 0.5%
		RecipientAddress:  "0x789...",
		SenderAddress:     "0xabc...",
	}

	// Create context with timeout
	ctx, cancel := context.WithTimeout(context.Background(), 10*time.Second)
	defer cancel()

	// Make the gRPC call
	resp, err := xploreClient.AggregateCall(ctx, req)
	if err != nil {
		log.Fatalf("Error calling AggregateCall: %v", err)
	}

	// Process the response
	fmt.Printf("Amount out: %s\n", resp.AmountOut)
	fmt.Printf("Price impact: %f\n", resp.PriceImpact)
}

API Reference

The Go client provides access to all methods of the Xplore Aggregator service:

  • AggregateCall: Request token swap quotes
  • AggregateMultiCall: Request multiple token swap quotes
  • GetTransactionRecord: Get details of a transaction
  • AggregateCallSplit: Request split token swap quotes
  • AggregateCallCrossChainSplit: Request cross-chain split quotes
  • RegisterDynamicNode: Register a node with the service
  • ListRegisteredNodes: List all registered nodes
  • DisableNode: Disable a specific node
  • EnableNode: Enable a specific node
  • WhitelistAddress: Whitelist an address
  • ListWhitelistedAddresses: List all whitelisted addresses
  • RemoveWhitelistedAddress: Remove an address from the whitelist
  • ListActiveNodes: List all active nodes
  • HealthCheck: Check the health of the service

Versioning

This library follows semantic versioning. Each release is tagged in the format vX.Y.Z. You can find all available versions on the releases page.

Source Repository

This client is automatically generated from the Xplore proto files in the main xplore-types repository. Updates are published whenever a new version tag is pushed to the main repository.

License

MIT

About

No description, website, or topics provided.

Resources

License

Stars

Watchers

Forks

Packages

No packages published