viem 2.57.5 → 2.57.6

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.
Files changed (178) hide show
  1. package/CHANGELOG.md +8 -0
  2. package/_cjs/errors/version.js +1 -1
  3. package/_cjs/tempo/Abis.js +297 -1
  4. package/_cjs/tempo/Abis.js.map +1 -1
  5. package/_cjs/tempo/Addresses.js +2 -1
  6. package/_cjs/tempo/Addresses.js.map +1 -1
  7. package/_cjs/tempo/Decorator.js.map +1 -1
  8. package/_cjs/tempo/ExecutionError.js +94 -3
  9. package/_cjs/tempo/ExecutionError.js.map +1 -1
  10. package/_cjs/tempo/actions/accessKey.js +382 -10
  11. package/_cjs/tempo/actions/accessKey.js.map +1 -1
  12. package/_cjs/tempo/actions/accounts.js +3 -2
  13. package/_cjs/tempo/actions/accounts.js.map +1 -1
  14. package/_cjs/tempo/actions/amm.js +90 -4
  15. package/_cjs/tempo/actions/amm.js.map +1 -1
  16. package/_cjs/tempo/actions/channel.js +183 -7
  17. package/_cjs/tempo/actions/channel.js.map +1 -1
  18. package/_cjs/tempo/actions/dex.js +507 -14
  19. package/_cjs/tempo/actions/dex.js.map +1 -1
  20. package/_cjs/tempo/actions/earn/deployment.js +4 -3
  21. package/_cjs/tempo/actions/earn/deployment.js.map +1 -1
  22. package/_cjs/tempo/actions/earn.js +22 -21
  23. package/_cjs/tempo/actions/earn.js.map +1 -1
  24. package/_cjs/tempo/actions/fee.js +85 -5
  25. package/_cjs/tempo/actions/fee.js.map +1 -1
  26. package/_cjs/tempo/actions/nonce.js +54 -1
  27. package/_cjs/tempo/actions/nonce.js.map +1 -1
  28. package/_cjs/tempo/actions/policy.js +35 -6
  29. package/_cjs/tempo/actions/policy.js.map +1 -1
  30. package/_cjs/tempo/actions/propAmm.js +18 -8
  31. package/_cjs/tempo/actions/propAmm.js.map +1 -1
  32. package/_cjs/tempo/actions/receivePolicy.js +7 -6
  33. package/_cjs/tempo/actions/receivePolicy.js.map +1 -1
  34. package/_cjs/tempo/actions/reward.js +7 -6
  35. package/_cjs/tempo/actions/reward.js.map +1 -1
  36. package/_cjs/tempo/actions/token.js +433 -22
  37. package/_cjs/tempo/actions/token.js.map +1 -1
  38. package/_cjs/tempo/actions/validator.js +12 -11
  39. package/_cjs/tempo/actions/validator.js.map +1 -1
  40. package/_cjs/tempo/actions/virtualAddress.js +3 -2
  41. package/_cjs/tempo/actions/virtualAddress.js.map +1 -1
  42. package/_cjs/tempo/actions/zone.js +12 -11
  43. package/_cjs/tempo/actions/zone.js.map +1 -1
  44. package/_cjs/tempo/errors.js +57 -1
  45. package/_cjs/tempo/errors.js.map +1 -1
  46. package/_cjs/tempo/internal/errors.js +46 -0
  47. package/_cjs/tempo/internal/errors.js.map +1 -0
  48. package/_cjs/tempo/internal/resolveError.js +128 -0
  49. package/_cjs/tempo/internal/resolveError.js.map +1 -0
  50. package/_cjs/tempo/internal/utils.js +1 -0
  51. package/_cjs/tempo/internal/utils.js.map +1 -1
  52. package/_esm/errors/version.js +1 -1
  53. package/_esm/tempo/Abis.js +297 -0
  54. package/_esm/tempo/Abis.js.map +1 -1
  55. package/_esm/tempo/Addresses.js +1 -0
  56. package/_esm/tempo/Addresses.js.map +1 -1
  57. package/_esm/tempo/Decorator.js.map +1 -1
  58. package/_esm/tempo/ExecutionError.js +95 -2
  59. package/_esm/tempo/ExecutionError.js.map +1 -1
  60. package/_esm/tempo/actions/accessKey.js +406 -10
  61. package/_esm/tempo/actions/accessKey.js.map +1 -1
  62. package/_esm/tempo/actions/accounts.js +3 -2
  63. package/_esm/tempo/actions/accounts.js.map +1 -1
  64. package/_esm/tempo/actions/amm.js +95 -4
  65. package/_esm/tempo/actions/amm.js.map +1 -1
  66. package/_esm/tempo/actions/channel.js +191 -7
  67. package/_esm/tempo/actions/channel.js.map +1 -1
  68. package/_esm/tempo/actions/dex.js +537 -14
  69. package/_esm/tempo/actions/dex.js.map +1 -1
  70. package/_esm/tempo/actions/earn/deployment.js +4 -3
  71. package/_esm/tempo/actions/earn/deployment.js.map +1 -1
  72. package/_esm/tempo/actions/earn.js +22 -21
  73. package/_esm/tempo/actions/earn.js.map +1 -1
  74. package/_esm/tempo/actions/fee.js +90 -6
  75. package/_esm/tempo/actions/fee.js.map +1 -1
  76. package/_esm/tempo/actions/nonce.js +57 -1
  77. package/_esm/tempo/actions/nonce.js.map +1 -1
  78. package/_esm/tempo/actions/policy.js +36 -6
  79. package/_esm/tempo/actions/policy.js.map +1 -1
  80. package/_esm/tempo/actions/propAmm.js +18 -8
  81. package/_esm/tempo/actions/propAmm.js.map +1 -1
  82. package/_esm/tempo/actions/receivePolicy.js +7 -6
  83. package/_esm/tempo/actions/receivePolicy.js.map +1 -1
  84. package/_esm/tempo/actions/reward.js +7 -6
  85. package/_esm/tempo/actions/reward.js.map +1 -1
  86. package/_esm/tempo/actions/token.js +461 -22
  87. package/_esm/tempo/actions/token.js.map +1 -1
  88. package/_esm/tempo/actions/validator.js +12 -11
  89. package/_esm/tempo/actions/validator.js.map +1 -1
  90. package/_esm/tempo/actions/virtualAddress.js +3 -2
  91. package/_esm/tempo/actions/virtualAddress.js.map +1 -1
  92. package/_esm/tempo/actions/zone.js +12 -11
  93. package/_esm/tempo/actions/zone.js.map +1 -1
  94. package/_esm/tempo/errors.js +63 -0
  95. package/_esm/tempo/errors.js.map +1 -1
  96. package/_esm/tempo/internal/errors.js +51 -0
  97. package/_esm/tempo/internal/errors.js.map +1 -0
  98. package/_esm/tempo/internal/resolveError.js +130 -0
  99. package/_esm/tempo/internal/resolveError.js.map +1 -0
  100. package/_esm/tempo/internal/utils.js +2 -0
  101. package/_esm/tempo/internal/utils.js.map +1 -1
  102. package/_types/errors/version.d.ts +1 -1
  103. package/_types/tempo/Abis.d.ts +807 -0
  104. package/_types/tempo/Abis.d.ts.map +1 -1
  105. package/_types/tempo/Addresses.d.ts +1 -0
  106. package/_types/tempo/Addresses.d.ts.map +1 -1
  107. package/_types/tempo/Decorator.d.ts +1 -1
  108. package/_types/tempo/Decorator.d.ts.map +1 -1
  109. package/_types/tempo/ExecutionError.d.ts +3 -1
  110. package/_types/tempo/ExecutionError.d.ts.map +1 -1
  111. package/_types/tempo/actions/accessKey.d.ts +155 -8
  112. package/_types/tempo/actions/accessKey.d.ts.map +1 -1
  113. package/_types/tempo/actions/accounts.d.ts +3 -1
  114. package/_types/tempo/actions/accounts.d.ts.map +1 -1
  115. package/_types/tempo/actions/amm.d.ts +39 -0
  116. package/_types/tempo/actions/amm.d.ts.map +1 -1
  117. package/_types/tempo/actions/channel.d.ts +77 -7
  118. package/_types/tempo/actions/channel.d.ts.map +1 -1
  119. package/_types/tempo/actions/dex.d.ts +222 -16
  120. package/_types/tempo/actions/dex.d.ts.map +1 -1
  121. package/_types/tempo/actions/earn/deployment.d.ts +7 -6
  122. package/_types/tempo/actions/earn/deployment.d.ts.map +1 -1
  123. package/_types/tempo/actions/earn.d.ts +15 -14
  124. package/_types/tempo/actions/earn.d.ts.map +1 -1
  125. package/_types/tempo/actions/fee.d.ts +32 -6
  126. package/_types/tempo/actions/fee.d.ts.map +1 -1
  127. package/_types/tempo/actions/nonce.d.ts +35 -0
  128. package/_types/tempo/actions/nonce.d.ts.map +1 -1
  129. package/_types/tempo/actions/policy.d.ts +29 -8
  130. package/_types/tempo/actions/policy.d.ts.map +1 -1
  131. package/_types/tempo/actions/propAmm.d.ts +9 -1
  132. package/_types/tempo/actions/propAmm.d.ts.map +1 -1
  133. package/_types/tempo/actions/receivePolicy.d.ts +10 -6
  134. package/_types/tempo/actions/receivePolicy.d.ts.map +1 -1
  135. package/_types/tempo/actions/reward.d.ts +7 -3
  136. package/_types/tempo/actions/reward.d.ts.map +1 -1
  137. package/_types/tempo/actions/token.d.ts +200 -32
  138. package/_types/tempo/actions/token.d.ts.map +1 -1
  139. package/_types/tempo/actions/validator.d.ts +17 -5
  140. package/_types/tempo/actions/validator.d.ts.map +1 -1
  141. package/_types/tempo/actions/virtualAddress.d.ts +4 -3
  142. package/_types/tempo/actions/virtualAddress.d.ts.map +1 -1
  143. package/_types/tempo/actions/zone.d.ts +10 -9
  144. package/_types/tempo/actions/zone.d.ts.map +1 -1
  145. package/_types/tempo/errors.d.ts +63 -1
  146. package/_types/tempo/errors.d.ts.map +1 -1
  147. package/_types/tempo/internal/errors.d.ts +59 -0
  148. package/_types/tempo/internal/errors.d.ts.map +1 -0
  149. package/_types/tempo/internal/resolveError.d.ts +8 -0
  150. package/_types/tempo/internal/resolveError.d.ts.map +1 -0
  151. package/_types/tempo/internal/utils.d.ts.map +1 -1
  152. package/errors/version.ts +1 -1
  153. package/package.json +1 -1
  154. package/tempo/Abis.ts +298 -0
  155. package/tempo/Addresses.ts +1 -0
  156. package/tempo/Decorator.ts +5 -3
  157. package/tempo/ExecutionError.ts +101 -3
  158. package/tempo/actions/accessKey.ts +496 -25
  159. package/tempo/actions/accounts.ts +7 -3
  160. package/tempo/actions/amm.ts +126 -4
  161. package/tempo/actions/channel.ts +248 -14
  162. package/tempo/actions/dex.ts +599 -33
  163. package/tempo/actions/earn/deployment.ts +11 -9
  164. package/tempo/actions/earn.ts +40 -35
  165. package/tempo/actions/fee.ts +111 -9
  166. package/tempo/actions/nonce.ts +86 -1
  167. package/tempo/actions/policy.ts +66 -14
  168. package/tempo/actions/propAmm.ts +36 -9
  169. package/tempo/actions/receivePolicy.ts +26 -15
  170. package/tempo/actions/reward.ts +17 -9
  171. package/tempo/actions/token.ts +519 -54
  172. package/tempo/actions/validator.ts +40 -16
  173. package/tempo/actions/virtualAddress.ts +7 -5
  174. package/tempo/actions/zone.ts +25 -20
  175. package/tempo/errors.ts +114 -1
  176. package/tempo/internal/errors.ts +110 -0
  177. package/tempo/internal/resolveError.ts +169 -0
  178. package/tempo/internal/utils.ts +2 -0
