Skip to content

Commit

Permalink
type js-buildTransaction
Browse files Browse the repository at this point in the history
  • Loading branch information
lvndry committed Oct 13, 2023
1 parent 2d9b161 commit e96e392
Showing 1 changed file with 9 additions and 11 deletions.
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import invariant from "invariant";
import StellarSdk from "stellar-sdk";
import { Memo, Operation as StellarSdkOperation, xdr } from "stellar-sdk";
import { AmountRequired, FeeNotLoaded, NetworkDown } from "@ledgerhq/errors";
import type { Account } from "@ledgerhq/types-live";
import type { Transaction } from "./types";
Expand All @@ -17,10 +17,7 @@ import { StellarAssetRequired, StellarMuxedAccountNotExist } from "../../errors"
* @param {Account} a
* @param {Transaction} t
*/
export const buildTransaction = async (
account: Account,
transaction: Transaction,
): Promise<any> => {
export const buildTransaction = async (account: Account, transaction: Transaction) => {
const { recipient, networkInfo, fees, memoType, memoValue, mode, assetCode, assetIssuer } =
transaction;

Expand All @@ -37,7 +34,7 @@ export const buildTransaction = async (
invariant(networkInfo && networkInfo.family === "stellar", "stellar family");

const transactionBuilder = buildTransactionBuilder(source, fees);
let operation = null;
let operation: xdr.Operation<StellarSdkOperation.ChangeTrust> | null = null;

if (mode === "changeTrust") {
if (!assetCode || !assetIssuer) {
Expand Down Expand Up @@ -76,24 +73,24 @@ export const buildTransaction = async (

transactionBuilder.addOperation(operation);

let memo = null;
let memo: Memo | null = null;

if (memoType && memoValue) {
switch (memoType) {
case "MEMO_TEXT":
memo = StellarSdk.Memo.text(memoValue);
memo = Memo.text(memoValue);
break;

case "MEMO_ID":
memo = StellarSdk.Memo.id(memoValue);
memo = Memo.id(memoValue);
break;

case "MEMO_HASH":
memo = StellarSdk.Memo.hash(memoValue);
memo = Memo.hash(memoValue);
break;

case "MEMO_RETURN":
memo = StellarSdk.Memo.return(memoValue);
memo = Memo.return(memoValue);
break;
}
}
Expand All @@ -105,4 +102,5 @@ export const buildTransaction = async (
const built = transactionBuilder.setTimeout(0).build();
return built;
};

export default buildTransaction;

1 comment on commit e96e392

@github-actions
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[Bot] Testing with 'Nitrogen' ✅ 4 txs ($6.83) ⏲ 2min 9s

✅ 1 specs are successful: Stellar

What is the bot and how does it work? Everything is documented here!

⚠️ 1 spec hints
  • Spec Stellar:
    • mutations should define a testDestination(): Send max XLM, move ~50% XLM
Details of the 4 mutations

Spec Stellar (6)

Spec Stellar found 6 Stellar accounts. Will use Stellar 4.0.1 on nanoS 2.1.0
Stellar 1 cross: 1.5005 XLM (289ops) (GDJPZPOWITPCBX3TIHB6N7E4WCHS6JBZKSNWGU34QYCJXKWBTUZY5RYC on 44'/148'/0') sep5#0 js:2:stellar:GDJPZPOWITPCBX3TIHB6N7E4WCHS6JBZKSNWGU34QYCJXKWBTUZY5RYC:sep5
Stellar 2: 7.07035 XLM (297ops) (GC25SBJ3F2XGWRTS3DGPCNFAGQLNDBFUKUJREJMHVV2JIUBZSVY2GAHZ on 44'/148'/1') sep5#1 js:2:stellar:GC25SBJ3F2XGWRTS3DGPCNFAGQLNDBFUKUJREJMHVV2JIUBZSVY2GAHZ:sep5
Stellar 3: 24.7882 XLM (293ops) (GA4A2FH4YYI2RXPUC3NPGZQP7XX4CEJNREB27XVX7B7D5RIA3KOLSKTI on 44'/148'/2') sep5#2 js:2:stellar:GA4A2FH4YYI2RXPUC3NPGZQP7XX4CEJNREB27XVX7B7D5RIA3KOLSKTI:sep5
Stellar 4: 26.4195 XLM (274ops) (GDTKZ5E53DELQO33QAYYR6TS4JX44MP2PGCRGKY3RE42IT7PUNLU2SHM on 44'/148'/3') sep5#3 js:2:stellar:GDTKZ5E53DELQO33QAYYR6TS4JX44MP2PGCRGKY3RE42IT7PUNLU2SHM:sep5
Stellar 5: 6.7182 XLM (248ops) (GBV2ROL25KKDSFCZC2TQPMUEN567YQHRWTRBYHCO5AKYWVIV4JKJ56AF on 44'/148'/4') sep5#4 js:2:stellar:GBV2ROL25KKDSFCZC2TQPMUEN567YQHRWTRBYHCO5AKYWVIV4JKJ56AF:sep5
Stellar 6: 0 XLM (0ops) (GCMN2KYJPPHB4TMXXF2OZPMWVM5EQSDD76IMFOMET7YMN64VJDVHVNCM on 44'/148'/5') sep5#5 js:2:stellar:GCMN2KYJPPHB4TMXXF2OZPMWVM5EQSDD76IMFOMET7YMN64VJDVHVNCM:sep5
necessary accounts resynced in 0.30ms
▬ Stellar 4.0.1 on nanoS 2.1.0
→ FROM Stellar 2: 7.07035 XLM (297ops) (GC25SBJ3F2XGWRTS3DGPCNFAGQLNDBFUKUJREJMHVV2JIUBZSVY2GAHZ on 44'/148'/1') sep5#1 js:2:stellar:GC25SBJ3F2XGWRTS3DGPCNFAGQLNDBFUKUJREJMHVV2JIUBZSVY2GAHZ:sep5 (! sum of ops 7.0799506 XLM)  TokenAccount USDC: 0 USDC (0 ops)
max spendable ~5.57033
★ using mutation 'Send max XLM'
→ TO Stellar 4: 26.4195 XLM (274ops) (GDTKZ5E53DELQO33QAYYR6TS4JX44MP2PGCRGKY3RE42IT7PUNLU2SHM on 44'/148'/3') sep5#3 js:2:stellar:GDTKZ5E53DELQO33QAYYR6TS4JX44MP2PGCRGKY3RE42IT7PUNLU2SHM:sep5
✔️ transaction 
    SEND MAX
    TO GDTKZ5E53DELQO33QAYYR6TS4JX44MP2PGCRGKY3RE42IT7PUNLU2SHM
    with fees=0.0005 XLM
STATUS (1439ms)
  amount: 5.5698483 XLM
  estimated fees: 0.0005 XLM
  total spent: 5.5698483 XLM
errors: 
errors: 
✔️ has been signed! (5.1s) 
✔️ broadcasted! (9.3s) optimistic operation: 
  -5.5698483 XLM     OUT        bd1482338760fdc81c138368d1f0fe393f9de908c88d157c0ce6e906cc434e04 2023-10-13T14:52
✔️ operation confirmed (10.8s): 
  -5.5698483 XLM     OUT        bd1482338760fdc81c138368d1f0fe393f9de908c88d157c0ce6e906cc434e04 2023-10-13T14:52
✔️ Stellar 2: 1.5005 XLM (298ops) (GC25SBJ3F2XGWRTS3DGPCNFAGQLNDBFUKUJREJMHVV2JIUBZSVY2GAHZ on 44'/148'/1') sep5#1 js:2:stellar:GC25SBJ3F2XGWRTS3DGPCNFAGQLNDBFUKUJREJMHVV2JIUBZSVY2GAHZ:sep5 (! sum of ops 1.5101023 XLM)  TokenAccount USDC: 0 USDC (0 ops)(in 10.8s)

necessary accounts resynced in 860ms
▬ Stellar 4.0.1 on nanoS 2.1.0
→ FROM Stellar 3: 24.7882 XLM (293ops) (GA4A2FH4YYI2RXPUC3NPGZQP7XX4CEJNREB27XVX7B7D5RIA3KOLSKTI on 44'/148'/2') sep5#2 js:2:stellar:GA4A2FH4YYI2RXPUC3NPGZQP7XX4CEJNREB27XVX7B7D5RIA3KOLSKTI:sep5 (! sum of ops 24.796132 XLM)  TokenAccount USDC: 0 USDC (0 ops)
max spendable ~23.2882
★ using mutation 'move ~50% XLM'
→ TO Stellar 1 cross: 1.5005 XLM (289ops) (GDJPZPOWITPCBX3TIHB6N7E4WCHS6JBZKSNWGU34QYCJXKWBTUZY5RYC on 44'/148'/0') sep5#0 js:2:stellar:GDJPZPOWITPCBX3TIHB6N7E4WCHS6JBZKSNWGU34QYCJXKWBTUZY5RYC:sep5
✔️ transaction 
    SEND 11.1683704 XLM
    TO GDJPZPOWITPCBX3TIHB6N7E4WCHS6JBZKSNWGU34QYCJXKWBTUZY5RYC
    with fees=0.0005 XLM
  memo=Ledger Live
STATUS (1370ms)
  amount: 11.1683704 XLM
  estimated fees: 0.0005 XLM
  total spent: 11.1688704 XLM
errors: 
errors: 
✔️ has been signed! (5s) 
✔️ broadcasted! (8.1s) optimistic operation: 
  -11.1683704 XLM    OUT        be72557828a69f43091394cde161141038fbd01c97efea0ec7bce64c09bea3c1 2023-10-13T14:52
✔️ operation confirmed (10.8s): 
  -11.1683704 XLM    OUT        be72557828a69f43091394cde161141038fbd01c97efea0ec7bce64c09bea3c1 2023-10-13T14:52
✔️ Stellar 3: 13.6198 XLM (294ops) (GA4A2FH4YYI2RXPUC3NPGZQP7XX4CEJNREB27XVX7B7D5RIA3KOLSKTI on 44'/148'/2') sep5#2 js:2:stellar:GA4A2FH4YYI2RXPUC3NPGZQP7XX4CEJNREB27XVX7B7D5RIA3KOLSKTI:sep5 (! sum of ops 13.6277616 XLM)  TokenAccount USDC: 0 USDC (0 ops)(in 10.8s)

necessary accounts resynced in 814ms
▬ Stellar 4.0.1 on nanoS 2.1.0
→ FROM Stellar 4: 31.9894 XLM (275ops) (GDTKZ5E53DELQO33QAYYR6TS4JX44MP2PGCRGKY3RE42IT7PUNLU2SHM on 44'/148'/3') sep5#3 js:2:stellar:GDTKZ5E53DELQO33QAYYR6TS4JX44MP2PGCRGKY3RE42IT7PUNLU2SHM:sep5 (! sum of ops 31.9982857 XLM)  TokenAccount USDC: 0 USDC (0 ops)
max spendable ~30.4894
★ using mutation 'move ~50% XLM'
→ TO Stellar 5: 6.7182 XLM (248ops) (GBV2ROL25KKDSFCZC2TQPMUEN567YQHRWTRBYHCO5AKYWVIV4JKJ56AF on 44'/148'/4') sep5#4 js:2:stellar:GBV2ROL25KKDSFCZC2TQPMUEN567YQHRWTRBYHCO5AKYWVIV4JKJ56AF:sep5
✔️ transaction 
    SEND 14.7790025 XLM
    TO GBV2ROL25KKDSFCZC2TQPMUEN567YQHRWTRBYHCO5AKYWVIV4JKJ56AF
    with fees=0.0005 XLM
STATUS (1487ms)
  amount: 14.7790025 XLM
  estimated fees: 0.0005 XLM
  total spent: 14.7795025 XLM
errors: 
errors: 
✔️ has been signed! (3.9s) 
✔️ broadcasted! (6.1s) optimistic operation: 
  -14.7790025 XLM    OUT        2fdbe99f52a707a6b18218cc1237cc48bf7202da4745e9cde9bb27f1b36a073d 2023-10-13T14:53
✔️ operation confirmed (10.9s): 
  -14.7790025 XLM    OUT        2fdbe99f52a707a6b18218cc1237cc48bf7202da4745e9cde9bb27f1b36a073d 2023-10-13T14:53
✔️ Stellar 4: 17.2104 XLM (276ops) (GDTKZ5E53DELQO33QAYYR6TS4JX44MP2PGCRGKY3RE42IT7PUNLU2SHM on 44'/148'/3') sep5#3 js:2:stellar:GDTKZ5E53DELQO33QAYYR6TS4JX44MP2PGCRGKY3RE42IT7PUNLU2SHM:sep5 (! sum of ops 17.2192832 XLM)  TokenAccount USDC: 0 USDC (0 ops)(in 10.9s)

necessary accounts resynced in 833ms
▬ Stellar 4.0.1 on nanoS 2.1.0
→ FROM Stellar 5: 21.4972 XLM (249ops) (GBV2ROL25KKDSFCZC2TQPMUEN567YQHRWTRBYHCO5AKYWVIV4JKJ56AF on 44'/148'/4') sep5#4 js:2:stellar:GBV2ROL25KKDSFCZC2TQPMUEN567YQHRWTRBYHCO5AKYWVIV4JKJ56AF:sep5 (! sum of ops 21.5021732 XLM)  TokenAccount USDC: 0 USDC (0 ops)
max spendable ~19.9971
★ using mutation 'Send max XLM'
→ TO Stellar 1 cross: 12.6688 XLM (290ops) (GDJPZPOWITPCBX3TIHB6N7E4WCHS6JBZKSNWGU34QYCJXKWBTUZY5RYC on 44'/148'/0') sep5#0 js:2:stellar:GDJPZPOWITPCBX3TIHB6N7E4WCHS6JBZKSNWGU34QYCJXKWBTUZY5RYC:sep5
✔️ transaction 
    SEND MAX
    TO GDJPZPOWITPCBX3TIHB6N7E4WCHS6JBZKSNWGU34QYCJXKWBTUZY5RYC
    with fees=0.0005 XLM
  memo=Ledger Live
STATUS (1232ms)
  amount: 19.9966961 XLM
  estimated fees: 0.0005 XLM
  total spent: 19.9966961 XLM
errors: 
errors: 
✔️ has been signed! (4.3s) 
✔️ broadcasted! (5.9s) optimistic operation: 
  -19.9966961 XLM    OUT        25480d9170108648bc35ca8e93ccc4f3ee29791d4878da3b7625a4274f60a76b 2023-10-13T14:53
✔️ operation confirmed (10.7s): 
  -19.9966961 XLM    OUT        25480d9170108648bc35ca8e93ccc4f3ee29791d4878da3b7625a4274f60a76b 2023-10-13T14:53
✔️ Stellar 5: 1.5005 XLM (250ops) (GBV2ROL25KKDSFCZC2TQPMUEN567YQHRWTRBYHCO5AKYWVIV4JKJ56AF on 44'/148'/4') sep5#4 js:2:stellar:GBV2ROL25KKDSFCZC2TQPMUEN567YQHRWTRBYHCO5AKYWVIV4JKJ56AF:sep5 (! sum of ops 1.5054771 XLM)  TokenAccount USDC: 0 USDC (0 ops)(in 10.7s)


Details of the 2 uncovered mutations

Spec Stellar (2)

  • add USDC asset: XLM balance is too low 1 (2)
  • move ~50% USDC asset: XLM balance is too low (2)
Portfolio ($6.83) – Details of the 1 currencies
Spec (accounts) State Remaining Runs (est) funds?
Stellar (6) 1409 ops (+8), 58.9968 XLM ($6.83) 💪 999+ GDJPZPOWITPCBX3TIHB6N7E4WCHS6JBZKSNWGU34QYCJXKWBTUZY5RYC
Stellar 1 cross: 32.6655 XLM (291ops) (GDJPZPOWITPCBX3TIHB6N7E4WCHS6JBZKSNWGU34QYCJXKWBTUZY5RYC on 44'/148'/0') sep5#0 js:2:stellar:GDJPZPOWITPCBX3TIHB6N7E4WCHS6JBZKSNWGU34QYCJXKWBTUZY5RYC:sep5
Stellar 2: 1.5005 XLM (298ops) (GC25SBJ3F2XGWRTS3DGPCNFAGQLNDBFUKUJREJMHVV2JIUBZSVY2GAHZ on 44'/148'/1') sep5#1 js:2:stellar:GC25SBJ3F2XGWRTS3DGPCNFAGQLNDBFUKUJREJMHVV2JIUBZSVY2GAHZ:sep5
Stellar 3: 13.6198 XLM (294ops) (GA4A2FH4YYI2RXPUC3NPGZQP7XX4CEJNREB27XVX7B7D5RIA3KOLSKTI on 44'/148'/2') sep5#2 js:2:stellar:GA4A2FH4YYI2RXPUC3NPGZQP7XX4CEJNREB27XVX7B7D5RIA3KOLSKTI:sep5
Stellar 4: 17.2104 XLM (276ops) (GDTKZ5E53DELQO33QAYYR6TS4JX44MP2PGCRGKY3RE42IT7PUNLU2SHM on 44'/148'/3') sep5#3 js:2:stellar:GDTKZ5E53DELQO33QAYYR6TS4JX44MP2PGCRGKY3RE42IT7PUNLU2SHM:sep5
Stellar 5: 1.5005 XLM (250ops) (GBV2ROL25KKDSFCZC2TQPMUEN567YQHRWTRBYHCO5AKYWVIV4JKJ56AF on 44'/148'/4') sep5#4 js:2:stellar:GBV2ROL25KKDSFCZC2TQPMUEN567YQHRWTRBYHCO5AKYWVIV4JKJ56AF:sep5
Stellar 6: 0 XLM (0ops) (GCMN2KYJPPHB4TMXXF2OZPMWVM5EQSDD76IMFOMET7YMN64VJDVHVNCM on 44'/148'/5') sep5#5 js:2:stellar:GCMN2KYJPPHB4TMXXF2OZPMWVM5EQSDD76IMFOMET7YMN64VJDVHVNCM:sep5
Performance ⏲ 2min 9s

Time spent for each spec: (total across mutations)

Spec (accounts) preload scan re-sync tx status sign op broadcast test destination test
TOTAL 1.56ms 18.2s 3.3s 5.5s 18.4s 29.5s 43.2s N/A
Stellar (5) 1.56ms 18.2s 3.3s 5.5s 18.4s 29.5s 43.2s N/A

What is the bot and how does it work? Everything is documented here!

Please sign in to comment.