@argent/x-shared 1.48.1 → 1.48.2
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.
|
@@ -1 +1 @@
|
|
|
1
|
-
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const u=require("url-join"),a=require("../../../errors/swap.cjs"),p=require("
|
|
1
|
+
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const u=require("url-join"),a=require("../../../errors/swap.cjs"),p=require("../models/quote.model.cjs"),l=require("../utils/totalFee.cjs"),S=require("../models/trade.model.cjs"),i=require("../models/order.model.cjs"),d=require("../../../utils/url/urlWithQuery.cjs");class y{constructor(e,r){if(this.httpService=e,!r)throw new a.SwapError({code:"NO_SWAP_URL"});this.swapQuoteUrl=u(r,"/quote"),this.swapOrderUrl=u(r,"/order")}async getSwapQuoteForPay(e,r,o,n,t="USD"){const s=d.urlWithQuery(this.swapQuoteUrl,{accountAddress:n,currency:t,chain:"starknet",sellToken:e,buyToken:r,sellAmount:o});try{const c=await this.httpService.get(s);return await p.SwapQuoteResponseSchema.parseAsync(c)}catch(c){throw console.error(c),new a.SwapError({code:"INVALID_QUOTE_RESPONSE"})}}async getSwapTradeFromQuote(e,r,o){if(!r||!o)throw new a.SwapError({code:"INVALID_SWAP_TOKENS"});const{totalFee:n,totalFeeInCurrency:t,totalFeePercentage:s}=l.calculateTotalFee(e);return S.TradeSchema.parse({payToken:r,receiveToken:o,payAmount:e.sellAmount,receiveAmount:e.buyAmount,payAmountInCurrency:e.sellAmountInCurrency,receiveAmountInCurrency:e.buyAmountInCurrency,totalFee:n,totalFeeInCurrency:t,totalFeePercentage:s,expiresAt:e.expiresAt,expiresIn:e.expiresIn,route:e.routes[0],data:e.data})}async getSwapOrderFromTrade(e,r,o){const n=i.SwapOrderRequestSchema.parse({chain:"starknet",sellToken:r.payToken.address,buyToken:r.receiveToken.address,sellAmount:r.payAmount,buyAmount:r.receiveAmount,accountAddress:e,slippage:o/1e4,data:r.data});try{const t=await this.httpService.post(this.swapOrderUrl,{body:JSON.stringify(n),headers:{"Content-Type":"application/json"}});return await i.SwapOrderResponseSchema.parseAsync(t)}catch(t){throw console.error(t),new a.SwapError({code:"INVALID_SWAP_ORDER_RESPONSE"})}}}exports.SharedSwapService=y;
|
|
@@ -1,10 +1,10 @@
|
|
|
1
1
|
import p from "url-join";
|
|
2
2
|
import { SwapError as a } from "../../../errors/swap.js";
|
|
3
|
-
import {
|
|
4
|
-
import {
|
|
5
|
-
import {
|
|
6
|
-
import {
|
|
7
|
-
import {
|
|
3
|
+
import { SwapQuoteResponseSchema as i } from "../models/quote.model.js";
|
|
4
|
+
import { calculateTotalFee as u } from "../utils/totalFee.js";
|
|
5
|
+
import { TradeSchema as m } from "../models/trade.model.js";
|
|
6
|
+
import { SwapOrderRequestSchema as l, SwapOrderResponseSchema as S } from "../models/order.model.js";
|
|
7
|
+
import { urlWithQuery as y } from "../../../utils/url/urlWithQuery.js";
|
|
8
8
|
class _ {
|
|
9
9
|
constructor(e, r) {
|
|
10
10
|
if (this.httpService = e, !r)
|
|
@@ -12,7 +12,7 @@ class _ {
|
|
|
12
12
|
this.swapQuoteUrl = p(r, "/quote"), this.swapOrderUrl = p(r, "/order");
|
|
13
13
|
}
|
|
14
14
|
async getSwapQuoteForPay(e, r, o, n, t = "USD") {
|
|
15
|
-
const s =
|
|
15
|
+
const s = y(this.swapQuoteUrl, {
|
|
16
16
|
accountAddress: n,
|
|
17
17
|
currency: t,
|
|
18
18
|
chain: "starknet",
|
|
@@ -22,7 +22,7 @@ class _ {
|
|
|
22
22
|
});
|
|
23
23
|
try {
|
|
24
24
|
const c = await this.httpService.get(s);
|
|
25
|
-
return await
|
|
25
|
+
return await i.parseAsync(c);
|
|
26
26
|
} catch (c) {
|
|
27
27
|
throw console.error(c), new a({ code: "INVALID_QUOTE_RESPONSE" });
|
|
28
28
|
}
|
|
@@ -30,8 +30,8 @@ class _ {
|
|
|
30
30
|
async getSwapTradeFromQuote(e, r, o) {
|
|
31
31
|
if (!r || !o)
|
|
32
32
|
throw new a({ code: "INVALID_SWAP_TOKENS" });
|
|
33
|
-
const { totalFee: n, totalFeeInCurrency: t, totalFeePercentage: s } =
|
|
34
|
-
return
|
|
33
|
+
const { totalFee: n, totalFeeInCurrency: t, totalFeePercentage: s } = u(e);
|
|
34
|
+
return m.parse({
|
|
35
35
|
payToken: r,
|
|
36
36
|
receiveToken: o,
|
|
37
37
|
payAmount: e.sellAmount,
|
|
@@ -48,7 +48,7 @@ class _ {
|
|
|
48
48
|
});
|
|
49
49
|
}
|
|
50
50
|
async getSwapOrderFromTrade(e, r, o) {
|
|
51
|
-
const n =
|
|
51
|
+
const n = l.parse({
|
|
52
52
|
chain: "starknet",
|
|
53
53
|
sellToken: r.payToken.address,
|
|
54
54
|
buyToken: r.receiveToken.address,
|
|
@@ -65,7 +65,7 @@ class _ {
|
|
|
65
65
|
"Content-Type": "application/json"
|
|
66
66
|
}
|
|
67
67
|
});
|
|
68
|
-
return await
|
|
68
|
+
return await S.parseAsync(t);
|
|
69
69
|
} catch (t) {
|
|
70
70
|
throw console.error(t), new a({ code: "INVALID_SWAP_ORDER_RESPONSE" });
|
|
71
71
|
}
|