From 69eb234881221d8a47f929142d2b8977e166a7e7 Mon Sep 17 00:00:00 2001 From: PeterWallet Date: Thu, 14 Nov 2024 19:54:32 +0900 Subject: [PATCH] init --- .github/CODEOWNERS | 1 + .github/workflows/deploy-npm.yaml | 40 + .gitignore | 44 + .npmignore | 6 + README.md | 144 + dist/command/abstract-trade.command.js | 109 + dist/command/buy.command.js | 70 + dist/command/command-action.js | 2 + dist/command/config-get.command.js | 25 + dist/command/config-set.command.js | 29 + dist/command/config.command.js | 50 + dist/command/list.command.js | 55 + dist/command/sell.command.js | 69 + dist/command/trade.options.js | 25 + dist/config.js | 119 + dist/contant.js | 35 + dist/index.js | 50 + dist/program.js | 76 + dist/prompt.js | 145 + dist/types.js | 8 + dist/util.js | 68 + dist/validator.js | 101 + package.json | 124 + yarn.lock | 4782 ++++++++++++++++++++++++ 24 files changed, 6177 insertions(+) create mode 100644 .github/CODEOWNERS create mode 100644 .github/workflows/deploy-npm.yaml create mode 100644 .gitignore create mode 100644 .npmignore create mode 100644 README.md create mode 100644 dist/command/abstract-trade.command.js create mode 100644 dist/command/buy.command.js create mode 100644 dist/command/command-action.js create mode 100644 dist/command/config-get.command.js create mode 100644 dist/command/config-set.command.js create mode 100644 dist/command/config.command.js create mode 100644 dist/command/list.command.js create mode 100644 dist/command/sell.command.js create mode 100644 dist/command/trade.options.js create mode 100644 dist/config.js create mode 100644 dist/contant.js create mode 100644 dist/index.js create mode 100644 dist/program.js create mode 100644 dist/prompt.js create mode 100644 dist/types.js create mode 100644 dist/util.js create mode 100644 dist/validator.js create mode 100644 package.json create mode 100644 yarn.lock diff --git a/.github/CODEOWNERS b/.github/CODEOWNERS new file mode 100644 index 0000000..0063963 --- /dev/null +++ b/.github/CODEOWNERS @@ -0,0 +1 @@ +@dexlab-project/core diff --git a/.github/workflows/deploy-npm.yaml b/.github/workflows/deploy-npm.yaml new file mode 100644 index 0000000..f472237 --- /dev/null +++ b/.github/workflows/deploy-npm.yaml @@ -0,0 +1,40 @@ +name: Deploy to npmjs + +on: + release: + types: [ created ] + +jobs: + publish: + runs-on: ${{ fromJson(vars.RUNNER) }} + steps: + - name: Checkout code + uses: actions/checkout@v4 + + - name: Get branch name + id: get_branch + run: echo "branch_name=$(git branch -r --contains ${{ github.event.release.tag_name }} | grep -o 'origin/.*' | sed 's|origin/||')" >> $GITHUB_ENV + + - name: Display branch name + run: | + echo "Release created on branch: ${{ env.branch_name }}" + + - name: Setup Node.js + uses: actions/setup-node@v4 + with: + node-version: '18' + cache: 'yarn' + registry-url: https://registry.npmjs.org/ + + - name: tarball + run: yarn pack + + - name: Find tarball + id: find_tarball + run: echo "TARBALL=$(ls *.tgz)" >> $GITHUB_ENV + + - name: publish + env: + NODE_AUTH_TOKEN: ${{ secrets.NPM_PACKAGES_TOKEN }} + run: yarn publish ${{ env.TARBALL }} --access public + diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..a98e0a0 --- /dev/null +++ b/.gitignore @@ -0,0 +1,44 @@ +# compiled output +**/release/ + +node_modules + +# Logs +logs +*.log +npm-debug.log* +pnpm-debug.log* +yarn-debug.log* +yarn-error.log* +lerna-debug.log* + +*.tsbuildinfo + +# OS +.DS_Store + +# Tests +coverage +.nyc_output + +# IDEs and editors +.idea +.project +.classpath +.c9/ +*.launch +.settings/ +*.sublime-workspace + +# IDE - VSCode +.vscode/* +!.vscode/settings.json +!.vscode/tasks.json +!.vscode/launch.json +!.vscode/extensions.json + +*.env +*.env.* + +.npmrc +.yarnrc diff --git a/.npmignore b/.npmignore new file mode 100644 index 0000000..ed6ad69 --- /dev/null +++ b/.npmignore @@ -0,0 +1,6 @@ +/src +/.idea +/node_modules +.npmrc +.env +.* diff --git a/README.md b/README.md new file mode 100644 index 0000000..0374913 --- /dev/null +++ b/README.md @@ -0,0 +1,144 @@ + +# Mome CLI + +With the CLI, you can conveniently and quickly conduct transactions on the MOME Launchpad without accessing the MOME web interface. + +## Setup + +### Prerequisites + +- Node.js >= 18.x +- Solana + +### Installation + +```zsh +$ npm i -g @dexlab-project/mome-cli +``` + +## Config + +Use the `config` command to view the current user settings. If it’s the first time running the CLI, you will be prompted to enter information to set up the RPC and wallet. Once completed, the current configuration details will be displayed. + +If this setup step is skipped, a prompt will appear for the configuration details when executing the buy/sell commands. + +```zsh +$ mome config +✔ Enter wallet path: +? Enter RPC URL: +{ + "walletPath": "", + "rpcUrl": "", + "slippage": 1500, + "waitForConfirmation": true +} +``` + +## Usage + +### buy / sell + +#### Interactive Mode + +Entering only the `mome` command launches interactive mode, allowing you to select either the buy or sell command. After selecting a command, enter the token and quantity to proceed with the transaction. + +```zsh +$ mome +? Choose a command: (Use arrow keys) +> buy + sell + list + exit +``` + +#### Command Line Mode + +You can initiate a transaction directly with the `buy` or `sell` command. If any required transaction details are missing, you will be prompted to enter them. + +```zsh +$ mome buy +``` + +#### Arguments + +- **token address**: The address of the token you want to trade. +- **amount**: The quantity of tokens to trade. + - When using the sell command, you can enter the exact amount or a percentage (%) of your holdings. + - For example, entering `10000` will sell 10,000 tokens, while `10%` will sell 10% of your tokens. If you hold 10,000 tokens, 1,000 will be sold. + - Percentage-based sales support up to two decimal places, with the third decimal truncated. + +#### Options + +| Parameter | Default | Description | +|----------------------------------|---------|---------------------------------------------------------------------------------------------------| +| `-y`, `--yes` | false | Skips the final confirmation before proceeding with the transaction. If not set, a summary will display, and confirmation will be required. | +| `-s `, `--slippage ` | 1500 | Sets the slippage tolerance in basis points. For example, `1500` represents a 1.5% slippage. | +| `--use-compute-unit [preset]` | N/A | Specifies the compute unit for transaction processing, using predefined presets. | +| `--use-jito-boost [lamports]` | false | Enables Jito Boost with a default of 0.001 SOL if no lamport amount is specified. | + +##### Compute Unit Preset + +The `--use-compute-unit` option allows you to specify the compute unit for transaction processing. Available presets are: + +| Preset | computeUnitPrice | computeUnitLimit | +|----------|------------------|------------------| +| `default` | 0 | 200,000 | +| `low` | 1000 | 500,000 | +| `medium` | 2000 | 1,000,000 | +| `high` | 3000 | 1,500,000 | +| `ultra` | 4000 | 2,000,000 | + +### Config + +Use the `config` command to view or change the current settings. + +#### View Settings + +Use `mome config` or `mome config get`. + +```zsh +$ mome config get +{ + "walletPath": "/.config/solana/id.json", + "rpcUrl": "https://", + "slippage": 1500, + "waitForConfirmation": true +} +``` + +#### Modify Settings + +To change a setting, use `mome config set `. + +```zsh +$ mome config set +``` + +Available settings: + +| Parameter | Type | Default | Description | +|------------------------|-----------|---------|-------------------------------------------------------------------------------------------------------| +| `walletPath` | `string` | null | Path to the wallet used for transactions. Enter the location of the JSON file created by solana-keygen or another method. | +| `rpcUrl` | `string` | null | RPC URL to use for transactions. | +| `slippage` | `number` | 1500 | Slippage tolerance in basis points. For example, `1500` represents a 1.5% slippage. Range is 0–10000.| +| `waitForConfirmation` | `boolean` | true | Waits until the transaction reaches confirmed status. Set to false to exit the program after sending. | + +### List + +Use `mome list