Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: add state of mika integration #286

Open
wants to merge 3 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions .env.example
Original file line number Diff line number Diff line change
Expand Up @@ -11,3 +11,5 @@ ALLORA_API_KEY=
ALLORA_API_URL=
ALLORA_NETWORK= testnet | mainnet
ELFA_AI_API_KEY=
# you may get a SOM_API_KEY from https://gmika.ai
SOM_API_KEY=
23 changes: 18 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -60,10 +60,10 @@ Anyone - whether an SF-based AI researcher or a crypto-native builder - can brin
- Cross-chain bridging via deBridge DLN

- **Solana Blinks**
- Lending by Lulo (Best APR for USDC)
- Send Arcade Games
- JupSOL staking
- Solayer SOL (sSOL)staking
- Lending by Lulo (Best APR for USDC)
- Send Arcade Games
- JupSOL staking
- Solayer SOL (sSOL)staking

- **Non-Financial Actions**
- Gib Work for registering bounties
Expand Down Expand Up @@ -100,8 +100,12 @@ Anyone - whether an SF-based AI researcher or a crypto-native builder - can brin
- Natural language processing for blockchain commands
- Price feed integration for market analysis
- Automated decision-making capabilities
- Evaluate mathematical expressions
- Scrape websites for data
- Get latest cryptocurrency or blockchain news

## 📃 Documentation

