Skip to content

Commit

Permalink
Merge branch 'refs/heads/ELIZAAI-18-cross-chain-swaps' into test
Browse files Browse the repository at this point in the history
# Conflicts:
#	agent/src/index.ts
#	packages/plugin-cosmos/src/index.ts
#	pnpm-lock.yaml
  • Loading branch information
stanislawkurzypBD committed Jan 13, 2025
2 parents 82607be + b14ba88 commit 941f811
Show file tree
Hide file tree
Showing 30 changed files with 5,494 additions and 3,957 deletions.
1 change: 1 addition & 0 deletions agent/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,7 @@ import { createCosmosPlugin } from "@elizaos/plugin-cosmos";
import { cronosZkEVMPlugin } from "@elizaos/plugin-cronoszkevm";
import { echoChambersPlugin } from "@elizaos/plugin-echochambers";
import { evmPlugin } from "@elizaos/plugin-evm";
import { createCosmosPlugin } from "@elizaos/plugin-cosmos";
import { flowPlugin } from "@elizaos/plugin-flow";
import { fuelPlugin } from "@elizaos/plugin-fuel";
import { genLayerPlugin } from "@elizaos/plugin-genlayer";
Expand Down
27 changes: 21 additions & 6 deletions characters/cosmosHelper.character.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,11 @@
"model": "en_US-male-medium"
},
"chains": {
"cosmos": ["axelar", "carbon", "mantrachaintestnet2"]
"cosmos": [
"axelar",
"carbon",
"mantrachaintestnet2"
]
}
},
"plugins": [],
Expand All @@ -27,13 +31,16 @@
"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 ask for confirmation ONCE and perform action after getting it. If user wants to change sth in data for transfer, should do it and ask again for confirmation of new data.",
"Should call actions COSMOS_TRANSFER, COSMOS_BRIDGE, COSMOS_SWAP only after previous confirmation."
],
"messageExamples": [
[
{
"user": "{{user1}}",
"content": { "text": "Show my balances of my wallet on {{mantrachaintestnet2}}" }
"content": {
"text": "Show my balances of my wallet on {{mantrachaintestnet2}}"
}
},
{
"user": "CosmosHelper",
Expand All @@ -45,7 +52,9 @@
[
{
"user": "{{user1}}",
"content": { "text": "How does IBC work?" }
"content": {
"text": "How does IBC work?"
}
},
{
"user": "CosmosHelper",
Expand All @@ -57,7 +66,9 @@
[
{
"user": "{{user1}}",
"content": { "text": "What is CosmWasm?" }
"content": {
"text": "What is CosmWasm?"
}
},
{
"user": "CosmosHelper",
Expand All @@ -69,7 +80,9 @@
[
{
"user": "{{user1}}",
"content": { "text": "Can you help me transfer tokens?" }
"content": {
"text": "Can you help me transfer tokens?"
}
},
{
"user": "CosmosHelper",
Expand All @@ -81,7 +94,9 @@
[
{
"user": "{{user1}}",
"content": { "text": "Make transfer 0.0001 OM to mantra13248w8dtnn07sxc3gq4l3ts4rvfyat6fks0ecj on mantrachaintestnet2" }
"content": {
"text": "Make transfer 0.0001 OM to mantra13248w8dtnn07sxc3gq4l3ts4rvfyat6fks0ecj on mantrachaintestnet2"
}
},
{
"user": "CosmosHelper",
Expand Down
112 changes: 112 additions & 0 deletions packages/plugin-cosmos/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -102,8 +102,120 @@ Yes

4. Action executed.

### Token IBC Transfer

This plugin supports a token transfer action, which allows users to transfer tokens between addresses on Cosmos-compatible blockchains between different chains.

#### Requirements

You need to set both chain that you want to transfer founds between in env file. For example:

```
COSMOS_AVAILABLE_CHAINS=osmosistestnet,neutrontestnet
```

If you want to transfer your tokens between Osmosis Testnet and Neutron Testnet

#### Example Prompts

Below are examples of how the ibc transfer action can be initiated and confirmed:

**Example**

1. User input:

```
Make an IBC transfer 0.0001 OSMO to neutron1nk3uuw6zt5t5aqw5fvujkd54sa4uws9xg2nk82 from osmosistestnet to neutrontestnet
```

2. Plugin response:

```
Before making the IBC transfer, I would like to confirm the details. You would like to transfer 0.0001 OSMO from osmosistestnet to neutrontestnet, specifically to the address neutron1nk3uuw6zt5t5aqw5fvujkd54sa4uws9xg2nk82, is that correct?
```

3. User confirmation:

```
Yes
```

4. Action executed.

---

### Token IBC Swap
This action allows swapping tokens between chains. The implementation of swapping is based on the Skip API and uses the @skip-go/client library.
To place transactions on chains, they must first be added to the env file. Specifically:
```env
COSMOS_AVAILABLE_CHAINS=osmosis,neutron,axelar,cosmoshub,terra2,pryzm
```
Keep in mind that most swaps require intermediate chains. These chains must also be included in the env file.

You can check which chains are supported by the Skip API and this plugin here: Skip API Documentation.

The list below contains all supported chains extracted from the Skip API:
```env
COSMOS_AVAILABLE_CHAINS=terra2,quicksilver,coreum,regen,mars,passage,dhealth,lumnetwork,provenance,chihuahua,pryzm,fetchhub,comdex,kyve,xpla,umee,celestia,osmosis,empowerchain,migaloo,dymension,kujira,self,humans,gitopia,agoric,doravota,int3face,quasar,gravitybridge,kava,sifchain,seda,shentu,decentr,cronos,carbon,stride,haqq,jackal,omniflixhub,noble,sentinel,nolus,odin,assetmantle,dydx,beezee,axelar,nois,mantrachain,elys,crescent,synternet,xion,source,akash,sei,canto,teritori,stargaze,titan,aura,evmos,archway,gateway,cheqd,milkyway,nibiru,cosmoshub,ununifi,nyx,bitsong,cryptoorgchain,neutron,penumbra,terra,shido,sommelier,saga,secretnetwork,chain4energy,juno,andromeda,planq,lava,oraichain,injective,persistence,composable
```

#### Example prompts:

##### Default flow
An example of the default flow of a swap request:

1. User input:
```
Swap 10 OSMO on osmosis to ATOM on cosmoshub
```
2. Agent asks for confirmation:
```
About to swap 10 OSMO on osmosis to ATAOM on cosmoshub. I would like to confirm the transaction details. Please confirm that you would like to proceed with the swap.
```
3. User confiramation:
```
confirming / yes
```
4. Agent calls action and responds after completing:
```
Successfuly swapped 10 OSMO tokens to ATOM on chain cosmoshub.
Transaction Hash: E84F36D6EEFAA6D7B70827F34EDAB83258BB86EFE33AEA1F4559D00B30CD3B50
```

##### Special case handling
An example of a flow when there is more than one token with the same symbol on the destination chain (e.g., multiple USDC tokens):
1. User input:
```
Swap 10 OSMO on osmosis to ATOM on cosmoshub
```
2. Agent asks for confirmation:
```
About to swap 10 OSMO on osmosis to ATAOM on cosmoshub. I would like to confirm the transaction details. Please confirm that you would like to proceed with the swap.
```
3. User confirmation:
```
confirming / yes
```
4. Model response:
```
I will now initiate the swap of 10 OSMO on the Osmosis chain to USDC on the Axelar chain. Please wait for the transaction to complete. If you need to swap more assets, feel free to let me know.
Error occured. Swap was not performed. Please provide denom for coin: USDC, on Chain Name: axelar. It is necessary as the symbol USDC is not unique among coins on chain axelar.
Select one from found assets:
Symbol: USDC Desc: Circle's stablecoin on Axelar Denom: uusdc,
Symbol: USDC Desc: Circle's stablecoin from Polygon on Axelar Denom: polygon-uusdc,
Symbol: USDC Desc: Circle's stablecoin from Avalanche on Axelar Denom: avalanche-uusdc
```
5. User response:
```
Swap 10 OSMO on osmosis to USDC with denom uusdc on axelar
```
6. Action call and agent response:
```
Successfuly swapped 10 OSMO tokens to USDC uusdc on chain axelar.
Transaction Hash: E84F36D6EEFAA6D7B70827F34EDAB83258BB86EFE33AEA1F4559D00B30CD3B50
```

## Contribution

The plugin includes comprehensive tests. Before submitting any pull requests, ensure all tests pass.
Expand Down
2 changes: 2 additions & 0 deletions packages/plugin-cosmos/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@
"@cosmjs/cosmwasm-stargate": "^0.32.4",
"@cosmjs/proto-signing": "^0.32.4",
"@cosmjs/stargate": "^0.32.4",
"@skip-go/client": "^0.16.3",
"axios": "^1.7.9",
"bignumber.js": "9.1.2",
"chain-registry": "^1.69.68",
"tsup": "8.3.5",
Expand Down
Loading

0 comments on commit 941f811

Please sign in to comment.