@augustdigital/sdk 6.0.1 → 7.0.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 (71) hide show
  1. package/lib/adapters/evm/getters.d.ts +1 -1
  2. package/lib/adapters/evm/getters.js +14 -19
  3. package/lib/adapters/evm/index.d.ts +8 -1
  4. package/lib/adapters/evm/index.js +24 -0
  5. package/lib/adapters/solana/index.d.ts +4 -4
  6. package/lib/adapters/solana/utils.d.ts +5 -4
  7. package/lib/adapters/solana/utils.js +82 -45
  8. package/lib/adapters/solana/vault.actions.d.ts +2 -2
  9. package/lib/adapters/solana/vault.actions.js +112 -74
  10. package/lib/adapters/stellar/actions.js +3 -2
  11. package/lib/adapters/stellar/constants.d.ts +2 -0
  12. package/lib/adapters/stellar/constants.js +3 -1
  13. package/lib/adapters/stellar/getters.js +2 -2
  14. package/lib/adapters/stellar/soroban.js +19 -8
  15. package/lib/adapters/stellar/submit.js +16 -6
  16. package/lib/adapters/stellar/utils.d.ts +2 -1
  17. package/lib/adapters/stellar/utils.js +7 -15
  18. package/lib/adapters/sui/utils.d.ts +1 -1
  19. package/lib/adapters/sui/utils.js +3 -7
  20. package/lib/core/analytics/chain-name.d.ts +1 -0
  21. package/lib/core/analytics/chain-name.js +26 -0
  22. package/lib/core/analytics/env.d.ts +4 -0
  23. package/lib/core/analytics/env.js +33 -0
  24. package/lib/core/analytics/index.d.ts +6 -2
  25. package/lib/core/analytics/index.js +16 -1
  26. package/lib/core/analytics/instrumentation.js +56 -48
  27. package/lib/core/analytics/method-taxonomy.d.ts +3 -0
  28. package/lib/core/analytics/method-taxonomy.js +82 -0
  29. package/lib/core/analytics/metrics.js +18 -42
  30. package/lib/core/analytics/sanitize.d.ts +1 -0
  31. package/lib/core/analytics/sanitize.js +34 -0
  32. package/lib/core/analytics/sentry-runtime.d.ts +4 -0
  33. package/lib/core/analytics/sentry-runtime.js +78 -0
  34. package/lib/core/analytics/sentry.d.ts +7 -1
  35. package/lib/core/analytics/sentry.js +107 -51
  36. package/lib/core/analytics/types.d.ts +2 -0
  37. package/lib/core/analytics/version.d.ts +1 -1
  38. package/lib/core/analytics/version.js +1 -1
  39. package/lib/core/base.class.d.ts +2 -1
  40. package/lib/core/base.class.js +5 -1
  41. package/lib/core/cache.d.ts +4 -0
  42. package/lib/core/cache.js +25 -0
  43. package/lib/core/fetcher.d.ts +4 -4
  44. package/lib/core/fetcher.js +49 -60
  45. package/lib/core/helpers/chain-address.d.ts +3 -0
  46. package/lib/core/helpers/chain-address.js +36 -0
  47. package/lib/core/helpers/explorer-link.d.ts +2 -0
  48. package/lib/core/helpers/explorer-link.js +11 -0
  49. package/lib/core/helpers/vault-version.d.ts +4 -0
  50. package/lib/core/helpers/vault-version.js +59 -0
  51. package/lib/core/helpers/vaults.d.ts +3 -4
  52. package/lib/core/helpers/vaults.js +12 -62
  53. package/lib/core/helpers/web3.d.ts +6 -6
  54. package/lib/core/helpers/web3.js +142 -79
  55. package/lib/core/logger/slack.js +2 -2
  56. package/lib/core/vault-metadata.d.ts +6 -0
  57. package/lib/core/vault-metadata.js +36 -0
  58. package/lib/evm/methods/crossChainVault.js +72 -16
  59. package/lib/evm/types/crossChain.d.ts +4 -0
  60. package/lib/evm/types/crossChain.js +6 -0
  61. package/lib/modules/vaults/fetcher.d.ts +1 -6
  62. package/lib/modules/vaults/fetcher.js +27 -36
  63. package/lib/modules/vaults/getters.d.ts +1 -1
  64. package/lib/modules/vaults/getters.js +3 -2
  65. package/lib/modules/vaults/read.actions.d.ts +27 -0
  66. package/lib/modules/vaults/read.actions.js +220 -0
  67. package/lib/modules/vaults/utils/date-utils.js +1 -2
  68. package/lib/modules/vaults/utils.js +57 -36
  69. package/lib/modules/vaults/write.actions.d.ts +35 -2
  70. package/lib/modules/vaults/write.actions.js +254 -94
  71. package/package.json +3 -1
