Skip to content

Commit 50d113c

Browse files
authored
feat(withdraw): allow a useMax field in withdraw shortcuts to withdraw the maximum amount on aave (#531)
1 parent 14e278f commit 50d113c

File tree

2 files changed

+12
-2
lines changed

2 files changed

+12
-2
lines changed

src/apps/aave/shortcuts.ts

+11-2
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,10 @@
1-
import { Address, encodeFunctionData, parseUnits, erc20Abi } from 'viem'
1+
import {
2+
Address,
3+
encodeFunctionData,
4+
parseUnits,
5+
erc20Abi,
6+
maxUint256,
7+
} from 'viem'
28
import {
39
createShortcut,
410
ShortcutsHook,
@@ -141,7 +147,10 @@ const hook: ShortcutsHook = {
141147
const transactions: Transaction[] = []
142148

143149
// amount in smallest unit
144-
const amountToWithdraw = parseUnits(tokens[0].amount, tokenDecimals)
150+
// useMax Withdraws entire balance https://docs.aave.com/developers/core-contracts/pool#withdraw
151+
const amountToWithdraw = tokens[0].useMax
152+
? maxUint256
153+
: parseUnits(tokens[0].amount, tokenDecimals)
145154

146155
const client = getClient(networkId)
147156

src/types/shortcuts.ts

+1
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ export const tokenAmounts = z
1515
z.object({
1616
tokenId: z.string(),
1717
amount: z.string(),
18+
useMax: z.boolean().optional(),
1819
}),
1920
)
2021
.nonempty()

0 commit comments

Comments
 (0)