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: improvements for plugin-cosmos #1934

Merged
merged 35 commits into from
Jan 8, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
35 commits
Select commit Hold shift + click to select a range
5798691
feat: add transfer action
KacperKoza343 Dec 24, 2024
7afa010
update: improve tests
KacperKoza343 Dec 24, 2024
4aa9d2d
update: improve according to CR suggestions
KacperKoza343 Dec 24, 2024
2bd8aa6
update: format code accroding to eslint config
KacperKoza343 Dec 30, 2024
4c8605e
Merge remote-tracking branch 'origin/develop' into ELIZAAI-16-token-t…
stanislawkurzypBD Dec 31, 2024
38bc2e1
ELIZAAI-16 Implemented token transfer with use of wallet provider
stanislawkurzypBD Jan 2, 2025
0e90f7e
[ELIZAAI-16](feat): cosmos wallet provider with balances
norbert-kulus-blockydevs Jan 2, 2025
331c643
ELIZAAI-16 Improved AI actor responses, added storing memory about co…
stanislawkurzypBD Jan 2, 2025
ea22ba3
[ELIZAAI-16](fix): fix conflicts after new cosmos provider implementa…
norbert-kulus-blockydevs Jan 2, 2025
c2e9dc2
[ELIZAAI-16](fix): instantalizate cosmosWalletProvider before passing…
norbert-kulus-blockydevs Jan 2, 2025
15f3f67
[ELIZAAI-16](feat): display coins in display denom, not base denom
norbert-kulus-blockydevs Jan 2, 2025
8979cef
[ELIZAAI-16](fix): use base denom if cannot find symbol of coin in as…
norbert-kulus-blockydevs Jan 2, 2025
7c7f70d
[ELIZAAI-16](fix): wallet base unit
norbert-kulus-blockydevs Jan 2, 2025
81a3328
[ELIZAAI-16](fix): add chain name
norbert-kulus-blockydevs Jan 2, 2025
84dff3c
ELIZAAI-16 Provider improvements
stanislawkurzypBD Jan 2, 2025
00cfb42
Merge remote-tracking branch 'origin/ELIZAAI-16-token-transfer' into …
norbert-kulus-blockydevs Jan 2, 2025
ab56e1a
Merge pull request #7 from blockydevs/ELIZAAI-16-wallet-provider
norbert-kulus-blockydevs Jan 2, 2025
80b0da3
[ELIZAAI-16](feat): clean up token transfer
norbert-kulus-blockydevs Jan 2, 2025
8f04d7b
Merge pull request #8 from blockydevs/ELIZAAI-16-clean-up-token-transfer
norbert-kulus-blockydevs Jan 2, 2025
d7d454f
[ELIZAAI-16](chore): remove chains from (default)character settings
norbert-kulus-blockydevs Jan 2, 2025
ede80f0
[ELIZAAI-16](chore): update messages thrown by cosmos assistant
norbert-kulus-blockydevs Jan 2, 2025
fdc81a7
[ELIZAAI-16](feat): custom chains and assets data
norbert-kulus-blockydevs Jan 3, 2025
46a24ad
[ELIZAAI-16](fix): add optional chaining for getAvailableChains and g…
norbert-kulus-blockydevs Jan 3, 2025
dd3e887
Merge pull request #9 from blockydevs/ELIZAAI-16-custom-chains-and-as…
norbert-kulus-blockydevs Jan 3, 2025
1117431
ELIZAAI-16 Fixed gasFee bug, reworked cosmos helper character
stanislawkurzypBD Jan 3, 2025
969f298
ELIZAAI-16 Unit test coverage increased, Added missing env to .env.ex…
stanislawkurzypBD Jan 3, 2025
6e71dfb
feat(): improve unit tests
migace Jan 7, 2025
ef9819f
Merge branch 'develop' into ELIZAAI-16-unit-tests
migace Jan 7, 2025
e5737c6
Merge pull request #13 from blockydevs/ELIZAAI-16-unit-tests
mgacek-blockydevs Jan 7, 2025
6a8b7d5
fix(): code style
migace Jan 7, 2025
556a265
fix(): code style
migace Jan 7, 2025
3db0363
fix(): code style
migace Jan 7, 2025
fd5da73
Merge remote-tracking branch 'eliza/develop' into develop
migace Jan 7, 2025
8ea5965
fix(): code style
migace Jan 7, 2025
ef85bda
Merge branch 'develop' into develop
mgacek-blockydevs Jan 7, 2025
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
3 changes: 3 additions & 0 deletions .env.example
Original file line number Diff line number Diff line change
Expand Up @@ -387,6 +387,9 @@ STORY_API_BASE_URL= # Story API base URL
STORY_API_KEY= # Story API key
PINATA_JWT= # Pinata JWT for uploading files to IPFS