@@ -1,4 +1,4 @@
1
1
  import { ITokenizedVault } from '../../types';
2
- import { IVaultBaseOptions } from '../../modules/vaults';
2
+ import { IVaultBaseOptions } from '../../modules/vaults/types';
3
3
  export declare const getEvmVaultV1: (tokenizedVault: ITokenizedVault, options: IVaultBaseOptions) => Promise<import("../../types").IVault>;
4
4
  export declare const getEvmVaultV2: (tokenizedVault: ITokenizedVault, options: IVaultBaseOptions) => Promise<import("../../types").IVault>;
@@ -6,7 +6,6 @@ const core_1 = require("../../core");
6
6
  const utils_1 = require("../../modules/vaults/utils");
7
7
  const TokenizedVaultV2_1 = require("../../abis/TokenizedVaultV2");
8
8
  const TokenizedVaultV2Receipt_1 = require("../../abis/TokenizedVaultV2Receipt");
9
- const TokenizedVaultV2WhitelistedAssets_1 = require("../../abis/TokenizedVaultV2WhitelistedAssets");
10
9
  const getEvmVaultV1 = async (tokenizedVault, options) => {
11
10
  const vault = tokenizedVault.address;
12
11
  if (!vault) {
@@ -109,29 +108,25 @@ const getEvmVaultV2 = async (tokenizedVault, options) => {
109
108
  return vaultContract[f]();
110
109
  }));
111
110
  const receiptAddress = vaultContractCalls[core_1.VAULT_FUNCTIONS_V2.length - 1];
111
+ const whitelistedAssetsAddress = vaultContractCalls[0];
112
112
  const reciptContract = (0, core_1.createContract)({
113
113
  address: receiptAddress,
114
114
  abi: TokenizedVaultV2Receipt_1.ABI_TOKENIZED_VAULT_V2_RECEIPT,
115
115
  provider,
116
116
  });
117
- const receiptContractCalls = await Promise.all(core_1.VAULT_FUNCTIONS_V2_RECEIPT.map((f) => {
118
- if (f === 'symbol') {
119
- return (0, core_1.getSymbol)(provider, receiptAddress, false);
120
- }
121
- if (f === 'decimals') {
122
- return (0, core_1.getDecimals)(provider, receiptAddress, false);
123
- }
124
- return reciptContract[f]();
125
- }));
126
- const whitelistedAssetsAddress = vaultContractCalls[0];
127
- const whitelistedAssetsContract = (0, core_1.createContract)({
128
- address: whitelistedAssetsAddress,
129
- abi: TokenizedVaultV2WhitelistedAssets_1.ABI_TOKENIZED_VAULT_V2_WHITELISTED_ASSETS,
130
- provider,
131
- });
132
- const whitelistedAssetsContractCalls = await Promise.all(core_1.VAULT_FUNCTIONS_V2_WHITELISTED_ASSETS.map((f) => {
133
- return whitelistedAssetsContract[f]();
134
- }));
117
+ const [receiptContractCalls, whitelistedList] = await Promise.all([
118
+ Promise.all(core_1.VAULT_FUNCTIONS_V2_RECEIPT.map((f) => {
119
+ if (f === 'symbol') {
120
+ return (0, core_1.getSymbol)(provider, receiptAddress, false);
121
+ }
122
+ if (f === 'decimals') {
123
+ return (0, core_1.getDecimals)(provider, receiptAddress, false);
124
+ }
125
+ return reciptContract[f]();
126
+ })),
127
+ (0, core_1.getWhitelistedAssets)(provider, whitelistedAssetsAddress),
128
+ ]);
129
+ const whitelistedAssetsContractCalls = [whitelistedList];
135
130
  const combinedCalls = [
136
131
  ...vaultContractCalls,
137
132
  ...receiptContractCalls,
@@ -1,4 +1,5 @@
1
- import { IContractWriteOptions, INativeDepositOptions } from '../../modules/vaults/write.actions';
1
+ import { IContractWriteOptions, INativeDepositOptions, ApproveResult } from '../../modules/vaults/write.actions';
2
+ import { IPreviewDepositOptions, IPreviewRedeemOptions, IAllowanceOptions, IBalanceOfOptions, IMaxDepositOptions } from '../../modules/vaults/read.actions';
2
3
  import { CompatibleSigner } from '../../core/helpers/signer';
3
4
  import { IAddress } from '../../types';
4
5
  export * from './getters';
@@ -9,6 +10,7 @@ declare class EVMAdapter {
9
10
  setSigner(signer: CompatibleSigner): void;
10
11
  private getSigner;
11
12
  vaultApprove(options: IContractWriteOptions): Promise<string>;
13
+ approve(options: IContractWriteOptions): Promise<ApproveResult>;
12
14
  vaultAllowance(options: IContractWriteOptions): Promise<import("../../types").INormalizedNumber>;
13
15
  vaultDeposit(options: IContractWriteOptions): Promise<string>;
14
16
  vaultRequestRedeem(options: IContractWriteOptions): Promise<string>;
@@ -37,5 +39,10 @@ declare class EVMAdapter {
37
39
  vault: IAddress;
38
40
  depositCapAmount?: bigint;
39
41
  }): Promise<import("../../types").INormalizedNumber>;
42
+ previewDeposit(options: IPreviewDepositOptions): Promise<bigint>;
43
+ previewRedeem(options: IPreviewRedeemOptions): Promise<bigint>;
44
+ allowance(options: IAllowanceOptions): Promise<bigint>;
45
+ balanceOf(options: IBalanceOfOptions): Promise<bigint>;
46
+ maxDeposit(options: IMaxDepositOptions): Promise<bigint>;
40
47
  }
