@shogun-sdk/swap 0.0.2-test.27 → 0.0.2-test.29
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/dist/core.cjs +307 -0
- package/dist/core.d.cts +1 -1
- package/dist/core.d.ts +1 -1
- package/dist/core.js +317 -0
- package/dist/{index-CmsKzdEu.d.cts → index-6Wt_Nfub.d.cts} +35 -18
- package/dist/{index-Qoc6Q9XN.d.ts → index-DdO3mOAE.d.ts} +35 -18
- package/dist/index.cjs +307 -0
- package/dist/index.d.cts +1 -1
- package/dist/index.d.ts +1 -1
- package/dist/index.js +317 -0
- package/dist/react.cjs +348 -0
- package/dist/react.d.cts +32 -4
- package/dist/react.d.ts +32 -4
- package/dist/react.js +358 -0
- package/package.json +1 -1
package/dist/react.d.cts
CHANGED
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
import React from 'react';
|
|
2
|
-
import { S as SwapSDKConfig, a as SwapSDK, b as SwapQuoteParams, c as SwapQuoteResponse, E as ExecuteOrderParams, d as Stage, P as PlaceOrderResult, T as TokenInfo, B as BalanceRequestParams, e as BalanceResponse } from './index-
|
|
3
|
-
export { C as ChainId, O as OrderExecutionType, j as SupportedChain, g as SupportedChains, h as TokenBalance, f as buildQuoteParams, i as isEvmChain } from './index-
|
|
2
|
+
import { S as SwapSDKConfig, a as SwapSDK, b as SwapQuoteParams, c as SwapQuoteResponse, E as ExecuteOrderParams, d as Stage, P as PlaceOrderResult, T as TokenInfo, B as BalanceRequestParams, e as BalanceResponse } from './index-6Wt_Nfub.cjs';
|
|
3
|
+
export { C as ChainId, O as OrderExecutionType, j as SupportedChain, g as SupportedChains, h as TokenBalance, f as buildQuoteParams, i as isEvmChain } from './index-6Wt_Nfub.cjs';
|
|
4
4
|
import { WalletClient } from 'viem';
|
|
5
5
|
import { A as AdaptedWallet } from './wallet-B9bKceyN.cjs';
|
|
6
|
-
import { ApiUserOrders } from '@shogun-sdk/intents-sdk';
|
|
6
|
+
import { ApiUserOrders, ApiCrossChainOrder, ApiSingleChainOrder } from '@shogun-sdk/intents-sdk';
|
|
7
7
|
import '@solana/web3.js';
|
|
8
8
|
|
|
9
9
|
/**
|
|
@@ -297,4 +297,32 @@ declare function useOrders(initialAddresses?: {
|
|
|
297
297
|
} | null;
|
|
298
298
|
};
|
|
299
299
|
|
|
300
|
-
|
|
300
|
+
/**
|
|
301
|
+
* `useCancelOrder`
|
|
302
|
+
*
|
|
303
|
+
* React hook to cancel an intents order (single-chain or cross-chain) on EVM or Solana.
|
|
304
|
+
* Returns helpers for loading/error state and the resulting transaction hash/signature.
|
|
305
|
+
*
|
|
306
|
+
* @example
|
|
307
|
+
* ```tsx
|
|
308
|
+
* const { cancel, isLoading, error, result } = useCancelOrder();
|
|
309
|
+
*
|
|
310
|
+
* await cancel({
|
|
311
|
+
* order,
|
|
312
|
+
* wallet, // AdaptedWallet instance
|
|
313
|
+
* solRpc: "https://api.mainnet-beta.solana.com",
|
|
314
|
+
* });
|
|
315
|
+
* ```
|
|
316
|
+
*/
|
|
317
|
+
declare function useCancelOrder(): {
|
|
318
|
+
cancel: (params: {
|
|
319
|
+
order: ApiCrossChainOrder | ApiSingleChainOrder;
|
|
320
|
+
wallet: AdaptedWallet;
|
|
321
|
+
solRpc: string;
|
|
322
|
+
}) => Promise<string>;
|
|
323
|
+
isLoading: boolean;
|
|
324
|
+
error: string | null;
|
|
325
|
+
result: string | null;
|
|
326
|
+
};
|
|
327
|
+
|
|
328
|
+
export { BalanceRequestParams, BalanceResponse, SwapProvider, SwapQuoteParams, SwapQuoteResponse, useBalances, useCancelOrder, useExecuteTransaction, useOrders, useQuote, useSwap, useTokenList, useTokensData };
|
package/dist/react.d.ts
CHANGED
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
import React from 'react';
|
|
2
|
-
import { S as SwapSDKConfig, a as SwapSDK, b as SwapQuoteParams, c as SwapQuoteResponse, E as ExecuteOrderParams, d as Stage, P as PlaceOrderResult, T as TokenInfo, B as BalanceRequestParams, e as BalanceResponse } from './index-
|
|
3
|
-
export { C as ChainId, O as OrderExecutionType, j as SupportedChain, g as SupportedChains, h as TokenBalance, f as buildQuoteParams, i as isEvmChain } from './index-
|
|
2
|
+
import { S as SwapSDKConfig, a as SwapSDK, b as SwapQuoteParams, c as SwapQuoteResponse, E as ExecuteOrderParams, d as Stage, P as PlaceOrderResult, T as TokenInfo, B as BalanceRequestParams, e as BalanceResponse } from './index-DdO3mOAE.js';
|
|
3
|
+
export { C as ChainId, O as OrderExecutionType, j as SupportedChain, g as SupportedChains, h as TokenBalance, f as buildQuoteParams, i as isEvmChain } from './index-DdO3mOAE.js';
|
|
4
4
|
import { WalletClient } from 'viem';
|
|
5
5
|
import { A as AdaptedWallet } from './wallet-B9bKceyN.js';
|
|
6
|
-
import { ApiUserOrders } from '@shogun-sdk/intents-sdk';
|
|
6
|
+
import { ApiUserOrders, ApiCrossChainOrder, ApiSingleChainOrder } from '@shogun-sdk/intents-sdk';
|
|
7
7
|
import '@solana/web3.js';
|
|
8
8
|
|
|
9
9
|
/**
|
|
@@ -297,4 +297,32 @@ declare function useOrders(initialAddresses?: {
|
|
|
297
297
|
} | null;
|
|
298
298
|
};
|
|
299
299
|
|
|
300
|
-
|
|
300
|
+
/**
|
|
301
|
+
* `useCancelOrder`
|
|
302
|
+
*
|
|
303
|
+
* React hook to cancel an intents order (single-chain or cross-chain) on EVM or Solana.
|
|
304
|
+
* Returns helpers for loading/error state and the resulting transaction hash/signature.
|
|
305
|
+
*
|
|
306
|
+
* @example
|
|
307
|
+
* ```tsx
|
|
308
|
+
* const { cancel, isLoading, error, result } = useCancelOrder();
|
|
309
|
+
*
|
|
310
|
+
* await cancel({
|
|
311
|
+
* order,
|
|
312
|
+
* wallet, // AdaptedWallet instance
|
|
313
|
+
* solRpc: "https://api.mainnet-beta.solana.com",
|
|
314
|
+
* });
|
|
315
|
+
* ```
|
|
316
|
+
*/
|
|
317
|
+
declare function useCancelOrder(): {
|
|
318
|
+
cancel: (params: {
|
|
319
|
+
order: ApiCrossChainOrder | ApiSingleChainOrder;
|
|
320
|
+
wallet: AdaptedWallet;
|
|
321
|
+
solRpc: string;
|
|
322
|
+
}) => Promise<string>;
|
|
323
|
+
isLoading: boolean;
|
|
324
|
+
error: string | null;
|
|
325
|
+
result: string | null;
|
|
326
|
+
};
|
|
327
|
+
|
|
328
|
+
export { BalanceRequestParams, BalanceResponse, SwapProvider, SwapQuoteParams, SwapQuoteResponse, useBalances, useCancelOrder, useExecuteTransaction, useOrders, useQuote, useSwap, useTokenList, useTokensData };
|
package/dist/react.js
CHANGED
|
@@ -949,6 +949,304 @@ async function getOrders({
|
|
|
949
949
|
return orders;
|
|
950
950
|
}
|
|
951
951
|
|
|
952
|
+
// src/core/orders/cancelOrder.ts
|
|
953
|
+
import {
|
|
954
|
+
cancelCrossChainOrderInstructionsAsBytes,
|
|
955
|
+
cancelSingleChainOrderInstructionsAsBytes,
|
|
956
|
+
ChainID as ChainID3,
|
|
957
|
+
CROSS_CHAIN_GUARD_ADDRESSES,
|
|
958
|
+
PERMIT2_ADDRESS as PERMIT2_ADDRESS2,
|
|
959
|
+
SINGLE_CHAIN_GUARD_ADDRESSES
|
|
960
|
+
} from "@shogun-sdk/intents-sdk";
|
|
961
|
+
import {
|
|
962
|
+
VersionedMessage,
|
|
963
|
+
VersionedTransaction as VersionedTransaction2
|
|
964
|
+
} from "@solana/web3.js";
|
|
965
|
+
import { encodeFunctionData as encodeFunctionData3 } from "viem";
|
|
966
|
+
async function cancelIntentsOrder({
|
|
967
|
+
order,
|
|
968
|
+
wallet,
|
|
969
|
+
sol_rpc
|
|
970
|
+
}) {
|
|
971
|
+
const isCrossChain = "srcChainId" in order && "destChainId" in order && order.srcChainId !== order.destChainId;
|
|
972
|
+
const srcChain = "srcChainId" in order ? order.srcChainId : order.chainId;
|
|
973
|
+
const isSolanaOrder = srcChain === ChainID3.Solana;
|
|
974
|
+
if (isSolanaOrder) {
|
|
975
|
+
if (!isCrossChain) {
|
|
976
|
+
const { versionedMessageBytes: versionedMessageBytes2 } = await cancelSingleChainOrderInstructionsAsBytes(
|
|
977
|
+
order.orderId,
|
|
978
|
+
order.user,
|
|
979
|
+
{ rpcUrl: sol_rpc }
|
|
980
|
+
);
|
|
981
|
+
const message2 = VersionedMessage.deserialize(
|
|
982
|
+
versionedMessageBytes2
|
|
983
|
+
);
|
|
984
|
+
const tx2 = new VersionedTransaction2(message2);
|
|
985
|
+
return await wallet.sendTransaction(tx2);
|
|
986
|
+
}
|
|
987
|
+
const { versionedMessageBytes } = await cancelCrossChainOrderInstructionsAsBytes(
|
|
988
|
+
order.orderId,
|
|
989
|
+
order.user,
|
|
990
|
+
{ rpcUrl: sol_rpc }
|
|
991
|
+
);
|
|
992
|
+
const message = VersionedMessage.deserialize(
|
|
993
|
+
versionedMessageBytes
|
|
994
|
+
);
|
|
995
|
+
const tx = new VersionedTransaction2(message);
|
|
996
|
+
return await wallet.sendTransaction(tx);
|
|
997
|
+
}
|
|
998
|
+
const chainId = srcChain;
|
|
999
|
+
const { readContract } = wallet;
|
|
1000
|
+
if (!readContract) {
|
|
1001
|
+
throw new Error("Wallet does not support readContract");
|
|
1002
|
+
}
|
|
1003
|
+
const nonce = BigInt(order.nonce ?? "0");
|
|
1004
|
+
const nonceWordPos = nonce >> 8n;
|
|
1005
|
+
const nonceBitPos = nonce - nonceWordPos * 256n;
|
|
1006
|
+
if (isCrossChain) {
|
|
1007
|
+
const [orderData = [false, false], currentNonceBitmap = 0n] = await Promise.all([
|
|
1008
|
+
readContract({
|
|
1009
|
+
address: CROSS_CHAIN_GUARD_ADDRESSES[chainId],
|
|
1010
|
+
abi: [
|
|
1011
|
+
{
|
|
1012
|
+
inputs: [{ name: "orderId", type: "bytes32" }],
|
|
1013
|
+
name: "orderData",
|
|
1014
|
+
outputs: [
|
|
1015
|
+
{ name: "initialized", type: "bool" },
|
|
1016
|
+
{ name: "deactivated", type: "bool" }
|
|
1017
|
+
],
|
|
1018
|
+
stateMutability: "view",
|
|
1019
|
+
type: "function"
|
|
1020
|
+
}
|
|
1021
|
+
],
|
|
1022
|
+
functionName: "orderData",
|
|
1023
|
+
args: [order.orderId]
|
|
1024
|
+
}),
|
|
1025
|
+
readContract({
|
|
1026
|
+
address: PERMIT2_ADDRESS2[chainId],
|
|
1027
|
+
abi: [
|
|
1028
|
+
{
|
|
1029
|
+
inputs: [
|
|
1030
|
+
{ name: "owner", type: "address" },
|
|
1031
|
+
{ name: "wordPos", type: "uint256" }
|
|
1032
|
+
],
|
|
1033
|
+
name: "nonceBitmap",
|
|
1034
|
+
outputs: [{ name: "", type: "uint256" }],
|
|
1035
|
+
stateMutability: "view",
|
|
1036
|
+
type: "function"
|
|
1037
|
+
}
|
|
1038
|
+
],
|
|
1039
|
+
functionName: "nonceBitmap",
|
|
1040
|
+
args: [order.user, nonceWordPos]
|
|
1041
|
+
})
|
|
1042
|
+
]);
|
|
1043
|
+
const [initialized, deactivated] = orderData;
|
|
1044
|
+
if (initialized) {
|
|
1045
|
+
if (deactivated) {
|
|
1046
|
+
throw new Error("Order is already deactivated");
|
|
1047
|
+
}
|
|
1048
|
+
return await wallet.sendTransaction({
|
|
1049
|
+
to: CROSS_CHAIN_GUARD_ADDRESSES[order.srcChainId],
|
|
1050
|
+
data: encodeFunctionData3({
|
|
1051
|
+
abi: [
|
|
1052
|
+
{
|
|
1053
|
+
inputs: [
|
|
1054
|
+
{
|
|
1055
|
+
components: [
|
|
1056
|
+
{ name: "user", type: "address" },
|
|
1057
|
+
{ name: "tokenIn", type: "address" },
|
|
1058
|
+
{ name: "srcChainId", type: "uint256" },
|
|
1059
|
+
{ name: "deadline", type: "uint256" },
|
|
1060
|
+
{ name: "amountIn", type: "uint256" },
|
|
1061
|
+
{ name: "minStablecoinsAmount", type: "uint256" },
|
|
1062
|
+
{ name: "executionDetailsHash", type: "bytes32" },
|
|
1063
|
+
{ name: "nonce", type: "uint256" }
|
|
1064
|
+
],
|
|
1065
|
+
name: "orderInfo",
|
|
1066
|
+
type: "tuple"
|
|
1067
|
+
}
|
|
1068
|
+
],
|
|
1069
|
+
name: "cancelOrder",
|
|
1070
|
+
outputs: [],
|
|
1071
|
+
stateMutability: "nonpayable",
|
|
1072
|
+
type: "function"
|
|
1073
|
+
}
|
|
1074
|
+
],
|
|
1075
|
+
functionName: "cancelOrder",
|
|
1076
|
+
args: [
|
|
1077
|
+
{
|
|
1078
|
+
user: order.user,
|
|
1079
|
+
tokenIn: order.tokenIn,
|
|
1080
|
+
srcChainId: BigInt(order.srcChainId),
|
|
1081
|
+
deadline: BigInt(order.deadline),
|
|
1082
|
+
amountIn: BigInt(order.amountIn),
|
|
1083
|
+
minStablecoinsAmount: BigInt(order.minStablecoinsAmount),
|
|
1084
|
+
executionDetailsHash: order.executionDetailsHash,
|
|
1085
|
+
nonce
|
|
1086
|
+
}
|
|
1087
|
+
]
|
|
1088
|
+
}),
|
|
1089
|
+
value: BigInt(0),
|
|
1090
|
+
from: order.user
|
|
1091
|
+
});
|
|
1092
|
+
} else {
|
|
1093
|
+
if ((currentNonceBitmap & 1n << nonceBitPos) !== 0n) {
|
|
1094
|
+
throw new Error("Nonce is already invalidated");
|
|
1095
|
+
}
|
|
1096
|
+
const mask2 = 1n << nonceBitPos;
|
|
1097
|
+
return await wallet.sendTransaction({
|
|
1098
|
+
to: PERMIT2_ADDRESS2[order.srcChainId],
|
|
1099
|
+
data: encodeFunctionData3({
|
|
1100
|
+
abi: [
|
|
1101
|
+
{
|
|
1102
|
+
inputs: [
|
|
1103
|
+
{ name: "wordPos", type: "uint256" },
|
|
1104
|
+
{ name: "mask", type: "uint256" }
|
|
1105
|
+
],
|
|
1106
|
+
name: "invalidateUnorderedNonces",
|
|
1107
|
+
outputs: [],
|
|
1108
|
+
stateMutability: "nonpayable",
|
|
1109
|
+
type: "function"
|
|
1110
|
+
}
|
|
1111
|
+
],
|
|
1112
|
+
functionName: "invalidateUnorderedNonces",
|
|
1113
|
+
args: [nonceWordPos, mask2]
|
|
1114
|
+
}),
|
|
1115
|
+
value: BigInt(0),
|
|
1116
|
+
from: order.user
|
|
1117
|
+
});
|
|
1118
|
+
}
|
|
1119
|
+
}
|
|
1120
|
+
const [wasManuallyInitialized, currentBitmap = 0n] = await Promise.all([
|
|
1121
|
+
readContract({
|
|
1122
|
+
address: SINGLE_CHAIN_GUARD_ADDRESSES[chainId],
|
|
1123
|
+
abi: [
|
|
1124
|
+
{
|
|
1125
|
+
inputs: [{ name: "orderHash", type: "bytes32" }],
|
|
1126
|
+
name: "orderManuallyInitialized",
|
|
1127
|
+
outputs: [{ name: "", type: "bool" }],
|
|
1128
|
+
stateMutability: "view",
|
|
1129
|
+
type: "function"
|
|
1130
|
+
}
|
|
1131
|
+
],
|
|
1132
|
+
functionName: "orderManuallyInitialized",
|
|
1133
|
+
args: [order.orderId]
|
|
1134
|
+
}),
|
|
1135
|
+
readContract({
|
|
1136
|
+
address: PERMIT2_ADDRESS2[chainId],
|
|
1137
|
+
abi: [
|
|
1138
|
+
{
|
|
1139
|
+
inputs: [
|
|
1140
|
+
{ name: "owner", type: "address" },
|
|
1141
|
+
{ name: "wordPos", type: "uint256" }
|
|
1142
|
+
],
|
|
1143
|
+
name: "nonceBitmap",
|
|
1144
|
+
outputs: [{ name: "", type: "uint256" }],
|
|
1145
|
+
stateMutability: "view",
|
|
1146
|
+
type: "function"
|
|
1147
|
+
}
|
|
1148
|
+
],
|
|
1149
|
+
functionName: "nonceBitmap",
|
|
1150
|
+
args: [order.user, nonceWordPos]
|
|
1151
|
+
})
|
|
1152
|
+
]);
|
|
1153
|
+
if (wasManuallyInitialized) {
|
|
1154
|
+
return await wallet.sendTransaction({
|
|
1155
|
+
to: SINGLE_CHAIN_GUARD_ADDRESSES[chainId],
|
|
1156
|
+
data: encodeFunctionData3({
|
|
1157
|
+
abi: [
|
|
1158
|
+
{
|
|
1159
|
+
inputs: [
|
|
1160
|
+
{
|
|
1161
|
+
name: "order",
|
|
1162
|
+
type: "tuple",
|
|
1163
|
+
components: [
|
|
1164
|
+
{ name: "amountIn", type: "uint256" },
|
|
1165
|
+
{ name: "tokenIn", type: "address" },
|
|
1166
|
+
{ name: "deadline", type: "uint256" },
|
|
1167
|
+
{ name: "nonce", type: "uint256" },
|
|
1168
|
+
{ name: "encodedExternalCallData", type: "bytes" },
|
|
1169
|
+
{
|
|
1170
|
+
name: "extraTransfers",
|
|
1171
|
+
type: "tuple[]",
|
|
1172
|
+
components: [
|
|
1173
|
+
{ name: "amount", type: "uint256" },
|
|
1174
|
+
{ name: "receiver", type: "address" },
|
|
1175
|
+
{ name: "token", type: "address" }
|
|
1176
|
+
]
|
|
1177
|
+
},
|
|
1178
|
+
{
|
|
1179
|
+
name: "requestedOutput",
|
|
1180
|
+
type: "tuple",
|
|
1181
|
+
components: [
|
|
1182
|
+
{ name: "amount", type: "uint256" },
|
|
1183
|
+
{ name: "receiver", type: "address" },
|
|
1184
|
+
{ name: "token", type: "address" }
|
|
1185
|
+
]
|
|
1186
|
+
},
|
|
1187
|
+
{ name: "user", type: "address" }
|
|
1188
|
+
]
|
|
1189
|
+
}
|
|
1190
|
+
],
|
|
1191
|
+
name: "cancelManuallyCreatedOrder",
|
|
1192
|
+
outputs: [],
|
|
1193
|
+
stateMutability: "nonpayable",
|
|
1194
|
+
type: "function"
|
|
1195
|
+
}
|
|
1196
|
+
],
|
|
1197
|
+
functionName: "cancelManuallyCreatedOrder",
|
|
1198
|
+
args: [
|
|
1199
|
+
{
|
|
1200
|
+
amountIn: BigInt(order.amountIn),
|
|
1201
|
+
tokenIn: order.tokenIn,
|
|
1202
|
+
deadline: BigInt(order.deadline),
|
|
1203
|
+
nonce,
|
|
1204
|
+
encodedExternalCallData: "0x",
|
|
1205
|
+
extraTransfers: (order.extraTransfers || []).map((t) => ({
|
|
1206
|
+
amount: BigInt(t.amount),
|
|
1207
|
+
receiver: t.receiver,
|
|
1208
|
+
token: t.token
|
|
1209
|
+
})),
|
|
1210
|
+
requestedOutput: {
|
|
1211
|
+
amount: BigInt(order.amountOutMin),
|
|
1212
|
+
receiver: order.destinationAddress,
|
|
1213
|
+
token: order.tokenOut
|
|
1214
|
+
},
|
|
1215
|
+
user: order.user
|
|
1216
|
+
}
|
|
1217
|
+
]
|
|
1218
|
+
}),
|
|
1219
|
+
value: 0n,
|
|
1220
|
+
from: order.user
|
|
1221
|
+
});
|
|
1222
|
+
}
|
|
1223
|
+
const mask = 1n << nonceBitPos;
|
|
1224
|
+
if ((currentBitmap & mask) !== 0n) {
|
|
1225
|
+
throw new Error("Nonce is already invalidated");
|
|
1226
|
+
}
|
|
1227
|
+
return await wallet.sendTransaction({
|
|
1228
|
+
to: PERMIT2_ADDRESS2[chainId],
|
|
1229
|
+
data: encodeFunctionData3({
|
|
1230
|
+
abi: [
|
|
1231
|
+
{
|
|
1232
|
+
inputs: [
|
|
1233
|
+
{ name: "wordPos", type: "uint256" },
|
|
1234
|
+
{ name: "mask", type: "uint256" }
|
|
1235
|
+
],
|
|
1236
|
+
name: "invalidateUnorderedNonces",
|
|
1237
|
+
outputs: [],
|
|
1238
|
+
stateMutability: "nonpayable",
|
|
1239
|
+
type: "function"
|
|
1240
|
+
}
|
|
1241
|
+
],
|
|
1242
|
+
functionName: "invalidateUnorderedNonces",
|
|
1243
|
+
args: [nonceWordPos, mask]
|
|
1244
|
+
}),
|
|
1245
|
+
value: 0n,
|
|
1246
|
+
from: order.user
|
|
1247
|
+
});
|
|
1248
|
+
}
|
|
1249
|
+
|
|
952
1250
|
// src/core/client.ts
|
|
953
1251
|
var SwapSDK = class {
|
|
954
1252
|
constructor(config) {
|
|
@@ -1109,6 +1407,25 @@ var SwapSDK = class {
|
|
|
1109
1407
|
async getOrders(params) {
|
|
1110
1408
|
return getOrders(params);
|
|
1111
1409
|
}
|
|
1410
|
+
/**
|
|
1411
|
+
* Cancels an order (single-chain or cross-chain) on EVM or Solana.
|
|
1412
|
+
*
|
|
1413
|
+
* Internally routes to the correct guard contract or Solana program to
|
|
1414
|
+
* deactivate the order or invalidate its nonce.
|
|
1415
|
+
*
|
|
1416
|
+
* @param params.order - Order payload returned from the Intents API.
|
|
1417
|
+
* @param params.wallet - Adapted wallet used to submit the cancellation transaction.
|
|
1418
|
+
* @param params.solRpc - Solana RPC URL used for SVM cancellations.
|
|
1419
|
+
*
|
|
1420
|
+
* @returns A transaction signature or hash from the underlying wallet.
|
|
1421
|
+
*/
|
|
1422
|
+
async cancelOrder(params) {
|
|
1423
|
+
return cancelIntentsOrder({
|
|
1424
|
+
order: params.order,
|
|
1425
|
+
wallet: params.wallet,
|
|
1426
|
+
sol_rpc: params.solRpc
|
|
1427
|
+
});
|
|
1428
|
+
}
|
|
1112
1429
|
};
|
|
1113
1430
|
|
|
1114
1431
|
// src/react/SwapProvider.tsx
|
|
@@ -1523,6 +1840,46 @@ function useOrders(initialAddresses) {
|
|
|
1523
1840
|
[data, loading, error, refetch, setAddresses]
|
|
1524
1841
|
);
|
|
1525
1842
|
}
|
|
1843
|
+
|
|
1844
|
+
// src/react/useCancelOrder.ts
|
|
1845
|
+
import { useCallback as useCallback6, useState as useState4 } from "react";
|
|
1846
|
+
import { mutate as mutate4 } from "swr";
|
|
1847
|
+
function useCancelOrder() {
|
|
1848
|
+
const sdk = useSwap();
|
|
1849
|
+
const [isLoading, setLoading] = useState4(false);
|
|
1850
|
+
const [error, setError] = useState4(null);
|
|
1851
|
+
const [result, setResult] = useState4(null);
|
|
1852
|
+
const cancel = useCallback6(
|
|
1853
|
+
async (params) => {
|
|
1854
|
+
setLoading(true);
|
|
1855
|
+
setError(null);
|
|
1856
|
+
setResult(null);
|
|
1857
|
+
try {
|
|
1858
|
+
const tx = await sdk.cancelOrder({
|
|
1859
|
+
order: params.order,
|
|
1860
|
+
wallet: params.wallet,
|
|
1861
|
+
solRpc: params.solRpc
|
|
1862
|
+
});
|
|
1863
|
+
setResult(tx);
|
|
1864
|
+
void mutate4("orders-global");
|
|
1865
|
+
return tx;
|
|
1866
|
+
} catch (err) {
|
|
1867
|
+
const msg = err instanceof Error ? err.message : String(err);
|
|
1868
|
+
setError(msg);
|
|
1869
|
+
throw err;
|
|
1870
|
+
} finally {
|
|
1871
|
+
setLoading(false);
|
|
1872
|
+
}
|
|
1873
|
+
},
|
|
1874
|
+
[sdk]
|
|
1875
|
+
);
|
|
1876
|
+
return {
|
|
1877
|
+
cancel,
|
|
1878
|
+
isLoading,
|
|
1879
|
+
error,
|
|
1880
|
+
result
|
|
1881
|
+
};
|
|
1882
|
+
}
|
|
1526
1883
|
export {
|
|
1527
1884
|
ChainId,
|
|
1528
1885
|
OrderExecutionType,
|
|
@@ -1531,6 +1888,7 @@ export {
|
|
|
1531
1888
|
buildQuoteParams,
|
|
1532
1889
|
isEvmChain,
|
|
1533
1890
|
useBalances,
|
|
1891
|
+
useCancelOrder,
|
|
1534
1892
|
useExecuteTransaction,
|
|
1535
1893
|
useOrders,
|
|
1536
1894
|
useQuote,
|