-
Notifications
You must be signed in to change notification settings - Fork 5
test: supply test #56
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from 17 commits
Commits
Show all changes
22 commits
Select commit
Hold shift + click to select a range
fd08727
fix: supply example
juangm f3652ca
test: reorganize specs
juangm f40a4bd
Merge branch 'main' into juan/supply-tests
juangm 535f951
Merge branch 'main' into juan/supply-tests
juangm 2358e65
Merge branch 'main' into juan/supply-tests
juangm 5950976
Merge branch 'main' into juan/supply-tests
juangm 4391160
fix
juangm 3ce6097
Merge branch 'main' into juan/supply-tests
juangm 7d5db3f
test: borrow test
juangm eea0b44
fix: assertion to check borrow amount
juangm c6d657d
Merge branch 'main' into juan/supply-tests
juangm cf4129f
test: repay scenarios
juangm bd0a0e6
test: withdraw scenario
juangm 83dd9c7
fix: remove not needed package
juangm d70712d
Merge branch 'main' into juan/supply-tests
juangm 84b0e49
fix: not use import from types-next
juangm ff2f5c7
Merge branch 'main' into juan/supply-tests
juangm 5025efa
fix: add new assertions and refactor fundErc20Address
juangm f180623
fix: add new assertions and refactor fundErc20Address
juangm 2088383
fix
juangm 7a29809
fix: remove not needed file
juangm f642dc5
fix
juangm File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,19 @@ | ||
| // Vitest Snapshot v1, https://vitest.dev/guide/snapshot.html | ||
|
|
||
| exports[`Aave V4 Borrow Scenarios > Given a user with a supply position as collateral > When the user borrows an ERC20 asset > Then the user's borrow positions are updated 1`] = ` | ||
| { | ||
| "__typename": "DecimalValue", | ||
| "decimals": 18, | ||
| "formatted": "0.000000000000000050", | ||
| "raw": 50n, | ||
| } | ||
| `; | ||
|
|
||
| exports[`Aave V4 Borrow Scenarios > Given a user with a supply position as collateral > When the user borrows an ERC20 asset > Then the user's borrow positions are updated 2`] = ` | ||
| { | ||
| "__typename": "DecimalValue", | ||
| "decimals": 18, | ||
| "formatted": "0.000000000000000050", | ||
| "raw": 50n, | ||
| } | ||
| `; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,81 @@ | ||
| import { assertOk, bigDecimal, evmAddress } from '@aave/client-next'; | ||
| import { borrow, userBorrows } from '@aave/client-next/actions'; | ||
| import { | ||
| client, | ||
| createNewWallet, | ||
| ETHEREUM_USDC_ADDRESS, | ||
| fundErc20Address, | ||
| } from '@aave/client-next/test-utils'; | ||
| import { sendWith } from '@aave/client-next/viem'; | ||
| import type { Reserve } from '@aave/graphql-next'; | ||
| import { beforeAll, describe, expect, it } from 'vitest'; | ||
| import { supplyToRandomERC20Reserve } from './helper'; | ||
|
|
||
| describe('Aave V4 Borrow Scenarios', () => { | ||
| describe('Given a user with a supply position as collateral', () => { | ||
| describe('When the user borrows an ERC20 asset', () => { | ||
| const user = createNewWallet(); | ||
| let reserve: Reserve; | ||
|
|
||
| beforeAll(async () => { | ||
| const setup = await fundErc20Address( | ||
| ETHEREUM_USDC_ADDRESS, | ||
| evmAddress(user.account!.address), | ||
| bigDecimal('100'), | ||
| 6, | ||
| ).andThen(() => | ||
| supplyToRandomERC20Reserve(client, user, ETHEREUM_USDC_ADDRESS), | ||
| ); | ||
|
|
||
| assertOk(setup); | ||
| reserve = setup.value; | ||
| }); | ||
|
|
||
| it(`Then the user's borrow positions are updated`, async () => { | ||
| const result = await borrow(client, { | ||
| sender: evmAddress(user.account!.address), | ||
| reserve: { | ||
| spoke: reserve.spoke.address, | ||
| reserveId: reserve.id, | ||
| chainId: reserve.chain.chainId, | ||
| }, | ||
| amount: { | ||
| erc20: { | ||
| value: bigDecimal('50'), | ||
| }, | ||
| }, | ||
| }) | ||
| .andThen(sendWith(user)) | ||
| .andThen(client.waitForTransaction) | ||
| .andThen(() => | ||
| userBorrows(client, { | ||
| query: { | ||
| userSpoke: { | ||
| spoke: { | ||
| address: reserve.spoke.address, | ||
| chainId: reserve.chain.chainId, | ||
| }, | ||
| user: evmAddress(user.account!.address), | ||
| }, | ||
| }, | ||
| }), | ||
| ); | ||
|
|
||
| assertOk(result); | ||
| expect(result.value.length).toBe(1); | ||
| // BUG: The amount is slightly different from the total borrow amount | ||
| // expect(result.value[0]?.amount.value).toMatchSnapshot(); | ||
| expect(Number(result.value[0]?.amount.value.formatted)).toBeCloseTo( | ||
| Number(bigDecimal('50')), | ||
| 4, | ||
| ); | ||
| expect(result.value[0]?.paid.value).toMatchSnapshot(); | ||
| expect(result.value[0]?.amount.isWrappedNative).toBe(false); | ||
| }); | ||
| }); | ||
|
|
||
| describe('When the user borrows from a reserve that supports native borrowing', () => { | ||
| it.todo(`Then the user's borrow positions are updated`); | ||
| }); | ||
| }); | ||
| }); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,75 @@ | ||
| import type { AaveClient, Reserve, SupplyRequest } from '@aave/client-next'; | ||
| import { | ||
| bigDecimal, | ||
| chainId, | ||
| type EvmAddress, | ||
| evmAddress, | ||
| invariant, | ||
| type ResultAsync, | ||
| type TxHash, | ||
| } from '@aave/client-next'; | ||
| import { reserves, supply } from '@aave/client-next/actions'; | ||
| import { sendWith } from '@aave/client-next/viem'; | ||
| import type { WalletClient } from 'viem'; | ||
|
|
||
| export function supplyToReserve( | ||
| client: AaveClient, | ||
| request: SupplyRequest, | ||
| user: WalletClient, | ||
| ): ResultAsync<TxHash, Error> { | ||
| return supply(client, request) | ||
| .andThen(sendWith(user)) | ||
| .andThen(client.waitForTransaction); | ||
| } | ||
|
|
||
| export function findReserveToSupply( | ||
| client: AaveClient, | ||
| token: EvmAddress, | ||
| ): ResultAsync<Reserve, Error> { | ||
| return reserves(client, { | ||
| query: { | ||
| tokens: [ | ||
| { | ||
| chainId: chainId(1), | ||
| address: token, | ||
| }, | ||
| ], | ||
| }, | ||
| }).map((listReserves) => { | ||
| invariant( | ||
| listReserves.length > 0, | ||
| `No reserves found for the token ${token}`, | ||
| ); | ||
| const reserveToSupply = listReserves.find( | ||
| (reserve) => reserve.canSupply === true, | ||
| ); | ||
| invariant( | ||
| reserveToSupply, | ||
| `No reserve found to supply to for the token ${token}`, | ||
| ); | ||
| return reserveToSupply; | ||
| }); | ||
| } | ||
|
|
||
| export function supplyToRandomERC20Reserve( | ||
| client: AaveClient, | ||
| user: WalletClient, | ||
| token: EvmAddress, | ||
| amount = bigDecimal('100'), | ||
| ): ResultAsync<Reserve, Error> { | ||
| return findReserveToSupply(client, token).andThen((reserve) => | ||
| supplyToReserve( | ||
| client, | ||
| { | ||
| reserve: { | ||
| reserveId: reserve.id, | ||
| chainId: reserve.chain.chainId, | ||
| spoke: reserve.spoke.address, | ||
| }, | ||
| amount: { erc20: { value: amount } }, | ||
| sender: evmAddress(user.account!.address), | ||
| }, | ||
| user, | ||
| ).map(() => reserve), | ||
| ); | ||
| } | ||
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,14 @@ | ||
| import { describe, it } from 'vitest'; | ||
|
|
||
| describe('Aave V4 User Supply Positions Scenarios', () => { | ||
| describe('Given a user with a more than one supply position', () => { | ||
| describe('When fetching supply positions ordered by', () => { | ||
| it.todo('Then it should return the supply positions ordered by amount'); | ||
| it.todo('Then it should return the supply positions ordered by earned'); | ||
| it.todo( | ||
| 'Then it should return the supply positions ordered by isCollateral', | ||
| ); | ||
| it.todo('Then it should return the supply positions ordered by reserve'); | ||
| }); | ||
| }); | ||
| }); |
10 changes: 0 additions & 10 deletions
10
packages/spec/borrow.spec.ts → packages/spec/positions/userBorrow.todo.ts
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
File renamed without changes.
File renamed without changes.
This file was deleted.
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
filter by supply reserves to make this semantically correct.