lyra-plugin-onchain 0.2.0 → 0.2.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/package.json +2 -2
- package/src/catalog.ts +120 -0
- package/src/guidance.ts +14 -40
- package/src/index.ts +4 -72
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "lyra-plugin-onchain",
|
|
3
|
-
"version": "0.2.
|
|
3
|
+
"version": "0.2.1",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"description": "The Sui on-chain tools for Lyra: SUI transfers, DeepBook market data, Walrus receipts/memory — every write policy-checked, simulated, and recorded on-chain via lyra::policy",
|
|
6
6
|
"license": "MIT",
|
|
@@ -55,7 +55,7 @@
|
|
|
55
55
|
"@scallop-io/sui-scallop-sdk": "^2.4.5",
|
|
56
56
|
"@suilend/sdk": "1.1.99",
|
|
57
57
|
"@suilend/sui-fe": "0.3.49",
|
|
58
|
-
"lyra-core": "^0.2.
|
|
58
|
+
"lyra-core": "^0.2.1",
|
|
59
59
|
"navi-sdk": "^1.7.3",
|
|
60
60
|
"zod": "^3.23.8"
|
|
61
61
|
}
|
package/src/catalog.ts
ADDED
|
@@ -0,0 +1,120 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The tool catalog — the ONE place every on-chain tool is declared. Adding a tool
|
|
3
|
+
* is a single entry here (plus the tool file itself); everything downstream is
|
|
4
|
+
* derived:
|
|
5
|
+
*
|
|
6
|
+
* - registration → the plugin iterates TOOLS (index.ts)
|
|
7
|
+
* - web console tool set → WEB_TOOL_NAMES (apps import it; no hand-kept allowlist)
|
|
8
|
+
* - agent guidance → capabilitySummary() feeds the system prompt (CLI + web),
|
|
9
|
+
* so the model learns a new capability with no prose edit
|
|
10
|
+
*
|
|
11
|
+
* `web` marks a tool for the browser console's inline-execute set (the rest run on
|
|
12
|
+
* the CLI/gateway, or have a web-native equivalent). `blurb` is an optional one-line
|
|
13
|
+
* capability description surfaced in the guidance — omit it for secondary tools in a
|
|
14
|
+
* family that a sibling already covers.
|
|
15
|
+
*/
|
|
16
|
+
|
|
17
|
+
import type { ToolDef } from 'lyra-core'
|
|
18
|
+
import { makeAccountInfo, makeSuiBalance } from './tools/balance'
|
|
19
|
+
import { makeCetusQuote } from './tools/cetus'
|
|
20
|
+
import { makeDeepbookMarkets } from './tools/deepbook'
|
|
21
|
+
import { makeDefiYields } from './tools/defillama'
|
|
22
|
+
import { makeVoloStake, makeVoloUnstake } from './tools/liquid-stake'
|
|
23
|
+
import {
|
|
24
|
+
makeNaviBorrow,
|
|
25
|
+
makeNaviMarkets,
|
|
26
|
+
makeNaviPosition,
|
|
27
|
+
makeNaviRepay,
|
|
28
|
+
makeNaviSupply,
|
|
29
|
+
makeNaviWithdraw,
|
|
30
|
+
} from './tools/navi'
|
|
31
|
+
import { makePolicyCreate, makePolicyShow } from './tools/policy'
|
|
32
|
+
import { makeProtocolsList } from './tools/protocols'
|
|
33
|
+
import {
|
|
34
|
+
makeScallopMarkets,
|
|
35
|
+
makeScallopPosition,
|
|
36
|
+
makeScallopSupply,
|
|
37
|
+
makeScallopWithdraw,
|
|
38
|
+
} from './tools/scallop'
|
|
39
|
+
import { makeSuiSend } from './tools/send'
|
|
40
|
+
import { makeStake, makeUnstake } from './tools/stake'
|
|
41
|
+
import {
|
|
42
|
+
makeSuilendBorrow,
|
|
43
|
+
makeSuilendPosition,
|
|
44
|
+
makeSuilendRepay,
|
|
45
|
+
makeSuilendSupply,
|
|
46
|
+
makeSuilendWithdraw,
|
|
47
|
+
} from './tools/suilend'
|
|
48
|
+
import { makeSwap } from './tools/swap'
|
|
49
|
+
import { makeWalrusStore } from './tools/walrus'
|
|
50
|
+
import { makeWalrusStake, makeWalrusStaking, makeWalrusUnstake } from './tools/walrus-stake'
|
|
51
|
+
import type { OnchainRuntimeContext } from './types'
|
|
52
|
+
|
|
53
|
+
// biome-ignore lint/suspicious/noExplicitAny: tools carry heterogeneous arg schemas
|
|
54
|
+
type Make = (ctx: OnchainRuntimeContext) => ToolDef<any>
|
|
55
|
+
|
|
56
|
+
export interface CatalogEntry {
|
|
57
|
+
/** The tool's registered name (also its dispatch key). */
|
|
58
|
+
name: string
|
|
59
|
+
/** Factory that binds the tool to a runtime context. */
|
|
60
|
+
make: Make
|
|
61
|
+
/** Exposed in the browser console's inline-execute tool set. */
|
|
62
|
+
web: boolean
|
|
63
|
+
/** One-line capability blurb for the agent guidance (optional). */
|
|
64
|
+
blurb?: string
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
export const TOOLS: CatalogEntry[] = [
|
|
68
|
+
// Reads / discovery
|
|
69
|
+
{ name: 'account.info', make: makeAccountInfo, web: false, blurb: 'account.info — the agent address, network, balance, and active policy.' },
|
|
70
|
+
{ name: 'sui.balance', make: makeSuiBalance, web: false, blurb: 'sui.balance — SUI + coin balances for the agent or any address.' },
|
|
71
|
+
{ name: 'policy.show', make: makePolicyShow, web: false, blurb: 'policy.show — the active fund-control policy (caps, allowlists, expiry).' },
|
|
72
|
+
{ name: 'protocols.list', make: makeProtocolsList, web: true, blurb: 'protocols.list — which protocols Lyra can READ vs EXECUTE on.' },
|
|
73
|
+
{ name: 'defi.yields', make: makeDefiYields, web: true, blurb: 'defi.yields — best yields across Sui (DefiLlama), tagged executable / executeWith.' },
|
|
74
|
+
{ name: 'deepbook.markets', make: makeDeepbookMarkets, web: true, blurb: 'deepbook.markets — DeepBook spot mid prices.' },
|
|
75
|
+
{ name: 'cetus.quote', make: makeCetusQuote, web: false, blurb: 'cetus.quote — best swap route/price across DEXes (read-only aggregator).' },
|
|
76
|
+
{ name: 'scallop.markets', make: makeScallopMarkets, web: true },
|
|
77
|
+
{ name: 'scallop.position', make: makeScallopPosition, web: true },
|
|
78
|
+
{ name: 'navi.markets', make: makeNaviMarkets, web: true },
|
|
79
|
+
{ name: 'navi.position', make: makeNaviPosition, web: true },
|
|
80
|
+
{ name: 'suilend.position', make: makeSuilendPosition, web: true },
|
|
81
|
+
{ name: 'walrus.staking', make: makeWalrusStaking, web: true, blurb: "walrus.staking — the agent's WAL balance, StakedWal positions, and nodes to stake with." },
|
|
82
|
+
|
|
83
|
+
// Policy / transfer / swap
|
|
84
|
+
{ name: 'policy.create', make: makePolicyCreate, web: false, blurb: 'policy.create — publish a shared on-chain AgentPolicy (arms enforcement + receipts).' },
|
|
85
|
+
{ name: 'sui.send', make: makeSuiSend, web: false, blurb: 'sui.send — transfer SUI; blocked if out of policy, mints an on-chain receipt.' },
|
|
86
|
+
{ name: 'swap', make: makeSwap, web: false, blurb: 'swap — best-route swap across the major Sui DEXes (7k aggregator).' },
|
|
87
|
+
|
|
88
|
+
// Lending
|
|
89
|
+
{ name: 'scallop.supply', make: makeScallopSupply, web: true, blurb: 'Lending — scallop.supply/withdraw, navi.supply/withdraw/borrow/repay, suilend.supply/withdraw/borrow/repay.' },
|
|
90
|
+
{ name: 'scallop.withdraw', make: makeScallopWithdraw, web: true },
|
|
91
|
+
{ name: 'navi.supply', make: makeNaviSupply, web: true },
|
|
92
|
+
{ name: 'navi.withdraw', make: makeNaviWithdraw, web: true },
|
|
93
|
+
{ name: 'navi.borrow', make: makeNaviBorrow, web: true },
|
|
94
|
+
{ name: 'navi.repay', make: makeNaviRepay, web: true },
|
|
95
|
+
{ name: 'suilend.supply', make: makeSuilendSupply, web: true },
|
|
96
|
+
{ name: 'suilend.withdraw', make: makeSuilendWithdraw, web: true },
|
|
97
|
+
{ name: 'suilend.borrow', make: makeSuilendBorrow, web: true },
|
|
98
|
+
{ name: 'suilend.repay', make: makeSuilendRepay, web: true },
|
|
99
|
+
|
|
100
|
+
// Staking
|
|
101
|
+
{ name: 'sui.stake', make: makeStake, web: true, blurb: 'sui.stake / sui.unstake — native SUI staking to a validator (min 1 SUI).' },
|
|
102
|
+
{ name: 'sui.unstake', make: makeUnstake, web: true },
|
|
103
|
+
{ name: 'volo.stake', make: makeVoloStake, web: true, blurb: 'volo.stake / volo.unstake — liquid staking, SUI ↔ vSUI.' },
|
|
104
|
+
{ name: 'volo.unstake', make: makeVoloUnstake, web: true },
|
|
105
|
+
{ name: 'walrus.stake', make: makeWalrusStake, web: true, blurb: 'walrus.stake / walrus.unstake — stake WAL to a Walrus storage node (min 1 WAL; unstake returns WAL next epoch).' },
|
|
106
|
+
{ name: 'walrus.unstake', make: makeWalrusUnstake, web: true },
|
|
107
|
+
|
|
108
|
+
// Storage
|
|
109
|
+
{ name: 'walrus.store', make: makeWalrusStore, web: false, blurb: 'walrus.store — persist a receipt/report/memory artifact to Walrus.' },
|
|
110
|
+
]
|
|
111
|
+
|
|
112
|
+
/** Tool names exposed in the browser console's inline-execute set (derived). */
|
|
113
|
+
export const WEB_TOOL_NAMES: string[] = TOOLS.filter(t => t.web).map(t => t.name)
|
|
114
|
+
|
|
115
|
+
/** The capability inventory for the agent guidance (derived from the catalog). */
|
|
116
|
+
export function capabilitySummary(): string {
|
|
117
|
+
return TOOLS.filter(t => t.blurb)
|
|
118
|
+
.map(t => `- ${t.blurb}`)
|
|
119
|
+
.join('\n')
|
|
120
|
+
}
|
package/src/guidance.ts
CHANGED
|
@@ -1,55 +1,29 @@
|
|
|
1
1
|
/**
|
|
2
|
-
* System-prompt guidance injected when the onchain plugin is active.
|
|
3
|
-
*
|
|
4
|
-
*
|
|
2
|
+
* System-prompt guidance injected when the onchain plugin is active. The policy
|
|
3
|
+
* framing + rules are hand-written; the CAPABILITY LIST is generated from the tool
|
|
4
|
+
* catalog (see `./catalog`), so adding a tool there surfaces it to the model here
|
|
5
|
+
* automatically — no prose edit per integration.
|
|
5
6
|
*/
|
|
6
7
|
|
|
8
|
+
import { capabilitySummary } from './catalog'
|
|
9
|
+
|
|
7
10
|
export const ONCHAIN_GUIDANCE = `# Sui on-chain tools (Lyra)
|
|
8
11
|
|
|
9
12
|
You operate a single Sui agent address. You can read and move funds ONLY through
|
|
10
13
|
these tools; every value-moving action is checked by a deterministic policy in
|
|
11
14
|
code AND re-enforced on-chain by the lyra::policy Move package. You cannot talk
|
|
12
|
-
your way past a cap — if
|
|
15
|
+
your way past a cap — if an action exceeds the per-tx cap or budget, the tool
|
|
13
16
|
returns "policy blocked" before anything is signed.
|
|
14
17
|
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
- sui.balance — SUI and coin balances for the agent or any address.
|
|
18
|
-
- policy.show — the active fund-control policy (caps, allowlists, expiry, tier).
|
|
19
|
-
- protocols.list — which protocols Lyra can READ vs EXECUTE on.
|
|
20
|
-
- defi.yields — best yields across ALL Sui protocols (DefiLlama). Each result is
|
|
21
|
-
tagged executable / executeWith.
|
|
22
|
-
- deepbook.markets — DeepBook spot mid prices.
|
|
23
|
-
- cetus.quote — best swap route/price across many DEXes (aggregator, read-only).
|
|
24
|
-
- scallop.markets / scallop.position, navi.markets / navi.position,
|
|
25
|
-
suilend.position — lending rates + the agent's positions.
|
|
26
|
-
- walrus.staking — the agent's WAL balance, current WAL staking positions
|
|
27
|
-
(StakedWal), and large Walrus storage nodes to stake with.
|
|
28
|
-
|
|
29
|
-
Writes (policy-checked → simulated → executed):
|
|
30
|
-
- policy.create — publish a shared on-chain AgentPolicy (budget, per-tx cap,
|
|
31
|
-
expiry). Do this first to arm on-chain enforcement + receipts.
|
|
32
|
-
- sui.send — transfer SUI. Blocked if out of policy; mints an on-chain receipt.
|
|
33
|
-
- swap — best-route swap across the major Sui DEXes (7k aggregator).
|
|
34
|
-
- Lending: scallop.supply / scallop.withdraw, navi.supply / navi.withdraw /
|
|
35
|
-
navi.borrow / navi.repay, suilend.supply / suilend.withdraw / suilend.borrow /
|
|
36
|
-
suilend.repay — lend, redeem, borrow, and repay across the largest Sui markets.
|
|
37
|
-
- Staking:
|
|
38
|
-
- sui.stake / sui.unstake — native SUI staking to a validator (min 1 SUI).
|
|
39
|
-
- volo.stake / volo.unstake — liquid staking, SUI ↔ vSUI.
|
|
40
|
-
- walrus.stake / walrus.unstake — stake WAL to a Walrus storage node to earn
|
|
41
|
-
rewards + secure decentralized storage (min 1 WAL; unstake returns WAL next
|
|
42
|
-
epoch). Use walrus.staking first to show the balance + available nodes.
|
|
43
|
-
- walrus.store — persist a receipt/report/memory artifact to Walrus.
|
|
18
|
+
Capabilities (each write runs policy-checked → simulated → executed):
|
|
19
|
+
${capabilitySummary()}
|
|
44
20
|
|
|
45
21
|
The capability boundary (important):
|
|
46
|
-
- Discovery is broad; EXECUTION is bounded
|
|
47
|
-
protocols.list
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
alternative (e.g. supply on NAVI/Scallop), or (b) concise manual steps. The
|
|
52
|
-
policy's protocol-allowlist enforces this on-chain too.
|
|
22
|
+
- Discovery is broad; EXECUTION is bounded to the protocols above (see
|
|
23
|
+
protocols.list). If the best yield/action a user wants is on a protocol Lyra has
|
|
24
|
+
NOT integrated, DO NOT invent a transaction. Say so honestly, then offer the best
|
|
25
|
+
executable alternative or concise manual steps. The policy's protocol-allowlist
|
|
26
|
+
enforces this on-chain too.
|
|
53
27
|
|
|
54
28
|
Rules:
|
|
55
29
|
- Call policy.show / protocols.list before claiming what you can spend or do.
|
package/src/index.ts
CHANGED
|
@@ -22,41 +22,10 @@
|
|
|
22
22
|
// navi-sdk → axios → follow-redirects, which crashes Bun at import otherwise.
|
|
23
23
|
import './capture-shim'
|
|
24
24
|
import type { NativePlugin, ToolDef } from 'lyra-core'
|
|
25
|
-
import {
|
|
26
|
-
import { makeCetusQuote } from './tools/cetus'
|
|
27
|
-
import { makeDeepbookMarkets } from './tools/deepbook'
|
|
28
|
-
import { makeDefiYields } from './tools/defillama'
|
|
29
|
-
import { makeVoloStake, makeVoloUnstake } from './tools/liquid-stake'
|
|
30
|
-
import {
|
|
31
|
-
makeNaviBorrow,
|
|
32
|
-
makeNaviMarkets,
|
|
33
|
-
makeNaviPosition,
|
|
34
|
-
makeNaviRepay,
|
|
35
|
-
makeNaviSupply,
|
|
36
|
-
makeNaviWithdraw,
|
|
37
|
-
} from './tools/navi'
|
|
38
|
-
import { makePolicyCreate, makePolicyShow } from './tools/policy'
|
|
39
|
-
import { makeProtocolsList } from './tools/protocols'
|
|
40
|
-
import {
|
|
41
|
-
makeScallopMarkets,
|
|
42
|
-
makeScallopPosition,
|
|
43
|
-
makeScallopSupply,
|
|
44
|
-
makeScallopWithdraw,
|
|
45
|
-
} from './tools/scallop'
|
|
46
|
-
import { makeSuiSend } from './tools/send'
|
|
47
|
-
import { makeStake, makeUnstake } from './tools/stake'
|
|
48
|
-
import {
|
|
49
|
-
makeSuilendBorrow,
|
|
50
|
-
makeSuilendPosition,
|
|
51
|
-
makeSuilendRepay,
|
|
52
|
-
makeSuilendSupply,
|
|
53
|
-
makeSuilendWithdraw,
|
|
54
|
-
} from './tools/suilend'
|
|
55
|
-
import { makeSwap } from './tools/swap'
|
|
56
|
-
import { makeWalrusStore } from './tools/walrus'
|
|
57
|
-
import { makeWalrusStake, makeWalrusStaking, makeWalrusUnstake } from './tools/walrus-stake'
|
|
25
|
+
import { TOOLS } from './catalog'
|
|
58
26
|
import type { OnchainRuntimeContext } from './types'
|
|
59
27
|
|
|
28
|
+
export { TOOLS, WEB_TOOL_NAMES, capabilitySummary, type CatalogEntry } from './catalog'
|
|
60
29
|
export {
|
|
61
30
|
makeSuiClient,
|
|
62
31
|
keypairFromSecret,
|
|
@@ -98,45 +67,8 @@ const plugin: NativePlugin = {
|
|
|
98
67
|
const onchain = (ctx as unknown as { onchain?: OnchainRuntimeContext }).onchain
|
|
99
68
|
if (!onchain) return // soft-init for tests / non-onchain contexts
|
|
100
69
|
|
|
101
|
-
|
|
102
|
-
ctx.registerTool(
|
|
103
|
-
ctx.registerTool(makeSuiSend(onchain) as ToolDef)
|
|
104
|
-
ctx.registerTool(makeSwap(onchain) as ToolDef)
|
|
105
|
-
ctx.registerTool(makePolicyShow(onchain) as ToolDef)
|
|
106
|
-
ctx.registerTool(makePolicyCreate(onchain) as ToolDef)
|
|
107
|
-
ctx.registerTool(makeWalrusStore(onchain) as ToolDef)
|
|
108
|
-
ctx.registerTool(makeDeepbookMarkets(onchain) as ToolDef)
|
|
109
|
-
|
|
110
|
-
// Discovery + capability map.
|
|
111
|
-
ctx.registerTool(makeProtocolsList(onchain) as ToolDef)
|
|
112
|
-
ctx.registerTool(makeDefiYields(onchain) as ToolDef)
|
|
113
|
-
ctx.registerTool(makeCetusQuote(onchain) as ToolDef)
|
|
114
|
-
|
|
115
|
-
// Lending (the two largest Sui money markets).
|
|
116
|
-
ctx.registerTool(makeScallopMarkets(onchain) as ToolDef)
|
|
117
|
-
ctx.registerTool(makeScallopPosition(onchain) as ToolDef)
|
|
118
|
-
ctx.registerTool(makeScallopSupply(onchain) as ToolDef)
|
|
119
|
-
ctx.registerTool(makeScallopWithdraw(onchain) as ToolDef)
|
|
120
|
-
ctx.registerTool(makeNaviMarkets(onchain) as ToolDef)
|
|
121
|
-
ctx.registerTool(makeNaviPosition(onchain) as ToolDef)
|
|
122
|
-
ctx.registerTool(makeNaviSupply(onchain) as ToolDef)
|
|
123
|
-
ctx.registerTool(makeNaviWithdraw(onchain) as ToolDef)
|
|
124
|
-
ctx.registerTool(makeNaviBorrow(onchain) as ToolDef)
|
|
125
|
-
ctx.registerTool(makeNaviRepay(onchain) as ToolDef)
|
|
126
|
-
ctx.registerTool(makeSuilendSupply(onchain) as ToolDef)
|
|
127
|
-
ctx.registerTool(makeSuilendWithdraw(onchain) as ToolDef)
|
|
128
|
-
ctx.registerTool(makeSuilendBorrow(onchain) as ToolDef)
|
|
129
|
-
ctx.registerTool(makeSuilendRepay(onchain) as ToolDef)
|
|
130
|
-
ctx.registerTool(makeSuilendPosition(onchain) as ToolDef)
|
|
131
|
-
|
|
132
|
-
// Staking: native delegation (min 1 SUI) + Volo liquid staking (vSUI).
|
|
133
|
-
ctx.registerTool(makeStake(onchain) as ToolDef)
|
|
134
|
-
ctx.registerTool(makeUnstake(onchain) as ToolDef)
|
|
135
|
-
ctx.registerTool(makeVoloStake(onchain) as ToolDef)
|
|
136
|
-
ctx.registerTool(makeVoloUnstake(onchain) as ToolDef)
|
|
137
|
-
ctx.registerTool(makeWalrusStake(onchain) as ToolDef)
|
|
138
|
-
ctx.registerTool(makeWalrusUnstake(onchain) as ToolDef)
|
|
139
|
-
ctx.registerTool(makeWalrusStaking(onchain) as ToolDef)
|
|
70
|
+
// Every tool is declared once in the catalog; registration just iterates it.
|
|
71
|
+
for (const tool of TOOLS) ctx.registerTool(tool.make(onchain) as ToolDef)
|
|
140
72
|
},
|
|
141
73
|
}
|
|
142
74
|
|