@triadxyz/triad-protocol
Version:
<div align="center"> <h1>Triad Protocol</h1> </div>
431 lines (430 loc) • 13.9 kB
TypeScript
import { Connection, PublicKey, TransactionInstruction } from '@solana/web3.js';
import { AnchorProvider, Program, Wallet } from '@coral-xyz/anchor';
import BN from 'bn.js';
import { TriadProtocol } from './types/triad_protocol';
import { CreateMarketArgs, OpenOrderArgs, UserTrade, CreateCustomerArgs, MarketBidOrderArgs, CancelBidOrderArgs, CancelAskOrderArgs, PlaceBidOrderArgs, PlaceAskOrderArgs, CreatePoolArgs, BookOrder, MarketAskOrderArgs, RpcOptions, CollectMarketFeeArgs } from './types';
import Stake from './stake';
import Poseidon from './poseidon';
export * from './types';
export * from './types/stake';
export * from './types/poseidon';
export * from './utils/helpers';
export default class TriadProtocolClient {
program: Program<TriadProtocol>;
provider: AnchorProvider;
stake: Stake;
poseidon: Poseidon;
decimals: number;
constructor(connection: Connection, wallet: Wallet);
/**
* Get All Pools
*
*/
getAllPools(): Promise<import("./types").Pool[]>;
/**
* Get All Markets
*
*/
getAllMarkets(): Promise<import("./types").Market[]>;
/**
* Get My User Trades from a user authority
* @param wallet - User wallet PublicKey
*
*/
getMyUserTrades(wallet: PublicKey): Promise<UserTrade[]>;
/**
* Get User Orders
* @param wallet - User wallet PublicKey
*
*/
getUserOrders(wallet: PublicKey): Promise<import("./types").Order[]>;
/**
* Get Pool By ID
* @param poolId - The ID of the pool
*
*/
getPoolById(poolId: number): Promise<import("./types").Pool>;
/**
* Get Market By ID
* @param marketId - The ID of the market
*
*/
getMarketById(marketId: number): Promise<import("./types").Market>;
/**
* Get Market By Address
* @param marketAddress - The address of the market
*
*/
getMarketByAddress(marketAddress: PublicKey): Promise<import("./types").Market>;
/**
* Get User Trade PDA
* @param wallet - User wallet PublicKey
* @param userNonce - The nonce of the user
*
*/
getUserPDA(wallet: PublicKey, userNonce?: number): PublicKey;
/**
* Get User Trade
* @param wallet - User wallet PublicKey
* @param userNonce - The nonce of the user
*
*/
getUserTrade(wallet: PublicKey, userNonce?: number): Promise<{
bump: number;
authority: PublicKey;
totalDeposits: BN;
totalWithdraws: BN;
padding1: number[];
orders: {
ts: BN;
orderId: BN;
filledShares: BN;
marketId: BN;
orderStatus: ({
open?: never;
closed?: never;
claimed?: never;
liquidated?: never;
waiting?: never;
} & {
init: Record<string, never>;
}) | ({
init?: never;
closed?: never;
claimed?: never;
liquidated?: never;
waiting?: never;
} & {
open: Record<string, never>;
}) | ({
init?: never;
open?: never;
claimed?: never;
liquidated?: never;
waiting?: never;
} & {
closed: Record<string, never>;
}) | ({
init?: never;
open?: never;
closed?: never;
liquidated?: never;
waiting?: never;
} & {
claimed: Record<string, never>;
}) | ({
init?: never;
open?: never;
closed?: never;
claimed?: never;
waiting?: never;
} & {
liquidated: Record<string, never>;
}) | ({
init?: never;
open?: never;
closed?: never;
claimed?: never;
liquidated?: never;
} & {
waiting: Record<string, never>;
});
price: BN;
padding1: number[];
totalShares: BN;
orderType: ({
limit?: never;
} & {
market: Record<string, never>;
}) | ({
market?: never;
} & {
limit: Record<string, never>;
});
orderDirection: ({
flop?: never;
} & {
hype: Record<string, never>;
}) | ({
hype?: never;
} & {
flop: Record<string, never>;
});
userNonce: number;
orderSide: ({
ask?: never;
} & {
bid: Record<string, never>;
}) | ({
bid?: never;
} & {
ask: Record<string, never>;
});
padding2: number[];
createdAt: BN;
padding3: number[];
padding: number[];
}[];
nonce: number;
isSubUser: boolean;
poseidon: number;
padding: number[];
}>;
/**
* Create Market
* @param args.marketId - new markert id - length + 1
* @param args.startTime - start time
* @param args.endTime - end time
* @param args.question - question (max 80 characters)
* @param args.liquidityAtStart - liquidity at start
* @param args.payoutFee - payout fee (to add affiliate system)
*
* @param options - RPC options
*
*/
createMarket({ markets, customer, mint, poolId }: CreateMarketArgs, options?: RpcOptions): Promise<string>;
/**
* Create Pool
* @param poolId - The ID of the pool
* @param question - The question of the pool
* @param markets - The markets of the pool
*
* @param options - RPC options
*/
createPool({ poolId, question, markets, mint, customer, startTime, endTime, feeBps, payoutFee, isFast }: CreatePoolArgs, options?: RpcOptions): Promise<string>;
/**
* Open Order
* @param args.marketId - The ID of the Market
* @param args.amount - The amount of the Order
* @param args.direction - The direction of the Order
* @param args.mint - The mint of the Order
* @param args.token - The token to use for the Order
*
* @param options - RPC options
*
*/
openOrder({ marketId, amount, direction, mint, token }: OpenOrderArgs, options?: RpcOptions): Promise<string>;
/**
* Close Order
* @param args.marketId - The ID of the Market
* @param args.orderId - The ID of the Order
* @param args.userNonce - The nonce of the user
*
* @param options - RPC options
*
*/
closeOrder({ marketId, orderId, userNonce }: {
marketId: number;
orderId: number;
userNonce: number;
}, options?: RpcOptions): Promise<string>;
/**
* Resolve Market
* @param args.marketId - The ID of the Market
* @param args.winningDirection - The Winning Direction of the Market
*
* @param options - RPC options
*
*/
resolveMarket({ marketId, poolId, winningDirection }: {
marketId: number;
poolId?: number;
winningDirection: {
hype: {};
} | {
flop: {};
} | {
none: {};
} | {
draw: {};
};
}, options?: RpcOptions): Promise<string>;
/**
* Collect Remaining Liquidity
* @param marketId - The ID of the market
*
* @param options - RPC options
*
*/
collectRemainingLiquidity(marketId: number, options?: RpcOptions): Promise<string>;
/**
* Payout Order
* @param args.marketId - The ID of the Market
* @param args.orderId - The ID of the Order to Payout
* @param args.userNonce - The nonce of the user
*
* @param options - RPC options
*
*/
payoutOrder(orders: {
marketId: number;
orderId: number;
userNonce: number;
mint: PublicKey;
}[], options?: RpcOptions): Promise<string>;
/**
* Allow Market to Payout
* @param marketId - The ID of the market
* @param poolId - The ID of the pool
*
* @param options - RPC options
*
*/
allowMarketToPayout({ marketId, poolId }: {
marketId: number;
poolId?: number;
}, options?: RpcOptions): Promise<string>;
/**
* Create Sub User Trade
* @param user - User PublicKey the main user
*
* @param options - RPC options
*
*/
createSubUserTrade(user: PublicKey, options?: RpcOptions): Promise<string>;
/**
* Update Market
* @param marketId - The ID of the market
* @param marketEnd - The end time of the market
*
* @param options - RPC options
*
*/
updateMarket(marketId: number, marketEnd: number, options?: RpcOptions): Promise<string>;
/**
* Create Customer
* @param args.id - The ID of the customer
* @param args.name - The name of the customer
* @param args.authority - The authority of the customer
* @param args.feeRecipient - The fee recipient of the customer
*
* @param options - RPC options
*
*/
createCustomer({ id, name, authority, feeRecipient, feeBps }: CreateCustomerArgs, options?: RpcOptions): Promise<string>;
/**
* Get User Trade Nonce With Slots
* @param userTrades - User Trades
*
*/
getUserTradeNonceWithSlots(userTrades: UserTrade[]): PublicKey;
/**
* Get User Trade Ixs
*
*/
getUserTradeIxs(): Promise<{
userTradePDA: PublicKey;
ixs: TransactionInstruction[];
nonce: number;
} | {
userTradePDA: PublicKey;
ixs: TransactionInstruction[];
nonce?: undefined;
}>;
/**
* Place Bid Order
* @param args.marketId - The ID of the Market
* @param args.amount - The amount of the Order
* @param args.direction - The direction of the Order
* @param args.mint - The mint of the Order
* @param args.price - The price of the Order
*
* @param options - RPC options
*/
placeBidOrder({ marketId, amount, direction, mint, price }: PlaceBidOrderArgs, options?: RpcOptions): Promise<string>;
/**
* Place Ask Order
* @param args.marketId - The ID of the Market
* @param args.amount - The amount of the Order
* @param args.direction - The direction of the Order
* @param args.price - The price of the Order
* @param args.bidOrderId - The ID of the Bid Order
* @param args.bidNonce - The nonce of the Bid Order
*
* @param options - RPC options
*
*/
placeAskOrder({ marketId, orders }: PlaceAskOrderArgs, options?: RpcOptions): Promise<string>;
/**
* Cancel Bid Order
* @param args.marketId - The ID of the Market
* @param args.orderId - The ID of the Order
* @param args.userNonce - The nonce of the user
* @param args.direction - The direction of the Order
*
* @param options - RPC options
*/
cancelBidOrder({ marketId, orderId, userNonce, mint, direction }: CancelBidOrderArgs, options?: RpcOptions): Promise<string>;
/**
* Cancel Ask Order
* @param args.marketId - The ID of the Market
* @param args.orderId - The ID of the Order
* @param args.userNonce - The nonce of the user
* @param args.userNonceBidOrder - The nonce of the bid user
* @param args.direction - The direction of the Order
*
* @param options - RPC options
*/
cancelAskOrder({ marketId, orderId, userNonce, direction }: CancelAskOrderArgs, options?: RpcOptions): Promise<string>;
/**
* Market Bid Order
* @param args.marketId - The ID of the Market
* @param args.amount - The amount of the Order
* @param args.direction - The direction of the Order
* @param args.mint - The mint of the Order
*
* @param options - RPC options
*/
marketBidOrder({ marketId, amount, direction, mint, feeBps }: MarketBidOrderArgs, options?: RpcOptions): Promise<string>;
/**
* Market Ask Order
* @param args.marketId - The ID of the Market
* @param args.shares - The amount of the Order
* @param args.bidOrderId - The ID of the Bid Order
* @param args.direction - The direction of the Order
* @param args.mint - The mint of the Order
*
* @param options - RPC options
*/
marketAskOrder({ marketId, shares, bidOrderId, direction, mint }: MarketAskOrderArgs, options?: RpcOptions): Promise<string>;
/**
* Get Orders By Market ID
* @param marketId - The ID of the market
*
*/
getOrderBook(marketId: number): Promise<{
marketId: number;
rewardsAvailable: string;
rewardsClaimed: string;
spreadToReward: string;
hype: {
bid: BookOrder[];
ask: BookOrder[];
};
flop: {
bid: BookOrder[];
ask: BookOrder[];
};
}>;
/**
* Collect Market Fee
* @param marketId - The ID of the market
*
* @param options - RPC options
*/
collectMarketFee({ marketId, feeRecipient }: CollectMarketFeeArgs, options?: RpcOptions): Promise<string>;
/**
* Close Order Book
* @param marketId - The ID of the market
*
* @param options - RPC options
*/
closeOrderBook(marketId: number, options?: RpcOptions): Promise<string>;
/**
* Create Refer
* @param id - The ID of the refer
*
* @param options - RPC options
*/
createRefer(id: number, options?: RpcOptions): Promise<string>;
}