@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,12 @@
1
+ import { ChainId, Protocols } from "@ape.swap/apeswap-lists";
2
+ declare enum NetworkNames {
3
+ ETHEREUM = "eth",
4
+ BNB = "bnb",
5
+ POLYGON = "pol",
6
+ ARBITRUM = "arb",
7
+ LINEA = "lna",
8
+ BASE = "bas"
9
+ }
10
+ export declare const getChainParam: (chain?: ChainId) => NetworkNames | null;
11
+ export declare const getLpType: (protocol?: Protocols) => "ichi" | "solidly" | "univ2" | null;
12
+ export {};
@@ -0,0 +1,34 @@
1
+ import { ChainId, Protocols } from "@ape.swap/apeswap-lists";
2
+ var NetworkNames;
3
+ (function (NetworkNames) {
4
+ NetworkNames["ETHEREUM"] = "eth";
5
+ NetworkNames["BNB"] = "bnb";
6
+ NetworkNames["POLYGON"] = "pol";
7
+ NetworkNames["ARBITRUM"] = "arb";
8
+ NetworkNames["LINEA"] = "lna";
9
+ NetworkNames["BASE"] = "bas";
10
+ })(NetworkNames || (NetworkNames = {}));
11
+ export var getChainParam = function (chain) {
12
+ return chain === ChainId.LINEA
13
+ ? NetworkNames.LINEA
14
+ : chain === ChainId.MATIC
15
+ ? NetworkNames.POLYGON
16
+ : chain === ChainId.BSC
17
+ ? NetworkNames.BNB
18
+ : chain === ChainId.BASE
19
+ ? NetworkNames.BASE
20
+ : chain === ChainId.ARBITRUM
21
+ ? NetworkNames.ARBITRUM
22
+ : null;
23
+ };
24
+ export var getLpType = function (protocol) {
25
+ return protocol === Protocols.Algebra
26
+ ? 'ichi'
27
+ : protocol === Protocols.Solidly
28
+ ? 'solidly'
29
+ : protocol === Protocols.V2
30
+ ? 'univ2'
31
+ : protocol === Protocols.V3 // This might be a hot fix. Lets revisit this on the future
32
+ ? 'ichi'
33
+ : null;
34
+ };
@@ -0,0 +1,4 @@
1
+ import { Token } from '@ape.swap/apeswap-lists';
2
+ import { BondsDataResponse } from '../../types/bonds';
3
+ declare const useSoulZapBondQuote: (typedValue: string, inputCurrency: "NATIVE" | Token | undefined, bond: BondsDataResponse | undefined, account?: string) => [loading: boolean, response: any, estimateOutput: string];
4
+ export default useSoulZapBondQuote;
@@ -0,0 +1,177 @@
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
+ var __spreadArray = (this && this.__spreadArray) || function (to, from, pack) {
38
+ if (pack || arguments.length === 2) for (var i = 0, l = from.length, ar; i < l; i++) {
39
+ if (ar || !(i in from)) {
40
+ if (!ar) ar = Array.prototype.slice.call(from, 0, i);
41
+ ar[i] = from[i];
42
+ }
43
+ }
44
+ return to.concat(ar || Array.prototype.slice.call(from));
45
+ };
46
+ import { useMemo } from 'react';
47
+ import BigNumber from 'bignumber.js';
48
+ import { dexFactories } from '@ape.swap/apeswap-lists';
49
+ import { getChainParam, getLpType } from './getChainParam';
50
+ import axios from 'axios';
51
+ import { useQuery } from '@tanstack/react-query';
52
+ import { QUERY_KEYS } from '../../config/constants/queryKeys';
53
+ import { zapInputTokens } from '../../config/constants/zapInputTokens';
54
+ import useCurrencyPrice from '../../state/price/useCurrencyPrice';
55
+ var useSoulZapBondQuote = function (typedValue, inputCurrency, bond, account) {
56
+ var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k, _l, _m, _o, _p, _q, _r, _s, _t, _u, _v, _w, _x, _y, _z, _0, _1, _2, _3;
57
+ var allowedSlippage = '0.5';
58
+ var principalToken = bond === null || bond === void 0 ? void 0 : bond.lpToken;
59
+ var bondContractAddress = bond === null || bond === void 0 ? void 0 : bond.billAddress;
60
+ var chainId = bond === null || bond === void 0 ? void 0 : bond.chainId;
61
+ var inputCurrencyString = inputCurrency === 'NATIVE' ? '0x0000000000000000000000000000000000000000' : inputCurrency === null || inputCurrency === void 0 ? void 0 : inputCurrency.address[chainId];
62
+ var inputCurrencyDecimals = inputCurrency === 'NATIVE' ? 18 : inputCurrency === null || inputCurrency === void 0 ? void 0 : inputCurrency.decimals[chainId];
63
+ var principalContractAddress = principalToken === null || principalToken === void 0 ? void 0 : principalToken.address[chainId];
64
+ var chainName = getChainParam(chainId);
65
+ var isReserveBond = (bond === null || bond === void 0 ? void 0 : bond.type) === 'reserve';
66
+ var liquidityDex = (_a = principalToken === null || principalToken === void 0 ? void 0 : principalToken.liquidityDex) === null || _a === void 0 ? void 0 : _a[chainId];
67
+ var protocol = (_c = (_b = dexFactories[chainId]) === null || _b === void 0 ? void 0 : _b[liquidityDex]) === null || _c === void 0 ? void 0 : _c.protocol;
68
+ var lpType = isReserveBond ? 'single' : getLpType(protocol);
69
+ var ichiUnderlyingDex = principalToken === null || principalToken === void 0 ? void 0 : principalToken.ichiUnderlyingDex;
70
+ var vault = (_d = principalToken === null || principalToken === void 0 ? void 0 : principalToken.address) === null || _d === void 0 ? void 0 : _d[chainId];
71
+ var router = (_f = (_e = dexFactories[chainId]) === null || _e === void 0 ? void 0 : _e[liquidityDex]) === null || _f === void 0 ? void 0 : _f.router;
72
+ // Validates that the user did not pass an amount with 19 decimals or more
73
+ var validated18DecimalAmount = new BigNumber(typedValue !== null && typedValue !== void 0 ? typedValue : '0').toFixed(18, 5);
74
+ var bigishInputAmount = new BigNumber(validated18DecimalAmount !== null && validated18DecimalAmount !== void 0 ? validated18DecimalAmount : '0')
75
+ .times(new BigNumber(10).pow(inputCurrencyDecimals !== null && inputCurrencyDecimals !== void 0 ? inputCurrencyDecimals : 18))
76
+ .toString();
77
+ var zapInputData = useMemo(function () {
78
+ if (inputCurrencyString &&
79
+ inputCurrencyDecimals &&
80
+ bigishInputAmount !== 'NaN' &&
81
+ bigishInputAmount !== '0' &&
82
+ principalContractAddress &&
83
+ chainName &&
84
+ bondContractAddress &&
85
+ (inputCurrency === 'NATIVE' || (inputCurrency === null || inputCurrency === void 0 ? void 0 : inputCurrency.address[chainId]) !== principalToken.address[chainId])) {
86
+ return {
87
+ chain: chainName,
88
+ recipient: account !== null && account !== void 0 ? account : '',
89
+ user: account !== null && account !== void 0 ? account : '',
90
+ lpData: {
91
+ lpType: lpType,
92
+ fromToken: inputCurrencyString,
93
+ fromAmount: bigishInputAmount,
94
+ underlyingDex: ichiUnderlyingDex,
95
+ vault: isReserveBond ? undefined : vault,
96
+ slippage: parseFloat(allowedSlippage !== null && allowedSlippage !== void 0 ? allowedSlippage : '0.5'),
97
+ lpAddress: lpType === 'solidly' || lpType === 'univ2' ? vault : undefined,
98
+ router: lpType === 'solidly' || lpType === 'univ2' ? router : undefined,
99
+ toToken: isReserveBond ? vault : undefined,
100
+ },
101
+ protocolData: {
102
+ protocol: 'ApeBond',
103
+ bond: bondContractAddress,
104
+ depositer: account !== null && account !== void 0 ? account : null,
105
+ },
106
+ };
107
+ }
108
+ else {
109
+ return null;
110
+ }
111
+ }, [bigishInputAmount, principalContractAddress, chainName, account, ichiUnderlyingDex, vault, lpType, router]);
112
+ var queryKey = useMemo(function () {
113
+ var _a, _b;
114
+ if (!zapInputData)
115
+ return null;
116
+ return [
117
+ 'zapBondDetails',
118
+ zapInputData.chain,
119
+ zapInputData.user,
120
+ zapInputData.lpData.lpType,
121
+ zapInputData.lpData.fromToken,
122
+ zapInputData.lpData.fromAmount,
123
+ (_a = zapInputData.lpData.underlyingDex) !== null && _a !== void 0 ? _a : '',
124
+ zapInputData.lpData.vault,
125
+ zapInputData.lpData.slippage,
126
+ zapInputData.lpData.lpAddress,
127
+ (_b = zapInputData.lpData.router) !== null && _b !== void 0 ? _b : '',
128
+ ];
129
+ }, [zapInputData]);
130
+ var fetchZapDetails = function () { return __awaiter(void 0, void 0, void 0, function () {
131
+ var response;
132
+ var _a, _b, _c, _d, _e, _f;
133
+ return __generator(this, function (_g) {
134
+ switch (_g.label) {
135
+ case 0:
136
+ console.log('Making Bond Zap call');
137
+ return [4 /*yield*/, axios.post('https://soulsolidity-zap-api-902f1d839e8d.herokuapp.com/zap?batch=1', {
138
+ '0': zapInputData,
139
+ })];
140
+ case 1:
141
+ response = _g.sent();
142
+ console.log((_c = (_b = (_a = response === null || response === void 0 ? void 0 : response.data) === null || _a === void 0 ? void 0 : _a[0]) === null || _b === void 0 ? void 0 : _b.result) === null || _c === void 0 ? void 0 : _c.data);
143
+ return [2 /*return*/, (_f = (_e = (_d = response.data) === null || _d === void 0 ? void 0 : _d[0]) === null || _e === void 0 ? void 0 : _e.result) === null || _f === void 0 ? void 0 : _f.data];
144
+ }
145
+ });
146
+ }); };
147
+ var _4 = useQuery({
148
+ queryKey: [QUERY_KEYS.ZAP_TOKEN_QUOTE, queryKey],
149
+ queryFn: fetchZapDetails,
150
+ enabled: !!queryKey,
151
+ }), response = _4.data, isLoading = _4.isLoading;
152
+ var tokenList = zapInputTokens[chainId] ? zapInputTokens[chainId] : [];
153
+ // toToken0 data
154
+ var toToken0Estimate = (_g = response === null || response === void 0 ? void 0 : response.lpQuote) === null || _g === void 0 ? void 0 : _g.token0.fromAmountEstimate;
155
+ var toToken0 = (_h = __spreadArray(__spreadArray([], tokenList, true), [principalToken], false)) === null || _h === void 0 ? void 0 : _h.find(function (token) { var _a, _b, _c, _d, _e; return ((_b = (_a = token === null || token === void 0 ? void 0 : token.address) === null || _a === void 0 ? void 0 : _a[chainId]) === null || _b === void 0 ? void 0 : _b.toLowerCase()) === ((_e = (_d = (_c = response === null || response === void 0 ? void 0 : response.lpQuote) === null || _c === void 0 ? void 0 : _c.token0) === null || _d === void 0 ? void 0 : _d.address) === null || _e === void 0 ? void 0 : _e.toLowerCase()); });
156
+ var toToken0Price = useCurrencyPrice(toToken0 !== null && toToken0 !== void 0 ? toToken0 : null, chainId).data;
157
+ // toToken1 data
158
+ var toToken1Estimate = (_k = (_j = response === null || response === void 0 ? void 0 : response.lpQuote) === null || _j === void 0 ? void 0 : _j.token1) === null || _k === void 0 ? void 0 : _k.fromAmountEstimate;
159
+ var toToken1 = (_l = zapInputTokens[chainId]) === null || _l === void 0 ? void 0 : _l.find(function (token) { var _a, _b, _c, _d; return ((_a = token.address[chainId]) === null || _a === void 0 ? void 0 : _a.toLowerCase()) === ((_d = (_c = (_b = response === null || response === void 0 ? void 0 : response.lpQuote) === null || _b === void 0 ? void 0 : _b.token1) === null || _c === void 0 ? void 0 : _c.address) === null || _d === void 0 ? void 0 : _d.toLowerCase()); });
160
+ var toToken1Price = useCurrencyPrice(toToken1 !== null && toToken1 !== void 0 ? toToken1 : null, chainId).data;
161
+ var toToken0USD = (_p = (_m = new BigNumber(toToken0Estimate !== null && toToken0Estimate !== void 0 ? toToken0Estimate : '0')) === null || _m === void 0 ? void 0 : _m.div(new BigNumber(10).pow((_o = toToken0 === null || toToken0 === void 0 ? void 0 : toToken0.decimals[chainId]) !== null && _o !== void 0 ? _o : 18)) // this is amount of swap output
162
+ ) === null || _p === void 0 ? void 0 : _p.times(new BigNumber((_q = toToken0Price === null || toToken0Price === void 0 ? void 0 : toToken0Price.price) !== null && _q !== void 0 ? _q : 0)); // convert it to usd price
163
+ if ((_s = (_r = response === null || response === void 0 ? void 0 : response.lpQuote) === null || _r === void 0 ? void 0 : _r.token0) === null || _s === void 0 ? void 0 : _s.fromAmountUSD) {
164
+ toToken0USD = new BigNumber((_u = (_t = response === null || response === void 0 ? void 0 : response.lpQuote) === null || _t === void 0 ? void 0 : _t.token0) === null || _u === void 0 ? void 0 : _u.fromAmountUSD);
165
+ }
166
+ var toToken1USD = (_x = (_v = new BigNumber(toToken1Estimate !== null && toToken1Estimate !== void 0 ? toToken1Estimate : '0')) === null || _v === void 0 ? void 0 : _v.div(new BigNumber(10).pow((_w = toToken1 === null || toToken1 === void 0 ? void 0 : toToken1.decimals[chainId]) !== null && _w !== void 0 ? _w : 18)) // this is amount of swap output
167
+ ) === null || _x === void 0 ? void 0 : _x.times(new BigNumber((_y = toToken1Price === null || toToken1Price === void 0 ? void 0 : toToken1Price.price) !== null && _y !== void 0 ? _y : 0)); // convert it to usd price
168
+ if ((_0 = (_z = response === null || response === void 0 ? void 0 : response.lpQuote) === null || _z === void 0 ? void 0 : _z.token0) === null || _0 === void 0 ? void 0 : _0.fromAmountUSD) {
169
+ toToken1USD = new BigNumber((_2 = (_1 = response === null || response === void 0 ? void 0 : response.lpQuote) === null || _1 === void 0 ? void 0 : _1.token1) === null || _2 === void 0 ? void 0 : _2.fromAmountUSD);
170
+ }
171
+ var totalUSDAmount = toToken0USD.plus(toToken1USD);
172
+ var ouputTokenPrice = useCurrencyPrice(principalToken !== null && principalToken !== void 0 ? principalToken : null, chainId).data;
173
+ var lpAmount = totalUSDAmount.div((_3 = ouputTokenPrice === null || ouputTokenPrice === void 0 ? void 0 : ouputTokenPrice.price) !== null && _3 !== void 0 ? _3 : 0); // then we divide the lp USD price to get the amount of LP tokens
174
+ var estimateOutput = lpAmount.toFixed(18);
175
+ return [isLoading, response, estimateOutput];
176
+ };
177
+ export default useSoulZapBondQuote;
@@ -0,0 +1,3 @@
1
+ import { ChainId, Token } from '@ape.swap/apeswap-lists';
2
+ declare const useSoulZapTokenQuote: (typedValue: string, inputCurrency: "NATIVE" | Token | undefined, outputToken: Token | undefined, chainId: ChainId, account?: string) => [loading: boolean, response: any, estimateOutput: string];
3
+ export default useSoulZapTokenQuote;
@@ -0,0 +1,167 @@
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
+ var __spreadArray = (this && this.__spreadArray) || function (to, from, pack) {
38
+ if (pack || arguments.length === 2) for (var i = 0, l = from.length, ar; i < l; i++) {
39
+ if (ar || !(i in from)) {
40
+ if (!ar) ar = Array.prototype.slice.call(from, 0, i);
41
+ ar[i] = from[i];
42
+ }
43
+ }
44
+ return to.concat(ar || Array.prototype.slice.call(from));
45
+ };
46
+ import { useMemo } from 'react';
47
+ import BigNumber from 'bignumber.js';
48
+ import { dexFactories } from '@ape.swap/apeswap-lists';
49
+ import { getChainParam, getLpType } from './getChainParam';
50
+ import axios from 'axios';
51
+ import { useQuery } from '@tanstack/react-query';
52
+ import { QUERY_KEYS } from '../../config/constants/queryKeys';
53
+ import { zapInputTokens } from '../../config/constants/zapInputTokens';
54
+ import useCurrencyPrice from '../../state/price/useCurrencyPrice';
55
+ var useSoulZapTokenQuote = function (typedValue, inputCurrency, outputToken, chainId, account) {
56
+ var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k, _l, _m, _o, _p, _q, _r, _s, _t, _u, _v, _w, _x, _y, _z, _0, _1, _2, _3, _4;
57
+ var allowedSlippage = '0.5';
58
+ var inputCurrencyString = inputCurrency === 'NATIVE' ? '0x0000000000000000000000000000000000000000' : inputCurrency === null || inputCurrency === void 0 ? void 0 : inputCurrency.address[chainId];
59
+ var inputCurrencyDecimals = inputCurrency === 'NATIVE' ? 18 : inputCurrency === null || inputCurrency === void 0 ? void 0 : inputCurrency.decimals[chainId];
60
+ var contractAddress = outputToken === null || outputToken === void 0 ? void 0 : outputToken.address[chainId];
61
+ var chain = getChainParam(chainId);
62
+ var isLP = (_a = outputToken === null || outputToken === void 0 ? void 0 : outputToken.lpToken) !== null && _a !== void 0 ? _a : false;
63
+ var liquidityDex = (_b = outputToken === null || outputToken === void 0 ? void 0 : outputToken.liquidityDex) === null || _b === void 0 ? void 0 : _b[chainId];
64
+ var protocol = (_d = (_c = dexFactories[chainId]) === null || _c === void 0 ? void 0 : _c[liquidityDex]) === null || _d === void 0 ? void 0 : _d.protocol;
65
+ var lpType = (outputToken === null || outputToken === void 0 ? void 0 : outputToken.lpToken) ? getLpType(protocol) : 'single';
66
+ var ichiUnderlyingDex = outputToken === null || outputToken === void 0 ? void 0 : outputToken.ichiUnderlyingDex;
67
+ var vault = (_e = outputToken === null || outputToken === void 0 ? void 0 : outputToken.address) === null || _e === void 0 ? void 0 : _e[chainId];
68
+ var router = (_g = (_f = dexFactories[chainId]) === null || _f === void 0 ? void 0 : _f[liquidityDex]) === null || _g === void 0 ? void 0 : _g.router;
69
+ // Validates that the user did not pass an amount with 19 decimals or more
70
+ var validated18DecimalAmount = new BigNumber(typedValue !== null && typedValue !== void 0 ? typedValue : '0').toFixed(18, 5);
71
+ var bigishInputAmount = new BigNumber(validated18DecimalAmount !== null && validated18DecimalAmount !== void 0 ? validated18DecimalAmount : '0')
72
+ .times(new BigNumber(10).pow(inputCurrencyDecimals !== null && inputCurrencyDecimals !== void 0 ? inputCurrencyDecimals : 18))
73
+ .toString();
74
+ var zapInputData = useMemo(function () {
75
+ if (inputCurrencyString &&
76
+ inputCurrencyDecimals &&
77
+ bigishInputAmount !== 'NaN' &&
78
+ bigishInputAmount !== '0' &&
79
+ contractAddress &&
80
+ chain) {
81
+ return {
82
+ chain: chain,
83
+ recipient: account !== null && account !== void 0 ? account : '',
84
+ user: account !== null && account !== void 0 ? account : '',
85
+ lpData: {
86
+ lpType: lpType,
87
+ fromToken: inputCurrencyString,
88
+ fromAmount: bigishInputAmount,
89
+ underlyingDex: ichiUnderlyingDex,
90
+ vault: isLP ? vault : undefined,
91
+ slippage: parseFloat(allowedSlippage !== null && allowedSlippage !== void 0 ? allowedSlippage : '0.5'),
92
+ lpAddress: lpType === 'solidly' || lpType === 'univ2' ? vault : undefined,
93
+ router: lpType === 'solidly' || lpType === 'univ2' ? router : undefined,
94
+ toToken: isLP ? undefined : vault,
95
+ },
96
+ };
97
+ }
98
+ else {
99
+ return null;
100
+ }
101
+ }, [bigishInputAmount, contractAddress, chain, account, ichiUnderlyingDex, vault, lpType, router]);
102
+ var queryKey = useMemo(function () {
103
+ var _a, _b;
104
+ if (!zapInputData)
105
+ return null;
106
+ return [
107
+ 'zapTokenDetails',
108
+ zapInputData.chain,
109
+ zapInputData.user,
110
+ zapInputData.lpData.lpType,
111
+ zapInputData.lpData.fromToken,
112
+ zapInputData.lpData.fromAmount,
113
+ (_a = zapInputData.lpData.underlyingDex) !== null && _a !== void 0 ? _a : '',
114
+ zapInputData.lpData.vault,
115
+ zapInputData.lpData.slippage,
116
+ zapInputData.lpData.lpAddress,
117
+ (_b = zapInputData.lpData.router) !== null && _b !== void 0 ? _b : '',
118
+ ];
119
+ }, [zapInputData]);
120
+ var fetchZapDetails = function () { return __awaiter(void 0, void 0, void 0, function () {
121
+ var response;
122
+ var _a, _b, _c;
123
+ return __generator(this, function (_d) {
124
+ switch (_d.label) {
125
+ case 0:
126
+ console.log('Making SoulZap Token Call');
127
+ return [4 /*yield*/, axios.post('https://soulsolidity-zap-api-902f1d839e8d.herokuapp.com/zap?batch=1', {
128
+ '0': zapInputData,
129
+ })];
130
+ case 1:
131
+ response = _d.sent();
132
+ return [2 /*return*/, (_c = (_b = (_a = response.data) === null || _a === void 0 ? void 0 : _a[0]) === null || _b === void 0 ? void 0 : _b.result) === null || _c === void 0 ? void 0 : _c.data];
133
+ }
134
+ });
135
+ }); };
136
+ var _5 = useQuery({
137
+ queryKey: [QUERY_KEYS.ZAP_TOKEN_QUOTE, queryKey],
138
+ queryFn: fetchZapDetails,
139
+ enabled: !!queryKey,
140
+ }), response = _5.data, isLoading = _5.isLoading;
141
+ var tokenList = zapInputTokens[chainId] ? zapInputTokens[chainId] : [];
142
+ // toToken0 data
143
+ var toToken0Estimate = (_h = response === null || response === void 0 ? void 0 : response.lpQuote) === null || _h === void 0 ? void 0 : _h.token0.fromAmountEstimate;
144
+ var toToken0 = (_j = __spreadArray(__spreadArray([], tokenList, true), [outputToken], false)) === null || _j === void 0 ? void 0 : _j.find(function (token) { var _a, _b, _c, _d, _e; return ((_b = (_a = token === null || token === void 0 ? void 0 : token.address) === null || _a === void 0 ? void 0 : _a[chainId]) === null || _b === void 0 ? void 0 : _b.toLowerCase()) === ((_e = (_d = (_c = response === null || response === void 0 ? void 0 : response.lpQuote) === null || _c === void 0 ? void 0 : _c.token0) === null || _d === void 0 ? void 0 : _d.address) === null || _e === void 0 ? void 0 : _e.toLowerCase()); });
145
+ var toToken0Price = useCurrencyPrice(toToken0 !== null && toToken0 !== void 0 ? toToken0 : null, chainId).data;
146
+ // toToken1 data
147
+ var toToken1Estimate = (_l = (_k = response === null || response === void 0 ? void 0 : response.lpQuote) === null || _k === void 0 ? void 0 : _k.token1) === null || _l === void 0 ? void 0 : _l.fromAmountEstimate;
148
+ var toToken1 = (_m = zapInputTokens[chainId]) === null || _m === void 0 ? void 0 : _m.find(function (token) { var _a, _b, _c, _d; return ((_a = token.address[chainId]) === null || _a === void 0 ? void 0 : _a.toLowerCase()) === ((_d = (_c = (_b = response === null || response === void 0 ? void 0 : response.lpQuote) === null || _b === void 0 ? void 0 : _b.token1) === null || _c === void 0 ? void 0 : _c.address) === null || _d === void 0 ? void 0 : _d.toLowerCase()); });
149
+ var toToken1Price = useCurrencyPrice(toToken1 !== null && toToken1 !== void 0 ? toToken1 : null, chainId).data;
150
+ var toToken0USD = (_q = (_o = new BigNumber(toToken0Estimate !== null && toToken0Estimate !== void 0 ? toToken0Estimate : '0')) === null || _o === void 0 ? void 0 : _o.div(new BigNumber(10).pow((_p = toToken0 === null || toToken0 === void 0 ? void 0 : toToken0.decimals[chainId]) !== null && _p !== void 0 ? _p : 18)) // this is amount of swap output
151
+ ) === null || _q === void 0 ? void 0 : _q.times(new BigNumber((_r = toToken0Price === null || toToken0Price === void 0 ? void 0 : toToken0Price.price) !== null && _r !== void 0 ? _r : 0)); // convert it to usd price
152
+ if ((_t = (_s = response === null || response === void 0 ? void 0 : response.lpQuote) === null || _s === void 0 ? void 0 : _s.token0) === null || _t === void 0 ? void 0 : _t.fromAmountUSD) {
153
+ toToken0USD = new BigNumber((_v = (_u = response === null || response === void 0 ? void 0 : response.lpQuote) === null || _u === void 0 ? void 0 : _u.token0) === null || _v === void 0 ? void 0 : _v.fromAmountUSD);
154
+ }
155
+ var toToken1USD = (_y = (_w = new BigNumber(toToken1Estimate !== null && toToken1Estimate !== void 0 ? toToken1Estimate : '0')) === null || _w === void 0 ? void 0 : _w.div(new BigNumber(10).pow((_x = toToken1 === null || toToken1 === void 0 ? void 0 : toToken1.decimals[chainId]) !== null && _x !== void 0 ? _x : 18)) // this is amount of swap output
156
+ ) === null || _y === void 0 ? void 0 : _y.times(new BigNumber((_z = toToken1Price === null || toToken1Price === void 0 ? void 0 : toToken1Price.price) !== null && _z !== void 0 ? _z : 0)); // convert it to usd price
157
+ if ((_1 = (_0 = response === null || response === void 0 ? void 0 : response.lpQuote) === null || _0 === void 0 ? void 0 : _0.token1) === null || _1 === void 0 ? void 0 : _1.fromAmountUSD) {
158
+ toToken1USD = new BigNumber((_3 = (_2 = response === null || response === void 0 ? void 0 : response.lpQuote) === null || _2 === void 0 ? void 0 : _2.token1) === null || _3 === void 0 ? void 0 : _3.fromAmountUSD);
159
+ }
160
+ var totalUSDAmount = toToken0USD.plus(toToken1USD);
161
+ var ouputTokenPrice = useCurrencyPrice(outputToken !== null && outputToken !== void 0 ? outputToken : null, chainId).data;
162
+ var outputTokenPrice = new BigNumber((_4 = ouputTokenPrice === null || ouputTokenPrice === void 0 ? void 0 : ouputTokenPrice.price) !== null && _4 !== void 0 ? _4 : 1);
163
+ var lpAmount = totalUSDAmount.div(outputTokenPrice); // then we divide the lp USD price to get the amount of LP tokens
164
+ var estimateOutput = lpAmount.toFixed(18);
165
+ return [isLoading, response, estimateOutput];
166
+ };
167
+ export default useSoulZapTokenQuote;
@@ -0,0 +1,3 @@
1
+ import { ChainId } from "@ape.swap/apeswap-lists";
2
+ declare const getNativeTicker: (chain?: ChainId) => string | undefined;
3
+ export default getNativeTicker;
@@ -0,0 +1,8 @@
1
+ import { WNATIVE } from "../config/constants/tokens";
2
+ var getNativeTicker = function (chain) {
3
+ var _a;
4
+ if (!chain)
5
+ return undefined;
6
+ return (_a = WNATIVE[chain]) === null || _a === void 0 ? void 0 : _a.symbol.substring(1);
7
+ };
8
+ export default getNativeTicker;
@@ -310,9 +310,9 @@ var BondModal = function (_a) {
310
310
  toNumber(inputValue) / toNumber(earnTokenPrice(bond))).toFixed(2), _jsx("span", { className: "text-highlight", children: "\u00A0additional" })] }), _jsx(Flex, { className: "button-container buy", sx: { justifyContent: 'end' }, children: chainId !== bond.chainId ? (_jsx(Button, { className: "switch-button button-narrow", disabled: isPending || isConfirming || (bond === null || bond === void 0 ? void 0 : bond.soldOut) || !account, onClick: function (event) {
311
311
  event.stopPropagation();
312
312
  switchChain({ chainId: bond.chainId });
313
- }, children: !account ? 'Connect Wallet' : "Switch to ".concat(NETWORK_LABEL[bond.chainId]) })) : approveTx != null && isConfirmed ? (_jsx(Button, { className: "action-button button-narrow", disabled: isPending || isConfirming || (bond === null || bond === void 0 ? void 0 : bond.soldOut) || !account, onClick: handleBuy, children: getActionButtonText(bond) })) : (_jsx(Button, { className: "action-button button-narrow", disabled: isPending || isConfirming || (bond === null || bond === void 0 ? void 0 : bond.soldOut) || !account, onClick: handleApprove, children: getActionButtonText(bond) })) })] }), _jsx(Flex, { sx: { width: '100%', marginTop: '10px', marginBottom: '10px' }, children: _jsx("hr", { className: "fading-hr" }) }), _jsxs(Flex, { sx: { width: '100%' }, children: [_jsxs(Flex, { sx: { width: '50%', flexDirection: 'column' }, children: ["Market Price: $", formatUSDNumber((toNumber(youGet(bond, inputValue)) * toNumber(earnTokenPrice(bond))).toString()), _jsx("hr", { className: "fading-hr" }), _jsx("span", { className: "text-highlight flex-inline", children: "Our price: " }), _jsxs("span", { className: "flex-inline", children: ["$", formatUSDNumber((toNumber(inputValue) * toNumber(bond.principalTokenPrice)).toString()), ' '] }), _jsxs("span", { className: "text-highlight flex-inline", children: ["(discount rate ", bond === null || bond === void 0 ? void 0 : bond.discount.toFixed(2), "%)"] })] }), _jsx(Flex, { sx: { width: '50px', alignItems: 'center', justifyContent: 'center' }, children: "vs." }), _jsxs(Flex, { sx: { width: '50%', flexDirection: 'column' }, children: ["If purchased from market: ", (toNumber(inputValue) / toNumber(earnTokenPrice(bond))).toFixed(0), ' ', bond.earnToken.symbol, _jsx("hr", { className: "fading-hr" }), _jsx("span", { className: "text-highlight flex-inline", children: "Amount you will get:" }), ' ', inputValue ? toNumber(youGet(bond, inputValue)).toFixed(2) : 0, ' ', _jsx("span", { className: "flex-inline", children: bond.earnToken.symbol })] })] })] })] })] }), _jsxs(Flex, { className: "footer-details", children: [_jsxs(Flex, { sx: { width: '25%', justifyContent: 'center' }, children: [_jsx("strong", { children: "Vesting start date:" }), "\u00A0", moment().format('DD-MMM-YYYY')] }), _jsxs(Flex, { sx: { width: '25%', justifyContent: 'center' }, children: [_jsx("strong", { children: "Vesting end date:" }), "\u00A0", moment()
313
+ }, children: !account ? 'Connect Wallet' : "Switch to ".concat(NETWORK_LABEL[bond.chainId]) })) : approveTx != null && isConfirmed ? (_jsx(Button, { className: "action-button button-narrow", disabled: isPending || isConfirming || (bond === null || bond === void 0 ? void 0 : bond.soldOut) || !account, onClick: handleBuy, children: getActionButtonText(bond) })) : (_jsx(Button, { className: "action-button button-narrow", disabled: isPending || isConfirming || (bond === null || bond === void 0 ? void 0 : bond.soldOut) || !account, onClick: handleApprove, children: getActionButtonText(bond) })) })] }), _jsx(Flex, { sx: { width: '100%', marginTop: '10px', marginBottom: '10px' }, children: _jsx("hr", { className: "fading-hr" }) }), _jsxs(Flex, { sx: { width: '100%' }, children: [_jsxs(Flex, { sx: { width: '50%', flexDirection: 'column' }, children: ["Market Price: $", formatUSDNumber((toNumber(youGet(bond, inputValue)) * toNumber(earnTokenPrice(bond))).toString()), _jsx("hr", { className: "fading-hr" }), _jsx("span", { className: "text-highlight flex-inline", children: "Our price: " }), _jsxs("span", { className: "flex-inline", children: ["$", formatUSDNumber((toNumber(inputValue) * toNumber(bond.principalTokenPrice)).toString()), ' '] }), _jsxs("span", { className: "text-highlight flex-inline", children: ["(discount rate ", bond === null || bond === void 0 ? void 0 : bond.discount.toFixed(2), "%)"] })] }), _jsx(Flex, { sx: { width: '50px', alignItems: 'center', justifyContent: 'center' }, children: "vs." }), _jsxs(Flex, { sx: { width: '50%', flexDirection: 'column' }, children: ["If purchased from market: ", (toNumber(inputValue) / toNumber(earnTokenPrice(bond))).toFixed(0), ' ', bond.earnToken.symbol, _jsx("hr", { className: "fading-hr" }), _jsx("span", { className: "text-highlight flex-inline", children: "Amount you will get:" }), ' ', toNumber(youGet(bond, inputValue)).toFixed(0), " ", _jsx("span", { className: "flex-inline", children: bond.earnToken.symbol })] })] })] })] })] }), _jsxs(Flex, { className: "footer-details", children: [_jsxs(Flex, { sx: { width: '25%', justifyContent: 'center' }, children: ["Vesting start date: ", moment().format('DD-MMM-YYYY')] }), _jsxs(Flex, { sx: { width: '25%', justifyContent: 'center' }, children: ["Vesting end date:", ' ', moment()
314
314
  .add(vestingTime((_u = bond === null || bond === void 0 ? void 0 : bond.vestingTerm) !== null && _u !== void 0 ? _u : 0).days, 'days')
315
- .format('DD-MMM-YYYY')] }), _jsxs(Flex, { sx: { width: '25%', justifyContent: 'center' }, children: [_jsx("strong", { children: "Vesting type:" }), "\u00A0Linear"] }), _jsxs(Flex, { sx: { width: '25%', justifyContent: 'center' }, className: "text-highlight", children: ["What are bonds?", _jsx("i", { className: "fa-solid fa-angle-down" })] })] }), accordionVisible && (_jsx(Flex, { className: "modaltable-container accordion-container", children: _jsx(AccordionText, { title: accordionTitle, body: accordionBody, isVisible: accordionVisible }) }))] }) })) }, bond.billAddress));
315
+ .format('DD-MMM-YYYY')] }), _jsx(Flex, { sx: { width: '25%', justifyContent: 'center' }, children: "Vesting type: Linear" }), _jsx(Flex, { sx: { width: '25%', justifyContent: 'center' }, children: "What are bonds?" })] }), accordionVisible && (_jsx(Flex, { className: "modaltable-container accordion-container", children: _jsx(AccordionText, { title: accordionTitle, body: accordionBody, isVisible: accordionVisible }) }))] }) })) }, bond.billAddress));
316
316
  }) }));
