@berachain/berajs 0.2.8-beta.7 → 0.2.8-beta.8
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/abi/exports.cjs +4452 -1
- package/dist/abi/exports.cjs.map +1 -1
- package/dist/abi/exports.mjs +4452 -1
- package/dist/abi/exports.mjs.map +1 -1
- package/dist/actions/exports.cjs +913 -1
- package/dist/actions/exports.cjs.map +1 -1
- package/dist/actions/exports.mjs +913 -1
- package/dist/actions/exports.mjs.map +1 -1
- package/dist/chunk-2R73G2PO.mjs +4698 -0
- package/dist/{chunk-MASD43N5.mjs.map → chunk-2R73G2PO.mjs.map} +1 -1
- package/dist/chunk-3M47ZRXT.mjs +417 -0
- package/dist/{chunk-ESAVA5OD.mjs.map → chunk-3M47ZRXT.mjs.map} +1 -1
- package/dist/chunk-4GFN4LEP.mjs +97 -0
- package/dist/{chunk-5W7UKRHX.mjs.map → chunk-4GFN4LEP.mjs.map} +1 -1
- package/dist/chunk-5N7QQS55.cjs +130 -0
- package/dist/chunk-5N7QQS55.cjs.map +1 -0
- package/dist/chunk-5NMATIH4.mjs +130 -0
- package/dist/{chunk-SSPFPAWX.mjs.map → chunk-5NMATIH4.mjs.map} +1 -1
- package/dist/chunk-7QKRRIHI.mjs +1844 -0
- package/dist/{chunk-RSDCKN4Q.mjs.map → chunk-7QKRRIHI.mjs.map} +1 -1
- package/dist/chunk-7TFV6UKF.mjs +24 -0
- package/dist/{chunk-MK5NS5B5.mjs.map → chunk-7TFV6UKF.mjs.map} +1 -1
- package/dist/chunk-A4FPM7U3.cjs +63 -0
- package/dist/chunk-A4FPM7U3.cjs.map +1 -0
- package/dist/chunk-BDHINMWQ.cjs +417 -0
- package/dist/chunk-BDHINMWQ.cjs.map +1 -0
- package/dist/chunk-BEHP54S3.cjs +24 -0
- package/dist/chunk-BEHP54S3.cjs.map +1 -0
- package/dist/chunk-EGDXV2PT.cjs +36 -0
- package/dist/chunk-EGDXV2PT.cjs.map +1 -0
- package/dist/chunk-EWBKSMPG.cjs +13 -0
- package/dist/chunk-EWBKSMPG.cjs.map +1 -0
- package/dist/chunk-F6ZW7ZDD.cjs +403 -0
- package/dist/chunk-F6ZW7ZDD.cjs.map +1 -0
- package/dist/chunk-FTXTRUYT.cjs +170 -0
- package/dist/chunk-FTXTRUYT.cjs.map +1 -0
- package/dist/chunk-GLWPRM33.mjs +13 -0
- package/dist/{chunk-575OK77P.mjs.map → chunk-GLWPRM33.mjs.map} +1 -1
- package/dist/chunk-GWSTVITN.mjs +572 -0
- package/dist/{chunk-NLVWRMGD.mjs.map → chunk-GWSTVITN.mjs.map} +1 -1
- package/dist/chunk-H3Z37RYU.cjs +15 -0
- package/dist/chunk-H3Z37RYU.cjs.map +1 -0
- package/dist/chunk-I3FTWD6I.mjs +170 -0
- package/dist/{chunk-JDZGYU5T.mjs.map → chunk-I3FTWD6I.mjs.map} +1 -1
- package/dist/chunk-JA4DHMTG.mjs +15 -0
- package/dist/{chunk-OGBD5YOG.mjs.map → chunk-JA4DHMTG.mjs.map} +1 -1
- package/dist/chunk-KL6YZ5VR.mjs +63 -0
- package/dist/{chunk-OGJMSGB2.mjs.map → chunk-KL6YZ5VR.mjs.map} +1 -1
- package/dist/chunk-MXWPP6MS.cjs +572 -0
- package/dist/chunk-MXWPP6MS.cjs.map +1 -0
- package/dist/chunk-SGZP4O6R.mjs +135 -0
- package/dist/{chunk-6K252BGM.mjs.map → chunk-SGZP4O6R.mjs.map} +1 -1
- package/dist/chunk-TDW5SPXR.cjs +244 -0
- package/dist/chunk-TDW5SPXR.cjs.map +1 -0
- package/dist/chunk-TGK3IXDN.cjs +169 -0
- package/dist/chunk-TGK3IXDN.cjs.map +1 -0
- package/dist/chunk-TJEW6YCJ.cjs +97 -0
- package/dist/chunk-TJEW6YCJ.cjs.map +1 -0
- package/dist/chunk-VA3BQ34H.mjs +403 -0
- package/dist/{chunk-UENDEN3M.mjs.map → chunk-VA3BQ34H.mjs.map} +1 -1
- package/dist/chunk-VA5L5FDG.mjs +36 -0
- package/dist/{chunk-3MZ7MLKF.mjs.map → chunk-VA5L5FDG.mjs.map} +1 -1
- package/dist/chunk-XSGCRLSD.cjs +1844 -0
- package/dist/chunk-XSGCRLSD.cjs.map +1 -0
- package/dist/chunk-XV3GG3HC.cjs +135 -0
- package/dist/chunk-XV3GG3HC.cjs.map +1 -0
- package/dist/chunk-Y5B224UX.cjs +4698 -0
- package/dist/chunk-Y5B224UX.cjs.map +1 -0
- package/dist/chunk-ZBTRKBSI.mjs +169 -0
- package/dist/{chunk-CWKDFUFR.mjs.map → chunk-ZBTRKBSI.mjs.map} +1 -1
- package/dist/chunk-ZCEFC2TK.mjs +244 -0
- package/dist/{chunk-NAXAZJJY.mjs.map → chunk-ZCEFC2TK.mjs.map} +1 -1
- package/dist/contexts/exports.cjs +82 -1
- package/dist/contexts/exports.cjs.map +1 -1
- package/dist/contexts/exports.mjs +82 -1
- package/dist/contexts/exports.mjs.map +1 -1
- package/dist/enum/exports.cjs +58 -1
- package/dist/enum/exports.cjs.map +1 -1
- package/dist/enum/exports.mjs +58 -1
- package/dist/enum/exports.mjs.map +1 -1
- package/dist/errors/exports.cjs +38 -1
- package/dist/errors/exports.cjs.map +1 -1
- package/dist/errors/exports.mjs +38 -1
- package/dist/hooks/exports.cjs +8332 -3
- package/dist/hooks/exports.cjs.map +1 -1
- package/dist/hooks/exports.mjs +8332 -3
- package/dist/hooks/exports.mjs.map +1 -1
- package/dist/utils/exports.cjs +786 -1
- package/dist/utils/exports.cjs.map +1 -1
- package/dist/utils/exports.mjs +786 -1
- package/dist/utils/exports.mjs.map +1 -1
- package/package.json +1 -1
- package/dist/chunk-3MZ7MLKF.mjs +0 -2
- package/dist/chunk-53TSJM6P.cjs +0 -2
- package/dist/chunk-53TSJM6P.cjs.map +0 -1
- package/dist/chunk-575OK77P.mjs +0 -2
- package/dist/chunk-5W7UKRHX.mjs +0 -2
- package/dist/chunk-6K252BGM.mjs +0 -2
- package/dist/chunk-CWKDFUFR.mjs +0 -2
- package/dist/chunk-D6L7LTA2.cjs +0 -2
- package/dist/chunk-D6L7LTA2.cjs.map +0 -1
- package/dist/chunk-DDEQFR3M.cjs +0 -2
- package/dist/chunk-DDEQFR3M.cjs.map +0 -1
- package/dist/chunk-DKY4QPWU.cjs +0 -2
- package/dist/chunk-DKY4QPWU.cjs.map +0 -1
- package/dist/chunk-DTBJO6VT.cjs +0 -2
- package/dist/chunk-DTBJO6VT.cjs.map +0 -1
- package/dist/chunk-ESAVA5OD.mjs +0 -2
- package/dist/chunk-JDZGYU5T.mjs +0 -2
- package/dist/chunk-JLFBRMOF.cjs +0 -2
- package/dist/chunk-JLFBRMOF.cjs.map +0 -1
- package/dist/chunk-KT6L4K4K.cjs +0 -2
- package/dist/chunk-KT6L4K4K.cjs.map +0 -1
- package/dist/chunk-MASD43N5.mjs +0 -4
- package/dist/chunk-MGGPHKA2.cjs +0 -4
- package/dist/chunk-MGGPHKA2.cjs.map +0 -1
- package/dist/chunk-MK5NS5B5.mjs +0 -2
- package/dist/chunk-NAXAZJJY.mjs +0 -2
- package/dist/chunk-NLVWRMGD.mjs +0 -2
- package/dist/chunk-OGBD5YOG.mjs +0 -2
- package/dist/chunk-OGJMSGB2.mjs +0 -2
- package/dist/chunk-OIYXOKTT.cjs +0 -2
- package/dist/chunk-OIYXOKTT.cjs.map +0 -1
- package/dist/chunk-OUD27MU7.cjs +0 -2
- package/dist/chunk-OUD27MU7.cjs.map +0 -1
- package/dist/chunk-QFLDL4UV.cjs +0 -2
- package/dist/chunk-QFLDL4UV.cjs.map +0 -1
- package/dist/chunk-RSDCKN4Q.mjs +0 -2
- package/dist/chunk-RWOICHRW.cjs +0 -2
- package/dist/chunk-RWOICHRW.cjs.map +0 -1
- package/dist/chunk-SSPFPAWX.mjs +0 -2
- package/dist/chunk-UENDEN3M.mjs +0 -2
- package/dist/chunk-UFIM7WQ4.cjs +0 -2
- package/dist/chunk-UFIM7WQ4.cjs.map +0 -1
- package/dist/chunk-WRFDB3QJ.cjs +0 -2
- package/dist/chunk-WRFDB3QJ.cjs.map +0 -1
- package/dist/chunk-XNJLSA6P.cjs +0 -2
- package/dist/chunk-XNJLSA6P.cjs.map +0 -1
- package/dist/chunk-ZYXVUXFQ.cjs +0 -2
- package/dist/chunk-ZYXVUXFQ.cjs.map +0 -1
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/utils/parseBaseArgs.ts","../src/utils/tokens.ts"],"sourcesContent":["import {\n type BeraConfig,\n chainConfigs,\n defaultChainId,\n} from \"@berachain/config/internal\";\n\nimport { InvalidArgumentError } from \"../errors/InvalidArgumentError\";\n\nexport function parseBaseArgs(args: BeraJS.BaseFunctionArgs) {\n const chainId = args.chainId ?? defaultChainId;\n const config: BeraConfig = args.config ?? chainConfigs[chainId];\n\n if (args.chainId && args.chainId !== config.chainId) {\n // this matches unless the config is explicitly provided\n throw new InvalidArgumentError({\n property: \"chainId\",\n value: chainId,\n expected: `config.chainId: ${config.chainId}`,\n });\n }\n\n return { config, chainId: config.chainId };\n}\n","import { type Address, ethAddress, isAddress, zeroAddress } from \"viem\";\n\nimport { mainnet } from \"@berachain/config/mainnet\";\n\nimport { InvalidArgumentError } from \"../errors/InvalidArgumentError\";\nimport type { TokenWithMetadata } from \"../types/dex\";\nimport { parseBaseArgs } from \"./parseBaseArgs\";\n\nexport const beraToken = {\n address: zeroAddress,\n decimals: 18,\n name: \"Bera\",\n symbol: \"BERA\",\n logoURI:\n \"https://imagedelivery.net/qNj7Q3MCke89zoKzav7eDQ/tokens/0x0000000000000000000000000000000000000000.png/public\",\n} as const satisfies Omit<TokenWithMetadata, \"chainId\">;\n\nexport const wBeraToken = {\n address: mainnet.tokens.wbera,\n decimals: 18,\n name: \"WBera\",\n symbol: \"WBERA\",\n} as const satisfies Omit<TokenWithMetadata, \"chainId\">;\n\nexport function getHoneyToken(baseArgs: BeraJS.BaseFunctionArgs) {\n const { config, chainId } = parseBaseArgs(baseArgs);\n\n return {\n address: config.honey.token,\n symbol: \"HONEY\",\n name: \"Honey\",\n decimals: 18,\n chainId,\n } as const satisfies TokenWithMetadata;\n}\n\ntype KnownTokens = \"BERA\" | \"WBERA\" | \"BGT\" | \"HONEY\" | \"SWBERA\" | \"ETH\";\n\ntype BaseToken =\n | {\n address: Address | string;\n }\n | Address;\n\ntype InputToken = BaseToken | string | undefined;\n\ntype IsTokenParams =\n | [\n token: InputToken,\n compareTo:\n | BaseToken\n | Extract<KnownTokens, \"BERA\" | \"WBERA\" | \"ETH\" | \"SWBERA\">,\n ]\n | [\n token: InputToken,\n compareTo: BaseToken | KnownTokens,\n baseArgs: BeraJS.BaseFunctionArgs,\n ];\n\nexport function isToken(...args: IsTokenParams): boolean {\n const [token, compareTo, baseArgs] = args;\n\n if (token === undefined) return false;\n\n const tokenAddress = typeof token === \"string\" ? token : token.address;\n\n if (\n typeof compareTo === \"string\" &&\n !isAddress(compareTo) &&\n // this is a safeguard against weird inputs from enso. `0x00`\n !compareTo.startsWith(\"0x\")\n ) {\n if (compareTo === \"BERA\") {\n return tokenAddress.toLowerCase() === zeroAddress;\n }\n if (compareTo === \"WBERA\") {\n // we are sure that wbera token is the same on all chains because it's checked on the config and forced as types\n return tokenAddress.toLowerCase() === mainnet.tokens.wbera;\n }\n\n if (compareTo === \"ETH\") {\n return tokenAddress.toLowerCase() === ethAddress;\n }\n\n if (compareTo === \"SWBERA\") {\n // we are sure that wbera token is the same on all chains because it's checked on the config and forced as types\n return tokenAddress.toLowerCase() === mainnet.tokens.swbera.toLowerCase();\n }\n\n if (baseArgs === undefined) {\n throw new InvalidArgumentError({\n property: \"baseArgs\",\n value: baseArgs,\n expected: \"BeraJS.BaseFunctionArgs\",\n message:\n \"baseArgs is required when compared to a known token different than BERA or WBERA. Checking against token: \" +\n compareTo +\n \" and token address: \" +\n tokenAddress,\n });\n }\n const { config } = parseBaseArgs(baseArgs);\n\n const tokenMap: Record<Exclude<KnownTokens, \"BERA\" | \"WBERA\">, Address> = {\n BGT: config.tokens.bgt,\n HONEY: config.honey.token,\n SWBERA: config.tokens.swbera,\n ETH: ethAddress as Address,\n } as const;\n if (compareTo in tokenMap) {\n return (\n tokenAddress.toLowerCase() ===\n tokenMap[compareTo as keyof typeof tokenMap].toLowerCase()\n );\n }\n }\n\n const compareToAddress =\n typeof compareTo === \"object\" ? compareTo.address : compareTo;\n\n return tokenAddress.toLowerCase() === compareToAddress.toLowerCase();\n}\n"],"mappings":"
|
|
1
|
+
{"version":3,"sources":["../src/utils/parseBaseArgs.ts","../src/utils/tokens.ts"],"sourcesContent":["import {\n type BeraConfig,\n chainConfigs,\n defaultChainId,\n} from \"@berachain/config/internal\";\n\nimport { InvalidArgumentError } from \"../errors/InvalidArgumentError\";\n\nexport function parseBaseArgs(args: BeraJS.BaseFunctionArgs) {\n const chainId = args.chainId ?? defaultChainId;\n const config: BeraConfig = args.config ?? chainConfigs[chainId];\n\n if (args.chainId && args.chainId !== config.chainId) {\n // this matches unless the config is explicitly provided\n throw new InvalidArgumentError({\n property: \"chainId\",\n value: chainId,\n expected: `config.chainId: ${config.chainId}`,\n });\n }\n\n return { config, chainId: config.chainId };\n}\n","import { type Address, ethAddress, isAddress, zeroAddress } from \"viem\";\n\nimport { mainnet } from \"@berachain/config/mainnet\";\n\nimport { InvalidArgumentError } from \"../errors/InvalidArgumentError\";\nimport type { TokenWithMetadata } from \"../types/dex\";\nimport { parseBaseArgs } from \"./parseBaseArgs\";\n\nexport const beraToken = {\n address: zeroAddress,\n decimals: 18,\n name: \"Bera\",\n symbol: \"BERA\",\n logoURI:\n \"https://imagedelivery.net/qNj7Q3MCke89zoKzav7eDQ/tokens/0x0000000000000000000000000000000000000000.png/public\",\n} as const satisfies Omit<TokenWithMetadata, \"chainId\">;\n\nexport const wBeraToken = {\n address: mainnet.tokens.wbera,\n decimals: 18,\n name: \"WBera\",\n symbol: \"WBERA\",\n} as const satisfies Omit<TokenWithMetadata, \"chainId\">;\n\nexport function getHoneyToken(baseArgs: BeraJS.BaseFunctionArgs) {\n const { config, chainId } = parseBaseArgs(baseArgs);\n\n return {\n address: config.honey.token,\n symbol: \"HONEY\",\n name: \"Honey\",\n decimals: 18,\n chainId,\n } as const satisfies TokenWithMetadata;\n}\n\ntype KnownTokens = \"BERA\" | \"WBERA\" | \"BGT\" | \"HONEY\" | \"SWBERA\" | \"ETH\";\n\ntype BaseToken =\n | {\n address: Address | string;\n }\n | Address;\n\ntype InputToken = BaseToken | string | undefined;\n\ntype IsTokenParams =\n | [\n token: InputToken,\n compareTo:\n | BaseToken\n | Extract<KnownTokens, \"BERA\" | \"WBERA\" | \"ETH\" | \"SWBERA\">,\n ]\n | [\n token: InputToken,\n compareTo: BaseToken | KnownTokens,\n baseArgs: BeraJS.BaseFunctionArgs,\n ];\n\nexport function isToken(...args: IsTokenParams): boolean {\n const [token, compareTo, baseArgs] = args;\n\n if (token === undefined) return false;\n\n const tokenAddress = typeof token === \"string\" ? token : token.address;\n\n if (\n typeof compareTo === \"string\" &&\n !isAddress(compareTo) &&\n // this is a safeguard against weird inputs from enso. `0x00`\n !compareTo.startsWith(\"0x\")\n ) {\n if (compareTo === \"BERA\") {\n return tokenAddress.toLowerCase() === zeroAddress;\n }\n if (compareTo === \"WBERA\") {\n // we are sure that wbera token is the same on all chains because it's checked on the config and forced as types\n return tokenAddress.toLowerCase() === mainnet.tokens.wbera;\n }\n\n if (compareTo === \"ETH\") {\n return tokenAddress.toLowerCase() === ethAddress;\n }\n\n if (compareTo === \"SWBERA\") {\n // we are sure that wbera token is the same on all chains because it's checked on the config and forced as types\n return tokenAddress.toLowerCase() === mainnet.tokens.swbera.toLowerCase();\n }\n\n if (baseArgs === undefined) {\n throw new InvalidArgumentError({\n property: \"baseArgs\",\n value: baseArgs,\n expected: \"BeraJS.BaseFunctionArgs\",\n message:\n \"baseArgs is required when compared to a known token different than BERA or WBERA. Checking against token: \" +\n compareTo +\n \" and token address: \" +\n tokenAddress,\n });\n }\n const { config } = parseBaseArgs(baseArgs);\n\n const tokenMap: Record<Exclude<KnownTokens, \"BERA\" | \"WBERA\">, Address> = {\n BGT: config.tokens.bgt,\n HONEY: config.honey.token,\n SWBERA: config.tokens.swbera,\n ETH: ethAddress as Address,\n } as const;\n if (compareTo in tokenMap) {\n return (\n tokenAddress.toLowerCase() ===\n tokenMap[compareTo as keyof typeof tokenMap].toLowerCase()\n );\n }\n }\n\n const compareToAddress =\n typeof compareTo === \"object\" ? compareTo.address : compareTo;\n\n return tokenAddress.toLowerCase() === compareToAddress.toLowerCase();\n}\n"],"mappings":";;;;;AAAA;AAAA,EAEE;AAAA,EACA;AAAA,OACK;AAIA,SAAS,cAAc,MAA+B;AAC3D,QAAM,UAAU,KAAK,WAAW;AAChC,QAAM,SAAqB,KAAK,UAAU,aAAa,OAAO;AAE9D,MAAI,KAAK,WAAW,KAAK,YAAY,OAAO,SAAS;AAEnD,UAAM,IAAI,qBAAqB;AAAA,MAC7B,UAAU;AAAA,MACV,OAAO;AAAA,MACP,UAAU,mBAAmB,OAAO,OAAO;AAAA,IAC7C,CAAC;AAAA,EACH;AAEA,SAAO,EAAE,QAAQ,SAAS,OAAO,QAAQ;AAC3C;;;ACtBA,SAAuB,YAAY,WAAW,mBAAmB;AAEjE,SAAS,eAAe;AAMjB,IAAM,YAAY;AAAA,EACvB,SAAS;AAAA,EACT,UAAU;AAAA,EACV,MAAM;AAAA,EACN,QAAQ;AAAA,EACR,SACE;AACJ;AAEO,IAAM,aAAa;AAAA,EACxB,SAAS,QAAQ,OAAO;AAAA,EACxB,UAAU;AAAA,EACV,MAAM;AAAA,EACN,QAAQ;AACV;AAEO,SAAS,cAAc,UAAmC;AAC/D,QAAM,EAAE,QAAQ,QAAQ,IAAI,cAAc,QAAQ;AAElD,SAAO;AAAA,IACL,SAAS,OAAO,MAAM;AAAA,IACtB,QAAQ;AAAA,IACR,MAAM;AAAA,IACN,UAAU;AAAA,IACV;AAAA,EACF;AACF;AAyBO,SAAS,WAAW,MAA8B;AACvD,QAAM,CAAC,OAAO,WAAW,QAAQ,IAAI;AAErC,MAAI,UAAU,OAAW,QAAO;AAEhC,QAAM,eAAe,OAAO,UAAU,WAAW,QAAQ,MAAM;AAE/D,MACE,OAAO,cAAc,YACrB,CAAC,UAAU,SAAS;AAAA,EAEpB,CAAC,UAAU,WAAW,IAAI,GAC1B;AACA,QAAI,cAAc,QAAQ;AACxB,aAAO,aAAa,YAAY,MAAM;AAAA,IACxC;AACA,QAAI,cAAc,SAAS;AAEzB,aAAO,aAAa,YAAY,MAAM,QAAQ,OAAO;AAAA,IACvD;AAEA,QAAI,cAAc,OAAO;AACvB,aAAO,aAAa,YAAY,MAAM;AAAA,IACxC;AAEA,QAAI,cAAc,UAAU;AAE1B,aAAO,aAAa,YAAY,MAAM,QAAQ,OAAO,OAAO,YAAY;AAAA,IAC1E;AAEA,QAAI,aAAa,QAAW;AAC1B,YAAM,IAAI,qBAAqB;AAAA,QAC7B,UAAU;AAAA,QACV,OAAO;AAAA,QACP,UAAU;AAAA,QACV,SACE,+GACA,YACA,yBACA;AAAA,MACJ,CAAC;AAAA,IACH;AACA,UAAM,EAAE,OAAO,IAAI,cAAc,QAAQ;AAEzC,UAAM,WAAoE;AAAA,MACxE,KAAK,OAAO,OAAO;AAAA,MACnB,OAAO,OAAO,MAAM;AAAA,MACpB,QAAQ,OAAO,OAAO;AAAA,MACtB,KAAK;AAAA,IACP;AACA,QAAI,aAAa,UAAU;AACzB,aACE,aAAa,YAAY,MACzB,SAAS,SAAkC,EAAE,YAAY;AAAA,IAE7D;AAAA,EACF;AAEA,QAAM,mBACJ,OAAO,cAAc,WAAW,UAAU,UAAU;AAEtD,SAAO,aAAa,YAAY,MAAM,iBAAiB,YAAY;AACrE;","names":[]}
|
|
@@ -0,0 +1,130 @@
|
|
|
1
|
+
"use strict";Object.defineProperty(exports, "__esModule", {value: true}); function _nullishCoalesce(lhs, rhsFn) { if (lhs != null) { return lhs; } else { return rhsFn(); } } var _class;
|
|
2
|
+
|
|
3
|
+
var _chunkXSGCRLSDcjs = require('./chunk-XSGCRLSD.cjs');
|
|
4
|
+
|
|
5
|
+
// src/errors/BeraTracing.ts
|
|
6
|
+
var _handlers = [];
|
|
7
|
+
var BeraTracing = {
|
|
8
|
+
/**
|
|
9
|
+
* Execute a callback, wrapping it in all registered span handlers.
|
|
10
|
+
*
|
|
11
|
+
* Handlers chain so each wraps the next. First registered = outermost wrapper.
|
|
12
|
+
* If no handlers are registered, the callback is executed directly.
|
|
13
|
+
*/
|
|
14
|
+
startSpan(context, callback) {
|
|
15
|
+
if (_handlers.length === 0) return callback();
|
|
16
|
+
return _handlers.reduceRight(
|
|
17
|
+
(next, handler) => () => handler(context, next),
|
|
18
|
+
callback
|
|
19
|
+
)();
|
|
20
|
+
},
|
|
21
|
+
/**
|
|
22
|
+
* Register a span tracing handler.
|
|
23
|
+
*
|
|
24
|
+
* @param _event - Must be "span". Exists for API consistency with BeraMonitoring.
|
|
25
|
+
* @param handler - A StartSpanFn, e.g. Sentry.startSpan.
|
|
26
|
+
* @returns An unsubscribe function to remove the handler.
|
|
27
|
+
*/
|
|
28
|
+
addSpanHandler(handler) {
|
|
29
|
+
_handlers.push(handler);
|
|
30
|
+
return () => {
|
|
31
|
+
const idx = _handlers.indexOf(handler);
|
|
32
|
+
if (idx !== -1) _handlers.splice(idx, 1);
|
|
33
|
+
};
|
|
34
|
+
}
|
|
35
|
+
};
|
|
36
|
+
|
|
37
|
+
// src/errors/NotFoundError.ts
|
|
38
|
+
var NotFoundError = class extends _chunkXSGCRLSDcjs.BeraError {
|
|
39
|
+
/**
|
|
40
|
+
* The name of the resource that was not found.
|
|
41
|
+
*
|
|
42
|
+
* @example "Reward vault"
|
|
43
|
+
*/
|
|
44
|
+
|
|
45
|
+
/**
|
|
46
|
+
* The id of the resource that was not found.
|
|
47
|
+
*
|
|
48
|
+
* @example "0x1234567890123456789012345678901234567890"
|
|
49
|
+
*/
|
|
50
|
+
|
|
51
|
+
constructor(args) {
|
|
52
|
+
super(args);
|
|
53
|
+
this.name = "NotFoundError";
|
|
54
|
+
this.level = _nullishCoalesce(args.level, () => ( "info"));
|
|
55
|
+
this.message = `Resource ${args.resource} with id ${args.id} not found`;
|
|
56
|
+
this.resource = args.resource;
|
|
57
|
+
this.id = args.id;
|
|
58
|
+
}
|
|
59
|
+
};
|
|
60
|
+
|
|
61
|
+
// src/errors/TransactionFailedError.ts
|
|
62
|
+
var TransactionFailedError = (_class = class extends _chunkXSGCRLSDcjs.BeraError {
|
|
63
|
+
/**
|
|
64
|
+
* The hash of the transaction that failed.
|
|
65
|
+
*
|
|
66
|
+
* Null if the error is due to a simulation failure.
|
|
67
|
+
*/
|
|
68
|
+
|
|
69
|
+
/**
|
|
70
|
+
* The receipt of the transaction that failed.
|
|
71
|
+
*
|
|
72
|
+
* Null if the error is due to a simulation failure.
|
|
73
|
+
*/
|
|
74
|
+
|
|
75
|
+
/**
|
|
76
|
+
* The address of the contract that was called.
|
|
77
|
+
*/
|
|
78
|
+
|
|
79
|
+
/**
|
|
80
|
+
* The data of the transaction that failed.
|
|
81
|
+
*/
|
|
82
|
+
|
|
83
|
+
/**
|
|
84
|
+
* The block number of the transaction that failed.
|
|
85
|
+
*/
|
|
86
|
+
__init() {this.blockNumber = null}
|
|
87
|
+
/**
|
|
88
|
+
* The input of the transaction that failed.
|
|
89
|
+
*/
|
|
90
|
+
|
|
91
|
+
/**
|
|
92
|
+
* The function name of the transaction that failed.
|
|
93
|
+
*/
|
|
94
|
+
|
|
95
|
+
constructor(args) {
|
|
96
|
+
super(args);_class.prototype.__init.call(this);;
|
|
97
|
+
this.name = "TransactionFailedError";
|
|
98
|
+
this.txHash = args.txHash || null;
|
|
99
|
+
this.receipt = args.receipt || null;
|
|
100
|
+
this.to = args.to;
|
|
101
|
+
this.functionName = args.functionName;
|
|
102
|
+
this.blockNumber = _nullishCoalesce(args.blockNumber, () => ( null));
|
|
103
|
+
this.input = args.input;
|
|
104
|
+
if (this.receipt) {
|
|
105
|
+
this.message = `Transaction reverted on chain for reason: ${this.reason}`;
|
|
106
|
+
} else if (this.txHash) {
|
|
107
|
+
this.message = `Transaction reverted after being broadcasted for reason: ${this.reason}`;
|
|
108
|
+
} else {
|
|
109
|
+
this.message = `${this.reason}: ${this.message}`;
|
|
110
|
+
}
|
|
111
|
+
this.tags = {
|
|
112
|
+
...this.tags,
|
|
113
|
+
"operation.txn.status": args.txHash ? "execution" : "simulation",
|
|
114
|
+
...args.tags
|
|
115
|
+
};
|
|
116
|
+
if (this.to) {
|
|
117
|
+
this.tags["operation.txn.to"] = this.to;
|
|
118
|
+
}
|
|
119
|
+
if (this.functionName) {
|
|
120
|
+
this.tags["operation.txn.functionName"] = this.functionName;
|
|
121
|
+
}
|
|
122
|
+
}
|
|
123
|
+
}, _class);
|
|
124
|
+
|
|
125
|
+
|
|
126
|
+
|
|
127
|
+
|
|
128
|
+
|
|
129
|
+
exports.BeraTracing = BeraTracing; exports.NotFoundError = NotFoundError; exports.TransactionFailedError = TransactionFailedError;
|
|
130
|
+
//# sourceMappingURL=chunk-5N7QQS55.cjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["/Users/pong/coding/monobera/packages/berajs/dist/chunk-5N7QQS55.cjs","../src/errors/BeraTracing.ts","../src/errors/NotFoundError.ts","../src/errors/TransactionFailedError.ts"],"names":[],"mappings":"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","file":"/Users/pong/coding/monobera/packages/berajs/dist/chunk-5N7QQS55.cjs","sourcesContent":[null,"import type { Unsubscribe } from \"../utils/createEmitter\";\n\n/**\n * Span context passed to tracing handlers.\n * Compatible with Sentry's StartSpanOptions (name, op, attributes).\n */\nexport type SpanContext = {\n name: string;\n op: string;\n attributes: Record<string, string | number | boolean | undefined>;\n};\n\n/**\n * A function that wraps a callback in a tracing span.\n * Compatible with Sentry.startSpan's signature.\n */\ntype StartSpanFn = <T>(\n context: SpanContext,\n callback: () => Promise<T>,\n) => Promise<T>;\n\nconst _handlers: StartSpanFn[] = [];\n\n/**\n * A generic span-tracing module for berajs.\n *\n * Instead of calling Sentry.startSpan directly, berajs calls\n * `BeraTracing.startSpan()`. Consumer apps subscribe via `.on(\"span\", handler)`\n * and forward spans to their tracing provider (Sentry, Datadog, etc.).\n *\n * Multiple handlers are supported and chain in registration order:\n * the first registered handler is the outermost wrapper.\n *\n * @example\n * ```ts\n * // In berajs code:\n * import { BeraTracing } from \"./BeraTracing\";\n * const result = await BeraTracing.startSpan(\n * { name: \"GraphQL query\", op: \"graphql.query\", attributes: {} },\n * () => executeQuery(),\n * );\n *\n * // In app instrumentation:\n * import { BeraTracing } from \"@berachain/berajs/errors\";\n * BeraTracing.addSpanHandler(Sentry.startSpan);\n * ```\n */\nexport const BeraTracing = {\n /**\n * Execute a callback, wrapping it in all registered span handlers.\n *\n * Handlers chain so each wraps the next. First registered = outermost wrapper.\n * If no handlers are registered, the callback is executed directly.\n */\n startSpan<T>(context: SpanContext, callback: () => Promise<T>): Promise<T> {\n if (_handlers.length === 0) return callback();\n\n // Chain: h1(ctx, () => h2(ctx, () => h3(ctx, () => callback())))\n return _handlers.reduceRight<() => Promise<T>>(\n (next, handler) => () => handler(context, next),\n callback,\n )();\n },\n\n /**\n * Register a span tracing handler.\n *\n * @param _event - Must be \"span\". Exists for API consistency with BeraMonitoring.\n * @param handler - A StartSpanFn, e.g. Sentry.startSpan.\n * @returns An unsubscribe function to remove the handler.\n */\n addSpanHandler(handler: StartSpanFn): Unsubscribe {\n _handlers.push(handler);\n return () => {\n const idx = _handlers.indexOf(handler);\n if (idx !== -1) _handlers.splice(idx, 1);\n };\n },\n};\n","import { BeraError, type IBeraErrorArgs } from \"./BeraError\";\n\nexport interface INotFoundErrorArgs extends IBeraErrorArgs {\n resource: string;\n id: string;\n chainId: number;\n}\n\n/**\n * Error thrown when a resource is not found.\n */\nexport class NotFoundError extends BeraError {\n /**\n * The name of the resource that was not found.\n *\n * @example \"Reward vault\"\n */\n resource: string;\n /**\n * The id of the resource that was not found.\n *\n * @example \"0x1234567890123456789012345678901234567890\"\n */\n id: string;\n\n constructor(args: INotFoundErrorArgs) {\n super(args);\n this.name = \"NotFoundError\";\n this.level = args.level ?? \"info\";\n this.message = `Resource ${args.resource} with id ${args.id} not found`;\n this.resource = args.resource;\n this.id = args.id;\n }\n}\n","import type { Hex } from \"@berachain-foundation/berancer-sdk\";\nimport type { Address, TransactionReceipt } from \"viem\";\n\nimport { BeraError, type IBeraErrorArgs } from \"./BeraError\";\n\n/**\n * This error is generally thrown by beraWriteContract when a transaction or simulation fails.\n */\nexport class TransactionFailedError extends BeraError {\n /**\n * The hash of the transaction that failed.\n *\n * Null if the error is due to a simulation failure.\n */\n txHash: string | null;\n\n /**\n * The receipt of the transaction that failed.\n *\n * Null if the error is due to a simulation failure.\n */\n receipt: TransactionReceipt | null;\n\n /**\n * The address of the contract that was called.\n */\n to: Address | undefined;\n\n /**\n * The data of the transaction that failed.\n */\n callData: Hex | undefined;\n\n /**\n * The block number of the transaction that failed.\n */\n blockNumber: bigint | null = null;\n\n /**\n * The input of the transaction that failed.\n */\n input: object;\n\n /**\n * The function name of the transaction that failed.\n */\n functionName: string | undefined;\n\n constructor(\n args: IBeraErrorArgs & {\n txHash?: string;\n receipt?: TransactionReceipt;\n to?: Address;\n blockNumber?: bigint;\n functionName?: string;\n input: object;\n },\n ) {\n super(args);\n this.name = \"TransactionFailedError\";\n this.txHash = args.txHash || null;\n this.receipt = args.receipt || null;\n this.to = args.to;\n this.functionName = args.functionName;\n this.blockNumber = args.blockNumber ?? null;\n this.input = args.input;\n\n if (this.receipt) {\n // If we have a receipt, transaction reverted on chain\n this.message = `Transaction reverted on chain for reason: ${this.reason}`;\n } else if (this.txHash) {\n // If we have a tx hash, transaction reverted after being broadcasted but we never got a receipt\n // Might happen for network reasons\n this.message = `Transaction reverted after being broadcasted for reason: ${this.reason}`;\n } else {\n this.message = `${this.reason}: ${this.message}`;\n }\n\n this.tags = {\n ...this.tags,\n \"operation.txn.status\": args.txHash ? \"execution\" : \"simulation\",\n ...args.tags,\n };\n\n if (this.to) {\n this.tags[\"operation.txn.to\"] = this.to;\n }\n\n if (this.functionName) {\n this.tags[\"operation.txn.functionName\"] = this.functionName;\n }\n }\n}\n"]}
|
|
@@ -0,0 +1,130 @@
|
|
|
1
|
+
import {
|
|
2
|
+
BeraError
|
|
3
|
+
} from "./chunk-7QKRRIHI.mjs";
|
|
4
|
+
|
|
5
|
+
// src/errors/BeraTracing.ts
|
|
6
|
+
var _handlers = [];
|
|
7
|
+
var BeraTracing = {
|
|
8
|
+
/**
|
|
9
|
+
* Execute a callback, wrapping it in all registered span handlers.
|
|
10
|
+
*
|
|
11
|
+
* Handlers chain so each wraps the next. First registered = outermost wrapper.
|
|
12
|
+
* If no handlers are registered, the callback is executed directly.
|
|
13
|
+
*/
|
|
14
|
+
startSpan(context, callback) {
|
|
15
|
+
if (_handlers.length === 0) return callback();
|
|
16
|
+
return _handlers.reduceRight(
|
|
17
|
+
(next, handler) => () => handler(context, next),
|
|
18
|
+
callback
|
|
19
|
+
)();
|
|
20
|
+
},
|
|
21
|
+
/**
|
|
22
|
+
* Register a span tracing handler.
|
|
23
|
+
*
|
|
24
|
+
* @param _event - Must be "span". Exists for API consistency with BeraMonitoring.
|
|
25
|
+
* @param handler - A StartSpanFn, e.g. Sentry.startSpan.
|
|
26
|
+
* @returns An unsubscribe function to remove the handler.
|
|
27
|
+
*/
|
|
28
|
+
addSpanHandler(handler) {
|
|
29
|
+
_handlers.push(handler);
|
|
30
|
+
return () => {
|
|
31
|
+
const idx = _handlers.indexOf(handler);
|
|
32
|
+
if (idx !== -1) _handlers.splice(idx, 1);
|
|
33
|
+
};
|
|
34
|
+
}
|
|
35
|
+
};
|
|
36
|
+
|
|
37
|
+
// src/errors/NotFoundError.ts
|
|
38
|
+
var NotFoundError = class extends BeraError {
|
|
39
|
+
/**
|
|
40
|
+
* The name of the resource that was not found.
|
|
41
|
+
*
|
|
42
|
+
* @example "Reward vault"
|
|
43
|
+
*/
|
|
44
|
+
resource;
|
|
45
|
+
/**
|
|
46
|
+
* The id of the resource that was not found.
|
|
47
|
+
*
|
|
48
|
+
* @example "0x1234567890123456789012345678901234567890"
|
|
49
|
+
*/
|
|
50
|
+
id;
|
|
51
|
+
constructor(args) {
|
|
52
|
+
super(args);
|
|
53
|
+
this.name = "NotFoundError";
|
|
54
|
+
this.level = args.level ?? "info";
|
|
55
|
+
this.message = `Resource ${args.resource} with id ${args.id} not found`;
|
|
56
|
+
this.resource = args.resource;
|
|
57
|
+
this.id = args.id;
|
|
58
|
+
}
|
|
59
|
+
};
|
|
60
|
+
|
|
61
|
+
// src/errors/TransactionFailedError.ts
|
|
62
|
+
var TransactionFailedError = class extends BeraError {
|
|
63
|
+
/**
|
|
64
|
+
* The hash of the transaction that failed.
|
|
65
|
+
*
|
|
66
|
+
* Null if the error is due to a simulation failure.
|
|
67
|
+
*/
|
|
68
|
+
txHash;
|
|
69
|
+
/**
|
|
70
|
+
* The receipt of the transaction that failed.
|
|
71
|
+
*
|
|
72
|
+
* Null if the error is due to a simulation failure.
|
|
73
|
+
*/
|
|
74
|
+
receipt;
|
|
75
|
+
/**
|
|
76
|
+
* The address of the contract that was called.
|
|
77
|
+
*/
|
|
78
|
+
to;
|
|
79
|
+
/**
|
|
80
|
+
* The data of the transaction that failed.
|
|
81
|
+
*/
|
|
82
|
+
callData;
|
|
83
|
+
/**
|
|
84
|
+
* The block number of the transaction that failed.
|
|
85
|
+
*/
|
|
86
|
+
blockNumber = null;
|
|
87
|
+
/**
|
|
88
|
+
* The input of the transaction that failed.
|
|
89
|
+
*/
|
|
90
|
+
input;
|
|
91
|
+
/**
|
|
92
|
+
* The function name of the transaction that failed.
|
|
93
|
+
*/
|
|
94
|
+
functionName;
|
|
95
|
+
constructor(args) {
|
|
96
|
+
super(args);
|
|
97
|
+
this.name = "TransactionFailedError";
|
|
98
|
+
this.txHash = args.txHash || null;
|
|
99
|
+
this.receipt = args.receipt || null;
|
|
100
|
+
this.to = args.to;
|
|
101
|
+
this.functionName = args.functionName;
|
|
102
|
+
this.blockNumber = args.blockNumber ?? null;
|
|
103
|
+
this.input = args.input;
|
|
104
|
+
if (this.receipt) {
|
|
105
|
+
this.message = `Transaction reverted on chain for reason: ${this.reason}`;
|
|
106
|
+
} else if (this.txHash) {
|
|
107
|
+
this.message = `Transaction reverted after being broadcasted for reason: ${this.reason}`;
|
|
108
|
+
} else {
|
|
109
|
+
this.message = `${this.reason}: ${this.message}`;
|
|
110
|
+
}
|
|
111
|
+
this.tags = {
|
|
112
|
+
...this.tags,
|
|
113
|
+
"operation.txn.status": args.txHash ? "execution" : "simulation",
|
|
114
|
+
...args.tags
|
|
115
|
+
};
|
|
116
|
+
if (this.to) {
|
|
117
|
+
this.tags["operation.txn.to"] = this.to;
|
|
118
|
+
}
|
|
119
|
+
if (this.functionName) {
|
|
120
|
+
this.tags["operation.txn.functionName"] = this.functionName;
|
|
121
|
+
}
|
|
122
|
+
}
|
|
123
|
+
};
|
|
124
|
+
|
|
125
|
+
export {
|
|
126
|
+
BeraTracing,
|
|
127
|
+
NotFoundError,
|
|
128
|
+
TransactionFailedError
|
|
129
|
+
};
|
|
130
|
+
//# sourceMappingURL=chunk-5NMATIH4.mjs.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/errors/BeraTracing.ts","../src/errors/NotFoundError.ts","../src/errors/TransactionFailedError.ts"],"sourcesContent":["import type { Unsubscribe } from \"../utils/createEmitter\";\n\n/**\n * Span context passed to tracing handlers.\n * Compatible with Sentry's StartSpanOptions (name, op, attributes).\n */\nexport type SpanContext = {\n name: string;\n op: string;\n attributes: Record<string, string | number | boolean | undefined>;\n};\n\n/**\n * A function that wraps a callback in a tracing span.\n * Compatible with Sentry.startSpan's signature.\n */\ntype StartSpanFn = <T>(\n context: SpanContext,\n callback: () => Promise<T>,\n) => Promise<T>;\n\nconst _handlers: StartSpanFn[] = [];\n\n/**\n * A generic span-tracing module for berajs.\n *\n * Instead of calling Sentry.startSpan directly, berajs calls\n * `BeraTracing.startSpan()`. Consumer apps subscribe via `.on(\"span\", handler)`\n * and forward spans to their tracing provider (Sentry, Datadog, etc.).\n *\n * Multiple handlers are supported and chain in registration order:\n * the first registered handler is the outermost wrapper.\n *\n * @example\n * ```ts\n * // In berajs code:\n * import { BeraTracing } from \"./BeraTracing\";\n * const result = await BeraTracing.startSpan(\n * { name: \"GraphQL query\", op: \"graphql.query\", attributes: {} },\n * () => executeQuery(),\n * );\n *\n * // In app instrumentation:\n * import { BeraTracing } from \"@berachain/berajs/errors\";\n * BeraTracing.addSpanHandler(Sentry.startSpan);\n * ```\n */\nexport const BeraTracing = {\n /**\n * Execute a callback, wrapping it in all registered span handlers.\n *\n * Handlers chain so each wraps the next. First registered = outermost wrapper.\n * If no handlers are registered, the callback is executed directly.\n */\n startSpan<T>(context: SpanContext, callback: () => Promise<T>): Promise<T> {\n if (_handlers.length === 0) return callback();\n\n // Chain: h1(ctx, () => h2(ctx, () => h3(ctx, () => callback())))\n return _handlers.reduceRight<() => Promise<T>>(\n (next, handler) => () => handler(context, next),\n callback,\n )();\n },\n\n /**\n * Register a span tracing handler.\n *\n * @param _event - Must be \"span\". Exists for API consistency with BeraMonitoring.\n * @param handler - A StartSpanFn, e.g. Sentry.startSpan.\n * @returns An unsubscribe function to remove the handler.\n */\n addSpanHandler(handler: StartSpanFn): Unsubscribe {\n _handlers.push(handler);\n return () => {\n const idx = _handlers.indexOf(handler);\n if (idx !== -1) _handlers.splice(idx, 1);\n };\n },\n};\n","import { BeraError, type IBeraErrorArgs } from \"./BeraError\";\n\nexport interface INotFoundErrorArgs extends IBeraErrorArgs {\n resource: string;\n id: string;\n chainId: number;\n}\n\n/**\n * Error thrown when a resource is not found.\n */\nexport class NotFoundError extends BeraError {\n /**\n * The name of the resource that was not found.\n *\n * @example \"Reward vault\"\n */\n resource: string;\n /**\n * The id of the resource that was not found.\n *\n * @example \"0x1234567890123456789012345678901234567890\"\n */\n id: string;\n\n constructor(args: INotFoundErrorArgs) {\n super(args);\n this.name = \"NotFoundError\";\n this.level = args.level ?? \"info\";\n this.message = `Resource ${args.resource} with id ${args.id} not found`;\n this.resource = args.resource;\n this.id = args.id;\n }\n}\n","import type { Hex } from \"@berachain-foundation/berancer-sdk\";\nimport type { Address, TransactionReceipt } from \"viem\";\n\nimport { BeraError, type IBeraErrorArgs } from \"./BeraError\";\n\n/**\n * This error is generally thrown by beraWriteContract when a transaction or simulation fails.\n */\nexport class TransactionFailedError extends BeraError {\n /**\n * The hash of the transaction that failed.\n *\n * Null if the error is due to a simulation failure.\n */\n txHash: string | null;\n\n /**\n * The receipt of the transaction that failed.\n *\n * Null if the error is due to a simulation failure.\n */\n receipt: TransactionReceipt | null;\n\n /**\n * The address of the contract that was called.\n */\n to: Address | undefined;\n\n /**\n * The data of the transaction that failed.\n */\n callData: Hex | undefined;\n\n /**\n * The block number of the transaction that failed.\n */\n blockNumber: bigint | null = null;\n\n /**\n * The input of the transaction that failed.\n */\n input: object;\n\n /**\n * The function name of the transaction that failed.\n */\n functionName: string | undefined;\n\n constructor(\n args: IBeraErrorArgs & {\n txHash?: string;\n receipt?: TransactionReceipt;\n to?: Address;\n blockNumber?: bigint;\n functionName?: string;\n input: object;\n },\n ) {\n super(args);\n this.name = \"TransactionFailedError\";\n this.txHash = args.txHash || null;\n this.receipt = args.receipt || null;\n this.to = args.to;\n this.functionName = args.functionName;\n this.blockNumber = args.blockNumber ?? null;\n this.input = args.input;\n\n if (this.receipt) {\n // If we have a receipt, transaction reverted on chain\n this.message = `Transaction reverted on chain for reason: ${this.reason}`;\n } else if (this.txHash) {\n // If we have a tx hash, transaction reverted after being broadcasted but we never got a receipt\n // Might happen for network reasons\n this.message = `Transaction reverted after being broadcasted for reason: ${this.reason}`;\n } else {\n this.message = `${this.reason}: ${this.message}`;\n }\n\n this.tags = {\n ...this.tags,\n \"operation.txn.status\": args.txHash ? \"execution\" : \"simulation\",\n ...args.tags,\n };\n\n if (this.to) {\n this.tags[\"operation.txn.to\"] = this.to;\n }\n\n if (this.functionName) {\n this.tags[\"operation.txn.functionName\"] = this.functionName;\n }\n }\n}\n"],"mappings":"
|
|
1
|
+
{"version":3,"sources":["../src/errors/BeraTracing.ts","../src/errors/NotFoundError.ts","../src/errors/TransactionFailedError.ts"],"sourcesContent":["import type { Unsubscribe } from \"../utils/createEmitter\";\n\n/**\n * Span context passed to tracing handlers.\n * Compatible with Sentry's StartSpanOptions (name, op, attributes).\n */\nexport type SpanContext = {\n name: string;\n op: string;\n attributes: Record<string, string | number | boolean | undefined>;\n};\n\n/**\n * A function that wraps a callback in a tracing span.\n * Compatible with Sentry.startSpan's signature.\n */\ntype StartSpanFn = <T>(\n context: SpanContext,\n callback: () => Promise<T>,\n) => Promise<T>;\n\nconst _handlers: StartSpanFn[] = [];\n\n/**\n * A generic span-tracing module for berajs.\n *\n * Instead of calling Sentry.startSpan directly, berajs calls\n * `BeraTracing.startSpan()`. Consumer apps subscribe via `.on(\"span\", handler)`\n * and forward spans to their tracing provider (Sentry, Datadog, etc.).\n *\n * Multiple handlers are supported and chain in registration order:\n * the first registered handler is the outermost wrapper.\n *\n * @example\n * ```ts\n * // In berajs code:\n * import { BeraTracing } from \"./BeraTracing\";\n * const result = await BeraTracing.startSpan(\n * { name: \"GraphQL query\", op: \"graphql.query\", attributes: {} },\n * () => executeQuery(),\n * );\n *\n * // In app instrumentation:\n * import { BeraTracing } from \"@berachain/berajs/errors\";\n * BeraTracing.addSpanHandler(Sentry.startSpan);\n * ```\n */\nexport const BeraTracing = {\n /**\n * Execute a callback, wrapping it in all registered span handlers.\n *\n * Handlers chain so each wraps the next. First registered = outermost wrapper.\n * If no handlers are registered, the callback is executed directly.\n */\n startSpan<T>(context: SpanContext, callback: () => Promise<T>): Promise<T> {\n if (_handlers.length === 0) return callback();\n\n // Chain: h1(ctx, () => h2(ctx, () => h3(ctx, () => callback())))\n return _handlers.reduceRight<() => Promise<T>>(\n (next, handler) => () => handler(context, next),\n callback,\n )();\n },\n\n /**\n * Register a span tracing handler.\n *\n * @param _event - Must be \"span\". Exists for API consistency with BeraMonitoring.\n * @param handler - A StartSpanFn, e.g. Sentry.startSpan.\n * @returns An unsubscribe function to remove the handler.\n */\n addSpanHandler(handler: StartSpanFn): Unsubscribe {\n _handlers.push(handler);\n return () => {\n const idx = _handlers.indexOf(handler);\n if (idx !== -1) _handlers.splice(idx, 1);\n };\n },\n};\n","import { BeraError, type IBeraErrorArgs } from \"./BeraError\";\n\nexport interface INotFoundErrorArgs extends IBeraErrorArgs {\n resource: string;\n id: string;\n chainId: number;\n}\n\n/**\n * Error thrown when a resource is not found.\n */\nexport class NotFoundError extends BeraError {\n /**\n * The name of the resource that was not found.\n *\n * @example \"Reward vault\"\n */\n resource: string;\n /**\n * The id of the resource that was not found.\n *\n * @example \"0x1234567890123456789012345678901234567890\"\n */\n id: string;\n\n constructor(args: INotFoundErrorArgs) {\n super(args);\n this.name = \"NotFoundError\";\n this.level = args.level ?? \"info\";\n this.message = `Resource ${args.resource} with id ${args.id} not found`;\n this.resource = args.resource;\n this.id = args.id;\n }\n}\n","import type { Hex } from \"@berachain-foundation/berancer-sdk\";\nimport type { Address, TransactionReceipt } from \"viem\";\n\nimport { BeraError, type IBeraErrorArgs } from \"./BeraError\";\n\n/**\n * This error is generally thrown by beraWriteContract when a transaction or simulation fails.\n */\nexport class TransactionFailedError extends BeraError {\n /**\n * The hash of the transaction that failed.\n *\n * Null if the error is due to a simulation failure.\n */\n txHash: string | null;\n\n /**\n * The receipt of the transaction that failed.\n *\n * Null if the error is due to a simulation failure.\n */\n receipt: TransactionReceipt | null;\n\n /**\n * The address of the contract that was called.\n */\n to: Address | undefined;\n\n /**\n * The data of the transaction that failed.\n */\n callData: Hex | undefined;\n\n /**\n * The block number of the transaction that failed.\n */\n blockNumber: bigint | null = null;\n\n /**\n * The input of the transaction that failed.\n */\n input: object;\n\n /**\n * The function name of the transaction that failed.\n */\n functionName: string | undefined;\n\n constructor(\n args: IBeraErrorArgs & {\n txHash?: string;\n receipt?: TransactionReceipt;\n to?: Address;\n blockNumber?: bigint;\n functionName?: string;\n input: object;\n },\n ) {\n super(args);\n this.name = \"TransactionFailedError\";\n this.txHash = args.txHash || null;\n this.receipt = args.receipt || null;\n this.to = args.to;\n this.functionName = args.functionName;\n this.blockNumber = args.blockNumber ?? null;\n this.input = args.input;\n\n if (this.receipt) {\n // If we have a receipt, transaction reverted on chain\n this.message = `Transaction reverted on chain for reason: ${this.reason}`;\n } else if (this.txHash) {\n // If we have a tx hash, transaction reverted after being broadcasted but we never got a receipt\n // Might happen for network reasons\n this.message = `Transaction reverted after being broadcasted for reason: ${this.reason}`;\n } else {\n this.message = `${this.reason}: ${this.message}`;\n }\n\n this.tags = {\n ...this.tags,\n \"operation.txn.status\": args.txHash ? \"execution\" : \"simulation\",\n ...args.tags,\n };\n\n if (this.to) {\n this.tags[\"operation.txn.to\"] = this.to;\n }\n\n if (this.functionName) {\n this.tags[\"operation.txn.functionName\"] = this.functionName;\n }\n }\n}\n"],"mappings":";;;;;AAqBA,IAAM,YAA2B,CAAC;AA0B3B,IAAM,cAAc;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EAOzB,UAAa,SAAsB,UAAwC;AACzE,QAAI,UAAU,WAAW,EAAG,QAAO,SAAS;AAG5C,WAAO,UAAU;AAAA,MACf,CAAC,MAAM,YAAY,MAAM,QAAQ,SAAS,IAAI;AAAA,MAC9C;AAAA,IACF,EAAE;AAAA,EACJ;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EASA,eAAe,SAAmC;AAChD,cAAU,KAAK,OAAO;AACtB,WAAO,MAAM;AACX,YAAM,MAAM,UAAU,QAAQ,OAAO;AACrC,UAAI,QAAQ,GAAI,WAAU,OAAO,KAAK,CAAC;AAAA,IACzC;AAAA,EACF;AACF;;;ACnEO,IAAM,gBAAN,cAA4B,UAAU;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EAM3C;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EAMA;AAAA,EAEA,YAAY,MAA0B;AACpC,UAAM,IAAI;AACV,SAAK,OAAO;AACZ,SAAK,QAAQ,KAAK,SAAS;AAC3B,SAAK,UAAU,YAAY,KAAK,QAAQ,YAAY,KAAK,EAAE;AAC3D,SAAK,WAAW,KAAK;AACrB,SAAK,KAAK,KAAK;AAAA,EACjB;AACF;;;ACzBO,IAAM,yBAAN,cAAqC,UAAU;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EAMpD;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EAOA;AAAA;AAAA;AAAA;AAAA,EAKA;AAAA;AAAA;AAAA;AAAA,EAKA;AAAA;AAAA;AAAA;AAAA,EAKA,cAA6B;AAAA;AAAA;AAAA;AAAA,EAK7B;AAAA;AAAA;AAAA;AAAA,EAKA;AAAA,EAEA,YACE,MAQA;AACA,UAAM,IAAI;AACV,SAAK,OAAO;AACZ,SAAK,SAAS,KAAK,UAAU;AAC7B,SAAK,UAAU,KAAK,WAAW;AAC/B,SAAK,KAAK,KAAK;AACf,SAAK,eAAe,KAAK;AACzB,SAAK,cAAc,KAAK,eAAe;AACvC,SAAK,QAAQ,KAAK;AAElB,QAAI,KAAK,SAAS;AAEhB,WAAK,UAAU,6CAA6C,KAAK,MAAM;AAAA,IACzE,WAAW,KAAK,QAAQ;AAGtB,WAAK,UAAU,4DAA4D,KAAK,MAAM;AAAA,IACxF,OAAO;AACL,WAAK,UAAU,GAAG,KAAK,MAAM,KAAK,KAAK,OAAO;AAAA,IAChD;AAEA,SAAK,OAAO;AAAA,MACV,GAAG,KAAK;AAAA,MACR,wBAAwB,KAAK,SAAS,cAAc;AAAA,MACpD,GAAG,KAAK;AAAA,IACV;AAEA,QAAI,KAAK,IAAI;AACX,WAAK,KAAK,kBAAkB,IAAI,KAAK;AAAA,IACvC;AAEA,QAAI,KAAK,cAAc;AACrB,WAAK,KAAK,4BAA4B,IAAI,KAAK;AAAA,IACjD;AAAA,EACF;AACF;","names":[]}
|