Skip to main content

Smart Contract Reference

This page provides a comprehensive technical reference for developers who want to interact with PredMart's smart contracts programmatically. It covers contract addresses, the complete ABI reference, all public functions, events, and integration patterns.


Contract Addresses

ContractNetworkChain IDAddress
PredMart Lending Pool (Proxy)Polygon Mainnet1370xD90D012990F0245cAD29823bdf0B4C9AF207d9ee
USDC.ePolygon Mainnet1370x2791Bca1f2de4661ED88A30C99A7a9449Aa84174
CTF (ERC-1155)Polygon Mainnet1370x4D97DCd97eC945f40cF65F87097ACe5EA0476045

The lending pool is deployed behind a UUPS proxy — always interact with the proxy address, not the implementation address. The proxy delegates all calls to the current implementation.


Core Functions

ERC-4626 Vault (Lending)

These functions follow the ERC-4626 standard and are used by lenders to supply and withdraw USDC.

deposit(uint256 assets, address receiver) → uint256 shares

Deposits USDC into the lending pool and mints pUSDC vault shares to the receiver.

ParameterTypeDescription
assetsuint256Amount of USDC to deposit (6 decimals)
receiveraddressAddress to receive the minted pUSDC shares
Returnsuint256Number of pUSDC shares minted

Requirements:

  • Caller must have approved the pool to spend at least assets USDC
  • Protocol must not be paused

mint(uint256 shares, address receiver) → uint256 assets

Mints a specific number of pUSDC shares by depositing the required USDC.

ParameterTypeDescription
sharesuint256Number of pUSDC shares to mint
receiveraddressAddress to receive the minted shares
Returnsuint256Amount of USDC deposited

withdraw(uint256 assets, address receiver, address owner) → uint256 shares

Withdraws a specific amount of USDC by burning the required pUSDC shares.

ParameterTypeDescription
assetsuint256Amount of USDC to withdraw
receiveraddressAddress to receive the USDC
owneraddressAddress whose pUSDC shares will be burned
Returnsuint256Number of pUSDC shares burned

Requirements:

  • Sufficient available liquidity in the pool
  • If owner != caller, caller must have sufficient allowance

redeem(uint256 shares, address receiver, address owner) → uint256 assets

Burns a specific number of pUSDC shares and sends the corresponding USDC.

ParameterTypeDescription
sharesuint256Number of pUSDC shares to burn
receiveraddressAddress to receive the USDC
owneraddressAddress whose shares will be burned
Returnsuint256Amount of USDC withdrawn

View Functions

FunctionReturnsDescription
totalAssets()uint256Total USDC in the pool (available + borrowed)
convertToShares(uint256 assets)uint256How many pUSDC shares for a given USDC amount
convertToAssets(uint256 shares)uint256How much USDC for a given number of pUSDC shares
maxDeposit(address)uint256Maximum depositable amount
maxWithdraw(address owner)uint256Maximum withdrawable amount
maxRedeem(address owner)uint256Maximum redeemable shares
previewDeposit(uint256 assets)uint256Preview shares from deposit
previewMint(uint256 shares)uint256Preview assets needed for mint
previewWithdraw(uint256 assets)uint256Preview shares burned for withdrawal
previewRedeem(uint256 shares)uint256Preview assets from redemption

Collateral Management

depositCollateral(uint256 tokenId, uint256 amount)

Deposits Polymarket CTF shares as collateral. The caller must have approved the pool via CTF.setApprovalForAll().

ParameterTypeDescription
tokenIduint256Polymarket outcome token ID
amountuint256Number of shares to deposit

depositCollateralFrom(address from, uint256 tokenId, uint256 amount)

Deposits collateral from another address (requires that address to have approved the pool). Only callable by the relayer.


Borrowing (Meta-Transaction Relay)

borrowViaRelay(BorrowIntent intent, bytes signature, PriceData priceData)

Executes a borrow on behalf of a user using their signed intent and oracle-signed price data. Only callable by the relayer.

BorrowIntent struct:

struct BorrowIntent {
address borrower;
uint256 tokenId;
uint256 amount;
uint256 nonce;
uint256 deadline;
}

PriceData struct:

struct PriceData {
uint256 chainId;
address pool;
uint256 tokenId;
uint256 price; // WAD scale (0 to 1e18)
uint256 timestamp;
uint256 maxBorrow; // USDC units
bytes signature;
}

withdrawViaRelay(WithdrawIntent intent, bytes signature, PriceData priceData)

Withdraws collateral on behalf of a user. Verifies health factor remains >= 1.0 if debt exists.

WithdrawIntent struct:

struct WithdrawIntent {
address borrower;
address to; // Destination address for the withdrawn collateral
uint256 tokenId;
uint256 amount;
uint256 nonce;
uint256 deadline;
}

