| name | cdpm-agent-sdk |
| description | TypeScript SDK guide for AI agents managing CDPM positions. Defines permission boundaries, operation workflows, automation strategies, and the Scallop and Kai SAV supply/redeem APIs agents share with owners and protocol bots. Use when building automated liquidity management agents. |
CDPM Agent SDK Guide
Overview
This guide is for AI agents authorized to manage CDPM positions on behalf of users. Agents have limited permissions and operate within specific boundaries.
Package Address: 0x573584cc4698e82fd85f2b54e64ad4cd901c42b768f7628ec167bf2d24aa2aa7 (only-dep-upgrades digest: F5kVa3YDSHoBvJvYJFH9y5dANCJScEdyZoxZLLy6qd15 — cdpm.move bytecode is locked; only dependency-version upgrades are allowed). Other shared object IDs live in reference/constants.md.
import { Transaction } from '@mysten/sui/transactions';
import { SuiGrpcClient } from '@mysten/sui/grpc';
Agent Permission Model
What Agents CAN Do
| Operation | Description |
|---|
| Add Liquidity | Add liquidity using PositionManager balance |
| Remove Liquidity | Remove liquidity and return to balance |
| Collect Fees | Collect fees from position (goes to fee bag) |
| Collect Rewards | Collect rewards (goes to fee bag) |
| Transfer Fee to Balance | Move fees from fee bag to balance |
Scallop scallop_supply | Park idle balance into Scallop |
Scallop scallop_redeem | Pull underlying back; yield fee deducted from interest portion |
Kai SAV kai_supply | Park idle balance into a Kai Vault<T, YT> |
Kai SAV kai_redeem | Pull underlying back via the strategy walk; same yield fee on interest |
What Agents CANNOT Do
| Operation | Reason |
|---|
| Withdraw Funds | Cannot move funds out of PositionManager |
| Close Position | Only owner can close |
| Authorize/Revoke Agents | Only owner can manage agents |
| Modify PositionManager | Cannot change configuration |
Permission Check
function canAgentOperate(
pm: PositionManager,
agentAddress: string
): boolean {
return pm.agents.includes(agentAddress);
}
const { response: pm } = await client.getObject({ id: pmId, include: { content: true } });
const agents = pm?.content?.fields?.agents || [];
const isAuthorized = agents.includes(agentAddress);
Topics
Core Operations
- Agent Operations - Add/remove liquidity, collect fees, transfer fees
- Scallop Lending - Agent-driven
scallop_supply / scallop_redeem (one tx.moveCall each); yield fee shares fee_house.fee_rate with Kai
- Kai SAV Lending - Agent-driven
kai_supply / kai_redeem (one tx.moveCall each); yield fee shares fee_house.fee_rate with Scallop
- Automation Strategies - Auto-compounding, rebalancing, fee collection scheduler
Monitoring & Best Practices
Reference
Calculations
For liquidity calculations, bin price math, position management, and fee calculations, use the cdpm-calculation skill with the Cetus DLMM SDK:
import { BinUtils, FeeUtils } from '@cetusprotocol/dlmm-sdk/utils'
const qPrice = BinUtils.getQPriceFromId(binId, binStep)
const liquidity = BinUtils.getLiquidity(amountA, amountB, qPrice)
const binId = BinUtils.getBinIdFromPrice(price, binStep, true, decimalA, decimalB)
const positionCount = BinUtils.getPositionCount(lowerBinId, upperBinId)
const { amount_a, amount_b } = BinUtils.calculateOutByShare(bin, removeLiquidity)
function distributeLiquidity(totalA: string, totalB: string, bins: number[], binStep: number) {
return bins.map(binId => {
const qPrice = BinUtils.getQPriceFromId(binId, binStep)
const amountA = (BigInt(totalA) / BigInt(bins.length)).toString()
const amountB = (BigInt(totalB) / BigInt(bins.length)).toString()
return { binId, amountA, amountB, liquidity: BinUtils.getLiquidity(amountA, amountB, qPrice) }
})
}
See cdpm-calculation-skill for the full reference (formulas, redemption sizing, distribution math).