1.0.178 • Published 10 months ago

@compass-labs/sdk v1.0.178

Weekly downloads
-
License
MIT
Repository
-
Last release
10 months ago

@compass-labs/sdk

This package is a TypeScript SDK for Compass API created specifically for the use in AI Agents.

Overview

The @compass-labs/sdk package is a TypeScript SDK designed to facilitate interaction with various blockchain protocols through a structured API. It is particularly useful for AI agents, such as ElizaOS, that require seamless integration with blockchain functionalities.

Features

  • Comprehensive API Client: The package provides a robust API client built using Zodios, which allows for type-safe API requests and responses. This ensures that interactions with the API are reliable and less prone to runtime errors.

  • Blockchain Interactions: The SDK includes a variety of endpoints for interacting with blockchain protocols, such as Uniswap, AAVE, Aerodrome, etc. These endpoints support operations like swapping tokens, removing liquidity, and fetching pool prices. The list of supported protocols and chains is expanded on a weekly basis. Feel free to contact Compass Team to include a protocol that you wish to use.

  • Type Safety: Leveraging TypeScript and zod for schema validation, the package ensures that all data structures conform to expected formats. This reduces the likelihood of errors and enhances code maintainability.

Usage

To use the @compass-labs/sdk package, you need to import the necessary modules and create an API client.

npm install @compass-labs/sdk

The API exposes two different endpoint types:

  • Read endpoints, ie endpoints making contract calls to retrieve on-chain data

Example, getting asset prices according to AAVE Oracle.

import { createApiClient } from '@compass-labs/sdk';

const apiClient = createApiClient('https://api.compasslabs.ai');

apiClient["post"]("/v0/aave/asset_price/get", {"chain": "arbitrum:mainnet", "asset": "WETH"}).then((response: any) => {
    console.log(response);
}).catch((error: any) => {
    console.error(error);
});

Each read endpoint has its own response schema, this can be found in the Compass API Docs

  • Unsigned transaction endpoints, ie endpoints generating an unsigned transcation to be broadcast to the blockchain:

Example, supplying WETH on AAVE:

apiClient["post"]("/v0/aave/supply", {
    "chain": "arbitrum:mainnet",
    "sender": "0x8A2c9eD8F6B9aD09036Cc0F5AAcaE7E6708f3D0c",
    "asset": "WETH",
    "amount": 1.5,
    "on_behalf_of": "0x8A2c9eD8F6B9aD09036Cc0F5AAcaE7E6708f3D0c"
  }).then((response: any) => {
    console.log(response);
}).catch((error: any) => {
    console.error(error);
});

if the request is successful, an unsigned transaction of the following form will be returned:

{
    chainId: "The chain id of the transaction",
    data: "The data of the transaction",
    from: "The sender of the transaction",
    gas: "The gas of the transaction",
    to: "The recipient of the transaction",
    value: "The value of the transaction",
    nonce: "The nonce of the address",
    maxFeePerGas: "The max fee per gas of the transaction",
    maxPriorityFeePerGas: "The max priority fee per gas of the transaction",
}

this can be further signed and sent, example using viem's WalletClient:

import { createWalletClient } from 'viem';

apiClient["post"]("/v0/aave/supply", {
    "chain": "arbitrum:mainnet",
    "sender": "0x8A2c9eD8F6B9aD09036Cc0F5AAcaE7E6708f3D0c",
    "asset": "WETH",
    "amount": 1.5,
    "on_behalf_of": "0x8A2c9eD8F6B9aD09036Cc0F5AAcaE7E6708f3D0c"
  }).then((response: any) => {
    const walletClient = createWalletClient(...);
    const txHash = await walletClient.sendTransaction(response);
    const txReceipt await walletClient.waitForTransactionReceipt({hash: txHash});
}).catch((error: any) => {
    console.error(error);
});
1.0.178

10 months ago

1.0.177

10 months ago

1.0.176

10 months ago

1.0.175

10 months ago

1.0.174

10 months ago

1.0.173

10 months ago

1.0.172

10 months ago

1.0.171

10 months ago

1.0.170

10 months ago

1.0.169

10 months ago

1.0.168

11 months ago

1.0.167

11 months ago

1.0.166

11 months ago

1.0.165

11 months ago

1.0.164

11 months ago

1.0.163

11 months ago

1.0.162

11 months ago

1.0.161

11 months ago

1.0.160

11 months ago

1.0.159

11 months ago

1.0.158

11 months ago

1.0.157

11 months ago

1.0.156

11 months ago

