@funkit/fun-relay 2.2.0-next.6 → 2.2.0

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,