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 55
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 #332 from elucidsoft/amm
AMM Protocol 18
- Loading branch information
Showing
170 changed files
with
5,305 additions
and
299 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
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 @@ | ||
using Microsoft.VisualStudio.TestTools.UnitTesting; | ||
using stellar_dotnet_sdk; | ||
using System; | ||
using System.Collections.Generic; | ||
using System.Text; | ||
|
||
namespace stellar_dotnet_sdk_test | ||
{ | ||
[TestClass] | ||
public class AssetAmountTest | ||
{ | ||
[TestMethod] | ||
public void TestDefaultConstructor() | ||
{ | ||
try | ||
{ | ||
new AssetAmount(); | ||
} | ||
catch (Exception e) | ||
{ | ||
Assert.Fail(); | ||
} | ||
} | ||
|
||
[TestMethod] | ||
public void TestCreation() | ||
{ | ||
var issuer = KeyPair.Random(); | ||
|
||
var assetAmount = new AssetAmount(Asset.CreateNonNativeAsset("TEST", issuer.AccountId), "100"); | ||
|
||
Assert.AreEqual(assetAmount.Asset.CanonicalName(), $"TEST:{issuer.AccountId}"); | ||
Assert.AreEqual(assetAmount.Amount, "100"); | ||
} | ||
|
||
[TestMethod] | ||
public void TestEquality() | ||
{ | ||
var issuer = KeyPair.Random(); | ||
|
||
var assetAmount = new AssetAmount(Asset.CreateNonNativeAsset("TEST", issuer.AccountId), "100"); | ||
var assetAmount2 = new AssetAmount(Asset.CreateNonNativeAsset("TEST", issuer.AccountId), "100"); | ||
|
||
Assert.AreEqual(assetAmount, assetAmount2); | ||
Assert.AreEqual(assetAmount.GetHashCode(), assetAmount2.GetHashCode()); | ||
Assert.IsFalse(assetAmount.Equals(issuer)); | ||
} | ||
} | ||
} |
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,92 @@ | ||
using Microsoft.VisualStudio.TestTools.UnitTesting; | ||
using stellar_dotnet_sdk; | ||
using XDR = stellar_dotnet_sdk.xdr; | ||
using System; | ||
using System.Collections.Generic; | ||
using System.Text; | ||
|
||
namespace stellar_dotnet_sdk_test | ||
{ | ||
[TestClass] | ||
public class ChangeTrustAssetTest | ||
{ | ||
[TestMethod] | ||
public void TestCreateCanonical() | ||
{ | ||
var keypair = KeyPair.Random(); | ||
var changeTrustAsset = (ChangeTrustAsset.Wrapper)ChangeTrustAsset.Create($"USD:{keypair.AccountId}"); | ||
Assert.AreEqual(changeTrustAsset.Asset.CanonicalName(), $"USD:{keypair.AccountId}"); | ||
} | ||
|
||
[TestMethod] | ||
public void TestCreateLiquidityPoolParameters() | ||
{ | ||
var keypair = KeyPair.Random(); | ||
var keypair2 = KeyPair.Random(); | ||
|
||
var assetA = Asset.Create($"EUR:{keypair.AccountId}"); | ||
var assetB = Asset.Create($"USD:{keypair2.AccountId}"); | ||
|
||
var parameters = LiquidityPoolParameters.Create(XDR.LiquidityPoolType.LiquidityPoolTypeEnum.LIQUIDITY_POOL_CONSTANT_PRODUCT, assetA, assetB, 30); | ||
|
||
var liquidityPoolShareChangeTrustAsset = (LiquidityPoolShareChangeTrustAsset)ChangeTrustAsset.Create(parameters); | ||
var liquidityPoolShareChangeTrustAsset2 = (LiquidityPoolShareChangeTrustAsset)LiquidityPoolShareChangeTrustAsset.FromXdr(liquidityPoolShareChangeTrustAsset.ToXdr()); | ||
|
||
Assert.AreEqual(liquidityPoolShareChangeTrustAsset.Parameters.GetID(), liquidityPoolShareChangeTrustAsset2.Parameters.GetID()); | ||
} | ||
|
||
[TestMethod] | ||
public void TestCreateTrustlineWrapper() | ||
{ | ||
var keypair = KeyPair.Random(); | ||
var trustlineAsset = (TrustlineAsset.Wrapper)TrustlineAsset.Create("non-native", "USD", keypair.AccountId); | ||
var changeTrustAsset = (ChangeTrustAsset.Wrapper)ChangeTrustAsset.Create(trustlineAsset); | ||
|
||
Assert.AreEqual(trustlineAsset.Asset, changeTrustAsset.Asset); | ||
} | ||
|
||
[TestMethod] | ||
public void TestCreateNonNative() | ||
{ | ||
var keypair = KeyPair.Random(); | ||
var changeTrustAsset = (ChangeTrustAsset.Wrapper)ChangeTrustAsset.CreateNonNativeAsset("USD", keypair.AccountId); | ||
Assert.AreEqual(changeTrustAsset.Asset.CanonicalName(), $"USD:{keypair.AccountId}"); | ||
} | ||
|
||
[TestMethod] | ||
public void TestFromXDRAlphaNum4() | ||
{ | ||
var keypair = KeyPair.Random(); | ||
|
||
var changeTrustAssetXdr = new XDR.ChangeTrustAsset(); | ||
changeTrustAssetXdr.Discriminant = new XDR.AssetType() { InnerValue = XDR.AssetType.AssetTypeEnum.ASSET_TYPE_CREDIT_ALPHANUM4 }; | ||
changeTrustAssetXdr.AlphaNum4 = Asset.Create($"USD:{keypair.AccountId}").ToXdr().AlphaNum4; | ||
|
||
var changeTrustAsset = (ChangeTrustAsset.Wrapper)ChangeTrustAsset.FromXdr(changeTrustAssetXdr); | ||
Assert.AreEqual(changeTrustAsset.Asset.CanonicalName(), $"USD:{keypair.AccountId}"); | ||
} | ||
|
||
[TestMethod] | ||
public void TestFromXDRAlphaNum12() | ||
{ | ||
var keypair = KeyPair.Random(); | ||
|
||
var changeTrustAssetXdr = new XDR.ChangeTrustAsset(); | ||
changeTrustAssetXdr.Discriminant = new XDR.AssetType() { InnerValue = XDR.AssetType.AssetTypeEnum.ASSET_TYPE_CREDIT_ALPHANUM12 }; | ||
changeTrustAssetXdr.AlphaNum12 = Asset.Create($"USDUSD:{keypair.AccountId}").ToXdr().AlphaNum12; | ||
|
||
var changeTrustAsset = (ChangeTrustAsset.Wrapper)ChangeTrustAsset.FromXdr(changeTrustAssetXdr); | ||
Assert.AreEqual(changeTrustAsset.Asset.CanonicalName(), $"USDUSD:{keypair.AccountId}"); | ||
} | ||
|
||
[TestMethod] | ||
public void TestFromXDRNative() | ||
{ | ||
var changeTrustAssetXdr = new XDR.ChangeTrustAsset(); | ||
changeTrustAssetXdr.Discriminant = new XDR.AssetType() { InnerValue = XDR.AssetType.AssetTypeEnum.ASSET_TYPE_NATIVE }; | ||
|
||
var trustlineAsset = (ChangeTrustAsset.Wrapper)ChangeTrustAsset.FromXdr(changeTrustAssetXdr); | ||
Assert.AreEqual(trustlineAsset.Asset.CanonicalName(), "native"); | ||
} | ||
} | ||
} |
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,39 @@ | ||
using Microsoft.VisualStudio.TestTools.UnitTesting; | ||
using stellar_dotnet_sdk; | ||
using stellar_dotnet_sdk.responses.results; | ||
using System; | ||
using System.Collections.Generic; | ||
using System.Text; | ||
using xdr = stellar_dotnet_sdk.xdr; | ||
|
||
namespace stellar_dotnet_sdk_test | ||
{ | ||
[TestClass] | ||
public class ClaimLiquidityAtomTest | ||
{ | ||
[TestMethod] | ||
public void TestFromXdr() | ||
{ | ||
var claimLiquidityAtomXdr = new stellar_dotnet_sdk.xdr.ClaimLiquidityAtom(); | ||
|
||
var asset1 = Asset.CreateNonNativeAsset("TEST0", KeyPair.Random().AccountId); | ||
var asset2 = Asset.CreateNonNativeAsset("TEST1", KeyPair.Random().AccountId); | ||
|
||
claimLiquidityAtomXdr.AmountBought = new stellar_dotnet_sdk.xdr.Int64(100L); | ||
claimLiquidityAtomXdr.AmountSold = new stellar_dotnet_sdk.xdr.Int64(100L); | ||
claimLiquidityAtomXdr.AssetBought = asset1.ToXdr(); | ||
claimLiquidityAtomXdr.AssetSold = asset2.ToXdr(); | ||
|
||
var liquidityPool = new LiquidityPoolID(stellar_dotnet_sdk.xdr.LiquidityPoolType.LiquidityPoolTypeEnum.LIQUIDITY_POOL_CONSTANT_PRODUCT, asset1, asset2, 100); | ||
claimLiquidityAtomXdr.LiquidityPoolID = liquidityPool.ToXdr(); | ||
|
||
var claimLiquidityAtom = ClaimLiquidityAtom.FromXdr(claimLiquidityAtomXdr); | ||
|
||
Assert.AreEqual(claimLiquidityAtom.AmountBought, "0.00001"); | ||
Assert.AreEqual(claimLiquidityAtom.AmountSold, "0.00001"); | ||
Assert.AreEqual(claimLiquidityAtom.AssetBought, asset1); | ||
Assert.AreEqual(claimLiquidityAtom.AssetSold, asset2); | ||
Assert.AreEqual(claimLiquidityAtom.LiquidityPoolID.Hash, liquidityPool.Hash); | ||
} | ||
} | ||
} |
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,57 @@ | ||
using Microsoft.VisualStudio.TestTools.UnitTesting; | ||
using stellar_dotnet_sdk; | ||
using System; | ||
using System.Collections.Generic; | ||
using System.Text; | ||
using XDR = stellar_dotnet_sdk.xdr; | ||
|
||
namespace stellar_dotnet_sdk_test | ||
{ | ||
[TestClass] | ||
public class LiquidityPoolIDTest | ||
{ | ||
[TestMethod] | ||
public void TestCreate() | ||
{ | ||
var a = Asset.Create("native"); | ||
var b = Asset.CreateNonNativeAsset("ABC", "GDQNY3PBOJOKYZSRMK2S7LHHGWZIUISD4QORETLMXEWXBI7KFZZMKTL3"); | ||
var c = Asset.CreateNonNativeAsset("ABCD", "GDQNY3PBOJOKYZSRMK2S7LHHGWZIUISD4QORETLMXEWXBI7KFZZMKTL3"); | ||
|
||
LiquidityPoolID id = new LiquidityPoolID(XDR.LiquidityPoolType.LiquidityPoolTypeEnum.LIQUIDITY_POOL_CONSTANT_PRODUCT, a, b, LiquidityPoolParameters.Fee); | ||
Assert.AreEqual("cc22414997d7e3d9a9ac3b1d65ca9cc3e5f35ce33e0bd6a885648b11aaa3b72d", id.ToString()); | ||
} | ||
|
||
[TestMethod] | ||
public void TestNotLexicographicOrder() | ||
{ | ||
var a = Asset.Create("native"); | ||
var b = Asset.CreateNonNativeAsset("ABC", "GDQNY3PBOJOKYZSRMK2S7LHHGWZIUISD4QORETLMXEWXBI7KFZZMKTL3"); | ||
var c = Asset.CreateNonNativeAsset("ABCD", "GDQNY3PBOJOKYZSRMK2S7LHHGWZIUISD4QORETLMXEWXBI7KFZZMKTL3"); | ||
|
||
Assert.ThrowsException<ArgumentException>(() => new LiquidityPoolID(XDR.LiquidityPoolType.LiquidityPoolTypeEnum.LIQUIDITY_POOL_CONSTANT_PRODUCT, b, a, LiquidityPoolParameters.Fee), "Asset A must be < Asset B (Lexicographic Order)"); | ||
} | ||
|
||
[TestMethod] | ||
public void TestEquality() | ||
{ | ||
var a = Asset.Create("native"); | ||
var b = Asset.CreateNonNativeAsset("ABC", "GDQNY3PBOJOKYZSRMK2S7LHHGWZIUISD4QORETLMXEWXBI7KFZZMKTL3"); | ||
var c = Asset.CreateNonNativeAsset("ABCD", "GDQNY3PBOJOKYZSRMK2S7LHHGWZIUISD4QORETLMXEWXBI7KFZZMKTL3"); | ||
|
||
LiquidityPoolID pool1 = new LiquidityPoolID(XDR.LiquidityPoolType.LiquidityPoolTypeEnum.LIQUIDITY_POOL_CONSTANT_PRODUCT, a, b, LiquidityPoolParameters.Fee); | ||
Assert.AreEqual(pool1, pool1); | ||
} | ||
|
||
[TestMethod] | ||
public void TestInequality() | ||
{ | ||
var a = Asset.Create("native"); | ||
var b = Asset.CreateNonNativeAsset("ABC", "GDQNY3PBOJOKYZSRMK2S7LHHGWZIUISD4QORETLMXEWXBI7KFZZMKTL3"); | ||
var c = Asset.CreateNonNativeAsset("ABCD", "GDQNY3PBOJOKYZSRMK2S7LHHGWZIUISD4QORETLMXEWXBI7KFZZMKTL3"); | ||
|
||
LiquidityPoolID pool1 = new LiquidityPoolID(XDR.LiquidityPoolType.LiquidityPoolTypeEnum.LIQUIDITY_POOL_CONSTANT_PRODUCT, a, b, LiquidityPoolParameters.Fee); | ||
LiquidityPoolID pool2 = new LiquidityPoolID(XDR.LiquidityPoolType.LiquidityPoolTypeEnum.LIQUIDITY_POOL_CONSTANT_PRODUCT, b, c, LiquidityPoolParameters.Fee); | ||
Assert.AreNotEqual(pool1, pool2); | ||
} | ||
} | ||
} |
40 changes: 40 additions & 0 deletions
40
stellar-dotnet-sdk-test/LiquidityPoolShareTrustlineAssetTest.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,40 @@ | ||
using Microsoft.VisualStudio.TestTools.UnitTesting; | ||
using stellar_dotnet_sdk; | ||
using System; | ||
using System.Collections.Generic; | ||
using System.Text; | ||
|
||
namespace stellar_dotnet_sdk_test | ||
{ | ||
[TestClass] | ||
public class LiquidityPoolShareTrustlineAssetTest | ||
{ | ||
[TestMethod] | ||
public void TestEquality() | ||
{ | ||
var keypair = KeyPair.Random(); | ||
var keypair2 = KeyPair.Random(); | ||
|
||
var assetA = Asset.Create($"EUR:{keypair.AccountId}"); | ||
var assetB = Asset.Create($"USD:{keypair2.AccountId}"); | ||
|
||
var trustlineAsset = (LiquidityPoolShareTrustlineAsset)TrustlineAsset.Create(LiquidityPoolParameters.Create(stellar_dotnet_sdk.xdr.LiquidityPoolType.LiquidityPoolTypeEnum.LIQUIDITY_POOL_CONSTANT_PRODUCT, assetA, assetB, 30)); | ||
var trustlineAsset2 = new LiquidityPoolShareTrustlineAsset(trustlineAsset.ID); | ||
Assert.IsTrue(trustlineAsset.Equals(trustlineAsset2)); | ||
} | ||
|
||
[TestMethod] | ||
public void TestGetType() | ||
{ | ||
var keypair = KeyPair.Random(); | ||
var keypair2 = KeyPair.Random(); | ||
|
||
var assetA = Asset.Create($"EUR:{keypair.AccountId}"); | ||
var assetB = Asset.Create($"USD:{keypair2.AccountId}"); | ||
|
||
var trustlineAsset = (LiquidityPoolShareTrustlineAsset)TrustlineAsset.Create(LiquidityPoolParameters.Create(stellar_dotnet_sdk.xdr.LiquidityPoolType.LiquidityPoolTypeEnum.LIQUIDITY_POOL_CONSTANT_PRODUCT, assetA, assetB, 30)); | ||
var trustlineAsset2 = new LiquidityPoolShareTrustlineAsset(trustlineAsset.ID); | ||
Assert.AreEqual(trustlineAsset.GetType(), "pool_share"); | ||
} | ||
} | ||
} |
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
Oops, something went wrong.