From 44d5d5e42c34320b4562710f22c6561bb6847d97 Mon Sep 17 00:00:00 2001 From: Yusuf Seyrek Date: Tue, 29 Aug 2023 00:26:06 +0300 Subject: [PATCH] feat(vaults): implement auto-lend to withdrawals (#402) --- src/store/slices/broadcast.ts | 15 ++++++++++++++- 1 file changed, 14 insertions(+), 1 deletion(-) diff --git a/src/store/slices/broadcast.ts b/src/store/slices/broadcast.ts index 54917e30..fa2bf7a8 100644 --- a/src/store/slices/broadcast.ts +++ b/src/store/slices/broadcast.ts @@ -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, [])], })