upshift-finance 1.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +21 -0
- package/README.md +349 -0
- package/lib/abis/AddressResolver.d.ts +28 -0
- package/lib/abis/AddressResolver.js +23 -0
- package/lib/abis/ChainlinkV3.d.ts +87 -0
- package/lib/abis/ChainlinkV3.js +117 -0
- package/lib/abis/ERC20.d.ts +168 -0
- package/lib/abis/ERC20.js +226 -0
- package/lib/abis/ERC20_Bytes32.d.ts +139 -0
- package/lib/abis/ERC20_Bytes32.js +196 -0
- package/lib/abis/ERC4626.d.ts +364 -0
- package/lib/abis/ERC4626.js +507 -0
- package/lib/abis/ERC721.d.ts +231 -0
- package/lib/abis/ERC721.js +321 -0
- package/lib/abis/FeeOracle.d.ts +120 -0
- package/lib/abis/FeeOracle.js +162 -0
- package/lib/abis/LendingPool.d.ts +1393 -0
- package/lib/abis/LendingPool.js +1807 -0
- package/lib/abis/LendingPoolV2.d.ts +1413 -0
- package/lib/abis/LendingPoolV2.js +1833 -0
- package/lib/abis/LendingPoolV3.d.ts +1677 -0
- package/lib/abis/LendingPoolV3.js +1160 -0
- package/lib/abis/Loan.d.ts +837 -0
- package/lib/abis/Loan.js +1080 -0
- package/lib/abis/MultiAssetNativeDepositWrapper.d.ts +137 -0
- package/lib/abis/MultiAssetNativeDepositWrapper.js +125 -0
- package/lib/abis/Multicall3.d.ts +30 -0
- package/lib/abis/Multicall3.js +97 -0
- package/lib/abis/OFT.d.ts +116 -0
- package/lib/abis/OFT.js +85 -0
- package/lib/abis/PoolAdapter.d.ts +36 -0
- package/lib/abis/PoolAdapter.js +51 -0
- package/lib/abis/RewardDistributor.d.ts +267 -0
- package/lib/abis/RewardDistributor.js +352 -0
- package/lib/abis/RwaRedeemSubaccount.d.ts +747 -0
- package/lib/abis/RwaRedeemSubaccount.js +548 -0
- package/lib/abis/SmartAccount.d.ts +17 -0
- package/lib/abis/SmartAccount.js +19 -0
- package/lib/abis/SwapRouter.d.ts +1043 -0
- package/lib/abis/SwapRouter.js +740 -0
- package/lib/abis/TextResolver.d.ts +16 -0
- package/lib/abis/TextResolver.js +16 -0
- package/lib/abis/TokenizedVaultV2.d.ts +1364 -0
- package/lib/abis/TokenizedVaultV2.js +1041 -0
- package/lib/abis/TokenizedVaultV2DepositWithPermit.d.ts +1456 -0
- package/lib/abis/TokenizedVaultV2DepositWithPermit.js +1878 -0
- package/lib/abis/TokenizedVaultV2Receipt.d.ts +1568 -0
- package/lib/abis/TokenizedVaultV2Receipt.js +1061 -0
- package/lib/abis/TokenizedVaultV2SenderAllocationWhitelist.d.ts +454 -0
- package/lib/abis/TokenizedVaultV2SenderAllocationWhitelist.js +327 -0
- package/lib/abis/TokenizedVaultV2WhitelistedAllocation.d.ts +1466 -0
- package/lib/abis/TokenizedVaultV2WhitelistedAllocation.js +1092 -0
- package/lib/abis/TokenizedVaultV2WhitelistedAssets.d.ts +274 -0
- package/lib/abis/TokenizedVaultV2WhitelistedAssets.js +167 -0
- package/lib/abis/UniversalResolverResolve.d.ts +69 -0
- package/lib/abis/UniversalResolverResolve.js +35 -0
- package/lib/abis/UniversalSignatureValidator.d.ts +17 -0
- package/lib/abis/UniversalSignatureValidator.js +30 -0
- package/lib/abis/WrapperAdapter.d.ts +71 -0
- package/lib/abis/WrapperAdapter.js +77 -0
- package/lib/abis/index.d.ts +34 -0
- package/lib/abis/index.js +51 -0
- package/lib/adapters/evm/getters.d.ts +19 -0
- package/lib/adapters/evm/getters.js +209 -0
- package/lib/adapters/evm/index.d.ts +353 -0
- package/lib/adapters/evm/index.js +434 -0
- package/lib/adapters/evm/utils.d.ts +8 -0
- package/lib/adapters/evm/utils.js +51 -0
- package/lib/adapters/solana/constants.d.ts +33 -0
- package/lib/adapters/solana/constants.js +52 -0
- package/lib/adapters/solana/getters.d.ts +11 -0
- package/lib/adapters/solana/getters.js +165 -0
- package/lib/adapters/solana/idl/vault-idl.d.ts +272 -0
- package/lib/adapters/solana/idl/vault-idl.js +1084 -0
- package/lib/adapters/solana/index.d.ts +233 -0
- package/lib/adapters/solana/index.js +291 -0
- package/lib/adapters/solana/types.d.ts +67 -0
- package/lib/adapters/solana/types.js +3 -0
- package/lib/adapters/solana/utils.d.ts +141 -0
- package/lib/adapters/solana/utils.js +595 -0
- package/lib/adapters/solana/vault.actions.d.ts +57 -0
- package/lib/adapters/solana/vault.actions.js +379 -0
- package/lib/adapters/stellar/actions.d.ts +28 -0
- package/lib/adapters/stellar/actions.js +77 -0
- package/lib/adapters/stellar/constants.d.ts +43 -0
- package/lib/adapters/stellar/constants.js +53 -0
- package/lib/adapters/stellar/getters.d.ts +68 -0
- package/lib/adapters/stellar/getters.js +290 -0
- package/lib/adapters/stellar/index.d.ts +114 -0
- package/lib/adapters/stellar/index.js +175 -0
- package/lib/adapters/stellar/soroban.d.ts +123 -0
- package/lib/adapters/stellar/soroban.js +613 -0
- package/lib/adapters/stellar/submit.d.ts +34 -0
- package/lib/adapters/stellar/submit.js +149 -0
- package/lib/adapters/stellar/types.d.ts +58 -0
- package/lib/adapters/stellar/types.js +6 -0
- package/lib/adapters/stellar/utils.d.ts +24 -0
- package/lib/adapters/stellar/utils.js +34 -0
- package/lib/adapters/sui/constants.d.ts +14 -0
- package/lib/adapters/sui/constants.js +29 -0
- package/lib/adapters/sui/getters.d.ts +9 -0
- package/lib/adapters/sui/getters.js +60 -0
- package/lib/adapters/sui/index.d.ts +45 -0
- package/lib/adapters/sui/index.js +101 -0
- package/lib/adapters/sui/transformer.d.ts +10 -0
- package/lib/adapters/sui/transformer.js +107 -0
- package/lib/adapters/sui/types.d.ts +66 -0
- package/lib/adapters/sui/types.js +3 -0
- package/lib/adapters/sui/utils.d.ts +10 -0
- package/lib/adapters/sui/utils.js +29 -0
- package/lib/core/analytics/chain-name.d.ts +9 -0
- package/lib/core/analytics/chain-name.js +34 -0
- package/lib/core/analytics/constants.d.ts +5 -0
- package/lib/core/analytics/constants.js +9 -0
- package/lib/core/analytics/env.d.ts +29 -0
- package/lib/core/analytics/env.js +59 -0
- package/lib/core/analytics/index.d.ts +36 -0
- package/lib/core/analytics/index.js +79 -0
- package/lib/core/analytics/instrumentation.d.ts +29 -0
- package/lib/core/analytics/instrumentation.js +277 -0
- package/lib/core/analytics/method-taxonomy.d.ts +19 -0
- package/lib/core/analytics/method-taxonomy.js +128 -0
- package/lib/core/analytics/metrics.d.ts +33 -0
- package/lib/core/analytics/metrics.js +116 -0
- package/lib/core/analytics/sanitize.d.ts +44 -0
- package/lib/core/analytics/sanitize.js +260 -0
- package/lib/core/analytics/sentry-runtime.d.ts +15 -0
- package/lib/core/analytics/sentry-runtime.js +97 -0
- package/lib/core/analytics/sentry.d.ts +67 -0
- package/lib/core/analytics/sentry.js +613 -0
- package/lib/core/analytics/types.d.ts +48 -0
- package/lib/core/analytics/types.js +3 -0
- package/lib/core/analytics/user-identity.d.ts +41 -0
- package/lib/core/analytics/user-identity.js +141 -0
- package/lib/core/analytics/version.d.ts +6 -0
- package/lib/core/analytics/version.js +10 -0
- package/lib/core/attribution.d.ts +111 -0
- package/lib/core/attribution.js +142 -0
- package/lib/core/auth/index.d.ts +1 -0
- package/lib/core/auth/index.js +18 -0
- package/lib/core/auth/verify.d.ts +2 -0
- package/lib/core/auth/verify.js +31 -0
- package/lib/core/base.class.d.ts +152 -0
- package/lib/core/base.class.js +172 -0
- package/lib/core/cache.d.ts +9 -0
- package/lib/core/cache.js +31 -0
- package/lib/core/constants/adapters.d.ts +103 -0
- package/lib/core/constants/adapters.js +180 -0
- package/lib/core/constants/core.d.ts +133 -0
- package/lib/core/constants/core.js +209 -0
- package/lib/core/constants/swap-router.d.ts +150 -0
- package/lib/core/constants/swap-router.js +169 -0
- package/lib/core/constants/vaults.d.ts +93 -0
- package/lib/core/constants/vaults.js +273 -0
- package/lib/core/constants/web3.d.ts +91 -0
- package/lib/core/constants/web3.js +229 -0
- package/lib/core/errors/index.d.ts +114 -0
- package/lib/core/errors/index.js +183 -0
- package/lib/core/fetcher.d.ts +198 -0
- package/lib/core/fetcher.js +903 -0
- package/lib/core/helpers/adapters.d.ts +13 -0
- package/lib/core/helpers/adapters.js +39 -0
- package/lib/core/helpers/chain-address.d.ts +13 -0
- package/lib/core/helpers/chain-address.js +47 -0
- package/lib/core/helpers/chain-error.d.ts +207 -0
- package/lib/core/helpers/chain-error.js +682 -0
- package/lib/core/helpers/chain-support.d.ts +80 -0
- package/lib/core/helpers/chain-support.js +115 -0
- package/lib/core/helpers/core.d.ts +68 -0
- package/lib/core/helpers/core.js +285 -0
- package/lib/core/helpers/explorer-link.d.ts +16 -0
- package/lib/core/helpers/explorer-link.js +26 -0
- package/lib/core/helpers/multicall.d.ts +68 -0
- package/lib/core/helpers/multicall.js +103 -0
- package/lib/core/helpers/revert-decode.d.ts +248 -0
- package/lib/core/helpers/revert-decode.js +515 -0
- package/lib/core/helpers/signer.d.ts +52 -0
- package/lib/core/helpers/signer.js +145 -0
- package/lib/core/helpers/swap-router.d.ts +211 -0
- package/lib/core/helpers/swap-router.js +480 -0
- package/lib/core/helpers/vault-version.d.ts +23 -0
- package/lib/core/helpers/vault-version.js +75 -0
- package/lib/core/helpers/vaults.d.ts +89 -0
- package/lib/core/helpers/vaults.js +235 -0
- package/lib/core/helpers/web3.d.ts +353 -0
- package/lib/core/helpers/web3.js +992 -0
- package/lib/core/index.d.ts +23 -0
- package/lib/core/index.js +40 -0
- package/lib/core/logger/index.d.ts +98 -0
- package/lib/core/logger/index.js +144 -0
- package/lib/core/logger/slack.d.ts +16 -0
- package/lib/core/logger/slack.js +57 -0
- package/lib/core/vault-metadata.d.ts +12 -0
- package/lib/core/vault-metadata.js +42 -0
- package/lib/core/version-check.d.ts +58 -0
- package/lib/core/version-check.js +182 -0
- package/lib/evm/index.d.ts +2 -0
- package/lib/evm/index.js +19 -0
- package/lib/evm/methods/crossChainVault.d.ts +128 -0
- package/lib/evm/methods/crossChainVault.js +853 -0
- package/lib/evm/methods/crossChainVaultRegistry.d.ts +93 -0
- package/lib/evm/methods/crossChainVaultRegistry.js +240 -0
- package/lib/evm/methods/index.d.ts +2 -0
- package/lib/evm/methods/index.js +19 -0
- package/lib/evm/types/crossChain.d.ts +363 -0
- package/lib/evm/types/crossChain.js +20 -0
- package/lib/evm/types/index.d.ts +1 -0
- package/lib/evm/types/index.js +18 -0
- package/lib/index.d.ts +30 -0
- package/lib/index.js +52 -0
- package/lib/main.d.ts +527 -0
- package/lib/main.js +601 -0
- package/lib/modules/api/fetcher.d.ts +82 -0
- package/lib/modules/api/fetcher.js +150 -0
- package/lib/modules/api/index.d.ts +1 -0
- package/lib/modules/api/index.js +6 -0
- package/lib/modules/api/main.d.ts +313 -0
- package/lib/modules/api/main.js +479 -0
- package/lib/modules/sub-accounts/fetcher.d.ts +53 -0
- package/lib/modules/sub-accounts/fetcher.js +120 -0
- package/lib/modules/sub-accounts/index.d.ts +2 -0
- package/lib/modules/sub-accounts/index.js +19 -0
- package/lib/modules/sub-accounts/main.d.ts +243 -0
- package/lib/modules/sub-accounts/main.js +205 -0
- package/lib/modules/sub-accounts/utils.d.ts +106 -0
- package/lib/modules/sub-accounts/utils.js +112 -0
- package/lib/modules/vaults/adapter.helpers.d.ts +64 -0
- package/lib/modules/vaults/adapter.helpers.js +184 -0
- package/lib/modules/vaults/fetcher.d.ts +147 -0
- package/lib/modules/vaults/fetcher.js +368 -0
- package/lib/modules/vaults/getters.d.ts +570 -0
- package/lib/modules/vaults/getters.js +3051 -0
- package/lib/modules/vaults/index.d.ts +20 -0
- package/lib/modules/vaults/index.js +44 -0
- package/lib/modules/vaults/main.d.ts +601 -0
- package/lib/modules/vaults/main.js +1623 -0
- package/lib/modules/vaults/prefetch.d.ts +65 -0
- package/lib/modules/vaults/prefetch.js +120 -0
- package/lib/modules/vaults/read.actions.d.ts +225 -0
- package/lib/modules/vaults/read.actions.js +596 -0
- package/lib/modules/vaults/types.d.ts +71 -0
- package/lib/modules/vaults/types.js +3 -0
- package/lib/modules/vaults/utils/call-data-decoder.d.ts +61 -0
- package/lib/modules/vaults/utils/call-data-decoder.js +194 -0
- package/lib/modules/vaults/utils/date-utils.d.ts +50 -0
- package/lib/modules/vaults/utils/date-utils.js +84 -0
- package/lib/modules/vaults/utils.d.ts +140 -0
- package/lib/modules/vaults/utils.js +799 -0
- package/lib/modules/vaults/write.actions.d.ts +529 -0
- package/lib/modules/vaults/write.actions.js +1749 -0
- package/lib/polyfills.d.ts +1 -0
- package/lib/polyfills.js +12 -0
- package/lib/sdk.d.ts +26721 -0
- package/lib/services/coingecko/fetcher.d.ts +15 -0
- package/lib/services/coingecko/fetcher.js +67 -0
- package/lib/services/coingecko/index.d.ts +2 -0
- package/lib/services/coingecko/index.js +19 -0
- package/lib/services/coingecko/utils.d.ts +1 -0
- package/lib/services/coingecko/utils.js +24 -0
- package/lib/services/debank/fetcher.d.ts +126 -0
- package/lib/services/debank/fetcher.js +47 -0
- package/lib/services/debank/index.d.ts +2 -0
- package/lib/services/debank/index.js +19 -0
- package/lib/services/debank/utils.d.ts +38 -0
- package/lib/services/debank/utils.js +297 -0
- package/lib/services/layerzero/deposits.d.ts +49 -0
- package/lib/services/layerzero/deposits.js +166 -0
- package/lib/services/layerzero/redeems.d.ts +20 -0
- package/lib/services/layerzero/redeems.js +92 -0
- package/lib/services/layerzero/utils.d.ts +9 -0
- package/lib/services/layerzero/utils.js +22 -0
- package/lib/services/octavfi/fetcher.d.ts +9 -0
- package/lib/services/octavfi/fetcher.js +103 -0
- package/lib/services/octavfi/index.d.ts +3 -0
- package/lib/services/octavfi/index.js +20 -0
- package/lib/services/octavfi/types.d.ts +34 -0
- package/lib/services/octavfi/types.js +3 -0
- package/lib/services/octavfi/utils.d.ts +16 -0
- package/lib/services/octavfi/utils.js +212 -0
- package/lib/services/subgraph/fetcher.d.ts +2 -0
- package/lib/services/subgraph/fetcher.js +61 -0
- package/lib/services/subgraph/index.d.ts +2 -0
- package/lib/services/subgraph/index.js +19 -0
- package/lib/services/subgraph/schema.d.ts +45 -0
- package/lib/services/subgraph/schema.js +75 -0
- package/lib/services/subgraph/vaults.d.ts +25 -0
- package/lib/services/subgraph/vaults.js +1106 -0
- package/lib/services/swap-quotes/index.d.ts +105 -0
- package/lib/services/swap-quotes/index.js +77 -0
- package/lib/services/swap-quotes/paraswap.d.ts +51 -0
- package/lib/services/swap-quotes/paraswap.js +138 -0
- package/lib/types/api.d.ts +280 -0
- package/lib/types/api.js +3 -0
- package/lib/types/index.d.ts +12 -0
- package/lib/types/index.js +28 -0
- package/lib/types/points.d.ts +28 -0
- package/lib/types/points.js +3 -0
- package/lib/types/pools.d.ts +144 -0
- package/lib/types/pools.js +3 -0
- package/lib/types/staking.d.ts +28 -0
- package/lib/types/staking.js +3 -0
- package/lib/types/sub-accounts.d.ts +140 -0
- package/lib/types/sub-accounts.js +3 -0
- package/lib/types/subgraph.d.ts +74 -0
- package/lib/types/subgraph.js +3 -0
- package/lib/types/typed-contract.d.ts +102 -0
- package/lib/types/typed-contract.js +3 -0
- package/lib/types/user.d.ts +1 -0
- package/lib/types/user.js +3 -0
- package/lib/types/vaults.d.ts +714 -0
- package/lib/types/vaults.js +24 -0
- package/lib/types/web3.d.ts +51 -0
- package/lib/types/web3.js +14 -0
- package/lib/types/webserver.d.ts +698 -0
- package/lib/types/webserver.js +3 -0
- package/package.json +78 -0
|
@@ -0,0 +1,260 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.sanitizeString = sanitizeString;
|
|
4
|
+
exports.sanitizeError = sanitizeError;
|
|
5
|
+
exports.sanitizeForLogging = sanitizeForLogging;
|
|
6
|
+
exports.computeArgShape = computeArgShape;
|
|
7
|
+
exports.sanitizeArgs = sanitizeArgs;
|
|
8
|
+
exports.sanitizeObject = sanitizeObject;
|
|
9
|
+
/** Keys that should never be sent to logging/observability sinks */
|
|
10
|
+
const SENSITIVE_KEYS = [
|
|
11
|
+
'apikey',
|
|
12
|
+
'api_key',
|
|
13
|
+
'apiKey',
|
|
14
|
+
'x-api-key',
|
|
15
|
+
'password',
|
|
16
|
+
'secret',
|
|
17
|
+
'token',
|
|
18
|
+
'bearer',
|
|
19
|
+
'authorization',
|
|
20
|
+
'proxy-authorization',
|
|
21
|
+
'cookie',
|
|
22
|
+
'set-cookie',
|
|
23
|
+
'privatekey',
|
|
24
|
+
'private_key',
|
|
25
|
+
'privateKey',
|
|
26
|
+
'mnemonic',
|
|
27
|
+
'seed',
|
|
28
|
+
// RPC endpoints can carry the API key in the path (e.g. Alchemy `/v2/<key>`),
|
|
29
|
+
// so a `sorobanRpcUrl` / `rpcUrl` argument must never reach telemetry. Matched
|
|
30
|
+
// as a substring, so it also covers `sorobanRpcUrls` and snake_case variants.
|
|
31
|
+
'rpcurl',
|
|
32
|
+
'rpc_url',
|
|
33
|
+
];
|
|
34
|
+
/** Regex patterns applied in order to scrub secrets from free-form strings. */
|
|
35
|
+
const STRING_REDACTION_PATTERNS = [
|
|
36
|
+
[/(authorization\s*[:=]\s*)(bearer|basic|token)\s+\S+/gi, '$1$2 [REDACTED]'],
|
|
37
|
+
[
|
|
38
|
+
/([?&](?:api[-_]?key|apikey|access[-_]?token|token|key|auth)=)[^&\s#]+/gi,
|
|
39
|
+
'$1[REDACTED]',
|
|
40
|
+
],
|
|
41
|
+
[/(gateway\.thegraph\.com\/api\/)[A-Za-z0-9]{20,}(\/)/g, '$1[REDACTED]$2'],
|
|
42
|
+
// Provider path-embedded API keys (e.g. Alchemy `…/v2/<key>`, Infura `…/v3/<key>`):
|
|
43
|
+
// a 16+ char token right after a `/vN/` segment is a key, not a resource path.
|
|
44
|
+
[/(\/v\d+\/)[A-Za-z0-9_-]{16,}/g, '$1[REDACTED]'],
|
|
45
|
+
[/eyJ[A-Za-z0-9_-]+\.[A-Za-z0-9_-]+\.[A-Za-z0-9_-]+/g, '[REDACTED_JWT]'],
|
|
46
|
+
[/\bnpm_[A-Za-z0-9]{30,}\b/g, '[REDACTED_NPM_TOKEN]'],
|
|
47
|
+
// Stop value match at & # so adjacent query params aren't swallowed.
|
|
48
|
+
[
|
|
49
|
+
/(\b(?:api[-_]?key|apikey|password|secret|private[-_]?key|mnemonic|seed)\s*[:=]\s*)["']?[^\s"',;}&#]+["']?/gi,
|
|
50
|
+
'$1[REDACTED]',
|
|
51
|
+
],
|
|
52
|
+
];
|
|
53
|
+
/**
|
|
54
|
+
* Redact secrets from a free-form string (error messages, URLs, log lines).
|
|
55
|
+
*
|
|
56
|
+
* @example
|
|
57
|
+
* sanitizeString('Request failed: https://api.example.com/v1?api_key=abc123')
|
|
58
|
+
* // → 'Request failed: https://api.example.com/v1?api_key=[REDACTED]'
|
|
59
|
+
*/
|
|
60
|
+
function sanitizeString(input) {
|
|
61
|
+
if (!input)
|
|
62
|
+
return input;
|
|
63
|
+
let out = input;
|
|
64
|
+
for (const [pattern, replacement] of STRING_REDACTION_PATTERNS) {
|
|
65
|
+
out = out.replace(pattern, replacement);
|
|
66
|
+
}
|
|
67
|
+
return out;
|
|
68
|
+
}
|
|
69
|
+
/**
|
|
70
|
+
* Return a redacted clone of `err`. Preserves prototype (so `instanceof` checks
|
|
71
|
+
* keep working), `name`, all own properties (`code`, `status`, `correlationId`,
|
|
72
|
+
* …), and `cause`. Subclass constructors are NOT invoked — they may have
|
|
73
|
+
* positional signatures (`new AugustAuthError(code, message, opts)`) that would
|
|
74
|
+
* misalign if we naively passed the sanitized message as the first arg.
|
|
75
|
+
*/
|
|
76
|
+
function sanitizeError(err) {
|
|
77
|
+
if (!(err instanceof Error))
|
|
78
|
+
return err;
|
|
79
|
+
const safe = Object.create(Object.getPrototypeOf(err));
|
|
80
|
+
for (const key of Object.getOwnPropertyNames(err)) {
|
|
81
|
+
const value = err[key];
|
|
82
|
+
if (key === 'message' && typeof value === 'string') {
|
|
83
|
+
safe[key] = sanitizeString(value);
|
|
84
|
+
}
|
|
85
|
+
else if (key === 'stack' && typeof value === 'string') {
|
|
86
|
+
safe[key] = sanitizeString(value);
|
|
87
|
+
}
|
|
88
|
+
else {
|
|
89
|
+
safe[key] = value;
|
|
90
|
+
}
|
|
91
|
+
}
|
|
92
|
+
if (!safe.message && typeof err.message === 'string') {
|
|
93
|
+
safe.message = sanitizeString(err.message);
|
|
94
|
+
}
|
|
95
|
+
if (!safe.stack && typeof err.stack === 'string') {
|
|
96
|
+
safe.stack = sanitizeString(err.stack);
|
|
97
|
+
}
|
|
98
|
+
safe.name = err.name;
|
|
99
|
+
return safe;
|
|
100
|
+
}
|
|
101
|
+
/** Sanitize arbitrary log input (strings, errors, objects, arrays, primitives). */
|
|
102
|
+
function sanitizeForLogging(input, depth = 0) {
|
|
103
|
+
if (input === null || input === undefined)
|
|
104
|
+
return input;
|
|
105
|
+
if (depth > 3)
|
|
106
|
+
return '[TRUNCATED]';
|
|
107
|
+
if (typeof input === 'string')
|
|
108
|
+
return sanitizeString(input);
|
|
109
|
+
if (typeof input === 'number' || typeof input === 'boolean')
|
|
110
|
+
return input;
|
|
111
|
+
if (input instanceof Error)
|
|
112
|
+
return sanitizeError(input);
|
|
113
|
+
if (Array.isArray(input)) {
|
|
114
|
+
return input.slice(0, 10).map((v) => sanitizeForLogging(v, depth + 1));
|
|
115
|
+
}
|
|
116
|
+
if (typeof input === 'object') {
|
|
117
|
+
return sanitizeObject(input, depth);
|
|
118
|
+
}
|
|
119
|
+
return `[${typeof input}]`;
|
|
120
|
+
}
|
|
121
|
+
/**
|
|
122
|
+
* Compute a value-free structural signature for a list of arguments — used
|
|
123
|
+
* as the `sdk.argShape` Sentry tag so dashboards can count which overload of
|
|
124
|
+
* a method partners call without ingesting wallet addresses or other PII.
|
|
125
|
+
*
|
|
126
|
+
* Tokens: primitives keep their `typeof` name; 0x-prefixed strings narrow to
|
|
127
|
+
* `'address'` / `'tx-hash'` / `'hex'`; arrays render as `'array(<length>)'`;
|
|
128
|
+
* objects render as `'options{<sorted,keys>}'`, capped at 12 keys.
|
|
129
|
+
*
|
|
130
|
+
* @param args - The `arguments` array of an instrumented method.
|
|
131
|
+
* @returns Shape tokens, one per arg, in argument order.
|
|
132
|
+
*
|
|
133
|
+
* @example
|
|
134
|
+
* computeArgShape(['0xabc…ef', { vault: '0x…', chainId: 1 }])
|
|
135
|
+
* // → ['address', 'options{chainId,vault}']
|
|
136
|
+
*/
|
|
137
|
+
function computeArgShape(args) {
|
|
138
|
+
return args.map((arg) => shapeOf(arg));
|
|
139
|
+
}
|
|
140
|
+
function shapeOf(value) {
|
|
141
|
+
if (value === null)
|
|
142
|
+
return 'null';
|
|
143
|
+
if (value === undefined)
|
|
144
|
+
return 'undefined';
|
|
145
|
+
const t = typeof value;
|
|
146
|
+
if (t === 'boolean' || t === 'number' || t === 'bigint' || t === 'function') {
|
|
147
|
+
return t;
|
|
148
|
+
}
|
|
149
|
+
if (t === 'string') {
|
|
150
|
+
const s = value;
|
|
151
|
+
if (/^0x[a-fA-F0-9]{40}$/.test(s))
|
|
152
|
+
return 'address';
|
|
153
|
+
if (/^0x[a-fA-F0-9]{64}$/.test(s))
|
|
154
|
+
return 'tx-hash';
|
|
155
|
+
if (/^0x[a-fA-F0-9]{6,}$/.test(s))
|
|
156
|
+
return 'hex';
|
|
157
|
+
return 'string';
|
|
158
|
+
}
|
|
159
|
+
if (Array.isArray(value)) {
|
|
160
|
+
return `array(${value.length})`;
|
|
161
|
+
}
|
|
162
|
+
if (t === 'object') {
|
|
163
|
+
const keys = Object.keys(value).sort();
|
|
164
|
+
const capped = keys.slice(0, 12);
|
|
165
|
+
const more = keys.length > 12 ? `,+${keys.length - 12}` : '';
|
|
166
|
+
return `options{${capped.join(',')}${more}}`;
|
|
167
|
+
}
|
|
168
|
+
return t;
|
|
169
|
+
}
|
|
170
|
+
/**
|
|
171
|
+
* Sanitize method arguments for safe logging to Sentry.
|
|
172
|
+
* Removes sensitive data and truncates large values.
|
|
173
|
+
*/
|
|
174
|
+
function sanitizeArgs(args) {
|
|
175
|
+
const sanitized = {};
|
|
176
|
+
args.forEach((arg, index) => {
|
|
177
|
+
const key = `arg${index}`;
|
|
178
|
+
if (arg === null || arg === undefined) {
|
|
179
|
+
sanitized[key] = arg;
|
|
180
|
+
return;
|
|
181
|
+
}
|
|
182
|
+
if (typeof arg === 'string') {
|
|
183
|
+
// Scrub embedded secrets, then truncate long strings.
|
|
184
|
+
const scrubbed = sanitizeString(arg);
|
|
185
|
+
sanitized[key] =
|
|
186
|
+
scrubbed.length > 100 ? `${scrubbed.substring(0, 100)}...` : scrubbed;
|
|
187
|
+
return;
|
|
188
|
+
}
|
|
189
|
+
if (typeof arg === 'number' || typeof arg === 'boolean') {
|
|
190
|
+
sanitized[key] = arg;
|
|
191
|
+
return;
|
|
192
|
+
}
|
|
193
|
+
if (typeof arg === 'object') {
|
|
194
|
+
sanitized[key] = sanitizeObject(arg);
|
|
195
|
+
return;
|
|
196
|
+
}
|
|
197
|
+
// For functions or other types, just note the type
|
|
198
|
+
sanitized[key] = `[${typeof arg}]`;
|
|
199
|
+
});
|
|
200
|
+
return sanitized;
|
|
201
|
+
}
|
|
202
|
+
/**
|
|
203
|
+
* Recursively sanitize an object, removing sensitive keys.
|
|
204
|
+
*/
|
|
205
|
+
function sanitizeObject(obj, depth = 0) {
|
|
206
|
+
// Prevent deep recursion
|
|
207
|
+
if (depth > 3) {
|
|
208
|
+
return { _truncated: true };
|
|
209
|
+
}
|
|
210
|
+
const sanitized = {};
|
|
211
|
+
for (const [key, value] of Object.entries(obj)) {
|
|
212
|
+
// Skip sensitive keys
|
|
213
|
+
if (SENSITIVE_KEYS.some((sk) => key.toLowerCase().includes(sk.toLowerCase()))) {
|
|
214
|
+
sanitized[key] = '[REDACTED]';
|
|
215
|
+
continue;
|
|
216
|
+
}
|
|
217
|
+
if (value === null || value === undefined) {
|
|
218
|
+
sanitized[key] = value;
|
|
219
|
+
continue;
|
|
220
|
+
}
|
|
221
|
+
if (typeof value === 'string') {
|
|
222
|
+
// Check if value looks like a private key or sensitive data
|
|
223
|
+
if (value.length > 64 && /^[a-fA-F0-9]+$/.test(value)) {
|
|
224
|
+
sanitized[key] = '[REDACTED_HEX]';
|
|
225
|
+
continue;
|
|
226
|
+
}
|
|
227
|
+
// Scrub embedded secrets (API keys in URL paths/queries, bearer tokens,
|
|
228
|
+
// JWTs, …) from free-form values before truncating — key-name matching
|
|
229
|
+
// alone misses a secret carried inside a value under a benign key.
|
|
230
|
+
const scrubbedValue = sanitizeString(value);
|
|
231
|
+
sanitized[key] =
|
|
232
|
+
scrubbedValue.length > 100
|
|
233
|
+
? `${scrubbedValue.substring(0, 100)}...`
|
|
234
|
+
: scrubbedValue;
|
|
235
|
+
continue;
|
|
236
|
+
}
|
|
237
|
+
if (typeof value === 'number' || typeof value === 'boolean') {
|
|
238
|
+
sanitized[key] = value;
|
|
239
|
+
continue;
|
|
240
|
+
}
|
|
241
|
+
if (Array.isArray(value)) {
|
|
242
|
+
sanitized[key] =
|
|
243
|
+
value.length > 10
|
|
244
|
+
? { _type: 'array', length: value.length, _truncated: true }
|
|
245
|
+
: value
|
|
246
|
+
.slice(0, 10)
|
|
247
|
+
.map((v) => typeof v === 'object' && v !== null
|
|
248
|
+
? sanitizeObject(v, depth + 1)
|
|
249
|
+
: v);
|
|
250
|
+
continue;
|
|
251
|
+
}
|
|
252
|
+
if (typeof value === 'object') {
|
|
253
|
+
sanitized[key] = sanitizeObject(value, depth + 1);
|
|
254
|
+
continue;
|
|
255
|
+
}
|
|
256
|
+
sanitized[key] = `[${typeof value}]`;
|
|
257
|
+
}
|
|
258
|
+
return sanitized;
|
|
259
|
+
}
|
|
260
|
+
//# sourceMappingURL=sanitize.js.map
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import type * as SentryBrowser from '@sentry/browser';
|
|
2
|
+
/**
|
|
3
|
+
* Returns the resolved Sentry SDK for the current runtime, or `null` if no
|
|
4
|
+
* SDK can be loaded. Idempotent and cached.
|
|
5
|
+
*/
|
|
6
|
+
export declare function getSentrySDK(): typeof SentryBrowser | null;
|
|
7
|
+
/**
|
|
8
|
+
* Returns the detected runtime label (`'browser'` | `'node'` | `'unknown'`).
|
|
9
|
+
* Used to set the `sdk.runtime` Sentry tag.
|
|
10
|
+
*/
|
|
11
|
+
export declare function getSentryRuntime(): 'browser' | 'node' | 'unknown';
|
|
12
|
+
/**
|
|
13
|
+
* Reset the cached SDK reference and runtime detection. Test-only.
|
|
14
|
+
*/
|
|
15
|
+
export declare function resetSentryRuntime(): void;
|
|
@@ -0,0 +1,97 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.getSentrySDK = getSentrySDK;
|
|
4
|
+
exports.getSentryRuntime = getSentryRuntime;
|
|
5
|
+
exports.resetSentryRuntime = resetSentryRuntime;
|
|
6
|
+
const logger_1 = require("../logger");
|
|
7
|
+
let cachedSdk = null;
|
|
8
|
+
let detectedRuntime = 'unknown';
|
|
9
|
+
function detectRuntime() {
|
|
10
|
+
try {
|
|
11
|
+
if (typeof window !== 'undefined' &&
|
|
12
|
+
typeof window.document !== 'undefined') {
|
|
13
|
+
return 'browser';
|
|
14
|
+
}
|
|
15
|
+
if (typeof process !== 'undefined' &&
|
|
16
|
+
process.versions?.node &&
|
|
17
|
+
typeof window === 'undefined') {
|
|
18
|
+
return 'node';
|
|
19
|
+
}
|
|
20
|
+
}
|
|
21
|
+
catch {
|
|
22
|
+
// Property access on locked-down globals can throw in some sandboxes.
|
|
23
|
+
}
|
|
24
|
+
return 'unknown';
|
|
25
|
+
}
|
|
26
|
+
function getNodeRequire() {
|
|
27
|
+
try {
|
|
28
|
+
// `new Function` is opaque to bundler static analysis (keeps
|
|
29
|
+
// @sentry/node out of browser bundles) AND blocked by strict
|
|
30
|
+
// script-src CSPs without 'unsafe-eval'. The CSP-blocked path falls
|
|
31
|
+
// through to @sentry/browser — do NOT replace with a direct
|
|
32
|
+
// `require('@sentry/node')`, which breaks the browser bundle.
|
|
33
|
+
const req = new Function('return typeof require === "function" ? require : null')();
|
|
34
|
+
return typeof req === 'function' ? req : null;
|
|
35
|
+
}
|
|
36
|
+
catch {
|
|
37
|
+
return null;
|
|
38
|
+
}
|
|
39
|
+
}
|
|
40
|
+
function loadSentrySDK() {
|
|
41
|
+
if (cachedSdk)
|
|
42
|
+
return cachedSdk;
|
|
43
|
+
detectedRuntime = detectRuntime();
|
|
44
|
+
if (detectedRuntime === 'node') {
|
|
45
|
+
const nodeRequire = getNodeRequire();
|
|
46
|
+
if (nodeRequire) {
|
|
47
|
+
try {
|
|
48
|
+
cachedSdk = nodeRequire('@sentry/node');
|
|
49
|
+
return cachedSdk;
|
|
50
|
+
}
|
|
51
|
+
catch (err) {
|
|
52
|
+
// Fall through to @sentry/browser, but surface it — running on Node
|
|
53
|
+
// without @sentry/node loses process-level exception capture.
|
|
54
|
+
logger_1.Logger.log.warn('analytics.runtime.sentry-node-missing', {
|
|
55
|
+
error: err instanceof Error ? err.message : String(err),
|
|
56
|
+
hint: 'Add @sentry/node to your dependencies for full Node telemetry coverage.',
|
|
57
|
+
});
|
|
58
|
+
}
|
|
59
|
+
}
|
|
60
|
+
}
|
|
61
|
+
try {
|
|
62
|
+
cachedSdk = require('@sentry/browser');
|
|
63
|
+
}
|
|
64
|
+
catch (err) {
|
|
65
|
+
logger_1.Logger.log.warn('analytics.runtime.sentry-browser-missing', {
|
|
66
|
+
runtime: detectedRuntime,
|
|
67
|
+
error: err instanceof Error ? err.message : String(err),
|
|
68
|
+
});
|
|
69
|
+
cachedSdk = null;
|
|
70
|
+
}
|
|
71
|
+
return cachedSdk;
|
|
72
|
+
}
|
|
73
|
+
/**
|
|
74
|
+
* Returns the resolved Sentry SDK for the current runtime, or `null` if no
|
|
75
|
+
* SDK can be loaded. Idempotent and cached.
|
|
76
|
+
*/
|
|
77
|
+
function getSentrySDK() {
|
|
78
|
+
return loadSentrySDK();
|
|
79
|
+
}
|
|
80
|
+
/**
|
|
81
|
+
* Returns the detected runtime label (`'browser'` | `'node'` | `'unknown'`).
|
|
82
|
+
* Used to set the `sdk.runtime` Sentry tag.
|
|
83
|
+
*/
|
|
84
|
+
function getSentryRuntime() {
|
|
85
|
+
if (detectedRuntime === 'unknown') {
|
|
86
|
+
detectedRuntime = detectRuntime();
|
|
87
|
+
}
|
|
88
|
+
return detectedRuntime;
|
|
89
|
+
}
|
|
90
|
+
/**
|
|
91
|
+
* Reset the cached SDK reference and runtime detection. Test-only.
|
|
92
|
+
*/
|
|
93
|
+
function resetSentryRuntime() {
|
|
94
|
+
cachedSdk = null;
|
|
95
|
+
detectedRuntime = 'unknown';
|
|
96
|
+
}
|
|
97
|
+
//# sourceMappingURL=sentry-runtime.js.map
|
|
@@ -0,0 +1,67 @@
|
|
|
1
|
+
import type * as Sentry from '@sentry/browser';
|
|
2
|
+
import type { IEnv } from '../../types';
|
|
3
|
+
import type { IAnalyticsConfig } from './types';
|
|
4
|
+
/**
|
|
5
|
+
* Clear the error dedupe bookkeeping. Test-only — the rate limiter is process
|
|
6
|
+
* lifetime state and would otherwise leak between test cases.
|
|
7
|
+
*
|
|
8
|
+
* @internal
|
|
9
|
+
*/
|
|
10
|
+
export declare function resetErrorDedupe(): void;
|
|
11
|
+
/**
|
|
12
|
+
* Initialize Sentry with SDK-specific configuration. Idempotent: re-calls
|
|
13
|
+
* only refresh user identity and the cached API-key hash.
|
|
14
|
+
*
|
|
15
|
+
* @param config - Analytics configuration. Pass `tracesSampleRate` to
|
|
16
|
+
* override the default of `0.1`.
|
|
17
|
+
* @param environment - Current environment (DEV or PROD).
|
|
18
|
+
* @param walletAddress - Optional wallet address for user identification.
|
|
19
|
+
* @param apiKey - Optional API key (hashed for identification).
|
|
20
|
+
* @param appName - Optional app-name slug. Set as the global `app.name`
|
|
21
|
+
* tag on every event; falls back to `'unverified:anonymous'` when
|
|
22
|
+
* omitted.
|
|
23
|
+
*/
|
|
24
|
+
export declare function initializeSentry(config: IAnalyticsConfig, environment: IEnv, walletAddress?: string, apiKey?: string, appName?: string): void;
|
|
25
|
+
/**
|
|
26
|
+
* Update the current user identity in Sentry.
|
|
27
|
+
* Called when wallet address changes.
|
|
28
|
+
*
|
|
29
|
+
* @param walletAddress - New wallet address (or undefined to clear)
|
|
30
|
+
* @param environment - Current environment
|
|
31
|
+
*/
|
|
32
|
+
export declare function updateUser(walletAddress?: string, environment?: IEnv): void;
|
|
33
|
+
/**
|
|
34
|
+
* Clear wallet from user identity.
|
|
35
|
+
* Called when user disconnects wallet.
|
|
36
|
+
*/
|
|
37
|
+
export declare function clearUser(): void;
|
|
38
|
+
/**
|
|
39
|
+
* Check if analytics is enabled and initialized.
|
|
40
|
+
*/
|
|
41
|
+
export declare function isAnalyticsEnabled(): boolean;
|
|
42
|
+
/**
|
|
43
|
+
* Get the current Sentry instance for advanced usage.
|
|
44
|
+
* Returns null if analytics is disabled.
|
|
45
|
+
*/
|
|
46
|
+
export declare function getSentry(): typeof Sentry | null;
|
|
47
|
+
/**
|
|
48
|
+
* Reset analytics state (useful for testing).
|
|
49
|
+
*/
|
|
50
|
+
export declare function resetAnalytics(): void;
|
|
51
|
+
/**
|
|
52
|
+
* Capture an exception into Sentry with SDK-specific context. Use from
|
|
53
|
+
* top-level error handlers (CLI, middleware, unhandled rejections) to
|
|
54
|
+
* report failures that don't flow through the auto-instrumented method
|
|
55
|
+
* surface. No-ops when analytics is disabled.
|
|
56
|
+
*
|
|
57
|
+
* @param error - Thrown value. Non-Error values are wrapped.
|
|
58
|
+
* @param options - `surface` ('cli' | 'sdk' | 'react' | string), extra `tags`,
|
|
59
|
+
* `extra` data, and a `flushTimeoutMs` to await before resolving (needed
|
|
60
|
+
* in Node when the process is about to exit).
|
|
61
|
+
*/
|
|
62
|
+
export declare function captureSdkException(error: unknown, options?: {
|
|
63
|
+
surface?: 'cli' | 'sdk' | 'react' | string;
|
|
64
|
+
tags?: Record<string, string>;
|
|
65
|
+
extra?: Record<string, unknown>;
|
|
66
|
+
flushTimeoutMs?: number;
|
|
67
|
+
}): Promise<void>;
|