@ape.swap/bonds-sdk 1.0.358 → 1.0.360

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.
@@ -1,61 +0,0 @@
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;
12
- return g = { next: verb(0), "throw": verb(1), "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 billsABI from '../../config/abi/bond.json';
38
- import { chunk } from 'lodash';
39
- import fetchBillsCalls from './fetchBillsCalls';
40
- import cleanBillsData from './cleanBillsData';
41
- import multicall from '../../utils/multicall';
42
- var fetchBills = function (chainId, tokenPrices, bills) { return __awaiter(void 0, void 0, void 0, function () {
43
- var billIds, billCalls, vals, chunkSize, chunkedBills;
44
- return __generator(this, function (_a) {
45
- switch (_a.label) {
46
- case 0:
47
- billIds = [];
48
- billCalls = bills.flatMap(function (bill) {
49
- billIds.push(bill.index);
50
- return fetchBillsCalls(bill);
51
- });
52
- return [4 /*yield*/, multicall(chainId, billsABI, billCalls)];
53
- case 1:
54
- vals = _a.sent();
55
- chunkSize = (vals === null || vals === void 0 ? void 0 : vals.length) / (bills === null || bills === void 0 ? void 0 : bills.length);
56
- chunkedBills = chunk(vals, chunkSize);
57
- return [2 /*return*/, cleanBillsData(billIds, chunkedBills, tokenPrices, chainId, bills)];
58
- }
59
- });
60
- }); };
61
- export default fetchBills;
@@ -1,4 +0,0 @@
1
- import { Call } from '../../utils/multicall';
2
- import { CleanedBondsState } from '../../types/bonds';
3
- declare const fetchBillsCalls: (bill: CleanedBondsState) => Call[];
4
- export default fetchBillsCalls;
@@ -1,27 +0,0 @@
1
- import { BillVersion } from '../../enum/apeswaplists';
2
- var fetchBillsCalls = function (bill) {
3
- var standardCalls = [
4
- // Get bill price with LP fees
5
- {
6
- address: bill.contractAddress,
7
- name: 'trueBillPrice',
8
- },
9
- // Get bill debt ratio
10
- {
11
- address: bill.contractAddress,
12
- name: 'totalPayoutGiven',
13
- },
14
- // Terms
15
- // (1) controlVariable (2) vestingTerm (3) minimumPrice (4) maxPayout (5) maxDebt
16
- {
17
- address: bill.contractAddress,
18
- name: 'terms',
19
- },
20
- {
21
- address: bill.contractAddress,
22
- name: bill.billVersion !== BillVersion.V1 ? 'getMaxTotalPayout' : 'maxTotalPayout',
23
- },
24
- ];
25
- return standardCalls;
26
- };
27
- export default fetchBillsCalls;
@@ -1,15 +0,0 @@
1
- import { Bills, CleanedBondsState, UserBill } from '../../types/bonds';
2
- import { ChainId } from '../../enum/apeswaplists';
3
- /**
4
- * Fetches user-owned bill NFT data for a given set of owned bills data, chain ID, and bills.
5
- * @param ownedBillsData An array of objects containing the ID, bill NFT address, and contract address of the owned bills.
6
- * @param chainId The ID of the blockchain network.
7
- * @param bills An array of objects containing the contract address and user-owned bill NFT data.
8
- * @returns An array of objects containing the ID and data of the user-owned bill NFTs.
9
- */
10
- export declare const fetchUserOwnedBillNftData: (ownedBillsData: {
11
- id: string;
12
- billNftAddress: string;
13
- contractAddress: string;
14
- }[], chainId: ChainId, bills: (CleanedBondsState | Bills)[]) => Promise<any[]>;
15
- export declare const fetchUserOwnedBills: (chainId: ChainId, account: string, bills: CleanedBondsState[]) => Promise<UserBill[]>;
@@ -1,171 +0,0 @@
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;
12
- return g = { next: verb(0), "throw": verb(1), "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 billAbi from '../../config/abi/bond.json';
38
- import BigNumber from 'bignumber.js';
39
- import { getBillNftBatchData } from './getBillNftData';
40
- import multicall from '../../utils/multicall';
41
- import { BillVersion } from '../../enum/apeswaplists';
42
- /**
43
- * Fetches user-owned bill NFT data for a given set of owned bills data, chain ID, and bills.
44
- * @param ownedBillsData An array of objects containing the ID, bill NFT address, and contract address of the owned bills.
45
- * @param chainId The ID of the blockchain network.
46
- * @param bills An array of objects containing the contract address and user-owned bill NFT data.
47
- * @returns An array of objects containing the ID and data of the user-owned bill NFTs.
48
- */
49
- export var fetchUserOwnedBillNftData = function (ownedBillsData, chainId, bills) { return __awaiter(void 0, void 0, void 0, function () {
50
- var billsToFetch, billsFetched, groupedBillsToFetch, groupedBillsToFetchArray, billNftData, billNftDataFlat, result;
51
- return __generator(this, function (_a) {
52
- switch (_a.label) {
53
- case 0:
54
- billsToFetch = [];
55
- billsFetched = [];
56
- // Loop through each owned bill and check if it exists in the bills array
57
- ownedBillsData === null || ownedBillsData === void 0 ? void 0 : ownedBillsData.forEach(function (_a) {
58
- var _b, _c;
59
- var id = _a.id, billNftAddress = _a.billNftAddress, contractAddress = _a.contractAddress;
60
- var bill = (_c = (_b = bills
61
- .find(function (b) { return b.contractAddress[chainId] === contractAddress; })) === null || _b === void 0 ? void 0 : _b.userOwnedBillsNftData) === null || _c === void 0 ? void 0 : _c.find(function (u) { return +u.tokenId === +id; });
62
- // If the bill exists in the bills array, add it to the billsFetched array
63
- if (bill) {
64
- billsFetched.push({ id: id, data: bill });
65
- }
66
- // If the bill doesn't exist in the bills array, add it to the billsToFetch array
67
- billsToFetch.push({ id: id, billNftAddress: billNftAddress, chainId: chainId });
68
- });
69
- groupedBillsToFetch = billsToFetch === null || billsToFetch === void 0 ? void 0 : billsToFetch.reduce(function (acc, bill) {
70
- var key = "".concat(bill === null || bill === void 0 ? void 0 : bill.billNftAddress, "-").concat(bill === null || bill === void 0 ? void 0 : bill.chainId);
71
- if (!acc[key]) {
72
- acc[key] = {
73
- billNftAddress: bill === null || bill === void 0 ? void 0 : bill.billNftAddress,
74
- chainId: bill === null || bill === void 0 ? void 0 : bill.chainId,
75
- ids: [],
76
- };
77
- }
78
- acc[key].ids.push(bill === null || bill === void 0 ? void 0 : bill.id);
79
- return acc;
80
- }, {});
81
- groupedBillsToFetchArray = Object.values(groupedBillsToFetch);
82
- return [4 /*yield*/, Promise.all(groupedBillsToFetchArray.map(function (_a) {
83
- var billNftAddress = _a.billNftAddress, chainId = _a.chainId, ids = _a.ids;
84
- return __awaiter(void 0, void 0, void 0, function () {
85
- return __generator(this, function (_b) {
86
- return [2 /*return*/, getBillNftBatchData(ids, billNftAddress, chainId)];
87
- });
88
- });
89
- }))
90
- // Flatten the resulting array of arrays into a single array
91
- ];
92
- case 1:
93
- billNftData = _a.sent();
94
- billNftDataFlat = billNftData.flat();
95
- result = billsFetched.concat(billNftDataFlat.map(function (data) { return ({ id: data.tokenId, data: data }); }));
96
- return [2 /*return*/, result];
97
- }
98
- });
99
- }); };
100
- export var fetchUserOwnedBills = function (chainId, account, bills) { return __awaiter(void 0, void 0, void 0, function () {
101
- var billIdCalls, billIds, billsPendingRewardCall, billDataCalls, billVersions, billData, pendingRewardsCall, result, i, billDataPos, data;
102
- var _a, _b, _c, _d, _e;
103
- return __generator(this, function (_f) {
104
- switch (_f.label) {
105
- case 0:
106
- billIdCalls = bills.map(function (b) { return ({
107
- address: b.contractAddress,
108
- name: 'getBillIds',
109
- params: [account],
110
- }); });
111
- return [4 /*yield*/, multicall(chainId, billAbi, billIdCalls, true, 15)];
112
- case 1:
113
- billIds = _f.sent();
114
- billsPendingRewardCall = [];
115
- billDataCalls = [];
116
- billVersions = [];
117
- billIds.forEach(function (idArray, index) {
118
- return idArray[0].forEach(function (id) {
119
- return id.gt(0) &&
120
- (billDataCalls.push({
121
- address: bills[index].contractAddress,
122
- name: bills[index].billVersion !== BillVersion.V1 ? 'getBillInfo' : 'billInfo',
123
- params: [id],
124
- }),
125
- billDataCalls.push({ address: bills[index].contractAddress, name: 'billNft' }),
126
- billsPendingRewardCall.push({
127
- address: bills[index].contractAddress,
128
- name: bills[index].billVersion !== BillVersion.V1 ? 'claimablePayout' : 'pendingPayoutFor',
129
- params: [id],
130
- }),
131
- billVersions.push(bills[index].billVersion));
132
- });
133
- });
134
- return [4 /*yield*/, multicall(chainId, billAbi, billDataCalls, true, 150)];
135
- case 2:
136
- billData = _f.sent();
137
- return [4 /*yield*/, multicall(chainId, billAbi, billsPendingRewardCall)];
138
- case 3:
139
- pendingRewardsCall = _f.sent();
140
- result = [];
141
- for (i = 0; i < billsPendingRewardCall.length; i++) {
142
- billDataPos = i === 0 ? 0 : i * 2;
143
- data = billVersions[i] !== BillVersion.V1
144
- ? {
145
- address: billsPendingRewardCall[i].address,
146
- id: billsPendingRewardCall[i].params[0].toString(),
147
- payout: new BigNumber((_a = billData[billDataPos][0]) === null || _a === void 0 ? void 0 : _a.payout.toString())
148
- .minus((_b = billData[billDataPos][0]) === null || _b === void 0 ? void 0 : _b.payoutClaimed.toString())
149
- .toString(),
150
- billNftAddress: billData[billDataPos + 1][0].toString(),
151
- vesting: (_c = billData[billDataPos][0]) === null || _c === void 0 ? void 0 : _c.vesting.toString(),
152
- lastBlockTimestamp: (_d = billData[billDataPos][0]) === null || _d === void 0 ? void 0 : _d.lastClaimTimestamp.toString(),
153
- truePricePaid: (_e = billData[billDataPos][0]) === null || _e === void 0 ? void 0 : _e.truePricePaid.toString(),
154
- pendingRewards: pendingRewardsCall[i][0].toString(),
155
- }
156
- : {
157
- address: billsPendingRewardCall[i].address,
158
- id: billsPendingRewardCall[i].params[0].toString(),
159
- payout: billData[billDataPos][0].toString(),
160
- billNftAddress: billData[billDataPos + 1][0].toString(),
161
- vesting: billData[billDataPos][1].toString(),
162
- lastBlockTimestamp: billData[billDataPos][2].toString(),
163
- truePricePaid: billData[billDataPos][3].toString(),
164
- pendingRewards: pendingRewardsCall[i][0].toString(),
165
- };
166
- result.push(data);
167
- }
168
- return [2 /*return*/, result];
169
- }
170
- });
171
- }); };
@@ -1,9 +0,0 @@
1
- export declare const getBillNftData: (billNftId: string, billNftAddress: string, chainId: number) => Promise<any>;
2
- /**
3
- * Retrieves batch data for a list of bill NFT IDs from the API.
4
- * @param billNftIds - An array of bill NFT IDs to retrieve data for.
5
- * @param billNftAddress - The address of the bill NFT contract.
6
- * @param chainId - The ID of the blockchain network to retrieve data from.
7
- * @returns A Promise that resolves to the batch data for the specified bill NFT IDs, or null if an error occurs.
8
- */
9
- export declare const getBillNftBatchData: (billNftIds: string[], billNftAddress: string, chainId: number) => Promise<any>;
@@ -1,109 +0,0 @@
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;
12
- return g = { next: verb(0), "throw": verb(1), "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 axiosRetry from 'axios-retry';
38
- import axios from 'axios';
39
- import { apiV2BaseUrl } from '../../config/constants/api';
40
- export var getBillNftData = function (billNftId, billNftAddress, chainId) { return __awaiter(void 0, void 0, void 0, function () {
41
- var response, billNftDataResp, error_1;
42
- return __generator(this, function (_a) {
43
- switch (_a.label) {
44
- case 0:
45
- _a.trys.push([0, 3, , 4]);
46
- axiosRetry(axios, {
47
- retries: 5,
48
- retryCondition: function () { return true; },
49
- });
50
- return [4 /*yield*/, axios.get("".concat(apiV2BaseUrl, "/bills/single/").concat(chainId, "/").concat(billNftAddress, "/").concat(billNftId))];
51
- case 1:
52
- response = _a.sent();
53
- return [4 /*yield*/, response.data];
54
- case 2:
55
- billNftDataResp = _a.sent();
56
- if (billNftDataResp.statusCode === 500) {
57
- return [2 /*return*/, null];
58
- }
59
- return [2 /*return*/, billNftDataResp];
60
- case 3:
61
- error_1 = _a.sent();
62
- return [2 /*return*/, null];
63
- case 4: return [2 /*return*/];
64
- }
65
- });
66
- }); };
67
- /**
68
- * Retrieves batch data for a list of bill NFT IDs from the API.
69
- * @param billNftIds - An array of bill NFT IDs to retrieve data for.
70
- * @param billNftAddress - The address of the bill NFT contract.
71
- * @param chainId - The ID of the blockchain network to retrieve data from.
72
- * @returns A Promise that resolves to the batch data for the specified bill NFT IDs, or null if an error occurs.
73
- */
74
- export var getBillNftBatchData = function (billNftIds, billNftAddress, chainId) { return __awaiter(void 0, void 0, void 0, function () {
75
- var response, billNftDataResp, error_2;
76
- return __generator(this, function (_a) {
77
- switch (_a.label) {
78
- case 0:
79
- _a.trys.push([0, 3, , 4]);
80
- // Retry the request up to 5 times if it fails
81
- axiosRetry(axios, {
82
- retries: 5,
83
- retryCondition: function () { return true; },
84
- });
85
- // If no bill NFT IDs are provided, return null
86
- if (!billNftIds || billNftIds.length === 0) {
87
- return [2 /*return*/, null];
88
- }
89
- return [4 /*yield*/, axios.get("".concat(apiV2BaseUrl, "/bills/batch/").concat(chainId, "/").concat(billNftAddress, "/?billIds[]=").concat(billNftIds.join('&billIds[]=')))
90
- // If the response status code is 500, return null
91
- ];
92
- case 1:
93
- response = _a.sent();
94
- return [4 /*yield*/, response.data];
95
- case 2:
96
- billNftDataResp = _a.sent();
97
- if (billNftDataResp.statusCode === 500) {
98
- return [2 /*return*/, null];
99
- }
100
- // Return the batch data for the specified bill NFT IDs
101
- return [2 /*return*/, billNftDataResp];
102
- case 3:
103
- error_2 = _a.sent();
104
- // If an error occurs, return null
105
- return [2 /*return*/, null];
106
- case 4: return [2 /*return*/];
107
- }
108
- });
109
- }); };
@@ -1,4 +0,0 @@
1
- import { ChainId } from '../../enum/apeswaplists';
2
- export declare const usePollBills: () => void;
3
- export declare const usePollSingleBill: (chainId?: ChainId, capturedBillAddress?: string) => void;
4
- export declare const usePollUserBills: () => any[];
@@ -1,142 +0,0 @@
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;
12
- return g = { next: verb(0), "throw": verb(1), "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 { useEffect, useState } from 'react';
38
- import { fetchBondsStats, fetchSingleBillPublicData, fetchUserOwnedBillsDataAsync } from '.';
39
- import { useWeb3React } from '@web3-react/core';
40
- import useRefresh from '../../hooks/useRefresh';
41
- import useTokenPricesNew from '../tokenPrices/useTokenPricesNew';
42
- import { MAINNET_CHAINS } from '../../config/constants/chains';
43
- // export const usePollBondsList = (bondApiList: CleanedBondsState[] | null) => {
44
- // const hasRun = useRef(false)
45
- // useEffect(() => {
46
- // if (!hasRun.current) {
47
- // const fetchBillsList = async () => {
48
- // try {
49
- // const response = await axios.get(`${APESWAP_LISTS_URL}/config/bills.json`)
50
- // const billsList: BillsConfig[] = response.data
51
- // console.log('fetch list')
52
- // const bondsData: CleanedBondsState[] = billsList.map((billConfig: BillsConfig) => {
53
- // const billApiData: CleanedBondsState | undefined = bondApiList?.find(
54
- // (bond: CleanedBondsState) => bond.index === billConfig.index,
55
- // )
56
- // return {
57
- // index: billConfig.index,
58
- // //@ts-ignore
59
- // cmcId: billConfig.cmcId ?? null,
60
- // chainId: billConfig.chainId,
61
- // principalTokenName: billConfig.lpToken.symbol,
62
- // principalToken: billConfig.lpToken.address[billConfig.chainId] as string,
63
- // principalTokenDecimals: billConfig.lpToken.decimals?.[billConfig.chainId] as number,
64
- // payoutTokenName: billConfig.earnToken.symbol,
65
- // payoutToken: billConfig.earnToken.address[billConfig.chainId] as string,
66
- // payoutTokenDecimals: billConfig.earnToken.decimals?.[billConfig.chainId] as number,
67
- // soldOut: billConfig.soldOut,
68
- // tags: billConfig.tags,
69
- // contractAddress: billConfig.contractAddress[billConfig.chainId] as string,
70
- // billNftAddress: billConfig.billNnftAddress[billConfig.chainId] as string,
71
- // inactive: billConfig.inactive,
72
- // showcaseTokenName: billConfig.showcaseToken?.symbol,
73
- // twitter: billConfig.twitter,
74
- // projectLink: billConfig.projectLink,
75
- // audit: billConfig.audit,
76
- // shortDescription: billConfig.shortDescription,
77
- // fullDescription: billConfig.fullDescription,
78
- // lpToken: billConfig.lpToken,
79
- // billType: billConfig.billType,
80
- // billVersion: billConfig.billVersion,
81
- // featuredURLS: billConfig.featuredURLS,
82
- // partnersURLS: billConfig.partnersURLS,
83
- // ...billApiData,
84
- // }
85
- // })
86
- // console.log('Set List data to State')
87
- // setBillsList({ value: bondsData })
88
- // } catch (error) {
89
- // console.log(error)
90
- // }
91
- // }
92
- // fetchBillsList()
93
- // hasRun.current = true
94
- // }
95
- // /* eslint-disable react-hooks/exhaustive-deps */
96
- // }, [])
97
- // }
98
- export var usePollBills = function () {
99
- var slowRefresh = useRefresh().slowRefresh;
100
- var tokenPrices = useTokenPricesNew().data;
101
- useEffect(function () {
102
- if (tokenPrices)
103
- fetchBondsStats(tokenPrices);
104
- }, [slowRefresh, tokenPrices === null || tokenPrices === void 0 ? void 0 : tokenPrices.length]);
105
- };
106
- export var usePollSingleBill = function (chainId, capturedBillAddress) {
107
- var tokenPrices = useTokenPricesNew().data;
108
- var slowRefresh = useRefresh().slowRefresh;
109
- useEffect(function () {
110
- if (chainId && capturedBillAddress && tokenPrices && (tokenPrices === null || tokenPrices === void 0 ? void 0 : tokenPrices.length) > 0) {
111
- fetchSingleBillPublicData(chainId, tokenPrices, capturedBillAddress);
112
- }
113
- /* eslint-disable react-hooks/exhaustive-deps */
114
- }, [slowRefresh, capturedBillAddress, chainId, tokenPrices === null || tokenPrices === void 0 ? void 0 : tokenPrices.length]);
115
- };
116
- export var usePollUserBills = function () {
117
- var slowRefresh = useRefresh().slowRefresh;
118
- var account = useWeb3React().account;
119
- var _a = useState([]), billsData = _a[0], setBillsData = _a[1];
120
- useEffect(function () {
121
- var fetchData = function () { return __awaiter(void 0, void 0, void 0, function () {
122
- var data;
123
- return __generator(this, function (_a) {
124
- switch (_a.label) {
125
- case 0:
126
- if (!account) return [3 /*break*/, 2];
127
- return [4 /*yield*/, Promise.all(MAINNET_CHAINS.map(function (chain) { return fetchUserOwnedBillsDataAsync(chain, account); }))];
128
- case 1:
129
- data = _a.sent();
130
- setBillsData(data);
131
- _a.label = 2;
132
- case 2: return [2 /*return*/];
133
- }
134
- });
135
- }); };
136
- fetchData();
137
- }, [account, slowRefresh]);
138
- return billsData;
139
- };
140
- // export const useBills = (): CleanedBondsState[] | undefined => {
141
- // return useSelector((state: AppState) => state.bills.data)
142
- // }
@@ -1,48 +0,0 @@
1
- import { Dispatch } from '@reduxjs/toolkit';
2
- import { TokenPrices } from '../tokenPrices/useTokenPricesNew';
3
- import { BondsDataResponse, CleanedBondsState } from '../../types/bonds';
4
- import { ChainId } from '../../enum/apeswaplists';
5
- export interface BillsState {
6
- isListFetched: boolean;
7
- data: CleanedBondsState[];
8
- }
9
- export declare const billsSlice: import("@reduxjs/toolkit").Slice<BillsState, {
10
- setBillsList: (state: any, action: {
11
- payload: {
12
- value: CleanedBondsState[];
13
- };
14
- }) => void;
15
- setBillsPublicData: (state: any, action: {
16
- payload: {
17
- value: CleanedBondsState[];
18
- };
19
- }) => void;
20
- setUserOwnedBillsData: (state: any, action: {
21
- payload: any;
22
- type: string;
23
- }) => void;
24
- setUserOwnedBillsNftData: (state: any, action: {
25
- payload: any;
26
- type: string;
27
- }) => void;
28
- }, "Bills", "Bills", import("@reduxjs/toolkit").SliceSelectors<BillsState>>;
29
- export declare const setBillsList: import("@reduxjs/toolkit").ActionCreatorWithPayload<{
30
- value: CleanedBondsState[];
31
- }, "Bills/setBillsList">, setBillsPublicData: import("@reduxjs/toolkit").ActionCreatorWithPayload<{
32
- value: CleanedBondsState[];
33
- }, "Bills/setBillsPublicData">, setUserOwnedBillsData: import("@reduxjs/toolkit").ActionCreatorWithPayload<any, "Bills/setUserOwnedBillsData">, setUserOwnedBillsNftData: import("@reduxjs/toolkit").ActionCreatorWithPayload<any, "Bills/setUserOwnedBillsNftData">;
34
- export declare const fetchBondsStats: (tokenPrices: TokenPrices[]) => (dispatch: Dispatch, getState: any) => Promise<void>;
35
- export declare const fetchSingleBillPublicData: (chainId: ChainId, tokenPrices: TokenPrices[], bondAddress: string) => (dispatch: Dispatch, getState: any) => Promise<void>;
36
- export declare const fetchUserOwnedBillsDataAsync: (chainId: ChainId, account: string) => (dispatch: Dispatch, getState: any) => Promise<{
37
- userOwnedBillsData: {
38
- index: number;
39
- userOwnedBills: import("../../types/bonds").UserBill[];
40
- }[];
41
- ownedBillsWithNftData: {
42
- index: number;
43
- userOwnedBillsNfts: any[];
44
- }[];
45
- }>;
46
- declare const _default: import("redux").Reducer<BillsState, import("redux").UnknownAction, BillsState>;
47
- export default _default;
48
- export declare const parseBondApiData: (billApiData: BondsDataResponse) => CleanedBondsState;