@augustdigital/sdk 7.0.1 → 8.2.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (41) hide show
  1. package/lib/abis/SwapRouter.d.ts +1042 -0
  2. package/lib/abis/SwapRouter.js +739 -0
  3. package/lib/abis/index.d.ts +1 -0
  4. package/lib/abis/index.js +1 -0
  5. package/lib/adapters/evm/index.d.ts +4 -0
  6. package/lib/adapters/evm/index.js +12 -0
  7. package/lib/adapters/stellar/types.d.ts +0 -1
  8. package/lib/core/analytics/method-taxonomy.js +3 -0
  9. package/lib/core/analytics/version.d.ts +1 -1
  10. package/lib/core/analytics/version.js +1 -1
  11. package/lib/core/base.class.d.ts +0 -1
  12. package/lib/core/constants/swap-router.d.ts +8 -0
  13. package/lib/core/constants/swap-router.js +18 -0
  14. package/lib/core/helpers/swap-router.d.ts +4 -0
  15. package/lib/core/helpers/swap-router.js +22 -0
  16. package/lib/core/index.d.ts +2 -0
  17. package/lib/core/index.js +2 -0
  18. package/lib/index.d.ts +1 -0
  19. package/lib/index.js +1 -0
  20. package/lib/main.d.ts +2 -1
  21. package/lib/main.js +1 -1
  22. package/lib/modules/vaults/fetcher.js +2 -2
  23. package/lib/modules/vaults/getters.d.ts +5 -14
  24. package/lib/modules/vaults/getters.js +54 -13
  25. package/lib/modules/vaults/main.d.ts +1 -1
  26. package/lib/modules/vaults/main.js +3 -1
  27. package/lib/modules/vaults/write.actions.d.ts +7 -0
  28. package/lib/modules/vaults/write.actions.js +260 -1
  29. package/lib/services/coingecko/fetcher.js +15 -5
  30. package/lib/services/debank/fetcher.js +6 -3
  31. package/lib/services/debank/utils.js +7 -6
  32. package/lib/services/octavfi/fetcher.js +10 -5
  33. package/lib/services/subgraph/vaults.js +6 -6
  34. package/lib/services/swap-quotes/index.d.ts +25 -0
  35. package/lib/services/swap-quotes/index.js +51 -0
  36. package/lib/services/swap-quotes/paraswap.d.ts +26 -0
  37. package/lib/services/swap-quotes/paraswap.js +116 -0
  38. package/lib/types/vaults.d.ts +40 -0
  39. package/lib/types/vaults.js +6 -1
  40. package/lib/types/web3.d.ts +0 -1
  41. package/package.json +1 -1
