Skip to content

Commit

Permalink
💱 DEX code examples setup
Browse files Browse the repository at this point in the history
No known existing community opinions or best practices on the java syntax per https://discord.com/channels/897514728459468821/966788672164855829/1314630372042084534 in re stellar#1044.
I know some of the existing pages have been loosely casted, but there seem to be a lot of new users complaining about Docs examples not compiling or running locally given test data.
  • Loading branch information
JFWooten4 committed Dec 8, 2024
1 parent ddd80c6 commit 81efcf5
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 22 deletions.
6 changes: 2 additions & 4 deletions docs/learn/encyclopedia/sdex/README.mdx
Original file line number Diff line number Diff line change
@@ -1,12 +1,10 @@
---
title: Payment Liquidity
title: Conversion Liquidity
sidebar_position: 90
---

import DocCardList from "@theme/DocCardList";

{_/ Opt. do as "Conversion" liquidirty _/}

Native network markets, liquidity, and conversions for all assets.
Native network markets, liquidity, and exchange for all assets.

<DocCardList />
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ server = Server("https://horizon-testnet.stellar.org")
privateKey = "SAXBT6KO6NJ6SJXHBO6EBC7I5ZB7DZFYNPQOLXZJOKQ2LSGY5FU7ZJZB"
publicKey = "GBRPYHIL2CI3R5N4A7WMBETDZQ24DXFQGNCJWHXPFRGFWZHJZZBDTWR2"

# Asset config
# Asset setup
astroDollar = Asset("AstroDollar", "GDRM3MK6KMHSYIT4E2AG2S2LWTDBJNYXE4H72C7YTTRWOWX5ZBECFWO7")
astroPeso = Asset("AstroPeso", "GBHNGLLIE3KWGKCHIKMHJ5HVZHYIK7WTBE4QF5PLAKL4CJGSEU7HZIW5")

Expand Down Expand Up @@ -72,7 +72,7 @@ const server = new Server("https://horizon-testnet.stellar.org");
const privateKey = "SAXBT6KO6NJ6SJXHBO6EBC7I5ZB7DZFYNPQOLXZJOKQ2LSGY5FU7ZJZB";
const publicKey = "GBRPYHIL2CI3R5N4A7WMBETDZQ24DXFQGNCJWHXPFRGFWZHJZZBDTWR2";

// Asset config
// Asset setup
const astroDollar = new Asset(
"AstroDollar",
"GDRM3MK6KMHSYIT4E2AG2S2LWTDBJNYXE4H72C7YTTRWOWX5ZBECFWO7",
Expand All @@ -82,25 +82,39 @@ const astroPeso = new Asset(
"GBHNGLLIE3KWGKCHIKMHJ5HVZHYIK7WTBE4QF5PLAKL4CJGSEU7HZIW5",
);

// pending newTxEnvelope(..)
function newTxBuilder(source, signer, ...ops) {
let tx = new sdk.TransactionBuilder(source, {
fee: sdk.BASE_FEE,
networkPassphrase: sdk.Networks.TESTNET,
});
ops.forEach((op) => tx.addOperation(op));
tx = tx.setTimeout(360).build();
tx.sign(signer);
return tx;
}
```

```java
import org.stellar.sdk.*;
import org.stellar.sdk.responses.AccountResponse;
import org.stellar.sdk.responses.SubmitTransactionResponse;


public class Liquidity {
static final Server server = new Server("https://horizon-testnet.stellar.org");

// Account setup
static String privateKey = "SAXBT6KO6NJ6SJXHBO6EBC7I5ZB7DZFYNPQOLXZJOKQ2LSGY5FU7ZJZB";
static String publicKey = "GBRPYHIL2CI3R5N4A7WMBETDZQ24DXFQGNCJWHXPFRGFWZHJZZBDTWR2";

// Asset config
Asset astroDollar = new AssetTypeCreditAlphaNum4("AstroDollar", "GDRM3MK6KMHSYIT4E2AG2S2LWTDBJNYXE4H72C7YTTRWOWX5ZBECFWO7");
Asset astroPeso = new AssetTypeCreditAlphaNum4("AstroPeso", "GBHNGLLIE3KWGKCHIKMHJ5HVZHYIK7WTBE4QF5PLAKL4CJGSEU7HZIW5");
// Asset setup
Asset astroDollar = new AssetTypeCreditAlphaNum4(
"AstroDollar",
"GDRM3MK6KMHSYIT4E2AG2S2LWTDBJNYXE4H72C7YTTRWOWX5ZBECFWO7"
);
Asset astroPeso = new AssetTypeCreditAlphaNum4(
"AstroPeso",
"GBHNGLLIE3KWGKCHIKMHJ5HVZHYIK7WTBE4QF5PLAKL4CJGSEU7HZIW5"
);

public static Transaction.Builder newTxBuilder(KeyPair source) {
AccountResponse sourceAccount = server.accounts().account(source.getAccountId());
Expand All @@ -112,6 +126,15 @@ public class Liquidity {
```

```go
import (
"fmt"
"strconv"
"github.com/stellar/go/keypair"
"github.com/stellar/go/txnbuild"
"github.com/stellar/go/clients/horizonclient"
"github.com/stellar/go/network"
)

func main() {
// Account setup
privateKey := "SAXBT6KO6NJ6SJXHBO6EBC7I5ZB7DZFYNPQOLXZJOKQ2LSGY5FU7ZJZB"
Expand Down Expand Up @@ -819,17 +842,6 @@ const [A, B] = orderAssets(
new sdk.Asset("B", kp0.publicKey()),
);

function newTxBuilder(source, signer, ...ops) {
let tx = new sdk.TransactionBuilder(source, {
fee: sdk.BASE_FEE,
networkPassphrase: sdk.Networks.TESTNET,
});
ops.forEach((op) => tx.addOperation(op));
tx = tx.setTimeout(360).build();
tx.sign(signer);
return tx;
}

// Establishes trustlines and funds `recipientKps` for all `assets`
function distributeAssets(issuerKp, recipientKps, ...assets) {
return server.loadAccount(issuerKp.publicKey()).then((issuer) => {
Expand Down

0 comments on commit 81efcf5

Please sign in to comment.