Skip to content

Commit

Permalink
1.Added rseth realpoints. 2.Optimize magpie access time.
Browse files Browse the repository at this point in the history
  • Loading branch information
robert-zklink committed Apr 18, 2024
1 parent eaac9b9 commit e6bf2da
Show file tree
Hide file tree
Showing 13 changed files with 512 additions and 314 deletions.
8 changes: 5 additions & 3 deletions src/app.module.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,10 +24,11 @@ import { NovaService } from './nova/nova.service';
import { NovaController } from './nova/nova.controller';
import { RenzoPagingController } from './renzo/renzo.paging.controller';
import { NovaPagingController } from './nova/nova.paging.controller';
import { RsethPagingController } from './rseth/rseth.paging.controller';
import { ProjectGraphService } from './common/service/projectGraph.service';
import { WithdrawService } from './common/service/withdraw.service';
import { MagpieService } from './magpie/magpie.service';
import { RsethApiService } from './rseth/rseth.api.service';
import { RsethService } from './rseth/rseth.service';

@Module({
imports: [
Expand All @@ -54,7 +55,6 @@ import { MagpieService } from './magpie/magpie.service';
MagpieController,
NovaController,
RenzoPagingController,
RsethPagingController,
NovaPagingController
],
providers: [
Expand All @@ -75,7 +75,9 @@ import { MagpieService } from './magpie/magpie.service';
NovaService,
ProjectGraphService,
WithdrawService,
MagpieService
MagpieService,
RsethApiService,
RsethService,
],
})
export class AppModule {}
10 changes: 3 additions & 7 deletions src/common/service/graphQuery.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ export class GraphQueryService implements OnModuleInit {
this.logger.error("GraphQueryService init failed", err.stack);
}
};
await func();
func();
setInterval(func, 1000 * 600);
}

