Commit Graph

27 Commits

Author SHA1 Message Date
dafyddd 95e563b193
Dd/serum max ts (#170)
* point to serum dex upstream for now; add in max_ts for PlaceSpotOrder and PlaceSpotOrder2; DOES NOT COMPILE UNTIL OUR SERUM DEX FORK IS UPDATED

* point to blockworks-foundation version of serum-dex

* add serum_dex.so from anchor build registry; fix initialize market in tests; tests still don't pass because of liquidate_token_and_token

* fixed tests breaking because of new fees in serum dex

* got rid of compile warnings in tests; made tests run faster
2022-04-18 17:07:23 -04:00
dafyddd 3583fa19a9
V3.3.0 (#91)
* Add instructions for closing a mango account

* Check owner account is signer

* Use checked functions to load mango accounts

* add wip create_dust_account and resolve_dust

* Make resolve_dust fail silently

* Add max account checking

* Add upgrade mango account instruction

* Update version

* Run cargo fmt

* Fix instruction number, make owner read, fix padding

* added cancel_all_side functions to mathcing

* added cancel_perp_orders_side; haven't tested

* added not_upgradable flag to MangoAccount and amended InitMangoAccount to set that flag to true.

* logging for cancel all perp orders; get_complete_base_pos for reduce only check

* complete_base_pos for trigger order exec as well

* added changelog

* fixed check enter bankruptcy bug

* added deploy time

* merged in v3.2.12 and updated cancel_side to do logging

* Most code review changes, check dust account health

* Remove whitespace

* changed dust_account owner to admin

* make resolve_dust not take in OpenOrders for DustAccount because it doesn't have any; Add more checks for MangoAccount in resolve_dust

* merged in main v3.2.13

* do in_margin_basket check in CloseSpotOpenOrders

* do in_margin_basket check in CloseSpotOpenOrders

* small edits to errors

* upgrade anchor and packages

* added some additional info to PlacePerpOrder in instruction.rs

* mc/add alternative authority which cant withdraw (#97)

* Support account delegation, delegate should be able to trade, but not withdraw assets to his own wallet

Signed-off-by: microwavedcola1 <microwavedcola@gmail.com>

* comment

Signed-off-by: microwavedcola1 <microwavedcola@gmail.com>

* comment

Signed-off-by: microwavedcola1 <microwavedcola@gmail.com>

* comment

Signed-off-by: microwavedcola1 <microwavedcola@gmail.com>

* newline

Signed-off-by: microwavedcola1 <microwavedcola@gmail.com>

* bump solana in tests

Signed-off-by: microwavedcola1 <microwavedcola@gmail.com>

* cargo-fmt

Signed-off-by: microwavedcola1 <microwavedcola@gmail.com>

* bump rust

Signed-off-by: microwavedcola1 <microwavedcola@gmail.com>

* fix solana verison

Signed-off-by: microwavedcola1 <microwavedcola@gmail.com>

* linter

Signed-off-by: microwavedcola1 <microwavedcola@gmail.com>

* note

Signed-off-by: microwavedcola1 <microwavedcola@gmail.com>

* typo

Signed-off-by: microwavedcola1 <microwavedcola@gmail.com>

* changed name from alternative_authority to delegate to be consistent with Solana naming and more accurate

Co-authored-by: dd <dafydd.durairaj@gmail.com>

* Fixes from code review

Signed-off-by: microwavedcola1 <microwavedcola@gmail.com>

* Tests: Fix program log output

The log scope for these changed in solana 1.9

* Remove unnecessary owner check

* fix: remove not used account from ix interface spec

* Fix instruction builder, owner will pay, and his lamports would need to be adjusted

Signed-off-by: microwavedcola1 <microwavedcola@gmail.com>

* implement price limit in place_spot_order and place_spot_order2

* remove print

* CI: add apt-get update (#116)

Installing libudev-dev failed

* README: Document branches (#114)

* remove a todo; cleanup devnet_deploy.sh

* mc/change spot market params (#110)

* Soteria and Cargo Audit Automation (#106)

* Create audit.toml

Cargo audit configuration file

* Create ci-cargo-audit.yml

Action to build and run cargo audit using arguments from the .cargo/audit.toml file

* Update and rename program.yml to ci-lint-test.yml

Minor name changes and addition of Soteria

* Update ci-lint-test.yml

update environment settings

* Update ci-lint-test.yml

adding apt-get update as the job fails to find packages

* Update ci-cargo-audit.yml

* Ignore tokio upstream vuln

Reported to Solana for upstream patching

* impose price limits (#108)

* impose price limits

* update deploy time

Co-authored-by: dd <dafydd.durairaj@gmail.com>

* checked math in all areas touched by place_perp_order (#109)

* checked math in all areas touched by place_perp_order

* update deploy time

* update deploy time

Co-authored-by: dd <dafydd.durairaj@gmail.com>

* change_spot_market_params

Signed-off-by: microwavedcola1 <microwavedcola@gmail.com>

* linter

Signed-off-by: microwavedcola1 <microwavedcola@gmail.com>

* in ci, perform apt-get update to prevent failure to install apt packages

Signed-off-by: microwavedcola1 <microwavedcola@gmail.com>

* fix from review

Signed-off-by: microwavedcola1 <microwavedcola@gmail.com>

* remove a todo; cleanup devnet_deploy.sh

Co-authored-by: silas <95582913+silas-x@users.noreply.github.com>
Co-authored-by: dafyddd <daffy321@gmail.com>
Co-authored-by: dd <dafydd.durairaj@gmail.com>

* fix integer overflow issue in get_total_native_borrow

* update changelog.md

* optimize create_dust_account

* added some checked math in execute_perp_trigger_order where dealing with bids_quantity

* Do pyth price filtering only on mainnet

* Add CreateSpotOpenOrders

* add tests for CreateSpotOpenOrders

* upgrade anchor version to 0.20.1

* update deploy time

Co-authored-by: Riordan Panayides <riordan@panayid.es>
Co-authored-by: dd <dafydd.durairaj@gmail.com>
Co-authored-by: microwavedcola1 <89031858+microwavedcola1@users.noreply.github.com>
Co-authored-by: microwavedcola1 <microwavedcola@gmail.com>
Co-authored-by: Christian Kamm <mail@ckamm.de>
Co-authored-by: Jakob Povšič <jakob.povsic@gmail.com>
Co-authored-by: silas <95582913+silas-x@users.noreply.github.com>
2022-01-16 20:08:54 -05:00
dafyddd 0c4d26e3e3
V3.1 (#66)
* implemented reduce_only and market order for PlacePerpOrder; untested

* added root bank cache valid check under MangoCache

* fixed the root bank cache function and made it compiling

* added some stuff during live stream. still not finished

* Cache validation moved to impl

* All cache validations moved to appropriate struct implementations

* Increase valid_interval for RootBankCache check

* implemented place_spot_order2; still not finished reducing size of the tx

* more progress on place_spot_order2

* finished implementing place_spot_order2

* intermediate work on advanced orders

* compiling and deployed to devnet; advanced orders still unfinished

* changed get_spot_val to use Option for open_orders; more work on advanced orders but not completed

* added testi80f48 into placespotorder2

* removed test_i80f48; removed rent_ai into invoke_place_order

* removed test_i80f48; removed rent_ai into invoke_place_order

* cleaned up compiler warnings

* use serum order v3 serialization

* add perp stop order instruction

* implement correctly register order

* connect instructions with impl

* changed name to PerpTriggerOrder. Still need to implement RemovePerpTriggerOrder and test;

* Added RemoveAdvancedOrder and rearranged some of the instruction discriminants

* remove perp trigger order instruction

* Fix pda_signer_seeds

* fixed borrow issue in AddPerpTriggerOrder

* Move transfer_lamports

* fix accounts comment

* fixed borrow checker issue in execute adv order; added signed version of transfer lamports

* added order_type into LeafNode to help with trading view order movement

* fixed issues with transfering lamports so now RemoveAdvancedOrder works

* added some TODOs for logs; added simulation of perp order to prevent exploits in ExecutePerpTriggerOrder

* added exp to liquidity mining params

* Replaced json logging of FillEvent with borsh serialized LoggableFillEvent base64 encoding

* Added accounts to logs where necessary (mango_group_pk, liqee, liqor). Fixed malformed json. Added logging to cache_perp_markets. Made 'init_health above zero' an error'.

* updated the LoggableFillEvent

* revert throwing zero on 'Account init_health above zero'

* Added accounts to logs where necessary (mango_group_pk, liqee, liqor)… (#55)

* Added accounts to logs where necessary (mango_group_pk, liqee, liqor). Fixed malformed json. Added logging to cache_perp_markets. Made 'init_health above zero' an error'.

* revert throwing zero on 'Account init_health above zero'

* fixed liquidate_perp_market log

* fixed zero open interest bug in perp bankruptcy

* fixed zero open interest bug in perp bankruptcy

* added anchor events framework in mango-logs directory. See the README on how to use it.

* added stubs for all the logs that need to be replaced

* Added mango group to FillLog and added cache prices log, CacheRootBanksLog

* added support for all logs; added OpenOrdersBalanceLog as well whereever OpenOrders changes

* Added PostOnlySlide

* fixed PostOnlySlide

* added MngoAccrual

* added MngoAccrualLog

* rearrange

* removed reduce_only restriction on AddPerpTriggerOrder

* added msg into exec perp trigger

* fixed check in ExecutePerpTriggerOrder

* Fix test build: don't require &'a [AccountInfo<'a>] lifetimes (#59)

It's sufficient to propagate the lifetimes on
checked_unpack_open_orders.

* Add log events for deposit, withdraw and redeem mngo (#58)

* updated I80F48 to u64 in new log structs

* Fix serialization of instructions (#60)

Now it matches what MangoInstruction::unpack() expects.

- Side, OrderType, AssetType, TriggerCondition are serialized into u8
- the Option fields in ChangePerpMarketParams have a fixed width

* merged in changes from main

* Update serum-dex program fixture to 0.4.0

Built from 1be91f2863d8ecede32daaae7e768034e24bbc79

* quantity == u64::max in withdraw now withdraws max possible (if allow borrow false)

* UpdateFunding now caches funding; new UpdateFundingLog

* Add perp trigger order unittests (#61)

* Fix sim_new_bid/ask when the book is empty

* Add first perp trigger order unittest

This test only runs with "cargo test-bpf" as the non-bpf runtime does
not allow creation of pda accounts.

- Test users are now owned by the system program, not by themselves
- MangoProgramTest::process_transaction no longer always returns success
  (must check for error; all existing users do)

* Test: Add perp trigger order test around health

* Minor fixes to mango-logs (#63)

* Add mango-logs to Anchor.toml

* mango-logs: Disable doctests

There's nothing to test and they fail spuriously with an ambiguity error
on the mango_logs program.

* Add github actions CI workflow (#64)

* Apply rustfmt

To allow the formatting lint CI job to pass

* Add github actions CI workflow

Adapted from https://github.com/solana-labs/dapp-scaffold

Co-authored-by: dafyddd <daffy321@gmail.com>

* updated github workflows

* added max_withdrawable utility function in processor.rs

* moved max_withdrawable into MangoAccount and now also uses existing deposits

* Added market index to FillLog

* removed some debug logging in execute trigger order

* added the deploy time for v3.1

Co-authored-by: dd <dafydd.durairaj@gmail.com>
Co-authored-by: Ralfs <lagzda7@inbox.lv>
Co-authored-by: Tyler Shipe <tjshipe@gmail.com>
Co-authored-by: Maximilian Schneider <mail@maximilianschneider.net>
Co-authored-by: Riordan Panayides <riordan@panayid.es>
Co-authored-by: root <nicholasgclarke@gmail.com>
Co-authored-by: Christian Kamm <ckamm@delightful-solutions.de>
2021-10-11 13:42:01 -04:00
dd bafa07c8fb updated Anchor version and solana version 2021-09-14 11:36:59 -04:00
dd 8a3597af81 changed up settle_pnl logging; added settle_fees logging; added FillEvent logging 2021-08-24 19:43:31 -04:00
dd 620f3602d1 Increased index starting point in an attempt to increase precision of calculations in the update_indexes 2021-08-24 17:04:13 -04:00
dafyddd 212764cd02
Dd/reorg (#39)
* reorganized and added Anchor.toml and cargo workspace to top level

* Added proper anchor file with solana version

Co-authored-by: dd <dafydd.durairaj@gmail.com>
2021-08-23 11:19:17 -04:00
dd 46e528dff6 cleanup serum dex dependency 2021-08-19 14:31:30 -04:00
dd 1042af7d6d fixed taker trade miscalculation issue; force cancel now doesn't error if order not found on book 2021-08-18 10:27:00 -04:00
dafyddd 6c9f6c533a
Dd/openorders (#34)
* Changed layout of perp open orders; added invalid_id_ok bool to cancel perp order instructions; compiles but is not tested

* update solana cli; delete unused code;

Co-authored-by: dd <dafydd.durairaj@gmail.com>
2021-08-17 10:08:54 -04:00
dd efb66b71cf updated place_perp_order to use new health cache; added checked math logic to update_funding 2021-08-14 16:11:38 -04:00
dd 536d81eff7 updated liquidate_token_and_perp to use new HealthCache mechanism 2021-08-07 16:51:32 -04:00
dd 9960949c57 Removed FastMath from everywhere; upgraded to rustc 1.56 and solana 1.7.9 2021-08-03 19:45:27 -04:00
dd 5df6c7ce20 added liquidation_fee to AddSpotMarket and removed some TODOs 2021-07-29 17:20:20 -04:00
dafyddd 8c8d8c9438
Ralfs/new tests (#29)
* maker and taker both executing async on event queue now

* Updated liquidate function to properly update open interest

* implemented socialize loss for perp market bankruptcy

* implemented socialize loss for perp market bankruptcy

* implemented settle_fees; upgraded to 1.7.3

* resolve_token_bankruptcy done

* moved interest rate function params into RootBank and added set_rate_params

* Added dao vault to init_mango_group

* added force_cancel_spot_orders

* Wire up liquidate instructions, fix compiler warning

* Added force cancenl perp orders; fixed stack error with inline(never)

* fixed withdraw function

* fixed set_rate_params

* Took out the '***' markers. Incomplete list of changes:
settle borrow is gone
borrow is gone
interest rate params are now stored on root bank
add spot market params changed
add perp market params changed
fees added to PerpMarketInfo
perp cancel order accounts changed
perp cancel order by client id accounts changed
InitMangoGroup accounts + params changed

* Helper functions

* Add new liquidation instructions to the list

* Remove todos

* Added in liquidity incentive fields into PerpMarket, FillEvent and PerpOpenOrders; plumbing unfinished

* Working but apply_incentives still not working

* Implemented apply incentives for cancel perp order functions; Still no tests

* Added liquidity incentive params to add_perp_market instruction

* init_perp_market, deposit, place_and_cancel

* Deposit implemented

* Test deposits re-implemented

* remove logs

* Testing place perp order

* merged in ralfs

* fixed consume events

* Fix tests to work with changes, create mngo and msrm mints in localnet

* Scenarios for place and cancel orders

* Add all spot markets to mango group

* added test_compute

* removed print statements to improve compute

* OO inits as Bids

* added some tx size optimization ideas

* added fast mul for unsigned I80F48

* started implementing Fast fixed point library

* Place spot order test working

* Code cleanup for previous

* Worst case scenario test

* Clock implemented

* started pushing in FI80F48

* Fix add oracle test bug

* Mint order fix

* 31 spot open orders test working

* 32 deposits, 31 spot open orders test

* cleaned up get_health and adding logging options for tests

* Perps added to test

* do an active_asset check on perp market before calculating health for it

* bunch of stuff

* Mint fixes

* uncommented perps

* clean up

* Fix duplicate borrows

* Resolve compiler warnings

* Massive cleanup of the tests

* fixed place perp order with reduce_only

* Massive cleanup of the tests part 2

* updated naming of fastmath checked ops

* updated liquidate token and token with optimizations

* optimized bankruptcy and liquidation functions

* wip to get fraction deposits

* not compiling; llvm intrinsics error

* removed llvm stuff

* Tests with fractions

* AddPerpMarket instruction changed
PerpMarket layout changed substantially
EventQueueHeader layout increased by 32 bytes to hold fee info
MangoGroup add 64 bytes padding at the end for expansions
MangoAccount add 32 byte buffer for info; add extra 64 byte padding at end for expansions
CancelPerpOrder and CancelPerpOrderByClientId now take in perp_market_ai as write

InitSpotOpenOrders instruction added and placeSpotOrder does not implicitly initialize an OpenOrders account. Look at mango-client-v3 in placeSpotOrder method to see new way to call

* AddPerpMarket instruction changed
PerpMarket layout changed substantially
EventQueueHeader layout increased by 32 bytes to hold fee info
MangoGroup add 64 bytes padding at the end for expansions
MangoAccount add 32 byte buffer for info; add extra 64 byte padding at end for expansions
CancelPerpOrder and CancelPerpOrderByClientId now take in perp_market_ai as write

InitSpotOpenOrders instruction added and placeSpotOrder does not implicitly initialize an OpenOrders account. Look at mango-client-v3 in placeSpotOrder method to see new way to call

MAX_TOKENS=16

Co-authored-by: dd <dafydd.durairaj@gmail.com>
Co-authored-by: Riordan Panayides <riordan@panayid.es>
Co-authored-by: Ralfs <lagzda7@inbox.lv>
2021-07-28 16:09:01 -04:00
dd 053ec9c694 fixed deploy script 2021-07-28 16:06:29 -04:00
dd c3028abe47 changed devnet_deploy.sh 2021-07-28 15:06:08 -04:00
dafyddd 1fd3094687
Dd/compute (#28)
* maker and taker both executing async on event queue now

* Updated liquidate function to properly update open interest

* implemented socialize loss for perp market bankruptcy

* implemented socialize loss for perp market bankruptcy

* implemented settle_fees; upgraded to 1.7.3

* resolve_token_bankruptcy done

* moved interest rate function params into RootBank and added set_rate_params

* Added dao vault to init_mango_group

* added force_cancel_spot_orders

* Wire up liquidate instructions, fix compiler warning

* Added force cancenl perp orders; fixed stack error with inline(never)

* fixed withdraw function

* fixed set_rate_params

* Took out the '***' markers. Incomplete list of changes:
settle borrow is gone
borrow is gone
interest rate params are now stored on root bank
add spot market params changed
add perp market params changed
fees added to PerpMarketInfo
perp cancel order accounts changed
perp cancel order by client id accounts changed
InitMangoGroup accounts + params changed

* Helper functions

* Add new liquidation instructions to the list

* Remove todos

* Added in liquidity incentive fields into PerpMarket, FillEvent and PerpOpenOrders; plumbing unfinished

* Working but apply_incentives still not working

* Implemented apply incentives for cancel perp order functions; Still no tests

* Added liquidity incentive params to add_perp_market instruction

* init_perp_market, deposit, place_and_cancel

* Deposit implemented

* Test deposits re-implemented

* remove logs

* Testing place perp order

* merged in ralfs

* fixed consume events

* Fix tests to work with changes, create mngo and msrm mints in localnet

* Scenarios for place and cancel orders

* Add all spot markets to mango group

* added test_compute

* removed print statements to improve compute

* OO inits as Bids

* added some tx size optimization ideas

* added fast mul for unsigned I80F48

* started implementing Fast fixed point library

* Place spot order test working

* Code cleanup for previous

* Worst case scenario test

* Clock implemented

* started pushing in FI80F48

* Fix add oracle test bug

* Mint order fix

* 31 spot open orders test working

* 32 deposits, 31 spot open orders test

* cleaned up get_health and adding logging options for tests

* Perps added to test

* do an active_asset check on perp market before calculating health for it

* bunch of stuff

* Mint fixes

* uncommented perps

* clean up

* Fix duplicate borrows

* Resolve compiler warnings

* Massive cleanup of the tests

* fixed place perp order with reduce_only

* Massive cleanup of the tests part 2

* updated naming of fastmath checked ops

* updated liquidate token and token with optimizations

* optimized bankruptcy and liquidation functions

* wip to get fraction deposits

* not compiling; llvm intrinsics error

* removed llvm stuff

* Tests with fractions

* AddPerpMarket instruction changed
PerpMarket layout changed substantially
EventQueueHeader layout increased by 32 bytes to hold fee info
MangoGroup add 64 bytes padding at the end for expansions
MangoAccount add 32 byte buffer for info; add extra 64 byte padding at end for expansions
CancelPerpOrder and CancelPerpOrderByClientId now take in perp_market_ai as write

InitSpotOpenOrders instruction added and placeSpotOrder does not implicitly initialize an OpenOrders account. Look at mango-client-v3 in placeSpotOrder method to see new way to call

* AddPerpMarket instruction changed
PerpMarket layout changed substantially
EventQueueHeader layout increased by 32 bytes to hold fee info
MangoGroup add 64 bytes padding at the end for expansions
MangoAccount add 32 byte buffer for info; add extra 64 byte padding at end for expansions
CancelPerpOrder and CancelPerpOrderByClientId now take in perp_market_ai as write

InitSpotOpenOrders instruction added and placeSpotOrder does not implicitly initialize an OpenOrders account. Look at mango-client-v3 in placeSpotOrder method to see new way to call

MAX_TOKENS=16

* merged in main; test-bpf worst_case_scenario still doesn't work; ready for mergin into main

Co-authored-by: dd <dafydd.durairaj@gmail.com>
Co-authored-by: Riordan Panayides <riordan@panayid.es>
Co-authored-by: Ralfs <lagzda7@inbox.lv>
2021-07-28 14:51:10 -04:00
Tyler Shipe 964c16a232 fix set-oracle price 2021-07-13 10:15:39 -04:00
Tyler Shipe 5954bf09a3 client cli commands for launching a new group 2021-07-13 10:06:54 -04:00
dd 6d64204b5e added devnet feature for cargo build bpf 2021-07-12 17:54:26 -04:00
dafyddd b550d26944
Dd/place spot (#23)
* fixed health calculation in get_spot_health by simulation bids and asks; added some inline nevers; added mutual exclusivity checks in MangoAccount checked_add, checked_sub functions

* rewrote place_spot_order

* added more checks to settle_funds instruction;

Co-authored-by: dd <dafydd.durairaj@gmail.com>
2021-07-08 14:02:19 -04:00
dd 12d2527243 added logging to update_funding 2021-06-24 13:36:16 -04:00
dd d599029aef Implicit remove from basket in settle_funds 2021-06-23 13:44:53 -04:00
dafyddd 5f928d15ed
Renamed to mango (#19)
Co-authored-by: dd <dafydd.durairaj@gmail.com>
2021-06-23 13:09:49 -04:00
dafyddd 148c4ce220
Dd/spotliq (#18)
* Added assets calculation utility functions

* Major changes including in_margin_basket; and check_caches_valid

* halfway done with liquidate; compiles and tests passing

* Merged main in; fixed failing tests

Co-authored-by: dd <dafydd.durairaj@gmail.com>
2021-06-23 12:49:24 -04:00
dd 77cbc801de Changed in_basket to include quote token 2021-06-16 11:49:06 -04:00