@xswap-link/sdk 0.10.8 → 0.10.9

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 (69) hide show
  1. package/.eslintrc.json +10 -1
  2. package/CHANGELOG.md +6 -0
  3. package/dist/index.global.js +331 -331
  4. package/dist/index.js +9 -9
  5. package/dist/index.mjs +9 -9
  6. package/package.json +6 -3
  7. package/src/components/Swap/SwapView/ConfirmationView/TxOverview/index.tsx +106 -9
  8. package/src/components/Swap/SwapView/SwapButton/index.tsx +11 -11
  9. package/src/constants/index.ts +19 -2
  10. package/src/context/SwapProvider.tsx +7 -3
  11. package/src/services/api.ts +1 -0
  12. package/src/services/svm/README.md +483 -0
  13. package/src/services/svm/bindings/accounts/AllowedOfframp.ts +73 -0
  14. package/src/services/svm/bindings/accounts/Config.ts +153 -0
  15. package/src/services/svm/bindings/accounts/DestChain.ts +113 -0
  16. package/src/services/svm/bindings/accounts/Nonce.ts +97 -0
  17. package/src/services/svm/bindings/accounts/index.ts +15 -0
  18. package/src/services/svm/bindings/accounts/tokenAdminRegistry.ts +128 -0
  19. package/src/services/svm/bindings/errors/anchor.ts +773 -0
  20. package/src/services/svm/bindings/errors/custom.ts +375 -0
  21. package/src/services/svm/bindings/errors/index.ts +62 -0
  22. package/src/services/svm/bindings/instructions/ccipSend.ts +112 -0
  23. package/src/services/svm/bindings/instructions/getFee.ts +73 -0
  24. package/src/services/svm/bindings/instructions/index.ts +4 -0
  25. package/src/services/svm/bindings/programId.ts +6 -0
  26. package/src/services/svm/bindings/types/BaseChain.ts +92 -0
  27. package/src/services/svm/bindings/types/BaseConfig.ts +184 -0
  28. package/src/services/svm/bindings/types/CodeVersion.ts +88 -0
  29. package/src/services/svm/bindings/types/CrossChainAmount.ts +53 -0
  30. package/src/services/svm/bindings/types/DestChainConfig.ts +76 -0
  31. package/src/services/svm/bindings/types/DestChainState.ts +76 -0
  32. package/src/services/svm/bindings/types/GetFeeResult.ts +72 -0
  33. package/src/services/svm/bindings/types/LockOrBurnInV1.ts +102 -0
  34. package/src/services/svm/bindings/types/LockOrBurnOutV1.ts +79 -0
  35. package/src/services/svm/bindings/types/RampMessageHeader.ts +94 -0
  36. package/src/services/svm/bindings/types/RateLimitConfig.ts +72 -0
  37. package/src/services/svm/bindings/types/RateLimitTokenBucket.ts +76 -0
  38. package/src/services/svm/bindings/types/ReleaseOrMintInV1.ts +156 -0
  39. package/src/services/svm/bindings/types/ReleaseOrMintOutV1.ts +53 -0
  40. package/src/services/svm/bindings/types/RemoteAddress.ts +61 -0
  41. package/src/services/svm/bindings/types/RemoteConfig.ts +86 -0
  42. package/src/services/svm/bindings/types/RestoreOnAction.ts +120 -0
  43. package/src/services/svm/bindings/types/SVM2AnyMessage.ts +128 -0
  44. package/src/services/svm/bindings/types/SVM2AnyRampMessage.ts +166 -0
  45. package/src/services/svm/bindings/types/SVM2AnyTokenTransfer.ts +118 -0
  46. package/src/services/svm/bindings/types/SVMTokenAmount.ts +64 -0
  47. package/src/services/svm/bindings/types/index.ts +78 -0
  48. package/src/services/svm/core/client/accounts.ts +97 -0
  49. package/src/services/svm/core/client/events.ts +95 -0
  50. package/src/services/svm/core/client/fee.ts +279 -0
  51. package/src/services/svm/core/client/index.ts +150 -0
  52. package/src/services/svm/core/client/send.ts +607 -0
  53. package/src/services/svm/core/client/utils.ts +131 -0
  54. package/src/services/svm/core/models.ts +236 -0
  55. package/src/services/svm/index.ts +32 -0
  56. package/src/services/svm/utils/conversion.ts +62 -0
  57. package/src/services/svm/utils/errors.ts +51 -0
  58. package/src/services/svm/utils/keypair.ts +19 -0
  59. package/src/services/svm/utils/logger.ts +171 -0
  60. package/src/services/svm/utils/pdas/common.ts +15 -0
  61. package/src/services/svm/utils/pdas/feeQuoter.ts +68 -0
  62. package/src/services/svm/utils/pdas/index.ts +12 -0
  63. package/src/services/svm/utils/pdas/receiver.ts +58 -0
  64. package/src/services/svm/utils/pdas/rmnRemote.ts +23 -0
  65. package/src/services/svm/utils/pdas/router.ts +328 -0
  66. package/src/services/svm/utils/pdas/tokenpool.ts +161 -0
  67. package/src/services/svm/utils/transaction.ts +132 -0
  68. package/src/utils/validation.ts +7 -3
  69. package/tsconfig.json +2 -1