317
317
  };
318
318
  export default BondModal;
@@ -6,7 +6,7 @@ declare global {
6
6
  ethereum?: any;
7
7
  }
8
8
  }
9
- interface BondsProps {
9
+ export interface BondsProps {
10
10
  account: string;
11
11
  accountChainId: number;
12
12
  isActive: boolean;
@@ -0,0 +1,4 @@
1
+ import React from "react";
2
+ import { BondsProps } from "./Bonds";
3
+ declare const BondsWithProviders: React.FC<BondsProps>;
4
+ export default BondsWithProviders;
@@ -0,0 +1,18 @@
1
+ var __assign = (this && this.__assign) || function () {
2
+ __assign = Object.assign || function(t) {
3
+ for (var s, i = 1, n = arguments.length; i < n; i++) {
4
+ s = arguments[i];
5
+ for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p))
6
+ t[p] = s[p];
7
+ }
8
+ return t;
9
+ };
10
+ return __assign.apply(this, arguments);
11
+ };
12
+ import { jsx as _jsx } from "theme-ui/jsx-runtime";
13
+ import Providers from "../../providers";
14
+ import Bonds from "./Bonds";
15
+ var BondsWithProviders = function (props) {
16
+ return (_jsx(Providers, { children: _jsx(Bonds, __assign({}, props)) }));
17
+ };
18
+ export default BondsWithProviders;
@@ -0,0 +1,14 @@
1
+ import React from 'react';
2
+ import { ChainId, Token } from '@ape.swap/apeswap-lists';
3
+ /**
4
+ * This Modal should be opened within a Providers Context
5
+ * @param chainId this is the chainId of the outputToken
6
+ */
7
+ interface ZapModalProps {
8
+ onDismiss?: () => void;
9
+ outputToken: Token;
10
+ chainId: ChainId;
11
+ account?: string;
12
+ }
13
+ declare const ZapModal: ({ onDismiss, outputToken, account, chainId }: ZapModalProps) => React.JSX.Element;
14
+ export default ZapModal;