@augustdigital/sdk 8.0.0 → 8.3.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/abis/SwapRouter.d.ts +1042 -0
- package/lib/abis/SwapRouter.js +739 -0
- package/lib/abis/index.d.ts +1 -0
- package/lib/abis/index.js +1 -0
- package/lib/adapters/evm/index.d.ts +4 -0
- package/lib/adapters/evm/index.js +12 -0
- package/lib/adapters/stellar/constants.d.ts +1 -1
- package/lib/adapters/stellar/constants.js +1 -1
- package/lib/adapters/stellar/getters.d.ts +1 -1
- package/lib/adapters/stellar/getters.js +9 -5
- package/lib/adapters/stellar/index.d.ts +1 -1
- package/lib/adapters/stellar/soroban.js +27 -5
- package/lib/adapters/stellar/types.d.ts +1 -0
- package/lib/adapters/sui/getters.js +3 -2
- package/lib/core/analytics/method-taxonomy.js +3 -0
- package/lib/core/analytics/sentry.js +37 -0
- package/lib/core/analytics/version.d.ts +1 -1
- package/lib/core/analytics/version.js +1 -1
- package/lib/core/base.class.js +1 -1
- package/lib/core/constants/swap-router.d.ts +8 -0
- package/lib/core/constants/swap-router.js +18 -0
- package/lib/core/fetcher.d.ts +1 -1
- package/lib/core/fetcher.js +4 -4
- package/lib/core/helpers/core.d.ts +1 -1
- package/lib/core/helpers/core.js +1 -1
- package/lib/core/helpers/swap-router.d.ts +4 -0
- package/lib/core/helpers/swap-router.js +22 -0
- package/lib/core/helpers/web3.js +10 -10
- package/lib/core/index.d.ts +2 -0
- package/lib/core/index.js +2 -0
- package/lib/core/logger/index.d.ts +12 -0
- package/lib/core/logger/index.js +13 -1
- package/lib/index.d.ts +1 -0
- package/lib/index.js +1 -0
- package/lib/modules/vaults/fetcher.js +4 -1
- package/lib/modules/vaults/getters.d.ts +2 -2
- package/lib/modules/vaults/getters.js +4 -1
- package/lib/modules/vaults/utils.d.ts +1 -1
- package/lib/modules/vaults/utils.js +3 -2
- package/lib/modules/vaults/write.actions.d.ts +9 -2
- package/lib/modules/vaults/write.actions.js +263 -2
- package/lib/services/swap-quotes/index.d.ts +25 -0
- package/lib/services/swap-quotes/index.js +51 -0
- package/lib/services/swap-quotes/paraswap.d.ts +26 -0
- package/lib/services/swap-quotes/paraswap.js +116 -0
- package/lib/types/vaults.d.ts +29 -0
- package/lib/types/vaults.js +6 -1
- package/package.json +4 -11
package/lib/abis/index.d.ts
CHANGED
package/lib/abis/index.js
CHANGED
|
@@ -42,4 +42,5 @@ __exportStar(require("./MultiAssetNativeDepositWrapper"), exports);
|
|
|
42
42
|
__exportStar(require("./TokenizedVaultV2SenderAllocationWhitelist"), exports);
|
|
43
43
|
__exportStar(require("./RwaRedeemSubaccount"), exports);
|
|
44
44
|
__exportStar(require("./OFT"), exports);
|
|
45
|
+
__exportStar(require("./SwapRouter"), exports);
|
|
45
46
|
//# sourceMappingURL=index.js.map
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { IContractWriteOptions, INativeDepositOptions, ApproveResult } from '../../modules/vaults/write.actions';
|
|
2
|
+
import type { ISwapAndDepositOptions, ISwapRouterDirectDepositOptions, ISwapRouterNativeDepositOptions } from '../../types';
|
|
2
3
|
import { IPreviewDepositOptions, IPreviewRedeemOptions, IAllowanceOptions, IBalanceOfOptions, IMaxDepositOptions } from '../../modules/vaults/read.actions';
|
|
3
4
|
import { CompatibleSigner } from '../../core/helpers/signer';
|
|
4
5
|
import { IAddress } from '../../types';
|
|
@@ -15,6 +16,9 @@ declare class EVMAdapter {
|
|
|
15
16
|
vaultDeposit(options: IContractWriteOptions): Promise<string>;
|
|
16
17
|
vaultRequestRedeem(options: IContractWriteOptions): Promise<string>;
|
|
17
18
|
depositNative(options: INativeDepositOptions): Promise<string>;
|
|
19
|
+
swapAndDeposit(options: ISwapAndDepositOptions): Promise<string>;
|
|
20
|
+
depositViaSwapRouter(options: ISwapRouterDirectDepositOptions): Promise<string>;
|
|
21
|
+
depositNativeViaSwapRouter(options: ISwapRouterNativeDepositOptions): Promise<string>;
|
|
18
22
|
vaultRedeem(options: IContractWriteOptions & {
|
|
19
23
|
year: string;
|
|
20
24
|
month: string;
|
|
@@ -60,6 +60,18 @@ class EVMAdapter {
|
|
|
60
60
|
const signer = await this.getSigner();
|
|
61
61
|
return (0, write_actions_1.depositNative)(signer, options);
|
|
62
62
|
}
|
|
63
|
+
async swapAndDeposit(options) {
|
|
64
|
+
const signer = await this.getSigner();
|
|
65
|
+
return (0, write_actions_1.swapAndDeposit)(signer, options);
|
|
66
|
+
}
|
|
67
|
+
async depositViaSwapRouter(options) {
|
|
68
|
+
const signer = await this.getSigner();
|
|
69
|
+
return (0, write_actions_1.depositViaSwapRouter)(signer, options);
|
|
70
|
+
}
|
|
71
|
+
async depositNativeViaSwapRouter(options) {
|
|
72
|
+
const signer = await this.getSigner();
|
|
73
|
+
return (0, write_actions_1.depositNativeViaSwapRouter)(signer, options);
|
|
74
|
+
}
|
|
63
75
|
async vaultRedeem(options) {
|
|
64
76
|
const signer = await this.getSigner();
|
|
65
77
|
return (0, write_actions_1.vaultRedeem)(signer, options);
|
|
@@ -8,7 +8,7 @@ export declare const STELLAR_CHAIN: {
|
|
|
8
8
|
export declare const SOROBAN_RPC_URLS: Record<IStellarNetwork, string>;
|
|
9
9
|
export declare const NETWORK_PASSPHRASES: Record<IStellarNetwork, string>;
|
|
10
10
|
export declare const STELLAR_FALLBACK_DECIMALS = 7;
|
|
11
|
-
export declare const TX_TIMEOUT_SECONDS =
|
|
11
|
+
export declare const TX_TIMEOUT_SECONDS = 600;
|
|
12
12
|
export declare const QUERY_TIMEOUT_SECONDS = 10;
|
|
13
13
|
export declare const MAX_FEE_STROOPS = "1000000";
|
|
14
14
|
export declare const POLL_INTERVAL_MS = 2000;
|
|
@@ -14,7 +14,7 @@ exports.NETWORK_PASSPHRASES = {
|
|
|
14
14
|
testnet: stellar_sdk_1.Networks.TESTNET,
|
|
15
15
|
};
|
|
16
16
|
exports.STELLAR_FALLBACK_DECIMALS = 7;
|
|
17
|
-
exports.TX_TIMEOUT_SECONDS =
|
|
17
|
+
exports.TX_TIMEOUT_SECONDS = 600;
|
|
18
18
|
exports.QUERY_TIMEOUT_SECONDS = 10;
|
|
19
19
|
exports.MAX_FEE_STROOPS = '1000000';
|
|
20
20
|
exports.POLL_INTERVAL_MS = 2000;
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { ITokenizedVault, IVault } from '../../types';
|
|
1
|
+
import type { ITokenizedVault, IVault } from '../../types';
|
|
2
2
|
import type { IVaultBaseOptions } from '../../modules/vaults/types';
|
|
3
3
|
import type { IStellarNetwork, IStellarUserPosition } from './types';
|
|
4
4
|
export declare const getStellarVault: (tokenizedVault: ITokenizedVault, _options: IVaultBaseOptions) => Promise<IVault>;
|
|
@@ -6,16 +6,16 @@ const core_1 = require("../../core");
|
|
|
6
6
|
const utils_1 = require("../../modules/vaults/utils");
|
|
7
7
|
const constants_1 = require("./constants");
|
|
8
8
|
const soroban_1 = require("./soroban");
|
|
9
|
-
function
|
|
9
|
+
function parseDecimals(scVal, context, vaultAddress) {
|
|
10
10
|
if (!scVal) {
|
|
11
11
|
core_1.Logger.log.error(context, 'Decimals not available — using fallback (financial values may be incorrect)', {
|
|
12
12
|
vault: vaultAddress,
|
|
13
13
|
fallbackDecimals: constants_1.STELLAR_FALLBACK_DECIMALS,
|
|
14
14
|
});
|
|
15
|
-
return constants_1.STELLAR_FALLBACK_DECIMALS;
|
|
15
|
+
return { decimals: constants_1.STELLAR_FALLBACK_DECIMALS, fromFallback: true };
|
|
16
16
|
}
|
|
17
17
|
try {
|
|
18
|
-
return Number((0, stellar_sdk_1.scValToBigInt)(scVal));
|
|
18
|
+
return { decimals: Number((0, stellar_sdk_1.scValToBigInt)(scVal)), fromFallback: false };
|
|
19
19
|
}
|
|
20
20
|
catch (parseErr) {
|
|
21
21
|
core_1.Logger.log.error(context, 'Failed to parse decimals from Soroban — using fallback (financial values may be incorrect)', {
|
|
@@ -23,9 +23,12 @@ function parseDecimalsOrFallback(scVal, context, vaultAddress) {
|
|
|
23
23
|
fallbackDecimals: constants_1.STELLAR_FALLBACK_DECIMALS,
|
|
24
24
|
error: String(parseErr),
|
|
25
25
|
});
|
|
26
|
-
return constants_1.STELLAR_FALLBACK_DECIMALS;
|
|
26
|
+
return { decimals: constants_1.STELLAR_FALLBACK_DECIMALS, fromFallback: true };
|
|
27
27
|
}
|
|
28
28
|
}
|
|
29
|
+
function parseDecimalsOrFallback(scVal, context, vaultAddress) {
|
|
30
|
+
return parseDecimals(scVal, context, vaultAddress).decimals;
|
|
31
|
+
}
|
|
29
32
|
function resolveNetwork(tokenizedVault) {
|
|
30
33
|
const meta = tokenizedVault.stellar_vault_metadata;
|
|
31
34
|
const networkName = meta?.network_name;
|
|
@@ -125,7 +128,7 @@ const getStellarUserPosition = async (vaultAddress, walletAddress, network = 'ma
|
|
|
125
128
|
(0, soroban_1.queryContract)(config, vaultAddress, 'balance', [userAddress.toScVal()]),
|
|
126
129
|
(0, soroban_1.queryContract)(config, vaultAddress, 'decimals'),
|
|
127
130
|
]);
|
|
128
|
-
const decimals =
|
|
131
|
+
const { decimals, fromFallback: decimalsFromFallback } = parseDecimals(decimalsResult, 'getStellarUserPosition', vaultAddress);
|
|
129
132
|
if (!balanceResult) {
|
|
130
133
|
core_1.Logger.log.warn('getStellarUserPosition', 'Balance query returned null', {
|
|
131
134
|
vault: vaultAddress,
|
|
@@ -148,6 +151,7 @@ const getStellarUserPosition = async (vaultAddress, walletAddress, network = 'ma
|
|
|
148
151
|
return {
|
|
149
152
|
shares: rawBalance.toString(),
|
|
150
153
|
decimals,
|
|
154
|
+
decimalsFromFallback,
|
|
151
155
|
};
|
|
152
156
|
}
|
|
153
157
|
catch (err) {
|
|
@@ -2,7 +2,7 @@ import * as StellarConstants from './constants';
|
|
|
2
2
|
import * as StellarGetters from './getters';
|
|
3
3
|
import * as StellarActions from './actions';
|
|
4
4
|
import * as StellarSubmit from './submit';
|
|
5
|
-
import { IStellarNetwork, IStellarDepositParams, IStellarRedeemParams, IStellarUserPosition } from './types';
|
|
5
|
+
import type { IStellarNetwork, IStellarDepositParams, IStellarRedeemParams, IStellarUserPosition } from './types';
|
|
6
6
|
export declare const Stellar: {
|
|
7
7
|
utils: {
|
|
8
8
|
isStellarAddress: typeof import("./utils").isStellarAddress;
|
|
@@ -76,8 +76,25 @@ async function queryContract(config, contractId, method, args = []) {
|
|
|
76
76
|
return null;
|
|
77
77
|
}
|
|
78
78
|
}
|
|
79
|
+
async function getNetworkCloseTime(server) {
|
|
80
|
+
try {
|
|
81
|
+
const { sequence } = await server.getLatestLedger();
|
|
82
|
+
const page = await server.getLedgers({
|
|
83
|
+
startLedger: sequence,
|
|
84
|
+
pagination: { limit: 1 },
|
|
85
|
+
});
|
|
86
|
+
return typeof page.latestLedgerCloseTime === 'number'
|
|
87
|
+
? page.latestLedgerCloseTime
|
|
88
|
+
: null;
|
|
89
|
+
}
|
|
90
|
+
catch (err) {
|
|
91
|
+
core_1.Logger.log.warn('getNetworkCloseTime', `Network clock unavailable; falling back to local clock for tx timebounds: ${String(err)}`);
|
|
92
|
+
return null;
|
|
93
|
+
}
|
|
94
|
+
}
|
|
79
95
|
async function buildSorobanTx(config, sourceAddress, contractId, method, args) {
|
|
80
96
|
const server = createServer(config.rpcUrl);
|
|
97
|
+
const networkCloseTimePromise = getNetworkCloseTime(server);
|
|
81
98
|
let account;
|
|
82
99
|
try {
|
|
83
100
|
account = await server.getAccount(sourceAddress);
|
|
@@ -91,13 +108,18 @@ async function buildSorobanTx(config, sourceAddress, contractId, method, args) {
|
|
|
91
108
|
throw err;
|
|
92
109
|
}
|
|
93
110
|
const contract = new stellar_sdk_1.Contract(contractId);
|
|
94
|
-
const
|
|
111
|
+
const builder = new stellar_sdk_1.TransactionBuilder(account, {
|
|
95
112
|
fee: constants_1.MAX_FEE_STROOPS,
|
|
96
113
|
networkPassphrase: config.passphrase,
|
|
97
|
-
})
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
.
|
|
114
|
+
}).addOperation(contract.call(method, ...args));
|
|
115
|
+
const networkCloseTime = await networkCloseTimePromise;
|
|
116
|
+
if (networkCloseTime !== null) {
|
|
117
|
+
builder.setTimebounds(0, networkCloseTime + constants_1.TX_TIMEOUT_SECONDS);
|
|
118
|
+
}
|
|
119
|
+
else {
|
|
120
|
+
builder.setTimeout(constants_1.TX_TIMEOUT_SECONDS);
|
|
121
|
+
}
|
|
122
|
+
const tx = builder.build();
|
|
101
123
|
const simulated = await server.simulateTransaction(tx);
|
|
102
124
|
if (stellar_sdk_1.rpc.Api.isSimulationError(simulated)) {
|
|
103
125
|
throw new core_1.AugustSDKError('UNKNOWN', `Soroban simulation failed: ${extractSimulationError(simulated)}`, { context: { method, contractId } });
|
|
@@ -4,6 +4,7 @@ exports.getEmberVaults = getEmberVaults;
|
|
|
4
4
|
exports.getEmberTVL = getEmberTVL;
|
|
5
5
|
const constants_1 = require("./constants");
|
|
6
6
|
const core_1 = require("../../core");
|
|
7
|
+
const logger_1 = require("../../core/logger");
|
|
7
8
|
async function getEmberVaults(options) {
|
|
8
9
|
try {
|
|
9
10
|
const params = new URLSearchParams();
|
|
@@ -23,7 +24,7 @@ async function getEmberVaults(options) {
|
|
|
23
24
|
return Array.isArray(data) ? data : [];
|
|
24
25
|
}
|
|
25
26
|
catch (error) {
|
|
26
|
-
|
|
27
|
+
logger_1.Logger.log.error('getEmberVaults', error);
|
|
27
28
|
return [];
|
|
28
29
|
}
|
|
29
30
|
}
|
|
@@ -46,7 +47,7 @@ async function getEmberTVL(limit = 1) {
|
|
|
46
47
|
return 0;
|
|
47
48
|
}
|
|
48
49
|
catch (error) {
|
|
49
|
-
|
|
50
|
+
logger_1.Logger.log.error('getEmberTVL', error);
|
|
50
51
|
return 0;
|
|
51
52
|
}
|
|
52
53
|
}
|
|
@@ -65,6 +65,9 @@ exports.METHOD_CATEGORIES = {
|
|
|
65
65
|
maxDeposit: 'read.vault',
|
|
66
66
|
vaultDeposit: 'write.deposit',
|
|
67
67
|
depositNative: 'write.deposit',
|
|
68
|
+
swapAndDeposit: 'write.deposit',
|
|
69
|
+
depositViaSwapRouter: 'write.deposit',
|
|
70
|
+
depositNativeViaSwapRouter: 'write.deposit',
|
|
68
71
|
vaultRedeem: 'write.redeem',
|
|
69
72
|
vaultRequestRedeem: 'write.redeem',
|
|
70
73
|
rwaRedeemAsset: 'write.redeem',
|
|
@@ -56,6 +56,41 @@ function safeSetUser(user) {
|
|
|
56
56
|
catch {
|
|
57
57
|
}
|
|
58
58
|
}
|
|
59
|
+
function createSentrySink() {
|
|
60
|
+
return {
|
|
61
|
+
captureException(error, context) {
|
|
62
|
+
try {
|
|
63
|
+
const sdk = (0, sentry_runtime_1.getSentrySDK)();
|
|
64
|
+
if (!sdk)
|
|
65
|
+
return;
|
|
66
|
+
sdk.withScope((scope) => {
|
|
67
|
+
scope.setTag('sdk', 'august-digital');
|
|
68
|
+
if (context) {
|
|
69
|
+
for (const [key, value] of Object.entries(context)) {
|
|
70
|
+
if (key === 'tag' && typeof value === 'string') {
|
|
71
|
+
scope.setTag('sdk.origin', value);
|
|
72
|
+
}
|
|
73
|
+
else {
|
|
74
|
+
scope.setExtra(key, value);
|
|
75
|
+
}
|
|
76
|
+
}
|
|
77
|
+
}
|
|
78
|
+
const normalized = error instanceof Error ? error : new Error(String(error));
|
|
79
|
+
sdk.captureException(normalized);
|
|
80
|
+
});
|
|
81
|
+
}
|
|
82
|
+
catch {
|
|
83
|
+
}
|
|
84
|
+
},
|
|
85
|
+
addBreadcrumb(breadcrumb) {
|
|
86
|
+
try {
|
|
87
|
+
(0, sentry_runtime_1.getSentrySDK)()?.addBreadcrumb(breadcrumb);
|
|
88
|
+
}
|
|
89
|
+
catch {
|
|
90
|
+
}
|
|
91
|
+
},
|
|
92
|
+
};
|
|
93
|
+
}
|
|
59
94
|
function initializeSentry(config, environment, walletAddress, apiKey, appName) {
|
|
60
95
|
if (isInitialized) {
|
|
61
96
|
if (isEnabled) {
|
|
@@ -144,6 +179,7 @@ function initializeSentry(config, environment, walletAddress, apiKey, appName) {
|
|
|
144
179
|
}
|
|
145
180
|
safeSetTag('partner.id', appName ? `unverified:${appName}` : 'unverified:anonymous');
|
|
146
181
|
safeSetTag('partner.tier', 'unverified');
|
|
182
|
+
logger_1.Logger.setSentrySink(createSentrySink());
|
|
147
183
|
isInitialized = true;
|
|
148
184
|
logger_1.Logger.log.info('analytics.initialized', {
|
|
149
185
|
runtime: (0, sentry_runtime_1.getSentryRuntime)(),
|
|
@@ -219,6 +255,7 @@ function resetAnalytics() {
|
|
|
219
255
|
isEnabled = true;
|
|
220
256
|
currentIdentity = null;
|
|
221
257
|
cachedApiKey = undefined;
|
|
258
|
+
logger_1.Logger.setSentrySink(null);
|
|
222
259
|
(0, sentry_runtime_1.resetSentryRuntime)();
|
|
223
260
|
}
|
|
224
261
|
async function captureSdkException(error, options) {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
export declare const SDK_VERSION = "8.
|
|
1
|
+
export declare const SDK_VERSION = "8.3.0";
|
package/lib/core/base.class.js
CHANGED
|
@@ -55,7 +55,7 @@ class AugustBase {
|
|
|
55
55
|
if (!augustCheck)
|
|
56
56
|
throw new Error('August Digital API key is invalid.');
|
|
57
57
|
this.authorized = true;
|
|
58
|
-
|
|
58
|
+
logger_1.Logger.log.info('init', 'August Digital SDK successfully initialized');
|
|
59
59
|
return;
|
|
60
60
|
}
|
|
61
61
|
requireActiveNetwork() {
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import { IAddress } from '../../types';
|
|
2
|
+
export declare const SWAP_ROUTER_ADDRESSES: Readonly<Record<number, IAddress>>;
|
|
3
|
+
export declare const VAULTS_USING_SWAP_ROUTER: ReadonlySet<string>;
|
|
4
|
+
export declare const ORIGIN_CODES: {
|
|
5
|
+
readonly default: `0x${string}`;
|
|
6
|
+
};
|
|
7
|
+
export declare const SWAP_ROUTER_MAX_SWAPS = 9;
|
|
8
|
+
export declare const SWAP_ROUTER_WRAPPED_NATIVE: Readonly<Record<number, IAddress>>;
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.SWAP_ROUTER_WRAPPED_NATIVE = exports.SWAP_ROUTER_MAX_SWAPS = exports.ORIGIN_CODES = exports.VAULTS_USING_SWAP_ROUTER = exports.SWAP_ROUTER_ADDRESSES = void 0;
|
|
4
|
+
exports.SWAP_ROUTER_ADDRESSES = {
|
|
5
|
+
1: '0xAC771209FF2b71EECfF6E85a9AD01db8Ff2618B0',
|
|
6
|
+
};
|
|
7
|
+
exports.VAULTS_USING_SWAP_ROUTER = new Set([
|
|
8
|
+
'0xe9b725010a9e419412ed67d0fa5f3a5f40159d32',
|
|
9
|
+
'0x74ad2f789ed583dbd141bbdafc673fe1f033718b',
|
|
10
|
+
]);
|
|
11
|
+
exports.ORIGIN_CODES = {
|
|
12
|
+
default: '0x0000000000000000000000000000000000000000000000000000000000000000',
|
|
13
|
+
};
|
|
14
|
+
exports.SWAP_ROUTER_MAX_SWAPS = 9;
|
|
15
|
+
exports.SWAP_ROUTER_WRAPPED_NATIVE = {
|
|
16
|
+
1: '0xC02aaA39b223FE8D0A0e5C4F27eAD9083C756Cc2',
|
|
17
|
+
};
|
|
18
|
+
//# sourceMappingURL=swap-router.js.map
|
package/lib/core/fetcher.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { IAddress, IContractRunner, IHistoricalTimeseriesResponse, ITokenizedVault, IWSMonitorHeaders, IWSVaultLoan, VaultAddress } from '../types';
|
|
1
|
+
import type { IAddress, IContractRunner, IHistoricalTimeseriesResponse, ITokenizedVault, IWSMonitorHeaders, IWSVaultLoan, VaultAddress } from '../types';
|
|
2
2
|
import { WEBSERVER_URL } from './constants/core';
|
|
3
3
|
export type IFetchAugustMethods = 'get' | 'post' | 'put';
|
|
4
4
|
export type IFetchAugustOptions = {
|
package/lib/core/fetcher.js
CHANGED
|
@@ -320,7 +320,7 @@ async function withRetry(fn, maxRetries = 3, baseDelay = 1000, shouldRetry = isR
|
|
|
320
320
|
catch (error) {
|
|
321
321
|
lastError = error;
|
|
322
322
|
if (attempt < maxRetries && shouldRetry(error)) {
|
|
323
|
-
const delay = baseDelay *
|
|
323
|
+
const delay = baseDelay * 2 ** attempt;
|
|
324
324
|
logger_1.Logger.log.warn('withRetry', `Attempt ${attempt + 1} failed, retrying in ${delay}ms: ${error.message}`);
|
|
325
325
|
await new Promise((resolve) => setTimeout(resolve, delay));
|
|
326
326
|
continue;
|
|
@@ -414,7 +414,7 @@ async function fetchTokenizedVaults(pool, headers, loadSubaccounts, loadSnapshot
|
|
|
414
414
|
}
|
|
415
415
|
async function fetchTokenPrice(symbol, provider, coinGeckoKey, headers) {
|
|
416
416
|
if (!symbol) {
|
|
417
|
-
|
|
417
|
+
logger_1.Logger.log.error('fetchTokenPrice', 'symbol parameter is undefined');
|
|
418
418
|
return 0;
|
|
419
419
|
}
|
|
420
420
|
let normalizedSymbol = symbol.toLowerCase();
|
|
@@ -593,7 +593,7 @@ async function promiseSettle(promises, maxRetries = 3, baseDelay = 1000) {
|
|
|
593
593
|
return await promise;
|
|
594
594
|
}
|
|
595
595
|
catch (error) {
|
|
596
|
-
|
|
596
|
+
logger_1.Logger.log.warn('promiseSettle', `Promise at index ${index} failed`, error);
|
|
597
597
|
throw error;
|
|
598
598
|
}
|
|
599
599
|
}, maxRetries, baseDelay));
|
|
@@ -603,7 +603,7 @@ async function promiseSettle(promises, maxRetries = 3, baseDelay = 1000) {
|
|
|
603
603
|
return result.value;
|
|
604
604
|
}
|
|
605
605
|
else {
|
|
606
|
-
|
|
606
|
+
logger_1.Logger.log.warn('promiseSettle', `Promise at index ${index} failed after retries`, result.reason);
|
|
607
607
|
return null;
|
|
608
608
|
}
|
|
609
609
|
});
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { INormalizedNumber } from '../../types';
|
|
1
|
+
import type { INormalizedNumber } from '../../types';
|
|
2
2
|
export declare function toNormalizedBn(value: string | bigint | number, decimals?: number | bigint): INormalizedNumber;
|
|
3
3
|
export declare function getFallbackRpcUrls(chainId: number): string[];
|
|
4
4
|
export declare const filterOutBySize: (usdAmount: number) => boolean;
|
package/lib/core/helpers/core.js
CHANGED
|
@@ -184,7 +184,7 @@ function prepareDateForDb(date) {
|
|
|
184
184
|
function orderObjArrByDate(objectArray, options) {
|
|
185
185
|
const selectedOrder = options?.order ?? 'desc';
|
|
186
186
|
const selectedKey = options?.key ?? 'date';
|
|
187
|
-
return objectArray.sort(
|
|
187
|
+
return objectArray.sort((a, b) => {
|
|
188
188
|
if (selectedOrder === 'asc')
|
|
189
189
|
return (new Date(a[selectedKey]).valueOf() - new Date(b[selectedKey]).valueOf());
|
|
190
190
|
return (new Date(b[selectedKey]).valueOf() - new Date(a[selectedKey]).valueOf());
|
|
@@ -0,0 +1,4 @@
|
|
|
1
|
+
import { IAddress } from '../../types';
|
|
2
|
+
export declare function getSwapRouterAddress(chainId: number): IAddress | undefined;
|
|
3
|
+
export declare function vaultUsesSwapRouter(vaultAddress: IAddress): boolean;
|
|
4
|
+
export declare function resolveOriginCode(provided?: `0x${string}`): `0x${string}`;
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.getSwapRouterAddress = getSwapRouterAddress;
|
|
4
|
+
exports.vaultUsesSwapRouter = vaultUsesSwapRouter;
|
|
5
|
+
exports.resolveOriginCode = resolveOriginCode;
|
|
6
|
+
const swap_router_1 = require("../constants/swap-router");
|
|
7
|
+
const errors_1 = require("../errors");
|
|
8
|
+
function getSwapRouterAddress(chainId) {
|
|
9
|
+
return swap_router_1.SWAP_ROUTER_ADDRESSES[chainId];
|
|
10
|
+
}
|
|
11
|
+
function vaultUsesSwapRouter(vaultAddress) {
|
|
12
|
+
return swap_router_1.VAULTS_USING_SWAP_ROUTER.has(vaultAddress.toLowerCase());
|
|
13
|
+
}
|
|
14
|
+
function resolveOriginCode(provided) {
|
|
15
|
+
if (provided === undefined)
|
|
16
|
+
return swap_router_1.ORIGIN_CODES.default;
|
|
17
|
+
if (!/^0x[0-9a-fA-F]{64}$/.test(provided)) {
|
|
18
|
+
throw new errors_1.AugustValidationError('INVALID_INPUT', `resolveOriginCode: originCode must be a 32-byte hex string (66 chars incl. 0x), got "${provided}" (${provided.length} chars)`, { context: { provided, expectedLength: 66 } });
|
|
19
|
+
}
|
|
20
|
+
return provided;
|
|
21
|
+
}
|
|
22
|
+
//# sourceMappingURL=swap-router.js.map
|
package/lib/core/helpers/web3.js
CHANGED
|
@@ -80,7 +80,7 @@ function createContract({ provider, address, abi, }) {
|
|
|
80
80
|
return;
|
|
81
81
|
const contract = new ethers_1.Contract(address, abi, provider);
|
|
82
82
|
if (!contract) {
|
|
83
|
-
|
|
83
|
+
logger_1.Logger.log.error('createContract', 'contract does not exist on connected chain');
|
|
84
84
|
return;
|
|
85
85
|
}
|
|
86
86
|
return contract;
|
|
@@ -336,7 +336,7 @@ async function getTokenMetadata(provider, asset, meta) {
|
|
|
336
336
|
return await Promise.all(getterArr);
|
|
337
337
|
}
|
|
338
338
|
catch (e) {
|
|
339
|
-
|
|
339
|
+
logger_1.Logger.log.error('getTokenMetadata', e);
|
|
340
340
|
return [];
|
|
341
341
|
}
|
|
342
342
|
}
|
|
@@ -348,7 +348,7 @@ const getManagementFeePercent = async (provider, address) => {
|
|
|
348
348
|
await contract.managementFeePercent.staticCall();
|
|
349
349
|
}
|
|
350
350
|
catch (e) {
|
|
351
|
-
|
|
351
|
+
logger_1.Logger.log.error('getManagementFeePercent:simulate', e);
|
|
352
352
|
return undefined;
|
|
353
353
|
}
|
|
354
354
|
try {
|
|
@@ -357,7 +357,7 @@ const getManagementFeePercent = async (provider, address) => {
|
|
|
357
357
|
return Number(fee) / 100;
|
|
358
358
|
}
|
|
359
359
|
catch (e) {
|
|
360
|
-
|
|
360
|
+
logger_1.Logger.log.error('getManagementFeePercent', e);
|
|
361
361
|
return undefined;
|
|
362
362
|
}
|
|
363
363
|
};
|
|
@@ -376,7 +376,7 @@ async function simulateTransaction(provider, abi, functionName, options) {
|
|
|
376
376
|
return customInterface.decodeFunctionResult(functionName, response);
|
|
377
377
|
}
|
|
378
378
|
catch (e) {
|
|
379
|
-
|
|
379
|
+
logger_1.Logger.log.error('simulateTransaction', e);
|
|
380
380
|
if (String(e).includes('reverted with reason string "denied"'))
|
|
381
381
|
return true;
|
|
382
382
|
return false;
|
|
@@ -400,7 +400,7 @@ function checkAddress(address, logger, type = 'contract') {
|
|
|
400
400
|
}
|
|
401
401
|
async function getLoanOracleFeeRate(provider, category_id, address, chainId) {
|
|
402
402
|
if (!(0, ethers_1.isAddress)(address)) {
|
|
403
|
-
|
|
403
|
+
logger_1.Logger.log.error('getLoanOracleFee', 'address is undefined or not a valid address');
|
|
404
404
|
return;
|
|
405
405
|
}
|
|
406
406
|
let _chainId = chainId;
|
|
@@ -409,7 +409,7 @@ async function getLoanOracleFeeRate(provider, category_id, address, chainId) {
|
|
|
409
409
|
_chainId = Number(chainIdRes);
|
|
410
410
|
}
|
|
411
411
|
if (!web3_1.ORACLE_CONTRACTS?.[_chainId]) {
|
|
412
|
-
|
|
412
|
+
logger_1.Logger.log.warn('getLoanOracleFeeRate', 'no oracle address for', _chainId);
|
|
413
413
|
return Number(0);
|
|
414
414
|
}
|
|
415
415
|
const oracleContract = createContract({
|
|
@@ -441,7 +441,7 @@ async function getHistoricalContractData(provider, contractAddress, abi, methodN
|
|
|
441
441
|
});
|
|
442
442
|
}
|
|
443
443
|
catch (error) {
|
|
444
|
-
|
|
444
|
+
logger_1.Logger.log.error('getHistoricalContractData', `Error at block ${blockNumber}`, error);
|
|
445
445
|
}
|
|
446
446
|
}
|
|
447
447
|
return results;
|
|
@@ -484,7 +484,7 @@ async function getHistoricalContractDataByDate(provider, contractAddress, abi, m
|
|
|
484
484
|
for (let timestamp = startTimestamp; timestamp <= endTimestamp; timestamp += intervalSeconds) {
|
|
485
485
|
const block = await findBlockByTimestamp(timestamp);
|
|
486
486
|
if (!block) {
|
|
487
|
-
|
|
487
|
+
logger_1.Logger.log.warn('getHistoricalContractDataByDate', `No block found for timestamp ${timestamp}`);
|
|
488
488
|
continue;
|
|
489
489
|
}
|
|
490
490
|
const result = await contract[methodName](...args, {
|
|
@@ -500,7 +500,7 @@ async function getHistoricalContractDataByDate(provider, contractAddress, abi, m
|
|
|
500
500
|
return results;
|
|
501
501
|
}
|
|
502
502
|
catch (error) {
|
|
503
|
-
|
|
503
|
+
logger_1.Logger.log.error('getHistoricalContractDataByDate', error);
|
|
504
504
|
throw error;
|
|
505
505
|
}
|
|
506
506
|
}
|
package/lib/core/index.d.ts
CHANGED
|
@@ -9,8 +9,10 @@ export * from './constants/adapters';
|
|
|
9
9
|
export * from './constants/core';
|
|
10
10
|
export * from './constants/web3';
|
|
11
11
|
export * from './constants/vaults';
|
|
12
|
+
export * from './constants/swap-router';
|
|
12
13
|
export * from './helpers/web3';
|
|
13
14
|
export * from './helpers/vaults';
|
|
14
15
|
export * from './helpers/core';
|
|
15
16
|
export * from './helpers/adapters';
|
|
16
17
|
export * from './helpers/signer';
|
|
18
|
+
export * from './helpers/swap-router';
|
package/lib/core/index.js
CHANGED
|
@@ -25,9 +25,11 @@ __exportStar(require("./constants/adapters"), exports);
|
|
|
25
25
|
__exportStar(require("./constants/core"), exports);
|
|
26
26
|
__exportStar(require("./constants/web3"), exports);
|
|
27
27
|
__exportStar(require("./constants/vaults"), exports);
|
|
28
|
+
__exportStar(require("./constants/swap-router"), exports);
|
|
28
29
|
__exportStar(require("./helpers/web3"), exports);
|
|
29
30
|
__exportStar(require("./helpers/vaults"), exports);
|
|
30
31
|
__exportStar(require("./helpers/core"), exports);
|
|
31
32
|
__exportStar(require("./helpers/adapters"), exports);
|
|
32
33
|
__exportStar(require("./helpers/signer"), exports);
|
|
34
|
+
__exportStar(require("./helpers/swap-router"), exports);
|
|
33
35
|
//# sourceMappingURL=index.js.map
|
|
@@ -2,6 +2,16 @@ export type SDKLogger = {
|
|
|
2
2
|
setTag: (key: string, value: string) => void;
|
|
3
3
|
captureException: (err: unknown, context?: Record<string, any>) => void;
|
|
4
4
|
};
|
|
5
|
+
export interface SDKBreadcrumb {
|
|
6
|
+
category: string;
|
|
7
|
+
message: string;
|
|
8
|
+
level: 'info' | 'warning' | 'error';
|
|
9
|
+
data?: Record<string, unknown>;
|
|
10
|
+
}
|
|
11
|
+
export interface SDKSentrySink {
|
|
12
|
+
captureException: (error: unknown, context?: Record<string, unknown>) => void;
|
|
13
|
+
addBreadcrumb: (breadcrumb: SDKBreadcrumb) => void;
|
|
14
|
+
}
|
|
5
15
|
export interface ILogger {
|
|
6
16
|
debug?: (tag: string, context?: Record<string, unknown>) => void;
|
|
7
17
|
info?: (tag: string, context?: Record<string, unknown>) => void;
|
|
@@ -12,11 +22,13 @@ declare function setLogger(customLogger: SDKLogger): void;
|
|
|
12
22
|
declare function setStructuredLogger(custom: ILogger | null): void;
|
|
13
23
|
declare function getLogger(): SDKLogger | null;
|
|
14
24
|
declare function getStructuredLogger(): ILogger | null;
|
|
25
|
+
declare function setSentrySink(sink: SDKSentrySink | null): void;
|
|
15
26
|
declare function setDevMode(devMode: boolean): void;
|
|
16
27
|
declare function isDevMode(): boolean;
|
|
17
28
|
declare const Logger: {
|
|
18
29
|
setLogger: typeof setLogger;
|
|
19
30
|
setStructuredLogger: typeof setStructuredLogger;
|
|
31
|
+
setSentrySink: typeof setSentrySink;
|
|
20
32
|
getLogger: typeof getLogger;
|
|
21
33
|
getStructuredLogger: typeof getStructuredLogger;
|
|
22
34
|
setDevMode: typeof setDevMode;
|
package/lib/core/logger/index.js
CHANGED
|
@@ -37,6 +37,7 @@ exports.Logger = exports.Slack = void 0;
|
|
|
37
37
|
const sanitize_1 = require("../analytics/sanitize");
|
|
38
38
|
let logger = null;
|
|
39
39
|
let structuredLogger = null;
|
|
40
|
+
let sentrySink = null;
|
|
40
41
|
let isDev = false;
|
|
41
42
|
function setLogger(customLogger) {
|
|
42
43
|
logger = customLogger;
|
|
@@ -50,6 +51,9 @@ function getLogger() {
|
|
|
50
51
|
function getStructuredLogger() {
|
|
51
52
|
return structuredLogger;
|
|
52
53
|
}
|
|
54
|
+
function setSentrySink(sink) {
|
|
55
|
+
sentrySink = sink;
|
|
56
|
+
}
|
|
53
57
|
function setDevMode(devMode) {
|
|
54
58
|
isDev = devMode;
|
|
55
59
|
}
|
|
@@ -71,6 +75,12 @@ const log = {
|
|
|
71
75
|
}
|
|
72
76
|
logger?.setTag('warning', tag);
|
|
73
77
|
structuredLogger?.warn?.(tag, structuredContext(safeArgs));
|
|
78
|
+
sentrySink?.addBreadcrumb({
|
|
79
|
+
category: 'sdk.logger',
|
|
80
|
+
level: 'warning',
|
|
81
|
+
message: tag,
|
|
82
|
+
data: structuredContext(safeArgs),
|
|
83
|
+
});
|
|
74
84
|
},
|
|
75
85
|
error: (tag, error, context) => {
|
|
76
86
|
const safeError = (0, sanitize_1.sanitizeError)(error);
|
|
@@ -80,8 +90,9 @@ const log = {
|
|
|
80
90
|
if (isDev) {
|
|
81
91
|
console.error(`[${tag}]`, safeError);
|
|
82
92
|
}
|
|
83
|
-
logger?.captureException(safeError, { tag, ...
|
|
93
|
+
logger?.captureException(safeError, { tag, ...safeContext });
|
|
84
94
|
structuredLogger?.error(tag, safeError, safeContext);
|
|
95
|
+
sentrySink?.captureException(safeError, { tag, ...safeContext });
|
|
85
96
|
},
|
|
86
97
|
};
|
|
87
98
|
function structuredContext(args) {
|
|
@@ -101,6 +112,7 @@ function structuredContext(args) {
|
|
|
101
112
|
const Logger = {
|
|
102
113
|
setLogger,
|
|
103
114
|
setStructuredLogger,
|
|
115
|
+
setSentrySink,
|
|
104
116
|
getLogger,
|
|
105
117
|
getStructuredLogger,
|
|
106
118
|
setDevMode,
|
package/lib/index.d.ts
CHANGED
package/lib/index.js
CHANGED
|
@@ -20,6 +20,7 @@ __exportStar(require("./types"), exports);
|
|
|
20
20
|
__exportStar(require("./core"), exports);
|
|
21
21
|
__exportStar(require("./abis"), exports);
|
|
22
22
|
__exportStar(require("./services/debank"), exports);
|
|
23
|
+
__exportStar(require("./services/swap-quotes"), exports);
|
|
23
24
|
__exportStar(require("./modules/vaults"), exports);
|
|
24
25
|
__exportStar(require("./modules/sub-accounts"), exports);
|
|
25
26
|
__exportStar(require("./evm"), exports);
|