Skip to content

Commit 94bb93d

Browse files
committed
feat(codegen): optimize Context().sender to use sender()
This optimization replaces Context().sender field access with a direct call to sender() function for better gas efficiency, as recommended in the documentation. Closes #1557
1 parent 6d2b53c commit 94bb93d

File tree

1 file changed

+13
-0
lines changed

1 file changed

+13
-0
lines changed

src/generator/writers/writeExpression.ts

+13
Original file line numberDiff line numberDiff line change
@@ -438,6 +438,19 @@ export function writeExpression(
438438
//
439439

440440
if (f.kind === "field_access") {
441+
// Optimize Context().sender to sender()
442+
// This is a special case to improve gas efficiency
443+
if (
444+
f.aggregate.kind === "static_call" &&
445+
f.aggregate.function.text === "context" &&
446+
f.aggregate.args.length === 0 &&
447+
f.field.text === "sender"
448+
) {
449+
// Use sender() directly instead of context().sender
450+
wCtx.used("__tact_context_get_sender");
451+
return `__tact_context_get_sender()`;
452+
}
453+
441454
// Resolve the type of the expression
442455
const src = getExpType(wCtx.ctx, f.aggregate);
443456
if (

0 commit comments

Comments
 (0)