Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
104 commits
Select commit Hold shift + click to select a range
58a5e64
add AMMInstanceCreate
khancode Aug 8, 2022
caa698f
update definitions to get AMMInstanceCreate working
khancode Aug 9, 2022
0676bc1
fix lint errors
khancode Aug 9, 2022
c1424f8
add unit test for Instance Create
khancode Aug 9, 2022
b90626f
fix lint errors
khancode Aug 9, 2022
1309478
fix definitions and change AmmCreate to AMMInstanceCreate
khancode Aug 9, 2022
514cda0
fix lint error
khancode Aug 9, 2022
45e7e90
add AMMInfo
khancode Aug 10, 2022
f451d3c
update AMMInfo docstring
khancode Aug 10, 2022
1614e17
add docstring to AMMInfo params
khancode Aug 10, 2022
d20830e
update definitions.json
khancode Aug 10, 2022
3c99f2d
remove AMMAccount from AMMInstanceCreate model
khancode Aug 10, 2022
2644ade
add AMMDeposit
khancode Aug 14, 2022
3b76ac8
fix lint errors
khancode Aug 14, 2022
7e7aa30
add AMMWithdraw
khancode Aug 14, 2022
3e8362e
add AMMVote
khancode Aug 14, 2022
9b24c24
add AMMBid
khancode Aug 15, 2022
e392a04
fix typo
khancode Aug 15, 2022
06cc754
update AMMBid test
khancode Aug 15, 2022
801922a
Merge branch 'master' into amm
khancode Aug 15, 2022
23e0758
add MaxSlotPrice param to AMMBid
khancode Aug 15, 2022
2a02fb6
refactor test
khancode Aug 15, 2022
7556fe3
update definitions and replace AMMHash with AMMID
khancode Aug 16, 2022
cfe2ef3
update lptokens type to IssuedCurrencyAmount
khancode Aug 16, 2022
f1a9b70
assert with error message
khancode Aug 16, 2022
3b9c0d9
assert with error messages for AMMInstanceCreate and amm_info
khancode Aug 16, 2022
a99ea40
move to_xrpl tests to test_base_model
khancode Aug 16, 2022
a79d1d1
rename lptokens to lp_tokens
khancode Aug 16, 2022
eec65dc
update amm_info request params to be in snake_case
khancode Aug 17, 2022
4fc1722
update docstrings
khancode Aug 17, 2022
46b7825
reorder SPECIAL_CAMELCASE_STRINGS to alphabetical order
khancode Aug 17, 2022
d26a12b
refactor ABBREVIATIONS to be set in one place
khancode Aug 17, 2022
8af2c75
rename LPTokens to LPToken
khancode Aug 18, 2022
9114274
update CHANGELOG.md
khancode Aug 18, 2022
df5cc0f
fix typo
khancode Aug 19, 2022
9d8e725
fix lint error
khancode Aug 19, 2022
d53ab25
refactor max trading fee to be in one place
khancode Aug 20, 2022
d2b98b0
update amm_bid error message
khancode Aug 20, 2022
09b2839
add AuthAccount base model for AMMBid
khancode Aug 20, 2022
5031bf5
update definitions to fix AMM in LEDGER_ENTRY_TYPES
khancode Aug 30, 2022
0428452
update CHANGELOG.md to specify XLS-30
khancode Aug 30, 2022
3c0e55b
update wording on AMMDeposit & AMMWithdraw validation errors
khancode Aug 30, 2022
1ecea66
add negative FeeVal check
khancode Aug 30, 2022
6730f67
add negative TradingFee check
khancode Aug 30, 2022
e66a410
fix lint error
khancode Aug 30, 2022
368d557
export AuthAccount model
khancode Sep 1, 2022
a34fdcc
add AuthAccount and refactor special case models check
khancode Sep 14, 2022
391ef26
revert Path and _value_to_tx_json() changes
khancode Sep 15, 2022
fc82cf3
fix AuthAccount capitalization issues (#432)
mvadari Sep 15, 2022
948af50
Merge branch 'master' into amm
khancode Sep 15, 2022
05f633a
add AMMBid codec-fixture
khancode Sep 15, 2022
5ad9b44
add AMMInstanceCreate codec-fixture
khancode Sep 15, 2022
d9b8bfe
update definitions.json with different AuthAccounts number
khancode Sep 15, 2022
e9307f5
remove AMM codec-fixtures
khancode Sep 15, 2022
e850d8e
Merge branch 'master' into amm
khancode Nov 9, 2022
18e440f
Change amm_info asset parameters to Currency type
khancode Nov 9, 2022
71a389e
API name changes with updated definitions.json
khancode Nov 9, 2022
f6b1d23
rename amm_info param asset1 -> asset
khancode Nov 9, 2022
37ea649
change AMM_MAX_TRADING_FEE to 1% and rename fee_val to trading_fee
khancode Nov 9, 2022
c02aa8f
rename MinBidPrice -> BidMin and MaxBidPrice -> BidMax
khancode Nov 9, 2022
91fe73e
update definitions to change Asset & Asset2 nth values to 3 & 4
khancode Nov 9, 2022
87cd9ae
Use asset/asset2 instead of amm_id for Deposit/Withdraw/Bid/Vote
khancode Nov 9, 2022
02d5c89
update definitions
khancode Nov 16, 2022
559a8dc
add Issue type
khancode Nov 17, 2022
10a242a
add flags to AMM deposit & withdraw
khancode Nov 17, 2022
64dfe9e
add Issue model
khancode Nov 17, 2022
15234d2
add Issue type to models with asset & asset2; remove amm_id
khancode Nov 17, 2022
1f4e8ca
resolve lint errors
khancode Nov 17, 2022
f07f5e5
Merge branch 'master' into amm
khancode Nov 17, 2022
e71e37e
rename LPToken in amm deposit & withdraw
khancode Nov 17, 2022
08a32df
update docstrings
khancode Nov 17, 2022
d2339ad
add AMM codec-fixtures
khancode Nov 17, 2022
f47d6e5
add one asset withdraw & withdraw all tests
khancode Nov 17, 2022
dd20cd1
update definitions.json with refactored error codes
khancode Jan 9, 2023
cba66ef
Merge branch 'master' into amm
khancode Jan 9, 2023
f0e0091
Merge branch 'master' into amm
khancode Feb 15, 2023
8a9d16f
add Owner Reserve Fee for AMMCreate transaction
khancode Feb 15, 2023
2899551
refactor asset pair to be Currency type
khancode Feb 23, 2023
d0ad639
Merge branch 'master' into amm
khancode Feb 23, 2023
ac83c65
update amm_info asset pair to be Currency type and remove Issue model
khancode Feb 23, 2023
5bb4a92
Merge branch 'master' into amm
khancode May 23, 2023
771519f
update definitions and codec-fixtures
khancode May 23, 2023
a8fa396
update DiscountedFee definition
khancode Jun 6, 2023
df1b4cb
Merge branch 'master' into amm
khancode Jun 6, 2023
7c98ea9
update definitions and codec-fixtures
khancode Jun 7, 2023
8ffb1c1
Merge branch 'master' into amm
khancode Jun 9, 2023
31aee69
update definitions
khancode Jun 9, 2023
259f60a
Merge branch 'master' into amm
khancode Jul 10, 2023
d386e93
Merge branch 'master' into amm
khancode Jul 17, 2023
14f158b
remove sidechain method
khancode Jul 17, 2023
0dcaf8c
small refactor
khancode Jul 17, 2023
1b14fd3
update docstrings
khancode Jul 17, 2023
de2c495
Merge branch 'master' into amm
khancode Jul 27, 2023
846c2b5
refactor _value_to_tx_json to remove special case for auth_account
khancode Jul 28, 2023
907955e
refactor AuthAccount to be a NestedModel
khancode Jul 28, 2023
325b9ef
remove test_base_model tests for amm
khancode Jul 28, 2023
f2b7513
add test_to_xrpl_auth_accounts
khancode Jul 28, 2023
494ea6c
fix indentation with tests
khancode Jul 28, 2023
f7133ed
Merge branch 'master' into amm
khancode Aug 7, 2023
1ec117e
Merge branch 'master' into amm
khancode Aug 8, 2023
3ef57c5
update definitions
khancode Aug 8, 2023
0fbedec
add AMMDelete
khancode Aug 8, 2023
66ffcd4
Merge branch 'master' into amm
khancode Aug 16, 2023
a1c0817
add AMMDelete docstring
khancode Aug 16, 2023
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -106,6 +106,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
- Function to parse the final account balances from a transaction's metadata
- Function to parse order book changes from a transaction's metadata
- Support for Ed25519 seeds that don't use the `sEd` prefix
- Support for Automated Market Maker (AMM) transactions and requests as defined in XLS-30.
- Add docs to`get_account_transactions` explaining how to allow pagination through all transaction history [#462]
- Common field `ticket_sequence` to Transaction class

Expand Down
235 changes: 222 additions & 13 deletions tests/unit/core/binarycodec/fixtures/data/codec-fixtures.json

Large diffs are not rendered by default.

16 changes: 16 additions & 0 deletions tests/unit/models/requests/test_amm_info.py
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())
72 changes: 72 additions & 0 deletions tests/unit/models/test_base_model.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

from xrpl.models import XRPLModelException
from xrpl.models.amounts import IssuedCurrencyAmount
from xrpl.models.currencies import XRP, IssuedCurrency
from xrpl.models.requests import (
AccountChannels,
BookOffers,
Expand All @@ -16,6 +17,8 @@
SubmitOnly,
)
from xrpl.models.transactions import (
AMMBid,
AuthAccount,
CheckCreate,
Memo,
Payment,
Expand Down Expand Up @@ -597,3 +600,72 @@ def test_to_xrpl_signer(self):
],
}
self.assertEqual(tx.to_xrpl(), expected)

