diff --git a/packages/core/src/positions/fetchLiquidityPositions/fetchClaimableAmount.ts b/packages/core/src/positions/fetchLiquidityPositions/fetchClaimableAmount.ts index fdd83a4..3ef33d4 100644 --- a/packages/core/src/positions/fetchLiquidityPositions/fetchClaimableAmount.ts +++ b/packages/core/src/positions/fetchLiquidityPositions/fetchClaimableAmount.ts @@ -1,23 +1,22 @@ import { NonfungiblePositionManager } from '@nftx/abi'; -import { NONFUNGIBLE_POSITION_MANAGER, Zero } from '@nftx/constants'; -import type { Provider, TokenId } from '@nftx/types'; -import { getChainConstant } from '@nftx/utils'; +import { Zero } from '@nftx/constants'; +import type { Address, Provider, TokenId } from '@nftx/types'; const MAX_UINT128 = 340282366920938463463374607431768211455n; const fetchClaimableAmount = async ({ - network, tokenId, provider, + manager, }: { provider: Provider; - network: number; tokenId: TokenId; + manager: Address; }): Promise<[bigint, bigint]> => { try { const ownerAddress = await provider.readContract({ abi: NonfungiblePositionManager, - address: getChainConstant(NONFUNGIBLE_POSITION_MANAGER, network), + address: manager, functionName: 'ownerOf', args: [BigInt(tokenId)], }); @@ -26,7 +25,7 @@ const fetchClaimableAmount = async ({ result: [amount0, amount1], } = await provider.simulateContract({ abi: NonfungiblePositionManager, - address: getChainConstant(NONFUNGIBLE_POSITION_MANAGER, network), + address: manager, functionName: 'collect', args: [ { diff --git a/packages/core/src/positions/fetchLiquidityPositions/fetchPositionsSet.ts b/packages/core/src/positions/fetchLiquidityPositions/fetchPositionsSet.ts index 593a60f..369b5bc 100644 --- a/packages/core/src/positions/fetchLiquidityPositions/fetchPositionsSet.ts +++ b/packages/core/src/positions/fetchLiquidityPositions/fetchPositionsSet.ts @@ -10,6 +10,7 @@ import { addressEqual } from '@nftx/utils'; import transformPosition from './transformPosition'; import { NotFoundError } from '@nftx/errors'; import fetchClaimableAmount from './fetchClaimableAmount'; +import getManager from './getManager'; const getVaultByTokens = >({ inputTokens, @@ -64,9 +65,9 @@ const fetchPositionsSet = async ({ vaults, }); const [claimable0, claimable1] = await fetchClaimableAmount({ - network, tokenId: position.tokenId as TokenId, provider, + manager: getManager(network, position.timestampOpened), }); return transformPosition({ network, diff --git a/packages/core/src/positions/fetchLiquidityPositions/getManager.ts b/packages/core/src/positions/fetchLiquidityPositions/getManager.ts new file mode 100644 index 0000000..9d55749 --- /dev/null +++ b/packages/core/src/positions/fetchLiquidityPositions/getManager.ts @@ -0,0 +1,14 @@ +import { NONFUNGIBLE_POSITION_MANAGER, Network } from '@nftx/constants'; +import { getChainConstant } from '@nftx/utils'; + +const getManager = (network: number, timestampOpened: string) => { + const lastTimeOldContractUsed = 1704206700; + const timestamp = Number(timestampOpened); + // If older than this, it's the old contract + if (timestamp <= lastTimeOldContractUsed && network === Network.Sepolia) { + return '0x55bdc76262b1e6e791d0636a0bc61cee23cdfa87'; + } + return getChainConstant(NONFUNGIBLE_POSITION_MANAGER, network); +}; + +export default getManager; diff --git a/packages/core/src/positions/fetchLiquidityPositions/queryPositionData.ts b/packages/core/src/positions/fetchLiquidityPositions/queryPositionData.ts index 3fd2138..121114b 100644 --- a/packages/core/src/positions/fetchLiquidityPositions/queryPositionData.ts +++ b/packages/core/src/positions/fetchLiquidityPositions/queryPositionData.ts @@ -32,6 +32,7 @@ const queryPositionData = ({ s.cumulativeDepositTokenAmounts, s.cumulativeWithdrawTokenAmounts, s.lockedUntil, + s.timestampOpened, s.tickUpper((tick) => [tick.index]), s.tickLower((tick) => [tick.index]), s.pool((pool) => [ diff --git a/packages/core/src/positions/fetchLiquidityPositions/transformPosition.ts b/packages/core/src/positions/fetchLiquidityPositions/transformPosition.ts index ff3055d..626b354 100644 --- a/packages/core/src/positions/fetchLiquidityPositions/transformPosition.ts +++ b/packages/core/src/positions/fetchLiquidityPositions/transformPosition.ts @@ -3,6 +3,7 @@ import type { PositionsResponse } from './types'; import { WETH_TOKEN, WeiPerEther, Zero } from '@nftx/constants'; import calculateVTokenEth from './calculateVTokenEth'; import { addressEqual, getChainConstant } from '@nftx/utils'; +import getManager from './getManager'; type Position = PositionsResponse['positions'][0]; @@ -66,6 +67,8 @@ const transformPosition = ({ // TODO: get this from... somwhere? const lifetimeRewards = Zero; + const manager = getManager(network, position.timestampOpened); + return { id: position.id as Address, poolId: position.pool.id as Address, @@ -90,6 +93,7 @@ const transformPosition = ({ poolShare: Zero, initialValue: value, lockedUntil, + manager, }; }; diff --git a/packages/types/src/positions.ts b/packages/types/src/positions.ts index 6a71c85..32b510d 100644 --- a/packages/types/src/positions.ts +++ b/packages/types/src/positions.ts @@ -41,6 +41,8 @@ export type LiquidityPosition = { /** The amount claimable on this position in ETH */ claimableValue: bigint; lockedUntil: number; + /** The address of the manager contract for this position */ + manager: Address; }; /** A user's Inventory Position, essentially a single xNFT */