@wkalidev/b2s-contracts
v1.2.1
Published
$B2S Token — Smart Contracts & TypeScript SDK for Base2Stacks DeFi on Stacks mainnet
Maintainers
Readme
@wkalidev/b2s-contracts
$B2S Token — TypeScript SDK & Smart Contract addresses for Base2Stacks DeFi on Stacks mainnet.
Why this SDK?
If you're building on Stacks and need to interact with $B2S DeFi contracts (token, staking, liquidity pool, governance, prediction markets), this SDK gives you:
- ✅ All mainnet contract addresses in one place — no more copy-pasting
- ✅ TypeScript-first — full type definitions included
- ✅ Tree-shakeable — ESM + CJS, import only what you need
- ✅ Helper functions — AMM swap math, APY calculator, address utils
- ✅ Client classes —
B2SClient,RewardsClient,OracleClientready to use
Installation
npm install @wkalidev/b2s-contracts
# or
yarn add @wkalidev/b2s-contracts
# or
pnpm add @wkalidev/b2s-contractsDeployed Contracts (Stacks Mainnet)
Deployer: SP936YWJPST8GB8FFRCN7CC6P2YR5K6NNBAARQ96
| Contract | Name | Description |
|----------|------|-------------|
| b2s-token-v4 | $B2S Token | SIP-010 fungible token, 6 decimals |
| b2s-staking-vault-v2 | Staking Vault | 12.5–37.5% APY with lock multipliers |
| b2s-liquidity-pool-v6 | AMM Pool | Constant product AMM, 0.25% fee |
| b2s-rewards-distributor-v3 | Rewards | 5 B2S daily claim |
| b2s-governance | DAO | On-chain proposals & voting |
| b2s-fee-router | Fee Router | Bridge fee collection & distribution |
| b2s-prediction-market | Prediction | AMM-style prediction markets |
| b2s-price-oracle | Oracle | Clarity 4 price feeds |
Quick Start
Get contract addresses
import { CONTRACTS, CONTRACT_NAMES, getContractId } from '@wkalidev/b2s-contracts/contracts'
// Full contract IDs
console.log(CONTRACTS['b2s-token-v4'])
// → 'SP936YWJPST8GB8FFRCN7CC6P2YR5K6NNBAARQ96.b2s-token-v4'
// Get any contract ID
const stakingId = getContractId(CONTRACT_NAMES.STAKING_VAULT)
// → 'SP936YWJPST8GB8FFRCN7CC6P2YR5K6NNBAARQ96.b2s-staking-vault-v2'Read $B2S balance
import { B2SClient } from '@wkalidev/b2s-contracts'
const client = new B2SClient() // defaults to mainnet
const { formatted } = await client.getBalance('SP1ABC...XYZ')
console.log(`Balance: ${formatted} B2S`)AMM swap calculation
import { calcSwapOutput, calcEffectiveApy, calcBridgeFee } from '@wkalidev/b2s-contracts/helpers'
// Calculate swap output (no RPC call needed)
const { amountOut, fee, priceImpact } = calcSwapOutput(
1_000_000n, // 1 B2S in
50_000_000n, // reserve B2S
10_000_000n, // reserve STX
)
// APY based on lock duration
calcEffectiveApy(2100) // → 37.5%
calcEffectiveApy(1050) // → 25%
calcEffectiveApy(0) // → 12.5%
// Bridge fee breakdown
const { totalFeeMicro, toTreasury, toStakers } = calcBridgeFee(1_000_000_000n)Staking rewards
import { RewardsClient } from '@wkalidev/b2s-contracts'
const rewards = new RewardsClient()
const pending = await rewards.getPendingRewards('SP1ABC...XYZ')
console.log(`Pending: ${pending.formatted} B2S`)
const info = await rewards.getStakerInfo('SP1ABC...XYZ')
console.log(`Staked: ${info?.stakedFormatted} B2S`)Price oracle
import { OracleClient } from '@wkalidev/b2s-contracts'
const oracle = new OracleClient()
const { price } = await oracle.getPrice('STX-USD')
console.log(`STX price: $${price}`)Utilities
import {
toMicroUnits,
fromMicroUnits,
formatB2S,
blocksToDuration,
isValidStacksAddress,
truncateAddress,
} from '@wkalidev/b2s-contracts/helpers'
formatB2S(5_000_000n) // → '5.000000 B2S'
blocksToDuration(2100) // → '~14d 0h'
isValidStacksAddress('SP1ABC...') // → true
truncateAddress('SP936YWJ...RQ96') // → 'SP936Y...R96'TypeScript Types
import type {
TokenBalance,
StakePosition,
PoolReserves,
SwapQuote,
BridgeTransaction,
Proposal,
ClaimRecord,
PriceFeed,
Result,
} from '@wkalidev/b2s-contracts/types'Development
git clone https://github.com/wkalidev/b2s-token-contract.git
cd b2s-token-contract
npm install
npm run build
npm testClarity contracts
clarinet check # type-check contracts
clarinet test # run contract testsLive App
base2stacks-tracker.vercel.app — the full DeFi dApp using this SDK on Stacks mainnet.
Contributing
PRs welcome! See CONTRIBUTING.md
License
MIT — © 2026 wkalidev
Built for #StacksBuilderRewards April 2026 🏆
