Summary
Proposal to add Magpie — an x402-native permissionless lending protocol on Solana — as a plugin-defi integration, so agents built on Solana Agent Kit can borrow SOL against their own collateral, arm in-vault take-profit / stop-loss exits, and repay, all signing locally.
Magpie is already x402-native and ships a typed SDK (@magpieloans/magpie-agent) and an MCP server (@magpieloans/magpie-mcp), so the SAK integration is a thin action wrapper over the SDK in the same shape as the existing Lulo / Drift / Lavarage integrations under packages/plugin-defi/src/.
What Magpie is (verified facts only)
- x402-native permissionless agent lending on Solana (HTTP 402 pay-per-call). No signup, no API key. Zero custody — the service holds no keys; the agent signs unsigned transactions locally with its own keypair.
- An agent borrows SOL against its own collateral — memecoins (V1 program) or tokenized-stock / RWA (V3 program, launching) — then optionally arms self-owned in-vault TP/SL exit orders (V4 program: proceeds accumulate inside the loan's vault, the loan stays Active, and the only path back to the wallet is a borrower-signed
repay). 170+ approved collateral tokens.
- Live x402 catalog:
https://x402.magpie.capital/.well-known/x402.json. Site: https://x402.magpie.capital. Repo: https://github.com/magpiecapital/magpie-x402 (SDK at sdk/, MCP at mcp/).
Proposed action surface (plugin-defi/src/magpie/)
Mapped 1:1 onto the existing @magpieloans/magpie-agent SDK methods (all sign locally with the agent's keypair):
| SAK action |
SDK method |
x402 cost |
Behavior |
MAGPIE_BORROW |
agent.borrow({ collateralMint, collateralAmount, tier, hasExitArming }) |
0.005 SOL |
Build + cosign + submit a borrow; hasExitArming: true routes to V4 so exits can be armed |
MAGPIE_ARM_EXIT |
agent.armExit({ loanId, direction, target | priceUsd | mcUsd | trailingBps, slippageBps, dest }) |
0.001 SOL |
Arm an in-vault TP (above) / SL (below) on the agent's own V4 loan |
MAGPIE_LIST_EXITS |
agent.listExits() |
free |
List the wallet's armed exit orders |
MAGPIE_REPAY |
agent.repay({ loanPda }) |
0.002 SOL |
Borrower-signed repay; releases collateral + any in-vault SOL proceeds |
MAGPIE_POOL_STATE |
agent.pools() / agent.poolState() |
free |
Live on-chain LendingPool state across V1/V3/V4 |
MAGPIE_SIMULATE_BORROW |
agent.simulateBorrow({...}) |
free |
Quote borrowable SOL before committing |
MAGPIE_WALLET_LOANS |
agent.walletLoans(wallet) |
free |
All loans a wallet holds across versions |
(Read actions — pool state, simulate-borrow, wallet loans — are free; borrow/armExit/repay carry the small x402 per-call fee shown.)
One open integration question (the reason this is an issue, not yet a PR)
SAK's BaseWallet (packages/core/src/types/wallet.ts) is a signing-surface-only abstraction — it exposes publicKey, signTransaction, signAllTransactions, signAndSendTransaction, signMessage, and intentionally no raw Keypair / secret key (so it works with Privy / Turnkey / embedded wallets).
The current @magpieloans/magpie-agent v0.1.4 constructor takes a Keypair directly (new MagpieAgent({ keypair })) and signs its x402 payment transfers and Ed25519 exit-order envelopes internally. So a clean in-tree wrapper needs one of:
- (Preferred) A
BaseWallet-compatible constructor in the Magpie SDK — accept an external signer (signTransaction + signMessage) instead of a raw Keypair. We (Magpie) are happy to ship this so the SAK action never touches a private key and stays compatible with embedded/MPC wallets. This keeps SAK's custody model intact.
- Or, scope the first cut to keypair-backed wallets only (extract the
Keypair from a KeypairWallet), which we'd rather avoid because it breaks for non-keypair wallets.
We'd like maintainer guidance on the preferred path before opening a PR, so the integration matches SAK's wallet abstraction cleanly rather than reaching around it. Option 1 is our default and we can have the SDK change ready quickly; then the plugin-defi/src/magpie/ action+tools PR follows the exact Lulo/Lavarage file layout (actions/*.ts Action objects + tools/*.ts + registration in plugin-defi/src/index.ts).
Happy to implement the full PR — just confirming the wallet-bridge approach you'd prefer so it's right the first time.
Summary
Proposal to add Magpie — an x402-native permissionless lending protocol on Solana — as a
plugin-defiintegration, so agents built on Solana Agent Kit can borrow SOL against their own collateral, arm in-vault take-profit / stop-loss exits, and repay, all signing locally.Magpie is already x402-native and ships a typed SDK (
@magpieloans/magpie-agent) and an MCP server (@magpieloans/magpie-mcp), so the SAK integration is a thin action wrapper over the SDK in the same shape as the existing Lulo / Drift / Lavarage integrations underpackages/plugin-defi/src/.What Magpie is (verified facts only)
repay). 170+ approved collateral tokens.https://x402.magpie.capital/.well-known/x402.json. Site:https://x402.magpie.capital. Repo:https://github.com/magpiecapital/magpie-x402(SDK atsdk/, MCP atmcp/).Proposed action surface (
plugin-defi/src/magpie/)Mapped 1:1 onto the existing
@magpieloans/magpie-agentSDK methods (all sign locally with the agent's keypair):MAGPIE_BORROWagent.borrow({ collateralMint, collateralAmount, tier, hasExitArming })hasExitArming: trueroutes to V4 so exits can be armedMAGPIE_ARM_EXITagent.armExit({ loanId, direction, target | priceUsd | mcUsd | trailingBps, slippageBps, dest })above) / SL (below) on the agent's own V4 loanMAGPIE_LIST_EXITSagent.listExits()MAGPIE_REPAYagent.repay({ loanPda })MAGPIE_POOL_STATEagent.pools()/agent.poolState()MAGPIE_SIMULATE_BORROWagent.simulateBorrow({...})MAGPIE_WALLET_LOANSagent.walletLoans(wallet)(Read actions — pool state, simulate-borrow, wallet loans — are free;
borrow/armExit/repaycarry the small x402 per-call fee shown.)One open integration question (the reason this is an issue, not yet a PR)
SAK's
BaseWallet(packages/core/src/types/wallet.ts) is a signing-surface-only abstraction — it exposespublicKey,signTransaction,signAllTransactions,signAndSendTransaction,signMessage, and intentionally no rawKeypair/ secret key (so it works with Privy / Turnkey / embedded wallets).The current
@magpieloans/magpie-agentv0.1.4 constructor takes aKeypairdirectly (new MagpieAgent({ keypair })) and signs its x402 payment transfers and Ed25519 exit-order envelopes internally. So a clean in-tree wrapper needs one of:BaseWallet-compatible constructor in the Magpie SDK — accept an external signer (signTransaction+signMessage) instead of a rawKeypair. We (Magpie) are happy to ship this so the SAK action never touches a private key and stays compatible with embedded/MPC wallets. This keeps SAK's custody model intact.Keypairfrom aKeypairWallet), which we'd rather avoid because it breaks for non-keypair wallets.We'd like maintainer guidance on the preferred path before opening a PR, so the integration matches SAK's wallet abstraction cleanly rather than reaching around it. Option 1 is our default and we can have the SDK change ready quickly; then the
plugin-defi/src/magpie/action+tools PR follows the exact Lulo/Lavarage file layout (actions/*.tsAction objects +tools/*.ts+ registration inplugin-defi/src/index.ts).Happy to implement the full PR — just confirming the wallet-bridge approach you'd prefer so it's right the first time.