-
Notifications
You must be signed in to change notification settings - Fork 159
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
AMM SDK Updates #359
Merged
Merged
AMM SDK Updates #359
Changes from 19 commits
Commits
Show all changes
21 commits
Select commit
Hold shift + click to select a range
047e8c7
Update xdr and run xdrgen
193d410
AssetAlphaNum -> AlphaNum
4ba6877
WIP amm stuff
7a963d7
Fixing up tests and equality
12695c3
First (janky) pass at deposit/withdraw operations
040d47b
Adding fields to AssetResponse
fa8c7bc
WIP trades and accounts request updates
66c1be8
Adding liquidity pools requests and responses
00c3bd8
Implement asset sorting
c4b7f0f
Fixing some compile errors
e9cbd9f
Fixing up deposit builder
ea0ffca
enforce asset ordering
a66c174
Fixing up build and tests
e4abedc
WIP
94cc7bd
Add effects
4be5e62
comment
2c48284
Fix type and add effect deserializers
25b3f00
review feedback
a16488a
Review feedback - remove builders
41a416e
use Longs for some stuff
38e2d63
Use longs for TradePrice
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 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,37 @@ | ||
package org.stellar.sdk; | ||
|
||
import com.google.common.base.Objects; | ||
|
||
public final class AssetAmount { | ||
private final Asset asset; | ||
private final String amount; | ||
|
||
AssetAmount(Asset asset, String amount) { | ||
this.asset = asset; | ||
this.amount = amount; | ||
} | ||
|
||
public Asset getAsset() { | ||
return this.asset; | ||
} | ||
|
||
public String getAmount() { | ||
return this.amount; | ||
} | ||
|
||
|
||
public int hashCode() { | ||
return Objects.hashCode(asset, amount); | ||
} | ||
|
||
@Override | ||
public boolean equals(Object object) { | ||
if (!(object instanceof AssetAmount)) { | ||
return false; | ||
} | ||
|
||
AssetAmount o = (AssetAmount) object; | ||
return Objects.equal(this.getAsset(), o.getAsset()) && | ||
Objects.equal(this.getAmount(), o.getAmount()); | ||
} | ||
} |
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
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,132 @@ | ||
package org.stellar.sdk; | ||
|
||
import static com.google.common.base.Preconditions.checkNotNull; | ||
|
||
/** | ||
* ChangeTrustAsset class. | ||
* @see <a href="https://www.stellar.org/developers/learn/concepts/assets.html" target="_blank">Assets</a> | ||
*/ | ||
public abstract class ChangeTrustAsset implements Comparable<ChangeTrustAsset> { | ||
ChangeTrustAsset() {} | ||
|
||
/** | ||
* Parses an asset string and returns the equivalent ChangeTrustAsset instance. | ||
* The asset string is expected to either be "native" or a string of the form "CODE:ISSUER" | ||
* | ||
* @param canonicalForm Canonical string representation of an asset | ||
*/ | ||
public static ChangeTrustAsset create(String canonicalForm) { | ||
return new Wrapper(Asset.create(canonicalForm)); | ||
} | ||
|
||
public static ChangeTrustAsset create(String type, String code, String issuer) { | ||
return new Wrapper(Asset.create(type, code, issuer)); | ||
} | ||
public static ChangeTrustAsset create(Asset asset) { | ||
return new Wrapper(asset); | ||
} | ||
public static ChangeTrustAsset create(LiquidityPoolParameters params) { | ||
return new LiquidityPoolShareChangeTrustAsset(params); | ||
} | ||
public static ChangeTrustAsset create(TrustLineAsset.Wrapper wrapper) { | ||
return new Wrapper(wrapper.getAsset()); | ||
} | ||
// Cannot convert from LiquidityPoolShareTrustLineAsset, as that only has a | ||
// liquidity pool id, not parameters. | ||
|
||
/** | ||
* Creates one of AssetTypeCreditAlphaNum4 or AssetTypeCreditAlphaNum12 object based on a <code>code</code> length | ||
* @param code ChangeTrustAsset code | ||
* @param issuer ChangeTrustAsset issuer | ||
*/ | ||
public static ChangeTrustAsset createNonNativeAsset(String code, String issuer) { | ||
return ChangeTrustAsset.create(Asset.createNonNativeAsset(code, issuer)); | ||
} | ||
|
||
/** | ||
* Generates ChangeTrustAsset object from a given XDR object | ||
* @param xdr XDR object | ||
*/ | ||
public static ChangeTrustAsset fromXdr(org.stellar.sdk.xdr.ChangeTrustAsset xdr) { | ||
// TODO: Figure out how we can re-use Asset.fromXdr here | ||
String accountId; | ||
switch (xdr.getDiscriminant()) { | ||
case ASSET_TYPE_NATIVE: | ||
return ChangeTrustAsset.create(new AssetTypeNative()); | ||
case ASSET_TYPE_CREDIT_ALPHANUM4: | ||
String assetCode4 = Util.paddedByteArrayToString(xdr.getAlphaNum4().getAssetCode().getAssetCode4()); | ||
accountId = StrKey.encodeStellarAccountId(xdr.getAlphaNum4().getIssuer()); | ||
return ChangeTrustAsset.create(new AssetTypeCreditAlphaNum4(assetCode4, accountId)); | ||
case ASSET_TYPE_CREDIT_ALPHANUM12: | ||
String assetCode12 = Util.paddedByteArrayToString(xdr.getAlphaNum12().getAssetCode().getAssetCode12()); | ||
accountId = StrKey.encodeStellarAccountId(xdr.getAlphaNum12().getIssuer()); | ||
return ChangeTrustAsset.create(new AssetTypeCreditAlphaNum12(assetCode12, accountId)); | ||
case ASSET_TYPE_POOL_SHARE: | ||
return new LiquidityPoolShareChangeTrustAsset(LiquidityPoolParameters.fromXdr(xdr.getLiquidityPool())); | ||
default: | ||
throw new IllegalArgumentException("Unknown asset type " + xdr.getDiscriminant()); | ||
} | ||
} | ||
|
||
public abstract String getType(); | ||
|
||
@Override | ||
public abstract boolean equals(Object object); | ||
|
||
@Override | ||
public abstract int compareTo(ChangeTrustAsset other); | ||
|
||
/** | ||
* Generates XDR object from a given ChangeTrustAsset object | ||
*/ | ||
public abstract org.stellar.sdk.xdr.ChangeTrustAsset toXdr(); | ||
|
||
public static final class Wrapper extends ChangeTrustAsset { | ||
private Asset asset; | ||
|
||
public Wrapper(Asset baseAsset) { | ||
super(); | ||
checkNotNull(baseAsset, "asset cannot be null"); | ||
asset = baseAsset; | ||
} | ||
|
||
public Asset getAsset() { | ||
return asset; | ||
} | ||
|
||
@Override | ||
public String getType() { | ||
return asset.getType(); | ||
} | ||
|
||
@Override | ||
public final boolean equals(Object object) { | ||
if (object == null || !this.getClass().equals(object.getClass())) { | ||
return false; | ||
} | ||
|
||
ChangeTrustAsset.Wrapper o = (ChangeTrustAsset.Wrapper) object; | ||
return this.getAsset().equals(o.getAsset()); | ||
} | ||
|
||
@Override | ||
public int compareTo(ChangeTrustAsset other) { | ||
if (other.getType() == "pool_share") { | ||
return -1; | ||
} | ||
return this.getAsset().compareTo(((ChangeTrustAsset.Wrapper) other).getAsset()); | ||
} | ||
|
||
@Override | ||
public org.stellar.sdk.xdr.ChangeTrustAsset toXdr() { | ||
org.stellar.sdk.xdr.ChangeTrustAsset xdr = new org.stellar.sdk.xdr.ChangeTrustAsset(); | ||
|
||
org.stellar.sdk.xdr.Asset assetXdr = asset.toXdr(); | ||
xdr.setDiscriminant(assetXdr.getDiscriminant()); | ||
xdr.setAlphaNum4(assetXdr.getAlphaNum4()); | ||
xdr.setAlphaNum12(assetXdr.getAlphaNum12()); | ||
|
||
return xdr; | ||
} | ||
} | ||
} |
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.
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm not sure if these methods are useful because calling
wrapped.getAsset()
is just as easy as callingAsset.create(wrapped)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yeah, my thinking was that the conversions would be more symmetric this way. e.g.
ChangeTrustAsset.create(native)
, orAsset.create(changeTrustAsset)