"Don’t burn bridges. You’ll be surprised how many times you have to cross the same river.”
- H. Jackson Brown, Jr.
StargatePool is a liquidity pool. Users can deposit tokens into the pool and receive LP tokens in exchange. LP tokens can be redeemed to recover the initial deposit. LP tokens can be deposited inside the StargateStaking contract to earn a reward that is a fraction of the fee accrued by the liquidity pool during the staking time.
Each pool gets deployed for a specific token, if the token is address(0)
, it is the native coin, such as ETH.
Every StargatePool has a concept of:
tokenDecimals
or localDecimals
(LD)
sharedDecimals
(SD)
convertRate
computed as 10**(localDecimals - sharedDecimals)
This enables swaps between correlated assets with different decimal configurations, e.g. USDC on Ethereum -> USDT on BNB.
This property also enables composability with non-EVM chains as token balances there can be restricted with uint64
.
Consider the example of the USDT Pool on BNB with sharedDecimals == 6
, localDecimals == 18
and convertRate == 10**12
.
The accounting during depositing/redeeming is denominated in SD.
An example:
Amount of USDT to deposit = 114444555555555555555
Amount deposited in LD = 114444555000000000000
Amount in SD = 114444555
The last 12 decimals are cleaned from the amount the user wants to deposit.
Here are a few issues one might encounter while integrating with StargatePool
.
Before the deposit into the StargatePool
adequate allowance needs to be granted to pull the tokens from the user. As dust gets removed from the amount transferred there could be pending allowances to the StargatePool
if the input amount contains any dust.
Contrary to regular pools where dust is only cleaned from the input amount, StargatePoolNative for native tokens reverts if there is any dust passed in the input parameter. If there is an automated entity providing liquidity to StargatePools this can cause un-expected reverts.
Redeeming LP tokens received during deposit for the underlying pool token can revert if there aren't enough credits. This can occur if there is strong buying pressure for a specific pool, e.g. everyone's buying USDC on Ethereum by depositing USDC/USDT on other chains.
The redeem logic removes dust from the amountLD
passed as a parameter. If the amount to redeem contains dust the amount of token received can be less than requested.
Integrating with Stargate or LayerZero?
Windhustler is an expert in Stargate/LayerZero integrations, and a member of the Enigma Dark Team. Reach out if you want to get your code secured!
- Enigma Dark
Securing the shadows