From cdc7164b8e9ac95fe6e763d299df0a7e580b6434 Mon Sep 17 00:00:00 2001 From: bhavik Date: Sat, 4 Dec 2021 15:30:24 +0530 Subject: [PATCH] checking transactions to/from dsa --- README.md | 2 +- Token_Tracking_agent/publish.log | 2 ++ Token_Tracking_agent/src/agent.js | 32 ++++++++++++++++++++++---- Token_Tracking_agent/src/agent.spec.js | 4 ++-- 4 files changed, 32 insertions(+), 8 deletions(-) create mode 100644 Token_Tracking_agent/publish.log diff --git a/README.md b/README.md index 653cc76..5f7a7da 100644 --- a/README.md +++ b/README.md @@ -26,4 +26,4 @@ npm start For verifying agent behaviour with transactions - ``` npm run tx -`` \ No newline at end of file +``` \ No newline at end of file diff --git a/Token_Tracking_agent/publish.log b/Token_Tracking_agent/publish.log new file mode 100644 index 0000000..01811e1 --- /dev/null +++ b/Token_Tracking_agent/publish.log @@ -0,0 +1,2 @@ +Thu, 02 Dec 2021 02:17:06 GMT: successfully pushed image with reference bafybeiapsyqgp2cgimwxsl4djbtd3opwym2gz5d7zraedl2mftdodtm2ci@sha256:c64dec59e9d46d2d93bb00fb579f8b7b2019038e156e4507297d0269916fcdfd +Sat, 04 Dec 2021 09:58:23 GMT: successfully pushed image with reference bafybeiempcyy6x3m7h7cwotf6knwegqzpxdwybd4ie652oenzne6uuzq2e@sha256:eaf45f1698e54b90c09ebddb6c58e754a6da8c62ed894b9463077695cc92fced diff --git a/Token_Tracking_agent/src/agent.js b/Token_Tracking_agent/src/agent.js index b80ba78..c17a5b6 100644 --- a/Token_Tracking_agent/src/agent.js +++ b/Token_Tracking_agent/src/agent.js @@ -41,14 +41,35 @@ function provideHandleTransaction(amountThreshold) { const to = tokenTransfer.args.to; const from = tokenTransfer.args.from; + const from_account = await instaList.accountID(from) const to_account = await instaList.accountID(to) const from_account_id = from_account.toNumber(); const to_account_id = to_account.toNumber(); - // Not a dsa address if account_id is 0 - if (from_account_id == 0 && to_account_id == 0) { + + let is_dsa_from = false; + let is_dsa_to = false; + + // address is dsa address if account_id is not 0 + let write_dsa_from = ""; + let write_dsa_to = ""; + + let check_dsa; + + if (from_account_id != 0) { + is_dsa_from = true; + write_dsa_from = "(dsa)"; + check_dsa = "from a dsa"; + } + if (to_account_id != 0) { + is_dsa_to = true; + write_dsa_to = "(dsa)"; + check_dsa = "to a dsa"; + } + + if (is_dsa_from == false && is_dsa_to == false) { continue; } @@ -61,16 +82,17 @@ function provideHandleTransaction(amountThreshold) { const formattedAmount = amount.toFixed(2); + findings.push( Finding.fromObject({ name: `Large ${tokens[token].name} Transfer`, - description: `${formattedAmount} ${tokens[token].name} Transferred`, + description: `${formattedAmount} ${tokens[token].name} transferred ${check_dsa}`, alertId: "INST-41", severity: FindingSeverity.Info, type: FindingType.Info, metadata: { - from: tokenTransfer.args.from, - to: tokenTransfer.args.to, + from: from.concat(write_dsa_from), + to: to.concat(write_dsa_to), amount: formattedAmount, }, }) diff --git a/Token_Tracking_agent/src/agent.spec.js b/Token_Tracking_agent/src/agent.spec.js index 0119cfa..8736416 100644 --- a/Token_Tracking_agent/src/agent.spec.js +++ b/Token_Tracking_agent/src/agent.spec.js @@ -73,12 +73,12 @@ describe("large transfer event agent", () => { expect(findings).toStrictEqual([ Finding.fromObject({ name: "Large DAI Transfer", - description: `${formattedAmount} DAI Transferred`, + description: `${formattedAmount} DAI transferred from a dsa address`, alertId: "INST-41", severity: FindingSeverity.Info, type: FindingType.Info, metadata: { - from: mockDaiTransferEvent.args.from, + from: mockDaiTransferEvent.args.from.concat("(dsa address)"), to: mockDaiTransferEvent.args.to, amount: formattedAmount, },