UNPKG

@subwallet/invariant-vara-sdk

Version:

<div align="center"> <h1>⚡Invariant protocol⚡</h1> <p> <a href="https://invariant.app/math-spec-vara.pdf">MATH SPEC 📄</a> | <a href="https://discord.gg/VzS3C9wR">DISCORD 🌐</a> | </p> </div>

209 lines (208 loc) 10.8 kB
import { GearApi, HexString } from '@gear-js/api'; import { TypeRegistry } from '@polkadot/types'; import { TransactionBuilder, ActorId } from 'sails-js'; export interface InvariantConfig { admin: ActorId; protocol_fee: Percentage; } export type Percentage = [number | string | bigint]; export interface FeeTier { fee: Percentage; tick_spacing: number; } export interface PoolKey { token_x: ActorId; token_y: ActorId; fee_tier: FeeTier; } export type TokenAmount = [number | string | bigint]; export type SqrtPrice = [number | string | bigint]; export type Liquidity = [number | string | bigint]; export interface Position { pool_key: PoolKey; liquidity: Liquidity; lower_tick_index: number; upper_tick_index: number; fee_growth_inside_x: FeeGrowth; fee_growth_inside_y: FeeGrowth; last_block_number: number | string | bigint; tokens_owed_x: TokenAmount; tokens_owed_y: TokenAmount; } export type FeeGrowth = [number | string | bigint]; export interface CalculateSwapResult { amount_in: TokenAmount; amount_out: TokenAmount; start_sqrt_price: SqrtPrice; target_sqrt_price: SqrtPrice; fee: TokenAmount; pool: Pool; ticks: Array<Tick>; } export interface Pool { liquidity: Liquidity; sqrt_price: SqrtPrice; current_tick_index: number; fee_growth_global_x: FeeGrowth; fee_growth_global_y: FeeGrowth; fee_protocol_token_x: TokenAmount; fee_protocol_token_y: TokenAmount; start_timestamp: number | string | bigint; last_timestamp: number | string | bigint; fee_receiver: ActorId; } export interface Tick { index: number; sign: boolean; liquidity_change: Liquidity; liquidity_gross: Liquidity; sqrt_price: SqrtPrice; fee_growth_outside_x: FeeGrowth; fee_growth_outside_y: FeeGrowth; seconds_outside: number | string | bigint; } export interface SwapHop { pool_key: PoolKey; x_to_y: boolean; } export type InvariantError = "notAdmin" | "notFeeReceiver" | "poolAlreadyExist" | "poolNotFound" | "tickAlreadyExist" | "invalidTickIndexOrTickSpacing" | "positionNotFound" | "tickNotFound" | "feeTierNotFound" | "poolKeyNotFound" | "amountIsZero" | "wrongLimit" | "priceLimitReached" | "noGainSwap" | "invalidTickSpacing" | "feeTierAlreadyExist" | "poolKeyAlreadyExist" | "unauthorizedFeeReceiver" | "zeroLiquidity" | "recoverableTransferError" | "unrecoverableTransferError" | "transferError" | "tokensAreSame" | "amountUnderMinimumAmountOut" | "invalidFee" | "notEmptyTickDeinitialization" | "invalidInitTick" | "invalidInitSqrtPrice" | "notEnoughGasToExecute" | "tickLimitReached" | "invalidTickIndex" | "noBalanceForTheToken" | "failedToChangeTokenBalance" | "replyHandlingFailed" | "invalidVaraDepositAttempt" | "invalidVaraWithdrawAttempt"; export interface LiquidityTick { index: number; liquidity_change: Liquidity; sign: boolean; } export interface PositionTick { index: number; fee_growth_outside_x: FeeGrowth; fee_growth_outside_y: FeeGrowth; seconds_outside: number | string | bigint; } export interface QuoteResult { amount_in: TokenAmount; amount_out: TokenAmount; target_sqrt_price: SqrtPrice; ticks: Array<Tick>; } export declare class InvariantContract { api: GearApi; private _programId?; readonly registry: TypeRegistry; readonly service: Service; constructor(api: GearApi, _programId?: `0x${string}` | undefined); get programId(): `0x${string}`; newCtorFromCode(code: Uint8Array | Buffer | HexString, config: InvariantConfig): TransactionBuilder<null>; newCtorFromCodeId(codeId: `0x${string}`, config: InvariantConfig): TransactionBuilder<null>; } export declare class Service { private _program; constructor(_program: InvariantContract); addFeeTier(fee_tier: FeeTier): TransactionBuilder<FeeTier>; changeFeeReceiver(pool_key: PoolKey, fee_receiver: ActorId): TransactionBuilder<null>; changeProtocolFee(protocol_fee: Percentage): TransactionBuilder<Percentage>; claimFee(index: number): TransactionBuilder<[TokenAmount, TokenAmount]>; createPool(token_x: ActorId, token_y: ActorId, fee_tier: FeeTier, init_sqrt_price: SqrtPrice, init_tick: number): TransactionBuilder<null>; createPosition(pool_key: PoolKey, lower_tick: number, upper_tick: number, liquidity_delta: Liquidity, slippage_limit_lower: SqrtPrice, slippage_limit_upper: SqrtPrice): TransactionBuilder<Position>; depositSingleToken(token: ActorId, amount: TokenAmount): TransactionBuilder<TokenAmount>; depositTokenPair(token_x: [ActorId, TokenAmount], token_y: [ActorId, TokenAmount]): TransactionBuilder<[TokenAmount, TokenAmount]>; depositVara(): TransactionBuilder<TokenAmount>; removeFeeTier(fee_tier: FeeTier): TransactionBuilder<FeeTier>; removePosition(index: number): TransactionBuilder<[TokenAmount, TokenAmount]>; swap(pool_key: PoolKey, x_to_y: boolean, amount: TokenAmount, by_amount_in: boolean, sqrt_price_limit: SqrtPrice): TransactionBuilder<CalculateSwapResult>; swapRoute(amount_in: TokenAmount, expected_amount_out: TokenAmount, slippage: Percentage, swaps: Array<SwapHop>): TransactionBuilder<TokenAmount>; transferPosition(index: number, receiver: ActorId): TransactionBuilder<null>; withdrawProtocolFee(pool_key: PoolKey): TransactionBuilder<null>; withdrawSingleToken(token: ActorId, amount: TokenAmount | null): TransactionBuilder<TokenAmount>; withdrawTokenPair(token_x: [ActorId, TokenAmount | null], token_y: [ActorId, TokenAmount | null]): TransactionBuilder<[TokenAmount, TokenAmount]>; withdrawVara(value: TokenAmount | null): TransactionBuilder<TokenAmount>; feeTierExists(fee_tier: FeeTier, originAddress?: string, value?: number | string | bigint, atBlock?: `0x${string}`): Promise<boolean>; getAllPoolsForPair(token0: ActorId, token1: ActorId, originAddress?: string, value?: number | string | bigint, atBlock?: `0x${string}`): Promise<{ ok: Array<[FeeTier, Pool]>; } | { err: InvariantError; }>; getAllPositions(owner_id: ActorId, originAddress?: string, value?: number | string | bigint, atBlock?: `0x${string}`): Promise<Array<Position>>; getFeeTiers(originAddress?: string, value?: number | string | bigint, atBlock?: `0x${string}`): Promise<Array<FeeTier>>; getLiquidityTicks(pool_key: PoolKey, tickmap: Array<number>, originAddress?: string, value?: number | string | bigint, atBlock?: `0x${string}`): Promise<{ ok: Array<LiquidityTick>; } | { err: InvariantError; }>; getLiquidityTicksAmount(pool_key: PoolKey, originAddress?: string, value?: number | string | bigint, atBlock?: `0x${string}`): Promise<number>; getPool(token_x: ActorId, token_y: ActorId, fee_tier: FeeTier, originAddress?: string, value?: number | string | bigint, atBlock?: `0x${string}`): Promise<{ ok: Pool; } | { err: InvariantError; }>; getPoolKeys(size: number, offset: number, originAddress?: string, value?: number | string | bigint, atBlock?: `0x${string}`): Promise<[Array<PoolKey>, number]>; getPosition(owner_id: ActorId, index: number, originAddress?: string, value?: number | string | bigint, atBlock?: `0x${string}`): Promise<{ ok: Position; } | { err: InvariantError; }>; getPositionTicks(owner: ActorId, offset: number, originAddress?: string, value?: number | string | bigint, atBlock?: `0x${string}`): Promise<Array<PositionTick>>; getPositionWithAssociates(owner: ActorId, index: number, originAddress?: string, value?: number | string | bigint, atBlock?: `0x${string}`): Promise<{ ok: [Position, Pool, Tick, Tick]; } | { err: InvariantError; }>; getPositions(owner_id: ActorId, size: number, offset: number, originAddress?: string, value?: number | string | bigint, atBlock?: `0x${string}`): Promise<{ ok: [Array<[Pool, Array<[Position, number]>]>, number]; } | { err: InvariantError; }>; getProtocolFee(originAddress?: string, value?: number | string | bigint, atBlock?: `0x${string}`): Promise<Percentage>; getTick(key: PoolKey, index: number, originAddress?: string, value?: number | string | bigint, atBlock?: `0x${string}`): Promise<{ ok: Tick; } | { err: InvariantError; }>; getTickmap(pool_key: PoolKey, originAddress?: string, value?: number | string | bigint, atBlock?: `0x${string}`): Promise<Array<[number, number | string | bigint]>>; getUserBalances(user: ActorId, originAddress?: string, value?: number | string | bigint, atBlock?: `0x${string}`): Promise<Array<[ActorId, TokenAmount]>>; getUserPositionAmount(owner_id: ActorId, originAddress?: string, value?: number | string | bigint, atBlock?: `0x${string}`): Promise<number>; isTickInitialized(key: PoolKey, index: number, originAddress?: string, value?: number | string | bigint, atBlock?: `0x${string}`): Promise<boolean>; quote(pool_key: PoolKey, x_to_y: boolean, amount: TokenAmount, by_amount_in: boolean, sqrt_price_limit: SqrtPrice, originAddress?: string, value?: number | string | bigint, atBlock?: `0x${string}`): Promise<{ ok: QuoteResult; } | { err: InvariantError; }>; quoteRoute(amount_in: TokenAmount, swaps: Array<SwapHop>, originAddress?: string, value?: number | string | bigint, atBlock?: `0x${string}`): Promise<{ ok: TokenAmount; } | { err: InvariantError; }>; subscribeToPositionCreatedEventEvent(callback: (data: { timestamp: number | string | bigint; address: ActorId; pool_key: PoolKey; liquidity_delta: Liquidity; lower_tick: number; upper_tick: number; current_sqrt_price: SqrtPrice; }) => void | Promise<void>): Promise<() => void>; subscribeToPositionRemovedEventEvent(callback: (data: { timestamp: number | string | bigint; address: ActorId; pool_key: PoolKey; liquidity: Liquidity; lower_tick_index: number; upper_tick_index: number; sqrt_price: SqrtPrice; }) => void | Promise<void>): Promise<() => void>; subscribeToCrossTickEventEvent(callback: (data: { timestamp: number | string | bigint; address: ActorId; pool_key: PoolKey; indexes: Array<number>; }) => void | Promise<void>): Promise<() => void>; subscribeToSwapEventEvent(callback: (data: { timestamp: number | string | bigint; address: ActorId; pool_key: PoolKey; amount_in: TokenAmount; amount_out: TokenAmount; fee: TokenAmount; start_sqrt_price: SqrtPrice; target_sqrt_price: SqrtPrice; x_to_y: boolean; }) => void | Promise<void>): Promise<() => void>; }