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

Cosmos JS #1721

Merged
46 commits merged into from Feb 21, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
46 commits
Select commit Hold shift + click to select a range
9ff6edc
increase gas amplifier
alexalouit Jan 31, 2022
bb1888b
fix payload construction
alexalouit Jan 31, 2022
92f4d59
More accurate gas amplifier
alexalouit Jan 31, 2022
f29a4ae
increase gas amplifier
alexalouit Jan 31, 2022
957a48f
use same node for calculation and broadcast
alexalouit Jan 31, 2022
b120a76
fix amount payload
alexalouit Jan 31, 2022
dd45d6d
Merge remote-tracking branch 'upstream/cosmos-js' into cosmos-js
alexalouit Jan 31, 2022
aaa9494
fix fees/gas calculation
alexalouit Jan 31, 2022
67a4414
fix signature
alexalouit Feb 1, 2022
510c1e9
Merge remote-tracking branch 'upstream/cosmos-js' into cosmos-js
alexalouit Feb 1, 2022
0594ce0
Merge remote-tracking branch 'upstream/cosmos-js' into cosmos-js
alexalouit Feb 3, 2022
75bd779
fix fees regression
alexalouit Feb 3, 2022
fff173f
Merge remote-tracking branch 'upstream/cosmos-js' into cosmos-js
alexalouit Feb 3, 2022
014b551
More accurate pubkey selection
alexalouit Feb 3, 2022
bed90f0
don't use extra.tx_bytes
alexalouit Feb 3, 2022
4faf89d
fix pubkey selection
alexalouit Feb 3, 2022
a49d4ff
simplify hex serialization
alexalouit Feb 4, 2022
e8ad8f3
update transaction: more strict types
alexalouit Feb 10, 2022
a03fd8f
many things
alexalouit Feb 10, 2022
27947b3
accuracy
alexalouit Feb 10, 2022
1ea1afe
remove useless isPreValidation
alexalouit Feb 10, 2022
f941d07
fix strange edge effect of ledger live desktop
alexalouit Feb 10, 2022
cda9bc1
Update xpub during sync
alexalouit Feb 14, 2022
d65266d
temporary enable log for bot
alexalouit Feb 14, 2022
1c62e0c
Merge remote-tracking branch 'upstream/cosmos-js' into cosmos-js
alexalouit Feb 14, 2022
8df4111
LL-9159 cosmos node
alexalouit Feb 16, 2022
804fccd
Update js-signOperation.ts
alexalouit Feb 16, 2022
35ecf59
fix signature
alexalouit Feb 16, 2022
f45276e
Merge remote-tracking branch 'upstream/cosmos-js' into cosmos-js
alexalouit Feb 17, 2022
99dc488
fix redelegate payload
alexalouit Feb 17, 2022
1800f02
fix payload send transaction when sendmax
alexalouit Feb 17, 2022
3aca833
fix optimistic operation type
alexalouit Feb 18, 2022
e22a144
Merge remote-tracking branch 'upstream/cosmos-js' into cosmos-js
alexalouit Feb 18, 2022
e7fd38b
fix typo
alexalouit Feb 18, 2022
c7a0e69
bugfix
alexalouit Feb 18, 2022
b64368e
fix regression
alexalouit Feb 18, 2022
523f73f
Merge remote-tracking branch 'upstream/cosmos-js' into cosmos-js
alexalouit Feb 18, 2022
992193f
update optimistic operation
alexalouit Feb 18, 2022
e81b5d3
Merge remote-tracking branch 'upstream/cosmos-js' into cosmos-js
alexalouit Feb 18, 2022
71ea6f8
fix prettier
alexalouit Feb 18, 2022
e0f4fce
more deterministic transaction parsing
alexalouit Feb 18, 2022
96591a7
Merge remote-tracking branch 'upstream/cosmos-js' into cosmos-js
alexalouit Feb 18, 2022
0d409ca
clarify code readable
alexalouit Feb 18, 2022
2823fcd
adjust sender and recipient
alexalouit Feb 18, 2022
fd3f0aa
fix fees when is ibc transaction
alexalouit Feb 18, 2022
6685baa
fix redelegations data mapping
alexalouit Feb 19, 2022
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 5 additions & 5 deletions src/families/cosmos/api/Cosmos.ts
Original file line number Diff line number Diff line change
Expand Up @@ -143,12 +143,12 @@ export const getRedelegations = async (address: string): Promise<any> => {
});

