UNPKG

@xlink-network/xlink-sdk

Version:
1 lines 3.98 kB
{"version":3,"sources":["../src/xlinkSdkUtils/types.ts"],"sourcesContent":["import { EVMEndpointContract } from \"../evmUtils/evmContractAddresses\"\nimport { BigNumber } from \"../utils/BigNumber\"\nimport { InvalidMethodParametersError } from \"../utils/errors\"\n\ntype SDKBrandedLiteral<\n Type extends string,\n T extends string | number,\n> = `${T} (XLinkSDK ${Type})`\n\n/**\n * Represents a unique identifier for a blockchain network.\n */\nexport type ChainId<T extends string = string> = SDKBrandedLiteral<\"ChainId\", T>\n/**\n * Represents a unique identifier for a cryptocurrency token.\n */\nexport type TokenId<T extends string = string> = SDKBrandedLiteral<\"TokenId\", T>\n\nexport type SDKNumber = SDKBrandedLiteral<\"number\", string>\nexport type SDKNumberifyNestly<T> =\n {\n // prettier-ignore\n [K in keyof T]:\n number extends T[K] ? SDKNumber | Exclude<T[K], number> :\n bigint extends T[K] ? SDKNumber | Exclude<T[K], bigint> :\n BigNumber extends T[K] ? SDKNumber | Exclude<T[K], BigNumber> :\n undefined extends T[K] ? undefined | SDKNumberifyNestly<Exclude<T[K], undefined>> :\n null extends T[K] ? null | SDKNumberifyNestly<Exclude<T[K], null>> :\n T[K] extends object ? SDKNumberifyNestly<T[K]> :\n T[K]\n}\n/**\n * https://github.com/MikeMcl/big.js/blob/9c6c959c92dc9044a0f98c31f60322fd91243468/big.js#L74\n */\nconst NUMERIC = /^-?(\\d+(\\.\\d*)?|\\.\\d+)(e[+-]?\\d+)?$/i\nexport function toSDKNumberOrUndefined<\n T extends null | undefined | SDKNumber | number | bigint | BigNumber,\n>(n: T): Exclude<T, number | bigint | BigNumber> | SDKNumber {\n if (n == null) return undefined as any\n\n const str = BigNumber.toString(n)\n if (!NUMERIC.test(str)) {\n throw new InvalidMethodParametersError(\n [\"toSDKNumberOrUndefined\"],\n [\n {\n name: \"n\",\n expected:\n \"a number, bigint, or a string that can be converted to a number\",\n received: str,\n },\n ],\n )\n }\n\n return BigNumber.toString(n) as SDKNumber\n}\n\nexport type EVMAddress = `0x${string}`\n\nexport const evmNativeCurrencyAddress = Symbol(\n \"[XLinkSDK] EVM Native Currency Address\",\n)\nexport type EVMNativeCurrencyAddress = typeof evmNativeCurrencyAddress\n\nexport interface StacksContractAddress {\n deployerAddress: string\n contractName: string\n}\nexport const isStacksContractAddressEqual = (\n a: StacksContractAddress,\n b: StacksContractAddress,\n): boolean => {\n return (\n a.deployerAddress === b.deployerAddress && a.contractName === b.contractName\n )\n}\n\n/**\n * Represents the type of public EVM contracts that are accessible through the SDK.\n * The `PublicEVMContractType` is tied to the specific `BridgeEndpoint` contract type defined\n * in the `EVMEndpointContract` namespace.\n */\nexport type PublicEVMContractType = typeof PublicEVMContractType.BridgeEndpoint\n/**\n * A namespace that defines the public contract types available in the SDK for EVM-compatible blockchains.\n * This namespace currently includes only the `BridgeEndpoint` contract type, which corresponds to\n * the main contract used for bridging assets across EVM-compatible blockchains.\n */\nexport namespace PublicEVMContractType {\n /** Represents the bridge endpoint contract type in an EVM-compatible blockchain. */\n export const BridgeEndpoint = EVMEndpointContract.BridgeEndpoint\n}\n"],"mappings":";;;;;;;;;;;AAkCA,IAAM,UAAU;AACT,SAAS,uBAEd,GAA2D;AAC3D,MAAI,KAAK,KAAM,QAAO;AAEtB,QAAM,MAAM,UAAU,SAAS,CAAC;AAChC,MAAI,CAAC,QAAQ,KAAK,GAAG,GAAG;AACtB,UAAM,IAAI;AAAA,MACR,CAAC,wBAAwB;AAAA,MACzB;AAAA,QACE;AAAA,UACE,MAAM;AAAA,UACN,UACE;AAAA,UACF,UAAU;AAAA,QACZ;AAAA,MACF;AAAA,IACF;AAAA,EACF;AAEA,SAAO,UAAU,SAAS,CAAC;AAC7B;AAIO,IAAM,2BAA2B;AAAA,EACtC;AACF;AAOO,IAAM,+BAA+B,CAC1C,GACA,MACY;AACZ,SACE,EAAE,oBAAoB,EAAE,mBAAmB,EAAE,iBAAiB,EAAE;AAEpE;AAaO,IAAU;AAAA,CAAV,CAAUA,2BAAV;AAEE,EAAMA,uBAAA,iBAAiB,oBAAoB;AAAA,GAFnC;","names":["PublicEVMContractType"]}