@stablechain/sdk 0.1.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.
- package/dist/index.cjs +893 -0
- package/dist/index.d.cts +169 -0
- package/dist/index.d.ts +169 -0
- package/dist/index.js +893 -0
- package/package.json +42 -0
package/dist/index.d.cts
ADDED
|
@@ -0,0 +1,169 @@
|
|
|
1
|
+
import { Account, Transport, WalletClient, Address, BaseError } from 'viem';
|
|
2
|
+
|
|
3
|
+
interface StableConfig {
|
|
4
|
+
/** Target network — defaults to Network.Mainnet */
|
|
5
|
+
network?: Network;
|
|
6
|
+
/** Optional RPC override — defaults to the public RPC for the selected network */
|
|
7
|
+
rpc?: string;
|
|
8
|
+
/** Server-side signing: pass a viem Account, e.g. privateKeyToAccount("0x...") */
|
|
9
|
+
account?: Account;
|
|
10
|
+
/** Browser-wallet signing: pass a viem Transport, e.g. custom(window.ethereum) */
|
|
11
|
+
transport?: Transport;
|
|
12
|
+
/** Pre-configured viem WalletClient — takes precedence over account/transport. */
|
|
13
|
+
walletClient?: WalletClient;
|
|
14
|
+
}
|
|
15
|
+
/**
|
|
16
|
+
* Unified result for transfer, bridge, and swap.
|
|
17
|
+
* `toAmount` is the destination-side amount in human units; omitted when no
|
|
18
|
+
* conversion happens (e.g. a same-asset transfer).
|
|
19
|
+
*/
|
|
20
|
+
interface OperationResult {
|
|
21
|
+
txHash: string;
|
|
22
|
+
toAmount?: number;
|
|
23
|
+
}
|
|
24
|
+
interface TransferParams {
|
|
25
|
+
from: string;
|
|
26
|
+
to: string;
|
|
27
|
+
amount: number;
|
|
28
|
+
/** ERC-20 token address. Omit to transfer native USDT0. */
|
|
29
|
+
token?: string;
|
|
30
|
+
/** Token decimals — fetched on-chain when omitted */
|
|
31
|
+
tokenDecimals?: number;
|
|
32
|
+
}
|
|
33
|
+
interface SwapParams {
|
|
34
|
+
/** Token address or symbol to swap from */
|
|
35
|
+
fromToken: string;
|
|
36
|
+
/** Token address or symbol to swap to */
|
|
37
|
+
toToken: string;
|
|
38
|
+
/** Human-readable amount */
|
|
39
|
+
amount: number;
|
|
40
|
+
/** Decimals of the source token (default: 6 for USDT0) */
|
|
41
|
+
fromDecimals?: number;
|
|
42
|
+
/** Recipient address — defaults to the signer */
|
|
43
|
+
toAddress?: string;
|
|
44
|
+
/** Pre-fetched quote from quoteSwap(). When provided, swap() skips the LI.FI quote call. */
|
|
45
|
+
quote?: SwapQuote;
|
|
46
|
+
}
|
|
47
|
+
interface SwapQuote {
|
|
48
|
+
/** Expected output amount (human-readable, formatted with toToken decimals) */
|
|
49
|
+
toAmount: number;
|
|
50
|
+
/** Source amount in raw units (used for ERC-20 approval) */
|
|
51
|
+
fromAmount: bigint;
|
|
52
|
+
/** Source token address — the ERC-20 to approve (or native sentinel) */
|
|
53
|
+
fromToken: string;
|
|
54
|
+
/** ERC-20 spender that needs approval — omitted for native sources */
|
|
55
|
+
approvalAddress?: string;
|
|
56
|
+
/** Pre-built transaction to execute */
|
|
57
|
+
transactionRequest: {
|
|
58
|
+
to: string;
|
|
59
|
+
data: string;
|
|
60
|
+
value: string;
|
|
61
|
+
gasLimit: string;
|
|
62
|
+
chainId: number;
|
|
63
|
+
};
|
|
64
|
+
}
|
|
65
|
+
declare enum Chain {
|
|
66
|
+
Sepolia = "sepolia",
|
|
67
|
+
StableTestnet = "stable-testnet",
|
|
68
|
+
Stable = "stable",
|
|
69
|
+
Ethereum = "ethereum",
|
|
70
|
+
Arbitrum = "arbitrum",
|
|
71
|
+
Ink = "ink",
|
|
72
|
+
Bera = "bera",
|
|
73
|
+
MegaETH = "megaeth",
|
|
74
|
+
Base = "base",
|
|
75
|
+
BSC = "bsc",
|
|
76
|
+
HyperEVM = "hyperevm"
|
|
77
|
+
}
|
|
78
|
+
declare enum Network {
|
|
79
|
+
Mainnet = "mainnet",
|
|
80
|
+
Testnet = "testnet"
|
|
81
|
+
}
|
|
82
|
+
interface BridgeQuote {
|
|
83
|
+
/** Estimated output amount on the destination chain */
|
|
84
|
+
toAmount?: number;
|
|
85
|
+
/** LayerZero native fee — only present for USDT0→USDT0 routes */
|
|
86
|
+
nativeFee?: bigint;
|
|
87
|
+
lzTokenFee?: bigint;
|
|
88
|
+
}
|
|
89
|
+
interface BridgeParams {
|
|
90
|
+
fromChain: Chain;
|
|
91
|
+
toChain: Chain;
|
|
92
|
+
/** Source token contract address */
|
|
93
|
+
fromToken: string;
|
|
94
|
+
/** Destination token contract address */
|
|
95
|
+
toToken: string;
|
|
96
|
+
amount: number;
|
|
97
|
+
/** Source token decimals (default: 6) */
|
|
98
|
+
fromDecimals?: number;
|
|
99
|
+
/** Recipient address — defaults to the signer */
|
|
100
|
+
recipient?: string;
|
|
101
|
+
/** Pre-fetched quote from quoteBridge() — skips the LayerZero quoteSend for USDT0 routes */
|
|
102
|
+
quote?: BridgeQuote;
|
|
103
|
+
}
|
|
104
|
+
|
|
105
|
+
interface StableClient {
|
|
106
|
+
transfer(params: TransferParams): Promise<OperationResult>;
|
|
107
|
+
quoteBridge(params: BridgeParams): Promise<BridgeQuote>;
|
|
108
|
+
bridge(params: BridgeParams): Promise<OperationResult>;
|
|
109
|
+
quoteSwap(params: SwapParams): Promise<SwapQuote>;
|
|
110
|
+
swap(params: SwapParams): Promise<OperationResult>;
|
|
111
|
+
}
|
|
112
|
+
declare function createStable({ network, rpc: rpcOverride, account, transport, walletClient, }: StableConfig): StableClient;
|
|
113
|
+
|
|
114
|
+
interface ChainConfig {
|
|
115
|
+
id: number;
|
|
116
|
+
rpc: string;
|
|
117
|
+
usdt: Address;
|
|
118
|
+
/** Decimals of the USDT token on this chain */
|
|
119
|
+
decimals: number;
|
|
120
|
+
}
|
|
121
|
+
declare const CHAIN_CONFIGS: Partial<Record<Chain, ChainConfig>>;
|
|
122
|
+
|
|
123
|
+
declare class StableError extends BaseError {
|
|
124
|
+
}
|
|
125
|
+
declare class StableValidationError extends StableError {
|
|
126
|
+
field: string;
|
|
127
|
+
value: unknown;
|
|
128
|
+
constructor(field: string, value: unknown, reason: string, opts?: {
|
|
129
|
+
cause?: Error;
|
|
130
|
+
});
|
|
131
|
+
}
|
|
132
|
+
declare class StableQuoteError extends StableError {
|
|
133
|
+
provider: "layerzero" | "lifi";
|
|
134
|
+
httpStatus?: number;
|
|
135
|
+
providerCode?: string;
|
|
136
|
+
body?: unknown;
|
|
137
|
+
constructor(args: {
|
|
138
|
+
provider: "layerzero" | "lifi";
|
|
139
|
+
shortMessage: string;
|
|
140
|
+
httpStatus?: number;
|
|
141
|
+
providerCode?: string;
|
|
142
|
+
body?: unknown;
|
|
143
|
+
cause?: Error;
|
|
144
|
+
});
|
|
145
|
+
}
|
|
146
|
+
declare class StableTransactionError extends StableError {
|
|
147
|
+
phase: "approve" | "send" | "receipt" | "switch_chain";
|
|
148
|
+
txHash?: `0x${string}`;
|
|
149
|
+
chainId?: number;
|
|
150
|
+
revertReason?: string;
|
|
151
|
+
constructor(args: {
|
|
152
|
+
phase: "approve" | "send" | "receipt" | "switch_chain";
|
|
153
|
+
shortMessage: string;
|
|
154
|
+
txHash?: `0x${string}`;
|
|
155
|
+
chainId?: number;
|
|
156
|
+
revertReason?: string;
|
|
157
|
+
cause?: Error;
|
|
158
|
+
});
|
|
159
|
+
}
|
|
160
|
+
declare class StableNetworkError extends StableError {
|
|
161
|
+
url?: string;
|
|
162
|
+
constructor(args: {
|
|
163
|
+
shortMessage: string;
|
|
164
|
+
url?: string;
|
|
165
|
+
cause?: Error;
|
|
166
|
+
});
|
|
167
|
+
}
|
|
168
|
+
|
|
169
|
+
export { type BridgeParams, type BridgeQuote, CHAIN_CONFIGS, Chain, type ChainConfig, Network, type OperationResult, type StableClient, type StableConfig, StableError, StableNetworkError, StableQuoteError, StableTransactionError, StableValidationError, type SwapParams, type SwapQuote, type TransferParams, createStable };
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,169 @@
|
|
|
1
|
+
import { Account, Transport, WalletClient, Address, BaseError } from 'viem';
|
|
2
|
+
|
|
3
|
+
interface StableConfig {
|
|
4
|
+
/** Target network — defaults to Network.Mainnet */
|
|
5
|
+
network?: Network;
|
|
6
|
+
/** Optional RPC override — defaults to the public RPC for the selected network */
|
|
7
|
+
rpc?: string;
|
|
8
|
+
/** Server-side signing: pass a viem Account, e.g. privateKeyToAccount("0x...") */
|
|
9
|
+
account?: Account;
|
|
10
|
+
/** Browser-wallet signing: pass a viem Transport, e.g. custom(window.ethereum) */
|
|
11
|
+
transport?: Transport;
|
|
12
|
+
/** Pre-configured viem WalletClient — takes precedence over account/transport. */
|
|
13
|
+
walletClient?: WalletClient;
|
|
14
|
+
}
|
|
15
|
+
/**
|
|
16
|
+
* Unified result for transfer, bridge, and swap.
|
|
17
|
+
* `toAmount` is the destination-side amount in human units; omitted when no
|
|
18
|
+
* conversion happens (e.g. a same-asset transfer).
|
|
19
|
+
*/
|
|
20
|
+
interface OperationResult {
|
|
21
|
+
txHash: string;
|
|
22
|
+
toAmount?: number;
|
|
23
|
+
}
|
|
24
|
+
interface TransferParams {
|
|
25
|
+
from: string;
|
|
26
|
+
to: string;
|
|
27
|
+
amount: number;
|
|
28
|
+
/** ERC-20 token address. Omit to transfer native USDT0. */
|
|
29
|
+
token?: string;
|
|
30
|
+
/** Token decimals — fetched on-chain when omitted */
|
|
31
|
+
tokenDecimals?: number;
|
|
32
|
+
}
|
|
33
|
+
interface SwapParams {
|
|
34
|
+
/** Token address or symbol to swap from */
|
|
35
|
+
fromToken: string;
|
|
36
|
+
/** Token address or symbol to swap to */
|
|
37
|
+
toToken: string;
|
|
38
|
+
/** Human-readable amount */
|
|
39
|
+
amount: number;
|
|
40
|
+
/** Decimals of the source token (default: 6 for USDT0) */
|
|
41
|
+
fromDecimals?: number;
|
|
42
|
+
/** Recipient address — defaults to the signer */
|
|
43
|
+
toAddress?: string;
|
|
44
|
+
/** Pre-fetched quote from quoteSwap(). When provided, swap() skips the LI.FI quote call. */
|
|
45
|
+
quote?: SwapQuote;
|
|
46
|
+
}
|
|
47
|
+
interface SwapQuote {
|
|
48
|
+
/** Expected output amount (human-readable, formatted with toToken decimals) */
|
|
49
|
+
toAmount: number;
|
|
50
|
+
/** Source amount in raw units (used for ERC-20 approval) */
|
|
51
|
+
fromAmount: bigint;
|
|
52
|
+
/** Source token address — the ERC-20 to approve (or native sentinel) */
|
|
53
|
+
fromToken: string;
|
|
54
|
+
/** ERC-20 spender that needs approval — omitted for native sources */
|
|
55
|
+
approvalAddress?: string;
|
|
56
|
+
/** Pre-built transaction to execute */
|
|
57
|
+
transactionRequest: {
|
|
58
|
+
to: string;
|
|
59
|
+
data: string;
|
|
60
|
+
value: string;
|
|
61
|
+
gasLimit: string;
|
|
62
|
+
chainId: number;
|
|
63
|
+
};
|
|
64
|
+
}
|
|
65
|
+
declare enum Chain {
|
|
66
|
+
Sepolia = "sepolia",
|
|
67
|
+
StableTestnet = "stable-testnet",
|
|
68
|
+
Stable = "stable",
|
|
69
|
+
Ethereum = "ethereum",
|
|
70
|
+
Arbitrum = "arbitrum",
|
|
71
|
+
Ink = "ink",
|
|
72
|
+
Bera = "bera",
|
|
73
|
+
MegaETH = "megaeth",
|
|
74
|
+
Base = "base",
|
|
75
|
+
BSC = "bsc",
|
|
76
|
+
HyperEVM = "hyperevm"
|
|
77
|
+
}
|
|
78
|
+
declare enum Network {
|
|
79
|
+
Mainnet = "mainnet",
|
|
80
|
+
Testnet = "testnet"
|
|
81
|
+
}
|
|
82
|
+
interface BridgeQuote {
|
|
83
|
+
/** Estimated output amount on the destination chain */
|
|
84
|
+
toAmount?: number;
|
|
85
|
+
/** LayerZero native fee — only present for USDT0→USDT0 routes */
|
|
86
|
+
nativeFee?: bigint;
|
|
87
|
+
lzTokenFee?: bigint;
|
|
88
|
+
}
|
|
89
|
+
interface BridgeParams {
|
|
90
|
+
fromChain: Chain;
|
|
91
|
+
toChain: Chain;
|
|
92
|
+
/** Source token contract address */
|
|
93
|
+
fromToken: string;
|
|
94
|
+
/** Destination token contract address */
|
|
95
|
+
toToken: string;
|
|
96
|
+
amount: number;
|
|
97
|
+
/** Source token decimals (default: 6) */
|
|
98
|
+
fromDecimals?: number;
|
|
99
|
+
/** Recipient address — defaults to the signer */
|
|
100
|
+
recipient?: string;
|
|
101
|
+
/** Pre-fetched quote from quoteBridge() — skips the LayerZero quoteSend for USDT0 routes */
|
|
102
|
+
quote?: BridgeQuote;
|
|
103
|
+
}
|
|
104
|
+
|
|
105
|
+
interface StableClient {
|
|
106
|
+
transfer(params: TransferParams): Promise<OperationResult>;
|
|
107
|
+
quoteBridge(params: BridgeParams): Promise<BridgeQuote>;
|
|
108
|
+
bridge(params: BridgeParams): Promise<OperationResult>;
|
|
109
|
+
quoteSwap(params: SwapParams): Promise<SwapQuote>;
|
|
110
|
+
swap(params: SwapParams): Promise<OperationResult>;
|
|
111
|
+
}
|
|
112
|
+
declare function createStable({ network, rpc: rpcOverride, account, transport, walletClient, }: StableConfig): StableClient;
|
|
113
|
+
|
|
114
|
+
interface ChainConfig {
|
|
115
|
+
id: number;
|
|
116
|
+
rpc: string;
|
|
117
|
+
usdt: Address;
|
|
118
|
+
/** Decimals of the USDT token on this chain */
|
|
119
|
+
decimals: number;
|
|
120
|
+
}
|
|
121
|
+
declare const CHAIN_CONFIGS: Partial<Record<Chain, ChainConfig>>;
|
|
122
|
+
|
|
123
|
+
declare class StableError extends BaseError {
|
|
124
|
+
}
|
|
125
|
+
declare class StableValidationError extends StableError {
|
|
126
|
+
field: string;
|
|
127
|
+
value: unknown;
|
|
128
|
+
constructor(field: string, value: unknown, reason: string, opts?: {
|
|
129
|
+
cause?: Error;
|
|
130
|
+
});
|
|
131
|
+
}
|
|
132
|
+
declare class StableQuoteError extends StableError {
|
|
133
|
+
provider: "layerzero" | "lifi";
|
|
134
|
+
httpStatus?: number;
|
|
135
|
+
providerCode?: string;
|
|
136
|
+
body?: unknown;
|
|
137
|
+
constructor(args: {
|
|
138
|
+
provider: "layerzero" | "lifi";
|
|
139
|
+
shortMessage: string;
|
|
140
|
+
httpStatus?: number;
|
|
141
|
+
providerCode?: string;
|
|
142
|
+
body?: unknown;
|
|
143
|
+
cause?: Error;
|
|
144
|
+
});
|
|
145
|
+
}
|
|
146
|
+
declare class StableTransactionError extends StableError {
|
|
147
|
+
phase: "approve" | "send" | "receipt" | "switch_chain";
|
|
148
|
+
txHash?: `0x${string}`;
|
|
149
|
+
chainId?: number;
|
|
150
|
+
revertReason?: string;
|
|
151
|
+
constructor(args: {
|
|
152
|
+
phase: "approve" | "send" | "receipt" | "switch_chain";
|
|
153
|
+
shortMessage: string;
|
|
154
|
+
txHash?: `0x${string}`;
|
|
155
|
+
chainId?: number;
|
|
156
|
+
revertReason?: string;
|
|
157
|
+
cause?: Error;
|
|
158
|
+
});
|
|
159
|
+
}
|
|
160
|
+
declare class StableNetworkError extends StableError {
|
|
161
|
+
url?: string;
|
|
162
|
+
constructor(args: {
|
|
163
|
+
shortMessage: string;
|
|
164
|
+
url?: string;
|
|
165
|
+
cause?: Error;
|
|
166
|
+
});
|
|
167
|
+
}
|
|
168
|
+
|
|
169
|
+
export { type BridgeParams, type BridgeQuote, CHAIN_CONFIGS, Chain, type ChainConfig, Network, type OperationResult, type StableClient, type StableConfig, StableError, StableNetworkError, StableQuoteError, StableTransactionError, StableValidationError, type SwapParams, type SwapQuote, type TransferParams, createStable };
|