-
Notifications
You must be signed in to change notification settings - Fork 8
Release/0.11.6 #12
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
Release/0.11.6 #12
Changes from all commits
5dda14d
23a1fe3
46b11ff
e099a3d
234d095
701ecd6
b3444a1
09e40dc
9e32a72
b04767e
592f0e6
10e122d
a0ecd76
0c2acea
fbad3c4
ab8236a
6e88efc
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,33 @@ | ||
| import { Config as BlockchainConfig } from '@super-protocol/sdk-js'; | ||
| import addValueOfferVersion from '../services/addValueOfferVersion'; | ||
| import Printer from '../printer'; | ||
| import readOfferVersionInfo from '../services/readOfferVersionInfo'; | ||
| import initBlockchainConnector from '../services/initBlockchainConnector'; | ||
|
|
||
| export type OfferAddVersionParams = { | ||
| actionAccountKey: string; | ||
| blockchainConfig: BlockchainConfig; | ||
| id: string; | ||
| ver: number; | ||
| path: string; | ||
| }; | ||
|
|
||
| export default async (params: OfferAddVersionParams): Promise<void> => { | ||
| try { | ||
| Printer.print('Connecting to the blockchain'); | ||
| await initBlockchainConnector({ | ||
| blockchainConfig: params.blockchainConfig, | ||
| actionAccountKey: params.actionAccountKey, | ||
| }); | ||
| const versionInfo = await readOfferVersionInfo({ path: params.path }); | ||
| const newVersion = await addValueOfferVersion({ | ||
| action: params.actionAccountKey, | ||
| version: params.ver, | ||
| versionInfo, | ||
| offerId: params.id, | ||
| }); | ||
| Printer.print(`Version ${newVersion} added successfully`); | ||
| } catch (error: any) { | ||
| Printer.print('Version add failed with error: ' + error?.message); | ||
| } | ||
| }; | ||
| Original file line number | Diff line number | Diff line change | ||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| @@ -0,0 +1,25 @@ | ||||||||||||||||
| import { Offer, Config as BlockchainConfig } from '@super-protocol/sdk-js'; | ||||||||||||||||
| import Printer from '../printer'; | ||||||||||||||||
| import initBlockchainConnector from '../services/initBlockchainConnector'; | ||||||||||||||||
|
|
||||||||||||||||
| export type OffersDisableVersionParams = { | ||||||||||||||||
| blockchainConfig: BlockchainConfig; | ||||||||||||||||
| actionAccountKey: string; | ||||||||||||||||
| id: string; | ||||||||||||||||
| ver: number; | ||||||||||||||||
| }; | ||||||||||||||||
|
Comment on lines
+5
to
+10
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 🛠️ Refactor suggestion Input contract lacks basic sanity checks
🤖 Prompt for AI Agents |
||||||||||||||||
|
|
||||||||||||||||
| export default async (params: OffersDisableVersionParams): Promise<void> => { | ||||||||||||||||
| try { | ||||||||||||||||
| Printer.print('Connecting to the blockchain'); | ||||||||||||||||
| const actionAddress = await initBlockchainConnector({ | ||||||||||||||||
| blockchainConfig: params.blockchainConfig, | ||||||||||||||||
| actionAccountKey: params.actionAccountKey, | ||||||||||||||||
| }); | ||||||||||||||||
| const offer = new Offer(params.id); | ||||||||||||||||
| await offer.deleteVersion(params.ver, { from: actionAddress }); | ||||||||||||||||
| Printer.print(`Version ${params.ver} for offer ${params.id} successfully removed`); | ||||||||||||||||
| } catch (error: any) { | ||||||||||||||||
| Printer.print('Remove offer version failed with error: ' + error?.message); | ||||||||||||||||
| } | ||||||||||||||||
|
Comment on lines
+22
to
+24
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Swallowed error obstructs CLI exit status The catch block only logs the error. The CLI that invokes this command will interpret a resolved promise as success, masking failures (e.g., CI/CD scripts will think the version was removed). - } catch (error: any) {
- Printer.print('Remove offer version failed with error: ' + error?.message);
+ } catch (error: unknown) {
+ Printer.print(`Remove offer version failed: ${(error as Error).message}`);
+ throw error; // let the upper layer decide how to handle/exit
}📝 Committable suggestion
Suggested change
🤖 Prompt for AI Agents |
||||||||||||||||
| }; | ||||||||||||||||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,73 @@ | ||
| import { Config as BlockchainConfig, Orders, OrderStatus } from '@super-protocol/sdk-js'; | ||
| import inquirer, { QuestionCollection } from 'inquirer'; | ||
| import Printer from '../printer'; | ||
| import initBlockchainConnectorService from '../services/initBlockchainConnector'; | ||
| import checkOrderService from '../services/checkOrder'; | ||
| import { etherToWei, weiToEther } from '../utils'; | ||
|
|
||
| export type WorkflowReplenishDepositParams = { | ||
| blockchainConfig: BlockchainConfig; | ||
| actionAccountKey: string; | ||
| minutes: number; | ||
| sppi: string; | ||
| orderId: string; | ||
| yes: boolean; | ||
| }; | ||
|
|
||
| const isActionConfirmed = async (question: string): Promise<boolean> => { | ||
| Printer.print(question); | ||
|
|
||
| const questions: QuestionCollection = [ | ||
| { | ||
| type: 'confirm', | ||
| name: 'confirmation', | ||
| message: `Confirm?`, | ||
| default: true, | ||
| }, | ||
| ]; | ||
| const answers = await inquirer.prompt(questions); | ||
|
|
||
| return answers.confirmation; | ||
| }; | ||
|
|
||
| export default async (params: WorkflowReplenishDepositParams): Promise<void> => { | ||
| Printer.print('Connecting to the blockchain'); | ||
| await initBlockchainConnectorService({ | ||
| blockchainConfig: params.blockchainConfig, | ||
| actionAccountKey: params.actionAccountKey, | ||
| }); | ||
|
|
||
| try { | ||
| Printer.print(`Checking order ${params.orderId}`); | ||
| await checkOrderService({ | ||
| id: params.orderId, | ||
| statuses: [OrderStatus.Blocked, OrderStatus.Processing, OrderStatus.New], | ||
| }); | ||
| const amountPerHour = await Orders.calculateWorkflowPerHourPrice(params.orderId); | ||
| let tokenAmount: bigint; | ||
| let minutes: number; | ||
|
|
||
| if (params.minutes) { | ||
| tokenAmount = (BigInt(amountPerHour) * BigInt(params.minutes)) / 60n; | ||
| minutes = params.minutes; | ||
| } else if (params.sppi) { | ||
| tokenAmount = etherToWei(params.sppi).toBigInt(); | ||
| minutes = Number((tokenAmount * 60n) / BigInt(amountPerHour)); | ||
| } else { | ||
| throw new Error('To complete command please define one of arguments --sppi or --minutes'); | ||
| } | ||
|
Comment on lines
+50
to
+58
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 🛠️ Refactor suggestion Calculation loses precision for non-divisible minute values
🤖 Prompt for AI Agents |
||
|
|
||
| const confirmed = | ||
| params.yes || | ||
| (await isActionConfirmed( | ||
| `Deposit will be replenished by ${weiToEther(tokenAmount)} SPPI. Order time is extended by ${minutes} minutes.`, | ||
| )); | ||
|
Comment on lines
+60
to
+64
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 🛠️ Refactor suggestion Dual-input ambiguity If the user provides both 🤖 Prompt for AI Agents |
||
| if (confirmed) { | ||
| await Orders.replenishWorkflowDeposit(params.orderId, tokenAmount.toString()); | ||
|
|
||
| Printer.print('Deposit replenished successfully'); | ||
| } | ||
| } catch (error: any) { | ||
| Printer.print(`Order ${params.orderId} was not replenished: ${error?.message}`); | ||
| } | ||
|
Comment on lines
+70
to
+72
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Error object typed as Re-throw after logging (see comments in other files) so the CLI command reflects failure status and exit code. 🤖 Prompt for AI Agents |
||
| }; | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -22,8 +22,17 @@ import ordersCancel from './commands/ordersCancel'; | |
| import ordersComplete, { OrderCompleteParams } from './commands/ordersComplete'; | ||
| import ordersReplenishDeposit from './commands/ordersReplenishDeposit'; | ||
| import workflowsCreate, { WorkflowCreateCommandParams } from './commands/workflowsCreate'; | ||
| import workflowsReplenishDeposit, { | ||
| WorkflowReplenishDepositParams, | ||
| } from './commands/workflowsReplenishDeposit'; | ||
| import Printer from './printer'; | ||
| import { collectOptions, commaSeparatedList, processSubCommands, validateFields } from './utils'; | ||
| import { | ||
| collectOptions, | ||
| commaSeparatedList, | ||
| parseNumber, | ||
| processSubCommands, | ||
| validateFields, | ||
| } from './utils'; | ||
| import generateSolutionKey from './commands/solutionsGenerateKey'; | ||
| import prepareSolution from './commands/solutionsPrepare'; | ||
| import ordersDownloadResult, { FilesDownloadParams } from './commands/ordersDownloadResult'; | ||
|
|
@@ -50,6 +59,8 @@ import offersUpdateOption from './commands/offersUpdateOption'; | |
| import offersDeleteOption from './commands/offersDeleteOption'; | ||
| import offersGetSlot from './commands/offersGetSlot'; | ||
| import offersGetOption from './commands/offersGetOption'; | ||
| import offerAddVersion from './commands/offerAddVersion'; | ||
| import offerDisableVersion from './commands/offerDisableVersion'; | ||
| import { checkForUpdates } from './services/checkReleaseVersion'; | ||
| import setup from './commands/setup'; | ||
| import { workflowGenerateKey } from './commands/workflowsGenerateKey'; | ||
|
|
@@ -99,6 +110,8 @@ async function main(): Promise<void> { | |
| const offersCommand = program.command('offers'); | ||
| const offersListCommand = offersCommand.command('list'); | ||
| const offersGetCommand = offersCommand.command('get'); | ||
| const offerCommand = program.command('offer'); | ||
| const offerVersionCommand = offerCommand.command('version'); | ||
| const quotesCommand = program.command('quotes'); | ||
|
|
||
| program.addCommand(secretsCommand); | ||
|
|
@@ -463,6 +476,41 @@ async function main(): Promise<void> { | |
| await workflowsCreate(requestParams); | ||
| }); | ||
|
|
||
| workflowsCommand | ||
| .command('replenish-deposit') | ||
| .argument('<orderId>', 'Order Id') | ||
| .option('--sppi <SPPI>', 'SPPI to add to the order') | ||
| .addOption( | ||
| new Option( | ||
| '--minutes <minutes>', | ||
| 'Time to extend order (automatically calculates tokens)', | ||
| ).argParser((val) => parseInt(val) || 0), | ||
| ) | ||
| .option('--yes', 'Silent question mode. All answers will be yes', false) | ||
| .action( | ||
| async ( | ||
| orderId: string, | ||
| options: { config: string; sppi: string; minutes: number; yes: boolean }, | ||
| ) => { | ||
| const configLoader = new ConfigLoader(options.config); | ||
| const actionAccountKey = configLoader.loadSection('blockchain').accountPrivateKey; | ||
| const blockchain = configLoader.loadSection('blockchain'); | ||
| const blockchainConfig = { | ||
| contractAddress: blockchain.smartContractAddress, | ||
| blockchainUrl: blockchain.rpcUrl, | ||
| }; | ||
| const requestParams: WorkflowReplenishDepositParams = { | ||
| blockchainConfig, | ||
| actionAccountKey, | ||
| orderId, | ||
| minutes: options.minutes, | ||
| sppi: options.sppi, | ||
| yes: options.yes, | ||
| }; | ||
| await workflowsReplenishDeposit(requestParams); | ||
| }, | ||
| ); | ||
|
|
||
| const ordersListFields = [ | ||
| 'id', | ||
| 'offer_name', | ||
|
|
@@ -1387,6 +1435,48 @@ async function main(): Promise<void> { | |
| }); | ||
| }); | ||
|
|
||
| offerVersionCommand | ||
| .command('add') | ||
| .description('Add new version of offer') | ||
| .requiredOption('--offer <id>', 'Offer id') | ||
| .requiredOption('--path <path>', 'Path to offer version info file') | ||
| .option('--ver <version>', 'Version number to add', parseNumber) | ||
| .action(async (options: { offer: string; path: string; ver: number; config: string }) => { | ||
| const configLoader = new ConfigLoader(options.config); | ||
| const blockchain = configLoader.loadSection('blockchain'); | ||
| const blockchainConfig = { | ||
| contractAddress: blockchain.smartContractAddress, | ||
| blockchainUrl: blockchain.rpcUrl, | ||
| }; | ||
| await offerAddVersion({ | ||
| actionAccountKey: blockchain.accountPrivateKey, | ||
| blockchainConfig, | ||
| id: options.offer, | ||
| ver: options.ver, | ||
| path: options.path, | ||
| }); | ||
| }); | ||
|
Comment on lines
+1438
to
+1458
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 🛠️ Refactor suggestion
When Either:
🤖 Prompt for AI Agents |
||
|
|
||
| offerVersionCommand | ||
| .command('disable') | ||
| .description('Disable offer version') | ||
| .requiredOption('--offer <id>', 'Offer id') | ||
| .requiredOption('--ver <version>', 'Version number to delete', parseNumber) | ||
| .action(async (options: { offer: string; ver: number; config: string }) => { | ||
| const configLoader = new ConfigLoader(options.config); | ||
| const blockchain = configLoader.loadSection('blockchain'); | ||
| const blockchainConfig = { | ||
| contractAddress: blockchain.smartContractAddress, | ||
| blockchainUrl: blockchain.rpcUrl, | ||
| }; | ||
| await offerDisableVersion({ | ||
| blockchainConfig, | ||
| id: options.offer, | ||
| ver: options.ver, | ||
| actionAccountKey: blockchain.accountPrivateKey, | ||
| }); | ||
| }); | ||
|
|
||
| filesCommand | ||
| .command('upload') | ||
| .description('Upload a file specified by the <localPath> argument to the remote storage') | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,23 @@ | ||
| import { OfferVersionInfo } from '@super-protocol/sdk-js'; | ||
| import readJsonFile from './readJsonFile'; | ||
| import { HashValidator } from '../services/readResourceFile'; | ||
| import { z } from 'zod'; | ||
|
|
||
| export type ReadFileParams = { | ||
| path: string; | ||
| }; | ||
|
|
||
| const OfferVersionInfoSchema = z.object({ | ||
| metadata: z.object({}).catchall(z.unknown()).optional(), | ||
| signatureKeyHash: HashValidator.optional(), | ||
| hash: HashValidator.optional(), | ||
| }); | ||
|
|
||
| export default async (params: ReadFileParams): Promise<OfferVersionInfo> => { | ||
| const offerOption = await readJsonFile({ | ||
| path: params.path, | ||
| validator: OfferVersionInfoSchema, | ||
| }); | ||
|
|
||
| return offerOption; | ||
| }; |
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.
Missing propagation of failures
Same as in
offerDisableVersion.ts: the error is logged but not re-thrown, so upstream code can’t tell the command failed.🤖 Prompt for AI Agents