Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ export 'general/wallet_info.dart';
export 'hd_wallet/account_balance_info.dart';
export 'hd_wallet/address_info.dart';
export 'hd_wallet/derivation_method.dart';
export 'lightning/channel_info.dart';
export 'networks/lightning/activation_params.dart';
export 'networks/lightning/channel/channels_index.dart';
export 'networks/lightning/channel/lightning_channel_amount.dart';
Expand All @@ -49,8 +50,13 @@ export 'nft/nft_metadata.dart';
export 'nft/nft_transfer.dart';
export 'nft/nft_transfer_filter.dart';
export 'nft/withdraw_nft_data.dart';
export 'orderbook/order_info.dart';
export 'orderbook/order_type.dart';
export 'pagination/history_target.dart';
export 'pagination/pagination.dart';
export 'primitive/numeric_value.dart';
export 'trading/order_status.dart';
export 'trading/swap_info.dart';
export 'trading/swap_method.dart';
export 'transaction_history/transaction_info.dart';
export 'transaction_history/transaction_sync_status.dart';
Original file line number Diff line number Diff line change
@@ -0,0 +1,133 @@
import 'package:komodo_defi_types/komodo_defi_type_utils.dart';

/// Represents information about a Lightning Network channel.
///
/// This class encapsulates all the essential details about a Lightning channel,
/// including its capacity, balance distribution, and operational status.
class ChannelInfo {
/// Creates a new [ChannelInfo] instance.
///
/// All parameters except [closureReason] are required.
///
/// - [channelId]: Unique identifier for the channel
/// - [counterpartyNodeId]: The node ID of the channel counterparty
/// - [fundingTxId]: Transaction ID that funded this channel
/// - [capacity]: Total capacity of the channel in satoshis
/// - [localBalance]: Balance available on the local side in satoshis
/// - [remoteBalance]: Balance available on the remote side in satoshis
/// - [isOutbound]: Whether this is an outbound channel (initiated by us)
/// - [isPublic]: Whether this channel is publicly announced
/// - [isUsable]: Whether this channel can currently be used for payments
/// - [closureReason]: Optional reason if the channel was closed
ChannelInfo({
required this.channelId,
required this.counterpartyNodeId,
required this.fundingTxId,
required this.capacity,
required this.localBalance,
required this.remoteBalance,
required this.isOutbound,
required this.isPublic,
required this.isUsable,
this.closureReason,
});

/// Creates a [ChannelInfo] instance from a JSON map.
///
/// Expects the following keys in the JSON:
/// - `channel_id`: String
/// - `counterparty_node_id`: String
/// - `funding_tx_id`: String
/// - `capacity`: int
/// - `local_balance`: int
/// - `remote_balance`: int
/// - `is_outbound`: bool
/// - `is_public`: bool
/// - `is_usable`: bool
/// - `closure_reason`: String (optional)
factory ChannelInfo.fromJson(JsonMap json) {
return ChannelInfo(
channelId: json.value<String>('channel_id'),
counterpartyNodeId: json.value<String>('counterparty_node_id'),
fundingTxId: json.value<String>('funding_tx_id'),
capacity: json.value<int>('capacity'),
localBalance: json.value<int>('local_balance'),
remoteBalance: json.value<int>('remote_balance'),
isOutbound: json.value<bool>('is_outbound'),
isPublic: json.value<bool>('is_public'),
isUsable: json.value<bool>('is_usable'),
closureReason: json.valueOrNull<String?>('closure_reason'),
);
}

/// Unique identifier for this Lightning channel.
///
/// This is typically a 64-character hex string that uniquely identifies
/// the channel on the Lightning Network.
final String channelId;

/// The public key/node ID of the channel counterparty.
///
/// This identifies the other participant in this channel.
final String counterpartyNodeId;

/// The transaction ID of the funding transaction that opened this channel.
///
/// This links the channel to its on-chain funding transaction.
final String fundingTxId;

/// Total capacity of the channel in satoshis.
///
/// This is the sum of [localBalance] and [remoteBalance], representing
/// the total amount that was locked when the channel was opened.
final int capacity;

/// Balance available on the local side of the channel in satoshis.
///
/// This is the amount that can be sent through this channel.
final int localBalance;

/// Balance available on the remote side of the channel in satoshis.
///
/// This is the amount that can be received through this channel.
final int remoteBalance;

/// Whether this is an outbound channel.
///
/// `true` if we initiated the channel opening, `false` if the counterparty did.
final bool isOutbound;

/// Whether this channel is publicly announced on the Lightning Network.
///
/// Public channels can be used for routing payments for other nodes.
final bool isPublic;

/// Whether this channel is currently usable for payments.
///
/// A channel might be unusable if it's closing, has insufficient balance,
/// or if there are connectivity issues with the counterparty.
final bool isUsable;

/// Optional reason for channel closure.
///
/// Only present if the channel has been closed. Contains a human-readable
/// description of why the channel was closed.
final String? closureReason;

/// Converts this [ChannelInfo] instance to a JSON map.
///
/// The resulting map can be serialized to JSON and will contain all
/// the channel information in the expected format.
Map<String, dynamic> toJson() => {
'channel_id': channelId,
'counterparty_node_id': counterpartyNodeId,
'funding_tx_id': fundingTxId,
'capacity': capacity,
'local_balance': localBalance,
'remote_balance': remoteBalance,
'is_outbound': isOutbound,
'is_public': isPublic,
'is_usable': isUsable,
if (closureReason != null) 'closure_reason': closureReason,
};
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,128 @@
import 'package:komodo_defi_types/komodo_defi_type_utils.dart';

/// Represents information about an order in the orderbook.
///
/// This class contains all the essential details about a trading order,
/// including pricing, volume constraints, and metadata about the order creator.
/// It's used to represent both bid and ask orders in orderbook responses.
class OrderInfo {
/// Creates a new [OrderInfo] instance.
///
/// All parameters are required and represent core order attributes:
/// - [uuid]: Unique identifier for the order
/// - [price]: The price per unit in rel coin
/// - [maxVolume]: Maximum volume available for this order
/// - [minVolume]: Minimum volume that must be traded
/// - [pubkey]: Public key of the order creator
/// - [age]: Age of the order in seconds
/// - [zcredits]: Zero-knowledge credits associated with the order
/// - [coin]: The coin being offered in this order
/// - [address]: The address associated with this order
OrderInfo({
required this.uuid,
required this.price,
required this.maxVolume,
required this.minVolume,
required this.pubkey,
required this.age,
required this.zcredits,
required this.coin,
required this.address,
});

/// Creates an [OrderInfo] instance from a JSON map.
///
/// Expects the following keys in the JSON:
/// - `uuid`: String - Unique order identifier
/// - `price`: String - Price per unit
/// - `max_volume`: String - Maximum tradeable volume
/// - `min_volume`: String - Minimum tradeable volume
/// - `pubkey`: String - Order creator's public key
/// - `age`: int - Order age in seconds
/// - `zcredits`: int - Zero-knowledge credits
/// - `coin`: String - Coin ticker
/// - `address`: String - Associated address
factory OrderInfo.fromJson(JsonMap json) {
return OrderInfo(
uuid: json.value<String>('uuid'),
price: json.value<String>('price'),
maxVolume: json.value<String>('max_volume'),
minVolume: json.value<String>('min_volume'),
pubkey: json.value<String>('pubkey'),
age: json.value<int>('age'),
zcredits: json.value<int>('zcredits'),
coin: json.value<String>('coin'),
address: json.value<String>('address'),
);
}

/// Unique identifier for this order.
///
/// This UUID is used to reference the order in subsequent operations
/// such as order matching or cancellation.
final String uuid;

/// The price per unit for this order.
///
/// Expressed as a string to maintain precision. This represents the
/// exchange rate between the base and rel coins.
final String price;

/// Maximum volume available for trading in this order.
///
/// This is the total amount of the coin that can be traded through
/// this order. Expressed as a string to maintain precision.
final String maxVolume;

/// Minimum volume that must be traded.
///
/// Orders cannot be partially filled below this threshold. This helps
/// prevent dust trades and ensures economically viable transactions.
/// Expressed as a string to maintain precision.
final String minVolume;

/// Public key of the order creator.
///
/// This identifies the node that created the order and is used for
/// P2P communication during swap negotiation.
final String pubkey;

/// Age of the order in seconds.
///
/// Indicates how long ago this order was created. Useful for sorting
/// orders by recency or implementing time-based order preferences.
final int age;

/// Zero-knowledge credits associated with this order.
///
/// Used in privacy-enhanced trading to manage reputation and trading
/// privileges without revealing identity.
final int zcredits;

/// The coin ticker for this order.
///
/// Identifies which coin is being offered in this order.
final String coin;

/// The address associated with this order.
///
/// This is typically the address that will receive funds in a swap
/// involving this order.
final String address;

/// Converts this [OrderInfo] instance to a JSON map.
///
/// The resulting map can be serialized to JSON and will contain all
/// the order information in the expected API format.
Map<String, dynamic> toJson() => {
'uuid': uuid,
'price': price,
'max_volume': maxVolume,
'min_volume': minVolume,
'pubkey': pubkey,
'age': age,
'zcredits': zcredits,
'coin': coin,
'address': address,
};
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
/// Defines the types of orders in trading operations.
///
/// This enum represents whether an order is a buy order or a sell order,
/// which determines the direction of the trade from the perspective of
/// the order creator.
enum OrderType {
/// Represents a buy order.
///
/// The order creator wants to buy the base coin using the rel coin.
/// In a BTC/USDT pair, a buy order means buying BTC with USDT.
buy,

/// Represents a sell order.
///
/// The order creator wants to sell the base coin for the rel coin.
/// In a BTC/USDT pair, a sell order means selling BTC for USDT.
sell;

/// Converts this [OrderType] to its JSON string representation.
///
/// Returns the lowercase string name of the enum value.
/// - `buy` → `"buy"`
/// - `sell` → `"sell"`
String toJson() => name;
}

/// Represents a trading pair in the orderbook.
///
/// This class defines a pair of coins that can be traded against each other,
/// with a base coin and a rel (relative/quote) coin. The convention follows
/// traditional trading pairs where BASE/REL represents trading BASE for REL.
class OrderbookPair {
/// Creates a new [OrderbookPair] instance.
///
/// - [base]: The base coin in the trading pair (what you're buying/selling)
/// - [rel]: The rel/quote coin in the trading pair (what you're paying with/receiving)
OrderbookPair({
required this.base,
required this.rel,
});

/// The base coin in the trading pair.
///
/// This is the coin being bought or sold. In a BTC/USDT pair,
/// BTC would be the base coin.
final String base;

/// The rel (relative/quote) coin in the trading pair.
///
/// This is the coin used to price the base coin. In a BTC/USDT pair,
/// USDT would be the rel coin.
final String rel;

/// Converts this [OrderbookPair] instance to a JSON map.
///
/// Returns a map with `base` and `rel` keys containing the respective
/// coin tickers.
Map<String, dynamic> toJson() => {
'base': base,
'rel': rel,
};
}
Loading
Loading