@dzapio/sdk 2.0.50 → 2.0.52
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/index.d.mts +91 -25
- package/dist/index.d.ts +91 -25
- package/dist/index.js +2167 -2050
- package/dist/index.mjs +2168 -2051
- package/package.json +2 -2
package/dist/index.mjs
CHANGED
|
@@ -1,15 +1,15 @@
|
|
|
1
|
-
import { encodeAbiParameters, parseAbiParameters, keccak256, encodePacked, stringToHex, defineChain as defineChain$1, zeroAddress as zeroAddress$1, isAddress, getAddress, formatUnits, http, createPublicClient, fallback, parseEventLogs,
|
|
1
|
+
import { encodeAbiParameters, parseAbiParameters, keccak256, encodePacked, stringToHex, defineChain as defineChain$1, zeroAddress as zeroAddress$1, isAddress, getAddress, formatUnits, maxUint256, encodeFunctionData, http, createPublicClient, fallback, parseEventLogs, maxUint48, getContract, decodeAbiParameters } from 'viem';
|
|
2
2
|
import Axios from 'axios';
|
|
3
3
|
import { Signer, ethers } from 'ethers';
|
|
4
4
|
import * as viemChains from 'viem/chains';
|
|
5
5
|
import { arcTestnet as arcTestnet$1, tempo as tempo$1, hemi as hemi$1, citrea as citrea$1, bitlayer as bitlayer$1, merlin as merlin$1, katana as katana$1 } from 'viem/chains';
|
|
6
6
|
import { defineChain, ChainId } from '@bigmi/core';
|
|
7
7
|
export { bitcoin } from '@bigmi/core';
|
|
8
|
-
import { decodeFunctionData, getAction } from 'viem/utils';
|
|
9
8
|
import { waitForCallsStatus, sendCalls } from 'viem/actions';
|
|
9
|
+
import { getAction, decodeFunctionData } from 'viem/utils';
|
|
10
|
+
import { Connection, clusterApiUrl, PublicKey } from '@solana/web3.js';
|
|
10
11
|
import Decimal from 'decimal.js';
|
|
11
12
|
import { validate, Network } from 'bitcoin-address-validation';
|
|
12
|
-
import { Connection, clusterApiUrl, PublicKey } from '@solana/web3.js';
|
|
13
13
|
import TonWeb from 'tonweb';
|
|
14
14
|
|
|
15
15
|
var __defProp = Object.defineProperty;
|
|
@@ -538,6 +538,7 @@ var eFormatNativeTokenLowerCase = "0xeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeee";
|
|
|
538
538
|
var eFormatNativeToken = "0xEeeeeEeeeEeEeeEeEeEeeEEEeeeeEeeeeeeeEEeE";
|
|
539
539
|
var zkNativeToken = "0x000000000000000000000000000000000000800A";
|
|
540
540
|
var solanaNativeToken = "11111111111111111111111111111111";
|
|
541
|
+
var solanaWNativeToken = "So11111111111111111111111111111111111111112";
|
|
541
542
|
var unmarshalDeadAddress = "0xDeadDeAddeAddEAddeadDEaDDEAdDeaDDeAD0000";
|
|
542
543
|
var tonNativeToken = "EQAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAM9c";
|
|
543
544
|
var artheraNativeToken = "0x000000000000000000000000000000000000aA09";
|
|
@@ -10898,1238 +10899,218 @@ var viemChainsById = [...Object.values(viemChains), ...customViemChains].reduce(
|
|
|
10898
10899
|
var RPC_RETRY_DELAY = 500;
|
|
10899
10900
|
var RPC_BATCHING_WAIT_TIME = 1e3;
|
|
10900
10901
|
|
|
10901
|
-
// src/utils/
|
|
10902
|
-
var
|
|
10903
|
-
|
|
10904
|
-
|
|
10905
|
-
|
|
10906
|
-
|
|
10907
|
-
|
|
10908
|
-
|
|
10909
|
-
|
|
10910
|
-
|
|
10911
|
-
|
|
10912
|
-
|
|
10913
|
-
|
|
10914
|
-
|
|
10915
|
-
},
|
|
10916
|
-
{
|
|
10917
|
-
internalType: "bytes",
|
|
10918
|
-
name: "_feeVerificationSignature",
|
|
10919
|
-
type: "bytes"
|
|
10920
|
-
},
|
|
10921
|
-
{
|
|
10922
|
-
internalType: "uint256",
|
|
10923
|
-
name: "_deadline",
|
|
10924
|
-
type: "uint256"
|
|
10925
|
-
},
|
|
10926
|
-
{
|
|
10927
|
-
components: [
|
|
10928
|
-
{
|
|
10929
|
-
internalType: "address",
|
|
10930
|
-
name: "token",
|
|
10931
|
-
type: "address"
|
|
10932
|
-
},
|
|
10933
|
-
{
|
|
10934
|
-
internalType: "uint256",
|
|
10935
|
-
name: "amount",
|
|
10936
|
-
type: "uint256"
|
|
10937
|
-
},
|
|
10938
|
-
{
|
|
10939
|
-
internalType: "bytes",
|
|
10940
|
-
name: "permit",
|
|
10941
|
-
type: "bytes"
|
|
10942
|
-
}
|
|
10943
|
-
],
|
|
10944
|
-
internalType: "struct InputToken",
|
|
10945
|
-
name: "_inputTokens",
|
|
10946
|
-
type: "tuple"
|
|
10947
|
-
},
|
|
10948
|
-
{
|
|
10949
|
-
components: [
|
|
10950
|
-
{
|
|
10951
|
-
internalType: "address",
|
|
10952
|
-
name: "recipient",
|
|
10953
|
-
type: "address"
|
|
10954
|
-
},
|
|
10955
|
-
{
|
|
10956
|
-
internalType: "address",
|
|
10957
|
-
name: "from",
|
|
10958
|
-
type: "address"
|
|
10959
|
-
},
|
|
10960
|
-
{
|
|
10961
|
-
internalType: "address",
|
|
10962
|
-
name: "to",
|
|
10963
|
-
type: "address"
|
|
10964
|
-
},
|
|
10965
|
-
{
|
|
10966
|
-
internalType: "uint256",
|
|
10967
|
-
name: "fromAmount",
|
|
10968
|
-
type: "uint256"
|
|
10969
|
-
},
|
|
10970
|
-
{
|
|
10971
|
-
internalType: "uint256",
|
|
10972
|
-
name: "minToAmount",
|
|
10973
|
-
type: "uint256"
|
|
10974
|
-
}
|
|
10975
|
-
],
|
|
10976
|
-
internalType: "struct SwapData",
|
|
10977
|
-
name: "_swapData",
|
|
10978
|
-
type: "tuple"
|
|
10979
|
-
},
|
|
10980
|
-
{
|
|
10981
|
-
components: [
|
|
10982
|
-
{
|
|
10983
|
-
internalType: "string",
|
|
10984
|
-
name: "dex",
|
|
10985
|
-
type: "string"
|
|
10986
|
-
},
|
|
10987
|
-
{
|
|
10988
|
-
internalType: "address",
|
|
10989
|
-
name: "callTo",
|
|
10990
|
-
type: "address"
|
|
10991
|
-
},
|
|
10992
|
-
{
|
|
10993
|
-
internalType: "address",
|
|
10994
|
-
name: "approveTo",
|
|
10995
|
-
type: "address"
|
|
10996
|
-
},
|
|
10997
|
-
{
|
|
10998
|
-
internalType: "bytes",
|
|
10999
|
-
name: "swapCallData",
|
|
11000
|
-
type: "bytes"
|
|
11001
|
-
},
|
|
11002
|
-
{
|
|
11003
|
-
internalType: "bool",
|
|
11004
|
-
name: "isDirectTransfer",
|
|
11005
|
-
type: "bool"
|
|
11006
|
-
}
|
|
11007
|
-
],
|
|
11008
|
-
internalType: "struct SwapExecutionData",
|
|
11009
|
-
name: "_swapExecutionData",
|
|
11010
|
-
type: "tuple"
|
|
11011
|
-
}
|
|
11012
|
-
],
|
|
11013
|
-
name: "swap",
|
|
11014
|
-
outputs: [],
|
|
11015
|
-
stateMutability: "payable",
|
|
11016
|
-
type: "function"
|
|
10902
|
+
// src/utils/index.ts
|
|
10903
|
+
var publicClientRpcConfig = { batch: { wait: RPC_BATCHING_WAIT_TIME }, retryDelay: RPC_RETRY_DELAY };
|
|
10904
|
+
var getPublicClient = ({ rpcUrls, chainId }) => {
|
|
10905
|
+
var _a, _b;
|
|
10906
|
+
const chain = viemChainsById[chainId];
|
|
10907
|
+
const urls = ((rpcUrls == null ? void 0 : rpcUrls.length) ? rpcUrls : (_b = (_a = chain == null ? void 0 : chain.rpcUrls) == null ? void 0 : _a.default) == null ? void 0 : _b.http) ?? [];
|
|
10908
|
+
const transports = urls.length ? urls.map((url) => http(url, publicClientRpcConfig)) : [http()];
|
|
10909
|
+
return createPublicClient({
|
|
10910
|
+
chain,
|
|
10911
|
+
transport: fallback(transports),
|
|
10912
|
+
batch: {
|
|
10913
|
+
multicall: {
|
|
10914
|
+
wait: RPC_BATCHING_WAIT_TIME
|
|
10915
|
+
}
|
|
11017
10916
|
}
|
|
11018
|
-
|
|
11019
|
-
|
|
11020
|
-
|
|
11021
|
-
|
|
11022
|
-
|
|
11023
|
-
|
|
11024
|
-
|
|
11025
|
-
|
|
11026
|
-
|
|
11027
|
-
|
|
11028
|
-
|
|
11029
|
-
|
|
11030
|
-
|
|
11031
|
-
|
|
11032
|
-
|
|
11033
|
-
|
|
11034
|
-
|
|
11035
|
-
|
|
11036
|
-
|
|
11037
|
-
|
|
11038
|
-
|
|
11039
|
-
|
|
11040
|
-
|
|
11041
|
-
|
|
11042
|
-
|
|
11043
|
-
|
|
11044
|
-
|
|
11045
|
-
|
|
11046
|
-
|
|
11047
|
-
|
|
11048
|
-
|
|
11049
|
-
|
|
11050
|
-
|
|
11051
|
-
|
|
11052
|
-
|
|
11053
|
-
|
|
11054
|
-
|
|
11055
|
-
|
|
11056
|
-
|
|
11057
|
-
|
|
11058
|
-
name: "amount",
|
|
11059
|
-
type: "uint256"
|
|
11060
|
-
}
|
|
11061
|
-
],
|
|
11062
|
-
internalType: "struct TokenPermissions[]",
|
|
11063
|
-
name: "permitted",
|
|
11064
|
-
type: "tuple[]"
|
|
11065
|
-
},
|
|
11066
|
-
{
|
|
11067
|
-
internalType: "uint256",
|
|
11068
|
-
name: "nonce",
|
|
11069
|
-
type: "uint256"
|
|
11070
|
-
},
|
|
11071
|
-
{
|
|
11072
|
-
internalType: "uint256",
|
|
11073
|
-
name: "deadline",
|
|
11074
|
-
type: "uint256"
|
|
11075
|
-
}
|
|
11076
|
-
],
|
|
11077
|
-
internalType: "struct PermitBatchTransferFrom",
|
|
11078
|
-
name: "_tokenDepositDetails",
|
|
11079
|
-
type: "tuple"
|
|
11080
|
-
},
|
|
11081
|
-
{
|
|
11082
|
-
components: [
|
|
11083
|
-
{
|
|
11084
|
-
internalType: "address",
|
|
11085
|
-
name: "recipient",
|
|
11086
|
-
type: "address"
|
|
11087
|
-
},
|
|
11088
|
-
{
|
|
11089
|
-
internalType: "address",
|
|
11090
|
-
name: "from",
|
|
11091
|
-
type: "address"
|
|
11092
|
-
},
|
|
11093
|
-
{
|
|
11094
|
-
internalType: "address",
|
|
11095
|
-
name: "to",
|
|
11096
|
-
type: "address"
|
|
11097
|
-
},
|
|
11098
|
-
{
|
|
11099
|
-
internalType: "uint256",
|
|
11100
|
-
name: "fromAmount",
|
|
11101
|
-
type: "uint256"
|
|
11102
|
-
},
|
|
11103
|
-
{
|
|
11104
|
-
internalType: "uint256",
|
|
11105
|
-
name: "minToAmount",
|
|
11106
|
-
type: "uint256"
|
|
11107
|
-
}
|
|
11108
|
-
],
|
|
11109
|
-
internalType: "struct SwapData[]",
|
|
11110
|
-
name: "_swapData",
|
|
11111
|
-
type: "tuple[]"
|
|
11112
|
-
},
|
|
11113
|
-
{
|
|
11114
|
-
components: [
|
|
11115
|
-
{
|
|
11116
|
-
internalType: "string",
|
|
11117
|
-
name: "dex",
|
|
11118
|
-
type: "string"
|
|
11119
|
-
},
|
|
11120
|
-
{
|
|
11121
|
-
internalType: "address",
|
|
11122
|
-
name: "callTo",
|
|
11123
|
-
type: "address"
|
|
11124
|
-
},
|
|
11125
|
-
{
|
|
11126
|
-
internalType: "address",
|
|
11127
|
-
name: "approveTo",
|
|
11128
|
-
type: "address"
|
|
11129
|
-
},
|
|
11130
|
-
{
|
|
11131
|
-
internalType: "bytes",
|
|
11132
|
-
name: "swapCallData",
|
|
11133
|
-
type: "bytes"
|
|
11134
|
-
},
|
|
11135
|
-
{
|
|
11136
|
-
internalType: "bool",
|
|
11137
|
-
name: "isDirectTransfer",
|
|
11138
|
-
type: "bool"
|
|
11139
|
-
}
|
|
11140
|
-
],
|
|
11141
|
-
internalType: "struct SwapExecutionData[]",
|
|
11142
|
-
name: "_swapExecutionData",
|
|
11143
|
-
type: "tuple[]"
|
|
11144
|
-
},
|
|
11145
|
-
{
|
|
11146
|
-
internalType: "bool",
|
|
11147
|
-
name: "withoutRevert",
|
|
11148
|
-
type: "bool"
|
|
11149
|
-
}
|
|
11150
|
-
],
|
|
11151
|
-
name: "swap",
|
|
11152
|
-
outputs: [],
|
|
11153
|
-
stateMutability: "payable",
|
|
11154
|
-
type: "function"
|
|
10917
|
+
});
|
|
10918
|
+
};
|
|
10919
|
+
function getTokensPairKey({
|
|
10920
|
+
srcToken,
|
|
10921
|
+
destToken,
|
|
10922
|
+
srcChainId,
|
|
10923
|
+
destChainId,
|
|
10924
|
+
srcChainNativeAddress = zeroAddress$1,
|
|
10925
|
+
destChainNativeAddress = zeroAddress$1
|
|
10926
|
+
}) {
|
|
10927
|
+
const srcFormattedAddress = formatToken(srcToken, srcChainNativeAddress);
|
|
10928
|
+
const destFormattedAddress = formatToken(destToken, destChainNativeAddress);
|
|
10929
|
+
return `${srcChainId}_${srcFormattedAddress}-${destChainId}_${destFormattedAddress}`;
|
|
10930
|
+
}
|
|
10931
|
+
var writeContract = async ({
|
|
10932
|
+
chainId,
|
|
10933
|
+
contractAddress,
|
|
10934
|
+
abi: abi7,
|
|
10935
|
+
functionName,
|
|
10936
|
+
args = [],
|
|
10937
|
+
value = "0",
|
|
10938
|
+
rpcUrls = [""],
|
|
10939
|
+
signer
|
|
10940
|
+
}) => {
|
|
10941
|
+
const publicClient = getPublicClient({ chainId, rpcUrls });
|
|
10942
|
+
try {
|
|
10943
|
+
const { request } = await publicClient.simulateContract({
|
|
10944
|
+
address: contractAddress,
|
|
10945
|
+
abi: abi7,
|
|
10946
|
+
functionName,
|
|
10947
|
+
args,
|
|
10948
|
+
account: signer.account,
|
|
10949
|
+
value: BigInt(value)
|
|
10950
|
+
});
|
|
10951
|
+
const hash = await signer.writeContract(request);
|
|
10952
|
+
return { txnHash: hash, status: "success" /* success */, code: 200 /* Success */ };
|
|
10953
|
+
} catch (e) {
|
|
10954
|
+
console.log({ e });
|
|
10955
|
+
if ((e == null ? void 0 : e.code) === 4001 /* UserRejectedRequest */) {
|
|
10956
|
+
return { status: "rejected" /* rejected */, code: e == null ? void 0 : e.code, txnHash: "" };
|
|
11155
10957
|
}
|
|
11156
|
-
|
|
11157
|
-
|
|
10958
|
+
return { status: "error" /* error */, code: e == null ? void 0 : e.code, txnHash: "" };
|
|
10959
|
+
}
|
|
10960
|
+
};
|
|
10961
|
+
var calcTotalSrcTokenAmount = (data) => {
|
|
10962
|
+
return data.reduce((acc, obj) => {
|
|
10963
|
+
return acc + BigInt(obj.amount);
|
|
10964
|
+
}, BigInt(0));
|
|
10965
|
+
};
|
|
10966
|
+
var isOneToMany = (firstTokenAddress, secondTokenAddress) => firstTokenAddress === secondTokenAddress;
|
|
10967
|
+
BigInt(15) / BigInt(10);
|
|
10968
|
+
var isTypeSigner = (variable) => {
|
|
10969
|
+
return variable instanceof Signer;
|
|
10970
|
+
};
|
|
10971
|
+
var isDZapNativeToken = (srcToken) => srcToken === dZapNativeTokenFormat;
|
|
10972
|
+
var getDZapAbi = (service, version) => {
|
|
10973
|
+
switch (service) {
|
|
10974
|
+
case Services.trade:
|
|
10975
|
+
switch (version) {
|
|
10976
|
+
case "v1" /* v1 */:
|
|
10977
|
+
return artifacts_exports[DZapAbis.dZapCoreAbi];
|
|
10978
|
+
case "v2" /* v2 */:
|
|
10979
|
+
return artifacts_exports[DZapAbis.dZapCoreV2Abi];
|
|
10980
|
+
default:
|
|
10981
|
+
throw new Error("Invalid Version for Trade");
|
|
10982
|
+
}
|
|
10983
|
+
case Services.dca:
|
|
10984
|
+
return artifacts_exports[DZapAbis.dZapDcaAbi];
|
|
10985
|
+
case Services.zap:
|
|
10986
|
+
default:
|
|
10987
|
+
throw new Error("Invalid Service");
|
|
10988
|
+
}
|
|
10989
|
+
};
|
|
10990
|
+
var getOtherAbis = (name) => {
|
|
10991
|
+
switch (name) {
|
|
10992
|
+
case OtherAbis.permit2:
|
|
10993
|
+
return abi4;
|
|
10994
|
+
case OtherAbis.erc20:
|
|
10995
|
+
return abi5;
|
|
10996
|
+
default:
|
|
10997
|
+
throw new Error("Invalid Abi");
|
|
10998
|
+
}
|
|
10999
|
+
};
|
|
11000
|
+
var BRIDGE_ERRORS = {
|
|
11001
|
+
BridgeCallFailed: "BridgeCallFailed"
|
|
11002
|
+
};
|
|
11003
|
+
function getErrorName(errorString) {
|
|
11004
|
+
const match = errorString.match(/Error: (\w+)/);
|
|
11005
|
+
return match ? match[1] : null;
|
|
11006
|
+
}
|
|
11007
|
+
var getRevertMsg = (res) => {
|
|
11008
|
+
if (res.length < 68) {
|
|
11009
|
+
return res;
|
|
11010
|
+
}
|
|
11011
|
+
const revertData = "0x" + res.slice(10);
|
|
11012
|
+
const msg = decodeAbiParameters(parseAbiParameters("string"), revertData)[0];
|
|
11013
|
+
return msg;
|
|
11014
|
+
};
|
|
11015
|
+
var isAxiosError = (error) => {
|
|
11016
|
+
return Boolean(error) && error.isAxiosError;
|
|
11017
|
+
};
|
|
11018
|
+
var handleViemTransactionError = ({ error }) => {
|
|
11019
|
+
var _a, _b;
|
|
11020
|
+
if ((error == null ? void 0 : error.code) === 429 /* WalletRPCFailure */ || ((_a = error == null ? void 0 : error.cause) == null ? void 0 : _a.code) === 429 /* WalletRPCFailure */) {
|
|
11021
|
+
return {
|
|
11022
|
+
error,
|
|
11023
|
+
errorMsg: "Too many requests, failure on user wallet",
|
|
11024
|
+
code: 429 /* WalletRPCFailure */,
|
|
11025
|
+
status: "error" /* error */
|
|
11026
|
+
};
|
|
11027
|
+
}
|
|
11028
|
+
if ((error == null ? void 0 : error.code) === 4001 /* UserRejectedRequest */ || ((_b = error == null ? void 0 : error.cause) == null ? void 0 : _b.code) === 4001 /* UserRejectedRequest */) {
|
|
11029
|
+
return {
|
|
11030
|
+
error,
|
|
11031
|
+
errorMsg: "Rejected by User",
|
|
11032
|
+
code: 4001 /* UserRejectedRequest */,
|
|
11033
|
+
status: "rejected" /* rejected */
|
|
11034
|
+
};
|
|
11035
|
+
}
|
|
11036
|
+
let errMsg = error.shortMessage;
|
|
11037
|
+
const errName = getErrorName(error.metaMessages[0]);
|
|
11038
|
+
if (errName == BRIDGE_ERRORS.BridgeCallFailed) {
|
|
11039
|
+
let msg = error.metaMessages[1];
|
|
11040
|
+
try {
|
|
11041
|
+
msg = getRevertMsg(error.metaMessages[1].match(/\((.*?)\)/)[1]);
|
|
11042
|
+
} catch (err) {
|
|
11043
|
+
}
|
|
11044
|
+
errMsg = `${BRIDGE_ERRORS.BridgeCallFailed} : ${msg}`;
|
|
11045
|
+
} else if (errName) {
|
|
11046
|
+
errMsg = errName;
|
|
11047
|
+
}
|
|
11048
|
+
return {
|
|
11049
|
+
status: "error" /* error */,
|
|
11050
|
+
error,
|
|
11051
|
+
errorMsg: errMsg,
|
|
11052
|
+
code: -500 /* ContractExecutionError */
|
|
11053
|
+
};
|
|
11054
|
+
};
|
|
11055
|
+
|
|
11056
|
+
// src/transactionHandlers/generic.ts
|
|
11057
|
+
var GenericTxnHandler = class {
|
|
11058
|
+
};
|
|
11059
|
+
GenericTxnHandler.sendTransaction = async ({
|
|
11060
|
+
chainId,
|
|
11061
|
+
signer,
|
|
11062
|
+
from,
|
|
11063
|
+
to,
|
|
11064
|
+
data,
|
|
11065
|
+
value
|
|
11066
|
+
}) => {
|
|
11067
|
+
try {
|
|
11068
|
+
if (isTypeSigner(signer)) {
|
|
11069
|
+
console.log("Using ethers signer.");
|
|
11070
|
+
const txnRes = await signer.sendTransaction({
|
|
11071
|
+
from,
|
|
11072
|
+
to,
|
|
11073
|
+
data,
|
|
11074
|
+
value
|
|
11075
|
+
});
|
|
11076
|
+
return {
|
|
11077
|
+
status: "success" /* success */,
|
|
11078
|
+
code: 200 /* Success */,
|
|
11079
|
+
txnHash: txnRes.hash
|
|
11080
|
+
};
|
|
11081
|
+
} else {
|
|
11082
|
+
console.log("Using viem walletClient.");
|
|
11083
|
+
const txnHash = await signer.sendTransaction({
|
|
11084
|
+
chain: viemChainsById[chainId],
|
|
11085
|
+
account: from,
|
|
11086
|
+
to,
|
|
11087
|
+
data,
|
|
11088
|
+
value: BigInt(value)
|
|
11089
|
+
});
|
|
11090
|
+
return {
|
|
11091
|
+
status: "success" /* success */,
|
|
11092
|
+
code: 200 /* Success */,
|
|
11093
|
+
txnHash
|
|
11094
|
+
};
|
|
11095
|
+
}
|
|
11096
|
+
} catch (error) {
|
|
11097
|
+
console.log({ error });
|
|
11098
|
+
return handleViemTransactionError({ error });
|
|
11099
|
+
}
|
|
11100
|
+
};
|
|
11101
|
+
var generic_default = GenericTxnHandler;
|
|
11102
|
+
|
|
11103
|
+
// src/types/eip-2612.ts
|
|
11104
|
+
var EIP2612DefaultTypes = {
|
|
11105
|
+
Permit: [
|
|
11158
11106
|
{
|
|
11159
|
-
|
|
11160
|
-
|
|
11161
|
-
|
|
11162
|
-
name: "_transactionId",
|
|
11163
|
-
type: "bytes32"
|
|
11164
|
-
},
|
|
11165
|
-
{
|
|
11166
|
-
internalType: "bytes",
|
|
11167
|
-
name: "_feeData",
|
|
11168
|
-
type: "bytes"
|
|
11169
|
-
},
|
|
11170
|
-
{
|
|
11171
|
-
internalType: "bytes",
|
|
11172
|
-
name: "_feeVerificationSignature",
|
|
11173
|
-
type: "bytes"
|
|
11174
|
-
},
|
|
11175
|
-
{
|
|
11176
|
-
internalType: "uint256",
|
|
11177
|
-
name: "_deadline",
|
|
11178
|
-
type: "uint256"
|
|
11179
|
-
},
|
|
11180
|
-
{
|
|
11181
|
-
components: [
|
|
11182
|
-
{
|
|
11183
|
-
internalType: "address",
|
|
11184
|
-
name: "token",
|
|
11185
|
-
type: "address"
|
|
11186
|
-
},
|
|
11187
|
-
{
|
|
11188
|
-
internalType: "uint256",
|
|
11189
|
-
name: "amount",
|
|
11190
|
-
type: "uint256"
|
|
11191
|
-
},
|
|
11192
|
-
{
|
|
11193
|
-
internalType: "bytes",
|
|
11194
|
-
name: "permit",
|
|
11195
|
-
type: "bytes"
|
|
11196
|
-
}
|
|
11197
|
-
],
|
|
11198
|
-
internalType: "struct InputToken[]",
|
|
11199
|
-
name: "_inputTokens",
|
|
11200
|
-
type: "tuple[]"
|
|
11201
|
-
},
|
|
11202
|
-
{
|
|
11203
|
-
components: [
|
|
11204
|
-
{
|
|
11205
|
-
internalType: "address",
|
|
11206
|
-
name: "recipient",
|
|
11207
|
-
type: "address"
|
|
11208
|
-
},
|
|
11209
|
-
{
|
|
11210
|
-
internalType: "address",
|
|
11211
|
-
name: "from",
|
|
11212
|
-
type: "address"
|
|
11213
|
-
},
|
|
11214
|
-
{
|
|
11215
|
-
internalType: "address",
|
|
11216
|
-
name: "to",
|
|
11217
|
-
type: "address"
|
|
11218
|
-
},
|
|
11219
|
-
{
|
|
11220
|
-
internalType: "uint256",
|
|
11221
|
-
name: "fromAmount",
|
|
11222
|
-
type: "uint256"
|
|
11223
|
-
},
|
|
11224
|
-
{
|
|
11225
|
-
internalType: "uint256",
|
|
11226
|
-
name: "minToAmount",
|
|
11227
|
-
type: "uint256"
|
|
11228
|
-
}
|
|
11229
|
-
],
|
|
11230
|
-
internalType: "struct SwapData[]",
|
|
11231
|
-
name: "_swapData",
|
|
11232
|
-
type: "tuple[]"
|
|
11233
|
-
},
|
|
11234
|
-
{
|
|
11235
|
-
components: [
|
|
11236
|
-
{
|
|
11237
|
-
internalType: "string",
|
|
11238
|
-
name: "dex",
|
|
11239
|
-
type: "string"
|
|
11240
|
-
},
|
|
11241
|
-
{
|
|
11242
|
-
internalType: "address",
|
|
11243
|
-
name: "callTo",
|
|
11244
|
-
type: "address"
|
|
11245
|
-
},
|
|
11246
|
-
{
|
|
11247
|
-
internalType: "address",
|
|
11248
|
-
name: "approveTo",
|
|
11249
|
-
type: "address"
|
|
11250
|
-
},
|
|
11251
|
-
{
|
|
11252
|
-
internalType: "bytes",
|
|
11253
|
-
name: "swapCallData",
|
|
11254
|
-
type: "bytes"
|
|
11255
|
-
},
|
|
11256
|
-
{
|
|
11257
|
-
internalType: "bool",
|
|
11258
|
-
name: "isDirectTransfer",
|
|
11259
|
-
type: "bool"
|
|
11260
|
-
}
|
|
11261
|
-
],
|
|
11262
|
-
internalType: "struct SwapExecutionData[]",
|
|
11263
|
-
name: "_swapExecutionData",
|
|
11264
|
-
type: "tuple[]"
|
|
11265
|
-
},
|
|
11266
|
-
{
|
|
11267
|
-
internalType: "bool",
|
|
11268
|
-
name: "withoutRevert",
|
|
11269
|
-
type: "bool"
|
|
11270
|
-
}
|
|
11271
|
-
],
|
|
11272
|
-
name: "swap",
|
|
11273
|
-
outputs: [],
|
|
11274
|
-
stateMutability: "payable",
|
|
11275
|
-
type: "function"
|
|
11276
|
-
}
|
|
11277
|
-
],
|
|
11278
|
-
GaslessExecuteMultiSwapAbi: [
|
|
11107
|
+
name: "owner",
|
|
11108
|
+
type: "address"
|
|
11109
|
+
},
|
|
11279
11110
|
{
|
|
11280
|
-
|
|
11281
|
-
|
|
11282
|
-
|
|
11283
|
-
name: "_transactionId",
|
|
11284
|
-
type: "bytes32"
|
|
11285
|
-
},
|
|
11286
|
-
{
|
|
11287
|
-
internalType: "bytes",
|
|
11288
|
-
name: "_feeData",
|
|
11289
|
-
type: "bytes"
|
|
11290
|
-
},
|
|
11291
|
-
{
|
|
11292
|
-
internalType: "bytes",
|
|
11293
|
-
name: "_feeVerificationSignature",
|
|
11294
|
-
type: "bytes"
|
|
11295
|
-
},
|
|
11296
|
-
{
|
|
11297
|
-
internalType: "bytes",
|
|
11298
|
-
name: "_userIntentSignature",
|
|
11299
|
-
type: "bytes"
|
|
11300
|
-
},
|
|
11301
|
-
{
|
|
11302
|
-
internalType: "uint256",
|
|
11303
|
-
name: "_userIntentDeadline",
|
|
11304
|
-
type: "uint256"
|
|
11305
|
-
},
|
|
11306
|
-
{
|
|
11307
|
-
internalType: "uint256",
|
|
11308
|
-
name: "_feeDeadline",
|
|
11309
|
-
type: "uint256"
|
|
11310
|
-
},
|
|
11311
|
-
{
|
|
11312
|
-
internalType: "address",
|
|
11313
|
-
name: "_user",
|
|
11314
|
-
type: "address"
|
|
11315
|
-
},
|
|
11316
|
-
{
|
|
11317
|
-
components: [
|
|
11318
|
-
{
|
|
11319
|
-
internalType: "address",
|
|
11320
|
-
name: "token",
|
|
11321
|
-
type: "address"
|
|
11322
|
-
},
|
|
11323
|
-
{
|
|
11324
|
-
internalType: "uint256",
|
|
11325
|
-
name: "amount",
|
|
11326
|
-
type: "uint256"
|
|
11327
|
-
},
|
|
11328
|
-
{
|
|
11329
|
-
internalType: "bytes",
|
|
11330
|
-
name: "permit",
|
|
11331
|
-
type: "bytes"
|
|
11332
|
-
}
|
|
11333
|
-
],
|
|
11334
|
-
internalType: "struct InputToken[]",
|
|
11335
|
-
name: "_inputTokens",
|
|
11336
|
-
type: "tuple[]"
|
|
11337
|
-
},
|
|
11338
|
-
{
|
|
11339
|
-
components: [
|
|
11340
|
-
{
|
|
11341
|
-
internalType: "address",
|
|
11342
|
-
name: "token",
|
|
11343
|
-
type: "address"
|
|
11344
|
-
},
|
|
11345
|
-
{
|
|
11346
|
-
internalType: "uint256",
|
|
11347
|
-
name: "amount",
|
|
11348
|
-
type: "uint256"
|
|
11349
|
-
}
|
|
11350
|
-
],
|
|
11351
|
-
internalType: "struct TokenInfo[]",
|
|
11352
|
-
name: "_executorFeeInfo",
|
|
11353
|
-
type: "tuple[]"
|
|
11354
|
-
},
|
|
11355
|
-
{
|
|
11356
|
-
components: [
|
|
11357
|
-
{
|
|
11358
|
-
internalType: "address",
|
|
11359
|
-
name: "recipient",
|
|
11360
|
-
type: "address"
|
|
11361
|
-
},
|
|
11362
|
-
{
|
|
11363
|
-
internalType: "address",
|
|
11364
|
-
name: "from",
|
|
11365
|
-
type: "address"
|
|
11366
|
-
},
|
|
11367
|
-
{
|
|
11368
|
-
internalType: "address",
|
|
11369
|
-
name: "to",
|
|
11370
|
-
type: "address"
|
|
11371
|
-
},
|
|
11372
|
-
{
|
|
11373
|
-
internalType: "uint256",
|
|
11374
|
-
name: "fromAmount",
|
|
11375
|
-
type: "uint256"
|
|
11376
|
-
},
|
|
11377
|
-
{
|
|
11378
|
-
internalType: "uint256",
|
|
11379
|
-
name: "minToAmount",
|
|
11380
|
-
type: "uint256"
|
|
11381
|
-
}
|
|
11382
|
-
],
|
|
11383
|
-
internalType: "struct SwapData[]",
|
|
11384
|
-
name: "_swapData",
|
|
11385
|
-
type: "tuple[]"
|
|
11386
|
-
},
|
|
11387
|
-
{
|
|
11388
|
-
components: [
|
|
11389
|
-
{
|
|
11390
|
-
internalType: "string",
|
|
11391
|
-
name: "dex",
|
|
11392
|
-
type: "string"
|
|
11393
|
-
},
|
|
11394
|
-
{
|
|
11395
|
-
internalType: "address",
|
|
11396
|
-
name: "callTo",
|
|
11397
|
-
type: "address"
|
|
11398
|
-
},
|
|
11399
|
-
{
|
|
11400
|
-
internalType: "address",
|
|
11401
|
-
name: "approveTo",
|
|
11402
|
-
type: "address"
|
|
11403
|
-
},
|
|
11404
|
-
{
|
|
11405
|
-
internalType: "bytes",
|
|
11406
|
-
name: "swapCallData",
|
|
11407
|
-
type: "bytes"
|
|
11408
|
-
},
|
|
11409
|
-
{
|
|
11410
|
-
internalType: "bool",
|
|
11411
|
-
name: "isDirectTransfer",
|
|
11412
|
-
type: "bool"
|
|
11413
|
-
}
|
|
11414
|
-
],
|
|
11415
|
-
internalType: "struct SwapExecutionData[]",
|
|
11416
|
-
name: "_swapExecutionData",
|
|
11417
|
-
type: "tuple[]"
|
|
11418
|
-
}
|
|
11419
|
-
],
|
|
11420
|
-
name: "executeMultiSwap",
|
|
11421
|
-
outputs: [],
|
|
11422
|
-
stateMutability: "payable",
|
|
11423
|
-
type: "function"
|
|
11424
|
-
}
|
|
11425
|
-
],
|
|
11426
|
-
GaslessExecuteMultiSwapWithWitnessAbi: [
|
|
11427
|
-
{
|
|
11428
|
-
inputs: [
|
|
11429
|
-
{
|
|
11430
|
-
internalType: "bytes32",
|
|
11431
|
-
name: "_transactionId",
|
|
11432
|
-
type: "bytes32"
|
|
11433
|
-
},
|
|
11434
|
-
{
|
|
11435
|
-
internalType: "bytes",
|
|
11436
|
-
name: "_feeData",
|
|
11437
|
-
type: "bytes"
|
|
11438
|
-
},
|
|
11439
|
-
{
|
|
11440
|
-
internalType: "bytes",
|
|
11441
|
-
name: "_feeVerificationSignature",
|
|
11442
|
-
type: "bytes"
|
|
11443
|
-
},
|
|
11444
|
-
{
|
|
11445
|
-
internalType: "bytes",
|
|
11446
|
-
name: "_userIntentSignature",
|
|
11447
|
-
type: "bytes"
|
|
11448
|
-
},
|
|
11449
|
-
{
|
|
11450
|
-
internalType: "uint256",
|
|
11451
|
-
name: "_feeDeadline",
|
|
11452
|
-
type: "uint256"
|
|
11453
|
-
},
|
|
11454
|
-
{
|
|
11455
|
-
internalType: "address",
|
|
11456
|
-
name: "_user",
|
|
11457
|
-
type: "address"
|
|
11458
|
-
},
|
|
11459
|
-
{
|
|
11460
|
-
components: [
|
|
11461
|
-
{
|
|
11462
|
-
components: [
|
|
11463
|
-
{
|
|
11464
|
-
internalType: "address",
|
|
11465
|
-
name: "token",
|
|
11466
|
-
type: "address"
|
|
11467
|
-
},
|
|
11468
|
-
{
|
|
11469
|
-
internalType: "uint256",
|
|
11470
|
-
name: "amount",
|
|
11471
|
-
type: "uint256"
|
|
11472
|
-
}
|
|
11473
|
-
],
|
|
11474
|
-
internalType: "struct TokenPermissions[]",
|
|
11475
|
-
name: "permitted",
|
|
11476
|
-
type: "tuple[]"
|
|
11477
|
-
},
|
|
11478
|
-
{
|
|
11479
|
-
internalType: "uint256",
|
|
11480
|
-
name: "nonce",
|
|
11481
|
-
type: "uint256"
|
|
11482
|
-
},
|
|
11483
|
-
{
|
|
11484
|
-
internalType: "uint256",
|
|
11485
|
-
name: "deadline",
|
|
11486
|
-
type: "uint256"
|
|
11487
|
-
}
|
|
11488
|
-
],
|
|
11489
|
-
internalType: "struct PermitBatchTransferFrom",
|
|
11490
|
-
name: "_tokenDepositDetails",
|
|
11491
|
-
type: "tuple"
|
|
11492
|
-
},
|
|
11493
|
-
{
|
|
11494
|
-
components: [
|
|
11495
|
-
{
|
|
11496
|
-
internalType: "address",
|
|
11497
|
-
name: "token",
|
|
11498
|
-
type: "address"
|
|
11499
|
-
},
|
|
11500
|
-
{
|
|
11501
|
-
internalType: "uint256",
|
|
11502
|
-
name: "amount",
|
|
11503
|
-
type: "uint256"
|
|
11504
|
-
}
|
|
11505
|
-
],
|
|
11506
|
-
internalType: "struct TokenInfo[]",
|
|
11507
|
-
name: "_executorFeeInfo",
|
|
11508
|
-
type: "tuple[]"
|
|
11509
|
-
},
|
|
11510
|
-
{
|
|
11511
|
-
components: [
|
|
11512
|
-
{
|
|
11513
|
-
internalType: "address",
|
|
11514
|
-
name: "recipient",
|
|
11515
|
-
type: "address"
|
|
11516
|
-
},
|
|
11517
|
-
{
|
|
11518
|
-
internalType: "address",
|
|
11519
|
-
name: "from",
|
|
11520
|
-
type: "address"
|
|
11521
|
-
},
|
|
11522
|
-
{
|
|
11523
|
-
internalType: "address",
|
|
11524
|
-
name: "to",
|
|
11525
|
-
type: "address"
|
|
11526
|
-
},
|
|
11527
|
-
{
|
|
11528
|
-
internalType: "uint256",
|
|
11529
|
-
name: "fromAmount",
|
|
11530
|
-
type: "uint256"
|
|
11531
|
-
},
|
|
11532
|
-
{
|
|
11533
|
-
internalType: "uint256",
|
|
11534
|
-
name: "minToAmount",
|
|
11535
|
-
type: "uint256"
|
|
11536
|
-
}
|
|
11537
|
-
],
|
|
11538
|
-
internalType: "struct SwapData[]",
|
|
11539
|
-
name: "_swapData",
|
|
11540
|
-
type: "tuple[]"
|
|
11541
|
-
},
|
|
11542
|
-
{
|
|
11543
|
-
components: [
|
|
11544
|
-
{
|
|
11545
|
-
internalType: "string",
|
|
11546
|
-
name: "dex",
|
|
11547
|
-
type: "string"
|
|
11548
|
-
},
|
|
11549
|
-
{
|
|
11550
|
-
internalType: "address",
|
|
11551
|
-
name: "callTo",
|
|
11552
|
-
type: "address"
|
|
11553
|
-
},
|
|
11554
|
-
{
|
|
11555
|
-
internalType: "address",
|
|
11556
|
-
name: "approveTo",
|
|
11557
|
-
type: "address"
|
|
11558
|
-
},
|
|
11559
|
-
{
|
|
11560
|
-
internalType: "bytes",
|
|
11561
|
-
name: "swapCallData",
|
|
11562
|
-
type: "bytes"
|
|
11563
|
-
},
|
|
11564
|
-
{
|
|
11565
|
-
internalType: "bool",
|
|
11566
|
-
name: "isDirectTransfer",
|
|
11567
|
-
type: "bool"
|
|
11568
|
-
}
|
|
11569
|
-
],
|
|
11570
|
-
internalType: "struct SwapExecutionData[]",
|
|
11571
|
-
name: "_swapExecutionData",
|
|
11572
|
-
type: "tuple[]"
|
|
11573
|
-
}
|
|
11574
|
-
],
|
|
11575
|
-
name: "executeMultiSwapWithWitness",
|
|
11576
|
-
outputs: [],
|
|
11577
|
-
stateMutability: "payable",
|
|
11578
|
-
type: "function"
|
|
11579
|
-
}
|
|
11580
|
-
],
|
|
11581
|
-
GaslessExecuteSwapAbi: [
|
|
11582
|
-
{
|
|
11583
|
-
inputs: [
|
|
11584
|
-
{
|
|
11585
|
-
internalType: "bytes32",
|
|
11586
|
-
name: "_transactionId",
|
|
11587
|
-
type: "bytes32"
|
|
11588
|
-
},
|
|
11589
|
-
{
|
|
11590
|
-
internalType: "bytes",
|
|
11591
|
-
name: "_feeData",
|
|
11592
|
-
type: "bytes"
|
|
11593
|
-
},
|
|
11594
|
-
{
|
|
11595
|
-
internalType: "bytes",
|
|
11596
|
-
name: "_feeVerificationSignature",
|
|
11597
|
-
type: "bytes"
|
|
11598
|
-
},
|
|
11599
|
-
{
|
|
11600
|
-
internalType: "bytes",
|
|
11601
|
-
name: "_userIntentSignature",
|
|
11602
|
-
type: "bytes"
|
|
11603
|
-
},
|
|
11604
|
-
{
|
|
11605
|
-
internalType: "uint256",
|
|
11606
|
-
name: "_userIntentDeadline",
|
|
11607
|
-
type: "uint256"
|
|
11608
|
-
},
|
|
11609
|
-
{
|
|
11610
|
-
internalType: "uint256",
|
|
11611
|
-
name: "_feeDeadline",
|
|
11612
|
-
type: "uint256"
|
|
11613
|
-
},
|
|
11614
|
-
{
|
|
11615
|
-
internalType: "address",
|
|
11616
|
-
name: "_user",
|
|
11617
|
-
type: "address"
|
|
11618
|
-
},
|
|
11619
|
-
{
|
|
11620
|
-
components: [
|
|
11621
|
-
{
|
|
11622
|
-
internalType: "address",
|
|
11623
|
-
name: "token",
|
|
11624
|
-
type: "address"
|
|
11625
|
-
},
|
|
11626
|
-
{
|
|
11627
|
-
internalType: "uint256",
|
|
11628
|
-
name: "amount",
|
|
11629
|
-
type: "uint256"
|
|
11630
|
-
},
|
|
11631
|
-
{
|
|
11632
|
-
internalType: "bytes",
|
|
11633
|
-
name: "permit",
|
|
11634
|
-
type: "bytes"
|
|
11635
|
-
}
|
|
11636
|
-
],
|
|
11637
|
-
internalType: "struct InputToken",
|
|
11638
|
-
name: "_inputToken",
|
|
11639
|
-
type: "tuple"
|
|
11640
|
-
},
|
|
11641
|
-
{
|
|
11642
|
-
components: [
|
|
11643
|
-
{
|
|
11644
|
-
internalType: "address",
|
|
11645
|
-
name: "token",
|
|
11646
|
-
type: "address"
|
|
11647
|
-
},
|
|
11648
|
-
{
|
|
11649
|
-
internalType: "uint256",
|
|
11650
|
-
name: "amount",
|
|
11651
|
-
type: "uint256"
|
|
11652
|
-
}
|
|
11653
|
-
],
|
|
11654
|
-
internalType: "struct TokenInfo",
|
|
11655
|
-
name: "_executorFeeInfo",
|
|
11656
|
-
type: "tuple"
|
|
11657
|
-
},
|
|
11658
|
-
{
|
|
11659
|
-
components: [
|
|
11660
|
-
{
|
|
11661
|
-
internalType: "address",
|
|
11662
|
-
name: "recipient",
|
|
11663
|
-
type: "address"
|
|
11664
|
-
},
|
|
11665
|
-
{
|
|
11666
|
-
internalType: "address",
|
|
11667
|
-
name: "from",
|
|
11668
|
-
type: "address"
|
|
11669
|
-
},
|
|
11670
|
-
{
|
|
11671
|
-
internalType: "address",
|
|
11672
|
-
name: "to",
|
|
11673
|
-
type: "address"
|
|
11674
|
-
},
|
|
11675
|
-
{
|
|
11676
|
-
internalType: "uint256",
|
|
11677
|
-
name: "fromAmount",
|
|
11678
|
-
type: "uint256"
|
|
11679
|
-
},
|
|
11680
|
-
{
|
|
11681
|
-
internalType: "uint256",
|
|
11682
|
-
name: "minToAmount",
|
|
11683
|
-
type: "uint256"
|
|
11684
|
-
}
|
|
11685
|
-
],
|
|
11686
|
-
internalType: "struct SwapData",
|
|
11687
|
-
name: "_swapData",
|
|
11688
|
-
type: "tuple"
|
|
11689
|
-
},
|
|
11690
|
-
{
|
|
11691
|
-
components: [
|
|
11692
|
-
{
|
|
11693
|
-
internalType: "string",
|
|
11694
|
-
name: "dex",
|
|
11695
|
-
type: "string"
|
|
11696
|
-
},
|
|
11697
|
-
{
|
|
11698
|
-
internalType: "address",
|
|
11699
|
-
name: "callTo",
|
|
11700
|
-
type: "address"
|
|
11701
|
-
},
|
|
11702
|
-
{
|
|
11703
|
-
internalType: "address",
|
|
11704
|
-
name: "approveTo",
|
|
11705
|
-
type: "address"
|
|
11706
|
-
},
|
|
11707
|
-
{
|
|
11708
|
-
internalType: "bytes",
|
|
11709
|
-
name: "swapCallData",
|
|
11710
|
-
type: "bytes"
|
|
11711
|
-
},
|
|
11712
|
-
{
|
|
11713
|
-
internalType: "bool",
|
|
11714
|
-
name: "isDirectTransfer",
|
|
11715
|
-
type: "bool"
|
|
11716
|
-
}
|
|
11717
|
-
],
|
|
11718
|
-
internalType: "struct SwapExecutionData",
|
|
11719
|
-
name: "_swapExecutionData",
|
|
11720
|
-
type: "tuple"
|
|
11721
|
-
}
|
|
11722
|
-
],
|
|
11723
|
-
name: "executeSwap",
|
|
11724
|
-
outputs: [],
|
|
11725
|
-
stateMutability: "payable",
|
|
11726
|
-
type: "function"
|
|
11727
|
-
}
|
|
11728
|
-
]
|
|
11729
|
-
};
|
|
11730
|
-
|
|
11731
|
-
// src/utils/decoder/swap/inputDataDecoder.ts
|
|
11732
|
-
var SwapInputDataDecoder = class {
|
|
11733
|
-
constructor() {
|
|
11734
|
-
this.decodeSingleSwapData = (data) => {
|
|
11735
|
-
var _a;
|
|
11736
|
-
const decodedData = decodeFunctionData({
|
|
11737
|
-
data,
|
|
11738
|
-
abi: SwapAbisByFunctionName.SingleSwap
|
|
11739
|
-
});
|
|
11740
|
-
return [(_a = decodedData == null ? void 0 : decodedData.args) == null ? void 0 : _a[4]];
|
|
11741
|
-
};
|
|
11742
|
-
this.decodeMultiSwapData = (data) => {
|
|
11743
|
-
var _a;
|
|
11744
|
-
const decodedData = decodeFunctionData({
|
|
11745
|
-
data,
|
|
11746
|
-
abi: SwapAbisByFunctionName.MultiSwapAbi
|
|
11747
|
-
});
|
|
11748
|
-
return (_a = decodedData == null ? void 0 : decodedData.args) == null ? void 0 : _a[4];
|
|
11749
|
-
};
|
|
11750
|
-
this.decodeBatchPermitSwapData = (data) => {
|
|
11751
|
-
var _a, _b;
|
|
11752
|
-
const decodedData = decodeFunctionData({
|
|
11753
|
-
data,
|
|
11754
|
-
abi: SwapAbisByFunctionName.BatchPermitSwapAbi
|
|
11755
|
-
});
|
|
11756
|
-
const permitData = (_b = (_a = decodedData == null ? void 0 : decodedData.args) == null ? void 0 : _a[5]) == null ? void 0 : _b.permitted;
|
|
11757
|
-
return permitData;
|
|
11758
|
-
};
|
|
11759
|
-
this.decodeGaslessExecuteMultiSwapData = (data) => {
|
|
11760
|
-
var _a;
|
|
11761
|
-
const decodedData = decodeFunctionData({
|
|
11762
|
-
data,
|
|
11763
|
-
abi: SwapAbisByFunctionName.GaslessExecuteMultiSwapAbi
|
|
11764
|
-
});
|
|
11765
|
-
return (_a = decodedData == null ? void 0 : decodedData.args) == null ? void 0 : _a[7];
|
|
11766
|
-
};
|
|
11767
|
-
this.decodeGaslessExecuteMultiSwapWithWitnessData = (data) => {
|
|
11768
|
-
var _a;
|
|
11769
|
-
const decodedData = decodeFunctionData({
|
|
11770
|
-
data,
|
|
11771
|
-
abi: SwapAbisByFunctionName.GaslessExecuteMultiSwapWithWitnessAbi
|
|
11772
|
-
});
|
|
11773
|
-
return (_a = decodedData == null ? void 0 : decodedData.args) == null ? void 0 : _a[7];
|
|
11774
|
-
};
|
|
11775
|
-
this.decodeGaslessExecuteSwapData = (data) => {
|
|
11776
|
-
var _a;
|
|
11777
|
-
const decodedData = decodeFunctionData({
|
|
11778
|
-
data,
|
|
11779
|
-
abi: SwapAbisByFunctionName.GaslessExecuteSwapAbi
|
|
11780
|
-
});
|
|
11781
|
-
return [(_a = decodedData == null ? void 0 : decodedData.args) == null ? void 0 : _a[7]];
|
|
11782
|
-
};
|
|
11783
|
-
this.swapFunctionSignatureWithInputTokenIndex = {
|
|
11784
|
-
"0x50d52584": {
|
|
11785
|
-
name: "singleSwap",
|
|
11786
|
-
decoder: this.decodeSingleSwapData
|
|
11787
|
-
},
|
|
11788
|
-
"0x8de34776": {
|
|
11789
|
-
name: "multiSwap",
|
|
11790
|
-
decoder: this.decodeMultiSwapData
|
|
11791
|
-
},
|
|
11792
|
-
"0x8d44ea24": {
|
|
11793
|
-
name: "batchPermitSwap",
|
|
11794
|
-
decoder: this.decodeBatchPermitSwapData
|
|
11795
|
-
},
|
|
11796
|
-
"0xd367ada5": {
|
|
11797
|
-
name: "gaslessExecuteMultiSwap",
|
|
11798
|
-
decoder: this.decodeGaslessExecuteMultiSwapData
|
|
11799
|
-
},
|
|
11800
|
-
"0xdcdc6089": {
|
|
11801
|
-
name: "gaslessExecuteMultiSwapWithWitness",
|
|
11802
|
-
decoder: this.decodeGaslessExecuteMultiSwapWithWitnessData
|
|
11803
|
-
},
|
|
11804
|
-
"0x0d2eedd4": {
|
|
11805
|
-
name: "gaslessExecuteSwap",
|
|
11806
|
-
decoder: this.decodeGaslessExecuteSwapData
|
|
11807
|
-
}
|
|
11808
|
-
};
|
|
11809
|
-
this.updateSwapInfo = ({
|
|
11810
|
-
data,
|
|
11811
|
-
eventSwapInfo
|
|
11812
|
-
}) => {
|
|
11813
|
-
var _a;
|
|
11814
|
-
try {
|
|
11815
|
-
if (!data || !eventSwapInfo || data === "0x") {
|
|
11816
|
-
return eventSwapInfo;
|
|
11817
|
-
}
|
|
11818
|
-
const functionSignature = data.slice(0, 10);
|
|
11819
|
-
const decoder = (_a = this.swapFunctionSignatureWithInputTokenIndex[functionSignature]) == null ? void 0 : _a.decoder;
|
|
11820
|
-
if (!decoder) {
|
|
11821
|
-
return eventSwapInfo;
|
|
11822
|
-
}
|
|
11823
|
-
const inputTokenData = decoder(data);
|
|
11824
|
-
if (!inputTokenData || inputTokenData.length === 0) {
|
|
11825
|
-
return eventSwapInfo;
|
|
11826
|
-
}
|
|
11827
|
-
const tokenToAmount = inputTokenData.filter((item) => item.token && item.amount).reduce(
|
|
11828
|
-
(acc, cur) => {
|
|
11829
|
-
acc[formatToken(cur.token)] = cur.amount;
|
|
11830
|
-
return acc;
|
|
11831
|
-
},
|
|
11832
|
-
{}
|
|
11833
|
-
);
|
|
11834
|
-
if (Array.isArray(eventSwapInfo)) {
|
|
11835
|
-
return eventSwapInfo.map((item) => {
|
|
11836
|
-
const formattedSrcToken = formatToken(item.fromToken);
|
|
11837
|
-
const inputAmount = tokenToAmount[formattedSrcToken] || item.fromAmount;
|
|
11838
|
-
return {
|
|
11839
|
-
...item,
|
|
11840
|
-
fromAmount: inputAmount
|
|
11841
|
-
};
|
|
11842
|
-
});
|
|
11843
|
-
} else {
|
|
11844
|
-
const formattedSrcToken = formatToken(eventSwapInfo.fromToken);
|
|
11845
|
-
const inputAmount = tokenToAmount[formattedSrcToken] || eventSwapInfo.fromAmount;
|
|
11846
|
-
return {
|
|
11847
|
-
...eventSwapInfo,
|
|
11848
|
-
fromAmount: inputAmount
|
|
11849
|
-
};
|
|
11850
|
-
}
|
|
11851
|
-
} catch (error) {
|
|
11852
|
-
return eventSwapInfo;
|
|
11853
|
-
}
|
|
11854
|
-
};
|
|
11855
|
-
}
|
|
11856
|
-
};
|
|
11857
|
-
|
|
11858
|
-
// src/utils/index.ts
|
|
11859
|
-
var publicClientRpcConfig = { batch: { wait: RPC_BATCHING_WAIT_TIME }, retryDelay: RPC_RETRY_DELAY };
|
|
11860
|
-
var getPublicClient = ({ rpcUrls, chainId }) => {
|
|
11861
|
-
var _a, _b;
|
|
11862
|
-
const chain = viemChainsById[chainId];
|
|
11863
|
-
const urls = ((rpcUrls == null ? void 0 : rpcUrls.length) ? rpcUrls : (_b = (_a = chain == null ? void 0 : chain.rpcUrls) == null ? void 0 : _a.default) == null ? void 0 : _b.http) ?? [];
|
|
11864
|
-
const transports = urls.length ? urls.map((url) => http(url, publicClientRpcConfig)) : [http()];
|
|
11865
|
-
return createPublicClient({
|
|
11866
|
-
chain,
|
|
11867
|
-
transport: fallback(transports),
|
|
11868
|
-
batch: {
|
|
11869
|
-
multicall: {
|
|
11870
|
-
wait: RPC_BATCHING_WAIT_TIME
|
|
11871
|
-
}
|
|
11872
|
-
}
|
|
11873
|
-
});
|
|
11874
|
-
};
|
|
11875
|
-
function getTokensPairKey({
|
|
11876
|
-
srcToken,
|
|
11877
|
-
destToken,
|
|
11878
|
-
srcChainId,
|
|
11879
|
-
destChainId,
|
|
11880
|
-
srcChainNativeAddress = zeroAddress$1,
|
|
11881
|
-
destChainNativeAddress = zeroAddress$1
|
|
11882
|
-
}) {
|
|
11883
|
-
const srcFormattedAddress = formatToken(srcToken, srcChainNativeAddress);
|
|
11884
|
-
const destFormattedAddress = formatToken(destToken, destChainNativeAddress);
|
|
11885
|
-
return `${srcChainId}_${srcFormattedAddress}-${destChainId}_${destFormattedAddress}`;
|
|
11886
|
-
}
|
|
11887
|
-
var writeContract = async ({
|
|
11888
|
-
chainId,
|
|
11889
|
-
contractAddress,
|
|
11890
|
-
abi: abi7,
|
|
11891
|
-
functionName,
|
|
11892
|
-
args = [],
|
|
11893
|
-
value = "0",
|
|
11894
|
-
rpcUrls = [""],
|
|
11895
|
-
signer
|
|
11896
|
-
}) => {
|
|
11897
|
-
const publicClient = getPublicClient({ chainId, rpcUrls });
|
|
11898
|
-
try {
|
|
11899
|
-
const { request } = await publicClient.simulateContract({
|
|
11900
|
-
address: contractAddress,
|
|
11901
|
-
abi: abi7,
|
|
11902
|
-
functionName,
|
|
11903
|
-
args,
|
|
11904
|
-
account: signer.account,
|
|
11905
|
-
value: BigInt(value)
|
|
11906
|
-
});
|
|
11907
|
-
const hash = await signer.writeContract(request);
|
|
11908
|
-
return { txnHash: hash, status: "success" /* success */, code: 200 /* Success */ };
|
|
11909
|
-
} catch (e) {
|
|
11910
|
-
console.log({ e });
|
|
11911
|
-
if ((e == null ? void 0 : e.code) === 4001 /* UserRejectedRequest */) {
|
|
11912
|
-
return { status: "rejected" /* rejected */, code: e == null ? void 0 : e.code, txnHash: "" };
|
|
11913
|
-
}
|
|
11914
|
-
return { status: "error" /* error */, code: e == null ? void 0 : e.code, txnHash: "" };
|
|
11915
|
-
}
|
|
11916
|
-
};
|
|
11917
|
-
var calcTotalSrcTokenAmount = (data) => {
|
|
11918
|
-
return data.reduce((acc, obj) => {
|
|
11919
|
-
return acc + BigInt(obj.amount);
|
|
11920
|
-
}, BigInt(0));
|
|
11921
|
-
};
|
|
11922
|
-
var isOneToMany = (firstTokenAddress, secondTokenAddress) => firstTokenAddress === secondTokenAddress;
|
|
11923
|
-
BigInt(15) / BigInt(10);
|
|
11924
|
-
var isTypeSigner = (variable) => {
|
|
11925
|
-
return variable instanceof Signer;
|
|
11926
|
-
};
|
|
11927
|
-
var isDZapNativeToken = (srcToken) => srcToken === dZapNativeTokenFormat;
|
|
11928
|
-
var getDZapAbi = (service, version) => {
|
|
11929
|
-
switch (service) {
|
|
11930
|
-
case Services.trade:
|
|
11931
|
-
switch (version) {
|
|
11932
|
-
case "v1" /* v1 */:
|
|
11933
|
-
return artifacts_exports[DZapAbis.dZapCoreAbi];
|
|
11934
|
-
case "v2" /* v2 */:
|
|
11935
|
-
return artifacts_exports[DZapAbis.dZapCoreV2Abi];
|
|
11936
|
-
default:
|
|
11937
|
-
throw new Error("Invalid Version for Trade");
|
|
11938
|
-
}
|
|
11939
|
-
case Services.dca:
|
|
11940
|
-
return artifacts_exports[DZapAbis.dZapDcaAbi];
|
|
11941
|
-
case Services.zap:
|
|
11942
|
-
default:
|
|
11943
|
-
throw new Error("Invalid Service");
|
|
11944
|
-
}
|
|
11945
|
-
};
|
|
11946
|
-
var handleDecodeTxnData = (transaction, receipt, service, chain) => {
|
|
11947
|
-
var _a, _b, _c, _d, _e;
|
|
11948
|
-
let events = [];
|
|
11949
|
-
const dZapAbi = getDZapAbi(service, (chain == null ? void 0 : chain.version) || "v1" /* v1 */);
|
|
11950
|
-
try {
|
|
11951
|
-
events = parseEventLogs({
|
|
11952
|
-
abi: dZapAbi,
|
|
11953
|
-
logs: receipt.logs
|
|
11954
|
-
});
|
|
11955
|
-
} catch (e) {
|
|
11956
|
-
events = [];
|
|
11957
|
-
}
|
|
11958
|
-
events = events == null ? void 0 : events.filter((item) => item !== null);
|
|
11959
|
-
const txLogArgs = (_a = events[0]) == null ? void 0 : _a.args;
|
|
11960
|
-
const swapFailPairs = [];
|
|
11961
|
-
let swapInfo = [];
|
|
11962
|
-
if (Array.isArray(txLogArgs == null ? void 0 : txLogArgs.swapInfo)) {
|
|
11963
|
-
swapInfo = txLogArgs.swapInfo.map((info) => {
|
|
11964
|
-
var _a2, _b2, _c2, _d2;
|
|
11965
|
-
if (BigInt(info.returnToAmount) === BigInt(0) || BigInt(info.fromAmount) === BigInt(0)) {
|
|
11966
|
-
swapFailPairs.push(
|
|
11967
|
-
getTokensPairKey({
|
|
11968
|
-
srcToken: info.fromToken,
|
|
11969
|
-
destToken: info.toToken,
|
|
11970
|
-
srcChainId: chain.chainId,
|
|
11971
|
-
destChainId: chain.chainId,
|
|
11972
|
-
srcChainNativeAddress: (_a2 = chain == null ? void 0 : chain.nativeToken) == null ? void 0 : _a2.contract,
|
|
11973
|
-
destChainNativeAddress: (_b2 = chain == null ? void 0 : chain.nativeToken) == null ? void 0 : _b2.contract
|
|
11974
|
-
})
|
|
11975
|
-
);
|
|
11976
|
-
}
|
|
11977
|
-
return {
|
|
11978
|
-
...info,
|
|
11979
|
-
fromToken: formatToken(info.fromToken, (_c2 = chain == null ? void 0 : chain.nativeToken) == null ? void 0 : _c2.contract),
|
|
11980
|
-
toToken: formatToken(info.toToken, (_d2 = chain == null ? void 0 : chain.nativeToken) == null ? void 0 : _d2.contract)
|
|
11981
|
-
};
|
|
11982
|
-
});
|
|
11983
|
-
} else if (typeof (txLogArgs == null ? void 0 : txLogArgs.swapInfo) === "object" && Object.keys(txLogArgs == null ? void 0 : txLogArgs.swapInfo).length > 0) {
|
|
11984
|
-
const { fromAmount, returnToAmount, fromToken, toToken } = txLogArgs.swapInfo;
|
|
11985
|
-
if (BigInt(returnToAmount) === BigInt(0) || BigInt(fromAmount) === BigInt(0)) {
|
|
11986
|
-
swapFailPairs.push(
|
|
11987
|
-
getTokensPairKey({
|
|
11988
|
-
srcToken: fromToken,
|
|
11989
|
-
destToken: toToken,
|
|
11990
|
-
srcChainId: chain.chainId,
|
|
11991
|
-
destChainId: chain.chainId,
|
|
11992
|
-
srcChainNativeAddress: (_b = chain == null ? void 0 : chain.nativeToken) == null ? void 0 : _b.contract,
|
|
11993
|
-
destChainNativeAddress: (_c = chain == null ? void 0 : chain.nativeToken) == null ? void 0 : _c.contract
|
|
11994
|
-
})
|
|
11995
|
-
);
|
|
11996
|
-
}
|
|
11997
|
-
swapInfo = {
|
|
11998
|
-
...txLogArgs.swapInfo,
|
|
11999
|
-
fromToken: formatToken(txLogArgs.swapInfo.fromToken, (_d = chain == null ? void 0 : chain.nativeToken) == null ? void 0 : _d.contract),
|
|
12000
|
-
toToken: formatToken(txLogArgs.swapInfo.toToken, (_e = chain == null ? void 0 : chain.nativeToken) == null ? void 0 : _e.contract)
|
|
12001
|
-
};
|
|
12002
|
-
}
|
|
12003
|
-
const updatedSwapInfo = new SwapInputDataDecoder().updateSwapInfo({
|
|
12004
|
-
data: transaction.input,
|
|
12005
|
-
eventSwapInfo: swapInfo
|
|
12006
|
-
}) || swapInfo;
|
|
12007
|
-
return { swapInfo: updatedSwapInfo, swapFailPairs };
|
|
12008
|
-
};
|
|
12009
|
-
var getOtherAbis = (name) => {
|
|
12010
|
-
switch (name) {
|
|
12011
|
-
case OtherAbis.permit2:
|
|
12012
|
-
return abi4;
|
|
12013
|
-
case OtherAbis.erc20:
|
|
12014
|
-
return abi5;
|
|
12015
|
-
default:
|
|
12016
|
-
throw new Error("Invalid Abi");
|
|
12017
|
-
}
|
|
12018
|
-
};
|
|
12019
|
-
var BRIDGE_ERRORS = {
|
|
12020
|
-
BridgeCallFailed: "BridgeCallFailed"
|
|
12021
|
-
};
|
|
12022
|
-
function getErrorName(errorString) {
|
|
12023
|
-
const match = errorString.match(/Error: (\w+)/);
|
|
12024
|
-
return match ? match[1] : null;
|
|
12025
|
-
}
|
|
12026
|
-
var getRevertMsg = (res) => {
|
|
12027
|
-
if (res.length < 68) {
|
|
12028
|
-
return res;
|
|
12029
|
-
}
|
|
12030
|
-
const revertData = "0x" + res.slice(10);
|
|
12031
|
-
const msg = decodeAbiParameters(parseAbiParameters("string"), revertData)[0];
|
|
12032
|
-
return msg;
|
|
12033
|
-
};
|
|
12034
|
-
var isAxiosError = (error) => {
|
|
12035
|
-
return Boolean(error) && error.isAxiosError;
|
|
12036
|
-
};
|
|
12037
|
-
var handleViemTransactionError = ({ error }) => {
|
|
12038
|
-
var _a, _b;
|
|
12039
|
-
if ((error == null ? void 0 : error.code) === 429 /* WalletRPCFailure */ || ((_a = error == null ? void 0 : error.cause) == null ? void 0 : _a.code) === 429 /* WalletRPCFailure */) {
|
|
12040
|
-
return {
|
|
12041
|
-
error,
|
|
12042
|
-
errorMsg: "Too many requests, failure on user wallet",
|
|
12043
|
-
code: 429 /* WalletRPCFailure */,
|
|
12044
|
-
status: "error" /* error */
|
|
12045
|
-
};
|
|
12046
|
-
}
|
|
12047
|
-
if ((error == null ? void 0 : error.code) === 4001 /* UserRejectedRequest */ || ((_b = error == null ? void 0 : error.cause) == null ? void 0 : _b.code) === 4001 /* UserRejectedRequest */) {
|
|
12048
|
-
return {
|
|
12049
|
-
error,
|
|
12050
|
-
errorMsg: "Rejected by User",
|
|
12051
|
-
code: 4001 /* UserRejectedRequest */,
|
|
12052
|
-
status: "rejected" /* rejected */
|
|
12053
|
-
};
|
|
12054
|
-
}
|
|
12055
|
-
let errMsg = error.shortMessage;
|
|
12056
|
-
const errName = getErrorName(error.metaMessages[0]);
|
|
12057
|
-
if (errName == BRIDGE_ERRORS.BridgeCallFailed) {
|
|
12058
|
-
let msg = error.metaMessages[1];
|
|
12059
|
-
try {
|
|
12060
|
-
msg = getRevertMsg(error.metaMessages[1].match(/\((.*?)\)/)[1]);
|
|
12061
|
-
} catch (err) {
|
|
12062
|
-
}
|
|
12063
|
-
errMsg = `${BRIDGE_ERRORS.BridgeCallFailed} : ${msg}`;
|
|
12064
|
-
} else if (errName) {
|
|
12065
|
-
errMsg = errName;
|
|
12066
|
-
}
|
|
12067
|
-
return {
|
|
12068
|
-
status: "error" /* error */,
|
|
12069
|
-
error,
|
|
12070
|
-
errorMsg: errMsg,
|
|
12071
|
-
code: -500 /* ContractExecutionError */
|
|
12072
|
-
};
|
|
12073
|
-
};
|
|
12074
|
-
|
|
12075
|
-
// src/transactionHandlers/generic.ts
|
|
12076
|
-
var GenericTxnHandler = class {
|
|
12077
|
-
};
|
|
12078
|
-
GenericTxnHandler.sendTransaction = async ({
|
|
12079
|
-
chainId,
|
|
12080
|
-
signer,
|
|
12081
|
-
from,
|
|
12082
|
-
to,
|
|
12083
|
-
data,
|
|
12084
|
-
value
|
|
12085
|
-
}) => {
|
|
12086
|
-
try {
|
|
12087
|
-
if (isTypeSigner(signer)) {
|
|
12088
|
-
console.log("Using ethers signer.");
|
|
12089
|
-
const txnRes = await signer.sendTransaction({
|
|
12090
|
-
from,
|
|
12091
|
-
to,
|
|
12092
|
-
data,
|
|
12093
|
-
value
|
|
12094
|
-
});
|
|
12095
|
-
return {
|
|
12096
|
-
status: "success" /* success */,
|
|
12097
|
-
code: 200 /* Success */,
|
|
12098
|
-
txnHash: txnRes.hash
|
|
12099
|
-
};
|
|
12100
|
-
} else {
|
|
12101
|
-
console.log("Using viem walletClient.");
|
|
12102
|
-
const txnHash = await signer.sendTransaction({
|
|
12103
|
-
chain: viemChainsById[chainId],
|
|
12104
|
-
account: from,
|
|
12105
|
-
to,
|
|
12106
|
-
data,
|
|
12107
|
-
value: BigInt(value)
|
|
12108
|
-
});
|
|
12109
|
-
return {
|
|
12110
|
-
status: "success" /* success */,
|
|
12111
|
-
code: 200 /* Success */,
|
|
12112
|
-
txnHash
|
|
12113
|
-
};
|
|
12114
|
-
}
|
|
12115
|
-
} catch (error) {
|
|
12116
|
-
console.log({ error });
|
|
12117
|
-
return handleViemTransactionError({ error });
|
|
12118
|
-
}
|
|
12119
|
-
};
|
|
12120
|
-
var generic_default = GenericTxnHandler;
|
|
12121
|
-
|
|
12122
|
-
// src/types/eip-2612.ts
|
|
12123
|
-
var EIP2612DefaultTypes = {
|
|
12124
|
-
Permit: [
|
|
12125
|
-
{
|
|
12126
|
-
name: "owner",
|
|
12127
|
-
type: "address"
|
|
12128
|
-
},
|
|
12129
|
-
{
|
|
12130
|
-
name: "spender",
|
|
12131
|
-
type: "address"
|
|
12132
|
-
},
|
|
11111
|
+
name: "spender",
|
|
11112
|
+
type: "address"
|
|
11113
|
+
},
|
|
12133
11114
|
{
|
|
12134
11115
|
name: "value",
|
|
12135
11116
|
type: "uint256"
|
|
@@ -14369,897 +13350,2030 @@ var _PermitTxnHandler = class _PermitTxnHandler {
|
|
|
14369
13350
|
permitType: PermitTypes.PermitBatchWitnessTransferFrom
|
|
14370
13351
|
//override because only PermitBatchWitnessTransferFrom supports batch
|
|
14371
13352
|
});
|
|
14372
|
-
if (resp.status !== "success" /* success */) {
|
|
14373
|
-
return { status: resp.status, code: resp.code, permitType: PermitTypes.PermitBatchWitnessTransferFrom };
|
|
14374
|
-
}
|
|
14375
|
-
if (signPermitReq.signatureCallback) {
|
|
14376
|
-
await signPermitReq.signatureCallback({
|
|
14377
|
-
batchPermitData: resp.permitData,
|
|
14378
|
-
tokens,
|
|
14379
|
-
permitType: resp.permitType
|
|
14380
|
-
});
|
|
14381
|
-
}
|
|
13353
|
+
if (resp.status !== "success" /* success */) {
|
|
13354
|
+
return { status: resp.status, code: resp.code, permitType: PermitTypes.PermitBatchWitnessTransferFrom };
|
|
13355
|
+
}
|
|
13356
|
+
if (signPermitReq.signatureCallback) {
|
|
13357
|
+
await signPermitReq.signatureCallback({
|
|
13358
|
+
batchPermitData: resp.permitData,
|
|
13359
|
+
tokens,
|
|
13360
|
+
permitType: resp.permitType
|
|
13361
|
+
});
|
|
13362
|
+
}
|
|
13363
|
+
return {
|
|
13364
|
+
status: "success" /* success */,
|
|
13365
|
+
code: 200 /* Success */,
|
|
13366
|
+
batchPermitData: resp.permitData,
|
|
13367
|
+
permitType: resp.permitType
|
|
13368
|
+
};
|
|
13369
|
+
} else {
|
|
13370
|
+
if (signPermitReq.permitType === PermitTypes.PermitBatchWitnessTransferFrom) {
|
|
13371
|
+
return { status: "error" /* error */, code: 500 /* Error */, permitType: PermitTypes.PermitBatchWitnessTransferFrom };
|
|
13372
|
+
}
|
|
13373
|
+
const totalSrcAmount = calcTotalSrcTokenAmount(tokens);
|
|
13374
|
+
let firstTokenNonce = null;
|
|
13375
|
+
let permitType = _PermitTxnHandler.v1PermitSupport({
|
|
13376
|
+
contractVersion: signPermitReq.contractVersion,
|
|
13377
|
+
service: signPermitReq.service
|
|
13378
|
+
}) ? PermitTypes.PermitSingle : signPermitReq.permitType;
|
|
13379
|
+
for (let dataIdx = 0; dataIdx < tokens.length; dataIdx++) {
|
|
13380
|
+
const isFirstToken = dataIdx === 0;
|
|
13381
|
+
const res = await _PermitTxnHandler.generatePermitDataForToken({
|
|
13382
|
+
...signPermitReq,
|
|
13383
|
+
token: {
|
|
13384
|
+
...tokens[dataIdx],
|
|
13385
|
+
index: dataIdx
|
|
13386
|
+
},
|
|
13387
|
+
firstTokenNonce: firstTokenNonce ?? void 0,
|
|
13388
|
+
oneToMany,
|
|
13389
|
+
totalSrcAmount,
|
|
13390
|
+
account: signPermitReq.sender,
|
|
13391
|
+
permitType
|
|
13392
|
+
});
|
|
13393
|
+
permitType = res.permitType;
|
|
13394
|
+
if (res.status !== "success" /* success */) {
|
|
13395
|
+
return { status: res.status, code: res.code, permitType: res.permitType };
|
|
13396
|
+
}
|
|
13397
|
+
tokens[dataIdx].permitData = res.permitData;
|
|
13398
|
+
if (isFirstToken && !isDZapNativeToken(tokens[dataIdx].address)) {
|
|
13399
|
+
firstTokenNonce = res.nonce ?? null;
|
|
13400
|
+
}
|
|
13401
|
+
if (signPermitReq.signatureCallback && !isDZapNativeToken(tokens[dataIdx].address)) {
|
|
13402
|
+
const amount = oneToMany && isFirstToken ? totalSrcAmount : BigInt(tokens[dataIdx].amount);
|
|
13403
|
+
await signPermitReq.signatureCallback({
|
|
13404
|
+
permitData: res.permitData,
|
|
13405
|
+
srcToken: tokens[dataIdx].address,
|
|
13406
|
+
amount: amount.toString(),
|
|
13407
|
+
permitType: res.permitType
|
|
13408
|
+
});
|
|
13409
|
+
}
|
|
13410
|
+
}
|
|
13411
|
+
return { status: "success" /* success */, tokens, code: 200 /* Success */, permitType };
|
|
13412
|
+
}
|
|
13413
|
+
}
|
|
13414
|
+
};
|
|
13415
|
+
_PermitTxnHandler.generateBatchPermitDataForTokens = async (params) => {
|
|
13416
|
+
const resp = await getPermit2Signature(params);
|
|
13417
|
+
return {
|
|
13418
|
+
...resp,
|
|
13419
|
+
permitType: PermitTypes.PermitBatchWitnessTransferFrom
|
|
13420
|
+
};
|
|
13421
|
+
};
|
|
13422
|
+
_PermitTxnHandler.generatePermitDataForToken = async (params) => {
|
|
13423
|
+
const { token, oneToMany, totalSrcAmount, chainId, rpcUrls, permitType, account } = params;
|
|
13424
|
+
const isFirstToken = token.index === 0;
|
|
13425
|
+
if (isDZapNativeToken(token.address)) {
|
|
13426
|
+
return {
|
|
13427
|
+
status: "success" /* success */,
|
|
13428
|
+
code: 200 /* Success */,
|
|
13429
|
+
permitData: DEFAULT_PERMIT_DATA,
|
|
13430
|
+
nonce: BigInt(0),
|
|
13431
|
+
// For native tokens, nonce is not used
|
|
13432
|
+
permitType: PermitTypes.EIP2612Permit
|
|
13433
|
+
};
|
|
13434
|
+
}
|
|
13435
|
+
const amount = oneToMany && isFirstToken ? totalSrcAmount : BigInt(token.amount);
|
|
13436
|
+
const eip2612PermitData = await checkEIP2612PermitSupport({
|
|
13437
|
+
address: token.address,
|
|
13438
|
+
chainId,
|
|
13439
|
+
rpcUrls,
|
|
13440
|
+
owner: account,
|
|
13441
|
+
permit: token.permit
|
|
13442
|
+
});
|
|
13443
|
+
if (permitType === PermitTypes.EIP2612Permit || permitType === PermitTypes.AutoPermit && eip2612PermitData.supportsPermit) {
|
|
13444
|
+
if (!eip2612PermitData.supportsPermit || !eip2612PermitData.data) {
|
|
13445
|
+
throw new Error("Token does not support EIP-2612 permits");
|
|
13446
|
+
}
|
|
13447
|
+
if (oneToMany && !isFirstToken) {
|
|
13448
|
+
return {
|
|
13449
|
+
status: "success" /* success */,
|
|
13450
|
+
code: 200 /* Success */,
|
|
13451
|
+
permitData: DEFAULT_PERMIT_DATA,
|
|
13452
|
+
nonce: BigInt(0),
|
|
13453
|
+
// For EIP2612 permits, nonce is not used it's already set in permitData
|
|
13454
|
+
permitType: PermitTypes.EIP2612Permit
|
|
13455
|
+
};
|
|
13456
|
+
}
|
|
13457
|
+
const { permitData, status, code } = await getEIP2612PermitSignature({
|
|
13458
|
+
...params,
|
|
13459
|
+
token: {
|
|
13460
|
+
address: token.address,
|
|
13461
|
+
amount: amount.toString(),
|
|
13462
|
+
index: 0,
|
|
13463
|
+
permit: token.permit
|
|
13464
|
+
},
|
|
13465
|
+
gasless: false,
|
|
13466
|
+
version: eip2612PermitData.data.version,
|
|
13467
|
+
name: eip2612PermitData.data.name,
|
|
13468
|
+
nonce: eip2612PermitData.data.nonce
|
|
13469
|
+
});
|
|
13470
|
+
return {
|
|
13471
|
+
status,
|
|
13472
|
+
code,
|
|
13473
|
+
permitData,
|
|
13474
|
+
nonce: BigInt(0),
|
|
13475
|
+
// For EIP2612 permits, nonce is not used
|
|
13476
|
+
permitType: PermitTypes.EIP2612Permit
|
|
13477
|
+
};
|
|
13478
|
+
} else {
|
|
13479
|
+
const normalizedPermitType = permitType === PermitTypes.AutoPermit ? PermitTypes.PermitWitnessTransferFrom : permitType;
|
|
13480
|
+
if (oneToMany && !isFirstToken) {
|
|
13481
|
+
return {
|
|
13482
|
+
status: "success" /* success */,
|
|
13483
|
+
code: 200 /* Success */,
|
|
13484
|
+
permitData: DEFAULT_PERMIT2_DATA,
|
|
13485
|
+
nonce: BigInt(0),
|
|
13486
|
+
// For one-to-many non-first tokens, nonce is not used
|
|
13487
|
+
permitType: normalizedPermitType
|
|
13488
|
+
};
|
|
13489
|
+
} else {
|
|
13490
|
+
const resp = await getPermit2Signature({
|
|
13491
|
+
...params,
|
|
13492
|
+
tokens: [token],
|
|
13493
|
+
permitType: normalizedPermitType
|
|
13494
|
+
});
|
|
13495
|
+
return {
|
|
13496
|
+
...resp,
|
|
13497
|
+
permitType: normalizedPermitType
|
|
13498
|
+
};
|
|
13499
|
+
}
|
|
13500
|
+
}
|
|
13501
|
+
};
|
|
13502
|
+
_PermitTxnHandler.signGaslessUserIntent = async (signPermitReq) => {
|
|
13503
|
+
const { tokens, sender, permitType } = signPermitReq;
|
|
13504
|
+
const type = permitType === PermitTypes.AutoPermit ? PermitTypes.PermitBatchWitnessTransferFrom : permitType;
|
|
13505
|
+
if (type === PermitTypes.EIP2612Permit) {
|
|
13506
|
+
const resp2 = await signGaslessDzapUserIntent({
|
|
13507
|
+
...signPermitReq,
|
|
13508
|
+
account: sender
|
|
13509
|
+
});
|
|
13510
|
+
return {
|
|
13511
|
+
status: resp2.status,
|
|
13512
|
+
code: resp2.code,
|
|
13513
|
+
data: (resp2 == null ? void 0 : resp2.data) && {
|
|
13514
|
+
...resp2.data,
|
|
13515
|
+
type
|
|
13516
|
+
}
|
|
13517
|
+
};
|
|
13518
|
+
}
|
|
13519
|
+
const resp = await getPermit2Signature({
|
|
13520
|
+
...signPermitReq,
|
|
13521
|
+
tokens: tokens.map((token, index) => ({ ...token, index })),
|
|
13522
|
+
account: sender,
|
|
13523
|
+
permitType: type
|
|
13524
|
+
});
|
|
13525
|
+
return {
|
|
13526
|
+
status: resp.status,
|
|
13527
|
+
code: resp.code,
|
|
13528
|
+
data: resp.permitData && {
|
|
13529
|
+
type,
|
|
13530
|
+
batchPermitData: resp.permitData
|
|
13531
|
+
}
|
|
13532
|
+
};
|
|
13533
|
+
};
|
|
13534
|
+
_PermitTxnHandler.v1PermitSupport = ({ contractVersion, service }) => {
|
|
13535
|
+
return contractVersion === "v1" /* v1 */ && service !== Services.zap;
|
|
13536
|
+
};
|
|
13537
|
+
_PermitTxnHandler.shouldUseBatchPermit = ({
|
|
13538
|
+
permitType,
|
|
13539
|
+
isBatchPermitAllowed = true,
|
|
13540
|
+
tokens,
|
|
13541
|
+
oneToMany,
|
|
13542
|
+
contractVersion,
|
|
13543
|
+
service
|
|
13544
|
+
}) => {
|
|
13545
|
+
const isBatchPermitRequested = permitType === PermitTypes.PermitBatchWitnessTransferFrom;
|
|
13546
|
+
const shouldAutoBatch = permitType === PermitTypes.AutoPermit && (tokens == null ? void 0 : tokens.length) > 1 && !oneToMany;
|
|
13547
|
+
const isContractSupport = !_PermitTxnHandler.v1PermitSupport({ contractVersion, service });
|
|
13548
|
+
return isBatchPermitAllowed && (isBatchPermitRequested || shouldAutoBatch) && isContractSupport;
|
|
13549
|
+
};
|
|
13550
|
+
var PermitTxnHandler = _PermitTxnHandler;
|
|
13551
|
+
var permit_default = PermitTxnHandler;
|
|
13552
|
+
function encodeApproveCallData({ spender, amount }) {
|
|
13553
|
+
return encodeFunctionData({
|
|
13554
|
+
abi: abi5,
|
|
13555
|
+
functionName: erc20Functions.approve,
|
|
13556
|
+
args: [spender, amount]
|
|
13557
|
+
});
|
|
13558
|
+
}
|
|
13559
|
+
var approveToken = async ({
|
|
13560
|
+
chainId,
|
|
13561
|
+
signer,
|
|
13562
|
+
rpcUrls,
|
|
13563
|
+
mode,
|
|
13564
|
+
tokens,
|
|
13565
|
+
approvalTxnCallback,
|
|
13566
|
+
spender
|
|
13567
|
+
}) => {
|
|
13568
|
+
if (mode !== ApprovalModes.Default) {
|
|
13569
|
+
spender = getPermit2Address(chainId);
|
|
13570
|
+
}
|
|
13571
|
+
for (let dataIdx = 0; dataIdx < tokens.length; dataIdx++) {
|
|
13572
|
+
let txnDetails = { status: "success" /* success */, code: 200 /* Success */, txnHash: "" };
|
|
13573
|
+
if (isTypeSigner(signer)) {
|
|
13574
|
+
const from = await signer.getAddress();
|
|
13575
|
+
const callData = encodeFunctionData({
|
|
13576
|
+
abi: abi5,
|
|
13577
|
+
functionName: erc20Functions.approve,
|
|
13578
|
+
args: [spender, BigInt(tokens[dataIdx].amount)]
|
|
13579
|
+
});
|
|
13580
|
+
await signer.sendTransaction({
|
|
13581
|
+
from,
|
|
13582
|
+
chainId,
|
|
13583
|
+
to: tokens[dataIdx].address,
|
|
13584
|
+
data: callData
|
|
13585
|
+
});
|
|
14382
13586
|
return {
|
|
14383
13587
|
status: "success" /* success */,
|
|
14384
|
-
code: 200 /* Success
|
|
14385
|
-
batchPermitData: resp.permitData,
|
|
14386
|
-
permitType: resp.permitType
|
|
13588
|
+
code: 200 /* Success */
|
|
14387
13589
|
};
|
|
14388
13590
|
} else {
|
|
14389
|
-
|
|
14390
|
-
|
|
13591
|
+
txnDetails = await writeContract({
|
|
13592
|
+
chainId,
|
|
13593
|
+
contractAddress: tokens[dataIdx].address,
|
|
13594
|
+
abi: abi5,
|
|
13595
|
+
functionName: erc20Functions.approve,
|
|
13596
|
+
args: [spender, tokens[dataIdx].amount],
|
|
13597
|
+
rpcUrls,
|
|
13598
|
+
signer
|
|
13599
|
+
});
|
|
13600
|
+
}
|
|
13601
|
+
if (txnDetails.code !== 200 /* Success */) {
|
|
13602
|
+
return {
|
|
13603
|
+
status: txnDetails.status,
|
|
13604
|
+
code: (txnDetails == null ? void 0 : txnDetails.code) || 32771 /* FunctionNotFound */
|
|
13605
|
+
};
|
|
13606
|
+
}
|
|
13607
|
+
if (approvalTxnCallback) {
|
|
13608
|
+
const callbackStatus = await approvalTxnCallback({ txnDetails, address: tokens[dataIdx].address });
|
|
13609
|
+
if (callbackStatus && callbackStatus !== "success" /* success */) {
|
|
13610
|
+
return {
|
|
13611
|
+
status: txnDetails.status,
|
|
13612
|
+
code: (txnDetails == null ? void 0 : txnDetails.code) || 500 /* Error */
|
|
13613
|
+
};
|
|
14391
13614
|
}
|
|
14392
|
-
|
|
14393
|
-
|
|
14394
|
-
|
|
14395
|
-
|
|
14396
|
-
|
|
14397
|
-
|
|
14398
|
-
|
|
14399
|
-
|
|
14400
|
-
|
|
14401
|
-
|
|
14402
|
-
|
|
14403
|
-
|
|
14404
|
-
|
|
14405
|
-
|
|
14406
|
-
|
|
14407
|
-
|
|
14408
|
-
|
|
14409
|
-
|
|
14410
|
-
|
|
13615
|
+
}
|
|
13616
|
+
}
|
|
13617
|
+
return { status: "success" /* success */, code: 200 /* Success */ };
|
|
13618
|
+
};
|
|
13619
|
+
var batchGetAllowances = async ({
|
|
13620
|
+
chainId,
|
|
13621
|
+
data,
|
|
13622
|
+
owner,
|
|
13623
|
+
multicallAddress,
|
|
13624
|
+
rpcUrls
|
|
13625
|
+
}) => {
|
|
13626
|
+
const contracts = data.map(({ token, spender }) => ({
|
|
13627
|
+
address: token,
|
|
13628
|
+
abi: abi5,
|
|
13629
|
+
functionName: erc20Functions.allowance,
|
|
13630
|
+
args: [owner, spender]
|
|
13631
|
+
}));
|
|
13632
|
+
const {
|
|
13633
|
+
status,
|
|
13634
|
+
code,
|
|
13635
|
+
data: allowances
|
|
13636
|
+
} = await multicall({
|
|
13637
|
+
chainId,
|
|
13638
|
+
contracts,
|
|
13639
|
+
rpcUrls,
|
|
13640
|
+
multicallAddress,
|
|
13641
|
+
allowFailure: false
|
|
13642
|
+
});
|
|
13643
|
+
if (status !== "success" /* success */) {
|
|
13644
|
+
return { status, code, data: {} };
|
|
13645
|
+
}
|
|
13646
|
+
const tokenAllowances = {};
|
|
13647
|
+
for (let i = 0; i < data.length; i++) {
|
|
13648
|
+
tokenAllowances[data[i].token] = allowances[i];
|
|
13649
|
+
}
|
|
13650
|
+
return { status, code, data: tokenAllowances };
|
|
13651
|
+
};
|
|
13652
|
+
var getAllowance = async ({ chainId, sender, tokens, rpcUrls, multicallAddress, mode, spender }) => {
|
|
13653
|
+
const data = {};
|
|
13654
|
+
const nativeTokens2 = tokens.filter(({ address }) => isDZapNativeToken(address));
|
|
13655
|
+
const erc20Tokens = tokens.filter(({ address }) => !isDZapNativeToken(address));
|
|
13656
|
+
const approvalData = await Promise.all(
|
|
13657
|
+
erc20Tokens.map(async ({ address, permit }) => {
|
|
13658
|
+
if (mode === ApprovalModes.AutoPermit) {
|
|
13659
|
+
const eip2612PermitData = await checkEIP2612PermitSupport({
|
|
13660
|
+
address,
|
|
13661
|
+
chainId,
|
|
13662
|
+
rpcUrls,
|
|
13663
|
+
owner: sender,
|
|
13664
|
+
permit
|
|
14411
13665
|
});
|
|
14412
|
-
|
|
14413
|
-
|
|
14414
|
-
|
|
14415
|
-
|
|
14416
|
-
|
|
14417
|
-
|
|
14418
|
-
|
|
14419
|
-
|
|
14420
|
-
|
|
14421
|
-
|
|
14422
|
-
|
|
14423
|
-
|
|
14424
|
-
|
|
14425
|
-
|
|
14426
|
-
|
|
14427
|
-
});
|
|
14428
|
-
}
|
|
13666
|
+
const allowanceType = eip2612PermitData.supportsPermit ? AllowanceTypes.eip2612 : AllowanceTypes.permit2;
|
|
13667
|
+
return {
|
|
13668
|
+
token: address,
|
|
13669
|
+
spender: eip2612PermitData.supportsPermit ? spender : getPermit2Address(chainId),
|
|
13670
|
+
allowanceType
|
|
13671
|
+
};
|
|
13672
|
+
} else if (mode === ApprovalModes.Default) {
|
|
13673
|
+
return {
|
|
13674
|
+
token: address,
|
|
13675
|
+
spender,
|
|
13676
|
+
allowanceType: AllowanceTypes.dzap
|
|
13677
|
+
};
|
|
13678
|
+
} else {
|
|
13679
|
+
const permit2Address = getPermit2Address(chainId);
|
|
13680
|
+
return { token: address, spender: permit2Address, allowanceType: AllowanceTypes.permit2 };
|
|
14429
13681
|
}
|
|
14430
|
-
|
|
13682
|
+
})
|
|
13683
|
+
);
|
|
13684
|
+
for (const { address } of nativeTokens2) {
|
|
13685
|
+
data[address] = { allowance: maxUint256, type: AllowanceTypes.dzap };
|
|
13686
|
+
}
|
|
13687
|
+
if (erc20Tokens.length === 0) {
|
|
13688
|
+
return { status: "success" /* success */, code: 200 /* Success */, data };
|
|
13689
|
+
}
|
|
13690
|
+
try {
|
|
13691
|
+
const { data: allowances } = await batchGetAllowances({
|
|
13692
|
+
chainId,
|
|
13693
|
+
data: approvalData,
|
|
13694
|
+
owner: sender,
|
|
13695
|
+
multicallAddress,
|
|
13696
|
+
rpcUrls
|
|
13697
|
+
});
|
|
13698
|
+
for (let i = 0; i < approvalData.length; i++) {
|
|
13699
|
+
const { token, allowanceType } = approvalData[i];
|
|
13700
|
+
const allowance = allowanceType === AllowanceTypes.eip2612 ? maxUint256 : allowances[token];
|
|
13701
|
+
data[token] = { allowance, type: allowanceType };
|
|
14431
13702
|
}
|
|
13703
|
+
return { status: "success" /* success */, code: 200 /* Success */, data };
|
|
13704
|
+
} catch (error) {
|
|
13705
|
+
console.error("Multicall allowance check failed:", error);
|
|
13706
|
+
return { status: "error" /* error */, code: 500 /* Error */, data };
|
|
14432
13707
|
}
|
|
14433
13708
|
};
|
|
14434
|
-
|
|
14435
|
-
|
|
14436
|
-
|
|
14437
|
-
|
|
14438
|
-
|
|
14439
|
-
|
|
13709
|
+
async function sendBatchCalls(walletClient, calls) {
|
|
13710
|
+
try {
|
|
13711
|
+
const result = await getAction(
|
|
13712
|
+
walletClient,
|
|
13713
|
+
sendCalls,
|
|
13714
|
+
"sendCalls"
|
|
13715
|
+
)({
|
|
13716
|
+
account: walletClient.account,
|
|
13717
|
+
calls: calls.map((call) => ({
|
|
13718
|
+
to: call.to,
|
|
13719
|
+
data: call.data,
|
|
13720
|
+
value: call.value ?? BigInt(0)
|
|
13721
|
+
}))
|
|
13722
|
+
});
|
|
13723
|
+
return result;
|
|
13724
|
+
} catch (error) {
|
|
13725
|
+
console.warn("EIP-5792 batch calls not supported:", error);
|
|
13726
|
+
return null;
|
|
13727
|
+
}
|
|
13728
|
+
}
|
|
13729
|
+
|
|
13730
|
+
// src/utils/eip-5792/batchApproveTokens.ts
|
|
13731
|
+
async function generateApprovalBatchCalls({
|
|
13732
|
+
tokens,
|
|
13733
|
+
chainId,
|
|
13734
|
+
sender,
|
|
13735
|
+
spender,
|
|
13736
|
+
multicallAddress,
|
|
13737
|
+
rpcUrls
|
|
13738
|
+
}) {
|
|
13739
|
+
const tokensToCheck = tokens.filter((token) => !isDZapNativeToken(token.address));
|
|
13740
|
+
if (tokensToCheck.length === 0) {
|
|
13741
|
+
return [];
|
|
13742
|
+
}
|
|
13743
|
+
const { data: allowanceData } = await getAllowance({
|
|
13744
|
+
chainId,
|
|
13745
|
+
sender,
|
|
13746
|
+
tokens: tokensToCheck,
|
|
13747
|
+
spender,
|
|
13748
|
+
multicallAddress,
|
|
13749
|
+
rpcUrls
|
|
13750
|
+
});
|
|
13751
|
+
const tokensNeedingApproval = tokensToCheck.filter((token) => {
|
|
13752
|
+
const { allowance, type } = allowanceData[token.address] ?? {};
|
|
13753
|
+
if (type === AllowanceTypes.eip2612) return false;
|
|
13754
|
+
return allowance === void 0 || allowance < BigInt(token.amount);
|
|
13755
|
+
});
|
|
13756
|
+
return tokensNeedingApproval.map((token) => ({
|
|
13757
|
+
to: token.address,
|
|
13758
|
+
data: encodeApproveCallData({
|
|
13759
|
+
spender,
|
|
13760
|
+
amount: BigInt(token.amount)
|
|
13761
|
+
}),
|
|
13762
|
+
value: BigInt(0)
|
|
13763
|
+
}));
|
|
13764
|
+
}
|
|
13765
|
+
var waitForBatchTransactionReceipt = async (client, batchHash) => {
|
|
13766
|
+
const { receipts, status, statusCode } = await getAction(
|
|
13767
|
+
client,
|
|
13768
|
+
waitForCallsStatus,
|
|
13769
|
+
"waitForCallsStatus"
|
|
13770
|
+
)({
|
|
13771
|
+
id: batchHash,
|
|
13772
|
+
timeout: 36e5 * 24
|
|
13773
|
+
});
|
|
13774
|
+
if (status === "success" /* success */) {
|
|
13775
|
+
if (!(receipts == null ? void 0 : receipts.length) || !receipts.every((receipt) => receipt.transactionHash) || receipts.some((receipt) => receipt.status === "reverted" /* reverted */)) {
|
|
13776
|
+
throw new Error("Transaction was reverted.");
|
|
13777
|
+
}
|
|
13778
|
+
const transactionReceipt = receipts[receipts.length - 1];
|
|
13779
|
+
return transactionReceipt;
|
|
13780
|
+
}
|
|
13781
|
+
if (statusCode >= 400 && statusCode < 500) {
|
|
13782
|
+
throw new Error("Transaction was canceled.");
|
|
13783
|
+
}
|
|
13784
|
+
throw new Error("Transaction failed.");
|
|
14440
13785
|
};
|
|
14441
|
-
|
|
14442
|
-
|
|
14443
|
-
|
|
14444
|
-
|
|
13786
|
+
|
|
13787
|
+
// src/utils/signIntent/custom.ts
|
|
13788
|
+
var signCustomTypedData = async (params) => {
|
|
13789
|
+
try {
|
|
13790
|
+
const { account, signer, message, domain, primaryType, types } = params;
|
|
13791
|
+
const signature = await signTypedData({
|
|
13792
|
+
signer,
|
|
13793
|
+
account,
|
|
13794
|
+
domain,
|
|
13795
|
+
message,
|
|
13796
|
+
primaryType,
|
|
13797
|
+
types
|
|
13798
|
+
});
|
|
14445
13799
|
return {
|
|
14446
13800
|
status: "success" /* success */,
|
|
14447
13801
|
code: 200 /* Success */,
|
|
14448
|
-
|
|
14449
|
-
|
|
14450
|
-
|
|
14451
|
-
|
|
13802
|
+
data: {
|
|
13803
|
+
signature,
|
|
13804
|
+
message
|
|
13805
|
+
}
|
|
14452
13806
|
};
|
|
13807
|
+
} catch (error) {
|
|
13808
|
+
return handleViemTransactionError({ error });
|
|
14453
13809
|
}
|
|
14454
|
-
|
|
14455
|
-
|
|
14456
|
-
|
|
14457
|
-
|
|
14458
|
-
|
|
14459
|
-
|
|
14460
|
-
|
|
14461
|
-
|
|
14462
|
-
if (
|
|
14463
|
-
if (!eip2612PermitData.supportsPermit || !eip2612PermitData.data) {
|
|
14464
|
-
throw new Error("Token does not support EIP-2612 permits");
|
|
14465
|
-
}
|
|
14466
|
-
if (oneToMany && !isFirstToken) {
|
|
14467
|
-
return {
|
|
14468
|
-
status: "success" /* success */,
|
|
14469
|
-
code: 200 /* Success */,
|
|
14470
|
-
permitData: DEFAULT_PERMIT_DATA,
|
|
14471
|
-
nonce: BigInt(0),
|
|
14472
|
-
// For EIP2612 permits, nonce is not used it's already set in permitData
|
|
14473
|
-
permitType: PermitTypes.EIP2612Permit
|
|
14474
|
-
};
|
|
14475
|
-
}
|
|
14476
|
-
const { permitData, status, code } = await getEIP2612PermitSignature({
|
|
14477
|
-
...params,
|
|
14478
|
-
token: {
|
|
14479
|
-
address: token.address,
|
|
14480
|
-
amount: amount.toString(),
|
|
14481
|
-
index: 0,
|
|
14482
|
-
permit: token.permit
|
|
14483
|
-
},
|
|
14484
|
-
gasless: false,
|
|
14485
|
-
version: eip2612PermitData.data.version,
|
|
14486
|
-
name: eip2612PermitData.data.name,
|
|
14487
|
-
nonce: eip2612PermitData.data.nonce
|
|
14488
|
-
});
|
|
13810
|
+
};
|
|
13811
|
+
|
|
13812
|
+
// src/transactionHandlers/hyperliquid.ts
|
|
13813
|
+
var HyperLiquidTxHandler = class {
|
|
13814
|
+
};
|
|
13815
|
+
HyperLiquidTxHandler.sendTransaction = async (signer, account, txnData, chainId, additionalInfo, updatedQuotes) => {
|
|
13816
|
+
var _a;
|
|
13817
|
+
const signTypedData2 = "signTypedData" in txnData.transaction ? txnData.transaction.signTypedData : null;
|
|
13818
|
+
if (!signTypedData2) {
|
|
14489
13819
|
return {
|
|
14490
|
-
status
|
|
14491
|
-
|
|
14492
|
-
|
|
14493
|
-
nonce: BigInt(0),
|
|
14494
|
-
// For EIP2612 permits, nonce is not used
|
|
14495
|
-
permitType: PermitTypes.EIP2612Permit
|
|
13820
|
+
status: "error" /* error */,
|
|
13821
|
+
errorMsg: "Missing typed data for HyperLiquid transaction",
|
|
13822
|
+
code: 500 /* Error */
|
|
14496
13823
|
};
|
|
14497
|
-
} else {
|
|
14498
|
-
const normalizedPermitType = permitType === PermitTypes.AutoPermit ? PermitTypes.PermitWitnessTransferFrom : permitType;
|
|
14499
|
-
if (oneToMany && !isFirstToken) {
|
|
14500
|
-
return {
|
|
14501
|
-
status: "success" /* success */,
|
|
14502
|
-
code: 200 /* Success */,
|
|
14503
|
-
permitData: DEFAULT_PERMIT2_DATA,
|
|
14504
|
-
nonce: BigInt(0),
|
|
14505
|
-
// For one-to-many non-first tokens, nonce is not used
|
|
14506
|
-
permitType: normalizedPermitType
|
|
14507
|
-
};
|
|
14508
|
-
} else {
|
|
14509
|
-
const resp = await getPermit2Signature({
|
|
14510
|
-
...params,
|
|
14511
|
-
tokens: [token],
|
|
14512
|
-
permitType: normalizedPermitType
|
|
14513
|
-
});
|
|
14514
|
-
return {
|
|
14515
|
-
...resp,
|
|
14516
|
-
permitType: normalizedPermitType
|
|
14517
|
-
};
|
|
14518
|
-
}
|
|
14519
13824
|
}
|
|
14520
|
-
|
|
14521
|
-
|
|
14522
|
-
|
|
14523
|
-
|
|
14524
|
-
|
|
14525
|
-
|
|
14526
|
-
|
|
14527
|
-
|
|
13825
|
+
const txData = [];
|
|
13826
|
+
for (let i = 0; i < signTypedData2.length; i++) {
|
|
13827
|
+
const typedData = signTypedData2[i];
|
|
13828
|
+
const [resp, signatureChainId] = await Promise.all([
|
|
13829
|
+
signCustomTypedData({
|
|
13830
|
+
signer,
|
|
13831
|
+
account,
|
|
13832
|
+
domain: typedData.domain,
|
|
13833
|
+
types: typedData.types,
|
|
13834
|
+
message: typedData.message,
|
|
13835
|
+
primaryType: typedData.primaryType
|
|
13836
|
+
}),
|
|
13837
|
+
signer.getChainId()
|
|
13838
|
+
]);
|
|
13839
|
+
if (resp.status !== "success" /* success */ || !((_a = resp.data) == null ? void 0 : _a.signature)) {
|
|
13840
|
+
throw new Error("Failed to sign transaction");
|
|
13841
|
+
}
|
|
13842
|
+
txData.push({
|
|
13843
|
+
primaryType: typedData.primaryType,
|
|
13844
|
+
message: typedData.message,
|
|
13845
|
+
signature: resp.data.signature,
|
|
13846
|
+
account,
|
|
13847
|
+
signatureChainId
|
|
14528
13848
|
});
|
|
14529
|
-
return {
|
|
14530
|
-
status: resp2.status,
|
|
14531
|
-
code: resp2.code,
|
|
14532
|
-
data: (resp2 == null ? void 0 : resp2.data) && {
|
|
14533
|
-
...resp2.data,
|
|
14534
|
-
type
|
|
14535
|
-
}
|
|
14536
|
-
};
|
|
14537
13849
|
}
|
|
14538
|
-
const
|
|
14539
|
-
|
|
14540
|
-
|
|
14541
|
-
|
|
14542
|
-
permitType: type
|
|
13850
|
+
const txResp = await broadcastTradeTx({
|
|
13851
|
+
chainId,
|
|
13852
|
+
txData,
|
|
13853
|
+
txId: txnData.txId
|
|
14543
13854
|
});
|
|
13855
|
+
if (txResp.status !== "success" /* success */) {
|
|
13856
|
+
throw new Error("Failed to broadcast or save transaction");
|
|
13857
|
+
}
|
|
14544
13858
|
return {
|
|
14545
|
-
status:
|
|
14546
|
-
code:
|
|
14547
|
-
|
|
14548
|
-
|
|
14549
|
-
|
|
14550
|
-
}
|
|
13859
|
+
status: "success" /* success */,
|
|
13860
|
+
code: 200 /* Success */,
|
|
13861
|
+
txnHash: txResp.txnHash,
|
|
13862
|
+
additionalInfo,
|
|
13863
|
+
updatedQuotes
|
|
14551
13864
|
};
|
|
14552
13865
|
};
|
|
14553
|
-
|
|
14554
|
-
|
|
13866
|
+
|
|
13867
|
+
// src/transactionHandlers/trade.ts
|
|
13868
|
+
var _TradeTxnHandler = class _TradeTxnHandler {
|
|
14555
13869
|
};
|
|
14556
|
-
|
|
14557
|
-
|
|
14558
|
-
|
|
14559
|
-
|
|
14560
|
-
|
|
14561
|
-
|
|
14562
|
-
|
|
14563
|
-
|
|
14564
|
-
|
|
14565
|
-
|
|
14566
|
-
|
|
14567
|
-
|
|
13870
|
+
_TradeTxnHandler.sendTransaction = async (signer, txnParams, chainId, additionalInfo, updatedQuotes) => {
|
|
13871
|
+
let txnHash;
|
|
13872
|
+
if (isTypeSigner(signer)) {
|
|
13873
|
+
const txnRes = await signer.sendTransaction({
|
|
13874
|
+
from: txnParams.from,
|
|
13875
|
+
to: txnParams.to,
|
|
13876
|
+
data: txnParams.data,
|
|
13877
|
+
value: txnParams.value,
|
|
13878
|
+
gasLimit: txnParams.gasLimit
|
|
13879
|
+
});
|
|
13880
|
+
txnHash = txnRes.hash;
|
|
13881
|
+
} else {
|
|
13882
|
+
txnHash = await signer.sendTransaction({
|
|
13883
|
+
chain: viemChainsById[chainId],
|
|
13884
|
+
account: txnParams.from,
|
|
13885
|
+
to: txnParams.to,
|
|
13886
|
+
data: txnParams.data,
|
|
13887
|
+
value: BigInt(txnParams.value)
|
|
13888
|
+
});
|
|
13889
|
+
}
|
|
13890
|
+
return {
|
|
13891
|
+
status: "success" /* success */,
|
|
13892
|
+
code: 200 /* Success */,
|
|
13893
|
+
txnHash,
|
|
13894
|
+
additionalInfo,
|
|
13895
|
+
updatedQuotes
|
|
13896
|
+
};
|
|
14568
13897
|
};
|
|
14569
|
-
|
|
14570
|
-
|
|
14571
|
-
|
|
14572
|
-
|
|
14573
|
-
|
|
14574
|
-
|
|
14575
|
-
|
|
13898
|
+
_TradeTxnHandler.sendTxnWithBatch = async (request, signer, txnParams, chainId, additionalInfo, updatedQuotes, multicallAddress, rpcUrls) => {
|
|
13899
|
+
const approvalBatchCalls = await generateApprovalBatchCalls({
|
|
13900
|
+
tokens: request.data.map((token) => ({
|
|
13901
|
+
address: token.srcToken,
|
|
13902
|
+
amount: token.amount
|
|
13903
|
+
})),
|
|
13904
|
+
chainId,
|
|
13905
|
+
multicallAddress,
|
|
13906
|
+
sender: txnParams.from,
|
|
13907
|
+
spender: txnParams.to,
|
|
13908
|
+
rpcUrls
|
|
14576
13909
|
});
|
|
14577
|
-
|
|
14578
|
-
|
|
14579
|
-
|
|
13910
|
+
const batchCalls = [
|
|
13911
|
+
...approvalBatchCalls,
|
|
13912
|
+
{
|
|
13913
|
+
to: txnParams.to,
|
|
13914
|
+
data: txnParams.data,
|
|
13915
|
+
value: BigInt(txnParams.value)
|
|
13916
|
+
}
|
|
13917
|
+
];
|
|
13918
|
+
if (approvalBatchCalls.length === 0) {
|
|
13919
|
+
return _TradeTxnHandler.sendTransaction(signer, txnParams, chainId, additionalInfo, updatedQuotes);
|
|
13920
|
+
}
|
|
13921
|
+
const batchResult = await sendBatchCalls(signer, batchCalls);
|
|
13922
|
+
if (!batchResult) {
|
|
13923
|
+
return {
|
|
13924
|
+
status: "error" /* error */,
|
|
13925
|
+
errorMsg: "Batch call failed",
|
|
13926
|
+
code: 500 /* Error */
|
|
13927
|
+
};
|
|
13928
|
+
}
|
|
13929
|
+
console.log("Waiting for batch transaction completion...");
|
|
13930
|
+
const receipt = await waitForBatchTransactionReceipt(signer, batchResult.id);
|
|
13931
|
+
console.log({ receipt });
|
|
13932
|
+
return {
|
|
13933
|
+
status: "success" /* success */,
|
|
13934
|
+
code: 200 /* Success */,
|
|
13935
|
+
txnHash: receipt.transactionHash,
|
|
13936
|
+
additionalInfo,
|
|
13937
|
+
updatedQuotes
|
|
13938
|
+
};
|
|
13939
|
+
};
|
|
13940
|
+
_TradeTxnHandler.buildAndSendTransaction = async ({
|
|
13941
|
+
request,
|
|
14580
13942
|
signer,
|
|
14581
|
-
|
|
14582
|
-
|
|
14583
|
-
|
|
14584
|
-
|
|
14585
|
-
spender
|
|
13943
|
+
txnData,
|
|
13944
|
+
multicallAddress,
|
|
13945
|
+
batchTransaction = false,
|
|
13946
|
+
rpcUrls
|
|
14586
13947
|
}) => {
|
|
14587
|
-
|
|
14588
|
-
|
|
14589
|
-
|
|
14590
|
-
|
|
14591
|
-
|
|
14592
|
-
|
|
14593
|
-
const from = await signer.getAddress();
|
|
14594
|
-
const callData = encodeFunctionData({
|
|
14595
|
-
abi: abi5,
|
|
14596
|
-
functionName: erc20Functions.approve,
|
|
14597
|
-
args: [spender, BigInt(tokens[dataIdx].amount)]
|
|
14598
|
-
});
|
|
14599
|
-
await signer.sendTransaction({
|
|
14600
|
-
from,
|
|
14601
|
-
chainId,
|
|
14602
|
-
to: tokens[dataIdx].address,
|
|
14603
|
-
data: callData
|
|
14604
|
-
});
|
|
14605
|
-
return {
|
|
14606
|
-
status: "success" /* success */,
|
|
14607
|
-
code: 200 /* Success */
|
|
14608
|
-
};
|
|
13948
|
+
var _a, _b, _c, _d, _e, _f, _g, _h;
|
|
13949
|
+
try {
|
|
13950
|
+
const chainId = request.fromChain;
|
|
13951
|
+
let buildTxnResponseData;
|
|
13952
|
+
if (txnData) {
|
|
13953
|
+
buildTxnResponseData = txnData;
|
|
14609
13954
|
} else {
|
|
14610
|
-
|
|
13955
|
+
buildTxnResponseData = await fetchTradeBuildTxnData(request);
|
|
13956
|
+
}
|
|
13957
|
+
const { data, from, to, value, gasLimit, additionalInfo, updatedQuotes } = buildTxnResponseData;
|
|
13958
|
+
const txnParams = { from, to, data, value, gasLimit };
|
|
13959
|
+
if (chainId === exclusiveChainIds.hyperLiquid) {
|
|
13960
|
+
return HyperLiquidTxHandler.sendTransaction(
|
|
13961
|
+
signer,
|
|
13962
|
+
txnParams.from,
|
|
13963
|
+
buildTxnResponseData,
|
|
14611
13964
|
chainId,
|
|
14612
|
-
|
|
14613
|
-
|
|
14614
|
-
|
|
14615
|
-
args: [spender, tokens[dataIdx].amount],
|
|
14616
|
-
rpcUrls,
|
|
14617
|
-
signer
|
|
14618
|
-
});
|
|
13965
|
+
additionalInfo,
|
|
13966
|
+
updatedQuotes
|
|
13967
|
+
);
|
|
14619
13968
|
}
|
|
14620
|
-
if (
|
|
14621
|
-
return
|
|
14622
|
-
status: txnDetails.status,
|
|
14623
|
-
code: (txnDetails == null ? void 0 : txnDetails.code) || 32771 /* FunctionNotFound */
|
|
14624
|
-
};
|
|
13969
|
+
if (batchTransaction && !isTypeSigner(signer)) {
|
|
13970
|
+
return _TradeTxnHandler.sendTxnWithBatch(request, signer, txnParams, chainId, additionalInfo, updatedQuotes, multicallAddress, rpcUrls);
|
|
14625
13971
|
}
|
|
14626
|
-
|
|
14627
|
-
|
|
14628
|
-
|
|
13972
|
+
console.log("Using viem walletClient - sending regular transaction.");
|
|
13973
|
+
return _TradeTxnHandler.sendTransaction(signer, txnParams, chainId, additionalInfo, updatedQuotes);
|
|
13974
|
+
} catch (error) {
|
|
13975
|
+
console.log({ error });
|
|
13976
|
+
if (isAxiosError(error)) {
|
|
13977
|
+
if (((_a = error == null ? void 0 : error.response) == null ? void 0 : _a.status) === 417 /* SimulationFailure */) {
|
|
14629
13978
|
return {
|
|
14630
|
-
status:
|
|
14631
|
-
|
|
13979
|
+
status: "error" /* error */,
|
|
13980
|
+
errorMsg: "Simulation Failed",
|
|
13981
|
+
error: ((_b = error.response) == null ? void 0 : _b.data).message,
|
|
13982
|
+
code: ((_c = error.response) == null ? void 0 : _c.data).code,
|
|
13983
|
+
action: ((_d = error.response) == null ? void 0 : _d.data).action
|
|
14632
13984
|
};
|
|
14633
13985
|
}
|
|
13986
|
+
return {
|
|
13987
|
+
status: "error" /* error */,
|
|
13988
|
+
errorMsg: "Params Failed: " + JSON.stringify((_f = (_e = error == null ? void 0 : error.response) == null ? void 0 : _e.data) == null ? void 0 : _f.message),
|
|
13989
|
+
error: ((_g = error == null ? void 0 : error.response) == null ? void 0 : _g.data) ?? error,
|
|
13990
|
+
code: ((_h = error == null ? void 0 : error.response) == null ? void 0 : _h.status) ?? 500 /* Error */
|
|
13991
|
+
};
|
|
14634
13992
|
}
|
|
13993
|
+
return handleViemTransactionError({ error });
|
|
14635
13994
|
}
|
|
14636
|
-
return { status: "success" /* success */, code: 200 /* Success */ };
|
|
14637
13995
|
};
|
|
14638
|
-
|
|
14639
|
-
|
|
14640
|
-
|
|
14641
|
-
|
|
14642
|
-
|
|
14643
|
-
|
|
13996
|
+
_TradeTxnHandler.buildGaslessTxAndSignPermit = async ({
|
|
13997
|
+
request,
|
|
13998
|
+
signer,
|
|
13999
|
+
rpcUrls,
|
|
14000
|
+
spender,
|
|
14001
|
+
txnData,
|
|
14002
|
+
txnStatusCallback
|
|
14644
14003
|
}) => {
|
|
14645
|
-
|
|
14646
|
-
|
|
14647
|
-
|
|
14648
|
-
|
|
14649
|
-
|
|
14650
|
-
|
|
14651
|
-
|
|
14652
|
-
|
|
14653
|
-
|
|
14654
|
-
|
|
14655
|
-
|
|
14656
|
-
|
|
14657
|
-
|
|
14658
|
-
|
|
14659
|
-
|
|
14660
|
-
|
|
14661
|
-
});
|
|
14662
|
-
if (status !== "success" /* success */) {
|
|
14663
|
-
return { status, code, data: {} };
|
|
14664
|
-
}
|
|
14665
|
-
const tokenAllowances = {};
|
|
14666
|
-
for (let i = 0; i < data.length; i++) {
|
|
14667
|
-
tokenAllowances[data[i].token] = allowances[i];
|
|
14668
|
-
}
|
|
14669
|
-
return { status, code, data: tokenAllowances };
|
|
14670
|
-
};
|
|
14671
|
-
var getAllowance = async ({ chainId, sender, tokens, rpcUrls, multicallAddress, mode, spender }) => {
|
|
14672
|
-
const data = {};
|
|
14673
|
-
const nativeTokens2 = tokens.filter(({ address }) => isDZapNativeToken(address));
|
|
14674
|
-
const erc20Tokens = tokens.filter(({ address }) => !isDZapNativeToken(address));
|
|
14675
|
-
const approvalData = await Promise.all(
|
|
14676
|
-
erc20Tokens.map(async ({ address, permit }) => {
|
|
14677
|
-
if (mode === ApprovalModes.AutoPermit) {
|
|
14678
|
-
const eip2612PermitData = await checkEIP2612PermitSupport({
|
|
14679
|
-
address,
|
|
14680
|
-
chainId,
|
|
14681
|
-
rpcUrls,
|
|
14682
|
-
owner: sender,
|
|
14683
|
-
permit
|
|
14684
|
-
});
|
|
14685
|
-
const allowanceType = eip2612PermitData.supportsPermit ? AllowanceTypes.eip2612 : AllowanceTypes.permit2;
|
|
14686
|
-
return {
|
|
14687
|
-
token: address,
|
|
14688
|
-
spender: eip2612PermitData.supportsPermit ? spender : getPermit2Address(chainId),
|
|
14689
|
-
allowanceType
|
|
14690
|
-
};
|
|
14691
|
-
} else if (mode === ApprovalModes.Default) {
|
|
14004
|
+
var _a, _b, _c, _d, _e, _f, _g, _h, _i, _j;
|
|
14005
|
+
try {
|
|
14006
|
+
const chainId = request.fromChain;
|
|
14007
|
+
let buildTxnResponseData;
|
|
14008
|
+
if (txnData) {
|
|
14009
|
+
buildTxnResponseData = txnData;
|
|
14010
|
+
} else {
|
|
14011
|
+
buildTxnResponseData = await fetchTradeBuildTxnData({
|
|
14012
|
+
...request,
|
|
14013
|
+
gasless: true
|
|
14014
|
+
});
|
|
14015
|
+
}
|
|
14016
|
+
const permitType = request.hasPermit2ApprovalForAllTokens ? PermitTypes.PermitBatchWitnessTransferFrom : PermitTypes.EIP2612Permit;
|
|
14017
|
+
const txId = buildTxnResponseData.txId;
|
|
14018
|
+
const resp = await permit_default.signGaslessUserIntent({
|
|
14019
|
+
tokens: request.data.map((req, index) => {
|
|
14692
14020
|
return {
|
|
14693
|
-
|
|
14694
|
-
|
|
14695
|
-
|
|
14021
|
+
address: req.srcToken,
|
|
14022
|
+
amount: req.amount,
|
|
14023
|
+
index
|
|
14696
14024
|
};
|
|
14697
|
-
}
|
|
14698
|
-
const permit2Address = getPermit2Address(chainId);
|
|
14699
|
-
return { token: address, spender: permit2Address, allowanceType: AllowanceTypes.permit2 };
|
|
14700
|
-
}
|
|
14701
|
-
})
|
|
14702
|
-
);
|
|
14703
|
-
for (const { address } of nativeTokens2) {
|
|
14704
|
-
data[address] = { allowance: maxUint256, type: AllowanceTypes.dzap };
|
|
14705
|
-
}
|
|
14706
|
-
if (erc20Tokens.length === 0) {
|
|
14707
|
-
return { status: "success" /* success */, code: 200 /* Success */, data };
|
|
14708
|
-
}
|
|
14709
|
-
try {
|
|
14710
|
-
const { data: allowances } = await batchGetAllowances({
|
|
14025
|
+
}),
|
|
14711
14026
|
chainId,
|
|
14712
|
-
|
|
14713
|
-
|
|
14714
|
-
|
|
14715
|
-
|
|
14027
|
+
rpcUrls,
|
|
14028
|
+
sender: request.sender,
|
|
14029
|
+
spender,
|
|
14030
|
+
permitType,
|
|
14031
|
+
signer,
|
|
14032
|
+
gasless: true,
|
|
14033
|
+
txId,
|
|
14034
|
+
service: "trade",
|
|
14035
|
+
contractVersion: "v2" /* v2 */,
|
|
14036
|
+
...buildTxnResponseData.transaction
|
|
14716
14037
|
});
|
|
14717
|
-
|
|
14718
|
-
|
|
14719
|
-
|
|
14720
|
-
|
|
14038
|
+
if (resp.status === "success" /* success */ && resp.data) {
|
|
14039
|
+
if (txnStatusCallback) {
|
|
14040
|
+
txnStatusCallback("waitingForExecution" /* waitingForExecution */);
|
|
14041
|
+
}
|
|
14042
|
+
const permit = resp.data.type === PermitTypes.EIP2612Permit ? {
|
|
14043
|
+
permitData: request.data.map((req) => {
|
|
14044
|
+
return {
|
|
14045
|
+
token: req.srcToken,
|
|
14046
|
+
amount: req.amount,
|
|
14047
|
+
permit: req.permitData
|
|
14048
|
+
};
|
|
14049
|
+
}),
|
|
14050
|
+
gaslessIntentNonce: (_a = resp.data.nonce) == null ? void 0 : _a.toString(),
|
|
14051
|
+
gaslessIntentSignature: resp.data.signature,
|
|
14052
|
+
gaslessIntentDeadline: (_b = resp.data.deadline) == null ? void 0 : _b.toString()
|
|
14053
|
+
} : {
|
|
14054
|
+
batchPermitData: resp.data.batchPermitData
|
|
14055
|
+
};
|
|
14056
|
+
const gaslessTxResp = await executeGaslessTxnData({
|
|
14057
|
+
chainId: request.fromChain,
|
|
14058
|
+
txId,
|
|
14059
|
+
permit
|
|
14060
|
+
});
|
|
14061
|
+
if (gaslessTxResp.status !== "success" /* success */) {
|
|
14062
|
+
throw new Error("Failed to execute gasless transaction");
|
|
14063
|
+
}
|
|
14064
|
+
return {
|
|
14065
|
+
status: "success" /* success */,
|
|
14066
|
+
code: 200 /* Success */,
|
|
14067
|
+
txnHash: gaslessTxResp.txnHash
|
|
14068
|
+
};
|
|
14069
|
+
}
|
|
14070
|
+
throw new Error("Gasless Transaction Failed");
|
|
14071
|
+
} catch (error) {
|
|
14072
|
+
console.log({ error });
|
|
14073
|
+
if (isAxiosError(error)) {
|
|
14074
|
+
if (((_c = error == null ? void 0 : error.response) == null ? void 0 : _c.status) === 417 /* SimulationFailure */) {
|
|
14075
|
+
return {
|
|
14076
|
+
status: "error" /* error */,
|
|
14077
|
+
errorMsg: "Simulation Failed",
|
|
14078
|
+
error: ((_d = error.response) == null ? void 0 : _d.data).message,
|
|
14079
|
+
code: ((_e = error.response) == null ? void 0 : _e.data).code,
|
|
14080
|
+
action: ((_f = error.response) == null ? void 0 : _f.data).action
|
|
14081
|
+
};
|
|
14082
|
+
}
|
|
14083
|
+
return {
|
|
14084
|
+
status: "error" /* error */,
|
|
14085
|
+
errorMsg: "Params Failed: " + JSON.stringify((_h = (_g = error == null ? void 0 : error.response) == null ? void 0 : _g.data) == null ? void 0 : _h.message),
|
|
14086
|
+
error: ((_i = error == null ? void 0 : error.response) == null ? void 0 : _i.data) ?? error,
|
|
14087
|
+
code: ((_j = error == null ? void 0 : error.response) == null ? void 0 : _j.status) ?? 500 /* Error */
|
|
14088
|
+
};
|
|
14721
14089
|
}
|
|
14722
|
-
return {
|
|
14723
|
-
} catch (error) {
|
|
14724
|
-
console.error("Multicall allowance check failed:", error);
|
|
14725
|
-
return { status: "error" /* error */, code: 500 /* Error */, data };
|
|
14090
|
+
return handleViemTransactionError({ error });
|
|
14726
14091
|
}
|
|
14727
14092
|
};
|
|
14728
|
-
|
|
14729
|
-
|
|
14730
|
-
const result = await getAction(
|
|
14731
|
-
walletClient,
|
|
14732
|
-
sendCalls,
|
|
14733
|
-
"sendCalls"
|
|
14734
|
-
)({
|
|
14735
|
-
account: walletClient.account,
|
|
14736
|
-
calls: calls.map((call) => ({
|
|
14737
|
-
to: call.to,
|
|
14738
|
-
data: call.data,
|
|
14739
|
-
value: call.value ?? BigInt(0)
|
|
14740
|
-
}))
|
|
14741
|
-
});
|
|
14742
|
-
return result;
|
|
14743
|
-
} catch (error) {
|
|
14744
|
-
console.warn("EIP-5792 batch calls not supported:", error);
|
|
14745
|
-
return null;
|
|
14746
|
-
}
|
|
14747
|
-
}
|
|
14093
|
+
var TradeTxnHandler = _TradeTxnHandler;
|
|
14094
|
+
var trade_default = TradeTxnHandler;
|
|
14748
14095
|
|
|
14749
|
-
// src/
|
|
14750
|
-
|
|
14751
|
-
|
|
14752
|
-
chainId,
|
|
14753
|
-
sender,
|
|
14754
|
-
spender,
|
|
14755
|
-
multicallAddress,
|
|
14756
|
-
rpcUrls
|
|
14757
|
-
}) {
|
|
14758
|
-
const tokensToCheck = tokens.filter((token) => !isDZapNativeToken(token.address));
|
|
14759
|
-
if (tokensToCheck.length === 0) {
|
|
14760
|
-
return [];
|
|
14761
|
-
}
|
|
14762
|
-
const { data: allowanceData } = await getAllowance({
|
|
14763
|
-
chainId,
|
|
14764
|
-
sender,
|
|
14765
|
-
tokens: tokensToCheck,
|
|
14766
|
-
spender,
|
|
14767
|
-
multicallAddress,
|
|
14768
|
-
rpcUrls
|
|
14769
|
-
});
|
|
14770
|
-
const tokensNeedingApproval = tokensToCheck.filter((token) => {
|
|
14771
|
-
const { allowance, type } = allowanceData[token.address] ?? {};
|
|
14772
|
-
if (type === AllowanceTypes.eip2612) return false;
|
|
14773
|
-
return allowance === void 0 || allowance < BigInt(token.amount);
|
|
14774
|
-
});
|
|
14775
|
-
return tokensNeedingApproval.map((token) => ({
|
|
14776
|
-
to: token.address,
|
|
14777
|
-
data: encodeApproveCallData({
|
|
14778
|
-
spender,
|
|
14779
|
-
amount: BigInt(token.amount)
|
|
14780
|
-
}),
|
|
14781
|
-
value: BigInt(0)
|
|
14782
|
-
}));
|
|
14783
|
-
}
|
|
14784
|
-
var waitForBatchTransactionReceipt = async (client, batchHash) => {
|
|
14785
|
-
const { receipts, status, statusCode } = await getAction(
|
|
14786
|
-
client,
|
|
14787
|
-
waitForCallsStatus,
|
|
14788
|
-
"waitForCallsStatus"
|
|
14789
|
-
)({
|
|
14790
|
-
id: batchHash,
|
|
14791
|
-
timeout: 36e5 * 24
|
|
14792
|
-
});
|
|
14793
|
-
if (status === "success" /* success */) {
|
|
14794
|
-
if (!(receipts == null ? void 0 : receipts.length) || !receipts.every((receipt) => receipt.transactionHash) || receipts.some((receipt) => receipt.status === "reverted" /* reverted */)) {
|
|
14795
|
-
throw new Error("Transaction was reverted.");
|
|
14796
|
-
}
|
|
14797
|
-
const transactionReceipt = receipts[receipts.length - 1];
|
|
14798
|
-
return transactionReceipt;
|
|
14799
|
-
}
|
|
14800
|
-
if (statusCode >= 400 && statusCode < 500) {
|
|
14801
|
-
throw new Error("Transaction was canceled.");
|
|
14802
|
-
}
|
|
14803
|
-
throw new Error("Transaction failed.");
|
|
14096
|
+
// src/zap/constants/step.ts
|
|
14097
|
+
var zapStepAction = {
|
|
14098
|
+
execute: "execute"
|
|
14804
14099
|
};
|
|
14805
14100
|
|
|
14806
|
-
// src/
|
|
14807
|
-
var
|
|
14101
|
+
// src/transactionHandlers/zap.ts
|
|
14102
|
+
var _ZapTxnHandler = class _ZapTxnHandler {
|
|
14103
|
+
};
|
|
14104
|
+
_ZapTxnHandler.execute = async ({
|
|
14105
|
+
chainId,
|
|
14106
|
+
txnData,
|
|
14107
|
+
signer
|
|
14108
|
+
}) => {
|
|
14109
|
+
var _a;
|
|
14808
14110
|
try {
|
|
14809
|
-
const {
|
|
14810
|
-
|
|
14811
|
-
signer
|
|
14812
|
-
|
|
14813
|
-
|
|
14814
|
-
|
|
14815
|
-
|
|
14816
|
-
|
|
14817
|
-
|
|
14818
|
-
|
|
14819
|
-
|
|
14820
|
-
|
|
14821
|
-
|
|
14822
|
-
|
|
14823
|
-
|
|
14824
|
-
}
|
|
14825
|
-
}
|
|
14111
|
+
const { callData, callTo, value, estimatedGas } = txnData;
|
|
14112
|
+
if (isTypeSigner(signer)) {
|
|
14113
|
+
console.log("Using ethers signer.");
|
|
14114
|
+
const from = await signer.getAddress();
|
|
14115
|
+
const txnRes = await signer.sendTransaction({
|
|
14116
|
+
from,
|
|
14117
|
+
to: callTo,
|
|
14118
|
+
data: callData,
|
|
14119
|
+
value: BigInt(value),
|
|
14120
|
+
gasLimit: BigInt(estimatedGas) ? BigInt(estimatedGas) : void 0
|
|
14121
|
+
});
|
|
14122
|
+
return {
|
|
14123
|
+
status: "success" /* success */,
|
|
14124
|
+
code: 200 /* Success */,
|
|
14125
|
+
txnHash: txnRes.hash
|
|
14126
|
+
};
|
|
14127
|
+
} else {
|
|
14128
|
+
console.log("Using viem walletClient.");
|
|
14129
|
+
const txnHash = await signer.sendTransaction({
|
|
14130
|
+
chain: viemChainsById[chainId],
|
|
14131
|
+
account: (_a = signer.account) == null ? void 0 : _a.address,
|
|
14132
|
+
to: txnData.callTo,
|
|
14133
|
+
data: txnData.callData,
|
|
14134
|
+
value: BigInt(txnData.value)
|
|
14135
|
+
});
|
|
14136
|
+
return {
|
|
14137
|
+
status: "success" /* success */,
|
|
14138
|
+
code: 200 /* Success */,
|
|
14139
|
+
txnHash
|
|
14140
|
+
};
|
|
14141
|
+
}
|
|
14826
14142
|
} catch (error) {
|
|
14143
|
+
console.log({ error });
|
|
14827
14144
|
return handleViemTransactionError({ error });
|
|
14828
14145
|
}
|
|
14829
14146
|
};
|
|
14830
|
-
|
|
14831
|
-
// src/transactionHandlers/hyperliquid.ts
|
|
14832
|
-
var HyperLiquidTxHandler = class {
|
|
14833
|
-
};
|
|
14834
|
-
HyperLiquidTxHandler.sendTransaction = async (signer, account, txnData, chainId, additionalInfo, updatedQuotes) => {
|
|
14147
|
+
_ZapTxnHandler.approve = async ({ chainId, data, signer }) => {
|
|
14835
14148
|
var _a;
|
|
14836
|
-
|
|
14837
|
-
|
|
14838
|
-
|
|
14839
|
-
|
|
14840
|
-
|
|
14841
|
-
|
|
14842
|
-
|
|
14149
|
+
try {
|
|
14150
|
+
const { callData, callTo, value, estimatedGas } = data;
|
|
14151
|
+
const publicClient = getPublicClient({ chainId, rpcUrls: void 0 });
|
|
14152
|
+
const blockNumber = await publicClient.getBlockNumber();
|
|
14153
|
+
console.log("block Number and data");
|
|
14154
|
+
console.dir(
|
|
14155
|
+
{
|
|
14156
|
+
blockNumber,
|
|
14157
|
+
...data
|
|
14158
|
+
},
|
|
14159
|
+
{ depth: null }
|
|
14160
|
+
);
|
|
14161
|
+
if (isTypeSigner(signer)) {
|
|
14162
|
+
console.log("Using ethers signer.");
|
|
14163
|
+
const from = await signer.getAddress();
|
|
14164
|
+
const txnRes = await signer.sendTransaction({
|
|
14165
|
+
from,
|
|
14166
|
+
to: callTo,
|
|
14167
|
+
data: callData,
|
|
14168
|
+
value: BigInt(value),
|
|
14169
|
+
gasLimit: BigInt(estimatedGas) ? BigInt(estimatedGas) : void 0
|
|
14170
|
+
});
|
|
14171
|
+
return {
|
|
14172
|
+
status: "success" /* success */,
|
|
14173
|
+
code: 200 /* Success */,
|
|
14174
|
+
txnHash: txnRes.hash
|
|
14175
|
+
};
|
|
14176
|
+
} else {
|
|
14177
|
+
console.log("Using viem walletClient.");
|
|
14178
|
+
const txnHash = await signer.sendTransaction({
|
|
14179
|
+
chain: viemChainsById[chainId],
|
|
14180
|
+
account: (_a = signer.account) == null ? void 0 : _a.address,
|
|
14181
|
+
to: data.callTo,
|
|
14182
|
+
data: data.callData,
|
|
14183
|
+
value: BigInt(data.value)
|
|
14184
|
+
});
|
|
14185
|
+
return {
|
|
14186
|
+
status: "success" /* success */,
|
|
14187
|
+
code: 200 /* Success */,
|
|
14188
|
+
txnHash
|
|
14189
|
+
};
|
|
14190
|
+
}
|
|
14191
|
+
} catch (error) {
|
|
14192
|
+
console.log({ error });
|
|
14193
|
+
return handleViemTransactionError({ error });
|
|
14843
14194
|
}
|
|
14844
|
-
|
|
14845
|
-
|
|
14846
|
-
|
|
14847
|
-
|
|
14848
|
-
|
|
14849
|
-
|
|
14850
|
-
|
|
14851
|
-
|
|
14852
|
-
|
|
14853
|
-
|
|
14854
|
-
|
|
14855
|
-
|
|
14856
|
-
|
|
14857
|
-
|
|
14858
|
-
|
|
14859
|
-
|
|
14195
|
+
};
|
|
14196
|
+
_ZapTxnHandler.zap = async ({
|
|
14197
|
+
request,
|
|
14198
|
+
steps,
|
|
14199
|
+
signer
|
|
14200
|
+
}) => {
|
|
14201
|
+
try {
|
|
14202
|
+
const chainId = "srcChainId" in request ? request.srcChainId : request.actions[0].srcChainId;
|
|
14203
|
+
if (!steps || steps.length === 0) {
|
|
14204
|
+
const route = "actions" in request ? (await fetchZapBundleBuildTx(request)).data : (await fetchZapBuildTxnData(request)).data;
|
|
14205
|
+
steps = route.steps;
|
|
14206
|
+
if (!steps || steps.length === 0) {
|
|
14207
|
+
return {
|
|
14208
|
+
status: "error" /* error */,
|
|
14209
|
+
code: 32771 /* FunctionNotFound */,
|
|
14210
|
+
errorMsg: "No steps found in the zap route."
|
|
14211
|
+
};
|
|
14212
|
+
}
|
|
14213
|
+
}
|
|
14214
|
+
let txnHash;
|
|
14215
|
+
for (let i = 0; i < steps.length; i++) {
|
|
14216
|
+
const step = steps[i];
|
|
14217
|
+
if (step.action === zapStepAction.execute) {
|
|
14218
|
+
const result = await _ZapTxnHandler.execute({ chainId, txnData: step.data, signer });
|
|
14219
|
+
if (result.status !== "success" /* success */) {
|
|
14220
|
+
return result;
|
|
14221
|
+
}
|
|
14222
|
+
txnHash = result.txnHash;
|
|
14223
|
+
}
|
|
14860
14224
|
}
|
|
14861
|
-
|
|
14862
|
-
|
|
14863
|
-
|
|
14864
|
-
|
|
14865
|
-
|
|
14866
|
-
|
|
14867
|
-
}
|
|
14225
|
+
if (!txnHash) {
|
|
14226
|
+
return {
|
|
14227
|
+
status: "error" /* error */,
|
|
14228
|
+
code: 500 /* Error */,
|
|
14229
|
+
errorMsg: "No executable steps found."
|
|
14230
|
+
};
|
|
14231
|
+
}
|
|
14232
|
+
return {
|
|
14233
|
+
status: "success" /* success */,
|
|
14234
|
+
code: 200 /* Success */,
|
|
14235
|
+
txnHash
|
|
14236
|
+
};
|
|
14237
|
+
} catch (error) {
|
|
14238
|
+
console.log({ error });
|
|
14239
|
+
return handleViemTransactionError({ error });
|
|
14868
14240
|
}
|
|
14869
|
-
|
|
14870
|
-
|
|
14871
|
-
|
|
14872
|
-
|
|
14241
|
+
};
|
|
14242
|
+
var ZapTxnHandler = _ZapTxnHandler;
|
|
14243
|
+
var zap_default = ZapTxnHandler;
|
|
14244
|
+
var SUI_DEFAULT_RPC = "https://sui-rpc.publicnode.com";
|
|
14245
|
+
var decodeSuivmTransaction = async ({ txHash, rpcUrls }) => {
|
|
14246
|
+
var _a, _b, _c, _d, _e, _f, _g, _h;
|
|
14247
|
+
const rpcUrl = (rpcUrls == null ? void 0 : rpcUrls[0]) ?? SUI_DEFAULT_RPC;
|
|
14248
|
+
const response = await Axios.post(rpcUrl, {
|
|
14249
|
+
jsonrpc: "2.0",
|
|
14250
|
+
id: 1,
|
|
14251
|
+
method: "sui_getTransactionBlock",
|
|
14252
|
+
params: [txHash, { showBalanceChanges: true, showEffects: true, showInput: true }]
|
|
14873
14253
|
});
|
|
14874
|
-
if (
|
|
14875
|
-
|
|
14254
|
+
if (response.status !== 200 || ((_a = response.data) == null ? void 0 : _a.error)) {
|
|
14255
|
+
return void 0;
|
|
14876
14256
|
}
|
|
14877
|
-
|
|
14878
|
-
|
|
14879
|
-
|
|
14880
|
-
|
|
14881
|
-
|
|
14882
|
-
updatedQuotes
|
|
14883
|
-
};
|
|
14884
|
-
};
|
|
14885
|
-
|
|
14886
|
-
// src/transactionHandlers/trade.ts
|
|
14887
|
-
var _TradeTxnHandler = class _TradeTxnHandler {
|
|
14888
|
-
};
|
|
14889
|
-
_TradeTxnHandler.sendTransaction = async (signer, txnParams, chainId, additionalInfo, updatedQuotes) => {
|
|
14890
|
-
let txnHash;
|
|
14891
|
-
if (isTypeSigner(signer)) {
|
|
14892
|
-
const txnRes = await signer.sendTransaction({
|
|
14893
|
-
from: txnParams.from,
|
|
14894
|
-
to: txnParams.to,
|
|
14895
|
-
data: txnParams.data,
|
|
14896
|
-
value: txnParams.value,
|
|
14897
|
-
gasLimit: txnParams.gasLimit
|
|
14898
|
-
});
|
|
14899
|
-
txnHash = txnRes.hash;
|
|
14900
|
-
} else {
|
|
14901
|
-
txnHash = await signer.sendTransaction({
|
|
14902
|
-
chain: viemChainsById[chainId],
|
|
14903
|
-
account: txnParams.from,
|
|
14904
|
-
to: txnParams.to,
|
|
14905
|
-
data: txnParams.data,
|
|
14906
|
-
value: BigInt(txnParams.value)
|
|
14907
|
-
});
|
|
14257
|
+
const result = (_b = response.data) == null ? void 0 : _b.result;
|
|
14258
|
+
const sender = (_d = (_c = result == null ? void 0 : result.transaction) == null ? void 0 : _c.data) == null ? void 0 : _d.sender;
|
|
14259
|
+
const balanceChanges = result == null ? void 0 : result.balanceChanges;
|
|
14260
|
+
if (!sender || !balanceChanges) {
|
|
14261
|
+
return void 0;
|
|
14908
14262
|
}
|
|
14909
|
-
|
|
14910
|
-
|
|
14911
|
-
|
|
14912
|
-
|
|
14913
|
-
|
|
14914
|
-
|
|
14915
|
-
|
|
14916
|
-
|
|
14917
|
-
|
|
14918
|
-
|
|
14919
|
-
|
|
14920
|
-
|
|
14921
|
-
|
|
14922
|
-
|
|
14923
|
-
chainId,
|
|
14924
|
-
multicallAddress,
|
|
14925
|
-
sender: txnParams.from,
|
|
14926
|
-
spender: txnParams.to,
|
|
14927
|
-
rpcUrls
|
|
14928
|
-
});
|
|
14929
|
-
const batchCalls = [
|
|
14930
|
-
...approvalBatchCalls,
|
|
14931
|
-
{
|
|
14932
|
-
to: txnParams.to,
|
|
14933
|
-
data: txnParams.data,
|
|
14934
|
-
value: BigInt(txnParams.value)
|
|
14263
|
+
const gasUsed = (_e = result == null ? void 0 : result.effects) == null ? void 0 : _e.gasUsed;
|
|
14264
|
+
const senderPaidGas = (((_h = (_g = (_f = result == null ? void 0 : result.transaction) == null ? void 0 : _f.data) == null ? void 0 : _g.gasData) == null ? void 0 : _h.owner) ?? sender) === sender;
|
|
14265
|
+
const gasCost = gasUsed && senderPaidGas ? BigInt(gasUsed.computationCost ?? 0) + BigInt(gasUsed.storageCost ?? 0) - BigInt(gasUsed.storageRebate ?? 0) : BigInt(0);
|
|
14266
|
+
const sent = [];
|
|
14267
|
+
const received = [];
|
|
14268
|
+
balanceChanges.filter((change) => {
|
|
14269
|
+
var _a2;
|
|
14270
|
+
return ((_a2 = change.owner) == null ? void 0 : _a2.AddressOwner) === sender;
|
|
14271
|
+
}).forEach((change) => {
|
|
14272
|
+
const amount = BigInt(change.amount) + (change.coinType === suiNativeToken ? gasCost : BigInt(0));
|
|
14273
|
+
if (amount < BigInt(0)) {
|
|
14274
|
+
sent.push({ token: change.coinType, amount: -amount });
|
|
14275
|
+
} else if (amount > BigInt(0)) {
|
|
14276
|
+
received.push({ token: change.coinType, amount });
|
|
14935
14277
|
}
|
|
14936
|
-
|
|
14937
|
-
if (
|
|
14938
|
-
return
|
|
14278
|
+
});
|
|
14279
|
+
if (sent.length === 0 && received.length === 0) {
|
|
14280
|
+
return void 0;
|
|
14939
14281
|
}
|
|
14940
|
-
|
|
14941
|
-
|
|
14942
|
-
|
|
14943
|
-
|
|
14944
|
-
|
|
14945
|
-
|
|
14946
|
-
|
|
14282
|
+
return { sent, received };
|
|
14283
|
+
};
|
|
14284
|
+
var SVM_TX_LOOKUP_ATTEMPTS = 6;
|
|
14285
|
+
var SVM_TX_LOOKUP_BASE_DELAY_MS = 500;
|
|
14286
|
+
var getConfirmedTransaction = async (connection, txHash, attempt = 1) => {
|
|
14287
|
+
const tx = await connection.getParsedTransaction(txHash, { commitment: "confirmed", maxSupportedTransactionVersion: 0 });
|
|
14288
|
+
if (tx) {
|
|
14289
|
+
return tx;
|
|
14947
14290
|
}
|
|
14948
|
-
|
|
14949
|
-
|
|
14950
|
-
|
|
14951
|
-
|
|
14952
|
-
|
|
14953
|
-
code: 200 /* Success */,
|
|
14954
|
-
txnHash: receipt.transactionHash,
|
|
14955
|
-
additionalInfo,
|
|
14956
|
-
updatedQuotes
|
|
14957
|
-
};
|
|
14291
|
+
if (attempt >= SVM_TX_LOOKUP_ATTEMPTS) {
|
|
14292
|
+
throw new Error(`transaction ${txHash} not found after ${attempt} attempts`);
|
|
14293
|
+
}
|
|
14294
|
+
await new Promise((resolve) => setTimeout(resolve, SVM_TX_LOOKUP_BASE_DELAY_MS * 2 ** (attempt - 1)));
|
|
14295
|
+
return getConfirmedTransaction(connection, txHash, attempt + 1);
|
|
14958
14296
|
};
|
|
14959
|
-
|
|
14960
|
-
|
|
14961
|
-
|
|
14962
|
-
|
|
14963
|
-
|
|
14964
|
-
|
|
14965
|
-
|
|
14966
|
-
|
|
14967
|
-
|
|
14968
|
-
|
|
14969
|
-
|
|
14970
|
-
|
|
14971
|
-
|
|
14972
|
-
|
|
14973
|
-
|
|
14974
|
-
|
|
14297
|
+
var decodeSvmTransaction = async ({ txHash, rpcUrls }) => {
|
|
14298
|
+
var _a, _b, _c, _d, _e;
|
|
14299
|
+
const connection = new Connection((rpcUrls == null ? void 0 : rpcUrls[0]) || clusterApiUrl("mainnet-beta"));
|
|
14300
|
+
const tx = await getConfirmedTransaction(connection, txHash);
|
|
14301
|
+
const meta = tx == null ? void 0 : tx.meta;
|
|
14302
|
+
const owner = (_e = (_d = (_c = (_b = (_a = tx == null ? void 0 : tx.transaction) == null ? void 0 : _a.message) == null ? void 0 : _b.accountKeys) == null ? void 0 : _c[0]) == null ? void 0 : _d.pubkey) == null ? void 0 : _e.toBase58();
|
|
14303
|
+
if (!meta || !owner) {
|
|
14304
|
+
return void 0;
|
|
14305
|
+
}
|
|
14306
|
+
const preTokenBalances = meta.preTokenBalances ?? [];
|
|
14307
|
+
const postTokenBalances = meta.postTokenBalances ?? [];
|
|
14308
|
+
const preBalances = meta.preBalances ?? [];
|
|
14309
|
+
const postBalances = meta.postBalances ?? [];
|
|
14310
|
+
const deltas = /* @__PURE__ */ new Map();
|
|
14311
|
+
const addDelta = (token, delta) => deltas.set(token, (deltas.get(token) ?? BigInt(0)) + delta);
|
|
14312
|
+
let rentAdjustment = BigInt(0);
|
|
14313
|
+
const rentOf = (accountIndex, wrappedDelta) => BigInt(postBalances[accountIndex] ?? 0) - BigInt(preBalances[accountIndex] ?? 0) - wrappedDelta;
|
|
14314
|
+
const wrappedPart = (mint, delta) => mint === solanaWNativeToken ? delta : BigInt(0);
|
|
14315
|
+
postTokenBalances.filter((balance) => balance.owner === owner).forEach((post) => {
|
|
14316
|
+
const pre = preTokenBalances.find((item) => item.accountIndex === post.accountIndex);
|
|
14317
|
+
const delta = BigInt(post.uiTokenAmount.amount) - BigInt((pre == null ? void 0 : pre.uiTokenAmount.amount) ?? "0");
|
|
14318
|
+
addDelta(post.mint, delta);
|
|
14319
|
+
if (!pre) {
|
|
14320
|
+
rentAdjustment += rentOf(post.accountIndex, wrappedPart(post.mint, delta));
|
|
14975
14321
|
}
|
|
14976
|
-
|
|
14977
|
-
|
|
14978
|
-
|
|
14979
|
-
|
|
14980
|
-
|
|
14981
|
-
|
|
14982
|
-
|
|
14983
|
-
|
|
14984
|
-
|
|
14985
|
-
|
|
14986
|
-
|
|
14322
|
+
});
|
|
14323
|
+
preTokenBalances.filter((balance) => balance.owner === owner && !postTokenBalances.some((post) => post.accountIndex === balance.accountIndex)).forEach((pre) => {
|
|
14324
|
+
const delta = -BigInt(pre.uiTokenAmount.amount);
|
|
14325
|
+
addDelta(pre.mint, delta);
|
|
14326
|
+
rentAdjustment += rentOf(pre.accountIndex, wrappedPart(pre.mint, delta));
|
|
14327
|
+
});
|
|
14328
|
+
const nativeDelta = BigInt(postBalances[0] ?? 0) - BigInt(preBalances[0] ?? 0) + BigInt(meta.fee ?? 0) + rentAdjustment;
|
|
14329
|
+
addDelta(solanaNativeToken, nativeDelta);
|
|
14330
|
+
const sent = [];
|
|
14331
|
+
const received = [];
|
|
14332
|
+
deltas.forEach((amount, token) => {
|
|
14333
|
+
if (amount < BigInt(0)) {
|
|
14334
|
+
sent.push({ token, amount: -amount });
|
|
14335
|
+
} else if (amount > BigInt(0)) {
|
|
14336
|
+
received.push({ token, amount });
|
|
14987
14337
|
}
|
|
14988
|
-
|
|
14989
|
-
|
|
14338
|
+
});
|
|
14339
|
+
if (sent.length === 0 && received.length === 0) {
|
|
14340
|
+
return void 0;
|
|
14341
|
+
}
|
|
14342
|
+
return { sent, received };
|
|
14343
|
+
};
|
|
14344
|
+
|
|
14345
|
+
// src/utils/decoder/swap/abis.ts
|
|
14346
|
+
var SwapAbisByFunctionName = {
|
|
14347
|
+
SingleSwap: [
|
|
14348
|
+
{
|
|
14349
|
+
inputs: [
|
|
14350
|
+
{
|
|
14351
|
+
internalType: "bytes32",
|
|
14352
|
+
name: "_transactionId",
|
|
14353
|
+
type: "bytes32"
|
|
14354
|
+
},
|
|
14355
|
+
{
|
|
14356
|
+
internalType: "bytes",
|
|
14357
|
+
name: "_feeData",
|
|
14358
|
+
type: "bytes"
|
|
14359
|
+
},
|
|
14360
|
+
{
|
|
14361
|
+
internalType: "bytes",
|
|
14362
|
+
name: "_feeVerificationSignature",
|
|
14363
|
+
type: "bytes"
|
|
14364
|
+
},
|
|
14365
|
+
{
|
|
14366
|
+
internalType: "uint256",
|
|
14367
|
+
name: "_deadline",
|
|
14368
|
+
type: "uint256"
|
|
14369
|
+
},
|
|
14370
|
+
{
|
|
14371
|
+
components: [
|
|
14372
|
+
{
|
|
14373
|
+
internalType: "address",
|
|
14374
|
+
name: "token",
|
|
14375
|
+
type: "address"
|
|
14376
|
+
},
|
|
14377
|
+
{
|
|
14378
|
+
internalType: "uint256",
|
|
14379
|
+
name: "amount",
|
|
14380
|
+
type: "uint256"
|
|
14381
|
+
},
|
|
14382
|
+
{
|
|
14383
|
+
internalType: "bytes",
|
|
14384
|
+
name: "permit",
|
|
14385
|
+
type: "bytes"
|
|
14386
|
+
}
|
|
14387
|
+
],
|
|
14388
|
+
internalType: "struct InputToken",
|
|
14389
|
+
name: "_inputTokens",
|
|
14390
|
+
type: "tuple"
|
|
14391
|
+
},
|
|
14392
|
+
{
|
|
14393
|
+
components: [
|
|
14394
|
+
{
|
|
14395
|
+
internalType: "address",
|
|
14396
|
+
name: "recipient",
|
|
14397
|
+
type: "address"
|
|
14398
|
+
},
|
|
14399
|
+
{
|
|
14400
|
+
internalType: "address",
|
|
14401
|
+
name: "from",
|
|
14402
|
+
type: "address"
|
|
14403
|
+
},
|
|
14404
|
+
{
|
|
14405
|
+
internalType: "address",
|
|
14406
|
+
name: "to",
|
|
14407
|
+
type: "address"
|
|
14408
|
+
},
|
|
14409
|
+
{
|
|
14410
|
+
internalType: "uint256",
|
|
14411
|
+
name: "fromAmount",
|
|
14412
|
+
type: "uint256"
|
|
14413
|
+
},
|
|
14414
|
+
{
|
|
14415
|
+
internalType: "uint256",
|
|
14416
|
+
name: "minToAmount",
|
|
14417
|
+
type: "uint256"
|
|
14418
|
+
}
|
|
14419
|
+
],
|
|
14420
|
+
internalType: "struct SwapData",
|
|
14421
|
+
name: "_swapData",
|
|
14422
|
+
type: "tuple"
|
|
14423
|
+
},
|
|
14424
|
+
{
|
|
14425
|
+
components: [
|
|
14426
|
+
{
|
|
14427
|
+
internalType: "string",
|
|
14428
|
+
name: "dex",
|
|
14429
|
+
type: "string"
|
|
14430
|
+
},
|
|
14431
|
+
{
|
|
14432
|
+
internalType: "address",
|
|
14433
|
+
name: "callTo",
|
|
14434
|
+
type: "address"
|
|
14435
|
+
},
|
|
14436
|
+
{
|
|
14437
|
+
internalType: "address",
|
|
14438
|
+
name: "approveTo",
|
|
14439
|
+
type: "address"
|
|
14440
|
+
},
|
|
14441
|
+
{
|
|
14442
|
+
internalType: "bytes",
|
|
14443
|
+
name: "swapCallData",
|
|
14444
|
+
type: "bytes"
|
|
14445
|
+
},
|
|
14446
|
+
{
|
|
14447
|
+
internalType: "bool",
|
|
14448
|
+
name: "isDirectTransfer",
|
|
14449
|
+
type: "bool"
|
|
14450
|
+
}
|
|
14451
|
+
],
|
|
14452
|
+
internalType: "struct SwapExecutionData",
|
|
14453
|
+
name: "_swapExecutionData",
|
|
14454
|
+
type: "tuple"
|
|
14455
|
+
}
|
|
14456
|
+
],
|
|
14457
|
+
name: "swap",
|
|
14458
|
+
outputs: [],
|
|
14459
|
+
stateMutability: "payable",
|
|
14460
|
+
type: "function"
|
|
14990
14461
|
}
|
|
14991
|
-
|
|
14992
|
-
|
|
14993
|
-
|
|
14994
|
-
|
|
14995
|
-
|
|
14996
|
-
|
|
14997
|
-
|
|
14998
|
-
|
|
14999
|
-
|
|
15000
|
-
|
|
15001
|
-
|
|
15002
|
-
|
|
15003
|
-
|
|
15004
|
-
|
|
15005
|
-
|
|
15006
|
-
|
|
15007
|
-
|
|
15008
|
-
|
|
15009
|
-
|
|
15010
|
-
|
|
14462
|
+
],
|
|
14463
|
+
BatchPermitSwapAbi: [
|
|
14464
|
+
{
|
|
14465
|
+
inputs: [
|
|
14466
|
+
{
|
|
14467
|
+
internalType: "bytes32",
|
|
14468
|
+
name: "_transactionId",
|
|
14469
|
+
type: "bytes32"
|
|
14470
|
+
},
|
|
14471
|
+
{
|
|
14472
|
+
internalType: "bytes",
|
|
14473
|
+
name: "_feeData",
|
|
14474
|
+
type: "bytes"
|
|
14475
|
+
},
|
|
14476
|
+
{
|
|
14477
|
+
internalType: "bytes",
|
|
14478
|
+
name: "_feeVerificationSignature",
|
|
14479
|
+
type: "bytes"
|
|
14480
|
+
},
|
|
14481
|
+
{
|
|
14482
|
+
internalType: "uint256",
|
|
14483
|
+
name: "_deadline",
|
|
14484
|
+
type: "uint256"
|
|
14485
|
+
},
|
|
14486
|
+
{
|
|
14487
|
+
internalType: "bytes",
|
|
14488
|
+
name: "_batchDepositSignature",
|
|
14489
|
+
type: "bytes"
|
|
14490
|
+
},
|
|
14491
|
+
{
|
|
14492
|
+
components: [
|
|
14493
|
+
{
|
|
14494
|
+
components: [
|
|
14495
|
+
{
|
|
14496
|
+
internalType: "address",
|
|
14497
|
+
name: "token",
|
|
14498
|
+
type: "address"
|
|
14499
|
+
},
|
|
14500
|
+
{
|
|
14501
|
+
internalType: "uint256",
|
|
14502
|
+
name: "amount",
|
|
14503
|
+
type: "uint256"
|
|
14504
|
+
}
|
|
14505
|
+
],
|
|
14506
|
+
internalType: "struct TokenPermissions[]",
|
|
14507
|
+
name: "permitted",
|
|
14508
|
+
type: "tuple[]"
|
|
14509
|
+
},
|
|
14510
|
+
{
|
|
14511
|
+
internalType: "uint256",
|
|
14512
|
+
name: "nonce",
|
|
14513
|
+
type: "uint256"
|
|
14514
|
+
},
|
|
14515
|
+
{
|
|
14516
|
+
internalType: "uint256",
|
|
14517
|
+
name: "deadline",
|
|
14518
|
+
type: "uint256"
|
|
14519
|
+
}
|
|
14520
|
+
],
|
|
14521
|
+
internalType: "struct PermitBatchTransferFrom",
|
|
14522
|
+
name: "_tokenDepositDetails",
|
|
14523
|
+
type: "tuple"
|
|
14524
|
+
},
|
|
14525
|
+
{
|
|
14526
|
+
components: [
|
|
14527
|
+
{
|
|
14528
|
+
internalType: "address",
|
|
14529
|
+
name: "recipient",
|
|
14530
|
+
type: "address"
|
|
14531
|
+
},
|
|
14532
|
+
{
|
|
14533
|
+
internalType: "address",
|
|
14534
|
+
name: "from",
|
|
14535
|
+
type: "address"
|
|
14536
|
+
},
|
|
14537
|
+
{
|
|
14538
|
+
internalType: "address",
|
|
14539
|
+
name: "to",
|
|
14540
|
+
type: "address"
|
|
14541
|
+
},
|
|
14542
|
+
{
|
|
14543
|
+
internalType: "uint256",
|
|
14544
|
+
name: "fromAmount",
|
|
14545
|
+
type: "uint256"
|
|
14546
|
+
},
|
|
14547
|
+
{
|
|
14548
|
+
internalType: "uint256",
|
|
14549
|
+
name: "minToAmount",
|
|
14550
|
+
type: "uint256"
|
|
14551
|
+
}
|
|
14552
|
+
],
|
|
14553
|
+
internalType: "struct SwapData[]",
|
|
14554
|
+
name: "_swapData",
|
|
14555
|
+
type: "tuple[]"
|
|
14556
|
+
},
|
|
14557
|
+
{
|
|
14558
|
+
components: [
|
|
14559
|
+
{
|
|
14560
|
+
internalType: "string",
|
|
14561
|
+
name: "dex",
|
|
14562
|
+
type: "string"
|
|
14563
|
+
},
|
|
14564
|
+
{
|
|
14565
|
+
internalType: "address",
|
|
14566
|
+
name: "callTo",
|
|
14567
|
+
type: "address"
|
|
14568
|
+
},
|
|
14569
|
+
{
|
|
14570
|
+
internalType: "address",
|
|
14571
|
+
name: "approveTo",
|
|
14572
|
+
type: "address"
|
|
14573
|
+
},
|
|
14574
|
+
{
|
|
14575
|
+
internalType: "bytes",
|
|
14576
|
+
name: "swapCallData",
|
|
14577
|
+
type: "bytes"
|
|
14578
|
+
},
|
|
14579
|
+
{
|
|
14580
|
+
internalType: "bool",
|
|
14581
|
+
name: "isDirectTransfer",
|
|
14582
|
+
type: "bool"
|
|
14583
|
+
}
|
|
14584
|
+
],
|
|
14585
|
+
internalType: "struct SwapExecutionData[]",
|
|
14586
|
+
name: "_swapExecutionData",
|
|
14587
|
+
type: "tuple[]"
|
|
14588
|
+
},
|
|
14589
|
+
{
|
|
14590
|
+
internalType: "bool",
|
|
14591
|
+
name: "withoutRevert",
|
|
14592
|
+
type: "bool"
|
|
14593
|
+
}
|
|
14594
|
+
],
|
|
14595
|
+
name: "swap",
|
|
14596
|
+
outputs: [],
|
|
14597
|
+
stateMutability: "payable",
|
|
14598
|
+
type: "function"
|
|
15011
14599
|
}
|
|
15012
|
-
|
|
15013
|
-
|
|
15014
|
-
|
|
15015
|
-
|
|
15016
|
-
|
|
15017
|
-
|
|
15018
|
-
|
|
15019
|
-
|
|
15020
|
-
|
|
15021
|
-
|
|
15022
|
-
|
|
15023
|
-
|
|
15024
|
-
|
|
15025
|
-
|
|
15026
|
-
|
|
15027
|
-
|
|
15028
|
-
|
|
15029
|
-
|
|
15030
|
-
|
|
15031
|
-
|
|
15032
|
-
|
|
15033
|
-
|
|
14600
|
+
],
|
|
14601
|
+
MultiSwapAbi: [
|
|
14602
|
+
{
|
|
14603
|
+
inputs: [
|
|
14604
|
+
{
|
|
14605
|
+
internalType: "bytes32",
|
|
14606
|
+
name: "_transactionId",
|
|
14607
|
+
type: "bytes32"
|
|
14608
|
+
},
|
|
14609
|
+
{
|
|
14610
|
+
internalType: "bytes",
|
|
14611
|
+
name: "_feeData",
|
|
14612
|
+
type: "bytes"
|
|
14613
|
+
},
|
|
14614
|
+
{
|
|
14615
|
+
internalType: "bytes",
|
|
14616
|
+
name: "_feeVerificationSignature",
|
|
14617
|
+
type: "bytes"
|
|
14618
|
+
},
|
|
14619
|
+
{
|
|
14620
|
+
internalType: "uint256",
|
|
14621
|
+
name: "_deadline",
|
|
14622
|
+
type: "uint256"
|
|
14623
|
+
},
|
|
14624
|
+
{
|
|
14625
|
+
components: [
|
|
14626
|
+
{
|
|
14627
|
+
internalType: "address",
|
|
14628
|
+
name: "token",
|
|
14629
|
+
type: "address"
|
|
14630
|
+
},
|
|
14631
|
+
{
|
|
14632
|
+
internalType: "uint256",
|
|
14633
|
+
name: "amount",
|
|
14634
|
+
type: "uint256"
|
|
14635
|
+
},
|
|
14636
|
+
{
|
|
14637
|
+
internalType: "bytes",
|
|
14638
|
+
name: "permit",
|
|
14639
|
+
type: "bytes"
|
|
14640
|
+
}
|
|
14641
|
+
],
|
|
14642
|
+
internalType: "struct InputToken[]",
|
|
14643
|
+
name: "_inputTokens",
|
|
14644
|
+
type: "tuple[]"
|
|
14645
|
+
},
|
|
14646
|
+
{
|
|
14647
|
+
components: [
|
|
14648
|
+
{
|
|
14649
|
+
internalType: "address",
|
|
14650
|
+
name: "recipient",
|
|
14651
|
+
type: "address"
|
|
14652
|
+
},
|
|
14653
|
+
{
|
|
14654
|
+
internalType: "address",
|
|
14655
|
+
name: "from",
|
|
14656
|
+
type: "address"
|
|
14657
|
+
},
|
|
14658
|
+
{
|
|
14659
|
+
internalType: "address",
|
|
14660
|
+
name: "to",
|
|
14661
|
+
type: "address"
|
|
14662
|
+
},
|
|
14663
|
+
{
|
|
14664
|
+
internalType: "uint256",
|
|
14665
|
+
name: "fromAmount",
|
|
14666
|
+
type: "uint256"
|
|
14667
|
+
},
|
|
14668
|
+
{
|
|
14669
|
+
internalType: "uint256",
|
|
14670
|
+
name: "minToAmount",
|
|
14671
|
+
type: "uint256"
|
|
14672
|
+
}
|
|
14673
|
+
],
|
|
14674
|
+
internalType: "struct SwapData[]",
|
|
14675
|
+
name: "_swapData",
|
|
14676
|
+
type: "tuple[]"
|
|
14677
|
+
},
|
|
14678
|
+
{
|
|
14679
|
+
components: [
|
|
14680
|
+
{
|
|
14681
|
+
internalType: "string",
|
|
14682
|
+
name: "dex",
|
|
14683
|
+
type: "string"
|
|
14684
|
+
},
|
|
14685
|
+
{
|
|
14686
|
+
internalType: "address",
|
|
14687
|
+
name: "callTo",
|
|
14688
|
+
type: "address"
|
|
14689
|
+
},
|
|
14690
|
+
{
|
|
14691
|
+
internalType: "address",
|
|
14692
|
+
name: "approveTo",
|
|
14693
|
+
type: "address"
|
|
14694
|
+
},
|
|
14695
|
+
{
|
|
14696
|
+
internalType: "bytes",
|
|
14697
|
+
name: "swapCallData",
|
|
14698
|
+
type: "bytes"
|
|
14699
|
+
},
|
|
14700
|
+
{
|
|
14701
|
+
internalType: "bool",
|
|
14702
|
+
name: "isDirectTransfer",
|
|
14703
|
+
type: "bool"
|
|
14704
|
+
}
|
|
14705
|
+
],
|
|
14706
|
+
internalType: "struct SwapExecutionData[]",
|
|
14707
|
+
name: "_swapExecutionData",
|
|
14708
|
+
type: "tuple[]"
|
|
14709
|
+
},
|
|
14710
|
+
{
|
|
14711
|
+
internalType: "bool",
|
|
14712
|
+
name: "withoutRevert",
|
|
14713
|
+
type: "bool"
|
|
14714
|
+
}
|
|
14715
|
+
],
|
|
14716
|
+
name: "swap",
|
|
14717
|
+
outputs: [],
|
|
14718
|
+
stateMutability: "payable",
|
|
14719
|
+
type: "function"
|
|
15034
14720
|
}
|
|
15035
|
-
|
|
15036
|
-
|
|
15037
|
-
|
|
15038
|
-
|
|
15039
|
-
|
|
15040
|
-
|
|
15041
|
-
|
|
15042
|
-
|
|
15043
|
-
}
|
|
15044
|
-
|
|
15045
|
-
|
|
15046
|
-
|
|
15047
|
-
|
|
15048
|
-
|
|
15049
|
-
|
|
15050
|
-
|
|
15051
|
-
|
|
15052
|
-
|
|
15053
|
-
|
|
15054
|
-
|
|
15055
|
-
|
|
15056
|
-
|
|
15057
|
-
|
|
15058
|
-
|
|
15059
|
-
|
|
15060
|
-
|
|
15061
|
-
|
|
15062
|
-
|
|
15063
|
-
|
|
15064
|
-
|
|
15065
|
-
|
|
15066
|
-
|
|
15067
|
-
|
|
15068
|
-
}
|
|
15069
|
-
|
|
15070
|
-
|
|
15071
|
-
|
|
15072
|
-
|
|
15073
|
-
|
|
15074
|
-
|
|
15075
|
-
|
|
15076
|
-
|
|
15077
|
-
|
|
15078
|
-
|
|
15079
|
-
|
|
15080
|
-
|
|
15081
|
-
|
|
15082
|
-
|
|
15083
|
-
|
|
15084
|
-
|
|
15085
|
-
|
|
15086
|
-
|
|
15087
|
-
|
|
14721
|
+
],
|
|
14722
|
+
GaslessExecuteMultiSwapAbi: [
|
|
14723
|
+
{
|
|
14724
|
+
inputs: [
|
|
14725
|
+
{
|
|
14726
|
+
internalType: "bytes32",
|
|
14727
|
+
name: "_transactionId",
|
|
14728
|
+
type: "bytes32"
|
|
14729
|
+
},
|
|
14730
|
+
{
|
|
14731
|
+
internalType: "bytes",
|
|
14732
|
+
name: "_feeData",
|
|
14733
|
+
type: "bytes"
|
|
14734
|
+
},
|
|
14735
|
+
{
|
|
14736
|
+
internalType: "bytes",
|
|
14737
|
+
name: "_feeVerificationSignature",
|
|
14738
|
+
type: "bytes"
|
|
14739
|
+
},
|
|
14740
|
+
{
|
|
14741
|
+
internalType: "bytes",
|
|
14742
|
+
name: "_userIntentSignature",
|
|
14743
|
+
type: "bytes"
|
|
14744
|
+
},
|
|
14745
|
+
{
|
|
14746
|
+
internalType: "uint256",
|
|
14747
|
+
name: "_userIntentDeadline",
|
|
14748
|
+
type: "uint256"
|
|
14749
|
+
},
|
|
14750
|
+
{
|
|
14751
|
+
internalType: "uint256",
|
|
14752
|
+
name: "_feeDeadline",
|
|
14753
|
+
type: "uint256"
|
|
14754
|
+
},
|
|
14755
|
+
{
|
|
14756
|
+
internalType: "address",
|
|
14757
|
+
name: "_user",
|
|
14758
|
+
type: "address"
|
|
14759
|
+
},
|
|
14760
|
+
{
|
|
14761
|
+
components: [
|
|
14762
|
+
{
|
|
14763
|
+
internalType: "address",
|
|
14764
|
+
name: "token",
|
|
14765
|
+
type: "address"
|
|
14766
|
+
},
|
|
14767
|
+
{
|
|
14768
|
+
internalType: "uint256",
|
|
14769
|
+
name: "amount",
|
|
14770
|
+
type: "uint256"
|
|
14771
|
+
},
|
|
14772
|
+
{
|
|
14773
|
+
internalType: "bytes",
|
|
14774
|
+
name: "permit",
|
|
14775
|
+
type: "bytes"
|
|
14776
|
+
}
|
|
14777
|
+
],
|
|
14778
|
+
internalType: "struct InputToken[]",
|
|
14779
|
+
name: "_inputTokens",
|
|
14780
|
+
type: "tuple[]"
|
|
14781
|
+
},
|
|
14782
|
+
{
|
|
14783
|
+
components: [
|
|
14784
|
+
{
|
|
14785
|
+
internalType: "address",
|
|
14786
|
+
name: "token",
|
|
14787
|
+
type: "address"
|
|
14788
|
+
},
|
|
14789
|
+
{
|
|
14790
|
+
internalType: "uint256",
|
|
14791
|
+
name: "amount",
|
|
14792
|
+
type: "uint256"
|
|
14793
|
+
}
|
|
14794
|
+
],
|
|
14795
|
+
internalType: "struct TokenInfo[]",
|
|
14796
|
+
name: "_executorFeeInfo",
|
|
14797
|
+
type: "tuple[]"
|
|
14798
|
+
},
|
|
14799
|
+
{
|
|
14800
|
+
components: [
|
|
14801
|
+
{
|
|
14802
|
+
internalType: "address",
|
|
14803
|
+
name: "recipient",
|
|
14804
|
+
type: "address"
|
|
14805
|
+
},
|
|
14806
|
+
{
|
|
14807
|
+
internalType: "address",
|
|
14808
|
+
name: "from",
|
|
14809
|
+
type: "address"
|
|
14810
|
+
},
|
|
14811
|
+
{
|
|
14812
|
+
internalType: "address",
|
|
14813
|
+
name: "to",
|
|
14814
|
+
type: "address"
|
|
14815
|
+
},
|
|
14816
|
+
{
|
|
14817
|
+
internalType: "uint256",
|
|
14818
|
+
name: "fromAmount",
|
|
14819
|
+
type: "uint256"
|
|
14820
|
+
},
|
|
14821
|
+
{
|
|
14822
|
+
internalType: "uint256",
|
|
14823
|
+
name: "minToAmount",
|
|
14824
|
+
type: "uint256"
|
|
14825
|
+
}
|
|
14826
|
+
],
|
|
14827
|
+
internalType: "struct SwapData[]",
|
|
14828
|
+
name: "_swapData",
|
|
14829
|
+
type: "tuple[]"
|
|
14830
|
+
},
|
|
14831
|
+
{
|
|
14832
|
+
components: [
|
|
14833
|
+
{
|
|
14834
|
+
internalType: "string",
|
|
14835
|
+
name: "dex",
|
|
14836
|
+
type: "string"
|
|
14837
|
+
},
|
|
14838
|
+
{
|
|
14839
|
+
internalType: "address",
|
|
14840
|
+
name: "callTo",
|
|
14841
|
+
type: "address"
|
|
14842
|
+
},
|
|
14843
|
+
{
|
|
14844
|
+
internalType: "address",
|
|
14845
|
+
name: "approveTo",
|
|
14846
|
+
type: "address"
|
|
14847
|
+
},
|
|
14848
|
+
{
|
|
14849
|
+
internalType: "bytes",
|
|
14850
|
+
name: "swapCallData",
|
|
14851
|
+
type: "bytes"
|
|
14852
|
+
},
|
|
14853
|
+
{
|
|
14854
|
+
internalType: "bool",
|
|
14855
|
+
name: "isDirectTransfer",
|
|
14856
|
+
type: "bool"
|
|
14857
|
+
}
|
|
14858
|
+
],
|
|
14859
|
+
internalType: "struct SwapExecutionData[]",
|
|
14860
|
+
name: "_swapExecutionData",
|
|
14861
|
+
type: "tuple[]"
|
|
14862
|
+
}
|
|
14863
|
+
],
|
|
14864
|
+
name: "executeMultiSwap",
|
|
14865
|
+
outputs: [],
|
|
14866
|
+
stateMutability: "payable",
|
|
14867
|
+
type: "function"
|
|
15088
14868
|
}
|
|
15089
|
-
|
|
15090
|
-
|
|
15091
|
-
|
|
15092
|
-
|
|
15093
|
-
|
|
15094
|
-
|
|
15095
|
-
|
|
15096
|
-
|
|
15097
|
-
|
|
15098
|
-
|
|
15099
|
-
|
|
15100
|
-
|
|
15101
|
-
|
|
15102
|
-
|
|
15103
|
-
|
|
15104
|
-
|
|
15105
|
-
|
|
15106
|
-
|
|
15107
|
-
|
|
14869
|
+
],
|
|
14870
|
+
GaslessExecuteMultiSwapWithWitnessAbi: [
|
|
14871
|
+
{
|
|
14872
|
+
inputs: [
|
|
14873
|
+
{
|
|
14874
|
+
internalType: "bytes32",
|
|
14875
|
+
name: "_transactionId",
|
|
14876
|
+
type: "bytes32"
|
|
14877
|
+
},
|
|
14878
|
+
{
|
|
14879
|
+
internalType: "bytes",
|
|
14880
|
+
name: "_feeData",
|
|
14881
|
+
type: "bytes"
|
|
14882
|
+
},
|
|
14883
|
+
{
|
|
14884
|
+
internalType: "bytes",
|
|
14885
|
+
name: "_feeVerificationSignature",
|
|
14886
|
+
type: "bytes"
|
|
14887
|
+
},
|
|
14888
|
+
{
|
|
14889
|
+
internalType: "bytes",
|
|
14890
|
+
name: "_userIntentSignature",
|
|
14891
|
+
type: "bytes"
|
|
14892
|
+
},
|
|
14893
|
+
{
|
|
14894
|
+
internalType: "uint256",
|
|
14895
|
+
name: "_feeDeadline",
|
|
14896
|
+
type: "uint256"
|
|
14897
|
+
},
|
|
14898
|
+
{
|
|
14899
|
+
internalType: "address",
|
|
14900
|
+
name: "_user",
|
|
14901
|
+
type: "address"
|
|
14902
|
+
},
|
|
14903
|
+
{
|
|
14904
|
+
components: [
|
|
14905
|
+
{
|
|
14906
|
+
components: [
|
|
14907
|
+
{
|
|
14908
|
+
internalType: "address",
|
|
14909
|
+
name: "token",
|
|
14910
|
+
type: "address"
|
|
14911
|
+
},
|
|
14912
|
+
{
|
|
14913
|
+
internalType: "uint256",
|
|
14914
|
+
name: "amount",
|
|
14915
|
+
type: "uint256"
|
|
14916
|
+
}
|
|
14917
|
+
],
|
|
14918
|
+
internalType: "struct TokenPermissions[]",
|
|
14919
|
+
name: "permitted",
|
|
14920
|
+
type: "tuple[]"
|
|
14921
|
+
},
|
|
14922
|
+
{
|
|
14923
|
+
internalType: "uint256",
|
|
14924
|
+
name: "nonce",
|
|
14925
|
+
type: "uint256"
|
|
14926
|
+
},
|
|
14927
|
+
{
|
|
14928
|
+
internalType: "uint256",
|
|
14929
|
+
name: "deadline",
|
|
14930
|
+
type: "uint256"
|
|
14931
|
+
}
|
|
14932
|
+
],
|
|
14933
|
+
internalType: "struct PermitBatchTransferFrom",
|
|
14934
|
+
name: "_tokenDepositDetails",
|
|
14935
|
+
type: "tuple"
|
|
14936
|
+
},
|
|
14937
|
+
{
|
|
14938
|
+
components: [
|
|
14939
|
+
{
|
|
14940
|
+
internalType: "address",
|
|
14941
|
+
name: "token",
|
|
14942
|
+
type: "address"
|
|
14943
|
+
},
|
|
14944
|
+
{
|
|
14945
|
+
internalType: "uint256",
|
|
14946
|
+
name: "amount",
|
|
14947
|
+
type: "uint256"
|
|
14948
|
+
}
|
|
14949
|
+
],
|
|
14950
|
+
internalType: "struct TokenInfo[]",
|
|
14951
|
+
name: "_executorFeeInfo",
|
|
14952
|
+
type: "tuple[]"
|
|
14953
|
+
},
|
|
14954
|
+
{
|
|
14955
|
+
components: [
|
|
14956
|
+
{
|
|
14957
|
+
internalType: "address",
|
|
14958
|
+
name: "recipient",
|
|
14959
|
+
type: "address"
|
|
14960
|
+
},
|
|
14961
|
+
{
|
|
14962
|
+
internalType: "address",
|
|
14963
|
+
name: "from",
|
|
14964
|
+
type: "address"
|
|
14965
|
+
},
|
|
14966
|
+
{
|
|
14967
|
+
internalType: "address",
|
|
14968
|
+
name: "to",
|
|
14969
|
+
type: "address"
|
|
14970
|
+
},
|
|
14971
|
+
{
|
|
14972
|
+
internalType: "uint256",
|
|
14973
|
+
name: "fromAmount",
|
|
14974
|
+
type: "uint256"
|
|
14975
|
+
},
|
|
14976
|
+
{
|
|
14977
|
+
internalType: "uint256",
|
|
14978
|
+
name: "minToAmount",
|
|
14979
|
+
type: "uint256"
|
|
14980
|
+
}
|
|
14981
|
+
],
|
|
14982
|
+
internalType: "struct SwapData[]",
|
|
14983
|
+
name: "_swapData",
|
|
14984
|
+
type: "tuple[]"
|
|
14985
|
+
},
|
|
14986
|
+
{
|
|
14987
|
+
components: [
|
|
14988
|
+
{
|
|
14989
|
+
internalType: "string",
|
|
14990
|
+
name: "dex",
|
|
14991
|
+
type: "string"
|
|
14992
|
+
},
|
|
14993
|
+
{
|
|
14994
|
+
internalType: "address",
|
|
14995
|
+
name: "callTo",
|
|
14996
|
+
type: "address"
|
|
14997
|
+
},
|
|
14998
|
+
{
|
|
14999
|
+
internalType: "address",
|
|
15000
|
+
name: "approveTo",
|
|
15001
|
+
type: "address"
|
|
15002
|
+
},
|
|
15003
|
+
{
|
|
15004
|
+
internalType: "bytes",
|
|
15005
|
+
name: "swapCallData",
|
|
15006
|
+
type: "bytes"
|
|
15007
|
+
},
|
|
15008
|
+
{
|
|
15009
|
+
internalType: "bool",
|
|
15010
|
+
name: "isDirectTransfer",
|
|
15011
|
+
type: "bool"
|
|
15012
|
+
}
|
|
15013
|
+
],
|
|
15014
|
+
internalType: "struct SwapExecutionData[]",
|
|
15015
|
+
name: "_swapExecutionData",
|
|
15016
|
+
type: "tuple[]"
|
|
15017
|
+
}
|
|
15018
|
+
],
|
|
15019
|
+
name: "executeMultiSwapWithWitness",
|
|
15020
|
+
outputs: [],
|
|
15021
|
+
stateMutability: "payable",
|
|
15022
|
+
type: "function"
|
|
15023
|
+
}
|
|
15024
|
+
],
|
|
15025
|
+
GaslessExecuteSwapAbi: [
|
|
15026
|
+
{
|
|
15027
|
+
inputs: [
|
|
15028
|
+
{
|
|
15029
|
+
internalType: "bytes32",
|
|
15030
|
+
name: "_transactionId",
|
|
15031
|
+
type: "bytes32"
|
|
15032
|
+
},
|
|
15033
|
+
{
|
|
15034
|
+
internalType: "bytes",
|
|
15035
|
+
name: "_feeData",
|
|
15036
|
+
type: "bytes"
|
|
15037
|
+
},
|
|
15038
|
+
{
|
|
15039
|
+
internalType: "bytes",
|
|
15040
|
+
name: "_feeVerificationSignature",
|
|
15041
|
+
type: "bytes"
|
|
15042
|
+
},
|
|
15043
|
+
{
|
|
15044
|
+
internalType: "bytes",
|
|
15045
|
+
name: "_userIntentSignature",
|
|
15046
|
+
type: "bytes"
|
|
15047
|
+
},
|
|
15048
|
+
{
|
|
15049
|
+
internalType: "uint256",
|
|
15050
|
+
name: "_userIntentDeadline",
|
|
15051
|
+
type: "uint256"
|
|
15052
|
+
},
|
|
15053
|
+
{
|
|
15054
|
+
internalType: "uint256",
|
|
15055
|
+
name: "_feeDeadline",
|
|
15056
|
+
type: "uint256"
|
|
15057
|
+
},
|
|
15058
|
+
{
|
|
15059
|
+
internalType: "address",
|
|
15060
|
+
name: "_user",
|
|
15061
|
+
type: "address"
|
|
15062
|
+
},
|
|
15063
|
+
{
|
|
15064
|
+
components: [
|
|
15065
|
+
{
|
|
15066
|
+
internalType: "address",
|
|
15067
|
+
name: "token",
|
|
15068
|
+
type: "address"
|
|
15069
|
+
},
|
|
15070
|
+
{
|
|
15071
|
+
internalType: "uint256",
|
|
15072
|
+
name: "amount",
|
|
15073
|
+
type: "uint256"
|
|
15074
|
+
},
|
|
15075
|
+
{
|
|
15076
|
+
internalType: "bytes",
|
|
15077
|
+
name: "permit",
|
|
15078
|
+
type: "bytes"
|
|
15079
|
+
}
|
|
15080
|
+
],
|
|
15081
|
+
internalType: "struct InputToken",
|
|
15082
|
+
name: "_inputToken",
|
|
15083
|
+
type: "tuple"
|
|
15084
|
+
},
|
|
15085
|
+
{
|
|
15086
|
+
components: [
|
|
15087
|
+
{
|
|
15088
|
+
internalType: "address",
|
|
15089
|
+
name: "token",
|
|
15090
|
+
type: "address"
|
|
15091
|
+
},
|
|
15092
|
+
{
|
|
15093
|
+
internalType: "uint256",
|
|
15094
|
+
name: "amount",
|
|
15095
|
+
type: "uint256"
|
|
15096
|
+
}
|
|
15097
|
+
],
|
|
15098
|
+
internalType: "struct TokenInfo",
|
|
15099
|
+
name: "_executorFeeInfo",
|
|
15100
|
+
type: "tuple"
|
|
15101
|
+
},
|
|
15102
|
+
{
|
|
15103
|
+
components: [
|
|
15104
|
+
{
|
|
15105
|
+
internalType: "address",
|
|
15106
|
+
name: "recipient",
|
|
15107
|
+
type: "address"
|
|
15108
|
+
},
|
|
15109
|
+
{
|
|
15110
|
+
internalType: "address",
|
|
15111
|
+
name: "from",
|
|
15112
|
+
type: "address"
|
|
15113
|
+
},
|
|
15114
|
+
{
|
|
15115
|
+
internalType: "address",
|
|
15116
|
+
name: "to",
|
|
15117
|
+
type: "address"
|
|
15118
|
+
},
|
|
15119
|
+
{
|
|
15120
|
+
internalType: "uint256",
|
|
15121
|
+
name: "fromAmount",
|
|
15122
|
+
type: "uint256"
|
|
15123
|
+
},
|
|
15124
|
+
{
|
|
15125
|
+
internalType: "uint256",
|
|
15126
|
+
name: "minToAmount",
|
|
15127
|
+
type: "uint256"
|
|
15128
|
+
}
|
|
15129
|
+
],
|
|
15130
|
+
internalType: "struct SwapData",
|
|
15131
|
+
name: "_swapData",
|
|
15132
|
+
type: "tuple"
|
|
15133
|
+
},
|
|
15134
|
+
{
|
|
15135
|
+
components: [
|
|
15136
|
+
{
|
|
15137
|
+
internalType: "string",
|
|
15138
|
+
name: "dex",
|
|
15139
|
+
type: "string"
|
|
15140
|
+
},
|
|
15141
|
+
{
|
|
15142
|
+
internalType: "address",
|
|
15143
|
+
name: "callTo",
|
|
15144
|
+
type: "address"
|
|
15145
|
+
},
|
|
15146
|
+
{
|
|
15147
|
+
internalType: "address",
|
|
15148
|
+
name: "approveTo",
|
|
15149
|
+
type: "address"
|
|
15150
|
+
},
|
|
15151
|
+
{
|
|
15152
|
+
internalType: "bytes",
|
|
15153
|
+
name: "swapCallData",
|
|
15154
|
+
type: "bytes"
|
|
15155
|
+
},
|
|
15156
|
+
{
|
|
15157
|
+
internalType: "bool",
|
|
15158
|
+
name: "isDirectTransfer",
|
|
15159
|
+
type: "bool"
|
|
15160
|
+
}
|
|
15161
|
+
],
|
|
15162
|
+
internalType: "struct SwapExecutionData",
|
|
15163
|
+
name: "_swapExecutionData",
|
|
15164
|
+
type: "tuple"
|
|
15165
|
+
}
|
|
15166
|
+
],
|
|
15167
|
+
name: "executeSwap",
|
|
15168
|
+
outputs: [],
|
|
15169
|
+
stateMutability: "payable",
|
|
15170
|
+
type: "function"
|
|
15108
15171
|
}
|
|
15109
|
-
|
|
15110
|
-
}
|
|
15172
|
+
]
|
|
15111
15173
|
};
|
|
15112
|
-
var TradeTxnHandler = _TradeTxnHandler;
|
|
15113
|
-
var trade_default = TradeTxnHandler;
|
|
15114
15174
|
|
|
15115
|
-
// src/
|
|
15116
|
-
var
|
|
15117
|
-
|
|
15175
|
+
// src/utils/decoder/swap/evm.ts
|
|
15176
|
+
var decodeSingleSwapData = (data) => {
|
|
15177
|
+
var _a;
|
|
15178
|
+
const decodedData = decodeFunctionData({ data, abi: SwapAbisByFunctionName.SingleSwap });
|
|
15179
|
+
return [(_a = decodedData == null ? void 0 : decodedData.args) == null ? void 0 : _a[4]];
|
|
15180
|
+
};
|
|
15181
|
+
var decodeMultiSwapData = (data) => {
|
|
15182
|
+
var _a;
|
|
15183
|
+
const decodedData = decodeFunctionData({ data, abi: SwapAbisByFunctionName.MultiSwapAbi });
|
|
15184
|
+
return (_a = decodedData == null ? void 0 : decodedData.args) == null ? void 0 : _a[4];
|
|
15185
|
+
};
|
|
15186
|
+
var decodeBatchPermitSwapData = (data) => {
|
|
15187
|
+
var _a, _b;
|
|
15188
|
+
const decodedData = decodeFunctionData({ data, abi: SwapAbisByFunctionName.BatchPermitSwapAbi });
|
|
15189
|
+
return (_b = (_a = decodedData == null ? void 0 : decodedData.args) == null ? void 0 : _a[5]) == null ? void 0 : _b.permitted;
|
|
15190
|
+
};
|
|
15191
|
+
var decodeGaslessExecuteMultiSwapData = (data) => {
|
|
15192
|
+
var _a;
|
|
15193
|
+
const decodedData = decodeFunctionData({ data, abi: SwapAbisByFunctionName.GaslessExecuteMultiSwapAbi });
|
|
15194
|
+
return (_a = decodedData == null ? void 0 : decodedData.args) == null ? void 0 : _a[7];
|
|
15195
|
+
};
|
|
15196
|
+
var decodeGaslessExecuteMultiSwapWithWitnessData = (data) => {
|
|
15197
|
+
var _a;
|
|
15198
|
+
const decodedData = decodeFunctionData({ data, abi: SwapAbisByFunctionName.GaslessExecuteMultiSwapWithWitnessAbi });
|
|
15199
|
+
return (_a = decodedData == null ? void 0 : decodedData.args) == null ? void 0 : _a[7];
|
|
15200
|
+
};
|
|
15201
|
+
var decodeGaslessExecuteSwapData = (data) => {
|
|
15202
|
+
var _a;
|
|
15203
|
+
const decodedData = decodeFunctionData({ data, abi: SwapAbisByFunctionName.GaslessExecuteSwapAbi });
|
|
15204
|
+
return [(_a = decodedData == null ? void 0 : decodedData.args) == null ? void 0 : _a[7]];
|
|
15205
|
+
};
|
|
15206
|
+
var swapFunctionSignatureWithInputTokenIndex = {
|
|
15207
|
+
"0x50d52584": decodeSingleSwapData,
|
|
15208
|
+
"0x8de34776": decodeMultiSwapData,
|
|
15209
|
+
"0x8d44ea24": decodeBatchPermitSwapData,
|
|
15210
|
+
"0xd367ada5": decodeGaslessExecuteMultiSwapData,
|
|
15211
|
+
"0xdcdc6089": decodeGaslessExecuteMultiSwapWithWitnessData,
|
|
15212
|
+
"0x0d2eedd4": decodeGaslessExecuteSwapData
|
|
15213
|
+
};
|
|
15214
|
+
var decodeEvmTransaction = async ({ txHash, chainId, rpcUrls }) => {
|
|
15215
|
+
const { input } = await getPublicClient({ chainId, rpcUrls }).getTransaction({ hash: txHash });
|
|
15216
|
+
const decoder = swapFunctionSignatureWithInputTokenIndex[input.slice(0, 10)];
|
|
15217
|
+
if (!decoder) {
|
|
15218
|
+
return void 0;
|
|
15219
|
+
}
|
|
15220
|
+
const sent = decoder(input).filter((item) => (item == null ? void 0 : item.token) && (item == null ? void 0 : item.amount));
|
|
15221
|
+
if (sent.length === 0) {
|
|
15222
|
+
return void 0;
|
|
15223
|
+
}
|
|
15224
|
+
return { sent };
|
|
15118
15225
|
};
|
|
15119
15226
|
|
|
15120
|
-
// src/
|
|
15121
|
-
var
|
|
15227
|
+
// src/utils/decoder/swap/index.ts
|
|
15228
|
+
var transactionDecoders = {
|
|
15229
|
+
[chainTypes.evm]: decodeEvmTransaction,
|
|
15230
|
+
[chainTypes.svm]: decodeSvmTransaction,
|
|
15231
|
+
[chainTypes.suivm]: decodeSuivmTransaction
|
|
15122
15232
|
};
|
|
15123
|
-
|
|
15233
|
+
var amountByToken = (tokenAmounts) => tokenAmounts.reduce(
|
|
15234
|
+
(acc, cur) => {
|
|
15235
|
+
const token = formatToken(cur.token);
|
|
15236
|
+
acc[token] = (acc[token] ?? BigInt(0)) + cur.amount;
|
|
15237
|
+
return acc;
|
|
15238
|
+
},
|
|
15239
|
+
{}
|
|
15240
|
+
);
|
|
15241
|
+
var swapCountByToken = (tokens) => tokens.reduce(
|
|
15242
|
+
(acc, cur) => {
|
|
15243
|
+
const token = formatToken(cur);
|
|
15244
|
+
acc[token] = (acc[token] ?? 0) + 1;
|
|
15245
|
+
return acc;
|
|
15246
|
+
},
|
|
15247
|
+
{}
|
|
15248
|
+
);
|
|
15249
|
+
var applyTxTokenAmounts = (eventSwapInfo, txTokenAmounts) => {
|
|
15250
|
+
const swaps = Array.isArray(eventSwapInfo) ? eventSwapInfo : [eventSwapInfo];
|
|
15251
|
+
const sentByToken = amountByToken(txTokenAmounts.sent);
|
|
15252
|
+
const receivedByToken = amountByToken(txTokenAmounts.received ?? []);
|
|
15253
|
+
const swapsByFromToken = swapCountByToken(swaps.map((info) => info.fromToken));
|
|
15254
|
+
const swapsByToToken = swapCountByToken(swaps.map((info) => info.toToken));
|
|
15255
|
+
const amountOf = (amounts, swapCounts, token) => swapCounts[formatToken(token)] === 1 ? amounts[formatToken(token)] : void 0;
|
|
15256
|
+
let isAmountPatched = false;
|
|
15257
|
+
const patch = (info) => {
|
|
15258
|
+
const fromAmount = amountOf(sentByToken, swapsByFromToken, info.fromToken);
|
|
15259
|
+
const returnToAmount = amountOf(receivedByToken, swapsByToToken, info.toToken);
|
|
15260
|
+
isAmountPatched = isAmountPatched || fromAmount !== void 0 || returnToAmount !== void 0;
|
|
15261
|
+
return { ...info, fromAmount: fromAmount ?? info.fromAmount, returnToAmount: returnToAmount ?? info.returnToAmount };
|
|
15262
|
+
};
|
|
15263
|
+
const swapInfo = Array.isArray(eventSwapInfo) ? eventSwapInfo.map(patch) : patch(eventSwapInfo);
|
|
15264
|
+
return isAmountPatched ? { swapInfo, isAmountPatched } : { swapInfo, isAmountPatched, amountPatchError: "no token amount of the transaction matched a swap token" };
|
|
15265
|
+
};
|
|
15266
|
+
var patchSwapAmountsFromTx = async ({
|
|
15267
|
+
chainType,
|
|
15124
15268
|
chainId,
|
|
15125
|
-
|
|
15126
|
-
|
|
15269
|
+
txHash,
|
|
15270
|
+
rpcUrls,
|
|
15271
|
+
eventSwapInfo
|
|
15127
15272
|
}) => {
|
|
15128
|
-
|
|
15273
|
+
const decodeTransaction = transactionDecoders[chainType];
|
|
15274
|
+
if (!decodeTransaction) {
|
|
15275
|
+
return { swapInfo: eventSwapInfo, isAmountPatched: false, amountPatchError: `decoding ${chainType} transactions is not supported` };
|
|
15276
|
+
}
|
|
15129
15277
|
try {
|
|
15130
|
-
const {
|
|
15131
|
-
if (
|
|
15132
|
-
|
|
15133
|
-
const from = await signer.getAddress();
|
|
15134
|
-
const txnRes = await signer.sendTransaction({
|
|
15135
|
-
from,
|
|
15136
|
-
to: callTo,
|
|
15137
|
-
data: callData,
|
|
15138
|
-
value: BigInt(value),
|
|
15139
|
-
gasLimit: BigInt(estimatedGas) ? BigInt(estimatedGas) : void 0
|
|
15140
|
-
});
|
|
15141
|
-
return {
|
|
15142
|
-
status: "success" /* success */,
|
|
15143
|
-
code: 200 /* Success */,
|
|
15144
|
-
txnHash: txnRes.hash
|
|
15145
|
-
};
|
|
15146
|
-
} else {
|
|
15147
|
-
console.log("Using viem walletClient.");
|
|
15148
|
-
const txnHash = await signer.sendTransaction({
|
|
15149
|
-
chain: viemChainsById[chainId],
|
|
15150
|
-
account: (_a = signer.account) == null ? void 0 : _a.address,
|
|
15151
|
-
to: txnData.callTo,
|
|
15152
|
-
data: txnData.callData,
|
|
15153
|
-
value: BigInt(txnData.value)
|
|
15154
|
-
});
|
|
15155
|
-
return {
|
|
15156
|
-
status: "success" /* success */,
|
|
15157
|
-
code: 200 /* Success */,
|
|
15158
|
-
txnHash
|
|
15159
|
-
};
|
|
15278
|
+
const txTokenAmounts = await decodeTransaction({ txHash, chainId, rpcUrls: rpcUrls ?? config.getRpcUrlsByChainId(chainId) });
|
|
15279
|
+
if (!txTokenAmounts) {
|
|
15280
|
+
return { swapInfo: eventSwapInfo, isAmountPatched: false, amountPatchError: `no token amounts could be decoded from transaction ${txHash}` };
|
|
15160
15281
|
}
|
|
15282
|
+
return applyTxTokenAmounts(eventSwapInfo, txTokenAmounts);
|
|
15161
15283
|
} catch (error) {
|
|
15162
|
-
|
|
15163
|
-
return handleViemTransactionError({ error });
|
|
15284
|
+
return { swapInfo: eventSwapInfo, isAmountPatched: false, amountPatchError: error instanceof Error ? error.message : String(error) };
|
|
15164
15285
|
}
|
|
15165
15286
|
};
|
|
15166
|
-
|
|
15167
|
-
|
|
15287
|
+
|
|
15288
|
+
// src/utils/decoder/index.ts
|
|
15289
|
+
var formatSwapInfoTokens = (info, chain) => {
|
|
15290
|
+
var _a, _b;
|
|
15291
|
+
return {
|
|
15292
|
+
...info,
|
|
15293
|
+
fromToken: formatToken(info.fromToken, (_a = chain == null ? void 0 : chain.nativeToken) == null ? void 0 : _a.contract),
|
|
15294
|
+
toToken: formatToken(info.toToken, (_b = chain == null ? void 0 : chain.nativeToken) == null ? void 0 : _b.contract)
|
|
15295
|
+
};
|
|
15296
|
+
};
|
|
15297
|
+
var getTxReceipt = async ({ chainId, txHash, rpcUrls }) => {
|
|
15298
|
+
return getPublicClient({ chainId, rpcUrls }).getTransactionReceipt({ hash: txHash });
|
|
15299
|
+
};
|
|
15300
|
+
var decodeSwapInfoFromReceipt = async ({
|
|
15301
|
+
txReceipt,
|
|
15302
|
+
service,
|
|
15303
|
+
chain
|
|
15304
|
+
}) => {
|
|
15305
|
+
var _a, _b;
|
|
15306
|
+
let events = [];
|
|
15307
|
+
const dZapAbi = getDZapAbi(service, (chain == null ? void 0 : chain.version) || "v1" /* v1 */);
|
|
15168
15308
|
try {
|
|
15169
|
-
|
|
15170
|
-
|
|
15171
|
-
|
|
15172
|
-
console.log("block Number and data");
|
|
15173
|
-
console.dir(
|
|
15174
|
-
{
|
|
15175
|
-
blockNumber,
|
|
15176
|
-
...data
|
|
15177
|
-
},
|
|
15178
|
-
{ depth: null }
|
|
15179
|
-
);
|
|
15180
|
-
if (isTypeSigner(signer)) {
|
|
15181
|
-
console.log("Using ethers signer.");
|
|
15182
|
-
const from = await signer.getAddress();
|
|
15183
|
-
const txnRes = await signer.sendTransaction({
|
|
15184
|
-
from,
|
|
15185
|
-
to: callTo,
|
|
15186
|
-
data: callData,
|
|
15187
|
-
value: BigInt(value),
|
|
15188
|
-
gasLimit: BigInt(estimatedGas) ? BigInt(estimatedGas) : void 0
|
|
15189
|
-
});
|
|
15190
|
-
return {
|
|
15191
|
-
status: "success" /* success */,
|
|
15192
|
-
code: 200 /* Success */,
|
|
15193
|
-
txnHash: txnRes.hash
|
|
15194
|
-
};
|
|
15195
|
-
} else {
|
|
15196
|
-
console.log("Using viem walletClient.");
|
|
15197
|
-
const txnHash = await signer.sendTransaction({
|
|
15198
|
-
chain: viemChainsById[chainId],
|
|
15199
|
-
account: (_a = signer.account) == null ? void 0 : _a.address,
|
|
15200
|
-
to: data.callTo,
|
|
15201
|
-
data: data.callData,
|
|
15202
|
-
value: BigInt(data.value)
|
|
15203
|
-
});
|
|
15204
|
-
return {
|
|
15205
|
-
status: "success" /* success */,
|
|
15206
|
-
code: 200 /* Success */,
|
|
15207
|
-
txnHash
|
|
15208
|
-
};
|
|
15209
|
-
}
|
|
15210
|
-
} catch (error) {
|
|
15211
|
-
console.log({ error });
|
|
15212
|
-
return handleViemTransactionError({ error });
|
|
15309
|
+
events = parseEventLogs({ abi: dZapAbi, logs: txReceipt.logs });
|
|
15310
|
+
} catch {
|
|
15311
|
+
events = [];
|
|
15213
15312
|
}
|
|
15313
|
+
const eventSwapInfo = (_b = (_a = events == null ? void 0 : events.find((item) => item !== null)) == null ? void 0 : _a.args) == null ? void 0 : _b.swapInfo;
|
|
15314
|
+
let swapInfo = [];
|
|
15315
|
+
if (Array.isArray(eventSwapInfo)) {
|
|
15316
|
+
swapInfo = eventSwapInfo.map((info) => formatSwapInfoTokens(info, chain));
|
|
15317
|
+
} else if (typeof eventSwapInfo === "object" && Object.keys(eventSwapInfo).length > 0) {
|
|
15318
|
+
swapInfo = formatSwapInfoTokens(eventSwapInfo, chain);
|
|
15319
|
+
}
|
|
15320
|
+
return { txHash: txReceipt.transactionHash, swapInfo };
|
|
15214
15321
|
};
|
|
15215
|
-
|
|
15216
|
-
|
|
15217
|
-
|
|
15218
|
-
|
|
15322
|
+
var fetchReceiptAndDecodeSwapInfo = async ({
|
|
15323
|
+
params,
|
|
15324
|
+
chain,
|
|
15325
|
+
rpcUrls
|
|
15219
15326
|
}) => {
|
|
15220
|
-
|
|
15221
|
-
|
|
15222
|
-
|
|
15223
|
-
|
|
15224
|
-
|
|
15225
|
-
|
|
15226
|
-
return {
|
|
15227
|
-
status: "error" /* error */,
|
|
15228
|
-
code: 32771 /* FunctionNotFound */,
|
|
15229
|
-
errorMsg: "No steps found in the zap route."
|
|
15230
|
-
};
|
|
15231
|
-
}
|
|
15232
|
-
}
|
|
15233
|
-
let txnHash;
|
|
15234
|
-
for (let i = 0; i < steps.length; i++) {
|
|
15235
|
-
const step = steps[i];
|
|
15236
|
-
if (step.action === zapStepAction.execute) {
|
|
15237
|
-
const result = await _ZapTxnHandler.execute({ chainId, txnData: step.data, signer });
|
|
15238
|
-
if (result.status !== "success" /* success */) {
|
|
15239
|
-
return result;
|
|
15240
|
-
}
|
|
15241
|
-
txnHash = result.txnHash;
|
|
15242
|
-
}
|
|
15243
|
-
}
|
|
15244
|
-
if (!txnHash) {
|
|
15245
|
-
return {
|
|
15246
|
-
status: "error" /* error */,
|
|
15247
|
-
code: 500 /* Error */,
|
|
15248
|
-
errorMsg: "No executable steps found."
|
|
15249
|
-
};
|
|
15250
|
-
}
|
|
15251
|
-
return {
|
|
15252
|
-
status: "success" /* success */,
|
|
15253
|
-
code: 200 /* Success */,
|
|
15254
|
-
txnHash
|
|
15255
|
-
};
|
|
15256
|
-
} catch (error) {
|
|
15257
|
-
console.log({ error });
|
|
15258
|
-
return handleViemTransactionError({ error });
|
|
15327
|
+
const txReceipt = await getTxReceipt({ txHash: params.txHash, chainId: chain.chainId, rpcUrls });
|
|
15328
|
+
return decodeSwapInfoFromReceipt({ txReceipt, service: params.service, chain });
|
|
15329
|
+
};
|
|
15330
|
+
var readGivenSwapInfo = async ({ params }) => {
|
|
15331
|
+
if ("txHash" in params && "eventSwapInfo" in params && typeof params.eventSwapInfo === "object" && Object.keys(params.eventSwapInfo).length > 0) {
|
|
15332
|
+
return { txHash: params.txHash, swapInfo: params.eventSwapInfo };
|
|
15259
15333
|
}
|
|
15334
|
+
throw new Error("Invalid decode params");
|
|
15335
|
+
};
|
|
15336
|
+
var getSwapFailPairs = (swapInfo, chain) => (Array.isArray(swapInfo) ? swapInfo : [swapInfo]).filter((info) => BigInt(info.returnToAmount) === BigInt(0)).map(
|
|
15337
|
+
(info) => {
|
|
15338
|
+
var _a, _b;
|
|
15339
|
+
return getTokensPairKey({
|
|
15340
|
+
srcToken: info.fromToken,
|
|
15341
|
+
destToken: info.toToken,
|
|
15342
|
+
srcChainId: chain.chainId,
|
|
15343
|
+
destChainId: chain.chainId,
|
|
15344
|
+
srcChainNativeAddress: (_a = chain == null ? void 0 : chain.nativeToken) == null ? void 0 : _a.contract,
|
|
15345
|
+
destChainNativeAddress: (_b = chain == null ? void 0 : chain.nativeToken) == null ? void 0 : _b.contract
|
|
15346
|
+
});
|
|
15347
|
+
}
|
|
15348
|
+
);
|
|
15349
|
+
var getSwapInfoForEvm = async ({ params, chain, rpcUrls }) => {
|
|
15350
|
+
if ("receipt" in params) {
|
|
15351
|
+
return await decodeSwapInfoFromReceipt({ txReceipt: params.receipt, service: params.service, chain });
|
|
15352
|
+
}
|
|
15353
|
+
if ("txHash" in params) {
|
|
15354
|
+
return await fetchReceiptAndDecodeSwapInfo({ params, chain, rpcUrls });
|
|
15355
|
+
}
|
|
15356
|
+
if ("eventSwapInfo" in params) {
|
|
15357
|
+
return await readGivenSwapInfo({ params });
|
|
15358
|
+
}
|
|
15359
|
+
throw new Error("Invalid decode params");
|
|
15360
|
+
};
|
|
15361
|
+
var chainDecoders = {
|
|
15362
|
+
[chainTypes.evm]: getSwapInfoForEvm,
|
|
15363
|
+
[chainTypes.svm]: readGivenSwapInfo,
|
|
15364
|
+
[chainTypes.suivm]: readGivenSwapInfo
|
|
15365
|
+
};
|
|
15366
|
+
var decodeTxnData = async (params) => {
|
|
15367
|
+
const { chainId, rpcUrls, chainsConfig } = params;
|
|
15368
|
+
const chain = chainsConfig[chainId];
|
|
15369
|
+
const decoder = chainDecoders[chain.chainType];
|
|
15370
|
+
if (!decoder) {
|
|
15371
|
+
throw new Error(`No decoder found for chain type ${chain.chainType}`);
|
|
15372
|
+
}
|
|
15373
|
+
const { txHash, swapInfo } = await decoder({ params, chain, rpcUrls });
|
|
15374
|
+
const patchResult = await patchSwapAmountsFromTx({ chainType: chain.chainType, chainId: chain.chainId, txHash, rpcUrls, eventSwapInfo: swapInfo });
|
|
15375
|
+
return { ...patchResult, swapFailPairs: getSwapFailPairs(patchResult.swapInfo, chain) };
|
|
15260
15376
|
};
|
|
15261
|
-
var ZapTxnHandler = _ZapTxnHandler;
|
|
15262
|
-
var zap_default = ZapTxnHandler;
|
|
15263
15377
|
var calculateAmountUSD = (amountInWei, decimals, price) => {
|
|
15264
15378
|
return decimals ? new Decimal(formatUnits(BigInt(amountInWei), decimals)).mul(price || 0).toFixed(5) : "0";
|
|
15265
15379
|
};
|
|
@@ -15879,15 +15993,22 @@ var _DZapClient = class _DZapClient {
|
|
|
15879
15993
|
return await waitForBatchTransactionReceipt(walletClient, batchHash);
|
|
15880
15994
|
}
|
|
15881
15995
|
/**
|
|
15882
|
-
* Decodes and interprets transaction
|
|
15883
|
-
*
|
|
15884
|
-
*
|
|
15996
|
+
* Decodes and interprets transaction data for DZap protocol operations on any supported chain type,
|
|
15997
|
+
* resolving the swap info and the actual fromAmount/returnToAmount of each swap.
|
|
15998
|
+
* On EVM the swap info is parsed from the transaction receipt's events. Solana and Sui have no such
|
|
15999
|
+
* event, so the caller-supplied `eventSwapInfo` (e.g. the quoted swap info) is patched with the
|
|
16000
|
+
* amounts the transaction actually moved.
|
|
15885
16001
|
*
|
|
15886
16002
|
* @param params - Configuration object for transaction decoding
|
|
15887
|
-
* @param params.data -
|
|
16003
|
+
* @param params.data - EVM: the transaction receipt to decode, fetched by `txHash` when omitted
|
|
16004
|
+
* @param params.txHash - The transaction hash, signature or digest; required on non-EVM chains
|
|
16005
|
+
* @param params.eventSwapInfo - Non-EVM: the swap info to patch with the actual amounts
|
|
15888
16006
|
* @param params.service - The DZap service type that generated the transaction
|
|
15889
16007
|
* @param params.chainId - The blockchain network ID where the transaction occurred
|
|
15890
|
-
* @
|
|
16008
|
+
* @param params.rpcUrls - Optional custom RPC URLs to read the transaction from
|
|
16009
|
+
* @returns Promise resolving to the swap info and failed swap pairs. `isAmountPatched` tells whether the
|
|
16010
|
+
* amounts were read from the transaction; when they could not be, the swap info is returned as given and
|
|
16011
|
+
* `amountPatchError` says why.
|
|
15891
16012
|
*
|
|
15892
16013
|
* @example
|
|
15893
16014
|
* ```typescript
|
|
@@ -15900,18 +16021,9 @@ var _DZapClient = class _DZapClient {
|
|
|
15900
16021
|
* console.log('Decoded transaction:', decodedData);
|
|
15901
16022
|
* ```
|
|
15902
16023
|
*/
|
|
15903
|
-
async decodeTxnData(
|
|
15904
|
-
const
|
|
15905
|
-
|
|
15906
|
-
_DZapClient.getChainConfig(),
|
|
15907
|
-
publicClient.getTransaction({
|
|
15908
|
-
hash: data.transactionHash
|
|
15909
|
-
})
|
|
15910
|
-
]);
|
|
15911
|
-
if (chainConfig === null || (chainConfig == null ? void 0 : chainConfig[chainId]) == null) {
|
|
15912
|
-
throw new Error("Chains config not found");
|
|
15913
|
-
}
|
|
15914
|
-
return handleDecodeTxnData(transactionData, data, service, chainConfig[chainId]);
|
|
16024
|
+
async decodeTxnData(params) {
|
|
16025
|
+
const chainConfig = await _DZapClient.getChainConfig();
|
|
16026
|
+
return decodeTxnData({ ...params, chainsConfig: chainConfig });
|
|
15915
16027
|
}
|
|
15916
16028
|
/**
|
|
15917
16029
|
* Calculates DZap reward points for completed trade operations including swaps and bridges.
|
|
@@ -16532,7 +16644,12 @@ var dZapClient_default = DZapClient;
|
|
|
16532
16644
|
var contractErrorActions = {
|
|
16533
16645
|
TRY_ANOTHER_ROUTE: "TRY_ANOTHER_ROUTE",
|
|
16534
16646
|
INCREASE_SLIPPAGE: "INCREASE_SLIPPAGE",
|
|
16535
|
-
INCREASE_ALLOWANCE: "INCREASE_ALLOWANCE"
|
|
16647
|
+
INCREASE_ALLOWANCE: "INCREASE_ALLOWANCE",
|
|
16648
|
+
INCREASE_AMOUNT: "INCREASE_AMOUNT",
|
|
16649
|
+
ADD_FUNDS: "ADD_FUNDS",
|
|
16650
|
+
RE_SIGN: "RE_SIGN",
|
|
16651
|
+
RETRY: "RETRY",
|
|
16652
|
+
CONTACT_SUPPORT: "CONTACT_SUPPORT"
|
|
16536
16653
|
};
|
|
16537
16654
|
var APTOS_DEFAULT_RPC = "https://fullnode.mainnet.aptoslabs.com";
|
|
16538
16655
|
var aptosAccountRegex = /^0x[a-fA-F0-9]{1,64}$/;
|
|
@@ -16720,7 +16837,7 @@ async function classifyEvmAddress(params) {
|
|
|
16720
16837
|
};
|
|
16721
16838
|
}
|
|
16722
16839
|
}
|
|
16723
|
-
var
|
|
16840
|
+
var SUI_DEFAULT_RPC2 = "https://fullnode.mainnet.sui.io";
|
|
16724
16841
|
var suiAccountRegex = /^0x[a-fA-F0-9]{1,64}$/;
|
|
16725
16842
|
var moveCoinTypeRegex2 = /^0x[a-fA-F0-9]{1,64}::[A-Za-z_][A-Za-z0-9_]*::[A-Za-z_][A-Za-z0-9_]*$/;
|
|
16726
16843
|
async function classifySuivmAddress(params) {
|
|
@@ -16756,7 +16873,7 @@ async function classifySuivmAddress(params) {
|
|
|
16756
16873
|
address
|
|
16757
16874
|
};
|
|
16758
16875
|
}
|
|
16759
|
-
const rpcUrl = (rpcUrls == null ? void 0 : rpcUrls[0]) ??
|
|
16876
|
+
const rpcUrl = (rpcUrls == null ? void 0 : rpcUrls[0]) ?? SUI_DEFAULT_RPC2;
|
|
16760
16877
|
try {
|
|
16761
16878
|
const response = await Axios.post(rpcUrl, {
|
|
16762
16879
|
jsonrpc: "2.0",
|
|
@@ -17099,4 +17216,4 @@ var zapRefundType = {
|
|
|
17099
17216
|
rent: "rent"
|
|
17100
17217
|
};
|
|
17101
17218
|
|
|
17102
|
-
export { AllowanceTypes, ApprovalModes, dZapClient_default as DZapClient, DZapPermitMode, OtherAbis, PermitTypes, QuoteFilters, STATUS, Services, SignatureExpiryInSecs, StatusCodes,
|
|
17219
|
+
export { AllowanceTypes, ApprovalModes, dZapClient_default as DZapClient, DZapPermitMode, OtherAbis, PermitTypes, QuoteFilters, STATUS, Services, SignatureExpiryInSecs, StatusCodes, TxnStatus, arcTestnet, arthera, astralisTestnet, bitcoinTestnet, bitlayer, checkEIP2612PermitSupport, citrea, classifyAddress, contractErrorActions, customViemChains, erc20Functions, extendViemChain, fiveIre, formatToken, getTokensPairKey, hemi, hyperEvm, hyperliquid, katana, merlin, patchSwapAmountsFromTx, pushTestnet, robinhood, stableChain, tempo, viemChainsById, zapFeeType, zapPathAction, zapRefundType, zapStepAction };
|