@goodaofi/bonds-sdk 3.0.175 → 3.0.176
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/main.js +174 -143
- package/dist/views/ZapModal/index.d.ts +3 -1
- package/package.json +1 -1
package/dist/main.js
CHANGED
|
@@ -65974,7 +65974,6 @@ const YourBondsModal = ({ onDismiss, bill }) => {
|
|
|
65974
65974
|
const lastBlockTimestamp = parseInt(userBill?.lastBlockTimestamp ?? '0');
|
|
65975
65975
|
const isPendingCliff = vestingCliff ? currentTime - lastBlockTimestamp < vestingCliff : false;
|
|
65976
65976
|
const cliffCountdown = getTimePeriods(lastBlockTimestamp + (vestingCliff ?? 0) - currentTime, true);
|
|
65977
|
-
const showImage = false;
|
|
65978
65977
|
const handleClaim = async (billId, billAddress) => {
|
|
65979
65978
|
const address = billAddress;
|
|
65980
65979
|
const isVestingNft = billAddress?.toLowerCase() === VESTING_NFT_ADDRESS.toLowerCase();
|
|
@@ -66028,7 +66027,10 @@ const YourBondsModal = ({ onDismiss, bill }) => {
|
|
|
66028
66027
|
};
|
|
66029
66028
|
const earnTokenPrice = useCurrencyPrice(userBill?.bond?.earnToken ?? null, userBill?.bond?.chainId ?? null);
|
|
66030
66029
|
const BILL_ATTRIBUTES = ['The Legend', 'The Location', 'The Moment', 'The Trend', 'The Innovation'];
|
|
66031
|
-
bondNFTData?.attributes?.filter((attrib) => BILL_ATTRIBUTES.includes(attrib.trait_type));
|
|
66030
|
+
const attributes = bondNFTData?.attributes?.filter((attrib) => BILL_ATTRIBUTES.includes(attrib.trait_type));
|
|
66031
|
+
const handleImageLoad = () => {
|
|
66032
|
+
setImgLoaded(true);
|
|
66033
|
+
};
|
|
66032
66034
|
const [onTransferBondModal] = useModal(jsx$2(TransferBondModal, { userBill: userBill }), true, true, `transferModal${userBill?.id}}`);
|
|
66033
66035
|
useEffect(() => {
|
|
66034
66036
|
if (isConfirmed) {
|
|
@@ -66037,9 +66039,32 @@ const YourBondsModal = ({ onDismiss, bill }) => {
|
|
|
66037
66039
|
}
|
|
66038
66040
|
/* eslint-disable react-hooks/exhaustive-deps */
|
|
66039
66041
|
}, [isConfirmed]);
|
|
66040
|
-
return (jsx$2(Modal, { className: "modal", children: jsxs(Flex$1, { className: "yourbondsmodal-content", children: [jsx$2(Flex$1, { className: "yourbondsmodal-header", children: jsx$2(Flex$1, { className: "svg-close", onClick: onDismiss, children: jsx$2(Svg, { icon: "close" }) }) }), jsxs(Flex$1, { className: "yourbondsmodal table-container", children: [
|
|
66042
|
+
return (jsx$2(Modal, { className: "modal", children: jsxs(Flex$1, { className: "yourbondsmodal-content", children: [jsx$2(Flex$1, { className: "yourbondsmodal-header", children: jsx$2(Flex$1, { className: "svg-close", onClick: onDismiss, children: jsx$2(Svg, { icon: "close" }) }) }), jsxs(Flex$1, { className: "yourbondsmodal table-container", children: [(jsxs(Flex$1, { className: "yourbondsmodal bondimage", children: [bondNFTData?.image && (jsx$2("img", { src: `${bondNFTData?.image}?img-width=720`, onLoad: handleImageLoad, style: { zIndex: 2 } })), !imgLoaded && (jsx$2(Flex$1, { sx: {
|
|
66043
|
+
position: 'absolute',
|
|
66044
|
+
top: 'calc(50% - 24px)',
|
|
66045
|
+
right: 'calc(50% - 50px)',
|
|
66046
|
+
justifyContent: 'center',
|
|
66047
|
+
alignItems: 'center',
|
|
66048
|
+
zIndex: 1,
|
|
66049
|
+
}, children: jsx$2(Spinner, { width: 100 }) }))] })), jsxs(Flex$1, { className: "yourbondsmodal yourbondinfo", children: [jsxs(Flex$1, { className: "yourbondinfo title-container", children: [jsx$2(Flex$1, { className: "title-container bondicon", children: userBill && (jsx$2(TokenImage, { symbol: userBill?.bond?.showcaseTokenName ?? userBill?.bond?.earnToken?.symbol, size: 40, chain: userBill?.bond?.chainId })) }), jsx$2(Flex$1, { className: "title-container tokenname", children: userBill?.bond?.showcaseTokenName ?? userBill?.bond?.earnToken.symbol }), jsx$2(Flex$1, { className: "title-container tokentags", children: userBill?.bond?.tags?.slice(0, 1).map((tag) => {
|
|
66041
66050
|
return (jsx$2(Flex$1, { sx: { marginRight: '10px' }, children: jsx$2(ListTag, { text: tag?.toUpperCase() }) }, tag));
|
|
66042
|
-
}) }), jsxs(Text, { sx: { color: 'text', opacity: '0.6', fontSize: ['12px', '12px', '12px', '16px'] }, children: ["#", userBill?.id] })] }), jsxs(Flex$1, { className: "yourbondinfo blocks-container", children: [
|
|
66051
|
+
}) }), jsxs(Text, { sx: { color: 'text', opacity: '0.6', fontSize: ['12px', '12px', '12px', '16px'] }, children: ["#", userBill?.id] })] }), jsxs(Flex$1, { className: "yourbondinfo blocks-container", children: [(jsxs(Flex$1, { className: "attributes-container", children: [jsxs(Flex$1, { className: "attributes-header", sx: {
|
|
66052
|
+
borderRadius: `${isOpenTraits ? '6px 6px 0px 0px' : 'normal'}`,
|
|
66053
|
+
}, onClick: () => setIsOpenTraits(!isOpenTraits), children: [jsxs(Flex$1, { sx: { gap: '10px', alignItems: 'center' }, children: [jsx$2(Svg, { icon: "tag", direction: "down" }), jsx$2(Text, { sx: { fontSize: '12px', fontWeight: 400, color: 'text', opacity: '0.6' }, children: "Traits" })] }), jsx$2(Svg, { icon: "caret", direction: isOpenTraits ? 'up' : 'down' })] }), userBill?.bond?.billType === 'staking' && (jsxs(Flex$1, { sx: {
|
|
66054
|
+
p: '5px 10px',
|
|
66055
|
+
width: '100%',
|
|
66056
|
+
background: '#8E568F',
|
|
66057
|
+
borderRadius: 'normal',
|
|
66058
|
+
mt: '10px',
|
|
66059
|
+
fontSize: '12px',
|
|
66060
|
+
fontWeight: 400,
|
|
66061
|
+
justifyContent: 'center',
|
|
66062
|
+
display: 'block',
|
|
66063
|
+
}, children: ["Tokens bought through this bond went directly to the", ' ', jsx$2("span", { onClick: () => window.open('https://basepad.finance/earn', '_blank'), style: { textDecoration: 'underline', cursor: 'pointer', color: 'blue' }, children: "$BPAD staking pool" }), ' ', "with a 365 days lock."] })), jsx$2(AnimatePresence, { children: isOpenTraits && (jsx$2(motion.div, { initial: { height: 0 }, animate: { height: 'fit-content' }, transition: { opacity: { duration: 0.2 } }, exit: { height: 0 }, sx: { overflow: 'hidden', width: '100%' }, children: jsx$2(Flex$1, { sx: { flexDirection: 'column', gap: '1px' }, children: attributes
|
|
66064
|
+
? attributes.map((a) => (jsxs(Flex$1, { sx: { background: 'white4', width: '100%', padding: '2px 8px' }, children: [jsx$2(Text, { sx: { fontSize: '10px', fontWeight: 500 }, children: a?.trait_type }), jsx$2(Text, { sx: { fontSize: '10px', fontWeight: 500 }, children: a?.value })] }, a.value)))
|
|
66065
|
+
: BILL_ATTRIBUTES.map((attrib) => {
|
|
66066
|
+
return (jsxs(Flex$1, { sx: { background: 'white4', width: '100%', padding: '2px 8px' }, children: [jsx$2(Text, { sx: { fontSize: '10px', fontWeight: 500 }, children: attrib }), jsx$2(Skeleton, { width: "150px" })] }, attrib));
|
|
66067
|
+
}) }) })) })] })), bondNFTData?.data?.deposit && (jsxs(Flex$1, { className: "yourbondinfo-block row-vested", children: [jsxs(Flex$1, { className: "yourbondinfo-block header", children: [jsx$2(Flex$1, { className: "yourbondinfo-block header-title", children: "You Spent" }), jsx$2(Flex$1, { className: "yourbondinfo-block header-tooltip", children: jsx$2(TooltipBubble, { className: "tooltip-bubble", body: jsx$2(Flex$1, { children: UserBillTooltipText.YouSpent }), width: "270px", placement: "bottomLeft", transformTip: "translate(-5%, 0%)", children: jsx$2(Flex$1, { className: "block-header icon", children: jsx$2(Svg, { icon: "questionCircle", width: "12px" }) }) }) })] }), jsx$2(Flex$1, { className: "yourbondinfo-block info", children: jsx$2(Flex$1, { className: "block-info text", children: jsxs(Text, { sx: { fontSize: ['12px', '12px', '12px', '19px'], fontWeight: 700 }, children: ["$", bondNFTData?.data?.dollarValue.toFixed(2)] }) }) })] })), jsxs(Flex$1, { className: "yourbondinfo-block row-vested", children: [jsxs(Flex$1, { className: "yourbondinfo-block header", children: [jsx$2(Flex$1, { className: "yourbondinfo-block header-title", children: "Fully Vested" }), jsx$2(Flex$1, { className: "yourbondinfo-block header-tooltip", children: jsx$2(TooltipBubble, { className: "tooltip-bubble", body: jsx$2(Flex$1, { children: UserBillTooltipText.FullyVested }), width: "230px", placement: "bottomLeft", transformTip: "translate(-5%, 0%)", children: jsx$2(Flex$1, { className: "block-header icon", children: jsx$2(Svg, { icon: "questionCircle", width: "12px" }) }) }) })] }), jsxs(Flex$1, { className: "yourbondinfo-block info", children: [jsx$2(Flex$1, { className: "block-info icon" }), jsx$2(Flex$1, { className: "block-info text", children: jsxs(Flex$1, { sx: { fontSize: ['12px', '12px', '12px', '19px'], fontWeight: 700 }, children: [vestingTimeRemainingString(userBill), isPendingCliff && (jsx$2(TooltipBubble, { className: "tooltip-bubble", body: jsxs(Flex$1, { children: ["Bond will be claimable in", ' ', `${cliffCountdown.days !== 0 ? `${cliffCountdown.days} days` : cliffCountdown.hours !== 0 ? `${cliffCountdown.hours} hours` : `${cliffCountdown.minutes} mins`}`, "."] }), width: "180px", placement: "bottomRight", transformTip: "translate(13%, 0%)", children: jsx$2(Flex$1, { sx: { opacity: 0.6, ml: '6px' }, children: jsx$2(Svg, { icon: "questionCircle", width: "12px" }) }) }))] }) })] })] }), jsxs(Flex$1, { className: "yourbondinfo-block row-pending", children: [jsxs(Flex$1, { className: "yourbondinfo-block header", children: [jsx$2(Flex$1, { className: "yourbondinfo-block header-title", children: "Pending" }), jsx$2(Flex$1, { className: "yourbondinfo-block header-tooltip", children: jsx$2(TooltipBubble, { className: "tooltip-bubble", body: jsx$2(Flex$1, { children: UserBillTooltipText.Pending }), width: "230px", placement: "bottomLeft", transformTip: "translate(-5%, 0%)", children: jsx$2(Flex$1, { className: "block-header icon", children: jsx$2(Svg, { icon: "questionCircle", width: "12px" }) }) }) })] }), jsxs(Flex$1, { className: "yourbondinfo-block info", children: [jsx$2(Flex$1, { className: "block-info icon", children: userBill && (jsx$2(TokenImage, { symbol: userBill?.bond?.showcaseTokenName ?? userBill?.bond?.earnToken?.symbol, size: 25, chain: userBill?.bond?.chainId })) }), jsxs(Flex$1, { className: "block-info text", children: [jsx$2(Text, { sx: { fontSize: ['12px', '12px', '12px', '19px'], fontWeight: 700 }, children: formatNumberSI(parseFloat(totalPending(userBill).toFixed(4)), 4) }), jsx$2(Text, { sx: {
|
|
66043
66068
|
fontSize: ['10px', '10px', '10px', '12px'],
|
|
66044
66069
|
fontWeight: [500, 500, 500, 400],
|
|
66045
66070
|
paddingLeft: '10px',
|
|
@@ -73119,7 +73144,7 @@ const useSoulZapTokenQuote = (typedValue, inputCurrency, outputToken, chainId, a
|
|
|
73119
73144
|
const contractAddress = outputToken?.address[chainId];
|
|
73120
73145
|
const chain = getChainParam(chainId);
|
|
73121
73146
|
const isLP = outputToken?.lpToken ?? false;
|
|
73122
|
-
const liquidityDex = outputToken?.liquidityDex?.[chainId];
|
|
73147
|
+
const liquidityDex = outputToken?.liquiditySource?.[chainId] ?? outputToken?.liquidityDex?.[chainId];
|
|
73123
73148
|
const protocol = main.dexFactories[chainId]?.[liquidityDex]?.protocol;
|
|
73124
73149
|
const lpType = outputToken?.lpToken ? getLpType(protocol) : 'single';
|
|
73125
73150
|
const ichiUnderlyingDex = outputToken?.ichiUnderlyingDex;
|
|
@@ -73220,6 +73245,139 @@ const useSoulZapTokenQuote = (typedValue, inputCurrency, outputToken, chainId, a
|
|
|
73220
73245
|
return [isLoading, response, estimateOutput, zapError];
|
|
73221
73246
|
};
|
|
73222
73247
|
|
|
73248
|
+
const useSoulZapBondQuote = (typedValue, inputCurrency, bond, account, tierProofSig) => {
|
|
73249
|
+
const debouncedInput = useDebounce(typedValue, 400);
|
|
73250
|
+
const [slippage] = useSlippage();
|
|
73251
|
+
const principalToken = bond?.lpToken;
|
|
73252
|
+
const bondContractAddress = bond?.contractAddress[bond?.chainId];
|
|
73253
|
+
const chainId = bond?.chainId;
|
|
73254
|
+
const inputCurrencyString = inputCurrency === 'NATIVE' ? '0x0000000000000000000000000000000000000000' : inputCurrency?.address[chainId];
|
|
73255
|
+
const inputCurrencyDecimals = inputCurrency === 'NATIVE' ? 18 : inputCurrency?.decimals[chainId];
|
|
73256
|
+
const principalContractAddress = principalToken?.address[chainId];
|
|
73257
|
+
const chainName = getChainParam(chainId);
|
|
73258
|
+
const isReserveBond = bond?.billType === 'reserve' || bond?.billType === 'staking';
|
|
73259
|
+
const liquidityDex = principalToken?.liquiditySource?.[chainId] ?? principalToken?.liquidityDex?.[chainId];
|
|
73260
|
+
const protocol = main.dexFactories[chainId]?.[liquidityDex]?.protocol;
|
|
73261
|
+
const lpType = isReserveBond ? 'single' : getLpType(protocol);
|
|
73262
|
+
const ichiUnderlyingDex = principalToken?.ichiUnderlyingDex;
|
|
73263
|
+
const vault = principalToken?.address?.[chainId];
|
|
73264
|
+
const router = main.dexFactories[chainId]?.[liquidityDex]?.router;
|
|
73265
|
+
// Validates that the user did not pass an amount with 19 decimals or more
|
|
73266
|
+
const validated18DecimalAmount = new BigNumber$1(debouncedInput ?? '0').toFixed(18, 5);
|
|
73267
|
+
const bigishInputAmount = new BigNumber$1(validated18DecimalAmount ?? '0')
|
|
73268
|
+
.times(new BigNumber$1(10).pow(inputCurrencyDecimals ?? 18))
|
|
73269
|
+
.toString();
|
|
73270
|
+
const zapInputData = useMemo(() => {
|
|
73271
|
+
if (inputCurrencyString &&
|
|
73272
|
+
inputCurrencyDecimals &&
|
|
73273
|
+
bigishInputAmount !== 'NaN' &&
|
|
73274
|
+
bigishInputAmount !== '0' &&
|
|
73275
|
+
principalContractAddress &&
|
|
73276
|
+
chainName &&
|
|
73277
|
+
bondContractAddress &&
|
|
73278
|
+
(inputCurrency === 'NATIVE' || inputCurrency?.address[chainId] !== principalToken.address[chainId])) {
|
|
73279
|
+
return {
|
|
73280
|
+
chain: chainName,
|
|
73281
|
+
recipient: account ?? '0x0000000000000000000000000000000000000000',
|
|
73282
|
+
user: account ?? '0x0000000000000000000000000000000000000000',
|
|
73283
|
+
lpData: {
|
|
73284
|
+
lpType,
|
|
73285
|
+
fromToken: inputCurrencyString,
|
|
73286
|
+
fromAmount: bigishInputAmount,
|
|
73287
|
+
underlyingDex: ichiUnderlyingDex,
|
|
73288
|
+
vault: isReserveBond ? undefined : vault,
|
|
73289
|
+
slippage: slippage,
|
|
73290
|
+
lpAddress: lpType === 'solidly' || lpType === 'univ2' || lpType === 'curve' ? vault : undefined,
|
|
73291
|
+
router: lpType === 'solidly' || lpType === 'univ2' ? router : undefined,
|
|
73292
|
+
toToken: isReserveBond ? vault : undefined,
|
|
73293
|
+
},
|
|
73294
|
+
protocolData: {
|
|
73295
|
+
protocol: 'ApeBond',
|
|
73296
|
+
bond: bondContractAddress,
|
|
73297
|
+
depositer: account ?? '0x0000000000000000000000000000000000000000',
|
|
73298
|
+
tierProofSignature: bond.billVersion === main.BillVersion.V4 && tierProofSig ? tierProofSig : undefined,
|
|
73299
|
+
},
|
|
73300
|
+
};
|
|
73301
|
+
}
|
|
73302
|
+
else {
|
|
73303
|
+
return null;
|
|
73304
|
+
}
|
|
73305
|
+
/* eslint-disable react-hooks/exhaustive-deps */
|
|
73306
|
+
}, [
|
|
73307
|
+
bigishInputAmount,
|
|
73308
|
+
principalContractAddress,
|
|
73309
|
+
chainName,
|
|
73310
|
+
account,
|
|
73311
|
+
ichiUnderlyingDex,
|
|
73312
|
+
vault,
|
|
73313
|
+
lpType,
|
|
73314
|
+
router,
|
|
73315
|
+
slippage,
|
|
73316
|
+
]);
|
|
73317
|
+
const queryKey = useMemo(() => {
|
|
73318
|
+
if (!zapInputData)
|
|
73319
|
+
return null;
|
|
73320
|
+
return [
|
|
73321
|
+
'zapBondDetails',
|
|
73322
|
+
zapInputData.chain,
|
|
73323
|
+
zapInputData.user,
|
|
73324
|
+
zapInputData.lpData.lpType,
|
|
73325
|
+
zapInputData.lpData.fromToken,
|
|
73326
|
+
zapInputData.lpData.fromAmount,
|
|
73327
|
+
zapInputData.lpData.underlyingDex ?? '',
|
|
73328
|
+
zapInputData.lpData.vault,
|
|
73329
|
+
zapInputData.lpData.slippage,
|
|
73330
|
+
zapInputData.lpData.lpAddress,
|
|
73331
|
+
zapInputData.lpData.router ?? '',
|
|
73332
|
+
];
|
|
73333
|
+
}, [zapInputData]);
|
|
73334
|
+
const fetchZapDetails = async () => {
|
|
73335
|
+
const response = await axios.post(SOUL_ZAP_API, {
|
|
73336
|
+
'0': zapInputData,
|
|
73337
|
+
});
|
|
73338
|
+
return response.data?.[0]?.result?.data;
|
|
73339
|
+
};
|
|
73340
|
+
const { data: response, isLoading, isFetching, error, } = useQuery({
|
|
73341
|
+
queryKey: [QUERY_KEYS.ZAP_TOKEN_QUOTE, queryKey],
|
|
73342
|
+
queryFn: fetchZapDetails,
|
|
73343
|
+
refetchInterval: 60000, // i.e. 60 sec
|
|
73344
|
+
enabled: !!queryKey,
|
|
73345
|
+
retry: 1,
|
|
73346
|
+
});
|
|
73347
|
+
const zapError = !!error;
|
|
73348
|
+
const tokenList = zapInputTokens[chainId] ? zapInputTokens[chainId] : [];
|
|
73349
|
+
// toToken0 data
|
|
73350
|
+
const toToken0Estimate = response?.lpQuote?.token0?.fromAmountEstimate;
|
|
73351
|
+
const toToken0 = [...tokenList, principalToken]?.find((token) => token?.address?.[chainId]?.toLowerCase() === response?.lpQuote?.token0?.address?.toLowerCase());
|
|
73352
|
+
const toToken0Price = useCurrencyPrice(toToken0 ?? null, chainId);
|
|
73353
|
+
// toToken1 data
|
|
73354
|
+
const toToken1Estimate = response?.lpQuote?.token1?.fromAmountEstimate;
|
|
73355
|
+
const toToken1 = zapInputTokens[chainId]?.find((token) => token.address[chainId]?.toLowerCase() === response?.lpQuote?.token1?.address?.toLowerCase());
|
|
73356
|
+
const toToken1Price = useCurrencyPrice(toToken1 ?? null, chainId);
|
|
73357
|
+
let toToken0USD = new BigNumber$1(toToken0Estimate ?? '0')
|
|
73358
|
+
?.div(new BigNumber$1(10).pow(toToken0?.decimals[chainId] ?? 18)) // this is amount of swap output
|
|
73359
|
+
?.times(new BigNumber$1(toToken0Price?.price ?? 0)); // convert it to usd price
|
|
73360
|
+
if (response?.lpQuote?.token0?.fromAmountUSD) {
|
|
73361
|
+
toToken0USD = new BigNumber$1(response?.lpQuote?.token0?.fromAmountUSD);
|
|
73362
|
+
}
|
|
73363
|
+
let toToken1USD = new BigNumber$1(toToken1Estimate ?? '0')
|
|
73364
|
+
?.div(new BigNumber$1(10).pow(toToken1?.decimals[chainId] ?? 18)) // this is amount of swap output
|
|
73365
|
+
?.times(new BigNumber$1(toToken1Price?.price ?? 0)); // convert it to usd price
|
|
73366
|
+
if (response?.lpQuote?.token1?.fromAmountUSD) {
|
|
73367
|
+
toToken1USD = new BigNumber$1(response?.lpQuote?.token1?.fromAmountUSD);
|
|
73368
|
+
}
|
|
73369
|
+
const youSpendUSD = toToken0USD.plus(toToken1USD); // youSpendUSD
|
|
73370
|
+
const estimatedDepositAmount = youSpendUSD.div(bond?.principalTokenPrice ?? '0');
|
|
73371
|
+
const isWrap = inputCurrency === 'NATIVE' &&
|
|
73372
|
+
bond?.lpToken?.address?.[chainId]?.toLowerCase() === WNATIVE[chainId]?.address?.[chainId]?.toLowerCase();
|
|
73373
|
+
const estimatedDepositAmountToReturn = isWrap ? typedValue : estimatedDepositAmount.toString();
|
|
73374
|
+
const trueBondPrice = response?.protocolQuote?.trueBondPrice;
|
|
73375
|
+
const zapLoading = isLoading || isFetching;
|
|
73376
|
+
if (zapLoading)
|
|
73377
|
+
return [true, undefined, '', false, undefined];
|
|
73378
|
+
return [zapLoading, response, estimatedDepositAmountToReturn, zapError, trueBondPrice];
|
|
73379
|
+
};
|
|
73380
|
+
|
|
73223
73381
|
function useCurrencyBalance(currency, account, chainId) {
|
|
73224
73382
|
return useQuery({
|
|
73225
73383
|
queryKey: [
|
|
@@ -74296,7 +74454,7 @@ const SlippageModal = () => {
|
|
|
74296
74454
|
}, children: jsx$2(Text, { weight: 700, children: "%" }) })] })] })] }) }) }) }));
|
|
74297
74455
|
};
|
|
74298
74456
|
|
|
74299
|
-
const ZapModal = ({ onDismiss, outputToken, account, chainId }) => {
|
|
74457
|
+
const ZapModal = ({ onDismiss, outputToken, account, chainId, bondData }) => {
|
|
74300
74458
|
// State
|
|
74301
74459
|
const [pendingTx, setPendingTx] = useState(false);
|
|
74302
74460
|
const [typedValue, setTypedValue] = useState('');
|
|
@@ -74320,8 +74478,14 @@ const ZapModal = ({ onDismiss, outputToken, account, chainId }) => {
|
|
|
74320
74478
|
const isWrap = inputTokenString === 'NATIVE' &&
|
|
74321
74479
|
outputToken?.address?.[chainId]?.toLowerCase() === WNATIVE[chainId]?.address?.[chainId]?.toLowerCase();
|
|
74322
74480
|
const outputTokenBalanceString = outputTokenBalance ? new BigNumber$1(outputTokenBalance).toPrecision(5) : 'loading';
|
|
74323
|
-
// Zap Quote
|
|
74324
|
-
const [
|
|
74481
|
+
// Zap Quote - use bond quote when bondData is present, token quote otherwise
|
|
74482
|
+
const [tokenFetchingQuote, tokenZapData, tokenOutputValue, tokenZapError] = useSoulZapTokenQuote(typedValue, inputToken, bondData ? undefined : outputToken, chainId, account);
|
|
74483
|
+
const [bondFetchingQuote, bondZapData, bondDepositAmount, bondZapError] = useSoulZapBondQuote(typedValue, inputToken, bondData, account);
|
|
74484
|
+
const isBondZap = !!bondData;
|
|
74485
|
+
const fetchingQuote = isBondZap ? bondFetchingQuote : tokenFetchingQuote;
|
|
74486
|
+
const zapData = isBondZap ? bondZapData : tokenZapData;
|
|
74487
|
+
const outputValue = isBondZap ? parseFloat(bondDepositAmount || '0') : tokenOutputValue;
|
|
74488
|
+
const zapError = isBondZap ? bondZapError : tokenZapError;
|
|
74325
74489
|
// Functions
|
|
74326
74490
|
const handleCurrencySelect = useCallback((newInputToken) => {
|
|
74327
74491
|
setTypedValue('');
|
|
@@ -74409,139 +74573,6 @@ const ZapModal = ({ onDismiss, outputToken, account, chainId }) => {
|
|
|
74409
74573
|
: 'BUY' })) }), jsx$2(Flex, { sx: { marginTop: '10px', justifyContent: 'center' }, children: jsx$2(Link, { href: "https://docs.ape.bond/apebond/products-and-features/zap", target: "_blank", rel: "noopener noreferrer", sx: { textDecoration: 'none' }, children: jsxs(Text, { style: { fontSize: '12px', lineHeight: '18px', fontWeight: 400, borderBottom: '1px solid' }, children: ["Learn more", '>'] }) }) })] })] }));
|
|
74410
74574
|
};
|
|
74411
74575
|
|
|
74412
|
-
const useSoulZapBondQuote = (typedValue, inputCurrency, bond, account, tierProofSig) => {
|
|
74413
|
-
const debouncedInput = useDebounce(typedValue, 400);
|
|
74414
|
-
const [slippage] = useSlippage();
|
|
74415
|
-
const principalToken = bond?.lpToken;
|
|
74416
|
-
const bondContractAddress = bond?.contractAddress[bond?.chainId];
|
|
74417
|
-
const chainId = bond?.chainId;
|
|
74418
|
-
const inputCurrencyString = inputCurrency === 'NATIVE' ? '0x0000000000000000000000000000000000000000' : inputCurrency?.address[chainId];
|
|
74419
|
-
const inputCurrencyDecimals = inputCurrency === 'NATIVE' ? 18 : inputCurrency?.decimals[chainId];
|
|
74420
|
-
const principalContractAddress = principalToken?.address[chainId];
|
|
74421
|
-
const chainName = getChainParam(chainId);
|
|
74422
|
-
const isReserveBond = bond?.billType === 'reserve' || bond?.billType === 'staking';
|
|
74423
|
-
const liquidityDex = principalToken?.liquiditySource?.[chainId] ?? principalToken?.liquidityDex?.[chainId];
|
|
74424
|
-
const protocol = main.dexFactories[chainId]?.[liquidityDex]?.protocol;
|
|
74425
|
-
const lpType = isReserveBond ? 'single' : getLpType(protocol);
|
|
74426
|
-
const ichiUnderlyingDex = principalToken?.ichiUnderlyingDex;
|
|
74427
|
-
const vault = principalToken?.address?.[chainId];
|
|
74428
|
-
const router = main.dexFactories[chainId]?.[liquidityDex]?.router;
|
|
74429
|
-
// Validates that the user did not pass an amount with 19 decimals or more
|
|
74430
|
-
const validated18DecimalAmount = new BigNumber$1(debouncedInput ?? '0').toFixed(18, 5);
|
|
74431
|
-
const bigishInputAmount = new BigNumber$1(validated18DecimalAmount ?? '0')
|
|
74432
|
-
.times(new BigNumber$1(10).pow(inputCurrencyDecimals ?? 18))
|
|
74433
|
-
.toString();
|
|
74434
|
-
const zapInputData = useMemo(() => {
|
|
74435
|
-
if (inputCurrencyString &&
|
|
74436
|
-
inputCurrencyDecimals &&
|
|
74437
|
-
bigishInputAmount !== 'NaN' &&
|
|
74438
|
-
bigishInputAmount !== '0' &&
|
|
74439
|
-
principalContractAddress &&
|
|
74440
|
-
chainName &&
|
|
74441
|
-
bondContractAddress &&
|
|
74442
|
-
(inputCurrency === 'NATIVE' || inputCurrency?.address[chainId] !== principalToken.address[chainId])) {
|
|
74443
|
-
return {
|
|
74444
|
-
chain: chainName,
|
|
74445
|
-
recipient: account ?? '0x0000000000000000000000000000000000000000',
|
|
74446
|
-
user: account ?? '0x0000000000000000000000000000000000000000',
|
|
74447
|
-
lpData: {
|
|
74448
|
-
lpType,
|
|
74449
|
-
fromToken: inputCurrencyString,
|
|
74450
|
-
fromAmount: bigishInputAmount,
|
|
74451
|
-
underlyingDex: ichiUnderlyingDex,
|
|
74452
|
-
vault: isReserveBond ? undefined : vault,
|
|
74453
|
-
slippage: slippage,
|
|
74454
|
-
lpAddress: lpType === 'solidly' || lpType === 'univ2' || lpType === 'curve' ? vault : undefined,
|
|
74455
|
-
router: lpType === 'solidly' || lpType === 'univ2' ? router : undefined,
|
|
74456
|
-
toToken: isReserveBond ? vault : undefined,
|
|
74457
|
-
},
|
|
74458
|
-
protocolData: {
|
|
74459
|
-
protocol: 'ApeBond',
|
|
74460
|
-
bond: bondContractAddress,
|
|
74461
|
-
depositer: account ?? '0x0000000000000000000000000000000000000000',
|
|
74462
|
-
tierProofSignature: bond.billVersion === main.BillVersion.V4 && tierProofSig ? tierProofSig : undefined,
|
|
74463
|
-
},
|
|
74464
|
-
};
|
|
74465
|
-
}
|
|
74466
|
-
else {
|
|
74467
|
-
return null;
|
|
74468
|
-
}
|
|
74469
|
-
/* eslint-disable react-hooks/exhaustive-deps */
|
|
74470
|
-
}, [
|
|
74471
|
-
bigishInputAmount,
|
|
74472
|
-
principalContractAddress,
|
|
74473
|
-
chainName,
|
|
74474
|
-
account,
|
|
74475
|
-
ichiUnderlyingDex,
|
|
74476
|
-
vault,
|
|
74477
|
-
lpType,
|
|
74478
|
-
router,
|
|
74479
|
-
slippage,
|
|
74480
|
-
]);
|
|
74481
|
-
const queryKey = useMemo(() => {
|
|
74482
|
-
if (!zapInputData)
|
|
74483
|
-
return null;
|
|
74484
|
-
return [
|
|
74485
|
-
'zapBondDetails',
|
|
74486
|
-
zapInputData.chain,
|
|
74487
|
-
zapInputData.user,
|
|
74488
|
-
zapInputData.lpData.lpType,
|
|
74489
|
-
zapInputData.lpData.fromToken,
|
|
74490
|
-
zapInputData.lpData.fromAmount,
|
|
74491
|
-
zapInputData.lpData.underlyingDex ?? '',
|
|
74492
|
-
zapInputData.lpData.vault,
|
|
74493
|
-
zapInputData.lpData.slippage,
|
|
74494
|
-
zapInputData.lpData.lpAddress,
|
|
74495
|
-
zapInputData.lpData.router ?? '',
|
|
74496
|
-
];
|
|
74497
|
-
}, [zapInputData]);
|
|
74498
|
-
const fetchZapDetails = async () => {
|
|
74499
|
-
const response = await axios.post(SOUL_ZAP_API, {
|
|
74500
|
-
'0': zapInputData,
|
|
74501
|
-
});
|
|
74502
|
-
return response.data?.[0]?.result?.data;
|
|
74503
|
-
};
|
|
74504
|
-
const { data: response, isLoading, isFetching, error, } = useQuery({
|
|
74505
|
-
queryKey: [QUERY_KEYS.ZAP_TOKEN_QUOTE, queryKey],
|
|
74506
|
-
queryFn: fetchZapDetails,
|
|
74507
|
-
refetchInterval: 60000, // i.e. 60 sec
|
|
74508
|
-
enabled: !!queryKey,
|
|
74509
|
-
retry: 1,
|
|
74510
|
-
});
|
|
74511
|
-
const zapError = !!error;
|
|
74512
|
-
const tokenList = zapInputTokens[chainId] ? zapInputTokens[chainId] : [];
|
|
74513
|
-
// toToken0 data
|
|
74514
|
-
const toToken0Estimate = response?.lpQuote?.token0?.fromAmountEstimate;
|
|
74515
|
-
const toToken0 = [...tokenList, principalToken]?.find((token) => token?.address?.[chainId]?.toLowerCase() === response?.lpQuote?.token0?.address?.toLowerCase());
|
|
74516
|
-
const toToken0Price = useCurrencyPrice(toToken0 ?? null, chainId);
|
|
74517
|
-
// toToken1 data
|
|
74518
|
-
const toToken1Estimate = response?.lpQuote?.token1?.fromAmountEstimate;
|
|
74519
|
-
const toToken1 = zapInputTokens[chainId]?.find((token) => token.address[chainId]?.toLowerCase() === response?.lpQuote?.token1?.address?.toLowerCase());
|
|
74520
|
-
const toToken1Price = useCurrencyPrice(toToken1 ?? null, chainId);
|
|
74521
|
-
let toToken0USD = new BigNumber$1(toToken0Estimate ?? '0')
|
|
74522
|
-
?.div(new BigNumber$1(10).pow(toToken0?.decimals[chainId] ?? 18)) // this is amount of swap output
|
|
74523
|
-
?.times(new BigNumber$1(toToken0Price?.price ?? 0)); // convert it to usd price
|
|
74524
|
-
if (response?.lpQuote?.token0?.fromAmountUSD) {
|
|
74525
|
-
toToken0USD = new BigNumber$1(response?.lpQuote?.token0?.fromAmountUSD);
|
|
74526
|
-
}
|
|
74527
|
-
let toToken1USD = new BigNumber$1(toToken1Estimate ?? '0')
|
|
74528
|
-
?.div(new BigNumber$1(10).pow(toToken1?.decimals[chainId] ?? 18)) // this is amount of swap output
|
|
74529
|
-
?.times(new BigNumber$1(toToken1Price?.price ?? 0)); // convert it to usd price
|
|
74530
|
-
if (response?.lpQuote?.token1?.fromAmountUSD) {
|
|
74531
|
-
toToken1USD = new BigNumber$1(response?.lpQuote?.token1?.fromAmountUSD);
|
|
74532
|
-
}
|
|
74533
|
-
const youSpendUSD = toToken0USD.plus(toToken1USD); // youSpendUSD
|
|
74534
|
-
const estimatedDepositAmount = youSpendUSD.div(bond?.principalTokenPrice ?? '0');
|
|
74535
|
-
const isWrap = inputCurrency === 'NATIVE' &&
|
|
74536
|
-
bond?.lpToken?.address?.[chainId]?.toLowerCase() === WNATIVE[chainId]?.address?.[chainId]?.toLowerCase();
|
|
74537
|
-
const estimatedDepositAmountToReturn = isWrap ? typedValue : estimatedDepositAmount.toString();
|
|
74538
|
-
const trueBondPrice = response?.protocolQuote?.trueBondPrice;
|
|
74539
|
-
const zapLoading = isLoading || isFetching;
|
|
74540
|
-
if (zapLoading)
|
|
74541
|
-
return [true, undefined, '', false, undefined];
|
|
74542
|
-
return [zapLoading, response, estimatedDepositAmountToReturn, zapError, trueBondPrice];
|
|
74543
|
-
};
|
|
74544
|
-
|
|
74545
74576
|
const useSendReferenceId = () => {
|
|
74546
74577
|
const config = useSDKConfig();
|
|
74547
74578
|
const apiV2URL = useURLByEnvironment('apiV2');
|
|
@@ -75425,7 +75456,7 @@ const BuyBond$1 = ({ onDismiss, bondAddress, bondChain, handlePurchasedBond, isP
|
|
|
75425
75456
|
// Modals
|
|
75426
75457
|
const [openNewRateModal] = useModal(jsx$2(NewRateModal$1, { bond: bondData, zapTrueBondPrice: zapTrueBondPrice, depositAmount: depositAmount, youSpendString: youSpendString, fetchingZapQuote: fetchingZapQuote, zapError: zapError }), true, false, 'newRateModal');
|
|
75427
75458
|
const [openTxModal] = useModal(jsx$2(TransactionModal$2, { txChain: bondChain, approvalState: approvalState, approveCallback: handleApprove, loadingTx: loadingTx, txCallback: handleBothPurchases, bondData: bondData, inputToken: inputToken, inputValue: inputValue, depositAmount: depositAmount, buyTxHash: buyTxHash, rateChanged: rateChanged }), false, true, 'transactionModal');
|
|
75428
|
-
const [onOpenZapModal] = useModal(jsx$2(ZapModal, { outputToken: bondData?.lpToken, account: account, chainId: bondData?.chainId }), true, true, 'zapModal');
|
|
75459
|
+
const [onOpenZapModal] = useModal(jsx$2(ZapModal, { outputToken: bondData?.lpToken, account: account, chainId: bondData?.chainId, bondData: bondData }), true, true, 'zapModal');
|
|
75429
75460
|
const [openNoBonusModal] = useModal(jsx$2(NoBonusModal, { onAcknowledge: openTxModal, showcaseTokenName: bondData?.showcaseTokenName }), true, true, 'NoBonusModal');
|
|
75430
75461
|
// Effects
|
|
75431
75462
|
const [hasChecked, setHasChecked] = useState(false);
|
|
@@ -99885,7 +99916,7 @@ const BuyBond = ({ onDismiss, bondAddress, bondChain, handlePurchasedBond, isPro
|
|
|
99885
99916
|
// Modals
|
|
99886
99917
|
useModal(jsx$2(NewRateModal, { bond: bondData, zapTrueBondPrice: zapTrueBondPrice, depositAmount: depositAmount, youSpendString: youSpendString, fetchingZapQuote: fetchingZapQuote, zapError: zapError }), true, false, 'newRateModal');
|
|
99887
99918
|
const [openTxModal] = useModal(jsx$2(TransactionModal$1, { txChain: bondChain, approvalState: approvalState, approveCallback: handleApprove, loadingTx: loadingTx, txCallback: handleBothPurchases, bondData: bondData, inputToken: inputToken, inputValue: inputValue, depositAmount: depositAmount, buyTxHash: buyTxHash, rateChanged: rateChanged, onDismiss: onDismiss }), false, true, 'transactionModal');
|
|
99888
|
-
useModal(jsx$2(ZapModal, { outputToken: bondData?.lpToken, account: account, chainId: bondData?.chainId }), true, true, 'zapModal');
|
|
99919
|
+
useModal(jsx$2(ZapModal, { outputToken: bondData?.lpToken, account: account, chainId: bondData?.chainId, bondData: bondData }), true, true, 'zapModal');
|
|
99889
99920
|
// Effects
|
|
99890
99921
|
const [hasChecked, setHasChecked] = useState(false);
|
|
99891
99922
|
const [hasCheckedTrack, setHasCheckedTrack] = useState(false);
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import React from 'react';
|
|
2
2
|
import { ChainId, Token } from '@ape.swap/apeswap-lists';
|
|
3
|
+
import { BondsData } from '../../types/bonds';
|
|
3
4
|
/**
|
|
4
5
|
* @param chainId this is the chainId of the outputToken
|
|
5
6
|
*/
|
|
@@ -8,6 +9,7 @@ interface ZapModalProps {
|
|
|
8
9
|
outputToken: Token;
|
|
9
10
|
chainId: ChainId;
|
|
10
11
|
account?: string;
|
|
12
|
+
bondData?: BondsData;
|
|
11
13
|
}
|
|
12
|
-
declare const ZapModal: ({ onDismiss, outputToken, account, chainId }: ZapModalProps) => React.JSX.Element;
|
|
14
|
+
declare const ZapModal: ({ onDismiss, outputToken, account, chainId, bondData }: ZapModalProps) => React.JSX.Element;
|
|
13
15
|
export default ZapModal;
|