mirror of
https://github.com/d0zingcat/solana-agent-kit.git
synced 2026-05-13 23:16:55 +00:00
Merge branch 'main' into feature/vercel-ai-sdk
This commit is contained in:
@@ -1,3 +1,5 @@
|
||||
OPENAI_API_KEY=
|
||||
RPC_URL=
|
||||
SOLANA_PRIVATE_KEY=
|
||||
JUPITER_REFERRAL_ACCOUNT=
|
||||
JUPITER_FEE_BPS=
|
||||
@@ -47,7 +47,8 @@ Anyone - whether an SF-based AI researcher or a crypto-native builder - can brin
|
||||
- Launch on Pump via PumpPortal
|
||||
- Raydium pool creation (CPMM, CLMM, AMMv4)
|
||||
- Orca Whirlpool integration
|
||||
- Meteora Dynamic AMM, DLMM Pool, and Alpga Vault
|
||||
- Manifest market creation, and limit orders
|
||||
- Meteora Dynamic AMM, DLMM Pool, and Alpha Vault
|
||||
- Openbook market creation
|
||||
- Register and Resolve SNS
|
||||
- Jito Bundles
|
||||
@@ -55,7 +56,7 @@ Anyone - whether an SF-based AI researcher or a crypto-native builder - can brin
|
||||
- Register/resolve Alldomains
|
||||
|
||||
- **Solana Blinks**
|
||||
- Lending by Lulon (Best APR for USDC)
|
||||
- Lending by Lulo (Best APR for USDC)
|
||||
- Send Arcade Games
|
||||
- JupSOL staking
|
||||
|
||||
|
||||
1
docs/assets/hierarchy.js
Normal file
1
docs/assets/hierarchy.js
Normal file
@@ -0,0 +1 @@
|
||||
window.hierarchyData = "eJyrVirKzy8pVrKKjtVRKkpNy0lNLsnMzytWsqqurQUAmx4Kpg=="
|
||||
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
|
Before Width: | Height: | Size: 9.5 KiB After Width: | Height: | Size: 12 KiB |
File diff suppressed because one or more lines are too long
@@ -1 +1 @@
|
||||
window.navigationData = "data:application/octet-stream;base64,H4sIAAAAAAAAE42TwU7DMAyG3yXniooJJtTbRFUkGDCN3hCHEFwaNXWixBFMaO+O6BCsLPW45OIv3x/ZzuOHIHgnUYgHayTKxSsg3WgSmXCSWlEIZWQIEPJx/aSl3ohMdBpfRHE6u9hmP6ZLawwo0hZLcMZuesA9n0YC30gFIU+BY/HsfJ4U37uvMxyxflOs0oMk69OiXY27XgGpduW1gjUEZzFA0nSIcdIr/fxmfTfEQy1Dt4Zp9RTMBVxHpwl8bTvAUpJMiv9CnHAZjV0oZSNSCSS1CWw7pnEu5FYj/c72rqrZjEmai1jF3jURlzKiall9kjymriIO7eS2N8Gx2g21/1zCNMrJ1bBUu49fW2v2XtxEHBob8gNobJyfbZ8+AWWuiIJlBAAA"
|
||||
window.navigationData = "eJyNlFFPwjAQx79Ln4kTFFTeiIhGUQnyZnwo5caadddlvSrE+N2NQGRj3cHLHna//+/Sy7Xv34JgRaIv3qyRKAdLQHrSJFoil5SIvlBGOgcuqtbPEsqMaIlU40L0253rn9a/aaBIW9wbNBIUsVTgom2pGu50e7Xw3UpmuQHGsSM41a01BjbwEHJj1xkgBY0h8DTxa/73dUesO4pXYqyXDZ6/EhsuQJItwultjYuPgFQyKbSCKbjcogvPvY5x0ns9/7JFumkPM+nSKTSrm2CuwaPPNUExsyngUJIMig8hTjj2xg6Ush5pCCS1cew4mnGuybNG2i/Gy2jG9mikuRYTn+Wxx7H0qBJWHySPqUceN+PkVj/Asdo1JScuYRjl5A8SFwZKl4PWObho9/sgeX5z1e52SmmpDk75KQst5wZctCtVDRflsNrs8/bhnFlrSprY4zYe1aCqsHdZEsIKlCc4fGD3sgrAiGKNi2bLvsoolkCVlzh4uBpUE378Ahp6RJM="
|
||||
File diff suppressed because one or more lines are too long
File diff suppressed because it is too large
Load Diff
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
2
docs/functions/executeAction.html
Normal file
2
docs/functions/executeAction.html
Normal file
@@ -0,0 +1,2 @@
|
||||
<!DOCTYPE html><html class="default" lang="en" data-base=".."><head><meta charset="utf-8"/><meta http-equiv="x-ua-compatible" content="IE=edge"/><title>executeAction | solana-agent-kit</title><meta name="description" content="Documentation for solana-agent-kit"/><meta name="viewport" content="width=device-width, initial-scale=1"/><link rel="stylesheet" href="../assets/style.css"/><link rel="stylesheet" href="../assets/highlight.css"/><script defer src="../assets/main.js"></script><script async src="../assets/icons.js" id="tsd-icons-script"></script><script async src="../assets/search.js" id="tsd-search-script"></script><script async src="../assets/navigation.js" id="tsd-nav-script"></script></head><body><script>document.documentElement.dataset.theme = localStorage.getItem("tsd-theme") || "os";document.body.style.display="none";setTimeout(() => app?app.showPage():document.body.style.removeProperty("display"),500)</script><header class="tsd-page-toolbar"><div class="tsd-toolbar-contents container"><div class="table-cell" id="tsd-search"><div class="field"><label for="tsd-search-field" class="tsd-widget tsd-toolbar-icon search no-caption"><svg width="16" height="16" viewBox="0 0 16 16" fill="none"><use href="../assets/icons.svg#icon-search"></use></svg></label><input type="text" id="tsd-search-field" aria-label="Search"/></div><div class="field"><div id="tsd-toolbar-links"></div></div><ul class="results"><li class="state loading">Preparing search index...</li><li class="state failure">The search index is not available</li></ul><a href="../index.html" class="title">solana-agent-kit</a></div><div class="table-cell" id="tsd-widgets"><a href="#" class="tsd-widget tsd-toolbar-icon menu no-caption" data-toggle="menu" aria-label="Menu"><svg width="16" height="16" viewBox="0 0 16 16" fill="none"><use href="../assets/icons.svg#icon-menu"></use></svg></a></div></div></header><div class="container container-main"><div class="col-content"><div class="tsd-page-title"><ul class="tsd-breadcrumb"><li><a href="../modules.html">solana-agent-kit</a></li><li><a href="executeAction.html">executeAction</a></li></ul><h1>Function executeAction</h1></div><section class="tsd-panel"><ul class="tsd-signatures"><li class="tsd-signature tsd-anchor-link"><a id="executeaction" class="tsd-anchor"></a><span class="tsd-kind-call-signature">executeAction</span><span class="tsd-signature-symbol">(</span><br/> <span class="tsd-kind-parameter">action</span><span class="tsd-signature-symbol">:</span> <a href="../interfaces/Action.html" class="tsd-signature-type tsd-kind-interface">Action</a><span class="tsd-signature-symbol">,</span><br/> <span class="tsd-kind-parameter">agent</span><span class="tsd-signature-symbol">:</span> <a href="../classes/SolanaAgentKit.html" class="tsd-signature-type tsd-kind-class">SolanaAgentKit</a><span class="tsd-signature-symbol">,</span><br/> <span class="tsd-kind-parameter">input</span><span class="tsd-signature-symbol">:</span> <span class="tsd-signature-type">Record</span><span class="tsd-signature-symbol"><</span><span class="tsd-signature-type">string</span><span class="tsd-signature-symbol">,</span> <span class="tsd-signature-type">any</span><span class="tsd-signature-symbol">></span><span class="tsd-signature-symbol">,</span><br/><span class="tsd-signature-symbol">)</span><span class="tsd-signature-symbol">:</span> <span class="tsd-signature-type">Promise</span><span class="tsd-signature-symbol"><</span><span class="tsd-signature-type">Record</span><span class="tsd-signature-symbol"><</span><span class="tsd-signature-type">string</span><span class="tsd-signature-symbol">,</span> <span class="tsd-signature-type">any</span><span class="tsd-signature-symbol">></span><span class="tsd-signature-symbol">></span><a href="#executeaction" aria-label="Permalink" class="tsd-anchor-icon"><svg viewBox="0 0 24 24"><use href="../assets/icons.svg#icon-anchor"></use></svg></a></li><li class="tsd-description"><div class="tsd-comment tsd-typography"><p>Execute an action with the given input</p>
|
||||
</div><div class="tsd-parameters"><h4 class="tsd-parameters-title">Parameters</h4><ul class="tsd-parameter-list"><li><span><span class="tsd-kind-parameter">action</span>: <a href="../interfaces/Action.html" class="tsd-signature-type tsd-kind-interface">Action</a></span></li><li><span><span class="tsd-kind-parameter">agent</span>: <a href="../classes/SolanaAgentKit.html" class="tsd-signature-type tsd-kind-class">SolanaAgentKit</a></span></li><li><span><span class="tsd-kind-parameter">input</span>: <span class="tsd-signature-type">Record</span><span class="tsd-signature-symbol"><</span><span class="tsd-signature-type">string</span><span class="tsd-signature-symbol">,</span> <span class="tsd-signature-type">any</span><span class="tsd-signature-symbol">></span></span></li></ul></div><h4 class="tsd-returns-title">Returns <span class="tsd-signature-type">Promise</span><span class="tsd-signature-symbol"><</span><span class="tsd-signature-type">Record</span><span class="tsd-signature-symbol"><</span><span class="tsd-signature-type">string</span><span class="tsd-signature-symbol">,</span> <span class="tsd-signature-type">any</span><span class="tsd-signature-symbol">></span><span class="tsd-signature-symbol">></span></h4><div class="tsd-comment tsd-typography"></div><aside class="tsd-sources"><ul><li>Defined in <a href="https://github.com/sendaifun/solana-agent-kit/blob/16f7dc62a5f443fd721656fd7eb6aa1de8fb1185/src/utils/actionExecutor.ts#L20">utils/actionExecutor.ts:20</a></li></ul></aside></li></ul></section></div><div class="col-sidebar"><div class="page-menu"><div class="tsd-navigation settings"><details class="tsd-accordion"><summary class="tsd-accordion-summary"><h3><svg width="20" height="20" viewBox="0 0 24 24" fill="none"><use href="../assets/icons.svg#icon-chevronDown"></use></svg>Settings</h3></summary><div class="tsd-accordion-details"><div class="tsd-filter-visibility"><span class="settings-label">Member Visibility</span><ul id="tsd-filter-options"><li class="tsd-filter-item"><label class="tsd-filter-input"><input type="checkbox" id="tsd-filter-protected" name="protected"/><svg width="32" height="32" viewBox="0 0 32 32" aria-hidden="true"><rect class="tsd-checkbox-background" width="30" height="30" x="1" y="1" rx="6" fill="none"></rect><path class="tsd-checkbox-checkmark" d="M8.35422 16.8214L13.2143 21.75L24.6458 10.25" stroke="none" stroke-width="3.5" stroke-linejoin="round" fill="none"></path></svg><span>Protected</span></label></li><li class="tsd-filter-item"><label class="tsd-filter-input"><input type="checkbox" id="tsd-filter-inherited" name="inherited" checked/><svg width="32" height="32" viewBox="0 0 32 32" aria-hidden="true"><rect class="tsd-checkbox-background" width="30" height="30" x="1" y="1" rx="6" fill="none"></rect><path class="tsd-checkbox-checkmark" d="M8.35422 16.8214L13.2143 21.75L24.6458 10.25" stroke="none" stroke-width="3.5" stroke-linejoin="round" fill="none"></path></svg><span>Inherited</span></label></li><li class="tsd-filter-item"><label class="tsd-filter-input"><input type="checkbox" id="tsd-filter-external" name="external"/><svg width="32" height="32" viewBox="0 0 32 32" aria-hidden="true"><rect class="tsd-checkbox-background" width="30" height="30" x="1" y="1" rx="6" fill="none"></rect><path class="tsd-checkbox-checkmark" d="M8.35422 16.8214L13.2143 21.75L24.6458 10.25" stroke="none" stroke-width="3.5" stroke-linejoin="round" fill="none"></path></svg><span>External</span></label></li></ul></div><div class="tsd-theme-toggle"><label class="settings-label" for="tsd-theme">Theme</label><select id="tsd-theme"><option value="os">OS</option><option value="light">Light</option><option value="dark">Dark</option></select></div></div></details></div></div><div class="site-menu"><nav class="tsd-navigation"><a href="../modules.html">solana-agent-kit</a><ul class="tsd-small-nested-navigation" id="tsd-nav-container"><li>Loading...</li></ul></nav></div></div></div><footer><p class="tsd-generator">Generated using <a href="https://typedoc.org/" target="_blank">TypeDoc</a></p></footer><div class="overlay"></div></body></html>
|
||||
2
docs/functions/findAction.html
Normal file
2
docs/functions/findAction.html
Normal file
@@ -0,0 +1,2 @@
|
||||
<!DOCTYPE html><html class="default" lang="en" data-base=".."><head><meta charset="utf-8"/><meta http-equiv="x-ua-compatible" content="IE=edge"/><title>findAction | solana-agent-kit</title><meta name="description" content="Documentation for solana-agent-kit"/><meta name="viewport" content="width=device-width, initial-scale=1"/><link rel="stylesheet" href="../assets/style.css"/><link rel="stylesheet" href="../assets/highlight.css"/><script defer src="../assets/main.js"></script><script async src="../assets/icons.js" id="tsd-icons-script"></script><script async src="../assets/search.js" id="tsd-search-script"></script><script async src="../assets/navigation.js" id="tsd-nav-script"></script></head><body><script>document.documentElement.dataset.theme = localStorage.getItem("tsd-theme") || "os";document.body.style.display="none";setTimeout(() => app?app.showPage():document.body.style.removeProperty("display"),500)</script><header class="tsd-page-toolbar"><div class="tsd-toolbar-contents container"><div class="table-cell" id="tsd-search"><div class="field"><label for="tsd-search-field" class="tsd-widget tsd-toolbar-icon search no-caption"><svg width="16" height="16" viewBox="0 0 16 16" fill="none"><use href="../assets/icons.svg#icon-search"></use></svg></label><input type="text" id="tsd-search-field" aria-label="Search"/></div><div class="field"><div id="tsd-toolbar-links"></div></div><ul class="results"><li class="state loading">Preparing search index...</li><li class="state failure">The search index is not available</li></ul><a href="../index.html" class="title">solana-agent-kit</a></div><div class="table-cell" id="tsd-widgets"><a href="#" class="tsd-widget tsd-toolbar-icon menu no-caption" data-toggle="menu" aria-label="Menu"><svg width="16" height="16" viewBox="0 0 16 16" fill="none"><use href="../assets/icons.svg#icon-menu"></use></svg></a></div></div></header><div class="container container-main"><div class="col-content"><div class="tsd-page-title"><ul class="tsd-breadcrumb"><li><a href="../modules.html">solana-agent-kit</a></li><li><a href="findAction.html">findAction</a></li></ul><h1>Function findAction</h1></div><section class="tsd-panel"><ul class="tsd-signatures"><li class="tsd-signature tsd-anchor-link"><a id="findaction" class="tsd-anchor"></a><span class="tsd-kind-call-signature">findAction</span><span class="tsd-signature-symbol">(</span><span class="tsd-kind-parameter">query</span><span class="tsd-signature-symbol">:</span> <span class="tsd-signature-type">string</span><span class="tsd-signature-symbol">)</span><span class="tsd-signature-symbol">:</span> <a href="../interfaces/Action.html" class="tsd-signature-type tsd-kind-interface">Action</a> <span class="tsd-signature-symbol">|</span> <span class="tsd-signature-type">undefined</span><a href="#findaction" aria-label="Permalink" class="tsd-anchor-icon"><svg viewBox="0 0 24 24"><use href="../assets/icons.svg#icon-anchor"></use></svg></a></li><li class="tsd-description"><div class="tsd-comment tsd-typography"><p>Find an action by its name or one of its similes</p>
|
||||
</div><div class="tsd-parameters"><h4 class="tsd-parameters-title">Parameters</h4><ul class="tsd-parameter-list"><li><span><span class="tsd-kind-parameter">query</span>: <span class="tsd-signature-type">string</span></span></li></ul></div><h4 class="tsd-returns-title">Returns <a href="../interfaces/Action.html" class="tsd-signature-type tsd-kind-interface">Action</a> <span class="tsd-signature-symbol">|</span> <span class="tsd-signature-type">undefined</span></h4><div class="tsd-comment tsd-typography"></div><aside class="tsd-sources"><ul><li>Defined in <a href="https://github.com/sendaifun/solana-agent-kit/blob/16f7dc62a5f443fd721656fd7eb6aa1de8fb1185/src/utils/actionExecutor.ts#L8">utils/actionExecutor.ts:8</a></li></ul></aside></li></ul></section></div><div class="col-sidebar"><div class="page-menu"><div class="tsd-navigation settings"><details class="tsd-accordion"><summary class="tsd-accordion-summary"><h3><svg width="20" height="20" viewBox="0 0 24 24" fill="none"><use href="../assets/icons.svg#icon-chevronDown"></use></svg>Settings</h3></summary><div class="tsd-accordion-details"><div class="tsd-filter-visibility"><span class="settings-label">Member Visibility</span><ul id="tsd-filter-options"><li class="tsd-filter-item"><label class="tsd-filter-input"><input type="checkbox" id="tsd-filter-protected" name="protected"/><svg width="32" height="32" viewBox="0 0 32 32" aria-hidden="true"><rect class="tsd-checkbox-background" width="30" height="30" x="1" y="1" rx="6" fill="none"></rect><path class="tsd-checkbox-checkmark" d="M8.35422 16.8214L13.2143 21.75L24.6458 10.25" stroke="none" stroke-width="3.5" stroke-linejoin="round" fill="none"></path></svg><span>Protected</span></label></li><li class="tsd-filter-item"><label class="tsd-filter-input"><input type="checkbox" id="tsd-filter-inherited" name="inherited" checked/><svg width="32" height="32" viewBox="0 0 32 32" aria-hidden="true"><rect class="tsd-checkbox-background" width="30" height="30" x="1" y="1" rx="6" fill="none"></rect><path class="tsd-checkbox-checkmark" d="M8.35422 16.8214L13.2143 21.75L24.6458 10.25" stroke="none" stroke-width="3.5" stroke-linejoin="round" fill="none"></path></svg><span>Inherited</span></label></li><li class="tsd-filter-item"><label class="tsd-filter-input"><input type="checkbox" id="tsd-filter-external" name="external"/><svg width="32" height="32" viewBox="0 0 32 32" aria-hidden="true"><rect class="tsd-checkbox-background" width="30" height="30" x="1" y="1" rx="6" fill="none"></rect><path class="tsd-checkbox-checkmark" d="M8.35422 16.8214L13.2143 21.75L24.6458 10.25" stroke="none" stroke-width="3.5" stroke-linejoin="round" fill="none"></path></svg><span>External</span></label></li></ul></div><div class="tsd-theme-toggle"><label class="settings-label" for="tsd-theme">Theme</label><select id="tsd-theme"><option value="os">OS</option><option value="light">Light</option><option value="dark">Dark</option></select></div></div></details></div></div><div class="site-menu"><nav class="tsd-navigation"><a href="../modules.html">solana-agent-kit</a><ul class="tsd-small-nested-navigation" id="tsd-nav-container"><li>Loading...</li></ul></nav></div></div></div><footer><p class="tsd-generator">Generated using <a href="https://typedoc.org/" target="_blank">TypeDoc</a></p></footer><div class="overlay"></div></body></html>
|
||||
2
docs/functions/getActionExamples.html
Normal file
2
docs/functions/getActionExamples.html
Normal file
@@ -0,0 +1,2 @@
|
||||
<!DOCTYPE html><html class="default" lang="en" data-base=".."><head><meta charset="utf-8"/><meta http-equiv="x-ua-compatible" content="IE=edge"/><title>getActionExamples | solana-agent-kit</title><meta name="description" content="Documentation for solana-agent-kit"/><meta name="viewport" content="width=device-width, initial-scale=1"/><link rel="stylesheet" href="../assets/style.css"/><link rel="stylesheet" href="../assets/highlight.css"/><script defer src="../assets/main.js"></script><script async src="../assets/icons.js" id="tsd-icons-script"></script><script async src="../assets/search.js" id="tsd-search-script"></script><script async src="../assets/navigation.js" id="tsd-nav-script"></script></head><body><script>document.documentElement.dataset.theme = localStorage.getItem("tsd-theme") || "os";document.body.style.display="none";setTimeout(() => app?app.showPage():document.body.style.removeProperty("display"),500)</script><header class="tsd-page-toolbar"><div class="tsd-toolbar-contents container"><div class="table-cell" id="tsd-search"><div class="field"><label for="tsd-search-field" class="tsd-widget tsd-toolbar-icon search no-caption"><svg width="16" height="16" viewBox="0 0 16 16" fill="none"><use href="../assets/icons.svg#icon-search"></use></svg></label><input type="text" id="tsd-search-field" aria-label="Search"/></div><div class="field"><div id="tsd-toolbar-links"></div></div><ul class="results"><li class="state loading">Preparing search index...</li><li class="state failure">The search index is not available</li></ul><a href="../index.html" class="title">solana-agent-kit</a></div><div class="table-cell" id="tsd-widgets"><a href="#" class="tsd-widget tsd-toolbar-icon menu no-caption" data-toggle="menu" aria-label="Menu"><svg width="16" height="16" viewBox="0 0 16 16" fill="none"><use href="../assets/icons.svg#icon-menu"></use></svg></a></div></div></header><div class="container container-main"><div class="col-content"><div class="tsd-page-title"><ul class="tsd-breadcrumb"><li><a href="../modules.html">solana-agent-kit</a></li><li><a href="getActionExamples.html">getActionExamples</a></li></ul><h1>Function getActionExamples</h1></div><section class="tsd-panel"><ul class="tsd-signatures"><li class="tsd-signature tsd-anchor-link"><a id="getactionexamples" class="tsd-anchor"></a><span class="tsd-kind-call-signature">getActionExamples</span><span class="tsd-signature-symbol">(</span><span class="tsd-kind-parameter">action</span><span class="tsd-signature-symbol">:</span> <a href="../interfaces/Action.html" class="tsd-signature-type tsd-kind-interface">Action</a><span class="tsd-signature-symbol">)</span><span class="tsd-signature-symbol">:</span> <span class="tsd-signature-type">string</span><a href="#getactionexamples" aria-label="Permalink" class="tsd-anchor-icon"><svg viewBox="0 0 24 24"><use href="../assets/icons.svg#icon-anchor"></use></svg></a></li><li class="tsd-description"><div class="tsd-comment tsd-typography"><p>Get examples for an action</p>
|
||||
</div><div class="tsd-parameters"><h4 class="tsd-parameters-title">Parameters</h4><ul class="tsd-parameter-list"><li><span><span class="tsd-kind-parameter">action</span>: <a href="../interfaces/Action.html" class="tsd-signature-type tsd-kind-interface">Action</a></span></li></ul></div><h4 class="tsd-returns-title">Returns <span class="tsd-signature-type">string</span></h4><div class="tsd-comment tsd-typography"></div><aside class="tsd-sources"><ul><li>Defined in <a href="https://github.com/sendaifun/solana-agent-kit/blob/16f7dc62a5f443fd721656fd7eb6aa1de8fb1185/src/utils/actionExecutor.ts#L58">utils/actionExecutor.ts:58</a></li></ul></aside></li></ul></section></div><div class="col-sidebar"><div class="page-menu"><div class="tsd-navigation settings"><details class="tsd-accordion"><summary class="tsd-accordion-summary"><h3><svg width="20" height="20" viewBox="0 0 24 24" fill="none"><use href="../assets/icons.svg#icon-chevronDown"></use></svg>Settings</h3></summary><div class="tsd-accordion-details"><div class="tsd-filter-visibility"><span class="settings-label">Member Visibility</span><ul id="tsd-filter-options"><li class="tsd-filter-item"><label class="tsd-filter-input"><input type="checkbox" id="tsd-filter-protected" name="protected"/><svg width="32" height="32" viewBox="0 0 32 32" aria-hidden="true"><rect class="tsd-checkbox-background" width="30" height="30" x="1" y="1" rx="6" fill="none"></rect><path class="tsd-checkbox-checkmark" d="M8.35422 16.8214L13.2143 21.75L24.6458 10.25" stroke="none" stroke-width="3.5" stroke-linejoin="round" fill="none"></path></svg><span>Protected</span></label></li><li class="tsd-filter-item"><label class="tsd-filter-input"><input type="checkbox" id="tsd-filter-inherited" name="inherited" checked/><svg width="32" height="32" viewBox="0 0 32 32" aria-hidden="true"><rect class="tsd-checkbox-background" width="30" height="30" x="1" y="1" rx="6" fill="none"></rect><path class="tsd-checkbox-checkmark" d="M8.35422 16.8214L13.2143 21.75L24.6458 10.25" stroke="none" stroke-width="3.5" stroke-linejoin="round" fill="none"></path></svg><span>Inherited</span></label></li><li class="tsd-filter-item"><label class="tsd-filter-input"><input type="checkbox" id="tsd-filter-external" name="external"/><svg width="32" height="32" viewBox="0 0 32 32" aria-hidden="true"><rect class="tsd-checkbox-background" width="30" height="30" x="1" y="1" rx="6" fill="none"></rect><path class="tsd-checkbox-checkmark" d="M8.35422 16.8214L13.2143 21.75L24.6458 10.25" stroke="none" stroke-width="3.5" stroke-linejoin="round" fill="none"></path></svg><span>External</span></label></li></ul></div><div class="tsd-theme-toggle"><label class="settings-label" for="tsd-theme">Theme</label><select id="tsd-theme"><option value="os">OS</option><option value="light">Light</option><option value="dark">Dark</option></select></div></div></details></div></div><div class="site-menu"><nav class="tsd-navigation"><a href="../modules.html">solana-agent-kit</a><ul class="tsd-small-nested-navigation" id="tsd-nav-container"><li>Loading...</li></ul></nav></div></div></div><footer><p class="tsd-generator">Generated using <a href="https://typedoc.org/" target="_blank">TypeDoc</a></p></footer><div class="overlay"></div></body></html>
|
||||
@@ -1,5 +1,5 @@
|
||||
<!DOCTYPE html><html class="default" lang="en"><head><meta charset="utf-8"/><meta http-equiv="x-ua-compatible" content="IE=edge"/><title>solana-agent-kit</title><meta name="description" content="Documentation for solana-agent-kit"/><meta name="viewport" content="width=device-width, initial-scale=1"/><link rel="stylesheet" href="assets/style.css"/><link rel="stylesheet" href="assets/highlight.css"/><script defer src="assets/main.js"></script><script async src="assets/icons.js" id="tsd-icons-script"></script><script async src="assets/search.js" id="tsd-search-script"></script><script async src="assets/navigation.js" id="tsd-nav-script"></script></head><body><script>document.documentElement.dataset.theme = localStorage.getItem("tsd-theme") || "os";document.body.style.display="none";setTimeout(() => app?app.showPage():document.body.style.removeProperty("display"),500)</script><header class="tsd-page-toolbar"><div class="tsd-toolbar-contents container"><div class="table-cell" id="tsd-search" data-base="."><div class="field"><label for="tsd-search-field" class="tsd-widget tsd-toolbar-icon search no-caption"><svg width="16" height="16" viewBox="0 0 16 16" fill="none"><use href="assets/icons.svg#icon-search"></use></svg></label><input type="text" id="tsd-search-field" aria-label="Search"/></div><div class="field"><div id="tsd-toolbar-links"></div></div><ul class="results"><li class="state loading">Preparing search index...</li><li class="state failure">The search index is not available</li></ul><a href="index.html" class="title">solana-agent-kit</a></div><div class="table-cell" id="tsd-widgets"><a href="#" class="tsd-widget tsd-toolbar-icon menu no-caption" data-toggle="menu" aria-label="Menu"><svg width="16" height="16" viewBox="0 0 16 16" fill="none"><use href="assets/icons.svg#icon-menu"></use></svg></a></div></div></header><div class="container container-main"><div class="col-content"><div class="tsd-page-title"><h1>solana-agent-kit</h1></div><div class="tsd-panel tsd-typography"><div align="center">
|
||||
<a id="md:solana-agent-kit" class="tsd-anchor"></a><h1 class="tsd-anchor-link">Solana Agent Kit<a href="#md:solana-agent-kit" aria-label="Permalink" class="tsd-anchor-icon"><svg viewBox="0 0 24 24"><use href="assets/icons.svg#icon-anchor"></use></svg></a></h1><p><img src="https://github.com/user-attachments/assets/cfa380f6-79d9-474d-9852-3e1976c6de70" alt="Solana Agent Kit Cover 1 (3)"></p>
|
||||
<!DOCTYPE html><html class="default" lang="en" data-base="."><head><meta charset="utf-8"/><meta http-equiv="x-ua-compatible" content="IE=edge"/><title>solana-agent-kit</title><meta name="description" content="Documentation for solana-agent-kit"/><meta name="viewport" content="width=device-width, initial-scale=1"/><link rel="stylesheet" href="assets/style.css"/><link rel="stylesheet" href="assets/highlight.css"/><script defer src="assets/main.js"></script><script async src="assets/icons.js" id="tsd-icons-script"></script><script async src="assets/search.js" id="tsd-search-script"></script><script async src="assets/navigation.js" id="tsd-nav-script"></script></head><body><script>document.documentElement.dataset.theme = localStorage.getItem("tsd-theme") || "os";document.body.style.display="none";setTimeout(() => app?app.showPage():document.body.style.removeProperty("display"),500)</script><header class="tsd-page-toolbar"><div class="tsd-toolbar-contents container"><div class="table-cell" id="tsd-search"><div class="field"><label for="tsd-search-field" class="tsd-widget tsd-toolbar-icon search no-caption"><svg width="16" height="16" viewBox="0 0 16 16" fill="none"><use href="assets/icons.svg#icon-search"></use></svg></label><input type="text" id="tsd-search-field" aria-label="Search"/></div><div class="field"><div id="tsd-toolbar-links"></div></div><ul class="results"><li class="state loading">Preparing search index...</li><li class="state failure">The search index is not available</li></ul><a href="index.html" class="title">solana-agent-kit</a></div><div class="table-cell" id="tsd-widgets"><a href="#" class="tsd-widget tsd-toolbar-icon menu no-caption" data-toggle="menu" aria-label="Menu"><svg width="16" height="16" viewBox="0 0 16 16" fill="none"><use href="assets/icons.svg#icon-menu"></use></svg></a></div></div></header><div class="container container-main"><div class="col-content"><div class="tsd-page-title"><h1>solana-agent-kit</h1></div><div class="tsd-panel tsd-typography"><div align="center">
|
||||
<a id="solana-agent-kit" class="tsd-anchor"></a><h1 class="tsd-anchor-link">Solana Agent Kit<a href="#solana-agent-kit" aria-label="Permalink" class="tsd-anchor-icon"><svg viewBox="0 0 24 24"><use href="assets/icons.svg#icon-anchor"></use></svg></a></h1><p><img src="https://github.com/user-attachments/assets/cfa380f6-79d9-474d-9852-3e1976c6de70" alt="Solana Agent Kit Cover 1 (3)"></p>
|
||||
<p><img src="https://img.shields.io/npm/dm/solana-agent-kit?style=for-the-badge" alt="NPM Downloads">
|
||||
<img src="https://img.shields.io/github/forks/sendaifun/solana-agent-kit?style=for-the-badge" alt="GitHub forks">
|
||||
<img src="https://img.shields.io/github/license/sendaifun/solana-agent-kit?style=for-the-badge" alt="GitHub License"></p>
|
||||
@@ -15,11 +15,11 @@
|
||||
<li>And more...</li>
|
||||
</ul>
|
||||
<p>Anyone - whether an SF-based AI researcher or a crypto-native builder - can bring their AI agents trained with any model and seamlessly integrate with Solana.</p>
|
||||
<p><a href="https://replit.com/@sendaifun/Solana-Agent-Kit" target="_blank" class="external"><img src="https://replit.com/badge/github/sendaifun/solana-agent-kit" alt="Run on Repl.it"></a></p>
|
||||
<p><a href="https://replit.com/@sendaifun/Solana-Agent-Kit"><img src="https://replit.com/badge/github/sendaifun/solana-agent-kit" alt="Run on Repl.it"></a></p>
|
||||
<blockquote>
|
||||
<p>Replit template created by <a href="https://github.com/The-x-35" target="_blank" class="external">Arpit Singh</a></p>
|
||||
<p>Replit template created by <a href="https://github.com/The-x-35">Arpit Singh</a></p>
|
||||
</blockquote>
|
||||
<a id="md:🔧-core-blockchain-features" class="tsd-anchor"></a><h2 class="tsd-anchor-link">🔧 Core Blockchain Features<a href="#md:🔧-core-blockchain-features" aria-label="Permalink" class="tsd-anchor-icon"><svg viewBox="0 0 24 24"><use href="assets/icons.svg#icon-anchor"></use></svg></a></h2><ul>
|
||||
<a id="🔧-core-blockchain-features" class="tsd-anchor"></a><h2 class="tsd-anchor-link">🔧 Core Blockchain Features<a href="#🔧-core-blockchain-features" aria-label="Permalink" class="tsd-anchor-icon"><svg viewBox="0 0 24 24"><use href="assets/icons.svg#icon-anchor"></use></svg></a></h2><ul>
|
||||
<li>
|
||||
<p><strong>Token Operations</strong></p>
|
||||
<ul>
|
||||
@@ -46,7 +46,8 @@
|
||||
<li>Launch on Pump via PumpPortal</li>
|
||||
<li>Raydium pool creation (CPMM, CLMM, AMMv4)</li>
|
||||
<li>Orca Whirlpool integration</li>
|
||||
<li>Meteora Dynamic AMM, DLMM Pool, and Alpga Vault</li>
|
||||
<li>Manifest market creation, and limit orders</li>
|
||||
<li>Meteora Dynamic AMM, DLMM Pool, and Alpha Vault</li>
|
||||
<li>Openbook market creation</li>
|
||||
<li>Register and Resolve SNS</li>
|
||||
<li>Jito Bundles</li>
|
||||
@@ -57,7 +58,7 @@
|
||||
<li>
|
||||
<p><strong>Solana Blinks</strong></p>
|
||||
<ul>
|
||||
<li>Lending by Lulon (Best APR for USDC)</li>
|
||||
<li>Lending by Lulo (Best APR for USDC)</li>
|
||||
<li>Send Arcade Games</li>
|
||||
<li>JupSOL staking</li>
|
||||
</ul>
|
||||
@@ -69,7 +70,7 @@
|
||||
</ul>
|
||||
</li>
|
||||
</ul>
|
||||
<a id="md:🤖-ai-integration-features" class="tsd-anchor"></a><h2 class="tsd-anchor-link">🤖 AI Integration Features<a href="#md:🤖-ai-integration-features" aria-label="Permalink" class="tsd-anchor-icon"><svg viewBox="0 0 24 24"><use href="assets/icons.svg#icon-anchor"></use></svg></a></h2><ul>
|
||||
<a id="🤖-ai-integration-features" class="tsd-anchor"></a><h2 class="tsd-anchor-link">🤖 AI Integration Features<a href="#🤖-ai-integration-features" aria-label="Permalink" class="tsd-anchor-icon"><svg viewBox="0 0 24 24"><use href="assets/icons.svg#icon-anchor"></use></svg></a></h2><ul>
|
||||
<li>
|
||||
<p><strong>LangChain Integration</strong></p>
|
||||
<ul>
|
||||
@@ -98,34 +99,34 @@
|
||||
</ul>
|
||||
</li>
|
||||
</ul>
|
||||
<a id="md:📦-installation" class="tsd-anchor"></a><h2 class="tsd-anchor-link">📦 Installation<a href="#md:📦-installation" aria-label="Permalink" class="tsd-anchor-icon"><svg viewBox="0 0 24 24"><use href="assets/icons.svg#icon-anchor"></use></svg></a></h2><pre><code class="bash"><span class="hl-0">npm</span><span class="hl-1"> </span><span class="hl-2">install</span><span class="hl-1"> </span><span class="hl-2">solana-agent-kit</span>
|
||||
<a id="📦-installation" class="tsd-anchor"></a><h2 class="tsd-anchor-link">📦 Installation<a href="#📦-installation" aria-label="Permalink" class="tsd-anchor-icon"><svg viewBox="0 0 24 24"><use href="assets/icons.svg#icon-anchor"></use></svg></a></h2><pre><code class="bash"><span class="hl-0">npm</span><span class="hl-1"> </span><span class="hl-2">install</span><span class="hl-1"> </span><span class="hl-2">solana-agent-kit</span>
|
||||
</code><button type="button">Copy</button></pre>
|
||||
|
||||
<a id="md:quick-start" class="tsd-anchor"></a><h2 class="tsd-anchor-link">Quick Start<a href="#md:quick-start" aria-label="Permalink" class="tsd-anchor-icon"><svg viewBox="0 0 24 24"><use href="assets/icons.svg#icon-anchor"></use></svg></a></h2><pre><code class="typescript"><span class="hl-3">import</span><span class="hl-1"> { </span><span class="hl-4">SolanaAgentKit</span><span class="hl-1">, </span><span class="hl-4">createSolanaTools</span><span class="hl-1"> } </span><span class="hl-3">from</span><span class="hl-1"> </span><span class="hl-2">"solana-agent-kit"</span><span class="hl-1">;</span><br/><br/><span class="hl-5">// Initialize with private key and optional RPC URL</span><br/><span class="hl-6">const</span><span class="hl-1"> </span><span class="hl-7">agent</span><span class="hl-1"> = </span><span class="hl-6">new</span><span class="hl-1"> </span><span class="hl-0">SolanaAgentKit</span><span class="hl-1">(</span><br/><span class="hl-1"> </span><span class="hl-2">"your-wallet-private-key-as-base58"</span><span class="hl-1">,</span><br/><span class="hl-1"> </span><span class="hl-2">"https://api.mainnet-beta.solana.com"</span><span class="hl-1">,</span><br/><span class="hl-1"> </span><span class="hl-2">"your-openai-api-key"</span><br/><span class="hl-1">);</span><br/><br/><span class="hl-5">// Create LangChain tools</span><br/><span class="hl-6">const</span><span class="hl-1"> </span><span class="hl-7">tools</span><span class="hl-1"> = </span><span class="hl-0">createSolanaTools</span><span class="hl-1">(</span><span class="hl-4">agent</span><span class="hl-1">);</span>
|
||||
<a id="quick-start" class="tsd-anchor"></a><h2 class="tsd-anchor-link">Quick Start<a href="#quick-start" aria-label="Permalink" class="tsd-anchor-icon"><svg viewBox="0 0 24 24"><use href="assets/icons.svg#icon-anchor"></use></svg></a></h2><pre><code class="typescript"><span class="hl-3">import</span><span class="hl-1"> { </span><span class="hl-4">SolanaAgentKit</span><span class="hl-1">, </span><span class="hl-4">createSolanaTools</span><span class="hl-1"> } </span><span class="hl-3">from</span><span class="hl-1"> </span><span class="hl-2">"solana-agent-kit"</span><span class="hl-1">;</span><br/><br/><span class="hl-5">// Initialize with private key and optional RPC URL</span><br/><span class="hl-6">const</span><span class="hl-1"> </span><span class="hl-7">agent</span><span class="hl-1"> = </span><span class="hl-6">new</span><span class="hl-1"> </span><span class="hl-0">SolanaAgentKit</span><span class="hl-1">(</span><br/><span class="hl-1"> </span><span class="hl-2">"your-wallet-private-key-as-base58"</span><span class="hl-1">,</span><br/><span class="hl-1"> </span><span class="hl-2">"https://api.mainnet-beta.solana.com"</span><span class="hl-1">,</span><br/><span class="hl-1"> </span><span class="hl-2">"your-openai-api-key"</span><br/><span class="hl-1">);</span><br/><br/><span class="hl-5">// Create LangChain tools</span><br/><span class="hl-6">const</span><span class="hl-1"> </span><span class="hl-7">tools</span><span class="hl-1"> = </span><span class="hl-0">createSolanaTools</span><span class="hl-1">(</span><span class="hl-4">agent</span><span class="hl-1">);</span>
|
||||
</code><button type="button">Copy</button></pre>
|
||||
|
||||
<a id="md:usage-examples" class="tsd-anchor"></a><h2 class="tsd-anchor-link">Usage Examples<a href="#md:usage-examples" aria-label="Permalink" class="tsd-anchor-icon"><svg viewBox="0 0 24 24"><use href="assets/icons.svg#icon-anchor"></use></svg></a></h2><a id="md:deploy-a-new-token" class="tsd-anchor"></a><h3 class="tsd-anchor-link">Deploy a New Token<a href="#md:deploy-a-new-token" aria-label="Permalink" class="tsd-anchor-icon"><svg viewBox="0 0 24 24"><use href="assets/icons.svg#icon-anchor"></use></svg></a></h3><pre><code class="typescript"><span class="hl-6">const</span><span class="hl-1"> </span><span class="hl-7">result</span><span class="hl-1"> = </span><span class="hl-3">await</span><span class="hl-1"> </span><span class="hl-4">agent</span><span class="hl-1">.</span><span class="hl-0">deployToken</span><span class="hl-1">(</span><br/><span class="hl-1"> </span><span class="hl-2">"my ai token"</span><span class="hl-1">, </span><span class="hl-5">// name</span><br/><span class="hl-1"> </span><span class="hl-2">"uri"</span><span class="hl-1">, </span><span class="hl-5">// uri</span><br/><span class="hl-1"> </span><span class="hl-2">"token"</span><span class="hl-1">, </span><span class="hl-5">// symbol</span><br/><span class="hl-1"> </span><span class="hl-8">9</span><span class="hl-1">, </span><span class="hl-5">// decimals</span><br/><span class="hl-1"> </span><span class="hl-8">1000000</span><span class="hl-1"> </span><span class="hl-5">// initial supply</span><br/><span class="hl-1">);</span><br/><br/><span class="hl-4">console</span><span class="hl-1">.</span><span class="hl-0">log</span><span class="hl-1">(</span><span class="hl-2">"Token Mint Address:"</span><span class="hl-1">, </span><span class="hl-4">result</span><span class="hl-1">.</span><span class="hl-4">mint</span><span class="hl-1">.</span><span class="hl-0">toString</span><span class="hl-1">());</span>
|
||||
<a id="usage-examples" class="tsd-anchor"></a><h2 class="tsd-anchor-link">Usage Examples<a href="#usage-examples" aria-label="Permalink" class="tsd-anchor-icon"><svg viewBox="0 0 24 24"><use href="assets/icons.svg#icon-anchor"></use></svg></a></h2><a id="deploy-a-new-token" class="tsd-anchor"></a><h3 class="tsd-anchor-link">Deploy a New Token<a href="#deploy-a-new-token" aria-label="Permalink" class="tsd-anchor-icon"><svg viewBox="0 0 24 24"><use href="assets/icons.svg#icon-anchor"></use></svg></a></h3><pre><code class="typescript"><span class="hl-6">const</span><span class="hl-1"> </span><span class="hl-7">result</span><span class="hl-1"> = </span><span class="hl-3">await</span><span class="hl-1"> </span><span class="hl-4">agent</span><span class="hl-1">.</span><span class="hl-0">deployToken</span><span class="hl-1">(</span><br/><span class="hl-1"> </span><span class="hl-2">"my ai token"</span><span class="hl-1">, </span><span class="hl-5">// name</span><br/><span class="hl-1"> </span><span class="hl-2">"uri"</span><span class="hl-1">, </span><span class="hl-5">// uri</span><br/><span class="hl-1"> </span><span class="hl-2">"token"</span><span class="hl-1">, </span><span class="hl-5">// symbol</span><br/><span class="hl-1"> </span><span class="hl-8">9</span><span class="hl-1">, </span><span class="hl-5">// decimals</span><br/><span class="hl-1"> </span><span class="hl-8">1000000</span><span class="hl-1"> </span><span class="hl-5">// initial supply</span><br/><span class="hl-1">);</span><br/><br/><span class="hl-4">console</span><span class="hl-1">.</span><span class="hl-0">log</span><span class="hl-1">(</span><span class="hl-2">"Token Mint Address:"</span><span class="hl-1">, </span><span class="hl-4">result</span><span class="hl-1">.</span><span class="hl-4">mint</span><span class="hl-1">.</span><span class="hl-0">toString</span><span class="hl-1">());</span>
|
||||
</code><button type="button">Copy</button></pre>
|
||||
|
||||
<a id="md:create-nft-collection" class="tsd-anchor"></a><h3 class="tsd-anchor-link">Create NFT Collection<a href="#md:create-nft-collection" aria-label="Permalink" class="tsd-anchor-icon"><svg viewBox="0 0 24 24"><use href="assets/icons.svg#icon-anchor"></use></svg></a></h3><pre><code class="typescript"><span class="hl-6">const</span><span class="hl-1"> </span><span class="hl-7">collection</span><span class="hl-1"> = </span><span class="hl-3">await</span><span class="hl-1"> </span><span class="hl-4">agent</span><span class="hl-1">.</span><span class="hl-0">deployCollection</span><span class="hl-1">({</span><br/><span class="hl-1"> </span><span class="hl-4">name:</span><span class="hl-1"> </span><span class="hl-2">"My NFT Collection"</span><span class="hl-1">,</span><br/><span class="hl-1"> </span><span class="hl-4">uri:</span><span class="hl-1"> </span><span class="hl-2">"https://arweave.net/metadata.json"</span><span class="hl-1">,</span><br/><span class="hl-1"> </span><span class="hl-4">royaltyBasisPoints:</span><span class="hl-1"> </span><span class="hl-8">500</span><span class="hl-1">, </span><span class="hl-5">// 5%</span><br/><span class="hl-1"> </span><span class="hl-4">creators:</span><span class="hl-1"> [</span><br/><span class="hl-1"> {</span><br/><span class="hl-1"> </span><span class="hl-4">address:</span><span class="hl-1"> </span><span class="hl-2">"creator-wallet-address"</span><span class="hl-1">,</span><br/><span class="hl-1"> </span><span class="hl-4">percentage:</span><span class="hl-1"> </span><span class="hl-8">100</span><span class="hl-1">,</span><br/><span class="hl-1"> },</span><br/><span class="hl-1"> ],</span><br/><span class="hl-1">});</span>
|
||||
<a id="create-nft-collection" class="tsd-anchor"></a><h3 class="tsd-anchor-link">Create NFT Collection<a href="#create-nft-collection" aria-label="Permalink" class="tsd-anchor-icon"><svg viewBox="0 0 24 24"><use href="assets/icons.svg#icon-anchor"></use></svg></a></h3><pre><code class="typescript"><span class="hl-6">const</span><span class="hl-1"> </span><span class="hl-7">collection</span><span class="hl-1"> = </span><span class="hl-3">await</span><span class="hl-1"> </span><span class="hl-4">agent</span><span class="hl-1">.</span><span class="hl-0">deployCollection</span><span class="hl-1">({</span><br/><span class="hl-1"> </span><span class="hl-4">name:</span><span class="hl-1"> </span><span class="hl-2">"My NFT Collection"</span><span class="hl-1">,</span><br/><span class="hl-1"> </span><span class="hl-4">uri:</span><span class="hl-1"> </span><span class="hl-2">"https://arweave.net/metadata.json"</span><span class="hl-1">,</span><br/><span class="hl-1"> </span><span class="hl-4">royaltyBasisPoints:</span><span class="hl-1"> </span><span class="hl-8">500</span><span class="hl-1">, </span><span class="hl-5">// 5%</span><br/><span class="hl-1"> </span><span class="hl-4">creators:</span><span class="hl-1"> [</span><br/><span class="hl-1"> {</span><br/><span class="hl-1"> </span><span class="hl-4">address:</span><span class="hl-1"> </span><span class="hl-2">"creator-wallet-address"</span><span class="hl-1">,</span><br/><span class="hl-1"> </span><span class="hl-4">percentage:</span><span class="hl-1"> </span><span class="hl-8">100</span><span class="hl-1">,</span><br/><span class="hl-1"> },</span><br/><span class="hl-1"> ],</span><br/><span class="hl-1">});</span>
|
||||
</code><button type="button">Copy</button></pre>
|
||||
|
||||
<a id="md:swap-tokens" class="tsd-anchor"></a><h3 class="tsd-anchor-link">Swap Tokens<a href="#md:swap-tokens" aria-label="Permalink" class="tsd-anchor-icon"><svg viewBox="0 0 24 24"><use href="assets/icons.svg#icon-anchor"></use></svg></a></h3><pre><code class="typescript"><span class="hl-3">import</span><span class="hl-1"> { </span><span class="hl-4">PublicKey</span><span class="hl-1"> } </span><span class="hl-3">from</span><span class="hl-1"> </span><span class="hl-2">"@solana/web3.js"</span><span class="hl-1">;</span><br/><br/><span class="hl-6">const</span><span class="hl-1"> </span><span class="hl-7">signature</span><span class="hl-1"> = </span><span class="hl-3">await</span><span class="hl-1"> </span><span class="hl-4">agent</span><span class="hl-1">.</span><span class="hl-0">trade</span><span class="hl-1">(</span><br/><span class="hl-1"> </span><span class="hl-6">new</span><span class="hl-1"> </span><span class="hl-0">PublicKey</span><span class="hl-1">(</span><span class="hl-2">"target-token-mint"</span><span class="hl-1">),</span><br/><span class="hl-1"> </span><span class="hl-8">100</span><span class="hl-1">, </span><span class="hl-5">// amount</span><br/><span class="hl-1"> </span><span class="hl-6">new</span><span class="hl-1"> </span><span class="hl-0">PublicKey</span><span class="hl-1">(</span><span class="hl-2">"source-token-mint"</span><span class="hl-1">),</span><br/><span class="hl-1"> </span><span class="hl-8">300</span><span class="hl-1"> </span><span class="hl-5">// 3% slippage</span><br/><span class="hl-1">);</span>
|
||||
<a id="swap-tokens" class="tsd-anchor"></a><h3 class="tsd-anchor-link">Swap Tokens<a href="#swap-tokens" aria-label="Permalink" class="tsd-anchor-icon"><svg viewBox="0 0 24 24"><use href="assets/icons.svg#icon-anchor"></use></svg></a></h3><pre><code class="typescript"><span class="hl-3">import</span><span class="hl-1"> { </span><span class="hl-4">PublicKey</span><span class="hl-1"> } </span><span class="hl-3">from</span><span class="hl-1"> </span><span class="hl-2">"@solana/web3.js"</span><span class="hl-1">;</span><br/><br/><span class="hl-6">const</span><span class="hl-1"> </span><span class="hl-7">signature</span><span class="hl-1"> = </span><span class="hl-3">await</span><span class="hl-1"> </span><span class="hl-4">agent</span><span class="hl-1">.</span><span class="hl-0">trade</span><span class="hl-1">(</span><br/><span class="hl-1"> </span><span class="hl-6">new</span><span class="hl-1"> </span><span class="hl-0">PublicKey</span><span class="hl-1">(</span><span class="hl-2">"target-token-mint"</span><span class="hl-1">),</span><br/><span class="hl-1"> </span><span class="hl-8">100</span><span class="hl-1">, </span><span class="hl-5">// amount</span><br/><span class="hl-1"> </span><span class="hl-6">new</span><span class="hl-1"> </span><span class="hl-0">PublicKey</span><span class="hl-1">(</span><span class="hl-2">"source-token-mint"</span><span class="hl-1">),</span><br/><span class="hl-1"> </span><span class="hl-8">300</span><span class="hl-1"> </span><span class="hl-5">// 3% slippage</span><br/><span class="hl-1">);</span>
|
||||
</code><button type="button">Copy</button></pre>
|
||||
|
||||
<a id="md:lend-tokens" class="tsd-anchor"></a><h3 class="tsd-anchor-link">Lend Tokens<a href="#md:lend-tokens" aria-label="Permalink" class="tsd-anchor-icon"><svg viewBox="0 0 24 24"><use href="assets/icons.svg#icon-anchor"></use></svg></a></h3><pre><code class="typescript"><span class="hl-3">import</span><span class="hl-1"> { </span><span class="hl-4">PublicKey</span><span class="hl-1"> } </span><span class="hl-3">from</span><span class="hl-1"> </span><span class="hl-2">"@solana/web3.js"</span><span class="hl-1">;</span><br/><br/><span class="hl-6">const</span><span class="hl-1"> </span><span class="hl-7">signature</span><span class="hl-1"> = </span><span class="hl-3">await</span><span class="hl-1"> </span><span class="hl-4">agent</span><span class="hl-1">.</span><span class="hl-0">lendAssets</span><span class="hl-1">(</span><br/><span class="hl-1"> </span><span class="hl-8">100</span><span class="hl-1"> </span><span class="hl-5">// amount of USDC to lend</span><br/><span class="hl-1">);</span>
|
||||
<a id="lend-tokens" class="tsd-anchor"></a><h3 class="tsd-anchor-link">Lend Tokens<a href="#lend-tokens" aria-label="Permalink" class="tsd-anchor-icon"><svg viewBox="0 0 24 24"><use href="assets/icons.svg#icon-anchor"></use></svg></a></h3><pre><code class="typescript"><span class="hl-3">import</span><span class="hl-1"> { </span><span class="hl-4">PublicKey</span><span class="hl-1"> } </span><span class="hl-3">from</span><span class="hl-1"> </span><span class="hl-2">"@solana/web3.js"</span><span class="hl-1">;</span><br/><br/><span class="hl-6">const</span><span class="hl-1"> </span><span class="hl-7">signature</span><span class="hl-1"> = </span><span class="hl-3">await</span><span class="hl-1"> </span><span class="hl-4">agent</span><span class="hl-1">.</span><span class="hl-0">lendAssets</span><span class="hl-1">(</span><br/><span class="hl-1"> </span><span class="hl-8">100</span><span class="hl-1"> </span><span class="hl-5">// amount of USDC to lend</span><br/><span class="hl-1">);</span>
|
||||
</code><button type="button">Copy</button></pre>
|
||||
|
||||
<a id="md:stake-sol" class="tsd-anchor"></a><h3 class="tsd-anchor-link">Stake SOL<a href="#md:stake-sol" aria-label="Permalink" class="tsd-anchor-icon"><svg viewBox="0 0 24 24"><use href="assets/icons.svg#icon-anchor"></use></svg></a></h3><pre><code class="typescript"><span class="hl-6">const</span><span class="hl-1"> </span><span class="hl-7">signature</span><span class="hl-1"> = </span><span class="hl-3">await</span><span class="hl-1"> </span><span class="hl-4">agent</span><span class="hl-1">.</span><span class="hl-0">stake</span><span class="hl-1">(</span><br/><span class="hl-1"> </span><span class="hl-8">1</span><span class="hl-1"> </span><span class="hl-5">// amount in SOL to stake</span><br/><span class="hl-1">);</span>
|
||||
<a id="stake-sol" class="tsd-anchor"></a><h3 class="tsd-anchor-link">Stake SOL<a href="#stake-sol" aria-label="Permalink" class="tsd-anchor-icon"><svg viewBox="0 0 24 24"><use href="assets/icons.svg#icon-anchor"></use></svg></a></h3><pre><code class="typescript"><span class="hl-6">const</span><span class="hl-1"> </span><span class="hl-7">signature</span><span class="hl-1"> = </span><span class="hl-3">await</span><span class="hl-1"> </span><span class="hl-4">agent</span><span class="hl-1">.</span><span class="hl-0">stake</span><span class="hl-1">(</span><br/><span class="hl-1"> </span><span class="hl-8">1</span><span class="hl-1"> </span><span class="hl-5">// amount in SOL to stake</span><br/><span class="hl-1">);</span>
|
||||
</code><button type="button">Copy</button></pre>
|
||||
|
||||
<a id="md:send-an-spl-token-airdrop-via-zk-compression" class="tsd-anchor"></a><h3 class="tsd-anchor-link">Send an SPL Token Airdrop via ZK Compression<a href="#md:send-an-spl-token-airdrop-via-zk-compression" aria-label="Permalink" class="tsd-anchor-icon"><svg viewBox="0 0 24 24"><use href="assets/icons.svg#icon-anchor"></use></svg></a></h3><pre><code class="typescript"><span class="hl-3">import</span><span class="hl-1"> { </span><span class="hl-4">PublicKey</span><span class="hl-1"> } </span><span class="hl-3">from</span><span class="hl-1"> </span><span class="hl-2">"@solana/web3.js"</span><span class="hl-1">;</span><br/><br/><span class="hl-1">(</span><span class="hl-6">async</span><span class="hl-1"> () </span><span class="hl-6">=></span><span class="hl-1"> {</span><br/><span class="hl-1"> </span><span class="hl-4">console</span><span class="hl-1">.</span><span class="hl-0">log</span><span class="hl-1">(</span><br/><span class="hl-1"> </span><span class="hl-2">"~Airdrop cost estimate:"</span><span class="hl-1">,</span><br/><span class="hl-1"> </span><span class="hl-0">getAirdropCostEstimate</span><span class="hl-1">(</span><br/><span class="hl-1"> </span><span class="hl-8">1000</span><span class="hl-1">, </span><span class="hl-5">// recipients</span><br/><span class="hl-1"> </span><span class="hl-8">30_000</span><span class="hl-1"> </span><span class="hl-5">// priority fee in lamports</span><br/><span class="hl-1"> )</span><br/><span class="hl-1"> );</span><br/><br/><span class="hl-1"> </span><span class="hl-6">const</span><span class="hl-1"> </span><span class="hl-7">signature</span><span class="hl-1"> = </span><span class="hl-3">await</span><span class="hl-1"> </span><span class="hl-4">agent</span><span class="hl-1">.</span><span class="hl-0">sendCompressedAirdrop</span><span class="hl-1">(</span><br/><span class="hl-1"> </span><span class="hl-6">new</span><span class="hl-1"> </span><span class="hl-0">PublicKey</span><span class="hl-1">(</span><span class="hl-2">"JUPyiwrYJFskUPiHa7hkeR8VUtAeFoSYbKedZNsDvCN"</span><span class="hl-1">), </span><span class="hl-5">// mint</span><br/><span class="hl-1"> </span><span class="hl-8">42</span><span class="hl-1">, </span><span class="hl-5">// amount per recipient</span><br/><span class="hl-1"> [</span><br/><span class="hl-1"> </span><span class="hl-6">new</span><span class="hl-1"> </span><span class="hl-0">PublicKey</span><span class="hl-1">(</span><span class="hl-2">"1nc1nerator11111111111111111111111111111111"</span><span class="hl-1">),</span><br/><span class="hl-1"> </span><span class="hl-5">// ... add more recipients</span><br/><span class="hl-1"> ],</span><br/><span class="hl-1"> </span><span class="hl-8">30_000</span><span class="hl-1"> </span><span class="hl-5">// priority fee in lamports</span><br/><span class="hl-1"> );</span><br/><span class="hl-1">})();</span>
|
||||
<a id="send-an-spl-token-airdrop-via-zk-compression" class="tsd-anchor"></a><h3 class="tsd-anchor-link">Send an SPL Token Airdrop via ZK Compression<a href="#send-an-spl-token-airdrop-via-zk-compression" aria-label="Permalink" class="tsd-anchor-icon"><svg viewBox="0 0 24 24"><use href="assets/icons.svg#icon-anchor"></use></svg></a></h3><pre><code class="typescript"><span class="hl-3">import</span><span class="hl-1"> { </span><span class="hl-4">PublicKey</span><span class="hl-1"> } </span><span class="hl-3">from</span><span class="hl-1"> </span><span class="hl-2">"@solana/web3.js"</span><span class="hl-1">;</span><br/><br/><span class="hl-1">(</span><span class="hl-6">async</span><span class="hl-1"> () </span><span class="hl-6">=></span><span class="hl-1"> {</span><br/><span class="hl-1"> </span><span class="hl-4">console</span><span class="hl-1">.</span><span class="hl-0">log</span><span class="hl-1">(</span><br/><span class="hl-1"> </span><span class="hl-2">"~Airdrop cost estimate:"</span><span class="hl-1">,</span><br/><span class="hl-1"> </span><span class="hl-0">getAirdropCostEstimate</span><span class="hl-1">(</span><br/><span class="hl-1"> </span><span class="hl-8">1000</span><span class="hl-1">, </span><span class="hl-5">// recipients</span><br/><span class="hl-1"> </span><span class="hl-8">30_000</span><span class="hl-1"> </span><span class="hl-5">// priority fee in lamports</span><br/><span class="hl-1"> )</span><br/><span class="hl-1"> );</span><br/><br/><span class="hl-1"> </span><span class="hl-6">const</span><span class="hl-1"> </span><span class="hl-7">signature</span><span class="hl-1"> = </span><span class="hl-3">await</span><span class="hl-1"> </span><span class="hl-4">agent</span><span class="hl-1">.</span><span class="hl-0">sendCompressedAirdrop</span><span class="hl-1">(</span><br/><span class="hl-1"> </span><span class="hl-6">new</span><span class="hl-1"> </span><span class="hl-0">PublicKey</span><span class="hl-1">(</span><span class="hl-2">"JUPyiwrYJFskUPiHa7hkeR8VUtAeFoSYbKedZNsDvCN"</span><span class="hl-1">), </span><span class="hl-5">// mint</span><br/><span class="hl-1"> </span><span class="hl-8">42</span><span class="hl-1">, </span><span class="hl-5">// amount per recipient</span><br/><span class="hl-1"> [</span><br/><span class="hl-1"> </span><span class="hl-6">new</span><span class="hl-1"> </span><span class="hl-0">PublicKey</span><span class="hl-1">(</span><span class="hl-2">"1nc1nerator11111111111111111111111111111111"</span><span class="hl-1">),</span><br/><span class="hl-1"> </span><span class="hl-5">// ... add more recipients</span><br/><span class="hl-1"> ],</span><br/><span class="hl-1"> </span><span class="hl-8">30_000</span><span class="hl-1"> </span><span class="hl-5">// priority fee in lamports</span><br/><span class="hl-1"> );</span><br/><span class="hl-1">})();</span>
|
||||
</code><button type="button">Copy</button></pre>
|
||||
|
||||
<a id="md:fetch-price-data-from-pyth" class="tsd-anchor"></a><h3 class="tsd-anchor-link">Fetch Price Data from Pyth<a href="#md:fetch-price-data-from-pyth" aria-label="Permalink" class="tsd-anchor-icon"><svg viewBox="0 0 24 24"><use href="assets/icons.svg#icon-anchor"></use></svg></a></h3><pre><code class="typescript"><br/><span class="hl-6">const</span><span class="hl-1"> </span><span class="hl-7">price</span><span class="hl-1"> = </span><span class="hl-3">await</span><span class="hl-1"> </span><span class="hl-4">agent</span><span class="hl-1">.</span><span class="hl-0">pythFetchPrice</span><span class="hl-1">(</span><br/><span class="hl-1"> </span><span class="hl-2">"0xe62df6c8b4a85fe1a67db44dc12de5db330f7ac66b72dc658afedf0f4a415b43"</span><br/><span class="hl-1">);</span><br/><br/><span class="hl-4">console</span><span class="hl-1">.</span><span class="hl-0">log</span><span class="hl-1">(</span><span class="hl-2">"Price in BTC/USD:"</span><span class="hl-1">, </span><span class="hl-4">price</span><span class="hl-1">);</span>
|
||||
<a id="fetch-price-data-from-pyth" class="tsd-anchor"></a><h3 class="tsd-anchor-link">Fetch Price Data from Pyth<a href="#fetch-price-data-from-pyth" aria-label="Permalink" class="tsd-anchor-icon"><svg viewBox="0 0 24 24"><use href="assets/icons.svg#icon-anchor"></use></svg></a></h3><pre><code class="typescript"><br/><span class="hl-6">const</span><span class="hl-1"> </span><span class="hl-7">price</span><span class="hl-1"> = </span><span class="hl-3">await</span><span class="hl-1"> </span><span class="hl-4">agent</span><span class="hl-1">.</span><span class="hl-0">pythFetchPrice</span><span class="hl-1">(</span><br/><span class="hl-1"> </span><span class="hl-2">"0xe62df6c8b4a85fe1a67db44dc12de5db330f7ac66b72dc658afedf0f4a415b43"</span><br/><span class="hl-1">);</span><br/><br/><span class="hl-4">console</span><span class="hl-1">.</span><span class="hl-0">log</span><span class="hl-1">(</span><span class="hl-2">"Price in BTC/USD:"</span><span class="hl-1">, </span><span class="hl-4">price</span><span class="hl-1">);</span>
|
||||
</code><button type="button">Copy</button></pre>
|
||||
|
||||
<a id="md:examples" class="tsd-anchor"></a><h2 class="tsd-anchor-link">Examples<a href="#md:examples" aria-label="Permalink" class="tsd-anchor-icon"><svg viewBox="0 0 24 24"><use href="assets/icons.svg#icon-anchor"></use></svg></a></h2><a id="md:langgraph-multi-agent-system" class="tsd-anchor"></a><h3 class="tsd-anchor-link">LangGraph Multi-Agent System<a href="#md:langgraph-multi-agent-system" aria-label="Permalink" class="tsd-anchor-icon"><svg viewBox="0 0 24 24"><use href="assets/icons.svg#icon-anchor"></use></svg></a></h3><p>The repository includes an advanced example of building a multi-agent system using LangGraph and Solana Agent Kit. Located in <code>examples/agent-kit-langgraph</code>, this example demonstrates:</p>
|
||||
<a id="examples" class="tsd-anchor"></a><h2 class="tsd-anchor-link">Examples<a href="#examples" aria-label="Permalink" class="tsd-anchor-icon"><svg viewBox="0 0 24 24"><use href="assets/icons.svg#icon-anchor"></use></svg></a></h2><a id="langgraph-multi-agent-system" class="tsd-anchor"></a><h3 class="tsd-anchor-link">LangGraph Multi-Agent System<a href="#langgraph-multi-agent-system" aria-label="Permalink" class="tsd-anchor-icon"><svg viewBox="0 0 24 24"><use href="assets/icons.svg#icon-anchor"></use></svg></a></h3><p>The repository includes an advanced example of building a multi-agent system using LangGraph and Solana Agent Kit. Located in <code>examples/agent-kit-langgraph</code>, this example demonstrates:</p>
|
||||
<ul>
|
||||
<li>Multi-agent architecture using LangGraph's StateGraph</li>
|
||||
<li>Specialized agents for different tasks:
|
||||
@@ -140,7 +141,7 @@
|
||||
<li>Environment-based configuration</li>
|
||||
</ul>
|
||||
<p>Check out the <a href="examples/agent-kit-langgraph">LangGraph example</a> for a complete implementation of an advanced Solana agent system.</p>
|
||||
<a id="md:dependencies" class="tsd-anchor"></a><h2 class="tsd-anchor-link">Dependencies<a href="#md:dependencies" aria-label="Permalink" class="tsd-anchor-icon"><svg viewBox="0 0 24 24"><use href="assets/icons.svg#icon-anchor"></use></svg></a></h2><p>The toolkit relies on several key Solana and Metaplex libraries:</p>
|
||||
<a id="dependencies" class="tsd-anchor"></a><h2 class="tsd-anchor-link">Dependencies<a href="#dependencies" aria-label="Permalink" class="tsd-anchor-icon"><svg viewBox="0 0 24 24"><use href="assets/icons.svg#icon-anchor"></use></svg></a></h2><p>The toolkit relies on several key Solana and Metaplex libraries:</p>
|
||||
<ul>
|
||||
<li>@solana/web3.js</li>
|
||||
<li>@solana/spl-token</li>
|
||||
@@ -151,12 +152,12 @@
|
||||
<li>@lightprotocol/stateless.js</li>
|
||||
<li>@pythnetwork/price-service-client</li>
|
||||
</ul>
|
||||
<a id="md:contributing" class="tsd-anchor"></a><h2 class="tsd-anchor-link">Contributing<a href="#md:contributing" aria-label="Permalink" class="tsd-anchor-icon"><svg viewBox="0 0 24 24"><use href="assets/icons.svg#icon-anchor"></use></svg></a></h2><p>Contributions are welcome! Please feel free to submit a Pull Request.
|
||||
<a id="contributing" class="tsd-anchor"></a><h2 class="tsd-anchor-link">Contributing<a href="#contributing" aria-label="Permalink" class="tsd-anchor-icon"><svg viewBox="0 0 24 24"><use href="assets/icons.svg#icon-anchor"></use></svg></a></h2><p>Contributions are welcome! Please feel free to submit a Pull Request.
|
||||
Refer to <a href="media/CONTRIBUTING.md">CONTRIBUTING.md</a> for detailed guidelines on how to contribute to this project.</p>
|
||||
<a id="md:contributors" class="tsd-anchor"></a><h2 class="tsd-anchor-link">Contributors<a href="#md:contributors" aria-label="Permalink" class="tsd-anchor-icon"><svg viewBox="0 0 24 24"><use href="assets/icons.svg#icon-anchor"></use></svg></a></h2><a href="https://github.com/sendaifun/solana-agent-kit/graphs/contributors">
|
||||
<a id="contributors" class="tsd-anchor"></a><h2 class="tsd-anchor-link">Contributors<a href="#contributors" aria-label="Permalink" class="tsd-anchor-icon"><svg viewBox="0 0 24 24"><use href="assets/icons.svg#icon-anchor"></use></svg></a></h2><a href="https://github.com/sendaifun/solana-agent-kit/graphs/contributors">
|
||||
<img src="https://contrib.rocks/image?repo=sendaifun/solana-agent-kit" />
|
||||
</a>
|
||||
<a id="md:star-history" class="tsd-anchor"></a><h2 class="tsd-anchor-link">Star History<a href="#md:star-history" aria-label="Permalink" class="tsd-anchor-icon"><svg viewBox="0 0 24 24"><use href="assets/icons.svg#icon-anchor"></use></svg></a></h2><p><a href="https://star-history.com/#sendaifun/solana-agent-kit&Date" target="_blank" class="external"><img src="https://api.star-history.com/svg?repos=sendaifun/solana-agent-kit&type=Date" alt="Star History Chart"></a></p>
|
||||
<a id="md:license" class="tsd-anchor"></a><h2 class="tsd-anchor-link">License<a href="#md:license" aria-label="Permalink" class="tsd-anchor-icon"><svg viewBox="0 0 24 24"><use href="assets/icons.svg#icon-anchor"></use></svg></a></h2><p>Apache-2 License</p>
|
||||
<a id="md:security" class="tsd-anchor"></a><h2 class="tsd-anchor-link">Security<a href="#md:security" aria-label="Permalink" class="tsd-anchor-icon"><svg viewBox="0 0 24 24"><use href="assets/icons.svg#icon-anchor"></use></svg></a></h2><p>This toolkit handles private keys and transactions. Always ensure you're using it in a secure environment and never share your private keys.</p>
|
||||
</div></div><div class="col-sidebar"><div class="page-menu"><div class="tsd-navigation settings"><details class="tsd-accordion"><summary class="tsd-accordion-summary"><h3><svg width="20" height="20" viewBox="0 0 24 24" fill="none"><use href="assets/icons.svg#icon-chevronDown"></use></svg>Settings</h3></summary><div class="tsd-accordion-details"><div class="tsd-filter-visibility"><span class="settings-label">Member Visibility</span><ul id="tsd-filter-options"><li class="tsd-filter-item"><label class="tsd-filter-input"><input type="checkbox" id="tsd-filter-protected" name="protected"/><svg width="32" height="32" viewBox="0 0 32 32" aria-hidden="true"><rect class="tsd-checkbox-background" width="30" height="30" x="1" y="1" rx="6" fill="none"></rect><path class="tsd-checkbox-checkmark" d="M8.35422 16.8214L13.2143 21.75L24.6458 10.25" stroke="none" stroke-width="3.5" stroke-linejoin="round" fill="none"></path></svg><span>Protected</span></label></li><li class="tsd-filter-item"><label class="tsd-filter-input"><input type="checkbox" id="tsd-filter-inherited" name="inherited" checked/><svg width="32" height="32" viewBox="0 0 32 32" aria-hidden="true"><rect class="tsd-checkbox-background" width="30" height="30" x="1" y="1" rx="6" fill="none"></rect><path class="tsd-checkbox-checkmark" d="M8.35422 16.8214L13.2143 21.75L24.6458 10.25" stroke="none" stroke-width="3.5" stroke-linejoin="round" fill="none"></path></svg><span>Inherited</span></label></li><li class="tsd-filter-item"><label class="tsd-filter-input"><input type="checkbox" id="tsd-filter-external" name="external"/><svg width="32" height="32" viewBox="0 0 32 32" aria-hidden="true"><rect class="tsd-checkbox-background" width="30" height="30" x="1" y="1" rx="6" fill="none"></rect><path class="tsd-checkbox-checkmark" d="M8.35422 16.8214L13.2143 21.75L24.6458 10.25" stroke="none" stroke-width="3.5" stroke-linejoin="round" fill="none"></path></svg><span>External</span></label></li></ul></div><div class="tsd-theme-toggle"><label class="settings-label" for="tsd-theme">Theme</label><select id="tsd-theme"><option value="os">OS</option><option value="light">Light</option><option value="dark">Dark</option></select></div></div></details></div><details open class="tsd-accordion tsd-page-navigation"><summary class="tsd-accordion-summary"><h3><svg width="20" height="20" viewBox="0 0 24 24" fill="none"><use href="assets/icons.svg#icon-chevronDown"></use></svg>On This Page</h3></summary><div class="tsd-accordion-details"><a href="#md:solana-agent-kit"><span>Solana <wbr/>Agent <wbr/>Kit</span></a><ul><li><a href="#md:🔧-core-blockchain-features"><span>🔧 <wbr/>Core <wbr/>Blockchain <wbr/>Features</span></a></li><li><a href="#md:🤖-ai-integration-features"><span>🤖 AI <wbr/>Integration <wbr/>Features</span></a></li><li><a href="#md:📦-installation"><span>📦 <wbr/>Installation</span></a></li><li><a href="#md:quick-start"><span>Quick <wbr/>Start</span></a></li><li><a href="#md:usage-examples"><span>Usage <wbr/>Examples</span></a></li><li><ul><li><a href="#md:deploy-a-new-token"><span>Deploy a <wbr/>New <wbr/>Token</span></a></li><li><a href="#md:create-nft-collection"><span>Create NFT <wbr/>Collection</span></a></li><li><a href="#md:swap-tokens"><span>Swap <wbr/>Tokens</span></a></li><li><a href="#md:lend-tokens"><span>Lend <wbr/>Tokens</span></a></li><li><a href="#md:stake-sol"><span>Stake SOL</span></a></li><li><a href="#md:send-an-spl-token-airdrop-via-zk-compression"><span>Send an SPL <wbr/>Token <wbr/>Airdrop via ZK <wbr/>Compression</span></a></li><li><a href="#md:fetch-price-data-from-pyth"><span>Fetch <wbr/>Price <wbr/>Data from <wbr/>Pyth</span></a></li></ul></li><li><a href="#md:examples"><span>Examples</span></a></li><li><ul><li><a href="#md:langgraph-multi-agent-system"><span>Lang<wbr/>Graph <wbr/>Multi-<wbr/>Agent <wbr/>System</span></a></li></ul></li><li><a href="#md:dependencies"><span>Dependencies</span></a></li><li><a href="#md:contributing"><span>Contributing</span></a></li><li><a href="#md:contributors"><span>Contributors</span></a></li><li><a href="#md:star-history"><span>Star <wbr/>History</span></a></li><li><a href="#md:license"><span>License</span></a></li><li><a href="#md:security"><span>Security</span></a></li></ul></div></details></div><div class="site-menu"><nav class="tsd-navigation"><a href="modules.html" class="current"><svg class="tsd-kind-icon" viewBox="0 0 24 24"><use href="assets/icons.svg#icon-1"></use></svg><span>solana-agent-kit</span></a><ul class="tsd-small-nested-navigation" id="tsd-nav-container" data-base="."><li>Loading...</li></ul></nav></div></div></div><footer><p class="tsd-generator">Generated using <a href="https://typedoc.org/" target="_blank">TypeDoc</a></p></footer><div class="overlay"></div></body></html>
|
||||
<a id="star-history" class="tsd-anchor"></a><h2 class="tsd-anchor-link">Star History<a href="#star-history" aria-label="Permalink" class="tsd-anchor-icon"><svg viewBox="0 0 24 24"><use href="assets/icons.svg#icon-anchor"></use></svg></a></h2><p><a href="https://star-history.com/#sendaifun/solana-agent-kit&Date"><img src="https://api.star-history.com/svg?repos=sendaifun/solana-agent-kit&type=Date" alt="Star History Chart"></a></p>
|
||||
<a id="license" class="tsd-anchor"></a><h2 class="tsd-anchor-link">License<a href="#license" aria-label="Permalink" class="tsd-anchor-icon"><svg viewBox="0 0 24 24"><use href="assets/icons.svg#icon-anchor"></use></svg></a></h2><p>Apache-2 License</p>
|
||||
<a id="security" class="tsd-anchor"></a><h2 class="tsd-anchor-link">Security<a href="#security" aria-label="Permalink" class="tsd-anchor-icon"><svg viewBox="0 0 24 24"><use href="assets/icons.svg#icon-anchor"></use></svg></a></h2><p>This toolkit handles private keys and transactions. Always ensure you're using it in a secure environment and never share your private keys.</p>
|
||||
</div></div><div class="col-sidebar"><div class="page-menu"><div class="tsd-navigation settings"><details class="tsd-accordion"><summary class="tsd-accordion-summary"><h3><svg width="20" height="20" viewBox="0 0 24 24" fill="none"><use href="assets/icons.svg#icon-chevronDown"></use></svg>Settings</h3></summary><div class="tsd-accordion-details"><div class="tsd-filter-visibility"><span class="settings-label">Member Visibility</span><ul id="tsd-filter-options"><li class="tsd-filter-item"><label class="tsd-filter-input"><input type="checkbox" id="tsd-filter-protected" name="protected"/><svg width="32" height="32" viewBox="0 0 32 32" aria-hidden="true"><rect class="tsd-checkbox-background" width="30" height="30" x="1" y="1" rx="6" fill="none"></rect><path class="tsd-checkbox-checkmark" d="M8.35422 16.8214L13.2143 21.75L24.6458 10.25" stroke="none" stroke-width="3.5" stroke-linejoin="round" fill="none"></path></svg><span>Protected</span></label></li><li class="tsd-filter-item"><label class="tsd-filter-input"><input type="checkbox" id="tsd-filter-inherited" name="inherited" checked/><svg width="32" height="32" viewBox="0 0 32 32" aria-hidden="true"><rect class="tsd-checkbox-background" width="30" height="30" x="1" y="1" rx="6" fill="none"></rect><path class="tsd-checkbox-checkmark" d="M8.35422 16.8214L13.2143 21.75L24.6458 10.25" stroke="none" stroke-width="3.5" stroke-linejoin="round" fill="none"></path></svg><span>Inherited</span></label></li><li class="tsd-filter-item"><label class="tsd-filter-input"><input type="checkbox" id="tsd-filter-external" name="external"/><svg width="32" height="32" viewBox="0 0 32 32" aria-hidden="true"><rect class="tsd-checkbox-background" width="30" height="30" x="1" y="1" rx="6" fill="none"></rect><path class="tsd-checkbox-checkmark" d="M8.35422 16.8214L13.2143 21.75L24.6458 10.25" stroke="none" stroke-width="3.5" stroke-linejoin="round" fill="none"></path></svg><span>External</span></label></li></ul></div><div class="tsd-theme-toggle"><label class="settings-label" for="tsd-theme">Theme</label><select id="tsd-theme"><option value="os">OS</option><option value="light">Light</option><option value="dark">Dark</option></select></div></div></details></div><details open class="tsd-accordion tsd-page-navigation"><summary class="tsd-accordion-summary"><h3><svg width="20" height="20" viewBox="0 0 24 24" fill="none"><use href="assets/icons.svg#icon-chevronDown"></use></svg>On This Page</h3></summary><div class="tsd-accordion-details"><a href="#solana-agent-kit"><span>Solana <wbr/>Agent <wbr/>Kit</span></a><ul><li><a href="#🔧-core-blockchain-features"><span>🔧 <wbr/>Core <wbr/>Blockchain <wbr/>Features</span></a></li><li><a href="#🤖-ai-integration-features"><span>🤖 AI <wbr/>Integration <wbr/>Features</span></a></li><li><a href="#📦-installation"><span>📦 <wbr/>Installation</span></a></li><li><a href="#quick-start"><span>Quick <wbr/>Start</span></a></li><li><a href="#usage-examples"><span>Usage <wbr/>Examples</span></a></li><li><ul><li><a href="#deploy-a-new-token"><span>Deploy a <wbr/>New <wbr/>Token</span></a></li><li><a href="#create-nft-collection"><span>Create NFT <wbr/>Collection</span></a></li><li><a href="#swap-tokens"><span>Swap <wbr/>Tokens</span></a></li><li><a href="#lend-tokens"><span>Lend <wbr/>Tokens</span></a></li><li><a href="#stake-sol"><span>Stake SOL</span></a></li><li><a href="#send-an-spl-token-airdrop-via-zk-compression"><span>Send an SPL <wbr/>Token <wbr/>Airdrop via ZK <wbr/>Compression</span></a></li><li><a href="#fetch-price-data-from-pyth"><span>Fetch <wbr/>Price <wbr/>Data from <wbr/>Pyth</span></a></li></ul></li><li><a href="#examples"><span>Examples</span></a></li><li><ul><li><a href="#langgraph-multi-agent-system"><span>Lang<wbr/>Graph <wbr/>Multi-<wbr/>Agent <wbr/>System</span></a></li></ul></li><li><a href="#dependencies"><span>Dependencies</span></a></li><li><a href="#contributing"><span>Contributing</span></a></li><li><a href="#contributors"><span>Contributors</span></a></li><li><a href="#star-history"><span>Star <wbr/>History</span></a></li><li><a href="#license"><span>License</span></a></li><li><a href="#security"><span>Security</span></a></li></ul></div></details></div><div class="site-menu"><nav class="tsd-navigation"><a href="modules.html">solana-agent-kit</a><ul class="tsd-small-nested-navigation" id="tsd-nav-container"><li>Loading...</li></ul></nav></div></div></div><footer><p class="tsd-generator">Generated using <a href="https://typedoc.org/" target="_blank">TypeDoc</a></p></footer><div class="overlay"></div></body></html>
|
||||
|
||||
16
docs/interfaces/Action.html
Normal file
16
docs/interfaces/Action.html
Normal file
@@ -0,0 +1,16 @@
|
||||
<!DOCTYPE html><html class="default" lang="en" data-base=".."><head><meta charset="utf-8"/><meta http-equiv="x-ua-compatible" content="IE=edge"/><title>Action | solana-agent-kit</title><meta name="description" content="Documentation for solana-agent-kit"/><meta name="viewport" content="width=device-width, initial-scale=1"/><link rel="stylesheet" href="../assets/style.css"/><link rel="stylesheet" href="../assets/highlight.css"/><script defer src="../assets/main.js"></script><script async src="../assets/icons.js" id="tsd-icons-script"></script><script async src="../assets/search.js" id="tsd-search-script"></script><script async src="../assets/navigation.js" id="tsd-nav-script"></script></head><body><script>document.documentElement.dataset.theme = localStorage.getItem("tsd-theme") || "os";document.body.style.display="none";setTimeout(() => app?app.showPage():document.body.style.removeProperty("display"),500)</script><header class="tsd-page-toolbar"><div class="tsd-toolbar-contents container"><div class="table-cell" id="tsd-search"><div class="field"><label for="tsd-search-field" class="tsd-widget tsd-toolbar-icon search no-caption"><svg width="16" height="16" viewBox="0 0 16 16" fill="none"><use href="../assets/icons.svg#icon-search"></use></svg></label><input type="text" id="tsd-search-field" aria-label="Search"/></div><div class="field"><div id="tsd-toolbar-links"></div></div><ul class="results"><li class="state loading">Preparing search index...</li><li class="state failure">The search index is not available</li></ul><a href="../index.html" class="title">solana-agent-kit</a></div><div class="table-cell" id="tsd-widgets"><a href="#" class="tsd-widget tsd-toolbar-icon menu no-caption" data-toggle="menu" aria-label="Menu"><svg width="16" height="16" viewBox="0 0 16 16" fill="none"><use href="../assets/icons.svg#icon-menu"></use></svg></a></div></div></header><div class="container container-main"><div class="col-content"><div class="tsd-page-title"><ul class="tsd-breadcrumb"><li><a href="../modules.html">solana-agent-kit</a></li><li><a href="Action.html">Action</a></li></ul><h1>Interface Action</h1></div><section class="tsd-panel tsd-comment"><div class="tsd-comment tsd-typography"><p>Main Action interface inspired by ELIZA
|
||||
This interface makes it easier to implement actions across different frameworks</p>
|
||||
</div><div class="tsd-comment tsd-typography"></div></section><div class="tsd-signature"><span class="tsd-signature-keyword">interface</span> <span class="tsd-kind-interface">Action</span> <span class="tsd-signature-symbol">{</span><br/> <a class="tsd-kind-property" href="Action.html#description">description</a><span class="tsd-signature-symbol">:</span> <span class="tsd-signature-type">string</span><span class="tsd-signature-symbol">;</span><br/> <a class="tsd-kind-property" href="Action.html#examples">examples</a><span class="tsd-signature-symbol">:</span> <a href="ActionExample.html" class="tsd-signature-type tsd-kind-interface">ActionExample</a><span class="tsd-signature-symbol">[]</span><span class="tsd-signature-symbol">[]</span><span class="tsd-signature-symbol">;</span><br/> <a class="tsd-kind-property" href="Action.html#handler">handler</a><span class="tsd-signature-symbol">:</span> <a href="../types/Handler.html" class="tsd-signature-type tsd-kind-type-alias">Handler</a><span class="tsd-signature-symbol">;</span><br/> <a class="tsd-kind-property" href="Action.html#name">name</a><span class="tsd-signature-symbol">:</span> <span class="tsd-signature-type">string</span><span class="tsd-signature-symbol">;</span><br/> <a class="tsd-kind-property" href="Action.html#schema">schema</a><span class="tsd-signature-symbol">:</span> <span class="tsd-signature-type">ZodType</span><span class="tsd-signature-symbol">;</span><br/> <a class="tsd-kind-property" href="Action.html#similes">similes</a><span class="tsd-signature-symbol">:</span> <span class="tsd-signature-type">string</span><span class="tsd-signature-symbol">[]</span><span class="tsd-signature-symbol">;</span><br/><span class="tsd-signature-symbol">}</span></div><aside class="tsd-sources"><ul><li>Defined in <a href="https://github.com/sendaifun/solana-agent-kit/blob/16f7dc62a5f443fd721656fd7eb6aa1de8fb1185/src/types/action.ts#L25">types/action.ts:25</a></li></ul></aside><section class="tsd-panel-group tsd-index-group"><section class="tsd-panel tsd-index-panel"><details class="tsd-index-content tsd-accordion" open><summary class="tsd-accordion-summary tsd-index-summary"><h5 class="tsd-index-heading uppercase" role="button" aria-expanded="false" tabIndex="0"><svg width="16" height="16" viewBox="0 0 16 16" fill="none"><use href="../assets/icons.svg#icon-chevronSmall"></use></svg> Index</h5></summary><div class="tsd-accordion-details"><section class="tsd-index-section"><h3 class="tsd-index-heading">Properties</h3><div class="tsd-index-list"><a href="Action.html#description" class="tsd-index-link"><svg class="tsd-kind-icon" viewBox="0 0 24 24"><use href="../assets/icons.svg#icon-1024"></use></svg><span>description</span></a>
|
||||
<a href="Action.html#examples" class="tsd-index-link"><svg class="tsd-kind-icon" viewBox="0 0 24 24"><use href="../assets/icons.svg#icon-1024"></use></svg><span>examples</span></a>
|
||||
<a href="Action.html#handler" class="tsd-index-link"><svg class="tsd-kind-icon" viewBox="0 0 24 24"><use href="../assets/icons.svg#icon-1024"></use></svg><span>handler</span></a>
|
||||
<a href="Action.html#name" class="tsd-index-link"><svg class="tsd-kind-icon" viewBox="0 0 24 24"><use href="../assets/icons.svg#icon-1024"></use></svg><span>name</span></a>
|
||||
<a href="Action.html#schema" class="tsd-index-link"><svg class="tsd-kind-icon" viewBox="0 0 24 24"><use href="../assets/icons.svg#icon-1024"></use></svg><span>schema</span></a>
|
||||
<a href="Action.html#similes" class="tsd-index-link"><svg class="tsd-kind-icon" viewBox="0 0 24 24"><use href="../assets/icons.svg#icon-1024"></use></svg><span>similes</span></a>
|
||||
</div></section></div></details></section></section><details class="tsd-panel-group tsd-member-group tsd-accordion" open><summary class="tsd-accordion-summary" data-key="section-Properties"><h2><svg width="20" height="20" viewBox="0 0 24 24" fill="none"><use href="../assets/icons.svg#icon-chevronDown"></use></svg> Properties</h2></summary><section><section class="tsd-panel tsd-member"><a id="description" class="tsd-anchor"></a><h3 class="tsd-anchor-link"><span>description</span><a href="#description" aria-label="Permalink" class="tsd-anchor-icon"><svg viewBox="0 0 24 24"><use href="../assets/icons.svg#icon-anchor"></use></svg></a></h3><div class="tsd-signature"><span class="tsd-kind-property">description</span><span class="tsd-signature-symbol">:</span> <span class="tsd-signature-type">string</span></div><div class="tsd-comment tsd-typography"><p>Detailed description of what the action does</p>
|
||||
</div><div class="tsd-comment tsd-typography"></div><aside class="tsd-sources"><ul><li>Defined in <a href="https://github.com/sendaifun/solana-agent-kit/blob/16f7dc62a5f443fd721656fd7eb6aa1de8fb1185/src/types/action.ts#L39">types/action.ts:39</a></li></ul></aside></section><section class="tsd-panel tsd-member"><a id="examples" class="tsd-anchor"></a><h3 class="tsd-anchor-link"><span>examples</span><a href="#examples" aria-label="Permalink" class="tsd-anchor-icon"><svg viewBox="0 0 24 24"><use href="../assets/icons.svg#icon-anchor"></use></svg></a></h3><div class="tsd-signature"><span class="tsd-kind-property">examples</span><span class="tsd-signature-symbol">:</span> <a href="ActionExample.html" class="tsd-signature-type tsd-kind-interface">ActionExample</a><span class="tsd-signature-symbol">[]</span><span class="tsd-signature-symbol">[]</span></div><div class="tsd-comment tsd-typography"><p>Array of example inputs and outputs for the action
|
||||
Each inner array represents a group of related examples</p>
|
||||
</div><div class="tsd-comment tsd-typography"></div><aside class="tsd-sources"><ul><li>Defined in <a href="https://github.com/sendaifun/solana-agent-kit/blob/16f7dc62a5f443fd721656fd7eb6aa1de8fb1185/src/types/action.ts#L45">types/action.ts:45</a></li></ul></aside></section><section class="tsd-panel tsd-member"><a id="handler" class="tsd-anchor"></a><h3 class="tsd-anchor-link"><span>handler</span><a href="#handler" aria-label="Permalink" class="tsd-anchor-icon"><svg viewBox="0 0 24 24"><use href="../assets/icons.svg#icon-anchor"></use></svg></a></h3><div class="tsd-signature"><span class="tsd-kind-property">handler</span><span class="tsd-signature-symbol">:</span> <a href="../types/Handler.html" class="tsd-signature-type tsd-kind-type-alias">Handler</a></div><div class="tsd-comment tsd-typography"><p>Function that executes the action</p>
|
||||
</div><div class="tsd-comment tsd-typography"></div><aside class="tsd-sources"><ul><li>Defined in <a href="https://github.com/sendaifun/solana-agent-kit/blob/16f7dc62a5f443fd721656fd7eb6aa1de8fb1185/src/types/action.ts#L55">types/action.ts:55</a></li></ul></aside></section><section class="tsd-panel tsd-member"><a id="name" class="tsd-anchor"></a><h3 class="tsd-anchor-link"><span>name</span><a href="#name" aria-label="Permalink" class="tsd-anchor-icon"><svg viewBox="0 0 24 24"><use href="../assets/icons.svg#icon-anchor"></use></svg></a></h3><div class="tsd-signature"><span class="tsd-kind-property">name</span><span class="tsd-signature-symbol">:</span> <span class="tsd-signature-type">string</span></div><div class="tsd-comment tsd-typography"><p>Unique name of the action</p>
|
||||
</div><div class="tsd-comment tsd-typography"></div><aside class="tsd-sources"><ul><li>Defined in <a href="https://github.com/sendaifun/solana-agent-kit/blob/16f7dc62a5f443fd721656fd7eb6aa1de8fb1185/src/types/action.ts#L29">types/action.ts:29</a></li></ul></aside></section><section class="tsd-panel tsd-member"><a id="schema" class="tsd-anchor"></a><h3 class="tsd-anchor-link"><span>schema</span><a href="#schema" aria-label="Permalink" class="tsd-anchor-icon"><svg viewBox="0 0 24 24"><use href="../assets/icons.svg#icon-anchor"></use></svg></a></h3><div class="tsd-signature"><span class="tsd-kind-property">schema</span><span class="tsd-signature-symbol">:</span> <span class="tsd-signature-type">ZodType</span></div><div class="tsd-comment tsd-typography"><p>Zod schema for input validation</p>
|
||||
</div><div class="tsd-comment tsd-typography"></div><aside class="tsd-sources"><ul><li>Defined in <a href="https://github.com/sendaifun/solana-agent-kit/blob/16f7dc62a5f443fd721656fd7eb6aa1de8fb1185/src/types/action.ts#L50">types/action.ts:50</a></li></ul></aside></section><section class="tsd-panel tsd-member"><a id="similes" class="tsd-anchor"></a><h3 class="tsd-anchor-link"><span>similes</span><a href="#similes" aria-label="Permalink" class="tsd-anchor-icon"><svg viewBox="0 0 24 24"><use href="../assets/icons.svg#icon-anchor"></use></svg></a></h3><div class="tsd-signature"><span class="tsd-kind-property">similes</span><span class="tsd-signature-symbol">:</span> <span class="tsd-signature-type">string</span><span class="tsd-signature-symbol">[]</span></div><div class="tsd-comment tsd-typography"><p>Alternative names/phrases that can trigger this action</p>
|
||||
</div><div class="tsd-comment tsd-typography"></div><aside class="tsd-sources"><ul><li>Defined in <a href="https://github.com/sendaifun/solana-agent-kit/blob/16f7dc62a5f443fd721656fd7eb6aa1de8fb1185/src/types/action.ts#L34">types/action.ts:34</a></li></ul></aside></section></section></details></div><div class="col-sidebar"><div class="page-menu"><div class="tsd-navigation settings"><details class="tsd-accordion"><summary class="tsd-accordion-summary"><h3><svg width="20" height="20" viewBox="0 0 24 24" fill="none"><use href="../assets/icons.svg#icon-chevronDown"></use></svg>Settings</h3></summary><div class="tsd-accordion-details"><div class="tsd-filter-visibility"><span class="settings-label">Member Visibility</span><ul id="tsd-filter-options"><li class="tsd-filter-item"><label class="tsd-filter-input"><input type="checkbox" id="tsd-filter-protected" name="protected"/><svg width="32" height="32" viewBox="0 0 32 32" aria-hidden="true"><rect class="tsd-checkbox-background" width="30" height="30" x="1" y="1" rx="6" fill="none"></rect><path class="tsd-checkbox-checkmark" d="M8.35422 16.8214L13.2143 21.75L24.6458 10.25" stroke="none" stroke-width="3.5" stroke-linejoin="round" fill="none"></path></svg><span>Protected</span></label></li><li class="tsd-filter-item"><label class="tsd-filter-input"><input type="checkbox" id="tsd-filter-inherited" name="inherited" checked/><svg width="32" height="32" viewBox="0 0 32 32" aria-hidden="true"><rect class="tsd-checkbox-background" width="30" height="30" x="1" y="1" rx="6" fill="none"></rect><path class="tsd-checkbox-checkmark" d="M8.35422 16.8214L13.2143 21.75L24.6458 10.25" stroke="none" stroke-width="3.5" stroke-linejoin="round" fill="none"></path></svg><span>Inherited</span></label></li><li class="tsd-filter-item"><label class="tsd-filter-input"><input type="checkbox" id="tsd-filter-external" name="external"/><svg width="32" height="32" viewBox="0 0 32 32" aria-hidden="true"><rect class="tsd-checkbox-background" width="30" height="30" x="1" y="1" rx="6" fill="none"></rect><path class="tsd-checkbox-checkmark" d="M8.35422 16.8214L13.2143 21.75L24.6458 10.25" stroke="none" stroke-width="3.5" stroke-linejoin="round" fill="none"></path></svg><span>External</span></label></li></ul></div><div class="tsd-theme-toggle"><label class="settings-label" for="tsd-theme">Theme</label><select id="tsd-theme"><option value="os">OS</option><option value="light">Light</option><option value="dark">Dark</option></select></div></div></details></div><details open class="tsd-accordion tsd-page-navigation"><summary class="tsd-accordion-summary"><h3><svg width="20" height="20" viewBox="0 0 24 24" fill="none"><use href="../assets/icons.svg#icon-chevronDown"></use></svg>On This Page</h3></summary><div class="tsd-accordion-details"><details open class="tsd-accordion tsd-page-navigation-section"><summary class="tsd-accordion-summary" data-key="section-Properties"><svg width="20" height="20" viewBox="0 0 24 24" fill="none"><use href="../assets/icons.svg#icon-chevronDown"></use></svg>Properties</summary><div><a href="#description" class=""><svg class="tsd-kind-icon" viewBox="0 0 24 24"><use href="../assets/icons.svg#icon-1024"></use></svg><span>description</span></a><a href="#examples" class=""><svg class="tsd-kind-icon" viewBox="0 0 24 24"><use href="../assets/icons.svg#icon-1024"></use></svg><span>examples</span></a><a href="#handler" class=""><svg class="tsd-kind-icon" viewBox="0 0 24 24"><use href="../assets/icons.svg#icon-1024"></use></svg><span>handler</span></a><a href="#name" class=""><svg class="tsd-kind-icon" viewBox="0 0 24 24"><use href="../assets/icons.svg#icon-1024"></use></svg><span>name</span></a><a href="#schema" class=""><svg class="tsd-kind-icon" viewBox="0 0 24 24"><use href="../assets/icons.svg#icon-1024"></use></svg><span>schema</span></a><a href="#similes" class=""><svg class="tsd-kind-icon" viewBox="0 0 24 24"><use href="../assets/icons.svg#icon-1024"></use></svg><span>similes</span></a></div></details></div></details></div><div class="site-menu"><nav class="tsd-navigation"><a href="../modules.html">solana-agent-kit</a><ul class="tsd-small-nested-navigation" id="tsd-nav-container"><li>Loading...</li></ul></nav></div></div></div><footer><p class="tsd-generator">Generated using <a href="https://typedoc.org/" target="_blank">TypeDoc</a></p></footer><div class="overlay"></div></body></html>
|
||||
5
docs/interfaces/ActionExample.html
Normal file
5
docs/interfaces/ActionExample.html
Normal file
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
4
docs/interfaces/Config.html
Normal file
4
docs/interfaces/Config.html
Normal file
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
2
docs/types/Handler.html
Normal file
2
docs/types/Handler.html
Normal file
File diff suppressed because one or more lines are too long
1
docs/variables/actions.html
Normal file
1
docs/variables/actions.html
Normal file
File diff suppressed because one or more lines are too long
4
examples/agent-kit-nextjs-langchain/.env.example
Normal file
4
examples/agent-kit-nextjs-langchain/.env.example
Normal file
@@ -0,0 +1,4 @@
|
||||
LANGCHAIN_CALLBACKS_BACKGROUND=false
|
||||
OPENAI_API_KEY=
|
||||
RPC_URL=
|
||||
SOLANA_PRIVATE_KEY=
|
||||
3
examples/agent-kit-nextjs-langchain/.eslintrc.json
Normal file
3
examples/agent-kit-nextjs-langchain/.eslintrc.json
Normal file
@@ -0,0 +1,3 @@
|
||||
{
|
||||
"extends": "next/core-web-vitals"
|
||||
}
|
||||
43
examples/agent-kit-nextjs-langchain/.gitignore
vendored
Normal file
43
examples/agent-kit-nextjs-langchain/.gitignore
vendored
Normal file
@@ -0,0 +1,43 @@
|
||||
# See https://help.github.com/articles/ignoring-files/ for more about ignoring files.
|
||||
|
||||
# dependencies
|
||||
/node_modules
|
||||
/.pnp
|
||||
.pnp.js
|
||||
|
||||
# testing
|
||||
/coverage
|
||||
|
||||
# next.js
|
||||
/.next/
|
||||
/out/
|
||||
|
||||
# production
|
||||
/build
|
||||
|
||||
# misc
|
||||
.DS_Store
|
||||
*.pem
|
||||
|
||||
# debug
|
||||
npm-debug.log*
|
||||
yarn-debug.log*
|
||||
yarn-error.log*
|
||||
|
||||
# local env files
|
||||
.env*.local
|
||||
|
||||
# vercel
|
||||
.vercel
|
||||
|
||||
# typescript
|
||||
*.tsbuildinfo
|
||||
next-env.d.ts
|
||||
|
||||
.yarn/*
|
||||
!.yarn/patches
|
||||
!.yarn/plugins
|
||||
!.yarn/releases
|
||||
!.yarn/sdks
|
||||
!.yarn/versions
|
||||
.env
|
||||
1
examples/agent-kit-nextjs-langchain/.prettierrc.json
Normal file
1
examples/agent-kit-nextjs-langchain/.prettierrc.json
Normal file
@@ -0,0 +1 @@
|
||||
{}
|
||||
21
examples/agent-kit-nextjs-langchain/LICENSE
Normal file
21
examples/agent-kit-nextjs-langchain/LICENSE
Normal file
@@ -0,0 +1,21 @@
|
||||
MIT License
|
||||
|
||||
Copyright (c) 2023 LangChain
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
of this software and associated documentation files (the "Software"), to deal
|
||||
in the Software without restriction, including without limitation the rights
|
||||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
copies of the Software, and to permit persons to whom the Software is
|
||||
furnished to do so, subject to the following conditions:
|
||||
|
||||
The above copyright notice and this permission notice shall be included in all
|
||||
copies or substantial portions of the Software.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||
SOFTWARE.
|
||||
56
examples/agent-kit-nextjs-langchain/README.md
Normal file
56
examples/agent-kit-nextjs-langchain/README.md
Normal file
@@ -0,0 +1,56 @@
|
||||
# SolanaAgentKit 🦜️🔗 LangChain + Next.js Starter Template
|
||||
|
||||
[](https://codespaces.new/michaelessiet/solana-agent-nextjs-starter-langchain)
|
||||
[](https://vercel.com/new/clone?repository-url=https%3A%2F%2Fgithub.com%2Fsendaifun%2Fsolana-agent-kit%2Ftree%2Fmain%2Fexamples%2Fagent-kit-nextjs-langchain&env=OPENAI_API_KEY,RPC_URL,SOLANA_PRIVATE_KEY&project-name=solana-agent-kit&repository-name=sak-yourprojectname)
|
||||
|
||||
This template scaffolds a SolanaAgentKit + LangChain.js + Next.js starter app.
|
||||
|
||||
The agent uses [LangGraph.js](https://langchain-ai.github.io/langgraphjs/), LangChain's framework for building agentic workflows. They use preconfigured helper functions to minimize boilerplate, but you can replace them with custom graphs as desired.
|
||||
|
||||

|
||||
|
||||
It's free-tier friendly too! Check out the [bundle size stats below](#-bundle-size).
|
||||
|
||||
## 🚀 Getting Started
|
||||
|
||||
First, clone this repo and download it locally.
|
||||
|
||||
Next, you'll need to set up environment variables in your repo's `.env.local` file. Copy the `.env.example` file to `.env.local`.
|
||||
To start, you'll just need to add your OpenAI API key, Solana RPC URL and wallet private key in base 58 string form.
|
||||
|
||||
Next, install the required packages using your preferred package manager (e.g. `pnpm`).
|
||||
|
||||
```bash
|
||||
pnpm install
|
||||
```
|
||||
|
||||
Now you're ready to run the development server:
|
||||
|
||||
```bash
|
||||
pnpm dev
|
||||
```
|
||||
|
||||
Open [http://localhost:3000](http://localhost:3000) with your browser to see the result! Ask the bot something and you'll see a streamed response:
|
||||
|
||||

|
||||
|
||||
You can start editing the page by modifying `app/page.tsx`. The page auto-updates as you edit the file.
|
||||
|
||||
Backend logic lives in `app/api/chat/route.ts`. From here, you can change the prompt and model, or add other modules and logic.
|
||||
|
||||
## 📚 Learn More
|
||||
|
||||
To learn more about what you can do with SolanaAgentKit and LangChain.js, check out the docs here:
|
||||
|
||||
- https://github.com/sendaifun/solana-agent-kit
|
||||
- https://js.langchain.com/docs/
|
||||
|
||||
## ▲ Deploy on Vercel
|
||||
|
||||
When ready, you can deploy your app on the [Vercel Platform](https://vercel.com/new?utm_medium=default-template&filter=next.js&utm_source=create-next-app&utm_campaign=create-next-app-readme).
|
||||
|
||||
Check out the [Next.js deployment documentation](https://nextjs.org/docs/deployment) for more details.
|
||||
|
||||
## Thank You!
|
||||
|
||||
Thanks for reading! If you have any questions or comments, please drop an issue on this repo or reach out to us on [X](https://x.com/sendaifun)
|
||||
71
examples/agent-kit-nextjs-langchain/app/api/chat/route.ts
Normal file
71
examples/agent-kit-nextjs-langchain/app/api/chat/route.ts
Normal file
@@ -0,0 +1,71 @@
|
||||
import { NextRequest, NextResponse } from "next/server";
|
||||
import { ChatOpenAI } from "@langchain/openai";
|
||||
import { MemorySaver } from "@langchain/langgraph";
|
||||
import { createReactAgent } from "@langchain/langgraph/prebuilt";
|
||||
import { SolanaAgentKit, createSolanaTools } from "solana-agent-kit";
|
||||
|
||||
const llm = new ChatOpenAI({
|
||||
temperature: 0.7,
|
||||
model: "gpt-4o-mini",
|
||||
});
|
||||
|
||||
const solanaAgent = new SolanaAgentKit(
|
||||
process.env.SOLANA_PRIVATE_KEY!,
|
||||
process.env.RPC_URL,
|
||||
process.env.OPENAI_API_KEY!,
|
||||
);
|
||||
|
||||
const tools = createSolanaTools(solanaAgent);
|
||||
const memory = new MemorySaver();
|
||||
|
||||
const agent = createReactAgent({
|
||||
llm,
|
||||
tools,
|
||||
checkpointSaver: memory,
|
||||
messageModifier: `
|
||||
You are a helpful agent that can interact onchain using the Solana Agent Kit. You are
|
||||
empowered to interact onchain using your tools. If you ever need funds, you can request them from the
|
||||
faucet. If not, you can provide your wallet details and request funds from the user. If there is a 5XX
|
||||
(internal) HTTP error code, ask the user to try again later. If someone asks you to do something you
|
||||
can't do with your currently available tools, you must say so, and encourage them to implement it
|
||||
themselves using the Solana Agent Kit, recommend they go to https://www.solanaagentkit.xyz for more information. Be
|
||||
concise and helpful with your responses. Refrain from restating your tools' descriptions unless it is explicitly requested.
|
||||
`,
|
||||
});
|
||||
|
||||
export async function POST(req: NextRequest) {
|
||||
try {
|
||||
const body = await req.json();
|
||||
const messages = body.messages ?? [];
|
||||
|
||||
const eventStream = agent.streamEvents(
|
||||
{
|
||||
messages,
|
||||
},
|
||||
{
|
||||
version: "v2",
|
||||
configurable: {
|
||||
thread_id: "Solana Agent Kit!",
|
||||
},
|
||||
},
|
||||
);
|
||||
|
||||
const textEncoder = new TextEncoder();
|
||||
const transformStream = new ReadableStream({
|
||||
async start(controller) {
|
||||
for await (const { event, data } of eventStream) {
|
||||
if (event === "on_chat_model_stream") {
|
||||
if (!!data.chunk.content) {
|
||||
controller.enqueue(textEncoder.encode(data.chunk.content));
|
||||
}
|
||||
}
|
||||
}
|
||||
controller.close();
|
||||
},
|
||||
});
|
||||
|
||||
return new Response(transformStream);
|
||||
} catch (e: any) {
|
||||
return NextResponse.json({ error: e.message }, { status: e.status ?? 500 });
|
||||
}
|
||||
}
|
||||
33
examples/agent-kit-nextjs-langchain/app/globals.css
Normal file
33
examples/agent-kit-nextjs-langchain/app/globals.css
Normal file
@@ -0,0 +1,33 @@
|
||||
@tailwind base;
|
||||
@tailwind components;
|
||||
@tailwind utilities;
|
||||
|
||||
body {
|
||||
color: #f8f8f8;
|
||||
background: #131318;
|
||||
}
|
||||
|
||||
body input,
|
||||
body textarea {
|
||||
color: black;
|
||||
}
|
||||
|
||||
a {
|
||||
color: #2d7bd4;
|
||||
}
|
||||
|
||||
a:hover {
|
||||
border-bottom: 1px solid;
|
||||
}
|
||||
|
||||
p {
|
||||
margin: 8px 0;
|
||||
}
|
||||
|
||||
code {
|
||||
color: #ffa500;
|
||||
}
|
||||
|
||||
li {
|
||||
padding: 4px;
|
||||
}
|
||||
45
examples/agent-kit-nextjs-langchain/app/layout.tsx
Normal file
45
examples/agent-kit-nextjs-langchain/app/layout.tsx
Normal file
@@ -0,0 +1,45 @@
|
||||
import "./globals.css";
|
||||
import { Public_Sans } from "next/font/google";
|
||||
|
||||
const publicSans = Public_Sans({ subsets: ["latin"] });
|
||||
|
||||
export default function RootLayout({
|
||||
children,
|
||||
}: {
|
||||
children: React.ReactNode;
|
||||
}) {
|
||||
return (
|
||||
<html lang="en">
|
||||
<head>
|
||||
<title>SolanaAgentKit + LangChain + Next.js Template</title>
|
||||
<link rel="shortcut icon" href="/images/favicon.ico" />
|
||||
<meta
|
||||
name="description"
|
||||
content="Starter template showing how to use SolanaAgentKit with Langchain in Next.js projects."
|
||||
/>
|
||||
<meta
|
||||
property="og:title"
|
||||
content="SolanaAgentKit + LangChain + Next.js Template"
|
||||
/>
|
||||
<meta
|
||||
property="og:description"
|
||||
content="Starter template showing how to use SolanaAgentKit with LangChain in Next.js projects."
|
||||
/>
|
||||
<meta property="og:image" content="/images/title-card.png" />
|
||||
<meta name="twitter:card" content="summary_large_image" />
|
||||
<meta
|
||||
name="twitter:title"
|
||||
content="SolanaAgentKit + LangChain + Next.js Template"
|
||||
/>
|
||||
<meta
|
||||
name="twitter:description"
|
||||
content="Starter template showing how to use SolanaAgentKit with LangChain in Next.js projects."
|
||||
/>
|
||||
<meta name="twitter:image" content="/images/title-card.png" />
|
||||
</head>
|
||||
<body className={publicSans.className}>
|
||||
<div className="flex flex-col p-4 md:p-12 h-[100vh]">{children}</div>
|
||||
</body>
|
||||
</html>
|
||||
);
|
||||
}
|
||||
75
examples/agent-kit-nextjs-langchain/app/page.tsx
Normal file
75
examples/agent-kit-nextjs-langchain/app/page.tsx
Normal file
@@ -0,0 +1,75 @@
|
||||
import { ChatWindow } from "@/components/ChatWindow";
|
||||
|
||||
export default function Home() {
|
||||
const InfoCard = (
|
||||
<div className="p-4 md:p-8 rounded bg-[#25252d] w-full max-h-[85%] overflow-hidden">
|
||||
<h1 className="text-3xl md:text-4xl mb-4">
|
||||
SolanaAgentKit + LangChain.js 🦜🔗 + Next.js
|
||||
</h1>
|
||||
<ul>
|
||||
<li className="text-l">
|
||||
🤝
|
||||
<span className="ml-2">
|
||||
This template showcases a simple agent chatbot using{" "}
|
||||
<a href="https://https://www.solanaagentkit.xyz/">SolanaAgentKit</a>
|
||||
{", "}
|
||||
<a href="https://js.langchain.com/" target="_blank">
|
||||
LangChain.js
|
||||
</a>{" "}
|
||||
and the Vercel{" "}
|
||||
<a href="https://sdk.vercel.ai/docs" target="_blank">
|
||||
AI SDK
|
||||
</a>{" "}
|
||||
in a{" "}
|
||||
<a href="https://nextjs.org/" target="_blank">
|
||||
Next.js
|
||||
</a>{" "}
|
||||
project.
|
||||
</span>
|
||||
</li>
|
||||
<li className="hidden text-l md:block">
|
||||
💻
|
||||
<span className="ml-2">
|
||||
You can find the prompt and model logic for this use-case in{" "}
|
||||
<code>app/api/chat/route.ts</code>.
|
||||
</span>
|
||||
</li>
|
||||
<li className="hidden text-l md:block">
|
||||
🎨
|
||||
<span className="ml-2">
|
||||
The main frontend logic is found in <code>app/page.tsx</code>.
|
||||
</span>
|
||||
</li>
|
||||
<li className="text-l">
|
||||
🐙
|
||||
<span className="ml-2">
|
||||
This template is open source - you can see the source code and
|
||||
deploy your own version{" "}
|
||||
<a
|
||||
href="https://github.com/michaelessiet/solana-agent-nextjs-starter-langchain"
|
||||
target="_blank"
|
||||
>
|
||||
from the GitHub repo
|
||||
</a>
|
||||
!
|
||||
</span>
|
||||
</li>
|
||||
<li className="text-l">
|
||||
👇
|
||||
<span className="ml-2">
|
||||
Try asking e.g. <code>What is my wallet address?</code> below!
|
||||
</span>
|
||||
</li>
|
||||
</ul>
|
||||
</div>
|
||||
);
|
||||
return (
|
||||
<ChatWindow
|
||||
endpoint="api/chat"
|
||||
emoji="🤖"
|
||||
titleText="Solana agent"
|
||||
placeholder="I'm your friendly Solana agent! Ask me anything..."
|
||||
emptyStateComponent={InfoCard}
|
||||
></ChatWindow>
|
||||
);
|
||||
}
|
||||
@@ -0,0 +1,58 @@
|
||||
import markdownToHtml from "@/utils/markdownToHTML";
|
||||
import type { Message } from "ai/react";
|
||||
import { useMemo } from "react";
|
||||
|
||||
export function ChatMessageBubble(props: {
|
||||
message: Message;
|
||||
aiEmoji?: string;
|
||||
sources: any[];
|
||||
}) {
|
||||
const colorClassName =
|
||||
props.message.role === "user" ? "bg-sky-600" : "bg-slate-50 text-black";
|
||||
const alignmentClassName =
|
||||
props.message.role === "user" ? "ml-auto" : "mr-auto";
|
||||
const prefix = props.message.role === "user" ? "🧑" : props.aiEmoji;
|
||||
|
||||
const content = useMemo(() => {
|
||||
return markdownToHtml(props.message.content);
|
||||
}, [props.message.content]);
|
||||
|
||||
return (
|
||||
<div
|
||||
className={`${alignmentClassName} ${colorClassName} rounded px-4 py-2 max-w-[80%] mb-8 flex`}
|
||||
>
|
||||
<div className="mr-2">{prefix}</div>
|
||||
<div className="flex flex-col">
|
||||
<div
|
||||
className="prose prose-lg max-w-none"
|
||||
dangerouslySetInnerHTML={{ __html: content }}
|
||||
></div>
|
||||
{props.sources && props.sources.length ? (
|
||||
<>
|
||||
<code className="mt-4 mr-auto bg-slate-600 px-2 py-1 rounded">
|
||||
<h2>🔍 Sources:</h2>
|
||||
</code>
|
||||
<code className="mt-1 mr-2 bg-slate-600 px-2 py-1 rounded text-xs">
|
||||
{props.sources?.map((source, i) => (
|
||||
<div className="mt-2" key={"source:" + i}>
|
||||
{i + 1}. "{source.pageContent}"
|
||||
{source.metadata?.loc?.lines !== undefined ? (
|
||||
<div>
|
||||
<br />
|
||||
Lines {source.metadata?.loc?.lines?.from} to{" "}
|
||||
{source.metadata?.loc?.lines?.to}
|
||||
</div>
|
||||
) : (
|
||||
""
|
||||
)}
|
||||
</div>
|
||||
))}
|
||||
</code>
|
||||
</>
|
||||
) : (
|
||||
""
|
||||
)}
|
||||
</div>
|
||||
</div>
|
||||
);
|
||||
}
|
||||
248
examples/agent-kit-nextjs-langchain/components/ChatWindow.tsx
Normal file
248
examples/agent-kit-nextjs-langchain/components/ChatWindow.tsx
Normal file
@@ -0,0 +1,248 @@
|
||||
"use client";
|
||||
|
||||
import { ToastContainer, toast } from "react-toastify";
|
||||
import "react-toastify/dist/ReactToastify.css";
|
||||
|
||||
import { Message } from "ai";
|
||||
import { useChat } from "ai/react";
|
||||
import { useRef, useState, ReactElement } from "react";
|
||||
import type { FormEvent } from "react";
|
||||
|
||||
import { ChatMessageBubble } from "@/components/ChatMessageBubble";
|
||||
import { IntermediateStep } from "./IntermediateStep";
|
||||
|
||||
export function ChatWindow(props: {
|
||||
endpoint: string;
|
||||
emptyStateComponent: ReactElement;
|
||||
placeholder?: string;
|
||||
titleText?: string;
|
||||
emoji?: string;
|
||||
showIntermediateStepsToggle?: boolean;
|
||||
}) {
|
||||
const messageContainerRef = useRef<HTMLDivElement | null>(null);
|
||||
|
||||
const {
|
||||
endpoint,
|
||||
emptyStateComponent,
|
||||
placeholder,
|
||||
titleText = "An LLM",
|
||||
showIntermediateStepsToggle,
|
||||
emoji,
|
||||
} = props;
|
||||
|
||||
const [showIntermediateSteps, setShowIntermediateSteps] = useState(false);
|
||||
const [intermediateStepsLoading, setIntermediateStepsLoading] =
|
||||
useState(false);
|
||||
const intemediateStepsToggle = showIntermediateStepsToggle && (
|
||||
<div>
|
||||
<input
|
||||
type="checkbox"
|
||||
id="show_intermediate_steps"
|
||||
name="show_intermediate_steps"
|
||||
checked={showIntermediateSteps}
|
||||
onChange={(e) => setShowIntermediateSteps(e.target.checked)}
|
||||
></input>
|
||||
<label htmlFor="show_intermediate_steps"> Show intermediate steps</label>
|
||||
</div>
|
||||
);
|
||||
|
||||
const [sourcesForMessages, setSourcesForMessages] = useState<
|
||||
Record<string, any>
|
||||
>({});
|
||||
|
||||
const {
|
||||
messages,
|
||||
input,
|
||||
setInput,
|
||||
handleInputChange,
|
||||
handleSubmit,
|
||||
isLoading: chatEndpointIsLoading,
|
||||
setMessages,
|
||||
} = useChat({
|
||||
api: endpoint,
|
||||
onResponse(response) {
|
||||
const sourcesHeader = response.headers.get("x-sources");
|
||||
const sources = sourcesHeader
|
||||
? JSON.parse(Buffer.from(sourcesHeader, "base64").toString("utf8"))
|
||||
: [];
|
||||
const messageIndexHeader = response.headers.get("x-message-index");
|
||||
if (sources.length && messageIndexHeader !== null) {
|
||||
setSourcesForMessages({
|
||||
...sourcesForMessages,
|
||||
[messageIndexHeader]: sources,
|
||||
});
|
||||
}
|
||||
},
|
||||
streamMode: "text",
|
||||
onError: (e) => {
|
||||
toast(e.message, {
|
||||
theme: "dark",
|
||||
});
|
||||
},
|
||||
});
|
||||
|
||||
async function sendMessage(e: FormEvent<HTMLFormElement>) {
|
||||
e.preventDefault();
|
||||
if (messageContainerRef.current) {
|
||||
messageContainerRef.current.classList.add("grow");
|
||||
}
|
||||
if (!messages.length) {
|
||||
await new Promise((resolve) => setTimeout(resolve, 300));
|
||||
}
|
||||
if (chatEndpointIsLoading ?? intermediateStepsLoading) {
|
||||
return;
|
||||
}
|
||||
if (!showIntermediateSteps) {
|
||||
handleSubmit(e);
|
||||
// Some extra work to show intermediate steps properly
|
||||
} else {
|
||||
setIntermediateStepsLoading(true);
|
||||
setInput("");
|
||||
const messagesWithUserReply = messages.concat({
|
||||
id: messages.length.toString(),
|
||||
content: input,
|
||||
role: "user",
|
||||
});
|
||||
setMessages(messagesWithUserReply);
|
||||
const response = await fetch(endpoint, {
|
||||
method: "POST",
|
||||
body: JSON.stringify({
|
||||
messages: messagesWithUserReply,
|
||||
show_intermediate_steps: true,
|
||||
}),
|
||||
});
|
||||
const json = await response.json();
|
||||
setIntermediateStepsLoading(false);
|
||||
if (response.status === 200) {
|
||||
const responseMessages: Message[] = json.messages;
|
||||
// Represent intermediate steps as system messages for display purposes
|
||||
// TODO: Add proper support for tool messages
|
||||
const toolCallMessages = responseMessages.filter(
|
||||
(responseMessage: Message) => {
|
||||
return (
|
||||
(responseMessage.role === "assistant" &&
|
||||
!!responseMessage.tool_calls?.length) ||
|
||||
responseMessage.role === "tool"
|
||||
);
|
||||
},
|
||||
);
|
||||
const intermediateStepMessages = [];
|
||||
for (let i = 0; i < toolCallMessages.length; i += 2) {
|
||||
const aiMessage = toolCallMessages[i];
|
||||
const toolMessage = toolCallMessages[i + 1];
|
||||
intermediateStepMessages.push({
|
||||
id: (messagesWithUserReply.length + i / 2).toString(),
|
||||
role: "system" as const,
|
||||
content: JSON.stringify({
|
||||
action: aiMessage.tool_calls?.[0],
|
||||
observation: toolMessage.content,
|
||||
}),
|
||||
});
|
||||
}
|
||||
const newMessages = messagesWithUserReply;
|
||||
for (const message of intermediateStepMessages) {
|
||||
newMessages.push(message);
|
||||
setMessages([...newMessages]);
|
||||
await new Promise((resolve) =>
|
||||
setTimeout(resolve, 1000 + Math.random() * 1000),
|
||||
);
|
||||
}
|
||||
setMessages([
|
||||
...newMessages,
|
||||
{
|
||||
id: newMessages.length.toString(),
|
||||
content: responseMessages[responseMessages.length - 1].content,
|
||||
role: "assistant",
|
||||
},
|
||||
]);
|
||||
} else {
|
||||
if (json.error) {
|
||||
toast(json.error, {
|
||||
theme: "dark",
|
||||
});
|
||||
throw new Error(json.error);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return (
|
||||
<div
|
||||
className={`flex flex-col items-center p-4 md:p-8 rounded grow overflow-hidden ${messages.length > 0 ? "border" : ""}`}
|
||||
>
|
||||
<h2 className={`${messages.length > 0 ? "" : "hidden"} text-2xl`}>
|
||||
{emoji} {titleText}
|
||||
</h2>
|
||||
{messages.length === 0 ? emptyStateComponent : ""}
|
||||
<div
|
||||
className="flex flex-col-reverse w-full mb-4 overflow-auto transition-[flex-grow] ease-in-out"
|
||||
ref={messageContainerRef}
|
||||
>
|
||||
{messages.length > 0
|
||||
? [...messages].reverse().map((m, i) => {
|
||||
const sourceKey = (messages.length - 1 - i).toString();
|
||||
return m.role === "system" ? (
|
||||
<IntermediateStep key={m.id} message={m}></IntermediateStep>
|
||||
) : (
|
||||
<ChatMessageBubble
|
||||
key={m.id}
|
||||
message={m}
|
||||
aiEmoji={emoji}
|
||||
sources={sourcesForMessages[sourceKey]}
|
||||
></ChatMessageBubble>
|
||||
);
|
||||
})
|
||||
: ""}
|
||||
</div>
|
||||
|
||||
<form onSubmit={sendMessage} className="flex w-full flex-col">
|
||||
<div className="flex">{intemediateStepsToggle}</div>
|
||||
<div className="flex w-full mt-4">
|
||||
<input
|
||||
className="grow mr-8 p-4 rounded"
|
||||
value={input}
|
||||
placeholder={placeholder ?? "What's it like to be a pirate?"}
|
||||
onChange={handleInputChange}
|
||||
/>
|
||||
<button
|
||||
type="submit"
|
||||
className="shrink-0 px-8 py-4 bg-sky-600 rounded w-28"
|
||||
>
|
||||
<div
|
||||
role="status"
|
||||
className={`${chatEndpointIsLoading || intermediateStepsLoading ? "" : "hidden"} flex justify-center`}
|
||||
>
|
||||
<svg
|
||||
aria-hidden="true"
|
||||
className="w-6 h-6 text-white animate-spin dark:text-white fill-sky-800"
|
||||
viewBox="0 0 100 101"
|
||||
fill="none"
|
||||
xmlns="http://www.w3.org/2000/svg"
|
||||
>
|
||||
<path
|
||||
d="M100 50.5908C100 78.2051 77.6142 100.591 50 100.591C22.3858 100.591 0 78.2051 0 50.5908C0 22.9766 22.3858 0.59082 50 0.59082C77.6142 0.59082 100 22.9766 100 50.5908ZM9.08144 50.5908C9.08144 73.1895 27.4013 91.5094 50 91.5094C72.5987 91.5094 90.9186 73.1895 90.9186 50.5908C90.9186 27.9921 72.5987 9.67226 50 9.67226C27.4013 9.67226 9.08144 27.9921 9.08144 50.5908Z"
|
||||
fill="currentColor"
|
||||
/>
|
||||
<path
|
||||
d="M93.9676 39.0409C96.393 38.4038 97.8624 35.9116 97.0079 33.5539C95.2932 28.8227 92.871 24.3692 89.8167 20.348C85.8452 15.1192 80.8826 10.7238 75.2124 7.41289C69.5422 4.10194 63.2754 1.94025 56.7698 1.05124C51.7666 0.367541 46.6976 0.446843 41.7345 1.27873C39.2613 1.69328 37.813 4.19778 38.4501 6.62326C39.0873 9.04874 41.5694 10.4717 44.0505 10.1071C47.8511 9.54855 51.7191 9.52689 55.5402 10.0491C60.8642 10.7766 65.9928 12.5457 70.6331 15.2552C75.2735 17.9648 79.3347 21.5619 82.5849 25.841C84.9175 28.9121 86.7997 32.2913 88.1811 35.8758C89.083 38.2158 91.5421 39.6781 93.9676 39.0409Z"
|
||||
fill="currentFill"
|
||||
/>
|
||||
</svg>
|
||||
<span className="sr-only">Loading...</span>
|
||||
</div>
|
||||
<span
|
||||
className={
|
||||
chatEndpointIsLoading || intermediateStepsLoading
|
||||
? "hidden"
|
||||
: ""
|
||||
}
|
||||
>
|
||||
Send
|
||||
</span>
|
||||
</button>
|
||||
</div>
|
||||
</form>
|
||||
<ToastContainer />
|
||||
</div>
|
||||
);
|
||||
}
|
||||
@@ -0,0 +1,50 @@
|
||||
import { useState } from "react";
|
||||
import type { Message } from "ai/react";
|
||||
|
||||
export function IntermediateStep(props: { message: Message }) {
|
||||
const parsedInput = JSON.parse(props.message.content);
|
||||
const action = parsedInput.action;
|
||||
const observation = parsedInput.observation;
|
||||
const [expanded, setExpanded] = useState(false);
|
||||
return (
|
||||
<div
|
||||
className={`ml-auto bg-green-600 rounded px-4 py-2 max-w-[80%] mb-8 whitespace-pre-wrap flex flex-col cursor-pointer`}
|
||||
>
|
||||
<div
|
||||
className={`text-right ${expanded ? "w-full" : ""}`}
|
||||
onClick={(e) => setExpanded(!expanded)}
|
||||
>
|
||||
<code className="mr-2 bg-slate-600 px-2 py-1 rounded hover:text-blue-600">
|
||||
🛠 <b>{action.name}</b>
|
||||
</code>
|
||||
<span className={expanded ? "hidden" : ""}>🔽</span>
|
||||
<span className={expanded ? "" : "hidden"}>🔼</span>
|
||||
</div>
|
||||
<div
|
||||
className={`overflow-hidden max-h-[0px] transition-[max-height] ease-in-out ${expanded ? "max-h-[360px]" : ""}`}
|
||||
>
|
||||
<div
|
||||
className={`bg-slate-600 rounded p-4 mt-1 max-w-0 ${expanded ? "max-w-full" : "transition-[max-width] delay-100"}`}
|
||||
>
|
||||
<code
|
||||
className={`opacity-0 max-h-[100px] overflow-auto transition ease-in-out delay-150 ${expanded ? "opacity-100" : ""}`}
|
||||
>
|
||||
Tool Input:
|
||||
<br></br>
|
||||
<br></br>
|
||||
{JSON.stringify(action.args)}
|
||||
</code>
|
||||
</div>
|
||||
<div
|
||||
className={`bg-slate-600 rounded p-4 mt-1 max-w-0 ${expanded ? "max-w-full" : "transition-[max-width] delay-100"}`}
|
||||
>
|
||||
<code
|
||||
className={`opacity-0 max-h-[260px] overflow-auto transition ease-in-out delay-150 ${expanded ? "opacity-100" : ""}`}
|
||||
>
|
||||
{observation}
|
||||
</code>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
);
|
||||
}
|
||||
540
examples/agent-kit-nextjs-langchain/data/DefaultRetrievalText.ts
Normal file
540
examples/agent-kit-nextjs-langchain/data/DefaultRetrievalText.ts
Normal file
@@ -0,0 +1,540 @@
|
||||
export default `# QA and Chat over Documents
|
||||
|
||||
Chat and Question-Answering (QA) over \`data\` are popular LLM use-cases.
|
||||
|
||||
\`data\` can include many things, including:
|
||||
|
||||
* \`Unstructured data\` (e.g., PDFs)
|
||||
* \`Structured data\` (e.g., SQL)
|
||||
* \`Code\` (e.g., Python)
|
||||
|
||||
Below we will review Chat and QA on \`Unstructured data\`.
|
||||
|
||||

|
||||
|
||||
\`Unstructured data\` can be loaded from many sources.
|
||||
|
||||
Check out the [document loader integrations here](/docs/modules/data_connection/document_loaders/) to browse the set of supported loaders.
|
||||
|
||||
Each loader returns data as a LangChain \`Document\`.
|
||||
|
||||
\`Documents\` are turned into a Chat or QA app following the general steps below:
|
||||
|
||||
* \`Splitting\`: [Text splitters](/docs/modules/data_connection/document_transformers/) break \`Documents\` into splits of specified size
|
||||
* \`Storage\`: Storage (e.g., often a [vectorstore](/docs/modules/data_connection/vectorstores/)) will house [and often embed](https://www.pinecone.io/learn/vector-embeddings/) the splits
|
||||
* \`Retrieval\`: The app retrieves splits from storage (e.g., often [with similar embeddings](https://www.pinecone.io/learn/k-nearest-neighbor/) to the input question)
|
||||
* \`Output\`: An [LLM](/docs/modules/model_io/models/llms/) produces an answer using a prompt that includes the question and the retrieved splits
|
||||
|
||||

|
||||
|
||||
## Quickstart
|
||||
|
||||
Let's load this [blog post](https://lilianweng.github.io/posts/2023-06-23-agent/) on agents as an example \`Document\`.
|
||||
|
||||
We'll have a QA app in a few lines of code.
|
||||
|
||||
First, set environment variables and install packages required for the guide:
|
||||
|
||||
\`\`\`shell
|
||||
> yarn add cheerio
|
||||
# Or load env vars in your preferred way:
|
||||
> export OPENAI_API_KEY="..."
|
||||
\`\`\`
|
||||
|
||||
## 1. Loading, Splitting, Storage
|
||||
|
||||
### 1.1 Getting started
|
||||
|
||||
Specify a \`Document\` loader.
|
||||
|
||||
\`\`\`typescript
|
||||
// Document loader
|
||||
import { CheerioWebBaseLoader } from "langchain/document_loaders/web/cheerio";
|
||||
|
||||
const loader = new CheerioWebBaseLoader(
|
||||
"https://lilianweng.github.io/posts/2023-06-23-agent/"
|
||||
);
|
||||
const data = await loader.load();
|
||||
\`\`\`
|
||||
|
||||
Split the \`Document\` into chunks for embedding and vector storage.
|
||||
|
||||
|
||||
\`\`\`typescript
|
||||
import { RecursiveCharacterTextSplitter } from "langchain/text_splitter";
|
||||
|
||||
const textSplitter = new RecursiveCharacterTextSplitter({
|
||||
chunkSize: 500,
|
||||
chunkOverlap: 0,
|
||||
});
|
||||
|
||||
const splitDocs = await textSplitter.splitDocuments(data);
|
||||
\`\`\`
|
||||
|
||||
Embed and store the splits in a vector database (for demo purposes we use an unoptimized, in-memory example but you can [browse integrations here](/docs/modules/data_connection/vectorstores/integrations/)):
|
||||
|
||||
|
||||
\`\`\`typescript
|
||||
import { OpenAIEmbeddings } from "langchain/embeddings/openai";
|
||||
import { MemoryVectorStore } from "langchain/vectorstores/memory";
|
||||
|
||||
const embeddings = new OpenAIEmbeddings();
|
||||
|
||||
const vectorStore = await MemoryVectorStore.fromDocuments(splitDocs, embeddings);
|
||||
\`\`\`
|
||||
|
||||
Here are the three pieces together:
|
||||
|
||||

|
||||
|
||||
### 1.2 Going Deeper
|
||||
|
||||
#### 1.2.1 Integrations
|
||||
|
||||
\`Document Loaders\`
|
||||
|
||||
* Browse document loader integrations [here](/docs/modules/data_connection/document_loaders/).
|
||||
|
||||
* See further documentation on loaders [here](/docs/modules/data_connection/document_loaders/).
|
||||
|
||||
\`Document Transformers\`
|
||||
|
||||
* All can ingest loaded \`Documents\` and process them (e.g., split).
|
||||
|
||||
* See further documentation on transformers [here](/docs/modules/data_connection/document_transformers/).
|
||||
|
||||
\`Vectorstores\`
|
||||
|
||||
* Browse vectorstore integrations [here](/docs/modules/data_connection/vectorstores/integrations/).
|
||||
|
||||
* See further documentation on vectorstores [here](/docs/modules/data_connection/vectorstores/).
|
||||
|
||||
## 2. Retrieval
|
||||
|
||||
### 2.1 Getting started
|
||||
|
||||
Retrieve [relevant splits](https://www.pinecone.io/learn/what-is-similarity-search/) for any question using \`similarity_search\`.
|
||||
|
||||
|
||||
\`\`\`typescript
|
||||
const relevantDocs = await vectorStore.similaritySearch("What is task decomposition?");
|
||||
|
||||
console.log(relevantDocs.length);
|
||||
|
||||
// 4
|
||||
\`\`\`
|
||||
|
||||
|
||||
### 2.2 Going Deeper
|
||||
|
||||
#### 2.2.1 Retrieval
|
||||
|
||||
Vectorstores are commonly used for retrieval.
|
||||
|
||||
But, they are not the only option.
|
||||
|
||||
For example, SVMs (see thread [here](https://twitter.com/karpathy/status/1647025230546886658?s=20)) can also be used.
|
||||
|
||||
LangChain [has many retrievers and retrieval methods](/docs/modules/data_connection/retrievers/) including, but not limited to, vectorstores.
|
||||
|
||||
All retrievers implement some common methods, such as \`getRelevantDocuments()\`.
|
||||
|
||||
|
||||
## 3. QA
|
||||
|
||||
### 3.1 Getting started
|
||||
|
||||
Distill the retrieved documents into an answer using an LLM (e.g., \`gpt-3.5-turbo\`) with \`RetrievalQA\` chain.
|
||||
|
||||
|
||||
\`\`\`typescript
|
||||
import { RetrievalQAChain } from "langchain/chains";
|
||||
import { ChatOpenAI } from "langchain/chat_models/openai";
|
||||
|
||||
const model = new ChatOpenAI({ model: "gpt-3.5-turbo" });
|
||||
const chain = RetrievalQAChain.fromLLM(model, vectorstore.asRetriever());
|
||||
|
||||
const response = await chain.call({
|
||||
query: "What is task decomposition?"
|
||||
});
|
||||
console.log(response);
|
||||
|
||||
/*
|
||||
{
|
||||
text: 'Task decomposition refers to the process of breaking down a larger task into smaller, more manageable subgoals. By decomposing a task, it becomes easier for an agent or system to handle complex tasks efficiently. Task decomposition can be done through various methods such as using prompting or task-specific instructions, or through human inputs. It helps in planning and organizing the steps required to complete a task effectively.'
|
||||
}
|
||||
*/
|
||||
\`\`\`
|
||||
|
||||
### 3.2 Going Deeper
|
||||
|
||||
#### 3.2.1 Integrations
|
||||
|
||||
\`LLMs\`
|
||||
|
||||
* Browse LLM integrations and further documentation [here](/docs/modules/model_io/models/).
|
||||
|
||||
#### 3.2.2 Customizing the prompt
|
||||
|
||||
The prompt in \`RetrievalQA\` chain can be customized as follows.
|
||||
|
||||
|
||||
\`\`\`typescript
|
||||
import { RetrievalQAChain } from "langchain/chains";
|
||||
import { ChatOpenAI } from "langchain/chat_models/openai";
|
||||
import { PromptTemplate } from "langchain/prompts";
|
||||
|
||||
const model = new ChatOpenAI({ model: "gpt-3.5-turbo" });
|
||||
|
||||
const template = \`Use the following pieces of context to answer the question at the end.
|
||||
If you don't know the answer, just say that you don't know, don't try to make up an answer.
|
||||
Use three sentences maximum and keep the answer as concise as possible.
|
||||
Always say "thanks for asking!" at the end of the answer.
|
||||
{context}
|
||||
Question: {question}
|
||||
Helpful Answer:\`;
|
||||
|
||||
const chain = RetrievalQAChain.fromLLM(model, vectorstore.asRetriever(), {
|
||||
prompt: PromptTemplate.fromTemplate(template),
|
||||
});
|
||||
|
||||
const response = await chain.call({
|
||||
query: "What is task decomposition?"
|
||||
});
|
||||
|
||||
console.log(response);
|
||||
|
||||
/*
|
||||
{
|
||||
text: 'Task decomposition is the process of breaking down a large task into smaller, more manageable subgoals. This allows for efficient handling of complex tasks and aids in planning and organizing the steps needed to achieve the overall goal. Thanks for asking!'
|
||||
}
|
||||
*/
|
||||
\`\`\`
|
||||
|
||||
|
||||
#### 3.2.3 Returning source documents
|
||||
|
||||
The full set of retrieved documents used for answer distillation can be returned using \`return_source_documents=True\`.
|
||||
|
||||
|
||||
\`\`\`typescript
|
||||
import { RetrievalQAChain } from "langchain/chains";
|
||||
import { ChatOpenAI } from "langchain/chat_models/openai";
|
||||
|
||||
const model = new ChatOpenAI({ model: "gpt-3.5-turbo" });
|
||||
|
||||
const chain = RetrievalQAChain.fromLLM(model, vectorstore.asRetriever(), {
|
||||
returnSourceDocuments: true
|
||||
});
|
||||
|
||||
const response = await chain.call({
|
||||
query: "What is task decomposition?"
|
||||
});
|
||||
|
||||
console.log(response.sourceDocuments[0]);
|
||||
|
||||
/*
|
||||
Document {
|
||||
pageContent: 'Task decomposition can be done (1) by LLM with simple prompting like "Steps for XYZ.\\n1.", "What are the subgoals for achieving XYZ?", (2) by using task-specific instructions; e.g. "Write a story outline." for writing a novel, or (3) with human inputs.',
|
||||
metadata: [Object]
|
||||
}
|
||||
*/
|
||||
\`\`\`
|
||||
|
||||
|
||||
#### 3.2.4 Customizing retrieved docs in the LLM prompt
|
||||
|
||||
Retrieved documents can be fed to an LLM for answer distillation in a few different ways.
|
||||
|
||||
\`stuff\`, \`refine\`, and \`map-reduce\` chains for passing documents to an LLM prompt are well summarized [here](/docs/modules/chains/document/).
|
||||
|
||||
\`stuff\` is commonly used because it simply "stuffs" all retrieved documents into the prompt.
|
||||
|
||||
The [loadQAChain](/docs/modules/chains/document/) methods are easy ways to pass documents to an LLM using these various approaches.
|
||||
|
||||
|
||||
\`\`\`typescript
|
||||
import { loadQAStuffChain } from "langchain/chains";
|
||||
|
||||
const stuffChain = loadQAStuffChain(model);
|
||||
|
||||
const stuffResult = await stuffChain.call({
|
||||
input_documents: relevantDocs,
|
||||
question: "What is task decomposition
|
||||
});
|
||||
|
||||
console.log(stuffResult);
|
||||
/*
|
||||
{
|
||||
text: 'Task decomposition is the process of breaking down a large task into smaller, more manageable subgoals or steps. This allows for efficient handling of complex tasks by focusing on one subgoal at a time. Task decomposition can be done through various methods such as using simple prompting, task-specific instructions, or human inputs.'
|
||||
}
|
||||
*/
|
||||
\`\`\`
|
||||
|
||||
## 4. Chat
|
||||
|
||||
### 4.1 Getting started
|
||||
|
||||
To keep chat history, we use a variant of the previous chain called a \`ConversationalRetrievalQAChain\`.
|
||||
First, specify a \`Memory buffer\` to track the conversation inputs / outputs.
|
||||
|
||||
|
||||
\`\`\`typescript
|
||||
import { ConversationalRetrievalQAChain } from "langchain/chains";
|
||||
import { BufferMemory } from "langchain/memory";
|
||||
import { ChatOpenAI } from "langchain/chat_models/openai";
|
||||
|
||||
const memory = new BufferMemory({
|
||||
memoryKey: "chat_history",
|
||||
returnMessages: true,
|
||||
});
|
||||
\`\`\`
|
||||
|
||||
Next, we initialize and call the chain:
|
||||
|
||||
\`\`\`typescript
|
||||
const model = new ChatOpenAI({ model: "gpt-3.5-turbo" });
|
||||
const chain = ConversationalRetrievalQAChain.fromLLM(model, vectorstore.asRetriever(), {
|
||||
memory
|
||||
});
|
||||
|
||||
const result = await chain.call({
|
||||
question: "What are some of the main ideas in self-reflection?"
|
||||
});
|
||||
console.log(result);
|
||||
|
||||
/*
|
||||
{
|
||||
text: 'Some main ideas in self-reflection include:\n' +
|
||||
'\n' +
|
||||
'1. Iterative Improvement: Self-reflection allows autonomous agents to improve by continuously refining past action decisions and correcting mistakes.\n' +
|
||||
'\n' +
|
||||
'2. Trial and Error: Self-reflection plays a crucial role in real-world tasks where trial and error are inevitable. It helps agents learn from failed trajectories and make adjustments for future actions.\n' +
|
||||
'\n' +
|
||||
'3. Constructive Criticism: Agents engage in constructive self-criticism of their big-picture behavior to identify areas for improvement.\n' +
|
||||
'\n' +
|
||||
'4. Decision and Strategy Refinement: Reflection on past decisions and strategies enables agents to refine their approach and make more informed choices.\n' +
|
||||
'\n' +
|
||||
'5. Efficiency and Optimization: Self-reflection encourages agents to be smart and efficient in their actions, aiming to complete tasks in the least number of steps.\n' +
|
||||
'\n' +
|
||||
'These ideas highlight the importance of self-reflection in enhancing performance and guiding future actions.'
|
||||
}
|
||||
*/
|
||||
\`\`\`
|
||||
|
||||
|
||||
The \`Memory buffer\` has context to resolve \`"it"\` ("self-reflection") in the below question.
|
||||
|
||||
|
||||
\`\`\`typescript
|
||||
const followupResult = await chain.call({
|
||||
question: "How does the Reflexion paper handle it?"
|
||||
});
|
||||
console.log(followupResult);
|
||||
|
||||
/*
|
||||
{
|
||||
text: "The Reflexion paper introduces a framework that equips agents with dynamic memory and self-reflection capabilities to improve their reasoning skills. The approach involves showing the agent two-shot examples, where each example consists of a failed trajectory and an ideal reflection on how to guide future changes in the agent's plan. These reflections are then added to the agent's working memory as context for querying a language model. The agent uses this self-reflection information to make decisions on whether to start a new trial or continue with the current plan."
|
||||
}
|
||||
*/
|
||||
\`\`\`
|
||||
|
||||
|
||||
### 4.2 Going deeper
|
||||
|
||||
The [documentation](/docs/modules/chains/popular/chat_vector_db) on \`ConversationalRetrievalQAChain\` offers a few extensions, such as streaming and source documents.
|
||||
|
||||
|
||||
# Conversational Retrieval Agents
|
||||
|
||||
This is an agent specifically optimized for doing retrieval when necessary while holding a conversation and being able
|
||||
to answer questions based on previous dialogue in the conversation.
|
||||
|
||||
To start, we will set up the retriever we want to use, then turn it into a retriever tool. Next, we will use the high-level constructor for this type of agent.
|
||||
Finally, we will walk through how to construct a conversational retrieval agent from components.
|
||||
|
||||
## The Retriever
|
||||
|
||||
To start, we need a retriever to use! The code here is mostly just example code. Feel free to use your own retriever and skip to the next section on creating a retriever tool.
|
||||
|
||||
\`\`\`typescript
|
||||
import { FaissStore } from "langchain/vectorstores/faiss";
|
||||
import { OpenAIEmbeddings } from "langchain/embeddings/openai";
|
||||
import { TextLoader } from "langchain/document_loaders/fs/text";
|
||||
import { RecursiveCharacterTextSplitter } from "langchain/text_splitter";
|
||||
|
||||
const loader = new TextLoader("state_of_the_union.txt");
|
||||
const docs = await loader.load();
|
||||
const splitter = new RecursiveCharacterTextSplitter({
|
||||
chunkSize: 1000,
|
||||
chunkOverlap: 0
|
||||
});
|
||||
|
||||
const texts = await splitter.splitDocuments(docs);
|
||||
|
||||
const vectorStore = await FaissStore.fromDocuments(texts, new OpenAIEmbeddings());
|
||||
|
||||
const retriever = vectorStore.asRetriever();
|
||||
\`\`\`
|
||||
|
||||
## Retriever Tool
|
||||
|
||||
Now we need to create a tool for our retriever. The main things we need to pass in are a \`name\` for the retriever as well as a \`description\`. These will both be used by the language model, so they should be informative.
|
||||
|
||||
\`\`\`typescript
|
||||
import { createRetrieverTool } from "langchain/agents/toolkits";
|
||||
|
||||
const tool = createRetrieverTool(retriever, {
|
||||
name: "search_state_of_union",
|
||||
description: "Searches and returns documents regarding the state-of-the-union.",
|
||||
});
|
||||
\`\`\`
|
||||
|
||||
## Agent Constructor
|
||||
|
||||
Here, we will use the high level \`create_conversational_retrieval_agent\` API to construct the agent.
|
||||
Notice that beside the list of tools, the only thing we need to pass in is a language model to use.
|
||||
|
||||
Under the hood, this agent is using the OpenAIFunctionsAgent, so we need to use an ChatOpenAI model.
|
||||
|
||||
\`\`\`typescript
|
||||
import { createConversationalRetrievalAgent } from "langchain/agents/toolkits";
|
||||
import { ChatOpenAI } from "langchain/chat_models/openai";
|
||||
|
||||
const model = new ChatOpenAI({
|
||||
temperature: 0,
|
||||
});
|
||||
|
||||
const executor = await createConversationalRetrievalAgent(model, [tool], {
|
||||
verbose: true,
|
||||
});
|
||||
\`\`\`
|
||||
|
||||
We can now try it out!
|
||||
|
||||
\`\`\`typescript
|
||||
const result = await executor.call({
|
||||
input: "Hi, I'm Bob!"
|
||||
});
|
||||
|
||||
console.log(result);
|
||||
|
||||
/*
|
||||
{
|
||||
output: 'Hello Bob! How can I assist you today?',
|
||||
intermediateSteps: []
|
||||
}
|
||||
*/
|
||||
|
||||
const result2 = await executor.call({
|
||||
input: "What's my name?"
|
||||
});
|
||||
|
||||
console.log(result2);
|
||||
|
||||
/*
|
||||
{ output: 'Your name is Bob.', intermediateSteps: [] }
|
||||
*/
|
||||
|
||||
const result3 = await executor.call({
|
||||
input: "What did the president say about Ketanji Brown Jackson in the most recent state of the union?"
|
||||
});
|
||||
|
||||
console.log(result3);
|
||||
|
||||
/*
|
||||
{
|
||||
output: "In the most recent state of the union, President Biden mentioned Ketanji Brown Jackson. He nominated her as a Circuit Court of Appeals judge and described her as one of the nation's top legal minds who will continue Justice Breyer's legacy of excellence. He mentioned that she has received a broad range of support, including from the Fraternal Order of Police and former judges appointed by Democrats and Republicans.",
|
||||
intermediateSteps: [
|
||||
{...}
|
||||
]
|
||||
}
|
||||
*/
|
||||
|
||||
const result4 = await executor.call({
|
||||
input: "How long ago did he nominate her?"
|
||||
});
|
||||
|
||||
console.log(result4);
|
||||
|
||||
/*
|
||||
{
|
||||
output: 'President Biden nominated Ketanji Brown Jackson four days before the most recent state of the union address.',
|
||||
intermediateSteps: []
|
||||
}
|
||||
*/
|
||||
\`\`\`
|
||||
|
||||
Note that for the final call, the agent used previously retrieved information to answer the query and did not need to call the tool again!
|
||||
|
||||
Here's a trace showing how the agent fetches documents to answer the question with the retrieval tool:
|
||||
|
||||
https://smith.langchain.com/public/1e2b1887-ca44-4210-913b-a69c1b8a8e7e/r
|
||||
|
||||
## Creating from components
|
||||
|
||||
What actually is going on underneath the hood? Let's take a look so we can understand how to modify things going forward.
|
||||
|
||||
### Memory
|
||||
|
||||
In this example, we want the agent to remember not only previous conversations, but also previous intermediate steps.
|
||||
For that, we can use \`OpenAIAgentTokenBufferMemory\`. Note that if you want to change whether the agent remembers intermediate steps,
|
||||
how the long the retained buffer is, or anything like that you should change this part.
|
||||
|
||||
\`\`\`typescript
|
||||
import { OpenAIAgentTokenBufferMemory } from "langchain/agents/toolkits";
|
||||
|
||||
const memory = new OpenAIAgentTokenBufferMemory({
|
||||
llm: model,
|
||||
memoryKey: "chat_history",
|
||||
outputKey: "output"
|
||||
});
|
||||
\`\`\`
|
||||
|
||||
You should make sure \`memoryKey\` is set to \`"chat_history"\` and \`outputKey\` is set to \`"output"\` for the OpenAI functions agent.
|
||||
This memory also has \`returnMessages\` set to \`true\` by default.
|
||||
|
||||
You can also load messages from prior conversations into this memory by initializing it with a pre-loaded chat history:
|
||||
|
||||
\`\`\`typescript
|
||||
import { ChatOpenAI } from "langchain/chat_models/openai";
|
||||
import { OpenAIAgentTokenBufferMemory } from "langchain/agents/toolkits";
|
||||
import { HumanMessage, AIMessage } from "langchain/schema";
|
||||
import { ChatMessageHistory } from "langchain/memory";
|
||||
|
||||
const previousMessages = [
|
||||
new HumanMessage("My name is Bob"),
|
||||
new AIMessage("Nice to meet you, Bob!"),
|
||||
];
|
||||
|
||||
const chatHistory = new ChatMessageHistory(previousMessages);
|
||||
|
||||
const memory = new OpenAIAgentTokenBufferMemory({
|
||||
llm: new ChatOpenAI({}),
|
||||
memoryKey: "chat_history",
|
||||
outputKey: "output",
|
||||
chatHistory,
|
||||
});
|
||||
\`\`\`
|
||||
|
||||
### Agent executor
|
||||
|
||||
We can recreate the agent executor directly with the \`initializeAgentExecutorWithOptions\` method.
|
||||
This allows us to customize the agent's system message by passing in a \`prefix\` into \`agentArgs\`.
|
||||
Importantly, we must pass in \`return_intermediate_steps: true\` since we are recording that with our memory object.
|
||||
|
||||
\`\`\`typescript
|
||||
import { initializeAgentExecutorWithOptions } from "langchain/agents";
|
||||
|
||||
const executor = await initializeAgentExecutorWithOptions(tools, llm, {
|
||||
agentType: "openai-functions",
|
||||
memory,
|
||||
returnIntermediateSteps: true,
|
||||
agentArgs: {
|
||||
prefix:
|
||||
prefix ??
|
||||
\`Do your best to answer the questions. Feel free to use any tools available to look up relevant information, only if necessary.\`,
|
||||
},
|
||||
});
|
||||
\`\`\`
|
||||
`;
|
||||
4
examples/agent-kit-nextjs-langchain/next.config.js
Normal file
4
examples/agent-kit-nextjs-langchain/next.config.js
Normal file
@@ -0,0 +1,4 @@
|
||||
const withBundleAnalyzer = require('@next/bundle-analyzer')({
|
||||
enabled: process.env.ANALYZE === 'true',
|
||||
})
|
||||
module.exports = withBundleAnalyzer({})
|
||||
47
examples/agent-kit-nextjs-langchain/package.json
Normal file
47
examples/agent-kit-nextjs-langchain/package.json
Normal file
@@ -0,0 +1,47 @@
|
||||
{
|
||||
"name": "langchain-nextjs-template",
|
||||
"version": "0.0.0",
|
||||
"private": true,
|
||||
"scripts": {
|
||||
"dev": "next dev",
|
||||
"build": "next build",
|
||||
"start": "next start",
|
||||
"lint": "next lint",
|
||||
"format": "prettier --write \"app\""
|
||||
},
|
||||
"engines": {
|
||||
"node": ">=18"
|
||||
},
|
||||
"dependencies": {
|
||||
"@langchain/community": "^0.3.11",
|
||||
"@langchain/core": "^0.3.17",
|
||||
"@langchain/langgraph": "^0.2.20",
|
||||
"@langchain/openai": "^0.3.11",
|
||||
"@next/bundle-analyzer": "^13.4.19",
|
||||
"@supabase/supabase-js": "^2.32.0",
|
||||
"@tailwindcss/typography": "^0.5.15",
|
||||
"@types/node": "20.12.12",
|
||||
"@types/react": "18.3.2",
|
||||
"@types/react-dom": "18.3.0",
|
||||
"ai": "^3.1.12",
|
||||
"autoprefixer": "10.4.14",
|
||||
"eslint": "8.46.0",
|
||||
"eslint-config-next": "13.4.12",
|
||||
"isomorphic-dompurify": "^2.19.0",
|
||||
"langchain": "^0.3.5",
|
||||
"marked": "^15.0.4",
|
||||
"next": "^14.2.3",
|
||||
"postcss": "8.4.27",
|
||||
"react": "^18.3.1",
|
||||
"react-dom": "^18.3.1",
|
||||
"react-toastify": "^9.1.3",
|
||||
"solana-agent-kit": "^1.3.0",
|
||||
"tailwindcss": "3.3.3",
|
||||
"typescript": "5.1.6",
|
||||
"zod": "^3.22.3",
|
||||
"zod-to-json-schema": "^3.21.4"
|
||||
},
|
||||
"devDependencies": {
|
||||
"prettier": "3.0.0"
|
||||
}
|
||||
}
|
||||
8019
examples/agent-kit-nextjs-langchain/pnpm-lock.yaml
generated
Normal file
8019
examples/agent-kit-nextjs-langchain/pnpm-lock.yaml
generated
Normal file
File diff suppressed because it is too large
Load Diff
6
examples/agent-kit-nextjs-langchain/postcss.config.js
Normal file
6
examples/agent-kit-nextjs-langchain/postcss.config.js
Normal file
@@ -0,0 +1,6 @@
|
||||
module.exports = {
|
||||
plugins: {
|
||||
tailwindcss: {},
|
||||
autoprefixer: {},
|
||||
},
|
||||
}
|
||||
BIN
examples/agent-kit-nextjs-langchain/public/images/favicon.ico
Normal file
BIN
examples/agent-kit-nextjs-langchain/public/images/favicon.ico
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 15 KiB |
BIN
examples/agent-kit-nextjs-langchain/public/images/og-image.png
Normal file
BIN
examples/agent-kit-nextjs-langchain/public/images/og-image.png
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 48 KiB |
BIN
examples/agent-kit-nextjs-langchain/public/images/title-card.png
Normal file
BIN
examples/agent-kit-nextjs-langchain/public/images/title-card.png
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 99 KiB |
18
examples/agent-kit-nextjs-langchain/tailwind.config.js
Normal file
18
examples/agent-kit-nextjs-langchain/tailwind.config.js
Normal file
@@ -0,0 +1,18 @@
|
||||
/** @type {import('tailwindcss').Config} */
|
||||
module.exports = {
|
||||
content: [
|
||||
"./pages/**/*.{js,ts,jsx,tsx,mdx}",
|
||||
"./components/**/*.{js,ts,jsx,tsx,mdx}",
|
||||
"./app/**/*.{js,ts,jsx,tsx,mdx}",
|
||||
],
|
||||
theme: {
|
||||
extend: {
|
||||
backgroundImage: {
|
||||
"gradient-radial": "radial-gradient(var(--tw-gradient-stops))",
|
||||
"gradient-conic":
|
||||
"conic-gradient(from 180deg at 50% 50%, var(--tw-gradient-stops))",
|
||||
},
|
||||
},
|
||||
},
|
||||
plugins: [require("@tailwindcss/typography")],
|
||||
};
|
||||
28
examples/agent-kit-nextjs-langchain/tsconfig.json
Normal file
28
examples/agent-kit-nextjs-langchain/tsconfig.json
Normal file
@@ -0,0 +1,28 @@
|
||||
{
|
||||
"compilerOptions": {
|
||||
"target": "es5",
|
||||
"lib": ["dom", "dom.iterable", "esnext"],
|
||||
"allowJs": true,
|
||||
"skipLibCheck": true,
|
||||
"strict": true,
|
||||
"forceConsistentCasingInFileNames": true,
|
||||
"noEmit": true,
|
||||
"esModuleInterop": true,
|
||||
"module": "esnext",
|
||||
"moduleResolution": "bundler",
|
||||
"resolveJsonModule": true,
|
||||
"isolatedModules": true,
|
||||
"jsx": "preserve",
|
||||
"incremental": true,
|
||||
"plugins": [
|
||||
{
|
||||
"name": "next"
|
||||
}
|
||||
],
|
||||
"paths": {
|
||||
"@/*": ["./*"]
|
||||
}
|
||||
},
|
||||
"include": ["next-env.d.ts", "**/*.ts", "**/*.tsx", ".next/types/**/*.ts"],
|
||||
"exclude": ["node_modules"]
|
||||
}
|
||||
30
examples/agent-kit-nextjs-langchain/utils/markdownToHTML.ts
Normal file
30
examples/agent-kit-nextjs-langchain/utils/markdownToHTML.ts
Normal file
@@ -0,0 +1,30 @@
|
||||
import { marked } from "marked";
|
||||
import DOMPurify from "isomorphic-dompurify";
|
||||
|
||||
interface MarkedOptions {
|
||||
gfm: boolean;
|
||||
breaks: boolean;
|
||||
headerIds: boolean;
|
||||
mangle: false;
|
||||
highlight?: (code: string, lang: string) => string;
|
||||
}
|
||||
|
||||
// Configure marked options
|
||||
const markedOptions: MarkedOptions = {
|
||||
gfm: true, // GitHub Flavored Markdown
|
||||
breaks: true, // Convert \n to <br>
|
||||
headerIds: true, // Add ids to headers
|
||||
mangle: false, // Don't escape HTML
|
||||
highlight: function (code: string, lang: string): string {
|
||||
// You can add syntax highlighting here if needed
|
||||
return code;
|
||||
},
|
||||
};
|
||||
|
||||
marked.setOptions(markedOptions);
|
||||
|
||||
// Basic markdown to HTML conversion with sanitization
|
||||
export default function markdownToHtml(markdown: string) {
|
||||
const rawHtml = marked.parse(markdown);
|
||||
return DOMPurify.sanitize(rawHtml as string);
|
||||
}
|
||||
@@ -15,7 +15,7 @@ To use this feature, ensure you have the following:
|
||||
|
||||
1. **PostgreSQL Database URL**: Create and host ur PostgreSQL databse and enter the URL. It will be of the format "postgresql://user:password@localhost:5432/db"
|
||||
|
||||
## Before applying persistance
|
||||
## Without persistence
|
||||
```
|
||||
Available modes:
|
||||
1. chat
|
||||
@@ -27,7 +27,7 @@ Starting chat mode... Type 'exit' to end.
|
||||
Prompt: i am arpit
|
||||
Hello Arpit! How can I assist you today?
|
||||
Prompt: ^С
|
||||
® arpitsingh Mac persistance-agent & ts-node index.ts
|
||||
® arpitsingh Mac persistent-agent & ts-node index.ts
|
||||
Starting Agent...
|
||||
Available modes:
|
||||
1. chat
|
||||
@@ -39,7 +39,7 @@ Starting chat mode... Type 'exit' to end.
|
||||
Prompt: do u know my name
|
||||
I don't know your name yet. If you'd like, you can share it.
|
||||
```
|
||||
## After applying persistence
|
||||
## With persistence
|
||||
```
|
||||
Available modes:
|
||||
1. chat
|
||||
@@ -51,7 +51,7 @@ Starting chat mode... Type 'exit' to end.
|
||||
Prompt: i am arpit
|
||||
Hello Arpit! How can I assist you today?
|
||||
Prompt: ^С
|
||||
® arpitsingh Mac persistance-agent & ts-node index.ts
|
||||
® arpitsingh Mac persistent-agent & ts-node index.ts
|
||||
Starting Agent...
|
||||
Available modes:
|
||||
1. chat
|
||||
@@ -1,8 +1,10 @@
|
||||
|
||||
# Telegram Bot Starter with Solana Agent Kit
|
||||
|
||||
This example showcases how we can make a telegram bot with the Solana Agent Kit by Send AI.
|
||||
|
||||
## Quick Deploy
|
||||
[](https://vercel.com/new/clone?repository-url=https%3A%2F%2Fgithub.com%2Fsendaifun%2Fsolana-agent-kit%2Ftree%2Fmain%2Fexamples%2Ftg-bot-starter&env=OPENAI_API_KEY,RPC_URL,SOLANA_PRIVATE_KEY,TELEGRAM_BOT_TOKEN&project-name=solana-agent-kit&repository-name=sak-yourprojectname)
|
||||
|
||||
## How to get the telegram bot token
|
||||
|
||||
You can check [here](https://help.zoho.com/portal/en/kb/desk/support-channels/instant-messaging/telegram/articles/telegram-integration-with-zoho-desk#How_to_find_a_token_for_an_existing_Telegram_Bot) how you can obtain a bot token for your telegram bot.
|
||||
@@ -18,5 +20,5 @@ You can check [here](https://help.zoho.com/portal/en/kb/desk/support-channels/in
|
||||
- You can host it on Vercel too as we have used NextJs in this.
|
||||
- Once the URL is set successfully, you will see this ``` {"ok":true,"result":true,"description":"Webhook was set"} ```
|
||||
|
||||
Done!!! Congrtulations you just hosted Solana Agent Kit on a Telegram bot.
|
||||
Done!!! Congratulations you just hosted Solana Agent Kit on a Telegram bot.
|
||||
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
{
|
||||
"name": "solana-agent-kit",
|
||||
"version": "1.3.1",
|
||||
"version": "1.3.4",
|
||||
"description": "connect any ai agents to solana protocols",
|
||||
"main": "dist/index.js",
|
||||
"types": "dist/index.d.ts",
|
||||
@@ -24,6 +24,7 @@
|
||||
"dependencies": {
|
||||
"@ai-sdk/openai": "^1.0.11",
|
||||
"@bonfida/spl-name-service": "^3.0.7",
|
||||
"@cks-systems/manifest-sdk": "^0.1.73",
|
||||
"@coral-xyz/anchor": "0.29",
|
||||
"@langchain/core": "^0.3.26",
|
||||
"@langchain/groq": "^0.1.2",
|
||||
@@ -44,6 +45,7 @@
|
||||
"@raydium-io/raydium-sdk-v2": "0.1.95-alpha",
|
||||
"@solana/spl-token": "^0.4.9",
|
||||
"ai": "^4.0.22",
|
||||
"@tensor-oss/tensorswap-sdk": "^4.5.0",
|
||||
"@solana/web3.js": "^1.98.0",
|
||||
"@tiplink/api": "^0.3.1",
|
||||
"bn.js": "^5.2.1",
|
||||
@@ -55,7 +57,8 @@
|
||||
"zod": "^3.24.1"
|
||||
"langchain": "^0.3.8",
|
||||
"openai": "^4.77.0",
|
||||
"typedoc": "^0.27.6"
|
||||
"typedoc": "^0.27.6",
|
||||
"zod": "^3.24.1"
|
||||
},
|
||||
"devDependencies": {
|
||||
"@types/bn.js": "^5.1.6",
|
||||
|
||||
1437
pnpm-lock.yaml
generated
1437
pnpm-lock.yaml
generated
File diff suppressed because it is too large
Load Diff
62
src/actions/balance.ts
Normal file
62
src/actions/balance.ts
Normal file
@@ -0,0 +1,62 @@
|
||||
import { PublicKey } from "@solana/web3.js";
|
||||
import { Action } from "../types/action";
|
||||
import { SolanaAgentKit } from "../agent";
|
||||
import { z } from "zod";
|
||||
import { get_balance } from "../tools";
|
||||
|
||||
const balanceAction: Action = {
|
||||
name: "BALANCE_ACTION",
|
||||
similes: [
|
||||
"check balance",
|
||||
"get wallet balance",
|
||||
"view balance",
|
||||
"show balance",
|
||||
"check token balance",
|
||||
],
|
||||
description: `Get the balance of a Solana wallet or token account.
|
||||
If you want to get the balance of your wallet, you don't need to provide the tokenAddress.
|
||||
If no tokenAddress is provided, the balance will be in SOL.`,
|
||||
examples: [
|
||||
[
|
||||
{
|
||||
input: {},
|
||||
output: {
|
||||
status: "success",
|
||||
balance: "100",
|
||||
token: "SOL",
|
||||
},
|
||||
explanation: "Get SOL balance of the wallet",
|
||||
},
|
||||
],
|
||||
[
|
||||
{
|
||||
input: {
|
||||
tokenAddress: "EPjFWdd5AufqSSqeM2qN1xzybapC8G4wEGGkZwyTDt1v",
|
||||
},
|
||||
output: {
|
||||
status: "success",
|
||||
balance: "1000",
|
||||
token: "EPjFWdd5AufqSSqeM2qN1xzybapC8G4wEGGkZwyTDt1v",
|
||||
},
|
||||
explanation: "Get USDC token balance",
|
||||
},
|
||||
],
|
||||
],
|
||||
schema: z.object({
|
||||
tokenAddress: z.string().optional(),
|
||||
}),
|
||||
handler: async (agent: SolanaAgentKit, input: Record<string, any>) => {
|
||||
const balance = await get_balance(
|
||||
agent,
|
||||
input.tokenAddress && new PublicKey(input.tokenAddress),
|
||||
);
|
||||
|
||||
return {
|
||||
status: "success",
|
||||
balance: balance,
|
||||
token: input.tokenAddress || "SOL",
|
||||
};
|
||||
},
|
||||
};
|
||||
|
||||
export default balanceAction;
|
||||
104
src/actions/compressedAirdrop.ts
Normal file
104
src/actions/compressedAirdrop.ts
Normal file
@@ -0,0 +1,104 @@
|
||||
import { Action } from "../types/action";
|
||||
import { SolanaAgentKit } from "../agent";
|
||||
import { z } from "zod";
|
||||
import { sendCompressedAirdrop } from "../tools";
|
||||
|
||||
const compressedAirdropAction: Action = {
|
||||
name: "COMPRESSED_AIRDROP",
|
||||
similes: [
|
||||
"ZK Compressed airdrop",
|
||||
"Airdrop tokens with compression",
|
||||
"Send compressed SPL airdrop",
|
||||
"Airdrop to multiple recipients",
|
||||
],
|
||||
description:
|
||||
"Airdrop SPL tokens with ZK Compression (also known as airdropping tokens) to multiple recipients",
|
||||
examples: [
|
||||
[
|
||||
{
|
||||
input: {
|
||||
mintAddress: "JUPyiwrYJFskUPiHa7hkeR8VUtAeFoSYbKedZNsDvCN",
|
||||
amount: 42,
|
||||
decimals: 6,
|
||||
recipients: [
|
||||
"1nc1nerator11111111111111111111111111111111",
|
||||
"BrFndAe111111111111111111111111111111111",
|
||||
],
|
||||
priorityFeeInLamports: 30000,
|
||||
shouldLog: true,
|
||||
},
|
||||
output: {
|
||||
status: "success",
|
||||
message: "Airdropped 42 tokens to 2 recipients.",
|
||||
transactionHashes: ["4uyfBN...", "9XsF2N..."],
|
||||
},
|
||||
explanation:
|
||||
"Airdrops 42 tokens (with 6 decimals) to 2 recipients, optionally logging progress to stdout.",
|
||||
},
|
||||
],
|
||||
],
|
||||
// Validate inputs with zod
|
||||
schema: z.object({
|
||||
mintAddress: z
|
||||
.string()
|
||||
.min(1)
|
||||
.describe("Mint address of the token, e.g., 'JUPy...'"),
|
||||
amount: z
|
||||
.number()
|
||||
.positive()
|
||||
.describe("Number of tokens to airdrop per recipient, e.g., 42"),
|
||||
decimals: z
|
||||
.number()
|
||||
.nonnegative()
|
||||
.int()
|
||||
.describe("Decimals of the token, e.g., 6"),
|
||||
recipients: z
|
||||
.array(z.string())
|
||||
.nonempty()
|
||||
.describe("Array of recipient addresses, e.g., ['1nc1n...']"),
|
||||
priorityFeeInLamports: z
|
||||
.number()
|
||||
.optional()
|
||||
.describe("Priority fee in lamports (default is 30_000)"),
|
||||
shouldLog: z
|
||||
.boolean()
|
||||
.optional()
|
||||
.describe("Whether to log progress to stdout (default is false)"),
|
||||
}),
|
||||
handler: async (agent: SolanaAgentKit, input: Record<string, any>) => {
|
||||
try {
|
||||
const {
|
||||
mintAddress,
|
||||
amount,
|
||||
decimals,
|
||||
recipients,
|
||||
priorityFeeInLamports,
|
||||
shouldLog,
|
||||
} = input;
|
||||
|
||||
// Call your airdrop method on the SolanaAgentKit
|
||||
const txs = await sendCompressedAirdrop(
|
||||
mintAddress,
|
||||
amount,
|
||||
decimals,
|
||||
recipients,
|
||||
priorityFeeInLamports || 30_000,
|
||||
shouldLog || false,
|
||||
);
|
||||
|
||||
return {
|
||||
status: "success",
|
||||
message: `Airdropped ${amount} tokens to ${recipients.length} recipients.`,
|
||||
transactionHashes: txs,
|
||||
};
|
||||
} catch (error: any) {
|
||||
return {
|
||||
status: "error",
|
||||
message: `Failed to airdrop tokens: ${error.message}`,
|
||||
code: error.code || "UNKNOWN_ERROR",
|
||||
};
|
||||
}
|
||||
},
|
||||
};
|
||||
|
||||
export default compressedAirdropAction;
|
||||
86
src/actions/createGibworkTask.ts
Normal file
86
src/actions/createGibworkTask.ts
Normal file
@@ -0,0 +1,86 @@
|
||||
import { Action } from "../types/action";
|
||||
import { SolanaAgentKit } from "../agent";
|
||||
import { z } from "zod";
|
||||
import { PublicKey } from "@solana/web3.js";
|
||||
import { create_gibwork_task } from "../tools";
|
||||
|
||||
const createGibworkTaskAction: Action = {
|
||||
name: "CREATE_GIBWORK_TASK",
|
||||
similes: [
|
||||
"create task",
|
||||
"post job",
|
||||
"create gig",
|
||||
"post task",
|
||||
"create work",
|
||||
"new task on gibwork",
|
||||
],
|
||||
description:
|
||||
"Create a new task on the Gibwork platform with payment in SPL tokens",
|
||||
examples: [
|
||||
[
|
||||
{
|
||||
input: {
|
||||
title: "Build a Solana dApp",
|
||||
content: "Create a simple Solana dApp with React frontend",
|
||||
requirements: "Experience with Rust and React",
|
||||
tags: ["solana", "rust", "react"],
|
||||
tokenMintAddress: "EPjFWdd5AufqSSqeM2qN1xzybapC8G4wEGGkZwyTDt1v",
|
||||
tokenAmount: 100,
|
||||
},
|
||||
output: {
|
||||
status: "success",
|
||||
taskId: "task_123",
|
||||
signature: "3YKpM1...",
|
||||
message: "Successfully created task: Build a Solana dApp",
|
||||
},
|
||||
explanation: "Create a new task on Gibwork with 100 USDC payment",
|
||||
},
|
||||
],
|
||||
],
|
||||
schema: z.object({
|
||||
title: z.string().min(1).describe("Title of the task"),
|
||||
content: z.string().min(1).describe("Description of the task"),
|
||||
requirements: z
|
||||
.string()
|
||||
.min(1)
|
||||
.describe("Requirements to complete the task"),
|
||||
tags: z
|
||||
.array(z.string())
|
||||
.min(1)
|
||||
.describe("List of tags associated with the task"),
|
||||
tokenMintAddress: z.string().describe("Token mint address for payment"),
|
||||
tokenAmount: z.number().positive().describe("Payment amount for the task"),
|
||||
payer: z
|
||||
.string()
|
||||
.optional()
|
||||
.describe("Optional payer address (defaults to wallet address)"),
|
||||
}),
|
||||
handler: async (agent: SolanaAgentKit, input: Record<string, any>) => {
|
||||
try {
|
||||
const responseData = await create_gibwork_task(
|
||||
agent,
|
||||
input.title,
|
||||
input.content,
|
||||
input.requirements,
|
||||
input.tags,
|
||||
new PublicKey(input.tokenMintAddress),
|
||||
input.tokenAmount,
|
||||
input.payer ? new PublicKey(input.payer) : undefined,
|
||||
);
|
||||
|
||||
return {
|
||||
status: "success",
|
||||
taskId: responseData.taskId,
|
||||
signature: responseData.signature,
|
||||
message: `Successfully created task: ${input.title}`,
|
||||
};
|
||||
} catch (error: any) {
|
||||
return {
|
||||
status: "error",
|
||||
message: `Failed to create task: ${error.message}`,
|
||||
};
|
||||
}
|
||||
},
|
||||
};
|
||||
|
||||
export default createGibworkTaskAction;
|
||||
101
src/actions/createImage.ts
Normal file
101
src/actions/createImage.ts
Normal file
@@ -0,0 +1,101 @@
|
||||
import { Action } from "../types/action";
|
||||
import { SolanaAgentKit } from "../agent";
|
||||
import { z } from "zod";
|
||||
import { create_image } from "../tools/create_image";
|
||||
|
||||
const createImageAction: Action = {
|
||||
name: "CREATE_IMAGE",
|
||||
similes: [
|
||||
"generate image",
|
||||
"create artwork",
|
||||
"make image",
|
||||
"generate artwork",
|
||||
"create picture",
|
||||
"generate picture",
|
||||
],
|
||||
description:
|
||||
"Create an AI-generated image based on a text prompt using OpenAI's DALL-E models",
|
||||
examples: [
|
||||
[
|
||||
{
|
||||
input: {
|
||||
prompt: "A beautiful sunset over a mountain landscape",
|
||||
model: "dall-e-3",
|
||||
size: "1024x1024",
|
||||
quality: "standard",
|
||||
style: "natural",
|
||||
},
|
||||
output: {
|
||||
status: "success",
|
||||
imageUrl: "https://example.com/image.png",
|
||||
message: "Successfully generated image",
|
||||
},
|
||||
explanation: "Generate an image of a sunset landscape using DALL-E 3",
|
||||
},
|
||||
],
|
||||
],
|
||||
schema: z.object({
|
||||
prompt: z
|
||||
.string()
|
||||
.min(1)
|
||||
.max(1000)
|
||||
.describe("The text description of the image to generate"),
|
||||
model: z
|
||||
.enum(["dall-e-3"])
|
||||
.default("dall-e-3")
|
||||
.describe("The AI model to use for generation"),
|
||||
size: z
|
||||
.enum(["256x256", "512x512", "1024x1024", "1792x1024", "1024x1792"])
|
||||
.default("1024x1024")
|
||||
.describe("The size of the generated image"),
|
||||
quality: z
|
||||
.enum(["standard", "hd"])
|
||||
.default("standard")
|
||||
.describe("The quality level of the generated image"),
|
||||
style: z
|
||||
.enum(["natural", "vivid"])
|
||||
.default("natural")
|
||||
.describe("The style of the generated image"),
|
||||
}),
|
||||
handler: async (agent: SolanaAgentKit, input: Record<string, any>) => {
|
||||
try {
|
||||
if (!agent.config.OPENAI_API_KEY) {
|
||||
return {
|
||||
status: "error",
|
||||
message: "OpenAI API key not found in agent configuration",
|
||||
};
|
||||
}
|
||||
|
||||
const { prompt, model, size } = input;
|
||||
const response = await create_image(agent, prompt, model, size);
|
||||
|
||||
return {
|
||||
status: "success",
|
||||
imageUrl: response.images[0].url,
|
||||
message: "Successfully generated image",
|
||||
};
|
||||
} catch (error: any) {
|
||||
// Handle specific OpenAI error types
|
||||
if (error.response) {
|
||||
const { status, data } = error.response;
|
||||
if (status === 429) {
|
||||
return {
|
||||
status: "error",
|
||||
message: "Rate limit exceeded. Please try again later.",
|
||||
};
|
||||
}
|
||||
return {
|
||||
status: "error",
|
||||
message: `OpenAI API error: ${data.error?.message || error.message}`,
|
||||
};
|
||||
}
|
||||
|
||||
return {
|
||||
status: "error",
|
||||
message: `Failed to generate image: ${error.message}`,
|
||||
};
|
||||
}
|
||||
},
|
||||
};
|
||||
|
||||
export default createImageAction;
|
||||
80
src/actions/createOpenbookMarket.ts
Normal file
80
src/actions/createOpenbookMarket.ts
Normal file
@@ -0,0 +1,80 @@
|
||||
import { Action } from "../types/action";
|
||||
import { SolanaAgentKit } from "../agent";
|
||||
import { z } from "zod";
|
||||
import { PublicKey } from "@solana/web3.js";
|
||||
import { openbookCreateMarket } from "../tools";
|
||||
|
||||
const createOpenbookMarketAction: Action = {
|
||||
name: "CREATE_OPENBOOK_MARKET",
|
||||
similes: [
|
||||
"create openbook market",
|
||||
"setup trading market",
|
||||
"new openbook market",
|
||||
"create trading pair",
|
||||
"setup dex market",
|
||||
"new trading market",
|
||||
],
|
||||
description: "Create a new trading market on Openbook DEX",
|
||||
examples: [
|
||||
[
|
||||
{
|
||||
input: {
|
||||
baseMint: "EPjFWdd5AufqSSqeM2qN1xzybapC8G4wEGGkZwyTDt1v", // USDC
|
||||
quoteMint: "So11111111111111111111111111111111111111112", // SOL
|
||||
lotSize: 1,
|
||||
tickSize: 0.01,
|
||||
},
|
||||
output: {
|
||||
status: "success",
|
||||
signatures: ["2ZE7Rz...", "3YKpM1..."],
|
||||
message: "Successfully created Openbook market",
|
||||
},
|
||||
explanation:
|
||||
"Create a new USDC/SOL market on Openbook with default lot and tick sizes",
|
||||
},
|
||||
],
|
||||
],
|
||||
schema: z.object({
|
||||
baseMint: z.string().min(1).describe("The base token's mint address"),
|
||||
quoteMint: z.string().min(1).describe("The quote token's mint address"),
|
||||
lotSize: z
|
||||
.number()
|
||||
.positive()
|
||||
.default(1)
|
||||
.describe("The minimum order size (lot size)"),
|
||||
tickSize: z
|
||||
.number()
|
||||
.positive()
|
||||
.default(0.01)
|
||||
.describe("The minimum price increment (tick size)"),
|
||||
}),
|
||||
handler: async (agent: SolanaAgentKit, input: Record<string, any>) => {
|
||||
try {
|
||||
const baseMint = new PublicKey(input.baseMint);
|
||||
const quoteMint = new PublicKey(input.quoteMint);
|
||||
const lotSize = input.lotSize || 1;
|
||||
const tickSize = input.tickSize || 0.01;
|
||||
|
||||
const signatures = await openbookCreateMarket(
|
||||
agent,
|
||||
baseMint,
|
||||
quoteMint,
|
||||
lotSize,
|
||||
tickSize,
|
||||
);
|
||||
|
||||
return {
|
||||
status: "success",
|
||||
signatures,
|
||||
message: "Successfully created Openbook market",
|
||||
};
|
||||
} catch (error: any) {
|
||||
return {
|
||||
status: "error",
|
||||
message: `Failed to create Openbook market: ${error.message}`,
|
||||
};
|
||||
}
|
||||
},
|
||||
};
|
||||
|
||||
export default createOpenbookMarketAction;
|
||||
117
src/actions/createOrcaSingleSidedWhirlpool.ts
Normal file
117
src/actions/createOrcaSingleSidedWhirlpool.ts
Normal file
@@ -0,0 +1,117 @@
|
||||
import { Action } from "../types/action";
|
||||
import { SolanaAgentKit } from "../agent";
|
||||
import { z } from "zod";
|
||||
import { PublicKey } from "@solana/web3.js";
|
||||
import { BN } from "@coral-xyz/anchor";
|
||||
import { Decimal } from "decimal.js";
|
||||
import { orcaCreateSingleSidedLiquidityPool } from "../tools";
|
||||
|
||||
// Fee tiers mapping from the original tool
|
||||
const FEE_TIERS = {
|
||||
0.01: 1,
|
||||
0.02: 2,
|
||||
0.04: 4,
|
||||
0.05: 8,
|
||||
0.16: 16,
|
||||
0.3: 64,
|
||||
0.65: 96,
|
||||
1.0: 128,
|
||||
2.0: 256,
|
||||
} as const;
|
||||
|
||||
const createOrcaSingleSidedWhirlpoolAction: Action = {
|
||||
name: "CREATE_ORCA_SINGLE_SIDED_WHIRLPOOL",
|
||||
similes: [
|
||||
"create orca whirlpool",
|
||||
"setup orca single sided pool",
|
||||
"initialize orca whirlpool",
|
||||
"create orca concentrated pool",
|
||||
"setup orca concentrated liquidity",
|
||||
"create orca trading pair",
|
||||
],
|
||||
description:
|
||||
"Create a new single-sided whirlpool on Orca with concentrated liquidity",
|
||||
examples: [
|
||||
[
|
||||
{
|
||||
input: {
|
||||
depositTokenAmount: "1000000000000", // 1 million tokens with 6 decimals
|
||||
depositTokenMint: "EPjFWdd5AufqSSqeM2qN1xzybapC8G4wEGGkZwyTDt1v", // USDC
|
||||
otherTokenMint: "So11111111111111111111111111111111111111112", // SOL
|
||||
initialPrice: "0.001",
|
||||
maxPrice: "5.0",
|
||||
feeTier: 0.3,
|
||||
},
|
||||
output: {
|
||||
status: "success",
|
||||
signature: "2ZE7Rz...",
|
||||
message: "Successfully created Orca single-sided whirlpool",
|
||||
},
|
||||
explanation:
|
||||
"Create a USDC/SOL whirlpool with 1M USDC initial liquidity",
|
||||
},
|
||||
],
|
||||
],
|
||||
schema: z.object({
|
||||
depositTokenAmount: z
|
||||
.string()
|
||||
.min(1)
|
||||
.describe(
|
||||
"The amount of deposit token to provide as liquidity (including decimals)",
|
||||
),
|
||||
depositTokenMint: z
|
||||
.string()
|
||||
.min(1)
|
||||
.describe("The mint address of the token being deposited"),
|
||||
otherTokenMint: z
|
||||
.string()
|
||||
.min(1)
|
||||
.describe("The mint address of the other token in the pool"),
|
||||
initialPrice: z
|
||||
.string()
|
||||
.min(1)
|
||||
.describe("Initial price of deposit token in terms of the other token"),
|
||||
maxPrice: z
|
||||
.string()
|
||||
.min(1)
|
||||
.describe("Maximum price at which liquidity is added"),
|
||||
feeTier: z
|
||||
.number()
|
||||
.refine((val) => val in FEE_TIERS, "Invalid fee tier")
|
||||
.describe("Fee tier percentage for the pool (e.g., 0.3 for 0.3%)"),
|
||||
}),
|
||||
handler: async (agent: SolanaAgentKit, input: Record<string, any>) => {
|
||||
try {
|
||||
const depositTokenAmount = Number(input.depositTokenAmount);
|
||||
const depositTokenMint = new PublicKey(input.depositTokenMint);
|
||||
const otherTokenMint = new PublicKey(input.otherTokenMint);
|
||||
const initialPrice = new Decimal(input.initialPrice);
|
||||
const maxPrice = new Decimal(input.maxPrice);
|
||||
const feeTier = input.feeTier
|
||||
|
||||
// Create the whirlpool
|
||||
const signature = await orcaCreateSingleSidedLiquidityPool(
|
||||
agent,
|
||||
depositTokenAmount,
|
||||
depositTokenMint,
|
||||
otherTokenMint,
|
||||
initialPrice,
|
||||
maxPrice,
|
||||
feeTier,
|
||||
);
|
||||
|
||||
return {
|
||||
status: "success",
|
||||
signature,
|
||||
message: "Successfully created Orca single-sided whirlpool",
|
||||
};
|
||||
} catch (error: any) {
|
||||
return {
|
||||
status: "error",
|
||||
message: `Failed to create whirlpool: ${error.message}`,
|
||||
};
|
||||
}
|
||||
},
|
||||
};
|
||||
|
||||
export default createOrcaSingleSidedWhirlpoolAction;
|
||||
78
src/actions/deployCollection.ts
Normal file
78
src/actions/deployCollection.ts
Normal file
@@ -0,0 +1,78 @@
|
||||
import { Action } from "../types/action";
|
||||
import { SolanaAgentKit } from "../agent";
|
||||
import { z } from "zod";
|
||||
import { deploy_collection } from "../tools";
|
||||
|
||||
interface CollectionOptions {
|
||||
name: string;
|
||||
uri: string;
|
||||
royaltyBasisPoints?: number;
|
||||
}
|
||||
|
||||
const deployCollectionAction: Action = {
|
||||
name: "DEPLOY_COLLECTION",
|
||||
similes: [
|
||||
"create collection",
|
||||
"launch collection",
|
||||
"deploy nft collection",
|
||||
"create nft collection",
|
||||
"mint collection",
|
||||
],
|
||||
description: `Deploy a new NFT collection on Solana blockchain.`,
|
||||
examples: [
|
||||
[
|
||||
{
|
||||
input: {
|
||||
name: "My Collection",
|
||||
uri: "https://example.com/collection.json",
|
||||
royaltyBasisPoints: 500,
|
||||
},
|
||||
output: {
|
||||
status: "success",
|
||||
message: "Collection deployed successfully",
|
||||
collectionAddress: "7nE9GvcwsqzYxmJLSrYmSB1V1YoJWVK1KWzAcWAzjXkN",
|
||||
name: "My Collection",
|
||||
},
|
||||
explanation: "Deploy an NFT collection with 5% royalty",
|
||||
},
|
||||
],
|
||||
[
|
||||
{
|
||||
input: {
|
||||
name: "Basic Collection",
|
||||
uri: "https://example.com/basic.json",
|
||||
},
|
||||
output: {
|
||||
status: "success",
|
||||
message: "Collection deployed successfully",
|
||||
collectionAddress: "8nE9GvcwsqzYxmJLSrYmSB1V1YoJWVK1KWzAcWAzjXkM",
|
||||
name: "Basic Collection",
|
||||
},
|
||||
explanation: "Deploy a basic NFT collection without royalties",
|
||||
},
|
||||
],
|
||||
],
|
||||
schema: z.object({
|
||||
name: z.string().min(1, "Name is required"),
|
||||
uri: z.string().url("URI must be a valid URL"),
|
||||
royaltyBasisPoints: z.number().min(0).max(10000).optional(),
|
||||
}),
|
||||
handler: async (agent: SolanaAgentKit, input: Record<string, any>) => {
|
||||
const options: CollectionOptions = {
|
||||
name: input.name,
|
||||
uri: input.uri,
|
||||
royaltyBasisPoints: input.royaltyBasisPoints,
|
||||
};
|
||||
|
||||
const result = await deploy_collection(agent, options);
|
||||
|
||||
return {
|
||||
status: "success",
|
||||
message: "Collection deployed successfully",
|
||||
collectionAddress: result.collectionAddress.toString(),
|
||||
name: input.name,
|
||||
};
|
||||
},
|
||||
};
|
||||
|
||||
export default deployCollectionAction;
|
||||
83
src/actions/deployToken.ts
Normal file
83
src/actions/deployToken.ts
Normal file
@@ -0,0 +1,83 @@
|
||||
import { Action } from "../types/action";
|
||||
import { SolanaAgentKit } from "../agent";
|
||||
import { z } from "zod";
|
||||
import { deploy_token } from "../tools";
|
||||
|
||||
const deployTokenAction: Action = {
|
||||
name: "DEPLOY_TOKEN",
|
||||
similes: [
|
||||
"create token",
|
||||
"launch token",
|
||||
"deploy new token",
|
||||
"create new token",
|
||||
"mint token",
|
||||
],
|
||||
description:
|
||||
"Deploy a new SPL token on the Solana blockchain with specified parameters",
|
||||
examples: [
|
||||
[
|
||||
{
|
||||
input: {
|
||||
name: "My Token",
|
||||
uri: "https://example.com/token.json",
|
||||
symbol: "MTK",
|
||||
decimals: 9,
|
||||
initialSupply: 1000000,
|
||||
},
|
||||
output: {
|
||||
mint: "7nE9GvcwsqzYxmJLSrYmSB1V1YoJWVK1KWzAcWAzjXkN",
|
||||
status: "success",
|
||||
message: "Token deployed successfully",
|
||||
},
|
||||
explanation: "Deploy a token with initial supply and metadata",
|
||||
},
|
||||
],
|
||||
[
|
||||
{
|
||||
input: {
|
||||
name: "Basic Token",
|
||||
uri: "https://example.com/basic.json",
|
||||
symbol: "BASIC",
|
||||
},
|
||||
output: {
|
||||
mint: "8nE9GvcwsqzYxmJLSrYmSB1V1YoJWVK1KWzAcWAzjXkM",
|
||||
status: "success",
|
||||
message: "Token deployed successfully",
|
||||
},
|
||||
explanation: "Deploy a basic token with minimal parameters",
|
||||
},
|
||||
],
|
||||
],
|
||||
schema: z.object({
|
||||
name: z.string().min(1, "Name is required"),
|
||||
uri: z.string().url("URI must be a valid URL"),
|
||||
symbol: z.string().min(1, "Symbol is required"),
|
||||
decimals: z.number().optional(),
|
||||
initialSupply: z.number().optional(),
|
||||
}),
|
||||
handler: async (agent: SolanaAgentKit, input: Record<string, any>) => {
|
||||
try {
|
||||
const result = await deploy_token(
|
||||
agent,
|
||||
input.name,
|
||||
input.uri,
|
||||
input.symbol,
|
||||
input.decimals,
|
||||
input.initialSupply,
|
||||
);
|
||||
|
||||
return {
|
||||
mint: result.mint.toString(),
|
||||
status: "success",
|
||||
message: "Token deployed successfully",
|
||||
};
|
||||
} catch (error: any) {
|
||||
return {
|
||||
status: "error",
|
||||
message: `Token deployment failed: ${error.message}`,
|
||||
};
|
||||
}
|
||||
},
|
||||
};
|
||||
|
||||
export default deployTokenAction;
|
||||
57
src/actions/fetchPrice.ts
Normal file
57
src/actions/fetchPrice.ts
Normal file
@@ -0,0 +1,57 @@
|
||||
import { Action } from "../types/action";
|
||||
import { SolanaAgentKit } from "../agent";
|
||||
import { z } from "zod";
|
||||
import { PublicKey } from "@solana/web3.js";
|
||||
import { fetchPrice } from "../tools";
|
||||
|
||||
const fetchPriceAction: Action = {
|
||||
name: "FETCH_PRICE",
|
||||
similes: [
|
||||
"get token price",
|
||||
"check price",
|
||||
"token value",
|
||||
"price check",
|
||||
"get price in usd",
|
||||
],
|
||||
description:
|
||||
"Fetch the current price of a Solana token in USDC using Jupiter API",
|
||||
examples: [
|
||||
[
|
||||
{
|
||||
input: {
|
||||
tokenAddress: "So11111111111111111111111111111111111111112",
|
||||
},
|
||||
output: {
|
||||
status: "success",
|
||||
price: "23.45",
|
||||
message: "Current price: $23.45 USDC",
|
||||
},
|
||||
explanation: "Get the current price of SOL token in USDC",
|
||||
},
|
||||
],
|
||||
],
|
||||
schema: z.object({
|
||||
tokenAddress: z
|
||||
.string()
|
||||
.describe("The mint address of the token to fetch the price for"),
|
||||
}),
|
||||
handler: async (agent: SolanaAgentKit, input: Record<string, any>) => {
|
||||
try {
|
||||
const tokenId = new PublicKey(input.tokenAddress);
|
||||
const price = await fetchPrice(tokenId);
|
||||
|
||||
return {
|
||||
status: "success",
|
||||
price,
|
||||
message: `Current price: $${price} USDC`,
|
||||
};
|
||||
} catch (error: any) {
|
||||
return {
|
||||
status: "error",
|
||||
message: `Failed to fetch price: ${error.message}`,
|
||||
};
|
||||
}
|
||||
},
|
||||
};
|
||||
|
||||
export default fetchPriceAction;
|
||||
52
src/actions/getAllDomainsTLDs.ts
Normal file
52
src/actions/getAllDomainsTLDs.ts
Normal file
@@ -0,0 +1,52 @@
|
||||
import { Action } from "../types/action";
|
||||
import { SolanaAgentKit } from "../agent";
|
||||
import { z } from "zod";
|
||||
import { getAllDomainsTLDs } from "../tools";
|
||||
|
||||
const getAllDomainsTLDsAction: Action = {
|
||||
name: "GET_ALL_TLDS",
|
||||
similes: [
|
||||
"list domain tlds",
|
||||
"get domain extensions",
|
||||
"fetch domain tlds",
|
||||
"get top level domains",
|
||||
"list available tlds",
|
||||
"get domain suffixes",
|
||||
],
|
||||
description:
|
||||
"Get a list of all available top-level domains (TLDs) for Solana domains",
|
||||
examples: [
|
||||
[
|
||||
{
|
||||
input: {},
|
||||
output: {
|
||||
status: "success",
|
||||
tlds: [".sol", ".abc", ".backpack", ".bonk"],
|
||||
message: "Successfully retrieved all domain TLDs",
|
||||
},
|
||||
explanation:
|
||||
"Get a list of all available TLDs that can be used for Solana domains",
|
||||
},
|
||||
],
|
||||
],
|
||||
schema: z.object({}),
|
||||
handler: async (agent: SolanaAgentKit) => {
|
||||
try {
|
||||
// Get all domain TLDs
|
||||
const tlds = await getAllDomainsTLDs(agent);
|
||||
|
||||
return {
|
||||
status: "success",
|
||||
tlds,
|
||||
message: "Successfully retrieved all domain TLDs",
|
||||
};
|
||||
} catch (error: any) {
|
||||
return {
|
||||
status: "error",
|
||||
message: `Failed to get domain TLDs: ${error.message}`,
|
||||
};
|
||||
}
|
||||
},
|
||||
};
|
||||
|
||||
export default getAllDomainsTLDsAction;
|
||||
70
src/actions/getAllRegisteredAllDomains.ts
Normal file
70
src/actions/getAllRegisteredAllDomains.ts
Normal file
@@ -0,0 +1,70 @@
|
||||
import { Action } from "../types/action";
|
||||
import { SolanaAgentKit } from "../agent";
|
||||
import { z } from "zod";
|
||||
import { getAllRegisteredAllDomains } from "../tools";
|
||||
|
||||
const getAllRegisteredAllDomainsAction: Action = {
|
||||
name: "GET_ALL_REGISTERED_ALL_DOMAINS",
|
||||
similes: [
|
||||
"list registered domains",
|
||||
"get all domains",
|
||||
"fetch registered domains",
|
||||
"get domain list",
|
||||
"list active domains",
|
||||
"get registered names",
|
||||
],
|
||||
description: "Get a list of all registered domains across all TLDs",
|
||||
examples: [
|
||||
[
|
||||
{
|
||||
input: {
|
||||
limit: 100,
|
||||
offset: 0,
|
||||
},
|
||||
output: {
|
||||
status: "success",
|
||||
domains: ["solana.sol", "bonk.abc", "wallet.backpack"],
|
||||
total: 3,
|
||||
message: "Successfully retrieved registered domains",
|
||||
},
|
||||
explanation: "Get the first 100 registered domains across all TLDs",
|
||||
},
|
||||
],
|
||||
],
|
||||
schema: z.object({
|
||||
limit: z
|
||||
.number()
|
||||
.positive()
|
||||
.max(1000)
|
||||
.default(100)
|
||||
.describe("Maximum number of domains to return"),
|
||||
offset: z
|
||||
.number()
|
||||
.nonnegative()
|
||||
.default(0)
|
||||
.describe("Number of domains to skip"),
|
||||
}),
|
||||
handler: async (agent: SolanaAgentKit, input: Record<string, any>) => {
|
||||
try {
|
||||
const limit = input.limit || 100;
|
||||
const offset = input.offset || 0;
|
||||
|
||||
// Get all registered domains
|
||||
const domains = await getAllRegisteredAllDomains(agent);
|
||||
|
||||
return {
|
||||
status: "success",
|
||||
domains: domains.slice(offset, offset + limit),
|
||||
total: domains.length,
|
||||
message: "Successfully retrieved registered domains",
|
||||
};
|
||||
} catch (error: any) {
|
||||
return {
|
||||
status: "error",
|
||||
message: `Failed to get registered domains: ${error.message}`,
|
||||
};
|
||||
}
|
||||
},
|
||||
};
|
||||
|
||||
export default getAllRegisteredAllDomainsAction;
|
||||
67
src/actions/getMainAllDomainsDomain.ts
Normal file
67
src/actions/getMainAllDomainsDomain.ts
Normal file
@@ -0,0 +1,67 @@
|
||||
import { Action } from "../types/action";
|
||||
import { SolanaAgentKit } from "../agent";
|
||||
import { z } from "zod";
|
||||
import { PublicKey } from "@solana/web3.js";
|
||||
import { getMainAllDomainsDomain } from "../tools";
|
||||
|
||||
const getMainAllDomainsDomainAction: Action = {
|
||||
name: "GET_MAIN_ALL_DOMAINS_DOMAIN",
|
||||
similes: [
|
||||
"get main domain",
|
||||
"fetch primary domain",
|
||||
"get default domain",
|
||||
"get main address name",
|
||||
"get primary name",
|
||||
"get main domain name",
|
||||
],
|
||||
description: "Get the main domain associated with a wallet address",
|
||||
examples: [
|
||||
[
|
||||
{
|
||||
input: {
|
||||
address: "7nxQB...",
|
||||
},
|
||||
output: {
|
||||
status: "success",
|
||||
domain: "solana.sol",
|
||||
message: "Successfully retrieved main domain",
|
||||
},
|
||||
explanation: "Get the main domain name for a given wallet address",
|
||||
},
|
||||
],
|
||||
],
|
||||
schema: z.object({
|
||||
address: z
|
||||
.string()
|
||||
.min(1)
|
||||
.describe("The wallet address to get the main domain for"),
|
||||
}),
|
||||
handler: async (agent: SolanaAgentKit, input: Record<string, any>) => {
|
||||
try {
|
||||
const mainDomain = await getMainAllDomainsDomain(
|
||||
agent,
|
||||
new PublicKey(input.address),
|
||||
);
|
||||
|
||||
if (!mainDomain) {
|
||||
return {
|
||||
status: "error",
|
||||
message: "No main domain found for this address",
|
||||
};
|
||||
}
|
||||
|
||||
return {
|
||||
status: "success",
|
||||
domain: mainDomain,
|
||||
message: "Successfully retrieved main domain",
|
||||
};
|
||||
} catch (error: any) {
|
||||
return {
|
||||
status: "error",
|
||||
message: `Failed to get main domain: ${error.message}`,
|
||||
};
|
||||
}
|
||||
},
|
||||
};
|
||||
|
||||
export default getMainAllDomainsDomainAction;
|
||||
63
src/actions/getOwnedAllDomains.ts
Normal file
63
src/actions/getOwnedAllDomains.ts
Normal file
@@ -0,0 +1,63 @@
|
||||
import { Action } from "../types/action";
|
||||
import { SolanaAgentKit } from "../agent";
|
||||
import { z } from "zod";
|
||||
import { PublicKey } from "@solana/web3.js";
|
||||
import { getOwnedAllDomains } from "../tools";
|
||||
|
||||
const getOwnedAllDomainsAction: Action = {
|
||||
name: "GET_OWNED_ALL_DOMAINS",
|
||||
similes: [
|
||||
"list owned domains",
|
||||
"get my domains",
|
||||
"fetch wallet domains",
|
||||
"get owned names",
|
||||
"list my domains",
|
||||
"get address domains",
|
||||
],
|
||||
description:
|
||||
"Get all domains owned by a specific wallet address across all TLDs",
|
||||
examples: [
|
||||
[
|
||||
{
|
||||
input: {
|
||||
address: "7nxQB...",
|
||||
},
|
||||
output: {
|
||||
status: "success",
|
||||
domains: ["solana.sol", "wallet.abc", "user.backpack"],
|
||||
total: 3,
|
||||
message: "Successfully retrieved owned domains",
|
||||
},
|
||||
explanation: "Get all domain names owned by a specific wallet address",
|
||||
},
|
||||
],
|
||||
],
|
||||
schema: z.object({
|
||||
address: z
|
||||
.string()
|
||||
.min(1)
|
||||
.describe("The wallet address to get owned domains for"),
|
||||
}),
|
||||
handler: async (agent: SolanaAgentKit, input: Record<string, any>) => {
|
||||
try {
|
||||
const address = new PublicKey(input.address);
|
||||
|
||||
// Get owned domains
|
||||
const domains = await getOwnedAllDomains(agent, address);
|
||||
|
||||
return {
|
||||
status: "success",
|
||||
domains,
|
||||
total: domains.length,
|
||||
message: `Successfully retrieved ${domains.length} owned domain${domains.length === 1 ? "" : "s"}`,
|
||||
};
|
||||
} catch (error: any) {
|
||||
return {
|
||||
status: "error",
|
||||
message: `Failed to get owned domains: ${error.message}`,
|
||||
};
|
||||
}
|
||||
},
|
||||
};
|
||||
|
||||
export default getOwnedAllDomainsAction;
|
||||
63
src/actions/getOwnedDomainsForTLD.ts
Normal file
63
src/actions/getOwnedDomainsForTLD.ts
Normal file
@@ -0,0 +1,63 @@
|
||||
import { Action } from "../types/action";
|
||||
import { SolanaAgentKit } from "../agent";
|
||||
import { z } from "zod";
|
||||
import { getOwnedDomainsForTLD } from "../tools";
|
||||
|
||||
const getOwnedDomainsForTLDAction: Action = {
|
||||
name: "GET_OWNED_DOMAINS_FOR_TLD",
|
||||
similes: [
|
||||
"list owned domains for tld",
|
||||
"get my domains for extension",
|
||||
"fetch wallet domains by tld",
|
||||
"get owned names by extension",
|
||||
"list my domains by tld",
|
||||
"get address domains for tld",
|
||||
],
|
||||
description:
|
||||
"Get all domains owned by a specific wallet address for a given top-level domain (TLD)",
|
||||
examples: [
|
||||
[
|
||||
{
|
||||
input: {
|
||||
tld: "sol",
|
||||
},
|
||||
output: {
|
||||
status: "success",
|
||||
domains: ["solana.sol", "wallet.sol", "user.sol"],
|
||||
total: 3,
|
||||
message: "Successfully retrieved owned domains for .sol",
|
||||
},
|
||||
explanation:
|
||||
"Get all .sol domain names owned by a specific wallet address",
|
||||
},
|
||||
],
|
||||
],
|
||||
schema: z.object({
|
||||
tld: z
|
||||
.string()
|
||||
.min(1)
|
||||
.describe("The top-level domain to filter by (e.g., 'sol', 'abc')"),
|
||||
}),
|
||||
handler: async (agent: SolanaAgentKit, input: Record<string, any>) => {
|
||||
try {
|
||||
const tld = input.tld.toLowerCase();
|
||||
|
||||
// Get owned domains for TLD
|
||||
const domains = await getOwnedDomainsForTLD(agent, tld);
|
||||
|
||||
return {
|
||||
status: "success",
|
||||
domains,
|
||||
total: domains.length,
|
||||
message: `Successfully retrieved ${domains.length} owned domain${domains.length === 1 ? "" : "s"} for .${tld}`,
|
||||
};
|
||||
} catch (error: any) {
|
||||
return {
|
||||
status: "error",
|
||||
message: `Failed to get owned domains: ${error.message}`,
|
||||
};
|
||||
}
|
||||
},
|
||||
};
|
||||
|
||||
export default getOwnedDomainsForTLDAction;
|
||||
57
src/actions/getPrimaryDomain.ts
Normal file
57
src/actions/getPrimaryDomain.ts
Normal file
@@ -0,0 +1,57 @@
|
||||
import { Action } from "../types/action";
|
||||
import { SolanaAgentKit } from "../agent";
|
||||
import { z } from "zod";
|
||||
import { PublicKey } from "@solana/web3.js";
|
||||
import { getPrimaryDomain } from "../tools";
|
||||
|
||||
const getPrimaryDomainAction: Action = {
|
||||
name: "GET_PRIMARY_DOMAIN",
|
||||
similes: [
|
||||
"get primary domain",
|
||||
"lookup primary domain",
|
||||
"check primary domain",
|
||||
"find primary domain",
|
||||
"get main domain",
|
||||
"primary sol domain",
|
||||
],
|
||||
description:
|
||||
"Get the primary .sol domain associated with a Solana wallet address",
|
||||
examples: [
|
||||
[
|
||||
{
|
||||
input: {
|
||||
account: "7nxQB...",
|
||||
},
|
||||
output: {
|
||||
status: "success",
|
||||
domain: "vitalik.sol",
|
||||
message: "Primary domain: vitalik.sol",
|
||||
},
|
||||
explanation: "Get the primary .sol domain for a wallet address",
|
||||
},
|
||||
],
|
||||
],
|
||||
schema: z.object({
|
||||
account: z.string().min(1).describe("The Solana wallet address to lookup"),
|
||||
}),
|
||||
handler: async (agent: SolanaAgentKit, input: Record<string, any>) => {
|
||||
try {
|
||||
const account = new PublicKey(input.account);
|
||||
|
||||
const response = await getPrimaryDomain(agent, account);
|
||||
|
||||
return {
|
||||
status: "success",
|
||||
domain: response,
|
||||
message: `Primary domain: ${response}`,
|
||||
};
|
||||
} catch (error: any) {
|
||||
return {
|
||||
status: "error",
|
||||
message: `Failed to get primary domain: ${error.message}`,
|
||||
};
|
||||
}
|
||||
},
|
||||
};
|
||||
|
||||
export default getPrimaryDomainAction;
|
||||
48
src/actions/getTPS.ts
Normal file
48
src/actions/getTPS.ts
Normal file
@@ -0,0 +1,48 @@
|
||||
import { Action } from "../types/action";
|
||||
import { SolanaAgentKit } from "../agent";
|
||||
import { z } from "zod";
|
||||
import { getTPS } from "../tools";
|
||||
|
||||
const getTPSAction: Action = {
|
||||
name: "GET_TPS",
|
||||
similes: [
|
||||
"get transactions per second",
|
||||
"check network speed",
|
||||
"network performance",
|
||||
"transaction throughput",
|
||||
"network tps",
|
||||
],
|
||||
description:
|
||||
"Get the current transactions per second (TPS) of the Solana network",
|
||||
examples: [
|
||||
[
|
||||
{
|
||||
input: {},
|
||||
output: {
|
||||
status: "success",
|
||||
tps: 3500,
|
||||
message: "Current network TPS: 3500",
|
||||
},
|
||||
explanation: "Get the current TPS of the Solana network",
|
||||
},
|
||||
],
|
||||
],
|
||||
schema: z.object({}), // No input parameters required
|
||||
handler: async (agent: SolanaAgentKit, _input: Record<string, any>) => {
|
||||
try {
|
||||
const response = await getTPS(agent);
|
||||
return {
|
||||
status: "success",
|
||||
response,
|
||||
message: `Current network TPS: ${response}`,
|
||||
};
|
||||
} catch (error: any) {
|
||||
return {
|
||||
status: "error",
|
||||
message: `Failed to get TPS: ${error.message}`,
|
||||
};
|
||||
}
|
||||
},
|
||||
};
|
||||
|
||||
export default getTPSAction;
|
||||
98
src/actions/getTokenData.ts
Normal file
98
src/actions/getTokenData.ts
Normal file
@@ -0,0 +1,98 @@
|
||||
import { Action } from "../types/action";
|
||||
import { SolanaAgentKit } from "../agent";
|
||||
import { z } from "zod";
|
||||
import { PublicKey } from "@solana/web3.js";
|
||||
import { JupiterTokenData } from "../types";
|
||||
import { getTokenAddressFromTicker, getTokenDataByAddress } from "../tools";
|
||||
|
||||
const getTokenDataAction: Action = {
|
||||
name: "GET_TOKEN_DATA",
|
||||
similes: [
|
||||
"get token info",
|
||||
"token details",
|
||||
"lookup token",
|
||||
"find token",
|
||||
"token data",
|
||||
],
|
||||
description: "Get token data from either a token address or ticker symbol",
|
||||
examples: [
|
||||
[
|
||||
{
|
||||
input: {
|
||||
address: "EPjFWdd5AufqSSqeM2qN1xzybapC8G4wEGGkZwyTDt1v",
|
||||
},
|
||||
output: {
|
||||
status: "success",
|
||||
token: {
|
||||
name: "USD Coin",
|
||||
symbol: "USDC",
|
||||
address: "EPjFWdd5AufqSSqeM2qN1xzybapC8G4wEGGkZwyTDt1v",
|
||||
decimals: 6,
|
||||
},
|
||||
},
|
||||
explanation: "Get token data using the token's address",
|
||||
},
|
||||
],
|
||||
[
|
||||
{
|
||||
input: {
|
||||
ticker: "SOL",
|
||||
},
|
||||
output: {
|
||||
status: "success",
|
||||
token: {
|
||||
name: "Wrapped SOL",
|
||||
symbol: "SOL",
|
||||
address: "So11111111111111111111111111111111111111112",
|
||||
decimals: 9,
|
||||
},
|
||||
},
|
||||
explanation: "Get token data using the token's ticker symbol",
|
||||
},
|
||||
],
|
||||
],
|
||||
schema: z
|
||||
.object({
|
||||
address: z.string().optional().describe("The token's mint address"),
|
||||
ticker: z.string().optional().describe("The token's ticker symbol"),
|
||||
})
|
||||
.refine((data) => data.address || data.ticker, {
|
||||
message: "Either address or ticker must be provided",
|
||||
}),
|
||||
handler: async (agent: SolanaAgentKit, input: Record<string, any>) => {
|
||||
try {
|
||||
let tokenData: JupiterTokenData | undefined;
|
||||
if (input.address) {
|
||||
tokenData = await getTokenDataByAddress(new PublicKey(input.address));
|
||||
} else if (input.ticker) {
|
||||
const address = await getTokenAddressFromTicker(input.ticker);
|
||||
if (address) {
|
||||
tokenData = await getTokenDataByAddress(new PublicKey(address));
|
||||
}
|
||||
}
|
||||
if (!tokenData) {
|
||||
return {
|
||||
status: "error",
|
||||
message: "Token not found or not verified",
|
||||
};
|
||||
}
|
||||
return {
|
||||
status: "success",
|
||||
token: {
|
||||
name: tokenData.name,
|
||||
symbol: tokenData.symbol,
|
||||
address: tokenData.address,
|
||||
decimals: tokenData.decimals,
|
||||
logoURI: tokenData.logoURI,
|
||||
},
|
||||
};
|
||||
} catch (error: any) {
|
||||
return {
|
||||
status: "error",
|
||||
message: `Failed to get token data: ${error.message}`,
|
||||
};
|
||||
}
|
||||
},
|
||||
};
|
||||
|
||||
export default getTokenDataAction;
|
||||
61
src/actions/index.ts
Normal file
61
src/actions/index.ts
Normal file
@@ -0,0 +1,61 @@
|
||||
import deployTokenAction from "./deployToken";
|
||||
import balanceAction from "./balance";
|
||||
import transferAction from "./transfer";
|
||||
import deployCollectionAction from "./deployCollection";
|
||||
import mintNFTAction from "./mintNFT";
|
||||
import tradeAction from "./trade";
|
||||
import requestFundsAction from "./requestFunds";
|
||||
import resolveDomainAction from "./resolveDomain";
|
||||
import getTokenDataAction from "./getTokenData";
|
||||
import getTPSAction from "./getTPS";
|
||||
import fetchPriceAction from "./fetchPrice";
|
||||
import stakeWithJupAction from "./stakeWithJup";
|
||||
import registerDomainAction from "./registerDomain";
|
||||
import lendAssetAction from "./lendAsset";
|
||||
import createGibworkTaskAction from "./createGibworkTask";
|
||||
import resolveSolDomainAction from "./resolveSolDomain";
|
||||
import pythFetchPriceAction from "./pythFetchPrice";
|
||||
import getOwnedDomainsForTLDAction from "./getOwnedDomainsForTLD";
|
||||
import getPrimaryDomainAction from "./getPrimaryDomain";
|
||||
import getAllDomainsTLDsAction from "./getAllDomainsTLDs";
|
||||
import getOwnedAllDomainsAction from "./getOwnedAllDomains";
|
||||
import createImageAction from "./createImage";
|
||||
import getMainAllDomainsDomainAction from "./getMainAllDomainsDomain";
|
||||
import getAllRegisteredAllDomainsAction from "./getAllRegisteredAllDomains";
|
||||
import raydiumCreateCpmmAction from "./raydiumCreateCpmm";
|
||||
import raydiumCreateAmmV4Action from "./raydiumCreateAmmV4";
|
||||
import createOrcaSingleSidedWhirlpoolAction from "./createOrcaSingleSidedWhirlpool";
|
||||
import launchPumpfunTokenAction from "./launchPumpfunToken";
|
||||
|
||||
export const ACTIONS = {
|
||||
"DEPLOY_TOKEN_ACTION" : deployTokenAction,
|
||||
"BALANCE_ACTION" : balanceAction,
|
||||
"TRANSFER_ACTION" : transferAction,
|
||||
"DEPLOY_COLLECTION_ACTION" : deployCollectionAction,
|
||||
"MINT_NFT_ACTION" : mintNFTAction,
|
||||
"TRADE_ACTION" : tradeAction,
|
||||
"REQUEST_FUNDS_ACTION" : requestFundsAction,
|
||||
"RESOLVE_DOMAIN_ACTION" : resolveDomainAction,
|
||||
"GET_TOKEN_DATA_ACTION" : getTokenDataAction,
|
||||
"GET_TPS_ACTION" : getTPSAction,
|
||||
"FETCH_PRICE_ACTION" : fetchPriceAction,
|
||||
"STAKE_WITH_JUP_ACTION" : stakeWithJupAction,
|
||||
"REGISTER_DOMAIN_ACTION" : registerDomainAction,
|
||||
"LEND_ASSET_ACTION" : lendAssetAction,
|
||||
"CREATE_GIBWORK_TASK_ACTION" : createGibworkTaskAction,
|
||||
"RESOLVE_SOL_DOMAIN_ACTION" : resolveSolDomainAction,
|
||||
"PYTH_FETCH_PRICE_ACTION" : pythFetchPriceAction,
|
||||
"GET_OWNED_DOMAINS_FOR_TLD_ACTION" : getOwnedDomainsForTLDAction,
|
||||
"GET_PRIMARY_DOMAIN_ACTION" : getPrimaryDomainAction,
|
||||
"GET_ALL_DOMAINS_TLDS_ACTION" : getAllDomainsTLDsAction,
|
||||
"GET_OWNED_ALL_DOMAINS_ACTION" : getOwnedAllDomainsAction,
|
||||
"CREATE_IMAGE_ACTION" : createImageAction,
|
||||
"GET_MAIN_ALL_DOMAINS_DOMAIN_ACTION" : getMainAllDomainsDomainAction,
|
||||
"GET_ALL_REGISTERED_ALL_DOMAINS_ACTION" : getAllRegisteredAllDomainsAction,
|
||||
"RAYDIUM_CREATE_CPMM_ACTION" : raydiumCreateCpmmAction,
|
||||
"RAYDIUM_CREATE_AMM_V4_ACTION" : raydiumCreateAmmV4Action,
|
||||
"CREATE_ORCA_SINGLE_SIDED_WHIRLPOOL_ACTION" : createOrcaSingleSidedWhirlpoolAction,
|
||||
"LAUNCH_PUMPFUN_TOKEN_ACTION" : launchPumpfunTokenAction,
|
||||
};
|
||||
|
||||
export type { Action, ActionExample, Handler } from "../types/action";
|
||||
106
src/actions/launchPumpfunToken.ts
Normal file
106
src/actions/launchPumpfunToken.ts
Normal file
@@ -0,0 +1,106 @@
|
||||
import { Action } from "../types/action";
|
||||
import { SolanaAgentKit } from "../agent";
|
||||
import { z } from "zod";
|
||||
import { launchPumpFunToken } from "../tools";
|
||||
|
||||
const launchPumpfunTokenAction: Action = {
|
||||
name: "LAUNCH_PUMPFUN_TOKEN",
|
||||
similes: [
|
||||
"create pumpfun token",
|
||||
"launch token on pumpfun",
|
||||
"deploy pumpfun token",
|
||||
"create meme token",
|
||||
"launch memecoin",
|
||||
"create pump token",
|
||||
],
|
||||
description:
|
||||
"Launch a new token on Pump.fun with customizable metadata and initial liquidity",
|
||||
examples: [
|
||||
[
|
||||
{
|
||||
input: {
|
||||
tokenName: "Sample Token",
|
||||
tokenTicker: "SMPL",
|
||||
description: "A sample token for demonstration",
|
||||
imageUrl: "https://example.com/token.png",
|
||||
twitter: "@sampletoken",
|
||||
telegram: "t.me/sampletoken",
|
||||
website: "https://sampletoken.com",
|
||||
initialLiquiditySOL: 0.1,
|
||||
slippageBps: 10,
|
||||
priorityFee: 0.0001,
|
||||
},
|
||||
output: {
|
||||
status: "success",
|
||||
signature: "2ZE7Rz...",
|
||||
mint: "7nxQB...",
|
||||
metadataUri: "https://arweave.net/...",
|
||||
message: "Successfully launched token on Pump.fun",
|
||||
},
|
||||
explanation:
|
||||
"Launch a new token with custom metadata and 0.1 SOL initial liquidity",
|
||||
},
|
||||
],
|
||||
],
|
||||
schema: z.object({
|
||||
tokenName: z.string().min(1).max(32).describe("Name of the token"),
|
||||
tokenTicker: z
|
||||
.string()
|
||||
.min(2)
|
||||
.max(10)
|
||||
.describe("Ticker symbol of the token"),
|
||||
description: z
|
||||
.string()
|
||||
.min(1)
|
||||
.max(1000)
|
||||
.describe("Description of the token"),
|
||||
imageUrl: z.string().url().describe("URL of the token image"),
|
||||
twitter: z.string().optional().describe("Twitter handle (optional)"),
|
||||
telegram: z.string().optional().describe("Telegram group link (optional)"),
|
||||
website: z.string().url().optional().describe("Website URL (optional)"),
|
||||
initialLiquiditySOL: z
|
||||
.number()
|
||||
.min(0.0001)
|
||||
.default(0.0001)
|
||||
.describe("Initial liquidity in SOL"),
|
||||
slippageBps: z
|
||||
.number()
|
||||
.min(1)
|
||||
.max(1000)
|
||||
.default(5)
|
||||
.describe("Slippage tolerance in basis points"),
|
||||
priorityFee: z
|
||||
.number()
|
||||
.min(0.00001)
|
||||
.default(0.00005)
|
||||
.describe("Priority fee in SOL"),
|
||||
}),
|
||||
handler: async (agent: SolanaAgentKit, input: Record<string, any>) => {
|
||||
try {
|
||||
const { tokenName, tokenTicker, description, imageUrl } = input;
|
||||
const result = await launchPumpFunToken(
|
||||
agent,
|
||||
tokenName,
|
||||
tokenTicker,
|
||||
description,
|
||||
imageUrl,
|
||||
input,
|
||||
);
|
||||
|
||||
return {
|
||||
status: "success",
|
||||
signature: result.signature,
|
||||
mint: result.mint,
|
||||
metadataUri: result.metadataUri,
|
||||
message: "Successfully launched token on Pump.fun",
|
||||
};
|
||||
} catch (error: any) {
|
||||
return {
|
||||
status: "error",
|
||||
message: `Failed to launch token: ${error.message}`,
|
||||
};
|
||||
}
|
||||
},
|
||||
};
|
||||
|
||||
export default launchPumpfunTokenAction;
|
||||
55
src/actions/lendAsset.ts
Normal file
55
src/actions/lendAsset.ts
Normal file
@@ -0,0 +1,55 @@
|
||||
import { Action } from "../types/action";
|
||||
import { SolanaAgentKit } from "../agent";
|
||||
import { z } from "zod";
|
||||
import { lendAsset } from "../tools";
|
||||
|
||||
const lendAssetAction: Action = {
|
||||
name: "LEND_ASSET",
|
||||
similes: [
|
||||
"lend usdc",
|
||||
"deposit for yield",
|
||||
"earn yield",
|
||||
"lend with lulo",
|
||||
"deposit usdc",
|
||||
"lending",
|
||||
],
|
||||
description: "Lend USDC tokens to earn yield using Lulo protocol",
|
||||
examples: [
|
||||
[
|
||||
{
|
||||
input: {
|
||||
amount: 100,
|
||||
},
|
||||
output: {
|
||||
status: "success",
|
||||
signature: "4xKpN2...",
|
||||
message: "Successfully lent 100 USDC",
|
||||
},
|
||||
explanation: "Lend 100 USDC to earn yield on Lulo",
|
||||
},
|
||||
],
|
||||
],
|
||||
schema: z.object({
|
||||
amount: z.number().positive().describe("Amount of USDC to lend"),
|
||||
}),
|
||||
handler: async (agent: SolanaAgentKit, input: Record<string, any>) => {
|
||||
try {
|
||||
const amount = input.amount as number;
|
||||
|
||||
const response = await lendAsset(agent, amount);
|
||||
|
||||
return {
|
||||
status: "success",
|
||||
signature: response,
|
||||
message: `Successfully lent ${amount} USDC`,
|
||||
};
|
||||
} catch (error: any) {
|
||||
return {
|
||||
status: "error",
|
||||
message: `Lending failed: ${error.message}`,
|
||||
};
|
||||
}
|
||||
},
|
||||
};
|
||||
|
||||
export default lendAssetAction;
|
||||
90
src/actions/mintNFT.ts
Normal file
90
src/actions/mintNFT.ts
Normal file
@@ -0,0 +1,90 @@
|
||||
import { PublicKey } from "@solana/web3.js";
|
||||
import { Action } from "../types/action";
|
||||
import { SolanaAgentKit } from "../agent";
|
||||
import { z } from "zod";
|
||||
import { mintCollectionNFT } from "../tools";
|
||||
|
||||
const mintNFTAction: Action = {
|
||||
name: "MINT_NFT",
|
||||
similes: [
|
||||
"mint nft",
|
||||
"create nft",
|
||||
"mint token",
|
||||
"create token",
|
||||
"add nft to collection",
|
||||
],
|
||||
description: `Mint a new NFT in a collection on Solana blockchain.`,
|
||||
examples: [
|
||||
[
|
||||
{
|
||||
input: {
|
||||
collectionMint: "J1S9H3QjnRtBbbuD4HjPV6RpRhwuk4zKbxsnCHuTgh9w",
|
||||
name: "My NFT",
|
||||
uri: "https://example.com/nft.json",
|
||||
},
|
||||
output: {
|
||||
status: "success",
|
||||
message: "NFT minted successfully",
|
||||
mintAddress: "7nE9GvcwsqzYxmJLSrYmSB1V1YoJWVK1KWzAcWAzjXkN",
|
||||
metadata: {
|
||||
name: "My NFT",
|
||||
uri: "https://example.com/nft.json",
|
||||
},
|
||||
recipient: "7nE9GvcwsqzYxmJLSrYmSB1V1YoJWVK1KWzAcWAzjXkN",
|
||||
},
|
||||
explanation: "Mint an NFT to the default wallet",
|
||||
},
|
||||
],
|
||||
[
|
||||
{
|
||||
input: {
|
||||
collectionMint: "J1S9H3QjnRtBbbuD4HjPV6RpRhwuk4zKbxsnCHuTgh9w",
|
||||
name: "Gift NFT",
|
||||
uri: "https://example.com/gift.json",
|
||||
recipient: "9aUn5swQzUTRanaaTwmszxiv89cvFwUCjEBv1vZCoT1u",
|
||||
},
|
||||
output: {
|
||||
status: "success",
|
||||
message: "NFT minted successfully",
|
||||
mintAddress: "8nE9GvcwsqzYxmJLSrYmSB1V1YoJWVK1KWzAcWAzjXkM",
|
||||
metadata: {
|
||||
name: "Gift NFT",
|
||||
uri: "https://example.com/gift.json",
|
||||
},
|
||||
recipient: "9aUn5swQzUTRanaaTwmszxiv89cvFwUCjEBv1vZCoT1u",
|
||||
},
|
||||
explanation: "Mint an NFT to a specific recipient",
|
||||
},
|
||||
],
|
||||
],
|
||||
schema: z.object({
|
||||
collectionMint: z.string().min(32, "Invalid collection mint address"),
|
||||
name: z.string().min(1, "Name is required"),
|
||||
uri: z.string().url("URI must be a valid URL"),
|
||||
recipient: z.string().min(32, "Invalid recipient address"),
|
||||
}),
|
||||
handler: async (agent: SolanaAgentKit, input: Record<string, any>) => {
|
||||
const result = await mintCollectionNFT(
|
||||
agent,
|
||||
new PublicKey(input.collectionMint),
|
||||
{
|
||||
name: input.name,
|
||||
uri: input.uri,
|
||||
},
|
||||
input.recipient ? new PublicKey(input.recipient) : undefined,
|
||||
);
|
||||
|
||||
return {
|
||||
status: "success",
|
||||
message: "NFT minted successfully",
|
||||
mintAddress: result.mint.toString(),
|
||||
metadata: {
|
||||
name: input.name,
|
||||
uri: input.uri,
|
||||
},
|
||||
recipient: input.recipient || result.mint.toString(),
|
||||
};
|
||||
},
|
||||
};
|
||||
|
||||
export default mintNFTAction;
|
||||
56
src/actions/pythFetchPrice.ts
Normal file
56
src/actions/pythFetchPrice.ts
Normal file
@@ -0,0 +1,56 @@
|
||||
import { Action } from "../types/action";
|
||||
import { SolanaAgentKit } from "../agent";
|
||||
import { z } from "zod";
|
||||
import { pythFetchPrice } from "../tools";
|
||||
|
||||
const pythFetchPriceAction: Action = {
|
||||
name: "PYTH_FETCH_PRICE",
|
||||
similes: [
|
||||
"get pyth price",
|
||||
"check pyth price",
|
||||
"pyth oracle price",
|
||||
"fetch from pyth",
|
||||
"pyth price feed",
|
||||
"oracle price",
|
||||
],
|
||||
description: "Fetch the current price from a Pyth oracle price feed",
|
||||
examples: [
|
||||
[
|
||||
{
|
||||
input: {
|
||||
priceFeedId: "Gnt27xtC473ZT2Mw5u8wZ68Z3gULkSTb5DuxJy7eJotD", // SOL/USD price feed
|
||||
},
|
||||
output: {
|
||||
status: "success",
|
||||
price: "23.45",
|
||||
message: "Current price: $23.45",
|
||||
},
|
||||
explanation: "Get the current SOL/USD price from Pyth oracle",
|
||||
},
|
||||
],
|
||||
],
|
||||
schema: z.object({
|
||||
priceFeedId: z
|
||||
.string()
|
||||
.min(1)
|
||||
.describe("The Pyth price feed ID to fetch the price from"),
|
||||
}),
|
||||
handler: async (_agent: SolanaAgentKit, input: Record<string, any>) => {
|
||||
try {
|
||||
const priceFeedId = input.tokenId as string;
|
||||
const priceStr = await pythFetchPrice(priceFeedId);
|
||||
return {
|
||||
status: "success",
|
||||
price: priceStr,
|
||||
message: `Current price: $${priceStr}`,
|
||||
};
|
||||
} catch (error: any) {
|
||||
return {
|
||||
status: "error",
|
||||
message: `Failed to fetch price from Pyth: ${error.message}`,
|
||||
};
|
||||
}
|
||||
},
|
||||
};
|
||||
|
||||
export default pythFetchPriceAction;
|
||||
91
src/actions/raydiumCreateAmmV4.ts
Normal file
91
src/actions/raydiumCreateAmmV4.ts
Normal file
@@ -0,0 +1,91 @@
|
||||
import { Action } from "../types/action";
|
||||
import { SolanaAgentKit } from "../agent";
|
||||
import { z } from "zod";
|
||||
import { PublicKey } from "@solana/web3.js";
|
||||
import BN from "bn.js";
|
||||
import { raydiumCreateAmmV4 } from "../tools";
|
||||
|
||||
const raydiumCreateAmmV4Action: Action = {
|
||||
name: "RAYDIUM_CREATE_AMM_V4",
|
||||
similes: [
|
||||
"create raydium v4 pool",
|
||||
"setup raydium v4 liquidity pool",
|
||||
"initialize raydium v4 amm",
|
||||
"create raydium v4 market maker",
|
||||
"setup raydium v4 pool",
|
||||
"create raydium v4 trading pair",
|
||||
],
|
||||
description:
|
||||
"Create a new AMM V4 pool on Raydium with advanced features and improved efficiency",
|
||||
examples: [
|
||||
[
|
||||
{
|
||||
input: {
|
||||
baseMint: "EPjFWdd5AufqSSqeM2qN1xzybapC8G4wEGGkZwyTDt1v", // USDC
|
||||
quoteMint: "So11111111111111111111111111111111111111112", // SOL
|
||||
baseAmount: 1000,
|
||||
quoteAmount: 10,
|
||||
startPrice: 100, // 1 SOL = 100 USDC
|
||||
openTime: 1672531200, // Unix timestamp
|
||||
},
|
||||
output: {
|
||||
status: "success",
|
||||
signature: "2ZE7Rz...",
|
||||
poolId: "7nxQB...",
|
||||
message: "Successfully created Raydium AMM V4 pool",
|
||||
},
|
||||
explanation:
|
||||
"Create a USDC-SOL V4 pool with initial liquidity and price",
|
||||
},
|
||||
],
|
||||
],
|
||||
schema: z.object({
|
||||
baseMint: z.string().min(1).describe("The base token mint address"),
|
||||
quoteMint: z.string().min(1).describe("The quote token mint address"),
|
||||
baseAmount: z
|
||||
.number()
|
||||
.positive()
|
||||
.describe("Initial base token amount to provide as liquidity"),
|
||||
quoteAmount: z
|
||||
.number()
|
||||
.positive()
|
||||
.describe("Initial quote token amount to provide as liquidity"),
|
||||
startPrice: z
|
||||
.number()
|
||||
.positive()
|
||||
.describe("Initial price of quote token in base token units"),
|
||||
openTime: z
|
||||
.number()
|
||||
.positive()
|
||||
.describe("Unix timestamp when trading should start"),
|
||||
}),
|
||||
handler: async (agent: SolanaAgentKit, input: Record<string, any>) => {
|
||||
try {
|
||||
const marketId = new PublicKey(input.marketId);
|
||||
const baseAmount = new BN(input.baseAmount);
|
||||
const quoteAmount = new BN(input.quoteAmount);
|
||||
const startTime = new BN(input.startTime);
|
||||
|
||||
const txId = await raydiumCreateAmmV4(
|
||||
agent,
|
||||
marketId,
|
||||
baseAmount,
|
||||
quoteAmount,
|
||||
startTime,
|
||||
);
|
||||
|
||||
return {
|
||||
status: "success",
|
||||
signature: txId,
|
||||
message: "Successfully created Raydium AMM V4 pool",
|
||||
};
|
||||
} catch (error: any) {
|
||||
return {
|
||||
status: "error",
|
||||
message: `Failed to create AMM V4 pool: ${error.message}`,
|
||||
};
|
||||
}
|
||||
},
|
||||
};
|
||||
|
||||
export default raydiumCreateAmmV4Action;
|
||||
76
src/actions/raydiumCreateClmm.ts
Normal file
76
src/actions/raydiumCreateClmm.ts
Normal file
@@ -0,0 +1,76 @@
|
||||
import { Action } from "../types/action";
|
||||
import { SolanaAgentKit } from "../agent";
|
||||
import { z } from "zod";
|
||||
import { PublicKey } from "@solana/web3.js";
|
||||
import { BN } from "@coral-xyz/anchor";
|
||||
import Decimal from "decimal.js";
|
||||
import { raydiumCreateClmm } from "../tools";
|
||||
|
||||
const raydiumCreateClmmAction: Action = {
|
||||
name: "RAYDIUM_CREATE_CLMM",
|
||||
similes: [
|
||||
"create clmm pool",
|
||||
"create concentrated liquidity pool",
|
||||
"raydium clmm setup",
|
||||
"launch concentrated liquidity market maker",
|
||||
],
|
||||
description: `Create a Raydium Concentrated Liquidity Market Maker (CLMM) pool with custom ranges, providing increased capital efficiency`,
|
||||
examples: [
|
||||
[
|
||||
{
|
||||
input: {
|
||||
mint1: "9xU1vzz456... (PublicKey)",
|
||||
mint2: "EfrsBcG98... (PublicKey)",
|
||||
configId: "D6yTTr... (Config PublicKey)",
|
||||
initialPrice: 123.12,
|
||||
startTime: 0, // or current UNIX timestamp
|
||||
},
|
||||
output: {
|
||||
status: "success",
|
||||
message: "Create raydium clmm pool successfully",
|
||||
transaction: "3skCN8... (transaction signature)",
|
||||
},
|
||||
explanation:
|
||||
"Creates a CLMM pool between mint1 and mint2 at an initial price of 123.12 and start time of 0.",
|
||||
},
|
||||
],
|
||||
],
|
||||
// Validate tool inputs using zod
|
||||
schema: z.object({
|
||||
mint1: z.string().min(1).describe("First token mint address (public key)"),
|
||||
mint2: z.string().min(1).describe("Second token mint address (public key)"),
|
||||
configId: z.string().min(1).describe("Raydium configId (public key)"),
|
||||
initialPrice: z.number().describe("Initial price for the CLMM pool"),
|
||||
startTime: z
|
||||
.number()
|
||||
.describe("Start time in seconds (UNIX timestamp or zero)"),
|
||||
}),
|
||||
handler: async (agent: SolanaAgentKit, input: Record<string, any>) => {
|
||||
try {
|
||||
const { mint1, mint2, configId, initialPrice, startTime } = input;
|
||||
|
||||
const tx = await raydiumCreateClmm(
|
||||
agent,
|
||||
new PublicKey(mint1),
|
||||
new PublicKey(mint2),
|
||||
new PublicKey(configId),
|
||||
new Decimal(initialPrice),
|
||||
new BN(startTime),
|
||||
);
|
||||
|
||||
return {
|
||||
status: "success",
|
||||
message: "Create raydium clmm pool successfully",
|
||||
transaction: tx,
|
||||
};
|
||||
} catch (error: any) {
|
||||
return {
|
||||
status: "error",
|
||||
message: `Failed to create CLMM pool: ${error.message}`,
|
||||
code: error.code || "UNKNOWN_ERROR",
|
||||
};
|
||||
}
|
||||
},
|
||||
};
|
||||
|
||||
export default raydiumCreateClmmAction;
|
||||
90
src/actions/raydiumCreateCpmm.ts
Normal file
90
src/actions/raydiumCreateCpmm.ts
Normal file
@@ -0,0 +1,90 @@
|
||||
import { Action } from "../types/action";
|
||||
import { SolanaAgentKit } from "../agent";
|
||||
import { z } from "zod";
|
||||
import { PublicKey } from "@solana/web3.js";
|
||||
import BN from "bn.js";
|
||||
import { raydiumCreateCpmm } from "../tools";
|
||||
|
||||
const raydiumCreateCpmmAction: Action = {
|
||||
name: "RAYDIUM_CREATE_CPMM",
|
||||
similes: [
|
||||
"create raydium pool",
|
||||
"setup raydium liquidity pool",
|
||||
"initialize raydium amm",
|
||||
"create constant product market maker",
|
||||
"setup raydium cpmm",
|
||||
"create raydium trading pair",
|
||||
],
|
||||
description:
|
||||
"Create a new Constant Product Market Maker (CPMM) pool on Raydium",
|
||||
examples: [
|
||||
[
|
||||
{
|
||||
input: {
|
||||
baseMint: "EPjFWdd5AufqSSqeM2qN1xzybapC8G4wEGGkZwyTDt1v", // USDC
|
||||
quoteMint: "So11111111111111111111111111111111111111112", // SOL
|
||||
baseAmount: 1000,
|
||||
quoteAmount: 10,
|
||||
startTime: 1672531200, // Unix timestamp
|
||||
},
|
||||
output: {
|
||||
status: "success",
|
||||
signature: "2ZE7Rz...",
|
||||
poolId: "7nxQB...",
|
||||
message: "Successfully created Raydium CPMM pool",
|
||||
},
|
||||
explanation:
|
||||
"Create a USDC-SOL pool with initial liquidity of 1000 USDC and 10 SOL",
|
||||
},
|
||||
],
|
||||
],
|
||||
schema: z.object({
|
||||
baseMint: z.string().min(1).describe("The base token mint address"),
|
||||
quoteMint: z.string().min(1).describe("The quote token mint address"),
|
||||
baseAmount: z
|
||||
.number()
|
||||
.positive()
|
||||
.describe("Initial base token amount to provide as liquidity"),
|
||||
quoteAmount: z
|
||||
.number()
|
||||
.positive()
|
||||
.describe("Initial quote token amount to provide as liquidity"),
|
||||
startTime: z
|
||||
.number()
|
||||
.positive()
|
||||
.describe("Unix timestamp when trading should start"),
|
||||
}),
|
||||
handler: async (agent: SolanaAgentKit, input: Record<string, any>) => {
|
||||
try {
|
||||
const mintA = new PublicKey(input.baseMint);
|
||||
const mintB = new PublicKey(input.quoteMint);
|
||||
const configId = new PublicKey(input.configId);
|
||||
const mintAAmount = new BN(input.baseAmount);
|
||||
const mintBAmount = new BN(input.quoteAmount);
|
||||
const startTime = new BN(input.startTime);
|
||||
|
||||
const txId = await raydiumCreateCpmm(
|
||||
agent,
|
||||
mintA,
|
||||
mintB,
|
||||
configId,
|
||||
mintAAmount,
|
||||
mintBAmount,
|
||||
startTime,
|
||||
);
|
||||
|
||||
return {
|
||||
status: "success",
|
||||
signature: txId,
|
||||
message: "Successfully created Raydium CPMM pool",
|
||||
};
|
||||
} catch (error: any) {
|
||||
return {
|
||||
status: "error",
|
||||
message: `Failed to create CPMM pool: ${error.message}`,
|
||||
};
|
||||
}
|
||||
},
|
||||
};
|
||||
|
||||
export default raydiumCreateCpmmAction;
|
||||
63
src/actions/registerDomain.ts
Normal file
63
src/actions/registerDomain.ts
Normal file
@@ -0,0 +1,63 @@
|
||||
import { Action } from "../types/action";
|
||||
import { SolanaAgentKit } from "../agent";
|
||||
import { z } from "zod";
|
||||
import { registerDomain } from "../tools";
|
||||
|
||||
const registerDomainAction: Action = {
|
||||
name: "REGISTER_DOMAIN",
|
||||
similes: [
|
||||
"register domain",
|
||||
"buy domain",
|
||||
"get domain name",
|
||||
"register .sol",
|
||||
"purchase domain",
|
||||
"domain registration",
|
||||
],
|
||||
description: "Register a .sol domain name using Bonfida Name Service",
|
||||
examples: [
|
||||
[
|
||||
{
|
||||
input: {
|
||||
name: "mydomain",
|
||||
spaceKB: 1,
|
||||
},
|
||||
output: {
|
||||
status: "success",
|
||||
signature: "2ZE7Rz...",
|
||||
message: "Successfully registered mydomain.sol",
|
||||
},
|
||||
explanation: "Register a new .sol domain with 1KB storage space",
|
||||
},
|
||||
],
|
||||
],
|
||||
schema: z.object({
|
||||
name: z.string().min(1).describe("Domain name to register (without .sol)"),
|
||||
spaceKB: z
|
||||
.number()
|
||||
.min(1)
|
||||
.max(10)
|
||||
.default(1)
|
||||
.describe("Space allocation in KB (max 10KB)"),
|
||||
}),
|
||||
handler: async (agent: SolanaAgentKit, input: Record<string, any>) => {
|
||||
try {
|
||||
const name = input.name as string;
|
||||
const spaceKB = (input.spaceKB as number) || 1;
|
||||
|
||||
const signature = await registerDomain(agent, name, spaceKB);
|
||||
|
||||
return {
|
||||
status: "success",
|
||||
signature,
|
||||
message: `Successfully registered ${name}.sol`,
|
||||
};
|
||||
} catch (error: any) {
|
||||
return {
|
||||
status: "error",
|
||||
message: `Domain registration failed: ${error.message}`,
|
||||
};
|
||||
}
|
||||
},
|
||||
};
|
||||
|
||||
export default registerDomainAction;
|
||||
41
src/actions/requestFunds.ts
Normal file
41
src/actions/requestFunds.ts
Normal file
@@ -0,0 +1,41 @@
|
||||
import { Action } from "../types/action";
|
||||
import { SolanaAgentKit } from "../agent";
|
||||
import { z } from "zod";
|
||||
import { request_faucet_funds } from "../tools";
|
||||
|
||||
const requestFundsAction: Action = {
|
||||
name: "REQUEST_FUNDS",
|
||||
similes: [
|
||||
"request sol",
|
||||
"get test sol",
|
||||
"use faucet",
|
||||
"request test tokens",
|
||||
"get devnet sol",
|
||||
],
|
||||
description: "Request SOL from Solana faucet (devnet/testnet only)",
|
||||
examples: [
|
||||
[
|
||||
{
|
||||
input: {},
|
||||
output: {
|
||||
status: "success",
|
||||
message: "Successfully requested faucet funds",
|
||||
network: "devnet.solana.com",
|
||||
},
|
||||
explanation: "Request SOL from the devnet faucet",
|
||||
},
|
||||
],
|
||||
],
|
||||
schema: z.object({}), // No input parameters required
|
||||
handler: async (agent: SolanaAgentKit, _input: Record<string, any>) => {
|
||||
await request_faucet_funds(agent);
|
||||
|
||||
return {
|
||||
status: "success",
|
||||
message: "Successfully requested faucet funds",
|
||||
network: agent.connection.rpcEndpoint.split("/")[2],
|
||||
};
|
||||
},
|
||||
};
|
||||
|
||||
export default requestFundsAction;
|
||||
51
src/actions/resolveDomain.ts
Normal file
51
src/actions/resolveDomain.ts
Normal file
@@ -0,0 +1,51 @@
|
||||
import { Action } from "../types/action";
|
||||
import { SolanaAgentKit } from "../agent";
|
||||
import { z } from "zod";
|
||||
import { resolveAllDomains } from "../tools";
|
||||
|
||||
const resolveDomainAction: Action = {
|
||||
name: "RESOLVE_ALL_DOMAINS",
|
||||
similes: [
|
||||
"resolve domain",
|
||||
"lookup domain",
|
||||
"get domain owner",
|
||||
"check domain",
|
||||
"find domain owner",
|
||||
],
|
||||
description: "Resolve a Solana domain name to get its owner's public key",
|
||||
examples: [
|
||||
[
|
||||
{
|
||||
input: {
|
||||
domain: "example.sol",
|
||||
},
|
||||
output: {
|
||||
status: "success",
|
||||
owner: "7nxQB...",
|
||||
},
|
||||
explanation: "Resolve a .sol domain name to get the owner's public key",
|
||||
},
|
||||
],
|
||||
],
|
||||
schema: z.object({
|
||||
domain: z.string().min(1).describe("The domain name to resolve"),
|
||||
}),
|
||||
handler: async (agent: SolanaAgentKit, input: Record<string, any>) => {
|
||||
try {
|
||||
const domain = input.domain as string;
|
||||
const tld = await resolveAllDomains(agent, domain);
|
||||
return {
|
||||
status: "success",
|
||||
owner: tld,
|
||||
message: `Successfully resolved domain ${domain}`,
|
||||
};
|
||||
} catch (error: any) {
|
||||
return {
|
||||
status: "error",
|
||||
message: `Failed to resolve domain: ${error.message}`,
|
||||
};
|
||||
}
|
||||
},
|
||||
};
|
||||
|
||||
export default resolveDomainAction;
|
||||
59
src/actions/resolveSolDomain.ts
Normal file
59
src/actions/resolveSolDomain.ts
Normal file
@@ -0,0 +1,59 @@
|
||||
import { Action } from "../types/action";
|
||||
import { SolanaAgentKit } from "../agent";
|
||||
import { z } from "zod";
|
||||
import { resolveSolDomain } from "../tools";
|
||||
|
||||
const resolveSolDomainAction: Action = {
|
||||
name: "RESOLVE_SOL_DOMAIN",
|
||||
similes: [
|
||||
"resolve sol domain",
|
||||
"lookup sol domain",
|
||||
"get sol domain owner",
|
||||
"check sol domain",
|
||||
"find sol domain owner",
|
||||
"resolve .sol",
|
||||
],
|
||||
description:
|
||||
"Resolve a .sol domain to its corresponding Solana wallet address using Bonfida Name Service",
|
||||
examples: [
|
||||
[
|
||||
{
|
||||
input: {
|
||||
domain: "vitalik.sol",
|
||||
},
|
||||
output: {
|
||||
status: "success",
|
||||
owner: "7nxQB...",
|
||||
message: "Successfully resolved vitalik.sol",
|
||||
},
|
||||
explanation: "Resolve a .sol domain to get the owner's wallet address",
|
||||
},
|
||||
],
|
||||
],
|
||||
schema: z.object({
|
||||
domain: z
|
||||
.string()
|
||||
.min(1)
|
||||
.describe("The .sol domain to resolve (with or without .sol suffix)"),
|
||||
}),
|
||||
handler: async (agent: SolanaAgentKit, input: Record<string, any>) => {
|
||||
try {
|
||||
const domain = input.domain as string;
|
||||
|
||||
const res = await resolveSolDomain(agent, domain);
|
||||
|
||||
return {
|
||||
status: "success",
|
||||
owner: res.toString(),
|
||||
message: `Successfully resolved ${res}`,
|
||||
};
|
||||
} catch (error: any) {
|
||||
return {
|
||||
status: "error",
|
||||
message: `Failed to resolve domain: ${error.message}`,
|
||||
};
|
||||
}
|
||||
},
|
||||
};
|
||||
|
||||
export default resolveSolDomainAction;
|
||||
55
src/actions/stakeWithJup.ts
Normal file
55
src/actions/stakeWithJup.ts
Normal file
@@ -0,0 +1,55 @@
|
||||
import { Action } from "../types/action";
|
||||
import { SolanaAgentKit } from "../agent";
|
||||
import { z } from "zod";
|
||||
import { stakeWithJup } from "../tools";
|
||||
|
||||
const stakeWithJupAction: Action = {
|
||||
name: "STAKE_WITH_JUPITER",
|
||||
similes: [
|
||||
"stake sol",
|
||||
"stake with jupiter",
|
||||
"jup staking",
|
||||
"stake with jup",
|
||||
"liquid staking",
|
||||
"get jupsol",
|
||||
],
|
||||
description:
|
||||
"Stake SOL tokens with Jupiter's liquid staking protocol to receive jupSOL",
|
||||
examples: [
|
||||
[
|
||||
{
|
||||
input: {
|
||||
amount: 1.5,
|
||||
},
|
||||
output: {
|
||||
status: "success",
|
||||
signature: "5KtPn3...",
|
||||
message: "Successfully staked 1.5 SOL for jupSOL",
|
||||
},
|
||||
explanation: "Stake 1.5 SOL to receive jupSOL tokens",
|
||||
},
|
||||
],
|
||||
],
|
||||
schema: z.object({
|
||||
amount: z.number().positive().describe("Amount of SOL to stake"),
|
||||
}),
|
||||
handler: async (agent: SolanaAgentKit, input: Record<string, any>) => {
|
||||
try {
|
||||
const amount = input.amount as number;
|
||||
|
||||
const res = await stakeWithJup(agent, amount);
|
||||
return {
|
||||
status: "success",
|
||||
res,
|
||||
message: `Successfully staked ${amount} SOL for jupSOL`,
|
||||
};
|
||||
} catch (error: any) {
|
||||
return {
|
||||
status: "error",
|
||||
message: `jupSOL staking failed: ${error.message}`,
|
||||
};
|
||||
}
|
||||
},
|
||||
};
|
||||
|
||||
export default stakeWithJupAction;
|
||||
60
src/actions/tokenDataByTicker.ts
Normal file
60
src/actions/tokenDataByTicker.ts
Normal file
@@ -0,0 +1,60 @@
|
||||
import { Action } from "../types/action";
|
||||
import { SolanaAgentKit } from "../agent";
|
||||
import { z } from "zod";
|
||||
import { getTokenDataByTicker } from "../tools";
|
||||
|
||||
const tokenDataByTickerAction: Action = {
|
||||
name: "GET_TOKEN_DATA_BY_TICKER",
|
||||
similes: [
|
||||
"token data by ticker",
|
||||
"fetch token info by ticker",
|
||||
"lookup token ticker info",
|
||||
"get token info by ticker",
|
||||
],
|
||||
description: "Get the token data for a given token ticker",
|
||||
examples: [
|
||||
[
|
||||
{
|
||||
input: {
|
||||
ticker: "USDC",
|
||||
},
|
||||
output: {
|
||||
status: "success",
|
||||
tokenData: {
|
||||
// Some placeholder example data
|
||||
symbol: "USDC",
|
||||
name: "USD Coin",
|
||||
decimals: 6,
|
||||
mintAddress: "FhRg...",
|
||||
},
|
||||
},
|
||||
explanation: "Fetches metadata for the USDC token by its ticker.",
|
||||
},
|
||||
],
|
||||
],
|
||||
schema: z.object({
|
||||
ticker: z.string().min(1).describe("Ticker of the token, e.g. 'USDC'"),
|
||||
}),
|
||||
handler: async (agent: SolanaAgentKit, input: Record<string, any>) => {
|
||||
try {
|
||||
const ticker = input.ticker as string;
|
||||
|
||||
// Use agent’s method to get token data by ticker
|
||||
const tokenData = await getTokenDataByTicker(ticker);
|
||||
|
||||
return {
|
||||
status: "success",
|
||||
tokenData: tokenData,
|
||||
message: `Successfully fetched token data for ticker: ${ticker}`,
|
||||
};
|
||||
} catch (error: any) {
|
||||
return {
|
||||
status: "error",
|
||||
message: `Failed to fetch token data for ticker: ${input.ticker || ""}. ${error.message}`,
|
||||
code: error.code || "UNKNOWN_ERROR",
|
||||
};
|
||||
}
|
||||
},
|
||||
};
|
||||
|
||||
export default tokenDataByTickerAction;
|
||||
85
src/actions/trade.ts
Normal file
85
src/actions/trade.ts
Normal file
@@ -0,0 +1,85 @@
|
||||
import { PublicKey } from "@solana/web3.js";
|
||||
import { Action } from "../types/action";
|
||||
import { SolanaAgentKit } from "../agent";
|
||||
import { z } from "zod";
|
||||
import { trade } from "../tools";
|
||||
|
||||
const tradeAction: Action = {
|
||||
name: "TRADE",
|
||||
similes: [
|
||||
"swap tokens",
|
||||
"exchange tokens",
|
||||
"trade tokens",
|
||||
"convert tokens",
|
||||
"swap sol",
|
||||
],
|
||||
description: `This tool can be used to swap tokens to another token (It uses Jupiter Exchange).`,
|
||||
examples: [
|
||||
[
|
||||
{
|
||||
input: {
|
||||
outputMint: "EPjFWdd5AufqSSqeM2qN1xzybapC8G4wEGGkZwyTDt1v",
|
||||
inputAmount: 1,
|
||||
},
|
||||
output: {
|
||||
status: "success",
|
||||
message: "Trade executed successfully",
|
||||
transaction:
|
||||
"5UfgJ5vVZxUxefDGqzqkVLHzHxVTyYH9StYyHKgvHYmXJgqJKxEqy9k4Rz9LpXrHF9kUZB7",
|
||||
inputAmount: 1,
|
||||
inputToken: "SOL",
|
||||
outputToken: "EPjFWdd5AufqSSqeM2qN1xzybapC8G4wEGGkZwyTDt1v",
|
||||
},
|
||||
explanation: "Swap 1 SOL for USDC",
|
||||
},
|
||||
],
|
||||
[
|
||||
{
|
||||
input: {
|
||||
outputMint: "So11111111111111111111111111111111111111112",
|
||||
inputAmount: 100,
|
||||
inputMint: "EPjFWdd5AufqSSqeM2qN1xzybapC8G4wEGGkZwyTDt1v",
|
||||
slippageBps: 100,
|
||||
},
|
||||
output: {
|
||||
status: "success",
|
||||
message: "Trade executed successfully",
|
||||
transaction:
|
||||
"4VfgJ5vVZxUxefDGqzqkVLHzHxVTyYH9StYyHKgvHYmXJgqJKxEqy9k4Rz9LpXrHF9kUZB7",
|
||||
inputAmount: 100,
|
||||
inputToken: "EPjFWdd5AufqSSqeM2qN1xzybapC8G4wEGGkZwyTDt1v",
|
||||
outputToken: "So11111111111111111111111111111111111111112",
|
||||
},
|
||||
explanation: "Swap 100 USDC for SOL with 1% slippage",
|
||||
},
|
||||
],
|
||||
],
|
||||
schema: z.object({
|
||||
outputMint: z.string().min(32, "Invalid output mint address"),
|
||||
inputAmount: z.number().positive("Input amount must be positive"),
|
||||
inputMint: z.string().min(32, "Invalid input mint address").optional(),
|
||||
slippageBps: z.number().min(0).max(10000).optional(),
|
||||
}),
|
||||
handler: async (agent: SolanaAgentKit, input: Record<string, any>) => {
|
||||
const tx = await trade(
|
||||
agent,
|
||||
new PublicKey(input.outputMint),
|
||||
input.inputAmount,
|
||||
input.inputMint
|
||||
? new PublicKey(input.inputMint)
|
||||
: new PublicKey("So11111111111111111111111111111111111111112"),
|
||||
input.slippageBps,
|
||||
);
|
||||
|
||||
return {
|
||||
status: "success",
|
||||
message: "Trade executed successfully",
|
||||
transaction: tx,
|
||||
inputAmount: input.inputAmount,
|
||||
inputToken: input.inputMint || "SOL",
|
||||
outputToken: input.outputMint,
|
||||
};
|
||||
},
|
||||
};
|
||||
|
||||
export default tradeAction;
|
||||
78
src/actions/transfer.ts
Normal file
78
src/actions/transfer.ts
Normal file
@@ -0,0 +1,78 @@
|
||||
import { PublicKey } from "@solana/web3.js";
|
||||
import { Action } from "../types/action";
|
||||
import { SolanaAgentKit } from "../agent";
|
||||
import { z } from "zod";
|
||||
import { transfer } from "../tools";
|
||||
|
||||
const transferAction: Action = {
|
||||
name: "TRANSFER",
|
||||
similes: [
|
||||
"send tokens",
|
||||
"transfer funds",
|
||||
"send money",
|
||||
"send sol",
|
||||
"transfer tokens",
|
||||
],
|
||||
description: `Transfer tokens or SOL to another address (also called as wallet address).`,
|
||||
examples: [
|
||||
[
|
||||
{
|
||||
input: {
|
||||
to: "8x2dR8Mpzuz2YqyZyZjUbYWKSWesBo5jMx2Q9Y86udVk",
|
||||
amount: 1,
|
||||
},
|
||||
output: {
|
||||
status: "success",
|
||||
message: "Transfer completed successfully",
|
||||
amount: 1,
|
||||
recipient: "8x2dR8Mpzuz2YqyZyZjUbYWKSWesBo5jMx2Q9Y86udVk",
|
||||
token: "SOL",
|
||||
transaction:
|
||||
"5UfgJ5vVZxUxefDGqzqkVLHzHxVTyYH9StYyHKgvHYmXJgqJKxEqy9k4Rz9LpXrHF9kUZB7",
|
||||
},
|
||||
explanation: "Transfer 1 SOL to the recipient address",
|
||||
},
|
||||
],
|
||||
[
|
||||
{
|
||||
input: {
|
||||
to: "8x2dR8Mpzuz2YqyZyZjUbYWKSWesBo5jMx2Q9Y86udVk",
|
||||
amount: 100,
|
||||
mint: "EPjFWdd5AufqSSqeM2qN1xzybapC8G4wEGGkZwyTDt1v",
|
||||
},
|
||||
output: {
|
||||
status: "success",
|
||||
message: "Transfer completed successfully",
|
||||
amount: 100,
|
||||
recipient: "8x2dR8Mpzuz2YqyZyZjUbYWKSWesBo5jMx2Q9Y86udVk",
|
||||
token: "EPjFWdd5AufqSSqeM2qN1xzybapC8G4wEGGkZwyTDt1v",
|
||||
transaction:
|
||||
"4VfgJ5vVZxUxefDGqzqkVLHzHxVTyYH9StYyHKgvHYmXJgqJKxEqy9k4Rz9LpXrHF9kUZB7",
|
||||
},
|
||||
explanation: "Transfer 100 USDC tokens to the recipient address",
|
||||
},
|
||||
],
|
||||
],
|
||||
schema: z.object({
|
||||
to: z.string().min(32, "Invalid Solana address"),
|
||||
amount: z.number().positive("Amount must be positive"),
|
||||
mint: z.string().optional(),
|
||||
}),
|
||||
handler: async (agent: SolanaAgentKit, input: Record<string, any>) => {
|
||||
const recipient = new PublicKey(input.to);
|
||||
const mintAddress = input.mint ? new PublicKey(input.mint) : undefined;
|
||||
|
||||
const tx = await transfer(agent, recipient, input.amount, mintAddress);
|
||||
|
||||
return {
|
||||
status: "success",
|
||||
message: "Transfer completed successfully",
|
||||
amount: input.amount,
|
||||
recipient: input.to,
|
||||
token: input.mint || "SOL",
|
||||
transaction: tx,
|
||||
};
|
||||
},
|
||||
};
|
||||
|
||||
export default transferAction;
|
||||
@@ -2,6 +2,7 @@ import { Connection, Keypair, PublicKey } from "@solana/web3.js";
|
||||
import bs58 from "bs58";
|
||||
import Decimal from "decimal.js";
|
||||
import { DEFAULT_OPTIONS } from "../constants";
|
||||
import { Config } from "../types";
|
||||
import {
|
||||
deploy_collection,
|
||||
deploy_token,
|
||||
@@ -14,12 +15,16 @@ import {
|
||||
lendAsset,
|
||||
mintCollectionNFT,
|
||||
openbookCreateMarket,
|
||||
manifestCreateMarket,
|
||||
raydiumCreateAmmV4,
|
||||
raydiumCreateClmm,
|
||||
raydiumCreateCpmm,
|
||||
registerDomain,
|
||||
request_faucet_funds,
|
||||
trade,
|
||||
limitOrder,
|
||||
cancelAllOrders,
|
||||
withdrawAll,
|
||||
transfer,
|
||||
getTokenDataByAddress,
|
||||
getTokenDataByTicker,
|
||||
@@ -43,6 +48,8 @@ import {
|
||||
orcaFetchPositions,
|
||||
rock_paper_scissor,
|
||||
create_TipLink,
|
||||
listNFTForSale,
|
||||
cancelListing,
|
||||
} from "../tools";
|
||||
|
||||
import {
|
||||
@@ -64,22 +71,39 @@ import { BN } from "@coral-xyz/anchor";
|
||||
* @property {Connection} connection - Solana RPC connection
|
||||
* @property {Keypair} wallet - Wallet keypair for signing transactions
|
||||
* @property {PublicKey} wallet_address - Public key of the wallet
|
||||
* @property {Config} config - Configuration object
|
||||
*/
|
||||
export class SolanaAgentKit {
|
||||
public connection: Connection;
|
||||
public wallet: Keypair;
|
||||
public wallet_address: PublicKey;
|
||||
public openai_api_key: string | null;
|
||||
public config: Config;
|
||||
|
||||
/**
|
||||
* @deprecated Using openai_api_key directly in constructor is deprecated.
|
||||
* Please use the new constructor with Config object instead:
|
||||
* @example
|
||||
* const agent = new SolanaAgentKit(privateKey, rpcUrl, {
|
||||
* OPENAI_API_KEY: 'your-key'
|
||||
* });
|
||||
*/
|
||||
constructor(private_key: string, rpc_url: string, openai_api_key: string | null);
|
||||
constructor(private_key: string, rpc_url: string, config: Config);
|
||||
constructor(
|
||||
private_key: string,
|
||||
rpc_url = "https://api.mainnet-beta.solana.com",
|
||||
openai_api_key: string | null = null,
|
||||
rpc_url: string,
|
||||
configOrKey: Config | string | null,
|
||||
) {
|
||||
this.connection = new Connection(rpc_url);
|
||||
this.connection = new Connection(rpc_url || "https://api.mainnet-beta.solana.com");
|
||||
this.wallet = Keypair.fromSecretKey(bs58.decode(private_key));
|
||||
this.wallet_address = this.wallet.publicKey;
|
||||
this.openai_api_key = openai_api_key;
|
||||
|
||||
// Handle both old and new patterns
|
||||
if (typeof configOrKey === 'string' || configOrKey === null) {
|
||||
this.config = { OPENAI_API_KEY: configOrKey || '' };
|
||||
} else {
|
||||
this.config = configOrKey;
|
||||
}
|
||||
}
|
||||
|
||||
// Tool methods
|
||||
@@ -151,6 +175,23 @@ export class SolanaAgentKit {
|
||||
return trade(this, outputMint, inputAmount, inputMint, slippageBps);
|
||||
}
|
||||
|
||||
async limitOrder(
|
||||
marketId: PublicKey,
|
||||
quantity: number,
|
||||
side: string,
|
||||
price: number,
|
||||
): Promise<string> {
|
||||
return limitOrder(this, marketId, quantity, side, price);
|
||||
}
|
||||
|
||||
async cancelAllOrders(marketId: PublicKey): Promise<string> {
|
||||
return cancelAllOrders(this, marketId);
|
||||
}
|
||||
|
||||
async withdrawAll(marketId: PublicKey): Promise<string> {
|
||||
return withdrawAll(this, marketId);
|
||||
}
|
||||
|
||||
async lendAssets(amount: number): Promise<string> {
|
||||
return lendAsset(this, amount);
|
||||
}
|
||||
@@ -295,8 +336,7 @@ export class SolanaAgentKit {
|
||||
return getOwnedDomainsForTLD(this, tld);
|
||||
}
|
||||
|
||||
// eslint-disable-next-line @typescript-eslint/ban-types
|
||||
async getAllDomainsTLDs(): Promise<String[]> {
|
||||
async getAllDomainsTLDs(): Promise<string[]> {
|
||||
return getAllDomainsTLDs(this);
|
||||
}
|
||||
|
||||
@@ -378,6 +418,13 @@ export class SolanaAgentKit {
|
||||
);
|
||||
}
|
||||
|
||||
async manifestCreateMarket(
|
||||
baseMint: PublicKey,
|
||||
quoteMint: PublicKey,
|
||||
): Promise<string[]> {
|
||||
return manifestCreateMarket(this, baseMint, quoteMint);
|
||||
}
|
||||
|
||||
async pythFetchPrice(priceFeedID: string): Promise<string> {
|
||||
return pythFetchPrice(priceFeedID);
|
||||
}
|
||||
@@ -412,4 +459,12 @@ export class SolanaAgentKit {
|
||||
async createTiplink(amount: number, splmintAddress?: PublicKey) {
|
||||
return create_TipLink(this, amount, splmintAddress);
|
||||
}
|
||||
|
||||
async tensorListNFT(nftMint: PublicKey, price: number): Promise<string> {
|
||||
return listNFTForSale(this, nftMint, price);
|
||||
}
|
||||
|
||||
async tensorCancelListing(nftMint: PublicKey): Promise<string> {
|
||||
return cancelListing(this, nftMint);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -22,9 +22,12 @@ export const TOKENS = {
|
||||
export const DEFAULT_OPTIONS = {
|
||||
SLIPPAGE_BPS: 300,
|
||||
TOKEN_DECIMALS: 9,
|
||||
RERERRAL_FEE: 200,
|
||||
} as const;
|
||||
|
||||
/**
|
||||
* Jupiter API URL
|
||||
*/
|
||||
export const JUP_API = "https://quote-api.jup.ag/v6";
|
||||
export const JUP_REFERRAL_ADDRESS =
|
||||
"REFER4ZgmyYx9c6He5XfaTMiGfdLwRnkV4RPp9t9iF3";
|
||||
|
||||
@@ -6,3 +6,7 @@ export { SolanaAgentKit, createSolanaTools, createVercelAITools };
|
||||
|
||||
// Optional: Export types that users might need
|
||||
export * from "./types";
|
||||
|
||||
// Export action system
|
||||
export { ACTIONS } from "./actions";
|
||||
export * from "./utils/actionExecutor";
|
||||
|
||||
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user