@loop-protocol/sdk
SDK Documentation
TypeScript SDK for building on Loop Protocol — value capture infrastructure for AI agents on Solana.
Installation
bash
npm install @loop-protocol/sdk
# or
yarn add @loop-protocol/sdk
# or
pnpm add @loop-protocol/sdkQuick Start
Connect, wrap USDC to Cred, and start stacking for yield.
typescript
import { Loop, Cred, Vault } from "@loop-protocol/sdk";
import { Connection, Keypair } from "@solana/web3.js";
// Initialize
const connection = new Connection("https://api.mainnet-beta.solana.com");
const wallet = Keypair.generate(); // Use your wallet
const loop = new Loop({ connection, wallet });
// Wrap USDC to Cred (1:1)
const wrapTx = await loop.cred.wrap({
amount: 100_000_000, // 100 USDC (6 decimals)
});
console.log("Wrapped:", wrapTx);
// Stack Cred for yield
const stackTx = await loop.vault.stack({
amount: 100_000_000, // 100 Cred
lockPeriod: 30, // 30 days
});
console.log("Stacked:", stackTx);
// Check position
const position = await loop.vault.getPosition(wallet.publicKey);
console.log("APY:", position.currentApy);Configuration
[MAINNET]
typescript
const loop = new Loop({
connection,
wallet,
cluster: "mainnet-beta",
});[DEVNET]
typescript
const loop = new Loop({
connection,
wallet,
cluster: "devnet",
});Vaults
Core primitive for value custody. Each user has a personal vault managed by their agent within on-chain policy constraints.
typescript
// Initialize a vault
const initTx = await loop.vault.initialize({
owner: wallet.publicKey,
agent: agentPublicKey,
policy: {
dailyLimit: 1000_000_000, // 1000 Cred
autoStack: true,
requireUserAbove: 500_000_000,
},
});
// Get vault info
const vault = await loop.vault.get(wallet.publicKey);
console.log("Balance:", vault.credBalance);
console.log("Staked:", vault.stakedAmount);
console.log("Agent:", vault.agent);Cred Token
Protocol's stable unit of account, backed 1:1 by USDC.
typescript
// Wrap USDC → Cred
const wrapTx = await loop.cred.wrap({
amount: 100_000_000, // 100 USDC
destination: vaultAddress, // Optional: direct to vault
});
// Unwrap Cred → USDC
const unwrapTx = await loop.cred.unwrap({
amount: 50_000_000, // 50 Cred
});
// Check balance
const balance = await loop.cred.getBalance(wallet.publicKey);Stacking
Stack Cred to earn yield from protocol fees. Longer lock periods = higher APY.
typescript
// Stack with lock period
const stackTx = await loop.vault.stack({
amount: 1000_000_000, // 1000 Cred
lockPeriod: 90, // 90 days for bonus APY
});
// Unstake (after lock expires)
const unstakeTx = await loop.vault.unstake({
amount: 500_000_000,
});
// Claim yield
const claimTx = await loop.vault.claimYield();
// Get staking info
const position = await loop.vault.getPosition(wallet.publicKey);
console.log({
staked: position.stakedAmount,
apy: position.currentApy,
pendingYield: position.pendingYield,
unlockDate: position.unlockDate,
});Service Agents
Register agents with bonding curve tokens.
typescript
// Register a new agent
const registerTx = await loop.agents.register({
name: "ShopCapture Pro",
capabilities: ["shopping_capture", "data_licensing"],
feePercentage: 5, // 5% of captured value
metadata: {
description: "Captures value from retail purchases",
website: "https://shopcapture.ai",
},
});
// Get agent info
const agent = await loop.agents.get(agentPublicKey);
console.log("Token Price:", agent.tokenPrice);
console.log("Subscribers:", agent.subscriberCount);
// Subscribe to an agent
const subscribeTx = await loop.agents.subscribe({
agent: agentPublicKey,
vault: vaultAddress,
});
// Buy agent tokens (bonding curve)
const buyTx = await loop.agents.buyTokens({
agent: agentPublicKey,
amount: 100,
maxPrice: 1_500_000, // Slippage protection
});Program IDs
Deployed program addresses on Solana mainnet.
| Program | Address |
|---|---|
| CRED | HYQJwCJ5wH9o4sb9sVPyvSSeY9DtsznZGy2AfpiBaBaG |
| VAULT | J8HhLeRv5iQaSyYQBXJoDwDKbw4V8uA84WN93YrVSWQT |
| SHOPPING | HiewKEBy6YVn3Xi5xdhyrsfPr3KjKg6Jy8PXemyeteXJ |
| Cred Mint | 9GQMCAK3MpZF1hEbwqA9d4mRGtippGV9hyr8fxmz6eA |