Expand All @@ -72,8 +72,8 @@ export class GraphQueryService implements OnModuleInit {
const allPoints = data.data.totalPoints as GraphTotalPoint[];
allPoints.forEach((totalPoint) => {
const projectArr = totalPoint.project.split('-');
const projectName = projectArr[0];
const tokenAddress = projectArr[1];
const projectName = projectArr[0].toLocaleLowerCase();
const tokenAddress = projectArr[1].toLocaleLowerCase();
if (!this.projectTokenMap.has(projectName)) {
this.projectTokenMap.set(projectName, new Map());
this.logger.log(`GraphQueryService ${projectName} had save to cache.`);
Expand All @@ -86,10 +86,6 @@ export class GraphQueryService implements OnModuleInit {
}

public getAllTokenAddresses(projectName: string): string[] {
for (const key in this.projectTokenMap) {
console.log(`token:${key}`);
console.log(this.projectTokenMap[key].keys());
}
const project = this.projectTokenMap.get(projectName);
return project ? Array.from(project.keys()) : [];
}
Expand Down
2 changes: 1 addition & 1 deletion src/common/service/withdraw.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ export class WithdrawService implements OnModuleInit{
this.logger.error(`${WithdrawService.name} init failed`, err.stack);
}
};
await func();
func();
setInterval(func, 1000 * 60);
}

Expand Down
4 changes: 2 additions & 2 deletions src/magpie/magpie.controller.ts
Original file line number Diff line number Diff line change
Expand Up @@ -175,14 +175,14 @@ export class MagpieController {
list = paging.items;
meta = paging.meta;
}
const res = {
let res = {
errno: 0,
errmsg: 'no error',
totals: {
eigenpiePoints: Number(ethers.formatEther(eigenpiePoints)).toFixed(6),
eigenLayerPoints: Number(ethers.formatEther(eigenLayerPoints)).toFixed(6),
},
data: finalPoints.map(item => {
data: list.map(item => {
return item.tokenAddress ?
{
address: item.address,
Expand Down
2 changes: 1 addition & 1 deletion src/nova/novaapi.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ export class NovaApiService {
this.logger.error("NovaApiService init failed", err.stack);
}
};
await func();
func();
setInterval(func, 1000 * 10);
}

Expand Down
6 changes: 2 additions & 4 deletions src/renzo/renzo.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ export class RenzoService{
private readonly renzoApiService: RenzoApiService,
private readonly projectGraphService: ProjectGraphService,
private readonly graphQueryService: GraphQueryService,
private readonly configService: ConfigService,
private readonly configService: ConfigService
) {
this.logger = new Logger(RenzoService.name);
this.l1Erc20BridgeEthereum = configService.get<string>('l1Erc20BridgeEthereum');
Expand Down Expand Up @@ -165,9 +165,7 @@ export class RenzoService{
}

private async getTokensMapBriageTokens(): Promise<Map<string, string>>{
const tokens = this.tokenAddress.map(item=>{
return item.toLocaleLowerCase();
});
const tokens = this.tokenAddress;
const tokensMapBridgeTokens: Map<string, string> = new Map;
const allTokens = await this.explorerService.getTokens();
for (const item of allTokens) {
Expand Down
28 changes: 0 additions & 28 deletions src/renzo/renzoapi.service.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,32 +16,4 @@ describe('RenzoApiService', () => {
renzoApiService = moduleFixture.get<RenzoApiService>(RenzoApiService);
configService = moduleFixture.get<ConfigService>(ConfigService);
});

it('fetchRenzoPoints', async () => {
const renzoPoints = await renzoApiService.fetchRenzoPoints();
const renzoPoints2 = [
await renzoApiService._fetchRenzoPoints(
configService.get<string>('l1Erc20BridgeEthereum'),
),
await renzoApiService._fetchRenzoPoints(
configService.get<string>('l1Erc20BridgeArbitrum'),
),
await renzoApiService._fetchRenzoPoints(
configService.get<string>('l1Erc20BridgeLinea'),
),
await renzoApiService._fetchRenzoPoints(
configService.get<string>('l1Erc20BridgeBlast'),
),
]
.flat()
.reduce(
(acc, renzoPoints) => {
acc.renzoPoints += renzoPoints.renzoPoints;
acc.eigenLayerPoints += renzoPoints.eigenLayerPoints;
return acc;
},
{ renzoPoints: 0, eigenLayerPoints: 0 },
);
expect(renzoPoints).toEqual(renzoPoints2);
},10000);
});
18 changes: 0 additions & 18 deletions src/renzo/renzoapi.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -37,24 +37,6 @@ export class RenzoApiService {
}
}

public async fetchRenzoPoints(): Promise<RenzoPoints> {
const allRenzoPoints = [];

for (const bridgeAddress of this.l1Erc20Bridges) {
const renzoPoints = await this._fetchRenzoPoints(bridgeAddress);
allRenzoPoints.push(renzoPoints);
await new Promise(resolve => setTimeout(resolve, 1000)); // wait 1s
}
return allRenzoPoints.reduce(
(acc, renzoPoints) => {
acc.renzoPoints += renzoPoints.renzoPoints;
acc.eigenLayerPoints += renzoPoints.eigenLayerPoints;
return acc;
},
{ renzoPoints: 0, eigenLayerPoints: 0 },
);
}

public async fetchTokensRenzoPoints(): Promise<Map<string, RenzoPoints>> {
const allRenzoPoints: Map<string, RenzoPoints> = new Map;

Expand Down
58 changes: 58 additions & 0 deletions src/rseth/rseth.api.service.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
import { Injectable, Logger } from '@nestjs/common';
import { ConfigService } from '@nestjs/config';

export interface RsethPoints {
elPoints: number;
kelpMiles: number;
}

@Injectable()
export class RsethApiService {
private readonly logger: Logger;
private readonly rsethApiBaseurl: string;
private readonly l1Erc20Bridges: string[];
public constructor(configService: ConfigService) {
this.logger = new Logger(RsethApiService.name);
this.rsethApiBaseurl = 'https://common.kelpdao.xyz/km-el-points/user/';
this.l1Erc20Bridges = [
configService.get<string>('l1Erc20BridgeEthereum'),
configService.get<string>('l1Erc20BridgeArbitrum')
];
}

public async fetchTokensRsethPoints(): Promise<Map<string, RsethPoints>> {
const allRsethPoints: Map<string, RsethPoints> = new Map;

for (const bridgeAddress of this.l1Erc20Bridges) {
const rsethPoints = await this._fetchRsethPoints(bridgeAddress);
allRsethPoints.set(bridgeAddress.toLocaleLowerCase(), rsethPoints);
await new Promise(resolve => setTimeout(resolve, 1000)); // wait 1s
}
return allRsethPoints;
}

public async _fetchRsethPoints(bridgeAddress: string): Promise<RsethPoints> {
this.logger.log(`start fetchRsethPoints bridgeAddress: ${bridgeAddress}`);
const responseStr = await fetch(`${this.rsethApiBaseurl}${bridgeAddress}`, {
method: 'get',
headers: {
'Content-Type': 'application/json',
'User-Agent': 'Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_8) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/116.0.0.0 Safari/537.36',
},
});
this.logger.log(`end fetchRsethPoints bridgeAddress: ${bridgeAddress}`);
const response = await responseStr.json();
if (
(response?.value?.elPoints ?? undefined) === undefined ||
(response?.value?.kelpMiles ?? undefined) === undefined
) {
this.logger.error(`No rseth points bridgeAddress: ${bridgeAddress}`);
return { elPoints: 0, kelpMiles: 0 };
}
this.logger.log(`success fetchRsethPoints bridgeAddress: ${bridgeAddress}, elPoints:${response.value.elPoints}, kelpMiles:${response.value.kelpMiles} `);
return {
elPoints: response.value.elPoints,
kelpMiles: response.value.kelpMiles
};
}
}
Loading

0 comments on commit e6bf2da

Please sign in to comment.