@leather.io/models 0.10.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,19 @@
1
+ import type BigNumber from 'bignumber.js';
2
+
3
+ export interface AverageBitcoinFeeRates {
4
+ fastestFee: BigNumber;
5
+ halfHourFee: BigNumber;
6
+ hourFee: BigNumber;
7
+ }
8
+
9
+ export const btcTxTimeMap: Record<keyof AverageBitcoinFeeRates, string> = {
10
+ fastestFee: '~10 – 20min',
11
+ halfHourFee: '~30 min',
12
+ hourFee: '~1 hour+',
13
+ };
14
+
15
+ export enum BtcFeeType {
16
+ High = 'High',
17
+ Standard = 'Standard',
18
+ Low = 'Low',
19
+ }
@@ -0,0 +1,23 @@
1
+ import { Blockchains } from '../types';
2
+ import { StacksFeeEstimate } from './stacks-fees.model';
3
+
4
+ export enum FeeTypes {
5
+ Low,
6
+ Middle,
7
+ High,
8
+ Custom,
9
+ Unknown,
10
+ }
11
+
12
+ export enum FeeCalculationTypes {
13
+ Api = 'api',
14
+ Default = 'default',
15
+ DefaultSimulated = 'default-simulated',
16
+ FeesCapped = 'fees-capped',
17
+ }
18
+
19
+ export interface Fees {
20
+ blockchain: Blockchains;
21
+ estimates: StacksFeeEstimate[];
22
+ calculation: FeeCalculationTypes;
23
+ }
@@ -0,0 +1,6 @@
1
+ import { Money } from '../money.model';
2
+
3
+ export interface StacksFeeEstimate {
4
+ fee: Money;
5
+ feeRate: number;
6
+ }
package/src/index.ts ADDED
@@ -0,0 +1,15 @@
1
+ export * from './crypto-assets/crypto-asset-balance.model';
2
+ export * from './crypto-assets/crypto-asset-info.model';
3
+ export * from './crypto-assets/bitcoin/inscription.model';
4
+ export * from './currencies.model';
5
+ export * from './fees/bitcoin-fees.model';
6
+ export * from './fees/fees.model';
7
+ export * from './fees/stacks-fees.model';
8
+ export * from './market.model';
9
+ export * from './types';
10
+ export * from './types.utils';
11
+ export * from './money.model';
12
+ export * from './network.model';
13
+ export * from './transactions/bitcoin-transaction.model';
14
+ export * from './transactions/stacks-transaction.model';
15
+ export * from './utxo.model';
@@ -0,0 +1,26 @@
1
+ import type { CryptoCurrencies, FiatCurrencies } from './currencies.model';
2
+ import type { Money } from './money.model';
3
+
4
+ interface MarketPair {
5
+ readonly base: CryptoCurrencies;
6
+ readonly quote: FiatCurrencies;
7
+ }
8
+
9
+ export function createMarketPair(base: CryptoCurrencies, quote: FiatCurrencies): MarketPair {
10
+ return Object.freeze({ base, quote });
11
+ }
12
+
13
+ export function formatMarketPair({ base, quote }: MarketPair) {
14
+ return `${base}/${quote}`;
15
+ }
16
+
17
+ export interface MarketData {
18
+ readonly pair: MarketPair;
19
+ readonly price: Money;
20
+ }
21
+
22
+ export function createMarketData(pair: MarketPair, price: Money): MarketData {
23
+ if (pair.quote !== price.symbol)
24
+ throw new Error('Cannot create market data when price does not match quote');
25
+ return Object.freeze({ pair, price });
26
+ }
@@ -0,0 +1,11 @@
1
+ import type BigNumber from 'bignumber.js';
2
+
3
+ import type { Currencies } from './currencies.model';
4
+
5
+ export type NumType = BigNumber | bigint | number;
6
+
7
+ export interface Money {
8
+ readonly amount: BigNumber;
9
+ readonly symbol: Currencies;
10
+ readonly decimals: number;
11
+ }
@@ -0,0 +1,169 @@
1
+ import { Blockchains } from './types';
2
+
3
+ export const HIRO_API_BASE_URL_MAINNET = 'https://api.hiro.so';
4
+ export const HIRO_API_BASE_URL_TESTNET = 'https://api.testnet.hiro.so';
5
+ export const HIRO_INSCRIPTIONS_API_URL = 'https://api.hiro.so/ordinals/v1/inscriptions';
6
+ export const HIRO_API_BASE_URL_NAKAMOTO_TESTNET = 'https://api.nakamoto.testnet.hiro.so';
7
+
8
+ export const BITCOIN_API_BASE_URL_MAINNET = 'https://blockstream.info/api';
9
+ export const BITCOIN_API_BASE_URL_TESTNET = 'https://blockstream.info/testnet/api';
10
+ export const BITCOIN_API_BASE_URL_SIGNET = 'https://mempool.space/signet/api';
11
+
12
+ export const BESTINSLOT_API_BASE_URL_MAINNET = 'https://leatherapi.bestinslot.xyz/v3';
13
+ export const BESTINSLOT_API_BASE_URL_TESTNET = 'https://leatherapi_testnet.bestinslot.xyz/v3';
14
+
15
+ export const STX20_API_BASE_URL_MAINNET = 'https://api.stx20.com/api/v1';
16
+
17
+ // Copied from @stacks/transactions to avoid dependencies
18
+ export enum ChainID {
19
+ Testnet = 2147483648,
20
+ Mainnet = 1,
21
+ }
22
+
23
+ export enum WalletDefaultNetworkConfigurationIds {
24
+ mainnet = 'mainnet',
25
+ testnet = 'testnet',
26
+ signet = 'signet',
27
+ sbtcDevenv = 'sbtcDevenv',
28
+ devnet = 'devnet',
29
+ }
30
+
31
+ export type DefaultNetworkConfigurations = keyof typeof WalletDefaultNetworkConfigurationIds;
32
+
33
+ const supportedBlockchains = ['stacks', 'bitcoin'] as const;
34
+
35
+ export type SupportedBlockchains = (typeof supportedBlockchains)[number];
36
+
37
+ const networkModes = ['mainnet', 'testnet'] as const;
38
+
39
+ export type NetworkModes = (typeof networkModes)[number];
40
+
41
+ type BitcoinTestnetModes = 'testnet' | 'regtest' | 'signet';
42
+
43
+ export type BitcoinNetworkModes = NetworkModes | BitcoinTestnetModes;
44
+
45
+ interface BaseChainConfig {
46
+ blockchain: Blockchains;
47
+ }
48
+
49
+ export interface BitcoinChainConfig extends BaseChainConfig {
50
+ blockchain: 'bitcoin';
51
+ bitcoinUrl: string;
52
+ bitcoinNetwork: BitcoinNetworkModes;
53
+ }
54
+
55
+ export interface StacksChainConfig extends BaseChainConfig {
56
+ blockchain: 'stacks';
57
+ url: string;
58
+ /** The chainId of the network (or parent network if this is a subnet) */
59
+ chainId: ChainID;
60
+ /** An additional chainId for subnets. Indicated a subnet if defined and is mainly used for signing. */
61
+ subnetChainId?: ChainID;
62
+ }
63
+
64
+ export interface NetworkConfiguration {
65
+ name: string;
66
+ id: DefaultNetworkConfigurations;
67
+ chain: {
68
+ bitcoin: BitcoinChainConfig;
69
+ stacks: StacksChainConfig;
70
+ };
71
+ }
72
+
73
+ const networkMainnet: NetworkConfiguration = {
74
+ id: WalletDefaultNetworkConfigurationIds.mainnet,
75
+ name: 'Mainnet',
76
+ chain: {
77
+ stacks: {
78
+ blockchain: 'stacks',
79
+ chainId: ChainID.Mainnet,
80
+ url: HIRO_API_BASE_URL_MAINNET,
81
+ },
82
+ bitcoin: {
83
+ blockchain: 'bitcoin',
84
+ bitcoinNetwork: 'mainnet',
85
+ bitcoinUrl: BITCOIN_API_BASE_URL_MAINNET,
86
+ },
87
+ },
88
+ };
89
+
90
+ const networkTestnet: NetworkConfiguration = {
91
+ id: WalletDefaultNetworkConfigurationIds.testnet,
92
+ name: 'Testnet',
93
+ chain: {
94
+ stacks: {
95
+ blockchain: 'stacks',
96
+ chainId: ChainID.Testnet,
97
+ url: HIRO_API_BASE_URL_TESTNET,
98
+ },
99
+ bitcoin: {
100
+ blockchain: 'bitcoin',
101
+ bitcoinNetwork: 'testnet',
102
+ bitcoinUrl: BITCOIN_API_BASE_URL_TESTNET,
103
+ },
104
+ },
105
+ };
106
+
107
+ const networkSignet: NetworkConfiguration = {
108
+ id: WalletDefaultNetworkConfigurationIds.signet,
109
+ name: 'Signet',
110
+ chain: {
111
+ stacks: {
112
+ blockchain: 'stacks',
113
+ chainId: ChainID.Testnet,
114
+ url: HIRO_API_BASE_URL_TESTNET,
115
+ },
116
+ bitcoin: {
117
+ blockchain: 'bitcoin',
118
+ bitcoinNetwork: 'signet',
119
+ bitcoinUrl: BITCOIN_API_BASE_URL_SIGNET,
120
+ },
121
+ },
122
+ };
123
+
124
+ const networkSbtcDevenv: NetworkConfiguration = {
125
+ id: WalletDefaultNetworkConfigurationIds.sbtcDevenv,
126
+ name: 'sBTC Devenv',
127
+ chain: {
128
+ stacks: {
129
+ blockchain: 'stacks',
130
+ chainId: ChainID.Testnet,
131
+ url: 'http://localhost:3999',
132
+ },
133
+ bitcoin: {
134
+ blockchain: 'bitcoin',
135
+ bitcoinNetwork: 'regtest',
136
+ bitcoinUrl: 'http://localhost:8999/api',
137
+ },
138
+ },
139
+ };
140
+
141
+ const networkDevnet: NetworkConfiguration = {
142
+ id: WalletDefaultNetworkConfigurationIds.devnet,
143
+ name: 'Devnet',
144
+ chain: {
145
+ stacks: {
146
+ blockchain: 'stacks',
147
+ chainId: ChainID.Testnet,
148
+ url: 'http://localhost:3999',
149
+ },
150
+ bitcoin: {
151
+ blockchain: 'bitcoin',
152
+ bitcoinNetwork: 'regtest',
153
+ bitcoinUrl: 'http://localhost:18443',
154
+ },
155
+ },
156
+ };
157
+
158
+ export const defaultCurrentNetwork: NetworkConfiguration = networkMainnet;
159
+
160
+ export const defaultNetworksKeyedById: Record<
161
+ WalletDefaultNetworkConfigurationIds,
162
+ NetworkConfiguration
163
+ > = {
164
+ [WalletDefaultNetworkConfigurationIds.mainnet]: networkMainnet,
165
+ [WalletDefaultNetworkConfigurationIds.testnet]: networkTestnet,
166
+ [WalletDefaultNetworkConfigurationIds.signet]: networkSignet,
167
+ [WalletDefaultNetworkConfigurationIds.sbtcDevenv]: networkSbtcDevenv,
168
+ [WalletDefaultNetworkConfigurationIds.devnet]: networkDevnet,
169
+ };
@@ -0,0 +1,66 @@
1
+ // Source: https://github.com/Blockstream/esplora/blob/master/API.md#transaction-format
2
+ interface BitcoinTransactionIssuance {
3
+ asset_id: string;
4
+ is_reissuance: boolean;
5
+ asset_blinding_nonce: number;
6
+ asset_entropy: number;
7
+ contract_hash: string;
8
+ assetamount?: number;
9
+ assetamountcommitment?: number;
10
+ tokenamount?: number;
11
+ tokenamountcommitment?: number;
12
+ }
13
+
14
+ interface BitcoinTransactionPegOut {
15
+ genesis_hash: string;
16
+ scriptpubkey: string;
17
+ scriptpubkey_asm: string;
18
+ scriptpubkey_address: string;
19
+ }
20
+
21
+ interface BitcoinTransactionStatus {
22
+ confirmed: boolean;
23
+ block_height?: number | null;
24
+ block_hash?: string | null;
25
+ block_time?: number | null;
26
+ }
27
+
28
+ export interface BitcoinTransactionVectorOutput {
29
+ scriptpubkey: string;
30
+ scriptpubkey_asm: string;
31
+ scriptpubkey_type: string;
32
+ scriptpubkey_address: string;
33
+ value: number;
34
+ valuecommitment?: number;
35
+ asset?: string;
36
+ assetcommitment?: number;
37
+ pegout?: BitcoinTransactionPegOut | null;
38
+ }
39
+
40
+ export interface BitcoinTransactionVectorInput {
41
+ inner_redeemscript_asm?: string;
42
+ inner_witnessscript_asm?: string;
43
+ is_coinbase: boolean;
44
+ is_pegin?: boolean;
45
+ issuance?: BitcoinTransactionIssuance | null;
46
+ prevout: BitcoinTransactionVectorOutput;
47
+ scriptsig: string;
48
+ scriptsig_asm: string;
49
+ sequence: number;
50
+ txid: string;
51
+ vout: number;
52
+ witness: string[];
53
+ }
54
+
55
+ export interface BitcoinTx {
56
+ fee: number;
57
+ locktime: number;
58
+ size: number;
59
+ status: BitcoinTransactionStatus;
60
+ tx_type?: string;
61
+ txid: string;
62
+ version: number;
63
+ vin: BitcoinTransactionVectorInput[];
64
+ vout: BitcoinTransactionVectorOutput[];
65
+ weight: number;
66
+ }
@@ -0,0 +1,17 @@
1
+ import type { MempoolTransaction, Transaction } from '@stacks/stacks-blockchain-api-types';
2
+
3
+ export type StacksTx = MempoolTransaction | Transaction;
4
+ export type StacksTxStatus = 'failed' | 'pending' | 'success';
5
+
6
+ export interface StxTransfer {
7
+ amount: string;
8
+ sender?: string;
9
+ recipient?: string;
10
+ }
11
+
12
+ export interface FtTransfer {
13
+ asset_identifier: string;
14
+ amount: string;
15
+ sender?: string;
16
+ recipient?: string;
17
+ }
package/src/types.ts ADDED
@@ -0,0 +1,15 @@
1
+ import { LiteralUnion } from './types.utils';
2
+
3
+ export type Blockchains = LiteralUnion<'bitcoin' | 'stacks', string>;
4
+
5
+ export type CryptoAssetType =
6
+ | 'btc'
7
+ | 'stx'
8
+ | 'brc-20'
9
+ | 'inscription'
10
+ | 'rune'
11
+ | 'sip-9'
12
+ | 'sip-10'
13
+ | 'src-20'
14
+ | 'stamp'
15
+ | 'stx-20';
@@ -0,0 +1,13 @@
1
+ export type ValueOf<T> = T[keyof T];
2
+
3
+ export interface AllowAdditionalProperties {
4
+ [x: string | number | symbol]: unknown;
5
+ }
6
+
7
+ type Primitive = null | undefined | string | number | boolean | symbol | bigint;
8
+
9
+ export type LiteralUnion<LiteralType, BaseType extends Primitive> =
10
+ | LiteralType
11
+ | (BaseType & Record<never, never>);
12
+
13
+ export type Entries<T> = { [K in keyof T]: [K, T[K]] }[keyof T][];
@@ -0,0 +1,11 @@
1
+ export interface UtxoItem {
2
+ txid: string;
3
+ vout: number;
4
+ status: {
5
+ confirmed: boolean;
6
+ block_height: number;
7
+ block_hash: string;
8
+ block_time: number;
9
+ };
10
+ value: number;
11
+ }
package/tsconfig.json ADDED
@@ -0,0 +1,8 @@
1
+ {
2
+ "extends": ["@leather.io/tsconfig-config/tsconfig.base.json"],
3
+ "include": ["**/*", ".*.ts"],
4
+ "exclude": ["./dist/"],
5
+ "compilerOptions": {
6
+ "outDir": "./dist"
7
+ }
8
+ }
package/tsup.config.ts ADDED
@@ -0,0 +1,9 @@
1
+ import { defineConfig } from 'tsup';
2
+
3
+ export default defineConfig({
4
+ entry: ['src/index.ts'],
5
+ sourcemap: true,
6
+ clean: true,
7
+ dts: true,
8
+ format: 'esm',
9
+ });