Skip to content

Commit

Permalink
Fix addresses endpoing requiring Wallet (#1010)
Browse files Browse the repository at this point in the history
  • Loading branch information
Christopher-Li authored Jan 24, 2024
1 parent 5ee11ed commit 396e56f
Show file tree
Hide file tree
Showing 4 changed files with 40 additions and 13 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import {
FundingIndexUpdatesTable,
BlockTable,
liquidityTierRefresher,
SubaccountTable,
} from '@dydxprotocol-indexer/postgres';
import { RequestMethod } from '../../../../src/types';
import request from 'supertest';
Expand Down Expand Up @@ -297,6 +298,43 @@ describe('addresses-controller#V4', () => {
});
});

it('returns 0 for totalTradingRewards if no wallet exists', async () => {
await PerpetualPositionTable.create(
testConstants.defaultPerpetualPosition,
);

await SubaccountTable.create({
...testConstants.defaultSubaccount,
address: testConstants.defaultWalletAddress,
subaccountNumber: 0,
});

const response: request.Response = await sendRequest({
type: RequestMethod.GET,
path: `/v4/addresses/${testConstants.defaultWalletAddress}`,
});

expect(response.body).toEqual({
subaccounts: [
{
address: testConstants.defaultWalletAddress,
subaccountNumber: 0,
equity: getFixedRepresentation(0),
freeCollateral: getFixedRepresentation(0),
marginEnabled: true,
assetPositions: {},
openPerpetualPositions: {},
},
],
totalTradingRewards: '0',
});
expect(stats.increment).toHaveBeenCalledWith('comlink.addresses-controller.response_status_code.200', 1,
{
path: '/:address',
method: 'GET',
});
});

it('Get / with non-existent address returns 404', async () => {
const response: request.Response = await sendRequest({
type: RequestMethod.GET,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,6 @@ describe('historical-block-trading-reward-controller#V4', () => {
const responseBody: HistoricalTradingRewardAggregationsResponse = response.body;
const rewards: HistoricalTradingRewardAggregation[] = responseBody.rewards;
expect(rewards.length).toEqual(2);
console.log(JSON.stringify(rewards));
expect(rewards[0]).toEqual(tradingRewardToResponse(
defaultTradingReward2,
));
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { logger, stats } from '@dydxprotocol-indexer/base';
import { stats } from '@dydxprotocol-indexer/base';
import {
AssetPositionFromDatabase,
BlockTable,
Expand Down Expand Up @@ -102,15 +102,6 @@ class AddressesController extends Controller {
throw new NotFoundError(`No subaccounts found for address ${address}`);
}

if (wallet === undefined) {
logger.error({
at: 'AddressesController#getAddress',
message: 'No wallet found for address, but subaccounts found for address, this should never happen',
address,
});
throw new NotFoundError(`No wallet found for address ${address}`);
}

const latestFundingIndexMap: FundingIndexMap = await FundingIndexUpdatesTable
.findFundingIndexMap(
latestBlock.blockHeight,
Expand Down Expand Up @@ -169,7 +160,7 @@ class AddressesController extends Controller {

return {
subaccounts: subaccountResponses,
totalTradingRewards: wallet?.totalTradingRewards,
totalTradingRewards: wallet !== undefined ? wallet.totalTradingRewards : '0',
};
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,6 @@ router.get(
startingBeforeOrAt,
startingBeforeOrAtHeight,
);
console.log(`response: ${JSON.stringify(response)}`);

return res.send(response);
} catch (error) {
Expand Down

0 comments on commit 396e56f

Please sign in to comment.