@xswap-link/sdk 0.10.7 → 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.
- package/.eslintrc.json +10 -1
- package/.github/workflows/publish.yml +10 -10
- package/CHANGELOG.md +12 -0
- package/dist/index.global.js +331 -331
- package/dist/index.js +9 -9
- package/dist/index.mjs +9 -9
- package/package.json +6 -3
- package/src/components/Swap/SwapView/ConfirmationView/TxOverview/index.tsx +106 -9
- package/src/components/Swap/SwapView/SwapButton/index.tsx +11 -11
- package/src/components/TxDataCard/TxDataCardUI/index.tsx +12 -18
- package/src/components/TxDataCard/index.tsx +6 -2
- package/src/constants/index.ts +19 -2
- package/src/context/SwapProvider.tsx +7 -3
- package/src/services/api.ts +1 -0
- package/src/services/solana/jupiter/extract-swap-data.ts +6 -7
- package/src/services/svm/README.md +483 -0
- package/src/services/svm/bindings/accounts/AllowedOfframp.ts +73 -0
- package/src/services/svm/bindings/accounts/Config.ts +153 -0
- package/src/services/svm/bindings/accounts/DestChain.ts +113 -0
- package/src/services/svm/bindings/accounts/Nonce.ts +97 -0
- package/src/services/svm/bindings/accounts/index.ts +15 -0
- package/src/services/svm/bindings/accounts/tokenAdminRegistry.ts +128 -0
- package/src/services/svm/bindings/errors/anchor.ts +773 -0
- package/src/services/svm/bindings/errors/custom.ts +375 -0
- package/src/services/svm/bindings/errors/index.ts +62 -0
- package/src/services/svm/bindings/instructions/ccipSend.ts +112 -0
- package/src/services/svm/bindings/instructions/getFee.ts +73 -0
- package/src/services/svm/bindings/instructions/index.ts +4 -0
- package/src/services/svm/bindings/programId.ts +6 -0
- package/src/services/svm/bindings/types/BaseChain.ts +92 -0
- package/src/services/svm/bindings/types/BaseConfig.ts +184 -0
- package/src/services/svm/bindings/types/CodeVersion.ts +88 -0
- package/src/services/svm/bindings/types/CrossChainAmount.ts +53 -0
- package/src/services/svm/bindings/types/DestChainConfig.ts +76 -0
- package/src/services/svm/bindings/types/DestChainState.ts +76 -0
- package/src/services/svm/bindings/types/GetFeeResult.ts +72 -0
- package/src/services/svm/bindings/types/LockOrBurnInV1.ts +102 -0
- package/src/services/svm/bindings/types/LockOrBurnOutV1.ts +79 -0
- package/src/services/svm/bindings/types/RampMessageHeader.ts +94 -0
- package/src/services/svm/bindings/types/RateLimitConfig.ts +72 -0
- package/src/services/svm/bindings/types/RateLimitTokenBucket.ts +76 -0
- package/src/services/svm/bindings/types/ReleaseOrMintInV1.ts +156 -0
- package/src/services/svm/bindings/types/ReleaseOrMintOutV1.ts +53 -0
- package/src/services/svm/bindings/types/RemoteAddress.ts +61 -0
- package/src/services/svm/bindings/types/RemoteConfig.ts +86 -0
- package/src/services/svm/bindings/types/RestoreOnAction.ts +120 -0
- package/src/services/svm/bindings/types/SVM2AnyMessage.ts +128 -0
- package/src/services/svm/bindings/types/SVM2AnyRampMessage.ts +166 -0
- package/src/services/svm/bindings/types/SVM2AnyTokenTransfer.ts +118 -0
- package/src/services/svm/bindings/types/SVMTokenAmount.ts +64 -0
- package/src/services/svm/bindings/types/index.ts +78 -0
- package/src/services/svm/core/client/accounts.ts +97 -0
- package/src/services/svm/core/client/events.ts +95 -0
- package/src/services/svm/core/client/fee.ts +279 -0
- package/src/services/svm/core/client/index.ts +150 -0
- package/src/services/svm/core/client/send.ts +607 -0
- package/src/services/svm/core/client/utils.ts +131 -0
- package/src/services/svm/core/models.ts +236 -0
- package/src/services/svm/index.ts +32 -0
- package/src/services/svm/utils/conversion.ts +62 -0
- package/src/services/svm/utils/errors.ts +51 -0
- package/src/services/svm/utils/keypair.ts +19 -0
- package/src/services/svm/utils/logger.ts +171 -0
- package/src/services/svm/utils/pdas/common.ts +15 -0
- package/src/services/svm/utils/pdas/feeQuoter.ts +68 -0
- package/src/services/svm/utils/pdas/index.ts +12 -0
- package/src/services/svm/utils/pdas/receiver.ts +58 -0
- package/src/services/svm/utils/pdas/rmnRemote.ts +23 -0
- package/src/services/svm/utils/pdas/router.ts +328 -0
- package/src/services/svm/utils/pdas/tokenpool.ts +161 -0
- package/src/services/svm/utils/transaction.ts +132 -0
- package/src/utils/validation.ts +7 -3
- 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
|
+
}
|
package/src/utils/validation.ts
CHANGED
|
@@ -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
|
-
|
|
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
|
-
|
|
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(
|