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

Cosmos JS #1743

Merged
merged 58 commits into from Feb 25, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
58 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
892148b
fix mixed styles
alexalouit Feb 21, 2022
7446337
fix array cast type
alexalouit Feb 21, 2022
d0819d0
Merge remote-tracking branch 'upstream/cosmos-js' into cosmos-js
alexalouit Feb 21, 2022
890c0d4
fix more determinist operation data
alexalouit Feb 21, 2022
289ef6d
fix could not find optimisticOperation in redelegate transaction
alexalouit Feb 22, 2022
6121e72
Merge remote-tracking branch 'upstream/cosmos-js' into cosmos-js
alexalouit Feb 22, 2022
c113968
restore getStargateRewardsState methode
alexalouit Feb 22, 2022
6c72c62
Merge remote-tracking branch 'upstream/cosmos-js' into cosmos-js
alexalouit Feb 22, 2022
c3e6853
amount of the operation more close
alexalouit Feb 25, 2022
6631073
return transaction in prepareTransaction
alexalouit Feb 25, 2022
a4b0c61
keep immutable paradigm for prepareTransaction
alexalouit Feb 25, 2022
b5e6e7f
Merge remote-tracking branch 'upstream/cosmos-js' into cosmos-js
alexalouit Feb 25, 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
27 changes: 19 additions & 8 deletions src/families/cosmos/js-prepareTransaction.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,13 +24,16 @@ const prepareTransaction = async (
account: Account,
transaction: Transaction
): Promise<Transaction> => {
const patch: Partial<Transaction> = {};
let memo = transaction.memo;
let fees = transaction.fees;
let gas = transaction.gas;
let amount = transaction.amount;

let gasQty = new BigNumber(250000);
const gasPrice = new BigNumber(getEnv("COSMOS_GAS_PRICE"));

if (transaction.useAllAmount) {
patch.amount = getMaxEstimatedBalance(
amount = getMaxEstimatedBalance(
account,
account.balance
.dividedBy(new BigNumber(getEnv("COSMOS_GAS_AMPLIFIER")))
Expand All @@ -39,12 +42,12 @@ const prepareTransaction = async (
}

if (transaction.mode !== "send" && !transaction.memo) {
patch.memo = "Ledger Live";
memo = "Ledger Live";
}

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

// be sure payload is complete
Expand All @@ -53,7 +56,7 @@ const prepareTransaction = async (
typeUrl: "/cosmos.tx.v1beta1.TxBody",
value: {
messages: unsignedPayload,
memo: transaction.memo || patch.memo || "",
memo: transaction.memo || memo || "",
},
};

Expand Down Expand Up @@ -111,11 +114,19 @@ const prepareTransaction = async (
}
}

patch.gas = gasQty;
gas = gasQty;

patch.fees = gasPrice.multipliedBy(gasQty).integerValue();
fees = gasPrice.multipliedBy(gasQty).integerValue();

return { ...transaction, ...patch };
if (
transaction.memo !== memo ||
transaction.fees !== fees ||
transaction.gas !== gas
) {
return { ...transaction, memo, fees, gas };
}

return transaction;
};

export default prepareTransaction;
10 changes: 7 additions & 3 deletions src/families/cosmos/js-signOperation.ts
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ const signOperation = ({
let cancelled;

async function main() {
const { accountNumber, sequence } = await getAccount(
const { accountNumber, sequence, spendableBalance } = await getAccount(
account.freshAddress
);

Expand Down Expand Up @@ -152,6 +152,8 @@ const signOperation = ({

const hash = ""; // resolved at broadcast time
const accountId = account.id;
const fee = transaction.fees || new BigNumber(0);

const type: OperationType =
transaction.mode === "undelegate"
? "UNDELEGATE"
Expand All @@ -176,8 +178,10 @@ const signOperation = ({
id: encodeOperationId(accountId, hash, type),
hash,
type,
value: transaction.amount,
fee: transaction.fees || new BigNumber(0),
value: transaction.useAllAmount
? spendableBalance
: transaction.amount.plus(fee),
fee,
extra: {},
blockHash: null,
blockHeight: null,
Expand Down