Skip to content
This repository has been archived by the owner on Jan 24, 2024. It is now read-only.

Commit

Permalink
fix(atlendis-v1): Fix decimals in balance, fix checksum address (#877)
Browse files Browse the repository at this point in the history
  • Loading branch information
immasandwich authored Jul 14, 2022
1 parent 11eda21 commit 402baab
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 14 deletions.
6 changes: 3 additions & 3 deletions src/apps/atlendis-v1/atlendis-v1.definition.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,10 @@ export const ATLENDIS_V_1_DEFINITION = appDefinition({
url: 'https://app.atlendis.io/',

groups: {
position: {
id: 'position',
lending: {
id: 'lending',
type: GroupType.POSITION,
label: 'Positions',
label: 'Lending',
},
},

Expand Down
26 changes: 15 additions & 11 deletions src/apps/atlendis-v1/polygon/atlendis-v1.balance-fetcher.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import { Inject } from '@nestjs/common';
import { BigNumber } from 'ethers';
import { BigNumber } from 'bignumber.js';
import { getAddress } from 'ethers/lib/utils';
import { sumBy } from 'lodash';

import { drillBalance } from '~app-toolkit';
Expand Down Expand Up @@ -33,7 +34,7 @@ export class PolygonAtlendisV1BalanceFetcher implements BalanceFetcher {
const data = await graphHelper.requestGraph({
endpoint: 'https://atlendis.herokuapp.com/graphql',
query: GET_USER_POSITIONS,
variables: { address },
variables: { address: getAddress(address) },
});
const baseTokens = await this.appToolkit.getBaseTokenPrices(network);

Expand All @@ -43,17 +44,17 @@ export class PolygonAtlendisV1BalanceFetcher implements BalanceFetcher {
t => t.address.toLowerCase() === position.pool.parameters.token.address.toLowerCase(),
);
if (!underlyingToken) return null;
const positionManagerAddress = '0x55E4e70a725C1439dac6B9412B71fC8372Bd73e9';
const positionManagerAddress = '0x55e4e70a725c1439dac6b9412b71fc8372bd73e9';

const positionContract: ContractPosition = {
type: ContractType.POSITION,
appId: ATLENDIS_V_1_DEFINITION.id,
groupId: ATLENDIS_V_1_DEFINITION.groups.position.id,
groupId: ATLENDIS_V_1_DEFINITION.groups.lending.id,
address: positionManagerAddress,
network,
tokens: [supplied(underlyingToken)],
dataProps: {
tokenId: position.tokenId,
tokenId: new BigNumber(position.tokenId).toString(),
},
displayProps: {
label: getLabelFromToken(underlyingToken),
Expand All @@ -67,18 +68,21 @@ export class PolygonAtlendisV1BalanceFetcher implements BalanceFetcher {
});

const { bondsQuantity, normalizedDepositedAmount } = await contract.getPositionRepartition(position.tokenId);
const balanceRawWei = new BigNumber(bondsQuantity.toString())
.plus(normalizedDepositedAmount.toString())
.toString();
const balanceRaw = new BigNumber(balanceRawWei)
.div(10 ** 18)
.times(10 ** positionContract.tokens[0].decimals)
.toString();

const tokenBalances = [
drillBalance(
positionContract.tokens[0],
BigNumber.from(bondsQuantity).add(BigNumber.from(normalizedDepositedAmount)).toString(),
),
];
const tokenBalances = [drillBalance(positionContract.tokens[0], balanceRaw)];
const contractPositionBalance: ContractPositionBalance = {
...positionContract,
tokens: tokenBalances,
balanceUSD: sumBy(tokenBalances, v => v.balanceUSD),
};

return contractPositionBalance;
}),
);
Expand Down
5 changes: 5 additions & 0 deletions src/balance/dto/get-balances-query.dto.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
import { ApiProperty } from '@nestjs/swagger';
import { Transform } from 'class-transformer';
import { ArrayMinSize, IsEnum, IsString } from 'class-validator';
import { uniq } from 'lodash';

import { Network } from '~types/network.interface';

Expand All @@ -11,5 +13,8 @@ export class GetBalancesQuery {
@ApiProperty({ description: 'Addresses for which to retrieve balances', type: [String], name: 'addresses[]' })
@IsString({ each: true })
@ArrayMinSize(1)
@Transform(({ value: addresses }: { value: string[] }) =>
uniq((Array.isArray(addresses) ? addresses : []).slice(0, 15).map(address => address.toLowerCase())),
)
addresses: string[];
}

0 comments on commit 402baab

Please sign in to comment.