Skip to content
This repository was archived by the owner on Aug 6, 2025. It is now read-only.
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 5 additions & 3 deletions src/features/gift/actors/giftMakerRootMachine.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { errors } from "@defuse-protocol/internal-utils"
import { errors, solverRelay } from "@defuse-protocol/internal-utils"

Check failure on line 1 in src/features/gift/actors/giftMakerRootMachine.ts

View workflow job for this annotation

GitHub Actions / test / test

Module '"@defuse-protocol/internal-utils"' has no exported member 'errors'.
import {
type ActorRefFrom,
type DoneActorEvent,
Expand All @@ -12,7 +12,6 @@
} from "xstate"
import type { SignerCredentials } from "../../../core/formatters"
import { logger } from "../../../logger"
import { waitForIntentSettlement } from "../../../sdk/solverRelay/waitForIntentSettlement"
import { emitEvent } from "../../../services/emitter"
import type { BaseTokenInfo, UnifiedTokenInfo } from "../../../types/base"
import type {
Expand Down Expand Up @@ -130,7 +129,10 @@
}: { input: { intentHashes: string[] }; signal: AbortSignal }) => {
const intentHash = input.intentHashes[0]
assert(intentHash, "intentHash is not defined")
return waitForIntentSettlement(signal, intentHash)
return solverRelay.waitForIntentSettlement({
signal,
intentHash,
})
}
),
savingGift: fromPromise(
Expand Down
21 changes: 14 additions & 7 deletions src/features/gift/actors/shared/giftClaimActor.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@
type PublishIntentsErr,
convertPublishIntentsToLegacyFormat,
} from "../../../../sdk/solverRelay/publishIntents"
import { waitForIntentSettlement } from "../../../../sdk/solverRelay/waitForIntentSettlement"
import { assert } from "../../../../utils/assert"
import { signGiftTakerMessage } from "../../utils/signGiftTakerMessage"
import type { GiftInfo } from "./getGiftInfo"
Expand Down Expand Up @@ -149,14 +148,22 @@
> => {
const intentHash = input.intentHashes[0]
assert(intentHash, "intentHash is not defined")
const result = await waitForIntentSettlement(signal, intentHash)
if (result.status === "NOT_FOUND_OR_NOT_VALID") {
return {
tag: "err" as const,
value: { reason: result.status },
try {
await solverRelay.waitForIntentSettlement({
signal,
intentHash,
})
return { tag: "ok" as const }
} catch (err) {
if (err instanceof solverRelay.IntentSettlementError) {

Check failure on line 158 in src/features/gift/actors/shared/giftClaimActor.ts

View workflow job for this annotation

GitHub Actions / test / test

Property 'IntentSettlementError' does not exist on type 'typeof index$1'.
return {
tag: "err" as const,
value: { reason: "NOT_FOUND_OR_NOT_VALID" },
}
}
// Optionally handle/log other error types here
throw err
}
return { tag: "ok" as const }
}
),
},
Expand Down
4 changes: 2 additions & 2 deletions src/features/gift/components/GiftTakerSuccessScreen.tsx
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
import { solverRelay } from "@defuse-protocol/internal-utils"
import { Button } from "@radix-ui/themes"
import { useQuery } from "@tanstack/react-query"
import {
computeTotalBalanceDifferentDecimals,
getUnderlyingBaseTokenInfos,
} from "src/utils/tokenUtils"
import { CopyButton } from "../../../components/IntentCard/CopyButton"
import { waitForIntentSettlement } from "../../../sdk/solverRelay/waitForIntentSettlement"
import type { RenderHostAppLink } from "../../../types/hostAppLink"
import { assert } from "../../../utils/assert"
import type { GiftInfo } from "../actors/shared/getGiftInfo"
Expand Down Expand Up @@ -38,7 +38,7 @@ export function GiftTakerSuccessScreen({
queryFn: async ({ signal }) => {
const intentHash = intentHashes[0]
assert(intentHash != null)
return waitForIntentSettlement(signal, intentHash)
return solverRelay.waitForIntentSettlement({ signal, intentHash })
},
})

