@typesol/cli 0.48.0 → 0.49.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -59,12 +59,12 @@ export function emitProgram(analysis, opts = {}) {
59
59
  else if (panicFlag.value)
60
60
  out.push(`#define TS_PANIC_ON_OVERFLOW 1`);
61
61
  }
62
- // `const PANIC_STYLE = "solana-1.14"`: panics log as solana_program 1.14's panic handler does and abort (read by the
63
- // emitter); PANIC_ON_OVERFLOW's panics abort too instead of calling sol_panic_.
62
+ // `const PANIC_STYLE = "solana-1.14"` / `"solana-1.18"`: panics log as that solana_program's panic handler does and
63
+ // abort (read by the emitter); PANIC_ON_OVERFLOW's panics abort too instead of calling sol_panic_.
64
64
  const panicStyle = model.constants.get("PANIC_STYLE");
65
65
  if (panicStyle) {
66
- if (panicStyle.value !== "solana-1.14")
67
- reporter.error(analysis.sourceFile, "PANIC_STYLE must be \"solana-1.14\" (panics log `panicked at '<message>', <file>:<line>:<col>` and abort, as programs built with solana-program 1.14 to 1.17 do); leave it out for the default");
66
+ if (panicStyle.value !== "solana-1.14" && panicStyle.value !== "solana-1.18")
67
+ reporter.error(analysis.sourceFile, 'PANIC_STYLE must be "solana-1.14" (panics log `panicked at \'<message>\', <file>:<line>:<col>` and abort, as programs built with solana-program 1.14 to 1.17 do) or "solana-1.18" (`panicked at <file>:<line>:<col>:` and the message on the next line, then abort, as solana-program 1.18\'s); leave it out for the default');
68
68
  else if (panicFlag?.value === true)
69
69
  out.push(`#define TS_PANIC_ABORT 1`);
70
70
  }
@@ -901,9 +901,14 @@ export class StorageEmitter extends AliasEmitter {
901
901
  const h = this.handle(node.expression);
902
902
  if (h) {
903
903
  // Remaining accounts carry no static guarantees: check writability where it is written, and that it is not
904
- // also another (declared or remaining) account, which would let one balance be counted twice.
905
- this.line(`TS_TRY(ts_check_writable(${h}));`);
906
- this.line(`TS_TRY(ts_check_unaliased(params, ${h}));`);
904
+ // also another (declared or remaining) account, which would let one balance be counted twice. Under
905
+ // NATIVE_ACCOUNT_WRITES the write is a native program's `**a.lamports.borrow_mut() = v`: an account passed twice
906
+ // shares one record (as Rust's duplicate AccountInfos share one RefCell), and the runtime judges writability
907
+ // when the instruction ends (ReadonlyLamportChange / UnbalancedInstruction).
908
+ if (!this.nativeAccountWrites()) {
909
+ this.line(`TS_TRY(ts_check_writable(${h}));`);
910
+ this.line(`TS_TRY(ts_check_unaliased(params, ${h}));`);
911
+ }
907
912
  return { type: U64, read: `${h}->lamports`, write: (c) => `${h}->lamports = ${c}` };
908
913
  }
909
914
  }
@@ -91,6 +91,9 @@ export function hintForTypeScript(d, message, libPath) {
91
91
  case 2365: // Operator '+=' cannot be applied to types 'bigint' and 'number'.
92
92
  case 2322: // Type 'number' is not assignable to type 'bigint'.
93
93
  case 2345: // Argument of type 'bigint' is not assignable to parameter of type 'number'.
94
+ // Argument of type 'TokenAccount' is not assignable to parameter of type 'RemainingAccount | AccountInfo'.
95
+ if (/parameter of type '(?:RemainingAccount \| AccountInfo|AccountInfo \| RemainingAccount)'/.test(message))
96
+ return "pass a remaining account (remainingAccounts().get(i)) or an AccountInfo parameter; a declared parameter of a program or sysvar type is used as it is";
94
97
  if (/\bDate\.now\(|\bnew Date\b/.test(line))
95
98
  return CLOCK_HINT;
96
99
  if (/\bMath\.\w+\(/.test(line))