data.redelegation_responses.forEach((elem) => {
elem.entries.forEach((entries) => {
elem.entries.forEach((entry) => {
redelegations.push({
validatorSrcAddress: elem.validator_src_address,
validatorDstAddress: elem.validator_dst_address,
amount: new BigNumber(entries.initial_balance),
completionDate: new Date(entries.completion_time),
validatorSrcAddress: elem.redelegation.validator_src_address,
validatorDstAddress: elem.redelegation.validator_dst_address,
amount: new BigNumber(entry.redelegation_entry.initial_balance),
completionDate: new Date(entry.redelegation_entry.completion_time),
});
});
});
Expand Down
29 changes: 21 additions & 8 deletions src/families/cosmos/js-signOperation.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,9 @@
import { Account, Operation, OperationType, SignOperationEvent } from "../../types";
import {
Account,
Operation,
OperationType,
SignOperationEvent,
} from "../../types";
import type { Transaction } from "./types";
import { getAccount, getChainId } from "./api/Cosmos";
import { Observable } from "rxjs";
Expand Down Expand Up @@ -145,7 +150,7 @@ const signOperation = ({

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

const txHash = ""; // resolved at broadcast time
const hash = ""; // resolved at broadcast time
const accountId = account.id;
const type: OperationType =
transaction.mode === "undelegate"
Expand All @@ -158,19 +163,27 @@ const signOperation = ({
? "REWARD"
: "OUT";

const senders = [] as any;
const recipients = [] as any;
This conversation was marked as resolved.
Show resolved Hide resolved

if (type === "OUT") {
senders.push(account.freshAddress);
recipients.push(transaction.recipient);
}

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

Expand Down
105 changes: 68 additions & 37 deletions src/families/cosmos/js-synchronisation.ts
Original file line number Diff line number Diff line change
Expand Up @@ -42,56 +42,87 @@ const txToOps = (info: any, id: string, txs: any): Operation[] => {
// https://docs.cosmos.network/v0.42/modules/staking/07_events.html
switch (message.type) {
case "transfer":
op.senders.push(attributes["sender"]);
op.recipients.push(attributes["recipient"]);

op.value = op.value.plus(
attributes["amount"].replace(currency.units[1].code, "")
);

if (attributes["sender"] === address) {
op.type = "OUT";
op.value = op.value.plus(fees);
} else if (attributes["recipient"] === address) {
op.type = "IN";
if (
attributes["sender"] &&
attributes["recipient"] &&
attributes["amount"]
) {
op.senders.push(attributes["sender"]);
op.recipients.push(attributes["recipient"]);

if (attributes["amount"].indexOf(currency.units[1].code) != -1) {
op.value = op.value.plus(
attributes["amount"].replace(currency.units[1].code, "")
);
}

if (attributes["sender"] === address) {
op.type = "OUT";
op.value = op.value.plus(fees);
} else if (attributes["recipient"] === address) {
op.type = "IN";
}
}
break;

case "withdraw_rewards":
op.type = "REWARD";
op.value = new BigNumber(fees);
op.extra.validators.push({
amount: attributes["amount"].replace(currency.units[1].code, ""),
address: attributes.validator,
});
if (
attributes["amount"] &&
attributes["amount"].indexOf(currency.units[1].code) != -1
) {
op.type = "REWARD";
op.value = new BigNumber(fees);
op.extra.validators.push({
amount: attributes["amount"].replace(currency.units[1].code, ""),
address: attributes.validator,
});
}
break;

case "delegate":
op.type = "DELEGATE";
op.value = new BigNumber(fees);
op.extra.validators.push({
amount: attributes["amount"].replace(currency.units[1].code, ""),
address: attributes.validator,
});
if (
attributes["amount"] &&
attributes["amount"].indexOf(currency.units[1].code) != -1
) {
op.type = "DELEGATE";
op.value = new BigNumber(fees);
op.extra.validators.push({
amount: attributes["amount"].replace(currency.units[1].code, ""),
address: attributes.validator,
});
}
break;

case "redelegate":
op.type = "REDELEGATE";
op.value = new BigNumber(fees);
op.extra.validators.push({
amount: attributes["amount"].replace(currency.units[1].code, ""),
address: attributes.destination_validator,
});
op.extra.cosmosSourceValidator = attributes.source_validator;
if (
attributes["amount"] &&
attributes["amount"].indexOf(currency.units[1].code) != -1 &&
attributes.destination_validator &&
attributes.source_validator
This conversation was marked as resolved.
Show resolved Hide resolved
) {
op.type = "REDELEGATE";
op.value = new BigNumber(fees);
op.extra.validators.push({
amount: attributes["amount"].replace(currency.units[1].code, ""),
address: attributes.destination_validator,
});
op.extra.cosmosSourceValidator = attributes.source_validator;
}
break;

case "unbond":
op.type = "UNDELEGATE";
op.value = new BigNumber(fees);
op.extra.validators.push({
amount: attributes["amount"].replace(currency.units[1].code, ""),
address: attributes.validator,
});
if (
attributes["amount"] &&
attributes["amount"].indexOf(currency.units[1].code) != -1 &&
attributes.validator
) {
op.type = "UNDELEGATE";
op.value = new BigNumber(fees);
op.extra.validators.push({
amount: attributes["amount"].replace(currency.units[1].code, ""),
address: attributes.validator,
});
}
break;
}
});
Expand Down