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 #1276

Merged
merged 11 commits into from
Feb 13, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
2 changes: 1 addition & 1 deletion src/config/default.json
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,7 @@
"createPair": 30000000,
"issueToken": 270000000,
"setLocalRoles": 270000000,
"multiPairSwapMultiplier": 100000000,
"multiPairSwapMultiplier": 110000000,
"swapEnableByUser": 180000000,
"admin": {
"setState": 200000000,
Expand Down
3 changes: 2 additions & 1 deletion src/config/mainnet.json
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,8 @@
"erd1qqqqqqqqqqqqqpgqmvzrwmwkrrzug50e64kk7xerufncp47d2jpsf9m8rx",
"erd1qqqqqqqqqqqqqpgqc6fyckfxvehlwr2zvfl34dycwgtm988g2jpsrnyazn",
"erd1qqqqqqqqqqqqqpgqm78a0zmuqlm7z5qw9nseg6ecdszafljp2jpsxkm4rp",
"erd1qqqqqqqqqqqqqpgqk5xplswklltypmazcxx5mhn3jdvaxuf92jpsudss7r"
"erd1qqqqqqqqqqqqqpgqk5xplswklltypmazcxx5mhn3jdvaxuf92jpsudss7r",
"erd1qqqqqqqqqqqqqpgqjgtun0fhl2em5ayukvahm3myltaxc5tz2jpssz8axf"
]
}
},
Expand Down
3 changes: 2 additions & 1 deletion src/config/staging.json
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,8 @@
"erd1qqqqqqqqqqqqqpgqmvzrwmwkrrzug50e64kk7xerufncp47d2jpsf9m8rx",
"erd1qqqqqqqqqqqqqpgqc6fyckfxvehlwr2zvfl34dycwgtm988g2jpsrnyazn",
"erd1qqqqqqqqqqqqqpgqm78a0zmuqlm7z5qw9nseg6ecdszafljp2jpsxkm4rp",
"erd1qqqqqqqqqqqqqpgqk5xplswklltypmazcxx5mhn3jdvaxuf92jpsudss7r"
"erd1qqqqqqqqqqqqqpgqk5xplswklltypmazcxx5mhn3jdvaxuf92jpsudss7r",
"erd1qqqqqqqqqqqqqpgqjgtun0fhl2em5ayukvahm3myltaxc5tz2jpssz8axf"
]
}
},
Expand Down
88 changes: 46 additions & 42 deletions src/modules/user/services/userEnergy/user.energy.compute.service.ts
Original file line number Diff line number Diff line change
@@ -1,12 +1,16 @@
import { Injectable } from '@nestjs/common';
import { constantsConfig, scAddress } from '../../../../config';
import { scAddress } from '../../../../config';
import { EnergyType } from '@multiversx/sdk-exchange';
import { ClaimProgress } from '../../../../submodules/weekly-rewards-splitting/models/weekly-rewards-splitting.model';
import { ContractType, OutdatedContract, UserDualYiledToken } from '../../models/user.model';
import {
ContractType,
OutdatedContract,
UserDualYiledToken,
} from '../../models/user.model';
import { ProxyService } from '../../../proxy/services/proxy.service';
import { StakingProxyService } from '../../../staking-proxy/services/staking.proxy.service';
import { FarmVersion } from '../../../farm/models/farm.model';
import { farmVersion, farmsAddresses } from '../../../../utils/farm.utils';
import { farmVersion } from '../../../../utils/farm.utils';
import { BigNumber } from 'bignumber.js';
import { WeekTimekeepingAbiService } from 'src/submodules/week-timekeeping/services/week-timekeeping.abi.service';
import { WeeklyRewardsSplittingAbiService } from 'src/submodules/weekly-rewards-splitting/services/weekly-rewards-splitting.abi.service';
Expand All @@ -19,7 +23,6 @@
import { EnergyAbiService } from 'src/modules/energy/services/energy.abi.service';
import { RemoteConfigGetterService } from 'src/modules/remote-config/remote-config.getter.service';
import { StakingService } from 'src/modules/staking/services/staking.service';
import { ContextGetterService } from 'src/services/context/context.getter.service';
import { PaginationArgs } from 'src/modules/dex.model';
import { UserMetaEsdtService } from '../user.metaEsdt.service';

Expand All @@ -37,7 +40,6 @@
private readonly proxyService: ProxyService,
private readonly remoteConfig: RemoteConfigGetterService,
private readonly userMetaEsdtService: UserMetaEsdtService,
private readonly contextGetter: ContextGetterService,
) {}

async getUserOutdatedContracts(
Expand Down Expand Up @@ -221,47 +223,45 @@
}

