From 683d72d6d9d18c4e5f7f201523ddac4c2c25cf04 Mon Sep 17 00:00:00 2001 From: Dong-Ha Kim Date: Mon, 16 Jan 2023 18:09:33 +0100 Subject: [PATCH 1/3] refactor: rename deposit fill event and props amplitude (#209) --- src/modules/ampli/index.ts | 41 ++++++++----------- .../adapter/amplitude/track-service.ts | 6 +-- .../messaging/TrackFillEventConsumer.ts | 10 +++-- 3 files changed, 25 insertions(+), 32 deletions(-) diff --git a/src/modules/ampli/index.ts b/src/modules/ampli/index.ts index 2eb4ac75..928074de 100644 --- a/src/modules/ampli/index.ts +++ b/src/modules/ampli/index.ts @@ -7,7 +7,7 @@ * To update run 'ampli pull scraper' * * Required dependencies: @amplitude/analytics-node@^0.5.0 - * Tracking Plan Version: 40 + * Tracking Plan Version: 43 * Build: 1.0.0 * Runtime: node.js:typescript-ampli-v2 * @@ -38,10 +38,10 @@ export const ApiKey: Record = { */ export const DefaultConfiguration: NodeOptions = { plan: { - version: "40", + version: "43", branch: "main", source: "scraper", - versionId: "cbc4a092-7d03-473a-bbba-f4fc79ef25b2", + versionId: "364c665a-00b3-4f3a-86b4-72245b71f5a0", }, ...{ ingestionMetadata: { @@ -118,7 +118,7 @@ export interface IdentifyProperties { walletType?: string; } -export interface TransferFillConfirmedProperties { +export interface TransferFillCompletedProperties { /** * Capital fee percent, in decimals */ @@ -135,7 +135,7 @@ export interface TransferFillConfirmedProperties { fillAmount: string; fillAmountUsd: string; fillCompleteTimestamp: string; - fillTime: string; + fillTimeInMs: string; /** * From amount in the bridge token, in decimals */ @@ -169,18 +169,9 @@ export interface TransferFillConfirmedProperties { * Lp fee in USD */ lpFeeTotalUsd: string; - /** - * Gas fee in network token - */ - NetworkFeeNative: string; - /** - * Network native token - */ - NetworkFeeNativeToken: string; - /** - * Gas fee in USD - */ - NetworkFeeUsd: string; + networkFeeNative: string; + networkFeeNativeToken: string; + networkFeeUsd: string; /** * Recipient wallet address */ @@ -281,10 +272,10 @@ export class Identify implements BaseEvent { } } -export class TransferFillConfirmed implements BaseEvent { - event_type = "TransferFillConfirmed"; +export class TransferFillCompleted implements BaseEvent { + event_type = "TransferFillCompleted"; - constructor(public event_properties: TransferFillConfirmedProperties) { + constructor(public event_properties: TransferFillCompletedProperties) { this.event_properties = event_properties; } } @@ -406,9 +397,9 @@ export class Ampli { } /** - * TransferFillConfirmed + * TransferFillCompleted * - * [View in Tracking Plan](https://data.amplitude.com/risklabs/Risk%20Labs/events/main/latest/TransferFillConfirmed) + * [View in Tracking Plan](https://data.amplitude.com/risklabs/Risk%20Labs/events/main/latest/TransferFillCompleted) * * Owner: Dong-Ha Kim * @@ -416,12 +407,12 @@ export class Ampli { * @param properties The event's properties (e.g. capitalFeePct) * @param options Amplitude event options. */ - transferFillConfirmed( + transferFillCompleted( userId: string | undefined, - properties: TransferFillConfirmedProperties, + properties: TransferFillCompletedProperties, options?: EventOptions, ) { - return this.track(userId, new TransferFillConfirmed(properties), options); + return this.track(userId, new TransferFillCompleted(properties), options); } } diff --git a/src/modules/scraper/adapter/amplitude/track-service.ts b/src/modules/scraper/adapter/amplitude/track-service.ts index ad0bc024..f2f1058e 100644 --- a/src/modules/scraper/adapter/amplitude/track-service.ts +++ b/src/modules/scraper/adapter/amplitude/track-service.ts @@ -1,7 +1,7 @@ import { HttpService } from "@nestjs/axios"; import { Injectable } from "@nestjs/common"; -import { EventOptions, TransferFillConfirmedProperties, ampli } from "../../../ampli"; +import { EventOptions, TransferFillCompletedProperties, ampli } from "../../../ampli"; import { AppConfig } from "../../../configuration/configuration.service"; @Injectable() @@ -22,9 +22,9 @@ export class TrackService { public async trackDepositFilledEvent( userId: string, - eventProperties: TransferFillConfirmedProperties, + eventProperties: TransferFillCompletedProperties, eventOptions?: EventOptions, ) { - return ampli.transferFillConfirmed(userId, eventProperties, eventOptions); + return ampli.transferFillCompleted(userId, eventProperties, eventOptions); } } diff --git a/src/modules/scraper/adapter/messaging/TrackFillEventConsumer.ts b/src/modules/scraper/adapter/messaging/TrackFillEventConsumer.ts index 277dab14..4c6c3e6a 100644 --- a/src/modules/scraper/adapter/messaging/TrackFillEventConsumer.ts +++ b/src/modules/scraper/adapter/messaging/TrackFillEventConsumer.ts @@ -101,7 +101,9 @@ export class TrackFillEventConsumer { fillAmount: fillAmounts.formattedAmount, fillAmountUsd: fillAmounts.formattedAmountUsd, fillCompleteTimestamp: String(DateTime.fromISO(fillTx.date).toMillis()), - fillTime: String(DateTime.fromISO(fillTx.date).diff(DateTime.fromJSDate(deposit.depositDate)).as("milliseconds")), + fillTimeInMs: String( + DateTime.fromISO(fillTx.date).diff(DateTime.fromJSDate(deposit.depositDate)).as("milliseconds"), + ), fromAmount: fromAmounts.formattedAmount, fromAmountUsd: fromAmounts.formattedAmountUsd, fromChainId: String(deposit.sourceChainId), @@ -111,9 +113,9 @@ export class TrackFillEventConsumer { lpFeePct: formattedLpFeeValues.pct, lpFeeTotal: formattedLpFeeValues.total, lpFeeTotalUsd: formattedLpFeeValues.totalUsd, - NetworkFeeNative: fee, - NetworkFeeNativeToken: destinationChainInfo.nativeSymbol.toUpperCase(), - NetworkFeeUsd: feeUsd, + networkFeeNative: fee, + networkFeeNativeToken: destinationChainInfo.nativeSymbol.toUpperCase(), + networkFeeUsd: feeUsd, recipient: deposit.recipientAddr, referralProgramAddress: deposit.referralAddress || "-", relayFeePct: formattedRelayFeeValues.pct, From 582eacf067b8d35f214c1e0285203aab19ddea20 Mon Sep 17 00:00:00 2001 From: amateima <89395931+amateima@users.noreply.github.com> Date: Mon, 30 Jan 2023 16:55:24 +0200 Subject: [PATCH 2/3] fix: /deposits, exclude pending deposits with amount 0 (#212) * fix: /deposits, exclude pending deposits with amount 0 * Fix * Fix tests * Update service.ts --- src/modules/deposit/service.ts | 1 + test/deposit.e2e-spec.ts | 4 ++-- 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/src/modules/deposit/service.ts b/src/modules/deposit/service.ts index b577c0ef..c71c8984 100644 --- a/src/modules/deposit/service.ts +++ b/src/modules/deposit/service.ts @@ -97,6 +97,7 @@ export class DepositService { [deposits, total] = await this.depositRepository .createQueryBuilder("d") .where("d.status = :status", { status }) + .andWhere("d.amount > 0") .andWhere("d.depositDate > NOW() - INTERVAL '1 days'") .andWhere(`d.depositRelayerFeePct * :multiplier >= d.suggestedRelayerFeePct`, { multiplier: this.appConfig.values.suggestedFees.deviationBufferMultiplier, diff --git a/test/deposit.e2e-spec.ts b/test/deposit.e2e-spec.ts index 8fd293a7..803eed7e 100644 --- a/test/deposit.e2e-spec.ts +++ b/test/deposit.e2e-spec.ts @@ -25,12 +25,12 @@ describe("GET /deposits", () => { // filled deposits with depositIds 10 - 19 and ascending depositDate const FILLED_DEPOSITS = mockManyDepositEntities(10, { depositIdStartIndex: 10, - overrides: { status: "filled", depositorAddr: depositorAddress }, + overrides: { status: "filled", depositorAddr: depositorAddress, amount: "10", filled: "10" }, }); // pending deposits with depositIds 20 - 29 and ascending depositDate const PENDING_DEPOSITS = mockManyDepositEntities(10, { depositIdStartIndex: 20, - overrides: { status: "pending", depositorAddr: depositorAddress }, + overrides: { status: "pending", depositorAddr: depositorAddress, amount: "10" }, }); beforeAll(async () => { From 452cdbf056b996d668c807793b6e734e35af2d5d Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Thu, 16 Feb 2023 23:49:08 +0000 Subject: [PATCH 3/3] build(deps): bump undici from 5.5.1 to 5.19.1 Bumps [undici](https://github.com/nodejs/undici) from 5.5.1 to 5.19.1. - [Release notes](https://github.com/nodejs/undici/releases) - [Commits](https://github.com/nodejs/undici/compare/v5.5.1...v5.19.1) --- updated-dependencies: - dependency-name: undici dependency-type: indirect ... Signed-off-by: dependabot[bot] --- yarn.lock | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/yarn.lock b/yarn.lock index 25990b8a..deeb8a47 100644 --- a/yarn.lock +++ b/yarn.lock @@ -5892,7 +5892,7 @@ bull@^4.8.4: semver "^7.3.2" uuid "^8.3.0" -busboy@^1.0.0: +busboy@^1.0.0, busboy@^1.6.0: version "1.6.0" resolved "https://registry.yarnpkg.com/busboy/-/busboy-1.6.0.tgz#966ea36a9502e43cdb9146962523b92f531f6893" integrity sha512-8SFQbg/0hQ9xy3UNTB0YEnsNBbWfhf7RtnzpL7TkBiTBRfrQ9Fxcnz7VJsleJpyp6rVLvXiuORqjlHi5q+PYuA== @@ -16196,9 +16196,11 @@ underscore@~1.13.2: integrity sha512-+A5Sja4HP1M08MaXya7p5LvjuM7K6q/2EaC0+iovj/wOcMsTzMvDFbasi/oSapiwOlt252IqsKqPjCl7huKS0A== undici@^5.4.0: - version "5.5.1" - resolved "https://registry.yarnpkg.com/undici/-/undici-5.5.1.tgz#baaf25844a99eaa0b22e1ef8d205bffe587c8f43" - integrity sha512-MEvryPLf18HvlCbLSzCW0U00IMftKGI5udnjrQbC5D4P0Hodwffhv+iGfWuJwg16Y/TK11ZFK8i+BPVW2z/eAw== + version "5.19.1" + resolved "https://registry.yarnpkg.com/undici/-/undici-5.19.1.tgz#92b1fd3ab2c089b5a6bd3e579dcda8f1934ebf6d" + integrity sha512-YiZ61LPIgY73E7syxCDxxa3LV2yl3sN8spnIuTct60boiiRaE1J8mNWHO8Im2Zi/sFrPusjLlmRPrsyraSqX6A== + dependencies: + busboy "^1.6.0" unique-string@^2.0.0: version "2.0.0"