@funkit/fun-relay 0.1.9-next.1 → 0.1.9
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/CHANGELOG.md +15 -0
- package/dist/index.js +75 -30
- package/dist/index.js.map +3 -3
- package/dist/index.mjs +75 -30
- package/dist/index.mjs.map +3 -3
- package/dist/src/execution.d.ts +13 -0
- package/dist/src/execution.d.ts.map +1 -1
- package/dist/src/utils.d.ts +2 -0
- package/dist/src/utils.d.ts.map +1 -1
- package/package.json +1 -1
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,20 @@
|
|
|
1
1
|
# @funkit/fun-relay
|
|
2
2
|
|
|
3
|
+
## 0.1.9
|
|
4
|
+
|
|
5
|
+
### Patch Changes
|
|
6
|
+
|
|
7
|
+
- f49824b: feat(relay): accurately check that each step item has a txHash
|
|
8
|
+
- d1133df: support withdrawal
|
|
9
|
+
- 57f6bd8: feat(relay): add payerKey to getSolanaWallet
|
|
10
|
+
- d4d61dc: manually register indexing for relay
|
|
11
|
+
|
|
12
|
+
## 0.1.9-next.2
|
|
13
|
+
|
|
14
|
+
### Patch Changes
|
|
15
|
+
|
|
16
|
+
- d4d61dc: manually register indexing for relay
|
|
17
|
+
|
|
3
18
|
## 0.1.9-next.1
|
|
4
19
|
|
|
5
20
|
### Patch Changes
|
package/dist/index.js
CHANGED
|
@@ -93,6 +93,45 @@ function getRelayClient() {
|
|
|
93
93
|
|
|
94
94
|
// src/execution.ts
|
|
95
95
|
var import_relay_sdk3 = require("@reservoir0x/relay-sdk");
|
|
96
|
+
|
|
97
|
+
// src/utils.ts
|
|
98
|
+
function convertFunToRelayTokenAddress(address) {
|
|
99
|
+
if (address.toLowerCase() === FUNKIT_NATIVE_TOKEN.toLowerCase()) {
|
|
100
|
+
return RELAY_NATIVE_TOKEN;
|
|
101
|
+
}
|
|
102
|
+
return address;
|
|
103
|
+
}
|
|
104
|
+
function getRelayExecutionRefundState(info) {
|
|
105
|
+
switch (info.status) {
|
|
106
|
+
case "refund":
|
|
107
|
+
return "REFUNDED" /* REFUNDED */;
|
|
108
|
+
default:
|
|
109
|
+
return void 0;
|
|
110
|
+
}
|
|
111
|
+
}
|
|
112
|
+
function getRelayExecutionState(info) {
|
|
113
|
+
switch (info.status) {
|
|
114
|
+
case "success":
|
|
115
|
+
return "COMPLETED" /* COMPLETED */;
|
|
116
|
+
case "failure":
|
|
117
|
+
case "refund":
|
|
118
|
+
return "CHECKOUT_ERROR" /* CHECKOUT_ERROR */;
|
|
119
|
+
default:
|
|
120
|
+
return "PENDING_RECEIVAL" /* PENDING_RECEIVAL */;
|
|
121
|
+
}
|
|
122
|
+
}
|
|
123
|
+
function isRelayExecutionTerminalStatus(info) {
|
|
124
|
+
return RELAY_TERMINAL_STATUSES.includes(info.status);
|
|
125
|
+
}
|
|
126
|
+
function jsonStringifyWithBigIntSanitization(serializable) {
|
|
127
|
+
return JSON.stringify(
|
|
128
|
+
serializable,
|
|
129
|
+
(_, value) => typeof value === "bigint" ? `0x${value.toString(16)}` : value
|
|
130
|
+
// return everything else unchanged
|
|
131
|
+
);
|
|
132
|
+
}
|
|
133
|
+
|
|
134
|
+
// src/execution.ts
|
|
96
135
|
async function executeRelayQuote({
|
|
97
136
|
logger,
|
|
98
137
|
onConfirmed,
|
|
@@ -139,6 +178,16 @@ async function executeRelayQuote({
|
|
|
139
178
|
) {
|
|
140
179
|
logger.info(`${logPrefix}:completed`, txHashes);
|
|
141
180
|
const txHash = txHashes[0].txHash;
|
|
181
|
+
if (relayQuote.steps[0].requestId) {
|
|
182
|
+
manuallyRegisterIndex(logger, {
|
|
183
|
+
requestId: relayQuote.steps[0].requestId,
|
|
184
|
+
chainId: relayQuote.steps[0].items[0].data.chainId,
|
|
185
|
+
tx: jsonStringifyWithBigIntSanitization({
|
|
186
|
+
...relayQuote.steps[0].items[0].data,
|
|
187
|
+
txHash
|
|
188
|
+
})
|
|
189
|
+
});
|
|
190
|
+
}
|
|
142
191
|
await onConfirmed(txHash).catch((e) => {
|
|
143
192
|
logger.error(`${logPrefix}:onConfirmedFailed`, e);
|
|
144
193
|
});
|
|
@@ -146,6 +195,32 @@ async function executeRelayQuote({
|
|
|
146
195
|
}
|
|
147
196
|
});
|
|
148
197
|
}
|
|
198
|
+
async function manuallyRegisterIndex(logger, registerRequest) {
|
|
199
|
+
const stringifiedRequest = JSON.stringify(registerRequest);
|
|
200
|
+
const url = `${import_relay_sdk3.MAINNET_RELAY_API}/transactions/single`;
|
|
201
|
+
try {
|
|
202
|
+
logger.info(`[registerIndexing] request: ${stringifiedRequest}`);
|
|
203
|
+
const response = await fetch(url, {
|
|
204
|
+
method: "POST",
|
|
205
|
+
body: JSON.stringify(registerRequest)
|
|
206
|
+
});
|
|
207
|
+
if (!response.ok) {
|
|
208
|
+
logger.error(
|
|
209
|
+
`Error sending request to manually register index: ${JSON.stringify(response)}`
|
|
210
|
+
);
|
|
211
|
+
return;
|
|
212
|
+
}
|
|
213
|
+
const data = await response.json();
|
|
214
|
+
if (data.message !== "Success") {
|
|
215
|
+
logger.error(`${data.message}. Params: ${stringifiedRequest}`);
|
|
216
|
+
}
|
|
217
|
+
return;
|
|
218
|
+
} catch (err) {
|
|
219
|
+
logger.error(
|
|
220
|
+
`Error sending request to register index at ${url}: ${JSON.stringify(err?.message)}. Params: ${stringifiedRequest}`
|
|
221
|
+
);
|
|
222
|
+
}
|
|
223
|
+
}
|
|
149
224
|
async function getRelayExecutionInfo(requestId) {
|
|
150
225
|
const url = `${import_relay_sdk3.MAINNET_RELAY_API}/intents/status/v2?requestId=${requestId}`;
|
|
151
226
|
const response = await fetch(url);
|
|
@@ -253,36 +328,6 @@ async function getRelayAssetInfo({
|
|
|
253
328
|
return data?.[0];
|
|
254
329
|
}
|
|
255
330
|
|
|
256
|
-
// src/utils.ts
|
|
257
|
-
function convertFunToRelayTokenAddress(address) {
|
|
258
|
-
if (address.toLowerCase() === FUNKIT_NATIVE_TOKEN.toLowerCase()) {
|
|
259
|
-
return RELAY_NATIVE_TOKEN;
|
|
260
|
-
}
|
|
261
|
-
return address;
|
|
262
|
-
}
|
|
263
|
-
function getRelayExecutionRefundState(info) {
|
|
264
|
-
switch (info.status) {
|
|
265
|
-
case "refund":
|
|
266
|
-
return "REFUNDED" /* REFUNDED */;
|
|
267
|
-
default:
|
|
268
|
-
return void 0;
|
|
269
|
-
}
|
|
270
|
-
}
|
|
271
|
-
function getRelayExecutionState(info) {
|
|
272
|
-
switch (info.status) {
|
|
273
|
-
case "success":
|
|
274
|
-
return "COMPLETED" /* COMPLETED */;
|
|
275
|
-
case "failure":
|
|
276
|
-
case "refund":
|
|
277
|
-
return "CHECKOUT_ERROR" /* CHECKOUT_ERROR */;
|
|
278
|
-
default:
|
|
279
|
-
return "PENDING_RECEIVAL" /* PENDING_RECEIVAL */;
|
|
280
|
-
}
|
|
281
|
-
}
|
|
282
|
-
function isRelayExecutionTerminalStatus(info) {
|
|
283
|
-
return RELAY_TERMINAL_STATUSES.includes(info.status);
|
|
284
|
-
}
|
|
285
|
-
|
|
286
331
|
// src/quote.ts
|
|
287
332
|
async function getQuoteEstUsdValue({
|
|
288
333
|
tokenChainId,
|
package/dist/index.js.map
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"version": 3,
|
|
3
|
-
"sources": ["../index.ts", "../src/client.ts", "../src/types.ts", "../src/constants.ts", "../src/execution.ts", "../src/
|
|
4
|
-
"sourcesContent": ["export {\n getRelayClient,\n initializeRelayClient,\n type InitializeRelayClientParams,\n} from './src/client'\nexport {\n FUN_RELAY_REFERRER,\n FUN_RELAY_REVENUE_WALLET,\n RELAY_SOLANA_CHAIN_ID,\n RELAY_SOLANA_CHAIN_ID_NUMBER,\n RELAY_TERMINAL_STATUSES,\n} from './src/constants'\nexport {\n type ExecuteRelayQuoteParams,\n type RelayAddress,\n type RelayChainId,\n type RelayExecutionStep,\n type RelayTxHash,\n type RelayVmType,\n type RelayWallet,\n executeRelayQuote,\n getRelayExecutionInfo,\n} from './src/execution'\nexport { parseRelayFees } from './src/fees'\nexport { getRelayAssetPriceInfo } from './src/price'\nexport {\n type GetRelayQuoteParams,\n type RelayQuote,\n getRelayQuote,\n} from './src/quote'\nexport {\n type SolanaAddress,\n type SolanaTxHash,\n type SolanaWallet,\n getSolanaWallet,\n} from './src/solana'\nexport {\n getRelayExecutionRefundState,\n getRelayExecutionState,\n isRelayExecutionTerminalStatus,\n convertFunToRelayTokenAddress,\n} from './src/utils'\nexport {\n LogLevel,\n type RelayExecutionInfo,\n type RelayExecutionStatus,\n type RelayTokenPriceInfo,\n} from './src/types'\n", "import {\n MAINNET_RELAY_API,\n type RelayClient,\n type RelayClientOptions,\n convertViemChainToRelayChain,\n createClient,\n getClient,\n} from '@reservoir0x/relay-sdk'\nimport type { Chain } from 'viem'\nimport { RELAY_SOLANA_CHAIN_ID_NUMBER } from './constants'\nimport type { Logger } from './types'\n\nexport type InitializeRelayClientParams = Omit<\n RelayClientOptions,\n 'baseApiUrl' | 'chains' | 'logger'\n> & {\n chains: Chain[]\n logger: Logger\n}\n\n/**\n * Initializes a global instance of the RelayClient\n * https://docs.relay.link/references/sdk/createClient\n */\nexport function initializeRelayClient({\n chains,\n logger,\n ...options\n}: InitializeRelayClientParams): RelayClient {\n return createClient({\n ...options,\n baseApiUrl: MAINNET_RELAY_API,\n chains: [\n ...chains.map(convertViemChainToRelayChain),\n {\n id: RELAY_SOLANA_CHAIN_ID_NUMBER,\n name: 'Solana',\n displayName: 'Solana',\n },\n ],\n logger: (message) => {\n logger.info('[RelayClient]:', message)\n },\n })\n}\n\n/**\n * Gets the global instance of the RelayClient\n */\nexport function getRelayClient(): RelayClient {\n const client = getClient()\n\n if (!client) {\n throw new Error('Relay client is not defined')\n }\n\n return client\n}\n", "import { LogLevel } from '@reservoir0x/relay-sdk'\nimport type { Abi, Address } from 'viem'\n\nexport { LogLevel }\n\n// https://docs.relay.link/references/api/get-intents-status-v2\nexport interface RelayExecutionInfo {\n status: RelayExecutionStatus\n details: string\n /** Incoming transaction hashes */\n inTxHashes: string[]\n /** Outgoing transaction hashes */\n txHashes: string[]\n /** The last timestamp the data was updated in milliseconds */\n time: number\n originChainId: number\n destinationChainId: number\n}\n\n// https://docs.relay.link/references/api/get-token-price\nexport interface RelayTokenPriceInfo {\n price: number\n}\n\n//// The types below are duplicated from @funkit/api-base atm, but this package should be used in BE as well\n//// TODO: Are we fine with BE importing @funkit/api-base and (by extension) @funkit/utils?\n//// See https://linear.app/funxyz/issue/PE-1342/sdk-extract-domainsrelayts-to-a-new-package#comment-d487d533\n\nexport interface Logger {\n error(message: string, data?: object): void\n info(message: string, data?: object): void\n}\n\n// Reference: https://github.com/reservoirprotocol/relay-kit/blob/211c645f9702a3b459ff545aa4e2e9d536c38455/packages/sdk/src/types/Execute.ts#L54-L61\nexport enum RelayExecutionStatus {\n DELAYED = 'delayed',\n FAILURE = 'failure',\n PENDING = 'pending',\n REFUND = 'refund',\n SUCCESS = 'success',\n WAITING = 'waiting',\n UNKNOWN = 'unknown',\n}\n\nexport interface ApiFunkitCheckoutActionParams {\n contractAbi: Abi\n contractAddress: Address\n functionName: string\n functionArgs: unknown[]\n value?: bigint\n}\n\nexport enum CheckoutRefundState {\n INITIATED = 'INITIATED',\n ERROR = 'ERROR',\n REFUNDED = 'REFUNDED',\n PROCEEDED = 'PROCEEDED',\n WAITING_FOR_FULFILLMENT = 'WAITING_FOR_FULFILLMENT',\n FULFILLED = 'FULFILLED',\n}\n\n// Reference from api server: https://github.com/fun-xyz/fun-api-server/blob/main/src/tables/FunWalletCheckout.ts#L11C1-L21C2\nexport enum CheckoutState {\n // In-progress States\n FROM_UNFUNDED = 'FROM_UNFUNDED',\n FROM_FUNDED = 'FROM_FUNDED',\n FROM_POOLED = 'FROM_POOLED',\n TO_UNFUNDED = 'TO_UNFUNDED',\n TO_FUNDED = 'TO_FUNDED',\n TO_POOLED = 'TO_POOLED',\n TO_READY = 'TO_READY',\n PENDING_RECEIVAL = 'PENDING_RECEIVAL',\n // Terminal States\n COMPLETED = 'COMPLETED',\n CHECKOUT_ERROR = 'CHECKOUT_ERROR',\n EXPIRED = 'EXPIRED',\n CANCELLED = 'CANCELLED',\n}\n\n// The response of the actual /checkout/quote api\nexport type CheckoutApiQuoteResponse = {\n quoteId: string\n estTotalFromAmountBaseUnit: string\n estSubtotalFromAmountBaseUnit: string\n estFeesFromAmountBaseUnit: string\n fromTokenAddress: Address\n estFeesUsd: number\n estSubtotalUsd: number\n estTotalUsd: number\n estCheckoutTimeMs: number\n estMarketMakerGasUsd: number\n lpFeePercentage: number\n lpFeeUsd: number\n}\n\n// The formatted response quote interface from the core sdk\nexport type CheckoutQuoteResponse = CheckoutApiQuoteResponse & {\n estTotalFromAmount: string\n estSubtotalFromAmount: string\n estFeesFromAmount: string\n\n // Any additional fields purely for frontend use\n metadata?: { [key: string]: unknown }\n}\n", "import type { Address } from 'viem'\nimport { RelayExecutionStatus } from './types'\n\n/**\n * Chain id that Relay uses to identify Solana\n *\n * See https://docs.relay.link/references/sdk/adapters#how-can-i-use-an-adapter%3F\n */\nexport const RELAY_SOLANA_CHAIN_ID_NUMBER = 792703809 // Why cannot Relay export this themselves... -.-\nexport const RELAY_SOLANA_CHAIN_ID = `${RELAY_SOLANA_CHAIN_ID_NUMBER}`\n\n/**\n * Fake address for a chain's native currency used by Funkit\n */\nexport const FUNKIT_NATIVE_TOKEN =\n '0xeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeee' satisfies Address\n\n/**\n * Fake address for a chain's native currency used by Relay\n */\nexport const RELAY_NATIVE_TOKEN =\n '0x0000000000000000000000000000000000000000' satisfies Address\n\n/**\n * Wallet that receives the app fees collected by Relay\n */\nexport const FUN_RELAY_REVENUE_WALLET =\n '0xb61562d83aEC43a050A06BED12Ac2bD8f9BFfd5E' satisfies Address\n\n/**\n * Referred field in Relay quote\n */\nexport const FUN_RELAY_REFERRER = 'funxyz'\n\n/**\n * Buffer added to Relay's time estimate (which sometimes is 0)\n */\nexport const RELAY_QUOTE_CHECKOUT_TIME_BUFFER_MS = 25_000 // 25 seconds\n\nexport const RELAY_TERMINAL_STATUSES: RelayExecutionStatus[] = [\n RelayExecutionStatus.REFUND,\n RelayExecutionStatus.FAILURE,\n RelayExecutionStatus.SUCCESS,\n]\n", "import {\n type AdaptedWallet,\n MAINNET_RELAY_API,\n type ProgressData,\n} from '@reservoir0x/relay-sdk'\nimport type { Address, Hex, WalletClient } from 'viem'\nimport { getRelayClient } from './client'\nimport type { RELAY_SOLANA_CHAIN_ID } from './constants'\nimport type { RelayQuoteResult } from './quote'\nimport type { SolanaAddress, SolanaTxHash, SolanaWallet } from './solana'\nimport type { Logger, RelayExecutionInfo } from './types'\n\nexport type RelayExecutionStep = ProgressData['currentStep'] & {}\n\nexport type RelayVmType = 'evm' | 'solana'\n\nexport type RelayAddress<VmType extends RelayVmType = RelayVmType> = {\n evm: Address\n solana: SolanaAddress\n}[VmType]\n\nexport type RelayChainId<VmType extends RelayVmType = RelayVmType> = {\n evm: string\n solana: typeof RELAY_SOLANA_CHAIN_ID\n}[VmType]\n\nexport type RelayTxHash<VmType extends RelayVmType = RelayVmType> = {\n evm: Hex\n solana: SolanaTxHash\n}[VmType]\n\nexport type RelayWallet<VmType extends RelayVmType = RelayVmType> = {\n evm: WalletClient | AdaptedWallet\n solana: SolanaWallet\n}[VmType]\n\nexport interface ExecuteRelayQuoteParams<VmType extends RelayVmType> {\n logger: Logger\n onConfirmed: (txHash: RelayTxHash<VmType>) => Promise<void>\n onError: (error: Error) => Promise<void>\n onProgress?: (step: RelayExecutionStep | null) => void\n relayQuote: RelayQuoteResult<VmType>\n walletClient: RelayWallet<VmType>\n}\n\nexport async function executeRelayQuote<VmType extends RelayVmType>({\n logger,\n onConfirmed,\n onError,\n onProgress,\n relayQuote,\n walletClient,\n}: ExecuteRelayQuoteParams<VmType>): Promise<void> {\n await getRelayClient().actions.execute({\n quote: relayQuote,\n wallet: walletClient,\n onProgress: async ({\n steps,\n fees,\n breakdown,\n currentStep,\n currentStepItem,\n txHashes,\n details,\n error,\n }) => {\n const logPrefix = 'onRelayProgress'\n logger.info(`${logPrefix}:params`, {\n steps,\n currentStep,\n fees,\n breakdown,\n currentStepItem,\n txHashes,\n details,\n error,\n })\n\n onProgress?.(currentStep ?? null)\n\n if (error) {\n logger.info(`${logPrefix}:errorDetected`, error)\n await onError(error).catch((e) => {\n logger.error(`${logPrefix}:onErrorFailed`, e)\n })\n } else if (\n // We can redirect as soon as all the required user step items have sent a transaction\n // Note that we are not actually waiting for a receipt / on-chain confirmation here\n // https://fun-xyz.slack.com/archives/C08MQ85QB2N/p1748381169792379\n txHashes?.length &&\n steps.every((step) => step.items.every((item) => item.txHashes?.length))\n ) {\n logger.info(`${logPrefix}:completed`, txHashes)\n // Can we assume its completed here?\n // Use first txHash as the main txHash in fun DE table\n const txHash = txHashes[0].txHash as RelayTxHash<VmType>\n await onConfirmed(txHash).catch((e) => {\n logger.error(`${logPrefix}:onConfirmedFailed`, e)\n })\n }\n },\n })\n}\n\nexport async function getRelayExecutionInfo(\n requestId: string,\n): Promise<RelayExecutionInfo> {\n const url = `${MAINNET_RELAY_API}/intents/status/v2?requestId=${requestId}`\n const response = await fetch(url)\n if (!response.ok) {\n throw Error(response.statusText)\n }\n\n const data = await response.json()\n return data as RelayExecutionInfo\n}\n", "import type { CallFees } from '@reservoir0x/relay-sdk'\nimport type { Logger } from './types'\n\nexport interface FunRelayFeeItem {\n b: number\n v: number\n}\n\nexport async function getFunRelayFees({\n fromTokenAddress,\n fromChainId,\n toTokenAddress,\n toChainId,\n estUsdValue,\n clientId,\n}: {\n fromTokenAddress: string\n fromChainId: string\n toTokenAddress: string\n toChainId: string\n estUsdValue: number\n clientId: string\n}): Promise<FunRelayFeeItem> {\n const url = `https://frog.fun.xyz/api/fee?fromTokenAddress=${fromTokenAddress}&fromChainId=${fromChainId}&toTokenAddress=${toTokenAddress}&toChainId=${toChainId}&estUsdValue=${estUsdValue}&clientId=${clientId}`\n const response = await fetch(url)\n if (!response.ok) {\n throw Error(response.statusText)\n }\n\n const data = await response.json()\n return data\n}\n\nexport function parseRelayFees({\n fees,\n logger,\n}: {\n fees: CallFees | undefined\n logger: Logger\n}) {\n // Gas fees, denominated in source chain native token\n const relayGasFeesUsd = Number.parseFloat(fees?.gas?.amountUsd || '0')\n\n // App fees, denominated in source chain token\n const funLpFeesUsd = Number.parseFloat(fees?.app?.amountUsd || '0')\n const funLpFeesFromAmount = Number.parseFloat(\n fees?.app?.amountFormatted || '0',\n )\n const funLpFeesFromAmountBaseUnit = BigInt(fees?.app?.amount || '0')\n\n // Relay fees, denominated in source chain token\n const relayLpFeesUsd = Number.parseFloat(fees?.relayer?.amountUsd || '0')\n const relayLpFeesFromAmount = Number.parseFloat(\n fees?.relayer?.amountFormatted || '0',\n )\n const relayLpFeesFromAmountBaseUnit = BigInt(fees?.relayer?.amount || '0')\n\n const totalLpFeesUsd = funLpFeesUsd + relayLpFeesUsd\n const totalLpFeesFromAmount = funLpFeesFromAmount + relayLpFeesFromAmount\n const totalLpFeesFromAmountBaseUnit =\n funLpFeesFromAmountBaseUnit + relayLpFeesFromAmountBaseUnit\n\n logger.info('parseRelayFees', {\n relayGasFeesUsd,\n funLpFeesUsd,\n funLpFeesFromAmount,\n funLpFeesFromAmountBaseUnit,\n relayLpFeesUsd,\n relayLpFeesFromAmount,\n relayLpFeesFromAmountBaseUnit,\n totalLpFeesUsd,\n totalLpFeesFromAmount,\n totalLpFeesFromAmountBaseUnit,\n })\n\n return {\n relayGasFeesUsd,\n totalLpFeesUsd,\n totalFeesUsd: relayGasFeesUsd + totalLpFeesUsd,\n totalFeesFromAmount: totalLpFeesFromAmount,\n totalFeesFromAmountBaseUnit: totalLpFeesFromAmountBaseUnit,\n }\n}\n", "import { MAINNET_RELAY_API } from '@reservoir0x/relay-sdk'\nimport type { RelayTokenPriceInfo } from './types'\n\nexport async function getRelayAssetPriceInfo({\n chainId,\n address,\n}: {\n chainId: string\n address: string\n}): Promise<RelayTokenPriceInfo> {\n const url = `${MAINNET_RELAY_API}/currencies/token/price?chainId=${chainId}&address=${address}`\n const response = await fetch(url)\n if (!response.ok) {\n throw Error(response.statusText)\n }\n\n const data = await response.json()\n return data as RelayTokenPriceInfo\n}\n", "import type { Execute, GetQuoteParameters } from '@reservoir0x/relay-sdk'\nimport { type Address, encodeFunctionData } from 'viem'\nimport { getRelayClient } from './client'\nimport {\n FUN_RELAY_REFERRER,\n FUN_RELAY_REVENUE_WALLET,\n RELAY_QUOTE_CHECKOUT_TIME_BUFFER_MS,\n} from './constants'\nimport { getRelayAssetInfo } from './currency'\nimport type {\n RelayAddress,\n RelayChainId,\n RelayVmType,\n RelayWallet,\n} from './execution'\nimport { getFunRelayFees, parseRelayFees } from './fees'\nimport { getRelayAssetPriceInfo } from './price'\nimport type {\n ApiFunkitCheckoutActionParams,\n CheckoutQuoteResponse,\n Logger,\n} from './types'\nimport { convertFunToRelayTokenAddress } from './utils'\n\ntype RelayQuoteOptions = GetQuoteParameters['options'] & {}\n\nexport type RelayQuoteResult<VmType extends RelayVmType> = Execute & {\n __vm: VmType\n}\n\nexport type GetRelayQuoteParams<\n SourceVmType extends RelayVmType = RelayVmType,\n TargetVmType extends RelayVmType = RelayVmType,\n> = {\n actionParams?: ApiFunkitCheckoutActionParams[]\n clientId: string\n fromChainId: RelayChainId<SourceVmType>\n fromTokenAddress: RelayAddress<SourceVmType>\n logger: Logger\n /**\n * {@link getRelayQuote} already sets {@link RelayQuoteOptions.appFees|appFees} and {@link RelayQuoteOptions.referrer|referrer}.\n * Only include them if you wish to override.\n */\n options?: RelayQuoteOptions\n recipientAddress: RelayAddress<TargetVmType> | undefined\n toChainId: RelayChainId<TargetVmType>\n toTokenAddress: RelayAddress<TargetVmType>\n tradeType: 'EXACT_INPUT' | 'EXACT_OUTPUT' | 'EXPECTED_OUTPUT'\n userAddress: RelayAddress<SourceVmType> | undefined\n walletClient?: RelayWallet<SourceVmType>\n} & (\n | {\n fromTokenAmountBaseUnit: bigint | string\n tradeType: 'EXACT_INPUT'\n }\n | {\n toTokenAmountBaseUnit: bigint | string\n tradeType: 'EXACT_OUTPUT' | 'EXPECTED_OUTPUT'\n }\n)\n\nexport type RelayQuote<VmType extends RelayVmType = RelayVmType> =\n CheckoutQuoteResponse & {\n /** Required for EXACT_INPUT checkouts */\n finalToAmountBaseUnit: string\n metadata: {\n fromAmountBaseUnit: string\n relayQuote: RelayQuoteResult<VmType>\n toAmountBaseUnit: string\n }\n }\n\nasync function getQuoteEstUsdValue({\n tokenChainId,\n tokenAddress,\n tokenAmountBaseUnit,\n logger,\n}: {\n tokenChainId: string\n tokenAddress: string\n tokenAmountBaseUnit: string\n logger: Logger\n}) {\n try {\n const [tokenPriceRes, tokenInfoRes] = await Promise.all([\n getRelayAssetPriceInfo({\n chainId: tokenChainId,\n address: convertFunToRelayTokenAddress(tokenAddress as Address),\n }),\n getRelayAssetInfo({\n chainId: tokenChainId,\n address: convertFunToRelayTokenAddress(tokenAddress as Address),\n }),\n ])\n\n const price = tokenPriceRes.price\n const decimals = tokenInfoRes.decimals\n\n const absoluteAmount = BigInt(tokenAmountBaseUnit) / BigInt(10 ** decimals)\n return Number(price) * Number(absoluteAmount)\n } catch (err) {\n logger.error('getQuoteEstUsdValueError', {\n message: `Failed to get USD value for token ${tokenAddress} on chain ${tokenChainId}: ${\n err instanceof Error ? err.message : JSON.stringify(err)\n }. Falling back to 0 USD.`,\n })\n // If any part fails, just fallback to 0 USD so that we do not block quote\n return 0\n }\n}\n\nexport async function getRelayQuote<\n SourceVmType extends RelayVmType,\n TargetVmType extends RelayVmType = RelayVmType,\n>({\n logger,\n walletClient,\n ...params\n}: GetRelayQuoteParams<SourceVmType, TargetVmType>): Promise<\n RelayQuote<SourceVmType>\n> {\n const {\n actionParams,\n clientId,\n fromChainId,\n fromTokenAddress,\n options,\n recipientAddress,\n toChainId,\n toTokenAddress,\n userAddress,\n } = params\n\n try {\n const relayClient = getRelayClient()\n\n const txs = actionParams?.map((action) => {\n const data = encodeFunctionData({\n abi: action.contractAbi,\n args: action.functionArgs,\n functionName: action.functionName,\n })\n\n return {\n data,\n to: action.contractAddress,\n value: String(action.value ?? 0n),\n }\n })\n\n const isExactIn = params.tradeType === 'EXACT_INPUT'\n const queryTokenAmountBaseUnit = isExactIn\n ? params.fromTokenAmountBaseUnit\n : params.toTokenAmountBaseUnit\n const queryTokenAddress = isExactIn ? fromTokenAddress : toTokenAddress\n const queryTokenChainId = isExactIn ? fromChainId : toChainId\n\n const estUsdValue = await getQuoteEstUsdValue({\n tokenChainId: queryTokenChainId,\n tokenAddress: queryTokenAddress,\n tokenAmountBaseUnit: queryTokenAmountBaseUnit.toString(),\n logger,\n })\n\n const feeInfo = await getFunRelayFees({\n fromTokenAddress,\n fromChainId,\n toTokenAddress,\n toChainId,\n estUsdValue: Number(estUsdValue) || 0,\n clientId,\n })\n\n const appFeeBp = feeInfo.b + feeInfo.v\n\n logger.info('getRelayQuoteParams', {\n ...params,\n queryTokenAmountBaseUnit,\n txs,\n estUsdValue,\n feeInfo,\n appFeeBp,\n })\n\n // Get the full quote with fees\n const relayQuote = await relayClient.actions.getQuote({\n chainId: Number(fromChainId),\n toChainId: Number(toChainId),\n currency: convertFunToRelayTokenAddress(fromTokenAddress),\n toCurrency: convertFunToRelayTokenAddress(toTokenAddress),\n amount: queryTokenAmountBaseUnit.toString(),\n recipient: recipientAddress,\n tradeType: params.tradeType,\n user: userAddress,\n wallet: walletClient,\n ...(txs && { txs }),\n options: {\n referrer: clientId\n ? `${FUN_RELAY_REFERRER}|${clientId}`\n : FUN_RELAY_REFERRER,\n appFees: [\n {\n fee: appFeeBp.toString(),\n recipient: FUN_RELAY_REVENUE_WALLET,\n },\n ],\n ...options,\n },\n })\n\n logger.info('relayQuote', relayQuote)\n\n const estSubtotalUsd = Number(\n relayQuote.details?.currencyOut?.amountUsd || 0,\n )\n const estTotalUsd = Number(relayQuote.details?.currencyIn?.amountUsd || 0)\n // Get how much fromAmount is needed for the quote\n const fromAmountString =\n relayQuote.details?.currencyIn?.amountFormatted || '0'\n const fromAmountBaseUnitString =\n relayQuote.details?.currencyIn?.amount || '0'\n\n // RequestID will be consistent across steps in the quote\n // https://fun-xyz.slack.com/archives/C08MQ85QB2N/p1747774944603209\n const relayRequestId = relayQuote.steps[0]?.requestId\n\n // TODO: Verify with relay team if this is possible?\n if (!relayRequestId) {\n throw new Error('Relay quote does not contain a requestId')\n }\n\n // TODO: Verify with relay team if this is possible?\n if (!relayQuote.details?.currencyIn || !relayQuote.details?.currencyOut) {\n throw new Error('Relay quote does not contain trade details')\n }\n\n const {\n relayGasFeesUsd,\n totalLpFeesUsd,\n totalFeesUsd,\n totalFeesFromAmount,\n totalFeesFromAmountBaseUnit,\n } = parseRelayFees({ fees: relayQuote.fees, logger })\n\n const estSubtotalFromAmount = (\n Number.parseFloat(fromAmountString) - totalFeesFromAmount\n ).toString()\n\n const estSubtotalFromAmountBaseUnit = (\n BigInt(fromAmountBaseUnitString) - totalFeesFromAmountBaseUnit\n ).toString()\n\n return {\n quoteId: relayRequestId,\n estCheckoutTimeMs:\n (relayQuote.details.timeEstimate || 0) * 1000 +\n RELAY_QUOTE_CHECKOUT_TIME_BUFFER_MS,\n estFeesFromAmount: totalFeesFromAmount.toString(),\n estFeesFromAmountBaseUnit: totalFeesFromAmountBaseUnit.toString(),\n estFeesUsd: totalFeesUsd,\n estMarketMakerGasUsd: relayGasFeesUsd,\n estSubtotalFromAmount,\n estSubtotalFromAmountBaseUnit,\n estSubtotalUsd,\n estTotalFromAmount: fromAmountString,\n estTotalFromAmountBaseUnit: fromAmountBaseUnitString,\n estTotalUsd,\n finalToAmountBaseUnit: relayQuote.details.currencyOut.amount ?? '0', // TODO: Or do we want 'minimumAmount'?\n fromTokenAddress: fromTokenAddress as Address, // TODO: fromTokenAddress is typed as `0x${string}` why does not accept SolanaAddress\n lpFeePercentage: 0, // TODO: ?\n lpFeeUsd: totalLpFeesUsd,\n metadata: {\n fromAmountBaseUnit: isExactIn\n ? queryTokenAmountBaseUnit.toString()\n : (relayQuote.details.currencyIn.amount ?? '0'),\n relayQuote: relayQuote as RelayQuoteResult<SourceVmType>,\n toAmountBaseUnit: isExactIn\n ? (relayQuote.details.currencyOut.amount ?? '0')\n : queryTokenAmountBaseUnit.toString(),\n },\n }\n } catch (err) {\n throw new Error(\n `An error occurred trying to generate a relay quote: ${\n err instanceof Error ? err.message : JSON.stringify(err)\n }`,\n )\n }\n}\n", "import { MAINNET_RELAY_API } from '@reservoir0x/relay-sdk'\n\nexport interface RelayTokenInfo {\n chainId: number\n address: string\n symbol: string\n name: string\n decimals: number\n vmType: string\n metadata: {\n logoURI: string\n verified: boolean\n isNative: boolean\n }\n}\n\nexport async function getRelayAssetInfo({\n chainId,\n address,\n}: {\n chainId: string\n address: string\n}): Promise<RelayTokenInfo> {\n const url = `${MAINNET_RELAY_API}/currencies/v2`\n const body = {\n chainIds: [chainId],\n address,\n }\n const response = await fetch(url, {\n method: 'POST',\n headers: { 'Content-Type': 'application/json' },\n body: JSON.stringify(body),\n })\n if (!response.ok) {\n throw Error(response.statusText)\n }\n\n const data = await response.json()\n return data?.[0] as RelayTokenInfo\n}\n", "import {\n FUNKIT_NATIVE_TOKEN,\n RELAY_NATIVE_TOKEN,\n RELAY_TERMINAL_STATUSES,\n} from './constants'\nimport type { RelayAddress, RelayVmType } from './execution'\nimport {\n CheckoutRefundState,\n CheckoutState,\n type RelayExecutionInfo,\n} from './types'\n\n/**\n * Converts a token address within Funkit the corresponding Relay token address.\n */\nexport function convertFunToRelayTokenAddress<T extends RelayVmType>(\n address: RelayAddress<T>,\n): RelayAddress<T> {\n if (address.toLowerCase() === FUNKIT_NATIVE_TOKEN.toLowerCase()) {\n return RELAY_NATIVE_TOKEN as RelayAddress<T>\n }\n\n return address\n}\n\nexport function getRelayExecutionRefundState(\n info: RelayExecutionInfo,\n): CheckoutRefundState | undefined {\n switch (info.status) {\n case 'refund':\n return CheckoutRefundState.REFUNDED\n default:\n return undefined\n }\n}\n\nexport function getRelayExecutionState(\n info: RelayExecutionInfo,\n): CheckoutState {\n switch (info.status) {\n case 'success':\n return CheckoutState.COMPLETED\n case 'failure':\n case 'refund':\n return CheckoutState.CHECKOUT_ERROR\n default:\n return CheckoutState.PENDING_RECEIVAL\n }\n}\n\n/**\n * Checks whether the Relay execution has reached a terminal status.\n */\nexport function isRelayExecutionTerminalStatus(\n info: RelayExecutionInfo,\n): boolean {\n return RELAY_TERMINAL_STATUSES.includes(info.status)\n}\n", "import type { AdaptedWallet } from '@reservoir0x/relay-sdk'\nimport { adaptSolanaWallet } from '@reservoir0x/relay-svm-wallet-adapter'\nimport {\n type Connection,\n SendTransactionError,\n type VersionedTransaction,\n} from '@solana/web3.js'\nimport { RELAY_SOLANA_CHAIN_ID_NUMBER } from './constants'\n\ntype Base58 =\n | '1'\n | '2'\n | '3'\n | '4'\n | '5'\n | '6'\n | '7'\n | '8'\n | '9'\n | 'A'\n | 'B'\n | 'C'\n | 'D'\n | 'E'\n | 'F'\n | 'G'\n | 'H'\n | 'J'\n | 'K'\n | 'L'\n | 'M'\n | 'N'\n | 'P'\n | 'Q'\n | 'R'\n | 'S'\n | 'T'\n | 'U'\n | 'V'\n | 'W'\n | 'X'\n | 'Y'\n | 'Z'\n | 'a'\n | 'b'\n | 'c'\n | 'd'\n | 'e'\n | 'f'\n | 'g'\n | 'h'\n | 'i'\n | 'j'\n | 'k'\n | 'm'\n | 'n'\n | 'o'\n | 'p'\n | 'q'\n | 'r'\n | 's'\n | 't'\n | 'u'\n | 'v'\n | 'w'\n | 'x'\n | 'y'\n | 'z'\n\nexport type SolanaAddress = `${Base58}${string}`\n\nexport type SolanaTxHash = `${Base58}${string}`\n\nexport type SolanaWallet = AdaptedWallet & {\n address(): Promise<SolanaAddress>\n}\n\nexport function getSolanaWallet(\n walletAddress: SolanaAddress,\n connection: Connection,\n signTransaction: (\n transaction: VersionedTransaction,\n ) => Promise<VersionedTransaction>,\n payerKey?: SolanaAddress,\n): SolanaWallet {\n return adaptSolanaWallet(\n walletAddress,\n RELAY_SOLANA_CHAIN_ID_NUMBER,\n connection,\n async (transaction, options) => {\n const signed = await signTransaction(transaction)\n try {\n const signature = await connection.sendTransaction(signed, {\n ...options,\n maxRetries: 5,\n })\n\n return { signature }\n } catch (error) {\n if (error instanceof SendTransactionError) {\n console.error(\n 'Failed transaction logs:',\n error,\n await error.getLogs(connection),\n )\n }\n\n throw error\n }\n },\n payerKey,\n ) as SolanaWallet\n}\n"],
|
|
5
|
-
"mappings": ";;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;;;ACAA,IAAAA,oBAOO;;;ACPP,uBAAyB;;;ACQlB,IAAM,+BAA+B;AACrC,IAAM,wBAAwB,GAAG,4BAA4B;AAK7D,IAAM,sBACX;AAKK,IAAM,qBACX;AAKK,IAAM,2BACX;AAKK,IAAM,qBAAqB;AAK3B,IAAM,sCAAsC;AAE5C,IAAM,0BAAkD;AAAA;AAAA;AAAA;AAI/D;;;AFnBO,SAAS,sBAAsB;AAAA,EACpC;AAAA,EACA;AAAA,EACA,GAAG;AACL,GAA6C;AAC3C,aAAO,gCAAa;AAAA,IAClB,GAAG;AAAA,IACH,YAAY;AAAA,IACZ,QAAQ;AAAA,MACN,GAAG,OAAO,IAAI,8CAA4B;AAAA,MAC1C;AAAA,QACE,IAAI;AAAA,QACJ,MAAM;AAAA,QACN,aAAa;AAAA,MACf;AAAA,IACF;AAAA,IACA,QAAQ,CAAC,YAAY;AACnB,aAAO,KAAK,kBAAkB,OAAO;AAAA,IACvC;AAAA,EACF,CAAC;AACH;AAKO,SAAS,iBAA8B;AAC5C,QAAM,aAAS,6BAAU;AAEzB,MAAI,CAAC,QAAQ;AACX,UAAM,IAAI,MAAM,6BAA6B;AAAA,EAC/C;AAEA,SAAO;AACT;;;AGzDA,IAAAC,oBAIO;
|
|
3
|
+
"sources": ["../index.ts", "../src/client.ts", "../src/types.ts", "../src/constants.ts", "../src/execution.ts", "../src/utils.ts", "../src/fees.ts", "../src/price.ts", "../src/quote.ts", "../src/currency.ts", "../src/solana.ts"],
|
|
4
|
+
"sourcesContent": ["export {\n getRelayClient,\n initializeRelayClient,\n type InitializeRelayClientParams,\n} from './src/client'\nexport {\n FUN_RELAY_REFERRER,\n FUN_RELAY_REVENUE_WALLET,\n RELAY_SOLANA_CHAIN_ID,\n RELAY_SOLANA_CHAIN_ID_NUMBER,\n RELAY_TERMINAL_STATUSES,\n} from './src/constants'\nexport {\n type ExecuteRelayQuoteParams,\n type RelayAddress,\n type RelayChainId,\n type RelayExecutionStep,\n type RelayTxHash,\n type RelayVmType,\n type RelayWallet,\n executeRelayQuote,\n getRelayExecutionInfo,\n} from './src/execution'\nexport { parseRelayFees } from './src/fees'\nexport { getRelayAssetPriceInfo } from './src/price'\nexport {\n type GetRelayQuoteParams,\n type RelayQuote,\n getRelayQuote,\n} from './src/quote'\nexport {\n type SolanaAddress,\n type SolanaTxHash,\n type SolanaWallet,\n getSolanaWallet,\n} from './src/solana'\nexport {\n getRelayExecutionRefundState,\n getRelayExecutionState,\n isRelayExecutionTerminalStatus,\n convertFunToRelayTokenAddress,\n} from './src/utils'\nexport {\n LogLevel,\n type RelayExecutionInfo,\n type RelayExecutionStatus,\n type RelayTokenPriceInfo,\n} from './src/types'\n", "import {\n MAINNET_RELAY_API,\n type RelayClient,\n type RelayClientOptions,\n convertViemChainToRelayChain,\n createClient,\n getClient,\n} from '@reservoir0x/relay-sdk'\nimport type { Chain } from 'viem'\nimport { RELAY_SOLANA_CHAIN_ID_NUMBER } from './constants'\nimport type { Logger } from './types'\n\nexport type InitializeRelayClientParams = Omit<\n RelayClientOptions,\n 'baseApiUrl' | 'chains' | 'logger'\n> & {\n chains: Chain[]\n logger: Logger\n}\n\n/**\n * Initializes a global instance of the RelayClient\n * https://docs.relay.link/references/sdk/createClient\n */\nexport function initializeRelayClient({\n chains,\n logger,\n ...options\n}: InitializeRelayClientParams): RelayClient {\n return createClient({\n ...options,\n baseApiUrl: MAINNET_RELAY_API,\n chains: [\n ...chains.map(convertViemChainToRelayChain),\n {\n id: RELAY_SOLANA_CHAIN_ID_NUMBER,\n name: 'Solana',\n displayName: 'Solana',\n },\n ],\n logger: (message) => {\n logger.info('[RelayClient]:', message)\n },\n })\n}\n\n/**\n * Gets the global instance of the RelayClient\n */\nexport function getRelayClient(): RelayClient {\n const client = getClient()\n\n if (!client) {\n throw new Error('Relay client is not defined')\n }\n\n return client\n}\n", "import { LogLevel } from '@reservoir0x/relay-sdk'\nimport type { Abi, Address } from 'viem'\n\nexport { LogLevel }\n\n// https://docs.relay.link/references/api/get-intents-status-v2\nexport interface RelayExecutionInfo {\n status: RelayExecutionStatus\n details: string\n /** Incoming transaction hashes */\n inTxHashes: string[]\n /** Outgoing transaction hashes */\n txHashes: string[]\n /** The last timestamp the data was updated in milliseconds */\n time: number\n originChainId: number\n destinationChainId: number\n}\n\n// https://docs.relay.link/references/api/get-token-price\nexport interface RelayTokenPriceInfo {\n price: number\n}\n\n//// The types below are duplicated from @funkit/api-base atm, but this package should be used in BE as well\n//// TODO: Are we fine with BE importing @funkit/api-base and (by extension) @funkit/utils?\n//// See https://linear.app/funxyz/issue/PE-1342/sdk-extract-domainsrelayts-to-a-new-package#comment-d487d533\n\nexport interface Logger {\n error(message: string, data?: object): void\n info(message: string, data?: object): void\n}\n\n// Reference: https://github.com/reservoirprotocol/relay-kit/blob/211c645f9702a3b459ff545aa4e2e9d536c38455/packages/sdk/src/types/Execute.ts#L54-L61\nexport enum RelayExecutionStatus {\n DELAYED = 'delayed',\n FAILURE = 'failure',\n PENDING = 'pending',\n REFUND = 'refund',\n SUCCESS = 'success',\n WAITING = 'waiting',\n UNKNOWN = 'unknown',\n}\n\nexport interface ApiFunkitCheckoutActionParams {\n contractAbi: Abi\n contractAddress: Address\n functionName: string\n functionArgs: unknown[]\n value?: bigint\n}\n\nexport enum CheckoutRefundState {\n INITIATED = 'INITIATED',\n ERROR = 'ERROR',\n REFUNDED = 'REFUNDED',\n PROCEEDED = 'PROCEEDED',\n WAITING_FOR_FULFILLMENT = 'WAITING_FOR_FULFILLMENT',\n FULFILLED = 'FULFILLED',\n}\n\n// Reference from api server: https://github.com/fun-xyz/fun-api-server/blob/main/src/tables/FunWalletCheckout.ts#L11C1-L21C2\nexport enum CheckoutState {\n // In-progress States\n FROM_UNFUNDED = 'FROM_UNFUNDED',\n FROM_FUNDED = 'FROM_FUNDED',\n FROM_POOLED = 'FROM_POOLED',\n TO_UNFUNDED = 'TO_UNFUNDED',\n TO_FUNDED = 'TO_FUNDED',\n TO_POOLED = 'TO_POOLED',\n TO_READY = 'TO_READY',\n PENDING_RECEIVAL = 'PENDING_RECEIVAL',\n // Terminal States\n COMPLETED = 'COMPLETED',\n CHECKOUT_ERROR = 'CHECKOUT_ERROR',\n EXPIRED = 'EXPIRED',\n CANCELLED = 'CANCELLED',\n}\n\n// The response of the actual /checkout/quote api\nexport type CheckoutApiQuoteResponse = {\n quoteId: string\n estTotalFromAmountBaseUnit: string\n estSubtotalFromAmountBaseUnit: string\n estFeesFromAmountBaseUnit: string\n fromTokenAddress: Address\n estFeesUsd: number\n estSubtotalUsd: number\n estTotalUsd: number\n estCheckoutTimeMs: number\n estMarketMakerGasUsd: number\n lpFeePercentage: number\n lpFeeUsd: number\n}\n\n// The formatted response quote interface from the core sdk\nexport type CheckoutQuoteResponse = CheckoutApiQuoteResponse & {\n estTotalFromAmount: string\n estSubtotalFromAmount: string\n estFeesFromAmount: string\n\n // Any additional fields purely for frontend use\n metadata?: { [key: string]: unknown }\n}\n", "import type { Address } from 'viem'\nimport { RelayExecutionStatus } from './types'\n\n/**\n * Chain id that Relay uses to identify Solana\n *\n * See https://docs.relay.link/references/sdk/adapters#how-can-i-use-an-adapter%3F\n */\nexport const RELAY_SOLANA_CHAIN_ID_NUMBER = 792703809 // Why cannot Relay export this themselves... -.-\nexport const RELAY_SOLANA_CHAIN_ID = `${RELAY_SOLANA_CHAIN_ID_NUMBER}`\n\n/**\n * Fake address for a chain's native currency used by Funkit\n */\nexport const FUNKIT_NATIVE_TOKEN =\n '0xeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeee' satisfies Address\n\n/**\n * Fake address for a chain's native currency used by Relay\n */\nexport const RELAY_NATIVE_TOKEN =\n '0x0000000000000000000000000000000000000000' satisfies Address\n\n/**\n * Wallet that receives the app fees collected by Relay\n */\nexport const FUN_RELAY_REVENUE_WALLET =\n '0xb61562d83aEC43a050A06BED12Ac2bD8f9BFfd5E' satisfies Address\n\n/**\n * Referred field in Relay quote\n */\nexport const FUN_RELAY_REFERRER = 'funxyz'\n\n/**\n * Buffer added to Relay's time estimate (which sometimes is 0)\n */\nexport const RELAY_QUOTE_CHECKOUT_TIME_BUFFER_MS = 25_000 // 25 seconds\n\nexport const RELAY_TERMINAL_STATUSES: RelayExecutionStatus[] = [\n RelayExecutionStatus.REFUND,\n RelayExecutionStatus.FAILURE,\n RelayExecutionStatus.SUCCESS,\n]\n", "import {\n type AdaptedWallet,\n MAINNET_RELAY_API,\n type ProgressData,\n} from '@reservoir0x/relay-sdk'\nimport type { Address, Hex, WalletClient } from 'viem'\nimport { getRelayClient } from './client'\nimport type { RELAY_SOLANA_CHAIN_ID } from './constants'\nimport type { RelayQuoteResult } from './quote'\nimport type { SolanaAddress, SolanaTxHash, SolanaWallet } from './solana'\nimport type { Logger, RelayExecutionInfo } from './types'\nimport { jsonStringifyWithBigIntSanitization } from './utils'\n\nexport type RelayExecutionStep = ProgressData['currentStep'] & {}\n\nexport type RelayVmType = 'evm' | 'solana'\n\nexport type RelayAddress<VmType extends RelayVmType = RelayVmType> = {\n evm: Address\n solana: SolanaAddress\n}[VmType]\n\nexport type RelayChainId<VmType extends RelayVmType = RelayVmType> = {\n evm: string\n solana: typeof RELAY_SOLANA_CHAIN_ID\n}[VmType]\n\nexport type RelayTxHash<VmType extends RelayVmType = RelayVmType> = {\n evm: Hex\n solana: SolanaTxHash\n}[VmType]\n\nexport type RelayWallet<VmType extends RelayVmType = RelayVmType> = {\n evm: WalletClient | AdaptedWallet\n solana: SolanaWallet\n}[VmType]\n\nexport interface ExecuteRelayQuoteParams<VmType extends RelayVmType> {\n logger: Logger\n onConfirmed: (txHash: RelayTxHash<VmType>) => Promise<void>\n onError: (error: Error) => Promise<void>\n onProgress?: (step: RelayExecutionStep | null) => void\n relayQuote: RelayQuoteResult<VmType>\n walletClient: RelayWallet<VmType>\n}\n\nexport async function executeRelayQuote<VmType extends RelayVmType>({\n logger,\n onConfirmed,\n onError,\n onProgress,\n relayQuote,\n walletClient,\n}: ExecuteRelayQuoteParams<VmType>): Promise<void> {\n await getRelayClient().actions.execute({\n quote: relayQuote,\n wallet: walletClient,\n onProgress: async ({\n steps,\n fees,\n breakdown,\n currentStep,\n currentStepItem,\n txHashes,\n details,\n error,\n }) => {\n const logPrefix = 'onRelayProgress'\n logger.info(`${logPrefix}:params`, {\n steps,\n currentStep,\n fees,\n breakdown,\n currentStepItem,\n txHashes,\n details,\n error,\n })\n\n onProgress?.(currentStep ?? null)\n\n if (error) {\n logger.info(`${logPrefix}:errorDetected`, error)\n await onError(error).catch((e) => {\n logger.error(`${logPrefix}:onErrorFailed`, e)\n })\n } else if (\n // We can redirect as soon as all the required user step items have sent a transaction\n // Note that we are not actually waiting for a receipt / on-chain confirmation here\n // https://fun-xyz.slack.com/archives/C08MQ85QB2N/p1748381169792379\n txHashes?.length &&\n steps.every((step) => step.items.every((item) => item.txHashes?.length))\n ) {\n logger.info(`${logPrefix}:completed`, txHashes)\n // Can we assume its completed here?\n // Use first txHash as the main txHash in fun DE table\n const txHash = txHashes[0].txHash as RelayTxHash<VmType>\n\n // fire and forget index registration\n if (relayQuote.steps[0].requestId) {\n manuallyRegisterIndex(logger, {\n requestId: relayQuote.steps[0].requestId,\n chainId: relayQuote.steps[0].items[0].data.chainId,\n tx: jsonStringifyWithBigIntSanitization({\n ...relayQuote.steps[0].items[0].data,\n txHash,\n }),\n })\n }\n await onConfirmed(txHash).catch((e) => {\n logger.error(`${logPrefix}:onConfirmedFailed`, e)\n })\n }\n },\n })\n}\n\nexport interface PostRegistrationRequest {\n requestId: string\n chainId: string\n tx: string\n}\n\nexport type RegisterIndexingResponse =\n | { success: never; message: 'Success' }\n | { success: false; message: string }\n\nexport async function manuallyRegisterIndex(\n logger: Logger,\n registerRequest: PostRegistrationRequest,\n): Promise<void> {\n const stringifiedRequest = JSON.stringify(registerRequest)\n const url = `${MAINNET_RELAY_API}/transactions/single`\n try {\n logger.info(`[registerIndexing] request: ${stringifiedRequest}`)\n const response = await fetch(url, {\n method: 'POST',\n body: JSON.stringify(registerRequest),\n })\n if (!response.ok) {\n logger.error(\n `Error sending request to manually register index: ${JSON.stringify(response)}`,\n )\n return\n }\n\n const data = (await response.json()) as RegisterIndexingResponse\n if (data.message !== 'Success') {\n logger.error(`${data.message}. Params: ${stringifiedRequest}`)\n }\n return\n } catch (err) {\n logger.error(\n `Error sending request to register index at ${url}: ${JSON.stringify((err as Error)?.message)}. Params: ${stringifiedRequest}`,\n )\n }\n}\n\nexport async function getRelayExecutionInfo(\n requestId: string,\n): Promise<RelayExecutionInfo> {\n const url = `${MAINNET_RELAY_API}/intents/status/v2?requestId=${requestId}`\n const response = await fetch(url)\n if (!response.ok) {\n throw Error(response.statusText)\n }\n\n const data = await response.json()\n return data as RelayExecutionInfo\n}\n", "import {\n FUNKIT_NATIVE_TOKEN,\n RELAY_NATIVE_TOKEN,\n RELAY_TERMINAL_STATUSES,\n} from './constants'\nimport type { RelayAddress, RelayVmType } from './execution'\nimport {\n CheckoutRefundState,\n CheckoutState,\n type RelayExecutionInfo,\n} from './types'\n\n/**\n * Converts a token address within Funkit the corresponding Relay token address.\n */\nexport function convertFunToRelayTokenAddress<T extends RelayVmType>(\n address: RelayAddress<T>,\n): RelayAddress<T> {\n if (address.toLowerCase() === FUNKIT_NATIVE_TOKEN.toLowerCase()) {\n return RELAY_NATIVE_TOKEN as RelayAddress<T>\n }\n\n return address\n}\n\nexport function getRelayExecutionRefundState(\n info: RelayExecutionInfo,\n): CheckoutRefundState | undefined {\n switch (info.status) {\n case 'refund':\n return CheckoutRefundState.REFUNDED\n default:\n return undefined\n }\n}\n\nexport function getRelayExecutionState(\n info: RelayExecutionInfo,\n): CheckoutState {\n switch (info.status) {\n case 'success':\n return CheckoutState.COMPLETED\n case 'failure':\n case 'refund':\n return CheckoutState.CHECKOUT_ERROR\n default:\n return CheckoutState.PENDING_RECEIVAL\n }\n}\n\n/**\n * Checks whether the Relay execution has reached a terminal status.\n */\nexport function isRelayExecutionTerminalStatus(\n info: RelayExecutionInfo,\n): boolean {\n return RELAY_TERMINAL_STATUSES.includes(info.status)\n}\n\nexport type Serializable =\n | bigint\n | boolean\n | null\n | number\n | string\n | Date\n | object // Should be '{ [key: string]: Serializable }' but helper gets called with loosely-typed 'object' and interfaces\n | Serializable[]\n\nexport function jsonStringifyWithBigIntSanitization(\n serializable: Serializable,\n): string {\n return JSON.stringify(\n serializable,\n (_, value) =>\n typeof value === 'bigint' ? `0x${value.toString(16)}` : value, // return everything else unchanged\n )\n}\n", "import type { CallFees } from '@reservoir0x/relay-sdk'\nimport type { Logger } from './types'\n\nexport interface FunRelayFeeItem {\n b: number\n v: number\n}\n\nexport async function getFunRelayFees({\n fromTokenAddress,\n fromChainId,\n toTokenAddress,\n toChainId,\n estUsdValue,\n clientId,\n}: {\n fromTokenAddress: string\n fromChainId: string\n toTokenAddress: string\n toChainId: string\n estUsdValue: number\n clientId: string\n}): Promise<FunRelayFeeItem> {\n const url = `https://frog.fun.xyz/api/fee?fromTokenAddress=${fromTokenAddress}&fromChainId=${fromChainId}&toTokenAddress=${toTokenAddress}&toChainId=${toChainId}&estUsdValue=${estUsdValue}&clientId=${clientId}`\n const response = await fetch(url)\n if (!response.ok) {\n throw Error(response.statusText)\n }\n\n const data = await response.json()\n return data\n}\n\nexport function parseRelayFees({\n fees,\n logger,\n}: {\n fees: CallFees | undefined\n logger: Logger\n}) {\n // Gas fees, denominated in source chain native token\n const relayGasFeesUsd = Number.parseFloat(fees?.gas?.amountUsd || '0')\n\n // App fees, denominated in source chain token\n const funLpFeesUsd = Number.parseFloat(fees?.app?.amountUsd || '0')\n const funLpFeesFromAmount = Number.parseFloat(\n fees?.app?.amountFormatted || '0',\n )\n const funLpFeesFromAmountBaseUnit = BigInt(fees?.app?.amount || '0')\n\n // Relay fees, denominated in source chain token\n const relayLpFeesUsd = Number.parseFloat(fees?.relayer?.amountUsd || '0')\n const relayLpFeesFromAmount = Number.parseFloat(\n fees?.relayer?.amountFormatted || '0',\n )\n const relayLpFeesFromAmountBaseUnit = BigInt(fees?.relayer?.amount || '0')\n\n const totalLpFeesUsd = funLpFeesUsd + relayLpFeesUsd\n const totalLpFeesFromAmount = funLpFeesFromAmount + relayLpFeesFromAmount\n const totalLpFeesFromAmountBaseUnit =\n funLpFeesFromAmountBaseUnit + relayLpFeesFromAmountBaseUnit\n\n logger.info('parseRelayFees', {\n relayGasFeesUsd,\n funLpFeesUsd,\n funLpFeesFromAmount,\n funLpFeesFromAmountBaseUnit,\n relayLpFeesUsd,\n relayLpFeesFromAmount,\n relayLpFeesFromAmountBaseUnit,\n totalLpFeesUsd,\n totalLpFeesFromAmount,\n totalLpFeesFromAmountBaseUnit,\n })\n\n return {\n relayGasFeesUsd,\n totalLpFeesUsd,\n totalFeesUsd: relayGasFeesUsd + totalLpFeesUsd,\n totalFeesFromAmount: totalLpFeesFromAmount,\n totalFeesFromAmountBaseUnit: totalLpFeesFromAmountBaseUnit,\n }\n}\n", "import { MAINNET_RELAY_API } from '@reservoir0x/relay-sdk'\nimport type { RelayTokenPriceInfo } from './types'\n\nexport async function getRelayAssetPriceInfo({\n chainId,\n address,\n}: {\n chainId: string\n address: string\n}): Promise<RelayTokenPriceInfo> {\n const url = `${MAINNET_RELAY_API}/currencies/token/price?chainId=${chainId}&address=${address}`\n const response = await fetch(url)\n if (!response.ok) {\n throw Error(response.statusText)\n }\n\n const data = await response.json()\n return data as RelayTokenPriceInfo\n}\n", "import type { Execute, GetQuoteParameters } from '@reservoir0x/relay-sdk'\nimport { type Address, encodeFunctionData } from 'viem'\nimport { getRelayClient } from './client'\nimport {\n FUN_RELAY_REFERRER,\n FUN_RELAY_REVENUE_WALLET,\n RELAY_QUOTE_CHECKOUT_TIME_BUFFER_MS,\n} from './constants'\nimport { getRelayAssetInfo } from './currency'\nimport type {\n RelayAddress,\n RelayChainId,\n RelayVmType,\n RelayWallet,\n} from './execution'\nimport { getFunRelayFees, parseRelayFees } from './fees'\nimport { getRelayAssetPriceInfo } from './price'\nimport type {\n ApiFunkitCheckoutActionParams,\n CheckoutQuoteResponse,\n Logger,\n} from './types'\nimport { convertFunToRelayTokenAddress } from './utils'\n\ntype RelayQuoteOptions = GetQuoteParameters['options'] & {}\n\nexport type RelayQuoteResult<VmType extends RelayVmType> = Execute & {\n __vm: VmType\n}\n\nexport type GetRelayQuoteParams<\n SourceVmType extends RelayVmType = RelayVmType,\n TargetVmType extends RelayVmType = RelayVmType,\n> = {\n actionParams?: ApiFunkitCheckoutActionParams[]\n clientId: string\n fromChainId: RelayChainId<SourceVmType>\n fromTokenAddress: RelayAddress<SourceVmType>\n logger: Logger\n /**\n * {@link getRelayQuote} already sets {@link RelayQuoteOptions.appFees|appFees} and {@link RelayQuoteOptions.referrer|referrer}.\n * Only include them if you wish to override.\n */\n options?: RelayQuoteOptions\n recipientAddress: RelayAddress<TargetVmType> | undefined\n toChainId: RelayChainId<TargetVmType>\n toTokenAddress: RelayAddress<TargetVmType>\n tradeType: 'EXACT_INPUT' | 'EXACT_OUTPUT' | 'EXPECTED_OUTPUT'\n userAddress: RelayAddress<SourceVmType> | undefined\n walletClient?: RelayWallet<SourceVmType>\n} & (\n | {\n fromTokenAmountBaseUnit: bigint | string\n tradeType: 'EXACT_INPUT'\n }\n | {\n toTokenAmountBaseUnit: bigint | string\n tradeType: 'EXACT_OUTPUT' | 'EXPECTED_OUTPUT'\n }\n)\n\nexport type RelayQuote<VmType extends RelayVmType = RelayVmType> =\n CheckoutQuoteResponse & {\n /** Required for EXACT_INPUT checkouts */\n finalToAmountBaseUnit: string\n metadata: {\n fromAmountBaseUnit: string\n relayQuote: RelayQuoteResult<VmType>\n toAmountBaseUnit: string\n }\n }\n\nasync function getQuoteEstUsdValue({\n tokenChainId,\n tokenAddress,\n tokenAmountBaseUnit,\n logger,\n}: {\n tokenChainId: string\n tokenAddress: string\n tokenAmountBaseUnit: string\n logger: Logger\n}) {\n try {\n const [tokenPriceRes, tokenInfoRes] = await Promise.all([\n getRelayAssetPriceInfo({\n chainId: tokenChainId,\n address: convertFunToRelayTokenAddress(tokenAddress as Address),\n }),\n getRelayAssetInfo({\n chainId: tokenChainId,\n address: convertFunToRelayTokenAddress(tokenAddress as Address),\n }),\n ])\n\n const price = tokenPriceRes.price\n const decimals = tokenInfoRes.decimals\n\n const absoluteAmount = BigInt(tokenAmountBaseUnit) / BigInt(10 ** decimals)\n return Number(price) * Number(absoluteAmount)\n } catch (err) {\n logger.error('getQuoteEstUsdValueError', {\n message: `Failed to get USD value for token ${tokenAddress} on chain ${tokenChainId}: ${\n err instanceof Error ? err.message : JSON.stringify(err)\n }. Falling back to 0 USD.`,\n })\n // If any part fails, just fallback to 0 USD so that we do not block quote\n return 0\n }\n}\n\nexport async function getRelayQuote<\n SourceVmType extends RelayVmType,\n TargetVmType extends RelayVmType = RelayVmType,\n>({\n logger,\n walletClient,\n ...params\n}: GetRelayQuoteParams<SourceVmType, TargetVmType>): Promise<\n RelayQuote<SourceVmType>\n> {\n const {\n actionParams,\n clientId,\n fromChainId,\n fromTokenAddress,\n options,\n recipientAddress,\n toChainId,\n toTokenAddress,\n userAddress,\n } = params\n\n try {\n const relayClient = getRelayClient()\n\n const txs = actionParams?.map((action) => {\n const data = encodeFunctionData({\n abi: action.contractAbi,\n args: action.functionArgs,\n functionName: action.functionName,\n })\n\n return {\n data,\n to: action.contractAddress,\n value: String(action.value ?? 0n),\n }\n })\n\n const isExactIn = params.tradeType === 'EXACT_INPUT'\n const queryTokenAmountBaseUnit = isExactIn\n ? params.fromTokenAmountBaseUnit\n : params.toTokenAmountBaseUnit\n const queryTokenAddress = isExactIn ? fromTokenAddress : toTokenAddress\n const queryTokenChainId = isExactIn ? fromChainId : toChainId\n\n const estUsdValue = await getQuoteEstUsdValue({\n tokenChainId: queryTokenChainId,\n tokenAddress: queryTokenAddress,\n tokenAmountBaseUnit: queryTokenAmountBaseUnit.toString(),\n logger,\n })\n\n const feeInfo = await getFunRelayFees({\n fromTokenAddress,\n fromChainId,\n toTokenAddress,\n toChainId,\n estUsdValue: Number(estUsdValue) || 0,\n clientId,\n })\n\n const appFeeBp = feeInfo.b + feeInfo.v\n\n logger.info('getRelayQuoteParams', {\n ...params,\n queryTokenAmountBaseUnit,\n txs,\n estUsdValue,\n feeInfo,\n appFeeBp,\n })\n\n // Get the full quote with fees\n const relayQuote = await relayClient.actions.getQuote({\n chainId: Number(fromChainId),\n toChainId: Number(toChainId),\n currency: convertFunToRelayTokenAddress(fromTokenAddress),\n toCurrency: convertFunToRelayTokenAddress(toTokenAddress),\n amount: queryTokenAmountBaseUnit.toString(),\n recipient: recipientAddress,\n tradeType: params.tradeType,\n user: userAddress,\n wallet: walletClient,\n ...(txs && { txs }),\n options: {\n referrer: clientId\n ? `${FUN_RELAY_REFERRER}|${clientId}`\n : FUN_RELAY_REFERRER,\n appFees: [\n {\n fee: appFeeBp.toString(),\n recipient: FUN_RELAY_REVENUE_WALLET,\n },\n ],\n ...options,\n },\n })\n\n logger.info('relayQuote', relayQuote)\n\n const estSubtotalUsd = Number(\n relayQuote.details?.currencyOut?.amountUsd || 0,\n )\n const estTotalUsd = Number(relayQuote.details?.currencyIn?.amountUsd || 0)\n // Get how much fromAmount is needed for the quote\n const fromAmountString =\n relayQuote.details?.currencyIn?.amountFormatted || '0'\n const fromAmountBaseUnitString =\n relayQuote.details?.currencyIn?.amount || '0'\n\n // RequestID will be consistent across steps in the quote\n // https://fun-xyz.slack.com/archives/C08MQ85QB2N/p1747774944603209\n const relayRequestId = relayQuote.steps[0]?.requestId\n\n // TODO: Verify with relay team if this is possible?\n if (!relayRequestId) {\n throw new Error('Relay quote does not contain a requestId')\n }\n\n // TODO: Verify with relay team if this is possible?\n if (!relayQuote.details?.currencyIn || !relayQuote.details?.currencyOut) {\n throw new Error('Relay quote does not contain trade details')\n }\n\n const {\n relayGasFeesUsd,\n totalLpFeesUsd,\n totalFeesUsd,\n totalFeesFromAmount,\n totalFeesFromAmountBaseUnit,\n } = parseRelayFees({ fees: relayQuote.fees, logger })\n\n const estSubtotalFromAmount = (\n Number.parseFloat(fromAmountString) - totalFeesFromAmount\n ).toString()\n\n const estSubtotalFromAmountBaseUnit = (\n BigInt(fromAmountBaseUnitString) - totalFeesFromAmountBaseUnit\n ).toString()\n\n return {\n quoteId: relayRequestId,\n estCheckoutTimeMs:\n (relayQuote.details.timeEstimate || 0) * 1000 +\n RELAY_QUOTE_CHECKOUT_TIME_BUFFER_MS,\n estFeesFromAmount: totalFeesFromAmount.toString(),\n estFeesFromAmountBaseUnit: totalFeesFromAmountBaseUnit.toString(),\n estFeesUsd: totalFeesUsd,\n estMarketMakerGasUsd: relayGasFeesUsd,\n estSubtotalFromAmount,\n estSubtotalFromAmountBaseUnit,\n estSubtotalUsd,\n estTotalFromAmount: fromAmountString,\n estTotalFromAmountBaseUnit: fromAmountBaseUnitString,\n estTotalUsd,\n finalToAmountBaseUnit: relayQuote.details.currencyOut.amount ?? '0', // TODO: Or do we want 'minimumAmount'?\n fromTokenAddress: fromTokenAddress as Address, // TODO: fromTokenAddress is typed as `0x${string}` why does not accept SolanaAddress\n lpFeePercentage: 0, // TODO: ?\n lpFeeUsd: totalLpFeesUsd,\n metadata: {\n fromAmountBaseUnit: isExactIn\n ? queryTokenAmountBaseUnit.toString()\n : (relayQuote.details.currencyIn.amount ?? '0'),\n relayQuote: relayQuote as RelayQuoteResult<SourceVmType>,\n toAmountBaseUnit: isExactIn\n ? (relayQuote.details.currencyOut.amount ?? '0')\n : queryTokenAmountBaseUnit.toString(),\n },\n }\n } catch (err) {\n throw new Error(\n `An error occurred trying to generate a relay quote: ${\n err instanceof Error ? err.message : JSON.stringify(err)\n }`,\n )\n }\n}\n", "import { MAINNET_RELAY_API } from '@reservoir0x/relay-sdk'\n\nexport interface RelayTokenInfo {\n chainId: number\n address: string\n symbol: string\n name: string\n decimals: number\n vmType: string\n metadata: {\n logoURI: string\n verified: boolean\n isNative: boolean\n }\n}\n\nexport async function getRelayAssetInfo({\n chainId,\n address,\n}: {\n chainId: string\n address: string\n}): Promise<RelayTokenInfo> {\n const url = `${MAINNET_RELAY_API}/currencies/v2`\n const body = {\n chainIds: [chainId],\n address,\n }\n const response = await fetch(url, {\n method: 'POST',\n headers: { 'Content-Type': 'application/json' },\n body: JSON.stringify(body),\n })\n if (!response.ok) {\n throw Error(response.statusText)\n }\n\n const data = await response.json()\n return data?.[0] as RelayTokenInfo\n}\n", "import type { AdaptedWallet } from '@reservoir0x/relay-sdk'\nimport { adaptSolanaWallet } from '@reservoir0x/relay-svm-wallet-adapter'\nimport {\n type Connection,\n SendTransactionError,\n type VersionedTransaction,\n} from '@solana/web3.js'\nimport { RELAY_SOLANA_CHAIN_ID_NUMBER } from './constants'\n\ntype Base58 =\n | '1'\n | '2'\n | '3'\n | '4'\n | '5'\n | '6'\n | '7'\n | '8'\n | '9'\n | 'A'\n | 'B'\n | 'C'\n | 'D'\n | 'E'\n | 'F'\n | 'G'\n | 'H'\n | 'J'\n | 'K'\n | 'L'\n | 'M'\n | 'N'\n | 'P'\n | 'Q'\n | 'R'\n | 'S'\n | 'T'\n | 'U'\n | 'V'\n | 'W'\n | 'X'\n | 'Y'\n | 'Z'\n | 'a'\n | 'b'\n | 'c'\n | 'd'\n | 'e'\n | 'f'\n | 'g'\n | 'h'\n | 'i'\n | 'j'\n | 'k'\n | 'm'\n | 'n'\n | 'o'\n | 'p'\n | 'q'\n | 'r'\n | 's'\n | 't'\n | 'u'\n | 'v'\n | 'w'\n | 'x'\n | 'y'\n | 'z'\n\nexport type SolanaAddress = `${Base58}${string}`\n\nexport type SolanaTxHash = `${Base58}${string}`\n\nexport type SolanaWallet = AdaptedWallet & {\n address(): Promise<SolanaAddress>\n}\n\nexport function getSolanaWallet(\n walletAddress: SolanaAddress,\n connection: Connection,\n signTransaction: (\n transaction: VersionedTransaction,\n ) => Promise<VersionedTransaction>,\n payerKey?: SolanaAddress,\n): SolanaWallet {\n return adaptSolanaWallet(\n walletAddress,\n RELAY_SOLANA_CHAIN_ID_NUMBER,\n connection,\n async (transaction, options) => {\n const signed = await signTransaction(transaction)\n try {\n const signature = await connection.sendTransaction(signed, {\n ...options,\n maxRetries: 5,\n })\n\n return { signature }\n } catch (error) {\n if (error instanceof SendTransactionError) {\n console.error(\n 'Failed transaction logs:',\n error,\n await error.getLogs(connection),\n )\n }\n\n throw error\n }\n },\n payerKey,\n ) as SolanaWallet\n}\n"],
|
|
5
|
+
"mappings": ";;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;;;ACAA,IAAAA,oBAOO;;;ACPP,uBAAyB;;;ACQlB,IAAM,+BAA+B;AACrC,IAAM,wBAAwB,GAAG,4BAA4B;AAK7D,IAAM,sBACX;AAKK,IAAM,qBACX;AAKK,IAAM,2BACX;AAKK,IAAM,qBAAqB;AAK3B,IAAM,sCAAsC;AAE5C,IAAM,0BAAkD;AAAA;AAAA;AAAA;AAI/D;;;AFnBO,SAAS,sBAAsB;AAAA,EACpC;AAAA,EACA;AAAA,EACA,GAAG;AACL,GAA6C;AAC3C,aAAO,gCAAa;AAAA,IAClB,GAAG;AAAA,IACH,YAAY;A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AAA,MACV,UAAU;AAAA,QACR,oBAAoB,YAChB,yBAAyB,SAAS,IACjC,WAAW,QAAQ,WAAW,UAAU;AAAA,QAC7C;AAAA,QACA,kBAAkB,YACb,WAAW,QAAQ,YAAY,UAAU,MAC1C,yBAAyB,SAAS;AAAA,MACxC;AAAA,IACF;AAAA,EACF,SAAS,KAAK;AACZ,UAAM,IAAI;AAAA,MACR,uDACE,eAAe,QAAQ,IAAI,UAAU,KAAK,UAAU,GAAG,CACzD;AAAA,IACF;AAAA,EACF;AACF;;;AE/RA,sCAAkC;AAClC,kBAIO;AAuEA,SAAS,gBACd,eACA,YACA,iBAGA,UACc;AACd,aAAO;AAAA,IACL;AAAA,IACA;AAAA,IACA;AAAA,IACA,OAAO,aAAa,YAAY;AAC9B,YAAM,SAAS,MAAM,gBAAgB,WAAW;AAChD,UAAI;AACF,cAAM,YAAY,MAAM,WAAW,gBAAgB,QAAQ;AAAA,UACzD,GAAG;AAAA,UACH,YAAY;AAAA,QACd,CAAC;AAED,eAAO,EAAE,UAAU;AAAA,MACrB,SAAS,OAAO;AACd,YAAI,iBAAiB,kCAAsB;AACzC,kBAAQ;AAAA,YACN;AAAA,YACA;AAAA,YACA,MAAM,MAAM,QAAQ,UAAU;AAAA,UAChC;AAAA,QACF;AAEA,cAAM;AAAA,MACR;AAAA,IACF;AAAA,IACA;AAAA,EACF;AACF;",
|
|
6
6
|
"names": ["import_relay_sdk", "import_relay_sdk", "import_relay_sdk", "import_relay_sdk"]
|
|
7
7
|
}
|
package/dist/index.mjs
CHANGED
|
@@ -57,6 +57,45 @@ function getRelayClient() {
|
|
|
57
57
|
import {
|
|
58
58
|
MAINNET_RELAY_API as MAINNET_RELAY_API2
|
|
59
59
|
} from "@reservoir0x/relay-sdk";
|
|
60
|
+
|
|
61
|
+
// src/utils.ts
|
|
62
|
+
function convertFunToRelayTokenAddress(address) {
|
|
63
|
+
if (address.toLowerCase() === FUNKIT_NATIVE_TOKEN.toLowerCase()) {
|
|
64
|
+
return RELAY_NATIVE_TOKEN;
|
|
65
|
+
}
|
|
66
|
+
return address;
|
|
67
|
+
}
|
|
68
|
+
function getRelayExecutionRefundState(info) {
|
|
69
|
+
switch (info.status) {
|
|
70
|
+
case "refund":
|
|
71
|
+
return "REFUNDED" /* REFUNDED */;
|
|
72
|
+
default:
|
|
73
|
+
return void 0;
|
|
74
|
+
}
|
|
75
|
+
}
|
|
76
|
+
function getRelayExecutionState(info) {
|
|
77
|
+
switch (info.status) {
|
|
78
|
+
case "success":
|
|
79
|
+
return "COMPLETED" /* COMPLETED */;
|
|
80
|
+
case "failure":
|
|
81
|
+
case "refund":
|
|
82
|
+
return "CHECKOUT_ERROR" /* CHECKOUT_ERROR */;
|
|
83
|
+
default:
|
|
84
|
+
return "PENDING_RECEIVAL" /* PENDING_RECEIVAL */;
|
|
85
|
+
}
|
|
86
|
+
}
|
|
87
|
+
function isRelayExecutionTerminalStatus(info) {
|
|
88
|
+
return RELAY_TERMINAL_STATUSES.includes(info.status);
|
|
89
|
+
}
|
|
90
|
+
function jsonStringifyWithBigIntSanitization(serializable) {
|
|
91
|
+
return JSON.stringify(
|
|
92
|
+
serializable,
|
|
93
|
+
(_, value) => typeof value === "bigint" ? `0x${value.toString(16)}` : value
|
|
94
|
+
// return everything else unchanged
|
|
95
|
+
);
|
|
96
|
+
}
|
|
97
|
+
|
|
98
|
+
// src/execution.ts
|
|
60
99
|
async function executeRelayQuote({
|
|
61
100
|
logger,
|
|
62
101
|
onConfirmed,
|
|
@@ -103,6 +142,16 @@ async function executeRelayQuote({
|
|
|
103
142
|
) {
|
|
104
143
|
logger.info(`${logPrefix}:completed`, txHashes);
|
|
105
144
|
const txHash = txHashes[0].txHash;
|
|
145
|
+
if (relayQuote.steps[0].requestId) {
|
|
146
|
+
manuallyRegisterIndex(logger, {
|
|
147
|
+
requestId: relayQuote.steps[0].requestId,
|
|
148
|
+
chainId: relayQuote.steps[0].items[0].data.chainId,
|
|
149
|
+
tx: jsonStringifyWithBigIntSanitization({
|
|
150
|
+
...relayQuote.steps[0].items[0].data,
|
|
151
|
+
txHash
|
|
152
|
+
})
|
|
153
|
+
});
|
|
154
|
+
}
|
|
106
155
|
await onConfirmed(txHash).catch((e) => {
|
|
107
156
|
logger.error(`${logPrefix}:onConfirmedFailed`, e);
|
|
108
157
|
});
|
|
@@ -110,6 +159,32 @@ async function executeRelayQuote({
|
|
|
110
159
|
}
|
|
111
160
|
});
|
|
112
161
|
}
|
|
162
|
+
async function manuallyRegisterIndex(logger, registerRequest) {
|
|
163
|
+
const stringifiedRequest = JSON.stringify(registerRequest);
|
|
164
|
+
const url = `${MAINNET_RELAY_API2}/transactions/single`;
|
|
165
|
+
try {
|
|
166
|
+
logger.info(`[registerIndexing] request: ${stringifiedRequest}`);
|
|
167
|
+
const response = await fetch(url, {
|
|
168
|
+
method: "POST",
|
|
169
|
+
body: JSON.stringify(registerRequest)
|
|
170
|
+
});
|
|
171
|
+
if (!response.ok) {
|
|
172
|
+
logger.error(
|
|
173
|
+
`Error sending request to manually register index: ${JSON.stringify(response)}`
|
|
174
|
+
);
|
|
175
|
+
return;
|
|
176
|
+
}
|
|
177
|
+
const data = await response.json();
|
|
178
|
+
if (data.message !== "Success") {
|
|
179
|
+
logger.error(`${data.message}. Params: ${stringifiedRequest}`);
|
|
180
|
+
}
|
|
181
|
+
return;
|
|
182
|
+
} catch (err) {
|
|
183
|
+
logger.error(
|
|
184
|
+
`Error sending request to register index at ${url}: ${JSON.stringify(err?.message)}. Params: ${stringifiedRequest}`
|
|
185
|
+
);
|
|
186
|
+
}
|
|
187
|
+
}
|
|
113
188
|
async function getRelayExecutionInfo(requestId) {
|
|
114
189
|
const url = `${MAINNET_RELAY_API2}/intents/status/v2?requestId=${requestId}`;
|
|
115
190
|
const response = await fetch(url);
|
|
@@ -217,36 +292,6 @@ async function getRelayAssetInfo({
|
|
|
217
292
|
return data?.[0];
|
|
218
293
|
}
|
|
219
294
|
|
|
220
|
-
// src/utils.ts
|
|
221
|
-
function convertFunToRelayTokenAddress(address) {
|
|
222
|
-
if (address.toLowerCase() === FUNKIT_NATIVE_TOKEN.toLowerCase()) {
|
|
223
|
-
return RELAY_NATIVE_TOKEN;
|
|
224
|
-
}
|
|
225
|
-
return address;
|
|
226
|
-
}
|
|
227
|
-
function getRelayExecutionRefundState(info) {
|
|
228
|
-
switch (info.status) {
|
|
229
|
-
case "refund":
|
|
230
|
-
return "REFUNDED" /* REFUNDED */;
|
|
231
|
-
default:
|
|
232
|
-
return void 0;
|
|
233
|
-
}
|
|
234
|
-
}
|
|
235
|
-
function getRelayExecutionState(info) {
|
|
236
|
-
switch (info.status) {
|
|
237
|
-
case "success":
|
|
238
|
-
return "COMPLETED" /* COMPLETED */;
|
|
239
|
-
case "failure":
|
|
240
|
-
case "refund":
|
|
241
|
-
return "CHECKOUT_ERROR" /* CHECKOUT_ERROR */;
|
|
242
|
-
default:
|
|
243
|
-
return "PENDING_RECEIVAL" /* PENDING_RECEIVAL */;
|
|
244
|
-
}
|
|
245
|
-
}
|
|
246
|
-
function isRelayExecutionTerminalStatus(info) {
|
|
247
|
-
return RELAY_TERMINAL_STATUSES.includes(info.status);
|
|
248
|
-
}
|
|
249
|
-
|
|
250
295
|
// src/quote.ts
|
|
251
296
|
async function getQuoteEstUsdValue({
|
|
252
297
|
tokenChainId,
|
package/dist/index.mjs.map
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"version": 3,
|
|
3
|
-
"sources": ["../src/client.ts", "../src/types.ts", "../src/constants.ts", "../src/execution.ts", "../src/
|
|
4
|
-
"sourcesContent": ["import {\n MAINNET_RELAY_API,\n type RelayClient,\n type RelayClientOptions,\n convertViemChainToRelayChain,\n createClient,\n getClient,\n} from '@reservoir0x/relay-sdk'\nimport type { Chain } from 'viem'\nimport { RELAY_SOLANA_CHAIN_ID_NUMBER } from './constants'\nimport type { Logger } from './types'\n\nexport type InitializeRelayClientParams = Omit<\n RelayClientOptions,\n 'baseApiUrl' | 'chains' | 'logger'\n> & {\n chains: Chain[]\n logger: Logger\n}\n\n/**\n * Initializes a global instance of the RelayClient\n * https://docs.relay.link/references/sdk/createClient\n */\nexport function initializeRelayClient({\n chains,\n logger,\n ...options\n}: InitializeRelayClientParams): RelayClient {\n return createClient({\n ...options,\n baseApiUrl: MAINNET_RELAY_API,\n chains: [\n ...chains.map(convertViemChainToRelayChain),\n {\n id: RELAY_SOLANA_CHAIN_ID_NUMBER,\n name: 'Solana',\n displayName: 'Solana',\n },\n ],\n logger: (message) => {\n logger.info('[RelayClient]:', message)\n },\n })\n}\n\n/**\n * Gets the global instance of the RelayClient\n */\nexport function getRelayClient(): RelayClient {\n const client = getClient()\n\n if (!client) {\n throw new Error('Relay client is not defined')\n }\n\n return client\n}\n", "import { LogLevel } from '@reservoir0x/relay-sdk'\nimport type { Abi, Address } from 'viem'\n\nexport { LogLevel }\n\n// https://docs.relay.link/references/api/get-intents-status-v2\nexport interface RelayExecutionInfo {\n status: RelayExecutionStatus\n details: string\n /** Incoming transaction hashes */\n inTxHashes: string[]\n /** Outgoing transaction hashes */\n txHashes: string[]\n /** The last timestamp the data was updated in milliseconds */\n time: number\n originChainId: number\n destinationChainId: number\n}\n\n// https://docs.relay.link/references/api/get-token-price\nexport interface RelayTokenPriceInfo {\n price: number\n}\n\n//// The types below are duplicated from @funkit/api-base atm, but this package should be used in BE as well\n//// TODO: Are we fine with BE importing @funkit/api-base and (by extension) @funkit/utils?\n//// See https://linear.app/funxyz/issue/PE-1342/sdk-extract-domainsrelayts-to-a-new-package#comment-d487d533\n\nexport interface Logger {\n error(message: string, data?: object): void\n info(message: string, data?: object): void\n}\n\n// Reference: https://github.com/reservoirprotocol/relay-kit/blob/211c645f9702a3b459ff545aa4e2e9d536c38455/packages/sdk/src/types/Execute.ts#L54-L61\nexport enum RelayExecutionStatus {\n DELAYED = 'delayed',\n FAILURE = 'failure',\n PENDING = 'pending',\n REFUND = 'refund',\n SUCCESS = 'success',\n WAITING = 'waiting',\n UNKNOWN = 'unknown',\n}\n\nexport interface ApiFunkitCheckoutActionParams {\n contractAbi: Abi\n contractAddress: Address\n functionName: string\n functionArgs: unknown[]\n value?: bigint\n}\n\nexport enum CheckoutRefundState {\n INITIATED = 'INITIATED',\n ERROR = 'ERROR',\n REFUNDED = 'REFUNDED',\n PROCEEDED = 'PROCEEDED',\n WAITING_FOR_FULFILLMENT = 'WAITING_FOR_FULFILLMENT',\n FULFILLED = 'FULFILLED',\n}\n\n// Reference from api server: https://github.com/fun-xyz/fun-api-server/blob/main/src/tables/FunWalletCheckout.ts#L11C1-L21C2\nexport enum CheckoutState {\n // In-progress States\n FROM_UNFUNDED = 'FROM_UNFUNDED',\n FROM_FUNDED = 'FROM_FUNDED',\n FROM_POOLED = 'FROM_POOLED',\n TO_UNFUNDED = 'TO_UNFUNDED',\n TO_FUNDED = 'TO_FUNDED',\n TO_POOLED = 'TO_POOLED',\n TO_READY = 'TO_READY',\n PENDING_RECEIVAL = 'PENDING_RECEIVAL',\n // Terminal States\n COMPLETED = 'COMPLETED',\n CHECKOUT_ERROR = 'CHECKOUT_ERROR',\n EXPIRED = 'EXPIRED',\n CANCELLED = 'CANCELLED',\n}\n\n// The response of the actual /checkout/quote api\nexport type CheckoutApiQuoteResponse = {\n quoteId: string\n estTotalFromAmountBaseUnit: string\n estSubtotalFromAmountBaseUnit: string\n estFeesFromAmountBaseUnit: string\n fromTokenAddress: Address\n estFeesUsd: number\n estSubtotalUsd: number\n estTotalUsd: number\n estCheckoutTimeMs: number\n estMarketMakerGasUsd: number\n lpFeePercentage: number\n lpFeeUsd: number\n}\n\n// The formatted response quote interface from the core sdk\nexport type CheckoutQuoteResponse = CheckoutApiQuoteResponse & {\n estTotalFromAmount: string\n estSubtotalFromAmount: string\n estFeesFromAmount: string\n\n // Any additional fields purely for frontend use\n metadata?: { [key: string]: unknown }\n}\n", "import type { Address } from 'viem'\nimport { RelayExecutionStatus } from './types'\n\n/**\n * Chain id that Relay uses to identify Solana\n *\n * See https://docs.relay.link/references/sdk/adapters#how-can-i-use-an-adapter%3F\n */\nexport const RELAY_SOLANA_CHAIN_ID_NUMBER = 792703809 // Why cannot Relay export this themselves... -.-\nexport const RELAY_SOLANA_CHAIN_ID = `${RELAY_SOLANA_CHAIN_ID_NUMBER}`\n\n/**\n * Fake address for a chain's native currency used by Funkit\n */\nexport const FUNKIT_NATIVE_TOKEN =\n '0xeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeee' satisfies Address\n\n/**\n * Fake address for a chain's native currency used by Relay\n */\nexport const RELAY_NATIVE_TOKEN =\n '0x0000000000000000000000000000000000000000' satisfies Address\n\n/**\n * Wallet that receives the app fees collected by Relay\n */\nexport const FUN_RELAY_REVENUE_WALLET =\n '0xb61562d83aEC43a050A06BED12Ac2bD8f9BFfd5E' satisfies Address\n\n/**\n * Referred field in Relay quote\n */\nexport const FUN_RELAY_REFERRER = 'funxyz'\n\n/**\n * Buffer added to Relay's time estimate (which sometimes is 0)\n */\nexport const RELAY_QUOTE_CHECKOUT_TIME_BUFFER_MS = 25_000 // 25 seconds\n\nexport const RELAY_TERMINAL_STATUSES: RelayExecutionStatus[] = [\n RelayExecutionStatus.REFUND,\n RelayExecutionStatus.FAILURE,\n RelayExecutionStatus.SUCCESS,\n]\n", "import {\n type AdaptedWallet,\n MAINNET_RELAY_API,\n type ProgressData,\n} from '@reservoir0x/relay-sdk'\nimport type { Address, Hex, WalletClient } from 'viem'\nimport { getRelayClient } from './client'\nimport type { RELAY_SOLANA_CHAIN_ID } from './constants'\nimport type { RelayQuoteResult } from './quote'\nimport type { SolanaAddress, SolanaTxHash, SolanaWallet } from './solana'\nimport type { Logger, RelayExecutionInfo } from './types'\n\nexport type RelayExecutionStep = ProgressData['currentStep'] & {}\n\nexport type RelayVmType = 'evm' | 'solana'\n\nexport type RelayAddress<VmType extends RelayVmType = RelayVmType> = {\n evm: Address\n solana: SolanaAddress\n}[VmType]\n\nexport type RelayChainId<VmType extends RelayVmType = RelayVmType> = {\n evm: string\n solana: typeof RELAY_SOLANA_CHAIN_ID\n}[VmType]\n\nexport type RelayTxHash<VmType extends RelayVmType = RelayVmType> = {\n evm: Hex\n solana: SolanaTxHash\n}[VmType]\n\nexport type RelayWallet<VmType extends RelayVmType = RelayVmType> = {\n evm: WalletClient | AdaptedWallet\n solana: SolanaWallet\n}[VmType]\n\nexport interface ExecuteRelayQuoteParams<VmType extends RelayVmType> {\n logger: Logger\n onConfirmed: (txHash: RelayTxHash<VmType>) => Promise<void>\n onError: (error: Error) => Promise<void>\n onProgress?: (step: RelayExecutionStep | null) => void\n relayQuote: RelayQuoteResult<VmType>\n walletClient: RelayWallet<VmType>\n}\n\nexport async function executeRelayQuote<VmType extends RelayVmType>({\n logger,\n onConfirmed,\n onError,\n onProgress,\n relayQuote,\n walletClient,\n}: ExecuteRelayQuoteParams<VmType>): Promise<void> {\n await getRelayClient().actions.execute({\n quote: relayQuote,\n wallet: walletClient,\n onProgress: async ({\n steps,\n fees,\n breakdown,\n currentStep,\n currentStepItem,\n txHashes,\n details,\n error,\n }) => {\n const logPrefix = 'onRelayProgress'\n logger.info(`${logPrefix}:params`, {\n steps,\n currentStep,\n fees,\n breakdown,\n currentStepItem,\n txHashes,\n details,\n error,\n })\n\n onProgress?.(currentStep ?? null)\n\n if (error) {\n logger.info(`${logPrefix}:errorDetected`, error)\n await onError(error).catch((e) => {\n logger.error(`${logPrefix}:onErrorFailed`, e)\n })\n } else if (\n // We can redirect as soon as all the required user step items have sent a transaction\n // Note that we are not actually waiting for a receipt / on-chain confirmation here\n // https://fun-xyz.slack.com/archives/C08MQ85QB2N/p1748381169792379\n txHashes?.length &&\n steps.every((step) => step.items.every((item) => item.txHashes?.length))\n ) {\n logger.info(`${logPrefix}:completed`, txHashes)\n // Can we assume its completed here?\n // Use first txHash as the main txHash in fun DE table\n const txHash = txHashes[0].txHash as RelayTxHash<VmType>\n await onConfirmed(txHash).catch((e) => {\n logger.error(`${logPrefix}:onConfirmedFailed`, e)\n })\n }\n },\n })\n}\n\nexport async function getRelayExecutionInfo(\n requestId: string,\n): Promise<RelayExecutionInfo> {\n const url = `${MAINNET_RELAY_API}/intents/status/v2?requestId=${requestId}`\n const response = await fetch(url)\n if (!response.ok) {\n throw Error(response.statusText)\n }\n\n const data = await response.json()\n return data as RelayExecutionInfo\n}\n", "import type { CallFees } from '@reservoir0x/relay-sdk'\nimport type { Logger } from './types'\n\nexport interface FunRelayFeeItem {\n b: number\n v: number\n}\n\nexport async function getFunRelayFees({\n fromTokenAddress,\n fromChainId,\n toTokenAddress,\n toChainId,\n estUsdValue,\n clientId,\n}: {\n fromTokenAddress: string\n fromChainId: string\n toTokenAddress: string\n toChainId: string\n estUsdValue: number\n clientId: string\n}): Promise<FunRelayFeeItem> {\n const url = `https://frog.fun.xyz/api/fee?fromTokenAddress=${fromTokenAddress}&fromChainId=${fromChainId}&toTokenAddress=${toTokenAddress}&toChainId=${toChainId}&estUsdValue=${estUsdValue}&clientId=${clientId}`\n const response = await fetch(url)\n if (!response.ok) {\n throw Error(response.statusText)\n }\n\n const data = await response.json()\n return data\n}\n\nexport function parseRelayFees({\n fees,\n logger,\n}: {\n fees: CallFees | undefined\n logger: Logger\n}) {\n // Gas fees, denominated in source chain native token\n const relayGasFeesUsd = Number.parseFloat(fees?.gas?.amountUsd || '0')\n\n // App fees, denominated in source chain token\n const funLpFeesUsd = Number.parseFloat(fees?.app?.amountUsd || '0')\n const funLpFeesFromAmount = Number.parseFloat(\n fees?.app?.amountFormatted || '0',\n )\n const funLpFeesFromAmountBaseUnit = BigInt(fees?.app?.amount || '0')\n\n // Relay fees, denominated in source chain token\n const relayLpFeesUsd = Number.parseFloat(fees?.relayer?.amountUsd || '0')\n const relayLpFeesFromAmount = Number.parseFloat(\n fees?.relayer?.amountFormatted || '0',\n )\n const relayLpFeesFromAmountBaseUnit = BigInt(fees?.relayer?.amount || '0')\n\n const totalLpFeesUsd = funLpFeesUsd + relayLpFeesUsd\n const totalLpFeesFromAmount = funLpFeesFromAmount + relayLpFeesFromAmount\n const totalLpFeesFromAmountBaseUnit =\n funLpFeesFromAmountBaseUnit + relayLpFeesFromAmountBaseUnit\n\n logger.info('parseRelayFees', {\n relayGasFeesUsd,\n funLpFeesUsd,\n funLpFeesFromAmount,\n funLpFeesFromAmountBaseUnit,\n relayLpFeesUsd,\n relayLpFeesFromAmount,\n relayLpFeesFromAmountBaseUnit,\n totalLpFeesUsd,\n totalLpFeesFromAmount,\n totalLpFeesFromAmountBaseUnit,\n })\n\n return {\n relayGasFeesUsd,\n totalLpFeesUsd,\n totalFeesUsd: relayGasFeesUsd + totalLpFeesUsd,\n totalFeesFromAmount: totalLpFeesFromAmount,\n totalFeesFromAmountBaseUnit: totalLpFeesFromAmountBaseUnit,\n }\n}\n", "import { MAINNET_RELAY_API } from '@reservoir0x/relay-sdk'\nimport type { RelayTokenPriceInfo } from './types'\n\nexport async function getRelayAssetPriceInfo({\n chainId,\n address,\n}: {\n chainId: string\n address: string\n}): Promise<RelayTokenPriceInfo> {\n const url = `${MAINNET_RELAY_API}/currencies/token/price?chainId=${chainId}&address=${address}`\n const response = await fetch(url)\n if (!response.ok) {\n throw Error(response.statusText)\n }\n\n const data = await response.json()\n return data as RelayTokenPriceInfo\n}\n", "import type { Execute, GetQuoteParameters } from '@reservoir0x/relay-sdk'\nimport { type Address, encodeFunctionData } from 'viem'\nimport { getRelayClient } from './client'\nimport {\n FUN_RELAY_REFERRER,\n FUN_RELAY_REVENUE_WALLET,\n RELAY_QUOTE_CHECKOUT_TIME_BUFFER_MS,\n} from './constants'\nimport { getRelayAssetInfo } from './currency'\nimport type {\n RelayAddress,\n RelayChainId,\n RelayVmType,\n RelayWallet,\n} from './execution'\nimport { getFunRelayFees, parseRelayFees } from './fees'\nimport { getRelayAssetPriceInfo } from './price'\nimport type {\n ApiFunkitCheckoutActionParams,\n CheckoutQuoteResponse,\n Logger,\n} from './types'\nimport { convertFunToRelayTokenAddress } from './utils'\n\ntype RelayQuoteOptions = GetQuoteParameters['options'] & {}\n\nexport type RelayQuoteResult<VmType extends RelayVmType> = Execute & {\n __vm: VmType\n}\n\nexport type GetRelayQuoteParams<\n SourceVmType extends RelayVmType = RelayVmType,\n TargetVmType extends RelayVmType = RelayVmType,\n> = {\n actionParams?: ApiFunkitCheckoutActionParams[]\n clientId: string\n fromChainId: RelayChainId<SourceVmType>\n fromTokenAddress: RelayAddress<SourceVmType>\n logger: Logger\n /**\n * {@link getRelayQuote} already sets {@link RelayQuoteOptions.appFees|appFees} and {@link RelayQuoteOptions.referrer|referrer}.\n * Only include them if you wish to override.\n */\n options?: RelayQuoteOptions\n recipientAddress: RelayAddress<TargetVmType> | undefined\n toChainId: RelayChainId<TargetVmType>\n toTokenAddress: RelayAddress<TargetVmType>\n tradeType: 'EXACT_INPUT' | 'EXACT_OUTPUT' | 'EXPECTED_OUTPUT'\n userAddress: RelayAddress<SourceVmType> | undefined\n walletClient?: RelayWallet<SourceVmType>\n} & (\n | {\n fromTokenAmountBaseUnit: bigint | string\n tradeType: 'EXACT_INPUT'\n }\n | {\n toTokenAmountBaseUnit: bigint | string\n tradeType: 'EXACT_OUTPUT' | 'EXPECTED_OUTPUT'\n }\n)\n\nexport type RelayQuote<VmType extends RelayVmType = RelayVmType> =\n CheckoutQuoteResponse & {\n /** Required for EXACT_INPUT checkouts */\n finalToAmountBaseUnit: string\n metadata: {\n fromAmountBaseUnit: string\n relayQuote: RelayQuoteResult<VmType>\n toAmountBaseUnit: string\n }\n }\n\nasync function getQuoteEstUsdValue({\n tokenChainId,\n tokenAddress,\n tokenAmountBaseUnit,\n logger,\n}: {\n tokenChainId: string\n tokenAddress: string\n tokenAmountBaseUnit: string\n logger: Logger\n}) {\n try {\n const [tokenPriceRes, tokenInfoRes] = await Promise.all([\n getRelayAssetPriceInfo({\n chainId: tokenChainId,\n address: convertFunToRelayTokenAddress(tokenAddress as Address),\n }),\n getRelayAssetInfo({\n chainId: tokenChainId,\n address: convertFunToRelayTokenAddress(tokenAddress as Address),\n }),\n ])\n\n const price = tokenPriceRes.price\n const decimals = tokenInfoRes.decimals\n\n const absoluteAmount = BigInt(tokenAmountBaseUnit) / BigInt(10 ** decimals)\n return Number(price) * Number(absoluteAmount)\n } catch (err) {\n logger.error('getQuoteEstUsdValueError', {\n message: `Failed to get USD value for token ${tokenAddress} on chain ${tokenChainId}: ${\n err instanceof Error ? err.message : JSON.stringify(err)\n }. Falling back to 0 USD.`,\n })\n // If any part fails, just fallback to 0 USD so that we do not block quote\n return 0\n }\n}\n\nexport async function getRelayQuote<\n SourceVmType extends RelayVmType,\n TargetVmType extends RelayVmType = RelayVmType,\n>({\n logger,\n walletClient,\n ...params\n}: GetRelayQuoteParams<SourceVmType, TargetVmType>): Promise<\n RelayQuote<SourceVmType>\n> {\n const {\n actionParams,\n clientId,\n fromChainId,\n fromTokenAddress,\n options,\n recipientAddress,\n toChainId,\n toTokenAddress,\n userAddress,\n } = params\n\n try {\n const relayClient = getRelayClient()\n\n const txs = actionParams?.map((action) => {\n const data = encodeFunctionData({\n abi: action.contractAbi,\n args: action.functionArgs,\n functionName: action.functionName,\n })\n\n return {\n data,\n to: action.contractAddress,\n value: String(action.value ?? 0n),\n }\n })\n\n const isExactIn = params.tradeType === 'EXACT_INPUT'\n const queryTokenAmountBaseUnit = isExactIn\n ? params.fromTokenAmountBaseUnit\n : params.toTokenAmountBaseUnit\n const queryTokenAddress = isExactIn ? fromTokenAddress : toTokenAddress\n const queryTokenChainId = isExactIn ? fromChainId : toChainId\n\n const estUsdValue = await getQuoteEstUsdValue({\n tokenChainId: queryTokenChainId,\n tokenAddress: queryTokenAddress,\n tokenAmountBaseUnit: queryTokenAmountBaseUnit.toString(),\n logger,\n })\n\n const feeInfo = await getFunRelayFees({\n fromTokenAddress,\n fromChainId,\n toTokenAddress,\n toChainId,\n estUsdValue: Number(estUsdValue) || 0,\n clientId,\n })\n\n const appFeeBp = feeInfo.b + feeInfo.v\n\n logger.info('getRelayQuoteParams', {\n ...params,\n queryTokenAmountBaseUnit,\n txs,\n estUsdValue,\n feeInfo,\n appFeeBp,\n })\n\n // Get the full quote with fees\n const relayQuote = await relayClient.actions.getQuote({\n chainId: Number(fromChainId),\n toChainId: Number(toChainId),\n currency: convertFunToRelayTokenAddress(fromTokenAddress),\n toCurrency: convertFunToRelayTokenAddress(toTokenAddress),\n amount: queryTokenAmountBaseUnit.toString(),\n recipient: recipientAddress,\n tradeType: params.tradeType,\n user: userAddress,\n wallet: walletClient,\n ...(txs && { txs }),\n options: {\n referrer: clientId\n ? `${FUN_RELAY_REFERRER}|${clientId}`\n : FUN_RELAY_REFERRER,\n appFees: [\n {\n fee: appFeeBp.toString(),\n recipient: FUN_RELAY_REVENUE_WALLET,\n },\n ],\n ...options,\n },\n })\n\n logger.info('relayQuote', relayQuote)\n\n const estSubtotalUsd = Number(\n relayQuote.details?.currencyOut?.amountUsd || 0,\n )\n const estTotalUsd = Number(relayQuote.details?.currencyIn?.amountUsd || 0)\n // Get how much fromAmount is needed for the quote\n const fromAmountString =\n relayQuote.details?.currencyIn?.amountFormatted || '0'\n const fromAmountBaseUnitString =\n relayQuote.details?.currencyIn?.amount || '0'\n\n // RequestID will be consistent across steps in the quote\n // https://fun-xyz.slack.com/archives/C08MQ85QB2N/p1747774944603209\n const relayRequestId = relayQuote.steps[0]?.requestId\n\n // TODO: Verify with relay team if this is possible?\n if (!relayRequestId) {\n throw new Error('Relay quote does not contain a requestId')\n }\n\n // TODO: Verify with relay team if this is possible?\n if (!relayQuote.details?.currencyIn || !relayQuote.details?.currencyOut) {\n throw new Error('Relay quote does not contain trade details')\n }\n\n const {\n relayGasFeesUsd,\n totalLpFeesUsd,\n totalFeesUsd,\n totalFeesFromAmount,\n totalFeesFromAmountBaseUnit,\n } = parseRelayFees({ fees: relayQuote.fees, logger })\n\n const estSubtotalFromAmount = (\n Number.parseFloat(fromAmountString) - totalFeesFromAmount\n ).toString()\n\n const estSubtotalFromAmountBaseUnit = (\n BigInt(fromAmountBaseUnitString) - totalFeesFromAmountBaseUnit\n ).toString()\n\n return {\n quoteId: relayRequestId,\n estCheckoutTimeMs:\n (relayQuote.details.timeEstimate || 0) * 1000 +\n RELAY_QUOTE_CHECKOUT_TIME_BUFFER_MS,\n estFeesFromAmount: totalFeesFromAmount.toString(),\n estFeesFromAmountBaseUnit: totalFeesFromAmountBaseUnit.toString(),\n estFeesUsd: totalFeesUsd,\n estMarketMakerGasUsd: relayGasFeesUsd,\n estSubtotalFromAmount,\n estSubtotalFromAmountBaseUnit,\n estSubtotalUsd,\n estTotalFromAmount: fromAmountString,\n estTotalFromAmountBaseUnit: fromAmountBaseUnitString,\n estTotalUsd,\n finalToAmountBaseUnit: relayQuote.details.currencyOut.amount ?? '0', // TODO: Or do we want 'minimumAmount'?\n fromTokenAddress: fromTokenAddress as Address, // TODO: fromTokenAddress is typed as `0x${string}` why does not accept SolanaAddress\n lpFeePercentage: 0, // TODO: ?\n lpFeeUsd: totalLpFeesUsd,\n metadata: {\n fromAmountBaseUnit: isExactIn\n ? queryTokenAmountBaseUnit.toString()\n : (relayQuote.details.currencyIn.amount ?? '0'),\n relayQuote: relayQuote as RelayQuoteResult<SourceVmType>,\n toAmountBaseUnit: isExactIn\n ? (relayQuote.details.currencyOut.amount ?? '0')\n : queryTokenAmountBaseUnit.toString(),\n },\n }\n } catch (err) {\n throw new Error(\n `An error occurred trying to generate a relay quote: ${\n err instanceof Error ? err.message : JSON.stringify(err)\n }`,\n )\n }\n}\n", "import { MAINNET_RELAY_API } from '@reservoir0x/relay-sdk'\n\nexport interface RelayTokenInfo {\n chainId: number\n address: string\n symbol: string\n name: string\n decimals: number\n vmType: string\n metadata: {\n logoURI: string\n verified: boolean\n isNative: boolean\n }\n}\n\nexport async function getRelayAssetInfo({\n chainId,\n address,\n}: {\n chainId: string\n address: string\n}): Promise<RelayTokenInfo> {\n const url = `${MAINNET_RELAY_API}/currencies/v2`\n const body = {\n chainIds: [chainId],\n address,\n }\n const response = await fetch(url, {\n method: 'POST',\n headers: { 'Content-Type': 'application/json' },\n body: JSON.stringify(body),\n })\n if (!response.ok) {\n throw Error(response.statusText)\n }\n\n const data = await response.json()\n return data?.[0] as RelayTokenInfo\n}\n", "import {\n FUNKIT_NATIVE_TOKEN,\n RELAY_NATIVE_TOKEN,\n RELAY_TERMINAL_STATUSES,\n} from './constants'\nimport type { RelayAddress, RelayVmType } from './execution'\nimport {\n CheckoutRefundState,\n CheckoutState,\n type RelayExecutionInfo,\n} from './types'\n\n/**\n * Converts a token address within Funkit the corresponding Relay token address.\n */\nexport function convertFunToRelayTokenAddress<T extends RelayVmType>(\n address: RelayAddress<T>,\n): RelayAddress<T> {\n if (address.toLowerCase() === FUNKIT_NATIVE_TOKEN.toLowerCase()) {\n return RELAY_NATIVE_TOKEN as RelayAddress<T>\n }\n\n return address\n}\n\nexport function getRelayExecutionRefundState(\n info: RelayExecutionInfo,\n): CheckoutRefundState | undefined {\n switch (info.status) {\n case 'refund':\n return CheckoutRefundState.REFUNDED\n default:\n return undefined\n }\n}\n\nexport function getRelayExecutionState(\n info: RelayExecutionInfo,\n): CheckoutState {\n switch (info.status) {\n case 'success':\n return CheckoutState.COMPLETED\n case 'failure':\n case 'refund':\n return CheckoutState.CHECKOUT_ERROR\n default:\n return CheckoutState.PENDING_RECEIVAL\n }\n}\n\n/**\n * Checks whether the Relay execution has reached a terminal status.\n */\nexport function isRelayExecutionTerminalStatus(\n info: RelayExecutionInfo,\n): boolean {\n return RELAY_TERMINAL_STATUSES.includes(info.status)\n}\n", "import type { AdaptedWallet } from '@reservoir0x/relay-sdk'\nimport { adaptSolanaWallet } from '@reservoir0x/relay-svm-wallet-adapter'\nimport {\n type Connection,\n SendTransactionError,\n type VersionedTransaction,\n} from '@solana/web3.js'\nimport { RELAY_SOLANA_CHAIN_ID_NUMBER } from './constants'\n\ntype Base58 =\n | '1'\n | '2'\n | '3'\n | '4'\n | '5'\n | '6'\n | '7'\n | '8'\n | '9'\n | 'A'\n | 'B'\n | 'C'\n | 'D'\n | 'E'\n | 'F'\n | 'G'\n | 'H'\n | 'J'\n | 'K'\n | 'L'\n | 'M'\n | 'N'\n | 'P'\n | 'Q'\n | 'R'\n | 'S'\n | 'T'\n | 'U'\n | 'V'\n | 'W'\n | 'X'\n | 'Y'\n | 'Z'\n | 'a'\n | 'b'\n | 'c'\n | 'd'\n | 'e'\n | 'f'\n | 'g'\n | 'h'\n | 'i'\n | 'j'\n | 'k'\n | 'm'\n | 'n'\n | 'o'\n | 'p'\n | 'q'\n | 'r'\n | 's'\n | 't'\n | 'u'\n | 'v'\n | 'w'\n | 'x'\n | 'y'\n | 'z'\n\nexport type SolanaAddress = `${Base58}${string}`\n\nexport type SolanaTxHash = `${Base58}${string}`\n\nexport type SolanaWallet = AdaptedWallet & {\n address(): Promise<SolanaAddress>\n}\n\nexport function getSolanaWallet(\n walletAddress: SolanaAddress,\n connection: Connection,\n signTransaction: (\n transaction: VersionedTransaction,\n ) => Promise<VersionedTransaction>,\n payerKey?: SolanaAddress,\n): SolanaWallet {\n return adaptSolanaWallet(\n walletAddress,\n RELAY_SOLANA_CHAIN_ID_NUMBER,\n connection,\n async (transaction, options) => {\n const signed = await signTransaction(transaction)\n try {\n const signature = await connection.sendTransaction(signed, {\n ...options,\n maxRetries: 5,\n })\n\n return { signature }\n } catch (error) {\n if (error instanceof SendTransactionError) {\n console.error(\n 'Failed transaction logs:',\n error,\n await error.getLogs(connection),\n )\n }\n\n throw error\n }\n },\n payerKey,\n ) as SolanaWallet\n}\n"],
|
|
5
|
-
"mappings": ";AAAA;AAAA,EACE;AAAA,EAGA;AAAA,EACA;AAAA,EACA;AAAA,OACK;;;ACPP,SAAS,gBAAgB;;;ACQlB,IAAM,+BAA+B;AACrC,IAAM,wBAAwB,GAAG,4BAA4B;AAK7D,IAAM,sBACX;AAKK,IAAM,qBACX;AAKK,IAAM,2BACX;AAKK,IAAM,qBAAqB;AAK3B,IAAM,sCAAsC;AAE5C,IAAM,0BAAkD;AAAA;AAAA;AAAA;AAI/D;;;AFnBO,SAAS,sBAAsB;AAAA,EACpC;AAAA,EACA;AAAA,EACA,GAAG;AACL,GAA6C;AAC3C,SAAO,aAAa;AAAA,IAClB,GAAG;AAAA,IACH,YAAY;AAAA,IACZ,QAAQ;AAAA,MACN,GAAG,OAAO,IAAI,4BAA4B;AAAA,MAC1C;AAAA,QACE,IAAI;AAAA,QACJ,MAAM;AAAA,QACN,aAAa;AAAA,MACf;AAAA,IACF;AAAA,IACA,QAAQ,CAAC,YAAY;AACnB,aAAO,KAAK,kBAAkB,OAAO;AAAA,IACvC;AAAA,EACF,CAAC;AACH;AAKO,SAAS,iBAA8B;AAC5C,QAAM,SAAS,UAAU;AAEzB,MAAI,CAAC,QAAQ;AACX,UAAM,IAAI,MAAM,6BAA6B;AAAA,EAC/C;AAEA,SAAO;AACT;;;AGzDA;AAAA,EAEE,qBAAAA;AAAA,OAEK;
|
|
3
|
+
"sources": ["../src/client.ts", "../src/types.ts", "../src/constants.ts", "../src/execution.ts", "../src/utils.ts", "../src/fees.ts", "../src/price.ts", "../src/quote.ts", "../src/currency.ts", "../src/solana.ts"],
|
|
4
|
+
"sourcesContent": ["import {\n MAINNET_RELAY_API,\n type RelayClient,\n type RelayClientOptions,\n convertViemChainToRelayChain,\n createClient,\n getClient,\n} from '@reservoir0x/relay-sdk'\nimport type { Chain } from 'viem'\nimport { RELAY_SOLANA_CHAIN_ID_NUMBER } from './constants'\nimport type { Logger } from './types'\n\nexport type InitializeRelayClientParams = Omit<\n RelayClientOptions,\n 'baseApiUrl' | 'chains' | 'logger'\n> & {\n chains: Chain[]\n logger: Logger\n}\n\n/**\n * Initializes a global instance of the RelayClient\n * https://docs.relay.link/references/sdk/createClient\n */\nexport function initializeRelayClient({\n chains,\n logger,\n ...options\n}: InitializeRelayClientParams): RelayClient {\n return createClient({\n ...options,\n baseApiUrl: MAINNET_RELAY_API,\n chains: [\n ...chains.map(convertViemChainToRelayChain),\n {\n id: RELAY_SOLANA_CHAIN_ID_NUMBER,\n name: 'Solana',\n displayName: 'Solana',\n },\n ],\n logger: (message) => {\n logger.info('[RelayClient]:', message)\n },\n })\n}\n\n/**\n * Gets the global instance of the RelayClient\n */\nexport function getRelayClient(): RelayClient {\n const client = getClient()\n\n if (!client) {\n throw new Error('Relay client is not defined')\n }\n\n return client\n}\n", "import { LogLevel } from '@reservoir0x/relay-sdk'\nimport type { Abi, Address } from 'viem'\n\nexport { LogLevel }\n\n// https://docs.relay.link/references/api/get-intents-status-v2\nexport interface RelayExecutionInfo {\n status: RelayExecutionStatus\n details: string\n /** Incoming transaction hashes */\n inTxHashes: string[]\n /** Outgoing transaction hashes */\n txHashes: string[]\n /** The last timestamp the data was updated in milliseconds */\n time: number\n originChainId: number\n destinationChainId: number\n}\n\n// https://docs.relay.link/references/api/get-token-price\nexport interface RelayTokenPriceInfo {\n price: number\n}\n\n//// The types below are duplicated from @funkit/api-base atm, but this package should be used in BE as well\n//// TODO: Are we fine with BE importing @funkit/api-base and (by extension) @funkit/utils?\n//// See https://linear.app/funxyz/issue/PE-1342/sdk-extract-domainsrelayts-to-a-new-package#comment-d487d533\n\nexport interface Logger {\n error(message: string, data?: object): void\n info(message: string, data?: object): void\n}\n\n// Reference: https://github.com/reservoirprotocol/relay-kit/blob/211c645f9702a3b459ff545aa4e2e9d536c38455/packages/sdk/src/types/Execute.ts#L54-L61\nexport enum RelayExecutionStatus {\n DELAYED = 'delayed',\n FAILURE = 'failure',\n PENDING = 'pending',\n REFUND = 'refund',\n SUCCESS = 'success',\n WAITING = 'waiting',\n UNKNOWN = 'unknown',\n}\n\nexport interface ApiFunkitCheckoutActionParams {\n contractAbi: Abi\n contractAddress: Address\n functionName: string\n functionArgs: unknown[]\n value?: bigint\n}\n\nexport enum CheckoutRefundState {\n INITIATED = 'INITIATED',\n ERROR = 'ERROR',\n REFUNDED = 'REFUNDED',\n PROCEEDED = 'PROCEEDED',\n WAITING_FOR_FULFILLMENT = 'WAITING_FOR_FULFILLMENT',\n FULFILLED = 'FULFILLED',\n}\n\n// Reference from api server: https://github.com/fun-xyz/fun-api-server/blob/main/src/tables/FunWalletCheckout.ts#L11C1-L21C2\nexport enum CheckoutState {\n // In-progress States\n FROM_UNFUNDED = 'FROM_UNFUNDED',\n FROM_FUNDED = 'FROM_FUNDED',\n FROM_POOLED = 'FROM_POOLED',\n TO_UNFUNDED = 'TO_UNFUNDED',\n TO_FUNDED = 'TO_FUNDED',\n TO_POOLED = 'TO_POOLED',\n TO_READY = 'TO_READY',\n PENDING_RECEIVAL = 'PENDING_RECEIVAL',\n // Terminal States\n COMPLETED = 'COMPLETED',\n CHECKOUT_ERROR = 'CHECKOUT_ERROR',\n EXPIRED = 'EXPIRED',\n CANCELLED = 'CANCELLED',\n}\n\n// The response of the actual /checkout/quote api\nexport type CheckoutApiQuoteResponse = {\n quoteId: string\n estTotalFromAmountBaseUnit: string\n estSubtotalFromAmountBaseUnit: string\n estFeesFromAmountBaseUnit: string\n fromTokenAddress: Address\n estFeesUsd: number\n estSubtotalUsd: number\n estTotalUsd: number\n estCheckoutTimeMs: number\n estMarketMakerGasUsd: number\n lpFeePercentage: number\n lpFeeUsd: number\n}\n\n// The formatted response quote interface from the core sdk\nexport type CheckoutQuoteResponse = CheckoutApiQuoteResponse & {\n estTotalFromAmount: string\n estSubtotalFromAmount: string\n estFeesFromAmount: string\n\n // Any additional fields purely for frontend use\n metadata?: { [key: string]: unknown }\n}\n", "import type { Address } from 'viem'\nimport { RelayExecutionStatus } from './types'\n\n/**\n * Chain id that Relay uses to identify Solana\n *\n * See https://docs.relay.link/references/sdk/adapters#how-can-i-use-an-adapter%3F\n */\nexport const RELAY_SOLANA_CHAIN_ID_NUMBER = 792703809 // Why cannot Relay export this themselves... -.-\nexport const RELAY_SOLANA_CHAIN_ID = `${RELAY_SOLANA_CHAIN_ID_NUMBER}`\n\n/**\n * Fake address for a chain's native currency used by Funkit\n */\nexport const FUNKIT_NATIVE_TOKEN =\n '0xeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeee' satisfies Address\n\n/**\n * Fake address for a chain's native currency used by Relay\n */\nexport const RELAY_NATIVE_TOKEN =\n '0x0000000000000000000000000000000000000000' satisfies Address\n\n/**\n * Wallet that receives the app fees collected by Relay\n */\nexport const FUN_RELAY_REVENUE_WALLET =\n '0xb61562d83aEC43a050A06BED12Ac2bD8f9BFfd5E' satisfies Address\n\n/**\n * Referred field in Relay quote\n */\nexport const FUN_RELAY_REFERRER = 'funxyz'\n\n/**\n * Buffer added to Relay's time estimate (which sometimes is 0)\n */\nexport const RELAY_QUOTE_CHECKOUT_TIME_BUFFER_MS = 25_000 // 25 seconds\n\nexport const RELAY_TERMINAL_STATUSES: RelayExecutionStatus[] = [\n RelayExecutionStatus.REFUND,\n RelayExecutionStatus.FAILURE,\n RelayExecutionStatus.SUCCESS,\n]\n", "import {\n type AdaptedWallet,\n MAINNET_RELAY_API,\n type ProgressData,\n} from '@reservoir0x/relay-sdk'\nimport type { Address, Hex, WalletClient } from 'viem'\nimport { getRelayClient } from './client'\nimport type { RELAY_SOLANA_CHAIN_ID } from './constants'\nimport type { RelayQuoteResult } from './quote'\nimport type { SolanaAddress, SolanaTxHash, SolanaWallet } from './solana'\nimport type { Logger, RelayExecutionInfo } from './types'\nimport { jsonStringifyWithBigIntSanitization } from './utils'\n\nexport type RelayExecutionStep = ProgressData['currentStep'] & {}\n\nexport type RelayVmType = 'evm' | 'solana'\n\nexport type RelayAddress<VmType extends RelayVmType = RelayVmType> = {\n evm: Address\n solana: SolanaAddress\n}[VmType]\n\nexport type RelayChainId<VmType extends RelayVmType = RelayVmType> = {\n evm: string\n solana: typeof RELAY_SOLANA_CHAIN_ID\n}[VmType]\n\nexport type RelayTxHash<VmType extends RelayVmType = RelayVmType> = {\n evm: Hex\n solana: SolanaTxHash\n}[VmType]\n\nexport type RelayWallet<VmType extends RelayVmType = RelayVmType> = {\n evm: WalletClient | AdaptedWallet\n solana: SolanaWallet\n}[VmType]\n\nexport interface ExecuteRelayQuoteParams<VmType extends RelayVmType> {\n logger: Logger\n onConfirmed: (txHash: RelayTxHash<VmType>) => Promise<void>\n onError: (error: Error) => Promise<void>\n onProgress?: (step: RelayExecutionStep | null) => void\n relayQuote: RelayQuoteResult<VmType>\n walletClient: RelayWallet<VmType>\n}\n\nexport async function executeRelayQuote<VmType extends RelayVmType>({\n logger,\n onConfirmed,\n onError,\n onProgress,\n relayQuote,\n walletClient,\n}: ExecuteRelayQuoteParams<VmType>): Promise<void> {\n await getRelayClient().actions.execute({\n quote: relayQuote,\n wallet: walletClient,\n onProgress: async ({\n steps,\n fees,\n breakdown,\n currentStep,\n currentStepItem,\n txHashes,\n details,\n error,\n }) => {\n const logPrefix = 'onRelayProgress'\n logger.info(`${logPrefix}:params`, {\n steps,\n currentStep,\n fees,\n breakdown,\n currentStepItem,\n txHashes,\n details,\n error,\n })\n\n onProgress?.(currentStep ?? null)\n\n if (error) {\n logger.info(`${logPrefix}:errorDetected`, error)\n await onError(error).catch((e) => {\n logger.error(`${logPrefix}:onErrorFailed`, e)\n })\n } else if (\n // We can redirect as soon as all the required user step items have sent a transaction\n // Note that we are not actually waiting for a receipt / on-chain confirmation here\n // https://fun-xyz.slack.com/archives/C08MQ85QB2N/p1748381169792379\n txHashes?.length &&\n steps.every((step) => step.items.every((item) => item.txHashes?.length))\n ) {\n logger.info(`${logPrefix}:completed`, txHashes)\n // Can we assume its completed here?\n // Use first txHash as the main txHash in fun DE table\n const txHash = txHashes[0].txHash as RelayTxHash<VmType>\n\n // fire and forget index registration\n if (relayQuote.steps[0].requestId) {\n manuallyRegisterIndex(logger, {\n requestId: relayQuote.steps[0].requestId,\n chainId: relayQuote.steps[0].items[0].data.chainId,\n tx: jsonStringifyWithBigIntSanitization({\n ...relayQuote.steps[0].items[0].data,\n txHash,\n }),\n })\n }\n await onConfirmed(txHash).catch((e) => {\n logger.error(`${logPrefix}:onConfirmedFailed`, e)\n })\n }\n },\n })\n}\n\nexport interface PostRegistrationRequest {\n requestId: string\n chainId: string\n tx: string\n}\n\nexport type RegisterIndexingResponse =\n | { success: never; message: 'Success' }\n | { success: false; message: string }\n\nexport async function manuallyRegisterIndex(\n logger: Logger,\n registerRequest: PostRegistrationRequest,\n): Promise<void> {\n const stringifiedRequest = JSON.stringify(registerRequest)\n const url = `${MAINNET_RELAY_API}/transactions/single`\n try {\n logger.info(`[registerIndexing] request: ${stringifiedRequest}`)\n const response = await fetch(url, {\n method: 'POST',\n body: JSON.stringify(registerRequest),\n })\n if (!response.ok) {\n logger.error(\n `Error sending request to manually register index: ${JSON.stringify(response)}`,\n )\n return\n }\n\n const data = (await response.json()) as RegisterIndexingResponse\n if (data.message !== 'Success') {\n logger.error(`${data.message}. Params: ${stringifiedRequest}`)\n }\n return\n } catch (err) {\n logger.error(\n `Error sending request to register index at ${url}: ${JSON.stringify((err as Error)?.message)}. Params: ${stringifiedRequest}`,\n )\n }\n}\n\nexport async function getRelayExecutionInfo(\n requestId: string,\n): Promise<RelayExecutionInfo> {\n const url = `${MAINNET_RELAY_API}/intents/status/v2?requestId=${requestId}`\n const response = await fetch(url)\n if (!response.ok) {\n throw Error(response.statusText)\n }\n\n const data = await response.json()\n return data as RelayExecutionInfo\n}\n", "import {\n FUNKIT_NATIVE_TOKEN,\n RELAY_NATIVE_TOKEN,\n RELAY_TERMINAL_STATUSES,\n} from './constants'\nimport type { RelayAddress, RelayVmType } from './execution'\nimport {\n CheckoutRefundState,\n CheckoutState,\n type RelayExecutionInfo,\n} from './types'\n\n/**\n * Converts a token address within Funkit the corresponding Relay token address.\n */\nexport function convertFunToRelayTokenAddress<T extends RelayVmType>(\n address: RelayAddress<T>,\n): RelayAddress<T> {\n if (address.toLowerCase() === FUNKIT_NATIVE_TOKEN.toLowerCase()) {\n return RELAY_NATIVE_TOKEN as RelayAddress<T>\n }\n\n return address\n}\n\nexport function getRelayExecutionRefundState(\n info: RelayExecutionInfo,\n): CheckoutRefundState | undefined {\n switch (info.status) {\n case 'refund':\n return CheckoutRefundState.REFUNDED\n default:\n return undefined\n }\n}\n\nexport function getRelayExecutionState(\n info: RelayExecutionInfo,\n): CheckoutState {\n switch (info.status) {\n case 'success':\n return CheckoutState.COMPLETED\n case 'failure':\n case 'refund':\n return CheckoutState.CHECKOUT_ERROR\n default:\n return CheckoutState.PENDING_RECEIVAL\n }\n}\n\n/**\n * Checks whether the Relay execution has reached a terminal status.\n */\nexport function isRelayExecutionTerminalStatus(\n info: RelayExecutionInfo,\n): boolean {\n return RELAY_TERMINAL_STATUSES.includes(info.status)\n}\n\nexport type Serializable =\n | bigint\n | boolean\n | null\n | number\n | string\n | Date\n | object // Should be '{ [key: string]: Serializable }' but helper gets called with loosely-typed 'object' and interfaces\n | Serializable[]\n\nexport function jsonStringifyWithBigIntSanitization(\n serializable: Serializable,\n): string {\n return JSON.stringify(\n serializable,\n (_, value) =>\n typeof value === 'bigint' ? `0x${value.toString(16)}` : value, // return everything else unchanged\n )\n}\n", "import type { CallFees } from '@reservoir0x/relay-sdk'\nimport type { Logger } from './types'\n\nexport interface FunRelayFeeItem {\n b: number\n v: number\n}\n\nexport async function getFunRelayFees({\n fromTokenAddress,\n fromChainId,\n toTokenAddress,\n toChainId,\n estUsdValue,\n clientId,\n}: {\n fromTokenAddress: string\n fromChainId: string\n toTokenAddress: string\n toChainId: string\n estUsdValue: number\n clientId: string\n}): Promise<FunRelayFeeItem> {\n const url = `https://frog.fun.xyz/api/fee?fromTokenAddress=${fromTokenAddress}&fromChainId=${fromChainId}&toTokenAddress=${toTokenAddress}&toChainId=${toChainId}&estUsdValue=${estUsdValue}&clientId=${clientId}`\n const response = await fetch(url)\n if (!response.ok) {\n throw Error(response.statusText)\n }\n\n const data = await response.json()\n return data\n}\n\nexport function parseRelayFees({\n fees,\n logger,\n}: {\n fees: CallFees | undefined\n logger: Logger\n}) {\n // Gas fees, denominated in source chain native token\n const relayGasFeesUsd = Number.parseFloat(fees?.gas?.amountUsd || '0')\n\n // App fees, denominated in source chain token\n const funLpFeesUsd = Number.parseFloat(fees?.app?.amountUsd || '0')\n const funLpFeesFromAmount = Number.parseFloat(\n fees?.app?.amountFormatted || '0',\n )\n const funLpFeesFromAmountBaseUnit = BigInt(fees?.app?.amount || '0')\n\n // Relay fees, denominated in source chain token\n const relayLpFeesUsd = Number.parseFloat(fees?.relayer?.amountUsd || '0')\n const relayLpFeesFromAmount = Number.parseFloat(\n fees?.relayer?.amountFormatted || '0',\n )\n const relayLpFeesFromAmountBaseUnit = BigInt(fees?.relayer?.amount || '0')\n\n const totalLpFeesUsd = funLpFeesUsd + relayLpFeesUsd\n const totalLpFeesFromAmount = funLpFeesFromAmount + relayLpFeesFromAmount\n const totalLpFeesFromAmountBaseUnit =\n funLpFeesFromAmountBaseUnit + relayLpFeesFromAmountBaseUnit\n\n logger.info('parseRelayFees', {\n relayGasFeesUsd,\n funLpFeesUsd,\n funLpFeesFromAmount,\n funLpFeesFromAmountBaseUnit,\n relayLpFeesUsd,\n relayLpFeesFromAmount,\n relayLpFeesFromAmountBaseUnit,\n totalLpFeesUsd,\n totalLpFeesFromAmount,\n totalLpFeesFromAmountBaseUnit,\n })\n\n return {\n relayGasFeesUsd,\n totalLpFeesUsd,\n totalFeesUsd: relayGasFeesUsd + totalLpFeesUsd,\n totalFeesFromAmount: totalLpFeesFromAmount,\n totalFeesFromAmountBaseUnit: totalLpFeesFromAmountBaseUnit,\n }\n}\n", "import { MAINNET_RELAY_API } from '@reservoir0x/relay-sdk'\nimport type { RelayTokenPriceInfo } from './types'\n\nexport async function getRelayAssetPriceInfo({\n chainId,\n address,\n}: {\n chainId: string\n address: string\n}): Promise<RelayTokenPriceInfo> {\n const url = `${MAINNET_RELAY_API}/currencies/token/price?chainId=${chainId}&address=${address}`\n const response = await fetch(url)\n if (!response.ok) {\n throw Error(response.statusText)\n }\n\n const data = await response.json()\n return data as RelayTokenPriceInfo\n}\n", "import type { Execute, GetQuoteParameters } from '@reservoir0x/relay-sdk'\nimport { type Address, encodeFunctionData } from 'viem'\nimport { getRelayClient } from './client'\nimport {\n FUN_RELAY_REFERRER,\n FUN_RELAY_REVENUE_WALLET,\n RELAY_QUOTE_CHECKOUT_TIME_BUFFER_MS,\n} from './constants'\nimport { getRelayAssetInfo } from './currency'\nimport type {\n RelayAddress,\n RelayChainId,\n RelayVmType,\n RelayWallet,\n} from './execution'\nimport { getFunRelayFees, parseRelayFees } from './fees'\nimport { getRelayAssetPriceInfo } from './price'\nimport type {\n ApiFunkitCheckoutActionParams,\n CheckoutQuoteResponse,\n Logger,\n} from './types'\nimport { convertFunToRelayTokenAddress } from './utils'\n\ntype RelayQuoteOptions = GetQuoteParameters['options'] & {}\n\nexport type RelayQuoteResult<VmType extends RelayVmType> = Execute & {\n __vm: VmType\n}\n\nexport type GetRelayQuoteParams<\n SourceVmType extends RelayVmType = RelayVmType,\n TargetVmType extends RelayVmType = RelayVmType,\n> = {\n actionParams?: ApiFunkitCheckoutActionParams[]\n clientId: string\n fromChainId: RelayChainId<SourceVmType>\n fromTokenAddress: RelayAddress<SourceVmType>\n logger: Logger\n /**\n * {@link getRelayQuote} already sets {@link RelayQuoteOptions.appFees|appFees} and {@link RelayQuoteOptions.referrer|referrer}.\n * Only include them if you wish to override.\n */\n options?: RelayQuoteOptions\n recipientAddress: RelayAddress<TargetVmType> | undefined\n toChainId: RelayChainId<TargetVmType>\n toTokenAddress: RelayAddress<TargetVmType>\n tradeType: 'EXACT_INPUT' | 'EXACT_OUTPUT' | 'EXPECTED_OUTPUT'\n userAddress: RelayAddress<SourceVmType> | undefined\n walletClient?: RelayWallet<SourceVmType>\n} & (\n | {\n fromTokenAmountBaseUnit: bigint | string\n tradeType: 'EXACT_INPUT'\n }\n | {\n toTokenAmountBaseUnit: bigint | string\n tradeType: 'EXACT_OUTPUT' | 'EXPECTED_OUTPUT'\n }\n)\n\nexport type RelayQuote<VmType extends RelayVmType = RelayVmType> =\n CheckoutQuoteResponse & {\n /** Required for EXACT_INPUT checkouts */\n finalToAmountBaseUnit: string\n metadata: {\n fromAmountBaseUnit: string\n relayQuote: RelayQuoteResult<VmType>\n toAmountBaseUnit: string\n }\n }\n\nasync function getQuoteEstUsdValue({\n tokenChainId,\n tokenAddress,\n tokenAmountBaseUnit,\n logger,\n}: {\n tokenChainId: string\n tokenAddress: string\n tokenAmountBaseUnit: string\n logger: Logger\n}) {\n try {\n const [tokenPriceRes, tokenInfoRes] = await Promise.all([\n getRelayAssetPriceInfo({\n chainId: tokenChainId,\n address: convertFunToRelayTokenAddress(tokenAddress as Address),\n }),\n getRelayAssetInfo({\n chainId: tokenChainId,\n address: convertFunToRelayTokenAddress(tokenAddress as Address),\n }),\n ])\n\n const price = tokenPriceRes.price\n const decimals = tokenInfoRes.decimals\n\n const absoluteAmount = BigInt(tokenAmountBaseUnit) / BigInt(10 ** decimals)\n return Number(price) * Number(absoluteAmount)\n } catch (err) {\n logger.error('getQuoteEstUsdValueError', {\n message: `Failed to get USD value for token ${tokenAddress} on chain ${tokenChainId}: ${\n err instanceof Error ? err.message : JSON.stringify(err)\n }. Falling back to 0 USD.`,\n })\n // If any part fails, just fallback to 0 USD so that we do not block quote\n return 0\n }\n}\n\nexport async function getRelayQuote<\n SourceVmType extends RelayVmType,\n TargetVmType extends RelayVmType = RelayVmType,\n>({\n logger,\n walletClient,\n ...params\n}: GetRelayQuoteParams<SourceVmType, TargetVmType>): Promise<\n RelayQuote<SourceVmType>\n> {\n const {\n actionParams,\n clientId,\n fromChainId,\n fromTokenAddress,\n options,\n recipientAddress,\n toChainId,\n toTokenAddress,\n userAddress,\n } = params\n\n try {\n const relayClient = getRelayClient()\n\n const txs = actionParams?.map((action) => {\n const data = encodeFunctionData({\n abi: action.contractAbi,\n args: action.functionArgs,\n functionName: action.functionName,\n })\n\n return {\n data,\n to: action.contractAddress,\n value: String(action.value ?? 0n),\n }\n })\n\n const isExactIn = params.tradeType === 'EXACT_INPUT'\n const queryTokenAmountBaseUnit = isExactIn\n ? params.fromTokenAmountBaseUnit\n : params.toTokenAmountBaseUnit\n const queryTokenAddress = isExactIn ? fromTokenAddress : toTokenAddress\n const queryTokenChainId = isExactIn ? fromChainId : toChainId\n\n const estUsdValue = await getQuoteEstUsdValue({\n tokenChainId: queryTokenChainId,\n tokenAddress: queryTokenAddress,\n tokenAmountBaseUnit: queryTokenAmountBaseUnit.toString(),\n logger,\n })\n\n const feeInfo = await getFunRelayFees({\n fromTokenAddress,\n fromChainId,\n toTokenAddress,\n toChainId,\n estUsdValue: Number(estUsdValue) || 0,\n clientId,\n })\n\n const appFeeBp = feeInfo.b + feeInfo.v\n\n logger.info('getRelayQuoteParams', {\n ...params,\n queryTokenAmountBaseUnit,\n txs,\n estUsdValue,\n feeInfo,\n appFeeBp,\n })\n\n // Get the full quote with fees\n const relayQuote = await relayClient.actions.getQuote({\n chainId: Number(fromChainId),\n toChainId: Number(toChainId),\n currency: convertFunToRelayTokenAddress(fromTokenAddress),\n toCurrency: convertFunToRelayTokenAddress(toTokenAddress),\n amount: queryTokenAmountBaseUnit.toString(),\n recipient: recipientAddress,\n tradeType: params.tradeType,\n user: userAddress,\n wallet: walletClient,\n ...(txs && { txs }),\n options: {\n referrer: clientId\n ? `${FUN_RELAY_REFERRER}|${clientId}`\n : FUN_RELAY_REFERRER,\n appFees: [\n {\n fee: appFeeBp.toString(),\n recipient: FUN_RELAY_REVENUE_WALLET,\n },\n ],\n ...options,\n },\n })\n\n logger.info('relayQuote', relayQuote)\n\n const estSubtotalUsd = Number(\n relayQuote.details?.currencyOut?.amountUsd || 0,\n )\n const estTotalUsd = Number(relayQuote.details?.currencyIn?.amountUsd || 0)\n // Get how much fromAmount is needed for the quote\n const fromAmountString =\n relayQuote.details?.currencyIn?.amountFormatted || '0'\n const fromAmountBaseUnitString =\n relayQuote.details?.currencyIn?.amount || '0'\n\n // RequestID will be consistent across steps in the quote\n // https://fun-xyz.slack.com/archives/C08MQ85QB2N/p1747774944603209\n const relayRequestId = relayQuote.steps[0]?.requestId\n\n // TODO: Verify with relay team if this is possible?\n if (!relayRequestId) {\n throw new Error('Relay quote does not contain a requestId')\n }\n\n // TODO: Verify with relay team if this is possible?\n if (!relayQuote.details?.currencyIn || !relayQuote.details?.currencyOut) {\n throw new Error('Relay quote does not contain trade details')\n }\n\n const {\n relayGasFeesUsd,\n totalLpFeesUsd,\n totalFeesUsd,\n totalFeesFromAmount,\n totalFeesFromAmountBaseUnit,\n } = parseRelayFees({ fees: relayQuote.fees, logger })\n\n const estSubtotalFromAmount = (\n Number.parseFloat(fromAmountString) - totalFeesFromAmount\n ).toString()\n\n const estSubtotalFromAmountBaseUnit = (\n BigInt(fromAmountBaseUnitString) - totalFeesFromAmountBaseUnit\n ).toString()\n\n return {\n quoteId: relayRequestId,\n estCheckoutTimeMs:\n (relayQuote.details.timeEstimate || 0) * 1000 +\n RELAY_QUOTE_CHECKOUT_TIME_BUFFER_MS,\n estFeesFromAmount: totalFeesFromAmount.toString(),\n estFeesFromAmountBaseUnit: totalFeesFromAmountBaseUnit.toString(),\n estFeesUsd: totalFeesUsd,\n estMarketMakerGasUsd: relayGasFeesUsd,\n estSubtotalFromAmount,\n estSubtotalFromAmountBaseUnit,\n estSubtotalUsd,\n estTotalFromAmount: fromAmountString,\n estTotalFromAmountBaseUnit: fromAmountBaseUnitString,\n estTotalUsd,\n finalToAmountBaseUnit: relayQuote.details.currencyOut.amount ?? '0', // TODO: Or do we want 'minimumAmount'?\n fromTokenAddress: fromTokenAddress as Address, // TODO: fromTokenAddress is typed as `0x${string}` why does not accept SolanaAddress\n lpFeePercentage: 0, // TODO: ?\n lpFeeUsd: totalLpFeesUsd,\n metadata: {\n fromAmountBaseUnit: isExactIn\n ? queryTokenAmountBaseUnit.toString()\n : (relayQuote.details.currencyIn.amount ?? '0'),\n relayQuote: relayQuote as RelayQuoteResult<SourceVmType>,\n toAmountBaseUnit: isExactIn\n ? (relayQuote.details.currencyOut.amount ?? '0')\n : queryTokenAmountBaseUnit.toString(),\n },\n }\n } catch (err) {\n throw new Error(\n `An error occurred trying to generate a relay quote: ${\n err instanceof Error ? err.message : JSON.stringify(err)\n }`,\n )\n }\n}\n", "import { MAINNET_RELAY_API } from '@reservoir0x/relay-sdk'\n\nexport interface RelayTokenInfo {\n chainId: number\n address: string\n symbol: string\n name: string\n decimals: number\n vmType: string\n metadata: {\n logoURI: string\n verified: boolean\n isNative: boolean\n }\n}\n\nexport async function getRelayAssetInfo({\n chainId,\n address,\n}: {\n chainId: string\n address: string\n}): Promise<RelayTokenInfo> {\n const url = `${MAINNET_RELAY_API}/currencies/v2`\n const body = {\n chainIds: [chainId],\n address,\n }\n const response = await fetch(url, {\n method: 'POST',\n headers: { 'Content-Type': 'application/json' },\n body: JSON.stringify(body),\n })\n if (!response.ok) {\n throw Error(response.statusText)\n }\n\n const data = await response.json()\n return data?.[0] as RelayTokenInfo\n}\n", "import type { AdaptedWallet } from '@reservoir0x/relay-sdk'\nimport { adaptSolanaWallet } from '@reservoir0x/relay-svm-wallet-adapter'\nimport {\n type Connection,\n SendTransactionError,\n type VersionedTransaction,\n} from '@solana/web3.js'\nimport { RELAY_SOLANA_CHAIN_ID_NUMBER } from './constants'\n\ntype Base58 =\n | '1'\n | '2'\n | '3'\n | '4'\n | '5'\n | '6'\n | '7'\n | '8'\n | '9'\n | 'A'\n | 'B'\n | 'C'\n | 'D'\n | 'E'\n | 'F'\n | 'G'\n | 'H'\n | 'J'\n | 'K'\n | 'L'\n | 'M'\n | 'N'\n | 'P'\n | 'Q'\n | 'R'\n | 'S'\n | 'T'\n | 'U'\n | 'V'\n | 'W'\n | 'X'\n | 'Y'\n | 'Z'\n | 'a'\n | 'b'\n | 'c'\n | 'd'\n | 'e'\n | 'f'\n | 'g'\n | 'h'\n | 'i'\n | 'j'\n | 'k'\n | 'm'\n | 'n'\n | 'o'\n | 'p'\n | 'q'\n | 'r'\n | 's'\n | 't'\n | 'u'\n | 'v'\n | 'w'\n | 'x'\n | 'y'\n | 'z'\n\nexport type SolanaAddress = `${Base58}${string}`\n\nexport type SolanaTxHash = `${Base58}${string}`\n\nexport type SolanaWallet = AdaptedWallet & {\n address(): Promise<SolanaAddress>\n}\n\nexport function getSolanaWallet(\n walletAddress: SolanaAddress,\n connection: Connection,\n signTransaction: (\n transaction: VersionedTransaction,\n ) => Promise<VersionedTransaction>,\n payerKey?: SolanaAddress,\n): SolanaWallet {\n return adaptSolanaWallet(\n walletAddress,\n RELAY_SOLANA_CHAIN_ID_NUMBER,\n connection,\n async (transaction, options) => {\n const signed = await signTransaction(transaction)\n try {\n const signature = await connection.sendTransaction(signed, {\n ...options,\n maxRetries: 5,\n })\n\n return { signature }\n } catch (error) {\n if (error instanceof SendTransactionError) {\n console.error(\n 'Failed transaction logs:',\n error,\n await error.getLogs(connection),\n )\n }\n\n throw error\n }\n },\n payerKey,\n ) as SolanaWallet\n}\n"],
|
|
5
|
+
"mappings": ";AAAA;AAAA,EACE;AAAA,EAGA;AAAA,EACA;AAAA,EACA;AAAA,OACK;;;ACPP,SAAS,gBAAgB;;;ACQlB,IAAM,+BAA+B;AACrC,IAAM,wBAAwB,GAAG,4BAA4B;AAK7D,IAAM,sBACX;AAKK,IAAM,qBACX;AAKK,IAAM,2BACX;AAKK,IAAM,qBAAqB;AAK3B,IAAM,sCAAsC;AAE5C,IAAM,0BAAkD;AAAA;AAAA;AAAA;AAI/D;;;AFnBO,SAAS,sBAAsB;AAAA,EACpC;AAAA,EACA;AAAA,EACA,GAAG;AACL,GAA6C;AAC3C,SAAO,aAAa;AAAA,IAClB,GAAG;AAAA,IACH,YAAY;AAAA,IACZ,QAAQ;AAAA,MACN,GAAG,OAAO,IAAI,4BAA4B;AAAA,MAC1C;AAAA,QACE,IAAI;AAAA,QACJ,MAAM;AAAA,QACN,aAAa;AAAA,MACf;AAAA,IACF;AAAA,IACA,QAAQ,CAAC,YAAY;AACnB,aAAO,KAAK,kBAAkB,OAAO;AAAA,IACvC;AAAA,EACF,CAAC;AACH;AAKO,SAAS,iBAA8B;AAC5C,QAAM,SAAS,UAAU;AAEzB,MAAI,CAAC,QAAQ;AACX,UAAM,IAAI,M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AU,GAAG,CACzD;AAAA,IACF;AAAA,EACF;AACF;;;AE/RA,SAAS,yBAAyB;AAClC;AAAA,EAEE;AAAA,OAEK;AAuEA,SAAS,gBACd,eACA,YACA,iBAGA,UACc;AACd,SAAO;AAAA,IACL;AAAA,IACA;AAAA,IACA;AAAA,IACA,OAAO,aAAa,YAAY;AAC9B,YAAM,SAAS,MAAM,gBAAgB,WAAW;AAChD,UAAI;AACF,cAAM,YAAY,MAAM,WAAW,gBAAgB,QAAQ;AAAA,UACzD,GAAG;AAAA,UACH,YAAY;AAAA,QACd,CAAC;AAED,eAAO,EAAE,UAAU;AAAA,MACrB,SAAS,OAAO;AACd,YAAI,iBAAiB,sBAAsB;AACzC,kBAAQ;AAAA,YACN;AAAA,YACA;AAAA,YACA,MAAM,MAAM,QAAQ,UAAU;AAAA,UAChC;AAAA,QACF;AAEA,cAAM;AAAA,MACR;AAAA,IACF;AAAA,IACA;AAAA,EACF;AACF;",
|
|
6
6
|
"names": ["MAINNET_RELAY_API", "MAINNET_RELAY_API", "MAINNET_RELAY_API", "MAINNET_RELAY_API"]
|
|
7
7
|
}
|
package/dist/src/execution.d.ts
CHANGED
|
@@ -31,5 +31,18 @@ export interface ExecuteRelayQuoteParams<VmType extends RelayVmType> {
|
|
|
31
31
|
walletClient: RelayWallet<VmType>;
|
|
32
32
|
}
|
|
33
33
|
export declare function executeRelayQuote<VmType extends RelayVmType>({ logger, onConfirmed, onError, onProgress, relayQuote, walletClient, }: ExecuteRelayQuoteParams<VmType>): Promise<void>;
|
|
34
|
+
export interface PostRegistrationRequest {
|
|
35
|
+
requestId: string;
|
|
36
|
+
chainId: string;
|
|
37
|
+
tx: string;
|
|
38
|
+
}
|
|
39
|
+
export type RegisterIndexingResponse = {
|
|
40
|
+
success: never;
|
|
41
|
+
message: 'Success';
|
|
42
|
+
} | {
|
|
43
|
+
success: false;
|
|
44
|
+
message: string;
|
|
45
|
+
};
|
|
46
|
+
export declare function manuallyRegisterIndex(logger: Logger, registerRequest: PostRegistrationRequest): Promise<void>;
|
|
34
47
|
export declare function getRelayExecutionInfo(requestId: string): Promise<RelayExecutionInfo>;
|
|
35
48
|
//# sourceMappingURL=execution.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"execution.d.ts","sourceRoot":"","sources":["../../src/execution.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,KAAK,aAAa,EAElB,KAAK,YAAY,EAClB,MAAM,wBAAwB,CAAA;AAC/B,OAAO,KAAK,EAAE,OAAO,EAAE,GAAG,EAAE,YAAY,EAAE,MAAM,MAAM,CAAA;AAEtD,OAAO,KAAK,EAAE,qBAAqB,EAAE,MAAM,aAAa,CAAA;AACxD,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,SAAS,CAAA;AAC/C,OAAO,KAAK,EAAE,aAAa,EAAE,YAAY,EAAE,YAAY,EAAE,MAAM,UAAU,CAAA;AACzE,OAAO,KAAK,EAAE,MAAM,EAAE,kBAAkB,EAAE,MAAM,SAAS,CAAA;
|
|
1
|
+
{"version":3,"file":"execution.d.ts","sourceRoot":"","sources":["../../src/execution.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,KAAK,aAAa,EAElB,KAAK,YAAY,EAClB,MAAM,wBAAwB,CAAA;AAC/B,OAAO,KAAK,EAAE,OAAO,EAAE,GAAG,EAAE,YAAY,EAAE,MAAM,MAAM,CAAA;AAEtD,OAAO,KAAK,EAAE,qBAAqB,EAAE,MAAM,aAAa,CAAA;AACxD,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,SAAS,CAAA;AAC/C,OAAO,KAAK,EAAE,aAAa,EAAE,YAAY,EAAE,YAAY,EAAE,MAAM,UAAU,CAAA;AACzE,OAAO,KAAK,EAAE,MAAM,EAAE,kBAAkB,EAAE,MAAM,SAAS,CAAA;AAGzD,MAAM,MAAM,kBAAkB,GAAG,YAAY,CAAC,aAAa,CAAC,GAAG,EAAE,CAAA;AAEjE,MAAM,MAAM,WAAW,GAAG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AE,uBAAuB,CAAC,MAAM,CAAC,GAAG,OAAO,CAAC,IAAI,CAAC,CA8DjD;AAED,MAAM,WAAW,uBAAuB;IACtC,SAAS,EAAE,MAAM,CAAA;IACjB,OAAO,EAAE,MAAM,CAAA;IACf,EAAE,EAAE,MAAM,CAAA;CACX;AAED,MAAM,MAAM,wBAAwB,GAChC;IAAE,OAAO,EAAE,KAAK,CAAC;IAAC,OAAO,EAAE,SAAS,CAAA;CAAE,GACtC;IAAE,OAAO,EAAE,KAAK,CAAC;IAAC,OAAO,EAAE,MAAM,CAAA;CAAE,CAAA;AAEvC,wBAAsB,qBAAqB,CACzC,MAAM,EAAE,MAAM,EACd,eAAe,EAAE,uBAAuB,GACvC,OAAO,CAAC,IAAI,CAAC,CA0Bf;AAED,wBAAsB,qBAAqB,CACzC,SAAS,EAAE,MAAM,GAChB,OAAO,CAAC,kBAAkB,CAAC,CAS7B"}
|
package/dist/src/utils.d.ts
CHANGED
|
@@ -10,4 +10,6 @@ export declare function getRelayExecutionState(info: RelayExecutionInfo): Checko
|
|
|
10
10
|
* Checks whether the Relay execution has reached a terminal status.
|
|
11
11
|
*/
|
|
12
12
|
export declare function isRelayExecutionTerminalStatus(info: RelayExecutionInfo): boolean;
|
|
13
|
+
export type Serializable = bigint | boolean | null | number | string | Date | object | Serializable[];
|
|
14
|
+
export declare function jsonStringifyWithBigIntSanitization(serializable: Serializable): string;
|
|
13
15
|
//# sourceMappingURL=utils.d.ts.map
|
package/dist/src/utils.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"utils.d.ts","sourceRoot":"","sources":["../../src/utils.ts"],"names":[],"mappings":"AAKA,OAAO,KAAK,EAAE,YAAY,EAAE,WAAW,EAAE,MAAM,aAAa,CAAA;AAC5D,OAAO,EACL,mBAAmB,EACnB,aAAa,EACb,KAAK,kBAAkB,EACxB,MAAM,SAAS,CAAA;AAEhB;;GAEG;AACH,wBAAgB,6BAA6B,CAAC,CAAC,SAAS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