Skip to content

Commit

Permalink
Mixmix/types+lint (#44)
Browse files Browse the repository at this point in the history
* Improves README readability. (#42)

* Improves README readability.

* Update README.md

Co-authored-by: Nayyir Jutha <nayyir.jutha@gmail.com>

---------

Co-authored-by: Nayyir Jutha <nayyir.jutha@gmail.com>

* remove deps, move files, add license, fix package.json

* linting hooks, tidy

* mostly fix types?

---------

Co-authored-by: Johnny <9611008+johnnymatthews@users.noreply.github.com>
Co-authored-by: Nayyir Jutha <nayyir.jutha@gmail.com>
  • Loading branch information
3 people authored May 17, 2024
1 parent 6837b9b commit 9920537
Show file tree
Hide file tree
Showing 22 changed files with 3,977 additions and 4,698 deletions.
10 changes: 0 additions & 10 deletions .eslint.js

This file was deleted.

5 changes: 2 additions & 3 deletions .eslintrc.cjs
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,11 @@ module.exports = {
root: true,
rules: {
indent: ['error', 2],
'space-before-function-paren': ['error', 'always'],
'space-before-function-paren': 2,
'@typescript-eslint/no-var-requires': 'off',
'@typescript-eslint/no-unused-vars': 'error',
'@typescript-eslint/ban-ts-comment': 1,
'@typescript-eslint/no-explicit-any': 'off',

'@typescript-eslint/no-explicit-any': 'warn'
},
ignorePatterns: ['node_modules/', 'dist/', 'examples/', '.yarnrc.yml'],
}
2 changes: 2 additions & 0 deletions .husky/pre-commit
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
npx tsc && echo "✔ tsc..." && \
npx lint-staged
661 changes: 661 additions & 0 deletions LICENSE.md

Large diffs are not rendered by default.

39 changes: 24 additions & 15 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,40 +1,42 @@
{
"name": "devnet_cli_tool",
"name": "@entropyxyz/cli",
"version": "1.0.0",
"description": "",
"scripts": {
"entropy": "yarn run start",
"test": "echo \"Error: no test specified\" && exit 1",
"lint:fix": "eslint . --ext .ts --fix",
"lint": "eslint . --ext .ts",
"tsc": "tsc",
"start": "ts-node index.ts"
"start": "ts-node src/index.ts",
"entropy": "npm run start",
"test": "npm run type-check && npm run lint",
"lint": "eslint . --ext .ts --fix",
"type-check": "tsc --project tsconfig.json",
"prepare": "husky",
"postinstall": "husky",
"prepack": "pinst --disable",
"postpack": "pinst --enable"
},
"repository": {
"type": "git",
"url": "git+https://github.com/entropyxyz/devnet_cli_tool.git"
"url": "git+https://github.com/entropyxyz/cli.git"
},
"keywords": [],
"author": "Jesse Abramowitz",
"license": "ISC",
"license": "AGPL-3.0-only",
"bugs": {
"url": "https://github.com/entropyxyz/devnet_cli_tool/issues"
"url": "https://github.com/entropyxyz/cli/issues"
},
"homepage": "https://github.com/entropyxyz/devnet_cli_tool#readme",
"homepage": "https://github.com/entropyxyz/cli#readme",
"dependencies": {
"@entropyxyz/sdk": "^0.1.4",
"@ethereumjs/util": "^9.0.2",
"@polkadot/util": "^12.6.2",
"@polkadot/util-crypto": "^12.5.1",
"@types/node": "^20.12.11",
"@types/node": "^20.12.12",
"alchemy-sdk": "^3.1.2",
"ansi-colors": "^4.1.3",
"axios": "^0.27.2",
"cli-progress": "^3.12.0",
"dotenv": "^16.4.1",
"ethers": "^5.7.2",
"inquirer": "8.0.0",
"ts-node": "^10.9.1",
"ts-node": "^10.9.2",
"typescript": "^4.8.4",
"viem": "^2.7.8",
"x25519": "^0.1.0"
Expand All @@ -44,10 +46,17 @@
"@swc/helpers": "^0.5.6",
"@types/cli-progress": "^3",
"@types/inquirer": "^9.0.2",
"@types/node": "^20.12.12",
"@typescript-eslint/eslint-plugin": "^6.21.0",
"@typescript-eslint/parser": "^6.21.0",
"eslint": "^8.56.0",
"husky": "^9.0.11",
"lint-staged": "^15.2.2",
"pinst": "^3.0.0",
"regenerator-runtime": "^0.14.1"
},
"packageManager": "yarn@1.22.1"
"packageManager": "yarn@1.22.1",
"lint-staged": {
"*.ts": "eslint --fix"
}
}
6 changes: 4 additions & 2 deletions src/common/initializeEntropy.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
import Entropy, { wasmGlobalsReady } from "@entropyxyz/sdk"
import Keyring from '@entropyxyz/sdk/keys'
// TODO: fix importing of types from @entropy/sdk/keys
// @ts-ignore
import Keyring from "@entropyxyz/sdk/keys"
import { decrypt } from "../flows/password"
import inquirer from "inquirer"

Expand Down Expand Up @@ -61,4 +63,4 @@ export const initializeEntropy = async ({data}, endpoint: string): Promise<Entro
}

return entropy
}
}
39 changes: 21 additions & 18 deletions src/common/prompts.ts
Original file line number Diff line number Diff line change
@@ -1,22 +1,25 @@
/* {
type: (String) Type of the prompt. Defaults: input - Possible values: input, number, confirm, list, rawlist, expand, checkbox, password, editor
name: (String) The name to use when storing the answer in the answers hash. If the name contains periods, it will define a path in the answers hash.
message: (String|Function) The question to print. If defined as a function, the first parameter will be the current inquirer session answers. Defaults to the value of name (followed by a colon).
default: (String|Number|Boolean|Array|Function) Default value(s) to use if nothing is entered, or a function that returns the default value(s). If defined as a function, the first parameter will be the current inquirer session answers.
choices: (Array|Function) Choices array or a function returning a choices array. If defined as a function, the first parameter will be the current inquirer session answers. Array values can be simple numbers, strings, or objects containing a name (to display in list), a value (to save in the answers hash), and a short (to display after selection) properties. The choices array can also contain a Separator.
validate: (Function) Receive the user input and answers hash. Should return true if the value is valid, and an error message (String) otherwise. If false is returned, a default error message is provided.
filter: (Function) Receive the user input and answers hash. Returns the filtered value to be used inside the program. The value returned will be added to the Answers hash.
transformer: (Function) Receive the user input, answers hash and option flags, and return a transformed value to display to the user. The transformation only impacts what is shown while editing. It does not modify the answers hash.
when: (Function, Boolean) Receive the current user answers hash and should return true or false depending on whether or not this question should be asked. The value can also be a simple boolean.
pageSize: (Number) Change the number of lines that will be rendered when using list, rawList, expand or checkbox.
prefix: (String) Change the default prefix message.
suffix: (String) Change the default suffix message.
askAnswered: (Boolean) Force to prompt the question if the answer already exists.
loop: (Boolean) Enable list looping. Defaults: true
waitUserInput: (Boolean) Flag to enable/disable wait for user input before opening system editor - Defaults: true} */
/*
{
type: (String) Type of the prompt. Defaults: input - Possible values: input, number, confirm, list, rawlist, expand, checkbox, password, editor
name: (String) The name to use when storing the answer in the answers hash. If the name contains periods, it will define a path in the answers hash.
message: (String|Function) The question to print. If defined as a function, the first parameter will be the current inquirer session answers. Defaults to the value of name (followed by a colon).
default: (String|Number|Boolean|Array|Function) Default value(s) to use if nothing is entered, or a function that returns the default value(s). If defined as a function, the first parameter will be the current inquirer session answers.
choices: (Array|Function) Choices array or a function returning a choices array. If defined as a function, the first parameter will be the current inquirer session answers. Array values can be simple numbers, strings, or objects containing a name (to display in list), a value (to save in the answers hash), and a short (to display after selection) properties. The choices array can also contain a Separator.
validate: (Function) Receive the user input and answers hash. Should return true if the value is valid, and an error message (String) otherwise. If false is returned, a default error message is provided.
filter: (Function) Receive the user input and answers hash. Returns the filtered value to be used inside the program. The value returned will be added to the Answers hash.
transformer: (Function) Receive the user input, answers hash and option flags, and return a transformed value to display to the user. The transformation only impacts what is shown while editing. It does not modify the answers hash.
when: (Function, Boolean) Receive the current user answers hash and should return true or false depending on whether or not this question should be asked. The value can also be a simple boolean.
pageSize: (Number) Change the number of lines that will be rendered when using list, rawList, expand or checkbox.
prefix: (String) Change the default prefix message.
suffix: (String) Change the default suffix message.
askAnswered: (Boolean) Force to prompt the question if the answer already exists.
loop: (Boolean) Enable list looping. Defaults: true
waitUserInput: (Boolean) Flag to enable/disable wait for user input before opening system editor - Defaults: true
}
const list = {}
const cofirm
const confirm
export const returnToMain = {
type: "confirm",
Expand All @@ -33,4 +36,4 @@ export const intro = {
choices: choices,
}

*/
2 changes: 1 addition & 1 deletion src/common/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ export function pubToAddress (publicKey: string): string {
}

