Skip to content

Commit

Permalink
Update gh workflow.
Browse files Browse the repository at this point in the history
vincentwschau committed Oct 25, 2024
1 parent 4b12b78 commit 7af7388
Showing 5 changed files with 15 additions and 12 deletions.
1 change: 1 addition & 0 deletions .github/workflows/indexer-build-and-push-dev-staging.yml
Original file line number Diff line number Diff line change
@@ -3,6 +3,7 @@ name: Indexer Build & Push Images to AWS ECR for Dev / Staging branches
on: # yamllint disable-line rule:truthy
push:
branches:
- vincentc/dedup-filter-ticks
- main
- 'release/indexer/v[0-9]+.[0-9]+.x' # e.g. release/indexer/v0.1.x
- 'release/indexer/v[0-9]+.x' # e.g. release/indexer/v1.x
10 changes: 6 additions & 4 deletions indexer/services/comlink/__tests__/lib/helpers.test.ts
Original file line number Diff line number Diff line change
@@ -58,7 +58,9 @@ import {
defaultTendermintEventId2,
defaultTendermintEventId3,
} from '@dydxprotocol-indexer/postgres/build/__tests__/helpers/constants';
import { AggregatedPnlTick, AssetPositionsMap, PerpetualPositionWithFunding, SubaccountResponseObject } from '../../src/types';
import {
AggregatedPnlTick, AssetPositionsMap, PerpetualPositionWithFunding, SubaccountResponseObject,
} from '../../src/types';
import { ZERO, ZERO_USDC_POSITION } from '../../src/lib/constants';
import { DateTime } from 'luxon';

@@ -849,7 +851,7 @@ describe('helpers', () => {
aggregatedPnlTicks,
).toEqual(
[expect.objectContaining(
{
{
pnlTick: expect.objectContaining(testConstants.defaultPnlTick),
numTicks: 1,
},
@@ -917,10 +919,10 @@ describe('helpers', () => {
blockHeight: blockHeight4,
blockTime: blockTime4,
createdAt: blockTime4,
}
};

const aggregatedPnlTicks: AggregatedPnlTick[] = aggregateHourlyPnlTicks(
[pnlTick, pnlTick2, pnlTick3, pnlTick4],
[pnlTick, pnlTick2, pnlTick3, pnlTick4, pnlTick5],
);
expect(aggregatedPnlTicks).toEqual(
expect.arrayContaining([
Original file line number Diff line number Diff line change
@@ -11,6 +11,7 @@ import {
} from '@dydxprotocol-indexer/postgres';
import express from 'express';
import { matchedData } from 'express-validator';
import _ from 'lodash';
import {
Controller, Get, Query, Route,
} from 'tsoa';
@@ -31,7 +32,6 @@ import { handleValidationErrors } from '../../../request-helpers/error-handler';
import ExportResponseCodeStats from '../../../request-helpers/export-response-code-stats';
import { pnlTicksToResponseObject } from '../../../request-helpers/request-transformer';
import { PnlTicksRequest, HistoricalPnlResponse, ParentSubaccountPnlTicksRequest } from '../../../types';
import _ from 'lodash';

const router: express.Router = express.Router();
const controllerName: string = 'historical-pnl-controller';
Original file line number Diff line number Diff line change
@@ -27,6 +27,7 @@ import {
MEGAVAULT_SUBACCOUNT_ID,
} from '@dydxprotocol-indexer/postgres';
import Big from 'big.js';
import bounds from 'binary-searching';
import express from 'express';
import { checkSchema, matchedData } from 'express-validator';
import _ from 'lodash';
@@ -58,7 +59,6 @@ import {
VaultsHistoricalPnlRequest,
AggregatedPnlTick,
} from '../../../types';
import bounds from 'binary-searching';

const router: express.Router = express.Router();
const controllerName: string = 'vault-controller';
@@ -311,7 +311,7 @@ router.get(
Date.now() - start,
);
}
}
},
);

async function getVaultSubaccountPnlTicks(
@@ -647,7 +647,7 @@ function getHeightWindows(
* the pnl tick was created.
* @param vaultPnlTicks Pnl ticks to aggregate.
* @param vaults List of all valid vaults.
* @returns
* @returns
*/
function aggregateVaultPnlTicks(
vaultPnlTicks: PnlTicksFromDatabase[],
@@ -656,20 +656,20 @@ function aggregateVaultPnlTicks(
// aggregate pnlTicks for all vault subaccounts grouped by blockHeight
const aggregatedPnlTicks: AggregatedPnlTick[] = aggregateHourlyPnlTicks(vaultPnlTicks);
const vaultCreationTimes: DateTime[] = _.map(vaults, 'createdAt').map(
(createdAt: string) => { return DateTime.fromISO(createdAt); }
(createdAt: string) => { return DateTime.fromISO(createdAt); },
).sort((a: DateTime, b: DateTime) => { return a.diff(b).milliseconds; });
return aggregatedPnlTicks.filter((aggregatedTick: AggregatedPnlTick) => {
// Get number of vaults created before the pnl tick was created by binary-searching for the
// index of the pnl ticks createdAt in a sorted array of vault createdAt times.
const numVaultsCreated: number = bounds.le(
vaultCreationTimes,
DateTime.fromISO(aggregatedTick.pnlTick.createdAt),
(a: DateTime, b: DateTime) => { return a.diff(b).milliseconds; }
(a: DateTime, b: DateTime) => { return a.diff(b).milliseconds; },
) + 1;
// Number of ticks should be strictly greater than number of vaults created before it
// as there should be a tick for the main vault subaccount.
return aggregatedTick.numTicks > numVaultsCreated;
}).map((aggregatedPnlTick: AggregatedPnlTick) => { return aggregatedPnlTick.pnlTick });
}).map((aggregatedPnlTick: AggregatedPnlTick) => { return aggregatedPnlTick.pnlTick; });
}

async function getVaultMapping(): Promise<VaultMapping> {
2 changes: 1 addition & 1 deletion indexer/services/comlink/src/lib/helpers.ts
Original file line number Diff line number Diff line change
@@ -717,6 +717,6 @@ export function aggregateHourlyPnlTicks(
return {
pnlTick: hourlyPnlTicks.get(hour) as PnlTicksFromDatabase,
numTicks: (hourlySubaccountIds.get(hour) as Set<string>).size,
}
};
});
}

0 comments on commit 7af7388

Please sign in to comment.