-
Notifications
You must be signed in to change notification settings - Fork 229
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
Use a single atomicRearrange for liquidityPool repay #11059
Open
Chris-Hibbert
wants to merge
3
commits into
master
Choose a base branch
from
cth-atomicRepay
base: master
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.
+46
−116
Open
Changes from 2 commits
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
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 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 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 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 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 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 |
---|---|---|
|
@@ -209,9 +209,8 @@ const scaleAmount = (frac: number, amount: Amount<'nat'>) => { | |
}; | ||
|
||
// ack: https://stackoverflow.com/a/2901298/7963 | ||
function numberWithCommas(x) { | ||
return x.toString().replace(/\B(?=(\d{3})+(?!\d))/g, ','); | ||
} | ||
const numberWithCommas = x => | ||
x.toString().replace(/\B(?=(\d{3})+(?!\d))/g, ','); | ||
|
||
const logAmt = amt => [ | ||
Number(amt.value), | ||
|
@@ -425,15 +424,8 @@ test('basic repay calculation', t => { | |
}; | ||
const encumberedBalance = make(USDC, 200n); | ||
const poolStats = makeInitialPoolStats(); | ||
const fromSeatAllocation = amounts; | ||
|
||
const result = repayCalc( | ||
shareWorth, | ||
fromSeatAllocation, | ||
amounts, | ||
encumberedBalance, | ||
poolStats, | ||
); | ||
const result = repayCalc(shareWorth, amounts, encumberedBalance, poolStats); | ||
|
||
t.deepEqual( | ||
result.encumberedBalance, | ||
|
@@ -489,23 +481,13 @@ test('repay fails when principal exceeds encumbered balance', t => { | |
|
||
const fromSeatAllocation = amounts; | ||
|
||
t.throws( | ||
() => | ||
repayCalc( | ||
shareWorth, | ||
fromSeatAllocation, | ||
amounts, | ||
encumberedBalance, | ||
poolStats, | ||
), | ||
{ | ||
message: /Cannot repay. Principal .* exceeds encumberedBalance/, | ||
}, | ||
); | ||
t.throws(() => repayCalc(shareWorth, amounts, encumberedBalance, poolStats), { | ||
message: /Cannot repay. Principal .* exceeds encumberedBalance/, | ||
}); | ||
|
||
t.notThrows( | ||
() => | ||
repayCalc(shareWorth, fromSeatAllocation, amounts, make(USDC, 200n), { | ||
repayCalc(shareWorth, amounts, make(USDC, 200n), { | ||
...makeInitialPoolStats(), | ||
totalBorrows: make(USDC, 200n), | ||
}), | ||
|
@@ -528,24 +510,9 @@ test('repay fails when seat allocation does not equal amounts', t => { | |
totalBorrows: make(USDC, 100n), | ||
}; | ||
|
||
const fromSeatAllocation = { | ||
...amounts, | ||
ContractFee: make(USDC, 1n), | ||
}; | ||
|
||
t.throws( | ||
() => | ||
repayCalc( | ||
shareWorth, | ||
fromSeatAllocation, | ||
amounts, | ||
encumberedBalance, | ||
poolStats, | ||
), | ||
{ | ||
message: /Cannot repay. From seat allocation .* does not equal amounts/, | ||
}, | ||
); | ||
t.throws(() => repayCalc(shareWorth, amounts, encumberedBalance, poolStats), { | ||
message: /Cannot repay. Principal .* exceeds encumberedBalance/, | ||
}); | ||
}); | ||
|
||
test('repay succeeds with no Pool or Contract Fee', t => { | ||
|
@@ -563,13 +530,7 @@ test('repay succeeds with no Pool or Contract Fee', t => { | |
totalBorrows: make(USDC, 100n), | ||
}; | ||
const fromSeatAllocation = amounts; | ||
const actual = repayCalc( | ||
shareWorth, | ||
fromSeatAllocation, | ||
amounts, | ||
encumberedBalance, | ||
poolStats, | ||
); | ||
const actual = repayCalc(shareWorth, amounts, encumberedBalance, poolStats); | ||
Comment on lines
-566
to
+533
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. getting these all on one line makes me happy 🥇 |
||
t.like(actual, { | ||
shareWorth, | ||
encumberedBalance: { | ||
|
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 could swear zcf throws when this
harden(...)
is missing. But maybe only the individual parts need to be hardened?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.
done.
Do you believe that even though tests all passed?
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
fast-usdc.contract.test.ts
is sufficiently high fidelity that if the tests pass, the code would work on chain withoutharden(...)
.