Introducing gToken Vaults.

Gains Network
Gains Network
Published in
12 min readDec 7, 2022


Gm gTraders!

Alongside our upcoming launch on Arbitrum, we’re thrilled to announce our re-architected gToken vault. The new vault will go live with our deployment on Arbitrum, and will be implemented shortly before on Polygon as well.

What’s gTrade’s DAI Vault?

The DAI vault is the backbone of gTrade — it serves as the liquidity for all synthetic trades that take place on the platform. Unlike most trading platforms which use separate liquidity pools for each trading pair, gTrade is built on a single vault (the current vault on Polygon has $20M+ DAI) to serve as the counterparty for all trades placed on the platform across 70+ asset pairs.

Let’s dig into the details of our vault upgrade — but first, let’s discuss the structure and improvement opportunities of our existing vault.

The current DAI Vault

Currently, anyone can stake their DAI in the vault to supply trading liquidity to the platform. In exchange, they receive a percentage of fees paid by those trading on gTrade (~10–25% of all fees go to DAI vault stakers right now).

When stakers want to withdraw their DAI from the vault, they may do so at any time, but only at a rate of 25% of their total deposit per day (meaning it’ll take 4 consecutive days to withdraw the full deposit). This is in place for the stability of the vault liquidity and as an additional guarantee for traders using the platform.

The vault manages its collateralization ratio in two main ways:

  1. When the vault is sufficiently over-collateralized (130% and above), excess DAI is used to market buy and burn GNS token supply in a slow and steady manner.
  2. When the vault is under-collateralized, GNS tokens are minted and market-sold slowly over time (this was the case prior to the UST collapse in May and the current vault no longer operates this way).

Because traders on average lose more than they win, #2 is unlikely and the DAI vault typically trends towards over-collateralization.

Issues with the current DAI Vault

gTrade’s motivation for building the new vault can be summed up into four categories that hold back the existing vault structure: risk management, efficiency, incentivization, and composability.

Risk Management

Risk is not distributed evenly with the current vault structure. If there was a run on the bank, it would be those who withdrew last left harvesting the losses (only if the vault were under-collateralized of course).

Additionally, the current collateralization ratio doesn’t consider the PnL of open trades. For example, a staker could front-run the closing of a big winning trade to reduce their risk at the expense of other stakers. Once again, the risk is unevenly distributed amongst stakers in this situation.


When the vault reaches 130% collateralization and the protocol begins buying and burning GNS on the market, this is subject to front-running if the buys are substantial enough. In this case, front-running means an individual could accumulate GNS in anticipation of the protocol’s buy, wait for the price appreciation, and sell shortly after for an arbitrage profit.

Additionally, protocol market buys and burns are quite inefficient when factoring in slippage and AMM swap fees.

Incentives alignment

Stakers should be rewarded asymmetrically for taking the risk of supplying liquidity when the vault is under-collateralized. Currently, there are no incentives in place.

Also, the protocol wants to incentivize stakers to continue staking their rewards, but auto-compounding doesn’t currently exist.

Lastly, gTrade wants to incentivize vault stability. The most effective way to do this is by proportionately rewarding those who lock their DAI for a period of time — there’s not currently a system in place for this.


When stakers deposit DAI in the vault, there isn’t a “receipt” received for their contribution. The DAI sits in the vault (serving as liquidity for platform trades), but its value is unable to be leveraged elsewhere.

When stakers want to transition their staked positions to a new vault (cross-chain) or to a new address, the only way to do so is by unstaking and restaking.

The New gDAI Vault!

The new and improved vault is designed with these issues at the forefront of the architecture.

At its core, the new vault is built around gDAI (or gTokens more generally), an ERC-20 token representing a staker’s ownership of DAI in the vault.

The vault implements ERC-4626, a tokenized vault standard for yield-bearing vault assets. It plays a big role in making gDAI composability simpler for both users and developers. Learn more about ERC-4626 here.

gDAI is minted when DAI is deposited at its current price (no price impact as a result of minting). gDAI is burned at its current price when DAI is withdrawn (no price impact as a result of burning).

Calculating the price of gDAI

gDAI uses an exchange rate model, meaning the rate between it and the underlying asset algorithmically changes. There are two variables impacting the rate: accumulated fees per gDAI and open + closed pnl per gDAI. The former always increases the price, while the latter is variable.

This means losses are shared equally between all stakers — not just the last to withdraw. This also means the vault’s over-collateralization lowers the risk for all gDAI holders evenly. On top of that, it enables powerful financial incentives to be put in place by the protocol during periods of higher liquidity risk.

The price of gDAI is determined by the open trades PnL value at the beginning of each epoch (explained below), along with the accumulated DAI rewards on an ongoing basis.

It’s calculated as follows:

gDAI = 1 + accRewardsPerToken — Math.max(0, accPnlPerTokenUsed)

accRewardsPerToken = The accumulated DAI rewards per gDAI.

accPnlPerTokenUsed = The accumulated PnL open and closed per gDAI at the start of each epoch (with a maximum of 1 + accRewardsPerToken, which would represent an empty vault).

