Skip to content

Commit 7e5afdc

Browse files
committed
feat: enabled swap by token symbol + added erc20 permit and allowance
1 parent b9322f9 commit 7e5afdc

File tree

8 files changed

+766
-13
lines changed

8 files changed

+766
-13
lines changed

README.md

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -531,6 +531,21 @@ const inference = await agent.getInferenceByTopicId(42);
531531
console.log("Allora inference for topic 42:", inference);
532532
```
533533

534+
### Cross-Chain Swap
535+
536+
```typescript
537+
import { PublicKey } from "@solana/web3.js";
538+
539+
const signature = await agent.swap(
540+
amount: "10",
541+
fromChain: "bsc",
542+
fromToken: "0x3c499c542cef5e3811e1192ce70d8cc03d5c3359",
543+
toChain: "solana",
544+
toToken: "0x0000000000000000000000000000000000000000",
545+
dstAddr: "0xc2d3024d64f27d85e05c40056674Fd18772dd922",
546+
);
547+
```
548+
534549
## Examples
535550

536551
### LangGraph Multi-Agent System

package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,7 @@
5555
"@meteora-ag/alpha-vault": "^1.1.7",
5656
"@meteora-ag/dlmm": "^1.3.0",
5757
"@onsol/tldparser": "^0.6.7",
58+
"@openzeppelin/contracts": "^5.2.0",
5859
"@orca-so/common-sdk": "0.6.4",
5960
"@orca-so/whirlpools-sdk": "^0.13.12",
6061
"@pythnetwork/hermes-client": "^1.3.0",

pnpm-lock.yaml

Lines changed: 8 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/actions/mayan/swap.ts

Lines changed: 23 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
import { PublicKey } from "@solana/web3.js";
21
import { Action } from "../../types/action";
32
import { SolanaAgentKit } from "../../agent";
43
import { z } from "zod";
@@ -27,8 +26,6 @@ const swapAction: Action = {
2726
explanation:
2827
"swap 0.02 0x0000000000000000000000000000000000000000 from solana to 0x0000000000000000000000000000000000000000 polygon destination 0x0cae42c0ce52e6e64c1e384ff98e686c6ee225f0",
2928
},
30-
],
31-
[
3229
{
3330
input: {
3431
amount: "0.02",
@@ -47,6 +44,25 @@ const swapAction: Action = {
4744
"swap 0.02 0x0000000000000000000000000000000000000000 from solana to HZ1JovNiVvGrGNiiYvEozEVgZ58xaU3RKwX8eACQBCt3 solana destination 4ZgCP2idpqrxuQNfsjakJEm9nFyZ2xnT4CrDPKPULJPk",
4845
},
4946
],
47+
[
48+
{
49+
input: {
50+
amount: "0.02",
51+
fromChain: "solana",
52+
fromToken: "sol",
53+
toChain: "solana",
54+
toToken: "HNT",
55+
dstAddr: "4ZgCP2idpqrxuQNfsjakJEm9nFyZ2xnT4CrDPKPULJPk",
56+
},
57+
output: {
58+
status: "success",
59+
message: "Swap executed successfully",
60+
url: "https://explorer.mayan.finance/swap/2GLNqs5gXCBSwRt6VjtfQRnLWYbcU1gzkgjWMWautv1RUj13Di4qJPjV29YRpoAdMYxgXj8ArMLzF3bCCZmVUXHz",
61+
},
62+
explanation:
63+
"swap 0.02 sol from solana to hnt solana destination 4ZgCP2idpqrxuQNfsjakJEm9nFyZ2xnT4CrDPKPULJPk",
64+
},
65+
],
5066
],
5167
schema: z.object({
5268
amount: z
@@ -65,7 +81,7 @@ const swapAction: Action = {
6581
"optimism",
6682
"base",
6783
]),
68-
fromToken: z.string().min(32, "Invalid from mint address"),
84+
fromToken: z.string(),
6985
toChain: z.enum([
7086
"solana",
7187
"ethereum",
@@ -76,7 +92,7 @@ const swapAction: Action = {
7692
"optimism",
7793
"base",
7894
]),
79-
toToken: z.string().min(32, "Invalid to mint address"),
95+
toToken: z.string(),
8096
dstAddr: z.string().min(32, "Invalid destination address"),
8197
inputAmount: z.number().positive("Input amount must be positive"),
8298
slippageBps: z.number().min(0).max(10000).optional(),
@@ -87,7 +103,7 @@ const swapAction: Action = {
87103
throw new Error("one of the from or to chain should be solana.");
88104
}
89105

90-
const tx = await swap(
106+
const url = await swap(
91107
agent,
92108
input.amount,
93109
input.fromChain,
@@ -101,10 +117,7 @@ const swapAction: Action = {
101117
return {
102118
status: "success",
103119
message: "Swap executed successfully",
104-
transaction: tx,
105-
inputAmount: input.inputAmount,
106-
inputToken: input.inputMint || "SOL",
107-
outputToken: input.outputMint,
120+
url,
108121
};
109122
},
110123
};

src/langchain/mayan/swap.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,9 +8,9 @@ export class SolanaCrossChainSwapTool extends Tool {
88
Inputs ( input is a JSON string):
99
amount: string, eg "0.02" or "7"
1010
fromChain: string, eg "solana" or "ethereum"
11-
fromToken: string, eg "0x0000000000000000000000000000000000000000" or "hntyVP6YFm1Hg25TN9WGLqM12b8TQmcknKrdu1oxWux"
11+
fromToken: string, eg "0x0000000000000000000000000000000000000000" or "hntyVP6YFm1Hg25TN9WGLqM12b8TQmcknKrdu1oxWux" or "sol" or "Pol"
1212
toChain: string, eg "solana" or "ethereum"
13-
toToken: string, eg "0x0000000000000000000000000000000000000000" or "0x6b175474e89094c44da98b954eedeac495271d0f"
13+
toToken: string, eg "0x0000000000000000000000000000000000000000" or "0x6b175474e89094c44da98b954eedeac495271d0f" or "SOL" or "eth"
1414
dstAddr: string, eg "4ZgCP2idpqrxuQNfsjakJEm9nFyZ2xnT4CrDPKPULJPk" or "0x0cae42c0cE52E6E64C1e384fF98e686C6eE225f0"
1515
slippageBps: number, eg 10 (optional)`;
1616

0 commit comments

Comments
 (0)