# Cosmos
COSMOS_RECOVERY_PHRASE= # 12 words recovery phrase (need to be in quotes, because of spaces)
COSMOS_AVAILABLE_CHAINS= # mantrachaintestnet2,cosmos # Array of chains
# Cronos zkEVM
CRONOSZKEVM_ADDRESS=
CRONOSZKEVM_PRIVATE_KEY=
Expand Down
4 changes: 4 additions & 0 deletions agent/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@ import { confluxPlugin } from "@elizaos/plugin-conflux";
import { cronosZkEVMPlugin } from "@elizaos/plugin-cronoszkevm";
import { echoChambersPlugin } from "@elizaos/plugin-echochambers";
import { evmPlugin } from "@elizaos/plugin-evm";
import { createCosmosPlugin } from "@ai16z/plugin-cosmos";
import { flowPlugin } from "@elizaos/plugin-flow";
import { fuelPlugin } from "@elizaos/plugin-fuel";
import { genLayerPlugin } from "@elizaos/plugin-genlayer";
Expand Down Expand Up @@ -577,6 +578,9 @@ export async function createAgent(
getSecret(character, "WALLET_PUBLIC_KEY")?.startsWith("0x"))
? evmPlugin
: null,
getSecret(character, "COSMOS_RECOVERY_PHRASE") &&
getSecret(character, "COSMOS_AVAILABLE_CHAINS") &&
createCosmosPlugin(),
(getSecret(character, "SOLANA_PUBLIC_KEY") ||
(getSecret(character, "WALLET_PUBLIC_KEY") &&
!getSecret(character, "WALLET_PUBLIC_KEY")?.startsWith(
Expand Down
36 changes: 10 additions & 26 deletions characters/cosmosHelper.character.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,15 +3,14 @@
"clients": [],
"modelProvider": "groq",
"settings": {
"secrets": {},
"voice": {
"model": "en_US-male-medium"
},
"chains": {
"cosmos": ["axelar", "carbon", "mantrachaintestnet2"]
}
},
"plugins": ["@ai16z/plugin-cosmos","@ai16z/plugin-bootstrap"],
"plugins": [],
"bio": [
"Expert in Cosmos ecosystem.",
"Knowledgeable in CosmWasm and Stargate.",
Expand All @@ -24,37 +23,22 @@
"Supports projects and interactions within the Cosmos ecosystem."
],
"knowledge": [
"knows EXACT cost to families under Kamala ($29,000)",
"understands REAL border numbers (worse than reported)",
"saw what really happened in Minneapolis 2020",
"remembers who begged for help (and when)",
"knows why Iran's president targeting us",
"understands Secret Service allocation (and why they do it)",
"knows REAL rally numbers (they hide them)",
"saw the TRUTH about China Virus response",
"understands states' rights better than anyone",
"knows why they're letting in illegal guns",
"remembers when America was AFFORDABLE",
"understands the REAL election interference",
"knows why they're scared of WorldLibertyFi",
"saw what they did to women's sports",
"understands the REAL Middle East situation",
"knows why missiles flying everywhere now",
"remembers perfect peace under Trump presidency",
"understands Democrat election strategy (letting in MILLIONS)",
"knows Kamala's REAL tax plans (coming for everything)",
"saw what they did to Minneapolis (and other cities)"
"Knows how Cosmos blockchain works",
"Knows what actions should he call for token transfer, swapping or bridging",
"Knows that users might want to do specific actions multiple times and should help them by doing it again.",
"Should always ask for confirmation before calling an COSMOS_TRANSFER, COSMOS_BRIDGE, COSMOS_SWAP actions.",
"Should call actions COSMOS_TRANSFER, COSMOS_BRIDGE, COSMOS_SWAP only after previous confirmation."
],
"messageExamples": [
[
{
"user": "{{user1}}",
"content": { "text": "Can you explain the Cosmos Hub?" }
"content": { "text": "Show my balances of my wallet on {{mantrachaintestnet2}}" }
},
{
"user": "CosmosHelper",
"content": {
"text": "The Cosmos Hub is the central blockchain in the Cosmos ecosystem, facilitating interoperability between connected blockchains."
"text": "Your balances on chain {{mantrachaintestnet2}} are: \n - 13456.124 OM\n - 1222 ONDO\n 0.122122 USDY"
}
}
],
Expand Down Expand Up @@ -97,12 +81,12 @@
[
{
"user": "{{user1}}",
"content": { "text": "What are validators?" }
"content": { "text": "Make transfer 0.0001 OM to mantra13248w8dtnn07sxc3gq4l3ts4rvfyat6fks0ecj on mantrachaintestnet2" }
},
{
"user": "CosmosHelper",
"content": {
"text": "Validators are responsible for securing the network by validating transactions and producing new blocks. They earn rewards through staking."
"text": "Sure, your transfer i being processed."
}
}
]
Expand Down
6 changes: 5 additions & 1 deletion packages/plugin-cosmos/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -13,12 +13,16 @@
"bignumber.js": "9.1.2",
"chain-registry": "^1.69.68",
"tsup": "8.3.5",
"zod": "3.23.8"
"zod": "3.23.8",
"interchain": "^1.10.4"
},
"scripts": {
"build": "tsup --format esm --dts",
"dev": "tsup --format esm --dts --watch",
"lint": "eslint --fix --cache .",
"test": "vitest run"
},
"devDependencies": {
"@chain-registry/types": "^0.50.44"
}
}
216 changes: 216 additions & 0 deletions packages/plugin-cosmos/src/actions/transfer/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,216 @@
import {
composeContext,
generateObjectDeprecated,
HandlerCallback,
IAgentRuntime,
Memory,
ModelClass,
State,
} from "@ai16z/eliza";
import { initWalletChainsData } from "../../providers/wallet/utils";
import { cosmosTransferTemplate } from "../../templates";
import { CosmosTransferActionService } from "./services/cosmos-transfer-action-service";
import type { CosmosTransferParams } from "./types";
import type {
ICosmosPluginOptions,
ICosmosWalletChains,
} from "../../shared/interfaces";

export const createTransferAction = (pluginOptions: ICosmosPluginOptions) => ({
name: "COSMOS_TRANSFER",
description: "Transfer tokens between addresses on the same chain",
handler: async (
_runtime: IAgentRuntime,
_message: Memory,
state: State,
_options: { [key: string]: unknown },
_callback?: HandlerCallback
) => {
const cosmosTransferContext = composeContext({
state: state,
template: cosmosTransferTemplate,
templatingEngine: "handlebars",
});

const cosmosTransferContent = await generateObjectDeprecated({
runtime: _runtime,
context: cosmosTransferContext,
modelClass: ModelClass.SMALL,
});

const paramOptions: CosmosTransferParams = {
chainName: cosmosTransferContent.chainName,
symbol: cosmosTransferContent.symbol,
amount: cosmosTransferContent.amount,
toAddress: cosmosTransferContent.toAddress,
};

try {
const walletProvider: ICosmosWalletChains =
await initWalletChainsData(_runtime);

const action = new CosmosTransferActionService(walletProvider);

const customAssets = (pluginOptions?.customChainData ?? []).map(
(chainData) => chainData.assets
);

const transferResp = await action.execute(
paramOptions,
customAssets
);

if (_callback) {
await _callback({
text: `Successfully transferred ${paramOptions.amount} tokens to ${paramOptions.toAddress}\nGas paid: ${transferResp.gasPaid}\nTransaction Hash: ${transferResp.txHash}`,
content: {
success: true,
hash: transferResp.txHash,
amount: paramOptions.amount,
recipient: transferResp.to,
chain: cosmosTransferContent.fromChain,
},
});

const newMemory: Memory = {
userId: _message.agentId,
agentId: _message.agentId,
roomId: _message.roomId,
content: {
text: `Transaction ${paramOptions.amount} ${paramOptions.symbol} to address ${paramOptions.toAddress} on chain ${paramOptions.toAddress} was successfully transfered.\n Gas paid: ${transferResp.gasPaid}. Tx hash: ${transferResp.txHash}`,
},
};

await _runtime.messageManager.createMemory(newMemory);
}
return true;
} catch (error) {
console.error("Error during token transfer:", error);

if (_callback) {
await _callback({
text: `Error transferring tokens: ${error.message}`,
content: { error: error.message },
});
}

const newMemory: Memory = {
userId: _message.agentId,
agentId: _message.agentId,
roomId: _message.roomId,
content: {
text: `Transaction ${paramOptions.amount} ${paramOptions.symbol} to address ${paramOptions.toAddress} on chain ${paramOptions.toAddress} was unsuccessful.`,
},
};

await _runtime.messageManager.createMemory(newMemory);

return false;
}
},
template: cosmosTransferTemplate,
validate: async (runtime: IAgentRuntime) => {
const mnemonic = runtime.getSetting("COSMOS_RECOVERY_PHRASE");
const availableChains = runtime.getSetting("COSMOS_AVAILABLE_CHAINS");
const availableChainsArray = availableChains?.split(",");

return !(mnemonic && availableChains && availableChainsArray.length);
},
examples: [
[
{
user: "{{user1}}",
content: {
text: "Make transfer {{0.0001 OM}} to {{mantra1pcnw46km8m5amvf7jlk2ks5std75k73aralhcf}} on {{mantrachaintestnet2}}",
action: "COSMOS_TRANSFER",
},
},
{
user: "{{user2}}",
content: {
text: "Do you confirm the transfer action?",
action: "COSMOS_TRANSFER",
},
},
{
user: "{{user1}}",
content: {
text: "Yes",
action: "COSMOS_TRANSFER",
},
},
{
user: "{{user2}}",
content: {
text: "",
action: "COSMOS_TRANSFER",
},
},
],
[
{
user: "{{user1}}",
content: {
text: "Send {{10 OSMO}} to {{osmo13248w8dtnn07sxc3gq4l3ts4rvfyat6f4qkdd6}} on {{osmosistestnet}}",
action: "COSMOS_TRANSFER",
},
},
{
user: "{{user2}}",
content: {
text: "Do you confirm the transfer action?",
action: "COSMOS_TRANSFER",
},
},
{
user: "{{user1}}",
content: {
text: "Yes",
action: "COSMOS_TRANSFER",
},
},
{
user: "{{user2}}",
content: {
text: "",
action: "COSMOS_TRANSFER",
},
},
],
[
{
user: "{{user1}}",
content: {
text: "Send {{0.0001 OM}} on {{mantrachaintestnet2}} to {{mantra1pcnw46km8m5amvf7jlk2ks5std75k73aralhcf}}.",
action: "COSMOS_TRANSFER",
},
},
{
user: "{{user2}}",
content: {
text: "Do you confirm the transfer action?",
action: "COSMOS_TRANSFER",
},
},
{
user: "{{user1}}",
content: {
text: "Yes",
action: "COSMOS_TRANSFER",
},
},
{
user: "{{user2}}",
content: {
text: "",
action: "COSMOS_TRANSFER",
},
},
],
],
similes: [
"COSMOS_SEND_TOKENS",
"COSMOS_TOKEN_TRANSFER",
"COSMOS_MOVE_TOKENS",
],
});
8 changes: 8 additions & 0 deletions packages/plugin-cosmos/src/actions/transfer/schema.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
import { z } from "zod";

export const cosmosTransferParamsSchema = z.object({
chainName: z.string(),
symbol: z.string(),
amount: z.string(),
toAddress: z.string(),
});
Loading
Loading