Skip to content
Merged
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: 1 addition & 1 deletion .papi/descriptors/package.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{
"version": "0.1.0-autogenerated.10336401122289269029",
"version": "0.1.0-autogenerated.15063461877034566089",
"name": "@polkadot-api/descriptors",
"files": [
"dist"
Expand Down
Binary file added .papi/metadata/paseo_people.scale
Binary file not shown.
6 changes: 6 additions & 0 deletions .papi/polkadot-api.json
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,12 @@
"metadata": ".papi/metadata/paseo.scale",
"genesis": "0x77afd6190f1554ad45fd0d31aee62aacc33c6db0ea801129acb813f913e0764f",
"codeHash": "0xcc4b027a0dbb5e0f389dd8418c41012d618290a22f84af8411c8fd20b2738304"
},
"paseo_people": {
"chain": "paseo_people",
"metadata": ".papi/metadata/paseo_people.scale",
"genesis": "0x4545454545454545454545454545454545454545454545454545454545454545",
"codeHash": "0xacf9e44512ac871585d8a389914acffbc97f5c767eed9ddef2cc0151e6d19a27"
}
}
}
5 changes: 4 additions & 1 deletion examples/telegram-bot/src/TelegramBot.ts
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ export class TelegramBot {

this.agent = new PolkadotAgentKit(privateKey as string, {
keyType: "Sr25519",
chains: ["paseo","paseo_people"]
});

this.llm = this.initializeLLM(openAiApiKey);
Expand Down Expand Up @@ -66,6 +67,7 @@ export class TelegramBot {
const unbond = this.agent.unbondTool();
const claimRewards = this.agent.claimRewardsTool();
const withdrawUnbonded = this.agent.withdrawUnbondedTool();
const registerIdentity = this.agent.registerIdentityTool();

setupHandlers(this.bot, this.llm, {
checkBalance: checkBalance,
Expand All @@ -76,7 +78,8 @@ export class TelegramBot {
bondExtra: bondExtra,
unbond: unbond,
claimRewards: claimRewards,
withdrawUnbonded: withdrawUnbonded
withdrawUnbonded: withdrawUnbonded,
registerIdentity: registerIdentity
});

console.log("Bot initialization complete");
Expand Down
16 changes: 14 additions & 2 deletions examples/telegram-bot/src/handlers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@ export const SYSTEM_PROMPT = `I am a Telegram bot powered by PolkadotAgentKit. I
- Checking WND balance on Westend (e.g., "check balance")
- Checking proxies (e.g., "check proxies on westend" or "check proxies")
- Transfer tokens through XCM (e.g., "transfer 1 WND to 5CSox4ZSN4SGLKUG9NYPtfVK9sByXLtxP4hmoF4UgkM4jgDJ from west to westend_asset_hub ")
- Register identity on People Chain (e.g., "register identity display=\"Gemini AI\" web=\"https://gemini.google.com\" twitter=\"@GoogleAI\" github=\"google\"")
- Register identity on People Chain (e.g., "register identity display=\"Gemini AI\" web=\"https://gemini.google.com\" twitter=\"@GoogleAI\" github=\"google\"")

DYNAMIC CHAIN INITIALIZATION:
When balance checking, native transfers, or XCM transfer tools fail because a chain is not available/initialized, I should:
Expand Down Expand Up @@ -178,6 +180,14 @@ Example: For "claim rewards from pool on paseo", call claimRewardsTool with:
- CRITICAL: If the user says "amount", use that value for 'slashingSpans'.
- Example: User says "withdraw unbonded with 1 amount on Paseo" -> Call 'withdrawUnbondedTool' with { slashingSpans: "1", chain: "paseo" }

3. To 'register identity' on People Chain:
- Use the 'register_identity' tool.
- - Parameters: any of the optional strings among display, legal, web, matrix, email, image, twitter, github, discord.
- - Example: User says "register identity display="Gemini AI" twitter="@GoogleAI"" -> Call 'register_identity' with { display: "Gemini AI", twitter: "@GoogleAI" }
+ - Parameters: provide at least one of: display, legal, web, matrix, email, image, twitter, github, discord (all strings, optional individually).
+ - Example A: User says "register identity with email abc@gmail.com" -> Call 'register_identity' with { email: "abc@gmail.com" }
+ - Example B: User says "register identity display="Gemini AI" twitter="@GoogleAI"" -> Call 'register_identity' with { display: "Gemini AI", twitter: "@GoogleAI" }

--- END OF TOOL-SPECIFIC RULES ---

When checking proxies, you can specify the chain (convert to real param) or not specify a chain (the first chain will be used by default)
Expand All @@ -196,7 +206,8 @@ export function setupHandlers(
'- Transferring native tokens (e.g., "transfer 1 token to westend_asset_hub to 5CSox4ZSN4SGLKUG9NYPtfVK9sByXLtxP4hmoF4UgkM4jgDJ")\n' +
'- Checking balance (e.g., "check balance on west/polkadot/kusama")\n' +
'- Checking proxies (e.g., "check proxies on westend" or "check proxies")\n' +
'- Transfer tokens through XCM (e.g., "transfer 1 WND to 5CSox4ZSN4SGLKUG9NYPtfVK9sByXLtxP4hmoF4UgkM4jgDJ from west to west_asset_hub ")\n' +
'- Transfer tokens through XCM (e.g., "transfer 1 WND to 5CSox4ZSN4SGLKUG9NYPtfVK9sByXLtxP4hmoF4UgkM4jgDJ from west to westend_asset_hub ")\n' +
'- Register identity on People Chain (e.g., "register identity display=\"Gemini AI\" web=\"https://gemini.google.com\" twitter=\"@GoogleAI\" github=\"google\"")' +
'- Bonding to a pool (e.g., "bond 100 DOT on Polkadot")\n' +
'- Re-staking rewards (e.g., "re-stake my rewards on Paseo")\n' +
'- Unbonding tokens from a pool (e.g., "unbond 100 DOT on Polkadot")\n' +
Expand Down Expand Up @@ -233,7 +244,8 @@ export function setupHandlers(
await ctx.reply(`Error: ${response.message}`);
} else {
const content = JSON.parse(response.content || "{}");
await ctx.reply(content.data || "No message from tool.");
const data = JSON.stringify(content.data);
await ctx.reply(data || "No message from tool.");
}
} else {
console.warn(`Tool not found: ${toolCall.name}`);
Expand Down
9 changes: 7 additions & 2 deletions packages/common/src/chains/chains.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import {
hydra,
paseo,
paseo_people,
polkadot,
polkadot_asset_hub,
west,
Expand All @@ -9,6 +10,7 @@ import {

import {
paseoChain,
paseoPeopleChain,
polkadotAssetHubChain,
polkadotChain,
westendAssetHubChain,
Expand All @@ -27,6 +29,7 @@ type DescriptorsAssetHubType = {

type DescriptorsParaType = {
hydra: typeof hydra
paseo_people: typeof paseo_people
}

const DESCRIPTORS_RELAY: DescriptorsRelayType = {
Expand All @@ -41,7 +44,8 @@ const DESCRIPTORS_ASSET_HUB: DescriptorsAssetHubType = {
}

const DESCRIPTORS_PARA: DescriptorsParaType = {
hydra
hydra,
paseo_people
}

export const DESCRIPTORS_ALL = {
Expand Down Expand Up @@ -111,7 +115,8 @@ const SUPPORTED_CHAINS: Chain[] = [
polkadotAssetHubChain,
westendChain,
westendAssetHubChain,
paseoChain
paseoChain,
paseoPeopleChain
]

export const getAllSupportedChains = (): Chain[] => {
Expand Down
14 changes: 14 additions & 0 deletions packages/common/src/chains/supported-chains.ts
Original file line number Diff line number Diff line change
Expand Up @@ -92,3 +92,17 @@ export const paseoChain = createChain({
decimals: 10,
symbol: "PAS"
})

export const paseoPeopleChain = createChain({
id: "paseo_people",
name: "PeoplePaseo",
specName: "paseo-people",
wsUrls: ["wss://people-paseo.dotters.network"],
relay: "paseo",
type: "system",
chainId: 1004,
blockExplorerUrl: "https://people-paseo.subscan.io/",
prefix: 0,
decimals: 10,
symbol: "PAS"
})
5 changes: 3 additions & 2 deletions packages/common/src/clients/chainSpec.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { chainSpec as paseoSpec } from "polkadot-api/chains/paseo"
import { chainSpec as paseoPeopleSpec } from "polkadot-api/chains/paseo_people"
import { chainSpec as polkadotSpec } from "polkadot-api/chains/polkadot"
import { chainSpec as polkadotAssetHubSpec } from "polkadot-api/chains/polkadot_asset_hub"
import { chainSpec as westSpec } from "polkadot-api/chains/westend2"
Expand Down Expand Up @@ -34,7 +35,6 @@ export function getChainSpec(
if (cachedSpec) {
return cachedSpec
}

// Get spec from registry
const chainSpec = specRegistry[chainId]
if (!chainSpec) {
Expand Down Expand Up @@ -74,6 +74,7 @@ export function specRegistry(): Partial<Record<ChainId, string>> {
west: westSpec,
polkadot_asset_hub: polkadotAssetHubSpec,
west_asset_hub: westAssetHubSpec,
paseo: paseoSpec
paseo: paseoSpec,
paseo_people: paseoPeopleSpec
}
}
3 changes: 2 additions & 1 deletion packages/core/src/api/client.ts
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,8 @@ export class PolkadotApi implements IPolkadotApi {
polkadot_asset_hub: "",
west_asset_hub: "",
hydra: "",
paseo: ""
paseo: "",
paseo_people: ""
}

for (const chain of supportedChains) {
Expand Down
1 change: 1 addition & 0 deletions packages/core/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
export * from "./api"
export * from "./defi/swap"
export * from "./pallets/assets"
export * from "./pallets/identity"
export * from "./pallets/nomination-pools"
export * from "./pallets/xcm"
export * from "./types"
Expand Down
1 change: 1 addition & 0 deletions packages/core/src/pallets/identity/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export * from "./register"
36 changes: 36 additions & 0 deletions packages/core/src/pallets/identity/register.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
import type { Api, ChainIdPara } from "@polkadot-agent-kit/common"

import { getRawOrNone, type Tx } from "../../types"

export const registerIdentity = (
api: Api<ChainIdPara>,
display?: string,
legal?: string,
web?: string,
matrix?: string,
email?: string,
image?: string,
twitter?: string,
github?: string,
discord?: string
): Tx => {
const identityInfo = {
display: getRawOrNone(display),
legal: getRawOrNone(legal),
web: getRawOrNone(web),
matrix: getRawOrNone(matrix),
email: getRawOrNone(email),
image: getRawOrNone(image),
twitter: getRawOrNone(twitter),
github: getRawOrNone(github),
discord: getRawOrNone(discord),
pgp_fingerprint: undefined
}

const setIdentityCall = api.tx.Identity.set_identity({
// eslint-disable-next-line @typescript-eslint/no-explicit-any, @typescript-eslint/no-unsafe-assignment
info: identityInfo as any
})

return setIdentityCall
}
25 changes: 25 additions & 0 deletions packages/core/src/types/identity.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
import type { IdentityData } from "@polkadot-api/descriptors"
import type { FixedSizeArray } from "polkadot-api"
import { FixedSizeBinary } from "polkadot-api"

export const getRawFromValue = (value: string) => `Raw${value.length}`

export const getRawOrNone = (value?: string) => {
return (
value
? { type: getRawFromValue(value), value: FixedSizeBinary.fromText(value) }
: { type: "None" }
) as IdentityData
}

export interface IdentityInfoPayload {
additional: FixedSizeArray<2, IdentityData>[]
display: IdentityData
legal: IdentityData
web: IdentityData
riot: IdentityData
email: IdentityData
pgp_fingerprint: FixedSizeBinary<20> | undefined
image: IdentityData
twitter: IdentityData
}
1 change: 1 addition & 0 deletions packages/core/src/types/index.ts
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
export * from "./identity"
export * from "./transaction"
13 changes: 13 additions & 0 deletions packages/llm/src/agent/api.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import {
claimRewardsTool,
initializeChainApiTool,
joinPoolTool,
registerIdentityTool,
swapTokensTool,
transferNativeTool,
unbondTool,
Expand All @@ -19,6 +20,7 @@ import type {
ClaimRewardsTool,
InitializeChainApiTool,
JoinPoolTool,
RegisterIdentityTool,
SwapTokensTool,
TransferTool,
UnbondTool,
Expand Down Expand Up @@ -97,6 +99,13 @@ export interface IPolkadotAgentApi {
* @returns A dynamic structured tool that claims rewards
*/
claimRewardsTool(signer: PolkadotSigner): ClaimRewardsTool

/**
* Returns a tool that registers an identity on People Chain
* @param signer - The signer to use for transactions
* @returns A dynamic structured tool that registers an identity on People Chain
*/
registerIdentityTool(signer: PolkadotSigner): RegisterIdentityTool
}

/**
Expand Down Expand Up @@ -152,4 +161,8 @@ export class PolkadotAgentApi implements IPolkadotAgentApi {
claimRewardsTool(signer: PolkadotSigner): ClaimRewardsTool {
return claimRewardsTool(this.api, signer) as unknown as ClaimRewardsTool
}

registerIdentityTool(signer: PolkadotSigner): RegisterIdentityTool {
return registerIdentityTool(this.api, signer) as unknown as RegisterIdentityTool
}
}
58 changes: 58 additions & 0 deletions packages/llm/src/langchain/identity.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
import { tool } from "@langchain/core/tools"
import type { Api, ChainIdPara } from "@polkadot-agent-kit/common"
import type { PolkadotApi } from "@polkadot-agent-kit/core"
import { registerIdentity, submitTxWithPolkadotSigner } from "@polkadot-agent-kit/core"
import type { PolkadotSigner } from "polkadot-api"
import type z from "zod"

import type { registerIdentitySchema, RegisterIdentityToolResult } from "../types"
import { toolConfigRegisterIdentity, ToolNames } from "../types"
import { executeTool } from "../utils"

export const registerIdentityTool = (polkadotApi: PolkadotApi, signer: PolkadotSigner) => {
return tool(
async ({
display,
legal,
web,
matrix,
email,
image,
twitter,
github,
discord
}: z.infer<typeof registerIdentitySchema>) => {
return executeTool<RegisterIdentityToolResult>(ToolNames.REGISTER_IDENTITY, async () => {
const api = polkadotApi.getApi("paseo_people") as Api<ChainIdPara>
const tx = registerIdentity(
api,
display,
legal,
web,
matrix,
email,
image,
twitter,
github,
discord
)

const result = await submitTxWithPolkadotSigner(tx, signer)

if (result.success) {
return {
success: result.success,
transactionHash: result.transactionHash
}
} else {
return {
success: false,
transactionHash: result.transactionHash,
error: result.error
}
}
})
},
toolConfigRegisterIdentity
)
}
1 change: 1 addition & 0 deletions packages/llm/src/langchain/index.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
export * from "./balance"
export * from "./chain"
export * from "./defi/swap"
export * from "./identity"
export * from "./staking"
export * from "./transfer"
export * from "./xcm"
4 changes: 3 additions & 1 deletion packages/llm/src/types/common.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,9 @@ export enum ToolNames {
/** Tool for claiming rewards from a nomination pool */
CLAIM_REWARDS = "claim_rewards",
/** Tool for getting nomination pool information */
GET_POOL_INFO = "get_pool_info"
GET_POOL_INFO = "get_pool_info",
/** Tool for registering an identity on People Chain */
REGISTER_IDENTITY = "register_identity"
}

/**
Expand Down
Loading