Skip to content

Commit 16f83b7

Browse files
AIFlowMLwtfsayo
andauthored
feat: Pyth Data Plugin (#2434)
* feat(pyth): add Pyth Data plugin - Create new plugin for Pyth Data integration - Add EventSource client for price feeds - Configure plugin in agent - Update dependencies and configuration files This plugin enables real-time price feed data from Pyth Network, including price updates, TWAPs, and publisher caps information. * feat: Wrap up changes for Pyth Data integration * Save local changes before merging upstream * Update index.ts, package.json, and add .env.example for Pyth Data integration * Missing lock --------- Co-authored-by: Sayo <hi@sayo.wtf>
1 parent 8188b89 commit 16f83b7

37 files changed

+12035
-463
lines changed

.env.example

+37
Original file line numberDiff line numberDiff line change
@@ -647,3 +647,40 @@ INSTAGRAM_POST_INTERVAL_MAX=120 # Default: 120 minutes
647647
INSTAGRAM_ENABLE_ACTION_PROCESSING=false # Enable/disable action processing
648648
INSTAGRAM_ACTION_INTERVAL=5 # Interval between actions in minutes
649649
INSTAGRAM_MAX_ACTIONS=1 # Maximum number of actions to process at once
650+
651+
####################################
652+
#### Pyth Plugin Configuration ####
653+
####################################
654+
# Network Environment (mainnet or testnet)git
655+
PYTH_NETWORK_ENV=mainnet
656+
657+
# Mainnet Network Configuration
658+
PYTH_MAINNET_HERMES_URL=https://hermes.pyth.network
659+
PYTH_MAINNET_WSS_URL=wss://hermes.pyth.network/ws
660+
PYTH_MAINNET_PYTHNET_URL=https://pythnet.rpcpool.com
661+
PYTH_MAINNET_CONTRACT_REGISTRY=https://pyth.network/developers/price-feed-ids
662+
PYTH_MAINNET_PROGRAM_KEY=
663+
664+
# Testnet Network Configuration
665+
PYTH_TESTNET_HERMES_URL=https://hermes.pyth.network
666+
PYTH_TESTNET_WSS_URL=wss://hermes.pyth.network/ws
667+
PYTH_TESTNET_PYTHNET_URL=https://pythnet.rpcpool.com
668+
PYTH_TESTNET_CONTRACT_REGISTRY=https://pyth.network/developers/price-feed-ids#testnet
669+
PYTH_TESTNET_PROGRAM_KEY=
670+
671+
# Connection Settings
672+
PYTH_MAX_RETRIES=3
673+
PYTH_RETRY_DELAY=1000
674+
PYTH_TIMEOUT=5000
675+
PYTH_GRANULAR_LOG=true
676+
PYTH_LOG_LEVEL=debug
677+
PYTH_LOG_LEVEL=info
678+
679+
# Runtime Settings
680+
RUNTIME_CHECK_MODE=false
681+
682+
# Pyth Price Streaming and test ID
683+
PYTH_ENABLE_PRICE_STREAMING=true
684+
PYTH_MAX_PRICE_STREAMS=2
685+
PYTH_TEST_ID01=0xe62df6c8b4a85fe1a67db44dc12de5db330f7ac66b72dc658afedf0f4a415b43
686+
PYTH_TEST_ID02=0xff61491a931112ddf1bd8147cd1b641375f79f5825126d665480874634fd0ace

agent/package.json

+12-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
{
22
"name": "@elizaos/agent",
33
"version": "0.1.9-alpha.1",
4+
"version": "0.1.9-alpha.1",
45
"main": "src/index.ts",
56
"type": "module",
67
"scripts": {
@@ -31,14 +32,18 @@
3132
"@elizaos/client-telegram": "workspace:*",
3233
"@elizaos/client-twitter": "workspace:*",
3334
"@elizaos/client-instagram": "workspace:*",
35+
"@elizaos/client-instagram": "workspace:*",
3436
"@elizaos/client-slack": "workspace:*",
3537
"@elizaos/core": "workspace:*",
3638
"@elizaos/plugin-0g": "workspace:*",
3739
"@elizaos/plugin-abstract": "workspace:*",
3840
"@elizaos/plugin-agentkit": "workspace:*",
41+
"@elizaos/plugin-agentkit": "workspace:*",
3942
"@elizaos/plugin-aptos": "workspace:*",
4043
"@elizaos/plugin-birdeye": "workspace:*",
4144
"@elizaos/plugin-coingecko": "workspace:*",
45+
"@elizaos/plugin-birdeye": "workspace:*",
46+
"@elizaos/plugin-coingecko": "workspace:*",
4247
"@elizaos/plugin-coinmarketcap": "workspace:*",
4348
"@elizaos/plugin-binance": "workspace:*",
4449
"@elizaos/plugin-avail": "workspace:*",
@@ -53,6 +58,7 @@
5358
"@elizaos/plugin-gitbook": "workspace:*",
5459
"@elizaos/plugin-story": "workspace:*",
5560
"@elizaos/plugin-gitcoin-passport": "workspace:*",
61+
"@elizaos/plugin-gitcoin-passport": "workspace:*",
5662
"@elizaos/plugin-goat": "workspace:*",
5763
"@elizaos/plugin-lensNetwork": "workspace:*",
5864
"@elizaos/plugin-icp": "workspace:*",
@@ -63,8 +69,10 @@
6369
"@elizaos/plugin-node": "workspace:*",
6470
"@elizaos/plugin-solana": "workspace:*",
6571
"@elizaos/plugin-injective": "workspace:*",
72+
"@elizaos/plugin-injective": "workspace:*",
6673
"@elizaos/plugin-solana-agentkit": "workspace:*",
6774
"@elizaos/plugin-squid-router": "workspace:*",
75+
"@elizaos/plugin-squid-router": "workspace:*",
6876
"@elizaos/plugin-autonome": "workspace:*",
6977
"@elizaos/plugin-starknet": "workspace:*",
7078
"@elizaos/plugin-stargaze": "workspace:*",
@@ -88,10 +96,12 @@
8896
"@elizaos/plugin-video-generation": "workspace:*",
8997
"@elizaos/plugin-web-search": "workspace:*",
9098
"@elizaos/plugin-dexscreener": "workspace:*",
99+
"@elizaos/plugin-dexscreener": "workspace:*",
91100
"@elizaos/plugin-letzai": "workspace:*",
92101
"@elizaos/plugin-thirdweb": "workspace:*",
93102
"@elizaos/plugin-genlayer": "workspace:*",
94103
"@elizaos/plugin-tee-verifiable-log": "workspace:*",
104+
"@elizaos/plugin-tee-verifiable-log": "workspace:*",
95105
"@elizaos/plugin-depin": "workspace:*",
96106
"@elizaos/plugin-open-weather": "workspace:*",
97107
"@elizaos/plugin-obsidian": "workspace:*",
@@ -103,6 +113,7 @@
103113
"@elizaos/plugin-quai": "workspace:*",
104114
"@elizaos/plugin-b2": "workspace:*",
105115
"@elizaos/plugin-nft-collections": "workspace:*",
116+
"@elizaos/plugin-pyth-data": "workspace:*",
106117
"readline": "1.3.0",
107118
"ws": "8.18.0",
108119
"yargs": "17.7.2"
@@ -114,4 +125,4 @@
114125
"ts-node": "10.9.2",
115126
"tsup": "8.3.5"
116127
}
117-
}
128+
}

