Skip to content

Commit

Permalink
fix injective first tx
Browse files Browse the repository at this point in the history
  • Loading branch information
hedi-edelbloute committed Sep 15, 2023
1 parent eefe3be commit c0a11d4
Show file tree
Hide file tree
Showing 6 changed files with 26 additions and 7 deletions.
14 changes: 11 additions & 3 deletions libs/ledger-live-common/src/families/cosmos/api/Cosmos.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ describe("CosmosApi", () => {
},
} as AxiosResponse);

const account = await cosmosApi.getAccount("addr");
const account = await cosmosApi.getAccount("addr", "default");
expect(account.accountNumber).toEqual(2);
expect(account.sequence).toEqual(42);
expect(account.pubKey).toEqual("k2");
Expand All @@ -47,7 +47,7 @@ describe("CosmosApi", () => {
},
} as AxiosResponse);

const account = await cosmosApi.getAccount("addr");
const account = await cosmosApi.getAccount("addr", "default");
expect(account.accountNumber).toEqual(1);
expect(account.sequence).toEqual(0);
expect(account.pubKey).toEqual("k");
Expand All @@ -58,9 +58,17 @@ describe("CosmosApi", () => {
mockedNetwork.mockImplementation(() => {
throw new Error();
});
const account = await cosmosApi.getAccount("addr");
const account = await cosmosApi.getAccount("addr", "default");
expect(account.sequence).toEqual(0);
});

it("should return default pubkeytype value if network fails", async () => {
mockedNetwork.mockImplementation(() => {
throw new Error();
});
const account = await cosmosApi.getAccount("addr", "default");
expect(account.pubKeyType).toEqual("default");
});
});