accPnlPerTokenUsed is a snapshot of accPnlPerToken at the start of the epoch. This is the value used in the price formula, meaning the gDAI price is updated once at the start of every new epoch (apart from DAI rewards, those are updated on a rolling basis).

The goal for this formula is to not increase the price of gDAI from over-collateralization (once the collateralization level reaches above 100%), as it will use the excess of DAI to create a protection layer for stakers, making it less likely from the gDAI price to ever decrease in the future (due to under-collateralization).

Finally it makes fees increase the price of gDAI, and increase the TVL / collateral available to pay trades just like new deposits.

More About The Open Trades Pnl Feed

Each epoch lasts 3 days, and there are 4 ‘open trades PnL measurements’ performed each epoch, powered by the same Chainlink DON used by gTrade. The measurements start 2 days after the start each epoch (on the start of the 3rd day), and happen every 6 hours (first measure at hour 0, then hour 6, hour 12, and hour 18). The protocol then has until the end of the 3rd day (72 hours after the start of the epoch) to double-check the measurements are correct — this is done to calculate the open trades PnL value we will use for the next epoch.

Each ‘open trades PnL measurements’ value is the median value of all answers sent by the Chainlink nodes. Note: All measurement median values can be reset if any oracle manipulation is detected. In that case, it would just start a new epoch using the previous epoch value.

Once the median values for the measurements have been acquired, gTrade takes the average of the 4 and then uses a floor of “0”, so only positive open PnL is taken into account. The delta with the previous average open PnL value (of the current epoch) is then used to update the accPnlPerToken variable, starting a new epoch.

Note: The delta in open positive PnL cannot take the accPnlPerToken value above 1 (which would represent < 0% collateralization); it is artificially capped. It also cannot change by more than “x” in a single epoch (eg. 0.2 would mean it can at most impact the collateralization ratio by 20% in a single epoch), which is an additional failsafe against oracle manipulation.

To recap, the price of gDAI is determined by two main variables:

  1. The accumulated DAI rewards per gDAI (accRewardsPerToken)
  2. The accumulated PnL open and closed per gDAI at the start of each epoch (accPnlPerTokenUsed)

The best part is, trading fees that have traditionally been rewarded to DAI vault stakers will now be auto-compounded into the price of gDAI.

Staking in the vault

Staking DAI to the new vault and receiving gDAI can be done at any time during an epoch.

You can also optionally receive a “discount” on your gDAI when staking DAI in the vault by choosing to lock your deposit for a certain period of time. The discount has two components: a time-based incentive and a collateralization-based incentive.

  1. Lock up your gDAI tokens when staking (from 2 weeks to 1 year).
  2. Mint gDAI anytime the collateralization ratio is below 150%. The discount is proportional to the collateralization level, with a maximum discount of 5%. At a collateralization ratio below 100%, the discount is 5%. Between 100%-150%, the discount linearly decreases from 5% to 0%.

Here’s an example:

Let’s say you deposit DAI into the vault when its collateralization ratio is 115% and decide to lock your gDAI for 6 months.

Your discount would be (150%-115%)/(150%-100%) collateralization * 5% total discount * 6mo/12mo = 1.75% discount.

Once the timelock elapses, you can claim the gDAI and get it back (locked in the gDAI contract).

Additionally, locked gDAI positions will be represented as NFTs (ERC-721 tokens) that can be exchanged, sold, or even potentially used as collateral in the future if other protocols start building on top of it. These positions are very similar to a zero-coupon bond — but in this case, the NFT earns trading fees during the lock period, meaning the principal value is likely to appreciate between purchase and maturation.

Incentivizing vault locks bring a new layer of safety and stability to gTrade’s liquidity.

Withdrawing from the vault

Withdrawal requests can only be executed in the first 2 days of each epoch.

There is a timelock (or delay) between the withdrawal request and the actual withdrawal. This timelock varies based on the collateralization ratio of the vault.

  • Vault is 120% or more collateralized = 1 epoch timelock (3 days)
  • Vault is 110%-120% collateralized = 2 epoch timelock (6 days)
  • Vault collateralization is below 110% = 3 epoch timelock (9 days)

This is another risk-management tool to ensure the long-term health of the vault across all market conditions.

Note: When you have a pending withdrawal request for ‘x’ amount of gDAI, you cannot transfer tokens that would make your balance go below ‘x’. This prevents an edge case where you could bypass the withdrawal timelock by using multiple wallets.

Incentives alignment

The new vault structure encourages liquidity providers to deposit into the vault at all collateralization levels — even when the vault is undercollateralized. When under 100%, DAI depositors receive both the highest discount on minting locked gDAI, along with a reduced gDAI price because it’s intrinsically tied to the vault’s health.

This serves as a powerful arbitrage opportunity for LPs expecting the vault to return to full collateralization, allowing them to earn on their deposit as the gDAI price goes back above 1 DAI! For example if you staked at 90% collateralization (assuming 0 fees distributed), the gDAI price is 0.9 DAI. Once the vault gets back to 100% collateralization, your deposit value will have increased by 11%.

