Skip to content

Commit

Permalink
Integrate allora-sdk for fetching topics and inferences
Browse files Browse the repository at this point in the history
  • Loading branch information
conache committed Jan 6, 2025
1 parent 63fa0fc commit 54140ca
Show file tree
Hide file tree
Showing 6 changed files with 1,492 additions and 1,446 deletions.
3 changes: 2 additions & 1 deletion packages/plugin-allora/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,8 @@
"@elizaos/core": "workspace:*",
"tsup": "8.3.5",
"node-cache": "5.1.2",
"vitest": "2.1.8"
"vitest": "2.1.8",
"@alloralabs/allora-sdk": "0.0.4"
},
"scripts": {
"build": "tsup --format esm --dts",
Expand Down
14 changes: 7 additions & 7 deletions packages/plugin-allora/src/actions/getInference.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,11 +12,11 @@ import {
} from "@elizaos/core";
import { z } from "zod";
import { topicsProvider } from "../providers/topics";
import { AlloraAPIClient } from "../providers/allora-api";
import { getInferenceTemplate } from "../templates";
import { AlloraAPIClient, ChainSlug } from "@alloralabs/allora-sdk";

interface InferenceFields {
topicId: string | null;
topicId: number | null;
topicName: string | null;
}

Expand Down Expand Up @@ -82,12 +82,12 @@ export const getInferenceAction: Action = {

try {
// Get inference from Allora API
const alloraApiClient = new AlloraAPIClient(
runtime.getSetting("ALLORA_CHAIN_SLUG"),
runtime.getSetting("ALLORA_API_KEY")
);
const alloraApiClient = new AlloraAPIClient({
chainSlug: runtime.getSetting("ALLORA_CHAIN_SLUG") as ChainSlug,
apiKey: runtime.getSetting("ALLORA_API_KEY") as string,
});

const inferenceRes = await alloraApiClient.getInference(
const inferenceRes = await alloraApiClient.getInferenceByTopicID(
inferenceFields.topicId
);
const inferenceValue =
Expand Down
122 changes: 0 additions & 122 deletions packages/plugin-allora/src/providers/allora-api.ts

This file was deleted.

10 changes: 5 additions & 5 deletions packages/plugin-allora/src/providers/topics.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@ import {
Provider,
State,
} from "@elizaos/core";
import { AlloraAPIClient, AlloraTopic } from "./allora-api";
import NodeCache from "node-cache";
import { AlloraAPIClient, AlloraTopic, ChainSlug } from "@alloralabs/allora-sdk";

export class TopicsProvider implements Provider {
private cache: NodeCache;
Expand Down Expand Up @@ -52,10 +52,10 @@ export class TopicsProvider implements Provider {
const alloraApiKey = runtime.getSetting("ALLORA_API_KEY");
const alloraChainSlug = runtime.getSetting("ALLORA_CHAIN_SLUG");

const alloraApiClient = new AlloraAPIClient(
alloraChainSlug,
alloraApiKey
);
const alloraApiClient = new AlloraAPIClient({
chainSlug: alloraChainSlug as ChainSlug,
apiKey: alloraApiKey as string,
});
const alloraTopics = await alloraApiClient.getAllTopics();

// Cache the retrieved topics
Expand Down
4 changes: 3 additions & 1 deletion packages/plugin-allora/tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,9 @@
"rootDir": "src",
"types": [
"node"
]
],
"esModuleInterop": true,
"allowSyntheticDefaultImports": true
},
"include": [
"src/**/*.ts"
Expand Down
Loading

0 comments on commit 54140ca

Please sign in to comment.