@voltr/vault-sdk 1.0.21 → 2.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/dist/extensions/batchFetchers.d.ts +7 -0
- package/dist/extensions/batchFetchers.d.ts.map +1 -0
- package/dist/extensions/batchFetchers.js +63 -0
- package/dist/extensions/batchFetchers.js.map +1 -0
- package/dist/extensions/decimal.d.ts +11 -0
- package/dist/extensions/decimal.d.ts.map +1 -0
- package/dist/extensions/decimal.js +19 -0
- package/dist/extensions/decimal.js.map +1 -0
- package/dist/extensions/fees.d.ts +6 -0
- package/dist/extensions/fees.d.ts.map +1 -0
- package/dist/extensions/fees.js +23 -0
- package/dist/extensions/fees.js.map +1 -0
- package/dist/extensions/index.d.ts +10 -0
- package/dist/extensions/index.d.ts.map +1 -0
- package/dist/extensions/index.js +26 -0
- package/dist/extensions/index.js.map +1 -0
- package/dist/extensions/lpEconomics.d.ts +27 -0
- package/dist/extensions/lpEconomics.d.ts.map +1 -0
- package/dist/extensions/lpEconomics.js +140 -0
- package/dist/extensions/lpEconomics.js.map +1 -0
- package/dist/extensions/math.d.ts +90 -0
- package/dist/extensions/math.d.ts.map +1 -0
- package/dist/extensions/math.js +182 -0
- package/dist/extensions/math.js.map +1 -0
- package/dist/extensions/metadataPda.d.ts +18 -0
- package/dist/extensions/metadataPda.d.ts.map +1 -0
- package/dist/extensions/metadataPda.js +34 -0
- package/dist/extensions/metadataPda.js.map +1 -0
- package/dist/extensions/position.d.ts +19 -0
- package/dist/extensions/position.d.ts.map +1 -0
- package/dist/extensions/position.js +28 -0
- package/dist/extensions/position.js.map +1 -0
- package/dist/extensions/rpc.d.ts +8 -0
- package/dist/extensions/rpc.d.ts.map +1 -0
- package/dist/{types/voltr_vault.js → extensions/rpc.js} +1 -0
- package/dist/extensions/rpc.js.map +1 -0
- package/dist/extensions/withdrawals.d.ts +16 -0
- package/dist/extensions/withdrawals.d.ts.map +1 -0
- package/dist/extensions/withdrawals.js +59 -0
- package/dist/extensions/withdrawals.js.map +1 -0
- package/dist/generated/accounts/adaptorAddReceipt.d.ts +57 -0
- package/dist/generated/accounts/adaptorAddReceipt.d.ts.map +1 -0
- package/dist/generated/accounts/adaptorAddReceipt.js +82 -0
- package/dist/generated/accounts/adaptorAddReceipt.js.map +1 -0
- package/dist/generated/accounts/directWithdrawInitReceipt.d.ts +60 -0
- package/dist/generated/accounts/directWithdrawInitReceipt.d.ts.map +1 -0
- package/dist/generated/accounts/directWithdrawInitReceipt.js +95 -0
- package/dist/generated/accounts/directWithdrawInitReceipt.js.map +1 -0
- package/dist/generated/accounts/index.d.ts +14 -0
- package/dist/generated/accounts/index.d.ts.map +1 -0
- package/dist/generated/accounts/index.js +30 -0
- package/dist/generated/accounts/index.js.map +1 -0
- package/dist/generated/accounts/protocol.d.ts +57 -0
- package/dist/generated/accounts/protocol.d.ts.map +1 -0
- package/dist/generated/accounts/protocol.js +82 -0
- package/dist/generated/accounts/protocol.js.map +1 -0
- package/dist/generated/accounts/requestWithdrawVaultReceipt.d.ts +43 -0
- package/dist/generated/accounts/requestWithdrawVaultReceipt.d.ts.map +1 -0
- package/dist/generated/accounts/requestWithdrawVaultReceipt.js +85 -0
- package/dist/generated/accounts/requestWithdrawVaultReceipt.js.map +1 -0
- package/dist/generated/accounts/strategyInitReceipt.d.ts +69 -0
- package/dist/generated/accounts/strategyInitReceipt.d.ts.map +1 -0
- package/dist/generated/accounts/strategyInitReceipt.js +91 -0
- package/dist/generated/accounts/strategyInitReceipt.js.map +1 -0
- package/dist/generated/accounts/vault.d.ts +100 -0
- package/dist/generated/accounts/vault.d.ts.map +1 -0
- package/dist/generated/accounts/vault.js +105 -0
- package/dist/generated/accounts/vault.js.map +1 -0
- package/dist/generated/errors/index.d.ts +9 -0
- package/dist/generated/errors/index.d.ts.map +1 -0
- package/dist/{types → generated/errors}/index.js +9 -2
- package/dist/generated/errors/index.js.map +1 -0
- package/dist/generated/errors/voltrVault.d.ts +52 -0
- package/dist/generated/errors/voltrVault.d.ts.map +1 -0
- package/dist/generated/errors/voltrVault.js +77 -0
- package/dist/generated/errors/voltrVault.js.map +1 -0
- package/dist/generated/index.d.ts +14 -0
- package/dist/generated/index.d.ts.map +1 -0
- package/dist/generated/index.js +30 -0
- package/dist/generated/index.js.map +1 -0
- package/dist/generated/instructions/acceptProtocolAdmin.d.ts +47 -0
- package/dist/generated/instructions/acceptProtocolAdmin.d.ts.map +1 -0
- package/dist/generated/instructions/acceptProtocolAdmin.js +103 -0
- package/dist/generated/instructions/acceptProtocolAdmin.js.map +1 -0
- package/dist/generated/instructions/acceptVaultAdmin.d.ts +40 -0
- package/dist/generated/instructions/acceptVaultAdmin.d.ts.map +1 -0
- package/dist/generated/instructions/acceptVaultAdmin.js +75 -0
- package/dist/generated/instructions/acceptVaultAdmin.js.map +1 -0
- package/dist/generated/instructions/addAdaptor.d.ts +67 -0
- package/dist/generated/instructions/addAdaptor.d.ts.map +1 -0
- package/dist/generated/instructions/addAdaptor.js +149 -0
- package/dist/generated/instructions/addAdaptor.js.map +1 -0
- package/dist/generated/instructions/calibrateHighWaterMark.d.ts +63 -0
- package/dist/generated/instructions/calibrateHighWaterMark.d.ts.map +1 -0
- package/dist/generated/instructions/calibrateHighWaterMark.js +150 -0
- package/dist/generated/instructions/calibrateHighWaterMark.js.map +1 -0
- package/dist/generated/instructions/calibrateHighWaterMarkUnsafe.d.ts +55 -0
- package/dist/generated/instructions/calibrateHighWaterMarkUnsafe.d.ts.map +1 -0
- package/dist/generated/instructions/calibrateHighWaterMarkUnsafe.js +121 -0
- package/dist/generated/instructions/calibrateHighWaterMarkUnsafe.js.map +1 -0
- package/dist/generated/instructions/cancelRequestWithdrawVault.d.ts +84 -0
- package/dist/generated/instructions/cancelRequestWithdrawVault.d.ts.map +1 -0
- package/dist/generated/instructions/cancelRequestWithdrawVault.js +208 -0
- package/dist/generated/instructions/cancelRequestWithdrawVault.js.map +1 -0
- package/dist/generated/instructions/closeStrategy.d.ts +67 -0
- package/dist/generated/instructions/closeStrategy.d.ts.map +1 -0
- package/dist/generated/instructions/closeStrategy.js +149 -0
- package/dist/generated/instructions/closeStrategy.js.map +1 -0
- package/dist/generated/instructions/createLpMetadata.d.ts +88 -0
- package/dist/generated/instructions/createLpMetadata.d.ts.map +1 -0
- package/dist/generated/instructions/createLpMetadata.js +194 -0
- package/dist/generated/instructions/createLpMetadata.js.map +1 -0
- package/dist/generated/instructions/depositStrategy.d.ts +111 -0
- package/dist/generated/instructions/depositStrategy.d.ts.map +1 -0
- package/dist/generated/instructions/depositStrategy.js +277 -0
- package/dist/generated/instructions/depositStrategy.js.map +1 -0
- package/dist/generated/instructions/depositVault.d.ts +108 -0
- package/dist/generated/instructions/depositVault.d.ts.map +1 -0
- package/dist/generated/instructions/depositVault.js +258 -0
- package/dist/generated/instructions/depositVault.js.map +1 -0
- package/dist/generated/instructions/directWithdrawStrategy.d.ts +125 -0
- package/dist/generated/instructions/directWithdrawStrategy.d.ts.map +1 -0
- package/dist/generated/instructions/directWithdrawStrategy.js +338 -0
- package/dist/generated/instructions/directWithdrawStrategy.js.map +1 -0
- package/dist/generated/instructions/directWithdrawStrategyWithTolerance.d.ts +129 -0
- package/dist/generated/instructions/directWithdrawStrategyWithTolerance.d.ts.map +1 -0
- package/dist/generated/instructions/directWithdrawStrategyWithTolerance.js +338 -0
- package/dist/generated/instructions/directWithdrawStrategyWithTolerance.js.map +1 -0
- package/dist/generated/instructions/harvestFee.d.ts +87 -0
- package/dist/generated/instructions/harvestFee.d.ts.map +1 -0
- package/dist/generated/instructions/harvestFee.js +220 -0
- package/dist/generated/instructions/harvestFee.js.map +1 -0
- package/dist/generated/instructions/index.d.ts +35 -0
- package/dist/generated/instructions/index.d.ts.map +1 -0
- package/dist/generated/instructions/index.js +51 -0
- package/dist/generated/instructions/index.js.map +1 -0
- package/dist/generated/instructions/initProtocol.d.ts +60 -0
- package/dist/generated/instructions/initProtocol.d.ts.map +1 -0
- package/dist/generated/instructions/initProtocol.js +130 -0
- package/dist/generated/instructions/initProtocol.js.map +1 -0
- package/dist/generated/instructions/initializeDirectWithdrawStrategy.d.ts +92 -0
- package/dist/generated/instructions/initializeDirectWithdrawStrategy.d.ts.map +1 -0
- package/dist/generated/instructions/initializeDirectWithdrawStrategy.js +214 -0
- package/dist/generated/instructions/initializeDirectWithdrawStrategy.js.map +1 -0
- package/dist/generated/instructions/initializeStrategy.d.ts +88 -0
- package/dist/generated/instructions/initializeStrategy.d.ts.map +1 -0
- package/dist/generated/instructions/initializeStrategy.js +210 -0
- package/dist/generated/instructions/initializeStrategy.js.map +1 -0
- package/dist/generated/instructions/initializeVault.d.ts +172 -0
- package/dist/generated/instructions/initializeVault.d.ts.map +1 -0
- package/dist/generated/instructions/initializeVault.js +289 -0
- package/dist/generated/instructions/initializeVault.js.map +1 -0
- package/dist/generated/instructions/instantWithdrawStrategy.d.ts +133 -0
- package/dist/generated/instructions/instantWithdrawStrategy.d.ts.map +1 -0
- package/dist/generated/instructions/instantWithdrawStrategy.js +320 -0
- package/dist/generated/instructions/instantWithdrawStrategy.js.map +1 -0
- package/dist/generated/instructions/instantWithdrawStrategyWithTolerance.d.ts +137 -0
- package/dist/generated/instructions/instantWithdrawStrategyWithTolerance.d.ts.map +1 -0
- package/dist/generated/instructions/instantWithdrawStrategyWithTolerance.js +320 -0
- package/dist/generated/instructions/instantWithdrawStrategyWithTolerance.js.map +1 -0
- package/dist/generated/instructions/instantWithdrawVault.d.ts +112 -0
- package/dist/generated/instructions/instantWithdrawVault.d.ts.map +1 -0
- package/dist/generated/instructions/instantWithdrawVault.js +249 -0
- package/dist/generated/instructions/instantWithdrawVault.js.map +1 -0
- package/dist/generated/instructions/removeAdaptor.d.ts +63 -0
- package/dist/generated/instructions/removeAdaptor.d.ts.map +1 -0
- package/dist/generated/instructions/removeAdaptor.js +144 -0
- package/dist/generated/instructions/removeAdaptor.js.map +1 -0
- package/dist/generated/instructions/requestWithdrawVault.d.ts +104 -0
- package/dist/generated/instructions/requestWithdrawVault.d.ts.map +1 -0
- package/dist/generated/instructions/requestWithdrawVault.js +225 -0
- package/dist/generated/instructions/requestWithdrawVault.js.map +1 -0
- package/dist/generated/instructions/updateProtocol.d.ts +57 -0
- package/dist/generated/instructions/updateProtocol.d.ts.map +1 -0
- package/dist/generated/instructions/updateProtocol.js +111 -0
- package/dist/generated/instructions/updateProtocol.js.map +1 -0
- package/dist/generated/instructions/updateVaultConfig.d.ts +65 -0
- package/dist/generated/instructions/updateVaultConfig.d.ts.map +1 -0
- package/dist/generated/instructions/updateVaultConfig.js +133 -0
- package/dist/generated/instructions/updateVaultConfig.js.map +1 -0
- package/dist/generated/instructions/updateVaultProtocolFee.d.ts +65 -0
- package/dist/generated/instructions/updateVaultProtocolFee.d.ts.map +1 -0
- package/dist/generated/instructions/updateVaultProtocolFee.js +132 -0
- package/dist/generated/instructions/updateVaultProtocolFee.js.map +1 -0
- package/dist/generated/instructions/withdrawStrategy.d.ts +111 -0
- package/dist/generated/instructions/withdrawStrategy.d.ts.map +1 -0
- package/dist/generated/instructions/withdrawStrategy.js +277 -0
- package/dist/generated/instructions/withdrawStrategy.js.map +1 -0
- package/dist/generated/instructions/withdrawVault.d.ts +103 -0
- package/dist/generated/instructions/withdrawVault.d.ts.map +1 -0
- package/dist/generated/instructions/withdrawVault.js +258 -0
- package/dist/generated/instructions/withdrawVault.js.map +1 -0
- package/dist/generated/pdas/adaptorAddReceipt.d.ts +16 -0
- package/dist/generated/pdas/adaptorAddReceipt.d.ts.map +1 -0
- package/dist/generated/pdas/adaptorAddReceipt.js +26 -0
- package/dist/generated/pdas/adaptorAddReceipt.js.map +1 -0
- package/dist/generated/pdas/directWithdrawInitReceipt.d.ts +16 -0
- package/dist/generated/pdas/directWithdrawInitReceipt.d.ts.map +1 -0
- package/dist/generated/pdas/directWithdrawInitReceipt.js +26 -0
- package/dist/generated/pdas/directWithdrawInitReceipt.js.map +1 -0
- package/dist/generated/pdas/index.d.ts +17 -0
- package/dist/generated/pdas/index.d.ts.map +1 -0
- package/dist/generated/pdas/index.js +33 -0
- package/dist/generated/pdas/index.js.map +1 -0
- package/dist/generated/pdas/protocol.d.ts +12 -0
- package/dist/generated/pdas/protocol.d.ts.map +1 -0
- package/dist/generated/pdas/protocol.js +21 -0
- package/dist/generated/pdas/protocol.js.map +1 -0
- package/dist/generated/pdas/requestWithdrawVaultReceipt.d.ts +16 -0
- package/dist/generated/pdas/requestWithdrawVaultReceipt.d.ts.map +1 -0
- package/dist/generated/pdas/requestWithdrawVaultReceipt.js +27 -0
- package/dist/generated/pdas/requestWithdrawVaultReceipt.js.map +1 -0
- package/dist/generated/pdas/strategyInitReceipt.d.ts +16 -0
- package/dist/generated/pdas/strategyInitReceipt.d.ts.map +1 -0
- package/dist/generated/pdas/strategyInitReceipt.js +26 -0
- package/dist/generated/pdas/strategyInitReceipt.js.map +1 -0
- package/dist/generated/pdas/vaultAssetIdleAuth.d.ts +15 -0
- package/dist/generated/pdas/vaultAssetIdleAuth.d.ts.map +1 -0
- package/dist/generated/pdas/vaultAssetIdleAuth.js +25 -0
- package/dist/generated/pdas/vaultAssetIdleAuth.js.map +1 -0
- package/dist/generated/pdas/vaultLpMint.d.ts +15 -0
- package/dist/generated/pdas/vaultLpMint.d.ts.map +1 -0
- package/dist/generated/pdas/vaultLpMint.js +24 -0
- package/dist/generated/pdas/vaultLpMint.js.map +1 -0
- package/dist/generated/pdas/vaultLpMintAuth.d.ts +15 -0
- package/dist/generated/pdas/vaultLpMintAuth.d.ts.map +1 -0
- package/dist/generated/pdas/vaultLpMintAuth.js +25 -0
- package/dist/generated/pdas/vaultLpMintAuth.js.map +1 -0
- package/dist/generated/pdas/vaultStrategyAuth.d.ts +16 -0
- package/dist/generated/pdas/vaultStrategyAuth.d.ts.map +1 -0
- package/dist/generated/pdas/vaultStrategyAuth.js +26 -0
- package/dist/generated/pdas/vaultStrategyAuth.js.map +1 -0
- package/dist/generated/programs/index.d.ts +9 -0
- package/dist/generated/programs/index.d.ts.map +1 -0
- package/dist/generated/programs/index.js +25 -0
- package/dist/generated/programs/index.js.map +1 -0
- package/dist/generated/programs/voltrVault.d.ts +172 -0
- package/dist/generated/programs/voltrVault.d.ts.map +1 -0
- package/dist/generated/programs/voltrVault.js +447 -0
- package/dist/generated/programs/voltrVault.js.map +1 -0
- package/dist/generated/types/acceptProtocolAdminEvent.d.ts +24 -0
- package/dist/generated/types/acceptProtocolAdminEvent.d.ts.map +1 -0
- package/dist/generated/types/acceptProtocolAdminEvent.js +33 -0
- package/dist/generated/types/acceptProtocolAdminEvent.js.map +1 -0
- package/dist/generated/types/acceptVaultAdminEvent.d.ts +24 -0
- package/dist/generated/types/acceptVaultAdminEvent.d.ts.map +1 -0
- package/dist/generated/types/acceptVaultAdminEvent.js +33 -0
- package/dist/generated/types/acceptVaultAdminEvent.js.map +1 -0
- package/dist/generated/types/addAdaptorEvent.d.ts +28 -0
- package/dist/generated/types/addAdaptorEvent.d.ts.map +1 -0
- package/dist/generated/types/addAdaptorEvent.js +37 -0
- package/dist/generated/types/addAdaptorEvent.js.map +1 -0
- package/dist/generated/types/calibrateHighWaterMarkEvent.d.ts +34 -0
- package/dist/generated/types/calibrateHighWaterMarkEvent.d.ts.map +1 -0
- package/dist/generated/types/calibrateHighWaterMarkEvent.js +43 -0
- package/dist/generated/types/calibrateHighWaterMarkEvent.js.map +1 -0
- package/dist/generated/types/calibrateHighWaterMarkUnsafeEvent.d.ts +30 -0
- package/dist/generated/types/calibrateHighWaterMarkUnsafeEvent.d.ts.map +1 -0
- package/dist/generated/types/calibrateHighWaterMarkUnsafeEvent.js +39 -0
- package/dist/generated/types/calibrateHighWaterMarkUnsafeEvent.js.map +1 -0
- package/dist/generated/types/cancelRequestWithdrawVaultEvent.d.ts +32 -0
- package/dist/generated/types/cancelRequestWithdrawVaultEvent.d.ts.map +1 -0
- package/dist/generated/types/cancelRequestWithdrawVaultEvent.js +41 -0
- package/dist/generated/types/cancelRequestWithdrawVaultEvent.js.map +1 -0
- package/dist/generated/types/closeStrategyEvent.d.ts +26 -0
- package/dist/generated/types/closeStrategyEvent.d.ts.map +1 -0
- package/dist/generated/types/closeStrategyEvent.js +35 -0
- package/dist/generated/types/closeStrategyEvent.js.map +1 -0
- package/dist/generated/types/depositStrategyEvent.d.ts +52 -0
- package/dist/generated/types/depositStrategyEvent.d.ts.map +1 -0
- package/dist/generated/types/depositStrategyEvent.js +61 -0
- package/dist/generated/types/depositStrategyEvent.js.map +1 -0
- package/dist/generated/types/depositVaultEvent.d.ts +48 -0
- package/dist/generated/types/depositVaultEvent.d.ts.map +1 -0
- package/dist/generated/types/depositVaultEvent.js +57 -0
- package/dist/generated/types/depositVaultEvent.js.map +1 -0
- package/dist/generated/types/directWithdrawStrategyEvent.d.ts +62 -0
- package/dist/generated/types/directWithdrawStrategyEvent.d.ts.map +1 -0
- package/dist/generated/types/directWithdrawStrategyEvent.js +71 -0
- package/dist/generated/types/directWithdrawStrategyEvent.js.map +1 -0
- package/dist/generated/types/feeConfiguration.d.ts +33 -0
- package/dist/generated/types/feeConfiguration.d.ts.map +1 -0
- package/dist/generated/types/feeConfiguration.js +43 -0
- package/dist/generated/types/feeConfiguration.js.map +1 -0
- package/dist/generated/types/feeState.d.ts +32 -0
- package/dist/generated/types/feeState.d.ts.map +1 -0
- package/dist/generated/types/feeState.js +33 -0
- package/dist/generated/types/feeState.js.map +1 -0
- package/dist/generated/types/feeUpdate.d.ts +24 -0
- package/dist/generated/types/feeUpdate.d.ts.map +1 -0
- package/dist/generated/types/feeUpdate.js +29 -0
- package/dist/generated/types/feeUpdate.js.map +1 -0
- package/dist/generated/types/harvestFeeEvent.d.ts +32 -0
- package/dist/generated/types/harvestFeeEvent.d.ts.map +1 -0
- package/dist/generated/types/harvestFeeEvent.js +41 -0
- package/dist/generated/types/harvestFeeEvent.js.map +1 -0
- package/dist/generated/types/highWaterMark.d.ts +28 -0
- package/dist/generated/types/highWaterMark.d.ts.map +1 -0
- package/dist/generated/types/highWaterMark.js +31 -0
- package/dist/generated/types/highWaterMark.js.map +1 -0
- package/dist/generated/types/index.d.ts +44 -0
- package/dist/generated/types/index.d.ts.map +1 -0
- package/dist/generated/types/index.js +60 -0
- package/dist/generated/types/index.js.map +1 -0
- package/dist/generated/types/initProtocolEvent.d.ts +22 -0
- package/dist/generated/types/initProtocolEvent.d.ts.map +1 -0
- package/dist/generated/types/initProtocolEvent.js +31 -0
- package/dist/generated/types/initProtocolEvent.js.map +1 -0
- package/dist/generated/types/initializeDirectWithdrawStrategyEvent.d.ts +34 -0
- package/dist/generated/types/initializeDirectWithdrawStrategyEvent.d.ts.map +1 -0
- package/dist/generated/types/initializeDirectWithdrawStrategyEvent.js +55 -0
- package/dist/generated/types/initializeDirectWithdrawStrategyEvent.js.map +1 -0
- package/dist/generated/types/initializeStrategyEvent.d.ts +32 -0
- package/dist/generated/types/initializeStrategyEvent.d.ts.map +1 -0
- package/dist/generated/types/initializeStrategyEvent.js +41 -0
- package/dist/generated/types/initializeStrategyEvent.js.map +1 -0
- package/dist/generated/types/initializeVaultEvent.d.ts +56 -0
- package/dist/generated/types/initializeVaultEvent.d.ts.map +1 -0
- package/dist/generated/types/initializeVaultEvent.js +71 -0
- package/dist/generated/types/initializeVaultEvent.js.map +1 -0
- package/dist/generated/types/instantWithdrawStrategyEvent.d.ts +68 -0
- package/dist/generated/types/instantWithdrawStrategyEvent.d.ts.map +1 -0
- package/dist/generated/types/instantWithdrawStrategyEvent.js +77 -0
- package/dist/generated/types/instantWithdrawStrategyEvent.js.map +1 -0
- package/dist/generated/types/instantWithdrawVaultEvent.d.ts +56 -0
- package/dist/generated/types/instantWithdrawVaultEvent.d.ts.map +1 -0
- package/dist/generated/types/instantWithdrawVaultEvent.js +65 -0
- package/dist/generated/types/instantWithdrawVaultEvent.js.map +1 -0
- package/dist/generated/types/lockedProfitState.d.ts +20 -0
- package/dist/generated/types/lockedProfitState.d.ts.map +1 -0
- package/dist/generated/types/lockedProfitState.js +29 -0
- package/dist/generated/types/lockedProfitState.js.map +1 -0
- package/dist/generated/types/protocolConfigField.d.ts +17 -0
- package/dist/generated/types/protocolConfigField.d.ts.map +1 -0
- package/dist/generated/types/protocolConfigField.js +29 -0
- package/dist/generated/types/protocolConfigField.js.map +1 -0
- package/dist/generated/types/protocolFeeField.d.ts +17 -0
- package/dist/generated/types/protocolFeeField.d.ts.map +1 -0
- package/dist/generated/types/protocolFeeField.js +29 -0
- package/dist/generated/types/protocolFeeField.js.map +1 -0
- package/dist/generated/types/removeAdaptorEvent.d.ts +26 -0
- package/dist/generated/types/removeAdaptorEvent.d.ts.map +1 -0
- package/dist/generated/types/removeAdaptorEvent.js +35 -0
- package/dist/generated/types/removeAdaptorEvent.js.map +1 -0
- package/dist/generated/types/requestWithdrawVaultEvent.d.ts +44 -0
- package/dist/generated/types/requestWithdrawVaultEvent.d.ts.map +1 -0
- package/dist/generated/types/requestWithdrawVaultEvent.js +53 -0
- package/dist/generated/types/requestWithdrawVaultEvent.js.map +1 -0
- package/dist/generated/types/updateProtocolEvent.d.ts +28 -0
- package/dist/generated/types/updateProtocolEvent.d.ts.map +1 -0
- package/dist/generated/types/updateProtocolEvent.js +37 -0
- package/dist/generated/types/updateProtocolEvent.js.map +1 -0
- package/dist/generated/types/updateVaultConfigEvent.d.ts +28 -0
- package/dist/generated/types/updateVaultConfigEvent.d.ts.map +1 -0
- package/dist/generated/types/updateVaultConfigEvent.js +37 -0
- package/dist/generated/types/updateVaultConfigEvent.js.map +1 -0
- package/dist/generated/types/updateVaultEvent.d.ts +62 -0
- package/dist/generated/types/updateVaultEvent.d.ts.map +1 -0
- package/dist/generated/types/updateVaultEvent.js +71 -0
- package/dist/generated/types/updateVaultEvent.js.map +1 -0
- package/dist/generated/types/updateVaultProtocolFeeEvent.d.ts +28 -0
- package/dist/generated/types/updateVaultProtocolFeeEvent.d.ts.map +1 -0
- package/dist/generated/types/updateVaultProtocolFeeEvent.js +37 -0
- package/dist/generated/types/updateVaultProtocolFeeEvent.js.map +1 -0
- package/dist/generated/types/vaultAsset.d.ts +36 -0
- package/dist/generated/types/vaultAsset.d.ts.map +1 -0
- package/dist/generated/types/vaultAsset.js +35 -0
- package/dist/generated/types/vaultAsset.js.map +1 -0
- package/dist/generated/types/vaultConfigField.d.ts +28 -0
- package/dist/generated/types/vaultConfigField.d.ts.map +1 -0
- package/dist/generated/types/vaultConfigField.js +40 -0
- package/dist/generated/types/vaultConfigField.js.map +1 -0
- package/dist/generated/types/vaultConfiguration.d.ts +40 -0
- package/dist/generated/types/vaultConfiguration.d.ts.map +1 -0
- package/dist/generated/types/vaultConfiguration.js +37 -0
- package/dist/generated/types/vaultConfiguration.js.map +1 -0
- package/dist/generated/types/vaultLp.d.ts +23 -0
- package/dist/generated/types/vaultLp.d.ts.map +1 -0
- package/dist/generated/types/vaultLp.js +33 -0
- package/dist/generated/types/vaultLp.js.map +1 -0
- package/dist/generated/types/withdrawStrategyEvent.d.ts +52 -0
- package/dist/generated/types/withdrawStrategyEvent.d.ts.map +1 -0
- package/dist/generated/types/withdrawStrategyEvent.js +61 -0
- package/dist/generated/types/withdrawStrategyEvent.js.map +1 -0
- package/dist/generated/types/withdrawVaultEvent.d.ts +50 -0
- package/dist/generated/types/withdrawVaultEvent.d.ts.map +1 -0
- package/dist/generated/types/withdrawVaultEvent.js +59 -0
- package/dist/generated/types/withdrawVaultEvent.js.map +1 -0
- package/dist/index.d.ts +3 -4
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +3 -4
- package/dist/index.js.map +1 -0
- package/package.json +31 -27
- package/src/extensions/batchFetchers.ts +121 -0
- package/src/extensions/decimal.ts +15 -0
- package/src/extensions/fees.ts +36 -0
- package/src/extensions/index.ts +9 -0
- package/src/extensions/lpEconomics.ts +225 -0
- package/src/extensions/math.ts +338 -0
- package/src/extensions/metadataPda.ts +47 -0
- package/src/extensions/position.ts +54 -0
- package/src/extensions/rpc.ts +17 -0
- package/src/extensions/withdrawals.ts +113 -0
- package/src/generated/accounts/adaptorAddReceipt.ts +194 -0
- package/src/generated/accounts/directWithdrawInitReceipt.ts +235 -0
- package/src/generated/accounts/index.ts +14 -0
- package/src/generated/accounts/protocol.ts +176 -0
- package/src/generated/accounts/requestWithdrawVaultReceipt.ts +197 -0
- package/src/generated/accounts/strategyInitReceipt.ts +221 -0
- package/src/generated/accounts/vault.ts +274 -0
- package/src/generated/errors/index.ts +9 -0
- package/src/generated/errors/voltrVault.ts +112 -0
- package/src/generated/index.ts +14 -0
- package/src/generated/instructions/acceptProtocolAdmin.ts +248 -0
- package/src/generated/instructions/acceptVaultAdmin.ts +187 -0
- package/src/generated/instructions/addAdaptor.ts +391 -0
- package/src/generated/instructions/calibrateHighWaterMark.ts +394 -0
- package/src/generated/instructions/calibrateHighWaterMarkUnsafe.ts +311 -0
- package/src/generated/instructions/cancelRequestWithdrawVault.ts +546 -0
- package/src/generated/instructions/closeStrategy.ts +395 -0
- package/src/generated/instructions/createLpMetadata.ts +501 -0
- package/src/generated/instructions/depositStrategy.ts +737 -0
- package/src/generated/instructions/depositVault.ts +686 -0
- package/src/generated/instructions/directWithdrawStrategy.ts +903 -0
- package/src/generated/instructions/directWithdrawStrategyWithTolerance.ts +913 -0
- package/src/generated/instructions/harvestFee.ts +599 -0
- package/src/generated/instructions/index.ts +35 -0
- package/src/generated/instructions/initProtocol.ts +329 -0
- package/src/generated/instructions/initializeDirectWithdrawStrategy.ts +576 -0
- package/src/generated/instructions/initializeStrategy.ts +557 -0
- package/src/generated/instructions/initializeVault.ts +784 -0
- package/src/generated/instructions/instantWithdrawStrategy.ts +870 -0
- package/src/generated/instructions/instantWithdrawStrategyWithTolerance.ts +878 -0
- package/src/generated/instructions/instantWithdrawVault.ts +670 -0
- package/src/generated/instructions/removeAdaptor.ts +371 -0
- package/src/generated/instructions/requestWithdrawVault.ts +608 -0
- package/src/generated/instructions/updateProtocol.ts +270 -0
- package/src/generated/instructions/updateVaultConfig.ts +343 -0
- package/src/generated/instructions/updateVaultProtocolFee.ts +344 -0
- package/src/generated/instructions/withdrawStrategy.ts +737 -0
- package/src/generated/instructions/withdrawVault.ts +685 -0
- package/src/generated/pdas/adaptorAddReceipt.ts +42 -0
- package/src/generated/pdas/directWithdrawInitReceipt.ts +42 -0
- package/src/generated/pdas/index.ts +17 -0
- package/src/generated/pdas/protocol.ts +30 -0
- package/src/generated/pdas/requestWithdrawVaultReceipt.ts +43 -0
- package/src/generated/pdas/strategyInitReceipt.ts +42 -0
- package/src/generated/pdas/vaultAssetIdleAuth.ts +40 -0
- package/src/generated/pdas/vaultLpMint.ts +39 -0
- package/src/generated/pdas/vaultLpMintAuth.ts +40 -0
- package/src/generated/pdas/vaultStrategyAuth.ts +42 -0
- package/src/generated/programs/index.ts +9 -0
- package/src/generated/programs/voltrVault.ts +1261 -0
- package/src/generated/types/acceptProtocolAdminEvent.ts +63 -0
- package/src/generated/types/acceptVaultAdminEvent.ts +63 -0
- package/src/generated/types/addAdaptorEvent.ts +68 -0
- package/src/generated/types/calibrateHighWaterMarkEvent.ts +85 -0
- package/src/generated/types/calibrateHighWaterMarkUnsafeEvent.ts +77 -0
- package/src/generated/types/cancelRequestWithdrawVaultEvent.ts +81 -0
- package/src/generated/types/closeStrategyEvent.ts +67 -0
- package/src/generated/types/depositStrategyEvent.ts +121 -0
- package/src/generated/types/depositVaultEvent.ts +113 -0
- package/src/generated/types/directWithdrawStrategyEvent.ts +141 -0
- package/src/generated/types/feeConfiguration.ts +84 -0
- package/src/generated/types/feeState.ts +67 -0
- package/src/generated/types/feeUpdate.ts +50 -0
- package/src/generated/types/harvestFeeEvent.ts +76 -0
- package/src/generated/types/highWaterMark.ts +66 -0
- package/src/generated/types/index.ts +44 -0
- package/src/generated/types/initProtocolEvent.ts +61 -0
- package/src/generated/types/initializeDirectWithdrawStrategyEvent.ts +104 -0
- package/src/generated/types/initializeStrategyEvent.ts +81 -0
- package/src/generated/types/initializeVaultEvent.ts +141 -0
- package/src/generated/types/instantWithdrawStrategyEvent.ts +155 -0
- package/src/generated/types/instantWithdrawVaultEvent.ts +131 -0
- package/src/generated/types/lockedProfitState.ts +52 -0
- package/src/generated/types/protocolConfigField.ts +41 -0
- package/src/generated/types/protocolFeeField.ts +41 -0
- package/src/generated/types/removeAdaptorEvent.ts +67 -0
- package/src/generated/types/requestWithdrawVaultEvent.ts +107 -0
- package/src/generated/types/updateProtocolEvent.ts +77 -0
- package/src/generated/types/updateVaultConfigEvent.ts +77 -0
- package/src/generated/types/updateVaultEvent.ts +141 -0
- package/src/generated/types/updateVaultProtocolFeeEvent.ts +79 -0
- package/src/generated/types/vaultAsset.ts +81 -0
- package/src/generated/types/vaultConfigField.ts +52 -0
- package/src/generated/types/vaultConfiguration.ts +87 -0
- package/src/generated/types/vaultLp.ts +61 -0
- package/src/generated/types/withdrawStrategyEvent.ts +121 -0
- package/src/generated/types/withdrawVaultEvent.ts +117 -0
- package/src/index.ts +2 -0
- package/README.md +0 -453
- package/dist/client.d.ts +0 -1544
- package/dist/client.js +0 -1964
- package/dist/constants.d.ts +0 -20
- package/dist/constants.js +0 -27
- package/dist/decimals.d.ts +0 -3
- package/dist/decimals.js +0 -10
- package/dist/idl/voltr_vault.json +0 -9029
- package/dist/types/index.d.ts +0 -2
- package/dist/types/vault.d.ts +0 -70
- package/dist/types/vault.js +0 -29
- package/dist/types/voltr_vault.d.ts +0 -9035
package/dist/client.js
DELETED
|
@@ -1,1964 +0,0 @@
|
|
|
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
|
-
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
36
|
-
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
37
|
-
};
|
|
38
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
39
|
-
exports.VoltrClient = void 0;
|
|
40
|
-
const anchor_1 = require("@coral-xyz/anchor");
|
|
41
|
-
const bn_js_1 = __importDefault(require("bn.js"));
|
|
42
|
-
const web3_js_1 = require("@solana/web3.js");
|
|
43
|
-
const spl_token_1 = require("@solana/spl-token");
|
|
44
|
-
const constants_1 = require("./constants");
|
|
45
|
-
const types_1 = require("./types");
|
|
46
|
-
// Import IDL files
|
|
47
|
-
const vaultIdl = __importStar(require("./idl/voltr_vault.json"));
|
|
48
|
-
const decimals_1 = require("./decimals");
|
|
49
|
-
class CustomWallet {
|
|
50
|
-
constructor(payer) {
|
|
51
|
-
this.payer = payer;
|
|
52
|
-
}
|
|
53
|
-
async signTransaction(tx) {
|
|
54
|
-
tx.partialSign(this.payer);
|
|
55
|
-
return tx;
|
|
56
|
-
}
|
|
57
|
-
async signAllTransactions(txs) {
|
|
58
|
-
return txs.map((t) => {
|
|
59
|
-
t.partialSign(this.payer);
|
|
60
|
-
return t;
|
|
61
|
-
});
|
|
62
|
-
}
|
|
63
|
-
get publicKey() {
|
|
64
|
-
return this.payer.publicKey;
|
|
65
|
-
}
|
|
66
|
-
}
|
|
67
|
-
class AccountUtils {
|
|
68
|
-
constructor(conn) {
|
|
69
|
-
this.conn = conn;
|
|
70
|
-
}
|
|
71
|
-
/**
|
|
72
|
-
* Gets the balance of a Solana account
|
|
73
|
-
* @param publicKey - Public key to check balance for
|
|
74
|
-
* @returns Promise resolving to the account balance in lamports
|
|
75
|
-
* @throws {Error} If fetching balance fails
|
|
76
|
-
*/
|
|
77
|
-
async getBalance(publicKey) {
|
|
78
|
-
try {
|
|
79
|
-
return await this.conn.getBalance(publicKey);
|
|
80
|
-
}
|
|
81
|
-
catch (error) {
|
|
82
|
-
throw new Error(`Failed to get account balance: ${error}`);
|
|
83
|
-
}
|
|
84
|
-
}
|
|
85
|
-
}
|
|
86
|
-
/**
|
|
87
|
-
* Main client for interacting with the Voltr protocol
|
|
88
|
-
*
|
|
89
|
-
* @remarks
|
|
90
|
-
* The VoltrClient provides methods for initializing and managing vaults,
|
|
91
|
-
* handling strategies, and performing deposits/withdrawals. It requires
|
|
92
|
-
* a Solana connection and optionally accepts a wallet for signing transactions.
|
|
93
|
-
*
|
|
94
|
-
* @example
|
|
95
|
-
* ```typescript
|
|
96
|
-
* import { VoltrClient } from '@voltr/vault-sdk';
|
|
97
|
-
* import { Connection } from '@solana/web3.js';
|
|
98
|
-
*
|
|
99
|
-
* const connection = new Connection('https://api.mainnet-beta.solana.com');
|
|
100
|
-
* const client = new VoltrClient(connection);
|
|
101
|
-
* ```
|
|
102
|
-
*/
|
|
103
|
-
class VoltrClient extends AccountUtils {
|
|
104
|
-
/**
|
|
105
|
-
* Creates a new VoltrClient instance
|
|
106
|
-
* @param conn - Solana connection instance
|
|
107
|
-
* @param wallet - Optional keypair for signing transactions
|
|
108
|
-
*/
|
|
109
|
-
constructor(conn, wallet, opts) {
|
|
110
|
-
super(conn);
|
|
111
|
-
// Initialize programs
|
|
112
|
-
this.setProvider(wallet, opts);
|
|
113
|
-
this.setPrograms(vaultIdl);
|
|
114
|
-
}
|
|
115
|
-
setProvider(wallet, opts) {
|
|
116
|
-
/// we are creating instructions with this client without signing
|
|
117
|
-
let kp;
|
|
118
|
-
if (!wallet) {
|
|
119
|
-
const leakedKp = web3_js_1.Keypair.fromSecretKey(Uint8Array.from([
|
|
120
|
-
208, 175, 150, 242, 88, 34, 108, 88, 177, 16, 168, 75, 115, 181, 199,
|
|
121
|
-
242, 120, 4, 78, 75, 19, 227, 13, 215, 184, 108, 226, 53, 111, 149,
|
|
122
|
-
179, 84, 137, 121, 79, 1, 160, 223, 124, 241, 202, 203, 220, 237, 50,
|
|
123
|
-
242, 57, 158, 226, 207, 203, 188, 43, 28, 70, 110, 214, 234, 251, 15,
|
|
124
|
-
249, 157, 62, 80,
|
|
125
|
-
]));
|
|
126
|
-
kp = leakedKp;
|
|
127
|
-
}
|
|
128
|
-
else {
|
|
129
|
-
kp = wallet;
|
|
130
|
-
}
|
|
131
|
-
this.provider = new anchor_1.AnchorProvider(this.conn, new CustomWallet(kp), opts ?? anchor_1.AnchorProvider.defaultOptions());
|
|
132
|
-
(0, anchor_1.setProvider)(this.provider);
|
|
133
|
-
}
|
|
134
|
-
setPrograms(vaultIdl) {
|
|
135
|
-
this.vaultProgram = new anchor_1.Program(vaultIdl, this.provider);
|
|
136
|
-
}
|
|
137
|
-
// --------------------------------------- Find PDA addresses
|
|
138
|
-
/**
|
|
139
|
-
* Finds the vault LP mint address for a given vault
|
|
140
|
-
* @param vault - Public key of the vault
|
|
141
|
-
* @returns The PDA for the vault's LP mint
|
|
142
|
-
*/
|
|
143
|
-
findVaultLpMint(vault) {
|
|
144
|
-
const [vaultLpMint] = web3_js_1.PublicKey.findProgramAddressSync([constants_1.SEEDS.VAULT_LP_MINT, vault.toBuffer()], this.vaultProgram.programId);
|
|
145
|
-
return vaultLpMint;
|
|
146
|
-
}
|
|
147
|
-
/**
|
|
148
|
-
* Finds the vault's asset idle authority address
|
|
149
|
-
* @param vault - Public key of the vault
|
|
150
|
-
* @returns The PDA for the vault's asset idle authority
|
|
151
|
-
*/
|
|
152
|
-
findVaultAssetIdleAuth(vault) {
|
|
153
|
-
const [vaultAssetIdleAuth] = web3_js_1.PublicKey.findProgramAddressSync([constants_1.SEEDS.VAULT_ASSET_IDLE_AUTH, vault.toBuffer()], this.vaultProgram.programId);
|
|
154
|
-
return vaultAssetIdleAuth;
|
|
155
|
-
}
|
|
156
|
-
/**
|
|
157
|
-
* Finds all vault-related addresses
|
|
158
|
-
* @param vault - Public key of the vault
|
|
159
|
-
* @returns Object containing all vault-related PDAs
|
|
160
|
-
*
|
|
161
|
-
* @example
|
|
162
|
-
* ```typescript
|
|
163
|
-
* const addresses = client.findVaultAddresses(vaultPubkey);
|
|
164
|
-
* console.log(addresses.vaultLpMint.toBase58());
|
|
165
|
-
* console.log(addresses.vaultAssetIdleAuth.toBase58());
|
|
166
|
-
* console.log(addresses.vaultLpFeeAuth.toBase58());
|
|
167
|
-
* ```
|
|
168
|
-
*/
|
|
169
|
-
findVaultAddresses(vault) {
|
|
170
|
-
const vaultLpMint = this.findVaultLpMint(vault);
|
|
171
|
-
const vaultAssetIdleAuth = this.findVaultAssetIdleAuth(vault);
|
|
172
|
-
return {
|
|
173
|
-
vaultLpMint,
|
|
174
|
-
vaultAssetIdleAuth,
|
|
175
|
-
};
|
|
176
|
-
}
|
|
177
|
-
/**
|
|
178
|
-
* Finds the vault strategy auth address
|
|
179
|
-
* @param vault - Public key of the vault
|
|
180
|
-
* @param strategy - Public key of the strategy
|
|
181
|
-
* @returns The PDA for the vault strategy auth
|
|
182
|
-
*
|
|
183
|
-
* @example
|
|
184
|
-
* ```typescript
|
|
185
|
-
* const vaultStrategyAuth = client.findVaultStrategyAuth(vaultPubkey, strategyPubkey);
|
|
186
|
-
* ```
|
|
187
|
-
*/
|
|
188
|
-
findVaultStrategyAuth(vault, strategy) {
|
|
189
|
-
const [vaultStrategyAuth] = web3_js_1.PublicKey.findProgramAddressSync([constants_1.SEEDS.VAULT_STRATEGY_AUTH, vault.toBuffer(), strategy.toBuffer()], this.vaultProgram.programId);
|
|
190
|
-
return vaultStrategyAuth;
|
|
191
|
-
}
|
|
192
|
-
/**
|
|
193
|
-
* Finds the strategy init receipt address
|
|
194
|
-
* @param vault - Public key of the vault
|
|
195
|
-
* @param strategy - Public key of the strategy
|
|
196
|
-
* @returns The PDA for the strategy init receipt
|
|
197
|
-
*
|
|
198
|
-
* @example
|
|
199
|
-
* ```typescript
|
|
200
|
-
* const strategyInitReceipt = client.findStrategyInitReceipt(vaultPubkey, strategyPubkey);
|
|
201
|
-
* ```
|
|
202
|
-
*/
|
|
203
|
-
findStrategyInitReceipt(vault, strategy) {
|
|
204
|
-
const [strategyInitReceipt] = web3_js_1.PublicKey.findProgramAddressSync([constants_1.SEEDS.STRATEGY_INIT_RECEIPT, vault.toBuffer(), strategy.toBuffer()], this.vaultProgram.programId);
|
|
205
|
-
return strategyInitReceipt;
|
|
206
|
-
}
|
|
207
|
-
/**
|
|
208
|
-
* Finds the direct withdraw init receipt address
|
|
209
|
-
* @param vault - Public key of the vault
|
|
210
|
-
* @param strategy - Public key of the strategy
|
|
211
|
-
* @returns The PDA for the direct withdraw init receipt
|
|
212
|
-
*
|
|
213
|
-
* @example
|
|
214
|
-
* ```typescript
|
|
215
|
-
* const directWithdrawInitReceipt = client.findDirectWithdrawInitReceipt(vaultPubkey, strategyPubkey);
|
|
216
|
-
* ```
|
|
217
|
-
*/
|
|
218
|
-
findDirectWithdrawInitReceipt(vault, strategy) {
|
|
219
|
-
const [directWithdrawInitReceipt] = web3_js_1.PublicKey.findProgramAddressSync([
|
|
220
|
-
constants_1.SEEDS.DIRECT_WITHDRAW_INIT_RECEIPT_SEED,
|
|
221
|
-
vault.toBuffer(),
|
|
222
|
-
strategy.toBuffer(),
|
|
223
|
-
], this.vaultProgram.programId);
|
|
224
|
-
return directWithdrawInitReceipt;
|
|
225
|
-
}
|
|
226
|
-
findVaultStrategyAddresses(vault, strategy) {
|
|
227
|
-
const vaultStrategyAuth = this.findVaultStrategyAuth(vault, strategy);
|
|
228
|
-
const strategyInitReceipt = this.findStrategyInitReceipt(vault, strategy);
|
|
229
|
-
const directWithdrawInitReceipt = this.findDirectWithdrawInitReceipt(vault, strategy);
|
|
230
|
-
return {
|
|
231
|
-
vaultStrategyAuth,
|
|
232
|
-
strategyInitReceipt,
|
|
233
|
-
directWithdrawInitReceipt,
|
|
234
|
-
};
|
|
235
|
-
}
|
|
236
|
-
/**
|
|
237
|
-
* Finds the request withdraw vault receipt address
|
|
238
|
-
* @param vault - Public key of the vault
|
|
239
|
-
* @param user - Public key of the user
|
|
240
|
-
* @returns The PDA for the request withdraw vault receipt
|
|
241
|
-
*
|
|
242
|
-
* @example
|
|
243
|
-
* ```typescript
|
|
244
|
-
* const requestWithdrawVaultReceipt = client.findRequestWithdrawVaultReceipt(vaultPubkey, userPubkey);
|
|
245
|
-
* ```
|
|
246
|
-
*/
|
|
247
|
-
findRequestWithdrawVaultReceipt(vault, user) {
|
|
248
|
-
const [requestWithdrawVaultReceipt] = web3_js_1.PublicKey.findProgramAddressSync([constants_1.SEEDS.REQUEST_WITHDRAW_VAULT_RECEIPT, vault.toBuffer(), user.toBuffer()], this.vaultProgram.programId);
|
|
249
|
-
return requestWithdrawVaultReceipt;
|
|
250
|
-
}
|
|
251
|
-
/**
|
|
252
|
-
* Finds the LP metadata account for a given vault
|
|
253
|
-
* @param vault - Public key of the vault
|
|
254
|
-
* @returns The PDA for the LP metadata account
|
|
255
|
-
*
|
|
256
|
-
* @example
|
|
257
|
-
* ```typescript
|
|
258
|
-
* const lpMetadataAccount = client.findLpMetadataAccount(vaultPubkey);
|
|
259
|
-
* ```
|
|
260
|
-
*/
|
|
261
|
-
findLpMetadataAccount(vault) {
|
|
262
|
-
const lpMint = this.findVaultLpMint(vault);
|
|
263
|
-
const [lpMetadataAccount] = web3_js_1.PublicKey.findProgramAddressSync([constants_1.SEEDS.METADATA, constants_1.METADATA_PROGRAM_ID.toBuffer(), lpMint.toBuffer()], constants_1.METADATA_PROGRAM_ID);
|
|
264
|
-
return lpMetadataAccount;
|
|
265
|
-
}
|
|
266
|
-
/**
|
|
267
|
-
* Finds the protocol PDA address
|
|
268
|
-
* @returns The PDA for the protocol account
|
|
269
|
-
*
|
|
270
|
-
* @example
|
|
271
|
-
* ```typescript
|
|
272
|
-
* const protocol = client.findProtocol();
|
|
273
|
-
* ```
|
|
274
|
-
*/
|
|
275
|
-
findProtocol() {
|
|
276
|
-
const [protocol] = web3_js_1.PublicKey.findProgramAddressSync([constants_1.SEEDS.PROTOCOL], this.vaultProgram.programId);
|
|
277
|
-
return protocol;
|
|
278
|
-
}
|
|
279
|
-
// --------------------------------------- Protocol Instructions
|
|
280
|
-
/**
|
|
281
|
-
* Creates an instruction to initialize the protocol
|
|
282
|
-
*
|
|
283
|
-
* @param {number} operationalState - Bitflags for allowed operations (e.g., CREATE_VAULT = 1, DEPOSIT_VAULT = 2, etc.)
|
|
284
|
-
* @param {Object} params - Parameters for initializing the protocol
|
|
285
|
-
* @param {PublicKey} params.payer - Public key of the fee payer
|
|
286
|
-
* @param {PublicKey} params.admin - Public key of the protocol admin
|
|
287
|
-
* @returns {Promise<TransactionInstruction>} Transaction instruction for initializing the protocol
|
|
288
|
-
*
|
|
289
|
-
* @example
|
|
290
|
-
* ```typescript
|
|
291
|
-
* const ix = await client.createInitProtocolIx(
|
|
292
|
-
* 0xFFFF, // enable all operations
|
|
293
|
-
* {
|
|
294
|
-
* payer: payerPubkey,
|
|
295
|
-
* admin: adminPubkey,
|
|
296
|
-
* }
|
|
297
|
-
* );
|
|
298
|
-
* ```
|
|
299
|
-
*/
|
|
300
|
-
async createInitProtocolIx(operationalState, { payer, admin, }) {
|
|
301
|
-
return await this.vaultProgram.methods
|
|
302
|
-
.initProtocol(operationalState)
|
|
303
|
-
.accounts({
|
|
304
|
-
payer,
|
|
305
|
-
admin,
|
|
306
|
-
})
|
|
307
|
-
.instruction();
|
|
308
|
-
}
|
|
309
|
-
/**
|
|
310
|
-
* Creates an instruction to update the protocol configuration
|
|
311
|
-
*
|
|
312
|
-
* @param {ProtocolConfigField} field - The protocol configuration field to update
|
|
313
|
-
* @param {Buffer} data - The serialized data for the new value
|
|
314
|
-
* @param {Object} params - Parameters for updating the protocol
|
|
315
|
-
* @param {PublicKey} params.admin - Public key of the protocol admin
|
|
316
|
-
* @returns {Promise<TransactionInstruction>} Transaction instruction for updating the protocol
|
|
317
|
-
*
|
|
318
|
-
* @throws {Error} If the field is unknown
|
|
319
|
-
*
|
|
320
|
-
* @example Update operational state
|
|
321
|
-
* ```typescript
|
|
322
|
-
* const data = Buffer.alloc(2);
|
|
323
|
-
* data.writeUInt16LE(0xFFFF, 0);
|
|
324
|
-
* const ix = await client.createUpdateProtocolIx(
|
|
325
|
-
* ProtocolConfigField.OperationalState,
|
|
326
|
-
* data,
|
|
327
|
-
* { admin: adminPubkey }
|
|
328
|
-
* );
|
|
329
|
-
* ```
|
|
330
|
-
*
|
|
331
|
-
* @example Set pending admin for 2-step transfer
|
|
332
|
-
* ```typescript
|
|
333
|
-
* const data = newAdmin.toBuffer();
|
|
334
|
-
* const ix = await client.createUpdateProtocolIx(
|
|
335
|
-
* ProtocolConfigField.PendingAdmin,
|
|
336
|
-
* data,
|
|
337
|
-
* { admin: adminPubkey }
|
|
338
|
-
* );
|
|
339
|
-
* ```
|
|
340
|
-
*/
|
|
341
|
-
async createUpdateProtocolIx(field, data, { admin, }) {
|
|
342
|
-
const fieldToVariant = {
|
|
343
|
-
[types_1.ProtocolConfigField.OperationalState]: { operationalState: {} },
|
|
344
|
-
[types_1.ProtocolConfigField.PendingAdmin]: { pendingAdmin: {} },
|
|
345
|
-
};
|
|
346
|
-
const fieldVariant = fieldToVariant[field];
|
|
347
|
-
if (!fieldVariant) {
|
|
348
|
-
throw new Error(`Unknown protocol config field: ${field}`);
|
|
349
|
-
}
|
|
350
|
-
return await this.vaultProgram.methods
|
|
351
|
-
.updateProtocol(fieldVariant, data)
|
|
352
|
-
.accounts({
|
|
353
|
-
admin,
|
|
354
|
-
})
|
|
355
|
-
.instruction();
|
|
356
|
-
}
|
|
357
|
-
/**
|
|
358
|
-
* Creates an instruction to accept a protocol admin transfer (2-step admin transfer)
|
|
359
|
-
*
|
|
360
|
-
* @param {Object} params - Parameters for accepting protocol admin
|
|
361
|
-
* @param {PublicKey} params.pendingAdmin - Public key of the pending admin (must be signer)
|
|
362
|
-
* @returns {Promise<TransactionInstruction>} Transaction instruction for accepting protocol admin
|
|
363
|
-
*
|
|
364
|
-
* @example
|
|
365
|
-
* ```typescript
|
|
366
|
-
* const ix = await client.createAcceptProtocolAdminIx({
|
|
367
|
-
* pendingAdmin: pendingAdminPubkey,
|
|
368
|
-
* });
|
|
369
|
-
* ```
|
|
370
|
-
*/
|
|
371
|
-
async createAcceptProtocolAdminIx({ pendingAdmin, }) {
|
|
372
|
-
return await this.vaultProgram.methods
|
|
373
|
-
.acceptProtocolAdmin()
|
|
374
|
-
.accounts({
|
|
375
|
-
pendingAdmin,
|
|
376
|
-
})
|
|
377
|
-
.instruction();
|
|
378
|
-
}
|
|
379
|
-
// --------------------------------------- Vault Instructions
|
|
380
|
-
/**
|
|
381
|
-
* Creates an instruction to initialize a new vault
|
|
382
|
-
*
|
|
383
|
-
* @param {VaultParams} vaultParams - Configuration parameters for the vault
|
|
384
|
-
* @param {VaultConfig} vaultParams.config - Vault configuration settings
|
|
385
|
-
* @param {BN} vaultParams.config.maxCap - Maximum capacity of the vault
|
|
386
|
-
* @param {BN} vaultParams.config.startAtTs - Vault start timestamp in seconds
|
|
387
|
-
* @param {BN} vaultParams.config.lockedProfitDegradationDuration - Locked profit degradation duration in seconds
|
|
388
|
-
* @param {number} vaultParams.config.managerManagementFee - Manager's management fee in basis points (e.g., 50 = 0.5%)
|
|
389
|
-
* @param {number} vaultParams.config.managerPerformanceFee - Manager's performance fee in basis points (e.g., 1000 = 10%)
|
|
390
|
-
* @param {number} vaultParams.config.adminManagementFee - Admin's management fee in basis points (e.g., 50 = 0.5%)
|
|
391
|
-
* @param {number} vaultParams.config.adminPerformanceFee - Admin's performance fee in basis points (e.g., 1000 = 10%)
|
|
392
|
-
* @param {number} vaultParams.config.redemptionFee - Redemption fee in basis points (e.g., 10 = 0.1%)
|
|
393
|
-
* @param {number} vaultParams.config.issuanceFee - Issuance fee in basis points (e.g., 10 = 0.1%)
|
|
394
|
-
* @param {BN} vaultParams.config.withdrawalWaitingPeriod - Withdrawal waiting period in seconds
|
|
395
|
-
* @param {string} vaultParams.name - Name of the vault
|
|
396
|
-
* @param {string} vaultParams.description - Description of the vault
|
|
397
|
-
* @param {Object} params - Additional parameters for initializing the vault
|
|
398
|
-
* @param {Keypair} params.vault - Keypair for the new vault
|
|
399
|
-
* @param {PublicKey} params.vaultAssetMint - Public key of the vault's asset mint
|
|
400
|
-
* @param {PublicKey} params.admin - Public key of the vault admin
|
|
401
|
-
* @param {PublicKey} params.manager - Public key of the vault manager
|
|
402
|
-
* @param {PublicKey} params.payer - Public key of the fee payer
|
|
403
|
-
* @returns {Promise<TransactionInstruction>} Transaction instruction for initializing the vault
|
|
404
|
-
*
|
|
405
|
-
* @example
|
|
406
|
-
* ```typescript
|
|
407
|
-
* const ix = await client.createInitializeVaultIx(
|
|
408
|
-
* {
|
|
409
|
-
* config: {
|
|
410
|
-
* maxCap: new BN('1000000000'),
|
|
411
|
-
* startAtTs: new BN(Math.floor(Date.now() / 1000)),
|
|
412
|
-
* lockedProfitDegradationDuration: new BN(3600), // 1 hour
|
|
413
|
-
* redemptionFee: 10,
|
|
414
|
-
* issuanceFee: 10,
|
|
415
|
-
* withdrawalWaitingPeriod: new BN(3600), // 1 hour
|
|
416
|
-
* managerManagementFee: 50, // 0.5%
|
|
417
|
-
* managerPerformanceFee: 1000, // 10%
|
|
418
|
-
* adminManagementFee: 50, // 0.5%
|
|
419
|
-
* adminPerformanceFee: 1000, // 10%
|
|
420
|
-
* },
|
|
421
|
-
* name: "My Vault",
|
|
422
|
-
* description: "Example vault"
|
|
423
|
-
* },
|
|
424
|
-
* {
|
|
425
|
-
* vault: vaultKeypair,
|
|
426
|
-
* vaultAssetMint: new PublicKey('...'),
|
|
427
|
-
* admin: adminPubkey,
|
|
428
|
-
* manager: managerPubkey,
|
|
429
|
-
* payer: payerPubkey
|
|
430
|
-
* }
|
|
431
|
-
* );
|
|
432
|
-
* ```
|
|
433
|
-
*/
|
|
434
|
-
async createInitializeVaultIx(vaultParams, { vault, vaultAssetMint, admin, manager, payer, }) {
|
|
435
|
-
const addresses = this.findVaultAddresses(vault);
|
|
436
|
-
const vaultAssetMintAccount = await this.provider.connection.getAccountInfo(vaultAssetMint);
|
|
437
|
-
const assetTokenProgram = vaultAssetMintAccount?.owner;
|
|
438
|
-
if (!assetTokenProgram) {
|
|
439
|
-
throw new Error("Vault asset mint not found");
|
|
440
|
-
}
|
|
441
|
-
const vaultAssetIdleAta = (0, spl_token_1.getAssociatedTokenAddressSync)(vaultAssetMint, addresses.vaultAssetIdleAuth, true, assetTokenProgram);
|
|
442
|
-
return await this.vaultProgram.methods
|
|
443
|
-
.initializeVault(vaultParams.config, vaultParams.name, vaultParams.description)
|
|
444
|
-
.accounts({
|
|
445
|
-
payer,
|
|
446
|
-
admin,
|
|
447
|
-
manager,
|
|
448
|
-
vault,
|
|
449
|
-
vaultAssetMint,
|
|
450
|
-
vaultAssetIdleAta,
|
|
451
|
-
assetTokenProgram,
|
|
452
|
-
})
|
|
453
|
-
.instruction();
|
|
454
|
-
}
|
|
455
|
-
/**
|
|
456
|
-
* Creates an instruction to update a specific vault configuration field
|
|
457
|
-
*
|
|
458
|
-
* @param {VaultConfigField} field - The configuration field to update
|
|
459
|
-
* @param {Buffer} data - The serialized data for the new value
|
|
460
|
-
* @param {Object} params - Parameters for updating the vault config
|
|
461
|
-
* @param {PublicKey} params.vault - Public key of the vault
|
|
462
|
-
* @param {PublicKey} params.admin - Public key of the vault admin
|
|
463
|
-
* @param {PublicKey} [params.vaultLpMint] - Required when updating management fees
|
|
464
|
-
* @returns {Promise<TransactionInstruction>} Transaction instruction for updating the vault config
|
|
465
|
-
*
|
|
466
|
-
* @throws {Error} If the field requires LP mint but it's not provided
|
|
467
|
-
*
|
|
468
|
-
* @example Update max cap
|
|
469
|
-
* ```typescript
|
|
470
|
-
* const newMaxCap = new BN(20_000_000_000_000);
|
|
471
|
-
* const data = newMaxCap.toArrayLike(Buffer, "le", 8);
|
|
472
|
-
*
|
|
473
|
-
* const ix = await client.createUpdateVaultConfigIx(
|
|
474
|
-
* VaultConfigField.MaxCap,
|
|
475
|
-
* data,
|
|
476
|
-
* {
|
|
477
|
-
* vault: vaultPubkey,
|
|
478
|
-
* admin: adminPubkey
|
|
479
|
-
* }
|
|
480
|
-
* );
|
|
481
|
-
* ```
|
|
482
|
-
*
|
|
483
|
-
* @example Update manager management fee (requires LP mint)
|
|
484
|
-
* ```typescript
|
|
485
|
-
* const newManagerManagementFee = 1000; // 10%
|
|
486
|
-
* const data = Buffer.alloc(2);
|
|
487
|
-
* data.writeUInt16LE(newManagerManagementFee, 0);
|
|
488
|
-
*
|
|
489
|
-
* const vaultLpMint = client.findVaultLpMint(vaultPubkey);
|
|
490
|
-
*
|
|
491
|
-
* const ix = await client.createUpdateVaultConfigIx(
|
|
492
|
-
* VaultConfigField.ManagerManagementFee,
|
|
493
|
-
* data,
|
|
494
|
-
* {
|
|
495
|
-
* vault: vaultPubkey,
|
|
496
|
-
* admin: adminPubkey,
|
|
497
|
-
* vaultLpMint: vaultLpMint
|
|
498
|
-
* }
|
|
499
|
-
* );
|
|
500
|
-
* ```
|
|
501
|
-
*
|
|
502
|
-
* @example Update manager (requires Pubkey)
|
|
503
|
-
* ```typescript
|
|
504
|
-
* const newManager = new PublicKey('...');
|
|
505
|
-
* const data = newManager.toBuffer();
|
|
506
|
-
*
|
|
507
|
-
* const ix = await client.createUpdateVaultConfigIx(
|
|
508
|
-
* VaultConfigField.Manager,
|
|
509
|
-
* data,
|
|
510
|
-
* {
|
|
511
|
-
* vault: vaultPubkey,
|
|
512
|
-
* admin: adminPubkey
|
|
513
|
-
* }
|
|
514
|
-
* );
|
|
515
|
-
* ```
|
|
516
|
-
*/
|
|
517
|
-
async createUpdateVaultConfigIx(field, data, { vault, admin, vaultLpMint, }) {
|
|
518
|
-
// Check if LP mint is required for this field
|
|
519
|
-
const requiresLpMint = field === types_1.VaultConfigField.ManagerManagementFee ||
|
|
520
|
-
field === types_1.VaultConfigField.AdminManagementFee;
|
|
521
|
-
if (requiresLpMint && !vaultLpMint) {
|
|
522
|
-
throw new Error(`LP mint is required when updating ${field}. Please provide vaultLpMint parameter.`);
|
|
523
|
-
}
|
|
524
|
-
// Build remaining accounts array
|
|
525
|
-
const remainingAccounts = [];
|
|
526
|
-
if (requiresLpMint && vaultLpMint) {
|
|
527
|
-
remainingAccounts.push({
|
|
528
|
-
pubkey: vaultLpMint,
|
|
529
|
-
isSigner: false,
|
|
530
|
-
isWritable: false,
|
|
531
|
-
});
|
|
532
|
-
}
|
|
533
|
-
const fieldToVariant = {
|
|
534
|
-
[types_1.VaultConfigField.MaxCap]: { maxCap: {} },
|
|
535
|
-
[types_1.VaultConfigField.StartAtTs]: { startAtTs: {} },
|
|
536
|
-
[types_1.VaultConfigField.LockedProfitDegradationDuration]: {
|
|
537
|
-
lockedProfitDegradationDuration: {},
|
|
538
|
-
},
|
|
539
|
-
[types_1.VaultConfigField.WithdrawalWaitingPeriod]: {
|
|
540
|
-
withdrawalWaitingPeriod: {},
|
|
541
|
-
},
|
|
542
|
-
[types_1.VaultConfigField.ManagerPerformanceFee]: { managerPerformanceFee: {} },
|
|
543
|
-
[types_1.VaultConfigField.AdminPerformanceFee]: { adminPerformanceFee: {} },
|
|
544
|
-
[types_1.VaultConfigField.ManagerManagementFee]: { managerManagementFee: {} },
|
|
545
|
-
[types_1.VaultConfigField.AdminManagementFee]: { adminManagementFee: {} },
|
|
546
|
-
[types_1.VaultConfigField.RedemptionFee]: { redemptionFee: {} },
|
|
547
|
-
[types_1.VaultConfigField.IssuanceFee]: { issuanceFee: {} },
|
|
548
|
-
[types_1.VaultConfigField.Manager]: { manager: {} },
|
|
549
|
-
[types_1.VaultConfigField.PendingAdmin]: { pendingAdmin: {} },
|
|
550
|
-
[types_1.VaultConfigField.DisabledOperations]: { disabledOperations: {} },
|
|
551
|
-
};
|
|
552
|
-
const fieldVariant = fieldToVariant[field];
|
|
553
|
-
if (!fieldVariant) {
|
|
554
|
-
throw new Error(`Unknown vault config field: ${field}`);
|
|
555
|
-
}
|
|
556
|
-
return await this.vaultProgram.methods
|
|
557
|
-
.updateVaultConfig(fieldVariant, data)
|
|
558
|
-
.accountsPartial({
|
|
559
|
-
admin,
|
|
560
|
-
vault,
|
|
561
|
-
})
|
|
562
|
-
.remainingAccounts(remainingAccounts)
|
|
563
|
-
.instruction();
|
|
564
|
-
}
|
|
565
|
-
/**
|
|
566
|
-
* Creates an instruction for the pending admin to accept the vault admin role
|
|
567
|
-
*
|
|
568
|
-
* @param {Object} params - Parameters for accepting vault admin
|
|
569
|
-
* @param {PublicKey} params.pendingAdmin - Public key of the pending admin (must be signer)
|
|
570
|
-
* @param {PublicKey} params.vault - Public key of the vault
|
|
571
|
-
* @returns {Promise<TransactionInstruction>} Transaction instruction for accepting vault admin
|
|
572
|
-
* @throws {Error} If instruction creation fails
|
|
573
|
-
*
|
|
574
|
-
* @example
|
|
575
|
-
* ```typescript
|
|
576
|
-
* const ix = await client.createAcceptVaultAdminIx({
|
|
577
|
-
* pendingAdmin: pendingAdminPubkey,
|
|
578
|
-
* vault: vaultPubkey,
|
|
579
|
-
* });
|
|
580
|
-
* ```
|
|
581
|
-
*/
|
|
582
|
-
async createAcceptVaultAdminIx({ pendingAdmin, vault, }) {
|
|
583
|
-
return await this.vaultProgram.methods
|
|
584
|
-
.acceptVaultAdmin()
|
|
585
|
-
.accountsStrict({
|
|
586
|
-
pendingAdmin,
|
|
587
|
-
vault,
|
|
588
|
-
})
|
|
589
|
-
.instruction();
|
|
590
|
-
}
|
|
591
|
-
/**
|
|
592
|
-
* Creates a deposit instruction for a vault
|
|
593
|
-
*
|
|
594
|
-
* @param {BN} amount - Amount of tokens to deposit
|
|
595
|
-
* @param {Object} params - Deposit parameters
|
|
596
|
-
* @param {PublicKey} params.userTransferAuthority - Public key of the user's transfer authority
|
|
597
|
-
* @param {PublicKey} params.vault - Public key of the vault
|
|
598
|
-
* @param {PublicKey} params.vaultAssetMint - Public key of the vault asset mint
|
|
599
|
-
* @param {PublicKey} params.assetTokenProgram - Public key of the asset token program
|
|
600
|
-
* @returns {Promise<TransactionInstruction>} Transaction instruction for depositing tokens
|
|
601
|
-
* @throws {Error} If instruction creation fails
|
|
602
|
-
*
|
|
603
|
-
* @example
|
|
604
|
-
* ```typescript
|
|
605
|
-
* const ix = await client.createDepositVaultIx(
|
|
606
|
-
* new BN('1000000000'),
|
|
607
|
-
* {
|
|
608
|
-
* userTransferAuthority: userPubkey,
|
|
609
|
-
* vault: vaultPubkey,
|
|
610
|
-
* vaultAssetMint: mintPubkey,
|
|
611
|
-
* assetTokenProgram: tokenProgramPubkey
|
|
612
|
-
* }
|
|
613
|
-
* );
|
|
614
|
-
* ```
|
|
615
|
-
*/
|
|
616
|
-
async createDepositVaultIx(amount, { userTransferAuthority, vault, vaultAssetMint, assetTokenProgram, }) {
|
|
617
|
-
return await this.vaultProgram.methods
|
|
618
|
-
.depositVault(amount)
|
|
619
|
-
.accounts({
|
|
620
|
-
userTransferAuthority,
|
|
621
|
-
vault,
|
|
622
|
-
vaultAssetMint,
|
|
623
|
-
assetTokenProgram,
|
|
624
|
-
})
|
|
625
|
-
.instruction();
|
|
626
|
-
}
|
|
627
|
-
/**
|
|
628
|
-
* Creates a request withdraw instruction for a vault
|
|
629
|
-
*
|
|
630
|
-
* @param {RequestWithdrawVaultArgs} requestWithdrawArgs - Arguments for withdrawing from the vault
|
|
631
|
-
* @param {BN} requestWithdrawArgs.amount - Amount of LP tokens to withdraw
|
|
632
|
-
* @param {boolean} requestWithdrawArgs.isAmountInLp - Whether the amount is in LP tokens
|
|
633
|
-
* @param {boolean} requestWithdrawArgs.isWithdrawAll - Whether to withdraw all assets
|
|
634
|
-
* @param {Object} params - Request withdraw parameters
|
|
635
|
-
* @param {PublicKey} params.payer - Public key of the payer
|
|
636
|
-
* @param {PublicKey} params.userTransferAuthority - Public key of the user authority
|
|
637
|
-
* @param {PublicKey} params.vault - Public key of the vault
|
|
638
|
-
* @returns {Promise<TransactionInstruction>} Transaction instruction for withdrawal
|
|
639
|
-
*
|
|
640
|
-
* @throws {Error} If the instruction creation fails
|
|
641
|
-
*
|
|
642
|
-
* @example
|
|
643
|
-
* const ix = await client.createRequestWithdrawVaultIx(
|
|
644
|
-
* {
|
|
645
|
-
* amount: new BN('1000000000'),
|
|
646
|
-
* isAmountInLp: true,
|
|
647
|
-
* isWithdrawAll: false,
|
|
648
|
-
* },
|
|
649
|
-
* {
|
|
650
|
-
* payer: payerPubkey,
|
|
651
|
-
* userTransferAuthority: userPubkey,
|
|
652
|
-
* vault: vaultPubkey,
|
|
653
|
-
* }
|
|
654
|
-
* );
|
|
655
|
-
*/
|
|
656
|
-
async createRequestWithdrawVaultIx({ amount, isAmountInLp, isWithdrawAll }, { payer, userTransferAuthority, vault, }) {
|
|
657
|
-
return await this.vaultProgram.methods
|
|
658
|
-
.requestWithdrawVault(amount, isAmountInLp, isWithdrawAll)
|
|
659
|
-
.accounts({
|
|
660
|
-
payer,
|
|
661
|
-
userTransferAuthority,
|
|
662
|
-
vault,
|
|
663
|
-
})
|
|
664
|
-
.instruction();
|
|
665
|
-
}
|
|
666
|
-
/**
|
|
667
|
-
* Creates a cancel withdraw instruction for a vault
|
|
668
|
-
*
|
|
669
|
-
* @param {Object} params - Cancel withdraw request parameters
|
|
670
|
-
* @param {PublicKey} params.userTransferAuthority - Public key of the user authority
|
|
671
|
-
* @param {PublicKey} params.vault - Public key of the vault
|
|
672
|
-
* @returns {Promise<TransactionInstruction>} Transaction instruction for withdrawal
|
|
673
|
-
*
|
|
674
|
-
* @throws {Error} If the instruction creation fails
|
|
675
|
-
*
|
|
676
|
-
* @example
|
|
677
|
-
* const ix = await client.createCancelRequestWithdrawVaultIx(
|
|
678
|
-
* {
|
|
679
|
-
* userTransferAuthority: userPubkey,
|
|
680
|
-
* vault: vaultPubkey,
|
|
681
|
-
* }
|
|
682
|
-
* );
|
|
683
|
-
*/
|
|
684
|
-
async createCancelRequestWithdrawVaultIx({ userTransferAuthority, vault, }) {
|
|
685
|
-
return await this.vaultProgram.methods
|
|
686
|
-
.cancelRequestWithdrawVault()
|
|
687
|
-
.accounts({
|
|
688
|
-
userTransferAuthority,
|
|
689
|
-
vault,
|
|
690
|
-
})
|
|
691
|
-
.instruction();
|
|
692
|
-
}
|
|
693
|
-
/**
|
|
694
|
-
* Creates a withdraw instruction for a vault
|
|
695
|
-
*
|
|
696
|
-
* @param {Object} params - Withdraw parameters
|
|
697
|
-
* @param {PublicKey} params.userTransferAuthority - Public key of the user authority
|
|
698
|
-
* @param {PublicKey} params.vault - Public key of the vault
|
|
699
|
-
* @param {PublicKey} params.vaultAssetMint - Public key of the vault asset mint
|
|
700
|
-
* @param {PublicKey} params.assetTokenProgram - Public key of the asset token program
|
|
701
|
-
* @returns {Promise<TransactionInstruction>} Transaction instruction for withdrawal
|
|
702
|
-
*
|
|
703
|
-
* @throws {Error} If the instruction creation fails
|
|
704
|
-
*
|
|
705
|
-
* @example
|
|
706
|
-
* const ix = await client.createWithdrawVaultIx(
|
|
707
|
-
* {
|
|
708
|
-
* userTransferAuthority: userPubkey,
|
|
709
|
-
* vault: vaultPubkey,
|
|
710
|
-
* vaultAssetMint: mintPubkey,
|
|
711
|
-
* assetTokenProgram: tokenProgramPubkey
|
|
712
|
-
* }
|
|
713
|
-
* );
|
|
714
|
-
*/
|
|
715
|
-
async createWithdrawVaultIx({ userTransferAuthority, vault, vaultAssetMint, assetTokenProgram, }) {
|
|
716
|
-
return await this.vaultProgram.methods
|
|
717
|
-
.withdrawVault()
|
|
718
|
-
.accounts({
|
|
719
|
-
userTransferAuthority,
|
|
720
|
-
vault,
|
|
721
|
-
vaultAssetMint,
|
|
722
|
-
assetTokenProgram,
|
|
723
|
-
})
|
|
724
|
-
.instruction();
|
|
725
|
-
}
|
|
726
|
-
/**
|
|
727
|
-
* Creates an instant withdraw instruction for a vault (no waiting period required)
|
|
728
|
-
*
|
|
729
|
-
* @param {InstantWithdrawVaultArgs} args - Instant withdrawal arguments
|
|
730
|
-
* @param {BN} args.amount - Amount to withdraw (in LP tokens or asset, depending on isAmountInLp)
|
|
731
|
-
* @param {boolean} args.isAmountInLp - Whether the amount is denominated in LP tokens
|
|
732
|
-
* @param {boolean} args.isWithdrawAll - Whether to withdraw all user's LP tokens
|
|
733
|
-
* @param {Object} params - Instant withdraw parameters
|
|
734
|
-
* @param {PublicKey} params.userTransferAuthority - Public key of the user's transfer authority
|
|
735
|
-
* @param {PublicKey} params.vault - Public key of the vault
|
|
736
|
-
* @param {PublicKey} params.vaultAssetMint - Public key of the vault asset mint
|
|
737
|
-
* @param {PublicKey} params.assetTokenProgram - Public key of the asset token program
|
|
738
|
-
* @returns {Promise<TransactionInstruction>} Transaction instruction for instant withdrawal
|
|
739
|
-
*
|
|
740
|
-
* @throws {Error} If the vault's withdrawal waiting period is not zero
|
|
741
|
-
*
|
|
742
|
-
* @example
|
|
743
|
-
* ```typescript
|
|
744
|
-
* const ix = await client.createInstantWithdrawVaultIx(
|
|
745
|
-
* {
|
|
746
|
-
* amount: new BN('1000000000'),
|
|
747
|
-
* isAmountInLp: true,
|
|
748
|
-
* isWithdrawAll: false,
|
|
749
|
-
* },
|
|
750
|
-
* {
|
|
751
|
-
* userTransferAuthority: userPubkey,
|
|
752
|
-
* vault: vaultPubkey,
|
|
753
|
-
* vaultAssetMint: mintPubkey,
|
|
754
|
-
* assetTokenProgram: tokenProgramPubkey,
|
|
755
|
-
* }
|
|
756
|
-
* );
|
|
757
|
-
* ```
|
|
758
|
-
*/
|
|
759
|
-
async createInstantWithdrawVaultIx({ amount, isAmountInLp, isWithdrawAll }, { userTransferAuthority, vault, vaultAssetMint, assetTokenProgram, }) {
|
|
760
|
-
return await this.vaultProgram.methods
|
|
761
|
-
.instantWithdrawVault(amount, isAmountInLp, isWithdrawAll)
|
|
762
|
-
.accounts({
|
|
763
|
-
userTransferAuthority,
|
|
764
|
-
vault,
|
|
765
|
-
vaultAssetMint,
|
|
766
|
-
assetTokenProgram,
|
|
767
|
-
})
|
|
768
|
-
.instruction();
|
|
769
|
-
}
|
|
770
|
-
// --------------------------------------- Strategy Instructions
|
|
771
|
-
/**
|
|
772
|
-
* Creates an instruction to add an adaptor to a vault
|
|
773
|
-
* @param {Object} params - Parameters for adding adaptor to vault
|
|
774
|
-
* @param {PublicKey} params.vault - Public key of the vault
|
|
775
|
-
* @param {PublicKey} params.payer - Public key of the payer
|
|
776
|
-
* @param {PublicKey} params.admin - Public key of the admin
|
|
777
|
-
* @param {PublicKey} params.adaptorProgram - Public key of the adaptor program
|
|
778
|
-
* @returns {Promise<TransactionInstruction>} Transaction instruction for adding adaptor to vault
|
|
779
|
-
*
|
|
780
|
-
* @throws {Error} If the instruction creation fails
|
|
781
|
-
*
|
|
782
|
-
* @example
|
|
783
|
-
* ```typescript
|
|
784
|
-
* const ix = await client.createAddAdaptorIx({
|
|
785
|
-
* vault: vaultPubkey,
|
|
786
|
-
* payer: payerPubkey,
|
|
787
|
-
* admin: adminPubkey,
|
|
788
|
-
* adaptorProgram: adaptorProgramPubkey
|
|
789
|
-
* });
|
|
790
|
-
* ```
|
|
791
|
-
*/
|
|
792
|
-
async createAddAdaptorIx({ vault, payer, admin, adaptorProgram, }) {
|
|
793
|
-
return await this.vaultProgram.methods
|
|
794
|
-
.addAdaptor()
|
|
795
|
-
.accountsPartial({
|
|
796
|
-
payer,
|
|
797
|
-
admin,
|
|
798
|
-
vault,
|
|
799
|
-
adaptorProgram,
|
|
800
|
-
})
|
|
801
|
-
.instruction();
|
|
802
|
-
}
|
|
803
|
-
/**
|
|
804
|
-
* Creates an instruction to initialize a strategy to a vault
|
|
805
|
-
* @param {InitializeStrategyArgs} initArgs - Arguments for strategy initialization
|
|
806
|
-
* @param {Buffer | null} [initArgs.instructionDiscriminator] - Optional discriminator for the instruction
|
|
807
|
-
* @param {Buffer | null} [initArgs.additionalArgs] - Optional additional arguments for the instruction
|
|
808
|
-
* @param {Object} params - Parameters for initializing strategy to vault
|
|
809
|
-
* @param {PublicKey} params.payer - Public key of the payer
|
|
810
|
-
* @param {PublicKey} params.vault - Public key of the vault
|
|
811
|
-
* @param {PublicKey} params.manager - Public key of the manager
|
|
812
|
-
* @param {PublicKey} params.strategy - Public key of the strategy
|
|
813
|
-
* @param {PublicKey} params.adaptorProgram - Public key of the adaptor program
|
|
814
|
-
* @param {Array<{ pubkey: PublicKey, isSigner: boolean, isWritable: boolean }>} params.remainingAccounts - Remaining accounts for the instruction
|
|
815
|
-
* @returns {Promise<TransactionInstruction>} Transaction instruction for initializing strategy to vault
|
|
816
|
-
* @throws {Error} If the instruction creation fails
|
|
817
|
-
*
|
|
818
|
-
* @example
|
|
819
|
-
* ```typescript
|
|
820
|
-
* const ix = await client.createInitializeStrategyIx(
|
|
821
|
-
* {
|
|
822
|
-
* instructionDiscriminator: Buffer.from('...'), // optional
|
|
823
|
-
* additionalArgs: Buffer.from('...') // optional
|
|
824
|
-
* },
|
|
825
|
-
* {
|
|
826
|
-
* payer: payerPubkey,
|
|
827
|
-
* vault: vaultPubkey,
|
|
828
|
-
* manager: managerPubkey,
|
|
829
|
-
* strategy: strategyPubkey,
|
|
830
|
-
* adaptorProgram: adaptorProgramPubkey,
|
|
831
|
-
* remainingAccounts: []
|
|
832
|
-
* }
|
|
833
|
-
* );
|
|
834
|
-
* ```
|
|
835
|
-
*/
|
|
836
|
-
async createInitializeStrategyIx({ instructionDiscriminator = null, additionalArgs = null, }, { payer, vault, manager, strategy, adaptorProgram, remainingAccounts, }) {
|
|
837
|
-
return await this.vaultProgram.methods
|
|
838
|
-
.initializeStrategy(instructionDiscriminator ?? null, additionalArgs ?? null)
|
|
839
|
-
.accounts({
|
|
840
|
-
payer,
|
|
841
|
-
vault,
|
|
842
|
-
manager,
|
|
843
|
-
strategy,
|
|
844
|
-
adaptorProgram,
|
|
845
|
-
})
|
|
846
|
-
.remainingAccounts(remainingAccounts)
|
|
847
|
-
.instruction();
|
|
848
|
-
}
|
|
849
|
-
/**
|
|
850
|
-
* Creates an instruction to deposit assets into a strategy
|
|
851
|
-
*
|
|
852
|
-
* @param {DepositStrategyArgs} depositArgs - Deposit arguments
|
|
853
|
-
* @param {BN} depositArgs.depositAmount - Amount of assets to deposit
|
|
854
|
-
* @param {Buffer | null} [depositArgs.instructionDiscriminator] - Optional discriminator for the instruction
|
|
855
|
-
* @param {Buffer | null} [depositArgs.additionalArgs] - Optional additional arguments for the instruction
|
|
856
|
-
* @param {Object} params - Strategy deposit parameters
|
|
857
|
-
* @param {PublicKey} params.manager - Public key of the manager
|
|
858
|
-
* @param {PublicKey} params.vault - Public key of the vault
|
|
859
|
-
* @param {PublicKey} params.vaultAssetMint - Public key of the vault asset mint
|
|
860
|
-
* @param {PublicKey} params.strategy - Public key of the strategy
|
|
861
|
-
* @param {PublicKey} params.assetTokenProgram - Public key of the asset token program
|
|
862
|
-
* @param {PublicKey} params.adaptorProgram - Public key of the adaptor program
|
|
863
|
-
* @param {Array<{ pubkey: PublicKey, isSigner: boolean, isWritable: boolean }>} params.remainingAccounts - Remaining accounts for the instruction
|
|
864
|
-
* @returns {Promise<TransactionInstruction>} Transaction instruction for depositing assets into strategy
|
|
865
|
-
* @throws {Error} If the instruction creation fails
|
|
866
|
-
*
|
|
867
|
-
* @example
|
|
868
|
-
* ```typescript
|
|
869
|
-
* const ix = await client.createDepositStrategyIx(
|
|
870
|
-
* {
|
|
871
|
-
* depositAmount: new BN('1000000000'),
|
|
872
|
-
* instructionDiscriminator: Buffer.from('...'),
|
|
873
|
-
* additionalArgs: Buffer.from('...')
|
|
874
|
-
* },
|
|
875
|
-
* {
|
|
876
|
-
* manager: managerPubkey,
|
|
877
|
-
* vault: vaultPubkey,
|
|
878
|
-
* vaultAssetMint: mintPubkey,
|
|
879
|
-
* strategy: strategyPubkey,
|
|
880
|
-
* assetTokenProgram: tokenProgramPubkey,
|
|
881
|
-
* adaptorProgram: adaptorProgramPubkey,
|
|
882
|
-
* remainingAccounts: []
|
|
883
|
-
* }
|
|
884
|
-
* );
|
|
885
|
-
* ```
|
|
886
|
-
*/
|
|
887
|
-
async createDepositStrategyIx({ depositAmount, instructionDiscriminator = null, additionalArgs = null, }, { manager, vault, vaultAssetMint, strategy, assetTokenProgram, adaptorProgram, remainingAccounts, }) {
|
|
888
|
-
return await this.vaultProgram.methods
|
|
889
|
-
.depositStrategy(depositAmount, instructionDiscriminator, additionalArgs)
|
|
890
|
-
.accounts({
|
|
891
|
-
manager,
|
|
892
|
-
vault,
|
|
893
|
-
vaultAssetMint,
|
|
894
|
-
adaptorProgram,
|
|
895
|
-
strategy,
|
|
896
|
-
assetTokenProgram,
|
|
897
|
-
})
|
|
898
|
-
.remainingAccounts(remainingAccounts)
|
|
899
|
-
.instruction();
|
|
900
|
-
}
|
|
901
|
-
/**
|
|
902
|
-
* Creates an instruction to withdraw assets from a strategy
|
|
903
|
-
*
|
|
904
|
-
* @param {WithdrawStrategyArgs} withdrawArgs - Withdrawal arguments
|
|
905
|
-
* @param {BN} withdrawArgs.withdrawAmount - Amount of assets to withdraw
|
|
906
|
-
* @param {Buffer | null} [withdrawArgs.instructionDiscriminator] - Optional discriminator for the instruction
|
|
907
|
-
* @param {Buffer | null} [withdrawArgs.additionalArgs] - Optional additional arguments for the instruction
|
|
908
|
-
* @param {Object} params - Strategy withdrawal parameters
|
|
909
|
-
* @param {PublicKey} params.vault - Public key of the vault
|
|
910
|
-
* @param {PublicKey} params.vaultAssetMint - Public key of the vault asset mint
|
|
911
|
-
* @param {PublicKey} params.strategy - Public key of the strategy
|
|
912
|
-
* @param {PublicKey} params.assetTokenProgram - Public key of the asset token program
|
|
913
|
-
* @param {PublicKey} params.adaptorProgram - Public key of the adaptor program
|
|
914
|
-
* @param {Array<{ pubkey: PublicKey, isSigner: boolean, isWritable: boolean }>} params.remainingAccounts - Remaining accounts for the instruction
|
|
915
|
-
* @returns {Promise<TransactionInstruction>} Transaction instruction for withdrawing assets from strategy
|
|
916
|
-
* @throws {Error} If the instruction creation fails
|
|
917
|
-
*
|
|
918
|
-
* @example
|
|
919
|
-
* ```typescript
|
|
920
|
-
* const ix = await client.createWithdrawStrategyIx(
|
|
921
|
-
* {
|
|
922
|
-
* withdrawAmount: new BN('1000000000'),
|
|
923
|
-
* instructionDiscriminator: Buffer.from('...'),
|
|
924
|
-
* additionalArgs: Buffer.from('...')
|
|
925
|
-
* },
|
|
926
|
-
* {
|
|
927
|
-
* vault: vaultPubkey,
|
|
928
|
-
* vaultAssetMint: mintPubkey,
|
|
929
|
-
* strategy: strategyPubkey,
|
|
930
|
-
* assetTokenProgram: tokenProgramPubkey,
|
|
931
|
-
* adaptorProgram: adaptorProgramPubkey,
|
|
932
|
-
* remainingAccounts: []
|
|
933
|
-
* }
|
|
934
|
-
* );
|
|
935
|
-
* ```
|
|
936
|
-
*/
|
|
937
|
-
async createWithdrawStrategyIx({ withdrawAmount, instructionDiscriminator = null, additionalArgs = null, }, { manager, vault, vaultAssetMint, strategy, assetTokenProgram, adaptorProgram, remainingAccounts, }) {
|
|
938
|
-
return await this.vaultProgram.methods
|
|
939
|
-
.withdrawStrategy(withdrawAmount, instructionDiscriminator, additionalArgs)
|
|
940
|
-
.accounts({
|
|
941
|
-
manager,
|
|
942
|
-
vault,
|
|
943
|
-
vaultAssetMint,
|
|
944
|
-
adaptorProgram,
|
|
945
|
-
strategy,
|
|
946
|
-
assetTokenProgram,
|
|
947
|
-
})
|
|
948
|
-
.remainingAccounts(remainingAccounts)
|
|
949
|
-
.instruction();
|
|
950
|
-
}
|
|
951
|
-
/**
|
|
952
|
-
* Creates an instruction to remove a strategy from a vault
|
|
953
|
-
* @param {Object} params - Parameters for removing strategy
|
|
954
|
-
* @param {PublicKey} params.vault - Public key of the vault
|
|
955
|
-
* @param {PublicKey} params.admin - Public key of the admin
|
|
956
|
-
* @param {PublicKey} params.adaptorProgram - Public key of the adaptor program
|
|
957
|
-
* @returns {Promise<TransactionInstruction>} Transaction instruction for removing adaptor from vault
|
|
958
|
-
* @throws {Error} If instruction creation fails
|
|
959
|
-
*
|
|
960
|
-
* @example
|
|
961
|
-
* ```typescript
|
|
962
|
-
* const ix = await client.createRemoveAdaptorIx({
|
|
963
|
-
* vault: vaultPubkey,
|
|
964
|
-
* admin: adminPubkey,
|
|
965
|
-
* adaptorProgram: adaptorProgramPubkey
|
|
966
|
-
* });
|
|
967
|
-
* ```
|
|
968
|
-
*/
|
|
969
|
-
async createRemoveAdaptorIx({ vault, admin, adaptorProgram, }) {
|
|
970
|
-
return await this.vaultProgram.methods
|
|
971
|
-
.removeAdaptor()
|
|
972
|
-
.accountsPartial({
|
|
973
|
-
vault,
|
|
974
|
-
admin,
|
|
975
|
-
adaptorProgram,
|
|
976
|
-
})
|
|
977
|
-
.instruction();
|
|
978
|
-
}
|
|
979
|
-
/**
|
|
980
|
-
* Creates an instruction to initialize a direct withdraw strategy
|
|
981
|
-
* @param {InitializeDirectWithdrawStrategyArgs} initArgs - Arguments for initializing direct withdraw strategy
|
|
982
|
-
* @param {Buffer | null} initArgs.instructionDiscriminator - Optional discriminator for the instruction
|
|
983
|
-
* @param {Buffer | null} initArgs.additionalArgs - Optional additional arguments for the instruction
|
|
984
|
-
* @param {boolean} initArgs.allowUserArgs - Whether to allow user arguments
|
|
985
|
-
* @param {Object} params - Parameters for initializing direct withdraw strategy
|
|
986
|
-
* @param {PublicKey} params.payer - Public key of the payer
|
|
987
|
-
* @param {PublicKey} params.admin - Public key of the admin
|
|
988
|
-
* @param {PublicKey} params.vault - Public key of the vault
|
|
989
|
-
* @param {PublicKey} params.strategy - Public key of the strategy
|
|
990
|
-
* @param {PublicKey} params.adaptorProgram - Public key of the adaptor program
|
|
991
|
-
* @returns {Promise<TransactionInstruction>} Transaction instruction for initializing direct withdraw strategy
|
|
992
|
-
* @throws {Error} If instruction creation fails
|
|
993
|
-
*
|
|
994
|
-
* @example
|
|
995
|
-
* ```typescript
|
|
996
|
-
* const ix = await client.createInitializeDirectWithdrawStrategyIx(
|
|
997
|
-
* {
|
|
998
|
-
* instructionDiscriminator: Buffer.from('...'),
|
|
999
|
-
* additionalArgs: Buffer.from('...'),
|
|
1000
|
-
* allowUserArgs: true
|
|
1001
|
-
* },
|
|
1002
|
-
* {
|
|
1003
|
-
* payer: payerPubkey,
|
|
1004
|
-
* admin: adminPubkey,
|
|
1005
|
-
* vault: vaultPubkey,
|
|
1006
|
-
* strategy: strategyPubkey,
|
|
1007
|
-
* adaptorProgram: adaptorProgramPubkey
|
|
1008
|
-
* }
|
|
1009
|
-
* );
|
|
1010
|
-
* ```
|
|
1011
|
-
*/
|
|
1012
|
-
async createInitializeDirectWithdrawStrategyIx({ instructionDiscriminator = null, additionalArgs = null, allowUserArgs = false, }, { payer, admin, vault, strategy, adaptorProgram, }) {
|
|
1013
|
-
return await this.vaultProgram.methods
|
|
1014
|
-
.initializeDirectWithdrawStrategy(instructionDiscriminator, additionalArgs, allowUserArgs)
|
|
1015
|
-
.accountsPartial({
|
|
1016
|
-
payer,
|
|
1017
|
-
admin,
|
|
1018
|
-
vault,
|
|
1019
|
-
strategy,
|
|
1020
|
-
adaptorProgram,
|
|
1021
|
-
})
|
|
1022
|
-
.instruction();
|
|
1023
|
-
}
|
|
1024
|
-
/**
|
|
1025
|
-
* Creates an instruction to withdraw assets from a direct withdraw strategy
|
|
1026
|
-
* @param {Object} directWithdrawArgs - Withdrawal arguments
|
|
1027
|
-
* @param {Buffer | null} [directWithdrawArgs.userArgs] - Optional user arguments for the instruction
|
|
1028
|
-
* @param {Object} params - Parameters for withdrawing assets from direct withdraw strategy
|
|
1029
|
-
* @param {PublicKey} params.user - Public key of the user
|
|
1030
|
-
* @param {PublicKey} params.vault - Public key of the vault
|
|
1031
|
-
* @param {PublicKey} params.strategy - Public key of the strategy
|
|
1032
|
-
* @param {PublicKey} params.vaultAssetMint - Public key of the vault asset mint
|
|
1033
|
-
* @param {PublicKey} params.assetTokenProgram - Public key of the asset token program
|
|
1034
|
-
* @param {PublicKey} params.adaptorProgram - Public key of the adaptor program
|
|
1035
|
-
* @param {Array<{ pubkey: PublicKey, isSigner: boolean, isWritable: boolean }>} params.remainingAccounts - Remaining accounts for the instruction
|
|
1036
|
-
* @returns {Promise<TransactionInstruction>} Transaction instruction for withdrawing assets from direct withdraw strategy
|
|
1037
|
-
* @throws {Error} If instruction creation fails
|
|
1038
|
-
*
|
|
1039
|
-
* @example
|
|
1040
|
-
* ```typescript
|
|
1041
|
-
* const ix = await client.createDirectWithdrawStrategyIx(
|
|
1042
|
-
* {
|
|
1043
|
-
* userArgs: Buffer.from('...')
|
|
1044
|
-
* },
|
|
1045
|
-
* {
|
|
1046
|
-
* user: userPubkey,
|
|
1047
|
-
* vault: vaultPubkey,
|
|
1048
|
-
* strategy: strategyPubkey,
|
|
1049
|
-
* vaultAssetMint: mintPubkey,
|
|
1050
|
-
* assetTokenProgram: tokenProgramPubkey,
|
|
1051
|
-
* adaptorProgram: adaptorProgramPubkey,
|
|
1052
|
-
* remainingAccounts: []
|
|
1053
|
-
* }
|
|
1054
|
-
* );
|
|
1055
|
-
* ```
|
|
1056
|
-
*/
|
|
1057
|
-
async createDirectWithdrawStrategyIx({ userArgs = null }, { user, vault, strategy, vaultAssetMint, assetTokenProgram, adaptorProgram, remainingAccounts, }) {
|
|
1058
|
-
return await this.vaultProgram.methods
|
|
1059
|
-
.directWithdrawStrategy(userArgs)
|
|
1060
|
-
.accounts({
|
|
1061
|
-
userTransferAuthority: user,
|
|
1062
|
-
strategy,
|
|
1063
|
-
adaptorProgram,
|
|
1064
|
-
vault,
|
|
1065
|
-
vaultAssetMint,
|
|
1066
|
-
assetTokenProgram,
|
|
1067
|
-
})
|
|
1068
|
-
.remainingAccounts(remainingAccounts)
|
|
1069
|
-
.instruction();
|
|
1070
|
-
}
|
|
1071
|
-
/**
|
|
1072
|
-
* Creates an instruction to withdraw assets from a direct withdraw strategy with slippage tolerance
|
|
1073
|
-
*
|
|
1074
|
-
* @param {Object} directWithdrawArgs - Withdrawal arguments
|
|
1075
|
-
* @param {Buffer | null} [directWithdrawArgs.userArgs] - Optional user arguments for the instruction
|
|
1076
|
-
* @param {BN} directWithdrawArgs.tolerance - Slippage tolerance in asset amount (max difference between requested and actual)
|
|
1077
|
-
* @param {Object} params - Parameters for withdrawing assets from direct withdraw strategy
|
|
1078
|
-
* @param {PublicKey} params.user - Public key of the user
|
|
1079
|
-
* @param {PublicKey} params.vault - Public key of the vault
|
|
1080
|
-
* @param {PublicKey} params.strategy - Public key of the strategy
|
|
1081
|
-
* @param {PublicKey} params.vaultAssetMint - Public key of the vault asset mint
|
|
1082
|
-
* @param {PublicKey} params.assetTokenProgram - Public key of the asset token program
|
|
1083
|
-
* @param {PublicKey} [params.adaptorProgram] - Public key of the adaptor program (defaults to lending adaptor)
|
|
1084
|
-
* @param {Array<{ pubkey: PublicKey, isSigner: boolean, isWritable: boolean }>} params.remainingAccounts - Remaining accounts for the instruction
|
|
1085
|
-
* @returns {Promise<TransactionInstruction>} Transaction instruction for direct withdraw with tolerance
|
|
1086
|
-
* @throws {Error} If instruction creation fails
|
|
1087
|
-
*
|
|
1088
|
-
* @example
|
|
1089
|
-
* ```typescript
|
|
1090
|
-
* const ix = await client.createDirectWithdrawStrategyWithToleranceIx(
|
|
1091
|
-
* {
|
|
1092
|
-
* userArgs: Buffer.from('...'),
|
|
1093
|
-
* tolerance: new BN(1000),
|
|
1094
|
-
* },
|
|
1095
|
-
* {
|
|
1096
|
-
* user: userPubkey,
|
|
1097
|
-
* vault: vaultPubkey,
|
|
1098
|
-
* strategy: strategyPubkey,
|
|
1099
|
-
* vaultAssetMint: mintPubkey,
|
|
1100
|
-
* assetTokenProgram: tokenProgramPubkey,
|
|
1101
|
-
* remainingAccounts: [],
|
|
1102
|
-
* }
|
|
1103
|
-
* );
|
|
1104
|
-
* ```
|
|
1105
|
-
*/
|
|
1106
|
-
async createDirectWithdrawStrategyWithToleranceIx({ userArgs = null, tolerance }, { user, vault, strategy, vaultAssetMint, assetTokenProgram, adaptorProgram, remainingAccounts, }) {
|
|
1107
|
-
return await this.vaultProgram.methods
|
|
1108
|
-
.directWithdrawStrategyWithTolerance(userArgs, tolerance)
|
|
1109
|
-
.accounts({
|
|
1110
|
-
userTransferAuthority: user,
|
|
1111
|
-
strategy,
|
|
1112
|
-
adaptorProgram,
|
|
1113
|
-
vault,
|
|
1114
|
-
vaultAssetMint,
|
|
1115
|
-
assetTokenProgram,
|
|
1116
|
-
})
|
|
1117
|
-
.remainingAccounts(remainingAccounts)
|
|
1118
|
-
.instruction();
|
|
1119
|
-
}
|
|
1120
|
-
/**
|
|
1121
|
-
* Creates an instant withdraw instruction for a strategy (no waiting period, withdraws directly from strategy)
|
|
1122
|
-
*
|
|
1123
|
-
* @param {InstantWithdrawStrategyArgs} args - Instant withdrawal arguments
|
|
1124
|
-
* @param {BN} args.amount - Amount to withdraw (in LP tokens or asset, depending on isAmountInLp)
|
|
1125
|
-
* @param {boolean} args.isAmountInLp - Whether the amount is denominated in LP tokens
|
|
1126
|
-
* @param {boolean} args.isWithdrawAll - Whether to withdraw all user's LP tokens
|
|
1127
|
-
* @param {Buffer | null} [args.userArgs] - Optional user arguments passed to the adaptor
|
|
1128
|
-
* @param {Object} params - Instant withdraw strategy parameters
|
|
1129
|
-
* @param {PublicKey} params.userTransferAuthority - Public key of the user's transfer authority
|
|
1130
|
-
* @param {PublicKey} params.vault - Public key of the vault
|
|
1131
|
-
* @param {PublicKey} params.strategy - Public key of the strategy
|
|
1132
|
-
* @param {PublicKey} params.vaultAssetMint - Public key of the vault asset mint
|
|
1133
|
-
* @param {PublicKey} params.assetTokenProgram - Public key of the asset token program
|
|
1134
|
-
* @param {PublicKey} [params.adaptorProgram] - Public key of the adaptor program (defaults to lending adaptor)
|
|
1135
|
-
* @param {Array<{ pubkey: PublicKey, isSigner: boolean, isWritable: boolean }>} params.remainingAccounts - Remaining accounts for the instruction
|
|
1136
|
-
* @returns {Promise<TransactionInstruction>} Transaction instruction for instant strategy withdrawal
|
|
1137
|
-
* @throws {Error} If the vault's withdrawal waiting period is not zero
|
|
1138
|
-
*
|
|
1139
|
-
* @example
|
|
1140
|
-
* ```typescript
|
|
1141
|
-
* const ix = await client.createInstantWithdrawStrategyIx(
|
|
1142
|
-
* {
|
|
1143
|
-
* amount: new BN('1000000000'),
|
|
1144
|
-
* isAmountInLp: true,
|
|
1145
|
-
* isWithdrawAll: false,
|
|
1146
|
-
* },
|
|
1147
|
-
* {
|
|
1148
|
-
* userTransferAuthority: userPubkey,
|
|
1149
|
-
* vault: vaultPubkey,
|
|
1150
|
-
* strategy: strategyPubkey,
|
|
1151
|
-
* vaultAssetMint: mintPubkey,
|
|
1152
|
-
* assetTokenProgram: tokenProgramPubkey,
|
|
1153
|
-
* remainingAccounts: [],
|
|
1154
|
-
* }
|
|
1155
|
-
* );
|
|
1156
|
-
* ```
|
|
1157
|
-
*/
|
|
1158
|
-
async createInstantWithdrawStrategyIx({ amount, isAmountInLp, isWithdrawAll, userArgs = null, }, { userTransferAuthority, vault, strategy, vaultAssetMint, assetTokenProgram, adaptorProgram, remainingAccounts, }) {
|
|
1159
|
-
return await this.vaultProgram.methods
|
|
1160
|
-
.instantWithdrawStrategy(amount, isAmountInLp, isWithdrawAll, userArgs ?? null)
|
|
1161
|
-
.accounts({
|
|
1162
|
-
userTransferAuthority,
|
|
1163
|
-
vault,
|
|
1164
|
-
strategy,
|
|
1165
|
-
vaultAssetMint,
|
|
1166
|
-
assetTokenProgram,
|
|
1167
|
-
adaptorProgram,
|
|
1168
|
-
})
|
|
1169
|
-
.remainingAccounts(remainingAccounts)
|
|
1170
|
-
.instruction();
|
|
1171
|
-
}
|
|
1172
|
-
/**
|
|
1173
|
-
* Creates an instant withdraw instruction for a strategy with slippage tolerance
|
|
1174
|
-
*
|
|
1175
|
-
* @param {InstantWithdrawStrategyArgs & { tolerance: BN }} args - Instant withdrawal arguments with tolerance
|
|
1176
|
-
* @param {BN} args.amount - Amount to withdraw (in LP tokens or asset, depending on isAmountInLp)
|
|
1177
|
-
* @param {boolean} args.isAmountInLp - Whether the amount is denominated in LP tokens
|
|
1178
|
-
* @param {boolean} args.isWithdrawAll - Whether to withdraw all user's LP tokens
|
|
1179
|
-
* @param {Buffer | null} [args.userArgs] - Optional user arguments passed to the adaptor
|
|
1180
|
-
* @param {BN} args.tolerance - Slippage tolerance in asset amount (max difference between requested and actual)
|
|
1181
|
-
* @param {Object} params - Instant withdraw strategy parameters
|
|
1182
|
-
* @param {PublicKey} params.userTransferAuthority - Public key of the user's transfer authority
|
|
1183
|
-
* @param {PublicKey} params.vault - Public key of the vault
|
|
1184
|
-
* @param {PublicKey} params.strategy - Public key of the strategy
|
|
1185
|
-
* @param {PublicKey} params.vaultAssetMint - Public key of the vault asset mint
|
|
1186
|
-
* @param {PublicKey} params.assetTokenProgram - Public key of the asset token program
|
|
1187
|
-
* @param {PublicKey} [params.adaptorProgram] - Public key of the adaptor program (defaults to lending adaptor)
|
|
1188
|
-
* @param {Array<{ pubkey: PublicKey, isSigner: boolean, isWritable: boolean }>} params.remainingAccounts - Remaining accounts for the instruction
|
|
1189
|
-
* @returns {Promise<TransactionInstruction>} Transaction instruction for instant strategy withdrawal with tolerance
|
|
1190
|
-
* @throws {Error} If the vault's withdrawal waiting period is not zero
|
|
1191
|
-
*
|
|
1192
|
-
* @example
|
|
1193
|
-
* ```typescript
|
|
1194
|
-
* const ix = await client.createInstantWithdrawStrategyWithToleranceIx(
|
|
1195
|
-
* {
|
|
1196
|
-
* amount: new BN('1000000000'),
|
|
1197
|
-
* isAmountInLp: true,
|
|
1198
|
-
* isWithdrawAll: false,
|
|
1199
|
-
* tolerance: new BN(1000),
|
|
1200
|
-
* },
|
|
1201
|
-
* {
|
|
1202
|
-
* userTransferAuthority: userPubkey,
|
|
1203
|
-
* vault: vaultPubkey,
|
|
1204
|
-
* strategy: strategyPubkey,
|
|
1205
|
-
* vaultAssetMint: mintPubkey,
|
|
1206
|
-
* assetTokenProgram: tokenProgramPubkey,
|
|
1207
|
-
* remainingAccounts: [],
|
|
1208
|
-
* }
|
|
1209
|
-
* );
|
|
1210
|
-
* ```
|
|
1211
|
-
*/
|
|
1212
|
-
async createInstantWithdrawStrategyWithToleranceIx({ amount, isAmountInLp, isWithdrawAll, userArgs = null, tolerance, }, { userTransferAuthority, vault, strategy, vaultAssetMint, assetTokenProgram, adaptorProgram, remainingAccounts, }) {
|
|
1213
|
-
return await this.vaultProgram.methods
|
|
1214
|
-
.instantWithdrawStrategyWithTolerance(amount, isAmountInLp, isWithdrawAll, userArgs ?? null, tolerance)
|
|
1215
|
-
.accounts({
|
|
1216
|
-
userTransferAuthority,
|
|
1217
|
-
vault,
|
|
1218
|
-
strategy,
|
|
1219
|
-
vaultAssetMint,
|
|
1220
|
-
assetTokenProgram,
|
|
1221
|
-
adaptorProgram,
|
|
1222
|
-
})
|
|
1223
|
-
.remainingAccounts(remainingAccounts)
|
|
1224
|
-
.instruction();
|
|
1225
|
-
}
|
|
1226
|
-
/**
|
|
1227
|
-
* Creates an instruction to harvest fees from a vault
|
|
1228
|
-
* @param {Object} params - Parameters for harvesting fees
|
|
1229
|
-
* @param {PublicKey} params.harvester - Public key of the harvester
|
|
1230
|
-
* @param {PublicKey} params.vaultManager - Public key of the vault manager
|
|
1231
|
-
* @param {PublicKey} params.vaultAdmin - Public key of the vault admin
|
|
1232
|
-
* @param {PublicKey} params.protocolAdmin - Public key of the protocol admin
|
|
1233
|
-
* @param {PublicKey} params.vault - Public key of the vault
|
|
1234
|
-
* @returns {Promise<TransactionInstruction>} Transaction instruction for harvesting fees
|
|
1235
|
-
* @throws {Error} If instruction creation fails
|
|
1236
|
-
*
|
|
1237
|
-
* @example
|
|
1238
|
-
* ```typescript
|
|
1239
|
-
* const ix = await client.createHarvestFeeIx({
|
|
1240
|
-
* harvester: harvesterPubkey,
|
|
1241
|
-
* vaultManager: vaultManagerPubkey,
|
|
1242
|
-
* vaultAdmin: vaultAdminPubkey,
|
|
1243
|
-
* protocolAdmin: protocolAdminPubkey,
|
|
1244
|
-
* vault: vaultPubkey,
|
|
1245
|
-
* });
|
|
1246
|
-
* ```
|
|
1247
|
-
*/
|
|
1248
|
-
async createHarvestFeeIx({ harvester, vaultManager, vaultAdmin, protocolAdmin, vault, }) {
|
|
1249
|
-
return await this.vaultProgram.methods
|
|
1250
|
-
.harvestFee()
|
|
1251
|
-
.accounts({
|
|
1252
|
-
harvester,
|
|
1253
|
-
vaultManager,
|
|
1254
|
-
vaultAdmin,
|
|
1255
|
-
vault,
|
|
1256
|
-
protocolAdmin,
|
|
1257
|
-
})
|
|
1258
|
-
.instruction();
|
|
1259
|
-
}
|
|
1260
|
-
/**
|
|
1261
|
-
* Creates an instruction to close a strategy
|
|
1262
|
-
* @param {Object} params - Parameters for closing strategy
|
|
1263
|
-
* @param {PublicKey} params.payer - Public key of the payer
|
|
1264
|
-
* @param {PublicKey} params.manager - Public key of the manager
|
|
1265
|
-
* @param {PublicKey} params.vault - Public key of the vault
|
|
1266
|
-
* @param {PublicKey} params.strategy - Public key of the strategy
|
|
1267
|
-
* @returns {Promise<TransactionInstruction>} Transaction instruction for closing strategy
|
|
1268
|
-
* @throws {Error} If instruction creation fails
|
|
1269
|
-
*
|
|
1270
|
-
* @example
|
|
1271
|
-
* ```typescript
|
|
1272
|
-
* const ix = await client.createCloseStrategyIx({
|
|
1273
|
-
* payer: payerPubkey,
|
|
1274
|
-
* manager: managerPubkey,
|
|
1275
|
-
* vault: vaultPubkey,
|
|
1276
|
-
* strategy: strategyPubkey,
|
|
1277
|
-
* });
|
|
1278
|
-
* ```
|
|
1279
|
-
*/
|
|
1280
|
-
async createCloseStrategyIx({ payer, manager, vault, strategy, }) {
|
|
1281
|
-
return await this.vaultProgram.methods
|
|
1282
|
-
.closeStrategy()
|
|
1283
|
-
.accounts({
|
|
1284
|
-
payer,
|
|
1285
|
-
manager,
|
|
1286
|
-
vault,
|
|
1287
|
-
strategy,
|
|
1288
|
-
})
|
|
1289
|
-
.instruction();
|
|
1290
|
-
}
|
|
1291
|
-
/**
|
|
1292
|
-
* Creates an instruction to calibrate the high water mark
|
|
1293
|
-
* @param {Object} params - Parameters for calibrating the high water mark
|
|
1294
|
-
* @param {PublicKey} params.vault - Public key of the vault
|
|
1295
|
-
* @param {PublicKey} params.admin - Public key of the admin
|
|
1296
|
-
* @returns {Promise<TransactionInstruction>} Transaction instruction for calibrating the high water mark
|
|
1297
|
-
* @throws {Error} If instruction creation fails
|
|
1298
|
-
*
|
|
1299
|
-
* @example
|
|
1300
|
-
* ```typescript
|
|
1301
|
-
* const ix = await client.createCalibrateHighWaterMarkIx({
|
|
1302
|
-
* vault: vaultPubkey,
|
|
1303
|
-
* admin: adminPubkey,
|
|
1304
|
-
* });
|
|
1305
|
-
* ```
|
|
1306
|
-
*/
|
|
1307
|
-
async createCalibrateHighWaterMarkIx({ vault, admin, }) {
|
|
1308
|
-
return await this.vaultProgram.methods
|
|
1309
|
-
.calibrateHighWaterMark()
|
|
1310
|
-
.accountsPartial({
|
|
1311
|
-
vault,
|
|
1312
|
-
admin,
|
|
1313
|
-
})
|
|
1314
|
-
.instruction();
|
|
1315
|
-
}
|
|
1316
|
-
/**
|
|
1317
|
-
* Creates an instruction to calibrate the high water mark without fee clawback (unsafe)
|
|
1318
|
-
* @param {Object} params - Parameters for calibrating the high water mark
|
|
1319
|
-
* @param {PublicKey} params.vault - Public key of the vault (must be whitelisted)
|
|
1320
|
-
* @param {PublicKey} params.admin - Public key of the admin
|
|
1321
|
-
* @returns {Promise<TransactionInstruction>} Transaction instruction for unsafe calibration
|
|
1322
|
-
* @throws {Error} If instruction creation fails or vault is not whitelisted
|
|
1323
|
-
*
|
|
1324
|
-
* @example
|
|
1325
|
-
* ```typescript
|
|
1326
|
-
* const ix = await client.createCalibrateHighWaterMarkUnsafeIx({
|
|
1327
|
-
* vault: vaultPubkey,
|
|
1328
|
-
* admin: adminPubkey,
|
|
1329
|
-
* });
|
|
1330
|
-
* ```
|
|
1331
|
-
*/
|
|
1332
|
-
async createCalibrateHighWaterMarkUnsafeIx({ vault, admin, }) {
|
|
1333
|
-
return await this.vaultProgram.methods
|
|
1334
|
-
.calibrateHighWaterMarkUnsafe()
|
|
1335
|
-
.accountsPartial({
|
|
1336
|
-
vault,
|
|
1337
|
-
admin,
|
|
1338
|
-
})
|
|
1339
|
-
.instruction();
|
|
1340
|
-
}
|
|
1341
|
-
/**
|
|
1342
|
-
* Creates an instruction to create LP metadata
|
|
1343
|
-
* @param {Object} createLpMetadataArgs - Parameters for creating LP metadata
|
|
1344
|
-
* @param {string} createLpMetadataArgs.name - Name of the LP
|
|
1345
|
-
* @param {string} createLpMetadataArgs.symbol - Symbol of the LP
|
|
1346
|
-
* @param {string} createLpMetadataArgs.uri - URI of the LP metadata
|
|
1347
|
-
* @param {Object} params - Parameters for creating LP metadata
|
|
1348
|
-
* @param {PublicKey} params.payer - Public key of the payer
|
|
1349
|
-
* @param {PublicKey} params.admin - Public key of the admin
|
|
1350
|
-
* @param {PublicKey} params.vault - Public key of the vault
|
|
1351
|
-
* @returns {Promise<TransactionInstruction>} Transaction instruction for creating LP metadata
|
|
1352
|
-
* @throws {Error} If instruction creation fails
|
|
1353
|
-
*
|
|
1354
|
-
* @example
|
|
1355
|
-
* ```typescript
|
|
1356
|
-
* const ix = await client.createCreateLpMetadataIx({
|
|
1357
|
-
* name: "My LP",
|
|
1358
|
-
* symbol: "MYLP",
|
|
1359
|
-
* uri: "https://mylp.com/metadata",
|
|
1360
|
-
* });
|
|
1361
|
-
* ```
|
|
1362
|
-
*/
|
|
1363
|
-
async createCreateLpMetadataIx({ name, symbol, uri, }, { payer, admin, vault, }) {
|
|
1364
|
-
const metadataAccount = this.findLpMetadataAccount(vault);
|
|
1365
|
-
return await this.vaultProgram.methods
|
|
1366
|
-
.createLpMetadata(name, symbol, uri)
|
|
1367
|
-
.accountsPartial({
|
|
1368
|
-
payer,
|
|
1369
|
-
vault,
|
|
1370
|
-
admin,
|
|
1371
|
-
metadataAccount,
|
|
1372
|
-
})
|
|
1373
|
-
.instruction();
|
|
1374
|
-
}
|
|
1375
|
-
/**
|
|
1376
|
-
* Creates an instruction to update per-vault protocol fees (admin-only, protocol level)
|
|
1377
|
-
*
|
|
1378
|
-
* @param {ProtocolFeeField} field - The protocol fee field to update
|
|
1379
|
-
* @param {number} feeBps - The new fee value in basis points
|
|
1380
|
-
* @param {Object} params - Parameters for updating the protocol fee
|
|
1381
|
-
* @param {PublicKey} params.admin - Public key of the protocol admin
|
|
1382
|
-
* @param {PublicKey} params.vault - Public key of the vault
|
|
1383
|
-
* @returns {Promise<TransactionInstruction>} Transaction instruction for updating the protocol fee
|
|
1384
|
-
*
|
|
1385
|
-
* @throws {Error} If the total fee (protocol + admin + manager) exceeds 10000 BPS
|
|
1386
|
-
*
|
|
1387
|
-
* @example
|
|
1388
|
-
* ```typescript
|
|
1389
|
-
* const ix = await client.createUpdateVaultProtocolFeeIx(
|
|
1390
|
-
* ProtocolFeeField.ProtocolPerformanceFee,
|
|
1391
|
-
* 500, // 5%
|
|
1392
|
-
* {
|
|
1393
|
-
* admin: protocolAdminPubkey,
|
|
1394
|
-
* vault: vaultPubkey,
|
|
1395
|
-
* }
|
|
1396
|
-
* );
|
|
1397
|
-
* ```
|
|
1398
|
-
*/
|
|
1399
|
-
async createUpdateVaultProtocolFeeIx(field, feeBps, { admin, vault, }) {
|
|
1400
|
-
const fieldToVariant = {
|
|
1401
|
-
[types_1.ProtocolFeeField.ProtocolPerformanceFee]: {
|
|
1402
|
-
protocolPerformanceFee: {},
|
|
1403
|
-
},
|
|
1404
|
-
[types_1.ProtocolFeeField.ProtocolManagementFee]: {
|
|
1405
|
-
protocolManagementFee: {},
|
|
1406
|
-
},
|
|
1407
|
-
};
|
|
1408
|
-
const fieldVariant = fieldToVariant[field];
|
|
1409
|
-
if (!fieldVariant) {
|
|
1410
|
-
throw new Error(`Unknown protocol fee field: ${field}`);
|
|
1411
|
-
}
|
|
1412
|
-
return await this.vaultProgram.methods
|
|
1413
|
-
.updateVaultProtocolFee(fieldVariant, feeBps)
|
|
1414
|
-
.accountsPartial({
|
|
1415
|
-
admin,
|
|
1416
|
-
vault,
|
|
1417
|
-
})
|
|
1418
|
-
.instruction();
|
|
1419
|
-
}
|
|
1420
|
-
// --------------------------------------- Account Fetching All
|
|
1421
|
-
/**
|
|
1422
|
-
* Fetches all strategy init receipt accounts
|
|
1423
|
-
* @returns Promise resolving to an array of strategy init receipt accounts
|
|
1424
|
-
*
|
|
1425
|
-
* @example
|
|
1426
|
-
* ```typescript
|
|
1427
|
-
* const strategyInitReceiptAccounts = await client.fetchAllStrategyInitReceiptAccounts();
|
|
1428
|
-
* ```
|
|
1429
|
-
*/
|
|
1430
|
-
async fetchAllStrategyInitReceiptAccounts() {
|
|
1431
|
-
return await this.vaultProgram.account.strategyInitReceipt.all();
|
|
1432
|
-
}
|
|
1433
|
-
/**
|
|
1434
|
-
* Fetches all strategy init receipt accounts of a vault
|
|
1435
|
-
* @param vault - Public key of the vault
|
|
1436
|
-
* @returns Promise resolving to an array of strategy init receipt accounts
|
|
1437
|
-
*
|
|
1438
|
-
* @example
|
|
1439
|
-
* ```typescript
|
|
1440
|
-
* const strategyInitReceiptAccounts = await client.fetchAllStrategyInitReceiptAccountsOfVault(vaultPubkey);
|
|
1441
|
-
* ```
|
|
1442
|
-
*/
|
|
1443
|
-
async fetchAllStrategyInitReceiptAccountsOfVault(vault) {
|
|
1444
|
-
return await this.vaultProgram.account.strategyInitReceipt.all([
|
|
1445
|
-
{
|
|
1446
|
-
memcmp: {
|
|
1447
|
-
offset: 8, // 8 for discriminator
|
|
1448
|
-
bytes: vault.toBase58(),
|
|
1449
|
-
},
|
|
1450
|
-
},
|
|
1451
|
-
]);
|
|
1452
|
-
}
|
|
1453
|
-
/**
|
|
1454
|
-
* Fetches all request withdraw vault receipt accounts of a vault
|
|
1455
|
-
* @param vault - Public key of the vault
|
|
1456
|
-
* @returns Promise resolving to an array of request withdraw vault receipt accounts
|
|
1457
|
-
*
|
|
1458
|
-
* @example
|
|
1459
|
-
* ```typescript
|
|
1460
|
-
* const requestWithdrawVaultReceiptAccounts = await client.fetchAllRequestWithdrawVaultReceiptsOfVault(vaultPubkey);
|
|
1461
|
-
* ```
|
|
1462
|
-
*/
|
|
1463
|
-
async fetchAllRequestWithdrawVaultReceiptsOfVault(vault) {
|
|
1464
|
-
return await this.vaultProgram.account.requestWithdrawVaultReceipt.all([
|
|
1465
|
-
{
|
|
1466
|
-
memcmp: {
|
|
1467
|
-
offset: 8, // 8 for discriminator
|
|
1468
|
-
bytes: vault.toBase58(),
|
|
1469
|
-
},
|
|
1470
|
-
},
|
|
1471
|
-
]);
|
|
1472
|
-
}
|
|
1473
|
-
/**
|
|
1474
|
-
* Fetches all adaptor add receipt accounts of a vault
|
|
1475
|
-
* @param vault - Public key of the vault
|
|
1476
|
-
* @returns Promise resolving to an array of adaptor add receipt accounts
|
|
1477
|
-
*
|
|
1478
|
-
* @example
|
|
1479
|
-
* ```typescript
|
|
1480
|
-
* const adaptorAddReceiptAccounts = await client.fetchAllAdaptorAddReceiptAccountsOfVault(vaultPubkey);
|
|
1481
|
-
* ```
|
|
1482
|
-
*/
|
|
1483
|
-
async fetchAllAdaptorAddReceiptAccountsOfVault(vault) {
|
|
1484
|
-
return await this.vaultProgram.account.adaptorAddReceipt.all([
|
|
1485
|
-
{
|
|
1486
|
-
memcmp: {
|
|
1487
|
-
offset: 8, // 8 for discriminator
|
|
1488
|
-
bytes: vault.toBase58(),
|
|
1489
|
-
},
|
|
1490
|
-
},
|
|
1491
|
-
]);
|
|
1492
|
-
}
|
|
1493
|
-
// --------------------------------------- Account Fetching
|
|
1494
|
-
/**
|
|
1495
|
-
* Fetches a vault account's data
|
|
1496
|
-
* @param vault - Public key of the vault
|
|
1497
|
-
* @returns Promise resolving to the vault account data
|
|
1498
|
-
*/
|
|
1499
|
-
/**
|
|
1500
|
-
* Fetches the protocol account's data
|
|
1501
|
-
* @returns Promise resolving to the protocol account data
|
|
1502
|
-
*
|
|
1503
|
-
* @example
|
|
1504
|
-
* ```typescript
|
|
1505
|
-
* const protocolAccount = await client.fetchProtocolAccount();
|
|
1506
|
-
* ```
|
|
1507
|
-
*/
|
|
1508
|
-
async fetchProtocolAccount() {
|
|
1509
|
-
const protocol = this.findProtocol();
|
|
1510
|
-
return await this.vaultProgram.account.protocol.fetch(protocol, this.provider.opts.commitment);
|
|
1511
|
-
}
|
|
1512
|
-
async fetchVaultAccount(vault) {
|
|
1513
|
-
return await this.vaultProgram.account.vault.fetch(vault, this.provider.opts.commitment);
|
|
1514
|
-
}
|
|
1515
|
-
/**
|
|
1516
|
-
* Fetches a strategy init receipt account's data
|
|
1517
|
-
* @param strategyInitReceipt - Public key of the strategy init receipt account
|
|
1518
|
-
* @returns Promise resolving to the strategy init receipt account data
|
|
1519
|
-
*
|
|
1520
|
-
* @example
|
|
1521
|
-
* ```typescript
|
|
1522
|
-
* const strategyInitReceiptAccount = await client.fetchStrategyInitReceiptAccount(strategyInitReceiptPubkey);
|
|
1523
|
-
* ```
|
|
1524
|
-
*/
|
|
1525
|
-
async fetchStrategyInitReceiptAccount(strategyInitReceipt) {
|
|
1526
|
-
return await this.vaultProgram.account.strategyInitReceipt.fetch(strategyInitReceipt, this.provider.opts.commitment);
|
|
1527
|
-
}
|
|
1528
|
-
/**
|
|
1529
|
-
* Fetches an adaptor add receipt account's data
|
|
1530
|
-
* @param adaptorAddReceipt - Public key of the adaptor add receipt account
|
|
1531
|
-
* @returns Promise resolving to the adaptor add receipt account data
|
|
1532
|
-
*
|
|
1533
|
-
* @example
|
|
1534
|
-
* ```typescript
|
|
1535
|
-
* const adaptorAddReceiptAccount = await client.fetchAdaptorAddReceiptAccount(adaptorAddReceiptPubkey);
|
|
1536
|
-
* ```
|
|
1537
|
-
*/
|
|
1538
|
-
async fetchAdaptorAddReceiptAccount(adaptorAddReceipt) {
|
|
1539
|
-
return await this.vaultProgram.account.adaptorAddReceipt.fetch(adaptorAddReceipt, this.provider.opts.commitment);
|
|
1540
|
-
}
|
|
1541
|
-
/**
|
|
1542
|
-
* Fetches a request withdraw vault receipt account's data
|
|
1543
|
-
* @param requestWithdrawVaultReceipt - Public key of the request withdraw vault receipt account
|
|
1544
|
-
* @returns Promise resolving to the request withdraw vault receipt account data
|
|
1545
|
-
*
|
|
1546
|
-
* @example
|
|
1547
|
-
* ```typescript
|
|
1548
|
-
* const requestWithdrawVaultReceiptAccount = await client.fetchRequestWithdrawVaultReceiptAccount(requestWithdrawVaultReceiptPubkey);
|
|
1549
|
-
* ```
|
|
1550
|
-
*/
|
|
1551
|
-
async fetchRequestWithdrawVaultReceiptAccount(requestWithdrawVaultReceipt) {
|
|
1552
|
-
return await this.vaultProgram.account.requestWithdrawVaultReceipt.fetch(requestWithdrawVaultReceipt, this.provider.opts.commitment);
|
|
1553
|
-
}
|
|
1554
|
-
// --------------------------------------- Helpers
|
|
1555
|
-
/**
|
|
1556
|
-
* Fetches the position and total values for a vault
|
|
1557
|
-
* @param vault - Public key of the vault
|
|
1558
|
-
* @returns Promise resolving to the position and total values
|
|
1559
|
-
*
|
|
1560
|
-
* @example
|
|
1561
|
-
* ```typescript
|
|
1562
|
-
* const positionAndTotalValues = await client.getPositionAndTotalValuesForVault(vaultPubkey);
|
|
1563
|
-
* ```
|
|
1564
|
-
*/
|
|
1565
|
-
async getPositionAndTotalValuesForVault(vault) {
|
|
1566
|
-
const vaultAccount = await this.fetchVaultAccount(vault);
|
|
1567
|
-
const totalAssetValue = vaultAccount.asset.totalValue;
|
|
1568
|
-
const strategyInitReceiptAccounts = await this.fetchAllStrategyInitReceiptAccountsOfVault(vault);
|
|
1569
|
-
const strategyInfo = strategyInitReceiptAccounts.map((vaultStrategyAccount) => ({
|
|
1570
|
-
strategyId: vaultStrategyAccount.account.strategy.toBase58(),
|
|
1571
|
-
amount: vaultStrategyAccount.account.positionValue.toNumber(),
|
|
1572
|
-
}));
|
|
1573
|
-
return {
|
|
1574
|
-
totalValue: totalAssetValue.toNumber(),
|
|
1575
|
-
strategies: strategyInfo,
|
|
1576
|
-
};
|
|
1577
|
-
}
|
|
1578
|
-
/**
|
|
1579
|
-
* Fetches the accumulated admin fees for a vault
|
|
1580
|
-
* @param vault - Public key of the vault
|
|
1581
|
-
* @returns Promise resolving to the accumulated admin fees
|
|
1582
|
-
*
|
|
1583
|
-
* @example
|
|
1584
|
-
* ```typescript
|
|
1585
|
-
* const accumulatedAdminFees = await client.getAccumulatedAdminFeesForVault(vaultPubkey);
|
|
1586
|
-
* ```
|
|
1587
|
-
*/
|
|
1588
|
-
async getAccumulatedAdminFeesForVault(vault) {
|
|
1589
|
-
const vaultAccount = await this.fetchVaultAccount(vault);
|
|
1590
|
-
return vaultAccount.feeState.accumulatedLpAdminFees;
|
|
1591
|
-
}
|
|
1592
|
-
/**
|
|
1593
|
-
* Fetches the accumulated manager fees for a vault
|
|
1594
|
-
* @param vault - Public key of the vault
|
|
1595
|
-
* @returns Promise resolving to the accumulated manager fees
|
|
1596
|
-
*
|
|
1597
|
-
* @example
|
|
1598
|
-
* ```typescript
|
|
1599
|
-
* const accumulatedManagerFees = await client.getAccumulatedManagerFeesForVault(vaultPubkey);
|
|
1600
|
-
* ```
|
|
1601
|
-
*/
|
|
1602
|
-
async getAccumulatedManagerFeesForVault(vault) {
|
|
1603
|
-
const vaultAccount = await this.fetchVaultAccount(vault);
|
|
1604
|
-
return vaultAccount.feeState.accumulatedLpManagerFees;
|
|
1605
|
-
}
|
|
1606
|
-
/**
|
|
1607
|
-
* Fetches the accumulated protocol fees for a vault
|
|
1608
|
-
* @param vault - Public key of the vault
|
|
1609
|
-
* @returns Promise resolving to the accumulated protocol fees
|
|
1610
|
-
*
|
|
1611
|
-
* @example
|
|
1612
|
-
* ```typescript
|
|
1613
|
-
* const accumulatedProtocolFees = await client.getAccumulatedProtocolFeesForVault(vaultPubkey);
|
|
1614
|
-
* ```
|
|
1615
|
-
*/
|
|
1616
|
-
async getAccumulatedProtocolFeesForVault(vault) {
|
|
1617
|
-
const vaultAccount = await this.fetchVaultAccount(vault);
|
|
1618
|
-
return vaultAccount.feeState.accumulatedLpProtocolFees;
|
|
1619
|
-
}
|
|
1620
|
-
/**
|
|
1621
|
-
* Fetches the current asset per LP for a vault
|
|
1622
|
-
* @param vault - Public key of the vault
|
|
1623
|
-
* @returns Promise resolving to the current asset per LP
|
|
1624
|
-
*
|
|
1625
|
-
* @example
|
|
1626
|
-
* ```typescript
|
|
1627
|
-
* const currentAssetPerLp = await client.getCurrentAssetPerLpForVault(vaultPubkey);
|
|
1628
|
-
* ```
|
|
1629
|
-
*/
|
|
1630
|
-
async getCurrentAssetPerLpForVault(vault) {
|
|
1631
|
-
const vaultLpMint = this.findVaultLpMint(vault);
|
|
1632
|
-
const vaultAccount = await this.fetchVaultAccount(vault);
|
|
1633
|
-
const lpSupply = await (0, spl_token_1.getMint)(this.conn, vaultLpMint, this.provider.opts.commitment).then((lp) => new bn_js_1.default(lp.supply.toString()));
|
|
1634
|
-
const unharvestedFeesLp = vaultAccount.feeState.accumulatedLpAdminFees
|
|
1635
|
-
.add(vaultAccount.feeState.accumulatedLpManagerFees)
|
|
1636
|
-
.add(vaultAccount.feeState.accumulatedLpProtocolFees);
|
|
1637
|
-
const deadWeight = vaultAccount.deadWeight;
|
|
1638
|
-
const totalLpSupply = unharvestedFeesLp.add(lpSupply).add(deadWeight);
|
|
1639
|
-
const currentAssetPerLp = vaultAccount.asset.totalValue.toNumber() / totalLpSupply.toNumber();
|
|
1640
|
-
return currentAssetPerLp;
|
|
1641
|
-
}
|
|
1642
|
-
/**
|
|
1643
|
-
* Fetches the high water mark for a vault
|
|
1644
|
-
* @param vault - Public key of the vault
|
|
1645
|
-
* @returns Promise resolving to the high water mark
|
|
1646
|
-
*
|
|
1647
|
-
* @example
|
|
1648
|
-
* ```typescript
|
|
1649
|
-
* const highWaterMark = await client.getHighWaterMarkForVault(vaultPubkey);
|
|
1650
|
-
* ```
|
|
1651
|
-
*/
|
|
1652
|
-
async getHighWaterMarkForVault(vault) {
|
|
1653
|
-
const vaultAccount = await this.fetchVaultAccount(vault);
|
|
1654
|
-
const highWaterMarkValue = (0, decimals_1.convertDecimalBitsToDecimal)(vaultAccount.highWaterMark.highestAssetPerLpDecimalBits);
|
|
1655
|
-
return {
|
|
1656
|
-
highestAssetPerLp: highWaterMarkValue.toNumber(),
|
|
1657
|
-
lastUpdatedTs: vaultAccount.highWaterMark.lastUpdatedTs.toNumber(),
|
|
1658
|
-
};
|
|
1659
|
-
}
|
|
1660
|
-
/**
|
|
1661
|
-
* Fetches the breakdown of the LP supply for a vault
|
|
1662
|
-
* @param vault - Public key of the vault
|
|
1663
|
-
* @returns Promise resolving to the breakdown of the LP supply
|
|
1664
|
-
*
|
|
1665
|
-
* @example
|
|
1666
|
-
* ```typescript
|
|
1667
|
-
* const lpSupplyBreakdown = await client.getVaultLpSupplyBreakdown(vaultPubkey);
|
|
1668
|
-
* ```
|
|
1669
|
-
*/
|
|
1670
|
-
async getVaultLpSupplyBreakdown(vault) {
|
|
1671
|
-
const [vaultAccount, lpMintInfo] = await Promise.all([
|
|
1672
|
-
this.fetchVaultAccount(vault),
|
|
1673
|
-
(0, spl_token_1.getMint)(this.conn, this.findVaultLpMint(vault), this.provider.opts.commitment),
|
|
1674
|
-
]);
|
|
1675
|
-
const circulating = new bn_js_1.default(lpMintInfo.supply.toString());
|
|
1676
|
-
const unharvestedFees = vaultAccount.feeState.accumulatedLpAdminFees
|
|
1677
|
-
.add(vaultAccount.feeState.accumulatedLpManagerFees)
|
|
1678
|
-
.add(vaultAccount.feeState.accumulatedLpProtocolFees);
|
|
1679
|
-
const deadWeight = vaultAccount.deadWeight;
|
|
1680
|
-
const currentTotalLp = circulating.add(unharvestedFees).add(deadWeight);
|
|
1681
|
-
const unrealisedFees = this.calculateUnrealisedLpFees(currentTotalLp, vaultAccount.asset.totalValue, vaultAccount.feeUpdate.lastManagementFeeUpdateTs, new bn_js_1.default(vaultAccount.feeConfiguration.managerManagementFee +
|
|
1682
|
-
vaultAccount.feeConfiguration.adminManagementFee +
|
|
1683
|
-
vaultAccount.feeConfiguration.protocolManagementFee));
|
|
1684
|
-
const total = currentTotalLp.add(unrealisedFees);
|
|
1685
|
-
return {
|
|
1686
|
-
circulating,
|
|
1687
|
-
unharvestedFees,
|
|
1688
|
-
unrealisedFees,
|
|
1689
|
-
total,
|
|
1690
|
-
};
|
|
1691
|
-
}
|
|
1692
|
-
/**
|
|
1693
|
-
* Processes a withdrawal receipt into a standardized withdrawal info object
|
|
1694
|
-
* @private
|
|
1695
|
-
*/
|
|
1696
|
-
async processWithdrawalReceipt(receipt, vaultAccount, lpSupply) {
|
|
1697
|
-
const amountAssetToWithdrawDecimal = (0, decimals_1.convertDecimalBitsToDecimal)(receipt.account.amountAssetToWithdrawDecimalBits);
|
|
1698
|
-
const amountAssetToWithdrawAtRequest = amountAssetToWithdrawDecimal.toNumber();
|
|
1699
|
-
const amountLpEscrowed = receipt.account.amountLpEscrowed;
|
|
1700
|
-
const amountAssetToWithdrawAtPresent = this.calculateAssetsForWithdrawHelper(vaultAccount.asset.totalValue, vaultAccount.lockedProfitState.lastUpdatedLockedProfit, vaultAccount.vaultConfiguration.lockedProfitDegradationDuration, vaultAccount.feeState.accumulatedLpAdminFees, vaultAccount.feeState.accumulatedLpManagerFees, vaultAccount.feeState.accumulatedLpProtocolFees, vaultAccount.feeConfiguration.redemptionFee, vaultAccount.feeConfiguration.managerManagementFee +
|
|
1701
|
-
vaultAccount.feeConfiguration.adminManagementFee +
|
|
1702
|
-
vaultAccount.feeConfiguration.protocolManagementFee, vaultAccount.feeUpdate.lastManagementFeeUpdateTs, lpSupply, amountLpEscrowed, vaultAccount.deadWeight).toNumber();
|
|
1703
|
-
// Cap the withdrawal amount to the initial request amount
|
|
1704
|
-
const amountAssetToWithdrawEffective = Math.min(amountAssetToWithdrawAtPresent, amountAssetToWithdrawAtRequest);
|
|
1705
|
-
return {
|
|
1706
|
-
user: receipt.account.user,
|
|
1707
|
-
amountAssetToWithdrawEffective,
|
|
1708
|
-
amountAssetToWithdrawAtRequest,
|
|
1709
|
-
amountAssetToWithdrawAtPresent,
|
|
1710
|
-
amountLpEscrowed: amountLpEscrowed.toNumber(),
|
|
1711
|
-
withdrawableFromTs: receipt.account.withdrawableFromTs.toNumber(),
|
|
1712
|
-
};
|
|
1713
|
-
}
|
|
1714
|
-
/**
|
|
1715
|
-
* Fetches the pending withdrawal for a user
|
|
1716
|
-
* @param vault - Public key of the vault
|
|
1717
|
-
* @param user - Public key of the user
|
|
1718
|
-
* @returns Promise resolving to the pending withdrawal
|
|
1719
|
-
*
|
|
1720
|
-
* @example
|
|
1721
|
-
* ```typescript
|
|
1722
|
-
* const pendingWithdrawal = await client.getPendingWithdrawalForUser(vaultPubkey, userPubkey);
|
|
1723
|
-
* ```
|
|
1724
|
-
*/
|
|
1725
|
-
async getPendingWithdrawalForUser(vault, user) {
|
|
1726
|
-
const [vaultAccount, lp] = await Promise.all([
|
|
1727
|
-
this.fetchVaultAccount(vault),
|
|
1728
|
-
(0, spl_token_1.getMint)(this.conn, this.findVaultLpMint(vault), this.provider.opts.commitment),
|
|
1729
|
-
]);
|
|
1730
|
-
const requestWithdrawVaultReceiptAddress = this.findRequestWithdrawVaultReceipt(vault, user);
|
|
1731
|
-
const receipt = await this.fetchRequestWithdrawVaultReceiptAccount(requestWithdrawVaultReceiptAddress);
|
|
1732
|
-
return this.processWithdrawalReceipt({ account: receipt }, vaultAccount, new bn_js_1.default(lp.supply.toString()));
|
|
1733
|
-
}
|
|
1734
|
-
/**
|
|
1735
|
-
* Fetches all pending withdrawals for a vault
|
|
1736
|
-
* @param vault - Public key of the vault
|
|
1737
|
-
* @returns Promise resolving to an array of pending withdrawals
|
|
1738
|
-
*
|
|
1739
|
-
* @example
|
|
1740
|
-
* ```typescript
|
|
1741
|
-
* const pendingWithdrawals = await client.getAllPendingWithdrawalsForVault(vaultPubkey);
|
|
1742
|
-
* ```
|
|
1743
|
-
*/
|
|
1744
|
-
async getAllPendingWithdrawalsForVault(vault) {
|
|
1745
|
-
const [requestWithdrawVaultReceipts, vaultAccount, lp] = await Promise.all([
|
|
1746
|
-
this.fetchAllRequestWithdrawVaultReceiptsOfVault(vault),
|
|
1747
|
-
this.fetchVaultAccount(vault),
|
|
1748
|
-
(0, spl_token_1.getMint)(this.conn, this.findVaultLpMint(vault), this.provider.opts.commitment),
|
|
1749
|
-
]);
|
|
1750
|
-
const lpSupply = new bn_js_1.default(lp.supply.toString());
|
|
1751
|
-
return Promise.all(requestWithdrawVaultReceipts.map((receipt) => this.processWithdrawalReceipt(receipt, vaultAccount, lpSupply)));
|
|
1752
|
-
}
|
|
1753
|
-
calculateLockedProfit(lastUpdatedLockedProfit, lockedProfitDegradationDuration, currentTime) {
|
|
1754
|
-
if (lockedProfitDegradationDuration.eq(new bn_js_1.default(0)))
|
|
1755
|
-
return new bn_js_1.default(0);
|
|
1756
|
-
const duration = currentTime.sub(lastUpdatedLockedProfit);
|
|
1757
|
-
const lockedProfit = lastUpdatedLockedProfit
|
|
1758
|
-
.mul(lockedProfitDegradationDuration.sub(duration))
|
|
1759
|
-
.div(lockedProfitDegradationDuration);
|
|
1760
|
-
if (duration.gt(lockedProfitDegradationDuration))
|
|
1761
|
-
return new bn_js_1.default(0);
|
|
1762
|
-
else
|
|
1763
|
-
return lockedProfit;
|
|
1764
|
-
}
|
|
1765
|
-
/**
|
|
1766
|
-
* Helper to calculate only the pending (unrealised) LP fees based on time elapsed.
|
|
1767
|
-
*/
|
|
1768
|
-
calculateUnrealisedLpFees(currentTotalLp, assetTotalValue, lastManagementFeeUpdateTs, managementFeeBps) {
|
|
1769
|
-
if (lastManagementFeeUpdateTs.eq(new bn_js_1.default(0)) ||
|
|
1770
|
-
assetTotalValue.eq(new bn_js_1.default(0)) ||
|
|
1771
|
-
managementFeeBps.eq(new bn_js_1.default(0))) {
|
|
1772
|
-
return new bn_js_1.default(0);
|
|
1773
|
-
}
|
|
1774
|
-
const nowBn = new bn_js_1.default(Math.floor(Date.now() / 1000));
|
|
1775
|
-
const timeElapsed = bn_js_1.default.max(new bn_js_1.default(0), nowBn.sub(lastManagementFeeUpdateTs));
|
|
1776
|
-
if (timeElapsed.eq(new bn_js_1.default(0))) {
|
|
1777
|
-
return new bn_js_1.default(0);
|
|
1778
|
-
}
|
|
1779
|
-
const feeAmountInAsset = assetTotalValue
|
|
1780
|
-
.mul(timeElapsed)
|
|
1781
|
-
.mul(managementFeeBps)
|
|
1782
|
-
.div(constants_1.MAX_FEE_BPS_BN)
|
|
1783
|
-
.div(constants_1.ONE_YEAR_BN);
|
|
1784
|
-
const lpNumerator = feeAmountInAsset.mul(currentTotalLp);
|
|
1785
|
-
const lpDenominator = assetTotalValue.sub(feeAmountInAsset);
|
|
1786
|
-
if (lpDenominator.lte(new bn_js_1.default(0))) {
|
|
1787
|
-
return new bn_js_1.default(0);
|
|
1788
|
-
}
|
|
1789
|
-
const pendingLpToMint = lpNumerator
|
|
1790
|
-
.add(lpDenominator)
|
|
1791
|
-
.sub(new bn_js_1.default(1))
|
|
1792
|
-
.div(lpDenominator);
|
|
1793
|
-
return pendingLpToMint;
|
|
1794
|
-
}
|
|
1795
|
-
calculateAssetsForWithdrawHelper(vaultTotalValue, vaultLastUpdatedLockedProfit, vaultLockedProfitDegradationDuration, vaultAccumulatedLpAdminFees, vaultAccumulatedLpManagerFees, vaultAccumulatedLpProtocolFees, vaultRedemptionFeeBps, vaultManagementFeeBps, vaultLastManagementFeeUpdateTs, lpSupply, lpAmount, deadWeight = new bn_js_1.default(0)) {
|
|
1796
|
-
if (lpSupply <= new bn_js_1.default(0))
|
|
1797
|
-
throw new Error("Invalid LP supply");
|
|
1798
|
-
if (vaultTotalValue <= new bn_js_1.default(0))
|
|
1799
|
-
throw new Error("Invalid total assets");
|
|
1800
|
-
const lockedProfit = this.calculateLockedProfit(vaultLastUpdatedLockedProfit, vaultLockedProfitDegradationDuration, new bn_js_1.default(Date.now() / 1000));
|
|
1801
|
-
const totalUnlockedValue = vaultTotalValue.sub(lockedProfit);
|
|
1802
|
-
const unharvestedFeesLp = vaultAccumulatedLpAdminFees
|
|
1803
|
-
.add(vaultAccumulatedLpManagerFees)
|
|
1804
|
-
.add(vaultAccumulatedLpProtocolFees);
|
|
1805
|
-
const lpSupplyInclAccumulatedFees = lpSupply
|
|
1806
|
-
.add(unharvestedFeesLp)
|
|
1807
|
-
.add(deadWeight);
|
|
1808
|
-
const unrealisedLpFees = this.calculateUnrealisedLpFees(lpSupplyInclAccumulatedFees, vaultTotalValue, vaultLastManagementFeeUpdateTs, new bn_js_1.default(vaultManagementFeeBps));
|
|
1809
|
-
const lpSupplyInclFees = unrealisedLpFees.add(lpSupplyInclAccumulatedFees);
|
|
1810
|
-
// asset_to_redeem_pre_fee = amount * (total_asset_pre_withdraw / total_lp_supply_pre_withdraw)
|
|
1811
|
-
// asset_to_redeem_post_fee = asset_to_redeem_pre_fee * (10000 - redemption_fee_bps) / 10000
|
|
1812
|
-
const assetToRedeemNumerator = lpAmount
|
|
1813
|
-
.mul(totalUnlockedValue)
|
|
1814
|
-
.mul(new bn_js_1.default(10000 - vaultRedemptionFeeBps));
|
|
1815
|
-
const assetToRedeemDenominator = lpSupplyInclFees.mul(new bn_js_1.default(10000));
|
|
1816
|
-
const amount = assetToRedeemNumerator.div(assetToRedeemDenominator);
|
|
1817
|
-
return amount;
|
|
1818
|
-
}
|
|
1819
|
-
/**
|
|
1820
|
-
* Calculates the amount of assets that would be received for a given LP token amount
|
|
1821
|
-
*
|
|
1822
|
-
* @param vaultPk - Public key of the vault
|
|
1823
|
-
* @param lpAmount - Amount of LP tokens to calculate for
|
|
1824
|
-
* @returns Promise resolving to the amount of assets that would be received
|
|
1825
|
-
*
|
|
1826
|
-
* @throws {Error} If LP supply or total assets are invalid
|
|
1827
|
-
* @throws {Error} If math overflow occurs during calculation
|
|
1828
|
-
*
|
|
1829
|
-
* @example
|
|
1830
|
-
* ```typescript
|
|
1831
|
-
* const assetsToReceive = await client.calculateAssetsForWithdraw(
|
|
1832
|
-
* vaultPubkey,
|
|
1833
|
-
* new BN('1000000000')
|
|
1834
|
-
* );
|
|
1835
|
-
* ```
|
|
1836
|
-
*/
|
|
1837
|
-
async calculateAssetsForWithdraw(vaultPk, lpAmount) {
|
|
1838
|
-
try {
|
|
1839
|
-
const vault = await this.fetchVaultAccount(vaultPk);
|
|
1840
|
-
const lpMint = this.findVaultLpMint(vaultPk);
|
|
1841
|
-
const lp = await (0, spl_token_1.getMint)(this.conn, lpMint, this.provider.opts.commitment);
|
|
1842
|
-
const amount = this.calculateAssetsForWithdrawHelper(vault.asset.totalValue, vault.lockedProfitState.lastUpdatedLockedProfit, vault.vaultConfiguration.lockedProfitDegradationDuration, vault.feeState.accumulatedLpAdminFees, vault.feeState.accumulatedLpManagerFees, vault.feeState.accumulatedLpProtocolFees, vault.feeConfiguration.redemptionFee, vault.feeConfiguration.managerManagementFee +
|
|
1843
|
-
vault.feeConfiguration.adminManagementFee +
|
|
1844
|
-
vault.feeConfiguration.protocolManagementFee, vault.feeUpdate.lastManagementFeeUpdateTs, new bn_js_1.default(lp.supply.toString()), lpAmount, vault.deadWeight);
|
|
1845
|
-
return amount;
|
|
1846
|
-
}
|
|
1847
|
-
catch (e) {
|
|
1848
|
-
throw new Error("Math overflow in asset calculation for withdraw");
|
|
1849
|
-
}
|
|
1850
|
-
}
|
|
1851
|
-
/**
|
|
1852
|
-
* Calculates the amount of LP tokens that would be burned for a given asset amount
|
|
1853
|
-
*
|
|
1854
|
-
* @param vaultPk - Public key of the vault
|
|
1855
|
-
* @param assetAmount - Amount of assets to calculate for
|
|
1856
|
-
* @returns Promise resolving to the amount of LP tokens that would be burned
|
|
1857
|
-
*
|
|
1858
|
-
* @throws {Error} If LP supply or total assets are invalid
|
|
1859
|
-
* @throws {Error} If math overflow occurs during calculation
|
|
1860
|
-
*
|
|
1861
|
-
* @example
|
|
1862
|
-
* ```typescript
|
|
1863
|
-
* const lpTokensToBurn = await client.calculateLpForWithdraw(
|
|
1864
|
-
* vaultPubkey,
|
|
1865
|
-
* new BN('1000000000')
|
|
1866
|
-
* );
|
|
1867
|
-
* ```
|
|
1868
|
-
*/
|
|
1869
|
-
async calculateLpForWithdraw(vaultPk, assetAmount) {
|
|
1870
|
-
try {
|
|
1871
|
-
const vault = await this.fetchVaultAccount(vaultPk);
|
|
1872
|
-
const totalValue = vault.asset.totalValue;
|
|
1873
|
-
const lockedProfit = this.calculateLockedProfit(vault.lockedProfitState.lastUpdatedLockedProfit, vault.vaultConfiguration.lockedProfitDegradationDuration, new bn_js_1.default(Date.now() / 1000));
|
|
1874
|
-
const totalUnlockedValue = totalValue.sub(lockedProfit);
|
|
1875
|
-
const lpMint = this.findVaultLpMint(vaultPk);
|
|
1876
|
-
const lp = await (0, spl_token_1.getMint)(this.conn, lpMint, this.provider.opts.commitment);
|
|
1877
|
-
const lpSupply = new bn_js_1.default(lp.supply.toString());
|
|
1878
|
-
// Validate inputs
|
|
1879
|
-
if (lpSupply <= new bn_js_1.default(0))
|
|
1880
|
-
throw new Error("Invalid LP supply");
|
|
1881
|
-
if (totalValue <= new bn_js_1.default(0))
|
|
1882
|
-
throw new Error("Invalid total assets");
|
|
1883
|
-
const unharvestedFeesLp = vault.feeState.accumulatedLpAdminFees
|
|
1884
|
-
.add(vault.feeState.accumulatedLpManagerFees)
|
|
1885
|
-
.add(vault.feeState.accumulatedLpProtocolFees);
|
|
1886
|
-
const lpSupplyInclAccumulatedFees = lpSupply
|
|
1887
|
-
.add(unharvestedFeesLp)
|
|
1888
|
-
.add(vault.deadWeight);
|
|
1889
|
-
const unrealisedLpFees = this.calculateUnrealisedLpFees(lpSupplyInclAccumulatedFees, totalValue, vault.feeUpdate.lastManagementFeeUpdateTs, new bn_js_1.default(vault.feeConfiguration.managerManagementFee +
|
|
1890
|
-
vault.feeConfiguration.adminManagementFee +
|
|
1891
|
-
vault.feeConfiguration.protocolManagementFee));
|
|
1892
|
-
const lpSupplyInclFees = unrealisedLpFees.add(lpSupplyInclAccumulatedFees);
|
|
1893
|
-
// lp_to_burn_pre_fee = redeem_amount * (total_lp_supply_pre_withdraw / total_asset_pre_withdraw)
|
|
1894
|
-
// lp_to_burn_post_fee = lp_to_burn_pre_fee * (10000 / (10000 - redemption_fee_bps))
|
|
1895
|
-
const lpToBurnNumerator = assetAmount
|
|
1896
|
-
.mul(lpSupplyInclFees)
|
|
1897
|
-
.mul(new bn_js_1.default(10000));
|
|
1898
|
-
const lpToBurnDenominator = totalUnlockedValue.mul(new bn_js_1.default(10000 - vault.feeConfiguration.redemptionFee));
|
|
1899
|
-
const lpToBurn = lpToBurnNumerator.div(lpToBurnDenominator);
|
|
1900
|
-
return lpToBurn;
|
|
1901
|
-
}
|
|
1902
|
-
catch (e) {
|
|
1903
|
-
throw new Error("Math overflow in LP token calculation for withdraw");
|
|
1904
|
-
}
|
|
1905
|
-
}
|
|
1906
|
-
/**
|
|
1907
|
-
* Calculates the amount of LP tokens that would be received for a given asset deposit
|
|
1908
|
-
*
|
|
1909
|
-
* @param vaultPk - Public key of the vault
|
|
1910
|
-
* @param assetAmount - Amount of assets to deposit
|
|
1911
|
-
* @returns Promise resolving to the amount of LP tokens that would be received
|
|
1912
|
-
*
|
|
1913
|
-
* @throws {Error} If math overflow occurs during calculation
|
|
1914
|
-
*
|
|
1915
|
-
* @example
|
|
1916
|
-
* ```typescript
|
|
1917
|
-
* const lpTokens = await client.calculateLpTokensForDeposit(
|
|
1918
|
-
* vaultPubkey
|
|
1919
|
-
* new BN('1000000000'),
|
|
1920
|
-
* );
|
|
1921
|
-
* ```
|
|
1922
|
-
*/
|
|
1923
|
-
async calculateLpForDeposit(vaultPk, assetAmount) {
|
|
1924
|
-
const vault = await this.fetchVaultAccount(vaultPk);
|
|
1925
|
-
const totalValue = vault.asset.totalValue;
|
|
1926
|
-
const lpMint = this.findVaultLpMint(vaultPk);
|
|
1927
|
-
const lp = await (0, spl_token_1.getMint)(this.conn, lpMint, this.provider.opts.commitment);
|
|
1928
|
-
const lpSupply = new bn_js_1.default(lp.supply.toString());
|
|
1929
|
-
const unharvestedFeesLp = vault.feeState.accumulatedLpAdminFees
|
|
1930
|
-
.add(vault.feeState.accumulatedLpManagerFees)
|
|
1931
|
-
.add(vault.feeState.accumulatedLpProtocolFees);
|
|
1932
|
-
const lpSupplyInclAccumulatedFees = lpSupply
|
|
1933
|
-
.add(unharvestedFeesLp)
|
|
1934
|
-
.add(vault.deadWeight);
|
|
1935
|
-
const unrealisedLpFees = this.calculateUnrealisedLpFees(lpSupplyInclAccumulatedFees, totalValue, vault.feeUpdate.lastManagementFeeUpdateTs, new bn_js_1.default(vault.feeConfiguration.managerManagementFee +
|
|
1936
|
-
vault.feeConfiguration.adminManagementFee +
|
|
1937
|
-
vault.feeConfiguration.protocolManagementFee));
|
|
1938
|
-
const lpSupplyInclFees = unrealisedLpFees.add(lpSupplyInclAccumulatedFees);
|
|
1939
|
-
// If the pool is empty, mint LP tokens 1:1 with deposit
|
|
1940
|
-
if (lpSupplyInclFees.eq(new bn_js_1.default(0))) {
|
|
1941
|
-
const assetMint = await (0, spl_token_1.getMint)(this.conn, vault.asset.mint, this.provider.opts.commitment);
|
|
1942
|
-
const assetDecimals = assetMint.decimals;
|
|
1943
|
-
const lpDecimals = lp.decimals;
|
|
1944
|
-
return assetAmount
|
|
1945
|
-
.mul(new bn_js_1.default(10 ** lpDecimals))
|
|
1946
|
-
.div(new bn_js_1.default(10 ** assetDecimals));
|
|
1947
|
-
}
|
|
1948
|
-
try {
|
|
1949
|
-
const lpToMintNumerator = assetAmount
|
|
1950
|
-
.mul(lpSupplyInclFees)
|
|
1951
|
-
.mul(new bn_js_1.default(10000 - vault.feeConfiguration.issuanceFee));
|
|
1952
|
-
const totalAssetPostDeposit = totalValue.add(assetAmount);
|
|
1953
|
-
const lpToMintDenominator = totalAssetPostDeposit
|
|
1954
|
-
.mul(new bn_js_1.default(10000))
|
|
1955
|
-
.sub(assetAmount.mul(new bn_js_1.default(10000 - vault.feeConfiguration.issuanceFee)));
|
|
1956
|
-
const lpToMint = lpToMintNumerator.div(lpToMintDenominator);
|
|
1957
|
-
return lpToMint;
|
|
1958
|
-
}
|
|
1959
|
-
catch (e) {
|
|
1960
|
-
throw new Error("Math overflow in LP token calculation for deposit");
|
|
1961
|
-
}
|
|
1962
|
-
}
|
|
1963
|
-
}
|
|
1964
|
-
exports.VoltrClient = VoltrClient;
|