agent/src/index.ts

+5-1
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,6 @@ import { zgPlugin } from "@elizaos/plugin-0g";
4141
import { bootstrapPlugin } from "@elizaos/plugin-bootstrap";
4242
import createGoatPlugin from "@elizaos/plugin-goat";
4343
// import { intifacePlugin } from "@elizaos/plugin-intiface";
44-
import { DirectClient } from "@elizaos/client-direct";
4544
import { ThreeDGenerationPlugin } from "@elizaos/plugin-3d-generation";
4645
import { abstractPlugin } from "@elizaos/plugin-abstract";
4746
import { akashPlugin } from "@elizaos/plugin-akash";
@@ -103,6 +102,7 @@ import { thirdwebPlugin } from "@elizaos/plugin-thirdweb";
103102
import { hyperliquidPlugin } from "@elizaos/plugin-hyperliquid";
104103
import { echoChambersPlugin } from "@elizaos/plugin-echochambers";
105104
import { dexScreenerPlugin } from "@elizaos/plugin-dexscreener";
105+
import { pythDataPlugin } from "@elizaos/plugin-pyth-data";
106106

107107
import { zksyncEraPlugin } from "@elizaos/plugin-zksync-era";
108108
import Database from "better-sqlite3";
@@ -1018,6 +1018,10 @@ export async function createAgent(
10181018
getSecret(character, "RESERVOIR_API_KEY")
10191019
? createNFTCollectionsPlugin()
10201020
: null,
1021+
getSecret(character, "PYTH_TESTNET_PROGRAM_KEY") ||
1022+
getSecret(character, "PYTH_MAINNET_PROGRAM_KEY")
1023+
? pythDataPlugin
1024+
: null,
10211025
].filter(Boolean),
10221026
providers: [],
10231027
actions: [],

