2021-06-23 07:36:51 -07:00
|
|
|
import { AccountInfo, PublicKey, Transaction } from '@solana/web3.js'
|
2021-04-02 11:26:21 -07:00
|
|
|
import { Market, OpenOrders } from '@project-serum/serum'
|
|
|
|
import { Event } from '@project-serum/serum/lib/queue'
|
2022-02-09 08:28:57 -08:00
|
|
|
import { I80F48 } from '@blockworks-foundation/mango-client'
|
2021-03-30 15:47:08 -07:00
|
|
|
|
2021-12-18 13:04:19 -08:00
|
|
|
export interface Token {
|
|
|
|
chainId: number // 101,
|
|
|
|
address: string // 'EPjFWdd5AufqSSqeM2qN1xzybapC8G4wEGGkZwyTDt1v',
|
|
|
|
symbol: string // 'USDC',
|
|
|
|
name: string // 'Wrapped USDC',
|
|
|
|
decimals: number // 6,
|
|
|
|
logoURI: string // 'https://raw.githubusercontent.com/solana-labs/token-list/main/assets/mainnet/BXXkv6z8ykpG1yuvUDPgh732wzVHB69RnB9YgSYh3itW/logo.png',
|
|
|
|
tags: string[] // [ 'stablecoin' ]
|
|
|
|
}
|
2021-03-30 15:47:08 -07:00
|
|
|
export interface MarketInfo {
|
2021-04-02 11:26:21 -07:00
|
|
|
address: PublicKey
|
|
|
|
name: string
|
|
|
|
programId: PublicKey
|
|
|
|
deprecated: boolean
|
|
|
|
quoteLabel?: string
|
|
|
|
baseLabel?: string
|
2021-03-30 15:47:08 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
export interface CustomMarketInfo {
|
2021-04-02 11:26:21 -07:00
|
|
|
address: string
|
|
|
|
name: string
|
|
|
|
programId: string
|
|
|
|
quoteLabel?: string
|
|
|
|
baseLabel?: string
|
2021-03-30 15:47:08 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
export interface TokenAccount {
|
2021-04-02 11:26:21 -07:00
|
|
|
pubkey: PublicKey
|
|
|
|
account: AccountInfo<Buffer> | null
|
|
|
|
effectiveMint: PublicKey
|
2021-03-30 15:47:08 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
export interface Trade extends Event {
|
2021-04-02 11:26:21 -07:00
|
|
|
side: string
|
|
|
|
price: number
|
|
|
|
feeCost: number
|
|
|
|
size: number
|
2021-03-30 15:47:08 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
interface BalancesBase {
|
2021-04-02 11:26:21 -07:00
|
|
|
key: string
|
2021-07-05 08:03:57 -07:00
|
|
|
symbol: string
|
2021-04-02 11:26:21 -07:00
|
|
|
wallet?: number | null | undefined
|
|
|
|
orders?: number | null | undefined
|
|
|
|
openOrders?: OpenOrders | null | undefined
|
|
|
|
unsettled?: number | null | undefined
|
2021-03-30 15:47:08 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
export interface Balances extends BalancesBase {
|
2021-04-02 11:26:21 -07:00
|
|
|
market?: Market | null | undefined
|
2021-08-18 13:43:51 -07:00
|
|
|
deposits?: I80F48 | null | undefined
|
2021-07-05 08:03:57 -07:00
|
|
|
borrows?: I80F48 | null | undefined
|
2021-07-08 07:16:39 -07:00
|
|
|
net?: I80F48 | null | undefined
|
2021-09-03 05:11:21 -07:00
|
|
|
value?: I80F48 | null | undefined
|
2021-09-06 04:51:18 -07:00
|
|
|
depositRate?: I80F48 | null | undefined
|
|
|
|
borrowRate?: I80F48 | null | undefined
|
2021-03-30 15:47:08 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
export interface OpenOrdersBalances extends BalancesBase {
|
2021-04-02 11:26:21 -07:00
|
|
|
market?: string | null | undefined
|
|
|
|
baseCurrencyAccount:
|
|
|
|
| { pubkey: PublicKey; account: AccountInfo<Buffer> }
|
|
|
|
| null
|
|
|
|
| undefined
|
|
|
|
quoteCurrencyAccount:
|
|
|
|
| { pubkey: PublicKey; account: AccountInfo<Buffer> }
|
|
|
|
| null
|
|
|
|
| undefined
|
2021-03-30 15:47:08 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
export interface EndpointInfo {
|
2021-04-02 11:26:21 -07:00
|
|
|
name: string
|
2021-04-20 14:00:45 -07:00
|
|
|
url: string
|
|
|
|
websocket: string
|
2021-04-02 11:26:21 -07:00
|
|
|
custom: boolean
|
2021-03-30 15:47:08 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* {tokenMint: preferred token account's base58 encoded public key}
|
|
|
|
*/
|
|
|
|
export interface SelectedTokenAccounts {
|
2021-04-02 11:26:21 -07:00
|
|
|
[tokenMint: string]: string
|
2021-03-30 15:47:08 -07:00
|
|
|
}
|
|
|
|
|
2021-04-05 13:48:24 -07:00
|
|
|
export interface ChartTradeType {
|
2021-04-02 11:26:21 -07:00
|
|
|
market: string
|
|
|
|
size: number
|
|
|
|
price: number
|
|
|
|
orderId: string
|
|
|
|
time: number
|
|
|
|
side: string
|
|
|
|
feeCost: number
|
|
|
|
marketAddress: string
|
2021-03-30 15:47:08 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
export interface FeeRates {
|
2021-04-02 11:26:21 -07:00
|
|
|
taker: number
|
|
|
|
maker: number
|
2021-03-30 15:47:08 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
// Type declaration for the margin accounts for the mango group
|
2021-04-02 11:26:21 -07:00
|
|
|
export type mangoTokenAccounts = {
|
|
|
|
mango_group: string
|
|
|
|
accounts: TokenAccount[]
|
|
|
|
}
|
2021-03-30 15:47:08 -07:00
|
|
|
|
|
|
|
// Token infos
|
|
|
|
export interface KnownToken {
|
2021-04-02 11:26:21 -07:00
|
|
|
tokenSymbol: string
|
|
|
|
tokenName: string
|
|
|
|
icon?: string
|
|
|
|
mintAddress: string
|
2021-03-30 15:47:08 -07:00
|
|
|
}
|
2021-04-13 22:23:50 -07:00
|
|
|
|
|
|
|
export const DEFAULT_PUBLIC_KEY = new PublicKey(
|
|
|
|
'11111111111111111111111111111111'
|
|
|
|
)
|
|
|
|
|
|
|
|
export interface WalletAdapter {
|
|
|
|
publicKey: PublicKey
|
|
|
|
autoApprove: boolean
|
|
|
|
connected: boolean
|
|
|
|
signTransaction: (transaction: Transaction) => Promise<Transaction>
|
|
|
|
signAllTransactions: (transaction: Transaction[]) => Promise<Transaction[]>
|
|
|
|
connect: () => any
|
|
|
|
disconnect: () => any
|
2021-04-14 11:40:28 -07:00
|
|
|
on(event: string, fn: () => void): this
|
2021-04-13 22:23:50 -07:00
|
|
|
}
|
2021-09-23 04:50:34 -07:00
|
|
|
|
|
|
|
export interface PerpTriggerOrder {
|
|
|
|
orderId: number
|
|
|
|
marketIndex: number
|
|
|
|
orderType: 'limit' | 'ioc' | 'postOnly' | 'market'
|
|
|
|
side: 'buy' | 'sell'
|
|
|
|
price: number
|
|
|
|
size: number
|
|
|
|
triggerCondition: 'above' | 'below'
|
|
|
|
triggerPrice: number
|
|
|
|
}
|