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

feat(aux-ts): sdk support for stake pools #296

Merged
merged 6 commits into from
Nov 22, 2022
Merged

feat(aux-ts): sdk support for stake pools #296

merged 6 commits into from
Nov 22, 2022

Conversation

leina05
Copy link
Collaborator

@leina05 leina05 commented Nov 21, 2022

No description provided.

@leina05 leina05 force-pushed the leina/stake_sdk branch 3 times, most recently from 59834b2 to fa9e087 Compare November 21, 2022 22:24
Copy link
Contributor

@misungson misungson left a comment

Choose a reason for hiding this comment

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

Thanks, Leina. I have a few questions re: the create function usage and added some minor comments. Can you help me with these when you have a chance?

aptos/api/aux-ts/src/stake/client.ts Outdated Show resolved Hide resolved
aptos/api/aux-ts/src/stake/client.ts Outdated Show resolved Hide resolved
aptos/api/aux-ts/src/stake/schema.ts Outdated Show resolved Hide resolved
aptos/api/aux-ts/src/stake/schema.ts Outdated Show resolved Hide resolved
aptos/contract/aux/sources/stake.move Outdated Show resolved Hide resolved
aptos/contract/aux/sources/stake.move Outdated Show resolved Hide resolved
aptos/contract/aux/sources/stake.move Outdated Show resolved Hide resolved
let pool = table::borrow_mut(&mut pools.pools, pool_id);
assert!(pool.authority == sender_addr, E_TEST_FAILURE);
assert!(pool.start_time == start_time, E_TEST_FAILURE);
assert!(pool.end_time == end_time, E_TEST_FAILURE);
Copy link
Contributor

Choose a reason for hiding this comment

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

Not so sure how this test was passingwith seemingly stale input parameters for create function line 1605. Maybe I'm missing something...

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Ah, that's a good catch. I think it's because in the tests, the timestamp starts as 0, so there's no difference between end_time and duration_us. I'll fast forward time a bit in the setup to avoid that.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Alright I added the fix and rebased, but if you check out this commit: 0f2761d65443b06ea73f409969f2d1fd82b29586 you should see these tests failing due to that bug.

Copy link
Contributor

@misungson misungson Nov 22, 2022

Choose a reason for hiding this comment

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