As Seb says “Much better incentive alignment, and it becomes actually interesting to stake in the vault while it is undercollateralized”. The rest of the team agrees.

To prevent the gDAI supply from going out of control while under 100% collateralization (since 1 DAI gets you more than 1 gDAI), we define a max daily gDAI supply increase of 2% while under collateralized.

$GNS Minting and Burning

While the new vault is over-collateralized, a percentage of ALL trading losses go into a pool that can be used by anyone to sell their $GNS OTC. The vault will buy and burn the $GNS and send the equivalent DAI amount OTC using the 1 hour TWAP price. The percentage of losses can be adjusted depending on the current collateralization ratio — at 100%, we want it lower so the vault’s collateralization will increase faster. But as it increases, we probably want to send more to the OTC pool to keep the collateralization ratio within its desired range and to maximize the burn mechanism.

This mechanism acts as a self-adjusting throttle to manage the collateralization ratio, while also shielding the $GNS token price from potential market-selling pressure and creating deflationary pressure on the supply!

When the vault is under-collateralized, it’ll be refilled by minting and selling $GNS OTC, capped at 0.05% of the $GNS total supply every 24 hours (18.25% per year). This enables $GNS minting to refill the vault safely, while also preventing the $GNS token from market sell pressure (compared to the mechanics in place pre-UST). It acts as a secondary market to buy $GNS directly from the vault. The biggest use-case for $GNS is back in place!

Please note that just like the burn, if nobody actually interacts, nothing happens. For example, there isn’t a bot doing it at fixed predictable intervals.

gDAI Composability

With the previous DAI vault, your staked positions were locked in the vault, earning protocol fees from traders leveraging the vault for liquidity.

This is still the case — but on top of it, you’ll also receive an ERC-20 token representing the DAI you provided in the vault. This is gDAI.

gDAI can be:

  • Transferred between wallets without the need to unstake
  • Accepted as collateral within other DeFi protocols
  • Serve as an over-collateralized stablecoin backed by gTrade liquidity
  • Used to provide liquidity to an AMM pool
  • And much more…

The composability possibilities are limitless — and certainly beyond what we can brainstorm at this moment. Other individuals and protocols are likely to leverage gDAI in ways we haven’t yet thought of, and we’re looking forward to it!

The big takeaway is: Your DAI vault position is no longer a static holding — it’s now an additional token with a whole new layer of composition.

Future gTokens

gDAI is only the start. The smart contract code used to create the new vault is collateral agnostic — meaning it can be deployed to create a vault for any other asset.

This means a suite of vaults (liquidity pools) that support traders on the gTrade platform — we’re calling these gTokens. Think gBTC, gETH, gUSDC, gMATIC, gMAI, etc. We’ll keep you all updated on what’s to come — for now, we start with gDAI!

What’s next?

With on-chain liquidity comes a lot of possibilities… possibilities beyond just leverage trading. We’re thinking big and look forward to exploring all possible use cases that can be built on top.

The gDAI token will be implemented on Polygon a few days before our Arbitrum launch. To limit the drawdown risk for early gDAI stakers and to make use of the significant buffer we’ve already accrued, we are going to transfer the over-collateralization from the current vault (after it’s deprecated) to the new gDAI vaults, so they start at higher than 100% collateralized.

There is currently 2.9m DAI of over-collateralization, of which about 1m belongs to the project / team funds (they were injected right after the UST crash to support the current vault). We are going to claim back the 1m DAI by closing the corresponding delta neutral trades, and use the 1.9m remaining DAI to bootstrap the over-collateralization of the new gDAI vaults on Polygon and Arbitrum.

The launch is coming soon. The Halborn audit report will be available shortly, and our dev team is heads-down wrapping up the smart contracts and front end. We estimate to be about a week from the Polygon gDAI launch and 2 weeks from the Arbitrum launch.

gTrade is taking off and we’re glad to have you with us!


1. Why use epochs?

Epochs are necessary because we can’t have the open trades PnL feed in real-time due to practical reasons (API calls, gas costs).

2. Why multiple open trade measures?

Multiple open trade measures make oracle manipulation harder and gives us more opportunities to check discrepancies

3. Why perform the open trade measures at the end of each epoch?

Because then it’s less lagging, and since withdrawal requests can only be made at the beginning of the epoch, it is more robust against anticipation of new epoch’s open pnl updates.

4. Why do we need to wait up to 3 epochs to withdraw?

Because it increases guarantees of liquidity availability for traders, and removes risks related to anticipating new epoch open pnl updates.

5. Why only use the open trades PnL if it’s positive? (= negative for collateralization)

If we didn’t, it might let people withdraw more than they should. Even if there’s $1M negative PnL, the DAI is not yet in the vault, so we cannot say it increases collateralization. However, we have to take into account the positive PnL because it could close anytime, and we don’t want people to withdraw right before, preventing us from being able to pay trades. It makes the vault more robust.

Thanks for reading!