Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: avoid duplicated EURe in adds receipt #291

Merged
merged 4 commits into from
Dec 11, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ import {
import { HumanTokenAmountWithAddress } from '../../../tokens/token.types'
import { emptyAddress } from '../../../web3/contracts/wagmi-helpers'
import { ProtocolVersion } from '@repo/lib/modules/pool/pool.types'
import { isSameAddress } from '@repo/lib/shared/utils/addresses'

type ParseProps = {
receiptLogs: Log[]
Expand Down Expand Up @@ -57,8 +58,17 @@ export function parseAddLiquidityReceipt({
const receivedBptAmount = getIncomingLogs(receiptLogs, userAddress)?.[0]?.args?.value
const receivedBptUnits = formatUnits(receivedBptAmount || 0n, BPT_DECIMALS)

// ERC-20: Monerium EURe (EURe)
const erc20EURe = '0x420ca0f9b9b604ce0fd9c18ef134c705e5fa3430'

return {
sentTokens,
/*
TODO:
properly implement this filter getting this info from LiquidityAdded/Removed event instead of Transfers
They use frontend (erc20) <> controller (upgradable proxy) setup - where calls to erc20 are forwarded to the controller.
Both emit events, which explains the duplicates.
*/
sentTokens: sentTokens.filter(t => !isSameAddress(t.tokenAddress, erc20EURe)),
receivedBptUnits,
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import { getGqlChain } from '@repo/lib/config/app.config'
import { ethAddress, polAddress } from '@repo/lib/debug-helpers'
import { GqlChain } from '@repo/lib/shared/services/api/generated/graphql'
import { Address, Hash } from 'viem'
import { polygon } from 'viem/chains'
import { gnosis, polygon } from 'viem/chains'
import { useAddLiquidityReceipt, useRemoveLiquidityReceipt, useSwapReceipt } from './receipt.hooks'
import { ProtocolVersion } from '@repo/lib/modules/pool/pool.types'

Expand Down Expand Up @@ -105,6 +105,42 @@ test('queries add liquidity with native token', async () => {
expect(result.current.receivedBptUnits).toBe('0.984524168989962117')
})

test('queries add liquidity in V3 GNOSIS pool', async () => {
const userAddress = '0xf76142b79Db34E57852d68F9c52C0E24f7349647'

// const poolId = '0xecc5aebd9569c82a0944007b22d03801a8fdfe99' // 59EURe 1sDAI 40USDC.e
//https://gnosisscan.io/tx/0x61286503bc38b6eda1477d3812cdd268114f3443138a513259a76c42b9cc53ac
const txHash = '0x61286503bc38b6eda1477d3812cdd268114f3443138a513259a76c42b9cc53ac'

const result = await testAddReceipt(userAddress, txHash, gnosis.id)

await waitFor(() => expect(result.current.isLoading).toBeFalsy())
await waitFor(() => expect(result.current.sentTokens).toBeDefined())

expect(result.current.sentTokens).toEqual([
{
humanAmount: '0.00000000000001',
tokenAddress: '0x2a22f9c3b484c3629090feed35f17ff8f88f76f0',
},
{
humanAmount: '0.000063840672042232',
tokenAddress: '0xe91d153e0b41518a2ce8dd3d7944fa863463a97d',
},
// the following one is excluded to avoid duplication
// ERC-20: Monerium EURe (EURe)
// {
// humanAmount: '0.014361104681096343',
// tokenAddress: '0x420ca0f9b9b604ce0fd9c18ef134c705e5fa3430',
// },
{
humanAmount: '0.014361104681096343',
tokenAddress: '0xcb444e90d8198415266c6a2724b7900fb12fc56e', // Monerium EUR emoney (EURe)
},
])

expect(result.current.receivedBptUnits).toBe('0.012149307213559577')
})

test('queries remove liquidity transaction', async () => {
// https://etherscan.io/tx/0x71301b46984d3d2e6b58c1fc0c99cc0561ec0f26d53bda8413528a7fb6828fc3
const userAddress = '0x84f240cA232917d771DFBbd8C917B4669Ed640CD'
Expand Down
15 changes: 13 additions & 2 deletions packages/lib/test/anvil/anvil-setup.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import { Address, Hex } from 'viem'
import { privateKeyToAccount } from 'viem/accounts'
import { mainnet, polygon, sepolia } from 'viem/chains'
import { gnosis, mainnet, polygon, sepolia } from 'viem/chains'

const networksWithFork = [mainnet, polygon, sepolia]
const networksWithFork = [mainnet, polygon, sepolia, gnosis] as const
export type NetworksWithFork = (typeof networksWithFork)[number]['name']

export type NetworkSetup = {
Expand Down Expand Up @@ -41,6 +41,7 @@
Ethereum: 8645,
Polygon: 8745,
Sepolia: 8845,
Gnosis: 9045,
}

export const ANVIL_NETWORKS: Record<NetworksWithFork, NetworkSetup> = {
Expand All @@ -67,6 +68,13 @@
// For now we will use the last block until v3 deployments are final
// forkBlockNumber: 6679621n,
},
Gnosis: {
networkName: 'Gnosis',
fallBackRpc: 'https://gnosis.drpc.org',
port: ANVIL_PORTS.Gnosis,
// For now we will use the last block until v3 deployments are final
// forkBlockNumber: ,
},
}

/*
Expand All @@ -74,7 +82,7 @@
When jobId is provided, the fork proxy uses this id to create a different local rpc url (e.g. `http://127.0.0.1:/port/jobId>/`
so that tests can be run in parallel (depending on the number of threads of the host machine)
*/
export const pool = Number(process.env.VITEST_POOL_ID ?? 1)

Check warning on line 85 in packages/lib/test/anvil/anvil-setup.ts

View workflow job for this annotation

GitHub Actions / Lint

VITEST_POOL_ID is not listed as a dependency in turbo.json

export function getTestRpcSetup(networkName: NetworksWithFork) {
const network = ANVIL_NETWORKS[networkName]
Expand Down Expand Up @@ -105,6 +113,9 @@
if (network.networkName === 'Sepolia') {
return dRpcUrl('sepolia')
}
if (network.networkName === 'Gnosis') {
return dRpcUrl('gnosis')
}
}

if (!network.fallBackRpc) {
Expand Down
10 changes: 8 additions & 2 deletions packages/lib/test/anvil/testWagmiConfig.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { NetworksWithFork, getTestRpcSetup, testAccounts } from '@repo/lib/test/anvil/anvil-setup'
import { Address, Chain, http } from 'viem'
import { mainnet, polygon, sepolia } from 'viem/chains'
import { gnosis, mainnet, polygon, sepolia } from 'viem/chains'
import { createConfig } from 'wagmi'
import { mock } from 'wagmi/connectors'

Expand All @@ -19,7 +19,12 @@ export const sepoliaTest = {
...getTestRpcUrls('Sepolia'),
} as const satisfies Chain

export const testChains = [mainnetTest, polygonTest, sepoliaTest] as const
export const gnosisTest = {
...gnosis,
...getTestRpcUrls('Gnosis'),
} as const satisfies Chain

export const testChains = [mainnetTest, polygonTest, sepoliaTest, gnosisTest] as const

function getTestRpcUrls(networkName: NetworksWithFork) {
const { port, rpcUrl } = getTestRpcSetup(networkName)
Expand Down Expand Up @@ -49,6 +54,7 @@ function createTestWagmiConfig() {
[mainnetTest.id]: http(),
[polygonTest.id]: http(),
[sepoliaTest.id]: http(),
[gnosisTest.id]: http(),
},
ssr: false,
})
Expand Down
5 changes: 3 additions & 2 deletions packages/lib/test/utils/wagmi/wagmi-test-clients.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import { testWagmiConfig } from '@repo/lib/test/anvil/testWagmiConfig'
import { publicActions, testActions, walletActions } from 'viem'
import { mainnet, polygon, sepolia } from 'viem/chains'
import { gnosis, mainnet, polygon, sepolia } from 'viem/chains'

export function createTestHttpClient(chainId: 1 | 137 | 11155111) {
export function createTestHttpClient(chainId: 1 | 137 | 11155111 | 100) {
return testWagmiConfig
.getClient({ chainId })
.extend(testActions({ mode: 'anvil' }))
Expand All @@ -13,3 +13,4 @@ export function createTestHttpClient(chainId: 1 | 137 | 11155111) {
export const mainnetTestPublicClient = createTestHttpClient(mainnet.id)
export const polygonTestPublicClient = createTestHttpClient(polygon.id)
export const sepoliaTestPublicClient = createTestHttpClient(sepolia.id)
export const gnosisTestPublicClient = createTestHttpClient(gnosis.id)
Loading