@upshiftfinance/sdk 0.1.0 → 0.2.0
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 +23 -23
- package/lib/adapters/sui/client.d.ts +83 -0
- package/lib/adapters/sui/client.js +216 -0
- package/lib/adapters/sui/constants.d.ts +32 -0
- package/lib/adapters/sui/constants.js +23 -1
- package/lib/adapters/sui/index.d.ts +4 -0
- package/lib/adapters/sui/index.js +4 -0
- package/lib/adapters/sui/targets.d.ts +171 -0
- package/lib/adapters/sui/targets.js +225 -0
- package/lib/core/analytics/version.d.ts +1 -1
- package/lib/core/analytics/version.js +1 -1
- package/lib/sdk.d.ts +21 -2
- package/lib/types/web3.d.ts +21 -2
- package/package.json +6 -5
- package/lib/adapters/sui/getters.d.ts +0 -24
- package/lib/adapters/sui/getters.js +0 -134
- package/lib/adapters/sui/transformer.d.ts +0 -10
- package/lib/adapters/sui/transformer.js +0 -115
- package/lib/adapters/sui/types.d.ts +0 -70
- package/lib/adapters/sui/types.js +0 -3
|
@@ -1,134 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.getEmberVaults = getEmberVaults;
|
|
4
|
-
exports.getEmberTVL = getEmberTVL;
|
|
5
|
-
const constants_1 = require("./constants");
|
|
6
|
-
const core_1 = require("../../core");
|
|
7
|
-
const cache_1 = require("../../core/cache");
|
|
8
|
-
const logger_1 = require("../../core/logger");
|
|
9
|
-
/**
|
|
10
|
-
* Hard ceiling on the Ember (Bluefin) vaults request. The endpoint is a
|
|
11
|
-
* third-party API awaited on the `getVaults` hot path; without a bound, a
|
|
12
|
-
* hung connection stalls every vault-list consumer indefinitely (the fetch
|
|
13
|
-
* options carry no signal and no timeout). Measured latency is 0.24–1.02s,
|
|
14
|
-
* so 5s is ~5× the observed worst case while still failing fast enough for
|
|
15
|
-
* callers racing `getVaults` against their own budgets.
|
|
16
|
-
*/
|
|
17
|
-
const EMBER_FETCH_TIMEOUT_MS = 5_000;
|
|
18
|
-
/**
|
|
19
|
-
* TTL for the cached Ember vaults payload. The set of active Ember vaults
|
|
20
|
-
* changes rarely (the SDK additionally filters it to a hardcoded allowlist),
|
|
21
|
-
* so 5 minutes matches the freshness of the other list-shaped caches without
|
|
22
|
-
* letting a stale payload outlive a delisting for long.
|
|
23
|
-
*/
|
|
24
|
-
const EMBER_CACHE_TTL_MS = 5 * 60 * 1000;
|
|
25
|
-
/**
|
|
26
|
-
* GET an Ember endpoint as a JSON array, with the timeout + cache both Ember
|
|
27
|
-
* getters share.
|
|
28
|
-
*
|
|
29
|
-
* Why: `getEmberVaults` and `getEmberTVL` hit the same third-party API from
|
|
30
|
-
* the same hot paths, but only the former was bounded and cached — a hung TVL
|
|
31
|
-
* request stalled callers indefinitely. Centralising the plumbing keeps the
|
|
32
|
-
* two from drifting again.
|
|
33
|
-
*
|
|
34
|
-
* - Cached for {@link EMBER_CACHE_TTL_MS}, keyed by `cacheKey` (callers embed
|
|
35
|
-
* the full URL so different query options cache independently). Only
|
|
36
|
-
* successful array payloads are cached; failures are never cached.
|
|
37
|
-
* - Aborted after {@link EMBER_FETCH_TIMEOUT_MS}. AbortController (not
|
|
38
|
-
* AbortSignal.timeout) for browser + older-Node parity. The timer stays armed
|
|
39
|
-
* through the body read: `fetch` resolves as soon as headers arrive, so
|
|
40
|
-
* clearing it there would leave a stalled `json()` unbounded — the exact
|
|
41
|
-
* hang the ceiling exists to prevent.
|
|
42
|
-
*
|
|
43
|
-
* @param cacheKey - Shared-LRU key for this request.
|
|
44
|
-
* @param url - Fully-qualified Ember URL (query string included).
|
|
45
|
-
* @returns The parsed array, or `[]` when the endpoint returns a non-array.
|
|
46
|
-
* @throws On non-2xx responses, network failure, or timeout (AbortError) —
|
|
47
|
-
* callers own the fail-tolerant fallback.
|
|
48
|
-
*/
|
|
49
|
-
async function fetchEmberArray(cacheKey, url) {
|
|
50
|
-
// The shared LRU is constructed with `allowStale: true`; opt out here so a
|
|
51
|
-
// payload past its TTL is refetched rather than served one last time —
|
|
52
|
-
// keeping the 5-minute bound above an exact contract.
|
|
53
|
-
const cached = cache_1.CACHE.get(cacheKey, { allowStale: false });
|
|
54
|
-
if (cached)
|
|
55
|
-
return cached;
|
|
56
|
-
const controller = new AbortController();
|
|
57
|
-
const timer = setTimeout(() => controller.abort(), EMBER_FETCH_TIMEOUT_MS);
|
|
58
|
-
let data;
|
|
59
|
-
try {
|
|
60
|
-
const response = await fetch(url, {
|
|
61
|
-
...core_1.DEFAULT_FETCH_OPTIONS,
|
|
62
|
-
signal: controller.signal,
|
|
63
|
-
});
|
|
64
|
-
if (!response.ok) {
|
|
65
|
-
throw new Error(`HTTP error! status: ${response.status}`);
|
|
66
|
-
}
|
|
67
|
-
data = await response.json();
|
|
68
|
-
}
|
|
69
|
-
finally {
|
|
70
|
-
clearTimeout(timer);
|
|
71
|
-
}
|
|
72
|
-
const rows = Array.isArray(data) ? data : [];
|
|
73
|
-
cache_1.CACHE.set(cacheKey, rows, { ttl: EMBER_CACHE_TTL_MS });
|
|
74
|
-
return rows;
|
|
75
|
-
}
|
|
76
|
-
/**
|
|
77
|
-
* Fetch Ember vaults from API.
|
|
78
|
-
*
|
|
79
|
-
* Results are cached for {@link EMBER_CACHE_TTL_MS} (keyed by the full request
|
|
80
|
-
* URL, so different query options cache independently) and the request is
|
|
81
|
-
* aborted after {@link EMBER_FETCH_TIMEOUT_MS}. Failures — including timeouts —
|
|
82
|
-
* are never cached and resolve to `[]`, preserving the long-standing
|
|
83
|
-
* fail-tolerant contract of this getter.
|
|
84
|
-
*/
|
|
85
|
-
async function getEmberVaults(options) {
|
|
86
|
-
try {
|
|
87
|
-
const params = new URLSearchParams();
|
|
88
|
-
if (options?.limit)
|
|
89
|
-
params.append('limit', options.limit.toString());
|
|
90
|
-
if (options?.offset)
|
|
91
|
-
params.append('offset', options.offset.toString());
|
|
92
|
-
if (options?.status)
|
|
93
|
-
params.append('status', options.status);
|
|
94
|
-
const queryString = params.toString();
|
|
95
|
-
const url = `${constants_1.EMBER_API_BASE_URL}${queryString ? `?${queryString}` : ''}`;
|
|
96
|
-
return await fetchEmberArray(`ember-vaults-${url}`, url);
|
|
97
|
-
}
|
|
98
|
-
catch (error) {
|
|
99
|
-
logger_1.Logger.log.error('getEmberVaults', error);
|
|
100
|
-
return [];
|
|
101
|
-
}
|
|
102
|
-
}
|
|
103
|
-
/**
|
|
104
|
-
* Fetch the latest Ember TVL (in whole units, i.e. `tvlE9 / 1e9`).
|
|
105
|
-
*
|
|
106
|
-
* Shares the timeout and cache of {@link getEmberVaults} via
|
|
107
|
-
* {@link fetchEmberArray}: the TVL history payload is cached for
|
|
108
|
-
* {@link EMBER_CACHE_TTL_MS} per `limit`, and a hung request is aborted after
|
|
109
|
-
* {@link EMBER_FETCH_TIMEOUT_MS}. Failures — including timeouts — are never
|
|
110
|
-
* cached and resolve to `0`.
|
|
111
|
-
*
|
|
112
|
-
* @param limit - Number of history rows to request; only the newest is read.
|
|
113
|
-
* @returns The latest TVL, or `0` when unavailable.
|
|
114
|
-
*/
|
|
115
|
-
async function getEmberTVL(limit = 1) {
|
|
116
|
-
try {
|
|
117
|
-
const params = new URLSearchParams();
|
|
118
|
-
if (limit)
|
|
119
|
-
params.append('limit', limit.toString());
|
|
120
|
-
const queryString = params.toString();
|
|
121
|
-
const url = `${constants_1.EMBER_API_BASE_URL}${constants_1.EMBER_ENDPOINTS.TVL}${queryString ? `?${queryString}` : ''}`;
|
|
122
|
-
const result = await fetchEmberArray(`ember-tvl-${url}`, url);
|
|
123
|
-
if (result.length > 0) {
|
|
124
|
-
const latestEntry = result[0];
|
|
125
|
-
return Number(latestEntry.tvlE9) / constants_1.EMBER_DEFAULTS.E9_DIVISOR;
|
|
126
|
-
}
|
|
127
|
-
return 0;
|
|
128
|
-
}
|
|
129
|
-
catch (error) {
|
|
130
|
-
logger_1.Logger.log.error('getEmberTVL', error);
|
|
131
|
-
return 0;
|
|
132
|
-
}
|
|
133
|
-
}
|
|
134
|
-
//# sourceMappingURL=getters.js.map
|
|
@@ -1,10 +0,0 @@
|
|
|
1
|
-
import type { IVault } from '../../types';
|
|
2
|
-
import type { IEmberVault } from './types';
|
|
3
|
-
/**
|
|
4
|
-
* Transform Ember vault to IVault format
|
|
5
|
-
*/
|
|
6
|
-
export declare function transformEmberVaultToIVault(emberVault: IEmberVault): IVault;
|
|
7
|
-
/**
|
|
8
|
-
* Transform multiple Ember vaults
|
|
9
|
-
*/
|
|
10
|
-
export declare function transformEmberVaultsToIVaults(emberVaults: IEmberVault[]): IVault[];
|
|
@@ -1,115 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.transformEmberVaultToIVault = transformEmberVaultToIVault;
|
|
4
|
-
exports.transformEmberVaultsToIVaults = transformEmberVaultsToIVaults;
|
|
5
|
-
const core_1 = require("../../core");
|
|
6
|
-
const constants_1 = require("./constants");
|
|
7
|
-
const utils_1 = require("./utils");
|
|
8
|
-
/**
|
|
9
|
-
* Transform Ember vault to IVault format
|
|
10
|
-
*/
|
|
11
|
-
function transformEmberVaultToIVault(emberVault) {
|
|
12
|
-
const depositTokenDecimals = emberVault.depositCoin?.decimals || constants_1.EMBER_DEFAULTS.DECIMALS;
|
|
13
|
-
const receiptTokenDecimals = emberVault.receiptCoin?.decimals || constants_1.EMBER_DEFAULTS.DECIMALS;
|
|
14
|
-
const returnObj = {
|
|
15
|
-
chainId: constants_1.SUI_CHAIN_ID,
|
|
16
|
-
maxDailyDrawdown: 0,
|
|
17
|
-
risk: 'medium',
|
|
18
|
-
lagDuration: 0,
|
|
19
|
-
address: emberVault.address,
|
|
20
|
-
name: emberVault.name,
|
|
21
|
-
logoUrl: emberVault.logoUrl || '',
|
|
22
|
-
apy: {
|
|
23
|
-
apy: (0, utils_1.convertFromE9)(emberVault.reportedApy?.reportedApyE9 || 0) * 100,
|
|
24
|
-
pointsApy: null,
|
|
25
|
-
campaignApy: null,
|
|
26
|
-
explainer: '',
|
|
27
|
-
liquidApy: 0,
|
|
28
|
-
rewardsClaimable: 0,
|
|
29
|
-
rewardsCompounded: 0,
|
|
30
|
-
underlyingApy: (0, utils_1.convertFromE9)(emberVault.reportedApy?.reportedApyE9 || 0) * 100,
|
|
31
|
-
},
|
|
32
|
-
historical_apy: {
|
|
33
|
-
7: (0, utils_1.convertFromE9)(emberVault.reportedApy?.reportedApyE9 || 0),
|
|
34
|
-
},
|
|
35
|
-
strategists: (emberVault.managers ||
|
|
36
|
-
emberVault.subAccounts?.map((s) => s.manager) ||
|
|
37
|
-
[]).map((manager) => ({
|
|
38
|
-
address: manager?.id || '',
|
|
39
|
-
logo: manager?.logoUrl || '',
|
|
40
|
-
name: manager?.name?.toLowerCase() === 'gamma'
|
|
41
|
-
? 'Gamma Research'
|
|
42
|
-
: manager?.name || 'Unknown',
|
|
43
|
-
type: 'subaccount',
|
|
44
|
-
website_url: null,
|
|
45
|
-
})),
|
|
46
|
-
fees: {
|
|
47
|
-
performance: (0, utils_1.convertFromE9)(emberVault.weeklyPerformanceFeeBpsE9 || 0) /
|
|
48
|
-
constants_1.EMBER_DEFAULTS.BPS_TO_PERCENT,
|
|
49
|
-
management: (0, utils_1.convertFromE9)(emberVault.managementFeePercentE9 || 0) * 100,
|
|
50
|
-
isManagementWaived: false,
|
|
51
|
-
managementFeeWaivedUntilDate: null,
|
|
52
|
-
managementFeeWaivedUntilTvl: null,
|
|
53
|
-
isPerformanceWaived: false,
|
|
54
|
-
performanceFeeWaivedUntilDate: null,
|
|
55
|
-
performanceFeeWaivedUntilTvl: null,
|
|
56
|
-
},
|
|
57
|
-
rewards: {
|
|
58
|
-
points: '0',
|
|
59
|
-
multiplier: 0,
|
|
60
|
-
multipliers: [],
|
|
61
|
-
additionalPoints: [],
|
|
62
|
-
additionalPointsDetailed: [],
|
|
63
|
-
},
|
|
64
|
-
version: constants_1.EMBER_DEFAULTS.VERSION,
|
|
65
|
-
description: emberVault.description || '',
|
|
66
|
-
startDatetime: new Date(emberVault.createdAt || Date.now()).toISOString(),
|
|
67
|
-
status: emberVault.status === 'deprecated' ? 'closed' : 'active',
|
|
68
|
-
tags: ['Sui DeFi', emberVault.publicType].filter(Boolean),
|
|
69
|
-
isFeatured: false,
|
|
70
|
-
isSpotlighted: false,
|
|
71
|
-
withdrawalOnly: undefined,
|
|
72
|
-
isVisible: emberVault.status === 'active' || emberVault.status === 'beta',
|
|
73
|
-
reserveTarget: 0,
|
|
74
|
-
reserveTolerance: 0,
|
|
75
|
-
isDepositPaused: emberVault.status === 'deprecated',
|
|
76
|
-
decimals: receiptTokenDecimals,
|
|
77
|
-
isWithdrawalPaused: emberVault.status === 'deprecated',
|
|
78
|
-
operator: '',
|
|
79
|
-
idleAssets: (0, core_1.toNormalizedBn)(0, receiptTokenDecimals),
|
|
80
|
-
depositAssets: [
|
|
81
|
-
{
|
|
82
|
-
address: emberVault.depositCoin?.address,
|
|
83
|
-
symbol: emberVault.depositCoin?.symbol || '',
|
|
84
|
-
decimals: depositTokenDecimals,
|
|
85
|
-
},
|
|
86
|
-
],
|
|
87
|
-
totalAssets: (0, core_1.toNormalizedBn)(BigInt(emberVault.totalDeposits || '0'), depositTokenDecimals),
|
|
88
|
-
/**
|
|
89
|
-
* PLACEHOLDER: `totalSupply` mirrors `totalDeposits`, so any share price
|
|
90
|
-
* derived as totalAssets / totalSupply is always 1.0 for Ember vaults and
|
|
91
|
-
* is NOT the real receipt-token price. Ember's `rateE9` is not read: its
|
|
92
|
-
* exact semantics (and whether `totalDeposits` is current TVL or a
|
|
93
|
-
* cumulative figure) are not documented by the Ember API, so it is not
|
|
94
|
-
* used to derive supply until that is confirmed.
|
|
95
|
-
*/
|
|
96
|
-
totalSupply: (0, core_1.toNormalizedBn)(BigInt(emberVault.totalDeposits || '0'), receiptTokenDecimals),
|
|
97
|
-
maxSupply: (0, core_1.toNormalizedBn)(BigInt(emberVault.maxDepositsAllowed || '0'), depositTokenDecimals),
|
|
98
|
-
receipt: {
|
|
99
|
-
symbol: emberVault.receiptCoin?.symbol || '',
|
|
100
|
-
address: emberVault.receiptCoin?.address,
|
|
101
|
-
decimals: receiptTokenDecimals,
|
|
102
|
-
},
|
|
103
|
-
composabilityIntegrations: [],
|
|
104
|
-
eoa_operators: [],
|
|
105
|
-
operators: [],
|
|
106
|
-
};
|
|
107
|
-
return returnObj;
|
|
108
|
-
}
|
|
109
|
-
/**
|
|
110
|
-
* Transform multiple Ember vaults
|
|
111
|
-
*/
|
|
112
|
-
function transformEmberVaultsToIVaults(emberVaults) {
|
|
113
|
-
return emberVaults.map(transformEmberVaultToIVault);
|
|
114
|
-
}
|
|
115
|
-
//# sourceMappingURL=transformer.js.map
|
|
@@ -1,70 +0,0 @@
|
|
|
1
|
-
import type { IHIstoricalSnapshot } from '../../types';
|
|
2
|
-
export interface IEmberVault {
|
|
3
|
-
address: string;
|
|
4
|
-
id: string;
|
|
5
|
-
name: string;
|
|
6
|
-
description: string;
|
|
7
|
-
logoUrl: string;
|
|
8
|
-
status: 'active' | 'beta' | 'deprecated';
|
|
9
|
-
publicType: string;
|
|
10
|
-
strategy: string;
|
|
11
|
-
createdAt: number;
|
|
12
|
-
totalDeposits: string;
|
|
13
|
-
totalDepositsInUsdE9: string;
|
|
14
|
-
maxDepositsAllowed: string;
|
|
15
|
-
rateE9: string;
|
|
16
|
-
managementFeePercentE9: string;
|
|
17
|
-
weeklyPerformanceFeeBpsE9: string;
|
|
18
|
-
withdrawalPeriodDays: number;
|
|
19
|
-
minWithdrawalSharesE9: string;
|
|
20
|
-
historicalSnapshots?: IHIstoricalSnapshot[];
|
|
21
|
-
max_drawdown?: number | null;
|
|
22
|
-
depositCoin: {
|
|
23
|
-
address: string;
|
|
24
|
-
symbol: string;
|
|
25
|
-
name: string;
|
|
26
|
-
decimals: number;
|
|
27
|
-
logoUrl: string;
|
|
28
|
-
priceE9: string;
|
|
29
|
-
type: string;
|
|
30
|
-
};
|
|
31
|
-
receiptCoin: {
|
|
32
|
-
address: string;
|
|
33
|
-
symbol: string;
|
|
34
|
-
name: string;
|
|
35
|
-
decimals: number;
|
|
36
|
-
logoUrl: string;
|
|
37
|
-
priceE9: string;
|
|
38
|
-
type: string;
|
|
39
|
-
};
|
|
40
|
-
reportedApy: {
|
|
41
|
-
apyE9: string;
|
|
42
|
-
reportedApyE9: string;
|
|
43
|
-
updatedAt: string;
|
|
44
|
-
};
|
|
45
|
-
managers: Array<{
|
|
46
|
-
id: string;
|
|
47
|
-
name: string;
|
|
48
|
-
logoUrl: string;
|
|
49
|
-
websiteUrl: string;
|
|
50
|
-
}>;
|
|
51
|
-
subAccounts: Array<{
|
|
52
|
-
address: string;
|
|
53
|
-
manager: {
|
|
54
|
-
id: string;
|
|
55
|
-
name: string;
|
|
56
|
-
logoUrl: string;
|
|
57
|
-
websiteUrl: string;
|
|
58
|
-
};
|
|
59
|
-
}>;
|
|
60
|
-
/**
|
|
61
|
-
* Ember reward entries. Their shape is not documented by the Ember API and
|
|
62
|
-
* the SDK does not read them, so they are typed `unknown` — narrow before use.
|
|
63
|
-
*/
|
|
64
|
-
rewards: unknown[];
|
|
65
|
-
}
|
|
66
|
-
export interface IFetchEmberVaultsOptions {
|
|
67
|
-
limit?: number;
|
|
68
|
-
offset?: number;
|
|
69
|
-
status?: string;
|
|
70
|
-
}
|