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

Realm #297

Open
wants to merge 8 commits into
base: main
Choose a base branch
from
Open

Realm #297

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
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,7 @@
"ethers": "^6.13.5",
"flash-sdk": "^2.24.3",
"form-data": "^4.0.1",
"governance-idl-sdk": "^0.0.4",
"langchain": "^0.3.8",
"openai": "^4.77.0",
"tiktoken": "^1.0.18",
Expand Down
16 changes: 16 additions & 0 deletions pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

14 changes: 14 additions & 0 deletions src/actions/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -109,6 +109,13 @@ import getCoingeckoTokenPriceDataAction from "./coingecko/getCoingeckoTokenPrice
import getCoingeckoTopGainersAction from "./coingecko/getCoingeckoTopGainers";
import getCoingeckoTrendingPoolsAction from "./coingecko/getCoingeckoTrendingPools";
import getCoingeckoTrendingTokensAction from "./coingecko/getCoingeckoTrendingTokens";
import castVoteAction from "./realm-governance/cast-vote";
import getRealmInfoAction from "./realm-governance/realm-info";
import createRealmAction from "./realm-governance/create-realm";
import createProposalAction from "./realm-governance/create-proposal";
import getVoterHistoryAction from "./realm-governance/voter-history";
import getTokenOwnerRecordAction from "./realm-governance/owner-record";

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please remove unnecessary white spaces/lines from any files that may have them


