DomFiDomination Finance

Contract Reference

All 16 DomFi contracts on Base Mainnet — type, purpose, and BaseScan links.

16 contracts on Base Mainnet. Ten upgradeable via TransparentUpgradeableProxy, six deployed directly.

Upgradeable Contracts

Interact with the proxy address, not the implementation.

ContractPurposeBaseScan
DomfiVaultERC-4626 vault. LPs deposit USDC, act as collective counterparty to all trades.View
DomfiTradingStoragePersistent storage for open trades, pending orders, and trader state.View
DomfiPairInfosPer-pair fee parameters: opening, closing, funding, and rollover fees.View
DomfiPairsStoragePair definitions, group config, leverage limits, collateral ranges.View
DomfiTradingUser-facing entry point: openTrade(), closeTradeMarket(), updateTp(), updateSl().View
DomfiTradingCallbacksExecutes trades after price fulfillment. Calculates PnL, applies fees, settles with vault.View
DomfiOpenPnlTracks unrealized PnL across all open positions. Used by vault for share pricing.View
DomfiTradesUpKeepAutomated position management: liquidations, stop-loss, take-profit.View
DomfiPriceRouterQueues price requests, routes fulfilled prices to callbacks.View
DomfiPrivatePriceUpKeepReceives signed prices from off-chain bot, forwards to PriceRouter.View

Non-Upgradeable Contracts

ContractPurposeBaseScan
DomfiOracleStores latest verified prices per dominance pair.View
DomfiTimelockOwnerTimelock for governance operations with role-based access control.View
ProxyAdminOpenZeppelin ProxyAdmin for managing proxy upgrades.View
DomfiRegistryCentral contract discovery. All contracts register here and resolve each other by name.View
DomfiLockedDepositNftERC-721 NFT representing locked vault deposits with time-based unlock.View
DomfiVerifierVerifies ECDSA signatures on price data from the publisher bot.View

Key Interfaces

Three interfaces cover most integration scenarios.

IDomfiTrading exposes trading entry points: opening and closing positions, updating take-profit and stop-loss. Primary interface for any trading integration.

IDomfiOracle provides read access to the latest verified dominance prices across all five pairs.

IDomfiVault follows ERC-4626 for LP deposits and withdrawals. Use it for vault integrations, yield aggregators, or monitoring vault health.

Key Functions

The 8 functions most integrators call. For full signatures, see verified ABIs on BaseScan.

DomfiTrading

openTrade

Opens a leveraged position on a dominance pair.

function openTrade(
    Trade calldata t,   // Trade struct: pairIndex, collateral, leverage, buy, tp, sl
    uint8 orderType,    // 0 = market, 1 = limit, 2 = stop
    uint256 slippageP   // Slippage tolerance, 2-decimal precision (50 = 0.5%)
) external payable;
ParameterTypeUnitsNotes
t.collateraluint2566 decimals (USDC)$100 = 100000000
t.leverageuint322 decimals50x = 5000, 250x = 25000
t.pairIndexuint160=BTCDOM, 1=ETHDOM, 2=USDTDOM, 3=BNBDOM, 4=SOLDOM
t.buybooltrue = long, false = short
t.tp / t.sluint19218 decimalsSet to 0 for no TP/SL
msg.valuewei~0.00003 ETH oracle fee

Reverts: MaxLeverageExceeded, InsufficientValue, TpTooHigh, MaxOpenInterestExceeded

Note: Approve USDC to DomfiTradingStorage, not DomfiTrading. Execution is asynchronous — listen for MarketOpenExecuted.

closeTradeMarket

Closes an open position at the current oracle price. Supports partial closes.

function closeTradeMarket(
    uint8 pairIndex,
    uint8 index,        // Position index for this pair
    uint256 percentage  // 2-decimal precision: 10000 = 100%, 5000 = 50%
) external payable;