Repayment

repay(uint256 tokenId, uint256 amount)

Repays outstanding debt for a position. The caller transfers USDC to the pool and borrow shares are burned.

ParameterTypeDescription
tokenIduint256Token ID of the position to repay
amountuint256Amount of USDC to repay (use type(uint256).max for full repayment)

Requirements:

  • Caller must have approved the pool to spend USDC
  • The position must have outstanding debt

Liquidation

liquidate(address borrower, uint256 tokenId, uint256 repayAmount, PriceData priceData)

Liquidates an unhealthy position. Only callable by the relayer.

ParameterTypeDescription
borroweraddressAddress of the borrower being liquidated
tokenIduint256Token ID of the position
repayAmountuint256Amount of debt to repay
priceDataPriceDataOracle-signed price data

Behavior:

  • If above water (collateral value >= debt): Uses close factor (50% or 100%) and liquidation bonus (5%)
  • If underwater (collateral value < debt): Seizes all collateral at 10% discount, absorbs bad debt

Market Resolution

resolveMarket(uint256 tokenId, ResolutionData resolutionData)

Registers that a market has resolved. Callable by anyone.

ResolutionData struct:

struct ResolutionData {
uint256 chainId;
address pool;
uint256 tokenId;
bool won;
uint256 timestamp;
bytes signature;
}

redeemWonCollateral(uint256 tokenId, bytes32 conditionId, uint256 indexSet)

Redeems winning CTF shares for USDC through the CTF contract. Callable by anyone.

settleRedemption(address borrower, uint256 tokenId)

Settles a borrower's position after winning collateral has been redeemed. Repays debt from proceeds and sends surplus to borrower. Callable by anyone.

closeResolvedPosition(address borrower, uint256 tokenId)

Closes a position backed by a losing token. Writes off debt as bad debt. Callable by anyone.


View Functions (Position Data)

FunctionReturnsDescription
getPosition(address, uint256)PositionCollateral amount, borrow shares, timestamp
getDebt(address, uint256)uint256Current debt including accrued interest
getHealthFactor(address, uint256, uint256 price)uint256Health factor at given price (WAD)
getLTV(uint256 price)uint256LTV ratio at given price (WAD)
getLiquidationThreshold(uint256 price)uint256Liquidation threshold at price (WAD)
totalBorrowAssets()uint256Total outstanding borrows including interest
totalBorrowShares()uint256Total borrow share tokens
totalBorrowedPerToken(uint256)uint256Total borrowed against a specific token
borrowNonce(address)uint256Current borrow nonce for an address
withdrawNonce(address)uint256Current withdraw nonce for an address
tokenFrozen(uint256)boolWhether a token is frozen
marketResolved(uint256)boolWhether a market has been resolved
marketWon(uint256)boolWhether a resolved market was won
paused()boolWhether the protocol is paused
admin()addressCurrent admin address
relayer()addressCurrent relayer address
oracle()addressCurrent oracle address
poolCapBps()uint256Current pool cap in basis points
reserves()uint256Accumulated protocol reserves
unsettledRedemptions(uint256)RedemptionRedemption tracking for won markets

Redemption Struct

When winning collateral is redeemed via redeemWonCollateral(), the protocol tracks the redemption proceeds for subsequent per-borrower settlement:

struct Redemption {
bool redeemed; // Whether CTF shares have been redeemed for USDC
uint256 totalShares; // Total CTF shares that were redeemed
uint256 usdcReceived; // Actual USDC received from the CTF contract
}

This struct is stored in unsettledRedemptions[tokenId] and is consumed by settleRedemption() to proportionally distribute USDC to each borrower based on their share of the total collateral.


Events

Collateral & Borrowing Events

event CollateralDeposited(address indexed borrower, uint256 indexed tokenId, uint256 amount);
event CollateralWithdrawn(address indexed borrower, uint256 indexed tokenId, uint256 amount);
event Borrowed(address indexed borrower, uint256 indexed tokenId, uint256 amount);
event Repaid(address indexed borrower, uint256 indexed tokenId, uint256 amount);

Liquidation Events

event Liquidated(
address indexed liquidator,
address indexed borrower,
uint256 indexed tokenId,
uint256 collateralSeized,
uint256 debtRepaid
);
event BadDebtAbsorbed(address indexed borrower, uint256 indexed tokenId, uint256 amount);

Market Resolution Events

event MarketResolvedEvent(uint256 indexed tokenId, bool won);
event PositionClosed(address indexed borrower, uint256 indexed tokenId, uint256 badDebt);
event CollateralRedeemed(uint256 indexed tokenId, uint256 sharesRedeemed, uint256 usdcReceived);
event RedemptionSettled(
address indexed borrower,
uint256 indexed tokenId,
uint256 debtRepaid,
uint256 surplusToUser
);

