@ape.swap/bonds-sdk 1.0.603 → 1.0.605
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.
|
@@ -61,10 +61,14 @@ var BondModal = function (_a) {
|
|
|
61
61
|
if (!isOpen)
|
|
62
62
|
return null;
|
|
63
63
|
var _b = useWriteContract(), hash = _b.data, isPending = _b.isPending, writeContract = _b.writeContract, writeContractAsync = _b.writeContractAsync;
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
64
|
+
// const transactionReceipt = async (txHash: `0x${string}`) => {
|
|
65
|
+
// return useWaitForTransactionReceipt({
|
|
66
|
+
// confirmations: 4,
|
|
67
|
+
// hash: txHash,
|
|
68
|
+
// pollingInterval: 1_000
|
|
69
|
+
// });
|
|
70
|
+
// }
|
|
71
|
+
var _c = useState([]), bondData = _c[0], setBondData = _c[1];
|
|
68
72
|
//This is a temp solution, but we will force approval each time, and then once set we will set status here and allow
|
|
69
73
|
//user to buy
|
|
70
74
|
//Check with Fede if this needs to be temp, if we force approval everytime, isn't this fine?
|
|
@@ -107,10 +111,10 @@ var BondModal = function (_a) {
|
|
|
107
111
|
}
|
|
108
112
|
});
|
|
109
113
|
}); };
|
|
110
|
-
var
|
|
114
|
+
var _d = useState(null), buyTx = _d[0], setBuyTx = _d[1];
|
|
111
115
|
//You approve the token, not the contract (this code will have to be updated for zap)
|
|
112
116
|
var handleApprove = function () { return __awaiter(void 0, void 0, void 0, function () {
|
|
113
|
-
var tokenAddress, decimals, amount, tx, error_2;
|
|
117
|
+
var tokenAddress, decimals, amount, tx, receipt, error_2;
|
|
114
118
|
return __generator(this, function (_a) {
|
|
115
119
|
switch (_a.label) {
|
|
116
120
|
case 0:
|
|
@@ -129,7 +133,16 @@ var BondModal = function (_a) {
|
|
|
129
133
|
})];
|
|
130
134
|
case 2:
|
|
131
135
|
tx = _a.sent();
|
|
132
|
-
|
|
136
|
+
receipt = useWaitForTransactionReceipt({
|
|
137
|
+
confirmations: 4,
|
|
138
|
+
hash: tx,
|
|
139
|
+
pollingInterval: 1000
|
|
140
|
+
});
|
|
141
|
+
;
|
|
142
|
+
if (receipt.isSuccess) {
|
|
143
|
+
setReceiptTx(receipt.data.transactionHash);
|
|
144
|
+
console.log('Receipt:', receipt);
|
|
145
|
+
}
|
|
133
146
|
if (tx) {
|
|
134
147
|
setApproveTx(tx);
|
|
135
148
|
console.log('setApproveTx:', tx);
|
|
@@ -144,45 +157,10 @@ var BondModal = function (_a) {
|
|
|
144
157
|
}
|
|
145
158
|
});
|
|
146
159
|
}); };
|
|
160
|
+
var _e = useState(null), receiptTx = _e[0], setReceiptTx = _e[1];
|
|
147
161
|
var _f = useState(null), approveTx = _f[0], setApproveTx = _f[1];
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
axios.get('https://realtime-api.ape.bond/bonds').then(function (response) {
|
|
151
|
-
var bond = response.data.bonds.filter(function (x) {
|
|
152
|
-
return x.billAddress.toLowerCase() === (bondAddress === null || bondAddress === void 0 ? void 0 : bondAddress.toLowerCase());
|
|
153
|
-
});
|
|
154
|
-
setBondData(bond);
|
|
155
|
-
});
|
|
156
|
-
}, [bondAddress]);
|
|
157
|
-
// Functions for calculations
|
|
158
|
-
var getDiscountColor = function (discount) {
|
|
159
|
-
return discount < 0 ? 'discount-negative' : 'discount-positive';
|
|
160
|
-
};
|
|
161
|
-
var discountEarnTokenPrice = function (bond) {
|
|
162
|
-
var _a, _b;
|
|
163
|
-
var earnTokenPrice = parseFloat((_a = bond === null || bond === void 0 ? void 0 : bond.payoutTokenPrice) !== null && _a !== void 0 ? _a : '0');
|
|
164
|
-
return getFirstNonZeroDigits(earnTokenPrice - earnTokenPrice * (((_b = bond === null || bond === void 0 ? void 0 : bond.discount) !== null && _b !== void 0 ? _b : 0) / 100));
|
|
165
|
-
};
|
|
166
|
-
var earnTokenPrice = function (bond) {
|
|
167
|
-
var _a;
|
|
168
|
-
return getFirstNonZeroDigits(parseFloat((_a = bond === null || bond === void 0 ? void 0 : bond.payoutTokenPrice) !== null && _a !== void 0 ? _a : '0'));
|
|
169
|
-
};
|
|
170
|
-
var vestingTime = function (vestingTerm) { return getTimePeriods(vestingTerm !== null && vestingTerm !== void 0 ? vestingTerm : 0, true); };
|
|
171
|
-
var maxBuy = function (bond) {
|
|
172
|
-
var _a, _b, _c, _d;
|
|
173
|
-
var available = new BigNumber((_a = bond === null || bond === void 0 ? void 0 : bond.tokensRemaining) !== null && _a !== void 0 ? _a : '0');
|
|
174
|
-
var threshold = 5;
|
|
175
|
-
var thresholdToShow = new BigNumber(threshold).div((_b = bond === null || bond === void 0 ? void 0 : bond.payoutTokenPrice) !== null && _b !== void 0 ? _b : 0);
|
|
176
|
-
var safeAvailable = available.minus(thresholdToShow);
|
|
177
|
-
var singlePurchaseLimit = new BigNumber((_c = bond === null || bond === void 0 ? void 0 : bond.maxPayout) !== null && _c !== void 0 ? _c : 0).div(new BigNumber(10).pow((_d = bond === null || bond === void 0 ? void 0 : bond.payoutTokenDecimals) !== null && _d !== void 0 ? _d : 18));
|
|
178
|
-
return !available ? 0 : (singlePurchaseLimit.lt(safeAvailable) ? singlePurchaseLimit : safeAvailable);
|
|
179
|
-
};
|
|
180
|
-
var _g = useState(''), inputValue = _g[0], setInputValue = _g[1];
|
|
181
|
-
var handleInputChange = function (event) {
|
|
182
|
-
setInputValue(event.target.value);
|
|
183
|
-
};
|
|
184
|
-
var _h = useState(null), tokenBalance = _h[0], setTokenBalance = _h[1];
|
|
185
|
-
var _j = useState(null), tokenDecimals = _j[0], setTokenDecimals = _j[1];
|
|
162
|
+
var _g = useState(null), tokenBalance = _g[0], setTokenBalance = _g[1];
|
|
163
|
+
var _h = useState(null), tokenDecimals = _h[0], setTokenDecimals = _h[1];
|
|
186
164
|
useEffect(function () {
|
|
187
165
|
if (isActive && account && bondData.length > 0) {
|
|
188
166
|
getTokenBalance(bondData[0].chainId, bondData[0].principalToken, account).then(function (_a) {
|
|
@@ -209,8 +187,6 @@ var BondModal = function (_a) {
|
|
|
209
187
|
return [4 /*yield*/, contract.decimals()];
|
|
210
188
|
case 1:
|
|
211
189
|
decimals = _a.sent();
|
|
212
|
-
console.log('Decimals:', decimals);
|
|
213
|
-
console.log(decimals);
|
|
214
190
|
return [4 /*yield*/, contract.balanceOf(walletAddress)];
|
|
215
191
|
case 2:
|
|
216
192
|
balance = _a.sent();
|
|
@@ -220,11 +196,47 @@ var BondModal = function (_a) {
|
|
|
220
196
|
case 3:
|
|
221
197
|
error_3 = _a.sent();
|
|
222
198
|
console.error('Error fetching token balance', error_3);
|
|
223
|
-
return [2 /*return*/, { balanceInEther: '0', decimals: 0 }];
|
|
199
|
+
return [2 /*return*/, { balanceInEther: '0', decimals: 0 }];
|
|
224
200
|
case 4: return [2 /*return*/];
|
|
225
201
|
}
|
|
226
202
|
});
|
|
227
203
|
}); };
|
|
204
|
+
// Fetch data
|
|
205
|
+
useEffect(function () {
|
|
206
|
+
axios.get('https://realtime-api.ape.bond/bonds').then(function (response) {
|
|
207
|
+
var bond = response.data.bonds.filter(function (x) {
|
|
208
|
+
return x.billAddress.toLowerCase() === (bondAddress === null || bondAddress === void 0 ? void 0 : bondAddress.toLowerCase());
|
|
209
|
+
});
|
|
210
|
+
setBondData(bond);
|
|
211
|
+
});
|
|
212
|
+
}, [bondAddress]);
|
|
213
|
+
// Functions for calculations
|
|
214
|
+
var getDiscountColor = function (discount) {
|
|
215
|
+
return discount < 0 ? 'discount-negative' : 'discount-positive';
|
|
216
|
+
};
|
|
217
|
+
var discountEarnTokenPrice = function (bond) {
|
|
218
|
+
var _a, _b;
|
|
219
|
+
var earnTokenPrice = parseFloat((_a = bond === null || bond === void 0 ? void 0 : bond.payoutTokenPrice) !== null && _a !== void 0 ? _a : '0');
|
|
220
|
+
return getFirstNonZeroDigits(earnTokenPrice - earnTokenPrice * (((_b = bond === null || bond === void 0 ? void 0 : bond.discount) !== null && _b !== void 0 ? _b : 0) / 100));
|
|
221
|
+
};
|
|
222
|
+
var earnTokenPrice = function (bond) {
|
|
223
|
+
var _a;
|
|
224
|
+
return getFirstNonZeroDigits(parseFloat((_a = bond === null || bond === void 0 ? void 0 : bond.payoutTokenPrice) !== null && _a !== void 0 ? _a : '0'));
|
|
225
|
+
};
|
|
226
|
+
var vestingTime = function (vestingTerm) { return getTimePeriods(vestingTerm !== null && vestingTerm !== void 0 ? vestingTerm : 0, true); };
|
|
227
|
+
var maxBuy = function (bond) {
|
|
228
|
+
var _a, _b, _c, _d;
|
|
229
|
+
var available = new BigNumber((_a = bond === null || bond === void 0 ? void 0 : bond.tokensRemaining) !== null && _a !== void 0 ? _a : '0');
|
|
230
|
+
var threshold = 5;
|
|
231
|
+
var thresholdToShow = new BigNumber(threshold).div((_b = bond === null || bond === void 0 ? void 0 : bond.payoutTokenPrice) !== null && _b !== void 0 ? _b : 0);
|
|
232
|
+
var safeAvailable = available.minus(thresholdToShow);
|
|
233
|
+
var singlePurchaseLimit = new BigNumber((_c = bond === null || bond === void 0 ? void 0 : bond.maxPayout) !== null && _c !== void 0 ? _c : 0).div(new BigNumber(10).pow((_d = bond === null || bond === void 0 ? void 0 : bond.payoutTokenDecimals) !== null && _d !== void 0 ? _d : 18));
|
|
234
|
+
return !available ? 0 : (singlePurchaseLimit.lt(safeAvailable) ? singlePurchaseLimit : safeAvailable);
|
|
235
|
+
};
|
|
236
|
+
var _j = useState(''), inputValue = _j[0], setInputValue = _j[1];
|
|
237
|
+
var handleInputChange = function (event) {
|
|
238
|
+
setInputValue(event.target.value);
|
|
239
|
+
};
|
|
228
240
|
return (_jsx(ThemeUIProvider, { theme: defaultTheme, children: bondData.map(function (bond) {
|
|
229
241
|
var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k, _l, _m, _o;
|
|
230
242
|
return (_jsx(React.Fragment, { children: _jsx(Flex, { className: "modal modal-backdrop", children: _jsxs(Flex, { className: "modal modal-content", children: [_jsx(Flex, { className: "modal modal-header", children: _jsx(Flex, { className: "svg-close", onClick: onClose, children: _jsx(Svg, { icon: "close" }) }) }), _jsxs(Flex, { className: "modal-container table-container", children: [_jsxs(Flex, { className: "modal-container title-container", children: [_jsx(Flex, { className: "title-container bondicon", children: _jsxs("div", { className: "icon-container", children: [_jsx(Svg, { width: 20, height: 20, icon: (_a = NETWORK_ICONS === null || NETWORK_ICONS === void 0 ? void 0 : NETWORK_ICONS[bond.chainId]) !== null && _a !== void 0 ? _a : 'question' }), _jsx(TokenImage, { symbol: (_b = bond.showcaseTokenName) !== null && _b !== void 0 ? _b : bond.payoutTokenName, size: 50 })] }) }), _jsx(Flex, { className: "title-container bondname", children: bond === null || bond === void 0 ? void 0 : bond.showcaseTokenName }), _jsxs(Flex, { className: "title-container price-container", children: [_jsxs(Flex, { className: "price-container price", children: ["$", earnTokenPrice(bond)] }), _jsxs(Flex, { className: "price-container discounted", children: ["$", discountEarnTokenPrice(bond)] })] }), _jsx(Flex, { className: "title-container tokentags", children: _jsx(ListTag, { text: (_c = bond === null || bond === void 0 ? void 0 : bond.tags) === null || _c === void 0 ? void 0 : _c[0], variant: ((_d = bond === null || bond === void 0 ? void 0 : bond.tags) === null || _d === void 0 ? void 0 : _d[0]) === 'Cex Fund' ? 'cex_fund' : 'liquidity' }) })] }), _jsx(Flex, { className: "modal-container description-container", children: bond === null || bond === void 0 ? void 0 : bond.shortDescription }), _jsxs(Flex, { className: "modal-container blocks-container", children: [_jsxs(Flex, { className: "modal-block column-discount ".concat(getDiscountColor(bond === null || bond === void 0 ? void 0 : bond.discount)), children: [_jsxs(Flex, { className: "block-header header", children: ["Discount", _jsx(TooltipBubble, { body: _jsx(Flex, { children: TooltipText.Discount }), width: "230px", placement: "bottomLeft", transformTip: "translate(-5%, -5%)", children: _jsx(Flex, { className: "block-header icon", children: _jsx(Svg, { icon: "questionCircle", width: "12px" }) }) })] }), "".concat((_e = bond === null || bond === void 0 ? void 0 : bond.discount) === null || _e === void 0 ? void 0 : _e.toFixed(2), "%")] }), _jsxs(Flex, { className: "modal-block column-arr", children: [_jsxs(Flex, { className: "block-header header", children: ["ARR", _jsx(TooltipBubble, { body: _jsx(Flex, { children: TooltipText.ARR }), width: "230px", placement: "bottomLeft", transformTip: "translate(-5%, -5%)", children: _jsx(Flex, { className: "block-header icon", children: _jsx(Svg, { icon: "questionCircle", width: "12px" }) }) })] }), "".concat(((((_f = bond === null || bond === void 0 ? void 0 : bond.discount) !== null && _f !== void 0 ? _f : 0) * 365) / vestingTime((_g = bond === null || bond === void 0 ? void 0 : bond.vestingTerm) !== null && _g !== void 0 ? _g : 0).days).toFixed(2), "%")] }), _jsxs(Flex, { className: "modal-block column-term", children: [_jsxs(Flex, { className: "block-header header", children: ["Terms", _jsx(TooltipBubble, { body: _jsx(Flex, { children: TooltipText.Terms }), width: "230px", placement: "bottomLeft", transformTip: "translate(-5%, -5%)", children: _jsx(Flex, { className: "block-header icon", children: _jsx(Svg, { icon: "questionCircle", width: "12px" }) }) })] }), vestingTime((_h = bond === null || bond === void 0 ? void 0 : bond.vestingTerm) !== null && _h !== void 0 ? _h : 0).days ? "".concat(vestingTime((_j = bond === null || bond === void 0 ? void 0 : bond.vestingTerm) !== null && _j !== void 0 ? _j : 0).days, " D") : '-'] }), _jsxs(Flex, { className: "modal-block column-maxbuy", children: [_jsxs(Flex, { className: "block-header header", children: ["Max Buy", _jsx(TooltipBubble, { body: _jsx(Flex, { children: TooltipText.MaxBuy(bond.payoutTokenName) }), width: "230px", placement: "bottomLeft", transformTip: "translate(-5%, -5%)", children: _jsx(Flex, { className: "block-header icon", children: _jsx(Svg, { icon: "questionCircle", width: "12px" }) }) })] }), (_k = parseFloat(maxBuy(bond).toFixed(0))) === null || _k === void 0 ? void 0 : _k.toLocaleString('en-US')] })] }), _jsxs(Flex, { className: "modal-container text-container", children: [_jsxs(Flex, { className: "text-container row", children: [_jsx(Flex, { className: "row-container spend", children: "You spend:" }), _jsxs(Flex, { className: "row-container spend-val", children: [youSpend(inputValue), " ", bond.principalTokenName, " = $ ", formatUSDNumber(youSpendUSD(bond, inputValue))] })] }), _jsxs(Flex, { className: "text-container row", children: [_jsxs(Flex, { className: "row-container premium", children: ["Premium:", _jsx(TooltipBubble, { body: _jsx(Flex, { children: TooltipText.Premium }), width: "230px", placement: "bottomLeft", transformTip: "translate(-5%, -5%)", children: _jsx(Flex, { className: "row-container premium-icon", children: _jsx(Svg, { icon: "questionCircle", width: "12px" }) }) })] }), _jsxs(Flex, { className: "row-container premium-val ".concat(getPremiumColor(bond, inputValue)), children: ["$ ", premium(bond, inputValue)] })] }), _jsxs(Flex, { className: "text-container row", children: [_jsxs(Flex, { className: "row-container get", children: ["You get (over ", vestingTime((_l = bond === null || bond === void 0 ? void 0 : bond.vestingTerm) !== null && _l !== void 0 ? _l : 0).days, " days):"] }), _jsxs(Flex, { className: "row-container get-val", children: [youGet(bond, inputValue), " ", bond === null || bond === void 0 ? void 0 : bond.showcaseTokenName, " = $ ", formatUSDNumber(youGetUSD(bond, inputValue))] })] })] }), _jsxs(Flex, { className: "modal-container input-container", children: [_jsxs(Flex, { className: "input-container inputrow", children: [_jsx(Flex, { className: "input-container input", children: _jsx(Input, { placeholder: "0.0", value: inputValue, pattern: "^[0-9]*[.,]?[0-9]*$", onChange: handleInputChange, onInput: function (v) {
|
|
@@ -241,7 +253,7 @@ var BondModal = function (_a) {
|
|
|
241
253
|
!!v.currentTarget.value && isNumber(v.currentTarget.value) && parseFloat(v.currentTarget.value) >= 0
|
|
242
254
|
? v.currentTarget.value
|
|
243
255
|
: v.currentTarget.value.slice(0, v.currentTarget.value.length - 1);
|
|
244
|
-
} }) }), _jsxs(Flex, { className: "input-container token", children: [_jsx(Flex, { className: "input-container bondicon", children: _jsxs("div", { className: "icon-container-small", children: [_jsx(Svg, { width: 12, height: 12, icon: (_m = NETWORK_ICONS === null || NETWORK_ICONS === void 0 ? void 0 : NETWORK_ICONS[bond.chainId]) !== null && _m !== void 0 ? _m : 'question' }), _jsx(TokenImage, { symbol: (_o = bond.principalTokenName) !== null && _o !== void 0 ? _o : bond.payoutTokenName, size: 30 })] }) }), _jsx(Flex, { className: "title-container tokenname-small", children: bond === null || bond === void 0 ? void 0 : bond.principalTokenName })] })] }), isActive && account && (_jsxs(Flex, { className: "input-container balancerow", children: [_jsxs(Flex, { className: "balancerow text", children: ["Balance: ", tokenBalance] }), _jsx(Flex, { className: "balancerow max", children: _jsx(Button, { onClick: function () { setInputValue(tokenBalance !== null && tokenBalance !== void 0 ? tokenBalance : '0'); }, children: "Max" }) })] }))] }), _jsxs(Flex, { className: "modal-container button-container", children: [_jsx(Flex, { className: "button-container get", children: _jsxs(Button, { onClick: function () { window.open('https://ape.bond/swap', '_blank'); }, children: ["Get ", bond === null || bond === void 0 ? void 0 : bond.principalTokenName] }) }), _jsx(Flex, { className: "button-container buy", children: approveTx != null ?
|
|
256
|
+
} }) }), _jsxs(Flex, { className: "input-container token", children: [_jsx(Flex, { className: "input-container bondicon", children: _jsxs("div", { className: "icon-container-small", children: [_jsx(Svg, { width: 12, height: 12, icon: (_m = NETWORK_ICONS === null || NETWORK_ICONS === void 0 ? void 0 : NETWORK_ICONS[bond.chainId]) !== null && _m !== void 0 ? _m : 'question' }), _jsx(TokenImage, { symbol: (_o = bond.principalTokenName) !== null && _o !== void 0 ? _o : bond.payoutTokenName, size: 30 })] }) }), _jsx(Flex, { className: "title-container tokenname-small", children: bond === null || bond === void 0 ? void 0 : bond.principalTokenName })] })] }), isActive && account && (_jsxs(Flex, { className: "input-container balancerow", children: [_jsxs(Flex, { className: "balancerow text", children: ["Balance: ", tokenBalance] }), _jsx(Flex, { className: "balancerow max", children: _jsx(Button, { onClick: function () { setInputValue(tokenBalance !== null && tokenBalance !== void 0 ? tokenBalance : '0'); }, children: "Max" }) })] }))] }), _jsxs(Flex, { className: "modal-container button-container", children: [_jsx(Flex, { className: "button-container get", children: _jsxs(Button, { onClick: function () { window.open('https://ape.bond/swap', '_blank'); }, children: ["Get ", bond === null || bond === void 0 ? void 0 : bond.principalTokenName] }) }), _jsx(Flex, { className: "button-container buy", children: approveTx != null && receiptTx != null ?
|
|
245
257
|
_jsxs(Button, { disabled: isPending, onClick: handleBuy, children: ["Buy ", bond === null || bond === void 0 ? void 0 : bond.showcaseTokenName] })
|
|
246
258
|
:
|
|
247
259
|
_jsx(Button, { disabled: isPending, onClick: handleApprove, children: "Approve" }) })] })] })] }) }) }, bond.billAddress));
|