@armory-sh/base 0.2.31 → 0.2.32

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.js CHANGED
@@ -1368,6 +1368,24 @@ var isResolvedToken = (value) => {
1368
1368
  };
1369
1369
 
1370
1370
  // src/payment-requirements.ts
1371
+ function resolveAmountForNetwork(config, network) {
1372
+ const defaultAmount = config.amount ?? "1.0";
1373
+ if (!config.amounts) {
1374
+ return defaultAmount;
1375
+ }
1376
+ const explicitDefault = config.amounts.default;
1377
+ const fallbackAmount = explicitDefault ?? defaultAmount;
1378
+ for (const [networkKey, amount] of Object.entries(config.amounts)) {
1379
+ if (networkKey === "default") {
1380
+ continue;
1381
+ }
1382
+ const resolvedNetwork = resolveNetwork(networkKey);
1383
+ if (!isValidationError2(resolvedNetwork) && resolvedNetwork.config.chainId === network.config.chainId) {
1384
+ return amount;
1385
+ }
1386
+ }
1387
+ return fallbackAmount;
1388
+ }
1371
1389
  var DEFAULT_NETWORKS = [
1372
1390
  "ethereum",
1373
1391
  "base",
@@ -1539,7 +1557,6 @@ function createPaymentRequirements(config) {
1539
1557
  chain,
1540
1558
  tokens,
1541
1559
  token,
1542
- amount = "1.0",
1543
1560
  maxTimeoutSeconds = 300
1544
1561
  } = config;
1545
1562
  const chainInputs = chain ? [chain] : chains;
@@ -1551,12 +1568,13 @@ function createPaymentRequirements(config) {
1551
1568
  const requirements = [];
1552
1569
  for (const network of networks) {
1553
1570
  const tokensToResolve = tokenInputs?.length ? tokenInputs : DEFAULT_TOKENS;
1571
+ const resolvedAmount = resolveAmountForNetwork(config, network);
1572
+ const atomicAmount = toAtomicUnits(resolvedAmount);
1554
1573
  for (const tokenId of tokensToResolve) {
1555
1574
  const resolvedToken = resolveToken(tokenId, network);
1556
1575
  if (isValidationError2(resolvedToken)) {
1557
1576
  continue;
1558
1577
  }
1559
- const atomicAmount = toAtomicUnits(amount);
1560
1578
  const tokenConfig = resolvedToken.config;
1561
1579
  const resolvedPayTo = resolvePayTo(config, network, resolvedToken);
1562
1580
  resolveFacilitatorUrl(
@@ -7,6 +7,7 @@ export interface PaymentConfig {
7
7
  tokens?: TokenId[];
8
8
  token?: TokenId;
9
9
  amount?: string;
10
+ amounts?: Record<string, string>;
10
11
  maxTimeoutSeconds?: number;
11
12
  payToByChain?: Record<string, Address | string>;
12
13
  payToByToken?: Record<string, Record<string, Address | string>>;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@armory-sh/base",
3
- "version": "0.2.31",
3
+ "version": "0.2.32",
4
4
  "license": "MIT",
5
5
  "author": "Sawyer Cutler <sawyer@dirtroad.dev>",
6
6
  "keywords": [
@@ -22,6 +22,7 @@ export interface PaymentConfig {
22
22
  tokens?: TokenId[];
23
23
  token?: TokenId;
24
24
  amount?: string;
25
+ amounts?: Record<string, string>;
25
26
  maxTimeoutSeconds?: number;
26
27
 
27
28
  payToByChain?: Record<string, Address | string>;
@@ -32,6 +33,35 @@ export interface PaymentConfig {
32
33
  facilitatorUrlByToken?: Record<string, Record<string, string>>;
33
34
  }
34
35
 
36
+ function resolveAmountForNetwork(
37
+ config: PaymentConfig,
38
+ network: ResolvedNetwork,
39
+ ): string {
40
+ const defaultAmount = config.amount ?? "1.0";
41
+ if (!config.amounts) {
42
+ return defaultAmount;
43
+ }
44
+
45
+ const explicitDefault = config.amounts.default;
46
+ const fallbackAmount = explicitDefault ?? defaultAmount;
47
+
48
+ for (const [networkKey, amount] of Object.entries(config.amounts)) {
49
+ if (networkKey === "default") {
50
+ continue;
51
+ }
52
+
53
+ const resolvedNetwork = resolveNetwork(networkKey);
54
+ if (
55
+ !isValidationError(resolvedNetwork) &&
56
+ resolvedNetwork.config.chainId === network.config.chainId
57
+ ) {
58
+ return amount;
59
+ }
60
+ }
61
+
62
+ return fallbackAmount;
63
+ }
64
+
35
65
  export interface ResolvedRequirementsConfig {
36
66
  requirements: PaymentRequirementsV2[];
37
67
  error?: ValidationError;
@@ -308,7 +338,6 @@ export function createPaymentRequirements(
308
338
  chain,
309
339
  tokens,
310
340
  token,
311
- amount = "1.0",
312
341
  maxTimeoutSeconds = 300,
313
342
  } = config;
314
343
 
@@ -324,6 +353,8 @@ export function createPaymentRequirements(
324
353
 
325
354
  for (const network of networks) {
326
355
  const tokensToResolve = tokenInputs?.length ? tokenInputs : DEFAULT_TOKENS;
356
+ const resolvedAmount = resolveAmountForNetwork(config, network);
357
+ const atomicAmount = toAtomicUnits(resolvedAmount);
327
358
 
328
359
  for (const tokenId of tokensToResolve) {
329
360
  const resolvedToken = resolveToken(tokenId, network);
@@ -331,7 +362,6 @@ export function createPaymentRequirements(
331
362
  continue;
332
363
  }
333
364
 
334
- const atomicAmount = toAtomicUnits(amount);
335
365
  const tokenConfig = resolvedToken.config;
336
366
 
337
367
  const resolvedPayTo = resolvePayTo(config, network, resolvedToken);