diff --git a/adapters/izumiswap/src/config/config.ts b/adapters/izumiswap/src/config/config.ts index d76dc42c..f6dffcfa 100644 --- a/adapters/izumiswap/src/config/config.ts +++ b/adapters/izumiswap/src/config/config.ts @@ -1,3 +1,6 @@ +import { createPublicClient, http } from 'viem'; +import { linea } from 'viem/chains'; + export const enum CHAINS{ MODE = 34443, LINEA = 59144, @@ -27,4 +30,31 @@ export const SUBGRAPH_URLS = { export const RPC_URLS = { [CHAINS.MODE]: "https://rpc.goldsky.com", [CHAINS.LINEA]: "https://rpc.linea.build", -} \ No newline at end of file +} + +export const client = createPublicClient({ + chain: linea, + transport: http(RPC_URLS[CHAINS.LINEA]), + }); + +export const FARM_CONTRACTS = ['0xbe138ad5d41fdc392ae0b61b09421987c1966cc3'] + +export const OWNERS_ABI = [{ + "inputs": [ + { + "internalType": "uint256", + "name": "", + "type": "uint256" + } + ], + "name": "owners", + "outputs": [ + { + "internalType": "address", + "name": "", + "type": "address" + } + ], + "stateMutability": "view", + "type": "function" + }] as const \ No newline at end of file diff --git a/adapters/izumiswap/src/utils/subgraphDetails.ts b/adapters/izumiswap/src/utils/subgraphDetails.ts index 5207a2e9..91c6aa18 100644 --- a/adapters/izumiswap/src/utils/subgraphDetails.ts +++ b/adapters/izumiswap/src/utils/subgraphDetails.ts @@ -1,5 +1,5 @@ import BigNumber from "bignumber.js"; -import { AMM_TYPES, CHAINS, PROTOCOLS, RPC_URLS, SUBGRAPH_URLS } from "../config/config"; +import { AMM_TYPES, CHAINS, FARM_CONTRACTS, OWNERS_ABI, PROTOCOLS, RPC_URLS, SUBGRAPH_URLS, client } from "../config/config"; import { PositionMath } from "./positionMath"; import { createPublicClient, extractChain, http } from "viem"; import { linea } from "viem/chains"; @@ -145,6 +145,26 @@ export const getPositionsForAddressByPoolAtBlock = async ( fetchNext = false; } } + + for (let contract of FARM_CONTRACTS){ + const ownedByFarm = result.filter( + (p) => p.owner === contract, + ); + + const owners = await getFarmOwner( + ownedByFarm.map((p) => p.id), + BigInt(blockNumber), + contract as any + ); + + for (const [index, owner] of owners.entries()) { + const pid = ownedByFarm[index].id; + + const item = result.find((p, index)=>p.id === pid) + if (item) item.owner = owner.toLowerCase(); + } + } + return result; } @@ -307,4 +327,24 @@ export const getTimestampAtBlock = async (blockNumber: number) => { blockNumber: BigInt(blockNumber), }); return Number(block.timestamp * 1000n); -}; \ No newline at end of file +}; + +export const getFarmOwner = async (ids: string[], blockNumber: bigint, farmAddress: '0x${string}') => { + const results = await client.multicall({ + allowFailure: false, + blockNumber, + contracts: ids.map( + (id) => + ({ + abi: OWNERS_ABI, + address: farmAddress, + functionName: 'owners', + args: [BigInt(id)], + } as const), + ), + }); + + return results.map((r) => { + return r; + }); +} \ No newline at end of file