@dhedge/trading-widget 6.1.1 → 6.2.0-canary.1
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/const.cjs +1 -1
- package/const.js +23 -24
- package/core-kit/const/error.d.ts +6 -1
- package/core-kit/utils/error-registry.d.ts +46 -0
- package/core-kit/utils/index.d.ts +1 -0
- package/dytm-D2sVE2th.cjs +1 -0
- package/dytm-DycL7_hQ.js +864 -0
- package/{gmx-c42QlKyJ.js → gmx-Cyz_GmV5.js} +332 -481
- package/gmx-DJ0gqvLq.cjs +1 -0
- package/index.cjs +1 -1
- package/index.js +1479 -1477
- package/package.json +1 -1
- package/utils.cjs +1 -1
- package/utils.js +69 -65
- package/dytm-CQG65-Rc.cjs +0 -1
- package/dytm-CWhBYz0P.js +0 -784
- package/gmx-U3Bnivj2.cjs +0 -1
package/package.json
CHANGED
package/utils.cjs
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const e=require("./dytm-
|
|
1
|
+
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const e=require("./dytm-D2sVE2th.cjs"),t=require("viem");exports.EMPTY_PER_ASSET_WITHDRAW_DATA=e.EMPTY_PER_ASSET_WITHDRAW_DATA;exports.applyContractErrorRegistry=e.applyContractErrorRegistry;exports.base64ToHex=e.base64ToHex;exports.buildAaveWithdrawAssetTransactionData=e.buildAaveWithdrawAssetTransactionData;exports.buildComplexAssetDataForRouter=e.buildComplexAssetDataForRouter;exports.buildDytmActions=e.buildDytmActions;exports.buildDytmRepayActions=e.buildDytmRepayActions;exports.buildSwapQuoteKeyForAave=e.buildSwapQuoteKeyForAave;exports.buildSwapWithdrawTransactionData=e.buildSwapWithdrawTransactionData;exports.buildZapDepositTransactionArguments=e.buildZapDepositTransactionArguments;exports.clientSide=e.clientSide;exports.computeAmountOutMinimumUsdc=e.computeAmountOutMinimumUsdc;exports.createDefaultComplexAssetData=e.createDefaultComplexAssetData;exports.encodeOndoWithdrawData=e.encodeOndoWithdrawData;exports.encodeUnwindPlan=e.encodeUnwindPlan;exports.enrichAssetsWithSwapQuotes=e.enrichAssetsWithSwapQuotes;exports.ensureContractErrorRegistryLoaded=e.ensureContractErrorRegistryLoaded;exports.ensureHexPrefix=e.ensureHexPrefix;exports.extractAvailableRouterKeys=e.extractAvailableRouterKeys;exports.fetchContractErrorRegistry=e.fetchContractErrorRegistry;exports.formatBalance=e.formatBalance;exports.formatByCurrency=e.formatByCurrency;exports.formatNumeratorToPercentage=e.formatNumeratorToPercentage;exports.formatTokenBalance=e.formatTokenBalance;exports.getAutoSlippageSimulationCandidates=e.getAutoSlippageSimulationCandidates;exports.getContractAbiById=e.getContractAbiById;exports.getContractAddressById=e.getContractAddressById;exports.getContractErrorRegistry=e.getContractErrorRegistry;exports.getConventionalTokenPriceDecimals=e.getConventionalTokenPriceDecimals;exports.getErrorKey=e.getErrorKey;exports.getFlatMoneyCollateralByLeverageAddress=e.getFlatMoneyCollateralByLeverageAddress;exports.getFlatMoneyLinkByUnitAddress=e.getFlatMoneyLinkByUnitAddress;exports.getGmxWithdrawAssetByLeverageAddress=e.getGmxWithdrawAssetByLeverageAddress;exports.getGmxWithdrawAssetByVaultAddress=e.getGmxWithdrawAssetByVaultAddress;exports.getHyperliquidWithdrawAsset=e.getHyperliquidWithdrawAsset;exports.getNativeTokenInvestableBalance=e.getNativeTokenInvestableBalance;exports.getPercent=e.getPercent;exports.getPoolFraction=e.getPoolFraction;exports.getSettleDelay=e.getSettleDelay;exports.getSlippageToleranceForContractTransaction=e.getSlippageToleranceForContractTransaction;exports.getTxHashShort=e.getTxHashShort;exports.groupPreviewByAccount=e.groupPreviewByAccount;exports.isAaveLendAndBorrowAsset=e.isAaveLendAndBorrowAsset;exports.isFlatMoneyLeveragedAsset=e.isFlatMoneyLeveragedAsset;exports.isFmpAirdropVaultAddress=e.isFmpAirdropVaultAddress;exports.isGmxLeveragedAsset=e.isGmxLeveragedAsset;exports.isHyperliquidPerpsAsset=e.isHyperliquidPerpsAsset;exports.isNativeToken=e.isNativeToken;exports.isStableSymbol=e.isStableSymbol;exports.logTransactionByActionType=e.logTransactionByActionType;exports.mapAttestationToOndoQuote=e.mapAttestationToOndoQuote;exports.mapOndoApiResponseToUpdatePricesArgs=e.mapOndoApiResponseToUpdatePricesArgs;exports.overlayWithdrawData=e.overlayWithdrawData;exports.parseAmountToD18=e.parseAmountToD18;exports.parseContractErrorMessage=e.parseContractErrorMessage;exports.shiftBy=e.shiftBy;exports.shortenAddress=e.shortenAddress;exports.shouldSwallowMainnetPollError=e.shouldSwallowMainnetPollError;exports.sliceByIndex=e.sliceByIndex;exports.toBigInt=e.toBigInt;exports.toBytes32Hex=e.toBytes32Hex;exports.transformAddressForAnalytics=e.transformAddressForAnalytics;exports.truncateString=e.truncateString;exports.tryEstimateWithRouters=e.tryEstimateWithRouters;exports.tryEstimateWithSlippageValues=e.tryEstimateWithSlippageValues;exports.validateLoggerEventParams=e.validateLoggerEventParams;Object.defineProperty(exports,"decodeErrorResult",{enumerable:!0,get:()=>t.decodeErrorResult});Object.defineProperty(exports,"encodeFunctionData",{enumerable:!0,get:()=>t.encodeFunctionData});Object.defineProperty(exports,"formatEther",{enumerable:!0,get:()=>t.formatEther});Object.defineProperty(exports,"formatUnits",{enumerable:!0,get:()=>t.formatUnits});Object.defineProperty(exports,"hexToString",{enumerable:!0,get:()=>t.hexToString});Object.defineProperty(exports,"trim",{enumerable:!0,get:()=>t.trim});
|
package/utils.js
CHANGED
|
@@ -1,72 +1,76 @@
|
|
|
1
|
-
import { E as s,
|
|
2
|
-
import { decodeErrorResult as
|
|
1
|
+
import { E as s, a as t, b as r, c as o, d as i, e as n, f as d, g as l, h as c, i as A, j as g, k as u, l as y, m, n as p, o as T, p as h, q as B, r as S, s as v, t as D, u as w, v as x, w as E, x as b, y as C, z as f, A as P, B as R, C as W, D as F, F as L, G as H, H as M, I, J as k, K as U, L as O, M as _, N as G, O as K, P as N, Q, R as V, S as q, T as Y, U as Z, V as j, W as z, X as J, Y as X, Z as $, _ as aa, $ as ea, a0 as sa, a1 as ta, a2 as ra, a3 as oa, a4 as ia, a5 as na, a6 as da, a7 as la, a8 as ca, a9 as Aa, aa as ga, ab as ua } from "./dytm-DycL7_hQ.js";
|
|
2
|
+
import { decodeErrorResult as ma, encodeFunctionData as pa, formatEther as Ta, formatUnits as ha, hexToString as Ba, trim as Sa } from "viem";
|
|
3
3
|
export {
|
|
4
4
|
s as EMPTY_PER_ASSET_WITHDRAW_DATA,
|
|
5
|
-
t as
|
|
6
|
-
r as
|
|
7
|
-
o as
|
|
8
|
-
i as
|
|
9
|
-
n as
|
|
10
|
-
d as
|
|
11
|
-
l as
|
|
5
|
+
t as applyContractErrorRegistry,
|
|
6
|
+
r as base64ToHex,
|
|
7
|
+
o as buildAaveWithdrawAssetTransactionData,
|
|
8
|
+
i as buildComplexAssetDataForRouter,
|
|
9
|
+
n as buildDytmActions,
|
|
10
|
+
d as buildDytmRepayActions,
|
|
11
|
+
l as buildSwapQuoteKeyForAave,
|
|
12
|
+
c as buildSwapWithdrawTransactionData,
|
|
12
13
|
A as buildZapDepositTransactionArguments,
|
|
13
|
-
|
|
14
|
+
g as clientSide,
|
|
14
15
|
u as computeAmountOutMinimumUsdc,
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
16
|
+
y as createDefaultComplexAssetData,
|
|
17
|
+
ma as decodeErrorResult,
|
|
18
|
+
pa as encodeFunctionData,
|
|
18
19
|
m as encodeOndoWithdrawData,
|
|
19
20
|
p as encodeUnwindPlan,
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
b as
|
|
32
|
-
|
|
33
|
-
f as
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
F as
|
|
38
|
-
|
|
39
|
-
H as
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
21
|
+
T as enrichAssetsWithSwapQuotes,
|
|
22
|
+
h as ensureContractErrorRegistryLoaded,
|
|
23
|
+
B as ensureHexPrefix,
|
|
24
|
+
S as extractAvailableRouterKeys,
|
|
25
|
+
v as fetchContractErrorRegistry,
|
|
26
|
+
D as formatBalance,
|
|
27
|
+
w as formatByCurrency,
|
|
28
|
+
Ta as formatEther,
|
|
29
|
+
x as formatNumeratorToPercentage,
|
|
30
|
+
E as formatTokenBalance,
|
|
31
|
+
ha as formatUnits,
|
|
32
|
+
b as getAutoSlippageSimulationCandidates,
|
|
33
|
+
C as getContractAbiById,
|
|
34
|
+
f as getContractAddressById,
|
|
35
|
+
P as getContractErrorRegistry,
|
|
36
|
+
R as getConventionalTokenPriceDecimals,
|
|
37
|
+
W as getErrorKey,
|
|
38
|
+
F as getFlatMoneyCollateralByLeverageAddress,
|
|
39
|
+
L as getFlatMoneyLinkByUnitAddress,
|
|
40
|
+
H as getGmxWithdrawAssetByLeverageAddress,
|
|
41
|
+
M as getGmxWithdrawAssetByVaultAddress,
|
|
42
|
+
I as getHyperliquidWithdrawAsset,
|
|
43
|
+
k as getNativeTokenInvestableBalance,
|
|
44
|
+
U as getPercent,
|
|
45
|
+
O as getPoolFraction,
|
|
46
|
+
_ as getSettleDelay,
|
|
47
|
+
G as getSlippageToleranceForContractTransaction,
|
|
48
|
+
K as getTxHashShort,
|
|
49
|
+
N as groupPreviewByAccount,
|
|
50
|
+
Ba as hexToString,
|
|
51
|
+
Q as isAaveLendAndBorrowAsset,
|
|
52
|
+
V as isFlatMoneyLeveragedAsset,
|
|
53
|
+
q as isFmpAirdropVaultAddress,
|
|
54
|
+
Y as isGmxLeveragedAsset,
|
|
55
|
+
Z as isHyperliquidPerpsAsset,
|
|
56
|
+
j as isNativeToken,
|
|
57
|
+
z as isStableSymbol,
|
|
58
|
+
J as logTransactionByActionType,
|
|
59
|
+
X as mapAttestationToOndoQuote,
|
|
60
|
+
$ as mapOndoApiResponseToUpdatePricesArgs,
|
|
61
|
+
aa as overlayWithdrawData,
|
|
62
|
+
ea as parseAmountToD18,
|
|
63
|
+
sa as parseContractErrorMessage,
|
|
64
|
+
ta as shiftBy,
|
|
65
|
+
ra as shortenAddress,
|
|
66
|
+
oa as shouldSwallowMainnetPollError,
|
|
67
|
+
ia as sliceByIndex,
|
|
68
|
+
na as toBigInt,
|
|
69
|
+
da as toBytes32Hex,
|
|
70
|
+
la as transformAddressForAnalytics,
|
|
71
|
+
Sa as trim,
|
|
72
|
+
ca as truncateString,
|
|
73
|
+
Aa as tryEstimateWithRouters,
|
|
74
|
+
ga as tryEstimateWithSlippageValues,
|
|
75
|
+
ua as validateLoggerEventParams
|
|
72
76
|
};
|
package/dytm-CQG65-Rc.cjs
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
"use strict";const y=require("wagmi/chains"),o=require("./gmx-U3Bnivj2.cjs"),p=require("bignumber.js"),d=require("viem"),X=typeof window<"u",J=[{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"},{inputs:[],name:"ondoGMSwap",outputs:[{internalType:"address",name:"",type:"address"}],stateMutability:"view",type:"function"},{inputs:[],name:"usdc",outputs:[{internalType:"address",name:"",type:"address"}],stateMutability:"view",type:"function"}],tt=[{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"}]}],et=[{name:"asset",type:"address"},{name:"amount",type:"uint256"},{name:"assetType",type:"uint16"},{name:"isPool",type:"bool"},{name:"isDebt",type:"bool"},{name:"marketId",type:"uint88"},{name:"accountId",type:"uint256"},{name:"tokenId",type:"uint256"},{name:"debtKey",type:"uint248"},{name:"shares",type:"uint256"}],nt=[{inputs:[{internalType:"address",name:"_pool",type:"address"},{internalType:"uint256",name:"_poolTokenAmount",type:"uint256"}],name:"previewWithdrawal",outputs:[{name:"assetData",type:"tuple[]",components:et}],stateMutability:"nonpayable",type:"function"},{inputs:[],name:"dytmWithdrawProcessor",outputs:[{name:"",type:"address"}],stateMutability:"view",type:"function"}],B=[{inputs:[{name:"params",type:"tuple",components:[{name:"account",type:"uint256"},{name:"tokenId",type:"uint256"},{name:"receiver",type:"address"},{name:"assets",type:"uint256"},{name:"shares",type:"uint256"},{name:"extraData",type:"bytes"}]}],name:"withdraw",outputs:[{name:"assets",type:"uint256"}],stateMutability:"nonpayable",type:"function"},{inputs:[{name:"params",type:"tuple",components:[{name:"account",type:"uint256"},{name:"key",type:"uint248"},{name:"withCollateralType",type:"uint8"},{name:"assets",type:"uint256"},{name:"shares",type:"uint256"},{name:"extraData",type:"bytes"}]}],name:"repay",outputs:[{name:"assetsRepaid",type:"uint256"}],stateMutability:"nonpayable",type:"function"}],at=[{inputs:[{name:"tokenIn",type:"address"},{name:"amountIn",type:"uint256"},{name:"tokenOut",type:"address"},{name:"amountOutMinimum",type:"uint256"},{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:"swapExactInWithAttestation",outputs:[],stateMutability:"nonpayable",type:"function"}],st=[{type:"tuple",components:[{name:"actions",type:"tuple[]",components:[{name:"to",type:"address"},{name:"data",type:"bytes"}]},{name:"outputAsset",type:"address"},{name:"minOutputAmount",type:"uint256"}]}],ot=()=>typeof window<"u";function rt(){return ot()&&typeof window.ethereum<"u"}async function it(t){try{if(rt())return window.ethereum.request({method:"wallet_watchAsset",params:{type:"ERC20",options:t}})}catch{return!1}return!1}const A=(t,e)=>t?.toLowerCase()===e?.toLowerCase(),ut=t=>A(t,o.AddressZero$1),D=t=>{if(!t)throw new Error("Cannot prefix an empty hex value");return t.startsWith("0x")?t:`0x${t}`},l=(t,e)=>{try{return BigInt(t)}catch{throw new Error(`Cannot convert "${e}" value "${t}" to bigint`)}},E=t=>t?d.pad(D(t),{size:32}):d.zeroHash,O=t=>{if(!t)throw new Error("Cannot decode an empty base64 string");return d.bytesToHex(Uint8Array.from(atob(t),e=>e.charCodeAt(0)))},M=(t,e)=>o.contractsAddressesMap[e]?.[t]??o.AddressZero,ct=t=>o.contractsAbisMap[t],dt=t=>t&&`${t.substring(0,6)}...${t.substring(t.length-4,t.length)}`,pt=({address:t,chainId:e})=>{const n=M("aaveLendingPoolV3",e);return A(t,n)},P=({sourceAddress:t,amount:e})=>`${t}_${e}`,mt=(t,e)=>{const n=t.slice(0,e),a=t.slice(e);return{firstPart:n,secondPart:a}},L=(t,e)=>t/e*100,lt=t=>t<1?4:t<10?3:2,At=(t,e=o.DEFAULT_PRECISION)=>new p(t.toString()).shiftedBy(e).toFixed(0),yt=(t,e,n,a)=>new p(e).dividedBy(n).multipliedBy(t).shiftedBy(-(a||o.DEFAULT_PRECISION)).toNumber(),Tt=t=>BigInt(new p(t||"0").shiftedBy(o.DEFAULT_PRECISION).toFixed(0,p.ROUND_DOWN)),x=t=>{const e=new p(.01),n=new p(t),a=!n.isZero()&&n.lt(e)?e:n;return BigInt(a.multipliedBy(100).toFixed(0))},gt=({vaultAddress:t,swapData:e,sendTokenAddress:n,sendTokenAmount:a,vaultDepositTokenAddress:s,minVaultTokensReceivedAmount:r,routerKey:i="ONE_INCH",swapDestinationAmount:c,swapSlippage:u})=>{const m=new p(c).multipliedBy(1-u/100).toFixed(0),T=[d.stringToHex(i,{size:32}),e];return[t,[[n,a,T],[s,m]],r]},Dt=({receiveAssetAddress:t,assets:e,swapData:n,slippage:a})=>{const s={srcData:[],destAmount:new p("0")},{srcData:r,destAmount:i}=e?.reduce((c,u)=>{const m=n?.[u.address];if(!m)return c;const T=[d.stringToHex(m.routerKey,{size:32}),m.rawTransaction.data],g=[u.address,u.rawBalance,T];return{srcData:[...c.srcData,g],destAmount:c.destAmount.plus(m.destinationAmount)}},s)??s;return[r,[t,i.times(1-a/100).toFixed(0,p.ROUND_DOWN)]]},v=({assetAddress:t,swapQuotes:e,swapParams:n,slippageToleranceForContractTransaction:a,routerKey:s})=>{if(!n)return{supportedAsset:t,withdrawData:"",slippageTolerance:BigInt(0)};const{srcData:r,dstData:i}=n,c=r.map(({asset:T,amount:g})=>{const S=e?.[P({sourceAddress:T,amount:g.toString()})]?.find(j=>j.routerKey===s);return{asset:T,amount:g,swapData:{routerKey:d.stringToHex(S?.routerKey??"",{size:32}),txData:S?.rawTransaction.data??"0x"}}}),u=d.encodeAbiParameters(o.ComplexWithdrawalAssetSrcDataAbiItem,[c]),m=d.encodeAbiParameters(o.ComplexWithdrawalDataAbiItem,[{encodedSrcData:u,dstData:{dstAddress:i.asset,dstAmount:i.amount},slippage:a}]);return{supportedAsset:t,withdrawData:m,slippageTolerance:a}},St=({chainId:t,txHash:e,error:n})=>{if(t!==y.mainnet.id||!e||!n)return!1;const a=n instanceof Error?n.message:String(n);return/\bNo Result\b/i.test(a)},Et=({chainId:t,action:e,isRabbyWallet:n})=>e==="update_ondo_prices"&&t===y.mainnet.id&&n?o.ONDO_PRICES_RABBY_SETTLE_DELAY:t?o.TRANSACTION_SETTLE_DELAY[t]??0:0,_t=(t,e)=>o.CHAIN_NATIVE_TOKENS[e]?.nativeTokenSymbol===t,ft=({nativeTokenBalance:t,tokenDecimals:e,gasPrice:n})=>{const a=new p(n).multipliedBy(o.NATIVE_TOKEN_GAS_RESERVE_UNITS).shiftedBy(-e),s=new p(t).minus(a);return s.gt("0")?s:new p("0")},bt=t=>o.STABLE_TOKEN_SYMBOLS.includes(t),wt=t=>{const e=Object.values(t).reduce((n,{type:a})=>(n[a]=n[a]+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},ht=(t,e=150)=>t.length>e?t.substring(0,e):t,_=(t,e=o.TRANSACTION_ERROR_KEYS)=>{const n=t.toLowerCase();return e.sort((a,s)=>s.length-a.length).find(a=>n.includes(a.toLowerCase()))},w=t=>o.TRANSACTION_ERRORS[t]??o.LIMIT_ORDER_TRANSACTION_ERRORS[t],It=({errorMessage:t,abiErrors:e})=>{if(!t||t.includes("User rejected"))return null;const n=e.find(r=>t.includes(r));if(n&&_(n))return w(n);const a=_(t);if(a)return w(a);const[s]=t.split(n?".":"Contract").map(r=>r.trim());return{title:"Transaction failed",hint:`${ht(s??"")} ${n?`: ${n}`:""}`}},Nt=t=>typeof t=="number"&&Number.isFinite(t),Rt=t=>typeof t=="bigint"&&t!==BigInt(0),F=(t,e=o.DEFAULT_PRECISION$1)=>new p(t).shiftedBy(-e).toNumber(),U=t=>!isNaN(parseFloat(t))&&!isNaN(t),W=({value:t,minimumFractionDigits:e=2,maximumFractionDigits:n=2,compact:a=!1,normalize:s=!1})=>new Intl.NumberFormat("en-US",{style:"currency",currency:"USD",notation:a?"compact":void 0,minimumFractionDigits:e,maximumFractionDigits:n}).format(s?F(t):Number(t)),f=t=>U(t)?new p(t).toFixed():"",h=["₀","₁","₂","₃","₄","₅","₆","₇","₈","₉"],G=({value:t,decimals:e=4})=>{const n=new p(t);if(n.isGreaterThan(1)||n.isZero())return f(n.toFixed(e));const s=(/e/i.test(t.toString())?parseFloat(t.toString()).toFixed(o.DEFAULT_PRECISION$1):t.toString()).match(/^0\.(0+)(\d+)$/);if(s){const[,r,i]=s;if(r.length>=e&&r.length<h.length)return`0.0${h[r.length]}${i.slice(0,3)}`}return f(n.toFixed(e))},H=(t,e=0)=>`${t.toLocaleString("en-US",{maximumFractionDigits:e})}%`,Ct=t=>t.toString().replace(/\B(?=(\d{3})+(?!\d))/g,","),Bt=(t,e,n=0)=>{const a=L(+t,e);return H(a,n)},Ot=({currency:t,value:e})=>t==="USD"?W({value:e}):`${o.CURRENCY_SYMBOL_MAP[t]} ${G({value:e,decimals:o.CURRENCY_DECIMALS_MAP[t]})}`,$=(t,e)=>new p(new p(t).toFixed(e,p.ROUND_DOWN)).toString(),k=(t,e=3,n=2)=>{if(t.length<=5)return t;const a="...";return t.length<=e+n+a.length?t:`${t.slice(0,e)}${a}${t.slice(-n)}`},Mt=({balance:t,symbol:e,precision:n,truncateSymbol:a})=>`${$(t,n)} ${a?k(e):e}`,Pt=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)}`},Lt=t=>A(o.FLATMONEY_EARLY_DEPOSITOR_VAULT_ADDRESS_BASE,t)||A(o.FLATMONEY_DHT_STAKING_VAULT_ADDRESS_BASE,t),xt=t=>o.FLAT_MONEY_LEVERAGED_ASSET_ADDRESSES.some(e=>A(e,t)),vt=t=>o.FLAT_MONEY_COLLATERAL_MAP[t.toLowerCase()]??{symbol:"",decimals:18,address:o.AddressZero},Ft=t=>A(t,o.FLAT_MONEY_V1_UNIT_ADDRESS)?o.FLAT_MONEY_V1_UNIT_LINK:o.FLAT_MONEY_UNIT_LINK,V=t=>`eth_${t}`,Ut=({action:t,log:e,symbol:n,vaultAddress:a,chainId:s})=>{const r={[o.TRADING_LOG_EVENT_PARAM.SYMBOL.NAME]:n,[o.TRADING_LOG_EVENT_PARAM.CHAIN_ID.NAME]:s,[o.TRADING_LOG_EVENT_PARAM.ADDRESS.NAME]:V(a)};o.LOG_EVENT_BY_TRANSACTION_ACTION_MAP[t].forEach(i=>{e?.(i,r)})},Wt=t=>o.GMX_MARKET_ASSETS.some(e=>A(e,t)),Gt=t=>o.GMX_WITHDRAW_ASSET_MAP[t.toLowerCase()]??{symbol:"",decimals:18,address:o.AddressZero},Ht=t=>o.GMX_WITHDRAW_ASSET_MAP_BY_VAULT_ADDRESS[t.toLowerCase()],q="0x3333333333333333333333333333333333333333";y.arbitrum.id+"",o.USDC_ARBITRUM.address,y.base.id+"",o.USDC_BASE.address,y.optimism.id+"",o.USDC_OPTIMISM.address,y.polygon.id+"",o.USDC_POLYGON.address,y.mainnet.id+"",o.USDC_MAINNET.address,y.hyperEvm.id+"",o.USDC_HYPEREVM.address;const $t=t=>A(t,q),kt=()=>o.USDC_HYPEREVM,Vt=new Map,b=(t,e)=>!e||e.size===0?t:t.map(n=>{const a=e.get(n.supportedAsset.toLowerCase());return a?{...n,withdrawData:a.withdrawData,slippageTolerance:a.slippageTolerance}:n}),Y=t=>{const e=t.find(({swapQuotes:n})=>n);return e?.swapQuotes?Object.values(e.swapQuotes)[0]?.map(({routerKey:n})=>n)??[]:[]},K=(t,e,n)=>t.map(({asset:a,swapParams:s,swapQuotes:r})=>!s||!r?{supportedAsset:a,withdrawData:"",slippageTolerance:n}:v({assetAddress:a,swapQuotes:r,swapParams:s,slippageToleranceForContractTransaction:n,routerKey:e})),Z=async(t,e,n,a,s,r)=>{for(const i of t){const c=b(K(e,i,n),r),{error:u}=await a(...s,c);if(!u)return c}return null},qt=(t,e,n)=>{const a=(t??[]).map(s=>({supportedAsset:s,withdrawData:"",slippageTolerance:e}));return b(a,n)},Yt=async(t,e,n,a,s)=>{for(const r of t){const i=x(r);try{const c=await e(r),u=Y(c),m=await Z(u,c,i,n,a,s);if(m)return console.debug(`[Init Withdraw] Auto slippage simulation succeeded: slippage=${r}%`),console.debug("[Init Withdraw] Complex asset data:",m),m}catch(c){console.error(`[Init Withdraw] Failed to fetch quotes for slippage=${r}%:`,c)}}return null},Kt=async(t,e,{fetchAaveSwapParams:n,fetchAaveSwapQuotes:a,withdrawAmountD18:s,slippage:r})=>Promise.all((t??[]).map(async i=>{if(!A(i,e))return{asset:i};try{const u=await n({withdrawAmountD18:s,slippage:r});if(u?.srcData.length){const m=await a({swapParams:u,slippage:r});return{asset:i,swapParams:u,swapQuotes:m}}return{asset:i}}catch(u){return console.error(u),{asset:i}}})),I=t=>Math.round(t*100)/100,Zt=({maxSlippage:t,candidates:e=o.SLIPPAGE_AUTO_SIMULATION_CANDIDATES})=>{if(!Number.isFinite(t)||t<=0)return[];const n=I(Math.min(t,100)),a=e.filter(r=>r>0&&r<=n).map(I),s=new Set(a);return s.add(n),s.add(t),Array.from(s).sort((r,i)=>r-i)},N=1000000000000000000n,Qt=1000000n,R=10000n,C=100n,zt=t=>({quotes:t.quotes.map(e=>({chainId:l(e.chainId,"chainId"),attestationId:l(e.attestationId,"attestationId"),userId:D(e.userId),asset:e.asset,price:l(e.price,"price"),quantity:l(e.quantity,"quantity"),expiration:l(e.expiration,"expiration"),side:Number(e.side),additionalData:D(e.additionalData)})),signatures:t.signatures.map(D)}),Q=(t,e,n)=>{const a=BigInt(Math.max(0,Math.round(n*100))),s=a>C?C:a,r=R-s,c=t*e/N*r*Qt,u=R*N;return(c+u-1n)/u},z=(t,e)=>({chainId:e,attestationId:l(t.attestationId,"attestationId"),userId:E(t.userId),asset:t.assetAddress,price:l(t.price,"price"),quantity:l(t.tokenAmount,"tokenAmount"),expiration:l(t.expiration,"expiration"),side:Number(t.side),additionalData:E(t.additionalData)}),jt=({attestation:t,chainId:e,slippagePercent:n})=>{const a=z(t,e);return d.encodeAbiParameters(tt,[{attestationSignature:O(t.signature),quote:a,amountOutMinimum:Q(a.quantity,a.price,n)}])},Xt=t=>[...t.reduce((n,a)=>n.has(a.accountId)?n:n.set(a.accountId,a),new Map).values()].map(({accountId:n,marketId:a})=>({accountId:n,marketId:a,collaterals:t.filter(s=>s.accountId===n&&!s.isDebt),debt:t.find(s=>s.accountId===n&&s.isDebt)})),Jt=({collateral:t,dytmOffice:e,processor:n,gmToken:a,ondoGMSwap:s,usdc:r,gmAmount:i,amountOutMinimum:c,signature:u,quote:m})=>[{to:e,data:d.encodeFunctionData({abi:B,functionName:"withdraw",args:[{account:t.accountId,tokenId:t.tokenId,receiver:n,assets:i,shares:0n,extraData:"0x"}]})},{to:a,data:d.encodeFunctionData({abi:d.erc20Abi,functionName:"approve",args:[s,i]})},{to:s,data:d.encodeFunctionData({abi:at,functionName:"swapExactInWithAttestation",args:[a,i,r,c,u,m]})}],te=({accountId:t,debtKey:e,dytmOffice:n,usdc:a})=>[{to:a,data:d.encodeFunctionData({abi:d.erc20Abi,functionName:"approve",args:[n,d.maxUint256]})},{to:n,data:d.encodeFunctionData({abi:B,functionName:"repay",args:[{account:t,key:e,withCollateralType:0,assets:d.maxUint256,shares:0n,extraData:"0x"}]})}],ee=({actions:t,outputAsset:e,minOutputAmount:n})=>d.encodeAbiParameters(st,[{actions:t,outputAsset:e,minOutputAmount:n}]);exports.DytmOfficeAssetGuardAbi=nt;exports.EMPTY_PER_ASSET_WITHDRAW_DATA=Vt;exports.HYPERLIQUID_PERPS_ACCOUNT_ADDRESS=q;exports.OndoGMTokenAssetGuardAbi=J;exports.addTokenToWallet=it;exports.base64ToHex=O;exports.buildAaveWithdrawAssetTransactionData=v;exports.buildComplexAssetDataForRouter=K;exports.buildDytmActions=Jt;exports.buildDytmRepayActions=te;exports.buildSwapQuoteKeyForAave=P;exports.buildSwapWithdrawTransactionData=Dt;exports.buildZapDepositTransactionArguments=gt;exports.clientSide=X;exports.commify=Ct;exports.computeAmountOutMinimumUsdc=Q;exports.createDefaultComplexAssetData=qt;exports.encodeOndoWithdrawData=jt;exports.encodeUnwindPlan=ee;exports.enrichAssetsWithSwapQuotes=Kt;exports.ensureHexPrefix=D;exports.extractAvailableRouterKeys=Y;exports.formatBalance=$;exports.formatByCurrency=Ot;exports.formatNumberToLimitedDecimals=G;exports.formatNumeratorToPercentage=Bt;exports.formatPercentage=H;exports.formatToUsd=W;exports.formatTokenBalance=Mt;exports.getAutoSlippageSimulationCandidates=Zt;exports.getContractAbiById=ct;exports.getContractAddressById=M;exports.getConventionalTokenPriceDecimals=lt;exports.getErrorKey=_;exports.getFlatMoneyCollateralByLeverageAddress=vt;exports.getFlatMoneyLinkByUnitAddress=Ft;exports.getGmxWithdrawAssetByLeverageAddress=Gt;exports.getGmxWithdrawAssetByVaultAddress=Ht;exports.getHyperliquidWithdrawAsset=kt;exports.getNativeTokenInvestableBalance=ft;exports.getPercent=L;exports.getPoolFraction=yt;exports.getSettleDelay=Et;exports.getSlippageToleranceForContractTransaction=x;exports.getTxHashShort=Pt;exports.groupPreviewByAccount=Xt;exports.isAaveLendAndBorrowAsset=pt;exports.isEqualAddress=A;exports.isFlatMoneyLeveragedAsset=xt;exports.isFmpAirdropVaultAddress=Lt;exports.isGmxLeveragedAsset=Wt;exports.isHyperliquidPerpsAsset=$t;exports.isNativeToken=_t;exports.isNumberType=Nt;exports.isNumeric=U;exports.isStableSymbol=bt;exports.isZeroAddress=ut;exports.logTransactionByActionType=Ut;exports.mapAttestationToOndoQuote=z;exports.mapOndoApiResponseToUpdatePricesArgs=zt;exports.nonZeroBigInt=Rt;exports.normalizeNumber=F;exports.overlayWithdrawData=b;exports.parseAmountToD18=Tt;exports.parseContractErrorMessage=It;exports.removeInsignificantTrailingZeros=f;exports.shiftBy=At;exports.shortenAddress=dt;exports.shouldSwallowMainnetPollError=St;exports.sliceByIndex=mt;exports.toBigInt=l;exports.toBytes32Hex=E;exports.transformAddressForAnalytics=V;exports.truncateString=k;exports.tryEstimateWithRouters=Z;exports.tryEstimateWithSlippageValues=Yt;exports.validateLoggerEventParams=wt;
|