@@ -0,0 +1,132 @@
1
+ import {
2
+ Commitment,
3
+ Connection,
4
+ Transaction,
5
+ TransactionInstruction,
6
+ } from "@solana/web3.js";
7
+ import { CCIPContext } from "../core/models";
8
+ import { TxOptions } from "../tokenpools/abstract";
9
+ import { createErrorEnhancer } from "./errors";
10
+ import { Logger } from "./logger";
11
+
12
+ /**
13
+ * Extended options for transaction execution that includes error context
14
+ */
15
+ export interface TransactionExecutionOptions extends TxOptions {
16
+ /**
17
+ * Optional context information to include in error messages
18
+ * This helps pinpoint the source and details of transaction failures
19
+ */
20
+ errorContext?: Record<string, string>;
21
+
22
+ /**
23
+ * Optional operation name for logging and error reporting
24
+ */
25
+ operationName?: string;
26
+ }
27
+
28
+ /**
29
+ * Extracts transaction options from various input structures
30
+ * Handles both nested txOptions and direct transaction parameters
31
+ *
32
+ * @param options Any object that might contain transaction options
33
+ * @returns Normalized TxOptions or undefined if no options found
34
+ */
35
+ export function extractTxOptions(options?: any): TxOptions | undefined {
36
+ if (!options) {
37
+ return undefined;
38
+ }
39
+
40
+ // If the options object has a txOptions property, use that
41
+ if (options.txOptions) {
42
+ return options.txOptions;
43
+ }
44
+
45
+ // If the options object itself has tx option properties, extract those
46
+ const txOptions: TxOptions = {};
47
+
48
+ // Check for and copy over common tx option properties
49
+ if (options.skipPreflight !== undefined) txOptions.skipPreflight = options.skipPreflight;
50
+ if (options.preflightCommitment !== undefined) txOptions.preflightCommitment = options.preflightCommitment;
51
+ if (options.maxRetries !== undefined) txOptions.maxRetries = options.maxRetries;
52
+ if (options.commitment !== undefined) txOptions.commitment = options.commitment;
53
+ if (options.confirmationCommitment !== undefined) txOptions.confirmationCommitment = options.confirmationCommitment;
54
+
55
+ // Return undefined if no tx options were found
56
+ return Object.keys(txOptions).length > 0 ? txOptions : undefined;
57
+ }
58
+
59
+ /**
60
+ * Executes a transaction with the given instructions
61
+ * Handles the entire transaction lifecycle: creation, signing, sending, and confirmation
62
+ *
63
+ * @param context CCIP context with provider and connection
64
+ * @param instructions Array of transaction instructions to execute
65
+ * @param options Transaction execution options including commitment levels and error context
66
+ * @returns Transaction signature
67
+ */
68
+ export async function executeTransaction(
69
+ context: CCIPContext,
70
+ instructions: TransactionInstruction[],
71
+ options?: TransactionExecutionOptions
72
+ ): Promise<string> {
73
+ const logger = context.logger || { debug: () => {}, info: () => {}, warn: () => {}, error: () => {} } as Logger;
74
+ const connection = context.provider.connection;
75
+ const txOptions = extractTxOptions(options);
76
+
77
+ // Setup error enhancement
78
+ const errorContext = options?.errorContext || {};
79
+ const operationName = options?.operationName || 'executeTransaction';
80
+ const enhanceError = createErrorEnhancer(logger);
81
+
82
+ try {
83
+ logger.debug(
84
+ `Starting transaction execution${operationName ? ` for ${operationName}` : ''}`
85
+ );
86
+
87
+ // Get the latest blockhash with configured commitment
88
+ const { blockhash, lastValidBlockHeight } = await connection.getLatestBlockhash({
89
+ commitment: txOptions?.commitment ?? "finalized",
90
+ });
91
+
92
+ // Create transaction with the instructions
93
+ const transaction = new Transaction();
94
+ transaction.recentBlockhash = blockhash;
95
+ transaction.feePayer = context.provider.getAddress();
96
+
97
+ // Add all instructions to the transaction
98
+ for (const instruction of instructions) {
99
+ transaction.add(instruction);
100
+ }
101
+
102
+ // Sign the transaction
103
+ const signedTx = await context.provider.signTransaction(transaction);
104
+
105
+ // Send the transaction with configurable options
106
+ const signature = await connection.sendRawTransaction(signedTx.serialize(), {
107
+ skipPreflight: txOptions?.skipPreflight ?? false,
108
+ preflightCommitment: txOptions?.preflightCommitment ?? ("processed" as Commitment),
109
+ maxRetries: txOptions?.maxRetries ?? 5,
110
+ });
111
+
112
+ logger.debug(`Transaction sent: ${signature}`);
113
+
114
+ // Wait for transaction confirmation
115
+ await connection.confirmTransaction(
116
+ {
117
+ signature,
118
+ blockhash,
119
+ lastValidBlockHeight,
120
+ },
121
+ txOptions?.confirmationCommitment ?? ("confirmed" as Commitment)
122
+ );
123
+
124
+ logger.debug(`Transaction confirmed: ${signature}`);
125
+ return signature;
126
+ } catch (error) {
127
+ throw enhanceError(error, {
128
+ operation: operationName,
129
+ ...errorContext,
130
+ });
131
+ }
132
+ }
@@ -4,7 +4,7 @@ import {
4
4
  DEFAULT_SOURCE_CHAIN_ID,
5
5
  DEFAULT_SOURCE_TOKEN_ADDR,
6
6
  } from "@src/constants";
