@ape.swap/bonds-sdk 1.0.78-2.test.28 → 1.0.78-2.test.30

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.
Files changed (44) hide show
  1. package/dist/components/TokenSelectorModal/TokenRow.d.ts +8 -0
  2. package/dist/components/TokenSelectorModal/TokenRow.js +18 -0
  3. package/dist/components/TokenSelectorModal/index.d.ts +11 -0
  4. package/dist/components/TokenSelectorModal/index.js +56 -0
  5. package/dist/components/TokenSelectorPanel/index.d.ts +16 -0
  6. package/dist/components/TokenSelectorPanel/index.js +36 -0
  7. package/dist/components/uikit-sdk/TokenImage/index.d.ts +3 -2
  8. package/dist/components/uikit-sdk/TokenImage/index.js +27 -4
  9. package/dist/config/abi/price-getter-linea.json +1448 -0
  10. package/dist/config/abi/price-getter.json +1309 -0
  11. package/dist/config/constants/queryKeys.d.ts +4 -1
  12. package/dist/config/constants/queryKeys.js +24 -1
  13. package/dist/config/constants/tokens.d.ts +3 -6
  14. package/dist/config/constants/tokens.js +64 -452
  15. package/dist/config/constants/zapInputTokens.d.ts +2 -0
  16. package/dist/config/constants/zapInputTokens.js +356 -0
  17. package/dist/hooks/useTokenFromZapList.d.ts +3 -0
  18. package/dist/hooks/useTokenFromZapList.js +10 -0
  19. package/dist/providers/index.d.ts +0 -3
  20. package/dist/providers/index.js +6 -0
  21. package/dist/scss/BondModal.scss +215 -195
  22. package/dist/state/allowance/useAllowance.d.ts +11 -0
  23. package/dist/state/allowance/useAllowance.js +148 -0
  24. package/dist/state/balance/useCurrencyBalance.d.ts +4 -0
  25. package/dist/state/balance/useCurrencyBalance.js +80 -0
  26. package/dist/state/price/useCurrencyPrice.d.ts +19 -0
  27. package/dist/state/price/useCurrencyPrice.js +397 -0
  28. package/dist/state/zap/getChainParam.d.ts +12 -0
  29. package/dist/state/zap/getChainParam.js +34 -0
  30. package/dist/state/zap/useSoulZapBondQuote.d.ts +4 -0
  31. package/dist/state/zap/useSoulZapBondQuote.js +177 -0
  32. package/dist/state/zap/useSoulZapTokenQuote.d.ts +3 -0
  33. package/dist/state/zap/useSoulZapTokenQuote.js +167 -0
  34. package/dist/utils/getNativeTicker.d.ts +3 -0
  35. package/dist/utils/getNativeTicker.js +8 -0
  36. package/dist/views/BondModal/BondModal.js +2 -2
  37. package/dist/views/Bonds/Bonds.d.ts +1 -1
  38. package/dist/views/Bonds/index.d.ts +4 -0
  39. package/dist/views/Bonds/index.js +18 -0
  40. package/dist/views/ZapModal/index.d.ts +14 -0
  41. package/dist/views/ZapModal/index.js +150 -0
  42. package/dist/views/ZapModal/styles.d.ts +2 -0
  43. package/dist/views/ZapModal/styles.js +35 -0
  44. package/package.json +3 -1
