@dexter_agent/smart-accounts-sdk
v0.2.51
Published
TypeScript SDK for Dexter Smart Accounts
Downloads
260
Maintainers
Readme
Dexter Smart Accounts SDK
A TypeScript SDK for interacting with Dexter Smart Accounts on Sui.
Installation
npm install @dexter/smart-accounts-sdkQuick Start
import { Transaction } from "@mysten/sui/transactions";
import { SuiClient } from "@mysten/sui/client";
import { DexterSdk } from "@dexter/smart-accounts-sdk";
// Initialize the Sui client and SDK
const client = new SuiClient({ url: "https://fullnode.mainnet.sui.io:443" });
const dexter = new DexterSdk(client);
// Create a transaction
const txb = new Transaction();
// Create a smart account
const { ownerCap } = dexter.account.create(txb, {
activationFee: "coinObjectId",
});
// Add a strategy
dexter.account.addStrategy(txb, {
account: "accountId",
ownerCap,
strategyName: "myStrategy",
clock: "0x6",
});
// Deposit assets with automatic rebalance to highest APR protocol
await dexter.account.deposit(txb, {
account: "accountId",
ownerCap,
coin: "coinObjectId",
strategyName: "myStrategy",
assetType: "0x2::sui::SUI",
});
// Execute the transaction
const result = await client.signAndExecuteTransaction({
signer: keypair,
transaction: txb,
});Auto-Rebalance Feature
The SDK now includes automatic rebalancing to the protocol with the highest APR when depositing assets:
import { STRATEGY_API_URL } from "@dexter/smart-accounts-sdk";
// Deposit with auto-rebalance (uses default strategy API)
await dexter.account.deposit(txb, {
account: "accountId",
ownerCap,
coin: "coinObjectId",
strategyName: "wal-multi-lend",
assetType:
"0x356a26eb9e012a68958082340d4c4116e7f55615cf27affcff209cf0ae544f59::wal::WAL",
});
// Deposit with custom strategy API
await dexter.account.deposit(
txb,
{
account: "accountId",
ownerCap,
coin: "coinObjectId",
strategyName: "wal-multi-lend",
assetType:
"0x356a26eb9e012a68958082340d4c4116e7f55615cf27affcff209cf0ae544f59::wal::WAL",
},
"https://custom-api.example.com/strategy/latest"
);
// Fetch strategy data manually
const strategyData = await dexter.account.getLatestStrategy(
STRATEGY_API_URL,
"0x356a26eb9e012a68958082340d4c4116e7f55615cf27affcff209cf0ae544f59::wal::WAL"
);
console.log(
`Best protocol: ${strategyData.rankings[0].protocol} (${strategyData.rankings[0].apy}% APR)`
);Agent Operations
// Comprehensive rebalance between protocols
await dexter.agent.rebalance(
txb,
{
account: "accountId",
strategyName: "wal-multi-lend",
fromAdapter: "scallop",
toAdapter: "suilend",
assetType:
"0x356a26eb9e012a68958082340d4c4116e7f55615cf27affcff209cf0ae544f59::wal::WAL",
},
ownerCap
);Data Fetching
import { SuiClient } from "@mysten/sui/client";
const client = new SuiClient({ url: "https://fullnode.mainnet.sui.io:443" });
const dexter = new DexterSdk(client);
// Fetch user's accounts
const ownerCaps = await dexter.account.fetchOwnerCaps("0xuser_address");
for (const ownerCap of ownerCaps) {
const accountData = await dexter.account.fetchAccount(ownerCap);
console.log("Account:", accountData?.objectId);
}API Reference
Account Methods
create(txb, args)- Create smart accountaddStrategy(txb, args)- Add strategy to accountdeposit(txb, args, strategyApiUrl?)- Deposit assets with auto-rebalancewithdraw(txb, args)- Withdraw assetsgetLatestStrategy(strategyApiUrl, assetType)- Fetch latest protocol rankingsfetchOwnerCaps(userAddress)- Fetch user's accountsfetchAccount(ownerCap)- Fetch account data
Agent Methods
rebalance(txb, args, ownerCap?)- Comprehensive rebalance between protocolsissueTicket(txb, args)- Issue transfer ticketaddAssetToTicket(txb, args)- Add assets to ticketconsumeTicketAssets(txb, args)- Consume ticket assetsfinalizeTicketConsumption(txb, args)- Finalize ticket
Config Methods (Admin only)
addPolicy(txb, args)- Add policyaddStrategy(txb, args)- Add strategyaddAgent(txb, args)- Add agent to whitelist
License
MIT
