TL;DR: Starkzap just shipped five new DeFi primitives as first-class TypeScript APIs: token swaps (AVNU + Ekubo), dollar-cost averaging, lending/borrowing (Vesu), multi-chain bridging (Ethereum + Solana), and ZK-powered confidential transfers (Tongo). Every feature works with the same wallet abstraction the SDK already used for staking and gasless transactions.
What Starkzap Is
Starkzap is a TypeScript SDK that abstracts the rough edges of building on Starknet. The first release covered wallet onboarding, ERC20 transfers, STRK staking, a fluent transaction builder, AVNU paymaster support for gasless transactions, and social login via Privy and Cartridge.
This release adds the DeFi layer: everything an app needs to let users swap, accumulate positions over time, lend idle assets, bridge in from Ethereum or Solana, and send funds without revealing amounts.
1. Token Swaps
Two swap providers ship out of the box: AVNU (a DEX aggregator that routes across multiple protocols) and Ekubo (Starknet's concentrated liquidity AMM). Both implement a common SwapProvider interface, so you can swap providers or combine them without changing your app code.
Register providers
import { StarkZap, AvnuSwapProvider, EkuboSwapProvider } from "starkzap";
const sdk = new StarkZap({ network: "mainnet" });
const wallet = await sdk.connectWallet({
account: { signer, accountClass: ArgentPreset },
swapProviders: [new AvnuSwapProvider(), new EkuboSwapProvider()],
defaultSwapProviderId: "avnu",
});
Get a quote
import { getPresets, Amount } from "starkzap";
const { STRK, USDC } = getPresets(wallet.getChainId());
const quote = await wallet.getQuote({
tokenIn: STRK,
tokenOut: USDC,
amountIn: Amount.parse("100", STRK),
});
console.log(quote.amountOutBase); // bigint in USDC base units
console.log(quote.priceImpactBps); // basis points, e.g. 12n = 0.12%
console.log(quote.provider); // "avnu" or "ekubo"
Execute a swap
const tx = await wallet.swap(
{
tokenIn: STRK,
tokenOut: USDC,
amountIn: Amount.parse("100", STRK),
slippageBps: 50n, // 0.5% max slippage
},
{ feeMode: "sponsored" }, // optional
);
await tx.wait();
Batching a swap with other calls
Swaps execute via wallet.swap(). To combine a swap with follow-up actions atomically, run the swap first then chain further operations with the tx builder:
// 1. Execute swap
const txSwap = await wallet.swap({
tokenIn: STRK,
tokenOut: USDC,
amountIn: Amount.parse("100", STRK),
});
await txSwap.wait();
// 2. Batch follow-up actions (e.g. deposit received USDC into lending)
const tx = await wallet
.tx()
.lendDeposit({ token: USDC, amount: Amount.parse("50", USDC) })
.send();
await tx.wait();
What this unlocks for your users: Any in-app marketplace, token sale, or reward claiming flow can now offer a "swap to desired token" step without sending users to an external DEX. Showing quote.amountOutBase and quote.priceImpactBps before execution gives users a clear preview before they commit.
2. Dollar-Cost Averaging (DCA)
DCA lets users schedule recurring swaps at the protocol level. Two providers ship out of the box:
-
AvnuDcaProviderdiscrete periodic swaps executed on a schedule via AVNU's DCA contracts. Supports optionalminBuyAmountBase/maxBuyAmountBaseprice guards per cycle. -
EkuboDcaProvidercontinuous streaming via Ekubo's TWAMM (Time-Weighted AMM) extension. Tokens are sold continuously over the order window rather than in discrete cycles. Does not support per-cycle price guards.
Orders use ISO 8601 duration strings for frequency ("P1D" = daily, "P1W" = weekly, "PT12H" = every 12 hours).
Register DCA providers
import {
StarkZap,
AvnuSwapProvider,
EkuboSwapProvider,
AvnuDcaProvider,
EkuboDcaProvider,
} from "starkzap";
const sdk = new StarkZap({ network: "mainnet" });
const wallet = await sdk.connectWallet({
account: { signer, accountClass: ArgentPreset },
swapProviders: [new AvnuSwapProvider(), new EkuboSwapProvider()],
defaultSwapProviderId: "avnu",
dcaProviders: [new AvnuDcaProvider(), new EkuboDcaProvider()],
defaultDcaProviderId: "avnu",
});
Create a DCA order (AVNU, discrete, with price guard)
const { USDC, ETH } = getPresets(wallet.getChainId());
const tx = await wallet.dca().create({
tokenIn: USDC,
tokenOut: ETH,
amountInPerCycle: Amount.parse("50", USDC),
frequency: "P1W", // weekly
// AVNU only: optional price guard (raw bigint base units)
maxBuyAmountBase: 50000000000000000n, // don't buy above this ETH amount per cycle
});
await tx.wait();
Create a DCA order (Ekubo TWAMM, continuous streaming)
Switch to EkuboDcaProvider and tokens sell in a continuous stream instead of discrete cycles:
const tx = await wallet.dca().create({
tokenIn: USDC,
tokenOut: ETH,
amountInPerCycle: Amount.parse("50", USDC),
frequency: "P1W",
provider: "ekubo",
// pricingStrategy is NOT supported for Ekubo TWAMM
});
await tx.wait();
Preview what a single cycle would return at current prices
const quote = await wallet.dca().previewCycle({
tokenIn: USDC,
tokenOut: ETH,
amountInPerCycle: Amount.parse("50", USDC),
provider: "avnu", // optional; uses default if omitted
});
console.log(`Each cycle buys ~${quote.amountOutBase} ETH base units`);
List and cancel active orders
const orders = await wallet.dca().getOrders({ provider: "avnu" });
for (const order of orders) {
console.log(order.id, order.tokenIn.symbol, order.tokenOut.symbol, order.frequency);
}
// Cancel by order ID
const tx = await wallet.dca().cancel({ orderId: orders[0].id });
await tx.wait();
What this unlocks for your users: Savings products, subscription-style accumulation ("stack sats weekly"), automated portfolio rebalancing, and loyalty reward programs that convert protocol tokens to stables on a schedule.
3. Lending and Borrowing
The lending module integrates with Vesu, Starknet's permissionless lending protocol. You can deposit collateral, borrow against it, repay, and withdraw, all through the same wallet-centric API. Vesu is registered automatically when the wallet is created; no extra configuration needed.
Deposit to earn yield
const { USDC } = getPresets(wallet.getChainId());
const tx = await wallet.lending().deposit({
token: USDC,
amount: Amount.parse("500", USDC),
// receiver defaults to wallet.address
});
await tx.wait();
Borrow against collateral
const { ETH, USDC } = getPresets(wallet.getChainId());
const tx = await wallet.lending().borrow({
collateralToken: ETH,
debtToken: USDC,
amount: Amount.parse("400", USDC), // amount of debt to borrow
});
await tx.wait();
Check position health
const health = await wallet.lending().getHealth({
collateralToken: ETH,
debtToken: USDC,
});
console.log("Collateralized:", health.isCollateralized); // false = liquidation risk
console.log("Collateral value:", health.collateralValue);
console.log("Debt value:", health.debtValue);
const position = await wallet.lending().getPosition({
collateralToken: ETH,
debtToken: USDC,
});
console.log(position.collateralAmount, position.debtAmount);
console.log("Collateralized:", position.isCollateralized);
Repay debt
const tx = await wallet.lending().repay({
collateralToken: ETH,
debtToken: USDC,
amount: Amount.parse("200", USDC),
withdrawCollateral: false, // optional, keep collateral deposited
});
await tx.wait();
What this unlocks for your users: In-app yield on idle stablecoins, leveraged positions without leaving your app, and "borrow against your token rewards" flows that were previously only possible on standalone lending frontends.
4. Multi-Chain Bridging
The bridge module lets users move tokens from Ethereum or Solana to Starknet. Under the hood it handles four Ethereum protocols (Canonical, CCTP for USDC fast transfers, OFT/LayerZero, and OFT-migrated) and Solana via Hyperlane, you write the same wallet.deposit(...) call regardless.
Configure the SDK
import { StarkZap } from "starkzap";
const sdk = new StarkZap({
network: "mainnet",
bridging: {
ethereumRpcUrl: "https://eth-mainnet.g.alchemy.com/v2/<key>",
solanaRpcUrl: "https://solana-mainnet.g.alchemy.com/v2/<key>",
layerZeroApiKey: "<layerzero-key>", // required for OFT/OFT-migrated routes
},
});
Discover bridgeable tokens
import { ExternalChain } from "starkzap";
// All tokens bridgeable to the current Starknet environment
const allTokens = await sdk.getBridgingTokens();
// Filter by source chain
const ethTokens = await sdk.getBridgingTokens(ExternalChain.ETHEREUM);
const solTokens = await sdk.getBridgingTokens(ExternalChain.SOLANA);
Bridge from Ethereum
import { ConnectedEthereumWallet, ExternalChain, Amount, fromAddress } from "starkzap";
const evmProvider = window.ethereum;
const [evmAddress] = await evmProvider.request({ method: "eth_requestAccounts" });
const evmChainId = await evmProvider.request({ method: "eth_chainId" });
const ethWallet = await ConnectedEthereumWallet.from(
{
chain: ExternalChain.ETHEREUM,
provider: evmProvider,
address: evmAddress,
chainId: evmChainId,
},
wallet.getChainId(), // Starknet chain ID
);
// Estimate fees before committing
const fees = await wallet.getDepositFeeEstimate(selectedToken, ethWallet, {
fastTransfer: true,
});
// Execute the bridge
const tx = await wallet.deposit(
fromAddress(wallet.address),
Amount.parse("100", selectedToken.decimals, selectedToken.symbol),
selectedToken,
ethWallet,
{ fastTransfer: true }, // CCTP fast path (~20 min vs ~8 h)
);
console.log(`Bridge tx: ${tx.hash}`);
Bridge from Solana
import { ConnectedSolanaWallet, ExternalChain } from "starkzap";
const solWallet = await ConnectedSolanaWallet.from(
{
chain: ExternalChain.SOLANA,
provider: solanaProvider, // must implement signAndSendTransaction()
address: solanaAddress,
chainId: solanaChainId,
},
wallet.getChainId(),
);
const tx = await wallet.deposit(
fromAddress(wallet.address),
Amount.parse("50", solBridgeToken.decimals, solBridgeToken.symbol),
solBridgeToken,
solWallet,
);
What this unlocks for your users: Onboarding from any chain in a single flow. A user coming from Coinbase with USDC on Ethereum, or a Solana native, can bridge directly inside your app without navigating to a separate bridge UI.
5. Confidential Transfers
The confidential module wraps the Tongo protocol, which uses zero-knowledge proofs to hide transfer amounts on-chain. All ZK proof generation happens locally in the SDK before submitting transactions, the chain never sees the amount in plaintext.
The Tongo private key is separate from the Starknet wallet key. Your app must create and hold a
TongoConfidentialinstance with the user's Tongo key and the correct Tongo contract address for the chain.
Set up a confidential account
import { StarkZap, TongoConfidential } from "starkzap";
const sdk = new StarkZap({ network: "mainnet" });
const wallet = await sdk.connectWallet({ account: { signer, accountClass } });
const confidential = new TongoConfidential({
privateKey: tongoPrivateKey, // separate from the wallet signing key
contractAddress: TONGO_CONTRACT, // Tongo deployment address for this chain
provider: wallet.getProvider(),
});
// Share recipientId with senders, it's the EC public key { x, y }, not the wallet address
const recipientId = confidential.recipientId;
Check encrypted balance
const state = await confidential.getState();
console.log("Active balance:", state.balance); // spendable
console.log("Pending balance:", state.pending); // needs rollover to become active
console.log("Nonce:", state.nonce);
Fund the confidential account
const { USDC } = getPresets(wallet.getChainId());
const tx = await wallet
.tx()
.confidentialFund(confidential, {
amount: Amount.parse("100", USDC),
sender: wallet.address,
})
.send();
await tx.wait();
Send a confidential transfer
The amount is hidden from all on-chain observers. The recipient is identified by their recipientId ({ x, y }), not their wallet address.
const tx = await wallet
.tx()
.confidentialTransfer(confidential, {
amount: Amount.parse("50", USDC),
to: recipientConfidential.recipientId, // { x, y }
sender: wallet.address,
})
.send();
await tx.wait();
Withdraw back to public ERC20
const tx = await wallet
.tx()
.confidentialWithdraw(confidential, {
amount: Amount.parse("25", USDC),
to: wallet.address,
sender: wallet.address,
})
.send();
await tx.wait();
Rollover and ragequit
Pending balances (received transfers not yet spendable) become active via rollover:
// Activate pending → active balance
const rolloverCalls = await confidential.rollover({ sender: wallet.address });
const tx = await wallet.tx().add(...rolloverCalls).send();
await tx.wait();
To exit the entire confidential balance in one call:
const ragequitCalls = await confidential.ragequit({
to: wallet.address,
sender: wallet.address,
});
const tx = await wallet.tx().add(...ragequitCalls).send();
await tx.wait();
What this unlocks for your users: Payroll and B2B payments where amounts are sensitive, private tipping and donations, confidential DAO compensation, any flow where "how much" is as sensitive as "to whom."
Putting It Together: A Complete Onboarding Flow
All five modules work with the same Wallet instance. Here's how to wire everything up from a single onboard() call:
import {
StarkZap,
OnboardStrategy,
AvnuSwapProvider,
EkuboSwapProvider,
AvnuDcaProvider,
EkuboDcaProvider,
} from "starkzap";
const sdk = new StarkZap({ network: "mainnet" });
// 1. Onboard with Privy (social login)
const onboard = await sdk.onboard({
strategy: OnboardStrategy.Privy,
privy: { resolve: getPrivyContext },
accountPreset: "argentXV050",
deploy: "if_needed",
});
const wallet = onboard.wallet;
// 2. Register swap and DCA providers
wallet.registerSwapProvider(new AvnuSwapProvider());
wallet.registerSwapProvider(new EkuboSwapProvider());
wallet.setDefaultSwapProvider("avnu");
wallet.dca().registerProvider(new AvnuDcaProvider());
wallet.dca().registerProvider(new EkuboDcaProvider());
wallet.dca().setDefaultDcaProvider("avnu");
// 3. Now the wallet can use all modules
await wallet.swap({ ... });
await wallet.dca().create({ ... });
await wallet.lending().deposit({ ... });
await wallet.deposit(recipient, amount, bridgeToken, ethWallet);
// Confidential transfers use TongoConfidential independently (see section 5)
Getting Started
npm install starkzap
Optional dependencies (install only what you use):
# Ethereum bridging
npm install ethers
# Solana bridging
npm install @solana/web3.js @hyperlane-xyz/sdk @hyperlane-xyz/registry @hyperlane-xyz/utils
# Confidential transfers
npm install @fatsolutions/tongo-sdk
- Docs: starkzap.io/docs
- GitHub: github.com/keep-starknet-strange/starkzap
- Examples: awesome-starkzap
- Website: starknet.io
The full feature set, staking, ERC20, tx builder, paymaster, social login, swaps, DCA, lending, bridging, and confidential transfers, runs on both mainnet and Sepolia testnet.
Top comments (0)