From 01225c8dff1d7cb8e18ec8156f85afda7406fe52 Mon Sep 17 00:00:00 2001 From: Noisekit <28145325+noisekit@users.noreply.github.com> Date: Mon, 16 Dec 2024 18:20:45 +1100 Subject: [PATCH] Fix for Pool rewards per collateral (#106) * Fix for Pool rewards per collateral * Reduce number of calls in a Rewards Multicall by eliminating impossible combinations --- .../8453-andromeda/Claim_All_Rewards.e2e.js | 18 +++++++++------- liquidity/lib/useRewards/useRewards.ts | 21 +++++++++++++++++++ 2 files changed, 32 insertions(+), 7 deletions(-) diff --git a/liquidity/cypress/cypress/e2e/8453-andromeda/Claim_All_Rewards.e2e.js b/liquidity/cypress/cypress/e2e/8453-andromeda/Claim_All_Rewards.e2e.js index 0e1efc3a..37e40d29 100644 --- a/liquidity/cypress/cypress/e2e/8453-andromeda/Claim_All_Rewards.e2e.js +++ b/liquidity/cypress/cypress/e2e/8453-andromeda/Claim_All_Rewards.e2e.js @@ -3,14 +3,18 @@ import { makeSearch } from '@snx-v3/useParams'; describe(__filename, () => { Cypress.env('chainId', '8453'); Cypress.env('preset', 'andromeda'); - Cypress.env('walletAddress', '0x1a245Fa866932731631E1ec8EDcDbB0C6A402559'); - Cypress.env('accountId', '1640332659'); + Cypress.env('walletAddress', '0xc3Cf311e04c1f8C74eCF6a795Ae760dc6312F345'); + Cypress.env('accountId', '522433293696'); + + // Account with old vault rewards + // Cypress.env('walletAddress', '0x1a245Fa866932731631E1ec8EDcDbB0C6A402559'); + // Cypress.env('accountId', '1640332659'); beforeEach(() => { cy.task('startAnvil', { chainId: Cypress.env('chainId'), forkUrl: `https://base-mainnet.infura.io/v3/${Cypress.env('INFURA_KEY')}`, - block: '22544990', + block: '23771246', }).then(() => cy.log('Anvil started')); cy.on('window:before:load', (win) => { @@ -40,8 +44,8 @@ describe(__filename, () => { cy.get('[data-cy="claim rewards info"]') .should('exist') - .and('include.text', 'Claiming 640.24 USDC') - .and('include.text', 'Claiming 449.22 SNX'); + .and('include.text', 'Claiming 2.37 USDC') + .and('include.text', 'Claiming 1.9 SNX'); cy.contains('[data-status="success"]', 'Your rewards have been claimed', { timeout: 180_000, @@ -49,8 +53,8 @@ describe(__filename, () => { cy.get('[data-cy="transaction hash"]').should('exist'); cy.get('[data-cy="claim rewards info"]') - .should('include.text', 'Claimed 640.24 USDC') - .and('include.text', 'Claimed 449.22 SNX'); + .should('include.text', 'Claimed 2.37 USDC') + .and('include.text', 'Claimed 1.9 SNX'); cy.contains('[data-cy="claim rewards dialog"] button', 'Done').click(); cy.get('[data-cy="rewards table"]', { timeout: 180_000 }).should( diff --git a/liquidity/lib/useRewards/useRewards.ts b/liquidity/lib/useRewards/useRewards.ts index 3d0a6d89..2bef6569 100644 --- a/liquidity/lib/useRewards/useRewards.ts +++ b/liquidity/lib/useRewards/useRewards.ts @@ -139,6 +139,7 @@ export function useRewards({ accountId }: { accountId?: string }) { const poolDistributors = rewardsDistributors .filter((distributor) => !distributor.collateralType) + .filter((distributor) => !distributor.name.includes('Liquidation Rewards')) .flatMap((distributor) => ({ method: 'getAvailablePoolRewards', claimMethod: 'claimPoolRewards', @@ -153,6 +154,25 @@ export function useRewards({ accountId }: { accountId?: string }) { })); log('poolDistributors', poolDistributors); + const poolDistributorsPerCollateral = rewardsDistributors + .filter((distributor) => !distributor.collateralType) + .filter((distributor) => !distributor.name.includes('Liquidation Rewards')) + .flatMap((distributor) => + collateralTypes.map((collateralType) => ({ + method: 'getAvailablePoolRewards', + claimMethod: 'claimPoolRewards', + args: [ + ethers.BigNumber.from(accountId), + ethers.BigNumber.from(POOL_ID), + collateralType.address, + distributor.address, + ], + distributor, + collateralType, + })) + ); + log('poolDistributorsPerCollateral', poolDistributorsPerCollateral); + const liquidationRewardsDistributors = rewardsDistributors .filter((distributor) => !distributor.collateralType) .filter((distributor) => distributor.name.includes('Liquidation Rewards')) @@ -175,6 +195,7 @@ export function useRewards({ accountId }: { accountId?: string }) { const multicall = [ ...vaultDistributors, ...poolDistributors, + ...poolDistributorsPerCollateral, ...liquidationRewardsDistributors, ]; log('multicall', multicall);