41
48
  export default EVMAdapter;
@@ -40,6 +40,10 @@ class EVMAdapter {
40
40
  const signer = await this.getSigner();
41
41
  return (0, write_actions_1.vaultApprove)(signer, options);
42
42
  }
43
+ async approve(options) {
44
+ const signer = await this.getSigner();
45
+ return (0, write_actions_1.approve)(signer, options);
46
+ }
43
47
  async vaultAllowance(options) {
44
48
  const signer = await this.getSigner();
45
49
  return (0, read_actions_1.vaultAllowance)(signer, options);
@@ -76,6 +80,26 @@ class EVMAdapter {
76
80
  const signer = await this.getSigner();
77
81
  return (0, read_actions_1.getRemainingAllocations)(signer, options);
78
82
  }
83
+ async previewDeposit(options) {
84
+ const signer = await this.getSigner();
85
+ return (0, read_actions_1.previewDeposit)(signer, options);
86
+ }
87
+ async previewRedeem(options) {
88
+ const signer = await this.getSigner();
89
+ return (0, read_actions_1.previewRedeem)(signer, options);
90
+ }
91
+ async allowance(options) {
92
+ const signer = await this.getSigner();
93
+ return (0, read_actions_1.allowance)(signer, options);
94
+ }
95
+ async balanceOf(options) {
96
+ const signer = await this.getSigner();
97
+ return (0, read_actions_1.balanceOf)(signer, options);
98
+ }
99
+ async maxDeposit(options) {
100
+ const signer = await this.getSigner();
101
+ return (0, read_actions_1.maxDeposit)(signer, options);
102
+ }
79
103
  }
80
104
  exports.default = EVMAdapter;
81
105
  //# sourceMappingURL=index.js.map
@@ -11,7 +11,7 @@ export declare const Solana: {
11
11
  signature: string;
12
12
  type: "tx" | "address" | "token";
13
13
  } & import("./types").ISolanaConnectionOptions) => string;
14
- isSolanaAddress: (address: string) => boolean;
14
+ isSolanaAddress: typeof import("./utils").isSolanaAddress;
15
15
  isSolana: (signature: string) => boolean;
