Skip to content

Commit

Permalink
🖌️ Update prettier config note
Browse files Browse the repository at this point in the history
I was messing around with `prettier-plugin-sh` and figured the note could be more localized in case we add tabWidths or such later on here (albeit you can locally inspect the upstream import for equivalent affect)
  • Loading branch information
JFWooten4 committed Nov 26, 2024
1 parent 80784d8 commit f1a50e2
Show file tree
Hide file tree
Showing 2 changed files with 121 additions and 123 deletions.
4 changes: 1 addition & 3 deletions .prettierrc.js
Original file line number Diff line number Diff line change
@@ -1,12 +1,10 @@
module.exports = {
...require("@stellar/prettier-config"),
// This is mostly content, and prose wrap has a way of exploding markdown
// diffs. Override the default for a better experience.
overrides: [
{
files: "*.mdx",
options: {
proseWrap: "never",
proseWrap: "never", // Minimize `mdx` diffs with simpler content lines
},
},
],
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -142,15 +142,15 @@ func main() {
}

func newTxBuilder(pubKey string) (*txnbuild.Transaction, error) {
account := horizonclient.AccountRequest{AccountID: pubKey}
account := horizonclient.AccountRequest{AccountID: pubKey}
check(err) // Confirm account & sequence number
txEnvelopeParams := &txnbuild.TransactionParams{
SourceAccount: &account,
BaseFee: txnbuild.MinBaseFee,
Timebounds: txnbuild.NewTimeout(360),
IncrementSequenceNum: true,
}
return txnbuild.NewTransaction(txEnvelopeParams)
txEnvelopeParams := &txnbuild.TransactionParams{
SourceAccount: &account,
BaseFee: txnbuild.MinBaseFee,
Timebounds: txnbuild.NewTimeout(360),
IncrementSequenceNum: true,
}
return txnbuild.NewTransaction(txEnvelopeParams)
}
```

Expand Down Expand Up @@ -695,17 +695,17 @@ public static void getSpotPrice(String[] args) throws Exception {

```go
func getSpotPrice(server *horizonclient.Client, poolID string) {
poolRequest := horizonclient.LiquidityPoolRequest{LiquidityPoolID: poolID}
pool, err := server.LiquidityPoolDetail(poolRequest)
check(err)
poolRequest := horizonclient.LiquidityPoolRequest{LiquidityPoolID: poolID}
pool, err := server.LiquidityPoolDetail(poolRequest)
check(err)

reserveA, err := strconv.ParseFloat(pool.Reserves[0].Amount, 64)
check(err)
reserveB, err := strconv.ParseFloat(pool.Reserves[1].Amount, 64)
check(err)
reserveA, err := strconv.ParseFloat(pool.Reserves[0].Amount, 64)
check(err)
reserveB, err := strconv.ParseFloat(pool.Reserves[1].Amount, 64)
check(err)

spotPrice := reserveA / reserveB
fmt.Printf("Price: %.7f/%.7f = %.7f\n", reserveA, reserveB, spotPrice)
spotPrice := reserveA / reserveB
fmt.Printf("Price: %.7f/%.7f = %.7f\n", reserveA, reserveB, spotPrice)
}
```

Expand Down Expand Up @@ -932,61 +932,61 @@ public static void preamble() throws Exception {

```go
var secrets = []string{
"SBGCD73TK2PTW2DQNWUYZSTCTHHVJPL4GZF3GVZMCDL6GYETYNAYOADN",
"SAAQFHI2FMSIC6OFPWZ3PDIIX3OF64RS3EB52VLYYZBX6GYB54TW3Q4U",
"SCJWYFTBDMDPAABHVJZE3DRMBRTEH4AIC5YUM54QGW57NUBM2XX6433P",
"SBGCD73TK2PTW2DQNWUYZSTCTHHVJPL4GZF3GVZMCDL6GYETYNAYOADN",
"SAAQFHI2FMSIC6OFPWZ3PDIIX3OF64RS3EB52VLYYZBX6GYB54TW3Q4U",
"SCJWYFTBDMDPAABHVJZE3DRMBRTEH4AIC5YUM54QGW57NUBM2XX6433P",
}

func distributeAssets(issuerKp, recipientKp *keypair.Full, assets []txnbuild.Asset) error {
tx, err := newTxBuilder(issuerKp.Address())
check(err)

ops := []txnbuild.Operation{}
for _, asset := range assets {
ops = append(ops,
&txnbuild.ChangeTrust{
Line: asset,
SourceAccount: recipientKp.Address(),
},
&txnbuild.Payment{
Destination: recipientKp.Address(),
Asset: asset,
Amount: "100000",
SourceAccount: issuerKp.Address(),
},
)
}

tx.Params.Operations = ops
tx, err := tx.BuildSignEncode(issuerKp, recipientKp)
check(err)

_, err = server.SubmitTransactionXDR(tx)
return err
tx, err := newTxBuilder(issuerKp.Address())
check(err)

ops := []txnbuild.Operation{}
for _, asset := range assets {
ops = append(ops,
&txnbuild.ChangeTrust{
Line: asset,
SourceAccount: recipientKp.Address(),
},
&txnbuild.Payment{
Destination: recipientKp.Address(),
Asset: asset,
Amount: "100000",
SourceAccount: issuerKp.Address(),
},
)
}

tx.Params.Operations = ops
tx, err := tx.BuildSignEncode(issuerKp, recipientKp)
check(err)

_, err = server.SubmitTransactionXDR(tx)
return err
}

// Function to order assets in "protocol order"
func orderAssets(a, b txnbuild.Asset) (txnbuild.Asset, txnbuild.Asset) {
if a.LessThan(b) {
return a, b
}
return b, a
if a.LessThan(b) {
return a, b
}
return b, a
}

func preamble() {
kp0 := keypair.MustParseFull(secrets[0])
kp1 := keypair.MustParseFull(secrets[1])
kp2 := keypair.MustParseFull(secrets[2])

assetA, assetB := orderAssets(
txnbuild.CreditAsset{"A", kp0.Address()},
txnbuild.CreditAsset{"B", kp0.Address()},
)

err := distributeAssets(kp0, kp1, []txnbuild.Asset{assetA, assetB})
check(err)
err = distributeAssets(kp0, kp2, []txnbuild.Asset{assetA, assetB})
check(err)
kp0 := keypair.MustParseFull(secrets[0])
kp1 := keypair.MustParseFull(secrets[1])
kp2 := keypair.MustParseFull(secrets[2])

assetA, assetB := orderAssets(
txnbuild.CreditAsset{"A", kp0.Address()},
txnbuild.CreditAsset{"B", kp0.Address()},
)

err := distributeAssets(kp0, kp1, []txnbuild.Asset{assetA, assetB})
check(err)
err = distributeAssets(kp0, kp2, []txnbuild.Asset{assetA, assetB})
check(err)
}
```

Expand Down Expand Up @@ -1405,36 +1405,36 @@ public Map<String, Object> removeLiquidity(KeyPair source, String poolId, String

```go
func removeLiquidity(source *keypair.Full, poolID string, sharesAmount float64) {
poolRequest := horizonclient.LiquidityPoolRequest{LiquidityPoolID: poolID}
poolInfo, err := client.LiquidityPoolDetail(poolRequest)
check(err)

totalShares, err := strconv.ParseFloat(poolInfo.TotalShares, 64)
check(err)
reserveA, err := strconv.ParseFloat(poolInfo.Reserves[0].Amount, 64)
check(err)
reserveB, err := strconv.ParseFloat(poolInfo.Reserves[1].Amount, 64)
check(err)

minReserveA := (sharesAmount / totalShares) * reserveA * 0.95 // 95% safety factor
minReserveB := (sharesAmount / totalShares) * reserveB * 0.95

tx := newTxBuilder(source.Address())
tx.Operations = []txnbuild.Operation{
&txnbuild.LiquidityPoolWithdraw{
LiquidityPoolID: poolID,
Amount: formatFloat(sharesAmount),
MinAmountA: formatFloat(minReserveA),
MinAmountB: formatFloat(minReserveB),
},
}

tx, err := tx.Build()
check(err)
signedTx, err := tx.Sign(txnbuild.NetworkTest, source)
check(err)
resp, err := client.SubmitTransaction(signedTx)
check(err)
poolRequest := horizonclient.LiquidityPoolRequest{LiquidityPoolID: poolID}
poolInfo, err := client.LiquidityPoolDetail(poolRequest)
check(err)

totalShares, err := strconv.ParseFloat(poolInfo.TotalShares, 64)
check(err)
reserveA, err := strconv.ParseFloat(poolInfo.Reserves[0].Amount, 64)
check(err)
reserveB, err := strconv.ParseFloat(poolInfo.Reserves[1].Amount, 64)
check(err)

minReserveA := (sharesAmount / totalShares) * reserveA * 0.95 // 95% safety factor
minReserveB := (sharesAmount / totalShares) * reserveB * 0.95

tx := newTxBuilder(source.Address())
tx.Operations = []txnbuild.Operation{
&txnbuild.LiquidityPoolWithdraw{
LiquidityPoolID: poolID,
Amount: formatFloat(sharesAmount),
MinAmountA: formatFloat(minReserveA),
MinAmountB: formatFloat(minReserveB),
},
}

tx, err := tx.Build()
check(err)
signedTx, err := tx.Sign(txnbuild.NetworkTest, source)
check(err)
resp, err := client.SubmitTransaction(signedTx)
check(err)
}
```

Expand Down Expand Up @@ -1560,43 +1560,43 @@ public static void main(String[] args) throws Exception {
```go
func main() {
kps := make([]*keypair.Full, len(secrets))
for i, secret := range secrets {
kps[i] = keypair.MustParseFull(secret)
}

// Simulate deposits from participants
for i := 1; i < len(kps); i++ {
kp := kps[i]
// Arbitrary deposit increasing amounts
for i, secret := range secrets {
kps[i] = keypair.MustParseFull(secret)
}

// Simulate deposits from participants
for i := 1; i < len(kps); i++ {
kp := kps[i]
// Arbitrary deposit increasing amounts
depositA := float64(i+1) * 1000
depositB := float64(i+1) * 3000 // Scalar maintains 1:3 ratio
depositB := float64(i+1) * 3000 // Scalar maintains 1:3 ratio

establishPoolTrustline(kp, poolID)
addLiquidity(kp, poolID, depositA, depositB)
getSpotPrice(poolID)
}
getSpotPrice(poolID)
}

// kp1 removes all liquidity
kp1 := kps[1]
account, err := server.AccountDetail(
// kp1 removes all liquidity
kp1 := kps[1]
account, err := server.AccountDetail(
horizonclient.AccountRequest{AccountID: kp1.Address()}
)
check(err)
check(err)

var balance float64
for _, bal := range account.Balances {
if bal.AssetType == "liquidity_pool_shares" &&
var balance float64
for _, bal := range account.Balances {
if bal.AssetType == "liquidity_pool_shares" &&
bal.LiquidityPoolID == poolID {
balance, err = strconv.ParseFloat(bal.Balance, 64)
check(err)
break
}
}
if balance == 0 {
log.Fatalf("No liquidity pool shares found for kp1.")
}
removeLiquidity(kp1, poolID, balance)
getSpotPrice(poolID)
balance, err = strconv.ParseFloat(bal.Balance, 64)
check(err)
break
}
}
if balance == 0 {
log.Fatalf("No liquidity pool shares found for kp1.")
}
removeLiquidity(kp1, poolID, balance)
getSpotPrice(poolID)
}
```

Expand Down

0 comments on commit f1a50e2

Please sign in to comment.