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

Commit

Permalink
Cosmos js (#1711)
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

Co-authored-by: Alexandre Alouit <[email protected]>
  • Loading branch information
wa-aal and alexalouit authored Feb 17, 2022
1 parent 56887dc commit c5cc07e
Show file tree
Hide file tree
Showing 3 changed files with 4 additions and 9 deletions.
6 changes: 2 additions & 4 deletions src/families/cosmos/api/Cosmos.ts
Original file line number Diff line number Diff line change
Expand Up @@ -226,8 +226,7 @@ export const broadcast = async ({
}): Promise<Operation> => {
const { data } = await network({
method: "POST",
// url: `${defaultEndpoint}/cosmos/tx/v1beta1/txs`, // FIXME LL-9159
url: `https://node.atomscan.com/cosmos/tx/v1beta1/txs`,
url: `${defaultEndpoint}/cosmos/tx/v1beta1/txs`,
data: {
tx_bytes: Array.from(Uint8Array.from(Buffer.from(signature, "hex"))),
mode: "BROADCAST_MODE_SYNC",
Expand Down Expand Up @@ -265,8 +264,7 @@ export const simulate = async (tx_bytes: Array<any>): Promise<BigNumber> => {
try {
const { data } = await network({
method: "POST",
// url: `${defaultEndpoint}/cosmos/tx/v1beta1/simulate`, // FIXME LL-9159
url: `https://node.atomscan.com/cosmos/tx/v1beta1/simulate`,
url: `${defaultEndpoint}/cosmos/tx/v1beta1/simulate`,
data: {
tx_bytes: tx_bytes,
},
Expand Down
1 change: 1 addition & 0 deletions src/families/cosmos/js-prepareTransaction.ts
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@ const prepareTransaction = async (
typeUrl: "/cosmos.tx.v1beta1.TxBody",
value: {
messages: unsignedPayload,
memo: transaction.memo || patch.memo || "",
},
};

Expand Down
6 changes: 1 addition & 5 deletions src/families/cosmos/js-signOperation.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@ import {
} from "cosmjs-types/cosmos/staking/v1beta1/tx";
import { MsgWithdrawDelegatorReward } from "cosmjs-types/cosmos/distribution/v1beta1/tx";
import BigNumber from "bignumber.js";
import { log } from "@ledgerhq/logs";

const aminoTypes = new AminoTypes({ prefix: "cosmos" });

Expand Down Expand Up @@ -69,12 +68,8 @@ const signOperation = ({

let pubkey;

log("engine", "look for pubkey for address", account.freshAddress);
log("engine", "path", account.freshAddressPath);

accounts.forEach((a) => {
if (a.address == account.freshAddress) {
log("engine", "found pubkey with same address");
pubkey = encodePubkey({
type: "tendermint/PubKeySecp256k1",
value: Buffer.from(a.pubkey).toString("base64"),
Expand Down Expand Up @@ -113,6 +108,7 @@ const signOperation = ({
typeUrl: "/cosmos.tx.v1beta1.TxBody",
value: {
messages: msgs.map((msg) => aminoTypes.fromAmino(msg)),
memo: transaction.memo || "",
},
};

Expand Down

2 comments on commit c5cc07e

@github-actions
Copy link

Choose a reason for hiding this comment

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

⚠️ 1 specs ($0.00) for Bot 'Cosmos JS'

⚠️ 6 mutations uncovered

1 critical spec errors

Spec Cosmos failed!

DisconnectedDeviceDuringOperation: DisconnectedDeviceDuringOperation
Details of the 0 mutations

Spec Cosmos (failed)


Details of the 6 uncovered mutations

Spec Cosmos (6)

  • send some:
  • send max:
  • delegate new validators:
  • undelegate:
  • redelegate:
  • claim rewards:

Portfolio ($0.00)

Details of the 1 currencies
Spec (accounts) Operations Balance funds?
Cosmos (0) 0 🤷‍♂️ ???

@github-actions
Copy link

Choose a reason for hiding this comment

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

✅ 1 txs ❌ 3 txs ($37.76) for Bot 'Cosmos JS'

⚠️ 3 mutations uncovered

3 mutation errors
all accounts sync in 1594ms
▬ Cosmos 2.18.0 on nanoS 2.0.0-rc5
→ FROM Cosmos 2: 0.3243 ATOM (9ops) (cosmos1zd0e8j9g9wur8up7j5aqahz233r4jmvqhyffnv on 44'/118'/1'/0/0) #1 js:2:cosmos:cosmos1zd0e8j9g9wur8up7j5aqahz233r4jmvqhyffnv: (! sum of ops 0.459466 ATOM) 0.207761 ATOM spendable. 0.116603 ATOM delegated. 
DELEGATIONS
  to cosmosvaloper146kwpzhmleafmhtaxulfptyhnvwxzlvm87hwnm 0.01132 ATOM 
  to cosmosvaloper1wlagucxdxvsmvj6330864x8q3vxz4x02rmvmsu 0.061104 ATOM 
  to cosmosvaloper16qme5yxucnaj6snx35nmwze0wyxr8wfgqxsqfw 0.024038 ATOM 
  to cosmosvaloper1rpgtz9pskr5geavkjz02caqmeep7cwwpv73axj 0.012531 ATOM 
  to cosmosvaloper1gjtvly9lel6zskvwtvlg5vhwpu9c9waw7sxzwx 0.00761 ATOM 
  to cosmosvaloper1sxx9mszve0gaedz5ld7qdkjkfv8z992ax69k08 0.004641 ATOM 
  to cosmosvaloper1cgh5ksjwy2sd407lyre4l3uj2fdrqhpkzp06e6 0.025155 ATOM 
  to cosmosvaloper1rcp29q3hpd246n6qak7jluqep4v006cdsc2kkl 0.087313 ATOM 
  to cosmosvaloper1x8rr4hcf54nz6hfckyy2n05sxss54h8wz9puzg 0.017993 ATOM 

max spendable ~0.20151
★ using mutation 'undelegate'
✔️ transaction 
UNDELEGATE 
TO 
  0.01132 -> cosmosvaloper146kwpzhmleafmhtaxulfptyhnvwxzlvm87hwnm
with fees=0.010892
  memo=LedgerLiveBot
STATUS (763ms)
  amount: 0 ATOM
  estimated fees: 0.010892 ATOM
  total spent: 0.010892 ATOM
✔️ has been signed! (2201ms) 
✔️ broadcasted! (125ms) optimistic operation: 
  -0 ATOM            OUT        9CEFBEDD4FD6F0739FE4D6717605423884B2B2284249C0D2C0DBC97F799C5EB8 2022-02-17T11:51
⚠️ Error: could not find optimisticOperation js:2:cosmos:cosmos1zd0e8j9g9wur8up7j5aqahz233r4jmvqhyffnv:-9CEFBEDD4FD6F0739FE4D6717605423884B2B2284249C0D2C0DBC97F799C5EB8-OUT

Error: could not find optimisticOperation js:2:cosmos:cosmos1zd0e8j9g9wur8up7j5aqahz233r4jmvqhyffnv:-9CEFBEDD4FD6F0739FE4D6717605423884B2B2284249C0D2C0DBC97F799C5EB8-OUT
all accounts sync in 1587ms
▬ Cosmos 2.18.0 on nanoS 2.0.0-rc5
→ FROM Cosmos 3: 0.3803 ATOM (7ops) (cosmos1uty5nf28emeahuhdg9runmzuluq9uj5uek4jk0 on 44'/118'/2'/0/0) #2 js:2:cosmos:cosmos1uty5nf28emeahuhdg9runmzuluq9uj5uek4jk0: 0.380396 ATOM spendable. 

max spendable ~0.3741
★ using mutation 'delegate new validators'
✔️ transaction 
DELEGATE 
TO 
  0.014991 -> cosmosvaloper14kn0kk33szpwus9nh8n87fjel8djx0y070ymmj
  0.171266 -> cosmosvaloper1d0aup392g3enru7eash83sedqclaxvp7fzh6gk
  0.007634 -> cosmosvaloper1ey69r37gfxvxg62sh4r0ktpuc46pzjrm873ae8
  0.002433 -> cosmosvaloper1n3mhyp9fvcmuu8l0q8qvjy07x0rql8q46fe2xk
  0.003646 -> cosmosvaloper1clpqr4nrk4khgkxj78fcwwh6dl3uw4epsluffn
with fees=0.026942
  memo=LedgerLiveBot
STATUS (2317ms)
  amount: 0.19997 ATOM
  estimated fees: 0.026942 ATOM
  total spent: 0.226912 ATOM
✔️ has been signed! (4.9s) 
✔️ broadcasted! (120ms) optimistic operation: 
  -0 ATOM            OUT        CFCC6B3F8BA29AD16B03E2419C5D17B832FD29C042530E53E3851E0F7326BDB5 2022-02-17T11:52
⚠️ Error: could not find optimisticOperation js:2:cosmos:cosmos1uty5nf28emeahuhdg9runmzuluq9uj5uek4jk0:-CFCC6B3F8BA29AD16B03E2419C5D17B832FD29C042530E53E3851E0F7326BDB5-OUT

Error: could not find optimisticOperation js:2:cosmos:cosmos1uty5nf28emeahuhdg9runmzuluq9uj5uek4jk0:-CFCC6B3F8BA29AD16B03E2419C5D17B832FD29C042530E53E3851E0F7326BDB5-OUT
all accounts sync in 1736ms
▬ Cosmos 2.18.0 on nanoS 2.0.0-rc5
→ FROM Cosmos 4: 0.29906 ATOM (4ops) (cosmos1ccemcd8p3r293e5rcv0awaj9hfnn6wmxkz520n on 44'/118'/3'/0/0) #3 js:2:cosmos:cosmos1ccemcd8p3r293e5rcv0awaj9hfnn6wmxkz520n: 0.299061 ATOM spendable. 

max spendable ~0.29281
★ using mutation 'delegate new validators'
✔️ transaction 
DELEGATE 
TO 
  0.01964 -> cosmosvaloper18extdhzzl5c8tr6453e5hzaj3exrdlea90fj3y
with fees=0.008456
  memo=LedgerLiveBot
STATUS (1873ms)
  amount: 0.01964 ATOM
  estimated fees: 0.008456 ATOM
  total spent: 0.028096 ATOM
✔️ has been signed! (2262ms) 
✔️ broadcasted! (121ms) optimistic operation: 
  -0 ATOM            OUT        6C438F12F1E5A85EEF65DC17FF500A2A638872D53F8919922FE9715834ABCB20 2022-02-17T11:52
⚠️ Error: could not find optimisticOperation js:2:cosmos:cosmos1ccemcd8p3r293e5rcv0awaj9hfnn6wmxkz520n:-6C438F12F1E5A85EEF65DC17FF500A2A638872D53F8919922FE9715834ABCB20-OUT

Error: could not find optimisticOperation js:2:cosmos:cosmos1ccemcd8p3r293e5rcv0awaj9hfnn6wmxkz520n:-6C438F12F1E5A85EEF65DC17FF500A2A638872D53F8919922FE9715834ABCB20-OUT
Details of the 4 mutations

Spec Cosmos (7)

Spec Cosmos found 7 Cosmos accounts (preload: 268ms). Will use Cosmos 2.18.0 on nanoS 2.0.0-rc5
(654ms) Cosmos 1: 0.12537 ATOM (10ops) (cosmos1zpvthe3pxvyje7vrcqv2m6qe2qgu0r8gkz64er on 44'/118'/0'/0/0) #0 js:2:cosmos:cosmos1zpvthe3pxvyje7vrcqv2m6qe2qgu0r8gkz64er:
(566ms) Cosmos 2: 0.4594 ATOM (9ops) (cosmos1zd0e8j9g9wur8up7j5aqahz233r4jmvqhyffnv on 44'/118'/1'/0/0) #1 js:2:cosmos:cosmos1zd0e8j9g9wur8up7j5aqahz233r4jmvqhyffnv:
(513ms) Cosmos 3: 0.30234 ATOM (6ops) (cosmos1uty5nf28emeahuhdg9runmzuluq9uj5uek4jk0 on 44'/118'/2'/0/0) #2 js:2:cosmos:cosmos1uty5nf28emeahuhdg9runmzuluq9uj5uek4jk0:
(408ms) Cosmos 4: 0.29906 ATOM (4ops) (cosmos1ccemcd8p3r293e5rcv0awaj9hfnn6wmxkz520n on 44'/118'/3'/0/0) #3 js:2:cosmos:cosmos1ccemcd8p3r293e5rcv0awaj9hfnn6wmxkz520n:
(716ms) Cosmos 5: 0.1038 ATOM (3ops) (cosmos1mvk3fwxgdfac4yjmgl9hdz0555q8gljydzvjtu on 44'/118'/4'/0/0) #4 js:2:cosmos:cosmos1mvk3fwxgdfac4yjmgl9hdz0555q8gljydzvjtu:
(467ms) Cosmos 6: 0.04732 ATOM (1ops) (cosmos1draxuzz0aukggx63m852wm8mlxqpus2009cs97 on 44'/118'/5'/0/0) #5 js:2:cosmos:cosmos1draxuzz0aukggx63m852wm8mlxqpus2009cs97:
(1270ms) Cosmos 7: 0 ATOM (0ops) (cosmos14k7faf4cvxlflta4hytxavx3p7vj6uw69lgf03 on 44'/118'/6'/0/0) #6 js:2:cosmos:cosmos14k7faf4cvxlflta4hytxavx3p7vj6uw69lgf03:
all accounts sync in 1894ms
▬ Cosmos 2.18.0 on nanoS 2.0.0-rc5
→ FROM Cosmos 1: 0.12537 ATOM (10ops) (cosmos1zpvthe3pxvyje7vrcqv2m6qe2qgu0r8gkz64er on 44'/118'/0'/0/0) #0 js:2:cosmos:cosmos1zpvthe3pxvyje7vrcqv2m6qe2qgu0r8gkz64er: (! sum of ops 0.133046 ATOM) 0.125376 ATOM spendable. 

max spendable ~0.11912
★ using mutation 'send some'
→ TO Cosmos 3: 0.30234 ATOM (6ops) (cosmos1uty5nf28emeahuhdg9runmzuluq9uj5uek4jk0 on 44'/118'/2'/0/0) #2 js:2:cosmos:cosmos1uty5nf28emeahuhdg9runmzuluq9uj5uek4jk0:
✔️ transaction 
SEND  0.078047 ATOM
TO cosmos1uty5nf28emeahuhdg9runmzuluq9uj5uek4jk0

with fees=0.004313
  memo=LedgerLiveBot
STATUS (1580ms)
  amount: 0.078047 ATOM
  estimated fees: 0.004313 ATOM
  total spent: 0.08236 ATOM
✔️ has been signed! (2661ms) 
✔️ broadcasted! (195ms) optimistic operation: 
  -0.078047 ATOM     OUT        7E75AC874C2B5B223DEF7F9BC36EC2E9A0449CAC9B45384FA705D1DBD6DAF54B 2022-02-17T11:50
✔️ operation confirmed (10.7s): 
  -0.08236 ATOM      OUT        7E75AC874C2B5B223DEF7F9BC36EC2E9A0449CAC9B45384FA705D1DBD6DAF54B 2022-02-17T11:50
✔️ Cosmos 1: 0.04301 ATOM (11ops) (cosmos1zpvthe3pxvyje7vrcqv2m6qe2qgu0r8gkz64er on 44'/118'/0'/0/0) #0 js:2:cosmos:cosmos1zpvthe3pxvyje7vrcqv2m6qe2qgu0r8gkz64er: (! sum of ops 0.050686 ATOM) 0.043016 ATOM spendable. 

(final state reached in 10.7s)

all accounts sync in 1594ms
▬ Cosmos 2.18.0 on nanoS 2.0.0-rc5
→ FROM Cosmos 2: 0.3243 ATOM (9ops) (cosmos1zd0e8j9g9wur8up7j5aqahz233r4jmvqhyffnv on 44'/118'/1'/0/0) #1 js:2:cosmos:cosmos1zd0e8j9g9wur8up7j5aqahz233r4jmvqhyffnv: (! sum of ops 0.459466 ATOM) 0.207761 ATOM spendable. 0.116603 ATOM delegated. 
DELEGATIONS
  to cosmosvaloper146kwpzhmleafmhtaxulfptyhnvwxzlvm87hwnm 0.01132 ATOM 
  to cosmosvaloper1wlagucxdxvsmvj6330864x8q3vxz4x02rmvmsu 0.061104 ATOM 
  to cosmosvaloper16qme5yxucnaj6snx35nmwze0wyxr8wfgqxsqfw 0.024038 ATOM 
  to cosmosvaloper1rpgtz9pskr5geavkjz02caqmeep7cwwpv73axj 0.012531 ATOM 
  to cosmosvaloper1gjtvly9lel6zskvwtvlg5vhwpu9c9waw7sxzwx 0.00761 ATOM 
  to cosmosvaloper1sxx9mszve0gaedz5ld7qdkjkfv8z992ax69k08 0.004641 ATOM 
  to cosmosvaloper1cgh5ksjwy2sd407lyre4l3uj2fdrqhpkzp06e6 0.025155 ATOM 
  to cosmosvaloper1rcp29q3hpd246n6qak7jluqep4v006cdsc2kkl 0.087313 ATOM 
  to cosmosvaloper1x8rr4hcf54nz6hfckyy2n05sxss54h8wz9puzg 0.017993 ATOM 

max spendable ~0.20151
★ using mutation 'undelegate'
✔️ transaction 
UNDELEGATE 
TO 
  0.01132 -> cosmosvaloper146kwpzhmleafmhtaxulfptyhnvwxzlvm87hwnm
with fees=0.010892
  memo=LedgerLiveBot
STATUS (763ms)
  amount: 0 ATOM
  estimated fees: 0.010892 ATOM
  total spent: 0.010892 ATOM
✔️ has been signed! (2201ms) 
✔️ broadcasted! (125ms) optimistic operation: 
  -0 ATOM            OUT        9CEFBEDD4FD6F0739FE4D6717605423884B2B2284249C0D2C0DBC97F799C5EB8 2022-02-17T11:51
⚠️ Error: could not find optimisticOperation js:2:cosmos:cosmos1zd0e8j9g9wur8up7j5aqahz233r4jmvqhyffnv:-9CEFBEDD4FD6F0739FE4D6717605423884B2B2284249C0D2C0DBC97F799C5EB8-OUT

all accounts sync in 1587ms
▬ Cosmos 2.18.0 on nanoS 2.0.0-rc5
→ FROM Cosmos 3: 0.3803 ATOM (7ops) (cosmos1uty5nf28emeahuhdg9runmzuluq9uj5uek4jk0 on 44'/118'/2'/0/0) #2 js:2:cosmos:cosmos1uty5nf28emeahuhdg9runmzuluq9uj5uek4jk0: 0.380396 ATOM spendable. 

max spendable ~0.3741
★ using mutation 'delegate new validators'
✔️ transaction 
DELEGATE 
TO 
  0.014991 -> cosmosvaloper14kn0kk33szpwus9nh8n87fjel8djx0y070ymmj
  0.171266 -> cosmosvaloper1d0aup392g3enru7eash83sedqclaxvp7fzh6gk
  0.007634 -> cosmosvaloper1ey69r37gfxvxg62sh4r0ktpuc46pzjrm873ae8
  0.002433 -> cosmosvaloper1n3mhyp9fvcmuu8l0q8qvjy07x0rql8q46fe2xk
  0.003646 -> cosmosvaloper1clpqr4nrk4khgkxj78fcwwh6dl3uw4epsluffn
with fees=0.026942
  memo=LedgerLiveBot
STATUS (2317ms)
  amount: 0.19997 ATOM
  estimated fees: 0.026942 ATOM
  total spent: 0.226912 ATOM
✔️ has been signed! (4.9s) 
✔️ broadcasted! (120ms) optimistic operation: 
  -0 ATOM            OUT        CFCC6B3F8BA29AD16B03E2419C5D17B832FD29C042530E53E3851E0F7326BDB5 2022-02-17T11:52
⚠️ Error: could not find optimisticOperation js:2:cosmos:cosmos1uty5nf28emeahuhdg9runmzuluq9uj5uek4jk0:-CFCC6B3F8BA29AD16B03E2419C5D17B832FD29C042530E53E3851E0F7326BDB5-OUT

all accounts sync in 1736ms
▬ Cosmos 2.18.0 on nanoS 2.0.0-rc5
→ FROM Cosmos 4: 0.29906 ATOM (4ops) (cosmos1ccemcd8p3r293e5rcv0awaj9hfnn6wmxkz520n on 44'/118'/3'/0/0) #3 js:2:cosmos:cosmos1ccemcd8p3r293e5rcv0awaj9hfnn6wmxkz520n: 0.299061 ATOM spendable. 

max spendable ~0.29281
★ using mutation 'delegate new validators'
✔️ transaction 
DELEGATE 
TO 
  0.01964 -> cosmosvaloper18extdhzzl5c8tr6453e5hzaj3exrdlea90fj3y
with fees=0.008456
  memo=LedgerLiveBot
STATUS (1873ms)
  amount: 0.01964 ATOM
  estimated fees: 0.008456 ATOM
  total spent: 0.028096 ATOM
✔️ has been signed! (2262ms) 
✔️ broadcasted! (121ms) optimistic operation: 
  -0 ATOM            OUT        6C438F12F1E5A85EEF65DC17FF500A2A638872D53F8919922FE9715834ABCB20 2022-02-17T11:52
⚠️ Error: could not find optimisticOperation js:2:cosmos:cosmos1ccemcd8p3r293e5rcv0awaj9hfnn6wmxkz520n:-6C438F12F1E5A85EEF65DC17FF500A2A638872D53F8919922FE9715834ABCB20-OUT


Details of the 3 uncovered mutations

Spec Cosmos (3)

  • send max: balance is too low (3)
  • redelegate: balance is too low (3)
  • claim rewards: balance is too low (3)

Portfolio ($37.76)

Details of the 1 currencies
Spec (accounts) Operations Balance funds?
Cosmos (6) 39 (+6) 1.0856 ATOM (- 0.27012) ($37.76) ⚠️ cosmos1zpvthe3pxvyje7vrcqv2m6qe2qgu0r8gkz64er

Please sign in to comment.