Withdraw
How to deposit stablecoins into Gro Protocol in exchange for PWRD or Vault (GVT) tokens
Before performing any withdrawal from Gro Protocol, the minimum amount of stablecoin to get in return must first be calculated. Calculating the value of
minAmount
involves converting the growth token amount into LP and then converting LP into a stablecoin amount. The process varies for PWRD and GVT.PWRD
Use
usdToLp
from the buoy contract to convert PWRD into LP and then use singleStableFromLp
to convert LP to stablecoin.const buoyContract = new web3.eth.Contract(
buoy.abi,
buoy.address
)
const lpAmount = await buoyContract.methods.usdToLp(growthTokenAmount).call();
const stableAmount = await buoyContract().methods.singleStableFromLp(lpAmount, index).call();
// 2% slippage => 0.02
// 5% withdrawFee => 0.05
const minAmount = stableAmount.mul(1 - (slippage + withdrawFee))
buoy.address
is a string set to the Buoy address.growthTokenAmount
: the amount of PWRD being withdrawn. This is an integer (uint256
) in the BigNumber format with conversions performed using BN.js.slippage
andwithdrawFee
are floats.
Convert GVT into a USD value before converting USD to LP with
buoy
contract's usdToLp
method and then converting LP to stablecoin with singleStableFromLp
.const buoyContract = new web3.eth.Contract(
buoy.abi,
buoy.address
)
const lpAmount = await buoyContract.methods.usdToLp(growthTokenAmount).call();
const stableAmount = await buoyContract().methods.singleStableFromLp(lpAmount, index).call();
// 2% slippage => 0.02
// 5% withdrawFee => 0.05
const minAmount = stableAmount.mul(1 - (slippage + withdrawFee))
buoy.address
is a string set to the Buoy address.growthTokenAmount
: the amount of GVT being withdrawn. This an integer (uint256
) in the BigNumber format with conversions performed using BN.js. To get the USD value of GVT token, you can use call the value from the Vault token contract withgetPricePerShare
(under number 17 on Etherscan read contract page).
const usdAmount = await gvtContract.methods.getPricePerShare(growthTokenAmount).call()
slippage
andwithdrawFee
are floats.
This section describes how you can withdraw some (but not all) of PWRD or GVT held into a single stable coin.
withdrawHandler.method.withdrawByStablecoin(isPwrd, index, lpAmount, minAmount)
- isPwrd: if true, this indicates that PWRD is being withdrawn into stablecoin; if false, this indicates that GVT is being withdrawn into stablecoins.
- index: an integer (
uint256
) representing the stablecoin index (0 for DAI; 1 for USDC; 2 for USDT) - lpAmount: an integer (
uint256
) that is the LP amount of the growth token to withdraw - minAmount: an integer (
uint256
) that is the minimum amount of stablecoin to get in return (value denoted in stablecoin tokens)
In the case of an Emergency Status, PWRD or GVT should be converted into USD rather than into LP.
Each PWRD token has a value of 1 USD. For an
growthTokenAmount
of GVT, the following converts the token amount into a USD value:const usdAmount = await gvtContract.methods.getPricePerShare(growthTokenAmount).call()
USD is then converted into stablecoin as follows.
const buoyContract.singleStableFromUsd(usdAmount, index)
Where
index
represents the stablecoin index (0 for DAI; 1 for USDC; 2 for USDT).
This section describes how to withdraw all of PWRD or GVT into a single stablecoin.
withdrawHandler.method.withdrawAllSingle(isPwrd, index, minAmount)
- isPwrd: if true, this indicates that PWRD is being withdrawn into stablecoin; if false, this indicates that GVT is being withdrawn into stablecoins.
- index: an integer (
uint256
) representing the stablecoin index (0 for DAI; 1 for USDC; 2 for USDT) - minAmount: an integer (
uint256
) that is the minimum amount of stablecoin to get in return (value denoted in stablecoin tokens)
This section describes how you can withdraw some (but not all) of PWRD or GVT held into a balanced distribution of stablecoins. 'Balanced' does not mean an equal distribution across all stablecoins, but rather balanced from the perspective of the protocol.
withdrawHandler.method.withdrawByLPToken(isPwrd, lpAmount, minAmounts)
- isPwrd: if true, this indicates that PWRD is being withdrawn into stablecoin; if false, this indicates that GVT is being withdrawn into stablecoins.
- lpAmount: an integer (
uint256
) that is the LP amount of the growth token to withdraw - minAmounts: an array of integers (
uint256[]
). Each element is the minimum amount of a stablecoin to get in return (value denoted in stablecoin tokens). This is returned in the order of DAI, USDC and USDT.
This section describes how to withdraw all of a growth token into a balanced distribution of stablecoins. 'Balanced' does not mean an equal distribution across all stablecoins, but rather balanced from the perspective of the protocol.
withdrawHandler.method.withdrawAllBalanced(isPwrd, minAmounts)
- isPwrd: if true, this indicates that PWRD is being withdrawn into stablecoin; if false, this indicates that GVT is being withdrawn into stablecoins.
- minAmounts: an array of integers (
uint256[]
). Each element is the minimum amount of a stablecoin to get in return (value denoted in stablecoin tokens). This is returned in the order of DAI, USDC and USDT.
Last modified 1yr ago