Withdraw
How to deposit stablecoins into Gro Protocol in exchange for PWRD or Vault (GVT) tokens

Required contract addresses

1) Calculate the min. amount of stablecoin to get in return

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.
1
const buoyContract = new web3.eth.Contract(
2
buoy.abi,
3
buoy.address
4
)
5
6
const lpAmount = await buoyContract.methods.usdToLp(growthTokenAmount).call();
7
8
const stableAmount = await buoyContract().methods.singleStableFromLp(lpAmount, index).call();
9
10
// 2% slippage => 0.02
11
// 5% withdrawFee => 0.05
12
const minAmount = stableAmount.mul(1 - (slippage + withdrawFee))
Copied!
  • 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 and withdrawFee are floats.

Vault (GVT)

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.
1
const buoyContract = new web3.eth.Contract(
2
buoy.abi,
3
buoy.address
4
)
5
6
const lpAmount = await buoyContract.methods.usdToLp(growthTokenAmount).call();
7
8
const stableAmount = await buoyContract().methods.singleStableFromLp(lpAmount, index).call();
9
10
// 2% slippage => 0.02
11
// 5% withdrawFee => 0.05
12
const minAmount = stableAmount.mul(1 - (slippage + withdrawFee))
Copied!
  • 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 with getPricePerShare (under number 17 on Etherscan read contract page).
1
const usdAmount = await gvtContract.methods.getPricePerShare(growthTokenAmount).call()
Copied!
  • slippage and withdrawFee are floats.

2) Withdraw some PWRD or GVT into a single stablecoin

This section describes how you can withdraw some (but not all) of PWRD or GVT held into a single stable coin.

How to withdraw some PWRD or GVT token

1
withdrawHandler.method.withdrawByStablecoin(isPwrd, index, lpAmount, minAmount)
Copied!
  • 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)

Withdraw in the case of Emergency Status

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:
1
const usdAmount = await gvtContract.methods.getPricePerShare(growthTokenAmount).call()
Copied!
USD is then converted into stablecoin as follows.
1
const buoyContract.singleStableFromUsd(usdAmount, index)
Copied!
Where index represents the stablecoin index (0 for DAI; 1 for USDC; 2 for USDT).

Withdraw all PWRD or GVT into a single stablecoin

This section describes how to withdraw all of PWRD or GVT into a single stablecoin.
1
withdrawHandler.method.withdrawAllSingle(isPwrd, index, minAmount)
Copied!
  • 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)

Withdraw some PWRD or GVT to balanced stablecoins

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.
1
withdrawHandler.method.withdrawByLPToken(isPwrd, lpAmount, minAmounts)
Copied!
  • 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.

Withdraw all PWRD or GVT to balanced stablecoins

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.
1
withdrawHandler.method.withdrawAllBalanced(isPwrd, minAmounts)
Copied!
  • 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.