Gains Network
  • 📚Home
  • Gains Network
    • 🔎Overview
    • 🍏GNS Token
    • 📔Contract Addresses
      • Apechain Mainnet
      • Arbitrum Mainnet
      • Base Mainnet
      • Polygon Mainnet
  • gTrade (Leveraged Trading)
    • 🔎Overview
    • 🎛️Setting up to trade
      • 🟣Polygon Network Setup
      • 🔵Arbitrum Network Setup
    • 🏦Opening / Closing trades
    • 💲Trade Collaterals
      • Spotlight: WETH
    • 📖Asset classes
      • 🪙Cryptocurrencies
      • 💵Forex
      • 🛢️Commodities
    • 🎫Fees & Spread
    • 📰Pair List
    • 🧒How to use Practice Mode
    • ⚡One-Click Trading (1CT)
    • 🌌gTrade Solana
    • 📺Video tutorials
  • Loyalty Programs
    • Prime Trader
    • gTrade Credits
  • Community
    • gTrade Guardians
    • Governance forum
  • Reward Pools
    • 💚GNS Staking
    • 👛gToken Vaults
      • 👷Staker Functions
      • ❔Staker FAQ
      • ⏳Upgrades, updates, and timelocks
    • 🔼Active Pools & Incentives
  • Help
    • ❓FAQ
    • ⏳Chain congestion
  • Bridges
    • 🪐Arbitrum <-> Polygon Bridge
    • 🪐ERC20 Bridge (Polygon)
    • 🪐NFT Bridge (Polygon)
  • Developer
    • Integrators
      • Trading Contracts
      • Backend
      • Price Feed
      • Guides
        • v9 migration
        • Calculating borrowing fees
        • Calculating liquidation price
    • Technical Reference
      • Contracts
        • Changelogs
          • v9.2.1 Update
          • v9.1 Update
          • v9.1.1 Update
          • v9 Update
        • Core
          • Abstract
            • GNSAddressStore
            • GNSDiamondCut
            • GNSDiamondLoupe
            • GNSDiamondStorage
          • Facets
            • GNSBorrowingFees
            • GNSOtc
            • GNSPriceAggregator
            • GNSTradingInteractions
            • GNSTriggerRewards
            • GNSFeeTiers
            • GNSPairsStorage
            • GNSPriceImpact
            • GNSReferrals
            • GNSTradingCallbacks
            • GNSTradingStorage
          • GNSMultiCollatDiamond
          • GNSStaking
          • GToken
          • GTokenOpenPnlFeed
        • Interfaces
          • Libraries
            • IBorrowingFeesUtils
            • IOtcUtils
            • IPriceAggregatorUtils
            • ITriggerRewardsUtils
            • IFeeTiersUtils
            • IPairsStorageUtils
            • IPriceImpactUtils
            • IReferralsUtils
            • ITradingCallbacksUtils
            • ITradingCommonUtils
            • ITradingInteractionsUtils
            • ITradingStorageUtils
            • IUpdateLeverageUtils
            • IUpdatePositionSizeUtils
          • Types
            • IAddressStore
            • IBorrowingFees
            • IDiamondStorage
            • IOtc
            • IPriceAggregator
            • ITradingStorage
            • ITradingInteractions
            • ITriggerRewards
            • ITypes
            • IUpdateLeverage
            • IPairsStorage
            • IFeeTiers
            • IPriceImpact
            • IReferrals
            • ITradingCallbacks
            • IUpdatePositionSize
          • IChainlinkFeed
          • IArbSys
          • IChainlinkOracle
          • IERC20
          • IERC721
          • IERC721Design
          • IGeneralErrors
          • IGNSAddressStore
          • IGNSDiamond
          • IGNSDiamondCut
          • IGNSMultiCollatDiamond
          • IGNSDiamondLoupe
          • IGNSStaking
          • IGToken
          • IGTokenLockedDepositNft
          • IGTokenOpenPnlFeed
          • IGTokenLockedDepositNftDesign
          • ILiquidityPool
          • IRateProvider
          • IOwnable
        • Libraries
          • updateLeverage
            • UpdateLeverageLifecycles
          • updatePositionSize
            • IncreasePositionSizeUtils
            • DecreasePositionSizeUtils
            • UpdatePositionSizeLifecycles
          • AddressStoreUtils
          • ChainlinkClientUtils
          • ChainUtils
          • ConstantsUtils
          • CollateralUtils
          • DiamondUtils
          • LiquidityPoolUtils
          • OtcUtils
          • PackingUtils
          • StorageUtils
          • TriggerRewardsUtils
          • ArrayGetters
          • BorrowingFeesUtils
          • FeeTiersUtils
          • PriceAggregatorUtils
          • PriceImpactUtils
          • ReferralsUtils
          • TradingCallbacksUtils
          • PairsStorageUtils
          • TradingCommonUtils
          • TradingStorageUtils
          • TradingInteractionsUtils
        • Misc
          • EpochBasedTokenClaim
          • GNSCompensationHandler
          • GTokenRateProvider
          • GTokenLockedDepositNftDesign
          • ManagerTimelock
          • OwnerTimelock
          • VotingDelegator
        • Tokens
          • GainsNetworkToken
          • GTokenLockedDepositNft
      • Backend
        • Backend Types
      • SDK
        • Client Types
  • Archived
    • 🖼️gFARM2 NFTs
