1.0.178 • Published 11 months ago

@compass-labs/sdk v1.0.178

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

11 months ago

1.0.177

11 months ago

1.0.176

11 months ago

1.0.175

11 months ago

1.0.174

11 months ago

1.0.173

11 months ago

1.0.172

11 months ago

1.0.171

11 months ago

1.0.170

11 months ago

1.0.169

11 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

12 months ago

1.0.144

12 months ago

1.0.143

12 months ago

1.0.142

12 months ago

1.0.141

12 months ago

1.0.140

12 months ago

1.0.139

12 months ago

1.0.138

12 months ago

1.0.137

12 months ago

1.0.136

12 months ago

1.0.135

12 months ago

1.0.134

12 months ago

1.0.133

12 months ago

1.0.132

12 months ago

1.0.131

12 months ago

1.0.130

12 months ago

1.0.129

12 months ago

1.0.128

12 months ago

1.0.127

12 months ago

1.0.126

12 months ago

1.0.125

12 months ago

1.0.124

12 months ago

1.0.123

12 months ago

1.0.122

12 months ago

1.0.121

12 months ago

1.0.120

12 months ago

1.0.119

12 months ago

1.0.118

12 months ago

1.0.117

12 months ago

1.0.116

12 months ago

1.0.115

12 months ago

1.0.114

12 months ago

1.0.113

12 months ago

1.0.112

12 months ago

1.0.111

12 months ago

1.0.110

12 months ago

1.0.109

12 months ago

1.0.108

12 months ago

1.0.107

12 months ago

1.0.106

12 months ago

1.0.105

12 months ago

1.0.104

12 months ago

1.0.103

12 months ago

1.0.102

12 months ago

1.0.101

12 months ago

1.0.100

12 months ago

1.0.99

12 months ago

1.0.98

12 months ago

1.0.97

12 months ago

1.0.96

12 months ago

1.0.95

12 months ago

1.0.94

12 months ago

1.0.93

12 months ago

1.0.92

12 months ago

1.0.91

12 months ago

1.0.90

12 months ago

1.0.89

12 months ago

1.0.88

12 months ago

1.0.87

12 months ago

1.0.86

12 months ago

1.0.85

12 months ago

1.0.84

12 months ago

1.0.83

12 months ago

1.0.82

12 months ago

1.0.81

1 year ago

1.0.74

1 year ago

1.0.73

1 year ago

1.0.72

1 year ago

1.0.71

1 year ago

1.0.70

1 year ago

1.0.69

1 year ago

1.0.68

1 year ago

1.0.67

1 year ago

1.0.66

1 year ago

1.0.65

1 year ago

1.0.64

1 year ago

1.0.63

1 year ago

1.0.62

1 year ago

1.0.61

1 year ago

1.0.60

1 year ago

1.0.59

1 year ago

1.0.58

1 year ago

1.0.57

1 year ago

1.0.56

1 year ago

1.0.55

1 year ago

1.0.54

1 year ago

1.0.53

1 year ago

1.0.52

1 year ago

1.0.51

1 year ago

1.0.50

1 year ago

1.0.49

1 year ago

1.0.48

1 year ago

1.0.47

1 year ago

1.0.46

1 year ago

1.0.45

1 year ago

1.0.44

1 year ago

1.0.43

1 year ago

1.0.42

1 year ago

1.0.41

1 year ago

1.0.40

1 year ago

1.0.39

1 year ago

1.0.38

1 year ago

1.0.37

1 year ago

1.0.36

1 year ago

1.0.35

1 year ago

1.0.34

1 year ago

1.0.33

1 year ago

1.0.32

1 year ago

1.0.31

1 year ago

1.0.30

1 year ago

1.0.29

1 year ago

1.0.28

1 year ago

1.0.27

1 year ago

1.0.26

1 year ago

1.0.25

1 year ago

1.0.24

1 year ago

1.0.23

1 year ago

1.0.22

1 year ago

1.0.21

1 year 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