Skip to content
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

Dex, vesting + finish supply/redeem/swap #501

Merged
merged 23 commits into from
Oct 26, 2022
Merged

Dex, vesting + finish supply/redeem/swap #501

merged 23 commits into from
Oct 26, 2022

Conversation

mitschabaude
Copy link
Collaborator

@mitschabaude mitschabaude commented Oct 20, 2022

This PR finishes all remaining tests in the categories "Supply liquidity", "Redeem liquidity", and "Swap".

See comments in dex/run.ts for details on how the tests were done, and the testing Google doc for comments about why certain tests were left out.

@@ -593,9 +593,9 @@ class SmartContract {
address: PublicKey;
tokenId: Field;

private _executionState: ExecutionState | undefined;
#executionState: ExecutionState | undefined;
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

changes in this file are to work around some TS glitches when returning a SmartContract from a function (i.e., using a class factory)

},
setGlobalSlotSinceHardfork(slot: UInt32) {
networkState.globalSlotSinceHardFork = slot;
incrementGlobalSlot(increment: UInt32 | number) {
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

improvement to the API of setting the global slot: globalSlotSinceGenesis and globalSlotSinceHardfork should always be updated together, not independent of each other. Also, the only update that makes sense is increasing them.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Does it matter to add UInt64 to this type as well?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't think so, slots are always just UInt32 in Mina

@@ -940,7 +940,8 @@ class AccountUpdate implements Types.AccountUpdate {
// if the fee payer is the same account update as this one, we have to start the nonce predicate at one higher,
// bc the fee payer already increases its nonce
let isFeePayer = Mina.currentTransaction()?.sender?.equals(publicKey);
if (isFeePayer?.toBoolean()) nonce++;
let shouldIncreaseNonce = isFeePayer?.and(tokenId.equals(TokenId.default));
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

small bug fix here when computing nonces in an edge case

@mitschabaude mitschabaude marked this pull request as ready for review October 21, 2022 20:08
@mitschabaude
Copy link
Collaborator Author

Note: tests are failing because the bindings are not updated, to make review easier

@mitschabaude mitschabaude changed the title Dex, happy paths + vesting Dex, vesting + finish supply/redeem/swap Oct 21, 2022
Copy link
Contributor

@MartinMinkov MartinMinkov left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Incredible work as always :D

Comment on lines +75 to +76
// FIXME
// Error: Constraint unsatisfied (unreduced): Equal 0 1
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should we remove these comments now that the line below has been enabled? I'm also curious to know what was causing this error if you know the cause?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I didn't test the line again with proving enabled - just wanted it enabled for fuller testing in the non proving case. All of these tests only work with not proving by now. I have an issue open just for investigating this line: #499

* Thus, a liquidity provider would need to wait for their current tokens to unlock before being able to
* supply liquidity again (or, create another account to supply liquidity from).
*/
let amountLocked = dl;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should we spin up a ticket to add a nicer API for updating timing functionality?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's covered by this one: #186

},
setGlobalSlotSinceHardfork(slot: UInt32) {
networkState.globalSlotSinceHardFork = slot;
incrementGlobalSlot(increment: UInt32 | number) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Does it matter to add UInt64 to this type as well?

Copy link
Member

@bkase bkase left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks great to me! @shimkiv should take a look too!

I think we need to at least sort out #499 before calling this part of the project done though

/**
* - Resulting operation will overflow the SC’s receiving token by type or by any other applicable limits;
*
* note: this throws not at the protocol level, but because the smart contract multiplies two UInt64s which overflow.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

what do you mean here? There is a constraint failure due to the overflow, right? It's just due to the smart contract.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes there is a constraint failure. So we don't get to the point where we could trigger an overflow failure in the protocol logic. In that sense, this is not a proper test as it was intended

@Trivo25 Trivo25 mentioned this pull request Oct 26, 2022
@mitschabaude mitschabaude merged commit f7c9a20 into main Oct 26, 2022
@mitschabaude mitschabaude deleted the dex/vesting branch October 26, 2022 23:19
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
3 participants