@@ -0,0 +1,150 @@
1
+ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
2
+ function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
3
+ return new (P || (P = Promise))(function (resolve, reject) {
4
+ function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
5
+ function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
6
+ function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
7
+ step((generator = generator.apply(thisArg, _arguments || [])).next());
8
+ });
9
+ };
10
+ var __generator = (this && this.__generator) || function (thisArg, body) {
11
+ var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g = Object.create((typeof Iterator === "function" ? Iterator : Object).prototype);
12
+ return g.next = verb(0), g["throw"] = verb(1), g["return"] = verb(2), typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
13
+ function verb(n) { return function (v) { return step([n, v]); }; }
14
+ function step(op) {
15
+ if (f) throw new TypeError("Generator is already executing.");
16
+ while (g && (g = 0, op[0] && (_ = 0)), _) try {
17
+ if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t;
18
+ if (y = 0, t) op = [op[0] & 2, t.value];
19
+ switch (op[0]) {
20
+ case 0: case 1: t = op; break;
21
+ case 4: _.label++; return { value: op[1], done: false };
22
+ case 5: _.label++; y = op[1]; op = [0]; continue;
23
+ case 7: op = _.ops.pop(); _.trys.pop(); continue;
24
+ default:
25
+ if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }
26
+ if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }
27
+ if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }
28
+ if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }
29
+ if (t[2]) _.ops.pop();
30
+ _.trys.pop(); continue;
31
+ }
32
+ op = body.call(thisArg, _);
33
+ } catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }
34
+ if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
35
+ }
36
+ };
37
+ import { jsx as _jsx, jsxs as _jsxs } from "theme-ui/jsx-runtime";
38
+ import { useCallback, useState } from 'react';
39
+ import { Button, Flex, Modal, Svg, Text } from '../../components/uikit-sdk';
40
+ import BigNumber from 'bignumber.js';
41
+ import { SoulZapTokenManager } from '../../config/constants/addresses';
42
+ import ModalHeader from '../../components/uikit-sdk/Modal/ModalHeader';
43
+ import { Box, Link } from 'theme-ui';
44
+ import { NumericInput } from '../../components/uikit-sdk/Input';
45
+ import { isArray } from 'lodash';
46
+ import { styles } from './styles';
47
+ import TokenImage from '../../components/uikit-sdk/TokenImage';
48
+ import { NETWORK_LABEL } from '../../config/constants/chains';
49
+ import TokenSelectorPanel from '../../components/TokenSelectorPanel';
50
+ import { useChainId, useSendTransaction, useSwitchChain, useWaitForTransactionReceipt } from 'wagmi';
51
+ import useSoulZapTokenQuote from '../../state/zap/useSoulZapTokenQuote';
52
+ import { ConnectButton } from '@rainbow-me/rainbowkit';
53
+ import useCurrencyBalance from '../../state/balance/useCurrencyBalance';
54
+ import useCurrencyPrice from '../../state/price/useCurrencyPrice';
55
+ import { ApprovalState, useApproval } from '../../state/allowance/useAllowance';
56
+ import { parseEther } from 'viem';
57
+ import useTokenFromZapList from '../../hooks/useTokenFromZapList';
58
+ var ZapModal = function (_a) {
59
+ var _b, _c, _d, _e;
60
+ var onDismiss = _a.onDismiss, outputToken = _a.outputToken, account = _a.account, chainId = _a.chainId;
61
+ // State
62
+ var _f = useState(false), pendingTx = _f[0], setPendingTx = _f[1];
63
+ var _g = useState(''), typedValue = _g[0], setTypedValue = _g[1];
64
+ var _h = useState('NATIVE'), inputTokenString = _h[0], setInputTokenString = _h[1];
65
+ // Hooks
66
+ var userChainId = useChainId();
67
+ var switchChain = useSwitchChain().switchChain;
68
+ var inputToken = useTokenFromZapList(inputTokenString);
69
+ var _j = useSendTransaction(), hash = _j.data, sendTransactionAsync = _j.sendTransactionAsync;
70
+ var _k = useWaitForTransactionReceipt({
71
+ confirmations: 1,
72
+ chainId: chainId,
73
+ hash: hash,
74
+ }), isConfirming = _k.isLoading, isConfirmed = _k.isSuccess;
75
+ // TODO: add slippage Modal
76
+ // const [onPresentSettingsModal] = useModal(<ZapSlippage />)
77
+ // Prices & Balances
78
+ var outputTokenBalance = useCurrencyBalance(outputToken !== null && outputToken !== void 0 ? outputToken : null, account !== null && account !== void 0 ? account : null, chainId).data;
79
+ var outputTokenPrice = useCurrencyPrice(outputToken !== null && outputToken !== void 0 ? outputToken : null, chainId).data;
80
+ var inputTokenBalance = useCurrencyBalance(inputToken !== null && inputToken !== void 0 ? inputToken : null, account !== null && account !== void 0 ? account : null, chainId).data;
81
+ var inputTokenPrice = useCurrencyPrice(inputToken !== null && inputToken !== void 0 ? inputToken : null, chainId).data;
82
+ var hasEnoughBalance = new BigNumber(typedValue).lte(new BigNumber(inputTokenBalance !== null && inputTokenBalance !== void 0 ? inputTokenBalance : '0'));
83
+ var splited = (_b = outputToken === null || outputToken === void 0 ? void 0 : outputToken.symbol) === null || _b === void 0 ? void 0 : _b.split('-');
84
+ var outputTokenBalanceString = outputTokenBalance ? new BigNumber(outputTokenBalance).toPrecision(5) : 'loading';
85
+ // Zap Quote
86
+ var _l = useSoulZapTokenQuote(typedValue, inputToken, outputToken, chainId, account), fetchingQuote = _l[0], zapData = _l[1], outputValue = _l[2];
87
+ // Functions
88
+ var handleCurrencySelect = useCallback(function (newInputToken) {
89
+ setTypedValue('');
90
+ setInputTokenString(newInputToken);
91
+ }, []);
92
+ var handleMaxInput = useCallback(function () {
93
+ setTypedValue(inputTokenBalance !== null && inputTokenBalance !== void 0 ? inputTokenBalance : '');
94
+ }, [inputTokenBalance]);
95
+ var soulZapCallback = useCallback(function () { return __awaiter(void 0, void 0, void 0, function () {
96
+ var validated18DecimalAmount, parsedValue, e_1;
97
+ var _a, _b;
98
+ return __generator(this, function (_c) {
99
+ switch (_c.label) {
100
+ case 0:
101
+ if (!(zapData && ((_a = zapData === null || zapData === void 0 ? void 0 : zapData.txData) === null || _a === void 0 ? void 0 : _a.to) && ((_b = zapData === null || zapData === void 0 ? void 0 : zapData.txData) === null || _b === void 0 ? void 0 : _b.data))) return [3 /*break*/, 4];
102
+ _c.label = 1;
103
+ case 1:
104
+ _c.trys.push([1, 3, , 4]);
105
+ console.log(zapData);
106
+ console.log('Attempting zap tx');
107
+ validated18DecimalAmount = new BigNumber(typedValue !== null && typedValue !== void 0 ? typedValue : '0').toFixed(18, 5);
108
+ parsedValue = parseEther(validated18DecimalAmount);
109
+ setPendingTx(true);
110
+ return [4 /*yield*/, sendTransactionAsync({
111
+ to: zapData.txData.to,
112
+ data: zapData.txData.data,
113
+ value: inputToken === 'NATIVE' ? parsedValue : undefined,
114
+ }).finally(function () { return setPendingTx(false); })];
115
+ case 2:
116
+ _c.sent();
117
+ return [3 /*break*/, 4];
118
+ case 3:
119
+ e_1 = _c.sent();
120
+ console.error(e_1);
121
+ setPendingTx(false);
122
+ return [3 /*break*/, 4];
123
+ case 4: return [2 /*return*/];
124
+ }
125
+ });
126
+ }); }, [zapData, (_c = zapData === null || zapData === void 0 ? void 0 : zapData.txData) === null || _c === void 0 ? void 0 : _c.to, (_d = zapData === null || zapData === void 0 ? void 0 : zapData.txData) === null || _d === void 0 ? void 0 : _d.data]);
127
+ // Approve hook
128
+ var _m = useApproval(typedValue, inputToken !== null && inputToken !== void 0 ? inputToken : null, (_e = SoulZapTokenManager[chainId]) !== null && _e !== void 0 ? _e : null, account !== null && account !== void 0 ? account : null, chainId), approvalState = _m[0], approveCallback = _m[1];
129
+ var handleApprove = useCallback(function () { return __awaiter(void 0, void 0, void 0, function () {
130
+ return __generator(this, function (_a) {
131
+ switch (_a.label) {
132
+ case 0:
133
+ setPendingTx(true);
134
+ return [4 /*yield*/, approveCallback().finally(function () { return setPendingTx(false); })];
135
+ case 1:
136
+ _a.sent();
137
+ return [2 /*return*/];
138
+ }
139
+ });
140
+ }); }, []);
141
+ return (_jsxs(Modal, { children: [_jsx(ModalHeader, { onDismiss: onDismiss, children: _jsxs(Flex, { sx: { width: '100%', justifyContent: 'space-between' }, children: [_jsx(Text, { sx: { fontSize: '22px', fontWeight: 700, lineHeight: '33px' }, children: "Liquidity" }), _jsx(Flex, { sx: { cursor: 'pointer', mr: '15px' }, onClick: function () { return null; }, children: _jsx(Svg, { icon: "cog", width: "16px" }) })] }) }), _jsxs(Flex, { sx: { flexDirection: 'column', pt: '10px', gap: '10px' }, children: [_jsx(Flex, { sx: { position: 'relative' }, children: _jsx(Text, { children: "From:" }) }), _jsx(Flex, { sx: { width: '100%', height: 'auto', justifyContent: 'space-between' }, children: _jsx(TokenSelectorPanel, { typedValue: typedValue, setTypedValue: setTypedValue, selectedToken: inputToken, handleMaxBtn: handleMaxInput, handleCurrencySelect: handleCurrencySelect, chainId: chainId, enableZap: true, tokenBalance: inputTokenBalance, selectedTokenPrice: inputTokenPrice === null || inputTokenPrice === void 0 ? void 0 : inputTokenPrice.price }) }), _jsxs(Flex, { sx: { position: 'relative', mt: '10px' }, children: [_jsx(Text, { children: "To:" }), _jsx(Box, { sx: { position: 'absolute', top: '50%', left: '50%', transform: 'translate(-50%, -50%)' }, children: _jsx(Svg, { icon: "ZapArrow" }) })] }), _jsxs(Flex, { sx: styles.toPanelContainer, children: [_jsxs(Flex, { sx: styles.cont, children: [_jsx(NumericInput, { value: parseFloat(outputValue) === 0 ? '' : outputValue, onUserInput: function () { return null; } }), _jsxs(Flex, { sx: styles.tokensContainer, children: [isArray(splited) && _jsx(TokenImage, { symbol: splited[0], symbol2: splited[1], size: 28 }), _jsx(Text, { sx: styles.tokenSymbolText, children: outputToken === null || outputToken === void 0 ? void 0 : outputToken.symbol })] })] }), _jsxs(Flex, { sx: { width: '100%', justifyContent: 'space-between' }, children: [_jsx(Flex, { sx: { alignItems: 'center', justifyContent: 'center' }, children: _jsx(Text, { size: "12px", sx: { opacity: 0.8 }, children: outputTokenPrice &&
142
+ (outputTokenPrice === null || outputTokenPrice === void 0 ? void 0 : outputTokenPrice.price) &&
143
+ outputValue &&
144
+ parseFloat(outputValue) !== 0 &&
145
+ "$".concat(((outputTokenPrice === null || outputTokenPrice === void 0 ? void 0 : outputTokenPrice.price) * parseFloat(outputValue)).toFixed(2)) }) }), _jsx(Flex, { sx: { alignItems: 'center' }, children: account ? (_jsxs(Text, { size: "12px", sx: { opacity: 0.8 }, children: ["Balance: ", outputTokenBalanceString] })) : null })] })] }), _jsx(Flex, { className: "button-container zap", children: !account ? (_jsx(ConnectButton, {})) : userChainId !== chainId ? (_jsxs(Button, { className: "switch-button zap", onClick: function (event) {
146
+ event.stopPropagation();
147
+ switchChain({ chainId: chainId });
148
+ }, children: ["Switch to ", NETWORK_LABEL[chainId]] })) : approvalState === ApprovalState.NOT_APPROVED || approvalState === ApprovalState.PENDING ? (_jsx(Button, { onClick: handleApprove, fullWidth: true, load: approvalState === ApprovalState.PENDING || pendingTx, disable: approvalState === ApprovalState.PENDING || pendingTx, children: pendingTx || approvalState === ApprovalState.PENDING ? 'ENABLING' : 'ENABLE' })) : (_jsx(Button, { onClick: soulZapCallback, fullWidth: true, load: pendingTx || fetchingQuote || isConfirming, disabled: pendingTx || fetchingQuote || !zapData || !hasEnoughBalance || isConfirming, children: "BUY" })) }), _jsx(Flex, { sx: { marginTop: '10px', justifyContent: 'center' }, children: _jsx(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", '>'] }) }) })] })] }));
149
+ };
150
+ export default ZapModal;
@@ -0,0 +1,2 @@
1
+ import { ThemeUIStyleObject } from 'theme-ui';
2
+ export declare const styles: Record<'toPanelContainer' | 'cont' | 'tokensContainer' | 'tokenSymbolText', ThemeUIStyleObject>;
@@ -0,0 +1,35 @@
1
+ export var styles = {
2
+ toPanelContainer: {
3
+ position: 'relative',
4
+ width: '100%',
5
+ height: '94px',
6
+ background: 'white3',
7
+ padding: '10px',
8
+ borderRadius: 'normal',
9
+ justifyContent: 'space-between',
10
+ flexDirection: 'column',
11
+ },
12
+ cont: {
13
+ width: '100%',
14
+ height: 'auto',
15
+ justifyContent: 'space-between',
16
+ },
17
+ tokensContainer: {
18
+ minWidth: 'max-content',
19
+ height: '40px',
20
+ background: 'white4',
21
+ padding: '5px 10px',
22
+ borderRadius: 'normal',
23
+ alignItems: 'center',
24
+ justifyContent: 'center',
25
+ transition: 'all .3s linear',
26
+ '&:active': {
27
+ transform: 'scale(0.9)',
28
+ },
29
+ },
30
+ tokenSymbolText: {
31
+ fontSize: '14px',
32
+ margin: '0px 7.5px',
33
+ textTransform: 'uppercase',
34
+ },
35
+ };
package/package.json CHANGED
@@ -3,7 +3,7 @@
3
3
  "description": "Ape Bond SDK",
4
4
  "author": "Ape Bond",
5
5
  "license": "MIT",
6
- "version": "1.0.78-2.test.28",
6
+ "version": "1.0.78-2.test.30",
7
7
  "main": "dist/index.js",
8
8
  "module": "dist/index.es.js",
9
9
  "types": "dist/index.d.ts",
@@ -64,8 +64,10 @@
64
64
  "@ape.swap/sdk-core": "^1.0.2",
65
65
  "@emotion/react": "^11.11.4",
66
66
  "@emotion/styled": "^11.11.5",
67
+ "@rainbow-me/rainbowkit": "^2.1.7",
67
68
  "@reduxjs/toolkit": "^2.2.6",
68
69
  "@tanstack/react-query": "^5.51.5",
70
+ "@tanstack/react-query-devtools": "^5.58.0",
69
71
  "@types/node": "^20.14.10",
70
72
  "@uniswap/token-lists": "^1.0.0-beta.34",
71
73
  "axios-retry": "^4.4.2",