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

Feature/mint #2

Open
wants to merge 20 commits into
base: main
Choose a base branch
from
Open

Feature/mint #2

wants to merge 20 commits into from

Conversation

Flocqst
Copy link
Contributor

@Flocqst Flocqst commented Jun 19, 2024

Implement Minting and Conversion Ratio to the KSX Vault

Description

See spec for Minting and Conversion Ratio :
https://github.com/Kwenta/kwenta-state-log/blob/master/kips/kip-123.md

Add tests to ensure the first $KSX is minted by depositing $KWENTA at an initial fixed ratio of 1,000 $KSX per $KWENTA.

Add KSXVaultBootsrap for tests

Copy link

@Flocqst Flocqst marked this pull request as ready for review September 10, 2024 15:30
@Flocqst Flocqst requested a review from jcmonte September 10, 2024 15:30
Copy link

@jcmonte jcmonte left a comment

Choose a reason for hiding this comment

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

Testing is a bit too light for logic this intricate. Also you should definitely have unit tests and integration tests split out. Where the former is testing purely the function effects and the latter is testing deeper integration with functioning StakingRewards.

Comment on lines 40 to 50
// Asserts correct deposit at 1000 shares ratio
// Converts asset values to shares and deposits assets into the vault
function test_vault_deposit() public {
uint256 amount = 1 ether;
vm.startPrank(alice);
depositToken.approve(address(ksxVault), amount);
ksxVault.deposit(1 ether, alice);
assertEq(ksxVault.balanceOf(alice), amount * (10 ** ksxVault.offset()));
assertEq(stakingRewards.stakedBalanceOf(address(ksxVault)), amount);
vm.stopPrank();
}
Copy link

Choose a reason for hiding this comment

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

This test checks that Alice is minted the offset amount specified in the contract, but it does not verify that 1 Kwenta = 1000 KSX. Like if you set offset to 0 this test would still pass.

You should have a separate test that shows 1 KWENTA deposited results in 1000 KWENTA hardcoded. (original business case)

This should also be fuzzed. For your fuzz test you can multiply the initial KWENTA amount by 1000. You're trying to prove that for all amounts of Kwenta the initial ratio is 1:1000.

Copy link

Choose a reason for hiding this comment

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

Secondarily, you should have tests that test consecutive actions. For example, you should be testing

  1. Deposit 1 KWENTA receive x amount
  2. Deposit 2 KWENTA, now what amount do you receive? Test your hypothesis

and

  1. Deposit 1 KWENTA as Alice receive x amount
  2. Allow some time to pass and staking rewards to accrue in the contract*
  3. Deposit 1 KWENTA as Bob and confirm the expected amount

* more of an integration test but you need to have this


Your goal with test coverage is to test as much branching logic you can think of. This SupplySchedule.t is the gold standard for testing. Note how it even tests contract state at random points in the time in the future (future weeks expected behavior). Take some time to review this and look how many test cases were covered.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Added new extensive tests for deposit process.

test/KSXVault.t.sol Outdated Show resolved Hide resolved

// Withdraws a specified amount of assets from the vault by burning the
// equivalent shares
function test_withdraw() public {
Copy link

Choose a reason for hiding this comment

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

Add a test that tests initial conversion ratio withdraw. ie. where Alice tries to withdraw 1 KWENTA and has to deposit 1000 KSX

Copy link

Choose a reason for hiding this comment

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

Secondarily you need more negative state tests. For example

  • trying to withdraw with no shares
  • trying to withdraw with more shares than you have

and do the same for deposits

A lot of this is already tested on ERC4626 but you modified the offset so you want to confirm that everything still works as intended. Also some modifications to stake/unstake

Copy link

Choose a reason for hiding this comment

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

https://github.com/Kwenta/token/blob/c724e9329f4fcc52b306fe81fdb4a640979dcc4c/test/local/contracts/MultipleMerkleDistributor.test.ts#L224-L269

This test file for the MultipleMerkleDistributor is another good study to understand what kind of negative tests I'm talking about. Don't leave stones unturned

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Added new extensive tests for redeeming process.

test/KSXVault.t.sol Outdated Show resolved Hide resolved
test/KSXVault.t.sol Outdated Show resolved Hide resolved
test/KSXVault.t.sol Outdated Show resolved Hide resolved
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants