forked from elizaOS/eliza
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtokenPriceProvider.ts
30 lines (28 loc) · 1.09 KB
/
tokenPriceProvider.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
import {elizaLogger, IAgentRuntime, Memory, Provider, State} from "@elizaos/core";
import {generateProof, verifyProof} from "../util/primusUtil.ts";
const tokenPriceProvider: Provider = {
get: async (runtime: IAgentRuntime, message: Memory, _state?: State) => {
//get btc price
const url = "https://api.binance.com/api/v3/ticker/price?symbol=BTCUSDT";
const method = 'GET';
const headers = {
'Accept ': '*/*',
};
const attestation = await generateProof(url, method, headers, "", "$.price");
const valid = await verifyProof(attestation);
if(!valid){
throw new Error("Invalid price attestation");
}
elizaLogger.info('price attestation:',attestation);
const responseData = JSON.parse((attestation as any).data);
const price = responseData.content;
return `
Get BTC price from Binance:
BTC: ${price} USDT
Time: ${new Date().toUTCString()}
POST by eliza #zilia
Attested by Primus #primus #zktls
`
},
};
export { tokenPriceProvider };