import { fetchData, print } from './helper'; export async function getUfogeesHolders(url: string): Promise { let allData = []; for (;;) { const data = JSON.stringify({ query: `{ ufogeesHolders { id holder tokenId timestamp } }`, }); const options = { url, headers: { 'Content-Type': 'application/json' }, body: data, }; const result = await fetchData(options); // print({ result }); if (result.errors) { print(result.errors); throw new Error('Error while fetching data from subgraph'); } else { allData.push(...result.data.ufogeesHolders); return allData; } } } export async function getUfogeesByHolder(url: string, address: string): Promise { let allData = []; for (;;) { const data = JSON.stringify({ query: `{ ufogeesHolders(where:{holder:"${address.toLowerCase()}"}) { id holder tokenId timestamp } }`, }); const options = { url, headers: { 'Content-Type': 'application/json' }, body: data, }; const result = await fetchData(options); // print({ result }); if (result.errors) { print(result.errors); throw new Error('Error while fetching data from subgraph'); } else { allData.push(...result.data.ufogeesHolders); return allData; } } } export async function getNFTHolders(url: string): Promise { let allData = []; for (;;) { const data = JSON.stringify({ query: `{ ufogeesMints { id holder amount mintType blockNumber timestamp } }`, }); const options = { url, headers: { 'Content-Type': 'application/json' }, body: data, }; const result = await fetchData(options); // print({ result }); if (result.errors) { print(result.errors); throw new Error('Error while fetching data from subgraph'); } else { allData.push(...result.data.ufogeesMints); return allData; } } } export async function getPresaleHolders(url: string): Promise { let allData = []; for (;;) { const data = JSON.stringify({ query: `{ ufogeesMints(where:{mintType: 0}) { id holder amount mintType blockNumber timestamp } }`, }); const options = { url, headers: { 'Content-Type': 'application/json' }, body: data, }; const result = await fetchData(options); // print({ result }); if (result.errors) { print(result.errors); throw new Error('Error while fetching data from subgraph'); } else { allData.push(...result.data.ufogeesMints); return allData; } } } export async function getBreedingNFT(url: string, address: string): Promise { let allData = []; for (;;) { const data = JSON.stringify({ query: `{ ufogeesBreeds(where:{creator: "${address.toLowerCase()}"}) { id creator ufogees1 ufogees2 releaseTime lockTime cancelTime claimTime state rewardType rewardCount } }`, }); const options = { url, headers: { 'Content-Type': 'application/json' }, body: data, }; const result = await fetchData(options); // print({ result }); if (result.errors) { print(result.errors); throw new Error('Error while fetching data from subgraph'); } else { allData.push(...result.data.ufogeesBreeds); return allData; } } } export async function getLockedBreedingNFT(url: string, address: string, timestamp: BigInt): Promise { let allData = []; for (;;) { const data = JSON.stringify({ query: `{ ufogeesBreeds(where:{creator: "${address.toLowerCase()}"}) { id creator ufogees1 ufogees2 releaseTime lockTime cancelTime claimTime state rewardType rewardCount } }`, }); const options = { url, headers: { 'Content-Type': 'application/json' }, body: data, }; const result = await fetchData(options); // print({ result }); if (result.errors) { print(result.errors); throw new Error('Error while fetching data from subgraph'); } else { result.data.ufogeesBreeds.map((item, index) => { if (Number(item.releaseTime) * 1000 > Number(timestamp)) { allData.push(item); } }); // allData.push(...result.data.ufogeesBreeds); return allData; } } } export async function getAvailableBreedingNFT(url: string, address: string, timestamp: BigInt): Promise { let allData = []; for (;;) { const data = JSON.stringify({ query: `{ ufogeesBreeds(where:{creator: "${address.toLowerCase()}"}) { id creator ufogees1 ufogees2 releaseTime lockTime cancelTime claimTime state rewardType rewardCount } }`, }); const options = { url, headers: { 'Content-Type': 'application/json' }, body: data, }; const result = await fetchData(options); // print({ result }); if (result.errors) { print(result.errors); throw new Error('Error while fetching data from subgraph'); } else { result.data.ufogeesBreeds.map((item, index) => { if (Number(item.releaseTime) * 1000 <= Number(timestamp)) { allData.push(item); } }); // allData.push(...result.data.ufogeesBreeds); return allData; } } } export async function getPublicHolders(url: string): Promise { let allData = []; for (;;) { const data = JSON.stringify({ query: `{ ufogeesMints(where:{mintType: 1}) { id holder amount mintType blockNumber timestamp } }`, }); const options = { url, headers: { 'Content-Type': 'application/json' }, body: data, }; const result = await fetchData(options); // print({ result }); if (result.errors) { print(result.errors); throw new Error('Error while fetching data from subgraph'); } else { allData.push(...result.data.ufogeesMints); return allData; } } }