Skip to main content
@tevm/voltaire
@tevm/voltaire / primitives/GasRefund

primitives/GasRefund

Type Aliases

GasRefundType

GasRefundType = bigint & object
Defined in: src/primitives/GasRefund/GasRefundType.ts:8 Branded GasRefund type - gas refunded after transaction Sources: SSTORE refunds, SELFDESTRUCT refunds (pre-London) Post-London (EIP-3529): Capped at gasUsed / 5

Type Declaration

[brand]
readonly [brand]: "GasRefund"

Variables

GasRefund

const GasRefund: object
Defined in: src/primitives/GasRefund/index.ts:46

Type Declaration

cappedRefund()
cappedRefund: (refund, gasUsed) => GasRefundType
Parameters
refund
string | number | bigint
gasUsed
bigint
Returns
GasRefundType
equals()
equals: (value1, value2) => boolean
Parameters
value1
string | number | bigint
value2
string | number | bigint
Returns
boolean
from()
from: (value) => GasRefundType
Create GasRefund from number, bigint, or string
Parameters
value
Gas refund value string | number | bigint
Returns
GasRefundType Branded gas refund
Throws
If value is negative
Example
const refund = GasRefund.from(15000n); // SSTORE clear refund
const noRefund = GasRefund.from(0n);
toBigInt()
toBigInt: (value) => bigint
Parameters
value
string | number | bigint
Returns
bigint
toHex()
toHex: (value) => string
Parameters
value
string | number | bigint
Returns
string
toNumber()
toNumber: (value) => number
Parameters
value
string | number | bigint
Returns
number

Functions

_cappedRefund()

_cappedRefund(this, gasUsed): GasRefundType
Defined in: src/primitives/GasRefund/cappedRefund.js:22 Apply EIP-3529 refund cap (gasUsed / 5) Post-London hard fork limitation on gas refunds

Parameters

this
GasRefundType
gasUsed
bigint Gas used by transaction

Returns

GasRefundType Capped refund

Example

const refund = GasRefund.from(15000n);
const gasUsed = 50000n;
// Cap = 50000 / 5 = 10000
GasRefund._cappedRefund.call(refund, gasUsed); // 10000n (capped)

const smallRefund = GasRefund.from(5000n);
GasRefund._cappedRefund.call(smallRefund, gasUsed); // 5000n (not capped)

_equals()

_equals(this, other): boolean
Defined in: src/primitives/GasRefund/equals.js:15 Check if two GasRefund values are equal

Parameters

this
GasRefundType
other
GasRefundType Other gas refund value

Returns

boolean True if equal

Example

const a = GasRefund.from(15000n);
const b = GasRefund.from(15000n);
GasRefund._equals.call(a, b); // true

_toBigInt()

_toBigInt(this): bigint
Defined in: src/primitives/GasRefund/toBigInt.js:13 Convert GasRefund to bigint (identity, for compatibility)

Parameters

this
GasRefundType

Returns

bigint Gas refund as bigint

Example

const refund = GasRefund.from(15000n);
GasRefund.toBigInt(refund); // 15000n

_toHex()

_toHex(this): string
Defined in: src/primitives/GasRefund/toHex.js:13 Convert GasRefund to hex string

Parameters

this
GasRefundType

Returns

string Gas refund as hex string (0x prefixed)

Example

const refund = GasRefund.from(15000n);
GasRefund.toHex(refund); // "0x3a98"

_toNumber()

_toNumber(this): number
Defined in: src/primitives/GasRefund/toNumber.js:13 Convert GasRefund to number

Parameters

this
GasRefundType

Returns

number Gas refund as number

Example

const refund = GasRefund.from(15000n);
GasRefund.toNumber(refund); // 15000

cappedRefund()

cappedRefund(refund, gasUsed): GasRefundType
Defined in: src/primitives/GasRefund/index.ts:35

Parameters

refund
string | number | bigint
gasUsed
bigint

Returns

GasRefundType

equals()

equals(value1, value2): boolean
Defined in: src/primitives/GasRefund/index.ts:28

Parameters

value1
string | number | bigint
value2
string | number | bigint

Returns

boolean

from()

from(value): GasRefundType
Defined in: src/primitives/GasRefund/from.js:16 Create GasRefund from number, bigint, or string

Parameters

value
Gas refund value string | number | bigint

Returns

GasRefundType Branded gas refund

Throws

If value is negative

Example

const refund = GasRefund.from(15000n); // SSTORE clear refund
const noRefund = GasRefund.from(0n);

toBigInt()

toBigInt(value): bigint
Defined in: src/primitives/GasRefund/index.ts:20

Parameters

value
string | number | bigint

Returns

bigint

toHex()

toHex(value): string
Defined in: src/primitives/GasRefund/index.ts:24

Parameters

value
string | number | bigint

Returns

string

toNumber()

toNumber(value): number
Defined in: src/primitives/GasRefund/index.ts:16

Parameters

value
string | number | bigint

Returns

number