-
Notifications
You must be signed in to change notification settings - Fork 92
/
types.ts
202 lines (178 loc) · 4.87 KB
/
types.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
import { Address, Asset, BaseAmount } from '@xchainjs/xchain-util'
/**
* Enumeration of network types.
*/
export enum Network {
Mainnet = 'mainnet',
Stagenet = 'stagenet',
Testnet = 'testnet',
}
/**
* Type definition for asset information.
*/
export type AssetInfo = {
asset: Asset // The asset
decimal: number // The decimal value
}
/**
* Type definition for a balance.
*/
export type Balance = {
asset: Asset // The asset
amount: BaseAmount // The amount
}
/**
* Enumeration of transaction types.
*/
export enum TxType {
Transfer = 'transfer',
Unknown = 'unknown',
}
/**
* Type definition for a transaction hash.
*/
export type TxHash = string
/**
* Type definition for the recipient of a transaction.
*/
export type TxTo = {
to: Address // The recipient address
amount: BaseAmount // The amount
asset?: Asset // The asset (optional)
}
/**
* Type definition for the sender of a transaction.
*/
export type TxFrom = {
from: Address | TxHash // The sender address or transaction hash
amount: BaseAmount // The amount
asset?: Asset // The asset (optional)
}
/**
* Type definition for a transaction.
*/
export type Tx = {
asset: Asset // The asset
from: TxFrom[] // List of sender transactions
to: TxTo[] // List of recipient transactions
date: Date // Timestamp of the transaction
type: TxType // Type of transaction
hash: string // Transaction hash
}
/**
* Type definition for a page of transactions.
*/
export type TxsPage = {
total: number // Total number of transactions
txs: Tx[] // Array of transactions
}
/**
* Type definition for parameters used to retrieve transaction history.
*/
export type TxHistoryParams = {
address: Address // Address to get history for
offset?: number // Optional offset
limit?: number // Optional limit of transactions
startTime?: Date // Optional start time
asset?: string // Optional asset. Result transactions will be filtered by this asset
}
/**
* Type definition for transaction parameters.
*/
export type TxParams = {
walletIndex?: number // Send from this HD index
asset?: Asset // The asset
amount: BaseAmount // The amount
recipient: Address // The recipient address
memo?: string // Optional memo to pass
}
/**
* Type definition for fee estimate options.
*/
export type FeeEstimateOptions = {
memo?: string // Memo
sender?: string // Sender
}
/**
* Enumeration of fee options.
*/
export enum FeeOption {
Average = 'average',
Fast = 'fast',
Fastest = 'fastest',
}
/**
* Type definition for a fee rate.
*/
export type FeeRate = number
/**
* Type definition for fee rates.
*/
export type FeeRates = Record<FeeOption, FeeRate>
/**
* Enumeration of fee types.
*/
export enum FeeType {
FlatFee = 'base',
PerByte = 'byte',
}
/**
* Type definition for a fee.
*/
export type Fee = BaseAmount
/**
* Type definition for fees.
*/
export type Fees = Record<FeeOption, Fee> & {
type: FeeType // Type of fee
}
/**
* Type definition for fees with rates.
*/
export type FeesWithRates = { rates: FeeRates; fees: Fees }
/**
* Type definition for fee bounds.
*/
export type FeeBounds = { lower: number; upper: number }
/**
* Type definition for root derivation paths.
*/
export type RootDerivationPaths = Record<Network, string>
/**
* Type definition for parameters used to configure an XChain client.
*/
export type XChainClientParams = {
network?: Network // Network type
phrase?: string // Phrase
feeBounds?: FeeBounds // Fee bounds
rootDerivationPaths?: RootDerivationPaths // Root derivation paths
}
/**
* Type definition for a prepared transaction.
*/
export type PreparedTx = {
rawUnsignedTx: string // Raw unsigned transaction
}
/**
* Interface for an XChain client.
*/
export interface XChainClient {
setNetwork(net: Network): void // Set network
getNetwork(): Network // Get network
getExplorerUrl(): string // Get explorer URL
getExplorerAddressUrl(address: Address): string // Get explorer address URL
getExplorerTxUrl(txID: string): string // Get explorer transaction URL
validateAddress(address: string): boolean // Validate address
getAddress(walletIndex?: number): Address // Get address
getAddressAsync(walletIndex?: number): Promise<Address> // Get address asynchronously
setPhrase(phrase: string, walletIndex: number): Address // Set phrase
getBalance(address: Address, assets?: Asset[]): Promise<Balance[]> // Get balance
getTransactions(params?: TxHistoryParams): Promise<TxsPage> // Get transactions
getTransactionData(txId: string, assetAddress?: Address): Promise<Tx> // Get transaction data
getFees(options?: FeeEstimateOptions): Promise<Fees> // Get fees
transfer(params: TxParams): Promise<TxHash> // Transfer
prepareTx(params: TxParams): Promise<PreparedTx> // Prepare transaction
broadcastTx(txHex: string): Promise<TxHash> // Broadcast transaction
purgeClient(): void // Purge client
getAssetInfo(): AssetInfo // Get native asset info
}