Commit Graph

26 Commits

Author SHA1 Message Date
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
Justin Starry ee99fcf025
Check for close and freeze authorities in token-swap (#686) 2020-10-22 21:20:38 +08: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 423d8b1ae9
Add checks for 0 token output and tests (#595) 2020-10-09 19:23:43 +02:00
Jon Cinque bbc5f57dcc
token-swap: Add slippage to swap / withdraw / deposit (#560)
* token-swap: Add slippage to swap / withdraw / deposit

* Update JS snake_case -> camelCase

* Run prettier
2020-10-02 10:40:33 +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
Tyera Eulberg 90b5ce6d65
Standardize failure case ordering (#509)
* Standardize processor failure-case ordering

* Fix token-swap test
2020-09-21 20:28:24 -06:00
Jack May 759fe1487e Switch to solana_sdk Pack and COption 2020-09-21 17:08:37 -07: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 f6fc53c311
token-swap: Fix withdraw instruction (#405)
* Include pool mint in instruction, required for burning
* Add simple Rust test
* Fix js withdraw test
2020-09-09 18:00:03 +02:00
Jon Cinque db729af089
Fix deposit instruction (#399)
* Fix deposit instruction

* Refactor tests for easier composibility
* Add deposit instruction and test
* Deposit JS test works again

* Fix js lint
2020-09-09 10:59:27 +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
Trent Nelson 9eb10d9144 Unrelated clippy... 2020-09-04 01:18:44 -06:00
Trent Nelson ddc47a6d86 Fix TokenSwap initialization test 2020-09-04 01:18:44 -06:00
Jack May 815cca3cb8
Don't repack if not needed (#355) 2020-08-28 12:03:10 -07:00
Jack May 2a5acff2d8
Safer pack/unpack (#349)
* Safer pack/unpack

* fix cli

* clippy

* fix swap

* nit

* clippy

Co-authored-by: Michael Vines <mvines@gmail.com>
2020-08-27 21:19:15 -07:00
Tyera Eulberg 49e6e4a589
Reinstate Mint supply (#342)
* Reinstate Mint supply, and adjust with Minto & Burn

* C headers

* Patch token-cli

* Patch token-swap
2020-08-27 13:06:23 -06:00
Michael Vines c671fdcd3a Update token-swap for token2 2020-08-26 23:10:18 -07:00
Michael Vines 77e43016f1 clippy 2020-08-14 01:22:11 +00:00
Michael Vines b9bb2f2c48 Adapt to create_program_address changes 2020-08-14 01:22:11 +00:00
Michael Vines 26ab9bb26a Reorganize crates based on program 2020-08-08 15:25:47 -07:00