feat(vaults): implement auto-lend to withdrawals (#402)

This commit is contained in:
Yusuf Seyrek 2023-08-29 00:26:06 +03:00 committed by GitHub
parent 69af852491
commit 44d5d5e42c
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -11,7 +11,7 @@ import {
Action as CreditManagerAction,
ExecuteMsg as CreditManagerExecuteMsg,
} from 'types/generated/mars-credit-manager/MarsCreditManager.types'
import { getAssetByDenom } from 'utils/assets'
import { getAssetByDenom, getAssetBySymbol } from 'utils/assets'
import { getSingleValueFromBroadcastResult } from 'utils/broadcast'
import checkAutoLendEnabled from 'utils/checkAutoLendEnabled'
import { defaultFee } from 'utils/constants'
@ -279,6 +279,19 @@ export default function createBroadcastSlice(
},
}
if (checkAutoLendEnabled(options.accountId)) {
for (const vault of options.vaults) {
for (const symbol of Object.values(vault.symbols)) {
const asset = getAssetBySymbol(symbol)
if (asset?.isAutoLendEnabled) {
msg.update_credit_account.actions.push({
lend: { denom: asset.denom, amount: 'account_balance' },
})
}
}
}
}
const response = await get().executeMsg({
messages: [generateExecutionMessage(get().address, ENV.ADDRESS_CREDIT_MANAGER, msg, [])],
})