-
Notifications
You must be signed in to change notification settings - Fork 116
feat: add AMM support #422
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
Merged
Changes from all commits
Commits
Show all changes
104 commits
Select commit
Hold shift + click to select a range
58a5e64
add AMMInstanceCreate
khancode caa698f
update definitions to get AMMInstanceCreate working
khancode 0676bc1
fix lint errors
khancode c1424f8
add unit test for Instance Create
khancode b90626f
fix lint errors
khancode 1309478
fix definitions and change AmmCreate to AMMInstanceCreate
khancode 514cda0
fix lint error
khancode 45e7e90
add AMMInfo
khancode f451d3c
update AMMInfo docstring
khancode 1614e17
add docstring to AMMInfo params
khancode d20830e
update definitions.json
khancode 3c99f2d
remove AMMAccount from AMMInstanceCreate model
khancode 2644ade
add AMMDeposit
khancode 3b76ac8
fix lint errors
khancode 7e7aa30
add AMMWithdraw
khancode 3e8362e
add AMMVote
khancode 9b24c24
add AMMBid
khancode e392a04
fix typo
khancode 06cc754
update AMMBid test
khancode 801922a
Merge branch 'master' into amm
khancode 23e0758
add MaxSlotPrice param to AMMBid
khancode 2a02fb6
refactor test
khancode 7556fe3
update definitions and replace AMMHash with AMMID
khancode cfe2ef3
update lptokens type to IssuedCurrencyAmount
khancode f1a9b70
assert with error message
khancode 3b9c0d9
assert with error messages for AMMInstanceCreate and amm_info
khancode a99ea40
move to_xrpl tests to test_base_model
khancode a79d1d1
rename lptokens to lp_tokens
khancode eec65dc
update amm_info request params to be in snake_case
khancode 4fc1722
update docstrings
khancode 46b7825
reorder SPECIAL_CAMELCASE_STRINGS to alphabetical order
khancode d26a12b
refactor ABBREVIATIONS to be set in one place
khancode 8af2c75
rename LPTokens to LPToken
khancode 9114274
update CHANGELOG.md
khancode df5cc0f
fix typo
khancode 9d8e725
fix lint error
khancode d53ab25
refactor max trading fee to be in one place
khancode d2b98b0
update amm_bid error message
khancode 09b2839
add AuthAccount base model for AMMBid
khancode 5031bf5
update definitions to fix AMM in LEDGER_ENTRY_TYPES
khancode 0428452
update CHANGELOG.md to specify XLS-30
khancode 3c0e55b
update wording on AMMDeposit & AMMWithdraw validation errors
khancode 1ecea66
add negative FeeVal check
khancode 6730f67
add negative TradingFee check
khancode e66a410
fix lint error
khancode 368d557
export AuthAccount model
khancode a34fdcc
add AuthAccount and refactor special case models check
khancode 391ef26
revert Path and _value_to_tx_json() changes
khancode fc82cf3
fix AuthAccount capitalization issues (#432)
mvadari 948af50
Merge branch 'master' into amm
khancode 05f633a
add AMMBid codec-fixture
khancode 5ad9b44
add AMMInstanceCreate codec-fixture
khancode d9b8bfe
update definitions.json with different AuthAccounts number
khancode e9307f5
remove AMM codec-fixtures
khancode e850d8e
Merge branch 'master' into amm
khancode 18e440f
Change amm_info asset parameters to Currency type
khancode 71a389e
API name changes with updated definitions.json
khancode f6b1d23
rename amm_info param asset1 -> asset
khancode 37ea649
change AMM_MAX_TRADING_FEE to 1% and rename fee_val to trading_fee
khancode c02aa8f
rename MinBidPrice -> BidMin and MaxBidPrice -> BidMax
khancode 91fe73e
update definitions to change Asset & Asset2 nth values to 3 & 4
khancode 87cd9ae
Use asset/asset2 instead of amm_id for Deposit/Withdraw/Bid/Vote
khancode 02d5c89
update definitions
khancode 559a8dc
add Issue type
khancode 10a242a
add flags to AMM deposit & withdraw
khancode 64dfe9e
add Issue model
khancode 15234d2
add Issue type to models with asset & asset2; remove amm_id
khancode 1f4e8ca
resolve lint errors
khancode f07f5e5
Merge branch 'master' into amm
khancode e71e37e
rename LPToken in amm deposit & withdraw
khancode 08a32df
update docstrings
khancode d2339ad
add AMM codec-fixtures
khancode f47d6e5
add one asset withdraw & withdraw all tests
khancode dd20cd1
update definitions.json with refactored error codes
khancode cba66ef
Merge branch 'master' into amm
khancode f0e0091
Merge branch 'master' into amm
khancode 8a9d16f
add Owner Reserve Fee for AMMCreate transaction
khancode 2899551
refactor asset pair to be Currency type
khancode d0ad639
Merge branch 'master' into amm
khancode ac83c65
update amm_info asset pair to be Currency type and remove Issue model
khancode 5bb4a92
Merge branch 'master' into amm
khancode 771519f
update definitions and codec-fixtures
khancode a8fa396
update DiscountedFee definition
khancode df1b4cb
Merge branch 'master' into amm
khancode 7c98ea9
update definitions and codec-fixtures
khancode 8ffb1c1
Merge branch 'master' into amm
khancode 31aee69
update definitions
khancode 259f60a
Merge branch 'master' into amm
khancode d386e93
Merge branch 'master' into amm
khancode 14f158b
remove sidechain method
khancode 0dcaf8c
small refactor
khancode 1b14fd3
update docstrings
khancode de2c495
Merge branch 'master' into amm
khancode 846c2b5
refactor _value_to_tx_json to remove special case for auth_account
khancode 907955e
refactor AuthAccount to be a NestedModel
khancode 325b9ef
remove test_base_model tests for amm
khancode f2b7513
add test_to_xrpl_auth_accounts
khancode 494ea6c
fix indentation with tests
khancode f7133ed
Merge branch 'master' into amm
khancode 1ec117e
Merge branch 'master' into amm
khancode 3ef57c5
update definitions
khancode 0fbedec
add AMMDelete
khancode 66ffcd4
Merge branch 'master' into amm
khancode a1c0817
add AMMDelete docstring
khancode File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
235 changes: 222 additions & 13 deletions
235
tests/unit/core/binarycodec/fixtures/data/codec-fixtures.json
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,16 @@ | ||
| from unittest import TestCase | ||
|
|
||
| from xrpl.models.currencies import XRP, IssuedCurrency | ||
| from xrpl.models.requests import AMMInfo | ||
|
|
||
| _ASSET = XRP() | ||
| _ASSET_2 = IssuedCurrency(currency="USD", issuer="rN6zcSynkRnf8zcgTVrRL8K7r4ovE7J4Zj") | ||
|
|
||
|
|
||
| class TestAMMInfo(TestCase): | ||
| def test_asset_asset2(self): | ||
| request = AMMInfo( | ||
| asset=_ASSET, | ||
| asset2=_ASSET_2, | ||
| ) | ||
| self.assertTrue(request.is_valid()) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,66 @@ | ||
| from unittest import TestCase | ||
|
|
||
| from xrpl.models.amounts import IssuedCurrencyAmount | ||
| from xrpl.models.currencies import XRP, IssuedCurrency | ||
| from xrpl.models.exceptions import XRPLModelException | ||
| from xrpl.models.transactions import AMMBid, AuthAccount | ||
|
|
||
| _ACCOUNT = "r9LqNeG6qHxjeUocjvVki2XR35weJ9mZgQ" | ||
| _ASSET = XRP() | ||
| _ASSET2 = IssuedCurrency(currency="ETH", issuer="rpGtkFRXhgVaBzC5XCR7gyE2AZN5SN3SEW") | ||
| _AUTH_ACCOUNTS = [ | ||
| AuthAccount( | ||
| account="rNZdsTBP5tH1M6GHC6bTreHAp6ouP8iZSh", | ||
| ), | ||
| AuthAccount( | ||
| account="rfpFv97Dwu89FTyUwPjtpZBbuZxTqqgTmH", | ||
| ), | ||
| AuthAccount( | ||
| account="rzzYHPGb8Pa64oqxCzmuffm122bitq3Vb", | ||
| ), | ||
| AuthAccount( | ||
| account="rhwxHxaHok86fe4LykBom1jSJ3RYQJs1h4", | ||
| ), | ||
| ] | ||
| _LPTOKEN_CURRENCY = "5475B6C930B7BDD81CDA8FBA5CED962B11218E5A" | ||
| _LPTOKEN_ISSUER = "r3628pXjRqfw5zfwGfhSusjZTvE3BoxEBw" | ||
|
|
||
|
|
||
| class TestAMMBid(TestCase): | ||
| def test_tx_valid(self): | ||
| tx = AMMBid( | ||
| account=_ACCOUNT, | ||
| asset=_ASSET, | ||
| asset2=_ASSET2, | ||
| bid_min=IssuedCurrencyAmount( | ||
| currency=_LPTOKEN_CURRENCY, | ||
| issuer=_LPTOKEN_ISSUER, | ||
| value="25", | ||
| ), | ||
| bid_max=IssuedCurrencyAmount( | ||
| currency=_LPTOKEN_CURRENCY, | ||
| issuer=_LPTOKEN_ISSUER, | ||
| value="35", | ||
| ), | ||
| auth_accounts=_AUTH_ACCOUNTS, | ||
| ) | ||
| self.assertTrue(tx.is_valid()) | ||
|
|
||
| def test_auth_accounts_length_error(self): | ||
| auth_accounts = _AUTH_ACCOUNTS.copy() | ||
| auth_accounts.append( | ||
| AuthAccount( | ||
| account="r3X6noRsvaLapAKCG78zAtWcbhB3sggS1s", | ||
| ), | ||
| ) | ||
| with self.assertRaises(XRPLModelException) as error: | ||
| AMMBid( | ||
| account=_ACCOUNT, | ||
| asset=_ASSET, | ||
| asset2=_ASSET2, | ||
| auth_accounts=auth_accounts, | ||
| ) | ||
| self.assertEqual( | ||
| error.exception.args[0], | ||
| "{'auth_accounts': 'Length must not be greater than 4'}", | ||
| ) | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,52 @@ | ||
| from sys import maxsize | ||
| from unittest import TestCase | ||
|
|
||
| from xrpl.models.amounts import IssuedCurrencyAmount | ||
| from xrpl.models.exceptions import XRPLModelException | ||
| from xrpl.models.transactions import AMMCreate | ||
|
|
||
| _ACCOUNT = "r9LqNeG6qHxjeUocjvVki2XR35weJ9mZgQ" | ||
| _IOU_ISSUER = "rPyfep3gcLzkosKC9XiE77Y8DZWG6iWDT9" | ||
|
|
||
|
|
||
| class TestAMMCreate(TestCase): | ||
| def test_tx_is_valid(self): | ||
| tx = AMMCreate( | ||
| account=_ACCOUNT, | ||
| amount="1000", | ||
| amount2=IssuedCurrencyAmount( | ||
| currency="USD", issuer=_IOU_ISSUER, value="1000" | ||
| ), | ||
| trading_fee=12, | ||
| ) | ||
| self.assertTrue(tx.is_valid()) | ||
|
|
||
| def test_trading_fee_too_high(self): | ||
| with self.assertRaises(XRPLModelException) as error: | ||
| AMMCreate( | ||
| account=_ACCOUNT, | ||
| amount="1000", | ||
| amount2=IssuedCurrencyAmount( | ||
| currency="USD", issuer=_IOU_ISSUER, value="1000" | ||
| ), | ||
| trading_fee=maxsize, | ||
| ) | ||
| self.assertEqual( | ||
| error.exception.args[0], | ||
| "{'trading_fee': 'Must be between 0 and 1000'}", | ||
| ) | ||
|
|
||
| def test_trading_fee_negative_number(self): | ||
| with self.assertRaises(XRPLModelException) as error: | ||
| AMMCreate( | ||
| account=_ACCOUNT, | ||
| amount="1000", | ||
| amount2=IssuedCurrencyAmount( | ||
| currency="USD", issuer=_IOU_ISSUER, value="1000" | ||
| ), | ||
| trading_fee=-1, | ||
| ) | ||
| self.assertEqual( | ||
| error.exception.args[0], | ||
| "{'trading_fee': 'Must be between 0 and 1000'}", | ||
| ) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,17 @@ | ||
| from unittest import TestCase | ||
|
|
||
| from xrpl.models.currencies import XRP, IssuedCurrency | ||
| from xrpl.models.transactions import AMMDelete | ||
|
|
||
|
|
||
| class TestAMMDeposit(TestCase): | ||
| def test_tx_valid(self): | ||
| tx = AMMDelete( | ||
| account="r9LqNeG6qHxjeUocjvVki2XR35weJ9mZgQ", | ||
| sequence=1337, | ||
| asset=XRP(), | ||
| asset2=IssuedCurrency( | ||
| currency="ETH", issuer="rpGtkFRXhgVaBzC5XCR7gyE2AZN5SN3SEW" | ||
| ), | ||
| ) | ||
| self.assertTrue(tx.is_valid()) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,127 @@ | ||
| from unittest import TestCase | ||
|
|
||
| from xrpl.models.amounts import IssuedCurrencyAmount | ||
| from xrpl.models.currencies import XRP, IssuedCurrency | ||
| from xrpl.models.exceptions import XRPLModelException | ||
| from xrpl.models.transactions import AMMDeposit | ||
| from xrpl.models.transactions.amm_deposit import AMMDepositFlag | ||
|
|
||
| _ACCOUNT = "r9LqNeG6qHxjeUocjvVki2XR35weJ9mZgQ" | ||
| _ASSET = XRP() | ||
| _ASSET2 = IssuedCurrency(currency="ETH", issuer="rpGtkFRXhgVaBzC5XCR7gyE2AZN5SN3SEW") | ||
| _AMOUNT = "1000" | ||
| _LPTOKEN_CURRENCY = "B3813FCAB4EE68B3D0D735D6849465A9113EE048" | ||
| _LPTOKEN_ISSUER = "rH438jEAzTs5PYtV6CHZqpDpwCKQmPW9Cg" | ||
|
|
||
|
|
||
| class TestAMMDeposit(TestCase): | ||
| def test_tx_valid_xrpl_lptokenout(self): | ||
| tx = AMMDeposit( | ||
| account=_ACCOUNT, | ||
| sequence=1337, | ||
| asset=_ASSET, | ||
| asset2=_ASSET2, | ||
| lp_token_out=IssuedCurrencyAmount( | ||
| currency=_LPTOKEN_CURRENCY, | ||
| issuer=_LPTOKEN_ISSUER, | ||
| value=_AMOUNT, | ||
| ), | ||
| flags=AMMDepositFlag.TF_LP_TOKEN, | ||
| ) | ||
| self.assertTrue(tx.is_valid()) | ||
|
|
||
| def test_tx_valid_amount(self): | ||
| tx = AMMDeposit( | ||
| account=_ACCOUNT, | ||
| sequence=1337, | ||
| asset=_ASSET, | ||
| asset2=_ASSET2, | ||
| amount=_AMOUNT, | ||
| flags=AMMDepositFlag.TF_SINGLE_ASSET, | ||
| ) | ||
| self.assertTrue(tx.is_valid()) | ||
|
|
||
| def test_tx_valid_amount_amount2(self): | ||
| tx = AMMDeposit( | ||
| account=_ACCOUNT, | ||
| sequence=1337, | ||
| asset=_ASSET, | ||
| asset2=_ASSET2, | ||
| amount=_AMOUNT, | ||
| amount2=IssuedCurrencyAmount( | ||
| currency=_ASSET2.currency, issuer=_ASSET2.issuer, value="500" | ||
| ), | ||
| flags=AMMDepositFlag.TF_TWO_ASSET, | ||
| ) | ||
| self.assertTrue(tx.is_valid()) | ||
|
|
||
| def test_tx_valid_amount_lptokenout(self): | ||
| tx = AMMDeposit( | ||
| account=_ACCOUNT, | ||
| sequence=1337, | ||
| asset=_ASSET, | ||
| asset2=_ASSET2, | ||
| amount=_AMOUNT, | ||
| lp_token_out=IssuedCurrencyAmount( | ||
| currency=_LPTOKEN_CURRENCY, | ||
| issuer=_LPTOKEN_ISSUER, | ||
| value="500", | ||
| ), | ||
| flags=AMMDepositFlag.TF_ONE_ASSET_LP_TOKEN, | ||
| ) | ||
| self.assertTrue(tx.is_valid()) | ||
|
|
||
| def test_tx_valid_amount_eprice(self): | ||
| tx = AMMDeposit( | ||
| account=_ACCOUNT, | ||
| sequence=1337, | ||
| asset=_ASSET, | ||
| asset2=_ASSET2, | ||
| amount=_AMOUNT, | ||
| e_price="25", | ||
| flags=AMMDepositFlag.TF_LIMIT_LP_TOKEN, | ||
| ) | ||
| self.assertTrue(tx.is_valid()) | ||
|
|
||
| def test_undefined_amount_undefined_lptokenout_invalid_combo(self): | ||
| with self.assertRaises(XRPLModelException) as error: | ||
| AMMDeposit( | ||
| account=_ACCOUNT, | ||
| sequence=1337, | ||
| asset=_ASSET, | ||
| asset2=_ASSET2, | ||
| ) | ||
| self.assertEqual( | ||
| error.exception.args[0], | ||
| "{'AMMDeposit': 'Must set at least `lp_token_out` or `amount`'}", | ||
| ) | ||
|
|
||
| def test_undefined_amount_defined_amount2_invalid_combo(self): | ||
| with self.assertRaises(XRPLModelException) as error: | ||
| AMMDeposit( | ||
| account=_ACCOUNT, | ||
| sequence=1337, | ||
| asset=_ASSET, | ||
| asset2=_ASSET2, | ||
| amount2=IssuedCurrencyAmount( | ||
| currency=_ASSET2.currency, issuer=_ASSET2.issuer, value="500" | ||
| ), | ||
| ) | ||
| self.assertEqual( | ||
| error.exception.args[0], | ||
| "{'AMMDeposit': 'Must set `amount` with `amount2`'}", | ||
| ) | ||
|
|
||
| def test_undefined_amount_defined_eprice_invalid_combo(self): | ||
| with self.assertRaises(XRPLModelException) as error: | ||
| AMMDeposit( | ||
| account=_ACCOUNT, | ||
| sequence=1337, | ||
| asset=_ASSET, | ||
| asset2=_ASSET2, | ||
| e_price="25", | ||
| ) | ||
| self.assertEqual( | ||
| error.exception.args[0], | ||
| "{'AMMDeposit': 'Must set `amount` with `e_price`'}", | ||
| ) |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.