16
16
  getProgram: ({ provider, idl, programId, network, }: {
17
17
  idl: any;
@@ -68,7 +68,7 @@ export declare const Solana: {
68
68
  amount: string;
69
69
  decimals: number | null;
70
70
  }>;
71
- getBestRpcEndpoint: ({ endpoint, network, connection, }: import("./types").ISolanaConnectionOptions) => Promise<`https://${string}` | "http://127.0.0.1:8899">;
71
+ getBestRpcEndpoint: ({ endpoint, network, connection, }: import("./types").ISolanaConnectionOptions) => Promise<"http://127.0.0.1:8899" | `https://${string}`>;
72
72
  fallbackDecimals: number;
73
73
  fallbackNetwork: import("../..").ISolanaNetwork;
74
74
  programIds: {
@@ -136,8 +136,8 @@ declare class SolanaAdapter {
136
136
  amount: string;
137
137
  decimals: number | null;
138
138
  }>;
139
- vaultDeposit(vaultProgramId: PublicKey | string, idl: any, publicKey: PublicKey | string, depositAmount: number, sendTransaction: (transaction: Transaction | web3.VersionedTransaction, connection: Connection, options?: SendTransactionOptions) => Promise<web3.TransactionSignature>, vaultAddress?: PublicKey | string): Promise<any>;
140
- vaultRedeem(vaultProgramId: PublicKey | string, idl: any, publicKey: PublicKey | string, redeemShares: number, sendTransaction: (transaction: Transaction | web3.VersionedTransaction, connection: Connection, options?: SendTransactionOptions) => Promise<web3.TransactionSignature>, vaultAddress?: PublicKey | string): Promise<any>;
139
+ vaultDeposit(vaultProgramId: PublicKey | string, idl: any, publicKey: PublicKey | string, depositAmount: number | bigint, sendTransaction: (transaction: Transaction | web3.VersionedTransaction, connection: Connection, options?: SendTransactionOptions) => Promise<web3.TransactionSignature>, vaultAddress?: PublicKey | string): Promise<any>;
140
+ vaultRedeem(vaultProgramId: PublicKey | string, idl: any, publicKey: PublicKey | string, redeemShares: number | bigint, sendTransaction: (transaction: Transaction | web3.VersionedTransaction, connection: Connection, options?: SendTransactionOptions) => Promise<web3.TransactionSignature>, vaultAddress?: PublicKey | string): Promise<any>;
141
141
  getProgramId(type: 'vault'): string;
142
142
  }
143
143
  export default SolanaAdapter;
@@ -1,17 +1,18 @@
1
- import { AnchorProvider, Program, web3 } from '@coral-xyz/anchor';
1
+ import { AnchorProvider, BN, Program, web3 } from '@coral-xyz/anchor';
2
2
  import { PublicKey, Transaction } from '@solana/web3.js';
3
3
  import { ISolanaConnectionOptions, ISolanaVaultState } from './types';
4
4
  declare function getExplorerLink({ signature, type, network, }: {
5
5
  signature: string;
6
6
  type: 'tx' | 'address' | 'token';
7
7
  } & ISolanaConnectionOptions): string;
8
- declare function isSolanaAddress(address: string): boolean;
8
+ import { isSolanaAddress } from '../../core/helpers/chain-address';
9
+ export { isSolanaAddress };
9
10
  declare function isSolana(signature: string): boolean;
10
11
  declare function getProgram({ provider, idl, programId, network, }: {
11
12
  idl: any;
12
13
  programId?: string;
13
14
  } & ISolanaConnectionOptions): Program<any>;
14
- declare function getBestRpcEndpoint({ endpoint, network, connection, }: ISolanaConnectionOptions): Promise<`https://${string}` | "http://127.0.0.1:8899">;
15
+ declare function getBestRpcEndpoint({ endpoint, network, connection, }: ISolanaConnectionOptions): Promise<"http://127.0.0.1:8899" | `https://${string}`>;
15
16
  declare function getProvider({ connection, publicKey, signTransaction, }: {
16
17
  publicKey: PublicKey;
17
18
  signTransaction: (<T extends Transaction | web3.VersionedTransaction>(transaction: T) => Promise<T>) | undefined;
@@ -75,6 +76,7 @@ declare function fetchUserShareBalanceRaw({ connection, publicKey, shareMint, }:
75
76
  declare function resolveProgramId(vaultAddress: string, solanaMetadata?: {
76
77
  program_id?: string;
77
78
  } | null): string;
79
+ export declare function uiAmountToRawBn(uiAmount: number, decimals: number): BN;
78
80
  export declare const SolanaUtils: {
79
81
  getExplorerLink: typeof getExplorerLink;
80
82
  isSolanaAddress: typeof isSolanaAddress;
@@ -112,4 +114,3 @@ export declare const SolanaUtils: {
112
114
  getVaultMints: typeof getVaultMints;
113
115
  resolveProgramId: typeof resolveProgramId;
114
116
  };
115
- export {};
@@ -1,6 +1,7 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.SolanaUtils = void 0;
3
+ exports.SolanaUtils = exports.isSolanaAddress = void 0;
4
+ exports.uiAmountToRawBn = uiAmountToRawBn;
4
5
  const anchor_1 = require("@coral-xyz/anchor");
5
6
  const web3_js_1 = require("@solana/web3.js");
6
7
  const ethers_1 = require("ethers");
@@ -10,25 +11,14 @@ function getExplorerLink({ signature, type = 'tx', network = constants_1.fallbac
10
11
  const baseUrl = 'https://solscan.io';
11
12
  return `${baseUrl}/${type}/${signature}?cluster=${network}`;
12
13
  }
13
- function isSolanaAddress(address) {
14
- if (!address)
15
- return false;
16
- if ((0, ethers_1.isAddress)(address))
17
- return false;
18
- try {
19
- new web3_js_1.PublicKey(address);
20
- return true;
21
- }
22
- catch (_e) {
23
- return false;
24
- }
25
- }
14
+ const chain_address_1 = require("../../core/helpers/chain-address");
15
+ Object.defineProperty(exports, "isSolanaAddress", { enumerable: true, get: function () { return chain_address_1.isSolanaAddress; } });
26
16
  function isSolana(signature) {
27
17
  if (!signature || typeof signature !== 'string')
28
18
  return false;
29
19
  if ((0, ethers_1.isAddress)(signature))
30
20
  return false;
31
- if (isSolanaAddress(signature))
21
+ if ((0, chain_address_1.isSolanaAddress)(signature))
32
22
  return false;
33
23
  const base58Chars = '123456789ABCDEFGHJKLMNPQRSTUVWXYZabcdefghijkmnopqrstuvwxyz';
34
24
  const isValidBase58 = signature
@@ -67,12 +57,12 @@ async function getBestRpcEndpoint({ endpoint, network = constants_1.fallbackNetw
67
57
  if (primaryTest.success) {
68
58
  return primaryEndpoint;
69
59
  }
70
- console.warn('⚠️ Primary RPC endpoint failed, using fallback:', fallbackEndpoint);
60
+ core_1.Logger.log.warn('getBestRpcEndpoint', '⚠️ Primary RPC endpoint failed, using fallback:', fallbackEndpoint);
71
61
  return fallbackEndpoint;
72
62
  }
73
63
  function getProvider({ connection, publicKey, signTransaction, }) {
74
64
  if (!publicKey || !signTransaction) {
75
- throw new Error('Wallet not connected');
65
+ throw new core_1.AugustValidationError('INVALID_INPUT', 'Wallet not connected: publicKey and signTransaction are required for write operations');
76
66
  }
77
67
  return new anchor_1.AnchorProvider(connection, {
78
68
  publicKey,
@@ -87,10 +77,10 @@ function getReadOnlyProvider({ connection }) {
87
77
  const dummyWallet = {
88
78
  publicKey: web3_js_1.PublicKey.default,
89
79
  signTransaction: async (_tx) => {
90
- throw new Error('Cannot sign transactions with read-only provider');
80
+ throw new core_1.AugustValidationError('INVALID_INPUT', 'Cannot sign transactions with read-only provider');
91
81
  },
92
82
  signAllTransactions: async (_txs) => {
93
- throw new Error('Cannot sign transactions with read-only provider');
83
+ throw new core_1.AugustValidationError('INVALID_INPUT', 'Cannot sign transactions with read-only provider');
94
84
  },
95
85
  };
96
86
  return new anchor_1.AnchorProvider(connection, dummyWallet, {
@@ -99,21 +89,21 @@ function getReadOnlyProvider({ connection }) {
99
89
  }
100
90
  function deriveVaultStatePda(vaultProgramId) {
101
91
  if (!vaultProgramId)
102
- throw new Error('Vault program ID missing');
92
+ throw new core_1.AugustValidationError('INVALID_INPUT', 'Vault program ID missing');
103
93
  const _vaultProgramId = new web3_js_1.PublicKey(vaultProgramId);
104
94
  const [pda] = web3_js_1.PublicKey.findProgramAddressSync([new TextEncoder().encode('VAULT_STATE')], _vaultProgramId);
105
95
  return pda;
106
96
  }
107
97
  function deriveShareMintPda(vaultProgramId) {
108
98
  if (!vaultProgramId)
109
- throw new Error('Vault program ID missing');
99
+ throw new core_1.AugustValidationError('INVALID_INPUT', 'Vault program ID missing');
110
100
  const _vaultProgramId = new web3_js_1.PublicKey(vaultProgramId);
111
101
  const [pda] = web3_js_1.PublicKey.findProgramAddressSync([new TextEncoder().encode('mint')], _vaultProgramId);
112
102
  return pda;
113
103
  }
114
104
  function deriveVaultTokenAtaPda(vaultProgramId, depositMint, vaultVersion) {
115
105
  if (!(vaultProgramId && depositMint))
116
- throw new Error('Vault program ID or deposit mint missing');
106
+ throw new core_1.AugustValidationError('INVALID_INPUT', 'Vault program ID or deposit mint missing');
117
107
  const _vaultProgramId = new web3_js_1.PublicKey(vaultProgramId);
118
108
  const seeds = [
119
109
  Buffer.from('token_vault'),
@@ -123,7 +113,7 @@ function deriveVaultTokenAtaPda(vaultProgramId, depositMint, vaultVersion) {
123
113
  if (!Number.isInteger(vaultVersion) ||
124
114
  vaultVersion < 0 ||
125
115
  vaultVersion > 255) {
126
- throw new Error(`Invalid vault version ${vaultVersion}: must be an integer between 0 and 255`);
116
+ throw new core_1.AugustValidationError('INVALID_INPUT', `Invalid vault version ${vaultVersion}: must be an integer between 0 and 255`);
127
117
  }
128
118
  seeds.push(Buffer.from([vaultVersion]));
129
119
  }
@@ -141,7 +131,7 @@ async function getVaultState({ provider, connection, vaultProgramId, vaultAddres
141
131
  if (cachedData)
142
132
  return cachedData;
143
133
  if (!vaultProgramId) {
144
- throw new Error('Please enter a vault program ID');
134
+ throw new core_1.AugustValidationError('INVALID_INPUT', 'Please enter a vault program ID');
145
135
  }
146
136
  const vaultStatePda = vaultAddress
147
137
  ? new web3_js_1.PublicKey(vaultAddress)
@@ -163,7 +153,9 @@ async function getVaultState({ provider, connection, vaultProgramId, vaultAddres
163
153
  }
164
154
  }
165
155
  catch (mintError) {
166
- console.error('Error fetching deposit mint decimals:', mintError);
156
+ core_1.Logger.log.error('getVaultState', mintError, {
157
+ message: 'Error fetching deposit mint decimals',
158
+ });
167
159
  }
168
160
  }
169
161
  await (0, core_1.setSafeCache)(cacheKey, returnObj);
@@ -171,7 +163,9 @@ async function getVaultState({ provider, connection, vaultProgramId, vaultAddres
171
163
  }
172
164
  catch (e) {
173
165
  const error = e;
174
- console.error('Error reading vault state:', error);
166
+ core_1.Logger.log.error('getVaultState', error, {
167
+ message: 'Error reading vault state',
168
+ });
175
169
  return returnObj;
176
170
  }
177
171
  }
@@ -186,7 +180,7 @@ async function getVaultStateReadOnly({ vaultProgramId, vaultAddress, connection,
186
180
  if (cachedData)
187
181
  return cachedData;
188
182
  if (!vaultProgramId) {
189
- throw new Error('Please enter a vault program ID');
183
+ throw new core_1.AugustValidationError('INVALID_INPUT', 'Please enter a vault program ID');
190
184
  }
191
185
  const _vaultProgramId = new web3_js_1.PublicKey(vaultProgramId);
192
186
  const vaultStatePda = vaultAddress
@@ -194,7 +188,7 @@ async function getVaultStateReadOnly({ vaultProgramId, vaultAddress, connection,
194
188
  : deriveVaultStatePda(_vaultProgramId);
195
189
  const accountInfo = await connection.getAccountInfo(vaultStatePda);
196
190
  if (!accountInfo) {
197
- console.warn('Vault state account not found');
191
+ core_1.Logger.log.warn('getVaultStateReadOnly', 'Vault state account not found');
198
192
  return returnObj;
199
193
  }
200
194
  try {
@@ -215,12 +209,16 @@ async function getVaultStateReadOnly({ vaultProgramId, vaultAddress, connection,
215
209
  }
216
210
  }
217
211
  catch (mintError) {
218
- console.error('Error fetching deposit mint decimals:', mintError);
212
+ core_1.Logger.log.error('getVaultStateReadOnly', mintError, {
213
+ message: 'Error fetching deposit mint decimals',
214
+ });
219
215
  }
220
216
  }
221
217
  }
222
218
  catch (programError) {
223
- console.error('Error creating program with read-only provider:', programError);
219
+ core_1.Logger.log.error('getVaultStateReadOnly', programError, {
220
+ message: 'Error creating program with read-only provider',
221
+ });
224
222
  returnObj.vaultState = null;
225
223
  }
226
224
  await (0, core_1.setSafeCache)(cacheKey, returnObj);
@@ -228,7 +226,9 @@ async function getVaultStateReadOnly({ vaultProgramId, vaultAddress, connection,
228
226
  }
229
227
  catch (e) {
230
228
  const error = e;
231
- console.error('Error reading vault state:', error);
229
+ core_1.Logger.log.error('getVaultStateReadOnly', error, {
230
+ message: 'Error reading vault state',
231
+ });
232
232
  return returnObj;
233
233
  }
234
234
  }
@@ -239,7 +239,7 @@ async function getVaultMints({ vaultProgramId, vaultAddress, connection, idl, })
239
239
  if (cachedData)
240
240
  return cachedData;
241
241
  if (!vaultProgramId) {
242
- throw new Error('Please enter a vault program ID');
242
+ throw new core_1.AugustValidationError('INVALID_INPUT', 'Please enter a vault program ID');
243
243
  }
244
244
  const _vaultProgramId = new web3_js_1.PublicKey(vaultProgramId);
245
245
  const vaultStatePda = vaultAddress
@@ -264,12 +264,19 @@ async function getVaultMints({ vaultProgramId, vaultAddress, connection, idl, })
264
264
  }
265
265
  catch (e) {
266
266
  const error = e;
267
- console.error('Error reading vault mints:', error);
268
- return {
269
- depositMint: '',
270
- shareMint: '',
271
- vaultVersion: undefined,
272
- };
267
+ const cause = error?.message || String(error);
268
+ core_1.Logger.log.error('getVaultMints', error, {
269
+ message: 'Error reading vault mints',
270
+ vaultProgramId: String(vaultProgramId),
271
+ vaultAddress: vaultAddress ? String(vaultAddress) : undefined,
272
+ });
273
+ throw new core_1.AugustSDKError('UNKNOWN', `Failed to read vault mints from on-chain state: ${cause}`, {
274
+ cause: error,
275
+ context: {
276
+ vaultProgramId: String(vaultProgramId),
277
+ vaultAddress: vaultAddress ? String(vaultAddress) : undefined,
278
+ },
279
+ });
273
280
  }
274
281
  }
275
282
  async function getToken({ mintAddress, endpoint, connection, }) {
@@ -349,13 +356,15 @@ async function getToken({ mintAddress, endpoint, connection, }) {
349
356
  }
350
357
  }
351
358
  catch (vaultError) {
352
- console.log('Not a vault program or error querying vault:', vaultError);
359
+ core_1.Logger.log.info('getToken', 'Not a vault program or error querying vault:', vaultError);
353
360
  }
354
361
  }
355
362
  return null;
356
363
  }
357
364
  catch (error) {
358
- console.error('Error fetching token metadata:', error);
365
+ core_1.Logger.log.error('getToken', error, {
366
+ message: 'Error fetching token metadata',
367
+ });
359
368
  return null;
360
369
  }
361
370
  }
@@ -368,7 +377,9 @@ async function getTokenSymbol({ endpoint, mintAddress, }) {
368
377
  return null;
369
378
  }
370
379
  catch (error) {
371
- console.error('Error fetching token symbol:', error);
380
+ core_1.Logger.log.error('getTokenSymbol', error, {
381
+ message: 'Error fetching token symbol',
382
+ });
372
383
  return null;
373
384
  }
374
385
  }
@@ -390,7 +401,9 @@ async function fetchUserTokenBalance({ connection, publicKey, depositMint, }) {
390
401
  }
391
402
  catch (e) {
392
403
  const error = e;
393
- console.error('Error fetching user token balance:', error);
404
+ core_1.Logger.log.error('fetchUserTokenBalance', error, {
405
+ message: 'Error fetching user token balance',
406
+ });
394
407
  return '0';
395
408
  }
396
409
  }
@@ -412,7 +425,9 @@ async function fetchUserShareBalance({ connection, publicKey, shareMint, }) {
412
425
  }
413
426
  catch (e) {
414
427
  const error = e;
415
- console.error('Error fetching user share balance:', error);
428
+ core_1.Logger.log.error('fetchUserShareBalance', error, {
429
+ message: 'Error fetching user share balance',
430
+ });
416
431
  return 0;
417
432
  }
418
433
  }
@@ -435,16 +450,38 @@ async function fetchUserShareBalanceRaw({ connection, publicKey, shareMint, }) {
435
450
  }
436
451
  catch (e) {
437
452
  const error = e;
438
- console.error('Error fetching raw user share balance:', error);
453
+ core_1.Logger.log.error('fetchUserShareBalanceRaw', error, {
454
+ message: 'Error fetching raw user share balance',
455
+ });
439
456
  return { amount: '0', decimals: null };
440
457
  }
441
458
  }
442
459
  function resolveProgramId(vaultAddress, solanaMetadata) {
443
460
  return solanaMetadata?.program_id || vaultAddress;
444
461
  }
462
+ function uiAmountToRawBn(uiAmount, decimals) {
463
+ if (!Number.isFinite(uiAmount)) {
464
+ throw new core_1.AugustValidationError('INVALID_INPUT', `uiAmountToRawBn: amount must be finite, got ${uiAmount}`);
465
+ }
466
+ if (uiAmount < 0) {
467
+ throw new core_1.AugustValidationError('INVALID_INPUT', `uiAmountToRawBn: amount must be non-negative, got ${uiAmount}`);
468
+ }
469
+ if (!Number.isInteger(decimals) || decimals < 0) {
470
+ throw new core_1.AugustValidationError('INVALID_INPUT', `uiAmountToRawBn: decimals must be a non-negative integer, got ${decimals}`);
471
+ }
472
+ const uiStr = uiAmount.toString();
473
+ const expansion = uiStr.includes('e') || uiStr.includes('E')
474
+ ? uiAmount.toFixed(Math.max(decimals, 20)).replace(/\.?0+$/, '')
475
+ : uiStr;
476
+ const [whole, fraction = ''] = expansion.split('.');
477
+ const truncated = fraction.slice(0, decimals);
478
+ const paddedFraction = truncated.padEnd(decimals, '0');
479
+ const raw = (whole + paddedFraction).replace(/^0+/, '') || '0';
480
+ return new anchor_1.BN(raw);
481
+ }
445
482
  exports.SolanaUtils = {
446
483
  getExplorerLink,
447
- isSolanaAddress,
484
+ isSolanaAddress: chain_address_1.isSolanaAddress,
448
485
  isSolana,
449
486
  getProgram,
450
487
  getProvider,
@@ -7,7 +7,7 @@ export declare function handleSolanaDeposit({ provider, connection, network, vau
7
7
  vaultAddress?: PublicKey | string;
8
8
  idl: any;
9
9
  publicKey: PublicKey | string;
10
- depositAmount: number;
10
+ depositAmount: number | bigint;
11
11
  sendTransaction: (transaction: Transaction | web3.VersionedTransaction, connection: Connection, options?: SendTransactionOptions) => Promise<web3.TransactionSignature>;
12
12
  } & ISolanaConnectionOptions): Promise<any>;
13
13
  export declare function handleSolanaRedeem({ provider, connection, vaultProgramId, vaultAddress, publicKey, redeemShares, sendTransaction, idl, }: {
@@ -15,6 +15,6 @@ export declare function handleSolanaRedeem({ provider, connection, vaultProgramI
15
15
  vaultProgramId: PublicKey | string;
16
16
  vaultAddress?: PublicKey | string;
17
17
  publicKey: PublicKey | string;
18
- redeemShares: number;
18
+ redeemShares: number | bigint;
19
19
  sendTransaction: (transaction: Transaction | web3.VersionedTransaction, connection: Connection, options?: SendTransactionOptions) => Promise<web3.TransactionSignature>;
20
20
  } & ISolanaConnectionOptions): Promise<any>;