describe("simulate", () => {
Expand Down
8 changes: 6 additions & 2 deletions libs/ledger-live-common/src/families/cosmos/api/Cosmos.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import { Operation } from "@ledgerhq/types-live";
import BigNumber from "bignumber.js";
import { patchOperationWithHash } from "../../../operation";
import cryptoFactory from "../chain/chain";
import cosmosBase from "../chain/cosmosBase";
import {
CosmosDelegation,
CosmosDelegationStatus,
Expand All @@ -16,9 +17,11 @@ import {
export class CosmosAPI {
protected defaultEndpoint: string;
private version: string;
private chainInstance: cosmosBase;

constructor(currencyId: string) {
const crypto = cryptoFactory(currencyId);
this.chainInstance = crypto;
this.defaultEndpoint = crypto.lcd;
this.version = crypto.version;
}
Expand Down Expand Up @@ -47,7 +50,7 @@ export class CosmosAPI {
unbondings,
withdrawAddress,
] = await Promise.all([
this.getAccount(address),
this.getAccount(address, this.chainInstance.defaultPubKeyType),
this.getAllBalances(address, currency),
this.getHeight(),
this.getTransactions(address, 100),
Expand All @@ -74,11 +77,12 @@ export class CosmosAPI {

getAccount = async (
address: string,
defaultPubKeyType: string,
): Promise<{ accountNumber: number; sequence: number; pubKeyType: string; pubKey: string }> => {
const accountData = {
accountNumber: 0,
sequence: 0,
pubKeyType: "/cosmos.crypto.secp256k1.PubKey",
pubKeyType: defaultPubKeyType,
pubKey: "",
};

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ class Injective extends CosmosBase {
this.unbondingPeriod = 21;
this.prefix = "inj";
this.validatorPrefix = `${this.prefix}valoper`;
this.defaultPubKeyType = "/injective.crypto.v1beta1.ethsecp256k1.PubKey";
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ abstract class cosmosBase {
abstract ledgerValidator?: string;
abstract validatorPrefix: string;
abstract prefix: string;
defaultPubKeyType = "/cosmos.crypto.secp256k1.PubKey";
defaultGas = 100000;
minGasPrice = 0.0025;
version = "v1beta1";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,10 @@ export const getEstimatedFees = async (

const cosmosAPI = new CosmosAPI(account.currency.id);
const { protoMsgs } = txToMessages(account, transaction);
const { sequence, pubKeyType, pubKey } = await cosmosAPI.getAccount(account.freshAddress);
const { sequence, pubKeyType, pubKey } = await cosmosAPI.getAccount(
account.freshAddress,
chainInstance.defaultPubKeyType,
);
const signature = new Uint8Array(Buffer.from(account.seedIdentifier, "hex"));

const txBytes = buildTransaction({
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,10 +20,12 @@ const signOperation: SignOperationFnSignature<Transaction> = ({ account, deviceI

async function main() {
const cosmosAPI = new CosmosAPI(account.currency.id);
const chainInstance = cryptoFactory(account.currency.id);

const { accountNumber, sequence, pubKeyType } = await cosmosAPI.getAccount(
account.freshAddress,
chainInstance.defaultPubKeyType,
);
const chainInstance = cryptoFactory(account.currency.id);
o.next({ type: "device-signature-requested" });
const { aminoMsgs, protoMsgs } = txToMessages(account, transaction);
if (transaction.fees == null || transaction.gas == null) {
Expand Down

2 comments on commit c0a11d4

@github-actions
Copy link

Choose a reason for hiding this comment

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

[Bot] Testing with 'Nitrogen' ✅ 1 txs ($0.00) ⏲ 13.9s

✅ 1 specs are successful: injective

What is the bot and how does it work? Everything is documented here!

⚠️ 1 spec hints
  • Spec injective:
    • There are not enough accounts to cover all mutations. Please increase the account target to at least 7 accounts
Details of the 1 mutations

Spec injective (2)

Spec injective found 2 Injective accounts (preload: 805ms). Will use Cosmos 2.34.11 on nanoS 2.1.0
Injective 1 cross: 0.02 INJ (0ops) (inj1vzjwweta3hegt99vfgrvmcq7rr5532yjsgxd4a on 44'/60'/0'/0/0) #0 js:2:injective:inj1vzjwweta3hegt99vfgrvmcq7rr5532yjsgxd4a:
Injective 2: 0 INJ (0ops) (inj1jz75s9zwpzmxfy9u4xn4d00f7qz0z7zhzmzvf0 on 44'/60'/1'/0/0) #1 js:2:injective:inj1jz75s9zwpzmxfy9u4xn4d00f7qz0z7zhzmzvf0:
necessary accounts resynced in 0.33ms
▬ Cosmos 2.34.11 on nanoS 2.1.0
→ FROM Injective 1 cross: 0.02 INJ (0ops) (inj1vzjwweta3hegt99vfgrvmcq7rr5532yjsgxd4a on 44'/60'/0'/0/0) #0 js:2:injective:inj1vzjwweta3hegt99vfgrvmcq7rr5532yjsgxd4a: (! sum of ops 0 INJ) 0.02 INJ spendable. 

max spendable ~0.0199026
★ using mutation 'send some'
→ TO Injective 2: 0 INJ (0ops) (inj1jz75s9zwpzmxfy9u4xn4d00f7qz0z7zhzmzvf0 on 44'/60'/1'/0/0) #1 js:2:injective:inj1jz75s9zwpzmxfy9u4xn4d00f7qz0z7zhzmzvf0:
✔️ transaction 
SEND  0.012502068327645058 INJ
TO inj1jz75s9zwpzmxfy9u4xn4d00f7qz0z7zhzmzvf0

with fees=0.00011946
STATUS (967ms)
  amount: 0.012502068327645058 INJ
  estimated fees: 0.0001194669 INJ
  total spent: 0.012621535227645058 INJ
errors: 
errors: 
✔️ has been signed! (3.5s) 
✔️ broadcasted! (105ms) optimistic operation: 
  -0.012621535227645058 INJ OUT        8165FE1AE79757B49488D065E0EDFEDB636A30161F1713A722F4DC07D697855C 2023-09-15T12:42
✔️ operation confirmed (0.70ms): 
  -0.012621535227645058 INJ OUT        8165FE1AE79757B49488D065E0EDFEDB636A30161F1713A722F4DC07D697855C 2023-09-15T12:42
✔️ Injective 1 cross: 0.02 INJ (0ops) (inj1vzjwweta3hegt99vfgrvmcq7rr5532yjsgxd4a on 44'/60'/0'/0/0) #0 js:2:injective:inj1vzjwweta3hegt99vfgrvmcq7rr5532yjsgxd4a: (! sum of ops 0 INJ) 0.02 INJ spendable. 
✔️ destination operation 
  ? -12621535227645058 OUT        8165FE1AE79757B49488D065E0EDFEDB636A30161F1713A722F4DC07D697855C 2023-09-15T12:42


Details of the 5 uncovered mutations

Spec injective (5)

  • send max: balance is too low for send max (1)
  • delegate new validators: can delegate (1)
  • undelegate: balance is too low (1)
  • redelegate: balance is too low for redelegate (1)
  • claim rewards: balance is too low for claim rewards (1)
Portfolio ($0.00) – Details of the 1 currencies
Spec (accounts) State Remaining Runs (est) funds?
injective (2) 0 ops , 0.02 INJ ($0.00) inj1vzjwweta3hegt99vfgrvmcq7rr5532yjsgxd4a
Injective 1 cross: 0.02 INJ (0ops) (inj1vzjwweta3hegt99vfgrvmcq7rr5532yjsgxd4a on 44'/60'/0'/0/0) #0 js:2:injective:inj1vzjwweta3hegt99vfgrvmcq7rr5532yjsgxd4a:
Injective 2: 0 INJ (0ops) (inj1jz75s9zwpzmxfy9u4xn4d00f7qz0z7zhzmzvf0 on 44'/60'/1'/0/0) #1 js:2:injective:inj1jz75s9zwpzmxfy9u4xn4d00f7qz0z7zhzmzvf0:
Performance ⏲ 13.9s

Time spent for each spec: (total across mutations)

Spec (accounts) preload scan re-sync tx status sign op broadcast test destination test
TOTAL 805ms 2427ms 0.85ms 967ms 3.5s 105ms 0.70ms N/A
injective (1) 805ms 2427ms 0.85ms 967ms 3.5s 105ms 0.70ms N/A

What is the bot and how does it work? Everything is documented here!

@github-actions
Copy link

Choose a reason for hiding this comment

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

[Bot] Testing with 'Nitrogen' ✅ 2 txs ($0.00) ⏲ 14.4s

✅ 1 specs are successful: injective

What is the bot and how does it work? Everything is documented here!

⚠️ 1 spec hints
  • Spec injective:
    • There are not enough accounts to cover all mutations. Please increase the account target to at least 7 accounts
Details of the 2 mutations

Spec injective (3)

Spec injective found 3 Injective accounts (preload: 370ms). Will use Cosmos 2.34.11 on nanoS 2.1.0
Injective 1 cross: 0.00737846 INJ (0ops) (inj1vzjwweta3hegt99vfgrvmcq7rr5532yjsgxd4a on 44'/60'/0'/0/0) #0 js:2:injective:inj1vzjwweta3hegt99vfgrvmcq7rr5532yjsgxd4a:
Injective 2: 0.012502 INJ (0ops) (inj1jz75s9zwpzmxfy9u4xn4d00f7qz0z7zhzmzvf0 on 44'/60'/1'/0/0) #1 js:2:injective:inj1jz75s9zwpzmxfy9u4xn4d00f7qz0z7zhzmzvf0:
Injective 3: 0 INJ (0ops) (inj1km5tqdc6zhx6muwcak3577y8pf0x3ze9g6kh8x on 44'/60'/2'/0/0) #2 js:2:injective:inj1km5tqdc6zhx6muwcak3577y8pf0x3ze9g6kh8x:
necessary accounts resynced in 0.68ms
▬ Cosmos 2.34.11 on nanoS 2.1.0
→ FROM Injective 1 cross: 0.00737846 INJ (0ops) (inj1vzjwweta3hegt99vfgrvmcq7rr5532yjsgxd4a on 44'/60'/0'/0/0) #0 js:2:injective:inj1vzjwweta3hegt99vfgrvmcq7rr5532yjsgxd4a: (! sum of ops 0 INJ) 0.007378464772354942 INJ spendable. 

max spendable ~0.00729265
★ using mutation 'send some'
→ TO Injective 3: 0 INJ (0ops) (inj1km5tqdc6zhx6muwcak3577y8pf0x3ze9g6kh8x on 44'/60'/2'/0/0) #2 js:2:injective:inj1km5tqdc6zhx6muwcak3577y8pf0x3ze9g6kh8x:
✔️ transaction 
SEND  0.003315694908820286 INJ
TO inj1km5tqdc6zhx6muwcak3577y8pf0x3ze9g6kh8x

with fees=0.0001095
  memo=LedgerLiveBot
STATUS (567ms)
  amount: 0.003315694908820286 INJ
  estimated fees: 0.0001095039 INJ
  total spent: 0.003425198808820286 INJ
errors: 
errors: 
✔️ has been signed! (3.6s) 
✔️ broadcasted! (59ms) optimistic operation: 
  -0.003425198808820286 INJ OUT        07CAC029E22B617B7758C298668444F566577801816860132F9A603030F98E89 2023-09-15T13:21
✔️ operation confirmed (0.66ms): 
  -0.003425198808820286 INJ OUT        07CAC029E22B617B7758C298668444F566577801816860132F9A603030F98E89 2023-09-15T13:21
✔️ Injective 1 cross: 0.00737846 INJ (0ops) (inj1vzjwweta3hegt99vfgrvmcq7rr5532yjsgxd4a on 44'/60'/0'/0/0) #0 js:2:injective:inj1vzjwweta3hegt99vfgrvmcq7rr5532yjsgxd4a: (! sum of ops 0 INJ) 0.007378464772354942 INJ spendable. 
✔️ destination operation 
  ? -3425198808820286 OUT        07CAC029E22B617B7758C298668444F566577801816860132F9A603030F98E89 2023-09-15T13:21

necessary accounts resynced in 0.17ms
▬ Cosmos 2.34.11 on nanoS 2.1.0
→ FROM Injective 2: 0.012502 INJ (0ops) (inj1jz75s9zwpzmxfy9u4xn4d00f7qz0z7zhzmzvf0 on 44'/60'/1'/0/0) #1 js:2:injective:inj1jz75s9zwpzmxfy9u4xn4d00f7qz0z7zhzmzvf0: (! sum of ops 0 INJ) 0.012502068327645058 INJ spendable. 

max spendable ~0.0124047
★ using mutation 'send max'
→ TO Injective 3: 0 INJ (0ops) (inj1km5tqdc6zhx6muwcak3577y8pf0x3ze9g6kh8x on 44'/60'/2'/0/0) #2 js:2:injective:inj1km5tqdc6zhx6muwcak3577y8pf0x3ze9g6kh8x:
✔️ transaction 
SEND MAX
TO inj1km5tqdc6zhx6muwcak3577y8pf0x3ze9g6kh8x

with fees=0.00011893
STATUS (574ms)
  amount: 0.012383136027645058 INJ
  estimated fees: 0.0001189323 INJ
  total spent: 0.012502068327645058 INJ
errors: 
errors: 
✔️ has been signed! (3.3s) 
✔️ broadcasted! (56ms) optimistic operation: 
  -0.012502068327645058 INJ OUT        81F3607D3CFB27371024AD89B269B908F413C58DCEE216F8F203B958B097E58B 2023-09-15T13:21
✔️ operation confirmed (0.29ms): 
  -0.012502068327645058 INJ OUT        81F3607D3CFB27371024AD89B269B908F413C58DCEE216F8F203B958B097E58B 2023-09-15T13:21
✔️ Injective 2: 0.012502 INJ (0ops) (inj1jz75s9zwpzmxfy9u4xn4d00f7qz0z7zhzmzvf0 on 44'/60'/1'/0/0) #1 js:2:injective:inj1jz75s9zwpzmxfy9u4xn4d00f7qz0z7zhzmzvf0: (! sum of ops 0 INJ) 0.012502068327645058 INJ spendable. 
✔️ destination operation 
  ? -12502068327645058 OUT        81F3607D3CFB27371024AD89B269B908F413C58DCEE216F8F203B958B097E58B 2023-09-15T13:21


Details of the 4 uncovered mutations

Spec injective (4)

  • delegate new validators: only one out of 2 accounts is not going to delegate (1)
  • undelegate: balance is too low (1)
  • redelegate: balance is too low for redelegate (1)
  • claim rewards: balance is too low for claim rewards (1)
Portfolio ($0.00) – Details of the 1 currencies
Spec (accounts) State Remaining Runs (est) funds?
injective (3) 0 ops , 0.0198805 INJ ($0.00) inj1vzjwweta3hegt99vfgrvmcq7rr5532yjsgxd4a
Injective 1 cross: 0.00737846 INJ (0ops) (inj1vzjwweta3hegt99vfgrvmcq7rr5532yjsgxd4a on 44'/60'/0'/0/0) #0 js:2:injective:inj1vzjwweta3hegt99vfgrvmcq7rr5532yjsgxd4a:
Injective 2: 0.012502 INJ (0ops) (inj1jz75s9zwpzmxfy9u4xn4d00f7qz0z7zhzmzvf0 on 44'/60'/1'/0/0) #1 js:2:injective:inj1jz75s9zwpzmxfy9u4xn4d00f7qz0z7zhzmzvf0:
Injective 3: 0 INJ (0ops) (inj1km5tqdc6zhx6muwcak3577y8pf0x3ze9g6kh8x on 44'/60'/2'/0/0) #2 js:2:injective:inj1km5tqdc6zhx6muwcak3577y8pf0x3ze9g6kh8x:
Performance ⏲ 14.4s

Time spent for each spec: (total across mutations)

Spec (accounts) preload scan re-sync tx status sign op broadcast test destination test
TOTAL 370ms 2157ms 3.77ms 1141ms 6.9s 115ms 0.95ms N/A
injective (2) 370ms 2157ms 3.77ms 1141ms 6.9s 115ms 0.95ms N/A

What is the bot and how does it work? Everything is documented here!

Please sign in to comment.