export const formatAmountAsHex = (amount) => {
return `${PREFIX}${(amount * (1 * (10 ** DECIMALS))).toString(16)}`;
return `${PREFIX}${(amount * (1 * (10 ** DECIMALS))).toString(16)}`;
}

export function getActiveOptions (options) {
Expand Down
28 changes: 14 additions & 14 deletions src/config/migrations/00.ts
Original file line number Diff line number Diff line change
@@ -1,19 +1,19 @@
export const version = '0'

export function migrate (data= {}) {
try {
const migratedData = {
...data,
accounts: [],
endpoints: {
dev: 'ws://127.0.0.1:9944',
'test-net': 'ws://testnet.entropy.xyz:9944/'
},
'migration-version': version,
}
return migratedData
} catch (e) {
console.error(`error in migration ${version}: e.message`)
try {
const migratedData = {
...data,
accounts: [],
endpoints: {
dev: 'ws://127.0.0.1:9944',
'test-net': 'ws://testnet.entropy.xyz:9944/'
},
'migration-version': version,
}
return migratedData
} catch (e) {
console.error(`error in migration ${version}: e.message`)
}
return data
}
}
9 changes: 5 additions & 4 deletions src/flows/UserPrograms/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -35,13 +35,13 @@ export async function userPrograms ({ accounts, endpoints }, options) {
endpoint
)

if (!entropy.account?.sigRequestKey) {
if (!entropy.registrationManager?.signer?.pair) {
throw new Error("Keys are undefined")
}

switch (actionChoice.action) {
case "View My Programs": {
const programs = await entropy.programs.get(entropy.account.sigRequestKey.wallet.address)
const programs = await entropy.programs.get(entropy.keyring.accounts.registration.address)
if (programs.length === 0) {
console.log("You currently have no programs set.")
} else {
Expand Down Expand Up @@ -90,7 +90,7 @@ export async function userPrograms ({ accounts, endpoints }, options) {
programPointer: programPointerToAdd,
programConfig: programConfigHex,
},
entropy.account.sigRequestKey.wallet.address
entropy.keyring.accounts.registration.address,
)

console.log("Program added successfully.")
Expand All @@ -106,7 +106,8 @@ export async function userPrograms ({ accounts, endpoints }, options) {
])
await entropy.programs.remove(
programPointerToRemove,
entropy.account.sigRequestKey.wallet.address
entropy.keyring.accounts.registration.address,
entropy.keyring.accounts.registration.verifyingKeys[0]
)
console.log("Program removed successfully.")
break
Expand Down
4 changes: 2 additions & 2 deletions src/flows/entropyFaucet/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ export async function entropyFaucet ({ accounts, endpoints }, options) {

const entropy = await initializeEntropy(aliceData, endpoint)

if (!entropy.account?.sigRequestKey?.pair) {
if (!entropy.registrationManager.signer.pair) {
throw new Error("Keys are undefined")
}

Expand All @@ -37,7 +37,7 @@ export async function entropyFaucet ({ accounts, endpoints }, options) {
)

await tx.signAndSend(
entropy.account.sigRequestKey.wallet,
entropy.registrationManager.signer.pair,
async ({ status }) => {
if (status.isInBlock || status.isFinalized) {
console.log(recipientAddress, "funded")
Expand Down
2 changes: 1 addition & 1 deletion src/flows/entropyTransfer/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ export async function entropyTransfer ({ accounts, endpoints }, options) {
await tx.signAndSend (entropy.registrationManager.signer.pair, ({ status }) => {
// initialize the bar - defining payload token "speed" with the default value "N/A"
b1.start(500, 0, {
speed: "N/A"
speed: "N/A"
});
// update values
const interval = setInterval(() => {
Expand Down
13 changes: 6 additions & 7 deletions src/flows/ethTransaction/index.ts
Original file line number Diff line number Diff line change
@@ -1,12 +1,11 @@
import inquirer from "inquirer"
import { exec } from 'child_process'
import util from 'util'
import { accountChoices, pubToAddress } from "../../common/utils"
import { initializeEntropy } from "../../common/initializeEntropy"
import { ethers } from "ethers"
import { Hex, createPublicClient } from 'viem'
import { http, Hex, createPublicClient } from 'viem'
import { sepolia } from 'viem/chains'
import { http } from "viem"
import { accountChoices, pubToAddress } from "../../common/utils"
import { initializeEntropy } from "../../common/initializeEntropy"

const execAsync = util.promisify(exec)

Expand Down Expand Up @@ -81,7 +80,7 @@ export async function ethTransaction ({ accounts, endpoints }, options): Promise

await entropy.ready

const address = entropy.account?.sigRequestKey?.wallet.address
const { address } = entropy.keyring.accounts.registration
if (address === undefined) {
throw new Error("Address issue")
}
Expand Down Expand Up @@ -118,7 +117,7 @@ export async function ethTransaction ({ accounts, endpoints }, options): Promise
}


const entropySig = await entropy.signTransaction({ txParams: basicTx, type: 'eth' }) as string
const entropySig = await entropy.signWithAdapter({ msg: basicTx, type: 'eth' }) as string
const addy = await getSenderAddressFromSignedTx(entropySig)
console.log({ addy })

Expand Down Expand Up @@ -251,4 +250,4 @@ export async function ethTransaction ({ accounts, endpoints }, options): Promise

// await sendCurlCommand(entropySig, infuraEndpoint)

// }
// }
4 changes: 2 additions & 2 deletions src/flows/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,6 @@ export { userPrograms } from './UserPrograms'
export { devPrograms } from './DeployPrograms'
export { sign } from './sign'
export { entropyTransfer } from './entropyTransfer'
export { ethTransaction } from './ethTransaction'
// export { ethTransaction } from './ethTransaction'
export { giveZaps } from './zaps'
export { wallet } from './wallet'
export { wallet } from './wallet'
8 changes: 3 additions & 5 deletions src/flows/register/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ export async function register ({ accounts, endpoints }, options) {
programModAccount = programModAccountAnswer.programModAccount.address
}

const isRegistered = await entropy.registrationManager.checkRegistrationStatus(selectedAccount.address)
const isRegistered = await entropy.isRegistered(selectedAccount.address)

console.log("isRegistered", isRegistered)

Expand All @@ -70,10 +70,8 @@ export async function register ({ accounts, endpoints }, options) {

console.log("Attempting to register the address:", selectedAccount.address)
await entropy.register({
programModAccount: programModAccount,
keyVisibility: "Permissioned",
initialPrograms: [programData],
freeTx: false,
programData: [programData],
programDeployer: programModAccount,
})

console.log("Your address", selectedAccount.data.address, "has been successfully registered.")
Expand Down
12 changes: 7 additions & 5 deletions src/flows/sign/index.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
import { initializeEntropy } from "../../common/initializeEntropy"
import { accountChoices } from "../../common/utils"
import inquirer from "inquirer"
import { ethers } from "ethers"
import { initializeEntropy } from "../../common/initializeEntropy"
import { accountChoices } from "../../common/utils"

// TODO revisit this file, rename as signEthTransaction?
export async function sign ({ accounts, endpoints }, options) {
const endpoint = endpoints[options.ENDPOINT]

Expand All @@ -24,7 +25,7 @@ export async function sign ({ accounts, endpoints }, options) {

await entropy.ready

const address = entropy.account?.sigRequestKey?.wallet.address
const { address } = entropy.keyring.accounts.registration
console.log({ address })
if (address == undefined) {
throw new Error("address issue")
Expand Down Expand Up @@ -63,6 +64,7 @@ export async function sign ({ accounts, endpoints }, options) {
},
])

// TODO: this is assuming signing an eth Tx, should remove?
const basicTx = {
to: txDetails.to,
value: ethers.utils.parseEther(txDetails.value).toHexString(),
Expand All @@ -71,8 +73,8 @@ export async function sign ({ accounts, endpoints }, options) {
data: "0x" + Buffer.from(`${txDetails.data}`).toString("hex"),
}

const signature = (await entropy.signTransaction({
txParams: basicTx,
const signature = (await entropy.signWithAdapter({
msg: basicTx,
type: "eth",
})) as string

Expand Down
1 change: 1 addition & 0 deletions src/flows/wallet/new-key.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import inquirer from 'inquirer'
import { randomAsHex } from '@polkadot/util-crypto'
// @ts-ignore
import Keyring from '@entropyxyz/sdk/keys'
import { importQuestions } from './import-key'
import * as passwordFlow from '../password'
Expand Down
Loading

0 comments on commit 9920537

Please sign in to comment.