|
| 1 | +import type { Reserve } from '@aave/graphql'; |
| 2 | +import { assertOk, bigDecimal, evmAddress } from '@aave/types'; |
| 3 | +import { beforeAll, describe, expect, it } from 'vitest'; |
| 4 | +import { |
| 5 | + client, |
| 6 | + createNewWallet, |
| 7 | + fetchReserve, |
| 8 | + fundErc20Address, |
| 9 | + fundNativeAddress, |
| 10 | + WETH_ADDRESS, |
| 11 | +} from '../test-utils'; |
| 12 | +import { sendWith } from '../viem'; |
| 13 | +import { supply } from './transactions'; |
| 14 | +import { userSupplies } from './user'; |
| 15 | + |
| 16 | +describe('Given an Aave Market', () => { |
| 17 | + describe('When the user supplies tokens to a Reserve', () => { |
| 18 | + const wallet = createNewWallet(); |
| 19 | + const amountToSupply = '0.01'; |
| 20 | + let reserveInfo: Reserve; |
| 21 | + |
| 22 | + beforeAll(async () => { |
| 23 | + await fundErc20Address( |
| 24 | + WETH_ADDRESS, |
| 25 | + evmAddress(wallet.account!.address), |
| 26 | + bigDecimal('0.02'), |
| 27 | + ); |
| 28 | + |
| 29 | + reserveInfo = await fetchReserve(WETH_ADDRESS); |
| 30 | + // Check if the reserve is not frozen or paused |
| 31 | + expect(reserveInfo.isFrozen).toBe(false); |
| 32 | + expect(reserveInfo.isPaused).toBe(false); |
| 33 | + }); |
| 34 | + |
| 35 | + it(`Then it should be available in the user's supply positions`, async () => { |
| 36 | + const result = await supply(client, { |
| 37 | + market: reserveInfo.market.address, |
| 38 | + supplier: evmAddress(wallet.account!.address), |
| 39 | + amount: { |
| 40 | + erc20: { |
| 41 | + value: amountToSupply, |
| 42 | + currency: WETH_ADDRESS, |
| 43 | + }, |
| 44 | + }, |
| 45 | + chainId: reserveInfo.market.chain.chainId, |
| 46 | + }) |
| 47 | + .andThen(sendWith(wallet)) |
| 48 | + .andThen(() => |
| 49 | + userSupplies(client, { |
| 50 | + markets: [ |
| 51 | + { |
| 52 | + address: reserveInfo.market.address, |
| 53 | + chainId: reserveInfo.market.chain.chainId, |
| 54 | + }, |
| 55 | + ], |
| 56 | + user: evmAddress(wallet.account!.address), |
| 57 | + }), |
| 58 | + ); |
| 59 | + assertOk(result); |
| 60 | + expect(result.value).toEqual([ |
| 61 | + expect.objectContaining({ |
| 62 | + balance: expect.objectContaining({ |
| 63 | + amount: expect.objectContaining({ |
| 64 | + value: expect.toBeBigDecimalCloseTo(amountToSupply), |
| 65 | + }), |
| 66 | + }), |
| 67 | + }), |
| 68 | + ]); |
| 69 | + }, 25_000); |
| 70 | + }); |
| 71 | + |
| 72 | + describe('And the Reserve allows to supply in native tokens', () => { |
| 73 | + let reserveInfo: Reserve; |
| 74 | + |
| 75 | + beforeAll(async () => { |
| 76 | + reserveInfo = await fetchReserve(WETH_ADDRESS); |
| 77 | + // Check if the reserve is not frozen or paused |
| 78 | + expect(reserveInfo.isFrozen).toBe(false); |
| 79 | + expect(reserveInfo.isPaused).toBe(false); |
| 80 | + // And accepts native tokens |
| 81 | + expect(reserveInfo.acceptsNative?.symbol).toEqual('ETH'); |
| 82 | + }); |
| 83 | + |
| 84 | + describe('When the user supplies to the reserve in native tokens', () => { |
| 85 | + const wallet = createNewWallet(); |
| 86 | + const amountToSupply = '0.01'; |
| 87 | + |
| 88 | + beforeAll(async () => { |
| 89 | + await fundNativeAddress( |
| 90 | + evmAddress(wallet.account!.address), |
| 91 | + bigDecimal('0.02'), |
| 92 | + ); |
| 93 | + }); |
| 94 | + |
| 95 | + it(`Then it should be available in the user's supply positions`, async () => { |
| 96 | + const result = await supply(client, { |
| 97 | + market: reserveInfo.market.address, |
| 98 | + supplier: evmAddress(wallet.account!.address), |
| 99 | + amount: { |
| 100 | + native: amountToSupply, |
| 101 | + }, |
| 102 | + chainId: reserveInfo.market.chain.chainId, |
| 103 | + }) |
| 104 | + .andThen(sendWith(wallet)) |
| 105 | + .andThen(() => |
| 106 | + userSupplies(client, { |
| 107 | + markets: [ |
| 108 | + { |
| 109 | + address: reserveInfo.market.address, |
| 110 | + chainId: reserveInfo.market.chain.chainId, |
| 111 | + }, |
| 112 | + ], |
| 113 | + user: evmAddress(wallet.account!.address), |
| 114 | + }), |
| 115 | + ); |
| 116 | + assertOk(result); |
| 117 | + expect(result.value).toEqual([ |
| 118 | + expect.objectContaining({ |
| 119 | + balance: expect.objectContaining({ |
| 120 | + amount: expect.objectContaining({ |
| 121 | + value: expect.toBeBigDecimalCloseTo(amountToSupply), |
| 122 | + }), |
| 123 | + }), |
| 124 | + }), |
| 125 | + ]); |
| 126 | + }, 25_000); |
| 127 | + }); |
| 128 | + }); |
| 129 | +}); |
0 commit comments