├── .DS_Store
├── .changeset
├── README.md
├── config.json
├── hip-onions-pump.md
├── loud-feet-cry.md
├── old-flowers-fold.md
└── quick-snails-joke.md
├── .github
├── .DS_Store
├── ISSUE_TEMPLATE
│ ├── bug_report.yml
│ ├── config.yml
│ └── feature_request.yml
├── PULL_REQUEST_TEMPLATE.md
└── workflows
│ ├── publish-commit.yml
│ ├── publish.yml
│ └── pull-request.yml
├── .gitignore
├── CODE_OF_CONDUCT.md
├── LICENSE.md
├── README.md
├── SECURITY.md
├── biome.json
├── examples
├── .DS_Store
├── chat-agent
│ ├── .example.env
│ ├── .gitignore
│ ├── README.md
│ ├── app
│ │ ├── api
│ │ │ └── hello
│ │ │ │ └── route.ts
│ │ ├── favicon.ico
│ │ ├── globals.css
│ │ ├── layout.tsx
│ │ └── page.tsx
│ ├── components
│ │ ├── ChatMessageBubble.tsx
│ │ ├── ChatWindow.tsx
│ │ └── IntermediateStep.tsx
│ ├── next.config.ts
│ ├── package.json
│ ├── pnpm-lock.yaml
│ ├── postcss.config.mjs
│ ├── public
│ │ ├── file.svg
│ │ ├── globe.svg
│ │ ├── next.svg
│ │ ├── vercel.svg
│ │ └── window.svg
│ ├── tailwind.config.ts
│ ├── tsconfig.json
│ └── utils
│ │ └── markdownToHtml.ts
├── langchain
│ ├── index.ts
│ └── test.ts
├── langgraph-agent
│ ├── .example.env
│ ├── README.md
│ ├── package.json
│ ├── pnpm-lock.yaml
│ ├── src
│ │ ├── agent.ts
│ │ ├── agents
│ │ │ ├── aptos-read-agent.ts
│ │ │ ├── manager.ts
│ │ │ ├── tweet-writer-agent.ts
│ │ │ └── x-post-agent.ts
│ │ ├── index.ts
│ │ └── state.ts
│ ├── test
│ │ └── index.ts
│ └── tsconfig.json
├── mcp-server
│ ├── .gitignore
│ ├── claude_desktop_config.json
│ ├── package.json
│ ├── src
│ │ └── index.ts
│ └── tsconfig.json
└── simple
│ └── index.ts
├── lefthook.yml
├── move-agent-kit.jpeg
├── package.json
├── pnpm-lock.yaml
├── src
├── .DS_Store
├── agent.ts
├── constants
│ └── price-feed.ts
├── index.ts
├── langchain
│ ├── account
│ │ ├── address.ts
│ │ └── index.ts
│ ├── amnis
│ │ ├── index.ts
│ │ ├── stake.ts
│ │ └── withdraw-stake.ts
│ ├── aptos
│ │ ├── balance.ts
│ │ ├── burn-nft.ts
│ │ ├── burn-token.ts
│ │ ├── create-token.ts
│ │ ├── get-token-details.ts
│ │ ├── get-token-price.ts
│ │ ├── get-transaction.ts
│ │ ├── index.ts
│ │ ├── mint-token.ts
│ │ ├── transfer-nft.ts
│ │ └── transfer-token.ts
│ ├── aries
│ │ ├── borrow-token.ts
│ │ ├── create-profile.ts
│ │ ├── index.ts
│ │ ├── lend-token.ts
│ │ ├── repay-token.ts
│ │ └── withdraw-token.ts
│ ├── echelon
│ │ ├── borrow-token.ts
│ │ ├── index.ts
│ │ ├── lend-token.ts
│ │ ├── repay-token.ts
│ │ └── withdraw-token.ts
│ ├── echo
│ │ ├── index.ts
│ │ ├── stake.ts
│ │ └── unstake.ts
│ ├── index.ts
│ ├── joule
│ │ ├── borrow-token.ts
│ │ ├── claim-reward.ts
│ │ ├── get-pool-details.ts
│ │ ├── get-user-all-positions.ts
│ │ ├── get-user-position.ts
│ │ ├── index.ts
│ │ ├── lend-token.ts
│ │ ├── repay-token.ts
│ │ └── withdraw-token.ts
│ ├── liquidswap
│ │ ├── add-liquidity.ts
│ │ ├── create-pool.ts
│ │ ├── index.ts
│ │ ├── remove-liquidity.ts
│ │ └── swap.ts
│ ├── merkletrade
│ │ ├── close-position.ts
│ │ ├── get-position.ts
│ │ ├── index.ts
│ │ ├── place-limit-order.ts
│ │ └── place-market-order.ts
│ ├── openai
│ │ ├── create-image.ts
│ │ └── index.ts
│ ├── panora
│ │ ├── index.ts
│ │ └── swap.ts
│ └── thala
│ │ ├── add-liquidity.ts
│ │ ├── create-pool.ts
│ │ ├── index.ts
│ │ ├── mint-mod.ts
│ │ ├── redeem-mod.ts
│ │ ├── remove-liquidity.ts
│ │ ├── stake.ts
│ │ └── unstake.ts
├── mcp
│ └── index.ts
├── signers
│ ├── base-signer.ts
│ ├── index.ts
│ ├── local-signer.ts
│ └── wallet-signer.ts
├── tools
│ ├── amnis
│ │ ├── index.ts
│ │ ├── stake-token.ts
│ │ └── withdraw-stake.ts
│ ├── aptos
│ │ ├── balance.ts
│ │ ├── burn-nft.ts
│ │ ├── burn-token.ts
│ │ ├── create-token.ts
│ │ ├── get-token-details.ts
│ │ ├── get-token-price.ts
│ │ ├── get-transaction.ts
│ │ ├── index.ts
│ │ ├── mint-token.ts
│ │ ├── transfer-nft.ts
│ │ └── transfer-token.ts
│ ├── aries
│ │ ├── borrow.ts
│ │ ├── create-profile.ts
│ │ ├── index.ts
│ │ ├── lend.ts
│ │ ├── repay.ts
│ │ └── withdraw.ts
│ ├── echelon
│ │ ├── borrow.ts
│ │ ├── index.ts
│ │ ├── lend.ts
│ │ ├── repay.ts
│ │ └── withdraw.ts
│ ├── echo
│ │ ├── index.ts
│ │ ├── stake.ts
│ │ └── unstake.ts
│ ├── index.ts
│ ├── joule
│ │ ├── borrow.ts
│ │ ├── claim-reward.ts
│ │ ├── index.ts
│ │ ├── lend.ts
│ │ ├── pool-detail.ts
│ │ ├── repay.ts
│ │ ├── user-all-positions.ts
│ │ ├── user-position.ts
│ │ └── withdraw.ts
│ ├── liquidswap
│ │ ├── add-liquidity.ts
│ │ ├── create-pool.ts
│ │ ├── index.ts
│ │ ├── remove-liquidity.ts
│ │ └── swap.ts
│ ├── merkletrade
│ │ ├── close-position.ts
│ │ ├── error.ts
│ │ ├── get-positions.ts
│ │ ├── index.ts
│ │ ├── place-limit-order.ts
│ │ └── place-market-order.ts
│ ├── openai
│ │ ├── create-image.ts
│ │ └── index.ts
│ ├── panora
│ │ ├── index.ts
│ │ └── swap.ts
│ └── thala
│ │ ├── add-liquidity.ts
│ │ ├── create-pool.ts
│ │ ├── index.ts
│ │ ├── mint-mod.ts
│ │ ├── redeem-mod.ts
│ │ ├── remove-liquidity.ts
│ │ ├── stake.ts
│ │ └── unstake.ts
├── types
│ ├── action.ts
│ └── index.ts
└── utils
│ ├── clean-joule-all-positions-list.ts
│ ├── get-pool-address-by-token-name.ts
│ ├── index.ts
│ ├── mcp-schema.ts
│ ├── parse-fungible-asset-to-wrapped-asset.ts
│ └── parse-json.ts
├── tsconfig.json
├── tsup.config.ts
└── tsup.dev.config.ts
/.DS_Store:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/MetaMove/move-agent-kit/fb25bd653a9f9a11684835131bc8b9efe17f9735/.DS_Store
--------------------------------------------------------------------------------
/.changeset/README.md:
--------------------------------------------------------------------------------
1 | # Changesets
2 |
3 | Hello and welcome! This folder has been automatically generated by `@changesets/cli`, a build tool that works
4 | with multi-package repos, or single-package repos to help you version and publish your code. You can
5 | find the full documentation for it [in our repository](https://github.com/changesets/changesets)
6 |
7 | We have a quick list of common questions to get you started engaging with this project in
8 | [our documentation](https://github.com/changesets/changesets/blob/main/docs/common-questions.md)
9 |
--------------------------------------------------------------------------------
/.changeset/config.json:
--------------------------------------------------------------------------------
1 | {
2 | "$schema": "https://unpkg.com/@changesets/config@3.0.5/schema.json",
3 | "changelog": "@changesets/cli/changelog",
4 | "commit": false,
5 | "fixed": [],
6 | "linked": [],
7 | "access": "public",
8 | "baseBranch": "main",
9 | "updateInternalDependencies": "patch",
10 | "ignore": []
11 | }
12 |
--------------------------------------------------------------------------------
/.changeset/hip-onions-pump.md:
--------------------------------------------------------------------------------
1 | ---
2 | "move-agent-kit": minor
3 | ---
4 |
5 | add new tools
6 |
--------------------------------------------------------------------------------
/.changeset/loud-feet-cry.md:
--------------------------------------------------------------------------------
1 | ---
2 | "move-agent-kit": patch
3 | ---
4 |
5 | code structuring
6 |
--------------------------------------------------------------------------------
/.changeset/old-flowers-fold.md:
--------------------------------------------------------------------------------
1 | ---
2 | "move-agent-kit": patch
3 | ---
4 |
5 | updated liquidswap prompts
6 |
--------------------------------------------------------------------------------
/.changeset/quick-snails-joke.md:
--------------------------------------------------------------------------------
1 | ---
2 | "move-agent-kit": minor
3 | ---
4 |
5 | fixed wallet-signer
6 |
--------------------------------------------------------------------------------
/.github/.DS_Store:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/MetaMove/move-agent-kit/fb25bd653a9f9a11684835131bc8b9efe17f9735/.github/.DS_Store
--------------------------------------------------------------------------------
/.github/ISSUE_TEMPLATE/bug_report.yml:
--------------------------------------------------------------------------------
1 | name: 🐞 Bug Report
2 | description: Create a bug report to help us improve
3 | title: "bug: "
4 | labels: ["🐞 unconfirmed bug"]
5 | body:
6 | - type: textarea
7 | attributes:
8 | label: Provide environment information
9 | description: |
10 | Run this command in your project root and paste the results:
11 | ```bash
12 | npx envinfo --system --binaries
13 | ```
14 |
15 | validations:
16 | required: true
17 | - type: textarea
18 | attributes:
19 | label: Describe the bug
20 | description: A clear and concise description of the bug, as well as what you expected to happen when encountering it.
21 | validations:
22 | required: true
23 | - type: input
24 | attributes:
25 | label: Reproduction repo
26 | description: If applicable, please provide a link to a reproduction repo or a Stackblitz / CodeSandbox project. Your issue may be closed if this is not provided and we are unable to reproduce the issue.
27 | - type: textarea
28 | attributes:
29 | label: Expected behavior
30 | description: A clear and concise description of what you expected to happen.
31 | validations:
32 | required: true
33 | - type: textarea
34 | attributes:
35 | label: Actual behavior
36 | description: A clear and concise description of what actually happened.
37 | validations:
38 | required: true
39 | - type: textarea
40 | attributes:
41 | label: Steps to reproduce
42 | description: Steps to reproduce the behavior.
43 | placeholder: |
44 | 1. Go to '...'
45 | 2. Click on '....'
46 | 3. Scroll down to '....'
47 | 4. See error
48 | validations:
49 | required: true
50 | - type: textarea
51 | attributes:
52 | label: Screenshots
53 | description: If applicable, add screenshots to help explain your problem.
54 | - type: textarea
55 | attributes:
56 | label: Additional context
57 | description: Add any other context about the problem here.
--------------------------------------------------------------------------------
/.github/ISSUE_TEMPLATE/config.yml:
--------------------------------------------------------------------------------
1 | blank_issues_enabled: false
2 | contact_links:
3 | - name: Ask a Question
4 | url: https://t.me/metamove_build
5 | about: Ask questions and discuss with other community members
--------------------------------------------------------------------------------
/.github/ISSUE_TEMPLATE/feature_request.yml:
--------------------------------------------------------------------------------
1 | name: Feature Request
2 | description: Suggest an idea for this project
3 | title: "feat: "
4 | labels: ["🌟 enhancement"]
5 | body:
6 | - type: textarea
7 | attributes:
8 | label: Is your feature request related to a problem? Please describe.
9 | description: A clear and concise description of what the problem is.
10 | validations:
11 | required: true
12 | - type: textarea
13 | attributes:
14 | label: Describe the solution you'd like to see
15 | description: A clear and concise description of what you want to happen.
16 | validations:
17 | required: true
18 | - type: textarea
19 | attributes:
20 | label: Describe alternate solutions
21 | description: A clear and concise description of any alternative solutions or features you've considered.
22 | validations:
23 | required: true
24 | - type: textarea
25 | attributes:
26 | label: Additional information
27 | description: Add any other information related to the feature here. If your feature request is related to any issues or discussions, link them here.
--------------------------------------------------------------------------------
/.github/PULL_REQUEST_TEMPLATE.md:
--------------------------------------------------------------------------------
1 | Fixes #
2 |
3 | # Description
4 |
5 | Please include a summary of the change and which issue is fixed. Please also include relevant motivation and context.
6 | List any dependencies that are required for this change.
7 |
8 | ## Type of change
9 |
10 | Please mark relevant options with an `x` in the brackets.
11 |
12 | - [ ] Bug fix (non-breaking change which fixes an issue)
13 | - [ ] New feature (non-breaking change which adds functionality)
14 | - [ ] Breaking change (fix or feature that would cause existing functionality to not work as expected)
15 | - [ ] This change requires a documentation update
16 | - [ ] Algorithm update - updates algorithm documentation/questions/answers etc.
17 | - [ ] Other (please describe):
18 |
19 | # How Has This Been Tested?
20 |
21 | Please describe the tests that you ran to verify your changes. Provide instructions so we can reproduce. Please also
22 | list any relevant details for your test configuration
23 |
24 | - [ ] Integration tests
25 | - [ ] Unit tests
26 | - [ ] Manual tests
27 | - [ ] No tests required
28 |
29 | # Reviewer checklist
30 |
31 | Mark everything that needs to be checked before merging the PR.
32 |
33 | - [ ] Check if the UI is working as expected and is satisfactory
34 | - [ ] Check if the code is well documented
35 | - [ ] Check if the behavior is what is expected
36 | - [ ] Check if the code is well tested
37 | - [ ] Check if the code is readable and well formatted
38 | - [ ] Additional checks (document below if any)
39 |
40 | # Screenshots (if appropriate):
41 |
42 | # Questions (if appropriate):
--------------------------------------------------------------------------------
/.github/workflows/publish-commit.yml:
--------------------------------------------------------------------------------
1 | name: 🚀 pkg-pr-new
2 | on: [push, pull_request]
3 | jobs:
4 | build:
5 | runs-on: ubuntu-latest
6 | steps:
7 | - name: Checkout code
8 | uses: actions/checkout@v4
9 | - uses: pnpm/action-setup@v2
10 | with:
11 | version: latest
12 | - uses: actions/setup-node@v4
13 | with:
14 | node-version: 20
15 | cache: 'pnpm'
16 | - name: Install dependencies
17 | run: pnpm install --no-frozen-lockfile
18 | - name: Build
19 | run: pnpm run build
20 | - run: pnpm dlx pkg-pr-new publish
21 |
--------------------------------------------------------------------------------
/.github/workflows/publish.yml:
--------------------------------------------------------------------------------
1 | name: Publish Package to npmjs
2 | on:
3 | release:
4 | types: [published]
5 | jobs:
6 | npm-publish:
7 | runs-on: ubuntu-latest
8 | steps:
9 | - uses: actions/checkout@v4
10 | - uses: pnpm/action-setup@v2
11 | with:
12 | version: latest
13 | - uses: actions/setup-node@v4
14 | with:
15 | node-version: "20.x"
16 | registry-url: "https://registry.npmjs.org"
17 | cache: 'pnpm'
18 | - run: pnpm install --no-frozen-lockfile
19 | - run: pnpm publish --no-git-checks
20 | env:
21 | NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }}
22 |
--------------------------------------------------------------------------------
/.github/workflows/pull-request.yml:
--------------------------------------------------------------------------------
1 | name: 🚀 PR
2 | concurrency:
3 | group: ${{ github.repository }}-${{ github.workflow }}-${{ github.ref }}
4 | cancel-in-progress: true
5 | on: [pull_request]
6 | permissions:
7 | actions: write
8 | contents: read
9 | pull-requests: write
10 | jobs:
11 | lint:
12 | name: ⬣ Linting
13 | runs-on: ubuntu-latest
14 | steps:
15 | - uses: actions/checkout@v4
16 | - uses: biomejs/setup-biome@v2
17 | - run: biome ci . --reporter=github
18 | typecheck:
19 | name: 🔎 Type check
20 | runs-on: ubuntu-latest
21 | steps:
22 | - name: 🛑 Cancel Previous Runs
23 | uses: styfle/cancel-workflow-action@0.12.1
24 | - name: ⬇️ Checkout repo
25 | uses: actions/checkout@v4
26 | - name: Setup PNPM
27 | uses: pnpm/action-setup@v2
28 | with:
29 | version: latest
30 | - name: ⎔ Setup node
31 | uses: actions/setup-node@v4
32 | with:
33 | node-version-file: "package.json"
34 | cache: 'pnpm'
35 | - name: 📥 Download deps
36 | run: pnpm install --no-frozen-lockfile
37 | - name: 🔎 Type check
38 | run: pnpm run typecheck
39 |
--------------------------------------------------------------------------------
/LICENSE.md:
--------------------------------------------------------------------------------
1 | MIT License
2 |
3 | Copyright (c) 2025 Fetcch Labs
4 |
5 | Permission is hereby granted, free of charge, to any person obtaining a copy
6 | of this software and associated documentation files (the "Software"), to deal
7 | in the Software without restriction, including without limitation the rights
8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9 | copies of the Software, and to permit persons to whom the Software is
10 | furnished to do so, subject to the following conditions:
11 |
12 | The above copyright notice and this permission notice shall be included in all
13 | copies or substantial portions of the Software.
14 |
15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21 | SOFTWARE.
--------------------------------------------------------------------------------
/SECURITY.md:
--------------------------------------------------------------------------------
1 | # Security Policy
2 |
3 | ## Supported Versions
4 |
5 | | Version | Supported |
6 | | ------- | ------------------ |
7 | | 1.0.x | :white_check_mark: |
8 |
9 | ## Reporting a Vulnerability
10 |
11 | In case of a vulnerability please reach out to active maintainers of the project and report it to them.
12 |
13 |
--------------------------------------------------------------------------------
/biome.json:
--------------------------------------------------------------------------------
1 | {
2 | "$schema": "./node_modules/@biomejs/biome/configuration_schema.json",
3 | "vcs": {
4 | "enabled": true,
5 | "clientKind": "git",
6 | "defaultBranch": "main",
7 | "useIgnoreFile": true
8 | },
9 | "formatter": {
10 | "ignore": [],
11 | "enabled": true,
12 | "formatWithErrors": false,
13 | "indentStyle": "tab",
14 | "lineEnding": "lf",
15 | "lineWidth": 120
16 | },
17 | "organizeImports": {
18 | "ignore": [],
19 | "enabled": true
20 | },
21 | "linter": {
22 | "ignore": ["examples/**"],
23 | "enabled": true,
24 | "rules": {
25 | "recommended": true,
26 | "suspicious": {
27 | "recommended": true,
28 | "noExplicitAny": "warn"
29 | },
30 | "style": {
31 | "recommended": true
32 | },
33 | "complexity": {
34 | "recommended": true
35 | },
36 | "security": {
37 | "recommended": true
38 | },
39 | "performance": {
40 | "recommended": true
41 | },
42 | "correctness": {
43 | "recommended": true
44 | },
45 | "a11y": {
46 | "recommended": true
47 | },
48 | "nursery": {
49 | "recommended": true,
50 | "useConsistentMemberAccessibility": "warn"
51 | }
52 | }
53 | },
54 | "javascript": {
55 | "formatter": {
56 | "semicolons": "asNeeded",
57 | "trailingCommas": "es5"
58 | }
59 | }
60 | }
61 |
--------------------------------------------------------------------------------
/examples/.DS_Store:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/MetaMove/move-agent-kit/fb25bd653a9f9a11684835131bc8b9efe17f9735/examples/.DS_Store
--------------------------------------------------------------------------------
/examples/chat-agent/.example.env:
--------------------------------------------------------------------------------
1 | # You can find the public key from https://docs.panora.exchange/developer/swap-api-and-sdk/swap-api
2 | PANORA_API_KEY=""
3 | # private key for aptos wallet you want the agent to use
4 | APTOS_PRIVATE_KEY=""
5 | # API key for Claude
6 | ANTHROPIC_API_KEY=""
7 |
--------------------------------------------------------------------------------
/examples/chat-agent/.gitignore:
--------------------------------------------------------------------------------
1 | # See https://help.github.com/articles/ignoring-files/ for more about ignoring files.
2 |
3 | # dependencies
4 | /node_modules
5 | /.pnp
6 | .pnp.*
7 | .yarn/*
8 | !.yarn/patches
9 | !.yarn/plugins
10 | !.yarn/releases
11 | !.yarn/versions
12 |
13 | # testing
14 | /coverage
15 |
16 | # next.js
17 | /.next/
18 | /out/
19 |
20 | # production
21 | /build
22 |
23 | # misc
24 | .DS_Store
25 | *.pem
26 |
27 | # debug
28 | npm-debug.log*
29 | yarn-debug.log*
30 | yarn-error.log*
31 | .pnpm-debug.log*
32 |
33 | # env files (can opt-in for committing if needed)
34 | .env*
35 |
36 | # vercel
37 | .vercel
38 |
39 | # typescript
40 | *.tsbuildinfo
41 | next-env.d.ts
42 |
--------------------------------------------------------------------------------
/examples/chat-agent/README.md:
--------------------------------------------------------------------------------
1 | This is a [Next.js](https://nextjs.org) project bootstrapped with [`create-next-app`](https://nextjs.org/docs/app/api-reference/cli/create-next-app).
2 |
3 | ## Getting Started
4 |
5 | In the root directory, install dependencies by running `pnpm i`.
6 |
7 | In the `examples/chat-agent` directory, install dependencies by running `pnpm i`.
8 |
9 | Make a copy of `.example.env` and rename it to `.env` and fill in your own API keys.
10 |
11 | Run `npm run dev` to start the development server.
12 |
--------------------------------------------------------------------------------
/examples/chat-agent/app/favicon.ico:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/MetaMove/move-agent-kit/fb25bd653a9f9a11684835131bc8b9efe17f9735/examples/chat-agent/app/favicon.ico
--------------------------------------------------------------------------------
/examples/chat-agent/app/globals.css:
--------------------------------------------------------------------------------
1 | @tailwind base;
2 | @tailwind components;
3 | @tailwind utilities;
4 |
5 | :root {
6 | --background: #ffffff;
7 | --foreground: #171717;
8 | }
9 |
10 | @media (prefers-color-scheme: dark) {
11 | :root {
12 | --background: #0a0a0a;
13 | --foreground: #ededed;
14 | }
15 | }
16 |
17 | body {
18 | color: var(--foreground);
19 | background: var(--background);
20 | font-family: Arial, Helvetica, sans-serif;
21 | }
22 |
--------------------------------------------------------------------------------
/examples/chat-agent/app/layout.tsx:
--------------------------------------------------------------------------------
1 | import type { Metadata } from "next"
2 | import { Geist, Geist_Mono } from "next/font/google"
3 | import "./globals.css"
4 |
5 | const geistSans = Geist({
6 | variable: "--font-geist-sans",
7 | subsets: ["latin"],
8 | })
9 |
10 | const geistMono = Geist_Mono({
11 | variable: "--font-geist-mono",
12 | subsets: ["latin"],
13 | })
14 |
15 | export const metadata: Metadata = {
16 | title: "Create Next App",
17 | description: "Generated by create next app",
18 | }
19 |
20 | export default function RootLayout({
21 | children,
22 | }: Readonly<{
23 | children: React.ReactNode
24 | }>) {
25 | return (
26 |
27 |
{children}
28 |
29 | )
30 | }
31 |
--------------------------------------------------------------------------------
/examples/chat-agent/app/page.tsx:
--------------------------------------------------------------------------------
1 | import { ChatWindow } from "@/components/ChatWindow"
2 |
3 | export default function Home() {
4 | const InfoCard = (
5 |
6 |
MoveAgentKit + LangChain.js 🦜🔗 + Next.js
7 |
8 | -
9 | 🤝
10 |
11 | This template showcases a simple agent chatbot using{" "}
12 | MoveAgentKit
13 | {", "}
14 |
15 | LangChain.js
16 | {" "}
17 | and the Vercel{" "}
18 |
19 | AI SDK
20 | {" "}
21 | in a{" "}
22 |
23 | Next.js
24 | {" "}
25 | project.
26 |
27 |
28 | -
29 | 💻
30 |
31 | You can find the prompt and model logic for this use-case in
app/api/chat/route.ts
.
32 |
33 |
34 | -
35 | 🎨
36 |
37 | The main frontend logic is found in
app/page.tsx
.
38 |
39 |
40 | -
41 | 🐙
42 |
43 | This template is open source - you can see the source code and deploy your own version{" "}
44 |
45 | from the GitHub repo (coming soon)
46 |
47 | !
48 |
49 |
50 | -
51 | 👇
52 |
53 | Try asking e.g.
What is my wallet address?
below!
54 |
55 |
56 |
57 |
58 | )
59 | return (
60 |
67 | )
68 | }
69 |
--------------------------------------------------------------------------------
/examples/chat-agent/components/ChatMessageBubble.tsx:
--------------------------------------------------------------------------------
1 | import markdownToHtml from "@/utils/markdownToHtml"
2 | import type { Message } from "ai/react"
3 | import { useMemo } from "react"
4 |
5 | export function ChatMessageBubble(props: {
6 | message: Message
7 | aiEmoji?: string
8 | sources: any[]
9 | }) {
10 | const colorClassName = props.message.role === "user" ? "bg-sky-600" : "bg-slate-50 text-black"
11 | const alignmentClassName = props.message.role === "user" ? "ml-auto" : "mr-auto"
12 | const prefix = props.message.role === "user" ? "🧑" : props.aiEmoji
13 |
14 | const content = useMemo(() => {
15 | return markdownToHtml(props.message.content)
16 | }, [props.message.content])
17 |
18 | return (
19 |
20 |
{prefix}
21 |
22 |
23 | {props.sources && props.sources.length ? (
24 | <>
25 |
26 | 🔍 Sources:
27 |
28 |
29 | {props.sources?.map((source, i) => (
30 |
31 | {i + 1}. "{source.pageContent}"
32 | {source.metadata?.loc?.lines !== undefined ? (
33 |
34 |
35 | Lines {source.metadata?.loc?.lines?.from} to {source.metadata?.loc?.lines?.to}
36 |
37 | ) : (
38 | ""
39 | )}
40 |
41 | ))}
42 |
43 | >
44 | ) : (
45 | ""
46 | )}
47 |
48 |
49 | )
50 | }
51 |
--------------------------------------------------------------------------------
/examples/chat-agent/components/IntermediateStep.tsx:
--------------------------------------------------------------------------------
1 | import type { Message } from "ai/react"
2 | import { useState } from "react"
3 |
4 | export function IntermediateStep(props: { message: Message }) {
5 | const parsedInput = JSON.parse(props.message.content)
6 | const action = parsedInput.action
7 | const observation = parsedInput.observation
8 | const [expanded, setExpanded] = useState(false)
9 | return (
10 |
13 |
setExpanded(!expanded)}>
14 |
15 | 🛠 {action.name}
16 |
17 | 🔽
18 | 🔼
19 |
20 |
23 |
26 |
29 | Tool Input:
30 |
31 |
32 | {JSON.stringify(action.args)}
33 |
34 |
35 |
38 |
41 | {observation}
42 |
43 |
44 |
45 |
46 | )
47 | }
48 |
--------------------------------------------------------------------------------
/examples/chat-agent/next.config.ts:
--------------------------------------------------------------------------------
1 | import type { NextConfig } from "next"
2 |
3 | const nextConfig: NextConfig = {
4 | /* config options here */
5 | }
6 |
7 | export default nextConfig
8 |
--------------------------------------------------------------------------------
/examples/chat-agent/package.json:
--------------------------------------------------------------------------------
1 | {
2 | "name": "chat-agent",
3 | "version": "0.1.0",
4 | "private": true,
5 | "scripts": {
6 | "dev": "next dev",
7 | "build": "next build",
8 | "start": "next start",
9 | "lint": "next lint"
10 | },
11 | "dependencies": {
12 | "@aptos-labs/ts-sdk": "^1.33.1",
13 | "@langchain/anthropic": "^0.3.12",
14 | "@langchain/core": "^0.3.32",
15 | "@langchain/langgraph": "^0.2.41",
16 | "ai": "^3.4.33",
17 | "isomorphic-dompurify": "^2.20.0",
18 | "marked": "^15.0.6",
19 | "move-agent-kit": "^0.1.2",
20 | "next": "15.1.4",
21 | "react": "^19.0.0",
22 | "react-dom": "^19.0.0",
23 | "react-toastify": "^11.0.3"
24 | },
25 | "devDependencies": {
26 | "@types/node": "^20.17.14",
27 | "@types/react": "^19.0.7",
28 | "@types/react-dom": "^19.0.3",
29 | "postcss": "^8.5.1",
30 | "tailwindcss": "^3.4.17",
31 | "typescript": "^5.7.3"
32 | }
33 | }
34 |
--------------------------------------------------------------------------------
/examples/chat-agent/postcss.config.mjs:
--------------------------------------------------------------------------------
1 | /** @type {import('postcss-load-config').Config} */
2 | const config = {
3 | plugins: {
4 | tailwindcss: {},
5 | },
6 | }
7 |
8 | export default config
9 |
--------------------------------------------------------------------------------
/examples/chat-agent/public/file.svg:
--------------------------------------------------------------------------------
1 |
--------------------------------------------------------------------------------
/examples/chat-agent/public/globe.svg:
--------------------------------------------------------------------------------
1 |
--------------------------------------------------------------------------------
/examples/chat-agent/public/next.svg:
--------------------------------------------------------------------------------
1 |
--------------------------------------------------------------------------------
/examples/chat-agent/public/vercel.svg:
--------------------------------------------------------------------------------
1 |
--------------------------------------------------------------------------------
/examples/chat-agent/public/window.svg:
--------------------------------------------------------------------------------
1 |
--------------------------------------------------------------------------------
/examples/chat-agent/tailwind.config.ts:
--------------------------------------------------------------------------------
1 | import type { Config } from "tailwindcss"
2 |
3 | export default {
4 | content: [
5 | "./pages/**/*.{js,ts,jsx,tsx,mdx}",
6 | "./components/**/*.{js,ts,jsx,tsx,mdx}",
7 | "./app/**/*.{js,ts,jsx,tsx,mdx}",
8 | ],
9 | theme: {
10 | extend: {
11 | colors: {
12 | background: "var(--background)",
13 | foreground: "var(--foreground)",
14 | },
15 | },
16 | },
17 | plugins: [],
18 | } satisfies Config
19 |
--------------------------------------------------------------------------------
/examples/chat-agent/tsconfig.json:
--------------------------------------------------------------------------------
1 | {
2 | "compilerOptions": {
3 | "target": "ES2017",
4 | "lib": ["dom", "dom.iterable", "esnext"],
5 | "allowJs": true,
6 | "skipLibCheck": true,
7 | "strict": true,
8 | "noEmit": true,
9 | "esModuleInterop": true,
10 | "module": "esnext",
11 | "moduleResolution": "bundler",
12 | "resolveJsonModule": true,
13 | "isolatedModules": true,
14 | "jsx": "preserve",
15 | "incremental": true,
16 | "plugins": [
17 | {
18 | "name": "next"
19 | }
20 | ],
21 | "paths": {
22 | "@/*": ["./*"]
23 | }
24 | },
25 | "include": ["next-env.d.ts", "**/*.ts", "**/*.tsx", ".next/types/**/*.ts"],
26 | "exclude": ["node_modules"]
27 | }
28 |
--------------------------------------------------------------------------------
/examples/chat-agent/utils/markdownToHtml.ts:
--------------------------------------------------------------------------------
1 | import DOMPurify from "isomorphic-dompurify"
2 | import { marked } from "marked"
3 |
4 | interface MarkedOptions {
5 | gfm: boolean
6 | breaks: boolean
7 | headerIds: boolean
8 | mangle: false
9 | highlight?: (code: string, lang: string) => string
10 | }
11 |
12 | // Configure marked options
13 | const markedOptions: MarkedOptions = {
14 | gfm: true, // GitHub Flavored Markdown
15 | breaks: true, // Convert \n to
16 | headerIds: true, // Add ids to headers
17 | mangle: false, // Don't escape HTML
18 | highlight: function (code: string, lang: string): string {
19 | // You can add syntax highlighting here if needed
20 | return code
21 | },
22 | }
23 |
24 | marked.setOptions(markedOptions)
25 |
26 | // Basic markdown to HTML conversion with sanitization
27 | export default function markdownToHtml(markdown: string) {
28 | console.log(markdown, "markdown")
29 | const rawHtml = marked.parse(markdown)
30 | return DOMPurify.sanitize(rawHtml as string)
31 | }
32 |
--------------------------------------------------------------------------------
/examples/langgraph-agent/.example.env:
--------------------------------------------------------------------------------
1 | # You can find the public key from https://docs.panora.exchange/developer/swap-api-and-sdk/swap-api
2 | PANORA_API_KEY=""
3 | # private key for aptos wallet you want the agent to use
4 | APTOS_PRIVATE_KEY=""
5 | # API key for Claude
6 | ANTHROPIC_API_KEY=""
7 | # Account username
8 | TWITTER_USERNAME=
9 | # Account password
10 | TWITTER_PASSWORD=
11 | # Account email
12 | TWITTER_EMAIL=
--------------------------------------------------------------------------------
/examples/langgraph-agent/README.md:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/MetaMove/move-agent-kit/fb25bd653a9f9a11684835131bc8b9efe17f9735/examples/langgraph-agent/README.md
--------------------------------------------------------------------------------
/examples/langgraph-agent/package.json:
--------------------------------------------------------------------------------
1 | {
2 | "name": "langgraph-agent",
3 | "version": "1.0.0",
4 | "description": "",
5 | "main": "index.js",
6 | "scripts": {
7 | "test": "echo \"Error: no test specified\" && exit 1"
8 | },
9 | "keywords": [],
10 | "author": "",
11 | "license": "ISC",
12 | "devDependencies": {
13 | "@types/node": "^22.10.7",
14 | "typescript": "^5.7.3"
15 | },
16 | "dependencies": {
17 | "@aptos-labs/ts-sdk": "^1.33.1",
18 | "@langchain/anthropic": "^0.3.11",
19 | "@langchain/core": "^0.3.30",
20 | "@langchain/langgraph": "^0.2.40",
21 | "agent-twitter-client": "^0.0.18",
22 | "dotenv": "^16.4.7",
23 | "move-agent-kit": "^0.2.0",
24 | "zod": "^3.24.2",
25 | "zod-to-json-schema": "^3.24.1"
26 | }
27 | }
28 |
--------------------------------------------------------------------------------
/examples/langgraph-agent/src/agent.ts:
--------------------------------------------------------------------------------
1 | import {
2 | Aptos,
3 | AptosConfig,
4 | Ed25519PrivateKey,
5 | HexInput,
6 | Network,
7 | PrivateKey,
8 | PrivateKeyVariants,
9 | } from "@aptos-labs/ts-sdk"
10 | import { ChatAnthropic } from "@langchain/anthropic"
11 | import { config } from "dotenv"
12 | import { AgentRuntime, LocalSigner } from "move-agent-kit"
13 | config()
14 |
15 | export const llm = new ChatAnthropic({
16 | model: "claude-3-5-sonnet-latest",
17 | anthropicApiKey: process.env.ANTHROPIC_API_KEY,
18 | })
19 |
20 | export const setupAgentKit = async () => {
21 | const aptosConfig = new AptosConfig({
22 | network: Network.MAINNET,
23 | })
24 | const aptos = new Aptos(aptosConfig)
25 | const account = await aptos.deriveAccountFromPrivateKey({
26 | privateKey: new Ed25519PrivateKey(
27 | PrivateKey.formatPrivateKey(process.env.APTOS_PRIVATE_KEY as HexInput, PrivateKeyVariants.Ed25519)
28 | ),
29 | })
30 | const signer = new LocalSigner(account, Network.MAINNET)
31 | const agentRuntime = new AgentRuntime(signer, aptos)
32 |
33 | return {
34 | agentRuntime,
35 | llm,
36 | }
37 | }
38 |
--------------------------------------------------------------------------------
/examples/langgraph-agent/src/agents/aptos-read-agent.ts:
--------------------------------------------------------------------------------
1 | import { createReactAgent } from "@langchain/langgraph/prebuilt"
2 | import {
3 | AptosAccountAddressTool,
4 | AptosBalanceTool,
5 | AptosGetTokenDetailTool,
6 | AptosGetTokenPriceTool,
7 | AptosTransactionTool,
8 | JouleGetPoolDetails,
9 | } from "move-agent-kit"
10 | import { setupAgentKit } from "../agent"
11 | import { StateAnnotation } from "../state"
12 |
13 | export const createAptosReadAgent = async () => {
14 | const { agentRuntime, llm } = await setupAgentKit()
15 |
16 | const readAgentTools = [
17 | new AptosBalanceTool(agentRuntime),
18 | new AptosGetTokenDetailTool(agentRuntime),
19 | new AptosAccountAddressTool(agentRuntime),
20 | new AptosTransactionTool(agentRuntime),
21 | new AptosGetTokenPriceTool(agentRuntime),
22 | new JouleGetPoolDetails(agentRuntime),
23 | ]
24 |
25 | const readAgent = createReactAgent({
26 | tools: readAgentTools,
27 | llm: llm,
28 | })
29 |
30 | return readAgent
31 | }
32 |
33 | export const aptosReadNode = async (state: typeof StateAnnotation.State) => {
34 | const { messages } = state
35 |
36 | const readAgent = await createAptosReadAgent()
37 |
38 | const result = await readAgent.invoke({ messages })
39 |
40 | return {
41 | messages: [...result.messages],
42 | }
43 | }
44 |
--------------------------------------------------------------------------------
/examples/langgraph-agent/src/agents/tweet-writer-agent.ts:
--------------------------------------------------------------------------------
1 | import { tool } from "@langchain/core/tools"
2 | import { createReactAgent } from "@langchain/langgraph/prebuilt"
3 | import z from "zod"
4 | import { llm } from "../agent"
5 | import { StateAnnotation } from "../state"
6 |
7 | export const writerTool = tool(
8 | async (poolData: any): Promise => {
9 | console.log(poolData)
10 | const writerAgent = llm
11 |
12 | const result = await writerAgent.invoke(
13 | `Write a bull post tweet using these data points ${poolData}
14 |
15 | note: you don't need confirmation from anyone
16 | `
17 | )
18 |
19 | return result.content.toString()
20 | },
21 | {
22 | name: "write_bull_post",
23 | description: "Write bull post for twitter",
24 | schema: z.any(),
25 | }
26 | )
27 |
28 | export const createWriterAgent = async () => {
29 | const agent = createReactAgent({
30 | tools: [writerTool],
31 | llm,
32 | })
33 |
34 | return agent
35 | }
36 |
37 | export const writerNode = async (state: typeof StateAnnotation.State) => {
38 | const { messages } = state
39 |
40 | const writerAgent = await createWriterAgent()
41 |
42 | const result = await writerAgent.invoke({ messages })
43 |
44 | return {
45 | messages: [...result.messages],
46 | }
47 | }
48 |
--------------------------------------------------------------------------------
/examples/langgraph-agent/src/agents/x-post-agent.ts:
--------------------------------------------------------------------------------
1 | import { tool } from "@langchain/core/tools"
2 | import { createReactAgent } from "@langchain/langgraph/prebuilt"
3 | import { Scraper } from "agent-twitter-client"
4 | import { z } from "zod"
5 | import { llm } from "../agent"
6 | import { StateAnnotation } from "../state"
7 |
8 | export const postOnXTool = tool(
9 | async ({ post }: { post: string }): Promise => {
10 | const scraper = new Scraper()
11 | const username = process.env.TWITTER_USERNAME as string
12 | const password = process.env.TWITTER_PASSWORD as string
13 |
14 | if (!username || !password) throw new Error("need username and password for posting on X")
15 | await scraper.login(username, password)
16 |
17 | const res = await scraper.sendTweet(post)
18 |
19 | return res.ok
20 | },
21 | {
22 | name: "post_on_x_twitter",
23 | description: "Post tweets on X or Twitter",
24 | schema: z.object({
25 | post: z.string().describe("twitter post"),
26 | }),
27 | }
28 | )
29 |
30 | export const createPostAgent = async () => {
31 | const agent = createReactAgent({
32 | tools: [postOnXTool],
33 | prompt: "note: you don't need confirmation from anyone",
34 | llm,
35 | })
36 |
37 | return agent
38 | }
39 |
40 | export const postNode = async (state: typeof StateAnnotation.State) => {
41 | const { messages } = state
42 |
43 | const postAgent = await createPostAgent()
44 |
45 | const result = await postAgent.invoke({ messages })
46 |
47 | return {
48 | messages: [...result.messages],
49 | }
50 | }
51 |
--------------------------------------------------------------------------------
/examples/langgraph-agent/src/index.ts:
--------------------------------------------------------------------------------
1 | import { END, START, StateGraph } from "@langchain/langgraph"
2 | import { aptosReadNode } from "./agents/aptos-read-agent"
3 | import { managerNode, managerRouter } from "./agents/manager"
4 | import { writerNode, writerTool } from "./agents/tweet-writer-agent"
5 | import { postNode, postOnXTool } from "./agents/x-post-agent"
6 | import { StateAnnotation } from "./state"
7 | import { HumanMessage } from "@langchain/core/messages"
8 |
9 | const workflow = new StateGraph(StateAnnotation)
10 | .addNode("manager", managerNode)
11 | .addNode("aptosRead", aptosReadNode)
12 | .addNode("tweetWriter", writerNode)
13 | .addNode("postOnTwitter", postNode)
14 | .addEdge("tweetWriter", "postOnTwitter")
15 | .addEdge("aptosRead", "tweetWriter")
16 | .addEdge("aptosRead", "postOnTwitter")
17 | .addEdge(START, "manager")
18 | .addConditionalEdges("manager", managerRouter)
19 | //.addEdge("aptosRead", END)
20 | //.addEdge("tweetWriter", END)
21 | // TODO: need to make sure the prompts recognize postOnTwitter tool before uncommenting above 2 lines
22 | .addEdge("postOnTwitter", END)
23 |
24 | export const graph = workflow.compile()
25 |
26 | graph.invoke({
27 | messages: [
28 | new HumanMessage("what is my address?")
29 | ]
30 | }).then(x => console.log(x))
--------------------------------------------------------------------------------
/examples/langgraph-agent/src/state.ts:
--------------------------------------------------------------------------------
1 | import { BaseMessage } from "@langchain/core/messages"
2 | import { Annotation, messagesStateReducer } from "@langchain/langgraph"
3 |
4 | export const StateAnnotation = Annotation.Root({
5 | messages: Annotation({
6 | reducer: messagesStateReducer,
7 | default: () => [],
8 | }),
9 | isAptosReadQuery: Annotation({
10 | reducer: (x, y) => y ?? x ?? false,
11 | default: () => false,
12 | }),
13 | isWriterQuery: Annotation({
14 | reducer: (x, y) => y ?? x ?? false,
15 | default: () => false,
16 | }),
17 | isXPostQuery: Annotation({
18 | reducer: (x, y) => y ?? x ?? false,
19 | default: () => false,
20 | }),
21 | })
22 |
--------------------------------------------------------------------------------
/examples/langgraph-agent/test/index.ts:
--------------------------------------------------------------------------------
1 | import { HumanMessage } from "@langchain/core/messages"
2 | import { graph } from "../src"
3 |
4 | const testBullPost = async () => {
5 | const result = await graph.invoke(
6 | {
7 | messages: [
8 | new HumanMessage(
9 | "You need to post on twitter using your account about Joule finance USDT Pool details which u can fetch"
10 | ),
11 | ],
12 | },
13 | {
14 | recursionLimit: 50,
15 | }
16 | )
17 |
18 | console.log(result)
19 |
20 | const messages = result.messages.map((msg) => ({
21 | role: msg.response_metadata.role,
22 | content: msg.content,
23 | }))
24 |
25 | for (const msg of messages) {
26 | console.log(`${msg.role}: ${msg.content}`)
27 | console.log()
28 | console.log()
29 | console.log()
30 | console.log("---------------")
31 | }
32 | }
33 |
--------------------------------------------------------------------------------
/examples/mcp-server/.gitignore:
--------------------------------------------------------------------------------
1 | # See https://help.github.com/articles/ignoring-files/ for more about ignoring files.
2 |
3 | # dependencies
4 | /node_modules
5 | /.pnp
6 | .pnp.*
7 | .yarn/*
8 | !.yarn/patches
9 | !.yarn/plugins
10 | !.yarn/releases
11 | !.yarn/versions
12 |
13 | # testing
14 | /coverage
15 |
16 | # next.js
17 | /.next/
18 | /out/
19 |
20 | # production
21 | /build
22 |
23 | # misc
24 | .DS_Store
25 | *.pem
26 |
27 | # debug
28 | npm-debug.log*
29 | yarn-debug.log*
30 | yarn-error.log*
31 | .pnpm-debug.log*
32 |
33 | # env files (can opt-in for committing if needed)
34 | .env*
35 |
36 | # vercel
37 | .vercel
38 |
39 | # typescript
40 | *.tsbuildinfo
41 | next-env.d.ts
42 |
43 |
44 | # Ignore all JavaScript files
45 | *.js
46 |
47 | # TypeScript declaration files
48 | **/*.d.ts
49 |
50 | # Ignore the script
51 | run-server.sh
--------------------------------------------------------------------------------
/examples/mcp-server/claude_desktop_config.json:
--------------------------------------------------------------------------------
1 | {
2 | "mcpServers": {
3 | "agent-kit": {
4 | "command": "/Users/nisargthakkar/move-agent-kit/examples/mcp-server/run-server.sh",
5 | "env": {},
6 | "args": []
7 | }
8 | }
9 | }
--------------------------------------------------------------------------------
/examples/mcp-server/package.json:
--------------------------------------------------------------------------------
1 | {
2 | "name": "mcp-server",
3 | "version": "1.0.0",
4 | "description": "",
5 | "main": "index.js",
6 | "scripts": {
7 | "test": "echo \"Error: no test specified\" && exit 1",
8 | "build": "tsc ",
9 | "start": "node dist/index.js",
10 | "dev": "ts-node --transpile-only src/index.ts"
11 | },
12 | "keywords": [],
13 | "author": "",
14 | "license": "ISC",
15 | "packageManager": "pnpm@10.5.2",
16 | "dependencies": {
17 | "dotenv": "^16.4.7",
18 | "ts-node": "^10.9.2"
19 | }
20 | }
21 |
--------------------------------------------------------------------------------
/examples/mcp-server/tsconfig.json:
--------------------------------------------------------------------------------
1 | {
2 | "compilerOptions": {
3 | "target": "ES2020",
4 | "module": "CommonJS",
5 | "lib": ["es2020"],
6 | "declaration": false,
7 | "outDir": "./dist",
8 | "rootDir": "../..",
9 | "strict": false,
10 | "types": ["node"],
11 | "esModuleInterop": true,
12 | "skipLibCheck": true,
13 | "forceConsistentCasingInFileNames": true,
14 | "resolveJsonModule": true,
15 | "noImplicitAny": false
16 | },
17 | "include": ["src/**/*", "../../src/**/*"],
18 | "exclude": ["node_modules", "dist"]
19 | }
--------------------------------------------------------------------------------
/examples/simple/index.ts:
--------------------------------------------------------------------------------
1 | import {
2 | Aptos,
3 | AptosConfig,
4 | Ed25519PrivateKey,
5 | HexInput,
6 | Network,
7 | PrivateKey,
8 | PrivateKeyVariants,
9 | } from "@aptos-labs/ts-sdk"
10 | import { AgentRuntime, LocalSigner } from "../../src"
11 |
12 | export const main = async () => {
13 | const aptosConfig = new AptosConfig({
14 | network: Network.MAINNET,
15 | })
16 | const aptos = new Aptos(aptosConfig)
17 | const account = await aptos.deriveAccountFromPrivateKey({
18 | privateKey: new Ed25519PrivateKey(
19 | PrivateKey.formatPrivateKey(process.env.PRIVATE_KEY as HexInput, PrivateKeyVariants.Ed25519)
20 | ),
21 | })
22 |
23 | const signer = new LocalSigner(account, Network.MAINNET)
24 | const agentRuntime = new AgentRuntime(signer, aptos)
25 |
26 | const balance = await agentRuntime.getBalance()
27 |
28 | console.log(balance)
29 | }
30 |
31 | main()
32 | .then((x) => console.log(x))
33 | .catch((e) => console.log("error", e))
34 |
--------------------------------------------------------------------------------
/lefthook.yml:
--------------------------------------------------------------------------------
1 | pre-commit:
2 | parallel: true
3 | commands:
4 | check:
5 | run: npm run check -- --staged --fix --no-errors-on-unmatched
6 | stage_fixed: true
7 | typecheck:
8 | run: npm run typecheck
9 |
--------------------------------------------------------------------------------
/move-agent-kit.jpeg:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/MetaMove/move-agent-kit/fb25bd653a9f9a11684835131bc8b9efe17f9735/move-agent-kit.jpeg
--------------------------------------------------------------------------------
/src/.DS_Store:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/MetaMove/move-agent-kit/fb25bd653a9f9a11684835131bc8b9efe17f9735/src/.DS_Store
--------------------------------------------------------------------------------
/src/constants/price-feed.ts:
--------------------------------------------------------------------------------
1 | export const priceFeed = [
2 | "0xeaa020c61cc479712813461ce153894a96a6c00b21ed0cfc2798d1f9a9e9c94a",
3 | "0x2b89b9dc8fdf9f34709a5b106b472f0f39bb6ca9ce04b0fd7f2e971688e2e53b",
4 | "0x2b89b9dc8fdf9f34709a5b106b472f0f39bb6ca9ce04b0fd7f2e971688e2e53b",
5 | "0x03ae4db29ed4ae33d323568895aa00337e658e348b37509f5372ae51f0af00d5",
6 | "0x9d4294bbcd1174d6f2003ec365831e64cc31d9f6f15a2b85399db8d5000960f6",
7 | "0x03ae4db29ed4ae33d323568895aa00337e658e348b37509f5372ae51f0af00d5",
8 | "0xc9d8b075a5c69303365ae23633d4e085199bf5c520a3b90fed1322a0342ffc33",
9 | "0xe62df6c8b4a85fe1a67db44dc12de5db330f7ac66b72dc658afedf0f4a415b43",
10 | ]
11 |
--------------------------------------------------------------------------------
/src/index.ts:
--------------------------------------------------------------------------------
1 | export * from "./signers"
2 | export * from "./agent"
3 | export * from "./langchain"
4 | export * from "./utils"
5 | export * from "./mcp"
6 |
--------------------------------------------------------------------------------
/src/langchain/account/address.ts:
--------------------------------------------------------------------------------
1 | import { Tool } from "langchain/tools"
2 | import type { AgentRuntime } from "../.."
3 |
4 | export class AptosAccountAddressTool extends Tool {
5 | name = "aptos_get_wallet_address"
6 | description = "Get the wallet address of the agent"
7 |
8 | constructor(private agent: AgentRuntime) {
9 | super()
10 | }
11 |
12 | async _call(_input: string): Promise {
13 | return this.agent.account.getAddress().toString()
14 | }
15 | }
16 |
--------------------------------------------------------------------------------
/src/langchain/account/index.ts:
--------------------------------------------------------------------------------
1 | export * from "./address"
2 |
--------------------------------------------------------------------------------
/src/langchain/amnis/index.ts:
--------------------------------------------------------------------------------
1 | export * from "./stake"
2 | export * from "./withdraw-stake"
3 |
--------------------------------------------------------------------------------
/src/langchain/amnis/stake.ts:
--------------------------------------------------------------------------------
1 | import { AccountAddress, convertAmountFromHumanReadableToOnChain } from "@aptos-labs/ts-sdk"
2 | import { Tool } from "langchain/tools"
3 | import { type AgentRuntime, parseJson } from "../.."
4 |
5 | export class AmnisStakeTool extends Tool {
6 | name = "amnis_stake"
7 | description = `this tool can be used to stake APT (Aptos) to amnis validator and receive its liquid staking token stAPT (staked APT)
8 |
9 | keep recipient blank if user themselves wants to receive stAPT and not send to anybody else
10 |
11 | Inputs ( input is a JSON string ) (required):
12 | amount: number, eg 1 or 0.01 (required)
13 | recipient: string, eg "0xf22bede237a07e121b56d91a491eb7bcdfd1f5907926a9e58338f964a01b17fa" (optional)`
14 |
15 | constructor(private agent: AgentRuntime) {
16 | super()
17 | }
18 |
19 | protected async _call(input: string): Promise {
20 | try {
21 | const parsedInput = parseJson(input)
22 |
23 | const recipient = AccountAddress.from(parsedInput.recipient) || this.agent.account.getAddress()
24 |
25 | const stakeTransactionHash = await this.agent.stakeTokensWithAmnis(
26 | recipient,
27 | convertAmountFromHumanReadableToOnChain(parsedInput.amount, 8)
28 | )
29 |
30 | return JSON.stringify({
31 | status: "success",
32 | stakeTransactionHash,
33 | token: {
34 | name: "stAPT",
35 | decimals: 8,
36 | },
37 | })
38 | } catch (error: any) {
39 | return JSON.stringify({
40 | status: "error",
41 | message: error.message,
42 | code: error.code || "UNKNOWN_ERROR",
43 | })
44 | }
45 | }
46 | }
47 |
--------------------------------------------------------------------------------
/src/langchain/amnis/withdraw-stake.ts:
--------------------------------------------------------------------------------
1 | import { AccountAddress, convertAmountFromHumanReadableToOnChain } from "@aptos-labs/ts-sdk"
2 | import { Tool } from "langchain/tools"
3 | import { type AgentRuntime, parseJson } from "../.."
4 |
5 | export class AmnisWithdrawStakeTool extends Tool {
6 | name = "amnis_withdraw_stake"
7 | description = `this tool can be used to withdraw staked APT (Aptos) from amnis validator and receive back APT
8 |
9 | keep recipient blank if user themselves wants to receive APT and not send to anybody else
10 |
11 | Inputs ( input is a JSON string ):
12 | amount: number, eg 1 or 0.01 (required)
13 | recipient: string, eg "0xf22bede237a07e121b56d91a491eb7bcdfd1f5907926a9e58338f964a01b17fa" (optional)`
14 |
15 | constructor(private agent: AgentRuntime) {
16 | super()
17 | }
18 |
19 | protected async _call(input: string): Promise {
20 | try {
21 | const parsedInput = parseJson(input)
22 |
23 | const recipient = AccountAddress.from(parsedInput.recipient) || this.agent.account.getAddress()
24 |
25 | const withdrawStakeTransactionHash = await this.agent.withdrawStakeFromAmnis(
26 | recipient,
27 | convertAmountFromHumanReadableToOnChain(parsedInput.amount, 8)
28 | )
29 |
30 | return JSON.stringify({
31 | status: "success",
32 | withdrawStakeTransactionHash,
33 | token: {
34 | name: "APT",
35 | decimals: 8,
36 | },
37 | })
38 | } catch (error: any) {
39 | return JSON.stringify({
40 | status: "error",
41 | message: error.message,
42 | code: error.code || "UNKNOWN_ERROR",
43 | })
44 | }
45 | }
46 | }
47 |
--------------------------------------------------------------------------------
/src/langchain/aptos/balance.ts:
--------------------------------------------------------------------------------
1 | import { Tool } from "langchain/tools"
2 | import { type AgentRuntime, parseJson } from "../.."
3 |
4 | export class AptosBalanceTool extends Tool {
5 | name = "aptos_balance"
6 | description = `Get the balance of a Aptos account.
7 |
8 | If you want to get the balance of your wallet, you don't need to provide the mint.
9 | If no mint is provided, the balance will be in APT.
10 | if you want to get balance of a fungible asset, you need to provide the asset address as mint
11 |
12 | Inputs ( input is a JSON string ):
13 | mint: string, eg "0xf22bede237a07e121b56d91a491eb7bcdfd1f5907926a9e58338f964a01b17fa::asset::USDT" or "
14 | 0x357b0b74bc833e95a115ad22604854d6b0fca151cecd94111770e5d6ffc9dc2b" (optional)`
15 |
16 | constructor(private agent: AgentRuntime) {
17 | super()
18 | }
19 |
20 | protected async _call(input: string): Promise {
21 | try {
22 | const parsedInput = parseJson(input)
23 | const mint = parsedInput.mint || undefined
24 | const mintDetails: any = this.agent.getTokenDetails(mint)
25 | const balance = await this.agent.getBalance(mint)
26 |
27 | return JSON.stringify({
28 | status: "success",
29 | balance,
30 | token: {
31 | name: mintDetails.name || "APT",
32 | decimals: mintDetails.decimals || 8,
33 | },
34 | })
35 | } catch (error: any) {
36 | return JSON.stringify({
37 | status: "error",
38 | message: error.message,
39 | code: error.code || "UNKNOWN_ERROR",
40 | })
41 | }
42 | }
43 | }
44 |
--------------------------------------------------------------------------------
/src/langchain/aptos/burn-nft.ts:
--------------------------------------------------------------------------------
1 | import { Tool } from "langchain/tools"
2 | import { type AgentRuntime, parseJson } from "../.."
3 |
4 | export class AptosBurnNFTTool extends Tool {
5 | name = "aptos_burn_nft"
6 | description = `this tool can be used to burn any NFT on aptos
7 |
8 | Inputs ( input is a JSON string ):
9 | mint: string, eg "0xf22bede237a07e121b56d91a491eb7bcdfd1f5907926a9e58338f964a01b17fa::asset::USDT" (required)`
10 |
11 | constructor(private agent: AgentRuntime) {
12 | super()
13 | }
14 |
15 | protected async _call(input: string): Promise {
16 | try {
17 | const parsedInput = parseJson(input)
18 |
19 | const transfer = await this.agent.burnNFT(parsedInput.mint)
20 |
21 | return JSON.stringify({
22 | status: "success",
23 | transfer,
24 | nft: parsedInput.mint,
25 | })
26 | } catch (error: any) {
27 | return JSON.stringify({
28 | status: "error",
29 | message: error.message,
30 | code: error.code || "UNKNOWN_ERROR",
31 | })
32 | }
33 | }
34 | }
35 |
--------------------------------------------------------------------------------
/src/langchain/aptos/burn-token.ts:
--------------------------------------------------------------------------------
1 | import { convertAmountFromHumanReadableToOnChain } from "@aptos-labs/ts-sdk"
2 | import { Tool } from "langchain/tools"
3 | import { type AgentRuntime, parseJson } from "../.."
4 |
5 | export class AptosBurnTokenTool extends Tool {
6 | name = "aptos_burn_token"
7 | description = `this tool can be used to burn a fungible asset
8 |
9 | Inputs ( input is a JSON string ):
10 | amount: number, eg 1 or 0.01 (required)
11 | mint: string, "0xf22bede237a07e121b56d91a491eb7bcdfd1f5907926a9e58338f964a01b17fa" (required)`
12 |
13 | constructor(private agent: AgentRuntime) {
14 | super()
15 | }
16 |
17 | protected async _call(input: string): Promise {
18 | try {
19 | const parsedInput = parseJson(input)
20 |
21 | const mintDetail = await this.agent.getTokenDetails(parsedInput.mint)
22 |
23 | const burnTransactionHash = await this.agent.burnToken(
24 | convertAmountFromHumanReadableToOnChain(parsedInput.amount, mintDetail.decimals || 8),
25 | parsedInput.mint
26 | )
27 |
28 | return JSON.stringify({
29 | status: "success",
30 | burnTransactionHash,
31 | token: {
32 | name: mintDetail.name,
33 | decimals: mintDetail.decimals,
34 | },
35 | })
36 | } catch (error: any) {
37 | return JSON.stringify({
38 | status: "error",
39 | message: error.message,
40 | code: error.code || "UNKNOWN_ERROR",
41 | })
42 | }
43 | }
44 | }
45 |
--------------------------------------------------------------------------------
/src/langchain/aptos/create-token.ts:
--------------------------------------------------------------------------------
1 | import { Tool } from "langchain/tools"
2 | import { type AgentRuntime, parseJson } from "../.."
3 |
4 | export class AptosCreateTokenTool extends Tool {
5 | name = "aptos_create_token"
6 | description = `this tool can be used to create fungible asset to a recipient
7 |
8 | Inputs ( input is a JSON string ):
9 | name: string, eg "USDT" (required)
10 | symbol: string, eg "USDT" (required)
11 | iconURI: string, eg "https://example.com/icon.png" (required)
12 | projectURI: string, eg "https://example.com/project" (required)
13 | `
14 |
15 | constructor(private agent: AgentRuntime) {
16 | super()
17 | }
18 |
19 | protected async _call(input: string): Promise {
20 | try {
21 | const parsedInput = parseJson(input)
22 |
23 | const createTokenTransactionHash = await this.agent.createToken(
24 | parsedInput.name,
25 | parsedInput.symbol,
26 | parsedInput.iconURI,
27 | parsedInput.projectURI
28 | )
29 |
30 | return JSON.stringify({
31 | status: "success",
32 | createTokenTransactionHash,
33 | token: {
34 | name: parsedInput.name,
35 | decimals: 8,
36 | },
37 | })
38 | } catch (error: any) {
39 | return JSON.stringify({
40 | status: "error",
41 | message: error.message,
42 | code: error.code || "UNKNOWN_ERROR",
43 | })
44 | }
45 | }
46 | }
47 |
--------------------------------------------------------------------------------
/src/langchain/aptos/get-token-details.ts:
--------------------------------------------------------------------------------
1 | import { Tool } from "langchain/tools"
2 | import { type AgentRuntime, parseJson } from "../.."
3 |
4 | export class AptosGetTokenDetailTool extends Tool {
5 | name = "aptos_token_details"
6 | description = `Get the detail of any aptos tokens
7 |
8 | details also include decimals which you can use to make onchain values readable to a human user
9 |
10 | Inputs ( input is a JSON string ):
11 | token: string, eg "0xf22bede237a07e121b56d91a491eb7bcdfd1f5907926a9e58338f964a01b17fa::asset::USDT" (optional)`
12 |
13 | constructor(private agent: AgentRuntime) {
14 | super()
15 | }
16 |
17 | protected async _call(input: string): Promise {
18 | try {
19 | const parsedInput = parseJson(input)
20 | const mint = parsedInput.token || ""
21 |
22 | const tokenData = await this.agent.getTokenDetails(mint)
23 |
24 | return JSON.stringify({
25 | status: "success",
26 | tokenData,
27 | })
28 | } catch (error: any) {
29 | return JSON.stringify({
30 | status: "error",
31 | message: error.message,
32 | code: error.code || "UNKNOWN_ERROR",
33 | })
34 | }
35 | }
36 | }
37 |
--------------------------------------------------------------------------------
/src/langchain/aptos/get-token-price.ts:
--------------------------------------------------------------------------------
1 | import { Tool } from "langchain/tools"
2 | import { type AgentRuntime, parseJson } from "../.."
3 |
4 | export class AptosGetTokenPriceTool extends Tool {
5 | name = "aptos_token_price"
6 | description = `Get the live price of any aptos tokens in USD.
7 | do not do any decimals conversion here, the price is already in USD
8 |
9 | details also include decimals which you can use to make onchain values readable to a human user
10 |
11 | Inputs ( input is a JSON string - this is IMPORTANT):
12 | token: string, eg usdt, btc etc.`
13 |
14 | constructor(private agent: AgentRuntime) {
15 | super()
16 | }
17 |
18 | protected async _call(input: string): Promise {
19 | console.log("input", input)
20 | try {
21 | const parsedInput = parseJson(input)
22 | const token = parsedInput.token || input || "usdt"
23 |
24 | const tokenData = await this.agent.getTokenPrice(token)
25 |
26 | return JSON.stringify({
27 | status: "success",
28 | tokenData,
29 | })
30 | } catch (error: any) {
31 | return JSON.stringify({
32 | status: "error",
33 | message: error.message,
34 | code: error.code || "UNKNOWN_ERROR",
35 | })
36 | }
37 | }
38 | }
39 |
--------------------------------------------------------------------------------
/src/langchain/aptos/get-transaction.ts:
--------------------------------------------------------------------------------
1 | import { Tool } from "langchain/tools"
2 | import { type AgentRuntime, parseJson } from "../.."
3 |
4 | export class AptosTransactionTool extends Tool {
5 | name = "aptos_get_transaction"
6 | description = `Fetches a transaction from aptos blockchain
7 |
8 | Inputs ( input is a JSON string ):
9 | transactionHash: string, eg "0xf22bede237a07e121b56d91a491eb7bcdfd1f5907926a9e58338f964a01b17fa" (required)`
10 |
11 | constructor(private agent: AgentRuntime) {
12 | super()
13 | }
14 |
15 | protected async _call(input: string): Promise {
16 | try {
17 | const parsedInput = parseJson(input)
18 |
19 | const aptosTransaction = await this.agent.getTransaction(parsedInput.transactionHash)
20 |
21 | return JSON.stringify({
22 | status: "success",
23 | aptosTransaction,
24 | })
25 | } catch (error: any) {
26 | return JSON.stringify({
27 | status: "error",
28 | message: error.message,
29 | code: error.code || "UNKNOWN_ERROR",
30 | })
31 | }
32 | }
33 | }
34 |
--------------------------------------------------------------------------------
/src/langchain/aptos/index.ts:
--------------------------------------------------------------------------------
1 | export * from "./balance"
2 | export * from "./get-token-details"
3 | export * from "./transfer-token"
4 | export * from "./burn-token"
5 | export * from "./mint-token"
6 | export * from "./create-token"
7 | export * from "./get-transaction"
8 | export * from "./get-token-price"
9 |
--------------------------------------------------------------------------------
/src/langchain/aptos/mint-token.ts:
--------------------------------------------------------------------------------
1 | import { AccountAddress } from "@aptos-labs/ts-sdk"
2 | import { Tool } from "langchain/tools"
3 | import { type AgentRuntime, parseJson } from "../.."
4 |
5 | export class AptosMintTokenTool extends Tool {
6 | name = "aptos_mint_token"
7 | description = `this tool can be used to create fungible asset to a recipient
8 |
9 | if the recipient wants to receive the token and not send to anybody else, keep to blank
10 |
11 | Inputs ( input is a JSON string ):
12 | to: string, eg "0xf22bede237a07e121b56d91a491eb7bcdfd1f5907926a9e58338f964a01b17fa" (required)
13 | amount: number, eg 1 or 0.01 (required)
14 | mint: string, eg "0xf22bede237a07e121b56d91a491eb7bcdfd1f5907926a9e58338f964a01b17fa" (required)
15 | `
16 |
17 | constructor(private agent: AgentRuntime) {
18 | super()
19 | }
20 |
21 | protected async _call(input: string): Promise {
22 | try {
23 | const parsedInput = parseJson(input)
24 |
25 | const mintDetail = await this.agent.getTokenDetails(parsedInput.mint)
26 |
27 | const recipient = AccountAddress.from(parsedInput.to) || this.agent.account.getAddress()
28 | const mintTokenTransactionHash = await this.agent.mintToken(recipient, parsedInput.mint, parsedInput.amount)
29 |
30 | return JSON.stringify({
31 | status: "success",
32 | mintTokenTransactionHash,
33 | token: {
34 | name: mintDetail.name || "APT",
35 | decimals: 8,
36 | },
37 | })
38 | } catch (error: any) {
39 | return JSON.stringify({
40 | status: "error",
41 | message: error.message,
42 | code: error.code || "UNKNOWN_ERROR",
43 | })
44 | }
45 | }
46 | }
47 |
--------------------------------------------------------------------------------
/src/langchain/aptos/transfer-nft.ts:
--------------------------------------------------------------------------------
1 | import { AccountAddress } from "@aptos-labs/ts-sdk"
2 | import { Tool } from "langchain/tools"
3 | import { type AgentRuntime, parseJson } from "../.."
4 |
5 | export class AptosTransferNFTTool extends Tool {
6 | name = "aptos_transfer_nft"
7 | description = `this tool can be used to transfer any NFT on aptos to receipient
8 |
9 | Inputs ( input is a JSON string ):
10 | to: string, eg "0xf22bede237a07e121b56d91a491eb7bcdfd1f5907926a9e58338f964a01b17fa" (required)
11 | mint: string, eg "0xf22bede237a07e121b56d91a491eb7bcdfd1f5907926a9e58338f964a01b17fa::asset::USDT" (required)`
12 |
13 | constructor(private agent: AgentRuntime) {
14 | super()
15 | }
16 |
17 | protected async _call(input: string): Promise {
18 | try {
19 | const parsedInput = parseJson(input)
20 |
21 | const transfer = await this.agent.transferNFT(AccountAddress.from(parsedInput.to), parsedInput.mint)
22 |
23 | return JSON.stringify({
24 | status: "success",
25 | transfer,
26 | nft: parsedInput.mint,
27 | })
28 | } catch (error: any) {
29 | return JSON.stringify({
30 | status: "error",
31 | message: error.message,
32 | code: error.code || "UNKNOWN_ERROR",
33 | })
34 | }
35 | }
36 | }
37 |
--------------------------------------------------------------------------------
/src/langchain/aptos/transfer-token.ts:
--------------------------------------------------------------------------------
1 | import { AccountAddress, convertAmountFromHumanReadableToOnChain } from "@aptos-labs/ts-sdk"
2 | import { Tool } from "langchain/tools"
3 | import { type AgentRuntime, parseJson } from "../.."
4 |
5 | export class AptosTransferTokenTool extends Tool {
6 | name = "aptos_transfer_token"
7 | description = `this tool can be used to transfer APT, any token or fungible asset to a recipient
8 |
9 | if you want to transfer APT, mint will be "0x1::aptos_coin::AptosCoin"
10 | if you want to transfer token other than APT, you need to provide the mint of that specific token
11 | if you want to transfer fungible asset, add fungible asset address as mint
12 |
13 | keep to blank if user themselves wants to receive the token and not send to anybody else
14 |
15 | Inputs ( input is a JSON string ):
16 | to: string, eg "0xf22bede237a07e121b56d91a491eb7bcdfd1f5907926a9e58338f964a01b17fa" (optional)
17 | amount: number, eg 1 or 0.01 (required)
18 | mint: string, eg "0xf22bede237a07e121b56d91a491eb7bcdfd1f5907926a9e58338f964a01b17fa::asset::USDT"
19 | or "0xf22bede237a07e121b56d91a491eb7bcdfd1f5907926a9e58338f964a01b17fa" (required)`
20 |
21 | constructor(private agent: AgentRuntime) {
22 | super()
23 | }
24 |
25 | protected async _call(input: string): Promise {
26 | try {
27 | const parsedInput = parseJson(input)
28 |
29 | const mintDetail = await this.agent.getTokenDetails(parsedInput.mint)
30 |
31 | const recipient = AccountAddress.from(parsedInput.to) || this.agent.account.getAddress()
32 |
33 | const transferTokenTransactionHash = await this.agent.transferTokens(
34 | recipient,
35 | convertAmountFromHumanReadableToOnChain(parsedInput.amount, mintDetail.decimals || 6),
36 | parsedInput.mint
37 | )
38 |
39 | return JSON.stringify({
40 | status: "success",
41 | transferTokenTransactionHash,
42 | token: {
43 | name: mintDetail.name,
44 | decimals: mintDetail.decimals,
45 | },
46 | })
47 | } catch (error: any) {
48 | return JSON.stringify({
49 | status: "error",
50 | message: error.message,
51 | code: error.code || "UNKNOWN_ERROR",
52 | })
53 | }
54 | }
55 | }
56 |
--------------------------------------------------------------------------------
/src/langchain/aries/borrow-token.ts:
--------------------------------------------------------------------------------
1 | import { convertAmountFromHumanReadableToOnChain } from "@aptos-labs/ts-sdk"
2 | import { Tool } from "langchain/tools"
3 | import type { AgentRuntime } from "../../agent"
4 | import { parseJson } from "../../utils"
5 |
6 | export class AriesBorrowTool extends Tool {
7 | name = "aries_borrow"
8 | description = `this tool can be used to borrow tokens from Aries
9 |
10 | if you want to borrow APT, mintType will be "0x1::aptos_coin::AptosCoin"
11 |
12 | Inputs ( input is a JSON string ):
13 | mintType: string, eg "0x1::aptos_coin::AptosCoin" (required)
14 | amount: number, eg 1 or 0.01 (required)
15 | `
16 |
17 | constructor(private agent: AgentRuntime) {
18 | super()
19 | }
20 |
21 | protected async _call(input: string): Promise {
22 | try {
23 | const parsedInput = parseJson(input)
24 |
25 | const mintDetail = await this.agent.getTokenDetails(parsedInput.mint)
26 |
27 | const borrowTokenTransactionHash = await this.agent.borrowAriesToken(
28 | parsedInput.mintType,
29 | convertAmountFromHumanReadableToOnChain(parsedInput.amount, mintDetail.decimals || 8)
30 | )
31 |
32 | return JSON.stringify({
33 | status: "success",
34 | borrowTokenTransactionHash,
35 | token: {
36 | name: mintDetail.name,
37 | decimals: mintDetail.decimals,
38 | },
39 | })
40 | } catch (error: any) {
41 | return JSON.stringify({
42 | status: "error",
43 | message: error.message,
44 | code: error.code || "UNKNOWN_ERROR",
45 | })
46 | }
47 | }
48 | }
49 |
--------------------------------------------------------------------------------
/src/langchain/aries/create-profile.ts:
--------------------------------------------------------------------------------
1 | import { Tool } from "langchain/tools"
2 | import type { AgentRuntime } from "../.."
3 |
4 | export class AriesCreateProfileTool extends Tool {
5 | name = "aries_create_profile"
6 | description = `this tool can be used to create a profile in Aries
7 | `
8 |
9 | constructor(private agent: AgentRuntime) {
10 | super()
11 | }
12 |
13 | protected async _call(): Promise {
14 | try {
15 | const createProfileTransactionHash = await this.agent.createAriesProfile()
16 |
17 | return JSON.stringify({
18 | status: "success",
19 | createProfileTransactionHash,
20 | })
21 | } catch (error: any) {
22 | return JSON.stringify({
23 | status: "error",
24 | message: error.message,
25 | code: error.code || "UNKNOWN_ERROR",
26 | })
27 | }
28 | }
29 | }
30 |
--------------------------------------------------------------------------------
/src/langchain/aries/index.ts:
--------------------------------------------------------------------------------
1 | export * from "./create-profile"
2 | export * from "./lend-token"
3 | export * from "./withdraw-token"
4 | export * from "./borrow-token"
5 | export * from "./repay-token"
6 |
--------------------------------------------------------------------------------
/src/langchain/aries/lend-token.ts:
--------------------------------------------------------------------------------
1 | import { convertAmountFromHumanReadableToOnChain } from "@aptos-labs/ts-sdk"
2 | import { Tool } from "langchain/tools"
3 | import type { AgentRuntime } from "../../agent"
4 | import { parseJson } from "../../utils"
5 |
6 | export class AriesLendTool extends Tool {
7 | name = "aries_lend"
8 | description = `this tool can be used to lend tokens in Aries
9 |
10 | if you want to lend APT, mintType will be "0x1::aptos_coin::AptosCoin"
11 |
12 | Inputs ( input is a JSON string ):
13 | mintType: string, eg "0x1::aptos_coin::AptosCoin" (required)
14 | amount: number, eg 1 or 0.01 (required)
15 | `
16 |
17 | constructor(private agent: AgentRuntime) {
18 | super()
19 | }
20 |
21 | protected async _call(input: string): Promise {
22 | try {
23 | const parsedInput = parseJson(input)
24 |
25 | const mintDetail = await this.agent.getTokenDetails(parsedInput.mint)
26 |
27 | const lendTokenTransactionHash = await this.agent.lendAriesToken(
28 | parsedInput.mintType,
29 | convertAmountFromHumanReadableToOnChain(parsedInput.amount, mintDetail.decimals || 8)
30 | )
31 |
32 | return JSON.stringify({
33 | status: "success",
34 | lendTokenTransactionHash,
35 | token: {
36 | name: mintDetail.name,
37 | decimals: mintDetail.decimals,
38 | },
39 | })
40 | } catch (error: any) {
41 | return JSON.stringify({
42 | status: "error",
43 | message: error.message,
44 | code: error.code || "UNKNOWN_ERROR",
45 | })
46 | }
47 | }
48 | }
49 |
--------------------------------------------------------------------------------
/src/langchain/aries/repay-token.ts:
--------------------------------------------------------------------------------
1 | import { convertAmountFromHumanReadableToOnChain } from "@aptos-labs/ts-sdk"
2 | import { Tool } from "langchain/tools"
3 | import type { AgentRuntime } from "../../agent"
4 | import { parseJson } from "../../utils"
5 |
6 | export class AriesRepayTool extends Tool {
7 | name = "aries_repay"
8 | description = `this tool can be used to repay tokens in Aries
9 |
10 | if you want to repay APT, mintType will be "0x1::aptos_coin::AptosCoin"
11 |
12 | Inputs ( input is a JSON string ):
13 | mintType: string, eg "0x1::aptos_coin::AptosCoin" (required)
14 | amount: number, eg 1 or 0.01 (required)
15 | `
16 |
17 | constructor(private agent: AgentRuntime) {
18 | super()
19 | }
20 |
21 | protected async _call(input: string): Promise {
22 | try {
23 | const parsedInput = parseJson(input)
24 |
25 | const mintDetail = await this.agent.getTokenDetails(parsedInput.mint)
26 |
27 | const repayTokenTransactionHash = await this.agent.repayAriesToken(
28 | parsedInput.mintType,
29 | convertAmountFromHumanReadableToOnChain(parsedInput.amount, mintDetail.decimals || 8)
30 | )
31 |
32 | return JSON.stringify({
33 | status: "success",
34 | repayTokenTransactionHash,
35 | token: {
36 | name: mintDetail.name,
37 | decimals: mintDetail.decimals,
38 | },
39 | })
40 | } catch (error: any) {
41 | return JSON.stringify({
42 | status: "error",
43 | message: error.message,
44 | code: error.code || "UNKNOWN_ERROR",
45 | })
46 | }
47 | }
48 | }
49 |
--------------------------------------------------------------------------------
/src/langchain/aries/withdraw-token.ts:
--------------------------------------------------------------------------------
1 | import { convertAmountFromHumanReadableToOnChain } from "@aptos-labs/ts-sdk"
2 | import { Tool } from "langchain/tools"
3 | import type { AgentRuntime } from "../../agent"
4 | import { parseJson } from "../../utils"
5 |
6 | export class AriesWithdrawTool extends Tool {
7 | name = "aries_withdraw"
8 | description = `this tool can be used to withdraw tokens from Aries
9 |
10 | if you want to withdraw APT, mintType will be "0x1::aptos_coin::AptosCoin"
11 |
12 | Inputs ( input is a JSON string ):
13 | mintType: string, eg "0x1::aptos_coin::AptosCoin" (required)
14 | amount: number, eg 1 or 0.01 (required)
15 | `
16 |
17 | constructor(private agent: AgentRuntime) {
18 | super()
19 | }
20 |
21 | protected async _call(input: string): Promise {
22 | try {
23 | const parsedInput = parseJson(input)
24 |
25 | const mintDetail = await this.agent.getTokenDetails(parsedInput.mint)
26 |
27 | const withdrawTokenTransactionHash = await this.agent.withdrawAriesToken(
28 | parsedInput.mintType,
29 | convertAmountFromHumanReadableToOnChain(parsedInput.amount, mintDetail.decimals || 8)
30 | )
31 |
32 | return JSON.stringify({
33 | status: "success",
34 | withdrawTokenTransactionHash,
35 | token: {
36 | name: mintDetail.name,
37 | decimals: mintDetail.decimals || 8,
38 | },
39 | })
40 | } catch (error: any) {
41 | return JSON.stringify({
42 | status: "error",
43 | message: error.message,
44 | code: error.code || "UNKNOWN_ERROR",
45 | })
46 | }
47 | }
48 | }
49 |
--------------------------------------------------------------------------------
/src/langchain/echelon/borrow-token.ts:
--------------------------------------------------------------------------------
1 | import { type MoveStructId, convertAmountFromHumanReadableToOnChain } from "@aptos-labs/ts-sdk"
2 | import { Tool } from "langchain/tools"
3 | import { type AgentRuntime, parseJson } from "../.."
4 | import { getTokenByTokenAddress, getTokenByTokenName } from "../../utils/get-pool-address-by-token-name"
5 |
6 | export class EchelonBorrowTokenTool extends Tool {
7 | name = "echelon_borrow_token"
8 | description = `this tool can be used to borrow APT, tokens or fungible asset from a position
9 |
10 | if you want to borrow APT, mint will be "0x1::aptos_coin::AptosCoin"
11 |
12 | if user added mint as asset name, and you don't have the address of the asset, you can use the following token names:
13 | ['usdt', 'zusdt', 'zusdc', 'apt', 'sthapt', 'mod', 'thl', 'wusdc' , 'zweth', 'wweth', 'cake', 'stapt', 'abtc', 'stone' , 'truapt', 'sbtc']
14 | or whatever name the user has provided, you can use the token name to get the address of the token
15 |
16 |
17 | Inputs ( input is a JSON string ) (IMPORTANT):
18 | amount: number, eg 1 or 0.01 (required)
19 | mint: string, eg "0xf22bede237a07e121b56d91a491eb7bcdfd1f5907926a9e58338f964a01b17fa::asset::USDT" or "usdt (name of the token)" (required)
20 | `
21 |
22 | constructor(private agent: AgentRuntime) {
23 | super()
24 | }
25 |
26 | protected async _call(input: string): Promise {
27 | try {
28 | const parsedInput = parseJson(input)
29 |
30 | const token = getTokenByTokenName(parsedInput.mint) || getTokenByTokenAddress(parsedInput.mint)
31 |
32 | if (!token) throw new Error("Token not found")
33 |
34 | const mintDetail = await this.agent.getTokenDetails(token.tokenAddress)
35 |
36 | const borrowTokenTransactionHash = await this.agent.borrowTokenWithEchelon(
37 | token.tokenAddress as MoveStructId,
38 | convertAmountFromHumanReadableToOnChain(parsedInput.amount, mintDetail.decimals || 8),
39 | token.poolAddress,
40 | token.tokenAddress.split("::").length !== 3
41 | )
42 |
43 | return JSON.stringify({
44 | status: "success",
45 | borrowTokenTransactionHash,
46 | token: {
47 | name: mintDetail.name || "APT",
48 | decimals: mintDetail.decimals || 8,
49 | },
50 | })
51 | } catch (error: any) {
52 | return JSON.stringify({
53 | status: "error",
54 | message: error.message,
55 | code: error.code || "UNKNOWN_ERROR",
56 | })
57 | }
58 | }
59 | }
60 |
--------------------------------------------------------------------------------
/src/langchain/echelon/index.ts:
--------------------------------------------------------------------------------
1 | export * from "./lend-token"
2 | export * from "./withdraw-token"
3 | export * from "./repay-token"
4 | export * from "./borrow-token"
5 |
--------------------------------------------------------------------------------
/src/langchain/echelon/lend-token.ts:
--------------------------------------------------------------------------------
1 | import { type MoveStructId, convertAmountFromHumanReadableToOnChain } from "@aptos-labs/ts-sdk"
2 | import { Tool } from "langchain/tools"
3 | import { type AgentRuntime, parseJson } from "../.."
4 | import { getTokenByTokenAddress, getTokenByTokenName } from "../../utils/get-pool-address-by-token-name"
5 |
6 | export class EchelonLendTokenTool extends Tool {
7 | name = "echelon_lend_token"
8 | description = `this tool can be used to lend APT, tokens or fungible asset to a position
9 |
10 | if you want to lend APT, mint will be "0x1::aptos_coin::AptosCoin"
11 | if user added mint as asset name, and you don't have the address of the asset, you can use the following token names:
12 | ['usdt', 'zusdt', 'zusdc', 'apt', 'sthapt', 'mod', 'thl', 'wusdc' , 'zweth', 'wweth', 'cake', 'stapt', 'abtc', 'stone' , 'truapt', 'sbtc']
13 | or whatever name the user has provided, you can use the token name to get the address of the token
14 |
15 | Inputs ( input is a JSON string ) (IMPORTANT):
16 | amount: number, eg 1 or 0.01 (required)
17 | mint: string, eg "0xf22bede237a07e121b56d91a491eb7bcdfd1f5907926a9e58338f964a01b17fa::asset::USDT" or "usdt (name of the token)" (required)
18 | `
19 |
20 | constructor(private agent: AgentRuntime) {
21 | super()
22 | }
23 |
24 | protected async _call(input: string): Promise {
25 | try {
26 | const parsedInput = parseJson(input)
27 |
28 | const token = getTokenByTokenName(parsedInput.mint) || getTokenByTokenAddress(parsedInput.mint)
29 |
30 | if (!token) throw new Error("Token not found")
31 |
32 | const mintDetail = await this.agent.getTokenDetails(token.tokenAddress)
33 |
34 | console.log("mintDetail", mintDetail)
35 |
36 | const lendTokenTransactionHash = await this.agent.lendTokenWithEchelon(
37 | token.tokenAddress as MoveStructId,
38 | convertAmountFromHumanReadableToOnChain(parsedInput.amount, mintDetail.decimals || 8),
39 | token.poolAddress,
40 | token.tokenAddress.split("::").length !== 3
41 | )
42 |
43 | return JSON.stringify({
44 | status: "success",
45 | lendTokenTransactionHash,
46 | token: {
47 | name: mintDetail.name || "APT",
48 | decimals: mintDetail.decimals || 8,
49 | },
50 | })
51 | } catch (error: any) {
52 | return JSON.stringify({
53 | status: "error",
54 | message: error.message,
55 | code: error.code || "UNKNOWN_ERROR",
56 | })
57 | }
58 | }
59 | }
60 |
--------------------------------------------------------------------------------
/src/langchain/echelon/repay-token.ts:
--------------------------------------------------------------------------------
1 | import { type MoveStructId, convertAmountFromHumanReadableToOnChain } from "@aptos-labs/ts-sdk"
2 | import { Tool } from "langchain/tools"
3 | import { type AgentRuntime, parseJson } from "../.."
4 | import { getTokenByTokenAddress, getTokenByTokenName } from "../../utils/get-pool-address-by-token-name"
5 |
6 | export class EchelonRepayTokenTool extends Tool {
7 | name = "echelon_repay_token"
8 | description = `this tool can be used to repay APT, tokens or fungible asset from a position
9 |
10 | if you want to repay APT, mint will be "0x1::aptos_coin::AptosCoin"
11 | if user added mint as asset name, and you don't have the address of the asset, you can use the following token names:
12 | ['usdt', 'zusdt', 'zusdc', 'apt', 'sthapt', 'mod', 'thl', 'wusdc' , 'zweth', 'wweth', 'cake', 'stapt', 'abtc', 'stone' , 'truapt', 'sbtc']
13 | or whatever name the user has provided, you can use the token name to get the address of the token
14 |
15 | Inputs ( input is a JSON string ) (IMPORTANT):
16 | amount: number, eg 1 or 0.01 (required)
17 | mint: string, eg "0xf22bede237a07e121b56d91a491eb7bcdfd1f5907926a9e58338f964a01b17fa::asset::USDT" or "usdt (name of the token)" (required)
18 | `
19 |
20 | constructor(private agent: AgentRuntime) {
21 | super()
22 | }
23 |
24 | protected async _call(input: string): Promise {
25 | try {
26 | const parsedInput = parseJson(input)
27 |
28 | const token = getTokenByTokenName(parsedInput.mint) || getTokenByTokenAddress(parsedInput.mint)
29 |
30 | if (!token) throw new Error("Token not found")
31 |
32 | const mintDetail = await this.agent.getTokenDetails(token.tokenAddress)
33 |
34 | const repayTokenTransactionHash = await this.agent.repayTokenWithEchelon(
35 | token.tokenAddress as MoveStructId,
36 | convertAmountFromHumanReadableToOnChain(parsedInput.amount, mintDetail.decimals || 8),
37 | token.poolAddress,
38 | token.tokenAddress.split("::").length !== 3
39 | )
40 |
41 | return JSON.stringify({
42 | status: "success",
43 | repayTokenTransactionHash,
44 | token: {
45 | name: mintDetail.name || "APT",
46 | decimals: mintDetail.decimals || 8,
47 | },
48 | })
49 | } catch (error: any) {
50 | return JSON.stringify({
51 | status: "error",
52 | message: error.message,
53 | code: error.code || "UNKNOWN_ERROR",
54 | })
55 | }
56 | }
57 | }
58 |
--------------------------------------------------------------------------------
/src/langchain/echelon/withdraw-token.ts:
--------------------------------------------------------------------------------
1 | import { type MoveStructId, convertAmountFromHumanReadableToOnChain } from "@aptos-labs/ts-sdk"
2 | import { Tool } from "langchain/tools"
3 | import { type AgentRuntime, parseJson } from "../.."
4 | import { getTokenByTokenAddress, getTokenByTokenName } from "../../utils/get-pool-address-by-token-name"
5 |
6 | export class EchelonWithdrawTokenTool extends Tool {
7 | name = "echelon_withdraw_token"
8 | description = `this tool can be used to withdraw APT, tokens or fungible asset from a position
9 |
10 | if you want to withdraw APT, mint will be "0x1::aptos_coin::AptosCoin"
11 | if user added mint as asset name, and you don't have the address of the asset, you can use the following token names:
12 | ['usdt', 'zusdt', 'zusdc', 'apt', 'sthapt', 'mod', 'thl', 'wusdc' , 'zweth', 'wweth', 'cake', 'stapt', 'abtc', 'stone' , 'truapt', 'sbtc']
13 | or whatever name the user has provided, you can use the token name to get the address of the token
14 |
15 | Inputs ( input is a JSON string ) (IMPORTANT):
16 | amount: number, eg 1 or 0.01 (required)
17 | mint: string, eg "0xf22bede237a07e121b56d91a491eb7bcdfd1f5907926a9e58338f964a01b17fa::asset::USDT" or "usdt (name of the token)" (required)
18 | `
19 |
20 | constructor(private agent: AgentRuntime) {
21 | super()
22 | }
23 |
24 | protected async _call(input: string): Promise {
25 | try {
26 | const parsedInput = parseJson(input)
27 |
28 | const token = getTokenByTokenName(parsedInput.mint) || getTokenByTokenAddress(parsedInput.mint)
29 |
30 | if (!token) throw new Error("Token not found")
31 |
32 | const mintDetail = await this.agent.getTokenDetails(token.tokenAddress)
33 |
34 | console.log("mintDetail", mintDetail)
35 |
36 | const withdrawTokenTransactionHash = await this.agent.withdrawTokenWithEchelon(
37 | token.tokenAddress as MoveStructId,
38 | convertAmountFromHumanReadableToOnChain(parsedInput.amount, mintDetail.decimals || 8),
39 | token.poolAddress,
40 | token.tokenAddress.split("::").length !== 3
41 | )
42 |
43 | return JSON.stringify({
44 | status: "success",
45 | withdrawTokenTransactionHash,
46 | token: {
47 | name: mintDetail.name || "APT",
48 | decimals: mintDetail.decimals || 8,
49 | },
50 | })
51 | } catch (error: any) {
52 | return JSON.stringify({
53 | status: "error",
54 | message: error.message,
55 | code: error.code || "UNKNOWN_ERROR",
56 | })
57 | }
58 | }
59 | }
60 |
--------------------------------------------------------------------------------
/src/langchain/echo/index.ts:
--------------------------------------------------------------------------------
1 | export * from "./stake"
2 | export * from "./unstake"
3 |
--------------------------------------------------------------------------------
/src/langchain/echo/stake.ts:
--------------------------------------------------------------------------------
1 | import { convertAmountFromHumanReadableToOnChain } from "@aptos-labs/ts-sdk"
2 | import { Tool } from "langchain/tools"
3 | import { type AgentRuntime, parseJson } from "../.."
4 |
5 | export class EchoStakeTokenTool extends Tool {
6 | name = "echo_stake_token"
7 | description = `this tool can be used to stake token in Echo
8 |
9 | Inputs ( input is a JSON string ):
10 | amount: number, eg 1 or 0.01 (required)
11 | `
12 |
13 | constructor(private agent: AgentRuntime) {
14 | super()
15 | }
16 |
17 | protected async _call(input: string): Promise {
18 | try {
19 | const parsedInput = parseJson(input)
20 |
21 | const stakeTransactionHash = await this.agent.stakeTokenWithEcho(
22 | convertAmountFromHumanReadableToOnChain(parsedInput.amount, 8)
23 | )
24 |
25 | return JSON.stringify({
26 | status: "success",
27 | stakeTransactionHash,
28 | token: {
29 | name: "eAPT",
30 | decimals: 8,
31 | },
32 | })
33 | } catch (error: any) {
34 | return JSON.stringify({
35 | status: "error",
36 | message: error.message,
37 | code: error.code || "UNKNOWN_ERROR",
38 | })
39 | }
40 | }
41 | }
42 |
--------------------------------------------------------------------------------
/src/langchain/echo/unstake.ts:
--------------------------------------------------------------------------------
1 | import { convertAmountFromHumanReadableToOnChain } from "@aptos-labs/ts-sdk"
2 | import { Tool } from "langchain/tools"
3 | import type { AgentRuntime } from "../../agent"
4 | import { parseJson } from "../../utils"
5 | export class EchoUnstakeTokenTool extends Tool {
6 | name = "echo_unstake_token"
7 | description = `this tool can be used to unstake token in Echo
8 |
9 | Inputs ( input is a JSON string ):
10 | amount: number, eg 1 or 0.01 (required)
11 | `
12 |
13 | constructor(private agent: AgentRuntime) {
14 | super()
15 | }
16 |
17 | protected async _call(input: string): Promise {
18 | try {
19 | const parsedInput = parseJson(input)
20 |
21 | const unstakeTransactionHash = await this.agent.unstakeTokenWithEcho(
22 | convertAmountFromHumanReadableToOnChain(parsedInput.amount, 8)
23 | )
24 |
25 | return JSON.stringify({
26 | status: "success",
27 | unstakeTransactionHash,
28 | token: {
29 | name: "APT",
30 | decimals: 8,
31 | },
32 | })
33 | } catch (error: any) {
34 | return JSON.stringify({
35 | status: "error",
36 | message: error.message,
37 | code: error.code || "UNKNOWN_ERROR",
38 | })
39 | }
40 | }
41 | }
42 |
--------------------------------------------------------------------------------
/src/langchain/joule/borrow-token.ts:
--------------------------------------------------------------------------------
1 | import { convertAmountFromHumanReadableToOnChain } from "@aptos-labs/ts-sdk"
2 | import { Tool } from "langchain/tools"
3 | import { type AgentRuntime, parseJson } from "../.."
4 |
5 | export class JouleBorrowTokenTool extends Tool {
6 | name = "joule_borrow_token"
7 | description = `this tool can be used to borrow APT, tokens or fungible asset from a position
8 |
9 | if you want to borrow APT, mint will be "0x1::aptos_coin::AptosCoin"
10 | if you want to borrow token other than APT, you need to provide the mint of that specific token
11 | if you want to borrow fungible asset, add "0x1::aptos_coin::AptosCoin" as mint and provide fungible asset address
12 |
13 | Inputs ( input is a JSON string ):
14 | amount: number, eg 1 or 0.01 (required)
15 | mint: string, eg "0xf22bede237a07e121b56d91a491eb7bcdfd1f5907926a9e58338f964a01b17fa::asset::USDT" (required)
16 | positionId: string, eg "0xf22bede237a07e121b56d91a491eb7bcdfd1f5907926a9e58338f964a01b17fa" (required)
17 | `
18 |
19 | constructor(private agent: AgentRuntime) {
20 | super()
21 | }
22 |
23 | protected async _call(input: string): Promise {
24 | try {
25 | const parsedInput = parseJson(input)
26 |
27 | const mintDetail = await this.agent.getTokenDetails(parsedInput.mint)
28 |
29 | const fungibleAsset = mintDetail.faAddress.toLowerCase() === parsedInput.mint.toLowerCase()
30 |
31 | const borrowTokenTransactionHash = await this.agent.borrowToken(
32 | convertAmountFromHumanReadableToOnChain(parsedInput.amount, mintDetail.decimals || 8),
33 | parsedInput.mint,
34 | parsedInput.positionId,
35 | fungibleAsset
36 | )
37 |
38 | return JSON.stringify({
39 | status: "success",
40 | borrowTokenTransactionHash,
41 | token: {
42 | name: mintDetail.name || "APT",
43 | decimals: mintDetail.decimals || 8,
44 | },
45 | })
46 | } catch (error: any) {
47 | return JSON.stringify({
48 | status: "error",
49 | message: error.message,
50 | code: error.code || "UNKNOWN_ERROR",
51 | })
52 | }
53 | }
54 | }
55 |
--------------------------------------------------------------------------------
/src/langchain/joule/claim-reward.ts:
--------------------------------------------------------------------------------
1 | import { Tool } from "langchain/tools"
2 | import type { AgentRuntime } from "../../agent"
3 | import { parseJson } from "../../utils"
4 |
5 | export class JouleClaimRewardTool extends Tool {
6 | name = "joule_claim_rewards"
7 | description = `this tool can be used to claim rewards from Joule pools
8 |
9 | Supports claiming both APT incentives and amAPT incentives.
10 |
11 | User can only claim rewards for coin -
12 | usdt - 0x357b0b74bc833e95a115ad22604854d6b0fca151cecd94111770e5d6ffc9dc2b
13 | usdc - 0xbae207659db88bea0cbead6da0ed00aac12edcdda169e591cd41c94180b46f3b
14 | weth - 0xf22bede237a07e121b56d91a491eb7bcdfd1f5907926a9e58338f964a01b17fa
15 | stapt - 0x111ae3e5bc816a5e63c2da97d0aa3886519e0cd5e4b046659fa35796bd11542a::stapt_token::StakedApt
16 |
17 | Inputs (input is a JSON string):
18 | rewardCoinType: string, eg "0x1::aptos_coin::AptosCoin" (required)
19 | `
20 |
21 | constructor(private agent: AgentRuntime) {
22 | super()
23 | }
24 |
25 | protected async _call(input: string): Promise {
26 | try {
27 | const parsedInput = parseJson(input)
28 |
29 | const claimRewardsTransactionHash = await this.agent.claimReward(parsedInput.rewardCoinType)
30 |
31 | const tokenDetails = await this.agent.getTokenDetails(parsedInput.rewardCoinType)
32 |
33 | return JSON.stringify({
34 | status: "success",
35 | claimRewardsTransactionHash,
36 | reward: {
37 | coinType: parsedInput.rewardCoinType,
38 | name: tokenDetails.name,
39 | type: parsedInput.rewardName,
40 | decimals: tokenDetails.decimals,
41 | },
42 | })
43 | } catch (error: any) {
44 | return JSON.stringify({
45 | status: "error",
46 | message: error.message,
47 | code: error.code || "UNKNOWN_ERROR",
48 | })
49 | }
50 | }
51 | }
52 |
--------------------------------------------------------------------------------
/src/langchain/joule/get-pool-details.ts:
--------------------------------------------------------------------------------
1 | import { Tool } from "langchain/tools"
2 | import { type AgentRuntime, parseJson } from "../.."
3 |
4 | export class JouleGetPoolDetails extends Tool {
5 | name = "joule_get_pool_details"
6 | description = `the tool can be used to get a token / fungible asset pool details
7 |
8 | Inputs ( input is a JSON string ):
9 | mint: string, eg "0xf22bede237a07e121b56d91a491eb7bcdfd1f5907926a9e58338f964a01b17fa::asset::USDT" (required)
10 |
11 | Example: '{"mint": "0xf22bede237a07e121b56d91a491eb7bcdfd1f5907926a9e58338f964a01b17fa::asset::USDT"}'
12 | `
13 |
14 | constructor(private agent: AgentRuntime) {
15 | super()
16 | }
17 |
18 | protected async _call(input: string): Promise {
19 | try {
20 | const parsedInput = parseJson(input)
21 |
22 | const pool = await this.agent.getPoolDetails(parsedInput.mint)
23 |
24 | return JSON.stringify({
25 | status: "success",
26 | pool,
27 | })
28 | } catch (error: any) {
29 | return JSON.stringify({
30 | status: "error",
31 | message: error.message,
32 | code: error.code || "UNKNOWN_ERROR",
33 | })
34 | }
35 | }
36 | }
37 |
--------------------------------------------------------------------------------
/src/langchain/joule/get-user-all-positions.ts:
--------------------------------------------------------------------------------
1 | import { AccountAddress } from "@aptos-labs/ts-sdk"
2 | import { Tool } from "langchain/tools"
3 | import { type AgentRuntime, parseJson } from "../.."
4 | import { tokensList } from "../../utils/get-pool-address-by-token-name"
5 |
6 | export class JouleGetUserAllPositions extends Tool {
7 | name = "joule_get_user_all_positions"
8 | description = `the tool can be used to get details about a user's all positions
9 |
10 | keep userAddress blank if user wants to get their own position or didn't provide any other user's address
11 |
12 | Inputs ( input is a JSON string ):
13 | userAddress: string, eg "0xf22bede237a07e121b56d91a491eb7bcdfd1f5907926a9e58338f964a01b17fa" (optional)
14 | `
15 |
16 | constructor(private agent: AgentRuntime) {
17 | super()
18 | }
19 |
20 | protected async _call(input: string): Promise {
21 | try {
22 | const parsedInput = parseJson(input)
23 |
24 | const userAddress = AccountAddress.from(parsedInput.userAddress) || this.agent.account.getAddress()
25 |
26 | const jouleUserAllPositions = await this.agent.getUserAllPositions(userAddress)
27 |
28 | return JSON.stringify({
29 | status: "success",
30 | jouleUserAllPositions,
31 | tokens: tokensList.map((token) => {
32 | return {
33 | name: token.name,
34 | decimals: token.decimals,
35 | tokenAddress: token.tokenAddress,
36 | }
37 | }),
38 | })
39 | } catch (error: any) {
40 | return JSON.stringify({
41 | status: "error",
42 | message: error.message,
43 | code: error.code || "UNKNOWN_ERROR",
44 | })
45 | }
46 | }
47 | }
48 |
--------------------------------------------------------------------------------
/src/langchain/joule/get-user-position.ts:
--------------------------------------------------------------------------------
1 | import { AccountAddress } from "@aptos-labs/ts-sdk"
2 | import { Tool } from "langchain/tools"
3 | import { type AgentRuntime, parseJson } from "../.."
4 |
5 | export class JouleGetUserPosition extends Tool {
6 | name = "joule_get_user_position"
7 | description = `the tool can be used to get details about a user's position
8 |
9 | keep userAddress blank if user wants to get their own position or didn't provide any other user's address
10 |
11 | ask user to provide positionId from the list of positions they have if they want to get details about a specific position.
12 | do not fill random positionId if the user didn't provide any positionId
13 |
14 | Inputs ( input is a JSON string ):
15 | userAddress: string, eg "0xf22bede237a07e121b56d91a491eb7bcdfd1f5907926a9e58338f964a01b17fa" (optional)
16 | positionId: string, eg "0xf22bede237a07e121b56d91a491eb7bcdfd1f5907926a9e58338f964a01b17fa" (required)
17 | `
18 |
19 | constructor(private agent: AgentRuntime) {
20 | super()
21 | }
22 |
23 | protected async _call(input: string): Promise {
24 | try {
25 | const parsedInput = parseJson(input)
26 |
27 | const userAddress = AccountAddress.from(parsedInput.userAddress) || this.agent.account.getAddress()
28 |
29 | const jouleUserPosition = await this.agent.getUserPosition(userAddress, parsedInput.positionId)
30 |
31 | return JSON.stringify({
32 | status: "success",
33 | jouleUserPosition,
34 | })
35 | } catch (error: any) {
36 | return JSON.stringify({
37 | status: "error",
38 | message: error.message,
39 | code: error.code || "UNKNOWN_ERROR",
40 | })
41 | }
42 | }
43 | }
44 |
--------------------------------------------------------------------------------
/src/langchain/joule/index.ts:
--------------------------------------------------------------------------------
1 | export * from "./lend-token"
2 | export * from "./borrow-token"
3 | export * from "./withdraw-token"
4 | export * from "./repay-token"
5 | export * from "./get-pool-details"
6 | export * from "./get-user-position"
7 | export * from "./get-user-all-positions"
8 | export * from "./claim-reward"
9 |
--------------------------------------------------------------------------------
/src/langchain/joule/lend-token.ts:
--------------------------------------------------------------------------------
1 | import { convertAmountFromHumanReadableToOnChain } from "@aptos-labs/ts-sdk"
2 | import { Tool } from "langchain/tools"
3 | import { type AgentRuntime, parseJson } from "../.."
4 |
5 | export class JouleLendTokenTool extends Tool {
6 | name = "joule_lend_token"
7 | description = `this tool can be used to lend APT, tokens or fungible asset to a position
8 |
9 | if you want to lend APT, mint will be "0x1::aptos_coin::AptosCoin"
10 | if you want to lend token other than APT, you need to provide the mint of that specific token
11 | if you want to lend fungible asset, add "0x1::aptos_coin::AptosCoin" as mint and provide fungible asset address
12 |
13 | if positionId is not provided, the positionId will be 1234 and newPosition should be true
14 |
15 | Inputs ( input is a JSON string ):
16 | amount: number, eg 1 or 0.01 (required)
17 | mint: string, eg "0xf22bede237a07e121b56d91a491eb7bcdfd1f5907926a9e58338f964a01b17fa::asset::USDT" (required)
18 | positionId: string, eg "0xf22bede237a07e121b56d91a491eb7bcdfd1f5907926a9e58338f964a01b17fa" (required)
19 | newPosition: boolean, (required)
20 | `
21 |
22 | constructor(private agent: AgentRuntime) {
23 | super()
24 | }
25 |
26 | protected async _call(input: string): Promise {
27 | try {
28 | const parsedInput = parseJson(input)
29 |
30 | const mintDetail = await this.agent.getTokenDetails(parsedInput.mint)
31 |
32 | const fungibleAsset = mintDetail.faAddress.toLowerCase() === parsedInput.mint.toLowerCase()
33 |
34 | const lendTokenTransactionHash = await this.agent.lendToken(
35 | convertAmountFromHumanReadableToOnChain(parsedInput.amount, mintDetail.decimals || 8),
36 | parsedInput.mint,
37 | parsedInput.positionId,
38 | parsedInput.newPosition,
39 | fungibleAsset
40 | )
41 |
42 | return JSON.stringify({
43 | status: "success",
44 | lendTokenTransactionHash,
45 | token: {
46 | name: mintDetail.name,
47 | decimals: mintDetail.decimals,
48 | },
49 | })
50 | } catch (error: any) {
51 | return JSON.stringify({
52 | status: "error",
53 | message: error.message,
54 | code: error.code || "UNKNOWN_ERROR",
55 | })
56 | }
57 | }
58 | }
59 |
--------------------------------------------------------------------------------
/src/langchain/joule/repay-token.ts:
--------------------------------------------------------------------------------
1 | import { convertAmountFromHumanReadableToOnChain } from "@aptos-labs/ts-sdk"
2 | import { Tool } from "langchain/tools"
3 | import { type AgentRuntime, parseJson } from "../.."
4 |
5 | export class JouleRepayTokenTool extends Tool {
6 | name = "joule_repay_token"
7 | description = `this tool can be used to repay APT, tokens or fungible asset from a position
8 |
9 | if you want to repay APT, mint will be "0x1::aptos_coin::AptosCoin"
10 | if you want to repay token other than APT, you need to provide the mint of that specific token
11 | if you want to repay fungible asset, add "0x1::aptos_coin::AptosCoin" as mint and provide fungible asset address
12 |
13 | Inputs ( input is a JSON string ):
14 | amount: number, eg 1 or 0.01 (required)
15 | mint: string, eg "0xf22bede237a07e121b56d91a491eb7bcdfd1f5907926a9e58338f964a01b17fa::asset::USDT" (required)
16 | positionId: string, eg "0xf22bede237a07e121b56d91a491eb7bcdfd1f5907926a9e58338f964a01b17fa" (required)
17 | fungibleAssetAddress: string, eg "0xf22bede237a07e121b56d91a491eb7bcdfd1f5907926a9e58338f964a01b17fa" (optional)
18 | `
19 |
20 | constructor(private agent: AgentRuntime) {
21 | super()
22 | }
23 |
24 | protected async _call(input: string): Promise {
25 | try {
26 | const parsedInput = parseJson(input)
27 |
28 | const mintDetail = await this.agent.getTokenDetails(parsedInput.mint)
29 |
30 | const repayTokenTransactionHash = await this.agent.repayToken(
31 | convertAmountFromHumanReadableToOnChain(parsedInput.amount, mintDetail.decimals || 8),
32 | parsedInput.mint,
33 | parsedInput.positionId,
34 | parsedInput.fungibleAssetAddress
35 | )
36 |
37 | return JSON.stringify({
38 | status: "success",
39 | repayTokenTransactionHash,
40 | token: {
41 | name: mintDetail.name,
42 | decimals: mintDetail.decimals,
43 | },
44 | })
45 | } catch (error: any) {
46 | return JSON.stringify({
47 | status: "error",
48 | message: error.message,
49 | code: error.code || "UNKNOWN_ERROR",
50 | })
51 | }
52 | }
53 | }
54 |
--------------------------------------------------------------------------------
/src/langchain/joule/withdraw-token.ts:
--------------------------------------------------------------------------------
1 | import { convertAmountFromHumanReadableToOnChain } from "@aptos-labs/ts-sdk"
2 | import { Tool } from "langchain/tools"
3 | import { type AgentRuntime, parseJson } from "../.."
4 |
5 | export class JouleWithdrawTokenTool extends Tool {
6 | name = "joule_withdraw_token"
7 | description = `this tool can be used to withdraw APT, tokens or fungible asset from a position
8 |
9 | if you want to withdraw APT, add "0x1::aptos_coin::AptosCoin" as mint
10 | if you want to withdraw token other than APT, you need to provide the mint of that specific token
11 | if you want to withdraw fungible asset, add "0x1::aptos_coin::AptosCoin" as mint and provide fungible asset address
12 |
13 | Inputs ( input is a JSON string ):
14 |
15 | amount: number, eg 1 or 0.01 (required)
16 | mint: string, eg "0xf22bede237a07e121b56d91a491eb7bcdfd1f5907926a9e58338f964a01b17fa::asset::USDT" (required)
17 | positionId: string, eg "0xf22bede237a07e121b56d91a491eb7bcdfd1f5907926a9e58338f964a01b17fa" (required)
18 | `
19 |
20 | constructor(private agent: AgentRuntime) {
21 | super()
22 | }
23 |
24 | protected async _call(input: string): Promise {
25 | try {
26 | const parsedInput = parseJson(input)
27 |
28 | const mintDetail = await this.agent.getTokenDetails(parsedInput.mint)
29 |
30 | const fungibleAsset = mintDetail.faAddress.toLowerCase() === parsedInput.mint.toLowerCase()
31 |
32 | const withdrawTokenTransactionHash = await this.agent.withdrawToken(
33 | convertAmountFromHumanReadableToOnChain(parsedInput.amount, mintDetail.decimals || 8),
34 | parsedInput.mint,
35 | parsedInput.positionId,
36 | fungibleAsset
37 | )
38 |
39 | return JSON.stringify({
40 | status: "success",
41 | withdrawTokenTransactionHash,
42 | token: {
43 | name: mintDetail.name,
44 | decimals: mintDetail.decimals,
45 | },
46 | })
47 | } catch (error: any) {
48 | return JSON.stringify({
49 | status: "error",
50 | message: error.message,
51 | code: error.code || "UNKNOWN_ERROR",
52 | })
53 | }
54 | }
55 | }
56 |
--------------------------------------------------------------------------------
/src/langchain/liquidswap/index.ts:
--------------------------------------------------------------------------------
1 | export * from "./swap"
2 | export * from "./create-pool"
3 | export * from "./add-liquidity"
4 | export * from "./remove-liquidity"
5 |
--------------------------------------------------------------------------------
/src/langchain/merkletrade/close-position.ts:
--------------------------------------------------------------------------------
1 | import { Tool } from "langchain/tools"
2 | import type { AgentRuntime } from "../../agent"
3 | import { parseJson } from "../../utils"
4 |
5 | export class MerkleTradeClosePositionTool extends Tool {
6 | name = "merkle_trade_close_position"
7 | description = `this tool can be used to close position on MerkleTrade
8 |
9 | if you want to close a position, pair will be "BTC_USD" and isLong will be true
10 |
11 | Inputs ( input is a JSON string ):
12 | pair: string, eg "BTC_USD" (required)
13 | isLong: boolean, eg true (required)
14 | `
15 |
16 | constructor(private agent: AgentRuntime) {
17 | super()
18 | }
19 |
20 | protected async _call(input: string): Promise {
21 | try {
22 | const parsedInput = parseJson(input)
23 |
24 | const txhash = await this.agent.closePositionWithMerkleTrade(parsedInput.pair, parsedInput.isLong)
25 |
26 | return JSON.stringify({
27 | status: "success",
28 | closePositionTransactionHash: txhash,
29 | position: {
30 | pair: parsedInput.pair,
31 | isLong: parsedInput.isLong,
32 | sizeDelta: parsedInput.sizeDelta,
33 | collateralDelta: parsedInput.collateralDelta,
34 | price: parsedInput.price,
35 | },
36 | })
37 | } catch (error: any) {
38 | return JSON.stringify({
39 | status: "error",
40 | message: error.message,
41 | code: error.code || "UNKNOWN_ERROR",
42 | })
43 | }
44 | }
45 | }
46 |
--------------------------------------------------------------------------------
/src/langchain/merkletrade/get-position.ts:
--------------------------------------------------------------------------------
1 | import { Tool } from "langchain/tools"
2 | import type { AgentRuntime } from "../../agent"
3 |
4 | export class MerkleTradeGetPositionTool extends Tool {
5 | name = "merkle_trade_get_position"
6 | description = `this tool can be used to get position on MerkleTrade
7 | No inputs required, this tool will return the current position of the agent
8 | `
9 |
10 | constructor(private agent: AgentRuntime) {
11 | super()
12 | }
13 |
14 | protected async _call(): Promise {
15 | try {
16 | const position = await this.agent.getPositionsWithMerkleTrade()
17 |
18 | return JSON.stringify({
19 | status: "success",
20 | position: position,
21 | })
22 | } catch (error: any) {
23 | return JSON.stringify({
24 | status: "error",
25 | message: error.message,
26 | code: error.code || "UNKNOWN_ERROR",
27 | })
28 | }
29 | }
30 | }
31 |
--------------------------------------------------------------------------------
/src/langchain/merkletrade/index.ts:
--------------------------------------------------------------------------------
1 | export * from "./get-position"
2 | export * from "./place-limit-order"
3 | export * from "./place-market-order"
4 | export * from "./close-position"
5 |
--------------------------------------------------------------------------------
/src/langchain/merkletrade/place-limit-order.ts:
--------------------------------------------------------------------------------
1 | import { Tool } from "langchain/tools"
2 | import type { AgentRuntime } from "../../agent"
3 | import { parseJson } from "../../utils"
4 |
5 | export class MerkleTradePlaceLimitOrderTool extends Tool {
6 | name = "merkle_trade_place_limit_order"
7 | description = `this tool can be used to place limit order on MerkleTrade
8 |
9 | if you want to place a limit order to buy BTC at 100000, pair will be "BTC_USD" and isLong will be true, price will be 100000
10 |
11 | Inputs ( input is a JSON string ):
12 | pair: string, eg "BTC_USD" (required)
13 | isLong: boolean, eg true (required)
14 | sizeDelta: number, eg 10 (required)
15 | collateralDelta: number, eg 10 (required)
16 | price: number, eg 10000 (required)
17 | `
18 |
19 | constructor(private agent: AgentRuntime) {
20 | super()
21 | }
22 |
23 | protected async _call(input: string): Promise {
24 | try {
25 | const parsedInput = parseJson(input)
26 |
27 | const txhash = await this.agent.placeLimitOrderWithMerkleTrade(
28 | parsedInput.pair,
29 | parsedInput.isLong,
30 | parsedInput.sizeDelta,
31 | parsedInput.collateralDelta,
32 | parsedInput.price
33 | )
34 |
35 | return JSON.stringify({
36 | status: "success",
37 | limitOrderTransactionHash: txhash,
38 | position: {
39 | pair: parsedInput.pair,
40 | isLong: parsedInput.isLong,
41 | sizeDelta: parsedInput.sizeDelta,
42 | collateralDelta: parsedInput.collateralDelta,
43 | price: parsedInput.price,
44 | },
45 | })
46 | } catch (error: any) {
47 | return JSON.stringify({
48 | status: "error",
49 | message: error.message,
50 | code: error.code || "UNKNOWN_ERROR",
51 | })
52 | }
53 | }
54 | }
55 |
--------------------------------------------------------------------------------
/src/langchain/merkletrade/place-market-order.ts:
--------------------------------------------------------------------------------
1 | import { Tool } from "langchain/tools"
2 | import type { AgentRuntime } from "../../agent"
3 | import { parseJson } from "../../utils"
4 |
5 | export class MerkleTradePlaceMarketOrderTool extends Tool {
6 | name = "merkle_trade_place_market_order"
7 | description = `this tool can be used to place market order on MerkleTrade
8 |
9 | if you want to place a market order to buy BTC, pair will be "BTC_USD" and isLong will be true,
10 | if you want to place a market order to sell BTC, pair will be "BTC_USD" and isLong will be false
11 | if you want to place a market order to size 100, collateral 10, sizeDelta will be 100, collateralDelta will be 10
12 |
13 | Inputs ( input is a JSON string ):
14 | pair: string, eg "BTC_USD" (required)
15 | isLong: boolean, eg true (required)
16 | sizeDelta: number, eg 10 (required)
17 | collateralDelta: number, eg 10 (required)
18 | `
19 |
20 | constructor(private agent: AgentRuntime) {
21 | super()
22 | }
23 |
24 | protected async _call(input: string): Promise {
25 | try {
26 | const parsedInput = parseJson(input)
27 |
28 | const txhash = await this.agent.placeMarketOrderWithMerkleTrade(
29 | parsedInput.pair,
30 | parsedInput.isLong,
31 | parsedInput.sizeDelta,
32 | parsedInput.collateralDelta
33 | )
34 |
35 | return JSON.stringify({
36 | status: "success",
37 | marketOrderTransactionHash: txhash,
38 | position: {
39 | pair: parsedInput.pair,
40 | isLong: parsedInput.isLong,
41 | sizeDelta: parsedInput.sizeDelta,
42 | collateralDelta: parsedInput.collateralDelta,
43 | },
44 | })
45 | } catch (error: any) {
46 | return JSON.stringify({
47 | status: "error",
48 | message: error.message,
49 | code: error.code || "UNKNOWN_ERROR",
50 | })
51 | }
52 | }
53 | }
54 |
--------------------------------------------------------------------------------
/src/langchain/openai/create-image.ts:
--------------------------------------------------------------------------------
1 | import { Tool } from "langchain/tools"
2 | import { type AgentRuntime, parseJson } from "../.."
3 |
4 | export class OpenAICreateImageTool extends Tool {
5 | name = "openai_create_image"
6 | description = `
7 | Generate an image using OpenAI's DALL-E
8 |
9 | Inputs ( input is a JSON string ):
10 | prompt: string, Text description of the image to generate (required)
11 | size: string, Image size ('256x256', '512x512', or '1024x1024') (default: '1024x1024')
12 | n: number, Number of images to generate (default: 1)`
13 |
14 | constructor(private agent: AgentRuntime) {
15 | super()
16 | }
17 |
18 | protected async _call(input: string): Promise {
19 | try {
20 | const parsedInput = parseJson(input)
21 |
22 | const response = await this.agent.createImageWithOpenAI(parsedInput.prompt, parsedInput.size, parsedInput.n)
23 |
24 | return JSON.stringify({
25 | status: "success",
26 | response,
27 | })
28 | } catch (error: any) {
29 | return JSON.stringify({
30 | status: "error",
31 | message: error.message,
32 | code: error.code || "UNKNOWN_ERROR",
33 | })
34 | }
35 | }
36 | }
37 |
--------------------------------------------------------------------------------
/src/langchain/openai/index.ts:
--------------------------------------------------------------------------------
1 | export * from "./create-image"
2 |
--------------------------------------------------------------------------------
/src/langchain/panora/index.ts:
--------------------------------------------------------------------------------
1 | export * from "./swap"
2 |
--------------------------------------------------------------------------------
/src/langchain/panora/swap.ts:
--------------------------------------------------------------------------------
1 | import { Tool } from "langchain/tools"
2 | import { type AgentRuntime, parseJson } from "../.."
3 |
4 | export class PanoraSwapTool extends Tool {
5 | name = "panora_aggregator_swap"
6 | description = `this tool can be used to swap tokens in panora - liquidity aggregator on aptos
7 |
8 | if you want to swap APT and one of the token, fromToken will be "0x1::aptos_coin::AptosCoin"
9 |
10 | Inputs ( input is a JSON string ):
11 | fromToken: string, eg "0xf22bede237a07e121b56d91a491eb7bcdfd1f5907926a9e58338f964a01b17fa::asset::USDT" (required)
12 | toToken: string, eg "0xf22bede237a07e121b56d91a491eb7bcdfd1f5907926a9e58338f964a01b17fa::asset::USDT" (required)
13 | swapAmount: number, eg 1 or 0.01 (required)
14 | toWalletAddress: string, eg "0xf22bede237a07e121b56d91a491eb7bcdfd1f5907926a9e58338f964a01b17fa" (optional)
15 | `
16 |
17 | constructor(private agent: AgentRuntime) {
18 | super()
19 | }
20 |
21 | protected async _call(input: string): Promise {
22 | try {
23 | const parsedInput = parseJson(input)
24 |
25 | const mintXDetail = await this.agent.getTokenDetails(parsedInput.fromToken)
26 |
27 | const mintYDetail = await this.agent.getTokenDetails(parsedInput.toToken)
28 |
29 | const swapTransactionHash = await this.agent.swapWithPanora(
30 | parsedInput.fromToken,
31 | parsedInput.toToken,
32 | parsedInput.swapAmount,
33 | parsedInput.toWalletAddress
34 | )
35 |
36 | return JSON.stringify({
37 | status: "success",
38 | swapTransactionHash,
39 | token: [
40 | {
41 | mintX: mintXDetail.name,
42 | decimals: mintXDetail.decimals,
43 | },
44 | {
45 | mintY: mintYDetail.name,
46 | decimals: mintYDetail.decimals,
47 | },
48 | ],
49 | })
50 | } catch (error: any) {
51 | return JSON.stringify({
52 | status: "error",
53 | message: error.message,
54 | code: error.code || "UNKNOWN_ERROR",
55 | })
56 | }
57 | }
58 | }
59 |
--------------------------------------------------------------------------------
/src/langchain/thala/add-liquidity.ts:
--------------------------------------------------------------------------------
1 | import { convertAmountFromHumanReadableToOnChain } from "@aptos-labs/ts-sdk"
2 | import { Tool } from "langchain/tools"
3 | import type { AgentRuntime } from "../../agent"
4 | import { parseJson } from "../../utils"
5 | export class ThalaAddLiquidityTool extends Tool {
6 | name = "thala_add_liquidity"
7 | description = `this tool can be used to add liquidity to a Thala pool
8 |
9 | If you want to add APT, use "0x1::aptos_coin::AptosCoin" as the coin type
10 |
11 | Inputs ( input is a JSON string ) (IMPORTANT):
12 | mintX: string, eg "0xf22bede237a07e121b56d91a491eb7bcdfd1f5907926a9e58338f964a01b17fa::asset::USDT" (required)
13 | mintY: string, eg "0xf22bede237a07e121b56d91a491eb7bcdfd1f5907926a9e58338f964a01b17fa::asset::USDT" (required)
14 | mintXAmount: number, eg 1 or 0.01 (required)
15 | mintYAmount: number, eg 1 or 0.01 (required)
16 | `
17 |
18 | constructor(private agent: AgentRuntime) {
19 | super()
20 | }
21 |
22 | protected async _call(input: string): Promise {
23 | try {
24 | const parsedInput = parseJson(input)
25 |
26 | const mintXDetail = await this.agent.getTokenDetails(parsedInput.mintX)
27 | const mintYDetail = await this.agent.getTokenDetails(parsedInput.mintY)
28 |
29 | const addLiquidityTransactionHash = await this.agent.addLiquidityWithThala(
30 | parsedInput.mintX,
31 | parsedInput.mintY,
32 | convertAmountFromHumanReadableToOnChain(parsedInput.mintXAmount, mintXDetail.decimals),
33 | convertAmountFromHumanReadableToOnChain(parsedInput.mintYAmount, mintYDetail.decimals)
34 | )
35 |
36 | return JSON.stringify({
37 | status: "success",
38 | addLiquidityTransactionHash,
39 | tokens: [
40 | {
41 | mintX: mintXDetail.name,
42 | decimals: mintXDetail.decimals,
43 | },
44 | {
45 | mintY: mintYDetail.name,
46 | decimals: mintYDetail.decimals,
47 | },
48 | ],
49 | })
50 | } catch (error: any) {
51 | return JSON.stringify({
52 | status: "error",
53 | message: error.message,
54 | code: error.code || "UNKNOWN_ERROR",
55 | })
56 | }
57 | }
58 | }
59 |
--------------------------------------------------------------------------------
/src/langchain/thala/create-pool.ts:
--------------------------------------------------------------------------------
1 | import { convertAmountFromHumanReadableToOnChain } from "@aptos-labs/ts-sdk"
2 | import { Tool } from "langchain/tools"
3 | import type { AgentRuntime } from "../../agent"
4 | import { parseJson } from "../../utils"
5 |
6 | export class ThalaCreatePoolTool extends Tool {
7 | name = "thala_create_pool"
8 | description = `this tool can be used to create a new pool in Thala
9 |
10 | If you want to create a pool with APT, use "0x1::aptos_coin::AptosCoin" as the coin type
11 | For other coins use their respective addresses
12 |
13 | Fee tiers:
14 | - 1 for 0.01%
15 | - 5 for 0.05%
16 | - 30 for 0.3%
17 | - 100 for 1%
18 |
19 | Amplification factors: 10, 100, or 1000
20 |
21 | If the user did not provide any input for fee tiers or amplification, do not fill any fee tiers or amplification.
22 | Ask the user to provide fee tiers and amplification.
23 |
24 | Inputs (input is a JSON string):
25 | mintX: string, eg "0x1::aptos_coin::AptosCoin" (required)
26 | mintY: string, eg "0xf22bede237a07e121b56d91a491eb7bcdfd1f5907926a9e58338f964a01b17fa::asset::USDT" (required)
27 | amountX: number, eg 1 or 0.01 (required)
28 | amountY: number, eg 1 or 0.01 (required)
29 | feeTier: number, eg 1, 5, 30, or 100 (required)
30 | amplificationFactor: number, eg 10, 100, or 1000 (required)
31 | `
32 |
33 | constructor(private agent: AgentRuntime) {
34 | super()
35 | }
36 |
37 | protected async _call(input: string): Promise {
38 | try {
39 | const parsedInput = parseJson(input)
40 |
41 | const mintXDetail = await this.agent.getTokenDetails(parsedInput.mintX)
42 | const mintYDetail = await this.agent.getTokenDetails(parsedInput.mintY)
43 |
44 | const createPoolTransactionHash = await this.agent.createPoolWithThala(
45 | parsedInput.mintX,
46 | parsedInput.mintY,
47 | convertAmountFromHumanReadableToOnChain(parsedInput.amountX, mintXDetail.decimals),
48 | convertAmountFromHumanReadableToOnChain(parsedInput.amountY, mintYDetail.decimals),
49 | parsedInput.feeTier,
50 | parsedInput.amplificationFactor
51 | )
52 |
53 | return JSON.stringify({
54 | status: "success",
55 | createPoolTransactionHash,
56 | tokens: [
57 | {
58 | mintX: mintXDetail.name,
59 | decimals: mintXDetail.decimals,
60 | },
61 | {
62 | mintY: mintYDetail.name,
63 | decimals: mintYDetail.decimals,
64 | },
65 | ],
66 | })
67 | } catch (error: any) {
68 | return JSON.stringify({
69 | status: "error",
70 | message: error.message,
71 | code: error.code || "UNKNOWN_ERROR",
72 | })
73 | }
74 | }
75 | }
76 |
--------------------------------------------------------------------------------
/src/langchain/thala/index.ts:
--------------------------------------------------------------------------------
1 | export * from "./stake"
2 | export * from "./unstake"
3 | export * from "./mint-mod"
4 | export * from "./redeem-mod"
5 | export * from "./add-liquidity"
6 | export * from "./remove-liquidity"
7 |
--------------------------------------------------------------------------------
/src/langchain/thala/mint-mod.ts:
--------------------------------------------------------------------------------
1 | import { convertAmountFromHumanReadableToOnChain } from "@aptos-labs/ts-sdk"
2 | import { Tool } from "langchain/tools"
3 | import type { AgentRuntime } from "../../agent"
4 | import { parseJson } from "../../utils"
5 |
6 | export class ThalaMintMODTool extends Tool {
7 | name = "thala_mint_mod"
8 | description = `this tool can be used to mint move dollar (MOD) in Thala
9 |
10 | Only supported coin types: lzUSDC, whUSDC, or USDt
11 |
12 | if the user coin is not in the list , default to lzUSDC
13 |
14 | mintType for lzUSDC - 0xf22bede237a07e121b56d91a491eb7bcdfd1f5907926a9e58338f964a01b17fa::asset::USDC
15 | mintType for wUSDC - 0x5e156f1207d0ebfa19a9eeff00d62a282278fb8719f4fab3a586a0a2c0fffbea::coin::T
16 | mintType for USDt - 0x357b0b74bc833e95a115ad22604854d6b0fca151cecd94111770e5d6ffc9dc2b
17 |
18 | Inputs ( input is a JSON string ):
19 | mintType: eg "0xf22bede237a07e121b56d91a491eb7bcdfd1f5907926a9e58338f964a01b17fa::asset::USDT" (required)
20 | amount: number, eg 1 or 0.01 (required)
21 | `
22 |
23 | constructor(private agent: AgentRuntime) {
24 | super()
25 | }
26 |
27 | protected async _call(input: string): Promise {
28 | try {
29 | const parsedInput = parseJson(input)
30 |
31 | const mintMODTransactionHash = await this.agent.mintMODWithThala(
32 | parsedInput.mintType,
33 | convertAmountFromHumanReadableToOnChain(parsedInput.amount, 6)
34 | )
35 |
36 | return JSON.stringify({
37 | status: "success",
38 | mintMODTransactionHash,
39 | token: {
40 | name: "MOD",
41 | decimals: 8,
42 | },
43 | })
44 | } catch (error: any) {
45 | return JSON.stringify({
46 | status: "error",
47 | message: error.message,
48 | code: error.code || "UNKNOWN_ERROR",
49 | })
50 | }
51 | }
52 | }
53 |
--------------------------------------------------------------------------------
/src/langchain/thala/redeem-mod.ts:
--------------------------------------------------------------------------------
1 | import { convertAmountFromHumanReadableToOnChain } from "@aptos-labs/ts-sdk"
2 | import { Tool } from "langchain/tools"
3 | import type { AgentRuntime } from "../../agent"
4 | import { parseJson } from "../../utils"
5 | export class ThalaRedeemMODTool extends Tool {
6 | name = "thala_redeem_mod"
7 | description = `this tool can be used to redeem move dollar (MOD) in Thala
8 |
9 | Only supported coin types: lzUSDC, whUSDC, or USDt
10 |
11 | if the user coin is not in the list , default to lzUSDC
12 |
13 | mintType for lzUSDC - 0xf22bede237a07e121b56d91a491eb7bcdfd1f5907926a9e58338f964a01b17fa::asset::USDC
14 | mintType for wUSDC - 0x5e156f1207d0ebfa19a9eeff00d62a282278fb8719f4fab3a586a0a2c0fffbea::coin::T
15 | mintType for USDt - 0x357b0b74bc833e95a115ad22604854d6b0fca151cecd94111770e5d6ffc9dc2b
16 |
17 |
18 | Inputs ( input is a JSON string ):
19 | mintType: string, eg "0xf22bede237a07e121b56d91a491eb7bcdfd1f5907926a9e58338f964a01b17fa::asset::USDT" (required)
20 | amount: number, eg 1 or 0.01 (required)
21 | `
22 |
23 | constructor(private agent: AgentRuntime) {
24 | super()
25 | }
26 |
27 | protected async _call(input: string): Promise {
28 | try {
29 | const parsedInput = parseJson(input)
30 |
31 | const tokenDetails = await this.agent.getTokenDetails(parsedInput.mintType)
32 |
33 | const redeemMODTransactionHash = await this.agent.redeemMODWithThala(
34 | parsedInput.mintType,
35 | convertAmountFromHumanReadableToOnChain(parsedInput.amount, 6)
36 | )
37 |
38 | return JSON.stringify({
39 | status: "success",
40 | redeemMODTransactionHash,
41 | token: {
42 | name: tokenDetails.name,
43 | decimals: tokenDetails.decimals,
44 | },
45 | })
46 | } catch (error: any) {
47 | return JSON.stringify({
48 | status: "error",
49 | message: error.message,
50 | code: error.code || "UNKNOWN_ERROR",
51 | })
52 | }
53 | }
54 | }
55 |
--------------------------------------------------------------------------------
/src/langchain/thala/remove-liquidity.ts:
--------------------------------------------------------------------------------
1 | import { convertAmountFromHumanReadableToOnChain } from "@aptos-labs/ts-sdk"
2 | import { Tool } from "langchain/tools"
3 | import type { AgentRuntime } from "../../agent"
4 | import { parseJson } from "../../utils"
5 |
6 | export class ThalaRemoveLiquidityTool extends Tool {
7 | name = "thala_remove_liquidity"
8 | description = `this tool can be used to remove liquidity from a Thala pool
9 |
10 | If one of your coins is APT, use "0x1::aptos_coin::AptosCoin" as the coin type
11 |
12 | Inputs ( input is a JSON string ):
13 | mintX: string, eg "0xf22bede237a07e121b56d91a491eb7bcdfd1f5907926a9e58338f964a01b17fa::asset::USDT" (required)
14 | mintY: string, eg "0xf22bede237a07e121b56d91a491eb7bcdfd1f5907926a9e58338f964a01b17fa::asset::USDT" (required)
15 | lpAmount: number, eg 1 or 0.01 (required)
16 | `
17 |
18 | constructor(private agent: AgentRuntime) {
19 | super()
20 | }
21 |
22 | protected async _call(input: string): Promise {
23 | try {
24 | const parsedInput = parseJson(input)
25 |
26 | const mintXDetail = await this.agent.getTokenDetails(parsedInput.mintX)
27 |
28 | const mintYDetail = await this.agent.getTokenDetails(parsedInput.mintY)
29 |
30 | const removeLiquidityTransactionHash = await this.agent.removeLiquidityWithThala(
31 | parsedInput.mintX,
32 | parsedInput.mintY,
33 | convertAmountFromHumanReadableToOnChain(parsedInput.lpAmount, 6)
34 | )
35 |
36 | return JSON.stringify({
37 | status: "success",
38 | removeLiquidityTransactionHash,
39 | tokens: [
40 | {
41 | mintX: mintXDetail.name,
42 | decimals: 6,
43 | },
44 | {
45 | mintY: mintYDetail.name,
46 | decimals: 6,
47 | },
48 | ],
49 | })
50 | } catch (error: any) {
51 | return JSON.stringify({
52 | status: "error",
53 | message: error.message,
54 | code: error.code || "UNKNOWN_ERROR",
55 | })
56 | }
57 | }
58 | }
59 |
--------------------------------------------------------------------------------
/src/langchain/thala/stake.ts:
--------------------------------------------------------------------------------
1 | import { convertAmountFromHumanReadableToOnChain } from "@aptos-labs/ts-sdk"
2 | import { Tool } from "langchain/tools"
3 | import { type AgentRuntime, parseJson } from "../.."
4 |
5 | export class ThalaStakeTokenTool extends Tool {
6 | name = "thala_stake_token"
7 | description = `this tool can be used to stake thAPT in Thala
8 |
9 | Inputs ( input is a JSON string ):
10 | amount: number, eg 1 or 0.01 (required)
11 | `
12 |
13 | constructor(private agent: AgentRuntime) {
14 | super()
15 | }
16 |
17 | protected async _call(input: string): Promise {
18 | try {
19 | const parsedInput = parseJson(input)
20 |
21 | const stakeTransactionHash = await this.agent.stakeTokensWithThala(
22 | convertAmountFromHumanReadableToOnChain(parsedInput.amount, 8)
23 | )
24 |
25 | return JSON.stringify({
26 | status: "success",
27 | stakeTransactionHash,
28 | token: {
29 | name: "thAPT",
30 | decimals: 8,
31 | },
32 | })
33 | } catch (error: any) {
34 | return JSON.stringify({
35 | status: "error",
36 | message: error.message,
37 | code: error.code || "UNKNOWN_ERROR",
38 | })
39 | }
40 | }
41 | }
42 |
--------------------------------------------------------------------------------
/src/langchain/thala/unstake.ts:
--------------------------------------------------------------------------------
1 | import { convertAmountFromHumanReadableToOnChain } from "@aptos-labs/ts-sdk"
2 | import { Tool } from "langchain/tools"
3 | import type { AgentRuntime } from "../../agent"
4 | import { parseJson } from "../../utils"
5 | export class ThalaUnstakeTokenTool extends Tool {
6 | name = "thala_unstake_token"
7 | description = `this tool can be used to unstake thAPT in Thala
8 |
9 | Inputs ( input is a JSON string ):
10 | amount: number, eg 1 or 0.01 (required)
11 | `
12 |
13 | constructor(private agent: AgentRuntime) {
14 | super()
15 | }
16 |
17 | protected async _call(input: string): Promise {
18 | try {
19 | const parsedInput = parseJson(input)
20 |
21 | const unstakeTransactionHash = await this.agent.unstakeTokensWithThala(
22 | convertAmountFromHumanReadableToOnChain(parsedInput.amount, 8)
23 | )
24 |
25 | return JSON.stringify({
26 | status: "success",
27 | unstakeTransactionHash,
28 | token: {
29 | name: "APT",
30 | decimals: 8,
31 | },
32 | })
33 | } catch (error: any) {
34 | return JSON.stringify({
35 | status: "error",
36 | message: error.message,
37 | code: error.code || "UNKNOWN_ERROR",
38 | })
39 | }
40 | }
41 | }
42 |
--------------------------------------------------------------------------------
/src/signers/base-signer.ts:
--------------------------------------------------------------------------------
1 | // src/signers/base-signer.ts
2 |
3 | import type { Account, AccountAddress, AnyRawTransaction, Aptos } from "@aptos-labs/ts-sdk"
4 | import type {
5 | AptosSignMessageInput,
6 | AptosSignMessageOutput,
7 | InputTransactionData,
8 | } from "@aptos-labs/wallet-adapter-react"
9 | import type { SignedTransactionResponse } from "../types"
10 |
11 | export abstract class BaseSigner {
12 | protected constructor(
13 | protected readonly account: Account,
14 | protected readonly aptos: Aptos
15 | ) {}
16 |
17 | public getAddress(): AccountAddress {
18 | return this.account.accountAddress
19 | }
20 |
21 | // abstract getAccount(): Account;
22 | abstract signTransaction(transaction: AnyRawTransaction): Promise
23 | abstract sendTransaction(transaction: InputTransactionData | AnyRawTransaction): Promise
24 | abstract signMessage(message: AptosSignMessageInput | string): Promise
25 | }
26 |
--------------------------------------------------------------------------------
/src/signers/index.ts:
--------------------------------------------------------------------------------
1 | export * from "./base-signer"
2 | export * from "./local-signer"
3 | export * from "./wallet-signer"
4 |
--------------------------------------------------------------------------------
/src/signers/local-signer.ts:
--------------------------------------------------------------------------------
1 | // src/signers/local-signer.ts
2 |
3 | import {
4 | type Account,
5 | type AccountAddress,
6 | type AnyRawTransaction,
7 | Aptos,
8 | AptosConfig,
9 | Network,
10 | } from "@aptos-labs/ts-sdk"
11 | import { BaseSigner } from "./base-signer"
12 |
13 | export class LocalSigner extends BaseSigner {
14 | constructor(account: Account, network: Network = Network.DEVNET) {
15 | const config = new AptosConfig({ network })
16 | const aptos = new Aptos(config)
17 | super(account, aptos)
18 | }
19 |
20 | public getAddress(): AccountAddress {
21 | return this.account.accountAddress
22 | }
23 |
24 | async signTransaction(transaction: AnyRawTransaction) {
25 | const senderAuthenticator = this.aptos.transaction.sign({
26 | signer: this.account,
27 | transaction,
28 | })
29 |
30 | return {
31 | senderAuthenticator,
32 | }
33 | }
34 |
35 | async sendTransaction(transaction: AnyRawTransaction) {
36 | const signedTx = await this.signTransaction(transaction)
37 |
38 | const submittedTx = await this.aptos.transaction.submit.simple({
39 | transaction,
40 | senderAuthenticator: signedTx.senderAuthenticator,
41 | })
42 |
43 | const result = await this.aptos.waitForTransaction({
44 | transactionHash: submittedTx.hash,
45 | })
46 |
47 | return result.hash
48 | }
49 |
50 | async signMessage(message: any): Promise {
51 | const signedMessage = this.account.signWithAuthenticator(message)
52 |
53 | return signedMessage.toString()
54 | }
55 | }
56 |
--------------------------------------------------------------------------------
/src/signers/wallet-signer.ts:
--------------------------------------------------------------------------------
1 | import { type Account, AccountAddress, type AnyRawTransaction, Aptos, AptosConfig, Network } from "@aptos-labs/ts-sdk"
2 | import type { AptosSignMessageInput, InputTransactionData, WalletContextState } from "@aptos-labs/wallet-adapter-react"
3 | import type { SignedTransactionResponse } from "../types"
4 | import { BaseSigner } from "./base-signer"
5 |
6 | export class WalletSigner extends BaseSigner {
7 | constructor(
8 | account: Account,
9 | private readonly wallet: WalletContextState,
10 | network: Network = Network.DEVNET
11 | ) {
12 | const config = new AptosConfig({ network })
13 | const aptos = new Aptos(config)
14 | super(account, aptos)
15 | }
16 |
17 | public override getAddress(): AccountAddress {
18 | const walletAddress = this.wallet?.account?.address
19 | return walletAddress ? AccountAddress.fromString(walletAddress.toString()) : this.account.accountAddress
20 | }
21 |
22 | async signTransaction(transaction: AnyRawTransaction): Promise {
23 | const senderAuthenticator = await this.wallet.signTransaction({
24 | transactionOrPayload: transaction,
25 | })
26 | return {
27 | senderAuthenticator: senderAuthenticator.authenticator,
28 | }
29 | }
30 |
31 | async sendTransaction(transaction: InputTransactionData): Promise {
32 | const txHash = await this.wallet.signAndSubmitTransaction(transaction)
33 |
34 | return txHash.hash
35 | }
36 |
37 | async signMessage(message: AptosSignMessageInput) {
38 | return this.wallet.signMessage(message)
39 | }
40 | }
41 |
--------------------------------------------------------------------------------
/src/tools/amnis/index.ts:
--------------------------------------------------------------------------------
1 | export * from "./stake-token"
2 | export * from "./withdraw-stake"
3 |
--------------------------------------------------------------------------------
/src/tools/amnis/stake-token.ts:
--------------------------------------------------------------------------------
1 | import { type AccountAddress, convertAmountFromHumanReadableToOnChain } from "@aptos-labs/ts-sdk"
2 | import type { AgentRuntime } from "../../agent"
3 |
4 | /**
5 | * Stake APT or any tokens on Amnis
6 | * @param agent MoveAgentKit instance
7 | * @param to Recipient's public key
8 | * @param amount Amount to transfer
9 | * @returns Transaction signature
10 | */
11 | export async function stakeTokens(agent: AgentRuntime, to: AccountAddress, amount: number): Promise {
12 | try {
13 | const transaction = await agent.aptos.transaction.build.simple({
14 | sender: agent.account.getAddress(),
15 | data: {
16 | function: "0x111ae3e5bc816a5e63c2da97d0aa3886519e0cd5e4b046659fa35796bd11542a::router::deposit_and_stake_entry",
17 | functionArguments: [amount, to.toString()],
18 | },
19 | })
20 |
21 | const committedTransactionHash = await agent.account.sendTransaction(transaction)
22 |
23 | const signedTransaction = await agent.aptos.waitForTransaction({
24 | transactionHash: committedTransactionHash,
25 | })
26 |
27 | if (!signedTransaction.success) {
28 | console.error(signedTransaction, "Token staking failed")
29 | throw new Error("Token staking failed")
30 | }
31 |
32 | return signedTransaction.hash
33 | } catch (error: any) {
34 | throw new Error(`Token staking failed: ${error.message}`)
35 | }
36 | }
37 |
--------------------------------------------------------------------------------
/src/tools/amnis/withdraw-stake.ts:
--------------------------------------------------------------------------------
1 | import type { AccountAddress } from "@aptos-labs/ts-sdk"
2 | import type { AgentRuntime } from "../../agent"
3 |
4 | /**
5 | * Unstake APT or any tokens on Amnis
6 | * @param agent MoveAgentKit instance
7 | * @param to Recipient's public key
8 | * @param amount Amount to unstake
9 | * @returns Transaction signature
10 | */
11 | export async function unstakeTokens(agent: AgentRuntime, to: AccountAddress, amount: number): Promise {
12 | try {
13 | const transaction = await agent.aptos.transaction.build.simple({
14 | sender: agent.account.getAddress(),
15 | data: {
16 | function: "0x111ae3e5bc816a5e63c2da97d0aa3886519e0cd5e4b046659fa35796bd11542a::router::unstake_entry",
17 | functionArguments: [amount, to.toString()],
18 | },
19 | })
20 |
21 | const committedTransactionHash = await agent.account.sendTransaction(transaction)
22 |
23 | const signedTransaction = await agent.aptos.waitForTransaction({
24 | transactionHash: committedTransactionHash,
25 | })
26 |
27 | if (!signedTransaction.success) {
28 | console.error(signedTransaction, "Token unstaking failed")
29 | throw new Error("Token unstaking failed")
30 | }
31 |
32 | return signedTransaction.hash
33 | } catch (error: any) {
34 | throw new Error(`Token unstaking failed: ${error.message}`)
35 | }
36 | }
37 |
--------------------------------------------------------------------------------
/src/tools/aptos/balance.ts:
--------------------------------------------------------------------------------
1 | import { type MoveStructId, convertAmountFromOnChainToHumanReadable } from "@aptos-labs/ts-sdk"
2 | import type { AgentRuntime } from "../../agent"
3 |
4 | /**
5 | * Fetches balance of an aptos account
6 | * @param agent MoveAgentKit instance
7 | * @returns Transaction signature
8 | * @example
9 | * ```ts
10 | * const balance = await getBalance(agent)
11 | * ```
12 | */
13 | export async function getBalance(agent: AgentRuntime, mint?: string | MoveStructId): Promise {
14 | try {
15 | if (mint) {
16 | let balance: number
17 | if (mint.split("::").length !== 3) {
18 | const balances = await agent.aptos.getCurrentFungibleAssetBalances({
19 | options: {
20 | where: {
21 | owner_address: {
22 | _eq: agent.account.getAddress().toStringLong(),
23 | },
24 | asset_type: { _eq: mint },
25 | },
26 | },
27 | })
28 |
29 | balance = balances[0].amount ?? 0
30 | } else {
31 | balance = await agent.aptos.getAccountCoinAmount({
32 | accountAddress: agent.account.getAddress(),
33 | coinType: mint as MoveStructId,
34 | })
35 | }
36 | return balance
37 | }
38 | const balance = await agent.aptos.getAccountAPTAmount({
39 | accountAddress: agent.account.getAddress(),
40 | })
41 |
42 | const convertedBalance = convertAmountFromOnChainToHumanReadable(balance, 8)
43 |
44 | return convertedBalance
45 | } catch (error: any) {
46 | throw new Error(`Token transfer failed: ${error.message}`)
47 | }
48 | }
49 |
--------------------------------------------------------------------------------
/src/tools/aptos/burn-nft.ts:
--------------------------------------------------------------------------------
1 | import { type AccountAddress, Aptos, AptosConfig } from "@aptos-labs/ts-sdk"
2 | import type { AgentRuntime } from "../../agent"
3 |
4 | /**
5 | * Burn NFT
6 | * @param agent MoveAgentKit instance
7 | * @param mint NFT mint address
8 | * @returns Transaction signature
9 | */
10 | export async function burnNFT(agent: AgentRuntime, mint: AccountAddress): Promise {
11 | return ""
12 | // try {
13 | // const transaction = await agent.aptos.burnDigitalAssetTransaction({
14 | // creator: agent.account.getAccount(),
15 | // digitalAssetAddress: mint,
16 | // });
17 |
18 | // const committedTransactionHash = await agent.account.sendTransaction(transaction);
19 |
20 | // const signedTransaction = await agent.aptos.waitForTransaction({
21 | // transactionHash: committedTransactionHash,
22 | // });
23 |
24 | // if (!signedTransaction.success) {
25 | // console.error(signedTransaction, "NFT burn failed");
26 | // throw new Error("NFT burn failed");
27 | // }
28 |
29 | // return signedTransaction.hash;
30 | // } catch (error: any) {
31 | // throw new Error(`NFT burn failed: ${error.message}`);
32 | // }
33 | }
34 |
--------------------------------------------------------------------------------
/src/tools/aptos/burn-token.ts:
--------------------------------------------------------------------------------
1 | import type { AgentRuntime } from "../../agent"
2 |
3 | /**
4 | * Burn fungible asset token
5 | * @param agent MoveAgentKit instance
6 | * @param amount Amount to burn
7 | * @param mint Fungible asset address to burn
8 | * @returns Transaction signature
9 | */
10 | export async function burnToken(agent: AgentRuntime, amount: number, mint: string): Promise {
11 | try {
12 | const transaction = await agent.aptos.transaction.build.simple({
13 | sender: agent.account.getAddress(),
14 | data: {
15 | function: "0x67c8564aee3799e9ac669553fdef3a3828d4626f24786b6a5642152fa09469dd::launchpad::burn_fa",
16 | functionArguments: [mint, amount],
17 | },
18 | })
19 |
20 | const committedTransactionHash = await agent.account.sendTransaction(transaction)
21 |
22 | const signedTransaction = await agent.aptos.waitForTransaction({
23 | transactionHash: committedTransactionHash,
24 | })
25 |
26 | if (!signedTransaction.success) {
27 | console.error(signedTransaction, "Token burn failed")
28 | throw new Error("Token burn failed")
29 | }
30 |
31 | return signedTransaction.hash
32 | } catch (error: any) {
33 | throw new Error(`Token burn failed: ${error.message}`)
34 | }
35 | }
36 |
--------------------------------------------------------------------------------
/src/tools/aptos/create-token.ts:
--------------------------------------------------------------------------------
1 | import type { AgentRuntime } from "../../agent"
2 |
3 | /**
4 | * Create a fungible asset token
5 | * @param agent MoveAgentKit instance
6 | * @param name Name of the token
7 | * @param symbol Symbol of the token
8 | * @param iconURI URI of the token icon
9 | * @param projectURI URI of the token project
10 | */
11 | export async function createToken(
12 | agent: AgentRuntime,
13 | name: string,
14 | symbol: string,
15 | iconURI: string,
16 | projectURI: string
17 | ): Promise<{
18 | hash: string
19 | token: any
20 | }> {
21 | try {
22 | const transaction = await agent.aptos.transaction.build.simple({
23 | sender: agent.account.getAddress(),
24 | data: {
25 | function: "0x67c8564aee3799e9ac669553fdef3a3828d4626f24786b6a5642152fa09469dd::launchpad::create_fa_simple",
26 | functionArguments: [name, symbol, iconURI, projectURI],
27 | },
28 | })
29 |
30 | const committedTransactionHash = await agent.account.sendTransaction(transaction)
31 |
32 | const signedTransaction = await agent.aptos.waitForTransaction({
33 | transactionHash: committedTransactionHash,
34 | })
35 |
36 | if (!signedTransaction.success) {
37 | console.error(signedTransaction, "Token creation failed")
38 | throw new Error("Token creation failed")
39 | }
40 |
41 | return {
42 | hash: signedTransaction.hash,
43 | // @ts-ignore
44 | token: signedTransaction.events[0].data.fa_obj.inner,
45 | }
46 | } catch (error: any) {
47 | throw new Error(`Token creation failed: ${error.message}`)
48 | }
49 | }
50 |
--------------------------------------------------------------------------------
/src/tools/aptos/get-token-details.ts:
--------------------------------------------------------------------------------
1 | import axios from "axios"
2 | import { AgentRuntime } from "../../agent"
3 |
4 | /**
5 | * Fetches balance of an aptos account
6 | * @param agent MoveAgentKit instance
7 | * @returns Transaction signature
8 | * @example
9 | * ```ts
10 | * const balance = await getBalance(agent)
11 | * ```
12 | */
13 | export async function getTokenDetails(tokenAddress: string): Promise {
14 | try {
15 | const res = await axios.get(
16 | "https://raw.githubusercontent.com/PanoraExchange/Aptos-Tokens/refs/heads/main/token-list.json"
17 | )
18 | const tokenData = await res.data
19 |
20 | if (!tokenAddress || tokenAddress === "") return tokenData[0]
21 |
22 | const token = tokenData.find(
23 | (tokenAddr: any) => (tokenAddr.tokenAddress || tokenAddr.faAddress).toLowerCase() === tokenAddress.toLowerCase()
24 | )
25 |
26 | if (!token && tokenAddress.includes("fa_to_coin_wrapper::WrappedUSDT")) {
27 | return tokenData.find(
28 | (e: any) => e.faAddress === "0x357b0b74bc833e95a115ad22604854d6b0fca151cecd94111770e5d6ffc9dc2b"
29 | )
30 | }
31 | if (!token) throw new Error("Cannot find token")
32 |
33 | return token
34 | } catch (error: any) {
35 | throw new Error(`Token transfer failed: ${error.message}`)
36 | }
37 | }
38 |
--------------------------------------------------------------------------------
/src/tools/aptos/get-token-price.ts:
--------------------------------------------------------------------------------
1 | /**
2 | * Fetches token price from the Pyth network
3 | * @param query Token query to search for
4 | * @returns Price feed data
5 | */
6 | export async function getTokenPrice(query: string): Promise {
7 | try {
8 | const assetDataResponse = await fetch(`https://hermes.pyth.network/v2/price_feeds?query=${query}&asset_type=crypto`)
9 |
10 | const assetData = await assetDataResponse.json()
11 |
12 | const formattedData = assetData.map((data: any) => {
13 | return {
14 | id: data.id,
15 | displayName: data.attributes.display_symbol,
16 | symbol: data.attributes.symbol,
17 | }
18 | })
19 |
20 | const assetIdArray = formattedData.map((data: any) => data.id)
21 |
22 | if (assetIdArray.length === 0) {
23 | throw new Error("No assets found for the given query")
24 | }
25 | const assetPriceDataResponse = await fetch(
26 | `https://hermes.pyth.network/v2/updates/price/latest?ids[]=${assetIdArray.join("&ids[]=")}`
27 | )
28 |
29 | const assetPriceData = await assetPriceDataResponse.json()
30 |
31 | const priceFeed = formattedData.map((data: any) => {
32 | const priceData = assetPriceData.parsed.find((price: any) => price.id === data.id)
33 |
34 | return {
35 | ...data,
36 | price:
37 | (Number(priceData.price.price) / 10 ** Math.abs(priceData.price.expo)).toLocaleString() ||
38 | Number(priceData.price.price).toLocaleString(),
39 | }
40 | })
41 |
42 | return priceFeed
43 | } catch (error: any) {
44 | throw new Error(`Token transfer failed: ${error.message}`)
45 | }
46 | }
47 |
--------------------------------------------------------------------------------
/src/tools/aptos/get-transaction.ts:
--------------------------------------------------------------------------------
1 | import type { TransactionResponse } from "@aptos-labs/ts-sdk"
2 | import type { AgentRuntime } from "../../agent"
3 |
4 | /**
5 | * Fetches transaction from aptos
6 | * @param agent MoveAgentKit instance
7 | * @param hash Transaction Hash
8 | * @returns Transaction signature
9 | * @example
10 | * ```ts
11 | * const transaction = await getTransaction(agent, "HASH")
12 | * ```
13 | */
14 | export async function getTransaction(agent: AgentRuntime, hash: string): Promise {
15 | try {
16 | const transaction = await agent.aptos.getTransactionByHash({
17 | transactionHash: hash,
18 | })
19 |
20 | return transaction
21 | } catch (error: any) {
22 | throw new Error(`Token transfer failed: ${error.message}`)
23 | }
24 | }
25 |
--------------------------------------------------------------------------------
/src/tools/aptos/index.ts:
--------------------------------------------------------------------------------
1 | export * from "./balance"
2 | export * from "./burn-nft"
3 | export * from "./burn-token"
4 | export * from "./transfer-nft"
5 | export * from "./transfer-token"
6 | export * from "./mint-token"
7 | export * from "./create-token"
8 | export * from "./get-transaction"
9 | export * from "./get-token-details"
10 | export * from "./get-token-price"
11 |
--------------------------------------------------------------------------------
/src/tools/aptos/mint-token.ts:
--------------------------------------------------------------------------------
1 | import { Account, type AccountAddress } from "@aptos-labs/ts-sdk"
2 | import type { AgentRuntime } from "../../agent"
3 |
4 | /**
5 | * Mint a fungible asset token
6 | * @param agent MoveAgentKit instance
7 | * @param name Name of the token
8 | * @param symbol Symbol of the token
9 | * @param iconURI URI of the token icon
10 | * @param projectURI URI of the token project
11 | */
12 | export async function mintToken(
13 | agent: AgentRuntime,
14 | to: AccountAddress,
15 | mint: string,
16 | amount: number
17 | ): Promise {
18 | try {
19 | const transaction = await agent.aptos.transaction.build.simple({
20 | sender: agent.account.getAddress(),
21 | data: {
22 | function: "0x67c8564aee3799e9ac669553fdef3a3828d4626f24786b6a5642152fa09469dd::launchpad::mint_to_address",
23 | functionArguments: [to.toString(), mint, amount],
24 | },
25 | })
26 |
27 | const committedTransactionHash = await agent.account.sendTransaction(transaction)
28 |
29 | const signedTransaction = await agent.aptos.waitForTransaction({
30 | transactionHash: committedTransactionHash,
31 | })
32 |
33 | if (!signedTransaction.success) {
34 | console.error(signedTransaction, "Token mint failed")
35 | throw new Error("Token mint failed")
36 | }
37 |
38 | return signedTransaction.hash
39 | } catch (error: any) {
40 | throw new Error(`Token mint failed: ${error.message}`)
41 | }
42 | }
43 |
--------------------------------------------------------------------------------
/src/tools/aptos/transfer-nft.ts:
--------------------------------------------------------------------------------
1 | import { type AccountAddress, Aptos, AptosConfig } from "@aptos-labs/ts-sdk"
2 | import type { AgentRuntime } from "../../agent"
3 |
4 | /**
5 | * Transfer NFT
6 | * @param agent MoveAgentKit instance
7 | * @param to Recipient's public key
8 | * @param mint NFT mint address
9 | * @returns Transaction signature
10 | */
11 | export async function transferNFT(
12 | agent: AgentRuntime, // Replace with the actual type of the move-agent
13 | to: AccountAddress,
14 | mint: AccountAddress
15 | ): Promise {
16 | return ""
17 | // try {
18 | // const transaction = await agent.aptos.transferDigitalAssetTransaction({
19 | // sender: agent.account.getAccount(),
20 | // digitalAssetAddress: mint,
21 | // recipient: to,
22 | // });
23 |
24 | // const committedTransaction = await agent.aptos.signAndSubmitTransaction({
25 | // signer: agent.account.getAccount(),
26 | // transaction,
27 | // });
28 |
29 | // const signedTransaction = await agent.aptos.waitForTransaction({
30 | // transactionHash: committedTransaction.hash,
31 | // });
32 |
33 | // if (!signedTransaction.success) {
34 | // console.error(signedTransaction, "NFT transfer failed");
35 | // throw new Error("NFT transfer failed");
36 | // }
37 |
38 | // return signedTransaction.hash;
39 | // } catch (error: any) {
40 | // throw new Error(`NFT transfer failed: ${error.message}`);
41 | // }
42 | }
43 |
--------------------------------------------------------------------------------
/src/tools/aptos/transfer-token.ts:
--------------------------------------------------------------------------------
1 | import {
2 | type AccountAddress,
3 | type InputGenerateTransactionPayloadData,
4 | convertAmountFromHumanReadableToOnChain,
5 | } from "@aptos-labs/ts-sdk"
6 | import type { AgentRuntime } from "../../agent"
7 |
8 | /**
9 | * Transfer APT, tokens or fungible asset to a recipient
10 | * @param agent MoveAgentKit instance
11 | * @param to Recipient's public key
12 | * @param amount Amount to transfer
13 | * @param mint Move struct ID or address of the token / fungible asset to transfer
14 | * @returns Transaction signature
15 | * @example
16 | * ```ts
17 | * const transactionHash = await transferTokens(agent, recipientAddress, amount, APTOS_COIN); // For APT
18 | * const otherTransactionHash = await transferTokens(agent, recipientAddress, amount, OTHER_TOKEN); // For another token
19 | * const fungibleAssetTransactionHash = await transferTokens(agent, recipientAddress, amount, fungibleAssetAddress); // For fungible asset
20 | * ```
21 | */
22 | export async function transferTokens(
23 | agent: AgentRuntime,
24 | to: AccountAddress,
25 | amount: number,
26 | mint: string
27 | ): Promise {
28 | const COIN_STANDARD_DATA: InputGenerateTransactionPayloadData = {
29 | function: "0x1::coin::transfer",
30 | typeArguments: [mint],
31 | functionArguments: [to.toString(), amount],
32 | }
33 |
34 | const FUNGIBLE_ASSET_DATA: InputGenerateTransactionPayloadData = {
35 | function: "0x1::primary_fungible_store::transfer",
36 | typeArguments: ["0x1::fungible_asset::Metadata"],
37 | functionArguments: [mint, to.toString(), amount],
38 | }
39 |
40 | try {
41 | const transaction = await agent.aptos.transaction.build.simple({
42 | sender: agent.account.getAddress(),
43 | data: mint.split("::").length === 3 ? COIN_STANDARD_DATA : FUNGIBLE_ASSET_DATA,
44 | })
45 |
46 | const committedTransactionHash = await agent.account.sendTransaction(transaction)
47 |
48 | const signedTransaction = await agent.aptos.waitForTransaction({
49 | transactionHash: committedTransactionHash,
50 | })
51 |
52 | if (!signedTransaction.success) {
53 | console.error(signedTransaction, "Token transfer failed")
54 | throw new Error("Token transfer failed")
55 | }
56 |
57 | return signedTransaction.hash
58 | } catch (error: any) {
59 | throw new Error(`Token transfer failed: ${error.message}`)
60 | }
61 | }
62 |
--------------------------------------------------------------------------------
/src/tools/aries/borrow.ts:
--------------------------------------------------------------------------------
1 | import type { MoveStructId } from "@aptos-labs/ts-sdk"
2 | import type { AgentRuntime } from "../../agent"
3 |
4 | /**
5 | * Borrow tokens from Aries
6 | * @param agent MoveAgentKit instance
7 | * @param mintType Type of coin to borrow
8 | * @param amount Amount to borrow
9 | * @returns Transaction signature
10 | */
11 | export async function borrowAriesToken(agent: AgentRuntime, mintType: MoveStructId, amount: number): Promise {
12 | try {
13 | const transaction = await agent.aptos.transaction.build.simple({
14 | sender: agent.account.getAddress(),
15 | data: {
16 | function: "0x9770fa9c725cbd97eb50b2be5f7416efdfd1f1554beb0750d4dae4c64e860da3::controller::withdraw",
17 | typeArguments: [mintType],
18 | functionArguments: ["Main account", amount, true],
19 | },
20 | })
21 |
22 | const committedTransactionHash = await agent.account.sendTransaction(transaction)
23 |
24 | const signedTransaction = await agent.aptos.waitForTransaction({
25 | transactionHash: committedTransactionHash,
26 | })
27 |
28 | if (!signedTransaction.success) {
29 | console.error(signedTransaction, "Borrow failed")
30 | throw new Error("Borrow failed")
31 | }
32 |
33 | return signedTransaction.hash
34 | } catch (error: any) {
35 | throw new Error(`Borrow failed: ${error.message}`)
36 | }
37 | }
38 |
--------------------------------------------------------------------------------
/src/tools/aries/create-profile.ts:
--------------------------------------------------------------------------------
1 | import type { AgentRuntime } from "../../agent"
2 |
3 | /**
4 | * Create a profile in Aries
5 | * @param agent MoveAgentKit instance
6 | * @returns Transaction signature
7 | */
8 | export async function createAriesProfile(agent: AgentRuntime): Promise {
9 | try {
10 | const transaction = await agent.aptos.transaction.build.simple({
11 | sender: agent.account.getAddress(),
12 | data: {
13 | function: "0x9770fa9c725cbd97eb50b2be5f7416efdfd1f1554beb0750d4dae4c64e860da3::controller::register_user",
14 | functionArguments: ["Main account"],
15 | },
16 | })
17 |
18 | const committedTransactionHash = await agent.account.sendTransaction(transaction)
19 |
20 | const signedTransaction = await agent.aptos.waitForTransaction({
21 | transactionHash: committedTransactionHash,
22 | })
23 |
24 | if (!signedTransaction.success) {
25 | console.error(signedTransaction, "Create profile failed")
26 | throw new Error("Create profile failed")
27 | }
28 |
29 | return signedTransaction.hash
30 | } catch (error: any) {
31 | throw new Error(`Create profile failed: ${error.message}`)
32 | }
33 | }
34 |
--------------------------------------------------------------------------------
/src/tools/aries/index.ts:
--------------------------------------------------------------------------------
1 | export * from "./create-profile"
2 | export * from "./lend"
3 | export * from "./borrow"
4 | export * from "./withdraw"
5 | export * from "./repay"
6 |
--------------------------------------------------------------------------------
/src/tools/aries/lend.ts:
--------------------------------------------------------------------------------
1 | import type { MoveStructId } from "@aptos-labs/ts-sdk"
2 | import type { AgentRuntime } from "../../agent"
3 |
4 | /**
5 | * Lend tokens in Aries
6 | * @param agent MoveAgentKit instance
7 | * @param mintType Type of coin to lend
8 | * @param amount Amount to lend
9 | * @returns Transaction signature
10 | */
11 | export async function lendAriesToken(agent: AgentRuntime, mintType: MoveStructId, amount: number): Promise {
12 | try {
13 | const transaction = await agent.aptos.transaction.build.simple({
14 | sender: agent.account.getAddress(),
15 | data: {
16 | function: "0x9770fa9c725cbd97eb50b2be5f7416efdfd1f1554beb0750d4dae4c64e860da3::controller::deposit",
17 | typeArguments: [mintType],
18 | functionArguments: ["Main account", amount, false],
19 | },
20 | })
21 |
22 | const committedTransactionHash = await agent.account.sendTransaction(transaction)
23 |
24 | const signedTransaction = await agent.aptos.waitForTransaction({
25 | transactionHash: committedTransactionHash,
26 | })
27 |
28 | if (!signedTransaction.success) {
29 | console.error(signedTransaction, "Lend failed")
30 | throw new Error("Lend failed")
31 | }
32 |
33 | return signedTransaction.hash
34 | } catch (error: any) {
35 | throw new Error(`Lend failed: ${error.message}`)
36 | }
37 | }
38 |
--------------------------------------------------------------------------------
/src/tools/aries/repay.ts:
--------------------------------------------------------------------------------
1 | import type { MoveStructId } from "@aptos-labs/ts-sdk"
2 | import type { AgentRuntime } from "../../agent"
3 |
4 | /**
5 | * Repay tokens in Aries
6 | * @param agent MoveAgentKit instance
7 | * @param mintType Type of coin to repay
8 | * @param amount Amount to repay
9 | * @returns Transaction signature
10 | */
11 | export async function repayAriesToken(agent: AgentRuntime, mintType: MoveStructId, amount: number): Promise {
12 | try {
13 | const transaction = await agent.aptos.transaction.build.simple({
14 | sender: agent.account.getAddress(),
15 | data: {
16 | function: "0x9770fa9c725cbd97eb50b2be5f7416efdfd1f1554beb0750d4dae4c64e860da3::controller::deposit",
17 | typeArguments: [mintType],
18 | functionArguments: ["Main account", amount, true],
19 | },
20 | })
21 |
22 | const committedTransactionHash = await agent.account.sendTransaction(transaction)
23 |
24 | const signedTransaction = await agent.aptos.waitForTransaction({
25 | transactionHash: committedTransactionHash,
26 | })
27 |
28 | if (!signedTransaction.success) {
29 | console.error(signedTransaction, "Repay failed")
30 | throw new Error("Repay failed")
31 | }
32 |
33 | return signedTransaction.hash
34 | } catch (error: any) {
35 | throw new Error(`Repay failed: ${error.message}`)
36 | }
37 | }
38 |
--------------------------------------------------------------------------------
/src/tools/aries/withdraw.ts:
--------------------------------------------------------------------------------
1 | import type { MoveStructId } from "@aptos-labs/ts-sdk"
2 | import type { AgentRuntime } from "../../agent"
3 |
4 | /**
5 | * Withdraw tokens from Aries
6 | * @param agent MoveAgentKit instance
7 | * @param mintType Type of coin to withdraw
8 | * @param amount Amount to withdraw
9 | * @returns Transaction signature
10 | */
11 | export async function withdrawAriesToken(agent: AgentRuntime, mintType: MoveStructId, amount: number): Promise {
12 | try {
13 | const transaction = await agent.aptos.transaction.build.simple({
14 | sender: agent.account.getAddress(),
15 | data: {
16 | function: "0x9770fa9c725cbd97eb50b2be5f7416efdfd1f1554beb0750d4dae4c64e860da3::controller::withdraw",
17 | typeArguments: [mintType],
18 | functionArguments: ["Main account", amount, false],
19 | },
20 | })
21 |
22 | const committedTransactionHash = await agent.account.sendTransaction(transaction)
23 |
24 | const signedTransaction = await agent.aptos.waitForTransaction({
25 | transactionHash: committedTransactionHash,
26 | })
27 |
28 | if (!signedTransaction.success) {
29 | console.error(signedTransaction, "Withdraw failed")
30 | throw new Error("Withdraw failed")
31 | }
32 |
33 | return signedTransaction.hash
34 | } catch (error: any) {
35 | throw new Error(`Withdraw failed: ${error.message}`)
36 | }
37 | }
38 |
--------------------------------------------------------------------------------
/src/tools/echelon/borrow.ts:
--------------------------------------------------------------------------------
1 | import type { InputGenerateTransactionPayloadData, MoveStructId } from "@aptos-labs/ts-sdk"
2 | import type { AgentRuntime } from "../../agent"
3 |
4 | /**
5 | * Borrow tokens from Echelon
6 | * @param agent MoveAgentKit instance
7 | * @param mintType Type of coin to lend
8 | * @param amount Amount to lend
9 | * @param poolAddress Pool address
10 | * @param fungibleAsset Whether the asset is fungible
11 | * @returns Transaction signature
12 | */
13 | export async function borrowTokenWithEchelon(
14 | agent: AgentRuntime,
15 | mintType: MoveStructId,
16 | amount: number,
17 | poolAddress: string,
18 | fungibleAsset: boolean
19 | ): Promise {
20 | const FUNCTIONAL_ARGS_DATA = [poolAddress, amount]
21 |
22 | const COIN_STANDARD_DATA: InputGenerateTransactionPayloadData = {
23 | function: "0xc6bc659f1649553c1a3fa05d9727433dc03843baac29473c817d06d39e7621ba::scripts::borrow",
24 | typeArguments: [mintType.toString()],
25 | functionArguments: FUNCTIONAL_ARGS_DATA,
26 | }
27 |
28 | const FUNGIBLE_ASSET_DATA: InputGenerateTransactionPayloadData = {
29 | function: "0xc6bc659f1649553c1a3fa05d9727433dc03843baac29473c817d06d39e7621ba::scripts::borrow_fa",
30 | functionArguments: FUNCTIONAL_ARGS_DATA,
31 | }
32 |
33 | try {
34 | const transaction = await agent.aptos.transaction.build.simple({
35 | sender: agent.account.getAddress(),
36 | data: fungibleAsset ? FUNGIBLE_ASSET_DATA : COIN_STANDARD_DATA,
37 | })
38 |
39 | const committedTransactionHash = await agent.account.sendTransaction(transaction)
40 |
41 | const signedTransaction = await agent.aptos.waitForTransaction({
42 | transactionHash: committedTransactionHash,
43 | })
44 |
45 | if (!signedTransaction.success) {
46 | console.error(signedTransaction, "Borrow failed")
47 | throw new Error("Borrow failed")
48 | }
49 |
50 | return signedTransaction.hash
51 | } catch (error: any) {
52 | throw new Error(`Borrow failed: ${error.message}`)
53 | }
54 | }
55 |
--------------------------------------------------------------------------------
/src/tools/echelon/index.ts:
--------------------------------------------------------------------------------
1 | export * from "./lend"
2 | export * from "./withdraw"
3 | export * from "./repay"
4 | export * from "./borrow"
5 |
--------------------------------------------------------------------------------
/src/tools/echelon/lend.ts:
--------------------------------------------------------------------------------
1 | import type { InputGenerateTransactionPayloadData, MoveStructId } from "@aptos-labs/ts-sdk"
2 | import type { AgentRuntime } from "../../agent"
3 |
4 | /**
5 | * Lend tokens in Echelon
6 | * @param agent MoveAgentKit instance
7 | * @param mintType Type of coin to lend
8 | * @param amount Amount to lend
9 | * @param poolAddress Pool address
10 | * @param fungibleAsset Whether the asset is fungible
11 | * @returns Transaction signature
12 | */
13 | export async function lendTokenWithEchelon(
14 | agent: AgentRuntime,
15 | mintType: MoveStructId,
16 | amount: number,
17 | poolAddress: string,
18 | fungibleAsset: boolean
19 | ): Promise {
20 | try {
21 | const FUNCTIONAL_ARGS_DATA = [poolAddress, amount]
22 |
23 | const COIN_STANDARD_DATA: InputGenerateTransactionPayloadData = {
24 | function: "0xc6bc659f1649553c1a3fa05d9727433dc03843baac29473c817d06d39e7621ba::scripts::supply",
25 | typeArguments: [mintType.toString()],
26 | functionArguments: FUNCTIONAL_ARGS_DATA,
27 | }
28 |
29 | const FUNGIBLE_ASSET_DATA: InputGenerateTransactionPayloadData = {
30 | function: "0xc6bc659f1649553c1a3fa05d9727433dc03843baac29473c817d06d39e7621ba::scripts::supply_fa",
31 | functionArguments: FUNCTIONAL_ARGS_DATA,
32 | }
33 |
34 | const transaction = await agent.aptos.transaction.build.simple({
35 | sender: agent.account.getAddress(),
36 | data: fungibleAsset ? FUNGIBLE_ASSET_DATA : COIN_STANDARD_DATA,
37 | })
38 |
39 | const committedTransactionHash = await agent.account.sendTransaction(transaction)
40 |
41 | const signedTransaction = await agent.aptos.waitForTransaction({
42 | transactionHash: committedTransactionHash,
43 | })
44 |
45 | if (!signedTransaction.success) {
46 | console.error(signedTransaction, "Lend failed")
47 | throw new Error("Lend failed")
48 | }
49 |
50 | return signedTransaction.hash
51 | } catch (error: any) {
52 | throw new Error(`Lend failed: ${error.message}`)
53 | }
54 | }
55 |
--------------------------------------------------------------------------------
/src/tools/echelon/repay.ts:
--------------------------------------------------------------------------------
1 | import type { InputGenerateTransactionPayloadData, MoveStructId } from "@aptos-labs/ts-sdk"
2 | import type { AgentRuntime } from "../../agent"
3 |
4 | /**
5 | * Repay tokens in Echelon
6 | * @param agent MoveAgentKit instance
7 | * @param mintType Type of coin to lend
8 | * @param amount Amount to lend
9 | * @param poolAddress Pool address
10 | * @param fungibleAsset Whether the asset is fungible
11 | * @returns Transaction signature
12 | */
13 | export async function repayTokenWithEchelon(
14 | agent: AgentRuntime,
15 | mintType: MoveStructId,
16 | amount: number,
17 | poolAddress: string,
18 | fungibleAsset: boolean
19 | ): Promise {
20 | try {
21 | const FUNCTIONAL_ARGS_DATA = [poolAddress, amount]
22 |
23 | const COIN_STANDARD_DATA: InputGenerateTransactionPayloadData = {
24 | function: "0xc6bc659f1649553c1a3fa05d9727433dc03843baac29473c817d06d39e7621ba::scripts::repay",
25 | typeArguments: [mintType.toString()],
26 | functionArguments: FUNCTIONAL_ARGS_DATA,
27 | }
28 |
29 | const FUNGIBLE_ASSET_DATA: InputGenerateTransactionPayloadData = {
30 | function: "0xc6bc659f1649553c1a3fa05d9727433dc03843baac29473c817d06d39e7621ba::scripts::repay_fa",
31 | functionArguments: FUNCTIONAL_ARGS_DATA,
32 | }
33 |
34 | const transaction = await agent.aptos.transaction.build.simple({
35 | sender: agent.account.getAddress(),
36 | data: fungibleAsset ? FUNGIBLE_ASSET_DATA : COIN_STANDARD_DATA,
37 | })
38 |
39 | const committedTransactionHash = await agent.account.sendTransaction(transaction)
40 |
41 | const signedTransaction = await agent.aptos.waitForTransaction({
42 | transactionHash: committedTransactionHash,
43 | })
44 |
45 | if (!signedTransaction.success) {
46 | console.error(signedTransaction, "Repay failed")
47 | throw new Error("Repay failed")
48 | }
49 |
50 | return signedTransaction.hash
51 | } catch (error: any) {
52 | throw new Error(`Repay failed: ${error.message}`)
53 | }
54 | }
55 |
--------------------------------------------------------------------------------
/src/tools/echelon/withdraw.ts:
--------------------------------------------------------------------------------
1 | import type { InputGenerateTransactionPayloadData, MoveStructId } from "@aptos-labs/ts-sdk"
2 | import type { AgentRuntime } from "../../agent"
3 |
4 | /**
5 | * Withdraw tokens from Echelon
6 | * @param agent MoveAgentKit instance
7 | * @param mintType Type of coin to lend
8 | * @param amount Amount to lend
9 | * @param poolAddress Pool address
10 | * @param fungibleAsset Whether the asset is fungible
11 | * @returns Transaction signature
12 | */
13 | export async function withdrawTokenWithEchelon(
14 | agent: AgentRuntime,
15 | mintType: MoveStructId,
16 | amount: number,
17 | poolAddress: string,
18 | fungibleAsset: boolean
19 | ): Promise {
20 | try {
21 | const FUNCTIONAL_ARGS_DATA = [poolAddress, amount]
22 |
23 | const COIN_STANDARD_DATA: InputGenerateTransactionPayloadData = {
24 | function: "0xc6bc659f1649553c1a3fa05d9727433dc03843baac29473c817d06d39e7621ba::scripts::withdraw",
25 | typeArguments: [mintType.toString()],
26 | functionArguments: FUNCTIONAL_ARGS_DATA,
27 | }
28 |
29 | const FUNGIBLE_ASSET_DATA: InputGenerateTransactionPayloadData = {
30 | function: "0xc6bc659f1649553c1a3fa05d9727433dc03843baac29473c817d06d39e7621ba::scripts::withdraw_fa",
31 | functionArguments: FUNCTIONAL_ARGS_DATA,
32 | }
33 |
34 | const transaction = await agent.aptos.transaction.build.simple({
35 | sender: agent.account.getAddress(),
36 | data: fungibleAsset ? FUNGIBLE_ASSET_DATA : COIN_STANDARD_DATA,
37 | })
38 |
39 | const committedTransactionHash = await agent.account.sendTransaction(transaction)
40 |
41 | const signedTransaction = await agent.aptos.waitForTransaction({
42 | transactionHash: committedTransactionHash,
43 | })
44 |
45 | if (!signedTransaction.success) {
46 | console.error(signedTransaction, "Withdraw failed")
47 | throw new Error("Withdraw failed")
48 | }
49 |
50 | return signedTransaction.hash
51 | } catch (error: any) {
52 | throw new Error(`Withdraw failed: ${error.message}`)
53 | }
54 | }
55 |
--------------------------------------------------------------------------------
/src/tools/echo/index.ts:
--------------------------------------------------------------------------------
1 | export * from "./stake"
2 | export * from "./unstake"
3 |
--------------------------------------------------------------------------------
/src/tools/echo/stake.ts:
--------------------------------------------------------------------------------
1 | import type { AgentRuntime } from "../../agent"
2 |
3 | /**
4 | * Stake tokens in Echo
5 | * @param agent MoveAgentKit instance
6 | * @param amount Amount of token to stake
7 | * @returns Transaction signature
8 | */
9 | export async function stakeTokenWithEcho(agent: AgentRuntime, amount: number): Promise {
10 | try {
11 | const transaction = await agent.aptos.transaction.build.simple({
12 | sender: agent.account.getAddress(),
13 | data: {
14 | function: "0xa0281660ff6ca6c1b68b55fcb9b213c2276f90ad007ad27fd003cf2f3478e96e::lsdmanage::stake",
15 | functionArguments: [amount],
16 | },
17 | })
18 |
19 | const committedTransactionHash = await agent.account.sendTransaction(transaction)
20 |
21 | const signedTransaction = await agent.aptos.waitForTransaction({
22 | transactionHash: committedTransactionHash,
23 | })
24 |
25 | if (!signedTransaction.success) {
26 | console.error(signedTransaction, "Stake token in Echo failed")
27 | throw new Error("Stake token in Echo failed")
28 | }
29 |
30 | return signedTransaction.hash
31 | } catch (error: any) {
32 | throw new Error(`Stake token in Echo failed: ${error.message}`)
33 | }
34 | }
35 |
--------------------------------------------------------------------------------
/src/tools/echo/unstake.ts:
--------------------------------------------------------------------------------
1 | import type { AgentRuntime } from "../../agent"
2 |
3 | /**
4 | * Unstake tokens in Echo
5 | * @param agent MoveAgentKit instance
6 | * @param amount Amount of APT to unstake
7 | * @returns Transaction signature
8 | */
9 | export async function unstakeTokenWithEcho(agent: AgentRuntime, amount: number): Promise {
10 | try {
11 | const transaction = await agent.aptos.transaction.build.simple({
12 | sender: agent.account.getAddress(),
13 | data: {
14 | function: "0xa0281660ff6ca6c1b68b55fcb9b213c2276f90ad007ad27fd003cf2f3478e96e::lsdmanage::unstake",
15 | functionArguments: [amount],
16 | },
17 | })
18 |
19 | const committedTransactionHash = await agent.account.sendTransaction(transaction)
20 |
21 | const signedTransaction = await agent.aptos.waitForTransaction({
22 | transactionHash: committedTransactionHash,
23 | })
24 |
25 | if (!signedTransaction.success) {
26 | console.error(signedTransaction, "Unstake token in Echo failed")
27 | throw new Error("Unstake token in Echo failed")
28 | }
29 |
30 | return signedTransaction.hash
31 | } catch (error: any) {
32 | throw new Error(`Unstake token in Echo failed: ${error.message}`)
33 | }
34 | }
35 |
--------------------------------------------------------------------------------
/src/tools/index.ts:
--------------------------------------------------------------------------------
1 | export * from "./amnis"
2 | export * from "./aptos"
3 | export * from "./joule"
4 | export * from "./aries"
5 | export * from "./echelon"
6 | export * from "./echo"
7 | export * from "./liquidswap"
8 | export * from "./panora"
9 | export * from "./openai"
10 | export * from "./thala"
11 | export * from "./merkletrade"
12 |
--------------------------------------------------------------------------------
/src/tools/joule/borrow.ts:
--------------------------------------------------------------------------------
1 | import { AccountAddress, type InputGenerateTransactionPayloadData, type MoveStructId } from "@aptos-labs/ts-sdk"
2 | import type { AgentRuntime } from "../../agent"
3 |
4 | /**
5 | * Borrow APT, tokens or fungible asset from a position
6 | * @param agent MoveAgentKit instance
7 | * @param amount Amount to mint
8 | * @param mint The Move struct ID of the token to borrow
9 | * @param positionId The position ID to borrow from
10 | * @param fungibleAsset boolean value for fungible asset
11 | * @returns Transaction signature and position ID
12 | * @example
13 | * ```ts
14 | * const transactionHash = await borrowToken(agent, amount, APTOS_COIN, positionId); // For APT
15 | * const otherTransactionHash = await borrowToken(agent, amount, OTHER_TOKEN, positionId); // For another token
16 | * const fungibleAssetTransactionHash = await borrowToken(agent, amount, APTOS_COIN, positionId, fungibleAssetAddress); // For fungible asset
17 | */
18 | export async function borrowToken(
19 | agent: AgentRuntime,
20 | amount: number,
21 | mint: MoveStructId,
22 | positionId: string,
23 | fungibleAsset: boolean
24 | ): Promise<{
25 | hash: string
26 | positionId: string
27 | }> {
28 | const pyth_update_data = await agent.getPythData()
29 |
30 | const DEFAULT_FUNCTIONAL_ARGS = [positionId, amount, pyth_update_data]
31 |
32 | const COIN_STANDARD_DATA: InputGenerateTransactionPayloadData = {
33 | function: "0x2fe576faa841347a9b1b32c869685deb75a15e3f62dfe37cbd6d52cc403a16f6::pool::borrow",
34 | typeArguments: [mint.toString()],
35 | functionArguments: DEFAULT_FUNCTIONAL_ARGS,
36 | }
37 |
38 | const FUNGIBLE_ASSET_DATA: InputGenerateTransactionPayloadData = {
39 | function: "0x2fe576faa841347a9b1b32c869685deb75a15e3f62dfe37cbd6d52cc403a16f6::pool::borrow_fa",
40 | functionArguments: [positionId, mint.toString(), amount, pyth_update_data],
41 | }
42 |
43 | try {
44 | const transaction = await agent.aptos.transaction.build.simple({
45 | sender: agent.account.getAddress(),
46 | data: fungibleAsset ? FUNGIBLE_ASSET_DATA : COIN_STANDARD_DATA,
47 | })
48 |
49 | const committedTransactionHash = await agent.account.sendTransaction(transaction)
50 |
51 | const signedTransaction = await agent.aptos.waitForTransaction({
52 | transactionHash: committedTransactionHash,
53 | })
54 |
55 | if (!signedTransaction.success) {
56 | console.error(signedTransaction, "Token borrow failed")
57 | throw new Error("Token borrow failed")
58 | }
59 |
60 | return {
61 | hash: signedTransaction.hash,
62 | positionId,
63 | }
64 | } catch (error: any) {
65 | throw new Error(`Token borrow failed: ${error.message}`)
66 | }
67 | }
68 |
--------------------------------------------------------------------------------
/src/tools/joule/claim-reward.ts:
--------------------------------------------------------------------------------
1 | import type { MoveStructId } from "@aptos-labs/ts-sdk"
2 | import type { AgentRuntime } from "../../agent"
3 |
4 | /**
5 | * Claim rewards from Joule pool
6 | * @param agent MoveAgentKit instance
7 | * @param rewardCoinType The coin type of the reward
8 | * @returns Transaction signature
9 | */
10 | export async function claimReward(agent: AgentRuntime, rewardCoinType: MoveStructId | string): Promise {
11 | try {
12 | const coinReward = `${rewardCoinType}1111`.replace("0x", "@")
13 |
14 | const isCoinTypeSTApt =
15 | rewardCoinType === "0x111ae3e5bc816a5e63c2da97d0aa3886519e0cd5e4b046659fa35796bd11542a::stapt_token::StakedApt"
16 |
17 | console.log({
18 | sender: agent.account.getAddress(),
19 | data: {
20 | function: "0x2fe576faa841347a9b1b32c869685deb75a15e3f62dfe37cbd6d52cc403a16f6::pool::claim_rewards",
21 | typeArguments: [
22 | isCoinTypeSTApt
23 | ? "0x111ae3e5bc816a5e63c2da97d0aa3886519e0cd5e4b046659fa35796bd11542a::amapt_token::AmnisApt"
24 | : "0x1::aptos_coin::AptosCoin",
25 | ],
26 | functionArguments: [coinReward, isCoinTypeSTApt ? "amAPTIncentives" : "APTIncentives"],
27 | },
28 | })
29 | const transaction = await agent.aptos.transaction.build.simple({
30 | sender: agent.account.getAddress(),
31 | data: {
32 | function: "0x2fe576faa841347a9b1b32c869685deb75a15e3f62dfe37cbd6d52cc403a16f6::pool::claim_rewards",
33 | typeArguments: [
34 | isCoinTypeSTApt
35 | ? "0x111ae3e5bc816a5e63c2da97d0aa3886519e0cd5e4b046659fa35796bd11542a::amapt_token::AmnisApt"
36 | : "0x1::aptos_coin::AptosCoin",
37 | ],
38 | functionArguments: [coinReward, isCoinTypeSTApt ? "amAPTIncentives" : "APTIncentives"],
39 | },
40 | })
41 |
42 | const committedTransactionHash = await agent.account.sendTransaction(transaction)
43 |
44 | const signedTransaction = await agent.aptos.waitForTransaction({
45 | transactionHash: committedTransactionHash,
46 | })
47 |
48 | if (!signedTransaction.success) {
49 | console.error(signedTransaction, "Claim rewards failed")
50 | throw new Error("Claim rewards failed")
51 | }
52 |
53 | return signedTransaction.hash
54 | } catch (error: any) {
55 | throw new Error(`Claim rewards failed: ${error.message}`)
56 | }
57 | }
58 |
--------------------------------------------------------------------------------
/src/tools/joule/index.ts:
--------------------------------------------------------------------------------
1 | export * from "./lend"
2 | export * from "./borrow"
3 | export * from "./repay"
4 | export * from "./withdraw"
5 | export * from "./pool-detail"
6 | export * from "./user-position"
7 | export * from "./user-all-positions"
8 | export * from "./claim-reward"
9 |
--------------------------------------------------------------------------------
/src/tools/joule/pool-detail.ts:
--------------------------------------------------------------------------------
1 | import type { AgentRuntime } from "../../agent"
2 |
3 | /**
4 | * Get details about a specific pool
5 | * @param agent MoveAgentKit instance
6 | * @param mint The Move struct ID of the token to get details for
7 | * @returns Pool details
8 | * @example
9 | * ```ts
10 | * const poolDetails = await getPoolDetails(agent, "0x1::aptos_coin::AptosCoin"); // For APT pool
11 | * const otherPoolDetails = await getPoolDetails(agent, otherCoinAddress); // For other token pool
12 | * ```
13 | */
14 | export async function getPoolDetails(agent: AgentRuntime, mint: string): Promise {
15 | try {
16 | const allPoolDetailsResponse = await fetch("https://price-api.joule.finance/api/market")
17 |
18 | const allPoolDetails = await allPoolDetailsResponse.json()
19 |
20 | const poolDetail = allPoolDetails.data.find((pool: any) => pool.asset.type.includes(mint))
21 |
22 | if (!poolDetail) {
23 | throw new Error("Pool not found")
24 | }
25 |
26 | return {
27 | assetName: poolDetail.asset.assetName,
28 | tokenAddress: mint,
29 | ltv: poolDetail.ltv,
30 | decimals: poolDetail.asset.decimals,
31 | marketSize: Number(poolDetail.marketSize) / poolDetail.asset.decimals,
32 | totalBorrowed: Number(poolDetail.totalBorrowed) / poolDetail.asset.decimals,
33 | depositApy: poolDetail.depositApy,
34 | extraDepositApy: poolDetail.extraAPY.depositAPY,
35 | borrowApy: poolDetail.borrowApy,
36 | price: poolDetail.priceInfo.price,
37 | }
38 | } catch (error: any) {
39 | throw new Error(`Failed to get pool details: ${error.message}`)
40 | }
41 | }
42 |
--------------------------------------------------------------------------------
/src/tools/joule/repay.ts:
--------------------------------------------------------------------------------
1 | import { AccountAddress, type InputGenerateTransactionPayloadData, type MoveStructId } from "@aptos-labs/ts-sdk"
2 | import type { AgentRuntime } from "../../agent"
3 |
4 | /**
5 | * Repay APT, tokens or fungible asset from a position
6 | * @param agent MoveAgentKit instance
7 | * @param amount Amount to mint
8 | * @param mint The Move struct ID of the token to repay
9 | * @param positionId The position ID to repay
10 | * @param fungibleAssetAddress The address of the fungible asset if the token is fungible (optional)
11 | * @returns Transaction signature and position ID
12 | * @example
13 | * ```ts
14 | * const transactionHash = await repayToken(agent, amount, APTOS_COIN, positionId); // For APT
15 | * const otherTransactionHash = await repayToken(agent, amount, OTHER_TOKEN, positionId); // For another token
16 | * const fungibleAssetTransactionHash = await repayToken(agent, amount, APTOS_COIN, positionId, fungibleAssetAddress); // For fungible asset
17 | */
18 | export async function repayToken(
19 | agent: AgentRuntime,
20 | amount: number,
21 | mint: MoveStructId,
22 | positionId: string,
23 | fungibleAsset: boolean
24 | ): Promise<{
25 | hash: string
26 | positionId: string
27 | }> {
28 | const DEFAULT_FUNCTIONAL_ARGS = [positionId, amount]
29 |
30 | const COIN_STANDARD_DATA: InputGenerateTransactionPayloadData = {
31 | function: "0x2fe576faa841347a9b1b32c869685deb75a15e3f62dfe37cbd6d52cc403a16f6::pool::repay",
32 | typeArguments: [mint.toString()],
33 | functionArguments: DEFAULT_FUNCTIONAL_ARGS,
34 | }
35 |
36 | const FUNGIBLE_ASSET_DATA: InputGenerateTransactionPayloadData = {
37 | function: "0x2fe576faa841347a9b1b32c869685deb75a15e3f62dfe37cbd6d52cc403a16f6::pool::repay_fa",
38 | functionArguments: [positionId, mint.toString(), amount],
39 | }
40 |
41 | try {
42 | const transaction = await agent.aptos.transaction.build.simple({
43 | sender: agent.account.getAddress(),
44 | data: fungibleAsset ? FUNGIBLE_ASSET_DATA : COIN_STANDARD_DATA,
45 | })
46 |
47 | const committedTransactionHash = await agent.account.sendTransaction(transaction)
48 |
49 | const signedTransaction = await agent.aptos.waitForTransaction({
50 | transactionHash: committedTransactionHash,
51 | })
52 |
53 | if (!signedTransaction.success) {
54 | console.error(signedTransaction, "Token repay failed")
55 | throw new Error("Token repay failed")
56 | }
57 |
58 | return {
59 | hash: signedTransaction.hash,
60 | positionId,
61 | }
62 | } catch (error: any) {
63 | throw new Error(`Token repay failed: ${error.message}`)
64 | }
65 | }
66 |
--------------------------------------------------------------------------------
/src/tools/joule/user-all-positions.ts:
--------------------------------------------------------------------------------
1 | import type { AccountAddress } from "@aptos-labs/ts-sdk"
2 | import type { AgentRuntime } from "../../agent"
3 | import { removeLastInterestRateIndex } from "../../utils/clean-joule-all-positions-list"
4 |
5 | /**
6 | * Get details about a user's all positions
7 | * @param agent MoveAgentKit instance
8 | * @param userAddress The address of the user
9 | * @returns List of user positions
10 | */
11 | export async function getUserAllPositions(agent: AgentRuntime, userAddress: AccountAddress | string): Promise {
12 | try {
13 | const transaction = await agent.aptos.view({
14 | payload: {
15 | function: "0x2fe576faa841347a9b1b32c869685deb75a15e3f62dfe37cbd6d52cc403a16f6::pool::user_positions_map",
16 | functionArguments: [userAddress.toString()],
17 | },
18 | })
19 |
20 | if (!transaction) {
21 | throw new Error("Failed to fetch user all positions")
22 | }
23 |
24 | // TODO : make the amounts human readable // sync with shivam for all view function
25 |
26 | const cleanedTransaction = removeLastInterestRateIndex(transaction)
27 |
28 | return cleanedTransaction
29 | } catch (error: any) {
30 | throw new Error(`Failed to get user all positions: ${error.message}`)
31 | }
32 | }
33 |
--------------------------------------------------------------------------------
/src/tools/joule/user-position.ts:
--------------------------------------------------------------------------------
1 | import type { AccountAddress } from "@aptos-labs/ts-sdk"
2 | import type { AgentRuntime } from "../../agent"
3 |
4 | /**
5 | * Get details about a user's position
6 | * @param agent MoveAgentKit instance
7 | * @param userAddress The address of the user
8 | * @param positionId The ID of the position to query
9 | * @returns Position details
10 | * @example
11 | * ```ts
12 | * const positionDetails = await getUserPosition(agent, userAddress, positionId);
13 | * ```
14 | */
15 | export async function getUserPosition(
16 | agent: AgentRuntime,
17 | userAddress: AccountAddress | string,
18 | positionId: string
19 | ): Promise {
20 | try {
21 | const transaction = await agent.aptos.view({
22 | payload: {
23 | function: "0x2fe576faa841347a9b1b32c869685deb75a15e3f62dfe37cbd6d52cc403a16f6::pool::user_position_details",
24 | functionArguments: [userAddress.toString(), positionId],
25 | },
26 | })
27 |
28 | if (!transaction) {
29 | throw new Error("Failed to fetch user position")
30 | }
31 |
32 | return transaction
33 | } catch (error: any) {
34 | throw new Error(`Failed to get user position: ${error.message}`)
35 | }
36 | }
37 |
--------------------------------------------------------------------------------
/src/tools/joule/withdraw.ts:
--------------------------------------------------------------------------------
1 | import { AccountAddress, type InputGenerateTransactionPayloadData, type MoveStructId } from "@aptos-labs/ts-sdk"
2 | import type { AgentRuntime } from "../../agent"
3 |
4 | /**
5 | * Withdraw APT, tokens or fungible asset from a position
6 | * @param agent MoveAgentKit instance
7 | * @param amount Amount to mint
8 | * @param mint The Move struct ID of the token to withdraw
9 | * @param positionId The position ID to withdraw from
10 | * @param fungibleAssetAddress The address of the fungible asset if the token is fungible (optional)
11 | * @returns Transaction signature and position ID
12 | * @example
13 | * ```ts
14 | * const transactionHash = await withdrawToken(agent, amount, APTOS_COIN, positionId); // For APT
15 | * const otherTransactionHash = await withdrawToken(agent, amount, OTHER_TOKEN, positionId); // For another token
16 | * const fungibleAssetTransactionHash = await withdrawToken(agent, amount, APTOS_COIN, positionId, fungibleAssetAddress); // For fungible asset
17 | */
18 | export async function withdrawToken(
19 | agent: AgentRuntime,
20 | amount: number,
21 | mint: MoveStructId,
22 | positionId: string,
23 | fungibleAsset: boolean
24 | ): Promise<{
25 | hash: string
26 | positionId: string
27 | }> {
28 | const pyth_update_data = await agent.getPythData()
29 |
30 | const DEFAULT_FUNCTIONAL_ARGS = [positionId, amount, pyth_update_data]
31 |
32 | const COIN_STANDARD_DATA: InputGenerateTransactionPayloadData = {
33 | function: "0x2fe576faa841347a9b1b32c869685deb75a15e3f62dfe37cbd6d52cc403a16f6::pool::withdraw",
34 | typeArguments: [mint.toString()],
35 | functionArguments: DEFAULT_FUNCTIONAL_ARGS,
36 | }
37 |
38 | const FUNGIBLE_ASSET_DATA: InputGenerateTransactionPayloadData = {
39 | function: "0x2fe576faa841347a9b1b32c869685deb75a15e3f62dfe37cbd6d52cc403a16f6::pool::withdraw_fa",
40 | functionArguments: [positionId, mint.toString(), amount, pyth_update_data],
41 | }
42 |
43 | try {
44 | const transaction = await agent.aptos.transaction.build.simple({
45 | sender: agent.account.getAddress(),
46 | data: fungibleAsset ? FUNGIBLE_ASSET_DATA : COIN_STANDARD_DATA,
47 | })
48 |
49 | const committedTransactionHash = await agent.account.sendTransaction(transaction)
50 |
51 | const signedTransaction = await agent.aptos.waitForTransaction({
52 | transactionHash: committedTransactionHash,
53 | })
54 |
55 | if (!signedTransaction.success) {
56 | console.error(signedTransaction, "Token withdraw failed")
57 | throw new Error("Token withdraw failed")
58 | }
59 |
60 | return {
61 | hash: signedTransaction.hash,
62 | positionId,
63 | }
64 | } catch (error: any) {
65 | throw new Error(`Token withdraw failed: ${error.message}`)
66 | }
67 | }
68 |
--------------------------------------------------------------------------------
/src/tools/liquidswap/add-liquidity.ts:
--------------------------------------------------------------------------------
1 | import type { MoveStructId } from "@aptos-labs/ts-sdk"
2 | import type { AgentRuntime } from "../../agent"
3 |
4 | /**
5 | * Add liquidity in liquidswap
6 | * @param agent MoveAgentKit instance
7 | * @param mintX MoveStructId of the first token
8 | * @param mintY MoveStructId of the second token
9 | * @param mintXAmount Amount of the first token to add
10 | * @param mintYAmount Amount of the second token to add
11 | * @returns Transaction signature
12 | */
13 | export async function addLiquidity(
14 | agent: AgentRuntime,
15 | mintX: MoveStructId,
16 | mintY: MoveStructId,
17 | mintXAmount: number,
18 | mintYAmount: number
19 | ): Promise {
20 | try {
21 | const transaction = await agent.aptos.transaction.build.simple({
22 | sender: agent.account.getAddress(),
23 | data: {
24 | function: "0x9dd974aea0f927ead664b9e1c295e4215bd441a9fb4e53e5ea0bf22f356c8a2b::router::add_liquidity_v05",
25 | typeArguments: [
26 | mintX,
27 | mintY,
28 | "0x163df34fccbf003ce219d3f1d9e70d140b60622cb9dd47599c25fb2f797ba6e::curves::Uncorrelated",
29 | ],
30 | functionArguments: [
31 | mintXAmount,
32 | 0, //coin_x_min,
33 | mintYAmount,
34 | 0, // coin_y_min
35 | ],
36 | },
37 | })
38 |
39 | const committedTransactionHash = await agent.account.sendTransaction(transaction)
40 |
41 | const signedTransaction = await agent.aptos.waitForTransaction({
42 | transactionHash: committedTransactionHash,
43 | })
44 |
45 | if (!signedTransaction.success) {
46 | console.error(signedTransaction, "Add liquidity failed")
47 | throw new Error("Add liquidity failed")
48 | }
49 |
50 | return signedTransaction.hash
51 | } catch (error: any) {
52 | console.error(error, "Add liquidity failed")
53 | throw new Error(`Add liquidity failed: ${error.message}`)
54 | }
55 | }
56 |
--------------------------------------------------------------------------------
/src/tools/liquidswap/create-pool.ts:
--------------------------------------------------------------------------------
1 | import type { MoveStructId } from "@aptos-labs/ts-sdk"
2 | import type { AgentRuntime } from "../../agent"
3 |
4 | /**
5 | * Create a new pool in liquidswap
6 | * @param agent MoveAgentKit instance
7 | * @param mintX MoveStructId of the first token
8 | * @param mintY MoveStructId of the second token
9 | * @returns Transaction signature
10 | */
11 | export async function createPool(agent: AgentRuntime, mintX: MoveStructId, mintY: MoveStructId): Promise {
12 | try {
13 | const transaction = await agent.aptos.transaction.build.simple({
14 | sender: agent.account.getAddress(),
15 | data: {
16 | function: "0x190d44266241744264b964a37b8f09863167a12d3e70cda39376cfb4e3561e12::scripts_v2::register_pool",
17 | typeArguments: [
18 | mintX,
19 | mintY,
20 | "0x190d44266241744264b964a37b8f09863167a12d3e70cda39376cfb4e3561e12::curves::Uncorrelated",
21 | ],
22 | functionArguments: [],
23 | },
24 | })
25 |
26 | const committedTransactionHash = await agent.account.sendTransaction(transaction)
27 |
28 | const signedTransaction = await agent.aptos.waitForTransaction({
29 | transactionHash: committedTransactionHash,
30 | })
31 |
32 | if (!signedTransaction.success) {
33 | console.error(signedTransaction, "Create pool failed")
34 | throw new Error("Create pool failed")
35 | }
36 |
37 | return signedTransaction.hash
38 | } catch (error: any) {
39 | throw new Error(`Create pool failed: ${error.message}`)
40 | }
41 | }
42 |
--------------------------------------------------------------------------------
/src/tools/liquidswap/index.ts:
--------------------------------------------------------------------------------
1 | export * from "./swap"
2 | export * from "./create-pool"
3 | export * from "./add-liquidity"
4 | export * from "./remove-liquidity"
5 |
--------------------------------------------------------------------------------
/src/tools/liquidswap/remove-liquidity.ts:
--------------------------------------------------------------------------------
1 | import type { MoveStructId } from "@aptos-labs/ts-sdk"
2 | import type { AgentRuntime } from "../../agent"
3 |
4 | /**
5 | * Remove liquidity from liquidswap
6 | * @param agent MoveAgentKit instance
7 | * @param mintX MoveStructId of the first token
8 | * @param mintY MoveStructId of the second token
9 | * @param lpAmount Amount of Liquidity Provider tokens to remove
10 | * @param minMintX Minimum amount of first token to receive (default 0)
11 | * @param minMintY Minimum amount of second token to receive (default 0)
12 | * @returns Transaction signature
13 | */
14 | export async function removeLiquidity(
15 | agent: AgentRuntime,
16 | mintX: MoveStructId,
17 | mintY: MoveStructId,
18 | lpAmount: number,
19 | minMintX = 0,
20 | minMintY = 0
21 | ): Promise {
22 | try {
23 | const transaction = await agent.aptos.transaction.build.simple({
24 | sender: agent.account.getAddress(),
25 | data: {
26 | function: "0x9dd974aea0f927ead664b9e1c295e4215bd441a9fb4e53e5ea0bf22f356c8a2b::router::remove_liquidity_v05",
27 | typeArguments: [
28 | mintX,
29 | mintY,
30 | "0x163df34fccbf003ce219d3f1d9e70d140b60622cb9dd47599c25fb2f797ba6e::curves::Uncorrelated",
31 | ],
32 | functionArguments: [lpAmount, minMintX, minMintY],
33 | },
34 | })
35 |
36 | const committedTransactionHash = await agent.account.sendTransaction(transaction)
37 |
38 | const signedTransaction = await agent.aptos.waitForTransaction({
39 | transactionHash: committedTransactionHash,
40 | })
41 |
42 | if (!signedTransaction.success) {
43 | console.error(signedTransaction, "Remove liquidity failed")
44 | throw new Error("Remove liquidity failed")
45 | }
46 |
47 | return signedTransaction.hash
48 | } catch (error: any) {
49 | throw new Error(`Remove liquidity failed: ${error.message}`)
50 | }
51 | }
52 |
--------------------------------------------------------------------------------
/src/tools/liquidswap/swap.ts:
--------------------------------------------------------------------------------
1 | import { type MoveStructId, convertAmountFromHumanReadableToOnChain } from "@aptos-labs/ts-sdk"
2 | import type { AgentRuntime } from "../../agent"
3 |
4 | /**
5 | * Swap tokens in liquidswap
6 | * @param agent MoveAgentKit instance
7 | * @param mintX MoveStructId of the token to swap from
8 | * @param mintY MoveStructId of the token to swap to
9 | * @param swapAmount Amount of tokens to swap
10 | * @param minCoinOut Minimum amount of tokens to receive (default 0)
11 | * @returns Transaction signature
12 | */
13 | export async function swap(
14 | agent: AgentRuntime,
15 | mintX: MoveStructId,
16 | mintY: MoveStructId,
17 | swapAmount: number,
18 | minCoinOut = 0
19 | ): Promise {
20 | try {
21 | const transaction = await agent.aptos.transaction.build.simple({
22 | sender: agent.account.getAddress(),
23 | data: {
24 | function: "0x190d44266241744264b964a37b8f09863167a12d3e70cda39376cfb4e3561e12::scripts_v2::swap",
25 | typeArguments: [
26 | mintX,
27 | mintY,
28 | "0x190d44266241744264b964a37b8f09863167a12d3e70cda39376cfb4e3561e12::curves::Uncorrelated",
29 | ],
30 | functionArguments: [swapAmount, minCoinOut],
31 | },
32 | })
33 |
34 | const committedTransactionHash = await agent.account.sendTransaction(transaction)
35 |
36 | const signedTransaction = await agent.aptos.waitForTransaction({
37 | transactionHash: committedTransactionHash,
38 | })
39 |
40 | if (!signedTransaction.success) {
41 | console.error(signedTransaction, "Swap failed")
42 | throw new Error("Swap failed")
43 | }
44 |
45 | return signedTransaction.hash
46 | } catch (error: any) {
47 | throw new Error(`Swap failed: ${error.message}`)
48 | }
49 | }
50 |
--------------------------------------------------------------------------------
/src/tools/merkletrade/close-position.ts:
--------------------------------------------------------------------------------
1 | import { MerkleClient, MerkleClientConfig } from "@merkletrade/ts-sdk"
2 | import type { AgentRuntime } from "../../agent"
3 | import { FailedSendTransactionError, MerkleBaseError, PositionNotFoundError } from "./error"
4 |
5 | /**
6 | * Close position on MerkleTrade
7 | * @param agent MoveAgentKit instance
8 | * @param pair Pair ID, e.g. "BTC_USD"
9 | * @param isLong True for long, false for short
10 | * @returns Transaction signature
11 | */
12 | export async function closePositionWithMerkleTrade(agent: AgentRuntime, pair: string, isLong: boolean) {
13 | try {
14 | const merkle = new MerkleClient(await MerkleClientConfig.mainnet())
15 |
16 | const positions = await merkle.getPositions({
17 | address: agent.account.getAddress().toString(),
18 | })
19 |
20 | const position = positions.find((position) => position.pairType === pair && position.isLong === isLong)
21 | if (!position) {
22 | throw new PositionNotFoundError(pair, isLong, "Position not found")
23 | }
24 |
25 | const payload = merkle.payloads.placeMarketOrder({
26 | pair: pair,
27 | userAddress: agent.account.getAddress(),
28 | sizeDelta: position.size,
29 | collateralDelta: position.collateral,
30 | isLong: position.isLong,
31 | isIncrease: false,
32 | })
33 |
34 | const transaction = await agent.aptos.transaction.build.simple({
35 | sender: agent.account.getAddress(),
36 | data: payload,
37 | })
38 |
39 | const txhash = await agent.account.sendTransaction(transaction)
40 |
41 | const signedTransaction = await agent.aptos.waitForTransaction({
42 | transactionHash: txhash,
43 | })
44 |
45 | if (!signedTransaction.success) {
46 | throw new FailedSendTransactionError("Close position failed", signedTransaction)
47 | }
48 |
49 | return signedTransaction.hash
50 | } catch (error: any) {
51 | if (error instanceof MerkleBaseError) {
52 | throw error
53 | }
54 | throw new Error(`Close position failed: ${error.message}`)
55 | }
56 | }
57 |
--------------------------------------------------------------------------------
/src/tools/merkletrade/error.ts:
--------------------------------------------------------------------------------
1 | import type { CommittedTransactionResponse } from "@aptos-labs/ts-sdk"
2 |
3 | export class MerkleBaseError extends Error {
4 | readonly code: string
5 | readonly status: string
6 |
7 | constructor(status: string, code: string, message: string) {
8 | super(message)
9 | this.code = code
10 | this.status = status
11 |
12 | Object.setPrototypeOf(this, MerkleBaseError.prototype)
13 | }
14 | }
15 |
16 | export class PositionNotFoundError extends MerkleBaseError {
17 | readonly pair: string
18 | readonly isLong: boolean
19 |
20 | constructor(pair: string, isLong: boolean, message: string) {
21 | super("error", "POSITION_NOT_FOUND", message)
22 | this.pair = pair
23 | this.isLong = isLong
24 | }
25 | }
26 |
27 | export class FailedSendTransactionError extends MerkleBaseError {
28 | readonly tx: CommittedTransactionResponse
29 | constructor(message: string, tx: CommittedTransactionResponse) {
30 | super("error", "FAILED_SEND_TRANSACTION", message)
31 | this.tx = tx
32 | }
33 | }
34 |
--------------------------------------------------------------------------------
/src/tools/merkletrade/get-positions.ts:
--------------------------------------------------------------------------------
1 | import { MerkleClient, MerkleClientConfig, toNumber } from "@merkletrade/ts-sdk"
2 | import type { AgentRuntime } from "../../agent"
3 |
4 | /**
5 | * Get positions from MerkleTrade
6 | * @param agent MoveAgentKit instance
7 | * @returns Positions
8 | */
9 | export async function getPositionsWithMerkleTrade(agent: AgentRuntime) {
10 | try {
11 | const merkle = new MerkleClient(await MerkleClientConfig.mainnet())
12 |
13 | const positions = await merkle.getPositions({
14 | address: agent.account.getAddress().toString(),
15 | })
16 |
17 | const humanReadablePositions = positions.map((position) => ({
18 | ...position,
19 | size: toNumber(position.size, 6),
20 | collateral: toNumber(position.collateral, 6),
21 | avgPrice: toNumber(position.avgPrice, 10),
22 | stopLossTriggerPrice: toNumber(position.stopLossTriggerPrice, 10),
23 | takeProfitTriggerPrice: toNumber(position.takeProfitTriggerPrice, 10),
24 | }))
25 |
26 | return humanReadablePositions
27 | } catch (error: any) {
28 | throw new Error(`Get positions failed: ${error.message}`)
29 | }
30 | }
31 |
--------------------------------------------------------------------------------
/src/tools/merkletrade/index.ts:
--------------------------------------------------------------------------------
1 | export * from "./place-limit-order"
2 | export * from "./place-market-order"
3 | export * from "./close-position"
4 | export * from "./get-positions"
5 |
--------------------------------------------------------------------------------
/src/tools/merkletrade/place-limit-order.ts:
--------------------------------------------------------------------------------
1 | import { MerkleClient, MerkleClientConfig, fromNumber } from "@merkletrade/ts-sdk"
2 | import type { AgentRuntime } from "../../agent"
3 | import { FailedSendTransactionError, MerkleBaseError } from "./error"
4 |
5 | /**
6 | * Place limit order on MerkleTrade
7 | * @param agent MoveAgentKit instance
8 | * @param pair Pair ID, e.g. "BTC_USD"
9 | * @param isLong True for long, false for short
10 | * @param sizeDelta Amount of tokens to buy/sell (in USDC, 10 USDC = 10)
11 | * @param collateralDelta Amount of collateral to buy/sell (in USDC, 10 USDC = 10)
12 | * @param price Price of the order (in USD)
13 | * @returns Transaction signature
14 | */
15 | export async function placeLimitOrderWithMerkleTrade(
16 | agent: AgentRuntime,
17 | pair: string,
18 | isLong: boolean,
19 | sizeDelta: number, // in USDC
20 | collateralDelta: number, // in USDC
21 | price: number // in USD
22 | ) {
23 | try {
24 | const merkle = new MerkleClient(await MerkleClientConfig.mainnet())
25 |
26 | const payload = merkle.payloads.placeLimitOrder({
27 | pair: pair,
28 | userAddress: agent.account.getAddress(),
29 | sizeDelta: fromNumber(sizeDelta, 6),
30 | collateralDelta: fromNumber(collateralDelta, 6),
31 | price: fromNumber(price, 10),
32 | isLong: isLong,
33 | isIncrease: true,
34 | })
35 |
36 | const transaction = await agent.aptos.transaction.build.simple({
37 | sender: agent.account.getAddress(),
38 | data: payload,
39 | })
40 |
41 | const txhash = await agent.account.sendTransaction(transaction)
42 |
43 | const signedTransaction = await agent.aptos.waitForTransaction({
44 | transactionHash: txhash,
45 | })
46 |
47 | if (!signedTransaction.success) {
48 | throw new FailedSendTransactionError("Place limit order failed", signedTransaction)
49 | }
50 |
51 | return signedTransaction.hash
52 | } catch (error: any) {
53 | if (error instanceof MerkleBaseError) {
54 | throw error
55 | }
56 | throw new Error(`Place market order failed: ${error.message}`)
57 | }
58 | }
59 |
--------------------------------------------------------------------------------
/src/tools/merkletrade/place-market-order.ts:
--------------------------------------------------------------------------------
1 | import { MerkleClient, MerkleClientConfig, fromNumber } from "@merkletrade/ts-sdk"
2 | import type { AgentRuntime } from "../../agent"
3 | import { FailedSendTransactionError, MerkleBaseError } from "./error"
4 |
5 | /**
6 | * Place market order on MerkleTrade
7 | * @param agent MoveAgentKit instance
8 | * @param pair Pair ID, e.g. "BTC_USD"
9 | * @param isLong True for long, false for short
10 | * @param sizeDelta Amount of tokens to buy/sell (in USDC, 10 USDC = 10)
11 | * @param collateralDelta Amount of collateral to buy/sell (in USDC, 10 USDC = 10)
12 | * @returns Transaction signature
13 | */
14 | export async function placeMarketOrderWithMerkleTrade(
15 | agent: AgentRuntime,
16 | pair: string,
17 | isLong: boolean,
18 | sizeDelta: number, // in USDC
19 | collateralDelta: number // in USDC
20 | ) {
21 | try {
22 | const merkle = new MerkleClient(await MerkleClientConfig.mainnet())
23 |
24 | const payload = merkle.payloads.placeMarketOrder({
25 | pair: pair,
26 | userAddress: agent.account.getAddress(),
27 | sizeDelta: fromNumber(sizeDelta, 6),
28 | collateralDelta: fromNumber(collateralDelta, 6),
29 | isLong: isLong,
30 | isIncrease: true,
31 | })
32 |
33 | const transaction = await agent.aptos.transaction.build.simple({
34 | sender: agent.account.getAddress(),
35 | data: payload,
36 | })
37 |
38 | const txhash = await agent.account.sendTransaction(transaction)
39 |
40 | const signedTransaction = await agent.aptos.waitForTransaction({
41 | transactionHash: txhash,
42 | })
43 |
44 | if (!signedTransaction.success) {
45 | throw new FailedSendTransactionError("Place market order failed", signedTransaction)
46 | }
47 |
48 | return signedTransaction.hash
49 | } catch (error: any) {
50 | if (error instanceof MerkleBaseError) {
51 | throw error
52 | }
53 | throw new Error(`Place market order failed: ${error.message}`)
54 | }
55 | }
56 |
--------------------------------------------------------------------------------
/src/tools/openai/create-image.ts:
--------------------------------------------------------------------------------
1 | import OpenAI from "openai"
2 | import type { AgentRuntime } from "../../agent"
3 |
4 | /**
5 | * Generate an image using OpenAI's DALL-E
6 | * @param agent MoveAgentKit instance
7 | * @param prompt Text description of the image to generate
8 | * @param size Image size ('256x256', '512x512', or '1024x1024') (default: '1024x1024')
9 | * @param n Number of images to generate (default: 1)
10 | * @returns Object containing the generated image URLs
11 | */
12 | export async function createImage(
13 | agent: AgentRuntime,
14 | prompt: string,
15 | size: "256x256" | "512x512" | "1024x1024" = "1024x1024",
16 | n = 1
17 | ) {
18 | try {
19 | const apiKey = agent.config.OPENAI_API_KEY
20 | if (!apiKey) {
21 | throw new Error("No OPENAI_API_KEY in config")
22 | }
23 |
24 | const openai = new OpenAI({ apiKey })
25 |
26 | const response = await openai.images.generate({
27 | prompt,
28 | n,
29 | size,
30 | })
31 |
32 | return {
33 | images: response.data.map((img: any) => img.url),
34 | }
35 | } catch (error: any) {
36 | throw new Error(`Image generation failed: ${error.message}`)
37 | }
38 | }
39 |
--------------------------------------------------------------------------------
/src/tools/openai/index.ts:
--------------------------------------------------------------------------------
1 | export * from "./create-image"
2 |
--------------------------------------------------------------------------------
/src/tools/panora/index.ts:
--------------------------------------------------------------------------------
1 | export * from "./swap"
2 |
--------------------------------------------------------------------------------
/src/tools/panora/swap.ts:
--------------------------------------------------------------------------------
1 | import axios from "axios"
2 | import type { AgentRuntime } from "../../agent"
3 |
4 | /**
5 | * Swap tokens in panora
6 | * @param agent MoveAgentKit instance
7 | * @param fromToken Address of the token to swap from
8 | * @param toToken Address of the token to swap to
9 | * @param swapAmount Amount of tokens to swap
10 | * @param minCoinOut Minimum amount of tokens to receive (default 0)
11 | * @returns Transaction signature
12 | */
13 | export async function swapWithPanora(
14 | agent: AgentRuntime,
15 | fromToken: string,
16 | toToken: string,
17 | swapAmount: number,
18 | toWalletAddress?: string
19 | ): Promise {
20 | try {
21 | const panoraParameters = {
22 | fromTokenAddress: fromToken,
23 | toTokenAddress: toToken,
24 | fromTokenAmount: swapAmount.toString(),
25 | toWalletAddress: toWalletAddress ? toWalletAddress : agent.account.getAddress().toString(),
26 | }
27 |
28 | const url = `https://api.panora.exchange/swap?${new URLSearchParams(panoraParameters).toString()}`
29 |
30 | const panoraApiKey = agent.config.PANORA_API_KEY
31 | if (!panoraApiKey) {
32 | throw new Error("No PANORA_API_KEY in config")
33 | }
34 |
35 | const res = await axios.post(
36 | url,
37 | {},
38 | {
39 | headers: {
40 | "x-api-key": panoraApiKey,
41 | },
42 | }
43 | )
44 | const response = await res.data
45 |
46 | if (response.quotes.length <= 0) {
47 | throw new Error("no quotes available from panora")
48 | }
49 |
50 | const transactionData = response.quotes[0].txData
51 |
52 | const transaction = await agent.aptos.transaction.build.simple({
53 | sender: agent.account.getAddress(),
54 | data: {
55 | function: transactionData.function,
56 | typeArguments: transactionData.type_arguments,
57 | functionArguments: transactionData.arguments,
58 | },
59 | })
60 |
61 | const committedTransactionHash = await agent.account.sendTransaction(transaction)
62 |
63 | const signedTransaction = await agent.aptos.waitForTransaction({
64 | transactionHash: committedTransactionHash,
65 | })
66 |
67 | if (!signedTransaction.success) {
68 | console.error(signedTransaction, "Swap failed")
69 | throw new Error("Swap tx failed")
70 | }
71 |
72 | return signedTransaction.hash
73 | } catch (error: any) {
74 | throw new Error(`Swap failed: ${error.message}`)
75 | }
76 | }
77 |
--------------------------------------------------------------------------------
/src/tools/thala/add-liquidity.ts:
--------------------------------------------------------------------------------
1 | import type { MoveStructId } from "@aptos-labs/ts-sdk"
2 | import type { AgentRuntime } from "../../agent"
3 |
4 | /**
5 | * Add liquidity to Thala pool
6 | * @param agent MoveAgentKit instance
7 | * @param mintTypeX First coin type
8 | * @param mintTypeY Second coin type
9 | * @param mintXAmount Amount of first coin
10 | * @param mintYAmount Amount of second coin
11 | * @returns Transaction signature
12 | */
13 | export async function addLiquidityWithThala(
14 | agent: AgentRuntime,
15 | mintTypeX: MoveStructId,
16 | mintTypeY: MoveStructId,
17 | mintXAmount: number,
18 | mintYAmount: number
19 | ): Promise {
20 | try {
21 | const transaction = await agent.aptos.transaction.build.simple({
22 | sender: agent.account.getAddress(),
23 | data: {
24 | function:
25 | "0x48271d39d0b05bd6efca2278f22277d6fcc375504f9839fd73f74ace240861af::weighted_pool_scripts::add_liquidity",
26 | typeArguments: [
27 | mintTypeX,
28 | mintTypeY,
29 | "0x48271d39d0b05bd6efca2278f22277d6fcc375504f9839fd73f74ace240861af::base_pool::Null",
30 | "0x48271d39d0b05bd6efca2278f22277d6fcc375504f9839fd73f74ace240861af::base_pool::Null",
31 | "0x48271d39d0b05bd6efca2278f22277d6fcc375504f9839fd73f74ace240861af::weighted_pool::Weight_50",
32 | "0x48271d39d0b05bd6efca2278f22277d6fcc375504f9839fd73f74ace240861af::weighted_pool::Weight_50",
33 | "0x48271d39d0b05bd6efca2278f22277d6fcc375504f9839fd73f74ace240861af::base_pool::Null",
34 | "0x48271d39d0b05bd6efca2278f22277d6fcc375504f9839fd73f74ace240861af::base_pool::Null",
35 | ],
36 | functionArguments: [mintXAmount, mintYAmount, 0, 0, 0, 0, 0, 0],
37 | },
38 | })
39 |
40 | const committedTransactionHash = await agent.account.sendTransaction(transaction)
41 |
42 | const signedTransaction = await agent.aptos.waitForTransaction({
43 | transactionHash: committedTransactionHash,
44 | })
45 |
46 | if (!signedTransaction.success) {
47 | console.error(signedTransaction, "Add liquidity failed")
48 | throw new Error("Add liquidity failed")
49 | }
50 |
51 | return signedTransaction.hash
52 | } catch (error: any) {
53 | throw new Error(`Add liquidity failed: ${error.message}`)
54 | }
55 | }
56 |
--------------------------------------------------------------------------------
/src/tools/thala/create-pool.ts:
--------------------------------------------------------------------------------
1 | import type { MoveStructId } from "@aptos-labs/ts-sdk"
2 | import type { AgentRuntime } from "../../agent"
3 |
4 | /**
5 | * Create a new pool in Thala
6 | * @param agent MoveAgentKit instance
7 | * @param mintX First coin type or FA address
8 | * @param mintY Second coin type or FA address
9 | * @param amountX Amount of first coin
10 | * @param amountY Amount of second coin
11 | * @param options Pool creation options
12 | * @returns Transaction signature
13 | */
14 |
15 | const NOTACOIN = "0x007730cd28ee1cdc9e999336cbc430f99e7c44397c0aa77516f6f23a78559bb5::coin_wrapper::Notacoin"
16 | export async function createPoolWithThala(
17 | agent: AgentRuntime,
18 | mintX: MoveStructId | string,
19 | mintY: MoveStructId | string,
20 | amountX: number,
21 | amountY: number,
22 | feeTier: number,
23 | amplificationFactor: number
24 | ): Promise {
25 | try {
26 | const isCoinX = mintX === "0x1::aptos_coin::AptosCoin" || mintX.includes("::")
27 | const isCoinY = mintY === "0x1::aptos_coin::AptosCoin" || mintY.includes("::")
28 |
29 | const functionArgs = [
30 | [isCoinX ? "0xa" : mintX, isCoinY ? "0xa" : mintY],
31 | [amountX, amountY],
32 | feeTier,
33 | amplificationFactor,
34 | ]
35 |
36 | const typeArgs = [isCoinX ? mintX : NOTACOIN, isCoinY ? mintY : NOTACOIN, NOTACOIN, NOTACOIN, NOTACOIN, NOTACOIN]
37 |
38 | const transaction = await agent.aptos.transaction.build.simple({
39 | sender: agent.account.getAddress(),
40 | data: {
41 | function:
42 | "0x007730cd28ee1cdc9e999336cbc430f99e7c44397c0aa77516f6f23a78559bb5::coin_wrapper::create_pool_stable",
43 | typeArguments: typeArgs,
44 | functionArguments: functionArgs,
45 | },
46 | })
47 |
48 | const committedTransactionHash = await agent.account.sendTransaction(transaction)
49 |
50 | const signedTransaction = await agent.aptos.waitForTransaction({
51 | transactionHash: committedTransactionHash,
52 | })
53 |
54 | if (!signedTransaction.success) {
55 | console.error(signedTransaction, "Create pool failed")
56 | throw new Error("Create pool failed")
57 | }
58 |
59 | return signedTransaction.hash
60 | } catch (error: any) {
61 | throw new Error(`Create pool failed: ${error.message}`)
62 | }
63 | }
64 |
--------------------------------------------------------------------------------
/src/tools/thala/index.ts:
--------------------------------------------------------------------------------
1 | export * from "./stake"
2 | export * from "./unstake"
3 | export * from "./mint-mod"
4 | export * from "./redeem-mod"
5 | export * from "./add-liquidity"
6 | export * from "./remove-liquidity"
7 | export * from "./create-pool"
8 |
--------------------------------------------------------------------------------
/src/tools/thala/mint-mod.ts:
--------------------------------------------------------------------------------
1 | import type { MoveStructId } from "@aptos-labs/ts-sdk"
2 | import type { AgentRuntime } from "../../agent"
3 |
4 | /**
5 | * Mint Move Dollar in Thala
6 | * @param agent MoveAgentKit instance
7 | * @param mintType Type of coin to mint MOD with
8 | * @param amount Amount to mint
9 | * @returns Transaction signature
10 | */
11 | export async function mintMODWithThala(agent: AgentRuntime, mintType: MoveStructId, amount: number): Promise {
12 | try {
13 | const transaction = await agent.aptos.transaction.build.simple({
14 | sender: agent.account.getAddress(),
15 | data: {
16 | function: "0x6f986d146e4a90b828d8c12c14b6f4e003fdff11a8eecceceb63744363eaac01::psm_scripts::mint",
17 | typeArguments: [mintType],
18 | functionArguments: [amount],
19 | },
20 | })
21 |
22 | const committedTransactionHash = await agent.account.sendTransaction(transaction)
23 |
24 | const signedTransaction = await agent.aptos.waitForTransaction({
25 | transactionHash: committedTransactionHash,
26 | })
27 |
28 | if (!signedTransaction.success) {
29 | console.error(signedTransaction, "Mint MOD failed")
30 | throw new Error("Mint MOD failed")
31 | }
32 |
33 | return signedTransaction.hash
34 | } catch (error: any) {
35 | throw new Error(`Mint MOD failed: ${error.message}`)
36 | }
37 | }
38 |
--------------------------------------------------------------------------------
/src/tools/thala/redeem-mod.ts:
--------------------------------------------------------------------------------
1 | import type { MoveStructId } from "@aptos-labs/ts-sdk"
2 | import type { AgentRuntime } from "../../agent"
3 |
4 | /**
5 | * Redeem MOD in Thala
6 | * @param agent MoveAgentKit instance
7 | * @param mintType Type of coin to redeem MOD for
8 | * @param amount Amount to redeem
9 | * @returns Transaction signature
10 | */
11 | export async function redeemMODWithThala(agent: AgentRuntime, mintType: MoveStructId, amount: number): Promise {
12 | try {
13 | const transaction = await agent.aptos.transaction.build.simple({
14 | sender: agent.account.getAddress(),
15 | data: {
16 | function: "0x6f986d146e4a90b828d8c12c14b6f4e003fdff11a8eecceceb63744363eaac01::psm_scripts::redeem",
17 | typeArguments: [mintType],
18 | functionArguments: [amount],
19 | },
20 | })
21 |
22 | const committedTransactionHash = await agent.account.sendTransaction(transaction)
23 |
24 | const signedTransaction = await agent.aptos.waitForTransaction({
25 | transactionHash: committedTransactionHash,
26 | })
27 |
28 | if (!signedTransaction.success) {
29 | console.error(signedTransaction, "Redeem MOD failed")
30 | throw new Error("Redeem MOD failed")
31 | }
32 |
33 | return signedTransaction.hash
34 | } catch (error: any) {
35 | throw new Error(`Redeem MOD failed: ${error.message}`)
36 | }
37 | }
38 |
--------------------------------------------------------------------------------
/src/tools/thala/remove-liquidity.ts:
--------------------------------------------------------------------------------
1 | import type { MoveStructId } from "@aptos-labs/ts-sdk"
2 | import type { AgentRuntime } from "../../agent"
3 |
4 | /**
5 | * Remove liquidity from Thala pool
6 | * @param agent MoveAgentKit instance
7 | * @param mintTypeX First coin type
8 | * @param mintTypeY Second coin type
9 | * @param lpAmount Amount of LP tokens to remove
10 | * @returns Transaction signature
11 | */
12 | export async function removeLiquidityWithThala(
13 | agent: AgentRuntime,
14 | mintTypeX: MoveStructId,
15 | mintTypeY: MoveStructId,
16 | lpAmount: number
17 | ): Promise {
18 | try {
19 | const transaction = await agent.aptos.transaction.build.simple({
20 | sender: agent.account.getAddress(),
21 | data: {
22 | function:
23 | "0x48271d39d0b05bd6efca2278f22277d6fcc375504f9839fd73f74ace240861af::weighted_pool_scripts::remove_liquidity",
24 | typeArguments: [
25 | mintTypeX,
26 | mintTypeY,
27 | "0x48271d39d0b05bd6efca2278f22277d6fcc375504f9839fd73f74ace240861af::base_pool::Null",
28 | "0x48271d39d0b05bd6efca2278f22277d6fcc375504f9839fd73f74ace240861af::base_pool::Null",
29 | "0x48271d39d0b05bd6efca2278f22277d6fcc375504f9839fd73f74ace240861af::weighted_pool::Weight_50",
30 | "0x48271d39d0b05bd6efca2278f22277d6fcc375504f9839fd73f74ace240861af::weighted_pool::Weight_50",
31 | "0x48271d39d0b05bd6efca2278f22277d6fcc375504f9839fd73f74ace240861af::base_pool::Null",
32 | "0x48271d39d0b05bd6efca2278f22277d6fcc375504f9839fd73f74ace240861af::base_pool::Null",
33 | ],
34 | functionArguments: [lpAmount, 0, 0, 0, 0],
35 | },
36 | })
37 |
38 | const committedTransactionHash = await agent.account.sendTransaction(transaction)
39 |
40 | const signedTransaction = await agent.aptos.waitForTransaction({
41 | transactionHash: committedTransactionHash,
42 | })
43 |
44 | if (!signedTransaction.success) {
45 | console.error(signedTransaction, "Remove liquidity failed")
46 | throw new Error("Remove liquidity failed")
47 | }
48 |
49 | return signedTransaction.hash
50 | } catch (error: any) {
51 | throw new Error(`Remove liquidity failed: ${error.message}`)
52 | }
53 | }
54 |
--------------------------------------------------------------------------------
/src/tools/thala/stake.ts:
--------------------------------------------------------------------------------
1 | import type { AgentRuntime } from "../../agent"
2 |
3 | /**
4 | * Stake tokens in Thala
5 | * @param agent MoveAgentKit instance
6 | * @param amount Amount of token to stake
7 | * @returns Transaction signature
8 | */
9 | export async function stakeTokenWithThala(agent: AgentRuntime, amount: number): Promise {
10 | try {
11 | const transaction = await agent.aptos.transaction.build.simple({
12 | sender: agent.account.getAddress(),
13 | data: {
14 | function: "0xfaf4e633ae9eb31366c9ca24214231760926576c7b625313b3688b5e900731f6::scripts::stake_APT_and_thAPT",
15 | functionArguments: [amount],
16 | },
17 | })
18 |
19 | const committedTransactionHash = await agent.account.sendTransaction(transaction)
20 |
21 | const signedTransaction = await agent.aptos.waitForTransaction({
22 | transactionHash: committedTransactionHash,
23 | })
24 |
25 | if (!signedTransaction.success) {
26 | console.error(signedTransaction, "Stake APT failed")
27 | throw new Error("Stake APT failed")
28 | }
29 |
30 | return signedTransaction.hash
31 | } catch (error: any) {
32 | throw new Error(`Stake APT failed: ${error.message}`)
33 | }
34 | }
35 |
--------------------------------------------------------------------------------
/src/tools/thala/unstake.ts:
--------------------------------------------------------------------------------
1 | import type { AgentRuntime } from "../../agent"
2 |
3 | /**
4 | * Unstake tokens in Thala
5 | * @param agent MoveAgentKit instance
6 | * @param amount Amount of APT to unstake
7 | * @returns Transaction signature
8 | */
9 | export async function unstakeAPTWithThala(agent: AgentRuntime, amount: number): Promise {
10 | try {
11 | const transaction = await agent.aptos.transaction.build.simple({
12 | sender: agent.account.getAddress(),
13 | data: {
14 | function: "0xfaf4e633ae9eb31366c9ca24214231760926576c7b625313b3688b5e900731f6::scripts::unstake_thAPT",
15 | functionArguments: [amount],
16 | },
17 | })
18 |
19 | const committedTransactionHash = await agent.account.sendTransaction(transaction)
20 |
21 | const signedTransaction = await agent.aptos.waitForTransaction({
22 | transactionHash: committedTransactionHash,
23 | })
24 |
25 | if (!signedTransaction.success) {
26 | console.error(signedTransaction, "Unstake token failed")
27 | throw new Error("Unstake token failed")
28 | }
29 |
30 | return signedTransaction.hash
31 | } catch (error: any) {
32 | throw new Error(`Unstake token failed: ${error.message}`)
33 | }
34 | }
35 |
--------------------------------------------------------------------------------
/src/types/action.ts:
--------------------------------------------------------------------------------
1 | import type { z } from "zod"
2 |
3 | /**
4 | * Example of an action with input and output
5 | */
6 | export interface ActionExample {
7 | input: Record
8 | output: Record
9 | explanation: string
10 | }
11 |
12 | /**
13 | * Handler function type for executing the action
14 | */
15 | export type Handler = (
16 | agent: any, // Replace with the actual type of the move-agent
17 | input: Record
18 | ) => Promise>
19 |
20 | /**
21 | * Main Action interface inspired by Solana Agent Kit
22 | * This interface makes it easier to implement actions across different frameworks
23 | */
24 | export interface Action {
25 | /**
26 | * Unique name of the action
27 | */
28 | name: string
29 |
30 | /**
31 | * Alternative names/phrases that can trigger this action
32 | */
33 | similes: string[]
34 |
35 | /**
36 | * Detailed description of what the action does
37 | */
38 | description: string
39 |
40 | /**
41 | * Array of example inputs and outputs for the action
42 | * Each inner array represents a group of related examples
43 | */
44 | examples: ActionExample[][]
45 |
46 | /**
47 | * Zod schema for input validation
48 | */
49 | schema: z.ZodType
50 |
51 | /**
52 | * Function that executes the action
53 | */
54 | handler: Handler
55 | }
56 |
--------------------------------------------------------------------------------
/src/types/index.ts:
--------------------------------------------------------------------------------
1 | import type { AccountAuthenticator } from "@aptos-labs/ts-sdk"
2 |
3 | export type ToolsNameList =
4 | | "aptos_balance"
5 | | "aptos_get_wallet_address"
6 | | "aptos_transfer_token"
7 | | "aptos_burn_token"
8 | | "aptos_get_transaction"
9 | | "aptos_token_details"
10 | | "aptos_mint_token"
11 | | "aptos_create_token"
12 | | "amnis_stake"
13 | | "amnis_withdraw_stake"
14 | | "joule_lend_token"
15 | | "joule_withdraw_token"
16 | | "joule_borrow_token"
17 | | "joule_repay_token"
18 | | "joule_get_pool_details"
19 | | "joule_get_user_position"
20 | | "joule_get_user_all_positions"
21 | | "liquidswap_add_liquidity"
22 | | "liquidswap_create_pool"
23 | | "liquidswap_remove_liquidity"
24 | | "liquidswap_swap"
25 | | "aries_create_profile"
26 | | "aries_withdraw"
27 | | "aries_borrow"
28 | | "aries_lend"
29 | | "aries_repay"
30 | | "thala_add_liquidity"
31 | | "thala_remove_liquidity"
32 | | "thala_mint_mod"
33 | | "thala_redeem_mod"
34 | | "thala_unstake_token"
35 | | "thala_stake_token"
36 | | "panora_aggregator_swap"
37 | | "openai_create_image"
38 | | "echo_stake_token"
39 | | "echo_unstake_token"
40 | | "echelon_lend_token"
41 | | "echelon_withdraw_token"
42 | | "echelon_borrow_token"
43 | | "echelon_repay_token"
44 | | "merkle_trade_place_market_order"
45 | | "merkle_trade_place_limit_order"
46 | | "merkle_trade_close_position"
47 | | "merkle_trade_get_position"
48 |
49 | export type SignedTransactionResponse = {
50 | senderAuthenticator?: AccountAuthenticator
51 | signature?: Uint8Array
52 | }
53 |
--------------------------------------------------------------------------------
/src/utils/clean-joule-all-positions-list.ts:
--------------------------------------------------------------------------------
1 | export const removeLastInterestRateIndex = (obj: any): any => {
2 | if (!obj || typeof obj !== "object") {
3 | return obj
4 | }
5 |
6 | if (Array.isArray(obj)) {
7 | return obj.map((item) => removeLastInterestRateIndex(item))
8 | }
9 |
10 | return Object.entries(obj).reduce((acc: { [key: string]: any }, [key, value]) => {
11 | if (key === "last_interest_rate_index") {
12 | return acc
13 | }
14 |
15 | acc[key] = removeLastInterestRateIndex(value)
16 | return acc
17 | }, {})
18 | }
19 |
--------------------------------------------------------------------------------
/src/utils/index.ts:
--------------------------------------------------------------------------------
1 | export * from "./parse-json"
2 |
--------------------------------------------------------------------------------
/src/utils/parse-fungible-asset-to-wrapped-asset.ts:
--------------------------------------------------------------------------------
1 | import type { MoveStructId } from "@aptos-labs/ts-sdk"
2 |
3 | export const parseFungibleAssetAddressToWrappedAssetAddress = (assetAddress: MoveStructId | string): MoveStructId => {
4 | if (assetAddress === "0x357b0b74bc833e95a115ad22604854d6b0fca151cecd94111770e5d6ffc9dc2b") {
5 | return "0x9770fa9c725cbd97eb50b2be5f7416efdfd1f1554beb0750d4dae4c64e860da3::fa_to_coin_wrapper::WrappedUSDT"
6 | }
7 | return assetAddress as MoveStructId
8 | }
9 |
--------------------------------------------------------------------------------
/src/utils/parse-json.ts:
--------------------------------------------------------------------------------
1 | export const parseJson = (input: string) => {
2 | try {
3 | const forbiddenWords = ["null", "undefined", "{}"]
4 | if (input in forbiddenWords) throw new Error()
5 |
6 | const parsedInput = JSON.parse(input)
7 |
8 | return parsedInput
9 | } catch (e) {
10 | return {}
11 | }
12 | }
13 |
--------------------------------------------------------------------------------
/tsconfig.json:
--------------------------------------------------------------------------------
1 | {
2 | "compilerOptions": {
3 | "target": "ESNext" /* Set the JavaScript language version for emitted JavaScript and include compatible library declarations. */,
4 | "moduleResolution": "Bundler",
5 | "module": "ESNext" /* Specify what module code is generated. */,
6 | "esModuleInterop": true /* Emit additional JavaScript to ease support for importing CommonJS modules. This enables 'allowSyntheticDefaultImports' for type compatibility. */,
7 | "forceConsistentCasingInFileNames": true /* Ensure that casing is correct in imports. */,
8 | "strict": true /* Enable all strict type-checking options. */,
9 | "skipLibCheck": true /* Skip type checking all .d.ts files. */,
10 | "rootDir": ".",
11 | "outDir": "./dist",
12 | "noEmit": true
13 | },
14 | "include": ["src/**/*", "tests/**/*"],
15 | "exclude": ["node_modules", "dist"]
16 | }
17 |
--------------------------------------------------------------------------------
/tsup.config.ts:
--------------------------------------------------------------------------------
1 | import { defineConfig } from "tsup"
2 |
3 | export default defineConfig({
4 | entry: ["src/index.ts"],
5 | sourcemap: true,
6 | clean: true,
7 | dts: true,
8 | minify: false,
9 | format: ["esm", "cjs"],
10 | outDir: "dist",
11 | })
12 |
--------------------------------------------------------------------------------
/tsup.dev.config.ts:
--------------------------------------------------------------------------------
1 | import { defineConfig } from "tsup"
2 |
3 | export default defineConfig({
4 | entry: ["src/index.ts"],
5 | sourcemap: true,
6 | dts: true,
7 | minify: false,
8 | format: ["esm", "cjs"],
9 | outDir: "dist",
10 | })
11 |
--------------------------------------------------------------------------------