@augustdigital/sdk 8.7.2 → 8.8.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/core/analytics/version.d.ts +1 -1
- package/lib/core/analytics/version.js +1 -1
- package/lib/core/base.class.d.ts +20 -1
- package/lib/core/base.class.js +8 -1
- package/lib/core/constants/web3.d.ts +17 -0
- package/lib/core/constants/web3.js +18 -1
- package/lib/core/fetcher.d.ts +35 -0
- package/lib/core/fetcher.js +80 -1
- package/lib/sdk.d.ts +83 -1
- package/lib/services/subgraph/vaults.js +89 -20
- package/lib/types/subgraph.d.ts +8 -0
- package/package.json +1 -1
package/lib/core/base.class.d.ts
CHANGED
|
@@ -63,6 +63,25 @@ export interface IAugustBase {
|
|
|
63
63
|
* with different timeouts in the same process.
|
|
64
64
|
*/
|
|
65
65
|
timeoutMs?: number;
|
|
66
|
+
/**
|
|
67
|
+
* Override the base URL for the SDK's unauthenticated `public` vault-catalog
|
|
68
|
+
* API (what `getVault` / `getVaults` / `fetchTokenizedVault` read from).
|
|
69
|
+
* Defaults to the compiled-in prod base
|
|
70
|
+
* (`https://api.augustdigital.io/api/v1`) when omitted — so production apps
|
|
71
|
+
* pass nothing and behaviour is unchanged.
|
|
72
|
+
*
|
|
73
|
+
* Set this ONLY for a non-prod deployment that runs against an isolated
|
|
74
|
+
* backend (e.g. a staging API serving staging-only vaults). Must be an
|
|
75
|
+
* absolute http(s) URL including any base path, e.g.
|
|
76
|
+
* `https://api.staging.augustdigital.io/api/v1`. Invalid values are ignored.
|
|
77
|
+
*
|
|
78
|
+
* Note: this is a process-global override on the underlying fetcher helpers,
|
|
79
|
+
* applied on EVERY construction — so the last `AugustSDK` instantiated is
|
|
80
|
+
* authoritative, and one that omits `publicApiBaseUrl` RESETS to the prod
|
|
81
|
+
* default. (Stricter than `timeoutMs`, which stays sticky when omitted, since
|
|
82
|
+
* a stale cross-environment base is higher blast-radius than a stale timeout.)
|
|
83
|
+
*/
|
|
84
|
+
publicApiBaseUrl?: string;
|
|
66
85
|
}
|
|
67
86
|
interface IActiveNetwork {
|
|
68
87
|
chainId: IChainId;
|
|
@@ -87,7 +106,7 @@ export declare class AugustBase {
|
|
|
87
106
|
* @throws If `appName` is missing, malformed, or out of the allowed
|
|
88
107
|
* length range — see {@link IAugustBase.appName}.
|
|
89
108
|
*/
|
|
90
|
-
constructor({ appName, providers, keys, monitoring, analytics, versionCheck, timeoutMs, }: IAugustBase);
|
|
109
|
+
constructor({ appName, providers, keys, monitoring, analytics, versionCheck, timeoutMs, publicApiBaseUrl, }: IAugustBase);
|
|
91
110
|
/**
|
|
92
111
|
* Verify API keys and authorize SDK usage.
|
|
93
112
|
* TODO: initialize class with appropriate keys and verify august key
|
package/lib/core/base.class.js
CHANGED
|
@@ -55,7 +55,7 @@ class AugustBase {
|
|
|
55
55
|
* @throws If `appName` is missing, malformed, or out of the allowed
|
|
56
56
|
* length range — see {@link IAugustBase.appName}.
|
|
57
57
|
*/
|
|
58
|
-
constructor({ appName, providers = {}, keys, monitoring, analytics, versionCheck, timeoutMs, }) {
|
|
58
|
+
constructor({ appName, providers = {}, keys, monitoring, analytics, versionCheck, timeoutMs, publicApiBaseUrl, }) {
|
|
59
59
|
// Validate first so the failure mode is a clear, actionable error before
|
|
60
60
|
// any provider / analytics side effects run.
|
|
61
61
|
this.appName = validateAppName(appName);
|
|
@@ -88,6 +88,13 @@ class AugustBase {
|
|
|
88
88
|
if (typeof timeoutMs === 'number') {
|
|
89
89
|
(0, fetcher_1.setSdkRequestTimeout)(timeoutMs);
|
|
90
90
|
}
|
|
91
|
+
// Repoint the unauthenticated `public` vault-catalog API when a non-prod
|
|
92
|
+
// deployment supplies an isolated backend. Called UNCONDITIONALLY so each
|
|
93
|
+
// instance is authoritative: an instance that omits `publicApiBaseUrl`
|
|
94
|
+
// passes `null` and RESETS to the compiled-in prod default. Without this a
|
|
95
|
+
// prior staging instance would leak into a later prod instance in the same
|
|
96
|
+
// process — the inverse of the isolation this option exists to provide.
|
|
97
|
+
(0, fetcher_1.setPublicApiBaseUrl)(publicApiBaseUrl ?? null);
|
|
91
98
|
}
|
|
92
99
|
/**
|
|
93
100
|
* Verify API keys and authorize SDK usage.
|
|
@@ -12,6 +12,23 @@ export declare const SPECIAL_CHAINS: {
|
|
|
12
12
|
};
|
|
13
13
|
};
|
|
14
14
|
export declare const NATIVE_ADDRESS = "0xEeeeeEeeeEeEeeEeEeEeeEEEeeeeEeeeeeeeEEeE";
|
|
15
|
+
/**
|
|
16
|
+
* Decimal precision of the native gas token on every EVM chain this SDK
|
|
17
|
+
* supports (ETH, Base, Arbitrum, Avalanche, Polygon, BNB, HyperEVM, Unichain,
|
|
18
|
+
* Mezo, Monad, Plasma, Ink, Flare, Katana, Citrea, Fluent, Tempo).
|
|
19
|
+
*
|
|
20
|
+
* All of them use 18-decimal native tokens, so this is a single constant rather
|
|
21
|
+
* than a per-chain map. It exists because the native token has no ERC-20
|
|
22
|
+
* `decimals()` to read on-chain: when a subgraph row denominates an amount in
|
|
23
|
+
* the native token it is flagged with a sentinel address ({@link NATIVE_ADDRESS}
|
|
24
|
+
* or the zero address) instead of a real contract, and callers must substitute
|
|
25
|
+
* this value rather than attempting (and failing) a `decimals()` read.
|
|
26
|
+
*
|
|
27
|
+
* Non-EVM natives differ (SOL is 9, XLM is 7) and are handled by their own
|
|
28
|
+
* adapters — those chains never flow through the EVM `decimals()` path this
|
|
29
|
+
* constant serves.
|
|
30
|
+
*/
|
|
31
|
+
export declare const EVM_NATIVE_DECIMALS = 18;
|
|
15
32
|
export declare const MIN_ABIS: {
|
|
16
33
|
name: string;
|
|
17
34
|
symbol: string;
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.FALLBACK_RPC_URLS = exports.FALLBACK_CHAINID = exports.FALLBACK_DECIMALS = exports.AVAILABLE_CHAINS = exports.NETWORKS = exports.ORACLE_CONTRACTS = exports.MIN_ABIS = exports.NATIVE_ADDRESS = exports.SPECIAL_CHAINS = void 0;
|
|
3
|
+
exports.FALLBACK_RPC_URLS = exports.FALLBACK_CHAINID = exports.FALLBACK_DECIMALS = exports.AVAILABLE_CHAINS = exports.NETWORKS = exports.ORACLE_CONTRACTS = exports.MIN_ABIS = exports.EVM_NATIVE_DECIMALS = exports.NATIVE_ADDRESS = exports.SPECIAL_CHAINS = void 0;
|
|
4
4
|
// Special Chains
|
|
5
5
|
exports.SPECIAL_CHAINS = {
|
|
6
6
|
solana: {
|
|
@@ -16,6 +16,23 @@ exports.SPECIAL_CHAINS = {
|
|
|
16
16
|
};
|
|
17
17
|
// General
|
|
18
18
|
exports.NATIVE_ADDRESS = '0xEeeeeEeeeEeEeeEeEeEeeEEEeeeeEeeeeeeeEEeE';
|
|
19
|
+
/**
|
|
20
|
+
* Decimal precision of the native gas token on every EVM chain this SDK
|
|
21
|
+
* supports (ETH, Base, Arbitrum, Avalanche, Polygon, BNB, HyperEVM, Unichain,
|
|
22
|
+
* Mezo, Monad, Plasma, Ink, Flare, Katana, Citrea, Fluent, Tempo).
|
|
23
|
+
*
|
|
24
|
+
* All of them use 18-decimal native tokens, so this is a single constant rather
|
|
25
|
+
* than a per-chain map. It exists because the native token has no ERC-20
|
|
26
|
+
* `decimals()` to read on-chain: when a subgraph row denominates an amount in
|
|
27
|
+
* the native token it is flagged with a sentinel address ({@link NATIVE_ADDRESS}
|
|
28
|
+
* or the zero address) instead of a real contract, and callers must substitute
|
|
29
|
+
* this value rather than attempting (and failing) a `decimals()` read.
|
|
30
|
+
*
|
|
31
|
+
* Non-EVM natives differ (SOL is 9, XLM is 7) and are handled by their own
|
|
32
|
+
* adapters — those chains never flow through the EVM `decimals()` path this
|
|
33
|
+
* constant serves.
|
|
34
|
+
*/
|
|
35
|
+
exports.EVM_NATIVE_DECIMALS = 18;
|
|
19
36
|
exports.MIN_ABIS = {
|
|
20
37
|
name: 'function name() view returns (string)',
|
|
21
38
|
symbol: 'function symbol() view returns (string)',
|
package/lib/core/fetcher.d.ts
CHANGED
|
@@ -41,6 +41,41 @@ export declare function setSdkRequestTimeout(ms?: number | null): void;
|
|
|
41
41
|
* otherwise the compiled-in `REQUEST_TIMEOUT_MS`.
|
|
42
42
|
*/
|
|
43
43
|
export declare function getSdkRequestTimeout(): number;
|
|
44
|
+
/**
|
|
45
|
+
* Override the base URL used for `WEBSERVER_URL.public` requests — the
|
|
46
|
+
* unauthenticated vault-catalog API that `getVault` / `fetchTokenizedVault`
|
|
47
|
+
* (and the other `fetchAugustPublic` callers) read from. Defaults to the
|
|
48
|
+
* compiled-in prod base (`https://api.augustdigital.io/api/v1`); pass `null`
|
|
49
|
+
* (or call with no arguments) to clear.
|
|
50
|
+
*
|
|
51
|
+
* Intended for non-prod deployments that run against an ISOLATED backend
|
|
52
|
+
* (e.g. a staging API): set it once at construction via
|
|
53
|
+
* `IAugustBase.publicApiBaseUrl` so a staging-only vault resolves. Production
|
|
54
|
+
* leaves it unset, so behaviour is unchanged.
|
|
55
|
+
*
|
|
56
|
+
* This is a process-global override on the fetcher helpers. The SDK constructor
|
|
57
|
+
* calls it on EVERY instantiation (with `null` when `publicApiBaseUrl` is
|
|
58
|
+
* omitted), so the last `AugustSDK` instantiated is authoritative — a prod
|
|
59
|
+
* instance resets it to the default even after a prior staging instance set it.
|
|
60
|
+
* An invalid or non-http(s) URL is treated as "no override": it RESETS to the
|
|
61
|
+
* compiled-in default (warned) rather than retaining a prior value, so a bad env
|
|
62
|
+
* value can neither break fetches nor silently leave a previous instance's base
|
|
63
|
+
* in place.
|
|
64
|
+
*
|
|
65
|
+
* Whenever the effective base CHANGES, the shared public-response cache is
|
|
66
|
+
* cleared, so catalog data fetched from the previous backend is never served for
|
|
67
|
+
* the new one (e.g. a prod-cached vault leaking into a staging instance). Base
|
|
68
|
+
* changes happen at construction, when the cache is cold, so this is ~free.
|
|
69
|
+
*
|
|
70
|
+
* @param url - Absolute http(s) base URL (trailing slash is trimmed). `null`, or
|
|
71
|
+
* an invalid / non-http(s) value, resets to the compiled-in public base.
|
|
72
|
+
*/
|
|
73
|
+
export declare function setPublicApiBaseUrl(url?: string | null): void;
|
|
74
|
+
/**
|
|
75
|
+
* Read the active base for the `public` server — the SDK-level override if set,
|
|
76
|
+
* otherwise the compiled-in `WEBSERVER_URL.public`.
|
|
77
|
+
*/
|
|
78
|
+
export declare function getPublicApiBaseUrl(): string;
|
|
44
79
|
import { CACHE, getSafeCache, setSafeCache } from './cache';
|
|
45
80
|
export { CACHE, getSafeCache, setSafeCache };
|
|
46
81
|
/**
|
package/lib/core/fetcher.js
CHANGED
|
@@ -3,6 +3,8 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
3
3
|
exports.setSafeCache = exports.getSafeCache = exports.CACHE = void 0;
|
|
4
4
|
exports.setSdkRequestTimeout = setSdkRequestTimeout;
|
|
5
5
|
exports.getSdkRequestTimeout = getSdkRequestTimeout;
|
|
6
|
+
exports.setPublicApiBaseUrl = setPublicApiBaseUrl;
|
|
7
|
+
exports.getPublicApiBaseUrl = getPublicApiBaseUrl;
|
|
6
8
|
exports.fetchAugustWithKey = fetchAugustWithKey;
|
|
7
9
|
exports.fetchAugustPublic = fetchAugustPublic;
|
|
8
10
|
exports.fetchAugustWithBearer = fetchAugustWithBearer;
|
|
@@ -73,6 +75,78 @@ function setSdkRequestTimeout(ms = null) {
|
|
|
73
75
|
function getSdkRequestTimeout() {
|
|
74
76
|
return SDK_REQUEST_TIMEOUT_OVERRIDE ?? core_2.REQUEST_TIMEOUT_MS;
|
|
75
77
|
}
|
|
78
|
+
let PUBLIC_API_BASE_OVERRIDE = null;
|
|
79
|
+
/**
|
|
80
|
+
* Override the base URL used for `WEBSERVER_URL.public` requests — the
|
|
81
|
+
* unauthenticated vault-catalog API that `getVault` / `fetchTokenizedVault`
|
|
82
|
+
* (and the other `fetchAugustPublic` callers) read from. Defaults to the
|
|
83
|
+
* compiled-in prod base (`https://api.augustdigital.io/api/v1`); pass `null`
|
|
84
|
+
* (or call with no arguments) to clear.
|
|
85
|
+
*
|
|
86
|
+
* Intended for non-prod deployments that run against an ISOLATED backend
|
|
87
|
+
* (e.g. a staging API): set it once at construction via
|
|
88
|
+
* `IAugustBase.publicApiBaseUrl` so a staging-only vault resolves. Production
|
|
89
|
+
* leaves it unset, so behaviour is unchanged.
|
|
90
|
+
*
|
|
91
|
+
* This is a process-global override on the fetcher helpers. The SDK constructor
|
|
92
|
+
* calls it on EVERY instantiation (with `null` when `publicApiBaseUrl` is
|
|
93
|
+
* omitted), so the last `AugustSDK` instantiated is authoritative — a prod
|
|
94
|
+
* instance resets it to the default even after a prior staging instance set it.
|
|
95
|
+
* An invalid or non-http(s) URL is treated as "no override": it RESETS to the
|
|
96
|
+
* compiled-in default (warned) rather than retaining a prior value, so a bad env
|
|
97
|
+
* value can neither break fetches nor silently leave a previous instance's base
|
|
98
|
+
* in place.
|
|
99
|
+
*
|
|
100
|
+
* Whenever the effective base CHANGES, the shared public-response cache is
|
|
101
|
+
* cleared, so catalog data fetched from the previous backend is never served for
|
|
102
|
+
* the new one (e.g. a prod-cached vault leaking into a staging instance). Base
|
|
103
|
+
* changes happen at construction, when the cache is cold, so this is ~free.
|
|
104
|
+
*
|
|
105
|
+
* @param url - Absolute http(s) base URL (trailing slash is trimmed). `null`, or
|
|
106
|
+
* an invalid / non-http(s) value, resets to the compiled-in public base.
|
|
107
|
+
*/
|
|
108
|
+
function setPublicApiBaseUrl(url = null) {
|
|
109
|
+
const previous = PUBLIC_API_BASE_OVERRIDE;
|
|
110
|
+
if (url === null) {
|
|
111
|
+
PUBLIC_API_BASE_OVERRIDE = null;
|
|
112
|
+
}
|
|
113
|
+
else {
|
|
114
|
+
let parsed = null;
|
|
115
|
+
try {
|
|
116
|
+
parsed = new URL(url);
|
|
117
|
+
}
|
|
118
|
+
catch {
|
|
119
|
+
parsed = null;
|
|
120
|
+
}
|
|
121
|
+
if (!parsed ||
|
|
122
|
+
(parsed.protocol !== 'https:' && parsed.protocol !== 'http:')) {
|
|
123
|
+
// Reset to the default rather than retaining a stale prior override, so
|
|
124
|
+
// each construction stays authoritative and a bad env value fails safe to
|
|
125
|
+
// prod instead of inheriting another instance's base.
|
|
126
|
+
logger_1.Logger.log.warn('setPublicApiBaseUrl', 'Ignoring invalid/non-http(s) URL; resetting to the default public base', { url });
|
|
127
|
+
PUBLIC_API_BASE_OVERRIDE = null;
|
|
128
|
+
}
|
|
129
|
+
else {
|
|
130
|
+
// Store WITHOUT a trailing slash: buildAugustUrl concatenates
|
|
131
|
+
// `${base}${relativeUrl}` (relativeUrl starts with '/'), so a trailing
|
|
132
|
+
// slash on the base would produce a double slash.
|
|
133
|
+
PUBLIC_API_BASE_OVERRIDE = url.replace(/\/+$/, '');
|
|
134
|
+
}
|
|
135
|
+
}
|
|
136
|
+
if (PUBLIC_API_BASE_OVERRIDE !== previous) {
|
|
137
|
+
// The public base moved (or reset). Drop cached public-catalog responses
|
|
138
|
+
// keyed against the previous base (see fetchTokenizedVault(s) etc.) so they
|
|
139
|
+
// aren't served for the new backend.
|
|
140
|
+
cache_1.CACHE.clear();
|
|
141
|
+
}
|
|
142
|
+
}
|
|
143
|
+
/**
|
|
144
|
+
* Read the active base for the `public` server — the SDK-level override if set,
|
|
145
|
+
* otherwise the compiled-in `WEBSERVER_URL.public`.
|
|
146
|
+
*/
|
|
147
|
+
function getPublicApiBaseUrl() {
|
|
148
|
+
return PUBLIC_API_BASE_OVERRIDE ?? core_2.WEBSERVER_URL.public;
|
|
149
|
+
}
|
|
76
150
|
/**
|
|
77
151
|
* Combine the per-request timeout signal with any caller-supplied signal.
|
|
78
152
|
* Uses `AbortSignal.any` (Node 22+) with a manual relay fallback.
|
|
@@ -182,7 +256,12 @@ const PRICE_REQUESTS = new Map();
|
|
|
182
256
|
*/
|
|
183
257
|
function buildAugustUrl(server, relativeUrl) {
|
|
184
258
|
const serverKey = server;
|
|
185
|
-
|
|
259
|
+
// The `public` base is overridable (setPublicApiBaseUrl / IAugustBase
|
|
260
|
+
// .publicApiBaseUrl) so non-prod deployments can point vault-catalog reads at
|
|
261
|
+
// an isolated backend. Resolved once here via getPublicApiBaseUrl() (single
|
|
262
|
+
// source of truth), so the origin check below validates against the OVERRIDDEN
|
|
263
|
+
// origin.
|
|
264
|
+
const base = serverKey === 'public' ? getPublicApiBaseUrl() : core_2.WEBSERVER_URL[serverKey];
|
|
186
265
|
if (!base) {
|
|
187
266
|
throw new errors_1.AugustValidationError('INVALID_URL', `Unknown August server "${String(server)}". Expected one of: ${Object.keys(core_2.WEBSERVER_URL).join(', ')}`);
|
|
188
267
|
}
|
package/lib/sdk.d.ts
CHANGED
|
@@ -15175,7 +15175,7 @@ export declare class AugustBase {
|
|
|
15175
15175
|
* @throws If `appName` is missing, malformed, or out of the allowed
|
|
15176
15176
|
* length range — see {@link IAugustBase.appName}.
|
|
15177
15177
|
*/
|
|
15178
|
-
constructor({ appName, providers, keys, monitoring, analytics, versionCheck, timeoutMs, }: IAugustBase);
|
|
15178
|
+
constructor({ appName, providers, keys, monitoring, analytics, versionCheck, timeoutMs, publicApiBaseUrl, }: IAugustBase);
|
|
15179
15179
|
/**
|
|
15180
15180
|
* Verify API keys and authorize SDK usage.
|
|
15181
15181
|
* TODO: initialize class with appropriate keys and verify august key
|
|
@@ -16818,6 +16818,24 @@ export declare function depositNative(signer: Signer | Wallet, options: INativeD
|
|
|
16818
16818
|
address?: string;
|
|
16819
16819
|
}): void;
|
|
16820
16820
|
|
|
16821
|
+
/**
|
|
16822
|
+
* Decimal precision of the native gas token on every EVM chain this SDK
|
|
16823
|
+
* supports (ETH, Base, Arbitrum, Avalanche, Polygon, BNB, HyperEVM, Unichain,
|
|
16824
|
+
* Mezo, Monad, Plasma, Ink, Flare, Katana, Citrea, Fluent, Tempo).
|
|
16825
|
+
*
|
|
16826
|
+
* All of them use 18-decimal native tokens, so this is a single constant rather
|
|
16827
|
+
* than a per-chain map. It exists because the native token has no ERC-20
|
|
16828
|
+
* `decimals()` to read on-chain: when a subgraph row denominates an amount in
|
|
16829
|
+
* the native token it is flagged with a sentinel address ({@link NATIVE_ADDRESS}
|
|
16830
|
+
* or the zero address) instead of a real contract, and callers must substitute
|
|
16831
|
+
* this value rather than attempting (and failing) a `decimals()` read.
|
|
16832
|
+
*
|
|
16833
|
+
* Non-EVM natives differ (SOL is 9, XLM is 7) and are handled by their own
|
|
16834
|
+
* adapters — those chains never flow through the EVM `decimals()` path this
|
|
16835
|
+
* constant serves.
|
|
16836
|
+
*/
|
|
16837
|
+
export declare const EVM_NATIVE_DECIMALS = 18;
|
|
16838
|
+
|
|
16821
16839
|
/**
|
|
16822
16840
|
* EVM Adapter for August SDK
|
|
16823
16841
|
* Supports both ethers Signer/Wallet and wagmi/viem WalletClient
|
|
@@ -17654,6 +17672,12 @@ export declare function depositNative(signer: Signer | Wallet, options: INativeD
|
|
|
17654
17672
|
options: IVaultBaseOptions;
|
|
17655
17673
|
}): Promise<INormalizedNumber>;
|
|
17656
17674
|
|
|
17675
|
+
/**
|
|
17676
|
+
* Read the active base for the `public` server — the SDK-level override if set,
|
|
17677
|
+
* otherwise the compiled-in `WEBSERVER_URL.public`.
|
|
17678
|
+
*/
|
|
17679
|
+
export declare function getPublicApiBaseUrl(): string;
|
|
17680
|
+
|
|
17657
17681
|
/**
|
|
17658
17682
|
* Fetch receipt token address from tokenized vault contract.
|
|
17659
17683
|
* Results are cached to minimize RPC calls.
|
|
@@ -18418,6 +18442,25 @@ export declare function depositNative(signer: Signer | Wallet, options: INativeD
|
|
|
18418
18442
|
* with different timeouts in the same process.
|
|
18419
18443
|
*/
|
|
18420
18444
|
timeoutMs?: number;
|
|
18445
|
+
/**
|
|
18446
|
+
* Override the base URL for the SDK's unauthenticated `public` vault-catalog
|
|
18447
|
+
* API (what `getVault` / `getVaults` / `fetchTokenizedVault` read from).
|
|
18448
|
+
* Defaults to the compiled-in prod base
|
|
18449
|
+
* (`https://api.augustdigital.io/api/v1`) when omitted — so production apps
|
|
18450
|
+
* pass nothing and behaviour is unchanged.
|
|
18451
|
+
*
|
|
18452
|
+
* Set this ONLY for a non-prod deployment that runs against an isolated
|
|
18453
|
+
* backend (e.g. a staging API serving staging-only vaults). Must be an
|
|
18454
|
+
* absolute http(s) URL including any base path, e.g.
|
|
18455
|
+
* `https://api.staging.augustdigital.io/api/v1`. Invalid values are ignored.
|
|
18456
|
+
*
|
|
18457
|
+
* Note: this is a process-global override on the underlying fetcher helpers,
|
|
18458
|
+
* applied on EVERY construction — so the last `AugustSDK` instantiated is
|
|
18459
|
+
* authoritative, and one that omits `publicApiBaseUrl` RESETS to the prod
|
|
18460
|
+
* default. (Stricter than `timeoutMs`, which stays sticky when omitted, since
|
|
18461
|
+
* a stale cross-environment base is higher blast-radius than a stale timeout.)
|
|
18462
|
+
*/
|
|
18463
|
+
publicApiBaseUrl?: string;
|
|
18421
18464
|
}
|
|
18422
18465
|
|
|
18423
18466
|
/** Options for {@link balanceOf}. */
|
|
@@ -19775,6 +19818,14 @@ export declare function depositNative(signer: Signer | Wallet, options: INativeD
|
|
|
19775
19818
|
owner: IAddress;
|
|
19776
19819
|
senderAddr?: IAddress;
|
|
19777
19820
|
amountIn?: string;
|
|
19821
|
+
/**
|
|
19822
|
+
* Deposit asset token address (evm-2 / pre-deposit vaults). The deposited
|
|
19823
|
+
* asset can differ from the vault's underlying and carry different decimals
|
|
19824
|
+
* (e.g. RLUSD at 18 into a 6-decimal sentUSD vault), so `amountIn` must be
|
|
19825
|
+
* normalized against this token's decimals, not the vault's. Absent for
|
|
19826
|
+
* single-asset vaults.
|
|
19827
|
+
*/
|
|
19828
|
+
assetIn?: IAddress;
|
|
19778
19829
|
}
|
|
19779
19830
|
|
|
19780
19831
|
export declare interface ISubgraphFormattedLoan {
|
|
@@ -22588,6 +22639,37 @@ export declare function depositNative(signer: Signer | Wallet, options: INativeD
|
|
|
22588
22639
|
|
|
22589
22640
|
declare function setLogger(customLogger: SDKLogger): void;
|
|
22590
22641
|
|
|
22642
|
+
/**
|
|
22643
|
+
* Override the base URL used for `WEBSERVER_URL.public` requests — the
|
|
22644
|
+
* unauthenticated vault-catalog API that `getVault` / `fetchTokenizedVault`
|
|
22645
|
+
* (and the other `fetchAugustPublic` callers) read from. Defaults to the
|
|
22646
|
+
* compiled-in prod base (`https://api.augustdigital.io/api/v1`); pass `null`
|
|
22647
|
+
* (or call with no arguments) to clear.
|
|
22648
|
+
*
|
|
22649
|
+
* Intended for non-prod deployments that run against an ISOLATED backend
|
|
22650
|
+
* (e.g. a staging API): set it once at construction via
|
|
22651
|
+
* `IAugustBase.publicApiBaseUrl` so a staging-only vault resolves. Production
|
|
22652
|
+
* leaves it unset, so behaviour is unchanged.
|
|
22653
|
+
*
|
|
22654
|
+
* This is a process-global override on the fetcher helpers. The SDK constructor
|
|
22655
|
+
* calls it on EVERY instantiation (with `null` when `publicApiBaseUrl` is
|
|
22656
|
+
* omitted), so the last `AugustSDK` instantiated is authoritative — a prod
|
|
22657
|
+
* instance resets it to the default even after a prior staging instance set it.
|
|
22658
|
+
* An invalid or non-http(s) URL is treated as "no override": it RESETS to the
|
|
22659
|
+
* compiled-in default (warned) rather than retaining a prior value, so a bad env
|
|
22660
|
+
* value can neither break fetches nor silently leave a previous instance's base
|
|
22661
|
+
* in place.
|
|
22662
|
+
*
|
|
22663
|
+
* Whenever the effective base CHANGES, the shared public-response cache is
|
|
22664
|
+
* cleared, so catalog data fetched from the previous backend is never served for
|
|
22665
|
+
* the new one (e.g. a prod-cached vault leaking into a staging instance). Base
|
|
22666
|
+
* changes happen at construction, when the cache is cold, so this is ~free.
|
|
22667
|
+
*
|
|
22668
|
+
* @param url - Absolute http(s) base URL (trailing slash is trimmed). `null`, or
|
|
22669
|
+
* an invalid / non-http(s) value, resets to the compiled-in public base.
|
|
22670
|
+
*/
|
|
22671
|
+
export declare function setPublicApiBaseUrl(url?: string | null): void;
|
|
22672
|
+
|
|
22591
22673
|
export declare const setSafeCache: <T>(key: string, value: T) => Promise<void>;
|
|
22592
22674
|
|
|
22593
22675
|
/**
|
|
@@ -55,7 +55,60 @@ function alertMissingSubgraphOnce(args) {
|
|
|
55
55
|
function needsMonadSuffix(chainId, symbol) {
|
|
56
56
|
return chainId === 143 && symbol.toLowerCase() === 'earnausd';
|
|
57
57
|
}
|
|
58
|
-
|
|
58
|
+
/**
|
|
59
|
+
* Read the decimals of every distinct deposit asset in a batch of deposit
|
|
60
|
+
* rows, keyed by lowercased token address.
|
|
61
|
+
*
|
|
62
|
+
* Pre-deposit / evm-2 vaults accept multiple deposit assets whose decimals can
|
|
63
|
+
* differ from the vault's own (e.g. RLUSD at 18 deposited into a 6-decimal
|
|
64
|
+
* sentUSD vault). `transformUserHistory` must normalize each deposit against
|
|
65
|
+
* its own asset's decimals rather than the vault's, or an 18-decimal amount
|
|
66
|
+
* normalized at 6 decimals renders ~1e12× too large (a 0.5 deposit shows as
|
|
67
|
+
* "500B"). `getDecimals` is cached and in-flight-deduped, and the distinct-asset
|
|
68
|
+
* set is tiny (typically 1-3), so this is at most a handful of RPC reads.
|
|
69
|
+
*
|
|
70
|
+
* Native-token deposits carry a sentinel `assetIn` — either the zero address or
|
|
71
|
+
* {@link NATIVE_ADDRESS} — that has no on-chain `decimals()`. These are mapped
|
|
72
|
+
* directly to {@link EVM_NATIVE_DECIMALS} (18 on every supported EVM chain)
|
|
73
|
+
* instead of being read. Without this guard `getDecimals(ZeroAddress)` returns
|
|
74
|
+
* `0`, which the caller's `?? decimals` fallback cannot override (0 is not
|
|
75
|
+
* nullish), overstating a native deposit ~1e18×; and `getDecimals(NATIVE_ADDRESS)`
|
|
76
|
+
* reverts, silently dropping to the vault's decimals which may differ.
|
|
77
|
+
*
|
|
78
|
+
* Only successfully-read decimals are entered in the map; a non-native asset
|
|
79
|
+
* whose `decimals()` read fails is omitted so the caller falls back to the
|
|
80
|
+
* vault's decimals. This also lets the vault-decimals read run in parallel with
|
|
81
|
+
* this one (no fallback value is needed up front).
|
|
82
|
+
*
|
|
83
|
+
* @param provider - EVM contract runner used to read `decimals()`.
|
|
84
|
+
* @param deposits - Deposit rows from the subgraph; `assetIn` may be absent.
|
|
85
|
+
* @returns Map of lowercased asset address to decimals (native sentinels and
|
|
86
|
+
* successful reads only).
|
|
87
|
+
*/
|
|
88
|
+
async function buildDepositAssetDecimals(provider, deposits) {
|
|
89
|
+
const map = new Map();
|
|
90
|
+
// Lowercased native-token sentinels: no ERC-20 `decimals()` exists to read.
|
|
91
|
+
const nativeSentinels = new Set([
|
|
92
|
+
ethers_1.ZeroAddress.toLowerCase(),
|
|
93
|
+
core_1.NATIVE_ADDRESS.toLowerCase(),
|
|
94
|
+
]);
|
|
95
|
+
const unique = new Set();
|
|
96
|
+
for (const d of deposits ?? []) {
|
|
97
|
+
if (d?.assetIn)
|
|
98
|
+
unique.add(d.assetIn.toLowerCase());
|
|
99
|
+
}
|
|
100
|
+
await Promise.all([...unique].map(async (addr) => {
|
|
101
|
+
if (nativeSentinels.has(addr)) {
|
|
102
|
+
map.set(addr, core_1.EVM_NATIVE_DECIMALS);
|
|
103
|
+
return;
|
|
104
|
+
}
|
|
105
|
+
const dec = await (0, core_1.getDecimals)(provider, addr, false);
|
|
106
|
+
if (typeof dec === 'number')
|
|
107
|
+
map.set(addr, dec);
|
|
108
|
+
}));
|
|
109
|
+
return map;
|
|
110
|
+
}
|
|
111
|
+
function transformUserHistory(data, chainId, decimals, poolAddress, assetDecimals) {
|
|
59
112
|
//ok to return dupes even though withdraws will return dupe because we parse out duplicate txn hash on the FE
|
|
60
113
|
return [
|
|
61
114
|
...(data.withdraws?.map((item) => ({
|
|
@@ -92,23 +145,33 @@ function transformUserHistory(data, chainId, decimals, poolAddress) {
|
|
|
92
145
|
timestamp: item.timestamp_,
|
|
93
146
|
decimals: decimals,
|
|
94
147
|
})) || []),
|
|
95
|
-
...(data.deposits?.map((item) =>
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
148
|
+
...(data.deposits?.map((item) => {
|
|
149
|
+
// Pair the decimals to the amount's denomination. `assets` (evm-1) is
|
|
150
|
+
// already in the vault's underlying, so it keeps the vault decimals.
|
|
151
|
+
// Only `amountIn` (evm-2 / pre-deposit) is denominated in `assetIn`,
|
|
152
|
+
// which may differ from the vault (e.g. RLUSD 18 → sentUSD 6) and would
|
|
153
|
+
// otherwise overstate the amount ~1e12×. Using the same source for both
|
|
154
|
+
// avoids a denomination/decimals mismatch, and the truthy `assetIn`
|
|
155
|
+
// guard drops empty-string addresses back to the vault decimals.
|
|
156
|
+
const assetKey = !item?.assets && item.assetIn ? item.assetIn.toLowerCase() : undefined;
|
|
157
|
+
return {
|
|
158
|
+
...item,
|
|
159
|
+
contractId_: item.contractId_ || poolAddress,
|
|
160
|
+
chainId: chainId,
|
|
161
|
+
type: 'deposit',
|
|
162
|
+
address: item?.sender || item?.senderAddr,
|
|
163
|
+
amount: item?.assets || item?.amountIn,
|
|
164
|
+
transactionHash: item.transactionHash_,
|
|
165
|
+
timestamp: item.timestamp_,
|
|
166
|
+
decimals: (assetKey ? assetDecimals?.get(assetKey) : undefined) ?? decimals,
|
|
167
|
+
};
|
|
168
|
+
}) || []),
|
|
106
169
|
];
|
|
107
170
|
}
|
|
108
|
-
function sortUserHistory(data, chainId, decimals, poolAddress) {
|
|
171
|
+
function sortUserHistory(data, chainId, decimals, poolAddress, assetDecimals) {
|
|
109
172
|
if (!(data && chainId && decimals))
|
|
110
173
|
return [];
|
|
111
|
-
return transformUserHistory(data, chainId, decimals, poolAddress).sort((a, b) => Number(a.timestamp_) - Number(b.timestamp_));
|
|
174
|
+
return transformUserHistory(data, chainId, decimals, poolAddress, assetDecimals).sort((a, b) => Number(a.timestamp_) - Number(b.timestamp_));
|
|
112
175
|
}
|
|
113
176
|
// queries
|
|
114
177
|
const WITHDRAWALS_REQUESTED_QUERY_PROPS = `
|
|
@@ -707,9 +770,12 @@ async function getSubgraphUserHistory(user, provider, pool, slackWebookUrl = sla
|
|
|
707
770
|
return requests;
|
|
708
771
|
}
|
|
709
772
|
const json = (await result.json());
|
|
710
|
-
// Format data
|
|
711
|
-
const decimals = await
|
|
712
|
-
|
|
773
|
+
// Format data — vault decimals and per-asset decimals are independent reads.
|
|
774
|
+
const [decimals, assetDecimals] = await Promise.all([
|
|
775
|
+
(0, core_1.getDecimals)(provider, pool),
|
|
776
|
+
buildDepositAssetDecimals(provider, json.data?.deposits),
|
|
777
|
+
]);
|
|
778
|
+
const formattedRequests = sortUserHistory(json.data, chainId, decimals, pool, assetDecimals);
|
|
713
779
|
return formattedRequests;
|
|
714
780
|
}
|
|
715
781
|
catch (e) {
|
|
@@ -857,10 +923,13 @@ async function getSubgraphVaultHistory(provider, pool, slackWebookUrl = slack_1.
|
|
|
857
923
|
break;
|
|
858
924
|
skip += PAGE_SIZE;
|
|
859
925
|
}
|
|
860
|
-
// Format data
|
|
926
|
+
// Format data — vault decimals and per-asset decimals are independent reads.
|
|
861
927
|
const chainId = await (0, core_1.getChainId)(provider);
|
|
862
|
-
const decimals = await
|
|
863
|
-
|
|
928
|
+
const [decimals, assetDecimals] = await Promise.all([
|
|
929
|
+
(0, core_1.getDecimals)(provider, pool),
|
|
930
|
+
buildDepositAssetDecimals(provider, accumulated?.deposits),
|
|
931
|
+
]);
|
|
932
|
+
const formattedRequests = sortUserHistory(accumulated, chainId, decimals, pool, assetDecimals);
|
|
864
933
|
return formattedRequests;
|
|
865
934
|
}
|
|
866
935
|
catch (e) {
|
package/lib/types/subgraph.d.ts
CHANGED
|
@@ -35,6 +35,14 @@ export interface ISubgraphDeposit extends ISubgraphBase {
|
|
|
35
35
|
owner: IAddress;
|
|
36
36
|
senderAddr?: IAddress;
|
|
37
37
|
amountIn?: string;
|
|
38
|
+
/**
|
|
39
|
+
* Deposit asset token address (evm-2 / pre-deposit vaults). The deposited
|
|
40
|
+
* asset can differ from the vault's underlying and carry different decimals
|
|
41
|
+
* (e.g. RLUSD at 18 into a 6-decimal sentUSD vault), so `amountIn` must be
|
|
42
|
+
* normalized against this token's decimals, not the vault's. Absent for
|
|
43
|
+
* single-asset vaults.
|
|
44
|
+
*/
|
|
45
|
+
assetIn?: IAddress;
|
|
38
46
|
}
|
|
39
47
|
export interface ISubgraphWithdrawRequest extends ISubgraphBase {
|
|
40
48
|
day: string;
|