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

Commit

Permalink
Cosmos JS (#1746)
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

* fix regression

* update optimistic operation

fix regression
add operation type
more consistent fee

* fix prettier

* more deterministic transaction parsing

* clarify code readable

* adjust sender and recipient

* fix fees when is ibc transaction

* fix redelegations data mapping

* fix mixed styles

* fix array cast type

* fix more determinist operation data

* fix could not find optimisticOperation in redelegate transaction

* restore getStargateRewardsState methode

* amount of the operation more close

* return transaction in prepareTransaction

* keep immutable paradigm for prepareTransaction

* fix amount update in prepareTransaction

* fix amount control to be more specific

* fix BigNumber compare

Co-authored-by: Alexandre Alouit <[email protected]>
  • Loading branch information
wa-aal and alexalouit authored Feb 25, 2022
1 parent 1808ef4 commit 5d663f0
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 8 deletions.
10 changes: 5 additions & 5 deletions src/families/cosmos/js-buildTransaction.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ const buildTransaction = async (

switch (transaction.mode) {
case "send":
if (!transaction.recipient || !transaction.amount) {
if (!transaction.recipient || transaction.amount.lte(0)) {
isComplete = false;
} else {
msg.push({
Expand All @@ -39,7 +39,7 @@ const buildTransaction = async (
isComplete = false;
} else {
transaction.validators.forEach((validator) => {
if (!validator.address || !validator.amount) {
if (!validator.address || validator.amount.lte(0)) {
isComplete = false;
}

Expand All @@ -63,7 +63,7 @@ const buildTransaction = async (
!transaction.validators ||
transaction.validators.length < 1 ||
!transaction.validators[0].address ||
!transaction.validators[0].amount
transaction.validators[0].amount.lte(0)
) {
isComplete = false;
} else {
Expand All @@ -87,7 +87,7 @@ const buildTransaction = async (
!transaction.validators ||
transaction.validators.length < 1 ||
!transaction.validators[0].address ||
!transaction.validators[0].amount
transaction.validators[0].amount.lte(0)
) {
isComplete = false;
} else {
Expand Down Expand Up @@ -129,7 +129,7 @@ const buildTransaction = async (
!transaction.validators ||
transaction.validators.length < 1 ||
!transaction.validators[0].address ||
!transaction.validators[0].amount
transaction.validators[0].amount.lte(0)
) {
isComplete = false;
} else {
Expand Down
7 changes: 4 additions & 3 deletions src/families/cosmos/js-prepareTransaction.ts
Original file line number Diff line number Diff line change
Expand Up @@ -120,10 +120,11 @@ const prepareTransaction = async (

if (
transaction.memo !== memo ||
transaction.fees !== fees ||
transaction.gas !== gas
!fees.eq(transaction.fees || new BigNumber(0)) ||
!gas.eq(transaction.gas || new BigNumber(0)) ||
!amount.eq(transaction.amount)
) {
return { ...transaction, memo, fees, gas };
return { ...transaction, memo, fees, gas, amount };
}

return transaction;
Expand Down

2 comments on commit 5d663f0

@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 ($35.00) for Bot 'Cosmos JS via Mère Denis'

⚠️ 6 mutations uncovered

1 critical spec errors

Spec Cosmos failed!

TypeError: Cannot read property 'negated' of undefined
Details of the 0 mutations

Spec Cosmos (2)

Spec Cosmos found 32 Cosmos accounts (preload: 1132ms). Will use Cosmos 2.18.0 on nanoS 2.0.0
(484ms) Cosmos 1: 0 ATOM (2ops) (cosmos14dwalys86ce67uycgsafgyxre8k39ux8lmw2nx on 44'/118'/0'/0/0) #0 js:2:cosmos:cosmos14dwalys86ce67uycgsafgyxre8k39ux8lmw2nx:
(513ms) Cosmos 2: 0.04364 ATOM (3ops) (cosmos1t4ughg9wcdzpsjyqr4lwd4385kvtnrv2xdtvhd on 44'/118'/1'/0/0) #1 js:2:cosmos:cosmos1t4ughg9wcdzpsjyqr4lwd4385kvtnrv2xdtvhd:
(545ms) Cosmos 3: 0.11631 ATOM (5ops) (cosmos1q3mj9faedpm7w0dc8lv66r7hm7xax8xmvxmh72 on 44'/118'/2'/0/0) #2 js:2:cosmos:cosmos1q3mj9faedpm7w0dc8lv66r7hm7xax8xmvxmh72:
(399ms) Cosmos 4: 0.1 ATOM (1ops) (cosmos1xudmy2ysmd6sha9talmwf6pj0clmp8lqlhgzks on 44'/118'/3'/0/0) #3 js:2:cosmos:cosmos1xudmy2ysmd6sha9talmwf6pj0clmp8lqlhgzks:
(489ms) Cosmos 5: 0.20323 ATOM (3ops) (cosmos1ua6szru8en6k7e6r89w22j3ecnukq52unmt3qd on 44'/118'/4'/0/0) #4 js:2:cosmos:cosmos1ua6szru8en6k7e6r89w22j3ecnukq52unmt3qd:
(330ms) Cosmos 6: 0 ATOM (1ops) (cosmos18y8q0ppsfkl0v4u02jjf3pr9t22qzqytzpyvfj on 44'/118'/5'/0/0) #5 js:2:cosmos:cosmos18y8q0ppsfkl0v4u02jjf3pr9t22qzqytzpyvfj:
(384ms) Cosmos 7: 0.03705 ATOM (2ops) (cosmos1exk40md6pzr9rjmrw6e8ndskszg3krjhvsqqfd on 44'/118'/6'/0/0) #6 js:2:cosmos:cosmos1exk40md6pzr9rjmrw6e8ndskszg3krjhvsqqfd:
(756ms) Cosmos 8: 0.020678 ATOM (1ops) (cosmos13wl4gggk60gk36ws2rsdsgdtmkz3xnua656c76 on 44'/118'/7'/0/0) #7 js:2:cosmos:cosmos13wl4gggk60gk36ws2rsdsgdtmkz3xnua656c76:
(391ms) Cosmos 9: 0.11315 ATOM (1ops) (cosmos1fz5fqcrg597clssa08lj3x7nlzdxa7hk40596r on 44'/118'/8'/0/0) #8 js:2:cosmos:cosmos1fz5fqcrg597clssa08lj3x7nlzdxa7hk40596r:
(352ms) Cosmos 10: 0.016215 ATOM (2ops) (cosmos1mr7cpce7xl8rt2eauljptk48pxvs6fwvak88xw on 44'/118'/9'/0/0) #9 js:2:cosmos:cosmos1mr7cpce7xl8rt2eauljptk48pxvs6fwvak88xw:
(386ms) Cosmos 11: 0.05335 ATOM (0ops) (cosmos1wwpv0nehnkf039lt40rnflpt9c347mwyrv28ys on 44'/118'/10'/0/0) #10 js:2:cosmos:cosmos1wwpv0nehnkf039lt40rnflpt9c347mwyrv28ys:
(451ms) Cosmos 12: 0.03639 ATOM (1ops) (cosmos1m6sf5rh2rsx5uu66gegek7s0dkqul65qtaqtav on 44'/118'/11'/0/0) #11 js:2:cosmos:cosmos1m6sf5rh2rsx5uu66gegek7s0dkqul65qtaqtav:
(472ms) Cosmos 13: 0 ATOM (7ops) (cosmos1849p2yy69ye64w66a43yaehv5dpu5xrlqlxddq on 44'/118'/12'/0/0) #12 js:2:cosmos:cosmos1849p2yy69ye64w66a43yaehv5dpu5xrlqlxddq:
(759ms) Cosmos 14: 0.15016 ATOM (3ops) (cosmos1n3w0gm0edtqat0m9790d7zuqmfvzf2xjrg9s3n on 44'/118'/13'/0/0) #13 js:2:cosmos:cosmos1n3w0gm0edtqat0m9790d7zuqmfvzf2xjrg9s3n:
(726ms) Cosmos 15: 0.03345 ATOM (5ops) (cosmos1h0hawcqv7p0gs72p3xv58rkjk83g9eq09zxera on 44'/118'/14'/0/0) #14 js:2:cosmos:cosmos1h0hawcqv7p0gs72p3xv58rkjk83g9eq09zxera:
(755ms) Cosmos 16: 0.05188 ATOM (2ops) (cosmos1jxa3txa9m4zudlp8sthyqm8up2vg48qgm2wt06 on 44'/118'/15'/0/0) #15 js:2:cosmos:cosmos1jxa3txa9m4zudlp8sthyqm8up2vg48qgm2wt06:
(777ms) Cosmos 17: 0 ATOM (4ops) (cosmos1njrejn90tzrvkrs3lc4a5e9gt3qjm8c68lgk84 on 44'/118'/16'/0/0) #16 js:2:cosmos:cosmos1njrejn90tzrvkrs3lc4a5e9gt3qjm8c68lgk84:
(403ms) Cosmos 18: 0 ATOM (3ops) (cosmos1wjqdz024687y0293xs30h3e56cafrr8trtm3ta on 44'/118'/17'/0/0) #17 js:2:cosmos:cosmos1wjqdz024687y0293xs30h3e56cafrr8trtm3ta:
(494ms) Cosmos 19: 0.006541 ATOM (5ops) (cosmos1p42xh2crjttyf59cgnky2sx66e7meqn43twuk8 on 44'/118'/18'/0/0) #18 js:2:cosmos:cosmos1p42xh2crjttyf59cgnky2sx66e7meqn43twuk8:
(408ms) Cosmos 20: 0.04263 ATOM (1ops) (cosmos10kq4g879aj5set6m8x9xryzgh423cnsrnv9p4s on 44'/118'/19'/0/0) #19 js:2:cosmos:cosmos10kq4g879aj5set6m8x9xryzgh423cnsrnv9p4s:
(426ms) Cosmos 21: 0.004765 ATOM (6ops) (cosmos1q7gw4agv7rsv2g047usa4aw08jmp8ysdt4h8v3 on 44'/118'/20'/0/0) #20 js:2:cosmos:cosmos1q7gw4agv7rsv2g047usa4aw08jmp8ysdt4h8v3:
(611ms) Cosmos 22: 0.04237 ATOM (0ops) (cosmos1uswzp7lrgyyy72aps7j30wj9mfh496qje3klup on 44'/118'/21'/0/0) #21 js:2:cosmos:cosmos1uswzp7lrgyyy72aps7j30wj9mfh496qje3klup:
(560ms) Cosmos 23: 0.03295 ATOM (9ops) (cosmos1lrmywr7vn32s4vsgvpe8avrtt90mql64sum0yt on 44'/118'/22'/0/0) #22 js:2:cosmos:cosmos1lrmywr7vn32s4vsgvpe8avrtt90mql64sum0yt:
(523ms) Cosmos 24: 0.018031 ATOM (8ops) (cosmos1xpum29lu0f9uhjar0226g35yst8jl0zcqrrr8j on 44'/118'/23'/0/0) #23 js:2:cosmos:cosmos1xpum29lu0f9uhjar0226g35yst8jl0zcqrrr8j:
(325ms) Cosmos 25: 0 ATOM (2ops) (cosmos1anpplwtuygcws2edsjljr3lpn907v5p0u3x5fc on 44'/118'/24'/0/0) #24 js:2:cosmos:cosmos1anpplwtuygcws2edsjljr3lpn907v5p0u3x5fc:
(601ms) Cosmos 26: 0.09107 ATOM (8ops) (cosmos1xs84an4wt4m36x6p29qpq47q9c6xpuf7vzc9v8 on 44'/118'/25'/0/0) #25 js:2:cosmos:cosmos1xs84an4wt4m36x6p29qpq47q9c6xpuf7vzc9v8:
(804ms) Cosmos 27: 0 ATOM (1ops) (cosmos12na0h3qyyjnlmyrragpg4njl99laee8u6ltzz8 on 44'/118'/26'/0/0) #26 js:2:cosmos:cosmos12na0h3qyyjnlmyrragpg4njl99laee8u6ltzz8:
(474ms) Cosmos 28: 0.05306 ATOM (5ops) (cosmos1tf0hmrcp67jxxvhh5tcp08ncg3zpmkzuun56at on 44'/118'/27'/0/0) #27 js:2:cosmos:cosmos1tf0hmrcp67jxxvhh5tcp08ncg3zpmkzuun56at:
(392ms) Cosmos 29: 0 ATOM (6ops) (cosmos1nacea6hdwm3d5uyagj9xz7u2gwumngdpfjw9e5 on 44'/118'/28'/0/0) #28 js:2:cosmos:cosmos1nacea6hdwm3d5uyagj9xz7u2gwumngdpfjw9e5:
(342ms) Cosmos 30: 0.002555 ATOM (0ops) (cosmos1tslqapwqwgcz0dmmsztl0mup9935rkjqgk37pq on 44'/118'/29'/0/0) #29 js:2:cosmos:cosmos1tslqapwqwgcz0dmmsztl0mup9935rkjqgk37pq:
(421ms) Cosmos 31: 0 ATOM (2ops) (cosmos1vmrfvhvv869vfamzs58vcnrq756ctchhfc4ne9 on 44'/118'/30'/0/0) #30 js:2:cosmos:cosmos1vmrfvhvv869vfamzs58vcnrq756ctchhfc4ne9:
(1393ms) Cosmos 32: 0 ATOM (0ops) (cosmos1f8ra0xfr6rthmw95kpayexcesn6dwm76m5npf0 on 44'/118'/31'/0/0) #31 js:2:cosmos:cosmos1f8ra0xfr6rthmw95kpayexcesn6dwm76m5npf0:

Details of the 6 uncovered mutations

Spec Cosmos (6)

  • send some: balance is too low (2)
  • send max: balance is too low (2)
  • delegate new validators: balance is too low (2)
  • undelegate: balance is too low (2)
  • redelegate: balance is too low (2)
  • claim rewards: balance is too low (2)

Portfolio ($35.00)

Details of the 1 currencies
Spec (accounts) Operations Balance funds?
Cosmos (31) 99 0.4046 ATOM ($35.00) ❌ cosmos14dwalys86ce67uycgsafgyxre8k39ux8lmw2nx

@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 ⚠️ 1 specs ($44.96) for Bot 'Cosmos JS'

⚠️ 5 mutations uncovered

1 critical spec errors

Spec Cosmos failed!

TypeError: Cannot read property 'negated' of undefined
Details of the 1 mutations

Spec Cosmos (7)

Spec Cosmos found 20 Cosmos accounts (preload: 1787ms). Will use Cosmos 2.18.0 on nanoS 2.0.0
(723ms) Cosmos 1: 0.03451 ATOM (44ops) (cosmos1zpvthe3pxvyje7vrcqv2m6qe2qgu0r8gkz64er on 44'/118'/0'/0/0) #0 js:2:cosmos:cosmos1zpvthe3pxvyje7vrcqv2m6qe2qgu0r8gkz64er:
(786ms) Cosmos 2: 0.25982 ATOM (51ops) (cosmos1zd0e8j9g9wur8up7j5aqahz233r4jmvqhyffnv on 44'/118'/1'/0/0) #1 js:2:cosmos:cosmos1zd0e8j9g9wur8up7j5aqahz233r4jmvqhyffnv:
(972ms) Cosmos 3: 0.30291 ATOM (41ops) (cosmos1uty5nf28emeahuhdg9runmzuluq9uj5uek4jk0 on 44'/118'/2'/0/0) #2 js:2:cosmos:cosmos1uty5nf28emeahuhdg9runmzuluq9uj5uek4jk0:
(787ms) Cosmos 4: 0.06887 ATOM (39ops) (cosmos1ccemcd8p3r293e5rcv0awaj9hfnn6wmxkz520n on 44'/118'/3'/0/0) #3 js:2:cosmos:cosmos1ccemcd8p3r293e5rcv0awaj9hfnn6wmxkz520n:
(700ms) Cosmos 5: 0.0913 ATOM (39ops) (cosmos1mvk3fwxgdfac4yjmgl9hdz0555q8gljydzvjtu on 44'/118'/4'/0/0) #4 js:2:cosmos:cosmos1mvk3fwxgdfac4yjmgl9hdz0555q8gljydzvjtu:
(1308ms) Cosmos 6: 0.05578 ATOM (32ops) (cosmos1draxuzz0aukggx63m852wm8mlxqpus2009cs97 on 44'/118'/5'/0/0) #5 js:2:cosmos:cosmos1draxuzz0aukggx63m852wm8mlxqpus2009cs97:
(702ms) Cosmos 7: 0.07142 ATOM (30ops) (cosmos14k7faf4cvxlflta4hytxavx3p7vj6uw69lgf03 on 44'/118'/6'/0/0) #6 js:2:cosmos:cosmos14k7faf4cvxlflta4hytxavx3p7vj6uw69lgf03:
(576ms) Cosmos 8: 0.29964 ATOM (44ops) (cosmos12uwsw42ec4lh75202zcp0r5ggj9vlwp4c05ydz on 44'/118'/7'/0/0) #7 js:2:cosmos:cosmos12uwsw42ec4lh75202zcp0r5ggj9vlwp4c05ydz:
(755ms) Cosmos 9: 0.06007 ATOM (25ops) (cosmos1pggp9ffssaf8hdev9aekcafarxnuxmz4er44hm on 44'/118'/8'/0/0) #8 js:2:cosmos:cosmos1pggp9ffssaf8hdev9aekcafarxnuxmz4er44hm:
(618ms) Cosmos 10: 0.0955 ATOM (35ops) (cosmos1cnr3madhjge7s3lpz52qdcay69llm6uwx3s8y3 on 44'/118'/9'/0/0) #9 js:2:cosmos:cosmos1cnr3madhjge7s3lpz52qdcay69llm6uwx3s8y3:
(531ms) Cosmos 11: 0.04336 ATOM (23ops) (cosmos1gyqj09h2yc0hs4ggwy74qca8t4hl6ns35w92l5 on 44'/118'/10'/0/0) #10 js:2:cosmos:cosmos1gyqj09h2yc0hs4ggwy74qca8t4hl6ns35w92l5:
(502ms) Cosmos 12: 0.07054 ATOM (31ops) (cosmos1zkx8vmvzfz6ah8les5y62rxmvdrk4egvcfzfcu on 44'/118'/11'/0/0) #11 js:2:cosmos:cosmos1zkx8vmvzfz6ah8les5y62rxmvdrk4egvcfzfcu:
(517ms) Cosmos 13: 0.023944 ATOM (13ops) (cosmos19y63dxgjvuj46hcgrt0w0rpct85d3sfxgmlgpa on 44'/118'/12'/0/0) #12 js:2:cosmos:cosmos19y63dxgjvuj46hcgrt0w0rpct85d3sfxgmlgpa:
(476ms) Cosmos 14: 0.04729 ATOM (18ops) (cosmos19fm3nalhxtswpn78ng2rl4vs7p04vljgfeq2qs on 44'/118'/13'/0/0) #13 js:2:cosmos:cosmos19fm3nalhxtswpn78ng2rl4vs7p04vljgfeq2qs:
(501ms) Cosmos 15: 0.04307 ATOM (12ops) (cosmos14ps228paxvqngcz6adj0d98f4qftkl68atrvjw on 44'/118'/14'/0/0) #14 js:2:cosmos:cosmos14ps228paxvqngcz6adj0d98f4qftkl68atrvjw:
(461ms) Cosmos 16: 0.10173 ATOM (13ops) (cosmos17wd40x799cjhh84zsz38tlqw4nefpcfwahp87t on 44'/118'/15'/0/0) #15 js:2:cosmos:cosmos17wd40x799cjhh84zsz38tlqw4nefpcfwahp87t:
(468ms) Cosmos 17: 0.04855 ATOM (6ops) (cosmos19u92aw048hh6ggw0jxrhl8npy9dk8mchas5lqk on 44'/118'/16'/0/0) #16 js:2:cosmos:cosmos19u92aw048hh6ggw0jxrhl8npy9dk8mchas5lqk:
(784ms) Cosmos 18: 0.05717 ATOM (12ops) (cosmos19xyjhr494jvemvh2jhq3ws4kpc3c9h6r2zlnmr on 44'/118'/17'/0/0) #17 js:2:cosmos:cosmos19xyjhr494jvemvh2jhq3ws4kpc3c9h6r2zlnmr:
(628ms) Cosmos 19: 0.13736 ATOM (4ops) (cosmos1r0ra6y8vveagmrrs5d8zzkgydhjvyfe6728vq2 on 44'/118'/18'/0/0) #18 js:2:cosmos:cosmos1r0ra6y8vveagmrrs5d8zzkgydhjvyfe6728vq2:
(1275ms) Cosmos 20: 0 ATOM (0ops) (cosmos1zqv0kyf5muqsk2z50j3msxaul00ldunvvp9aym on 44'/118'/19'/0/0) #19 js:2:cosmos:cosmos1zqv0kyf5muqsk2z50j3msxaul00ldunvvp9aym:
all accounts sync in 4.1s
▬ Cosmos 2.18.0 on nanoS 2.0.0
→ FROM Cosmos 5: 0.0913 ATOM (39ops) (cosmos1mvk3fwxgdfac4yjmgl9hdz0555q8gljydzvjtu on 44'/118'/4'/0/0) #4 js:2:cosmos:cosmos1mvk3fwxgdfac4yjmgl9hdz0555q8gljydzvjtu: 0.091301 ATOM spendable. 

max spendable ~0.08649
★ using mutation 'send some'
→ TO Cosmos 2: 0.25982 ATOM (51ops) (cosmos1zd0e8j9g9wur8up7j5aqahz233r4jmvqhyffnv on 44'/118'/1'/0/0) #1 js:2:cosmos:cosmos1zd0e8j9g9wur8up7j5aqahz233r4jmvqhyffnv:
✔️ transaction 
SEND  0.02889 ATOM
TO cosmos1zd0e8j9g9wur8up7j5aqahz233r4jmvqhyffnv

with fees=0.004298
STATUS (1078ms)
  amount: 0.02889 ATOM
  estimated fees: 0.004298 ATOM
  total spent: 0.033188 ATOM
✔️ has been signed! (2442ms) 
✔️ broadcasted! (186ms) optimistic operation: 
  -0.033188 ATOM     OUT        926BC489693B2384C526B92798446D26D7D0B9D3D24E4AAB7A344022A0B81BC7 2022-02-25T15:40
✔️ operation confirmed (5.7s): 
  -0.033188 ATOM     OUT        926BC489693B2384C526B92798446D26D7D0B9D3D24E4AAB7A344022A0B81BC7 2022-02-25T15:40
✔️ Cosmos 5: 0.05811 ATOM (40ops) (cosmos1mvk3fwxgdfac4yjmgl9hdz0555q8gljydzvjtu on 44'/118'/4'/0/0) #4 js:2:cosmos:cosmos1mvk3fwxgdfac4yjmgl9hdz0555q8gljydzvjtu: 0.058113 ATOM spendable. 

(final state reached in 5.7s)


Details of the 5 uncovered mutations

Spec Cosmos (5)

  • send max: balance is too low (6)
  • delegate new validators: balance is too low (6)
  • undelegate: balance is too low (6)
  • redelegate: balance is too low (6)
  • claim rewards: balance is too low (6)

Portfolio ($44.96)

Details of the 1 currencies
Spec (accounts) Operations Balance funds?
Cosmos (19) 514 (+2) 1.2108 ATOM (- 0.004298) ($44.96) 👍 cosmos1zpvthe3pxvyje7vrcqv2m6qe2qgu0r8gkz64er

Please sign in to comment.