7
- import { BridgeTokensDictionary, Chain, Token } from "@src/models";
7
+ import { BridgeTokensDictionary, Chain, Ecosystem, Token } from "@src/models";
8
8
 
9
9
  export const getDefaultSwapSourceChain = ({
10
10
  supportedChains,
@@ -355,7 +355,9 @@ const mapToValidPathBridge = ({
355
355
  const isBridgeable =
356
356
  Object.keys(
357
357
  bridgeTokensDictionary[newSourceChain.chainId]?.[
358
- newSourceToken.address.toLowerCase()
358
+ newSourceChain.ecosystem === Ecosystem.SOLANA
359
+ ? newSourceToken.address
360
+ : newSourceToken.address.toLowerCase()
359
361
  ] || {},
360
362
  ).length > 0;
361
363
 
@@ -402,7 +404,9 @@ const mapToValidPathBridge = ({
402
404
  if (newSourceToken && newSourceChain && newTargetChain) {
403
405
  const correspondingTokenAddress =
404
406
  bridgeTokensDictionary[newSourceChain.chainId]?.[
405
- newSourceToken.address.toLowerCase()
407
+ newSourceChain.ecosystem === Ecosystem.SOLANA
408
+ ? newSourceToken.address
409
+ : newSourceToken.address.toLowerCase()
406
410
  ]?.[newTargetChain.chainId];
407
411
 
408
412
  const correspondingToken = newTargetChain.tokens.find(
package/tsconfig.json CHANGED
@@ -18,5 +18,6 @@
18
18
  "@src/*": ["./src/*"]
19
19
  }
20
20
  },
21
- "include": ["src"]
21
+ "include": ["src"],
22
+ "exclude": ["src/services/svm"]
22
23
  }