-
Notifications
You must be signed in to change notification settings - Fork 11
feat(cli): add exchange-rates, crypto, discoveries, uma-providers, tokens, and internal-account update/export #705
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Closed
Closed
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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 hidden or 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 hidden or 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,62 @@ | ||
| import { Command } from "commander"; | ||
| import { GridClient } from "../client"; | ||
| import { outputResponse, formatError, output } from "../output"; | ||
| import { GlobalOptions } from "../index"; | ||
|
|
||
| interface EstimateCryptoWithdrawalFeeResponse { | ||
| networkFee: number; | ||
| networkFeeAsset: string; | ||
| applicationFee: number; | ||
| totalFee: number; | ||
| netAmount: number; | ||
| } | ||
|
|
||
| export function registerCryptoCommand( | ||
| program: Command, | ||
| getClient: (opts: GlobalOptions) => GridClient | null | ||
| ): void { | ||
| const cryptoCmd = program | ||
| .command("crypto") | ||
| .description("Crypto helper commands"); | ||
|
|
||
| cryptoCmd | ||
| .command("estimate-fee") | ||
| .description("Estimate the fee for a crypto withdrawal") | ||
| .requiredOption("--internal-account-id <id>", "Source internal account ID") | ||
| .requiredOption("--currency <code>", "Currency code (e.g. USDC)") | ||
| .requiredOption("--crypto-network <network>", "Crypto network (e.g. SOLANA)") | ||
| .requiredOption("--amount <number>", "Amount in the smallest unit") | ||
| .requiredOption("--destination-address <address>", "Destination address") | ||
| .action(async (options) => { | ||
| const opts = program.opts<GlobalOptions>(); | ||
| const client = getClient(opts); | ||
| if (!client) return; | ||
|
|
||
| // A crypto amount must be a positive integer in the smallest unit; | ||
| // reject trailing garbage (e.g. "10foo") and out-of-range values that | ||
| // parseInt would otherwise accept or truncate. | ||
| if (!/^\d+$/.test(options.amount)) { | ||
| output(formatError("--amount must be a positive integer")); | ||
| process.exitCode = 1; | ||
| return; | ||
| } | ||
| const amount = Number(options.amount); | ||
| if (!Number.isSafeInteger(amount) || amount < 1) { | ||
| output(formatError("--amount is out of range")); | ||
| process.exitCode = 1; | ||
| return; | ||
| } | ||
|
|
||
| const response = await client.post<EstimateCryptoWithdrawalFeeResponse>( | ||
| "/crypto/estimate-withdrawal-fee", | ||
| { | ||
| internalAccountId: options.internalAccountId, | ||
| currency: options.currency, | ||
| cryptoNetwork: options.cryptoNetwork, | ||
| amount, | ||
| destinationAddress: options.destinationAddress, | ||
| } | ||
| ); | ||
| outputResponse(response); | ||
| }); | ||
| } |
This file contains hidden or 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,33 @@ | ||
| import { Command } from "commander"; | ||
| import { GridClient } from "../client"; | ||
| import { outputResponse } from "../output"; | ||
| import { GlobalOptions } from "../index"; | ||
|
|
||
| interface Discovery { | ||
| bankName: string; | ||
| displayName: string; | ||
| country: string; | ||
| currency: string; | ||
| } | ||
|
|
||
| export function registerDiscoveriesCommand( | ||
| program: Command, | ||
| getClient: (opts: GlobalOptions) => GridClient | null | ||
| ): void { | ||
| program | ||
| .command("discoveries") | ||
| .description("List available receiving institutions") | ||
| .option("--country <code>", "Filter by country (ISO 3166-1 alpha-2)") | ||
| .option("--currency <code>", "Filter by currency (ISO 4217)") | ||
| .action(async (options) => { | ||
| const opts = program.opts<GlobalOptions>(); | ||
| const client = getClient(opts); | ||
| if (!client) return; | ||
|
|
||
| const response = await client.get<{ data: Discovery[] }>("/discoveries", { | ||
| country: options.country, | ||
| currency: options.currency, | ||
| }); | ||
| outputResponse(response); | ||
| }); | ||
| } |
This file contains hidden or 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,66 @@ | ||
| import { Command } from "commander"; | ||
| import { GridClient } from "../client"; | ||
| import { outputResponse, formatError, output } from "../output"; | ||
| import { GlobalOptions } from "../index"; | ||
|
|
||
| interface Currency { | ||
| code: string; | ||
| name?: string; | ||
| symbol?: string; | ||
| decimals?: number; | ||
| } | ||
|
|
||
| interface ExchangeRate { | ||
| sourceCurrency: Currency; | ||
| sendingAmount: number; | ||
| destinationCurrency: Currency; | ||
| destinationPaymentRail: string; | ||
| receivingAmount: number; | ||
| exchangeRate: number; | ||
| updatedAt: string; | ||
| } | ||
|
|
||
| function collect(value: string, previous: string[] = []): string[] { | ||
| return [...previous, value]; | ||
| } | ||
|
|
||
| export function registerExchangeRatesCommand( | ||
| program: Command, | ||
| getClient: (opts: GlobalOptions) => GridClient | null | ||
| ): void { | ||
| program | ||
| .command("exchange-rates") | ||
| .description("Get exchange rates") | ||
| .option("--source-currency <code>", "Source currency code") | ||
| .option( | ||
| "--destination-currency <code>", | ||
| "Destination currency code (repeatable)", | ||
| collect | ||
| ) | ||
| .option("--sending-amount <number>", "Sending amount in the smallest unit") | ||
| .action(async (options) => { | ||
| const opts = program.opts<GlobalOptions>(); | ||
| const client = getClient(opts); | ||
| if (!client) return; | ||
|
|
||
| let sendingAmount: number | undefined; | ||
| if (options.sendingAmount !== undefined) { | ||
| sendingAmount = parseInt(options.sendingAmount, 10); | ||
| if (Number.isNaN(sendingAmount)) { | ||
| output(formatError("--sending-amount must be a number")); | ||
| process.exitCode = 1; | ||
| return; | ||
| } | ||
| } | ||
|
|
||
| const response = await client.get<{ data: ExchangeRate[] }>( | ||
| "/exchange-rates", | ||
| { | ||
| sourceCurrency: options.sourceCurrency, | ||
| destinationCurrency: options.destinationCurrency, | ||
| sendingAmount, | ||
| } | ||
| ); | ||
| outputResponse(response); | ||
| }); | ||
| } | ||
This file contains hidden or 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,66 @@ | ||
| import { Command } from "commander"; | ||
| import { GridClient } from "../client"; | ||
| import { outputResponse, formatError, output } from "../output"; | ||
| import { GlobalOptions } from "../index"; | ||
| import { addSignedOptions, signedHeaders } from "../signed"; | ||
|
|
||
| export function registerInternalAccountsCommand( | ||
| program: Command, | ||
| getClient: (opts: GlobalOptions) => GridClient | null | ||
| ): void { | ||
| const internalAccountsCmd = program | ||
| .command("internal-accounts") | ||
| .description("Internal account update/export commands"); | ||
|
|
||
| addSignedOptions( | ||
| internalAccountsCmd | ||
| .command("update <internalAccountId>") | ||
| .description("Update an internal account") | ||
| .option("--private-enabled <true|false>", "Enable/disable Embedded Wallet privacy") | ||
| ).action(async (internalAccountId: string, options) => { | ||
| const opts = program.opts<GlobalOptions>(); | ||
| const client = getClient(opts); | ||
| if (!client) return; | ||
|
|
||
| if (options.privateEnabled === undefined) { | ||
| output(formatError("Provide --private-enabled <true|false>")); | ||
| process.exitCode = 1; | ||
| return; | ||
| } | ||
| if (options.privateEnabled !== "true" && options.privateEnabled !== "false") { | ||
| output(formatError("--private-enabled must be true or false")); | ||
| process.exitCode = 1; | ||
| return; | ||
| } | ||
|
|
||
| const response = await client.patch( | ||
| `/internal-accounts/${internalAccountId}`, | ||
| { privateEnabled: options.privateEnabled === "true" }, | ||
| signedHeaders(options) | ||
| ); | ||
| outputResponse(response); | ||
| }); | ||
|
|
||
| addSignedOptions( | ||
| internalAccountsCmd | ||
| .command("export <internalAccountId>") | ||
| .description( | ||
| "Export an internal account's wallet credentials — returns an HPKE-sealed ciphertext you decrypt client-side with the matching private key" | ||
| ) | ||
| .requiredOption( | ||
| "--client-public-key <hex>", | ||
| "Ephemeral client P-256 public key (uncompressed SEC1 hex); discard the private key after decrypting" | ||
| ) | ||
| ).action(async (internalAccountId: string, options) => { | ||
| const opts = program.opts<GlobalOptions>(); | ||
| const client = getClient(opts); | ||
| if (!client) return; | ||
|
|
||
| const response = await client.post( | ||
| `/internal-accounts/${internalAccountId}/export`, | ||
| { clientPublicKey: options.clientPublicKey }, | ||
| signedHeaders(options) | ||
| ); | ||
| outputResponse(response); | ||
| }); | ||
| } |
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
parseIntsilently truncates non-integer inputsparseInt("10.5", 10)returns10andparseInt("-50", 10)returns-50— both are accepted without any error, even though the help text says "Sending amount in the smallest unit" (implying a positive integer). The result is that a user passing--sending-amount 10.5gets rate quotes for10instead of an error, and a negative amount is forwarded to the API. Thecrypto estimate-feecommand in the same PR guards against exactly this with a/^\d+$/regex plus anamount >= 1check — the same approach should be used here for consistency and correctness.Prompt To Fix With AI