Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merge development into feat/xexchange-v3 #1270

Merged
merged 20 commits into from
Feb 12, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
20 commits
Select commit Hold shift + click to select a range
c28dae2
config: update gas limits for mainnet
claudiulataretu Jan 18, 2024
cd0bc23
Merge pull request #1262 from multiversx/mainnet/gas-limits-v1.6.0
claudiulataretu Jan 18, 2024
b60008b
SERVICES-2105: improve logging and API metrics
claudiulataretu Feb 1, 2024
07aab66
config: update gas limits for simple lock contract
claudiulataretu Feb 1, 2024
7a9c865
Merge pull request #1267 from multiversx/mainnet/gas-limits-v1.6.0
claudiulataretu Feb 1, 2024
c3cc311
SERVICES-2105: improve performance of user outdated contracts
claudiulataretu Feb 2, 2024
767732e
SERVICES-2105: add 6 seconds cache for user nfts
claudiulataretu Feb 2, 2024
4100c10
SERVICES-2105: uncomment auth logging
claudiulataretu Feb 5, 2024
99c73a8
SERVICES-2105: add mock userNfts for context getter service
claudiulataretu Feb 5, 2024
da88c85
SERVICES-2105: fix unit tests imports
claudiulataretu Feb 5, 2024
0159d1a
SERVICES-2112: upgrade native auth server to 1.0.13
claudiulataretu Feb 6, 2024
dd461f3
SERVICES-2112: update package-lock.json
claudiulataretu Feb 6, 2024
336ec56
SERVICES-2112: remove logging message
claudiulataretu Feb 6, 2024
bce2e0d
SERVICES-2112: upgrade native auth server to 1.0.14
claudiulataretu Feb 6, 2024
0281c49
Merge pull request #1269 from multiversx/SERVICES-2112-upgrade-native…
claudiulataretu Feb 7, 2024
b5bdadf
SERVICES-2105: remove redundant call for user nfts count
claudiulataretu Feb 7, 2024
98f572c
SERVICES-2105: removed unused mocked method
claudiulataretu Feb 7, 2024
35f6b12
Merge pull request #1268 from multiversx/SERVICES-2105-load-testing
claudiulataretu Feb 7, 2024
ff2177b
Merge branch 'development' into merge/development-feat-xexchange-v3
claudiulataretu Feb 7, 2024
86dc0ac
merge: fixes after merge
claudiulataretu Feb 7, 2024
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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 @@
return origins.split(',');
}

getImpersonateUrl(): string {
const impersonateUrl =
this.configService.get<string>('IMPERSONATE_URL');

Check warning on line 231 in src/helpers/api.config.service.ts

View check run for this annotation

Codecov / codecov/patch

src/helpers/api.config.service.ts#L231

Added line #L231 was not covered by tests
if (!impersonateUrl) {
throw new Error('No impersonate url present');

Check warning on line 233 in src/helpers/api.config.service.ts

View check run for this annotation

Codecov / codecov/patch

src/helpers/api.config.service.ts#L233

Added line #L233 was not covered by tests
}

return impersonateUrl;

Check warning on line 236 in src/helpers/api.config.service.ts

View check run for this annotation

Codecov / codecov/patch

src/helpers/api.config.service.ts#L236

Added line #L236 was not covered by tests
}

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
Loading