Thanks, Leina! I cannot replicate the test failures : (
misung@penguin:~/aux-exchange/aptos/api/aux-ts$ git checkout 0f2761d65443b06ea73f409969f2d1fd82b29586 fatal: reference is not a tree: 0f2761d65443b06ea73f409969f2d1fd82b29586
I was able to check out another commit f854bb8 instead, but I'm not so sure how to run these tests in stake.move instead of stake.spec.ts:

misung@penguin:~ /aux-exchange/aptos/api/aux-ts$ git checkout f854bb8
HEAD is now at f854bb8 fast forward start time in stake tests
misung@penguin:~/aux-exchange/aptos/api/aux-ts$ APTOS_NETWORK="local" yarn test --g "Stake"

Stake Pool tests
✔ fundAccount (1113ms)
✔ createStakePoolClient
✔ mintAux (2482ms)
✔ mintOther (1073ms)
✔ createStakePool (1069ms)
✔ deposit (1153ms)
Sleeping for 2 seconds
✔ claim (3057ms)
✔ modifyPool (1065ms)
✔ modifyAuthority (3305ms)
✔ endRewardEarly (2191ms)
✔ withdraw (1128ms)
✔ deleteEmptyPool (1075ms)

12 passing (19s)

aptos/contract/aux/sources/stake.move Outdated Show resolved Hide resolved
aptos/contract/aux/sources/stake.move Outdated Show resolved Hide resolved
@leina05
Copy link
Collaborator Author

leina05 commented Nov 22, 2022

Thanks, Leina. I have a few questions re: the create function usage and added some minor comments. Can you help me with these when you have a chance?

Thanks for reviewing, @misungson. I believe I applied / fixed all of your suggestions, but let me know if I missed anything.

Copy link
Contributor

@misungson misungson left a comment

Choose a reason for hiding this comment

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

Thank you for making the changes, Leina!
They all look good to me. I'm failing to replicate the intermediate test results (details mentioned in the other comment), but that would be due to my user error.

let pool = table::borrow_mut(&mut pools.pools, pool_id);
assert!(pool.authority == sender_addr, E_TEST_FAILURE);
assert!(pool.start_time == start_time, E_TEST_FAILURE);
assert!(pool.end_time == end_time, E_TEST_FAILURE);
Copy link
Contributor

@misungson misungson Nov 22, 2022

Choose a reason for hiding this comment

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

Thanks, Leina! I cannot replicate the test failures : (
misung@penguin:~/aux-exchange/aptos/api/aux-ts$ git checkout 0f2761d65443b06ea73f409969f2d1fd82b29586 fatal: reference is not a tree: 0f2761d65443b06ea73f409969f2d1fd82b29586
I was able to check out another commit f854bb8 instead, but I'm not so sure how to run these tests in stake.move instead of stake.spec.ts:

misung@penguin:~ /aux-exchange/aptos/api/aux-ts$ git checkout f854bb8
HEAD is now at f854bb8 fast forward start time in stake tests
misung@penguin:~/aux-exchange/aptos/api/aux-ts$ APTOS_NETWORK="local" yarn test --g "Stake"

Stake Pool tests
✔ fundAccount (1113ms)
✔ createStakePoolClient
✔ mintAux (2482ms)
✔ mintOther (1073ms)
✔ createStakePool (1069ms)
✔ deposit (1153ms)
Sleeping for 2 seconds
✔ claim (3057ms)
✔ modifyPool (1065ms)
✔ modifyAuthority (3305ms)
✔ endRewardEarly (2191ms)
✔ withdraw (1128ms)
✔ deleteEmptyPool (1075ms)

12 passing (19s)

@leina05 leina05 merged commit 0d0b7f8 into main Nov 22, 2022
@leina05 leina05 deleted the leina/stake_sdk branch November 22, 2022 18:43
leina05 added a commit that referenced this pull request Dec 5, 2022
* feat(aux): simple staking contract, modeled after sushiswap masterchef

* chore(aux): reward_debt -> last_acc_reward_per_share

* chore(aux): abort only contract

feat(aux-ts): sdk support for stake pools (#296)

* add timestamps to stake pool events

stake pools sdk

* chore(aux-ts): stake pool tests
feat(aux): add end_reward_early function to stake.move

* fast forward start time in stake tests

* update all tests to use duration instead of end_time in pool creation

* replace endTimeUs with durationUs

* Co-authored-by: Misung Son <misungs@gmail.com>

Apply suggestions from code review

feat(aux-ts): stake sdk localnet example (#303)

* Initial commit of stake sdk localnet example.

* add examples section to CONTRIBUTING.md

* Added start:localnet-stake-example to package.json.

* Changed the example to staker allocating between two pools (seems more relevant to me) instead of staking in one pool above threshold.

* fix(localnet-stake-allocator.ts): set up other staking account

* Switched to a brute-force method to find optimal staker positions.

* Minor change in comments.

* A little generalization using M in computing x1Optimal.

Co-authored-by: Leina McDermott <leina05@gmail.com>
leina05 added a commit that referenced this pull request Dec 6, 2022
* feat(aux): simple staking contract, modeled after sushiswap masterchef

* chore(aux): reward_debt -> last_acc_reward_per_share

* chore(aux): abort only contract

feat(aux-ts): sdk support for stake pools (#296)

* add timestamps to stake pool events

stake pools sdk

* chore(aux-ts): stake pool tests
feat(aux): add end_reward_early function to stake.move

* fast forward start time in stake tests

* update all tests to use duration instead of end_time in pool creation

* replace endTimeUs with durationUs

* Co-authored-by: Misung Son <misungs@gmail.com>

Apply suggestions from code review

feat(aux-ts): stake sdk localnet example (#303)

* Initial commit of stake sdk localnet example.

* add examples section to CONTRIBUTING.md

* Added start:localnet-stake-example to package.json.

* Changed the example to staker allocating between two pools (seems more relevant to me) instead of staking in one pool above threshold.

* fix(localnet-stake-allocator.ts): set up other staking account

* Switched to a brute-force method to find optimal staker positions.

* Minor change in comments.

* A little generalization using M in computing x1Optimal.

Co-authored-by: Leina McDermott <leina05@gmail.com>
leina05 added a commit that referenced this pull request Dec 6, 2022
* feat(aux): simple staking contract, modeled after sushiswap masterchef

* chore(aux): reward_debt -> last_acc_reward_per_share

* chore(aux): abort only contract

feat(aux-ts): sdk support for stake pools (#296)

* add timestamps to stake pool events

stake pools sdk

* chore(aux-ts): stake pool tests
feat(aux): add end_reward_early function to stake.move

* fast forward start time in stake tests

* update all tests to use duration instead of end_time in pool creation

* replace endTimeUs with durationUs

Apply suggestions from code review

feat(aux-ts): stake sdk localnet example (#303)

* Initial commit of stake sdk localnet example.

* add examples section to CONTRIBUTING.md

* Added start:localnet-stake-example to package.json.

* Changed the example to staker allocating between two pools (seems more relevant to me) instead of staking in one pool above threshold.

* fix(localnet-stake-allocator.ts): set up other staking account

* Switched to a brute-force method to find optimal staker positions.

* Minor change in comments.

* A little generalization using M in computing x1Optimal.

Co-authored-by: Misung Son <misungs@gmail.com>
Co-authored-by: Leina McDermott <leina05@gmail.com>
leina05 added a commit that referenced this pull request Dec 6, 2022
* feat(aux): simple yield farming contract (masterchef) (#260)

* feat(aux): simple staking contract, modeled after sushiswap masterchef

* chore(aux): reward_debt -> last_acc_reward_per_share

feat(aux-ts): sdk support for stake pools (#296)

* add timestamps to stake pool events

stake pools sdk

* chore(aux-ts): stake pool tests
feat(aux): add end_reward_early function to stake.move

* fast forward start time in stake tests

* update all tests to use duration instead of end_time in pool creation

* replace endTimeUs with durationUs

Apply suggestions from code review

feat(aux-ts): stake sdk localnet example (#303)

* Initial commit of stake sdk localnet example.

* add examples section to CONTRIBUTING.md

* Added start:localnet-stake-example to package.json.

* Changed the example to staker allocating between two pools (seems more relevant to me) instead of staking in one pool above threshold.

* fix(localnet-stake-allocator.ts): set up other staking account

* Switched to a brute-force method to find optimal staker positions.

* Minor change in comments.

* A little generalization using M in computing x1Optimal.

Co-authored-by: Misung Son <misungs@gmail.com>
Co-authored-by: Leina McDermott <leina05@gmail.com>

* fix(aux): remove support for duplicate stake pool type creation

* feat(aux): add wrapped st coin to support stake coin rehypothecation

* chore(aux): add st coin balance checks to tests and add test for double dip

* fix(aux): stash initialized coin caps when deleting pool to allow to reuse for new pools

Co-authored-by: Misung Son <misungs@gmail.com>
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.

None yet

2 participants