1.0.155

11 months ago

1.0.154

11 months ago

1.0.153

11 months ago

1.0.152

11 months ago

1.0.151

11 months ago

1.0.150

11 months ago

1.0.149

11 months ago

1.0.148

11 months ago

1.0.147

11 months ago

1.0.146

11 months ago

1.0.145

11 months ago

1.0.144

11 months ago

1.0.143

11 months ago

1.0.142

11 months ago

1.0.141

11 months ago

1.0.140

11 months ago

1.0.139

11 months ago

1.0.138

11 months ago

1.0.137

11 months ago

1.0.136

11 months ago

1.0.135

11 months ago

1.0.134

11 months ago

1.0.133

11 months ago

1.0.132

11 months ago

1.0.131

11 months ago

1.0.130

11 months ago

1.0.129

11 months ago

1.0.128

11 months ago

1.0.127

11 months ago

1.0.126

11 months ago

1.0.125

11 months ago

1.0.124

11 months ago

1.0.123

11 months ago

1.0.122

11 months ago

1.0.121

11 months ago

1.0.120

11 months ago

1.0.119

11 months ago

1.0.118

11 months ago

1.0.117

11 months ago

1.0.116

11 months ago

1.0.115

11 months ago

1.0.114

11 months ago

1.0.113

11 months ago

1.0.112

11 months ago

1.0.111

11 months ago

1.0.110

11 months ago

1.0.109

11 months ago

1.0.108

11 months ago

1.0.107

11 months ago

1.0.106

11 months ago

1.0.105

11 months ago

1.0.104

11 months ago

1.0.103

11 months ago

1.0.102

11 months ago

1.0.101

11 months ago

1.0.100

11 months ago

1.0.99

11 months ago

1.0.98

11 months ago

1.0.97

11 months ago

1.0.96

11 months ago

1.0.95

11 months ago

1.0.94

11 months ago

1.0.93

11 months ago

1.0.92

11 months ago

1.0.91

11 months ago

1.0.90

11 months ago

1.0.89

11 months ago

1.0.88

11 months ago

1.0.87

11 months ago

1.0.86

11 months ago

1.0.85

11 months ago

1.0.84

11 months ago

1.0.83

11 months ago

1.0.82

11 months ago

1.0.81

11 months ago

1.0.74

11 months ago

1.0.73

11 months ago

1.0.72

11 months ago

1.0.71

11 months ago

1.0.70

12 months ago

1.0.69

12 months ago

1.0.68

12 months ago

1.0.67

12 months ago

1.0.66

12 months ago

1.0.65

12 months ago

1.0.64

12 months ago

1.0.63

12 months ago

1.0.62

12 months ago

1.0.61

12 months ago

1.0.60

12 months ago

1.0.59

12 months ago

1.0.58

12 months ago

1.0.57

12 months ago

1.0.56

12 months ago

1.0.55

12 months ago

1.0.54

12 months ago

1.0.53

12 months ago

1.0.52

12 months ago

1.0.51

12 months ago

1.0.50

12 months ago

1.0.49

12 months ago

1.0.48

12 months ago

1.0.47

12 months ago

1.0.46

12 months ago

1.0.45

12 months ago

1.0.44

12 months ago

1.0.43

12 months ago

1.0.42

12 months ago

1.0.41

12 months ago

1.0.40

12 months ago

1.0.39

12 months ago

1.0.38

12 months ago

1.0.37

12 months ago

1.0.36

12 months ago

1.0.35

12 months ago

1.0.34

12 months ago

1.0.33

12 months ago

1.0.32

12 months ago

1.0.31

12 months ago

1.0.30

12 months ago

1.0.29

12 months ago

1.0.28

12 months ago

1.0.27

12 months ago

1.0.26

12 months ago

1.0.25

12 months ago

1.0.24

12 months ago

1.0.23

12 months ago

1.0.22

12 months ago

1.0.21

12 months ago

1.0.20

1 year ago

1.0.19

1 year ago

1.0.18

1 year ago

1.0.17

1 year ago

1.0.16

1 year ago

1.0.15

1 year ago

1.0.14

1 year ago

1.0.13

1 year ago

1.0.12

1 year ago

1.0.11

1 year ago

1.0.10

1 year ago

1.0.9

1 year ago

1.0.8

1 year ago

1.0.7

1 year ago

1.0.6

1 year ago

1.0.5

1 year ago

1.0.4

1 year ago

1.0.3

1 year ago

1.0.2

1 year ago

1.0.1

1 year ago