@ape.swap/bonds-sdk 1.0.603 → 1.0.604
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,16 @@ 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
|
-
var
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
64
|
+
var transactionReceipt = function (txHash) { return __awaiter(void 0, void 0, void 0, function () {
|
|
65
|
+
return __generator(this, function (_a) {
|
|
66
|
+
return [2 /*return*/, useWaitForTransactionReceipt({
|
|
67
|
+
confirmations: 4,
|
|
68
|
+
hash: txHash,
|
|
69
|
+
pollingInterval: 1000
|
|
70
|
+
})];
|
|
71
|
+
});
|
|
72
|
+
}); };
|
|
73
|
+
var _c = useState([]), bondData = _c[0], setBondData = _c[1];
|
|
68
74
|
//This is a temp solution, but we will force approval each time, and then once set we will set status here and allow
|
|
69
75
|
//user to buy
|
|
70
76
|
//Check with Fede if this needs to be temp, if we force approval everytime, isn't this fine?
|
|
@@ -107,10 +113,10 @@ var BondModal = function (_a) {
|
|
|
107
113
|
}
|
|
108
114
|
});
|
|
109
115
|
}); };
|
|
110
|
-
var
|
|
116
|
+
var _d = useState(null), buyTx = _d[0], setBuyTx = _d[1];
|
|
111
117
|
//You approve the token, not the contract (this code will have to be updated for zap)
|
|
112
118
|
var handleApprove = function () { return __awaiter(void 0, void 0, void 0, function () {
|
|
113
|
-
var tokenAddress, decimals, amount, tx, error_2;
|
|
119
|
+
var tokenAddress, decimals, amount, tx, receipt, error_2;
|
|
114
120
|
return __generator(this, function (_a) {
|
|
115
121
|
switch (_a.label) {
|
|
116
122
|
case 0:
|
|
@@ -118,7 +124,7 @@ var BondModal = function (_a) {
|
|
|
118
124
|
decimals = tokenDecimals !== null && tokenDecimals !== void 0 ? tokenDecimals : 18;
|
|
119
125
|
_a.label = 1;
|
|
120
126
|
case 1:
|
|
121
|
-
_a.trys.push([1,
|
|
127
|
+
_a.trys.push([1, 4, , 5]);
|
|
122
128
|
amount = convertToTokenValue(inputValue, decimals);
|
|
123
129
|
console.log('Amount:', amount);
|
|
124
130
|
return [4 /*yield*/, writeContractAsync({
|
|
@@ -129,60 +135,31 @@ var BondModal = function (_a) {
|
|
|
129
135
|
})];
|
|
130
136
|
case 2:
|
|
131
137
|
tx = _a.sent();
|
|
132
|
-
|
|
138
|
+
return [4 /*yield*/, transactionReceipt(tx)];
|
|
139
|
+
case 3:
|
|
140
|
+
receipt = _a.sent();
|
|
141
|
+
if (receipt.isSuccess) {
|
|
142
|
+
setReceiptTx(receipt.data.transactionHash);
|
|
143
|
+
console.log('Receipt:', receipt);
|
|
144
|
+
}
|
|
133
145
|
if (tx) {
|
|
134
146
|
setApproveTx(tx);
|
|
135
147
|
console.log('setApproveTx:', tx);
|
|
136
148
|
}
|
|
137
|
-
return [3 /*break*/,
|
|
138
|
-
case
|
|
149
|
+
return [3 /*break*/, 5];
|
|
150
|
+
case 4:
|
|
139
151
|
error_2 = _a.sent();
|
|
140
152
|
console.error('Approval failed:', error_2);
|
|
141
153
|
alert('Approval Failed');
|
|
142
|
-
return [3 /*break*/,
|
|
143
|
-
case
|
|
154
|
+
return [3 /*break*/, 5];
|
|
155
|
+
case 5: return [2 /*return*/];
|
|
144
156
|
}
|
|
145
157
|
});
|
|
146
158
|
}); };
|
|
159
|
+
var _e = useState(null), receiptTx = _e[0], setReceiptTx = _e[1];
|
|
147
160
|
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];
|
|
161
|
+
var _g = useState(null), tokenBalance = _g[0], setTokenBalance = _g[1];
|
|
162
|
+
var _h = useState(null), tokenDecimals = _h[0], setTokenDecimals = _h[1];
|
|
186
163
|
useEffect(function () {
|
|
187
164
|
if (isActive && account && bondData.length > 0) {
|
|
188
165
|
getTokenBalance(bondData[0].chainId, bondData[0].principalToken, account).then(function (_a) {
|
|
@@ -209,8 +186,6 @@ var BondModal = function (_a) {
|
|
|
209
186
|
return [4 /*yield*/, contract.decimals()];
|
|
210
187
|
case 1:
|
|
211
188
|
decimals = _a.sent();
|
|
212
|
-
console.log('Decimals:', decimals);
|
|
213
|
-
console.log(decimals);
|
|
214
189
|
return [4 /*yield*/, contract.balanceOf(walletAddress)];
|
|
215
190
|
case 2:
|
|
216
191
|
balance = _a.sent();
|
|
@@ -220,11 +195,47 @@ var BondModal = function (_a) {
|
|
|
220
195
|
case 3:
|
|
221
196
|
error_3 = _a.sent();
|
|
222
197
|
console.error('Error fetching token balance', error_3);
|
|
223
|
-
return [2 /*return*/, { balanceInEther: '0', decimals: 0 }];
|
|
198
|
+
return [2 /*return*/, { balanceInEther: '0', decimals: 0 }];
|
|
224
199
|
case 4: return [2 /*return*/];
|
|
225
200
|
}
|
|
226
201
|
});
|
|
227
202
|
}); };
|
|
203
|
+
// Fetch data
|
|
204
|
+
useEffect(function () {
|
|
205
|
+
axios.get('https://realtime-api.ape.bond/bonds').then(function (response) {
|
|
206
|
+
var bond = response.data.bonds.filter(function (x) {
|
|
207
|
+
return x.billAddress.toLowerCase() === (bondAddress === null || bondAddress === void 0 ? void 0 : bondAddress.toLowerCase());
|
|
208
|
+
});
|
|
209
|
+
setBondData(bond);
|
|
210
|
+
});
|
|
211
|
+
}, [bondAddress]);
|
|
212
|
+
// Functions for calculations
|
|
213
|
+
var getDiscountColor = function (discount) {
|
|
214
|
+
return discount < 0 ? 'discount-negative' : 'discount-positive';
|
|
215
|
+
};
|
|
216
|
+
var discountEarnTokenPrice = function (bond) {
|
|
217
|
+
var _a, _b;
|
|
218
|
+
var earnTokenPrice = parseFloat((_a = bond === null || bond === void 0 ? void 0 : bond.payoutTokenPrice) !== null && _a !== void 0 ? _a : '0');
|
|
219
|
+
return getFirstNonZeroDigits(earnTokenPrice - earnTokenPrice * (((_b = bond === null || bond === void 0 ? void 0 : bond.discount) !== null && _b !== void 0 ? _b : 0) / 100));
|
|
220
|
+
};
|
|
221
|
+
var earnTokenPrice = function (bond) {
|
|
222
|
+
var _a;
|
|
223
|
+
return getFirstNonZeroDigits(parseFloat((_a = bond === null || bond === void 0 ? void 0 : bond.payoutTokenPrice) !== null && _a !== void 0 ? _a : '0'));
|
|
224
|
+
};
|
|
225
|
+
var vestingTime = function (vestingTerm) { return getTimePeriods(vestingTerm !== null && vestingTerm !== void 0 ? vestingTerm : 0, true); };
|
|
226
|
+
var maxBuy = function (bond) {
|
|
227
|
+
var _a, _b, _c, _d;
|
|
228
|
+
var available = new BigNumber((_a = bond === null || bond === void 0 ? void 0 : bond.tokensRemaining) !== null && _a !== void 0 ? _a : '0');
|
|
229
|
+
var threshold = 5;
|
|
230
|
+
var thresholdToShow = new BigNumber(threshold).div((_b = bond === null || bond === void 0 ? void 0 : bond.payoutTokenPrice) !== null && _b !== void 0 ? _b : 0);
|
|
231
|
+
var safeAvailable = available.minus(thresholdToShow);
|
|
232
|
+
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));
|
|
233
|
+
return !available ? 0 : (singlePurchaseLimit.lt(safeAvailable) ? singlePurchaseLimit : safeAvailable);
|
|
234
|
+
};
|
|
235
|
+
var _j = useState(''), inputValue = _j[0], setInputValue = _j[1];
|
|
236
|
+
var handleInputChange = function (event) {
|
|
237
|
+
setInputValue(event.target.value);
|
|
238
|
+
};
|
|
228
239
|
return (_jsx(ThemeUIProvider, { theme: defaultTheme, children: bondData.map(function (bond) {
|
|
229
240
|
var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k, _l, _m, _o;
|
|
230
241
|
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 +252,7 @@ var BondModal = function (_a) {
|
|
|
241
252
|
!!v.currentTarget.value && isNumber(v.currentTarget.value) && parseFloat(v.currentTarget.value) >= 0
|
|
242
253
|
? v.currentTarget.value
|
|
243
254
|
: 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 ?
|
|
255
|
+
} }) }), _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
256
|
_jsxs(Button, { disabled: isPending, onClick: handleBuy, children: ["Buy ", bond === null || bond === void 0 ? void 0 : bond.showcaseTokenName] })
|
|
246
257
|
:
|
|
247
258
|
_jsx(Button, { disabled: isPending, onClick: handleApprove, children: "Approve" }) })] })] })] }) }) }, bond.billAddress));
|