@townsq/mm-sdk
v1.7.0
Published
TownSquare Money Market SDK for interacting with lending, borrowing, and liquidation logic.
Downloads
1,220
Maintainers
Readme
🏛️ TownSquare MM SDK
@townsq-mm-sdk is the official SDK for interacting with the liquidation functionality of the TownSquare lending protocol.
⚠️ This initial release focuses exclusively on loan liquidation. Additional features like supplying, borrowing, and repayment will be added in future updates.
🚀 Features
- Check loan health using protocol data
- Prepare and execute liquidation transactions
- Fully TypeScript-compatible with EVM support
📦 Installation
Install with npm or yarn:
npm install @townsq-mm-sdk
# or
yarn add @townsq-mm-sdk🛠️ Quickstart
This example shows how to connect the SDK and execute a loan liquidation.
- Initialize the SDK
import { TSCore, NetworkType } from '@townsq-mm-sdk';
TSCore.init({
network: NetworkType.MAINNET,
provider: { evm: {} },
});
TSCore.setNetwork(NetworkType.MAINNET);- Set Up a Signer
import { createWalletClient, http } from 'viem';
import { CHAIN_VIEM, TS_CHAIN_ID } from '@townsq-mm-sdk';
const signer = createWalletClient({
chain: CHAIN_VIEM[TS_CHAIN_ID.MONAD],
transport: http(), // You can also pass a custom RPC URL
});
TSCore.setTSsSigner({
signer,
tsChainId: TS_CHAIN_ID.MONAD,
});- Get Account ID and Loan Info
import { TSAccount, TSLoan } from '@townsq-mm-sdk';
const userAddress = '0xYourWalletAddressHere';
const accountId = await TSAccount.read.getAccountIdOfAddressOnChain(userAddress);
// Replace with an actual violator loan ID
const violatorLoanId = '0x...';
const loanData = await TSLoan.read.retrieveUserLoan([violatorLoanId]);- Prepare and Execute Liquidation
import {
MAINNET_TS_TOKEN_ID,
parseUnits,
convertToGenericAddress,
ChainType,
} from '@townsq-mm-sdk';
const prepareCall = await TSLoan.prepare.liquidate(
accountId,
'0xYourLiquidatorLoanId',
violatorLoanId,
MAINNET_TS_TOKEN_ID.USDC,
MAINNET_TS_TOKEN_ID.MON,
parseUnits('100', 18),
parseUnits('0', 18),
convertToGenericAddress('0xYourRecipient', ChainType.EVM)
);
const tx = await TSLoan.write.liquidate(accountId, prepareCall);
console.log(`Liquidation sent: ${tx}`);