@compass-labs/widgets 0.1.5 → 0.1.6
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/index.d.mts +13 -5
- package/dist/index.d.ts +13 -5
- package/dist/index.js +45 -20
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +45 -20
- package/dist/index.mjs.map +1 -1
- package/dist/server/index.js +68 -0
- package/dist/server/index.js.map +1 -1
- package/dist/server/index.mjs +68 -0
- package/dist/server/index.mjs.map +1 -1
- package/package.json +1 -1
package/dist/index.mjs
CHANGED
|
@@ -7,7 +7,7 @@ import { Wallet, LogOut, X, ChevronDown, AlertCircle, ArrowRight, Loader2, Arrow
|
|
|
7
7
|
|
|
8
8
|
// src/provider/CompassProvider.tsx
|
|
9
9
|
var ApiContext = createContext(null);
|
|
10
|
-
function ApiProvider({ children, apiKey, serverURL }) {
|
|
10
|
+
function ApiProvider({ children, apiKey = "", serverURL }) {
|
|
11
11
|
const client = useMemo(() => {
|
|
12
12
|
return new CompassApiSDK({
|
|
13
13
|
apiKeyAuth: apiKey,
|
|
@@ -2910,7 +2910,6 @@ function VaultCard({
|
|
|
2910
2910
|
);
|
|
2911
2911
|
}
|
|
2912
2912
|
function useVaultsData(options = {}) {
|
|
2913
|
-
const { client } = useEmbeddableApi();
|
|
2914
2913
|
const { address } = useEmbeddableWallet();
|
|
2915
2914
|
const { chainId } = useChain();
|
|
2916
2915
|
const { sortBy = "apy_7d", assetFilter, minApy, minTvl } = options;
|
|
@@ -2918,14 +2917,19 @@ function useVaultsData(options = {}) {
|
|
|
2918
2917
|
queryKey: ["vaults", chainId, sortBy, assetFilter, minApy, minTvl],
|
|
2919
2918
|
queryFn: async () => {
|
|
2920
2919
|
const assetSymbol = assetFilter && assetFilter.length === 1 ? assetFilter[0] : void 0;
|
|
2921
|
-
const
|
|
2920
|
+
const params = new URLSearchParams({
|
|
2922
2921
|
chain: chainId,
|
|
2923
2922
|
orderBy: sortBy === "tvl" ? "tvl_usd" : sortBy,
|
|
2924
2923
|
direction: "desc",
|
|
2925
|
-
limit: 100,
|
|
2924
|
+
limit: "100",
|
|
2926
2925
|
...assetSymbol && { assetSymbol }
|
|
2927
2926
|
});
|
|
2928
|
-
|
|
2927
|
+
const response = await fetch(`/api/compass/vaults?${params}`);
|
|
2928
|
+
if (!response.ok) {
|
|
2929
|
+
throw new Error("Failed to fetch vaults");
|
|
2930
|
+
}
|
|
2931
|
+
const data = await response.json();
|
|
2932
|
+
let vaults = (data.vaults || []).map((v) => ({
|
|
2929
2933
|
vaultAddress: v.vaultAddress,
|
|
2930
2934
|
name: v.name || "Unknown Vault",
|
|
2931
2935
|
assetSymbol: v.assetSymbol || "UNKNOWN",
|
|
@@ -2959,11 +2963,16 @@ function useVaultsData(options = {}) {
|
|
|
2959
2963
|
queryKey: ["vaultPositions", chainId, address],
|
|
2960
2964
|
queryFn: async () => {
|
|
2961
2965
|
if (!address) return [];
|
|
2962
|
-
const
|
|
2966
|
+
const params = new URLSearchParams({
|
|
2963
2967
|
chain: chainId,
|
|
2964
2968
|
owner: address
|
|
2965
2969
|
});
|
|
2966
|
-
|
|
2970
|
+
const response = await fetch(`/api/compass/positions?${params}`);
|
|
2971
|
+
if (!response.ok) {
|
|
2972
|
+
throw new Error("Failed to fetch positions");
|
|
2973
|
+
}
|
|
2974
|
+
const data = await response.json();
|
|
2975
|
+
return (data.vaults || []).map((p) => ({
|
|
2967
2976
|
vaultAddress: p.vaultAddress,
|
|
2968
2977
|
balance: p.balance || "0",
|
|
2969
2978
|
pnl: p.pnl ? {
|
|
@@ -3244,17 +3253,19 @@ function VaultsList({
|
|
|
3244
3253
|
] });
|
|
3245
3254
|
}
|
|
3246
3255
|
function useAaveData(options = {}) {
|
|
3247
|
-
const { client } = useEmbeddableApi();
|
|
3248
3256
|
const { address } = useEmbeddableWallet();
|
|
3249
3257
|
const { chainId } = useChain();
|
|
3250
3258
|
const { assetFilter } = options;
|
|
3251
3259
|
const marketsQuery = useQuery({
|
|
3252
3260
|
queryKey: ["aaveMarkets", chainId, assetFilter],
|
|
3253
3261
|
queryFn: async () => {
|
|
3254
|
-
const
|
|
3255
|
-
|
|
3256
|
-
|
|
3257
|
-
|
|
3262
|
+
const params = new URLSearchParams({ chain: chainId });
|
|
3263
|
+
const response = await fetch(`/api/compass/aave/markets?${params}`);
|
|
3264
|
+
if (!response.ok) {
|
|
3265
|
+
throw new Error("Failed to fetch Aave markets");
|
|
3266
|
+
}
|
|
3267
|
+
const data = await response.json();
|
|
3268
|
+
const marketsDict = data.markets || {};
|
|
3258
3269
|
let markets = [];
|
|
3259
3270
|
for (const [symbol, tokenData] of Object.entries(marketsDict)) {
|
|
3260
3271
|
if (assetFilter && assetFilter.length > 0) {
|
|
@@ -3285,11 +3296,16 @@ function useAaveData(options = {}) {
|
|
|
3285
3296
|
queryKey: ["aavePositions", chainId, address],
|
|
3286
3297
|
queryFn: async () => {
|
|
3287
3298
|
if (!address) return [];
|
|
3288
|
-
const
|
|
3299
|
+
const params = new URLSearchParams({
|
|
3289
3300
|
chain: chainId,
|
|
3290
3301
|
owner: address
|
|
3291
3302
|
});
|
|
3292
|
-
|
|
3303
|
+
const response = await fetch(`/api/compass/positions?${params}`);
|
|
3304
|
+
if (!response.ok) {
|
|
3305
|
+
throw new Error("Failed to fetch positions");
|
|
3306
|
+
}
|
|
3307
|
+
const data = await response.json();
|
|
3308
|
+
return (data.aave || []).map((p) => ({
|
|
3293
3309
|
marketAddress: p.marketAddress || "",
|
|
3294
3310
|
reserveSymbol: p.reserveSymbol || "",
|
|
3295
3311
|
balance: p.balance || "0",
|
|
@@ -3530,7 +3546,6 @@ function AaveMarketsList({
|
|
|
3530
3546
|
] });
|
|
3531
3547
|
}
|
|
3532
3548
|
function usePendleData(options = {}) {
|
|
3533
|
-
const { client } = useEmbeddableApi();
|
|
3534
3549
|
const { address } = useEmbeddableWallet();
|
|
3535
3550
|
const { chainId } = useChain();
|
|
3536
3551
|
const { sortBy = "fixed_apy", assetFilter, minTvl } = options;
|
|
@@ -3539,15 +3554,20 @@ function usePendleData(options = {}) {
|
|
|
3539
3554
|
queryFn: async () => {
|
|
3540
3555
|
const underlyingSymbol = assetFilter && assetFilter.length === 1 ? assetFilter[0] : void 0;
|
|
3541
3556
|
const orderBy = sortBy === "tvl" ? "tvl_usd" : "implied_apy";
|
|
3542
|
-
const
|
|
3557
|
+
const params = new URLSearchParams({
|
|
3543
3558
|
chain: chainId,
|
|
3544
3559
|
orderBy,
|
|
3545
3560
|
direction: "desc",
|
|
3546
|
-
limit: 100,
|
|
3561
|
+
limit: "100",
|
|
3547
3562
|
...underlyingSymbol && { underlyingSymbol }
|
|
3548
3563
|
});
|
|
3564
|
+
const response = await fetch(`/api/compass/pendle/markets?${params}`);
|
|
3565
|
+
if (!response.ok) {
|
|
3566
|
+
throw new Error("Failed to fetch Pendle markets");
|
|
3567
|
+
}
|
|
3568
|
+
const data = await response.json();
|
|
3549
3569
|
const now = Date.now() / 1e3;
|
|
3550
|
-
let markets = (
|
|
3570
|
+
let markets = (data.markets || []).filter((m) => m.expiry && m.expiry > now).map((m) => ({
|
|
3551
3571
|
marketAddress: m.marketAddress || "",
|
|
3552
3572
|
ptAddress: m.ptAddress || "",
|
|
3553
3573
|
name: m.ptName || `PT-${m.underlyingSymbol || "UNKNOWN"}`,
|
|
@@ -3583,11 +3603,16 @@ function usePendleData(options = {}) {
|
|
|
3583
3603
|
queryKey: ["pendlePositions", chainId, address],
|
|
3584
3604
|
queryFn: async () => {
|
|
3585
3605
|
if (!address) return [];
|
|
3586
|
-
const
|
|
3606
|
+
const params = new URLSearchParams({
|
|
3587
3607
|
chain: chainId,
|
|
3588
3608
|
owner: address
|
|
3589
3609
|
});
|
|
3590
|
-
|
|
3610
|
+
const response = await fetch(`/api/compass/positions?${params}`);
|
|
3611
|
+
if (!response.ok) {
|
|
3612
|
+
throw new Error("Failed to fetch positions");
|
|
3613
|
+
}
|
|
3614
|
+
const data = await response.json();
|
|
3615
|
+
return (data.pendlePt || []).map((p) => ({
|
|
3591
3616
|
marketAddress: p.marketAddress || "",
|
|
3592
3617
|
balance: p.balance || "0",
|
|
3593
3618
|
pnl: p.pnl ? {
|