|
5 | 5 | "context" |
6 | 6 | "errors" |
7 | 7 | "fmt" |
| 8 | + "os" |
8 | 9 | "strconv" |
9 | 10 | "strings" |
10 | 11 |
|
@@ -390,6 +391,34 @@ var setParamsCommand = &cli.Command{ |
390 | 391 | "save on chain fees. Not setting this flag " + |
391 | 392 | "therefore might result in a lower swap fees", |
392 | 393 | }, |
| 394 | + &cli.BoolFlag{ |
| 395 | + Name: "scriptautoloop", |
| 396 | + Usage: "set to true to enable scriptable autoloop " + |
| 397 | + "using Starlark scripts. This allows custom " + |
| 398 | + "swap logic with variables, functions, loops, " + |
| 399 | + "and sorting. Mutually exclusive with " + |
| 400 | + "easyautoloop and threshold rules.", |
| 401 | + }, |
| 402 | + &cli.StringFlag{ |
| 403 | + Name: "scriptfile", |
| 404 | + Usage: "path to a Starlark script file for " + |
| 405 | + "scriptable autoloop. The script must set " + |
| 406 | + "a 'decisions' variable to a list of swaps. " + |
| 407 | + "Recommended for production use as it allows " + |
| 408 | + "version control and proper editing.", |
| 409 | + }, |
| 410 | + &cli.StringFlag{ |
| 411 | + Name: "script", |
| 412 | + Usage: "inline Starlark script for scriptable " + |
| 413 | + "autoloop. For simple scripts only; use " + |
| 414 | + "--scriptfile for complex scripts.", |
| 415 | + }, |
| 416 | + &cli.Uint64Flag{ |
| 417 | + Name: "scripttickinterval", |
| 418 | + Usage: "custom tick interval in seconds for " + |
| 419 | + "scriptable autoloop. If not set, uses " + |
| 420 | + "the default 20-minute interval.", |
| 421 | + }, |
393 | 422 | }, |
394 | 423 | Action: setParams, |
395 | 424 | } |
@@ -637,6 +666,48 @@ func setParams(ctx context.Context, cmd *cli.Command) error { |
637 | 666 | params.FastSwapPublication = true |
638 | 667 | } |
639 | 668 |
|
| 669 | + // Handle scriptable autoloop flags. |
| 670 | + if cmd.IsSet("scriptautoloop") { |
| 671 | + params.ScriptableAutoloop = cmd.Bool("scriptautoloop") |
| 672 | + flagSet = true |
| 673 | + } |
| 674 | + |
| 675 | + // Handle script content from file or inline. |
| 676 | + scriptFileSet := cmd.IsSet("scriptfile") |
| 677 | + scriptInlineSet := cmd.IsSet("script") |
| 678 | + |
| 679 | + if scriptFileSet && scriptInlineSet { |
| 680 | + return fmt.Errorf("cannot set both --scriptfile and --script; " + |
| 681 | + "use one or the other") |
| 682 | + } |
| 683 | + |
| 684 | + if scriptFileSet { |
| 685 | + scriptPath := cmd.String("scriptfile") |
| 686 | + scriptBytes, err := os.ReadFile(scriptPath) |
| 687 | + if err != nil { |
| 688 | + return fmt.Errorf("failed to read script file %s: %w", |
| 689 | + scriptPath, err) |
| 690 | + } |
| 691 | + params.ScriptableScript = string(scriptBytes) |
| 692 | + flagSet = true |
| 693 | + } |
| 694 | + |
| 695 | + if scriptInlineSet { |
| 696 | + params.ScriptableScript = cmd.String("script") |
| 697 | + flagSet = true |
| 698 | + } |
| 699 | + |
| 700 | + if cmd.IsSet("scripttickinterval") { |
| 701 | + params.ScriptableTickIntervalSec = cmd.Uint64("scripttickinterval") |
| 702 | + flagSet = true |
| 703 | + } |
| 704 | + |
| 705 | + // Validate that scriptable autoloop is not used with easyautoloop. |
| 706 | + if params.ScriptableAutoloop && params.EasyAutoloop { |
| 707 | + return fmt.Errorf("scriptable autoloop cannot be used with " + |
| 708 | + "easy autoloop; disable one before enabling the other") |
| 709 | + } |
| 710 | + |
640 | 711 | if !flagSet { |
641 | 712 | return fmt.Errorf("at least one flag required to set params") |
642 | 713 | } |
|
0 commit comments