@leviosasdk/sdk
The SDK behind Leviosa, the AI trading wallet for GIWA.
A user says "새로 졸업한 토큰 0.001 ETH어치 사줘" ("buy 0.001 ETH of the token that
just graduated"); your app shows the venue, price, fee and safety check; the user
signs once; and an EIP-7702 policy wallet enforces KRW limits and a venue
allowlist on-chain. The model only fills a typed intent. Addresses, calldata and
minimum output come from code and on-chain reads.
| Entry point |
For |
@leviosasdk/sdk/launchpad |
One interface over 18 GIWA launchpads and DEXes: read a market, quote a trade by simulating it, and build the batch through LeviosaLaunchRouter with the platform fee (0.03%) in the same transaction. GIWA Sepolia, unaudited. |
@leviosasdk/sdk/giwa |
The GIWA pipeline: an intent parser that runs on your server with your own LLM key, a planner, and helpers for the on-chain policy delegate (KRW limits, allowlist, 2FA step-up, session keys). GIWA Sepolia, unaudited. |
@leviosasdk/sdk/options |
CallPut options on GIWA: market feed, spreads, and order building. |
@leviosasdk/sdk/wallet |
Self-custodial key handling: 2-of-3 Shamir key shares (device / auth / password-encrypted recovery). Unaudited. |
@leviosasdk/sdk |
The Leviosa API client: chat, actions, signing and execution through Leviosa's backend. Needs a partner key (see Partner keys). |
@leviosasdk/sdk/react |
Hooks over the API client: useLeviosaClient, useConversation, useBalances, usePositions. |
The on-chain entry points (/launchpad, /giwa, /options, /wallet) need no
Leviosa key: they talk to GIWA directly through your own client and wallet.
Install
npm i @leviosasdk/sdk viem
viem is a peer dependency; react (18+) is an optional one, needed only for @leviosasdk/sdk/react. Runtime dependencies: zod and shamir-secret-sharing (Privy's audited implementation, used by ./wallet). The package is ESM and needs Node 20+ or a modern browser.
React Native works when the runtime provides a fetch with streaming bodies (or pass one via fetch), TextDecoder and AbortController.
Quick start: buy a GIWA launch token
import { loadLaunchpadNetwork, planLaunchBuy, quoteBuy, readMarket, readTokenInfo, batchMatchesTrade } from '@leviosasdk/sdk/launchpad';
const network = loadLaunchpadNetwork(registryJson, routerAddress); // packages/contracts/deployments
const market = await readMarket(client, network, 'gamapad', token);
const quote = await quoteBuy(client, network, market, { account, ethIn, feeBps: 3 });
const plan = planLaunchBuy({
network, market, account, krwPerEth, nonce, deadline,
token: await readTokenInfo(client, token),
ethIn, feeBps: 3, expectedTokensOut: quote.amountOut,
});
// A launch token has no on-chain price, so the floor in the order is what protects
// the trade. Check the numbers you show against the bytes you sign.
if (!batchMatchesTrade(plan.steps, plan.launch)) throw new Error('Do not sign this.');
The registry and router address are in
packages/contracts/deployments.
Leviosa API client
The root entry point talks to Leviosa's backend and needs a publishable partner key.
import { Leviosa, browserTokenStore, fromEip1193 } from '@leviosasdk/sdk';
const provider = await wallet.getEthereumProvider(); // any EIP-1193 provider
const lv = new Leviosa({
// apiUrl defaults to LEVIOSA_API_URL (https://sdk-api.leviosaai.com) — an origin, no /api.
apiKey: 'pk_live_…', // your publishable partner key
signer: fromEip1193(provider, wallet.address, {
// EIP-7702 delegation, needed the first time an account executes on a chain.
signAuthorization: (req) => signAuthorization({ contractAddress: req.address, chainId: req.chainId, nonce: req.nonce }),
rawSignMethod: 'secp256k1_sign',
}),
policy: { maxAmountUsd: 1_000, maxLeverage: 5 },
locale: 'ko', // SDK-written messages in Korean
tokenStore: browserTokenStore(), // stay signed in across reloads
});
const chat = lv.conversation();
chat.subscribe(() => render(chat.messages));
const turn = await chat.send('USDC 10개 보내줘');
if (turn.action) {
const result = await chat.execute(turn.action, {
confirm: (action) => showReviewCard(action), // return false → nothing is signed
onStatus: (s) => setStage(s.stage),
});
showReceipt(result.explorerUrl);
}
The first request that needs a session signs the user in with SIWE
automatically. Call lv.connect() if you want the sign-in prompt to appear at a
time you choose.
React
import { LeviosaProvider, useLeviosaClient, useConversation, useBalances } from '@leviosasdk/sdk/react';
function App({ signer }: { signer: LeviosaSigner | null }) {
const lv = useLeviosaClient({ apiUrl, signer, policy: { maxLeverage: 5 } }); // signer changes are applied
return <LeviosaProvider client={lv}><Chat /></LeviosaProvider>;
}
function Chat() {
const chat = useConversation(); // new wallet → new conversation
const { data: balances } = useBalances(); // refetched after every execution
return (
<>
{chat.messages.map((m) => <Bubble key={m.id} message={m} />)}
{/* for an assistant message with m.turn?.action: */}
{/* <ReviewCard state={chat.stateOf(action.id)} onConfirm={() => chat.execute(action)} /> */}
</>
);
}
useConversation re-renders on every transcript change, streamed text included, and on every change in execution state. Its functions stay stable, so they can go in dependency arrays.
Concepts
Turn
ask and send return one normalised reply:
interface Turn {
text: string; // markdown; streams through onText / chat.messages
action?: Action; // present when the reply can be executed
unsupported?: UnsupportedKind; // recognised, but not executable through the SDK yet
yieldTable?: YieldRow[]; // "예치할만한 곳 보여줘"
actionCards?: ActionCard[];
quickReplies?: QuickReply[];
suggestions?: Suggestion[];
limitReached?: boolean; // the daily free-chat quota is used up
raw?: GenerateResult; // the untouched backend payload
}
Action
kind |
What |
Signatures |
supertx |
Transfer, bridge, Morpho deposit/withdraw, Aave/Compound withdraw. One or more chains. |
EIP-7702 authorization per new chain (first time only), then one SuperTx signature. Gas is paid in USDC. |
perp-order |
Hyperliquid crypto perp open or close |
Open: set leverage, then place the order (2). Close: 1. |
perp-withdraw |
Hyperliquid → EVM chain |
1 |
xyz-order |
Hyperliquid stock / index / commodity / FX perp (the HIP-3 xyz dex): open with optional TP/SL, conditional entry, or close |
Open: set leverage, then the order (2). Close: 1. |
xyz-cancel |
Cancel open orders (e.g. a pending conditional entry) on one market |
1 when there is something to cancel, else 0 |
xyz-send-asset |
Move USDC collateral from the main HyperCore account to the xyz dex |
1. result.followUpMessage is the original request; Conversation asks it again automatically. |
bridge2-deposit |
Arbitrum USDC → HyperCore, through Hyperliquid's Bridge2 — how a new user funds perps |
Like supertx: 7702 on first use, then 1. Gas in USDC. |
fusion-deposit |
Bridge to another chain and deposit into a Morpho vault |
7702 per missing chain, then 1 |
hypercore-deposit |
HyperEVM → HyperCore (HyperEVM has no EIP-7702) |
1 plain transaction; needs signer.sendTransaction |
merkl-claim |
Merkl rewards, every chain that has some. Also from lv.merklClaimable() → lv.merklClaimAction(data) |
1 plain transaction per chain; needs signer.sendTransaction |
Only deposits to a centralised exchange arrive as turn.unsupported ('exchange-deposit'): that flow belongs to the Leviosa consumer app.
Spot trading (buying, selling or swapping tokens) is not offered to wallets. In
the Leviosa consumer app, spot trading goes through a centralised exchange. For
traffic that carries a partner key, the backend answers a buy, sell or swap
request with a plain "not supported" reply and never an order flow.
execute always requests a fresh quote before signing, because the SuperTx hash
changes with every quote. An action from a few minutes ago is safe to execute.
Gates, in order
policy (ClientPolicy): checked locally. When it fails, execute throws POLICY_BLOCKED, and nothing is sent.
confirm: your review card. Returning false throws NOT_CONFIRMED, and nothing is signed.
- Signatures: the user's wallet. A rejection throws
USER_REJECTED, and nothing is executed.
The backend runs its own guards regardless of these gates: it blocks prompt injection and seed-phrase requests, refuses price predictions and investment advice, caps slippage, and applies leverage rules.
Signing guards
The backend decides what to sign, but the SDK decides whether the wallet
agrees. So a compromised or buggy backend cannot redirect a signature. These
checks run before any signature is requested, and a failure throws
UNSAFE_REQUEST:
| Guard |
Allowlist |
| EIP-7702 delegate |
Biconomy Nexus 0x00000000383e8cbe298514674ea60ee1d1de50ac only (override: trustedDelegates) |
| Bridge2 deposit |
Arbitrum native USDC, sent to Bridge2 0x2df1c51e09aecf9cacb7bc98cb1742757f163df7 |
| HyperCore deposit |
the 0x20…00‖index system-address pattern |
| Merkl claim |
distributor 0x3ef3d8ba38ebe18db133cec108f4d14ce00dd9ae |
These are the same allowlists the Leviosa consumer app uses.
After execution
- Cost basis. When a proposal carries
purchase or sale metadata, the SDK records it to the backend's cost-basis ledger (/purchase/record, /purchase/sale). The wallet surface does not produce spot trades today, so this only fires for consumer-app-style proposals. If recording fails, the SDK adds 'cost-basis: not recorded' to result.warnings and still reports success.
- Cross-chain moves with a follow-up, such as "bridge, then deposit": call
lv.waitForArrival(action) before offering action.followUp. It resolves once the destination USDC has risen by at least max(0.5, 80% of the amount), so the follow-up can be quoted against funds that are actually there.
Stock and index perps
The Leviosa API returns only the order parameters for xyz markets, so the SDK
does the rest. It resolves the market's asset id from Hyperliquid at runtime,
because the id depends on the dex's position and is never hard-coded. It then
builds the action, hashes it with msgpack and keccak, gets the user's signature,
and submits to Hyperliquid directly. Hashing is tested byte-for-byte against
@msgpack/msgpack, the encoder the backend uses. Pass hyperliquidUrl to point
at the testnet.
Execution status
onStatus reports each stage in order: quoting → authorizing (7702, with
{ index, total, chainId }) → signing → submitting → pending (repeats as
explorer links arrive) → confirmed. Pass wait: false to return as soon as
the transaction is submitted.
API
new Leviosa(config)