@funkit/fun-relay 2.1.15 → 2.1.16-next.1

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.js CHANGED
@@ -20,6 +20,7 @@ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: tru
20
20
  // index.ts
21
21
  var index_exports = {};
22
22
  __export(index_exports, {
23
+ DYNAMIC_ROUTES: () => DYNAMIC_ROUTES,
23
24
  FUN_RELAY_REFERRER: () => FUN_RELAY_REFERRER,
24
25
  FUN_RELAY_REVENUE_WALLET: () => FUN_RELAY_REVENUE_WALLET,
25
26
  LogLevel: () => import_relay_sdk.LogLevel,
@@ -46,6 +47,7 @@ __export(index_exports, {
46
47
  getRelayExecutionState: () => getRelayExecutionState,
47
48
  getRelayQuote: () => getRelayQuote,
48
49
  getSolanaWallet: () => getSolanaWallet,
50
+ initDynamicRouting: () => initDynamicRouting,
49
51
  initializeRelayClient: () => initializeRelayClient,
50
52
  isRelayExecutionTerminalStatus: () => isRelayExecutionTerminalStatus,
51
53
  parseRelayFees: () => parseRelayFees
@@ -87,7 +89,14 @@ var RELAY_NATIVE_TOKEN = "0x0000000000000000000000000000000000000000";
87
89
  var RELAY_NATIVE_TOKEN_HYPERCORE = "0x00000000000000000000000000000000";
88
90
  var RELAY_NATIVE_TOKEN_SOLANA = "11111111111111111111111111111111";
89
91
  var RELAY_NATIVE_TOKEN_BITCOIN = "bc1qqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqmql8k8";
90
- var RELAY_NATIVE_TOKEN_LIGHTER = "0";
92
+ var RELAY_LIGHTER_USDC_PERPS = "0";
93
+ var RELAY_LIGHTER_USDC_SPOT = "3";
94
+ var RELAY_LIGHTER_ETH_SPOT = "1";
95
+ var RELAY_LIGHTER_FUN_ADDRESS_MAP = {
96
+ "0x0000000000000000000000000000000000000000": RELAY_LIGHTER_USDC_PERPS,
97
+ "0x0000000000000000000000000000000000000001": RELAY_LIGHTER_ETH_SPOT,
98
+ "0x0000000000000000000000000000000000000003": RELAY_LIGHTER_USDC_SPOT
99
+ };
91
100
  var FUN_RELAY_REVENUE_WALLET = "0xdfd877679e95c1276c85801805b2c2ab8f4f4cf6";
92
101
  var FUN_RELAY_REFERRER = "funxyz";
93
102
  var RELAY_QUOTE_CHECKOUT_TIME_BUFFER_MS = 25e3;
@@ -147,11 +156,17 @@ function convertFunToRelayTokenAddress(address, chainId) {
147
156
  case FUN_SOLANA_CHAIN_ID_NUMBER:
148
157
  return RELAY_NATIVE_TOKEN_SOLANA;
149
158
  case RELAY_LIGHTER_CHAIN_ID_NUMBER:
150
- return RELAY_NATIVE_TOKEN_LIGHTER;
159
+ return RELAY_LIGHTER_USDC_PERPS;
151
160
  default:
152
161
  return RELAY_NATIVE_TOKEN;
153
162
  }
154
163
  }
164
+ if (RELAY_LIGHTER_CHAIN_ID_NUMBER === chainId) {
165
+ const relayAddress = RELAY_LIGHTER_FUN_ADDRESS_MAP[address.toLowerCase()];
166
+ if (relayAddress) {
167
+ return relayAddress;
168
+ }
169
+ }
155
170
  return address;
156
171
  }
157
172
  function convertFunToRelayChainId(chainId) {
@@ -189,6 +204,17 @@ function jsonStringifyWithBigIntSanitization(serializable) {
189
204
  // return everything else unchanged
190
205
  );
191
206
  }
207
+ function indexBy(items, getKey) {
208
+ const indexedItems = {};
209
+ for (const item of items) {
210
+ const key = getKey(item);
211
+ if (!key) {
212
+ continue;
213
+ }
214
+ indexedItems[key] = item;
215
+ }
216
+ return indexedItems;
217
+ }
192
218
 
193
219
  // src/execution.ts
194
220
  function getTxHash({
@@ -812,4 +838,821 @@ function getSolanaWallet(walletAddress, connection, signTransaction, payerKey) {
812
838
  payerKey
813
839
  );
814
840
  }
841
+
842
+ // src/dynamicRoutes/lighter.ts
843
+ var import_viem4 = require("viem");
844
+ var import_chains2 = require("viem/chains");
845
+
846
+ // src/dynamicRoutes/abi.ts
847
+ var UNWRAP_AND_CALL_ABI = [
848
+ {
849
+ name: "unwrapAndCall",
850
+ type: "function",
851
+ stateMutability: "nonpayable",
852
+ inputs: [
853
+ { name: "target", type: "address" },
854
+ { name: "callData", type: "bytes" }
855
+ ],
856
+ outputs: [{ name: "returnData", type: "bytes" }]
857
+ }
858
+ ];
859
+ var VAULT_DEPOSITOR_ABI = [
860
+ {
861
+ inputs: [
862
+ { internalType: "address", name: "initialOwner", type: "address" }
863
+ ],
864
+ stateMutability: "nonpayable",
865
+ type: "constructor"
866
+ },
867
+ {
868
+ inputs: [
869
+ { internalType: "uint256", name: "amount", type: "uint256" },
870
+ { internalType: "uint256", name: "tickSize", type: "uint256" }
871
+ ],
872
+ name: "AmountBelowMinimumTick",
873
+ type: "error"
874
+ },
875
+ {
876
+ inputs: [{ internalType: "bytes", name: "returnData", type: "bytes" }],
877
+ name: "DepositFailed",
878
+ type: "error"
879
+ },
880
+ { inputs: [], name: "DustRefundFailed", type: "error" },
881
+ { inputs: [], name: "EmptyMethodSignature", type: "error" },
882
+ { inputs: [], name: "InsufficientETHAmount", type: "error" },
883
+ { inputs: [], name: "InsufficientTokenAmount", type: "error" },
884
+ {
885
+ inputs: [{ internalType: "string", name: "reason", type: "string" }],
886
+ name: "InvalidCalldata",
887
+ type: "error"
888
+ },
889
+ { inputs: [], name: "InvalidDustRecipient", type: "error" },
890
+ { inputs: [], name: "InvalidFunctionSelector", type: "error" },
891
+ { inputs: [], name: "InvalidTickSize", type: "error" },
892
+ { inputs: [], name: "InvalidVault", type: "error" },
893
+ { inputs: [], name: "NoETHInContract", type: "error" },
894
+ {
895
+ inputs: [{ internalType: "address", name: "owner", type: "address" }],
896
+ name: "OwnableInvalidOwner",
897
+ type: "error"
898
+ },
899
+ {
900
+ inputs: [{ internalType: "address", name: "account", type: "address" }],
901
+ name: "OwnableUnauthorizedAccount",
902
+ type: "error"
903
+ },
904
+ { inputs: [], name: "ReentrancyGuardReentrantCall", type: "error" },
905
+ {
906
+ inputs: [{ internalType: "address", name: "token", type: "address" }],
907
+ name: "SafeERC20FailedOperation",
908
+ type: "error"
909
+ },
910
+ {
911
+ inputs: [
912
+ { internalType: "address", name: "vault", type: "address" },
913
+ { internalType: "bytes4", name: "selector", type: "bytes4" }
914
+ ],
915
+ name: "SelectorNotAllowed",
916
+ type: "error"
917
+ },
918
+ { inputs: [], name: "VaultAlreadyRegistered", type: "error" },
919
+ { inputs: [], name: "VaultDoesNotSupportNative", type: "error" },
920
+ { inputs: [], name: "VaultNotRegistered", type: "error" },
921
+ { inputs: [], name: "VaultNotRegisteredForDeposit", type: "error" },
922
+ {
923
+ anonymous: false,
924
+ inputs: [
925
+ {
926
+ indexed: true,
927
+ internalType: "address",
928
+ name: "recipient",
929
+ type: "address"
930
+ },
931
+ {
932
+ indexed: true,
933
+ internalType: "address",
934
+ name: "token",
935
+ type: "address"
936
+ },
937
+ {
938
+ indexed: false,
939
+ internalType: "uint256",
940
+ name: "dust",
941
+ type: "uint256"
942
+ },
943
+ {
944
+ indexed: false,
945
+ internalType: "uint256",
946
+ name: "originalAmount",
947
+ type: "uint256"
948
+ },
949
+ {
950
+ indexed: false,
951
+ internalType: "uint256",
952
+ name: "depositedAmount",
953
+ type: "uint256"
954
+ }
955
+ ],
956
+ name: "DustRefunded",
957
+ type: "event"
958
+ },
959
+ {
960
+ anonymous: false,
961
+ inputs: [
962
+ {
963
+ indexed: true,
964
+ internalType: "address",
965
+ name: "vault",
966
+ type: "address"
967
+ },
968
+ {
969
+ indexed: true,
970
+ internalType: "address",
971
+ name: "token",
972
+ type: "address"
973
+ },
974
+ {
975
+ indexed: false,
976
+ internalType: "uint256",
977
+ name: "amount",
978
+ type: "uint256"
979
+ },
980
+ {
981
+ indexed: false,
982
+ internalType: "bytes",
983
+ name: "returnData",
984
+ type: "bytes"
985
+ }
986
+ ],
987
+ name: "FunMediatedDeposit",
988
+ type: "event"
989
+ },
990
+ {
991
+ anonymous: false,
992
+ inputs: [
993
+ {
994
+ indexed: true,
995
+ internalType: "address",
996
+ name: "previousOwner",
997
+ type: "address"
998
+ },
999
+ {
1000
+ indexed: true,
1001
+ internalType: "address",
1002
+ name: "newOwner",
1003
+ type: "address"
1004
+ }
1005
+ ],
1006
+ name: "OwnershipTransferred",
1007
+ type: "event"
1008
+ },
1009
+ {
1010
+ anonymous: false,
1011
+ inputs: [
1012
+ {
1013
+ indexed: true,
1014
+ internalType: "address",
1015
+ name: "vault",
1016
+ type: "address"
1017
+ },
1018
+ {
1019
+ indexed: true,
1020
+ internalType: "bytes4",
1021
+ name: "newSelector",
1022
+ type: "bytes4"
1023
+ }
1024
+ ],
1025
+ name: "SelectorUpdated",
1026
+ type: "event"
1027
+ },
1028
+ {
1029
+ anonymous: false,
1030
+ inputs: [
1031
+ {
1032
+ indexed: true,
1033
+ internalType: "address",
1034
+ name: "vault",
1035
+ type: "address"
1036
+ },
1037
+ {
1038
+ indexed: false,
1039
+ internalType: "string",
1040
+ name: "methodSignature",
1041
+ type: "string"
1042
+ },
1043
+ {
1044
+ indexed: false,
1045
+ internalType: "bool",
1046
+ name: "convertTo18Decimals",
1047
+ type: "bool"
1048
+ }
1049
+ ],
1050
+ name: "VaultRegistered",
1051
+ type: "event"
1052
+ },
1053
+ {
1054
+ anonymous: false,
1055
+ inputs: [
1056
+ {
1057
+ indexed: true,
1058
+ internalType: "address",
1059
+ name: "vault",
1060
+ type: "address"
1061
+ }
1062
+ ],
1063
+ name: "VaultRemoved",
1064
+ type: "event"
1065
+ },
1066
+ {
1067
+ inputs: [],
1068
+ name: "AMOUNT_PLACEHOLDER",
1069
+ outputs: [{ internalType: "uint256", name: "", type: "uint256" }],
1070
+ stateMutability: "view",
1071
+ type: "function"
1072
+ },
1073
+ {
1074
+ inputs: [],
1075
+ name: "AMOUNT_PLACEHOLDER_BYTES32",
1076
+ outputs: [{ internalType: "bytes32", name: "", type: "bytes32" }],
1077
+ stateMutability: "view",
1078
+ type: "function"
1079
+ },
1080
+ {
1081
+ inputs: [],
1082
+ name: "NATIVE_TOKEN",
1083
+ outputs: [{ internalType: "address", name: "", type: "address" }],
1084
+ stateMutability: "view",
1085
+ type: "function"
1086
+ },
1087
+ {
1088
+ inputs: [
1089
+ { internalType: "uint256", name: "amount", type: "uint256" },
1090
+ { internalType: "uint256", name: "tickSize", type: "uint256" }
1091
+ ],
1092
+ name: "calculateTickRounding",
1093
+ outputs: [
1094
+ { internalType: "uint256", name: "roundedAmount", type: "uint256" },
1095
+ { internalType: "uint256", name: "dust", type: "uint256" }
1096
+ ],
1097
+ stateMutability: "pure",
1098
+ type: "function"
1099
+ },
1100
+ {
1101
+ inputs: [
1102
+ { internalType: "address", name: "token", type: "address" },
1103
+ { internalType: "address", name: "vault", type: "address" },
1104
+ { internalType: "bytes", name: "callData", type: "bytes" },
1105
+ { internalType: "uint256", name: "minAmountOut", type: "uint256" }
1106
+ ],
1107
+ name: "deposit",
1108
+ outputs: [{ internalType: "bytes", name: "returnData", type: "bytes" }],
1109
+ stateMutability: "nonpayable",
1110
+ type: "function"
1111
+ },
1112
+ {
1113
+ inputs: [
1114
+ { internalType: "address", name: "token", type: "address" },
1115
+ { internalType: "address", name: "vault", type: "address" },
1116
+ { internalType: "bytes", name: "callData", type: "bytes" },
1117
+ { internalType: "uint256", name: "minAmountOut", type: "uint256" },
1118
+ { internalType: "uint256", name: "tickSize", type: "uint256" },
1119
+ { internalType: "address", name: "dustRecipient", type: "address" }
1120
+ ],
1121
+ name: "depositWithTick",
1122
+ outputs: [{ internalType: "bytes", name: "returnData", type: "bytes" }],
1123
+ stateMutability: "nonpayable",
1124
+ type: "function"
1125
+ },
1126
+ {
1127
+ inputs: [{ internalType: "address", name: "vault", type: "address" }],
1128
+ name: "getAllowedSelector",
1129
+ outputs: [{ internalType: "bytes4", name: "", type: "bytes4" }],
1130
+ stateMutability: "view",
1131
+ type: "function"
1132
+ },
1133
+ {
1134
+ inputs: [{ internalType: "uint256", name: "tickSize", type: "uint256" }],
1135
+ name: "getMinimumDepositForTick",
1136
+ outputs: [{ internalType: "uint256", name: "minAmount", type: "uint256" }],
1137
+ stateMutability: "pure",
1138
+ type: "function"
1139
+ },
1140
+ {
1141
+ inputs: [{ internalType: "address", name: "vault", type: "address" }],
1142
+ name: "getVaultConfig",
1143
+ outputs: [
1144
+ {
1145
+ components: [
1146
+ { internalType: "bool", name: "isRegistered", type: "bool" },
1147
+ { internalType: "bool", name: "convertTo18Decimals", type: "bool" },
1148
+ { internalType: "bool", name: "allowsNative", type: "bool" },
1149
+ { internalType: "bytes4", name: "allowedSelector", type: "bytes4" }
1150
+ ],
1151
+ internalType: "struct VaultConfigLib.VaultConfig",
1152
+ name: "config",
1153
+ type: "tuple"
1154
+ }
1155
+ ],
1156
+ stateMutability: "view",
1157
+ type: "function"
1158
+ },
1159
+ {
1160
+ inputs: [{ internalType: "address", name: "vault", type: "address" }],
1161
+ name: "isVaultRegistered",
1162
+ outputs: [{ internalType: "bool", name: "", type: "bool" }],
1163
+ stateMutability: "view",
1164
+ type: "function"
1165
+ },
1166
+ {
1167
+ inputs: [],
1168
+ name: "owner",
1169
+ outputs: [{ internalType: "address", name: "", type: "address" }],
1170
+ stateMutability: "view",
1171
+ type: "function"
1172
+ },
1173
+ {
1174
+ inputs: [
1175
+ { internalType: "address", name: "vault", type: "address" },
1176
+ { internalType: "string", name: "vaultABI", type: "string" },
1177
+ {
1178
+ internalType: "bytes4",
1179
+ name: "allowedFunctionSelector",
1180
+ type: "bytes4"
1181
+ },
1182
+ { internalType: "bool", name: "convertTo18Decimals", type: "bool" },
1183
+ { internalType: "bool", name: "allowsNative", type: "bool" }
1184
+ ],
1185
+ name: "registerVault",
1186
+ outputs: [],
1187
+ stateMutability: "nonpayable",
1188
+ type: "function"
1189
+ },
1190
+ {
1191
+ inputs: [{ internalType: "address", name: "vault", type: "address" }],
1192
+ name: "removeVault",
1193
+ outputs: [],
1194
+ stateMutability: "nonpayable",
1195
+ type: "function"
1196
+ },
1197
+ {
1198
+ inputs: [],
1199
+ name: "renounceOwnership",
1200
+ outputs: [],
1201
+ stateMutability: "nonpayable",
1202
+ type: "function"
1203
+ },
1204
+ {
1205
+ inputs: [{ internalType: "address", name: "newOwner", type: "address" }],
1206
+ name: "transferOwnership",
1207
+ outputs: [],
1208
+ stateMutability: "nonpayable",
1209
+ type: "function"
1210
+ },
1211
+ {
1212
+ inputs: [
1213
+ { internalType: "address", name: "vault", type: "address" },
1214
+ { internalType: "bytes4", name: "newSelector", type: "bytes4" }
1215
+ ],
1216
+ name: "updateAllowedSelector",
1217
+ outputs: [],
1218
+ stateMutability: "nonpayable",
1219
+ type: "function"
1220
+ },
1221
+ {
1222
+ inputs: [
1223
+ { internalType: "uint256", name: "amount", type: "uint256" },
1224
+ { internalType: "uint256", name: "tickSize", type: "uint256" }
1225
+ ],
1226
+ name: "validateAmountForTick",
1227
+ outputs: [
1228
+ { internalType: "bool", name: "isValid", type: "bool" },
1229
+ { internalType: "uint256", name: "roundedAmount", type: "uint256" },
1230
+ { internalType: "uint256", name: "dust", type: "uint256" }
1231
+ ],
1232
+ stateMutability: "pure",
1233
+ type: "function"
1234
+ },
1235
+ {
1236
+ inputs: [{ internalType: "address", name: "vault", type: "address" }],
1237
+ name: "vaultAllowsNative",
1238
+ outputs: [{ internalType: "bool", name: "", type: "bool" }],
1239
+ stateMutability: "view",
1240
+ type: "function"
1241
+ },
1242
+ {
1243
+ inputs: [{ internalType: "address", name: "", type: "address" }],
1244
+ name: "vaultConfigs",
1245
+ outputs: [{ internalType: "uint40", name: "", type: "uint40" }],
1246
+ stateMutability: "view",
1247
+ type: "function"
1248
+ },
1249
+ {
1250
+ inputs: [{ internalType: "address", name: "vault", type: "address" }],
1251
+ name: "vaultRequires18Decimals",
1252
+ outputs: [{ internalType: "bool", name: "", type: "bool" }],
1253
+ stateMutability: "view",
1254
+ type: "function"
1255
+ },
1256
+ { stateMutability: "payable", type: "receive" }
1257
+ ];
1258
+
1259
+ // src/dynamicRoutes/assets.ts
1260
+ var ASSET_LOGO_SRCS = {
1261
+ $MFER: "https://sdk-cdn.fun.xyz/images/mfer.png",
1262
+ AARBUSDCN: "https://sdk-cdn.fun.xyz/images/aarbusdcn.png",
1263
+ AAVE: "https://sdk-cdn.fun.xyz/images/aave.svg",
1264
+ AERO: "https://sdk-cdn.fun.xyz/images/aero.svg",
1265
+ APE: "https://sdk-cdn.fun.xyz/images/ape.svg",
1266
+ APOLWMATIC: "https://sdk-cdn.fun.xyz/images/apolwmatic.png",
1267
+ ARB: "https://sdk-cdn.fun.xyz/images/arb.svg",
1268
+ BEHYPE: "https://sdk-cdn.fun.xyz/images/behype.svg",
1269
+ BENTO: "https://sdk-cdn.fun.xyz/images/bento.png",
1270
+ BLERF: "https://sdk-cdn.fun.xyz/images/blerf.png",
1271
+ BRETT: "https://sdk-cdn.fun.xyz/images/brett.svg",
1272
+ BSHIB: "https://sdk-cdn.fun.xyz/images/bshib.png",
1273
+ BTC: "https://sdk-cdn.fun.xyz/images/btc.svg",
1274
+ CBBTC: "https://sdk-cdn.fun.xyz/images/cbbtc.svg",
1275
+ CBETH: "https://sdk-cdn.fun.xyz/images/cbeth.png",
1276
+ CRO: "https://sdk-cdn.fun.xyz/images/cro.svg",
1277
+ CRV: "https://sdk-cdn.fun.xyz/images/crv.svg",
1278
+ DAI: "https://sdk-cdn.fun.xyz/images/dai.svg",
1279
+ DEGEN: "https://sdk-cdn.fun.xyz/images/degen.svg",
1280
+ ETH: "https://sdk-cdn.fun.xyz/images/eth.svg",
1281
+ GMX: "https://sdk-cdn.fun.xyz/images/gmx.svg",
1282
+ GRT: "https://sdk-cdn.fun.xyz/images/grt.svg",
1283
+ HYPE: "https://sdk-cdn.fun.xyz/images/hype.svg",
1284
+ IMX: "https://sdk-cdn.fun.xyz/images/imx.svg",
1285
+ INJ: "https://sdk-cdn.fun.xyz/images/inj.svg",
1286
+ LDO: "https://sdk-cdn.fun.xyz/images/ldo.svg",
1287
+ LINK: "https://sdk-cdn.fun.xyz/images/link.svg",
1288
+ LUCK: "https://sdk-cdn.fun.xyz/images/luck.png",
1289
+ MATIC: "https://sdk-cdn.fun.xyz/images/matic.svg",
1290
+ MFER: "https://sdk-cdn.fun.xyz/images/mfer.png",
1291
+ MKR: "https://sdk-cdn.fun.xyz/images/mkr.svg",
1292
+ MNT: "https://sdk-cdn.fun.xyz/images/mnt.svg",
1293
+ PENDLE: "https://sdk-cdn.fun.xyz/images/pendle.svg",
1294
+ POL: "https://sdk-cdn.fun.xyz/images/matic.svg",
1295
+ PYUSD: "https://sdk-cdn.fun.xyz/images/pyusd.svg",
1296
+ QNT: "https://sdk-cdn.fun.xyz/images/qnt.svg",
1297
+ RNDR: "https://sdk-cdn.fun.xyz/images/rndr.svg",
1298
+ ROOST: "https://sdk-cdn.fun.xyz/images/roost.png",
1299
+ SAND: "https://sdk-cdn.fun.xyz/images/sand.svg",
1300
+ SHIB: "https://sdk-cdn.fun.xyz/images/shib.svg",
1301
+ SNX: "https://sdk-cdn.fun.xyz/images/snx.svg",
1302
+ SOL: "https://sdk-cdn.fun.xyz/images/sol.svg",
1303
+ SUSDS: "https://sdk-cdn.fun.xyz/images/susds.svg",
1304
+ TYBG: "https://sdk-cdn.fun.xyz/images/tybg.png",
1305
+ UNI: "https://sdk-cdn.fun.xyz/images/uni.svg",
1306
+ USDC: "https://sdk-cdn.fun.xyz/images/usdc.svg",
1307
+ "USDC.E": "https://sdk-cdn.fun.xyz/images/usdc.svg",
1308
+ USDE: "https://sdk-cdn.fun.xyz/images/usde.svg",
1309
+ WUSDE: "https://sdk-cdn.fun.xyz/images/usde.svg",
1310
+ EUSDE: "https://sdk-cdn.fun.xyz/images/eusde.svg",
1311
+ USDT: "https://sdk-cdn.fun.xyz/images/usdt.svg",
1312
+ "USD\u20AE0": "https://sdk-cdn.fun.xyz/images/usdt0.svg",
1313
+ USDT0: "https://sdk-cdn.fun.xyz/images/usdt0.svg",
1314
+ USDS: "https://sdk-cdn.fun.xyz/images/usds.svg",
1315
+ USDH: "https://sdk-cdn.fun.xyz/images/usdh.svg",
1316
+ VRTX: "https://sdk-cdn.fun.xyz/images/vrtx.svg",
1317
+ WBTC: "https://sdk-cdn.fun.xyz/images/wbtc.svg",
1318
+ WEETH: "https://sdk-cdn.fun.xyz/images/weeth.png",
1319
+ WETH: "https://sdk-cdn.fun.xyz/images/weth.svg",
1320
+ WHYPE: "https://sdk-cdn.fun.xyz/images/whype.png",
1321
+ WSTETH: "https://sdk-cdn.fun.xyz/images/wsteth.png",
1322
+ TRUMP: "https://sdk-cdn.fun.xyz/images/trump.png",
1323
+ BNB: "https://sdk-cdn.fun.xyz/images/bsc.svg",
1324
+ WBNB: "https://sdk-cdn.fun.xyz/images/bsc.svg",
1325
+ BTCB: "https://sdk-cdn.fun.xyz/images/btc.svg",
1326
+ UBTC: "https://sdk-cdn.fun.xyz/images/btc.svg",
1327
+ BUSD: "https://sdk-cdn.fun.xyz/images/busd.svg",
1328
+ XAUT: "https://sdk-cdn.fun.xyz/images/xaut.png",
1329
+ ADA: "https://sdk-cdn.fun.xyz/images/ada.svg",
1330
+ XRP: "https://sdk-cdn.fun.xyz/images/xrp.svg",
1331
+ UDOGE: "https://sdk-cdn.fun.xyz/images/doge.svg",
1332
+ DOGE: "https://sdk-cdn.fun.xyz/images/doge.svg",
1333
+ LTC: "https://sdk-cdn.fun.xyz/images/ltc.svg",
1334
+ HNT: "https://sdk-cdn.fun.xyz/images/hnt.svg",
1335
+ COMP: "https://sdk-cdn.fun.xyz/images/comp.svg",
1336
+ PEPE: "https://sdk-cdn.fun.xyz/images/pepe.svg",
1337
+ LSTHYPE: "https://sdk-cdn.fun.xyz/images/lsthype.svg",
1338
+ HBUSDT: "https://sdk-cdn.fun.xyz/images/hbusdt.svg",
1339
+ WVLP: "https://sdk-cdn.fun.xyz/images/wvlp.svg",
1340
+ LIQUIDHYPE: "https://sdk-cdn.fun.xyz/images/liquidhype.svg",
1341
+ VHYPE: "https://sdk-cdn.fun.xyz/images/vhype.png",
1342
+ HBHYPE: "https://sdk-cdn.fun.xyz/images/hbhype.svg",
1343
+ MON: "https://sdk-cdn.fun.xyz/images/monad.svg",
1344
+ WMON: "https://sdk-cdn.fun.xyz/images/wmon.svg",
1345
+ AUSD: "https://sdk-cdn.fun.xyz/images/ausd.svg",
1346
+ SUSHI: "https://sdk-cdn.fun.xyz/images/sushi.svg"
1347
+ };
1348
+
1349
+ // src/dynamicRoutes/consts.ts
1350
+ var import_viem2 = require("viem");
1351
+ var import_chains = require("viem/chains");
1352
+ var import_viem3 = require("viem");
1353
+ var AMOUNT_PLACEHOLDER = 0xffffffffffffffffffffffffffffffffffffffffffffffffffffffffdeadbeefn;
1354
+ var tokenAddresses = {
1355
+ WETH: {
1356
+ [import_chains.mainnet.id]: (0, import_viem2.getAddress)("0xC02aaA39b223FE8D0A0e5C4F27eAD9083C756Cc2")
1357
+ },
1358
+ USDC: {
1359
+ [import_chains.mainnet.id]: (0, import_viem2.getAddress)("0xA0b86991c6218b36c1d19D4a2e9Eb0cE3606eB48")
1360
+ }
1361
+ };
1362
+ var UNWRAP_AND_CALL_ADDRESS = {
1363
+ [import_chains.mainnet.id]: (0, import_viem2.getAddress)("0x177591f2F4DcC3a47F768f6533eC6Edf564d6927")
1364
+ };
1365
+ var VAULT_DEPOSITOR_ADDRESS = {
1366
+ [import_chains.mainnet.id]: (0, import_viem2.getAddress)("0x40b72bB73B1E9380629B205e7880Fa409ae7fcc9")
1367
+ };
1368
+ var LIGHTER_DEPOSIT_ADDRESS = (0, import_viem2.getAddress)(
1369
+ "0x3b4d794a66304f130a4db8f2551b0070dfcf5ca7"
1370
+ );
1371
+ var MATCH_ALL_CONDITION = "*";
1372
+
1373
+ // src/dynamicRoutes/utils.ts
1374
+ var createPath = (config) => {
1375
+ return config;
1376
+ };
1377
+ var createRoute = (config) => {
1378
+ const getPathById = (pathId) => {
1379
+ const path = config.paths[pathId];
1380
+ if (!path) {
1381
+ return null;
1382
+ }
1383
+ return path;
1384
+ };
1385
+ return {
1386
+ id: config.id,
1387
+ config,
1388
+ getPathById
1389
+ };
1390
+ };
1391
+ var resolveBadge = (rule) => {
1392
+ if ("badge" in rule.use) {
1393
+ return rule.use.badge;
1394
+ }
1395
+ return void 0;
1396
+ };
1397
+ var initDynamicRouting = (dynamicRoutes, dynamicRoutingConfig) => {
1398
+ const indexedRoutes = indexBy(dynamicRoutes, (route) => route.id);
1399
+ const indexedDynamicRoutingConfig = dynamicRoutingConfig.reduce(
1400
+ (acc, routeConfig) => {
1401
+ const route = indexedRoutes[routeConfig.routeId];
1402
+ if (!route) {
1403
+ return acc;
1404
+ }
1405
+ const { rules } = routeConfig;
1406
+ const indexedRules = indexBy([...rules], (rule) => {
1407
+ if (rule.when === MATCH_ALL_CONDITION) {
1408
+ return MATCH_ALL_CONDITION;
1409
+ }
1410
+ return `${rule.when.chainId}-${rule.when.tokenAddress}`.toLowerCase();
1411
+ });
1412
+ const resolveRule = (rule) => {
1413
+ const path = route.getPathById(rule.use.path);
1414
+ if (!path) {
1415
+ return null;
1416
+ }
1417
+ const badge = resolveBadge(rule);
1418
+ return {
1419
+ path,
1420
+ badge
1421
+ };
1422
+ };
1423
+ const findPath = ({
1424
+ chainId,
1425
+ tokenAddress
1426
+ }) => {
1427
+ const specificRule = indexedRules[`${chainId}-${tokenAddress}`.toLowerCase()];
1428
+ if (specificRule) {
1429
+ return resolveRule(specificRule);
1430
+ }
1431
+ const anyChainSpecificTokenAddress = indexedRules[`${MATCH_ALL_CONDITION}-${tokenAddress}`.toLowerCase()];
1432
+ if (anyChainSpecificTokenAddress) {
1433
+ return resolveRule(anyChainSpecificTokenAddress);
1434
+ }
1435
+ const anyTokenAddressSpecificChain = indexedRules[`${chainId}-${MATCH_ALL_CONDITION}`.toLowerCase()];
1436
+ if (anyTokenAddressSpecificChain) {
1437
+ return resolveRule(anyTokenAddressSpecificChain);
1438
+ }
1439
+ const wildcardRule = indexedRules[MATCH_ALL_CONDITION];
1440
+ if (wildcardRule) {
1441
+ return resolveRule(wildcardRule);
1442
+ }
1443
+ return null;
1444
+ };
1445
+ acc[routeConfig.routeId] = {
1446
+ route,
1447
+ rules,
1448
+ findPath
1449
+ };
1450
+ return acc;
1451
+ },
1452
+ {}
1453
+ );
1454
+ return indexedDynamicRoutingConfig;
1455
+ };
1456
+
1457
+ // src/dynamicRoutes/lighter.ts
1458
+ var NATIVE_TOKEN = FUNKIT_NATIVE_TOKEN;
1459
+ var RELAY_LIGHTER_CHAIN_ID2 = 3586256;
1460
+ var RELAY_LIGHTER_ETH_SPOT_ADDRESS = "0x0000000000000000000000000000000000000001";
1461
+ var RELAY_LIGHTER_USDC_PERPS_ADDRESS = "0x0000000000000000000000000000000000000000";
1462
+ var TICK_SIZE_FOR_ASSET_INDEX = {
1463
+ [3 /* USDC */]: BigInt(1),
1464
+ [1 /* ETH */]: BigInt(10 ** 10)
1465
+ };
1466
+ var DEPOSIT_TOKEN_FOR_ASSET_INDEX = {
1467
+ [3 /* USDC */]: tokenAddresses.USDC[import_chains2.mainnet.id],
1468
+ [1 /* ETH */]: NATIVE_TOKEN
1469
+ };
1470
+ var USDC_PERPS_SYMBOL = "USDC (Perps)";
1471
+ var ETH_SPOT_SYMBOL = "ETH (Spot)";
1472
+ var generateLighterMainnetDepositActions = ({
1473
+ address,
1474
+ assetIndex,
1475
+ routeType
1476
+ }) => {
1477
+ const depositSelector = (0, import_viem4.toFunctionSelector)(
1478
+ "deposit(address,uint16,uint8,uint256)"
1479
+ );
1480
+ const encodedLighterParams = (0, import_viem4.encodeAbiParameters)(
1481
+ [
1482
+ { type: "address" },
1483
+ { type: "uint16" },
1484
+ { type: "uint8" },
1485
+ { type: "uint256" }
1486
+ ],
1487
+ [address, assetIndex, routeType, AMOUNT_PLACEHOLDER]
1488
+ );
1489
+ const lighterDepositCalldata = (0, import_viem4.concat)([depositSelector, encodedLighterParams]);
1490
+ const depositToken = DEPOSIT_TOKEN_FOR_ASSET_INDEX[assetIndex];
1491
+ const tickSize = TICK_SIZE_FOR_ASSET_INDEX[assetIndex];
1492
+ const dustRecipient = address;
1493
+ if (depositToken === NATIVE_TOKEN) {
1494
+ const vaultWrapperCalldata = (0, import_viem4.encodeFunctionData)({
1495
+ abi: VAULT_DEPOSITOR_ABI,
1496
+ functionName: "depositWithTick",
1497
+ args: [
1498
+ depositToken,
1499
+ // token (native ETH)
1500
+ LIGHTER_DEPOSIT_ADDRESS,
1501
+ // vault (Lighter deposit contract)
1502
+ lighterDepositCalldata,
1503
+ // callData
1504
+ 0n,
1505
+ // minAmountOut
1506
+ tickSize,
1507
+ // tickSize
1508
+ dustRecipient
1509
+ // dustRecipient
1510
+ ]
1511
+ });
1512
+ return [
1513
+ // Step 1: Approve WETH to UnwrapWETHAndCall
1514
+ {
1515
+ contractAbi: import_viem3.erc20Abi,
1516
+ contractAddress: tokenAddresses.WETH[import_chains2.mainnet.id],
1517
+ functionName: "approve",
1518
+ functionArgs: [
1519
+ UNWRAP_AND_CALL_ADDRESS[import_chains2.mainnet.id],
1520
+ "0xffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff"
1521
+ ]
1522
+ },
1523
+ // Step 2: UnwrapWETHAndCall pulls WETH, unwraps to ETH, sends to VaultWrapper, calls deposit
1524
+ {
1525
+ contractAbi: UNWRAP_AND_CALL_ABI,
1526
+ contractAddress: UNWRAP_AND_CALL_ADDRESS[import_chains2.mainnet.id],
1527
+ functionName: "unwrapAndCall",
1528
+ functionArgs: [
1529
+ VAULT_DEPOSITOR_ADDRESS[import_chains2.mainnet.id],
1530
+ // target (VaultWrapper)
1531
+ vaultWrapperCalldata
1532
+ // VaultWrapper.deposit() calldata
1533
+ ]
1534
+ }
1535
+ ];
1536
+ }
1537
+ if (depositToken === tokenAddresses.USDC[import_chains2.mainnet.id]) {
1538
+ return [
1539
+ // Step 1: Approve USDC to VaultDepositor
1540
+ {
1541
+ contractAbi: import_viem3.erc20Abi,
1542
+ contractAddress: tokenAddresses.USDC[import_chains2.mainnet.id],
1543
+ functionName: "approve",
1544
+ functionArgs: [
1545
+ VAULT_DEPOSITOR_ADDRESS[import_chains2.mainnet.id],
1546
+ "0xffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff"
1547
+ // Max approval
1548
+ ]
1549
+ },
1550
+ // Step 2: VaultDepositor pulls USDC and calls Lighter deposit
1551
+ {
1552
+ contractAbi: VAULT_DEPOSITOR_ABI,
1553
+ contractAddress: VAULT_DEPOSITOR_ADDRESS[import_chains2.mainnet.id],
1554
+ functionName: "depositWithTick",
1555
+ functionArgs: [
1556
+ tokenAddresses.USDC[import_chains2.mainnet.id],
1557
+ // token (USDC)
1558
+ LIGHTER_DEPOSIT_ADDRESS,
1559
+ // vault (Lighter deposit contract)
1560
+ lighterDepositCalldata,
1561
+ // callData
1562
+ 0n,
1563
+ // minAmountOut
1564
+ tickSize,
1565
+ // tickSize
1566
+ dustRecipient
1567
+ // dustRecipient
1568
+ ]
1569
+ }
1570
+ ];
1571
+ }
1572
+ };
1573
+ var LIGHTER_USDC_PERPS_FUN_MAINNET_DEPOSIT = createPath({
1574
+ targetChain: import_chains2.mainnet.id.toString(),
1575
+ targetAsset: tokenAddresses.USDC[import_chains2.mainnet.id],
1576
+ targetAssetTicker: USDC_PERPS_SYMBOL,
1577
+ iconSrc: ASSET_LOGO_SRCS.USDC,
1578
+ generateActionsParams: (address) => async (_finalTargetAssetAmount, outputConfig) => {
1579
+ if (!outputConfig) {
1580
+ return [];
1581
+ }
1582
+ if (outputConfig.targetChain !== import_chains2.mainnet.id.toString()) {
1583
+ return [];
1584
+ }
1585
+ return generateLighterMainnetDepositActions({
1586
+ address,
1587
+ assetIndex: 3 /* USDC */,
1588
+ routeType: 0 /* Perps */
1589
+ });
1590
+ }
1591
+ });
1592
+ var LIGHTER_ETH_SPOT_FUN_MAINNET_DEPOSIT = createPath({
1593
+ targetChain: import_chains2.mainnet.id.toString(),
1594
+ targetAsset: tokenAddresses.WETH[import_chains2.mainnet.id],
1595
+ targetAssetTicker: ETH_SPOT_SYMBOL,
1596
+ iconSrc: ASSET_LOGO_SRCS.ETH,
1597
+ generateActionsParams: (address) => async (_finalTargetAssetAmount, outputConfig) => {
1598
+ if (!outputConfig) {
1599
+ return [];
1600
+ }
1601
+ if (outputConfig.targetChain !== import_chains2.mainnet.id.toString()) {
1602
+ return [];
1603
+ }
1604
+ return generateLighterMainnetDepositActions({
1605
+ address,
1606
+ assetIndex: 1 /* ETH */,
1607
+ routeType: 1 /* Spot */
1608
+ });
1609
+ }
1610
+ });
1611
+ var LIGHTER_DYNAMIC_ROUTES = [
1612
+ createRoute({
1613
+ id: "LIGHTER_ETH_SPOT",
1614
+ paths: {
1615
+ FUN_MAINNET_DEPOSIT: LIGHTER_ETH_SPOT_FUN_MAINNET_DEPOSIT,
1616
+ RL_TRANSFER: createPath({
1617
+ targetChain: RELAY_LIGHTER_CHAIN_ID2.toString(),
1618
+ targetAsset: RELAY_LIGHTER_ETH_SPOT_ADDRESS,
1619
+ targetAssetTicker: ETH_SPOT_SYMBOL,
1620
+ iconSrc: ASSET_LOGO_SRCS.ETH,
1621
+ getCustomRecipient: ({ l2Address }) => {
1622
+ return l2Address;
1623
+ }
1624
+ })
1625
+ }
1626
+ }),
1627
+ createRoute({
1628
+ id: "LIGHTER_USDC_PERPS",
1629
+ paths: {
1630
+ FUN_MAINNET_DEPOSIT: LIGHTER_USDC_PERPS_FUN_MAINNET_DEPOSIT,
1631
+ RL_TRANSFER: createPath({
1632
+ targetChain: RELAY_LIGHTER_CHAIN_ID2.toString(),
1633
+ targetAsset: RELAY_LIGHTER_USDC_PERPS_ADDRESS,
1634
+ targetAssetTicker: USDC_PERPS_SYMBOL,
1635
+ iconSrc: ASSET_LOGO_SRCS.ETH,
1636
+ getCustomRecipient: ({ l2Address }) => {
1637
+ return l2Address;
1638
+ }
1639
+ })
1640
+ }
1641
+ }),
1642
+ createRoute({
1643
+ id: "LIGHTER_USDC_PERPS_NEW_USER",
1644
+ paths: {
1645
+ FUN_MAINNET_DEPOSIT: LIGHTER_USDC_PERPS_FUN_MAINNET_DEPOSIT
1646
+ }
1647
+ }),
1648
+ createRoute({
1649
+ id: "LIGHTER_ETH_SPOT_NEW_USER",
1650
+ paths: {
1651
+ FUN_MAINNET_DEPOSIT: LIGHTER_ETH_SPOT_FUN_MAINNET_DEPOSIT
1652
+ }
1653
+ })
1654
+ ];
1655
+
1656
+ // src/dynamicRoutes/index.ts
1657
+ var DYNAMIC_ROUTES = [...LIGHTER_DYNAMIC_ROUTES];
815
1658
  //# sourceMappingURL=index.js.map