Skip to content

Commit 5f3ce93

Browse files
committed
AMMWihdraw AMM account detection when there are two pools
1 parent 45f6136 commit 5f3ce93

File tree

3 files changed

+344
-0
lines changed

3 files changed

+344
-0
lines changed

src/TxParticipantExtractor.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -248,6 +248,8 @@ private function logic_detectAMMWithdraw()
248248
if(count($accounts) == 2) {
249249
//Handle case when LPToken issuer and non LPToken issuer are left (see AA32D2BFA786383BE8AA96CB9ACA59C4E3DEE2410879E6B52B8928DF1CE544B9)
250250

251+
$accounts = array_reverse($accounts); //first discovered is usually LPToken issuer
252+
251253
//Remove account with RIPPLESTATE_HIGHLIMIT_ISSUER
252254
foreach($accounts as $_a => $roles) {
253255
if(\in_array('RIPPLESTATE_HIGHLIMIT_ISSUER',$roles)) {

tests/Tx58Test.php

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
<?php declare(strict_types=1);
2+
3+
namespace XRPLWin\XRPLTxParticipantExtractor\Tests;
4+
5+
use PHPUnit\Framework\TestCase;
6+
use XRPLWin\XRPLTxParticipantExtractor\TxParticipantExtractor;
7+
8+
/***
9+
* AMMWithdraw
10+
* Happens when liquidity is withdrawn from an AMM pool and there is other pool involvement.
11+
* @see 2859C63BBFFEB25EE0D116284DC903A2EE3AE8548275D79BD5D33BB5B25C10A9
12+
*/
13+
final class Tx58Test extends TestCase
14+
{
15+
public function testAMMWithdrawMultiAMM()
16+
{
17+
$transaction = file_get_contents(__DIR__.'/fixtures/tx58.json');
18+
$transaction = \json_decode($transaction);
19+
$TxParticipantExtractor = new TxParticipantExtractor($transaction->result);
20+
21+
$parsedTransaction = $TxParticipantExtractor->result();
22+
$this->assertIsArray($parsedTransaction);
23+
$accounts = $TxParticipantExtractor->accounts();
24+
25+
//AMM account
26+
$this->assertEquals([
27+
'RIPPLESTATE_HIGHLIMIT_ISSUER',
28+
'RIPPLESTATE_LOWLIMIT_ISSUER',
29+
'DIRECTORYNODE_OWNER',
30+
'AMM_ACCOUNT'
31+
], $accounts['rnuESaWHkTUjU9hys6UP5MVsDjrmWRYVk5']);
32+
33+
//NOT amm account in this case
34+
$this->assertEquals([
35+
'DIRECTORYNODE_OWNER',
36+
'RIPPLESTATE_HIGHLIMIT_ISSUER',
37+
], $accounts['r4UPddYeGeZgDhSGPkooURsQtmGda4oYQW']); //not AMM
38+
$this->assertTrue(true);
39+
40+
}
41+
}

tests/fixtures/tx58.json

Lines changed: 301 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,301 @@
1+
{
2+
"result": {
3+
"Account": "rUmkDMvA3nuVKdbp26WS7GooQrhTdXWEq",
4+
"Asset": {
5+
"currency": "584D454D45000000000000000000000000000000",
6+
"issuer": "r4UPddYeGeZgDhSGPkooURsQtmGda4oYQW"
7+
},
8+
"Asset2": {
9+
"currency": "XPM",
10+
"issuer": "rXPMxBeefHGxx2K7g5qmmWq3gFsgawkoa"
11+
},
12+
"Fee": "12",
13+
"Flags": 2147614720,
14+
"LastLedgerSequence": 99779920,
15+
"Memos": [
16+
{
17+
"Memo": {
18+
"MemoData": "414D4D20776974686472617720696E69746961746564207669612058506D61726B65742E636F6D"
19+
}
20+
}
21+
],
22+
"Sequence": 91806585,
23+
"SigningPubKey": "036CD5914E03CB3A6D670C329BB4B52D4B54F3316A50EFAC61166F37E490989480",
24+
"SourceTag": 20221212,
25+
"TransactionType": "AMMWithdraw",
26+
"TxnSignature": "3045022100A5F42F6BF0C2D5404992AF2B12E6BABFCFD046E669B1882499F8664BE8DAD01E02203D55578F0AEB7745405067CF537E33FDC885BA7555AF04AADE14CA6EB4FD9500",
27+
"ctid": "C5F2853E00290000",
28+
"date": 814786461,
29+
"hash": "2859C63BBFFEB25EE0D116284DC903A2EE3AE8548275D79BD5D33BB5B25C10A9",
30+
"inLedger": 99779902,
31+
"ledger_index": 99779902,
32+
"meta": {
33+
"AffectedNodes": [
34+
{
35+
"ModifiedNode": {
36+
"LedgerEntryType": "AccountRoot",
37+
"LedgerIndex": "0A4CF135FCB8A62C6C74911E186F736DFD26C12179B1408920A581DEEAC7FB68",
38+
"PreviousTxnID": "18324B40827755DCC9F72311642556840B40C42890AFE1E763C6585791F5C600",
39+
"PreviousTxnLgrSeq": 99779885
40+
}
41+
},
42+
{
43+
"ModifiedNode": {
44+
"FinalFields": {
45+
"Balance": {
46+
"currency": "XPM",
47+
"issuer": "rrrrrrrrrrrrrrrrrrrrBZbvji",
48+
"value": "-26834.16325634331"
49+
},
50+
"Flags": 16908288,
51+
"HighLimit": {
52+
"currency": "XPM",
53+
"issuer": "rnuESaWHkTUjU9hys6UP5MVsDjrmWRYVk5",
54+
"value": "0"
55+
},
56+
"HighNode": "0",
57+
"LowLimit": {
58+
"currency": "XPM",
59+
"issuer": "rXPMxBeefHGxx2K7g5qmmWq3gFsgawkoa",
60+
"value": "0"
61+
},
62+
"LowNode": "23d"
63+
},
64+
"LedgerEntryType": "RippleState",
65+
"LedgerIndex": "14AE45DE9CEB716D31E41636A8FAAF8A7101173D6824EB16E0E0DCFFFBF830F8",
66+
"PreviousFields": {
67+
"Balance": {
68+
"currency": "XPM",
69+
"issuer": "rrrrrrrrrrrrrrrrrrrrBZbvji",
70+
"value": "-26834.16325634332"
71+
}
72+
},
73+
"PreviousTxnID": "18324B40827755DCC9F72311642556840B40C42890AFE1E763C6585791F5C600",
74+
"PreviousTxnLgrSeq": 99779885
75+
}
76+
},
77+
{
78+
"ModifiedNode": {
79+
"FinalFields": {
80+
"Account": "rUmkDMvA3nuVKdbp26WS7GooQrhTdXWEq",
81+
"Balance": "170057906",
82+
"Flags": 0,
83+
"OwnerCount": 817,
84+
"Sequence": 91806586
85+
},
86+
"LedgerEntryType": "AccountRoot",
87+
"LedgerIndex": "2641DE75C04137349D9C05744A6FF3FCEE57A67F1A124D0C1C88D39B655FB1A0",
88+
"PreviousFields": {
89+
"Balance": "170057918",
90+
"Sequence": 91806585
91+
},
92+
"PreviousTxnID": "F46CC5D282A1E3C0BD8BB64F5AB1093DD220C6E4D6E08768D1E03FCEE997218E",
93+
"PreviousTxnLgrSeq": 99779898
94+
}
95+
},
96+
{
97+
"ModifiedNode": {
98+
"FinalFields": {
99+
"Balance": {
100+
"currency": "XPM",
101+
"issuer": "rrrrrrrrrrrrrrrrrrrrBZbvji",
102+
"value": "9474.455916896954"
103+
},
104+
"Flags": 1114112,
105+
"HighLimit": {
106+
"currency": "XPM",
107+
"issuer": "rXPMxBeefHGxx2K7g5qmmWq3gFsgawkoa",
108+
"value": "0"
109+
},
110+
"HighNode": "a0",
111+
"LowLimit": {
112+
"currency": "XPM",
113+
"issuer": "rUmkDMvA3nuVKdbp26WS7GooQrhTdXWEq",
114+
"value": "1000000000000000e-3"
115+
},
116+
"LowNode": "0"
117+
},
118+
"LedgerEntryType": "RippleState",
119+
"LedgerIndex": "3987A54B1F3C4DA04797214750715FA2E5E01CF97CFC9439AAFF9F69C1B68EF2",
120+
"PreviousFields": {
121+
"Balance": {
122+
"currency": "XPM",
123+
"issuer": "rrrrrrrrrrrrrrrrrrrrBZbvji",
124+
"value": "9474.455916896949"
125+
}
126+
},
127+
"PreviousTxnID": "220E84CF149724F543EF2C7F26555646EA850F81FE25B98E55829333EF66DE76",
128+
"PreviousTxnLgrSeq": 99779713
129+
}
130+
},
131+
{
132+
"DeletedNode": {
133+
"FinalFields": {
134+
"Balance": {
135+
"currency": "03F2F0D53EE208B8188EEA2F9871D6F27149C8A9",
136+
"issuer": "rrrrrrrrrrrrrrrrrrrrBZbvji",
137+
"value": "0"
138+
},
139+
"Flags": 1048576,
140+
"HighLimit": {
141+
"currency": "03F2F0D53EE208B8188EEA2F9871D6F27149C8A9",
142+
"issuer": "rnuESaWHkTUjU9hys6UP5MVsDjrmWRYVk5",
143+
"value": "0"
144+
},
145+
"HighNode": "6",
146+
"LowLimit": {
147+
"currency": "03F2F0D53EE208B8188EEA2F9871D6F27149C8A9",
148+
"issuer": "rUmkDMvA3nuVKdbp26WS7GooQrhTdXWEq",
149+
"value": "0"
150+
},
151+
"LowNode": "d",
152+
"PreviousTxnID": "D282C3ED69A31AFD5B4C62367955775205EED5061FB17027FB74AC33270E12A8",
153+
"PreviousTxnLgrSeq": 99779699
154+
},
155+
"LedgerEntryType": "RippleState",
156+
"LedgerIndex": "622AAB6682ACC1A826FCDF6DE67001F4D7542E21F71E3831001E7D84BA525618",
157+
"PreviousFields": {
158+
"Balance": {
159+
"currency": "03F2F0D53EE208B8188EEA2F9871D6F27149C8A9",
160+
"issuer": "rrrrrrrrrrrrrrrrrrrrBZbvji",
161+
"value": "0.0000000002"
162+
},
163+
"Flags": 1114112
164+
}
165+
}
166+
},
167+
{
168+
"ModifiedNode": {
169+
"FinalFields": {
170+
"Flags": 0,
171+
"IndexNext": "e",
172+
"IndexPrevious": "c",
173+
"Owner": "rUmkDMvA3nuVKdbp26WS7GooQrhTdXWEq",
174+
"RootIndex": "0EAF0845BC28CB9A543F7212FF4B307B844D837FE75EE7243AA3BECEF5E19854"
175+
},
176+
"LedgerEntryType": "DirectoryNode",
177+
"LedgerIndex": "94D602EFF095013ABBD7224A7E3EE44FC7CAB499458FC753C3B1C8A46425C81B",
178+
"PreviousTxnID": "41D2C79479CE970AFBEB8D70132F8B2315FD95C87C0347514909192F73C6F2AD",
179+
"PreviousTxnLgrSeq": 99779782
180+
}
181+
},
182+
{
183+
"ModifiedNode": {
184+
"FinalFields": {
185+
"Flags": 0,
186+
"IndexPrevious": "108",
187+
"Owner": "r4UPddYeGeZgDhSGPkooURsQtmGda4oYQW",
188+
"RootIndex": "C588859A643002A8ABF88A658A0B7588B36C55801AF4B7BB37C07783DF7765AF"
189+
},
190+
"LedgerEntryType": "DirectoryNode",
191+
"LedgerIndex": "9D414A5EA97E31F07E2686C2247FB61A09DFF93EA292C80242F3AD32934EF459",
192+
"PreviousTxnID": "18324B40827755DCC9F72311642556840B40C42890AFE1E763C6585791F5C600",
193+
"PreviousTxnLgrSeq": 99779885
194+
}
195+
},
196+
{
197+
"CreatedNode": {
198+
"LedgerEntryType": "RippleState",
199+
"LedgerIndex": "B7B11A809DD05A52E0536D84EF7C45ED51797586E6A72D18986238005870B46C",
200+
"NewFields": {
201+
"Balance": {
202+
"currency": "584D454D45000000000000000000000000000000",
203+
"issuer": "rrrrrrrrrrrrrrrrrrrrBZbvji",
204+
"value": "0.000000008883372170117126"
205+
},
206+
"Flags": 1114112,
207+
"HighLimit": {
208+
"currency": "584D454D45000000000000000000000000000000",
209+
"issuer": "r4UPddYeGeZgDhSGPkooURsQtmGda4oYQW",
210+
"value": "0"
211+
},
212+
"HighNode": "109",
213+
"LowLimit": {
214+
"currency": "584D454D45000000000000000000000000000000",
215+
"issuer": "rUmkDMvA3nuVKdbp26WS7GooQrhTdXWEq",
216+
"value": "0"
217+
},
218+
"LowNode": "22"
219+
}
220+
}
221+
},
222+
{
223+
"ModifiedNode": {
224+
"LedgerEntryType": "AccountRoot",
225+
"LedgerIndex": "BE724DC6C2DACBFB29B5C9CBC92691AAEEA01B7773F8C007AD714C393A1DFC1A",
226+
"PreviousTxnID": "18324B40827755DCC9F72311642556840B40C42890AFE1E763C6585791F5C600",
227+
"PreviousTxnLgrSeq": 99779885
228+
}
229+
},
230+
{
231+
"ModifiedNode": {
232+
"FinalFields": {
233+
"Flags": 0,
234+
"IndexPrevious": "21",
235+
"Owner": "rUmkDMvA3nuVKdbp26WS7GooQrhTdXWEq",
236+
"RootIndex": "0EAF0845BC28CB9A543F7212FF4B307B844D837FE75EE7243AA3BECEF5E19854"
237+
},
238+
"LedgerEntryType": "DirectoryNode",
239+
"LedgerIndex": "CF348E552C8187424938D9363AF8425A479B8864D5C6F9FFEEF3437B2825382D",
240+
"PreviousTxnID": "82AA1201B93814818A14212F6F682FFCF2C4DFEAA1CC6FBDDAFB093E0D6D7C99",
241+
"PreviousTxnLgrSeq": 99770232
242+
}
243+
},
244+
{
245+
"ModifiedNode": {
246+
"FinalFields": {
247+
"Balance": {
248+
"currency": "584D454D45000000000000000000000000000000",
249+
"issuer": "rrrrrrrrrrrrrrrrrrrrBZbvji",
250+
"value": "46573659.76025771"
251+
},
252+
"Flags": 16842752,
253+
"HighLimit": {
254+
"currency": "584D454D45000000000000000000000000000000",
255+
"issuer": "r4UPddYeGeZgDhSGPkooURsQtmGda4oYQW",
256+
"value": "0"
257+
},
258+
"HighNode": "e0",
259+
"LowLimit": {
260+
"currency": "584D454D45000000000000000000000000000000",
261+
"issuer": "rnuESaWHkTUjU9hys6UP5MVsDjrmWRYVk5",
262+
"value": "0"
263+
},
264+
"LowNode": "0"
265+
},
266+
"LedgerEntryType": "RippleState",
267+
"LedgerIndex": "E1F5817ED607B44EC240F212919DB4C7266C61432B3A76671E94E014FD5B415C",
268+
"PreviousFields": {
269+
"Balance": {
270+
"currency": "584D454D45000000000000000000000000000000",
271+
"issuer": "rrrrrrrrrrrrrrrrrrrrBZbvji",
272+
"value": "46573659.76025772"
273+
}
274+
},
275+
"PreviousTxnID": "18324B40827755DCC9F72311642556840B40C42890AFE1E763C6585791F5C600",
276+
"PreviousTxnLgrSeq": 99779885
277+
}
278+
},
279+
{
280+
"ModifiedNode": {
281+
"FinalFields": {
282+
"Flags": 0,
283+
"IndexNext": "7",
284+
"IndexPrevious": "5",
285+
"Owner": "rnuESaWHkTUjU9hys6UP5MVsDjrmWRYVk5",
286+
"RootIndex": "09FCFBCFFF9D025FF62130A9928906852418FE619689DF3111AACA0B269BE93A"
287+
},
288+
"LedgerEntryType": "DirectoryNode",
289+
"LedgerIndex": "FCEEF171468C1D6390A48D4F48F6DF46DD8941B814685DBF96BE8FD707FD8001",
290+
"PreviousTxnID": "E9243147361B1E6085774D398269B511CAA4726E5C9BC2FE86286A5A27B2CE1D",
291+
"PreviousTxnLgrSeq": 98894081
292+
}
293+
}
294+
],
295+
"TransactionIndex": 41,
296+
"TransactionResult": "tesSUCCESS"
297+
},
298+
"status": "success",
299+
"validated": true
300+
}
301+
}

0 commit comments

Comments
 (0)