@augustdigital/sdk 8.3.2 → 8.6.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.
Files changed (213) hide show
  1. package/README.md +207 -117
  2. package/lib/abis/ERC20_Bytes32.d.ts +4 -0
  3. package/lib/abis/ERC20_Bytes32.js +4 -0
  4. package/lib/abis/ERC4626.d.ts +1 -0
  5. package/lib/abis/ERC4626.js +1 -0
  6. package/lib/abis/ERC721.d.ts +1 -0
  7. package/lib/abis/ERC721.js +1 -0
  8. package/lib/abis/FeeOracle.js +1 -0
  9. package/lib/abis/LendingPool.js +1 -0
  10. package/lib/abis/LendingPoolV2.js +1 -0
  11. package/lib/abis/Multicall3.js +3 -0
  12. package/lib/abis/OFT.d.ts +20 -0
  13. package/lib/abis/OFT.js +20 -0
  14. package/lib/abis/SmartAccount.d.ts +1 -0
  15. package/lib/abis/SmartAccount.js +3 -0
  16. package/lib/abis/SwapRouter.d.ts +1 -0
  17. package/lib/abis/SwapRouter.js +1 -0
  18. package/lib/abis/UniversalSignatureValidator.js +3 -0
  19. package/lib/abis/index.d.ts +5 -0
  20. package/lib/abis/index.js +5 -0
  21. package/lib/adapters/evm/getters.d.ts +17 -2
  22. package/lib/adapters/evm/getters.js +35 -3
  23. package/lib/adapters/evm/index.d.ts +266 -4
  24. package/lib/adapters/evm/index.js +270 -1
  25. package/lib/adapters/evm/utils.d.ts +6 -0
  26. package/lib/adapters/evm/utils.js +7 -0
  27. package/lib/adapters/solana/constants.d.ts +1 -1
  28. package/lib/adapters/solana/constants.js +4 -1
  29. package/lib/adapters/solana/getters.d.ts +9 -1
  30. package/lib/adapters/solana/getters.js +21 -0
  31. package/lib/adapters/solana/idl/vault-idl.js +9 -0
  32. package/lib/adapters/solana/index.d.ts +59 -4
  33. package/lib/adapters/solana/index.js +61 -0
  34. package/lib/adapters/solana/types.d.ts +1 -1
  35. package/lib/adapters/solana/utils.d.ts +31 -3
  36. package/lib/adapters/solana/utils.js +79 -4
  37. package/lib/adapters/solana/vault.actions.d.ts +23 -4
  38. package/lib/adapters/solana/vault.actions.js +47 -3
  39. package/lib/adapters/stellar/actions.d.ts +26 -1
  40. package/lib/adapters/stellar/actions.js +33 -0
  41. package/lib/adapters/stellar/constants.d.ts +26 -0
  42. package/lib/adapters/stellar/constants.js +29 -0
  43. package/lib/adapters/stellar/getters.d.ts +56 -0
  44. package/lib/adapters/stellar/getters.js +81 -0
  45. package/lib/adapters/stellar/index.d.ts +70 -0
  46. package/lib/adapters/stellar/index.js +71 -0
  47. package/lib/adapters/stellar/soroban.d.ts +21 -1
  48. package/lib/adapters/stellar/soroban.js +47 -1
  49. package/lib/adapters/stellar/submit.d.ts +29 -0
  50. package/lib/adapters/stellar/submit.js +90 -5
  51. package/lib/adapters/stellar/types.d.ts +27 -0
  52. package/lib/adapters/stellar/types.js +3 -0
  53. package/lib/adapters/stellar/utils.d.ts +10 -0
  54. package/lib/adapters/stellar/utils.js +10 -0
  55. package/lib/adapters/sui/getters.d.ts +7 -1
  56. package/lib/adapters/sui/getters.js +6 -0
  57. package/lib/adapters/sui/index.d.ts +16 -1
  58. package/lib/adapters/sui/index.js +17 -0
  59. package/lib/adapters/sui/transformer.d.ts +8 -2
  60. package/lib/adapters/sui/transformer.js +7 -0
  61. package/lib/adapters/sui/types.d.ts +1 -1
  62. package/lib/adapters/sui/utils.d.ts +6 -0
  63. package/lib/adapters/sui/utils.js +6 -0
  64. package/lib/core/analytics/chain-name.d.ts +8 -0
  65. package/lib/core/analytics/chain-name.js +8 -0
  66. package/lib/core/analytics/constants.d.ts +4 -0
  67. package/lib/core/analytics/constants.js +4 -0
  68. package/lib/core/analytics/env.d.ts +25 -0
  69. package/lib/core/analytics/env.js +26 -0
  70. package/lib/core/analytics/index.d.ts +26 -0
  71. package/lib/core/analytics/index.js +35 -0
  72. package/lib/core/analytics/instrumentation.d.ts +26 -0
  73. package/lib/core/analytics/instrumentation.js +66 -2
  74. package/lib/core/analytics/method-taxonomy.d.ts +16 -0
  75. package/lib/core/analytics/method-taxonomy.js +18 -0
  76. package/lib/core/analytics/metrics.d.ts +23 -0
  77. package/lib/core/analytics/metrics.js +40 -0
  78. package/lib/core/analytics/sanitize.d.ts +38 -0
  79. package/lib/core/analytics/sanitize.js +46 -0
  80. package/lib/core/analytics/sentry-runtime.d.ts +11 -0
  81. package/lib/core/analytics/sentry-runtime.js +20 -1
  82. package/lib/core/analytics/sentry.d.ts +47 -2
  83. package/lib/core/analytics/sentry.js +115 -2
  84. package/lib/core/analytics/types.d.ts +28 -1
  85. package/lib/core/analytics/user-identity.d.ts +36 -2
  86. package/lib/core/analytics/user-identity.js +43 -1
  87. package/lib/core/analytics/version.d.ts +6 -1
  88. package/lib/core/analytics/version.js +6 -1
  89. package/lib/core/auth/verify.js +5 -0
  90. package/lib/core/base.class.d.ts +78 -3
  91. package/lib/core/base.class.js +66 -4
  92. package/lib/core/cache.d.ts +5 -0
  93. package/lib/core/cache.js +6 -0
  94. package/lib/core/constants/adapters.d.ts +16 -1
  95. package/lib/core/constants/adapters.js +28 -8
  96. package/lib/core/constants/core.d.ts +14 -1
  97. package/lib/core/constants/core.js +18 -0
  98. package/lib/core/constants/swap-router.d.ts +83 -1
  99. package/lib/core/constants/swap-router.js +91 -1
  100. package/lib/core/constants/vaults.d.ts +57 -1
  101. package/lib/core/constants/vaults.js +66 -1
  102. package/lib/core/constants/web3.d.ts +4 -1
  103. package/lib/core/constants/web3.js +15 -5
  104. package/lib/core/errors/index.d.ts +38 -2
  105. package/lib/core/errors/index.js +38 -0
  106. package/lib/core/fetcher.d.ts +136 -2
  107. package/lib/core/fetcher.js +229 -25
  108. package/lib/core/helpers/adapters.d.ts +10 -1
  109. package/lib/core/helpers/adapters.js +11 -0
  110. package/lib/core/helpers/chain-address.d.ts +10 -0
  111. package/lib/core/helpers/chain-address.js +11 -0
  112. package/lib/core/helpers/core.d.ts +49 -4
  113. package/lib/core/helpers/core.js +74 -7
  114. package/lib/core/helpers/explorer-link.d.ts +15 -1
  115. package/lib/core/helpers/explorer-link.js +14 -0
  116. package/lib/core/helpers/signer.d.ts +27 -1
  117. package/lib/core/helpers/signer.js +39 -0
  118. package/lib/core/helpers/swap-router.d.ts +33 -1
  119. package/lib/core/helpers/swap-router.js +32 -0
  120. package/lib/core/helpers/vault-version.d.ts +2 -1
  121. package/lib/core/helpers/vault-version.js +2 -0
  122. package/lib/core/helpers/vaults.d.ts +9 -1
  123. package/lib/core/helpers/vaults.js +22 -8
  124. package/lib/core/helpers/web3.d.ts +154 -2
  125. package/lib/core/helpers/web3.js +192 -15
  126. package/lib/core/logger/index.d.ts +55 -0
  127. package/lib/core/logger/index.js +19 -0
  128. package/lib/core/logger/slack.d.ts +3 -0
  129. package/lib/core/logger/slack.js +3 -0
  130. package/lib/core/vault-metadata.d.ts +7 -1
  131. package/lib/core/vault-metadata.js +6 -0
  132. package/lib/core/version-check.d.ts +52 -0
  133. package/lib/core/version-check.js +82 -1
  134. package/lib/evm/methods/crossChainVault.d.ts +90 -0
  135. package/lib/evm/methods/crossChainVault.js +187 -2
  136. package/lib/evm/methods/crossChainVaultRegistry.d.ts +93 -0
  137. package/lib/evm/methods/crossChainVaultRegistry.js +240 -0
  138. package/lib/evm/methods/index.d.ts +1 -0
  139. package/lib/evm/methods/index.js +1 -0
  140. package/lib/evm/types/crossChain.d.ts +202 -0
  141. package/lib/evm/types/crossChain.js +12 -1
  142. package/lib/index.d.ts +16 -0
  143. package/lib/index.js +19 -0
  144. package/lib/main.d.ts +289 -6
  145. package/lib/main.js +312 -0
  146. package/lib/modules/api/index.d.ts +1 -0
  147. package/lib/modules/api/index.js +6 -0
  148. package/lib/modules/api/main.d.ts +52 -0
  149. package/lib/modules/api/main.js +130 -0
  150. package/lib/modules/sub-accounts/fetcher.d.ts +17 -2
  151. package/lib/modules/sub-accounts/fetcher.js +15 -0
  152. package/lib/modules/sub-accounts/main.d.ts +35 -2
  153. package/lib/modules/sub-accounts/main.js +39 -1
  154. package/lib/modules/sub-accounts/utils.d.ts +4 -1
  155. package/lib/modules/sub-accounts/utils.js +3 -0
  156. package/lib/modules/vaults/adapter.helpers.d.ts +21 -3
  157. package/lib/modules/vaults/adapter.helpers.js +34 -0
  158. package/lib/modules/vaults/fetcher.d.ts +45 -0
  159. package/lib/modules/vaults/fetcher.js +91 -4
  160. package/lib/modules/vaults/getters.d.ts +295 -0
  161. package/lib/modules/vaults/getters.js +567 -26
  162. package/lib/modules/vaults/index.d.ts +12 -0
  163. package/lib/modules/vaults/index.js +12 -0
  164. package/lib/modules/vaults/main.d.ts +292 -4
  165. package/lib/modules/vaults/main.js +382 -8
  166. package/lib/modules/vaults/read.actions.d.ts +170 -2
  167. package/lib/modules/vaults/read.actions.js +143 -0
  168. package/lib/modules/vaults/types.d.ts +34 -0
  169. package/lib/modules/vaults/utils/call-data-decoder.d.ts +48 -1
  170. package/lib/modules/vaults/utils/call-data-decoder.js +56 -0
  171. package/lib/modules/vaults/utils/date-utils.d.ts +39 -0
  172. package/lib/modules/vaults/utils/date-utils.js +47 -1
  173. package/lib/modules/vaults/utils.d.ts +85 -0
  174. package/lib/modules/vaults/utils.js +139 -7
  175. package/lib/modules/vaults/write.actions.d.ts +363 -3
  176. package/lib/modules/vaults/write.actions.js +399 -3
  177. package/lib/polyfills.js +4 -2
  178. package/lib/sdk.d.ts +23847 -0
  179. package/lib/services/coingecko/fetcher.d.ts +15 -1
  180. package/lib/services/coingecko/fetcher.js +30 -9
  181. package/lib/services/debank/fetcher.d.ts +15 -1
  182. package/lib/services/debank/fetcher.js +12 -0
  183. package/lib/services/debank/utils.d.ts +1 -1
  184. package/lib/services/debank/utils.js +18 -1
  185. package/lib/services/layerzero/deposits.d.ts +12 -1
  186. package/lib/services/layerzero/deposits.js +34 -11
  187. package/lib/services/layerzero/redeems.d.ts +11 -1
  188. package/lib/services/layerzero/redeems.js +13 -0
  189. package/lib/services/layerzero/utils.d.ts +8 -0
  190. package/lib/services/layerzero/utils.js +11 -0
  191. package/lib/services/octavfi/fetcher.d.ts +8 -1
  192. package/lib/services/octavfi/fetcher.js +25 -0
  193. package/lib/services/octavfi/types.d.ts +1 -1
  194. package/lib/services/octavfi/utils.d.ts +14 -2
  195. package/lib/services/octavfi/utils.js +44 -10
  196. package/lib/services/subgraph/fetcher.js +4 -2
  197. package/lib/services/subgraph/vaults.d.ts +12 -0
  198. package/lib/services/subgraph/vaults.js +119 -2
  199. package/lib/services/swap-quotes/index.d.ts +80 -0
  200. package/lib/services/swap-quotes/index.js +27 -1
  201. package/lib/services/swap-quotes/paraswap.d.ts +25 -0
  202. package/lib/services/swap-quotes/paraswap.js +22 -0
  203. package/lib/types/pools.d.ts +5 -2
  204. package/lib/types/staking.d.ts +1 -1
  205. package/lib/types/sub-accounts.d.ts +1 -1
  206. package/lib/types/subgraph.d.ts +10 -1
  207. package/lib/types/typed-contract.d.ts +64 -0
  208. package/lib/types/vaults.d.ts +163 -2
  209. package/lib/types/vaults.js +10 -0
  210. package/lib/types/web3.d.ts +9 -1
  211. package/lib/types/web3.js +1 -0
  212. package/lib/types/webserver.d.ts +47 -2
  213. package/package.json +6 -5
