-
Notifications
You must be signed in to change notification settings - Fork 18
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
3 changed files
with
205 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,57 @@ | ||
import { AxiosInstance, AxiosResponse } from "axios"; | ||
import { Packet, StatusError, StatusState, TransferInfo } from "../types"; | ||
|
||
export interface StatusRequest { | ||
tx_hash: string; | ||
chain_id: string; | ||
} | ||
|
||
export interface StatusResponse { | ||
status: StatusState; | ||
transfer_sequence: TransferInfo[]; | ||
error?: StatusError; | ||
} | ||
|
||
export interface TrackRequest { | ||
tx_hash: string; | ||
chain_id: string; | ||
} | ||
|
||
export interface TrackResponse { | ||
success: boolean; | ||
tx_hash: string; | ||
} | ||
|
||
export class TransactionService { | ||
private httpClient: AxiosInstance; | ||
|
||
constructor(httpClient: AxiosInstance) { | ||
this.httpClient = httpClient; | ||
} | ||
|
||
async track(txHash: string, chainID: string): Promise<TrackResponse> { | ||
const response = await this.httpClient.post< | ||
TrackResponse, | ||
AxiosResponse<TrackResponse, any>, | ||
TrackRequest | ||
>("/tx/track", { | ||
tx_hash: txHash, | ||
chain_id: chainID, | ||
}); | ||
|
||
return response.data; | ||
} | ||
|
||
async status(txHash: string, chainID: string): Promise<StatusResponse> { | ||
const params: StatusRequest = { | ||
tx_hash: txHash, | ||
chain_id: chainID, | ||
}; | ||
|
||
const response = await this.httpClient.get<StatusResponse>("/tx/status", { | ||
params, | ||
}); | ||
|
||
return response.data; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,147 @@ | ||
export interface Asset { | ||
denom: string; | ||
chain_id: string; | ||
|
||
origin_denom: string; | ||
origin_chain_id: string; | ||
|
||
symbol?: string; | ||
name?: string; | ||
logo_uri?: string; | ||
decimals?: number; | ||
} | ||
|
||
export type AssetWithMetadata = Required<Asset>; | ||
|
||
export interface Chain { | ||
chain_name: string; | ||
chain_id: string; | ||
pfm_enabled: boolean; | ||
cosmos_sdk_version: string; | ||
modules: Record<string, ModuleVersionInfo>; | ||
} | ||
|
||
export interface ChainTransaction { | ||
chain_id: string; | ||
tx_hash: string; | ||
} | ||
|
||
export interface ModuleVersionInfo { | ||
path: string; | ||
version: string; | ||
sum: string; | ||
} | ||
|
||
export type TransferState = | ||
| "TRANSFER_UNKNOWN" | ||
| "TRANSFER_PENDING" | ||
| "TRANSFER_RECEIVED" | ||
| "TRANSFER_SUCCESS" | ||
| "TRANSFER_FAILURE"; | ||
|
||
export interface TransferInfo { | ||
src_chain_id: string; | ||
dst_chain_id: string; | ||
state: TransferState; | ||
packet_txs: Packet; | ||
} | ||
|
||
export interface Packet { | ||
send_tx?: ChainTransaction; | ||
receive_tx?: ChainTransaction; | ||
acknowledge_tx?: ChainTransaction; | ||
timeout_tx?: ChainTransaction; | ||
|
||
error?: PacketError; | ||
} | ||
|
||
export interface PacketError { | ||
code: number; | ||
message: string; | ||
} | ||
|
||
export interface StatusError { | ||
code: number; | ||
message: string; | ||
} | ||
|
||
export type StatusState = | ||
| "STATE_UNKNOWN" | ||
| "STATE_SUBMITTED" | ||
| "STATE_PENDING" | ||
| "STATE_RECEIVED" | ||
| "STATE_COMPLETED" | ||
| "STATE_ABANDONED"; | ||
|
||
export interface SwapVenue { | ||
name: string; | ||
chain_id: string; | ||
} | ||
|
||
export interface SwapOperation { | ||
pool: string; | ||
denom_in: string; | ||
denom_out: string; | ||
} | ||
|
||
export interface SwapExactCoinOut { | ||
swap_venue: SwapVenue; | ||
swap_operations: SwapOperation[]; | ||
swap_amount_out: string; | ||
} | ||
|
||
export interface SwapIn { | ||
swap_venue: SwapVenue; | ||
swap_operations: SwapOperation[]; | ||
swap_amount_in?: string; | ||
} | ||
|
||
export interface Transfer { | ||
port: string; | ||
channel: string; | ||
chain_id: string; | ||
pfm_enabled: boolean; | ||
dest_denom: string; | ||
} | ||
|
||
export interface Swap { | ||
swap_in?: SwapIn; | ||
swap_out?: SwapExactCoinOut; | ||
estimated_affiliate_fee?: string; | ||
} | ||
|
||
export interface OperationWithSwap { | ||
swap: Swap; | ||
transfer: never; | ||
} | ||
|
||
export interface OperationWithTransfer { | ||
swap: never; | ||
transfer: Transfer; | ||
} | ||
|
||
export type Operation = OperationWithSwap | OperationWithTransfer; | ||
|
||
export function isSwapOperation( | ||
operation: Operation | ||
): operation is OperationWithSwap { | ||
return operation.swap !== undefined; | ||
} | ||
|
||
export function isTransferOperation( | ||
operation: Operation | ||
): operation is OperationWithTransfer { | ||
return operation.transfer !== undefined; | ||
} | ||
|
||
export interface Affiliate { | ||
basis_points_fee: string; | ||
address: string; | ||
} | ||
|
||
export interface MultiChainMsg { | ||
chain_id: string; | ||
path: string[]; | ||
msg: string; | ||
msg_type_url: string; | ||
} |