Skip to content

Conversation

@cnek
Copy link
Contributor

@cnek cnek commented May 3, 2022

#142
#145
#156
#159
work with anchor-comp branch: mango_msol (related PR UXDProtocol/anchor-comp#5)

acamill and others added 16 commits February 24, 2022 15:17
* - ProgramResult -> Result<()>

* Use error!

* use error from anchor

* Add Check for Unchecked accountsInfo

* WIP trying to make it work but seems that devnet is having issues.
Pausing for now
* feat: accounting suite for accounting tests

* added more checks

* working

* changed back to test_development
* Use new anchor-comp package for mango CPI

* remove old CPI helpers

* Safe changes (w/o mint/redeem/rebalance)

* Use place_perp_order_v2 and simplify code

* Working

* Update tests (most logic been offloaded to Mango)

* Remove uneeded accounts + explicit ATA checks

* allow 100% slippage

* Improve computing for tests

* Slippage tweaks
- Slippage u32 -> u16
- 0 slippage accepted again (was disabled due to previous code but that's been refactored)
* Update mango 3.4.1

* fix comment

* Enforce limit price through providing it from front end

* Cleanup

* Ken comments

* idl

* json idl
* Add zo-abi

WIP zo

Stash pop

stash pop

WIP Cpi almost there.

More updates

Currently doesn't work with yarn so kinda annoying, let's wait for them to fix this as discussed in the TG

Toward cpi support..

Toward cpi support.. almost there

Update reserved padding

Update IDL and client version (still using yarn link)

Fixes

Working Init zo deposiroty + tests

Init Control account in the program for simplicity

Mint WIP

Cargo audit fix

Working register with OO account creationg

Mint issue with CPI

Update client

* wip ZO - issue with constraint. Will add anchor latest for more info to debug

* Deposit mint

* Redeem and mint - Computing issue. Breakpoiint will transit to 0copy

* Redeem withdraw and controller as zero_copy

Require!

* Update PR feedback

* Use latest client (private)
Use accountLoader for mango depository

* Fixing test slowly...

* More test updates and fixes

* Update latest 01 version

* Fixed tests

* ZO Cleanup
(Make a branc without any ZO change for clarity)

* Updated idl

* add the mistakenly erased bank keypair
@cnek cnek added the enhancement New feature or request label May 3, 2022
acamill and others added 13 commits May 4, 2022 11:04
* Use udx-protocol on NPM instead of private gh version

* Misc

* Fixed mint

* Working integration tests

* Offering to Clippy gods + fmt

* New program ID  + resident program for CI

* Update CI

* npm ci

Co-authored-by: Bamboozelino <memail>
* first

* instructions (#139)

* instructions

* comments

* api

* rename

* math

* start on tests

* wip tests

* require

* fixes with accounts and merge

* quote_redeem (#140)

* quote_redeem

* comments

* fixed comments and mango check

* a

* poggers

* latest

* save

* nothing

* save

* math fixes

* save

* Invalid Blockhash

* for remote version

* Feature/positive minting and more (#151)

* quote_redeem

* comments

* fixed comments and mango check

* a

* poggers

* latest

* save

* nothing

* save

* math fixes

* save

* Fix memory layout of accounts

* Use the oss version of the client and ditch the private one

* Invalid Blockhash

* for remote version

* simplified assertion (#147)

* save changes

* save

* Chore/fix tests (#149)

* Use udx-protocol on NPM instead of private gh version

* Misc

* Fixed mint

* Working integration tests

* Offering to Clippy gods + fmt

* New program ID  + resident program for CI

* Update CI

* npm ci

Co-authored-by: Bamboozelino <memail>

* committed

* save

* progress

Co-authored-by: Acammm <alexcamill@gmail.com>
Co-authored-by: Ken C <ctk2012ac@gmail.com>
Co-authored-by: acammm <40299747+acamill@users.noreply.github.com>

* Work with max

* misc
- added test to ensure user has UXD
- formatting
- account mutability for mango

* Added test quote test to CI

* - fix quoteMintAndRedeemSuite switch cases
- fix quote mint and redeem test asserts
- changed equals to close_to

* testing improvements
- adding accounting tests for quoteMint and quoteRedeem
- incorporate accounting tests into test suite

* - small test fix

* Test working

Co-authored-by: Max Planck <maxplanck.crypto@gmail.com>
Co-authored-by: Max Planck <99688618+CryptoMaxPlanck@users.noreply.github.com>
Co-authored-by: Ken C <ctk2012ac@gmail.com>
Co-authored-by: Bamboozelino <memail>

pub fn handler(ctx: Context<EnableMsolSwap>, enable: bool) -> Result<()> {
let msol_config = &mut ctx.accounts.msol_config.load_mut()?;
msol_config.enabled = enable;
Copy link
Member

Choose a reason for hiding this comment

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

Not sure should we have a single "edit_msol_settings" or smthg and have a object passed as parameter that can change multiple parameters, makes the code simpler.
Downside is that it's less explicit, I do like solo instruction like this one more, just takes more space.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I would rather make them explicit, there are only two fields editable right now and can't see there are anymore in the current "msol" scope.

Copy link
Member

Choose a reason for hiding this comment

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

Yhea ok let's keep that for a global param struct refactor later on

target_liquidity_ratio: u16,
) -> Result<()> {
msg!("[create_depository_msol_config]");
instructions::create_depository_msol_config::handler(ctx, target_liquidity_ratio).map_err(
Copy link
Member

Choose a reason for hiding this comment

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

This has been removed from a while ago can do a rebase

)]
pub fn enable_msol_swap(ctx: Context<EnableMsolSwap>, enable: bool) -> Result<()> {
msg!("[enable_msol_swap]");
instructions::enable_msol_swap::handler(ctx, enable).map_err(|e| {
Copy link
Member

Choose a reason for hiding this comment

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

same

target_liquidity_ratio: u16,
) -> Result<()> {
msg!("[set_msol_liquidity_ratio]");
instructions::set_msol_liquidity_ratio::handler(ctx, target_liquidity_ratio).map_err(|e| {
Copy link
Member

Choose a reason for hiding this comment

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

same

Copy link
Member

@acamill acamill left a comment

Choose a reason for hiding this comment

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

Let me know if you want to call or review smthg specific, I think we could finalize this by the time @alg747 join so that we can start UXSol

(Also I assume latest changes are not reflected here you must have another unpushed branch)

CryptoMaxPlanck and others added 6 commits May 24, 2022 10:05
* first commit

* - added "should fail" tests for quoteMint and quoteRedeem
- added unit tests
* added msol config state and ixn to create one

* added msol config ixns

* doc updated

* added back account contraints

* updated according to pr comments

* fixed error code

* renamed conversion to swap

* rebased fixed error

* used account loader create msol config

* used account loader / require
* added mango_info

* dissolved mango info

* use local client package for testing
@cnek cnek force-pushed the feature/mango-msol branch from 6749896 to d221db1 Compare May 29, 2022 03:46
@cnek cnek changed the base branch from v3.1.0 to v3.2.0 May 29, 2022 11:23
cnek added 2 commits May 29, 2022 19:27
* wip

wip

swapping enabled checking

wip

test cpi wip

added mut to accounts

liquid unstake cpi test

msol

fixed up

wip

sol-msol-sol draft

disable wip

sol-msol-sol test

clean up program

removed unused ix and test code

fixed error and better doc

reverted debug code

fixed fmt/clippy

fixed ata pass to mango cpi

* fixed idl

* added mainnet integration test for msol / fixed program (#159)

* internal mainnet testing setup

* rm extra seed added for debug

* set mainnet program address

* added wrap/unwrap sol on chain

* added sync native after wrapping

* minor

* revert test_development

* exit ix when swapping amount is zero

* added msol utils, refactor

* install marinade sdk

* refactor test

* fixed comment
let cpi_program = self.mango_program.to_account_info();
CpiContext::new(cpi_program, cpi_accounts)
}

Copy link
Member

Choose a reason for hiding this comment

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

Nice to have the factorisation but would be nice to keep it smol in the main logic. Can do by adding two helper that keep the parameterization out of the main logic here

}
MsolSwapRoute::LiquidUnstake => {
// 6. msol equivalent lamports need to withdraw from mango
let liquid_unstake_lamports: u64 = diff_to_target_liquidity
Copy link
Member

Choose a reason for hiding this comment

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

amount of MSOL to be withdrawn and converted back to SOL

-> sol_withdraw_amount

.ok_or_else(|| error!(UxdError::MathError))?;

// 7. msol amount of (6)
let msol_liquid_unstake_amount = marinade_state
Copy link
Member

Choose a reason for hiding this comment

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

amount of MSOL to be unstaked from Marinade

calc_msol_from_lamports -> convert_sol_to_msol_amount

DISLAIMER: it's from Marinade not us, so cannot rename (@cnek )

)?;

// 9. convert msol from msol passthrough to sol and transfer to the user
let cpi_ctx = ctx.accounts.into_liquid_unstake_cpi_ctx();
Copy link
Member

Choose a reason for hiding this comment

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

Here depending of the amount of buffer left should be done delayed or instant

@cnek
Copy link
Contributor Author

cnek commented Jun 9, 2022

update:
moved marinade / sync native cpi invocation to anchor-comp for alignment
group different rebalancing route into dedicated functions for better readability

@cnek cnek changed the base branch from v3.2.0 to main October 3, 2022 12:18
@cnek cnek closed this Oct 18, 2022
@acamill acamill deleted the feature/mango-msol branch April 21, 2023 00:49
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

enhancement New feature or request

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants