Commit Graph

14 Commits

Author SHA1 Message Date
Michael Huang 5bf4b76df4
Refactor curve.rs (#754)
* Refactor shared out of curve.rs

* Refactor out flat curve

* Refactor out constant product curve

* Cargo fmt

* More moving

* Fixup

* use::super -> user::create::curve

* cp -> constant_product

* Fix circular dependency

* Docs

* Trigger Build
2020-11-02 14:29:00 +01:00
Tyera Eulberg c312a0576a
Clippy suggestions (#765) 2020-10-31 19:10:33 -06:00
Jon Cinque 9cd1cb0900
Token-swap: Add "production mode" hard-coded fee constraints (#731)
* Add statically configured program constraints

* Allow missing host fee account

* Run cargo fmt + clippy

* Update JS for new host fee account param

* Fix merge issues

* Add host fee to curve, constrain on curves

* Cleanup static variable

* Add production test to CI

Integrate review feedback

* Run cargo fmt, clippy, prettier

* Re-run cargo fmt

* Fix test for eslint / prettier clash
2020-10-29 12:52:17 +01:00
Michael Vines 80e29ef6b9 Port SPL to solana-program and `cargo build-bpf` 2020-10-24 19:21:38 -07:00
Jon Cinque b0867c7e28
token-swap: Add fee account to receive withdraw / trading fees, trading token mints (#695)
* Add mints to swap info

* Add mints to JS

* Add fee account in SwapInfo / init

* Add test for 0 fee, init test fully

* Add withdraw command interface

* Add fee accounts to swap instruction

* Add calculations for swap and withdraw fees

* Run cargo fmt

* Add new fees to JS and test

* Review feedback: fixup instruction doc and clone

* Update order of accounts in instructions

* Run cargo fmt

* Fix owner fee pool token calculation to include trading fee

* Add owner fees to flat curve, per request

* Fix instruction comment numbering

* Add more errors types for clearer calculation errors

Add a check for withdrawing from fee account

* Cargo fmt
2020-10-23 18:31:58 +02:00
Jon Cinque db42f7abbe
token-swap: Add curve and pool token trait and integrate in processor (#624)
* Add SwapCurve trait and integrate in processor

* Add PoolTokenConverter trait to correspond

* Add curve type parameter to initialization and JS

* Refactor for flat curve test, fmt

* Update token-swap/program/src/curve.rs

Co-authored-by: Tyera Eulberg <teulberg@gmail.com>

* Refactor swap curve to allow for any implementation

* Rename SwapCurveWrapper -> SwapCurve

* Run cargo fmt

* Update CurveType to enum in JS

Co-authored-by: Tyera Eulberg <teulberg@gmail.com>
2020-10-21 20:46:50 +02:00
Yutaro Mori 5f56635fde
Pass TokenSwap state into the constructor to simplify function calls (#586)
* Pass TokenSwap state into the constructor to simplify function calls

* WIP: Update program to return token_program_id

* Add tokenProgramId to js TokenSwapInfo object

* Address pr comments

* Remove TokenSwapInfo and use loadTokenSwap as the primary way to fetch TokenSwap metadata

* Fix module.d.ts

* Address pr comments

* Clarification on comments

Co-authored-by: Yutaro Mori <yutaro@umaproject.org>
2020-10-14 12:37:58 +02:00
Jon Cinque 5e1c2bb34d
token-swap: Use sdk version of Pack (#554)
* token-swap: Use sdk version of Pack

* Update to get_packed_len per review
2020-10-01 11:02:31 +02:00
Jon Cinque 13de66817d
token-swap: Improve pool token supply on initialization, deposit, and withdrawal (#508)
* token-swap: Add token supply in invariant calculation

* Refactor state classes into curve components for future use
* Align pool initialization with Uniswap using geometric mean of token
  amounts
* Fix deposit and withdraw instruction to work as a proportion of pool
  tokens
* Add math utilities to calculate the geometric mean with u64

* Improve variable names

* Use a fixed starting pool size

* Run cargo fmt

* Update js tests with new pool numbers

* Run linting

* Remove math

* Fix BN type issues found by flow
2020-09-23 23:08:44 +02:00
Jon Cinque 84cf55e9ae
Token-swap: add tests for all instructions (#455)
* token-swap: Add initialize tests

* Cleanup initialize test using helper struct

* Add deposit tests

* Run cargo fmt

* Add withdraw tests, refactor swap in test

* Add swap tests

* Integrate review feedback
2020-09-17 12:11:24 +02:00
Jon Cinque 759cbb3866
Pack instructions and state more efficiently (#420)
* Pack instructions and state more efficiently

* SwapInfo and SwapInstruction are more memory-efficient, following the
  example from SPL Token
* Remove unnecessary helper structs to make instructions clearer
* Error -> SwapError
* Update JS tests to reflect the change

* Integrate review feedback
2020-09-11 18:19:06 +02:00
Jon Cinque f5e0d793a9
token-swap: Swap instruction fix and update libs for CI (#408)
* token-swap: Fix swap instruction

* Update SDK libs and fix outstanding issues

* Run lint in token/js

* Disable CI token-swap js tests

* Update code for web3.js 0.75.0

* Update output -> destination verbiage for clarity / consistency
2020-09-10 20:16:50 +02:00
Jon Cinque ac73bd2e73
Fix token-swap tests (#388)
* Fix local token-swap tests

* Change generation of program address to use a nonce
* Accept nonce properly in initialization
* Include nonce in TokenSwap structure
* Fixup serialization with new parameter (padding used for now)
* Update dependencies

Update toml / lock files

Fix token swap initialization end-to-end

Cleanup unit test to use `find_program_address`

Add / refactor tests

Most importantly, added a special test to make sure that
token_program_id is provided at the end of CPI instructions, since
unit testing did not pick up that problem, and it was tough to debug
during end-to-end testing

* Revert some testing changes for PR

* Update token-swap/program/src/processor.rs

Co-authored-by: Tyera Eulberg <teulberg@gmail.com>

* Integrate review comments

* Fmt and clippy

* Refactor for clippy

* Fmt again

* Fix npm lint error

* Clarify signers line as requested

Co-authored-by: Tyera Eulberg <teulberg@gmail.com>
2020-09-06 00:09:05 +02:00
Michael Vines 26ab9bb26a Reorganize crates based on program 2020-08-08 15:25:47 -07:00