upshift-finance 1.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +21 -0
- package/README.md +349 -0
- package/lib/abis/AddressResolver.d.ts +28 -0
- package/lib/abis/AddressResolver.js +23 -0
- package/lib/abis/ChainlinkV3.d.ts +87 -0
- package/lib/abis/ChainlinkV3.js +117 -0
- package/lib/abis/ERC20.d.ts +168 -0
- package/lib/abis/ERC20.js +226 -0
- package/lib/abis/ERC20_Bytes32.d.ts +139 -0
- package/lib/abis/ERC20_Bytes32.js +196 -0
- package/lib/abis/ERC4626.d.ts +364 -0
- package/lib/abis/ERC4626.js +507 -0
- package/lib/abis/ERC721.d.ts +231 -0
- package/lib/abis/ERC721.js +321 -0
- package/lib/abis/FeeOracle.d.ts +120 -0
- package/lib/abis/FeeOracle.js +162 -0
- package/lib/abis/LendingPool.d.ts +1393 -0
- package/lib/abis/LendingPool.js +1807 -0
- package/lib/abis/LendingPoolV2.d.ts +1413 -0
- package/lib/abis/LendingPoolV2.js +1833 -0
- package/lib/abis/LendingPoolV3.d.ts +1677 -0
- package/lib/abis/LendingPoolV3.js +1160 -0
- package/lib/abis/Loan.d.ts +837 -0
- package/lib/abis/Loan.js +1080 -0
- package/lib/abis/MultiAssetNativeDepositWrapper.d.ts +137 -0
- package/lib/abis/MultiAssetNativeDepositWrapper.js +125 -0
- package/lib/abis/Multicall3.d.ts +30 -0
- package/lib/abis/Multicall3.js +97 -0
- package/lib/abis/OFT.d.ts +116 -0
- package/lib/abis/OFT.js +85 -0
- package/lib/abis/PoolAdapter.d.ts +36 -0
- package/lib/abis/PoolAdapter.js +51 -0
- package/lib/abis/RewardDistributor.d.ts +267 -0
- package/lib/abis/RewardDistributor.js +352 -0
- package/lib/abis/RwaRedeemSubaccount.d.ts +747 -0
- package/lib/abis/RwaRedeemSubaccount.js +548 -0
- package/lib/abis/SmartAccount.d.ts +17 -0
- package/lib/abis/SmartAccount.js +19 -0
- package/lib/abis/SwapRouter.d.ts +1043 -0
- package/lib/abis/SwapRouter.js +740 -0
- package/lib/abis/TextResolver.d.ts +16 -0
- package/lib/abis/TextResolver.js +16 -0
- package/lib/abis/TokenizedVaultV2.d.ts +1364 -0
- package/lib/abis/TokenizedVaultV2.js +1041 -0
- package/lib/abis/TokenizedVaultV2DepositWithPermit.d.ts +1456 -0
- package/lib/abis/TokenizedVaultV2DepositWithPermit.js +1878 -0
- package/lib/abis/TokenizedVaultV2Receipt.d.ts +1568 -0
- package/lib/abis/TokenizedVaultV2Receipt.js +1061 -0
- package/lib/abis/TokenizedVaultV2SenderAllocationWhitelist.d.ts +454 -0
- package/lib/abis/TokenizedVaultV2SenderAllocationWhitelist.js +327 -0
- package/lib/abis/TokenizedVaultV2WhitelistedAllocation.d.ts +1466 -0
- package/lib/abis/TokenizedVaultV2WhitelistedAllocation.js +1092 -0
- package/lib/abis/TokenizedVaultV2WhitelistedAssets.d.ts +274 -0
- package/lib/abis/TokenizedVaultV2WhitelistedAssets.js +167 -0
- package/lib/abis/UniversalResolverResolve.d.ts +69 -0
- package/lib/abis/UniversalResolverResolve.js +35 -0
- package/lib/abis/UniversalSignatureValidator.d.ts +17 -0
- package/lib/abis/UniversalSignatureValidator.js +30 -0
- package/lib/abis/WrapperAdapter.d.ts +71 -0
- package/lib/abis/WrapperAdapter.js +77 -0
- package/lib/abis/index.d.ts +34 -0
- package/lib/abis/index.js +51 -0
- package/lib/adapters/evm/getters.d.ts +19 -0
- package/lib/adapters/evm/getters.js +209 -0
- package/lib/adapters/evm/index.d.ts +353 -0
- package/lib/adapters/evm/index.js +434 -0
- package/lib/adapters/evm/utils.d.ts +8 -0
- package/lib/adapters/evm/utils.js +51 -0
- package/lib/adapters/solana/constants.d.ts +33 -0
- package/lib/adapters/solana/constants.js +52 -0
- package/lib/adapters/solana/getters.d.ts +11 -0
- package/lib/adapters/solana/getters.js +165 -0
- package/lib/adapters/solana/idl/vault-idl.d.ts +272 -0
- package/lib/adapters/solana/idl/vault-idl.js +1084 -0
- package/lib/adapters/solana/index.d.ts +233 -0
- package/lib/adapters/solana/index.js +291 -0
- package/lib/adapters/solana/types.d.ts +67 -0
- package/lib/adapters/solana/types.js +3 -0
- package/lib/adapters/solana/utils.d.ts +141 -0
- package/lib/adapters/solana/utils.js +595 -0
- package/lib/adapters/solana/vault.actions.d.ts +57 -0
- package/lib/adapters/solana/vault.actions.js +379 -0
- package/lib/adapters/stellar/actions.d.ts +28 -0
- package/lib/adapters/stellar/actions.js +77 -0
- package/lib/adapters/stellar/constants.d.ts +43 -0
- package/lib/adapters/stellar/constants.js +53 -0
- package/lib/adapters/stellar/getters.d.ts +68 -0
- package/lib/adapters/stellar/getters.js +290 -0
- package/lib/adapters/stellar/index.d.ts +114 -0
- package/lib/adapters/stellar/index.js +175 -0
- package/lib/adapters/stellar/soroban.d.ts +123 -0
- package/lib/adapters/stellar/soroban.js +613 -0
- package/lib/adapters/stellar/submit.d.ts +34 -0
- package/lib/adapters/stellar/submit.js +149 -0
- package/lib/adapters/stellar/types.d.ts +58 -0
- package/lib/adapters/stellar/types.js +6 -0
- package/lib/adapters/stellar/utils.d.ts +24 -0
- package/lib/adapters/stellar/utils.js +34 -0
- package/lib/adapters/sui/constants.d.ts +14 -0
- package/lib/adapters/sui/constants.js +29 -0
- package/lib/adapters/sui/getters.d.ts +9 -0
- package/lib/adapters/sui/getters.js +60 -0
- package/lib/adapters/sui/index.d.ts +45 -0
- package/lib/adapters/sui/index.js +101 -0
- package/lib/adapters/sui/transformer.d.ts +10 -0
- package/lib/adapters/sui/transformer.js +107 -0
- package/lib/adapters/sui/types.d.ts +66 -0
- package/lib/adapters/sui/types.js +3 -0
- package/lib/adapters/sui/utils.d.ts +10 -0
- package/lib/adapters/sui/utils.js +29 -0
- package/lib/core/analytics/chain-name.d.ts +9 -0
- package/lib/core/analytics/chain-name.js +34 -0
- package/lib/core/analytics/constants.d.ts +5 -0
- package/lib/core/analytics/constants.js +9 -0
- package/lib/core/analytics/env.d.ts +29 -0
- package/lib/core/analytics/env.js +59 -0
- package/lib/core/analytics/index.d.ts +36 -0
- package/lib/core/analytics/index.js +79 -0
- package/lib/core/analytics/instrumentation.d.ts +29 -0
- package/lib/core/analytics/instrumentation.js +277 -0
- package/lib/core/analytics/method-taxonomy.d.ts +19 -0
- package/lib/core/analytics/method-taxonomy.js +128 -0
- package/lib/core/analytics/metrics.d.ts +33 -0
- package/lib/core/analytics/metrics.js +116 -0
- package/lib/core/analytics/sanitize.d.ts +44 -0
- package/lib/core/analytics/sanitize.js +260 -0
- package/lib/core/analytics/sentry-runtime.d.ts +15 -0
- package/lib/core/analytics/sentry-runtime.js +97 -0
- package/lib/core/analytics/sentry.d.ts +67 -0
- package/lib/core/analytics/sentry.js +613 -0
- package/lib/core/analytics/types.d.ts +48 -0
- package/lib/core/analytics/types.js +3 -0
- package/lib/core/analytics/user-identity.d.ts +41 -0
- package/lib/core/analytics/user-identity.js +141 -0
- package/lib/core/analytics/version.d.ts +6 -0
- package/lib/core/analytics/version.js +10 -0
- package/lib/core/attribution.d.ts +111 -0
- package/lib/core/attribution.js +142 -0
- package/lib/core/auth/index.d.ts +1 -0
- package/lib/core/auth/index.js +18 -0
- package/lib/core/auth/verify.d.ts +2 -0
- package/lib/core/auth/verify.js +31 -0
- package/lib/core/base.class.d.ts +152 -0
- package/lib/core/base.class.js +172 -0
- package/lib/core/cache.d.ts +9 -0
- package/lib/core/cache.js +31 -0
- package/lib/core/constants/adapters.d.ts +103 -0
- package/lib/core/constants/adapters.js +180 -0
- package/lib/core/constants/core.d.ts +133 -0
- package/lib/core/constants/core.js +209 -0
- package/lib/core/constants/swap-router.d.ts +150 -0
- package/lib/core/constants/swap-router.js +169 -0
- package/lib/core/constants/vaults.d.ts +93 -0
- package/lib/core/constants/vaults.js +273 -0
- package/lib/core/constants/web3.d.ts +91 -0
- package/lib/core/constants/web3.js +229 -0
- package/lib/core/errors/index.d.ts +114 -0
- package/lib/core/errors/index.js +183 -0
- package/lib/core/fetcher.d.ts +198 -0
- package/lib/core/fetcher.js +903 -0
- package/lib/core/helpers/adapters.d.ts +13 -0
- package/lib/core/helpers/adapters.js +39 -0
- package/lib/core/helpers/chain-address.d.ts +13 -0
- package/lib/core/helpers/chain-address.js +47 -0
- package/lib/core/helpers/chain-error.d.ts +207 -0
- package/lib/core/helpers/chain-error.js +682 -0
- package/lib/core/helpers/chain-support.d.ts +80 -0
- package/lib/core/helpers/chain-support.js +115 -0
- package/lib/core/helpers/core.d.ts +68 -0
- package/lib/core/helpers/core.js +285 -0
- package/lib/core/helpers/explorer-link.d.ts +16 -0
- package/lib/core/helpers/explorer-link.js +26 -0
- package/lib/core/helpers/multicall.d.ts +68 -0
- package/lib/core/helpers/multicall.js +103 -0
- package/lib/core/helpers/revert-decode.d.ts +248 -0
- package/lib/core/helpers/revert-decode.js +515 -0
- package/lib/core/helpers/signer.d.ts +52 -0
- package/lib/core/helpers/signer.js +145 -0
- package/lib/core/helpers/swap-router.d.ts +211 -0
- package/lib/core/helpers/swap-router.js +480 -0
- package/lib/core/helpers/vault-version.d.ts +23 -0
- package/lib/core/helpers/vault-version.js +75 -0
- package/lib/core/helpers/vaults.d.ts +89 -0
- package/lib/core/helpers/vaults.js +235 -0
- package/lib/core/helpers/web3.d.ts +353 -0
- package/lib/core/helpers/web3.js +992 -0
- package/lib/core/index.d.ts +23 -0
- package/lib/core/index.js +40 -0
- package/lib/core/logger/index.d.ts +98 -0
- package/lib/core/logger/index.js +144 -0
- package/lib/core/logger/slack.d.ts +16 -0
- package/lib/core/logger/slack.js +57 -0
- package/lib/core/vault-metadata.d.ts +12 -0
- package/lib/core/vault-metadata.js +42 -0
- package/lib/core/version-check.d.ts +58 -0
- package/lib/core/version-check.js +182 -0
- package/lib/evm/index.d.ts +2 -0
- package/lib/evm/index.js +19 -0
- package/lib/evm/methods/crossChainVault.d.ts +128 -0
- package/lib/evm/methods/crossChainVault.js +853 -0
- package/lib/evm/methods/crossChainVaultRegistry.d.ts +93 -0
- package/lib/evm/methods/crossChainVaultRegistry.js +240 -0
- package/lib/evm/methods/index.d.ts +2 -0
- package/lib/evm/methods/index.js +19 -0
- package/lib/evm/types/crossChain.d.ts +363 -0
- package/lib/evm/types/crossChain.js +20 -0
- package/lib/evm/types/index.d.ts +1 -0
- package/lib/evm/types/index.js +18 -0
- package/lib/index.d.ts +30 -0
- package/lib/index.js +52 -0
- package/lib/main.d.ts +527 -0
- package/lib/main.js +601 -0
- package/lib/modules/api/fetcher.d.ts +82 -0
- package/lib/modules/api/fetcher.js +150 -0
- package/lib/modules/api/index.d.ts +1 -0
- package/lib/modules/api/index.js +6 -0
- package/lib/modules/api/main.d.ts +313 -0
- package/lib/modules/api/main.js +479 -0
- package/lib/modules/sub-accounts/fetcher.d.ts +53 -0
- package/lib/modules/sub-accounts/fetcher.js +120 -0
- package/lib/modules/sub-accounts/index.d.ts +2 -0
- package/lib/modules/sub-accounts/index.js +19 -0
- package/lib/modules/sub-accounts/main.d.ts +243 -0
- package/lib/modules/sub-accounts/main.js +205 -0
- package/lib/modules/sub-accounts/utils.d.ts +106 -0
- package/lib/modules/sub-accounts/utils.js +112 -0
- package/lib/modules/vaults/adapter.helpers.d.ts +64 -0
- package/lib/modules/vaults/adapter.helpers.js +184 -0
- package/lib/modules/vaults/fetcher.d.ts +147 -0
- package/lib/modules/vaults/fetcher.js +368 -0
- package/lib/modules/vaults/getters.d.ts +570 -0
- package/lib/modules/vaults/getters.js +3051 -0
- package/lib/modules/vaults/index.d.ts +20 -0
- package/lib/modules/vaults/index.js +44 -0
- package/lib/modules/vaults/main.d.ts +601 -0
- package/lib/modules/vaults/main.js +1623 -0
- package/lib/modules/vaults/prefetch.d.ts +65 -0
- package/lib/modules/vaults/prefetch.js +120 -0
- package/lib/modules/vaults/read.actions.d.ts +225 -0
- package/lib/modules/vaults/read.actions.js +596 -0
- package/lib/modules/vaults/types.d.ts +71 -0
- package/lib/modules/vaults/types.js +3 -0
- package/lib/modules/vaults/utils/call-data-decoder.d.ts +61 -0
- package/lib/modules/vaults/utils/call-data-decoder.js +194 -0
- package/lib/modules/vaults/utils/date-utils.d.ts +50 -0
- package/lib/modules/vaults/utils/date-utils.js +84 -0
- package/lib/modules/vaults/utils.d.ts +140 -0
- package/lib/modules/vaults/utils.js +799 -0
- package/lib/modules/vaults/write.actions.d.ts +529 -0
- package/lib/modules/vaults/write.actions.js +1749 -0
- package/lib/polyfills.d.ts +1 -0
- package/lib/polyfills.js +12 -0
- package/lib/sdk.d.ts +26721 -0
- package/lib/services/coingecko/fetcher.d.ts +15 -0
- package/lib/services/coingecko/fetcher.js +67 -0
- package/lib/services/coingecko/index.d.ts +2 -0
- package/lib/services/coingecko/index.js +19 -0
- package/lib/services/coingecko/utils.d.ts +1 -0
- package/lib/services/coingecko/utils.js +24 -0
- package/lib/services/debank/fetcher.d.ts +126 -0
- package/lib/services/debank/fetcher.js +47 -0
- package/lib/services/debank/index.d.ts +2 -0
- package/lib/services/debank/index.js +19 -0
- package/lib/services/debank/utils.d.ts +38 -0
- package/lib/services/debank/utils.js +297 -0
- package/lib/services/layerzero/deposits.d.ts +49 -0
- package/lib/services/layerzero/deposits.js +166 -0
- package/lib/services/layerzero/redeems.d.ts +20 -0
- package/lib/services/layerzero/redeems.js +92 -0
- package/lib/services/layerzero/utils.d.ts +9 -0
- package/lib/services/layerzero/utils.js +22 -0
- package/lib/services/octavfi/fetcher.d.ts +9 -0
- package/lib/services/octavfi/fetcher.js +103 -0
- package/lib/services/octavfi/index.d.ts +3 -0
- package/lib/services/octavfi/index.js +20 -0
- package/lib/services/octavfi/types.d.ts +34 -0
- package/lib/services/octavfi/types.js +3 -0
- package/lib/services/octavfi/utils.d.ts +16 -0
- package/lib/services/octavfi/utils.js +212 -0
- package/lib/services/subgraph/fetcher.d.ts +2 -0
- package/lib/services/subgraph/fetcher.js +61 -0
- package/lib/services/subgraph/index.d.ts +2 -0
- package/lib/services/subgraph/index.js +19 -0
- package/lib/services/subgraph/schema.d.ts +45 -0
- package/lib/services/subgraph/schema.js +75 -0
- package/lib/services/subgraph/vaults.d.ts +25 -0
- package/lib/services/subgraph/vaults.js +1106 -0
- package/lib/services/swap-quotes/index.d.ts +105 -0
- package/lib/services/swap-quotes/index.js +77 -0
- package/lib/services/swap-quotes/paraswap.d.ts +51 -0
- package/lib/services/swap-quotes/paraswap.js +138 -0
- package/lib/types/api.d.ts +280 -0
- package/lib/types/api.js +3 -0
- package/lib/types/index.d.ts +12 -0
- package/lib/types/index.js +28 -0
- package/lib/types/points.d.ts +28 -0
- package/lib/types/points.js +3 -0
- package/lib/types/pools.d.ts +144 -0
- package/lib/types/pools.js +3 -0
- package/lib/types/staking.d.ts +28 -0
- package/lib/types/staking.js +3 -0
- package/lib/types/sub-accounts.d.ts +140 -0
- package/lib/types/sub-accounts.js +3 -0
- package/lib/types/subgraph.d.ts +74 -0
- package/lib/types/subgraph.js +3 -0
- package/lib/types/typed-contract.d.ts +102 -0
- package/lib/types/typed-contract.js +3 -0
- package/lib/types/user.d.ts +1 -0
- package/lib/types/user.js +3 -0
- package/lib/types/vaults.d.ts +714 -0
- package/lib/types/vaults.js +24 -0
- package/lib/types/web3.d.ts +51 -0
- package/lib/types/web3.js +14 -0
- package/lib/types/webserver.d.ts +698 -0
- package/lib/types/webserver.js +3 -0
- package/package.json +78 -0
|
@@ -0,0 +1,105 @@
|
|
|
1
|
+
/** @module core/services/swap-quotes */
|
|
2
|
+
import type { IAddress } from '../../types';
|
|
3
|
+
/** Quote-provider discriminant. Will widen as new providers are added. */
|
|
4
|
+
export type ISwapQuoteProvider = 'paraswap';
|
|
5
|
+
/**
|
|
6
|
+
* Input to {@link fetchSwapQuote}.
|
|
7
|
+
*/
|
|
8
|
+
export interface ISwapQuoteRequest {
|
|
9
|
+
/** EVM chain ID where the swap will execute. */
|
|
10
|
+
chainId: number;
|
|
11
|
+
/** ERC-20 the user holds. */
|
|
12
|
+
srcToken: IAddress;
|
|
13
|
+
/** `srcToken.decimals()`. */
|
|
14
|
+
srcDecimals: number;
|
|
15
|
+
/** ERC-20 the SwapRouter should produce — typically the vault's `referenceAsset`. */
|
|
16
|
+
destToken: IAddress;
|
|
17
|
+
/** `destToken.decimals()`. */
|
|
18
|
+
destDecimals: number;
|
|
19
|
+
/** Input amount in `srcToken`'s smallest unit. */
|
|
20
|
+
amount: bigint;
|
|
21
|
+
/**
|
|
22
|
+
* Address that will execute the resulting calldata. For SwapRouter use,
|
|
23
|
+
* pass the SwapRouter's address — the aggregator's calldata is bound to
|
|
24
|
+
* this address, so it must hold the tokens at swap time.
|
|
25
|
+
*/
|
|
26
|
+
receiver: IAddress;
|
|
27
|
+
/**
|
|
28
|
+
* Slippage tolerance in bps (1 bp = 0.01%). Defaults to 100 (1%). Must be
|
|
29
|
+
* in `[0, 10_000)` — 10_000 disables protection entirely and is rejected.
|
|
30
|
+
*/
|
|
31
|
+
slippageBps?: number;
|
|
32
|
+
/**
|
|
33
|
+
* Optional aggregator contract-method filter. When set, the aggregator is
|
|
34
|
+
* constrained to this single method (ParaSwap's `/prices`
|
|
35
|
+
* `includeContractMethods`), so the returned calldata's leading 4-byte
|
|
36
|
+
* selector is deterministic — required when the on-chain SwapRouter only
|
|
37
|
+
* authorizes one selector per router. When omitted, the aggregator picks the
|
|
38
|
+
* optimal method freely and the selector may vary between quotes.
|
|
39
|
+
*/
|
|
40
|
+
contractMethod?: string;
|
|
41
|
+
/** Aggregator partner key. Defaults to `'august'`. */
|
|
42
|
+
partner?: string;
|
|
43
|
+
/** Aggregator partner-fee receiver. Defaults to the August partner address. */
|
|
44
|
+
partnerAddress?: IAddress;
|
|
45
|
+
/**
|
|
46
|
+
* `fetch`-compatible function override. Defaults to `globalThis.fetch`.
|
|
47
|
+
* Exposed so callers in Node environments lacking a global `fetch` can
|
|
48
|
+
* inject one, and so tests can mock without touching the global.
|
|
49
|
+
*/
|
|
50
|
+
fetchImpl?: typeof fetch;
|
|
51
|
+
/** Optional AbortSignal to cancel the in-flight Paraswap requests. */
|
|
52
|
+
signal?: AbortSignal;
|
|
53
|
+
}
|
|
54
|
+
/**
|
|
55
|
+
* Output of {@link fetchSwapQuote}. The `router` + `payload` pair maps
|
|
56
|
+
* directly into one entry of an `ISwapParams[]` passed to
|
|
57
|
+
* `SwapRouter.swapAndDeposit`.
|
|
58
|
+
*
|
|
59
|
+
* Modeled as a discriminated union on `provider` so adding 1inch/0x is an
|
|
60
|
+
* additive change rather than a breaking widening.
|
|
61
|
+
*/
|
|
62
|
+
export type ISwapQuoteResult = {
|
|
63
|
+
/** Quote provider that produced this calldata. */
|
|
64
|
+
provider: 'paraswap';
|
|
65
|
+
/** DEX router that will execute the swap (the contract `payload` is calldata for). */
|
|
66
|
+
router: IAddress;
|
|
67
|
+
/** ABI-encoded calldata for `router`. */
|
|
68
|
+
payload: `0x${string}`;
|
|
69
|
+
/** Expected output in `destToken` units before slippage. */
|
|
70
|
+
expectedAmountOut: bigint;
|
|
71
|
+
/** Slippage-adjusted minimum output. Below this the on-chain call reverts. */
|
|
72
|
+
minAmountOut: bigint;
|
|
73
|
+
/**
|
|
74
|
+
* Epoch ms when the quote was fetched. Callers that prefetch a quote
|
|
75
|
+
* before submitting should re-fetch when this is older than ~60s — DEX
|
|
76
|
+
* pool state moves and a stale `minAmountOut` may have been computed
|
|
77
|
+
* against a price that no longer holds.
|
|
78
|
+
*/
|
|
79
|
+
fetchedAt: number;
|
|
80
|
+
};
|
|
81
|
+
/**
|
|
82
|
+
* Fetch a swap quote and the calldata required for the on-chain SwapRouter
|
|
83
|
+
* to execute it.
|
|
84
|
+
*
|
|
85
|
+
* @throws {@link AugustValidationError} on invalid input (slippage out of
|
|
86
|
+
* range, zero amount, src===dst).
|
|
87
|
+
* @throws {@link AugustNetworkError} on transport failure.
|
|
88
|
+
* @throws {@link AugustServerError} on aggregator-side errors.
|
|
89
|
+
*
|
|
90
|
+
* @example
|
|
91
|
+
* ```ts
|
|
92
|
+
* const quote = await fetchSwapQuote({
|
|
93
|
+
* chainId: 1,
|
|
94
|
+
* srcToken: WBTC,
|
|
95
|
+
* srcDecimals: 8,
|
|
96
|
+
* destToken: USDC,
|
|
97
|
+
* destDecimals: 6,
|
|
98
|
+
* amount: 100_000_000n,
|
|
99
|
+
* receiver: SWAP_ROUTER_ADDRESSES[1]!,
|
|
100
|
+
* });
|
|
101
|
+
* // quote.router -> Paraswap augustor
|
|
102
|
+
* // quote.payload -> calldata
|
|
103
|
+
* ```
|
|
104
|
+
*/
|
|
105
|
+
export declare function fetchSwapQuote(request: ISwapQuoteRequest): Promise<ISwapQuoteResult>;
|
|
@@ -0,0 +1,77 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/** @module core/services/swap-quotes */
|
|
3
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
4
|
+
exports.fetchSwapQuote = fetchSwapQuote;
|
|
5
|
+
const errors_1 = require("../../core/errors");
|
|
6
|
+
const paraswap_1 = require("./paraswap");
|
|
7
|
+
const DEFAULT_SLIPPAGE_BPS = 100;
|
|
8
|
+
const BPS_DENOMINATOR = 10000n;
|
|
9
|
+
/**
|
|
10
|
+
* Fetch a swap quote and the calldata required for the on-chain SwapRouter
|
|
11
|
+
* to execute it.
|
|
12
|
+
*
|
|
13
|
+
* @throws {@link AugustValidationError} on invalid input (slippage out of
|
|
14
|
+
* range, zero amount, src===dst).
|
|
15
|
+
* @throws {@link AugustNetworkError} on transport failure.
|
|
16
|
+
* @throws {@link AugustServerError} on aggregator-side errors.
|
|
17
|
+
*
|
|
18
|
+
* @example
|
|
19
|
+
* ```ts
|
|
20
|
+
* const quote = await fetchSwapQuote({
|
|
21
|
+
* chainId: 1,
|
|
22
|
+
* srcToken: WBTC,
|
|
23
|
+
* srcDecimals: 8,
|
|
24
|
+
* destToken: USDC,
|
|
25
|
+
* destDecimals: 6,
|
|
26
|
+
* amount: 100_000_000n,
|
|
27
|
+
* receiver: SWAP_ROUTER_ADDRESSES[1]!,
|
|
28
|
+
* });
|
|
29
|
+
* // quote.router -> Paraswap augustor
|
|
30
|
+
* // quote.payload -> calldata
|
|
31
|
+
* ```
|
|
32
|
+
*/
|
|
33
|
+
async function fetchSwapQuote(request) {
|
|
34
|
+
validateRequest(request);
|
|
35
|
+
const slippageBps = request.slippageBps ?? DEFAULT_SLIPPAGE_BPS;
|
|
36
|
+
const fetchImpl = request.fetchImpl ?? globalThis.fetch;
|
|
37
|
+
const { router, payload, expectedAmountOut, fetchedAt } = await (0, paraswap_1.fetchParaswapQuote)({
|
|
38
|
+
chainId: request.chainId,
|
|
39
|
+
srcToken: request.srcToken,
|
|
40
|
+
srcDecimals: request.srcDecimals,
|
|
41
|
+
destToken: request.destToken,
|
|
42
|
+
destDecimals: request.destDecimals,
|
|
43
|
+
amount: request.amount,
|
|
44
|
+
receiver: request.receiver,
|
|
45
|
+
slippageBps,
|
|
46
|
+
partner: request.partner ?? paraswap_1.PARASWAP_DEFAULTS.partner,
|
|
47
|
+
partnerAddress: request.partnerAddress ?? paraswap_1.PARASWAP_DEFAULTS.partnerAddress,
|
|
48
|
+
contractMethod: request.contractMethod,
|
|
49
|
+
fetchImpl,
|
|
50
|
+
signal: request.signal,
|
|
51
|
+
});
|
|
52
|
+
const minAmountOut = applySlippage(expectedAmountOut, slippageBps);
|
|
53
|
+
return {
|
|
54
|
+
provider: 'paraswap',
|
|
55
|
+
router,
|
|
56
|
+
payload,
|
|
57
|
+
expectedAmountOut,
|
|
58
|
+
minAmountOut,
|
|
59
|
+
fetchedAt,
|
|
60
|
+
};
|
|
61
|
+
}
|
|
62
|
+
function validateRequest(req) {
|
|
63
|
+
if (req.slippageBps !== undefined &&
|
|
64
|
+
(req.slippageBps < 0 || req.slippageBps >= 10_000)) {
|
|
65
|
+
throw new errors_1.AugustValidationError('INVALID_INPUT', `fetchSwapQuote: slippageBps must be in [0, 10000), got ${req.slippageBps}. 10000 bps = 100% slippage and disables protection entirely; use a tighter bound.`);
|
|
66
|
+
}
|
|
67
|
+
if (req.amount === 0n) {
|
|
68
|
+
throw new errors_1.AugustValidationError('INVALID_INPUT', 'fetchSwapQuote: amount must be greater than zero');
|
|
69
|
+
}
|
|
70
|
+
if (req.srcToken.toLowerCase() === req.destToken.toLowerCase()) {
|
|
71
|
+
throw new errors_1.AugustValidationError('INVALID_INPUT', 'fetchSwapQuote: srcToken and destToken are identical — no swap needed');
|
|
72
|
+
}
|
|
73
|
+
}
|
|
74
|
+
function applySlippage(amount, slippageBps) {
|
|
75
|
+
return (amount * (BPS_DENOMINATOR - BigInt(slippageBps))) / BPS_DENOMINATOR;
|
|
76
|
+
}
|
|
77
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
import type { IAddress } from '../../types';
|
|
2
|
+
export interface IParaswapQuoteInput {
|
|
3
|
+
chainId: number;
|
|
4
|
+
srcToken: IAddress;
|
|
5
|
+
srcDecimals: number;
|
|
6
|
+
destToken: IAddress;
|
|
7
|
+
destDecimals: number;
|
|
8
|
+
amount: bigint;
|
|
9
|
+
receiver: IAddress;
|
|
10
|
+
/**
|
|
11
|
+
* Slippage tolerance in bps (1 bp = 0.01%). Used to derive the
|
|
12
|
+
* `destAmount` minimum baked into the resulting Paraswap calldata, so the
|
|
13
|
+
* on-chain DEX leg enforces the same tolerance the SwapRouter does
|
|
14
|
+
* (otherwise the leg reverts at the aggregator's exact-out check before
|
|
15
|
+
* the SwapRouter's `minAmountOut` is ever evaluated).
|
|
16
|
+
*/
|
|
17
|
+
slippageBps: number;
|
|
18
|
+
partner: string;
|
|
19
|
+
partnerAddress: IAddress;
|
|
20
|
+
/**
|
|
21
|
+
* Optional `includeContractMethods` value passed to Paraswap's `/prices`. When
|
|
22
|
+
* set, Paraswap is restricted to this single contract method so the resulting
|
|
23
|
+
* calldata's leading selector is deterministic and matches the one the
|
|
24
|
+
* SwapRouter authorizes for this router. When omitted, Paraswap is free to
|
|
25
|
+
* pick whichever method is optimal for the route.
|
|
26
|
+
*/
|
|
27
|
+
contractMethod?: string;
|
|
28
|
+
fetchImpl: typeof fetch;
|
|
29
|
+
signal?: AbortSignal;
|
|
30
|
+
}
|
|
31
|
+
export interface IParaswapQuoteOutput {
|
|
32
|
+
router: IAddress;
|
|
33
|
+
payload: `0x${string}`;
|
|
34
|
+
expectedAmountOut: bigint;
|
|
35
|
+
fetchedAt: number;
|
|
36
|
+
}
|
|
37
|
+
/**
|
|
38
|
+
* Fetch a Paraswap quote and the calldata to execute it on behalf of the
|
|
39
|
+
* SwapRouter. Throws `AugustNetworkError` on fetch-layer failure and
|
|
40
|
+
* `AugustServerError` on Paraswap-side error responses or malformed bodies.
|
|
41
|
+
*
|
|
42
|
+
* `fetchedAt` is the wall-clock timestamp captured *after* the calldata
|
|
43
|
+
* response — callers downstream can use it to decide whether the leg is
|
|
44
|
+
* fresh enough to broadcast (DEX pool state moves; stale calldata may
|
|
45
|
+
* silently revert at the on-chain slippage check).
|
|
46
|
+
*/
|
|
47
|
+
export declare function fetchParaswapQuote(input: IParaswapQuoteInput): Promise<IParaswapQuoteOutput>;
|
|
48
|
+
export declare const PARASWAP_DEFAULTS: {
|
|
49
|
+
readonly partner: "august";
|
|
50
|
+
readonly partnerAddress: `0x${string}`;
|
|
51
|
+
};
|
|
@@ -0,0 +1,138 @@
|
|
|
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
|
+
/**
|
|
14
|
+
* Fetch a Paraswap quote and the calldata to execute it on behalf of the
|
|
15
|
+
* SwapRouter. Throws `AugustNetworkError` on fetch-layer failure and
|
|
16
|
+
* `AugustServerError` on Paraswap-side error responses or malformed bodies.
|
|
17
|
+
*
|
|
18
|
+
* `fetchedAt` is the wall-clock timestamp captured *after* the calldata
|
|
19
|
+
* response — callers downstream can use it to decide whether the leg is
|
|
20
|
+
* fresh enough to broadcast (DEX pool state moves; stale calldata may
|
|
21
|
+
* silently revert at the on-chain slippage check).
|
|
22
|
+
*/
|
|
23
|
+
async function fetchParaswapQuote(input) {
|
|
24
|
+
const priceRoute = await getPriceRoute(input);
|
|
25
|
+
const destAmountRaw = priceRoute.destAmount;
|
|
26
|
+
if (typeof destAmountRaw !== 'string' || !/^\d+$/.test(destAmountRaw)) {
|
|
27
|
+
throw new errors_1.AugustServerError(200, `fetchSwapQuote: Paraswap /prices returned non-numeric destAmount: ${String(destAmountRaw)}`, { context: { destAmount: destAmountRaw } });
|
|
28
|
+
}
|
|
29
|
+
const expectedAmountOut = BigInt(destAmountRaw);
|
|
30
|
+
const { router, payload } = await getTransactionData(input, priceRoute);
|
|
31
|
+
return { router, payload, expectedAmountOut, fetchedAt: Date.now() };
|
|
32
|
+
}
|
|
33
|
+
async function getPriceRoute(input) {
|
|
34
|
+
const params = new URLSearchParams({
|
|
35
|
+
network: String(input.chainId),
|
|
36
|
+
srcToken: input.srcToken,
|
|
37
|
+
srcDecimals: String(input.srcDecimals),
|
|
38
|
+
destToken: input.destToken,
|
|
39
|
+
destDecimals: String(input.destDecimals),
|
|
40
|
+
amount: input.amount.toString(),
|
|
41
|
+
partner: input.partner,
|
|
42
|
+
partnerAddress: input.partnerAddress,
|
|
43
|
+
version: PARASWAP_VERSION,
|
|
44
|
+
});
|
|
45
|
+
// Restrict the route to a single contract method when the caller pins one,
|
|
46
|
+
// so the calldata's selector is deterministic and matches the SwapRouter's
|
|
47
|
+
// per-router authorized selector. Without this the aggregator may return a
|
|
48
|
+
// route-optimized method (e.g. swapExactAmountInOnUniswapV3) whose selector
|
|
49
|
+
// the SwapRouter has not whitelisted, reverting with InvalidNotWhitelisted().
|
|
50
|
+
if (input.contractMethod) {
|
|
51
|
+
params.append('includeContractMethods', input.contractMethod);
|
|
52
|
+
}
|
|
53
|
+
const url = `${PARASWAP_PRICES_URL}?${params.toString()}`;
|
|
54
|
+
let response;
|
|
55
|
+
try {
|
|
56
|
+
response = await input.fetchImpl(url, {
|
|
57
|
+
method: 'GET',
|
|
58
|
+
headers: { 'Content-Type': 'application/json' },
|
|
59
|
+
signal: input.signal,
|
|
60
|
+
});
|
|
61
|
+
}
|
|
62
|
+
catch (cause) {
|
|
63
|
+
throw new errors_1.AugustNetworkError('fetchSwapQuote: Paraswap /prices fetch failed', { cause, context: { url } });
|
|
64
|
+
}
|
|
65
|
+
if (!response.ok) {
|
|
66
|
+
throw new errors_1.AugustServerError(response.status, `fetchSwapQuote: Paraswap /prices returned HTTP ${response.status}`, { context: { url } });
|
|
67
|
+
}
|
|
68
|
+
const body = (await response.json());
|
|
69
|
+
if (body.error) {
|
|
70
|
+
throw new errors_1.AugustServerError(response.status, `fetchSwapQuote: Paraswap /prices error: ${body.error}`, { context: { providerError: body.error } });
|
|
71
|
+
}
|
|
72
|
+
if (!body.priceRoute) {
|
|
73
|
+
throw new errors_1.AugustServerError(response.status, 'fetchSwapQuote: Paraswap /prices returned no priceRoute', { context: { body } });
|
|
74
|
+
}
|
|
75
|
+
return body.priceRoute;
|
|
76
|
+
}
|
|
77
|
+
async function getTransactionData(input, priceRoute) {
|
|
78
|
+
const url = `${PARASWAP_TRANSACTIONS_BASE_URL}/${input.chainId}/?ignoreChecks=true&ignoreGasEstimate=true&onlyParams=false`;
|
|
79
|
+
// Bake slippage into the destAmount Paraswap embeds as the aggregator's
|
|
80
|
+
// own min-out, so the DEX leg enforces the same lower bound the
|
|
81
|
+
// SwapRouter will check. Without this the aggregator uses the exact
|
|
82
|
+
// priceRoute quote (0% tolerance) and reverts on any adverse movement.
|
|
83
|
+
const expectedDestAmount = BigInt(priceRoute.destAmount);
|
|
84
|
+
const minDestAmount = (expectedDestAmount * (BPS_DENOMINATOR - BigInt(input.slippageBps))) /
|
|
85
|
+
BPS_DENOMINATOR;
|
|
86
|
+
const requestBody = {
|
|
87
|
+
userAddress: input.receiver,
|
|
88
|
+
srcToken: input.srcToken,
|
|
89
|
+
destToken: input.destToken,
|
|
90
|
+
srcDecimals: input.srcDecimals,
|
|
91
|
+
destDecimals: input.destDecimals,
|
|
92
|
+
srcAmount: input.amount.toString(),
|
|
93
|
+
destAmount: minDestAmount.toString(),
|
|
94
|
+
priceRoute,
|
|
95
|
+
partner: input.partner,
|
|
96
|
+
partnerAddress: input.partnerAddress,
|
|
97
|
+
};
|
|
98
|
+
let response;
|
|
99
|
+
try {
|
|
100
|
+
response = await input.fetchImpl(url, {
|
|
101
|
+
method: 'POST',
|
|
102
|
+
headers: { 'Content-Type': 'application/json' },
|
|
103
|
+
body: JSON.stringify(requestBody),
|
|
104
|
+
signal: input.signal,
|
|
105
|
+
});
|
|
106
|
+
}
|
|
107
|
+
catch (cause) {
|
|
108
|
+
throw new errors_1.AugustNetworkError('fetchSwapQuote: Paraswap /transactions fetch failed', { cause, context: { url } });
|
|
109
|
+
}
|
|
110
|
+
if (!response.ok) {
|
|
111
|
+
throw new errors_1.AugustServerError(response.status, `fetchSwapQuote: Paraswap /transactions returned HTTP ${response.status}`, { context: { url } });
|
|
112
|
+
}
|
|
113
|
+
const body = (await response.json());
|
|
114
|
+
if (body.error) {
|
|
115
|
+
throw new errors_1.AugustServerError(response.status, `fetchSwapQuote: Paraswap /transactions error: ${body.error}`, { context: { providerError: body.error } });
|
|
116
|
+
}
|
|
117
|
+
if (!body.to || !body.data) {
|
|
118
|
+
throw new errors_1.AugustServerError(response.status, 'fetchSwapQuote: Paraswap /transactions returned no to/data', { context: { body } });
|
|
119
|
+
}
|
|
120
|
+
if (!(0, web3_1.checkAddress)(body.to, console, 'contract')) {
|
|
121
|
+
throw new errors_1.AugustServerError(response.status, `fetchSwapQuote: Paraswap /transactions returned an invalid router address: ${body.to}`, { context: { to: body.to } });
|
|
122
|
+
}
|
|
123
|
+
if (!/^0x[0-9a-fA-F]+$/.test(body.data) || body.data.length % 2 !== 0) {
|
|
124
|
+
throw new errors_1.AugustServerError(response.status, `fetchSwapQuote: Paraswap /transactions returned malformed calldata (${body.data.length} chars)`, { context: { dataPrefix: body.data.slice(0, 16) } });
|
|
125
|
+
}
|
|
126
|
+
if (body.data.length < 10) {
|
|
127
|
+
throw new errors_1.AugustValidationError('INVALID_INPUT', 'fetchSwapQuote: Paraswap /transactions returned calldata shorter than a 4-byte selector');
|
|
128
|
+
}
|
|
129
|
+
return {
|
|
130
|
+
router: body.to,
|
|
131
|
+
payload: body.data,
|
|
132
|
+
};
|
|
133
|
+
}
|
|
134
|
+
exports.PARASWAP_DEFAULTS = {
|
|
135
|
+
partner: DEFAULT_PARTNER,
|
|
136
|
+
partnerAddress: DEFAULT_PARTNER_ADDRESS,
|
|
137
|
+
};
|
|
138
|
+
//# sourceMappingURL=paraswap.js.map
|
|
@@ -0,0 +1,280 @@
|
|
|
1
|
+
import type { IAddress } from './web3';
|
|
2
|
+
/**
|
|
3
|
+
* A whitelisted token as embedded in loan-book records by the backend
|
|
4
|
+
* `WhitelistedTokenModel` schema. `chain` is the numeric August chain id
|
|
5
|
+
* (backend `Chain` IntEnum value, e.g. `1` for Ethereum mainnet).
|
|
6
|
+
*/
|
|
7
|
+
export interface IWhitelistedToken {
|
|
8
|
+
chain: number;
|
|
9
|
+
name: string;
|
|
10
|
+
token_type: string;
|
|
11
|
+
address: IAddress;
|
|
12
|
+
decimals: number;
|
|
13
|
+
symbol: string;
|
|
14
|
+
discount_factor: number;
|
|
15
|
+
img_url: string | null;
|
|
16
|
+
price: number | null;
|
|
17
|
+
}
|
|
18
|
+
/**
|
|
19
|
+
* The amount and due date of a loan's next scheduled payment, as serialized
|
|
20
|
+
* by the backend `UpcomingPayment` schema. `due_date` is an ISO-8601 datetime
|
|
21
|
+
* string.
|
|
22
|
+
*/
|
|
23
|
+
export interface ILoanUpcomingPayment {
|
|
24
|
+
amount: number;
|
|
25
|
+
due_date: string;
|
|
26
|
+
}
|
|
27
|
+
/**
|
|
28
|
+
* One loan-book entry from the admin loan-book endpoints (backend
|
|
29
|
+
* `LoanBookInfo` schema). Amounts are decimal-adjusted floats; monetary
|
|
30
|
+
* fields are denominated in the loan's principal token. `deployed_date` is an
|
|
31
|
+
* ISO-8601 datetime string; `state` is the backend `LoanStateStr` value
|
|
32
|
+
* (e.g. `"ACTIVE"`).
|
|
33
|
+
*/
|
|
34
|
+
export interface ILoanBookInfo {
|
|
35
|
+
address: IAddress;
|
|
36
|
+
lender: IAddress;
|
|
37
|
+
borrower: IAddress;
|
|
38
|
+
state: string;
|
|
39
|
+
total_repaid: number;
|
|
40
|
+
principal_token: IWhitelistedToken;
|
|
41
|
+
principal_amount: number;
|
|
42
|
+
interest_amount: number;
|
|
43
|
+
upcoming_payment: ILoanUpcomingPayment;
|
|
44
|
+
apr: number;
|
|
45
|
+
initial_principal_amount: number;
|
|
46
|
+
deployed_date: string;
|
|
47
|
+
payment_interval: number;
|
|
48
|
+
total_interest_payment_fees: number;
|
|
49
|
+
lender_apr: number;
|
|
50
|
+
}
|
|
51
|
+
/**
|
|
52
|
+
* A token's discount-factor ladder from `GET /risk/discount_factors`
|
|
53
|
+
* (backend `DiscountFactorRead` schema). `steps` are ascending notional
|
|
54
|
+
* thresholds (in the token's smallest unit) and `factors` the corresponding
|
|
55
|
+
* ascending haircut multipliers in `[0, 1]`; the two arrays are equal length.
|
|
56
|
+
* `chain` is the numeric August chain id.
|
|
57
|
+
*/
|
|
58
|
+
export interface IDiscountFactorLadder {
|
|
59
|
+
steps: number[] | null;
|
|
60
|
+
factors: number[] | null;
|
|
61
|
+
address: IAddress;
|
|
62
|
+
chain: number;
|
|
63
|
+
}
|
|
64
|
+
/**
|
|
65
|
+
* Result of `GET /risk/collateral_excess_or_deficit` (backend
|
|
66
|
+
* `CollateralExcessOrDeficit` schema). A positive value is excess collateral
|
|
67
|
+
* that could be withdrawn; a negative value is the shortfall that must be
|
|
68
|
+
* deposited to reach the target health factor.
|
|
69
|
+
*/
|
|
70
|
+
export interface ICollateralExcessOrDeficit {
|
|
71
|
+
amount_usd: number;
|
|
72
|
+
amount_token: number;
|
|
73
|
+
}
|
|
74
|
+
/**
|
|
75
|
+
* Request body for `POST /risk/collateral_simulation` (backend
|
|
76
|
+
* `CollateralSimulation` schema). Chain fields are numeric August chain ids.
|
|
77
|
+
* `collateral_tokens` is a list of `[chain, address]` pairs and
|
|
78
|
+
* `collateral_token_allocation` the matching per-token weights (normalized
|
|
79
|
+
* server-side, so relative magnitudes are what matter). When `on_platform`
|
|
80
|
+
* is `true`, both `loan_redeployed_token_*` fields are required by the
|
|
81
|
+
* backend.
|
|
82
|
+
*/
|
|
83
|
+
export interface ICollateralSimulationInput {
|
|
84
|
+
loan_token_chain: number;
|
|
85
|
+
loan_token_address: IAddress;
|
|
86
|
+
loan_amount: number;
|
|
87
|
+
on_platform?: boolean;
|
|
88
|
+
loan_redeployed_token_chain?: number | null;
|
|
89
|
+
loan_redeployed_token_address?: IAddress | null;
|
|
90
|
+
collateral_tokens: [number, IAddress][];
|
|
91
|
+
collateral_token_allocation: number[];
|
|
92
|
+
target_health_factor?: number;
|
|
93
|
+
}
|
|
94
|
+
/**
|
|
95
|
+
* Per-collateral-token breakdown within a collateral simulation (backend
|
|
96
|
+
* `CollateralDetailsResult` schema). `chain` is the numeric August chain id.
|
|
97
|
+
*/
|
|
98
|
+
export interface ICollateralDetailsResult {
|
|
99
|
+
chain: number;
|
|
100
|
+
token_address: IAddress;
|
|
101
|
+
price: number;
|
|
102
|
+
allocation: number;
|
|
103
|
+
collateral_value_from_redeployed_loan_usd: number;
|
|
104
|
+
collateral_value_usd: number;
|
|
105
|
+
amount_usd: number;
|
|
106
|
+
amount_token: number;
|
|
107
|
+
effective_discount_factor: number;
|
|
108
|
+
is_top_up: boolean;
|
|
109
|
+
}
|
|
110
|
+
/**
|
|
111
|
+
* Result of `POST /risk/collateral_simulation` (backend
|
|
112
|
+
* `CollateralSimulationResults` schema). `collateral_details` is keyed by
|
|
113
|
+
* `"<symbol>_<chainName>"`.
|
|
114
|
+
*/
|
|
115
|
+
export interface ICollateralSimulationResults {
|
|
116
|
+
total_debt_usd: number;
|
|
117
|
+
total_required_collateral_usd: number;
|
|
118
|
+
total_collateral_value_from_redeployed_loan_usd: number;
|
|
119
|
+
health_factor: number;
|
|
120
|
+
collateral_details: Record<string, ICollateralDetailsResult>;
|
|
121
|
+
}
|
|
122
|
+
/**
|
|
123
|
+
* Result of the public `GET /revert_reason` endpoint (backend `RevertResponse`
|
|
124
|
+
* schema) — the decoded failure reasons for a reverted transaction, collected
|
|
125
|
+
* from a `debug_traceTransaction` call tree. All three arrays are empty when
|
|
126
|
+
* no matching signal was found in the trace.
|
|
127
|
+
*/
|
|
128
|
+
export interface IRevertReason {
|
|
129
|
+
error_messages: string[];
|
|
130
|
+
revert_reasons: string[];
|
|
131
|
+
universal_subaccount_errors: string[];
|
|
132
|
+
}
|
|
133
|
+
/**
|
|
134
|
+
* One transaction record from `GET /transactions/v2` (backend
|
|
135
|
+
* `TransactionAPIRead` schema). `chain` is the numeric August chain id;
|
|
136
|
+
* `value` is decimal-adjusted; `timestamp` is a Unix epoch (seconds).
|
|
137
|
+
* `from_` mirrors the backend field name (`from` is reserved). Nested
|
|
138
|
+
* `logs` / `transfers` / `function_signature` / `otc_cashflow` are passed
|
|
139
|
+
* through as-is. `transaction_name` is the resolved function name (or the raw
|
|
140
|
+
* selector when unknown).
|
|
141
|
+
*/
|
|
142
|
+
export interface ISubaccountTransaction {
|
|
143
|
+
id: string;
|
|
144
|
+
tx_hash: string;
|
|
145
|
+
chain: number;
|
|
146
|
+
from_: IAddress;
|
|
147
|
+
to: IAddress;
|
|
148
|
+
value: number;
|
|
149
|
+
block_number: number;
|
|
150
|
+
timestamp: number;
|
|
151
|
+
selector: string | null;
|
|
152
|
+
logs: unknown[];
|
|
153
|
+
transfers: unknown[];
|
|
154
|
+
function_signature: Record<string, unknown> | null;
|
|
155
|
+
otc_cashflow: Record<string, unknown> | null;
|
|
156
|
+
transaction_name: string | null;
|
|
157
|
+
}
|
|
158
|
+
/**
|
|
159
|
+
* DeBank positions and tokens for a single account (backend
|
|
160
|
+
* `DebankAccountData` schema). `positions`, `app_positions`, and `tokens`
|
|
161
|
+
* are passed through as raw DeBank objects.
|
|
162
|
+
*/
|
|
163
|
+
export interface ISubaccountDebankData {
|
|
164
|
+
positions: unknown[];
|
|
165
|
+
app_positions: unknown[];
|
|
166
|
+
tokens: unknown[];
|
|
167
|
+
}
|
|
168
|
+
/**
|
|
169
|
+
* Cross-chain DeBank protocol positions for a subaccount and its associated
|
|
170
|
+
* strategies (backend `SubaccountDebankAccountData` schema). `strategies` is
|
|
171
|
+
* keyed by strategy address. This endpoint is slow (300-second server-side
|
|
172
|
+
* cache) as it fans out across every supported chain.
|
|
173
|
+
*/
|
|
174
|
+
export interface ISubaccountDebank {
|
|
175
|
+
subaccount: ISubaccountDebankData;
|
|
176
|
+
strategies: Record<string, ISubaccountDebankData>;
|
|
177
|
+
}
|
|
178
|
+
/**
|
|
179
|
+
* A tracked position from `GET /otc/position` (backend `IPositionRead`
|
|
180
|
+
* schema). `configs` is a free-form JSON object of position-specific
|
|
181
|
+
* settings; `category` is the position category (e.g. `"otc"`).
|
|
182
|
+
*/
|
|
183
|
+
export interface IOtcPositionRead {
|
|
184
|
+
id: string;
|
|
185
|
+
slug: string;
|
|
186
|
+
position_class: string | null;
|
|
187
|
+
configs: Record<string, unknown> | null;
|
|
188
|
+
category: string | null;
|
|
189
|
+
position_discount_factor: number | null;
|
|
190
|
+
}
|
|
191
|
+
/**
|
|
192
|
+
* An OTC margin requirement from `GET /otc/margin_requirement` (backend
|
|
193
|
+
* `IOTCMarginRequirementRead` schema) — the margin the `payer` must post to
|
|
194
|
+
* the given counterparty.
|
|
195
|
+
*/
|
|
196
|
+
export interface IOtcMarginRequirement {
|
|
197
|
+
otc_counter_party_id: string;
|
|
198
|
+
margin_requirement: number;
|
|
199
|
+
payer: IAddress;
|
|
200
|
+
}
|
|
201
|
+
/**
|
|
202
|
+
* On-chain whitelist status of one subaccount linked to a vault, from
|
|
203
|
+
* `GET /curator/vaults/{vault_address}/whitelist` (backend
|
|
204
|
+
* `WhitelistStatusResponse` schema). EVM vaults only.
|
|
205
|
+
*/
|
|
206
|
+
export interface ICuratorWhitelistStatus {
|
|
207
|
+
address: IAddress;
|
|
208
|
+
is_whitelisted: boolean;
|
|
209
|
+
}
|
|
210
|
+
/**
|
|
211
|
+
* One timelock request from `GET /timelock-requests` (backend
|
|
212
|
+
* `ITimelockRequestRead` schema). `chain_id` is the numeric chain id;
|
|
213
|
+
* `status` is one of `"scheduled" | "executed" | "cancelled"`; `params` is a
|
|
214
|
+
* free-form JSON object; datetime fields are ISO-8601 strings.
|
|
215
|
+
*/
|
|
216
|
+
export interface ITimelockRequest {
|
|
217
|
+
id: string;
|
|
218
|
+
hash: string;
|
|
219
|
+
vault_address: IAddress;
|
|
220
|
+
timelock_address: IAddress;
|
|
221
|
+
chain_id: number;
|
|
222
|
+
action_id: string;
|
|
223
|
+
params: Record<string, unknown>;
|
|
224
|
+
status: string;
|
|
225
|
+
schedule_tx_hash: string;
|
|
226
|
+
execute_tx_hash: string | null;
|
|
227
|
+
cancel_tx_hash: string | null;
|
|
228
|
+
submitted_by: string | null;
|
|
229
|
+
scheduled_at: string;
|
|
230
|
+
resolved_at: string | null;
|
|
231
|
+
created_at: string | null;
|
|
232
|
+
updated_at: string | null;
|
|
233
|
+
}
|
|
234
|
+
/**
|
|
235
|
+
* Performance-fee computation for a vault from
|
|
236
|
+
* `GET /metrics/vault_performance_fees` (backend `UpshiftVaultPerformanceFees`
|
|
237
|
+
* schema). High/low water marks are share-price levels; `*_datetime` fields
|
|
238
|
+
* are ISO-8601 strings. `calculation_period` is `"YearToDate"` /
|
|
239
|
+
* `"MonthToDate"` (null when a custom date range was supplied).
|
|
240
|
+
*/
|
|
241
|
+
export interface IVaultPerformanceFees {
|
|
242
|
+
previous_water_mark: number;
|
|
243
|
+
previous_water_mark_datetime: string;
|
|
244
|
+
last_water_mark: number;
|
|
245
|
+
last_water_mark_datetime: string;
|
|
246
|
+
is_in_drawdown: boolean;
|
|
247
|
+
asset_symbol: string | null;
|
|
248
|
+
total_pnl_in_asset: number;
|
|
249
|
+
total_perf_fees_asset: number;
|
|
250
|
+
calculation_period: string | null;
|
|
251
|
+
annualized_fees_pct: number;
|
|
252
|
+
underlying_asset_vs_native_perf: number | null;
|
|
253
|
+
native_token_symbol: string | null;
|
|
254
|
+
}
|
|
255
|
+
/**
|
|
256
|
+
* One row of a vault's NAV-oracle classification table (backend
|
|
257
|
+
* `OracleClassificationRow` schema) — how a single position/token is priced
|
|
258
|
+
* and its USD value.
|
|
259
|
+
*/
|
|
260
|
+
export interface IOracleClassificationRow {
|
|
261
|
+
position: string;
|
|
262
|
+
type: string;
|
|
263
|
+
oracle_source: string;
|
|
264
|
+
usd_value: number;
|
|
265
|
+
}
|
|
266
|
+
/**
|
|
267
|
+
* A vault's NAV-oracle classification from the public
|
|
268
|
+
* `GET /upshift/oracle_classification/{vault_address}` endpoint (backend
|
|
269
|
+
* `OracleClassificationResponse` schema). `warnings` lists tokens that could
|
|
270
|
+
* not be resolved (`"unresolved:<symbol>"`). `snapshot_at` is an ISO-8601
|
|
271
|
+
* datetime string.
|
|
272
|
+
*/
|
|
273
|
+
export interface IOracleClassification {
|
|
274
|
+
vault_address: IAddress;
|
|
275
|
+
chain_id: number;
|
|
276
|
+
snapshot_at: string;
|
|
277
|
+
methodology: string;
|
|
278
|
+
rows: IOracleClassificationRow[];
|
|
279
|
+
warnings: string[];
|
|
280
|
+
}
|
package/lib/types/api.js
ADDED
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
export type IEnv = 'DEV' | 'PROD';
|
|
2
|
+
export * from './web3';
|
|
3
|
+
export * from './typed-contract';
|
|
4
|
+
export * from './user';
|
|
5
|
+
export * from './webserver';
|
|
6
|
+
export * from './pools';
|
|
7
|
+
export * from './staking';
|
|
8
|
+
export * from './subgraph';
|
|
9
|
+
export * from './vaults';
|
|
10
|
+
export * from './points';
|
|
11
|
+
export * from './sub-accounts';
|
|
12
|
+
export * from './api';
|