@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/index.js
CHANGED
|
@@ -946,6 +946,304 @@ async function getOrders({
|
|
|
946
946
|
return orders;
|
|
947
947
|
}
|
|
948
948
|
|
|
949
|
+
// src/core/orders/cancelOrder.ts
|
|
950
|
+
import {
|
|
951
|
+
cancelCrossChainOrderInstructionsAsBytes,
|
|
952
|
+
cancelSingleChainOrderInstructionsAsBytes,
|
|
953
|
+
ChainID as ChainID3,
|
|
954
|
+
CROSS_CHAIN_GUARD_ADDRESSES,
|
|
955
|
+
PERMIT2_ADDRESS as PERMIT2_ADDRESS2,
|
|
956
|
+
SINGLE_CHAIN_GUARD_ADDRESSES
|
|
957
|
+
} from "@shogun-sdk/intents-sdk";
|
|
958
|
+
import {
|
|
959
|
+
VersionedMessage,
|
|
960
|
+
VersionedTransaction as VersionedTransaction2
|
|
961
|
+
} from "@solana/web3.js";
|
|
962
|
+
import { encodeFunctionData as encodeFunctionData3 } from "viem";
|
|
963
|
+
async function cancelIntentsOrder({
|
|
964
|
+
order,
|
|
965
|
+
wallet,
|
|
966
|
+
sol_rpc
|
|
967
|
+
}) {
|
|
968
|
+
const isCrossChain = "srcChainId" in order && "destChainId" in order && order.srcChainId !== order.destChainId;
|
|
969
|
+
const srcChain = "srcChainId" in order ? order.srcChainId : order.chainId;
|
|
970
|
+
const isSolanaOrder = srcChain === ChainID3.Solana;
|
|
971
|
+
if (isSolanaOrder) {
|
|
972
|
+
if (!isCrossChain) {
|
|
973
|
+
const { versionedMessageBytes: versionedMessageBytes2 } = await cancelSingleChainOrderInstructionsAsBytes(
|
|
974
|
+
order.orderId,
|
|
975
|
+
order.user,
|
|
976
|
+
{ rpcUrl: sol_rpc }
|
|
977
|
+
);
|
|
978
|
+
const message2 = VersionedMessage.deserialize(
|
|
979
|
+
versionedMessageBytes2
|
|
980
|
+
);
|
|
981
|
+
const tx2 = new VersionedTransaction2(message2);
|
|
982
|
+
return await wallet.sendTransaction(tx2);
|
|
983
|
+
}
|
|
984
|
+
const { versionedMessageBytes } = await cancelCrossChainOrderInstructionsAsBytes(
|
|
985
|
+
order.orderId,
|
|
986
|
+
order.user,
|
|
987
|
+
{ rpcUrl: sol_rpc }
|
|
988
|
+
);
|
|
989
|
+
const message = VersionedMessage.deserialize(
|
|
990
|
+
versionedMessageBytes
|
|
991
|
+
);
|
|
992
|
+
const tx = new VersionedTransaction2(message);
|
|
993
|
+
return await wallet.sendTransaction(tx);
|
|
994
|
+
}
|
|
995
|
+
const chainId = srcChain;
|
|
996
|
+
const { readContract } = wallet;
|
|
997
|
+
if (!readContract) {
|
|
998
|
+
throw new Error("Wallet does not support readContract");
|
|
999
|
+
}
|
|
1000
|
+
const nonce = BigInt(order.nonce ?? "0");
|
|
1001
|
+
const nonceWordPos = nonce >> 8n;
|
|
1002
|
+
const nonceBitPos = nonce - nonceWordPos * 256n;
|
|
1003
|
+
if (isCrossChain) {
|
|
1004
|
+
const [orderData = [false, false], currentNonceBitmap = 0n] = await Promise.all([
|
|
1005
|
+
readContract({
|
|
1006
|
+
address: CROSS_CHAIN_GUARD_ADDRESSES[chainId],
|
|
1007
|
+
abi: [
|
|
1008
|
+
{
|
|
1009
|
+
inputs: [{ name: "orderId", type: "bytes32" }],
|
|
1010
|
+
name: "orderData",
|
|
1011
|
+
outputs: [
|
|
1012
|
+
{ name: "initialized", type: "bool" },
|
|
1013
|
+
{ name: "deactivated", type: "bool" }
|
|
1014
|
+
],
|
|
1015
|
+
stateMutability: "view",
|
|
1016
|
+
type: "function"
|
|
1017
|
+
}
|
|
1018
|
+
],
|
|
1019
|
+
functionName: "orderData",
|
|
1020
|
+
args: [order.orderId]
|
|
1021
|
+
}),
|
|
1022
|
+
readContract({
|
|
1023
|
+
address: PERMIT2_ADDRESS2[chainId],
|
|
1024
|
+
abi: [
|
|
1025
|
+
{
|
|
1026
|
+
inputs: [
|
|
1027
|
+
{ name: "owner", type: "address" },
|
|
1028
|
+
{ name: "wordPos", type: "uint256" }
|
|
1029
|
+
],
|
|
1030
|
+
name: "nonceBitmap",
|
|
1031
|
+
outputs: [{ name: "", type: "uint256" }],
|
|
1032
|
+
stateMutability: "view",
|
|
1033
|
+
type: "function"
|
|
1034
|
+
}
|
|
1035
|
+
],
|
|
1036
|
+
functionName: "nonceBitmap",
|
|
1037
|
+
args: [order.user, nonceWordPos]
|
|
1038
|
+
})
|
|
1039
|
+
]);
|
|
1040
|
+
const [initialized, deactivated] = orderData;
|
|
1041
|
+
if (initialized) {
|
|
1042
|
+
if (deactivated) {
|
|
1043
|
+
throw new Error("Order is already deactivated");
|
|
1044
|
+
}
|
|
1045
|
+
return await wallet.sendTransaction({
|
|
1046
|
+
to: CROSS_CHAIN_GUARD_ADDRESSES[order.srcChainId],
|
|
1047
|
+
data: encodeFunctionData3({
|
|
1048
|
+
abi: [
|
|
1049
|
+
{
|
|
1050
|
+
inputs: [
|
|
1051
|
+
{
|
|
1052
|
+
components: [
|
|
1053
|
+
{ name: "user", type: "address" },
|
|
1054
|
+
{ name: "tokenIn", type: "address" },
|
|
1055
|
+
{ name: "srcChainId", type: "uint256" },
|
|
1056
|
+
{ name: "deadline", type: "uint256" },
|
|
1057
|
+
{ name: "amountIn", type: "uint256" },
|
|
1058
|
+
{ name: "minStablecoinsAmount", type: "uint256" },
|
|
1059
|
+
{ name: "executionDetailsHash", type: "bytes32" },
|
|
1060
|
+
{ name: "nonce", type: "uint256" }
|
|
1061
|
+
],
|
|
1062
|
+
name: "orderInfo",
|
|
1063
|
+
type: "tuple"
|
|
1064
|
+
}
|
|
1065
|
+
],
|
|
1066
|
+
name: "cancelOrder",
|
|
1067
|
+
outputs: [],
|
|
1068
|
+
stateMutability: "nonpayable",
|
|
1069
|
+
type: "function"
|
|
1070
|
+
}
|
|
1071
|
+
],
|
|
1072
|
+
functionName: "cancelOrder",
|
|
1073
|
+
args: [
|
|
1074
|
+
{
|
|
1075
|
+
user: order.user,
|
|
1076
|
+
tokenIn: order.tokenIn,
|
|
1077
|
+
srcChainId: BigInt(order.srcChainId),
|
|
1078
|
+
deadline: BigInt(order.deadline),
|
|
1079
|
+
amountIn: BigInt(order.amountIn),
|
|
1080
|
+
minStablecoinsAmount: BigInt(order.minStablecoinsAmount),
|
|
1081
|
+
executionDetailsHash: order.executionDetailsHash,
|
|
1082
|
+
nonce
|
|
1083
|
+
}
|
|
1084
|
+
]
|
|
1085
|
+
}),
|
|
1086
|
+
value: BigInt(0),
|
|
1087
|
+
from: order.user
|
|
1088
|
+
});
|
|
1089
|
+
} else {
|
|
1090
|
+
if ((currentNonceBitmap & 1n << nonceBitPos) !== 0n) {
|
|
1091
|
+
throw new Error("Nonce is already invalidated");
|
|
1092
|
+
}
|
|
1093
|
+
const mask2 = 1n << nonceBitPos;
|
|
1094
|
+
return await wallet.sendTransaction({
|
|
1095
|
+
to: PERMIT2_ADDRESS2[order.srcChainId],
|
|
1096
|
+
data: encodeFunctionData3({
|
|
1097
|
+
abi: [
|
|
1098
|
+
{
|
|
1099
|
+
inputs: [
|
|
1100
|
+
{ name: "wordPos", type: "uint256" },
|
|
1101
|
+
{ name: "mask", type: "uint256" }
|
|
1102
|
+
],
|
|
1103
|
+
name: "invalidateUnorderedNonces",
|
|
1104
|
+
outputs: [],
|
|
1105
|
+
stateMutability: "nonpayable",
|
|
1106
|
+
type: "function"
|
|
1107
|
+
}
|
|
1108
|
+
],
|
|
1109
|
+
functionName: "invalidateUnorderedNonces",
|
|
1110
|
+
args: [nonceWordPos, mask2]
|
|
1111
|
+
}),
|
|
1112
|
+
value: BigInt(0),
|
|
1113
|
+
from: order.user
|
|
1114
|
+
});
|
|
1115
|
+
}
|
|
1116
|
+
}
|
|
1117
|
+
const [wasManuallyInitialized, currentBitmap = 0n] = await Promise.all([
|
|
1118
|
+
readContract({
|
|
1119
|
+
address: SINGLE_CHAIN_GUARD_ADDRESSES[chainId],
|
|
1120
|
+
abi: [
|
|
1121
|
+
{
|
|
1122
|
+
inputs: [{ name: "orderHash", type: "bytes32" }],
|
|
1123
|
+
name: "orderManuallyInitialized",
|
|
1124
|
+
outputs: [{ name: "", type: "bool" }],
|
|
1125
|
+
stateMutability: "view",
|
|
1126
|
+
type: "function"
|
|
1127
|
+
}
|
|
1128
|
+
],
|
|
1129
|
+
functionName: "orderManuallyInitialized",
|
|
1130
|
+
args: [order.orderId]
|
|
1131
|
+
}),
|
|
1132
|
+
readContract({
|
|
1133
|
+
address: PERMIT2_ADDRESS2[chainId],
|
|
1134
|
+
abi: [
|
|
1135
|
+
{
|
|
1136
|
+
inputs: [
|
|
1137
|
+
{ name: "owner", type: "address" },
|
|
1138
|
+
{ name: "wordPos", type: "uint256" }
|
|
1139
|
+
],
|
|
1140
|
+
name: "nonceBitmap",
|
|
1141
|
+
outputs: [{ name: "", type: "uint256" }],
|
|
1142
|
+
stateMutability: "view",
|
|
1143
|
+
type: "function"
|
|
1144
|
+
}
|
|
1145
|
+
],
|
|
1146
|
+
functionName: "nonceBitmap",
|
|
1147
|
+
args: [order.user, nonceWordPos]
|
|
1148
|
+
})
|
|
1149
|
+
]);
|
|
1150
|
+
if (wasManuallyInitialized) {
|
|
1151
|
+
return await wallet.sendTransaction({
|
|
1152
|
+
to: SINGLE_CHAIN_GUARD_ADDRESSES[chainId],
|
|
1153
|
+
data: encodeFunctionData3({
|
|
1154
|
+
abi: [
|
|
1155
|
+
{
|
|
1156
|
+
inputs: [
|
|
1157
|
+
{
|
|
1158
|
+
name: "order",
|
|
1159
|
+
type: "tuple",
|
|
1160
|
+
components: [
|
|
1161
|
+
{ name: "amountIn", type: "uint256" },
|
|
1162
|
+
{ name: "tokenIn", type: "address" },
|
|
1163
|
+
{ name: "deadline", type: "uint256" },
|
|
1164
|
+
{ name: "nonce", type: "uint256" },
|
|
1165
|
+
{ name: "encodedExternalCallData", type: "bytes" },
|
|
1166
|
+
{
|
|
1167
|
+
name: "extraTransfers",
|
|
1168
|
+
type: "tuple[]",
|
|
1169
|
+
components: [
|
|
1170
|
+
{ name: "amount", type: "uint256" },
|
|
1171
|
+
{ name: "receiver", type: "address" },
|
|
1172
|
+
{ name: "token", type: "address" }
|
|
1173
|
+
]
|
|
1174
|
+
},
|
|
1175
|
+
{
|
|
1176
|
+
name: "requestedOutput",
|
|
1177
|
+
type: "tuple",
|
|
1178
|
+
components: [
|
|
1179
|
+
{ name: "amount", type: "uint256" },
|
|
1180
|
+
{ name: "receiver", type: "address" },
|
|
1181
|
+
{ name: "token", type: "address" }
|
|
1182
|
+
]
|
|
1183
|
+
},
|
|
1184
|
+
{ name: "user", type: "address" }
|
|
1185
|
+
]
|
|
1186
|
+
}
|
|
1187
|
+
],
|
|
1188
|
+
name: "cancelManuallyCreatedOrder",
|
|
1189
|
+
outputs: [],
|
|
1190
|
+
stateMutability: "nonpayable",
|
|
1191
|
+
type: "function"
|
|
1192
|
+
}
|
|
1193
|
+
],
|
|
1194
|
+
functionName: "cancelManuallyCreatedOrder",
|
|
1195
|
+
args: [
|
|
1196
|
+
{
|
|
1197
|
+
amountIn: BigInt(order.amountIn),
|
|
1198
|
+
tokenIn: order.tokenIn,
|
|
1199
|
+
deadline: BigInt(order.deadline),
|
|
1200
|
+
nonce,
|
|
1201
|
+
encodedExternalCallData: "0x",
|
|
1202
|
+
extraTransfers: (order.extraTransfers || []).map((t) => ({
|
|
1203
|
+
amount: BigInt(t.amount),
|
|
1204
|
+
receiver: t.receiver,
|
|
1205
|
+
token: t.token
|
|
1206
|
+
})),
|
|
1207
|
+
requestedOutput: {
|
|
1208
|
+
amount: BigInt(order.amountOutMin),
|
|
1209
|
+
receiver: order.destinationAddress,
|
|
1210
|
+
token: order.tokenOut
|
|
1211
|
+
},
|
|
1212
|
+
user: order.user
|
|
1213
|
+
}
|
|
1214
|
+
]
|
|
1215
|
+
}),
|
|
1216
|
+
value: 0n,
|
|
1217
|
+
from: order.user
|
|
1218
|
+
});
|
|
1219
|
+
}
|
|
1220
|
+
const mask = 1n << nonceBitPos;
|
|
1221
|
+
if ((currentBitmap & mask) !== 0n) {
|
|
1222
|
+
throw new Error("Nonce is already invalidated");
|
|
1223
|
+
}
|
|
1224
|
+
return await wallet.sendTransaction({
|
|
1225
|
+
to: PERMIT2_ADDRESS2[chainId],
|
|
1226
|
+
data: encodeFunctionData3({
|
|
1227
|
+
abi: [
|
|
1228
|
+
{
|
|
1229
|
+
inputs: [
|
|
1230
|
+
{ name: "wordPos", type: "uint256" },
|
|
1231
|
+
{ name: "mask", type: "uint256" }
|
|
1232
|
+
],
|
|
1233
|
+
name: "invalidateUnorderedNonces",
|
|
1234
|
+
outputs: [],
|
|
1235
|
+
stateMutability: "nonpayable",
|
|
1236
|
+
type: "function"
|
|
1237
|
+
}
|
|
1238
|
+
],
|
|
1239
|
+
functionName: "invalidateUnorderedNonces",
|
|
1240
|
+
args: [nonceWordPos, mask]
|
|
1241
|
+
}),
|
|
1242
|
+
value: 0n,
|
|
1243
|
+
from: order.user
|
|
1244
|
+
});
|
|
1245
|
+
}
|
|
1246
|
+
|
|
949
1247
|
// src/core/client.ts
|
|
950
1248
|
var SwapSDK = class {
|
|
951
1249
|
constructor(config) {
|
|
@@ -1106,6 +1404,25 @@ var SwapSDK = class {
|
|
|
1106
1404
|
async getOrders(params) {
|
|
1107
1405
|
return getOrders(params);
|
|
1108
1406
|
}
|
|
1407
|
+
/**
|
|
1408
|
+
* Cancels an order (single-chain or cross-chain) on EVM or Solana.
|
|
1409
|
+
*
|
|
1410
|
+
* Internally routes to the correct guard contract or Solana program to
|
|
1411
|
+
* deactivate the order or invalidate its nonce.
|
|
1412
|
+
*
|
|
1413
|
+
* @param params.order - Order payload returned from the Intents API.
|
|
1414
|
+
* @param params.wallet - Adapted wallet used to submit the cancellation transaction.
|
|
1415
|
+
* @param params.solRpc - Solana RPC URL used for SVM cancellations.
|
|
1416
|
+
*
|
|
1417
|
+
* @returns A transaction signature or hash from the underlying wallet.
|
|
1418
|
+
*/
|
|
1419
|
+
async cancelOrder(params) {
|
|
1420
|
+
return cancelIntentsOrder({
|
|
1421
|
+
order: params.order,
|
|
1422
|
+
wallet: params.wallet,
|
|
1423
|
+
sol_rpc: params.solRpc
|
|
1424
|
+
});
|
|
1425
|
+
}
|
|
1109
1426
|
};
|
|
1110
1427
|
export {
|
|
1111
1428
|
ChainId,
|
package/dist/react.cjs
CHANGED
|
@@ -39,6 +39,7 @@ __export(react_exports, {
|
|
|
39
39
|
buildQuoteParams: () => buildQuoteParams,
|
|
40
40
|
isEvmChain: () => isEvmChain,
|
|
41
41
|
useBalances: () => useBalances,
|
|
42
|
+
useCancelOrder: () => useCancelOrder,
|
|
42
43
|
useExecuteTransaction: () => useExecuteTransaction,
|
|
43
44
|
useOrders: () => useOrders,
|
|
44
45
|
useQuote: () => useQuote,
|
|
@@ -986,6 +987,294 @@ async function getOrders({
|
|
|
986
987
|
return orders;
|
|
987
988
|
}
|
|
988
989
|
|
|
990
|
+
// src/core/orders/cancelOrder.ts
|
|
991
|
+
var import_intents_sdk14 = require("@shogun-sdk/intents-sdk");
|
|
992
|
+
var import_web32 = require("@solana/web3.js");
|
|
993
|
+
var import_viem8 = require("viem");
|
|
994
|
+
async function cancelIntentsOrder({
|
|
995
|
+
order,
|
|
996
|
+
wallet,
|
|
997
|
+
sol_rpc
|
|
998
|
+
}) {
|
|
999
|
+
const isCrossChain = "srcChainId" in order && "destChainId" in order && order.srcChainId !== order.destChainId;
|
|
1000
|
+
const srcChain = "srcChainId" in order ? order.srcChainId : order.chainId;
|
|
1001
|
+
const isSolanaOrder = srcChain === import_intents_sdk14.ChainID.Solana;
|
|
1002
|
+
if (isSolanaOrder) {
|
|
1003
|
+
if (!isCrossChain) {
|
|
1004
|
+
const { versionedMessageBytes: versionedMessageBytes2 } = await (0, import_intents_sdk14.cancelSingleChainOrderInstructionsAsBytes)(
|
|
1005
|
+
order.orderId,
|
|
1006
|
+
order.user,
|
|
1007
|
+
{ rpcUrl: sol_rpc }
|
|
1008
|
+
);
|
|
1009
|
+
const message2 = import_web32.VersionedMessage.deserialize(
|
|
1010
|
+
versionedMessageBytes2
|
|
1011
|
+
);
|
|
1012
|
+
const tx2 = new import_web32.VersionedTransaction(message2);
|
|
1013
|
+
return await wallet.sendTransaction(tx2);
|
|
1014
|
+
}
|
|
1015
|
+
const { versionedMessageBytes } = await (0, import_intents_sdk14.cancelCrossChainOrderInstructionsAsBytes)(
|
|
1016
|
+
order.orderId,
|
|
1017
|
+
order.user,
|
|
1018
|
+
{ rpcUrl: sol_rpc }
|
|
1019
|
+
);
|
|
1020
|
+
const message = import_web32.VersionedMessage.deserialize(
|
|
1021
|
+
versionedMessageBytes
|
|
1022
|
+
);
|
|
1023
|
+
const tx = new import_web32.VersionedTransaction(message);
|
|
1024
|
+
return await wallet.sendTransaction(tx);
|
|
1025
|
+
}
|
|
1026
|
+
const chainId = srcChain;
|
|
1027
|
+
const { readContract } = wallet;
|
|
1028
|
+
if (!readContract) {
|
|
1029
|
+
throw new Error("Wallet does not support readContract");
|
|
1030
|
+
}
|
|
1031
|
+
const nonce = BigInt(order.nonce ?? "0");
|
|
1032
|
+
const nonceWordPos = nonce >> 8n;
|
|
1033
|
+
const nonceBitPos = nonce - nonceWordPos * 256n;
|
|
1034
|
+
if (isCrossChain) {
|
|
1035
|
+
const [orderData = [false, false], currentNonceBitmap = 0n] = await Promise.all([
|
|
1036
|
+
readContract({
|
|
1037
|
+
address: import_intents_sdk14.CROSS_CHAIN_GUARD_ADDRESSES[chainId],
|
|
1038
|
+
abi: [
|
|
1039
|
+
{
|
|
1040
|
+
inputs: [{ name: "orderId", type: "bytes32" }],
|
|
1041
|
+
name: "orderData",
|
|
1042
|
+
outputs: [
|
|
1043
|
+
{ name: "initialized", type: "bool" },
|
|
1044
|
+
{ name: "deactivated", type: "bool" }
|
|
1045
|
+
],
|
|
1046
|
+
stateMutability: "view",
|
|
1047
|
+
type: "function"
|
|
1048
|
+
}
|
|
1049
|
+
],
|
|
1050
|
+
functionName: "orderData",
|
|
1051
|
+
args: [order.orderId]
|
|
1052
|
+
}),
|
|
1053
|
+
readContract({
|
|
1054
|
+
address: import_intents_sdk14.PERMIT2_ADDRESS[chainId],
|
|
1055
|
+
abi: [
|
|
1056
|
+
{
|
|
1057
|
+
inputs: [
|
|
1058
|
+
{ name: "owner", type: "address" },
|
|
1059
|
+
{ name: "wordPos", type: "uint256" }
|
|
1060
|
+
],
|
|
1061
|
+
name: "nonceBitmap",
|
|
1062
|
+
outputs: [{ name: "", type: "uint256" }],
|
|
1063
|
+
stateMutability: "view",
|
|
1064
|
+
type: "function"
|
|
1065
|
+
}
|
|
1066
|
+
],
|
|
1067
|
+
functionName: "nonceBitmap",
|
|
1068
|
+
args: [order.user, nonceWordPos]
|
|
1069
|
+
})
|
|
1070
|
+
]);
|
|
1071
|
+
const [initialized, deactivated] = orderData;
|
|
1072
|
+
if (initialized) {
|
|
1073
|
+
if (deactivated) {
|
|
1074
|
+
throw new Error("Order is already deactivated");
|
|
1075
|
+
}
|
|
1076
|
+
return await wallet.sendTransaction({
|
|
1077
|
+
to: import_intents_sdk14.CROSS_CHAIN_GUARD_ADDRESSES[order.srcChainId],
|
|
1078
|
+
data: (0, import_viem8.encodeFunctionData)({
|
|
1079
|
+
abi: [
|
|
1080
|
+
{
|
|
1081
|
+
inputs: [
|
|
1082
|
+
{
|
|
1083
|
+
components: [
|
|
1084
|
+
{ name: "user", type: "address" },
|
|
1085
|
+
{ name: "tokenIn", type: "address" },
|
|
1086
|
+
{ name: "srcChainId", type: "uint256" },
|
|
1087
|
+
{ name: "deadline", type: "uint256" },
|
|
1088
|
+
{ name: "amountIn", type: "uint256" },
|
|
1089
|
+
{ name: "minStablecoinsAmount", type: "uint256" },
|
|
1090
|
+
{ name: "executionDetailsHash", type: "bytes32" },
|
|
1091
|
+
{ name: "nonce", type: "uint256" }
|
|
1092
|
+
],
|
|
1093
|
+
name: "orderInfo",
|
|
1094
|
+
type: "tuple"
|
|
1095
|
+
}
|
|
1096
|
+
],
|
|
1097
|
+
name: "cancelOrder",
|
|
1098
|
+
outputs: [],
|
|
1099
|
+
stateMutability: "nonpayable",
|
|
1100
|
+
type: "function"
|
|
1101
|
+
}
|
|
1102
|
+
],
|
|
1103
|
+
functionName: "cancelOrder",
|
|
1104
|
+
args: [
|
|
1105
|
+
{
|
|
1106
|
+
user: order.user,
|
|
1107
|
+
tokenIn: order.tokenIn,
|
|
1108
|
+
srcChainId: BigInt(order.srcChainId),
|
|
1109
|
+
deadline: BigInt(order.deadline),
|
|
1110
|
+
amountIn: BigInt(order.amountIn),
|
|
1111
|
+
minStablecoinsAmount: BigInt(order.minStablecoinsAmount),
|
|
1112
|
+
executionDetailsHash: order.executionDetailsHash,
|
|
1113
|
+
nonce
|
|
1114
|
+
}
|
|
1115
|
+
]
|
|
1116
|
+
}),
|
|
1117
|
+
value: BigInt(0),
|
|
1118
|
+
from: order.user
|
|
1119
|
+
});
|
|
1120
|
+
} else {
|
|
1121
|
+
if ((currentNonceBitmap & 1n << nonceBitPos) !== 0n) {
|
|
1122
|
+
throw new Error("Nonce is already invalidated");
|
|
1123
|
+
}
|
|
1124
|
+
const mask2 = 1n << nonceBitPos;
|
|
1125
|
+
return await wallet.sendTransaction({
|
|
1126
|
+
to: import_intents_sdk14.PERMIT2_ADDRESS[order.srcChainId],
|
|
1127
|
+
data: (0, import_viem8.encodeFunctionData)({
|
|
1128
|
+
abi: [
|
|
1129
|
+
{
|
|
1130
|
+
inputs: [
|
|
1131
|
+
{ name: "wordPos", type: "uint256" },
|
|
1132
|
+
{ name: "mask", type: "uint256" }
|
|
1133
|
+
],
|
|
1134
|
+
name: "invalidateUnorderedNonces",
|
|
1135
|
+
outputs: [],
|
|
1136
|
+
stateMutability: "nonpayable",
|
|
1137
|
+
type: "function"
|
|
1138
|
+
}
|
|
1139
|
+
],
|
|
1140
|
+
functionName: "invalidateUnorderedNonces",
|
|
1141
|
+
args: [nonceWordPos, mask2]
|
|
1142
|
+
}),
|
|
1143
|
+
value: BigInt(0),
|
|
1144
|
+
from: order.user
|
|
1145
|
+
});
|
|
1146
|
+
}
|
|
1147
|
+
}
|
|
1148
|
+
const [wasManuallyInitialized, currentBitmap = 0n] = await Promise.all([
|
|
1149
|
+
readContract({
|
|
1150
|
+
address: import_intents_sdk14.SINGLE_CHAIN_GUARD_ADDRESSES[chainId],
|
|
1151
|
+
abi: [
|
|
1152
|
+
{
|
|
1153
|
+
inputs: [{ name: "orderHash", type: "bytes32" }],
|
|
1154
|
+
name: "orderManuallyInitialized",
|
|
1155
|
+
outputs: [{ name: "", type: "bool" }],
|
|
1156
|
+
stateMutability: "view",
|
|
1157
|
+
type: "function"
|
|
1158
|
+
}
|
|
1159
|
+
],
|
|
1160
|
+
functionName: "orderManuallyInitialized",
|
|
1161
|
+
args: [order.orderId]
|
|
1162
|
+
}),
|
|
1163
|
+
readContract({
|
|
1164
|
+
address: import_intents_sdk14.PERMIT2_ADDRESS[chainId],
|
|
1165
|
+
abi: [
|
|
1166
|
+
{
|
|
1167
|
+
inputs: [
|
|
1168
|
+
{ name: "owner", type: "address" },
|
|
1169
|
+
{ name: "wordPos", type: "uint256" }
|
|
1170
|
+
],
|
|
1171
|
+
name: "nonceBitmap",
|
|
1172
|
+
outputs: [{ name: "", type: "uint256" }],
|
|
1173
|
+
stateMutability: "view",
|
|
1174
|
+
type: "function"
|
|
1175
|
+
}
|
|
1176
|
+
],
|
|
1177
|
+
functionName: "nonceBitmap",
|
|
1178
|
+
args: [order.user, nonceWordPos]
|
|
1179
|
+
})
|
|
1180
|
+
]);
|
|
1181
|
+
if (wasManuallyInitialized) {
|
|
1182
|
+
return await wallet.sendTransaction({
|
|
1183
|
+
to: import_intents_sdk14.SINGLE_CHAIN_GUARD_ADDRESSES[chainId],
|
|
1184
|
+
data: (0, import_viem8.encodeFunctionData)({
|
|
1185
|
+
abi: [
|
|
1186
|
+
{
|
|
1187
|
+
inputs: [
|
|
1188
|
+
{
|
|
1189
|
+
name: "order",
|
|
1190
|
+
type: "tuple",
|
|
1191
|
+
components: [
|
|
1192
|
+
{ name: "amountIn", type: "uint256" },
|
|
1193
|
+
{ name: "tokenIn", type: "address" },
|
|
1194
|
+
{ name: "deadline", type: "uint256" },
|
|
1195
|
+
{ name: "nonce", type: "uint256" },
|
|
1196
|
+
{ name: "encodedExternalCallData", type: "bytes" },
|
|
1197
|
+
{
|
|
1198
|
+
name: "extraTransfers",
|
|
1199
|
+
type: "tuple[]",
|
|
1200
|
+
components: [
|
|
1201
|
+
{ name: "amount", type: "uint256" },
|
|
1202
|
+
{ name: "receiver", type: "address" },
|
|
1203
|
+
{ name: "token", type: "address" }
|
|
1204
|
+
]
|
|
1205
|
+
},
|
|
1206
|
+
{
|
|
1207
|
+
name: "requestedOutput",
|
|
1208
|
+
type: "tuple",
|
|
1209
|
+
components: [
|
|
1210
|
+
{ name: "amount", type: "uint256" },
|
|
1211
|
+
{ name: "receiver", type: "address" },
|
|
1212
|
+
{ name: "token", type: "address" }
|
|
1213
|
+
]
|
|
1214
|
+
},
|
|
1215
|
+
{ name: "user", type: "address" }
|
|
1216
|
+
]
|
|
1217
|
+
}
|
|
1218
|
+
],
|
|
1219
|
+
name: "cancelManuallyCreatedOrder",
|
|
1220
|
+
outputs: [],
|
|
1221
|
+
stateMutability: "nonpayable",
|
|
1222
|
+
type: "function"
|
|
1223
|
+
}
|
|
1224
|
+
],
|
|
1225
|
+
functionName: "cancelManuallyCreatedOrder",
|
|
1226
|
+
args: [
|
|
1227
|
+
{
|
|
1228
|
+
amountIn: BigInt(order.amountIn),
|
|
1229
|
+
tokenIn: order.tokenIn,
|
|
1230
|
+
deadline: BigInt(order.deadline),
|
|
1231
|
+
nonce,
|
|
1232
|
+
encodedExternalCallData: "0x",
|
|
1233
|
+
extraTransfers: (order.extraTransfers || []).map((t) => ({
|
|
1234
|
+
amount: BigInt(t.amount),
|
|
1235
|
+
receiver: t.receiver,
|
|
1236
|
+
token: t.token
|
|
1237
|
+
})),
|
|
1238
|
+
requestedOutput: {
|
|
1239
|
+
amount: BigInt(order.amountOutMin),
|
|
1240
|
+
receiver: order.destinationAddress,
|
|
1241
|
+
token: order.tokenOut
|
|
1242
|
+
},
|
|
1243
|
+
user: order.user
|
|
1244
|
+
}
|
|
1245
|
+
]
|
|
1246
|
+
}),
|
|
1247
|
+
value: 0n,
|
|
1248
|
+
from: order.user
|
|
1249
|
+
});
|
|
1250
|
+
}
|
|
1251
|
+
const mask = 1n << nonceBitPos;
|
|
1252
|
+
if ((currentBitmap & mask) !== 0n) {
|
|
1253
|
+
throw new Error("Nonce is already invalidated");
|
|
1254
|
+
}
|
|
1255
|
+
return await wallet.sendTransaction({
|
|
1256
|
+
to: import_intents_sdk14.PERMIT2_ADDRESS[chainId],
|
|
1257
|
+
data: (0, import_viem8.encodeFunctionData)({
|
|
1258
|
+
abi: [
|
|
1259
|
+
{
|
|
1260
|
+
inputs: [
|
|
1261
|
+
{ name: "wordPos", type: "uint256" },
|
|
1262
|
+
{ name: "mask", type: "uint256" }
|
|
1263
|
+
],
|
|
1264
|
+
name: "invalidateUnorderedNonces",
|
|
1265
|
+
outputs: [],
|
|
1266
|
+
stateMutability: "nonpayable",
|
|
1267
|
+
type: "function"
|
|
1268
|
+
}
|
|
1269
|
+
],
|
|
1270
|
+
functionName: "invalidateUnorderedNonces",
|
|
1271
|
+
args: [nonceWordPos, mask]
|
|
1272
|
+
}),
|
|
1273
|
+
value: 0n,
|
|
1274
|
+
from: order.user
|
|
1275
|
+
});
|
|
1276
|
+
}
|
|
1277
|
+
|
|
989
1278
|
// src/core/client.ts
|
|
990
1279
|
var SwapSDK = class {
|
|
991
1280
|
constructor(config) {
|
|
@@ -1146,6 +1435,25 @@ var SwapSDK = class {
|
|
|
1146
1435
|
async getOrders(params) {
|
|
1147
1436
|
return getOrders(params);
|
|
1148
1437
|
}
|
|
1438
|
+
/**
|
|
1439
|
+
* Cancels an order (single-chain or cross-chain) on EVM or Solana.
|
|
1440
|
+
*
|
|
1441
|
+
* Internally routes to the correct guard contract or Solana program to
|
|
1442
|
+
* deactivate the order or invalidate its nonce.
|
|
1443
|
+
*
|
|
1444
|
+
* @param params.order - Order payload returned from the Intents API.
|
|
1445
|
+
* @param params.wallet - Adapted wallet used to submit the cancellation transaction.
|
|
1446
|
+
* @param params.solRpc - Solana RPC URL used for SVM cancellations.
|
|
1447
|
+
*
|
|
1448
|
+
* @returns A transaction signature or hash from the underlying wallet.
|
|
1449
|
+
*/
|
|
1450
|
+
async cancelOrder(params) {
|
|
1451
|
+
return cancelIntentsOrder({
|
|
1452
|
+
order: params.order,
|
|
1453
|
+
wallet: params.wallet,
|
|
1454
|
+
sol_rpc: params.solRpc
|
|
1455
|
+
});
|
|
1456
|
+
}
|
|
1149
1457
|
};
|
|
1150
1458
|
|
|
1151
1459
|
// src/react/SwapProvider.tsx
|
|
@@ -1560,3 +1868,43 @@ function useOrders(initialAddresses) {
|
|
|
1560
1868
|
[data, loading, error, refetch, setAddresses]
|
|
1561
1869
|
);
|
|
1562
1870
|
}
|
|
1871
|
+
|
|
1872
|
+
// src/react/useCancelOrder.ts
|
|
1873
|
+
var import_react8 = require("react");
|
|
1874
|
+
var import_swr4 = require("swr");
|
|
1875
|
+
function useCancelOrder() {
|
|
1876
|
+
const sdk = useSwap();
|
|
1877
|
+
const [isLoading, setLoading] = (0, import_react8.useState)(false);
|
|
1878
|
+
const [error, setError] = (0, import_react8.useState)(null);
|
|
1879
|
+
const [result, setResult] = (0, import_react8.useState)(null);
|
|
1880
|
+
const cancel = (0, import_react8.useCallback)(
|
|
1881
|
+
async (params) => {
|
|
1882
|
+
setLoading(true);
|
|
1883
|
+
setError(null);
|
|
1884
|
+
setResult(null);
|
|
1885
|
+
try {
|
|
1886
|
+
const tx = await sdk.cancelOrder({
|
|
1887
|
+
order: params.order,
|
|
1888
|
+
wallet: params.wallet,
|
|
1889
|
+
solRpc: params.solRpc
|
|
1890
|
+
});
|
|
1891
|
+
setResult(tx);
|
|
1892
|
+
void (0, import_swr4.mutate)("orders-global");
|
|
1893
|
+
return tx;
|
|
1894
|
+
} catch (err) {
|
|
1895
|
+
const msg = err instanceof Error ? err.message : String(err);
|
|
1896
|
+
setError(msg);
|
|
1897
|
+
throw err;
|
|
1898
|
+
} finally {
|
|
1899
|
+
setLoading(false);
|
|
1900
|
+
}
|
|
1901
|
+
},
|
|
1902
|
+
[sdk]
|
|
1903
|
+
);
|
|
1904
|
+
return {
|
|
1905
|
+
cancel,
|
|
1906
|
+
isLoading,
|
|
1907
|
+
error,
|
|
1908
|
+
result
|
|
1909
|
+
};
|
|
1910
|
+
}
|