Skip to content

Commit

Permalink
Merge pull request #1270 from multiversx/merge/development-feat-xexch…
Browse files Browse the repository at this point in the history
…ange-v3

Merge development into feat/xexchange-v3
  • Loading branch information
claudiulataretu authored Feb 12, 2024
2 parents 498bc5c + 86dc0ac commit 64a53df
Show file tree
Hide file tree
Showing 31 changed files with 536 additions and 460 deletions.
1 change: 1 addition & 0 deletions .env.example
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@ LOG_LEVEL=info
JWT_SECRET=
NATIVE_AUTH_MAX_EXPIRY_SECONDS=86400
NATIVE_AUTH_ACCEPTED_ORIGINS=
IMPERSONATE_URL=

# RabbitMQ
RABBITMQ_URL=
Expand Down
583 changes: 264 additions & 319 deletions package-lock.json

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@
"@multiversx/sdk-core": "^12.8.0",
"@multiversx/sdk-data-api-client": "^0.5.8",
"@multiversx/sdk-exchange": "^0.2.20",
"@multiversx/sdk-native-auth-server": "1.0.7",
"@multiversx/sdk-native-auth-server": "1.0.14",
"@multiversx/sdk-nestjs-cache": "^2.0.0-beta.2",
"@multiversx/sdk-nestjs-common": "^2.0.0-beta.2",
"@multiversx/sdk-nestjs-elastic": "^2.0.0-beta.3",
Expand Down
14 changes: 7 additions & 7 deletions src/config/default.json
Original file line number Diff line number Diff line change
Expand Up @@ -100,9 +100,9 @@
"router": {
"createPair": 30000000,
"issueToken": 270000000,
"setLocalRoles": 150000000,
"setLocalRoles": 270000000,
"multiPairSwapMultiplier": 100000000,
"swapEnableByUser": 170000000,
"swapEnableByUser": 180000000,
"admin": {
"setState": 200000000,
"setFee": 200000000,
Expand Down Expand Up @@ -439,14 +439,14 @@
},
"simpleLock": {
"lockTokens": 10000000,
"unlockTokens": 5000000,
"unlockTokens": 6000000,
"addLiquidityLockedToken": 20000000,
"removeLiquidityLockedToken": 15000000,
"removeLiquidityLockedToken": 18000000,
"enterFarmLockedToken": {
"default": 25000000,
"withTokenMerge": 30000000
"default": 30000000,
"withTokenMerge": 35000000
},
"exitFarmLockedToken": 50000000,
"exitFarmLockedToken": 60000000,
"claimRewardsFarmLockedToken": 35000000
},
"simpleLockEnergy": {
Expand Down
10 changes: 10 additions & 0 deletions src/helpers/api.config.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -226,6 +226,16 @@ export class ApiConfigService {
return origins.split(',');
}

getImpersonateUrl(): string {
const impersonateUrl =
this.configService.get<string>('IMPERSONATE_URL');
if (!impersonateUrl) {
throw new Error('No impersonate url present');
}

return impersonateUrl;
}

getMXDataApiURL(): string {
const url = this.configService.get<string>('MX_DATA_API_URL');
if (!url) {
Expand Down
8 changes: 4 additions & 4 deletions src/modules/auth/gql.auth.guard.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,15 +25,16 @@ export class GqlAuthGuard implements CanActivate {
const headers = req.headers;
this.logger.info('request header', [
{
requestIP: req.ip, headers: {
'host': headers['host'],
requestIP: req.ip,
headers: {
host: headers['host'],
'x-request-id': headers['x-request-id'],
'x-real-ip': headers['x-real-ip'],
'x-forwarded-for': headers['x-forwarded-for'],
'x-forwarded-host': headers['x-forwarded-host'],
'x-forwarded-port': headers['x-forwarded-port'],
'user-agent': headers['user-agent'],
}
},
},
]);

Expand Down Expand Up @@ -74,7 +75,6 @@ export class GqlAuthGuard implements CanActivate {
});
});
} catch (error) {
this.logger.error(error);
return false;
}

Expand Down
2 changes: 1 addition & 1 deletion src/modules/auth/jwt.or.native.auth.guard.ts
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ export class JwtOrNativeAuthGuard implements CanActivate {
try {
return guard.canActivate(context);
} catch (error) {
this.logger.error(
this.logger.warn(
`${JwtOrNativeAuthGuard.name}: ${error.message}`,
);
return false;
Expand Down
27 changes: 14 additions & 13 deletions src/modules/auth/native.auth.guard.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,7 @@
import { NativeAuthServer } from '@multiversx/sdk-native-auth-server';
import {
NativeAuthError,
NativeAuthServer,
} from '@multiversx/sdk-native-auth-server';
import {
Injectable,
CanActivate,
Expand All @@ -16,7 +19,6 @@ import { Logger } from 'winston';
@Injectable()
export class NativeAuthGuard implements CanActivate {
private readonly authServer: NativeAuthServer;
private impersonateAddress: string;

constructor(
private readonly apiConfigService: ApiConfigService,
Expand All @@ -29,6 +31,7 @@ export class NativeAuthGuard implements CanActivate {
this.apiConfigService.getNativeAuthMaxExpirySeconds(),
acceptedOrigins:
this.apiConfigService.getNativeAuthAcceptedOrigins(),
validateImpersonateUrl: this.apiConfigService.getImpersonateUrl(),
cache: {
getValue: async <T>(key: string): Promise<T | undefined> => {
if (key === 'block:timestamp:latest') {
Expand All @@ -53,10 +56,6 @@ export class NativeAuthGuard implements CanActivate {
const ctx = GqlExecutionContext.create(context);
const { req } = ctx.getContext();

if (req.headers !== undefined) {
this.impersonateAddress = req.headers['impersonate-address'];
}

const authorization: string = req.headers['authorization'];
const origin = req.headers['origin'];

Expand Down Expand Up @@ -89,14 +88,16 @@ export class NativeAuthGuard implements CanActivate {
req.auth = userInfo;
req.jwt = userInfo;

if (this.impersonateAddress) {
if (
userInfo.extraInfo.impersonate &&
userInfo.extraInfo.impersonate !== undefined
) {
const admins = process.env.SECURITY_ADMINS.split(',');
if (admins.find((admin) => admin === userInfo.address)) {
req.res.set(
'X-Native-Auth-Address',
this.impersonateAddress,
);
req.auth.address = this.impersonateAddress;
if (
admins.find((admin) => admin === userInfo.signerAddress) ===
undefined
) {
throw new NativeAuthError('Impersonation not allowed');
}
}

Expand Down
2 changes: 2 additions & 0 deletions src/modules/auto-router/specs/auto-router.service.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ import { ApiConfigService } from 'src/helpers/api.config.service';
import winston from 'winston';
import { DynamicModuleUtils } from 'src/utils/dynamic.module.utils';
import { ComposableTasksTransactionService } from 'src/modules/composable-tasks/services/composable.tasks.transaction';
import { MXApiServiceProvider } from 'src/services/multiversx-communication/mx.api.service.mock';

describe('AutoRouterService', () => {
let service: AutoRouterService;
Expand Down Expand Up @@ -80,6 +81,7 @@ describe('AutoRouterService', () => {
AutoRouterTransactionService,
ComposableTasksTransactionService,
ApiConfigService,
MXApiServiceProvider,
],
exports: [],
}).compile();
Expand Down
4 changes: 3 additions & 1 deletion src/modules/farm/v2/services/farm.v2.transaction.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ import { FarmAbiServiceV2 } from './farm.v2.abi.service';
import { PairService } from 'src/modules/pair/services/pair.service';
import { PairAbiService } from 'src/modules/pair/services/pair.abi.service';
import { MXApiService } from 'src/services/multiversx-communication/mx.api.service';
import { ContextGetterService } from 'src/services/context/context.getter.service';

@Injectable()
export class FarmTransactionServiceV2 extends TransactionsFarmService {
Expand All @@ -27,6 +28,7 @@ export class FarmTransactionServiceV2 extends TransactionsFarmService {
protected readonly pairService: PairService,
protected readonly pairAbi: PairAbiService,
private readonly mxApi: MXApiService,
private readonly contextGetter: ContextGetterService,
) {
super(mxProxy, farmAbi, pairService, pairAbi);
}
Expand Down Expand Up @@ -168,7 +170,7 @@ export class FarmTransactionServiceV2 extends TransactionsFarmService {
return [];
}

const userNfts = await this.mxApi.getNftsForUser(
const userNfts = await this.contextGetter.getNftsForUser(
userAddress,
0,
userNftsCount,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ import { ApiConfigService } from 'src/helpers/api.config.service';
import winston from 'winston';
import { DynamicModuleUtils } from 'src/utils/dynamic.module.utils';
import { AnalyticsQueryServiceProvider } from 'src/services/analytics/mocks/analytics.query.service.mock';
import { MXApiServiceProvider } from 'src/services/multiversx-communication/mx.api.service.mock';

describe('FeesCollectorComputeService', () => {
let module: TestingModule;
Expand Down Expand Up @@ -70,6 +71,7 @@ describe('FeesCollectorComputeService', () => {
},
AnalyticsQueryServiceProvider,
ApiConfigService,
MXApiServiceProvider,
],
}).compile();
});
Expand Down
2 changes: 2 additions & 0 deletions src/modules/pair/specs/pair.compute.service.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ import { WinstonModule } from 'nest-winston';
import { ApiConfigService } from 'src/helpers/api.config.service';
import winston from 'winston';
import { DynamicModuleUtils } from 'src/utils/dynamic.module.utils';
import { MXApiServiceProvider } from 'src/services/multiversx-communication/mx.api.service.mock';

describe('PairService', () => {
let module: TestingModule;
Expand All @@ -42,6 +43,7 @@ describe('PairService', () => {
AnalyticsQueryServiceProvider,
ContextGetterServiceProvider,
ApiConfigService,
MXApiServiceProvider,
],
}).compile();
});
Expand Down
2 changes: 2 additions & 0 deletions src/modules/pair/specs/pair.service.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import { WinstonModule } from 'nest-winston';
import { ApiConfigService } from 'src/helpers/api.config.service';
import winston from 'winston';
import { DynamicModuleUtils } from 'src/utils/dynamic.module.utils';
import { MXApiServiceProvider } from 'src/services/multiversx-communication/mx.api.service.mock';

describe('PairService', () => {
let module: TestingModule;
Expand All @@ -34,6 +35,7 @@ describe('PairService', () => {
ContextGetterServiceProvider,
RouterAbiServiceProvider,
ApiConfigService,
MXApiServiceProvider,
],
}).compile();
});
Expand Down
2 changes: 2 additions & 0 deletions src/modules/pair/specs/pair.transactions.service.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ import { WinstonModule } from 'nest-winston';
import winston from 'winston';
import { DynamicModuleUtils } from 'src/utils/dynamic.module.utils';
import { ComposableTasksTransactionService } from 'src/modules/composable-tasks/services/composable.tasks.transaction';
import { MXApiServiceProvider } from 'src/services/multiversx-communication/mx.api.service.mock';

describe('TransactionPairService', () => {
let module: TestingModule;
Expand Down Expand Up @@ -48,6 +49,7 @@ describe('TransactionPairService', () => {
TokenServiceProvider,
ComposableTasksTransactionService,
PairTransactionService,
MXApiServiceProvider,
],
}).compile();
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ import { ProxyFarmAbiServiceProvider } from 'src/modules/proxy/mocks/proxy.abi.s
import { EnergyAbiServiceProvider } from 'src/modules/energy/mocks/energy.abi.service.mock';
import { scAddress } from 'src/config';
import { StakingAbiService } from 'src/modules/staking/services/staking.abi.service';
import { MXApiServiceProvider } from 'src/services/multiversx-communication/mx.api.service.mock';

describe('PositionCreatorTransaction', () => {
let module: TestingModule;
Expand Down Expand Up @@ -74,6 +75,7 @@ describe('PositionCreatorTransaction', () => {
ConfigService,
ApiConfigService,
ContextGetterServiceProvider,
MXApiServiceProvider,
],
}).compile();
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ import {
WrappedFarmTokenAttributesV2,
} from '@multiversx/sdk-exchange';
import { FarmAbiServiceV2 } from 'src/modules/farm/v2/services/farm.v2.abi.service';
import { ContextGetterService } from 'src/services/context/context.getter.service';

@Injectable()
export class ProxyFarmTransactionsService {
Expand All @@ -45,6 +46,7 @@ export class ProxyFarmTransactionsService {
private readonly pairService: PairService,
private readonly pairAbi: PairAbiService,
private readonly proxyFarmAbi: ProxyFarmAbiService,
private readonly contextGetter: ContextGetterService,
) {}

async enterFarmProxy(
Expand Down Expand Up @@ -283,7 +285,7 @@ export class ProxyFarmTransactionsService {
proxyAddress,
);
const userNftsCount = await this.mxApi.getNftsCountForUser(sender);
const userNfts = await this.mxApi.getNftsForUser(
const userNfts = await this.contextGetter.getNftsForUser(
sender,
0,
userNftsCount,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ import { encodeTransactionData } from 'src/helpers/helpers';
import { WinstonModule } from 'nest-winston';
import winston from 'winston';
import { DynamicModuleUtils } from 'src/utils/dynamic.module.utils';
import { MXApiServiceProvider } from 'src/services/multiversx-communication/mx.api.service.mock';

describe('TransactionProxyPairService', () => {
let module: TestingModule;
Expand Down Expand Up @@ -57,6 +58,7 @@ describe('TransactionProxyPairService', () => {
},
RouterAbiServiceProvider,
ContextGetterServiceProvider,
MXApiServiceProvider,
],
}).compile();
});
Expand Down
2 changes: 2 additions & 0 deletions src/modules/router/specs/router.transactions.service.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ import { WinstonModule } from 'nest-winston';
import { ConfigModule } from '@nestjs/config';
import winston from 'winston';
import { DynamicModuleUtils } from 'src/utils/dynamic.module.utils';
import { MXApiServiceProvider } from 'src/services/multiversx-communication/mx.api.service.mock';

describe('RouterService', () => {
let module: TestingModule;
Expand Down Expand Up @@ -54,6 +55,7 @@ describe('RouterService', () => {
RouterTransactionService,
TokenServiceProvider,
RouterService,
MXApiServiceProvider,
],
}).compile();
});
Expand Down
4 changes: 3 additions & 1 deletion src/modules/staking/services/staking.transactions.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,13 +16,15 @@ import { MXProxyService } from 'src/services/multiversx-communication/mx.proxy.s
import { StakingAbiService } from './staking.abi.service';
import { ErrorLoggerAsync } from '@multiversx/sdk-nestjs-common';
import { MXApiService } from 'src/services/multiversx-communication/mx.api.service';
import { ContextGetterService } from 'src/services/context/context.getter.service';

@Injectable()
export class StakingTransactionService {
constructor(
private readonly stakingAbi: StakingAbiService,
private readonly mxProxy: MXProxyService,
private readonly mxApi: MXApiService,
private readonly contextGetter: ContextGetterService,
) {}

@ErrorLoggerAsync()
Expand Down Expand Up @@ -210,7 +212,7 @@ export class StakingTransactionService {
],
);

const userNfts = await this.mxApi.getNftsForUser(
const userNfts = await this.contextGetter.getNftsForUser(
userAddress,
0,
userNftsCount,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ describe('StakingTransactionService', () => {
MXGatewayService,
MXApiServiceProvider,
ApiConfigService,
MXApiServiceProvider,
],
}).compile();
});
Expand Down
2 changes: 2 additions & 0 deletions src/modules/tokens/specs/token.compute.service.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ import { ApiConfigService } from 'src/helpers/api.config.service';
import winston from 'winston';
import { DynamicModuleUtils } from 'src/utils/dynamic.module.utils';
import { AnalyticsQueryServiceProvider } from 'src/services/analytics/mocks/analytics.query.service.mock';
import { MXApiServiceProvider } from 'src/services/multiversx-communication/mx.api.service.mock';

describe('TokenComputeService', () => {
let module: TestingModule;
Expand All @@ -40,6 +41,7 @@ describe('TokenComputeService', () => {
TokenComputeService,
ApiConfigService,
AnalyticsQueryServiceProvider,
MXApiServiceProvider,
],
}).compile();
});
Expand Down
Loading

0 comments on commit 64a53df

Please sign in to comment.