Skip to content

Commit

Permalink
Merge pull request #19 from multiversx/develop
Browse files Browse the repository at this point in the history
Develop
  • Loading branch information
raress96 authored Feb 12, 2025
2 parents 48da071 + 3d55036 commit bd626db
Show file tree
Hide file tree
Showing 11 changed files with 196 additions and 79 deletions.
2 changes: 1 addition & 1 deletion .env.example
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ EVENTS_NOTIFIER_QUEUE=queue

CONTRACT_GATEWAY=erd1qqqqqqqqqqqqqpgqvaj9w3g006wgj7avhen3au27datwgk63kklszcamgw
CONTRACT_GAS_SERVICE=erd1qqqqqqqqqqqqqpgqvr340nazahl2r0q7dnqvyakuk909yjvukklsuzx4ar
CONTRACT_ITS=erd1qqqqqqqqqqqqqpgqcv3rhjjrqpl88es4q25lw03hfhpw6s36kklsn6t9a6
CONTRACT_ITS=erd1qqqqqqqqqqqqqpgqc5ypvy2d6z52fwscsfnrwcdkdh2fnthfkkls7kcn9j

CONTRACT_WEGLD_SWAP=erd1qqqqqqqqqqqqqpgqpv09kfzry5y4sj05udcngesat07umyj70n4sa2c0rp

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import { ApprovalsProcessorService } from './approvals.processor.service';
import { ApiModule } from '@mvx-monorepo/common/api/api.module';
import { ContractsModule } from '@mvx-monorepo/common/contracts/contracts.module';
import { ScheduleModule } from '@nestjs/schedule';
import { HelpersModule } from '@mvx-monorepo/common/helpers/helpers.module';

@Module({
imports: [
Expand All @@ -13,6 +14,7 @@ import { ScheduleModule } from '@nestjs/schedule';
ApiModule,
ContractsModule,
DatabaseModule,
HelpersModule,
],
providers: [ApprovalsProcessorService],
})
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ import { BinaryUtils, Locker } from '@multiversx/sdk-nestjs-common';
import { Inject, Injectable, Logger } from '@nestjs/common';
import { Cron } from '@nestjs/schedule';
import { AxelarGmpApi } from '@mvx-monorepo/common/api/axelar.gmp.api';
import { RedisCacheService } from '@multiversx/sdk-nestjs-cache';
import { CacheInfo, GasServiceContract } from '@mvx-monorepo/common';
import { ProviderKeys } from '@mvx-monorepo/common/utils/provider.enum';
import { UserSigner } from '@multiversx/sdk-wallet/out';
Expand All @@ -21,6 +20,7 @@ import ExecuteTask = Components.Schemas.ExecuteTask;
import RefundTask = Components.Schemas.RefundTask;
import { GasError } from '@mvx-monorepo/common/contracts/entities/gas.error';
import { GasInfo } from '@mvx-monorepo/common/utils/gas.info';
import { RedisHelper } from '@mvx-monorepo/common/helpers/redis.helper';

const MAX_NUMBER_OF_RETRIES = 3;

Expand All @@ -30,7 +30,7 @@ export class ApprovalsProcessorService {

constructor(
private readonly axelarGmpApi: AxelarGmpApi,
private readonly redisCacheService: RedisCacheService,
private readonly redisHelper: RedisHelper,
@Inject(ProviderKeys.WALLET_SIGNER) private readonly walletSigner: UserSigner,
private readonly transactionsHelper: TransactionsHelper,
private readonly gatewayContract: GatewayContract,
Expand All @@ -52,7 +52,7 @@ export class ApprovalsProcessorService {
}

async handleNewTasksRaw() {
let lastTaskUUID = (await this.redisCacheService.get<string>(CacheInfo.LastTaskUUID().key)) || undefined;
let lastTaskUUID = (await this.redisHelper.get<string>(CacheInfo.LastTaskUUID().key)) || undefined;

this.logger.debug(`Trying to process tasks for multiversx starting from id: ${lastTaskUUID}`);

Expand All @@ -76,7 +76,7 @@ export class ApprovalsProcessorService {

lastTaskUUID = task.id;

await this.redisCacheService.set(CacheInfo.LastTaskUUID().key, lastTaskUUID, CacheInfo.LastTaskUUID().ttl);
await this.redisHelper.set(CacheInfo.LastTaskUUID().key, lastTaskUUID, CacheInfo.LastTaskUUID().ttl);
} catch (e) {
this.logger.error(`Could not process task ${task.id}`, task, e);

Expand All @@ -95,11 +95,9 @@ export class ApprovalsProcessorService {
}

async handlePendingTransactionsRaw() {
const keys = await this.redisCacheService.scan(CacheInfo.PendingTransaction('*').key);
const keys = await this.redisHelper.scan(CacheInfo.PendingTransaction('*').key);
for (const key of keys) {
const cachedValue = await this.redisCacheService.get<PendingTransaction>(key);

await this.redisCacheService.delete(key);
const cachedValue = await this.redisHelper.getDel<PendingTransaction>(key);

if (cachedValue === undefined) {
continue;
Expand Down Expand Up @@ -129,7 +127,7 @@ export class ApprovalsProcessorService {
this.logger.error(e);

// Set value back in cache to be retried again (with same retry number if it failed to even be sent to the chain)
await this.redisCacheService.set<PendingTransaction>(
await this.redisHelper.set<PendingTransaction>(
CacheInfo.PendingTransaction(txHash).key,
{
txHash,
Expand Down Expand Up @@ -193,7 +191,7 @@ export class ApprovalsProcessorService {
// In case the gas estimation fails, the transaction will fail on chain, but we will still send it
// for transparency
if (e instanceof GasError) {
this.logger.warn('Could not estimate gas for Gateway transaction...');
this.logger.warn('Could not estimate gas for Gateway transaction...', e);

transaction.setGasLimit(GasInfo.GatewayDefault.value);
} else {
Expand All @@ -203,7 +201,7 @@ export class ApprovalsProcessorService {

const txHash = await this.transactionsHelper.signAndSendTransaction(transaction, this.walletSigner);

await this.redisCacheService.set<PendingTransaction>(
await this.redisHelper.set<PendingTransaction>(
CacheInfo.PendingTransaction(txHash).key,
{
txHash,
Expand Down
Loading

0 comments on commit bd626db

Please sign in to comment.