diff --git a/indexer/pnpm-lock.yaml b/indexer/pnpm-lock.yaml index 8f0733538a..6b5fa6706a 100644 --- a/indexer/pnpm-lock.yaml +++ b/indexer/pnpm-lock.yaml @@ -628,7 +628,6 @@ importers: ts-node: ^10.8.2 tsconfig-paths: ^4.0.0 typescript: ^4.7.4 - unique-username-generator: ^1.3.0 uuid: ^8.3.2 dependencies: '@dydxprotocol-indexer/base': link:../../packages/base @@ -646,7 +645,6 @@ importers: lodash: 4.17.21 luxon: 3.0.1 redis: 2.8.0 - unique-username-generator: 1.3.0 uuid: 8.3.2 devDependencies: '@dydxprotocol-indexer/dev': link:../../packages/dev @@ -13599,10 +13597,6 @@ packages: set-value: 2.0.1 dev: false - /unique-username-generator/1.3.0: - resolution: {integrity: sha512-oPs+Jq9UlXmcrpzrpYvWOWVUVLkJ0/x8zM66ikWEBe1l/hBqXS5fofsDvdScLIlPtqQKlu8/Y91b6T2XtIFubQ==} - dev: false - /universalify/2.0.0: resolution: {integrity: sha512-hAZsKq7Yy11Zu1DE0OzWjw7nnLZmJZYTDZZyEFHZdUhV8FkH5MCfoU1XMaxXovpyW5nq5scPqq0ZDP9Zyl04oQ==} engines: {node: '>= 10.0.0'} diff --git a/indexer/services/roundtable/__tests__/helpers/usernames-helper.test.ts b/indexer/services/roundtable/__tests__/helpers/usernames-helper.test.ts new file mode 100644 index 0000000000..38c5bb7cb1 --- /dev/null +++ b/indexer/services/roundtable/__tests__/helpers/usernames-helper.test.ts @@ -0,0 +1,11 @@ +import { generateUsername } from '../../src/helpers/usernames-helper'; + +describe('usernames-helper', () => { + it('Check format of username', () => { + const username: string = generateUsername(); + expect(username.match(/[A-Z]/g)).toHaveLength(2); + expect(username.match(/\d/g)).toHaveLength(3); + // check length is at the very minimum 7 + expect(username.length).toBeGreaterThanOrEqual(7); + }); +}); diff --git a/indexer/services/roundtable/package.json b/indexer/services/roundtable/package.json index b3fda95490..ad23413ca1 100644 --- a/indexer/services/roundtable/package.json +++ b/indexer/services/roundtable/package.json @@ -31,7 +31,6 @@ "lodash": "^4.17.21", "luxon": "^3.0.1", "redis": "2.8.0", - "unique-username-generator": "^1.3.0", "uuid": "^8.3.2" }, "devDependencies": { diff --git a/indexer/services/roundtable/src/config.ts b/indexer/services/roundtable/src/config.ts index b4ce74e577..714a34a3de 100644 --- a/indexer/services/roundtable/src/config.ts +++ b/indexer/services/roundtable/src/config.ts @@ -196,6 +196,7 @@ export const configSchema = { // Subaccount username generator SUBACCOUNT_USERNAME_NUM_RANDOM_DIGITS: parseInteger({ default: 3 }), + SUBACCOUNT_USERNAME_MAX_LENGTH: parseInteger({ default: 13 }), }; export default parseSchema(configSchema); diff --git a/indexer/services/roundtable/src/helpers/adjectives.json b/indexer/services/roundtable/src/helpers/adjectives.json new file mode 100644 index 0000000000..c9873f0aaf --- /dev/null +++ b/indexer/services/roundtable/src/helpers/adjectives.json @@ -0,0 +1,359 @@ +[ + "able", + "ace", + "acid", + "airy", + "alert", + "all", + "alpha", + "aloof", + "amber", + "ample", + "apt", + "arcane", + "arid", + "artsy", + "ashy", + "atomic", + "avid", + "awake", + "aware", + "azure", + "basic", + "beefy", + "beige", + "best", + "big", + "blah", + "bland", + "blocky", + "blue", + "bogus", + "bold", + "bony", + "bossy", + "bouncy", + "brave", + "breezy", + "brief", + "brisk", + "broad", + "bubbly", + "bumpy", + "busy", + "cagey", + "calm", + "campy", + "candid", + "canny", + "casual", + "chaotic", + "cheap", + "cheeky", + "cheery", + "chief", + "chilly", + "chubby", + "civil", + "clean", + "clear", + "close", + "cold", + "comfy", + "cool", + "copper", + "coral", + "corny", + "cozy", + "crafty", + "cranky", + "crisp", + "crusty", + "curly", + "curt", + "cushy", + "cute", + "daffy", + "dainty", + "damp", + "dandy", + "deep", + "dense", + "dim", + "dinky", + "dizzy", + "domed", + "dotty", + "dry", + "dull", + "dusty", + "eager", + "early", + "earthy", + "easy", + "elite", + "empty", + "equal", + "exact", + "exotic", + "expert", + "extra", + "faded", + "fair", + "fancy", + "far", + "fast", + "fiery", + "fine", + "firm", + "fishy", + "flaky", + "flat", + "flimsy", + "fresh", + "frilly", + "frosty", + "frugal", + "full", + "funny", + "fuzzy", + "gauche", + "gaudy", + "giant", + "giddy", + "glad", + "gnarly", + "gonzo", + "good", + "goofy", + "grand", + "great", + "green", + "grim", + "gummy", + "handy", + "happy", + "hard", + "hardy", + "harsh", + "hasty", + "hazy", + "heavy", + "hefty", + "high", + "hilly", + "hip", + "hot", + "huge", + "humid", + "husky", + "icky", + "icy", + "ideal", + "idle", + "inky", + "itchy", + "ivory", + "jade", + "jazzy", + "jolly", + "jumpy", + "keen", + "khaki", + "kind", + "lame", + "large", + "last", + "late", + "lavish", + "lax", + "lazy", + "leafy", + "lemon", + "level", + "light", + "like", + "lilac", + "lithe", + "live", + "lofty", + "lone", + "long", + "loud", + "lousy", + "low", + "loyal", + "lucid", + "lucky", + "lunar", + "macro", + "mad", + "main", + "major", + "maroon", + "matey", + "mauve", + "meek", + "merry", + "mild", + "misty", + "moist", + "moral", + "mossy", + "mute", + "mushy", + "naive", + "near", + "neat", + "neon", + "new", + "next", + "nice", + "nifty", + "noble", + "noisy", + "oblong", + "obtuse", + "odd", + "olden", + "open", + "opal", + "other", + "oval", + "pale", + "paltry", + "parched", + "pastel", + "peaky", + "petty", + "plain", + "plump", + "polite", + "poor", + "proud", + "pure", + "quick", + "quiet", + "rapid", + "rare", + "raw", + "ready", + "real", + "red", + "retro", + "rich", + "rigid", + "ripe", + "roomy", + "rosy", + "rough", + "round", + "rude", + "royal", + "rusty", + "sad", + "safe", + "salty", + "same", + "sandy", + "sane", + "sassy", + "scaly", + "sepia", + "shaky", + "sharp", + "shiny", + "short", + "shy", + "silky", + "silly", + "slack", + "sleek", + "slick", + "slim", + "slow", + "small", + "smart", + "smug", + "smooth", + "snappy", + "snug", + "soft", + "solid", + "sonic", + "sore", + "sour", + "spicy", + "spiffy", + "spry", + "stark", + "steel", + "steep", + "stern", + "still", + "stout", + "stuffy", + "sunny", + "super", + "sweet", + "swift", + "tacky", + "tall", + "tame", + "tan", + "tangy", + "tart", + "tasty", + "taupe", + "teal", + "tepid", + "tense", + "thick", + "thin", + "tidy", + "tiny", + "tired", + "tough", + "trim", + "true", + "tubby", + "twisty", + "udder", + "ultra", + "umber", + "unique", + "unruly", + "untidy", + "unzip", + "upper", + "urban", + "used", + "vague", + "vain", + "valid", + "vapid", + "vast", + "vexed", + "vital", + "vivid", + "wacky", + "warm", + "weak", + "weary", + "wide", + "windy", + "wiry", + "wise", + "wispy", + "witty", + "wooly", + "woozy", + "yappy", + "yummy", + "zany", + "zero", + "zesty", + "zingy", + "zippy", + "zoom" +] diff --git a/indexer/services/roundtable/src/helpers/nouns.json b/indexer/services/roundtable/src/helpers/nouns.json new file mode 100644 index 0000000000..63afed6d28 --- /dev/null +++ b/indexer/services/roundtable/src/helpers/nouns.json @@ -0,0 +1,240 @@ +[ + "ace", + "acorn", + "act", + "air", + "ant", + "apple", + "arm", + "art", + "atom", + "axe", + "bag", + "ball", + "band", + "bank", + "bark", + "base", + "bath", + "bead", + "beam", + "bean", + "bear", + "bed", + "bee", + "bell", + "belt", + "bird", + "blade", + "boat", + "bone", + "book", + "boot", + "bowl", + "box", + "bread", + "brick", + "brush", + "bulb", + "bus", + "cake", + "can", + "cap", + "car", + "card", + "cart", + "cat", + "cave", + "chair", + "chalk", + "chart", + "cheese", + "chess", + "clay", + "clock", + "cloud", + "coat", + "coin", + "comb", + "cook", + "cord", + "cork", + "corn", + "cow", + "crab", + "crow", + "crown", + "cube", + "cup", + "desk", + "dish", + "dog", + "door", + "dot", + "drum", + "duck", + "dust", + "ear", + "egg", + "eye", + "face", + "fan", + "farm", + "fern", + "fire", + "fish", + "flag", + "flute", + "fog", + "food", + "foot", + "fork", + "fox", + "frog", + "fruit", + "game", + "gate", + "gem", + "gift", + "glass", + "glove", + "goal", + "goat", + "gold", + "grape", + "grass", + "hat", + "head", + "heart", + "hill", + "home", + "hook", + "horn", + "horse", + "hose", + "house", + "ice", + "ink", + "iron", + "jar", + "jet", + "key", + "kite", + "knee", + "knife", + "lamp", + "leaf", + "leg", + "lens", + "line", + "lion", + "lip", + "lock", + "log", + "loop", + "mail", + "map", + "mask", + "mat", + "milk", + "mint", + "mist", + "moon", + "moss", + "moth", + "mouse", + "mug", + "nail", + "nest", + "net", + "nose", + "note", + "nut", + "oar", + "owl", + "page", + "pan", + "pea", + "peach", + "pear", + "pen", + "pig", + "pin", + "pipe", + "plan", + "plane", + "plant", + "plate", + "plum", + "pool", + "pot", + "rain", + "rat", + "ring", + "road", + "rock", + "roof", + "room", + "root", + "rope", + "rose", + "rug", + "sail", + "salt", + "sand", + "sea", + "seed", + "ship", + "shoe", + "shop", + "sign", + "silk", + "sink", + "sky", + "sled", + "snow", + "soap", + "sock", + "sofa", + "soup", + "star", + "stem", + "step", + "stew", + "stove", + "sun", + "swan", + "table", + "tail", + "tea", + "tent", + "tie", + "tire", + "toe", + "tomb", + "tool", + "tooth", + "top", + "toy", + "tree", + "tub", + "vase", + "vest", + "wall", + "wave", + "weed", + "well", + "wheel", + "wing", + "wire", + "wolf", + "wood", + "wool", + "worm", + "yard", + "yarn", + "yoyo", + "zebra", + "zero", + "zoo" +] diff --git a/indexer/services/roundtable/src/helpers/usernames-helper.ts b/indexer/services/roundtable/src/helpers/usernames-helper.ts new file mode 100644 index 0000000000..e668d46a2b --- /dev/null +++ b/indexer/services/roundtable/src/helpers/usernames-helper.ts @@ -0,0 +1,18 @@ +import { randomInt } from 'crypto'; + +import config from '../config'; +import adjectives from './adjectives.json'; +import nouns from './nouns.json'; + +export function generateUsername(): string { + const randomAdjective: string = adjectives[randomInt(0, adjectives.length)]; + const randomNoun: string = nouns[randomInt(0, nouns.length)]; + const randomNumber: string = randomInt(0, 1000).toString().padStart( + config.SUBACCOUNT_USERNAME_NUM_RANDOM_DIGITS, '0'); + + const capitalizedAdjective: string = randomAdjective.charAt( + 0).toUpperCase() + randomAdjective.slice(1); + const capitalizedNoun: string = randomNoun.charAt(0).toUpperCase() + randomNoun.slice(1); + + return `${capitalizedAdjective}${capitalizedNoun}${randomNumber}`; +} diff --git a/indexer/services/roundtable/src/tasks/subaccount-username-generator.ts b/indexer/services/roundtable/src/tasks/subaccount-username-generator.ts index d9fdbbe196..af0312481c 100644 --- a/indexer/services/roundtable/src/tasks/subaccount-username-generator.ts +++ b/indexer/services/roundtable/src/tasks/subaccount-username-generator.ts @@ -3,19 +3,18 @@ import { SubaccountUsernamesTable, SubaccountsWithoutUsernamesResult, } from '@dydxprotocol-indexer/postgres'; -import { generateUsername } from 'unique-username-generator'; -import config from '../config'; +import { generateUsername } from '../helpers/usernames-helper'; export default async function runTask(): Promise { const subaccounts: SubaccountsWithoutUsernamesResult[] = await SubaccountUsernamesTable.getSubaccountsWithoutUsernames(); for (const subaccount of subaccounts) { - const username: string = generateUsername('', config.SUBACCOUNT_USERNAME_NUM_RANDOM_DIGITS); + const username: string = generateUsername(); try { // if insert fails, try it in the next roundtable cycle - // There are roughly 50 Billion possible usernames with 3 random digits + // There are roughly ~87.5 million possible usernames // so the chance of a collision is very low await SubaccountUsernamesTable.create({ username,