@t402/stacks 2.4.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/README.md +178 -0
- package/dist/exact-direct/client/index.cjs +167 -0
- package/dist/exact-direct/client/index.cjs.map +1 -0
- package/dist/exact-direct/client/index.d.cts +39 -0
- package/dist/exact-direct/client/index.d.ts +39 -0
- package/dist/exact-direct/client/index.mjs +139 -0
- package/dist/exact-direct/client/index.mjs.map +1 -0
- package/dist/exact-direct/facilitator/index.cjs +395 -0
- package/dist/exact-direct/facilitator/index.cjs.map +1 -0
- package/dist/exact-direct/facilitator/index.d.cts +55 -0
- package/dist/exact-direct/facilitator/index.d.ts +55 -0
- package/dist/exact-direct/facilitator/index.mjs +367 -0
- package/dist/exact-direct/facilitator/index.mjs.map +1 -0
- package/dist/exact-direct/server/index.cjs +247 -0
- package/dist/exact-direct/server/index.cjs.map +1 -0
- package/dist/exact-direct/server/index.d.cts +109 -0
- package/dist/exact-direct/server/index.d.ts +109 -0
- package/dist/exact-direct/server/index.mjs +218 -0
- package/dist/exact-direct/server/index.mjs.map +1 -0
- package/dist/index.cjs +261 -0
- package/dist/index.cjs.map +1 -0
- package/dist/index.d.cts +126 -0
- package/dist/index.d.ts +126 -0
- package/dist/index.mjs +212 -0
- package/dist/index.mjs.map +1 -0
- package/dist/types-Bxzo3eQ1.d.cts +172 -0
- package/dist/types-Bxzo3eQ1.d.ts +172 -0
- package/package.json +102 -0
- package/src/constants.ts +66 -0
- package/src/exact-direct/client/index.ts +5 -0
- package/src/exact-direct/client/scheme.ts +115 -0
- package/src/exact-direct/facilitator/index.ts +4 -0
- package/src/exact-direct/facilitator/scheme.ts +308 -0
- package/src/exact-direct/server/index.ts +9 -0
- package/src/exact-direct/server/register.ts +57 -0
- package/src/exact-direct/server/scheme.ts +216 -0
- package/src/index.ts +78 -0
- package/src/tokens.ts +96 -0
- package/src/types.ts +184 -0
- package/src/utils.ts +198 -0
package/dist/index.cjs
ADDED
|
@@ -0,0 +1,261 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __defProp = Object.defineProperty;
|
|
3
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
4
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
5
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
6
|
+
var __export = (target, all) => {
|
|
7
|
+
for (var name in all)
|
|
8
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
9
|
+
};
|
|
10
|
+
var __copyProps = (to, from, except, desc) => {
|
|
11
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
12
|
+
for (let key of __getOwnPropNames(from))
|
|
13
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
14
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
15
|
+
}
|
|
16
|
+
return to;
|
|
17
|
+
};
|
|
18
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
19
|
+
|
|
20
|
+
// src/index.ts
|
|
21
|
+
var index_exports = {};
|
|
22
|
+
__export(index_exports, {
|
|
23
|
+
DEFAULT_MAINNET_API: () => DEFAULT_MAINNET_API,
|
|
24
|
+
DEFAULT_TESTNET_API: () => DEFAULT_TESTNET_API,
|
|
25
|
+
DEFAULT_TOKENS: () => DEFAULT_TOKENS,
|
|
26
|
+
SCHEME_EXACT_DIRECT: () => SCHEME_EXACT_DIRECT,
|
|
27
|
+
STACKS_CAIP2_NAMESPACE: () => STACKS_CAIP2_NAMESPACE,
|
|
28
|
+
STACKS_MAINNET_CAIP2: () => STACKS_MAINNET_CAIP2,
|
|
29
|
+
STACKS_NETWORKS: () => STACKS_NETWORKS,
|
|
30
|
+
STACKS_TESTNET_CAIP2: () => STACKS_TESTNET_CAIP2,
|
|
31
|
+
SUSDC_MAINNET: () => SUSDC_MAINNET,
|
|
32
|
+
SUSDC_TESTNET: () => SUSDC_TESTNET,
|
|
33
|
+
TOKEN_REGISTRY: () => TOKEN_REGISTRY,
|
|
34
|
+
comparePrincipals: () => comparePrincipals,
|
|
35
|
+
extractTokenTransfer: () => extractTokenTransfer,
|
|
36
|
+
extractTokenTransferFromPostConditions: () => extractTokenTransferFromPostConditions,
|
|
37
|
+
formatAmount: () => formatAmount,
|
|
38
|
+
getContractAddress: () => getContractAddress,
|
|
39
|
+
getDefaultToken: () => getDefaultToken,
|
|
40
|
+
getNetworkConfig: () => getNetworkConfig,
|
|
41
|
+
getTokenConfig: () => getTokenConfig,
|
|
42
|
+
isStacksNetwork: () => isStacksNetwork,
|
|
43
|
+
isValidPrincipal: () => isValidPrincipal,
|
|
44
|
+
isValidTxId: () => isValidTxId,
|
|
45
|
+
parseAmount: () => parseAmount
|
|
46
|
+
});
|
|
47
|
+
module.exports = __toCommonJS(index_exports);
|
|
48
|
+
|
|
49
|
+
// src/constants.ts
|
|
50
|
+
var STACKS_CAIP2_NAMESPACE = "stacks";
|
|
51
|
+
var STACKS_MAINNET_CAIP2 = "stacks:1";
|
|
52
|
+
var STACKS_TESTNET_CAIP2 = "stacks:2147483648";
|
|
53
|
+
var SCHEME_EXACT_DIRECT = "exact-direct";
|
|
54
|
+
var DEFAULT_MAINNET_API = "https://api.mainnet.hiro.so";
|
|
55
|
+
var DEFAULT_TESTNET_API = "https://api.testnet.hiro.so";
|
|
56
|
+
var STACKS_NETWORKS = {
|
|
57
|
+
[STACKS_MAINNET_CAIP2]: {
|
|
58
|
+
name: "Stacks Mainnet",
|
|
59
|
+
caip2: STACKS_MAINNET_CAIP2,
|
|
60
|
+
apiUrl: DEFAULT_MAINNET_API,
|
|
61
|
+
chainId: 1,
|
|
62
|
+
addressPrefix: "SP",
|
|
63
|
+
isTestnet: false
|
|
64
|
+
},
|
|
65
|
+
[STACKS_TESTNET_CAIP2]: {
|
|
66
|
+
name: "Stacks Testnet",
|
|
67
|
+
caip2: STACKS_TESTNET_CAIP2,
|
|
68
|
+
apiUrl: DEFAULT_TESTNET_API,
|
|
69
|
+
chainId: 2147483648,
|
|
70
|
+
addressPrefix: "ST",
|
|
71
|
+
isTestnet: true
|
|
72
|
+
}
|
|
73
|
+
};
|
|
74
|
+
function getNetworkConfig(network) {
|
|
75
|
+
return STACKS_NETWORKS[network];
|
|
76
|
+
}
|
|
77
|
+
function isStacksNetwork(network) {
|
|
78
|
+
return network.startsWith(`${STACKS_CAIP2_NAMESPACE}:`);
|
|
79
|
+
}
|
|
80
|
+
|
|
81
|
+
// src/tokens.ts
|
|
82
|
+
var SUSDC_MAINNET = {
|
|
83
|
+
contractAddress: "SP3Y2ZSH8P7D50B0VBTSX11S7XSG24M1VB9YFQA4K.token-susdc",
|
|
84
|
+
symbol: "sUSDC",
|
|
85
|
+
name: "Stacks USDC",
|
|
86
|
+
decimals: 6,
|
|
87
|
+
issuer: "Stacks"
|
|
88
|
+
};
|
|
89
|
+
var SUSDC_TESTNET = {
|
|
90
|
+
contractAddress: "ST1PQHQKV0RJXZFY1DGX8MNSNYVE3VGZJSRTPGZGM.token-susdc",
|
|
91
|
+
symbol: "sUSDC",
|
|
92
|
+
name: "Test Stacks USDC",
|
|
93
|
+
decimals: 6
|
|
94
|
+
};
|
|
95
|
+
var TOKEN_REGISTRY = {
|
|
96
|
+
[STACKS_MAINNET_CAIP2]: {
|
|
97
|
+
sUSDC: SUSDC_MAINNET
|
|
98
|
+
},
|
|
99
|
+
[STACKS_TESTNET_CAIP2]: {
|
|
100
|
+
sUSDC: SUSDC_TESTNET
|
|
101
|
+
}
|
|
102
|
+
};
|
|
103
|
+
var DEFAULT_TOKENS = {
|
|
104
|
+
[STACKS_MAINNET_CAIP2]: SUSDC_MAINNET,
|
|
105
|
+
[STACKS_TESTNET_CAIP2]: SUSDC_TESTNET
|
|
106
|
+
};
|
|
107
|
+
function getTokenConfig(network, symbol = "sUSDC") {
|
|
108
|
+
return TOKEN_REGISTRY[network]?.[symbol];
|
|
109
|
+
}
|
|
110
|
+
function getDefaultToken(network) {
|
|
111
|
+
return DEFAULT_TOKENS[network];
|
|
112
|
+
}
|
|
113
|
+
function getContractAddress(network, symbol = "sUSDC") {
|
|
114
|
+
return getTokenConfig(network, symbol)?.contractAddress;
|
|
115
|
+
}
|
|
116
|
+
|
|
117
|
+
// src/utils.ts
|
|
118
|
+
function isValidPrincipal(address) {
|
|
119
|
+
if (!address || typeof address !== "string") {
|
|
120
|
+
return false;
|
|
121
|
+
}
|
|
122
|
+
const parts = address.split(".");
|
|
123
|
+
const principal = parts[0];
|
|
124
|
+
const principalRegex = /^(SP|ST)[0-9A-HJ-NP-Za-km-z]{33,41}$/;
|
|
125
|
+
if (!principalRegex.test(principal)) {
|
|
126
|
+
return false;
|
|
127
|
+
}
|
|
128
|
+
if (parts.length === 2) {
|
|
129
|
+
const contractName = parts[1];
|
|
130
|
+
const contractNameRegex = /^[a-zA-Z][a-zA-Z0-9\-_]{0,127}$/;
|
|
131
|
+
return contractNameRegex.test(contractName);
|
|
132
|
+
}
|
|
133
|
+
return parts.length === 1;
|
|
134
|
+
}
|
|
135
|
+
function isValidTxId(hash) {
|
|
136
|
+
if (!hash || typeof hash !== "string") {
|
|
137
|
+
return false;
|
|
138
|
+
}
|
|
139
|
+
return /^0x[a-fA-F0-9]{64}$/.test(hash);
|
|
140
|
+
}
|
|
141
|
+
function comparePrincipals(a, b) {
|
|
142
|
+
return a === b;
|
|
143
|
+
}
|
|
144
|
+
function formatAmount(amount, decimals) {
|
|
145
|
+
const amountBigInt = BigInt(amount);
|
|
146
|
+
const divisor = BigInt(10 ** decimals);
|
|
147
|
+
const wholePart = amountBigInt / divisor;
|
|
148
|
+
const fractionalPart = amountBigInt % divisor;
|
|
149
|
+
if (fractionalPart === 0n) {
|
|
150
|
+
return wholePart.toString();
|
|
151
|
+
}
|
|
152
|
+
const fractionalStr = fractionalPart.toString().padStart(decimals, "0");
|
|
153
|
+
const trimmedFractional = fractionalStr.replace(/0+$/, "");
|
|
154
|
+
return `${wholePart}.${trimmedFractional}`;
|
|
155
|
+
}
|
|
156
|
+
function parseAmount(amount, decimals) {
|
|
157
|
+
const parts = amount.split(".");
|
|
158
|
+
const wholePart = parts[0] || "0";
|
|
159
|
+
const fractionalPart = (parts[1] || "").padEnd(decimals, "0").slice(0, decimals);
|
|
160
|
+
return BigInt(wholePart + fractionalPart).toString();
|
|
161
|
+
}
|
|
162
|
+
function extractTokenTransfer(result, contractAddress) {
|
|
163
|
+
if (result.txStatus !== "success") {
|
|
164
|
+
return null;
|
|
165
|
+
}
|
|
166
|
+
if (result.txType !== "contract_call") {
|
|
167
|
+
return null;
|
|
168
|
+
}
|
|
169
|
+
if (result.contractCall) {
|
|
170
|
+
const { contractId, functionName } = result.contractCall;
|
|
171
|
+
if (functionName !== "transfer") {
|
|
172
|
+
return null;
|
|
173
|
+
}
|
|
174
|
+
if (contractAddress && contractId !== contractAddress) {
|
|
175
|
+
return null;
|
|
176
|
+
}
|
|
177
|
+
const transferEvent = result.events.find(
|
|
178
|
+
(e) => e.eventType === "fungible_token_asset" && e.asset?.assetEventType === "transfer"
|
|
179
|
+
);
|
|
180
|
+
if (transferEvent?.asset) {
|
|
181
|
+
return {
|
|
182
|
+
contractAddress: contractId,
|
|
183
|
+
from: transferEvent.asset.sender,
|
|
184
|
+
to: transferEvent.asset.recipient,
|
|
185
|
+
amount: transferEvent.asset.amount,
|
|
186
|
+
success: true
|
|
187
|
+
};
|
|
188
|
+
}
|
|
189
|
+
if (result.contractCall.functionArgs.length >= 3) {
|
|
190
|
+
const amountArg = result.contractCall.functionArgs[0];
|
|
191
|
+
const senderArg = result.contractCall.functionArgs[1];
|
|
192
|
+
const recipientArg = result.contractCall.functionArgs[2];
|
|
193
|
+
const senderMatch = senderArg?.repr?.match(/^'?(S[PT][0-9A-HJ-NP-Za-km-z]+)/);
|
|
194
|
+
const recipientMatch = recipientArg?.repr?.match(/^'?(S[PT][0-9A-HJ-NP-Za-km-z]+)/);
|
|
195
|
+
const amountMatch = amountArg?.repr?.match(/^u(\d+)$/);
|
|
196
|
+
if (senderMatch && recipientMatch && amountMatch) {
|
|
197
|
+
return {
|
|
198
|
+
contractAddress: contractId,
|
|
199
|
+
from: senderMatch[1],
|
|
200
|
+
to: recipientMatch[1],
|
|
201
|
+
amount: amountMatch[1],
|
|
202
|
+
success: true
|
|
203
|
+
};
|
|
204
|
+
}
|
|
205
|
+
}
|
|
206
|
+
}
|
|
207
|
+
return null;
|
|
208
|
+
}
|
|
209
|
+
function extractTokenTransferFromPostConditions(result, contractAddress) {
|
|
210
|
+
if (result.txStatus !== "success") {
|
|
211
|
+
return null;
|
|
212
|
+
}
|
|
213
|
+
for (const pc of result.postConditions) {
|
|
214
|
+
if (pc.asset) {
|
|
215
|
+
const assetContractAddress = `${pc.asset.contractAddress}.${pc.asset.contractName}`;
|
|
216
|
+
if (contractAddress && assetContractAddress !== contractAddress) {
|
|
217
|
+
continue;
|
|
218
|
+
}
|
|
219
|
+
const transferEvent = result.events.find(
|
|
220
|
+
(e) => e.eventType === "fungible_token_asset" && e.asset?.assetEventType === "transfer" && e.asset?.sender === pc.principal.address
|
|
221
|
+
);
|
|
222
|
+
if (transferEvent?.asset) {
|
|
223
|
+
return {
|
|
224
|
+
contractAddress: assetContractAddress,
|
|
225
|
+
from: transferEvent.asset.sender,
|
|
226
|
+
to: transferEvent.asset.recipient,
|
|
227
|
+
amount: transferEvent.asset.amount,
|
|
228
|
+
success: true
|
|
229
|
+
};
|
|
230
|
+
}
|
|
231
|
+
}
|
|
232
|
+
}
|
|
233
|
+
return null;
|
|
234
|
+
}
|
|
235
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
236
|
+
0 && (module.exports = {
|
|
237
|
+
DEFAULT_MAINNET_API,
|
|
238
|
+
DEFAULT_TESTNET_API,
|
|
239
|
+
DEFAULT_TOKENS,
|
|
240
|
+
SCHEME_EXACT_DIRECT,
|
|
241
|
+
STACKS_CAIP2_NAMESPACE,
|
|
242
|
+
STACKS_MAINNET_CAIP2,
|
|
243
|
+
STACKS_NETWORKS,
|
|
244
|
+
STACKS_TESTNET_CAIP2,
|
|
245
|
+
SUSDC_MAINNET,
|
|
246
|
+
SUSDC_TESTNET,
|
|
247
|
+
TOKEN_REGISTRY,
|
|
248
|
+
comparePrincipals,
|
|
249
|
+
extractTokenTransfer,
|
|
250
|
+
extractTokenTransferFromPostConditions,
|
|
251
|
+
formatAmount,
|
|
252
|
+
getContractAddress,
|
|
253
|
+
getDefaultToken,
|
|
254
|
+
getNetworkConfig,
|
|
255
|
+
getTokenConfig,
|
|
256
|
+
isStacksNetwork,
|
|
257
|
+
isValidPrincipal,
|
|
258
|
+
isValidTxId,
|
|
259
|
+
parseAmount
|
|
260
|
+
});
|
|
261
|
+
//# sourceMappingURL=index.cjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/index.ts","../src/constants.ts","../src/tokens.ts","../src/utils.ts"],"sourcesContent":["/**\n * @t402/stacks - Stacks mechanism for T402\n *\n * This package provides support for SIP-010 token payments on Stacks (Bitcoin L2)\n * using the exact-direct scheme.\n *\n * @example\n * ```typescript\n * // Client usage\n * import { createExactDirectStacksClient } from '@t402/stacks/exact-direct/client';\n *\n * const client = createExactDirectStacksClient({\n * signer: myStacksSigner,\n * });\n *\n * // Server usage\n * import { registerExactDirectStacksServer } from '@t402/stacks/exact-direct/server';\n *\n * registerExactDirectStacksServer(server);\n *\n * // Facilitator usage\n * import { createExactDirectStacksFacilitator } from '@t402/stacks/exact-direct/facilitator';\n *\n * const facilitator = createExactDirectStacksFacilitator(signer);\n * ```\n */\n\n// Re-export constants\nexport {\n STACKS_CAIP2_NAMESPACE,\n STACKS_MAINNET_CAIP2,\n STACKS_TESTNET_CAIP2,\n SCHEME_EXACT_DIRECT,\n DEFAULT_MAINNET_API,\n DEFAULT_TESTNET_API,\n STACKS_NETWORKS,\n getNetworkConfig,\n isStacksNetwork,\n type StacksNetworkConfig,\n} from \"./constants.js\";\n\n// Re-export token registry\nexport {\n SUSDC_MAINNET,\n SUSDC_TESTNET,\n TOKEN_REGISTRY,\n DEFAULT_TOKENS,\n getTokenConfig,\n getDefaultToken,\n getContractAddress,\n type TokenConfig,\n} from \"./tokens.js\";\n\n// Re-export types\nexport type {\n ExactDirectStacksPayload,\n StacksTransactionResult,\n StacksContractCall,\n StacksFunctionArg,\n StacksPostCondition,\n StacksEvent,\n ParsedTokenTransfer,\n FacilitatorStacksSigner,\n ClientStacksSigner,\n StacksServerConfig,\n StacksFacilitatorConfig,\n} from \"./types.js\";\n\n// Re-export utilities\nexport {\n isValidPrincipal,\n isValidTxId,\n comparePrincipals,\n formatAmount,\n parseAmount,\n extractTokenTransfer,\n extractTokenTransferFromPostConditions,\n} from \"./utils.js\";\n","/**\n * Stacks T402 Constants\n *\n * Stacks is a Bitcoin Layer 2 that brings smart contracts and DeFi\n * to Bitcoin. SIP-010 is the fungible token standard on Stacks.\n */\n\n// CAIP-2 namespace for Stacks\nexport const STACKS_CAIP2_NAMESPACE = \"stacks\";\n\n// CAIP-2 network identifiers\n// Stacks Mainnet (chain ID: 1)\nexport const STACKS_MAINNET_CAIP2 = \"stacks:1\";\n\n// Stacks Testnet (chain ID: 2147483648)\nexport const STACKS_TESTNET_CAIP2 = \"stacks:2147483648\";\n\n// Scheme identifier\nexport const SCHEME_EXACT_DIRECT = \"exact-direct\";\n\n// Default API endpoints (Hiro API)\nexport const DEFAULT_MAINNET_API = \"https://api.mainnet.hiro.so\";\nexport const DEFAULT_TESTNET_API = \"https://api.testnet.hiro.so\";\n\n// Network configurations\nexport interface StacksNetworkConfig {\n readonly name: string;\n readonly caip2: string;\n readonly apiUrl: string;\n readonly chainId: number;\n readonly addressPrefix: string;\n readonly isTestnet: boolean;\n}\n\nexport const STACKS_NETWORKS: Record<string, StacksNetworkConfig> = {\n [STACKS_MAINNET_CAIP2]: {\n name: \"Stacks Mainnet\",\n caip2: STACKS_MAINNET_CAIP2,\n apiUrl: DEFAULT_MAINNET_API,\n chainId: 1,\n addressPrefix: \"SP\",\n isTestnet: false,\n },\n [STACKS_TESTNET_CAIP2]: {\n name: \"Stacks Testnet\",\n caip2: STACKS_TESTNET_CAIP2,\n apiUrl: DEFAULT_TESTNET_API,\n chainId: 2147483648,\n addressPrefix: \"ST\",\n isTestnet: true,\n },\n};\n\n/**\n * Get network configuration by CAIP-2 identifier\n */\nexport function getNetworkConfig(network: string): StacksNetworkConfig | undefined {\n return STACKS_NETWORKS[network];\n}\n\n/**\n * Check if a network identifier is a Stacks network\n */\nexport function isStacksNetwork(network: string): boolean {\n return network.startsWith(`${STACKS_CAIP2_NAMESPACE}:`);\n}\n","/**\n * Stacks Token Registry\n *\n * On Stacks, tokens are SIP-010 fungible tokens identified by\n * their contract address (principal.contract-name).\n */\n\nimport {\n STACKS_MAINNET_CAIP2,\n STACKS_TESTNET_CAIP2,\n} from \"./constants.js\";\n\n/**\n * Token configuration for Stacks SIP-010 tokens\n */\nexport interface TokenConfig {\n /** Contract address (principal.contract-name) */\n readonly contractAddress: string;\n /** Token symbol */\n readonly symbol: string;\n /** Token name */\n readonly name: string;\n /** Decimal places */\n readonly decimals: number;\n /** Token issuer */\n readonly issuer?: string;\n}\n\n/**\n * sUSDC on Stacks Mainnet\n * Contract: SP3Y2ZSH8P7D50B0VBTSX11S7XSG24M1VB9YFQA4K.token-susdc\n * Decimals: 6\n */\nexport const SUSDC_MAINNET: TokenConfig = {\n contractAddress: \"SP3Y2ZSH8P7D50B0VBTSX11S7XSG24M1VB9YFQA4K.token-susdc\",\n symbol: \"sUSDC\",\n name: \"Stacks USDC\",\n decimals: 6,\n issuer: \"Stacks\",\n};\n\n/**\n * sUSDC on Stacks Testnet\n * Contract: ST1PQHQKV0RJXZFY1DGX8MNSNYVE3VGZJSRTPGZGM.token-susdc\n * Decimals: 6\n */\nexport const SUSDC_TESTNET: TokenConfig = {\n contractAddress: \"ST1PQHQKV0RJXZFY1DGX8MNSNYVE3VGZJSRTPGZGM.token-susdc\",\n symbol: \"sUSDC\",\n name: \"Test Stacks USDC\",\n decimals: 6,\n};\n\n/**\n * Network-specific token registries\n */\nexport const TOKEN_REGISTRY: Record<string, Record<string, TokenConfig>> = {\n [STACKS_MAINNET_CAIP2]: {\n sUSDC: SUSDC_MAINNET,\n },\n [STACKS_TESTNET_CAIP2]: {\n sUSDC: SUSDC_TESTNET,\n },\n};\n\n/**\n * Default tokens per network\n */\nexport const DEFAULT_TOKENS: Record<string, TokenConfig> = {\n [STACKS_MAINNET_CAIP2]: SUSDC_MAINNET,\n [STACKS_TESTNET_CAIP2]: SUSDC_TESTNET,\n};\n\n/**\n * Get token configuration by network and symbol\n */\nexport function getTokenConfig(\n network: string,\n symbol: string = \"sUSDC\",\n): TokenConfig | undefined {\n return TOKEN_REGISTRY[network]?.[symbol];\n}\n\n/**\n * Get the default token for a network\n */\nexport function getDefaultToken(network: string): TokenConfig | undefined {\n return DEFAULT_TOKENS[network];\n}\n\n/**\n * Get contract address for a token on a network\n */\nexport function getContractAddress(network: string, symbol: string = \"sUSDC\"): string | undefined {\n return getTokenConfig(network, symbol)?.contractAddress;\n}\n","/**\n * Stacks Utility Functions\n */\n\nimport type { StacksTransactionResult, ParsedTokenTransfer } from \"./types.js\";\n\n/**\n * Validate a Stacks principal address format\n * Stacks addresses start with SP (mainnet) or ST (testnet)\n * followed by alphanumeric characters (base58-like encoding)\n */\nexport function isValidPrincipal(address: string): boolean {\n if (!address || typeof address !== \"string\") {\n return false;\n }\n\n // Standard principal: SP/ST prefix + base58 characters (33-41 chars total)\n // Contract principal: standard-principal.contract-name\n const parts = address.split(\".\");\n const principal = parts[0];\n\n // Check principal format: SP or ST prefix + alphanumeric (base58 chars)\n const principalRegex = /^(SP|ST)[0-9A-HJ-NP-Za-km-z]{33,41}$/;\n if (!principalRegex.test(principal)) {\n return false;\n }\n\n // If it's a contract principal, validate contract name\n if (parts.length === 2) {\n const contractName = parts[1];\n // Contract names: 1-128 chars, alphanumeric + hyphen + underscore\n const contractNameRegex = /^[a-zA-Z][a-zA-Z0-9\\-_]{0,127}$/;\n return contractNameRegex.test(contractName);\n }\n\n // Standard principal (no contract part) or exactly one dot for contract\n return parts.length === 1;\n}\n\n/**\n * Validate a Stacks transaction ID format\n * Transaction IDs are 0x-prefixed 64-character hex strings\n */\nexport function isValidTxId(hash: string): boolean {\n if (!hash || typeof hash !== \"string\") {\n return false;\n }\n return /^0x[a-fA-F0-9]{64}$/.test(hash);\n}\n\n/**\n * Compare two Stacks principals (case-sensitive)\n */\nexport function comparePrincipals(a: string, b: string): boolean {\n return a === b;\n}\n\n/**\n * Format an amount with decimals for display\n */\nexport function formatAmount(amount: string, decimals: number): string {\n const amountBigInt = BigInt(amount);\n const divisor = BigInt(10 ** decimals);\n const wholePart = amountBigInt / divisor;\n const fractionalPart = amountBigInt % divisor;\n\n if (fractionalPart === 0n) {\n return wholePart.toString();\n }\n\n const fractionalStr = fractionalPart.toString().padStart(decimals, \"0\");\n const trimmedFractional = fractionalStr.replace(/0+$/, \"\");\n return `${wholePart}.${trimmedFractional}`;\n}\n\n/**\n * Parse an amount string to the smallest unit (with decimals applied)\n */\nexport function parseAmount(amount: string, decimals: number): string {\n const parts = amount.split(\".\");\n const wholePart = parts[0] || \"0\";\n const fractionalPart = (parts[1] || \"\").padEnd(decimals, \"0\").slice(0, decimals);\n return BigInt(wholePart + fractionalPart).toString();\n}\n\n/**\n * Extract token transfer details from a Stacks transaction result\n * Looks for ft_transfer events matching the expected contract\n */\nexport function extractTokenTransfer(\n result: StacksTransactionResult,\n contractAddress?: string,\n): ParsedTokenTransfer | null {\n if (result.txStatus !== \"success\") {\n return null;\n }\n\n // Check if this is a contract-call transaction\n if (result.txType !== \"contract_call\") {\n return null;\n }\n\n // Check contract call is a transfer function\n if (result.contractCall) {\n const { contractId, functionName } = result.contractCall;\n\n if (functionName !== \"transfer\") {\n return null;\n }\n\n // If contractAddress specified, verify it matches\n if (contractAddress && contractId !== contractAddress) {\n return null;\n }\n\n // Look for ft_transfer event\n const transferEvent = result.events.find(\n (e) => e.eventType === \"fungible_token_asset\" && e.asset?.assetEventType === \"transfer\",\n );\n\n if (transferEvent?.asset) {\n return {\n contractAddress: contractId,\n from: transferEvent.asset.sender,\n to: transferEvent.asset.recipient,\n amount: transferEvent.asset.amount,\n success: true,\n };\n }\n\n // Fallback: extract from function args if events not available\n if (result.contractCall.functionArgs.length >= 3) {\n const amountArg = result.contractCall.functionArgs[0];\n const senderArg = result.contractCall.functionArgs[1];\n const recipientArg = result.contractCall.functionArgs[2];\n\n // Parse principal from repr (format: 'SP...')\n const senderMatch = senderArg?.repr?.match(/^'?(S[PT][0-9A-HJ-NP-Za-km-z]+)/);\n const recipientMatch = recipientArg?.repr?.match(/^'?(S[PT][0-9A-HJ-NP-Za-km-z]+)/);\n const amountMatch = amountArg?.repr?.match(/^u(\\d+)$/);\n\n if (senderMatch && recipientMatch && amountMatch) {\n return {\n contractAddress: contractId,\n from: senderMatch[1],\n to: recipientMatch[1],\n amount: amountMatch[1],\n success: true,\n };\n }\n }\n }\n\n return null;\n}\n\n/**\n * Extract token transfer from post conditions (alternative method)\n */\nexport function extractTokenTransferFromPostConditions(\n result: StacksTransactionResult,\n contractAddress?: string,\n): ParsedTokenTransfer | null {\n if (result.txStatus !== \"success\") {\n return null;\n }\n\n // Look for fungible token post conditions\n for (const pc of result.postConditions) {\n if (pc.asset) {\n const assetContractAddress = `${pc.asset.contractAddress}.${pc.asset.contractName}`;\n\n if (contractAddress && assetContractAddress !== contractAddress) {\n continue;\n }\n\n // Find corresponding ft_transfer event for recipient\n const transferEvent = result.events.find(\n (e) =>\n e.eventType === \"fungible_token_asset\" &&\n e.asset?.assetEventType === \"transfer\" &&\n e.asset?.sender === pc.principal.address,\n );\n\n if (transferEvent?.asset) {\n return {\n contractAddress: assetContractAddress,\n from: transferEvent.asset.sender,\n to: transferEvent.asset.recipient,\n amount: transferEvent.asset.amount,\n success: true,\n };\n }\n }\n }\n\n return null;\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;AAA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AQ,YAAY,CAAC;AAAA,UACrB,SAAS;AAAA,QACX;AAAA,MACF;AAAA,IACF;AAAA,EACF;AAEA,SAAO;AACT;AAKO,SAAS,uCACd,QACA,iBAC4B;AAC5B,MAAI,OAAO,aAAa,WAAW;AACjC,WAAO;AAAA,EACT;AAGA,aAAW,MAAM,OAAO,gBAAgB;AACtC,QAAI,GAAG,OAAO;AACZ,YAAM,uBAAuB,GAAG,GAAG,MAAM,eAAe,IAAI,GAAG,MAAM,YAAY;AAEjF,UAAI,mBAAmB,yBAAyB,iBAAiB;AAC/D;AAAA,MACF;AAGA,YAAM,gBAAgB,OAAO,OAAO;AAAA,QAClC,CAAC,MACC,EAAE,cAAc,0BAChB,EAAE,OAAO,mBAAmB,cAC5B,EAAE,OAAO,WAAW,GAAG,UAAU;AAAA,MACrC;AAEA,UAAI,eAAe,OAAO;AACxB,eAAO;AAAA,UACL,iBAAiB;AAAA,UACjB,MAAM,cAAc,MAAM;AAAA,UAC1B,IAAI,cAAc,MAAM;AAAA,UACxB,QAAQ,cAAc,MAAM;AAAA,UAC5B,SAAS;AAAA,QACX;AAAA,MACF;AAAA,IACF;AAAA,EACF;AAEA,SAAO;AACT;","names":[]}
|
package/dist/index.d.cts
ADDED
|
@@ -0,0 +1,126 @@
|
|
|
1
|
+
import { S as StacksTransactionResult, P as ParsedTokenTransfer } from './types-Bxzo3eQ1.cjs';
|
|
2
|
+
export { C as ClientStacksSigner, E as ExactDirectStacksPayload, F as FacilitatorStacksSigner, a as StacksContractCall, d as StacksEvent, f as StacksFacilitatorConfig, b as StacksFunctionArg, c as StacksPostCondition, e as StacksServerConfig } from './types-Bxzo3eQ1.cjs';
|
|
3
|
+
import '@t402/core/types';
|
|
4
|
+
|
|
5
|
+
/**
|
|
6
|
+
* Stacks T402 Constants
|
|
7
|
+
*
|
|
8
|
+
* Stacks is a Bitcoin Layer 2 that brings smart contracts and DeFi
|
|
9
|
+
* to Bitcoin. SIP-010 is the fungible token standard on Stacks.
|
|
10
|
+
*/
|
|
11
|
+
declare const STACKS_CAIP2_NAMESPACE = "stacks";
|
|
12
|
+
declare const STACKS_MAINNET_CAIP2 = "stacks:1";
|
|
13
|
+
declare const STACKS_TESTNET_CAIP2 = "stacks:2147483648";
|
|
14
|
+
declare const SCHEME_EXACT_DIRECT = "exact-direct";
|
|
15
|
+
declare const DEFAULT_MAINNET_API = "https://api.mainnet.hiro.so";
|
|
16
|
+
declare const DEFAULT_TESTNET_API = "https://api.testnet.hiro.so";
|
|
17
|
+
interface StacksNetworkConfig {
|
|
18
|
+
readonly name: string;
|
|
19
|
+
readonly caip2: string;
|
|
20
|
+
readonly apiUrl: string;
|
|
21
|
+
readonly chainId: number;
|
|
22
|
+
readonly addressPrefix: string;
|
|
23
|
+
readonly isTestnet: boolean;
|
|
24
|
+
}
|
|
25
|
+
declare const STACKS_NETWORKS: Record<string, StacksNetworkConfig>;
|
|
26
|
+
/**
|
|
27
|
+
* Get network configuration by CAIP-2 identifier
|
|
28
|
+
*/
|
|
29
|
+
declare function getNetworkConfig(network: string): StacksNetworkConfig | undefined;
|
|
30
|
+
/**
|
|
31
|
+
* Check if a network identifier is a Stacks network
|
|
32
|
+
*/
|
|
33
|
+
declare function isStacksNetwork(network: string): boolean;
|
|
34
|
+
|
|
35
|
+
/**
|
|
36
|
+
* Stacks Token Registry
|
|
37
|
+
*
|
|
38
|
+
* On Stacks, tokens are SIP-010 fungible tokens identified by
|
|
39
|
+
* their contract address (principal.contract-name).
|
|
40
|
+
*/
|
|
41
|
+
/**
|
|
42
|
+
* Token configuration for Stacks SIP-010 tokens
|
|
43
|
+
*/
|
|
44
|
+
interface TokenConfig {
|
|
45
|
+
/** Contract address (principal.contract-name) */
|
|
46
|
+
readonly contractAddress: string;
|
|
47
|
+
/** Token symbol */
|
|
48
|
+
readonly symbol: string;
|
|
49
|
+
/** Token name */
|
|
50
|
+
readonly name: string;
|
|
51
|
+
/** Decimal places */
|
|
52
|
+
readonly decimals: number;
|
|
53
|
+
/** Token issuer */
|
|
54
|
+
readonly issuer?: string;
|
|
55
|
+
}
|
|
56
|
+
/**
|
|
57
|
+
* sUSDC on Stacks Mainnet
|
|
58
|
+
* Contract: SP3Y2ZSH8P7D50B0VBTSX11S7XSG24M1VB9YFQA4K.token-susdc
|
|
59
|
+
* Decimals: 6
|
|
60
|
+
*/
|
|
61
|
+
declare const SUSDC_MAINNET: TokenConfig;
|
|
62
|
+
/**
|
|
63
|
+
* sUSDC on Stacks Testnet
|
|
64
|
+
* Contract: ST1PQHQKV0RJXZFY1DGX8MNSNYVE3VGZJSRTPGZGM.token-susdc
|
|
65
|
+
* Decimals: 6
|
|
66
|
+
*/
|
|
67
|
+
declare const SUSDC_TESTNET: TokenConfig;
|
|
68
|
+
/**
|
|
69
|
+
* Network-specific token registries
|
|
70
|
+
*/
|
|
71
|
+
declare const TOKEN_REGISTRY: Record<string, Record<string, TokenConfig>>;
|
|
72
|
+
/**
|
|
73
|
+
* Default tokens per network
|
|
74
|
+
*/
|
|
75
|
+
declare const DEFAULT_TOKENS: Record<string, TokenConfig>;
|
|
76
|
+
/**
|
|
77
|
+
* Get token configuration by network and symbol
|
|
78
|
+
*/
|
|
79
|
+
declare function getTokenConfig(network: string, symbol?: string): TokenConfig | undefined;
|
|
80
|
+
/**
|
|
81
|
+
* Get the default token for a network
|
|
82
|
+
*/
|
|
83
|
+
declare function getDefaultToken(network: string): TokenConfig | undefined;
|
|
84
|
+
/**
|
|
85
|
+
* Get contract address for a token on a network
|
|
86
|
+
*/
|
|
87
|
+
declare function getContractAddress(network: string, symbol?: string): string | undefined;
|
|
88
|
+
|
|
89
|
+
/**
|
|
90
|
+
* Stacks Utility Functions
|
|
91
|
+
*/
|
|
92
|
+
|
|
93
|
+
/**
|
|
94
|
+
* Validate a Stacks principal address format
|
|
95
|
+
* Stacks addresses start with SP (mainnet) or ST (testnet)
|
|
96
|
+
* followed by alphanumeric characters (base58-like encoding)
|
|
97
|
+
*/
|
|
98
|
+
declare function isValidPrincipal(address: string): boolean;
|
|
99
|
+
/**
|
|
100
|
+
* Validate a Stacks transaction ID format
|
|
101
|
+
* Transaction IDs are 0x-prefixed 64-character hex strings
|
|
102
|
+
*/
|
|
103
|
+
declare function isValidTxId(hash: string): boolean;
|
|
104
|
+
/**
|
|
105
|
+
* Compare two Stacks principals (case-sensitive)
|
|
106
|
+
*/
|
|
107
|
+
declare function comparePrincipals(a: string, b: string): boolean;
|
|
108
|
+
/**
|
|
109
|
+
* Format an amount with decimals for display
|
|
110
|
+
*/
|
|
111
|
+
declare function formatAmount(amount: string, decimals: number): string;
|
|
112
|
+
/**
|
|
113
|
+
* Parse an amount string to the smallest unit (with decimals applied)
|
|
114
|
+
*/
|
|
115
|
+
declare function parseAmount(amount: string, decimals: number): string;
|
|
116
|
+
/**
|
|
117
|
+
* Extract token transfer details from a Stacks transaction result
|
|
118
|
+
* Looks for ft_transfer events matching the expected contract
|
|
119
|
+
*/
|
|
120
|
+
declare function extractTokenTransfer(result: StacksTransactionResult, contractAddress?: string): ParsedTokenTransfer | null;
|
|
121
|
+
/**
|
|
122
|
+
* Extract token transfer from post conditions (alternative method)
|
|
123
|
+
*/
|
|
124
|
+
declare function extractTokenTransferFromPostConditions(result: StacksTransactionResult, contractAddress?: string): ParsedTokenTransfer | null;
|
|
125
|
+
|
|
126
|
+
export { DEFAULT_MAINNET_API, DEFAULT_TESTNET_API, DEFAULT_TOKENS, ParsedTokenTransfer, SCHEME_EXACT_DIRECT, STACKS_CAIP2_NAMESPACE, STACKS_MAINNET_CAIP2, STACKS_NETWORKS, STACKS_TESTNET_CAIP2, SUSDC_MAINNET, SUSDC_TESTNET, type StacksNetworkConfig, StacksTransactionResult, TOKEN_REGISTRY, type TokenConfig, comparePrincipals, extractTokenTransfer, extractTokenTransferFromPostConditions, formatAmount, getContractAddress, getDefaultToken, getNetworkConfig, getTokenConfig, isStacksNetwork, isValidPrincipal, isValidTxId, parseAmount };
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,126 @@
|
|
|
1
|
+
import { S as StacksTransactionResult, P as ParsedTokenTransfer } from './types-Bxzo3eQ1.js';
|
|
2
|
+
export { C as ClientStacksSigner, E as ExactDirectStacksPayload, F as FacilitatorStacksSigner, a as StacksContractCall, d as StacksEvent, f as StacksFacilitatorConfig, b as StacksFunctionArg, c as StacksPostCondition, e as StacksServerConfig } from './types-Bxzo3eQ1.js';
|
|
3
|
+
import '@t402/core/types';
|
|
4
|
+
|
|
5
|
+
/**
|
|
6
|
+
* Stacks T402 Constants
|
|
7
|
+
*
|
|
8
|
+
* Stacks is a Bitcoin Layer 2 that brings smart contracts and DeFi
|
|
9
|
+
* to Bitcoin. SIP-010 is the fungible token standard on Stacks.
|
|
10
|
+
*/
|
|
11
|
+
declare const STACKS_CAIP2_NAMESPACE = "stacks";
|
|
12
|
+
declare const STACKS_MAINNET_CAIP2 = "stacks:1";
|
|
13
|
+
declare const STACKS_TESTNET_CAIP2 = "stacks:2147483648";
|
|
14
|
+
declare const SCHEME_EXACT_DIRECT = "exact-direct";
|
|
15
|
+
declare const DEFAULT_MAINNET_API = "https://api.mainnet.hiro.so";
|
|
16
|
+
declare const DEFAULT_TESTNET_API = "https://api.testnet.hiro.so";
|
|
17
|
+
interface StacksNetworkConfig {
|
|
18
|
+
readonly name: string;
|
|
19
|
+
readonly caip2: string;
|
|
20
|
+
readonly apiUrl: string;
|
|
21
|
+
readonly chainId: number;
|
|
22
|
+
readonly addressPrefix: string;
|
|
23
|
+
readonly isTestnet: boolean;
|
|
24
|
+
}
|
|
25
|
+
declare const STACKS_NETWORKS: Record<string, StacksNetworkConfig>;
|
|
26
|
+
/**
|
|
27
|
+
* Get network configuration by CAIP-2 identifier
|
|
28
|
+
*/
|
|
29
|
+
declare function getNetworkConfig(network: string): StacksNetworkConfig | undefined;
|
|
30
|
+
/**
|
|
31
|
+
* Check if a network identifier is a Stacks network
|
|
32
|
+
*/
|
|
33
|
+
declare function isStacksNetwork(network: string): boolean;
|
|
34
|
+
|
|
35
|
+
/**
|
|
36
|
+
* Stacks Token Registry
|
|
37
|
+
*
|
|
38
|
+
* On Stacks, tokens are SIP-010 fungible tokens identified by
|
|
39
|
+
* their contract address (principal.contract-name).
|
|
40
|
+
*/
|
|
41
|
+
/**
|
|
42
|
+
* Token configuration for Stacks SIP-010 tokens
|
|
43
|
+
*/
|
|
44
|
+
interface TokenConfig {
|
|
45
|
+
/** Contract address (principal.contract-name) */
|
|
46
|
+
readonly contractAddress: string;
|
|
47
|
+
/** Token symbol */
|
|
48
|
+
readonly symbol: string;
|
|
49
|
+
/** Token name */
|
|
50
|
+
readonly name: string;
|
|
51
|
+
/** Decimal places */
|
|
52
|
+
readonly decimals: number;
|
|
53
|
+
/** Token issuer */
|
|
54
|
+
readonly issuer?: string;
|
|
55
|
+
}
|
|
56
|
+
/**
|
|
57
|
+
* sUSDC on Stacks Mainnet
|
|
58
|
+
* Contract: SP3Y2ZSH8P7D50B0VBTSX11S7XSG24M1VB9YFQA4K.token-susdc
|
|
59
|
+
* Decimals: 6
|
|
60
|
+
*/
|
|
61
|
+
declare const SUSDC_MAINNET: TokenConfig;
|
|
62
|
+
/**
|
|
63
|
+
* sUSDC on Stacks Testnet
|
|
64
|
+
* Contract: ST1PQHQKV0RJXZFY1DGX8MNSNYVE3VGZJSRTPGZGM.token-susdc
|
|
65
|
+
* Decimals: 6
|
|
66
|
+
*/
|
|
67
|
+
declare const SUSDC_TESTNET: TokenConfig;
|
|
68
|
+
/**
|
|
69
|
+
* Network-specific token registries
|
|
70
|
+
*/
|
|
71
|
+
declare const TOKEN_REGISTRY: Record<string, Record<string, TokenConfig>>;
|
|
72
|
+
/**
|
|
73
|
+
* Default tokens per network
|
|
74
|
+
*/
|
|
75
|
+
declare const DEFAULT_TOKENS: Record<string, TokenConfig>;
|
|
76
|
+
/**
|
|
77
|
+
* Get token configuration by network and symbol
|
|
78
|
+
*/
|
|
79
|
+
declare function getTokenConfig(network: string, symbol?: string): TokenConfig | undefined;
|
|
80
|
+
/**
|
|
81
|
+
* Get the default token for a network
|
|
82
|
+
*/
|
|
83
|
+
declare function getDefaultToken(network: string): TokenConfig | undefined;
|
|
84
|
+
/**
|
|
85
|
+
* Get contract address for a token on a network
|
|
86
|
+
*/
|
|
87
|
+
declare function getContractAddress(network: string, symbol?: string): string | undefined;
|
|
88
|
+
|
|
89
|
+
/**
|
|
90
|
+
* Stacks Utility Functions
|
|
91
|
+
*/
|
|
92
|
+
|
|
93
|
+
/**
|
|
94
|
+
* Validate a Stacks principal address format
|
|
95
|
+
* Stacks addresses start with SP (mainnet) or ST (testnet)
|
|
96
|
+
* followed by alphanumeric characters (base58-like encoding)
|
|
97
|
+
*/
|
|
98
|
+
declare function isValidPrincipal(address: string): boolean;
|
|
99
|
+
/**
|
|
100
|
+
* Validate a Stacks transaction ID format
|
|
101
|
+
* Transaction IDs are 0x-prefixed 64-character hex strings
|
|
102
|
+
*/
|
|
103
|
+
declare function isValidTxId(hash: string): boolean;
|
|
104
|
+
/**
|
|
105
|
+
* Compare two Stacks principals (case-sensitive)
|
|
106
|
+
*/
|
|
107
|
+
declare function comparePrincipals(a: string, b: string): boolean;
|
|
108
|
+
/**
|
|
109
|
+
* Format an amount with decimals for display
|
|
110
|
+
*/
|
|
111
|
+
declare function formatAmount(amount: string, decimals: number): string;
|
|
112
|
+
/**
|
|
113
|
+
* Parse an amount string to the smallest unit (with decimals applied)
|
|
114
|
+
*/
|
|
115
|
+
declare function parseAmount(amount: string, decimals: number): string;
|
|
116
|
+
/**
|
|
117
|
+
* Extract token transfer details from a Stacks transaction result
|
|
118
|
+
* Looks for ft_transfer events matching the expected contract
|
|
119
|
+
*/
|
|
120
|
+
declare function extractTokenTransfer(result: StacksTransactionResult, contractAddress?: string): ParsedTokenTransfer | null;
|
|
121
|
+
/**
|
|
122
|
+
* Extract token transfer from post conditions (alternative method)
|
|
123
|
+
*/
|
|
124
|
+
declare function extractTokenTransferFromPostConditions(result: StacksTransactionResult, contractAddress?: string): ParsedTokenTransfer | null;
|
|
125
|
+
|
|
126
|
+
export { DEFAULT_MAINNET_API, DEFAULT_TESTNET_API, DEFAULT_TOKENS, ParsedTokenTransfer, SCHEME_EXACT_DIRECT, STACKS_CAIP2_NAMESPACE, STACKS_MAINNET_CAIP2, STACKS_NETWORKS, STACKS_TESTNET_CAIP2, SUSDC_MAINNET, SUSDC_TESTNET, type StacksNetworkConfig, StacksTransactionResult, TOKEN_REGISTRY, type TokenConfig, comparePrincipals, extractTokenTransfer, extractTokenTransferFromPostConditions, formatAmount, getContractAddress, getDefaultToken, getNetworkConfig, getTokenConfig, isStacksNetwork, isValidPrincipal, isValidTxId, parseAmount };
|