Developers
TypeScript SDK
Instruction builders and account decoders for every VYLO program.
Package#
The client lives in the VYLO monorepo as @vylo/solana. @vylo/solana/programs exports a builder for every instruction and a decoder for every account. It depends only on @solana/web3.js.
Swap on a VYLO pool#
typescript
import { Connection, PublicKey, Transaction } from "@solana/web3.js";
import { cpmmPoolAddress, decodeCpmmPool, cpmmQuote, cpmmSwap } from "@vylo/solana/programs";
const CPMM = new PublicKey("8y8iTACBBkZM87URNoPvpsGRe7it2QtxqT6gxwebTkbA");
const address = cpmmPoolAddress(CPMM, mintA, mintB, 30); // 0.30% tier
const pool = decodeCpmmPool(address, (await conn.getAccountInfo(address))!.data)!;
const reserveA = (await conn.getTokenAccountBalance(pool.vaultA)).value.amount;
const reserveB = (await conn.getTokenAccountBalance(pool.vaultB)).value.amount;
const q = cpmmQuote(pool, BigInt(reserveA) - pool.protocolA, BigInt(reserveB) - pool.protocolB, 1_000_000n);
const ix = cpmmSwap(CPMM, wallet.publicKey, pool, pool.mintA, 1_000_000n, (q.out * 995n) / 1000n); // 0.5% slippage
await wallet.sendTransaction(new Transaction().add(ix), conn);Stake and claim#
typescript
import { stakingPoolAddress, stakePositionAddress, decodeStakingPool, stakingStake, stakingClaim } from "@vylo/solana/programs";
const addr = stakingPoolAddress(STAKING);
const pool = decodeStakingPool(addr, (await conn.getAccountInfo(addr))!.data)!;
const id = BigInt(Date.now()); // one position per lock
const stake = stakingStake(STAKING, owner, pool, id, 1_000_000_000n, 180 * 86_400); // 180 day lock, 1.48x
const position = stakePositionAddress(STAKING, owner, id);
const claimUsdc = stakingClaim(STAKING, owner, pool, position, 0); // reward index 0Create an Agent Vault#
typescript
import { agentVaultCreate, agentVaultDeposit, agentVaultAddress } from "@vylo/solana/programs";
const policy = {
agent: agentKey,
expiry: Math.floor(Date.now() / 1000) + 30 * 86400, // 30 days
reserveBps: 2000, // 20% never deployed
mints: [{ mint: USDC, maxTx: 1_000_000_000n, maxDaily: 5_000_000_000n }],
pools: [poolAddress],
};
const createIx = agentVaultCreate(AGENT_VAULT, owner, 1n, policy);
const vault = agentVaultAddress(AGENT_VAULT, owner, 1n);
const depositIx = agentVaultDeposit(AGENT_VAULT, owner, vault, USDC, TOKEN_PROGRAM, 10_000_000_000n);Create a vesting#
typescript
import { lockCreateStream } from "@vylo/solana/programs";
const now = Math.floor(Date.now() / 1000);
const ix = lockCreateStream(LOCK, creator, mint, TOKEN_PROGRAM, {
id: BigInt(Date.now()), recipient, amount: 1_000_000_000n,
start: now, cliff: now + 30 * 86_400, cliffAmount: 100_000_000n, // 10% after 30 days
end: now + 395 * 86_400, period: 86_400, // then daily for a year
cancelable: true, kind: 0, // kind 1 = token lock
});Exports#
| Program | Builders | Decoders |
|---|---|---|
| Pool Factory | cpmmCreatePool, cpmmDeposit, cpmmWithdraw, cpmmSwap, cpmmCollect, cpmmQuote | decodeCpmmPool |
| Staking | stakingStake, stakingUnstake, stakingClaim, stakingExtend, stakingExpire, stakingClose, stakingSync, stakeBoostBps, stakePending | decodeStakingPool, decodeStakePosition |
| VYLO Lock | lockCreateStream, lockWithdraw, lockCancel, lockCloseStream, lockCreateDrop, lockAddRecipients, lockClaimDrop, lockClawback, lockSweepTokens, lockSweepSol, streamUnlocked, tokenFee | decodeStream, decodeDrop, decodeClaim |
| Buyback | buybackInit, buybackSetVyloMint, buybackExecute, buybackSetBurn, buybackBurn | decodeBuybackConfig |
| Agent Vault | agentVaultCreate, agentVaultUpdatePolicy, agentVaultSetAgent, agentVaultSetPaused, agentVaultDeposit, agentVaultWithdraw, agentVaultLiquidity, agentVaultSwap | decodeAgentVault |
| Fee Router | feeRouterInitialize, feeRouterRouteFees, feeRouterSetPaused, feeRouterProposeDestinations | decodeFeeRouterConfig |