Skip to content

Commit

Permalink
feat: support sepolia network (#12)
Browse files Browse the repository at this point in the history
  • Loading branch information
jackmellis committed Nov 22, 2023
1 parent c44f6c4 commit ec678f6
Show file tree
Hide file tree
Showing 27 changed files with 2,323 additions and 45 deletions.
2 changes: 1 addition & 1 deletion docs/config.md
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ config.configure({
ERC721_SUBGRAPH: 'custom-subgraph-endpoint',
},
urls: {
ALCHEMY_URL: 'custom-alchemy-url',
NFTX_API_URL: 'custom-url',
},
contracts: {
multicall: false,
Expand Down
4 changes: 1 addition & 3 deletions packages/config/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ import {
NON_STANDARD_SUBGRAPH,
NFTX_APR_URL,
Network,
ALCHEMY_URL,
NFTX_API_URL,
NFTX_ROUTER_URL,
NFTX_UNISWAP_SUBGRAPH,
Expand Down Expand Up @@ -40,7 +39,6 @@ export interface Config {
urls: {
NFTX_ROUTER_URL: Record<string, string>;
NFTX_APR_URL: Record<string, string>;
ALCHEMY_URL: Record<string, string>;
NFTX_API_URL: string;
};
/** Contract configuration options */
Expand Down Expand Up @@ -103,12 +101,12 @@ const defaultConfig: Config = {
urls: {
NFTX_ROUTER_URL,
NFTX_APR_URL,
ALCHEMY_URL,
NFTX_API_URL,
},
contracts: {
ethPrice: {
[Network.Goerli]: '2500000000', // $2.5k
[Network.Sepolia]: '2000000000', // $2k
},
},

Expand Down
12 changes: 12 additions & 0 deletions packages/constants/src/addresses.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,13 +19,15 @@ export const WETH_TOKEN = {
[Network.Mainnet]: a('0xc02aaa39b223fe8d0a0e5c4f27ead9083c756cc2'),
[Network.Arbitrum]: a('0x82af49447d8a07e3bd95bd0d56f35241523fbab1'),
[Network.Goerli]: a('0xb4fbf271143f4fbf7b91a5ded31805e42b2208d6'),
[Network.Sepolia]: a('0xfFf9976782d46CC05630D1f6eBAb18b2324d6B14'),
};

/** The address for USDC across networks */
export const USDC = {
[Network.Mainnet]: a('0xA0b86991c6218b36c1d19D4a2e9Eb0cE3606eB48'),
[Network.Arbitrum]: a('0xff970a61a04b1ca14834a43f5de4533ebddb5cc8'),
[Network.Goerli]: a('0x2f3a40a3db8a7e3d09b0adfefbce4f6f81927557'),
[Network.Sepolia]: a('0x2C032Aa43D119D7bf4Adc42583F1f94f3bf3023a'),
};

export const OPENSEA_COLLECTION = a(
Expand All @@ -35,48 +37,58 @@ export const OPENSEA_COLLECTION = a(
/** Zap specifically for creating new vaults */
export const CREATE_VAULT_ZAP = {
[Network.Goerli]: a('0xFA7d98Ec2b046e636c45A0291F931b94a5a1CA59'),
[Network.Sepolia]: a('0x50f69c6556338965bf77C16ADb462Fdb5bE01C09'),
};

/** Perform buy/sell/swaps */
export const MARKETPLACE_ZAP = {
[Network.Goerli]: a('0x5A40C0288d23E83a23bb16C29B790F7e49e49ee6'),
[Network.Sepolia]: a('0x5Af324A8c90966Bef28386A67c6bE0A16aA03c19'),
};

/** Stake NFTs or vTokens for xNFTs */
export const INVENTORY_STAKING = {
[Network.Goerli]: a('0xEf771a17e6970d8B4b208a76e94F175277554230'),
[Network.Sepolia]: a('0xfBFf0635f7c5327FD138E1EBa72BD9877A6a7C1C'),
};

/** AMM Router (Universal Router / nftxUniversalRouter) */
export const NFTX_ROUTER = {
[Network.Goerli]: a('0xF7c4FC5C2e30258e1E4d1197fc63aeDE371508f3'),
[Network.Sepolia]: a('0x12156cCA1958B6591CC49EaE03a5553458a4b424'),
};

/** Staking / Liquidity / Pools (NftxRouter) */
export const POOL_ROUTER = {
[Network.Goerli]: a('0xb95e2Fb1eDA32BbFbDaE2463BB3E64bb3E1E41D5'),
[Network.Sepolia]: a('0xD36ece08F76c50EC3F01db65BBc5Ef5Aa5fbE849'),
};

export const NONFUNGIBLE_POSITION_MANAGER = {
[Network.Goerli]: a('0xaEC6537206e8e590603399c714c39947680f1181'),
[Network.Sepolia]: a('0x55BDc76262B1e6e791D0636A0bC61cee23CDFa87'),
};

/** The permit2 contract, needs an approval signature because the UniversalRouter only transfers tokens from user via Permit2 */
export const PERMIT2 = {
[Network.Goerli]: a('0x000000000022d473030f116ddee9f6b43ac78ba3'),
[Network.Sepolia]: a('0x000000000022d473030f116ddee9f6b43ac78ba3'),
};

/** ENS Address */
export const ENS_REGISTRAR = {
[Network.Mainnet]: a('0x57f1887a8BF19b14fC0dF6Fd9B2acc9Af147eA85'),
[Network.Arbitrum]: a('0x57f1887a8BF19b14fC0dF6Fd9B2acc9Af147eA85'),
[Network.Goerli]: a('0x57f1887a8BF19b14fC0dF6Fd9B2acc9Af147eA85'),
[Network.Sepolia]: a('0x57f1887a8bf19b14fc0df6fd9b2acc9af147ea85'),
};

export const AMM_FACTORY = {
[Network.Goerli]: a('0xf25081B098c5929A26F562aa2502795fE89BC73f'),
[Network.Sepolia]: a('0xDD2dce9C403f93c10af1846543870D065419E70b'),
};

export const VAULT_FACTORY = {
[Network.Goerli]: a('0x1d552A0e6c2f680872C4a88b1e7def05F1858dF0'),
[Network.Sepolia]: a('0x31C56CaF49125043e80B4d3C7f8734f949d8178C'),
};
4 changes: 2 additions & 2 deletions packages/constants/src/networks.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
export enum Network {
Mainnet = 1,
Rinkeby = 4,
Arbitrum = 42161,
Arbitrum = 42_161,
Goerli = 5,
Sepolia = 11_155_111,
}
9 changes: 8 additions & 1 deletion packages/constants/src/subgraph.ts
Original file line number Diff line number Diff line change
Expand Up @@ -47,13 +47,17 @@ export const ERC721_SUBGRAPH = {
[Network.Arbitrum]: `${SHARED_PROXY_ROOT}/quantumlyy/eip721-subgraph-arbitrum`,
[Network.Goerli]:
'https://api.thegraph.com/subgraphs/name/nftx-project/eip721-looksrare-goerli',
[Network.Sepolia]:
'https://api.thegraph.com/subgraphs/name/nftx-project/721-sepolia-data-nexus',
};

export const ERC1155_SUBGRAPH = {
[Network.Mainnet]: `${GATEWAY_PROXY_ROOT}/GCQVLurkeZrdMf4t5v5NyeWJY8pHhfE9sinjFMjLYd9C`,
[Network.Arbitrum]: `${SHARED_PROXY_ROOT}/quantumlyy/eip1155-subgraph-arbitrum`,
[Network.Goerli]:
'https://api.thegraph.com/subgraphs/name/nftx-project/eip1155-looksrare-goerli',
[Network.Sepolia]:
'https://api.thegraph.com/subgraphs/name/nftx-project/1155-sepolia-data-nexus',
};

export const NFTX_SUBGRAPH_MAINNET_URLS = {
Expand All @@ -80,11 +84,14 @@ export const NFTX_SUBGRAPH = {
NFTX_SUBGRAPH_MAINNET_URLS.SHARED,
],
[Network.Arbitrum]: `${SHARED_ROOT}/nftx-project/nftx-v2-arbitrum`,
// [Network.Goerli]: `${SHARED_ROOT}/nftx-project/nftx-v2-1-goerli`,
[Network.Goerli]:
'https://api.thegraph.com/subgraphs/name/gundamdweeb/nftx-v3-vaults',
[Network.Sepolia]:
'https://api.thegraph.com/subgraphs/name/nftx-project/nftx-v3-vaults-sepolia',
};

export const NFTX_UNISWAP_SUBGRAPH = {
[Network.Goerli]: `https://api.thegraph.com/subgraphs/name/gundamdweeb/nftx-amm`,
[Network.Sepolia]:
'https://api.thegraph.com/subgraphs/name/nftx-project/nftx-v3-amm-sepolia',
};
12 changes: 3 additions & 9 deletions packages/constants/src/urls.ts
Original file line number Diff line number Diff line change
@@ -1,27 +1,21 @@
import { Network } from './networks';

export const NFTX_ROUTER_URL = {
[Network.Goerli]:
'https://lmw8qdcm7e.execute-api.eu-central-1.amazonaws.com/prod/quote',
[Network.Goerli]: 'https://api.nftx.xyz/v3/eth-goerli/quote',
[Network.Sepolia]: 'https://api.nftx.xyz/v3/eth-sepolia/quote',
};

export const NFTX_APR_URL = {
[Network.Mainnet]: 'https://data.nftx.xyz/vaultaprs',
[Network.Rinkeby]: 'https://data.nftx.xyz/vaultaprs',
[Network.Arbitrum]: 'https://data.nftx.xyz/vaultaprs',
[Network.Goerli]: 'https://data.nftx.xyz/vaultaprs',
};

export const ALCHEMY_URL = {
[Network.Mainnet]: 'https://eth-mainnet.g.alchemy.com',
[Network.Goerli]: 'https://eth-goerli.g.alchemy.com',
[Network.Arbitrum]: 'https://arb-mainnet.g.alchemy.com',
};

export const NFTX_API_URL = 'https://api-v3.nftx.xyz';

export const RESERVOIR_URL = {
[Network.Mainnet]: 'https://api.reservoir.tools',
[Network.Goerli]: 'https://api-goerli.reservoir.tools',
[Network.Arbitrum]: 'https://api-arbitrum.reservoir.tools',
[Network.Sepolia]: 'https://api-sepolia.reservoir.tools',
};
8 changes: 7 additions & 1 deletion packages/constants/src/values.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,11 @@
import { Network } from './networks';

export const WeiPerEther = 1000000000000000000n;
export const Zero = 0n;
export const MaxUint256 =
115792089237316195423570985008687907853269984665640564039457584007913129639935n;
export const PREMIUM_DURATION = 36000;

export const PREMIUM_DURATION = {
[Network.Goerli]: 36000, // 10 hours
[Network.Sepolia]: 3600, // 1 hour
};
71 changes: 67 additions & 4 deletions packages/core/src/assets/fetchUserHoldings/fetchErc1155s.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import config from '@nftx/config';
import { gql, querySubgraph } from '@nftx/subgraph';
import type { Address } from '@nftx/types';
import { createQuery, gql, querySubgraph } from '@nftx/subgraph';
import type { Address, ERC1155Sepolia, TokenId } from '@nftx/types';
import { getChainConstant } from '@nftx/utils';
import { createCursor, parseCursor } from './cursor';
import { parseEther } from 'viem';
Expand Down Expand Up @@ -80,14 +80,66 @@ const makeFetchErc1155sMainnet =
const holdings = balances.map((x) => {
return {
assetAddress: x.contract.id,
tokenId: BigInt(x.token.identifier).toString(),
tokenId: BigInt(x.token.identifier).toString() as TokenId,
quantity: Number(x.value) < 1 ? parseEther(x.value) : BigInt(x.value),
};
});

return [holdings, createCursor('1155', nextId)] as const;
};

const makeFetchErc1155sSepolia =
({ querySubgraph }: { querySubgraph: QuerySubgraph }) =>
async ({
lastId,
network,
userAddress,
}: {
network: number;
lastId: string;
userAddress: Address;
}) => {
let holdings: Array<Holding> = [];
let nextId: string | undefined;

const q = createQuery<ERC1155Sepolia.Query>();

const query = q.account.id(userAddress).select((s) => [
s.holdings(
q.holdings
.first(1000)
.orderBy('id')
.orderDirection('asc')
.where((w) => [w.id.gt(lastId)])
.select((s) => [
s.id,
s.balance,
s.token((t) => [t.identifier, t.collection((c) => [c.id])]),
])
),
]);

const data = await querySubgraph({
url: getChainConstant(config.subgraph.ERC1155_SUBGRAPH, network),
query,
});

if (data?.account?.holdings?.length) {
holdings = data.account.holdings.map((x) => {
return {
assetAddress: x.token.collection.id as Address,
tokenId: BigInt(x.token.identifier).toString() as TokenId,
quantity: BigInt(x.balance || '1'),
};
});
}
if (data?.account?.holdings?.length === 1000) {
nextId = data.account.holdings[data.account.holdings.length - 1].id;
}

return [holdings, nextId] as const;
};

const makeFetchErc1155sGoerli =
({ querySubgraph }: { querySubgraph: QuerySubgraph }) =>
async ({
Expand Down Expand Up @@ -144,7 +196,7 @@ const makeFetchErc1155sGoerli =
holdings = data.owners[0].tokens.map((x) => {
return {
assetAddress: x.collection.id,
tokenId: x.tokenID,
tokenId: BigInt(x.tokenID).toString() as TokenId,
};
});
}
Expand All @@ -161,16 +213,19 @@ const makeFetchErc1155sArbitrum = makeFetchErc1155sMainnet;
type FetchErc1155sMainnet = ReturnType<typeof makeFetchErc1155sMainnet>;
type FetchErc1155sGoerli = ReturnType<typeof makeFetchErc1155sGoerli>;
type FetchErc1155sArbitrum = ReturnType<typeof makeFetchErc1155sArbitrum>;
type FetchErc1155sSepolia = ReturnType<typeof makeFetchErc1155sSepolia>;

const makeFetchErc1155s =
({
fetchErc1155sArbitrum,
fetchErc1155sGoerli,
fetchErc1155sMainnet,
fetchErc1155sSepolia,
}: {
fetchErc1155sMainnet: FetchErc1155sMainnet;
fetchErc1155sGoerli: FetchErc1155sGoerli;
fetchErc1155sArbitrum: FetchErc1155sArbitrum;
fetchErc1155sSepolia: FetchErc1155sSepolia;
}) =>
async ({
userAddress,
Expand Down Expand Up @@ -203,6 +258,13 @@ const makeFetchErc1155s =
userAddress,
});
break;
case Network.Sepolia:
[holdings, nextId] = await fetchErc1155sSepolia({
lastId,
network,
userAddress,
});
break;
case Network.Arbitrum:
[holdings, nextId] = await fetchErc1155sArbitrum({
lastId,
Expand All @@ -224,4 +286,5 @@ export default makeFetchErc1155s({
fetchErc1155sArbitrum: makeFetchErc1155sArbitrum({ querySubgraph }),
fetchErc1155sGoerli: makeFetchErc1155sGoerli({ querySubgraph }),
fetchErc1155sMainnet: makeFetchErc1155sMainnet({ querySubgraph }),
fetchErc1155sSepolia: makeFetchErc1155sSepolia({ querySubgraph }),
});
Loading

0 comments on commit ec678f6

Please sign in to comment.