@clarigen/core 1.0.13 → 1.0.15
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 +21 -13
- package/dist/index.js +1 -1
- package/dist/index.mjs +1 -1
- package/package.json +4 -1
package/dist/index.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { ClarityAbi as ClarityAbi$1, PrincipalCV, ClarityValue,
|
|
1
|
+
import { ClarityAbi as ClarityAbi$1, PrincipalCV, ClarityValue, ClarityAbiTypeTuple as ClarityAbiTypeTuple$1, ContractPrincipalCV, AssetInfo } from 'micro-stacks/clarity';
|
|
2
2
|
import { StacksTransaction, NonFungibleConditionCode, PostCondition, FungibleConditionCode } from 'micro-stacks/transactions';
|
|
3
3
|
import { IntegerType } from 'micro-stacks/common';
|
|
4
4
|
|
|
@@ -27,7 +27,7 @@ type ClarityAbiTypeOptional = {
|
|
|
27
27
|
optional: ClarityAbiType;
|
|
28
28
|
};
|
|
29
29
|
type ClarityAbiTypeTuple = {
|
|
30
|
-
tuple: {
|
|
30
|
+
tuple: readonly {
|
|
31
31
|
name: string;
|
|
32
32
|
type: ClarityAbiType;
|
|
33
33
|
}[];
|
|
@@ -144,7 +144,15 @@ declare function cvToValue<T = any>(val: ClarityValue, returnResponse?: boolean)
|
|
|
144
144
|
declare function hexToCvValue<T>(hex: string, jsonCompat?: boolean): any;
|
|
145
145
|
type TupleInput = Record<string, any>;
|
|
146
146
|
type CVInput = string | boolean | TupleInput | number | bigint;
|
|
147
|
-
declare
|
|
147
|
+
declare const isClarityAbiPrimitive: (val: ClarityAbiType) => val is ClarityAbiTypePrimitive;
|
|
148
|
+
declare const isClarityAbiBuffer: (val: ClarityAbiType) => val is ClarityAbiTypeBuffer;
|
|
149
|
+
declare const isClarityAbiStringAscii: (val: ClarityAbiType) => val is ClarityAbiTypeStringAscii;
|
|
150
|
+
declare const isClarityAbiStringUtf8: (val: ClarityAbiType) => val is ClarityAbiTypeStringUtf8;
|
|
151
|
+
declare const isClarityAbiResponse: (val: ClarityAbiType) => val is ClarityAbiTypeResponse;
|
|
152
|
+
declare const isClarityAbiOptional: (val: ClarityAbiType) => val is ClarityAbiTypeOptional;
|
|
153
|
+
declare const isClarityAbiTuple: (val: ClarityAbiType) => val is ClarityAbiTypeTuple$1;
|
|
154
|
+
declare const isClarityAbiList: (val: ClarityAbiType) => val is ClarityAbiTypeList;
|
|
155
|
+
declare function parseToCV(input: CVInput, type: ClarityAbiType): ClarityValue;
|
|
148
156
|
declare function cvToString(val: ClarityValue, encoding?: 'tryAscii' | 'hex'): string;
|
|
149
157
|
/**
|
|
150
158
|
* Convert a Clarity value to valid JSON. This does this same thing as
|
|
@@ -154,9 +162,9 @@ declare function cvToString(val: ClarityValue, encoding?: 'tryAscii' | 'hex'): s
|
|
|
154
162
|
* @param val - ClarityValue
|
|
155
163
|
*/
|
|
156
164
|
declare function cvToJSON<T = any>(val: ClarityValue, returnResponse?: boolean): T;
|
|
157
|
-
declare function transformObjectArgs(func: ClarityAbiFunction
|
|
158
|
-
declare function transformArgsArray(func: ClarityAbiFunction
|
|
159
|
-
declare function transformArgsToCV(func: ClarityAbiFunction
|
|
165
|
+
declare function transformObjectArgs(func: ClarityAbiFunction, args: Record<string, any>): ClarityValue[];
|
|
166
|
+
declare function transformArgsArray(func: ClarityAbiFunction, args: any[]): ClarityValue[];
|
|
167
|
+
declare function transformArgsToCV(func: ClarityAbiFunction, args: any[] | [Record<string, any>]): ClarityValue[];
|
|
160
168
|
declare function findJsTupleKey(key: string, input: Record<string, any>): string;
|
|
161
169
|
declare function expectOk<Ok>(response: Response<Ok, any>): Ok;
|
|
162
170
|
declare function expectErr<Err>(response: Response<any, Err>): Err;
|
|
@@ -172,7 +180,7 @@ type Compact$1<T> = {
|
|
|
172
180
|
[K in keyof T]: T[K];
|
|
173
181
|
};
|
|
174
182
|
type AbiTupleTo<T extends ReadonlyTuple> = Compact$1<UnionToIntersection$1<TupleTypeUnion<T['tuple'][number]>>>;
|
|
175
|
-
type AbiTypeTo<T extends ClarityAbiType
|
|
183
|
+
type AbiTypeTo<T extends ClarityAbiType | 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> : never;
|
|
176
184
|
type FunctionReturnType<T> = T extends TypedAbiFunction<TypedAbiArg<unknown, string>[], infer R> ? R : never;
|
|
177
185
|
type Jsonize<T> = T extends BigInt ? string : T extends Uint8Array ? string : T extends (infer V)[] ? Jsonize<V>[] : T extends Record<keyof T, unknown> ? {
|
|
178
186
|
[K in keyof T as K]: Jsonize<T[K]>;
|
|
@@ -586,8 +594,9 @@ type Project<C extends AllContracts, D extends DeploymentsForContracts<C>> = {
|
|
|
586
594
|
type FullContractWithIdentifier<C extends TypedAbi, Id extends string> = FullContract<C> & {
|
|
587
595
|
identifier: Id;
|
|
588
596
|
};
|
|
597
|
+
type IsDeploymentNetwork<T> = T extends DeploymentNetwork ? DeploymentNetwork extends T ? true : false : never;
|
|
589
598
|
type ProjectFactory<P extends Project<any, any>, N extends DeploymentNetwork> = {
|
|
590
|
-
[ContractName in keyof P['contracts']]: P['
|
|
599
|
+
[ContractName in keyof P['contracts']]: FullContractWithIdentifier<P['contracts'][ContractName], IsDeploymentNetwork<N> extends true ? '' : NonNullable<P['deployments'][ContractName][N]>>;
|
|
591
600
|
};
|
|
592
601
|
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>;
|
|
593
602
|
declare function contractsFactory<T extends AllContracts>(contracts: T, deployer: string): ContractFactory<T>;
|
|
@@ -604,12 +613,11 @@ declare function mapFactory<Key, Val>(map: TypedAbiMap<Key, Val>, key: Key): Map
|
|
|
604
613
|
|
|
605
614
|
type AbiWithAssets = Pick<FullContract<TypedAbi>, 'non_fungible_tokens' | 'fungible_tokens' | 'identifier'>;
|
|
606
615
|
type AssetNames<T extends AbiWithAssets> = T['non_fungible_tokens'][number]['name'] | T['fungible_tokens'][number]['name'];
|
|
607
|
-
type NftAssets<T extends AbiWithAssets> = {
|
|
608
|
-
[K in keyof T['non_fungible_tokens']]: K extends number ? [T['non_fungible_tokens'][K]['name'], T['non_fungible_tokens'][K]['type']] : never;
|
|
609
|
-
};
|
|
610
616
|
declare function createAssetInfo<T extends AbiWithAssets>(contract: T, asset: AssetNames<T>): AssetInfo;
|
|
611
|
-
type NftAssetType<T extends AbiWithAssets> = T['non_fungible_tokens'][0] extends
|
|
617
|
+
type NftAssetType<T extends AbiWithAssets> = T['non_fungible_tokens'][0] extends {
|
|
618
|
+
type: infer Type;
|
|
619
|
+
} ? Type extends ClarityAbiType | ReadonlyTuple ? AbiTypeTo<Type> : never : never;
|
|
612
620
|
declare function makeNonFungiblePostCondition<T extends AbiWithAssets>(contract: T, sender: string, condition: NonFungibleConditionCode, value: NftAssetType<T>): PostCondition;
|
|
613
621
|
declare function makeFungiblePostCondition<T extends AbiWithAssets>(contract: T, sender: string, condition: FungibleConditionCode, amount: IntegerType): PostCondition;
|
|
614
622
|
|
|
615
|
-
export { AbiPrimitiveTo, AbiTupleTo, AbiTypeTo, AllContracts, ApiOptions, ApiOptionsBase, ApiOptionsJsonize, ApiOptionsNetwork, ApiOptionsNoJson, ApiOptionsUrl, ArgsRecord, ArgsTuple, ArgsType, AssetNames, CVInput, ClarigenClient, 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, ExtractArgs, ExtractArgsRecord, FnToContractCall, FtBurnEvent, FtMintEvent, FtTransferEvent, FullContract, FullContractWithIdentifier, FunctionReturnType, FunctionsToContractCalls, JsonIfOption, Jsonize, Kebab, KebabObject, MAINNET_BURN_ADDRESS, MapFactory, Network, NftAssetType,
|
|
623
|
+
export { AbiPrimitiveTo, AbiTupleTo, AbiTypeTo, AllContracts, ApiOptions, ApiOptionsBase, ApiOptionsJsonize, ApiOptionsNetwork, ApiOptionsNoJson, ApiOptionsUrl, ArgsRecord, ArgsTuple, ArgsType, AssetNames, CVInput, ClarigenClient, 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, ExtractArgs, ExtractArgsRecord, FnToContractCall, FtBurnEvent, FtMintEvent, FtTransferEvent, FullContract, FullContractWithIdentifier, FunctionReturnType, FunctionsToContractCalls, JsonIfOption, Jsonize, Kebab, KebabObject, MAINNET_BURN_ADDRESS, MapFactory, Network, NftAssetType, NftBurnEvent, NftMintEvent, NftTransferEvent, NonStandardClarityValue, OkType, Project, ProjectFactory, ReadonlyTuple, Response, ResponseErr, ResponseOk, ResultAssets, SimnetDeploymentPlan, SmartContractEvent, StxBurnEvent, StxLockEvent, StxMintEvent, StxTransferEvent, TESTNET_BURN_ADDRESS, TupleInput, TypedAbi, TypedAbiArg, TypedAbiFunction, TypedAbiMap, TypedAbiVariable, UnionToIntersection, UnknownArg, UnknownArgs, bootContractIdentifier, broadcast, contractFactory, contractsFactory, createAssetInfo, cvToJSON, cvToString, cvToValue, deploymentFactory, err, expectErr, expectOk, fetchMapGet, filterEvents, findJsTupleKey, functionsFactory, getApiUrl, getContractIdentifier, getContractNameFromPath, getContractPrincipalCV, hexToCvValue, isClarityAbiBuffer, isClarityAbiList, isClarityAbiOptional, isClarityAbiPrimitive, isClarityAbiResponse, isClarityAbiStringAscii, isClarityAbiStringUtf8, isClarityAbiTuple, makeContracts, makeFungiblePostCondition, makeNonFungiblePostCondition, mapFactory, ok, parseToCV, principalToString, projectFactory, pureProxy, ro, roErr, roOk, toCamelCase, toKebabCase, transformArgsArray, transformArgsToCV, transformObjectArgs };
|
package/dist/index.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
"use strict";Object.defineProperty(exports, "__esModule", {value: true});var Q=Object.defineProperty,X=Object.defineProperties;var tt=Object.getOwnPropertyDescriptors;var w=Object.getOwnPropertySymbols;var et=Object.prototype.hasOwnProperty,nt=Object.prototype.propertyIsEnumerable;var F=(t,e,n)=>e in t?Q(t,e,{enumerable:!0,configurable:!0,writable:!0,value:n}):t[e]=n,y=(t,e)=>{for(var n in e||(e={}))et.call(e,n)&&F(t,n,e[n]);if(w)for(var n of w(e))nt.call(e,n)&&F(t,n,e[n]);return t},x=(t,e)=>X(t,tt(e));var _clarity = require('micro-stacks/clarity');var ot="ST000000000000000000002AMW42H",at= exports.MAINNET_BURN_ADDRESS ="SP000000000000000000002Q6VF78",C= exports.toCamelCase =(t,e)=>{let n=typeof t=="string"?t:String(t),[r,...o]=n.replace("!","").replace("?","").split("-"),s=`${e?r[0].toUpperCase():r[0].toLowerCase()}${r.slice(1)}`;return o.forEach(p=>{s+=p[0].toUpperCase()+p.slice(1)}),s};function S(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 it=t=>{let e=t.split("/"),n=e[e.length-1],[r]=n.split(".");return r},Zt= exports.getContractIdentifier =t=>`${t.address}.${t.name}`,Yt= exports.getContractPrincipalCV =t=>{let e=it(t.contractFile);return _clarity.contractPrincipalCV.call(void 0, t.address,e)};function Qt(t,e){return`${e?at:ot}.${t}`}var st=(c=>(c.ContractEvent="contract_event",c.StxTransferEvent="stx_transfer_event",c.StxMintEvent="stx_mint_event",c.StxBurnEvent="stx_burn_event",c.StxLockEvent="stx_lock_event",c.NftTransferEvent="nft_transfer_event",c.NftMintEvent="nft_mint_event",c.NftBurnEvent="nft_burn_event",c.FtTransferEvent="ft_transfer_event",c.FtMintEvent="ft_mint_event",c.FtBurnEvent="ft_burn_event",c))(st||{});function te(t,e){return t.filter(n=>n.type===e)}function ne(t,e={}){let n={};for(let r in t){let o=t[r],i=e.deployerAddress||o.address,s=`${i}.${o.name}`,p=o.contract(i,o.name);n[r]={identifier:s,contract:p}}return n}var _transactions = require('micro-stacks/transactions');var _common = require('micro-stacks/common');function $(t){return{isOk:!0,value:t}}function M(t){return{isOk:!1,value:t}}function v(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 f(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 f(t.value);case _clarity.ClarityType.ResponseErr:return e?M(f(t.value)):f(t.value);case _clarity.ClarityType.ResponseOk:return e?$(f(t.value)):f(t.value);case _clarity.ClarityType.PrincipalStandard:case _clarity.ClarityType.PrincipalContract:return v(t);case _clarity.ClarityType.List:return t.list.map(r=>f(r));case _clarity.ClarityType.Tuple:return Object.entries(t.data).reduce((r,[o,i])=>{let s=C(o);return x(y({},r),{[s]:f(i)})},{});case _clarity.ClarityType.StringASCII:return t.data;case _clarity.ClarityType.StringUTF8:return t.data}}function ye(t,e=!1){return f(_clarity.hexToCV.call(void 0, t),e)}function I(t){if(!(typeof t=="bigint"||typeof t=="number"||typeof t=="string"))throw new Error("Invalid input type for integer");return BigInt(t)}function d(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=E(r.name,t),i=t[o];n[r.name]=d(i,r.type)}),_clarity.tupleCV.call(void 0, n)}else if(_transactions.isClarityAbiList.call(void 0, e)){let r=t.map(o=>d(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, d(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=I(t);return _clarity.uintCV.call(void 0, n.toString())}else if(e==="int128"){let n=I(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 g(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 ${g(t.value,e)})`;case _clarity.ClarityType.ResponseErr:return`(err ${g(t.value,e)})`;case _clarity.ClarityType.ResponseOk:return`(ok ${g(t.value,e)})`;case _clarity.ClarityType.PrincipalStandard:case _clarity.ClarityType.PrincipalContract:return`'${v(t)}`;case _clarity.ClarityType.List:return`(list ${t.list.map(n=>g(n,e)).join(" ")})`;case _clarity.ClarityType.Tuple:return`(tuple ${Object.keys(t.data).map(n=>`(${n} ${g(t.data[n],e)})`).join(" ")})`;case _clarity.ClarityType.StringASCII:return`"${t.data}"`;case _clarity.ClarityType.StringUTF8:return`u"${t.data}"`}}function T(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 _common.bytesToHex.call(void 0, t.buffer);case _clarity.ClarityType.OptionalNone:return null;case _clarity.ClarityType.OptionalSome:return T(t.value);case _clarity.ClarityType.ResponseErr:return e?M(T(t.value)):T(t.value);case _clarity.ClarityType.ResponseOk:return e?$(T(t.value)):T(t.value);case _clarity.ClarityType.PrincipalStandard:case _clarity.ClarityType.PrincipalContract:return v(t);case _clarity.ClarityType.List:return t.list.map(r=>T(r));case _clarity.ClarityType.Tuple:return Object.entries(t.data).reduce((r,[o,i])=>{let s=C(o);return x(y({},r),{[s]:T(i)})},{});case _clarity.ClarityType.StringASCII:return t.data;case _clarity.ClarityType.StringUTF8:return t.data}}function V(t,e){return t.args.map(n=>{let r=E(n.name,e),o=e[r];return d(o,n.type)})}function ht(t,e){return e.map((n,r)=>d(n,t.args[r].type))}function b(t,e){if(e.length===0)return[];let[n]=e;if(e.length===1&&t.args.length!==1)return V(t,n);if(typeof n=="object"&&!Array.isArray(n)&&n!==null)try{let r=!0;if(t.args.forEach(o=>{try{E(o.name,n)}catch (e2){r=!1}}),r)return V(t,n)}catch (e3){}return ht(t,e)}function E(t,e){let n=Object.keys(e).find(r=>{let o=t===r,i=t===S(r);return o||i});if(!n)throw new Error(`Error encoding JS tuple: ${t} not found in input.`);return n}function D(t){if(t.isOk)return t.value;throw new Error(`Expected OK, received error: ${String(t.value)}`)}function U(t){if(!t.isOk)return t.value;throw new Error(`Expected Err, received ok: ${String(t.value)}`)}function Nt(t,e){let n=t.abi.functions.find(o=>C(o.name)===e);if(n)return function(...o){return{functionArgs:b(n,o),contractAddress:t.contractAddress,contractName:t.contractName,function:n,functionName:n.name,nativeArgs:o}};let r=t.abi.maps.find(o=>C(o.name)===e);if(r)return o=>{let i=d(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 Pt={get:Nt},wt= exports.pureProxy =t=>new Proxy(t,Pt);var _api = require('micro-stacks/api');function Ft(t){let e=[];return t.forEach(n=>e.push(...n.transactions)),e}function j(t){return Ft(t).filter(O)}function K(t){if(!O(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 J(t){if(!O(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 O(t){return!("contract-call"in t||"btc-transfer"in t||"emulated-contract-call"in t)}var Fe=["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,L(o,i)]),!1}),Object.fromEntries(n)}function Re(t,e){return Object.fromEntries(Object.entries(t).map(([n,r])=>{let o=`${e}.${r.contractName}`;return[n,L(r,o)]}))}function St(t,e){return Object.fromEntries(Object.entries(t).map(([n,r])=>{let o=Object.assign((...i)=>{let s=b(r,i),[p,l]=e.split(".");return{functionArgs:s,contractAddress:p,contractName:l,function:r,functionName:r.name,nativeArgs:i}},{abi:r});return[n,o]}))}function L(t,e){let n=y({},t);return x(y(y({},St(t.functions,e)),n),{identifier:e})}function _e(t,e){let n={};return j(e.plan.batches).forEach(o=>{let i=J(o),[s,p]=i.split("."),l=C(p),m=t[l],u=t[l];if(typeof u>"u")throw new Error(`Clarigen error: mismatch for contract '${l}'`);n[l]=u,u.contractFile=K(o),u.identifier=i,Object.keys(t[l].functions).forEach(c=>{let A=c,Y=(...N)=>{let P=m.functions[A];return{functionArgs:b(P,N),contractAddress:s,contractName:u.contractName,function:P,nativeArgs:N}};u[A]=Y})}),n}function q(t,e){let n=d(e,t.key);return{key:e,keyCV:n,map:t}}async function W(t){let{contractName:e,contractAddress:n,functionName:r,functionArgs:o,senderAddress:i=n,tip:s,url:p}=t,l=`${p}/v2/contracts/call-read/${n}/${e}/${encodeURIComponent(r)}`;s&&(l+=`?tip=${s}`);let m=JSON.stringify({sender:i,arguments:o.map(c=>typeof c=="string"?c:_clarity.cvToHex.call(void 0, c))}),u=await _common.fetchPrivate.call(void 0, l,{method:"POST",body:m,headers:{"Content-Type":"application/json"}});if(!u.ok){let c="";try{c=await u.text()}catch (e4){}throw new Error(`Error calling read-only function. Response ${u.status}: ${u.statusText}. Attempted to fetch ${l} and failed with the message: "${c}"`)}return _api.parseReadOnlyResponse.call(void 0, await u.json())}function H(t){if(t.latest!==!1)return t.latest||typeof t.tip>"u"?"latest":t.tip}async function k(t,e){let n=H(e),r=await W({contractAddress:t.contractAddress,contractName:t.contractName,functionName:t.functionName,functionArgs:t.functionArgs,tip:n,url:h(e)});return e.json?T(r):f(r,!0)}async function Ut(t,e){let n=await k(t,e);return D(n)}async function jt(t,e){let n=await k(t,e);return U(n)}function h(t){return"network"in t?t.network.getCoreApiUrl():t.url}async function Ye(t,e,n,r){let o=q(e,n),i=JSON.stringify(_clarity.cvToHex.call(void 0, o.keyCV)),[s,p]=t.split("."),l=_api.generateUrl.call(void 0, `${_api.v2Endpoint.call(void 0, h(r))}/map_entry/${s}/${p}/${o.map.name}`,{proof:0,tip:H(r)}),u=await(await fetch(l,{method:"POST",body:i,headers:{"Content-Type":"application/json",Accept:"application/json"}})).json(),c=_clarity.hexToCV.call(void 0, u.data);return f(c,!0)}async function Qe(t,e){let n=`${h(e)}/v2/transactions`,r=await _transactions.broadcastRawTransaction.call(void 0, t.serialize(),n);if("error"in r)throw new Error(`Error broadcasting tx: ${r.error} - ${r.reason} - ${JSON.stringify(r.reason_data)}`);return{txId:r.txid,stacksTransaction:t}}var z=class{constructor(e){typeof e=="string"?this.url=e:this.url=e.getCoreApiUrl()}roOptions(e){return y({url:this.url},e)}ro(e,n){return k(e,this.roOptions(n||{}))}roOk(e,n){return Ut(e,this.roOptions(n||{}))}roErr(e,n){return jt(e,this.roOptions(n||{}))}};function Z(t,e){if(!("identifier"in t))throw new Error("Invalid contract");let[n,r]=t.identifier.split(".");for(let o of t.non_fungible_tokens)if(o.name===e)return _transactions.createAssetInfo.call(void 0, n,r,o.name);for(let o of t.fungible_tokens)if(o.name===e)return _transactions.createAssetInfo.call(void 0, n,r,o.name);throw new Error(`Invalid asset: "${r}" is not an asset in contract.`)}function cn(t,e,n,r){let[o,i]=e.split("."),[s]=t.non_fungible_tokens,p=Z(t,s.name),l=s.type,m=d(r,l);return typeof i>"u"?_transactions.makeStandardNonFungiblePostCondition.call(void 0, o,n,p,m):_transactions.makeContractNonFungiblePostCondition.call(void 0, o,i,n,p,m)}function pn(t,e,n,r){let[o,i]=e.split("."),[s]=t.fungible_tokens,p=Z(t,s.name);return typeof i>"u"?_transactions.makeStandardFungiblePostCondition.call(void 0, o,n,r,p):_transactions.makeContractFungiblePostCondition.call(void 0, o,i,n,r,p)}exports.ClarigenClient = z; exports.CoreNodeEventType = st; exports.DEPLOYMENT_NETWORKS = Fe; exports.MAINNET_BURN_ADDRESS = at; exports.TESTNET_BURN_ADDRESS = ot; exports.bootContractIdentifier = Qt; exports.broadcast = Qe; exports.contractFactory = L; exports.contractsFactory = Re; exports.createAssetInfo = Z; exports.cvToJSON = T; exports.cvToString = g; exports.cvToValue = f; exports.deploymentFactory = _e; exports.err = M; exports.expectErr = U; exports.expectOk = D; exports.fetchMapGet = Ye; exports.filterEvents = te; exports.findJsTupleKey = E; exports.functionsFactory = St; exports.getApiUrl = h; exports.getContractIdentifier = Zt; exports.getContractNameFromPath = it; exports.getContractPrincipalCV = Yt; exports.hexToCvValue = ye; exports.makeContracts = ne; exports.makeFungiblePostCondition = pn; exports.makeNonFungiblePostCondition = cn; exports.mapFactory = q; exports.ok = $; exports.parseToCV = d; exports.principalToString = v; exports.projectFactory = Se; exports.pureProxy = wt; exports.ro = k; exports.roErr = jt; exports.roOk = Ut; exports.toCamelCase = C; exports.toKebabCase = S; exports.transformArgsArray = ht; exports.transformArgsToCV = b; exports.transformObjectArgs = V;
|
|
1
|
+
"use strict";Object.defineProperty(exports, "__esModule", {value: true});var Q=Object.defineProperty,X=Object.defineProperties;var tt=Object.getOwnPropertyDescriptors;var P=Object.getOwnPropertySymbols;var et=Object.prototype.hasOwnProperty,nt=Object.prototype.propertyIsEnumerable;var S=(t,e,n)=>e in t?Q(t,e,{enumerable:!0,configurable:!0,writable:!0,value:n}):t[e]=n,d=(t,e)=>{for(var n in e||(e={}))et.call(e,n)&&S(t,n,e[n]);if(P)for(var n of P(e))nt.call(e,n)&&S(t,n,e[n]);return t},x=(t,e)=>X(t,tt(e));var _clarity = require('micro-stacks/clarity');var ot="ST000000000000000000002AMW42H",it= exports.MAINNET_BURN_ADDRESS ="SP000000000000000000002Q6VF78",C= exports.toCamelCase =(t,e)=>{let n=typeof t=="string"?t:String(t),[r,...o]=n.replace("!","").replace("?","").split("-"),s=`${e?r[0].toUpperCase():r[0].toLowerCase()}${r.slice(1)}`;return o.forEach(p=>{s+=p[0].toUpperCase()+p.slice(1)}),s};function F(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 at=t=>{let e=t.split("/"),n=e[e.length-1],[r]=n.split(".");return r},Zt= exports.getContractIdentifier =t=>`${t.address}.${t.name}`,Yt= exports.getContractPrincipalCV =t=>{let e=at(t.contractFile);return _clarity.contractPrincipalCV.call(void 0, t.address,e)};function Qt(t,e){return`${e?it:ot}.${t}`}var st=(c=>(c.ContractEvent="contract_event",c.StxTransferEvent="stx_transfer_event",c.StxMintEvent="stx_mint_event",c.StxBurnEvent="stx_burn_event",c.StxLockEvent="stx_lock_event",c.NftTransferEvent="nft_transfer_event",c.NftMintEvent="nft_mint_event",c.NftBurnEvent="nft_burn_event",c.FtTransferEvent="ft_transfer_event",c.FtMintEvent="ft_mint_event",c.FtBurnEvent="ft_burn_event",c))(st||{});function te(t,e){return t.filter(n=>n.type===e)}function ne(t,e={}){let n={};for(let r in t){let o=t[r],a=e.deployerAddress||o.address,s=`${a}.${o.name}`,p=o.contract(a,o.name);n[r]={identifier:s,contract:p}}return n}var _transactions = require('micro-stacks/transactions');var _common = require('micro-stacks/common');function $(t){return{isOk:!0,value:t}}function D(t){return{isOk:!1,value:t}}function v(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 f(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 f(t.value);case _clarity.ClarityType.ResponseErr:return e?D(f(t.value)):f(t.value);case _clarity.ClarityType.ResponseOk:return e?$(f(t.value)):f(t.value);case _clarity.ClarityType.PrincipalStandard:case _clarity.ClarityType.PrincipalContract:return v(t);case _clarity.ClarityType.List:return t.list.map(r=>f(r));case _clarity.ClarityType.Tuple:return Object.entries(t.data).reduce((r,[o,a])=>{let s=C(o);return x(d({},r),{[s]:f(a)})},{});case _clarity.ClarityType.StringASCII:return t.data;case _clarity.ClarityType.StringUTF8:return t.data}}function ye(t,e=!1){return f(_clarity.hexToCV.call(void 0, t),e)}function _(t){if(!(typeof t=="bigint"||typeof t=="number"||typeof t=="string"))throw new Error("Invalid input type for integer");return BigInt(t)}var de=t=>typeof t=="string",gt= exports.isClarityAbiBuffer =t=>t.buffer!==void 0,At= exports.isClarityAbiStringAscii =t=>t["string-ascii"]!==void 0,vt= exports.isClarityAbiStringUtf8 =t=>t["string-utf8"]!==void 0,Te= exports.isClarityAbiResponse =t=>t.response!==void 0,Et= exports.isClarityAbiOptional =t=>t.optional!==void 0,Ot= exports.isClarityAbiTuple =t=>t.tuple!==void 0,ht= exports.isClarityAbiList =t=>t.list!==void 0;function y(t,e){if(Ot(e)){if(typeof t!="object")throw new Error("Invalid tuple input");let n={};return e.tuple.forEach(r=>{let o=E(r.name,t),a=t[o];n[r.name]=y(a,r.type)}),_clarity.tupleCV.call(void 0, n)}else if(ht(e)){let r=t.map(o=>y(o,e.list.type));return _clarity.listCV.call(void 0, r)}else{if(Et(e))return t===null?_clarity.noneCV.call(void 0, ):_clarity.someCV.call(void 0, y(t,e.optional));if(At(e)){if(typeof t!="string")throw new Error("Invalid string-ascii input");return _clarity.stringAsciiCV.call(void 0, t)}else if(vt(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=_(t);return _clarity.uintCV.call(void 0, n.toString())}else if(e==="int128"){let n=_(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(gt(e))return _clarity.bufferCV.call(void 0, t)}return _transactions.parseToCV.call(void 0, t,e)}function b(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 ${b(t.value,e)})`;case _clarity.ClarityType.ResponseErr:return`(err ${b(t.value,e)})`;case _clarity.ClarityType.ResponseOk:return`(ok ${b(t.value,e)})`;case _clarity.ClarityType.PrincipalStandard:case _clarity.ClarityType.PrincipalContract:return`'${v(t)}`;case _clarity.ClarityType.List:return`(list ${t.list.map(n=>b(n,e)).join(" ")})`;case _clarity.ClarityType.Tuple:return`(tuple ${Object.keys(t.data).map(n=>`(${n} ${b(t.data[n],e)})`).join(" ")})`;case _clarity.ClarityType.StringASCII:return`"${t.data}"`;case _clarity.ClarityType.StringUTF8:return`u"${t.data}"`}}function T(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 _common.bytesToHex.call(void 0, t.buffer);case _clarity.ClarityType.OptionalNone:return null;case _clarity.ClarityType.OptionalSome:return T(t.value);case _clarity.ClarityType.ResponseErr:return e?D(T(t.value)):T(t.value);case _clarity.ClarityType.ResponseOk:return e?$(T(t.value)):T(t.value);case _clarity.ClarityType.PrincipalStandard:case _clarity.ClarityType.PrincipalContract:return v(t);case _clarity.ClarityType.List:return t.list.map(r=>T(r));case _clarity.ClarityType.Tuple:return Object.entries(t.data).reduce((r,[o,a])=>{let s=C(o);return x(d({},r),{[s]:T(a)})},{});case _clarity.ClarityType.StringASCII:return t.data;case _clarity.ClarityType.StringUTF8:return t.data}}function V(t,e){return t.args.map(n=>{let r=E(n.name,e),o=e[r];return y(o,n.type)})}function kt(t,e){return e.map((n,r)=>y(n,t.args[r].type))}function g(t,e){if(e.length===0)return[];let[n]=e;if(e.length===1&&t.args.length!==1)return V(t,n);if(typeof n=="object"&&!Array.isArray(n)&&n!==null)try{let r=!0;if(t.args.forEach(o=>{try{E(o.name,n)}catch (e2){r=!1}}),r)return V(t,n)}catch (e3){}return kt(t,e)}function E(t,e){let n=Object.keys(e).find(r=>{let o=t===r,a=t===F(r);return o||a});if(!n)throw new Error(`Error encoding JS tuple: ${t} not found in input.`);return n}function M(t){if(t.isOk)return t.value;throw new Error(`Expected OK, received error: ${String(t.value)}`)}function U(t){if(!t.isOk)return t.value;throw new Error(`Expected Err, received ok: ${String(t.value)}`)}function Nt(t,e){let n=t.abi.functions.find(o=>C(o.name)===e);if(n)return function(...o){return{functionArgs:g(n,o),contractAddress:t.contractAddress,contractName:t.contractName,function:n,functionName:n.name,nativeArgs:o}};let r=t.abi.maps.find(o=>C(o.name)===e);if(r)return o=>{let a=y(o,r.key);return{contractAddress:t.contractAddress,contractName:t.contractName,map:r,nativeKey:o,key:a}};throw new Error(`Invalid function call: no function exists for ${String(e)}`)}var wt={get:Nt},Pt= exports.pureProxy =t=>new Proxy(t,wt);var _api = require('micro-stacks/api');function St(t){let e=[];return t.forEach(n=>e.push(...n.transactions)),e}function j(t){return St(t).filter(O)}function J(t){if(!O(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 K(t){if(!O(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 O(t){return!("contract-call"in t||"btc-transfer"in t||"emulated-contract-call"in t)}var Fe=["devnet","simnet","testnet","mainnet"];function Re(t,e){let n=[];return Object.entries(t.contracts).forEach(([r,o])=>{let a=t.deployments[r][e];return a&&n.push([r,L(o,a)]),!1}),Object.fromEntries(n)}function Ie(t,e){return Object.fromEntries(Object.entries(t).map(([n,r])=>{let o=`${e}.${r.contractName}`;return[n,L(r,o)]}))}function Ft(t,e){return Object.fromEntries(Object.entries(t).map(([n,r])=>{let o=Object.assign((...a)=>{let s=g(r,a),[p,l]=e.split(".");return{functionArgs:s,contractAddress:p,contractName:l,function:r,functionName:r.name,nativeArgs:a}},{abi:r});return[n,o]}))}function L(t,e){let n=d({},t);return x(d(d({},Ft(t.functions,e)),n),{identifier:e})}function _e(t,e){let n={};return j(e.plan.batches).forEach(o=>{let a=K(o),[s,p]=a.split("."),l=C(p),m=t[l],u=t[l];if(typeof u>"u")throw new Error(`Clarigen error: mismatch for contract '${l}'`);n[l]=u,u.contractFile=J(o),u.identifier=a,Object.keys(t[l].functions).forEach(c=>{let A=c,Y=(...N)=>{let w=m.functions[A];return{functionArgs:g(w,N),contractAddress:s,contractName:u.contractName,function:w,nativeArgs:N}};u[A]=Y})}),n}function q(t,e){let n=y(e,t.key);return{key:e,keyCV:n,map:t}}async function z(t){let{contractName:e,contractAddress:n,functionName:r,functionArgs:o,senderAddress:a=n,tip:s,url:p}=t,l=`${p}/v2/contracts/call-read/${n}/${e}/${encodeURIComponent(r)}`;s&&(l+=`?tip=${s}`);let m=JSON.stringify({sender:a,arguments:o.map(c=>typeof c=="string"?c:_clarity.cvToHex.call(void 0, c))}),u=await _common.fetchPrivate.call(void 0, l,{method:"POST",body:m,headers:{"Content-Type":"application/json"}});if(!u.ok){let c="";try{c=await u.text()}catch (e4){}throw new Error(`Error calling read-only function. Response ${u.status}: ${u.statusText}. Attempted to fetch ${l} and failed with the message: "${c}"`)}return _api.parseReadOnlyResponse.call(void 0, await u.json())}function H(t){if(t.latest!==!1)return t.latest||typeof t.tip>"u"?"latest":t.tip}async function h(t,e){let n=H(e),r=await z({contractAddress:t.contractAddress,contractName:t.contractName,functionName:t.functionName,functionArgs:t.functionArgs,tip:n,url:k(e)});return e.json?T(r):f(r,!0)}async function Ut(t,e){let n=await h(t,e);return M(n)}async function jt(t,e){let n=await h(t,e);return U(n)}function k(t){return"network"in t?t.network.getCoreApiUrl():t.url}async function Qe(t,e,n,r){let o=q(e,n),a=JSON.stringify(_clarity.cvToHex.call(void 0, o.keyCV)),[s,p]=t.split("."),l=_api.generateUrl.call(void 0, `${_api.v2Endpoint.call(void 0, k(r))}/map_entry/${s}/${p}/${o.map.name}`,{proof:0,tip:H(r)}),u=await(await fetch(l,{method:"POST",body:a,headers:{"Content-Type":"application/json",Accept:"application/json"}})).json(),c=_clarity.hexToCV.call(void 0, u.data);return f(c,!0)}async function Xe(t,e){let n=`${k(e)}/v2/transactions`,r=await _transactions.broadcastRawTransaction.call(void 0, t.serialize(),n);if("error"in r)throw new Error(`Error broadcasting tx: ${r.error} - ${r.reason} - ${JSON.stringify(r.reason_data)}`);return{txId:r.txid,stacksTransaction:t}}var W=class{constructor(e){typeof e=="string"?this.url=e:this.url=e.getCoreApiUrl()}roOptions(e){return d({url:this.url},e)}ro(e,n){return h(e,this.roOptions(n||{}))}roOk(e,n){return Ut(e,this.roOptions(n||{}))}roErr(e,n){return jt(e,this.roOptions(n||{}))}};function Z(t,e){if(!("identifier"in t))throw new Error("Invalid contract");let[n,r]=t.identifier.split(".");for(let o of t.non_fungible_tokens)if(o.name===e)return _transactions.createAssetInfo.call(void 0, n,r,o.name);for(let o of t.fungible_tokens)if(o.name===e)return _transactions.createAssetInfo.call(void 0, n,r,o.name);throw new Error(`Invalid asset: "${e}" is not an asset in contract.`)}function ln(t,e,n,r){let[o,a]=e.split("."),[s]=t.non_fungible_tokens,p=Z(t,s.name),l=s.type,m=y(r,l);return typeof a>"u"?_transactions.makeStandardNonFungiblePostCondition.call(void 0, o,n,p,m):_transactions.makeContractNonFungiblePostCondition.call(void 0, o,a,n,p,m)}function un(t,e,n,r){let[o,a]=e.split("."),[s]=t.fungible_tokens,p=Z(t,s.name);return typeof a>"u"?_transactions.makeStandardFungiblePostCondition.call(void 0, o,n,r,p):_transactions.makeContractFungiblePostCondition.call(void 0, o,a,n,r,p)}exports.ClarigenClient = W; exports.CoreNodeEventType = st; exports.DEPLOYMENT_NETWORKS = Fe; exports.MAINNET_BURN_ADDRESS = it; exports.TESTNET_BURN_ADDRESS = ot; exports.bootContractIdentifier = Qt; exports.broadcast = Xe; exports.contractFactory = L; exports.contractsFactory = Ie; exports.createAssetInfo = Z; exports.cvToJSON = T; exports.cvToString = b; exports.cvToValue = f; exports.deploymentFactory = _e; exports.err = D; exports.expectErr = U; exports.expectOk = M; exports.fetchMapGet = Qe; exports.filterEvents = te; exports.findJsTupleKey = E; exports.functionsFactory = Ft; exports.getApiUrl = k; exports.getContractIdentifier = Zt; exports.getContractNameFromPath = at; exports.getContractPrincipalCV = Yt; exports.hexToCvValue = ye; exports.isClarityAbiBuffer = gt; exports.isClarityAbiList = ht; exports.isClarityAbiOptional = Et; exports.isClarityAbiPrimitive = de; exports.isClarityAbiResponse = Te; exports.isClarityAbiStringAscii = At; exports.isClarityAbiStringUtf8 = vt; exports.isClarityAbiTuple = Ot; exports.makeContracts = ne; exports.makeFungiblePostCondition = un; exports.makeNonFungiblePostCondition = ln; exports.mapFactory = q; exports.ok = $; exports.parseToCV = y; exports.principalToString = v; exports.projectFactory = Re; exports.pureProxy = Pt; exports.ro = h; exports.roErr = jt; exports.roOk = Ut; exports.toCamelCase = C; exports.toKebabCase = F; exports.transformArgsArray = kt; exports.transformArgsToCV = g; exports.transformObjectArgs = V;
|
package/dist/index.mjs
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
var Q=Object.defineProperty,X=Object.defineProperties;var tt=Object.getOwnPropertyDescriptors;var w=Object.getOwnPropertySymbols;var et=Object.prototype.hasOwnProperty,nt=Object.prototype.propertyIsEnumerable;var F=(t,e,n)=>e in t?Q(t,e,{enumerable:!0,configurable:!0,writable:!0,value:n}):t[e]=n,y=(t,e)=>{for(var n in e||(e={}))et.call(e,n)&&F(t,n,e[n]);if(w)for(var n of w(e))nt.call(e,n)&&F(t,n,e[n]);return t},x=(t,e)=>X(t,tt(e));import{contractPrincipalCV as rt}from"micro-stacks/clarity";var ot="ST000000000000000000002AMW42H",at="SP000000000000000000002Q6VF78",C=(t,e)=>{let n=typeof t=="string"?t:String(t),[r,...o]=n.replace("!","").replace("?","").split("-"),s=`${e?r[0].toUpperCase():r[0].toLowerCase()}${r.slice(1)}`;return o.forEach(p=>{s+=p[0].toUpperCase()+p.slice(1)}),s};function S(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 it=t=>{let e=t.split("/"),n=e[e.length-1],[r]=n.split(".");return r},Zt=t=>`${t.address}.${t.name}`,Yt=t=>{let e=it(t.contractFile);return rt(t.address,e)};function Qt(t,e){return`${e?at:ot}.${t}`}var st=(c=>(c.ContractEvent="contract_event",c.StxTransferEvent="stx_transfer_event",c.StxMintEvent="stx_mint_event",c.StxBurnEvent="stx_burn_event",c.StxLockEvent="stx_lock_event",c.NftTransferEvent="nft_transfer_event",c.NftMintEvent="nft_mint_event",c.NftBurnEvent="nft_burn_event",c.FtTransferEvent="ft_transfer_event",c.FtMintEvent="ft_mint_event",c.FtBurnEvent="ft_burn_event",c))(st||{});function te(t,e){return t.filter(n=>n.type===e)}function ne(t,e={}){let n={};for(let r in t){let o=t[r],i=e.deployerAddress||o.address,s=`${i}.${o.name}`,p=o.contract(i,o.name);n[r]={identifier:s,contract:p}}return n}import{addressToString as R,ClarityType as a,uintCV as ct,contractPrincipalCV as pt,intCV as lt,stringAsciiCV as ut,stringUtf8CV as ft,noneCV as dt,someCV as yt,tupleCV as Tt,listCV as Ct,hexToCV as mt,bufferCV as xt}from"micro-stacks/clarity";import{isClarityAbiList as gt,isClarityAbiOptional as bt,isClarityAbiStringAscii as At,isClarityAbiStringUtf8 as vt,isClarityAbiTuple as Et,isClarityAbiBuffer as Ot,parseToCV as _}from"micro-stacks/transactions";import{bytesToAscii as kt,bytesToHex as B}from"micro-stacks/common";function $(t){return{isOk:!0,value:t}}function M(t){return{isOk:!1,value:t}}function v(t){if(t.type===a.PrincipalStandard)return R(t.address);if(t.type===a.PrincipalContract)return`${R(t.address)}.${t.contractName.content}`;throw new Error(`Unexpected principal data: ${JSON.stringify(t)}`)}function f(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 f(t.value);case a.ResponseErr:return e?M(f(t.value)):f(t.value);case a.ResponseOk:return e?$(f(t.value)):f(t.value);case a.PrincipalStandard:case a.PrincipalContract:return v(t);case a.List:return t.list.map(r=>f(r));case a.Tuple:return Object.entries(t.data).reduce((r,[o,i])=>{let s=C(o);return x(y({},r),{[s]:f(i)})},{});case a.StringASCII:return t.data;case a.StringUTF8:return t.data}}function ye(t,e=!1){return f(mt(t),e)}function I(t){if(!(typeof t=="bigint"||typeof t=="number"||typeof t=="string"))throw new Error("Invalid input type for integer");return BigInt(t)}function d(t,e){if(Et(e)){if(typeof t!="object")throw new Error("Invalid tuple input");let n={};return e.tuple.forEach(r=>{let o=E(r.name,t),i=t[o];n[r.name]=d(i,r.type)}),Tt(n)}else if(gt(e)){let r=t.map(o=>d(o,e.list.type));return Ct(r)}else{if(bt(e))return t?yt(d(t,e.optional)):dt();if(At(e)){if(typeof t!="string")throw new Error("Invalid string-ascii input");return ut(t)}else if(vt(e)){if(typeof t!="string")throw new Error("Invalid string-ascii input");return ft(t)}else if(e==="bool"){let n=typeof t=="boolean"?t.toString():t;return _(n,e)}else if(e==="uint128"){let n=I(t);return ct(n.toString())}else if(e==="int128"){let n=I(t);return lt(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 pt(n,r)}else if(Ot(e))return xt(t)}return _(t,e)}function g(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=kt(t.buffer);if(/[ -~]/.test(n))return JSON.stringify(n)}return`0x${B(t.buffer)}`;case a.OptionalNone:return"none";case a.OptionalSome:return`(some ${g(t.value,e)})`;case a.ResponseErr:return`(err ${g(t.value,e)})`;case a.ResponseOk:return`(ok ${g(t.value,e)})`;case a.PrincipalStandard:case a.PrincipalContract:return`'${v(t)}`;case a.List:return`(list ${t.list.map(n=>g(n,e)).join(" ")})`;case a.Tuple:return`(tuple ${Object.keys(t.data).map(n=>`(${n} ${g(t.data[n],e)})`).join(" ")})`;case a.StringASCII:return`"${t.data}"`;case a.StringUTF8:return`u"${t.data}"`}}function T(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 B(t.buffer);case a.OptionalNone:return null;case a.OptionalSome:return T(t.value);case a.ResponseErr:return e?M(T(t.value)):T(t.value);case a.ResponseOk:return e?$(T(t.value)):T(t.value);case a.PrincipalStandard:case a.PrincipalContract:return v(t);case a.List:return t.list.map(r=>T(r));case a.Tuple:return Object.entries(t.data).reduce((r,[o,i])=>{let s=C(o);return x(y({},r),{[s]:T(i)})},{});case a.StringASCII:return t.data;case a.StringUTF8:return t.data}}function V(t,e){return t.args.map(n=>{let r=E(n.name,e),o=e[r];return d(o,n.type)})}function ht(t,e){return e.map((n,r)=>d(n,t.args[r].type))}function b(t,e){if(e.length===0)return[];let[n]=e;if(e.length===1&&t.args.length!==1)return V(t,n);if(typeof n=="object"&&!Array.isArray(n)&&n!==null)try{let r=!0;if(t.args.forEach(o=>{try{E(o.name,n)}catch{r=!1}}),r)return V(t,n)}catch{}return ht(t,e)}function E(t,e){let n=Object.keys(e).find(r=>{let o=t===r,i=t===S(r);return o||i});if(!n)throw new Error(`Error encoding JS tuple: ${t} not found in input.`);return n}function D(t){if(t.isOk)return t.value;throw new Error(`Expected OK, received error: ${String(t.value)}`)}function U(t){if(!t.isOk)return t.value;throw new Error(`Expected Err, received ok: ${String(t.value)}`)}function Nt(t,e){let n=t.abi.functions.find(o=>C(o.name)===e);if(n)return function(...o){return{functionArgs:b(n,o),contractAddress:t.contractAddress,contractName:t.contractName,function:n,functionName:n.name,nativeArgs:o}};let r=t.abi.maps.find(o=>C(o.name)===e);if(r)return o=>{let i=d(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 Pt={get:Nt},wt=t=>new Proxy(t,Pt);import{v2Endpoint as Vt,generateUrl as Bt}from"micro-stacks/api";import{cvToHex as $t,hexToCV as Mt}from"micro-stacks/clarity";import{broadcastRawTransaction as Dt}from"micro-stacks/transactions";function Ft(t){let e=[];return t.forEach(n=>e.push(...n.transactions)),e}function j(t){return Ft(t).filter(O)}function K(t){if(!O(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 J(t){if(!O(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 O(t){return!("contract-call"in t||"btc-transfer"in t||"emulated-contract-call"in t)}var Fe=["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,L(o,i)]),!1}),Object.fromEntries(n)}function Re(t,e){return Object.fromEntries(Object.entries(t).map(([n,r])=>{let o=`${e}.${r.contractName}`;return[n,L(r,o)]}))}function St(t,e){return Object.fromEntries(Object.entries(t).map(([n,r])=>{let o=Object.assign((...i)=>{let s=b(r,i),[p,l]=e.split(".");return{functionArgs:s,contractAddress:p,contractName:l,function:r,functionName:r.name,nativeArgs:i}},{abi:r});return[n,o]}))}function L(t,e){let n=y({},t);return x(y(y({},St(t.functions,e)),n),{identifier:e})}function _e(t,e){let n={};return j(e.plan.batches).forEach(o=>{let i=J(o),[s,p]=i.split("."),l=C(p),m=t[l],u=t[l];if(typeof u>"u")throw new Error(`Clarigen error: mismatch for contract '${l}'`);n[l]=u,u.contractFile=K(o),u.identifier=i,Object.keys(t[l].functions).forEach(c=>{let A=c,Y=(...N)=>{let P=m.functions[A];return{functionArgs:b(P,N),contractAddress:s,contractName:u.contractName,function:P,nativeArgs:N}};u[A]=Y})}),n}function q(t,e){let n=d(e,t.key);return{key:e,keyCV:n,map:t}}import{parseReadOnlyResponse as Rt}from"micro-stacks/api";import{cvToHex as _t}from"micro-stacks/clarity";import{fetchPrivate as It}from"micro-stacks/common";async function W(t){let{contractName:e,contractAddress:n,functionName:r,functionArgs:o,senderAddress:i=n,tip:s,url:p}=t,l=`${p}/v2/contracts/call-read/${n}/${e}/${encodeURIComponent(r)}`;s&&(l+=`?tip=${s}`);let m=JSON.stringify({sender:i,arguments:o.map(c=>typeof c=="string"?c:_t(c))}),u=await It(l,{method:"POST",body:m,headers:{"Content-Type":"application/json"}});if(!u.ok){let c="";try{c=await u.text()}catch{}throw new Error(`Error calling read-only function. Response ${u.status}: ${u.statusText}. Attempted to fetch ${l} and failed with the message: "${c}"`)}return Rt(await u.json())}function H(t){if(t.latest!==!1)return t.latest||typeof t.tip>"u"?"latest":t.tip}async function k(t,e){let n=H(e),r=await W({contractAddress:t.contractAddress,contractName:t.contractName,functionName:t.functionName,functionArgs:t.functionArgs,tip:n,url:h(e)});return e.json?T(r):f(r,!0)}async function Ut(t,e){let n=await k(t,e);return D(n)}async function jt(t,e){let n=await k(t,e);return U(n)}function h(t){return"network"in t?t.network.getCoreApiUrl():t.url}async function Ye(t,e,n,r){let o=q(e,n),i=JSON.stringify($t(o.keyCV)),[s,p]=t.split("."),l=Bt(`${Vt(h(r))}/map_entry/${s}/${p}/${o.map.name}`,{proof:0,tip:H(r)}),u=await(await fetch(l,{method:"POST",body:i,headers:{"Content-Type":"application/json",Accept:"application/json"}})).json(),c=Mt(u.data);return f(c,!0)}async function Qe(t,e){let n=`${h(e)}/v2/transactions`,r=await Dt(t.serialize(),n);if("error"in r)throw new Error(`Error broadcasting tx: ${r.error} - ${r.reason} - ${JSON.stringify(r.reason_data)}`);return{txId:r.txid,stacksTransaction:t}}var z=class{constructor(e){typeof e=="string"?this.url=e:this.url=e.getCoreApiUrl()}roOptions(e){return y({url:this.url},e)}ro(e,n){return k(e,this.roOptions(n||{}))}roOk(e,n){return Ut(e,this.roOptions(n||{}))}roErr(e,n){return jt(e,this.roOptions(n||{}))}};import{createAssetInfo as G,makeContractFungiblePostCondition as Kt,makeContractNonFungiblePostCondition as Jt,makeStandardFungiblePostCondition as Lt,makeStandardNonFungiblePostCondition as qt}from"micro-stacks/transactions";function Z(t,e){if(!("identifier"in t))throw new Error("Invalid contract");let[n,r]=t.identifier.split(".");for(let o of t.non_fungible_tokens)if(o.name===e)return G(n,r,o.name);for(let o of t.fungible_tokens)if(o.name===e)return G(n,r,o.name);throw new Error(`Invalid asset: "${r}" is not an asset in contract.`)}function cn(t,e,n,r){let[o,i]=e.split("."),[s]=t.non_fungible_tokens,p=Z(t,s.name),l=s.type,m=d(r,l);return typeof i>"u"?qt(o,n,p,m):Jt(o,i,n,p,m)}function pn(t,e,n,r){let[o,i]=e.split("."),[s]=t.fungible_tokens,p=Z(t,s.name);return typeof i>"u"?Lt(o,n,r,p):Kt(o,i,n,r,p)}export{z as ClarigenClient,st as CoreNodeEventType,Fe as DEPLOYMENT_NETWORKS,at as MAINNET_BURN_ADDRESS,ot as TESTNET_BURN_ADDRESS,Qt as bootContractIdentifier,Qe as broadcast,L as contractFactory,Re as contractsFactory,Z as createAssetInfo,T as cvToJSON,g as cvToString,f as cvToValue,_e as deploymentFactory,M as err,U as expectErr,D as expectOk,Ye as fetchMapGet,te as filterEvents,E as findJsTupleKey,St as functionsFactory,h as getApiUrl,Zt as getContractIdentifier,it as getContractNameFromPath,Yt as getContractPrincipalCV,ye as hexToCvValue,ne as makeContracts,pn as makeFungiblePostCondition,cn as makeNonFungiblePostCondition,q as mapFactory,$ as ok,d as parseToCV,v as principalToString,Se as projectFactory,wt as pureProxy,k as ro,jt as roErr,Ut as roOk,C as toCamelCase,S as toKebabCase,ht as transformArgsArray,b as transformArgsToCV,V as transformObjectArgs};
|
|
1
|
+
var Q=Object.defineProperty,X=Object.defineProperties;var tt=Object.getOwnPropertyDescriptors;var P=Object.getOwnPropertySymbols;var et=Object.prototype.hasOwnProperty,nt=Object.prototype.propertyIsEnumerable;var S=(t,e,n)=>e in t?Q(t,e,{enumerable:!0,configurable:!0,writable:!0,value:n}):t[e]=n,d=(t,e)=>{for(var n in e||(e={}))et.call(e,n)&&S(t,n,e[n]);if(P)for(var n of P(e))nt.call(e,n)&&S(t,n,e[n]);return t},x=(t,e)=>X(t,tt(e));import{contractPrincipalCV as rt}from"micro-stacks/clarity";var ot="ST000000000000000000002AMW42H",it="SP000000000000000000002Q6VF78",C=(t,e)=>{let n=typeof t=="string"?t:String(t),[r,...o]=n.replace("!","").replace("?","").split("-"),s=`${e?r[0].toUpperCase():r[0].toLowerCase()}${r.slice(1)}`;return o.forEach(p=>{s+=p[0].toUpperCase()+p.slice(1)}),s};function F(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 at=t=>{let e=t.split("/"),n=e[e.length-1],[r]=n.split(".");return r},Zt=t=>`${t.address}.${t.name}`,Yt=t=>{let e=at(t.contractFile);return rt(t.address,e)};function Qt(t,e){return`${e?it:ot}.${t}`}var st=(c=>(c.ContractEvent="contract_event",c.StxTransferEvent="stx_transfer_event",c.StxMintEvent="stx_mint_event",c.StxBurnEvent="stx_burn_event",c.StxLockEvent="stx_lock_event",c.NftTransferEvent="nft_transfer_event",c.NftMintEvent="nft_mint_event",c.NftBurnEvent="nft_burn_event",c.FtTransferEvent="ft_transfer_event",c.FtMintEvent="ft_mint_event",c.FtBurnEvent="ft_burn_event",c))(st||{});function te(t,e){return t.filter(n=>n.type===e)}function ne(t,e={}){let n={};for(let r in t){let o=t[r],a=e.deployerAddress||o.address,s=`${a}.${o.name}`,p=o.contract(a,o.name);n[r]={identifier:s,contract:p}}return n}import{addressToString as R,ClarityType as i,uintCV as ct,contractPrincipalCV as pt,intCV as lt,stringAsciiCV as ut,stringUtf8CV as ft,noneCV as yt,someCV as dt,tupleCV as Tt,listCV as Ct,hexToCV as mt,bufferCV as xt}from"micro-stacks/clarity";import{parseToCV as I}from"micro-stacks/transactions";import{bytesToAscii as bt,bytesToHex as B}from"micro-stacks/common";function $(t){return{isOk:!0,value:t}}function D(t){return{isOk:!1,value:t}}function v(t){if(t.type===i.PrincipalStandard)return R(t.address);if(t.type===i.PrincipalContract)return`${R(t.address)}.${t.contractName.content}`;throw new Error(`Unexpected principal data: ${JSON.stringify(t)}`)}function f(t,e=!1){switch(t.type){case i.BoolTrue:return!0;case i.BoolFalse:return!1;case i.Int:case i.UInt:return t.value;case i.Buffer:return t.buffer;case i.OptionalNone:return null;case i.OptionalSome:return f(t.value);case i.ResponseErr:return e?D(f(t.value)):f(t.value);case i.ResponseOk:return e?$(f(t.value)):f(t.value);case i.PrincipalStandard:case i.PrincipalContract:return v(t);case i.List:return t.list.map(r=>f(r));case i.Tuple:return Object.entries(t.data).reduce((r,[o,a])=>{let s=C(o);return x(d({},r),{[s]:f(a)})},{});case i.StringASCII:return t.data;case i.StringUTF8:return t.data}}function ye(t,e=!1){return f(mt(t),e)}function _(t){if(!(typeof t=="bigint"||typeof t=="number"||typeof t=="string"))throw new Error("Invalid input type for integer");return BigInt(t)}var de=t=>typeof t=="string",gt=t=>t.buffer!==void 0,At=t=>t["string-ascii"]!==void 0,vt=t=>t["string-utf8"]!==void 0,Te=t=>t.response!==void 0,Et=t=>t.optional!==void 0,Ot=t=>t.tuple!==void 0,ht=t=>t.list!==void 0;function y(t,e){if(Ot(e)){if(typeof t!="object")throw new Error("Invalid tuple input");let n={};return e.tuple.forEach(r=>{let o=E(r.name,t),a=t[o];n[r.name]=y(a,r.type)}),Tt(n)}else if(ht(e)){let r=t.map(o=>y(o,e.list.type));return Ct(r)}else{if(Et(e))return t===null?yt():dt(y(t,e.optional));if(At(e)){if(typeof t!="string")throw new Error("Invalid string-ascii input");return ut(t)}else if(vt(e)){if(typeof t!="string")throw new Error("Invalid string-ascii input");return ft(t)}else if(e==="bool"){let n=typeof t=="boolean"?t.toString():t;return I(n,e)}else if(e==="uint128"){let n=_(t);return ct(n.toString())}else if(e==="int128"){let n=_(t);return lt(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 pt(n,r)}else if(gt(e))return xt(t)}return I(t,e)}function b(t,e="hex"){switch(t.type){case i.BoolTrue:return"true";case i.BoolFalse:return"false";case i.Int:return t.value.toString();case i.UInt:return`u${t.value.toString()}`;case i.Buffer:if(e==="tryAscii"){let n=bt(t.buffer);if(/[ -~]/.test(n))return JSON.stringify(n)}return`0x${B(t.buffer)}`;case i.OptionalNone:return"none";case i.OptionalSome:return`(some ${b(t.value,e)})`;case i.ResponseErr:return`(err ${b(t.value,e)})`;case i.ResponseOk:return`(ok ${b(t.value,e)})`;case i.PrincipalStandard:case i.PrincipalContract:return`'${v(t)}`;case i.List:return`(list ${t.list.map(n=>b(n,e)).join(" ")})`;case i.Tuple:return`(tuple ${Object.keys(t.data).map(n=>`(${n} ${b(t.data[n],e)})`).join(" ")})`;case i.StringASCII:return`"${t.data}"`;case i.StringUTF8:return`u"${t.data}"`}}function T(t,e=!1){switch(t.type){case i.BoolTrue:return!0;case i.BoolFalse:return!1;case i.Int:case i.UInt:return`${t.value}`;case i.Buffer:return B(t.buffer);case i.OptionalNone:return null;case i.OptionalSome:return T(t.value);case i.ResponseErr:return e?D(T(t.value)):T(t.value);case i.ResponseOk:return e?$(T(t.value)):T(t.value);case i.PrincipalStandard:case i.PrincipalContract:return v(t);case i.List:return t.list.map(r=>T(r));case i.Tuple:return Object.entries(t.data).reduce((r,[o,a])=>{let s=C(o);return x(d({},r),{[s]:T(a)})},{});case i.StringASCII:return t.data;case i.StringUTF8:return t.data}}function V(t,e){return t.args.map(n=>{let r=E(n.name,e),o=e[r];return y(o,n.type)})}function kt(t,e){return e.map((n,r)=>y(n,t.args[r].type))}function g(t,e){if(e.length===0)return[];let[n]=e;if(e.length===1&&t.args.length!==1)return V(t,n);if(typeof n=="object"&&!Array.isArray(n)&&n!==null)try{let r=!0;if(t.args.forEach(o=>{try{E(o.name,n)}catch{r=!1}}),r)return V(t,n)}catch{}return kt(t,e)}function E(t,e){let n=Object.keys(e).find(r=>{let o=t===r,a=t===F(r);return o||a});if(!n)throw new Error(`Error encoding JS tuple: ${t} not found in input.`);return n}function M(t){if(t.isOk)return t.value;throw new Error(`Expected OK, received error: ${String(t.value)}`)}function U(t){if(!t.isOk)return t.value;throw new Error(`Expected Err, received ok: ${String(t.value)}`)}function Nt(t,e){let n=t.abi.functions.find(o=>C(o.name)===e);if(n)return function(...o){return{functionArgs:g(n,o),contractAddress:t.contractAddress,contractName:t.contractName,function:n,functionName:n.name,nativeArgs:o}};let r=t.abi.maps.find(o=>C(o.name)===e);if(r)return o=>{let a=y(o,r.key);return{contractAddress:t.contractAddress,contractName:t.contractName,map:r,nativeKey:o,key:a}};throw new Error(`Invalid function call: no function exists for ${String(e)}`)}var wt={get:Nt},Pt=t=>new Proxy(t,wt);import{v2Endpoint as Vt,generateUrl as Bt}from"micro-stacks/api";import{cvToHex as $t,hexToCV as Dt}from"micro-stacks/clarity";import{broadcastRawTransaction as Mt}from"micro-stacks/transactions";function St(t){let e=[];return t.forEach(n=>e.push(...n.transactions)),e}function j(t){return St(t).filter(O)}function J(t){if(!O(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 K(t){if(!O(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 O(t){return!("contract-call"in t||"btc-transfer"in t||"emulated-contract-call"in t)}var Fe=["devnet","simnet","testnet","mainnet"];function Re(t,e){let n=[];return Object.entries(t.contracts).forEach(([r,o])=>{let a=t.deployments[r][e];return a&&n.push([r,L(o,a)]),!1}),Object.fromEntries(n)}function Ie(t,e){return Object.fromEntries(Object.entries(t).map(([n,r])=>{let o=`${e}.${r.contractName}`;return[n,L(r,o)]}))}function Ft(t,e){return Object.fromEntries(Object.entries(t).map(([n,r])=>{let o=Object.assign((...a)=>{let s=g(r,a),[p,l]=e.split(".");return{functionArgs:s,contractAddress:p,contractName:l,function:r,functionName:r.name,nativeArgs:a}},{abi:r});return[n,o]}))}function L(t,e){let n=d({},t);return x(d(d({},Ft(t.functions,e)),n),{identifier:e})}function _e(t,e){let n={};return j(e.plan.batches).forEach(o=>{let a=K(o),[s,p]=a.split("."),l=C(p),m=t[l],u=t[l];if(typeof u>"u")throw new Error(`Clarigen error: mismatch for contract '${l}'`);n[l]=u,u.contractFile=J(o),u.identifier=a,Object.keys(t[l].functions).forEach(c=>{let A=c,Y=(...N)=>{let w=m.functions[A];return{functionArgs:g(w,N),contractAddress:s,contractName:u.contractName,function:w,nativeArgs:N}};u[A]=Y})}),n}function q(t,e){let n=y(e,t.key);return{key:e,keyCV:n,map:t}}import{parseReadOnlyResponse as Rt}from"micro-stacks/api";import{cvToHex as It}from"micro-stacks/clarity";import{fetchPrivate as _t}from"micro-stacks/common";async function z(t){let{contractName:e,contractAddress:n,functionName:r,functionArgs:o,senderAddress:a=n,tip:s,url:p}=t,l=`${p}/v2/contracts/call-read/${n}/${e}/${encodeURIComponent(r)}`;s&&(l+=`?tip=${s}`);let m=JSON.stringify({sender:a,arguments:o.map(c=>typeof c=="string"?c:It(c))}),u=await _t(l,{method:"POST",body:m,headers:{"Content-Type":"application/json"}});if(!u.ok){let c="";try{c=await u.text()}catch{}throw new Error(`Error calling read-only function. Response ${u.status}: ${u.statusText}. Attempted to fetch ${l} and failed with the message: "${c}"`)}return Rt(await u.json())}function H(t){if(t.latest!==!1)return t.latest||typeof t.tip>"u"?"latest":t.tip}async function h(t,e){let n=H(e),r=await z({contractAddress:t.contractAddress,contractName:t.contractName,functionName:t.functionName,functionArgs:t.functionArgs,tip:n,url:k(e)});return e.json?T(r):f(r,!0)}async function Ut(t,e){let n=await h(t,e);return M(n)}async function jt(t,e){let n=await h(t,e);return U(n)}function k(t){return"network"in t?t.network.getCoreApiUrl():t.url}async function Qe(t,e,n,r){let o=q(e,n),a=JSON.stringify($t(o.keyCV)),[s,p]=t.split("."),l=Bt(`${Vt(k(r))}/map_entry/${s}/${p}/${o.map.name}`,{proof:0,tip:H(r)}),u=await(await fetch(l,{method:"POST",body:a,headers:{"Content-Type":"application/json",Accept:"application/json"}})).json(),c=Dt(u.data);return f(c,!0)}async function Xe(t,e){let n=`${k(e)}/v2/transactions`,r=await Mt(t.serialize(),n);if("error"in r)throw new Error(`Error broadcasting tx: ${r.error} - ${r.reason} - ${JSON.stringify(r.reason_data)}`);return{txId:r.txid,stacksTransaction:t}}var W=class{constructor(e){typeof e=="string"?this.url=e:this.url=e.getCoreApiUrl()}roOptions(e){return d({url:this.url},e)}ro(e,n){return h(e,this.roOptions(n||{}))}roOk(e,n){return Ut(e,this.roOptions(n||{}))}roErr(e,n){return jt(e,this.roOptions(n||{}))}};import{createAssetInfo as G,makeContractFungiblePostCondition as Jt,makeContractNonFungiblePostCondition as Kt,makeStandardFungiblePostCondition as Lt,makeStandardNonFungiblePostCondition as qt}from"micro-stacks/transactions";function Z(t,e){if(!("identifier"in t))throw new Error("Invalid contract");let[n,r]=t.identifier.split(".");for(let o of t.non_fungible_tokens)if(o.name===e)return G(n,r,o.name);for(let o of t.fungible_tokens)if(o.name===e)return G(n,r,o.name);throw new Error(`Invalid asset: "${e}" is not an asset in contract.`)}function ln(t,e,n,r){let[o,a]=e.split("."),[s]=t.non_fungible_tokens,p=Z(t,s.name),l=s.type,m=y(r,l);return typeof a>"u"?qt(o,n,p,m):Kt(o,a,n,p,m)}function un(t,e,n,r){let[o,a]=e.split("."),[s]=t.fungible_tokens,p=Z(t,s.name);return typeof a>"u"?Lt(o,n,r,p):Jt(o,a,n,r,p)}export{W as ClarigenClient,st as CoreNodeEventType,Fe as DEPLOYMENT_NETWORKS,it as MAINNET_BURN_ADDRESS,ot as TESTNET_BURN_ADDRESS,Qt as bootContractIdentifier,Xe as broadcast,L as contractFactory,Ie as contractsFactory,Z as createAssetInfo,T as cvToJSON,b as cvToString,f as cvToValue,_e as deploymentFactory,D as err,U as expectErr,M as expectOk,Qe as fetchMapGet,te as filterEvents,E as findJsTupleKey,Ft as functionsFactory,k as getApiUrl,Zt as getContractIdentifier,at as getContractNameFromPath,Yt as getContractPrincipalCV,ye as hexToCvValue,gt as isClarityAbiBuffer,ht as isClarityAbiList,Et as isClarityAbiOptional,de as isClarityAbiPrimitive,Te as isClarityAbiResponse,At as isClarityAbiStringAscii,vt as isClarityAbiStringUtf8,Ot as isClarityAbiTuple,ne as makeContracts,un as makeFungiblePostCondition,ln as makeNonFungiblePostCondition,q as mapFactory,$ as ok,y as parseToCV,v as principalToString,Re as projectFactory,Pt as pureProxy,h as ro,jt as roErr,Ut as roOk,C as toCamelCase,F as toKebabCase,kt as transformArgsArray,g as transformArgsToCV,V as transformObjectArgs};
|
package/package.json
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
{
|
|
2
|
-
"version": "1.0.
|
|
2
|
+
"version": "1.0.15",
|
|
3
3
|
"license": "MIT",
|
|
4
4
|
"types": "./dist/index.d.ts",
|
|
5
5
|
"main": "./dist/index.js",
|
|
@@ -17,6 +17,9 @@
|
|
|
17
17
|
"dependencies": {
|
|
18
18
|
"micro-stacks": "^1.1.4"
|
|
19
19
|
},
|
|
20
|
+
"devDependencies": {
|
|
21
|
+
"demo-project": "1.0.15"
|
|
22
|
+
},
|
|
20
23
|
"publishConfig": {
|
|
21
24
|
"access": "public"
|
|
22
25
|
},
|