@funkit/fun-relay 2.2.0-next.6 → 2.2.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.mjs CHANGED
@@ -96,90 +96,6 @@ function getRelayClient() {
96
96
  import {
97
97
  MAINNET_RELAY_API as MAINNET_RELAY_API2
98
98
  } from "@relayprotocol/relay-sdk";
99
-
100
- // src/utils.ts
101
- function convertFunToRelayTokenAddress(address, chainId) {
102
- if (address.toLowerCase() === FUNKIT_NATIVE_TOKEN.toLowerCase()) {
103
- switch (chainId) {
104
- case FUN_HYPERCORE_CHAIN_ID_NUMBER:
105
- return RELAY_NATIVE_TOKEN_HYPERCORE;
106
- case RELAY_BITCOIN_CHAIN_ID_NUMBER:
107
- return RELAY_NATIVE_TOKEN_BITCOIN;
108
- // TODO: is it correct to assume chainId here is relay chain id?
109
- case RELAY_SOLANA_CHAIN_ID_NUMBER:
110
- case FUN_SOLANA_CHAIN_ID_NUMBER:
111
- return RELAY_NATIVE_TOKEN_SOLANA;
112
- case RELAY_LIGHTER_CHAIN_ID_NUMBER:
113
- return RELAY_LIGHTER_USDC_PERPS;
114
- default:
115
- return RELAY_NATIVE_TOKEN;
116
- }
117
- }
118
- if (RELAY_LIGHTER_CHAIN_ID_NUMBER === chainId) {
119
- const relayAddress = RELAY_LIGHTER_FUN_ADDRESS_MAP[address.toLowerCase()];
120
- if (relayAddress) {
121
- return relayAddress;
122
- }
123
- }
124
- return address;
125
- }
126
- function convertFunToRelayChainId(chainId) {
127
- if (chainId === FUN_SOLANA_CHAIN_ID_NUMBER) {
128
- return RELAY_SOLANA_CHAIN_ID_NUMBER;
129
- }
130
- return chainId;
131
- }
132
- function getRelayExecutionRefundState(info) {
133
- switch (info.status) {
134
- case "refund" /* REFUND */:
135
- return "REFUNDED" /* REFUNDED */;
136
- default:
137
- return void 0;
138
- }
139
- }
140
- function getRelayExecutionState(info) {
141
- switch (info.status) {
142
- case "success" /* SUCCESS */:
143
- return "COMPLETED" /* COMPLETED */;
144
- case "failure" /* FAILURE */:
145
- case "refund" /* REFUND */:
146
- return "CHECKOUT_ERROR" /* CHECKOUT_ERROR */;
147
- default:
148
- return "PENDING_RECEIVAL" /* PENDING_RECEIVAL */;
149
- }
150
- }
151
- function isRelayExecutionTerminalStatus(info) {
152
- return RELAY_TERMINAL_STATUSES.includes(info.status);
153
- }
154
- function jsonStringifyWithBigIntSanitization(serializable) {
155
- return JSON.stringify(
156
- serializable,
157
- (_, value) => typeof value === "bigint" ? `0x${value.toString(16)}` : value
158
- // return everything else unchanged
159
- );
160
- }
161
- function indexBy(items, getKey) {
162
- const indexedItems = {};
163
- for (const item of items) {
164
- const key = getKey(item);
165
- if (!key) {
166
- continue;
167
- }
168
- indexedItems[key] = item;
169
- }
170
- return indexedItems;
171
- }
172
- function filterNullishHeaders(params) {
173
- const result = {};
174
- for (const [key, value] of Object.entries(params)) {
175
- if (value != null) {
176
- result[key] = value;
177
- }
178
- }
179
- return result;
180
- }
181
-
182
- // src/execution.ts
183
99
  function getTxHash({
184
100
  logger,
185
101
  transactionType,
@@ -330,18 +246,6 @@ async function executeRelayQuote({
330
246
  ) {
331
247
  logger.info(`${logPrefix}:onTransactionConfirmed`, txHashes);
332
248
  isTransactionConfirmed = true;
333
- const firstStep = relayQuote.steps[0];
334
- const firstItem = firstStep?.items[0];
335
- if (firstStep?.requestId && firstItem) {
336
- manuallyRegisterIndex(logger, {
337
- requestId: firstStep.requestId,
338
- chainId: firstItem.data.chainId,
339
- tx: jsonStringifyWithBigIntSanitization({
340
- ...firstItem.data,
341
- txHash
342
- })
343
- });
344
- }
345
249
  try {
346
250
  await onTransactionConfirmed?.(txHash);
347
251
  } catch (e) {
@@ -355,42 +259,6 @@ async function executeRelayQuote({
355
259
  }
356
260
  });
357
261
  }
358
- async function manuallyRegisterIndex(logger, registerRequest) {
359
- const logPrefix = "manuallyRegisterIndex";
360
- const stringifiedRequest = JSON.stringify(registerRequest);
361
- const url = `${MAINNET_RELAY_API2}/transactions/single`;
362
- try {
363
- logger.info(`${logPrefix}:onManuallyRegisterIndex`, {
364
- params: stringifiedRequest
365
- });
366
- const response = await fetch(url, {
367
- method: "POST",
368
- body: JSON.stringify(registerRequest)
369
- });
370
- if (!response.ok) {
371
- logger.error(`${logPrefix}:onManuallyRegisterIndexError`, {
372
- message: "Error !response.ok - request to manually register index",
373
- response: JSON.stringify(response),
374
- params: stringifiedRequest
375
- });
376
- return;
377
- }
378
- const data = await response.json();
379
- if (data.message !== "Success") {
380
- logger.error(`${logPrefix}:onManuallyRegisterIndexError`, {
381
- message: `Data.message is not of type Success - ${data.message}`,
382
- response: JSON.stringify(response),
383
- params: stringifiedRequest
384
- });
385
- }
386
- return;
387
- } catch (err) {
388
- logger.error(`${logPrefix}:onManuallyRegisterIndexError`, {
389
- message: `Error sending request to register index at ${url}: ${JSON.stringify(err?.message)}`,
390
- params: stringifiedRequest
391
- });
392
- }
393
- }
394
262
  async function getRelayExecutionInfo(requestId, apiKey) {
395
263
  const url = `${MAINNET_RELAY_API2}/intents/status/v2?requestId=${requestId}`;
396
264
  const response = await fetch(url, {
@@ -475,6 +343,83 @@ function parseRelayFees({
475
343
 
476
344
  // src/price.ts
477
345
  import { MAINNET_RELAY_API as MAINNET_RELAY_API3 } from "@relayprotocol/relay-sdk";
346
+
347
+ // src/utils.ts
348
+ function convertFunToRelayTokenAddress(address, chainId) {
349
+ if (address.toLowerCase() === FUNKIT_NATIVE_TOKEN.toLowerCase()) {
350
+ switch (chainId) {
351
+ case FUN_HYPERCORE_CHAIN_ID_NUMBER:
352
+ return RELAY_NATIVE_TOKEN_HYPERCORE;
353
+ case RELAY_BITCOIN_CHAIN_ID_NUMBER:
354
+ return RELAY_NATIVE_TOKEN_BITCOIN;
355
+ // TODO: is it correct to assume chainId here is relay chain id?
356
+ case RELAY_SOLANA_CHAIN_ID_NUMBER:
357
+ case FUN_SOLANA_CHAIN_ID_NUMBER:
358
+ return RELAY_NATIVE_TOKEN_SOLANA;
359
+ case RELAY_LIGHTER_CHAIN_ID_NUMBER:
360
+ return RELAY_LIGHTER_USDC_PERPS;
361
+ default:
362
+ return RELAY_NATIVE_TOKEN;
363
+ }
364
+ }
365
+ if (RELAY_LIGHTER_CHAIN_ID_NUMBER === chainId) {
366
+ const relayAddress = RELAY_LIGHTER_FUN_ADDRESS_MAP[address.toLowerCase()];
367
+ if (relayAddress) {
368
+ return relayAddress;
369
+ }
370
+ }
371
+ return address;
372
+ }
373
+ function convertFunToRelayChainId(chainId) {
374
+ if (chainId === FUN_SOLANA_CHAIN_ID_NUMBER) {
375
+ return RELAY_SOLANA_CHAIN_ID_NUMBER;
376
+ }
377
+ return chainId;
378
+ }
379
+ function getRelayExecutionRefundState(info) {
380
+ switch (info.status) {
381
+ case "refund" /* REFUND */:
382
+ return "REFUNDED" /* REFUNDED */;
383
+ default:
384
+ return void 0;
385
+ }
386
+ }
387
+ function getRelayExecutionState(info) {
388
+ switch (info.status) {
389
+ case "success" /* SUCCESS */:
390
+ return "COMPLETED" /* COMPLETED */;
391
+ case "failure" /* FAILURE */:
392
+ case "refund" /* REFUND */:
393
+ return "CHECKOUT_ERROR" /* CHECKOUT_ERROR */;
394
+ default:
395
+ return "PENDING_RECEIVAL" /* PENDING_RECEIVAL */;
396
+ }
397
+ }
398
+ function isRelayExecutionTerminalStatus(info) {
399
+ return RELAY_TERMINAL_STATUSES.includes(info.status);
400
+ }
401
+ function indexBy(items, getKey) {
402
+ const indexedItems = {};
403
+ for (const item of items) {
404
+ const key = getKey(item);
405
+ if (!key) {
406
+ continue;
407
+ }
408
+ indexedItems[key] = item;
409
+ }
410
+ return indexedItems;
411
+ }
412
+ function filterNullishHeaders(params) {
413
+ const result = {};
414
+ for (const [key, value] of Object.entries(params)) {
415
+ if (value != null) {
416
+ result[key] = value;
417
+ }
418
+ }
419
+ return result;
420
+ }
421
+
422
+ // src/price.ts
478
423
  async function getRelayAssetPriceInfo({
479
424
  chainId,
480
425
  address,
@@ -1336,7 +1281,8 @@ var ASSET_LOGO_SRCS = {
1336
1281
  WMON: "https://sdk-cdn.fun.xyz/images/wmon.svg",
1337
1282
  AUSD: "https://sdk-cdn.fun.xyz/images/ausd.svg",
1338
1283
  SUSHI: "https://sdk-cdn.fun.xyz/images/sushi.svg",
1339
- SKY: "https://sdk-cdn.fun.xyz/images/sky.svg"
1284
+ SKY: "https://sdk-cdn.fun.xyz/images/sky.svg",
1285
+ LIT: "https://sdk-cdn.fun.xyz/images/lit.svg"
1340
1286
  };
1341
1287
 
1342
1288
  // src/dynamicRoutes/consts.ts
@@ -1351,7 +1297,6 @@ var tokenAddresses = {
1351
1297
  USDC: {
1352
1298
  [mainnet.id]: getAddress("0xA0b86991c6218b36c1d19D4a2e9Eb0cE3606eB48")
1353
1299
  },
1354
- // LIT is currently unused
1355
1300
  LIT: {
1356
1301
  [mainnet.id]: getAddress("0x232CE3bd40fCd6f80f3d55A522d03f25Df784Ee2")
1357
1302
  },
@@ -1529,6 +1474,7 @@ var UNI_SPOT_SYMBOL = "UNI (Spot)";
1529
1474
  var AAVE_SPOT_SYMBOL = "AAVE (Spot)";
1530
1475
  var SKY_SPOT_SYMBOL = "SKY (Spot)";
1531
1476
  var LDO_SPOT_SYMBOL = "LDO (Spot)";
1477
+ var LIT_SPOT_SYMBOL = "LIT (Spot)";
1532
1478
  var generateLighterMainnetDepositActions = ({
1533
1479
  address,
1534
1480
  assetIndex,
@@ -1665,6 +1611,25 @@ var LIGHTER_ETH_SPOT_FUN_MAINNET_DEPOSIT = createPath({
1665
1611
  });
1666
1612
  }
1667
1613
  });
1614
+ var LIGHTER_LIT_SPOT_FUN_MAINNET_DEPOSIT = createPath({
1615
+ targetChain: mainnet3.id.toString(),
1616
+ targetAsset: tokenAddresses.LIT[mainnet3.id],
1617
+ targetAssetTicker: LIT_SPOT_SYMBOL,
1618
+ iconSrc: ASSET_LOGO_SRCS.LIT,
1619
+ generateActionsParams: (address) => async (_finalTargetAssetAmount, outputConfig) => {
1620
+ if (!outputConfig) {
1621
+ return [];
1622
+ }
1623
+ if (outputConfig.targetChain !== mainnet3.id.toString()) {
1624
+ return [];
1625
+ }
1626
+ return generateLighterMainnetDepositActions({
1627
+ address,
1628
+ assetIndex: 2 /* LIT */,
1629
+ routeType: 1 /* Spot */
1630
+ });
1631
+ }
1632
+ });
1668
1633
  var LIGHTER_LINK_SPOT_FUN_MAINNET_DEPOSIT = createPath({
1669
1634
  targetChain: mainnet3.id.toString(),
1670
1635
  targetAsset: tokenAddresses.LINK[mainnet3.id],
@@ -1804,6 +1769,12 @@ var LIGHTER_DYNAMIC_ROUTES = [
1804
1769
  }
1805
1770
  }),
1806
1771
  // LINK, UNI, AAVE, SKY, LDO tokens
1772
+ createRoute({
1773
+ id: "LIGHTER_LIT_SPOT_NEW_USER",
1774
+ paths: {
1775
+ FUN_MAINNET_DEPOSIT: LIGHTER_LIT_SPOT_FUN_MAINNET_DEPOSIT
1776
+ }
1777
+ }),
1807
1778
  createRoute({
1808
1779
  id: "LIGHTER_LINK_SPOT_NEW_USER",
1809
1780
  paths: {