# DeFi: Stargate v2 Integration Checklist

By [Enigma Dark](https://paragraph.com/@enigma-dark) · 2024-10-07

---

"Don’t burn bridges. You’ll be surprised how many times you have to cross the same river.”

\- H. Jackson Brown, Jr.

Introduction
------------

[StargatePool](https://github.com/stargate-protocol/stargate-v2/blob/62bc1f8/packages/stg-evm-v2/src/StargatePool.sol#L16) 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](https://github.com/stargate-protocol/stargate-v2/blob/4eec1af/packages/stg-evm-v2/src/peripheral/rewarder/StargateStaking.sol#L13) 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.

Token Precision
---------------

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.

Common pitfalls
---------------

Here are a few issues one might encounter while integrating with `StargatePool`.

### Dangling allowances

Before the deposit into the `StargatePool` adequate allowance needs to be granted to [pull the tokens from the user](https://github.com/stargate-protocol/stargate-v2/blob/85ee6cbc6fc858b32ea272d22c81a6096236b5c8/packages/stg-evm-v2/src/StargatePool.sol#L260-L263). As dust gets removed from the amount transferred there could be pending allowances to the `StargatePool` if the input amount contains any dust.

### Reverts due to dust with native pools

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](https://github.com/stargate-protocol/stargate-v2/blob/85ee6cbc6fc858b32ea272d22c81a6096236b5c8/packages/stg-evm-v2/src/StargatePoolNative.sol#L68-L76). If there is an automated entity providing liquidity to StargatePools this can cause un-expected reverts.

### Redeeming LP tokens can fail

Redeeming LP tokens received during deposit for the underlying pool token can [revert if there aren't enough credits](https://github.com/stargate-protocol/stargate-v2/blob/85ee6cbc6fc858b32ea272d22c81a6096236b5c8/packages/stg-evm-v2/src/StargatePool.sol#L73). 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.

### Dust removal during redeem

The redeem logic [removes dust from the](https://github.com/stargate-protocol/stargate-v2/blob/85ee6cbc6fc858b32ea272d22c81a6096236b5c8/packages/stg-evm-v2/src/StargatePool.sol#L81-L82) `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](https://x.com/windhustler) is an expert in Stargate/LayerZero integrations, and a member of the Enigma Dark Team. [Reach out](https://www.enigmadark.com/contact) if you want to get your code secured!

\- Enigma Dark

_Securing the shadows_

---

*Originally published on [Enigma Dark](https://paragraph.com/@enigma-dark/defi-stargate-v2-integration-checklist-2)*
