@dhedge/trading-widget 6.0.3 → 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-BnkOJgHw.cjs DELETED
@@ -1 +0,0 @@
1
- "use strict";const u=require("bignumber.js"),r=require("./gmx-DVJxXc_8.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),O=(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=O("aaveLendingPoolV3",e);return l(t,n)},B=({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)),P=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)]]},M=({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?.[B({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()))},h=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 h(n);const s=_(t);if(s)return h(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():"",N=["₀","₁","₂","₃","₄","₅","₆","₇","₈","₉"],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<N.length)return`0.0${N[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)},It=({currency:t,value:e})=>t==="USD"?U({value:e}):`${r.CURRENCY_SYMBOL_MAP[t]} ${v({value:e,decimals:r.CURRENCY_DECIMALS_MAP[t]})}`,G=(t,e)=>new u(new u(t).toFixed(e,u.ROUND_DOWN)).toString(),$=(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)}`},ht=({balance:t,symbol:e,precision:n,truncateSymbol:s})=>`${G(t,n)} ${s?$(e):e}`,Nt=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)}`},ft=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)})},Ot=t=>r.GMX_MARKET_ASSETS.some(e=>l(e,t)),Bt=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 Pt=t=>l(t,V),Mt=()=>r.USDC_HYPEREVM,xt=new Map,I=(t,e)=>!e||e.size===0?t:t.map(n=>{const s=e.get(n.supportedAsset.toLowerCase());return s?{...n,withdrawData:s,slippageTolerance:r.DEFAULT_ONDO_WITHDRAWAL_CONTRACT_SLIPPAGE}: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}:M({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=I(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 I(s,n)},Ut=async(t,e,n,s,o)=>{for(const a of t){const i=P(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}}})),f=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=f(Math.min(t,100)),s=e.filter(a=>a>0&&a<=n).map(f),o=new Set(s);return o.add(n),o.add(t),Array.from(o).sort((a,i)=>a-i)},w=1000000000000000000n,Gt=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)))},$t=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*Gt,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=M;exports.buildComplexAssetDataForRouter=Y;exports.buildSwapQuoteKeyForAave=B;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=G;exports.formatByCurrency=It;exports.formatNumberToLimitedDecimals=v;exports.formatNumeratorToPercentage=Et;exports.formatPercentage=W;exports.formatToUsd=U;exports.formatTokenBalance=ht;exports.getAutoSlippageSimulationCandidates=Wt;exports.getContractAbiById=nt;exports.getContractAddressById=O;exports.getConventionalTokenPriceDecimals=at;exports.getErrorKey=_;exports.getFlatMoneyCollateralByLeverageAddress=bt;exports.getFlatMoneyLinkByUnitAddress=Rt;exports.getGmxWithdrawAssetByLeverageAddress=Bt;exports.getGmxWithdrawAssetByVaultAddress=Lt;exports.getHyperliquidWithdrawAsset=Mt;exports.getNativeTokenInvestableBalance=mt;exports.getPercent=L;exports.getPoolFraction=ct;exports.getSlippageToleranceForContractTransaction=P;exports.getTxHashShort=Nt;exports.isAaveLendAndBorrowAsset=rt;exports.isEqualAddress=l;exports.isFlatMoneyLeveragedAsset=wt;exports.isFmpAirdropVaultAddress=ft;exports.isGmxLeveragedAsset=Ot;exports.isHyperliquidPerpsAsset=Pt;exports.isNativeToken=lt;exports.isNumberType=St;exports.isNumeric=F;exports.isStableSymbol=pt;exports.isZeroAddress=et;exports.logTransactionByActionType=Ct;exports.mapOndoApiResponseToUpdatePricesArgs=$t;exports.nonZeroBigInt=Dt;exports.normalizeNumber=x;exports.overlayWithdrawData=I;exports.parseAmountToD18=dt;exports.parseContractErrorMessage=yt;exports.removeInsignificantTrailingZeros=E;exports.shiftBy=it;exports.shortenAddress=st;exports.sliceByIndex=ot;exports.transformAddressForAnalytics=H;exports.truncateString=$;exports.tryEstimateWithRouters=K;exports.tryEstimateWithSlippageValues=Ut;exports.validateLoggerEventParams=gt;
package/ondo-Cl97ID2o.js DELETED
@@ -1,525 +0,0 @@
1
- import d from "bignumber.js";
2
- import { am as x, ak as U, al as F, a as D, q as y, an as W, ao as $, a3 as v, b as G, a9 as V, af as Y, ae as H, Z as q, ap as L, e as K, d as k, M as Z, R as z, P as Q, aq as X, ar as j, Q as J, N as tt, ac as S, _ as et, W as st, X as at, U as nt, as as B, at as rt, au as ot, av as it, aw as ct, ax as dt, o as ut, a8 as lt } from "./gmx-C9vHHvqC.js";
3
- import { stringToHex as f, encodeAbiParameters as _, bytesToHex as mt, zeroHash as pt, pad as At } from "viem";
4
- import { hyperEvm as Tt, mainnet as gt, polygon as St, optimism as _t, base as Dt, arbitrum as yt } from "wagmi/chains";
5
- const zt = typeof window < "u", Qt = [
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
- ], ft = [
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
- ], Et = () => typeof window < "u";
43
- function It() {
44
- return Et() && typeof window.ethereum < "u";
45
- }
46
- async function Xt(t) {
47
- try {
48
- if (It())
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, x), ht = (t, e) => F[e]?.[t] ?? D, Jt = (t) => U[t], te = (t) => t && `${t.substring(0, 6)}...${t.substring(
62
- t.length - 4,
63
- t.length
64
- )}`, ee = ({
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}`, se = (t, e) => {
77
- const s = t.slice(0, e), a = t.slice(e);
78
- return { firstPart: s, secondPart: a };
79
- }, Nt = (t, e) => t / e * 100, ae = (t) => t < 1 ? 4 : t < 10 ? 3 : 2, ne = (t, e = y) => new d(t.toString()).shiftedBy(e).toFixed(0), re = (t, e, s, a) => new d(e).dividedBy(s).multipliedBy(t).shiftedBy(-(a || y)).toNumber(), oe = (t) => BigInt(
80
- new d(t || "0").shiftedBy(y).toFixed(0, d.ROUND_DOWN)
81
- ), Ot = (t) => {
82
- const e = new d(0.01), s = new d(t), a = !s.isZero() && s.lt(e) ? e : s;
83
- return BigInt(a.multipliedBy(100).toFixed(0));
84
- }, ie = ({
85
- vaultAddress: t,
86
- swapData: e,
87
- sendTokenAddress: s,
88
- sendTokenAmount: a,
89
- vaultDepositTokenAddress: n,
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, a, p], [n, u]], r];
97
- }, ce = ({
98
- receiveAssetAddress: t,
99
- assets: e,
100
- swapData: s,
101
- slippage: a
102
- }) => {
103
- const n = {
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
- }, n) ?? n;
119
- return [
120
- r,
121
- [
122
- t,
123
- o.times(1 - a / 100).toFixed(0, d.ROUND_DOWN)
124
- ]
125
- ];
126
- }, bt = ({
127
- assetAddress: t,
128
- swapQuotes: e,
129
- swapParams: s,
130
- slippageToleranceForContractTransaction: a,
131
- routerKey: n
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 g = e?.[wt({
141
- sourceAddress: p,
142
- amount: A.toString()
143
- })]?.find((P) => P.routerKey === n);
144
- return {
145
- asset: p,
146
- amount: A,
147
- swapData: {
148
- routerKey: f(g?.routerKey ?? "", { size: 32 }),
149
- txData: g?.rawTransaction.data ?? "0x"
150
- }
151
- };
152
- }), i = _(
153
- W,
154
- [c]
155
- ), u = _($, [
156
- {
157
- encodedSrcData: i,
158
- dstData: {
159
- dstAddress: o.asset,
160
- dstAmount: o.amount
161
- },
162
- slippage: a
163
- }
164
- ]);
165
- return {
166
- supportedAsset: t,
167
- withdrawData: u,
168
- slippageTolerance: a
169
- };
170
- }, de = (t, e) => G[e]?.nativeTokenSymbol === t, ue = ({
171
- nativeTokenBalance: t,
172
- tokenDecimals: e,
173
- gasPrice: s
174
- }) => {
175
- const a = new d(s).multipliedBy(v).shiftedBy(-e), n = new d(t).minus(
176
- a
177
- );
178
- return n.gt("0") ? n : new d("0");
179
- }, le = (t) => V.includes(t), me = (t) => {
180
- const e = Object.values(t).reduce(
181
- (s, { type: a }) => (s[a] = s[a] + 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
- }, Rt = (t, e = 150) => t.length > e ? t.substring(0, e) : t, E = (t, e = Y) => {
190
- const s = t.toLowerCase();
191
- return e.sort((a, n) => n.length - a.length).find((a) => s.includes(a.toLowerCase()));
192
- }, I = (t) => H[t] ?? q[t], pe = ({
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 I(s);
201
- const a = E(t);
202
- if (a)
203
- return I(a);
204
- const [n] = t.split(s ? "." : "Contract").map((r) => r.trim());
205
- return {
206
- title: "Transaction failed",
207
- hint: `${Rt(n ?? "")} ${s ? `: ${s}` : ""}`
208
- };
209
- }, Ae = (t) => typeof t == "number" && Number.isFinite(t), Te = (t) => typeof t == "bigint" && t !== BigInt(0), Ct = (t, e = L) => new d(t).shiftedBy(-e).toNumber(), Lt = (t) => !isNaN(parseFloat(t)) && !isNaN(t), Bt = ({
210
- value: t,
211
- minimumFractionDigits: e = 2,
212
- maximumFractionDigits: s = 2,
213
- compact: a = !1,
214
- normalize: n = !1
215
- }) => new Intl.NumberFormat("en-US", {
216
- style: "currency",
217
- currency: "USD",
218
- notation: a ? "compact" : void 0,
219
- minimumFractionDigits: e,
220
- maximumFractionDigits: s
221
- }).format(n ? Ct(t) : Number(t)), h = (t) => Lt(t) ? new d(t).toFixed() : "", w = ["₀", "₁", "₂", "₃", "₄", "₅", "₆", "₇", "₈", "₉"], Mt = ({
222
- value: t,
223
- decimals: e = 4
224
- }) => {
225
- const s = new d(t);
226
- if (s.isGreaterThan(1) || s.isZero())
227
- return h(s.toFixed(e));
228
- const n = (/e/i.test(t.toString()) ? parseFloat(t.toString()).toFixed(L) : t.toString()).match(/^0\.(0+)(\d+)$/);
229
- if (n) {
230
- const [, r, o] = n;
231
- if (r.length >= e && r.length < w.length)
232
- return `0.0${w[r.length]}${o.slice(0, 3)}`;
233
- }
234
- return h(s.toFixed(e));
235
- }, Pt = (t, e = 0) => `${t.toLocaleString("en-US", { maximumFractionDigits: e })}%`, ge = (t) => t.toString().replace(/\B(?=(\d{3})+(?!\d))/g, ","), Se = (t, e, s = 0) => {
236
- const a = Nt(+t, e);
237
- return Pt(a, s);
238
- }, _e = ({
239
- currency: t,
240
- value: e
241
- }) => t === "USD" ? Bt({ value: e }) : `${K[t]} ${Mt({
242
- value: e,
243
- decimals: k[t]
244
- })}`, xt = (t, e) => new d(
245
- new d(t).toFixed(e, d.ROUND_DOWN)
246
- ).toString(), Ut = (t, e = 3, s = 2) => {
247
- if (t.length <= 5)
248
- return t;
249
- const a = "...";
250
- return t.length <= e + s + a.length ? t : `${t.slice(0, e)}${a}${t.slice(-s)}`;
251
- }, De = ({
252
- balance: t,
253
- symbol: e,
254
- precision: s,
255
- truncateSymbol: a
256
- }) => `${xt(t, s)} ${a ? Ut(e) : e}`, ye = (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
- }, fe = (t) => m(X, t) || m(j, t), Ee = (t) => tt.some(
265
- (e) => m(e, t)
266
- ), Ie = (t) => Z[t.toLowerCase()] ?? {
267
- symbol: "",
268
- decimals: 18,
269
- address: D
270
- }, he = (t) => m(t, J) ? z : Q, Ft = (t) => `eth_${t}`, we = ({
271
- action: t,
272
- log: e,
273
- symbol: s,
274
- vaultAddress: a,
275
- chainId: n
276
- }) => {
277
- const r = {
278
- [S.SYMBOL.NAME]: s,
279
- [S.CHAIN_ID.NAME]: n,
280
- [S.ADDRESS.NAME]: Ft(a)
281
- };
282
- et[t].forEach((o) => {
283
- e?.(o, r);
284
- });
285
- }, Ne = (t) => nt.some((e) => m(e, t)), Oe = (t) => st[t.toLowerCase()] ?? {
286
- symbol: "",
287
- decimals: 18,
288
- address: D
289
- }, be = (t) => at[t.toLowerCase()], Wt = "0x3333333333333333333333333333333333333333";
290
- yt.id + "", dt.address, Dt.id + "", ct.address, _t.id + "", it.address, St.id + "", ot.address, gt.id + "", rt.address, Tt.id + "", B.address;
291
- const Re = (t) => m(t, Wt), Ce = () => B, Le = /* @__PURE__ */ new Map(), M = (t, e) => !e || e.size === 0 ? t : t.map((s) => {
292
- const a = e.get(
293
- s.supportedAsset.toLowerCase()
294
- );
295
- return a ? {
296
- ...s,
297
- withdrawData: a,
298
- // Ondo assets require a hardcoded increased slippage
299
- slippageTolerance: ut
300
- } : s;
301
- }), $t = (t) => {
302
- const e = t.find(
303
- ({ swapQuotes: s }) => s
304
- );
305
- return e?.swapQuotes ? Object.values(e.swapQuotes)[0]?.map(
306
- ({ routerKey: s }) => s
307
- ) ?? [] : [];
308
- }, vt = (t, e, s) => t.map(({ asset: a, swapParams: n, swapQuotes: r }) => !n || !r ? {
309
- supportedAsset: a,
310
- withdrawData: "",
311
- slippageTolerance: s
312
- } : bt({
313
- assetAddress: a,
314
- swapQuotes: r,
315
- swapParams: n,
316
- slippageToleranceForContractTransaction: s,
317
- routerKey: e
318
- })), Gt = async (t, e, s, a, n, r) => {
319
- for (const o of t) {
320
- const c = M(
321
- vt(
322
- e,
323
- o,
324
- s
325
- ),
326
- r
327
- ), { error: i } = await a(...n, c);
328
- if (!i)
329
- return c;
330
- }
331
- return null;
332
- }, Be = (t, e, s) => {
333
- const a = (t ?? []).map((n) => ({
334
- supportedAsset: n,
335
- withdrawData: "",
336
- slippageTolerance: e
337
- }));
338
- return M(a, s);
339
- }, Me = async (t, e, s, a, n) => {
340
- for (const r of t) {
341
- const o = Ot(r);
342
- try {
343
- const c = await e(r), i = $t(
344
- c
345
- ), u = await Gt(
346
- i,
347
- c,
348
- o,
349
- s,
350
- a,
351
- n
352
- );
353
- if (u)
354
- return console.debug(
355
- `[Init Withdraw] Auto slippage simulation succeeded: slippage=${r}%`
356
- ), console.debug("[Init Withdraw] Complex asset data:", u), u;
357
- } catch (c) {
358
- console.error(
359
- `[Init Withdraw] Failed to fetch quotes for slippage=${r}%:`,
360
- c
361
- );
362
- }
363
- }
364
- return null;
365
- }, Pe = async (t, e, {
366
- fetchAaveSwapParams: s,
367
- fetchAaveSwapQuotes: a,
368
- withdrawAmountD18: n,
369
- slippage: r
370
- }) => Promise.all(
371
- (t ?? []).map(async (o) => {
372
- if (!m(o, e))
373
- return { asset: o };
374
- try {
375
- const i = await s({
376
- withdrawAmountD18: n,
377
- slippage: r
378
- });
379
- if (i?.srcData.length) {
380
- const u = await a({
381
- swapParams: i,
382
- slippage: r
383
- });
384
- return { asset: o, swapParams: i, swapQuotes: u };
385
- }
386
- return { asset: o };
387
- } catch (i) {
388
- return console.error(i), { asset: o };
389
- }
390
- })
391
- ), N = (t) => Math.round(t * 100) / 100, xe = ({
392
- maxSlippage: t,
393
- candidates: e = lt
394
- }) => {
395
- if (!Number.isFinite(t) || t <= 0)
396
- return [];
397
- const s = N(Math.min(t, 100)), a = e.filter((r) => r > 0 && r <= s).map(N), n = new Set(a);
398
- return n.add(s), n.add(t), Array.from(n).sort((r, o) => r - o);
399
- }, O = 1000000000000000000n, Vt = 1000000n, b = 10000n, R = 100n, T = (t) => {
400
- if (!t) throw new Error("Ondo: empty hex value");
401
- return t.startsWith("0x") ? t : `0x${t}`;
402
- }, l = (t, e) => {
403
- try {
404
- return BigInt(t);
405
- } catch {
406
- throw new Error(
407
- `Ondo: cannot convert "${e}" value "${t}" to bigint`
408
- );
409
- }
410
- }, C = (t) => t ? At(T(t), { size: 32 }) : pt, Yt = (t) => {
411
- if (!t) throw new Error("Ondo: empty signature");
412
- return mt(Uint8Array.from(atob(t), (e) => e.charCodeAt(0)));
413
- }, Ue = (t) => ({
414
- quotes: t.quotes.map(
415
- (e) => ({
416
- chainId: l(e.chainId, "chainId"),
417
- attestationId: l(e.attestationId, "attestationId"),
418
- userId: T(e.userId),
419
- asset: e.asset,
420
- price: l(e.price, "price"),
421
- quantity: l(e.quantity, "quantity"),
422
- expiration: l(e.expiration, "expiration"),
423
- side: Number(e.side),
424
- additionalData: T(e.additionalData)
425
- })
426
- ),
427
- signatures: t.signatures.map(T)
428
- }), Ht = (t, e, s) => {
429
- const a = BigInt(Math.max(0, Math.round(s * 100))), n = a > R ? R : a, r = b - n, c = t * e / O * r * Vt, i = b * O;
430
- return (c + i - 1n) / i;
431
- }, Fe = ({
432
- attestation: t,
433
- chainId: e,
434
- slippagePercent: s
435
- }) => {
436
- const a = l(t.tokenAmount, "tokenAmount"), n = l(t.price, "price");
437
- return _(ft, [
438
- {
439
- attestationSignature: Yt(t.signature),
440
- quote: {
441
- chainId: e,
442
- attestationId: l(t.attestationId, "attestationId"),
443
- userId: C(t.userId),
444
- asset: t.assetAddress,
445
- price: n,
446
- quantity: a,
447
- expiration: l(t.expiration, "expiration"),
448
- side: Number(t.side),
449
- additionalData: C(t.additionalData)
450
- },
451
- amountOutMinimum: Ht(
452
- a,
453
- n,
454
- s
455
- )
456
- }
457
- ]);
458
- };
459
- export {
460
- m as $,
461
- Nt as A,
462
- re as B,
463
- Ot as C,
464
- ye as D,
465
- Le as E,
466
- ee as F,
467
- Ee as G,
468
- fe as H,
469
- Ne as I,
470
- Re as J,
471
- de as K,
472
- le as L,
473
- we as M,
474
- Ue as N,
475
- M as O,
476
- oe as P,
477
- pe as Q,
478
- ne as R,
479
- te as S,
480
- se as T,
481
- Ft as U,
482
- Ut as V,
483
- Gt as W,
484
- Me as X,
485
- me as Y,
486
- jt as Z,
487
- Ae as _,
488
- bt as a,
489
- Bt as a0,
490
- Te as a1,
491
- Ct as a2,
492
- Qt as a3,
493
- Wt as a4,
494
- Mt as a5,
495
- Xt as a6,
496
- Pt as a7,
497
- Lt as a8,
498
- ge as a9,
499
- h as aa,
500
- Yt as b,
501
- vt as c,
502
- wt as d,
503
- ce as e,
504
- ie as f,
505
- zt as g,
506
- Be as h,
507
- Fe as i,
508
- Pe as j,
509
- $t as k,
510
- xt as l,
511
- _e as m,
512
- Se as n,
513
- De as o,
514
- xe as p,
515
- Jt as q,
516
- ht as r,
517
- ae as s,
518
- E as t,
519
- Ie as u,
520
- he as v,
521
- Oe as w,
522
- be as x,
523
- Ce as y,
524
- ue as z
525
- };