@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
package/dist/simulation.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const
|
|
1
|
+
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const n=require("./transactionVersion-CaRQ5Df4.js"),p=require("lodash-es"),d=require("./webToken.model-Dsd8Rd3e.js");require("starknet");require("zod");require("@scure/base");require("react");require("object-hash");require("swr");function l(e){return e.error?e.error:e.message&&e.code?`${e.code}: ${e.message}`:"Unknown error"}function g(e){if(!e)return;const s=e.transactions.flatMap(u=>n.isTransactionSimulationError(u)?u.simulationError:!1),t=s==null?void 0:s[s.length-1];if(!t)return;const i=l(t),r=t.message||t.error,c=n.getPrettyRpcError(r),o=c||t.label;return{message:c?r:i,label:o}}const f=e=>e.map(m),m=e=>{var i,r,c,o;if(n.isActivitySummary(e))return n.activitySummarySchema.parse(e);const s=!!e.sent;if(e.token.type!=="ERC20"){const a={asset:{type:"nft",tokenAddress:e.token.address,tokenId:e.tokenId?parseInt(e.tokenId):0,amount:e.value,collectionName:e.token.name,collectionPreviewImage:(i=e.token.imageUrls)==null?void 0:i.preview,nftName:(r=e.tokenIdDetails)==null?void 0:r.name,nftPreviewImage:(o=(c=e.tokenIdDetails)==null?void 0:c.imageUrls)==null?void 0:o.preview},sent:s};return n.activitySummarySchema.parse(a)}const t={asset:{type:"token",tokenAddress:e.token.address,amount:e.value,fiatAmount:{currency:"USD",currencyAmount:e.usdValue||"0"}},sent:s};return n.activitySummarySchema.parse(t)};function A(e){var i,r;const s=(r=(i=e.transactions)==null?void 0:i[0].reviewOfTransaction)==null?void 0:r.reviews;return s?s.map(c=>c.action):void 0}function k({simulateAndReview:e,...s}){var i,r;const t={type:n.NativeActivityTypeNative,...s};if(e&&!p.isEmpty(e.transactions)){const c=e.transactions[e.transactions.length-1],o=(i=c.simulation)==null?void 0:i.summary;if(o){const h=f(o);t.transferSummary=h}const a=(r=c.reviewOfTransaction)==null?void 0:r.targetedDapp;a&&(t.dapp=a);const u=A(e);u&&(t.actions=u)}return n.nativeActivitySchema.parse(t)}function v(e){const s=T(e),t=E(e);return s||t}const T=e=>{var o;if(!((o=e.actions)!=null&&o.length))return!1;const s=e.actions[0];if(s.name!=="ERC20_transfer")return!1;let t,i,r,c;return s.defaultProperties&&s.defaultProperties.forEach(a=>{a.type==="token_address"&&a.token.address===n.ETH_TOKEN_ADDRESS&&(i=!0),a.type==="calldata"&&(t=a.calldata[0])}),s.properties.length>1&&s.properties.forEach(a=>{a.type==="amount"&&a.label==="ERC20_transfer_amount"&&a.amount==="0"&&(r=!0),a.type==="address"&&a.label==="ERC20_transfer_recipient"&&d.isEqualAddress(a.address,t)&&(c=!0)}),i&&r&&c},E=e=>{var s,t;return!!("meta"in e&&(t=(s=e.meta)==null?void 0:s.title)!=null&&t.includes("On-chain rejection"))};function y(e,s=!1){var t,i;if(e.type===n.NativeActivityTypeNative){if(s&&((t=e.meta)!=null&&t.shortTitle))return e.meta.shortTitle;if((i=e.meta)!=null&&i.title)return e.meta.title}else{if(v(e))return"On-chain rejection";if(e.title)return e.title}return"Contract interaction"}function N(e){return y(e,!0)}function D(e){return e.map(i=>i.lastModified).sort().pop()}const O=e=>{var t,i;return!!((i=(t=e.details)==null?void 0:t.calls)==null?void 0:i.some(r=>{var c,o,a;return(o=(c=r==null?void 0:r.details)==null?void 0:c.function)!=null&&o.name?((a=r==null?void 0:r.details)==null?void 0:a.function.name)==="lock_and_delegate_by_sig":!1}))},S=e=>{var s;return e.type==="multicall"&&"calls"in e.details&&((s=e.details.calls)==null?void 0:s.some(t=>{var i;return((i=t==null?void 0:t.details)==null?void 0:i.type)==="deploy"&&d.isEqualAddress((t==null?void 0:t.details.contractAddress)||"",e.wallet)}))};function w(e){const s=M(e),t=R(e);return s||t}const M=e=>{var t;if(!((t=e.actions)!=null&&t.length))return!1;const s=e.actions[0];if(s.name!=="account_upgrade")return!1;s.defaultProperties&&s.defaultProperties.forEach(i=>{if(i.type==="calldata"&&i.entrypoint==="upgrade")return!0})},R=e=>{var s,t;return!!("meta"in e&&(t=(s=e.meta)==null?void 0:s.title)!=null&&t.includes("Upgrade account"))};function _({activities:e,accountAddressesOnNetwork:s}){const t={};return e.forEach(i=>{const r=i.wallet,c=i.type==="deploy"?i.type:i.details.type==="security"?i.details.action:void 0;i.group==="security"&&d.includesAddress(r,s)&&c&&(t[c]=t[c]||[],d.includesAddress(r,t[c])||(t[c]=d.ensureArray(t[c]).concat(r))),S(i)&&(t.deploy=d.ensureArray(t.deploy).concat(r))}),t}function j({activities:e,accountAddressesOnNetwork:s,tokenAddressesOnNetwork:t}){const i={tokenActivity:{accountAddresses:[],tokenAddresses:[],newTokenAddresses:[]},nftActivity:{accountAddresses:[],tokenAddresses:[]}};return e.forEach(r=>{if(r.group==="finance"&&r.relatedAddresses){const c=r.transfers.some(o=>o.asset.type==="token");r.relatedAddresses.forEach(({type:o,address:a})=>{o==="token"?d.includesAddress(a,t)&&(d.includesAddress(a,i.tokenActivity.tokenAddresses)||i.tokenActivity.tokenAddresses.push(a)):o==="wallet"&&d.includesAddress(a,s)&&(c?d.includesAddress(a,i.tokenActivity.accountAddresses)||i.tokenActivity.accountAddresses.push(a):d.includesAddress(a,i.nftActivity.accountAddresses)||i.nftActivity.accountAddresses.push(a))}),r.transfers.forEach(o=>{if(o.asset.type==="token"){const a=o.asset.tokenAddress;!d.includesAddress(a,t)&&!d.includesAddress(a,i.tokenActivity.newTokenAddresses)&&i.tokenActivity.newTokenAddresses.push(a)}else if(o.asset.type==="nft"){const a=o.asset.tokenAddress;d.includesAddress(a,i.nftActivity.tokenAddresses)||i.nftActivity.tokenAddresses.push(a)}})}}),i}const q=e=>{if(e.length===0)return null;const s=["critical","high","caution","info"];return e.reduce((t,i)=>{const r=s.indexOf(i.severity),c=s.indexOf(t.severity);return r<c?i:t},e[0])};exports.NativeActivityStatusCancelled=n.NativeActivityStatusCancelled;exports.NativeActivityStatusQueued=n.NativeActivityStatusQueued;exports.NativeActivityStatusRejected=n.NativeActivityStatusRejected;exports.NativeActivityTypeNative=n.NativeActivityTypeNative;exports.actionSchema=n.actionSchema;exports.activitiesSchema=n.activitiesSchema;exports.activityDappSchema=n.activityDappSchema;exports.activityDetailsSchema=n.activityDetailsSchema;exports.activityResponseSchema=n.activityResponseSchema;exports.activitySchema=n.activitySchema;exports.activitySummarySchema=n.activitySummarySchema;exports.activityTransferSchema=n.activityTransferSchema;exports.assessmentSchema=n.assessmentSchema;exports.enrichedSimulateAndReviewSchema=n.enrichedSimulateAndReviewSchema;exports.estimatedFeeSchema=n.estimatedFeeSchema;exports.estimatedFeesSchema=n.estimatedFeesSchema;exports.feeEstimationSchema=n.feeEstimationSchema;exports.feeSchema=n.feeSchema;exports.isActivityDetailsAction=n.isActivityDetailsAction;exports.isActivitySummary=n.isActivitySummary;exports.isNftActivitySummary=n.isNftActivitySummary;exports.isNotTransactionSimulationError=n.isNotTransactionSimulationError;exports.isTokenActivitySummary=n.isTokenActivitySummary;exports.isTransactionSimulationError=n.isTransactionSimulationError;exports.nativeActivityMetaSchema=n.nativeActivityMetaSchema;exports.nativeActivitySchema=n.nativeActivitySchema;exports.propertySchema=n.propertySchema;exports.reasonsSchema=n.reasonsSchema;exports.reviewSchema=n.reviewSchema;exports.severitySchema=n.severitySchema;exports.simulateAndReviewSchema=n.simulateAndReviewSchema;exports.targetedDappSchema=n.targetedDappSchema;exports.warningDetailsSchema=n.warningDetailsSchema;exports.warningSchema=n.warningSchema;exports.createNativeActivity=k;exports.getAnyActivityShortTitle=N;exports.getAnyActivityTitle=y;exports.getErrorMessageAndLabelFromSimulation=g;exports.getHighestSeverity=q;exports.getMessageFromSimulationError=l;exports.getOverallLastModified=D;exports.hasDelegationActivity=O;exports.isMulticallWithDeploymentActivity=S;exports.isRejectOnChainActivity=v;exports.isUpgradeActivity=w;exports.normalizeActions=A;exports.normalizeActivitySummary=m;exports.normalizeActivitySummaryCollection=f;exports.parseAccountActivities=_;exports.parseFinanceActivities=j;
|
package/dist/simulation.mjs
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import {
|
|
1
|
+
import { i as m, K as h, O as v, P as f, Q as l, U as g, E as y } from "./transactionVersion-CACUj2ch.mjs";
|
|
2
|
+
import { a0 as J, a1 as I, $ as ee, aa as te, a2 as se, X as ne, W as ae, a3 as ie, Z as re, V as oe, ab as ce, ag as de, a7 as fe, a8 as ue, f as le, Y as pe, a4 as Ae, a6 as me, ah as he, a5 as ve, _ as ge, a9 as ye, aj as Se, ae as ke, ai as Te, s as Ee, af as Oe, ac as we, ad as De } from "./transactionVersion-CACUj2ch.mjs";
|
|
3
3
|
import { isEmpty as S } from "lodash-es";
|
|
4
|
+
import { h as p, R as c, F as u } from "./webToken.model-Cl4dvcmj.mjs";
|
|
4
5
|
import "starknet";
|
|
5
6
|
import "zod";
|
|
6
7
|
import "@scure/base";
|
|
@@ -10,25 +11,25 @@ import "swr";
|
|
|
10
11
|
function k(e) {
|
|
11
12
|
return e.error ? e.error : e.message && e.code ? `${e.code}: ${e.message}` : "Unknown error";
|
|
12
13
|
}
|
|
13
|
-
function
|
|
14
|
+
function W(e) {
|
|
14
15
|
if (!e)
|
|
15
16
|
return;
|
|
16
17
|
const n = e.transactions.flatMap((d) => m(d) ? d.simulationError : !1), t = n == null ? void 0 : n[n.length - 1];
|
|
17
18
|
if (!t)
|
|
18
19
|
return;
|
|
19
|
-
const s = k(t),
|
|
20
|
+
const s = k(t), i = t.message || t.error, r = h(i), o = r || t.label;
|
|
20
21
|
return {
|
|
21
|
-
message: r ?
|
|
22
|
+
message: r ? i : s,
|
|
22
23
|
label: o
|
|
23
24
|
};
|
|
24
25
|
}
|
|
25
26
|
const T = (e) => e.map(E), E = (e) => {
|
|
26
|
-
var s,
|
|
27
|
+
var s, i, r, o;
|
|
27
28
|
if (v(e))
|
|
28
29
|
return f.parse(e);
|
|
29
30
|
const n = !!e.sent;
|
|
30
31
|
if (e.token.type !== "ERC20") {
|
|
31
|
-
const
|
|
32
|
+
const a = {
|
|
32
33
|
asset: {
|
|
33
34
|
type: "nft",
|
|
34
35
|
tokenAddress: e.token.address,
|
|
@@ -36,12 +37,12 @@ const T = (e) => e.map(E), E = (e) => {
|
|
|
36
37
|
amount: e.value,
|
|
37
38
|
collectionName: e.token.name,
|
|
38
39
|
collectionPreviewImage: (s = e.token.imageUrls) == null ? void 0 : s.preview,
|
|
39
|
-
nftName: (
|
|
40
|
+
nftName: (i = e.tokenIdDetails) == null ? void 0 : i.name,
|
|
40
41
|
nftPreviewImage: (o = (r = e.tokenIdDetails) == null ? void 0 : r.imageUrls) == null ? void 0 : o.preview
|
|
41
42
|
},
|
|
42
43
|
sent: n
|
|
43
44
|
};
|
|
44
|
-
return f.parse(
|
|
45
|
+
return f.parse(a);
|
|
45
46
|
}
|
|
46
47
|
const t = {
|
|
47
48
|
asset: {
|
|
@@ -58,12 +59,12 @@ const T = (e) => e.map(E), E = (e) => {
|
|
|
58
59
|
return f.parse(t);
|
|
59
60
|
};
|
|
60
61
|
function O(e) {
|
|
61
|
-
var s,
|
|
62
|
-
const n = (
|
|
62
|
+
var s, i;
|
|
63
|
+
const n = (i = (s = e.transactions) == null ? void 0 : s[0].reviewOfTransaction) == null ? void 0 : i.reviews;
|
|
63
64
|
return n ? n.map((r) => r.action) : void 0;
|
|
64
65
|
}
|
|
65
66
|
function $({ simulateAndReview: e, ...n }) {
|
|
66
|
-
var s,
|
|
67
|
+
var s, i;
|
|
67
68
|
const t = {
|
|
68
69
|
type: l,
|
|
69
70
|
...n
|
|
@@ -74,8 +75,8 @@ function $({ simulateAndReview: e, ...n }) {
|
|
|
74
75
|
const A = T(o);
|
|
75
76
|
t.transferSummary = A;
|
|
76
77
|
}
|
|
77
|
-
const
|
|
78
|
-
|
|
78
|
+
const a = (i = r.reviewOfTransaction) == null ? void 0 : i.targetedDapp;
|
|
79
|
+
a && (t.dapp = a);
|
|
79
80
|
const d = O(e);
|
|
80
81
|
d && (t.actions = d);
|
|
81
82
|
}
|
|
@@ -92,12 +93,12 @@ const D = (e) => {
|
|
|
92
93
|
const n = e.actions[0];
|
|
93
94
|
if (n.name !== "ERC20_transfer")
|
|
94
95
|
return !1;
|
|
95
|
-
let t, s,
|
|
96
|
-
return n.defaultProperties && n.defaultProperties.forEach((
|
|
97
|
-
|
|
98
|
-
}), n.properties.length > 1 && n.properties.forEach((
|
|
99
|
-
|
|
100
|
-
}), s &&
|
|
96
|
+
let t, s, i, r;
|
|
97
|
+
return n.defaultProperties && n.defaultProperties.forEach((a) => {
|
|
98
|
+
a.type === "token_address" && a.token.address === y && (s = !0), a.type === "calldata" && (t = a.calldata[0]);
|
|
99
|
+
}), n.properties.length > 1 && n.properties.forEach((a) => {
|
|
100
|
+
a.type === "amount" && a.label === "ERC20_transfer_amount" && a.amount === "0" && (i = !0), a.type === "address" && a.label === "ERC20_transfer_recipient" && p(a.address, t) && (r = !0);
|
|
101
|
+
}), s && i && r;
|
|
101
102
|
}, M = (e) => {
|
|
102
103
|
var n, t;
|
|
103
104
|
return !!("meta" in e && (t = (n = e.meta) == null ? void 0 : n.title) != null && t.includes("On-chain rejection"));
|
|
@@ -117,17 +118,17 @@ function R(e, n = !1) {
|
|
|
117
118
|
}
|
|
118
119
|
return "Contract interaction";
|
|
119
120
|
}
|
|
120
|
-
function
|
|
121
|
+
function H(e) {
|
|
121
122
|
return R(e, !0);
|
|
122
123
|
}
|
|
123
|
-
function
|
|
124
|
+
function K(e) {
|
|
124
125
|
return e.map((s) => s.lastModified).sort().pop();
|
|
125
126
|
}
|
|
126
|
-
const
|
|
127
|
+
const Q = (e) => {
|
|
127
128
|
var t, s;
|
|
128
|
-
return !!((s = (t = e.details) == null ? void 0 : t.calls) == null ? void 0 : s.some((
|
|
129
|
-
var r, o,
|
|
130
|
-
return (o = (r =
|
|
129
|
+
return !!((s = (t = e.details) == null ? void 0 : t.calls) == null ? void 0 : s.some((i) => {
|
|
130
|
+
var r, o, a;
|
|
131
|
+
return (o = (r = i == null ? void 0 : i.details) == null ? void 0 : r.function) != null && o.name ? ((a = i == null ? void 0 : i.details) == null ? void 0 : a.function.name) === "lock_and_delegate_by_sig" : !1;
|
|
131
132
|
}));
|
|
132
133
|
}, _ = (e) => {
|
|
133
134
|
var n;
|
|
@@ -136,7 +137,7 @@ const K = (e) => {
|
|
|
136
137
|
return ((s = t == null ? void 0 : t.details) == null ? void 0 : s.type) === "deploy" && p((t == null ? void 0 : t.details.contractAddress) || "", e.wallet);
|
|
137
138
|
}));
|
|
138
139
|
};
|
|
139
|
-
function
|
|
140
|
+
function V(e) {
|
|
140
141
|
const n = N(e), t = B(e);
|
|
141
142
|
return n || t;
|
|
142
143
|
}
|
|
@@ -155,14 +156,14 @@ const N = (e) => {
|
|
|
155
156
|
var n, t;
|
|
156
157
|
return !!("meta" in e && (t = (n = e.meta) == null ? void 0 : n.title) != null && t.includes("Upgrade account"));
|
|
157
158
|
};
|
|
158
|
-
function
|
|
159
|
+
function Z({ activities: e, accountAddressesOnNetwork: n }) {
|
|
159
160
|
const t = {};
|
|
160
161
|
return e.forEach((s) => {
|
|
161
|
-
const
|
|
162
|
-
s.group === "security" && c(
|
|
162
|
+
const i = s.wallet, r = s.type === "deploy" ? s.type : s.details.type === "security" ? s.details.action : void 0;
|
|
163
|
+
s.group === "security" && c(i, n) && r && (t[r] = t[r] || [], c(i, t[r]) || (t[r] = u(t[r]).concat(i))), _(s) && (t.deploy = u(t.deploy).concat(i));
|
|
163
164
|
}), t;
|
|
164
165
|
}
|
|
165
|
-
function
|
|
166
|
+
function q({ activities: e, accountAddressesOnNetwork: n, tokenAddressesOnNetwork: t }) {
|
|
166
167
|
const s = {
|
|
167
168
|
tokenActivity: {
|
|
168
169
|
accountAddresses: [],
|
|
@@ -174,81 +175,81 @@ function V({ activities: e, accountAddressesOnNetwork: n, tokenAddressesOnNetwor
|
|
|
174
175
|
tokenAddresses: []
|
|
175
176
|
}
|
|
176
177
|
};
|
|
177
|
-
return e.forEach((
|
|
178
|
-
if (
|
|
179
|
-
const r =
|
|
180
|
-
|
|
181
|
-
o === "token" ? c(
|
|
182
|
-
}),
|
|
178
|
+
return e.forEach((i) => {
|
|
179
|
+
if (i.group === "finance" && i.relatedAddresses) {
|
|
180
|
+
const r = i.transfers.some((o) => o.asset.type === "token");
|
|
181
|
+
i.relatedAddresses.forEach(({ type: o, address: a }) => {
|
|
182
|
+
o === "token" ? c(a, t) && (c(a, s.tokenActivity.tokenAddresses) || s.tokenActivity.tokenAddresses.push(a)) : o === "wallet" && c(a, n) && (r ? c(a, s.tokenActivity.accountAddresses) || s.tokenActivity.accountAddresses.push(a) : c(a, s.nftActivity.accountAddresses) || s.nftActivity.accountAddresses.push(a));
|
|
183
|
+
}), i.transfers.forEach((o) => {
|
|
183
184
|
if (o.asset.type === "token") {
|
|
184
|
-
const
|
|
185
|
-
!c(
|
|
185
|
+
const a = o.asset.tokenAddress;
|
|
186
|
+
!c(a, t) && !c(a, s.tokenActivity.newTokenAddresses) && s.tokenActivity.newTokenAddresses.push(a);
|
|
186
187
|
} else if (o.asset.type === "nft") {
|
|
187
|
-
const
|
|
188
|
-
c(
|
|
188
|
+
const a = o.asset.tokenAddress;
|
|
189
|
+
c(a, s.nftActivity.tokenAddresses) || s.nftActivity.tokenAddresses.push(a);
|
|
189
190
|
}
|
|
190
191
|
});
|
|
191
192
|
}
|
|
192
193
|
}), s;
|
|
193
194
|
}
|
|
194
|
-
const
|
|
195
|
+
const X = (e) => {
|
|
195
196
|
if (e.length === 0)
|
|
196
197
|
return null;
|
|
197
198
|
const n = ["critical", "high", "caution", "info"];
|
|
198
199
|
return e.reduce((t, s) => {
|
|
199
|
-
const
|
|
200
|
-
return
|
|
200
|
+
const i = n.indexOf(s.severity), r = n.indexOf(t.severity);
|
|
201
|
+
return i < r ? s : t;
|
|
201
202
|
}, e[0]);
|
|
202
203
|
};
|
|
203
204
|
export {
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
205
|
+
J as NativeActivityStatusCancelled,
|
|
206
|
+
I as NativeActivityStatusQueued,
|
|
207
|
+
ee as NativeActivityStatusRejected,
|
|
207
208
|
l as NativeActivityTypeNative,
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
209
|
+
te as actionSchema,
|
|
210
|
+
se as activitiesSchema,
|
|
211
|
+
ne as activityDappSchema,
|
|
212
|
+
ae as activityDetailsSchema,
|
|
212
213
|
ie as activityResponseSchema,
|
|
213
|
-
|
|
214
|
+
re as activitySchema,
|
|
214
215
|
f as activitySummarySchema,
|
|
215
|
-
|
|
216
|
-
|
|
216
|
+
oe as activityTransferSchema,
|
|
217
|
+
ce as assessmentSchema,
|
|
217
218
|
$ as createNativeActivity,
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
219
|
+
de as enrichedSimulateAndReviewSchema,
|
|
220
|
+
fe as estimatedFeeSchema,
|
|
221
|
+
ue as estimatedFeesSchema,
|
|
222
|
+
le as feeEstimationSchema,
|
|
223
|
+
pe as feeSchema,
|
|
224
|
+
H as getAnyActivityShortTitle,
|
|
224
225
|
R as getAnyActivityTitle,
|
|
225
|
-
|
|
226
|
-
|
|
226
|
+
W as getErrorMessageAndLabelFromSimulation,
|
|
227
|
+
X as getHighestSeverity,
|
|
227
228
|
k as getMessageFromSimulationError,
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
229
|
+
K as getOverallLastModified,
|
|
230
|
+
Q as hasDelegationActivity,
|
|
231
|
+
Ae as isActivityDetailsAction,
|
|
231
232
|
v as isActivitySummary,
|
|
232
233
|
_ as isMulticallWithDeploymentActivity,
|
|
233
|
-
|
|
234
|
-
|
|
234
|
+
me as isNftActivitySummary,
|
|
235
|
+
he as isNotTransactionSimulationError,
|
|
235
236
|
w as isRejectOnChainActivity,
|
|
236
|
-
|
|
237
|
+
ve as isTokenActivitySummary,
|
|
237
238
|
m as isTransactionSimulationError,
|
|
238
|
-
|
|
239
|
-
|
|
239
|
+
V as isUpgradeActivity,
|
|
240
|
+
ge as nativeActivityMetaSchema,
|
|
240
241
|
g as nativeActivitySchema,
|
|
241
242
|
O as normalizeActions,
|
|
242
243
|
E as normalizeActivitySummary,
|
|
243
244
|
T as normalizeActivitySummaryCollection,
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
|
|
245
|
+
Z as parseAccountActivities,
|
|
246
|
+
q as parseFinanceActivities,
|
|
247
|
+
ye as propertySchema,
|
|
248
|
+
Se as reasonsSchema,
|
|
249
|
+
ke as reviewSchema,
|
|
250
|
+
Te as severitySchema,
|
|
251
|
+
Ee as simulateAndReviewSchema,
|
|
252
|
+
Oe as targetedDappSchema,
|
|
253
|
+
we as warningDetailsSchema,
|
|
254
|
+
De as warningSchema
|
|
254
255
|
};
|
package/dist/swap.d.ts
ADDED
package/dist/swap.js
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const o=require("./webToken.model-Dsd8Rd3e.js"),e=require("zod");require("starknet");require("lodash-es");require("@scure/base");const s=require("./bips-CP71ZN9a.js");var y;(function(r){r.NO_SWAP_URL="Swap base url not provided",r.INVALID_QUOTE_RESPONSE="Invalid quote response",r.NO_NETWORK_FOR_SWAP="Network for swap not found",r.INVALID_SWAP_TOKENS="Invalid swap tokens",r.INVALID_SWAP_ORDER_RESPONSE="Invalid swap order response"})(y||(y={}));class p extends o.BaseError{constructor(n){super(n,y),this.name="SwapError"}}const m=e.z.object({quoteId:e.z.string()}),d=e.z.lazy(()=>e.z.object({name:e.z.string(),percent:e.z.number(),sellToken:o.addressSchema,buyToken:o.addressSchema,routes:e.z.array(d)})),S=e.z.object({sellToken:o.addressSchema,sellAmount:e.z.string(),sellAmountInCurrency:e.z.string(),buyToken:o.addressSchema,buyAmount:e.z.string(),buyAmountInCurrency:e.z.string(),expiresAt:e.z.number(),expiresIn:e.z.number(),dexCount:e.z.number(),routes:e.z.array(d),providerName:e.z.string(),providerFee:e.z.string(),providerFeeInCurrency:e.z.string(),providerFeePercentage:e.z.number(),argentFee:e.z.string(),argentFeeInCurrency:e.z.string(),argentFeePercentage:e.z.number(),feeToken:o.addressSchema,data:m}),T=e.z.object({chain:e.z.literal("starknet"),sellToken:o.addressSchema,buyToken:o.addressSchema,sellAmount:e.z.string(),buyAmount:e.z.string(),accountAddress:o.addressSchema,slippage:e.z.number().transform(r=>r.toString()),data:m}),A=e.z.object({calls:e.z.array(o.callSchema)});exports.TradeType=void 0;(function(r){r.EXACT_PAY="EXACT_PAY",r.EXACT_RECEIVE="EXACT_RECEIVE"})(exports.TradeType||(exports.TradeType={}));const g=e.z.nativeEnum(exports.TradeType),h=e.z.object({payToken:o.webTokenSchema,receiveToken:o.webTokenSchema,tradeType:g.default(exports.TradeType.EXACT_PAY),payAmount:e.z.string(),receiveAmount:e.z.string(),payAmountInCurrency:e.z.string(),receiveAmountInCurrency:e.z.string(),totalFee:e.z.string(),totalFeeInCurrency:e.z.string().optional(),totalFeePercentage:e.z.number(),expiresAt:e.z.number(),expiresIn:e.z.number(),route:d,data:m});function I(r){const n=BigInt(r.providerFee)+BigInt(r.argentFee),t=s.add(s.parseCurrency(r.argentFeeInCurrency),s.parseCurrency(r.providerFeeInCurrency)),a=s.formatCurrency(t.value),c=r.argentFeePercentage+r.providerFeePercentage;return{totalFee:n.toString(),totalFeePercentage:c,totalFeeInCurrency:a}}function z(r,n){const t=s.bipsToPercent(n),a={value:BigInt(r.payAmount),decimals:r.payToken.decimals};if(r.tradeType===exports.TradeType.EXACT_PAY||t.value<=0n)return a;const c=s.add(s.ONE,t);return s.mul(a,c)}function w(r,n){const t=s.bipsToPercent(n),a={value:BigInt(r.receiveAmount),decimals:r.receiveToken.decimals};if(r.tradeType===exports.TradeType.EXACT_RECEIVE)return a;const c=s.add(s.ONE,t);return s.div(a,c)}class b{constructor(n,t){if(this.httpService=n,!t)throw new p({code:"NO_SWAP_URL"});this.swapQuoteUrl=o.urlJoin(t,"/quote"),this.swapOrderUrl=o.urlJoin(t,"/order")}async getSwapQuoteForPay(n,t,a,c,u="USD"){const i=s.urlWithQuery(this.swapQuoteUrl,{accountAddress:c,currency:u,chain:"starknet",sellToken:n,buyToken:t,sellAmount:a});try{const l=await this.httpService.get(i);return await S.parseAsync(l)}catch(l){throw console.error(l),new p({code:"INVALID_QUOTE_RESPONSE"})}}async getSwapTradeFromQuote(n,t,a){if(!t||!a)throw new p({code:"INVALID_SWAP_TOKENS"});const{totalFee:c,totalFeeInCurrency:u,totalFeePercentage:i}=I(n);return h.parse({payToken:t,receiveToken:a,payAmount:n.sellAmount,receiveAmount:n.buyAmount,payAmountInCurrency:n.sellAmountInCurrency,receiveAmountInCurrency:n.buyAmountInCurrency,totalFee:c,totalFeeInCurrency:u,totalFeePercentage:i,expiresAt:n.expiresAt,expiresIn:n.expiresIn,route:n.routes[0],data:n.data})}async getSwapOrderFromTrade(n,t,a){const c=T.parse({chain:"starknet",sellToken:t.payToken.address,buyToken:t.receiveToken.address,sellAmount:t.payAmount,buyAmount:t.receiveAmount,accountAddress:n,slippage:a/1e4,data:t.data});try{const u=await this.httpService.post(this.swapOrderUrl,{body:JSON.stringify(c),headers:{"Content-Type":"application/json"}});return await A.parseAsync(u)}catch(u){throw console.error(u),new p({code:"INVALID_SWAP_ORDER_RESPONSE"})}}}exports.SharedSwapService=b;exports.SwapDataSchema=m;exports.SwapOrderRequestSchema=T;exports.SwapOrderResponseSchema=A;exports.SwapQuoteResponseSchema=S;exports.SwapQuoteRouteSchema=d;exports.TradeSchema=h;exports.TradeTypeSchema=g;exports.calculateTotalFee=I;exports.maximumAmountInForTrade=z;exports.minimumAmountOutFromTrade=w;
|
package/dist/swap.mjs
ADDED
|
@@ -0,0 +1,183 @@
|
|
|
1
|
+
import { a7 as b, t as s, c as w, ao as g, u as I } from "./webToken.model-Cl4dvcmj.mjs";
|
|
2
|
+
import { z as e } from "zod";
|
|
3
|
+
import "starknet";
|
|
4
|
+
import "lodash-es";
|
|
5
|
+
import "@scure/base";
|
|
6
|
+
import { c as d, p as T, f as v, x as S, O as h, n as C, d as F, w as E } from "./bips-zBtnMbia.mjs";
|
|
7
|
+
var l;
|
|
8
|
+
(function(r) {
|
|
9
|
+
r.NO_SWAP_URL = "Swap base url not provided", r.INVALID_QUOTE_RESPONSE = "Invalid quote response", r.NO_NETWORK_FOR_SWAP = "Network for swap not found", r.INVALID_SWAP_TOKENS = "Invalid swap tokens", r.INVALID_SWAP_ORDER_RESPONSE = "Invalid swap order response";
|
|
10
|
+
})(l || (l = {}));
|
|
11
|
+
class p extends b {
|
|
12
|
+
constructor(n) {
|
|
13
|
+
super(n, l), this.name = "SwapError";
|
|
14
|
+
}
|
|
15
|
+
}
|
|
16
|
+
const y = e.object({
|
|
17
|
+
quoteId: e.string()
|
|
18
|
+
}), A = e.lazy(() => e.object({
|
|
19
|
+
name: e.string(),
|
|
20
|
+
percent: e.number(),
|
|
21
|
+
sellToken: s,
|
|
22
|
+
buyToken: s,
|
|
23
|
+
routes: e.array(A)
|
|
24
|
+
})), P = e.object({
|
|
25
|
+
sellToken: s,
|
|
26
|
+
sellAmount: e.string(),
|
|
27
|
+
sellAmountInCurrency: e.string(),
|
|
28
|
+
buyToken: s,
|
|
29
|
+
buyAmount: e.string(),
|
|
30
|
+
buyAmountInCurrency: e.string(),
|
|
31
|
+
expiresAt: e.number(),
|
|
32
|
+
expiresIn: e.number(),
|
|
33
|
+
dexCount: e.number(),
|
|
34
|
+
routes: e.array(A),
|
|
35
|
+
providerName: e.string(),
|
|
36
|
+
providerFee: e.string(),
|
|
37
|
+
providerFeeInCurrency: e.string(),
|
|
38
|
+
providerFeePercentage: e.number(),
|
|
39
|
+
argentFee: e.string(),
|
|
40
|
+
argentFeeInCurrency: e.string(),
|
|
41
|
+
argentFeePercentage: e.number(),
|
|
42
|
+
feeToken: s,
|
|
43
|
+
data: y
|
|
44
|
+
}), _ = e.object({
|
|
45
|
+
chain: e.literal("starknet"),
|
|
46
|
+
sellToken: s,
|
|
47
|
+
buyToken: s,
|
|
48
|
+
sellAmount: e.string(),
|
|
49
|
+
buyAmount: e.string(),
|
|
50
|
+
accountAddress: s,
|
|
51
|
+
slippage: e.number().transform((r) => r.toString()),
|
|
52
|
+
data: y
|
|
53
|
+
}), f = e.object({
|
|
54
|
+
calls: e.array(w)
|
|
55
|
+
});
|
|
56
|
+
var i;
|
|
57
|
+
(function(r) {
|
|
58
|
+
r.EXACT_PAY = "EXACT_PAY", r.EXACT_RECEIVE = "EXACT_RECEIVE";
|
|
59
|
+
})(i || (i = {}));
|
|
60
|
+
const k = e.nativeEnum(i), O = e.object({
|
|
61
|
+
payToken: g,
|
|
62
|
+
receiveToken: g,
|
|
63
|
+
tradeType: k.default(i.EXACT_PAY),
|
|
64
|
+
payAmount: e.string(),
|
|
65
|
+
receiveAmount: e.string(),
|
|
66
|
+
payAmountInCurrency: e.string(),
|
|
67
|
+
receiveAmountInCurrency: e.string(),
|
|
68
|
+
totalFee: e.string(),
|
|
69
|
+
totalFeeInCurrency: e.string().optional(),
|
|
70
|
+
totalFeePercentage: e.number(),
|
|
71
|
+
expiresAt: e.number(),
|
|
72
|
+
expiresIn: e.number(),
|
|
73
|
+
route: A,
|
|
74
|
+
data: y
|
|
75
|
+
});
|
|
76
|
+
function N(r) {
|
|
77
|
+
const n = BigInt(r.providerFee) + BigInt(r.argentFee), t = d(T(r.argentFeeInCurrency), T(r.providerFeeInCurrency)), o = v(t.value), a = r.argentFeePercentage + r.providerFeePercentage;
|
|
78
|
+
return {
|
|
79
|
+
totalFee: n.toString(),
|
|
80
|
+
totalFeePercentage: a,
|
|
81
|
+
totalFeeInCurrency: o
|
|
82
|
+
};
|
|
83
|
+
}
|
|
84
|
+
function j(r, n) {
|
|
85
|
+
const t = S(n), o = {
|
|
86
|
+
value: BigInt(r.payAmount),
|
|
87
|
+
decimals: r.payToken.decimals
|
|
88
|
+
};
|
|
89
|
+
if (r.tradeType === i.EXACT_PAY || t.value <= 0n)
|
|
90
|
+
return o;
|
|
91
|
+
const a = d(h, t);
|
|
92
|
+
return C(o, a);
|
|
93
|
+
}
|
|
94
|
+
function X(r, n) {
|
|
95
|
+
const t = S(n), o = {
|
|
96
|
+
value: BigInt(r.receiveAmount),
|
|
97
|
+
decimals: r.receiveToken.decimals
|
|
98
|
+
};
|
|
99
|
+
if (r.tradeType === i.EXACT_RECEIVE)
|
|
100
|
+
return o;
|
|
101
|
+
const a = d(h, t);
|
|
102
|
+
return F(o, a);
|
|
103
|
+
}
|
|
104
|
+
class W {
|
|
105
|
+
constructor(n, t) {
|
|
106
|
+
if (this.httpService = n, !t)
|
|
107
|
+
throw new p({ code: "NO_SWAP_URL" });
|
|
108
|
+
this.swapQuoteUrl = I(t, "/quote"), this.swapOrderUrl = I(t, "/order");
|
|
109
|
+
}
|
|
110
|
+
async getSwapQuoteForPay(n, t, o, a, c = "USD") {
|
|
111
|
+
const u = E(this.swapQuoteUrl, {
|
|
112
|
+
accountAddress: a,
|
|
113
|
+
currency: c,
|
|
114
|
+
chain: "starknet",
|
|
115
|
+
sellToken: n,
|
|
116
|
+
buyToken: t,
|
|
117
|
+
sellAmount: o
|
|
118
|
+
});
|
|
119
|
+
try {
|
|
120
|
+
const m = await this.httpService.get(u);
|
|
121
|
+
return await P.parseAsync(m);
|
|
122
|
+
} catch (m) {
|
|
123
|
+
throw console.error(m), new p({ code: "INVALID_QUOTE_RESPONSE" });
|
|
124
|
+
}
|
|
125
|
+
}
|
|
126
|
+
async getSwapTradeFromQuote(n, t, o) {
|
|
127
|
+
if (!t || !o)
|
|
128
|
+
throw new p({ code: "INVALID_SWAP_TOKENS" });
|
|
129
|
+
const { totalFee: a, totalFeeInCurrency: c, totalFeePercentage: u } = N(n);
|
|
130
|
+
return O.parse({
|
|
131
|
+
payToken: t,
|
|
132
|
+
receiveToken: o,
|
|
133
|
+
payAmount: n.sellAmount,
|
|
134
|
+
receiveAmount: n.buyAmount,
|
|
135
|
+
payAmountInCurrency: n.sellAmountInCurrency,
|
|
136
|
+
receiveAmountInCurrency: n.buyAmountInCurrency,
|
|
137
|
+
totalFee: a,
|
|
138
|
+
totalFeeInCurrency: c,
|
|
139
|
+
totalFeePercentage: u,
|
|
140
|
+
expiresAt: n.expiresAt,
|
|
141
|
+
expiresIn: n.expiresIn,
|
|
142
|
+
route: n.routes[0],
|
|
143
|
+
data: n.data
|
|
144
|
+
});
|
|
145
|
+
}
|
|
146
|
+
async getSwapOrderFromTrade(n, t, o) {
|
|
147
|
+
const a = _.parse({
|
|
148
|
+
chain: "starknet",
|
|
149
|
+
sellToken: t.payToken.address,
|
|
150
|
+
buyToken: t.receiveToken.address,
|
|
151
|
+
sellAmount: t.payAmount,
|
|
152
|
+
buyAmount: t.receiveAmount,
|
|
153
|
+
accountAddress: n,
|
|
154
|
+
slippage: o / 1e4,
|
|
155
|
+
data: t.data
|
|
156
|
+
});
|
|
157
|
+
try {
|
|
158
|
+
const c = await this.httpService.post(this.swapOrderUrl, {
|
|
159
|
+
body: JSON.stringify(a),
|
|
160
|
+
headers: {
|
|
161
|
+
"Content-Type": "application/json"
|
|
162
|
+
}
|
|
163
|
+
});
|
|
164
|
+
return await f.parseAsync(c);
|
|
165
|
+
} catch (c) {
|
|
166
|
+
throw console.error(c), new p({ code: "INVALID_SWAP_ORDER_RESPONSE" });
|
|
167
|
+
}
|
|
168
|
+
}
|
|
169
|
+
}
|
|
170
|
+
export {
|
|
171
|
+
W as SharedSwapService,
|
|
172
|
+
y as SwapDataSchema,
|
|
173
|
+
_ as SwapOrderRequestSchema,
|
|
174
|
+
f as SwapOrderResponseSchema,
|
|
175
|
+
P as SwapQuoteResponseSchema,
|
|
176
|
+
A as SwapQuoteRouteSchema,
|
|
177
|
+
O as TradeSchema,
|
|
178
|
+
i as TradeType,
|
|
179
|
+
k as TradeTypeSchema,
|
|
180
|
+
N as calculateTotalFee,
|
|
181
|
+
j as maximumAmountInForTrade,
|
|
182
|
+
X as minimumAmountOutFromTrade
|
|
183
|
+
};
|