@@ -6,8 +6,11 @@ import { watchContractEvent, } from '../../actions/public/watchContractEvent.js'
6
6
  import { writeContract, } from '../../actions/wallet/writeContract.js';
7
7
  import { writeContractSync } from '../../actions/wallet/writeContractSync.js';
8
8
  import { parseEventLogs } from '../../utils/abi/parseEventLogs.js';
9
+ import { isAddressEqual } from '../../utils/address/isAddressEqual.js';
9
10
  import * as Abis from '../Abis.js';
10
11
  import * as Addresses from '../Addresses.js';
12
+ import { TempoExecutionError } from '../errors.js';
13
+ import { withExecutionError, } from '../internal/errors.js';
11
14
  import { defineCall } from '../internal/utils.js';
12
15
  /**
13
16
  * Buys a specific amount of tokens.
@@ -45,7 +48,7 @@ export async function buy(client, parameters) {
45
48
  async function inner(action, client, parameters) {
46
49
  const { tokenIn, tokenOut, amountOut, maxAmountIn, ...rest } = parameters;
47
50
  const call = buy.call({ tokenIn, tokenOut, amountOut, maxAmountIn });
48
- return (await action(client, {
51
+ return (await withExecutionError(action)(client, {
49
52
  ...rest,
50
53
  ...call,
51
54
  }));
@@ -165,7 +168,7 @@ export async function cancel(client, parameters) {
165
168
  async function inner(action, client, parameters) {
166
169
  const { orderId, ...rest } = parameters;
167
170
  const call = cancel.call({ orderId });
168
- return (await action(client, {
171
+ return (await withExecutionError(action)(client, {
169
172
  ...rest,
170
173
  ...call,
171
174
  }));
@@ -306,7 +309,7 @@ export async function cancelStale(client, parameters) {
306
309
  async function inner(action, client, parameters) {
307
310
  const { orderId, ...rest } = parameters;
308
311
  const call = cancelStale.call({ orderId });
309
- return (await action(client, {
312
+ return (await withExecutionError(action)(client, {
310
313
  ...rest,
311
314
  ...call,
312
315
  }));
@@ -447,7 +450,7 @@ export async function createPair(client, parameters) {
447
450
  async function inner(action, client, parameters) {
448
451
  const { base, ...rest } = parameters;
449
452
  const call = createPair.call({ base });
450
- return (await action(client, {
453
+ return (await withExecutionError(action)(client, {
451
454
  ...rest,
452
455
  ...call,
453
456
  }));
@@ -581,7 +584,7 @@ export async function getBalance(client, parameters) {
581
584
  const address = acc ? parseAccount(acc).address : undefined;
582
585
  if (!address)
583
586
  throw new Error('account is required.');
584
- return readContract(client, {
587
+ return withExecutionError(readContract)(client, {
585
588
  ...rest,
586
589
  ...getBalance.call({ account: address, token }),
587
590
  });
@@ -631,7 +634,7 @@ export async function getBalance(client, parameters) {
631
634
  */
