GUniFactory
instantiating a tokenized V3 Position. When liquidity is added into the pool, G-UNI tokens are minted and credited to the provider. Inversely, G-UNI tokens can be burned to redeem that proportion of the pool's V3 position liquidity and fees earned. Thus, G-UNI tokens represent proportional ownership (or "shares") of the underlying Uniswap V3 position. Similar to the Uniswap V2 LP experience, anyone can add liquidity to or remove liquidity from a G-UNI Pool, and can earn their portion of the fees generated just by holding the fungible tokens.
Some G-UNI pools may have a special privileged manager
role (see the createManagedPool
and Manager Functions
sections).GUniFactory
smart contract governs over the creation of G-UNI Pools. In theory, any account or smart contract can create a G-UNI Pool via the factory by calling createPool
. This creates a tokenized UniswapV3 Position with a given immutable price range on the token pair and fee tier of your choice. Anyone can now participate as an LP in that range, by adding liquidity into this position and minting G-UNI tokens.tokenA
One of the tokens in the Uniswap V3 pairtokenB
The other token in the Uniswap V3 pairuniFee
Fee tier of the Uniswap V3 pair (500, 3000, 10000)lowerTick
Initial lower price bound for the position, represented as a Uniswap V3 tick.upperTick
Initial upper price bound for the position, represented as a Uniswap V3 tick.lowerTick
and upperTick
:
1. MUST be set to integers between -887272 and 887272 where upperTick > lowerTick
2. MUST be integers divisible by the tickSpacing of the Uniswap pair.createPool
method above, which creates an immutable G-UNI pool that no account has special privileges for. If you create a pool via the sorbet UI this is indeed the type of pool you create. However G-UNI pools are further customizable and can be used to implement tokenized dynamic strategies on top of Uniswap V3. To do this one needs to create a "managed" G-UNI pool, which creates a pool with a privileged manager role with the ability to executiveRebalance
the position moving the liquidity to a new range on that Uniswap V3 token pair. Via this manager functionality arbitrary rebalancing strategies can be implemented.tokenA
One of the tokens in the Uniswap V3 pairtokenB
The other token in the Uniswap V3 pairuniFee
Fee tier of the Uniswap V3 pair (500, 3000, 10000)managerFee
The proportion of fees earned that manager
takes as a cut in Basis Points (deployer address is initial manager). Note: The managerFee can only be set to a non-zero value once (immutable afterwards) lowerTick
Initial lower price bound for the position, represented as a Uniswap V3 tick.upperTick
Initial upper price bound for the position, represented as a Uniswap V3 tick.rebalanceAndAddLiquidity
Router method. However the swap parameters passed as argument to this function must be carefully chosen to deposit maximal liquidity and produce the least leftover (any leftover is returned to msg.sender
). This resolver contract exposes a helper for just that.rebalanceAndAddLiquidity
callpool
Address of G-UNI pool of interestamount0In
amount of token0 sender forwards to routeramount1In
amount of token1 sender forwards to routerprice18Decimals
price ratio of token1/token0
disregarding (normalizing by) token decimals and then expressed as a WAD (multiplied by 10^18
).zeroForOne
direction of swapswapAmount
amount of token to swapprice18Decimals
to get a preliminary swapAmount
, then get a more accurate price18Decimals
(using this swapAmount
as input), and finally call this method again with the more accurate price to get a final and more precise swapAmount
createManagedPool
are assigned a manager
account who can configure the Gelato Executor meta-parameters and also can control and alter the range of the underlying Uniswap V3 position.executiveRebalance
method on the GUniPool
. This permissioned method is the only way to change the price range of the underlying Uniswap V3 Position. Manager accounts who control this function are the means by which custom rebalancing strategies can be built on top of G-UNI. These strategies can be implemented by governance (slow, but decentralized) or by some central managerial party (more responsive but requiring much more trust) and in the future the manager role can be granted to a Gelato automated smart contract so that they have a sophisticated LP strategy fully automated by Gelato (both reinvesting fees and in rebalancing ranges).newLowerTick
The new lower price bound of the position represented as a Uniswap V3 tick.newUpperTick
The new upper price bound of the position represented as a Uniswap V3 tick.swapThresholdPrice
A sqrtPriceX96 that acts as a slippage parameter for the swap that rebalances the inventory (to deposit maximal liquidity around the new price bounds).swapAmountBPS
Amount of inventory to swap represented as Basis Points of the remaining amount of the token to swap.zeroForOne
The direction of the rebalancing swap.getUnderlyingBalances
on the GUniPool to obtain amount0Current
and amount1Current
2. Compute amount0Liquidity
and amount1Liquidity
using LiquidityAmounts.sol library, the new position bounds, the current price and the current amounts from step 1.amount0Leftover
and amount1Leftover
with formula amount0Leftover = amount0Current - amount0Liquidity
. In most cases one of these values will be 0 (or very close to 0).
4. Use amount0Liquidity
and amount1Liquidity
to compute the current proportion of each asset needed.
5. Use the amount0Leftover
and amount1Leftover
and the proportion from previous step to compute which token to swap and the swapAmount.swapAmount * 10000 / amountLeftover
for the token being swapped.manager
is to configure the parameters that restrict the functionality of Gelato Executors
. These parameters include how often Gelato bots can reinvest fees and withdraw manager fees, as well as other safety params like the slippage check. Only the manager can call updateGelatoParams
.newRebalanceBPS
The maximum percentage the auto fee reinvestment transaction cost can be compared to the fees earned in that feeToken. The percentage is given in Basis Points (where 10000 mean 100%). Example: if rebalanceBPS is 200 and the transaction fee is 10 USDC then the fees earned in USDC must be 500 UDSC or the transaction will revert.newWithdrawBPS
The maximum percentage the auto withdraw transaction fee can be compared to the amount withdrawn of that feeToken.newSlippageBPS
The maximum percentage that the rebalance slippage can be from the TWAP.newSlippageInterval
length of time in seconds for to compute the TWAP (time weighted average price). I.e. 300 means a 5 minute average price for the pool.newTreasury
The treasury address where manager fees are auto withdrawn.newOwner
the new account to act as manager._managerFeeBPS
the percent commission of fees earned to go to the manager account.GUniFactory
createPool
method. Most relevant information about about a G-UNI position is indexed and queryable via the subgraph. Query URL is: https://api.thegraph.com/subgraphs/name/gelatodigital/g-uni
Here is an example query which fetches all information about all G-UNI Positions:id
: subgraph identifier for the pool (contract address)
blockCreated
: block G-UNI position was deployed
address
: contract address of G-UNI positions
uniswapPool
: contract address of Uniswap V3 pair
token0
: address of token0
token1
: address of token1
feeTier
: Uniswap V3 Pair fee tier (500, 3000, 1000)
liquidity
: amount of liquidity currently in G-UNI position
lowerTick
: current lower tick of G-UNI Position
upperTick
: current upper tick of G-UNI Position
totalSupply
: current total supply of G-UNI token
positionId
: Uniswap V3 ID of the G-UNI position
supplySnapshots
: snapshots of the supply when it changes
feeSnapshots
: snapshots of fees earned latestInfo:
has up to date info about the position in a recent block.
The supplySnapshots
, feeSnapshots
, and latestInfo
can be ingested together to produce an estimated APR for fees generated by the position.
APR is calculated from these values in the following way:
1. We use the supplySnapshots
to calculate the time weighted average value of reserves Vr
. This value includes all fees earned.feeSnapshots
to add up all the fees earned to generate the total value of fees earned Vf
.
3. We compute APR as Vf / (Vr - Vf)
(when Vr > Vf
). In rare cases when Vf > Vr
i.e. feesEarned are larger than the time weighted average reserves, one can simply useVf/Vr
GUniPool
contract are low level and are NOT RECOMMENDED for direct interaction by end users unless they know why and what they are doing. For standard mint/burn interaction with G-UNI see GUniRouter
GUniPool
smart contract is the core implementation that powers the G-UNI protocol (all G-UNI token proxy contracts point to this implementation). It is an extension of the ERC20 interface so all normal ERC20 token functions apply, as well as a number of custom methods particular to G-UNI which will be outlined below. Most of the methods on the GUniPool are low level and end users should likely be interacting with peripheral contracts rather than directly with these low level methods. Nevertheless these methods are publicly exposed and functional.amount0Max
and amount1Max
positions
method on UniswapV3Pool.sol
).