import { Transaction, TransactionArgument, TransactionObjectInput, TransactionResult } from '@mysten/sui/transactions'; import type { EnvConfig } from '../../_envs'; export interface NewConfigArgs { windowDuration: bigint | TransactionArgument; maxOutflow: bigint | TransactionArgument; } /** * Creates a new rate limiter configuration. * * # Arguments * * * `window_duration` - The duration of the rate limiter window in seconds. * * `max_outflow` - The maximum allowed outflow in a single window. * * # Returns * * * `RateLimiterConfig` - A new configuration instance for the rate limiter. * * # Panics * * * If `window_duration` is zero (`EInvalidConfig`). */ export declare function newConfig(tx: Transaction, args: NewConfigArgs, options?: { env?: EnvConfig; }): TransactionResult; export interface NewArgs { config: TransactionObjectInput; curTime: bigint | TransactionArgument; } /** * Creates a new rate limiter with the specified configuration and current time. * * Initializes the rate limiter with zero previous and current quantities, setting the * window start to the provided time. * * # Arguments * * * `config` - The `RateLimiterConfig` defining the window duration and max outflow. * * `cur_time` - The current timestamp in seconds. * * # Returns * * * `RateLimiter` - A new rate limiter instance. */ export declare function new_(tx: Transaction, args: NewArgs, options?: { env?: EnvConfig; }): TransactionResult; export interface UpdateInternalArgs { rateLimiter: TransactionObjectInput; curTime: bigint | TransactionArgument; } /** * Updates the rate limiter's state based on the current time. * * This internal function shifts the window forward if the current time exceeds the * current window's end. It moves the current quantity to the previous quantity and * resets the current quantity if within the next window, or clears both if the time * is beyond two windows. * * # Arguments * * * `rate_limiter` - A mutable reference to the `RateLimiter` to update. * * `cur_time` - The current timestamp in seconds. * * # Panics * * * If `cur_time` is less than the rate limiter's `window_start` (`EInvalidTime`). */ export declare function updateInternal(tx: Transaction, args: UpdateInternalArgs, options?: { env?: EnvConfig; }): TransactionResult; export interface CurrentOutflowArgs { rateLimiter: TransactionObjectInput; curTime: bigint | TransactionArgument; } /** * Calculates the current outflow for the rate limiter. * * This function assumes an even distribution of the previous window's outflow and * combines it with the current window's outflow, weighted by the time remaining in * the previous window. Must be called after `update_internal`. * * # Arguments * * * `rate_limiter` - A reference to the `RateLimiter` to query. * * `cur_time` - The current timestamp in seconds. * * # Returns * * * `Decimal` - The calculated current outflow, combining weighted previous and current quantities. * * # Panics * * * If the `window_duration` is zero, as this would lead to division by zero. */ export declare function currentOutflow(tx: Transaction, args: CurrentOutflowArgs, options?: { env?: EnvConfig; }): TransactionResult; export interface ProcessQtyArgs { rateLimiter: TransactionObjectInput; curTime: bigint | TransactionArgument; qty: TransactionObjectInput; } /** * Processes a new outflow quantity, updating the rate limiter and checking the limit. * * Updates the rate limiter's state and adds the specified quantity to the current * window's outflow. It ensures the total outflow does not exceed the configured maximum. * * # Arguments * * * `rate_limiter` - A mutable reference to the `RateLimiter` to update. * * `cur_time` - The current timestamp in seconds. * * `qty` - The outflow quantity to process, as a `Decimal`. * * # Panics * * * If `cur_time` is less than the rate limiter's `window_start` (`EInvalidTime`). * * If the total outflow exceeds the configured `max_outflow` (`ERateLimitExceeded`). * * If the `window_duration` is zero, as this would lead to division by zero in `current_outflow`. */ export declare function processQty(tx: Transaction, args: ProcessQtyArgs, options?: { env?: EnvConfig; }): TransactionResult; export interface RemainingOutflowArgs { rateLimiter: TransactionObjectInput; curTime: bigint | TransactionArgument; } /** * Calculates the remaining outflow capacity in the current window. * * Updates the rate limiter's state and returns the difference between the maximum * allowed outflow and the current outflow, ensuring non-negative results. * * # Arguments * * * `rate_limiter` - A mutable reference to the `RateLimiter` to query. * * `cur_time` - The current timestamp in seconds. * * # Returns * * * `Decimal` - The remaining outflow capacity in the current window. * * # Panics * * * If `cur_time` is less than the rate limiter's `window_start` (`EInvalidTime`). * * If the `window_duration` is zero, as this would lead to division by zero in `current_outflow`. */ export declare function remainingOutflow(tx: Transaction, args: RemainingOutflowArgs, options?: { env?: EnvConfig; }): TransactionResult;