Expand Down
24 changes: 14 additions & 10 deletions src/features/machines/intentStatusMachine.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import type { BridgeSDK } from "@defuse-protocol/bridge-sdk"
import { solverRelay } from "@defuse-protocol/internal-utils"
import {
type ActorRef,
type Snapshot,
Expand All @@ -11,10 +12,6 @@ import {
import { auroraEngineContractId } from "../../constants/aurora"
import { bridgeSDK } from "../../constants/bridgeSdk"
import { logger } from "../../logger"
import {
type IntentSettlementResult,
waitForIntentSettlement,
} from "../../sdk/solverRelay/waitForIntentSettlement"
import type {
BaseTokenInfo,
SupportedBridge,
Expand Down Expand Up @@ -61,8 +58,10 @@ export const intentStatusMachine = setup({
logger.error(params.error)
},
setSettlementResult: assign({
txHash: (_, settlementResult: IntentSettlementResult) =>
settlementResult.txHash,
txHash: (
_,
settlementResult: solverRelay.WaitForIntentSettlementReturnType
) => settlementResult.txHash,
}),
setBridgeTransactionResult: assign({
bridgeTransactionResult: (
Expand All @@ -79,8 +78,11 @@ export const intentStatusMachine = setup({
}: {
input: { intentHash: string }
signal: AbortSignal
}): Promise<IntentSettlementResult> =>
waitForIntentSettlement(signal, input.intentHash)
}): Promise<solverRelay.WaitForIntentSettlementReturnType> =>
solverRelay.waitForIntentSettlement({
signal,
intentHash: input.intentHash,
})
),
waitForBridgeActor: fromPromise(
async ({
Expand Down Expand Up @@ -116,8 +118,10 @@ export const intentStatusMachine = setup({
),
},
guards: {
isSettled: (_, settlementResult: IntentSettlementResult) =>
settlementResult.status === "SETTLED",
isSettled: (
_,
settlementResult: solverRelay.WaitForIntentSettlementReturnType
) => !!settlementResult.txHash,
isWithdraw: ({ context }) => {
return context.intentDescription.type === "withdraw"
},
Expand Down
4 changes: 2 additions & 2 deletions src/features/otcDesk/components/OtcTakerSuccessScreen.tsx
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import { solverRelay } from "@defuse-protocol/internal-utils"
import { Check as CheckIcon } from "@phosphor-icons/react"
import { Button } from "@radix-ui/themes"
import { useQuery } from "@tanstack/react-query"
import { CopyButton } from "src/components/IntentCard/CopyButton"
import { waitForIntentSettlement } from "../../../sdk/solverRelay/waitForIntentSettlement"
import type { BaseTokenInfo, UnifiedTokenInfo } from "../../../types/base"
import type { RenderHostAppLink } from "../../../types/hostAppLink"
import { assert } from "../../../utils/assert"
Expand Down Expand Up @@ -53,7 +53,7 @@ export function OtcTakerSuccessScreen({
queryFn: async ({ signal }) => {
const intentHash = intentHashes[0]
assert(intentHash != null)
return waitForIntentSettlement(signal, intentHash)
return solverRelay.waitForIntentSettlement({ signal, intentHash })
},
})

Expand Down
6 changes: 3 additions & 3 deletions src/features/otcDesk/utils/quoteUtils.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import type { solverRelay } from "@defuse-protocol/internal-utils"
import { Err, Ok, type Result } from "@thames/monads"
import { settings } from "../../../constants/settings"
import type { FailedQuote } from "../../../sdk/solverRelay/solverRelayHttpClient/types"
import { quoteWithLog } from "../../../sdk/solverRelay/utils/quoteWithLog"
import {
type AggregatedQuote,
Expand Down Expand Up @@ -52,8 +52,8 @@ function handleQuote(
return Err({ reason: "NO_QUOTES" })
}

const failedQuotes: FailedQuote[] = []
const validQuotes = []
const failedQuotes: solverRelay.FailedQuote[] = []
const validQuotes: solverRelay.Quote[] = []
for (const q of quotes) {
if (isFailedQuote(q)) {
failedQuotes.push(q)
Expand Down
14 changes: 8 additions & 6 deletions src/features/tokenMigration/machines/tokenMigrationMachine.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,6 @@ import { nearClient } from "../../../constants/nearClient"
import type { SignerCredentials } from "../../../core/formatters"
import { logger } from "../../../logger"
import { convertPublishIntentToLegacyFormat } from "../../../sdk/solverRelay/utils/parseFailedPublishError"
import {
type IntentSettlementResult,
waitForIntentSettlement,
} from "../../../sdk/solverRelay/waitForIntentSettlement"
import { getDepositedBalances } from "../../../services/defuseBalanceService"
import type { IntentsUserId } from "../../../types/intentsUserId"
import type { WalletSignatureResult } from "../../../types/walletMessage"
Expand All @@ -35,7 +31,7 @@ export const tokenMigrationMachine = setup({
signature: null | WalletSignatureResult
intentHash: null | string
error: null | string
intentStatus: null | IntentSettlementResult
intentStatus: null | solverRelay.WaitForIntentSettlementReturnType
},
},

Expand Down Expand Up @@ -68,7 +64,13 @@ export const tokenMigrationMachine = setup({
input,
signal,
}: { input: { intentHash: string }; signal: AbortSignal }) =>
waitForIntentSettlement(signal, input.intentHash)
solverRelay
.waitForIntentSettlement({ signal, intentHash: input.intentHash })
.then((result) => ({
...result,
status:
result.txHash != null ? "SETTLED" : "NOT_FOUND_OR_NOT_VALID",
}))
),
},

Expand Down
14 changes: 7 additions & 7 deletions src/sdk/aggregatedQuote/aggregateQuotes.test.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import type { solverRelay } from "@defuse-protocol/internal-utils"
import { describe, expect, it } from "vitest"
import { QuoteError } from "../solverRelay/errors/quote"
import type { Quote } from "../solverRelay/solverRelayHttpClient/types"
import { aggregateQuotes } from "./aggregateQuotes"
import { AggregatedQuoteError } from "./errors/aggregatedQuoteError"

Expand All @@ -12,15 +12,15 @@ describe("aggregateQuotes()", () => {

it("aggregates quotes correctly", async () => {
const quotes = await Promise.allSettled([
Promise.resolve<Quote>({
Promise.resolve<solverRelay.Quote>({
quote_hash: "q1",
defuse_asset_identifier_in: "token1",
defuse_asset_identifier_out: "tokenOut",
amount_in: "1000000", // 1.0 with 6 decimals
amount_out: "2000000", // 2.0 with 6 decimals
expiration_time: "2024-01-15T12:05:00.000Z",
}),
Promise.resolve<Quote>({
Promise.resolve<solverRelay.Quote>({
quote_hash: "q2",
defuse_asset_identifier_in: "token2",
defuse_asset_identifier_out: "tokenOut",
Expand Down Expand Up @@ -52,7 +52,7 @@ describe("aggregateQuotes()", () => {

it("continues with valid quotes even when some quotes have failed", async () => {
const quotes = await Promise.allSettled([
Promise.reject<Quote>(
Promise.reject<solverRelay.Quote>(
new QuoteError({
quote: {
type: "INSUFFICIENT_AMOUNT",
Expand All @@ -61,7 +61,7 @@ describe("aggregateQuotes()", () => {
quoteParams: defaultQuoteParams,
})
),
Promise.resolve<Quote>({
Promise.resolve<solverRelay.Quote>({
quote_hash: "q1",
defuse_asset_identifier_in: "token1",
defuse_asset_identifier_out: "token2",
Expand Down Expand Up @@ -100,7 +100,7 @@ describe("aggregateQuotes()", () => {

it("throws error when all quotes have failed", async () => {
const quotes = await Promise.allSettled([
Promise.reject<Quote>(
Promise.reject<solverRelay.Quote>(
new QuoteError({
quote: {
type: "INSUFFICIENT_AMOUNT" as const,
Expand All @@ -109,7 +109,7 @@ describe("aggregateQuotes()", () => {
quoteParams: defaultQuoteParams,
})
),
Promise.reject<Quote>(
Promise.reject<solverRelay.Quote>(
new QuoteError({
quote: null,
quoteParams: defaultQuoteParams,
Expand Down
28 changes: 14 additions & 14 deletions src/sdk/aggregatedQuote/getAggregatedQuoteExactIn.test.ts
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
import { solverRelay } from "@defuse-protocol/internal-utils"
import { afterEach, describe, expect, it, vi } from "vitest"
import type { BaseTokenInfo } from "../../types/base"
import { adjustDecimals } from "../../utils/tokenUtils"
import { QuoteError } from "../solverRelay/errors/quote"
import * as relayClient from "../solverRelay/solverRelayHttpClient"
import { AggregatedQuoteError } from "./errors/aggregatedQuoteError"
import { getAggregatedQuoteExactIn } from "./getAggregatedQuoteExactIn"

vi.spyOn(relayClient, "quote")
vi.spyOn(solverRelay, "quote")

const tokenInfo: BaseTokenInfo = {
defuseAssetId: "",
Expand Down Expand Up @@ -53,7 +53,7 @@ describe("getAggregatedQuoteExactIn()", () => {
waitMs: 0,
}

vi.mocked(relayClient.quote).mockImplementationOnce(async () => [
vi.mocked(solverRelay.quote).mockImplementationOnce(async () => [
{
quote_hash: "q1",
defuse_asset_identifier_in: "token1",
Expand All @@ -76,8 +76,8 @@ describe("getAggregatedQuoteExactIn()", () => {
wait_ms: 0,
}

expect(relayClient.quote).toHaveBeenCalledTimes(1)
expect(relayClient.quote).toHaveBeenCalledWith(
expect(solverRelay.quote).toHaveBeenCalledTimes(1)
expect(solverRelay.quote).toHaveBeenCalledWith(
quoteParams,
expect.any(Object)
)
Expand Down Expand Up @@ -107,7 +107,7 @@ describe("getAggregatedQuoteExactIn()", () => {
waitMs: 0,
}

vi.mocked(relayClient.quote)
vi.mocked(solverRelay.quote)
.mockImplementationOnce(async () => [
{
quote_hash: "q1",
Expand Down Expand Up @@ -150,12 +150,12 @@ describe("getAggregatedQuoteExactIn()", () => {
},
]

expect(relayClient.quote).toHaveBeenCalledTimes(2)
expect(relayClient.quote).toHaveBeenCalledWith(
expect(solverRelay.quote).toHaveBeenCalledTimes(2)
expect(solverRelay.quote).toHaveBeenCalledWith(
quoteParams[0],
expect.any(Object)
)
expect(relayClient.quote).toHaveBeenCalledWith(
expect(solverRelay.quote).toHaveBeenCalledWith(
quoteParams[1],
expect.any(Object)
)
Expand Down Expand Up @@ -183,7 +183,7 @@ describe("getAggregatedQuoteExactIn()", () => {
waitMs: 0,
}

vi.mocked(relayClient.quote).mockImplementationOnce(async () => [
vi.mocked(solverRelay.quote).mockImplementationOnce(async () => [
{
quote_hash: "q1",
defuse_asset_identifier_in: "token1",
Expand Down Expand Up @@ -244,7 +244,7 @@ describe("getAggregatedQuoteExactIn()", () => {
waitMs: 0,
}

vi.mocked(relayClient.quote)
vi.mocked(solverRelay.quote)
.mockImplementationOnce(async () => null)
.mockImplementationOnce(async () => [])

Expand Down Expand Up @@ -285,7 +285,7 @@ describe("getAggregatedQuoteExactIn()", () => {
},
]

vi.mocked(relayClient.quote)
vi.mocked(solverRelay.quote)
.mockImplementationOnce(async () => [
{
quote_hash: "q1",
Expand Down Expand Up @@ -331,7 +331,7 @@ describe("getAggregatedQuoteExactIn()", () => {
waitMs: 0,
}

vi.mocked(relayClient.quote).mockImplementationOnce(async () => [
vi.mocked(solverRelay.quote).mockImplementationOnce(async () => [
{
quote_hash: "q1",
defuse_asset_identifier_in: "token1",
Expand All @@ -346,7 +346,7 @@ describe("getAggregatedQuoteExactIn()", () => {
aggregatedQuoteParams: input,
})

expect(relayClient.quote).toHaveBeenCalledTimes(1)
expect(solverRelay.quote).toHaveBeenCalledTimes(1)
expect(result).toEqual({
expirationTime: expect.any(String),
quoteHashes: ["q1"],
Expand Down
Loading
Loading