Skip to content

Commit

Permalink
Add fuse 2 borrower nft fetching
Browse files Browse the repository at this point in the history
  • Loading branch information
IanWoodard committed Oct 31, 2023
1 parent b3e2def commit b2ea422
Show file tree
Hide file tree
Showing 4 changed files with 91 additions and 0 deletions.
70 changes: 70 additions & 0 deletions earn/src/data/BorrowerNft.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,13 @@
import { ContractCallContext, Multicall } from 'ethereum-multicall';
import { BigNumber, ethers } from 'ethers';
import { borrowerAbi } from 'shared/lib/abis/Borrower';
import { borrowerLensAbi } from 'shared/lib/abis/BorrowerLens';
import { borrowerNftAbi } from 'shared/lib/abis/BorrowerNft';
import {
ALOE_II_BORROWER_LENS_ADDRESS,
ALOE_II_BORROWER_NFT_ADDRESS,
ALOE_II_PERMIT2_MANAGER_ADDRESS,
ALOE_II_SIMPLE_MANAGER_ADDRESS,
MULTICALL_ADDRESS,
} from 'shared/lib/data/constants/ChainSpecific';
import { Address } from 'wagmi';
Expand Down Expand Up @@ -120,3 +123,70 @@ export async function fetchListOfBorrowerNfts(

return { borrowers, tokenIds, indices };
}

export async function fetchListOfFuse2BorrowNfts(
chainId: number,
provider: ethers.providers.BaseProvider,
userAddress: Address,
uniswapPool?: Address
): Promise<
Array<{
borrowerAddress: Address;
tokenId: string;
index: number;
}>
> {
const originalBorrowerNfts = await fetchListOfBorrowerNfts(chainId, provider, userAddress, {
includeFreshBorrowers: false, // TODO: change later
onlyCheckMostRecentModify: true, // TODO: Hayden has concerns (as usual)
validManagerSet: new Set([ALOE_II_SIMPLE_MANAGER_ADDRESS[chainId], ALOE_II_PERMIT2_MANAGER_ADDRESS[chainId]]),
validUniswapPool: uniswapPool,
});

const slot0Contexts: ContractCallContext[] = originalBorrowerNfts.borrowers.map((borrower) => {
return {
abi: borrowerAbi as any,
calls: [
{
methodName: 'slot0',
methodParameters: [],
reference: 'slot0',
},
],
contractAddress: borrower,
reference: borrower,
};
});

// Execute multicall fetch
const multicall = new Multicall({
ethersProvider: provider,
tryAggregate: true,
multicallCustomContractAddress: MULTICALL_ADDRESS[chainId],
});

const slot0Results = await multicall.call(slot0Contexts);

const filterMap = originalBorrowerNfts.borrowers.map((borrower) => {
const result = slot0Results.results[borrower];
const slot0Hex = result.callsReturnContext[0].returnValues[0].hex;
const extraDataHex: string = slot0Hex.slice(14, 30);
return extraDataHex.endsWith('83ee755b');
});

const borrowerNfts: Array<{
borrowerAddress: Address;
tokenId: string;
index: number;
}> = [];
for (let i = 0; i < originalBorrowerNfts.borrowers.length; i++) {
if (!filterMap[i]) continue;
borrowerNfts.push({
borrowerAddress: originalBorrowerNfts.borrowers[i],
index: originalBorrowerNfts.indices[i],
tokenId: originalBorrowerNfts.tokenIds[i],
});
}

return borrowerNfts;
}
8 changes: 8 additions & 0 deletions earn/src/pages/MarketsPage.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ import {
import { fetchMarginAccounts, MarginAccount } from '../data/MarginAccount';
import { PriceRelayLatestResponse } from '../data/PriceRelayResponse';
import { getProminentColor } from '../util/Colors';
// import { fetchListOfFuse2BorrowNfts } from '../data/BorrowerNft';

export type TokenQuote = {
token: Token;
Expand Down Expand Up @@ -149,6 +150,13 @@ export default function MarketsPage() {
})();
}, [userAddress, borrowerLensContract, provider, availablePools, setMarginAccounts]);

useEffect(() => {
(async () => {
if (userAddress === undefined) return;
//const fuse2BorrowerNfts = await fetchListOfFuse2BorrowNfts(activeChain.id, provider, userAddress);
})();
}, [activeChain.id, provider, userAddress]);

const combinedBalances: TokenBalance[] = useMemo(() => {
if (tokenQuotes.length === 0) {
return [];
Expand Down
4 changes: 4 additions & 0 deletions shared/src/data/constants/Addresses.ts
Original file line number Diff line number Diff line change
Expand Up @@ -51,3 +51,7 @@ export const ALOE_II_BOOST_MANAGER_BASE = '0xAAE7aB9b8FBA833699842aC5f198CEFE384
export const ALOE_II_BORROWER_NFT_ADDRESS_OPTIMISM = '0x460d71e21e1768d943B1573B8B71399Ee7d84134';
export const ALOE_II_BORROWER_NFT_ADDRESS_ARBITRUM = '0x5e8D8Fb3Dd504bE6dCb535eaaacC0cdDFa086C9e';
export const ALOE_II_BORROWER_NFT_ADDRESS_BASE = '0xFB7d202BaFfeDc92Efc3E32aDB00B80F459FA9C5';

export const ALOE_II_PERMIT2_MANAGER_ADDRESS_OPTIMISM = '0xF9FBA8a3f471B78127b60eA343FD73ad20C15578';
export const ALOE_II_PERMIT2_MANAGER_ADDRESS_ARBITRUM = '0xac340D6428052e396640726ed278774C738cfC4F';
export const ALOE_II_PERMIT2_MANAGER_ADDRESS_BASE = '0xF9FBA8a3f471B78127b60eA343FD73ad20C15578'; // TODO: update
9 changes: 9 additions & 0 deletions shared/src/data/constants/ChainSpecific.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,9 @@ import {
ALOE_II_BOOST_MANAGER_OPTIMISM,
ALOE_II_BOOST_MANAGER_ARBITRUM,
ALOE_II_BOOST_MANAGER_BASE,
ALOE_II_PERMIT2_MANAGER_ADDRESS_OPTIMISM,
ALOE_II_PERMIT2_MANAGER_ADDRESS_ARBITRUM,
ALOE_II_PERMIT2_MANAGER_ADDRESS_BASE,
} from './Addresses';

export const BRIDGE_SUPPORTED_CHAINS = [mainnet, optimism, arbitrum];
Expand Down Expand Up @@ -152,3 +155,9 @@ export const ALOE_II_BOOST_MANAGER_ADDRESS: { [chainId: number]: Address } = {
[arbitrum.id]: ALOE_II_BOOST_MANAGER_ARBITRUM,
[base.id]: ALOE_II_BOOST_MANAGER_BASE,
};

export const ALOE_II_PERMIT2_MANAGER_ADDRESS: { [chainId: number]: Address } = {
[optimism.id]: ALOE_II_PERMIT2_MANAGER_ADDRESS_OPTIMISM,
[arbitrum.id]: ALOE_II_PERMIT2_MANAGER_ADDRESS_ARBITRUM,
[base.id]: ALOE_II_PERMIT2_MANAGER_ADDRESS_BASE,
};

0 comments on commit b2ea422

Please sign in to comment.