This repository has been archived by the owner on May 24, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 54
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #336 from elucidsoft/fix-liquidity-pool-operations…
…-responses Fix for AMM Protocol
- Loading branch information
Showing
13 changed files
with
412 additions
and
60 deletions.
There are no files selected for viewing
This file contains 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
55 changes: 55 additions & 0 deletions
55
stellar-dotnet-sdk-test/responses/operations/LiquidityPoolDepositOperationResponse/Data.json
This file contains 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,55 @@ | ||
{ | ||
"_links": { | ||
"self": { | ||
"href": "https://horizon-testnet.stellar.org/operations/1508315204960257" | ||
}, | ||
"transaction": { | ||
"href": "https://horizon-testnet.stellar.org/transactions/618930125efa20b6da220d8750c975580efeed18cf19a928500866fa78dd5d27" | ||
}, | ||
"effects": { | ||
"href": "https://horizon-testnet.stellar.org/operations/1508315204960257/effects" | ||
}, | ||
"succeeds": { | ||
"href": "https://horizon-testnet.stellar.org/effects?order=desc&cursor=1508315204960257" | ||
}, | ||
"precedes": { | ||
"href": "https://horizon-testnet.stellar.org/effects?order=asc&cursor=1508315204960257" | ||
} | ||
}, | ||
"id": "1508315204960257", | ||
"paging_token": "1508315204960257", | ||
"transaction_successful": false, | ||
"source_account": "GAIWHTRJ2ISBQRYSNRPAUMFXC66QIPS34R7YMTES7QYG6DYF25IRTSER", | ||
"type": "liquidity_pool_deposit", | ||
"type_i": 22, | ||
"created_at": "2021-10-06T18:04:24Z", | ||
"transaction_hash": "618930125efa20b6da220d8750c975580efeed18cf19a928500866fa78dd5d27", | ||
"liquidity_pool_id": "b26c0d6545349ad7f44ba758b7c705459537201583f2e524635be04aff84bc69", | ||
"reserves_max": [ | ||
{ | ||
"amount": "1000.0000000" | ||
}, | ||
{ | ||
"amount": "1.0000000" | ||
} | ||
], | ||
"min_price": "1.0000000", | ||
"min_price_r": { | ||
"n": 1, | ||
"d": 1 | ||
}, | ||
"max_price": "100000000.0000000", | ||
"max_price_r": { | ||
"n": 100000000, | ||
"d": 1 | ||
}, | ||
"reserves_deposited": [ | ||
{ | ||
"amount": "0.0000000" | ||
}, | ||
{ | ||
"amount": "0.0000000" | ||
} | ||
], | ||
"shares_received": "0.0000000" | ||
} |
75 changes: 75 additions & 0 deletions
75
...ations/LiquidityPoolDepositOperationResponse/LiquidityPoolDepositOperationResponseTest.cs
This file contains 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,75 @@ | ||
using Microsoft.VisualStudio.TestTools.UnitTesting; | ||
using Newtonsoft.Json; | ||
using stellar_dotnet_sdk; | ||
using stellar_dotnet_sdk.responses; | ||
using stellar_dotnet_sdk.responses.operations; | ||
using System; | ||
using System.Collections.Generic; | ||
using System.IO; | ||
using System.Text; | ||
|
||
namespace stellar_dotnet_sdk_test.responses.operations | ||
{ | ||
[TestClass] | ||
public class LiquidityPoolDepositOperationResponseTest | ||
{ | ||
[JsonProperty("liquidity_pool_id")] | ||
public LiquidityPoolID LiquidityPoolID { get; set; } | ||
|
||
[JsonProperty("reserves_max")] | ||
public List<Reserve> ReservesMax { get; set; } | ||
|
||
[JsonProperty("min_price")] | ||
public string MinPrice { get; set; } | ||
|
||
[JsonProperty("max_price")] | ||
public string MaxPrice { get; set; } | ||
|
||
[JsonProperty("reserves_deposited")] | ||
public List<Reserve> ReservesDeposited { get; set; } | ||
|
||
[JsonProperty("shares_received")] | ||
public string SharesReceived { get; set; } | ||
|
||
//Allow Trust | ||
[TestMethod] | ||
public void TestDeserialize() | ||
{ | ||
var json = File.ReadAllText(Path.Combine("responses/operations/LiquidityPoolDepositOperationResponse", "Data.json")); | ||
var instance = (LiquidityPoolDepositOperationResponse)JsonSingleton.GetInstance<OperationResponse>(json); | ||
|
||
AssertData(instance); | ||
} | ||
|
||
[TestMethod] | ||
public void TestSerializeDeserialize() | ||
{ | ||
var json = File.ReadAllText(Path.Combine("responses/operations/LiquidityPoolDepositOperationResponse", "Data.json")); | ||
var instance = JsonSingleton.GetInstance<OperationResponse>(json); | ||
var serialized = JsonConvert.SerializeObject(instance); | ||
var back = (LiquidityPoolDepositOperationResponse)JsonConvert.DeserializeObject<OperationResponse>(serialized); | ||
|
||
AssertData(back); | ||
} | ||
|
||
public void AssertData(LiquidityPoolDepositOperationResponse instance) | ||
{ | ||
Assert.AreEqual(new LiquidityPoolID("b26c0d6545349ad7f44ba758b7c705459537201583f2e524635be04aff84bc69"), instance.LiquidityPoolID); | ||
Assert.AreEqual("1508315204960257", instance.PagingToken); | ||
|
||
Assert.AreEqual("1.0000000", instance.MinPrice); | ||
Assert.AreEqual("100000000.0000000", instance.MaxPrice); | ||
|
||
Assert.AreEqual("1000.0000000", instance.ReservesMax[0].Amount); | ||
Assert.AreEqual(null, instance.ReservesMax[0].Asset); | ||
|
||
Assert.AreEqual("1.0000000", instance.ReservesMax[1].Amount); | ||
Assert.AreEqual(null, instance.ReservesMax[1].Asset); | ||
|
||
Assert.AreEqual("0.0000000", instance.ReservesDeposited[0].Amount); | ||
Assert.AreEqual("0.0000000", instance.ReservesDeposited[1].Amount); | ||
|
||
Assert.AreEqual("0.0000000", instance.SharesReceived); | ||
} | ||
} | ||
} |
49 changes: 49 additions & 0 deletions
49
...lar-dotnet-sdk-test/responses/operations/LiquidityPoolWithdrawOperationResponse/Data.json
This file contains 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,49 @@ | ||
{ | ||
"_links": { | ||
"self": { | ||
"href": "https://horizon-testnet.stellar.org/operations/1508641622462465" | ||
}, | ||
"transaction": { | ||
"href": "https://horizon-testnet.stellar.org/transactions/e8332b8dcada55e2801438c01d20f5abdeac60791260b24eb2f07be01cf57f2a" | ||
}, | ||
"effects": { | ||
"href": "https://horizon-testnet.stellar.org/operations/1508641622462465/effects" | ||
}, | ||
"succeeds": { | ||
"href": "https://horizon-testnet.stellar.org/effects?order=desc&cursor=1508641622462465" | ||
}, | ||
"precedes": { | ||
"href": "https://horizon-testnet.stellar.org/effects?order=asc&cursor=1508641622462465" | ||
} | ||
}, | ||
"id": "1508641622462465", | ||
"paging_token": "1508641622462465", | ||
"transaction_successful": true, | ||
"source_account": "GBCB56ASGYTRLYGIQPQMCR7HICUJYXXPTZAMD2CWG3UFB7JPD6YXC66Q", | ||
"type": "liquidity_pool_withdraw", | ||
"type_i": 23, | ||
"created_at": "2021-10-06T18:10:59Z", | ||
"transaction_hash": "e8332b8dcada55e2801438c01d20f5abdeac60791260b24eb2f07be01cf57f2a", | ||
"liquidity_pool_id": "b26c0d6545349ad7f44ba758b7c705459537201583f2e524635be04aff84bc69", | ||
"reserves_min": [ | ||
{ | ||
"asset": "native", | ||
"amount": "0.0000000" | ||
}, | ||
{ | ||
"asset": "USDC:GAKMOAANQHJKF5735OYVSQZL6KC3VMFL4LP4ZYY2LWK256TSUG45IEFB", | ||
"amount": "0.0000000" | ||
} | ||
], | ||
"shares": "1000.0000000", | ||
"reserves_received": [ | ||
{ | ||
"asset": "native", | ||
"amount": "1000.0000000" | ||
}, | ||
{ | ||
"asset": "USDC:GAKMOAANQHJKF5735OYVSQZL6KC3VMFL4LP4ZYY2LWK256TSUG45IEFB", | ||
"amount": "1000.0000000" | ||
} | ||
] | ||
} |
75 changes: 75 additions & 0 deletions
75
...ions/LiquidityPoolWithdrawOperationResponse/LiquidityPoolWithdrawOperationResponseTest.cs
This file contains 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,75 @@ | ||
using Microsoft.VisualStudio.TestTools.UnitTesting; | ||
using Newtonsoft.Json; | ||
using stellar_dotnet_sdk; | ||
using stellar_dotnet_sdk.responses; | ||
using stellar_dotnet_sdk.responses.operations; | ||
using System; | ||
using System.Collections.Generic; | ||
using System.IO; | ||
using System.Text; | ||
|
||
namespace stellar_dotnet_sdk_test.responses.operations | ||
{ | ||
[TestClass] | ||
public class LiquidityPoolWithdrawOperationResponseTest | ||
{ | ||
[JsonProperty("liquidity_pool_id")] | ||
public LiquidityPoolID LiquidityPoolID { get; set; } | ||
|
||
[JsonProperty("reserves_max")] | ||
public List<Reserve> ReservesMax { get; set; } | ||
|
||
[JsonProperty("min_price")] | ||
public string MinPrice { get; set; } | ||
|
||
[JsonProperty("max_price")] | ||
public string MaxPrice { get; set; } | ||
|
||
[JsonProperty("reserves_deposited")] | ||
public List<Reserve> ReservesDeposited { get; set; } | ||
|
||
[JsonProperty("shares_received")] | ||
public string SharesReceived { get; set; } | ||
|
||
//Allow Trust | ||
[TestMethod] | ||
public void TestDeserialize() | ||
{ | ||
var json = File.ReadAllText(Path.Combine("responses/operations/LiquidityPoolWithdrawOperationResponse", "Data.json")); | ||
var instance = (LiquidityPoolWithdrawOperationResponse)JsonSingleton.GetInstance<OperationResponse>(json); | ||
|
||
AssertData(instance); | ||
} | ||
|
||
[TestMethod] | ||
public void TestSerializeDeserialize() | ||
{ | ||
var json = File.ReadAllText(Path.Combine("responses/operations/LiquidityPoolWithdrawOperationResponse", "Data.json")); | ||
var instance = JsonSingleton.GetInstance<OperationResponse>(json); | ||
var serialized = JsonConvert.SerializeObject(instance); | ||
var back = (LiquidityPoolWithdrawOperationResponse)JsonConvert.DeserializeObject<OperationResponse>(serialized); | ||
|
||
AssertData(back); | ||
} | ||
|
||
public void AssertData(LiquidityPoolWithdrawOperationResponse instance) | ||
{ | ||
Assert.AreEqual(new LiquidityPoolID("b26c0d6545349ad7f44ba758b7c705459537201583f2e524635be04aff84bc69"), instance.LiquidityPoolID); | ||
Assert.AreEqual("1508641622462465", instance.PagingToken); | ||
|
||
Assert.AreEqual("0.0000000", instance.ReservesMin[0].Amount); | ||
Assert.AreEqual("native", instance.ReservesMin[0].Asset.CanonicalName()); | ||
|
||
Assert.AreEqual("0.0000000", instance.ReservesMin[1].Amount); | ||
Assert.AreEqual("USDC:GAKMOAANQHJKF5735OYVSQZL6KC3VMFL4LP4ZYY2LWK256TSUG45IEFB", instance.ReservesMin[1].Asset.CanonicalName()); | ||
|
||
Assert.AreEqual("1000.0000000", instance.Shares); | ||
|
||
Assert.AreEqual("1000.0000000", instance.ReservesReceived[0].Amount); | ||
Assert.AreEqual("native", instance.ReservesReceived[0].Asset.CanonicalName()); | ||
|
||
Assert.AreEqual("1000.0000000", instance.ReservesReceived[1].Amount); | ||
Assert.AreEqual("USDC:GAKMOAANQHJKF5735OYVSQZL6KC3VMFL4LP4ZYY2LWK256TSUG45IEFB", instance.ReservesReceived[1].Asset.CanonicalName()); | ||
} | ||
} | ||
} |
This file contains 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 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,45 @@ | ||
using Newtonsoft.Json; | ||
using stellar_dotnet_sdk.converters; | ||
using System; | ||
using System.Collections.Generic; | ||
using System.Text; | ||
|
||
namespace stellar_dotnet_sdk | ||
{ | ||
[JsonConverter(typeof(ReserveJsonConverter))] | ||
public class Reserve | ||
{ | ||
[JsonProperty(PropertyName = "amount")] | ||
public string Amount { get; set; } | ||
|
||
[JsonProperty(PropertyName = "asset")] | ||
public Asset Asset { get; set; } | ||
|
||
public Reserve() { } | ||
|
||
public Reserve(string amount, Asset asset) | ||
{ | ||
Amount = amount ?? throw new ArgumentNullException(nameof(amount), "amount cannot be null"); | ||
Asset = asset ?? throw new ArgumentNullException(nameof(amount), "asset cannot be null"); | ||
} | ||
|
||
public override bool Equals(object obj) | ||
{ | ||
if (!(obj is Reserve)) | ||
{ | ||
return false; | ||
} | ||
|
||
Reserve other = (Reserve)obj; | ||
return Equals(Asset, other.Asset) && Equals(Amount, other.Amount); | ||
} | ||
|
||
public override int GetHashCode() | ||
{ | ||
int hashCode = 1588693772; | ||
hashCode = (hashCode * -1521134295) + EqualityComparer<string>.Default.GetHashCode(Amount); | ||
hashCode = (hashCode * -1521134295) + EqualityComparer<Asset>.Default.GetHashCode(Asset); | ||
return hashCode; | ||
} | ||
} | ||
} |
29 changes: 0 additions & 29 deletions
29
stellar-dotnet-sdk/converters/LiquidityPoolResponseReserveJsonConverter.cs
This file was deleted.
Oops, something went wrong.
Oops, something went wrong.