-
Notifications
You must be signed in to change notification settings - Fork 5
test: check userPositions match (totalCollateral, totalSupplied, totalDebt, netBalance) #212
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
Open
juangm
wants to merge
24
commits into
main
Choose a base branch
from
test/math-check-user-position-summary
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from 12 commits
Commits
Show all changes
24 commits
Select commit
Hold shift + click to select a range
33271fb
core: refactor helper to include fund wallet when doing a supply
juangm a178888
test: userPosition math checks v1
juangm d372e31
Merge branch 'main' into test/math-check-user-position-summary
juangm b3011e6
fix: rename test scenario
juangm b45b497
fix: add changeset
juangm 9069110
Merge branch 'main' into test/math-check-user-position-summary
juangm 05c6da4
feat: add helper to call getAcccountData in the spoke contract
juangm 48daa14
test: add healthFactor math calculations
juangm 4b0981e
test: check netCollateral and averageCollateralFactor
juangm 202a5f1
Merge branch 'main' into test/math-check-user-position-summary
juangm de40ff1
Merge branch 'main' into test/math-check-user-position-summary
juangm 5f93a96
Merge branch 'main' into test/math-check-user-position-summary
juangm 6930de7
Merge branch 'main' into test/math-check-user-position-summary
juangm febf923
refactor: remove autoFund parameter and always auto-fund in test helpers
juangm 0d56477
test: make precision parameter required in toBeBigDecimalCloseTo matcher
juangm 1b6d4e5
refactor: inline recreateUserPositionInOneSpoke helper into userPosit…
juangm ecc9895
fix: remove not needed imports
juangm 4a95adc
Merge branch 'main' into test/math-check-user-position-summary
juangm 44ad3f1
fix: use a publicClient instead of exporting devnet
juangm 572e901
test: check riskPremium value
juangm ade5c25
Merge branch 'main' into test/math-check-user-position-summary
juangm d8131cf
fix: typo and rename test description
juangm 11530da
Merge branch 'main' into test/math-check-user-position-summary
juangm 921d93a
Merge branch 'main' into test/math-check-user-position-summary
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,2 @@ | ||
| --- | ||
| --- |
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 |
|---|---|---|
|
|
@@ -72,23 +72,39 @@ export function findReserveAndSupply( | |
| amount, | ||
| spoke, | ||
| asCollateral, | ||
| autoFund, | ||
| }: { | ||
| token: EvmAddress; | ||
| amount: BigDecimal; | ||
| spoke?: SpokeId; | ||
| asCollateral?: boolean; | ||
| autoFund?: boolean; | ||
|
||
| }, | ||
| ): ResultAsync<Reserve, Error> { | ||
| return findReservesToSupply(client, user, { | ||
| token: token, | ||
| spoke: spoke, | ||
| asCollateral: asCollateral, | ||
| }).andThen((reserves) => | ||
| supplyToReserve(client, user, { | ||
| reserve: reserves[0].id, | ||
| amount: { erc20: { value: amount } }, | ||
| sender: evmAddress(user.account.address), | ||
| }).map(() => reserves[0]), | ||
| autoFund | ||
| ? fundErc20Address(evmAddress(user.account.address), { | ||
| address: token, | ||
| amount: amount, | ||
| decimals: reserves[0]!.asset.underlying.info.decimals, | ||
| }).andThen(() => | ||
| supplyToReserve(client, user, { | ||
| reserve: reserves[0]!.id, | ||
| amount: { erc20: { value: amount } }, | ||
| sender: evmAddress(user.account.address), | ||
| enableCollateral: asCollateral ?? true, | ||
| }).map(() => reserves[0]), | ||
| ) | ||
| : supplyToReserve(client, user, { | ||
| reserve: reserves[0].id, | ||
| amount: { erc20: { value: amount } }, | ||
| sender: evmAddress(user.account.address), | ||
| enableCollateral: asCollateral ?? true, | ||
| }).map(() => reserves[0]), | ||
| ); | ||
| } | ||
|
|
||
|
|
@@ -141,6 +157,33 @@ export function supplyAndBorrow( | |
| ); | ||
| } | ||
|
|
||
| export function borrowFromRandomReserve( | ||
| client: AaveClient, | ||
| user: WalletClient<Transport, Chain, Account>, | ||
| params: { | ||
| spoke?: SpokeId; | ||
| token?: EvmAddress; | ||
| ratioToBorrow?: number; | ||
| }, | ||
| ): ResultAsync<Reserve, Error> { | ||
| return findReservesToBorrow(client, user, { | ||
| spoke: params.spoke, | ||
| token: params.token, | ||
| }).andThen((reserves) => { | ||
| return borrowFromReserve(client, user, { | ||
| reserve: reserves[0].id, | ||
| amount: { | ||
| erc20: { | ||
| value: reserves[0].userState!.borrowable.amount.value.times( | ||
| params.ratioToBorrow ?? 0.1, | ||
| ), | ||
| }, | ||
| }, | ||
| sender: evmAddress(user.account.address), | ||
| }).map(() => reserves[0]); | ||
| }); | ||
| } | ||
|
|
||
| export function supplyAndBorrowNativeToken( | ||
| client: AaveClient, | ||
| user: WalletClient<Transport, Chain, Account>, | ||
|
|
||
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
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.
I think it's better to export a
PublicClientalready wired instead of thedevnetChain.