@lifi/sdk-provider-solana 0.0.0-preview-e8c80bc4 → 0.0.0-preview-155bb7fe
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 +16 -3
- package/dist/cjs/SolanaProvider.js.map +1 -1
- package/dist/cjs/confirmation/raceRpcs.js.map +1 -1
- package/dist/cjs/core/SolanaStepExecutor.js.map +1 -1
- package/dist/cjs/core/tasks/SolanaJitoWaitForTransactionTask.js.map +1 -1
- package/dist/cjs/core/tasks/SolanaSignAndExecuteTask.js.map +1 -1
- package/dist/cjs/core/tasks/SolanaStandardWaitForTransactionTask.js.map +1 -1
- package/dist/cjs/core/tasks/resumeFromStore.js.map +1 -1
- package/dist/cjs/errors/parseSolanaErrors.js +6 -3
- package/dist/cjs/errors/parseSolanaErrors.js.map +1 -1
- package/dist/cjs/utils/KeypairWalletAdapter.js.map +1 -1
- package/dist/cjs/utils/solanaErrorCause.js.map +1 -1
- package/dist/cjs/version.d.ts +1 -1
- package/dist/cjs/version.js +1 -1
- package/dist/cjs/version.js.map +1 -1
- package/dist/esm/confirmation/raceRpcs.js.map +1 -1
- package/dist/esm/core/SolanaStepExecutor.js.map +1 -1
- package/dist/esm/core/tasks/SolanaJitoWaitForTransactionTask.d.ts.map +1 -1
- package/dist/esm/core/tasks/SolanaSignAndExecuteTask.d.ts.map +1 -1
- package/dist/esm/core/tasks/SolanaStandardWaitForTransactionTask.d.ts.map +1 -1
- package/dist/esm/core/tasks/SolanaWaitForTransactionTask.d.ts.map +1 -1
- package/dist/esm/errors/parseSolanaErrors.js +6 -3
- package/dist/esm/errors/parseSolanaErrors.js.map +1 -1
- package/dist/esm/utils/KeypairWalletAdapter.d.ts.map +1 -1
- package/dist/esm/utils/KeypairWalletAdapter.js.map +1 -1
- package/dist/esm/utils/solanaErrorCause.js.map +1 -1
- package/dist/esm/version.d.ts +1 -1
- package/dist/esm/version.js +1 -1
- package/dist/esm/version.js.map +1 -1
- package/package.json +2 -2
- package/src/errors/parseSolanaErrors.ts +12 -3
- package/src/version.ts +1 -1
package/CHANGELOG.md
CHANGED
|
@@ -1,12 +1,25 @@
|
|
|
1
1
|
# @lifi/sdk-provider-solana
|
|
2
2
|
|
|
3
|
-
## 0.0.0-preview-
|
|
3
|
+
## 0.0.0-preview-155bb7fe
|
|
4
|
+
|
|
5
|
+
### Patch Changes
|
|
6
|
+
|
|
7
|
+
- Updated dependencies [[`09fa8a3`](https://github.com/lifinance/sdk/commit/09fa8a35f30fe67f136cd6d6c7bd32c23f1b8c1f)]:
|
|
8
|
+
- @lifi/sdk@0.0.0-preview-155bb7fe
|
|
9
|
+
|
|
10
|
+
## 4.3.9
|
|
11
|
+
|
|
12
|
+
### Patch Changes
|
|
13
|
+
|
|
14
|
+
- [#555](https://github.com/lifinance/sdk/pull/555) [`e2541bd`](https://github.com/lifinance/sdk/commit/e2541bde4b5fcd6b73d2711644b4aa86216a0362) Thanks [@chybisov](https://github.com/chybisov)! - A wallet error with only the text "Transaction canceled" now gets the code `SignatureRejected` (1012), not `UnknownError` (1000). The SDK already uses this code when the user rejects a sign request. Apps can then show the rejection message and do not report the cancel as a failure.
|
|
15
|
+
|
|
16
|
+
## 4.3.8
|
|
4
17
|
|
|
5
18
|
### Patch Changes
|
|
6
19
|
|
|
7
20
|
- [#539](https://github.com/lifinance/sdk/pull/539) [`b80e5f4`](https://github.com/lifinance/sdk/commit/b80e5f49941190812935644c55d5c9c075bac354) Thanks [@chybisov](https://github.com/chybisov)! - Bump runtime dependencies: @lifi/types to 18.16.0, bitcoinjs-lib to 7.0.5, viem to 2.57.17, @solana/kit to 8.6.0, @stellar/stellar-sdk to 17.4.0, @mysten/sui to 2.39.1.
|
|
8
|
-
- Updated dependencies [[`b80e5f4`](https://github.com/lifinance/sdk/commit/b80e5f49941190812935644c55d5c9c075bac354), [`
|
|
9
|
-
- @lifi/sdk@
|
|
21
|
+
- Updated dependencies [[`aa5d2ff`](https://github.com/lifinance/sdk/commit/aa5d2ffe2acccc7c7e17eac09562f491eb9cc0ac), [`b80e5f4`](https://github.com/lifinance/sdk/commit/b80e5f49941190812935644c55d5c9c075bac354), [`3129a50`](https://github.com/lifinance/sdk/commit/3129a50fadf41317592b2403c42f2816540cb045)]:
|
|
22
|
+
- @lifi/sdk@4.13.0
|
|
10
23
|
|
|
11
24
|
## 4.3.7
|
|
12
25
|
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"SolanaProvider.js","names":["ChainType","isAddress","resolveSolanaAddress","getSolanaBalance","ProviderError","LiFiErrorCode","SolanaStepExecutor"],"sources":["../../src/SolanaProvider.ts"],"sourcesContent":["import {\n ChainType,\n LiFiErrorCode,\n ProviderError,\n type StepExecutorOptions,\n} from '@lifi/sdk'\nimport { isAddress } from '@solana/kit'\nimport { getSolanaBalance } from './actions/getSolanaBalance.js'\nimport { resolveSolanaAddress } from './actions/resolveSolanaAddress.js'\nimport { SolanaStepExecutor } from './core/SolanaStepExecutor.js'\nimport type { SolanaProviderOptions, SolanaSDKProvider } from './types.js'\n\nexport function SolanaProvider(\n options?: SolanaProviderOptions\n): SolanaSDKProvider {\n const _options: SolanaProviderOptions = options ?? {}\n return {\n get type() {\n return ChainType.SVM\n },\n isAddress,\n isTokenAddress: isAddress,\n resolveAddress: resolveSolanaAddress,\n getBalance: getSolanaBalance,\n async getStepExecutor(\n options: StepExecutorOptions\n ): Promise<SolanaStepExecutor> {\n if (!_options.getWallet) {\n throw new ProviderError(\n LiFiErrorCode.ConfigError,\n 'SolanaProvider requires a getWallet function'\n )\n }\n\n const wallet = await _options.getWallet()\n\n const executor = new SolanaStepExecutor({\n wallet,\n routeId: options.routeId,\n skipSimulation: _options.skipSimulation,\n executionOptions: {\n ...options.executionOptions,\n },\n })\n\n return executor\n },\n setOptions(options: SolanaProviderOptions) {\n Object.assign(_options, options)\n },\n }\n}\n"],"mappings":";;;;;;;AAYA,SAAgB,eACd,SACmB;CACnB,MAAM,WAAkC,WAAW,CAAC;CACpD,OAAO;EACL,IAAI,OAAO;GACT,OAAOA,UAAAA,UAAU;EACnB;
|
|
1
|
+
{"version":3,"file":"SolanaProvider.js","names":["ChainType","isAddress","resolveSolanaAddress","getSolanaBalance","ProviderError","LiFiErrorCode","SolanaStepExecutor"],"sources":["../../src/SolanaProvider.ts"],"sourcesContent":["import {\n ChainType,\n LiFiErrorCode,\n ProviderError,\n type StepExecutorOptions,\n} from '@lifi/sdk'\nimport { isAddress } from '@solana/kit'\nimport { getSolanaBalance } from './actions/getSolanaBalance.js'\nimport { resolveSolanaAddress } from './actions/resolveSolanaAddress.js'\nimport { SolanaStepExecutor } from './core/SolanaStepExecutor.js'\nimport type { SolanaProviderOptions, SolanaSDKProvider } from './types.js'\n\nexport function SolanaProvider(\n options?: SolanaProviderOptions\n): SolanaSDKProvider {\n const _options: SolanaProviderOptions = options ?? {}\n return {\n get type() {\n return ChainType.SVM\n },\n isAddress,\n isTokenAddress: isAddress,\n resolveAddress: resolveSolanaAddress,\n getBalance: getSolanaBalance,\n async getStepExecutor(\n options: StepExecutorOptions\n ): Promise<SolanaStepExecutor> {\n if (!_options.getWallet) {\n throw new ProviderError(\n LiFiErrorCode.ConfigError,\n 'SolanaProvider requires a getWallet function'\n )\n }\n\n const wallet = await _options.getWallet()\n\n const executor = new SolanaStepExecutor({\n wallet,\n routeId: options.routeId,\n skipSimulation: _options.skipSimulation,\n executionOptions: {\n ...options.executionOptions,\n },\n })\n\n return executor\n },\n setOptions(options: SolanaProviderOptions) {\n Object.assign(_options, options)\n },\n }\n}\n"],"mappings":";;;;;;;AAYA,SAAgB,eACd,SACmB;CACnB,MAAM,WAAkC,WAAW,CAAC;CACpD,OAAO;EACL,IAAI,OAAO;GACT,OAAOA,UAAAA,UAAU;EACnB;EACAC,WAAAA,YAAAA;EACA,gBAAgBA,YAAAA;EAChB,gBAAgBC,qCAAAA;EAChB,YAAYC,iCAAAA;EACZ,MAAM,gBACJ,SAC6B;GAC7B,IAAI,CAAC,SAAS,WACZ,MAAM,IAAIC,UAAAA,cACRC,UAAAA,cAAc,aACd,8CACF;GAGF,MAAM,SAAS,MAAM,SAAS,UAAU;GAWxC,OAAO,IATcC,gCAAAA,mBAAmB;IACtC;IACA,SAAS,QAAQ;IACjB,gBAAgB,SAAS;IACzB,kBAAkB,EAChB,GAAG,QAAQ,iBACb;GACF,CAEc;EAChB;EACA,WAAW,SAAgC;GACzC,OAAO,OAAO,UAAU,OAAO;EACjC;CACF;AACF"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"raceRpcs.js","names":[],"sources":["../../../src/confirmation/raceRpcs.ts"],"sourcesContent":["import type { ConfirmationOutcome } from './types.js'\n\nexport type RaceResult<T> =\n | { kind: 'confirmed'; value: T }\n /** `slot`: the highest verdict slot of the branches. The transaction can\n * no longer land after it. */\n | { kind: 'expired'; slot: bigint; errors: Error[] }\n | { kind: 'not-confirmed'; errors: Error[] }\n | { kind: 'rpc-unavailable'; errors: Error[] }\n\n/** Every result that is not a confirmation. Independent of the value type. */\nexport type UnconfirmedRaceResult = Exclude<\n RaceResult<unknown>,\n { kind: 'confirmed' }\n>\n\nconst toError = (reason: unknown): Error =>\n reason instanceof Error ? reason : new Error(String(reason))\n\n/**\n * Aborts when `signal` aborts or `timeoutMs` elapses, whichever is first.\n *\n * Not `AbortSignal.any` + `AbortSignal.timeout`: both are Baseline March 2024,\n * and a published SDK should not raise its runtime floor for a convenience one\n * controller and one timer already cover. The caller's signal is never aborted\n * here, so \"caller aborted\" and \"timeout fired\" stay distinguishable.\n */\nfunction abortAfter(\n signal: AbortSignal,\n timeoutMs: number\n): { signal: AbortSignal; dispose: () => void } {\n const linked = new AbortController()\n const forward = (): void => linked.abort(signal.reason)\n\n const timer = setTimeout(() => {\n linked.abort(new Error(`This RPC did not answer within ${timeoutMs}ms.`))\n }, timeoutMs)\n // A pending timer keeps Node's event loop alive. `dispose` clears it; the\n // unref only covers a path that skips `dispose`.\n const handle = timer as unknown as { unref?: () => void }\n handle.unref?.()\n\n if (signal.aborted) {\n forward()\n } else {\n signal.addEventListener('abort', forward, { once: true })\n }\n\n return {\n signal: linked.signal,\n dispose: (): void => {\n clearTimeout(timer)\n signal.removeEventListener('abort', forward)\n },\n }\n}\n\n/**\n * Runs `run` against every RPC in parallel and reports the first confirmation.\n *\n * Not `Promise.any`: it turns \"polled and saw nothing\" into a thrown sentinel,\n * collapsing the difference between an expired transaction and an RPC that\n * never answered - the defect that reported live swaps as `TransactionExpired`.\n * `timeoutMs` is the caller's; this module holds no confirmation policy.\n */\nexport async function raceRpcs<Rpc, T>(\n rpcs: Rpc[],\n run: (rpc: Rpc, signal: AbortSignal) => Promise<ConfirmationOutcome<T>>,\n options: { timeoutMs: number }\n): Promise<RaceResult<T>> {\n if (rpcs.length === 0) {\n return { kind: 'rpc-unavailable', errors: [] }\n }\n\n const controller = new AbortController()\n // Kept distinct: `controller` means \"another branch confirmed\", the timeout\n // means \"this endpoint never answered\". The timeout aborts the linked signal\n // only.\n const branch = abortAfter(controller.signal, options.timeoutMs)\n\n let resolveConfirmed: ((value: T) => void) | undefined\n const firstConfirmation = new Promise<T>((resolve) => {\n resolveConfirmed = resolve\n })\n\n const settled = Promise.allSettled(\n rpcs.map(async (rpc) => {\n const outcome = await run(rpc, branch.signal)\n if (outcome.kind === 'confirmed') {\n resolveConfirmed?.(outcome.value)\n controller.abort()\n }\n return outcome\n })\n )\n\n const classify = (\n results: PromiseSettledResult<ConfirmationOutcome<T>>[]\n ): RaceResult<T> => {\n let expiredAtSlot: bigint | undefined\n let sawNotConfirmed = false\n const errors: Error[] = []\n\n for (const entry of results) {\n if (entry.status === 'fulfilled') {\n // Unreachable today - `firstConfirmation` always wins - but keeps\n // `classify` correct if that structure changes.\n if (entry.value.kind === 'confirmed') {\n return { kind: 'confirmed', value: entry.value.value }\n }\n if (entry.value.kind === 'expired') {\n // The highest verdict slot: the strictest head a dropped check can\n // demand.\n if (expiredAtSlot === undefined || entry.value.slot > expiredAtSlot) {\n expiredAtSlot = entry.value.slot\n }\n } else {\n sawNotConfirmed = true\n }\n continue\n }\n // Cancelled branches are not failures. A branch the timeout killed is,\n // so its error is collected.\n if (controller.signal.aborted) {\n continue\n }\n errors.push(toError(entry.reason))\n }\n\n // A completed observation outranks a thrown error, but the collected\n // errors still travel with it as the expiry's `cause`.\n //\n // Among the observations, the ceiling outranks an expiry: `expired` may\n // end in a final \"dropped\", so every branch that observed has to agree\n // on it. A stale node alone must not drop a transaction that another\n // endpoint still watched to its ceiling.\n if (sawNotConfirmed) {\n return { kind: 'not-confirmed', errors }\n }\n if (expiredAtSlot !== undefined) {\n return { kind: 'expired', slot: expiredAtSlot, errors }\n }\n return { kind: 'rpc-unavailable', errors }\n }\n\n try {\n const result = await Promise.race([\n firstConfirmation.then((value): RaceResult<T> => ({\n kind: 'confirmed',\n value,\n })),\n settled.then(classify),\n ])\n\n return result\n } finally {\n // Cancels every in-flight branch on every path out, rejections included.\n // Must run before `dispose`, which detaches the listener carrying it.\n controller.abort()\n branch.dispose()\n }\n}\n"],"mappings":";;AAgBA,MAAM,WAAW,WACf,kBAAkB,QAAQ,SAAS,IAAI,MAAM,OAAO,MAAM,CAAC;;;;;;;;;AAU7D,SAAS,WACP,QACA,WAC8C;CAC9C,MAAM,SAAS,IAAI,gBAAgB;CACnC,MAAM,gBAAsB,OAAO,MAAM,OAAO,MAAM;CAEtD,MAAM,QAAQ,iBAAiB;EAC7B,OAAO,sBAAM,IAAI,MAAM,kCAAkC,UAAU,IAAI,CAAC;CAC1E,GAAG,SAAS;
|
|
1
|
+
{"version":3,"file":"raceRpcs.js","names":["handle"],"sources":["../../../src/confirmation/raceRpcs.ts"],"sourcesContent":["import type { ConfirmationOutcome } from './types.js'\n\nexport type RaceResult<T> =\n | { kind: 'confirmed'; value: T }\n /** `slot`: the highest verdict slot of the branches. The transaction can\n * no longer land after it. */\n | { kind: 'expired'; slot: bigint; errors: Error[] }\n | { kind: 'not-confirmed'; errors: Error[] }\n | { kind: 'rpc-unavailable'; errors: Error[] }\n\n/** Every result that is not a confirmation. Independent of the value type. */\nexport type UnconfirmedRaceResult = Exclude<\n RaceResult<unknown>,\n { kind: 'confirmed' }\n>\n\nconst toError = (reason: unknown): Error =>\n reason instanceof Error ? reason : new Error(String(reason))\n\n/**\n * Aborts when `signal` aborts or `timeoutMs` elapses, whichever is first.\n *\n * Not `AbortSignal.any` + `AbortSignal.timeout`: both are Baseline March 2024,\n * and a published SDK should not raise its runtime floor for a convenience one\n * controller and one timer already cover. The caller's signal is never aborted\n * here, so \"caller aborted\" and \"timeout fired\" stay distinguishable.\n */\nfunction abortAfter(\n signal: AbortSignal,\n timeoutMs: number\n): { signal: AbortSignal; dispose: () => void } {\n const linked = new AbortController()\n const forward = (): void => linked.abort(signal.reason)\n\n const timer = setTimeout(() => {\n linked.abort(new Error(`This RPC did not answer within ${timeoutMs}ms.`))\n }, timeoutMs)\n // A pending timer keeps Node's event loop alive. `dispose` clears it; the\n // unref only covers a path that skips `dispose`.\n const handle = timer as unknown as { unref?: () => void }\n handle.unref?.()\n\n if (signal.aborted) {\n forward()\n } else {\n signal.addEventListener('abort', forward, { once: true })\n }\n\n return {\n signal: linked.signal,\n dispose: (): void => {\n clearTimeout(timer)\n signal.removeEventListener('abort', forward)\n },\n }\n}\n\n/**\n * Runs `run` against every RPC in parallel and reports the first confirmation.\n *\n * Not `Promise.any`: it turns \"polled and saw nothing\" into a thrown sentinel,\n * collapsing the difference between an expired transaction and an RPC that\n * never answered - the defect that reported live swaps as `TransactionExpired`.\n * `timeoutMs` is the caller's; this module holds no confirmation policy.\n */\nexport async function raceRpcs<Rpc, T>(\n rpcs: Rpc[],\n run: (rpc: Rpc, signal: AbortSignal) => Promise<ConfirmationOutcome<T>>,\n options: { timeoutMs: number }\n): Promise<RaceResult<T>> {\n if (rpcs.length === 0) {\n return { kind: 'rpc-unavailable', errors: [] }\n }\n\n const controller = new AbortController()\n // Kept distinct: `controller` means \"another branch confirmed\", the timeout\n // means \"this endpoint never answered\". The timeout aborts the linked signal\n // only.\n const branch = abortAfter(controller.signal, options.timeoutMs)\n\n let resolveConfirmed: ((value: T) => void) | undefined\n const firstConfirmation = new Promise<T>((resolve) => {\n resolveConfirmed = resolve\n })\n\n const settled = Promise.allSettled(\n rpcs.map(async (rpc) => {\n const outcome = await run(rpc, branch.signal)\n if (outcome.kind === 'confirmed') {\n resolveConfirmed?.(outcome.value)\n controller.abort()\n }\n return outcome\n })\n )\n\n const classify = (\n results: PromiseSettledResult<ConfirmationOutcome<T>>[]\n ): RaceResult<T> => {\n let expiredAtSlot: bigint | undefined\n let sawNotConfirmed = false\n const errors: Error[] = []\n\n for (const entry of results) {\n if (entry.status === 'fulfilled') {\n // Unreachable today - `firstConfirmation` always wins - but keeps\n // `classify` correct if that structure changes.\n if (entry.value.kind === 'confirmed') {\n return { kind: 'confirmed', value: entry.value.value }\n }\n if (entry.value.kind === 'expired') {\n // The highest verdict slot: the strictest head a dropped check can\n // demand.\n if (expiredAtSlot === undefined || entry.value.slot > expiredAtSlot) {\n expiredAtSlot = entry.value.slot\n }\n } else {\n sawNotConfirmed = true\n }\n continue\n }\n // Cancelled branches are not failures. A branch the timeout killed is,\n // so its error is collected.\n if (controller.signal.aborted) {\n continue\n }\n errors.push(toError(entry.reason))\n }\n\n // A completed observation outranks a thrown error, but the collected\n // errors still travel with it as the expiry's `cause`.\n //\n // Among the observations, the ceiling outranks an expiry: `expired` may\n // end in a final \"dropped\", so every branch that observed has to agree\n // on it. A stale node alone must not drop a transaction that another\n // endpoint still watched to its ceiling.\n if (sawNotConfirmed) {\n return { kind: 'not-confirmed', errors }\n }\n if (expiredAtSlot !== undefined) {\n return { kind: 'expired', slot: expiredAtSlot, errors }\n }\n return { kind: 'rpc-unavailable', errors }\n }\n\n try {\n const result = await Promise.race([\n firstConfirmation.then((value): RaceResult<T> => ({\n kind: 'confirmed',\n value,\n })),\n settled.then(classify),\n ])\n\n return result\n } finally {\n // Cancels every in-flight branch on every path out, rejections included.\n // Must run before `dispose`, which detaches the listener carrying it.\n controller.abort()\n branch.dispose()\n }\n}\n"],"mappings":";;AAgBA,MAAM,WAAW,WACf,kBAAkB,QAAQ,SAAS,IAAI,MAAM,OAAO,MAAM,CAAC;;;;;;;;;AAU7D,SAAS,WACP,QACA,WAC8C;CAC9C,MAAM,SAAS,IAAI,gBAAgB;CACnC,MAAM,gBAAsB,OAAO,MAAM,OAAO,MAAM;CAEtD,MAAM,QAAQ,iBAAiB;EAC7B,OAAO,sBAAM,IAAI,MAAM,kCAAkC,UAAU,IAAI,CAAC;CAC1E,GAAG,SAAS;CAIZA,MAAO,QAAQ;CAEf,IAAI,OAAO,SACT,QAAQ;MAER,OAAO,iBAAiB,SAAS,SAAS,EAAE,MAAM,KAAK,CAAC;CAG1D,OAAO;EACL,QAAQ,OAAO;EACf,eAAqB;GACnB,aAAa,KAAK;GAClB,OAAO,oBAAoB,SAAS,OAAO;EAC7C;CACF;AACF;;;;;;;;;AAUA,eAAsB,SACpB,MACA,KACA,SACwB;CACxB,IAAI,KAAK,WAAW,GAClB,OAAO;EAAE,MAAM;EAAmB,QAAQ,CAAC;CAAE;CAG/C,MAAM,aAAa,IAAI,gBAAgB;CAIvC,MAAM,SAAS,WAAW,WAAW,QAAQ,QAAQ,SAAS;CAE9D,IAAI;CACJ,MAAM,oBAAoB,IAAI,SAAY,YAAY;EACpD,mBAAmB;CACrB,CAAC;CAED,MAAM,UAAU,QAAQ,WACtB,KAAK,IAAI,OAAO,QAAQ;EACtB,MAAM,UAAU,MAAM,IAAI,KAAK,OAAO,MAAM;EAC5C,IAAI,QAAQ,SAAS,aAAa;GAChC,mBAAmB,QAAQ,KAAK;GAChC,WAAW,MAAM;EACnB;EACA,OAAO;CACT,CAAC,CACH;CAEA,MAAM,YACJ,YACkB;EAClB,IAAI;EACJ,IAAI,kBAAkB;EACtB,MAAM,SAAkB,CAAC;EAEzB,KAAK,MAAM,SAAS,SAAS;GAC3B,IAAI,MAAM,WAAW,aAAa;IAGhC,IAAI,MAAM,MAAM,SAAS,aACvB,OAAO;KAAE,MAAM;KAAa,OAAO,MAAM,MAAM;IAAM;IAEvD,IAAI,MAAM,MAAM,SAAS,WAGnB;SAAA,kBAAkB,KAAA,KAAa,MAAM,MAAM,OAAO,eACpD,gBAAgB,MAAM,MAAM;IAAA,OAG9B,kBAAkB;IAEpB;GACF;GAGA,IAAI,WAAW,OAAO,SACpB;GAEF,OAAO,KAAK,QAAQ,MAAM,MAAM,CAAC;EACnC;EASA,IAAI,iBACF,OAAO;GAAE,MAAM;GAAiB;EAAO;EAEzC,IAAI,kBAAkB,KAAA,GACpB,OAAO;GAAE,MAAM;GAAW,MAAM;GAAe;EAAO;EAExD,OAAO;GAAE,MAAM;GAAmB;EAAO;CAC3C;CAEA,IAAI;EASF,OAAO,MARc,QAAQ,KAAK,CAChC,kBAAkB,MAAM,WAA0B;GAChD,MAAM;GACN;EACF,EAAE,GACF,QAAQ,KAAK,QAAQ,CACvB,CAAC;CAGH,UAAU;EAGR,WAAW,MAAM;EACjB,OAAO,QAAQ;CACjB;AACF"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"SolanaStepExecutor.js","names":["BaseStepExecutor","TransactionError","LiFiErrorCode","parseSolanaErrors","CheckBalanceTask","PrepareTransactionTask","SolanaSignAndExecuteTask","SolanaWaitForTransactionTask","WaitForTransactionStatusTask","hasOpenTransaction","TaskPipeline"],"sources":["../../../src/core/SolanaStepExecutor.ts"],"sourcesContent":["import {\n BaseStepExecutor,\n CheckBalanceTask,\n type ExecutionAction,\n hasOpenTransaction,\n LiFiErrorCode,\n type LiFiStepExtended,\n PrepareTransactionTask,\n type SDKError,\n type StepExecutorBaseContext,\n TaskPipeline,\n TransactionError,\n WaitForTransactionStatusTask,\n} from '@lifi/sdk'\nimport type { Wallet, WalletAccount } from '@wallet-standard/base'\nimport { parseSolanaErrors } from '../errors/parseSolanaErrors.js'\nimport type {\n SolanaStepExecutorContext,\n SolanaStepExecutorOptions,\n} from '../types.js'\nimport { SolanaSignAndExecuteTask } from './tasks/SolanaSignAndExecuteTask.js'\nimport { SolanaWaitForTransactionTask } from './tasks/SolanaWaitForTransactionTask.js'\n\nexport class SolanaStepExecutor extends BaseStepExecutor {\n private wallet: Wallet\n private skipSimulation: boolean\n\n constructor(options: SolanaStepExecutorOptions) {\n super(options)\n this.wallet = options.wallet\n this.skipSimulation = options.skipSimulation ?? false\n }\n\n getWalletAccount = (step: LiFiStepExtended): WalletAccount => {\n const account = this.wallet.accounts.find(\n (account) => account.address === step.action.fromAddress\n )\n\n if (!account) {\n throw new TransactionError(\n LiFiErrorCode.WalletChangedDuringExecution,\n 'The wallet address that requested the quote does not match the wallet address attempting to sign the transaction.'\n )\n }\n\n return account\n }\n\n override parseErrors = (\n error: Error,\n step?: LiFiStepExtended,\n action?: ExecutionAction\n ): Promise<SDKError> => parseSolanaErrors(error, step, action)\n\n override createContext = async (\n baseContext: StepExecutorBaseContext\n ): Promise<SolanaStepExecutorContext> => {\n // The account is resolved by the sign task, not here: a resume that only\n // waits must not fail because the wallet has not reconnected yet.\n return {\n ...baseContext,\n wallet: this.wallet,\n getWalletAccount: this.getWalletAccount,\n skipSimulation: this.skipSimulation,\n }\n }\n\n override createPipeline = (\n context: SolanaStepExecutorContext\n ): TaskPipeline => {\n const { step, isBridgeExecution } = context\n\n const tasks = [\n new CheckBalanceTask(),\n new PrepareTransactionTask(),\n new SolanaSignAndExecuteTask(),\n new SolanaWaitForTransactionTask(),\n new WaitForTransactionStatusTask(\n isBridgeExecution ? 'RECEIVING_CHAIN' : 'SWAP'\n ),\n ]\n\n const swapOrBridgeAction = this.statusManager.findAction(\n step,\n isBridgeExecution ? 'CROSS_CHAIN' : 'SWAP'\n )\n\n // Three-way, as Stellar and Bitcoin do. An open transaction - a broadcast\n // signature, or signed bytes that may have been sent - resumes at the\n // wait task, which looks it up and resends the same bytes. Starting at\n // CheckBalanceTask would fetch a new quote and sign a second transaction\n // while the first can still land. A same-chain swap stays PENDING with\n // its signature until the LI.FI status is DONE, so this is the common\n // reload.\n const firstTask = hasOpenTransaction(swapOrBridgeAction)\n ? swapOrBridgeAction?.status === 'DONE'\n ? WaitForTransactionStatusTask\n : SolanaWaitForTransactionTask\n : CheckBalanceTask\n\n // Compare classes, not names: a minifier can give two task classes the\n // same name.\n const firstTaskIndex = tasks.findIndex(\n (task) => task.constructor === firstTask\n )\n if (firstTaskIndex === -1) {\n throw new TransactionError(\n LiFiErrorCode.InternalError,\n 'SolanaStepExecutor.createPipeline: first task not found'\n )\n }\n\n const tasksToRun = tasks.slice(firstTaskIndex)\n\n return new TaskPipeline(tasksToRun)\n }\n}\n"],"mappings":";;;;;;AAuBA,IAAa,qBAAb,cAAwCA,UAAAA,iBAAiB;
|
|
1
|
+
{"version":3,"file":"SolanaStepExecutor.js","names":["BaseStepExecutor","TransactionError","LiFiErrorCode","parseSolanaErrors","CheckBalanceTask","PrepareTransactionTask","SolanaSignAndExecuteTask","SolanaWaitForTransactionTask","WaitForTransactionStatusTask","hasOpenTransaction","TaskPipeline"],"sources":["../../../src/core/SolanaStepExecutor.ts"],"sourcesContent":["import {\n BaseStepExecutor,\n CheckBalanceTask,\n type ExecutionAction,\n hasOpenTransaction,\n LiFiErrorCode,\n type LiFiStepExtended,\n PrepareTransactionTask,\n type SDKError,\n type StepExecutorBaseContext,\n TaskPipeline,\n TransactionError,\n WaitForTransactionStatusTask,\n} from '@lifi/sdk'\nimport type { Wallet, WalletAccount } from '@wallet-standard/base'\nimport { parseSolanaErrors } from '../errors/parseSolanaErrors.js'\nimport type {\n SolanaStepExecutorContext,\n SolanaStepExecutorOptions,\n} from '../types.js'\nimport { SolanaSignAndExecuteTask } from './tasks/SolanaSignAndExecuteTask.js'\nimport { SolanaWaitForTransactionTask } from './tasks/SolanaWaitForTransactionTask.js'\n\nexport class SolanaStepExecutor extends BaseStepExecutor {\n private wallet: Wallet\n private skipSimulation: boolean\n\n constructor(options: SolanaStepExecutorOptions) {\n super(options)\n this.wallet = options.wallet\n this.skipSimulation = options.skipSimulation ?? false\n }\n\n getWalletAccount = (step: LiFiStepExtended): WalletAccount => {\n const account = this.wallet.accounts.find(\n (account) => account.address === step.action.fromAddress\n )\n\n if (!account) {\n throw new TransactionError(\n LiFiErrorCode.WalletChangedDuringExecution,\n 'The wallet address that requested the quote does not match the wallet address attempting to sign the transaction.'\n )\n }\n\n return account\n }\n\n override parseErrors = (\n error: Error,\n step?: LiFiStepExtended,\n action?: ExecutionAction\n ): Promise<SDKError> => parseSolanaErrors(error, step, action)\n\n override createContext = async (\n baseContext: StepExecutorBaseContext\n ): Promise<SolanaStepExecutorContext> => {\n // The account is resolved by the sign task, not here: a resume that only\n // waits must not fail because the wallet has not reconnected yet.\n return {\n ...baseContext,\n wallet: this.wallet,\n getWalletAccount: this.getWalletAccount,\n skipSimulation: this.skipSimulation,\n }\n }\n\n override createPipeline = (\n context: SolanaStepExecutorContext\n ): TaskPipeline => {\n const { step, isBridgeExecution } = context\n\n const tasks = [\n new CheckBalanceTask(),\n new PrepareTransactionTask(),\n new SolanaSignAndExecuteTask(),\n new SolanaWaitForTransactionTask(),\n new WaitForTransactionStatusTask(\n isBridgeExecution ? 'RECEIVING_CHAIN' : 'SWAP'\n ),\n ]\n\n const swapOrBridgeAction = this.statusManager.findAction(\n step,\n isBridgeExecution ? 'CROSS_CHAIN' : 'SWAP'\n )\n\n // Three-way, as Stellar and Bitcoin do. An open transaction - a broadcast\n // signature, or signed bytes that may have been sent - resumes at the\n // wait task, which looks it up and resends the same bytes. Starting at\n // CheckBalanceTask would fetch a new quote and sign a second transaction\n // while the first can still land. A same-chain swap stays PENDING with\n // its signature until the LI.FI status is DONE, so this is the common\n // reload.\n const firstTask = hasOpenTransaction(swapOrBridgeAction)\n ? swapOrBridgeAction?.status === 'DONE'\n ? WaitForTransactionStatusTask\n : SolanaWaitForTransactionTask\n : CheckBalanceTask\n\n // Compare classes, not names: a minifier can give two task classes the\n // same name.\n const firstTaskIndex = tasks.findIndex(\n (task) => task.constructor === firstTask\n )\n if (firstTaskIndex === -1) {\n throw new TransactionError(\n LiFiErrorCode.InternalError,\n 'SolanaStepExecutor.createPipeline: first task not found'\n )\n }\n\n const tasksToRun = tasks.slice(firstTaskIndex)\n\n return new TaskPipeline(tasksToRun)\n }\n}\n"],"mappings":";;;;;;AAuBA,IAAa,qBAAb,cAAwCA,UAAAA,iBAAiB;CAC/C;CACA;CAER,YAAY,SAAoC;EAC9C,MAAM,OAAO;EACb,KAAK,SAAS,QAAQ;EACtB,KAAK,iBAAiB,QAAQ,kBAAkB;CAClD;CAEA,oBAAoB,SAA0C;EAC5D,MAAM,UAAU,KAAK,OAAO,SAAS,MAClC,YAAY,QAAQ,YAAY,KAAK,OAAO,WAC/C;EAEA,IAAI,CAAC,SACH,MAAM,IAAIC,UAAAA,iBACRC,UAAAA,cAAc,8BACd,mHACF;EAGF,OAAO;CACT;CAES,eACP,OACA,MACA,WACsBC,iCAAAA,kBAAkB,OAAO,MAAM,MAAM;CAEpD,gBAAgB,OACvB,gBACuC;EAGvC,OAAO;GACL,GAAG;GACH,QAAQ,KAAK;GACb,kBAAkB,KAAK;GACvB,gBAAgB,KAAK;EACvB;CACF;CAES,kBACP,YACiB;EACjB,MAAM,EAAE,MAAM,sBAAsB;EAEpC,MAAM,QAAQ;GACZ,IAAIC,UAAAA,iBAAiB;GACrB,IAAIC,UAAAA,uBAAuB;GAC3B,IAAIC,4CAAAA,yBAAyB;GAC7B,IAAIC,gDAAAA,6BAA6B;GACjC,IAAIC,UAAAA,6BACF,oBAAoB,oBAAoB,MAC1C;EACF;EAEA,MAAM,qBAAqB,KAAK,cAAc,WAC5C,MACA,oBAAoB,gBAAgB,MACtC;EASA,MAAM,aAAA,GAAYC,UAAAA,mBAAAA,CAAmB,kBAAkB,IACnD,oBAAoB,WAAW,SAC7BD,UAAAA,+BACAD,gDAAAA,+BACFH,UAAAA;EAIJ,MAAM,iBAAiB,MAAM,WAC1B,SAAS,KAAK,gBAAgB,SACjC;EACA,IAAI,mBAAmB,IACrB,MAAM,IAAIH,UAAAA,iBACRC,UAAAA,cAAc,eACd,yDACF;EAGF,MAAM,aAAa,MAAM,MAAM,cAAc;EAE7C,OAAO,IAAIQ,UAAAA,aAAa,UAAU;CACpC;AACF"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"SolanaJitoWaitForTransactionTask.js","names":["failureOf","BaseStepExecutionTask","TransactionError","LiFiErrorCode","resumeFromStore","readSignature","getTransactionLifetime","getTxLink","sendAndSettle","canResendStored","sendAndConfirmBundle"],"sources":["../../../../src/core/tasks/SolanaJitoWaitForTransactionTask.ts"],"sourcesContent":["import {\n BaseStepExecutionTask,\n type ExecutionAction,\n LiFiErrorCode,\n type TaskResult,\n TransactionError,\n} from '@lifi/sdk'\nimport type { Signature, Transaction } from '@solana/kit'\nimport { sendAndConfirmBundle } from '../../actions/sendAndConfirmBundle.js'\nimport type { BundleConfirmation } from '../../confirmation/confirmBundle.js'\nimport type { RaceResult } from '../../confirmation/raceRpcs.js'\nimport type { SolanaStepExecutorContext } from '../../types.js'\nimport {\n getTransactionLifetime,\n type TransactionLifetime,\n} from '../../utils/getTransactionLifetime.js'\nimport type { ConfirmationMessages } from './confirmationError.js'\nimport { readSignature } from './readSignature.js'\nimport { resumeFromStore } from './resumeFromStore.js'\nimport {\n canResendStored,\n clearStoredTransactions,\n failureOf,\n getTxLink,\n sendAndSettle,\n} from './transactionOutcome.js'\n\n// The `rpc-unavailable` message is distinct from the empty-list throw inside\n// `sendAndConfirmBundle`: RPCs were configured and every one of them failed.\n// Every read RPC confirms and waits for the one shared submission, so a\n// refused submission fails every branch with the same error.\nconst MESSAGES: ConfirmationMessages = {\n rpcUnavailable:\n 'Unable to confirm bundle: every configured Solana RPC failed.',\n notConfirmed: 'Bundle was not confirmed before the SDK stopped waiting.',\n allRpcsFailed: 'All Solana RPCs failed',\n someRpcsFailed:\n 'Some Solana RPCs failed while the confirmation window was open',\n}\n\n/** The failure of a landed bundle, if any: the first transaction `err`. */\nfunction bundleFailureOf(\n confirmation: BundleConfirmation\n): { err: unknown } | undefined {\n return confirmation.signatureResults.map(failureOf).find(Boolean)\n}\n\nexport class SolanaJitoWaitForTransactionTask extends BaseStepExecutionTask {\n async run(context: SolanaStepExecutorContext): Promise<TaskResult> {\n const { step, statusManager, isBridgeExecution, signedTransactions } =\n context\n\n const action = statusManager.findAction(\n step,\n isBridgeExecution ? 'CROSS_CHAIN' : 'SWAP'\n )\n if (!action) {\n throw new TransactionError(\n LiFiErrorCode.TransactionUnprepared,\n 'Unable to prepare transaction. Action not found.'\n )\n }\n\n // Resume mode: the sign task did not run in this session, so the signed\n // bundle comes from `txHex`, or only the first hash from `txHash`.\n if (!signedTransactions) {\n return resumeFromStore(context, action, {\n messages: MESSAGES,\n // Submitted once, as on the first run.\n send: (stored, lifetimes) =>\n sendSigned(context, action, {\n transactions: stored.transactions,\n signature: stored.signature,\n lifetimes,\n resuming: true,\n }),\n })\n }\n\n if (!signedTransactions.length) {\n throw new TransactionError(\n LiFiErrorCode.TransactionUnprepared,\n 'Unable to prepare transaction. Signed transactions are not found.'\n )\n }\n\n let txSignature: Signature\n try {\n txSignature = readSignature(signedTransactions[0])\n } catch (error) {\n // Nothing left the SDK: the bytes go, so \"Try again\" signs again.\n clearStoredTransactions(context, action)\n throw error\n }\n\n const lifetimes = await Promise.all(\n signedTransactions.map((transaction) =>\n getTransactionLifetime(transaction)\n )\n )\n\n return sendSigned(context, action, {\n transactions: signedTransactions,\n signature: txSignature,\n lifetimes,\n resuming: false,\n })\n }\n}\n\n/**\n * Submits the signed bundle once, confirms it and applies the result rules\n * of `sendAndSettle`, on the first run and on a resume alike. A Jito bundle\n * lands whole or not at all, so the first transaction's signature stands for\n * it. A sender that is not Jito can land the transactions one by one; a\n * lookup by the first signature then misses a partial landing.\n */\nfunction sendSigned(\n context: SolanaStepExecutorContext,\n action: ExecutionAction,\n options: {\n transactions: Transaction[]\n signature: Signature\n lifetimes: TransactionLifetime[]\n /** An earlier run may already have submitted this bundle. */\n resuming: boolean\n }\n): Promise<TaskResult> {\n const { client, step, statusManager } = context\n const { transactions, signature, lifetimes, resuming } = options\n const txLink = getTxLink(context, signature)\n\n return sendAndSettle(context, action, {\n signature,\n send: async (): Promise<RaceResult<BundleConfirmation>> => {\n // Read right before the one submission: a bundle without its own\n // expiry goes out only inside the resend age cap. Past it nothing is\n // sent, and the outcome stays unknown until the dropped rule holds.\n if (!canResendStored(lifetimes, step.execution?.signedAt)) {\n return {\n kind: 'not-confirmed',\n errors: [\n new Error(\n 'The resend age cap has passed; the stored bundle is not sent.'\n ),\n ],\n }\n }\n // An empty Jito RPC list - the configuration gap, as opposed to an\n // outage - throws inside `sendAndConfirmBundle` with its own message,\n // before anything is submitted.\n return sendAndConfirmBundle(client, transactions, {\n onBroadcast: () => {\n // The earliest honest point for both: an RPC has accepted the\n // transaction, so the signature now resolves on chain.\n statusManager.updateAction(step, action.type, 'PENDING', {\n txHash: signature,\n txLink,\n })\n },\n })\n },\n confirmedFailure: bundleFailureOf,\n resuming,\n messages: MESSAGES,\n })\n}\n"],"mappings":";;;;;;;;AA+BA,MAAM,WAAiC;CACrC,gBACE;CACF,cAAc;CACd,eAAe;CACf,gBACE;AACJ;;AAGA,SAAS,gBACP,cAC8B;CAC9B,OAAO,aAAa,iBAAiB,IAAIA,sCAAAA,SAAS,CAAC,CAAC,KAAK,OAAO;AAClE;AAEA,IAAa,mCAAb,cAAsDC,UAAAA,sBAAsB;CAC1E,MAAM,IAAI,SAAyD;EACjE,MAAM,EAAE,MAAM,eAAe,mBAAmB,uBAC9C;EAEF,MAAM,SAAS,cAAc,WAC3B,MACA,oBAAoB,gBAAgB,MACtC;EACA,IAAI,CAAC,QACH,MAAM,IAAIC,UAAAA,iBACRC,UAAAA,cAAc,uBACd,kDACF;EAKF,IAAI,CAAC,oBACH,OAAOC,mCAAAA,gBAAgB,SAAS,QAAQ;GACtC,UAAU;GAEV,OAAO,QAAQ,cACb,WAAW,SAAS,QAAQ;IAC1B,cAAc,OAAO;IACrB,WAAW,OAAO;IAClB;IACA,UAAU;GACZ,CAAC;EACL,CAAC;EAGH,IAAI,CAAC,mBAAmB,QACtB,MAAM,IAAIF,UAAAA,iBACRC,UAAAA,cAAc,uBACd,mEACF;EAGF,IAAI;EACJ,IAAI;GACF,cAAcE,iCAAAA,cAAc,mBAAmB,EAAE;EACnD,SAAS,OAAO;
|
|
1
|
+
{"version":3,"file":"SolanaJitoWaitForTransactionTask.js","names":["failureOf","BaseStepExecutionTask","TransactionError","LiFiErrorCode","resumeFromStore","readSignature","clearStoredTransactions","getTransactionLifetime","getTxLink","sendAndSettle","canResendStored","sendAndConfirmBundle"],"sources":["../../../../src/core/tasks/SolanaJitoWaitForTransactionTask.ts"],"sourcesContent":["import {\n BaseStepExecutionTask,\n type ExecutionAction,\n LiFiErrorCode,\n type TaskResult,\n TransactionError,\n} from '@lifi/sdk'\nimport type { Signature, Transaction } from '@solana/kit'\nimport { sendAndConfirmBundle } from '../../actions/sendAndConfirmBundle.js'\nimport type { BundleConfirmation } from '../../confirmation/confirmBundle.js'\nimport type { RaceResult } from '../../confirmation/raceRpcs.js'\nimport type { SolanaStepExecutorContext } from '../../types.js'\nimport {\n getTransactionLifetime,\n type TransactionLifetime,\n} from '../../utils/getTransactionLifetime.js'\nimport type { ConfirmationMessages } from './confirmationError.js'\nimport { readSignature } from './readSignature.js'\nimport { resumeFromStore } from './resumeFromStore.js'\nimport {\n canResendStored,\n clearStoredTransactions,\n failureOf,\n getTxLink,\n sendAndSettle,\n} from './transactionOutcome.js'\n\n// The `rpc-unavailable` message is distinct from the empty-list throw inside\n// `sendAndConfirmBundle`: RPCs were configured and every one of them failed.\n// Every read RPC confirms and waits for the one shared submission, so a\n// refused submission fails every branch with the same error.\nconst MESSAGES: ConfirmationMessages = {\n rpcUnavailable:\n 'Unable to confirm bundle: every configured Solana RPC failed.',\n notConfirmed: 'Bundle was not confirmed before the SDK stopped waiting.',\n allRpcsFailed: 'All Solana RPCs failed',\n someRpcsFailed:\n 'Some Solana RPCs failed while the confirmation window was open',\n}\n\n/** The failure of a landed bundle, if any: the first transaction `err`. */\nfunction bundleFailureOf(\n confirmation: BundleConfirmation\n): { err: unknown } | undefined {\n return confirmation.signatureResults.map(failureOf).find(Boolean)\n}\n\nexport class SolanaJitoWaitForTransactionTask extends BaseStepExecutionTask {\n async run(context: SolanaStepExecutorContext): Promise<TaskResult> {\n const { step, statusManager, isBridgeExecution, signedTransactions } =\n context\n\n const action = statusManager.findAction(\n step,\n isBridgeExecution ? 'CROSS_CHAIN' : 'SWAP'\n )\n if (!action) {\n throw new TransactionError(\n LiFiErrorCode.TransactionUnprepared,\n 'Unable to prepare transaction. Action not found.'\n )\n }\n\n // Resume mode: the sign task did not run in this session, so the signed\n // bundle comes from `txHex`, or only the first hash from `txHash`.\n if (!signedTransactions) {\n return resumeFromStore(context, action, {\n messages: MESSAGES,\n // Submitted once, as on the first run.\n send: (stored, lifetimes) =>\n sendSigned(context, action, {\n transactions: stored.transactions,\n signature: stored.signature,\n lifetimes,\n resuming: true,\n }),\n })\n }\n\n if (!signedTransactions.length) {\n throw new TransactionError(\n LiFiErrorCode.TransactionUnprepared,\n 'Unable to prepare transaction. Signed transactions are not found.'\n )\n }\n\n let txSignature: Signature\n try {\n txSignature = readSignature(signedTransactions[0])\n } catch (error) {\n // Nothing left the SDK: the bytes go, so \"Try again\" signs again.\n clearStoredTransactions(context, action)\n throw error\n }\n\n const lifetimes = await Promise.all(\n signedTransactions.map((transaction) =>\n getTransactionLifetime(transaction)\n )\n )\n\n return sendSigned(context, action, {\n transactions: signedTransactions,\n signature: txSignature,\n lifetimes,\n resuming: false,\n })\n }\n}\n\n/**\n * Submits the signed bundle once, confirms it and applies the result rules\n * of `sendAndSettle`, on the first run and on a resume alike. A Jito bundle\n * lands whole or not at all, so the first transaction's signature stands for\n * it. A sender that is not Jito can land the transactions one by one; a\n * lookup by the first signature then misses a partial landing.\n */\nfunction sendSigned(\n context: SolanaStepExecutorContext,\n action: ExecutionAction,\n options: {\n transactions: Transaction[]\n signature: Signature\n lifetimes: TransactionLifetime[]\n /** An earlier run may already have submitted this bundle. */\n resuming: boolean\n }\n): Promise<TaskResult> {\n const { client, step, statusManager } = context\n const { transactions, signature, lifetimes, resuming } = options\n const txLink = getTxLink(context, signature)\n\n return sendAndSettle(context, action, {\n signature,\n send: async (): Promise<RaceResult<BundleConfirmation>> => {\n // Read right before the one submission: a bundle without its own\n // expiry goes out only inside the resend age cap. Past it nothing is\n // sent, and the outcome stays unknown until the dropped rule holds.\n if (!canResendStored(lifetimes, step.execution?.signedAt)) {\n return {\n kind: 'not-confirmed',\n errors: [\n new Error(\n 'The resend age cap has passed; the stored bundle is not sent.'\n ),\n ],\n }\n }\n // An empty Jito RPC list - the configuration gap, as opposed to an\n // outage - throws inside `sendAndConfirmBundle` with its own message,\n // before anything is submitted.\n return sendAndConfirmBundle(client, transactions, {\n onBroadcast: () => {\n // The earliest honest point for both: an RPC has accepted the\n // transaction, so the signature now resolves on chain.\n statusManager.updateAction(step, action.type, 'PENDING', {\n txHash: signature,\n txLink,\n })\n },\n })\n },\n confirmedFailure: bundleFailureOf,\n resuming,\n messages: MESSAGES,\n })\n}\n"],"mappings":";;;;;;;;AA+BA,MAAM,WAAiC;CACrC,gBACE;CACF,cAAc;CACd,eAAe;CACf,gBACE;AACJ;;AAGA,SAAS,gBACP,cAC8B;CAC9B,OAAO,aAAa,iBAAiB,IAAIA,sCAAAA,SAAS,CAAC,CAAC,KAAK,OAAO;AAClE;AAEA,IAAa,mCAAb,cAAsDC,UAAAA,sBAAsB;CAC1E,MAAM,IAAI,SAAyD;EACjE,MAAM,EAAE,MAAM,eAAe,mBAAmB,uBAC9C;EAEF,MAAM,SAAS,cAAc,WAC3B,MACA,oBAAoB,gBAAgB,MACtC;EACA,IAAI,CAAC,QACH,MAAM,IAAIC,UAAAA,iBACRC,UAAAA,cAAc,uBACd,kDACF;EAKF,IAAI,CAAC,oBACH,OAAOC,mCAAAA,gBAAgB,SAAS,QAAQ;GACtC,UAAU;GAEV,OAAO,QAAQ,cACb,WAAW,SAAS,QAAQ;IAC1B,cAAc,OAAO;IACrB,WAAW,OAAO;IAClB;IACA,UAAU;GACZ,CAAC;EACL,CAAC;EAGH,IAAI,CAAC,mBAAmB,QACtB,MAAM,IAAIF,UAAAA,iBACRC,UAAAA,cAAc,uBACd,mEACF;EAGF,IAAI;EACJ,IAAI;GACF,cAAcE,iCAAAA,cAAc,mBAAmB,EAAE;EACnD,SAAS,OAAO;GAEdC,sCAAAA,wBAAwB,SAAS,MAAM;GACvC,MAAM;EACR;EAEA,MAAM,YAAY,MAAM,QAAQ,IAC9B,mBAAmB,KAAK,gBACtBC,qCAAAA,uBAAuB,WAAW,CACpC,CACF;EAEA,OAAO,WAAW,SAAS,QAAQ;GACjC,cAAc;GACd,WAAW;GACX;GACA,UAAU;EACZ,CAAC;CACH;AACF;;;;;;;;AASA,SAAS,WACP,SACA,QACA,SAOqB;CACrB,MAAM,EAAE,QAAQ,MAAM,kBAAkB;CACxC,MAAM,EAAE,cAAc,WAAW,WAAW,aAAa;CACzD,MAAM,SAASC,sCAAAA,UAAU,SAAS,SAAS;CAE3C,OAAOC,sCAAAA,cAAc,SAAS,QAAQ;EACpC;EACA,MAAM,YAAqD;GAIzD,IAAI,CAACC,sCAAAA,gBAAgB,WAAW,KAAK,WAAW,QAAQ,GACtD,OAAO;IACL,MAAM;IACN,QAAQ,iBACN,IAAI,MACF,+DACF,CACF;GACF;GAKF,OAAOC,qCAAAA,qBAAqB,QAAQ,cAAc,EAChD,mBAAmB;IAGjB,cAAc,aAAa,MAAM,OAAO,MAAM,WAAW;KACvD,QAAQ;KACR;IACF,CAAC;GACH,EACF,CAAC;EACH;EACA,kBAAkB;EAClB;EACA,UAAU;CACZ,CAAC;AACH"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"SolanaSignAndExecuteTask.js","names":["BaseStepExecutionTask","TransactionError","LiFiErrorCode","getTransactionRequestData","base64ToUint8Array","withTimeout","getWalletFeature","SolanaSignTransaction","CLEARED_TRANSACTION_FIELDS","getTransactionCodec","encodeStoredTransactions"],"sources":["../../../../src/core/tasks/SolanaSignAndExecuteTask.ts"],"sourcesContent":["import {\n assertNoOpenTransaction,\n BaseStepExecutionTask,\n CLEARED_TRANSACTION_FIELDS,\n getTransactionRequestData,\n LiFiErrorCode,\n type TaskResult,\n TransactionError,\n withTimeout,\n} from '@lifi/sdk'\nimport { getTransactionCodec } from '@solana/kit'\nimport { SolanaSignTransaction } from '@solana/wallet-standard-features'\nimport type { SolanaStepExecutorContext } from '../../types.js'\nimport { base64ToUint8Array } from '../../utils/base64ToUint8Array.js'\nimport { getWalletFeature } from '../../utils/getWalletFeature.js'\nimport { encodeStoredTransactions } from '../../utils/storedTransactions.js'\nimport { readSignature } from './readSignature.js'\n\nexport class SolanaSignAndExecuteTask extends BaseStepExecutionTask {\n async run(context: SolanaStepExecutorContext): Promise<TaskResult> {\n const {\n step,\n wallet,\n getWalletAccount,\n statusManager,\n executionOptions,\n isBridgeExecution,\n } = context\n\n const action = statusManager.findAction(\n step,\n isBridgeExecution ? 'CROSS_CHAIN' : 'SWAP'\n )\n\n // Defence in depth: the selector sends an action with an open\n // transaction to the wait task. Signing here could put a second\n // transaction on chain while the first can still land.\n assertNoOpenTransaction(action)\n\n if (!action) {\n throw new TransactionError(\n LiFiErrorCode.TransactionUnprepared,\n 'Unable to prepare transaction. Action not found.'\n )\n }\n\n // Resolved here and not in `createContext`: a resume that only waits\n // never signs, so it must not fail because the wallet has not\n // reconnected yet.\n const walletAccount = getWalletAccount(step)\n\n const transactionRequestData = (await getTransactionRequestData(\n step,\n executionOptions\n )) as string | string[]\n\n // The backend returns an array when it produced a Jito bundle and a string\n // for a single transaction. The shape determines how we submit it later:\n // array -> sendBundle, string -> sendTransaction.\n const isBundleExecution = Array.isArray(transactionRequestData)\n\n const transactionDataArray = isBundleExecution\n ? transactionRequestData\n : [transactionRequestData]\n\n const transactionBytesArray = transactionDataArray.map((data) =>\n base64ToUint8Array(data)\n )\n\n // Checked again right before the wallet: a late write of an older run\n // can merge its transaction into this action during the await above.\n assertNoOpenTransaction(statusManager.findAction(step, action.type))\n\n const signedTransactionOutputs = await withTimeout(\n async () => {\n const { signTransaction } = getWalletFeature(\n wallet,\n SolanaSignTransaction\n )\n // Spread the inputs to sign all transactions at once\n return signTransaction(\n ...transactionBytesArray.map((transaction) => ({\n account: walletAccount,\n transaction,\n }))\n )\n },\n {\n // https://solana.com/docs/advanced/confirmation#transaction-expiration\n // Use 2 minutes to account for fluctuations\n timeout: 120_000,\n errorInstance: new TransactionError(\n LiFiErrorCode.TransactionExpired,\n 'Transaction has expired: blockhash is no longer recent enough.'\n ),\n }\n )\n\n // Checked once more after the wallet: a stopped run's late write can\n // merge its transaction into this action while the prompt is open.\n // Nothing awaits from here to the two writes below, so no late write can\n // land between this check and either of them.\n assertNoOpenTransaction(statusManager.findAction(step, action.type))\n\n if (signedTransactionOutputs.length === 0) {\n throw new TransactionError(\n LiFiErrorCode.TransactionUnprepared,\n 'No signed transaction returned from signer.'\n )\n }\n\n // Neither `txHash` nor `txLink` is written here. A signature is fixed at\n // signing, but the transaction does not exist yet: `getTransaction`\n // returns `null` for it, and simulation, the empty-Jito-RPC throw and\n // every send failure all sit between this task and the first broadcast.\n // The wait tasks write both on `onBroadcast`, when an RPC has accepted it.\n //\n // The previous transaction's fields (`CLEARED_TRANSACTION_FIELDS`) are\n // cleared explicitly. Only a final failure reaches this task with them\n // set, and a stale hash would look open again once its `txFinal` is gone.\n // This write runs BEFORE the decode below, which can throw on a malformed\n // wallet output and would otherwise strand the old fields.\n statusManager.updateAction(step, action.type, 'PENDING', {\n ...CLEARED_TRANSACTION_FIELDS,\n signedAt: Date.now(),\n })\n\n const transactionCodec = getTransactionCodec()\n\n // Decode all signed transactions\n const signedTransactions = signedTransactionOutputs.map((output) =>\n transactionCodec.decode(output.signedTransaction)\n )\n\n // Every transaction must carry its fee payer signature before its bytes\n // are stored: an unreadable value would fail every resume the same way.\n // Nothing has been sent yet, so the `TransactionUnprepared` this throws\n // leaves \"Try again\" free to sign again.\n for (const signedTransaction of signedTransactions) {\n readSignature(signedTransaction)\n }\n\n // Stored before any send: a reload from here on resends these bytes\n // instead of asking the wallet again. A bundle stays a JSON array, which\n // is how a resume knows to submit it with `sendBundle`.\n statusManager.updateAction(step, action.type, 'PENDING', {\n txHex: encodeStoredTransactions(\n signedTransactionOutputs.map((output) => output.signedTransaction),\n isBundleExecution\n ),\n })\n\n return {\n status: 'COMPLETED',\n context: { signedTransactions, isBundleExecution },\n }\n }\n}\n"],"mappings":";;;;;;;;;AAkBA,IAAa,2BAAb,cAA8CA,UAAAA,sBAAsB;CAClE,MAAM,IAAI,SAAyD;EACjE,MAAM,EACJ,MACA,QACA,kBACA,eACA,kBACA,sBACE;EAEJ,MAAM,SAAS,cAAc,WAC3B,MACA,oBAAoB,gBAAgB,MACtC;
|
|
1
|
+
{"version":3,"file":"SolanaSignAndExecuteTask.js","names":["BaseStepExecutionTask","assertNoOpenTransaction","TransactionError","LiFiErrorCode","getTransactionRequestData","base64ToUint8Array","withTimeout","getWalletFeature","SolanaSignTransaction","CLEARED_TRANSACTION_FIELDS","getTransactionCodec","readSignature","encodeStoredTransactions"],"sources":["../../../../src/core/tasks/SolanaSignAndExecuteTask.ts"],"sourcesContent":["import {\n assertNoOpenTransaction,\n BaseStepExecutionTask,\n CLEARED_TRANSACTION_FIELDS,\n getTransactionRequestData,\n LiFiErrorCode,\n type TaskResult,\n TransactionError,\n withTimeout,\n} from '@lifi/sdk'\nimport { getTransactionCodec } from '@solana/kit'\nimport { SolanaSignTransaction } from '@solana/wallet-standard-features'\nimport type { SolanaStepExecutorContext } from '../../types.js'\nimport { base64ToUint8Array } from '../../utils/base64ToUint8Array.js'\nimport { getWalletFeature } from '../../utils/getWalletFeature.js'\nimport { encodeStoredTransactions } from '../../utils/storedTransactions.js'\nimport { readSignature } from './readSignature.js'\n\nexport class SolanaSignAndExecuteTask extends BaseStepExecutionTask {\n async run(context: SolanaStepExecutorContext): Promise<TaskResult> {\n const {\n step,\n wallet,\n getWalletAccount,\n statusManager,\n executionOptions,\n isBridgeExecution,\n } = context\n\n const action = statusManager.findAction(\n step,\n isBridgeExecution ? 'CROSS_CHAIN' : 'SWAP'\n )\n\n // Defence in depth: the selector sends an action with an open\n // transaction to the wait task. Signing here could put a second\n // transaction on chain while the first can still land.\n assertNoOpenTransaction(action)\n\n if (!action) {\n throw new TransactionError(\n LiFiErrorCode.TransactionUnprepared,\n 'Unable to prepare transaction. Action not found.'\n )\n }\n\n // Resolved here and not in `createContext`: a resume that only waits\n // never signs, so it must not fail because the wallet has not\n // reconnected yet.\n const walletAccount = getWalletAccount(step)\n\n const transactionRequestData = (await getTransactionRequestData(\n step,\n executionOptions\n )) as string | string[]\n\n // The backend returns an array when it produced a Jito bundle and a string\n // for a single transaction. The shape determines how we submit it later:\n // array -> sendBundle, string -> sendTransaction.\n const isBundleExecution = Array.isArray(transactionRequestData)\n\n const transactionDataArray = isBundleExecution\n ? transactionRequestData\n : [transactionRequestData]\n\n const transactionBytesArray = transactionDataArray.map((data) =>\n base64ToUint8Array(data)\n )\n\n // Checked again right before the wallet: a late write of an older run\n // can merge its transaction into this action during the await above.\n assertNoOpenTransaction(statusManager.findAction(step, action.type))\n\n const signedTransactionOutputs = await withTimeout(\n async () => {\n const { signTransaction } = getWalletFeature(\n wallet,\n SolanaSignTransaction\n )\n // Spread the inputs to sign all transactions at once\n return signTransaction(\n ...transactionBytesArray.map((transaction) => ({\n account: walletAccount,\n transaction,\n }))\n )\n },\n {\n // https://solana.com/docs/advanced/confirmation#transaction-expiration\n // Use 2 minutes to account for fluctuations\n timeout: 120_000,\n errorInstance: new TransactionError(\n LiFiErrorCode.TransactionExpired,\n 'Transaction has expired: blockhash is no longer recent enough.'\n ),\n }\n )\n\n // Checked once more after the wallet: a stopped run's late write can\n // merge its transaction into this action while the prompt is open.\n // Nothing awaits from here to the two writes below, so no late write can\n // land between this check and either of them.\n assertNoOpenTransaction(statusManager.findAction(step, action.type))\n\n if (signedTransactionOutputs.length === 0) {\n throw new TransactionError(\n LiFiErrorCode.TransactionUnprepared,\n 'No signed transaction returned from signer.'\n )\n }\n\n // Neither `txHash` nor `txLink` is written here. A signature is fixed at\n // signing, but the transaction does not exist yet: `getTransaction`\n // returns `null` for it, and simulation, the empty-Jito-RPC throw and\n // every send failure all sit between this task and the first broadcast.\n // The wait tasks write both on `onBroadcast`, when an RPC has accepted it.\n //\n // The previous transaction's fields (`CLEARED_TRANSACTION_FIELDS`) are\n // cleared explicitly. Only a final failure reaches this task with them\n // set, and a stale hash would look open again once its `txFinal` is gone.\n // This write runs BEFORE the decode below, which can throw on a malformed\n // wallet output and would otherwise strand the old fields.\n statusManager.updateAction(step, action.type, 'PENDING', {\n ...CLEARED_TRANSACTION_FIELDS,\n signedAt: Date.now(),\n })\n\n const transactionCodec = getTransactionCodec()\n\n // Decode all signed transactions\n const signedTransactions = signedTransactionOutputs.map((output) =>\n transactionCodec.decode(output.signedTransaction)\n )\n\n // Every transaction must carry its fee payer signature before its bytes\n // are stored: an unreadable value would fail every resume the same way.\n // Nothing has been sent yet, so the `TransactionUnprepared` this throws\n // leaves \"Try again\" free to sign again.\n for (const signedTransaction of signedTransactions) {\n readSignature(signedTransaction)\n }\n\n // Stored before any send: a reload from here on resends these bytes\n // instead of asking the wallet again. A bundle stays a JSON array, which\n // is how a resume knows to submit it with `sendBundle`.\n statusManager.updateAction(step, action.type, 'PENDING', {\n txHex: encodeStoredTransactions(\n signedTransactionOutputs.map((output) => output.signedTransaction),\n isBundleExecution\n ),\n })\n\n return {\n status: 'COMPLETED',\n context: { signedTransactions, isBundleExecution },\n }\n }\n}\n"],"mappings":";;;;;;;;;AAkBA,IAAa,2BAAb,cAA8CA,UAAAA,sBAAsB;CAClE,MAAM,IAAI,SAAyD;EACjE,MAAM,EACJ,MACA,QACA,kBACA,eACA,kBACA,sBACE;EAEJ,MAAM,SAAS,cAAc,WAC3B,MACA,oBAAoB,gBAAgB,MACtC;EAKAC,CAAAA,GAAAA,UAAAA,wBAAAA,CAAwB,MAAM;EAE9B,IAAI,CAAC,QACH,MAAM,IAAIC,UAAAA,iBACRC,UAAAA,cAAc,uBACd,kDACF;EAMF,MAAM,gBAAgB,iBAAiB,IAAI;EAE3C,MAAM,yBAA0B,OAAA,GAAMC,UAAAA,0BAAAA,CACpC,MACA,gBACF;EAKA,MAAM,oBAAoB,MAAM,QAAQ,sBAAsB;EAM9D,MAAM,yBAJuB,oBACzB,yBACA,CAAC,sBAAsB,EAAA,CAEwB,KAAK,SACtDC,iCAAAA,mBAAmB,IAAI,CACzB;EAIAJ,CAAAA,GAAAA,UAAAA,wBAAAA,CAAwB,cAAc,WAAW,MAAM,OAAO,IAAI,CAAC;EAEnE,MAAM,2BAA2B,OAAA,GAAMK,UAAAA,YAAAA,CACrC,YAAY;GACV,MAAM,EAAE,oBAAoBC,+BAAAA,iBAC1B,QACAC,iCAAAA,qBACF;GAEA,OAAO,gBACL,GAAG,sBAAsB,KAAK,iBAAiB;IAC7C,SAAS;IACT;GACF,EAAE,CACJ;EACF,GACA;GAGE,SAAS;GACT,eAAe,IAAIN,UAAAA,iBACjBC,UAAAA,cAAc,oBACd,gEACF;EACF,CACF;EAMAF,CAAAA,GAAAA,UAAAA,wBAAAA,CAAwB,cAAc,WAAW,MAAM,OAAO,IAAI,CAAC;EAEnE,IAAI,yBAAyB,WAAW,GACtC,MAAM,IAAIC,UAAAA,iBACRC,UAAAA,cAAc,uBACd,6CACF;EAcF,cAAc,aAAa,MAAM,OAAO,MAAM,WAAW;GACvD,GAAGM,UAAAA;GACH,UAAU,KAAK,IAAI;EACrB,CAAC;EAED,MAAM,oBAAA,GAAmBC,YAAAA,oBAAAA,CAAoB;EAG7C,MAAM,qBAAqB,yBAAyB,KAAK,WACvD,iBAAiB,OAAO,OAAO,iBAAiB,CAClD;EAMA,KAAK,MAAM,qBAAqB,oBAC9BC,iCAAAA,cAAc,iBAAiB;EAMjC,cAAc,aAAa,MAAM,OAAO,MAAM,WAAW,EACvD,OAAOC,iCAAAA,yBACL,yBAAyB,KAAK,WAAW,OAAO,iBAAiB,GACjE,iBACF,EACF,CAAC;EAED,OAAO;GACL,QAAQ;GACR,SAAS;IAAE;IAAoB;GAAkB;EACnD;CACF;AACF"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"SolanaStandardWaitForTransactionTask.js","names":["BaseStepExecutionTask","TransactionError","LiFiErrorCode","resumeFromStore","readSignature","getTransactionLifetime","getTxLink","sendAndSettle","sendAndConfirmTransaction","canResendStored","failureOf","getBase64EncodedWireTransaction","callSolanaRpcsWithRetry","SolanaTransactionDetailsError"],"sources":["../../../../src/core/tasks/SolanaStandardWaitForTransactionTask.ts"],"sourcesContent":["import {\n BaseStepExecutionTask,\n type ExecutionAction,\n LiFiErrorCode,\n type TaskResult,\n TransactionError,\n} from '@lifi/sdk'\nimport {\n getBase64EncodedWireTransaction,\n type Signature,\n type Transaction,\n} from '@solana/kit'\nimport { sendAndConfirmTransaction } from '../../actions/sendAndConfirmTransaction.js'\nimport { callSolanaRpcsWithRetry } from '../../rpc/utils.js'\nimport type { SolanaStepExecutorContext } from '../../types.js'\nimport {\n getTransactionLifetime,\n type TransactionLifetime,\n} from '../../utils/getTransactionLifetime.js'\nimport { SolanaTransactionDetailsError } from '../../utils/solanaErrorCause.js'\nimport type { ConfirmationMessages } from './confirmationError.js'\nimport { readSignature } from './readSignature.js'\nimport { resumeFromStore } from './resumeFromStore.js'\nimport {\n canResendStored,\n clearStoredTransactions,\n failureOf,\n getTxLink,\n sendAndSettle,\n} from './transactionOutcome.js'\n\nconst MESSAGES: ConfirmationMessages = {\n rpcUnavailable:\n 'Unable to confirm transaction: no Solana RPC returned a usable response.',\n notConfirmed: 'Transaction was not confirmed before the SDK stopped waiting.',\n allRpcsFailed: 'All Solana RPCs failed',\n someRpcsFailed:\n 'Some Solana RPCs failed while the confirmation window was open',\n}\n\nexport class SolanaStandardWaitForTransactionTask extends BaseStepExecutionTask {\n async run(context: SolanaStepExecutorContext): Promise<TaskResult> {\n const { step, statusManager, isBridgeExecution, signedTransactions } =\n context\n\n const action = statusManager.findAction(\n step,\n isBridgeExecution ? 'CROSS_CHAIN' : 'SWAP'\n )\n if (!action) {\n throw new TransactionError(\n LiFiErrorCode.TransactionUnprepared,\n 'Unable to prepare transaction. Action not found.'\n )\n }\n\n // Resume mode: the sign task did not run in this session, so the signed\n // bytes come from `txHex`, or only the hash from `txHash`.\n if (!signedTransactions) {\n return resumeFromStore(context, action, {\n messages: MESSAGES,\n send: (stored, lifetimes) =>\n sendSigned(context, action, {\n transaction: stored.transactions[0],\n signature: stored.signature,\n lifetimes,\n resuming: true,\n }),\n })\n }\n\n if (!signedTransactions.length) {\n throw new TransactionError(\n LiFiErrorCode.TransactionUnprepared,\n 'Unable to prepare transaction. Signed transactions are not found.'\n )\n }\n\n // Use regular transaction submission\n const signedTransaction = signedTransactions[0]\n\n let txSignature: Signature\n let lifetime: TransactionLifetime\n try {\n if (!context.skipSimulation) {\n await simulate(context, signedTransaction)\n }\n txSignature = readSignature(signedTransaction)\n lifetime = await getTransactionLifetime(signedTransaction)\n } catch (error) {\n // Nothing left the SDK: the bytes go, so \"Try again\" signs again\n // instead of resending a transaction that failed before it was sent.\n clearStoredTransactions(context, action)\n throw error\n }\n\n return sendSigned(context, action, {\n transaction: signedTransaction,\n signature: txSignature,\n lifetimes: [lifetime],\n resuming: false,\n })\n }\n}\n\n/**\n * Sends one signed transaction, confirms it and applies the result rules of\n * `sendAndSettle`, on the first run and on a resume alike.\n */\nfunction sendSigned(\n context: SolanaStepExecutorContext,\n action: ExecutionAction,\n options: {\n transaction: Transaction\n signature: Signature\n lifetimes: TransactionLifetime[]\n /** An earlier run may already have sent these bytes. */\n resuming: boolean\n }\n): Promise<TaskResult> {\n const { client, step, statusManager } = context\n const { transaction, signature, lifetimes, resuming } = options\n const txLink = getTxLink(context, signature)\n\n return sendAndSettle(context, action, {\n signature,\n send: () =>\n sendAndConfirmTransaction(client, transaction, {\n onBroadcast: () => {\n // The earliest honest point for both: an RPC has accepted the\n // transaction, so the signature now resolves on chain.\n statusManager.updateAction(step, action.type, 'PENDING', {\n txHash: signature,\n txLink,\n })\n },\n // Read at every send: bytes without their own expiry go out only\n // inside the resend age cap, however long the resend loop runs.\n mayResend: () => canResendStored(lifetimes, step.execution?.signedAt),\n }),\n confirmedFailure: failureOf,\n resuming,\n messages: MESSAGES,\n })\n}\n\n/** First run only: a resend never simulates. */\nasync function simulate(\n context: SolanaStepExecutorContext,\n signedTransaction: Transaction\n): Promise<void> {\n const encodedTransaction = getBase64EncodedWireTransaction(signedTransaction)\n\n const simulationResult = await callSolanaRpcsWithRetry(\n context.client,\n (connection) =>\n connection\n .simulateTransaction(encodedTransaction, {\n commitment: 'confirmed',\n replaceRecentBlockhash: true,\n encoding: 'base64',\n })\n .send()\n )\n\n if (simulationResult.value.err) {\n const cause = new SolanaTransactionDetailsError(\n simulationResult.value.err,\n simulationResult.value.logs\n )\n throw new TransactionError(\n LiFiErrorCode.TransactionSimulationFailed,\n `Transaction simulation failed: ${cause.message}`,\n cause\n )\n }\n}\n"],"mappings":";;;;;;;;;;;AA+BA,MAAM,WAAiC;CACrC,gBACE;CACF,cAAc;CACd,eAAe;CACf,gBACE;AACJ;AAEA,IAAa,uCAAb,cAA0DA,UAAAA,sBAAsB;CAC9E,MAAM,IAAI,SAAyD;EACjE,MAAM,EAAE,MAAM,eAAe,mBAAmB,uBAC9C;EAEF,MAAM,SAAS,cAAc,WAC3B,MACA,oBAAoB,gBAAgB,MACtC;EACA,IAAI,CAAC,QACH,MAAM,IAAIC,UAAAA,iBACRC,UAAAA,cAAc,uBACd,kDACF;EAKF,IAAI,CAAC,oBACH,OAAOC,mCAAAA,gBAAgB,SAAS,QAAQ;GACtC,UAAU;GACV,OAAO,QAAQ,cACb,WAAW,SAAS,QAAQ;IAC1B,aAAa,OAAO,aAAa;IACjC,WAAW,OAAO;IAClB;IACA,UAAU;GACZ,CAAC;EACL,CAAC;EAGH,IAAI,CAAC,mBAAmB,QACtB,MAAM,IAAIF,UAAAA,iBACRC,UAAAA,cAAc,uBACd,mEACF;EAIF,MAAM,oBAAoB,mBAAmB;EAE7C,IAAI;EACJ,IAAI;EACJ,IAAI;GACF,IAAI,CAAC,QAAQ,gBACX,MAAM,SAAS,SAAS,iBAAiB;GAE3C,cAAcE,iCAAAA,cAAc,iBAAiB;GAC7C,WAAW,MAAMC,qCAAAA,uBAAuB,iBAAiB;EAC3D,SAAS,OAAO;
|
|
1
|
+
{"version":3,"file":"SolanaStandardWaitForTransactionTask.js","names":["BaseStepExecutionTask","TransactionError","LiFiErrorCode","resumeFromStore","readSignature","getTransactionLifetime","clearStoredTransactions","getTxLink","sendAndSettle","sendAndConfirmTransaction","canResendStored","failureOf","getBase64EncodedWireTransaction","callSolanaRpcsWithRetry","SolanaTransactionDetailsError"],"sources":["../../../../src/core/tasks/SolanaStandardWaitForTransactionTask.ts"],"sourcesContent":["import {\n BaseStepExecutionTask,\n type ExecutionAction,\n LiFiErrorCode,\n type TaskResult,\n TransactionError,\n} from '@lifi/sdk'\nimport {\n getBase64EncodedWireTransaction,\n type Signature,\n type Transaction,\n} from '@solana/kit'\nimport { sendAndConfirmTransaction } from '../../actions/sendAndConfirmTransaction.js'\nimport { callSolanaRpcsWithRetry } from '../../rpc/utils.js'\nimport type { SolanaStepExecutorContext } from '../../types.js'\nimport {\n getTransactionLifetime,\n type TransactionLifetime,\n} from '../../utils/getTransactionLifetime.js'\nimport { SolanaTransactionDetailsError } from '../../utils/solanaErrorCause.js'\nimport type { ConfirmationMessages } from './confirmationError.js'\nimport { readSignature } from './readSignature.js'\nimport { resumeFromStore } from './resumeFromStore.js'\nimport {\n canResendStored,\n clearStoredTransactions,\n failureOf,\n getTxLink,\n sendAndSettle,\n} from './transactionOutcome.js'\n\nconst MESSAGES: ConfirmationMessages = {\n rpcUnavailable:\n 'Unable to confirm transaction: no Solana RPC returned a usable response.',\n notConfirmed: 'Transaction was not confirmed before the SDK stopped waiting.',\n allRpcsFailed: 'All Solana RPCs failed',\n someRpcsFailed:\n 'Some Solana RPCs failed while the confirmation window was open',\n}\n\nexport class SolanaStandardWaitForTransactionTask extends BaseStepExecutionTask {\n async run(context: SolanaStepExecutorContext): Promise<TaskResult> {\n const { step, statusManager, isBridgeExecution, signedTransactions } =\n context\n\n const action = statusManager.findAction(\n step,\n isBridgeExecution ? 'CROSS_CHAIN' : 'SWAP'\n )\n if (!action) {\n throw new TransactionError(\n LiFiErrorCode.TransactionUnprepared,\n 'Unable to prepare transaction. Action not found.'\n )\n }\n\n // Resume mode: the sign task did not run in this session, so the signed\n // bytes come from `txHex`, or only the hash from `txHash`.\n if (!signedTransactions) {\n return resumeFromStore(context, action, {\n messages: MESSAGES,\n send: (stored, lifetimes) =>\n sendSigned(context, action, {\n transaction: stored.transactions[0],\n signature: stored.signature,\n lifetimes,\n resuming: true,\n }),\n })\n }\n\n if (!signedTransactions.length) {\n throw new TransactionError(\n LiFiErrorCode.TransactionUnprepared,\n 'Unable to prepare transaction. Signed transactions are not found.'\n )\n }\n\n // Use regular transaction submission\n const signedTransaction = signedTransactions[0]\n\n let txSignature: Signature\n let lifetime: TransactionLifetime\n try {\n if (!context.skipSimulation) {\n await simulate(context, signedTransaction)\n }\n txSignature = readSignature(signedTransaction)\n lifetime = await getTransactionLifetime(signedTransaction)\n } catch (error) {\n // Nothing left the SDK: the bytes go, so \"Try again\" signs again\n // instead of resending a transaction that failed before it was sent.\n clearStoredTransactions(context, action)\n throw error\n }\n\n return sendSigned(context, action, {\n transaction: signedTransaction,\n signature: txSignature,\n lifetimes: [lifetime],\n resuming: false,\n })\n }\n}\n\n/**\n * Sends one signed transaction, confirms it and applies the result rules of\n * `sendAndSettle`, on the first run and on a resume alike.\n */\nfunction sendSigned(\n context: SolanaStepExecutorContext,\n action: ExecutionAction,\n options: {\n transaction: Transaction\n signature: Signature\n lifetimes: TransactionLifetime[]\n /** An earlier run may already have sent these bytes. */\n resuming: boolean\n }\n): Promise<TaskResult> {\n const { client, step, statusManager } = context\n const { transaction, signature, lifetimes, resuming } = options\n const txLink = getTxLink(context, signature)\n\n return sendAndSettle(context, action, {\n signature,\n send: () =>\n sendAndConfirmTransaction(client, transaction, {\n onBroadcast: () => {\n // The earliest honest point for both: an RPC has accepted the\n // transaction, so the signature now resolves on chain.\n statusManager.updateAction(step, action.type, 'PENDING', {\n txHash: signature,\n txLink,\n })\n },\n // Read at every send: bytes without their own expiry go out only\n // inside the resend age cap, however long the resend loop runs.\n mayResend: () => canResendStored(lifetimes, step.execution?.signedAt),\n }),\n confirmedFailure: failureOf,\n resuming,\n messages: MESSAGES,\n })\n}\n\n/** First run only: a resend never simulates. */\nasync function simulate(\n context: SolanaStepExecutorContext,\n signedTransaction: Transaction\n): Promise<void> {\n const encodedTransaction = getBase64EncodedWireTransaction(signedTransaction)\n\n const simulationResult = await callSolanaRpcsWithRetry(\n context.client,\n (connection) =>\n connection\n .simulateTransaction(encodedTransaction, {\n commitment: 'confirmed',\n replaceRecentBlockhash: true,\n encoding: 'base64',\n })\n .send()\n )\n\n if (simulationResult.value.err) {\n const cause = new SolanaTransactionDetailsError(\n simulationResult.value.err,\n simulationResult.value.logs\n )\n throw new TransactionError(\n LiFiErrorCode.TransactionSimulationFailed,\n `Transaction simulation failed: ${cause.message}`,\n cause\n )\n }\n}\n"],"mappings":";;;;;;;;;;;AA+BA,MAAM,WAAiC;CACrC,gBACE;CACF,cAAc;CACd,eAAe;CACf,gBACE;AACJ;AAEA,IAAa,uCAAb,cAA0DA,UAAAA,sBAAsB;CAC9E,MAAM,IAAI,SAAyD;EACjE,MAAM,EAAE,MAAM,eAAe,mBAAmB,uBAC9C;EAEF,MAAM,SAAS,cAAc,WAC3B,MACA,oBAAoB,gBAAgB,MACtC;EACA,IAAI,CAAC,QACH,MAAM,IAAIC,UAAAA,iBACRC,UAAAA,cAAc,uBACd,kDACF;EAKF,IAAI,CAAC,oBACH,OAAOC,mCAAAA,gBAAgB,SAAS,QAAQ;GACtC,UAAU;GACV,OAAO,QAAQ,cACb,WAAW,SAAS,QAAQ;IAC1B,aAAa,OAAO,aAAa;IACjC,WAAW,OAAO;IAClB;IACA,UAAU;GACZ,CAAC;EACL,CAAC;EAGH,IAAI,CAAC,mBAAmB,QACtB,MAAM,IAAIF,UAAAA,iBACRC,UAAAA,cAAc,uBACd,mEACF;EAIF,MAAM,oBAAoB,mBAAmB;EAE7C,IAAI;EACJ,IAAI;EACJ,IAAI;GACF,IAAI,CAAC,QAAQ,gBACX,MAAM,SAAS,SAAS,iBAAiB;GAE3C,cAAcE,iCAAAA,cAAc,iBAAiB;GAC7C,WAAW,MAAMC,qCAAAA,uBAAuB,iBAAiB;EAC3D,SAAS,OAAO;GAGdC,sCAAAA,wBAAwB,SAAS,MAAM;GACvC,MAAM;EACR;EAEA,OAAO,WAAW,SAAS,QAAQ;GACjC,aAAa;GACb,WAAW;GACX,WAAW,CAAC,QAAQ;GACpB,UAAU;EACZ,CAAC;CACH;AACF;;;;;AAMA,SAAS,WACP,SACA,QACA,SAOqB;CACrB,MAAM,EAAE,QAAQ,MAAM,kBAAkB;CACxC,MAAM,EAAE,aAAa,WAAW,WAAW,aAAa;CACxD,MAAM,SAASC,sCAAAA,UAAU,SAAS,SAAS;CAE3C,OAAOC,sCAAAA,cAAc,SAAS,QAAQ;EACpC;EACA,YACEC,0CAAAA,0BAA0B,QAAQ,aAAa;GAC7C,mBAAmB;IAGjB,cAAc,aAAa,MAAM,OAAO,MAAM,WAAW;KACvD,QAAQ;KACR;IACF,CAAC;GACH;GAGA,iBAAiBC,sCAAAA,gBAAgB,WAAW,KAAK,WAAW,QAAQ;EACtE,CAAC;EACH,kBAAkBC,sCAAAA;EAClB;EACA,UAAU;CACZ,CAAC;AACH;;AAGA,eAAe,SACb,SACA,mBACe;CACf,MAAM,sBAAA,GAAqBC,YAAAA,gCAAAA,CAAgC,iBAAiB;CAE5E,MAAM,mBAAmB,MAAMC,kBAAAA,wBAC7B,QAAQ,SACP,eACC,WACG,oBAAoB,oBAAoB;EACvC,YAAY;EACZ,wBAAwB;EACxB,UAAU;CACZ,CAAC,CAAC,CACD,KAAK,CACZ;CAEA,IAAI,iBAAiB,MAAM,KAAK;EAC9B,MAAM,QAAQ,IAAIC,+BAAAA,8BAChB,iBAAiB,MAAM,KACvB,iBAAiB,MAAM,IACzB;EACA,MAAM,IAAIb,UAAAA,iBACRC,UAAAA,cAAc,6BACd,kCAAkC,MAAM,WACxC,KACF;CACF;AACF"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"resumeFromStore.js","names":["decodeStoredTransactions","TransactionError","LiFiErrorCode","lookupSignatureStatus","isConfirmedCommitment","recordLanded","failureOf","getTransactionLifetime","canResendStored","confirmationError","resolveUnconfirmed"],"sources":["../../../../src/core/tasks/resumeFromStore.ts"],"sourcesContent":["import {\n type ExecutionAction,\n LiFiErrorCode,\n type TaskResult,\n TransactionError,\n} from '@lifi/sdk'\nimport type { Signature } from '@solana/kit'\nimport { lookupSignatureStatus } from '../../actions/lookupSignatureStatus.js'\nimport { isConfirmedCommitment } from '../../confirmation/types.js'\nimport type { SolanaStepExecutorContext } from '../../types.js'\nimport {\n getTransactionLifetime,\n type TransactionLifetime,\n} from '../../utils/getTransactionLifetime.js'\nimport {\n decodeStoredTransactions,\n type StoredTransactions,\n} from '../../utils/storedTransactions.js'\nimport {\n confirmationError,\n type ConfirmationMessages,\n} from './confirmationError.js'\nimport {\n canResendStored,\n clearStoredTransactions,\n failureOf,\n recordLanded,\n resolveUnconfirmed,\n} from './transactionOutcome.js'\n\n/** What a resumed wait task can work from. */\ntype ResumeSource =\n /** Signed bytes that may still need to be sent. */\n | { kind: 'bytes'; stored: StoredTransactions }\n /** A broadcast signature alone: a route stored before the upgrade, or\n * bytes that no longer decode. */\n | { kind: 'hash'; signature: Signature }\n /** Bytes whose first signature is not the stored txHash (damaged\n * storage). They prove nothing about that transaction, and they may have\n * been sent: nothing is sent and nothing is dropped. */\n | { kind: 'mismatch'; signature: Signature }\n\nfunction readResumeSource(\n context: SolanaStepExecutorContext,\n action: ExecutionAction\n): ResumeSource {\n if (action.txHex) {\n const stored = decodeStoredTransactions(action.txHex)\n if (stored) {\n if (action.txHash && action.txHash !== stored.signature) {\n return { kind: 'mismatch', signature: action.txHash as Signature }\n }\n return { kind: 'bytes', stored }\n }\n // The sign task stores only bytes that decode, so these were damaged\n // after the write - by the integrator's storage, say. They would fail\n // every resume the same way.\n clearStoredTransactions(context, action)\n }\n\n if (action.txHash) {\n return { kind: 'hash', signature: action.txHash as Signature }\n }\n\n // Without a hash no RPC ever accepted a send - `txHash` is written on the\n // first accepted one - so nothing can land. No final marker: \"Try again\"\n // signs again.\n throw new TransactionError(\n LiFiErrorCode.TransactionUnprepared,\n 'Unable to prepare transaction. Signed transactions are not found.'\n )\n}\n\n/**\n * Resume mode of both wait tasks: the sign task did not run in this session,\n * so the transaction comes from the action.\n *\n * 1. Look the signature up on every RPC. A confirmed status goes straight to\n * the result rules: the transaction may have landed after the page closed.\n * This look only has to find, so it asks for no canary.\n * 2. Otherwise resend the stored bytes through `send` when that is allowed -\n * the task's normal send path, without simulation.\n * 3. Otherwise - a hash alone, or bytes past the resend age cap - nothing is\n * sent, and only the dropped rule can make the outcome final.\n *\n * Bytes that are not the stored txHash's transaction are never sent, and the\n * dropped rule never runs for them: the outcome stays unknown unless the\n * lookup by txHash finds it confirmed.\n */\nexport async function resumeFromStore(\n context: SolanaStepExecutorContext,\n action: ExecutionAction,\n options: {\n messages: ConfirmationMessages\n /** Sends the stored bytes and applies the result rules, as the first\n * run does, but never simulates: a transaction that already landed, or\n * funds it already spent, would fail the simulation falsely. */\n send: (\n stored: StoredTransactions,\n lifetimes: TransactionLifetime[]\n ) => Promise<TaskResult>\n }\n): Promise<TaskResult> {\n const { client, step } = context\n const source = readResumeSource(context, action)\n const signature =\n source.kind === 'bytes' ? source.stored.signature : source.signature\n\n const lookup = await lookupSignatureStatus(client, signature)\n if (\n lookup.kind === 'found' &&\n isConfirmedCommitment(lookup.status.confirmationStatus)\n ) {\n return recordLanded(context, action, {\n signature,\n failure: failureOf(lookup.status),\n })\n }\n\n const lifetimes =\n source.kind === 'bytes'\n ? await Promise.all(\n source.stored.transactions.map((transaction) =>\n getTransactionLifetime(transaction)\n )\n )\n : []\n\n // A `processed` status resends too: a signature executes at most once.\n if (\n source.kind === 'bytes' &&\n canResendStored(lifetimes, step.execution?.signedAt)\n ) {\n return options.send(source.stored, lifetimes)\n }\n\n // No RPC answered at all: an outage, as today. Otherwise the transaction\n // was simply not seen.\n const silent = lookup.kind === 'unknown' && !lookup.answered\n const error = confirmationError(\n silent\n ? { kind: 'rpc-unavailable', errors: lookup.errors }\n : { kind: 'not-confirmed', errors: [] },\n options.messages\n )\n if (source.kind === 'mismatch') {\n // Damaged storage: no dropped rule, so the outcome stays unknown.\n throw error\n }\n const status = await resolveUnconfirmed(context, action, {\n signature,\n error,\n expiredAtSlot: undefined,\n messages: options.messages,\n })\n return recordLanded(context, action, {\n signature,\n failure: failureOf(status),\n })\n}\n"],"mappings":";;;;;;;;;AA0CA,SAAS,iBACP,SACA,QACc;CACd,IAAI,OAAO,OAAO;EAChB,MAAM,SAASA,iCAAAA,yBAAyB,OAAO,KAAK;EACpD,IAAI,QAAQ;GACV,IAAI,OAAO,UAAU,OAAO,WAAW,OAAO,WAC5C,OAAO;IAAE,MAAM;IAAY,WAAW,OAAO;GAAoB;GAEnE,OAAO;IAAE,MAAM;IAAS;GAAO;EACjC;
|
|
1
|
+
{"version":3,"file":"resumeFromStore.js","names":["decodeStoredTransactions","clearStoredTransactions","TransactionError","LiFiErrorCode","lookupSignatureStatus","isConfirmedCommitment","recordLanded","failureOf","getTransactionLifetime","canResendStored","confirmationError","resolveUnconfirmed"],"sources":["../../../../src/core/tasks/resumeFromStore.ts"],"sourcesContent":["import {\n type ExecutionAction,\n LiFiErrorCode,\n type TaskResult,\n TransactionError,\n} from '@lifi/sdk'\nimport type { Signature } from '@solana/kit'\nimport { lookupSignatureStatus } from '../../actions/lookupSignatureStatus.js'\nimport { isConfirmedCommitment } from '../../confirmation/types.js'\nimport type { SolanaStepExecutorContext } from '../../types.js'\nimport {\n getTransactionLifetime,\n type TransactionLifetime,\n} from '../../utils/getTransactionLifetime.js'\nimport {\n decodeStoredTransactions,\n type StoredTransactions,\n} from '../../utils/storedTransactions.js'\nimport {\n confirmationError,\n type ConfirmationMessages,\n} from './confirmationError.js'\nimport {\n canResendStored,\n clearStoredTransactions,\n failureOf,\n recordLanded,\n resolveUnconfirmed,\n} from './transactionOutcome.js'\n\n/** What a resumed wait task can work from. */\ntype ResumeSource =\n /** Signed bytes that may still need to be sent. */\n | { kind: 'bytes'; stored: StoredTransactions }\n /** A broadcast signature alone: a route stored before the upgrade, or\n * bytes that no longer decode. */\n | { kind: 'hash'; signature: Signature }\n /** Bytes whose first signature is not the stored txHash (damaged\n * storage). They prove nothing about that transaction, and they may have\n * been sent: nothing is sent and nothing is dropped. */\n | { kind: 'mismatch'; signature: Signature }\n\nfunction readResumeSource(\n context: SolanaStepExecutorContext,\n action: ExecutionAction\n): ResumeSource {\n if (action.txHex) {\n const stored = decodeStoredTransactions(action.txHex)\n if (stored) {\n if (action.txHash && action.txHash !== stored.signature) {\n return { kind: 'mismatch', signature: action.txHash as Signature }\n }\n return { kind: 'bytes', stored }\n }\n // The sign task stores only bytes that decode, so these were damaged\n // after the write - by the integrator's storage, say. They would fail\n // every resume the same way.\n clearStoredTransactions(context, action)\n }\n\n if (action.txHash) {\n return { kind: 'hash', signature: action.txHash as Signature }\n }\n\n // Without a hash no RPC ever accepted a send - `txHash` is written on the\n // first accepted one - so nothing can land. No final marker: \"Try again\"\n // signs again.\n throw new TransactionError(\n LiFiErrorCode.TransactionUnprepared,\n 'Unable to prepare transaction. Signed transactions are not found.'\n )\n}\n\n/**\n * Resume mode of both wait tasks: the sign task did not run in this session,\n * so the transaction comes from the action.\n *\n * 1. Look the signature up on every RPC. A confirmed status goes straight to\n * the result rules: the transaction may have landed after the page closed.\n * This look only has to find, so it asks for no canary.\n * 2. Otherwise resend the stored bytes through `send` when that is allowed -\n * the task's normal send path, without simulation.\n * 3. Otherwise - a hash alone, or bytes past the resend age cap - nothing is\n * sent, and only the dropped rule can make the outcome final.\n *\n * Bytes that are not the stored txHash's transaction are never sent, and the\n * dropped rule never runs for them: the outcome stays unknown unless the\n * lookup by txHash finds it confirmed.\n */\nexport async function resumeFromStore(\n context: SolanaStepExecutorContext,\n action: ExecutionAction,\n options: {\n messages: ConfirmationMessages\n /** Sends the stored bytes and applies the result rules, as the first\n * run does, but never simulates: a transaction that already landed, or\n * funds it already spent, would fail the simulation falsely. */\n send: (\n stored: StoredTransactions,\n lifetimes: TransactionLifetime[]\n ) => Promise<TaskResult>\n }\n): Promise<TaskResult> {\n const { client, step } = context\n const source = readResumeSource(context, action)\n const signature =\n source.kind === 'bytes' ? source.stored.signature : source.signature\n\n const lookup = await lookupSignatureStatus(client, signature)\n if (\n lookup.kind === 'found' &&\n isConfirmedCommitment(lookup.status.confirmationStatus)\n ) {\n return recordLanded(context, action, {\n signature,\n failure: failureOf(lookup.status),\n })\n }\n\n const lifetimes =\n source.kind === 'bytes'\n ? await Promise.all(\n source.stored.transactions.map((transaction) =>\n getTransactionLifetime(transaction)\n )\n )\n : []\n\n // A `processed` status resends too: a signature executes at most once.\n if (\n source.kind === 'bytes' &&\n canResendStored(lifetimes, step.execution?.signedAt)\n ) {\n return options.send(source.stored, lifetimes)\n }\n\n // No RPC answered at all: an outage, as today. Otherwise the transaction\n // was simply not seen.\n const silent = lookup.kind === 'unknown' && !lookup.answered\n const error = confirmationError(\n silent\n ? { kind: 'rpc-unavailable', errors: lookup.errors }\n : { kind: 'not-confirmed', errors: [] },\n options.messages\n )\n if (source.kind === 'mismatch') {\n // Damaged storage: no dropped rule, so the outcome stays unknown.\n throw error\n }\n const status = await resolveUnconfirmed(context, action, {\n signature,\n error,\n expiredAtSlot: undefined,\n messages: options.messages,\n })\n return recordLanded(context, action, {\n signature,\n failure: failureOf(status),\n })\n}\n"],"mappings":";;;;;;;;;AA0CA,SAAS,iBACP,SACA,QACc;CACd,IAAI,OAAO,OAAO;EAChB,MAAM,SAASA,iCAAAA,yBAAyB,OAAO,KAAK;EACpD,IAAI,QAAQ;GACV,IAAI,OAAO,UAAU,OAAO,WAAW,OAAO,WAC5C,OAAO;IAAE,MAAM;IAAY,WAAW,OAAO;GAAoB;GAEnE,OAAO;IAAE,MAAM;IAAS;GAAO;EACjC;EAIAC,sCAAAA,wBAAwB,SAAS,MAAM;CACzC;CAEA,IAAI,OAAO,QACT,OAAO;EAAE,MAAM;EAAQ,WAAW,OAAO;CAAoB;CAM/D,MAAM,IAAIC,UAAAA,iBACRC,UAAAA,cAAc,uBACd,mEACF;AACF;;;;;;;;;;;;;;;;;AAkBA,eAAsB,gBACpB,SACA,QACA,SAUqB;CACrB,MAAM,EAAE,QAAQ,SAAS;CACzB,MAAM,SAAS,iBAAiB,SAAS,MAAM;CAC/C,MAAM,YACJ,OAAO,SAAS,UAAU,OAAO,OAAO,YAAY,OAAO;CAE7D,MAAM,SAAS,MAAMC,sCAAAA,sBAAsB,QAAQ,SAAS;CAC5D,IACE,OAAO,SAAS,WAChBC,2BAAAA,sBAAsB,OAAO,OAAO,kBAAkB,GAEtD,OAAOC,sCAAAA,aAAa,SAAS,QAAQ;EACnC;EACA,SAASC,sCAAAA,UAAU,OAAO,MAAM;CAClC,CAAC;CAGH,MAAM,YACJ,OAAO,SAAS,UACZ,MAAM,QAAQ,IACZ,OAAO,OAAO,aAAa,KAAK,gBAC9BC,qCAAAA,uBAAuB,WAAW,CACpC,CACF,IACA,CAAC;CAGP,IACE,OAAO,SAAS,WAChBC,sCAAAA,gBAAgB,WAAW,KAAK,WAAW,QAAQ,GAEnD,OAAO,QAAQ,KAAK,OAAO,QAAQ,SAAS;CAK9C,MAAM,SAAS,OAAO,SAAS,aAAa,CAAC,OAAO;CACpD,MAAM,QAAQC,qCAAAA,kBACZ,SACI;EAAE,MAAM;EAAmB,QAAQ,OAAO;CAAO,IACjD;EAAE,MAAM;EAAiB,QAAQ,CAAC;CAAE,GACxC,QAAQ,QACV;CACA,IAAI,OAAO,SAAS,YAElB,MAAM;CAER,MAAM,SAAS,MAAMC,sCAAAA,mBAAmB,SAAS,QAAQ;EACvD;EACA;EACA,eAAe,KAAA;EACf,UAAU,QAAQ;CACpB,CAAC;CACD,OAAOL,sCAAAA,aAAa,SAAS,QAAQ;EACnC;EACA,SAASC,sCAAAA,UAAU,MAAM;CAC3B,CAAC;AACH"}
|
|
@@ -11,13 +11,16 @@ const parseSolanaErrors = async (e, step, action) => {
|
|
|
11
11
|
return new _lifi_sdk.SDKError(baseError, step, action);
|
|
12
12
|
};
|
|
13
13
|
const userRejectionMessage = /(^|\W)user\W+(has\W+)?(rejected|denied|cancell?ed)|\b(rejected|denied|cancell?ed)\W+by\W+(the\W+)?user\b/i;
|
|
14
|
+
const walletCancelMessage = /^transaction (was )?cancell?ed\.?$/i;
|
|
14
15
|
/**
|
|
15
16
|
* The SDK calls the Wallet Standard features directly, so a wallet's own error
|
|
16
17
|
* arrives here unwrapped. Wallets report a rejection with the EIP-1193 code
|
|
17
|
-
* 4001 or only with a message.
|
|
18
|
-
*
|
|
18
|
+
* 4001 or only with a message. A wallet cancel is a rejection too: the prompt
|
|
19
|
+
* was open and the wallet sent nothing, as with `WalletSignTransactionError`.
|
|
20
|
+
* An `AbortError` is not a rejection: nothing says the user caused it. The
|
|
21
|
+
* SDK's own errors keep their code.
|
|
19
22
|
*/
|
|
20
|
-
const isUserRejection = (e) => !(e instanceof _lifi_sdk.BaseError) && (e.code === 4001 || typeof e.message === "string" && userRejectionMessage.test(e.message));
|
|
23
|
+
const isUserRejection = (e) => !(e instanceof _lifi_sdk.BaseError) && (e.code === 4001 || typeof e.message === "string" && (userRejectionMessage.test(e.message) || walletCancelMessage.test(e.message.trim())));
|
|
21
24
|
const handleSpecificErrors = (e) => {
|
|
22
25
|
if (e.name === "WalletSignTransactionError") return new _lifi_sdk.TransactionError(_lifi_sdk.LiFiErrorCode.SignatureRejected, e.message, e);
|
|
23
26
|
if (e.name === "SendTransactionError") return new _lifi_sdk.TransactionError(_lifi_sdk.LiFiErrorCode.TransactionFailed, e.message, e);
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"parseSolanaErrors.js","names":["SDKError","BaseError","TransactionError","LiFiErrorCode","UnknownError","ErrorMessage"],"sources":["../../../src/errors/parseSolanaErrors.ts"],"sourcesContent":["import {\n BaseError,\n ErrorMessage,\n type ExecutionAction,\n LiFiErrorCode,\n type LiFiStep,\n SDKError,\n TransactionError,\n UnknownError,\n} from '@lifi/sdk'\n\nexport const parseSolanaErrors = async (\n e: Error,\n step?: LiFiStep,\n action?: ExecutionAction\n): Promise<SDKError> => {\n if (e instanceof SDKError) {\n e.step = e.step ?? step\n e.action = e.action ?? action\n return e\n }\n\n const baseError = handleSpecificErrors(e)\n\n return new SDKError(baseError, step, action)\n}\n\n// Same pattern as bigmi's `isUserRejection`. It is anchored on \"user\", so a\n// refusal by a node or a host does not count as a rejection.\nconst userRejectionMessage =\n /(^|\\W)user\\W+(has\\W+)?(rejected|denied|cancell?ed)|\\b(rejected|denied|cancell?ed)\\W+by\\W+(the\\W+)?user\\b/i\n\n/**\n * The SDK calls the Wallet Standard features directly, so a wallet's own error\n * arrives here unwrapped. Wallets report a rejection with the EIP-1193 code\n * 4001 or only with a message. An `AbortError` is not a rejection: nothing
|
|
1
|
+
{"version":3,"file":"parseSolanaErrors.js","names":["SDKError","BaseError","TransactionError","LiFiErrorCode","UnknownError","ErrorMessage"],"sources":["../../../src/errors/parseSolanaErrors.ts"],"sourcesContent":["import {\n BaseError,\n ErrorMessage,\n type ExecutionAction,\n LiFiErrorCode,\n type LiFiStep,\n SDKError,\n TransactionError,\n UnknownError,\n} from '@lifi/sdk'\n\nexport const parseSolanaErrors = async (\n e: Error,\n step?: LiFiStep,\n action?: ExecutionAction\n): Promise<SDKError> => {\n if (e instanceof SDKError) {\n e.step = e.step ?? step\n e.action = e.action ?? action\n return e\n }\n\n const baseError = handleSpecificErrors(e)\n\n return new SDKError(baseError, step, action)\n}\n\n// Same pattern as bigmi's `isUserRejection`. It is anchored on \"user\", so a\n// refusal by a node or a host does not count as a rejection.\nconst userRejectionMessage =\n /(^|\\W)user\\W+(has\\W+)?(rejected|denied|cancell?ed)|\\b(rejected|denied|cancell?ed)\\W+by\\W+(the\\W+)?user\\b/i\n\n// Some wallets report a Cancel on the sign prompt only with this text (an\n// Android in-app wallet). The whole message must match, so a longer error that\n// starts with these words does not count.\nconst walletCancelMessage = /^transaction (was )?cancell?ed\\.?$/i\n\n/**\n * The SDK calls the Wallet Standard features directly, so a wallet's own error\n * arrives here unwrapped. Wallets report a rejection with the EIP-1193 code\n * 4001 or only with a message. A wallet cancel is a rejection too: the prompt\n * was open and the wallet sent nothing, as with `WalletSignTransactionError`.\n * An `AbortError` is not a rejection: nothing says the user caused it. The\n * SDK's own errors keep their code.\n */\nconst isUserRejection = (e: any): boolean =>\n !(e instanceof BaseError) &&\n (e.code === 4001 ||\n (typeof e.message === 'string' &&\n (userRejectionMessage.test(e.message) ||\n walletCancelMessage.test(e.message.trim()))))\n\nconst handleSpecificErrors = (e: any) => {\n if (e.name === 'WalletSignTransactionError') {\n return new TransactionError(LiFiErrorCode.SignatureRejected, e.message, e)\n }\n\n if (e.name === 'SendTransactionError') {\n return new TransactionError(LiFiErrorCode.TransactionFailed, e.message, e)\n }\n\n if (e.name === 'TransactionExpiredBlockheightExceededError') {\n return new TransactionError(LiFiErrorCode.TransactionExpired, e.message, e)\n }\n\n // After the name checks: a known error keeps its code, even when its\n // message quotes program logs that look like a rejection.\n if (isUserRejection(e)) {\n return new TransactionError(LiFiErrorCode.SignatureRejected, e.message, e)\n }\n\n if (e.message?.includes('simulate')) {\n return new TransactionError(\n LiFiErrorCode.TransactionSimulationFailed,\n e.message,\n e\n )\n }\n\n if (e instanceof BaseError) {\n return e\n }\n\n return new UnknownError(e.message || ErrorMessage.UnknownError, e)\n}\n"],"mappings":";;;AAWA,MAAa,oBAAoB,OAC/B,GACA,MACA,WACsB;CACtB,IAAI,aAAaA,UAAAA,UAAU;EACzB,EAAE,OAAO,EAAE,QAAQ;EACnB,EAAE,SAAS,EAAE,UAAU;EACvB,OAAO;CACT;CAEA,MAAM,YAAY,qBAAqB,CAAC;CAExC,OAAO,IAAIA,UAAAA,SAAS,WAAW,MAAM,MAAM;AAC7C;AAIA,MAAM,uBACJ;AAKF,MAAM,sBAAsB;;;;;;;;;AAU5B,MAAM,mBAAmB,MACvB,EAAE,aAAaC,UAAAA,eACd,EAAE,SAAS,QACT,OAAO,EAAE,YAAY,aACnB,qBAAqB,KAAK,EAAE,OAAO,KAClC,oBAAoB,KAAK,EAAE,QAAQ,KAAK,CAAC;AAEjD,MAAM,wBAAwB,MAAW;CACvC,IAAI,EAAE,SAAS,8BACb,OAAO,IAAIC,UAAAA,iBAAiBC,UAAAA,cAAc,mBAAmB,EAAE,SAAS,CAAC;CAG3E,IAAI,EAAE,SAAS,wBACb,OAAO,IAAID,UAAAA,iBAAiBC,UAAAA,cAAc,mBAAmB,EAAE,SAAS,CAAC;CAG3E,IAAI,EAAE,SAAS,8CACb,OAAO,IAAID,UAAAA,iBAAiBC,UAAAA,cAAc,oBAAoB,EAAE,SAAS,CAAC;CAK5E,IAAI,gBAAgB,CAAC,GACnB,OAAO,IAAID,UAAAA,iBAAiBC,UAAAA,cAAc,mBAAmB,EAAE,SAAS,CAAC;CAG3E,IAAI,EAAE,SAAS,SAAS,UAAU,GAChC,OAAO,IAAID,UAAAA,iBACTC,UAAAA,cAAc,6BACd,EAAE,SACF,CACF;CAGF,IAAI,aAAaF,UAAAA,WACf,OAAO;CAGT,OAAO,IAAIG,UAAAA,aAAa,EAAE,WAAWC,UAAAA,aAAa,cAAc,CAAC;AACnE"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"KeypairWalletAdapter.js","names":["getBase58Codec","SolanaSignTransaction","createKeyPairSignerFromBytes","getTransactionCodec","getBase64EncodedWireTransaction","base64ToUint8Array"],"sources":["../../../src/utils/KeypairWalletAdapter.ts"],"sourcesContent":["import {\n assertIsTransactionWithinSizeLimit,\n createKeyPairSignerFromBytes,\n getBase58Codec,\n getBase64EncodedWireTransaction,\n getTransactionCodec,\n type KeyPairSigner,\n type ReadonlyUint8Array,\n} from '@solana/kit'\nimport {\n SolanaSignTransaction,\n type SolanaSignTransactionFeature,\n type SolanaSignTransactionInput,\n type SolanaSignTransactionOutput,\n} from '@solana/wallet-standard-features'\nimport type { Wallet, WalletAccount } from '@wallet-standard/base'\nimport { base64ToUint8Array } from './base64ToUint8Array.js'\n\n/**\n * This keypair wallet adapter is unsafe to use on the frontend and is only included to provide an easy way for applications to test\n * Wallet Adapter without using a third-party wallet.\n */\nexport class KeypairWalletAdapter implements Wallet {\n /**\n * Storing a keypair locally like this is not safe because any application using this adapter could retrieve the\n * secret key, and because the keypair will be lost any time the wallet is disconnected or the window is refreshed.\n */\n private _signer: KeyPairSigner | undefined\n private _account: WalletAccount | undefined\n private readonly _secretKeyBytes: ReadonlyUint8Array\n\n readonly version = '1.0.0' as const\n readonly name = 'Keypair Wallet' as const\n readonly icon =\n 'data:image/svg+xml;base64,PHN2ZyB3aWR0aD0iMzIiIGhlaWdodD0iMzIiIHZpZXdCb3g9IjAgMCAzMiAzMiIgZmlsbD0ibm9uZSIgeG1sbnM9Imh0dHA6Ly93d3cudzMub3JnLzIwMDAvc3ZnIj48L3N2Zz4=' as const\n\n constructor(secretKeyBase58: string) {\n if (!secretKeyBase58) {\n throw new Error('Private key is required')\n }\n\n const base58Codec = getBase58Codec()\n let encoded: ReadonlyUint8Array\n try {\n encoded = base58Codec.encode(secretKeyBase58)\n } catch {\n throw new Error('Invalid private key format')\n }\n\n if (encoded.length !== 64) {\n throw new Error('Invalid private key length. Expected 64 bytes.')\n }\n\n this._secretKeyBytes = encoded\n }\n\n // Wallet Standard interface properties\n get chains() {\n return ['solana:mainnet', 'solana:devnet', 'solana:testnet'] as const\n }\n\n get accounts(): readonly WalletAccount[] {\n return this._account ? [this._account] : []\n }\n\n get features(): SolanaSignTransactionFeature {\n return {\n [SolanaSignTransaction]: {\n version: '1.0.0' as const,\n supportedTransactionVersions: ['legacy', 0] as const,\n signTransaction: this._signTransactionFeature.bind(this),\n },\n }\n }\n\n async connect(): Promise<void> {\n this._signer = await createKeyPairSignerFromBytes(this._secretKeyBytes)\n\n const publicKeyBytes = new Uint8Array(\n await crypto.subtle.exportKey('raw', this._signer.keyPair.publicKey)\n )\n\n this._account = {\n address: this._signer.address,\n publicKey: publicKeyBytes,\n chains: this.chains,\n features: [SolanaSignTransaction],\n }\n }\n\n async disconnect(): Promise<void> {\n this._signer = undefined\n this._account = undefined\n }\n\n // Wallet Standard feature implementations\n private async _signTransactionFeature(\n ...inputs: readonly SolanaSignTransactionInput[]\n ): Promise<readonly SolanaSignTransactionOutput[]> {\n if (!this._signer) {\n throw new Error('Wallet is not connected')\n }\n\n const results: SolanaSignTransactionOutput[] = []\n\n for (const input of inputs) {\n const transaction = getTransactionCodec().decode(input.transaction)\n\n assertIsTransactionWithinSizeLimit(transaction)\n\n // `assertIsTransactionWithBlockhashLifetime` is deliberately NOT called\n // here. It tests `'lifetimeConstraint' in transaction`, and no kit\n // decoder reconstructs that property - decoding wire bytes yields\n // `{ messageBytes, signatures }` alone, so the assert rejected every\n // transaction a wallet is ever handed. Signing does not need it either:\n // `partiallySignTransaction` signs `messageBytes` and never reads the\n // lifetime. The blockhash still travels inside `messageBytes`, where\n // `getTransactionLifetime` reads it for the confirmation deadline.\n // Cast because `signTransactions` types its argument as carrying a\n // lifetime, while the runtime path - `partiallySignTransaction` - reads\n // only `messageBytes`. A decoded transaction never has the property, so\n // without this the type demands something no decoder can produce.\n const [signatureDictionary] = await this._signer.signTransactions([\n transaction as Parameters<\n typeof this._signer.signTransactions\n >[0][number],\n ])\n\n const signature = signatureDictionary?.[this._signer.address]\n if (!signature) {\n throw new Error('Failed to sign transaction')\n }\n\n // The signature has to be merged back in. `partiallySignTransaction`\n // returns a new frozen object rather than mutating its argument, so\n // encoding `transaction` here shipped the unsigned original and threw\n // the signature away - the transaction then failed on chain for a\n // missing signature, far from the code that dropped it.\n //\n // The cast mirrors the one above: the wire format is `messageBytes`\n // plus `signatures`, and the encoder reads nothing else - the lifetime\n // already travels inside `messageBytes`.\n const signedTransaction = getBase64EncodedWireTransaction({\n ...transaction,\n signatures: {\n ...transaction.signatures,\n [this._signer.address]: signature,\n },\n } as Parameters<typeof getBase64EncodedWireTransaction>[0])\n\n results.push({\n signedTransaction: base64ToUint8Array(signedTransaction),\n })\n }\n\n return results\n }\n}\n"],"mappings":";;;;;;;;;AAsBA,IAAa,uBAAb,MAAoD;;;;;
|
|
1
|
+
{"version":3,"file":"KeypairWalletAdapter.js","names":["getBase58Codec","SolanaSignTransaction","createKeyPairSignerFromBytes","getTransactionCodec","assertIsTransactionWithinSizeLimit","getBase64EncodedWireTransaction","base64ToUint8Array"],"sources":["../../../src/utils/KeypairWalletAdapter.ts"],"sourcesContent":["import {\n assertIsTransactionWithinSizeLimit,\n createKeyPairSignerFromBytes,\n getBase58Codec,\n getBase64EncodedWireTransaction,\n getTransactionCodec,\n type KeyPairSigner,\n type ReadonlyUint8Array,\n} from '@solana/kit'\nimport {\n SolanaSignTransaction,\n type SolanaSignTransactionFeature,\n type SolanaSignTransactionInput,\n type SolanaSignTransactionOutput,\n} from '@solana/wallet-standard-features'\nimport type { Wallet, WalletAccount } from '@wallet-standard/base'\nimport { base64ToUint8Array } from './base64ToUint8Array.js'\n\n/**\n * This keypair wallet adapter is unsafe to use on the frontend and is only included to provide an easy way for applications to test\n * Wallet Adapter without using a third-party wallet.\n */\nexport class KeypairWalletAdapter implements Wallet {\n /**\n * Storing a keypair locally like this is not safe because any application using this adapter could retrieve the\n * secret key, and because the keypair will be lost any time the wallet is disconnected or the window is refreshed.\n */\n private _signer: KeyPairSigner | undefined\n private _account: WalletAccount | undefined\n private readonly _secretKeyBytes: ReadonlyUint8Array\n\n readonly version = '1.0.0' as const\n readonly name = 'Keypair Wallet' as const\n readonly icon =\n 'data:image/svg+xml;base64,PHN2ZyB3aWR0aD0iMzIiIGhlaWdodD0iMzIiIHZpZXdCb3g9IjAgMCAzMiAzMiIgZmlsbD0ibm9uZSIgeG1sbnM9Imh0dHA6Ly93d3cudzMub3JnLzIwMDAvc3ZnIj48L3N2Zz4=' as const\n\n constructor(secretKeyBase58: string) {\n if (!secretKeyBase58) {\n throw new Error('Private key is required')\n }\n\n const base58Codec = getBase58Codec()\n let encoded: ReadonlyUint8Array\n try {\n encoded = base58Codec.encode(secretKeyBase58)\n } catch {\n throw new Error('Invalid private key format')\n }\n\n if (encoded.length !== 64) {\n throw new Error('Invalid private key length. Expected 64 bytes.')\n }\n\n this._secretKeyBytes = encoded\n }\n\n // Wallet Standard interface properties\n get chains() {\n return ['solana:mainnet', 'solana:devnet', 'solana:testnet'] as const\n }\n\n get accounts(): readonly WalletAccount[] {\n return this._account ? [this._account] : []\n }\n\n get features(): SolanaSignTransactionFeature {\n return {\n [SolanaSignTransaction]: {\n version: '1.0.0' as const,\n supportedTransactionVersions: ['legacy', 0] as const,\n signTransaction: this._signTransactionFeature.bind(this),\n },\n }\n }\n\n async connect(): Promise<void> {\n this._signer = await createKeyPairSignerFromBytes(this._secretKeyBytes)\n\n const publicKeyBytes = new Uint8Array(\n await crypto.subtle.exportKey('raw', this._signer.keyPair.publicKey)\n )\n\n this._account = {\n address: this._signer.address,\n publicKey: publicKeyBytes,\n chains: this.chains,\n features: [SolanaSignTransaction],\n }\n }\n\n async disconnect(): Promise<void> {\n this._signer = undefined\n this._account = undefined\n }\n\n // Wallet Standard feature implementations\n private async _signTransactionFeature(\n ...inputs: readonly SolanaSignTransactionInput[]\n ): Promise<readonly SolanaSignTransactionOutput[]> {\n if (!this._signer) {\n throw new Error('Wallet is not connected')\n }\n\n const results: SolanaSignTransactionOutput[] = []\n\n for (const input of inputs) {\n const transaction = getTransactionCodec().decode(input.transaction)\n\n assertIsTransactionWithinSizeLimit(transaction)\n\n // `assertIsTransactionWithBlockhashLifetime` is deliberately NOT called\n // here. It tests `'lifetimeConstraint' in transaction`, and no kit\n // decoder reconstructs that property - decoding wire bytes yields\n // `{ messageBytes, signatures }` alone, so the assert rejected every\n // transaction a wallet is ever handed. Signing does not need it either:\n // `partiallySignTransaction` signs `messageBytes` and never reads the\n // lifetime. The blockhash still travels inside `messageBytes`, where\n // `getTransactionLifetime` reads it for the confirmation deadline.\n // Cast because `signTransactions` types its argument as carrying a\n // lifetime, while the runtime path - `partiallySignTransaction` - reads\n // only `messageBytes`. A decoded transaction never has the property, so\n // without this the type demands something no decoder can produce.\n const [signatureDictionary] = await this._signer.signTransactions([\n transaction as Parameters<\n typeof this._signer.signTransactions\n >[0][number],\n ])\n\n const signature = signatureDictionary?.[this._signer.address]\n if (!signature) {\n throw new Error('Failed to sign transaction')\n }\n\n // The signature has to be merged back in. `partiallySignTransaction`\n // returns a new frozen object rather than mutating its argument, so\n // encoding `transaction` here shipped the unsigned original and threw\n // the signature away - the transaction then failed on chain for a\n // missing signature, far from the code that dropped it.\n //\n // The cast mirrors the one above: the wire format is `messageBytes`\n // plus `signatures`, and the encoder reads nothing else - the lifetime\n // already travels inside `messageBytes`.\n const signedTransaction = getBase64EncodedWireTransaction({\n ...transaction,\n signatures: {\n ...transaction.signatures,\n [this._signer.address]: signature,\n },\n } as Parameters<typeof getBase64EncodedWireTransaction>[0])\n\n results.push({\n signedTransaction: base64ToUint8Array(signedTransaction),\n })\n }\n\n return results\n }\n}\n"],"mappings":";;;;;;;;;AAsBA,IAAa,uBAAb,MAAoD;;;;;CAK1C;CACA;CACS;CAER,UAAU;CACV,OAAO;CACP,OACP;CAEF,YAAY,iBAAyB;EACnC,IAAI,CAAC,iBACH,MAAM,IAAI,MAAM,yBAAyB;EAG3C,MAAM,eAAA,GAAcA,YAAAA,eAAAA,CAAe;EACnC,IAAI;EACJ,IAAI;GACF,UAAU,YAAY,OAAO,eAAe;EAC9C,QAAQ;GACN,MAAM,IAAI,MAAM,4BAA4B;EAC9C;EAEA,IAAI,QAAQ,WAAW,IACrB,MAAM,IAAI,MAAM,gDAAgD;EAGlE,KAAK,kBAAkB;CACzB;CAGA,IAAI,SAAS;EACX,OAAO;GAAC;GAAkB;GAAiB;EAAgB;CAC7D;CAEA,IAAI,WAAqC;EACvC,OAAO,KAAK,WAAW,CAAC,KAAK,QAAQ,IAAI,CAAC;CAC5C;CAEA,IAAI,WAAyC;EAC3C,OAAO,GACJC,iCAAAA,wBAAwB;GACvB,SAAS;GACT,8BAA8B,CAAC,UAAU,CAAC;GAC1C,iBAAiB,KAAK,wBAAwB,KAAK,IAAI;EACzD,EACF;CACF;CAEA,MAAM,UAAyB;EAC7B,KAAK,UAAU,OAAA,GAAMC,YAAAA,6BAAAA,CAA6B,KAAK,eAAe;EAEtE,MAAM,iBAAiB,IAAI,WACzB,MAAM,OAAO,OAAO,UAAU,OAAO,KAAK,QAAQ,QAAQ,SAAS,CACrE;EAEA,KAAK,WAAW;GACd,SAAS,KAAK,QAAQ;GACtB,WAAW;GACX,QAAQ,KAAK;GACb,UAAU,CAACD,iCAAAA,qBAAqB;EAClC;CACF;CAEA,MAAM,aAA4B;EAChC,KAAK,UAAU,KAAA;EACf,KAAK,WAAW,KAAA;CAClB;CAGA,MAAc,wBACZ,GAAG,QAC8C;EACjD,IAAI,CAAC,KAAK,SACR,MAAM,IAAI,MAAM,yBAAyB;EAG3C,MAAM,UAAyC,CAAC;EAEhD,KAAK,MAAM,SAAS,QAAQ;GAC1B,MAAM,eAAA,GAAcE,YAAAA,oBAAAA,CAAoB,CAAC,CAAC,OAAO,MAAM,WAAW;GAElEC,CAAAA,GAAAA,YAAAA,mCAAAA,CAAmC,WAAW;GAc9C,MAAM,CAAC,uBAAuB,MAAM,KAAK,QAAQ,iBAAiB,CAChE,WAGF,CAAC;GAED,MAAM,YAAY,sBAAsB,KAAK,QAAQ;GACrD,IAAI,CAAC,WACH,MAAM,IAAI,MAAM,4BAA4B;GAY9C,MAAM,qBAAA,GAAoBC,YAAAA,gCAAAA,CAAgC;IACxD,GAAG;IACH,YAAY;KACV,GAAG,YAAY;MACd,KAAK,QAAQ,UAAU;IAC1B;GACF,CAA0D;GAE1D,QAAQ,KAAK,EACX,mBAAmBC,iCAAAA,mBAAmB,iBAAiB,EACzD,CAAC;EACH;EAEA,OAAO;CACT;AACF"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"solanaErrorCause.js","names":[],"sources":["../../../src/utils/solanaErrorCause.ts"],"sourcesContent":["export const safeStringifyBigInt = (value: unknown): string =>\n JSON.stringify(value, (_, v) => (typeof v === 'bigint' ? v.toString() : v))\n\nconst formatSolanaErr = (err: unknown): string =>\n typeof err === 'object' && err !== null\n ? safeStringifyBigInt(err)\n : String(err)\n\n/**\n * Carries the structured payload of a failed Solana RPC simulation or\n * confirmation so consumers can inspect `err` and `logs` directly from\n * the thrown `TransactionError`'s `cause`, without re-simulating.\n */\nexport class SolanaTransactionDetailsError extends Error {\n readonly err: unknown\n readonly logs: readonly string[] | null\n\n constructor(err: unknown, logs: readonly string[] | null = null) {\n super(formatSolanaErr(err))\n this.name = 'SolanaTransactionDetailsError'\n this.err = err\n this.logs = logs\n }\n}\n"],"mappings":";;AAAA,MAAa,uBAAuB,UAClC,KAAK,UAAU,QAAQ,GAAG,MAAO,OAAO,MAAM,WAAW,EAAE,SAAS,IAAI,CAAE;AAE5E,MAAM,mBAAmB,QACvB,OAAO,QAAQ,YAAY,QAAQ,OAC/B,oBAAoB,GAAG,IACvB,OAAO,GAAG;;;;;;AAOhB,IAAa,gCAAb,cAAmD,MAAM;
|
|
1
|
+
{"version":3,"file":"solanaErrorCause.js","names":[],"sources":["../../../src/utils/solanaErrorCause.ts"],"sourcesContent":["export const safeStringifyBigInt = (value: unknown): string =>\n JSON.stringify(value, (_, v) => (typeof v === 'bigint' ? v.toString() : v))\n\nconst formatSolanaErr = (err: unknown): string =>\n typeof err === 'object' && err !== null\n ? safeStringifyBigInt(err)\n : String(err)\n\n/**\n * Carries the structured payload of a failed Solana RPC simulation or\n * confirmation so consumers can inspect `err` and `logs` directly from\n * the thrown `TransactionError`'s `cause`, without re-simulating.\n */\nexport class SolanaTransactionDetailsError extends Error {\n readonly err: unknown\n readonly logs: readonly string[] | null\n\n constructor(err: unknown, logs: readonly string[] | null = null) {\n super(formatSolanaErr(err))\n this.name = 'SolanaTransactionDetailsError'\n this.err = err\n this.logs = logs\n }\n}\n"],"mappings":";;AAAA,MAAa,uBAAuB,UAClC,KAAK,UAAU,QAAQ,GAAG,MAAO,OAAO,MAAM,WAAW,EAAE,SAAS,IAAI,CAAE;AAE5E,MAAM,mBAAmB,QACvB,OAAO,QAAQ,YAAY,QAAQ,OAC/B,oBAAoB,GAAG,IACvB,OAAO,GAAG;;;;;;AAOhB,IAAa,gCAAb,cAAmD,MAAM;CAC9C;CACA;CAET,YAAY,KAAc,OAAiC,MAAM;EAC/D,MAAM,gBAAgB,GAAG,CAAC;EAC1B,KAAK,OAAO;EACZ,KAAK,MAAM;EACX,KAAK,OAAO;CACd;AACF"}
|
package/dist/cjs/version.d.ts
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
1
|
export declare const name = "@lifi/sdk-provider-solana";
|
|
2
|
-
export declare const version = "0.0.0-preview-
|
|
2
|
+
export declare const version = "0.0.0-preview-155bb7fe";
|
package/dist/cjs/version.js
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
|
|
2
2
|
// src/version.ts
|
|
3
3
|
const name = "@lifi/sdk-provider-solana";
|
|
4
|
-
const version = "0.0.0-preview-
|
|
4
|
+
const version = "0.0.0-preview-155bb7fe";
|
|
5
5
|
exports.name = name;
|
|
6
6
|
exports.version = version;
|
|
7
7
|
|
package/dist/cjs/version.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"version.js","names":[],"sources":["../../src/version.ts"],"sourcesContent":["export const name = '@lifi/sdk-provider-solana'\nexport const version = '0.0.0-preview-
|
|
1
|
+
{"version":3,"file":"version.js","names":[],"sources":["../../src/version.ts"],"sourcesContent":["export const name = '@lifi/sdk-provider-solana'\nexport const version = '0.0.0-preview-155bb7fe'\n"],"mappings":";;AAAA,MAAa,OAAO;AACpB,MAAa,UAAU"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"raceRpcs.js","names":[],"sources":["../../../src/confirmation/raceRpcs.ts"],"sourcesContent":["import type { ConfirmationOutcome } from './types.js'\n\nexport type RaceResult<T> =\n | { kind: 'confirmed'; value: T }\n /** `slot`: the highest verdict slot of the branches. The transaction can\n * no longer land after it. */\n | { kind: 'expired'; slot: bigint; errors: Error[] }\n | { kind: 'not-confirmed'; errors: Error[] }\n | { kind: 'rpc-unavailable'; errors: Error[] }\n\n/** Every result that is not a confirmation. Independent of the value type. */\nexport type UnconfirmedRaceResult = Exclude<\n RaceResult<unknown>,\n { kind: 'confirmed' }\n>\n\nconst toError = (reason: unknown): Error =>\n reason instanceof Error ? reason : new Error(String(reason))\n\n/**\n * Aborts when `signal` aborts or `timeoutMs` elapses, whichever is first.\n *\n * Not `AbortSignal.any` + `AbortSignal.timeout`: both are Baseline March 2024,\n * and a published SDK should not raise its runtime floor for a convenience one\n * controller and one timer already cover. The caller's signal is never aborted\n * here, so \"caller aborted\" and \"timeout fired\" stay distinguishable.\n */\nfunction abortAfter(\n signal: AbortSignal,\n timeoutMs: number\n): { signal: AbortSignal; dispose: () => void } {\n const linked = new AbortController()\n const forward = (): void => linked.abort(signal.reason)\n\n const timer = setTimeout(() => {\n linked.abort(new Error(`This RPC did not answer within ${timeoutMs}ms.`))\n }, timeoutMs)\n // A pending timer keeps Node's event loop alive. `dispose` clears it; the\n // unref only covers a path that skips `dispose`.\n const handle = timer as unknown as { unref?: () => void }\n handle.unref?.()\n\n if (signal.aborted) {\n forward()\n } else {\n signal.addEventListener('abort', forward, { once: true })\n }\n\n return {\n signal: linked.signal,\n dispose: (): void => {\n clearTimeout(timer)\n signal.removeEventListener('abort', forward)\n },\n }\n}\n\n/**\n * Runs `run` against every RPC in parallel and reports the first confirmation.\n *\n * Not `Promise.any`: it turns \"polled and saw nothing\" into a thrown sentinel,\n * collapsing the difference between an expired transaction and an RPC that\n * never answered - the defect that reported live swaps as `TransactionExpired`.\n * `timeoutMs` is the caller's; this module holds no confirmation policy.\n */\nexport async function raceRpcs<Rpc, T>(\n rpcs: Rpc[],\n run: (rpc: Rpc, signal: AbortSignal) => Promise<ConfirmationOutcome<T>>,\n options: { timeoutMs: number }\n): Promise<RaceResult<T>> {\n if (rpcs.length === 0) {\n return { kind: 'rpc-unavailable', errors: [] }\n }\n\n const controller = new AbortController()\n // Kept distinct: `controller` means \"another branch confirmed\", the timeout\n // means \"this endpoint never answered\". The timeout aborts the linked signal\n // only.\n const branch = abortAfter(controller.signal, options.timeoutMs)\n\n let resolveConfirmed: ((value: T) => void) | undefined\n const firstConfirmation = new Promise<T>((resolve) => {\n resolveConfirmed = resolve\n })\n\n const settled = Promise.allSettled(\n rpcs.map(async (rpc) => {\n const outcome = await run(rpc, branch.signal)\n if (outcome.kind === 'confirmed') {\n resolveConfirmed?.(outcome.value)\n controller.abort()\n }\n return outcome\n })\n )\n\n const classify = (\n results: PromiseSettledResult<ConfirmationOutcome<T>>[]\n ): RaceResult<T> => {\n let expiredAtSlot: bigint | undefined\n let sawNotConfirmed = false\n const errors: Error[] = []\n\n for (const entry of results) {\n if (entry.status === 'fulfilled') {\n // Unreachable today - `firstConfirmation` always wins - but keeps\n // `classify` correct if that structure changes.\n if (entry.value.kind === 'confirmed') {\n return { kind: 'confirmed', value: entry.value.value }\n }\n if (entry.value.kind === 'expired') {\n // The highest verdict slot: the strictest head a dropped check can\n // demand.\n if (expiredAtSlot === undefined || entry.value.slot > expiredAtSlot) {\n expiredAtSlot = entry.value.slot\n }\n } else {\n sawNotConfirmed = true\n }\n continue\n }\n // Cancelled branches are not failures. A branch the timeout killed is,\n // so its error is collected.\n if (controller.signal.aborted) {\n continue\n }\n errors.push(toError(entry.reason))\n }\n\n // A completed observation outranks a thrown error, but the collected\n // errors still travel with it as the expiry's `cause`.\n //\n // Among the observations, the ceiling outranks an expiry: `expired` may\n // end in a final \"dropped\", so every branch that observed has to agree\n // on it. A stale node alone must not drop a transaction that another\n // endpoint still watched to its ceiling.\n if (sawNotConfirmed) {\n return { kind: 'not-confirmed', errors }\n }\n if (expiredAtSlot !== undefined) {\n return { kind: 'expired', slot: expiredAtSlot, errors }\n }\n return { kind: 'rpc-unavailable', errors }\n }\n\n try {\n const result = await Promise.race([\n firstConfirmation.then((value): RaceResult<T> => ({\n kind: 'confirmed',\n value,\n })),\n settled.then(classify),\n ])\n\n return result\n } finally {\n // Cancels every in-flight branch on every path out, rejections included.\n // Must run before `dispose`, which detaches the listener carrying it.\n controller.abort()\n branch.dispose()\n }\n}\n"],"mappings":";AAgBA,MAAM,WAAW,WACf,kBAAkB,QAAQ,SAAS,IAAI,MAAM,OAAO,MAAM,CAAC;;;;;;;;;AAU7D,SAAS,WACP,QACA,WAC8C;CAC9C,MAAM,SAAS,IAAI,gBAAgB;CACnC,MAAM,gBAAsB,OAAO,MAAM,OAAO,MAAM;CAEtD,MAAM,QAAQ,iBAAiB;EAC7B,OAAO,sBAAM,IAAI,MAAM,kCAAkC,UAAU,IAAI,CAAC;CAC1E,GAAG,SAAS;
|
|
1
|
+
{"version":3,"file":"raceRpcs.js","names":["handle"],"sources":["../../../src/confirmation/raceRpcs.ts"],"sourcesContent":["import type { ConfirmationOutcome } from './types.js'\n\nexport type RaceResult<T> =\n | { kind: 'confirmed'; value: T }\n /** `slot`: the highest verdict slot of the branches. The transaction can\n * no longer land after it. */\n | { kind: 'expired'; slot: bigint; errors: Error[] }\n | { kind: 'not-confirmed'; errors: Error[] }\n | { kind: 'rpc-unavailable'; errors: Error[] }\n\n/** Every result that is not a confirmation. Independent of the value type. */\nexport type UnconfirmedRaceResult = Exclude<\n RaceResult<unknown>,\n { kind: 'confirmed' }\n>\n\nconst toError = (reason: unknown): Error =>\n reason instanceof Error ? reason : new Error(String(reason))\n\n/**\n * Aborts when `signal` aborts or `timeoutMs` elapses, whichever is first.\n *\n * Not `AbortSignal.any` + `AbortSignal.timeout`: both are Baseline March 2024,\n * and a published SDK should not raise its runtime floor for a convenience one\n * controller and one timer already cover. The caller's signal is never aborted\n * here, so \"caller aborted\" and \"timeout fired\" stay distinguishable.\n */\nfunction abortAfter(\n signal: AbortSignal,\n timeoutMs: number\n): { signal: AbortSignal; dispose: () => void } {\n const linked = new AbortController()\n const forward = (): void => linked.abort(signal.reason)\n\n const timer = setTimeout(() => {\n linked.abort(new Error(`This RPC did not answer within ${timeoutMs}ms.`))\n }, timeoutMs)\n // A pending timer keeps Node's event loop alive. `dispose` clears it; the\n // unref only covers a path that skips `dispose`.\n const handle = timer as unknown as { unref?: () => void }\n handle.unref?.()\n\n if (signal.aborted) {\n forward()\n } else {\n signal.addEventListener('abort', forward, { once: true })\n }\n\n return {\n signal: linked.signal,\n dispose: (): void => {\n clearTimeout(timer)\n signal.removeEventListener('abort', forward)\n },\n }\n}\n\n/**\n * Runs `run` against every RPC in parallel and reports the first confirmation.\n *\n * Not `Promise.any`: it turns \"polled and saw nothing\" into a thrown sentinel,\n * collapsing the difference between an expired transaction and an RPC that\n * never answered - the defect that reported live swaps as `TransactionExpired`.\n * `timeoutMs` is the caller's; this module holds no confirmation policy.\n */\nexport async function raceRpcs<Rpc, T>(\n rpcs: Rpc[],\n run: (rpc: Rpc, signal: AbortSignal) => Promise<ConfirmationOutcome<T>>,\n options: { timeoutMs: number }\n): Promise<RaceResult<T>> {\n if (rpcs.length === 0) {\n return { kind: 'rpc-unavailable', errors: [] }\n }\n\n const controller = new AbortController()\n // Kept distinct: `controller` means \"another branch confirmed\", the timeout\n // means \"this endpoint never answered\". The timeout aborts the linked signal\n // only.\n const branch = abortAfter(controller.signal, options.timeoutMs)\n\n let resolveConfirmed: ((value: T) => void) | undefined\n const firstConfirmation = new Promise<T>((resolve) => {\n resolveConfirmed = resolve\n })\n\n const settled = Promise.allSettled(\n rpcs.map(async (rpc) => {\n const outcome = await run(rpc, branch.signal)\n if (outcome.kind === 'confirmed') {\n resolveConfirmed?.(outcome.value)\n controller.abort()\n }\n return outcome\n })\n )\n\n const classify = (\n results: PromiseSettledResult<ConfirmationOutcome<T>>[]\n ): RaceResult<T> => {\n let expiredAtSlot: bigint | undefined\n let sawNotConfirmed = false\n const errors: Error[] = []\n\n for (const entry of results) {\n if (entry.status === 'fulfilled') {\n // Unreachable today - `firstConfirmation` always wins - but keeps\n // `classify` correct if that structure changes.\n if (entry.value.kind === 'confirmed') {\n return { kind: 'confirmed', value: entry.value.value }\n }\n if (entry.value.kind === 'expired') {\n // The highest verdict slot: the strictest head a dropped check can\n // demand.\n if (expiredAtSlot === undefined || entry.value.slot > expiredAtSlot) {\n expiredAtSlot = entry.value.slot\n }\n } else {\n sawNotConfirmed = true\n }\n continue\n }\n // Cancelled branches are not failures. A branch the timeout killed is,\n // so its error is collected.\n if (controller.signal.aborted) {\n continue\n }\n errors.push(toError(entry.reason))\n }\n\n // A completed observation outranks a thrown error, but the collected\n // errors still travel with it as the expiry's `cause`.\n //\n // Among the observations, the ceiling outranks an expiry: `expired` may\n // end in a final \"dropped\", so every branch that observed has to agree\n // on it. A stale node alone must not drop a transaction that another\n // endpoint still watched to its ceiling.\n if (sawNotConfirmed) {\n return { kind: 'not-confirmed', errors }\n }\n if (expiredAtSlot !== undefined) {\n return { kind: 'expired', slot: expiredAtSlot, errors }\n }\n return { kind: 'rpc-unavailable', errors }\n }\n\n try {\n const result = await Promise.race([\n firstConfirmation.then((value): RaceResult<T> => ({\n kind: 'confirmed',\n value,\n })),\n settled.then(classify),\n ])\n\n return result\n } finally {\n // Cancels every in-flight branch on every path out, rejections included.\n // Must run before `dispose`, which detaches the listener carrying it.\n controller.abort()\n branch.dispose()\n }\n}\n"],"mappings":";AAgBA,MAAM,WAAW,WACf,kBAAkB,QAAQ,SAAS,IAAI,MAAM,OAAO,MAAM,CAAC;;;;;;;;;AAU7D,SAAS,WACP,QACA,WAC8C;CAC9C,MAAM,SAAS,IAAI,gBAAgB;CACnC,MAAM,gBAAsB,OAAO,MAAM,OAAO,MAAM;CAEtD,MAAM,QAAQ,iBAAiB;EAC7B,OAAO,sBAAM,IAAI,MAAM,kCAAkC,UAAU,IAAI,CAAC;CAC1E,GAAG,SAAS;CAIZA,MAAO,QAAQ;CAEf,IAAI,OAAO,SACT,QAAQ;MAER,OAAO,iBAAiB,SAAS,SAAS,EAAE,MAAM,KAAK,CAAC;CAG1D,OAAO;EACL,QAAQ,OAAO;EACf,eAAqB;GACnB,aAAa,KAAK;GAClB,OAAO,oBAAoB,SAAS,OAAO;EAC7C;CACF;AACF;;;;;;;;;AAUA,eAAsB,SACpB,MACA,KACA,SACwB;CACxB,IAAI,KAAK,WAAW,GAClB,OAAO;EAAE,MAAM;EAAmB,QAAQ,CAAC;CAAE;CAG/C,MAAM,aAAa,IAAI,gBAAgB;CAIvC,MAAM,SAAS,WAAW,WAAW,QAAQ,QAAQ,SAAS;CAE9D,IAAI;CACJ,MAAM,oBAAoB,IAAI,SAAY,YAAY;EACpD,mBAAmB;CACrB,CAAC;CAED,MAAM,UAAU,QAAQ,WACtB,KAAK,IAAI,OAAO,QAAQ;EACtB,MAAM,UAAU,MAAM,IAAI,KAAK,OAAO,MAAM;EAC5C,IAAI,QAAQ,SAAS,aAAa;GAChC,mBAAmB,QAAQ,KAAK;GAChC,WAAW,MAAM;EACnB;EACA,OAAO;CACT,CAAC,CACH;CAEA,MAAM,YACJ,YACkB;EAClB,IAAI;EACJ,IAAI,kBAAkB;EACtB,MAAM,SAAkB,CAAC;EAEzB,KAAK,MAAM,SAAS,SAAS;GAC3B,IAAI,MAAM,WAAW,aAAa;IAGhC,IAAI,MAAM,MAAM,SAAS,aACvB,OAAO;KAAE,MAAM;KAAa,OAAO,MAAM,MAAM;IAAM;IAEvD,IAAI,MAAM,MAAM,SAAS,WAGnB;SAAA,kBAAkB,KAAA,KAAa,MAAM,MAAM,OAAO,eACpD,gBAAgB,MAAM,MAAM;IAAA,OAG9B,kBAAkB;IAEpB;GACF;GAGA,IAAI,WAAW,OAAO,SACpB;GAEF,OAAO,KAAK,QAAQ,MAAM,MAAM,CAAC;EACnC;EASA,IAAI,iBACF,OAAO;GAAE,MAAM;GAAiB;EAAO;EAEzC,IAAI,kBAAkB,KAAA,GACpB,OAAO;GAAE,MAAM;GAAW,MAAM;GAAe;EAAO;EAExD,OAAO;GAAE,MAAM;GAAmB;EAAO;CAC3C;CAEA,IAAI;EASF,OAAO,MARc,QAAQ,KAAK,CAChC,kBAAkB,MAAM,WAA0B;GAChD,MAAM;GACN;EACF,EAAE,GACF,QAAQ,KAAK,QAAQ,CACvB,CAAC;CAGH,UAAU;EAGR,WAAW,MAAM;EACjB,OAAO,QAAQ;CACjB;AACF"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"SolanaStepExecutor.js","names":[],"sources":["../../../src/core/SolanaStepExecutor.ts"],"sourcesContent":["import {\n BaseStepExecutor,\n CheckBalanceTask,\n type ExecutionAction,\n hasOpenTransaction,\n LiFiErrorCode,\n type LiFiStepExtended,\n PrepareTransactionTask,\n type SDKError,\n type StepExecutorBaseContext,\n TaskPipeline,\n TransactionError,\n WaitForTransactionStatusTask,\n} from '@lifi/sdk'\nimport type { Wallet, WalletAccount } from '@wallet-standard/base'\nimport { parseSolanaErrors } from '../errors/parseSolanaErrors.js'\nimport type {\n SolanaStepExecutorContext,\n SolanaStepExecutorOptions,\n} from '../types.js'\nimport { SolanaSignAndExecuteTask } from './tasks/SolanaSignAndExecuteTask.js'\nimport { SolanaWaitForTransactionTask } from './tasks/SolanaWaitForTransactionTask.js'\n\nexport class SolanaStepExecutor extends BaseStepExecutor {\n private wallet: Wallet\n private skipSimulation: boolean\n\n constructor(options: SolanaStepExecutorOptions) {\n super(options)\n this.wallet = options.wallet\n this.skipSimulation = options.skipSimulation ?? false\n }\n\n getWalletAccount = (step: LiFiStepExtended): WalletAccount => {\n const account = this.wallet.accounts.find(\n (account) => account.address === step.action.fromAddress\n )\n\n if (!account) {\n throw new TransactionError(\n LiFiErrorCode.WalletChangedDuringExecution,\n 'The wallet address that requested the quote does not match the wallet address attempting to sign the transaction.'\n )\n }\n\n return account\n }\n\n override parseErrors = (\n error: Error,\n step?: LiFiStepExtended,\n action?: ExecutionAction\n ): Promise<SDKError> => parseSolanaErrors(error, step, action)\n\n override createContext = async (\n baseContext: StepExecutorBaseContext\n ): Promise<SolanaStepExecutorContext> => {\n // The account is resolved by the sign task, not here: a resume that only\n // waits must not fail because the wallet has not reconnected yet.\n return {\n ...baseContext,\n wallet: this.wallet,\n getWalletAccount: this.getWalletAccount,\n skipSimulation: this.skipSimulation,\n }\n }\n\n override createPipeline = (\n context: SolanaStepExecutorContext\n ): TaskPipeline => {\n const { step, isBridgeExecution } = context\n\n const tasks = [\n new CheckBalanceTask(),\n new PrepareTransactionTask(),\n new SolanaSignAndExecuteTask(),\n new SolanaWaitForTransactionTask(),\n new WaitForTransactionStatusTask(\n isBridgeExecution ? 'RECEIVING_CHAIN' : 'SWAP'\n ),\n ]\n\n const swapOrBridgeAction = this.statusManager.findAction(\n step,\n isBridgeExecution ? 'CROSS_CHAIN' : 'SWAP'\n )\n\n // Three-way, as Stellar and Bitcoin do. An open transaction - a broadcast\n // signature, or signed bytes that may have been sent - resumes at the\n // wait task, which looks it up and resends the same bytes. Starting at\n // CheckBalanceTask would fetch a new quote and sign a second transaction\n // while the first can still land. A same-chain swap stays PENDING with\n // its signature until the LI.FI status is DONE, so this is the common\n // reload.\n const firstTask = hasOpenTransaction(swapOrBridgeAction)\n ? swapOrBridgeAction?.status === 'DONE'\n ? WaitForTransactionStatusTask\n : SolanaWaitForTransactionTask\n : CheckBalanceTask\n\n // Compare classes, not names: a minifier can give two task classes the\n // same name.\n const firstTaskIndex = tasks.findIndex(\n (task) => task.constructor === firstTask\n )\n if (firstTaskIndex === -1) {\n throw new TransactionError(\n LiFiErrorCode.InternalError,\n 'SolanaStepExecutor.createPipeline: first task not found'\n )\n }\n\n const tasksToRun = tasks.slice(firstTaskIndex)\n\n return new TaskPipeline(tasksToRun)\n }\n}\n"],"mappings":";;;;;AAuBA,IAAa,qBAAb,cAAwC,iBAAiB;
|
|
1
|
+
{"version":3,"file":"SolanaStepExecutor.js","names":[],"sources":["../../../src/core/SolanaStepExecutor.ts"],"sourcesContent":["import {\n BaseStepExecutor,\n CheckBalanceTask,\n type ExecutionAction,\n hasOpenTransaction,\n LiFiErrorCode,\n type LiFiStepExtended,\n PrepareTransactionTask,\n type SDKError,\n type StepExecutorBaseContext,\n TaskPipeline,\n TransactionError,\n WaitForTransactionStatusTask,\n} from '@lifi/sdk'\nimport type { Wallet, WalletAccount } from '@wallet-standard/base'\nimport { parseSolanaErrors } from '../errors/parseSolanaErrors.js'\nimport type {\n SolanaStepExecutorContext,\n SolanaStepExecutorOptions,\n} from '../types.js'\nimport { SolanaSignAndExecuteTask } from './tasks/SolanaSignAndExecuteTask.js'\nimport { SolanaWaitForTransactionTask } from './tasks/SolanaWaitForTransactionTask.js'\n\nexport class SolanaStepExecutor extends BaseStepExecutor {\n private wallet: Wallet\n private skipSimulation: boolean\n\n constructor(options: SolanaStepExecutorOptions) {\n super(options)\n this.wallet = options.wallet\n this.skipSimulation = options.skipSimulation ?? false\n }\n\n getWalletAccount = (step: LiFiStepExtended): WalletAccount => {\n const account = this.wallet.accounts.find(\n (account) => account.address === step.action.fromAddress\n )\n\n if (!account) {\n throw new TransactionError(\n LiFiErrorCode.WalletChangedDuringExecution,\n 'The wallet address that requested the quote does not match the wallet address attempting to sign the transaction.'\n )\n }\n\n return account\n }\n\n override parseErrors = (\n error: Error,\n step?: LiFiStepExtended,\n action?: ExecutionAction\n ): Promise<SDKError> => parseSolanaErrors(error, step, action)\n\n override createContext = async (\n baseContext: StepExecutorBaseContext\n ): Promise<SolanaStepExecutorContext> => {\n // The account is resolved by the sign task, not here: a resume that only\n // waits must not fail because the wallet has not reconnected yet.\n return {\n ...baseContext,\n wallet: this.wallet,\n getWalletAccount: this.getWalletAccount,\n skipSimulation: this.skipSimulation,\n }\n }\n\n override createPipeline = (\n context: SolanaStepExecutorContext\n ): TaskPipeline => {\n const { step, isBridgeExecution } = context\n\n const tasks = [\n new CheckBalanceTask(),\n new PrepareTransactionTask(),\n new SolanaSignAndExecuteTask(),\n new SolanaWaitForTransactionTask(),\n new WaitForTransactionStatusTask(\n isBridgeExecution ? 'RECEIVING_CHAIN' : 'SWAP'\n ),\n ]\n\n const swapOrBridgeAction = this.statusManager.findAction(\n step,\n isBridgeExecution ? 'CROSS_CHAIN' : 'SWAP'\n )\n\n // Three-way, as Stellar and Bitcoin do. An open transaction - a broadcast\n // signature, or signed bytes that may have been sent - resumes at the\n // wait task, which looks it up and resends the same bytes. Starting at\n // CheckBalanceTask would fetch a new quote and sign a second transaction\n // while the first can still land. A same-chain swap stays PENDING with\n // its signature until the LI.FI status is DONE, so this is the common\n // reload.\n const firstTask = hasOpenTransaction(swapOrBridgeAction)\n ? swapOrBridgeAction?.status === 'DONE'\n ? WaitForTransactionStatusTask\n : SolanaWaitForTransactionTask\n : CheckBalanceTask\n\n // Compare classes, not names: a minifier can give two task classes the\n // same name.\n const firstTaskIndex = tasks.findIndex(\n (task) => task.constructor === firstTask\n )\n if (firstTaskIndex === -1) {\n throw new TransactionError(\n LiFiErrorCode.InternalError,\n 'SolanaStepExecutor.createPipeline: first task not found'\n )\n }\n\n const tasksToRun = tasks.slice(firstTaskIndex)\n\n return new TaskPipeline(tasksToRun)\n }\n}\n"],"mappings":";;;;;AAuBA,IAAa,qBAAb,cAAwC,iBAAiB;CAC/C;CACA;CAER,YAAY,SAAoC;EAC9C,MAAM,OAAO;EACb,KAAK,SAAS,QAAQ;EACtB,KAAK,iBAAiB,QAAQ,kBAAkB;CAClD;CAEA,oBAAoB,SAA0C;EAC5D,MAAM,UAAU,KAAK,OAAO,SAAS,MAClC,YAAY,QAAQ,YAAY,KAAK,OAAO,WAC/C;EAEA,IAAI,CAAC,SACH,MAAM,IAAI,iBACR,cAAc,8BACd,mHACF;EAGF,OAAO;CACT;CAES,eACP,OACA,MACA,WACsB,kBAAkB,OAAO,MAAM,MAAM;CAEpD,gBAAgB,OACvB,gBACuC;EAGvC,OAAO;GACL,GAAG;GACH,QAAQ,KAAK;GACb,kBAAkB,KAAK;GACvB,gBAAgB,KAAK;EACvB;CACF;CAES,kBACP,YACiB;EACjB,MAAM,EAAE,MAAM,sBAAsB;EAEpC,MAAM,QAAQ;GACZ,IAAI,iBAAiB;GACrB,IAAI,uBAAuB;GAC3B,IAAI,yBAAyB;GAC7B,IAAI,6BAA6B;GACjC,IAAI,6BACF,oBAAoB,oBAAoB,MAC1C;EACF;EAEA,MAAM,qBAAqB,KAAK,cAAc,WAC5C,MACA,oBAAoB,gBAAgB,MACtC;EASA,MAAM,YAAY,mBAAmB,kBAAkB,IACnD,oBAAoB,WAAW,SAC7B,+BACA,+BACF;EAIJ,MAAM,iBAAiB,MAAM,WAC1B,SAAS,KAAK,gBAAgB,SACjC;EACA,IAAI,mBAAmB,IACrB,MAAM,IAAI,iBACR,cAAc,eACd,yDACF;EAGF,MAAM,aAAa,MAAM,MAAM,cAAc;EAE7C,OAAO,IAAI,aAAa,UAAU;CACpC;AACF"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"SolanaJitoWaitForTransactionTask.d.ts","names":[],"sources":["../../../../src/core/tasks/SolanaJitoWaitForTransactionTask.ts"],"mappings":";;qBA+Ca,yCAAyC;
|
|
1
|
+
{"version":3,"file":"SolanaJitoWaitForTransactionTask.d.ts","names":[],"sources":["../../../../src/core/tasks/SolanaJitoWaitForTransactionTask.ts"],"mappings":";;qBA+Ca,yCAAyC;EAC9C,IAAI,SAAS,4BAA4B,QAAQ"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"SolanaSignAndExecuteTask.d.ts","names":[],"sources":["../../../../src/core/tasks/SolanaSignAndExecuteTask.ts"],"mappings":";;qBAkBa,iCAAiC;
|
|
1
|
+
{"version":3,"file":"SolanaSignAndExecuteTask.d.ts","names":[],"sources":["../../../../src/core/tasks/SolanaSignAndExecuteTask.ts"],"mappings":";;qBAkBa,iCAAiC;EACtC,IAAI,SAAS,4BAA4B,QAAQ"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"SolanaStandardWaitForTransactionTask.d.ts","names":[],"sources":["../../../../src/core/tasks/SolanaStandardWaitForTransactionTask.ts"],"mappings":";;qBAwCa,6CAA6C;
|
|
1
|
+
{"version":3,"file":"SolanaStandardWaitForTransactionTask.d.ts","names":[],"sources":["../../../../src/core/tasks/SolanaStandardWaitForTransactionTask.ts"],"mappings":";;qBAwCa,6CAA6C;EAClD,IAAI,SAAS,4BAA4B,QAAQ"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"SolanaWaitForTransactionTask.d.ts","names":[],"sources":["../../../../src/core/tasks/SolanaWaitForTransactionTask.ts"],"mappings":";;qBAuBa,qCAAqC;
|
|
1
|
+
{"version":3,"file":"SolanaWaitForTransactionTask.d.ts","names":[],"sources":["../../../../src/core/tasks/SolanaWaitForTransactionTask.ts"],"mappings":";;qBAuBa,qCAAqC;EAC1C,IAAI,SAAS,4BAA4B,QAAQ"}
|
|
@@ -10,13 +10,16 @@ const parseSolanaErrors = async (e, step, action) => {
|
|
|
10
10
|
return new SDKError(baseError, step, action);
|
|
11
11
|
};
|
|
12
12
|
const userRejectionMessage = /(^|\W)user\W+(has\W+)?(rejected|denied|cancell?ed)|\b(rejected|denied|cancell?ed)\W+by\W+(the\W+)?user\b/i;
|
|
13
|
+
const walletCancelMessage = /^transaction (was )?cancell?ed\.?$/i;
|
|
13
14
|
/**
|
|
14
15
|
* The SDK calls the Wallet Standard features directly, so a wallet's own error
|
|
15
16
|
* arrives here unwrapped. Wallets report a rejection with the EIP-1193 code
|
|
16
|
-
* 4001 or only with a message.
|
|
17
|
-
*
|
|
17
|
+
* 4001 or only with a message. A wallet cancel is a rejection too: the prompt
|
|
18
|
+
* was open and the wallet sent nothing, as with `WalletSignTransactionError`.
|
|
19
|
+
* An `AbortError` is not a rejection: nothing says the user caused it. The
|
|
20
|
+
* SDK's own errors keep their code.
|
|
18
21
|
*/
|
|
19
|
-
const isUserRejection = (e) => !(e instanceof BaseError) && (e.code === 4001 || typeof e.message === "string" && userRejectionMessage.test(e.message));
|
|
22
|
+
const isUserRejection = (e) => !(e instanceof BaseError) && (e.code === 4001 || typeof e.message === "string" && (userRejectionMessage.test(e.message) || walletCancelMessage.test(e.message.trim())));
|
|
20
23
|
const handleSpecificErrors = (e) => {
|
|
21
24
|
if (e.name === "WalletSignTransactionError") return new TransactionError(LiFiErrorCode.SignatureRejected, e.message, e);
|
|
22
25
|
if (e.name === "SendTransactionError") return new TransactionError(LiFiErrorCode.TransactionFailed, e.message, e);
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"parseSolanaErrors.js","names":[],"sources":["../../../src/errors/parseSolanaErrors.ts"],"sourcesContent":["import {\n BaseError,\n ErrorMessage,\n type ExecutionAction,\n LiFiErrorCode,\n type LiFiStep,\n SDKError,\n TransactionError,\n UnknownError,\n} from '@lifi/sdk'\n\nexport const parseSolanaErrors = async (\n e: Error,\n step?: LiFiStep,\n action?: ExecutionAction\n): Promise<SDKError> => {\n if (e instanceof SDKError) {\n e.step = e.step ?? step\n e.action = e.action ?? action\n return e\n }\n\n const baseError = handleSpecificErrors(e)\n\n return new SDKError(baseError, step, action)\n}\n\n// Same pattern as bigmi's `isUserRejection`. It is anchored on \"user\", so a\n// refusal by a node or a host does not count as a rejection.\nconst userRejectionMessage =\n /(^|\\W)user\\W+(has\\W+)?(rejected|denied|cancell?ed)|\\b(rejected|denied|cancell?ed)\\W+by\\W+(the\\W+)?user\\b/i\n\n/**\n * The SDK calls the Wallet Standard features directly, so a wallet's own error\n * arrives here unwrapped. Wallets report a rejection with the EIP-1193 code\n * 4001 or only with a message. An `AbortError` is not a rejection: nothing
|
|
1
|
+
{"version":3,"file":"parseSolanaErrors.js","names":[],"sources":["../../../src/errors/parseSolanaErrors.ts"],"sourcesContent":["import {\n BaseError,\n ErrorMessage,\n type ExecutionAction,\n LiFiErrorCode,\n type LiFiStep,\n SDKError,\n TransactionError,\n UnknownError,\n} from '@lifi/sdk'\n\nexport const parseSolanaErrors = async (\n e: Error,\n step?: LiFiStep,\n action?: ExecutionAction\n): Promise<SDKError> => {\n if (e instanceof SDKError) {\n e.step = e.step ?? step\n e.action = e.action ?? action\n return e\n }\n\n const baseError = handleSpecificErrors(e)\n\n return new SDKError(baseError, step, action)\n}\n\n// Same pattern as bigmi's `isUserRejection`. It is anchored on \"user\", so a\n// refusal by a node or a host does not count as a rejection.\nconst userRejectionMessage =\n /(^|\\W)user\\W+(has\\W+)?(rejected|denied|cancell?ed)|\\b(rejected|denied|cancell?ed)\\W+by\\W+(the\\W+)?user\\b/i\n\n// Some wallets report a Cancel on the sign prompt only with this text (an\n// Android in-app wallet). The whole message must match, so a longer error that\n// starts with these words does not count.\nconst walletCancelMessage = /^transaction (was )?cancell?ed\\.?$/i\n\n/**\n * The SDK calls the Wallet Standard features directly, so a wallet's own error\n * arrives here unwrapped. Wallets report a rejection with the EIP-1193 code\n * 4001 or only with a message. A wallet cancel is a rejection too: the prompt\n * was open and the wallet sent nothing, as with `WalletSignTransactionError`.\n * An `AbortError` is not a rejection: nothing says the user caused it. The\n * SDK's own errors keep their code.\n */\nconst isUserRejection = (e: any): boolean =>\n !(e instanceof BaseError) &&\n (e.code === 4001 ||\n (typeof e.message === 'string' &&\n (userRejectionMessage.test(e.message) ||\n walletCancelMessage.test(e.message.trim()))))\n\nconst handleSpecificErrors = (e: any) => {\n if (e.name === 'WalletSignTransactionError') {\n return new TransactionError(LiFiErrorCode.SignatureRejected, e.message, e)\n }\n\n if (e.name === 'SendTransactionError') {\n return new TransactionError(LiFiErrorCode.TransactionFailed, e.message, e)\n }\n\n if (e.name === 'TransactionExpiredBlockheightExceededError') {\n return new TransactionError(LiFiErrorCode.TransactionExpired, e.message, e)\n }\n\n // After the name checks: a known error keeps its code, even when its\n // message quotes program logs that look like a rejection.\n if (isUserRejection(e)) {\n return new TransactionError(LiFiErrorCode.SignatureRejected, e.message, e)\n }\n\n if (e.message?.includes('simulate')) {\n return new TransactionError(\n LiFiErrorCode.TransactionSimulationFailed,\n e.message,\n e\n )\n }\n\n if (e instanceof BaseError) {\n return e\n }\n\n return new UnknownError(e.message || ErrorMessage.UnknownError, e)\n}\n"],"mappings":";;AAWA,MAAa,oBAAoB,OAC/B,GACA,MACA,WACsB;CACtB,IAAI,aAAa,UAAU;EACzB,EAAE,OAAO,EAAE,QAAQ;EACnB,EAAE,SAAS,EAAE,UAAU;EACvB,OAAO;CACT;CAEA,MAAM,YAAY,qBAAqB,CAAC;CAExC,OAAO,IAAI,SAAS,WAAW,MAAM,MAAM;AAC7C;AAIA,MAAM,uBACJ;AAKF,MAAM,sBAAsB;;;;;;;;;AAU5B,MAAM,mBAAmB,MACvB,EAAE,aAAa,eACd,EAAE,SAAS,QACT,OAAO,EAAE,YAAY,aACnB,qBAAqB,KAAK,EAAE,OAAO,KAClC,oBAAoB,KAAK,EAAE,QAAQ,KAAK,CAAC;AAEjD,MAAM,wBAAwB,MAAW;CACvC,IAAI,EAAE,SAAS,8BACb,OAAO,IAAI,iBAAiB,cAAc,mBAAmB,EAAE,SAAS,CAAC;CAG3E,IAAI,EAAE,SAAS,wBACb,OAAO,IAAI,iBAAiB,cAAc,mBAAmB,EAAE,SAAS,CAAC;CAG3E,IAAI,EAAE,SAAS,8CACb,OAAO,IAAI,iBAAiB,cAAc,oBAAoB,EAAE,SAAS,CAAC;CAK5E,IAAI,gBAAgB,CAAC,GACnB,OAAO,IAAI,iBAAiB,cAAc,mBAAmB,EAAE,SAAS,CAAC;CAG3E,IAAI,EAAE,SAAS,SAAS,UAAU,GAChC,OAAO,IAAI,iBACT,cAAc,6BACd,EAAE,SACF,CACF;CAGF,IAAI,aAAa,WACf,OAAO;CAGT,OAAO,IAAI,aAAa,EAAE,WAAW,aAAa,cAAc,CAAC;AACnE"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"KeypairWalletAdapter.d.ts","names":[],"sources":["../../../src/utils/KeypairWalletAdapter.ts"],"mappings":";;;;;;qBAsBa,gCAAgC;;;;;UAKnC;UACA;mBACS;WAER;WACA;WACA;EAGT,YAAY;MAqBR;MAIA,qBAAqB;MAIrB,YAAY;
|
|
1
|
+
{"version":3,"file":"KeypairWalletAdapter.d.ts","names":[],"sources":["../../../src/utils/KeypairWalletAdapter.ts"],"mappings":";;;;;;qBAsBa,gCAAgC;;;;;UAKnC;UACA;mBACS;WAER;WACA;WACA;EAGT,YAAY;MAqBR;MAIA,qBAAqB;MAIrB,YAAY;EAUV,WAAW;EAeX,cAAc;UAMN"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"KeypairWalletAdapter.js","names":[],"sources":["../../../src/utils/KeypairWalletAdapter.ts"],"sourcesContent":["import {\n assertIsTransactionWithinSizeLimit,\n createKeyPairSignerFromBytes,\n getBase58Codec,\n getBase64EncodedWireTransaction,\n getTransactionCodec,\n type KeyPairSigner,\n type ReadonlyUint8Array,\n} from '@solana/kit'\nimport {\n SolanaSignTransaction,\n type SolanaSignTransactionFeature,\n type SolanaSignTransactionInput,\n type SolanaSignTransactionOutput,\n} from '@solana/wallet-standard-features'\nimport type { Wallet, WalletAccount } from '@wallet-standard/base'\nimport { base64ToUint8Array } from './base64ToUint8Array.js'\n\n/**\n * This keypair wallet adapter is unsafe to use on the frontend and is only included to provide an easy way for applications to test\n * Wallet Adapter without using a third-party wallet.\n */\nexport class KeypairWalletAdapter implements Wallet {\n /**\n * Storing a keypair locally like this is not safe because any application using this adapter could retrieve the\n * secret key, and because the keypair will be lost any time the wallet is disconnected or the window is refreshed.\n */\n private _signer: KeyPairSigner | undefined\n private _account: WalletAccount | undefined\n private readonly _secretKeyBytes: ReadonlyUint8Array\n\n readonly version = '1.0.0' as const\n readonly name = 'Keypair Wallet' as const\n readonly icon =\n 'data:image/svg+xml;base64,PHN2ZyB3aWR0aD0iMzIiIGhlaWdodD0iMzIiIHZpZXdCb3g9IjAgMCAzMiAzMiIgZmlsbD0ibm9uZSIgeG1sbnM9Imh0dHA6Ly93d3cudzMub3JnLzIwMDAvc3ZnIj48L3N2Zz4=' as const\n\n constructor(secretKeyBase58: string) {\n if (!secretKeyBase58) {\n throw new Error('Private key is required')\n }\n\n const base58Codec = getBase58Codec()\n let encoded: ReadonlyUint8Array\n try {\n encoded = base58Codec.encode(secretKeyBase58)\n } catch {\n throw new Error('Invalid private key format')\n }\n\n if (encoded.length !== 64) {\n throw new Error('Invalid private key length. Expected 64 bytes.')\n }\n\n this._secretKeyBytes = encoded\n }\n\n // Wallet Standard interface properties\n get chains() {\n return ['solana:mainnet', 'solana:devnet', 'solana:testnet'] as const\n }\n\n get accounts(): readonly WalletAccount[] {\n return this._account ? [this._account] : []\n }\n\n get features(): SolanaSignTransactionFeature {\n return {\n [SolanaSignTransaction]: {\n version: '1.0.0' as const,\n supportedTransactionVersions: ['legacy', 0] as const,\n signTransaction: this._signTransactionFeature.bind(this),\n },\n }\n }\n\n async connect(): Promise<void> {\n this._signer = await createKeyPairSignerFromBytes(this._secretKeyBytes)\n\n const publicKeyBytes = new Uint8Array(\n await crypto.subtle.exportKey('raw', this._signer.keyPair.publicKey)\n )\n\n this._account = {\n address: this._signer.address,\n publicKey: publicKeyBytes,\n chains: this.chains,\n features: [SolanaSignTransaction],\n }\n }\n\n async disconnect(): Promise<void> {\n this._signer = undefined\n this._account = undefined\n }\n\n // Wallet Standard feature implementations\n private async _signTransactionFeature(\n ...inputs: readonly SolanaSignTransactionInput[]\n ): Promise<readonly SolanaSignTransactionOutput[]> {\n if (!this._signer) {\n throw new Error('Wallet is not connected')\n }\n\n const results: SolanaSignTransactionOutput[] = []\n\n for (const input of inputs) {\n const transaction = getTransactionCodec().decode(input.transaction)\n\n assertIsTransactionWithinSizeLimit(transaction)\n\n // `assertIsTransactionWithBlockhashLifetime` is deliberately NOT called\n // here. It tests `'lifetimeConstraint' in transaction`, and no kit\n // decoder reconstructs that property - decoding wire bytes yields\n // `{ messageBytes, signatures }` alone, so the assert rejected every\n // transaction a wallet is ever handed. Signing does not need it either:\n // `partiallySignTransaction` signs `messageBytes` and never reads the\n // lifetime. The blockhash still travels inside `messageBytes`, where\n // `getTransactionLifetime` reads it for the confirmation deadline.\n // Cast because `signTransactions` types its argument as carrying a\n // lifetime, while the runtime path - `partiallySignTransaction` - reads\n // only `messageBytes`. A decoded transaction never has the property, so\n // without this the type demands something no decoder can produce.\n const [signatureDictionary] = await this._signer.signTransactions([\n transaction as Parameters<\n typeof this._signer.signTransactions\n >[0][number],\n ])\n\n const signature = signatureDictionary?.[this._signer.address]\n if (!signature) {\n throw new Error('Failed to sign transaction')\n }\n\n // The signature has to be merged back in. `partiallySignTransaction`\n // returns a new frozen object rather than mutating its argument, so\n // encoding `transaction` here shipped the unsigned original and threw\n // the signature away - the transaction then failed on chain for a\n // missing signature, far from the code that dropped it.\n //\n // The cast mirrors the one above: the wire format is `messageBytes`\n // plus `signatures`, and the encoder reads nothing else - the lifetime\n // already travels inside `messageBytes`.\n const signedTransaction = getBase64EncodedWireTransaction({\n ...transaction,\n signatures: {\n ...transaction.signatures,\n [this._signer.address]: signature,\n },\n } as Parameters<typeof getBase64EncodedWireTransaction>[0])\n\n results.push({\n signedTransaction: base64ToUint8Array(signedTransaction),\n })\n }\n\n return results\n }\n}\n"],"mappings":";;;;;;;;AAsBA,IAAa,uBAAb,MAAoD;;;;;
|
|
1
|
+
{"version":3,"file":"KeypairWalletAdapter.js","names":[],"sources":["../../../src/utils/KeypairWalletAdapter.ts"],"sourcesContent":["import {\n assertIsTransactionWithinSizeLimit,\n createKeyPairSignerFromBytes,\n getBase58Codec,\n getBase64EncodedWireTransaction,\n getTransactionCodec,\n type KeyPairSigner,\n type ReadonlyUint8Array,\n} from '@solana/kit'\nimport {\n SolanaSignTransaction,\n type SolanaSignTransactionFeature,\n type SolanaSignTransactionInput,\n type SolanaSignTransactionOutput,\n} from '@solana/wallet-standard-features'\nimport type { Wallet, WalletAccount } from '@wallet-standard/base'\nimport { base64ToUint8Array } from './base64ToUint8Array.js'\n\n/**\n * This keypair wallet adapter is unsafe to use on the frontend and is only included to provide an easy way for applications to test\n * Wallet Adapter without using a third-party wallet.\n */\nexport class KeypairWalletAdapter implements Wallet {\n /**\n * Storing a keypair locally like this is not safe because any application using this adapter could retrieve the\n * secret key, and because the keypair will be lost any time the wallet is disconnected or the window is refreshed.\n */\n private _signer: KeyPairSigner | undefined\n private _account: WalletAccount | undefined\n private readonly _secretKeyBytes: ReadonlyUint8Array\n\n readonly version = '1.0.0' as const\n readonly name = 'Keypair Wallet' as const\n readonly icon =\n 'data:image/svg+xml;base64,PHN2ZyB3aWR0aD0iMzIiIGhlaWdodD0iMzIiIHZpZXdCb3g9IjAgMCAzMiAzMiIgZmlsbD0ibm9uZSIgeG1sbnM9Imh0dHA6Ly93d3cudzMub3JnLzIwMDAvc3ZnIj48L3N2Zz4=' as const\n\n constructor(secretKeyBase58: string) {\n if (!secretKeyBase58) {\n throw new Error('Private key is required')\n }\n\n const base58Codec = getBase58Codec()\n let encoded: ReadonlyUint8Array\n try {\n encoded = base58Codec.encode(secretKeyBase58)\n } catch {\n throw new Error('Invalid private key format')\n }\n\n if (encoded.length !== 64) {\n throw new Error('Invalid private key length. Expected 64 bytes.')\n }\n\n this._secretKeyBytes = encoded\n }\n\n // Wallet Standard interface properties\n get chains() {\n return ['solana:mainnet', 'solana:devnet', 'solana:testnet'] as const\n }\n\n get accounts(): readonly WalletAccount[] {\n return this._account ? [this._account] : []\n }\n\n get features(): SolanaSignTransactionFeature {\n return {\n [SolanaSignTransaction]: {\n version: '1.0.0' as const,\n supportedTransactionVersions: ['legacy', 0] as const,\n signTransaction: this._signTransactionFeature.bind(this),\n },\n }\n }\n\n async connect(): Promise<void> {\n this._signer = await createKeyPairSignerFromBytes(this._secretKeyBytes)\n\n const publicKeyBytes = new Uint8Array(\n await crypto.subtle.exportKey('raw', this._signer.keyPair.publicKey)\n )\n\n this._account = {\n address: this._signer.address,\n publicKey: publicKeyBytes,\n chains: this.chains,\n features: [SolanaSignTransaction],\n }\n }\n\n async disconnect(): Promise<void> {\n this._signer = undefined\n this._account = undefined\n }\n\n // Wallet Standard feature implementations\n private async _signTransactionFeature(\n ...inputs: readonly SolanaSignTransactionInput[]\n ): Promise<readonly SolanaSignTransactionOutput[]> {\n if (!this._signer) {\n throw new Error('Wallet is not connected')\n }\n\n const results: SolanaSignTransactionOutput[] = []\n\n for (const input of inputs) {\n const transaction = getTransactionCodec().decode(input.transaction)\n\n assertIsTransactionWithinSizeLimit(transaction)\n\n // `assertIsTransactionWithBlockhashLifetime` is deliberately NOT called\n // here. It tests `'lifetimeConstraint' in transaction`, and no kit\n // decoder reconstructs that property - decoding wire bytes yields\n // `{ messageBytes, signatures }` alone, so the assert rejected every\n // transaction a wallet is ever handed. Signing does not need it either:\n // `partiallySignTransaction` signs `messageBytes` and never reads the\n // lifetime. The blockhash still travels inside `messageBytes`, where\n // `getTransactionLifetime` reads it for the confirmation deadline.\n // Cast because `signTransactions` types its argument as carrying a\n // lifetime, while the runtime path - `partiallySignTransaction` - reads\n // only `messageBytes`. A decoded transaction never has the property, so\n // without this the type demands something no decoder can produce.\n const [signatureDictionary] = await this._signer.signTransactions([\n transaction as Parameters<\n typeof this._signer.signTransactions\n >[0][number],\n ])\n\n const signature = signatureDictionary?.[this._signer.address]\n if (!signature) {\n throw new Error('Failed to sign transaction')\n }\n\n // The signature has to be merged back in. `partiallySignTransaction`\n // returns a new frozen object rather than mutating its argument, so\n // encoding `transaction` here shipped the unsigned original and threw\n // the signature away - the transaction then failed on chain for a\n // missing signature, far from the code that dropped it.\n //\n // The cast mirrors the one above: the wire format is `messageBytes`\n // plus `signatures`, and the encoder reads nothing else - the lifetime\n // already travels inside `messageBytes`.\n const signedTransaction = getBase64EncodedWireTransaction({\n ...transaction,\n signatures: {\n ...transaction.signatures,\n [this._signer.address]: signature,\n },\n } as Parameters<typeof getBase64EncodedWireTransaction>[0])\n\n results.push({\n signedTransaction: base64ToUint8Array(signedTransaction),\n })\n }\n\n return results\n }\n}\n"],"mappings":";;;;;;;;AAsBA,IAAa,uBAAb,MAAoD;;;;;CAK1C;CACA;CACS;CAER,UAAU;CACV,OAAO;CACP,OACP;CAEF,YAAY,iBAAyB;EACnC,IAAI,CAAC,iBACH,MAAM,IAAI,MAAM,yBAAyB;EAG3C,MAAM,cAAc,eAAe;EACnC,IAAI;EACJ,IAAI;GACF,UAAU,YAAY,OAAO,eAAe;EAC9C,QAAQ;GACN,MAAM,IAAI,MAAM,4BAA4B;EAC9C;EAEA,IAAI,QAAQ,WAAW,IACrB,MAAM,IAAI,MAAM,gDAAgD;EAGlE,KAAK,kBAAkB;CACzB;CAGA,IAAI,SAAS;EACX,OAAO;GAAC;GAAkB;GAAiB;EAAgB;CAC7D;CAEA,IAAI,WAAqC;EACvC,OAAO,KAAK,WAAW,CAAC,KAAK,QAAQ,IAAI,CAAC;CAC5C;CAEA,IAAI,WAAyC;EAC3C,OAAO,GACJ,wBAAwB;GACvB,SAAS;GACT,8BAA8B,CAAC,UAAU,CAAC;GAC1C,iBAAiB,KAAK,wBAAwB,KAAK,IAAI;EACzD,EACF;CACF;CAEA,MAAM,UAAyB;EAC7B,KAAK,UAAU,MAAM,6BAA6B,KAAK,eAAe;EAEtE,MAAM,iBAAiB,IAAI,WACzB,MAAM,OAAO,OAAO,UAAU,OAAO,KAAK,QAAQ,QAAQ,SAAS,CACrE;EAEA,KAAK,WAAW;GACd,SAAS,KAAK,QAAQ;GACtB,WAAW;GACX,QAAQ,KAAK;GACb,UAAU,CAAC,qBAAqB;EAClC;CACF;CAEA,MAAM,aAA4B;EAChC,KAAK,UAAU,KAAA;EACf,KAAK,WAAW,KAAA;CAClB;CAGA,MAAc,wBACZ,GAAG,QAC8C;EACjD,IAAI,CAAC,KAAK,SACR,MAAM,IAAI,MAAM,yBAAyB;EAG3C,MAAM,UAAyC,CAAC;EAEhD,KAAK,MAAM,SAAS,QAAQ;GAC1B,MAAM,cAAc,oBAAoB,CAAC,CAAC,OAAO,MAAM,WAAW;GAElE,mCAAmC,WAAW;GAc9C,MAAM,CAAC,uBAAuB,MAAM,KAAK,QAAQ,iBAAiB,CAChE,WAGF,CAAC;GAED,MAAM,YAAY,sBAAsB,KAAK,QAAQ;GACrD,IAAI,CAAC,WACH,MAAM,IAAI,MAAM,4BAA4B;GAY9C,MAAM,oBAAoB,gCAAgC;IACxD,GAAG;IACH,YAAY;KACV,GAAG,YAAY;MACd,KAAK,QAAQ,UAAU;IAC1B;GACF,CAA0D;GAE1D,QAAQ,KAAK,EACX,mBAAmB,mBAAmB,iBAAiB,EACzD,CAAC;EACH;EAEA,OAAO;CACT;AACF"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"solanaErrorCause.js","names":[],"sources":["../../../src/utils/solanaErrorCause.ts"],"sourcesContent":["export const safeStringifyBigInt = (value: unknown): string =>\n JSON.stringify(value, (_, v) => (typeof v === 'bigint' ? v.toString() : v))\n\nconst formatSolanaErr = (err: unknown): string =>\n typeof err === 'object' && err !== null\n ? safeStringifyBigInt(err)\n : String(err)\n\n/**\n * Carries the structured payload of a failed Solana RPC simulation or\n * confirmation so consumers can inspect `err` and `logs` directly from\n * the thrown `TransactionError`'s `cause`, without re-simulating.\n */\nexport class SolanaTransactionDetailsError extends Error {\n readonly err: unknown\n readonly logs: readonly string[] | null\n\n constructor(err: unknown, logs: readonly string[] | null = null) {\n super(formatSolanaErr(err))\n this.name = 'SolanaTransactionDetailsError'\n this.err = err\n this.logs = logs\n }\n}\n"],"mappings":";AAAA,MAAa,uBAAuB,UAClC,KAAK,UAAU,QAAQ,GAAG,MAAO,OAAO,MAAM,WAAW,EAAE,SAAS,IAAI,CAAE;AAE5E,MAAM,mBAAmB,QACvB,OAAO,QAAQ,YAAY,QAAQ,OAC/B,oBAAoB,GAAG,IACvB,OAAO,GAAG;;;;;;AAOhB,IAAa,gCAAb,cAAmD,MAAM;
|
|
1
|
+
{"version":3,"file":"solanaErrorCause.js","names":[],"sources":["../../../src/utils/solanaErrorCause.ts"],"sourcesContent":["export const safeStringifyBigInt = (value: unknown): string =>\n JSON.stringify(value, (_, v) => (typeof v === 'bigint' ? v.toString() : v))\n\nconst formatSolanaErr = (err: unknown): string =>\n typeof err === 'object' && err !== null\n ? safeStringifyBigInt(err)\n : String(err)\n\n/**\n * Carries the structured payload of a failed Solana RPC simulation or\n * confirmation so consumers can inspect `err` and `logs` directly from\n * the thrown `TransactionError`'s `cause`, without re-simulating.\n */\nexport class SolanaTransactionDetailsError extends Error {\n readonly err: unknown\n readonly logs: readonly string[] | null\n\n constructor(err: unknown, logs: readonly string[] | null = null) {\n super(formatSolanaErr(err))\n this.name = 'SolanaTransactionDetailsError'\n this.err = err\n this.logs = logs\n }\n}\n"],"mappings":";AAAA,MAAa,uBAAuB,UAClC,KAAK,UAAU,QAAQ,GAAG,MAAO,OAAO,MAAM,WAAW,EAAE,SAAS,IAAI,CAAE;AAE5E,MAAM,mBAAmB,QACvB,OAAO,QAAQ,YAAY,QAAQ,OAC/B,oBAAoB,GAAG,IACvB,OAAO,GAAG;;;;;;AAOhB,IAAa,gCAAb,cAAmD,MAAM;CAC9C;CACA;CAET,YAAY,KAAc,OAAiC,MAAM;EAC/D,MAAM,gBAAgB,GAAG,CAAC;EAC1B,KAAK,OAAO;EACZ,KAAK,MAAM;EACX,KAAK,OAAO;CACd;AACF"}
|
package/dist/esm/version.d.ts
CHANGED
package/dist/esm/version.js
CHANGED
package/dist/esm/version.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"version.js","names":[],"sources":["../../src/version.ts"],"sourcesContent":["export const name = '@lifi/sdk-provider-solana'\nexport const version = '0.0.0-preview-
|
|
1
|
+
{"version":3,"file":"version.js","names":[],"sources":["../../src/version.ts"],"sourcesContent":["export const name = '@lifi/sdk-provider-solana'\nexport const version = '0.0.0-preview-155bb7fe'\n"],"mappings":";AAAA,MAAa,OAAO;AACpB,MAAa,UAAU"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@lifi/sdk-provider-solana",
|
|
3
|
-
"version": "0.0.0-preview-
|
|
3
|
+
"version": "0.0.0-preview-155bb7fe",
|
|
4
4
|
"description": "LI.FI Solana SDK Provider for Any-to-Any Cross-Chain-Swap",
|
|
5
5
|
"homepage": "https://github.com/lifinance/sdk",
|
|
6
6
|
"bugs": {
|
|
@@ -28,7 +28,7 @@
|
|
|
28
28
|
"./package.json": "./package.json"
|
|
29
29
|
},
|
|
30
30
|
"dependencies": {
|
|
31
|
-
"@lifi/sdk": "0.0.0-preview-
|
|
31
|
+
"@lifi/sdk": "0.0.0-preview-155bb7fe",
|
|
32
32
|
"@solana/kit": "^8.6.0",
|
|
33
33
|
"@solana/wallet-standard-features": "^1.5.0",
|
|
34
34
|
"@wallet-standard/base": "^1.1.1"
|
|
@@ -30,16 +30,25 @@ export const parseSolanaErrors = async (
|
|
|
30
30
|
const userRejectionMessage =
|
|
31
31
|
/(^|\W)user\W+(has\W+)?(rejected|denied|cancell?ed)|\b(rejected|denied|cancell?ed)\W+by\W+(the\W+)?user\b/i
|
|
32
32
|
|
|
33
|
+
// Some wallets report a Cancel on the sign prompt only with this text (an
|
|
34
|
+
// Android in-app wallet). The whole message must match, so a longer error that
|
|
35
|
+
// starts with these words does not count.
|
|
36
|
+
const walletCancelMessage = /^transaction (was )?cancell?ed\.?$/i
|
|
37
|
+
|
|
33
38
|
/**
|
|
34
39
|
* The SDK calls the Wallet Standard features directly, so a wallet's own error
|
|
35
40
|
* arrives here unwrapped. Wallets report a rejection with the EIP-1193 code
|
|
36
|
-
* 4001 or only with a message.
|
|
37
|
-
*
|
|
41
|
+
* 4001 or only with a message. A wallet cancel is a rejection too: the prompt
|
|
42
|
+
* was open and the wallet sent nothing, as with `WalletSignTransactionError`.
|
|
43
|
+
* An `AbortError` is not a rejection: nothing says the user caused it. The
|
|
44
|
+
* SDK's own errors keep their code.
|
|
38
45
|
*/
|
|
39
46
|
const isUserRejection = (e: any): boolean =>
|
|
40
47
|
!(e instanceof BaseError) &&
|
|
41
48
|
(e.code === 4001 ||
|
|
42
|
-
(typeof e.message === 'string' &&
|
|
49
|
+
(typeof e.message === 'string' &&
|
|
50
|
+
(userRejectionMessage.test(e.message) ||
|
|
51
|
+
walletCancelMessage.test(e.message.trim()))))
|
|
43
52
|
|
|
44
53
|
const handleSpecificErrors = (e: any) => {
|
|
45
54
|
if (e.name === 'WalletSignTransactionError') {
|
package/src/version.ts
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
1
|
export const name = '@lifi/sdk-provider-solana'
|
|
2
|
-
export const version = '0.0.0-preview-
|
|
2
|
+
export const version = '0.0.0-preview-155bb7fe'
|