repositories
loading repo index
repositories
loading repo index
repository
loading code, commits, and activity
public Clawd ADK gateway launch mirror
stars
latest
clone command
git clone gitlawb://did:key:z6Mkq5mY...iFZ5/my-project-publ...git clone gitlawb://did:key:z6Mkq5mY.../my-project-publ...2fa351d6docs: add automaton and perps launch sources16d ago| #1 | /** |
| #2 | * leviathan/src/agent/wallet.ts — AgenticWallet adapter |
| #3 | * |
| #4 | * Wraps @openclawd/wallet (Privy TEE-backed) when available. |
| #5 | * Falls back to the leviathan's own keypair for signing. |
| #6 | * |
| #7 | * API mirrors AgenticWallet from the published package (once released): |
| #8 | * import { AgenticWallet } from '@openclawd/wallet'; |
| #9 | * |
| #10 | * Until the package ships, this shim covers the surface the Leviathan needs. |
| #11 | */ |
| #12 | |
| #13 | import { Connection, PublicKey, LAMPORTS_PER_SOL } from '@solana/web3.js'; |
| #14 | import { loadPubkey, signMessage } from '../identity/index.js'; |
| #15 | |
| #16 | const USDC_DEVNET = 'Gh9ZwEmdLJ8DscKNTkTqPbNwLNNBjuSzaG9Vp2KGtKJr'; // devnet USDC |
| #17 | |
| #18 | export interface WalletBrief { |
| #19 | pubkey: string; |
| #20 | solBalance: number; |
| #21 | usdcBalance: number; |
| #22 | cluster: string; |
| #23 | } |
| #24 | |
| #25 | export interface SwapQuote { |
| #26 | inputMint: string; |
| #27 | outputMint: string; |
| #28 | inAmount: string; |
| #29 | outAmount: string; |
| #30 | priceImpactPct: string; |
| #31 | routePlan: string[]; |
| #32 | } |
| #33 | |
| #34 | export class AgenticWalletShim { |
| #35 | private connection: Connection; |
| #36 | private rpcUrl: string; |
| #37 | |
| #38 | constructor() { |
| #39 | this.rpcUrl = process.env['SOLANA_RPC_URL'] ?? 'https://api.devnet.solana.com'; |
| #40 | this.connection = new Connection(this.rpcUrl, 'confirmed'); |
| #41 | } |
| #42 | |
| #43 | get pubkey(): string { |
| #44 | return loadPubkey() ?? 'unknown'; |
| #45 | } |
| #46 | |
| #47 | async brief(): Promise<WalletBrief> { |
| #48 | const pubkeyStr = this.pubkey; |
| #49 | let solBalance = 0; |
| #50 | let usdcBalance = 0; |
| #51 | |
| #52 | try { |
| #53 | const pk = new PublicKey(pubkeyStr); |
| #54 | const lamports = await this.connection.getBalance(pk); |
| #55 | solBalance = lamports / LAMPORTS_PER_SOL; |
| #56 | } catch { /* devnet may not have the account */ } |
| #57 | |
| #58 | return { |
| #59 | pubkey: pubkeyStr, |
| #60 | solBalance, |
| #61 | usdcBalance, |
| #62 | cluster: this.rpcUrl.includes('devnet') ? 'devnet' : 'mainnet-beta', |
| #63 | }; |
| #64 | } |
| #65 | |
| #66 | async jupiterSwapQuote(opts: { |
| #67 | inputMint: string; |
| #68 | outputMint: string; |
| #69 | amount: string; |
| #70 | slippageBps?: number; |
| #71 | }): Promise<SwapQuote | string> { |
| #72 | try { |
| #73 | const url = `https://lite-api.jup.ag/swap/v1/quote?inputMint=${opts.inputMint}&outputMint=${opts.outputMint}&amount=${opts.amount}&slippageBps=${opts.slippageBps ?? 50}`; |
| #74 | const res = await fetch(url, { signal: AbortSignal.timeout(8000) }); |
| #75 | if (!res.ok) return `Jupiter quote failed: ${res.status}`; |
| #76 | const data = (await res.json()) as { |
| #77 | inAmount: string; |
| #78 | outAmount: string; |
| #79 | priceImpactPct: string; |
| #80 | routePlan?: Array<{ swapInfo?: { label?: string } }>; |
| #81 | }; |
| #82 | return { |
| #83 | inputMint: opts.inputMint, |
| #84 | outputMint: opts.outputMint, |
| #85 | inAmount: data.inAmount, |
| #86 | outAmount: data.outAmount, |
| #87 | priceImpactPct: data.priceImpactPct, |
| #88 | routePlan: (data.routePlan ?? []).map((r) => r.swapInfo?.label ?? '?'), |
| #89 | }; |
| #90 | } catch (e) { |
| #91 | return String(e); |
| #92 | } |
| #93 | } |
| #94 | |
| #95 | sign(message: Uint8Array): string { |
| #96 | return signMessage(message); |
| #97 | } |
| #98 | } |
| #99 | |
| #100 | export function getWallet(): AgenticWalletShim { |
| #101 | return new AgenticWalletShim(); |
| #102 | } |
| #103 |