@upshiftfinance/sdk 0.0.0-stage → 0.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.
- package/LICENSE +21 -0
- package/README.md +408 -2
- 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 +953 -0
- package/lib/abis/SwapRouter.js +1228 -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 +249 -0
- package/lib/adapters/evm/index.d.ts +539 -0
- package/lib/adapters/evm/index.js +656 -0
- package/lib/adapters/evm/utils.d.ts +8 -0
- package/lib/adapters/evm/utils.js +51 -0
- package/lib/adapters/solana/confirm.d.ts +88 -0
- package/lib/adapters/solana/confirm.js +291 -0
- package/lib/adapters/solana/constants.d.ts +42 -0
- package/lib/adapters/solana/constants.js +59 -0
- package/lib/adapters/solana/getters.d.ts +42 -0
- package/lib/adapters/solana/getters.js +275 -0
- package/lib/adapters/solana/idl/vault-idl.d.ts +700 -0
- package/lib/adapters/solana/idl/vault-idl.js +2101 -0
- package/lib/adapters/solana/idl/withdrawal-queue-idl.d.ts +795 -0
- package/lib/adapters/solana/idl/withdrawal-queue-idl.js +1864 -0
- package/lib/adapters/solana/index.d.ts +372 -0
- package/lib/adapters/solana/index.js +459 -0
- package/lib/adapters/solana/pricing.d.ts +184 -0
- package/lib/adapters/solana/pricing.js +239 -0
- package/lib/adapters/solana/queue-hints.d.ts +29 -0
- package/lib/adapters/solana/queue-hints.js +59 -0
- package/lib/adapters/solana/queue.actions.d.ts +97 -0
- package/lib/adapters/solana/queue.actions.js +468 -0
- package/lib/adapters/solana/token-reads.d.ts +108 -0
- package/lib/adapters/solana/token-reads.js +145 -0
- package/lib/adapters/solana/types.d.ts +325 -0
- package/lib/adapters/solana/types.js +3 -0
- package/lib/adapters/solana/utils.d.ts +229 -0
- package/lib/adapters/solana/utils.js +773 -0
- package/lib/adapters/solana/vault.actions.d.ts +140 -0
- package/lib/adapters/solana/vault.actions.js +657 -0
- package/lib/adapters/solana/withdrawal-queue.d.ts +125 -0
- package/lib/adapters/solana/withdrawal-queue.js +301 -0
- package/lib/adapters/stellar/actions.d.ts +41 -0
- package/lib/adapters/stellar/actions.js +126 -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 +126 -0
- package/lib/adapters/stellar/index.js +187 -0
- package/lib/adapters/stellar/invocation.d.ts +55 -0
- package/lib/adapters/stellar/invocation.js +92 -0
- package/lib/adapters/stellar/soroban.d.ts +131 -0
- package/lib/adapters/stellar/soroban.js +617 -0
- package/lib/adapters/stellar/submit.d.ts +42 -0
- package/lib/adapters/stellar/submit.js +195 -0
- package/lib/adapters/stellar/types.d.ts +57 -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/client.d.ts +83 -0
- package/lib/adapters/sui/client.js +216 -0
- package/lib/adapters/sui/constants.d.ts +33 -0
- package/lib/adapters/sui/constants.js +31 -0
- package/lib/adapters/sui/index.d.ts +57 -0
- package/lib/adapters/sui/index.js +100 -0
- package/lib/adapters/sui/targets.d.ts +171 -0
- package/lib/adapters/sui/targets.js +225 -0
- package/lib/adapters/sui/utils.d.ts +8 -0
- package/lib/adapters/sui/utils.js +17 -0
- package/lib/core/analytics/app-name.d.ts +27 -0
- package/lib/core/analytics/app-name.js +48 -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 +15 -0
- package/lib/core/analytics/constants.js +28 -0
- package/lib/core/analytics/env.d.ts +46 -0
- package/lib/core/analytics/env.js +147 -0
- package/lib/core/analytics/index.d.ts +39 -0
- package/lib/core/analytics/index.js +83 -0
- package/lib/core/analytics/instrumentation.d.ts +29 -0
- package/lib/core/analytics/instrumentation.js +292 -0
- package/lib/core/analytics/method-taxonomy.d.ts +19 -0
- package/lib/core/analytics/method-taxonomy.js +156 -0
- package/lib/core/analytics/metrics.d.ts +48 -0
- package/lib/core/analytics/metrics.js +142 -0
- package/lib/core/analytics/sanitize.d.ts +57 -0
- package/lib/core/analytics/sanitize.js +272 -0
- package/lib/core/analytics/sentry-runtime.d.ts +15 -0
- package/lib/core/analytics/sentry-runtime.js +131 -0
- package/lib/core/analytics/sentry.d.ts +100 -0
- package/lib/core/analytics/sentry.js +696 -0
- package/lib/core/analytics/types.d.ts +55 -0
- package/lib/core/analytics/types.js +3 -0
- package/lib/core/analytics/user-identity.d.ts +55 -0
- package/lib/core/analytics/user-identity.js +218 -0
- package/lib/core/analytics/version.d.ts +6 -0
- package/lib/core/analytics/version.js +10 -0
- package/lib/core/attribution.d.ts +159 -0
- package/lib/core/attribution.js +194 -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 +35 -0
- package/lib/core/base.class.d.ts +193 -0
- package/lib/core/base.class.js +163 -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 +162 -0
- package/lib/core/constants/core.js +281 -0
- package/lib/core/constants/swap-router.d.ts +180 -0
- package/lib/core/constants/swap-router.js +203 -0
- package/lib/core/constants/vaults.d.ts +93 -0
- package/lib/core/constants/vaults.js +277 -0
- package/lib/core/constants/web3.d.ts +106 -0
- package/lib/core/constants/web3.js +251 -0
- package/lib/core/errors/index.d.ts +177 -0
- package/lib/core/errors/index.js +257 -0
- package/lib/core/fetcher.d.ts +237 -0
- package/lib/core/fetcher.js +1103 -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 +697 -0
- package/lib/core/helpers/chain-support.d.ts +98 -0
- package/lib/core/helpers/chain-support.js +139 -0
- package/lib/core/helpers/concurrency.d.ts +51 -0
- package/lib/core/helpers/concurrency.js +79 -0
- package/lib/core/helpers/core.d.ts +92 -0
- package/lib/core/helpers/core.js +368 -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 +61 -0
- package/lib/core/helpers/signer.js +184 -0
- package/lib/core/helpers/swap-router.d.ts +269 -0
- package/lib/core/helpers/swap-router.js +542 -0
- package/lib/core/helpers/vault-version.d.ts +24 -0
- package/lib/core/helpers/vault-version.js +83 -0
- package/lib/core/helpers/vaults.d.ts +89 -0
- package/lib/core/helpers/vaults.js +241 -0
- package/lib/core/helpers/web3.d.ts +366 -0
- package/lib/core/helpers/web3.js +1034 -0
- package/lib/core/index.d.ts +23 -0
- package/lib/core/index.js +40 -0
- package/lib/core/logger/curator-alert.d.ts +217 -0
- package/lib/core/logger/curator-alert.js +276 -0
- package/lib/core/logger/index.d.ts +99 -0
- package/lib/core/logger/index.js +163 -0
- package/lib/core/logger/slack.d.ts +49 -0
- package/lib/core/logger/slack.js +111 -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 +132 -0
- package/lib/evm/methods/crossChainVault.js +857 -0
- package/lib/evm/methods/crossChainVaultRegistry.d.ts +92 -0
- package/lib/evm/methods/crossChainVaultRegistry.js +239 -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 +596 -0
- package/lib/main.js +681 -0
- package/lib/modules/api/fetcher.d.ts +108 -0
- package/lib/modules/api/fetcher.js +187 -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 +587 -0
- package/lib/modules/api/main.js +911 -0
- package/lib/modules/sub-accounts/fetcher.d.ts +53 -0
- package/lib/modules/sub-accounts/fetcher.js +96 -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 +249 -0
- package/lib/modules/sub-accounts/main.js +211 -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 +84 -0
- package/lib/modules/vaults/adapter.helpers.js +202 -0
- package/lib/modules/vaults/fetcher.d.ts +147 -0
- package/lib/modules/vaults/fetcher.js +357 -0
- package/lib/modules/vaults/getters.d.ts +1060 -0
- package/lib/modules/vaults/getters.js +4079 -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 +607 -0
- package/lib/modules/vaults/main.js +1687 -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 +406 -0
- package/lib/modules/vaults/read.actions.js +891 -0
- package/lib/modules/vaults/types.d.ts +149 -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 +153 -0
- package/lib/modules/vaults/utils.js +818 -0
- package/lib/modules/vaults/write.actions.d.ts +812 -0
- package/lib/modules/vaults/write.actions.js +2377 -0
- package/lib/polyfills.d.ts +1 -0
- package/lib/polyfills.js +12 -0
- package/lib/sdk.d.ts +30173 -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 +50 -0
- package/lib/services/debank/utils.js +325 -0
- package/lib/services/layerzero/deposits.d.ts +55 -0
- package/lib/services/layerzero/deposits.js +174 -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 +33 -0
- package/lib/services/octavfi/fetcher.js +39 -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 +244 -0
- package/lib/services/subgraph/fetcher.d.ts +2 -0
- package/lib/services/subgraph/fetcher.js +66 -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 +48 -0
- package/lib/services/subgraph/schema.js +87 -0
- package/lib/services/subgraph/vaults.d.ts +83 -0
- package/lib/services/subgraph/vaults.js +1282 -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/services/untangled/fetcher.d.ts +40 -0
- package/lib/services/untangled/fetcher.js +110 -0
- package/lib/services/untangled/index.d.ts +3 -0
- package/lib/services/untangled/index.js +20 -0
- package/lib/services/untangled/types.d.ts +83 -0
- package/lib/services/untangled/types.js +10 -0
- package/lib/services/untangled/utils.d.ts +91 -0
- package/lib/services/untangled/utils.js +339 -0
- package/lib/types/api.d.ts +498 -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 +150 -0
- package/lib/types/sub-accounts.js +3 -0
- package/lib/types/subgraph.d.ts +84 -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 +886 -0
- package/lib/types/vaults.js +30 -0
- package/lib/types/web3.d.ts +100 -0
- package/lib/types/web3.js +14 -0
- package/lib/types/webserver.d.ts +730 -0
- package/lib/types/webserver.js +3 -0
- package/package.json +79 -3
|
@@ -0,0 +1,459 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
+
if (k2 === undefined) k2 = k;
|
|
4
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
+
}
|
|
8
|
+
Object.defineProperty(o, k2, desc);
|
|
9
|
+
}) : (function(o, m, k, k2) {
|
|
10
|
+
if (k2 === undefined) k2 = k;
|
|
11
|
+
o[k2] = m[k];
|
|
12
|
+
}));
|
|
13
|
+
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
14
|
+
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
15
|
+
}) : function(o, v) {
|
|
16
|
+
o["default"] = v;
|
|
17
|
+
});
|
|
18
|
+
var __importStar = (this && this.__importStar) || (function () {
|
|
19
|
+
var ownKeys = function(o) {
|
|
20
|
+
ownKeys = Object.getOwnPropertyNames || function (o) {
|
|
21
|
+
var ar = [];
|
|
22
|
+
for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
|
|
23
|
+
return ar;
|
|
24
|
+
};
|
|
25
|
+
return ownKeys(o);
|
|
26
|
+
};
|
|
27
|
+
return function (mod) {
|
|
28
|
+
if (mod && mod.__esModule) return mod;
|
|
29
|
+
var result = {};
|
|
30
|
+
if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
|
|
31
|
+
__setModuleDefault(result, mod);
|
|
32
|
+
return result;
|
|
33
|
+
};
|
|
34
|
+
})();
|
|
35
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
36
|
+
exports.Solana = void 0;
|
|
37
|
+
/**
|
|
38
|
+
* Solana Adapter for Upshift SDK
|
|
39
|
+
*
|
|
40
|
+
* @module SolanaAdapter
|
|
41
|
+
*/
|
|
42
|
+
const SolanaConstants = __importStar(require("./constants"));
|
|
43
|
+
const SolanaGetters = __importStar(require("./getters"));
|
|
44
|
+
const SolanaActions = __importStar(require("./vault.actions"));
|
|
45
|
+
const web3_js_1 = require("@solana/web3.js");
|
|
46
|
+
const utils_1 = require("./utils");
|
|
47
|
+
const vault_actions_1 = require("./vault.actions");
|
|
48
|
+
const queue_actions_1 = require("./queue.actions");
|
|
49
|
+
const constants_1 = require("./constants");
|
|
50
|
+
const core_1 = require("../../core");
|
|
51
|
+
exports.Solana = {
|
|
52
|
+
utils: utils_1.SolanaUtils,
|
|
53
|
+
constants: SolanaConstants,
|
|
54
|
+
actions: SolanaActions,
|
|
55
|
+
getters: SolanaGetters,
|
|
56
|
+
};
|
|
57
|
+
/**
|
|
58
|
+
* Solana Adapter for Upshift SDK
|
|
59
|
+
*
|
|
60
|
+
* @example
|
|
61
|
+
* To access the Solana adapter instance
|
|
62
|
+
* ```
|
|
63
|
+
* const sdk = new UpshiftSDK()
|
|
64
|
+
* sdk.solana.getVaultState()
|
|
65
|
+
* ```
|
|
66
|
+
*/
|
|
67
|
+
class SolanaAdapter {
|
|
68
|
+
_endpoint;
|
|
69
|
+
_network;
|
|
70
|
+
_connection;
|
|
71
|
+
_provider;
|
|
72
|
+
/**
|
|
73
|
+
* @param commitment - Commitment for every read this adapter makes *and* for
|
|
74
|
+
* the confirmation of every write, so the two always describe the same
|
|
75
|
+
* chain state — the vault handlers take it from this same `Connection`.
|
|
76
|
+
*
|
|
77
|
+
* Defaults to `'finalized'`, which is what this adapter has always used in
|
|
78
|
+
* practice: it previously passed no commitment at all, so both reads and
|
|
79
|
+
* confirmations fell through to the RPC's own `'finalized'` default. The
|
|
80
|
+
* default is stated explicitly now rather than inherited, but it is
|
|
81
|
+
* unchanged.
|
|
82
|
+
*
|
|
83
|
+
* Pass `'confirmed'` for a markedly faster round trip — seconds rather
|
|
84
|
+
* than tens of seconds — accepting that the state you act on can still, in
|
|
85
|
+
* principle, be rolled back. Also settable as the `commitment` field of
|
|
86
|
+
* the `solana` config passed to `UpshiftSDK`.
|
|
87
|
+
*/
|
|
88
|
+
constructor(endpoint, network = utils_1.SolanaUtils.fallbackNetwork, commitment = 'finalized') {
|
|
89
|
+
this._endpoint = endpoint;
|
|
90
|
+
this._network = network;
|
|
91
|
+
// Explicit rather than inherited: left unset, web3.js omits the parameter
|
|
92
|
+
// and the RPC applies its own default, which is the same 'finalized' —
|
|
93
|
+
// but then nothing ties it to the commitment writes confirm at.
|
|
94
|
+
const connection = new web3_js_1.Connection(endpoint, commitment);
|
|
95
|
+
this._connection = connection;
|
|
96
|
+
this._provider = utils_1.SolanaUtils.getReadOnlyProvider({
|
|
97
|
+
network: this._network,
|
|
98
|
+
connection,
|
|
99
|
+
});
|
|
100
|
+
}
|
|
101
|
+
// Getters and setters for private properties
|
|
102
|
+
get endpoint() {
|
|
103
|
+
return this._endpoint;
|
|
104
|
+
}
|
|
105
|
+
get network() {
|
|
106
|
+
return this._network;
|
|
107
|
+
}
|
|
108
|
+
get connection() {
|
|
109
|
+
return this._connection;
|
|
110
|
+
}
|
|
111
|
+
get provider() {
|
|
112
|
+
return this._provider;
|
|
113
|
+
}
|
|
114
|
+
// Method to set connection with wallet for authenticated operations
|
|
115
|
+
setWalletProvider(_publicKey, signTransaction) {
|
|
116
|
+
if (_publicKey && signTransaction) {
|
|
117
|
+
const publicKey = typeof _publicKey === 'string' ? new web3_js_1.PublicKey(_publicKey) : _publicKey;
|
|
118
|
+
this._provider = utils_1.SolanaUtils.getProvider({
|
|
119
|
+
network: this._network,
|
|
120
|
+
connection: this._connection,
|
|
121
|
+
publicKey,
|
|
122
|
+
signTransaction,
|
|
123
|
+
});
|
|
124
|
+
}
|
|
125
|
+
else {
|
|
126
|
+
this._provider = utils_1.SolanaUtils.getReadOnlyProvider({
|
|
127
|
+
network: this._network,
|
|
128
|
+
connection: this._connection,
|
|
129
|
+
});
|
|
130
|
+
}
|
|
131
|
+
}
|
|
132
|
+
/**
|
|
133
|
+
* Build an Anchor `Program` bound to this adapter's provider and network.
|
|
134
|
+
*
|
|
135
|
+
* The program id is resolved as: explicit `programId` → the `address` carried
|
|
136
|
+
* by a custom `programIdl` → the canonical deployment for this adapter's
|
|
137
|
+
* network. A copy of the SDK's bundled `vaultIdl` defers to the network
|
|
138
|
+
* default (its embedded `address` is a build stamp, not network-aware), so
|
|
139
|
+
* forwarding it on devnet never silently targets the mainnet program.
|
|
140
|
+
*
|
|
141
|
+
* An IDL whose `metadata.name` is `august_withdrawal_queue` resolves against
|
|
142
|
+
* the withdrawal queue program's network default instead of the vault's.
|
|
143
|
+
*
|
|
144
|
+
* @param programIdl - Anchor IDL to bind. Defaults to the SDK's bundled
|
|
145
|
+
* `august_vault` IDL. A custom IDL's `address` is honoured when it differs
|
|
146
|
+
* from the program's canonical id (the build stamp every bundled copy of
|
|
147
|
+
* the vault or queue IDL carries).
|
|
148
|
+
* @param programId - Base58 program id that overrides both the IDL's address
|
|
149
|
+
* and the network default. Use this to target a non-canonical deployment.
|
|
150
|
+
* @returns An Anchor `Program` for the resolved program id. No RPC is made —
|
|
151
|
+
* construction is offline.
|
|
152
|
+
* @throws {@link UpshiftValidationError} if no program id can be resolved
|
|
153
|
+
* because the program has no canonical deployment on this adapter's network
|
|
154
|
+
* (neither program on `testnet`) and neither `programId` nor a custom IDL
|
|
155
|
+
* address was supplied.
|
|
156
|
+
*
|
|
157
|
+
* @example
|
|
158
|
+
* ```ts
|
|
159
|
+
* // canonical program on the adapter's network
|
|
160
|
+
* const program = sdk.solana.getProgram();
|
|
161
|
+
*
|
|
162
|
+
* // a different deployment, same interface
|
|
163
|
+
* const legacy = sdk.solana.getProgram(vaultIdl, '7B8n9vL51b6ibqRAd1adZsi3x3kxtq5NZaondh22Vkyq');
|
|
164
|
+
* ```
|
|
165
|
+
*/
|
|
166
|
+
getProgram(programIdl, programId) {
|
|
167
|
+
return utils_1.SolanaUtils.getProgram({
|
|
168
|
+
network: this._network,
|
|
169
|
+
provider: this._provider,
|
|
170
|
+
idl: programIdl,
|
|
171
|
+
programId,
|
|
172
|
+
});
|
|
173
|
+
}
|
|
174
|
+
async getVaultState(vaultProgramId, idl, vaultAddress) {
|
|
175
|
+
return await utils_1.SolanaUtils.getVaultState({
|
|
176
|
+
network: this._network,
|
|
177
|
+
provider: this._provider,
|
|
178
|
+
connection: this._connection,
|
|
179
|
+
vaultProgramId,
|
|
180
|
+
vaultAddress,
|
|
181
|
+
idl,
|
|
182
|
+
});
|
|
183
|
+
}
|
|
184
|
+
async getVaultStateReadOnly(vaultProgramId, idl, vaultAddress) {
|
|
185
|
+
return await utils_1.SolanaUtils.getVaultStateReadOnly({
|
|
186
|
+
network: this._network,
|
|
187
|
+
connection: this._connection,
|
|
188
|
+
vaultProgramId,
|
|
189
|
+
vaultAddress,
|
|
190
|
+
idl,
|
|
191
|
+
});
|
|
192
|
+
}
|
|
193
|
+
async getToken(mintAddress) {
|
|
194
|
+
return await utils_1.SolanaUtils.getToken({
|
|
195
|
+
network: this._network,
|
|
196
|
+
mintAddress,
|
|
197
|
+
endpoint: this._endpoint,
|
|
198
|
+
});
|
|
199
|
+
}
|
|
200
|
+
async getTokenSymbol(mintAddress) {
|
|
201
|
+
return await utils_1.SolanaUtils.getTokenSymbol({
|
|
202
|
+
network: this._network,
|
|
203
|
+
mintAddress,
|
|
204
|
+
endpoint: this._endpoint,
|
|
205
|
+
});
|
|
206
|
+
}
|
|
207
|
+
async fetchUserTokenBalance(publicKey, depositMint) {
|
|
208
|
+
return await utils_1.SolanaUtils.fetchUserTokenBalance({
|
|
209
|
+
network: this._network,
|
|
210
|
+
connection: this._connection,
|
|
211
|
+
publicKey,
|
|
212
|
+
depositMint,
|
|
213
|
+
});
|
|
214
|
+
}
|
|
215
|
+
async fetchUserShareBalance(publicKey, shareMint) {
|
|
216
|
+
return await utils_1.SolanaUtils.fetchUserShareBalance({
|
|
217
|
+
network: this._network,
|
|
218
|
+
connection: this._connection,
|
|
219
|
+
publicKey,
|
|
220
|
+
shareMint,
|
|
221
|
+
});
|
|
222
|
+
}
|
|
223
|
+
/**
|
|
224
|
+
* BigInt-safe variant of {@link fetchUserShareBalance}. Returns the raw u64
|
|
225
|
+
* `amount` (as a base-units string) plus the mint's `decimals` (or `null`
|
|
226
|
+
* when the scale can't be determined — see Returns), so the caller can
|
|
227
|
+
* produce a correct `INormalizedNumber` without losing precision.
|
|
228
|
+
*
|
|
229
|
+
* Prefer this anywhere the result feeds BigInt math — positions, max-
|
|
230
|
+
* actions, redemption sizing, allowance checks. `fetchUserShareBalance`
|
|
231
|
+
* returns a JS-number `uiAmount` which silently encodes against 18 decimals
|
|
232
|
+
* when passed through `toNormalizedBn(value)` without an explicit decimals
|
|
233
|
+
* argument; that's exactly how the jitoSOL "missing position" regression
|
|
234
|
+
* manifested.
|
|
235
|
+
*
|
|
236
|
+
* RPC cost: 1 `getParsedTokenAccountsByOwner` call. Worst case ~150ms on a
|
|
237
|
+
* healthy mainnet endpoint.
|
|
238
|
+
*
|
|
239
|
+
* @param publicKey Wallet owner (PublicKey or base58 string).
|
|
240
|
+
* @param shareMint The vault's share-token mint (PublicKey or base58).
|
|
241
|
+
* @returns
|
|
242
|
+
* `{ amount, decimals }`. Three observable shapes:
|
|
243
|
+
* - `{ amount: '<u64>', decimals: <number> }` — token account exists.
|
|
244
|
+
* - `{ amount: '0', decimals: null }` — no token account for this mint
|
|
245
|
+
* under this wallet, OR `tokenAmount` was missing from the response,
|
|
246
|
+
* OR `publicKey`/`shareMint` was not supplied. Distinguishable from a
|
|
247
|
+
* genuine zero-balance account (`decimals` would be set there).
|
|
248
|
+
* - `{ amount: '0', decimals: null }` — RPC threw (error is logged).
|
|
249
|
+
*
|
|
250
|
+
* `decimals === null` means "we could not determine the scale" — callers
|
|
251
|
+
* that need an `INormalizedNumber` must fall back to a known decimals
|
|
252
|
+
* value (typically the deposit mint's decimals from backend metadata)
|
|
253
|
+
* before normalizing. Never throws.
|
|
254
|
+
*/
|
|
255
|
+
async fetchUserShareBalanceRaw(publicKey, shareMint) {
|
|
256
|
+
return await utils_1.SolanaUtils.fetchUserShareBalanceRaw({
|
|
257
|
+
network: this._network,
|
|
258
|
+
connection: this._connection,
|
|
259
|
+
publicKey,
|
|
260
|
+
shareMint,
|
|
261
|
+
});
|
|
262
|
+
}
|
|
263
|
+
/**
|
|
264
|
+
* Deposit funds into a Solana Upshift vault.
|
|
265
|
+
* @param depositAmount `bigint` (raw on-chain units) or `number` (UI amount).
|
|
266
|
+
* @param sendTransaction - **Ignored; scheduled for removal in the next major release.**
|
|
267
|
+
* Share-account creation is now prepended to the deposit instruction, so
|
|
268
|
+
* the SDK sends no second transaction and never invokes this callback —
|
|
269
|
+
* signing goes through the provider's wallet.
|
|
270
|
+
*
|
|
271
|
+
* **Pass `undefined` here; do not delete the argument.** It sits *before*
|
|
272
|
+
* `vaultAddress`, so removing it shifts your vault address into this slot
|
|
273
|
+
* and leaves `vaultAddress` undefined — which silently falls back to the
|
|
274
|
+
* legacy single-vault PDA derivation and targets a different vault.
|
|
275
|
+
* @param options - Slippage protection. By default the SDK quotes the shares this deposit should mint
|
|
276
|
+
* from the vault's current state and passes that quote, lowered by 50 bps,
|
|
277
|
+
* as the floor to the program's checked instruction. See {@link ISolanaDepositOptions}.
|
|
278
|
+
*/
|
|
279
|
+
async vaultDeposit(vaultProgramId, idl, publicKey, depositAmount, sendTransaction, vaultAddress, options) {
|
|
280
|
+
return await (0, vault_actions_1.handleSolanaDeposit)({
|
|
281
|
+
network: this._network,
|
|
282
|
+
provider: this._provider,
|
|
283
|
+
connection: this._connection,
|
|
284
|
+
vaultProgramId,
|
|
285
|
+
vaultAddress,
|
|
286
|
+
idl,
|
|
287
|
+
publicKey,
|
|
288
|
+
depositAmount,
|
|
289
|
+
sendTransaction,
|
|
290
|
+
options,
|
|
291
|
+
});
|
|
292
|
+
}
|
|
293
|
+
/**
|
|
294
|
+
* Redeem vault shares from a Solana Upshift vault.
|
|
295
|
+
* @param redeemShares `bigint` (raw share units) or `number` (UI amount).
|
|
296
|
+
* @param sendTransaction - **Ignored; scheduled for removal in the next major release.**
|
|
297
|
+
* Payout- and fee-recipient-account creation is now prepended to the redeem
|
|
298
|
+
* instruction, so the SDK sends no second transaction and never invokes
|
|
299
|
+
* this callback — signing goes through the provider's wallet.
|
|
300
|
+
*
|
|
301
|
+
* **Pass `undefined` here; do not delete the argument.** It sits *before*
|
|
302
|
+
* `vaultAddress`, so removing it shifts your vault address into this slot
|
|
303
|
+
* and leaves `vaultAddress` undefined — which silently falls back to the
|
|
304
|
+
* legacy single-vault PDA derivation and targets a different vault.
|
|
305
|
+
* @param options - Slippage protection. By default the SDK quotes the net payout these shares should return
|
|
306
|
+
* from the vault's current state and passes that quote, lowered by 50 bps,
|
|
307
|
+
* as the floor to the program's checked instruction. See {@link ISolanaRedeemOptions}.
|
|
308
|
+
*
|
|
309
|
+
* **On a vault with a withdrawal queue**, holders cannot redeem directly:
|
|
310
|
+
* request with {@link SolanaAdapter.vaultRequestRedeem}, then claim here with
|
|
311
|
+
* `options.request` once the cooldown has run. The claim settles at the share
|
|
312
|
+
* price of that moment, net of the withdrawal fee, held to the floor set at
|
|
313
|
+
* request time, and pays the request's recipient; `redeemShares` and
|
|
314
|
+
* `vaultAddress` are then ignored, and `slippageBps` / `minAssetsOut` must
|
|
315
|
+
* be left unset. Without `request`, a
|
|
316
|
+
* queued vault is refused before signing.
|
|
317
|
+
* @returns The confirmed transaction's signature.
|
|
318
|
+
* @throws {@link UpshiftValidationError} for bad input, for a queued vault
|
|
319
|
+
* without `options.request`, or for a request the wallet cannot claim yet.
|
|
320
|
+
* @example
|
|
321
|
+
* ```ts
|
|
322
|
+
* // A vault with a withdrawal queue: claim a ready request.
|
|
323
|
+
* const { pendingRedemptions } = await sdk.getVaultAvailableRedemptions({ vault, wallet });
|
|
324
|
+
* await sdk.solana.vaultRedeem(programId, vaultIdl, wallet, 0n, undefined, undefined, {
|
|
325
|
+
* request: pendingRedemptions[0].id,
|
|
326
|
+
* });
|
|
327
|
+
* ```
|
|
328
|
+
*/
|
|
329
|
+
async vaultRedeem(vaultProgramId, idl, publicKey, redeemShares, sendTransaction, vaultAddress, options) {
|
|
330
|
+
if (options?.request !== undefined) {
|
|
331
|
+
if (options.slippageBps !== undefined ||
|
|
332
|
+
options.minAssetsOut !== undefined) {
|
|
333
|
+
throw new core_1.UpshiftValidationError('INVALID_INPUT', 'vaultRedeem: a withdrawal-queue claim is held to the floor set when the request was made, not one passed here; leave `slippageBps` and `minAssetsOut` unset when passing `request`.');
|
|
334
|
+
}
|
|
335
|
+
return await (0, queue_actions_1.handleSolanaClaimRedeem)({
|
|
336
|
+
provider: this._provider,
|
|
337
|
+
connection: this._connection,
|
|
338
|
+
vaultProgramId: new web3_js_1.PublicKey(vaultProgramId),
|
|
339
|
+
queueProgramId: new web3_js_1.PublicKey(this.getProgramId('withdrawalQueue')),
|
|
340
|
+
wallet: publicKey,
|
|
341
|
+
request: options.request,
|
|
342
|
+
});
|
|
343
|
+
}
|
|
344
|
+
return await (0, vault_actions_1.handleSolanaRedeem)({
|
|
345
|
+
network: this._network,
|
|
346
|
+
provider: this._provider,
|
|
347
|
+
connection: this._connection,
|
|
348
|
+
vaultProgramId,
|
|
349
|
+
vaultAddress,
|
|
350
|
+
idl,
|
|
351
|
+
publicKey,
|
|
352
|
+
redeemShares,
|
|
353
|
+
sendTransaction,
|
|
354
|
+
options,
|
|
355
|
+
});
|
|
356
|
+
}
|
|
357
|
+
/**
|
|
358
|
+
* Request a withdrawal from a Solana vault that has a withdrawal queue.
|
|
359
|
+
*
|
|
360
|
+
* With a queue attached, a vault's shares cannot be redeemed directly: the
|
|
361
|
+
* holder escrows them in a request, waits out the queue's cooldown, then
|
|
362
|
+
* claims with {@link SolanaAdapter.vaultRedeem} and `options.request`, or
|
|
363
|
+
* anyone the request permits (a keeper, by default) claims for them. The
|
|
364
|
+
* payout is priced when the request is claimed, not now, but never below the
|
|
365
|
+
* floor set here: by default the current net quote lowered by 50 bps, so a
|
|
366
|
+
* fee rise or mark-down in between makes the claim fail rather than pay
|
|
367
|
+
* less. A pending request
|
|
368
|
+
* can be cancelled at any time with
|
|
369
|
+
* {@link SolanaAdapter.vaultCancelRedeemRequest}, which returns the shares.
|
|
370
|
+
*
|
|
371
|
+
* Signs through the provider's wallet and submits one transaction, which
|
|
372
|
+
* also creates the recipient's deposit-token account when it has none. The
|
|
373
|
+
* holder pays the request account's rent, refunded when it is claimed or
|
|
374
|
+
* cancelled, plus rent for any account created. Use
|
|
375
|
+
* `getVaultAvailableRedemptions` to list requests and see when they can be
|
|
376
|
+
* claimed.
|
|
377
|
+
*
|
|
378
|
+
* RPC: three to four reads, then the send.
|
|
379
|
+
*
|
|
380
|
+
* @param params - Vault, wallet, shares, and optional recipient, finalizer,
|
|
381
|
+
* request id and floor. See {@link ISolanaRequestRedeemParams}.
|
|
382
|
+
* @returns The signature, the request's address (pass it as `request` to
|
|
383
|
+
* claim or cancel) and its id.
|
|
384
|
+
* @throws {@link UpshiftValidationError} for bad input, a vault without an
|
|
385
|
+
* attached queue, a frozen account or too few shares, before signing.
|
|
386
|
+
* @throws {@link UpshiftSDKError} when the transaction fails.
|
|
387
|
+
* @example
|
|
388
|
+
* ```ts
|
|
389
|
+
* const { request } = await sdk.solana.vaultRequestRedeem({
|
|
390
|
+
* vault: vaultStateAddress,
|
|
391
|
+
* wallet: wallet.publicKey,
|
|
392
|
+
* amount: 10, // shares, UI units
|
|
393
|
+
* });
|
|
394
|
+
* // ...once the cooldown has run:
|
|
395
|
+
* await sdk.solana.vaultRedeem(programId, vaultIdl, wallet.publicKey, 0n, undefined, undefined, { request });
|
|
396
|
+
* ```
|
|
397
|
+
*/
|
|
398
|
+
async vaultRequestRedeem(params) {
|
|
399
|
+
return await (0, queue_actions_1.handleSolanaRequestRedeem)({
|
|
400
|
+
provider: this._provider,
|
|
401
|
+
connection: this._connection,
|
|
402
|
+
queueProgramId: new web3_js_1.PublicKey(this.getProgramId('withdrawalQueue')),
|
|
403
|
+
params,
|
|
404
|
+
});
|
|
405
|
+
}
|
|
406
|
+
/**
|
|
407
|
+
* Cancel a pending withdrawal request, returning its shares to the holder.
|
|
408
|
+
*
|
|
409
|
+
* Allowed at any time while the request exists: during the cooldown, after
|
|
410
|
+
* it, past the fulfillment window, and while the vault is paused. Only the
|
|
411
|
+
* holder who made the request may cancel it. Signs through the provider's
|
|
412
|
+
* wallet; the request's rent is refunded to the holder.
|
|
413
|
+
*
|
|
414
|
+
* RPC: three reads, then the send.
|
|
415
|
+
*
|
|
416
|
+
* @param params - The holder and the request address. See
|
|
417
|
+
* {@link ISolanaCancelRedeemRequestParams}.
|
|
418
|
+
* @returns The confirmed transaction's signature.
|
|
419
|
+
* @throws {@link UpshiftValidationError} for a missing request, or one this
|
|
420
|
+
* wallet did not make, before signing.
|
|
421
|
+
* @throws {@link UpshiftSDKError} when the transaction fails.
|
|
422
|
+
* @example
|
|
423
|
+
* ```ts
|
|
424
|
+
* await sdk.solana.vaultCancelRedeemRequest({ wallet: wallet.publicKey, request });
|
|
425
|
+
* ```
|
|
426
|
+
*/
|
|
427
|
+
async vaultCancelRedeemRequest(params) {
|
|
428
|
+
return await (0, queue_actions_1.handleSolanaCancelRedeemRequest)({
|
|
429
|
+
provider: this._provider,
|
|
430
|
+
connection: this._connection,
|
|
431
|
+
queueProgramId: new web3_js_1.PublicKey(this.getProgramId('withdrawalQueue')),
|
|
432
|
+
params,
|
|
433
|
+
});
|
|
434
|
+
}
|
|
435
|
+
/**
|
|
436
|
+
* Canonical program id for a program type on this adapter's network.
|
|
437
|
+
*
|
|
438
|
+
* @param type - Program to look up: `'vault'` (august_vault) or
|
|
439
|
+
* `'withdrawalQueue'` (august_withdrawal_queue).
|
|
440
|
+
* @returns The base58 program id.
|
|
441
|
+
* @throws {@link UpshiftValidationError} if `type` is not one of the two
|
|
442
|
+
* program types, or the program is not deployed on this adapter's network
|
|
443
|
+
* (neither program on `testnet`).
|
|
444
|
+
* @example
|
|
445
|
+
* ```ts
|
|
446
|
+
* const queueProgram = adapter.getProgramId('withdrawalQueue');
|
|
447
|
+
* ```
|
|
448
|
+
*/
|
|
449
|
+
getProgramId(type) {
|
|
450
|
+
(0, utils_1.assertSolanaProgramType)(type);
|
|
451
|
+
const programId = (0, constants_1.getDeployedProgramIds)(this._network)?.[type];
|
|
452
|
+
if (!programId) {
|
|
453
|
+
throw new core_1.UpshiftValidationError('INVALID_INPUT', (0, utils_1.undeployedProgramMessage)(type, this._network));
|
|
454
|
+
}
|
|
455
|
+
return programId;
|
|
456
|
+
}
|
|
457
|
+
}
|
|
458
|
+
exports.default = SolanaAdapter;
|
|
459
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1,184 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Off-chain mirror of the `august_vault` pricing math.
|
|
3
|
+
*
|
|
4
|
+
* Used to quote what a deposit or redeem is expected to return so a slippage
|
|
5
|
+
* floor can be handed to `deposit_checked` / `redeem_checked`. Mirrors
|
|
6
|
+
* `VaultState::shares_for_deposit_with_offset` and
|
|
7
|
+
* `assets_for_redeem_with_offset` (`programs/august-vault/src/state/vault.rs`):
|
|
8
|
+
* `u128` intermediates, a per-vault virtual-share offset defaulting to
|
|
9
|
+
* `EXTRA_SHARES = 1_000_000`, a pro-rata floor (deposit) or cap (redeem),
|
|
10
|
+
* every division rounded down; plus the withdrawal fee `redeem_checked` takes,
|
|
11
|
+
* `ceil(assets * fee / 1e6)` at `FEE_RATE_DENOMINATOR_VALUE = 1_000_000`.
|
|
12
|
+
*
|
|
13
|
+
* A quote is only a quote. The program prices at execution, against state
|
|
14
|
+
* that may have moved since the read; the floor derived here is what protects
|
|
15
|
+
* the caller when the two differ.
|
|
16
|
+
*
|
|
17
|
+
* This mirror cannot validate itself — agreeing with its own tests proves
|
|
18
|
+
* nothing about the program — so every claim below about program behaviour is
|
|
19
|
+
* cited to its handler in `fractal-protocol/solana-upshift-vault-programs`, by
|
|
20
|
+
* file and function rather than line. Verified against that repo at 3b91c86.
|
|
21
|
+
* Do not "fix" the math here against intuition; re-read the handler.
|
|
22
|
+
*
|
|
23
|
+
* Adapter-internal. These functions are exported for `vault.actions.ts` and
|
|
24
|
+
* the unit tests only — deliberately absent from the `adapters/solana` barrel,
|
|
25
|
+
* so they are not public SDK surface and carry no benchmark or telemetry
|
|
26
|
+
* taxonomy obligation. Promoting one to the barrel means taking both on.
|
|
27
|
+
*
|
|
28
|
+
* @packageDocumentation
|
|
29
|
+
*/
|
|
30
|
+
/** What the program uses when a vault stores `share_offset == 0` (vaults created before the field existed). */
|
|
31
|
+
export declare const DEFAULT_SHARE_OFFSET = 1000000n;
|
|
32
|
+
/** Slippage tolerance applied when a caller gives neither `slippageBps` nor an explicit floor. */
|
|
33
|
+
export declare const DEFAULT_SLIPPAGE_BPS = 50;
|
|
34
|
+
/**
|
|
35
|
+
* Coerce an on-chain integer as Anchor decodes it (`BN`, `number`, decimal
|
|
36
|
+
* string, or `bigint`) to `bigint`.
|
|
37
|
+
*
|
|
38
|
+
* @param value - The decoded field.
|
|
39
|
+
* @param label - Named in the error when the value is not a non-negative integer.
|
|
40
|
+
* @throws UpshiftSDKError when the value cannot be read as a non-negative integer.
|
|
41
|
+
*/
|
|
42
|
+
export declare function toBigInt(value: unknown, label: string): bigint;
|
|
43
|
+
/**
|
|
44
|
+
* The vault's effective share offset. A stored zero (or a state decoded from
|
|
45
|
+
* an IDL that predates the field) resolves to the program default, exactly as
|
|
46
|
+
* `VaultState::share_offset()` does on-chain.
|
|
47
|
+
*
|
|
48
|
+
* @param raw - `VaultState.shareOffset` as decoded, or `undefined`.
|
|
49
|
+
*/
|
|
50
|
+
export declare function resolveShareOffset(raw: unknown): bigint;
|
|
51
|
+
/**
|
|
52
|
+
* `localAum + deployedAum`, the `total_assets()` the program prices against.
|
|
53
|
+
*
|
|
54
|
+
* @param state - Decoded `VaultState`.
|
|
55
|
+
* @throws UpshiftSDKError when either field is missing, which means the state
|
|
56
|
+
* was decoded with an IDL this SDK cannot price against.
|
|
57
|
+
*/
|
|
58
|
+
export declare function totalAssetsOf(state: {
|
|
59
|
+
localAum?: unknown;
|
|
60
|
+
deployedAum?: unknown;
|
|
61
|
+
}): bigint;
|
|
62
|
+
/**
|
|
63
|
+
* Whether the vault has a share price. Mirrors `SharePriceUndefined`:
|
|
64
|
+
* outstanding shares against no assets has no price in either direction.
|
|
65
|
+
*/
|
|
66
|
+
export declare function hasSharePrice(supply: bigint, totalAssets: bigint): boolean;
|
|
67
|
+
/**
|
|
68
|
+
* Shares minted for depositing `amount` base units.
|
|
69
|
+
*
|
|
70
|
+
* `floor(max(amount * (supply + offset) / (totalAssets + offset), amount * supply / totalAssets))`.
|
|
71
|
+
* Above par the offset term is the larger and binds; below par the pro-rata
|
|
72
|
+
* floor binds so a depositor never hands value to incumbents on arrival.
|
|
73
|
+
*
|
|
74
|
+
* @param input - Share supply, total assets and the vault's resolved offset,
|
|
75
|
+
* all in raw base units.
|
|
76
|
+
* @throws UpshiftValidationError when the vault has no share price.
|
|
77
|
+
*/
|
|
78
|
+
export declare function sharesForDeposit(input: {
|
|
79
|
+
supply: bigint;
|
|
80
|
+
totalAssets: bigint;
|
|
81
|
+
amount: bigint;
|
|
82
|
+
offset: bigint;
|
|
83
|
+
}): bigint;
|
|
84
|
+
/**
|
|
85
|
+
* Assets paid, before the withdrawal fee, for burning `shares`.
|
|
86
|
+
*
|
|
87
|
+
* `floor(min(shares * (totalAssets + offset) / (supply + offset), shares * totalAssets / supply))`.
|
|
88
|
+
* The mirror of {@link sharesForDeposit}: above par the offset term binds,
|
|
89
|
+
* below par the pro-rata cap does, so no redeemer takes more than its share.
|
|
90
|
+
*
|
|
91
|
+
* @param input - Share supply, total assets and the vault's resolved offset,
|
|
92
|
+
* all in raw base units.
|
|
93
|
+
* @throws UpshiftValidationError when the vault has no share price.
|
|
94
|
+
*/
|
|
95
|
+
export declare function assetsForRedeem(input: {
|
|
96
|
+
supply: bigint;
|
|
97
|
+
totalAssets: bigint;
|
|
98
|
+
shares: bigint;
|
|
99
|
+
offset: bigint;
|
|
100
|
+
}): bigint;
|
|
101
|
+
/**
|
|
102
|
+
* The withdrawal fee the program takes from a gross redemption:
|
|
103
|
+
* `ceil(assets * feePpm / 1e6)`, rounded **up** as on-chain.
|
|
104
|
+
*
|
|
105
|
+
* @param assets - Gross assets from {@link assetsForRedeem}.
|
|
106
|
+
* @param feePpm - `VaultState.withdrawalFee`, parts per million.
|
|
107
|
+
*/
|
|
108
|
+
export declare function withdrawalFee(assets: bigint, feePpm: bigint): bigint;
|
|
109
|
+
/**
|
|
110
|
+
* Refuse a `slippageBps` that is not an integer in `0 .. 10_000`.
|
|
111
|
+
*
|
|
112
|
+
* @throws UpshiftValidationError when it is out of range or not an integer.
|
|
113
|
+
*/
|
|
114
|
+
export declare function validateSlippageBps(slippageBps: number): void;
|
|
115
|
+
/**
|
|
116
|
+
* Lower `expected` by `slippageBps` basis points, rounding down.
|
|
117
|
+
*
|
|
118
|
+
* @param expected - The quoted output in raw base units.
|
|
119
|
+
* @param slippageBps - Integer basis points, `0` to `10_000`.
|
|
120
|
+
* @throws UpshiftValidationError when `slippageBps` is out of range or not an integer.
|
|
121
|
+
*/
|
|
122
|
+
export declare function applySlippage(expected: bigint, slippageBps: number): bigint;
|
|
123
|
+
/**
|
|
124
|
+
* The `min_shares_out` to pass to `deposit_checked`: the quoted shares for
|
|
125
|
+
* `amount`, lowered by `slippageBps`.
|
|
126
|
+
*
|
|
127
|
+
* Nothing is netted out, because there is no deposit-side fee. In
|
|
128
|
+
* `instructions/deposit.rs::handler_checked` the comparison is
|
|
129
|
+
* `require!(shares >= min_shares_out, SlippageExceeded)` directly on the
|
|
130
|
+
* `shares_for_deposit` result, with no fee term anywhere in the handler.
|
|
131
|
+
* Structurally too: `VaultState` carries exactly one fee field,
|
|
132
|
+
* `withdrawal_fee`, and `deposit_checked` takes no `fee_recipient_account`
|
|
133
|
+
* among its accounts (`redeem_checked` does), so it has no account to pay one
|
|
134
|
+
* to. Gross and net are the same quantity here.
|
|
135
|
+
*
|
|
136
|
+
* Quoting from state read *before* the transaction is correct despite the
|
|
137
|
+
* handler transferring the deposit in first: `transfer_in_ctx` moves SPL
|
|
138
|
+
* tokens into the vault ATA, but `total_assets()` sums the stored `local_aum`
|
|
139
|
+
* and `deployed_aum` fields, and `local_aum` is incremented only *after*
|
|
140
|
+
* `shares_for_deposit` has been computed. Supply is likewise read before the
|
|
141
|
+
* mint. The handler prices against the same pre-deposit figures this quote
|
|
142
|
+
* does.
|
|
143
|
+
*
|
|
144
|
+
* @param input - Vault state, deposit amount and tolerance.
|
|
145
|
+
*/
|
|
146
|
+
export declare function quoteDepositFloor(input: {
|
|
147
|
+
supply: bigint;
|
|
148
|
+
totalAssets: bigint;
|
|
149
|
+
amount: bigint;
|
|
150
|
+
offset: bigint;
|
|
151
|
+
slippageBps: number;
|
|
152
|
+
}): bigint;
|
|
153
|
+
/**
|
|
154
|
+
* The `min_assets_out` to pass to `redeem_checked`: the quoted payout for
|
|
155
|
+
* `shares` **net of the withdrawal fee** — which is what `redeem_checked`
|
|
156
|
+
* compares against — lowered by `slippageBps`.
|
|
157
|
+
*
|
|
158
|
+
* Net rather than gross is the hinge of the whole guarantee, so it is pinned
|
|
159
|
+
* here rather than left to be re-derived. In
|
|
160
|
+
* `instructions/redeem.rs::handler_checked` the program computes the gross
|
|
161
|
+
* `assets`, subtracts `fees` — the `ceil_div` of `assets * withdrawal_fee`
|
|
162
|
+
* over `FEE_RATE_DENOMINATOR_VALUE` — and compares `min_assets_out` against
|
|
163
|
+
* that difference, which is the figure the caller actually receives.
|
|
164
|
+
* `Redeem::ceil_div` is `(n + d - 1) / d`, which is what
|
|
165
|
+
* {@link withdrawalFee} reproduces.
|
|
166
|
+
*
|
|
167
|
+
* Getting this wrong fails quietly in the dangerous direction. Quote against
|
|
168
|
+
* the gross payout and the floor sits a whole fee above what the program
|
|
169
|
+
* measures, so it binds early and reverts healthy redemptions. Net it twice —
|
|
170
|
+
* or drop the fee from a vault that charges one — and the floor sits below the
|
|
171
|
+
* real payout by the fee, leaving protection weaker than the advertised
|
|
172
|
+
* `slippageBps` instead of visibly broken. `withdrawal_fee` is capped just
|
|
173
|
+
* under 10% (`set_withdrawal_fee`), which bounds that silent gap.
|
|
174
|
+
*
|
|
175
|
+
* @param input - Vault state, shares to burn, fee and tolerance.
|
|
176
|
+
*/
|
|
177
|
+
export declare function quoteRedeemFloor(input: {
|
|
178
|
+
supply: bigint;
|
|
179
|
+
totalAssets: bigint;
|
|
180
|
+
shares: bigint;
|
|
181
|
+
offset: bigint;
|
|
182
|
+
feePpm: bigint;
|
|
183
|
+
slippageBps: number;
|
|
184
|
+
}): bigint;
|