@@ -1,3 +1,28 @@
1
- import { IStellarDepositParams, IStellarRedeemParams } from './types';
1
+ /**
2
+ * Stellar Vault Actions
3
+ *
4
+ * Builds unsigned Soroban transactions for vault deposit/redeem operations.
5
+ * Returns assembled XDR (base64) for wallet signing (e.g. Freighter).
6
+ */
7
+ import type { IStellarDepositParams, IStellarRedeemParams } from './types';
8
+ /**
9
+ * Deposit assets into a Stellar vault (self-deposit).
10
+ *
11
+ * Builds an unsigned Soroban transaction invoking the vault's `deposit` function.
12
+ * All three address roles (receiver, from, operator) are set to senderAddress.
13
+ *
14
+ * Contract signature: deposit(assets: i128, receiver: Address, from: Address, operator: Address) -> i128
15
+ *
16
+ * @returns Base64-encoded XDR of the unsigned transaction, ready for wallet signing.
17
+ */
2
18
  export declare function handleStellarDeposit(params: IStellarDepositParams): Promise<string>;
19
+ /**
20
+ * Build an unsigned self-redeem Soroban transaction (receiver, owner, and
21
+ * operator all = `receiverAddress`). Assumes the deployed vault exposes
22
+ * `redeem(shares: i128, receiver, owner, operator) -> i128`; divergence
23
+ * surfaces as a generic Soroban simulation error.
24
+ *
25
+ * @returns Base64-encoded XDR ready for wallet signing; pass the signed
26
+ * XDR to {@link submitStellarTransaction}.
27
+ */
3
28
  export declare function handleStellarRedeem(params: IStellarRedeemParams): Promise<string>;
