Skip to content

Commit e89ff31

Browse files
adapt buyWithFiat legacy function
1 parent cec95b0 commit e89ff31

File tree

4 files changed

+222
-128
lines changed

4 files changed

+222
-128
lines changed

packages/thirdweb/src/bridge/Onramp.ts

Lines changed: 5 additions & 60 deletions
Original file line numberDiff line numberDiff line change
@@ -3,37 +3,12 @@ import type { ThirdwebClient } from "../client/client.js";
33
import { getThirdwebBaseUrl } from "../utils/domains.js";
44
import { getClientFetch } from "../utils/fetch.js";
55
import { stringify } from "../utils/json.js";
6-
import type { BridgeAction } from "./types/BridgeAction.js";
6+
import type { RouteStep } from "./types/Route.js";
77
import type { Token } from "./types/Token.js";
88

99
// export status within the Onramp module
1010
export { status } from "./OnrampStatus.js";
1111

12-
// API-specific type for Transactions as returned by the Onramp prepare endpoint
13-
type ApiBridgeTransaction = {
14-
id: string;
15-
chainId: number;
16-
maxPriorityFeePerGas?: string;
17-
maxFeePerGas?: string;
18-
to: string;
19-
from?: string | null;
20-
value?: string;
21-
gas?: string;
22-
data?: string;
23-
type: "eip1559";
24-
action: BridgeAction;
25-
};
26-
27-
// Helper types based on OpenAPI spec for POST /v1/onramp/prepare response
28-
type OnrampStep = {
29-
originToken: Token;
30-
destinationToken: Token;
31-
transactions: ApiBridgeTransaction[];
32-
originAmount: string;
33-
destinationAmount: string;
34-
estimatedExecutionTimeMs: number;
35-
};
36-
3712
type OnrampIntent = {
3813
onramp: "stripe" | "coinbase" | "transak";
3914
chainId: number;
@@ -54,10 +29,11 @@ type OnrampPrepareQuoteResponseData = {
5429
link: string;
5530
currency: string;
5631
currencyAmount: number;
57-
destinationAmount: string;
32+
destinationAmount: bigint;
33+
destinationToken: Token;
5834
timestamp?: number;
5935
expiration?: number;
60-
steps: OnrampStep[];
36+
steps: RouteStep[];
6137
intent: OnrampIntent;
6238
};
6339

@@ -231,11 +207,6 @@ export async function prepare(
231207
transactions: step.transactions.map((tx) => ({
232208
...tx,
233209
value: tx.value ? BigInt(tx.value) : undefined,
234-
gas: tx.gas ? BigInt(tx.gas) : undefined,
235-
maxFeePerGas: tx.maxFeePerGas ? BigInt(tx.maxFeePerGas) : undefined,
236-
maxPriorityFeePerGas: tx.maxPriorityFeePerGas
237-
? BigInt(tx.maxPriorityFeePerGas)
238-
: undefined,
239210
})),
240211
}));
241212

@@ -269,31 +240,5 @@ export declare namespace prepare {
269240
excludeChainIds?: string | string[];
270241
};
271242

272-
export type Result = Omit<
273-
OnrampPrepareQuoteResponseData,
274-
"destinationAmount" | "steps" | "intent"
275-
> & {
276-
destinationAmount: bigint;
277-
steps: Array<
278-
Omit<
279-
OnrampStep,
280-
"originAmount" | "destinationAmount" | "transactions"
281-
> & {
282-
originAmount: bigint;
283-
destinationAmount: bigint;
284-
transactions: Array<
285-
Omit<
286-
ApiBridgeTransaction,
287-
"value" | "gas" | "maxFeePerGas" | "maxPriorityFeePerGas"
288-
> & {
289-
value?: bigint;
290-
gas?: bigint;
291-
maxFeePerGas?: bigint;
292-
maxPriorityFeePerGas?: bigint;
293-
}
294-
>;
295-
}
296-
>;
297-
intent: OnrampIntent;
298-
};
243+
export type Result = OnrampPrepareQuoteResponseData;
299244
}

packages/thirdweb/src/bridge/types/Quote.ts

Lines changed: 3 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,4 @@
1-
import type { Hex as ox__Hex } from "ox";
2-
import type { Chain } from "../../chains/types.js";
3-
import type { ThirdwebClient } from "../../client/client.js";
4-
import type { BridgeAction } from "./BridgeAction.js";
5-
import type { Token } from "./Token.js";
1+
import type { RouteQuoteStep, RouteStep } from "./Route.js";
62

73
export type Quote = {
84
/**
@@ -28,13 +24,7 @@ export type Quote = {
2824
/**
2925
* The steps required to complete the quote.
3026
*/
31-
steps: Array<{
32-
originToken: Token;
33-
destinationToken: Token;
34-
originAmount: bigint;
35-
destinationAmount: bigint;
36-
estimatedExecutionTimeMs: number;
37-
}>;
27+
steps: RouteQuoteStep[];
3828
};
3929

4030
export type PreparedQuote = {
@@ -65,27 +55,5 @@ export type PreparedQuote = {
6555
/**
6656
* A series of steps required to complete the quote, along with the transactions to execute in order.
6757
*/
68-
steps: Array<{
69-
originToken: Token;
70-
destinationToken: Token;
71-
originAmount: bigint;
72-
destinationAmount: bigint;
73-
estimatedExecutionTimeMs: number;
74-
transactions: Array<{
75-
data: ox__Hex.Hex;
76-
to: ox__Hex.Hex;
77-
value?: bigint | undefined;
78-
chainId: number;
79-
/**
80-
* The action this transaction performs. This can be "approval", "transfer", "buy", or "sell".
81-
*/
82-
action: BridgeAction;
83-
/**
84-
* The transaction ID, used for tracking purposes.
85-
*/
86-
id: ox__Hex.Hex;
87-
client: ThirdwebClient;
88-
chain: Chain;
89-
}>;
90-
}>;
58+
steps: RouteStep[];
9159
};
Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,45 @@
1+
import type { Hex as ox__Hex } from "ox";
2+
import type { Chain } from "../../chains/types.js";
3+
import type { ThirdwebClient } from "../../client/client.js";
4+
import type { BridgeAction } from "./BridgeAction.js";
15
import type { Token } from "./Token.js";
26

37
export type Route = {
48
originToken: Token;
59
destinationToken: Token;
610
};
11+
12+
export type RouteQuoteStep = {
13+
originToken: Token;
14+
destinationToken: Token;
15+
originAmount: bigint;
16+
destinationAmount: bigint;
17+
estimatedExecutionTimeMs: number;
18+
};
19+
20+
export type RouteStep = {
21+
originToken: Token;
22+
destinationToken: Token;
23+
originAmount: bigint;
24+
destinationAmount: bigint;
25+
estimatedExecutionTimeMs: number;
26+
transactions: RouteTransaction[];
27+
};
28+
29+
export type RouteTransaction = {
30+
data: ox__Hex.Hex;
31+
to: ox__Hex.Hex;
32+
value?: bigint | undefined;
33+
chainId: number;
34+
35+
/**
36+
* The action this transaction performs. This can be "approval", "transfer", "buy", or "sell".
37+
*/
38+
action: BridgeAction;
39+
/**
40+
* The transaction ID, used for tracking purposes.
41+
*/
42+
id: ox__Hex.Hex;
43+
client: ThirdwebClient;
44+
chain: Chain;
45+
};

0 commit comments

Comments
 (0)