Gains Network
Search…
⌃K

gDAI Vault

First gToken built to support the gTrade trading protocol
gDAI Vault is a DAI vault following ERC-4626, a standard API for tokenized yield-bearing vaults that represent shares of a single underlying ERC-20 asset. For this vault, gDAI shares represent the underlying DAI asset.
The vault serves as the counterparty to all trades made on the platform:
  • When traders win (positive PnL), their winnings are received from the vault.
  • When traders lose (negative PnL), their losses are sent to the vault.
In exchange, the vault receives a portion of trading fees. These fees are proportionally split among gDAI shares, incentivizing stakers to stay in the vault.
Collateralization of the vault depends on trader PnL. As long as fees earned is greater than PnL payouts, stakers earn a positive return. This has proven to be the case for two+ years and the protocol has various risk management measures in place to ensure it continues.
When overall PnL is negative, the vault starts to create a buffer with those funds, further protecting stakers' funds and the protocol from future PnL abnormalities.
To better approximate real collateralization ratio, and to minimize risks for the protocol (including stakers), the vault follows an epoch system for capturing snapshots of open PnL. Open PnL represents the aggregate PnL of all open trades at the time of the snapshot.

gDAI

gDAI is an ERC-20 representing ownership of the underlying DAI asset. It follows an exchange rate model (similar to Compound's cTokens) where the price of gDAI to DAI changes in real-time from two variables: accumulated fees and trader PnL (both open and closed).
gDAI = 1 + accRewardsPerToken — Math.max(0, accPnlPerTokenUsed)
accRewardsPerToken: accumulator value representing how many fees a single gDAI has accrued. This value always increases over time.
accPnlPerTokenUsed: a snapshotted accumulator value of trader PnL from all closed trades and a snapshot of open trades from the end of the previous epoch. This value changes every epoch and can move in either direction.

gNFT

gNFT is an ERC-721 representing ownership of locked gDAI shares. Locked gDAI is purchased at a discount, based on the amount of time a lender is willing to lock up their funds, and can be unlocked following the lock duration.
Locked gDAI accumulates fees like all other shares.

Epoch system

Epoch system provides open PnL data to the vault in a decentralized manner, so the vault better understands its collateralization ratio. Calculating open PnL is too computationally expensive to do in real-time, on-chain.
There are two states the epoch system can be in:
  • Withdraw window - the period before open PnL values are being received and stakers may make withdraw-related actions (both requests and withdraws).
  • Open PnL window - the period before the epoch closes where the protocol requests open PnL snapshots from oracles. It makes multiple requests to a network of oracles, taking the median value, finally averaging across the request periods. This PnL value is then used in the succeeding epoch.

Withdraw locks

For the security of the vault, and to prevent stakers from front-running PnL changes, DAI can't be withdrawn immediately. Instead it must go through a withdraw request system.
Depending on the collateralization ratio of the vault, a staker may withdraw either 1, 2, or 3 epochs after making a request. The higher collateralization ratio, the shorter the lock period.
If a staker misses their withdraw window, they must make a new request.
For a more detailed overview of the vault, please see our Medium post:

Audit

Gains_Trade_Smart_Contract_Security_Audit_Report_Halborn_Final.pdf
6MB
PDF