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

get the owners of nfts staked in farm #74

Merged
merged 1 commit into from
Apr 30, 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
32 changes: 31 additions & 1 deletion adapters/izumiswap/src/config/config.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
import { createPublicClient, http } from 'viem';
import { linea } from 'viem/chains';

export const enum CHAINS{
MODE = 34443,
LINEA = 59144,
Expand Down Expand Up @@ -27,4 +30,31 @@ export const SUBGRAPH_URLS = {
export const RPC_URLS = {
[CHAINS.MODE]: "https://rpc.goldsky.com",
[CHAINS.LINEA]: "https://rpc.linea.build",
}
}

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
44 changes: 42 additions & 2 deletions adapters/izumiswap/src/utils/subgraphDetails.ts
Original file line number Diff line number Diff line change
@@ -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";
Expand Down Expand Up @@ -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;
}

Expand Down Expand Up @@ -307,4 +327,24 @@ export const getTimestampAtBlock = async (blockNumber: number) => {
blockNumber: BigInt(blockNumber),
});
return Number(block.timestamp * 1000n);
};
};

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;
});
}
Loading