|
1 | 1 | import { |
2 | 2 | BorrowQuery, |
3 | 3 | type BorrowRequest, |
| 4 | + RepayQuery, |
| 5 | + type RepayRequest, |
| 6 | + SupplyQuery, |
| 7 | + type SupplyRequest, |
4 | 8 | type Transaction, |
| 9 | + WithdrawQuery, |
| 10 | + type WithdrawRequest, |
5 | 11 | } from '@aave/graphql'; |
6 | 12 | import type { ResultAsync } from '@aave/types'; |
7 | 13 | import type { AaveClient } from '../client'; |
@@ -34,3 +40,87 @@ export function borrow( |
34 | 40 | ): ResultAsync<Transaction, UnexpectedError> { |
35 | 41 | return client.query(BorrowQuery, { request }); |
36 | 42 | } |
| 43 | + |
| 44 | +/** |
| 45 | + * Creates a transaction to supply to a market. |
| 46 | + * |
| 47 | + * ```ts |
| 48 | + * const result = await supply(client, { |
| 49 | + * market: evmAddress('0x87870bca3f3fd6335c3f4ce8392d69350b4fa4e2'), |
| 50 | + * amount: { |
| 51 | + * erc20: { |
| 52 | + * currency: evmAddress('0xa0b86a33e6441c8c5f0bb9b7e5e1f8bbf5b78b5c'), |
| 53 | + * value: '1000' |
| 54 | + * } |
| 55 | + * }, |
| 56 | + * supplier: evmAddress('0x742d35cc6e5c4ce3b69a2a8c7c8e5f7e9a0b1234'), |
| 57 | + * chainId: chainId(1) |
| 58 | + * }); |
| 59 | + * ``` |
| 60 | + * |
| 61 | + * @param client - Aave client. |
| 62 | + * @param request - The supply request parameters. |
| 63 | + * @returns The transaction data, approval requirements, or insufficient balance error. |
| 64 | + */ |
| 65 | +export function supply( |
| 66 | + client: AaveClient, |
| 67 | + request: SupplyRequest, |
| 68 | +): ResultAsync<Transaction, UnexpectedError> { |
| 69 | + return client.query(SupplyQuery, { request }); |
| 70 | +} |
| 71 | + |
| 72 | +/** |
| 73 | + * Creates a transaction to repay to a market. |
| 74 | + * |
| 75 | + * ```ts |
| 76 | + * const result = await repay(client, { |
| 77 | + * market: evmAddress('0x87870bca3f3fd6335c3f4ce8392d69350b4fa4e2'), |
| 78 | + * amount: { |
| 79 | + * erc20: { |
| 80 | + * currency: evmAddress('0xa0b86a33e6441c8c5f0bb9b7e5e1f8bbf5b78b5c'), |
| 81 | + * value: '500' |
| 82 | + * } |
| 83 | + * }, |
| 84 | + * borrower: evmAddress('0x742d35cc6e5c4ce3b69a2a8c7c8e5f7e9a0b1234'), |
| 85 | + * chainId: chainId(1) |
| 86 | + * }); |
| 87 | + * ``` |
| 88 | + * |
| 89 | + * @param client - Aave client. |
| 90 | + * @param request - The repay request parameters. |
| 91 | + * @returns The transaction data, approval requirements, or insufficient balance error. |
| 92 | + */ |
| 93 | +export function repay( |
| 94 | + client: AaveClient, |
| 95 | + request: RepayRequest, |
| 96 | +): ResultAsync<Transaction, UnexpectedError> { |
| 97 | + return client.query(RepayQuery, { request }); |
| 98 | +} |
| 99 | + |
| 100 | +/** |
| 101 | + * Creates a transaction to withdraw from a market. |
| 102 | + * |
| 103 | + * ```ts |
| 104 | + * const result = await withdraw(client, { |
| 105 | + * market: evmAddress('0x87870bca3f3fd6335c3f4ce8392d69350b4fa4e2'), |
| 106 | + * amount: { |
| 107 | + * erc20: { |
| 108 | + * currency: evmAddress('0xa0b86a33e6441c8c5f0bb9b7e5e1f8bbf5b78b5c'), |
| 109 | + * value: '750' |
| 110 | + * } |
| 111 | + * }, |
| 112 | + * supplier: evmAddress('0x742d35cc6e5c4ce3b69a2a8c7c8e5f7e9a0b1234'), |
| 113 | + * chainId: chainId(1) |
| 114 | + * }); |
| 115 | + * ``` |
| 116 | + * |
| 117 | + * @param client - Aave client. |
| 118 | + * @param request - The withdraw request parameters. |
| 119 | + * @returns The transaction data, approval requirements, or insufficient balance error. |
| 120 | + */ |
| 121 | +export function withdraw( |
| 122 | + client: AaveClient, |
| 123 | + request: WithdrawRequest, |
| 124 | +): ResultAsync<Transaction, UnexpectedError> { |
| 125 | + return client.query(WithdrawQuery, { request }); |
| 126 | +} |
0 commit comments