@@ -1,4 +1,10 @@
1
1
  "use strict";
2
+ /**
3
+ * Stellar Vault Actions
4
+ *
5
+ * Builds unsigned Soroban transactions for vault deposit/redeem operations.
6
+ * Returns assembled XDR (base64) for wallet signing (e.g. Freighter).
7
+ */
2
8
  Object.defineProperty(exports, "__esModule", { value: true });
3
9
  exports.handleStellarDeposit = handleStellarDeposit;
4
10
  exports.handleStellarRedeem = handleStellarRedeem;
@@ -16,6 +22,14 @@ function validateAccountAddress(address, label) {
16
22
  throw new core_1.AugustValidationError('INVALID_ADDRESS', `Invalid ${label} address: expected a Stellar account (G-prefix), got "${address}"`);
17
23
  }
18
24
  }
25
+ /**
26
+ * Build a self-operation Soroban transaction where all address roles
27
+ * (receiver, from/owner, operator) are set to the same user address.
28
+ *
29
+ * Note: This only supports self-operations. If delegated operations
30
+ * (distinct receiver/owner/operator) are needed in the future,
31
+ * a separate argument builder will be required.
32
+ */
19
33
  function buildSelfOperationArgs(amount, userAddress) {
20
34
  const userScVal = new stellar_sdk_1.Address(userAddress).toScVal();
21
35
  return [
@@ -25,6 +39,16 @@ function buildSelfOperationArgs(amount, userAddress) {
25
39
  userScVal,
26
40
  ];
27
41
  }
42
+ /**
43
+ * Deposit assets into a Stellar vault (self-deposit).
44
+ *
45
+ * Builds an unsigned Soroban transaction invoking the vault's `deposit` function.
46
+ * All three address roles (receiver, from, operator) are set to senderAddress.
47
+ *
48
+ * Contract signature: deposit(assets: i128, receiver: Address, from: Address, operator: Address) -> i128
49
+ *
50
+ * @returns Base64-encoded XDR of the unsigned transaction, ready for wallet signing.
51
+ */
28
52
  async function handleStellarDeposit(params) {
29
53
  const { contractId, amount, senderAddress, network } = params;
30
54
  validateContractAddress(contractId);
@@ -33,6 +57,15 @@ async function handleStellarDeposit(params) {
33
57
  const args = buildSelfOperationArgs((0, soroban_1.toBigIntAmount)(amount, 'deposit amount'), senderAddress);
34
58
  return (0, soroban_1.buildSorobanTx)(config, senderAddress, contractId, 'deposit', args);
35
59
  }
60
+ /**
61
+ * Build an unsigned self-redeem Soroban transaction (receiver, owner, and
62
+ * operator all = `receiverAddress`). Assumes the deployed vault exposes
63
+ * `redeem(shares: i128, receiver, owner, operator) -> i128`; divergence
64
+ * surfaces as a generic Soroban simulation error.
65
+ *
66
+ * @returns Base64-encoded XDR ready for wallet signing; pass the signed
67
+ * XDR to {@link submitStellarTransaction}.
68
+ */
36
69
  async function handleStellarRedeem(params) {
37
70
  const { contractId, shares, receiverAddress, network } = params;
38
71
  validateContractAddress(contractId);
@@ -1,3 +1,6 @@
1
+ /**
2
+ * Stellar Constants
3
+ */
1
4
  import type { IStellarNetwork } from './types';
2
5
  export declare const STELLAR_CHAIN_ID: number;
3
6
  export declare const STELLAR_CHAIN: {
@@ -8,10 +11,33 @@ export declare const STELLAR_CHAIN: {
8
11
  export declare const SOROBAN_RPC_URLS: Record<IStellarNetwork, string>;
9
12
  export declare const NETWORK_PASSPHRASES: Record<IStellarNetwork, string>;
10
13
  export declare const STELLAR_FALLBACK_DECIMALS = 7;
14
+ /**
15
+ * Validity window for a submitted Soroban invocation (seconds).
16
+ *
17
+ * This becomes the transaction's `maxTime`. Validators reject a tx whose
18
+ * `maxTime` has passed (`txTOO_LATE`), so the window must outlast the slowest
19
+ * realistic sign-then-submit path: hardware wallets, careful manual review,
20
+ * and institutional approval flows (e.g. Fordefi) that don't sign instantly.
21
+ * 10 minutes comfortably covers those while staying well inside the Soroban
22
+ * footprint/ledger-entry TTL, so the simulated footprint can't go stale first.
23
+ *
24
+ * The window is anchored to the *network* clock (see `getNetworkCloseTime` in
25
+ * soroban.ts), not the signer's `Date.now()`, so a skewed device clock can't
26
+ * make the deadline expire early.
27
+ */
11
28
  export declare const TX_TIMEOUT_SECONDS = 600;
29
+ /** Timeout for read-only Soroban simulation queries (seconds). */
12
30
  export declare const QUERY_TIMEOUT_SECONDS = 10;
31
+ /**
32
+ * Max fee ceiling in stroops (1_000_000 stroops = 0.1 XLM).
33
+ * assembleTransaction adjusts to the actual fee from simulation.
34
+ */
13
35
  export declare const MAX_FEE_STROOPS = "1000000";
36
+ /** Initial confirmation-poll interval (ms). Grows up to {@link POLL_INTERVAL_MAX_MS}. */
14
37
  export declare const POLL_INTERVAL_MS = 2000;
38
+ /** Cap for the backed-off confirmation-poll interval (ms). */
15
39
  export declare const POLL_INTERVAL_MAX_MS = 8000;
40
+ /** Multiplier applied to the poll interval after each NOT_FOUND poll. */
16
41
  export declare const POLL_INTERVAL_BACKOFF = 1.5;
42
+ /** Maximum number of polling attempts before timeout. */
17
43
  export declare const MAX_POLL_ATTEMPTS = 30;
@@ -1,8 +1,12 @@
1
1
  "use strict";
2
+ /**
3
+ * Stellar Constants
4
+ */
2
5
  Object.defineProperty(exports, "__esModule", { value: true });
3
6
  exports.MAX_POLL_ATTEMPTS = exports.POLL_INTERVAL_BACKOFF = exports.POLL_INTERVAL_MAX_MS = exports.POLL_INTERVAL_MS = exports.MAX_FEE_STROOPS = exports.QUERY_TIMEOUT_SECONDS = exports.TX_TIMEOUT_SECONDS = exports.STELLAR_FALLBACK_DECIMALS = exports.NETWORK_PASSPHRASES = exports.SOROBAN_RPC_URLS = exports.STELLAR_CHAIN = exports.STELLAR_CHAIN_ID = void 0;
4
7
  const stellar_sdk_1 = require("@stellar/stellar-sdk");
5
8
  const web3_1 = require("../../core/constants/web3");
9
+ // Synthetic chain ID for Stellar, sourced from SPECIAL_CHAINS. See core/constants/web3.ts for all non-EVM chain IDs.
6
10
  exports.STELLAR_CHAIN_ID = web3_1.SPECIAL_CHAINS.stellar.chainId;
7
11
  exports.STELLAR_CHAIN = web3_1.SPECIAL_CHAINS.stellar;
8
12
  exports.SOROBAN_RPC_URLS = {
@@ -13,12 +17,37 @@ exports.NETWORK_PASSPHRASES = {
13
17
  mainnet: stellar_sdk_1.Networks.PUBLIC,
14
18
  testnet: stellar_sdk_1.Networks.TESTNET,
15
19
  };
20
+ // Most Stellar/Soroban tokens use 7 decimal places (matching XLM's 10^7 stroops convention).
21
+ // Used as fallback when deposit_token_decimals is not available from backend metadata.
16
22
  exports.STELLAR_FALLBACK_DECIMALS = 7;
23
+ /**
24
+ * Validity window for a submitted Soroban invocation (seconds).
25
+ *
26
+ * This becomes the transaction's `maxTime`. Validators reject a tx whose
27
+ * `maxTime` has passed (`txTOO_LATE`), so the window must outlast the slowest
28
+ * realistic sign-then-submit path: hardware wallets, careful manual review,
29
+ * and institutional approval flows (e.g. Fordefi) that don't sign instantly.
30
+ * 10 minutes comfortably covers those while staying well inside the Soroban
31
+ * footprint/ledger-entry TTL, so the simulated footprint can't go stale first.
32
+ *
33
+ * The window is anchored to the *network* clock (see `getNetworkCloseTime` in
34
+ * soroban.ts), not the signer's `Date.now()`, so a skewed device clock can't
35
+ * make the deadline expire early.
36
+ */
17
37
  exports.TX_TIMEOUT_SECONDS = 600;
38
+ /** Timeout for read-only Soroban simulation queries (seconds). */
18
39
  exports.QUERY_TIMEOUT_SECONDS = 10;
40
+ /**
41
+ * Max fee ceiling in stroops (1_000_000 stroops = 0.1 XLM).
42
+ * assembleTransaction adjusts to the actual fee from simulation.
43
+ */
19
44
  exports.MAX_FEE_STROOPS = '1000000';
45
+ /** Initial confirmation-poll interval (ms). Grows up to {@link POLL_INTERVAL_MAX_MS}. */
20
46
  exports.POLL_INTERVAL_MS = 2000;
47
+ /** Cap for the backed-off confirmation-poll interval (ms). */
21
48
  exports.POLL_INTERVAL_MAX_MS = 8000;
49
+ /** Multiplier applied to the poll interval after each NOT_FOUND poll. */
22
50
  exports.POLL_INTERVAL_BACKOFF = 1.5;
51
+ /** Maximum number of polling attempts before timeout. */
23
52
  exports.MAX_POLL_ATTEMPTS = 30;
24
53
  //# sourceMappingURL=constants.js.map
@@ -1,6 +1,62 @@
1
+ /**
2
+ * Stellar Vault Getters
3
+ *
4
+ * Data fetching for Stellar vaults. Enriches backend metadata with on-chain
5
+ * total assets, total supply, and share decimals from Soroban RPC. Also
6
+ * provides user position queries and deposit preview (convertToShares).
7
+ * Falls back to backend TVL for total assets, zero for total supply, and
8
+ * STELLAR_FALLBACK_DECIMALS for share decimals when on-chain queries fail.
9
+ */
1
10
  import type { ITokenizedVault, IVault } from '../../types';
2
11
  import type { IVaultBaseOptions } from '../../modules/vaults/types';
3
12
  import type { IStellarNetwork, IStellarUserPosition } from './types';
13
+ /**
14
+ * Build a unified IVault from backend + on-chain data for Stellar vaults.
15
+ * Reads total assets and total supply from the Soroban contract via RPC.
16
+ * Falls back to backend `latest_reported_tvl` for total assets, or zero
17
+ * for total supply, when on-chain queries fail.
18
+ */
4
19
  export declare const getStellarVault: (tokenizedVault: ITokenizedVault, _options: IVaultBaseOptions) => Promise<IVault>;
20
+ /**
21
+ * Get user position for a Stellar vault.
22
+ * Queries the vault contract's balance(address) and decimals() functions via Soroban RPC.
23
+ *
24
+ * Returns `{ shares, decimals, decimalsFromFallback }` on success (shares may be
25
+ * '0' for zero balance), or null when the balance query fails. The two reads are
26
+ * independent: a `decimals()` failure does NOT null the result — instead
27
+ * `decimals` falls back to STELLAR_FALLBACK_DECIMALS (7) and
28
+ * `decimalsFromFallback` is set to `true` so callers can tell a fabricated 7
29
+ * apart from a genuine 7-decimal vault.
30
+ *
31
+ * Why this matters: an ERC4626 offset vault has share decimals = asset + offset
32
+ * (e.g. 13). A consumer that sizes a redeem trusting a silent fallback 7 would
33
+ * under-redeem by `10^offset`. Callers that settle a redeem from this position
34
+ * MUST refuse (surface an error) when `decimalsFromFallback` is `true` rather
35
+ * than trusting `decimals`. See AUGUST-6381 (follow-up to AUGUST-6380).
36
+ *
37
+ * @param vaultAddress - Stellar vault contract ID (C… address)
38
+ * @param walletAddress - User's Stellar account (G… address); validated upfront
39
+ * @param network - 'mainnet' | 'testnet' (defaults to 'mainnet')
40
+ * @returns The position, or `null` if the balance read failed or was unparseable.
41
+ * @throws AugustValidationError on an invalid `walletAddress`.
42
+ * @example
43
+ * ```ts
44
+ * const pos = await getStellarUserPosition(vault, wallet, 'mainnet');
45
+ * if (!pos || pos.decimalsFromFallback) {
46
+ * // Refuse to size a redeem — share scale is not authoritatively known.
47
+ * throw new Error('Stellar share decimals unresolved');
48
+ * }
49
+ * const human = Number(pos.shares) / 10 ** pos.decimals;
50
+ * ```
51
+ */
5
52
  export declare const getStellarUserPosition: (vaultAddress: string, walletAddress: string, network?: IStellarNetwork) => Promise<IStellarUserPosition | null>;
53
+ /**
54
+ * Query the vault's `convert_to_shares` to preview how many shares a deposit
55
+ * amount would yield. Returns the raw share amount as a string, or null on
56
+ * failure.
57
+ *
58
+ * @param vaultAddress Stellar contract ID (C… address)
59
+ * @param rawAmount Deposit amount in the deposit token's smallest unit
60
+ * @param network 'mainnet' | 'testnet'
61
+ */
6
62
  export declare const convertToShares: (vaultAddress: string, rawAmount: string, network?: IStellarNetwork) => Promise<string | null>;
@@ -1,4 +1,13 @@
1
1
  "use strict";
2
+ /**
3
+ * Stellar Vault Getters
4
+ *
5
+ * Data fetching for Stellar vaults. Enriches backend metadata with on-chain
6
+ * total assets, total supply, and share decimals from Soroban RPC. Also
7
+ * provides user position queries and deposit preview (convertToShares).
8
+ * Falls back to backend TVL for total assets, zero for total supply, and
9
+ * STELLAR_FALLBACK_DECIMALS for share decimals when on-chain queries fail.
10
+ */
2
11
  Object.defineProperty(exports, "__esModule", { value: true });
3
12
  exports.convertToShares = exports.getStellarUserPosition = exports.getStellarVault = void 0;
4
13
  const stellar_sdk_1 = require("@stellar/stellar-sdk");
@@ -6,6 +15,16 @@ const core_1 = require("../../core");
6
15
  const utils_1 = require("../../modules/vaults/utils");
7
16
  const constants_1 = require("./constants");
8
17
  const soroban_1 = require("./soroban");
18
+ /**
19
+ * Parse an ScVal into a share-decimals value, reporting whether the
20
+ * authoritative on-chain value was available.
21
+ *
22
+ * Returns `{ decimals, fromFallback }`. When the `decimals()` retval is missing
23
+ * or unparseable, `decimals` is STELLAR_FALLBACK_DECIMALS (7) and `fromFallback`
24
+ * is `true` — the signal callers need to avoid trusting a fabricated scale (a
25
+ * silent 7 under-redeems ERC4626 offset vaults; see AUGUST-6381). A successful
26
+ * parse returns the on-chain value with `fromFallback: false`.
27
+ */
9
28
  function parseDecimals(scVal, context, vaultAddress) {
10
29
  if (!scVal) {
11
30
  core_1.Logger.log.error(context, 'Decimals not available — using fallback (financial values may be incorrect)', {
@@ -26,9 +45,19 @@ function parseDecimals(scVal, context, vaultAddress) {
26
45
  return { decimals: constants_1.STELLAR_FALLBACK_DECIMALS, fromFallback: true };
27
46
  }
28
47
  }
48
+ /**
49
+ * Parse an ScVal into a decimals number, returning the fallback on failure.
50
+ * Thin wrapper over {@link parseDecimals} for callers that only need the value
51
+ * (the fallback is already surfaced via logs). Prefer `parseDecimals` when the
52
+ * caller must distinguish a fallback from an authoritative read.
53
+ */
29
54
  function parseDecimalsOrFallback(scVal, context, vaultAddress) {
30
55
  return parseDecimals(scVal, context, vaultAddress).decimals;
31
56
  }
57
+ /**
58
+ * Resolve the Stellar network for a vault from its backend metadata.
59
+ * Logs a warning when falling back to mainnet.
60
+ */
32
61
  function resolveNetwork(tokenizedVault) {
33
62
  const meta = tokenizedVault.stellar_vault_metadata;
34
63
  const networkName = meta?.network_name;
@@ -43,6 +72,12 @@ function resolveNetwork(tokenizedVault) {
43
72
  }
44
73
  return 'mainnet';
45
74
  }
75
+ /**
76
+ * Build a unified IVault from backend + on-chain data for Stellar vaults.
77
+ * Reads total assets and total supply from the Soroban contract via RPC.
78
+ * Falls back to backend `latest_reported_tvl` for total assets, or zero
79
+ * for total supply, when on-chain queries fail.
80
+ */
46
81
  const getStellarVault = async (tokenizedVault, _options) => {
47
82
  const stellarMetadata = tokenizedVault.stellar_vault_metadata;
48
83
  const depositDecimals = stellarMetadata?.deposit_token_decimals ?? constants_1.STELLAR_FALLBACK_DECIMALS;
@@ -53,6 +88,7 @@ const getStellarVault = async (tokenizedVault, _options) => {
53
88
  STELLAR_FALLBACK_DECIMALS: constants_1.STELLAR_FALLBACK_DECIMALS,
54
89
  });
55
90
  }
91
+ // Attempt on-chain queries for total assets, total supply, and share decimals
56
92
  const network = resolveNetwork(tokenizedVault);
57
93
  const config = (0, soroban_1.resolveNetworkConfig)(network);
58
94
  const [assetsResult, supplyResult, decimalsResult] = await Promise.all([
@@ -60,6 +96,7 @@ const getStellarVault = async (tokenizedVault, _options) => {
60
96
  (0, soroban_1.queryContract)(config, tokenizedVault.address, 'total_supply'),
61
97
  (0, soroban_1.queryContract)(config, tokenizedVault.address, 'decimals'),
62
98
  ]);
99
+ // Share token decimals may differ from deposit token decimals
63
100
  const shareDecimals = parseDecimalsOrFallback(decimalsResult, 'getStellarVault', tokenizedVault.address);
64
101
  let totalAssets;
65
102
  if (assetsResult) {
@@ -114,8 +151,41 @@ const getStellarVault = async (tokenizedVault, _options) => {
114
151
  });
115
152
  };
116
153
  exports.getStellarVault = getStellarVault;
154
+ /**
155
+ * Get user position for a Stellar vault.
156
+ * Queries the vault contract's balance(address) and decimals() functions via Soroban RPC.
157
+ *
158
+ * Returns `{ shares, decimals, decimalsFromFallback }` on success (shares may be
159
+ * '0' for zero balance), or null when the balance query fails. The two reads are
160
+ * independent: a `decimals()` failure does NOT null the result — instead
161
+ * `decimals` falls back to STELLAR_FALLBACK_DECIMALS (7) and
162
+ * `decimalsFromFallback` is set to `true` so callers can tell a fabricated 7
163
+ * apart from a genuine 7-decimal vault.
164
+ *
165
+ * Why this matters: an ERC4626 offset vault has share decimals = asset + offset
166
+ * (e.g. 13). A consumer that sizes a redeem trusting a silent fallback 7 would
167
+ * under-redeem by `10^offset`. Callers that settle a redeem from this position
168
+ * MUST refuse (surface an error) when `decimalsFromFallback` is `true` rather
169
+ * than trusting `decimals`. See AUGUST-6381 (follow-up to AUGUST-6380).
170
+ *
171
+ * @param vaultAddress - Stellar vault contract ID (C… address)
172
+ * @param walletAddress - User's Stellar account (G… address); validated upfront
173
+ * @param network - 'mainnet' | 'testnet' (defaults to 'mainnet')
174
+ * @returns The position, or `null` if the balance read failed or was unparseable.
175
+ * @throws AugustValidationError on an invalid `walletAddress`.
176
+ * @example
177
+ * ```ts
178
+ * const pos = await getStellarUserPosition(vault, wallet, 'mainnet');
179
+ * if (!pos || pos.decimalsFromFallback) {
180
+ * // Refuse to size a redeem — share scale is not authoritatively known.
181
+ * throw new Error('Stellar share decimals unresolved');
182
+ * }
183
+ * const human = Number(pos.shares) / 10 ** pos.decimals;
184
+ * ```
185
+ */
117
186
  const getStellarUserPosition = async (vaultAddress, walletAddress, network = 'mainnet') => {
118
187
  const config = (0, soroban_1.resolveNetworkConfig)(network);
188
+ // Validate address upfront — invalid input is a caller bug, not an RPC issue
119
189
  let userAddress;
120
190
  try {
121
191
  userAddress = new stellar_sdk_1.Address(walletAddress);
@@ -124,6 +194,7 @@ const getStellarUserPosition = async (vaultAddress, walletAddress, network = 'ma
124
194
  throw new core_1.AugustValidationError('INVALID_ADDRESS', `getStellarUserPosition: invalid walletAddress "${walletAddress}": ${String(addrErr)}`, { cause: addrErr });
125
195
  }
126
196
  try {
197
+ // Fetch balance and decimals in parallel — they're independent queries
127
198
  const [balanceResult, decimalsResult] = await Promise.all([
128
199
  (0, soroban_1.queryContract)(config, vaultAddress, 'balance', [userAddress.toScVal()]),
129
200
  (0, soroban_1.queryContract)(config, vaultAddress, 'decimals'),
@@ -164,7 +235,17 @@ const getStellarUserPosition = async (vaultAddress, walletAddress, network = 'ma
164
235
  }
165
236
  };
166
237
  exports.getStellarUserPosition = getStellarUserPosition;
238
+ /**
239
+ * Query the vault's `convert_to_shares` to preview how many shares a deposit
240
+ * amount would yield. Returns the raw share amount as a string, or null on
241
+ * failure.
242
+ *
243
+ * @param vaultAddress Stellar contract ID (C… address)
244
+ * @param rawAmount Deposit amount in the deposit token's smallest unit
245
+ * @param network 'mainnet' | 'testnet'
246
+ */
167
247
  const convertToShares = async (vaultAddress, rawAmount, network = 'mainnet') => {
248
+ // Validate address upfront — invalid input is a caller bug, not an RPC issue
168
249
  try {
169
250
  new stellar_sdk_1.Address(vaultAddress);
170
251
  }
@@ -1,3 +1,11 @@
1
+ /**
2
+ * Stellar Adapter for August SDK
3
+ *
4
+ * Provides Stellar vault operations: deposit, redeem, position queries,
5
+ * and on-chain data fetching via Soroban RPC.
6
+ *
7
+ * @module StellarAdapter
8
+ */
1
9
  import * as StellarConstants from './constants';
2
10
  import * as StellarGetters from './getters';
3
11
  import * as StellarActions from './actions';
@@ -14,16 +22,78 @@ export declare const Stellar: {
14
22
  submit: typeof StellarSubmit;
15
23
  getters: typeof StellarGetters;
16
24
  };
25
+ /**
26
+ * Stellar Adapter for August SDK
27
+ *
28
+ * @example
29
+ * ```
30
+ * const adapter = new StellarAdapter('testnet');
31
+ * const xdr = await adapter.vaultDeposit({
32
+ * contractId: 'CBGWW5...',
33
+ * amount: '1000000',
34
+ * senderAddress: 'GDLZ...',
35
+ * });
36
+ * // Sign xdr with wallet (e.g. Freighter), then submit via adapter.submitTransaction()
37
+ * ```
38
+ */
17
39
  declare class StellarAdapter {
18
40
  private _network;
19
41
  constructor(network?: IStellarNetwork);
20
42
  get network(): IStellarNetwork;
21
43
  isStellarAddress(address: string): boolean;
22
44
  getExplorerLink(id: string, type?: 'contract' | 'account' | 'tx'): string;
45
+ /**
46
+ * Build an unsigned deposit transaction for a Stellar vault.
47
+ * @returns Base64-encoded XDR of the unsigned transaction.
48
+ */
23
49
  vaultDeposit(params: Omit<IStellarDepositParams, 'network'>): Promise<string>;
50
+ /**
51
+ * Build an unsigned redeem transaction for a Stellar vault.
52
+ * @returns Base64-encoded XDR of the unsigned transaction.
53
+ */
24
54
  vaultRedeem(params: Omit<IStellarRedeemParams, 'network'>): Promise<string>;
55
+ /**
56
+ * Submit a signed Soroban transaction and poll until the network confirms it.
57
+ *
58
+ * Submits on the network this adapter was constructed with, so `signedXdr`
59
+ * must be signed for that same network.
60
+ *
61
+ * @param signedXdr - Base64-encoded XDR of the signed transaction.
62
+ * @returns The transaction hash once the network confirms it as successful.
63
+ * @throws {@link AugustTimeoutError} when the transaction is not confirmed
64
+ * within the poll budget (`MAX_POLL_ATTEMPTS`).
65
+ * @throws {@link AugustSDKError} when the RPC rejects the submission or the
66
+ * transaction confirms as failed. Its `context` carries `{ network, status }`
67
+ * plus, when the result XDR decodes, a `resultCode` string holding the
68
+ * transaction-level reason (e.g. `"txBadSeq"`, `"txTooLate"`); `resultCode`
69
+ * is `undefined` when the code cannot be decoded.
70
+ * @example
71
+ * ```ts
72
+ * try {
73
+ * const hash = await adapter.submitTransaction(signedXdr);
74
+ * } catch (err) {
75
+ * if (err instanceof AugustSDKError && err.context?.resultCode === 'txBadSeq') {
76
+ * // stale sequence number — rebuild the transaction and resubmit
77
+ * }
78
+ * }
79
+ * ```
80
+ */
25
81
  submitTransaction(signedXdr: string): Promise<string>;
82
+ /**
83
+ * Get user's vault share balance.
84
+ *
85
+ * @returns The position `{ shares, decimals, decimalsFromFallback }`, or null
86
+ * if the balance read fails. When `decimalsFromFallback` is `true` the
87
+ * `decimals()` read failed and `decimals` is the fallback (7) — callers sizing
88
+ * a redeem MUST refuse rather than trust it (see AUGUST-6381).
89
+ */
26
90
  getUserPosition(vaultAddress: string, walletAddress: string): Promise<IStellarUserPosition | null>;
91
+ /**
92
+ * Preview how many vault shares a deposit amount would yield.
93
+ * @param vaultAddress Stellar contract ID (C… address)
94
+ * @param rawAmount Deposit amount in the deposit token's smallest unit
95
+ * @returns Raw share amount as a string, or null if query fails.
96
+ */
27
97
  convertToShares(vaultAddress: string, rawAmount: string): Promise<string | null>;
28
98
  }
29
99
  export default StellarAdapter;
@@ -1,4 +1,12 @@
1
1
  "use strict";
2
+ /**
3
+ * Stellar Adapter for August SDK
4
+ *
5
+ * Provides Stellar vault operations: deposit, redeem, position queries,
6
+ * and on-chain data fetching via Soroban RPC.
7
+ *
8
+ * @module StellarAdapter
9
+ */
2
10
  var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
11
  if (k2 === undefined) k2 = k;
4
12
  var desc = Object.getOwnPropertyDescriptor(m, k);
@@ -46,7 +54,22 @@ exports.Stellar = {
46
54
  submit: StellarSubmit,
47
55
  getters: StellarGetters,
48
56
  };
57
+ /**
58
+ * Stellar Adapter for August SDK
59
+ *
60
+ * @example
61
+ * ```
62
+ * const adapter = new StellarAdapter('testnet');
63
+ * const xdr = await adapter.vaultDeposit({
64
+ * contractId: 'CBGWW5...',
65
+ * amount: '1000000',
66
+ * senderAddress: 'GDLZ...',
67
+ * });
68
+ * // Sign xdr with wallet (e.g. Freighter), then submit via adapter.submitTransaction()
69
+ * ```
70
+ */
49
71
  class StellarAdapter {
72
+ _network;
50
73
  constructor(network = 'mainnet') {
51
74
  this._network = network;
52
75
  }
@@ -59,24 +82,72 @@ class StellarAdapter {
59
82
  getExplorerLink(id, type) {
60
83
  return utils_1.StellarUtils.getExplorerLink({ id, type, network: this._network });
61
84
  }
85
+ /**
86
+ * Build an unsigned deposit transaction for a Stellar vault.
87
+ * @returns Base64-encoded XDR of the unsigned transaction.
88
+ */
62
89
  async vaultDeposit(params) {
63
90
  return StellarActions.handleStellarDeposit({
64
91
  ...params,
65
92
  network: this._network,
66
93
  });
67
94
  }
95
+ /**
96
+ * Build an unsigned redeem transaction for a Stellar vault.
97
+ * @returns Base64-encoded XDR of the unsigned transaction.
98
+ */
68
99
  async vaultRedeem(params) {
69
100
  return StellarActions.handleStellarRedeem({
70
101
  ...params,
71
102
  network: this._network,
72
103
  });
73
104
  }
105
+ /**
106
+ * Submit a signed Soroban transaction and poll until the network confirms it.
107
+ *
108
+ * Submits on the network this adapter was constructed with, so `signedXdr`
109
+ * must be signed for that same network.
110
+ *
111
+ * @param signedXdr - Base64-encoded XDR of the signed transaction.
112
+ * @returns The transaction hash once the network confirms it as successful.
113
+ * @throws {@link AugustTimeoutError} when the transaction is not confirmed
114
+ * within the poll budget (`MAX_POLL_ATTEMPTS`).
115
+ * @throws {@link AugustSDKError} when the RPC rejects the submission or the
116
+ * transaction confirms as failed. Its `context` carries `{ network, status }`
117
+ * plus, when the result XDR decodes, a `resultCode` string holding the
118
+ * transaction-level reason (e.g. `"txBadSeq"`, `"txTooLate"`); `resultCode`
119
+ * is `undefined` when the code cannot be decoded.
120
+ * @example
121
+ * ```ts
122
+ * try {
123
+ * const hash = await adapter.submitTransaction(signedXdr);
124
+ * } catch (err) {
125
+ * if (err instanceof AugustSDKError && err.context?.resultCode === 'txBadSeq') {
126
+ * // stale sequence number — rebuild the transaction and resubmit
127
+ * }
128
+ * }
129
+ * ```
130
+ */
74
131
  async submitTransaction(signedXdr) {
75
132
  return StellarSubmit.submitStellarTransaction(signedXdr, this._network);
76
133
  }
134
+ /**
135
+ * Get user's vault share balance.
136
+ *
137
+ * @returns The position `{ shares, decimals, decimalsFromFallback }`, or null
138
+ * if the balance read fails. When `decimalsFromFallback` is `true` the
139
+ * `decimals()` read failed and `decimals` is the fallback (7) — callers sizing
140
+ * a redeem MUST refuse rather than trust it (see AUGUST-6381).
141
+ */
77
142
  async getUserPosition(vaultAddress, walletAddress) {
78
143
  return StellarGetters.getStellarUserPosition(vaultAddress, walletAddress, this._network);
79
144
  }
145
+ /**
146
+ * Preview how many vault shares a deposit amount would yield.
147
+ * @param vaultAddress Stellar contract ID (C… address)
148
+ * @param rawAmount Deposit amount in the deposit token's smallest unit
149
+ * @returns Raw share amount as a string, or null if query fails.
150
+ */
80
151
  async convertToShares(vaultAddress, rawAmount) {
81
152
  return StellarGetters.convertToShares(vaultAddress, rawAmount, this._network);
82
153
  }
@@ -1,11 +1,31 @@
1
- import { xdr, rpc } from '@stellar/stellar-sdk';
1
+ /**
2
+ * Shared Soroban RPC utilities
3
+ *
4
+ * Common transaction building and read-only query helpers used by
5
+ * actions, submit, and getters modules.
6
+ */
7
+ import { type xdr, rpc } from '@stellar/stellar-sdk';
2
8
  import type { IStellarNetwork } from './types';
9
+ /** Resolved network configuration for Soroban RPC calls. */
3
10
  export interface ISorobanNetworkConfig {
4
11
  rpcUrl: string;
5
12
  passphrase: string;
6
13
  }
7
14
  export declare function createServer(rpcUrl: string): rpc.Server;
15
+ /**
16
+ * Resolve RPC URL and network passphrase for a Stellar network.
17
+ */
8
18
  export declare function resolveNetworkConfig(network: IStellarNetwork): ISorobanNetworkConfig;
19
+ /**
20
+ * Validate and convert a string amount to a non-negative BigInt.
21
+ * Throws a descriptive error if the value is not a valid non-negative integer string.
22
+ */
9
23
  export declare function toBigIntAmount(value: string, label: string): bigint;
10
24
  export declare function queryContract(config: ISorobanNetworkConfig, contractId: string, method: string, args?: xdr.ScVal[]): Promise<xdr.ScVal | null>;
25
+ /**
26
+ * Build an unsigned Soroban contract invocation transaction.
27
+ * Fetches the real source account from the network (the account must exist and be funded).
28
+ * Simulates via Soroban RPC to attach resource footprint and auth entries,
29
+ * using MAX_FEE_STROOPS as the fee ceiling and incorporating the simulated resource fee.
30
+ */
11
31
  export declare function buildSorobanTx(config: ISorobanNetworkConfig, sourceAddress: string, contractId: string, method: string, args: xdr.ScVal[]): Promise<string>;