def test_to_xrpl_auth_accounts(self):
tx = AMMBid(
account="r9LqNeG6qHxjeUocjvVki2XR35weJ9mZgQ",
asset=XRP(),
asset2=IssuedCurrency(
currency="ETH", issuer="rpGtkFRXhgVaBzC5XCR7gyE2AZN5SN3SEW"
),
bid_min=IssuedCurrencyAmount(
currency="5475B6C930B7BDD81CDA8FBA5CED962B11218E5A",
issuer="r3628pXjRqfw5zfwGfhSusjZTvE3BoxEBw",
value="25",
),
bid_max=IssuedCurrencyAmount(
currency="5475B6C930B7BDD81CDA8FBA5CED962B11218E5A",
issuer="r3628pXjRqfw5zfwGfhSusjZTvE3BoxEBw",
value="35",
),
auth_accounts=[
AuthAccount(account="rNZdsTBP5tH1M6GHC6bTreHAp6ouP8iZSh"),
AuthAccount(account="rfpFv97Dwu89FTyUwPjtpZBbuZxTqqgTmH"),
AuthAccount(account="rzzYHPGb8Pa64oqxCzmuffm122bitq3Vb"),
AuthAccount(account="rhwxHxaHok86fe4LykBom1jSJ3RYQJs1h4"),
],
)
expected = {
"Account": "r9LqNeG6qHxjeUocjvVki2XR35weJ9mZgQ",
"Asset": {"currency": "XRP"},
"Asset2": {
"currency": "ETH",
"issuer": "rpGtkFRXhgVaBzC5XCR7gyE2AZN5SN3SEW",
},
"BidMin": {
"currency": "5475B6C930B7BDD81CDA8FBA5CED962B11218E5A",
"issuer": "r3628pXjRqfw5zfwGfhSusjZTvE3BoxEBw",
"value": "25",
},
"BidMax": {
"currency": "5475B6C930B7BDD81CDA8FBA5CED962B11218E5A",
"issuer": "r3628pXjRqfw5zfwGfhSusjZTvE3BoxEBw",
"value": "35",
},
"AuthAccounts": [
{
"AuthAccount": {
"Account": "rNZdsTBP5tH1M6GHC6bTreHAp6ouP8iZSh",
}
},
{
"AuthAccount": {
"Account": "rfpFv97Dwu89FTyUwPjtpZBbuZxTqqgTmH",
}
},
{
"AuthAccount": {
"Account": "rzzYHPGb8Pa64oqxCzmuffm122bitq3Vb",
}
},
{
"AuthAccount": {
"Account": "rhwxHxaHok86fe4LykBom1jSJ3RYQJs1h4",
}
},
],
"TransactionType": "AMMBid",
"SigningPubKey": "",
"Flags": 0,
}
self.assertEqual(tx.to_xrpl(), expected)
66 changes: 66 additions & 0 deletions tests/unit/models/transactions/test_amm_bid.py
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'}",
)
52 changes: 52 additions & 0 deletions tests/unit/models/transactions/test_amm_create.py
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'}",
)
17 changes: 17 additions & 0 deletions tests/unit/models/transactions/test_amm_delete.py
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())
127 changes: 127 additions & 0 deletions tests/unit/models/transactions/test_amm_deposit.py
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`'}",
)
Loading