Interest & Reserves Events

event InterestAccrued(uint256 interest, uint256 reserve);
event ReservesWithdrawn(address indexed to, uint256 amount);

Admin Events

event OracleUpdated(address indexed oldOracle, address indexed newOracle);
event AnchorsUpdated();
event PausedStateChanged(bool paused);
event TokenFrozenEvent(uint256 indexed tokenId, bool frozen);
event TimelockActivated(uint256 delay);
event PoolCapUpdated(uint256 newCapBps);
event RelayerUpdated(address indexed oldRelayer, address indexed newRelayer);

Governance (Timelock) Events

event OracleChangeProposed(address indexed newOracle, uint256 executeAfter);
event OracleChangeCancelled();
event AnchorsChangeProposed(uint256 executeAfter);
event AnchorsChangeCancelled();
event UpgradeProposed(address indexed newImplementation, uint256 executeAfter);
event UpgradeCancelled();

ERC-4626 Vault Events

// Inherited from ERC-4626/ERC-20 standards
event Deposit(address indexed sender, address indexed owner, uint256 assets, uint256 shares);
event Withdraw(address indexed sender, address indexed receiver, address indexed owner, uint256 assets, uint256 shares);
event Transfer(address indexed from, address indexed to, uint256 value);
event Approval(address indexed owner, address indexed spender, uint256 value);

EIP-712 Domain

PredMart uses EIP-712 typed structured data for signing borrow and withdraw intents:

EIP712Domain({
name: "Predmart Lending Pool",
version: "0.8.0",
chainId: 137, // Polygon Mainnet
verifyingContract: 0xD90D012990F0245cAD29823bdf0B4C9AF207d9ee
})

BorrowIntent Type Hash

BorrowIntent(address borrower,uint256 tokenId,uint256 amount,uint256 nonce,uint256 deadline)

WithdrawIntent Type Hash

WithdrawIntent(address borrower,address to,uint256 tokenId,uint256 amount,uint256 nonce,uint256 deadline)

REST API Endpoints for Developers

PredMart provides a comprehensive REST API at https://api.predmart.com. Full interactive documentation is available at api.predmart.com/docs (Swagger UI).

Key Endpoints

EndpointMethodDescription
/lending/pool-statsGETPool TVL, utilization, rates
/lending/position/{address}/{token_id}GETSingle position with risk metrics
/lending/positions/{address}GETAll positions for a wallet
/lending/events/{address}GETLending event history
/lending/liquidations/{address}GETLiquidation history
/lending/rate-historyGETHistorical rate data
/lending/depth-statusGETDepth gate status per token
/lending/constantsGETContract addresses and protocol params
/oracle/borrow-intent/{borrower}/{token_id}/{amount}GETEIP-712 data for borrow signing
/oracle/borrow-relayPOSTSubmit signed borrow intent
/oracle/withdraw-intent/{borrower}/{to}/{token_id}/{amount}GETEIP-712 data for withdraw signing
/oracle/withdraw-relayPOSTSubmit signed withdraw intent
/healthGETSimple health check
/health/detailedGETDetailed system health status

Integration Example: Reading a Position

// Using ethers.js v6
import { Contract, JsonRpcProvider } from 'ethers';

const POOL_ADDRESS = '0xD90D012990F0245cAD29823bdf0B4C9AF207d9ee';
const provider = new JsonRpcProvider('https://polygon-rpc.com');

const pool = new Contract(POOL_ADDRESS, [
'function getPosition(address, uint256) view returns (uint256 collateralAmount, uint256 borrowShares, uint256 lastDepositTimestamp)',
'function getDebt(address, uint256) view returns (uint256)',
'function getHealthFactor(address, uint256, uint256) view returns (uint256)',
'function totalAssets() view returns (uint256)',
'function totalBorrowAssets() view returns (uint256)',
], provider);

// Read a position
const [collateral, shares, _] = await pool.getPosition(borrowerAddress, tokenId);
const debt = await pool.getDebt(borrowerAddress, tokenId);

// Get health factor at a specific price (WAD scale)
const price = ethers.parseUnits('0.65', 18); // $0.65
const healthFactor = await pool.getHealthFactor(borrowerAddress, tokenId, price);

console.log(`Collateral: ${collateral} shares`);
console.log(`Debt: ${ethers.formatUnits(debt, 6)} USDC`);
console.log(`Health Factor: ${ethers.formatUnits(healthFactor, 18)}`);

Deployment Details

PropertyValue
Solidity Pragma^0.8.24
Compiler Version0.8.27
Protocol Version0.8.0
OptimizerEnabled, 1 run
via_irEnabled
Proxy PatternUUPS (ERC-1967)
FrameworkFoundry
NetworkPolygon (EVM-compatible)

Next Steps