@argent/x-shared 1.34.6 → 1.35.0
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/dist/bips-CP71ZN9a.js +1 -0
- package/dist/bips-zBtnMbia.mjs +114 -0
- package/dist/chains/starknet/address.d.ts +2 -2
- package/dist/errors/swap.d.ts +12 -0
- package/dist/features/swap/index.d.ts +3 -0
- package/dist/features/swap/models/index.d.ts +3 -0
- package/dist/features/swap/models/order.model.d.ts +48 -0
- package/dist/features/swap/models/quote.model.d.ts +82 -0
- package/dist/features/swap/models/trade.model.d.ts +186 -0
- package/dist/features/swap/services/implementation.d.ts +14 -0
- package/dist/features/swap/services/index.d.ts +2 -0
- package/dist/features/swap/services/interface.d.ts +8 -0
- package/dist/features/swap/services/order.mock.d.ts +7 -0
- package/dist/features/swap/services/quote.mock.d.ts +29 -0
- package/dist/features/swap/tests/token.mock.d.ts +2 -0
- package/dist/features/swap/tests/trade.mock.d.ts +2 -0
- package/dist/features/swap/tests/walletAccount.mock.d.ts +43 -0
- package/dist/features/swap/utils/index.d.ts +2 -0
- package/dist/features/swap/utils/slippage.d.ts +16 -0
- package/dist/features/swap/utils/totalFee.d.ts +5 -0
- package/dist/index.js +2 -2
- package/dist/index.mjs +1355 -1425
- package/dist/simulation.js +1 -1
- package/dist/simulation.mjs +81 -80
- package/dist/swap.d.ts +2 -0
- package/dist/swap.js +1 -0
- package/dist/swap.mjs +183 -0
- package/dist/transactionVersion-CACUj2ch.mjs +793 -0
- package/dist/transactionVersion-CaRQ5Df4.js +1 -0
- package/dist/utils/bips.d.ts +7 -0
- package/dist/utils/index.d.ts +1 -0
- package/dist/webToken.model-Cl4dvcmj.mjs +1881 -0
- package/dist/webToken.model-Dsd8Rd3e.js +1 -0
- package/package.json +8 -1
- package/dist/transactionVersion-CKz-zi84.js +0 -1
- package/dist/transactionVersion-cwkr7wat.mjs +0 -2665
|
@@ -0,0 +1 @@
|
|
|
1
|
+
"use strict";const a=require("./webToken.model-Dsd8Rd3e.js");require("starknet");require("lodash-es");require("@scure/base");require("zod");const c=18;function l({value:e,decimals:t}){if(t===0)return e.toString();const r=e<0n;e=r?-e:e;const n=e.toString().padStart(t,"0"),s=n.slice(0,-t)||"0",i=n.slice(-t).replace(/0+$/,"");return`${r?"-":""}${s}${i?`.${i}`:""}`}const d=(e,t)=>({decimals:t,value:t>=e.decimals?e.value*BigInt(10)**BigInt(t-e.decimals):e.value/BigInt(10)**BigInt(e.decimals-t)}),g=e=>{const t=e.value.toString().split("").reverse();let r=0;for(let s=0;s<t.length&&t[s]==="0";s++)r++;const n=e.decimals-r;return d(e,n)},v=(e,t)=>{const r=Math.max(e.decimals,t.decimals),[n,s]=[e,t].map(i=>d(i,r));return[n.value,s.value,r]},u=e=>(t,r)=>{const[n,s,i]=v(t,r);return{decimals:i,value:e(n,s,i)}},o=e=>(t,r)=>{const[n,s]=v(t,r);return e(n,s)},I=u((e,t)=>e+t),E=u((e,t)=>e-t),f=u((e,t,r)=>{if(t===BigInt(0))throw new Error("Division by zero is not allowed");return e*BigInt(10)**BigInt(r)/t}),h=(e,t)=>g({decimals:e.decimals+t.decimals,value:e.value*t.value}),b=u((e,t)=>{if(t===BigInt(0))throw new Error("Modulus by zero is not allowed");return e%t}),m=e=>({decimals:e.decimals,value:e.value>=BigInt(0)?e.value:-e.value}),B=o((e,t)=>e===t),y=o((e,t)=>e<t),A=o((e,t)=>e>t),D=o((e,t)=>e<=t),w=o((e,t)=>e>=t),C=(e,t)=>!B(e,t);function T(e){return l({value:e,decimals:c})}function q(e){return a.parseUnits(e,c)}function S(e){return l({value:e,decimals:c})}function p(e){return a.parseUnits(e,c)}function j(e){return m({value:e,decimals:0}).value}function U(e){return m(p(e))}function O(e,t){return{value:BigInt(e),decimals:t}}const P={value:1n,decimals:0},$=(e,t)=>{const r=new URLSearchParams(t),n=r.size?`?${r}`:"";return a.urlJoin(...a.ensureArray(e),n)};function L(e){const t={value:BigInt(e),decimals:2},r={value:BigInt(1e4),decimals:2};return f(t,r)}exports.DEFAULT_TOKEN_DECIMALS=c;exports.ONE=P;exports.abs=m;exports.absBigInt=j;exports.add=I;exports.bipsToPercent=L;exports.div=f;exports.eq=B;exports.formatCurrency=S;exports.formatEther=T;exports.formatUnits=l;exports.gt=A;exports.gte=w;exports.lt=y;exports.lte=D;exports.mod=b;exports.mul=h;exports.not=C;exports.parseCurrency=p;exports.parseCurrencyAbs=U;exports.parseEther=q;exports.sub=E;exports.toBigDecimal=O;exports.toFixedDecimals=d;exports.toTiniestPossibleDecimal=g;exports.urlWithQuery=$;
|
|
@@ -0,0 +1,114 @@
|
|
|
1
|
+
import { p as u, u as v, F as f } from "./webToken.model-Cl4dvcmj.mjs";
|
|
2
|
+
import "starknet";
|
|
3
|
+
import "lodash-es";
|
|
4
|
+
import "@scure/base";
|
|
5
|
+
import "zod";
|
|
6
|
+
const o = 18;
|
|
7
|
+
function l({ value: t, decimals: e }) {
|
|
8
|
+
if (e === 0)
|
|
9
|
+
return t.toString();
|
|
10
|
+
const s = t < 0n;
|
|
11
|
+
t = s ? -t : t;
|
|
12
|
+
const n = t.toString().padStart(e, "0"), r = n.slice(0, -e) || "0", a = n.slice(-e).replace(/0+$/, "");
|
|
13
|
+
return `${s ? "-" : ""}${r}${a ? `.${a}` : ""}`;
|
|
14
|
+
}
|
|
15
|
+
const d = (t, e) => ({
|
|
16
|
+
decimals: e,
|
|
17
|
+
value: e >= t.decimals ? t.value * BigInt(10) ** BigInt(e - t.decimals) : t.value / BigInt(10) ** BigInt(t.decimals - e)
|
|
18
|
+
}), p = (t) => {
|
|
19
|
+
const e = t.value.toString().split("").reverse();
|
|
20
|
+
let s = 0;
|
|
21
|
+
for (let r = 0; r < e.length && e[r] === "0"; r++)
|
|
22
|
+
s++;
|
|
23
|
+
const n = t.decimals - s;
|
|
24
|
+
return d(t, n);
|
|
25
|
+
}, m = (t, e) => {
|
|
26
|
+
const s = Math.max(t.decimals, e.decimals), [n, r] = [t, e].map((a) => d(a, s));
|
|
27
|
+
return [n.value, r.value, s];
|
|
28
|
+
}, c = (t) => (e, s) => {
|
|
29
|
+
const [n, r, a] = m(e, s);
|
|
30
|
+
return {
|
|
31
|
+
decimals: a,
|
|
32
|
+
value: t(n, r, a)
|
|
33
|
+
};
|
|
34
|
+
}, i = (t) => (e, s) => {
|
|
35
|
+
const [n, r] = m(e, s);
|
|
36
|
+
return t(n, r);
|
|
37
|
+
}, E = c((t, e) => t + e), S = c((t, e) => t - e), B = c((t, e, s) => {
|
|
38
|
+
if (e === BigInt(0))
|
|
39
|
+
throw new Error("Division by zero is not allowed");
|
|
40
|
+
return t * BigInt(10) ** BigInt(s) / e;
|
|
41
|
+
}), b = (t, e) => p({
|
|
42
|
+
decimals: t.decimals + e.decimals,
|
|
43
|
+
value: t.value * e.value
|
|
44
|
+
}), $ = c((t, e) => {
|
|
45
|
+
if (e === BigInt(0))
|
|
46
|
+
throw new Error("Modulus by zero is not allowed");
|
|
47
|
+
return t % e;
|
|
48
|
+
}), g = (t) => ({
|
|
49
|
+
decimals: t.decimals,
|
|
50
|
+
value: t.value >= BigInt(0) ? t.value : -t.value
|
|
51
|
+
}), I = i((t, e) => t === e), C = i((t, e) => t < e), O = i((t, e) => t > e), x = i((t, e) => t <= e), P = i((t, e) => t >= e), T = (t, e) => !I(t, e);
|
|
52
|
+
function U(t) {
|
|
53
|
+
return l({ value: t, decimals: o });
|
|
54
|
+
}
|
|
55
|
+
function q(t) {
|
|
56
|
+
return u(t, o);
|
|
57
|
+
}
|
|
58
|
+
function z(t) {
|
|
59
|
+
return l({ value: t, decimals: o });
|
|
60
|
+
}
|
|
61
|
+
function h(t) {
|
|
62
|
+
return u(t, o);
|
|
63
|
+
}
|
|
64
|
+
function F(t) {
|
|
65
|
+
return g({ value: t, decimals: 0 }).value;
|
|
66
|
+
}
|
|
67
|
+
function L(t) {
|
|
68
|
+
return g(h(t));
|
|
69
|
+
}
|
|
70
|
+
function M(t, e) {
|
|
71
|
+
return {
|
|
72
|
+
value: BigInt(t),
|
|
73
|
+
decimals: e
|
|
74
|
+
};
|
|
75
|
+
}
|
|
76
|
+
const k = { value: 1n, decimals: 0 }, N = (t, e) => {
|
|
77
|
+
const s = new URLSearchParams(e), n = s.size ? `?${s}` : "";
|
|
78
|
+
return v(...f(t), n);
|
|
79
|
+
};
|
|
80
|
+
function _(t) {
|
|
81
|
+
const e = { value: BigInt(t), decimals: 2 }, s = {
|
|
82
|
+
value: BigInt(1e4),
|
|
83
|
+
decimals: 2
|
|
84
|
+
};
|
|
85
|
+
return B(e, s);
|
|
86
|
+
}
|
|
87
|
+
export {
|
|
88
|
+
o as D,
|
|
89
|
+
k as O,
|
|
90
|
+
g as a,
|
|
91
|
+
F as b,
|
|
92
|
+
E as c,
|
|
93
|
+
B as d,
|
|
94
|
+
I as e,
|
|
95
|
+
z as f,
|
|
96
|
+
U as g,
|
|
97
|
+
l as h,
|
|
98
|
+
O as i,
|
|
99
|
+
P as j,
|
|
100
|
+
x as k,
|
|
101
|
+
C as l,
|
|
102
|
+
$ as m,
|
|
103
|
+
b as n,
|
|
104
|
+
T as o,
|
|
105
|
+
h as p,
|
|
106
|
+
L as q,
|
|
107
|
+
q as r,
|
|
108
|
+
S as s,
|
|
109
|
+
M as t,
|
|
110
|
+
d as u,
|
|
111
|
+
p as v,
|
|
112
|
+
N as w,
|
|
113
|
+
_ as x
|
|
114
|
+
};
|
|
@@ -18,5 +18,5 @@ export declare const formatFullAddress: (address: string) => string;
|
|
|
18
18
|
export declare const isEqualAddress: (a?: string, b?: string) => boolean;
|
|
19
19
|
export declare const isZeroAddress: (address: string) => boolean;
|
|
20
20
|
export declare const includesAddress: (needle: string, haystack?: string[]) => boolean;
|
|
21
|
-
export declare const formatTruncatedSignerKey: (
|
|
22
|
-
export declare const formatTruncatedString: (
|
|
21
|
+
export declare const formatTruncatedSignerKey: (signerKey: string) => string;
|
|
22
|
+
export declare const formatTruncatedString: (string: string, targetLength: number) => string;
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import { BaseError, BaseErrorPayload } from './baseErrors';
|
|
2
|
+
export declare enum SWAP_ERROR_MESSAGE {
|
|
3
|
+
NO_SWAP_URL = "Swap base url not provided",
|
|
4
|
+
INVALID_QUOTE_RESPONSE = "Invalid quote response",
|
|
5
|
+
NO_NETWORK_FOR_SWAP = "Network for swap not found",
|
|
6
|
+
INVALID_SWAP_TOKENS = "Invalid swap tokens",
|
|
7
|
+
INVALID_SWAP_ORDER_RESPONSE = "Invalid swap order response"
|
|
8
|
+
}
|
|
9
|
+
export type SwapErrorMessage = keyof typeof SWAP_ERROR_MESSAGE;
|
|
10
|
+
export declare class SwapError extends BaseError<SwapErrorMessage> {
|
|
11
|
+
constructor(payload: BaseErrorPayload<SwapErrorMessage>);
|
|
12
|
+
}
|
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
import { z } from 'zod';
|
|
2
|
+
export declare const SwapOrderRequestSchema: z.ZodObject<{
|
|
3
|
+
chain: z.ZodLiteral<"starknet">;
|
|
4
|
+
sellToken: z.ZodEffects<z.ZodPipeline<z.ZodString, z.ZodEffects<z.ZodString, string, string>>, `0x${string}`, string>;
|
|
5
|
+
buyToken: z.ZodEffects<z.ZodPipeline<z.ZodString, z.ZodEffects<z.ZodString, string, string>>, `0x${string}`, string>;
|
|
6
|
+
sellAmount: z.ZodString;
|
|
7
|
+
buyAmount: z.ZodString;
|
|
8
|
+
accountAddress: z.ZodEffects<z.ZodPipeline<z.ZodString, z.ZodEffects<z.ZodString, string, string>>, `0x${string}`, string>;
|
|
9
|
+
slippage: z.ZodEffects<z.ZodNumber, string, number>;
|
|
10
|
+
data: z.ZodObject<{
|
|
11
|
+
quoteId: z.ZodString;
|
|
12
|
+
}, "strip", z.ZodTypeAny, {
|
|
13
|
+
quoteId: string;
|
|
14
|
+
}, {
|
|
15
|
+
quoteId: string;
|
|
16
|
+
}>;
|
|
17
|
+
}, "strip", z.ZodTypeAny, {
|
|
18
|
+
chain: "starknet";
|
|
19
|
+
accountAddress: `0x${string}`;
|
|
20
|
+
data: {
|
|
21
|
+
quoteId: string;
|
|
22
|
+
};
|
|
23
|
+
sellToken: `0x${string}`;
|
|
24
|
+
buyToken: `0x${string}`;
|
|
25
|
+
sellAmount: string;
|
|
26
|
+
buyAmount: string;
|
|
27
|
+
slippage: string;
|
|
28
|
+
}, {
|
|
29
|
+
chain: "starknet";
|
|
30
|
+
accountAddress: string;
|
|
31
|
+
data: {
|
|
32
|
+
quoteId: string;
|
|
33
|
+
};
|
|
34
|
+
sellToken: string;
|
|
35
|
+
buyToken: string;
|
|
36
|
+
sellAmount: string;
|
|
37
|
+
buyAmount: string;
|
|
38
|
+
slippage: number;
|
|
39
|
+
}>;
|
|
40
|
+
export type SwapOrderRequest = z.infer<typeof SwapOrderRequestSchema>;
|
|
41
|
+
export declare const SwapOrderResponseSchema: z.ZodObject<{
|
|
42
|
+
calls: z.ZodArray<z.ZodType<import('starknet').Call, z.ZodTypeDef, import('starknet').Call>, "many">;
|
|
43
|
+
}, "strip", z.ZodTypeAny, {
|
|
44
|
+
calls: import('starknet').Call[];
|
|
45
|
+
}, {
|
|
46
|
+
calls: import('starknet').Call[];
|
|
47
|
+
}>;
|
|
48
|
+
export type SwapOrderResponse = z.infer<typeof SwapOrderResponseSchema>;
|
|
@@ -0,0 +1,82 @@
|
|
|
1
|
+
import { z } from 'zod';
|
|
2
|
+
export declare const SwapDataSchema: z.ZodObject<{
|
|
3
|
+
quoteId: z.ZodString;
|
|
4
|
+
}, "strip", z.ZodTypeAny, {
|
|
5
|
+
quoteId: string;
|
|
6
|
+
}, {
|
|
7
|
+
quoteId: string;
|
|
8
|
+
}>;
|
|
9
|
+
export declare const SwapQuoteRouteSchema: z.ZodSchema;
|
|
10
|
+
export type SwapQuoteRoute = z.infer<typeof SwapQuoteRouteSchema>;
|
|
11
|
+
export declare const SwapQuoteResponseSchema: z.ZodObject<{
|
|
12
|
+
sellToken: z.ZodEffects<z.ZodPipeline<z.ZodString, z.ZodEffects<z.ZodString, string, string>>, `0x${string}`, string>;
|
|
13
|
+
sellAmount: z.ZodString;
|
|
14
|
+
sellAmountInCurrency: z.ZodString;
|
|
15
|
+
buyToken: z.ZodEffects<z.ZodPipeline<z.ZodString, z.ZodEffects<z.ZodString, string, string>>, `0x${string}`, string>;
|
|
16
|
+
buyAmount: z.ZodString;
|
|
17
|
+
buyAmountInCurrency: z.ZodString;
|
|
18
|
+
expiresAt: z.ZodNumber;
|
|
19
|
+
expiresIn: z.ZodNumber;
|
|
20
|
+
dexCount: z.ZodNumber;
|
|
21
|
+
routes: z.ZodArray<z.ZodType<any, z.ZodTypeDef, any>, "many">;
|
|
22
|
+
providerName: z.ZodString;
|
|
23
|
+
providerFee: z.ZodString;
|
|
24
|
+
providerFeeInCurrency: z.ZodString;
|
|
25
|
+
providerFeePercentage: z.ZodNumber;
|
|
26
|
+
argentFee: z.ZodString;
|
|
27
|
+
argentFeeInCurrency: z.ZodString;
|
|
28
|
+
argentFeePercentage: z.ZodNumber;
|
|
29
|
+
feeToken: z.ZodEffects<z.ZodPipeline<z.ZodString, z.ZodEffects<z.ZodString, string, string>>, `0x${string}`, string>;
|
|
30
|
+
data: z.ZodObject<{
|
|
31
|
+
quoteId: z.ZodString;
|
|
32
|
+
}, "strip", z.ZodTypeAny, {
|
|
33
|
+
quoteId: string;
|
|
34
|
+
}, {
|
|
35
|
+
quoteId: string;
|
|
36
|
+
}>;
|
|
37
|
+
}, "strip", z.ZodTypeAny, {
|
|
38
|
+
data: {
|
|
39
|
+
quoteId: string;
|
|
40
|
+
};
|
|
41
|
+
feeToken: `0x${string}`;
|
|
42
|
+
sellToken: `0x${string}`;
|
|
43
|
+
buyToken: `0x${string}`;
|
|
44
|
+
routes: any[];
|
|
45
|
+
sellAmount: string;
|
|
46
|
+
sellAmountInCurrency: string;
|
|
47
|
+
buyAmount: string;
|
|
48
|
+
buyAmountInCurrency: string;
|
|
49
|
+
expiresAt: number;
|
|
50
|
+
expiresIn: number;
|
|
51
|
+
dexCount: number;
|
|
52
|
+
providerName: string;
|
|
53
|
+
providerFee: string;
|
|
54
|
+
providerFeeInCurrency: string;
|
|
55
|
+
providerFeePercentage: number;
|
|
56
|
+
argentFee: string;
|
|
57
|
+
argentFeeInCurrency: string;
|
|
58
|
+
argentFeePercentage: number;
|
|
59
|
+
}, {
|
|
60
|
+
data: {
|
|
61
|
+
quoteId: string;
|
|
62
|
+
};
|
|
63
|
+
feeToken: string;
|
|
64
|
+
sellToken: string;
|
|
65
|
+
buyToken: string;
|
|
66
|
+
routes: any[];
|
|
67
|
+
sellAmount: string;
|
|
68
|
+
sellAmountInCurrency: string;
|
|
69
|
+
buyAmount: string;
|
|
70
|
+
buyAmountInCurrency: string;
|
|
71
|
+
expiresAt: number;
|
|
72
|
+
expiresIn: number;
|
|
73
|
+
dexCount: number;
|
|
74
|
+
providerName: string;
|
|
75
|
+
providerFee: string;
|
|
76
|
+
providerFeeInCurrency: string;
|
|
77
|
+
providerFeePercentage: number;
|
|
78
|
+
argentFee: string;
|
|
79
|
+
argentFeeInCurrency: string;
|
|
80
|
+
argentFeePercentage: number;
|
|
81
|
+
}>;
|
|
82
|
+
export type SwapQuoteResponse = z.infer<typeof SwapQuoteResponseSchema>;
|
|
@@ -0,0 +1,186 @@
|
|
|
1
|
+
import { z } from 'zod';
|
|
2
|
+
export declare enum TradeType {
|
|
3
|
+
EXACT_PAY = "EXACT_PAY",
|
|
4
|
+
EXACT_RECEIVE = "EXACT_RECEIVE"
|
|
5
|
+
}
|
|
6
|
+
export declare const TradeTypeSchema: z.ZodNativeEnum<typeof TradeType>;
|
|
7
|
+
export declare const TradeSchema: z.ZodObject<{
|
|
8
|
+
payToken: z.ZodObject<z.objectUtil.extendShape<{
|
|
9
|
+
address: z.ZodEffects<z.ZodPipeline<z.ZodString, z.ZodEffects<z.ZodString, string, string>>, `0x${string}`, string>;
|
|
10
|
+
networkId: z.ZodString;
|
|
11
|
+
}, {
|
|
12
|
+
id: z.ZodOptional<z.ZodNumber>;
|
|
13
|
+
name: z.ZodOptional<z.ZodString>;
|
|
14
|
+
symbol: z.ZodOptional<z.ZodString>;
|
|
15
|
+
decimals: z.ZodOptional<z.ZodNumber>;
|
|
16
|
+
iconUrl: z.ZodUnion<[z.ZodOptional<z.ZodString>, z.ZodLiteral<"">]>;
|
|
17
|
+
pricingId: z.ZodOptional<z.ZodNumber>;
|
|
18
|
+
category: z.ZodOptional<z.ZodString>;
|
|
19
|
+
dappId: z.ZodOptional<z.ZodString>;
|
|
20
|
+
brandColor: z.ZodOptional<z.ZodString>;
|
|
21
|
+
}>, "strip", z.ZodTypeAny, {
|
|
22
|
+
address: `0x${string}`;
|
|
23
|
+
networkId: string;
|
|
24
|
+
symbol?: string | undefined;
|
|
25
|
+
name?: string | undefined;
|
|
26
|
+
decimals?: number | undefined;
|
|
27
|
+
dappId?: string | undefined;
|
|
28
|
+
brandColor?: string | undefined;
|
|
29
|
+
id?: number | undefined;
|
|
30
|
+
iconUrl?: string | undefined;
|
|
31
|
+
category?: string | undefined;
|
|
32
|
+
pricingId?: number | undefined;
|
|
33
|
+
}, {
|
|
34
|
+
address: string;
|
|
35
|
+
networkId: string;
|
|
36
|
+
symbol?: string | undefined;
|
|
37
|
+
name?: string | undefined;
|
|
38
|
+
decimals?: number | undefined;
|
|
39
|
+
dappId?: string | undefined;
|
|
40
|
+
brandColor?: string | undefined;
|
|
41
|
+
id?: number | undefined;
|
|
42
|
+
iconUrl?: string | undefined;
|
|
43
|
+
category?: string | undefined;
|
|
44
|
+
pricingId?: number | undefined;
|
|
45
|
+
}>;
|
|
46
|
+
receiveToken: z.ZodObject<z.objectUtil.extendShape<{
|
|
47
|
+
address: z.ZodEffects<z.ZodPipeline<z.ZodString, z.ZodEffects<z.ZodString, string, string>>, `0x${string}`, string>;
|
|
48
|
+
networkId: z.ZodString;
|
|
49
|
+
}, {
|
|
50
|
+
id: z.ZodOptional<z.ZodNumber>;
|
|
51
|
+
name: z.ZodOptional<z.ZodString>;
|
|
52
|
+
symbol: z.ZodOptional<z.ZodString>;
|
|
53
|
+
decimals: z.ZodOptional<z.ZodNumber>;
|
|
54
|
+
iconUrl: z.ZodUnion<[z.ZodOptional<z.ZodString>, z.ZodLiteral<"">]>;
|
|
55
|
+
pricingId: z.ZodOptional<z.ZodNumber>;
|
|
56
|
+
category: z.ZodOptional<z.ZodString>;
|
|
57
|
+
dappId: z.ZodOptional<z.ZodString>;
|
|
58
|
+
brandColor: z.ZodOptional<z.ZodString>;
|
|
59
|
+
}>, "strip", z.ZodTypeAny, {
|
|
60
|
+
address: `0x${string}`;
|
|
61
|
+
networkId: string;
|
|
62
|
+
symbol?: string | undefined;
|
|
63
|
+
name?: string | undefined;
|
|
64
|
+
decimals?: number | undefined;
|
|
65
|
+
dappId?: string | undefined;
|
|
66
|
+
brandColor?: string | undefined;
|
|
67
|
+
id?: number | undefined;
|
|
68
|
+
iconUrl?: string | undefined;
|
|
69
|
+
category?: string | undefined;
|
|
70
|
+
pricingId?: number | undefined;
|
|
71
|
+
}, {
|
|
72
|
+
address: string;
|
|
73
|
+
networkId: string;
|
|
74
|
+
symbol?: string | undefined;
|
|
75
|
+
name?: string | undefined;
|
|
76
|
+
decimals?: number | undefined;
|
|
77
|
+
dappId?: string | undefined;
|
|
78
|
+
brandColor?: string | undefined;
|
|
79
|
+
id?: number | undefined;
|
|
80
|
+
iconUrl?: string | undefined;
|
|
81
|
+
category?: string | undefined;
|
|
82
|
+
pricingId?: number | undefined;
|
|
83
|
+
}>;
|
|
84
|
+
tradeType: z.ZodDefault<z.ZodNativeEnum<typeof TradeType>>;
|
|
85
|
+
payAmount: z.ZodString;
|
|
86
|
+
receiveAmount: z.ZodString;
|
|
87
|
+
payAmountInCurrency: z.ZodString;
|
|
88
|
+
receiveAmountInCurrency: z.ZodString;
|
|
89
|
+
totalFee: z.ZodString;
|
|
90
|
+
totalFeeInCurrency: z.ZodOptional<z.ZodString>;
|
|
91
|
+
totalFeePercentage: z.ZodNumber;
|
|
92
|
+
expiresAt: z.ZodNumber;
|
|
93
|
+
expiresIn: z.ZodNumber;
|
|
94
|
+
route: z.ZodType<any, z.ZodTypeDef, any>;
|
|
95
|
+
data: z.ZodObject<{
|
|
96
|
+
quoteId: z.ZodString;
|
|
97
|
+
}, "strip", z.ZodTypeAny, {
|
|
98
|
+
quoteId: string;
|
|
99
|
+
}, {
|
|
100
|
+
quoteId: string;
|
|
101
|
+
}>;
|
|
102
|
+
}, "strip", z.ZodTypeAny, {
|
|
103
|
+
data: {
|
|
104
|
+
quoteId: string;
|
|
105
|
+
};
|
|
106
|
+
expiresAt: number;
|
|
107
|
+
expiresIn: number;
|
|
108
|
+
payToken: {
|
|
109
|
+
address: `0x${string}`;
|
|
110
|
+
networkId: string;
|
|
111
|
+
symbol?: string | undefined;
|
|
112
|
+
name?: string | undefined;
|
|
113
|
+
decimals?: number | undefined;
|
|
114
|
+
dappId?: string | undefined;
|
|
115
|
+
brandColor?: string | undefined;
|
|
116
|
+
id?: number | undefined;
|
|
117
|
+
iconUrl?: string | undefined;
|
|
118
|
+
category?: string | undefined;
|
|
119
|
+
pricingId?: number | undefined;
|
|
120
|
+
};
|
|
121
|
+
receiveToken: {
|
|
122
|
+
address: `0x${string}`;
|
|
123
|
+
networkId: string;
|
|
124
|
+
symbol?: string | undefined;
|
|
125
|
+
name?: string | undefined;
|
|
126
|
+
decimals?: number | undefined;
|
|
127
|
+
dappId?: string | undefined;
|
|
128
|
+
brandColor?: string | undefined;
|
|
129
|
+
id?: number | undefined;
|
|
130
|
+
iconUrl?: string | undefined;
|
|
131
|
+
category?: string | undefined;
|
|
132
|
+
pricingId?: number | undefined;
|
|
133
|
+
};
|
|
134
|
+
tradeType: TradeType;
|
|
135
|
+
payAmount: string;
|
|
136
|
+
receiveAmount: string;
|
|
137
|
+
payAmountInCurrency: string;
|
|
138
|
+
receiveAmountInCurrency: string;
|
|
139
|
+
totalFee: string;
|
|
140
|
+
totalFeePercentage: number;
|
|
141
|
+
totalFeeInCurrency?: string | undefined;
|
|
142
|
+
route?: any;
|
|
143
|
+
}, {
|
|
144
|
+
data: {
|
|
145
|
+
quoteId: string;
|
|
146
|
+
};
|
|
147
|
+
expiresAt: number;
|
|
148
|
+
expiresIn: number;
|
|
149
|
+
payToken: {
|
|
150
|
+
address: string;
|
|
151
|
+
networkId: string;
|
|
152
|
+
symbol?: string | undefined;
|
|
153
|
+
name?: string | undefined;
|
|
154
|
+
decimals?: number | undefined;
|
|
155
|
+
dappId?: string | undefined;
|
|
156
|
+
brandColor?: string | undefined;
|
|
157
|
+
id?: number | undefined;
|
|
158
|
+
iconUrl?: string | undefined;
|
|
159
|
+
category?: string | undefined;
|
|
160
|
+
pricingId?: number | undefined;
|
|
161
|
+
};
|
|
162
|
+
receiveToken: {
|
|
163
|
+
address: string;
|
|
164
|
+
networkId: string;
|
|
165
|
+
symbol?: string | undefined;
|
|
166
|
+
name?: string | undefined;
|
|
167
|
+
decimals?: number | undefined;
|
|
168
|
+
dappId?: string | undefined;
|
|
169
|
+
brandColor?: string | undefined;
|
|
170
|
+
id?: number | undefined;
|
|
171
|
+
iconUrl?: string | undefined;
|
|
172
|
+
category?: string | undefined;
|
|
173
|
+
pricingId?: number | undefined;
|
|
174
|
+
};
|
|
175
|
+
payAmount: string;
|
|
176
|
+
receiveAmount: string;
|
|
177
|
+
payAmountInCurrency: string;
|
|
178
|
+
receiveAmountInCurrency: string;
|
|
179
|
+
totalFee: string;
|
|
180
|
+
totalFeePercentage: number;
|
|
181
|
+
tradeType?: TradeType | undefined;
|
|
182
|
+
totalFeeInCurrency?: string | undefined;
|
|
183
|
+
route?: any;
|
|
184
|
+
}>;
|
|
185
|
+
export type Trade = z.infer<typeof TradeSchema>;
|
|
186
|
+
export type TradeAmounts = Pick<Trade, "payAmount" | "receiveAmount">;
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import { Address } from '../../../chains';
|
|
2
|
+
import { SwapOrderResponse, SwapQuoteResponse, Trade } from '../models';
|
|
3
|
+
import { IHttpService } from '../../../http';
|
|
4
|
+
import { WebToken } from '../../../tokens/service/types/webToken.model';
|
|
5
|
+
import { ISharedSwapService } from './interface';
|
|
6
|
+
export declare class SharedSwapService implements ISharedSwapService {
|
|
7
|
+
private readonly httpService;
|
|
8
|
+
swapQuoteUrl: string;
|
|
9
|
+
swapOrderUrl: string;
|
|
10
|
+
constructor(httpService: IHttpService, swapBaseUrl?: string);
|
|
11
|
+
getSwapQuoteForPay(payTokenAddress: Address, receiveTokenAddress: Address, payAmount: string, accountAddress: Address, currency?: string): Promise<SwapQuoteResponse>;
|
|
12
|
+
getSwapTradeFromQuote(quote: SwapQuoteResponse, payToken: WebToken, receiveToken: WebToken): Promise<Trade>;
|
|
13
|
+
getSwapOrderFromTrade(accountAddress: string, trade: Trade, userSlippageTolerance: number): Promise<SwapOrderResponse>;
|
|
14
|
+
}
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import { Address } from '../../../chains';
|
|
2
|
+
import { SwapQuoteResponse, Trade, SwapOrderResponse } from '../models';
|
|
3
|
+
import { WebToken } from '../../../tokens/service/types/webToken.model';
|
|
4
|
+
export interface ISharedSwapService {
|
|
5
|
+
getSwapQuoteForPay: (payTokenAddress: Address, receiveTokenAddress: Address, payAmount: string, accountAddress: Address) => Promise<SwapQuoteResponse>;
|
|
6
|
+
getSwapTradeFromQuote: (quote: SwapQuoteResponse, payToken: WebToken, receiveToken: WebToken) => Promise<Trade>;
|
|
7
|
+
getSwapOrderFromTrade: (accountAddress: Address, trade: Trade, userSlippage: number) => Promise<SwapOrderResponse>;
|
|
8
|
+
}
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
export declare const sampleQuoteJson: {
|
|
2
|
+
sellToken: string;
|
|
3
|
+
sellAmount: string;
|
|
4
|
+
sellAmountInCurrency: string;
|
|
5
|
+
buyToken: string;
|
|
6
|
+
buyAmount: string;
|
|
7
|
+
buyAmountInCurrency: string;
|
|
8
|
+
expiresAt: number;
|
|
9
|
+
expiresIn: number;
|
|
10
|
+
dexCount: number;
|
|
11
|
+
routes: {
|
|
12
|
+
name: string;
|
|
13
|
+
percent: number;
|
|
14
|
+
sellToken: string;
|
|
15
|
+
buyToken: string;
|
|
16
|
+
routes: never[];
|
|
17
|
+
}[];
|
|
18
|
+
providerName: string;
|
|
19
|
+
providerFee: string;
|
|
20
|
+
providerFeeInCurrency: string;
|
|
21
|
+
providerFeePercentage: number;
|
|
22
|
+
argentFee: string;
|
|
23
|
+
argentFeeInCurrency: string;
|
|
24
|
+
argentFeePercentage: number;
|
|
25
|
+
feeToken: string;
|
|
26
|
+
data: {
|
|
27
|
+
quoteId: string;
|
|
28
|
+
};
|
|
29
|
+
};
|
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
declare const defaultWalletAccount: {
|
|
2
|
+
name: string;
|
|
3
|
+
address: string;
|
|
4
|
+
network: {
|
|
5
|
+
id: string;
|
|
6
|
+
name: string;
|
|
7
|
+
chainId: string;
|
|
8
|
+
possibleFeeTokenAddresses: string[];
|
|
9
|
+
rpcUrl: string;
|
|
10
|
+
};
|
|
11
|
+
networkId: string;
|
|
12
|
+
signer: {
|
|
13
|
+
type: string;
|
|
14
|
+
derivationPath: string;
|
|
15
|
+
};
|
|
16
|
+
type: string;
|
|
17
|
+
guardian: undefined;
|
|
18
|
+
escape: undefined;
|
|
19
|
+
needsDeploy: boolean;
|
|
20
|
+
hidden: boolean;
|
|
21
|
+
};
|
|
22
|
+
export declare const getMockWalletAccount: (overrides?: Partial<typeof defaultWalletAccount>) => {
|
|
23
|
+
name: string;
|
|
24
|
+
address: string;
|
|
25
|
+
network: {
|
|
26
|
+
id: string;
|
|
27
|
+
name: string;
|
|
28
|
+
chainId: string;
|
|
29
|
+
possibleFeeTokenAddresses: string[];
|
|
30
|
+
rpcUrl: string;
|
|
31
|
+
};
|
|
32
|
+
networkId: string;
|
|
33
|
+
signer: {
|
|
34
|
+
type: string;
|
|
35
|
+
derivationPath: string;
|
|
36
|
+
};
|
|
37
|
+
type: string;
|
|
38
|
+
guardian: undefined;
|
|
39
|
+
escape: undefined;
|
|
40
|
+
needsDeploy: boolean;
|
|
41
|
+
hidden: boolean;
|
|
42
|
+
};
|
|
43
|
+
export {};
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import { Trade } from '..';
|
|
2
|
+
import * as bigDecimal from "@/bigdecimal";
|
|
3
|
+
/**
|
|
4
|
+
* Calculates the maximum amount that should be paid for a trade after accounting for slippage.
|
|
5
|
+
* @param trade - The trade to calculate for.
|
|
6
|
+
* @param slippage - The slippage percentage in basis points.
|
|
7
|
+
* @returns The maximum amount that should be paid as a BigDecimal.
|
|
8
|
+
*/
|
|
9
|
+
export declare function maximumAmountInForTrade(trade: Trade, slippage: number): bigDecimal.BigDecimal;
|
|
10
|
+
/**
|
|
11
|
+
* Calculates the minimum amount that should be received from a trade after accounting for slippage.
|
|
12
|
+
* @param trade - The trade to calculate for.
|
|
13
|
+
* @param slippage - The slippage percentage in basis points.
|
|
14
|
+
* @returns The minimum amount that should be received as a BigDecimal.
|
|
15
|
+
*/
|
|
16
|
+
export declare function minimumAmountOutFromTrade(trade: Trade, slippage: number): bigDecimal.BigDecimal;
|
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
import { SwapQuoteResponse, Trade } from '../models';
|
|
2
|
+
type TotalTradeFee = Pick<Trade, "totalFee" | "totalFeeInCurrency" | "totalFeePercentage">;
|
|
3
|
+
type QuoteFee = Pick<SwapQuoteResponse, "providerFee" | "argentFee" | "argentFeeInCurrency" | "providerFeeInCurrency" | "argentFeePercentage" | "providerFeePercentage">;
|
|
4
|
+
export declare function calculateTotalFee(quote: QuoteFee): TotalTradeFee;
|
|
5
|
+
export {};
|