Skip to content

Commit

Permalink
* Add a 'name' and 'symbol' field to the AvatarRow
Browse files Browse the repository at this point in the history
* Provide all three circles balances: CRC, Circles, Static Circles
* add new event type: CrcV2_DepositDemurraged, CrcV2_DepositInflationary, CrcV2_WithdrawDemurraged, CrcV2_WithdrawInflationary, CrcV2_Erc20WrapperTransfer, CrcV2_Erc20WrapperTransfer
* Return 'memberCount' and 'trustedCount' for groups
* add an option to 'getAvatar()' without subscribing to events
* Adapted to new tokenTypes returned by the nethermind indexer: "CrcV1_Signup" | "CrcV2_RegisterHuman" | "CrcV2_RegisterGroup" | "CrcV2_ERC20WrapperDeployed_Inflationary" | "CrcV2_ERC20WrapperDeployed_Demurraged"
  • Loading branch information
jaensen committed Sep 17, 2024
1 parent f594e2b commit 29d926e
Show file tree
Hide file tree
Showing 16 changed files with 449 additions and 243 deletions.
60 changes: 46 additions & 14 deletions packages/data/src/circlesData.ts
Original file line number Diff line number Diff line change
Expand Up @@ -95,35 +95,58 @@ function calculateBalances(row: TransactionHistoryRow) {
let circles: number;
let staticAttoCircles: bigint;
let staticCircles: number;
let attoCrc: bigint;
let crc: number;

if (tokenInfo?.isInflationary) {
staticAttoCircles = BigInt(rawBalance);
staticCircles = attoCirclesToCircles(staticAttoCircles);
if (row.version === 1) {
attoCrc = BigInt(rawBalance);
crc = attoCirclesToCircles(attoCrc);

circles = crcToTc(new Date(), staticAttoCircles);
circles = crcToTc(new Date(), attoCrc);
attoCircles = circlesToAttoCircles(circles);

staticCircles = crc * 3.0;
staticAttoCircles = attoCircles * 3n;
} else {
attoCircles = BigInt(rawBalance);
circles = attoCirclesToCircles(attoCircles);
if (tokenInfo?.isInflationary) {
staticAttoCircles = BigInt(rawBalance);
staticCircles = attoCirclesToCircles(staticAttoCircles);

circles = crcToTc(new Date(), staticAttoCircles / 3n);
attoCircles = circlesToAttoCircles(circles);

attoCrc = tcToCrc(new Date(), circles);
crc = attoCirclesToCircles(attoCrc);
} else {
attoCircles = BigInt(rawBalance);
circles = attoCirclesToCircles(attoCircles);

attoCrc = tcToCrc(new Date(), circles);
crc = attoCirclesToCircles(attoCrc);

staticAttoCircles = tcToCrc(new Date(), circles);
staticCircles = attoCirclesToCircles(staticAttoCircles);
staticAttoCircles = tcToCrc(new Date(), circles) * 3n;
staticCircles = attoCirclesToCircles(staticAttoCircles);
}
}

return {
attoCircles,
circles,
staticAttoCircles,
staticCircles
staticCircles,
attoCrc,
crc
};
} catch (e) {
console.error(e);
console.log(row);
// console.error(e);
// console.log(row);
return {
attoCircles: 0n,
circles: 0,
staticAttoCircles: 0n,
inflationaryCircles: 0
inflationaryCircles: 0,
attoCrc: 0n,
crc: 0
}
}
}
Expand Down Expand Up @@ -224,6 +247,12 @@ export class CirclesData implements CirclesDataInterface {
}, {
name: "staticAttoCircles",
generator: async (row: TransactionHistoryRow) => calculateBalances(row).staticAttoCircles
}, {
name: "crc",
generator: async (row: TransactionHistoryRow) => calculateBalances(row).crc
}, {
name: "attoCrc",
generator: async (row: TransactionHistoryRow) => calculateBalances(row).attoCrc
}]);
}

Expand Down Expand Up @@ -400,7 +429,8 @@ export class CirclesData implements CirclesDataInterface {
'type',
'avatar',
'tokenId',
'cidV0Digest'
'cidV0Digest',
'name'
],
filter: [
{
Expand Down Expand Up @@ -603,8 +633,10 @@ export class CirclesData implements CirclesDataInterface {
'name',
'symbol',
'cidV0Digest',
'memberCount',
'trustedCount'
],
sortOrder: 'DESC',
sortOrder: "DESC",
limit: pageSize
};

Expand Down
2 changes: 1 addition & 1 deletion packages/data/src/circlesDataInterface.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ export interface GroupQueryParams {
nameStartsWith?: string;
symbolStartsWith?: string;
groupAddressIn?: string[];
sortBy?: 'age_asc' | 'age_desc' | 'name_asc' | 'name_desc' | 'symbol_asc' | 'symbol_desc';
sortBy?: 'age_asc' | 'age_desc' | 'name_asc' | 'name_desc' | 'symbol_asc' | 'symbol_desc' | 'memberCount_desc' | 'memberCount_asc' | 'trustedCount_desc' | 'trustedCount_asc';
}

export interface CirclesDataInterface {
Expand Down
Loading

0 comments on commit 29d926e

Please sign in to comment.