export const ACTIONS = {
GET_INFO_ACTION: getInfoAction,
Expand Down Expand Up @@ -226,6 +233,13 @@ export const ACTIONS = {
GET_COINGECKO_TOP_GAINERS_ACTION: getCoingeckoTopGainersAction,
GET_COINGECKO_TRENDING_POOLS_ACTION: getCoingeckoTrendingPoolsAction,
GET_COINGECKO_TRENDING_TOKENS_ACTION: getCoingeckoTrendingTokensAction,
CAST_VOTE_ACTION: castVoteAction,
GET_REALM_INFO_ACTION: getRealmInfoAction,
CREATE_REALM_ACTION: createRealmAction,
CREATE_PROPOSAL_ACTION: createProposalAction,
GET_VOTER_HISTORY_ACTION: getVoterHistoryAction,
GET_TOKEN_OWNER_RECORD_ACTION: getTokenOwnerRecordAction,

};

export type { Action, ActionExample, Handler } from "../types/action";
69 changes: 69 additions & 0 deletions src/actions/realm-governance/cast-vote.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
import { PublicKey } from "@solana/web3.js";
import { z } from "zod";
import { SolanaAgentKit } from "../../agent";
import { Action, VoteConfig } from "../../types";

const castVoteAction: Action = {
name: "SPL_CAST_VOTE",
similes: [
"vote on proposal",
"cast dao vote",
"submit governance vote",
"vote on dao motion",
"participate in dao governance",
"cast ballot on proposal",
],
description: "Cast a vote on an existing proposal in a DAO",
examples: [
[
{
input: {
proposal: "2ZE7Rz...",
tokenOwnerRecord: "8gYZR...",
},
output: {
status: "success",
voteRecordAddress: "5PmxV...",
message: "Successfully cast vote on proposal",
},
explanation: "Cast a vote on an existing proposal",
},
],
],
schema: z.object({
proposal: z.string().min(1).describe("Address of the proposal to vote on"),
tokenOwnerRecord: z
.string()
.min(1)
.describe("Token owner record address for voting"),

}),
handler: async (agent: SolanaAgentKit, input: Record<string, any>) => {
try {

const voteConfig: VoteConfig = {
proposal: new PublicKey(input.proposal),
tokenOwnerRecord: new PublicKey(input.tokenOwnerRecord),
realm: new PublicKey("11111111111111111111111111111111"),
choice: 0,
governingTokenMint: new PublicKey("11111111111111111111111111111111"),
governance: new PublicKey("11111111111111111111111111111111")
};

const result = await agent.castVote(voteConfig);

return {
status: "success",
voteRecordAddress: result.toString(),
message: "Successfully cast vote on proposal",
};
} catch (error: any) {
return {
status: "error",
message: `Failed to cast vote: ${error.message}`,
};
}
},
};

export default castVoteAction;
75 changes: 75 additions & 0 deletions src/actions/realm-governance/create-proposal.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,75 @@
import { PublicKey } from "@solana/web3.js";
import { z } from "zod";
import { SolanaAgentKit } from "../../agent";
import { Action } from "../../types";

const createProposalAction: Action = {
name: "SPL_CREATE_PROPOSAL",
similes: [
"create dao proposal",
"submit governance proposal",
"initiate dao vote",
"propose dao action",
"start governance vote",
"submit dao motion",
],
description:
"Create a new proposal in a DAO realm for community or council voting",
examples: [
[
{
input: {
realm: "7nxQB...",
name: "Treasury Funding Allocation",
description: "Proposal to allocate 1000 tokens to the development team",
governingTokenMint: "EPjFWdd5AufqSSqeM2qN1xzybapC8G4wEGGkZwyTDt1v",
voteType: "single-choice",
},
output: {
status: "success",
proposalAddress: "2ZE7Rz...",
message: "Successfully created proposal for community voting",
},
explanation:
"Create a single-choice proposal for community members to vote on",
},
],
],
schema: z.object({
realm: z.string().min(1).describe("Address of the DAO realm"),
name: z.string().min(1).describe("Name of the proposal"),
description: z.string().min(1).describe("Description of the proposal"),
governingTokenMint: z
.string()
.min(1)
.describe("Token mint address for voting (community or council)"),
voteType: z
.enum(["single-choice", "multiple-choice"])
.describe("Type of voting mechanism for the proposal"),
}),
handler: async (agent: SolanaAgentKit, input: Record<string, any>) => {
try {
const result = await agent.createProposal(new PublicKey(input.realm), {
name: input.name,
description: input.description,
governingTokenMint: new PublicKey(input.governingTokenMint),
voteType: input.voteType,
options: ["Approve", "Deny"],
});

return {
status: "success",
proposalAddress: result.toString(),
message: `Successfully created proposal: ${input.name}`,
};
} catch (error: any) {
return {
status: "error",
message: `Failed to create proposal: ${error.message}`,
};
}
},
};


export default createProposalAction;
77 changes: 77 additions & 0 deletions src/actions/realm-governance/create-realm.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,77 @@
import { PublicKey } from "@solana/web3.js";
import { z } from "zod";
import { SolanaAgentKit } from "../../agent";
import { Action } from "../../types";

const createRealmAction: Action = {
name: "SPL_CREATE_REALM",
similes: [
"create dao realm",
"initialize governance realm",
"setup dao",
"create governance entity",
"establish dao space",
"initialize dao organization",
],
description:
"Create a new DAO realm with specified configuration for on-chain governance",
examples: [
[
{
input: {
name: "My Community DAO",
communityMint: "EPjFWdd5AufqSSqeM2qN1xzybapC8G4wEGGkZwyTDt1v",
minCommunityTokens: 1000,
councilMint: "So11111111111111111111111111111111111111112",
},
output: {
status: "success",
realmAddress: "7nxQB...",
message: "Successfully created DAO realm",
},
explanation:
"Create a new DAO realm with community and council tokens for governance",
},
],
],
schema: z.object({
name: z.string().min(1).describe("Name of the DAO realm"),
communityMint: z
.string()
.min(1)
.describe("Address of the community token mint"),
minCommunityTokens: z
.number()
.positive()
.describe("Minimum community tokens required to create governance"),
councilMint: z
.string()
.optional()
.describe("Optional address of the council token mint"),
}),
handler: async (agent: SolanaAgentKit, input: Record<string, any>) => {
try {
const result = await agent.createRealm({
name: input.name,
communityMint: new PublicKey(input.communityMint),
minCommunityTokensToCreateGovernance: input.minCommunityTokens,
councilMint: input.councilMint
? new PublicKey(input.councilMint)
: undefined,
});

return {
status: "success",
realmAddress: result.toString(),
message: `Successfully created realm: ${input.name}`,
};
} catch (error: any) {
return {
status: "error",
message: `Failed to create realm: ${error.message}`,
};
}
},
};

export default createRealmAction;
71 changes: 71 additions & 0 deletions src/actions/realm-governance/owner-record.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@
import { PublicKey } from "@solana/web3.js";
import { z } from "zod";
import { SolanaAgentKit } from "../../agent";
import { Action } from "../../types";

const getTokenOwnerRecordAction: Action = {
name: "SPL_GET_TOKEN_OWNER_RECORD",
similes: [
"check dao membership status",
"get governance token holdings",
"view dao member record",
"check voting power",
"verify dao participation rights",
"view governance token record",
],
description: "Get token owner record for a member in a DAO realm",
examples: [
[
{
input: {
realm: "7nxQB...",
governingTokenMint: "EPjF...",
governingTokenOwner: "DqYm...",
},
output: {
status: "success",
tokenOwnerRecord: {
governingTokenOwner: "DqYm...",
tokenBalance: 5000,
// other member data
},
message: "Successfully retrieved token owner record",
},
explanation: "Retrieve a member's voting power and participation record",
},
],
],
schema: z.object({
realm: z.string().min(1).describe("Address of the DAO realm"),
governingTokenMint: z
.string()
.min(1)
.describe("Token mint address for voting (community or council)"),
governingTokenOwner: z
.string()
.min(1)
.describe("Address of the token owner/member"),
}),
handler: async (agent: SolanaAgentKit, input: Record<string, any>) => {
try {
const result = await agent.getTokenOwnerRecord(
new PublicKey(input.realm),
new PublicKey(input.governingTokenMint),
new PublicKey(input.governingTokenOwner)
);

return {
status: "success",
tokenOwnerRecord: result,
message: "Successfully retrieved token owner record",
};
} catch (error: any) {
return {
status: "error",
message: `Failed to get token owner record: ${error.message}`,
};
}
},
};

export default getTokenOwnerRecordAction;
Loading