@coinbase/cdp-sdk 1.1.2 → 1.3.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/CHANGELOG.md +91 -0
- package/LICENSE +21 -0
- package/README.md +88 -1
- package/{dist → _cjs}/accounts/evm/toEvmServerAccount.js +1 -0
- package/_cjs/accounts/evm/toEvmServerAccount.js.map +1 -0
- package/{dist → _cjs}/accounts/evm/toEvmSmartAccount.js +1 -0
- package/_cjs/accounts/evm/toEvmSmartAccount.js.map +1 -0
- package/{dist → _cjs}/accounts/types.js +1 -0
- package/_cjs/accounts/types.js.map +1 -0
- package/{dist → _cjs}/actions/evm/sendUserOperation.js +1 -0
- package/_cjs/actions/evm/sendUserOperation.js.map +1 -0
- package/{dist → _cjs}/actions/evm/waitForUserOperation.js +10 -9
- package/_cjs/actions/evm/waitForUserOperation.js.map +1 -0
- package/{dist → _cjs}/analytics.js +32 -12
- package/_cjs/analytics.js.map +1 -0
- package/{dist → _cjs}/auth/errors.js +1 -0
- package/_cjs/auth/errors.js.map +1 -0
- package/{dist → _cjs}/auth/hooks/axios/index.js +2 -1
- package/_cjs/auth/hooks/axios/index.js.map +1 -0
- package/{dist → _cjs}/auth/hooks/axios/withAuth.js +4 -2
- package/_cjs/auth/hooks/axios/withAuth.js.map +1 -0
- package/{dist → _cjs}/auth/index.js +4 -3
- package/_cjs/auth/index.js.map +1 -0
- package/{dist → _cjs}/auth/utils/http.js +6 -5
- package/_cjs/auth/utils/http.js.map +1 -0
- package/{dist → _cjs}/auth/utils/index.js +3 -2
- package/_cjs/auth/utils/index.js.map +1 -0
- package/{dist → _cjs}/auth/utils/jwt.js +4 -3
- package/_cjs/auth/utils/jwt.js.map +1 -0
- package/_cjs/client/cdp.js +101 -0
- package/_cjs/client/cdp.js.map +1 -0
- package/_cjs/client/evm/evm.js +641 -0
- package/_cjs/client/evm/evm.js.map +1 -0
- package/{dist → _cjs}/client/evm/evm.types.js +1 -0
- package/_cjs/client/evm/evm.types.js.map +1 -0
- package/{dist → _cjs}/client/solana/index.js +3 -2
- package/_cjs/client/solana/index.js.map +1 -0
- package/{dist → _cjs}/client/solana/solana.js +9 -8
- package/_cjs/client/solana/solana.js.map +1 -0
- package/{dist → _cjs}/client/solana/solana.types.js +1 -0
- package/_cjs/client/solana/solana.types.js.map +1 -0
- package/{dist → _cjs}/constants.js +1 -0
- package/_cjs/constants.js.map +1 -0
- package/{dist → _cjs}/errors.js +1 -0
- package/_cjs/errors.js.map +1 -0
- package/{dist → _cjs}/index.js +4 -3
- package/_cjs/index.js.map +1 -0
- package/_cjs/openapi-client/cdpApiClient.js +116 -0
- package/_cjs/openapi-client/cdpApiClient.js.map +1 -0
- package/{dist → _cjs}/openapi-client/errors.js +44 -3
- package/_cjs/openapi-client/errors.js.map +1 -0
- package/_cjs/openapi-client/generated/coinbaseDeveloperPlatformAPIs.schemas.js +66 -0
- package/_cjs/openapi-client/generated/coinbaseDeveloperPlatformAPIs.schemas.js.map +1 -0
- package/_cjs/openapi-client/generated/evm-accounts/evm-accounts.js +125 -0
- package/_cjs/openapi-client/generated/evm-accounts/evm-accounts.js.map +1 -0
- package/_cjs/openapi-client/generated/evm-accounts/evm-accounts.msw.js +160 -0
- package/_cjs/openapi-client/generated/evm-accounts/evm-accounts.msw.js.map +1 -0
- package/_cjs/openapi-client/generated/evm-smart-accounts/evm-smart-accounts.js +70 -0
- package/_cjs/openapi-client/generated/evm-smart-accounts/evm-smart-accounts.js.map +1 -0
- package/_cjs/openapi-client/generated/evm-smart-accounts/evm-smart-accounts.msw.js +188 -0
- package/_cjs/openapi-client/generated/evm-smart-accounts/evm-smart-accounts.msw.js.map +1 -0
- package/_cjs/openapi-client/generated/evm-token-balances/evm-token-balances.js +15 -0
- package/_cjs/openapi-client/generated/evm-token-balances/evm-token-balances.js.map +1 -0
- package/_cjs/openapi-client/generated/evm-token-balances/evm-token-balances.msw.js +45 -0
- package/_cjs/openapi-client/generated/evm-token-balances/evm-token-balances.msw.js.map +1 -0
- package/{dist → _cjs}/openapi-client/generated/faucets/faucets.js +20 -14
- package/_cjs/openapi-client/generated/faucets/faucets.js.map +1 -0
- package/{dist → _cjs}/openapi-client/generated/faucets/faucets.msw.js +16 -12
- package/_cjs/openapi-client/generated/faucets/faucets.msw.js.map +1 -0
- package/{dist → _cjs}/openapi-client/generated/index.msw.js +6 -4
- package/_cjs/openapi-client/generated/index.msw.js.map +1 -0
- package/{dist → _cjs}/openapi-client/generated/solana-accounts/solana-accounts.js +38 -35
- package/_cjs/openapi-client/generated/solana-accounts/solana-accounts.js.map +1 -0
- package/{dist → _cjs}/openapi-client/generated/solana-accounts/solana-accounts.msw.js +68 -35
- package/_cjs/openapi-client/generated/solana-accounts/solana-accounts.msw.js.map +1 -0
- package/{dist → _cjs}/openapi-client/index.js +16 -11
- package/_cjs/openapi-client/index.js.map +1 -0
- package/_cjs/package.json +1 -0
- package/{dist → _cjs}/types/calls.js +1 -0
- package/_cjs/types/calls.js.map +1 -0
- package/{dist → _cjs}/types/contract.js +1 -0
- package/_cjs/types/contract.js.map +1 -0
- package/{dist → _cjs}/types/misc.js +1 -0
- package/_cjs/types/misc.js.map +1 -0
- package/{dist → _cjs}/types/multicall.js +1 -0
- package/_cjs/types/multicall.js.map +1 -0
- package/{dist → _cjs}/types/utils.js +1 -0
- package/_cjs/types/utils.js.map +1 -0
- package/{dist → _cjs}/utils/wait.js +3 -2
- package/_cjs/utils/wait.js.map +1 -0
- package/_cjs/version.js +5 -0
- package/_cjs/version.js.map +1 -0
- package/_esm/accounts/evm/toEvmServerAccount.js +40 -0
- package/_esm/accounts/evm/toEvmServerAccount.js.map +1 -0
- package/_esm/accounts/evm/toEvmSmartAccount.js +22 -0
- package/_esm/accounts/evm/toEvmSmartAccount.js.map +1 -0
- package/_esm/accounts/types.js +2 -0
- package/_esm/accounts/types.js.map +1 -0
- package/_esm/actions/evm/sendUserOperation.js +85 -0
- package/_esm/actions/evm/sendUserOperation.js.map +1 -0
- package/_esm/actions/evm/waitForUserOperation.js +58 -0
- package/_esm/actions/evm/waitForUserOperation.js.map +1 -0
- package/_esm/analytics.js +101 -0
- package/_esm/analytics.js.map +1 -0
- package/_esm/auth/errors.js +57 -0
- package/_esm/auth/errors.js.map +1 -0
- package/_esm/auth/hooks/axios/index.js +2 -0
- package/_esm/auth/hooks/axios/index.js.map +1 -0
- package/_esm/auth/hooks/axios/withAuth.js +72 -0
- package/_esm/auth/hooks/axios/withAuth.js.map +1 -0
- package/_esm/auth/index.js +5 -0
- package/_esm/auth/index.js.map +1 -0
- package/_esm/auth/utils/http.js +70 -0
- package/_esm/auth/utils/http.js.map +1 -0
- package/_esm/auth/utils/index.js +3 -0
- package/_esm/auth/utils/index.js.map +1 -0
- package/_esm/auth/utils/jwt.js +199 -0
- package/_esm/auth/utils/jwt.js.map +1 -0
- package/{dist → _esm}/client/cdp.js +16 -13
- package/_esm/client/cdp.js.map +1 -0
- package/{dist → _esm}/client/evm/evm.js +146 -30
- package/_esm/client/evm/evm.js.map +1 -0
- package/_esm/client/evm/evm.types.js +2 -0
- package/_esm/client/evm/evm.types.js.map +1 -0
- package/_esm/client/solana/index.js +2 -0
- package/_esm/client/solana/index.js.map +1 -0
- package/_esm/client/solana/solana.js +204 -0
- package/_esm/client/solana/solana.js.map +1 -0
- package/_esm/client/solana/solana.types.js +2 -0
- package/_esm/client/solana/solana.types.js.map +1 -0
- package/_esm/constants.js +5 -0
- package/_esm/constants.js.map +1 -0
- package/_esm/errors.js +18 -0
- package/_esm/errors.js.map +1 -0
- package/_esm/index.js +3 -0
- package/_esm/index.js.map +1 -0
- package/_esm/openapi-client/cdpApiClient.js +108 -0
- package/_esm/openapi-client/cdpApiClient.js.map +1 -0
- package/_esm/openapi-client/errors.js +104 -0
- package/_esm/openapi-client/errors.js.map +1 -0
- package/_esm/openapi-client/generated/coinbaseDeveloperPlatformAPIs.schemas.js +63 -0
- package/_esm/openapi-client/generated/coinbaseDeveloperPlatformAPIs.schemas.js.map +1 -0
- package/_esm/openapi-client/generated/evm-accounts/evm-accounts.js +114 -0
- package/_esm/openapi-client/generated/evm-accounts/evm-accounts.js.map +1 -0
- package/_esm/openapi-client/generated/evm-accounts/evm-accounts.msw.js +140 -0
- package/_esm/openapi-client/generated/evm-accounts/evm-accounts.msw.js.map +1 -0
- package/_esm/openapi-client/generated/evm-smart-accounts/evm-smart-accounts.js +61 -0
- package/_esm/openapi-client/generated/evm-smart-accounts/evm-smart-accounts.js.map +1 -0
- package/_esm/openapi-client/generated/evm-smart-accounts/evm-smart-accounts.msw.js +172 -0
- package/_esm/openapi-client/generated/evm-smart-accounts/evm-smart-accounts.msw.js.map +1 -0
- package/_esm/openapi-client/generated/evm-token-balances/evm-token-balances.js +11 -0
- package/_esm/openapi-client/generated/evm-token-balances/evm-token-balances.js.map +1 -0
- package/_esm/openapi-client/generated/evm-token-balances/evm-token-balances.msw.js +39 -0
- package/_esm/openapi-client/generated/evm-token-balances/evm-token-balances.msw.js.map +1 -0
- package/_esm/openapi-client/generated/faucets/faucets.js +52 -0
- package/_esm/openapi-client/generated/faucets/faucets.js.map +1 -0
- package/_esm/openapi-client/generated/faucets/faucets.msw.js +39 -0
- package/_esm/openapi-client/generated/faucets/faucets.msw.js.map +1 -0
- package/_esm/openapi-client/generated/index.msw.js +6 -0
- package/_esm/openapi-client/generated/index.msw.js.map +1 -0
- package/_esm/openapi-client/generated/solana-accounts/solana-accounts.js +73 -0
- package/_esm/openapi-client/generated/solana-accounts/solana-accounts.js.map +1 -0
- package/_esm/openapi-client/generated/solana-accounts/solana-accounts.msw.js +116 -0
- package/_esm/openapi-client/generated/solana-accounts/solana-accounts.msw.js.map +1 -0
- package/_esm/openapi-client/index.js +31 -0
- package/_esm/openapi-client/index.js.map +1 -0
- package/_esm/package.json +1 -0
- package/_esm/types/calls.js +4 -0
- package/_esm/types/calls.js.map +1 -0
- package/_esm/types/contract.js +4 -0
- package/_esm/types/contract.js.map +1 -0
- package/_esm/types/misc.js +3 -0
- package/_esm/types/misc.js.map +1 -0
- package/_esm/types/multicall.js +2 -0
- package/_esm/types/multicall.js.map +1 -0
- package/_esm/types/utils.js +4 -0
- package/_esm/types/utils.js.map +1 -0
- package/_esm/utils/wait.js +32 -0
- package/_esm/utils/wait.js.map +1 -0
- package/_esm/version.js +2 -0
- package/_esm/version.js.map +1 -0
- package/{dist → _types}/accounts/evm/toEvmServerAccount.d.ts +3 -2
- package/_types/accounts/evm/toEvmServerAccount.d.ts.map +1 -0
- package/{dist → _types}/accounts/evm/toEvmSmartAccount.d.ts +3 -2
- package/_types/accounts/evm/toEvmSmartAccount.d.ts.map +1 -0
- package/{dist → _types}/accounts/types.d.ts +3 -2
- package/_types/accounts/types.d.ts.map +1 -0
- package/{dist → _types}/actions/evm/sendUserOperation.d.ts +5 -5
- package/_types/actions/evm/sendUserOperation.d.ts.map +1 -0
- package/{dist → _types}/actions/evm/waitForUserOperation.d.ts +4 -3
- package/_types/actions/evm/waitForUserOperation.d.ts.map +1 -0
- package/{dist → _types}/analytics.d.ts +16 -0
- package/_types/analytics.d.ts.map +1 -0
- package/{dist → _types}/auth/errors.d.ts +1 -0
- package/_types/auth/errors.d.ts.map +1 -0
- package/_types/auth/hooks/axios/index.d.ts +2 -0
- package/_types/auth/hooks/axios/index.d.ts.map +1 -0
- package/{dist → _types}/auth/hooks/axios/withAuth.d.ts +1 -0
- package/_types/auth/hooks/axios/withAuth.d.ts.map +1 -0
- package/_types/auth/index.d.ts +5 -0
- package/_types/auth/index.d.ts.map +1 -0
- package/{dist → _types}/auth/utils/http.d.ts +1 -0
- package/_types/auth/utils/http.d.ts.map +1 -0
- package/_types/auth/utils/index.d.ts +3 -0
- package/_types/auth/utils/index.d.ts.map +1 -0
- package/{dist → _types}/auth/utils/jwt.d.ts +1 -0
- package/_types/auth/utils/jwt.d.ts.map +1 -0
- package/{dist → _types}/client/cdp.d.ts +3 -2
- package/_types/client/cdp.d.ts.map +1 -0
- package/{dist → _types}/client/evm/evm.d.ts +86 -3
- package/_types/client/evm/evm.d.ts.map +1 -0
- package/{dist → _types}/client/evm/evm.types.d.ts +104 -7
- package/_types/client/evm/evm.types.d.ts.map +1 -0
- package/_types/client/solana/index.d.ts +2 -0
- package/_types/client/solana/index.d.ts.map +1 -0
- package/{dist → _types}/client/solana/solana.d.ts +2 -1
- package/_types/client/solana/solana.d.ts.map +1 -0
- package/{dist → _types}/client/solana/solana.types.d.ts +2 -1
- package/_types/client/solana/solana.types.d.ts.map +1 -0
- package/{dist → _types}/constants.d.ts +1 -0
- package/_types/constants.d.ts.map +1 -0
- package/{dist → _types}/errors.d.ts +1 -0
- package/_types/errors.d.ts.map +1 -0
- package/_types/index.d.ts +4 -0
- package/_types/index.d.ts.map +1 -0
- package/{dist → _types}/openapi-client/cdpApiClient.d.ts +1 -0
- package/_types/openapi-client/cdpApiClient.d.ts.map +1 -0
- package/{dist → _types}/openapi-client/errors.d.ts +30 -2
- package/_types/openapi-client/errors.d.ts.map +1 -0
- package/{dist → _types}/openapi-client/generated/coinbaseDeveloperPlatformAPIs.schemas.d.ts +100 -14
- package/_types/openapi-client/generated/coinbaseDeveloperPlatformAPIs.schemas.d.ts.map +1 -0
- package/_types/openapi-client/generated/evm-accounts/evm-accounts.d.ts +91 -0
- package/_types/openapi-client/generated/evm-accounts/evm-accounts.d.ts.map +1 -0
- package/{dist → _types}/openapi-client/generated/evm-accounts/evm-accounts.msw.d.ts +5 -2
- package/_types/openapi-client/generated/evm-accounts/evm-accounts.msw.d.ts.map +1 -0
- package/{dist → _types}/openapi-client/generated/evm-smart-accounts/evm-smart-accounts.d.ts +22 -20
- package/_types/openapi-client/generated/evm-smart-accounts/evm-smart-accounts.d.ts.map +1 -0
- package/{dist → _types}/openapi-client/generated/evm-smart-accounts/evm-smart-accounts.msw.d.ts +3 -2
- package/_types/openapi-client/generated/evm-smart-accounts/evm-smart-accounts.msw.d.ts.map +1 -0
- package/_types/openapi-client/generated/evm-token-balances/evm-token-balances.d.ts +20 -0
- package/_types/openapi-client/generated/evm-token-balances/evm-token-balances.d.ts.map +1 -0
- package/_types/openapi-client/generated/evm-token-balances/evm-token-balances.msw.d.ts +6 -0
- package/_types/openapi-client/generated/evm-token-balances/evm-token-balances.msw.d.ts.map +1 -0
- package/{dist → _types}/openapi-client/generated/faucets/faucets.d.ts +11 -9
- package/_types/openapi-client/generated/faucets/faucets.d.ts.map +1 -0
- package/{dist → _types}/openapi-client/generated/faucets/faucets.msw.d.ts +3 -2
- package/_types/openapi-client/generated/faucets/faucets.msw.d.ts.map +1 -0
- package/_types/openapi-client/generated/index.msw.d.ts +6 -0
- package/_types/openapi-client/generated/index.msw.d.ts.map +1 -0
- package/{dist → _types}/openapi-client/generated/solana-accounts/solana-accounts.d.ts +21 -20
- package/_types/openapi-client/generated/solana-accounts/solana-accounts.d.ts.map +1 -0
- package/{dist → _types}/openapi-client/generated/solana-accounts/solana-accounts.msw.d.ts +3 -2
- package/_types/openapi-client/generated/solana-accounts/solana-accounts.msw.d.ts.map +1 -0
- package/_types/openapi-client/index.d.ts +61 -0
- package/_types/openapi-client/index.d.ts.map +1 -0
- package/{dist → _types}/types/calls.d.ts +4 -3
- package/_types/types/calls.d.ts.map +1 -0
- package/{dist → _types}/types/contract.d.ts +3 -2
- package/_types/types/contract.d.ts.map +1 -0
- package/_types/types/misc.d.ts +41 -0
- package/_types/types/misc.d.ts.map +1 -0
- package/{dist → _types}/types/multicall.d.ts +2 -1
- package/_types/types/multicall.d.ts.map +1 -0
- package/{dist → _types}/types/utils.d.ts +1 -0
- package/_types/types/utils.d.ts.map +1 -0
- package/{dist → _types}/utils/wait.d.ts +1 -0
- package/_types/utils/wait.d.ts.map +1 -0
- package/_types/version.d.ts +2 -0
- package/_types/version.d.ts.map +1 -0
- package/accounts/evm/toEvmServerAccount.ts +60 -0
- package/accounts/evm/toEvmSmartAccount.ts +37 -0
- package/accounts/types.ts +53 -0
- package/actions/evm/sendUserOperation.ts +163 -0
- package/actions/evm/waitForUserOperation.ts +115 -0
- package/analytics.ts +142 -0
- package/auth/README.md +145 -0
- package/auth/errors.ts +59 -0
- package/auth/hooks/axios/index.ts +1 -0
- package/auth/hooks/axios/withAuth.ts +121 -0
- package/auth/index.ts +5 -0
- package/auth/utils/http.ts +146 -0
- package/auth/utils/index.ts +2 -0
- package/auth/utils/jwt.ts +324 -0
- package/client/cdp.ts +116 -0
- package/client/evm/evm.ts +739 -0
- package/client/evm/evm.types.ts +408 -0
- package/client/solana/index.ts +1 -0
- package/client/solana/solana.ts +237 -0
- package/client/solana/solana.types.ts +114 -0
- package/constants.ts +4 -0
- package/errors.ts +17 -0
- package/index.ts +4 -0
- package/openapi-client/cdpApiClient.ts +221 -0
- package/openapi-client/errors.ts +132 -0
- package/openapi-client/generated/coinbaseDeveloperPlatformAPIs.schemas.ts +512 -0
- package/openapi-client/generated/evm-accounts/evm-accounts.msw.ts +271 -0
- package/openapi-client/generated/evm-accounts/evm-accounts.ts +194 -0
- package/openapi-client/generated/evm-smart-accounts/evm-smart-accounts.msw.ts +283 -0
- package/openapi-client/generated/evm-smart-accounts/evm-smart-accounts.ts +132 -0
- package/openapi-client/generated/evm-token-balances/evm-token-balances.msw.ts +57 -0
- package/openapi-client/generated/evm-token-balances/evm-token-balances.ts +37 -0
- package/openapi-client/generated/faucets/faucets.msw.ts +76 -0
- package/openapi-client/generated/faucets/faucets.ts +84 -0
- package/openapi-client/generated/index.msw.ts +5 -0
- package/openapi-client/generated/solana-accounts/solana-accounts.msw.ts +219 -0
- package/openapi-client/generated/solana-accounts/solana-accounts.ts +143 -0
- package/openapi-client/index.ts +36 -0
- package/package.json +31 -66
- package/types/calls.ts +40 -0
- package/types/contract.ts +126 -0
- package/types/misc.ts +44 -0
- package/types/multicall.ts +29 -0
- package/types/utils.ts +288 -0
- package/utils/wait.ts +52 -0
- package/version.ts +1 -0
- package/dist/auth/hooks/axios/index.d.ts +0 -1
- package/dist/auth/index.d.ts +0 -4
- package/dist/auth/utils/index.d.ts +0 -2
- package/dist/client/evm/index.d.ts +0 -1
- package/dist/client/evm/index.js +0 -5
- package/dist/client/solana/index.d.ts +0 -1
- package/dist/index.d.ts +0 -3
- package/dist/openapi-client/cdpApiClient.js +0 -146
- package/dist/openapi-client/generated/coinbaseDeveloperPlatformAPIs.schemas.js +0 -54
- package/dist/openapi-client/generated/evm-accounts/evm-accounts.d.ts +0 -62
- package/dist/openapi-client/generated/evm-accounts/evm-accounts.js +0 -85
- package/dist/openapi-client/generated/evm-accounts/evm-accounts.msw.js +0 -113
- package/dist/openapi-client/generated/evm-smart-accounts/evm-smart-accounts.js +0 -66
- package/dist/openapi-client/generated/evm-smart-accounts/evm-smart-accounts.msw.js +0 -99
- package/dist/openapi-client/generated/index.msw.d.ts +0 -4
- package/dist/openapi-client/index.d.ts +0 -55
- package/dist/types/misc.d.ts +0 -3
package/types/misc.ts
ADDED
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
// Adapted from viem (https://github.com/wevm/viem)
|
|
2
|
+
|
|
3
|
+
export type Hex = `0x${string}`;
|
|
4
|
+
export type Hash = `0x${string}`;
|
|
5
|
+
export type Address = `0x${string}`;
|
|
6
|
+
|
|
7
|
+
export type AccessList = readonly {
|
|
8
|
+
address: Address;
|
|
9
|
+
storageKeys: readonly Hex[];
|
|
10
|
+
}[];
|
|
11
|
+
|
|
12
|
+
export type TransactionRequestEIP1559 = {
|
|
13
|
+
/** The address of the contract or account to send the transaction to. */
|
|
14
|
+
to: Address;
|
|
15
|
+
/** The amount of ETH, in wei, to send with the transaction. */
|
|
16
|
+
value?: bigint | undefined;
|
|
17
|
+
/** The data to send with the transaction; only used for contract calls. */
|
|
18
|
+
data?: Hex | undefined;
|
|
19
|
+
/** The amount of gas to use for the transaction. */
|
|
20
|
+
gas?: bigint | undefined;
|
|
21
|
+
/**
|
|
22
|
+
* The nonce to use for the transaction.
|
|
23
|
+
* If not provided, the API will assign a nonce to the transaction based on the current state of the account.
|
|
24
|
+
*/
|
|
25
|
+
nonce?: number | undefined;
|
|
26
|
+
/**
|
|
27
|
+
* The maximum fee per gas to use for the transaction.
|
|
28
|
+
* If not provided, the API will estimate a value based on current network conditions.
|
|
29
|
+
*/
|
|
30
|
+
maxFeePerGas?: bigint | undefined;
|
|
31
|
+
/**
|
|
32
|
+
* The maximum priority fee per gas to use for the transaction.
|
|
33
|
+
* If not provided, the API will estimate a value based on current network conditions.
|
|
34
|
+
*/
|
|
35
|
+
maxPriorityFeePerGas?: bigint | undefined;
|
|
36
|
+
/** The access list to use for the transaction. */
|
|
37
|
+
accessList?: AccessList | undefined;
|
|
38
|
+
/** (Ignored) The value of the `chainId` field in the transaction is ignored. */
|
|
39
|
+
chainId?: number | undefined;
|
|
40
|
+
/** (Ignored) Ignored in favor of the account address that is sending the transaction. */
|
|
41
|
+
from?: Address | undefined;
|
|
42
|
+
/** (Ignored) The transaction type is always `eip1559`. */
|
|
43
|
+
type?: "eip1559" | undefined;
|
|
44
|
+
};
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
// Adapted from viem (https://github.com/wevm/viem)
|
|
2
|
+
import type {
|
|
3
|
+
ContractFunctionArgs,
|
|
4
|
+
ContractFunctionName,
|
|
5
|
+
ContractFunctionParameters,
|
|
6
|
+
} from "./contract.js";
|
|
7
|
+
import type { Abi, AbiStateMutability } from "abitype";
|
|
8
|
+
|
|
9
|
+
// infer contract parameters from `unknown`
|
|
10
|
+
export type GetMulticallContractParameters<
|
|
11
|
+
contract,
|
|
12
|
+
mutability extends AbiStateMutability,
|
|
13
|
+
> = contract extends { abi: infer abi extends Abi } // 1. Check if `abi` is const-asserted or defined inline
|
|
14
|
+
? // 1a. Check if `functionName` is valid for `abi`
|
|
15
|
+
contract extends {
|
|
16
|
+
functionName: infer functionName extends ContractFunctionName<abi, mutability>;
|
|
17
|
+
}
|
|
18
|
+
? // 1aa. Check if `args` is valid for `abi` and `functionName`
|
|
19
|
+
contract extends {
|
|
20
|
+
args: infer args extends ContractFunctionArgs<abi, mutability, functionName>;
|
|
21
|
+
}
|
|
22
|
+
? ContractFunctionParameters<abi, mutability, functionName, args> // `args` valid, pass through
|
|
23
|
+
: ContractFunctionParameters<abi, mutability, functionName> // invalid `args`
|
|
24
|
+
: // 1b. `functionName` is invalid, check if `abi` is declared as `Abi`
|
|
25
|
+
Abi extends abi
|
|
26
|
+
? ContractFunctionParameters // `abi` declared as `Abi`, unable to infer types further
|
|
27
|
+
: // `abi` is const-asserted or defined inline, infer types for `functionName` and `args`
|
|
28
|
+
ContractFunctionParameters<abi, mutability>
|
|
29
|
+
: ContractFunctionParameters<readonly unknown[]>; // invalid `contract['abi']`, set to `readonly unknown[]`
|
package/types/utils.ts
ADDED
|
@@ -0,0 +1,288 @@
|
|
|
1
|
+
/* eslint-disable */
|
|
2
|
+
// Adapted from viem (https://github.com/wevm/viem)
|
|
3
|
+
|
|
4
|
+
/**
|
|
5
|
+
* Filters out all members of {@link T} that are not {@link P}
|
|
6
|
+
*
|
|
7
|
+
* @param T - Items to filter
|
|
8
|
+
* @param P - Type to filter out
|
|
9
|
+
* @returns Filtered items
|
|
10
|
+
*
|
|
11
|
+
* @example
|
|
12
|
+
* type Result = Filter<['a', 'b', 'c'], 'b'>
|
|
13
|
+
* // ^? type Result = ['a', 'c']
|
|
14
|
+
*/
|
|
15
|
+
export type Filter<
|
|
16
|
+
T extends readonly unknown[],
|
|
17
|
+
P,
|
|
18
|
+
Acc extends readonly unknown[] = [],
|
|
19
|
+
> = T extends readonly [infer F, ...infer Rest extends readonly unknown[]]
|
|
20
|
+
? [F] extends [P]
|
|
21
|
+
? Filter<Rest, P, [...Acc, F]>
|
|
22
|
+
: Filter<Rest, P, Acc>
|
|
23
|
+
: readonly [...Acc];
|
|
24
|
+
|
|
25
|
+
/**
|
|
26
|
+
* @description Checks if {@link T} can be narrowed further than {@link U}
|
|
27
|
+
* @param T - Type to check
|
|
28
|
+
* @param U - Type to against
|
|
29
|
+
* @example
|
|
30
|
+
* type Result = IsNarrowable<'foo', string>
|
|
31
|
+
* // ^? true
|
|
32
|
+
*/
|
|
33
|
+
export type IsNarrowable<T, U> =
|
|
34
|
+
IsNever<(T extends U ? true : false) & (U extends T ? false : true)> extends true ? false : true;
|
|
35
|
+
|
|
36
|
+
/**
|
|
37
|
+
* @description Checks if {@link T} is `never`
|
|
38
|
+
* @param T - Type to check
|
|
39
|
+
* @example
|
|
40
|
+
* type Result = IsNever<never>
|
|
41
|
+
* // ^? type Result = true
|
|
42
|
+
*/
|
|
43
|
+
export type IsNever<T> = [T] extends [never] ? true : false;
|
|
44
|
+
|
|
45
|
+
/** Removes `readonly` from all properties of an object. */
|
|
46
|
+
export type Mutable<type extends object> = {
|
|
47
|
+
-readonly [key in keyof type]: type[key];
|
|
48
|
+
};
|
|
49
|
+
|
|
50
|
+
/**
|
|
51
|
+
* @description Evaluates boolean "or" condition for {@link T} properties.
|
|
52
|
+
* @param T - Type to check
|
|
53
|
+
*
|
|
54
|
+
* @example
|
|
55
|
+
* type Result = Or<[false, true, false]>
|
|
56
|
+
* // ^? type Result = true
|
|
57
|
+
*
|
|
58
|
+
* @example
|
|
59
|
+
* type Result = Or<[false, false, false]>
|
|
60
|
+
* // ^? type Result = false
|
|
61
|
+
*/
|
|
62
|
+
export type Or<T extends readonly unknown[]> = T extends readonly [infer Head, ...infer Tail]
|
|
63
|
+
? Head extends true
|
|
64
|
+
? true
|
|
65
|
+
: Or<Tail>
|
|
66
|
+
: false;
|
|
67
|
+
|
|
68
|
+
/**
|
|
69
|
+
* @description Checks if {@link T} is `undefined`
|
|
70
|
+
* @param T - Type to check
|
|
71
|
+
* @example
|
|
72
|
+
* type Result = IsUndefined<undefined>
|
|
73
|
+
* // ^? type Result = true
|
|
74
|
+
*/
|
|
75
|
+
export type IsUndefined<T> = [undefined] extends [T] ? true : false;
|
|
76
|
+
|
|
77
|
+
export type MaybePromise<T> = T | Promise<T>;
|
|
78
|
+
|
|
79
|
+
/**
|
|
80
|
+
* @description Makes attributes on the type T required if required is true.
|
|
81
|
+
*
|
|
82
|
+
* @example
|
|
83
|
+
* MaybeRequired<{ a: string, b?: number }, true>
|
|
84
|
+
* => { a: string, b: number }
|
|
85
|
+
*
|
|
86
|
+
* MaybeRequired<{ a: string, b?: number }, false>
|
|
87
|
+
* => { a: string, b?: number }
|
|
88
|
+
*/
|
|
89
|
+
export type MaybeRequired<T, required extends boolean> = required extends true
|
|
90
|
+
? ExactRequired<T>
|
|
91
|
+
: T;
|
|
92
|
+
|
|
93
|
+
/**
|
|
94
|
+
* @description Assigns the properties of U onto T.
|
|
95
|
+
*
|
|
96
|
+
* @example
|
|
97
|
+
* Assign<{ a: string, b: number }, { a: undefined, c: boolean }>
|
|
98
|
+
* => { a: undefined, b: number, c: boolean }
|
|
99
|
+
*/
|
|
100
|
+
export type Assign<T, U> = Assign_<T, U> & U;
|
|
101
|
+
type Assign_<T, U> = {
|
|
102
|
+
[K in keyof T as K extends keyof U ? (U[K] extends void ? never : K) : K]: K extends keyof U
|
|
103
|
+
? U[K]
|
|
104
|
+
: T[K];
|
|
105
|
+
};
|
|
106
|
+
|
|
107
|
+
// TODO: Remove when peer dep `typescript@>=4.5` (NoInfer is native)
|
|
108
|
+
export type NoInfer<type> = [type][type extends any ? 0 : never];
|
|
109
|
+
|
|
110
|
+
/**
|
|
111
|
+
* @description Constructs a type by excluding `undefined` from `T`.
|
|
112
|
+
*
|
|
113
|
+
* @example
|
|
114
|
+
* NoUndefined<string | undefined>
|
|
115
|
+
* => string
|
|
116
|
+
*
|
|
117
|
+
* @internal
|
|
118
|
+
*/
|
|
119
|
+
export type NoUndefined<T> = T extends undefined ? never : T;
|
|
120
|
+
|
|
121
|
+
/** Strict version of built-in Omit type */
|
|
122
|
+
export type Omit<type, keys extends keyof type> = Pick<type, Exclude<keyof type, keys>>;
|
|
123
|
+
|
|
124
|
+
/**
|
|
125
|
+
* @description Creates a type that is a partial of T, but with the required keys K.
|
|
126
|
+
*
|
|
127
|
+
* @example
|
|
128
|
+
* PartialBy<{ a: string, b: number }, 'a'>
|
|
129
|
+
* => { a?: string, b: number }
|
|
130
|
+
*/
|
|
131
|
+
export type PartialBy<T, K extends keyof T> = Omit<T, K> & ExactPartial<Pick<T, K>>;
|
|
132
|
+
|
|
133
|
+
/**
|
|
134
|
+
* @description Combines members of an intersection into a readable type.
|
|
135
|
+
*
|
|
136
|
+
* @see {@link https://twitter.com/mattpocockuk/status/1622730173446557697?s=20&t=NdpAcmEFXY01xkqU3KO0Mg}
|
|
137
|
+
* @example
|
|
138
|
+
* Prettify<{ a: string } & { b: string } & { c: number, d: bigint }>
|
|
139
|
+
* => { a: string, b: string, c: number, d: bigint }
|
|
140
|
+
*/
|
|
141
|
+
export type Prettify<T> = {
|
|
142
|
+
[K in keyof T]: T[K];
|
|
143
|
+
} & {};
|
|
144
|
+
|
|
145
|
+
/** @internal */
|
|
146
|
+
export type Evaluate<type> = {
|
|
147
|
+
[key in keyof type]: type[key];
|
|
148
|
+
} & {};
|
|
149
|
+
|
|
150
|
+
/**
|
|
151
|
+
* @description Creates a type that is T with the required keys K.
|
|
152
|
+
*
|
|
153
|
+
* @example
|
|
154
|
+
* RequiredBy<{ a?: string, b: number }, 'a'>
|
|
155
|
+
* => { a: string, b: number }
|
|
156
|
+
*/
|
|
157
|
+
export type RequiredBy<T, K extends keyof T> = Omit<T, K> & ExactRequired<Pick<T, K>>;
|
|
158
|
+
|
|
159
|
+
/**
|
|
160
|
+
* @description Returns truthy if `array` contains `value`.
|
|
161
|
+
*
|
|
162
|
+
* @example
|
|
163
|
+
* Some<[1, 2, 3], 2>
|
|
164
|
+
* => true
|
|
165
|
+
*/
|
|
166
|
+
export type Some<array extends readonly unknown[], value> = array extends readonly [
|
|
167
|
+
value,
|
|
168
|
+
...unknown[],
|
|
169
|
+
]
|
|
170
|
+
? true
|
|
171
|
+
: array extends readonly [unknown, ...infer rest]
|
|
172
|
+
? Some<rest, value>
|
|
173
|
+
: false;
|
|
174
|
+
|
|
175
|
+
/**
|
|
176
|
+
* @description Creates a type that extracts the values of T.
|
|
177
|
+
*
|
|
178
|
+
* @example
|
|
179
|
+
* ValueOf<{ a: string, b: number }>
|
|
180
|
+
* => string | number
|
|
181
|
+
*
|
|
182
|
+
* @internal
|
|
183
|
+
*/
|
|
184
|
+
export type ValueOf<T> = T[keyof T];
|
|
185
|
+
|
|
186
|
+
export type UnionToTuple<
|
|
187
|
+
union,
|
|
188
|
+
///
|
|
189
|
+
last = LastInUnion<union>,
|
|
190
|
+
> = [union] extends [never] ? [] : [...UnionToTuple<Exclude<union, last>>, last];
|
|
191
|
+
type LastInUnion<U> =
|
|
192
|
+
UnionToIntersection<U extends unknown ? (x: U) => 0 : never> extends (x: infer l) => 0
|
|
193
|
+
? l
|
|
194
|
+
: never;
|
|
195
|
+
type UnionToIntersection<union> = (union extends unknown ? (arg: union) => 0 : never) extends (
|
|
196
|
+
arg: infer i,
|
|
197
|
+
) => 0
|
|
198
|
+
? i
|
|
199
|
+
: never;
|
|
200
|
+
|
|
201
|
+
export type IsUnion<
|
|
202
|
+
union,
|
|
203
|
+
///
|
|
204
|
+
union2 = union,
|
|
205
|
+
> = union extends union2 ? ([union2] extends [union] ? false : true) : never;
|
|
206
|
+
|
|
207
|
+
export type MaybePartial<type, enabled extends boolean | undefined> = enabled extends true
|
|
208
|
+
? Prettify<ExactPartial<type>>
|
|
209
|
+
: type;
|
|
210
|
+
|
|
211
|
+
export type ExactPartial<type> = {
|
|
212
|
+
[key in keyof type]?: type[key] | undefined;
|
|
213
|
+
};
|
|
214
|
+
|
|
215
|
+
export type ExactRequired<type> = {
|
|
216
|
+
[P in keyof type]-?: Exclude<type[P], undefined>;
|
|
217
|
+
};
|
|
218
|
+
|
|
219
|
+
export type OneOf<
|
|
220
|
+
union extends object,
|
|
221
|
+
fallback extends object | undefined = undefined,
|
|
222
|
+
///
|
|
223
|
+
keys extends KeyofUnion<union> = KeyofUnion<union>,
|
|
224
|
+
> = union extends infer item
|
|
225
|
+
? Prettify<
|
|
226
|
+
item & {
|
|
227
|
+
[key in Exclude<keys, keyof item>]?: fallback extends object
|
|
228
|
+
? key extends keyof fallback
|
|
229
|
+
? fallback[key]
|
|
230
|
+
: undefined
|
|
231
|
+
: undefined;
|
|
232
|
+
}
|
|
233
|
+
>
|
|
234
|
+
: never;
|
|
235
|
+
type KeyofUnion<type> = type extends type ? keyof type : never;
|
|
236
|
+
|
|
237
|
+
///////////////////////////////////////////////////////////////////////////
|
|
238
|
+
// Loose types
|
|
239
|
+
|
|
240
|
+
/**
|
|
241
|
+
* Loose version of {@link Omit}
|
|
242
|
+
*
|
|
243
|
+
* @internal
|
|
244
|
+
*/
|
|
245
|
+
export type LooseOmit<type, keys extends string> = Pick<type, Exclude<keyof type, keys>>;
|
|
246
|
+
|
|
247
|
+
///////////////////////////////////////////////////////////////////////////
|
|
248
|
+
// Union types
|
|
249
|
+
|
|
250
|
+
export type UnionEvaluate<type> = type extends object ? Prettify<type> : type;
|
|
251
|
+
|
|
252
|
+
export type UnionLooseOmit<type, keys extends string> = type extends any
|
|
253
|
+
? LooseOmit<type, keys>
|
|
254
|
+
: never;
|
|
255
|
+
|
|
256
|
+
/**
|
|
257
|
+
* @description Construct a type with the properties of union type T except for those in type K.
|
|
258
|
+
* @example
|
|
259
|
+
* type Result = UnionOmit<{ a: string, b: number } | { a: string, b: undefined, c: number }, 'a'>
|
|
260
|
+
* => { b: number } | { b: undefined, c: number }
|
|
261
|
+
*/
|
|
262
|
+
export type UnionOmit<type, keys extends keyof type> = type extends any ? Omit<type, keys> : never;
|
|
263
|
+
|
|
264
|
+
/**
|
|
265
|
+
* @description Construct a type with the properties of union type T except for those in type K.
|
|
266
|
+
* @example
|
|
267
|
+
* type Result = UnionOmit<{ a: string, b: number } | { a: string, b: undefined, c: number }, 'a'>
|
|
268
|
+
* => { b: number } | { b: undefined, c: number }
|
|
269
|
+
*/
|
|
270
|
+
export type UnionPick<type, keys extends keyof type> = type extends any ? Pick<type, keys> : never;
|
|
271
|
+
|
|
272
|
+
/**
|
|
273
|
+
* @description Creates a type that is a partial of T, but with the required keys K.
|
|
274
|
+
*
|
|
275
|
+
* @example
|
|
276
|
+
* PartialBy<{ a: string, b: number } | { a: string, b: undefined, c: number }, 'a'>
|
|
277
|
+
* => { a?: string, b: number } | { a?: string, b: undefined, c: number }
|
|
278
|
+
*/
|
|
279
|
+
export type UnionPartialBy<T, K extends keyof T> = T extends any ? PartialBy<T, K> : never;
|
|
280
|
+
|
|
281
|
+
/**
|
|
282
|
+
* @description Creates a type that is T with the required keys K.
|
|
283
|
+
*
|
|
284
|
+
* @example
|
|
285
|
+
* RequiredBy<{ a?: string, b: number } | { a?: string, c?: number }, 'a'>
|
|
286
|
+
* => { a: string, b: number } | { a: string, c?: number }
|
|
287
|
+
*/
|
|
288
|
+
export type UnionRequiredBy<T, K extends keyof T> = T extends any ? RequiredBy<T, K> : never;
|
package/utils/wait.ts
ADDED
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
import { TimeoutError } from "../errors.js";
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* Options for the wait function
|
|
5
|
+
*/
|
|
6
|
+
export type WaitOptions = {
|
|
7
|
+
/** Interval between retries in seconds. Defaults to 0.2 */
|
|
8
|
+
intervalSeconds?: number;
|
|
9
|
+
/** Maximum time to wait before timing out in seconds. Defaults to 10 */
|
|
10
|
+
timeoutSeconds?: number;
|
|
11
|
+
};
|
|
12
|
+
|
|
13
|
+
/**
|
|
14
|
+
* Polls a resource until a terminal condition is met or timeout occurs.
|
|
15
|
+
*
|
|
16
|
+
* @param reload - Function that fetches the latest state of the resource
|
|
17
|
+
* @param isTerminal - Function that determines if the current state is terminal
|
|
18
|
+
* @param transform - Function that transforms the resource into a new type
|
|
19
|
+
* @param options - Configuration options for polling behavior
|
|
20
|
+
* @returns The resource in its terminal state
|
|
21
|
+
* @throws {TimeoutError} If the operation exceeds the timeout duration
|
|
22
|
+
*
|
|
23
|
+
* @example
|
|
24
|
+
* const result = await wait(
|
|
25
|
+
* () => fetchOrderStatus(orderId),
|
|
26
|
+
* (status) => status === 'completed',
|
|
27
|
+
* (status) => status === 'completed' ? { status } : undefined,
|
|
28
|
+
* { timeoutSeconds: 30 }
|
|
29
|
+
* );
|
|
30
|
+
*/
|
|
31
|
+
export async function wait<T, K = T>(
|
|
32
|
+
reload: () => Promise<T>,
|
|
33
|
+
isTerminal: (obj: T) => boolean,
|
|
34
|
+
transform: (obj: T) => K = (obj: T) => obj as unknown as K,
|
|
35
|
+
options: WaitOptions = {},
|
|
36
|
+
): Promise<K> {
|
|
37
|
+
const { intervalSeconds = 0.2, timeoutSeconds = 10 } = options;
|
|
38
|
+
const startTime = Date.now();
|
|
39
|
+
|
|
40
|
+
while (Date.now() - startTime < timeoutSeconds * 1000) {
|
|
41
|
+
const updatedObject = await reload();
|
|
42
|
+
|
|
43
|
+
if (isTerminal(updatedObject)) {
|
|
44
|
+
return transform(updatedObject);
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
await new Promise(resolve => setTimeout(resolve, intervalSeconds * 1000));
|
|
48
|
+
}
|
|
49
|
+
throw new TimeoutError(
|
|
50
|
+
`Operation has not reached a terminal state after ${timeoutSeconds} seconds and may still succeed. Retry with a longer timeout using the timeoutSeconds option.`,
|
|
51
|
+
);
|
|
52
|
+
}
|
package/version.ts
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export const version = "1.3.0";
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export * from "./withAuth";
|
package/dist/auth/index.d.ts
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export { EvmClient } from "./evm";
|
package/dist/client/evm/index.js
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export { SolanaClient } from "./solana";
|
package/dist/index.d.ts
DELETED
|
@@ -1,146 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
-
if (k2 === undefined) k2 = k;
|
|
4
|
-
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
-
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
-
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
-
}
|
|
8
|
-
Object.defineProperty(o, k2, desc);
|
|
9
|
-
}) : (function(o, m, k, k2) {
|
|
10
|
-
if (k2 === undefined) k2 = k;
|
|
11
|
-
o[k2] = m[k];
|
|
12
|
-
}));
|
|
13
|
-
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
14
|
-
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
15
|
-
}) : function(o, v) {
|
|
16
|
-
o["default"] = v;
|
|
17
|
-
});
|
|
18
|
-
var __importStar = (this && this.__importStar) || (function () {
|
|
19
|
-
var ownKeys = function(o) {
|
|
20
|
-
ownKeys = Object.getOwnPropertyNames || function (o) {
|
|
21
|
-
var ar = [];
|
|
22
|
-
for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
|
|
23
|
-
return ar;
|
|
24
|
-
};
|
|
25
|
-
return ownKeys(o);
|
|
26
|
-
};
|
|
27
|
-
return function (mod) {
|
|
28
|
-
if (mod && mod.__esModule) return mod;
|
|
29
|
-
var result = {};
|
|
30
|
-
if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
|
|
31
|
-
__setModuleDefault(result, mod);
|
|
32
|
-
return result;
|
|
33
|
-
};
|
|
34
|
-
})();
|
|
35
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
36
|
-
exports.cdpApiClient = exports.configure = void 0;
|
|
37
|
-
const axios_1 = __importStar(require("axios"));
|
|
38
|
-
const axios_2 = require("../auth/hooks/axios");
|
|
39
|
-
const errors_1 = require("./errors");
|
|
40
|
-
const constants_1 = require("../constants");
|
|
41
|
-
let axiosInstance;
|
|
42
|
-
/**
|
|
43
|
-
* Configures the CDP client with the given options.
|
|
44
|
-
*
|
|
45
|
-
* @param {CdpOptions} options - The CDP options.
|
|
46
|
-
*/
|
|
47
|
-
const configure = (options) => {
|
|
48
|
-
axiosInstance = axios_1.default.create({
|
|
49
|
-
baseURL: options.basePath || "https://api.cdp.coinbase.com/platform",
|
|
50
|
-
});
|
|
51
|
-
axiosInstance = (0, axios_2.withAuth)(axiosInstance, {
|
|
52
|
-
apiKeyId: options.apiKeyId,
|
|
53
|
-
apiKeySecret: options.apiKeySecret,
|
|
54
|
-
source: options.source || "sdk-openapi-client",
|
|
55
|
-
sourceVersion: options.sourceVersion,
|
|
56
|
-
walletSecret: options.walletSecret,
|
|
57
|
-
expiresIn: options.expiresIn,
|
|
58
|
-
debug: options.debugging,
|
|
59
|
-
});
|
|
60
|
-
};
|
|
61
|
-
exports.configure = configure;
|
|
62
|
-
/**
|
|
63
|
-
* Adds an idempotency key to request config if provided
|
|
64
|
-
*
|
|
65
|
-
* @param config - The Axios request configuration.
|
|
66
|
-
* @param idempotencyKey - The idempotency key.
|
|
67
|
-
* @returns The Axios request configuration with the idempotency key.
|
|
68
|
-
*/
|
|
69
|
-
const addIdempotencyKey = (config, idempotencyKey) => {
|
|
70
|
-
if (!idempotencyKey) {
|
|
71
|
-
return config;
|
|
72
|
-
}
|
|
73
|
-
return {
|
|
74
|
-
...config,
|
|
75
|
-
headers: {
|
|
76
|
-
...(config.headers || {}),
|
|
77
|
-
"X-Idempotency-Key": idempotencyKey,
|
|
78
|
-
},
|
|
79
|
-
};
|
|
80
|
-
};
|
|
81
|
-
/**
|
|
82
|
-
* Mutates the given Axios request configuration to add the CDP API key signature
|
|
83
|
-
* to the request headers.
|
|
84
|
-
*
|
|
85
|
-
* @param {AxiosRequestConfig} config - The Axios request configuration.
|
|
86
|
-
* @param idempotencyKey - The idempotency key.
|
|
87
|
-
* @returns {Promise<T>} A promise that resolves to the response data.
|
|
88
|
-
* @throws {APIError} If the request fails.
|
|
89
|
-
*/
|
|
90
|
-
const cdpApiClient = async (config, idempotencyKey) => {
|
|
91
|
-
validateCall(config);
|
|
92
|
-
// Add idempotency key to the request headers if provided
|
|
93
|
-
const configWithIdempotencyKey = addIdempotencyKey(config, idempotencyKey);
|
|
94
|
-
try {
|
|
95
|
-
const response = await axiosInstance(configWithIdempotencyKey);
|
|
96
|
-
return response.data;
|
|
97
|
-
}
|
|
98
|
-
catch (error) {
|
|
99
|
-
if (axios_1.default.isAxiosError(error) && error.response) {
|
|
100
|
-
if ((0, errors_1.isOpenAPIError)(error.response.data)) {
|
|
101
|
-
throw new errors_1.APIError(error.response.status, error.response.data.errorType, error.response.data.errorMessage, error.response.data.correlationId, error.response.data.errorLink);
|
|
102
|
-
}
|
|
103
|
-
else {
|
|
104
|
-
const statusCode = error.response.status;
|
|
105
|
-
switch (statusCode) {
|
|
106
|
-
case 401:
|
|
107
|
-
throw new errors_1.APIError(statusCode, errors_1.HttpErrorType.unauthorized, "Unauthorized.", undefined, `${constants_1.ERROR_DOCS_PAGE_URL}#unauthorized`);
|
|
108
|
-
case 404:
|
|
109
|
-
throw new errors_1.APIError(statusCode, errors_1.HttpErrorType.not_found, "API not found.", undefined, `${constants_1.ERROR_DOCS_PAGE_URL}#not_found`);
|
|
110
|
-
case 502:
|
|
111
|
-
throw new errors_1.APIError(statusCode, errors_1.HttpErrorType.bad_gateway, "Bad gateway.", undefined, `${constants_1.ERROR_DOCS_PAGE_URL}`);
|
|
112
|
-
case 503:
|
|
113
|
-
throw new errors_1.APIError(statusCode, errors_1.HttpErrorType.service_unavailable, "Service unavailable. Please try again later.", undefined, `${constants_1.ERROR_DOCS_PAGE_URL}`);
|
|
114
|
-
default:
|
|
115
|
-
throw new errors_1.APIError(statusCode, errors_1.HttpErrorType.unexpected_error, "An unexpected error occurred.", undefined, `${constants_1.ERROR_DOCS_PAGE_URL}`);
|
|
116
|
-
}
|
|
117
|
-
}
|
|
118
|
-
}
|
|
119
|
-
else if (axios_1.default.isAxiosError(error) && error.request) {
|
|
120
|
-
throw new errors_1.APIError(axios_1.HttpStatusCode.ServiceUnavailable, errors_1.HttpErrorType.service_unavailable, "Network error, unable to reach the service.", undefined, `${constants_1.ERROR_DOCS_PAGE_URL}`);
|
|
121
|
-
}
|
|
122
|
-
else {
|
|
123
|
-
throw new errors_1.APIError(axios_1.HttpStatusCode.InternalServerError, errors_1.HttpErrorType.unexpected_error, error instanceof Error
|
|
124
|
-
? error.message
|
|
125
|
-
: `An unexpected error occurred: ${JSON.stringify(error, Object.getOwnPropertyNames(error))}`, undefined, `${constants_1.ERROR_DOCS_PAGE_URL}`);
|
|
126
|
-
}
|
|
127
|
-
}
|
|
128
|
-
};
|
|
129
|
-
exports.cdpApiClient = cdpApiClient;
|
|
130
|
-
/**
|
|
131
|
-
* Validates the call to the cdpApiClient.
|
|
132
|
-
*
|
|
133
|
-
* @param {AxiosRequestConfig} config - The Axios request configuration.
|
|
134
|
-
* @throws {Error} If the call is not valid.
|
|
135
|
-
*/
|
|
136
|
-
const validateCall = (config) => {
|
|
137
|
-
if (!axiosInstance.getUri() || axiosInstance.getUri() === "") {
|
|
138
|
-
throw new Error("CDP client URI not configured. Call configure() first.");
|
|
139
|
-
}
|
|
140
|
-
if (!config.url || config.url === "") {
|
|
141
|
-
throw new Error("AxiosRequestConfig URL is empty. This should never happen.");
|
|
142
|
-
}
|
|
143
|
-
if (!config.method || config.method === "") {
|
|
144
|
-
throw new Error("AxiosRequestConfig method is empty. This should never happen.");
|
|
145
|
-
}
|
|
146
|
-
};
|
|
@@ -1,54 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.RequestSolanaFaucetBodyToken = exports.RequestEvmFaucetBodyToken = exports.RequestEvmFaucetBodyNetwork = exports.PrepareUserOperationBodyNetwork = exports.EvmUserOperationStatus = exports.EvmUserOperationNetwork = exports.ErrorType = void 0;
|
|
4
|
-
// eslint-disable-next-line @typescript-eslint/no-redeclare
|
|
5
|
-
exports.ErrorType = {
|
|
6
|
-
already_exists: 'already_exists',
|
|
7
|
-
faucet_limit_exceeded: 'faucet_limit_exceeded',
|
|
8
|
-
forbidden: 'forbidden',
|
|
9
|
-
idempotency_error: 'idempotency_error',
|
|
10
|
-
internal_server_error: 'internal_server_error',
|
|
11
|
-
invalid_request: 'invalid_request',
|
|
12
|
-
invalid_signature: 'invalid_signature',
|
|
13
|
-
malformed_transaction: 'malformed_transaction',
|
|
14
|
-
not_found: 'not_found',
|
|
15
|
-
rate_limit_exceeded: 'rate_limit_exceeded',
|
|
16
|
-
request_canceled: 'request_canceled',
|
|
17
|
-
timed_out: 'timed_out',
|
|
18
|
-
unauthorized: 'unauthorized',
|
|
19
|
-
};
|
|
20
|
-
// eslint-disable-next-line @typescript-eslint/no-redeclare
|
|
21
|
-
exports.EvmUserOperationNetwork = {
|
|
22
|
-
'base-sepolia': 'base-sepolia',
|
|
23
|
-
base: 'base',
|
|
24
|
-
};
|
|
25
|
-
// eslint-disable-next-line @typescript-eslint/no-redeclare
|
|
26
|
-
exports.EvmUserOperationStatus = {
|
|
27
|
-
pending: 'pending',
|
|
28
|
-
signed: 'signed',
|
|
29
|
-
broadcast: 'broadcast',
|
|
30
|
-
complete: 'complete',
|
|
31
|
-
failed: 'failed',
|
|
32
|
-
};
|
|
33
|
-
// eslint-disable-next-line @typescript-eslint/no-redeclare
|
|
34
|
-
exports.PrepareUserOperationBodyNetwork = {
|
|
35
|
-
'base-sepolia': 'base-sepolia',
|
|
36
|
-
base: 'base',
|
|
37
|
-
};
|
|
38
|
-
// eslint-disable-next-line @typescript-eslint/no-redeclare
|
|
39
|
-
exports.RequestEvmFaucetBodyNetwork = {
|
|
40
|
-
'base-sepolia': 'base-sepolia',
|
|
41
|
-
'ethereum-sepolia': 'ethereum-sepolia',
|
|
42
|
-
};
|
|
43
|
-
// eslint-disable-next-line @typescript-eslint/no-redeclare
|
|
44
|
-
exports.RequestEvmFaucetBodyToken = {
|
|
45
|
-
eth: 'eth',
|
|
46
|
-
usdc: 'usdc',
|
|
47
|
-
eurc: 'eurc',
|
|
48
|
-
cbbtc: 'cbbtc',
|
|
49
|
-
};
|
|
50
|
-
// eslint-disable-next-line @typescript-eslint/no-redeclare
|
|
51
|
-
exports.RequestSolanaFaucetBodyToken = {
|
|
52
|
-
sol: 'sol',
|
|
53
|
-
usdc: 'usdc',
|
|
54
|
-
};
|