You can view the full documentation of the kit at [docs.solanaagentkit.xyz](https://docs.solanaagentkit.xyz)

## 📦 Installation
Expand Down Expand Up @@ -141,7 +145,9 @@ const result = await agent.deployToken(

console.log("Token Mint Address:", result.mint.toString());
```

### Create NFT Collection on 3Land

```typescript
const isDevnet = false; // (Optional) if not present TX takes place in Mainnet
const priorityFeeParam = 1000000; // (Optional) if not present the default priority fee will be 50000
Expand All @@ -161,7 +167,9 @@ const result = await agent.create3LandCollection(
```

### Create NFT on 3Land

When creating an NFT using 3Land's tool, it automatically goes for sale on 3.land website

```typescript
const isDevnet = true; // (Optional) if not present TX takes place in Mainnet
const withPool = true; // (Optional) only present if NFT will be created with a Liquidity Pool for a specific SPL token
Expand Down Expand Up @@ -191,7 +199,6 @@ const result = await agent.create3LandNft(

```


### Create NFT Collection

```typescript
Expand Down Expand Up @@ -571,20 +578,23 @@ const signature = await agent.swap(
The Solana Agent Kit supports cross-chain token transfers using deBridge's DLN protocol. Here's how to use it:

1. Check supported chains:

```typescript
const chains = await agent.getDebridgeSupportedChains();
console.log("Available chains:", chains);
// Example output: { chains: [{ chainId: "1", chainName: "Ethereum" }, { chainId: "7565164", chainName: "Solana" }] }
```

2. Get available tokens (optional):

```typescript
const tokens = await agent.getDebridgeTokensInfo("1", "USDC"); // Search for USDC on Ethereum
console.log("Available tokens:", tokens);
// Shows tokens matching 'USDC' on the specified chain
```

3. Create bridge order (SOL -> ETH):

```typescript
const orderInput = {
srcChainId: "7565164", // Solana
Expand All @@ -601,19 +611,22 @@ console.log("Order created:", order);
```

4. Execute the bridge order:

```typescript
const signature = await agent.executeDebridgeOrder(order.tx.data);
console.log("Bridge transaction sent:", signature);
```

5. Check bridge status:

```typescript
const status = await agent.checkDebridgeTransactionStatus(signature);
console.log("Bridge status:", status);
// Shows current status: Created, Fulfilled, etc.
```

Note: When bridging between chains:

- To Solana: Use base58 addresses for recipients and token mints
- From Solana: Use EVM addresses for recipients and ERC-20 format for tokens
- Always verify addresses and amounts before executing bridge transactions
Expand Down
6 changes: 6 additions & 0 deletions src/actions/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -109,6 +109,9 @@ import getCoingeckoTokenPriceDataAction from "./coingecko/getCoingeckoTokenPrice
import getCoingeckoTopGainersAction from "./coingecko/getCoingeckoTopGainers";
import getCoingeckoTrendingPoolsAction from "./coingecko/getCoingeckoTrendingPools";
import getCoingeckoTrendingTokensAction from "./coingecko/getCoingeckoTrendingTokens";
import scrapeWebsiteAction from "./stateofmika/scrapeWebsite";
import evaluateMathAction from "./stateofmika/evaluateMath";
import getCryptoNewsAction from "./stateofmika/getCryptoNews";

export const ACTIONS = {
GET_INFO_ACTION: getInfoAction,
Expand Down Expand Up @@ -226,6 +229,9 @@ export const ACTIONS = {
GET_COINGECKO_TOP_GAINERS_ACTION: getCoingeckoTopGainersAction,
GET_COINGECKO_TRENDING_POOLS_ACTION: getCoingeckoTrendingPoolsAction,
GET_COINGECKO_TRENDING_TOKENS_ACTION: getCoingeckoTrendingTokensAction,
SCRAPE_WEBSITE_ACTION: scrapeWebsiteAction,
EVALUATE_MATH_ACTION: evaluateMathAction,
GET_CRYPTO_NEWS_ACTION: getCryptoNewsAction,
};

export type { Action, ActionExample, Handler } from "../types/action";
63 changes: 63 additions & 0 deletions src/actions/stateofmika/evaluateMath.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
import { z } from "zod";
import { Action } from "../../types";

const evaluateMathAction: Action = {
name: "EVALUATE_MATH_ACTION",
description: "Evaluate mathematical expressions",
similes: [
"Calculate mathematical expressions",
"evaluate this math problem",
"solve this equation",
],
examples: [
[
{
input: {
query: "What is the result of 5 + 3?",
},
explanation: "Calculate the sum of 5 and 3",
output: {
original_query: "What is the result of 5 + 3?",
route: {
tool: "math",
confidence: 1.0,
parameters: { expression: "5 + 3" },
description:
"The query is a straightforward mathematical expression that requires evaluation, making the math tool the most appropriate choice.",
},
response: {
processed_response: "8",
original_response: {
expression: "5 + 3",
result: "8.0",
steps: [
"Received expression: '5 + 3'",
"Parsed expression (Sympy form): 3 + 5",
"Simplified expression: 8",
"Final numeric result: 8.0",
],
},
},
},
},
],
],
schema: z.object({
query: z.string(),
}),
handler: async (agent, input) => {
try {
return {
status: "success",
result: await agent.evaluateMathExpressionUsingSOM(input.query),
};
} catch (e) {
return {
status: "error",
message: e,
};
}
},
};

export default evaluateMathAction;
61 changes: 61 additions & 0 deletions src/actions/stateofmika/getCryptoNews.ts

Large diffs are not rendered by default.

87 changes: 87 additions & 0 deletions src/actions/stateofmika/scrapeWebsite.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,87 @@
import { z } from "zod";
import { Action } from "../../types";

const scrapeWebsiteAction: Action = {
name: "SCRAPE_WEBSITE_ACTION",
description: "Scrape content or news from external websites",
similes: [
"Scrape content from external websites",
"scrape this website",
"scrape this page",
],
examples: [
[
{
input: {
query: "Tell me the trending news from bbc.co.uk",
},
explanation: "Scrape the trending news from bbc.co.uk",
output: {
original_query: "Tell me the trending news from bbc.co.uk",
route: {
tool: "scraper",
confidence: 0.9,
parameters: {
url: "https://www.bbc.co.uk",
instructions: "Get the trending news articles",
},
description:
"The user is asking for trending news from a specific website (bbc.co.uk), which aligns with the capabilities of the scraper tool to extract content from external websites.",
},
response: {
processed_response:
"- Putin ready to speak to Zelensky 'if necessary', Kremlin says as US and Russia hold talks\n- Natasha Bedingfield covers an Oasis classic in the Piano Room\n- A body found in the Norwegian town of Larvik turns out to be an American",
original_response: {
original_url: "https://www.bbc.co.uk/",
instructions:
"Extract the top trending news headlines from the scraped data and present them in a bulleted list format.",
processed_content: {
url: "https://www.bbc.co.uk/",
title: "Unknown Title",
content:
"BBC Homepage Live. Putin ready to speak to Zelensky 'if necessary', Kremlin says as US and Russia hold talks The US says the talks are a first step to see if Russia is \"serious\" about peace - but Ukraine has not been invited. Keep up with the latest from BBC Sport The top stories from England, Scotland, Wales and Northern Ireland Latest news and must-see moments Natasha Bedingfield covers an Oasis classic in the Piano Room. Video, 24 minutes The singer teams up with the BBC Concert Orchestra to put her own spin on a Britpop classic along with a fresh take on two of her hit songs. - AttributionBBC Radio 2 - AttributionHistory of the BBC Meal ideas, cooking tips and more, updated daily to keep you inspired Tuck into these creamy and comforting risotto recipes on cold nights Perfect for midweek, here are all of our favourite risottos in one place. - AttributionBBC Food Is Essex really the county of grafters? 'I think we're built different around here,' says car boot sale trader Sonny Green. - Attribution Uplifting stories Insight and analysis A closer look at the week's stories New and trending on the BBC Add to your watchlist on iPlayer and subscribe on Sounds - AttributioniPlayer - AttributionSounds - AttributioniPlayer - AttributionSounds Discover more to watch and listen to A body found in the Norwegian town of Larvik turns out to be an American. Video, 42 minutes William Wisting, a widowed senior detective, leads an investigation that turns into an international hunt for a serial killer. - AttributionBBC Four - AttributionBBC World Service National Lottery draws See the latest results, including Lotto, EuroMillions, Set for Life and Thunderball",
metadata: {
content_type: "news",
topic_category: "current events",
reading_time_minutes: "3",
content_quality: "high",
content_analysis:
"The content is relevant and timely, addressing significant geopolitical issues while also showcasing cultural events, reflecting the BBC's diverse coverage.",
key_insights: [
"Putin is open to discussions with Zelensky if necessary, indicating a potential shift in diplomatic relations.",
"The US and Russia are engaging in talks to assess Russia's commitment to peace.",
"Natasha Bedingfield's performance highlights the intersection of music and culture on BBC platforms.",
],
},
summary:
"The BBC homepage features key news updates including potential talks between Putin and Zelensky, a performance by Natasha Bedingfield, and various cultural insights.",
tags: ["news", "politics", "entertainment", "culture", "BBC"],
word_count: "281",
timestamp: "2025-02-18T10:32:31.469815",
},
error: "None",
},
},
},
},
],
],
schema: z.object({
query: z.string(),
}),
handler: async (agent, input) => {
try {
return {
status: "success",
result: await agent.scrapeWebsiteUsingSOM(input.query),
};
} catch (e) {
return {
status: "error",
message: e,
};
}
},
};

export default scrapeWebsiteAction;
16 changes: 16 additions & 0 deletions src/agent/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -179,6 +179,7 @@ import {
getTrendingTokensUsingElfaAi,
getSmartTwitterAccountStats,
} from "../tools/elfa_ai";
import { somRouter } from "../tools/stateofmika";

/**
* Main class for interacting with Solana blockchain
Expand Down Expand Up @@ -1267,4 +1268,19 @@ export class SolanaAgentKit {
async getTrendingTokensOnCoingecko() {
return await getTrendingTokens(this);
}

async scrapeWebsiteUsingSOM(query: string) {
const response = await somRouter(this, query);
return response;
}

async evaluateMathExpressionUsingSOM(query: string) {
const response = await somRouter(this, query);
return response;
}

async getCryptoNewsUsingSom(query: string) {
const response = await somRouter(this, query);
return response;
}
}
1 change: 1 addition & 0 deletions src/tools/stateofmika/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export * from "./router";
26 changes: 26 additions & 0 deletions src/tools/stateofmika/router.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
import { SolanaAgentKit } from "../../agent";

export async function somRouter(agent: SolanaAgentKit, query: string) {
try {
if (!agent.config.SOM_API_KEY) {
throw new Error("No State of Mika API key provided");
}

const url = "https://state.gmika.io/api/v1/";
const formData = new FormData();
formData.append("query", query);

const res = await fetch(url, {
method: "POST",
headers: {
"X-API-Key": agent.config.SOM_API_KEY,
},
body: formData,
});
const data = await res.json();

return data;
} catch (e) {
throw new Error(`Error from State Of Mika router: ${e}`);
}
}
1 change: 1 addition & 0 deletions src/types/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ export interface Config {
ELFA_AI_API_KEY?: string;
COINGECKO_PRO_API_KEY?: string;
COINGECKO_DEMO_API_KEY?: string;
SOM_API_KEY?: string;
}

export interface Creator {
Expand Down
Loading