@augustdigital/sdk 8.8.0 → 8.10.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/method-taxonomy.js +16 -0
- package/lib/core/analytics/version.d.ts +1 -1
- package/lib/core/analytics/version.js +1 -1
- package/lib/core/constants/core.d.ts +32 -0
- package/lib/core/constants/core.js +72 -0
- package/lib/core/constants/vaults.d.ts +5 -0
- package/lib/core/constants/vaults.js +7 -0
- package/lib/core/helpers/chain-error.d.ts +1 -0
- package/lib/core/helpers/chain-error.js +96 -0
- package/lib/main.js +1 -1
- package/lib/modules/api/fetcher.d.ts +82 -0
- package/lib/modules/api/fetcher.js +150 -0
- package/lib/modules/api/main.d.ts +263 -2
- package/lib/modules/api/main.js +353 -4
- package/lib/modules/sub-accounts/fetcher.d.ts +28 -1
- package/lib/modules/sub-accounts/fetcher.js +51 -1
- package/lib/modules/sub-accounts/main.d.ts +93 -1
- package/lib/modules/sub-accounts/main.js +123 -0
- package/lib/modules/vaults/write.actions.js +76 -6
- package/lib/sdk.d.ts +759 -1
- package/lib/types/api.d.ts +280 -0
- package/lib/types/api.js +3 -0
- package/lib/types/index.d.ts +1 -0
- package/lib/types/index.js +1 -0
- package/lib/types/sub-accounts.d.ts +36 -0
- package/package.json +1 -1
|
@@ -1,5 +1,32 @@
|
|
|
1
1
|
import { type IFetchAugustOptions } from '../../core';
|
|
2
|
-
import type { IAddress, IOTCPosition, IWSSubaccountCefi, IWSSubAccountHealthFactor, IWSSubaccountLoan, IWSSubaccountSummary } from '../../types';
|
|
2
|
+
import type { IAddress, ILoanBookInfo, IOTCPosition, ISubaccountDebank, ISubaccountTransaction, IWSSubaccountCefi, IWSSubAccountHealthFactor, IWSSubaccountListItem, IWSSubaccountLoan, IWSSubaccountSummary } from '../../types';
|
|
3
|
+
/**
|
|
4
|
+
* Fetch one page of the subaccount directory (admin-only backend endpoint)
|
|
5
|
+
*/
|
|
6
|
+
export declare const fetchAllSubaccounts: (pagination: {
|
|
7
|
+
offset?: number;
|
|
8
|
+
limit?: number;
|
|
9
|
+
}, augustKey: string, headers?: IFetchAugustOptions["headers"]) => Promise<IWSSubaccountListItem[]>;
|
|
10
|
+
/**
|
|
11
|
+
* Fetch a subaccount's transaction history (authenticated `GET
|
|
12
|
+
* /transactions/v2`), optionally windowed by ISO-8601 start/end datetimes.
|
|
13
|
+
*/
|
|
14
|
+
export declare const fetchSubaccountTransactions: (payload: {
|
|
15
|
+
address: IAddress;
|
|
16
|
+
startTime?: string;
|
|
17
|
+
endTime?: string;
|
|
18
|
+
}, augustKey: string, headers?: IFetchAugustOptions["headers"]) => Promise<ISubaccountTransaction[]>;
|
|
19
|
+
/**
|
|
20
|
+
* Fetch a single loan's loan-book detail by loan address + chain
|
|
21
|
+
* (admin-only `GET /subaccount/loans/{loan_address}`).
|
|
22
|
+
*/
|
|
23
|
+
export declare const fetchSubaccountLoanByAddress: (loanAddress: string, chainId: number, augustKey: string, headers?: IFetchAugustOptions["headers"]) => Promise<ILoanBookInfo>;
|
|
24
|
+
/**
|
|
25
|
+
* Fetch cross-chain DeBank positions for a subaccount (`GET
|
|
26
|
+
* /subaccount/{subaccount_address}/debank`). Slow endpoint (300-second
|
|
27
|
+
* server-side cache) — it fans out across every supported chain.
|
|
28
|
+
*/
|
|
29
|
+
export declare const fetchSubaccountDebank: (address: IAddress, augustKey: string, headers?: IFetchAugustOptions["headers"]) => Promise<ISubaccountDebank>;
|
|
3
30
|
/**
|
|
4
31
|
* Fetch subaccount health factor for a given subaccount address
|
|
5
32
|
*/
|
|
@@ -1,7 +1,57 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.fetchSubaccountSummary = exports.fetchSubaccountOtcPositions = exports.fetchSubaccountCefiPositions = exports.fetchSubaccountLoans = exports.fetchSubaccountHeathFactor = void 0;
|
|
3
|
+
exports.fetchSubaccountSummary = exports.fetchSubaccountOtcPositions = exports.fetchSubaccountCefiPositions = exports.fetchSubaccountLoans = exports.fetchSubaccountHeathFactor = exports.fetchSubaccountDebank = exports.fetchSubaccountLoanByAddress = exports.fetchSubaccountTransactions = exports.fetchAllSubaccounts = void 0;
|
|
4
4
|
const core_1 = require("../../core");
|
|
5
|
+
/**
|
|
6
|
+
* Fetch one page of the subaccount directory (admin-only backend endpoint)
|
|
7
|
+
*/
|
|
8
|
+
const fetchAllSubaccounts = async (pagination, augustKey, headers) => {
|
|
9
|
+
const response = await (0, core_1.fetchAugustWithKey)(augustKey, core_1.WEBSERVER_ENDPOINTS.subaccount.list(pagination.offset, pagination.limit), {
|
|
10
|
+
headers,
|
|
11
|
+
});
|
|
12
|
+
if (!response.ok || typeof response.json !== 'function') {
|
|
13
|
+
throw new Error(`Failed to fetch subaccounts: ${response.statusText || 'Unknown error'}`);
|
|
14
|
+
}
|
|
15
|
+
return response.json();
|
|
16
|
+
};
|
|
17
|
+
exports.fetchAllSubaccounts = fetchAllSubaccounts;
|
|
18
|
+
/**
|
|
19
|
+
* Fetch a subaccount's transaction history (authenticated `GET
|
|
20
|
+
* /transactions/v2`), optionally windowed by ISO-8601 start/end datetimes.
|
|
21
|
+
*/
|
|
22
|
+
const fetchSubaccountTransactions = async (payload, augustKey, headers) => {
|
|
23
|
+
const response = await (0, core_1.fetchAugustWithKey)(augustKey, core_1.WEBSERVER_ENDPOINTS.transactions.v2(payload.address, payload.startTime, payload.endTime), { headers });
|
|
24
|
+
if (!response.ok || typeof response.json !== 'function') {
|
|
25
|
+
throw new Error(`Failed to fetch subaccount transactions: ${response.statusText || 'Unknown error'}`);
|
|
26
|
+
}
|
|
27
|
+
return response.json();
|
|
28
|
+
};
|
|
29
|
+
exports.fetchSubaccountTransactions = fetchSubaccountTransactions;
|
|
30
|
+
/**
|
|
31
|
+
* Fetch a single loan's loan-book detail by loan address + chain
|
|
32
|
+
* (admin-only `GET /subaccount/loans/{loan_address}`).
|
|
33
|
+
*/
|
|
34
|
+
const fetchSubaccountLoanByAddress = async (loanAddress, chainId, augustKey, headers) => {
|
|
35
|
+
const response = await (0, core_1.fetchAugustWithKey)(augustKey, core_1.WEBSERVER_ENDPOINTS.subaccount.loanByAddress(loanAddress, chainId), { headers });
|
|
36
|
+
if (!response.ok || typeof response.json !== 'function') {
|
|
37
|
+
throw new Error(`Failed to fetch loan by address: ${response.statusText || 'Unknown error'}`);
|
|
38
|
+
}
|
|
39
|
+
return response.json();
|
|
40
|
+
};
|
|
41
|
+
exports.fetchSubaccountLoanByAddress = fetchSubaccountLoanByAddress;
|
|
42
|
+
/**
|
|
43
|
+
* Fetch cross-chain DeBank positions for a subaccount (`GET
|
|
44
|
+
* /subaccount/{subaccount_address}/debank`). Slow endpoint (300-second
|
|
45
|
+
* server-side cache) — it fans out across every supported chain.
|
|
46
|
+
*/
|
|
47
|
+
const fetchSubaccountDebank = async (address, augustKey, headers) => {
|
|
48
|
+
const response = await (0, core_1.fetchAugustWithKey)(augustKey, core_1.WEBSERVER_ENDPOINTS.subaccount.debank(address), { headers });
|
|
49
|
+
if (!response.ok || typeof response.json !== 'function') {
|
|
50
|
+
throw new Error(`Failed to fetch subaccount debank: ${response.statusText || 'Unknown error'}`);
|
|
51
|
+
}
|
|
52
|
+
return response.json();
|
|
53
|
+
};
|
|
54
|
+
exports.fetchSubaccountDebank = fetchSubaccountDebank;
|
|
5
55
|
/**
|
|
6
56
|
* Fetch subaccount health factor for a given subaccount address
|
|
7
57
|
*/
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { AugustBase, type IAugustBase } from '../../core';
|
|
2
|
-
import type { IAddress } from '../../types';
|
|
2
|
+
import type { IAddress, ILoanBookInfo, ISubaccountDebank, ISubaccountTransaction, IWSSubaccountListItem } from '../../types';
|
|
3
3
|
/**
|
|
4
4
|
* Subaccount operation class interacting with August Subaccounts
|
|
5
5
|
* Subaccount is a smart contract wallet that serves as the fundamental infrastructure for August's platform.
|
|
@@ -9,6 +9,31 @@ import type { IAddress } from '../../types';
|
|
|
9
9
|
export declare class AugustSubAccounts extends AugustBase {
|
|
10
10
|
private headers;
|
|
11
11
|
constructor(baseConfig: IAugustBase);
|
|
12
|
+
/**
|
|
13
|
+
* Retrieves one page of the directory of all August subaccounts.
|
|
14
|
+
*
|
|
15
|
+
* Backed by the admin-only `GET /subaccount` backend endpoint, so the
|
|
16
|
+
* August API key configured on the SDK must belong to an admin user —
|
|
17
|
+
* non-admin keys are rejected with an auth error by the backend. Makes
|
|
18
|
+
* exactly one HTTP request and no RPC calls.
|
|
19
|
+
*
|
|
20
|
+
* @param options - Pagination window over the subaccount directory
|
|
21
|
+
* @param options.offset - Number of records to skip. Defaults to 0; must be a non-negative integer.
|
|
22
|
+
* @param options.limit - Page size. Defaults to 100; must be an integer between 1 and 1000 (backend maximum).
|
|
23
|
+
* @returns The page of subaccount records (address, internal/friendly names, status, type, linked chains, risk metadata). An empty array means the offset is past the end of the directory.
|
|
24
|
+
* @throws AugustValidationError when `offset` or `limit` is out of range
|
|
25
|
+
* @throws AugustAuthError when the API key is missing or not admin-scoped
|
|
26
|
+
* @example
|
|
27
|
+
* const page = await augustSdk.subAccountsModule.getAllSubaccounts({
|
|
28
|
+
* offset: 0,
|
|
29
|
+
* limit: 200,
|
|
30
|
+
* });
|
|
31
|
+
* console.log(page.map((s) => `${s.internal_name}: ${s.address}`));
|
|
32
|
+
*/
|
|
33
|
+
getAllSubaccounts(options?: {
|
|
34
|
+
offset?: number;
|
|
35
|
+
limit?: number;
|
|
36
|
+
}): Promise<IWSSubaccountListItem[]>;
|
|
12
37
|
/**
|
|
13
38
|
* Retrieves the health factor for a subaccount.
|
|
14
39
|
* @param subaccountAddress - The address of the subaccount to query
|
|
@@ -148,4 +173,71 @@ export declare class AugustSubAccounts extends AugustBase {
|
|
|
148
173
|
netAccountValue: number;
|
|
149
174
|
totalEquityValue: number;
|
|
150
175
|
}>;
|
|
176
|
+
/**
|
|
177
|
+
* Retrieves a subaccount's on-chain transaction history, newest first,
|
|
178
|
+
* optionally windowed by a time range.
|
|
179
|
+
*
|
|
180
|
+
* Backed by the authenticated `GET /transactions/v2` backend endpoint,
|
|
181
|
+
* which resolves and authorizes the subaccount, so the configured August
|
|
182
|
+
* API key must be authorized for it (an admin-scoped key always is). Makes
|
|
183
|
+
* exactly one HTTP request and no RPC calls.
|
|
184
|
+
*
|
|
185
|
+
* @param subaccountAddress - The address of the subaccount to query
|
|
186
|
+
* @param options - Optional time window
|
|
187
|
+
* @param options.startTime - ISO-8601 datetime lower bound (inclusive); omit for no lower bound
|
|
188
|
+
* @param options.endTime - ISO-8601 datetime upper bound (inclusive); omit for no upper bound
|
|
189
|
+
* @returns The subaccount's transactions with decoded logs, transfers, and function names
|
|
190
|
+
* @throws AugustValidationError When `subaccountAddress` is not a valid EVM address
|
|
191
|
+
* @throws AugustAuthError When the API key is missing or not authorized for the subaccount
|
|
192
|
+
* @throws AugustServerError When the API responds with a non-2xx status
|
|
193
|
+
* @example
|
|
194
|
+
* const txs = await augustSdk.subAccountsModule.getSubaccountTransactions(
|
|
195
|
+
* '0xabc…',
|
|
196
|
+
* { startTime: '2026-01-01T00:00:00Z' },
|
|
197
|
+
* );
|
|
198
|
+
*/
|
|
199
|
+
getSubaccountTransactions(subaccountAddress: IAddress, options?: {
|
|
200
|
+
startTime?: string;
|
|
201
|
+
endTime?: string;
|
|
202
|
+
}): Promise<ISubaccountTransaction[]>;
|
|
203
|
+
/**
|
|
204
|
+
* Retrieves the full loan-book detail for a single loan by its address and
|
|
205
|
+
* chain.
|
|
206
|
+
*
|
|
207
|
+
* Backed by the admin-only `GET /subaccount/loans/{loan_address}` backend
|
|
208
|
+
* endpoint (60-second server-side cache), so the configured August API key
|
|
209
|
+
* must belong to an admin user. Makes exactly one HTTP request and no RPC
|
|
210
|
+
* calls.
|
|
211
|
+
*
|
|
212
|
+
* @param loanAddress - The loan contract address
|
|
213
|
+
* @param chainId - Numeric August chain id the loan lives on (e.g. `1` for Ethereum mainnet)
|
|
214
|
+
* @returns The loan's {@link ILoanBookInfo} detail
|
|
215
|
+
* @throws AugustValidationError When `chainId` is not an integer
|
|
216
|
+
* @throws AugustAuthError When the API key is missing or not admin-scoped
|
|
217
|
+
* @throws AugustServerError When the loan or chain is not found, or the API otherwise responds non-2xx
|
|
218
|
+
* @example
|
|
219
|
+
* const loan = await augustSdk.subAccountsModule.getSubaccountLoanByAddress(
|
|
220
|
+
* '0xloan…',
|
|
221
|
+
* 1,
|
|
222
|
+
* );
|
|
223
|
+
*/
|
|
224
|
+
getSubaccountLoanByAddress(loanAddress: string, chainId: number): Promise<ILoanBookInfo>;
|
|
225
|
+
/**
|
|
226
|
+
* Retrieves cross-chain DeBank protocol positions and token balances for a
|
|
227
|
+
* subaccount and its associated strategies.
|
|
228
|
+
*
|
|
229
|
+
* Backed by `GET /subaccount/{subaccount_address}/debank` (300-second
|
|
230
|
+
* server-side cache). This is a slow endpoint — it fans out to DeBank
|
|
231
|
+
* across every supported chain — so expect higher latency than other
|
|
232
|
+
* subaccount reads. Makes exactly one HTTP request and no RPC calls.
|
|
233
|
+
*
|
|
234
|
+
* @param subaccountAddress - The address of the subaccount to query
|
|
235
|
+
* @returns The subaccount's DeBank positions/tokens plus per-strategy breakdowns
|
|
236
|
+
* @throws AugustValidationError When `subaccountAddress` is not a valid EVM address
|
|
237
|
+
* @throws AugustServerError When the API responds with a non-2xx status
|
|
238
|
+
* @example
|
|
239
|
+
* const debank = await augustSdk.subAccountsModule.getSubaccountDebank('0xabc…');
|
|
240
|
+
* console.log(debank.subaccount.positions.length);
|
|
241
|
+
*/
|
|
242
|
+
getSubaccountDebank(subaccountAddress: IAddress): Promise<ISubaccountDebank>;
|
|
151
243
|
}
|
|
@@ -7,8 +7,20 @@ exports.AugustSubAccounts = void 0;
|
|
|
7
7
|
* @module AugustSubAccounts
|
|
8
8
|
*/
|
|
9
9
|
const fetcher_1 = require("./fetcher");
|
|
10
|
+
const ethers_1 = require("ethers");
|
|
10
11
|
const utils_1 = require("./utils");
|
|
11
12
|
const core_1 = require("../../core");
|
|
13
|
+
/**
|
|
14
|
+
* Validates that a subaccount address is a well-formed EVM address, throwing a
|
|
15
|
+
* typed {@link AugustValidationError} if not. August subaccounts are EVM
|
|
16
|
+
* smart-contract wallets, so an invalid value should fail fast in the SDK
|
|
17
|
+
* rather than reaching the backend.
|
|
18
|
+
*/
|
|
19
|
+
function assertSubaccountAddress(address, method) {
|
|
20
|
+
if (typeof address !== 'string' || !(0, ethers_1.isAddress)(address)) {
|
|
21
|
+
throw new core_1.AugustValidationError('INVALID_ADDRESS', `${method}: "${address}" is not a valid subaccount address — pass the subaccount's EVM (0x…) address.`);
|
|
22
|
+
}
|
|
23
|
+
}
|
|
12
24
|
/**
|
|
13
25
|
* Subaccount operation class interacting with August Subaccounts
|
|
14
26
|
* Subaccount is a smart contract wallet that serves as the fundamental infrastructure for August's platform.
|
|
@@ -24,6 +36,38 @@ class AugustSubAccounts extends core_1.AugustBase {
|
|
|
24
36
|
'x-user-id': this.monitoring?.['x-user-id'],
|
|
25
37
|
};
|
|
26
38
|
}
|
|
39
|
+
/**
|
|
40
|
+
* Retrieves one page of the directory of all August subaccounts.
|
|
41
|
+
*
|
|
42
|
+
* Backed by the admin-only `GET /subaccount` backend endpoint, so the
|
|
43
|
+
* August API key configured on the SDK must belong to an admin user —
|
|
44
|
+
* non-admin keys are rejected with an auth error by the backend. Makes
|
|
45
|
+
* exactly one HTTP request and no RPC calls.
|
|
46
|
+
*
|
|
47
|
+
* @param options - Pagination window over the subaccount directory
|
|
48
|
+
* @param options.offset - Number of records to skip. Defaults to 0; must be a non-negative integer.
|
|
49
|
+
* @param options.limit - Page size. Defaults to 100; must be an integer between 1 and 1000 (backend maximum).
|
|
50
|
+
* @returns The page of subaccount records (address, internal/friendly names, status, type, linked chains, risk metadata). An empty array means the offset is past the end of the directory.
|
|
51
|
+
* @throws AugustValidationError when `offset` or `limit` is out of range
|
|
52
|
+
* @throws AugustAuthError when the API key is missing or not admin-scoped
|
|
53
|
+
* @example
|
|
54
|
+
* const page = await augustSdk.subAccountsModule.getAllSubaccounts({
|
|
55
|
+
* offset: 0,
|
|
56
|
+
* limit: 200,
|
|
57
|
+
* });
|
|
58
|
+
* console.log(page.map((s) => `${s.internal_name}: ${s.address}`));
|
|
59
|
+
*/
|
|
60
|
+
async getAllSubaccounts(options = {}) {
|
|
61
|
+
const offset = options.offset ?? 0;
|
|
62
|
+
const limit = options.limit ?? 100;
|
|
63
|
+
if (!Number.isInteger(offset) || offset < 0) {
|
|
64
|
+
throw new core_1.AugustValidationError('INVALID_INPUT', `getAllSubaccounts: offset must be a non-negative integer, got ${offset}`);
|
|
65
|
+
}
|
|
66
|
+
if (!Number.isInteger(limit) || limit < 1 || limit > 1000) {
|
|
67
|
+
throw new core_1.AugustValidationError('INVALID_INPUT', `getAllSubaccounts: limit must be an integer between 1 and 1000, got ${limit}`);
|
|
68
|
+
}
|
|
69
|
+
return (0, fetcher_1.fetchAllSubaccounts)({ offset, limit }, this.keys.august, this.headers);
|
|
70
|
+
}
|
|
27
71
|
/**
|
|
28
72
|
* Retrieves the health factor for a subaccount.
|
|
29
73
|
* @param subaccountAddress - The address of the subaccount to query
|
|
@@ -77,6 +121,85 @@ class AugustSubAccounts extends core_1.AugustBase {
|
|
|
77
121
|
const response = await (0, fetcher_1.fetchSubaccountSummary)(subaccountAddress, this.keys.august, this.headers);
|
|
78
122
|
return (0, utils_1.transformSubaccountSummary)(response);
|
|
79
123
|
}
|
|
124
|
+
/**
|
|
125
|
+
* Retrieves a subaccount's on-chain transaction history, newest first,
|
|
126
|
+
* optionally windowed by a time range.
|
|
127
|
+
*
|
|
128
|
+
* Backed by the authenticated `GET /transactions/v2` backend endpoint,
|
|
129
|
+
* which resolves and authorizes the subaccount, so the configured August
|
|
130
|
+
* API key must be authorized for it (an admin-scoped key always is). Makes
|
|
131
|
+
* exactly one HTTP request and no RPC calls.
|
|
132
|
+
*
|
|
133
|
+
* @param subaccountAddress - The address of the subaccount to query
|
|
134
|
+
* @param options - Optional time window
|
|
135
|
+
* @param options.startTime - ISO-8601 datetime lower bound (inclusive); omit for no lower bound
|
|
136
|
+
* @param options.endTime - ISO-8601 datetime upper bound (inclusive); omit for no upper bound
|
|
137
|
+
* @returns The subaccount's transactions with decoded logs, transfers, and function names
|
|
138
|
+
* @throws AugustValidationError When `subaccountAddress` is not a valid EVM address
|
|
139
|
+
* @throws AugustAuthError When the API key is missing or not authorized for the subaccount
|
|
140
|
+
* @throws AugustServerError When the API responds with a non-2xx status
|
|
141
|
+
* @example
|
|
142
|
+
* const txs = await augustSdk.subAccountsModule.getSubaccountTransactions(
|
|
143
|
+
* '0xabc…',
|
|
144
|
+
* { startTime: '2026-01-01T00:00:00Z' },
|
|
145
|
+
* );
|
|
146
|
+
*/
|
|
147
|
+
async getSubaccountTransactions(subaccountAddress, options = {}) {
|
|
148
|
+
assertSubaccountAddress(subaccountAddress, 'getSubaccountTransactions');
|
|
149
|
+
return (0, fetcher_1.fetchSubaccountTransactions)({
|
|
150
|
+
address: subaccountAddress,
|
|
151
|
+
startTime: options.startTime,
|
|
152
|
+
endTime: options.endTime,
|
|
153
|
+
}, this.keys.august, this.headers);
|
|
154
|
+
}
|
|
155
|
+
/**
|
|
156
|
+
* Retrieves the full loan-book detail for a single loan by its address and
|
|
157
|
+
* chain.
|
|
158
|
+
*
|
|
159
|
+
* Backed by the admin-only `GET /subaccount/loans/{loan_address}` backend
|
|
160
|
+
* endpoint (60-second server-side cache), so the configured August API key
|
|
161
|
+
* must belong to an admin user. Makes exactly one HTTP request and no RPC
|
|
162
|
+
* calls.
|
|
163
|
+
*
|
|
164
|
+
* @param loanAddress - The loan contract address
|
|
165
|
+
* @param chainId - Numeric August chain id the loan lives on (e.g. `1` for Ethereum mainnet)
|
|
166
|
+
* @returns The loan's {@link ILoanBookInfo} detail
|
|
167
|
+
* @throws AugustValidationError When `chainId` is not an integer
|
|
168
|
+
* @throws AugustAuthError When the API key is missing or not admin-scoped
|
|
169
|
+
* @throws AugustServerError When the loan or chain is not found, or the API otherwise responds non-2xx
|
|
170
|
+
* @example
|
|
171
|
+
* const loan = await augustSdk.subAccountsModule.getSubaccountLoanByAddress(
|
|
172
|
+
* '0xloan…',
|
|
173
|
+
* 1,
|
|
174
|
+
* );
|
|
175
|
+
*/
|
|
176
|
+
async getSubaccountLoanByAddress(loanAddress, chainId) {
|
|
177
|
+
if (!Number.isInteger(chainId)) {
|
|
178
|
+
throw new core_1.AugustValidationError('INVALID_CHAIN', `getSubaccountLoanByAddress: chainId must be an integer August chain id, got ${chainId}.`);
|
|
179
|
+
}
|
|
180
|
+
return (0, fetcher_1.fetchSubaccountLoanByAddress)(loanAddress, chainId, this.keys.august, this.headers);
|
|
181
|
+
}
|
|
182
|
+
/**
|
|
183
|
+
* Retrieves cross-chain DeBank protocol positions and token balances for a
|
|
184
|
+
* subaccount and its associated strategies.
|
|
185
|
+
*
|
|
186
|
+
* Backed by `GET /subaccount/{subaccount_address}/debank` (300-second
|
|
187
|
+
* server-side cache). This is a slow endpoint — it fans out to DeBank
|
|
188
|
+
* across every supported chain — so expect higher latency than other
|
|
189
|
+
* subaccount reads. Makes exactly one HTTP request and no RPC calls.
|
|
190
|
+
*
|
|
191
|
+
* @param subaccountAddress - The address of the subaccount to query
|
|
192
|
+
* @returns The subaccount's DeBank positions/tokens plus per-strategy breakdowns
|
|
193
|
+
* @throws AugustValidationError When `subaccountAddress` is not a valid EVM address
|
|
194
|
+
* @throws AugustServerError When the API responds with a non-2xx status
|
|
195
|
+
* @example
|
|
196
|
+
* const debank = await augustSdk.subAccountsModule.getSubaccountDebank('0xabc…');
|
|
197
|
+
* console.log(debank.subaccount.positions.length);
|
|
198
|
+
*/
|
|
199
|
+
async getSubaccountDebank(subaccountAddress) {
|
|
200
|
+
assertSubaccountAddress(subaccountAddress, 'getSubaccountDebank');
|
|
201
|
+
return (0, fetcher_1.fetchSubaccountDebank)(subaccountAddress, this.keys.august, this.headers);
|
|
202
|
+
}
|
|
80
203
|
}
|
|
81
204
|
exports.AugustSubAccounts = AugustSubAccounts;
|
|
82
205
|
//# sourceMappingURL=main.js.map
|
|
@@ -185,6 +185,39 @@ async function tryRecoverTxHash(error, signer, wait) {
|
|
|
185
185
|
}
|
|
186
186
|
return txHash;
|
|
187
187
|
}
|
|
188
|
+
/**
|
|
189
|
+
* Rethrow a caught write-path error as a typed {@link AugustValidationError}
|
|
190
|
+
* when it is the chain node reporting the sender can't afford the transaction's
|
|
191
|
+
* gas/fee (see {@link isInsufficientFundsError}).
|
|
192
|
+
*
|
|
193
|
+
* Why: for an underfunded account ethers surfaces an opaque `CALL_EXCEPTION` /
|
|
194
|
+
* "missing revert data" that gives the caller no stable way to tell "user needs
|
|
195
|
+
* gas" apart from a genuine on-chain failure. Converting it to the
|
|
196
|
+
* `ACCOUNT_NOT_FUNDED` code lets a consuming UI branch on `err.code` (e.g. show
|
|
197
|
+
* a "top up to cover network fees" prompt) instead of string-matching. Every
|
|
198
|
+
* write path shares this so the classification is identical across
|
|
199
|
+
* deposit/redeem/approve rather than drifting per call site.
|
|
200
|
+
*
|
|
201
|
+
* A no-op when `isInsufficient` is `false`, so callers fall through to their
|
|
202
|
+
* existing handling unchanged. The caller passes the already-computed
|
|
203
|
+
* classification (it also feeds the telemetry-demotion decision) so
|
|
204
|
+
* {@link isInsufficientFundsError} runs once per catch, not twice.
|
|
205
|
+
*
|
|
206
|
+
* @param isInsufficient - Result of {@link isInsufficientFundsError} for
|
|
207
|
+
* `error`, computed once by the caller and shared with the benign-log flag.
|
|
208
|
+
* @param operation - Human-readable label for the attempted write (e.g.
|
|
209
|
+
* `'Request redeem'`), used verbatim in the thrown error's message.
|
|
210
|
+
* @param error - The caught value, of unknown type, preserved as the thrown
|
|
211
|
+
* error's `cause`.
|
|
212
|
+
* @param context - Structured context attached to the thrown error for logging.
|
|
213
|
+
* @throws {AugustValidationError} with code `ACCOUNT_NOT_FUNDED` when
|
|
214
|
+
* `isInsufficient` is `true`.
|
|
215
|
+
*/
|
|
216
|
+
function throwIfInsufficientFunds(isInsufficient, operation, error, context) {
|
|
217
|
+
if (!isInsufficient)
|
|
218
|
+
return;
|
|
219
|
+
throw new core_1.AugustValidationError('ACCOUNT_NOT_FUNDED', `${operation} failed: insufficient native balance to cover gas/network fees`, { cause: error, context });
|
|
220
|
+
}
|
|
188
221
|
async function approveCore(signer, options) {
|
|
189
222
|
const { wallet, target, wait, amount, depositAsset } = options;
|
|
190
223
|
const [goodWallet, goodPool] = [
|
|
@@ -293,7 +326,12 @@ async function approveCore(signer, options) {
|
|
|
293
326
|
throw e;
|
|
294
327
|
// A user declining the approval in their wallet is product behaviour, not
|
|
295
328
|
// an SDK fault — demote it to a breadcrumb so it doesn't bill as an issue.
|
|
296
|
-
|
|
329
|
+
const insufficientFunds = (0, core_1.isInsufficientFundsError)(e);
|
|
330
|
+
(0, core_1.logChainError)('vaultApprove', e, (0, core_1.isUserRejectionError)(e) || insufficientFunds, {
|
|
331
|
+
target,
|
|
332
|
+
amount,
|
|
333
|
+
});
|
|
334
|
+
throwIfInsufficientFunds(insufficientFunds, 'Approval', e, {
|
|
297
335
|
target,
|
|
298
336
|
amount,
|
|
299
337
|
});
|
|
@@ -601,7 +639,13 @@ async function vaultDeposit(signer, options) {
|
|
|
601
639
|
if (e instanceof core_1.AugustSDKError)
|
|
602
640
|
throw e;
|
|
603
641
|
// User-cancelled deposits are normal; only genuine failures stay at error.
|
|
604
|
-
|
|
642
|
+
const insufficientFunds = (0, core_1.isInsufficientFundsError)(e);
|
|
643
|
+
(0, core_1.logChainError)('deposit', e, (0, core_1.isUserRejectionError)(e) || insufficientFunds, {
|
|
644
|
+
target,
|
|
645
|
+
amount,
|
|
646
|
+
depositAsset,
|
|
647
|
+
});
|
|
648
|
+
throwIfInsufficientFunds(insufficientFunds, 'Deposit', e, {
|
|
605
649
|
target,
|
|
606
650
|
amount,
|
|
607
651
|
depositAsset,
|
|
@@ -754,7 +798,12 @@ async function vaultRequestRedeem(signer, options) {
|
|
|
754
798
|
if (e instanceof core_1.AugustSDKError)
|
|
755
799
|
throw e;
|
|
756
800
|
// User-cancelled redeem requests are normal; only genuine failures stay at error.
|
|
757
|
-
|
|
801
|
+
const insufficientFunds = (0, core_1.isInsufficientFundsError)(e);
|
|
802
|
+
(0, core_1.logChainError)('requestRedeem', e, (0, core_1.isUserRejectionError)(e) || insufficientFunds, {
|
|
803
|
+
target,
|
|
804
|
+
amount,
|
|
805
|
+
});
|
|
806
|
+
throwIfInsufficientFunds(insufficientFunds, 'Request redeem', e, {
|
|
758
807
|
target,
|
|
759
808
|
amount,
|
|
760
809
|
});
|
|
@@ -801,7 +850,15 @@ async function vaultRedeem(signer, options) {
|
|
|
801
850
|
if (e instanceof core_1.AugustSDKError)
|
|
802
851
|
throw e;
|
|
803
852
|
// User-cancelled redeems are normal; only genuine failures stay at error.
|
|
804
|
-
|
|
853
|
+
const insufficientFunds = (0, core_1.isInsufficientFundsError)(e);
|
|
854
|
+
(0, core_1.logChainError)('redeem', e, (0, core_1.isUserRejectionError)(e) || insufficientFunds, {
|
|
855
|
+
target,
|
|
856
|
+
year,
|
|
857
|
+
month,
|
|
858
|
+
day,
|
|
859
|
+
receiverIndex,
|
|
860
|
+
});
|
|
861
|
+
throwIfInsufficientFunds(insufficientFunds, 'Redeem', e, {
|
|
805
862
|
target,
|
|
806
863
|
year,
|
|
807
864
|
month,
|
|
@@ -899,7 +956,13 @@ async function depositNative(signer, options) {
|
|
|
899
956
|
if (e instanceof core_1.AugustSDKError)
|
|
900
957
|
throw e;
|
|
901
958
|
// User-cancelled native deposits are normal; only genuine failures stay at error.
|
|
902
|
-
|
|
959
|
+
const insufficientFunds = (0, core_1.isInsufficientFundsError)(e);
|
|
960
|
+
(0, core_1.logChainError)('depositNative', e, (0, core_1.isUserRejectionError)(e) || insufficientFunds, {
|
|
961
|
+
wrapperAddress,
|
|
962
|
+
receiver,
|
|
963
|
+
amount,
|
|
964
|
+
});
|
|
965
|
+
throwIfInsufficientFunds(insufficientFunds, 'Deposit native', e, {
|
|
903
966
|
wrapperAddress,
|
|
904
967
|
receiver,
|
|
905
968
|
amount,
|
|
@@ -978,7 +1041,14 @@ async function rwaRedeemAsset(signer, options) {
|
|
|
978
1041
|
if (e instanceof core_1.AugustSDKError)
|
|
979
1042
|
throw e;
|
|
980
1043
|
// User-cancelled RWA redeems are normal; only genuine failures stay at error.
|
|
981
|
-
|
|
1044
|
+
const insufficientFunds = (0, core_1.isInsufficientFundsError)(e);
|
|
1045
|
+
(0, core_1.logChainError)('rwaRedeemAsset', e, (0, core_1.isUserRejectionError)(e) || insufficientFunds, {
|
|
1046
|
+
target,
|
|
1047
|
+
asset,
|
|
1048
|
+
amount,
|
|
1049
|
+
minOut,
|
|
1050
|
+
});
|
|
1051
|
+
throwIfInsufficientFunds(insufficientFunds, 'RWA redeem', e, {
|
|
982
1052
|
target,
|
|
983
1053
|
asset,
|
|
984
1054
|
amount,
|