Skip to content

Commit

Permalink
Remove sync reports from sync script
Browse files Browse the repository at this point in the history
  • Loading branch information
ae2079 committed Oct 21, 2024
1 parent 8bcd7b5 commit 113c95c
Show file tree
Hide file tree
Showing 3 changed files with 6 additions and 89 deletions.
33 changes: 3 additions & 30 deletions src/scripts/runScript.ts
Original file line number Diff line number Diff line change
@@ -1,38 +1,11 @@
/* eslint-disable no-console */
import path from 'path';
import fs from 'fs-extra';
import { syncDonationsWithBlockchainData } from './syncDataWithInverter';
import { repoLocalDir, reportsDir, getReportsSubDir } from './configs';
import { ensureDirectoryExists } from './helpers';

// copy reports from output of funding pot service
async function copyReports() {
const reportsSubDir = getReportsSubDir();
// Copy the report files from the subdirectory to the output folder
const reportFilesDir = path.join(repoLocalDir, reportsSubDir);
ensureDirectoryExists(reportsDir);

if (fs.existsSync(reportFilesDir)) {
fs.emptyDirSync(reportsDir); // Clear the destination folder first
fs.copySync(reportFilesDir, reportsDir, { recursive: true }); // Copy recursively
console.info('Report files copied successfully.');
} else {
console.error(
`Subdirectory ${reportsSubDir} does not exist in the repository.`,
);
}
}
import { syncDonationsWithIndexerData } from './syncDataWithInverter';

// Main function to pull reports and sync donations
async function main() {
try {
// Step 1: Pull the latest reports from GitHub
console.info('Start copy report files...');
await copyReports();
console.info('Reports were copy successfully.');

// Step 2: Sync donations with the blockchain data
await syncDonationsWithBlockchainData();
console.info('Start syncing data with indexer...');
await syncDonationsWithIndexerData();
console.info('Data synced successfully.');
process.exit();
} catch (error) {
Expand Down
53 changes: 2 additions & 51 deletions src/scripts/syncDataWithInverter.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,26 +6,17 @@ import {
saveProjectDirectlyToDb,
createProjectData,
generateRandomEtheriumAddress,
createDonationData,
saveDonationDirectlyToDb,
deleteProjectDirectlyFromDb,
saveEARoundDirectlyToDb,
} from '../../test/testUtils';
import { Donation } from '../entities/donation';
import { syncDonationsWithBlockchainData } from './syncDataWithInverter';
import { syncDonationsWithIndexerData } from './syncDataWithInverter';
import { InverterAdapter } from '../adapters/inverter/inverterAdapter';
import { EarlyAccessRound } from '../entities/earlyAccessRound';

describe.skip('Sync Donations Script Test Cases', () => {
let existingProjectIds: number[] = [];
let existingDonationIds: number[] = [];
beforeEach(async () => {
existingProjectIds =
(await Project.find({ select: ['id'] }))?.map(project => project.id) ||
[];
existingDonationIds =
(await Donation.find({ select: ['id'] }))?.map(donation => donation.id) ||
[];
});
afterEach(async () => {
sinon.restore();
Expand All @@ -48,37 +39,14 @@ describe.skip('Sync Donations Script Test Cases', () => {
},
});

const earlyAccessRound = await saveEARoundDirectlyToDb({
roundNumber: 1,
startDate: new Date('2024-09-01'),
endDate: new Date('2024-09-05'),
roundUSDCapPerProject: 1000000,
roundUSDCapPerUserPerProject: 50000,
tokenPrice: 0.12345678,
});

const donation = await saveDonationDirectlyToDb(
{
...createDonationData({ transactionId: '0x123' }),
fromWalletAddress: '0xce989336BdED425897Ac63d1359628E26E24f794', // got from inverter
blockNumber: 1234,
earlyAccessRoundId: earlyAccessRound.id,
},
undefined,
project.id,
);

sinon
.stub(InverterAdapter.prototype, 'getBlockTimestamp')
.resolves(1725987224);

await syncDonationsWithBlockchainData({
await syncDonationsWithIndexerData({
projectFilter: {
id: Not(In(existingProjectIds)),
},
donationFilter: {
id: Not(In(existingDonationIds)),
},
});

const updatedProject = await Project.findOneBy({
Expand All @@ -88,23 +56,6 @@ describe.skip('Sync Donations Script Test Cases', () => {
assert.equal(updatedProject?.abc.tokenPrice, 0.000000000000004444);
assert.equal(updatedProject?.abc.totalSupply, 201001.63618501218);

const updatedDonation = await Donation.findOneBy({
id: donation.id,
});

assert.equal(updatedDonation?.cliff, 2);
assert.equal(
updatedDonation?.rewardStreamStart?.getTime(),
new Date(1).getTime(),
);
assert.equal(
updatedDonation?.rewardStreamEnd?.getTime(),
new Date(10).getTime(),
);
assert.equal(updatedDonation?.rewardTokenAmount, 0.004);

await Donation.remove(donation);
await EarlyAccessRound.remove(earlyAccessRound);
await deleteProjectDirectlyFromDb(project.id);
});
});
9 changes: 1 addition & 8 deletions src/scripts/syncDataWithInverter.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,9 @@
/* eslint-disable no-console */
import { FindOptionsWhere } from 'typeorm';
import { Donation } from '../entities/donation';
import { Project } from '../entities/project';
import { InverterAdapter } from '../adapters/inverter/inverterAdapter';
import { AppDataSource } from '../orm';
import { getProvider, QACC_NETWORK_ID } from '../provider';
import { updateRewardsForDonations } from './syncDataWithJsonReport';

const adapter = new InverterAdapter(getProvider(QACC_NETWORK_ID));

Expand Down Expand Up @@ -86,23 +84,18 @@ async function fetchTokenTotalSupply(project: Project) {
}
}

export async function syncDonationsWithBlockchainData(
export async function syncDonationsWithIndexerData(
{
projectFilter,
donationFilter,
}: {
projectFilter: FindOptionsWhere<Project>;
donationFilter: FindOptionsWhere<Donation>;
} = {
projectFilter: {},
donationFilter: {},
},
) {
console.debug('bootstrap() before AppDataSource.initialize()', new Date());
await AppDataSource.initialize(false);
console.debug('bootstrap() after AppDataSource.initialize()', new Date());

await updateTokenPriceAndTotalSupplyForProjects(projectFilter);

await updateRewardsForDonations(donationFilter);
}

0 comments on commit 113c95c

Please sign in to comment.