@augustdigital/sdk 6.0.1 → 7.0.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/lib/adapters/evm/getters.d.ts +1 -1
- package/lib/adapters/evm/getters.js +14 -19
- package/lib/adapters/evm/index.d.ts +8 -1
- package/lib/adapters/evm/index.js +24 -0
- package/lib/adapters/solana/index.d.ts +4 -4
- package/lib/adapters/solana/utils.d.ts +5 -4
- package/lib/adapters/solana/utils.js +82 -45
- package/lib/adapters/solana/vault.actions.d.ts +2 -2
- package/lib/adapters/solana/vault.actions.js +112 -74
- package/lib/adapters/stellar/actions.js +3 -2
- package/lib/adapters/stellar/constants.d.ts +2 -0
- package/lib/adapters/stellar/constants.js +3 -1
- package/lib/adapters/stellar/getters.js +2 -2
- package/lib/adapters/stellar/soroban.js +19 -8
- package/lib/adapters/stellar/submit.js +16 -6
- package/lib/adapters/stellar/utils.d.ts +2 -1
- package/lib/adapters/stellar/utils.js +7 -15
- package/lib/adapters/sui/utils.d.ts +1 -1
- package/lib/adapters/sui/utils.js +3 -7
- package/lib/core/analytics/chain-name.d.ts +1 -0
- package/lib/core/analytics/chain-name.js +26 -0
- package/lib/core/analytics/env.d.ts +4 -0
- package/lib/core/analytics/env.js +33 -0
- package/lib/core/analytics/index.d.ts +6 -2
- package/lib/core/analytics/index.js +16 -1
- package/lib/core/analytics/instrumentation.js +56 -48
- package/lib/core/analytics/method-taxonomy.d.ts +3 -0
- package/lib/core/analytics/method-taxonomy.js +82 -0
- package/lib/core/analytics/metrics.js +18 -42
- package/lib/core/analytics/sanitize.d.ts +1 -0
- package/lib/core/analytics/sanitize.js +34 -0
- package/lib/core/analytics/sentry-runtime.d.ts +4 -0
- package/lib/core/analytics/sentry-runtime.js +78 -0
- package/lib/core/analytics/sentry.d.ts +7 -1
- package/lib/core/analytics/sentry.js +107 -51
- package/lib/core/analytics/types.d.ts +2 -0
- package/lib/core/analytics/version.d.ts +1 -1
- package/lib/core/analytics/version.js +1 -1
- package/lib/core/base.class.d.ts +2 -1
- package/lib/core/base.class.js +5 -1
- package/lib/core/cache.d.ts +4 -0
- package/lib/core/cache.js +25 -0
- package/lib/core/fetcher.d.ts +4 -4
- package/lib/core/fetcher.js +49 -60
- package/lib/core/helpers/chain-address.d.ts +3 -0
- package/lib/core/helpers/chain-address.js +36 -0
- package/lib/core/helpers/explorer-link.d.ts +2 -0
- package/lib/core/helpers/explorer-link.js +11 -0
- package/lib/core/helpers/vault-version.d.ts +4 -0
- package/lib/core/helpers/vault-version.js +59 -0
- package/lib/core/helpers/vaults.d.ts +3 -4
- package/lib/core/helpers/vaults.js +12 -62
- package/lib/core/helpers/web3.d.ts +6 -6
- package/lib/core/helpers/web3.js +142 -79
- package/lib/core/logger/slack.js +2 -2
- package/lib/core/vault-metadata.d.ts +6 -0
- package/lib/core/vault-metadata.js +36 -0
- package/lib/evm/methods/crossChainVault.js +72 -16
- package/lib/evm/types/crossChain.d.ts +4 -0
- package/lib/evm/types/crossChain.js +6 -0
- package/lib/modules/vaults/fetcher.d.ts +1 -6
- package/lib/modules/vaults/fetcher.js +27 -36
- package/lib/modules/vaults/getters.d.ts +1 -1
- package/lib/modules/vaults/getters.js +3 -2
- package/lib/modules/vaults/read.actions.d.ts +27 -0
- package/lib/modules/vaults/read.actions.js +220 -0
- package/lib/modules/vaults/utils/date-utils.js +1 -2
- package/lib/modules/vaults/utils.js +57 -36
- package/lib/modules/vaults/write.actions.d.ts +35 -2
- package/lib/modules/vaults/write.actions.js +254 -94
- package/package.json +3 -1
|
@@ -1,37 +1,4 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
-
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
-
if (k2 === undefined) k2 = k;
|
|
4
|
-
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
-
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
-
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
-
}
|
|
8
|
-
Object.defineProperty(o, k2, desc);
|
|
9
|
-
}) : (function(o, m, k, k2) {
|
|
10
|
-
if (k2 === undefined) k2 = k;
|
|
11
|
-
o[k2] = m[k];
|
|
12
|
-
}));
|
|
13
|
-
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
14
|
-
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
15
|
-
}) : function(o, v) {
|
|
16
|
-
o["default"] = v;
|
|
17
|
-
});
|
|
18
|
-
var __importStar = (this && this.__importStar) || (function () {
|
|
19
|
-
var ownKeys = function(o) {
|
|
20
|
-
ownKeys = Object.getOwnPropertyNames || function (o) {
|
|
21
|
-
var ar = [];
|
|
22
|
-
for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
|
|
23
|
-
return ar;
|
|
24
|
-
};
|
|
25
|
-
return ownKeys(o);
|
|
26
|
-
};
|
|
27
|
-
return function (mod) {
|
|
28
|
-
if (mod && mod.__esModule) return mod;
|
|
29
|
-
var result = {};
|
|
30
|
-
if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
|
|
31
|
-
__setModuleDefault(result, mod);
|
|
32
|
-
return result;
|
|
33
|
-
};
|
|
34
|
-
})();
|
|
35
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
36
3
|
exports.initializeSentry = initializeSentry;
|
|
37
4
|
exports.updateUser = updateUser;
|
|
@@ -39,8 +6,11 @@ exports.clearUser = clearUser;
|
|
|
39
6
|
exports.isAnalyticsEnabled = isAnalyticsEnabled;
|
|
40
7
|
exports.getSentry = getSentry;
|
|
41
8
|
exports.resetAnalytics = resetAnalytics;
|
|
42
|
-
|
|
9
|
+
exports.captureSdkException = captureSdkException;
|
|
10
|
+
const logger_1 = require("../logger");
|
|
43
11
|
const constants_1 = require("./constants");
|
|
12
|
+
const env_1 = require("./env");
|
|
13
|
+
const sentry_runtime_1 = require("./sentry-runtime");
|
|
44
14
|
const user_identity_1 = require("./user-identity");
|
|
45
15
|
let isInitialized = false;
|
|
46
16
|
let isEnabled = true;
|
|
@@ -72,46 +42,89 @@ function isLocalhost() {
|
|
|
72
42
|
}
|
|
73
43
|
function safeSetTag(key, value) {
|
|
74
44
|
try {
|
|
75
|
-
|
|
45
|
+
const sdk = (0, sentry_runtime_1.getSentrySDK)();
|
|
46
|
+
sdk?.setTag(key, value);
|
|
76
47
|
}
|
|
77
48
|
catch {
|
|
78
49
|
}
|
|
79
50
|
}
|
|
80
51
|
function safeSetUser(user) {
|
|
81
52
|
try {
|
|
82
|
-
|
|
53
|
+
const sdk = (0, sentry_runtime_1.getSentrySDK)();
|
|
54
|
+
sdk?.setUser(user);
|
|
83
55
|
}
|
|
84
56
|
catch {
|
|
85
57
|
}
|
|
86
58
|
}
|
|
87
59
|
function initializeSentry(config, environment, walletAddress, apiKey, appName) {
|
|
60
|
+
if (isInitialized) {
|
|
61
|
+
if (isEnabled) {
|
|
62
|
+
if (apiKey !== undefined && apiKey !== cachedApiKey) {
|
|
63
|
+
cachedApiKey = apiKey;
|
|
64
|
+
updateUser(walletAddress, environment);
|
|
65
|
+
}
|
|
66
|
+
else if (walletAddress !== currentIdentity?.walletAddress ||
|
|
67
|
+
environment !== currentIdentity?.environment) {
|
|
68
|
+
updateUser(walletAddress, environment);
|
|
69
|
+
}
|
|
70
|
+
}
|
|
71
|
+
return;
|
|
72
|
+
}
|
|
88
73
|
if (config.enabled === false) {
|
|
89
74
|
isEnabled = false;
|
|
90
|
-
|
|
75
|
+
isInitialized = true;
|
|
76
|
+
logger_1.Logger.log.info('analytics.disabled', { reason: 'config' });
|
|
91
77
|
return;
|
|
92
78
|
}
|
|
93
|
-
|
|
79
|
+
const forced = (0, env_1.isAnalyticsForcedOnViaEnv)();
|
|
80
|
+
if (!forced && (0, env_1.isAnalyticsDisabledViaEnv)()) {
|
|
94
81
|
isEnabled = false;
|
|
95
|
-
|
|
82
|
+
isInitialized = true;
|
|
83
|
+
logger_1.Logger.log.info('analytics.disabled', {
|
|
84
|
+
reason: 'AUGUST_SDK_DISABLE_ANALYTICS',
|
|
85
|
+
});
|
|
96
86
|
return;
|
|
97
87
|
}
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
88
|
+
if (!forced && (0, env_1.isNodeDevOrTestEnv)()) {
|
|
89
|
+
isEnabled = false;
|
|
90
|
+
isInitialized = true;
|
|
91
|
+
logger_1.Logger.log.info('analytics.disabled', {
|
|
92
|
+
reason: 'NODE_ENV',
|
|
93
|
+
nodeEnv: (0, env_1.readEnv)('NODE_ENV'),
|
|
94
|
+
hint: 'set AUGUST_SDK_FORCE_ANALYTICS=1 to override',
|
|
95
|
+
});
|
|
96
|
+
return;
|
|
97
|
+
}
|
|
98
|
+
if (!forced && isLocalhost()) {
|
|
99
|
+
isEnabled = false;
|
|
100
|
+
isInitialized = true;
|
|
101
|
+
logger_1.Logger.log.info('analytics.disabled', { reason: 'localhost' });
|
|
104
102
|
return;
|
|
105
103
|
}
|
|
104
|
+
cachedApiKey = apiKey;
|
|
106
105
|
try {
|
|
107
|
-
|
|
106
|
+
const sdk = (0, sentry_runtime_1.getSentrySDK)();
|
|
107
|
+
if (!sdk) {
|
|
108
|
+
logger_1.Logger.log.warn('analytics.init.sentry-unavailable', {
|
|
109
|
+
runtime: (0, sentry_runtime_1.getSentryRuntime)(),
|
|
110
|
+
hint: 'Confirm @sentry/browser (or @sentry/node) is installed and reachable.',
|
|
111
|
+
});
|
|
112
|
+
isEnabled = false;
|
|
113
|
+
return;
|
|
114
|
+
}
|
|
115
|
+
const rawSampleRate = typeof config.tracesSampleRate === 'number' &&
|
|
116
|
+
Number.isFinite(config.tracesSampleRate)
|
|
117
|
+
? config.tracesSampleRate
|
|
118
|
+
: 1.0;
|
|
119
|
+
const tracesSampleRate = Math.max(0, Math.min(1, rawSampleRate));
|
|
120
|
+
sdk.init({
|
|
108
121
|
dsn: constants_1.SENTRY_DSN,
|
|
109
|
-
tracesSampleRate
|
|
122
|
+
tracesSampleRate,
|
|
110
123
|
enableTracing: true,
|
|
111
124
|
environment: environment.toLowerCase(),
|
|
112
125
|
release: `august-sdk@${getSDKVersion()}`,
|
|
113
126
|
sendDefaultPii: true,
|
|
114
|
-
integrations: [
|
|
127
|
+
integrations: [sdk.captureConsoleIntegration({ levels: ['error'] })],
|
|
115
128
|
beforeSend(event) {
|
|
116
129
|
if (event.tags?.sdk !== 'august-digital') {
|
|
117
130
|
return null;
|
|
@@ -125,13 +138,23 @@ function initializeSentry(config, environment, walletAddress, apiKey, appName) {
|
|
|
125
138
|
updateUser(walletAddress, environment);
|
|
126
139
|
safeSetTag('sdk', 'august-digital');
|
|
127
140
|
safeSetTag('sdk.version', getSDKVersion());
|
|
141
|
+
safeSetTag('sdk.runtime', (0, sentry_runtime_1.getSentryRuntime)());
|
|
128
142
|
if (appName) {
|
|
129
143
|
safeSetTag('app.name', appName);
|
|
130
144
|
}
|
|
145
|
+
safeSetTag('partner.id', appName ? `unverified:${appName}` : 'unverified:anonymous');
|
|
146
|
+
safeSetTag('partner.tier', 'unverified');
|
|
131
147
|
isInitialized = true;
|
|
132
|
-
|
|
148
|
+
logger_1.Logger.log.info('analytics.initialized', {
|
|
149
|
+
runtime: (0, sentry_runtime_1.getSentryRuntime)(),
|
|
150
|
+
hint: 'Disable with { analytics: { enabled: false } } or AUGUST_SDK_DISABLE_ANALYTICS=1',
|
|
151
|
+
});
|
|
133
152
|
}
|
|
134
|
-
catch {
|
|
153
|
+
catch (err) {
|
|
154
|
+
logger_1.Logger.log.warn('analytics.init.failed', {
|
|
155
|
+
runtime: (0, sentry_runtime_1.getSentryRuntime)(),
|
|
156
|
+
error: err instanceof Error ? err.message : String(err),
|
|
157
|
+
});
|
|
135
158
|
isEnabled = false;
|
|
136
159
|
}
|
|
137
160
|
}
|
|
@@ -189,12 +212,45 @@ function isAnalyticsEnabled() {
|
|
|
189
212
|
function getSentry() {
|
|
190
213
|
if (!isAnalyticsEnabled())
|
|
191
214
|
return null;
|
|
192
|
-
return
|
|
215
|
+
return (0, sentry_runtime_1.getSentrySDK)();
|
|
193
216
|
}
|
|
194
217
|
function resetAnalytics() {
|
|
195
218
|
isInitialized = false;
|
|
196
219
|
isEnabled = true;
|
|
197
220
|
currentIdentity = null;
|
|
198
221
|
cachedApiKey = undefined;
|
|
222
|
+
(0, sentry_runtime_1.resetSentryRuntime)();
|
|
223
|
+
}
|
|
224
|
+
async function captureSdkException(error, options) {
|
|
225
|
+
if (!isAnalyticsEnabled())
|
|
226
|
+
return;
|
|
227
|
+
try {
|
|
228
|
+
const sdk = (0, sentry_runtime_1.getSentrySDK)();
|
|
229
|
+
if (!sdk)
|
|
230
|
+
return;
|
|
231
|
+
sdk.withScope((scope) => {
|
|
232
|
+
scope.setTag('sdk', 'august-digital');
|
|
233
|
+
if (options?.surface) {
|
|
234
|
+
scope.setTag('sdk.surface', options.surface);
|
|
235
|
+
}
|
|
236
|
+
if (options?.tags) {
|
|
237
|
+
for (const [k, v] of Object.entries(options.tags)) {
|
|
238
|
+
scope.setTag(k, v);
|
|
239
|
+
}
|
|
240
|
+
}
|
|
241
|
+
if (options?.extra) {
|
|
242
|
+
for (const [k, v] of Object.entries(options.extra)) {
|
|
243
|
+
scope.setExtra(k, v);
|
|
244
|
+
}
|
|
245
|
+
}
|
|
246
|
+
const normalized = error instanceof Error ? error : new Error(String(error));
|
|
247
|
+
sdk.captureException(normalized);
|
|
248
|
+
});
|
|
249
|
+
if (options?.flushTimeoutMs && options.flushTimeoutMs > 0) {
|
|
250
|
+
await sdk.flush(options.flushTimeoutMs);
|
|
251
|
+
}
|
|
252
|
+
}
|
|
253
|
+
catch {
|
|
254
|
+
}
|
|
199
255
|
}
|
|
200
256
|
//# sourceMappingURL=sentry.js.map
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import { IEnv } from '../../types';
|
|
2
2
|
export interface IAnalyticsConfig {
|
|
3
3
|
enabled?: boolean;
|
|
4
|
+
tracesSampleRate?: number;
|
|
4
5
|
}
|
|
5
6
|
export interface IUserIdentity {
|
|
6
7
|
apiKeyHash?: string;
|
|
@@ -12,6 +13,7 @@ export interface IUserIdentity {
|
|
|
12
13
|
}
|
|
13
14
|
export interface IMethodCallMetrics {
|
|
14
15
|
method: string;
|
|
16
|
+
category?: string;
|
|
15
17
|
chainId?: number;
|
|
16
18
|
duration: number;
|
|
17
19
|
success: boolean;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
export declare const SDK_VERSION = "
|
|
1
|
+
export declare const SDK_VERSION = "7.0.0";
|
package/lib/core/base.class.d.ts
CHANGED
|
@@ -19,6 +19,7 @@ export interface IAugustBase {
|
|
|
19
19
|
monitoring?: IMonitoring;
|
|
20
20
|
analytics?: IAnalyticsConfig;
|
|
21
21
|
versionCheck?: IVersionCheckConfig;
|
|
22
|
+
timeoutMs?: number;
|
|
22
23
|
}
|
|
23
24
|
interface IActiveNetwork {
|
|
24
25
|
chainId: IChainId;
|
|
@@ -31,7 +32,7 @@ export declare class AugustBase {
|
|
|
31
32
|
activeNetwork?: IActiveNetwork;
|
|
32
33
|
providers: IProvidersConfig;
|
|
33
34
|
appName: string;
|
|
34
|
-
constructor({ appName, providers, keys, monitoring, analytics, versionCheck, }: IAugustBase);
|
|
35
|
+
constructor({ appName, providers, keys, monitoring, analytics, versionCheck, timeoutMs, }: IAugustBase);
|
|
35
36
|
init(): Promise<void>;
|
|
36
37
|
protected requireActiveNetwork(): IActiveNetwork;
|
|
37
38
|
switchNetwork(chainId: IChainId): void;
|
package/lib/core/base.class.js
CHANGED
|
@@ -5,6 +5,7 @@ const auth_1 = require("./auth");
|
|
|
5
5
|
const logger_1 = require("./logger");
|
|
6
6
|
const analytics_1 = require("./analytics");
|
|
7
7
|
const version_check_1 = require("./version-check");
|
|
8
|
+
const fetcher_1 = require("./fetcher");
|
|
8
9
|
function validateAppName(value) {
|
|
9
10
|
const docsHint = 'See https://docs.augustdigital.io/developers/typescript-sdk#app-name';
|
|
10
11
|
if (typeof value !== 'string' || value.trim().length === 0) {
|
|
@@ -20,7 +21,7 @@ function validateAppName(value) {
|
|
|
20
21
|
return trimmed;
|
|
21
22
|
}
|
|
22
23
|
class AugustBase {
|
|
23
|
-
constructor({ appName, providers = {}, keys, monitoring, analytics, versionCheck, }) {
|
|
24
|
+
constructor({ appName, providers = {}, keys, monitoring, analytics, versionCheck, timeoutMs, }) {
|
|
24
25
|
this.monitoring = {
|
|
25
26
|
'x-user-id': undefined,
|
|
26
27
|
'x-environment': undefined,
|
|
@@ -43,6 +44,9 @@ class AugustBase {
|
|
|
43
44
|
logger_1.Logger.setDevMode(environment === 'DEV');
|
|
44
45
|
(0, analytics_1.initializeSentry)(analytics ?? { enabled: true }, environment, monitoring?.['x-user-id'], keys?.august, this.appName);
|
|
45
46
|
(0, version_check_1.runVersionCheck)(versionCheck);
|
|
47
|
+
if (typeof timeoutMs === 'number') {
|
|
48
|
+
(0, fetcher_1.setSdkRequestTimeout)(timeoutMs);
|
|
49
|
+
}
|
|
46
50
|
}
|
|
47
51
|
async init() {
|
|
48
52
|
const [augustCheck] = await Promise.all([
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.setSafeCache = exports.getSafeCache = exports.CACHE = void 0;
|
|
4
|
+
const lru_cache_1 = require("lru-cache");
|
|
5
|
+
exports.CACHE = new lru_cache_1.LRUCache({
|
|
6
|
+
max: 1000,
|
|
7
|
+
ttl: 1000 * 60 * 60 * 24,
|
|
8
|
+
allowStale: true,
|
|
9
|
+
});
|
|
10
|
+
const getSafeCache = async (key) => {
|
|
11
|
+
if (!key)
|
|
12
|
+
return null;
|
|
13
|
+
if (exports.CACHE.has(key)) {
|
|
14
|
+
return exports.CACHE.get(key);
|
|
15
|
+
}
|
|
16
|
+
return null;
|
|
17
|
+
};
|
|
18
|
+
exports.getSafeCache = getSafeCache;
|
|
19
|
+
const setSafeCache = async (key, value) => {
|
|
20
|
+
if (key && value) {
|
|
21
|
+
exports.CACHE.set(key, value);
|
|
22
|
+
}
|
|
23
|
+
};
|
|
24
|
+
exports.setSafeCache = setSafeCache;
|
|
25
|
+
//# sourceMappingURL=cache.js.map
|
package/lib/core/fetcher.d.ts
CHANGED
|
@@ -1,5 +1,4 @@
|
|
|
1
1
|
import { IAddress, IContractRunner, IHistoricalTimeseriesResponse, ITokenizedVault, IWSMonitorHeaders, IWSVaultLoan, VaultAddress } from '../types';
|
|
2
|
-
import { LRUCache } from 'lru-cache';
|
|
3
2
|
import { WEBSERVER_URL } from './constants/core';
|
|
4
3
|
export type IFetchAugustMethods = 'get' | 'post' | 'put';
|
|
5
4
|
export type IFetchAugustOptions = {
|
|
@@ -11,9 +10,10 @@ export type IFetchAugustOptions = {
|
|
|
11
10
|
timeoutMs?: number;
|
|
12
11
|
override?: boolean;
|
|
13
12
|
};
|
|
14
|
-
export declare
|
|
15
|
-
export declare
|
|
16
|
-
|
|
13
|
+
export declare function setSdkRequestTimeout(ms?: number | null): void;
|
|
14
|
+
export declare function getSdkRequestTimeout(): number;
|
|
15
|
+
import { CACHE, getSafeCache, setSafeCache } from './cache';
|
|
16
|
+
export { CACHE, getSafeCache, setSafeCache };
|
|
17
17
|
export declare function fetchAugustWithKey(apiKey: string, relativeUrl: string, options?: IFetchAugustOptions): Promise<Response>;
|
|
18
18
|
export declare function fetchAugustPublic(relativeUrl: string, options?: IFetchAugustOptions): Promise<Response>;
|
|
19
19
|
export declare function fetchAugustWithBearer(bearerToken: string, relativeUrl: string, options?: IFetchAugustOptions): Promise<Response>;
|
package/lib/core/fetcher.js
CHANGED
|
@@ -1,6 +1,8 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.setSafeCache = exports.getSafeCache = exports.CACHE = void 0;
|
|
4
|
+
exports.setSdkRequestTimeout = setSdkRequestTimeout;
|
|
5
|
+
exports.getSdkRequestTimeout = getSdkRequestTimeout;
|
|
4
6
|
exports.fetchAugustWithKey = fetchAugustWithKey;
|
|
5
7
|
exports.fetchAugustPublic = fetchAugustPublic;
|
|
6
8
|
exports.fetchAugustWithBearer = fetchAugustWithBearer;
|
|
@@ -18,13 +20,13 @@ const core_1 = require("./helpers/core");
|
|
|
18
20
|
const ethers_1 = require("ethers");
|
|
19
21
|
const abis_1 = require("../abis");
|
|
20
22
|
const lru_cache_1 = require("lru-cache");
|
|
21
|
-
const
|
|
22
|
-
const utils_2 = require("../adapters/stellar/utils");
|
|
23
|
+
const chain_address_1 = require("./helpers/chain-address");
|
|
23
24
|
const fetcher_1 = require("../services/coingecko/fetcher");
|
|
24
25
|
const logger_1 = require("./logger");
|
|
25
|
-
const
|
|
26
|
+
const ethers_2 = require("ethers");
|
|
27
|
+
const web3_1 = require("./constants/web3");
|
|
26
28
|
const core_2 = require("./constants/core");
|
|
27
|
-
const
|
|
29
|
+
const vault_version_1 = require("./helpers/vault-version");
|
|
28
30
|
const analytics_1 = require("./analytics");
|
|
29
31
|
const sanitize_1 = require("./analytics/sanitize");
|
|
30
32
|
const errors_1 = require("./errors");
|
|
@@ -40,8 +42,25 @@ function errorFromResponseStatus(status, message, options) {
|
|
|
40
42
|
}
|
|
41
43
|
return new errors_1.AugustServerError(status, message, options);
|
|
42
44
|
}
|
|
45
|
+
let SDK_REQUEST_TIMEOUT_OVERRIDE = null;
|
|
46
|
+
function setSdkRequestTimeout(ms = null) {
|
|
47
|
+
if (ms === null) {
|
|
48
|
+
SDK_REQUEST_TIMEOUT_OVERRIDE = null;
|
|
49
|
+
return;
|
|
50
|
+
}
|
|
51
|
+
if (!Number.isFinite(ms) || ms <= 0) {
|
|
52
|
+
logger_1.Logger.log.warn('setSdkRequestTimeout', 'Ignoring non-positive timeout', {
|
|
53
|
+
ms,
|
|
54
|
+
});
|
|
55
|
+
return;
|
|
56
|
+
}
|
|
57
|
+
SDK_REQUEST_TIMEOUT_OVERRIDE = ms;
|
|
58
|
+
}
|
|
59
|
+
function getSdkRequestTimeout() {
|
|
60
|
+
return SDK_REQUEST_TIMEOUT_OVERRIDE ?? core_2.REQUEST_TIMEOUT_MS;
|
|
61
|
+
}
|
|
43
62
|
function buildRequestAbortSignal(options) {
|
|
44
|
-
const timeoutMs = options?.timeoutMs ?? core_2.REQUEST_TIMEOUT_MS;
|
|
63
|
+
const timeoutMs = options?.timeoutMs ?? SDK_REQUEST_TIMEOUT_OVERRIDE ?? core_2.REQUEST_TIMEOUT_MS;
|
|
45
64
|
const timeoutController = new AbortController();
|
|
46
65
|
let didTimeout = false;
|
|
47
66
|
const timeoutId = setTimeout(() => {
|
|
@@ -91,26 +110,10 @@ function readResponseHeader(headers, name) {
|
|
|
91
110
|
const v = headers[name];
|
|
92
111
|
return typeof v === 'string' ? v : undefined;
|
|
93
112
|
}
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
});
|
|
99
|
-
const getSafeCache = async (key) => {
|
|
100
|
-
if (!key)
|
|
101
|
-
return null;
|
|
102
|
-
if (exports.CACHE.has(key)) {
|
|
103
|
-
return exports.CACHE.get(key);
|
|
104
|
-
}
|
|
105
|
-
return null;
|
|
106
|
-
};
|
|
107
|
-
exports.getSafeCache = getSafeCache;
|
|
108
|
-
const setSafeCache = async (key, value) => {
|
|
109
|
-
if (key && value) {
|
|
110
|
-
exports.CACHE.set(key, value);
|
|
111
|
-
}
|
|
112
|
-
};
|
|
113
|
-
exports.setSafeCache = setSafeCache;
|
|
113
|
+
const cache_1 = require("./cache");
|
|
114
|
+
Object.defineProperty(exports, "CACHE", { enumerable: true, get: function () { return cache_1.CACHE; } });
|
|
115
|
+
Object.defineProperty(exports, "getSafeCache", { enumerable: true, get: function () { return cache_1.getSafeCache; } });
|
|
116
|
+
Object.defineProperty(exports, "setSafeCache", { enumerable: true, get: function () { return cache_1.setSafeCache; } });
|
|
114
117
|
const PRICE_CACHE = new lru_cache_1.LRUCache({
|
|
115
118
|
max: 500,
|
|
116
119
|
ttl: 1000 * 30,
|
|
@@ -338,7 +341,7 @@ async function fetchTokenizedVault(pool, headers, loadSubaccounts, loadSnapshots
|
|
|
338
341
|
keyParts.push('no-snapshots');
|
|
339
342
|
const key = keyParts.join('-');
|
|
340
343
|
let tokenizedVault;
|
|
341
|
-
const cachedResponse = await (0,
|
|
344
|
+
const cachedResponse = await (0, cache_1.getSafeCache)(key);
|
|
342
345
|
if (cachedResponse) {
|
|
343
346
|
tokenizedVault = cachedResponse;
|
|
344
347
|
}
|
|
@@ -359,12 +362,10 @@ async function fetchTokenizedVault(pool, headers, loadSubaccounts, loadSnapshots
|
|
|
359
362
|
headers: headers,
|
|
360
363
|
});
|
|
361
364
|
tokenizedVault = (await tokenizedVaultsResponse.json());
|
|
362
|
-
|
|
365
|
+
cache_1.CACHE.set(key, tokenizedVault, { ttl: 1000 * 60 * 10 });
|
|
363
366
|
}
|
|
364
367
|
if (pool &&
|
|
365
|
-
((0, ethers_1.isAddress)(pool) ||
|
|
366
|
-
utils_1.SolanaUtils.isSolanaAddress(pool) ||
|
|
367
|
-
(0, utils_2.isStellarAddress)(pool))) {
|
|
368
|
+
((0, ethers_1.isAddress)(pool) || (0, chain_address_1.isSolanaAddress)(pool) || (0, chain_address_1.isStellarAddress)(pool))) {
|
|
368
369
|
return tokenizedVault ? [tokenizedVault] : [];
|
|
369
370
|
}
|
|
370
371
|
return [tokenizedVault];
|
|
@@ -379,7 +380,7 @@ async function fetchTokenizedVaults(pool, headers, loadSubaccounts, loadSnapshot
|
|
|
379
380
|
keyParts.push('no-snapshots');
|
|
380
381
|
const key = keyParts.join('-');
|
|
381
382
|
let tokenizedVaults;
|
|
382
|
-
const cachedResponse = await (0,
|
|
383
|
+
const cachedResponse = await (0, cache_1.getSafeCache)(key);
|
|
383
384
|
if (cachedResponse) {
|
|
384
385
|
tokenizedVaults = cachedResponse;
|
|
385
386
|
}
|
|
@@ -402,12 +403,10 @@ async function fetchTokenizedVaults(pool, headers, loadSubaccounts, loadSnapshot
|
|
|
402
403
|
tokenizedVaults =
|
|
403
404
|
(await tokenizedVaultsResponse.json());
|
|
404
405
|
const ttl = 1000 * 60 * 15;
|
|
405
|
-
|
|
406
|
+
cache_1.CACHE.set(key, tokenizedVaults, { ttl });
|
|
406
407
|
}
|
|
407
408
|
if (pool &&
|
|
408
|
-
((0, ethers_1.isAddress)(pool) ||
|
|
409
|
-
utils_1.SolanaUtils.isSolanaAddress(pool) ||
|
|
410
|
-
(0, utils_2.isStellarAddress)(pool))) {
|
|
409
|
+
((0, ethers_1.isAddress)(pool) || (0, chain_address_1.isSolanaAddress)(pool) || (0, chain_address_1.isStellarAddress)(pool))) {
|
|
411
410
|
const foundObj = tokenizedVaults.find((t) => t.address.toLowerCase() === pool.toLowerCase());
|
|
412
411
|
return foundObj ? [foundObj] : [];
|
|
413
412
|
}
|
|
@@ -465,15 +464,13 @@ async function _fetchTokenPriceInternal(symbol, provider, coinGeckoKey, headers)
|
|
|
465
464
|
}));
|
|
466
465
|
const foundVaultLpAsset = vaultArray.find((v) => v.symbol?.toLowerCase() === symbol?.toLowerCase());
|
|
467
466
|
const tokenizedVault = tokenizedVaults.find((vault) => vault.address === foundVaultLpAsset?.vault);
|
|
468
|
-
const version = (0,
|
|
467
|
+
const version = (0, vault_version_1.getVaultVersionV2)(tokenizedVault);
|
|
469
468
|
if (foundVaultLpAsset?.vault && provider && version === 'evm-2') {
|
|
470
469
|
try {
|
|
471
|
-
const vaultContract = (0,
|
|
472
|
-
|
|
473
|
-
|
|
474
|
-
|
|
475
|
-
});
|
|
476
|
-
const decimals = await (0, web3_1.getDecimals)(provider, await (0, web3_1.getReceiptTokenAddress)(provider, foundVaultLpAsset?.vault), false);
|
|
470
|
+
const vaultContract = new ethers_2.Contract((0, ethers_1.getAddress)(foundVaultLpAsset?.vault), abis_1.ABI_TOKENIZED_VAULT_V2, provider);
|
|
471
|
+
const receiptAddress = (await vaultContract.lpTokenAddress());
|
|
472
|
+
const receiptContract = new ethers_2.Contract(receiptAddress, [web3_1.MIN_ABIS.decimals], provider);
|
|
473
|
+
const decimals = Number(await receiptContract.decimals());
|
|
477
474
|
const sharePrice = await vaultContract.getSharePrice();
|
|
478
475
|
return Number((0, core_1.toNormalizedBn)(sharePrice, decimals).normalized);
|
|
479
476
|
}
|
|
@@ -491,11 +488,7 @@ async function _fetchTokenPriceInternal(symbol, provider, coinGeckoKey, headers)
|
|
|
491
488
|
}
|
|
492
489
|
const json = (await res.json());
|
|
493
490
|
if (foundVaultLpAsset && provider) {
|
|
494
|
-
const vaultContract = (0,
|
|
495
|
-
provider,
|
|
496
|
-
address: (0, ethers_1.getAddress)(foundVaultLpAsset.vault),
|
|
497
|
-
abi: abis_1.ABI_LENDING_POOL_V2,
|
|
498
|
-
});
|
|
491
|
+
const vaultContract = new ethers_2.Contract((0, ethers_1.getAddress)(foundVaultLpAsset.vault), abis_1.ABI_LENDING_POOL_V2, provider);
|
|
499
492
|
const [totalAssets, totalSupply, rawDecimals] = await Promise.all([
|
|
500
493
|
vaultContract.totalAssets(),
|
|
501
494
|
vaultContract.totalSupply(),
|
|
@@ -510,11 +503,7 @@ async function _fetchTokenPriceInternal(symbol, provider, coinGeckoKey, headers)
|
|
|
510
503
|
catch (e) {
|
|
511
504
|
const fallbackPrice = await (0, fetcher_1.fetchTokenPricesFromCoinGecko)(symbol, coinGeckoKey);
|
|
512
505
|
if (foundVaultLpAsset && provider) {
|
|
513
|
-
const vaultContract = (0,
|
|
514
|
-
provider,
|
|
515
|
-
address: (0, ethers_1.getAddress)(foundVaultLpAsset.vault),
|
|
516
|
-
abi: abis_1.ABI_LENDING_POOL_V2,
|
|
517
|
-
});
|
|
506
|
+
const vaultContract = new ethers_2.Contract((0, ethers_1.getAddress)(foundVaultLpAsset.vault), abis_1.ABI_LENDING_POOL_V2, provider);
|
|
518
507
|
const [totalAssets, totalSupply, rawDecimals] = await Promise.all([
|
|
519
508
|
vaultContract.totalAssets(),
|
|
520
509
|
vaultContract.totalSupply(),
|
|
@@ -561,32 +550,32 @@ async function fetchTokenPriceByAddress(address, chainId, headers) {
|
|
|
561
550
|
async function fetchTokenizedVaultLoans(pool, chainId, headers) {
|
|
562
551
|
const key = `loans-${chainId}-${pool}`;
|
|
563
552
|
let loans;
|
|
564
|
-
if (
|
|
565
|
-
loans =
|
|
553
|
+
if (cache_1.CACHE.get(key)) {
|
|
554
|
+
loans = cache_1.CACHE.get(key);
|
|
566
555
|
}
|
|
567
556
|
else {
|
|
568
557
|
const tokenizedVaultsResponse = await fetchAugustPublic(core_2.WEBSERVER_ENDPOINTS.public.tokenizedVault.loans(pool, chainId, true), { headers: headers });
|
|
569
558
|
loans = (await tokenizedVaultsResponse.json()).loans;
|
|
570
|
-
|
|
559
|
+
cache_1.CACHE.set(key, loans);
|
|
571
560
|
}
|
|
572
561
|
return loans?.filter((l) => l.state.toLowerCase() === 'active');
|
|
573
562
|
}
|
|
574
563
|
async function fetchTokenizedVaultSubaccountLoans(pool, chainId, headers) {
|
|
575
564
|
const key = `subaccount-loans-${chainId}-${pool}`;
|
|
576
565
|
let loans;
|
|
577
|
-
if (
|
|
578
|
-
loans =
|
|
566
|
+
if (cache_1.CACHE.get(key)) {
|
|
567
|
+
loans = cache_1.CACHE.get(key);
|
|
579
568
|
}
|
|
580
569
|
else {
|
|
581
570
|
const tokenizedVaultsResponse = await fetchAugustPublic(core_2.WEBSERVER_ENDPOINTS.public.tokenizedVault.subaccountLoans(pool, chainId, true), { headers: headers });
|
|
582
571
|
loans = (await tokenizedVaultsResponse.json()).loans;
|
|
583
|
-
|
|
572
|
+
cache_1.CACHE.set(key, loans);
|
|
584
573
|
}
|
|
585
574
|
return loans?.filter((l) => l.state.toLowerCase() === 'active');
|
|
586
575
|
}
|
|
587
576
|
async function fetchVaultHistoricalTimeseries(vaultAddress, nDays, headers) {
|
|
588
577
|
const key = `vault-historical-timeseries-${vaultAddress}-${nDays}`;
|
|
589
|
-
const cachedResponse = await (0,
|
|
578
|
+
const cachedResponse = await (0, cache_1.getSafeCache)(key);
|
|
590
579
|
if (cachedResponse) {
|
|
591
580
|
return cachedResponse;
|
|
592
581
|
}
|
|
@@ -595,7 +584,7 @@ async function fetchVaultHistoricalTimeseries(vaultAddress, nDays, headers) {
|
|
|
595
584
|
throw new Error(`Failed to fetch historical timeseries data: ${response.statusText}`);
|
|
596
585
|
}
|
|
597
586
|
const json = (await response.json());
|
|
598
|
-
|
|
587
|
+
cache_1.CACHE.set(key, json, { ttl: 1000 * 60 * 10 });
|
|
599
588
|
return json;
|
|
600
589
|
}
|
|
601
590
|
async function promiseSettle(promises, maxRetries = 3, baseDelay = 1000) {
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.isSolanaAddress = isSolanaAddress;
|
|
4
|
+
exports.isStellarAddress = isStellarAddress;
|
|
5
|
+
exports.isSuiAddress = isSuiAddress;
|
|
6
|
+
const ethers_1 = require("ethers");
|
|
7
|
+
const web3_js_1 = require("@solana/web3.js");
|
|
8
|
+
const STELLAR_ADDRESS_RE = /^[A-Z2-7]{56}$/;
|
|
9
|
+
function isSolanaAddress(address) {
|
|
10
|
+
if (!address)
|
|
11
|
+
return false;
|
|
12
|
+
if ((0, ethers_1.isAddress)(address))
|
|
13
|
+
return false;
|
|
14
|
+
try {
|
|
15
|
+
new web3_js_1.PublicKey(address);
|
|
16
|
+
return true;
|
|
17
|
+
}
|
|
18
|
+
catch {
|
|
19
|
+
return false;
|
|
20
|
+
}
|
|
21
|
+
}
|
|
22
|
+
function isStellarAddress(address) {
|
|
23
|
+
if (!address || typeof address !== 'string')
|
|
24
|
+
return false;
|
|
25
|
+
if (address.length !== 56)
|
|
26
|
+
return false;
|
|
27
|
+
if (address[0] !== 'G' && address[0] !== 'C')
|
|
28
|
+
return false;
|
|
29
|
+
return STELLAR_ADDRESS_RE.test(address);
|
|
30
|
+
}
|
|
31
|
+
function isSuiAddress(address) {
|
|
32
|
+
if (!address || typeof address !== 'string')
|
|
33
|
+
return false;
|
|
34
|
+
return /^0x[a-fA-F0-9]{64}$/.test(address);
|
|
35
|
+
}
|
|
36
|
+
//# sourceMappingURL=chain-address.js.map
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.explorerLink = void 0;
|
|
4
|
+
const web3_1 = require("../constants/web3");
|
|
5
|
+
const explorerLink = (hex, chain, type) => {
|
|
6
|
+
if (!chain)
|
|
7
|
+
return;
|
|
8
|
+
return `${web3_1.NETWORKS[chain].explorer}/${type}/${hex}`;
|
|
9
|
+
};
|
|
10
|
+
exports.explorerLink = explorerLink;
|
|
11
|
+
//# sourceMappingURL=explorer-link.js.map
|
|
@@ -0,0 +1,4 @@
|
|
|
1
|
+
import { ITokenizedVault, IVaultVersion, ChainType } from '../../types';
|
|
2
|
+
export declare function getAddressChainType(address: string): ChainType;
|
|
3
|
+
export declare function getVaultVersion(vault: string): IVaultVersion | undefined;
|
|
4
|
+
export declare function getVaultVersionV2(vault: ITokenizedVault): IVaultVersion | undefined;
|