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