diff --git a/src/magpie/magpie.controller.ts b/src/magpie/magpie.controller.ts index 3d12773..4f5aa62 100644 --- a/src/magpie/magpie.controller.ts +++ b/src/magpie/magpie.controller.ts @@ -50,7 +50,7 @@ export class MagpieController { try { pointData = await this.magpieService.getPointsData(address); } catch (err) { - this.logger.error("Get magpie all points failed", err); + this.logger.error("Get magpie all points failed", err.stack); return SERVICE_EXCEPTION; } return this.getReturnData( diff --git a/src/magpie/magpie.service.ts b/src/magpie/magpie.service.ts index 37a995e..d92670b 100644 --- a/src/magpie/magpie.service.ts +++ b/src/magpie/magpie.service.ts @@ -1,5 +1,4 @@ import { Injectable, Logger } from "@nestjs/common"; -import { cloneDeep } from "lodash"; import { GraphQueryService } from "../common/service/graphQuery.service"; import { LocalPointsItem } from "../common/service/projectGraph.service"; import waitFor from "src/utils/waitFor"; @@ -37,6 +36,10 @@ export interface MagpieData { localTotalPoints: bigint; realTotalEigenpiePoints: bigint; realTotalEigenLayerPoints: bigint; + itemMaps?: Map< + string, + MagpiePointItemWithBalance[] | MagpiePointItemWithoutBalance[] + >; items: MagpiePointItemWithBalance[] | MagpiePointItemWithoutBalance[]; } @@ -50,6 +53,7 @@ export class MagpieService extends Worker { localTotalPoints: 0n, realTotalEigenpiePoints: 0n, realTotalEigenLayerPoints: 0n, + itemMaps: new Map(), items: [], }; @@ -154,11 +158,23 @@ export class MagpieService extends Worker { }; data.push(pointsItem); } + + const itemMaps = new Map(); + for (let i = 0; i < data.length; i++) { + const item = data[i]; + if (!itemMaps.has(item.address)) { + itemMaps.set(item.address, [item]); + } else { + const tmpItems = itemMaps.get(item.address); + itemMaps.set(item.address, [...tmpItems, item]); + } + } if (data.length > 0) { this.magpieData = { localTotalPoints: localTotalPoints, realTotalEigenpiePoints: realTotalPointsData.eigenpiePoints, realTotalEigenLayerPoints: realTotalPointsData.eigenLayerPoints, + itemMaps: itemMaps, items: data, }; } else { @@ -168,14 +184,14 @@ export class MagpieService extends Worker { // return points data public getPointsData(address?: string): MagpieData { - let result: MagpieData = cloneDeep(this.magpieData); - if (address) { - const _address = address.toLocaleLowerCase(); - result.items = this.magpieData.items.filter( - (item) => item.address === _address, - ); - } - return result; + return { + localTotalPoints: this.magpieData.localTotalPoints, + realTotalEigenpiePoints: this.magpieData.realTotalEigenpiePoints, + realTotalEigenLayerPoints: this.magpieData.realTotalEigenLayerPoints, + items: address + ? this.magpieData.itemMaps.get(address) ?? [] + : this.magpieData.items, + }; } // return local points and totalPoints @@ -190,7 +206,6 @@ export class MagpieService extends Worker { // return real points group by address public getPointsDataGroupByAddress(): MagpieData { - let result: MagpieData = cloneDeep(this.magpieData); let data: Map = new Map(); const now = (new Date().getTime() / 1000) | 0; for (let i = 0; i < this.magpieData.items.length; i++) { @@ -208,7 +223,11 @@ export class MagpieService extends Worker { tmpItem.realEigenpiePoints += item.realEigenpiePoints; } } - result.items = Array.from(data.values()); - return result; + return { + localTotalPoints: this.magpieData.localTotalPoints, + realTotalEigenpiePoints: this.magpieData.realTotalEigenpiePoints, + realTotalEigenLayerPoints: this.magpieData.realTotalEigenLayerPoints, + items: Array.from(data.values()), + }; } } diff --git a/src/renzo/renzo.service.ts b/src/renzo/renzo.service.ts index 6315aa6..be5eede 100644 --- a/src/renzo/renzo.service.ts +++ b/src/renzo/renzo.service.ts @@ -8,7 +8,6 @@ import { import { GraphQueryService } from "src/common/service/graphQuery.service"; import { RenzoApiService, RenzoPoints } from "src/renzo/renzoapi.service"; import { ExplorerService } from "src/common/service/explorer.service"; -import { cloneDeep } from "lodash"; import BigNumber from "bignumber.js"; import waitFor from "src/utils/waitFor"; import { Worker } from "src/common/worker"; @@ -30,6 +29,7 @@ export interface RenzoData { localTotalPoints: bigint; realTotalRenzoPoints: number; realTotalEigenLayerPoints: number; + itemMaps?: Map; items: RenzoPointItem[]; } @@ -43,6 +43,7 @@ export class RenzoService extends Worker { localTotalPoints: BigInt(0), realTotalRenzoPoints: 0, realTotalEigenLayerPoints: 0, + itemMaps: new Map(), items: [], }; private readonly l1Erc20BridgeEthereum: string; @@ -84,7 +85,7 @@ export class RenzoService extends Worker { } // load points data - public async loadPointsData() { + private async loadPointsData() { // get tokens from graph const tokens = this.graphQueryService.getAllTokenAddresses( this.projectName, @@ -96,19 +97,10 @@ export class RenzoService extends Worker { this.tokenAddress = tokens; const realTokenTotalPoints = await this.getRealPointsData(); - this.logger.log( - "renzoLog: realTokenTotalPoints:", - realTokenTotalPoints.size, - ); const pointsData = await this.getLocalPointsData(); - this.logger.log("renzoLog: pointsData"); const localPoints = pointsData.localPoints; const localTotalPoints = pointsData.localTotalPoints; const tokensMapBridgeTokens = await this.getTokensMapBriageTokens(); - this.logger.log( - "renzoLog: tokensMapBridgeTokens:", - tokensMapBridgeTokens.size, - ); if ( tokensMapBridgeTokens.size < 1 || localPoints.length < 1 || @@ -127,10 +119,6 @@ export class RenzoService extends Worker { const transferFaildPoints = this.projectGraphService.getTransferFaildPoints( this.tokenAddress, ); - this.logger.log( - "renzoLog: transferFaildPoints:", - transferFaildPoints.length, - ); const localPointsMap = new Map(); const totalPointsPerTokenMap = new Map(); const now = (new Date().getTime() / 1000) | 0; @@ -139,7 +127,7 @@ export class RenzoService extends Worker { totalPointsPerTokenMap.set(item.token, item.totalPointsPerToken); localPointsMap.set(key, item); } - this.logger.log("renzoLog: localPointsMap:", localPointsMap.size); + // loop transferFaildData, and added transferFaildPoint to localPoints for (const item of transferFaildPoints) { const key = `${item.address}_${item.tokenAddress}`; @@ -166,7 +154,6 @@ export class RenzoService extends Worker { } } // end added transferFaildPoint - this.logger.log("renzoLog: end added transferFaildPoint"); for (const [, point] of localPointsMap) { const tokenAddress = point.token.toLocaleLowerCase(); if (!tokenAddress) { @@ -210,12 +197,23 @@ export class RenzoService extends Worker { }; data.push(pointsItem); } - this.logger.log("renzoLog: data", data.length); + + const itemMaps = new Map(); + for (let i = 0; i < data.length; i++) { + const item = data[i]; + if (!itemMaps.has(item.address)) { + itemMaps.set(item.address, [item]); + } else { + const tmpItems = itemMaps.get(item.address); + itemMaps.set(item.address, [...tmpItems, item]); + } + } if (data.length > 0) { this.renzoData = { localTotalPoints: localTotalPoints, realTotalRenzoPoints: realTotalRenzoPoints, realTotalEigenLayerPoints: realTotalEigenLayerPoints, + itemMaps: itemMaps, items: data, }; } else { @@ -225,23 +223,24 @@ export class RenzoService extends Worker { // return points data public getPointsData(address?: string): RenzoData { - const result: RenzoData = cloneDeep(this.renzoData); - if (address) { - const _address = address.toLocaleLowerCase(); - result.items = this.renzoData.items.filter( - (item) => item.address === _address, - ); - } + const result: RenzoData = { + localTotalPoints: this.renzoData.localTotalPoints, + realTotalRenzoPoints: this.renzoData.realTotalRenzoPoints, + realTotalEigenLayerPoints: this.renzoData.realTotalEigenLayerPoints, + items: address + ? this.renzoData.itemMaps.get(address) ?? [] + : this.renzoData.items, + }; return result; } // return local points and totalPoints - public async getLocalPointsData(): Promise { + private async getLocalPointsData(): Promise { return await this.projectGraphService.getPoints(this.projectName); } // return real totalPoints - public async getRealPointsData(): Promise> { + private async getRealPointsData(): Promise> { return await this.renzoApiService.fetchTokensRenzoPoints(); } diff --git a/src/renzo/renzoapi.service.ts b/src/renzo/renzoapi.service.ts index 5799a45..32c8644 100644 --- a/src/renzo/renzoapi.service.ts +++ b/src/renzo/renzoapi.service.ts @@ -43,7 +43,7 @@ export class RenzoApiService { for (const bridgeAddress of this.l1Erc20Bridges) { const renzoPoints = await this._fetchRenzoPoints(bridgeAddress); allRenzoPoints.set(bridgeAddress.toLocaleLowerCase(), renzoPoints); - //await new Promise((resolve) => setTimeout(resolve, 1000)); // wait 1s + await new Promise((resolve) => setTimeout(resolve, 1000)); // wait 1s } return allRenzoPoints; } diff --git a/src/rseth/rseth.service.ts b/src/rseth/rseth.service.ts index 0356dc7..b25fb8b 100644 --- a/src/rseth/rseth.service.ts +++ b/src/rseth/rseth.service.ts @@ -1,5 +1,4 @@ import { Injectable, Logger } from "@nestjs/common"; -import { cloneDeep } from "lodash"; import { LocalPointData, ProjectGraphService, @@ -37,6 +36,10 @@ export interface RsethData { localTotalPoints: bigint; realTotalElPoints: number; realTotalKelpMiles: number; + itemMaps?: Map< + string, + RsethPointItemWithBalance[] | RsethPointItemWithoutBalance[] + >; items: RsethPointItemWithBalance[] | RsethPointItemWithoutBalance[]; } @@ -50,6 +53,7 @@ export class RsethService extends Worker { localTotalPoints: BigInt(0), realTotalElPoints: 0, realTotalKelpMiles: 0, + itemMaps: new Map(), items: [], }; private readonly l1Erc20BridgeEthereum: string; @@ -188,11 +192,23 @@ export class RsethService extends Worker { }; data.push(pointsItem); } + + const itemMaps = new Map(); + for (let i = 0; i < data.length; i++) { + const item = data[i]; + if (!itemMaps.has(item.address)) { + itemMaps.set(item.address, [item]); + } else { + const tmpItems = itemMaps.get(item.address); + itemMaps.set(item.address, [...tmpItems, item]); + } + } if (data.length > 0) { this.rsethData = { localTotalPoints: localTotalPoints, realTotalElPoints: realTotalElPoints, realTotalKelpMiles: realTotalKelpMiles, + itemMaps: itemMaps, items: data, }; } else { @@ -202,14 +218,14 @@ export class RsethService extends Worker { // return points data public getPointsData(address?: string): RsethData { - const result: RsethData = cloneDeep(this.rsethData); - if (address) { - const _address = address.toLocaleLowerCase(); - result.items = this.rsethData.items.filter( - (item) => item.address === _address, - ); - } - return result; + return { + localTotalPoints: this.rsethData.localTotalPoints, + realTotalElPoints: this.rsethData.realTotalElPoints, + realTotalKelpMiles: this.rsethData.realTotalKelpMiles, + items: address + ? this.rsethData.itemMaps.get(address) ?? [] + : this.rsethData.items, + }; } // return local points and totalPoints @@ -224,7 +240,6 @@ export class RsethService extends Worker { // return real points group by address public getPointsDataGroupByAddress(): RsethData { - const result: RsethData = cloneDeep(this.rsethData); const data: Map = new Map(); const now = (new Date().getTime() / 1000) | 0; for (let i = 0; i < this.rsethData.items.length; i++) { @@ -242,8 +257,12 @@ export class RsethService extends Worker { tmpItem.realElPoints += item.realElPoints; } } - result.items = Array.from(data.values()); - return result; + return { + localTotalPoints: this.rsethData.localTotalPoints, + realTotalElPoints: this.rsethData.realTotalElPoints, + realTotalKelpMiles: this.rsethData.realTotalKelpMiles, + items: Array.from(data.values()), + }; } // token match bridge token