@klappay/types 3.0.1 → 3.1.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/dist/index.mjs CHANGED
@@ -1,3 +1,15 @@
1
+ import {
2
+ ALT_TOKEN_ADDRESSES,
3
+ ALT_TOKEN_DECIMALS,
4
+ CHAIN_IDS,
5
+ EVM_NETWORKS,
6
+ NETWORK_EXPLORERS,
7
+ NETWORK_LABELS,
8
+ OPERATIONAL_NETWORKS,
9
+ TOKEN_ADDRESSES,
10
+ TOKEN_DECIMALS
11
+ } from "./chunk-KZ3646WX.mjs";
12
+
1
13
  // src/errors.ts
2
14
  import { z } from "zod";
3
15
  var ErrorPayloadSchema = z.object({
@@ -54,42 +66,6 @@ function findConflictingScopes(scopes) {
54
66
  // src/networks.ts
55
67
  import { z as z4 } from "zod";
56
68
  var NetworkSchema = z4.enum(["base", "optimism", "polygon", "ethereum", "arbitrum", "avalanche", "bnb"]).describe("The blockchain a charge/payment is on.");
57
- var NETWORK_LABELS = {
58
- base: "Base",
59
- optimism: "Optimism",
60
- polygon: "Polygon",
61
- ethereum: "Ethereum",
62
- arbitrum: "Arbitrum",
63
- avalanche: "Avalanche",
64
- bnb: "BNB Chain"
65
- };
66
- var NETWORK_EXPLORERS = {
67
- base: "https://basescan.org",
68
- optimism: "https://optimistic.etherscan.io",
69
- polygon: "https://polygonscan.com",
70
- ethereum: "https://etherscan.io",
71
- arbitrum: "https://arbiscan.io",
72
- avalanche: "https://snowtrace.io",
73
- bnb: "https://bscscan.com"
74
- };
75
- var EVM_NETWORKS = [
76
- "base",
77
- "optimism",
78
- "polygon",
79
- "ethereum",
80
- "arbitrum",
81
- "avalanche",
82
- "bnb"
83
- ];
84
- var OPERATIONAL_NETWORKS = [
85
- "base",
86
- "arbitrum",
87
- "optimism",
88
- "polygon",
89
- "ethereum",
90
- "avalanche",
91
- "bnb"
92
- ];
93
69
 
94
70
  // src/pagination.ts
95
71
  import { z as z5 } from "zod";
@@ -117,66 +93,26 @@ import { z as z6 } from "zod";
117
93
  var TokenSchema = z6.enum(["USDC", "USDT"]).describe(
118
94
  `Which stablecoin the payer will send. Support depends on both \`network\` and \`environment\` \u2014 not every token/network/environment combination is deployed; today, both \`USDC\` and \`USDT\` are deployed on every operational network's \`live\` side except BNB Chain (\`${OPERATIONAL_NETWORKS.join(", ")}\`), but \`test\` coverage varies per network \u2014 Base, Optimism, and Ethereum each have a \`test\` environment (\`USDC\` only; none has an official Sepolia USDT), Arbitrum, Polygon, Avalanche, and BNB Chain have none yet (0xSplits hasn't deployed on Arbitrum Sepolia and has no Polygon, Avalanche Fuji, or BNB testnet support at all). An unconfigured combination is rejected with \`422 token_not_supported\`, not silently accepted. **BNB Chain's \`USDC\` address is Binance-Peg USDC, not an official Circle deployment** \u2014 Circle does not issue native USDC on BNB Chain at all; this is a Binance-custodied, 1:1-pegged BEP-20 token, a materially different trust model than every other \`TOKEN_ADDRESSES\` entry (all verified directly against their real issuer). Accepted at the payer's own risk \u2014 Klappay does not verify or guarantee Binance's collateral backing it. \`USDT\` on BNB Chain is Tether's own official issuance, same trust model as everywhere else. More tokens/networks are expected to be added over time \u2014 check \`TOKEN_ADDRESSES\` in \`@klappay/types\` (or a future \`GET /v1/networks\` capabilities endpoint) for the exact current matrix rather than assuming full coverage.`
119
95
  );
120
- var TOKEN_DECIMALS = 6;
121
- var TOKEN_ADDRESSES = {
122
- USDC: {
123
- base: {
124
- live: "0x833589fCD6eDb6E08f4c7C32D4f71b54bdA02913",
125
- test: "0x036CbD53842c5426634e7929541eC2318f3dCF7e"
126
- },
127
- optimism: {
128
- live: "0x0b2C639c533813f4Aa9D7837CAf62653d097Ff85",
129
- test: "0x5fd84259d66Cd46123540766Be93DFE6D43130D7"
130
- },
131
- polygon: { live: "0x3c499c542cEF5E3811e1192ce70d8cC03d5c3359" },
132
- ethereum: {
133
- live: "0xA0b86991c6218b36c1d19D4a2e9Eb0cE3606eB48",
134
- test: "0x1c7D4B196Cb0C7B01d743Fbc6116a902379C7238"
135
- },
136
- arbitrum: { live: "0xaf88d065e77c8cC2239327C5EDb3A432268e5831" },
137
- avalanche: { live: "0xB97EF9Ef8734C71904D8002F8b6Bc66Dd9c48a6E" },
138
- bnb: { live: "0x8AC76a51cc950d9822D68b83fE1Ad97B32Cd580d" }
139
- },
140
- USDT: {
141
- base: { live: "0xfde4C96c8593536E31F229EA8f37b2ADa2699bb2" },
142
- optimism: { live: "0x94b008aA00579c1307B0EF2c499aD98a8ce58e58" },
143
- polygon: { live: "0xc2132D05D31c914a87C6611C10748AEb04B58e8F" },
144
- ethereum: { live: "0xdAC17F958D2ee523a2206206994597C13D831ec7" },
145
- arbitrum: { live: "0xFd086bC7CD5C481DCC9C85ebE478A1C0b69FCbb9" },
146
- avalanche: { live: "0x9702230A8Ea53601f5cD2dc00fDBc13d4dF4A8c7" },
147
- bnb: { live: "0x55d398326f99059fF775485246999027B3197955" }
148
- }
149
- };
150
96
 
151
97
  // src/alt-tokens.ts
152
98
  import { z as z7 } from "zod";
153
99
  var AltTokenSchema = z7.enum(["ETH", "BNB", "MATIC", "AVAX", "BTC"]).describe(
154
100
  "A non-stablecoin cryptocurrency Klappay trusts as swap input for a charge, via the 0x Swap API \u2014 swapped to one of the charge's `acceptedPayments` tokens before it ever reaches the merchant, so the merchant always receives USDC/USDT regardless of what the payer sent. Only a network's own native currency, plus `BTC` (wrapped) on the networks with deep, reputably-custodied liquidity, is trusted today (see `ALT_TOKEN_ADDRESSES`) \u2014 never assume every value here is available on every network."
155
101
  );
156
- var ALT_TOKEN_DECIMALS = {
157
- ETH: 18,
158
- BNB: 18,
159
- MATIC: 18,
160
- AVAX: 18,
161
- BTC: 8
162
- };
163
- var ALT_TOKEN_ADDRESSES = {
164
- base: { ETH: "native", BTC: "0xcbB7C0000aB88B473b1f5aFd9ef808440eed33Bf" },
165
- optimism: { ETH: "native", BTC: "0x68f180fcCe6836688e9084f035309E29Bf0A2095" },
166
- ethereum: { ETH: "native", BTC: "0x2260FAC5E5542a773Aa44fBCfeDf7C193bc2C599" },
167
- arbitrum: { ETH: "native", BTC: "0x2f2a2543B76A4166549F7aaB2e75Bef0aefC5B0f" },
168
- polygon: { MATIC: "native", BTC: "0x1BFD67037B42Cf73acF2047067bd4F2C47D9BfD6" },
169
- avalanche: { AVAX: "native" },
170
- bnb: { BNB: "native" }
171
- };
172
- function listAltTokensForNetworks(networks) {
173
- const found = /* @__PURE__ */ new Set();
174
- for (const network of networks) {
102
+ var SwapAlternativeSchema = z7.object({
103
+ token: AltTokenSchema,
104
+ network: NetworkSchema.describe(
105
+ "Which network to send `token` on \u2014 pass both as `inputToken`/`inputNetwork` to `POST /v1/charges/{id}/quote`. The same token can appear more than once here, once per network that trusts it and that this charge accepts payment on."
106
+ )
107
+ });
108
+ function listSwapAlternatives(networks) {
109
+ const alternatives = [];
110
+ for (const network of new Set(networks)) {
175
111
  for (const token of Object.keys(ALT_TOKEN_ADDRESSES[network] ?? {})) {
176
- found.add(token);
112
+ alternatives.push({ token, network });
177
113
  }
178
114
  }
179
- return [...found];
115
+ return alternatives;
180
116
  }
181
117
 
182
118
  // src/charges.ts
@@ -317,8 +253,8 @@ var ChargeSchema = z9.object({
317
253
  paidWith: z9.array(AcceptedPaymentSchema).describe(
318
254
  "Every distinct `(token, network)` pair that has actually contributed a credited transfer so far \u2014 empty until the first one arrives. Can hold more than one entry: a charge accepting several pairs can be paid across a combination of them, and every entry here sums toward `amountReceived`."
319
255
  ),
320
- swapAlternatives: z9.array(AltTokenSchema).describe(
321
- "Non-stablecoin cryptocurrencies the payer can pay with instead, via `POST /v1/charges/{id}/quote` \u2014 derived from the networks in `acceptedPayments` (e.g. a charge accepting USDC on Base lists `ETH` here, since Base's native currency is trusted as swap input). Recomputed on every read against Klappay's current trusted list, not frozen at creation \u2014 empty if this charge's networks have no trusted alt-token, or if swap-to-pay isn't configured on this deployment."
256
+ swapAlternatives: z9.array(SwapAlternativeSchema).describe(
257
+ "Every `(token, network)` pair the payer can pay with instead, via `POST /v1/charges/{id}/quote` \u2014 derived from the networks in `acceptedPayments` (e.g. a charge accepting USDC on both Base and Optimism lists `ETH` on Base and `ETH` on Optimism separately, since they're different networks the payer has to choose between, not one merged option). Pass an entry's `token`/`network` straight through as `inputToken`/`inputNetwork`. Recomputed on every read against Klappay's current trusted list, not frozen at creation \u2014 empty if this charge's networks have no trusted alt-token, if swap-to-pay isn't configured on this deployment, or if `environment` is `test` (0x, who powers the swap, has no testnet support at all \u2014 `POST /v1/charges/{id}/quote` always rejects a test-environment charge with `422 swap_test_environment_unsupported`)."
322
258
  ),
323
259
  address: z9.string().describe(
324
260
  "The on-chain address the payer must send funds to \u2014 identical across every accepted network (0xSplits addresses are chain-agnostic). Unique per charge, predicted at creation time \u2014 funds sent here go directly to the merchant, Klappay never custodies them."
@@ -936,6 +872,7 @@ export {
936
872
  AcceptedPaymentSchema,
937
873
  AltTokenSchema,
938
874
  ApiKeyScopeSchema,
875
+ CHAIN_IDS,
939
876
  CHARGE_ACCEPTED_PAYMENTS_MAX,
940
877
  CHARGE_AMOUNT_MAX,
941
878
  CHARGE_EXPIRES_IN_MAX_SECONDS,
@@ -1003,6 +940,7 @@ export {
1003
940
  SplitDistributionStatusSchema,
1004
941
  SplitRecipientInputSchema,
1005
942
  SplitRecipientSchema,
943
+ SwapAlternativeSchema,
1006
944
  SwapQuoteSchema,
1007
945
  TOKEN_ADDRESSES,
1008
946
  TOKEN_DECIMALS,
@@ -1025,7 +963,7 @@ export {
1025
963
  WebhookPayloadSchema,
1026
964
  WebhookSchema,
1027
965
  findConflictingScopes,
1028
- listAltTokensForNetworks,
966
+ listSwapAlternatives,
1029
967
  paginatedSchema
1030
968
  };
1031
969
  //# sourceMappingURL=index.mjs.map