Skip to content

Commit

Permalink
feat(ton): add fees as suboperation on IN txs and update snapshot
Browse files Browse the repository at this point in the history
  • Loading branch information
ayelenmurano committed Jul 11, 2024
1 parent 47c741d commit a212dfd
Show file tree
Hide file tree
Showing 10 changed files with 60 additions and 117 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,15 @@ export const tonTransactionResponse: TonTransactionsList = {
total_fees: "0",
prev_trans_hash: "",
prev_trans_lt: "",
description: "",
description: {
aborted: true,
destroyed: false,
compute_ph: {
success: false,
exit_code: -14,
},
credit_first: true,
},
block_ref: null,
in_msg: {
source: "0:959EAA8BD0E3A2662D814278D51A6F997946207D48478008BEBE7F45F3EF781F",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -123,12 +123,6 @@ export const dataset: DatasetTest<Transaction> = {
},
};

// describe("Ton bridge", () => {
// test.todo(
// "This is an empty test to make jest command pass. Remove it once there is a real test.",
// );
// });

/**
* NOTE: if tests are added to this file,
* like done in libs/coin-polkadot/src/bridge.integration.test.ts for example,
Expand Down
18 changes: 17 additions & 1 deletion libs/coin-modules/coin-ton/src/bridge/bridgeHelpers/api.types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,22 @@ interface TonBlock {
prev_blocks: BlockReference[];
}

interface TrComputePhase {
exit_code: number;
success: boolean;
}

interface TonDescription {
aborted: boolean;
compute_ph: TrComputePhase;
credit_first: boolean;
storage_ph?: unknown;
credit_ph?: unknown;
action?: unknown;
bounce?: unknown;
destroyed: boolean;
}

export interface TonTransaction {
account: string;
hash: string;
Expand All @@ -88,7 +104,7 @@ export interface TonTransaction {
total_fees: string;
prev_trans_hash: string;
prev_trans_lt: string;
description: unknown;
description: TonDescription;
block_ref: {
workchain: number;
shard: string;
Expand Down
54 changes: 31 additions & 23 deletions libs/coin-modules/coin-ton/src/bridge/bridgeHelpers/txn.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { encodeOperationId } from "@ledgerhq/coin-framework/operation";
import { Operation } from "@ledgerhq/types-live";
import { Address } from "@ton/ton";
import BigNumber from "bignumber.js";
import { TonOperation } from "../../types";
Expand Down Expand Up @@ -71,32 +72,38 @@ export function mapTxToOps(

const date = new Date(tx.now * 1000); // now is defined in seconds
const hash = tx.in_msg?.hash ?? tx.hash; // this is the hash we know in signature time
const hasFailed =
tx.description.compute_ph.success === false && tx.description.compute_ph.exit_code !== 0;

if (isReceiving) {
let subOperations: Operation[] | undefined;
if (tx.total_fees !== "0") {
// these are small amount of fees payed when receiving
// we don't want to show them in the charts
ops.push({
id: encodeOperationId(accountId, hash, "NONE"),
hash,
type: "NONE",
value: BigNumber(tx.total_fees),
fee: BigNumber(0),
blockHeight: tx.mc_block_seqno ?? 1,
blockHash: null,
hasFailed: false,
accountId,
senders: [accountAddr],
recipients: [],
date,
extra: {
lt: tx.lt,
explorerHash: tx.hash,
comment: {
isEncrypted: false,
text: "",
subOperations = [
{
id: encodeOperationId(accountId, hash, "NONE"),
hash,
type: "NONE",
value: BigNumber(tx.total_fees),
fee: BigNumber(0),
blockHeight: tx.mc_block_seqno ?? 1,
blockHash: null,
hasFailed,
accountId,
senders: [accountAddr],
recipients: [],
date,
extra: {
lt: tx.lt,
explorerHash: tx.hash,
comment: {
isEncrypted: false,
text: "",
},
},
},
});
];
}
ops.push({
id: encodeOperationId(accountId, hash, "IN"),
Expand All @@ -106,7 +113,7 @@ export function mapTxToOps(
fee: BigNumber(tx.total_fees),
blockHeight: tx.mc_block_seqno ?? 1,
blockHash: null,
hasFailed: false,
hasFailed,
accountId,
senders: getFriendlyAddress(addressBook, tx.in_msg?.source),
recipients: [accountAddr],
Expand All @@ -122,6 +129,7 @@ export function mapTxToOps(
: "",
},
},
subOperations,
});
}

Expand All @@ -130,11 +138,11 @@ export function mapTxToOps(
id: encodeOperationId(accountId, hash, "OUT"),
hash: tx.out_msgs[0].hash, // this hash matches with in_msg.hash of IN transaction
type: "OUT",
value: BigNumber(tx.out_msgs[0].value ?? 0).plus(BigNumber(tx.total_fees)),
value: BigNumber(tx.out_msgs[0].value ?? 0),
fee: BigNumber(tx.total_fees),
blockHeight: tx.mc_block_seqno ?? 1,
blockHash: null,
hasFailed: false,
hasFailed,
accountId,
senders: [accountAddr],
recipients: getFriendlyAddress(addressBook, tx.out_msgs[0].destination),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ exports[`ton currency bridge scanAccounts ton seed 1 1`] = `
"freshAddressPath": "44'/607'/0'/0'/0'/0'",
"id": "js:2:ton:86196cb40cd25e9e696bc808e3f2c074ce0b39f2a2a9d482a68eafef86e4a060:ton",
"index": 0,
"operationsCount": 9,
"operationsCount": 6,
"pendingOperations": [],
"seedIdentifier": "86196cb40cd25e9e696bc808e3f2c074ce0b39f2a2a9d482a68eafef86e4a060",
"spendableBalance": "933174896",
Expand Down Expand Up @@ -65,7 +65,7 @@ exports[`ton currency bridge scanAccounts ton seed 1 2`] = `
"UQCOvQLYvTcbi5tL9MaDNzuVl3-J3vATimNm9yO5XPafLfV4",
],
"type": "OUT",
"value": "55547465",
"value": "50000000",
},
{
"accountId": "js:2:ton:86196cb40cd25e9e696bc808e3f2c074ce0b39f2a2a9d482a68eafef86e4a060:ton",
Expand All @@ -92,29 +92,6 @@ exports[`ton currency bridge scanAccounts ton seed 1 2`] = `
"type": "IN",
"value": "21509565",
},
{
"accountId": "js:2:ton:86196cb40cd25e9e696bc808e3f2c074ce0b39f2a2a9d482a68eafef86e4a060:ton",
"blockHash": null,
"blockHeight": 37795026,
"extra": {
"comment": {
"isEncrypted": false,
"text": "",
},
"explorerHash": "zlj5W9f4F4rHDFHzdC3gSa+nKcgobho4MV8JzZWkzoE=",
"lt": "46398669000001",
},
"fee": "0",
"hasFailed": false,
"hash": "4dDNdHb5JwpES6VYZS6ZyKSDnNNk0i37CLF6sYqD7oc=",
"id": "js:2:ton:86196cb40cd25e9e696bc808e3f2c074ce0b39f2a2a9d482a68eafef86e4a060:ton-4dDNdHb5JwpES6VYZS6ZyKSDnNNk0i37CLF6sYqD7oc=-NONE",
"recipients": [],
"senders": [
"UQCOvQLYvTcbi5tL9MaDNzuVl3-J3vATimNm9yO5XPafLfV4",
],
"type": "NONE",
"value": "396411",
},
{
"accountId": "js:2:ton:86196cb40cd25e9e696bc808e3f2c074ce0b39f2a2a9d482a68eafef86e4a060:ton",
"blockHash": null,
Expand All @@ -138,7 +115,7 @@ exports[`ton currency bridge scanAccounts ton seed 1 2`] = `
"UQCOvQLYvTcbi5tL9MaDNzuVl3-J3vATimNm9yO5XPafLfV4",
],
"type": "OUT",
"value": "52474733",
"value": "50000000",
},
{
"accountId": "js:2:ton:86196cb40cd25e9e696bc808e3f2c074ce0b39f2a2a9d482a68eafef86e4a060:ton",
Expand All @@ -165,29 +142,6 @@ exports[`ton currency bridge scanAccounts ton seed 1 2`] = `
"type": "IN",
"value": "21509565",
},
{
"accountId": "js:2:ton:86196cb40cd25e9e696bc808e3f2c074ce0b39f2a2a9d482a68eafef86e4a060:ton",
"blockHash": null,
"blockHeight": 37795087,
"extra": {
"comment": {
"isEncrypted": false,
"text": "",
},
"explorerHash": "3QMpehQMIEz1L9i2RR8NlQ8MEhtIW8OlN9DBmm5PtyM=",
"lt": "46398745000001",
},
"fee": "0",
"hasFailed": false,
"hash": "ExoMI/oYFVbPvh+Q52cf2Pyq0aL4jSpuwen8nmOvGBo=",
"id": "js:2:ton:86196cb40cd25e9e696bc808e3f2c074ce0b39f2a2a9d482a68eafef86e4a060:ton-ExoMI/oYFVbPvh+Q52cf2Pyq0aL4jSpuwen8nmOvGBo=-NONE",
"recipients": [],
"senders": [
"UQCOvQLYvTcbi5tL9MaDNzuVl3-J3vATimNm9yO5XPafLfV4",
],
"type": "NONE",
"value": "396410",
},
{
"accountId": "js:2:ton:86196cb40cd25e9e696bc808e3f2c074ce0b39f2a2a9d482a68eafef86e4a060:ton",
"blockHash": null,
Expand All @@ -213,29 +167,6 @@ exports[`ton currency bridge scanAccounts ton seed 1 2`] = `
"type": "IN",
"value": "1",
},
{
"accountId": "js:2:ton:86196cb40cd25e9e696bc808e3f2c074ce0b39f2a2a9d482a68eafef86e4a060:ton",
"blockHash": null,
"blockHeight": 37794992,
"extra": {
"comment": {
"isEncrypted": false,
"text": "",
},
"explorerHash": "XxJMiFGk4BHIwNWy1w4ZdenPc0Bh2No+tpUEIi6sycs=",
"lt": "46398628000001",
},
"fee": "0",
"hasFailed": false,
"hash": "f73qoft8iF7ANKH32Mq0cRGO9STLYlhuOFVXPQE1jI0=",
"id": "js:2:ton:86196cb40cd25e9e696bc808e3f2c074ce0b39f2a2a9d482a68eafef86e4a060:ton-f73qoft8iF7ANKH32Mq0cRGO9STLYlhuOFVXPQE1jI0=-NONE",
"recipients": [],
"senders": [
"UQCOvQLYvTcbi5tL9MaDNzuVl3-J3vATimNm9yO5XPafLfV4",
],
"type": "NONE",
"value": "84142",
},
{
"accountId": "js:2:ton:86196cb40cd25e9e696bc808e3f2c074ce0b39f2a2a9d482a68eafef86e4a060:ton",
"blockHash": null,
Expand Down
2 changes: 0 additions & 2 deletions libs/ledger-live-common/src/generated/bridge/js.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ import filecoin from "../../families/filecoin/bridge/js";
import hedera from "../../families/hedera/bridge/js";
import internet_computer from "../../families/internet_computer/bridge/js";
import stacks from "../../families/stacks/bridge/js";
import ton from "../../families/ton/bridge/js";
import vechain from "../../families/vechain/bridge/js";
import { bridge as algorand } from "../../families/algorand/setup";
import { bridge as bitcoin } from "../../families/bitcoin/setup";
Expand All @@ -32,7 +31,6 @@ export default {
hedera,
internet_computer,
stacks,
ton,
vechain,
algorand,
bitcoin,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,6 @@ import filecoin from "../families/filecoin/deviceTransactionConfig";
import hedera from "../families/hedera/deviceTransactionConfig";
import internet_computer from "../families/internet_computer/deviceTransactionConfig";
import stacks from "../families/stacks/deviceTransactionConfig";
import ton from "../families/ton/deviceTransactionConfig";
import tron from "../families/tron/deviceTransactionConfig";
import algorand from "@ledgerhq/coin-algorand/deviceTransactionConfig";
import bitcoin from "@ledgerhq/coin-bitcoin/deviceTransactionConfig";
import cardano from "@ledgerhq/coin-cardano/deviceTransactionConfig";
Expand All @@ -32,7 +30,6 @@ export default {
hedera,
internet_computer,
stacks,
ton,
algorand,
bitcoin,
cardano,
Expand Down
3 changes: 0 additions & 3 deletions libs/ledger-live-common/src/generated/hw-getAddress.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,6 @@ import filecoin from "../families/filecoin/hw-getAddress";
import hedera from "../families/hedera/hw-getAddress";
import internet_computer from "../families/internet_computer/hw-getAddress";
import stacks from "../families/stacks/hw-getAddress";
import ton from "../families/ton/hw-getAddress";
import tron from "../families/tron/hw-getAddress";
import vechain from "../families/vechain/hw-getAddress";
import { resolver as algorand } from "../families/algorand/setup";
import { resolver as bitcoin } from "../families/bitcoin/setup";
Expand All @@ -33,7 +31,6 @@ export default {
hedera,
internet_computer,
stacks,
ton,
vechain,
algorand,
bitcoin,
Expand Down
3 changes: 0 additions & 3 deletions libs/ledger-live-common/src/generated/specs.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,6 @@ import filecoin from "../families/filecoin/specs";
import hedera from "../families/hedera/specs";
import internet_computer from "../families/internet_computer/specs";
import stacks from "../families/stacks/specs";
import ton from "../families/ton/specs";
import tron from "../families/tron/specs";
import vechain from "../families/vechain/specs";
import algorand from "@ledgerhq/coin-algorand/specs";
import bitcoin from "@ledgerhq/coin-bitcoin/specs";
Expand All @@ -33,7 +31,6 @@ export default {
hedera,
internet_computer,
stacks,
ton,
vechain,
algorand,
bitcoin,
Expand Down
3 changes: 0 additions & 3 deletions libs/ledger-live-common/src/generated/transaction.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,6 @@ import filecoin from "../families/filecoin/transaction";
import hedera from "../families/hedera/transaction";
import internet_computer from "../families/internet_computer/transaction";
import stacks from "../families/stacks/transaction";
import ton from "../families/ton/transaction";
import tron from "../families/tron/transaction";
import vechain from "../families/vechain/transaction";
import algorand from "@ledgerhq/coin-algorand/transaction";
import bitcoin from "@ledgerhq/coin-bitcoin/transaction";
Expand All @@ -33,7 +31,6 @@ export default {
hedera,
internet_computer,
stacks,
ton,
vechain,
algorand,
bitcoin,
Expand Down

0 comments on commit a212dfd

Please sign in to comment.