async computeActiveFarmsV2ForUser(userAddress: string): Promise<string[]> {
const userNfts = await this.contextGetter.getNftsForUser(
userAddress,
0,
constantsConfig.MAX_USER_NFTS,
);
const stakingProxies = await this.stakeProxyService.getStakingProxies();
const filterAddresses = [
...farmsAddresses([FarmVersion.V2]),
stakingProxies.map((proxy) => proxy.address),
scAddress.proxyDexAddress.v2,
];
const filteredNfts = userNfts.filter((nft) =>
filterAddresses.includes(nft.creator),
);
const userActiveFarmAddresses = filteredNfts
.filter((nft) =>
farmsAddresses([FarmVersion.V2]).includes(nft.creator),
)
.map((nft) => nft.creator);
const maxPagination = new PaginationArgs({

Check warning on line 226 in src/modules/user/services/userEnergy/user.energy.compute.service.ts

View check run for this annotation

Codecov / codecov/patch

src/modules/user/services/userEnergy/user.energy.compute.service.ts#L226

Added line #L226 was not covered by tests
limit: 100,
offset: 0,
});
const [farmTokens, farmLockedTokens, dualYieldTokens] =
await Promise.all([

Check warning on line 231 in src/modules/user/services/userEnergy/user.energy.compute.service.ts

View check run for this annotation

Codecov / codecov/patch

src/modules/user/services/userEnergy/user.energy.compute.service.ts#L231

Added line #L231 was not covered by tests
this.userMetaEsdtService.getUserFarmTokens(
userAddress,
maxPagination,
false,
),
this.userMetaEsdtService.getUserLockedFarmTokensV2(
userAddress,
maxPagination,
false,
),
this.userMetaEsdtService.getUserDualYieldTokens(
userAddress,
maxPagination,
false,
),
]);

const proxyNfts = filteredNfts.filter(
(nft) => nft.creator === scAddress.proxyDexAddress.v2,
);
const promisesFarmLockedTokens = proxyNfts.map((token) =>
this.decodeAndGetFarmAddressFarmLockedTokens(
let userActiveFarmAddresses = farmTokens.map((token) => token.creator);
const promisesFarmLockedTokens = farmLockedTokens.map((token) => {
return this.decodeAndGetFarmAddressFarmLockedTokens(

Check warning on line 251 in src/modules/user/services/userEnergy/user.energy.compute.service.ts

View check run for this annotation

Codecov / codecov/patch

src/modules/user/services/userEnergy/user.energy.compute.service.ts#L249-L251

Added lines #L249 - L251 were not covered by tests
token.identifier,
token.attributes,
),
);
userActiveFarmAddresses.push(
...(await Promise.all(promisesFarmLockedTokens)),
);
);
});
const promisesDualYieldTokens = dualYieldTokens.map((token) => {
return this.getFarmAddressForDualYieldToken(token.collection);

Check warning on line 257 in src/modules/user/services/userEnergy/user.energy.compute.service.ts

View check run for this annotation

Codecov / codecov/patch

src/modules/user/services/userEnergy/user.energy.compute.service.ts#L256-L257

Added lines #L256 - L257 were not covered by tests
});

const stakingProxyNfts = filteredNfts.filter((nft) =>
stakingProxies.map((proxy) => proxy.address).includes(nft.creator),
);
const promisesDualYieldTokens = stakingProxyNfts.map((token) =>
this.getFarmAddressForDualYieldToken(token.identifier),
);
userActiveFarmAddresses.push(
...(await Promise.all(promisesDualYieldTokens)),
userActiveFarmAddresses = userActiveFarmAddresses.concat(

Check warning on line 260 in src/modules/user/services/userEnergy/user.energy.compute.service.ts

View check run for this annotation

Codecov / codecov/patch

src/modules/user/services/userEnergy/user.energy.compute.service.ts#L260

Added line #L260 was not covered by tests
await Promise.all([
...promisesFarmLockedTokens,
...promisesDualYieldTokens,
]),
);
return [...new Set(userActiveFarmAddresses)].filter(
(address) => farmVersion(address) === FarmVersion.V2,
Expand Down Expand Up @@ -326,6 +326,10 @@
}

async getFarmAddressForDualYieldToken(collection: string): Promise<string> {
if (!collection || collection === undefined) {
return undefined;

Check warning on line 330 in src/modules/user/services/userEnergy/user.energy.compute.service.ts

View check run for this annotation

Codecov / codecov/patch

src/modules/user/services/userEnergy/user.energy.compute.service.ts#L330

Added line #L330 was not covered by tests
}

const stakingProxyAddress =
await this.stakeProxyService.getStakingProxyAddressByDualYieldTokenID(
collection,
Expand Down
18 changes: 1 addition & 17 deletions src/services/context/context.getter.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -61,23 +61,7 @@
type = 'MetaESDT',
collections?: string[],
): Promise<NftToken[]> {
const cacheKey = this.getCacheKey('nftsForUser', address, from, size);
let nfts = await this.cachingService.getRemote<NftToken[]>(cacheKey);
if (nfts) {
const userNfts = collections
? nfts
.filter((nft) => collections.includes(nft.collection))
.slice(from, size)
: nfts.slice(from, size);
return userNfts;
}

nfts = await this.apiService.getNftsForUser(address, type);
await this.cachingService.setRemote(
cacheKey,
nfts,
Constants.oneSecond() * 6,
);
const nfts = await this.apiService.getNftsForUser(address, type);

Check warning on line 64 in src/services/context/context.getter.service.ts

View check run for this annotation

Codecov / codecov/patch

src/services/context/context.getter.service.ts#L64

Added line #L64 was not covered by tests

const userNfts = collections
? nfts
Expand Down
Loading