Skip to content
This repository has been archived by the owner on Jul 15, 2022. It is now read-only.

Commit

Permalink
Cosmos JS (#1713)
Browse files Browse the repository at this point in the history
* increase gas amplifier

* fix payload construction

handle payload atomic construction

* More accurate gas amplifier

* increase gas amplifier

* use same node for calculation and broadcast

* fix amount payload

* fix fees/gas calculation

* fix signature

fix public key when account is derivate

* fix fees regression

* More accurate pubkey selection

* don't use extra.tx_bytes

* fix pubkey selection

* simplify hex serialization

* update transaction: more strict types

* many things

restruct operation builder
simulate now return int
prepareTransaction use patch format

* accuracy

more accuracy int value
small refactor

* remove useless isPreValidation

* fix strange edge effect of ledger live desktop

* Update xpub during sync

* temporary enable log for bot

* LL-9159 cosmos node

* Update js-signOperation.ts

revert back test trace for bot

* fix signature

* fix redelegate payload

* fix payload send transaction when sendmax

* fix optimistic operation type

* fix typo

* bugfix

Co-authored-by: Alexandre Alouit <[email protected]>
  • Loading branch information
wa-aal and alexalouit authored Feb 18, 2022
1 parent a84f238 commit c9df7c4
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 12 deletions.
2 changes: 1 addition & 1 deletion src/families/cosmos/js-buildTransaction.ts
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,7 @@ const buildTransaction = async (
value: {
validatorSrcAddress: transaction.cosmosSourceValidator,
delegatorAddress: account.freshAddress,
validatorAddress: transaction.validators[0].address,
validatorDstAddress: transaction.validators[0].address,
amount: {
denom: account.currency.units[1].code,
amount: transaction.validators[0].amount.toString(),
Expand Down
5 changes: 4 additions & 1 deletion src/families/cosmos/js-prepareTransaction.ts
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,10 @@ const prepareTransaction = async (
patch.memo = "Ledger Live";
}

const unsignedPayload = await buildTransaction(account, transaction);
const unsignedPayload = await buildTransaction(account, {
...transaction,
...patch,
});

// be sure payload is complete
if (unsignedPayload) {
Expand Down
27 changes: 17 additions & 10 deletions src/families/cosmos/js-signOperation.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { Account, SignOperationEvent } from "../../types";
import { Account, OperationType, SignOperationEvent } from "../../types";
import type { Transaction } from "./types";
import { getAccount, getChainId } from "./api/Cosmos";
import { Observable } from "rxjs";
Expand Down Expand Up @@ -145,24 +145,31 @@ const signOperation = ({

o.next({ type: "device-signature-granted" });

// build optimistic operation
const txHash = ""; // resolved at broadcast time
const senders = [account.freshAddress];
const recipients = [transaction.recipient];
const accountId = account.id;
const type: OperationType =
transaction.mode === "undelegate"
? "UNDELEGATE"
: transaction.mode === "delegate"
? "DELEGATE"
: transaction.mode === "redelegate"
? "REDELEGATE"
: ["claimReward", "claimRewardCompound"].includes(transaction.mode)
? "REWARD"
: "OUT";

// build optimistic operation
const operation = {
id: encodeOperationId(accountId, txHash, "OUT"),
id: encodeOperationId(account.id, txHash, type),
hash: txHash,
type: "OUT",
type: type,
value: transaction.amount,
fee: transaction.fees,
extra: {},
blockHash: null,
blockHeight: null,
senders,
recipients,
accountId,
senders: [account.freshAddress],
recipients: [transaction.recipient],
account: account.id,
date: new Date(),
};

Expand Down

1 comment on commit c9df7c4

@github-actions
Copy link

Choose a reason for hiding this comment

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

❌ 2 txs ($32.84) for Bot 'Cosmos JS'

⚠️ 4 mutations uncovered

2 mutation errors
all accounts sync in 1625ms
▬ Cosmos 2.18.0 on nanoS 2.0.0
→ FROM Cosmos 2: 0.4182 ATOM (11ops) (cosmos1zd0e8j9g9wur8up7j5aqahz233r4jmvqhyffnv on 44'/118'/1'/0/0) #1 js:2:cosmos:cosmos1zd0e8j9g9wur8up7j5aqahz233r4jmvqhyffnv: (! sum of ops 0.437028 ATOM) 0.185588 ATOM spendable. 0.232622 ATOM delegated. 
DELEGATIONS
  to cosmosvaloper1rpgtz9pskr5geavkjz02caqmeep7cwwpv73axj 0.012531 ATOM 
  to cosmosvaloper1x8rr4hcf54nz6hfckyy2n05sxss54h8wz9puzg 0.017993 ATOM 
  to cosmosvaloper1cgh5ksjwy2sd407lyre4l3uj2fdrqhpkzp06e6 0.022033 ATOM 
  to cosmosvaloper1rcp29q3hpd246n6qak7jluqep4v006cdsc2kkl 0.087313 ATOM 
  to cosmosvaloper16qme5yxucnaj6snx35nmwze0wyxr8wfgqxsqfw 0.024038 ATOM 
  to cosmosvaloper1wlagucxdxvsmvj6330864x8q3vxz4x02rmvmsu 0.061104 ATOM 
  to cosmosvaloper1gjtvly9lel6zskvwtvlg5vhwpu9c9waw7sxzwx 0.00761 ATOM 
  to cosmosvaloper1sxx9mszve0gaedz5ld7qdkjkfv8z992ax69k08 0.004641 ATOM 
UNDELEGATIONS
  from cosmosvaloper146kwpzhmleafmhtaxulfptyhnvwxzlvm87hwnm 0.01132 ATOM
  from cosmosvaloper1cgh5ksjwy2sd407lyre4l3uj2fdrqhpkzp06e6 0.003122 ATOM

max spendable ~0.17933
★ using mutation 'delegate new validators'
✔️ transaction 
DELEGATE 
TO 
  0.001467 -> cosmosvaloper1thl5syhmscgnj7whdyrydw3w6vy80044hjpnxh
  0.002439 -> cosmosvaloper1q6d3d089hg59x6gcx92uumx70s5y5wadklue8s
  0.000786 -> cosmosvaloper14jlpmqquh0gste6nzf4dn43kc8h50l6fmx6dfs
  0.002094 -> cosmosvaloper102ruvpv2srmunfffxavttxnhezln6fnc54at8c
  0.000084 -> cosmosvaloper156gqf9837u7d4c4678yt3rl4ls9c5vuursrrzf
with fees=0.026357
  memo=LedgerLiveBot
STATUS (2161ms)
  amount: 0.00687 ATOM
  estimated fees: 0.026357 ATOM
  total spent: 0.033227 ATOM
✔️ has been signed! (4.8s) 
✔️ broadcasted! (130ms) optimistic operation: 
  ? 0                DELEGATE   4BB144D014BEA56A23B30BA41A7CDC15A4BFCA16CE3DBB51404B8A656A06EE16 2022-02-18T12:24
⚠️ Error: could not find optimisticOperation undefined-4BB144D014BEA56A23B30BA41A7CDC15A4BFCA16CE3DBB51404B8A656A06EE16-DELEGATE

Error: could not find optimisticOperation undefined-4BB144D014BEA56A23B30BA41A7CDC15A4BFCA16CE3DBB51404B8A656A06EE16-DELEGATE
all accounts sync in 2085ms
▬ Cosmos 2.18.0 on nanoS 2.0.0
→ FROM Cosmos 3: 0.4384 ATOM (11ops) (cosmos1uty5nf28emeahuhdg9runmzuluq9uj5uek4jk0 on 44'/118'/2'/0/0) #2 js:2:cosmos:cosmos1uty5nf28emeahuhdg9runmzuluq9uj5uek4jk0: (! sum of ops 0.439304 ATOM) 0.225495 ATOM spendable. 0.212908 ATOM delegated. 
DELEGATIONS
  to cosmosvaloper1nm0rrq86ucezaf8uj35pq9fpwr5r82clzyvtd8 0.002212 ATOM 
  to cosmosvaloper1ey69r37gfxvxg62sh4r0ktpuc46pzjrm873ae8 0.006734 ATOM 
  to cosmosvaloper1000ya26q2cmh399q4c5aaacd9lmmdqp90kw2jn 0.006595 ATOM 
  to cosmosvaloper14kn0kk33szpwus9nh8n87fjel8djx0y070ymmj 0.014991 ATOM 
  to cosmosvaloper1clpqr4nrk4khgkxj78fcwwh6dl3uw4epsluffn 0.003646 ATOM 
  to cosmosvaloper1d0aup392g3enru7eash83sedqclaxvp7fzh6gk 0.171265 ATOM 
  to cosmosvaloper1n3mhyp9fvcmuu8l0q8qvjy07x0rql8q46fe2xk 0.002433 ATOM 
  to cosmosvaloper157v7tczs40axfgejp2m43kwuzqe0wsy0rv8puv 0.000232 ATOM 
  to cosmosvaloper1hjadhj9nqzpye2vkmkz4thahhd0z8dh3udhq74 0.002393 ATOM 
  to cosmosvaloper1hjct6q7npsspsg3dgvzk3sdf89spmlpfdn6m9d 0.002407 ATOM 
UNDELEGATIONS
  from cosmosvaloper1ey69r37gfxvxg62sh4r0ktpuc46pzjrm873ae8 0.000899 ATOM

max spendable ~0.21924
★ using mutation 'redelegate'
✔️ transaction 
REDELEGATE 
TO 
  0.000078 -> cosmosvaloper1n3mhyp9fvcmuu8l0q8qvjy07x0rql8q46fe2xk
  source validator=cosmosvaloper1clpqr4nrk4khgkxj78fcwwh6dl3uw4epsluffn
with fees=0.016416
  memo=LedgerLiveBot
STATUS (727ms)
  amount: 0 ATOM
  estimated fees: 0.016416 ATOM
  total spent: 0.016416 ATOM
✔️ has been signed! (2691ms) 
✔️ broadcasted! (133ms) optimistic operation: 
  ? 0                REDELEGATE 246CA4C4FA7252FD5634DFBE7DA6BE4BC90944367ABAB5036AD267F6279FB983 2022-02-18T12:27
⚠️ Error: could not find optimisticOperation undefined-246CA4C4FA7252FD5634DFBE7DA6BE4BC90944367ABAB5036AD267F6279FB983-REDELEGATE

Error: could not find optimisticOperation undefined-246CA4C4FA7252FD5634DFBE7DA6BE4BC90944367ABAB5036AD267F6279FB983-REDELEGATE
Details of the 2 mutations

Spec Cosmos (7)

Spec Cosmos found 7 Cosmos accounts (preload: 343ms). Will use Cosmos 2.18.0 on nanoS 2.0.0
(538ms) Cosmos 1: 0.04301 ATOM (11ops) (cosmos1zpvthe3pxvyje7vrcqv2m6qe2qgu0r8gkz64er on 44'/118'/0'/0/0) #0 js:2:cosmos:cosmos1zpvthe3pxvyje7vrcqv2m6qe2qgu0r8gkz64er:
(671ms) Cosmos 2: 0.4228 ATOM (11ops) (cosmos1zd0e8j9g9wur8up7j5aqahz233r4jmvqhyffnv on 44'/118'/1'/0/0) #1 js:2:cosmos:cosmos1zd0e8j9g9wur8up7j5aqahz233r4jmvqhyffnv:
(433ms) Cosmos 3: 0.4357 ATOM (11ops) (cosmos1uty5nf28emeahuhdg9runmzuluq9uj5uek4jk0 on 44'/118'/2'/0/0) #2 js:2:cosmos:cosmos1uty5nf28emeahuhdg9runmzuluq9uj5uek4jk0:
(677ms) Cosmos 4: 0.08733 ATOM (8ops) (cosmos1ccemcd8p3r293e5rcv0awaj9hfnn6wmxkz520n on 44'/118'/3'/0/0) #3 js:2:cosmos:cosmos1ccemcd8p3r293e5rcv0awaj9hfnn6wmxkz520n:
(806ms) Cosmos 5: 0.1038 ATOM (3ops) (cosmos1mvk3fwxgdfac4yjmgl9hdz0555q8gljydzvjtu on 44'/118'/4'/0/0) #4 js:2:cosmos:cosmos1mvk3fwxgdfac4yjmgl9hdz0555q8gljydzvjtu:
(621ms) Cosmos 6: 0.09884 ATOM (2ops) (cosmos1draxuzz0aukggx63m852wm8mlxqpus2009cs97 on 44'/118'/5'/0/0) #5 js:2:cosmos:cosmos1draxuzz0aukggx63m852wm8mlxqpus2009cs97:
(1277ms) Cosmos 7: 0 ATOM (0ops) (cosmos14k7faf4cvxlflta4hytxavx3p7vj6uw69lgf03 on 44'/118'/6'/0/0) #6 js:2:cosmos:cosmos14k7faf4cvxlflta4hytxavx3p7vj6uw69lgf03:
all accounts sync in 1625ms
▬ Cosmos 2.18.0 on nanoS 2.0.0
→ FROM Cosmos 2: 0.4182 ATOM (11ops) (cosmos1zd0e8j9g9wur8up7j5aqahz233r4jmvqhyffnv on 44'/118'/1'/0/0) #1 js:2:cosmos:cosmos1zd0e8j9g9wur8up7j5aqahz233r4jmvqhyffnv: (! sum of ops 0.437028 ATOM) 0.185588 ATOM spendable. 0.232622 ATOM delegated. 
DELEGATIONS
  to cosmosvaloper1rpgtz9pskr5geavkjz02caqmeep7cwwpv73axj 0.012531 ATOM 
  to cosmosvaloper1x8rr4hcf54nz6hfckyy2n05sxss54h8wz9puzg 0.017993 ATOM 
  to cosmosvaloper1cgh5ksjwy2sd407lyre4l3uj2fdrqhpkzp06e6 0.022033 ATOM 
  to cosmosvaloper1rcp29q3hpd246n6qak7jluqep4v006cdsc2kkl 0.087313 ATOM 
  to cosmosvaloper16qme5yxucnaj6snx35nmwze0wyxr8wfgqxsqfw 0.024038 ATOM 
  to cosmosvaloper1wlagucxdxvsmvj6330864x8q3vxz4x02rmvmsu 0.061104 ATOM 
  to cosmosvaloper1gjtvly9lel6zskvwtvlg5vhwpu9c9waw7sxzwx 0.00761 ATOM 
  to cosmosvaloper1sxx9mszve0gaedz5ld7qdkjkfv8z992ax69k08 0.004641 ATOM 
UNDELEGATIONS
  from cosmosvaloper146kwpzhmleafmhtaxulfptyhnvwxzlvm87hwnm 0.01132 ATOM
  from cosmosvaloper1cgh5ksjwy2sd407lyre4l3uj2fdrqhpkzp06e6 0.003122 ATOM

max spendable ~0.17933
★ using mutation 'delegate new validators'
✔️ transaction 
DELEGATE 
TO 
  0.001467 -> cosmosvaloper1thl5syhmscgnj7whdyrydw3w6vy80044hjpnxh
  0.002439 -> cosmosvaloper1q6d3d089hg59x6gcx92uumx70s5y5wadklue8s
  0.000786 -> cosmosvaloper14jlpmqquh0gste6nzf4dn43kc8h50l6fmx6dfs
  0.002094 -> cosmosvaloper102ruvpv2srmunfffxavttxnhezln6fnc54at8c
  0.000084 -> cosmosvaloper156gqf9837u7d4c4678yt3rl4ls9c5vuursrrzf
with fees=0.026357
  memo=LedgerLiveBot
STATUS (2161ms)
  amount: 0.00687 ATOM
  estimated fees: 0.026357 ATOM
  total spent: 0.033227 ATOM
✔️ has been signed! (4.8s) 
✔️ broadcasted! (130ms) optimistic operation: 
  ? 0                DELEGATE   4BB144D014BEA56A23B30BA41A7CDC15A4BFCA16CE3DBB51404B8A656A06EE16 2022-02-18T12:24
⚠️ Error: could not find optimisticOperation undefined-4BB144D014BEA56A23B30BA41A7CDC15A4BFCA16CE3DBB51404B8A656A06EE16-DELEGATE

all accounts sync in 2085ms
▬ Cosmos 2.18.0 on nanoS 2.0.0
→ FROM Cosmos 3: 0.4384 ATOM (11ops) (cosmos1uty5nf28emeahuhdg9runmzuluq9uj5uek4jk0 on 44'/118'/2'/0/0) #2 js:2:cosmos:cosmos1uty5nf28emeahuhdg9runmzuluq9uj5uek4jk0: (! sum of ops 0.439304 ATOM) 0.225495 ATOM spendable. 0.212908 ATOM delegated. 
DELEGATIONS
  to cosmosvaloper1nm0rrq86ucezaf8uj35pq9fpwr5r82clzyvtd8 0.002212 ATOM 
  to cosmosvaloper1ey69r37gfxvxg62sh4r0ktpuc46pzjrm873ae8 0.006734 ATOM 
  to cosmosvaloper1000ya26q2cmh399q4c5aaacd9lmmdqp90kw2jn 0.006595 ATOM 
  to cosmosvaloper14kn0kk33szpwus9nh8n87fjel8djx0y070ymmj 0.014991 ATOM 
  to cosmosvaloper1clpqr4nrk4khgkxj78fcwwh6dl3uw4epsluffn 0.003646 ATOM 
  to cosmosvaloper1d0aup392g3enru7eash83sedqclaxvp7fzh6gk 0.171265 ATOM 
  to cosmosvaloper1n3mhyp9fvcmuu8l0q8qvjy07x0rql8q46fe2xk 0.002433 ATOM 
  to cosmosvaloper157v7tczs40axfgejp2m43kwuzqe0wsy0rv8puv 0.000232 ATOM 
  to cosmosvaloper1hjadhj9nqzpye2vkmkz4thahhd0z8dh3udhq74 0.002393 ATOM 
  to cosmosvaloper1hjct6q7npsspsg3dgvzk3sdf89spmlpfdn6m9d 0.002407 ATOM 
UNDELEGATIONS
  from cosmosvaloper1ey69r37gfxvxg62sh4r0ktpuc46pzjrm873ae8 0.000899 ATOM

max spendable ~0.21924
★ using mutation 'redelegate'
✔️ transaction 
REDELEGATE 
TO 
  0.000078 -> cosmosvaloper1n3mhyp9fvcmuu8l0q8qvjy07x0rql8q46fe2xk
  source validator=cosmosvaloper1clpqr4nrk4khgkxj78fcwwh6dl3uw4epsluffn
with fees=0.016416
  memo=LedgerLiveBot
STATUS (727ms)
  amount: 0 ATOM
  estimated fees: 0.016416 ATOM
  total spent: 0.016416 ATOM
✔️ has been signed! (2691ms) 
✔️ broadcasted! (133ms) optimistic operation: 
  ? 0                REDELEGATE 246CA4C4FA7252FD5634DFBE7DA6BE4BC90944367ABAB5036AD267F6279FB983 2022-02-18T12:27
⚠️ Error: could not find optimisticOperation undefined-246CA4C4FA7252FD5634DFBE7DA6BE4BC90944367ABAB5036AD267F6279FB983-REDELEGATE


Details of the 4 uncovered mutations

Spec Cosmos (4)

  • send some: balance is too low (5)
  • send max: balance is too low (5)
  • undelegate: balance is too low (5)
  • claim rewards: balance is too low (5)

Portfolio ($32.84)

Details of the 1 currencies
Spec (accounts) Operations Balance funds?
Cosmos (6) 49 (+3) 0.7175 ATOM (- 0.04964) ($32.84) ⚠️ cosmos1zpvthe3pxvyje7vrcqv2m6qe2qgu0r8gkz64er

Please sign in to comment.