@dhedge/trading-widget 6.0.1 → 6.0.4

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 +0,0 @@
1
- "use strict";const a=new Set(["0x2fbadd08ade2e8a24cf1fe3a58fe918336b39a72"]),S={REFERRER:"referrer",REF_POOL:"ref_pool"},E={BY:"Belarus",CD:"Democratic Republic of the Congo",CI:"Côte d'Ivoire",CU:"Cuba",IQ:"Iraq",IR:"Iran",KP:"North Korea",LB:"Lebanon",LR:"Liberia",LY:"Libya",MM:"Myanmar",RU:"Russia",SD:"Sudan",SO:"Somalia",SY:"Syria",VE:"Venezuela",YE:"Yemen",ZW:"Zimbabwe"},O={AF:"Afghanistan",BY:"Belarus",CA:"Canada",CU:"Cuba",KP:"North Korea",IR:"Iran",LY:"Libya",MM:"Myanmar",RU:"Russia",SO:"Somalia",SS:"South Sudan",SD:"Sudan",SY:"Syria",US:"United States"};exports.BLOCKED_COUNTRY_CODES_MAP=E;exports.COVERED_CALL_VAULT_ADDRESSES=a;exports.LOCAL_STORAGE_KEYS=S;exports.ONDO_ASSET_TYPE=41;exports.ONDO_BLOCKED_COUNTRY_CODES_MAP=O;
package/ondo-RW9qMjVL.cjs DELETED
@@ -1 +0,0 @@
1
- "use strict";const u=require("bignumber.js"),r=require("./gmx-DwT1ybQ5.cjs"),p=require("viem"),T=require("wagmi/chains"),Q=typeof window<"u",z=[{inputs:[{internalType:"address",name:"_pool",type:"address"},{internalType:"address",name:"_asset",type:"address"},{internalType:"uint256",name:"_poolTokenAmount",type:"uint256"}],name:"previewGmTokenAmount",outputs:[{internalType:"uint256",name:"gmTokenAmount",type:"uint256"}],stateMutability:"nonpayable",type:"function"}],j=[{type:"tuple",components:[{name:"attestationSignature",type:"bytes"},{name:"quote",type:"tuple",components:[{name:"chainId",type:"uint256"},{name:"attestationId",type:"uint256"},{name:"userId",type:"bytes32"},{name:"asset",type:"address"},{name:"price",type:"uint256"},{name:"quantity",type:"uint256"},{name:"expiration",type:"uint256"},{name:"side",type:"uint8"},{name:"additionalData",type:"bytes32"}]},{name:"amountOutMinimum",type:"uint256"}]}],X=()=>typeof window<"u";function J(){return X()&&typeof window.ethereum<"u"}async function tt(t){try{if(J())return window.ethereum.request({method:"wallet_watchAsset",params:{type:"ERC20",options:t}})}catch{return!1}return!1}const l=(t,e)=>t?.toLowerCase()===e?.toLowerCase(),et=t=>l(t,r.AddressZero$1),B=(t,e)=>r.contractsAddressesMap[e]?.[t]??r.AddressZero,nt=t=>r.contractsAbisMap[t],st=t=>t&&`${t.substring(0,6)}...${t.substring(t.length-4,t.length)}`,rt=({address:t,chainId:e})=>{const n=B("aaveLendingPoolV3",e);return l(t,n)},O=({sourceAddress:t,amount:e})=>`${t}_${e}`,ot=(t,e)=>{const n=t.slice(0,e),s=t.slice(e);return{firstPart:n,secondPart:s}},L=(t,e)=>t/e*100,at=t=>t<1?4:t<10?3:2,it=(t,e=r.DEFAULT_PRECISION)=>new u(t.toString()).shiftedBy(e).toFixed(0),ct=(t,e,n,s)=>new u(e).dividedBy(n).multipliedBy(t).shiftedBy(-(s||r.DEFAULT_PRECISION)).toNumber(),dt=t=>BigInt(new u(t||"0").shiftedBy(r.DEFAULT_PRECISION).toFixed(0,u.ROUND_DOWN)),M=t=>{const e=new u(.01),n=new u(t),s=!n.isZero()&&n.lt(e)?e:n;return BigInt(s.multipliedBy(100).toFixed(0))},ut=({vaultAddress:t,swapData:e,sendTokenAddress:n,sendTokenAmount:s,vaultDepositTokenAddress:o,minVaultTokensReceivedAmount:a,routerKey:i="ONE_INCH",swapDestinationAmount:d,swapSlippage:c})=>{const A=new u(d).multipliedBy(1-c/100).toFixed(0),g=[p.stringToHex(i,{size:32}),e];return[t,[[n,s,g],[o,A]],a]},At=({receiveAssetAddress:t,assets:e,swapData:n,slippage:s})=>{const o={srcData:[],destAmount:new u("0")},{srcData:a,destAmount:i}=e?.reduce((d,c)=>{const A=n?.[c.address];if(!A)return d;const g=[p.stringToHex(A.routerKey,{size:32}),A.rawTransaction.data],y=[c.address,c.rawBalance,g];return{srcData:[...d.srcData,y],destAmount:d.destAmount.plus(A.destinationAmount)}},o)??o;return[a,[t,i.times(1-s/100).toFixed(0,u.ROUND_DOWN)]]},P=({assetAddress:t,swapQuotes:e,swapParams:n,slippageToleranceForContractTransaction:s,routerKey:o})=>{if(!n)return{supportedAsset:t,withdrawData:"",slippageTolerance:BigInt(0)};const{srcData:a,dstData:i}=n,d=a.map(({asset:g,amount:y})=>{const D=e?.[O({sourceAddress:g,amount:y.toString()})]?.find(Z=>Z.routerKey===o);return{asset:g,amount:y,swapData:{routerKey:p.stringToHex(D?.routerKey??"",{size:32}),txData:D?.rawTransaction.data??"0x"}}}),c=p.encodeAbiParameters(r.ComplexWithdrawalAssetSrcDataAbiItem,[d]),A=p.encodeAbiParameters(r.ComplexWithdrawalDataAbiItem,[{encodedSrcData:c,dstData:{dstAddress:i.asset,dstAmount:i.amount},slippage:s}]);return{supportedAsset:t,withdrawData:A,slippageTolerance:s}},lt=(t,e)=>r.CHAIN_NATIVE_TOKENS[e]?.nativeTokenSymbol===t,mt=({nativeTokenBalance:t,tokenDecimals:e,gasPrice:n})=>{const s=new u(n).multipliedBy(r.NATIVE_TOKEN_DEPOSIT_GAS_LIMIT).shiftedBy(-e),o=new u(t).minus(s);return o.gt("0")?o:new u("0")},pt=t=>r.STABLE_TOKEN_SYMBOLS.includes(t),gt=t=>{const e=Object.values(t).reduce((n,{type:s})=>(n[s]=n[s]+1,n),{string:0,number:0});if(e.string>10)throw new Error("logger params must contain up to 10 string values");if(e.number>40)throw new Error("logger params must contain up to 40 numeric values");return!0},Tt=(t,e=150)=>t.length>e?t.substring(0,e):t,_=(t,e=r.TRANSACTION_ERROR_KEYS)=>{const n=t.toLowerCase();return e.sort((s,o)=>o.length-s.length).find(s=>n.includes(s.toLowerCase()))},I=t=>r.TRANSACTION_ERRORS[t]??r.LIMIT_ORDER_TRANSACTION_ERRORS[t],yt=({errorMessage:t,abiErrors:e})=>{if(!t||t.includes("User rejected"))return null;const n=e.find(a=>t.includes(a));if(n&&_(n))return I(n);const s=_(t);if(s)return I(s);const[o]=t.split(n?".":"Contract").map(a=>a.trim());return{title:"Transaction failed",hint:`${Tt(o??"")} ${n?`: ${n}`:""}`}},St=t=>typeof t=="number"&&Number.isFinite(t),Dt=t=>typeof t=="bigint"&&t!==BigInt(0),x=(t,e=r.DEFAULT_PRECISION$1)=>new u(t).shiftedBy(-e).toNumber(),F=t=>!isNaN(parseFloat(t))&&!isNaN(t),U=({value:t,minimumFractionDigits:e=2,maximumFractionDigits:n=2,compact:s=!1,normalize:o=!1})=>new Intl.NumberFormat("en-US",{style:"currency",currency:"USD",notation:s?"compact":void 0,minimumFractionDigits:e,maximumFractionDigits:n}).format(o?x(t):Number(t)),E=t=>F(t)?new u(t).toFixed():"",f=["₀","₁","₂","₃","₄","₅","₆","₇","₈","₉"],v=({value:t,decimals:e=4})=>{const n=new u(t);if(n.isGreaterThan(1)||n.isZero())return E(n.toFixed(e));const o=(/e/i.test(t.toString())?parseFloat(t.toString()).toFixed(r.DEFAULT_PRECISION$1):t.toString()).match(/^0\.(0+)(\d+)$/);if(o){const[,a,i]=o;if(a.length>=e&&a.length<f.length)return`0.0${f[a.length]}${i.slice(0,3)}`}return E(n.toFixed(e))},W=(t,e=0)=>`${t.toLocaleString("en-US",{maximumFractionDigits:e})}%`,_t=t=>t.toString().replace(/\B(?=(\d{3})+(?!\d))/g,","),Et=(t,e,n=0)=>{const s=L(+t,e);return W(s,n)},ht=({currency:t,value:e})=>t==="USD"?U({value:e}):`${r.CURRENCY_SYMBOL_MAP[t]} ${v({value:e,decimals:r.CURRENCY_DECIMALS_MAP[t]})}`,$=(t,e)=>new u(new u(t).toFixed(e,u.ROUND_DOWN)).toString(),G=(t,e=3,n=2)=>{if(t.length<=5)return t;const s="...";return t.length<=e+n+s.length?t:`${t.slice(0,e)}${s}${t.slice(-n)}`},It=({balance:t,symbol:e,precision:n,truncateSymbol:s})=>`${$(t,n)} ${s?G(e):e}`,ft=t=>{if(!t)return;const e=t.match(/0x[a-fA-F0-9]{64}/);if(!e)return;const n=e[0];return`${n.slice(0,4)}...${n.slice(-3)}`},Nt=t=>l(r.FLATMONEY_EARLY_DEPOSITOR_VAULT_ADDRESS_BASE,t)||l(r.FLATMONEY_DHT_STAKING_VAULT_ADDRESS_BASE,t),wt=t=>r.FLAT_MONEY_LEVERAGED_ASSET_ADDRESSES.some(e=>l(e,t)),bt=t=>r.FLAT_MONEY_COLLATERAL_MAP[t.toLowerCase()]??{symbol:"",decimals:18,address:r.AddressZero},Rt=t=>l(t,r.FLAT_MONEY_V1_UNIT_ADDRESS)?r.FLAT_MONEY_V1_UNIT_LINK:r.FLAT_MONEY_UNIT_LINK,H=t=>`eth_${t}`,Ct=({action:t,log:e,symbol:n,vaultAddress:s,chainId:o})=>{const a={[r.TRADING_LOG_EVENT_PARAM.SYMBOL.NAME]:n,[r.TRADING_LOG_EVENT_PARAM.CHAIN_ID.NAME]:o,[r.TRADING_LOG_EVENT_PARAM.ADDRESS.NAME]:H(s)};r.LOG_EVENT_BY_TRANSACTION_ACTION_MAP[t].forEach(i=>{e?.(i,a)})},Bt=t=>r.GMX_MARKET_ASSETS.some(e=>l(e,t)),Ot=t=>r.GMX_WITHDRAW_ASSET_MAP[t.toLowerCase()]??{symbol:"",decimals:18,address:r.AddressZero},Lt=t=>r.GMX_WITHDRAW_ASSET_MAP_BY_VAULT_ADDRESS[t.toLowerCase()],V="0x3333333333333333333333333333333333333333";T.arbitrum.id+"",r.USDC_ARBITRUM.address,T.base.id+"",r.USDC_BASE.address,T.optimism.id+"",r.USDC_OPTIMISM.address,T.polygon.id+"",r.USDC_POLYGON.address,T.mainnet.id+"",r.USDC_MAINNET.address,T.hyperEvm.id+"",r.USDC_HYPEREVM.address;const Mt=t=>l(t,V),Pt=()=>r.USDC_HYPEREVM,xt=new Map,h=(t,e)=>!e||e.size===0?t:t.map(n=>{const s=e.get(n.supportedAsset.toLowerCase());return s?{...n,withdrawData:s}:n}),q=t=>{const e=t.find(({swapQuotes:n})=>n);return e?.swapQuotes?Object.values(e.swapQuotes)[0]?.map(({routerKey:n})=>n)??[]:[]},Y=(t,e,n)=>t.map(({asset:s,swapParams:o,swapQuotes:a})=>!o||!a?{supportedAsset:s,withdrawData:"",slippageTolerance:n}:P({assetAddress:s,swapQuotes:a,swapParams:o,slippageToleranceForContractTransaction:n,routerKey:e})),K=async(t,e,n,s,o,a)=>{for(const i of t){const d=h(Y(e,i,n),a),{error:c}=await s(...o,d);if(!c)return d}return null},Ft=(t,e,n)=>{const s=(t??[]).map(o=>({supportedAsset:o,withdrawData:"",slippageTolerance:e}));return h(s,n)},Ut=async(t,e,n,s,o)=>{for(const a of t){const i=M(a);try{const d=await e(a),c=q(d),A=await K(c,d,i,n,s,o);if(A)return console.debug(`[Init Withdraw] Auto slippage simulation succeeded: slippage=${a}%`),console.debug("[Init Withdraw] Complex asset data:",A),A}catch(d){console.error(`[Init Withdraw] Failed to fetch quotes for slippage=${a}%:`,d)}}return null},vt=async(t,e,{fetchAaveSwapParams:n,fetchAaveSwapQuotes:s,withdrawAmountD18:o,slippage:a})=>Promise.all((t??[]).map(async i=>{if(!l(i,e))return{asset:i};try{const c=await n({withdrawAmountD18:o,slippage:a});if(c?.srcData.length){const A=await s({swapParams:c,slippage:a});return{asset:i,swapParams:c,swapQuotes:A}}return{asset:i}}catch(c){return console.error(c),{asset:i}}})),N=t=>Math.round(t*100)/100,Wt=({maxSlippage:t,candidates:e=r.SLIPPAGE_AUTO_SIMULATION_CANDIDATES})=>{if(!Number.isFinite(t)||t<=0)return[];const n=N(Math.min(t,100)),s=e.filter(a=>a>0&&a<=n).map(N),o=new Set(s);return o.add(n),o.add(t),Array.from(o).sort((a,i)=>a-i)},w=1000000000000000000n,$t=1000000n,b=10000n,R=100n,S=t=>{if(!t)throw new Error("Ondo: empty hex value");return t.startsWith("0x")?t:`0x${t}`},m=(t,e)=>{try{return BigInt(t)}catch{throw new Error(`Ondo: cannot convert "${e}" value "${t}" to bigint`)}},C=t=>t?p.pad(S(t),{size:32}):p.zeroHash,k=t=>{if(!t)throw new Error("Ondo: empty signature");return p.bytesToHex(Uint8Array.from(atob(t),e=>e.charCodeAt(0)))},Gt=t=>({quotes:t.quotes.map(e=>({chainId:m(e.chainId,"chainId"),attestationId:m(e.attestationId,"attestationId"),userId:S(e.userId),asset:e.asset,price:m(e.price,"price"),quantity:m(e.quantity,"quantity"),expiration:m(e.expiration,"expiration"),side:Number(e.side),additionalData:S(e.additionalData)})),signatures:t.signatures.map(S)}),Ht=(t,e,n)=>{const s=BigInt(Math.max(0,Math.round(n*100))),o=s>R?R:s,a=b-o,d=t*e/w*a*$t,c=b*w;return(d+c-1n)/c},Vt=({attestation:t,chainId:e,slippagePercent:n})=>{const s=m(t.tokenAmount,"tokenAmount"),o=m(t.price,"price");return p.encodeAbiParameters(j,[{attestationSignature:k(t.signature),quote:{chainId:e,attestationId:m(t.attestationId,"attestationId"),userId:C(t.userId),asset:t.assetAddress,price:o,quantity:s,expiration:m(t.expiration,"expiration"),side:Number(t.side),additionalData:C(t.additionalData)},amountOutMinimum:Ht(s,o,n)}])};exports.EMPTY_PER_ASSET_WITHDRAW_DATA=xt;exports.HYPERLIQUID_PERPS_ACCOUNT_ADDRESS=V;exports.OndoGMTokenAssetGuardAbi=z;exports.addTokenToWallet=tt;exports.base64SignatureToHex=k;exports.buildAaveWithdrawAssetTransactionData=P;exports.buildComplexAssetDataForRouter=Y;exports.buildSwapQuoteKeyForAave=O;exports.buildSwapWithdrawTransactionData=At;exports.buildZapDepositTransactionArguments=ut;exports.clientSide=Q;exports.commify=_t;exports.createDefaultComplexAssetData=Ft;exports.encodeOndoWithdrawData=Vt;exports.enrichAssetsWithSwapQuotes=vt;exports.extractAvailableRouterKeys=q;exports.formatBalance=$;exports.formatByCurrency=ht;exports.formatNumberToLimitedDecimals=v;exports.formatNumeratorToPercentage=Et;exports.formatPercentage=W;exports.formatToUsd=U;exports.formatTokenBalance=It;exports.getAutoSlippageSimulationCandidates=Wt;exports.getContractAbiById=nt;exports.getContractAddressById=B;exports.getConventionalTokenPriceDecimals=at;exports.getErrorKey=_;exports.getFlatMoneyCollateralByLeverageAddress=bt;exports.getFlatMoneyLinkByUnitAddress=Rt;exports.getGmxWithdrawAssetByLeverageAddress=Ot;exports.getGmxWithdrawAssetByVaultAddress=Lt;exports.getHyperliquidWithdrawAsset=Pt;exports.getNativeTokenInvestableBalance=mt;exports.getPercent=L;exports.getPoolFraction=ct;exports.getSlippageToleranceForContractTransaction=M;exports.getTxHashShort=ft;exports.isAaveLendAndBorrowAsset=rt;exports.isEqualAddress=l;exports.isFlatMoneyLeveragedAsset=wt;exports.isFmpAirdropVaultAddress=Nt;exports.isGmxLeveragedAsset=Bt;exports.isHyperliquidPerpsAsset=Mt;exports.isNativeToken=lt;exports.isNumberType=St;exports.isNumeric=F;exports.isStableSymbol=pt;exports.isZeroAddress=et;exports.logTransactionByActionType=Ct;exports.mapOndoApiResponseToUpdatePricesArgs=Gt;exports.nonZeroBigInt=Dt;exports.normalizeNumber=x;exports.overlayWithdrawData=h;exports.parseAmountToD18=dt;exports.parseContractErrorMessage=yt;exports.removeInsignificantTrailingZeros=E;exports.shiftBy=it;exports.shortenAddress=st;exports.sliceByIndex=ot;exports.transformAddressForAnalytics=H;exports.truncateString=G;exports.tryEstimateWithRouters=K;exports.tryEstimateWithSlippageValues=Ut;exports.validateLoggerEventParams=gt;
package/ondo-v5VUY6Q9.js DELETED
@@ -1,520 +0,0 @@
1
- import d from "bignumber.js";
2
- import { al as P, aj as U, ak as F, a as D, p as _, am as W, an as $, a2 as v, b as V, a8 as Y, ae as G, ad as H, Y as K, ao as C, e as q, d as k, L as Z, Q as z, O as Q, ap as j, aq as X, P as J, M as tt, ab as S, Z as et, V as st, W as nt, T as at, ar as L, as as rt, at as ot, au as it, av as ct, aw as dt, a7 as ut } from "./gmx-Cu3Ax-nZ.js";
3
- import { stringToHex as f, encodeAbiParameters as y, bytesToHex as lt, zeroHash as mt, pad as pt } from "viem";
4
- import { hyperEvm as At, mainnet as gt, polygon as Tt, optimism as St, base as yt, arbitrum as Dt } from "wagmi/chains";
5
- const Zt = typeof window < "u", zt = [
6
- {
7
- inputs: [
8
- { internalType: "address", name: "_pool", type: "address" },
9
- { internalType: "address", name: "_asset", type: "address" },
10
- { internalType: "uint256", name: "_poolTokenAmount", type: "uint256" }
11
- ],
12
- name: "previewGmTokenAmount",
13
- outputs: [
14
- { internalType: "uint256", name: "gmTokenAmount", type: "uint256" }
15
- ],
16
- stateMutability: "nonpayable",
17
- type: "function"
18
- }
19
- ], _t = [
20
- {
21
- type: "tuple",
22
- components: [
23
- { name: "attestationSignature", type: "bytes" },
24
- {
25
- name: "quote",
26
- type: "tuple",
27
- components: [
28
- { name: "chainId", type: "uint256" },
29
- { name: "attestationId", type: "uint256" },
30
- { name: "userId", type: "bytes32" },
31
- { name: "asset", type: "address" },
32
- { name: "price", type: "uint256" },
33
- { name: "quantity", type: "uint256" },
34
- { name: "expiration", type: "uint256" },
35
- { name: "side", type: "uint8" },
36
- { name: "additionalData", type: "bytes32" }
37
- ]
38
- },
39
- { name: "amountOutMinimum", type: "uint256" }
40
- ]
41
- }
42
- ], ft = () => typeof window < "u";
43
- function Et() {
44
- return ft() && typeof window.ethereum < "u";
45
- }
46
- async function Qt(t) {
47
- try {
48
- if (Et())
49
- return window.ethereum.request({
50
- method: "wallet_watchAsset",
51
- params: {
52
- type: "ERC20",
53
- options: t
54
- }
55
- });
56
- } catch {
57
- return !1;
58
- }
59
- return !1;
60
- }
61
- const m = (t, e) => t?.toLowerCase() === e?.toLowerCase(), jt = (t) => m(t, P), ht = (t, e) => F[e]?.[t] ?? D, Xt = (t) => U[t], Jt = (t) => t && `${t.substring(0, 6)}...${t.substring(
62
- t.length - 4,
63
- t.length
64
- )}`, te = ({
65
- address: t,
66
- chainId: e
67
- }) => {
68
- const s = ht(
69
- "aaveLendingPoolV3",
70
- e
71
- );
72
- return m(t, s);
73
- }, wt = ({
74
- sourceAddress: t,
75
- amount: e
76
- }) => `${t}_${e}`, ee = (t, e) => {
77
- const s = t.slice(0, e), n = t.slice(e);
78
- return { firstPart: s, secondPart: n };
79
- }, It = (t, e) => t / e * 100, se = (t) => t < 1 ? 4 : t < 10 ? 3 : 2, ne = (t, e = _) => new d(t.toString()).shiftedBy(e).toFixed(0), ae = (t, e, s, n) => new d(e).dividedBy(s).multipliedBy(t).shiftedBy(-(n || _)).toNumber(), re = (t) => BigInt(
80
- new d(t || "0").shiftedBy(_).toFixed(0, d.ROUND_DOWN)
81
- ), Nt = (t) => {
82
- const e = new d(0.01), s = new d(t), n = !s.isZero() && s.lt(e) ? e : s;
83
- return BigInt(n.multipliedBy(100).toFixed(0));
84
- }, oe = ({
85
- vaultAddress: t,
86
- swapData: e,
87
- sendTokenAddress: s,
88
- sendTokenAmount: n,
89
- vaultDepositTokenAddress: a,
90
- minVaultTokensReceivedAmount: r,
91
- routerKey: o = "ONE_INCH",
92
- swapDestinationAmount: c,
93
- swapSlippage: i
94
- }) => {
95
- const u = new d(c).multipliedBy(1 - i / 100).toFixed(0), p = [f(o, { size: 32 }), e];
96
- return [t, [[s, n, p], [a, u]], r];
97
- }, ie = ({
98
- receiveAssetAddress: t,
99
- assets: e,
100
- swapData: s,
101
- slippage: n
102
- }) => {
103
- const a = {
104
- srcData: [],
105
- destAmount: new d("0")
106
- }, { srcData: r, destAmount: o } = e?.reduce((c, i) => {
107
- const u = s?.[i.address];
108
- if (!u)
109
- return c;
110
- const p = [
111
- f(u.routerKey, { size: 32 }),
112
- u.rawTransaction.data
113
- ], A = [i.address, i.rawBalance, p];
114
- return {
115
- srcData: [...c.srcData, A],
116
- destAmount: c.destAmount.plus(u.destinationAmount)
117
- };
118
- }, a) ?? a;
119
- return [
120
- r,
121
- [
122
- t,
123
- o.times(1 - n / 100).toFixed(0, d.ROUND_DOWN)
124
- ]
125
- ];
126
- }, Ot = ({
127
- assetAddress: t,
128
- swapQuotes: e,
129
- swapParams: s,
130
- slippageToleranceForContractTransaction: n,
131
- routerKey: a
132
- }) => {
133
- if (!s)
134
- return {
135
- supportedAsset: t,
136
- withdrawData: "",
137
- slippageTolerance: BigInt(0)
138
- };
139
- const { srcData: r, dstData: o } = s, c = r.map(({ asset: p, amount: A }) => {
140
- const T = e?.[wt({
141
- sourceAddress: p,
142
- amount: A.toString()
143
- })]?.find((x) => x.routerKey === a);
144
- return {
145
- asset: p,
146
- amount: A,
147
- swapData: {
148
- routerKey: f(T?.routerKey ?? "", { size: 32 }),
149
- txData: T?.rawTransaction.data ?? "0x"
150
- }
151
- };
152
- }), i = y(
153
- W,
154
- [c]
155
- ), u = y($, [
156
- {
157
- encodedSrcData: i,
158
- dstData: {
159
- dstAddress: o.asset,
160
- dstAmount: o.amount
161
- },
162
- slippage: n
163
- }
164
- ]);
165
- return {
166
- supportedAsset: t,
167
- withdrawData: u,
168
- slippageTolerance: n
169
- };
170
- }, ce = (t, e) => V[e]?.nativeTokenSymbol === t, de = ({
171
- nativeTokenBalance: t,
172
- tokenDecimals: e,
173
- gasPrice: s
174
- }) => {
175
- const n = new d(s).multipliedBy(v).shiftedBy(-e), a = new d(t).minus(
176
- n
177
- );
178
- return a.gt("0") ? a : new d("0");
179
- }, ue = (t) => Y.includes(t), le = (t) => {
180
- const e = Object.values(t).reduce(
181
- (s, { type: n }) => (s[n] = s[n] + 1, s),
182
- { string: 0, number: 0 }
183
- );
184
- if (e.string > 10)
185
- throw new Error("logger params must contain up to 10 string values");
186
- if (e.number > 40)
187
- throw new Error("logger params must contain up to 40 numeric values");
188
- return !0;
189
- }, bt = (t, e = 150) => t.length > e ? t.substring(0, e) : t, E = (t, e = G) => {
190
- const s = t.toLowerCase();
191
- return e.sort((n, a) => a.length - n.length).find((n) => s.includes(n.toLowerCase()));
192
- }, h = (t) => H[t] ?? K[t], me = ({
193
- errorMessage: t,
194
- abiErrors: e
195
- }) => {
196
- if (!t || t.includes("User rejected"))
197
- return null;
198
- const s = e.find((r) => t.includes(r));
199
- if (s && E(s))
200
- return h(s);
201
- const n = E(t);
202
- if (n)
203
- return h(n);
204
- const [a] = t.split(s ? "." : "Contract").map((r) => r.trim());
205
- return {
206
- title: "Transaction failed",
207
- hint: `${bt(a ?? "")} ${s ? `: ${s}` : ""}`
208
- };
209
- }, pe = (t) => typeof t == "number" && Number.isFinite(t), Ae = (t) => typeof t == "bigint" && t !== BigInt(0), Rt = (t, e = C) => new d(t).shiftedBy(-e).toNumber(), Bt = (t) => !isNaN(parseFloat(t)) && !isNaN(t), Ct = ({
210
- value: t,
211
- minimumFractionDigits: e = 2,
212
- maximumFractionDigits: s = 2,
213
- compact: n = !1,
214
- normalize: a = !1
215
- }) => new Intl.NumberFormat("en-US", {
216
- style: "currency",
217
- currency: "USD",
218
- notation: n ? "compact" : void 0,
219
- minimumFractionDigits: e,
220
- maximumFractionDigits: s
221
- }).format(a ? Rt(t) : Number(t)), w = (t) => Bt(t) ? new d(t).toFixed() : "", I = ["₀", "₁", "₂", "₃", "₄", "₅", "₆", "₇", "₈", "₉"], Lt = ({
222
- value: t,
223
- decimals: e = 4
224
- }) => {
225
- const s = new d(t);
226
- if (s.isGreaterThan(1) || s.isZero())
227
- return w(s.toFixed(e));
228
- const a = (/e/i.test(t.toString()) ? parseFloat(t.toString()).toFixed(C) : t.toString()).match(/^0\.(0+)(\d+)$/);
229
- if (a) {
230
- const [, r, o] = a;
231
- if (r.length >= e && r.length < I.length)
232
- return `0.0${I[r.length]}${o.slice(0, 3)}`;
233
- }
234
- return w(s.toFixed(e));
235
- }, Mt = (t, e = 0) => `${t.toLocaleString("en-US", { maximumFractionDigits: e })}%`, ge = (t) => t.toString().replace(/\B(?=(\d{3})+(?!\d))/g, ","), Te = (t, e, s = 0) => {
236
- const n = It(+t, e);
237
- return Mt(n, s);
238
- }, Se = ({
239
- currency: t,
240
- value: e
241
- }) => t === "USD" ? Ct({ value: e }) : `${q[t]} ${Lt({
242
- value: e,
243
- decimals: k[t]
244
- })}`, xt = (t, e) => new d(
245
- new d(t).toFixed(e, d.ROUND_DOWN)
246
- ).toString(), Pt = (t, e = 3, s = 2) => {
247
- if (t.length <= 5)
248
- return t;
249
- const n = "...";
250
- return t.length <= e + s + n.length ? t : `${t.slice(0, e)}${n}${t.slice(-s)}`;
251
- }, ye = ({
252
- balance: t,
253
- symbol: e,
254
- precision: s,
255
- truncateSymbol: n
256
- }) => `${xt(t, s)} ${n ? Pt(e) : e}`, De = (t) => {
257
- if (!t)
258
- return;
259
- const e = t.match(/0x[a-fA-F0-9]{64}/);
260
- if (!e)
261
- return;
262
- const s = e[0];
263
- return `${s.slice(0, 4)}...${s.slice(-3)}`;
264
- }, _e = (t) => m(j, t) || m(X, t), fe = (t) => tt.some(
265
- (e) => m(e, t)
266
- ), Ee = (t) => Z[t.toLowerCase()] ?? {
267
- symbol: "",
268
- decimals: 18,
269
- address: D
270
- }, he = (t) => m(t, J) ? z : Q, Ut = (t) => `eth_${t}`, we = ({
271
- action: t,
272
- log: e,
273
- symbol: s,
274
- vaultAddress: n,
275
- chainId: a
276
- }) => {
277
- const r = {
278
- [S.SYMBOL.NAME]: s,
279
- [S.CHAIN_ID.NAME]: a,
280
- [S.ADDRESS.NAME]: Ut(n)
281
- };
282
- et[t].forEach((o) => {
283
- e?.(o, r);
284
- });
285
- }, Ie = (t) => at.some((e) => m(e, t)), Ne = (t) => st[t.toLowerCase()] ?? {
286
- symbol: "",
287
- decimals: 18,
288
- address: D
289
- }, Oe = (t) => nt[t.toLowerCase()], Ft = "0x3333333333333333333333333333333333333333";
290
- Dt.id + "", dt.address, yt.id + "", ct.address, St.id + "", it.address, Tt.id + "", ot.address, gt.id + "", rt.address, At.id + "", L.address;
291
- const be = (t) => m(t, Ft), Re = () => L, Be = /* @__PURE__ */ new Map(), M = (t, e) => !e || e.size === 0 ? t : t.map((s) => {
292
- const n = e.get(
293
- s.supportedAsset.toLowerCase()
294
- );
295
- return n ? { ...s, withdrawData: n } : s;
296
- }), Wt = (t) => {
297
- const e = t.find(
298
- ({ swapQuotes: s }) => s
299
- );
300
- return e?.swapQuotes ? Object.values(e.swapQuotes)[0]?.map(
301
- ({ routerKey: s }) => s
302
- ) ?? [] : [];
303
- }, $t = (t, e, s) => t.map(({ asset: n, swapParams: a, swapQuotes: r }) => !a || !r ? {
304
- supportedAsset: n,
305
- withdrawData: "",
306
- slippageTolerance: s
307
- } : Ot({
308
- assetAddress: n,
309
- swapQuotes: r,
310
- swapParams: a,
311
- slippageToleranceForContractTransaction: s,
312
- routerKey: e
313
- })), vt = async (t, e, s, n, a, r) => {
314
- for (const o of t) {
315
- const c = M(
316
- $t(
317
- e,
318
- o,
319
- s
320
- ),
321
- r
322
- ), { error: i } = await n(...a, c);
323
- if (!i)
324
- return c;
325
- }
326
- return null;
327
- }, Ce = (t, e, s) => {
328
- const n = (t ?? []).map((a) => ({
329
- supportedAsset: a,
330
- withdrawData: "",
331
- slippageTolerance: e
332
- }));
333
- return M(n, s);
334
- }, Le = async (t, e, s, n, a) => {
335
- for (const r of t) {
336
- const o = Nt(r);
337
- try {
338
- const c = await e(r), i = Wt(
339
- c
340
- ), u = await vt(
341
- i,
342
- c,
343
- o,
344
- s,
345
- n,
346
- a
347
- );
348
- if (u)
349
- return console.debug(
350
- `[Init Withdraw] Auto slippage simulation succeeded: slippage=${r}%`
351
- ), console.debug("[Init Withdraw] Complex asset data:", u), u;
352
- } catch (c) {
353
- console.error(
354
- `[Init Withdraw] Failed to fetch quotes for slippage=${r}%:`,
355
- c
356
- );
357
- }
358
- }
359
- return null;
360
- }, Me = async (t, e, {
361
- fetchAaveSwapParams: s,
362
- fetchAaveSwapQuotes: n,
363
- withdrawAmountD18: a,
364
- slippage: r
365
- }) => Promise.all(
366
- (t ?? []).map(async (o) => {
367
- if (!m(o, e))
368
- return { asset: o };
369
- try {
370
- const i = await s({
371
- withdrawAmountD18: a,
372
- slippage: r
373
- });
374
- if (i?.srcData.length) {
375
- const u = await n({
376
- swapParams: i,
377
- slippage: r
378
- });
379
- return { asset: o, swapParams: i, swapQuotes: u };
380
- }
381
- return { asset: o };
382
- } catch (i) {
383
- return console.error(i), { asset: o };
384
- }
385
- })
386
- ), N = (t) => Math.round(t * 100) / 100, xe = ({
387
- maxSlippage: t,
388
- candidates: e = ut
389
- }) => {
390
- if (!Number.isFinite(t) || t <= 0)
391
- return [];
392
- const s = N(Math.min(t, 100)), n = e.filter((r) => r > 0 && r <= s).map(N), a = new Set(n);
393
- return a.add(s), a.add(t), Array.from(a).sort((r, o) => r - o);
394
- }, O = 1000000000000000000n, Vt = 1000000n, b = 10000n, R = 100n, g = (t) => {
395
- if (!t) throw new Error("Ondo: empty hex value");
396
- return t.startsWith("0x") ? t : `0x${t}`;
397
- }, l = (t, e) => {
398
- try {
399
- return BigInt(t);
400
- } catch {
401
- throw new Error(
402
- `Ondo: cannot convert "${e}" value "${t}" to bigint`
403
- );
404
- }
405
- }, B = (t) => t ? pt(g(t), { size: 32 }) : mt, Yt = (t) => {
406
- if (!t) throw new Error("Ondo: empty signature");
407
- return lt(Uint8Array.from(atob(t), (e) => e.charCodeAt(0)));
408
- }, Pe = (t) => ({
409
- quotes: t.quotes.map(
410
- (e) => ({
411
- chainId: l(e.chainId, "chainId"),
412
- attestationId: l(e.attestationId, "attestationId"),
413
- userId: g(e.userId),
414
- asset: e.asset,
415
- price: l(e.price, "price"),
416
- quantity: l(e.quantity, "quantity"),
417
- expiration: l(e.expiration, "expiration"),
418
- side: Number(e.side),
419
- additionalData: g(e.additionalData)
420
- })
421
- ),
422
- signatures: t.signatures.map(g)
423
- }), Gt = (t, e, s) => {
424
- const n = BigInt(Math.max(0, Math.round(s * 100))), a = n > R ? R : n, r = b - a, c = t * e / O * r * Vt, i = b * O;
425
- return (c + i - 1n) / i;
426
- }, Ue = ({
427
- attestation: t,
428
- chainId: e,
429
- slippagePercent: s
430
- }) => {
431
- const n = l(t.tokenAmount, "tokenAmount"), a = l(t.price, "price");
432
- return y(_t, [
433
- {
434
- attestationSignature: Yt(t.signature),
435
- quote: {
436
- chainId: e,
437
- attestationId: l(t.attestationId, "attestationId"),
438
- userId: B(t.userId),
439
- asset: t.assetAddress,
440
- price: a,
441
- quantity: n,
442
- expiration: l(t.expiration, "expiration"),
443
- side: Number(t.side),
444
- additionalData: B(t.additionalData)
445
- },
446
- amountOutMinimum: Gt(
447
- n,
448
- a,
449
- s
450
- )
451
- }
452
- ]);
453
- };
454
- export {
455
- m as $,
456
- It as A,
457
- ae as B,
458
- Nt as C,
459
- De as D,
460
- Be as E,
461
- te as F,
462
- fe as G,
463
- _e as H,
464
- Ie as I,
465
- be as J,
466
- ce as K,
467
- ue as L,
468
- we as M,
469
- Pe as N,
470
- M as O,
471
- re as P,
472
- me as Q,
473
- ne as R,
474
- Jt as S,
475
- ee as T,
476
- Ut as U,
477
- Pt as V,
478
- vt as W,
479
- Le as X,
480
- le as Y,
481
- jt as Z,
482
- pe as _,
483
- Ot as a,
484
- Ct as a0,
485
- Ae as a1,
486
- Rt as a2,
487
- zt as a3,
488
- Ft as a4,
489
- Lt as a5,
490
- Qt as a6,
491
- Mt as a7,
492
- Bt as a8,
493
- ge as a9,
494
- w as aa,
495
- Yt as b,
496
- $t as c,
497
- wt as d,
498
- ie as e,
499
- oe as f,
500
- Zt as g,
501
- Ce as h,
502
- Ue as i,
503
- Me as j,
504
- Wt as k,
505
- xt as l,
506
- Se as m,
507
- Te as n,
508
- ye as o,
509
- xe as p,
510
- Xt as q,
511
- ht as r,
512
- se as s,
513
- E as t,
514
- Ee as u,
515
- he as v,
516
- Ne as w,
517
- Oe as x,
518
- Re as y,
519
- de as z
520
- };