Skip to content

Commit

Permalink
Fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
Boldizsar Mezei committed May 10, 2024
1 parent b091fd0 commit 5707801
Showing 1 changed file with 10 additions and 4 deletions.
14 changes: 10 additions & 4 deletions packages/functions/scripts/dbUpgrades/soon.snapshot.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { MilestoneTransactions, database } from '@buildcore/database';
import { COL, Network, SUB_COL, TokenDropStatus } from '@buildcore/interfaces';
import { COL, Member, Network, SUB_COL, TokenDropStatus } from '@buildcore/interfaces';
import {
Address,
AddressType,
Expand Down Expand Up @@ -38,7 +38,8 @@ export const soonSnapshot = async (tokenId?: string, network?: Network.SMR | Net
MILESTONE_COL = NETWORK === Network.SMR ? COL.MILESTONE_SMR : COL.MILESTONE_RMS;
tokensPerAddress = {};

await database().getCon()(COL.SOON_SNAP).delete();
const deleted = await database().getCon()(COL.SOON_SNAP).delete();
console.log('deleted', deleted);

await createSoonSnapshot();
const tokensPerMember = await addressesToMembers();
Expand Down Expand Up @@ -100,7 +101,7 @@ const createSoonSnapshot = async () => {
const addressesToMembers = async () => {
const tokensPerMember: { [key: string]: number } = {};

const batches = chunk(Object.entries(tokensPerAddress), 100);
const batches = chunk(Object.entries(tokensPerAddress), 10);
let count = 0;
console.log('addressesToMembers', 'total', Object.entries(tokensPerAddress).length);

Expand All @@ -119,17 +120,22 @@ const addressesToMembers = async () => {
return tokensPerMember;
};

const members: { [key: string]: Member } = {};

const addressToMember = async (address: string, count: number) => {
const tokensPerMember: { [key: string]: number } = {};
console.log('addressToMember', 'getting airdrops', address);
const airdropsSnap = await database()
.collection(COL.AIRDROP)
.where('sourceAddress', '==', address)
.where('status', '==', TokenDropStatus.UNCLAIMED)
.get();
console.log('addressToMember', 'airdrops', airdropsSnap.length);

for (const airdrop of airdropsSnap) {
if (airdrop.member.startsWith('0x')) {
const member = await database().doc(COL.MEMBER, airdrop.member).get();
const member =
members[airdrop.member] || (await database().doc(COL.MEMBER, airdrop.member).get());
const memberAddress = member?.validatedAddress?.[NETWORK] || airdrop.member;
tokensPerMember[memberAddress] = (tokensPerMember[memberAddress] || 0) + airdrop.count;
continue;
Expand Down

0 comments on commit 5707801

Please sign in to comment.