-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
cli cmd for return depositors (#652)
* return user cli * rename data pkg * move utils into data package and import in screener cli * changeset
- Loading branch information
1 parent
0a08a9e
commit 74c4be8
Showing
24 changed files
with
105 additions
and
46 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
--- | ||
"@nocturne-xyz/deposit-screener": patch | ||
"@nocturne-xyz/data": patch | ||
--- | ||
|
||
move csv and address parsing util functions into data package and import in screener |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
--- | ||
"@nocturne-xyz/data": minor | ||
--- | ||
|
||
add return-depositors command to track return users |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
import { parseAndFilterCsvOfAddresses } from "../utils"; | ||
import { Command } from "commander"; | ||
|
||
export const returnDepositors = new Command("return-depositors") | ||
.summary("Print list of return depositors (at least 2 deposits)") | ||
.description( | ||
"Print list of return depositors to number of deposits. Minimum 2 deposits to show in list." | ||
) | ||
.requiredOption("--input-csv <string>", "Path to input CSV") | ||
.action(main); | ||
|
||
async function main(options: any): Promise<void> { | ||
const { inputCsv } = options; | ||
|
||
const addresses = await parseAndFilterCsvOfAddresses(inputCsv, { | ||
dedupAddresses: false, | ||
}); | ||
|
||
const depositorsMap = new Map<string, number>(); | ||
for (const address of addresses) { | ||
const count = depositorsMap.get(address) || 0; | ||
depositorsMap.set(address, count + 1); | ||
} | ||
|
||
const filtered = new Map( | ||
Array.from(depositorsMap.entries()) | ||
.filter(([, count]) => count > 1) | ||
.sort((a, b) => b[1] - a[1]) | ||
); | ||
|
||
console.log(filtered); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
export * from "./utils"; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
import { Address } from "@nocturne-xyz/core"; | ||
import fs from "fs"; | ||
|
||
interface ParseAndFilterCsvOfAddressesOpts { | ||
dedupAddresses?: boolean; | ||
} | ||
|
||
export async function parseAndFilterCsvOfAddresses( | ||
path: string, | ||
opts: ParseAndFilterCsvOfAddressesOpts = {} | ||
): Promise<Address[]> { | ||
const inputFileText = await fs.promises.readFile(path, "utf-8"); | ||
// split the input file into lines | ||
const inputFileLines = inputFileText.split("\n"); | ||
// take the first column | ||
const addresses = inputFileLines.map((line) => line.trim().split(",")[0]); | ||
// filter out anything that doesn't look like an address | ||
const filteredAddresses = addresses.filter((address) => { | ||
return address.match(/^0x[0-9a-fA-F]{40}$/i); | ||
}); | ||
|
||
// deduplicate and sort | ||
return opts.dedupAddresses | ||
? dedupAddressesInOrder(filteredAddresses) | ||
: filteredAddresses; | ||
} | ||
|
||
export function dedupAddressesInOrder(addresses: string[]): string[] { | ||
// deduplicate and sort | ||
const uniqueAddresses = new Set(); | ||
const dedupedAddresses = []; | ||
for (const address of addresses) { | ||
if (!uniqueAddresses.has(address)) { | ||
uniqueAddresses.add(address); | ||
dedupedAddresses.push(address); | ||
} | ||
} | ||
|
||
return dedupedAddresses; | ||
} |
File renamed without changes.
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters