1.0.178 • Published 9 months ago

@compass-labs/sdk v1.0.178

Weekly downloads
-
License
MIT
Repository
-
Last release
9 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

9 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

10 months ago

1.0.167

10 months ago

1.0.166

10 months ago

1.0.165

10 months ago

1.0.164

10 months ago

1.0.163

10 months ago

1.0.162

10 months ago

1.0.161

10 months ago

1.0.160

10 months ago

1.0.159

10 months ago

1.0.158

10 months ago

1.0.157

10 months ago

1.0.156

10 months ago

1.0.155

10 months ago

1.0.154

10 months ago

1.0.153

10 months ago

1.0.152

10 months ago

1.0.151

10 months ago

1.0.150

10 months ago

1.0.149

10 months ago

1.0.148

10 months ago

1.0.147

10 months ago

1.0.146

10 months ago

1.0.145

10 months ago

1.0.144

10 months ago

1.0.143

10 months ago

1.0.142

10 months ago

1.0.141

10 months ago

1.0.140

10 months ago

1.0.139

10 months ago

1.0.138

10 months ago

1.0.137

10 months ago

1.0.136

10 months ago

1.0.135

10 months ago

1.0.134

10 months ago

1.0.133

10 months ago

1.0.132

10 months ago

1.0.131

10 months ago

1.0.130

10 months ago

1.0.129

10 months ago

1.0.128

10 months ago

1.0.127

10 months ago

1.0.126

10 months ago

1.0.125

10 months ago

1.0.124

10 months ago

1.0.123

10 months ago

1.0.122

10 months ago

1.0.121

10 months ago

1.0.120

10 months ago

1.0.119

10 months ago

1.0.118

10 months ago

1.0.117

10 months ago

1.0.116

10 months ago

1.0.115

10 months ago

1.0.114

10 months ago

1.0.113

10 months ago

1.0.112

10 months ago

1.0.111

10 months ago

1.0.110

10 months ago

1.0.109

10 months ago

1.0.108

10 months ago

1.0.107

10 months ago

1.0.106

10 months ago

1.0.105

10 months ago

1.0.104

10 months ago

1.0.103

10 months ago

1.0.102

10 months ago

1.0.101

10 months ago

1.0.100

10 months ago

1.0.99

10 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

11 months ago

1.0.69

11 months ago

1.0.68

11 months ago

1.0.67

11 months ago

1.0.66

11 months ago

1.0.65

11 months ago

1.0.64

11 months ago

1.0.63

11 months ago

1.0.62

11 months ago

1.0.61

11 months ago

1.0.60

11 months ago

1.0.59

11 months ago

1.0.58

11 months ago

1.0.57

11 months ago

1.0.56

11 months ago

1.0.55

11 months ago

1.0.54

11 months ago

1.0.53

11 months ago

1.0.52

11 months ago

1.0.51

11 months ago

1.0.50

11 months ago

1.0.49

11 months ago

1.0.48

11 months ago

1.0.47

11 months ago

1.0.46

11 months ago

1.0.45

11 months ago

1.0.44

11 months ago

1.0.43

11 months ago

1.0.42

11 months ago

1.0.41

11 months ago

1.0.40

11 months ago

1.0.39

11 months ago

1.0.38

11 months ago

1.0.37

11 months ago

1.0.36

11 months ago

1.0.35

11 months ago

1.0.34

11 months ago

1.0.33

11 months ago

1.0.32

11 months ago

1.0.31

11 months ago

1.0.30

11 months ago

1.0.29

11 months ago

1.0.28

11 months ago

1.0.27

11 months ago

1.0.26

11 months ago

1.0.25

11 months ago

1.0.24

11 months ago

1.0.23

11 months ago

1.0.22

11 months ago

1.0.21

11 months ago

1.0.20

11 months ago

1.0.19

12 months ago

1.0.18

12 months ago

1.0.17

12 months ago

1.0.16

12 months ago

1.0.15

12 months ago

1.0.14

12 months ago

1.0.13

12 months ago

1.0.12

12 months ago

1.0.11

12 months ago

1.0.10

12 months ago

1.0.9

12 months ago

1.0.8

12 months ago

1.0.7

12 months ago

1.0.6

12 months ago

1.0.5

12 months ago

1.0.4

12 months ago

1.0.3

12 months ago

1.0.2

12 months ago

1.0.1

12 months ago