@@ -0,0 +1,116 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.PARASWAP_DEFAULTS = void 0;
4
+ exports.fetchParaswapQuote = fetchParaswapQuote;
5
+ const errors_1 = require("../../core/errors");
6
+ const web3_1 = require("../../core/helpers/web3");
7
+ const PARASWAP_PRICES_URL = 'https://api.paraswap.io/prices';
8
+ const PARASWAP_TRANSACTIONS_BASE_URL = 'https://api.paraswap.io/transactions';
9
+ const DEFAULT_PARTNER = 'august';
10
+ const DEFAULT_PARTNER_ADDRESS = '0xb60ee0FA5B6bA917255A03e744967E0Bda531dD0';
11
+ const PARASWAP_VERSION = '6.2';
12
+ const BPS_DENOMINATOR = 10000n;
13
+ async function fetchParaswapQuote(input) {
14
+ const priceRoute = await getPriceRoute(input);
15
+ const destAmountRaw = priceRoute.destAmount;
16
+ if (typeof destAmountRaw !== 'string' || !/^\d+$/.test(destAmountRaw)) {
17
+ throw new errors_1.AugustServerError(200, `fetchSwapQuote: Paraswap /prices returned non-numeric destAmount: ${String(destAmountRaw)}`, { context: { destAmount: destAmountRaw } });
18
+ }
19
+ const expectedAmountOut = BigInt(destAmountRaw);
20
+ const { router, payload } = await getTransactionData(input, priceRoute);
21
+ return { router, payload, expectedAmountOut, fetchedAt: Date.now() };
22
+ }
23
+ async function getPriceRoute(input) {
24
+ const params = new URLSearchParams({
25
+ network: String(input.chainId),
26
+ srcToken: input.srcToken,
27
+ srcDecimals: String(input.srcDecimals),
28
+ destToken: input.destToken,
29
+ destDecimals: String(input.destDecimals),
30
+ amount: input.amount.toString(),
31
+ partner: input.partner,
32
+ partnerAddress: input.partnerAddress,
33
+ version: PARASWAP_VERSION,
34
+ });
35
+ const url = `${PARASWAP_PRICES_URL}?${params.toString()}`;
36
+ let response;
37
+ try {
38
+ response = await input.fetchImpl(url, {
39
+ method: 'GET',
40
+ headers: { 'Content-Type': 'application/json' },
41
+ signal: input.signal,
42
+ });
43
+ }
44
+ catch (cause) {
45
+ throw new errors_1.AugustNetworkError('fetchSwapQuote: Paraswap /prices fetch failed', { cause, context: { url } });
46
+ }
47
+ if (!response.ok) {
48
+ throw new errors_1.AugustServerError(response.status, `fetchSwapQuote: Paraswap /prices returned HTTP ${response.status}`, { context: { url } });
49
+ }
50
+ const body = (await response.json());
51
+ if (body.error) {
52
+ throw new errors_1.AugustServerError(response.status, `fetchSwapQuote: Paraswap /prices error: ${body.error}`, { context: { providerError: body.error } });
53
+ }
54
+ if (!body.priceRoute) {
55
+ throw new errors_1.AugustServerError(response.status, 'fetchSwapQuote: Paraswap /prices returned no priceRoute', { context: { body } });
56
+ }
57
+ return body.priceRoute;
58
+ }
59
+ async function getTransactionData(input, priceRoute) {
60
+ const url = `${PARASWAP_TRANSACTIONS_BASE_URL}/${input.chainId}/?ignoreChecks=true&ignoreGasEstimate=true&onlyParams=false`;
61
+ const expectedDestAmount = BigInt(priceRoute.destAmount);
62
+ const minDestAmount = (expectedDestAmount * (BPS_DENOMINATOR - BigInt(input.slippageBps))) /
63
+ BPS_DENOMINATOR;
64
+ const requestBody = {
65
+ userAddress: input.receiver,
66
+ srcToken: input.srcToken,
67
+ destToken: input.destToken,
68
+ srcDecimals: input.srcDecimals,
69
+ destDecimals: input.destDecimals,
70
+ srcAmount: input.amount.toString(),
71
+ destAmount: minDestAmount.toString(),
72
+ priceRoute,
73
+ partner: input.partner,
74
+ partnerAddress: input.partnerAddress,
75
+ };
76
+ let response;
77
+ try {
78
+ response = await input.fetchImpl(url, {
79
+ method: 'POST',
80
+ headers: { 'Content-Type': 'application/json' },
81
+ body: JSON.stringify(requestBody),
82
+ signal: input.signal,
83
+ });
84
+ }
85
+ catch (cause) {
86
+ throw new errors_1.AugustNetworkError('fetchSwapQuote: Paraswap /transactions fetch failed', { cause, context: { url } });
87
+ }
88
+ if (!response.ok) {
89
+ throw new errors_1.AugustServerError(response.status, `fetchSwapQuote: Paraswap /transactions returned HTTP ${response.status}`, { context: { url } });
90
+ }
91
+ const body = (await response.json());
92
+ if (body.error) {
93
+ throw new errors_1.AugustServerError(response.status, `fetchSwapQuote: Paraswap /transactions error: ${body.error}`, { context: { providerError: body.error } });
94
+ }
95
+ if (!body.to || !body.data) {
96
+ throw new errors_1.AugustServerError(response.status, 'fetchSwapQuote: Paraswap /transactions returned no to/data', { context: { body } });
97
+ }
98
+ if (!(0, web3_1.checkAddress)(body.to, console, 'contract')) {
99
+ throw new errors_1.AugustServerError(response.status, `fetchSwapQuote: Paraswap /transactions returned an invalid router address: ${body.to}`, { context: { to: body.to } });
100
+ }
101
+ if (!/^0x[0-9a-fA-F]+$/.test(body.data) || body.data.length % 2 !== 0) {
102
+ throw new errors_1.AugustServerError(response.status, `fetchSwapQuote: Paraswap /transactions returned malformed calldata (${body.data.length} chars)`, { context: { dataPrefix: body.data.slice(0, 16) } });
103
+ }
104
+ if (body.data.length < 10) {
105
+ throw new errors_1.AugustValidationError('INVALID_INPUT', 'fetchSwapQuote: Paraswap /transactions returned calldata shorter than a 4-byte selector');
106
+ }
107
+ return {
108
+ router: body.to,
109
+ payload: body.data,
110
+ };
111
+ }
112
+ exports.PARASWAP_DEFAULTS = {
113
+ partner: DEFAULT_PARTNER,
114
+ partnerAddress: DEFAULT_PARTNER_ADDRESS,
115
+ };
116
+ //# sourceMappingURL=paraswap.js.map
@@ -22,6 +22,17 @@ export interface IVaultLoan {
22
22
  isIdleCapital: boolean;
23
23
  allocation: number;
24
24
  }
