Smart Contracts
Technical reference for Siprifi protocol smart contracts. All contracts are deployed on Ethereum mainnet and verified on Etherscan.
All contracts are written in Solidity ^0.8.24 and use OpenZeppelin libraries for security.
Contract Addresses
Configure these addresses in your environment variables:
| Contract | Environment Variable |
|---|---|
| PredictionMarketCDS | NEXT_PUBLIC_MARKET_ADDRESS |
| SiprifiVault | NEXT_PUBLIC_VAULT_ADDRESS |
| SiprifiLending | NEXT_PUBLIC_LENDING_ADDRESS |
| SiprifiCredit (SPC) | NEXT_PUBLIC_CREDIT_ADDRESS |
| SiprifiNAVEngine | NEXT_PUBLIC_NAV_ENGINE_ADDRESS |
| SiprifiRiskEngine | NEXT_PUBLIC_RISK_ENGINE_ADDRESS |
PredictionMarketCDS
The core market contract that handles market creation, YES/NO token minting, resolution, and claiming.
Market Struct
solidity
struct Market {
address issuer; // Market creator
string eventName; // Description of credit event
uint256 maturity; // Unix timestamp
uint256 collateralETH; // Total ETH locked
uint256 yesIssued; // Total YES tokens minted
bool resolved; // Resolution status
uint8 outcome; // 0=NO wins, 1=YES wins
address yesToken; // YES ERC-20 address
address noToken; // NO ERC-20 address
uint8 status; // Market status enum
}Key Functions
solidity
// Create a new CDS market
function createMarket(
string memory eventName,
uint256 maturity
) external payable returns (uint256 marketId);
// Buy YES tokens (exactly 0.1 ETH)
function buyYes(uint256 id) external payable;
// Resolve market (issuer only, after maturity)
function resolve(uint256 id, uint8 outcome) external;
// Claim winnings after resolution
function claim(uint256 id) external;Constants
| Constant | Value | Description |
|---|---|---|
| YES_PRICE | 0.1 ether | Cost per YES token |
SiprifiVault
Manages user deposits and calculates Effective Borrowing Power (EBP).
solidity
// Deposit tokens into vault
function deposit(address token, uint256 amount) external;
// Withdraw tokens from vault
function withdraw(address token, uint256 amount) external;
// Get user's Effective Borrowing Power
function getEBP(address user) external view returns (uint256);
// Get user's deposit balance
function deposits(address user, address token)
external view returns (uint256);SiprifiLending
Enables borrowing sipUSD (SPC) against deposited collateral.
solidity
// Borrow sipUSD against collateral
function borrow(uint256 amount) external;
// Repay borrowed sipUSD
function repay(uint256 amount) external;
// Get user's debt
function debt(address user) external view returns (uint256);
// Get user's health factor
function healthFactor(address user) external view returns (uint256);SiprifiCredit (SPC)
The protocol's credit token, an ERC-20 used for borrowing and lending.
solidity
// Standard ERC-20 functions
function transfer(address to, uint256 amount) external returns (bool);
function approve(address spender, uint256 amount) external returns (bool);
function balanceOf(address account) external view returns (uint256);
function totalSupply() external view returns (uint256);
// Minting/burning (restricted)
function mint(address to, uint256 amount) external;
function burn(address from, uint256 amount) external;MarketToken
ERC-20 token contract used for YES and NO tokens. Each market creates two instances.
solidity
contract MarketToken is ERC20 {
address public market; // PredictionMarketCDS address
// Only market contract can mint/burn
function mint(address to, uint256 amount) external;
function burn(address from, uint256 amount) external;
}SiprifiNAVEngine
Calculates Net Asset Value for users based on their vault deposits.
solidity
// Get user's NAV in USD and ETH
function getNAV(address user) external view returns (
uint256 navUSD,
uint256 navETH
);Integration Example
Here's how to integrate with Siprifi contracts using wagmi/viem:
typescript
import { useWriteContract, useReadContract } from 'wagmi';
import { parseEther } from 'viem';
// Read market data
const { data: market } = useReadContract({
address: MARKET_ADDRESS,
abi: PREDICTION_MARKET_CDS_ABI,
functionName: 'markets',
args: [BigInt(marketId)],
});
// Buy YES tokens
const { writeContract } = useWriteContract();
writeContract({
address: MARKET_ADDRESS,
abi: PREDICTION_MARKET_CDS_ABI,
functionName: 'buyYes',
args: [BigInt(marketId)],
value: parseEther('0.1'),
});Security Note: Always verify contract addresses before interacting. Never approve unlimited token allowances.