@alphafi/alphafi-sdk 0.0.35 → 0.0.36
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/cjs/common/coins.d.ts +1 -1
- package/dist/cjs/common/coins.d.ts.map +1 -1
- package/dist/cjs/common/coins.js +15 -11
- package/dist/cjs/common/coins.js.map +1 -1
- package/dist/cjs/common/constants.d.ts +436 -32
- package/dist/cjs/common/constants.d.ts.map +1 -1
- package/dist/cjs/common/constants.js +488 -56
- package/dist/cjs/common/constants.js.map +1 -1
- package/dist/cjs/common/maps.d.ts +46 -28
- package/dist/cjs/common/maps.d.ts.map +1 -1
- package/dist/cjs/common/maps.js +358 -227
- package/dist/cjs/common/maps.js.map +1 -1
- package/dist/cjs/common/types.d.ts +59 -47
- package/dist/cjs/common/types.d.ts.map +1 -1
- package/dist/cjs/common/types.js.map +1 -1
- package/dist/cjs/getVaultBalances.d.ts +2 -1
- package/dist/cjs/getVaultBalances.d.ts.map +1 -1
- package/dist/cjs/getVaultBalances.js +16 -1
- package/dist/cjs/getVaultBalances.js.map +1 -1
- package/dist/cjs/graphql/getMultiReceipts.d.ts.map +1 -1
- package/dist/cjs/graphql/getMultiReceipts.js +4 -0
- package/dist/cjs/graphql/getMultiReceipts.js.map +1 -1
- package/dist/cjs/index.d.ts +4 -4
- package/dist/cjs/index.d.ts.map +1 -1
- package/dist/cjs/index.js +13 -5
- package/dist/cjs/index.js.map +1 -1
- package/dist/cjs/sui-sdk/events/fetchAfterTransactionEvents.d.ts.map +1 -1
- package/dist/cjs/sui-sdk/events/fetchAfterTransactionEvents.js +2 -2
- package/dist/cjs/sui-sdk/events/fetchAfterTransactionEvents.js.map +1 -1
- package/dist/cjs/sui-sdk/events/fetchAutoCompoundingEvents.d.ts.map +1 -1
- package/dist/cjs/sui-sdk/events/fetchAutoCompoundingEvents.js +2 -2
- package/dist/cjs/sui-sdk/events/fetchAutoCompoundingEvents.js.map +1 -1
- package/dist/cjs/sui-sdk/events/fetchRebalanceEvents.d.ts.map +1 -1
- package/dist/cjs/sui-sdk/events/fetchRebalanceEvents.js +5 -7
- package/dist/cjs/sui-sdk/events/fetchRebalanceEvents.js.map +1 -1
- package/dist/cjs/sui-sdk/functions/fetchUserVaultBalances.d.ts +1 -1
- package/dist/cjs/sui-sdk/functions/fetchUserVaultBalances.d.ts.map +1 -1
- package/dist/cjs/sui-sdk/functions/fetchUserVaultBalances.js +11 -20
- package/dist/cjs/sui-sdk/functions/fetchUserVaultBalances.js.map +1 -1
- package/dist/cjs/sui-sdk/functions/fetchUserVaults.d.ts.map +1 -1
- package/dist/cjs/sui-sdk/functions/fetchUserVaults.js +8 -7
- package/dist/cjs/sui-sdk/functions/fetchUserVaults.js.map +1 -1
- package/dist/cjs/sui-sdk/functions/getPortfolioAmounts.d.ts +8 -23
- package/dist/cjs/sui-sdk/functions/getPortfolioAmounts.d.ts.map +1 -1
- package/dist/cjs/sui-sdk/functions/getPortfolioAmounts.js +157 -141
- package/dist/cjs/sui-sdk/functions/getPortfolioAmounts.js.map +1 -1
- package/dist/cjs/sui-sdk/functions/getReceipts.d.ts +15 -10
- package/dist/cjs/sui-sdk/functions/getReceipts.d.ts.map +1 -1
- package/dist/cjs/sui-sdk/functions/getReceipts.js +274 -190
- package/dist/cjs/sui-sdk/functions/getReceipts.js.map +1 -1
- package/dist/cjs/utils/clmm/prices.js +9 -9
- package/dist/cjs/utils/clmm/prices.js.map +1 -1
- package/dist/cjs/utils/getHoldersFromTransactionsUtils.d.ts.map +1 -1
- package/dist/cjs/utils/getHoldersFromTransactionsUtils.js +7 -7
- package/dist/cjs/utils/getHoldersFromTransactionsUtils.js.map +1 -1
- package/dist/cjs/utils/hop.js +3 -3
- package/dist/cjs/utils/hop.js.map +1 -1
- package/dist/cjs/utils/prices.d.ts +2 -0
- package/dist/cjs/utils/prices.d.ts.map +1 -1
- package/dist/cjs/utils/prices.js +39 -0
- package/dist/cjs/utils/prices.js.map +1 -1
- package/dist/cjs/utils/userHoldings.d.ts.map +1 -1
- package/dist/cjs/utils/userHoldings.js +18 -18
- package/dist/cjs/utils/userHoldings.js.map +1 -1
- package/dist/esm/common/coins.d.ts +1 -1
- package/dist/esm/common/coins.d.ts.map +1 -1
- package/dist/esm/common/coins.js +14 -10
- package/dist/esm/common/coins.js.map +1 -1
- package/dist/esm/common/constants.d.ts +436 -32
- package/dist/esm/common/constants.d.ts.map +1 -1
- package/dist/esm/common/constants.js +488 -56
- package/dist/esm/common/constants.js.map +1 -1
- package/dist/esm/common/maps.d.ts +46 -28
- package/dist/esm/common/maps.d.ts.map +1 -1
- package/dist/esm/common/maps.js +355 -226
- package/dist/esm/common/maps.js.map +1 -1
- package/dist/esm/common/types.d.ts +59 -47
- package/dist/esm/common/types.d.ts.map +1 -1
- package/dist/esm/common/types.js.map +1 -1
- package/dist/esm/getVaultBalances.d.ts +2 -1
- package/dist/esm/getVaultBalances.d.ts.map +1 -1
- package/dist/esm/getVaultBalances.js +15 -1
- package/dist/esm/getVaultBalances.js.map +1 -1
- package/dist/esm/graphql/getMultiReceipts.d.ts.map +1 -1
- package/dist/esm/graphql/getMultiReceipts.js +4 -0
- package/dist/esm/graphql/getMultiReceipts.js.map +1 -1
- package/dist/esm/index.d.ts +4 -4
- package/dist/esm/index.d.ts.map +1 -1
- package/dist/esm/index.js +4 -4
- package/dist/esm/index.js.map +1 -1
- package/dist/esm/sui-sdk/events/fetchAfterTransactionEvents.d.ts.map +1 -1
- package/dist/esm/sui-sdk/events/fetchAfterTransactionEvents.js +4 -4
- package/dist/esm/sui-sdk/events/fetchAfterTransactionEvents.js.map +1 -1
- package/dist/esm/sui-sdk/events/fetchAutoCompoundingEvents.d.ts.map +1 -1
- package/dist/esm/sui-sdk/events/fetchAutoCompoundingEvents.js +4 -4
- package/dist/esm/sui-sdk/events/fetchAutoCompoundingEvents.js.map +1 -1
- package/dist/esm/sui-sdk/events/fetchRebalanceEvents.d.ts.map +1 -1
- package/dist/esm/sui-sdk/events/fetchRebalanceEvents.js +7 -9
- package/dist/esm/sui-sdk/events/fetchRebalanceEvents.js.map +1 -1
- package/dist/esm/sui-sdk/functions/fetchUserVaultBalances.d.ts +1 -1
- package/dist/esm/sui-sdk/functions/fetchUserVaultBalances.d.ts.map +1 -1
- package/dist/esm/sui-sdk/functions/fetchUserVaultBalances.js +11 -20
- package/dist/esm/sui-sdk/functions/fetchUserVaultBalances.js.map +1 -1
- package/dist/esm/sui-sdk/functions/fetchUserVaults.d.ts.map +1 -1
- package/dist/esm/sui-sdk/functions/fetchUserVaults.js +9 -8
- package/dist/esm/sui-sdk/functions/fetchUserVaults.js.map +1 -1
- package/dist/esm/sui-sdk/functions/getPortfolioAmounts.d.ts +8 -23
- package/dist/esm/sui-sdk/functions/getPortfolioAmounts.d.ts.map +1 -1
- package/dist/esm/sui-sdk/functions/getPortfolioAmounts.js +158 -144
- package/dist/esm/sui-sdk/functions/getPortfolioAmounts.js.map +1 -1
- package/dist/esm/sui-sdk/functions/getReceipts.d.ts +15 -10
- package/dist/esm/sui-sdk/functions/getReceipts.d.ts.map +1 -1
- package/dist/esm/sui-sdk/functions/getReceipts.js +266 -186
- package/dist/esm/sui-sdk/functions/getReceipts.js.map +1 -1
- package/dist/esm/utils/clmm/prices.js +10 -10
- package/dist/esm/utils/clmm/prices.js.map +1 -1
- package/dist/esm/utils/getHoldersFromTransactionsUtils.d.ts.map +1 -1
- package/dist/esm/utils/getHoldersFromTransactionsUtils.js +9 -9
- package/dist/esm/utils/getHoldersFromTransactionsUtils.js.map +1 -1
- package/dist/esm/utils/hop.js +4 -4
- package/dist/esm/utils/hop.js.map +1 -1
- package/dist/esm/utils/prices.d.ts +2 -0
- package/dist/esm/utils/prices.d.ts.map +1 -1
- package/dist/esm/utils/prices.js +37 -0
- package/dist/esm/utils/prices.js.map +1 -1
- package/dist/esm/utils/userHoldings.d.ts.map +1 -1
- package/dist/esm/utils/userHoldings.js +20 -20
- package/dist/esm/utils/userHoldings.js.map +1 -1
- package/package.json +2 -2
|
@@ -1,26 +1,126 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.convertReceiptGQLToReceipt = convertReceiptGQLToReceipt;
|
|
4
|
+
exports.getMultiReceipts = getMultiReceipts;
|
|
3
5
|
exports.getReceipts = getReceipts;
|
|
4
6
|
exports.getPoolExchangeRate = getPoolExchangeRate;
|
|
5
|
-
exports.
|
|
7
|
+
exports.getMultiPool = getMultiPool;
|
|
6
8
|
exports.getPool = getPool;
|
|
7
|
-
exports.
|
|
8
|
-
exports.
|
|
9
|
-
exports.
|
|
9
|
+
exports.getMultiParentPool = getMultiParentPool;
|
|
10
|
+
exports.getParentPool = getParentPool;
|
|
11
|
+
exports.getMultiInvestor = getMultiInvestor;
|
|
12
|
+
exports.getInvestor = getInvestor;
|
|
10
13
|
exports.fetchVoloExchangeRate = fetchVoloExchangeRate;
|
|
14
|
+
exports.getCoinAmountsFromLiquidity = getCoinAmountsFromLiquidity;
|
|
11
15
|
exports.multiGetNaviInvestor = multiGetNaviInvestor;
|
|
12
16
|
const tslib_1 = require("tslib");
|
|
17
|
+
const index_js_1 = require("../../index.js");
|
|
13
18
|
const maps_js_1 = require("../../common/maps.js");
|
|
14
|
-
const simpleCache_js_1 = require("../../utils/simpleCache.js");
|
|
15
19
|
const cetus_sui_clmm_sdk_1 = require("@cetusprotocol/cetus-sui-clmm-sdk");
|
|
16
20
|
const bn_js_1 = tslib_1.__importDefault(require("bn.js"));
|
|
17
21
|
const decimal_js_1 = require("decimal.js");
|
|
18
22
|
const client_js_1 = require("../client.js");
|
|
19
|
-
const
|
|
20
|
-
|
|
21
|
-
|
|
23
|
+
const simpleCache_js_1 = require("../../utils/simpleCache.js");
|
|
24
|
+
function convertReceiptGQLToReceipt(receipts) {
|
|
25
|
+
const res = receipts.map((receipt) => {
|
|
26
|
+
return {
|
|
27
|
+
objectId: receipt.address,
|
|
28
|
+
version: receipt.version,
|
|
29
|
+
digest: receipt.digest,
|
|
30
|
+
content: {
|
|
31
|
+
dataType: "moveObject", // Assuming a fixed value as it's not available in ReceiptA
|
|
32
|
+
type: receipt.contents.type.repr,
|
|
33
|
+
hasPublicTransfer: receipt.hasPublicTransfer,
|
|
34
|
+
fields: {
|
|
35
|
+
id: { id: receipt.contents.json.id },
|
|
36
|
+
image_url: receipt.contents.json.image_url,
|
|
37
|
+
last_acc_reward_per_xtoken: {
|
|
38
|
+
type: "unknown", // Assuming fixed value
|
|
39
|
+
fields: {
|
|
40
|
+
contents: receipt.contents.json.last_acc_reward_per_xtoken.contents.map((item) => ({
|
|
41
|
+
type: "unknown", // Assuming fixed value
|
|
42
|
+
fields: {
|
|
43
|
+
value: item.value,
|
|
44
|
+
key: {
|
|
45
|
+
type: "unknown", // Assuming fixed value
|
|
46
|
+
fields: {
|
|
47
|
+
name: item.key.name,
|
|
48
|
+
},
|
|
49
|
+
},
|
|
50
|
+
},
|
|
51
|
+
})),
|
|
52
|
+
},
|
|
53
|
+
},
|
|
54
|
+
locked_balance: receipt.contents.json.locked_balance
|
|
55
|
+
? {
|
|
56
|
+
type: "unknown", // Assuming fixed value
|
|
57
|
+
fields: {
|
|
58
|
+
head: receipt.contents.json.locked_balance.head,
|
|
59
|
+
id: { id: receipt.contents.json.locked_balance.id },
|
|
60
|
+
size: receipt.contents.json.locked_balance.size,
|
|
61
|
+
tail: receipt.contents.json.locked_balance.tail,
|
|
62
|
+
},
|
|
63
|
+
}
|
|
64
|
+
: undefined,
|
|
65
|
+
name: receipt.contents.json.name,
|
|
66
|
+
owner: receipt.contents.json.owner,
|
|
67
|
+
pending_rewards: {
|
|
68
|
+
type: "unknown", // Assuming fixed value
|
|
69
|
+
fields: {
|
|
70
|
+
contents: receipt.contents.json.pending_rewards.contents.map((item) => ({
|
|
71
|
+
type: "unknown", // Assuming fixed value
|
|
72
|
+
fields: {
|
|
73
|
+
key: {
|
|
74
|
+
type: "unknown", // Assuming fixed value
|
|
75
|
+
fields: {
|
|
76
|
+
name: item.key.name,
|
|
77
|
+
},
|
|
78
|
+
},
|
|
79
|
+
value: item.value,
|
|
80
|
+
},
|
|
81
|
+
})),
|
|
82
|
+
},
|
|
83
|
+
},
|
|
84
|
+
pool_id: receipt.contents.json.pool_id,
|
|
85
|
+
xTokenBalance: receipt.contents.json.xTokenBalance,
|
|
86
|
+
unlocked_xtokens: receipt.contents.json.unlocked_xtokens ?? undefined,
|
|
87
|
+
},
|
|
88
|
+
},
|
|
89
|
+
};
|
|
90
|
+
});
|
|
91
|
+
return res;
|
|
92
|
+
}
|
|
93
|
+
const receiptsCache = new simpleCache_js_1.SimpleCache(3600000);
|
|
94
|
+
const receiptsPromiseCache = new simpleCache_js_1.SimpleCache(3600000);
|
|
95
|
+
async function getMultiReceipts(address) {
|
|
96
|
+
try {
|
|
97
|
+
const receiptMap = await (0, index_js_1.fetchMultiReceipts)(address);
|
|
98
|
+
for (const pool of Object.keys(maps_js_1.poolInfo)) {
|
|
99
|
+
const cacheKey = `getReceipts-${maps_js_1.poolInfo[pool].receiptName}-${address}`;
|
|
100
|
+
let receipt = [];
|
|
101
|
+
if (receiptMap.has(maps_js_1.poolInfo[pool].receiptName)) {
|
|
102
|
+
receipt = convertReceiptGQLToReceipt(receiptMap.get(maps_js_1.poolInfo[pool].receiptName));
|
|
103
|
+
}
|
|
104
|
+
receiptsCache.set(cacheKey, receipt);
|
|
105
|
+
}
|
|
106
|
+
}
|
|
107
|
+
catch (error) {
|
|
108
|
+
console.error("Error fetching receipts from graphQL:", error);
|
|
109
|
+
// get receipts individually
|
|
110
|
+
const pools = Object.keys(maps_js_1.poolInfo);
|
|
111
|
+
const receiptPromises = pools.map((pool) => {
|
|
112
|
+
return getReceipts(pool, address, true);
|
|
113
|
+
});
|
|
114
|
+
const receipts = await Promise.all(receiptPromises);
|
|
115
|
+
receipts.forEach((receipt, index) => {
|
|
116
|
+
const cacheKey = `getReceipts-${maps_js_1.poolInfo[pools[index]].receiptName}-${address}`;
|
|
117
|
+
receiptsCache.set(cacheKey, receipt);
|
|
118
|
+
});
|
|
119
|
+
}
|
|
120
|
+
}
|
|
121
|
+
async function getReceipts(poolName, address, ignoreCache) {
|
|
22
122
|
const suiClient = (0, client_js_1.getSuiClient)();
|
|
23
|
-
const receiptsCacheKey = `getReceipts-${poolName}-${address}`;
|
|
123
|
+
const receiptsCacheKey = `getReceipts-${maps_js_1.poolInfo[poolName].receiptName}-${address}`;
|
|
24
124
|
if (ignoreCache) {
|
|
25
125
|
receiptsCache.delete(receiptsCacheKey);
|
|
26
126
|
receiptsPromiseCache.delete(receiptsCacheKey);
|
|
@@ -29,16 +129,16 @@ async function getReceipts(poolName, address, ignoreCache = false) {
|
|
|
29
129
|
if (cachedResponse) {
|
|
30
130
|
return cachedResponse;
|
|
31
131
|
}
|
|
132
|
+
//
|
|
32
133
|
const nfts = [];
|
|
33
|
-
if (maps_js_1.poolInfo[poolName].receiptType
|
|
134
|
+
if (maps_js_1.poolInfo[poolName].receiptType == "") {
|
|
34
135
|
return nfts;
|
|
35
136
|
}
|
|
36
137
|
let cachedPromise = receiptsPromiseCache.get(receiptsCacheKey);
|
|
37
138
|
if (!cachedPromise) {
|
|
38
139
|
cachedPromise = (async () => {
|
|
39
|
-
// const first_package =
|
|
140
|
+
// const first_package = getConf().ALPHA_FIRST_PACKAGE_ID;
|
|
40
141
|
let currentCursor = null;
|
|
41
|
-
/* eslint-disable-next-line no-constant-condition */
|
|
42
142
|
while (true) {
|
|
43
143
|
const paginatedObjects = await suiClient.getOwnedObjects({
|
|
44
144
|
owner: address,
|
|
@@ -48,7 +148,6 @@ async function getReceipts(poolName, address, ignoreCache = false) {
|
|
|
48
148
|
StructType: maps_js_1.poolInfo[poolName].receiptType,
|
|
49
149
|
},
|
|
50
150
|
options: {
|
|
51
|
-
showType: true,
|
|
52
151
|
showContent: true,
|
|
53
152
|
},
|
|
54
153
|
});
|
|
@@ -67,6 +166,7 @@ async function getReceipts(poolName, address, ignoreCache = false) {
|
|
|
67
166
|
}
|
|
68
167
|
else {
|
|
69
168
|
// No more pages available
|
|
169
|
+
// console.log("No more receipts available.");
|
|
70
170
|
break;
|
|
71
171
|
}
|
|
72
172
|
}
|
|
@@ -74,90 +174,75 @@ async function getReceipts(poolName, address, ignoreCache = false) {
|
|
|
74
174
|
receiptsPromiseCache.delete(receiptsCacheKey);
|
|
75
175
|
return nfts;
|
|
76
176
|
})().catch((error) => {
|
|
77
|
-
//
|
|
78
|
-
|
|
79
|
-
return nfts;
|
|
80
|
-
}
|
|
81
|
-
else {
|
|
82
|
-
receiptsPromiseCache.delete(receiptsCacheKey); // Remove the promise from cache
|
|
83
|
-
throw error;
|
|
84
|
-
}
|
|
177
|
+
receiptsPromiseCache.delete(receiptsCacheKey); // Remove the promise from cache
|
|
178
|
+
throw error;
|
|
85
179
|
});
|
|
180
|
+
// const data = await cachedPromise;
|
|
181
|
+
// console.log("received cached data", data);
|
|
86
182
|
receiptsPromiseCache.set(receiptsCacheKey, cachedPromise);
|
|
87
183
|
}
|
|
88
184
|
return cachedPromise;
|
|
89
185
|
}
|
|
90
|
-
|
|
91
|
-
async function getPoolExchangeRate(poolName, ignoreCache = false) {
|
|
92
|
-
const poolExchangeRateCacheKey = `getPoolExchangeRate-${poolName}`;
|
|
93
|
-
if (ignoreCache) {
|
|
94
|
-
poolExchangeRateCache.delete(poolExchangeRateCacheKey);
|
|
95
|
-
}
|
|
96
|
-
const cachedResponse = poolExchangeRateCache.get(poolExchangeRateCacheKey);
|
|
97
|
-
if (cachedResponse) {
|
|
98
|
-
return cachedResponse;
|
|
99
|
-
}
|
|
186
|
+
async function getPoolExchangeRate(poolName, ignoreCache) {
|
|
100
187
|
let pool;
|
|
101
188
|
try {
|
|
102
|
-
|
|
103
|
-
pool = await getPool("ALPHA");
|
|
104
|
-
}
|
|
105
|
-
else if (poolName === "ALPHA-SUI" ||
|
|
106
|
-
poolName === "USDT-WUSDC" ||
|
|
107
|
-
poolName === "USDY-WUSDC" ||
|
|
108
|
-
poolName === "HASUI-SUI" ||
|
|
109
|
-
poolName === "WUSDC-SUI" ||
|
|
110
|
-
poolName === "WETH-WUSDC") {
|
|
111
|
-
pool = await getPool(poolName);
|
|
112
|
-
}
|
|
113
|
-
else {
|
|
114
|
-
pool = await getPool(poolName);
|
|
115
|
-
}
|
|
189
|
+
pool = await getPool(poolName, ignoreCache);
|
|
116
190
|
if (pool) {
|
|
117
191
|
const xTokenSupply = new decimal_js_1.Decimal(pool.content.fields.xTokenSupply);
|
|
118
192
|
let tokensInvested = new decimal_js_1.Decimal(pool.content.fields.tokensInvested);
|
|
119
193
|
if (poolName == "ALPHA") {
|
|
120
194
|
tokensInvested = new decimal_js_1.Decimal(pool.content.fields.alpha_bal);
|
|
121
195
|
}
|
|
196
|
+
else if (maps_js_1.poolInfo[poolName].parentProtocolName == "CETUS") {
|
|
197
|
+
const investor = (await getInvestor(poolName, ignoreCache));
|
|
198
|
+
if (!investor) {
|
|
199
|
+
throw new Error(`couldnt fetch investor object for pool: ${poolName}`);
|
|
200
|
+
}
|
|
201
|
+
tokensInvested = new decimal_js_1.Decimal(pool.content.fields.tokensInvested);
|
|
202
|
+
}
|
|
122
203
|
// Check for division by zero
|
|
123
204
|
if (xTokenSupply.eq(0)) {
|
|
124
205
|
console.error("Division by zero error: tokensInvested is zero.");
|
|
125
206
|
return undefined;
|
|
126
207
|
}
|
|
127
208
|
const poolExchangeRate = tokensInvested.div(xTokenSupply);
|
|
128
|
-
poolExchangeRateCache.set(poolExchangeRateCacheKey, poolExchangeRate);
|
|
129
209
|
return poolExchangeRate;
|
|
130
210
|
}
|
|
131
211
|
}
|
|
132
212
|
catch (e) {
|
|
133
|
-
console.
|
|
213
|
+
console.log(`getPoolExchangeRate failed for poolName: ${poolName}, with error ${e}`);
|
|
134
214
|
}
|
|
135
215
|
return undefined;
|
|
136
216
|
}
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
217
|
+
const poolCache = new simpleCache_js_1.SimpleCache();
|
|
218
|
+
const poolPromiseCache = new simpleCache_js_1.SimpleCache();
|
|
219
|
+
async function getMultiPool() {
|
|
220
|
+
let pools = Object.keys(maps_js_1.poolInfo);
|
|
221
|
+
pools = pools.filter((pool) => {
|
|
222
|
+
return maps_js_1.poolInfo[pool].poolId !== "";
|
|
223
|
+
});
|
|
224
|
+
const poolIds = pools.map((pool) => {
|
|
225
|
+
return maps_js_1.poolInfo[pool].poolId;
|
|
226
|
+
});
|
|
227
|
+
try {
|
|
228
|
+
const o = await (0, client_js_1.getSuiClient)().multiGetObjects({
|
|
229
|
+
ids: poolIds,
|
|
230
|
+
options: {
|
|
231
|
+
showContent: true,
|
|
232
|
+
},
|
|
233
|
+
});
|
|
234
|
+
for (let i = 0; i < pools.length; i = i + 1) {
|
|
235
|
+
const poolData = o[i].data;
|
|
236
|
+
const cacheKey = `pool_${maps_js_1.poolInfo[pools[i]].poolId}`;
|
|
237
|
+
poolCache.set(cacheKey, poolData);
|
|
238
|
+
}
|
|
153
239
|
}
|
|
154
|
-
|
|
155
|
-
|
|
240
|
+
catch (e) {
|
|
241
|
+
console.error(`Error getting multiPools`);
|
|
156
242
|
}
|
|
157
243
|
}
|
|
158
|
-
|
|
159
|
-
const
|
|
160
|
-
async function getPool(poolName, ignoreCache = false) {
|
|
244
|
+
async function getPool(poolName, ignoreCache) {
|
|
245
|
+
const suiClient = (0, client_js_1.getSuiClient)();
|
|
161
246
|
const cacheKey = `pool_${maps_js_1.poolInfo[poolName.toUpperCase()].poolId}`;
|
|
162
247
|
if (ignoreCache) {
|
|
163
248
|
poolCache.delete(cacheKey);
|
|
@@ -175,7 +260,6 @@ async function getPool(poolName, ignoreCache = false) {
|
|
|
175
260
|
}
|
|
176
261
|
// If not, create a new promise and cache it
|
|
177
262
|
poolPromise = (async () => {
|
|
178
|
-
const suiClient = (0, client_js_1.getSuiClient)();
|
|
179
263
|
try {
|
|
180
264
|
const o = await suiClient.getObject({
|
|
181
265
|
id: maps_js_1.poolInfo[poolName].poolId,
|
|
@@ -203,8 +287,34 @@ async function getPool(poolName, ignoreCache = false) {
|
|
|
203
287
|
}
|
|
204
288
|
const cetusPoolCache = new simpleCache_js_1.SimpleCache();
|
|
205
289
|
const cetusPoolPromiseCache = new simpleCache_js_1.SimpleCache();
|
|
206
|
-
async function
|
|
207
|
-
|
|
290
|
+
async function getMultiParentPool() {
|
|
291
|
+
let pools = Object.keys(maps_js_1.poolInfo);
|
|
292
|
+
pools = pools.filter((pool) => {
|
|
293
|
+
return maps_js_1.poolInfo[pool].poolId !== "";
|
|
294
|
+
});
|
|
295
|
+
const poolIds = pools.map((pool) => {
|
|
296
|
+
return maps_js_1.poolInfo[pool].parentPoolId;
|
|
297
|
+
});
|
|
298
|
+
try {
|
|
299
|
+
const o = await (0, client_js_1.getSuiClient)().multiGetObjects({
|
|
300
|
+
ids: poolIds,
|
|
301
|
+
options: {
|
|
302
|
+
showContent: true,
|
|
303
|
+
},
|
|
304
|
+
});
|
|
305
|
+
for (let i = 0; i < pools.length; i = i + 1) {
|
|
306
|
+
const poolData = o[i].data;
|
|
307
|
+
const cacheKey = `pool_${maps_js_1.poolInfo[pools[i]].parentPoolId}`;
|
|
308
|
+
cetusPoolCache.set(cacheKey, poolData);
|
|
309
|
+
}
|
|
310
|
+
}
|
|
311
|
+
catch (e) {
|
|
312
|
+
console.error(`Error getting multiPools`);
|
|
313
|
+
}
|
|
314
|
+
}
|
|
315
|
+
async function getParentPool(poolName, ignoreCache) {
|
|
316
|
+
const suiClient = (0, client_js_1.getSuiClient)();
|
|
317
|
+
const cacheKey = `pool_${index_js_1.cetusPoolMap[poolName.toUpperCase()]}`;
|
|
208
318
|
if (ignoreCache) {
|
|
209
319
|
cetusPoolCache.delete(cacheKey);
|
|
210
320
|
cetusPoolPromiseCache.delete(cacheKey);
|
|
@@ -222,9 +332,13 @@ async function getCetusPool(poolName, ignoreCache = false) {
|
|
|
222
332
|
// If not, create a new promise and cache it
|
|
223
333
|
cetusPoolPromise = (async () => {
|
|
224
334
|
try {
|
|
225
|
-
const
|
|
335
|
+
const id = maps_js_1.poolInfo[poolName]
|
|
336
|
+
? maps_js_1.poolInfo[poolName].parentPoolId
|
|
337
|
+
: index_js_1.cetusPoolMap[poolName]
|
|
338
|
+
? index_js_1.cetusPoolMap[poolName]
|
|
339
|
+
: index_js_1.bluefinPoolMap[poolName];
|
|
226
340
|
const o = await suiClient.getObject({
|
|
227
|
-
id:
|
|
341
|
+
id: id,
|
|
228
342
|
options: {
|
|
229
343
|
showContent: true,
|
|
230
344
|
},
|
|
@@ -236,7 +350,6 @@ async function getCetusPool(poolName, ignoreCache = false) {
|
|
|
236
350
|
}
|
|
237
351
|
catch (e) {
|
|
238
352
|
console.error(`getCetusPool failed for poolName: ${poolName}`);
|
|
239
|
-
console.error(e);
|
|
240
353
|
return undefined;
|
|
241
354
|
}
|
|
242
355
|
finally {
|
|
@@ -248,176 +361,147 @@ async function getCetusPool(poolName, ignoreCache = false) {
|
|
|
248
361
|
cetusPoolPromiseCache.set(cacheKey, cetusPoolPromise);
|
|
249
362
|
return cetusPoolPromise;
|
|
250
363
|
}
|
|
251
|
-
const
|
|
252
|
-
const
|
|
253
|
-
async function
|
|
364
|
+
const investorCache = new simpleCache_js_1.SimpleCache();
|
|
365
|
+
const investorPromiseCache = new simpleCache_js_1.SimpleCache();
|
|
366
|
+
async function getMultiInvestor() {
|
|
367
|
+
let pools = Object.keys(maps_js_1.poolInfo);
|
|
368
|
+
pools = pools.filter((pool) => {
|
|
369
|
+
return maps_js_1.poolInfo[pool].investorId !== "";
|
|
370
|
+
});
|
|
371
|
+
const investorIds = pools.map((pool) => {
|
|
372
|
+
return maps_js_1.poolInfo[pool].investorId;
|
|
373
|
+
});
|
|
374
|
+
try {
|
|
375
|
+
const o = await (0, client_js_1.getSuiClient)().multiGetObjects({
|
|
376
|
+
ids: investorIds,
|
|
377
|
+
options: {
|
|
378
|
+
showContent: true,
|
|
379
|
+
},
|
|
380
|
+
});
|
|
381
|
+
for (let i = 0; i < pools.length; i = i + 1) {
|
|
382
|
+
const investorData = o[i].data;
|
|
383
|
+
const cacheKey = `investor_${maps_js_1.poolInfo[pools[i]].investorId}`;
|
|
384
|
+
investorCache.set(cacheKey, investorData);
|
|
385
|
+
}
|
|
386
|
+
}
|
|
387
|
+
catch (e) {
|
|
388
|
+
console.error(`Error getting multiPools`);
|
|
389
|
+
}
|
|
390
|
+
}
|
|
391
|
+
async function getInvestor(poolName, ignoreCache) {
|
|
392
|
+
const suiClient = (0, client_js_1.getSuiClient)();
|
|
254
393
|
const cacheKey = `investor_${maps_js_1.poolInfo[poolName.toUpperCase()].investorId}`;
|
|
255
394
|
if (ignoreCache) {
|
|
256
|
-
|
|
257
|
-
|
|
395
|
+
investorCache.delete(cacheKey);
|
|
396
|
+
investorPromiseCache.delete(cacheKey);
|
|
258
397
|
}
|
|
259
398
|
// Check if the investor is already in the cache
|
|
260
|
-
const cachedInvestor =
|
|
399
|
+
const cachedInvestor = investorCache.get(cacheKey);
|
|
261
400
|
if (cachedInvestor) {
|
|
262
401
|
return cachedInvestor;
|
|
263
402
|
}
|
|
264
403
|
// Check if there is already a promise in the cache
|
|
265
|
-
let cetusInvestorPromise =
|
|
404
|
+
let cetusInvestorPromise = investorPromiseCache.get(cacheKey);
|
|
266
405
|
if (cetusInvestorPromise) {
|
|
267
406
|
return cetusInvestorPromise;
|
|
268
407
|
}
|
|
269
408
|
// If not, create a new promise and cache it
|
|
270
409
|
cetusInvestorPromise = (async () => {
|
|
271
410
|
try {
|
|
272
|
-
const suiClient = (0, client_js_1.getSuiClient)();
|
|
273
411
|
const o = await suiClient.getObject({
|
|
274
412
|
id: maps_js_1.poolInfo[poolName.toUpperCase()].investorId,
|
|
275
413
|
options: {
|
|
276
414
|
showContent: true,
|
|
277
415
|
},
|
|
278
416
|
});
|
|
279
|
-
|
|
417
|
+
let cetusInvestor;
|
|
418
|
+
if (maps_js_1.poolInfo[poolName].parentProtocolName == "NAVI") {
|
|
419
|
+
cetusInvestor = o.data;
|
|
420
|
+
}
|
|
421
|
+
else if (maps_js_1.poolInfo[poolName].parentProtocolName == "BUCKET") {
|
|
422
|
+
cetusInvestor = o.data;
|
|
423
|
+
}
|
|
424
|
+
else if (maps_js_1.poolInfo[poolName].parentProtocolName == "BLUEFIN") {
|
|
425
|
+
cetusInvestor = o.data;
|
|
426
|
+
}
|
|
427
|
+
else {
|
|
428
|
+
cetusInvestor = o.data;
|
|
429
|
+
}
|
|
280
430
|
// Cache the investor object
|
|
281
|
-
|
|
282
|
-
return
|
|
431
|
+
investorCache.set(cacheKey, cetusInvestor);
|
|
432
|
+
return cetusInvestor;
|
|
283
433
|
}
|
|
284
434
|
catch (e) {
|
|
285
|
-
console.error(`
|
|
435
|
+
console.error(`getInvestor failed for pool: ${poolName}`);
|
|
286
436
|
return undefined;
|
|
287
437
|
}
|
|
288
438
|
finally {
|
|
289
439
|
// Remove the promise from the cache after it resolves
|
|
290
|
-
|
|
440
|
+
investorPromiseCache.delete(cacheKey);
|
|
291
441
|
}
|
|
292
442
|
})();
|
|
293
443
|
// Cache the promise
|
|
294
|
-
|
|
444
|
+
investorPromiseCache.set(cacheKey, cetusInvestorPromise);
|
|
295
445
|
return cetusInvestorPromise;
|
|
296
446
|
}
|
|
297
|
-
|
|
298
|
-
const
|
|
299
|
-
|
|
300
|
-
|
|
301
|
-
|
|
302
|
-
|
|
303
|
-
naviInvestorPromiseCache.delete(cacheKey);
|
|
304
|
-
}
|
|
305
|
-
// Check if the investor is already in the cache
|
|
306
|
-
const cachedInvestor = naviInvestorCache.get(cacheKey);
|
|
307
|
-
if (cachedInvestor) {
|
|
308
|
-
return cachedInvestor;
|
|
309
|
-
}
|
|
310
|
-
// Check if there is already a promise in the cache
|
|
311
|
-
let naviInvestorPromise = naviInvestorPromiseCache.get(cacheKey);
|
|
312
|
-
if (naviInvestorPromise) {
|
|
313
|
-
return naviInvestorPromise;
|
|
314
|
-
}
|
|
315
|
-
// If not, create a new promise and cache it
|
|
316
|
-
naviInvestorPromise = (async () => {
|
|
317
|
-
try {
|
|
318
|
-
const suiClient = (0, client_js_1.getSuiClient)();
|
|
319
|
-
const o = await suiClient.getObject({
|
|
320
|
-
id: maps_js_1.poolInfo[poolName.toUpperCase()].investorId,
|
|
321
|
-
options: {
|
|
322
|
-
showContent: true,
|
|
323
|
-
},
|
|
324
|
-
});
|
|
325
|
-
const navi_investor = o.data;
|
|
326
|
-
// Cache the investor object
|
|
327
|
-
naviInvestorCache.set(cacheKey, navi_investor);
|
|
328
|
-
return navi_investor;
|
|
329
|
-
}
|
|
330
|
-
catch (e) {
|
|
331
|
-
console.error(`getNaviInvestor failed for pool: ${poolName}`);
|
|
332
|
-
return undefined;
|
|
333
|
-
}
|
|
334
|
-
finally {
|
|
335
|
-
// Remove the promise from the cache after it resolves
|
|
336
|
-
naviInvestorPromiseCache.delete(cacheKey);
|
|
447
|
+
async function fetchVoloExchangeRate() {
|
|
448
|
+
const apiUrl = "https://open-api.naviprotocol.io/api/volo/stats";
|
|
449
|
+
const NaviVoloDetails = await fetch(apiUrl)
|
|
450
|
+
.then(async (response) => {
|
|
451
|
+
if (!response.ok) {
|
|
452
|
+
throw new Error(`HTTP error! status: ${response.status}`);
|
|
337
453
|
}
|
|
338
|
-
|
|
339
|
-
|
|
340
|
-
|
|
341
|
-
|
|
454
|
+
const data = (await response.json()); // Parse the JSON response
|
|
455
|
+
return data;
|
|
456
|
+
})
|
|
457
|
+
.catch((error) => {
|
|
458
|
+
console.log("failed to fetch Navi-volo details", error);
|
|
459
|
+
throw error;
|
|
460
|
+
});
|
|
461
|
+
return NaviVoloDetails;
|
|
342
462
|
}
|
|
343
|
-
|
|
344
|
-
const
|
|
345
|
-
|
|
346
|
-
const
|
|
347
|
-
let
|
|
348
|
-
|
|
349
|
-
|
|
350
|
-
|
|
463
|
+
async function getCoinAmountsFromLiquidity(poolName, liquidity, ignoreCache) {
|
|
464
|
+
const clmmPool = await getParentPool(poolName, ignoreCache);
|
|
465
|
+
const investor = (await getInvestor(poolName, ignoreCache));
|
|
466
|
+
const upper_bound = 443636;
|
|
467
|
+
let lower_tick = Number(investor.content.fields.lower_tick);
|
|
468
|
+
let upper_tick = Number(investor.content.fields.upper_tick);
|
|
469
|
+
if (lower_tick > upper_bound) {
|
|
470
|
+
lower_tick = -~(lower_tick - 1);
|
|
351
471
|
}
|
|
352
|
-
|
|
353
|
-
|
|
354
|
-
|
|
472
|
+
if (upper_tick > upper_bound) {
|
|
473
|
+
upper_tick = -~(upper_tick - 1);
|
|
474
|
+
}
|
|
475
|
+
if (clmmPool) {
|
|
476
|
+
const liquidityInt = Math.floor(parseFloat(liquidity));
|
|
477
|
+
const coin_amounts = cetus_sui_clmm_sdk_1.ClmmPoolUtil.getCoinAmountFromLiquidity(new bn_js_1.default(`${liquidityInt}`), new bn_js_1.default(clmmPool.content.fields.current_sqrt_price), cetus_sui_clmm_sdk_1.TickMath.tickIndexToSqrtPriceX64(lower_tick), cetus_sui_clmm_sdk_1.TickMath.tickIndexToSqrtPriceX64(upper_tick), true);
|
|
478
|
+
return [coin_amounts.coinA.toString(), coin_amounts.coinB.toString()];
|
|
355
479
|
}
|
|
356
480
|
else {
|
|
357
|
-
|
|
358
|
-
if (!cachedPromise) {
|
|
359
|
-
cachedPromise = fetch(apiUrl)
|
|
360
|
-
.then(async (response) => {
|
|
361
|
-
if (!response.ok) {
|
|
362
|
-
throw new Error(`HTTP error! status: ${response.status}`);
|
|
363
|
-
}
|
|
364
|
-
const data = (await response.json()); // Parse the JSON response
|
|
365
|
-
naviVoloExchangeRateCache.set(apiUrl, data); // Cache the response
|
|
366
|
-
naviVoloExchangeRatePromiseCache.delete(apiUrl); // Remove the promise from the cache
|
|
367
|
-
return data;
|
|
368
|
-
})
|
|
369
|
-
.catch((error) => {
|
|
370
|
-
naviVoloExchangeRatePromiseCache.delete(apiUrl); // Ensure the promise is removed on error
|
|
371
|
-
throw error;
|
|
372
|
-
});
|
|
373
|
-
naviVoloExchangeRatePromiseCache.set(apiUrl, cachedPromise);
|
|
374
|
-
NaviVoloDetails = await cachedPromise;
|
|
375
|
-
}
|
|
376
|
-
return cachedPromise;
|
|
481
|
+
return ["0", "0"];
|
|
377
482
|
}
|
|
378
|
-
return NaviVoloDetails;
|
|
379
483
|
}
|
|
380
|
-
async function multiGetNaviInvestor(poolNames
|
|
484
|
+
async function multiGetNaviInvestor(poolNames) {
|
|
381
485
|
const results = {};
|
|
382
|
-
const
|
|
383
|
-
const missingPoolNames = [];
|
|
486
|
+
const poolInvestorIds = [];
|
|
384
487
|
for (const poolName of poolNames) {
|
|
385
|
-
|
|
386
|
-
if (ignoreCache) {
|
|
387
|
-
naviInvestorCache.delete(cacheKey);
|
|
388
|
-
naviInvestorPromiseCache.delete(cacheKey);
|
|
389
|
-
}
|
|
390
|
-
// Check if the investor is already cached
|
|
391
|
-
const cachedInvestor = naviInvestorCache.get(cacheKey);
|
|
392
|
-
if (cachedInvestor) {
|
|
393
|
-
results[poolName] = cachedInvestor;
|
|
394
|
-
continue;
|
|
395
|
-
}
|
|
396
|
-
else {
|
|
397
|
-
// Add to missing list if not in cache
|
|
398
|
-
if (maps_js_1.poolInfo[poolName.toUpperCase()].investorId) {
|
|
399
|
-
missingPoolNames.push(poolName);
|
|
400
|
-
missingPoolInvestorIds.push(maps_js_1.poolInfo[poolName.toUpperCase()].investorId);
|
|
401
|
-
}
|
|
402
|
-
}
|
|
488
|
+
poolInvestorIds.push(maps_js_1.poolInfo[poolName.toUpperCase()].investorId);
|
|
403
489
|
}
|
|
404
490
|
try {
|
|
405
491
|
const suiClient = (0, client_js_1.getSuiClient)();
|
|
406
492
|
const objects = await suiClient.multiGetObjects({
|
|
407
|
-
ids:
|
|
493
|
+
ids: poolInvestorIds,
|
|
408
494
|
options: { showContent: true },
|
|
409
495
|
});
|
|
410
496
|
for (let i = 0; i < objects.length; i++) {
|
|
411
497
|
const investor = objects[i].data;
|
|
412
|
-
|
|
413
|
-
naviInvestorCache.set(cacheKey, investor);
|
|
414
|
-
results[missingPoolNames[i]] = investor;
|
|
498
|
+
results[poolNames[i]] = investor;
|
|
415
499
|
}
|
|
416
500
|
return results;
|
|
417
501
|
}
|
|
418
502
|
catch (err) {
|
|
419
503
|
//improve
|
|
420
|
-
console.error("multiGetNaviInvestor failed for poolNames: ",
|
|
504
|
+
console.error("multiGetNaviInvestor failed for poolNames: ", poolNames.join(", "));
|
|
421
505
|
throw err;
|
|
422
506
|
}
|
|
423
507
|
}
|