25
+ export interface IVaultBorrowerHealthFactor {
26
+ borrower: IAddress;
27
+ loan: IAddress;
28
+ health_factor?: {
29
+ datetime: string;
30
+ health_factor: number;
31
+ id: string;
32
+ total_collateral_value: number;
33
+ total_loan_value: number;
34
+ };
35
+ }
25
36
  export type IVaultUserHistoryItem = {
26
37
  timestamp: number;
27
38
  address: IAddress;
@@ -321,3 +332,32 @@ export interface IVaultMetadataItem {
321
332
  address: string;
322
333
  }
323
334
  export type IVaultMetadata = Record<string, IVaultMetadataItem>;
335
+ export declare enum SwapRouterVaultType {
336
+ ERC4626 = 1,
337
+ TokenizedVaultV2 = 2
338
+ }
339
+ export interface ISwapParams {
340
+ tokenIn: IAddress;
341
+ tokenOut: IAddress;
342
+ amountIn: bigint;
343
+ minAmountOut: bigint;
344
+ router: IAddress;
345
+ payload: `0x${string}`;
346
+ }
347
+ export interface ISwapRouterBaseOptions {
348
+ chainId: number;
349
+ vault: IAddress;
350
+ receiver: IAddress;
351
+ originCode?: `0x${string}`;
352
+ wait?: boolean;
353
+ }
354
+ export interface ISwapAndDepositOptions extends ISwapRouterBaseOptions {
355
+ swaps: ISwapParams[];
356
+ }
357
+ export interface ISwapRouterDirectDepositOptions extends ISwapRouterBaseOptions {
358
+ asset: IAddress;
359
+ amount: bigint;
360
+ }
361
+ export interface ISwapRouterNativeDepositOptions extends ISwapRouterBaseOptions {
362
+ amount: bigint;
363
+ }
@@ -1,9 +1,14 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.VaultRedemptionStatus = void 0;
3
+ exports.SwapRouterVaultType = exports.VaultRedemptionStatus = void 0;
4
4
  var VaultRedemptionStatus;
5
5
  (function (VaultRedemptionStatus) {
6
6
  VaultRedemptionStatus["AWAITING_COOLDOWN"] = "awaiting_cooldown";
7
7
  VaultRedemptionStatus["READY_TO_CLAIM"] = "ready_to_claim";
8
8
  })(VaultRedemptionStatus || (exports.VaultRedemptionStatus = VaultRedemptionStatus = {}));
9
+ var SwapRouterVaultType;
10
+ (function (SwapRouterVaultType) {
11
+ SwapRouterVaultType[SwapRouterVaultType["ERC4626"] = 1] = "ERC4626";
12
+ SwapRouterVaultType[SwapRouterVaultType["TokenizedVaultV2"] = 2] = "TokenizedVaultV2";
13
+ })(SwapRouterVaultType || (exports.SwapRouterVaultType = SwapRouterVaultType = {}));
9
14
  //# sourceMappingURL=vaults.js.map
@@ -22,7 +22,6 @@ export type IInfuraOptions = {
22
22
  };
23
23
  export type ISolanaNetwork = 'devnet' | 'mainnet-beta' | 'testnet' | 'localnet';
24
24
  export type IStellarNetwork = 'mainnet' | 'testnet';
25
- export type StellarNetwork = IStellarNetwork;
26
25
  export interface ISolanaConfig {
27
26
  rpcUrl: string;
28
27
  network: ISolanaNetwork;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@augustdigital/sdk",
3
- "version": "7.0.1",
3
+ "version": "8.2.0",
4
4
  "main": "lib/index.js",
5
5
  "keywords": [
6
6
  "augustdigital",