632
635
  export async function getBuyQuote(client, parameters) {
633
636
  const { tokenIn, tokenOut, amountOut, ...rest } = parameters;
634
- return readContract(client, {
637
+ return withExecutionError(readContract)(client, {
635
638
  ...rest,
636
639
  ...getBuyQuote.call({ tokenIn, tokenOut, amountOut }),
637
640
  });
@@ -679,7 +682,7 @@ export async function getBuyQuote(client, parameters) {
679
682
  */
680
683
  export async function getOrder(client, parameters) {
681
684
  const { orderId, ...rest } = parameters;
682
- return readContract(client, {
685
+ return withExecutionError(readContract)(client, {
683
686
  ...rest,
684
687
  ...getOrder.call({ orderId }),
685
688
  });
@@ -728,7 +731,7 @@ export async function getOrder(client, parameters) {
728
731
  */
729
732
  export async function getOrderbook(client, parameters) {
730
733
  const { base, quote, ...rest } = parameters;
731
- return readContract(client, {
734
+ return withExecutionError(readContract)(client, {
732
735
  ...rest,
733
736
  ...getOrderbook.call({ base, quote }),
734
737
  });
@@ -779,7 +782,7 @@ export async function getOrderbook(client, parameters) {
779
782
  */
780
783
  export async function getTickLevel(client, parameters) {
781
784
  const { base, tick, isBid, ...rest } = parameters;
782
- const [head, tail, totalLiquidity] = await readContract(client, {
785
+ const [head, tail, totalLiquidity] = await withExecutionError(readContract)(client, {
783
786
  ...rest,
784
787
  ...getTickLevel.call({ base, tick, isBid }),
785
788
  });
@@ -830,7 +833,7 @@ export async function getTickLevel(client, parameters) {
830
833
  */
831
834
  export async function getSellQuote(client, parameters) {
832
835
  const { tokenIn, tokenOut, amountIn, ...rest } = parameters;
833
- return readContract(client, {
836
+ return withExecutionError(readContract)(client, {
834
837
  ...rest,
835
838
  ...getSellQuote.call({ tokenIn, tokenOut, amountIn }),
836
839
  });
@@ -889,7 +892,7 @@ export async function place(client, parameters) {
889
892
  async function inner(action, client, parameters) {
890
893
  const { amount, token, type, tick, ...rest } = parameters;
891
894
  const call = place.call({ amount, token, type, tick });
892
- return (await action(client, {
895
+ return (await withExecutionError(action)(client, {
893
896
  ...rest,
894
897
  ...call,
895
898
  }));
@@ -996,7 +999,7 @@ export async function placeFlip(client, parameters) {
996
999
  async function inner(action, client, parameters) {
997
1000
  const { amount, flipTick, tick, token, type, ...rest } = parameters;
998
1001
  const call = placeFlip.call({ amount, flipTick, tick, token, type });
999
- return (await action(client, {
1002
+ return (await withExecutionError(action)(client, {
1000
1003
  ...rest,
1001
1004
  ...call,
1002
1005
  }));
@@ -1189,7 +1192,7 @@ export async function sell(client, parameters) {
1189
1192
  async function inner(action, client, parameters) {
1190
1193
  const { tokenIn, tokenOut, amountIn, minAmountOut, ...rest } = parameters;
1191
1194
  const call = sell.call({ tokenIn, tokenOut, amountIn, minAmountOut });
1192
- return (await action(client, {
1195
+ return (await withExecutionError(action)(client, {
1193
1196
  ...rest,
1194
1197
  ...call,
1195
1198
  }));
@@ -1482,7 +1485,7 @@ export async function withdraw(client, parameters) {
1482
1485
  async function inner(action, client, parameters) {
1483
1486
  const { token, amount, ...rest } = parameters;
1484
1487
  const call = withdraw.call({ token, amount });
1485
- return (await action(client, {
1488
+ return (await withExecutionError(action)(client, {
1486
1489
  ...rest,
1487
1490
  ...call,
1488
1491
  }));
@@ -1568,4 +1571,524 @@ export async function withdrawSync(client, parameters) {
1568
1571
  function getPairKey(base, quote) {
1569
1572
  return Hash.keccak256(Hex.concat(base, quote));
1570
1573
  }
1574
+ /** Thrown when a sell would return less than `minAmountOut`. */
1575
+ export class DexInsufficientOutputError extends TempoExecutionError {
1576
+ constructor(parameters) {
1577
+ const { amountIn, minAmountOut, quote, tokenIn, tokenOut } = parameters;
1578
+ super(parameters, {
1579
+ details: {
1580
+ 'token in': tokenIn,
1581
+ 'token out': tokenOut,
1582
+ 'amount in': amountIn,
1583
+ 'min amount out': minAmountOut,
1584
+ quote,
1585
+ },
1586
+ name: 'DexInsufficientOutputError',
1587
+ });
1588
+ /** Amount of `tokenIn` to sell. */
1589
+ Object.defineProperty(this, "amountIn", {
1590
+ enumerable: true,
1591
+ configurable: true,
1592
+ writable: true,
1593
+ value: void 0
1594
+ });
1595
+ /** Minimum amount of `tokenOut` to receive. */
1596
+ Object.defineProperty(this, "minAmountOut", {
1597
+ enumerable: true,
1598
+ configurable: true,
1599
+ writable: true,
1600
+ value: void 0
1601
+ });
1602
+ /** Current quote for `amountIn`, when available. */
1603
+ Object.defineProperty(this, "quote", {
1604
+ enumerable: true,
1605
+ configurable: true,
1606
+ writable: true,
1607
+ value: void 0
1608
+ });
1609
+ /** Token to sell. */
1610
+ Object.defineProperty(this, "tokenIn", {
1611
+ enumerable: true,
1612
+ configurable: true,
1613
+ writable: true,
1614
+ value: void 0
1615
+ });
1616
+ /** Token to buy. */
1617
+ Object.defineProperty(this, "tokenOut", {
1618
+ enumerable: true,
1619
+ configurable: true,
1620
+ writable: true,
1621
+ value: void 0
1622
+ });
1623
+ this.amountIn = amountIn;
1624
+ this.minAmountOut = minAmountOut;
1625
+ this.quote = quote;
1626
+ this.tokenIn = tokenIn;
1627
+ this.tokenOut = tokenOut;
1628
+ }
1629
+ }
1630
+ /** Thrown when a buy would cost more than `maxAmountIn`. */
1631
+ export class DexMaxInputExceededError extends TempoExecutionError {
1632
+ constructor(parameters) {
1633
+ const { amountOut, maxAmountIn, quote, tokenIn, tokenOut } = parameters;
1634
+ super(parameters, {
1635
+ details: {
1636
+ 'token in': tokenIn,
1637
+ 'token out': tokenOut,
1638
+ 'amount out': amountOut,
1639
+ 'max amount in': maxAmountIn,
1640
+ quote,
1641
+ },
1642
+ name: 'DexMaxInputExceededError',
1643
+ });
1644
+ /** Amount of `tokenOut` to buy. */
1645
+ Object.defineProperty(this, "amountOut", {
1646
+ enumerable: true,
1647
+ configurable: true,
1648
+ writable: true,
1649
+ value: void 0
1650
+ });
1651
+ /** Maximum amount of `tokenIn` to spend. */
1652
+ Object.defineProperty(this, "maxAmountIn", {
1653
+ enumerable: true,
1654
+ configurable: true,
1655
+ writable: true,
1656
+ value: void 0
1657
+ });
1658
+ /** Current cost of `amountOut`, when available. */
1659
+ Object.defineProperty(this, "quote", {
1660
+ enumerable: true,
1661
+ configurable: true,
1662
+ writable: true,
1663
+ value: void 0
1664
+ });
1665
+ /** Token to spend. */
1666
+ Object.defineProperty(this, "tokenIn", {
1667
+ enumerable: true,
1668
+ configurable: true,
1669
+ writable: true,
1670
+ value: void 0
1671
+ });
1672
+ /** Token to buy. */
1673
+ Object.defineProperty(this, "tokenOut", {
1674
+ enumerable: true,
1675
+ configurable: true,
1676
+ writable: true,
1677
+ value: void 0
1678
+ });
1679
+ this.amountOut = amountOut;
1680
+ this.maxAmountIn = maxAmountIn;
1681
+ this.quote = quote;
1682
+ this.tokenIn = tokenIn;
1683
+ this.tokenOut = tokenOut;
1684
+ }
1685
+ }
1686
+ /** Thrown when the order book cannot fill a swap. */
1687
+ export class DexInsufficientLiquidityError extends TempoExecutionError {
1688
+ constructor(parameters) {
1689
+ const { amountIn, amountOut, tokenIn, tokenOut } = parameters;
1690
+ super(parameters, {
1691
+ details: {
1692
+ 'token in': tokenIn,
1693
+ 'token out': tokenOut,
1694
+ 'amount in': amountIn,
1695
+ 'amount out': amountOut,
1696
+ },
1697
+ name: 'DexInsufficientLiquidityError',
1698
+ });
1699
+ /** Amount of `tokenIn` to sell, for sells. */
1700
+ Object.defineProperty(this, "amountIn", {
1701
+ enumerable: true,
1702
+ configurable: true,
1703
+ writable: true,
1704
+ value: void 0
1705
+ });
1706
+ /** Amount of `tokenOut` to buy, for buys. */
1707
+ Object.defineProperty(this, "amountOut", {
1708
+ enumerable: true,
1709
+ configurable: true,
1710
+ writable: true,
1711
+ value: void 0
1712
+ });
1713
+ /** Token to spend. */
1714
+ Object.defineProperty(this, "tokenIn", {
1715
+ enumerable: true,
1716
+ configurable: true,
1717
+ writable: true,
1718
+ value: void 0
1719
+ });
1720
+ /** Token to buy. */
1721
+ Object.defineProperty(this, "tokenOut", {
1722
+ enumerable: true,
1723
+ configurable: true,
1724
+ writable: true,
1725
+ value: void 0
1726
+ });
1727
+ this.amountIn = amountIn;
1728
+ this.amountOut = amountOut;
1729
+ this.tokenIn = tokenIn;
1730
+ this.tokenOut = tokenOut;
1731
+ }
1732
+ }
1733
+ /** Thrown when an order is smaller than the minimum order size. */
1734
+ export class DexBelowMinimumOrderSizeError extends TempoExecutionError {
1735
+ constructor(parameters) {
1736
+ const [amount] = parameters.error.args;
1737
+ const { minimum } = parameters;
1738
+ super(parameters, {
1739
+ details: { amount, minimum },
1740
+ name: 'DexBelowMinimumOrderSizeError',
1741
+ shortMessage: `Order amount ${amount} is below the minimum${minimum === undefined ? '' : ` of ${minimum}`}.`,
1742
+ });
1743
+ /** Order amount. */
1744
+ Object.defineProperty(this, "amount", {
1745
+ enumerable: true,
1746
+ configurable: true,
1747
+ writable: true,
1748
+ value: void 0
1749
+ });
1750
+ /** Minimum order amount, when known. */
1751
+ Object.defineProperty(this, "minimum", {
1752
+ enumerable: true,
1753
+ configurable: true,
1754
+ writable: true,
1755
+ value: void 0
1756
+ });
1757
+ this.amount = amount;
1758
+ this.minimum = minimum;
1759
+ }
1760
+ }
1761
+ /** Thrown when an order's tick or flip tick is outside the allowed range. */
1762
+ export class DexTickOutOfBoundsError extends TempoExecutionError {
1763
+ constructor(parameters) {
1764
+ const [tick] = parameters.error.args;
1765
+ const { maxTick, minTick } = parameters;
1766
+ super(parameters, {
1767
+ details: {
1768
+ tick,
1769
+ range: minTick === undefined || maxTick === undefined
1770
+ ? undefined
1771
+ : `${minTick} to ${maxTick}`,
1772
+ },
1773
+ name: 'DexTickOutOfBoundsError',
1774
+ });
1775
+ /** Highest allowed tick, when known. */
1776
+ Object.defineProperty(this, "maxTick", {
1777
+ enumerable: true,
1778
+ configurable: true,
1779
+ writable: true,
1780
+ value: void 0
1781
+ });
1782
+ /** Lowest allowed tick, when known. */
1783
+ Object.defineProperty(this, "minTick", {
1784
+ enumerable: true,
1785
+ configurable: true,
1786
+ writable: true,
1787
+ value: void 0
1788
+ });
1789
+ /** Tick that is out of range. */
1790
+ Object.defineProperty(this, "tick", {
1791
+ enumerable: true,
1792
+ configurable: true,
1793
+ writable: true,
1794
+ value: void 0
1795
+ });
1796
+ this.maxTick = maxTick;
1797
+ this.minTick = minTick;
1798
+ this.tick = tick;
1799
+ }
1800
+ }
1801
+ /** Thrown when a flip order's flip tick is on the wrong side of its tick or off the tick spacing. */
1802
+ export class DexInvalidFlipTickError extends TempoExecutionError {
1803
+ constructor(parameters) {
1804
+ const { flipTick, side, tick, tickSpacing } = parameters;
1805
+ super(parameters, {
1806
+ details: {
1807
+ side,
1808
+ tick,
1809
+ 'flip tick': flipTick,
1810
+ 'tick spacing': tickSpacing,
1811
+ },
1812
+ name: 'DexInvalidFlipTickError',
1813
+ shortMessage: side === 'buy'
1814
+ ? 'The flip tick of a buy order must be at or above its tick, and a multiple of the tick spacing.'
1815
+ : side === 'sell'
1816
+ ? 'The flip tick of a sell order must be at or below its tick, and a multiple of the tick spacing.'
1817
+ : undefined,
1818
+ });
1819
+ /** Flip tick. */
1820
+ Object.defineProperty(this, "flipTick", {
1821
+ enumerable: true,
1822
+ configurable: true,
1823
+ writable: true,
1824
+ value: void 0
1825
+ });
1826
+ /** Order side. */
1827
+ Object.defineProperty(this, "side", {
1828
+ enumerable: true,
1829
+ configurable: true,
1830
+ writable: true,
1831
+ value: void 0
1832
+ });
1833
+ /** Order tick. */
1834
+ Object.defineProperty(this, "tick", {
1835
+ enumerable: true,
1836
+ configurable: true,
1837
+ writable: true,
1838
+ value: void 0
1839
+ });
1840
+ /** Tick spacing, when known. */
1841
+ Object.defineProperty(this, "tickSpacing", {
1842
+ enumerable: true,
1843
+ configurable: true,
1844
+ writable: true,
1845
+ value: void 0
1846
+ });
1847
+ this.flipTick = flipTick;
1848
+ this.side = side;
1849
+ this.tick = tick;
1850
+ this.tickSpacing = tickSpacing;
1851
+ }
1852
+ }
1853
+ /** Thrown when an order does not exist or is already filled. */
1854
+ export class DexOrderNotFoundError extends TempoExecutionError {
1855
+ constructor(parameters) {
1856
+ super(parameters, {
1857
+ details: { order: parameters.orderId },
1858
+ name: 'DexOrderNotFoundError',
1859
+ shortMessage: `Order ${parameters.orderId} does not exist or is already filled.`,
1860
+ });
1861
+ /** Order ID. */
1862
+ Object.defineProperty(this, "orderId", {
1863
+ enumerable: true,
1864
+ configurable: true,
1865
+ writable: true,
1866
+ value: void 0
1867
+ });
1868
+ this.orderId = parameters.orderId;
1869
+ }
1870
+ }
1871
+ /** Thrown when cancelling a stale order whose maker is still authorized by the token's policy. */
1872
+ export class DexOrderNotStaleError extends TempoExecutionError {
1873
+ constructor(parameters) {
1874
+ super(parameters, {
1875
+ details: { order: parameters.orderId },
1876
+ name: 'DexOrderNotStaleError',
1877
+ shortMessage: `Order ${parameters.orderId} is not stale: its maker is still authorized.`,
1878
+ });
1879
+ /** Order ID. */
1880
+ Object.defineProperty(this, "orderId", {
1881
+ enumerable: true,
1882
+ configurable: true,
1883
+ writable: true,
1884
+ value: void 0
1885
+ });
1886
+ this.orderId = parameters.orderId;
1887
+ }
1888
+ }
1889
+ /** Thrown when no trading pair exists for a token. */
1890
+ export class DexPairNotFoundError extends TempoExecutionError {
1891
+ constructor(parameters) {
1892
+ super(parameters, {
1893
+ details: { tokens: parameters.tokens.join(', ') || undefined },
1894
+ name: 'DexPairNotFoundError',
1895
+ });
1896
+ /** Tokens of the call. */
1897
+ Object.defineProperty(this, "tokens", {
1898
+ enumerable: true,
1899
+ configurable: true,
1900
+ writable: true,
1901
+ value: void 0
1902
+ });
1903
+ this.tokens = parameters.tokens;
1904
+ }
1905
+ }
1906
+ /** Thrown when withdrawing more than the account's exchange balance. */
1907
+ export class DexInsufficientBalanceError extends TempoExecutionError {
1908
+ constructor(parameters) {
1909
+ const { amount, balance, token } = parameters;
1910
+ super(parameters, {
1911
+ details: { token, amount, balance },
1912
+ name: 'DexInsufficientBalanceError',
1913
+ shortMessage: `Insufficient exchange balance of token "${token}".`,
1914
+ });
1915
+ /** Amount to withdraw. */
1916
+ Object.defineProperty(this, "amount", {
1917
+ enumerable: true,
1918
+ configurable: true,
1919
+ writable: true,
1920
+ value: void 0
1921
+ });
1922
+ /** Exchange balance, when known. */
1923
+ Object.defineProperty(this, "balance", {
1924
+ enumerable: true,
1925
+ configurable: true,
1926
+ writable: true,
1927
+ value: void 0
1928
+ });
1929
+ /** Token address. */
1930
+ Object.defineProperty(this, "token", {
1931
+ enumerable: true,
1932
+ configurable: true,
1933
+ writable: true,
1934
+ value: void 0
1935
+ });
1936
+ this.amount = amount;
1937
+ this.balance = balance;
1938
+ this.token = token;
1939
+ }
1940
+ }
1941
+ const exchange = {
1942
+ address: Addresses.stablecoinDex,
1943
+ abi: Abis.stablecoinDex,
1944
+ };
1945
+ /** The failed call, when it targets the exchange. */
1946
+ function getExchangeCall(context) {
1947
+ const { call } = context;
1948
+ return call && isAddressEqual(call.address, Addresses.stablecoinDex)
1949
+ ? call
1950
+ : undefined;
1951
+ }
1952
+ /** @internal */
1953
+ export const errorResolvers = {
1954
+ 'BelowMinimumOrderSize(uint128)': async (context) => {
1955
+ if (!getExchangeCall(context) || !context.base.error.args)
1956
+ return undefined;
1957
+ const [minimum] = await context.read([
1958
+ { ...exchange, functionName: 'MIN_ORDER_AMOUNT' },
1959
+ ]);
1960
+ return new DexBelowMinimumOrderSizeError({
1961
+ ...context.base,
1962
+ minimum: minimum?.result,
1963
+ });
1964
+ },
1965
+ 'InsufficientBalance()': async (context) => {
1966
+ const call = getExchangeCall(context);
1967
+ const token = call?.arg('token');
1968
+ if (call?.functionName !== 'withdraw' || !token || !context.signer)
1969
+ return undefined;
1970
+ const [balance] = await context.read([
1971
+ {
1972
+ ...exchange,
1973
+ functionName: 'balanceOf',
1974
+ args: [context.signer.address, token],
1975
+ },
1976
+ ]);
1977
+ return new DexInsufficientBalanceError({
1978
+ ...context.base,
1979
+ amount: call.arg('amount'),
1980
+ balance: balance?.result,
1981
+ token,
1982
+ });
1983
+ },
1984
+ 'InsufficientLiquidity()': (context) => {
1985
+ const call = getExchangeCall(context);
1986
+ if (!call)
1987
+ return undefined;
1988
+ return new DexInsufficientLiquidityError({
1989
+ ...context.base,
1990
+ amountIn: call.arg('amountIn'),
1991
+ amountOut: call.arg('amountOut'),
1992
+ tokenIn: call.arg('tokenIn'),
1993
+ tokenOut: call.arg('tokenOut'),
1994
+ });
1995
+ },
1996
+ 'InsufficientOutput()': async (context) => {
1997
+ const call = getExchangeCall(context);
1998
+ if (!call)
1999
+ return undefined;
2000
+ const tokenIn = call.arg('tokenIn');
2001
+ const tokenOut = call.arg('tokenOut');
2002
+ const amountIn = call.arg('amountIn');
2003
+ const [quote] = await context.read([
2004
+ {
2005
+ ...exchange,
2006
+ functionName: 'quoteSwapExactAmountIn',
2007
+ args: [tokenIn, tokenOut, amountIn],
2008
+ },
2009
+ ]);
2010
+ return new DexInsufficientOutputError({
2011
+ ...context.base,
2012
+ amountIn,
2013
+ minAmountOut: call.arg('minAmountOut'),
2014
+ quote: quote?.result,
2015
+ tokenIn,
2016
+ tokenOut,
2017
+ });
2018
+ },
2019
+ 'InvalidFlipTick()': async (context) => {
2020
+ const call = getExchangeCall(context);
2021
+ if (!call)
2022
+ return undefined;
2023
+ const [tickSpacing] = await context.read([
2024
+ { ...exchange, functionName: 'TICK_SPACING' },
2025
+ ]);
2026
+ const isBid = call.arg('isBid');
2027
+ return new DexInvalidFlipTickError({
2028
+ ...context.base,
2029
+ flipTick: call.arg('flipTick'),
2030
+ side: isBid === undefined ? undefined : isBid ? 'buy' : 'sell',
2031
+ tick: call.arg('tick'),
2032
+ tickSpacing: tickSpacing?.result,
2033
+ });
2034
+ },
2035
+ 'MaxInputExceeded()': async (context) => {
2036
+ const call = getExchangeCall(context);
2037
+ if (!call)
2038
+ return undefined;
2039
+ const tokenIn = call.arg('tokenIn');
2040
+ const tokenOut = call.arg('tokenOut');
2041
+ const amountOut = call.arg('amountOut');
2042
+ const [quote] = await context.read([
2043
+ {
2044
+ ...exchange,
2045
+ functionName: 'quoteSwapExactAmountOut',
2046
+ args: [tokenIn, tokenOut, amountOut],
2047
+ },
2048
+ ]);
2049
+ return new DexMaxInputExceededError({
2050
+ ...context.base,
2051
+ amountOut,
2052
+ maxAmountIn: call.arg('maxAmountIn'),
2053
+ quote: quote?.result,
2054
+ tokenIn,
2055
+ tokenOut,
2056
+ });
2057
+ },
2058
+ 'OrderDoesNotExist()': (context) => {
2059
+ const orderId = getExchangeCall(context)?.arg('orderId');
2060
+ if (orderId === undefined)
2061
+ return undefined;
2062
+ return new DexOrderNotFoundError({ ...context.base, orderId });
2063
+ },
2064
+ 'OrderNotStale()': (context) => {
2065
+ const orderId = getExchangeCall(context)?.arg('orderId');
2066
+ if (orderId === undefined)
2067
+ return undefined;
2068
+ return new DexOrderNotStaleError({ ...context.base, orderId });
2069
+ },
2070
+ 'PairDoesNotExist()': (context) => {
2071
+ const call = getExchangeCall(context);
2072
+ if (!call)
2073
+ return undefined;
2074
+ const tokens = ['token', 'tokenIn', 'tokenOut', 'base'].flatMap((name) => {
2075
+ const token = call.arg(name);
2076
+ return token ? [token] : [];
2077
+ });
2078
+ return new DexPairNotFoundError({ ...context.base, tokens });
2079
+ },
2080
+ 'TickOutOfBounds(int16)': async (context) => {
2081
+ if (!getExchangeCall(context) || !context.base.error.args)
2082
+ return undefined;
2083
+ const [minTick, maxTick] = await context.read([
2084
+ { ...exchange, functionName: 'MIN_TICK' },
2085
+ { ...exchange, functionName: 'MAX_TICK' },
2086
+ ]);
2087
+ return new DexTickOutOfBoundsError({
2088
+ ...context.base,
2089
+ maxTick: maxTick?.result,
2090
+ minTick: minTick?.result,
2091
+ });
2092
+ },
2093
+ };
1571
2094
  //# sourceMappingURL=dex.js.map