-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
0 parents
commit 69eb234
Showing
24 changed files
with
6,177 additions
and
0 deletions.
There are no files selected for viewing
Validating CODEOWNERS rules …
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 @@ | ||
@dexlab-project/core |
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 @@ | ||
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 | ||
|
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,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 |
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 @@ | ||
/src | ||
/.idea | ||
/node_modules | ||
.npmrc | ||
.env | ||
.* |
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,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": "<YOUR SOLANA CLI WALLET PATH>", | ||
"rpcUrl": "<YOUR RPC URL>", | ||
"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 <token-address> <amount> <options> | ||
``` | ||
|
||
#### 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 <bps>`, `--slippage <bps>` | 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": "<path>/.config/solana/id.json", | ||
"rpcUrl": "https://<RPC_URL>", | ||
"slippage": 1500, | ||
"waitForConfirmation": true | ||
} | ||
``` | ||
|
||
#### Modify Settings | ||
|
||
To change a setting, use `mome config set <key> <value>`. | ||
|
||
```zsh | ||
$ mome config set <key> <value> | ||
``` | ||
|
||
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 <option>` to view the list of available tokens for purchase. | ||
|
||
```zsh | ||
$ mome list | ||
? Choose a token to trade: | ||
MOME CrMCv6oAr2HbTTiUQ3of8eCBgBMUdaS34JSyaYkvD3wz 2024-10-28 11:27:49 🟢Active | ||
$olPEPE HQSK7jGo5J4UwTyQa4qfvxTvkZXFEfpJNDqan5uYAp82 2024-10-28 11:26:18 🚀Migrated | ||
test4 AnhMP8ndNRZE6T64UGubCJBX5QAokvdCoKVAWK7bU8g3 2024-11-01 09:50:42 🟢Active | ||
test3 4R1XngXUGUxzHNBLxXuA5EKn7yubvAB5vGfLfHJdd1qg 2024-11-01 09:46:11 🟢Active | ||
❯ Next >> | ||
``` | ||
|
||
Selecting a token launches the purchase prompt, where you can immediately enter the price to buy. Use `Next >>` to navigate between pages. Adjust sorting by `--sort <sortOption>`, with available options `createdAt` (default), `lastCommentedAt`, and `marketCap`, sorted in descending order. | ||
|
||
### Help | ||
|
||
Use the `mome help` command to view help information. For specific command details, use `mome help <command>`. |
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,109 @@ | ||
"use strict"; | ||
var __importDefault = (this && this.__importDefault) || function (mod) { | ||
return (mod && mod.__esModule) ? mod : { "default": mod }; | ||
}; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports.AbstractTradeCommand = void 0; | ||
const mome_sdk_1 = require("@dexlab-project/mome-sdk"); | ||
const util_1 = require("../util"); | ||
const validator_1 = require("../validator"); | ||
const cli_spinner_1 = require("cli-spinner"); | ||
const prompt_1 = require("../prompt"); | ||
const chalk_1 = __importDefault(require("chalk")); | ||
const contant_1 = require("../contant"); | ||
class AbstractTradeCommand { | ||
constructor(config) { | ||
this.config = config; | ||
} | ||
buildTransaction(builder, option) { | ||
let txBuilder = builder; | ||
if (option?.useJitoBoost) { | ||
if ((0, validator_1.isBoolean)(option.useJitoBoost)) { | ||
txBuilder = txBuilder.setBundle({ | ||
lamports: contant_1.DEFAULT_USE_JITO_BOOST, | ||
}); | ||
} | ||
else { | ||
txBuilder = txBuilder.setBundle({ | ||
lamports: option.useJitoBoost, | ||
}); | ||
} | ||
} | ||
if (option?.useComputeUnit !== undefined && option?.useComputeUnit !== null) { | ||
const computeUnit = (0, util_1.convertComputeUnitPresetToValue)((0, validator_1.isBoolean)(option.useComputeUnit) ? 'default' : option.useComputeUnit); | ||
txBuilder = txBuilder.setComputeUnit(computeUnit); | ||
} | ||
return txBuilder; | ||
} | ||
async finalizeTransaction(mome, tx) { | ||
const userConfig = this.config.getConfig(); | ||
if (userConfig.waitForConfirmation ?? true) { | ||
const spinner = new cli_spinner_1.Spinner(`%s Waiting for confirmation ${tx.signature}`); | ||
spinner.setSpinnerString(29); | ||
spinner.setSpinnerDelay(80); | ||
spinner.start(); | ||
await mome.waitForConfirmation(tx.signature, tx.transactionBlockhash); | ||
spinner.stop(); | ||
console.log(`\nTransaction confirmed!`); | ||
} | ||
else { | ||
console.log(`Transaction send signature: ${tx.signature}`); | ||
} | ||
} | ||
async requireTradeInputs(mome, tradeType, option, tokenAddressArg, amountArg) { | ||
let tokenAddress; | ||
if (tokenAddressArg) { | ||
tokenAddress = tokenAddressArg; | ||
} | ||
else { | ||
tokenAddress = await (0, prompt_1.promptInputTokenAddress)(); | ||
} | ||
let token; | ||
try { | ||
token = mome.getToken(tokenAddress); | ||
} | ||
catch (e) { | ||
throw new Error(`Invalid token address ${tokenAddress}`); | ||
} | ||
const tokenInfo = await token.getInfo(); | ||
const balance = tradeType === 'buy' ? await mome.getLamports() : await mome.getTokenBalance(tokenAddress); | ||
let userInputAmount; | ||
const validator = tradeType === 'buy' ? validator_1.amountValidator : validator_1.percentAmountValidator; | ||
if (amountArg) { | ||
const validated = validator(amountArg); | ||
if (validated === true) { | ||
userInputAmount = (0, validator_1.parseAmountInput)(amountArg); | ||
} | ||
else { | ||
const extraMessage = chalk_1.default.red(`You entered an invalid amount (${amountArg}).\n`); | ||
userInputAmount = await (0, prompt_1.promptInputAmount)(tradeType, tokenInfo, balance, extraMessage); | ||
} | ||
} | ||
else { | ||
userInputAmount = await (0, prompt_1.promptInputAmount)(tradeType, tokenInfo, balance); | ||
} | ||
const amount = userInputAmount.type === 'percent' | ||
? (0, mome_sdk_1.toUiVolume)((balance * BigInt(Math.floor(userInputAmount.value * 100)) / 100n) / 100n, tokenInfo.decimals).toNumber() | ||
: userInputAmount.value; | ||
if (!option.yes) { | ||
const confirm = await (0, prompt_1.promptConfirm)({ | ||
tokenAddress, | ||
symbol: tokenInfo.symbol, | ||
action: tradeType, | ||
amount: amount, | ||
slippageBps: option.slippageBps ?? contant_1.DEFAULT_SLIPPAGE_BPS, | ||
useJitoBoost: option.useJitoBoost, | ||
useComputeUnit: option.useComputeUnit, | ||
}); | ||
if (!confirm) { | ||
return; | ||
} | ||
} | ||
return { | ||
tokenAddress, | ||
amount: amount, | ||
slippageBps: option.slippageBps ?? contant_1.DEFAULT_SLIPPAGE_BPS, | ||
}; | ||
} | ||
} | ||
exports.AbstractTradeCommand = AbstractTradeCommand; |
Oops, something went wrong.