Powered by GitBook
On this page
  • rewardToken
  • manager
  • epochRoots
  • epochCids
  • epochTraderClaimed
  • ManagerUpdated
  • TokensWithdrawn
  • EpochMerkleRootSet
  • TokensClaimed
  • TokensClaimed
  • AddressZero
  • NotManager
  • RootAlreadySet
  • RootZero
  • RewardsZero
  • CidZero
  • InvalidEpochs
  • ArrayLengthMismatch
  • EpochNotSet
  • NotEnoughBalance
  • AlreadyClaimed
  • InvalidProof
  • constructor
  • onlyManager
  • setManager
  • setRoot
  • withdrawTokens
  • claimRewards
  • claimMultipleRewards
  • _hashLeaf
  • _validateClaim

Was this helpful?

  1. Developer
  2. Technical Reference
  3. Contracts
  4. Misc

EpochBasedTokenClaim

Contract to claim rewards based on epoch and merkle tree (used for Arbitrum STIP trading incentives)

rewardToken

contract IERC20 rewardToken

manager

address manager

epochRoots

mapping(uint256 => bytes32) epochRoots

epochCids

mapping(uint256 => string) epochCids

epochTraderClaimed

mapping(uint256 => mapping(address => bool)) epochTraderClaimed

ManagerUpdated

event ManagerUpdated(address newManager)

TokensWithdrawn

event TokensWithdrawn()

EpochMerkleRootSet

event EpochMerkleRootSet(uint256 epoch, bytes32 root, uint256 totalRewards, string cid)

TokensClaimed

event TokensClaimed(uint256 epoch, address user, uint256 rewardAmount)

TokensClaimed

event TokensClaimed(uint256[] epochs, address user, uint256 rewardAmount)

AddressZero

error AddressZero()

NotManager

error NotManager()

RootAlreadySet

error RootAlreadySet()

RootZero

error RootZero()

RewardsZero

error RewardsZero()

CidZero

error CidZero()

InvalidEpochs

error InvalidEpochs()

ArrayLengthMismatch

error ArrayLengthMismatch()

EpochNotSet

error EpochNotSet()

NotEnoughBalance

error NotEnoughBalance()

AlreadyClaimed

error AlreadyClaimed()

InvalidProof

error InvalidProof()

constructor

constructor(contract IERC20 _rewardToken, address _owner, address _manager) public

onlyManager

modifier onlyManager()

setManager

function setManager(address _manager) external

Sets manager address to _manager. Only callable by owner() (multisig)

setRoot

function setRoot(uint256 _epoch, bytes32 _root, uint256 _totalRewards, string _cid) external

_Sets Merkle Tree _root and 'cid' for an _epoch and transfers _totalRewards from the owner() (multisig) to this contract. Only callable by manager.

withdrawTokens

function withdrawTokens() external

Prevents stuck tokens in case of misconfiguration; Only owner() (multisig) can claim the tokens back

claimRewards

function claimRewards(uint256 _epoch, uint256 _rewardAmount, bytes32[] _proof) external

Claims trader rewards for a specific _epoch

claimMultipleRewards

function claimMultipleRewards(uint256[] _epochs, uint256[] _rewardAmounts, bytes32[][] _proofs) external

Claims trader rewards for multiple _epochs

_hashLeaf

function _hashLeaf(address _user, uint256 _amount) internal pure returns (bytes32)

Returns a hashed leaf of _user + _amount

_validateClaim

function _validateClaim(uint256 _epoch, address _trader, uint256 _rewardAmount, bytes32[] _proof) internal view

_Validates that:

  1. The _epoch merkle tree root is set

  2. There are enough token rewards in the contract

  3. Rewards for leaf are unclaimed

  4. The leaf and _proof validate against epochRoot_

PreviousMiscNextGNSCompensationHandler

Was this helpful?