Skip to content

Commit

Permalink
screener cli fixes (#641)
Browse files Browse the repository at this point in the history
* small fixes to screener cli trm monitor after running first time on mainnet

* changesets

* delete csv

* add changeset

* prettier
  • Loading branch information
luketchang authored Nov 22, 2023
1 parent f5220e8 commit 5a3afc7
Show file tree
Hide file tree
Showing 7 changed files with 48 additions and 16 deletions.
5 changes: 5 additions & 0 deletions .changeset/brown-jeans-end.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@nocturne-xyz/deposit-screener": patch
---

fix trm tx monitor command to only handle transfers where tx.from matches --from-address
5 changes: 5 additions & 0 deletions .changeset/popular-frogs-try.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@nocturne-xyz/deposit-screener": patch
---

trm tx monitor uses rand uuid to avoid clashes of transfers within the same transaction
5 changes: 5 additions & 0 deletions .changeset/shiny-kangaroos-change.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@nocturne-xyz/offchain-utils": patch
---

fix bug where response.clone() was prematurely consuming response, ser then deser to deep copy
8 changes: 7 additions & 1 deletion actors/deposit-screener/.env.example
Original file line number Diff line number Diff line change
Expand Up @@ -14,4 +14,10 @@ OZ_RELAYER_SPEED=
TX_SIGNER_KEY=
ATTESTATION_SIGNER_KEY=

OTEL_EXPORTER_OTLP_ENDPOINT=
OTEL_EXPORTER_OTLP_ENDPOINT=

# CLI tools
MISTTRACK_API_KEY=
TRM_API_KEY=
ETHERSCAN_API_KEY=
COINMARKETCAP_API_KEY=
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ import fs from "fs";
import path from "path";
import { EtherscanErc20Transfer, EtherscanInternalTx } from "./etherscan";
import { TRMTransferRequest } from "./trm";
import { randomUUID } from "crypto";

export type OutputItem = {
path: string;
Expand Down Expand Up @@ -59,7 +60,7 @@ export function etherscanErc20ToTrmTransferRequest(
assetAmount: wholeTokensAmount.toString(),
chain: "ethereum", // TODO: allow more chains
destinationAddress: transfer.to,
externalId: transfer.hash,
externalId: randomUUID(),
fiatCurrency: "USD",
fiatValue: fiatValue.toString(), // Assuming fiatValue is not directly provided in Etherscan's response
onchainReference: transfer.hash,
Expand Down
28 changes: 20 additions & 8 deletions actors/deposit-screener/src/cli/commands/inspect/trmTxMonitor.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,8 @@ import {
getLocalRedis,
} from "./helpers/utils";
import * as JSON from "bigint-json-serialization";
import { submitTrmTransfer } from "./helpers/trm";
import { getCoinMarketCapPriceConversion } from "./helpers";
import { getCoinMarketCapPriceConversion, submitTrmTransfer } from "./helpers";
import { ethers } from "ethers";

/**
* Example
Expand Down Expand Up @@ -71,13 +71,19 @@ async function main(options: any): Promise<void> {
let erc20Outflows: EtherscanErc20Transfer[] = [];
if (tokenAddress) {
logger.info(`Checking outflows for token address: ${tokenAddress}`);
erc20Outflows = await getEtherscanErc20Transfers(
tokenAddress,
fromAddress,
startBlock,
endBlock,
redis
erc20Outflows = (
await getEtherscanErc20Transfers(
tokenAddress,
fromAddress,
startBlock,
endBlock,
redis
)
).filter(
(tx) =>
ethers.utils.getAddress(tx.from) == ethers.utils.getAddress(fromAddress)
);

erc20Outflows.forEach((tx) => {
logger.info(`ERC-20 outflow: ${JSON.stringify(tx)}`);
});
Expand Down Expand Up @@ -126,6 +132,8 @@ async function main(options: any): Promise<void> {
const res = await submitTrmTransfer(trmRequest, redis);
logger.info(`TRM response: ${JSON.stringify(res)}`);
}

logger.info(`Sent ${trmErc20Requests.length} ETH transfers to TRM`);
}

if (ethOutflows.length > 0) {
Expand All @@ -148,7 +156,11 @@ async function main(options: any): Promise<void> {
const res = await submitTrmTransfer(trmRequest, redis);
logger.info(`TRM response: ${JSON.stringify(res)}`);
}

logger.info(`Sent ${trmEthRequests.length} ETH transfers to TRM`);
}

logger.info("Done!");
}

export default runTrmTxMonitor;
10 changes: 4 additions & 6 deletions packages/offchain-utils/src/request.ts
Original file line number Diff line number Diff line change
Expand Up @@ -90,13 +90,11 @@ export async function cachedFetch(
}

// Cache response
await redis.setex(
cacheKey,
ttlSeconds,
await serializeResponse(response.clone())
);
const serializedResponse = await serializeResponse(response);
await redis.setex(cacheKey, ttlSeconds, serializedResponse);

return response.clone();
// Hack: create copy of response since we already consumed it via res.json() in serializeResponse
return deserializeToResponseString(serializedResponse);
}

export function formatCachedFetchCacheKey(
Expand Down

0 comments on commit 5a3afc7

Please sign in to comment.