@clarigen/core 1.0.0-next.3 → 1.0.0-next.30
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.d.ts +541 -13
- package/dist/index.js +1 -8
- package/dist/index.mjs +1 -0
- package/package.json +17 -17
- package/dist/api.d.ts +0 -15
- package/dist/base-provider.d.ts +0 -6
- package/dist/clarity-types.d.ts +0 -34
- package/dist/contracts.d.ts +0 -6
- package/dist/core.cjs.development.js +0 -1351
- package/dist/core.cjs.development.js.map +0 -1
- package/dist/core.cjs.production.min.js +0 -2
- package/dist/core.cjs.production.min.js.map +0 -1
- package/dist/core.esm.js +0 -1330
- package/dist/core.esm.js.map +0 -1
- package/dist/events.d.ts +0 -129
- package/dist/pure/index.d.ts +0 -36
- package/dist/transaction.d.ts +0 -69
- package/dist/types.d.ts +0 -19
- package/dist/utils.d.ts +0 -9
package/dist/index.d.ts
CHANGED
|
@@ -1,13 +1,541 @@
|
|
|
1
|
-
import { ClarityAbi } from '
|
|
2
|
-
import {
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
1
|
+
import { ClarityAbi as ClarityAbi$1, ClarityValue, ClarityAbiType as ClarityAbiType$1, ClarityAbiFunction as ClarityAbiFunction$1, ClarityAbiTypeTuple as ClarityAbiTypeTuple$1, ContractPrincipalCV } from 'micro-stacks/clarity';
|
|
2
|
+
import { StacksNetwork } from 'micro-stacks/network';
|
|
3
|
+
import { StacksTransaction } from 'micro-stacks/transactions';
|
|
4
|
+
|
|
5
|
+
declare type ClarityAbiTypeBuffer = {
|
|
6
|
+
buffer: {
|
|
7
|
+
length: number;
|
|
8
|
+
};
|
|
9
|
+
};
|
|
10
|
+
declare type ClarityAbiTypeStringAscii = {
|
|
11
|
+
'string-ascii': {
|
|
12
|
+
length: number;
|
|
13
|
+
};
|
|
14
|
+
};
|
|
15
|
+
declare type ClarityAbiTypeStringUtf8 = {
|
|
16
|
+
'string-utf8': {
|
|
17
|
+
length: number;
|
|
18
|
+
};
|
|
19
|
+
};
|
|
20
|
+
declare type ClarityAbiTypeResponse = {
|
|
21
|
+
response: {
|
|
22
|
+
ok: ClarityAbiType;
|
|
23
|
+
error: ClarityAbiType;
|
|
24
|
+
};
|
|
25
|
+
};
|
|
26
|
+
declare type ClarityAbiTypeOptional = {
|
|
27
|
+
optional: ClarityAbiType;
|
|
28
|
+
};
|
|
29
|
+
declare type ClarityAbiTypeTuple = {
|
|
30
|
+
tuple: {
|
|
31
|
+
name: string;
|
|
32
|
+
type: ClarityAbiType;
|
|
33
|
+
}[];
|
|
34
|
+
};
|
|
35
|
+
declare type ClarityAbiTypeList = {
|
|
36
|
+
list: {
|
|
37
|
+
type: ClarityAbiType;
|
|
38
|
+
length: number;
|
|
39
|
+
};
|
|
40
|
+
};
|
|
41
|
+
declare type ClarityAbiTypeUInt128 = 'uint128';
|
|
42
|
+
declare type ClarityAbiTypeInt128 = 'int128';
|
|
43
|
+
declare type ClarityAbiTypeBool = 'bool';
|
|
44
|
+
declare type ClarityAbiTypePrincipal = 'principal';
|
|
45
|
+
declare type ClarityAbiTypeTraitReference = 'trait_reference';
|
|
46
|
+
declare type ClarityAbiTypeNone = 'none';
|
|
47
|
+
declare type ClarityAbiTypePrimitive = ClarityAbiTypeUInt128 | ClarityAbiTypeInt128 | ClarityAbiTypeBool | ClarityAbiTypePrincipal | ClarityAbiTypeTraitReference | ClarityAbiTypeNone;
|
|
48
|
+
declare type ClarityAbiType = ClarityAbiTypePrimitive | ClarityAbiTypeBuffer | ClarityAbiTypeResponse | ClarityAbiTypeOptional | ClarityAbiTypeTuple | ClarityAbiTypeList | ClarityAbiTypeStringAscii | ClarityAbiTypeStringUtf8 | ClarityAbiTypeTraitReference;
|
|
49
|
+
interface ClarityAbiArg {
|
|
50
|
+
name: string;
|
|
51
|
+
type: ClarityAbiType;
|
|
52
|
+
}
|
|
53
|
+
interface ClarityAbiFunction {
|
|
54
|
+
name: string;
|
|
55
|
+
access: 'private' | 'public' | 'read_only';
|
|
56
|
+
args: ClarityAbiArg[];
|
|
57
|
+
outputs: {
|
|
58
|
+
type: ClarityAbiType;
|
|
59
|
+
};
|
|
60
|
+
}
|
|
61
|
+
declare type TypedAbiArg<T, N extends string> = {
|
|
62
|
+
_t?: T;
|
|
63
|
+
name: N;
|
|
64
|
+
};
|
|
65
|
+
declare type TypedAbiFunction<T extends TypedAbiArg<unknown, string>[], R> = ClarityAbiFunction & {
|
|
66
|
+
_t?: T;
|
|
67
|
+
_r?: R;
|
|
68
|
+
};
|
|
69
|
+
interface ClarityAbiVariable {
|
|
70
|
+
name: string;
|
|
71
|
+
access: 'variable' | 'constant';
|
|
72
|
+
type: ClarityAbiType;
|
|
73
|
+
}
|
|
74
|
+
declare type TypedAbiVariable<T> = ClarityAbiVariable & {
|
|
75
|
+
defaultValue: T;
|
|
76
|
+
};
|
|
77
|
+
interface ClarityAbiMap {
|
|
78
|
+
name: string;
|
|
79
|
+
key: ClarityAbiType;
|
|
80
|
+
value: ClarityAbiType;
|
|
81
|
+
}
|
|
82
|
+
declare type TypedAbiMap<K, V> = ClarityAbiMap & {
|
|
83
|
+
_k?: K;
|
|
84
|
+
_v?: V;
|
|
85
|
+
};
|
|
86
|
+
interface ClarityAbiTypeFungibleToken {
|
|
87
|
+
name: string;
|
|
88
|
+
}
|
|
89
|
+
interface ClarityAbiTypeNonFungibleToken {
|
|
90
|
+
name: string;
|
|
91
|
+
type: ClarityAbiType;
|
|
92
|
+
}
|
|
93
|
+
declare type TypedAbi = Readonly<{
|
|
94
|
+
functions: {
|
|
95
|
+
[key: string]: TypedAbiFunction<TypedAbiArg<unknown, string>[], unknown>;
|
|
96
|
+
};
|
|
97
|
+
variables: {
|
|
98
|
+
[key: string]: TypedAbiVariable<unknown>;
|
|
99
|
+
};
|
|
100
|
+
maps: {
|
|
101
|
+
[key: string]: TypedAbiMap<unknown, unknown>;
|
|
102
|
+
};
|
|
103
|
+
constants: {
|
|
104
|
+
[key: string]: any;
|
|
105
|
+
};
|
|
106
|
+
fungible_tokens: Readonly<ClarityAbiTypeFungibleToken[]>;
|
|
107
|
+
non_fungible_tokens: Readonly<ClarityAbiTypeNonFungibleToken[]>;
|
|
108
|
+
contractName: string;
|
|
109
|
+
contractFile?: string;
|
|
110
|
+
}>;
|
|
111
|
+
interface ResponseOk<T, E> {
|
|
112
|
+
value: T;
|
|
113
|
+
isOk: true;
|
|
114
|
+
_e?: E;
|
|
115
|
+
}
|
|
116
|
+
interface ResponseErr<T, E> {
|
|
117
|
+
value: E;
|
|
118
|
+
isOk: false;
|
|
119
|
+
_o?: T;
|
|
120
|
+
}
|
|
121
|
+
declare type Response<Ok, Err> = ResponseOk<Ok, Err> | ResponseErr<Ok, Err>;
|
|
122
|
+
declare type OkType<R> = R extends ResponseOk<infer V, unknown> ? V : never;
|
|
123
|
+
declare type ErrType<R> = R extends ResponseErr<unknown, infer V> ? V : never;
|
|
124
|
+
|
|
125
|
+
declare function ok<T, Err = never>(value: T): ResponseOk<T, Err>;
|
|
126
|
+
declare function err<Ok = never, T = unknown>(value: T): ResponseErr<Ok, T>;
|
|
127
|
+
interface ClarityAbi extends Omit<ClarityAbi$1, 'maps'> {
|
|
128
|
+
maps: ClarityAbiMap[];
|
|
129
|
+
clarity_version?: string;
|
|
130
|
+
}
|
|
131
|
+
/**
|
|
132
|
+
* @param val - ClarityValue
|
|
133
|
+
* @param returnResponse - if true, this will return a "response" object.
|
|
134
|
+
* Otherwise, it returns the inner value of the response (whether ok or err)
|
|
135
|
+
*/
|
|
136
|
+
declare function cvToValue<T = any>(val: ClarityValue, returnResponse?: boolean): T;
|
|
137
|
+
/**
|
|
138
|
+
* Converts a hex encoded string to the javascript clarity value object {type: string; value: any}
|
|
139
|
+
* @param hex - the hex encoded string with or without `0x` prefix
|
|
140
|
+
* @param jsonCompat - enable to serialize bigints to strings
|
|
141
|
+
*/
|
|
142
|
+
declare function hexToCvValue<T>(hex: string, jsonCompat?: boolean): any;
|
|
143
|
+
declare type TupleInput = Record<string, any>;
|
|
144
|
+
declare type CVInput = string | boolean | TupleInput | number | bigint;
|
|
145
|
+
declare function parseToCV(input: CVInput, type: ClarityAbiType$1): ClarityValue;
|
|
146
|
+
declare function cvToString(val: ClarityValue, encoding?: 'tryAscii' | 'hex'): string;
|
|
147
|
+
declare function transformObjectArgs(func: ClarityAbiFunction$1, args: Record<string, any>): ClarityValue[];
|
|
148
|
+
declare function transformArgsArray(func: ClarityAbiFunction$1, args: any[]): ClarityValue[];
|
|
149
|
+
declare function transformArgsToCV(func: ClarityAbiFunction$1, args: any[] | [Record<string, any>]): ClarityValue[];
|
|
150
|
+
declare function findJsTupleKey(key: string, input: Record<string, any>): string;
|
|
151
|
+
declare function expectOk<Ok>(response: Response<Ok, any>): Ok;
|
|
152
|
+
declare function expectErr<Err>(response: Response<any, Err>): Err;
|
|
153
|
+
declare type AbiPrimitiveTo<T extends ClarityAbiTypePrimitive> = T extends ClarityAbiTypeInt128 ? bigint : T extends ClarityAbiTypeUInt128 ? bigint : T extends ClarityAbiTypeBool ? boolean : T extends ClarityAbiTypePrincipal ? string : T extends ClarityAbiTypeTraitReference ? string : T extends ClarityAbiTypeNone ? never : T;
|
|
154
|
+
declare type ReadonlyTuple = {
|
|
155
|
+
readonly tuple: Readonly<ClarityAbiTypeTuple$1['tuple']>;
|
|
156
|
+
};
|
|
157
|
+
declare type TupleTypeUnion<T> = T extends Readonly<ClarityAbiTypeTuple$1['tuple'][number]> ? {
|
|
158
|
+
-readonly [Z in T['name']]: AbiTypeTo<T['type']>;
|
|
159
|
+
} : never;
|
|
160
|
+
declare type UnionToIntersection$1<U> = (U extends any ? (k: U) => void : never) extends (k: infer I) => void ? I : never;
|
|
161
|
+
declare type Compact$1<T> = {
|
|
162
|
+
[K in keyof T]: T[K];
|
|
163
|
+
};
|
|
164
|
+
declare type AbiTupleTo<T extends ReadonlyTuple> = Compact$1<UnionToIntersection$1<TupleTypeUnion<T['tuple'][number]>>>;
|
|
165
|
+
declare type AbiTypeTo<T extends ClarityAbiType$1 | ReadonlyTuple> = T extends ClarityAbiTypePrimitive ? AbiPrimitiveTo<T> : T extends ClarityAbiTypeBuffer ? Uint8Array : T extends ClarityAbiTypeStringAscii ? string : T extends ClarityAbiTypeStringUtf8 ? string : T extends ClarityAbiTypeList ? AbiTypeTo<T['list']['type']>[] : T extends ClarityAbiTypeOptional ? AbiTypeTo<T['optional']> | null : T extends ClarityAbiTypeResponse ? Response<AbiTypeTo<T['response']['ok']>, AbiTypeTo<T['response']['error']>> : T extends ReadonlyTuple ? AbiTupleTo<T> : T;
|
|
166
|
+
|
|
167
|
+
interface ResultAssets {
|
|
168
|
+
stx: Record<string, string>;
|
|
169
|
+
burns: Record<string, string>;
|
|
170
|
+
tokens: Record<string, Record<string, string>>;
|
|
171
|
+
assets: Record<string, Record<string, string>>;
|
|
172
|
+
}
|
|
173
|
+
|
|
174
|
+
declare type ContractBuilder<T> = (contractAddress: string, contractName: string) => T;
|
|
175
|
+
interface Contract<T> {
|
|
176
|
+
address: string;
|
|
177
|
+
contractFile: string;
|
|
178
|
+
contract: ContractBuilder<T>;
|
|
179
|
+
abi: ClarityAbi;
|
|
180
|
+
name: string;
|
|
181
|
+
}
|
|
182
|
+
interface Contracts<T> {
|
|
183
|
+
[key: string]: Contract<T>;
|
|
184
|
+
}
|
|
185
|
+
interface ContractInstance<T> {
|
|
186
|
+
identifier: string;
|
|
187
|
+
contract: T;
|
|
188
|
+
}
|
|
189
|
+
declare type ContractInstances<T extends Contracts<any>> = {
|
|
190
|
+
[Name in keyof T]: ContractInstance<ReturnType<T[Name]['contract']>>;
|
|
191
|
+
};
|
|
192
|
+
|
|
193
|
+
declare const TESTNET_BURN_ADDRESS = "ST000000000000000000002AMW42H";
|
|
194
|
+
declare const MAINNET_BURN_ADDRESS = "SP000000000000000000002Q6VF78";
|
|
195
|
+
declare const toCamelCase: (input: string | number | symbol, titleCase?: boolean) => string;
|
|
196
|
+
declare function toKebabCase(input: string): string;
|
|
197
|
+
declare const getContractNameFromPath: (path: string) => string;
|
|
198
|
+
declare const getContractIdentifier: <T>(contract: Contract<T>) => string;
|
|
199
|
+
declare const getContractPrincipalCV: <T>(contract: Contract<T>) => ContractPrincipalCV;
|
|
200
|
+
declare function bootContractIdentifier(name: string, mainnet: boolean): string;
|
|
201
|
+
|
|
202
|
+
declare enum CoreNodeEventType {
|
|
203
|
+
ContractEvent = "contract_event",
|
|
204
|
+
StxTransferEvent = "stx_transfer_event",
|
|
205
|
+
StxMintEvent = "stx_mint_event",
|
|
206
|
+
StxBurnEvent = "stx_burn_event",
|
|
207
|
+
StxLockEvent = "stx_lock_event",
|
|
208
|
+
NftTransferEvent = "nft_transfer_event",
|
|
209
|
+
NftMintEvent = "nft_mint_event",
|
|
210
|
+
NftBurnEvent = "nft_burn_event",
|
|
211
|
+
FtTransferEvent = "ft_transfer_event",
|
|
212
|
+
FtMintEvent = "ft_mint_event",
|
|
213
|
+
FtBurnEvent = "ft_burn_event"
|
|
214
|
+
}
|
|
215
|
+
declare type NonStandardClarityValue = unknown;
|
|
216
|
+
interface CoreNodeEventBase {
|
|
217
|
+
/** 0x-prefix transaction hash. */
|
|
218
|
+
txid: string;
|
|
219
|
+
event_index: number;
|
|
220
|
+
committed: boolean;
|
|
221
|
+
}
|
|
222
|
+
interface SmartContractEvent extends CoreNodeEventBase {
|
|
223
|
+
type: CoreNodeEventType.ContractEvent;
|
|
224
|
+
contract_event: {
|
|
225
|
+
/** Fully qualified contract ID, e.g. "ST2ZRX0K27GW0SP3GJCEMHD95TQGJMKB7G9Y0X1MH.kv-store" */
|
|
226
|
+
contract_identifier: string;
|
|
227
|
+
topic: string;
|
|
228
|
+
value: NonStandardClarityValue;
|
|
229
|
+
/** Hex encoded Clarity value. */
|
|
230
|
+
raw_value: string;
|
|
231
|
+
};
|
|
232
|
+
}
|
|
233
|
+
interface StxTransferEvent extends CoreNodeEventBase {
|
|
234
|
+
type: CoreNodeEventType.StxTransferEvent;
|
|
235
|
+
stx_transfer_event: {
|
|
236
|
+
recipient: string;
|
|
237
|
+
sender: string;
|
|
238
|
+
amount: string;
|
|
239
|
+
};
|
|
240
|
+
}
|
|
241
|
+
interface StxMintEvent extends CoreNodeEventBase {
|
|
242
|
+
type: CoreNodeEventType.StxMintEvent;
|
|
243
|
+
stx_mint_event: {
|
|
244
|
+
recipient: string;
|
|
245
|
+
amount: string;
|
|
246
|
+
};
|
|
247
|
+
}
|
|
248
|
+
interface StxBurnEvent extends CoreNodeEventBase {
|
|
249
|
+
type: CoreNodeEventType.StxBurnEvent;
|
|
250
|
+
stx_burn_event: {
|
|
251
|
+
sender: string;
|
|
252
|
+
amount: string;
|
|
253
|
+
};
|
|
254
|
+
}
|
|
255
|
+
interface StxLockEvent extends CoreNodeEventBase {
|
|
256
|
+
type: CoreNodeEventType.StxLockEvent;
|
|
257
|
+
/** TODO: what dis? */
|
|
258
|
+
committed: boolean;
|
|
259
|
+
stx_lock_event: {
|
|
260
|
+
/** String quoted base10 integer. */
|
|
261
|
+
locked_amount: string;
|
|
262
|
+
/** String quoted base10 integer. */
|
|
263
|
+
unlock_height: string;
|
|
264
|
+
/** STX principal associated with the locked tokens. */
|
|
265
|
+
locked_address: string;
|
|
266
|
+
};
|
|
267
|
+
}
|
|
268
|
+
interface NftTransferEvent extends CoreNodeEventBase {
|
|
269
|
+
type: CoreNodeEventType.NftTransferEvent;
|
|
270
|
+
nft_transfer_event: {
|
|
271
|
+
/** Fully qualified asset ID, e.g. "ST2ZRX0K27GW0SP3GJCEMHD95TQGJMKB7G9Y0X1MH.contract-name.asset-name" */
|
|
272
|
+
asset_identifier: string;
|
|
273
|
+
recipient: string;
|
|
274
|
+
sender: string;
|
|
275
|
+
value: NonStandardClarityValue;
|
|
276
|
+
/** Hex encoded Clarity value. */
|
|
277
|
+
raw_value: string;
|
|
278
|
+
};
|
|
279
|
+
}
|
|
280
|
+
interface NftMintEvent extends CoreNodeEventBase {
|
|
281
|
+
type: CoreNodeEventType.NftMintEvent;
|
|
282
|
+
nft_mint_event: {
|
|
283
|
+
/** Fully qualified asset ID, e.g. "ST2ZRX0K27GW0SP3GJCEMHD95TQGJMKB7G9Y0X1MH.contract-name.asset-name" */
|
|
284
|
+
asset_identifier: string;
|
|
285
|
+
recipient: string;
|
|
286
|
+
value: NonStandardClarityValue;
|
|
287
|
+
/** Hex encoded Clarity value. */
|
|
288
|
+
raw_value: string;
|
|
289
|
+
};
|
|
290
|
+
}
|
|
291
|
+
interface NftBurnEvent extends CoreNodeEventBase {
|
|
292
|
+
type: CoreNodeEventType.NftBurnEvent;
|
|
293
|
+
nft_burn_event: {
|
|
294
|
+
/** Fully qualified asset ID, e.g. "ST2ZRX0K27GW0SP3GJCEMHD95TQGJMKB7G9Y0X1MH.contract-name.asset-name" */
|
|
295
|
+
asset_identifier: string;
|
|
296
|
+
sender: string;
|
|
297
|
+
value: NonStandardClarityValue;
|
|
298
|
+
/** Hex encoded Clarity value. */
|
|
299
|
+
raw_value: string;
|
|
300
|
+
};
|
|
301
|
+
}
|
|
302
|
+
interface FtTransferEvent extends CoreNodeEventBase {
|
|
303
|
+
type: CoreNodeEventType.FtTransferEvent;
|
|
304
|
+
ft_transfer_event: {
|
|
305
|
+
/** Fully qualified asset ID, e.g. "ST2ZRX0K27GW0SP3GJCEMHD95TQGJMKB7G9Y0X1MH.contract-name.asset-name" */
|
|
306
|
+
asset_identifier: string;
|
|
307
|
+
recipient: string;
|
|
308
|
+
sender: string;
|
|
309
|
+
amount: string;
|
|
310
|
+
};
|
|
311
|
+
}
|
|
312
|
+
interface FtMintEvent extends CoreNodeEventBase {
|
|
313
|
+
type: CoreNodeEventType.FtMintEvent;
|
|
314
|
+
ft_mint_event: {
|
|
315
|
+
/** Fully qualified asset ID, e.g. "ST2ZRX0K27GW0SP3GJCEMHD95TQGJMKB7G9Y0X1MH.contract-name.asset-name" */
|
|
316
|
+
asset_identifier: string;
|
|
317
|
+
recipient: string;
|
|
318
|
+
amount: string;
|
|
319
|
+
};
|
|
320
|
+
}
|
|
321
|
+
interface FtBurnEvent extends CoreNodeEventBase {
|
|
322
|
+
type: CoreNodeEventType.FtBurnEvent;
|
|
323
|
+
ft_burn_event: {
|
|
324
|
+
/** Fully qualified asset ID, e.g. "ST2ZRX0K27GW0SP3GJCEMHD95TQGJMKB7G9Y0X1MH.contract-name.asset-name" */
|
|
325
|
+
asset_identifier: string;
|
|
326
|
+
sender: string;
|
|
327
|
+
amount: string;
|
|
328
|
+
};
|
|
329
|
+
}
|
|
330
|
+
declare type CoreNodeEvent = SmartContractEvent | StxTransferEvent | StxMintEvent | StxBurnEvent | StxLockEvent | FtTransferEvent | FtMintEvent | FtBurnEvent | NftTransferEvent | NftMintEvent | NftBurnEvent;
|
|
331
|
+
declare function filterEvents(events: CoreNodeEvent[], type: CoreNodeEventType.ContractEvent): SmartContractEvent[];
|
|
332
|
+
declare function filterEvents(events: CoreNodeEvent[], type: CoreNodeEventType.StxTransferEvent): StxTransferEvent[];
|
|
333
|
+
declare function filterEvents(events: CoreNodeEvent[], type: CoreNodeEventType.StxMintEvent): StxMintEvent[];
|
|
334
|
+
declare function filterEvents(events: CoreNodeEvent[], type: CoreNodeEventType.StxBurnEvent): StxBurnEvent[];
|
|
335
|
+
declare function filterEvents(events: CoreNodeEvent[], type: CoreNodeEventType.StxLockEvent): StxLockEvent[];
|
|
336
|
+
declare function filterEvents(events: CoreNodeEvent[], type: CoreNodeEventType.NftTransferEvent): NftTransferEvent[];
|
|
337
|
+
declare function filterEvents(events: CoreNodeEvent[], type: CoreNodeEventType.NftMintEvent): NftMintEvent[];
|
|
338
|
+
declare function filterEvents(events: CoreNodeEvent[], type: CoreNodeEventType.NftBurnEvent): NftBurnEvent[];
|
|
339
|
+
declare function filterEvents(events: CoreNodeEvent[], type: CoreNodeEventType.FtTransferEvent): FtTransferEvent[];
|
|
340
|
+
declare function filterEvents(events: CoreNodeEvent[], type: CoreNodeEventType.FtMintEvent): FtMintEvent[];
|
|
341
|
+
declare function filterEvents(events: CoreNodeEvent[], type: CoreNodeEventType.FtBurnEvent): FtBurnEvent[];
|
|
342
|
+
|
|
343
|
+
interface MakeContractsOptions {
|
|
344
|
+
deployerAddress?: string;
|
|
345
|
+
}
|
|
346
|
+
declare function makeContracts<T extends Contracts<any>>(contracts: T, options?: MakeContractsOptions): ContractInstances<T>;
|
|
347
|
+
|
|
348
|
+
interface ContractCall<T> {
|
|
349
|
+
function: ClarityAbiFunction;
|
|
350
|
+
nativeArgs: any[];
|
|
351
|
+
functionArgs: ClarityValue[];
|
|
352
|
+
contractAddress: string;
|
|
353
|
+
contractName: string;
|
|
354
|
+
_r?: T;
|
|
355
|
+
}
|
|
356
|
+
interface ContractCallTyped<Args extends UnknownArgs, R> extends Omit<ContractCall<R>, 'nativeArgs'> {
|
|
357
|
+
nativeArgs: ArgsType<Args>;
|
|
358
|
+
}
|
|
359
|
+
declare type ContractFunctions = {
|
|
360
|
+
[key: string]: TypedAbiFunction<UnknownArgs, unknown>;
|
|
361
|
+
};
|
|
362
|
+
declare type AllContracts = Record<string, TypedAbi>;
|
|
363
|
+
declare type UnknownArg = TypedAbiArg<unknown, string>;
|
|
364
|
+
declare type UnknownArgs = UnknownArg[];
|
|
365
|
+
declare type ArgsTuple<T extends UnknownArgs> = {
|
|
366
|
+
[K in keyof T]: T[K] extends TypedAbiArg<infer A, string> ? A : never;
|
|
367
|
+
};
|
|
368
|
+
declare type ArgsRecordUnion<T extends TypedAbiArg<unknown, string>> = T extends TypedAbiArg<infer A, infer N> ? {
|
|
369
|
+
[K in T as N]: A;
|
|
370
|
+
} : never;
|
|
371
|
+
declare type InnerUnionToIntersection<U> = (U extends any ? (k: U) => void : never) extends (k: infer I) => void ? I : never;
|
|
372
|
+
declare type Compact<T> = {
|
|
373
|
+
[K in keyof T]: T[K];
|
|
374
|
+
};
|
|
375
|
+
declare type UnionToIntersection<T> = Compact<InnerUnionToIntersection<T>>;
|
|
376
|
+
declare type ArgsRecord<T extends UnknownArgs> = UnionToIntersection<ArgsRecordUnion<T[number]>>;
|
|
377
|
+
declare type ArgsType<T extends UnknownArgs> = [ArgsRecord<T>] | ArgsTuple<T>;
|
|
378
|
+
declare type ContractCallFunction<Args extends UnknownArgs, R> = (...args: ArgsType<Args>) => ContractCallTyped<Args, R>;
|
|
379
|
+
declare type FnToContractCall<T> = T extends TypedAbiFunction<infer Arg, infer R> ? ContractCallFunction<Arg, R> : never;
|
|
380
|
+
declare type FunctionsToContractCalls<T> = T extends ContractFunctions ? {
|
|
381
|
+
[key in keyof T]: FnToContractCall<T[key]>;
|
|
382
|
+
} : never;
|
|
383
|
+
declare type ContractsToContractCalls<T> = T extends AllContracts ? {
|
|
384
|
+
[key in keyof T]: FunctionsToContractCalls<T[key]['functions']>;
|
|
385
|
+
} : never;
|
|
386
|
+
declare type FullContract<T> = T extends TypedAbi ? FunctionsToContractCalls<T['functions']> & T & {
|
|
387
|
+
identifier: string;
|
|
388
|
+
} & {
|
|
389
|
+
contractFile: string;
|
|
390
|
+
} : never;
|
|
391
|
+
declare type ContractFactory<T extends AllContracts> = {
|
|
392
|
+
[key in keyof T]: FullContract<T[key]>;
|
|
393
|
+
};
|
|
394
|
+
|
|
395
|
+
interface PureContractInfo {
|
|
396
|
+
abi: ClarityAbi;
|
|
397
|
+
contractAddress: string;
|
|
398
|
+
contractName: string;
|
|
399
|
+
}
|
|
400
|
+
declare type ContractFn<T> = (args: any) => T;
|
|
401
|
+
declare type ContractReturn<C extends ContractFn<ContractCalls.ReadOnly<any>>> = C extends ContractFn<ContractCalls.ReadOnly<infer T>> ? T : unknown;
|
|
402
|
+
declare type ContractReturnOk<C extends ContractFn<ContractCalls.ReadOnly<any>>> = ContractReturn<C> extends Response<infer O, any> ? O : unknown;
|
|
403
|
+
declare type ContractReturnErr<C extends ContractFn<ContractCalls.ReadOnly<any>>> = ContractReturn<C> extends Response<any, infer E> ? E : unknown;
|
|
404
|
+
interface MapGet<Key, Val> {
|
|
405
|
+
map: ClarityAbiMap;
|
|
406
|
+
nativeKey: Key;
|
|
407
|
+
key: ClarityValue;
|
|
408
|
+
contractAddress: string;
|
|
409
|
+
contractName: string;
|
|
410
|
+
}
|
|
411
|
+
declare namespace ContractCalls {
|
|
412
|
+
type ReadOnly<T> = ContractCall<T>;
|
|
413
|
+
type Public<Ok, Err> = ContractCall<Response<Ok, Err>>;
|
|
414
|
+
type Private<T> = ContractCall<T>;
|
|
415
|
+
type Map<Key, Val> = MapGet<Key, Val>;
|
|
416
|
+
}
|
|
417
|
+
declare const pureProxy: <T extends object>(target: PureContractInfo) => T;
|
|
418
|
+
|
|
419
|
+
interface ApiOptions {
|
|
420
|
+
network: StacksNetwork;
|
|
421
|
+
}
|
|
422
|
+
declare function ro<T>(tx: ContractCall<T>, options: ApiOptions): Promise<T>;
|
|
423
|
+
declare function roOk<Ok>(tx: ContractCall<Response<Ok, any>>, options: ApiOptions): Promise<Ok>;
|
|
424
|
+
declare function roErr<Err>(tx: ContractCall<Response<any, Err>>, options: ApiOptions): Promise<Err>;
|
|
425
|
+
declare function fetchMapGet<T extends ContractCalls.Map<any, Val>, Val>(map: T, options: ApiOptions): Promise<Val | null>;
|
|
426
|
+
declare function broadcast(transaction: StacksTransaction, options: ApiOptions): Promise<{
|
|
427
|
+
txId: string;
|
|
428
|
+
stacksTransaction: StacksTransaction;
|
|
429
|
+
}>;
|
|
430
|
+
|
|
431
|
+
interface EmulatedContractPublishTransaction {
|
|
432
|
+
'emulated-contract-publish': {
|
|
433
|
+
'contract-name': string;
|
|
434
|
+
'emulated-sender': string;
|
|
435
|
+
path: string;
|
|
436
|
+
};
|
|
437
|
+
}
|
|
438
|
+
interface RequirementPublishTransaction {
|
|
439
|
+
'requirement-publish': {
|
|
440
|
+
'contract-id': string;
|
|
441
|
+
'remap-sender': string;
|
|
442
|
+
'remap-principals': Record<string, string>;
|
|
443
|
+
path: string;
|
|
444
|
+
};
|
|
445
|
+
}
|
|
446
|
+
interface ContractPublishTransaction {
|
|
447
|
+
'contract-publish': {
|
|
448
|
+
'contract-name': string;
|
|
449
|
+
'expected-sender': string;
|
|
450
|
+
path: string;
|
|
451
|
+
};
|
|
452
|
+
}
|
|
453
|
+
interface ContractCallTransaction {
|
|
454
|
+
'contract-call': {
|
|
455
|
+
'contract-id': string;
|
|
456
|
+
'expected-sender': string;
|
|
457
|
+
parameters: Readonly<string[]>;
|
|
458
|
+
method: string;
|
|
459
|
+
};
|
|
460
|
+
}
|
|
461
|
+
interface EmulatedContractCallTransaction {
|
|
462
|
+
'emulated-contract-call': {
|
|
463
|
+
'contract-id': string;
|
|
464
|
+
'emulated-sender': string;
|
|
465
|
+
parameters: Readonly<string[]>;
|
|
466
|
+
method: string;
|
|
467
|
+
};
|
|
468
|
+
}
|
|
469
|
+
interface BtcTransferTransaction {
|
|
470
|
+
'btc-transfer': {
|
|
471
|
+
'expected-sender': string;
|
|
472
|
+
recipient: string;
|
|
473
|
+
'sats-per-byte': string;
|
|
474
|
+
'sats-amount': string;
|
|
475
|
+
};
|
|
476
|
+
}
|
|
477
|
+
declare type Transaction = EmulatedContractPublishTransaction | RequirementPublishTransaction | ContractPublishTransaction | EmulatedContractCallTransaction | BtcTransferTransaction | ContractCallTransaction;
|
|
478
|
+
interface Batch<T extends Transaction> {
|
|
479
|
+
id: number;
|
|
480
|
+
transactions: Readonly<T[]>;
|
|
481
|
+
}
|
|
482
|
+
interface SimnetAccount {
|
|
483
|
+
address: string;
|
|
484
|
+
name: string;
|
|
485
|
+
balance: string;
|
|
486
|
+
}
|
|
487
|
+
interface SimnetAccountDeployer extends SimnetAccount {
|
|
488
|
+
name: 'deployer';
|
|
489
|
+
}
|
|
490
|
+
interface SimnetDeploymentPlan {
|
|
491
|
+
network: 'simnet';
|
|
492
|
+
genesis: {
|
|
493
|
+
wallets: Readonly<[SimnetAccountDeployer, ...SimnetAccount[]]>;
|
|
494
|
+
contracts: Readonly<string[]>;
|
|
495
|
+
};
|
|
496
|
+
plan: {
|
|
497
|
+
batches: Readonly<Batch<EmulatedContractPublishTransaction | EmulatedContractCallTransaction>[]>;
|
|
498
|
+
};
|
|
499
|
+
}
|
|
500
|
+
interface DevnetDeploymentPlan {
|
|
501
|
+
network: 'devnet';
|
|
502
|
+
plan: {
|
|
503
|
+
batches: Readonly<Batch<RequirementPublishTransaction | ContractPublishTransaction | ContractCallTransaction | BtcTransferTransaction>[]>;
|
|
504
|
+
};
|
|
505
|
+
}
|
|
506
|
+
declare type TestnetDeploymentPlan = Omit<DevnetDeploymentPlan, 'network'> & {
|
|
507
|
+
network: 'testnet';
|
|
508
|
+
};
|
|
509
|
+
interface MainnetDeploymentPlan {
|
|
510
|
+
network: 'mainnet';
|
|
511
|
+
plan: {
|
|
512
|
+
batches: Readonly<Batch<ContractPublishTransaction | ContractCallTransaction | BtcTransferTransaction>[]>;
|
|
513
|
+
};
|
|
514
|
+
}
|
|
515
|
+
declare type DeploymentPlan = SimnetDeploymentPlan | DevnetDeploymentPlan | TestnetDeploymentPlan | MainnetDeploymentPlan;
|
|
516
|
+
|
|
517
|
+
declare const DEPLOYMENT_NETWORKS: readonly ["devnet", "simnet", "testnet", "mainnet"];
|
|
518
|
+
declare type DeploymentNetwork = typeof DEPLOYMENT_NETWORKS[number];
|
|
519
|
+
declare type DeploymentsForContracts<C extends AllContracts> = {
|
|
520
|
+
[K in keyof C]: ContractDeployments;
|
|
521
|
+
};
|
|
522
|
+
declare type ContractDeployments = {
|
|
523
|
+
[key in DeploymentNetwork]: string | null;
|
|
524
|
+
};
|
|
525
|
+
declare type Project<C extends AllContracts, D extends DeploymentsForContracts<C>> = {
|
|
526
|
+
contracts: C;
|
|
527
|
+
deployments: D;
|
|
528
|
+
};
|
|
529
|
+
declare type FullContractWithIdentifier<C extends TypedAbi, Id extends string> = FullContract<C> & {
|
|
530
|
+
identifier: Id;
|
|
531
|
+
};
|
|
532
|
+
declare type ProjectFactory<P extends Project<any, any>, N extends DeploymentNetwork> = {
|
|
533
|
+
[ContractName in keyof P['contracts']]: P['deployments'][ContractName][N] extends string ? FullContractWithIdentifier<P['contracts'][ContractName], P['deployments'][ContractName][N]> : undefined;
|
|
534
|
+
};
|
|
535
|
+
declare function projectFactory<P extends Project<C, D>, N extends DeploymentNetwork, C extends AllContracts, D extends DeploymentsForContracts<C>>(project: P, network: N): ProjectFactory<P, N>;
|
|
536
|
+
declare function contractsFactory<T extends AllContracts>(contracts: T, deployer: string): ContractFactory<T>;
|
|
537
|
+
declare function functionsFactory<T extends ContractFunctions>(functions: T, identifier: string): FunctionsToContractCalls<T>;
|
|
538
|
+
declare function contractFactory<T extends TypedAbi, Id extends string>(abi: T, identifier: Id): FullContractWithIdentifier<T, Id>;
|
|
539
|
+
declare function deploymentFactory<T extends AllContracts>(contracts: T, deployer: DeploymentPlan): ContractFactory<T>;
|
|
540
|
+
|
|
541
|
+
export { AbiPrimitiveTo, AbiTupleTo, AbiTypeTo, AllContracts, ArgsType, ClarityAbi, ClarityAbiArg, ClarityAbiFunction, ClarityAbiMap, ClarityAbiType, ClarityAbiTypeBool, ClarityAbiTypeBuffer, ClarityAbiTypeFungibleToken, ClarityAbiTypeInt128, ClarityAbiTypeList, ClarityAbiTypeNonFungibleToken, ClarityAbiTypeNone, ClarityAbiTypeOptional, ClarityAbiTypePrimitive, ClarityAbiTypePrincipal, ClarityAbiTypeResponse, ClarityAbiTypeStringAscii, ClarityAbiTypeStringUtf8, ClarityAbiTypeTraitReference, ClarityAbiTypeTuple, ClarityAbiTypeUInt128, ClarityAbiVariable, Contract, ContractBuilder, ContractCall, ContractCallFunction, ContractCallTyped, ContractCalls, ContractDeployments, ContractFactory, ContractFn, ContractFunctions, ContractInstance, ContractInstances, ContractReturn, ContractReturnErr, ContractReturnOk, Contracts, ContractsToContractCalls, CoreNodeEvent, CoreNodeEventBase, CoreNodeEventType, DEPLOYMENT_NETWORKS, DeploymentNetwork, DeploymentPlan, DeploymentsForContracts, ErrType, FnToContractCall, FtBurnEvent, FtMintEvent, FtTransferEvent, FullContract, FullContractWithIdentifier, FunctionsToContractCalls, MAINNET_BURN_ADDRESS, NftBurnEvent, NftMintEvent, NftTransferEvent, NonStandardClarityValue, OkType, Project, ProjectFactory, Response, ResponseErr, ResponseOk, ResultAssets, SimnetDeploymentPlan, SmartContractEvent, StxBurnEvent, StxLockEvent, StxMintEvent, StxTransferEvent, TESTNET_BURN_ADDRESS, TypedAbi, TypedAbiArg, TypedAbiFunction, TypedAbiMap, TypedAbiVariable, UnionToIntersection, bootContractIdentifier, broadcast, contractFactory, contractsFactory, cvToString, cvToValue, deploymentFactory, err, expectErr, expectOk, fetchMapGet, filterEvents, findJsTupleKey, functionsFactory, getContractIdentifier, getContractNameFromPath, getContractPrincipalCV, hexToCvValue, makeContracts, ok, parseToCV, projectFactory, pureProxy, ro, roErr, roOk, toCamelCase, toKebabCase, transformArgsArray, transformArgsToCV, transformObjectArgs };
|
package/dist/index.js
CHANGED
|
@@ -1,8 +1 @@
|
|
|
1
|
-
|
|
2
|
-
'use strict'
|
|
3
|
-
|
|
4
|
-
if (process.env.NODE_ENV === 'production') {
|
|
5
|
-
module.exports = require('./core.cjs.production.min.js')
|
|
6
|
-
} else {
|
|
7
|
-
module.exports = require('./core.cjs.development.js')
|
|
8
|
-
}
|
|
1
|
+
"use strict";Object.defineProperty(exports, "__esModule", {value: true});var K=Object.defineProperty,L=Object.defineProperties;var q=Object.getOwnPropertyDescriptors;var h=Object.getOwnPropertySymbols;var H=Object.prototype.hasOwnProperty,G=Object.prototype.propertyIsEnumerable;var N=(t,e,n)=>e in t?K(t,e,{enumerable:!0,configurable:!0,writable:!0,value:n}):t[e]=n,C=(t,e)=>{for(var n in e||(e={}))H.call(e,n)&&N(t,n,e[n]);if(h)for(var n of h(e))G.call(e,n)&&N(t,n,e[n]);return t},x=(t,e)=>L(t,q(e));var _clarity = require('micro-stacks/clarity');var W="ST000000000000000000002AMW42H",Z= exports.MAINNET_BURN_ADDRESS ="SP000000000000000000002Q6VF78",f= exports.toCamelCase =(t,e)=>{let n=typeof t=="string"?t:String(t),[r,...o]=n.replace("!","").replace("?","").split("-"),c=`${e?r[0].toUpperCase():r[0].toLowerCase()}${r.slice(1)}`;return o.forEach(s=>{c+=s[0].toUpperCase()+s.slice(1)}),c};function k(t){let e=t.match(/[A-Z]{2,}(?=[A-Z][a-z]+[0-9]*|\b)|[A-Z]?[a-z]+[0-9]*|[A-Z]|[0-9]+/g);return e?e.join("-").toLowerCase():t}var z=t=>{let e=t.split("/"),n=e[e.length-1],[r]=n.split(".");return r},Bt= exports.getContractIdentifier =t=>`${t.address}.${t.name}`,It= exports.getContractPrincipalCV =t=>{let e=z(t.contractFile);return _clarity.contractPrincipalCV.call(void 0, t.address,e)};function Vt(t,e){return`${e?Z:W}.${t}`}var Y=(l=>(l.ContractEvent="contract_event",l.StxTransferEvent="stx_transfer_event",l.StxMintEvent="stx_mint_event",l.StxBurnEvent="stx_burn_event",l.StxLockEvent="stx_lock_event",l.NftTransferEvent="nft_transfer_event",l.NftMintEvent="nft_mint_event",l.NftBurnEvent="nft_burn_event",l.FtTransferEvent="ft_transfer_event",l.FtMintEvent="ft_mint_event",l.FtBurnEvent="ft_burn_event",l))(Y||{});function $t(t,e){return t.filter(n=>n.type===e)}function Ut(t,e={}){let n={};for(let r in t){let o=t[r],i=e.deployerAddress||o.address,c=`${i}.${o.name}`,s=o.contract(i,o.name);n[r]={identifier:c,contract:s}}return n}var _transactions = require('micro-stacks/transactions');var _common = require('micro-stacks/common');function mt(t){return{isOk:!0,value:t}}function xt(t){return{isOk:!1,value:t}}function R(t){if(t.type===_clarity.ClarityType.PrincipalStandard)return _clarity.addressToString.call(void 0, t.address);if(t.type===_clarity.ClarityType.PrincipalContract)return`${_clarity.addressToString.call(void 0, t.address)}.${t.contractName.content}`;throw new Error(`Unexpected principal data: ${JSON.stringify(t)}`)}function p(t,e=!1){switch(t.type){case _clarity.ClarityType.BoolTrue:return!0;case _clarity.ClarityType.BoolFalse:return!1;case _clarity.ClarityType.Int:case _clarity.ClarityType.UInt:return t.value;case _clarity.ClarityType.Buffer:return t.buffer;case _clarity.ClarityType.OptionalNone:return null;case _clarity.ClarityType.OptionalSome:return p(t.value);case _clarity.ClarityType.ResponseErr:return e?xt(p(t.value)):p(t.value);case _clarity.ClarityType.ResponseOk:return e?mt(p(t.value)):p(t.value);case _clarity.ClarityType.PrincipalStandard:case _clarity.ClarityType.PrincipalContract:return R(t);case _clarity.ClarityType.List:return t.list.map(r=>p(r));case _clarity.ClarityType.Tuple:return Object.entries(t.data).reduce((r,[o,i])=>{let c=f(o);return x(C({},r),{[c]:p(i)})},{});case _clarity.ClarityType.StringASCII:return t.data;case _clarity.ClarityType.StringUTF8:return t.data}}function Xt(t,e=!1){return p(_clarity.hexToCV.call(void 0, t),e)}function w(t){if(!(typeof t=="bigint"||typeof t=="number"||typeof t=="string"))throw new Error("Invalid input type for integer");return BigInt(t)}function y(t,e){if(_transactions.isClarityAbiTuple.call(void 0, e)){if(typeof t!="object")throw new Error("Invalid tuple input");let n={};return e.tuple.forEach(r=>{let o=g(r.name,t),i=t[o];n[r.name]=y(i,r.type)}),_clarity.tupleCV.call(void 0, n)}else if(_transactions.isClarityAbiList.call(void 0, e)){let r=t.map(o=>y(o,e.list.type));return _clarity.listCV.call(void 0, r)}else{if(_transactions.isClarityAbiOptional.call(void 0, e))return t?_clarity.someCV.call(void 0, y(t,e.optional)):_clarity.noneCV.call(void 0, );if(_transactions.isClarityAbiStringAscii.call(void 0, e)){if(typeof t!="string")throw new Error("Invalid string-ascii input");return _clarity.stringAsciiCV.call(void 0, t)}else if(_transactions.isClarityAbiStringUtf8.call(void 0, e)){if(typeof t!="string")throw new Error("Invalid string-ascii input");return _clarity.stringUtf8CV.call(void 0, t)}else if(e==="bool"){let n=typeof t=="boolean"?t.toString():t;return _transactions.parseToCV.call(void 0, n,e)}else if(e==="uint128"){let n=w(t);return _clarity.uintCV.call(void 0, n.toString())}else if(e==="int128"){let n=w(t);return _clarity.intCV.call(void 0, n.toString())}else if(e==="trait_reference"){if(typeof t!="string")throw new Error("Invalid input for trait_reference");let[n,r]=t.split(".");return _clarity.contractPrincipalCV.call(void 0, n,r)}else if(_transactions.isClarityAbiBuffer.call(void 0, e))return _clarity.bufferCV.call(void 0, t)}return _transactions.parseToCV.call(void 0, t,e)}function T(t,e="hex"){switch(t.type){case _clarity.ClarityType.BoolTrue:return"true";case _clarity.ClarityType.BoolFalse:return"false";case _clarity.ClarityType.Int:return t.value.toString();case _clarity.ClarityType.UInt:return`u${t.value.toString()}`;case _clarity.ClarityType.Buffer:if(e==="tryAscii"){let n=_common.bytesToAscii.call(void 0, t.buffer);if(/[ -~]/.test(n))return JSON.stringify(n)}return`0x${_common.bytesToHex.call(void 0, t.buffer)}`;case _clarity.ClarityType.OptionalNone:return"none";case _clarity.ClarityType.OptionalSome:return`(some ${T(t.value,e)})`;case _clarity.ClarityType.ResponseErr:return`(err ${T(t.value,e)})`;case _clarity.ClarityType.ResponseOk:return`(ok ${T(t.value,e)})`;case _clarity.ClarityType.PrincipalStandard:case _clarity.ClarityType.PrincipalContract:return`'${R(t)}`;case _clarity.ClarityType.List:return`(list ${t.list.map(n=>T(n,e)).join(" ")})`;case _clarity.ClarityType.Tuple:return`(tuple ${Object.keys(t.data).map(n=>`(${n} ${T(t.data[n],e)})`).join(" ")})`;case _clarity.ClarityType.StringASCII:return`"${t.data}"`;case _clarity.ClarityType.StringUTF8:return`u"${t.data}"`}}function F(t,e){return t.args.map(n=>{let r=g(n.name,e),o=e[r];return y(o,n.type)})}function gt(t,e){return e.map((n,r)=>y(n,t.args[r].type))}function m(t,e){if(e.length===0)return[];let[n]=e;if(e.length===1&&t.args.length!==1)return F(t,n);if(typeof n=="object"&&!Array.isArray(n)&&n!==null)try{let r=!0;if(t.args.forEach(o=>{try{g(o.name,n)}catch (e2){r=!1}}),r)return F(t,n)}catch (e3){}return gt(t,e)}function g(t,e){let n=Object.keys(e).find(r=>{let o=t===r,i=t===k(r);return o||i});if(!n)throw new Error(`Error encoding JS tuple: ${t} not found in input.`);return n}function _(t){if(t.isOk)return t.value;throw new Error(`Expected OK, received error: ${String(t.value)}`)}function O(t){if(!t.isOk)return t.value;throw new Error(`Expected Err, received ok: ${String(t.value)}`)}function vt(t,e){let n=t.abi.functions.find(o=>f(o.name)===e);if(n)return function(...o){return{functionArgs:m(n,o),contractAddress:t.contractAddress,contractName:t.contractName,function:n,nativeArgs:o}};let r=t.abi.maps.find(o=>f(o.name)===e);if(r)return o=>{let i=y(o,r.key);return{contractAddress:t.contractAddress,contractName:t.contractName,map:r,nativeKey:o,key:i}};throw new Error(`Invalid function call: no function exists for ${String(e)}`)}var Et={get:vt},bt= exports.pureProxy =t=>new Proxy(t,Et);var _api = require('micro-stacks/api');async function I(t,e){let r=`${e.network.getReadOnlyFunctionCallApiUrl(t.contractAddress,t.contractName,t.function.name)}?tip=latest`,o=JSON.stringify({sender:t.contractAddress,arguments:t.functionArgs.map(s=>typeof s=="string"?s:_clarity.cvToHex.call(void 0, s))}),i=await _common.fetchPrivate.call(void 0, r,{method:"POST",body:o,headers:{"Content-Type":"application/json"}});if(!i.ok){let s="";try{s=await i.text()}catch (e4){}throw new Error(`Error calling read-only function. Response ${i.status}: ${i.statusText}. Attempted to fetch ${r} and failed with the message: "${s}"`)}let c=_api.parseReadOnlyResponse.call(void 0, await i.json());return p(c,!0)}async function fe(t,e){let n=await I(t,e);return _(n)}async function ye(t,e){let n=await I(t,e);return O(n)}async function de(t,e){let n=_clarity.cvToHex.call(void 0, t.key),r=await _api.fetchContractDataMapEntry.call(void 0, {contract_address:t.contractAddress,contract_name:t.contractName,map_name:t.map.name,lookup_key:n,tip:"latest",url:e.network.getCoreApiUrl(),proof:0}),o=_clarity.hexToCV.call(void 0, r.data);return p(o,!0)}async function Ce(t,e){let n=await _transactions.broadcastTransaction.call(void 0, t,e.network);if("error"in n)throw new Error(`Error broadcasting tx: ${n.error} - ${n.reason} - ${n.reason_data}`);return{txId:n.txid,stacksTransaction:t}}function Pt(t){let e=[];return t.forEach(n=>e.push(...n.transactions)),e}function V(t){return Pt(t).filter(v)}function D(t){if(!v(t))throw new Error("Unable to get path for tx type.");if("requirement-publish"in t)return t["requirement-publish"].path;if("emulated-contract-publish"in t)return t["emulated-contract-publish"].path;if("contract-publish"in t)return t["contract-publish"].path;throw new Error("Couldnt get path for deployment tx.")}function $(t){if(!v(t))throw new Error("Unable to get ID for tx type.");if("requirement-publish"in t){let e=t["requirement-publish"],[n,r]=e["contract-id"].split(".");return`${e["remap-sender"]}.${r}`}else if("emulated-contract-publish"in t){let e=t["emulated-contract-publish"];return`${e["emulated-sender"]}.${e["contract-name"]}`}else if("contract-publish"in t){let e=t["contract-publish"];return`${e["expected-sender"]}.${e["contract-name"]}`}throw new Error("Unable to find ID for contract.")}function v(t){return!("contract-call"in t||"btc-transfer"in t||"emulated-contract-call"in t)}var ke=["devnet","simnet","testnet","mainnet"];function Se(t,e){let n=[];return Object.entries(t.contracts).forEach(([r,o])=>{let i=t.deployments[r][e];return i&&n.push([r,M(o,i)]),!1}),Object.fromEntries(n)}function Pe(t,e){return Object.fromEntries(Object.entries(t).map(([n,r])=>{let o=`${e}.${r.contractName}`;return[n,M(r,o)]}))}function wt(t,e){return Object.fromEntries(Object.entries(t).map(([n,r])=>[n,(...i)=>{let c=m(r,i),[s,u]=e.split(".");return{functionArgs:c,contractAddress:s,contractName:u,function:r,nativeArgs:i}}]))}function M(t,e){let n=C({},t);return x(C(C({},wt(t.functions,e)),n),{identifier:e})}function we(t,e){let n={};return V(e.plan.batches).forEach(o=>{let i=$(o),[c,s]=i.split("."),u=f(s),U=t[u],d=t[u];if(typeof d>"u")throw new Error(`Clarigen error: mismatch for contract '${u}'`);n[u]=d,d.contractFile=D(o),d.identifier=i,Object.keys(t[u].functions).forEach(l=>{let E=l,j=(...b)=>{let A=U.functions[E];return{functionArgs:m(A,b),contractAddress:c,contractName:d.contractName,function:A,nativeArgs:b}};d[E]=j})}),n}exports.CoreNodeEventType = Y; exports.DEPLOYMENT_NETWORKS = ke; exports.MAINNET_BURN_ADDRESS = Z; exports.TESTNET_BURN_ADDRESS = W; exports.bootContractIdentifier = Vt; exports.broadcast = Ce; exports.contractFactory = M; exports.contractsFactory = Pe; exports.cvToString = T; exports.cvToValue = p; exports.deploymentFactory = we; exports.err = xt; exports.expectErr = O; exports.expectOk = _; exports.fetchMapGet = de; exports.filterEvents = $t; exports.findJsTupleKey = g; exports.functionsFactory = wt; exports.getContractIdentifier = Bt; exports.getContractNameFromPath = z; exports.getContractPrincipalCV = It; exports.hexToCvValue = Xt; exports.makeContracts = Ut; exports.ok = mt; exports.parseToCV = y; exports.projectFactory = Se; exports.pureProxy = bt; exports.ro = I; exports.roErr = ye; exports.roOk = fe; exports.toCamelCase = f; exports.toKebabCase = k; exports.transformArgsArray = gt; exports.transformArgsToCV = m; exports.transformObjectArgs = F;
|
package/dist/index.mjs
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
var K=Object.defineProperty,L=Object.defineProperties;var q=Object.getOwnPropertyDescriptors;var h=Object.getOwnPropertySymbols;var H=Object.prototype.hasOwnProperty,G=Object.prototype.propertyIsEnumerable;var N=(t,e,n)=>e in t?K(t,e,{enumerable:!0,configurable:!0,writable:!0,value:n}):t[e]=n,C=(t,e)=>{for(var n in e||(e={}))H.call(e,n)&&N(t,n,e[n]);if(h)for(var n of h(e))G.call(e,n)&&N(t,n,e[n]);return t},x=(t,e)=>L(t,q(e));import{contractPrincipalCV as J}from"micro-stacks/clarity";var W="ST000000000000000000002AMW42H",Z="SP000000000000000000002Q6VF78",f=(t,e)=>{let n=typeof t=="string"?t:String(t),[r,...o]=n.replace("!","").replace("?","").split("-"),c=`${e?r[0].toUpperCase():r[0].toLowerCase()}${r.slice(1)}`;return o.forEach(s=>{c+=s[0].toUpperCase()+s.slice(1)}),c};function k(t){let e=t.match(/[A-Z]{2,}(?=[A-Z][a-z]+[0-9]*|\b)|[A-Z]?[a-z]+[0-9]*|[A-Z]|[0-9]+/g);return e?e.join("-").toLowerCase():t}var z=t=>{let e=t.split("/"),n=e[e.length-1],[r]=n.split(".");return r},Bt=t=>`${t.address}.${t.name}`,It=t=>{let e=z(t.contractFile);return J(t.address,e)};function Vt(t,e){return`${e?Z:W}.${t}`}var Y=(l=>(l.ContractEvent="contract_event",l.StxTransferEvent="stx_transfer_event",l.StxMintEvent="stx_mint_event",l.StxBurnEvent="stx_burn_event",l.StxLockEvent="stx_lock_event",l.NftTransferEvent="nft_transfer_event",l.NftMintEvent="nft_mint_event",l.NftBurnEvent="nft_burn_event",l.FtTransferEvent="ft_transfer_event",l.FtMintEvent="ft_mint_event",l.FtBurnEvent="ft_burn_event",l))(Y||{});function $t(t,e){return t.filter(n=>n.type===e)}function Ut(t,e={}){let n={};for(let r in t){let o=t[r],i=e.deployerAddress||o.address,c=`${i}.${o.name}`,s=o.contract(i,o.name);n[r]={identifier:c,contract:s}}return n}import{addressToString as S,ClarityType as a,uintCV as Q,contractPrincipalCV as X,intCV as tt,stringAsciiCV as et,stringUtf8CV as nt,noneCV as rt,someCV as ot,tupleCV as at,listCV as it,hexToCV as st,bufferCV as ct}from"micro-stacks/clarity";import{isClarityAbiList as lt,isClarityAbiOptional as pt,isClarityAbiStringAscii as ut,isClarityAbiStringUtf8 as ft,isClarityAbiTuple as yt,isClarityAbiBuffer as dt,parseToCV as P}from"micro-stacks/transactions";import{bytesToAscii as Ct,bytesToHex as Tt}from"micro-stacks/common";function mt(t){return{isOk:!0,value:t}}function xt(t){return{isOk:!1,value:t}}function R(t){if(t.type===a.PrincipalStandard)return S(t.address);if(t.type===a.PrincipalContract)return`${S(t.address)}.${t.contractName.content}`;throw new Error(`Unexpected principal data: ${JSON.stringify(t)}`)}function p(t,e=!1){switch(t.type){case a.BoolTrue:return!0;case a.BoolFalse:return!1;case a.Int:case a.UInt:return t.value;case a.Buffer:return t.buffer;case a.OptionalNone:return null;case a.OptionalSome:return p(t.value);case a.ResponseErr:return e?xt(p(t.value)):p(t.value);case a.ResponseOk:return e?mt(p(t.value)):p(t.value);case a.PrincipalStandard:case a.PrincipalContract:return R(t);case a.List:return t.list.map(r=>p(r));case a.Tuple:return Object.entries(t.data).reduce((r,[o,i])=>{let c=f(o);return x(C({},r),{[c]:p(i)})},{});case a.StringASCII:return t.data;case a.StringUTF8:return t.data}}function Xt(t,e=!1){return p(st(t),e)}function w(t){if(!(typeof t=="bigint"||typeof t=="number"||typeof t=="string"))throw new Error("Invalid input type for integer");return BigInt(t)}function y(t,e){if(yt(e)){if(typeof t!="object")throw new Error("Invalid tuple input");let n={};return e.tuple.forEach(r=>{let o=g(r.name,t),i=t[o];n[r.name]=y(i,r.type)}),at(n)}else if(lt(e)){let r=t.map(o=>y(o,e.list.type));return it(r)}else{if(pt(e))return t?ot(y(t,e.optional)):rt();if(ut(e)){if(typeof t!="string")throw new Error("Invalid string-ascii input");return et(t)}else if(ft(e)){if(typeof t!="string")throw new Error("Invalid string-ascii input");return nt(t)}else if(e==="bool"){let n=typeof t=="boolean"?t.toString():t;return P(n,e)}else if(e==="uint128"){let n=w(t);return Q(n.toString())}else if(e==="int128"){let n=w(t);return tt(n.toString())}else if(e==="trait_reference"){if(typeof t!="string")throw new Error("Invalid input for trait_reference");let[n,r]=t.split(".");return X(n,r)}else if(dt(e))return ct(t)}return P(t,e)}function T(t,e="hex"){switch(t.type){case a.BoolTrue:return"true";case a.BoolFalse:return"false";case a.Int:return t.value.toString();case a.UInt:return`u${t.value.toString()}`;case a.Buffer:if(e==="tryAscii"){let n=Ct(t.buffer);if(/[ -~]/.test(n))return JSON.stringify(n)}return`0x${Tt(t.buffer)}`;case a.OptionalNone:return"none";case a.OptionalSome:return`(some ${T(t.value,e)})`;case a.ResponseErr:return`(err ${T(t.value,e)})`;case a.ResponseOk:return`(ok ${T(t.value,e)})`;case a.PrincipalStandard:case a.PrincipalContract:return`'${R(t)}`;case a.List:return`(list ${t.list.map(n=>T(n,e)).join(" ")})`;case a.Tuple:return`(tuple ${Object.keys(t.data).map(n=>`(${n} ${T(t.data[n],e)})`).join(" ")})`;case a.StringASCII:return`"${t.data}"`;case a.StringUTF8:return`u"${t.data}"`}}function F(t,e){return t.args.map(n=>{let r=g(n.name,e),o=e[r];return y(o,n.type)})}function gt(t,e){return e.map((n,r)=>y(n,t.args[r].type))}function m(t,e){if(e.length===0)return[];let[n]=e;if(e.length===1&&t.args.length!==1)return F(t,n);if(typeof n=="object"&&!Array.isArray(n)&&n!==null)try{let r=!0;if(t.args.forEach(o=>{try{g(o.name,n)}catch{r=!1}}),r)return F(t,n)}catch{}return gt(t,e)}function g(t,e){let n=Object.keys(e).find(r=>{let o=t===r,i=t===k(r);return o||i});if(!n)throw new Error(`Error encoding JS tuple: ${t} not found in input.`);return n}function _(t){if(t.isOk)return t.value;throw new Error(`Expected OK, received error: ${String(t.value)}`)}function O(t){if(!t.isOk)return t.value;throw new Error(`Expected Err, received ok: ${String(t.value)}`)}function vt(t,e){let n=t.abi.functions.find(o=>f(o.name)===e);if(n)return function(...o){return{functionArgs:m(n,o),contractAddress:t.contractAddress,contractName:t.contractName,function:n,nativeArgs:o}};let r=t.abi.maps.find(o=>f(o.name)===e);if(r)return o=>{let i=y(o,r.key);return{contractAddress:t.contractAddress,contractName:t.contractName,map:r,nativeKey:o,key:i}};throw new Error(`Invalid function call: no function exists for ${String(e)}`)}var Et={get:vt},bt=t=>new Proxy(t,Et);import{parseReadOnlyResponse as At,fetchContractDataMapEntry as ht}from"micro-stacks/api";import{cvToHex as B,hexToCV as Nt}from"micro-stacks/clarity";import{fetchPrivate as kt}from"micro-stacks/common";import{broadcastTransaction as St}from"micro-stacks/transactions";async function I(t,e){let r=`${e.network.getReadOnlyFunctionCallApiUrl(t.contractAddress,t.contractName,t.function.name)}?tip=latest`,o=JSON.stringify({sender:t.contractAddress,arguments:t.functionArgs.map(s=>typeof s=="string"?s:B(s))}),i=await kt(r,{method:"POST",body:o,headers:{"Content-Type":"application/json"}});if(!i.ok){let s="";try{s=await i.text()}catch{}throw new Error(`Error calling read-only function. Response ${i.status}: ${i.statusText}. Attempted to fetch ${r} and failed with the message: "${s}"`)}let c=At(await i.json());return p(c,!0)}async function fe(t,e){let n=await I(t,e);return _(n)}async function ye(t,e){let n=await I(t,e);return O(n)}async function de(t,e){let n=B(t.key),r=await ht({contract_address:t.contractAddress,contract_name:t.contractName,map_name:t.map.name,lookup_key:n,tip:"latest",url:e.network.getCoreApiUrl(),proof:0}),o=Nt(r.data);return p(o,!0)}async function Ce(t,e){let n=await St(t,e.network);if("error"in n)throw new Error(`Error broadcasting tx: ${n.error} - ${n.reason} - ${n.reason_data}`);return{txId:n.txid,stacksTransaction:t}}function Pt(t){let e=[];return t.forEach(n=>e.push(...n.transactions)),e}function V(t){return Pt(t).filter(v)}function D(t){if(!v(t))throw new Error("Unable to get path for tx type.");if("requirement-publish"in t)return t["requirement-publish"].path;if("emulated-contract-publish"in t)return t["emulated-contract-publish"].path;if("contract-publish"in t)return t["contract-publish"].path;throw new Error("Couldnt get path for deployment tx.")}function $(t){if(!v(t))throw new Error("Unable to get ID for tx type.");if("requirement-publish"in t){let e=t["requirement-publish"],[n,r]=e["contract-id"].split(".");return`${e["remap-sender"]}.${r}`}else if("emulated-contract-publish"in t){let e=t["emulated-contract-publish"];return`${e["emulated-sender"]}.${e["contract-name"]}`}else if("contract-publish"in t){let e=t["contract-publish"];return`${e["expected-sender"]}.${e["contract-name"]}`}throw new Error("Unable to find ID for contract.")}function v(t){return!("contract-call"in t||"btc-transfer"in t||"emulated-contract-call"in t)}var ke=["devnet","simnet","testnet","mainnet"];function Se(t,e){let n=[];return Object.entries(t.contracts).forEach(([r,o])=>{let i=t.deployments[r][e];return i&&n.push([r,M(o,i)]),!1}),Object.fromEntries(n)}function Pe(t,e){return Object.fromEntries(Object.entries(t).map(([n,r])=>{let o=`${e}.${r.contractName}`;return[n,M(r,o)]}))}function wt(t,e){return Object.fromEntries(Object.entries(t).map(([n,r])=>[n,(...i)=>{let c=m(r,i),[s,u]=e.split(".");return{functionArgs:c,contractAddress:s,contractName:u,function:r,nativeArgs:i}}]))}function M(t,e){let n=C({},t);return x(C(C({},wt(t.functions,e)),n),{identifier:e})}function we(t,e){let n={};return V(e.plan.batches).forEach(o=>{let i=$(o),[c,s]=i.split("."),u=f(s),U=t[u],d=t[u];if(typeof d>"u")throw new Error(`Clarigen error: mismatch for contract '${u}'`);n[u]=d,d.contractFile=D(o),d.identifier=i,Object.keys(t[u].functions).forEach(l=>{let E=l,j=(...b)=>{let A=U.functions[E];return{functionArgs:m(A,b),contractAddress:c,contractName:d.contractName,function:A,nativeArgs:b}};d[E]=j})}),n}export{Y as CoreNodeEventType,ke as DEPLOYMENT_NETWORKS,Z as MAINNET_BURN_ADDRESS,W as TESTNET_BURN_ADDRESS,Vt as bootContractIdentifier,Ce as broadcast,M as contractFactory,Pe as contractsFactory,T as cvToString,p as cvToValue,we as deploymentFactory,xt as err,O as expectErr,_ as expectOk,de as fetchMapGet,$t as filterEvents,g as findJsTupleKey,wt as functionsFactory,Bt as getContractIdentifier,z as getContractNameFromPath,It as getContractPrincipalCV,Xt as hexToCvValue,Ut as makeContracts,mt as ok,y as parseToCV,Se as projectFactory,bt as pureProxy,I as ro,ye as roErr,fe as roOk,f as toCamelCase,k as toKebabCase,gt as transformArgsArray,m as transformArgsToCV,F as transformObjectArgs};
|
package/package.json
CHANGED
|
@@ -1,33 +1,33 @@
|
|
|
1
1
|
{
|
|
2
|
-
"version": "1.0.0-next.
|
|
2
|
+
"version": "1.0.0-next.30",
|
|
3
3
|
"license": "MIT",
|
|
4
|
-
"
|
|
5
|
-
"
|
|
4
|
+
"types": "./dist/index.d.ts",
|
|
5
|
+
"main": "./dist/index.js",
|
|
6
|
+
"module": "./dist/index.mjs",
|
|
7
|
+
"import": "./dist/index.mjs",
|
|
6
8
|
"files": [
|
|
7
9
|
"dist"
|
|
8
10
|
],
|
|
9
11
|
"engines": {
|
|
10
12
|
"node": ">=10"
|
|
11
13
|
},
|
|
12
|
-
"scripts": {
|
|
13
|
-
"start": "tsdx watch",
|
|
14
|
-
"dev": "tsdx watch",
|
|
15
|
-
"build": "tsdx build",
|
|
16
|
-
"test": "jest",
|
|
17
|
-
"lint": "tsdx lint",
|
|
18
|
-
"prepublishOnly": "yarn build",
|
|
19
|
-
"typecheck": "tsc --noEmit"
|
|
20
|
-
},
|
|
21
14
|
"prettier": "@stacks/prettier-config",
|
|
22
15
|
"name": "@clarigen/core",
|
|
23
16
|
"author": "Hank Stoever",
|
|
24
|
-
"module": "dist/core.esm.js",
|
|
25
17
|
"dependencies": {
|
|
26
|
-
"micro-stacks": "^0.2
|
|
27
|
-
"neverthrow": "4.2.1"
|
|
18
|
+
"micro-stacks": "^0.5.2"
|
|
28
19
|
},
|
|
29
20
|
"publishConfig": {
|
|
30
21
|
"access": "public"
|
|
31
22
|
},
|
|
32
|
-
"
|
|
33
|
-
|
|
23
|
+
"scripts": {
|
|
24
|
+
"start": "tsup --watch",
|
|
25
|
+
"dev": "tsup --watch",
|
|
26
|
+
"build": "shx rm -rf ./dist && tsup",
|
|
27
|
+
"test": "jest",
|
|
28
|
+
"lint": "eslint \"src/**/*.{ts,tsx}\" && prettier --check src/**/*.ts",
|
|
29
|
+
"typecheck": "tsc --noEmit",
|
|
30
|
+
"publish:dev": "pnpm build && yalc publish --push",
|
|
31
|
+
"copy-types": "node copy-types.js"
|
|
32
|
+
}
|
|
33
|
+
}
|