characters/dobby.character.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
{
22
"name": "Dobby",
33
"clients": [],
4-
"modelProvider": "anthropic",
4+
"modelProvider": "openai",
55
"settings": {
66
"voice": {
77
"model": "en_GB-danny-low"

packages/plugin-iq6900/package.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
"types": "dist/index.d.ts",
77
"dependencies": {
88
"@elizaos/core": "workspace:*",
9-
"@solana/web3.js": "1.95.8"
9+
"@solana/web3.js": "^1.95.8"
1010
},
1111
"devDependencies": {
1212
"tsup": "8.3.5",

packages/plugin-iq6900/src/functions/bringIQData.ts

+6-11
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import { elizaLogger } from "@elizaos/core";
22

33
import { Connection, PublicKey } from "@solana/web3.js";
4-
const network = process.env.IQSOlRPC||"https://api.mainnet-beta.solana.com";
4+
const network = process.env.IQSOlRPC || "https://api.mainnet-beta.solana.com";
55
const stringAddress = process.env.IQ_WALLET_ADDRESS;
66

77
const connection = new Connection(network, "confirmed");
@@ -10,18 +10,14 @@ const iqHost = "https://solanacontractapi.uc.r.appspot.com";
1010

1111
async function fetchDBPDA(): Promise<string> {
1212
try {
13-
if(stringAddress){
13+
if (stringAddress) {
1414
elizaLogger.info("Connecting to Solana...(IQ6900)");
1515
elizaLogger.info("Your Address:" + stringAddress);
1616
const response = await fetch(`${iqHost}/getDBPDA/${stringAddress}`);
1717
const data = await response.json();
1818
if (response.ok) {
1919
return data.DBPDA as string;
20-
} else {
21-
throw new Error(data.error || "Failed to fetch PDA");
2220
}
23-
}else{
24-
return "null";
2521
}
2622
} catch (error) {
2723
console.error("Error fetching PDA:", error);
@@ -160,8 +156,8 @@ async function fetchSignaturesForAddress(
160156
}
161157

162158
async function findRecentJsonSignature(): Promise<string> {
163-
164159
const dbAddress = await fetchDBPDA();
160+
if (!dbAddress) return;
165161
const signatures = await fetchSignaturesForAddress(
166162
new PublicKey(dbAddress)
167163
);
@@ -170,15 +166,14 @@ async function findRecentJsonSignature(): Promise<string> {
170166
const commit = await extractCommitMessage(signature);
171167
if (commit !== "null") return signature;
172168
}
173-
return "null";
169+
return;
174170
}
175171

176172
export async function bringAgentWithWalletAddress() {
177-
178173
const recent = await findRecentJsonSignature();
179-
if (recent === "null") {
174+
if (!recent) {
180175
elizaLogger.error("Cannot found onchain data in this wallet.");
181-
return "null";
176+
return;
182177
}
183178
const result = await bringCode(recent);
184179
const json_string = result.json_data;

packages/plugin-nft-generation/package.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@
2828
"@metaplex-foundation/umi-bundle-defaults": "^0.9.2",
2929
"@openzeppelin/contracts": "^5.1.0",
3030
"@solana-developers/helpers": "^2.5.6",
31-
"@solana/web3.js": "1.95.5",
31+
"@solana/web3.js": "1.95.8",
3232
"axios": "^1.7.9",
3333
"bs58": "6.0.0",
3434
"express": "4.21.1",
2.06 MB
Loading
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
import eslintGlobalConfig from "../../eslint.config.mjs";
2+
3+
export default [
4+
...eslintGlobalConfig,
5+
{
6+
files: ["src/**/*.ts"],
7+
rules: {
8+
// Disable problematic rules
9+
"@typescript-eslint/no-unused-expressions": "off",
10+
"@typescript-eslint/no-explicit-any": "warn",
11+
"@typescript-eslint/no-unsafe-member-access": "off",
12+
"@typescript-eslint/no-unsafe-assignment": "off",
13+
"@typescript-eslint/no-unsafe-return": "off",
14+
"@typescript-eslint/no-unsafe-call": "off",
15+
},
16+
},
17+
];
+59
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,59 @@
1+
{
2+
"name": "@elizaos/plugin-pyth-data",
3+
"version": "1.0.0",
4+
"description": "Pyth Network data plugin for Eliza",
5+
"type": "module",
6+
"main": "dist/index.js",
7+
"types": "dist/index.d.ts",
8+
"scripts": {
9+
"build": "tsup --format esm --dts",
10+
"test": "vitest",
11+
"lint": "eslint src --ext .ts",
12+
"clean": "rimraf dist",
13+
"build:schemas": "openapi-zod-client ./schema.json --output src/types/zodSchemas.ts",
14+
"pull:schema": "curl -o schema.json -z schema.json https://hermes.pyth.network/docs/openapi.json",
15+
"prebuild": "pnpm run pull:schema && pnpm run build:schemas"
16+
},
17+
"dependencies": {
18+
"@elizaos/core": "^0.1.7",
19+
"@pythnetwork/client": "^2.22.0",
20+
"@pythnetwork/hermes-client": "^1.3.0",
21+
"@solana/web3.js": "1.95.8",
22+
"@zodios/core": "^10.9.6",
23+
"ajv": "^8.12.0",
24+
"buffer": "6.0.3",
25+
"chalk": "^5.4.1",
26+
"cli-table3": "^0.6.5",
27+
"cross-fetch": "^4.0.0",
28+
"eventsource": "^3.0.2",
29+
"jstat": "^1.9.6",
30+
"ora": "^8.1.1",
31+
"zod": "^3.23.8"
32+
},
33+
"devDependencies": {
34+
"@types/node": "^20.8.2",
35+
"@typescript-eslint/eslint-plugin": "^6.7.4",
36+
"@typescript-eslint/parser": "^6.7.4",
37+
"eslint": "^8.50.0",
38+
"openapi-zod-client": "^1.18.1",
39+
"rimraf": "^5.0.5",
40+
"tsup": "^8.0.0",
41+
"typescript": "^5.2.2",
42+
"vitest": "^1.0.0"
43+
},
44+
"peerDependencies": {
45+
"@elizaos/core": "^0.1.7"
46+
},
47+
"engines": {
48+
"node": ">=16.0.0"
49+
},
50+
"keywords": [
51+
"eliza",
52+
"plugin",
53+
"pyth",
54+
"oracle",
55+
"price-feed"
56+
],
57+
"author": "Eliza Team",
58+
"license": "MIT"
59+
}

0 commit comments

Comments
 (0)