Reverts: NoTrade (position doesn't exist), InsufficientValue (missing oracle fee)

updateTp / updateSl

Updates take-profit or stop-loss on an open position.

function updateTp(uint8 pairIndex, uint8 index, uint192 newTp) external payable;
function updateSl(uint8 pairIndex, uint8 index, uint192 newSl) external payable;

Prices use 18-decimal precision. Set to 0 to remove the trigger. Requires oracle fee as msg.value.

DomfiOracle

getPrice

Returns the latest verified dominance price for a pair.

function getPrice(uint16 pairIndex) external view returns (uint256);

Returns an 18-decimal value. BTCDOM at 52.5% returns 52500000000000000000. This is a view function — no gas cost, no oracle fee.

DomfiVault (ERC-4626)

deposit

Deposits USDC into the vault in exchange for $dfUSDC shares.

function deposit(uint256 assets, address receiver) external returns (uint256 shares);

assets uses 6 decimals (USDC). Approve USDC to the vault address first. Returns the number of $dfUSDC shares minted.

makeWithdrawRequest

Initiates a withdrawal. Locks $dfUSDC during the cool-off period.

function makeWithdrawRequest(uint256 shares) external;

Cool-off is 1-3 epochs (3-9 days) depending on vault collateralization. After cool-off, call completeWithdrawRequest() to claim USDC.

DomfiTradingStorage

openTrades

Reads an open position's data.

function openTrades(address trader, uint8 index) external view returns (Trade memory);

Returns the full Trade struct including entry price, collateral, leverage, and TP/SL levels. View function — no gas cost.

Events

Events are declared in the interface contracts. All events below include their indexed annotations.

DomfiTrading

EventParametersMeaning
MarketOpenOrderInitiatedorderId (indexed), trader (indexed), pairIndex (indexed)User submitted a market open order
MarketCloseOrderInitiatedorderId (indexed), tradeId (indexed), trader (indexed), pairIndex, closePercentageUser submitted a market close order
OpenLimitPlacedtrader (indexed), pairIndex (indexed), index, wantedPriceLimit order placed
OpenLimitUpdatedtrader (indexed), pairIndex (indexed), index, newPrice, newTp, newSlLimit order updated
OpenLimitCanceledtrader (indexed), pairIndex (indexed), indexLimit order canceled
TpUpdatedtradeId (indexed), trader (indexed), pairIndex (indexed), index, newTpTake-profit updated on open position
SlUpdatedtradeId (indexed), trader (indexed), pairIndex (indexed), index, newSlStop-loss updated on open position
TopUpCollateralExecutedtradeId (indexed), trader (indexed), pairIndex (indexed), topUpAmount, newLeverageCollateral added to position
RemoveCollateralInitiatedtradeId (indexed), orderId (indexed), trader (indexed), pairIndex, removeAmountCollateral removal queued for oracle
MarketOpenTimeoutExecutedorderId (indexed), order structStale open order timed out and refunded
MarketCloseTimeoutExecutedorderId (indexed), tradeId (indexed), order structStale close order timed out

DomfiTradingCallbacks

EventParametersMeaning
MarketOpenExecutedorderId (indexed), trade struct, priceImpactP, tradeNotionalTrade opened successfully
MarketCloseExecutedorderId (indexed), tradeId (indexed), price, priceImpactP, percentProfit, usdcSentToTrader, percentageClosedTrade closed, PnL settled
MarketOpenCanceledorderId (indexed), trader (indexed), pairIndex (indexed), cancelReasonOpen order rejected (price, slippage, etc.)
MarketCloseCanceledorderId (indexed), tradeId (indexed), trader (indexed), pairIndex, index, cancelReasonClose order rejected
LimitOpenExecutedorderId (indexed), limitIndex, trade struct, priceImpactP, tradeNotionalLimit order triggered and filled
LimitCloseExecutedorderId (indexed), tradeId (indexed), orderType, price, priceImpactP, percentProfit, usdcSentToTraderTP/SL/liquidation executed
RemoveCollateralExecutedorderId (indexed), tradeId (indexed), trader (indexed), pairIndex, removeAmount, leverage, tp, slCollateral removed from position
VaultOpeningFeeChargedtradeId (indexed), trader (indexed), amountOpening fee sent to vault
VaultClosingFeeChargedtradeId (indexed), trader (indexed), amountClosing fee sent to vault
VaultLiqFeeChargedorderId (indexed), tradeId (indexed), trader (indexed), amountLiquidation margin sent to vault
FeesChargedorderId (indexed), tradeId (indexed), trader (indexed), fundingFeesFunding fees settled

DomfiVault

EventParametersMeaning
WithdrawRequestedsender (indexed), owner (indexed), shares, currEpoch, unlockEpoch (indexed)LP requested withdrawal
WithdrawCanceledsender (indexed), owner (indexed), shares, currEpoch, unlockEpoch (indexed)LP canceled pending withdrawal
DepositLockedsender (indexed), owner (indexed), depositId, deposit structLocked deposit created (NFT minted)
DepositUnlockedsender (indexed), receiver (indexed), owner (indexed), depositId, deposit structLocked deposit unlocked (NFT burned)
AssetsSentsender (indexed), receiver (indexed), assetsUSDC paid out to winning trader
AssetsReceivedsender (indexed), user (indexed), assetsUSDC received from losing trader
AccPnlPerTokenUsedUpdatedsender (indexed), newEpoch (indexed), prevOpenPnl, newOpenPnl, newEpochOpenPnl, newAccPnlPerTokenUsedEpoch boundary — PnL committed to share price
DailyAccPnlDeltaResetprevDailyAccPnlDeltaPerTokenDaily circuit breaker counter reset

DomfiPriceRouter

EventParametersMeaning
PriceRequestedorderId (indexed), feed, timestamp, publishIdPrice request queued for oracle
PriceReceivedorderId (indexed), pairIndex (indexed), price, nativeFeeSigned price delivered by oracle bot

DomfiTradesUpKeep

EventParametersMeaning
AutomationOpenOrderInitiatedorderId (indexed), trader (indexed), pairIndex (indexed), indexAutomation bot triggering a limit open
AutomationCloseOrderInitiatedorderId (indexed), tradeId (indexed), trader (indexed), pairIndex, orderTypeAutomation bot triggering TP/SL/liquidation
AutomationExecutePerformedorderId, limitOrder (indexed), pairIndex (indexed), status (indexed), traderAutomation order execution result

Errors

Common Trading Errors

ErrorContractCauseResolution
InsufficientOracleFeeDomfiTradingETH msg.value too low for oracle feeSend at least ~0.00003 ETH as value
WrongLeverageDomfiTradingLeverage exceeds 250x or below minimumUse leverage 1–250x (100–25000 in 2-decimal)
WrongTPDomfiTradingTake-profit exceeds 900% capSet TP ≤ 900% of collateral
WrongSLDomfiTradingStop-loss outside valid rangeSet SL between entry and liquidation price
BelowMinLevPosDomfiTradingcollateral × leverage below minimum position sizeIncrease collateral or leverage
ExposureLimitsDomfiTradingTrade would exceed OI cap per direction per pairReduce position size
AboveMaxAllowedCollateralDomfiTradingCollateral exceeds protocol maximumUse less collateral
MaxPendingMarketOrdersReachedDomfiTradingToo many pending orders for this traderWait for existing orders to fill
MaxTradesPerPairReachedDomfiTradingMax open positions on this pair for this traderClose a position first
NoTradeFoundDomfiTradingPosition doesn't exist at given indexCheck trader address, pair, and index
TriggerPendingDomfiTradingCan't modify position while TP/SL/liquidation is pendingWait for pending trigger to resolve
IsPausedDomfiTradingTrading is paused by governanceWait for unpause

Callback / Execution Errors

ErrorContractCause
MarketOpenCanceled (event)DomfiTradingCallbacksOpen rejected — check CancelReason: slippage exceeded, insufficient collateral after fees, pair not listed, max OI exceeded
MarketCloseCanceled (event)DomfiTradingCallbacksClose rejected — trade no longer exists or conditions changed
RemoveCollateralRejected (event)DomfiTradingCallbacksRemoval rejected — position would be under liquidation, exceed max leverage, or at max profit cap

Vault Errors

ErrorContractCauseResolution
MaxDailyPnlReachedDomfiVaultDaily loss cap hit — vault can't pay more winning traders todayRetry after 24-hour reset
NotEnoughAssetsDomfiVaultCumulative PnL cap hit — vault has insufficient reservesRetry after vault receives more fees/losses
PendingWithdrawalDomfiVaultCannot transfer shares while a withdrawal is pendingCancel or complete the pending withdrawal first
WrongLockDurationDomfiVaultLock duration outside 7–365 day rangeUse a duration between 7 and 365 days
DepositNotUnlockedDomfiVaultAttempting to unlock before lock expiresWait for the lock period to end
NotAllowedDomfiVaultCaller is not the NFT owner or approvedMust be the NFT holder or have approval

ABIs

Verified source and ABIs are on BaseScan. Click any "View" link above, then navigate to the Contract tab.

For local development, generate TypeScript bindings from contract source:

cd onchain/exchange
make gen-types chain=base-mainnet

This produces ethers-v6 TypeScript types and ABI JSON files in script/deployments/base-mainnet/types/ and script/deployments/base-mainnet/abis/.

SDKs

There is no official JavaScript or Python SDK. Use viem or ethers.js directly with the contract ABIs linked above. The Quick Start shows working examples with both libraries.

See Also