@haven-fi/solauto-sdk 1.0.0
Sign up to get free protection for your applications and to get access to all the features.
- package/dist/clients/index.d.ts +2 -0
- package/dist/clients/index.d.ts.map +1 -0
- package/dist/clients/index.js +17 -0
- package/dist/clients/solautoClient.d.ts +73 -0
- package/dist/clients/solautoClient.d.ts.map +1 -0
- package/dist/clients/solautoClient.js +416 -0
- package/dist/clients/solautoMarginfiClient.d.ts +40 -0
- package/dist/clients/solautoMarginfiClient.d.ts.map +1 -0
- package/dist/clients/solautoMarginfiClient.js +313 -0
- package/dist/constants/generalAccounts.d.ts +5 -0
- package/dist/constants/generalAccounts.d.ts.map +1 -0
- package/dist/constants/generalAccounts.js +8 -0
- package/dist/constants/index.d.ts +6 -0
- package/dist/constants/index.d.ts.map +1 -0
- package/dist/constants/index.js +21 -0
- package/dist/constants/marginfiAccounts.d.ts +7 -0
- package/dist/constants/marginfiAccounts.d.ts.map +1 -0
- package/dist/constants/marginfiAccounts.js +23 -0
- package/dist/constants/pythConstants.d.ts +5 -0
- package/dist/constants/pythConstants.d.ts.map +1 -0
- package/dist/constants/pythConstants.js +10 -0
- package/dist/constants/solautoConstants.d.ts +19 -0
- package/dist/constants/solautoConstants.d.ts.map +1 -0
- package/dist/constants/solautoConstants.js +35 -0
- package/dist/constants/tokenConstants.d.ts +3 -0
- package/dist/constants/tokenConstants.d.ts.map +1 -0
- package/dist/constants/tokenConstants.js +10 -0
- package/dist/generated/accounts/index.d.ts +10 -0
- package/dist/generated/accounts/index.d.ts.map +1 -0
- package/dist/generated/accounts/index.js +25 -0
- package/dist/generated/accounts/referralState.d.ts +37 -0
- package/dist/generated/accounts/referralState.d.ts.map +1 -0
- package/dist/generated/accounts/referralState.js +73 -0
- package/dist/generated/accounts/solautoPosition.d.ts +58 -0
- package/dist/generated/accounts/solautoPosition.d.ts.map +1 -0
- package/dist/generated/accounts/solautoPosition.js +82 -0
- package/dist/generated/errors/index.d.ts +9 -0
- package/dist/generated/errors/index.d.ts.map +1 -0
- package/dist/generated/errors/index.js +24 -0
- package/dist/generated/errors/solauto.d.ts +91 -0
- package/dist/generated/errors/solauto.d.ts.map +1 -0
- package/dist/generated/errors/solauto.js +163 -0
- package/dist/generated/index.d.ts +14 -0
- package/dist/generated/index.d.ts.map +1 -0
- package/dist/generated/index.js +29 -0
- package/dist/generated/instructions/cancelDCA.d.ts +26 -0
- package/dist/generated/instructions/cancelDCA.d.ts.map +1 -0
- package/dist/generated/instructions/cancelDCA.js +92 -0
- package/dist/generated/instructions/claimReferralFees.d.ts +26 -0
- package/dist/generated/instructions/claimReferralFees.d.ts.map +1 -0
- package/dist/generated/instructions/claimReferralFees.js +87 -0
- package/dist/generated/instructions/closePosition.d.ts +28 -0
- package/dist/generated/instructions/closePosition.d.ts.map +1 -0
- package/dist/generated/instructions/closePosition.js +102 -0
- package/dist/generated/instructions/convertReferralFees.d.ts +27 -0
- package/dist/generated/instructions/convertReferralFees.d.ts.map +1 -0
- package/dist/generated/instructions/convertReferralFees.js +96 -0
- package/dist/generated/instructions/index.d.ts +18 -0
- package/dist/generated/instructions/index.d.ts.map +1 -0
- package/dist/generated/instructions/index.js +33 -0
- package/dist/generated/instructions/marginfiOpenPosition.d.ts +46 -0
- package/dist/generated/instructions/marginfiOpenPosition.d.ts.map +1 -0
- package/dist/generated/instructions/marginfiOpenPosition.js +161 -0
- package/dist/generated/instructions/marginfiProtocolInteraction.d.ts +42 -0
- package/dist/generated/instructions/marginfiProtocolInteraction.d.ts.map +1 -0
- package/dist/generated/instructions/marginfiProtocolInteraction.js +150 -0
- package/dist/generated/instructions/marginfiRebalance.d.ts +49 -0
- package/dist/generated/instructions/marginfiRebalance.d.ts.map +1 -0
- package/dist/generated/instructions/marginfiRebalance.js +164 -0
- package/dist/generated/instructions/marginfiRefreshData.d.ts +27 -0
- package/dist/generated/instructions/marginfiRefreshData.d.ts.map +1 -0
- package/dist/generated/instructions/marginfiRefreshData.js +84 -0
- package/dist/generated/instructions/updatePosition.d.ts +30 -0
- package/dist/generated/instructions/updatePosition.d.ts.map +1 -0
- package/dist/generated/instructions/updatePosition.js +87 -0
- package/dist/generated/instructions/updateReferralStates.d.ts +30 -0
- package/dist/generated/instructions/updateReferralStates.d.ts.map +1 -0
- package/dist/generated/instructions/updateReferralStates.js +77 -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 +24 -0
- package/dist/generated/programs/solauto.d.ts +13 -0
- package/dist/generated/programs/solauto.d.ts.map +1 -0
- package/dist/generated/programs/solauto.js +36 -0
- package/dist/generated/shared/index.d.ts +54 -0
- package/dist/generated/shared/index.d.ts.map +1 -0
- package/dist/generated/shared/index.js +70 -0
- package/dist/generated/types/automationSettings.d.ts +26 -0
- package/dist/generated/types/automationSettings.d.ts.map +1 -0
- package/dist/generated/types/automationSettings.js +22 -0
- package/dist/generated/types/automationSettingsInp.d.ts +22 -0
- package/dist/generated/types/automationSettingsInp.d.ts.map +1 -0
- package/dist/generated/types/automationSettingsInp.js +20 -0
- package/dist/generated/types/dCASettings.d.ts +21 -0
- package/dist/generated/types/dCASettings.d.ts.map +1 -0
- package/dist/generated/types/dCASettings.js +20 -0
- package/dist/generated/types/dCASettingsInp.d.ts +19 -0
- package/dist/generated/types/dCASettingsInp.d.ts.map +1 -0
- package/dist/generated/types/dCASettingsInp.js +19 -0
- package/dist/generated/types/feeType.d.ts +15 -0
- package/dist/generated/types/feeType.d.ts.map +1 -0
- package/dist/generated/types/feeType.js +20 -0
- package/dist/generated/types/index.d.ts +26 -0
- package/dist/generated/types/index.d.ts.map +1 -0
- package/dist/generated/types/index.js +41 -0
- package/dist/generated/types/lendingPlatform.d.ts +16 -0
- package/dist/generated/types/lendingPlatform.d.ts.map +1 -0
- package/dist/generated/types/lendingPlatform.js +23 -0
- package/dist/generated/types/podBool.d.ts +14 -0
- package/dist/generated/types/podBool.d.ts.map +1 -0
- package/dist/generated/types/podBool.js +17 -0
- package/dist/generated/types/positionData.d.ts +32 -0
- package/dist/generated/types/positionData.d.ts.map +1 -0
- package/dist/generated/types/positionData.js +25 -0
- package/dist/generated/types/positionState.d.ts +35 -0
- package/dist/generated/types/positionState.d.ts.map +1 -0
- package/dist/generated/types/positionState.js +27 -0
- package/dist/generated/types/positionTokenUsage.d.ts +36 -0
- package/dist/generated/types/positionTokenUsage.d.ts.map +1 -0
- package/dist/generated/types/positionTokenUsage.js +27 -0
- package/dist/generated/types/rebalanceData.d.ts +29 -0
- package/dist/generated/types/rebalanceData.d.ts.map +1 -0
- package/dist/generated/types/rebalanceData.js +24 -0
- package/dist/generated/types/solautoAction.d.ts +44 -0
- package/dist/generated/types/solautoAction.d.ts.map +1 -0
- package/dist/generated/types/solautoAction.js +51 -0
- package/dist/generated/types/solautoRebalanceType.d.ts +17 -0
- package/dist/generated/types/solautoRebalanceType.d.ts.map +1 -0
- package/dist/generated/types/solautoRebalanceType.js +24 -0
- package/dist/generated/types/solautoSettingsParameters.d.ts +31 -0
- package/dist/generated/types/solautoSettingsParameters.d.ts.map +1 -0
- package/dist/generated/types/solautoSettingsParameters.js +25 -0
- package/dist/generated/types/solautoSettingsParametersInp.d.ts +28 -0
- package/dist/generated/types/solautoSettingsParametersInp.d.ts.map +1 -0
- package/dist/generated/types/solautoSettingsParametersInp.js +23 -0
- package/dist/generated/types/tokenAmount.d.ts +18 -0
- package/dist/generated/types/tokenAmount.d.ts.map +1 -0
- package/dist/generated/types/tokenAmount.js +18 -0
- package/dist/generated/types/tokenBalanceAmount.d.ts +27 -0
- package/dist/generated/types/tokenBalanceAmount.d.ts.map +1 -0
- package/dist/generated/types/tokenBalanceAmount.js +33 -0
- package/dist/generated/types/updatePositionData.d.ts +22 -0
- package/dist/generated/types/updatePositionData.d.ts.map +1 -0
- package/dist/generated/types/updatePositionData.js +20 -0
- package/dist/index.d.ts +7 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +22 -0
- package/dist/marginfi-sdk/accounts/bank.d.ts +136 -0
- package/dist/marginfi-sdk/accounts/bank.d.ts.map +1 -0
- package/dist/marginfi-sdk/accounts/bank.js +124 -0
- package/dist/marginfi-sdk/accounts/index.d.ts +11 -0
- package/dist/marginfi-sdk/accounts/index.d.ts.map +1 -0
- package/dist/marginfi-sdk/accounts/index.js +26 -0
- package/dist/marginfi-sdk/accounts/marginfiAccount.d.ts +58 -0
- package/dist/marginfi-sdk/accounts/marginfiAccount.d.ts.map +1 -0
- package/dist/marginfi-sdk/accounts/marginfiAccount.js +76 -0
- package/dist/marginfi-sdk/accounts/marginfiGroup.d.ts +35 -0
- package/dist/marginfi-sdk/accounts/marginfiGroup.d.ts.map +1 -0
- package/dist/marginfi-sdk/accounts/marginfiGroup.js +71 -0
- package/dist/marginfi-sdk/errors/index.d.ts +9 -0
- package/dist/marginfi-sdk/errors/index.d.ts.map +1 -0
- package/dist/marginfi-sdk/errors/index.js +24 -0
- package/dist/marginfi-sdk/errors/marginfi.d.ts +283 -0
- package/dist/marginfi-sdk/errors/marginfi.d.ts.map +1 -0
- package/dist/marginfi-sdk/errors/marginfi.js +515 -0
- package/dist/marginfi-sdk/index.d.ts +14 -0
- package/dist/marginfi-sdk/index.d.ts.map +1 -0
- package/dist/marginfi-sdk/index.js +29 -0
- package/dist/marginfi-sdk/instructions/index.d.ts +32 -0
- package/dist/marginfi-sdk/instructions/index.d.ts.map +1 -0
- package/dist/marginfi-sdk/instructions/index.js +47 -0
- package/dist/marginfi-sdk/instructions/lendingAccountBorrow.d.ts +30 -0
- package/dist/marginfi-sdk/instructions/lendingAccountBorrow.d.ts.map +1 -0
- package/dist/marginfi-sdk/instructions/lendingAccountBorrow.js +83 -0
- package/dist/marginfi-sdk/instructions/lendingAccountCloseBalance.d.ts +22 -0
- package/dist/marginfi-sdk/instructions/lendingAccountCloseBalance.d.ts.map +1 -0
- package/dist/marginfi-sdk/instructions/lendingAccountCloseBalance.js +53 -0
- package/dist/marginfi-sdk/instructions/lendingAccountDeposit.d.ts +29 -0
- package/dist/marginfi-sdk/instructions/lendingAccountDeposit.d.ts.map +1 -0
- package/dist/marginfi-sdk/instructions/lendingAccountDeposit.js +81 -0
- package/dist/marginfi-sdk/instructions/lendingAccountEndFlashloan.d.ts +20 -0
- package/dist/marginfi-sdk/instructions/lendingAccountEndFlashloan.d.ts.map +1 -0
- package/dist/marginfi-sdk/instructions/lendingAccountEndFlashloan.js +50 -0
- package/dist/marginfi-sdk/instructions/lendingAccountLiquidate.d.ts +32 -0
- package/dist/marginfi-sdk/instructions/lendingAccountLiquidate.d.ts.map +1 -0
- package/dist/marginfi-sdk/instructions/lendingAccountLiquidate.js +100 -0
- package/dist/marginfi-sdk/instructions/lendingAccountRepay.d.ts +31 -0
- package/dist/marginfi-sdk/instructions/lendingAccountRepay.d.ts.map +1 -0
- package/dist/marginfi-sdk/instructions/lendingAccountRepay.js +82 -0
- package/dist/marginfi-sdk/instructions/lendingAccountSettleEmissions.d.ts +20 -0
- package/dist/marginfi-sdk/instructions/lendingAccountSettleEmissions.d.ts.map +1 -0
- package/dist/marginfi-sdk/instructions/lendingAccountSettleEmissions.js +46 -0
- package/dist/marginfi-sdk/instructions/lendingAccountStartFlashloan.d.ts +25 -0
- package/dist/marginfi-sdk/instructions/lendingAccountStartFlashloan.d.ts.map +1 -0
- package/dist/marginfi-sdk/instructions/lendingAccountStartFlashloan.js +62 -0
- package/dist/marginfi-sdk/instructions/lendingAccountWithdraw.d.ts +32 -0
- package/dist/marginfi-sdk/instructions/lendingAccountWithdraw.d.ts.map +1 -0
- package/dist/marginfi-sdk/instructions/lendingAccountWithdraw.js +87 -0
- package/dist/marginfi-sdk/instructions/lendingAccountWithdrawEmissions.d.ts +27 -0
- package/dist/marginfi-sdk/instructions/lendingAccountWithdrawEmissions.d.ts.map +1 -0
- package/dist/marginfi-sdk/instructions/lendingAccountWithdrawEmissions.js +86 -0
- package/dist/marginfi-sdk/instructions/lendingPoolAccrueBankInterest.d.ts +20 -0
- package/dist/marginfi-sdk/instructions/lendingPoolAccrueBankInterest.d.ts.map +1 -0
- package/dist/marginfi-sdk/instructions/lendingPoolAccrueBankInterest.js +46 -0
- package/dist/marginfi-sdk/instructions/lendingPoolAddBank.d.ts +37 -0
- package/dist/marginfi-sdk/instructions/lendingPoolAddBank.d.ts.map +1 -0
- package/dist/marginfi-sdk/instructions/lendingPoolAddBank.js +127 -0
- package/dist/marginfi-sdk/instructions/lendingPoolAddBankWithSeed.d.ts +39 -0
- package/dist/marginfi-sdk/instructions/lendingPoolAddBankWithSeed.d.ts.map +1 -0
- package/dist/marginfi-sdk/instructions/lendingPoolAddBankWithSeed.js +128 -0
- package/dist/marginfi-sdk/instructions/lendingPoolCollectBankFees.d.ts +25 -0
- package/dist/marginfi-sdk/instructions/lendingPoolCollectBankFees.d.ts.map +1 -0
- package/dist/marginfi-sdk/instructions/lendingPoolCollectBankFees.js +76 -0
- package/dist/marginfi-sdk/instructions/lendingPoolConfigureBank.d.ts +46 -0
- package/dist/marginfi-sdk/instructions/lendingPoolConfigureBank.d.ts.map +1 -0
- package/dist/marginfi-sdk/instructions/lendingPoolConfigureBank.js +67 -0
- package/dist/marginfi-sdk/instructions/lendingPoolHandleBankruptcy.d.ts +26 -0
- package/dist/marginfi-sdk/instructions/lendingPoolHandleBankruptcy.d.ts.map +1 -0
- package/dist/marginfi-sdk/instructions/lendingPoolHandleBankruptcy.js +81 -0
- package/dist/marginfi-sdk/instructions/lendingPoolSetupEmissions.d.ts +35 -0
- package/dist/marginfi-sdk/instructions/lendingPoolSetupEmissions.d.ts.map +1 -0
- package/dist/marginfi-sdk/instructions/lendingPoolSetupEmissions.js +97 -0
- package/dist/marginfi-sdk/instructions/lendingPoolUpdateEmissionsParameters.d.ts +33 -0
- package/dist/marginfi-sdk/instructions/lendingPoolUpdateEmissionsParameters.d.ts.map +1 -0
- package/dist/marginfi-sdk/instructions/lendingPoolUpdateEmissionsParameters.js +85 -0
- package/dist/marginfi-sdk/instructions/marginfiAccountInitialize.d.ts +23 -0
- package/dist/marginfi-sdk/instructions/marginfiAccountInitialize.d.ts.map +1 -0
- package/dist/marginfi-sdk/instructions/marginfiAccountInitialize.js +76 -0
- package/dist/marginfi-sdk/instructions/marginfiGroupConfigure.d.ts +24 -0
- package/dist/marginfi-sdk/instructions/marginfiGroupConfigure.d.ts.map +1 -0
- package/dist/marginfi-sdk/instructions/marginfiGroupConfigure.js +52 -0
- package/dist/marginfi-sdk/instructions/marginfiGroupInitialize.d.ts +21 -0
- package/dist/marginfi-sdk/instructions/marginfiGroupInitialize.d.ts.map +1 -0
- package/dist/marginfi-sdk/instructions/marginfiGroupInitialize.js +57 -0
- package/dist/marginfi-sdk/instructions/setAccountFlag.d.ts +26 -0
- package/dist/marginfi-sdk/instructions/setAccountFlag.d.ts.map +1 -0
- package/dist/marginfi-sdk/instructions/setAccountFlag.js +60 -0
- package/dist/marginfi-sdk/instructions/setNewAccountAuthority.d.ts +23 -0
- package/dist/marginfi-sdk/instructions/setNewAccountAuthority.d.ts.map +1 -0
- package/dist/marginfi-sdk/instructions/setNewAccountAuthority.js +69 -0
- package/dist/marginfi-sdk/instructions/unsetAccountFlag.d.ts +26 -0
- package/dist/marginfi-sdk/instructions/unsetAccountFlag.d.ts.map +1 -0
- package/dist/marginfi-sdk/instructions/unsetAccountFlag.js +57 -0
- package/dist/marginfi-sdk/programs/index.d.ts +9 -0
- package/dist/marginfi-sdk/programs/index.d.ts.map +1 -0
- package/dist/marginfi-sdk/programs/index.js +24 -0
- package/dist/marginfi-sdk/programs/marginfi.d.ts +13 -0
- package/dist/marginfi-sdk/programs/marginfi.d.ts.map +1 -0
- package/dist/marginfi-sdk/programs/marginfi.js +36 -0
- package/dist/marginfi-sdk/shared/index.d.ts +54 -0
- package/dist/marginfi-sdk/shared/index.d.ts.map +1 -0
- package/dist/marginfi-sdk/shared/index.js +70 -0
- package/dist/marginfi-sdk/types/accountEventHeader.d.ts +23 -0
- package/dist/marginfi-sdk/types/accountEventHeader.d.ts.map +1 -0
- package/dist/marginfi-sdk/types/accountEventHeader.js +20 -0
- package/dist/marginfi-sdk/types/balance.d.ts +32 -0
- package/dist/marginfi-sdk/types/balance.d.ts.map +1 -0
- package/dist/marginfi-sdk/types/balance.js +25 -0
- package/dist/marginfi-sdk/types/balanceDecreaseType.d.ts +17 -0
- package/dist/marginfi-sdk/types/balanceDecreaseType.d.ts.map +1 -0
- package/dist/marginfi-sdk/types/balanceDecreaseType.js +24 -0
- package/dist/marginfi-sdk/types/balanceIncreaseType.d.ts +17 -0
- package/dist/marginfi-sdk/types/balanceIncreaseType.d.ts.map +1 -0
- package/dist/marginfi-sdk/types/balanceIncreaseType.js +24 -0
- package/dist/marginfi-sdk/types/balanceSide.d.ts +15 -0
- package/dist/marginfi-sdk/types/balanceSide.d.ts.map +1 -0
- package/dist/marginfi-sdk/types/balanceSide.js +22 -0
- package/dist/marginfi-sdk/types/bankConfig.d.ts +67 -0
- package/dist/marginfi-sdk/types/bankConfig.d.ts.map +1 -0
- package/dist/marginfi-sdk/types/bankConfig.js +32 -0
- package/dist/marginfi-sdk/types/bankConfigCompact.d.ts +65 -0
- package/dist/marginfi-sdk/types/bankConfigCompact.d.ts.map +1 -0
- package/dist/marginfi-sdk/types/bankConfigCompact.js +31 -0
- package/dist/marginfi-sdk/types/bankOperationalState.d.ts +16 -0
- package/dist/marginfi-sdk/types/bankOperationalState.d.ts.map +1 -0
- package/dist/marginfi-sdk/types/bankOperationalState.js +23 -0
- package/dist/marginfi-sdk/types/bankVaultType.d.ts +16 -0
- package/dist/marginfi-sdk/types/bankVaultType.d.ts.map +1 -0
- package/dist/marginfi-sdk/types/bankVaultType.js +23 -0
- package/dist/marginfi-sdk/types/groupEventHeader.d.ts +19 -0
- package/dist/marginfi-sdk/types/groupEventHeader.d.ts.map +1 -0
- package/dist/marginfi-sdk/types/groupEventHeader.js +18 -0
- package/dist/marginfi-sdk/types/index.d.ts +31 -0
- package/dist/marginfi-sdk/types/index.d.ts.map +1 -0
- package/dist/marginfi-sdk/types/index.js +46 -0
- package/dist/marginfi-sdk/types/interestRateConfig.d.ts +31 -0
- package/dist/marginfi-sdk/types/interestRateConfig.d.ts.map +1 -0
- package/dist/marginfi-sdk/types/interestRateConfig.js +25 -0
- package/dist/marginfi-sdk/types/interestRateConfigCompact.d.ts +29 -0
- package/dist/marginfi-sdk/types/interestRateConfigCompact.d.ts.map +1 -0
- package/dist/marginfi-sdk/types/interestRateConfigCompact.js +24 -0
- package/dist/marginfi-sdk/types/interestRateConfigOpt.d.ts +30 -0
- package/dist/marginfi-sdk/types/interestRateConfigOpt.d.ts.map +1 -0
- package/dist/marginfi-sdk/types/interestRateConfigOpt.js +24 -0
- package/dist/marginfi-sdk/types/lendingAccount.d.ts +19 -0
- package/dist/marginfi-sdk/types/lendingAccount.d.ts.map +1 -0
- package/dist/marginfi-sdk/types/lendingAccount.js +19 -0
- package/dist/marginfi-sdk/types/liquidationBalances.d.ts +17 -0
- package/dist/marginfi-sdk/types/liquidationBalances.d.ts.map +1 -0
- package/dist/marginfi-sdk/types/liquidationBalances.js +20 -0
- package/dist/marginfi-sdk/types/oracleConfig.d.ts +20 -0
- package/dist/marginfi-sdk/types/oracleConfig.d.ts.map +1 -0
- package/dist/marginfi-sdk/types/oracleConfig.js +19 -0
- package/dist/marginfi-sdk/types/oraclePriceType.d.ts +15 -0
- package/dist/marginfi-sdk/types/oraclePriceType.d.ts.map +1 -0
- package/dist/marginfi-sdk/types/oraclePriceType.js +22 -0
- package/dist/marginfi-sdk/types/oracleSetup.d.ts +17 -0
- package/dist/marginfi-sdk/types/oracleSetup.d.ts.map +1 -0
- package/dist/marginfi-sdk/types/oracleSetup.js +24 -0
- package/dist/marginfi-sdk/types/priceBias.d.ts +15 -0
- package/dist/marginfi-sdk/types/priceBias.d.ts.map +1 -0
- package/dist/marginfi-sdk/types/priceBias.js +22 -0
- package/dist/marginfi-sdk/types/requirementType.d.ts +16 -0
- package/dist/marginfi-sdk/types/requirementType.d.ts.map +1 -0
- package/dist/marginfi-sdk/types/requirementType.js +23 -0
- package/dist/marginfi-sdk/types/riskRequirementType.d.ts +16 -0
- package/dist/marginfi-sdk/types/riskRequirementType.d.ts.map +1 -0
- package/dist/marginfi-sdk/types/riskRequirementType.js +23 -0
- package/dist/marginfi-sdk/types/riskTier.d.ts +15 -0
- package/dist/marginfi-sdk/types/riskTier.d.ts.map +1 -0
- package/dist/marginfi-sdk/types/riskTier.js +22 -0
- package/dist/marginfi-sdk/types/wrappedI80F48.d.ts +16 -0
- package/dist/marginfi-sdk/types/wrappedI80F48.d.ts.map +1 -0
- package/dist/marginfi-sdk/types/wrappedI80F48.js +17 -0
- package/dist/transactions/index.d.ts +3 -0
- package/dist/transactions/index.d.ts.map +1 -0
- package/dist/transactions/index.js +18 -0
- package/dist/transactions/transactionUtils.d.ts +12 -0
- package/dist/transactions/transactionUtils.d.ts.map +1 -0
- package/dist/transactions/transactionUtils.js +262 -0
- package/dist/transactions/transactionsManager.d.ts +42 -0
- package/dist/transactions/transactionsManager.d.ts.map +1 -0
- package/dist/transactions/transactionsManager.js +246 -0
- package/dist/types/accounts.d.ts +8 -0
- package/dist/types/accounts.d.ts.map +1 -0
- package/dist/types/accounts.js +2 -0
- package/dist/types/index.d.ts +2 -0
- package/dist/types/index.d.ts.map +1 -0
- package/dist/types/index.js +17 -0
- package/dist/utils/accountUtils.d.ts +11 -0
- package/dist/utils/accountUtils.d.ts.map +1 -0
- package/dist/utils/accountUtils.js +60 -0
- package/dist/utils/deleteme.d.ts +2 -0
- package/dist/utils/deleteme.d.ts.map +1 -0
- package/dist/utils/deleteme.js +21 -0
- package/dist/utils/generalUtils.d.ts +11 -0
- package/dist/utils/generalUtils.d.ts.map +1 -0
- package/dist/utils/generalUtils.js +107 -0
- package/dist/utils/index.d.ts +9 -0
- package/dist/utils/index.d.ts.map +1 -0
- package/dist/utils/index.js +24 -0
- package/dist/utils/jitoUtils.d.ts +15 -0
- package/dist/utils/jitoUtils.d.ts.map +1 -0
- package/dist/utils/jitoUtils.js +108 -0
- package/dist/utils/jupiterUtils.d.ts +21 -0
- package/dist/utils/jupiterUtils.d.ts.map +1 -0
- package/dist/utils/jupiterUtils.js +61 -0
- package/dist/utils/local/shared.d.ts +3 -0
- package/dist/utils/local/shared.d.ts.map +1 -0
- package/dist/utils/local/shared.js +63 -0
- package/dist/utils/local/updateMarginfiLUT.d.ts +2 -0
- package/dist/utils/local/updateMarginfiLUT.d.ts.map +1 -0
- package/dist/utils/local/updateMarginfiLUT.js +22 -0
- package/dist/utils/local/updateSolautoLUT.d.ts +2 -0
- package/dist/utils/local/updateSolautoLUT.d.ts.map +1 -0
- package/dist/utils/local/updateSolautoLUT.js +13 -0
- package/dist/utils/marginfiUtils.d.ts +14 -0
- package/dist/utils/marginfiUtils.d.ts.map +1 -0
- package/dist/utils/marginfiUtils.js +201 -0
- package/dist/utils/numberUtils.d.ts +9 -0
- package/dist/utils/numberUtils.d.ts.map +1 -0
- package/dist/utils/numberUtils.js +62 -0
- package/dist/utils/solanaUtils.d.ts +18 -0
- package/dist/utils/solanaUtils.d.ts.map +1 -0
- package/dist/utils/solanaUtils.js +183 -0
- package/dist/utils/solauto/generalUtils.d.ts +51 -0
- package/dist/utils/solauto/generalUtils.d.ts.map +1 -0
- package/dist/utils/solauto/generalUtils.js +271 -0
- package/dist/utils/solauto/index.d.ts +3 -0
- package/dist/utils/solauto/index.d.ts.map +1 -0
- package/dist/utils/solauto/index.js +18 -0
- package/dist/utils/solauto/rebalanceUtils.d.ts +17 -0
- package/dist/utils/solauto/rebalanceUtils.d.ts.map +1 -0
- package/dist/utils/solauto/rebalanceUtils.js +199 -0
- package/package.json +37 -0
- package/src/clients/index.ts +1 -0
- package/src/clients/solautoClient.ts +684 -0
- package/src/clients/solautoMarginfiClient.ts +496 -0
- package/src/constants/README.md +9 -0
- package/src/constants/generalAccounts.ts +8 -0
- package/src/constants/index.ts +5 -0
- package/src/constants/marginfiAccounts.ts +24 -0
- package/src/constants/pythConstants.ts +10 -0
- package/src/constants/solautoConstants.ts +54 -0
- package/src/constants/tokenConstants.ts +9 -0
- package/src/generated/accounts/index.ts +10 -0
- package/src/generated/accounts/referralState.ts +159 -0
- package/src/generated/accounts/solautoPosition.ts +205 -0
- package/src/generated/errors/index.ts +9 -0
- package/src/generated/errors/solauto.ts +228 -0
- package/src/generated/index.ts +14 -0
- package/src/generated/instructions/cancelDCA.ts +161 -0
- package/src/generated/instructions/claimReferralFees.ts +159 -0
- package/src/generated/instructions/closePosition.ts +176 -0
- package/src/generated/instructions/convertReferralFees.ts +172 -0
- package/src/generated/instructions/index.ts +18 -0
- package/src/generated/instructions/marginfiOpenPosition.ts +275 -0
- package/src/generated/instructions/marginfiProtocolInteraction.ts +257 -0
- package/src/generated/instructions/marginfiRebalance.ts +274 -0
- package/src/generated/instructions/marginfiRefreshData.ts +147 -0
- package/src/generated/instructions/updatePosition.ts +173 -0
- package/src/generated/instructions/updateReferralStates.ts +166 -0
- package/src/generated/programs/index.ts +9 -0
- package/src/generated/programs/solauto.ts +52 -0
- package/src/generated/shared/index.ts +117 -0
- package/src/generated/types/automationSettings.ts +52 -0
- package/src/generated/types/automationSettingsInp.ts +43 -0
- package/src/generated/types/dCASettings.ts +45 -0
- package/src/generated/types/dCASettingsInp.ts +37 -0
- package/src/generated/types/feeType.ts +23 -0
- package/src/generated/types/index.ts +26 -0
- package/src/generated/types/lendingPlatform.ts +26 -0
- package/src/generated/types/podBool.ts +19 -0
- package/src/generated/types/positionData.ts +69 -0
- package/src/generated/types/positionState.ts +72 -0
- package/src/generated/types/positionTokenUsage.ts +67 -0
- package/src/generated/types/rebalanceData.ts +60 -0
- package/src/generated/types/solautoAction.ts +101 -0
- package/src/generated/types/solautoRebalanceType.ts +27 -0
- package/src/generated/types/solautoSettingsParameters.ts +62 -0
- package/src/generated/types/solautoSettingsParametersInp.ts +58 -0
- package/src/generated/types/tokenAmount.ts +29 -0
- package/src/generated/types/tokenBalanceAmount.ts +67 -0
- package/src/generated/types/updatePositionData.ts +49 -0
- package/src/index.ts +6 -0
- package/src/marginfi-sdk/accounts/bank.ts +311 -0
- package/src/marginfi-sdk/accounts/index.ts +11 -0
- package/src/marginfi-sdk/accounts/marginfiAccount.ts +195 -0
- package/src/marginfi-sdk/accounts/marginfiGroup.ts +164 -0
- package/src/marginfi-sdk/errors/index.ts +9 -0
- package/src/marginfi-sdk/errors/marginfi.ts +650 -0
- package/src/marginfi-sdk/index.ts +14 -0
- package/src/marginfi-sdk/instructions/index.ts +32 -0
- package/src/marginfi-sdk/instructions/lendingAccountBorrow.ts +167 -0
- package/src/marginfi-sdk/instructions/lendingAccountCloseBalance.ts +118 -0
- package/src/marginfi-sdk/instructions/lendingAccountDeposit.ts +164 -0
- package/src/marginfi-sdk/instructions/lendingAccountEndFlashloan.ts +113 -0
- package/src/marginfi-sdk/instructions/lendingAccountLiquidate.ts +186 -0
- package/src/marginfi-sdk/instructions/lendingAccountRepay.ts +171 -0
- package/src/marginfi-sdk/instructions/lendingAccountSettleEmissions.ts +108 -0
- package/src/marginfi-sdk/instructions/lendingAccountStartFlashloan.ts +138 -0
- package/src/marginfi-sdk/instructions/lendingAccountWithdraw.ts +177 -0
- package/src/marginfi-sdk/instructions/lendingAccountWithdrawEmissions.ts +160 -0
- package/src/marginfi-sdk/instructions/lendingPoolAccrueBankInterest.ts +108 -0
- package/src/marginfi-sdk/instructions/lendingPoolAddBank.ts +226 -0
- package/src/marginfi-sdk/instructions/lendingPoolAddBankWithSeed.ts +231 -0
- package/src/marginfi-sdk/instructions/lendingPoolCollectBankFees.ts +147 -0
- package/src/marginfi-sdk/instructions/lendingPoolConfigureBank.ts +181 -0
- package/src/marginfi-sdk/instructions/lendingPoolHandleBankruptcy.ts +154 -0
- package/src/marginfi-sdk/instructions/lendingPoolSetupEmissions.ts +190 -0
- package/src/marginfi-sdk/instructions/lendingPoolUpdateEmissionsParameters.ts +176 -0
- package/src/marginfi-sdk/instructions/marginfiAccountInitialize.ts +146 -0
- package/src/marginfi-sdk/instructions/marginfiGroupConfigure.ts +129 -0
- package/src/marginfi-sdk/instructions/marginfiGroupInitialize.ts +126 -0
- package/src/marginfi-sdk/instructions/setAccountFlag.ts +132 -0
- package/src/marginfi-sdk/instructions/setNewAccountAuthority.ts +137 -0
- package/src/marginfi-sdk/instructions/unsetAccountFlag.ts +130 -0
- package/src/marginfi-sdk/programs/index.ts +9 -0
- package/src/marginfi-sdk/programs/marginfi.ts +52 -0
- package/src/marginfi-sdk/shared/index.ts +117 -0
- package/src/marginfi-sdk/types/accountEventHeader.ts +44 -0
- package/src/marginfi-sdk/types/balance.ts +61 -0
- package/src/marginfi-sdk/types/balanceDecreaseType.ts +27 -0
- package/src/marginfi-sdk/types/balanceIncreaseType.ts +27 -0
- package/src/marginfi-sdk/types/balanceSide.ts +25 -0
- package/src/marginfi-sdk/types/bankConfig.ts +117 -0
- package/src/marginfi-sdk/types/bankConfigCompact.ts +114 -0
- package/src/marginfi-sdk/types/bankOperationalState.ts +26 -0
- package/src/marginfi-sdk/types/bankVaultType.ts +26 -0
- package/src/marginfi-sdk/types/groupEventHeader.ts +38 -0
- package/src/marginfi-sdk/types/index.ts +31 -0
- package/src/marginfi-sdk/types/interestRateConfig.ts +60 -0
- package/src/marginfi-sdk/types/interestRateConfigCompact.ts +52 -0
- package/src/marginfi-sdk/types/interestRateConfigOpt.ts +57 -0
- package/src/marginfi-sdk/types/lendingAccount.ts +38 -0
- package/src/marginfi-sdk/types/liquidationBalances.ts +33 -0
- package/src/marginfi-sdk/types/oracleConfig.ts +36 -0
- package/src/marginfi-sdk/types/oraclePriceType.ts +25 -0
- package/src/marginfi-sdk/types/oracleSetup.ts +27 -0
- package/src/marginfi-sdk/types/priceBias.ts +22 -0
- package/src/marginfi-sdk/types/requirementType.ts +26 -0
- package/src/marginfi-sdk/types/riskRequirementType.ts +26 -0
- package/src/marginfi-sdk/types/riskTier.ts +22 -0
- package/src/marginfi-sdk/types/wrappedI80F48.ts +22 -0
- package/src/transactions/index.ts +2 -0
- package/src/transactions/transactionUtils.ts +518 -0
- package/src/transactions/transactionsManager.ts +344 -0
- package/src/types/accounts.ts +7 -0
- package/src/types/index.ts +1 -0
- package/src/utils/accountUtils.ts +92 -0
- package/src/utils/deleteme.ts +40 -0
- package/src/utils/generalUtils.ts +123 -0
- package/src/utils/index.ts +8 -0
- package/src/utils/jitoUtils.ts +192 -0
- package/src/utils/jupiterUtils.ts +114 -0
- package/src/utils/local/shared.ts +85 -0
- package/src/utils/local/updateMarginfiLUT.ts +33 -0
- package/src/utils/local/updateSolautoLUT.ts +15 -0
- package/src/utils/marginfiUtils.ts +383 -0
- package/src/utils/numberUtils.ts +77 -0
- package/src/utils/solanaUtils.ts +333 -0
- package/src/utils/solauto/generalUtils.ts +371 -0
- package/src/utils/solauto/index.ts +2 -0
- package/src/utils/solauto/rebalanceUtils.ts +359 -0
- package/tests/shared.ts +15 -0
- package/tests/transactions/solautoMarginfi.ts +144 -0
- package/tests/unit/lookupTables.ts +40 -0
- package/tests/unit/rebalanceCalculations.ts +432 -0
- package/tsconfig.json +22 -0
@@ -0,0 +1,383 @@
|
|
1
|
+
import { PublicKey } from "@solana/web3.js";
|
2
|
+
import { publicKey } from "@metaplex-foundation/umi";
|
3
|
+
import { toWeb3JsPublicKey } from "@metaplex-foundation/umi-web3js-adapters";
|
4
|
+
import {
|
5
|
+
Bank,
|
6
|
+
getMarginfiAccountSize,
|
7
|
+
MARGINFI_PROGRAM_ID,
|
8
|
+
MarginfiAccount,
|
9
|
+
safeFetchAllMarginfiAccount,
|
10
|
+
safeFetchBank,
|
11
|
+
} from "../marginfi-sdk";
|
12
|
+
import { currentUnixSeconds, getTokenPrices } from "./generalUtils";
|
13
|
+
import {
|
14
|
+
bytesToI80F48,
|
15
|
+
fromBaseUnit,
|
16
|
+
getLiqUtilzationRateBps,
|
17
|
+
toBaseUnit,
|
18
|
+
} from "./numberUtils";
|
19
|
+
import { PRICES, UMI } from "../constants/solautoConstants";
|
20
|
+
import { MARGINFI_ACCOUNTS } from "../constants/marginfiAccounts";
|
21
|
+
import { MarginfiTokenAccounts } from "../types/accounts";
|
22
|
+
import { PositionState, PositionTokenUsage } from "../generated";
|
23
|
+
import { USD_DECIMALS } from "../constants/generalAccounts";
|
24
|
+
import { LivePositionUpdates } from "./solauto/generalUtils";
|
25
|
+
import { currentUnixSecondsSolana } from "./solanaUtils";
|
26
|
+
|
27
|
+
export function findMarginfiBankAccounts({
|
28
|
+
mint,
|
29
|
+
bank,
|
30
|
+
}: {
|
31
|
+
mint?: string;
|
32
|
+
bank?: string;
|
33
|
+
}): MarginfiTokenAccounts {
|
34
|
+
for (const key in MARGINFI_ACCOUNTS) {
|
35
|
+
const account = MARGINFI_ACCOUNTS[key];
|
36
|
+
if (mint && account.mint.toString().toLowerCase() === mint.toLowerCase()) {
|
37
|
+
return account;
|
38
|
+
}
|
39
|
+
if (bank && account.bank.toString().toLowerCase() === bank.toLowerCase()) {
|
40
|
+
return account;
|
41
|
+
}
|
42
|
+
}
|
43
|
+
throw new Error(`Marginfi accounts not found by the mint: ${mint}`);
|
44
|
+
}
|
45
|
+
|
46
|
+
export async function getMaxLtvAndLiqThreshold(
|
47
|
+
supplyBank: Bank,
|
48
|
+
debtBank: Bank,
|
49
|
+
supplyPrice?: number
|
50
|
+
): Promise<[number, number]> {
|
51
|
+
if (!PRICES[supplyBank.mint.toString()].price) {
|
52
|
+
const [price] = await getTokenPrices([toWeb3JsPublicKey(supplyBank.mint)]);
|
53
|
+
supplyPrice = price;
|
54
|
+
}
|
55
|
+
|
56
|
+
let maxLtv =
|
57
|
+
bytesToI80F48(supplyBank.config.assetWeightInit.value) /
|
58
|
+
bytesToI80F48(debtBank.config.liabilityWeightInit.value);
|
59
|
+
const liqThreshold =
|
60
|
+
bytesToI80F48(supplyBank.config.assetWeightMaint.value) /
|
61
|
+
bytesToI80F48(debtBank.config.liabilityWeightMaint.value);
|
62
|
+
|
63
|
+
const totalDepositedUsdValue =
|
64
|
+
fromBaseUnit(
|
65
|
+
BigInt(
|
66
|
+
Math.round(
|
67
|
+
bytesToI80F48(supplyBank!.totalAssetShares.value) *
|
68
|
+
bytesToI80F48(supplyBank!.assetShareValue.value)
|
69
|
+
)
|
70
|
+
),
|
71
|
+
supplyBank!.mintDecimals
|
72
|
+
) * supplyPrice!;
|
73
|
+
if (
|
74
|
+
supplyBank!.config.totalAssetValueInitLimit !== BigInt(0) &&
|
75
|
+
totalDepositedUsdValue > supplyBank!.config.totalAssetValueInitLimit
|
76
|
+
) {
|
77
|
+
const discount =
|
78
|
+
Number(supplyBank!.config.totalAssetValueInitLimit) /
|
79
|
+
totalDepositedUsdValue;
|
80
|
+
maxLtv = Math.round(maxLtv * Number(discount));
|
81
|
+
}
|
82
|
+
|
83
|
+
return [maxLtv, liqThreshold];
|
84
|
+
}
|
85
|
+
|
86
|
+
export async function getAllMarginfiAccountsByAuthority(
|
87
|
+
authority: PublicKey
|
88
|
+
): Promise<MarginfiAccount[]> {
|
89
|
+
const marginfiAccounts = await UMI.rpc.getProgramAccounts(
|
90
|
+
MARGINFI_PROGRAM_ID,
|
91
|
+
{
|
92
|
+
commitment: "finalized",
|
93
|
+
dataSlice: {
|
94
|
+
offset: 0,
|
95
|
+
length: 0,
|
96
|
+
},
|
97
|
+
filters: [
|
98
|
+
{
|
99
|
+
dataSize: getMarginfiAccountSize(),
|
100
|
+
},
|
101
|
+
{
|
102
|
+
memcmp: {
|
103
|
+
bytes: new Uint8Array(authority.toBuffer()),
|
104
|
+
offset: 40, // Anchor account discriminator + group pubkey
|
105
|
+
},
|
106
|
+
},
|
107
|
+
],
|
108
|
+
}
|
109
|
+
);
|
110
|
+
|
111
|
+
return safeFetchAllMarginfiAccount(
|
112
|
+
UMI,
|
113
|
+
marginfiAccounts.map((x) => x.publicKey)
|
114
|
+
);
|
115
|
+
}
|
116
|
+
|
117
|
+
async function getTokenUsage(
|
118
|
+
bank: Bank,
|
119
|
+
isAsset: boolean,
|
120
|
+
shares: number,
|
121
|
+
amountUsedAdjustment?: bigint
|
122
|
+
): Promise<PositionTokenUsage> {
|
123
|
+
let [marketPrice] = await getTokenPrices([toWeb3JsPublicKey(bank.mint)]);
|
124
|
+
const [assetShareValue, liabilityShareValue] =
|
125
|
+
await getUpToDateShareValues(bank);
|
126
|
+
const shareValue = isAsset ? assetShareValue : liabilityShareValue;
|
127
|
+
const amountUsed = shares * shareValue + Number(amountUsedAdjustment ?? 0);
|
128
|
+
|
129
|
+
const totalDeposited =
|
130
|
+
bytesToI80F48(bank.totalAssetShares.value) * assetShareValue;
|
131
|
+
const amountCanBeUsd = isAsset
|
132
|
+
? Number(bank.config.depositLimit) - totalDeposited
|
133
|
+
: totalDeposited -
|
134
|
+
bytesToI80F48(bank.totalLiabilityShares.value) * liabilityShareValue;
|
135
|
+
|
136
|
+
return {
|
137
|
+
mint: bank.mint,
|
138
|
+
decimals: bank.mintDecimals,
|
139
|
+
amountUsed: {
|
140
|
+
baseUnit: BigInt(Math.round(amountUsed)),
|
141
|
+
baseAmountUsdValue: toBaseUnit(
|
142
|
+
fromBaseUnit(BigInt(Math.round(amountUsed)), bank.mintDecimals) *
|
143
|
+
marketPrice,
|
144
|
+
USD_DECIMALS
|
145
|
+
),
|
146
|
+
},
|
147
|
+
amountCanBeUsed: {
|
148
|
+
baseUnit: BigInt(Math.round(amountCanBeUsd)),
|
149
|
+
baseAmountUsdValue: toBaseUnit(
|
150
|
+
fromBaseUnit(BigInt(Math.round(amountCanBeUsd)), bank.mintDecimals) *
|
151
|
+
marketPrice,
|
152
|
+
USD_DECIMALS
|
153
|
+
),
|
154
|
+
},
|
155
|
+
baseAmountMarketPriceUsd: toBaseUnit(marketPrice, USD_DECIMALS),
|
156
|
+
flashLoanFeeBps: 0,
|
157
|
+
borrowFeeBps: 0,
|
158
|
+
padding1: [],
|
159
|
+
padding2: [],
|
160
|
+
padding: new Uint8Array([]),
|
161
|
+
};
|
162
|
+
}
|
163
|
+
|
164
|
+
export async function getMarginfiAccountPositionState(
|
165
|
+
supplyMint: PublicKey,
|
166
|
+
debtMint: PublicKey,
|
167
|
+
marginfiAccount: MarginfiAccount | null,
|
168
|
+
livePositionUpdates?: LivePositionUpdates
|
169
|
+
): Promise<PositionState | undefined> {
|
170
|
+
let supplyBank: Bank | null =
|
171
|
+
supplyMint && supplyMint !== PublicKey.default
|
172
|
+
? await safeFetchBank(
|
173
|
+
UMI,
|
174
|
+
publicKey(
|
175
|
+
findMarginfiBankAccounts({ mint: supplyMint.toString() }).bank
|
176
|
+
)
|
177
|
+
)
|
178
|
+
: null;
|
179
|
+
let debtBank: Bank | null =
|
180
|
+
debtMint && debtMint !== PublicKey.default
|
181
|
+
? await safeFetchBank(
|
182
|
+
UMI,
|
183
|
+
publicKey(
|
184
|
+
findMarginfiBankAccounts({ mint: debtMint.toString() }).bank
|
185
|
+
)
|
186
|
+
)
|
187
|
+
: null;
|
188
|
+
|
189
|
+
let supplyUsage: PositionTokenUsage | undefined = undefined;
|
190
|
+
let debtUsage: PositionTokenUsage | undefined = undefined;
|
191
|
+
|
192
|
+
if (
|
193
|
+
marginfiAccount !== null &&
|
194
|
+
marginfiAccount.lendingAccount.balances.filter((x) => x.active).length > 0
|
195
|
+
) {
|
196
|
+
const supplyBalances = marginfiAccount.lendingAccount.balances.filter(
|
197
|
+
(balance) =>
|
198
|
+
balance.active && bytesToI80F48(balance.assetShares.value) > 0
|
199
|
+
);
|
200
|
+
const debtBalances = marginfiAccount.lendingAccount.balances.filter(
|
201
|
+
(balance) =>
|
202
|
+
balance.active && bytesToI80F48(balance.liabilityShares.value) > 0
|
203
|
+
);
|
204
|
+
|
205
|
+
for (const balance of supplyBalances) {
|
206
|
+
if (supplyBank === null) {
|
207
|
+
supplyBank = await safeFetchBank(UMI, balance.bankPk);
|
208
|
+
}
|
209
|
+
|
210
|
+
supplyUsage = await getTokenUsage(
|
211
|
+
supplyBank!,
|
212
|
+
true,
|
213
|
+
bytesToI80F48(balance.assetShares.value),
|
214
|
+
livePositionUpdates?.supplyAdjustment
|
215
|
+
);
|
216
|
+
break;
|
217
|
+
}
|
218
|
+
for (const balance of debtBalances) {
|
219
|
+
if (debtBank === null) {
|
220
|
+
debtBank = await safeFetchBank(UMI, balance.bankPk);
|
221
|
+
}
|
222
|
+
|
223
|
+
debtUsage = await getTokenUsage(
|
224
|
+
debtBank!,
|
225
|
+
false,
|
226
|
+
bytesToI80F48(balance.liabilityShares.value),
|
227
|
+
livePositionUpdates?.debtAdjustment
|
228
|
+
);
|
229
|
+
break;
|
230
|
+
}
|
231
|
+
}
|
232
|
+
|
233
|
+
if (supplyBank !== null && !supplyUsage) {
|
234
|
+
supplyUsage = await getTokenUsage(
|
235
|
+
supplyBank,
|
236
|
+
true,
|
237
|
+
0,
|
238
|
+
livePositionUpdates?.supplyAdjustment
|
239
|
+
);
|
240
|
+
}
|
241
|
+
|
242
|
+
if (debtBank !== null && !debtUsage) {
|
243
|
+
debtUsage = await getTokenUsage(
|
244
|
+
debtBank,
|
245
|
+
false,
|
246
|
+
0,
|
247
|
+
livePositionUpdates?.debtAdjustment
|
248
|
+
);
|
249
|
+
}
|
250
|
+
|
251
|
+
if (supplyBank === null || debtBank === null) {
|
252
|
+
return undefined;
|
253
|
+
}
|
254
|
+
|
255
|
+
const supplyPrice = PRICES[supplyMint.toString()].price;
|
256
|
+
let [maxLtv, liqThreshold] = await getMaxLtvAndLiqThreshold(
|
257
|
+
supplyBank,
|
258
|
+
debtBank,
|
259
|
+
supplyPrice
|
260
|
+
);
|
261
|
+
const supplyUsd = fromBaseUnit(
|
262
|
+
supplyUsage!.amountUsed.baseAmountUsdValue,
|
263
|
+
USD_DECIMALS
|
264
|
+
);
|
265
|
+
const debtUsd = fromBaseUnit(
|
266
|
+
debtUsage?.amountUsed?.baseAmountUsdValue ?? BigInt(0),
|
267
|
+
USD_DECIMALS
|
268
|
+
);
|
269
|
+
|
270
|
+
return {
|
271
|
+
liqUtilizationRateBps: getLiqUtilzationRateBps(
|
272
|
+
supplyUsd,
|
273
|
+
debtUsd,
|
274
|
+
Math.round(liqThreshold * 10000)
|
275
|
+
),
|
276
|
+
netWorth: {
|
277
|
+
baseAmountUsdValue: toBaseUnit(supplyUsd - debtUsd, USD_DECIMALS),
|
278
|
+
baseUnit: toBaseUnit(
|
279
|
+
(supplyUsd - debtUsd) / supplyPrice,
|
280
|
+
supplyUsage!.decimals
|
281
|
+
),
|
282
|
+
},
|
283
|
+
supply: supplyUsage!,
|
284
|
+
debt: debtUsage!,
|
285
|
+
maxLtvBps: Math.round(maxLtv * 10000),
|
286
|
+
liqThresholdBps: Math.round(liqThreshold * 10000),
|
287
|
+
lastUpdated: BigInt(currentUnixSeconds()),
|
288
|
+
padding1: [],
|
289
|
+
padding2: [],
|
290
|
+
padding: [],
|
291
|
+
};
|
292
|
+
}
|
293
|
+
|
294
|
+
function marginfiInterestRateCurve(
|
295
|
+
bank: Bank,
|
296
|
+
utilizationRatio: number
|
297
|
+
): number {
|
298
|
+
const optimalUr = bytesToI80F48(
|
299
|
+
bank.config.interestRateConfig.optimalUtilizationRate.value
|
300
|
+
);
|
301
|
+
const plateauIr = bytesToI80F48(
|
302
|
+
bank.config.interestRateConfig.plateauInterestRate.value
|
303
|
+
);
|
304
|
+
const maxIr = bytesToI80F48(
|
305
|
+
bank.config.interestRateConfig.maxInterestRate.value
|
306
|
+
);
|
307
|
+
|
308
|
+
if (utilizationRatio <= optimalUr) {
|
309
|
+
return (utilizationRatio / optimalUr) * plateauIr;
|
310
|
+
} else {
|
311
|
+
return (
|
312
|
+
((utilizationRatio - optimalUr) / (1 - optimalUr)) * (maxIr - plateauIr) +
|
313
|
+
plateauIr
|
314
|
+
);
|
315
|
+
}
|
316
|
+
}
|
317
|
+
|
318
|
+
function calcInterestRate(
|
319
|
+
bank: Bank,
|
320
|
+
utilizationRatio: number
|
321
|
+
): [number, number] {
|
322
|
+
const baseRate = marginfiInterestRateCurve(bank, utilizationRatio);
|
323
|
+
|
324
|
+
const lendingRate = baseRate * utilizationRatio;
|
325
|
+
|
326
|
+
const protocolIrFee = bytesToI80F48(
|
327
|
+
bank.config.interestRateConfig.protocolIrFee.value
|
328
|
+
);
|
329
|
+
const insuranceIrFee = bytesToI80F48(
|
330
|
+
bank.config.interestRateConfig.insuranceIrFee.value
|
331
|
+
);
|
332
|
+
const protocolFixedFeeApr = bytesToI80F48(
|
333
|
+
bank.config.interestRateConfig.protocolFixedFeeApr.value
|
334
|
+
);
|
335
|
+
const insuranceFixedFeeApr = bytesToI80F48(
|
336
|
+
bank.config.interestRateConfig.insuranceFeeFixedApr.value
|
337
|
+
);
|
338
|
+
const rateFee = protocolIrFee + insuranceIrFee;
|
339
|
+
const totalFixedFeeApr = protocolFixedFeeApr + insuranceFixedFeeApr;
|
340
|
+
const borrowingRate = baseRate * (1 + rateFee) * totalFixedFeeApr;
|
341
|
+
|
342
|
+
return [lendingRate, borrowingRate];
|
343
|
+
}
|
344
|
+
|
345
|
+
function calcAccruedInterestPaymentPerPeriod(
|
346
|
+
apr: number,
|
347
|
+
timeDelta: number,
|
348
|
+
shareValue: number
|
349
|
+
) {
|
350
|
+
const irPerPeriod = (apr * timeDelta) / 31_536_000; // Seconds per year
|
351
|
+
const newValue = shareValue * (1 + irPerPeriod);
|
352
|
+
return newValue;
|
353
|
+
}
|
354
|
+
|
355
|
+
export async function getUpToDateShareValues(
|
356
|
+
bank: Bank
|
357
|
+
): Promise<[number, number]> {
|
358
|
+
const currentTime = await currentUnixSecondsSolana();
|
359
|
+
let timeDelta = currentTime - Number(bank.lastUpdate);
|
360
|
+
|
361
|
+
const totalAssets =
|
362
|
+
bytesToI80F48(bank.totalAssetShares.value) *
|
363
|
+
bytesToI80F48(bank.assetShareValue.value);
|
364
|
+
const totalLiabilities =
|
365
|
+
bytesToI80F48(bank.totalLiabilityShares.value) *
|
366
|
+
bytesToI80F48(bank.liabilityShareValue.value);
|
367
|
+
|
368
|
+
const utilizationRatio = totalLiabilities / totalAssets;
|
369
|
+
const [lendingApr, borrowingApr] = calcInterestRate(bank, utilizationRatio);
|
370
|
+
|
371
|
+
return [
|
372
|
+
calcAccruedInterestPaymentPerPeriod(
|
373
|
+
lendingApr,
|
374
|
+
timeDelta,
|
375
|
+
bytesToI80F48(bank.assetShareValue.value)
|
376
|
+
),
|
377
|
+
calcAccruedInterestPaymentPerPeriod(
|
378
|
+
borrowingApr,
|
379
|
+
timeDelta,
|
380
|
+
bytesToI80F48(bank.liabilityShareValue.value)
|
381
|
+
),
|
382
|
+
];
|
383
|
+
}
|
@@ -0,0 +1,77 @@
|
|
1
|
+
|
2
|
+
export function getLiqUtilzationRateBps(supplyUsd: number, debtUsd: number, liqThresholdBps: number): number {
|
3
|
+
if (supplyUsd === 0) {
|
4
|
+
return 0;
|
5
|
+
}
|
6
|
+
|
7
|
+
return toBps(debtUsd / (supplyUsd * fromBps(liqThresholdBps)));
|
8
|
+
}
|
9
|
+
|
10
|
+
export function toBaseUnit(value: number, decimals: number): bigint {
|
11
|
+
return BigInt(Math.round(value * Math.pow(10, decimals)));
|
12
|
+
}
|
13
|
+
|
14
|
+
export function fromBaseUnit(value: bigint, decimals: number): number {
|
15
|
+
return Number(value) / Math.pow(10, decimals);
|
16
|
+
}
|
17
|
+
|
18
|
+
export function fromBps(value: number): number {
|
19
|
+
return value / 10000;
|
20
|
+
}
|
21
|
+
|
22
|
+
export function toBps(value: number): number {
|
23
|
+
return Math.round(value * 10000);
|
24
|
+
}
|
25
|
+
|
26
|
+
export function bytesToI80F48(bytes: number[]): number {
|
27
|
+
if (bytes.length !== 16) {
|
28
|
+
throw new Error('Byte array must be exactly 16 bytes.');
|
29
|
+
}
|
30
|
+
|
31
|
+
const reversedBytes = bytes.slice().reverse();
|
32
|
+
|
33
|
+
let integerPart = BigInt(0);
|
34
|
+
let fractionalPart = BigInt(0);
|
35
|
+
|
36
|
+
for (let i = 0; i < 10; i++) {
|
37
|
+
integerPart = (integerPart << 8n) | BigInt(reversedBytes[i]);
|
38
|
+
}
|
39
|
+
|
40
|
+
for (let i = 10; i < 16; i++) {
|
41
|
+
fractionalPart = (fractionalPart << 8n) | BigInt(reversedBytes[i]);
|
42
|
+
}
|
43
|
+
|
44
|
+
const fullValue = integerPart * BigInt(2 ** 48) + fractionalPart;
|
45
|
+
|
46
|
+
return Number(fullValue) / (2 ** 48);
|
47
|
+
}
|
48
|
+
|
49
|
+
export function uint8ArrayToBigInt(uint8Array: Uint8Array): bigint {
|
50
|
+
if (uint8Array.length !== 8) {
|
51
|
+
throw new Error('Uint8Array must be exactly 8 bytes long to convert to u64.');
|
52
|
+
}
|
53
|
+
|
54
|
+
const buffer = uint8Array.buffer;
|
55
|
+
|
56
|
+
const dataView = new DataView(buffer);
|
57
|
+
|
58
|
+
const low = dataView.getUint32(0, true);
|
59
|
+
const high = dataView.getUint32(4, true);
|
60
|
+
|
61
|
+
return BigInt(high) << 32n | BigInt(low);
|
62
|
+
}
|
63
|
+
|
64
|
+
export function getDebtAdjustmentUsd(
|
65
|
+
liqThresholdBps: number,
|
66
|
+
supplyUsd: number,
|
67
|
+
debtUsd: number,
|
68
|
+
targetLiqUtilizationRateBps: number,
|
69
|
+
adjustmentFeeBps?: number
|
70
|
+
) {
|
71
|
+
const adjustmentFee = adjustmentFeeBps && adjustmentFeeBps > 0 ? fromBps(adjustmentFeeBps) : 0;
|
72
|
+
const liqThreshold = fromBps(liqThresholdBps);
|
73
|
+
const targetLiqUtilizationRate = fromBps(targetLiqUtilizationRateBps);
|
74
|
+
|
75
|
+
const debtAdjustmentUsd = (targetLiqUtilizationRate * supplyUsd * liqThreshold - debtUsd) / (1 - targetLiqUtilizationRate * (1 - adjustmentFee) * liqThreshold);
|
76
|
+
return debtAdjustmentUsd;
|
77
|
+
}
|