GoodDocs
  • Welcome to GoodDocs!
  • GoodDollar Ecosystem Vision
  • About the Protocol
    • Usage
    • Tokenomics
    • Sybil-Resistance
    • Protocol V3 Documentation
      • Architecture & Value Flow
      • System's Elements
      • Core Contracts & API
        • GoodDollar
        • GoodCompoundStaking V2 (DAI)
        • GoodAaveStaking V2 (USDC)
        • GoodReserveCDai
        • GoodFundManager
        • GoodMarketMaker
        • ContributionCalculation
        • UBIScheme
        • Identity
        • FirstClaimPool
        • AdminWallet
        • OneTimePayments
        • DonationsStaking
        • NameService
        • GReputation
        • CompoundVotingMachine
        • StakersDistribution
        • UniswapV2SwapHelper
        • Invites
        • GovernanceStaking
        • ClaimersDistribution
        • CompoundStakingFactory
        • AaveStakingFactory
        • ExchangeHelper
        • FuseFaucet
        • GoodDollarMintBurnWrapper
      • Previous Protocol Versions
        • Protocol V1
          • Architecture & Value Flow
          • Core Contracts & API
        • Protocol V2
          • Architecture & Value Flow
          • System's Elements
            • 1. The token (G$)
            • 2. The Reserve
            • 3. The Trust
            • 4. Staking rewards (APR)
            • 5. The Fund Manager
            • 6. The Distribution Contract (DisCo)
            • 7. Governance (DAO)
          • Core Contracts & API
            • GoodDollar
            • GoodCompoundStaking V2 (DAI)
            • GoodAaveStaking V2 (USDC)
            • GoodReserveCDai
            • GoodFundManager
            • GoodMarketMaker
            • ContributionCalculation
            • UBIScheme
            • Identity
            • FirstClaimPool
            • AdminWallet
            • OneTimePayments
            • DonationsStaking
            • NameService
            • GReputation
            • CompoundVotingMachine
            • StakersDistribution
            • UniswapV2SwapHelper
            • Invites
            • GovernanceStaking
            • ClaimersDistribution
            • CompoundStakingFactory
            • AaveStakingFactory
            • ExchangeHelper
            • FuseFaucet
  • User Guides
    • Buy & Sell G$
    • Stake to create UBI
    • Claim GOOD and G$X
    • Bridge GoodDollars
    • Connect another wallet address to identity
  • Liquidity
  • Wallet and Products
    • GoodWallet
    • GoodDapp
    • New GoodWallet
    • GoodCollective
    • GoodID & GoodOffers
    • 3rd Party Partners and Integrations
  • Frequently Asked Questions
    • Web3 basic knowledge and security tips - by Consensys
    • About GoodDollar
    • GoodDollar Protocol & G$ Token
    • Using GoodDollar
    • GoodDollar Community
    • Troubleshooting
  • For Developers
    • Contributing to GoodDollar
    • GoodDapp Developer Guides
      • Deploy your own GoodDapp UI
    • APIs & SDKs
      • Claim UBI
      • React Hooks Setup
      • Login With GoodDollar
      • Sybil Resistance
        • Identity (Ethers v5 / React)
        • Identity (Viem/Wagmi)
  • Useful Links
    • GoodDollar.org
    • GoodDapp
    • GoodWallet
    • GoodDollar User Guides
    • Statistics Dashboard
    • GoodDollar Whitepaper
    • GoodDollar Litepaper
    • GoodDollar Litepaper - Español
Powered by GitBook
On this page
  • maxSafeTokenAmount
  • swap

Was this helpful?

  1. About the Protocol
  2. Protocol V3 Documentation
  3. Core Contracts & API

UniswapV2SwapHelper

The utilitary library which is helping to perform swaps in Uniswap V2.

maxSafeTokenAmount

A helper function to calculate percentage out of token liquidity in pool that is safe to exchange against sandwich attack.

Also checks if token->Native token has better safe limit, so perhaps doing tokenA->Native token->tokenB is better than tokenA->tokenB.

In that case it could be that Native token->tokenB can be attacked because we dont know if Native token received for tokenA->Native token is less than _maxPercentage of the liquidity in Native token->tokenB.

In our use case it is always eth->dai so either it will be safe or very minimal.

Parameter name
Annotation

_iHasRouter

The contract address which instance has router address.

_inToken

The address of the token we are swapping.

_outToken

The address of swap result token.

_inTokenAmount

The amount of in token required to swap.

_maxLiquidityPercentageSwap

Max percentage of liquidity to swap to token. When swapping tokens and this value is out of 100000, so for example if you want to set it to 0.3 you need set it to 300.

Returns: safe amount of token that could be swapped.

function maxSafeTokenAmount(
    address _iHasRouter,
    address _inToken,
    address _outToken,
    uint256 _inTokenAmount,
    uint256 _maxLiquidityPercentageSwap
) public view returns (uint256 safeAmount);

swap

A helper function to perform swap tokens in the Uniswap V2.

Parameter name
Annotation

_iHasRouter

The contract address which instance has router address.

_path

The path of the swap.

_tokenAmount

The token amount to swap.

_mintTokenReturn

Minimum token amount to get in swap transaction.

_receiver

The receiver of tokens after swap transaction.

Can only be called by the Avatar.

function swap(
    address _iHasRouter,
    address[] memory _path,
    uint256 _tokenAmount,
    uint256 _minTokenReturn,
    address _receiver
) internal returns (uint256 swapResult);
PreviousStakersDistributionNextInvites

Last updated 2 years ago

Was this helpful?