@ape.swap/bonds-sdk 1.0.352 → 1.0.354
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.
- package/dist/components/BondModal/BondModal.js +1 -1
- package/dist/components/YourBonds/YourBonds.js +40 -66
- package/dist/components/YourBonds/fetchBillsUser.d.ts +3 -3
- package/dist/components/YourBonds/fetchBillsUser.js +4 -4
- package/dist/types/bonds.d.ts +0 -62
- package/dist/types/yourbonds.d.ts +0 -4
- package/package.json +1 -1
- package/dist/config/abi/erc20.json +0 -117
- package/dist/config/abi/price-getter-linea.json +0 -1448
- package/dist/config/abi/price-getter.json +0 -1309
- package/dist/hooks/PriceGetter/usePricesFromPriceGetter.d.ts +0 -17
- package/dist/hooks/PriceGetter/usePricesFromPriceGetter.js +0 -205
- package/dist/state/bills/cleanBillsData.d.ts +0 -5
- package/dist/state/bills/cleanBillsData.js +0 -41
- package/dist/state/bills/fetchBills.d.ts +0 -4
- package/dist/state/bills/fetchBills.js +0 -61
- package/dist/state/bills/fetchBillsCalls.d.ts +0 -4
- package/dist/state/bills/fetchBillsCalls.js +0 -27
- package/dist/state/bills/fetchBillsUser.d.ts +0 -15
- package/dist/state/bills/fetchBillsUser.js +0 -171
- package/dist/state/bills/getBillNftData.d.ts +0 -9
- package/dist/state/bills/getBillNftData.js +0 -109
- package/dist/state/bills/hooks.d.ts +0 -4
- package/dist/state/bills/hooks.js +0 -142
- package/dist/state/bills/index.d.ts +0 -48
- package/dist/state/bills/index.js +0 -293
- package/dist/state/bills/types.d.ts +0 -168
- package/dist/state/bills/types.js +0 -1
- package/dist/state/tokenPrices/fetchTokenPricesForMultipleChains.d.ts +0 -4
- package/dist/state/tokenPrices/fetchTokenPricesForMultipleChains.js +0 -68
- package/dist/state/tokenPrices/getAllTokenPrices.d.ts +0 -5
- package/dist/state/tokenPrices/getAllTokenPrices.js +0 -288
- package/dist/state/tokenPrices/useTokenPricesNew.d.ts +0 -11
- package/dist/state/tokenPrices/useTokenPricesNew.js +0 -72
- package/dist/types/dexFactories.d.ts +0 -11
- package/dist/types/dexFactories.js +0 -2
|
@@ -1,17 +0,0 @@
|
|
|
1
|
-
import { ChainId, Token as Token_ApeSwapLists } from '../../enum/apeswaplists';
|
|
2
|
-
type TokenRecord = {
|
|
3
|
-
[k: string]: Token_ApeSwapLists;
|
|
4
|
-
};
|
|
5
|
-
export declare function getTokenPricesV2FromPriceGetter(tokensToCall: TokenRecord, chain: ChainId, lpTokens?: boolean): Promise<any>;
|
|
6
|
-
/**
|
|
7
|
-
* Custom hook to get price getter data.
|
|
8
|
-
*
|
|
9
|
-
* @param tokens - Tokens to build tx data for.
|
|
10
|
-
* @param supportedChainId - The chain ID.
|
|
11
|
-
* @returns The token price calls.
|
|
12
|
-
*/
|
|
13
|
-
export declare function usePriceGetterData(tokensToCall: TokenRecord, // replace 'any' with the actual type
|
|
14
|
-
supportedChainId: ChainId, lpTokens: boolean): (string | number | undefined)[][];
|
|
15
|
-
export declare function getPriceGetterCallData(tokensToCall: TokenRecord, // replace 'any' with the actual type
|
|
16
|
-
supportedChainId: ChainId, lpTokens: boolean): (string | number | undefined)[][];
|
|
17
|
-
export {};
|
|
@@ -1,205 +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 { ZERO_ADDRESS } from '../../config/constants/misc';
|
|
38
|
-
import { useMemo } from 'react';
|
|
39
|
-
import multicall from '../../utils/multicall';
|
|
40
|
-
import { PRICE_GETTER_ADDRESSES } from '../../config/constants/addresses';
|
|
41
|
-
import PRICE_GETTER_ABI from '../../config/abi/price-getter.json';
|
|
42
|
-
import PRICE_GETTER_ABI_LINEA from '../../config/abi/price-getter-linea.json';
|
|
43
|
-
import { ChainId, Protocols } from '../../enum/apeswaplists';
|
|
44
|
-
import { defaultDexFactories, dexFactories } from '../../types/dexFactories';
|
|
45
|
-
export function getTokenPricesV2FromPriceGetter(tokensToCall, chain, lpTokens) {
|
|
46
|
-
if (lpTokens === void 0) { lpTokens = false; }
|
|
47
|
-
return __awaiter(this, void 0, void 0, function () {
|
|
48
|
-
var tokenCalls, calls, tokenResults;
|
|
49
|
-
return __generator(this, function (_a) {
|
|
50
|
-
switch (_a.label) {
|
|
51
|
-
case 0:
|
|
52
|
-
tokenCalls = getPriceGetterCallData(tokensToCall, chain, lpTokens);
|
|
53
|
-
calls = tokenCalls.map(function (t) { return ({
|
|
54
|
-
address: PRICE_GETTER_ADDRESSES[chain],
|
|
55
|
-
name: lpTokens ? 'getLPPriceFromFactory' : 'getPriceFromFactory',
|
|
56
|
-
params: t,
|
|
57
|
-
}); });
|
|
58
|
-
return [4 /*yield*/, multicall(+chain, [ChainId.LINEA, ChainId.LIGHTLINK, ChainId.IOTA, ChainId.BASE].includes(chain)
|
|
59
|
-
? PRICE_GETTER_ABI_LINEA
|
|
60
|
-
: PRICE_GETTER_ABI, calls)];
|
|
61
|
-
case 1:
|
|
62
|
-
tokenResults = _a.sent();
|
|
63
|
-
return [2 /*return*/, tokenResults];
|
|
64
|
-
}
|
|
65
|
-
});
|
|
66
|
-
});
|
|
67
|
-
}
|
|
68
|
-
/**
|
|
69
|
-
* Custom hook to get price getter data.
|
|
70
|
-
*
|
|
71
|
-
* @param tokens - Tokens to build tx data for.
|
|
72
|
-
* @param supportedChainId - The chain ID.
|
|
73
|
-
* @returns The token price calls.
|
|
74
|
-
*/
|
|
75
|
-
export function usePriceGetterData(tokensToCall, // replace 'any' with the actual type
|
|
76
|
-
supportedChainId, lpTokens) {
|
|
77
|
-
return useMemo(function () {
|
|
78
|
-
return Object.values(tokensToCall).map(function (token) {
|
|
79
|
-
var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k, _l, _m, _o, _p, _q;
|
|
80
|
-
var liquidityDex = (_a = token.liquidityDex) === null || _a === void 0 ? void 0 : _a[supportedChainId];
|
|
81
|
-
var dexFactory;
|
|
82
|
-
var protocol = 2;
|
|
83
|
-
var factoryV2 = (_c = (_b = defaultDexFactories === null || defaultDexFactories === void 0 ? void 0 : defaultDexFactories[supportedChainId]) === null || _b === void 0 ? void 0 : _b[2]) !== null && _c !== void 0 ? _c : ZERO_ADDRESS;
|
|
84
|
-
var factoryV3 = (_e = (_d = defaultDexFactories === null || defaultDexFactories === void 0 ? void 0 : defaultDexFactories[supportedChainId]) === null || _d === void 0 ? void 0 : _d[3]) !== null && _e !== void 0 ? _e : ZERO_ADDRESS;
|
|
85
|
-
var factoryAlgebra = (_g = (_f = defaultDexFactories === null || defaultDexFactories === void 0 ? void 0 : defaultDexFactories[supportedChainId]) === null || _f === void 0 ? void 0 : _f[4]) !== null && _g !== void 0 ? _g : ZERO_ADDRESS;
|
|
86
|
-
var factorySolidly = (_j = (_h = defaultDexFactories === null || defaultDexFactories === void 0 ? void 0 : defaultDexFactories[supportedChainId]) === null || _h === void 0 ? void 0 : _h[7]) !== null && _j !== void 0 ? _j : ZERO_ADDRESS;
|
|
87
|
-
if (liquidityDex) {
|
|
88
|
-
dexFactory = (_k = dexFactories[supportedChainId]) === null || _k === void 0 ? void 0 : _k[liquidityDex];
|
|
89
|
-
protocol = (_l = dexFactory === null || dexFactory === void 0 ? void 0 : dexFactory.protocol) !== null && _l !== void 0 ? _l : Protocols.V2;
|
|
90
|
-
switch (protocol) {
|
|
91
|
-
case Protocols.V2:
|
|
92
|
-
factoryV2 = (_m = dexFactory === null || dexFactory === void 0 ? void 0 : dexFactory.factory) !== null && _m !== void 0 ? _m : factoryV2;
|
|
93
|
-
break;
|
|
94
|
-
case Protocols.V3:
|
|
95
|
-
factoryV3 = (_o = dexFactory === null || dexFactory === void 0 ? void 0 : dexFactory.factory) !== null && _o !== void 0 ? _o : factoryV3;
|
|
96
|
-
break;
|
|
97
|
-
case Protocols.Algebra:
|
|
98
|
-
factoryAlgebra = (_p = dexFactory === null || dexFactory === void 0 ? void 0 : dexFactory.factory) !== null && _p !== void 0 ? _p : factoryAlgebra;
|
|
99
|
-
break;
|
|
100
|
-
case Protocols.Solidly:
|
|
101
|
-
factorySolidly = (_q = dexFactory === null || dexFactory === void 0 ? void 0 : dexFactory.factory) !== null && _q !== void 0 ? _q : factorySolidly;
|
|
102
|
-
break;
|
|
103
|
-
}
|
|
104
|
-
}
|
|
105
|
-
var errMsg = "No default dex factory found for retrieving price. For Protocol: ".concat(protocol, ".");
|
|
106
|
-
switch (protocol) {
|
|
107
|
-
case Protocols.Both:
|
|
108
|
-
if (factoryV2 === ZERO_ADDRESS || factoryV3 === ZERO_ADDRESS) {
|
|
109
|
-
throw new Error(errMsg);
|
|
110
|
-
}
|
|
111
|
-
break;
|
|
112
|
-
case Protocols.V2:
|
|
113
|
-
if (factoryV2 === ZERO_ADDRESS) {
|
|
114
|
-
throw new Error(errMsg);
|
|
115
|
-
}
|
|
116
|
-
break;
|
|
117
|
-
case Protocols.V3:
|
|
118
|
-
if (factoryV3 === ZERO_ADDRESS) {
|
|
119
|
-
throw new Error(errMsg);
|
|
120
|
-
}
|
|
121
|
-
break;
|
|
122
|
-
}
|
|
123
|
-
// Not sure if this is the best way to handle this. It requires all tokens to be either LP or not
|
|
124
|
-
if (lpTokens && protocol == Protocols.Algebra) {
|
|
125
|
-
protocol = Protocols.Gamma;
|
|
126
|
-
}
|
|
127
|
-
if (lpTokens && protocol == Protocols.V3) {
|
|
128
|
-
protocol = Protocols.Steer;
|
|
129
|
-
}
|
|
130
|
-
return [token.address[supportedChainId], protocol, factoryV2, factoryV3, factoryAlgebra, factorySolidly];
|
|
131
|
-
});
|
|
132
|
-
}, [tokensToCall, supportedChainId, lpTokens]);
|
|
133
|
-
}
|
|
134
|
-
export function getPriceGetterCallData(tokensToCall, // replace 'any' with the actual type
|
|
135
|
-
supportedChainId, lpTokens) {
|
|
136
|
-
return Object.values(tokensToCall).map(function (token) {
|
|
137
|
-
var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k, _l, _m, _o, _p, _q, _r, _s, _t;
|
|
138
|
-
var liquidityDex = (_a = token.liquidityDex) === null || _a === void 0 ? void 0 : _a[supportedChainId];
|
|
139
|
-
var dexFactory;
|
|
140
|
-
var protocol = 2;
|
|
141
|
-
var factoryV2 = (_c = (_b = defaultDexFactories === null || defaultDexFactories === void 0 ? void 0 : defaultDexFactories[supportedChainId]) === null || _b === void 0 ? void 0 : _b[2]) !== null && _c !== void 0 ? _c : ZERO_ADDRESS;
|
|
142
|
-
var factoryV3 = (_e = (_d = defaultDexFactories === null || defaultDexFactories === void 0 ? void 0 : defaultDexFactories[supportedChainId]) === null || _d === void 0 ? void 0 : _d[3]) !== null && _e !== void 0 ? _e : ZERO_ADDRESS;
|
|
143
|
-
var factoryAlgebra = (_g = (_f = defaultDexFactories === null || defaultDexFactories === void 0 ? void 0 : defaultDexFactories[supportedChainId]) === null || _f === void 0 ? void 0 : _f[4]) !== null && _g !== void 0 ? _g : ZERO_ADDRESS;
|
|
144
|
-
var factorySolidly = (_j = (_h = defaultDexFactories === null || defaultDexFactories === void 0 ? void 0 : defaultDexFactories[supportedChainId]) === null || _h === void 0 ? void 0 : _h[7]) !== null && _j !== void 0 ? _j : ZERO_ADDRESS;
|
|
145
|
-
var factoryXFAI = (_l = (_k = defaultDexFactories === null || defaultDexFactories === void 0 ? void 0 : defaultDexFactories[supportedChainId]) === null || _k === void 0 ? void 0 : _k[8]) !== null && _l !== void 0 ? _l : ZERO_ADDRESS;
|
|
146
|
-
if (liquidityDex) {
|
|
147
|
-
dexFactory = (_m = dexFactories[supportedChainId]) === null || _m === void 0 ? void 0 : _m[liquidityDex];
|
|
148
|
-
protocol = (_o = dexFactory === null || dexFactory === void 0 ? void 0 : dexFactory.protocol) !== null && _o !== void 0 ? _o : Protocols.V2;
|
|
149
|
-
switch (protocol) {
|
|
150
|
-
case Protocols.V2:
|
|
151
|
-
factoryV2 = (_p = dexFactory === null || dexFactory === void 0 ? void 0 : dexFactory.factory) !== null && _p !== void 0 ? _p : factoryV2;
|
|
152
|
-
break;
|
|
153
|
-
case Protocols.V3:
|
|
154
|
-
factoryV3 = (_q = dexFactory === null || dexFactory === void 0 ? void 0 : dexFactory.factory) !== null && _q !== void 0 ? _q : factoryV3;
|
|
155
|
-
break;
|
|
156
|
-
case Protocols.Algebra:
|
|
157
|
-
factoryAlgebra = (_r = dexFactory === null || dexFactory === void 0 ? void 0 : dexFactory.factory) !== null && _r !== void 0 ? _r : factoryAlgebra;
|
|
158
|
-
break;
|
|
159
|
-
case Protocols.Solidly:
|
|
160
|
-
factorySolidly = (_s = dexFactory === null || dexFactory === void 0 ? void 0 : dexFactory.factory) !== null && _s !== void 0 ? _s : factorySolidly;
|
|
161
|
-
break;
|
|
162
|
-
case Protocols.XFAI:
|
|
163
|
-
factoryXFAI = (_t = dexFactory === null || dexFactory === void 0 ? void 0 : dexFactory.factory) !== null && _t !== void 0 ? _t : factoryXFAI;
|
|
164
|
-
}
|
|
165
|
-
}
|
|
166
|
-
var errMsg = "No default dex factory found for retrieving price. For Protocol: ".concat(protocol, ".");
|
|
167
|
-
switch (protocol) {
|
|
168
|
-
case Protocols.Both:
|
|
169
|
-
if (factoryV2 === ZERO_ADDRESS || factoryV3 === ZERO_ADDRESS) {
|
|
170
|
-
throw new Error(errMsg);
|
|
171
|
-
}
|
|
172
|
-
break;
|
|
173
|
-
case Protocols.V2:
|
|
174
|
-
if (factoryV2 === ZERO_ADDRESS) {
|
|
175
|
-
throw new Error(errMsg);
|
|
176
|
-
}
|
|
177
|
-
break;
|
|
178
|
-
case Protocols.V3:
|
|
179
|
-
if (factoryV3 === ZERO_ADDRESS) {
|
|
180
|
-
throw new Error(errMsg);
|
|
181
|
-
}
|
|
182
|
-
break;
|
|
183
|
-
}
|
|
184
|
-
// TODO: Not sure if this is the best way to handle this. It requires all tokens to be either LP or not
|
|
185
|
-
if (lpTokens && protocol == Protocols.Algebra) {
|
|
186
|
-
protocol = Protocols.Gamma;
|
|
187
|
-
}
|
|
188
|
-
if (lpTokens && protocol == Protocols.V3) {
|
|
189
|
-
protocol = Protocols.Steer;
|
|
190
|
-
}
|
|
191
|
-
if ([ChainId.LINEA, ChainId.LIGHTLINK, ChainId.IOTA, ChainId.BASE].includes(supportedChainId) && !token.lpToken) {
|
|
192
|
-
return [
|
|
193
|
-
token.address[supportedChainId],
|
|
194
|
-
protocol,
|
|
195
|
-
factoryV2,
|
|
196
|
-
factoryV3,
|
|
197
|
-
factoryAlgebra,
|
|
198
|
-
factorySolidly,
|
|
199
|
-
factoryXFAI,
|
|
200
|
-
];
|
|
201
|
-
}
|
|
202
|
-
else
|
|
203
|
-
return [token.address[supportedChainId], protocol, factoryV2, factoryV3, factoryAlgebra, factorySolidly];
|
|
204
|
-
});
|
|
205
|
-
}
|
|
@@ -1,5 +0,0 @@
|
|
|
1
|
-
import { ChainId } from '../../enum/apeswaplists';
|
|
2
|
-
import { CleanedBondsState } from '../../types/bonds';
|
|
3
|
-
import { TokenPrices } from '../tokenPrices/useTokenPricesNew';
|
|
4
|
-
declare const cleanBillsData: (billIds: number[], chunkedBills: any[], tokenPrices: TokenPrices[], chainId: ChainId, bills: CleanedBondsState[]) => CleanedBondsState[];
|
|
5
|
-
export default cleanBillsData;
|
|
@@ -1,41 +0,0 @@
|
|
|
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 { getBalanceNumber } from '../../utils/getBalanceNumber';
|
|
13
|
-
import BigNumber from 'bignumber.js';
|
|
14
|
-
var cleanBillsData = function (billIds, chunkedBills, tokenPrices, chainId, bills) {
|
|
15
|
-
var data = chunkedBills === null || chunkedBills === void 0 ? void 0 : chunkedBills.map(function (chunk, index) {
|
|
16
|
-
var _a, _b, _c;
|
|
17
|
-
var billFromState = bills === null || bills === void 0 ? void 0 : bills.find(function (bill) { return (bill === null || bill === void 0 ? void 0 : bill.index) === billIds[index]; });
|
|
18
|
-
var lpPrice = (_a = tokenPrices === null || tokenPrices === void 0 ? void 0 : tokenPrices.find(function (tokenPrice) {
|
|
19
|
-
var _a;
|
|
20
|
-
return ((_a = tokenPrice.address) === null || _a === void 0 ? void 0 : _a.toLowerCase()) === (billFromState === null || billFromState === void 0 ? void 0 : billFromState.principalToken.toLowerCase()) &&
|
|
21
|
-
tokenPrice.chainId === chainId;
|
|
22
|
-
})) === null || _a === void 0 ? void 0 : _a.price;
|
|
23
|
-
var earnTokenPrice = (_b = tokenPrices === null || tokenPrices === void 0 ? void 0 : tokenPrices.find(function (tokenPrice) {
|
|
24
|
-
var _a;
|
|
25
|
-
return ((_a = tokenPrice.address) === null || _a === void 0 ? void 0 : _a.toLowerCase()) === (billFromState === null || billFromState === void 0 ? void 0 : billFromState.payoutToken.toLowerCase()) &&
|
|
26
|
-
tokenPrice.chainId === chainId;
|
|
27
|
-
})) === null || _b === void 0 ? void 0 : _b.price;
|
|
28
|
-
var trueBillPrice = chunk[0], totalPayoutGiven = chunk[1], terms = chunk[2], maxTotalPayout = chunk[3];
|
|
29
|
-
var vestingTerm = terms[1], maxPayout = terms[3];
|
|
30
|
-
var priceUsd = lpPrice && trueBillPrice && getBalanceNumber(trueBillPrice === null || trueBillPrice === void 0 ? void 0 : trueBillPrice.toString()) * lpPrice;
|
|
31
|
-
var discount = earnTokenPrice && priceUsd && ((earnTokenPrice - priceUsd) / earnTokenPrice) * 100;
|
|
32
|
-
var tokensRemaining = new BigNumber(maxTotalPayout !== null && maxTotalPayout !== void 0 ? maxTotalPayout : '0')
|
|
33
|
-
.minus(new BigNumber(totalPayoutGiven))
|
|
34
|
-
.div(new BigNumber(10).pow((_c = billFromState === null || billFromState === void 0 ? void 0 : billFromState.payoutTokenDecimals) !== null && _c !== void 0 ? _c : 18))
|
|
35
|
-
.toString();
|
|
36
|
-
var cleanedData = __assign(__assign({}, billFromState), { discount: discount, principalTokenPrice: lpPrice === null || lpPrice === void 0 ? void 0 : lpPrice.toString(), payoutTokenPrice: earnTokenPrice === null || earnTokenPrice === void 0 ? void 0 : earnTokenPrice.toString(), tokensRemaining: tokensRemaining, maxTotalPayout: maxTotalPayout === null || maxTotalPayout === void 0 ? void 0 : maxTotalPayout.toString(), trueBillPrice: trueBillPrice === null || trueBillPrice === void 0 ? void 0 : trueBillPrice.toString(), maxPayout: maxPayout === null || maxPayout === void 0 ? void 0 : maxPayout.toString(), totalPayoutGiven: totalPayoutGiven === null || totalPayoutGiven === void 0 ? void 0 : totalPayoutGiven.toString(), vestingTerm: vestingTerm.toNumber() });
|
|
37
|
-
return cleanedData;
|
|
38
|
-
});
|
|
39
|
-
return data;
|
|
40
|
-
};
|
|
41
|
-
export default cleanBillsData;
|
|
@@ -1,4 +0,0 @@
|
|
|
1
|
-
import { TokenPrices } from '../tokenPrices/useTokenPricesNew';
|
|
2
|
-
import { CleanedBondsState } from '../../types/bonds';
|
|
3
|
-
declare const fetchBills: (chainId: number, tokenPrices: TokenPrices[], bills: CleanedBondsState[]) => Promise<CleanedBondsState[]>;
|
|
4
|
-
export default fetchBills;
|
|
@@ -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,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>;
|