Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Disable auto rewards withdrawal #8770

Open
wants to merge 2 commits into
base: develop
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
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
5 changes: 5 additions & 0 deletions .changeset/perfect-schools-pretend.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@ledgerhq/coin-cardano": minor
---

Disable auto withdrawal of rewards as a workaround for the upcoming Cardano hard fork
52 changes: 28 additions & 24 deletions libs/coin-modules/coin-cardano/src/buildTransaction.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,11 @@ import {
} from "@stricahq/typhonjs";
import BigNumber from "bignumber.js";
import type { TokenAccount } from "@ledgerhq/types-live";
import { RewardAddress } from "@stricahq/typhonjs/dist/address";
import {
getAccountStakeCredential,
getBaseAddress,
getTTL,
mergeTokens,
isTestnet,
isProtocolParamsValid,
} from "./logic";
import { decodeTokenAssetId, decodeTokenCurrencyId, getTokenAssetId } from "./buildSubAccounts";
Expand Down Expand Up @@ -44,28 +42,34 @@ function getTyphonInputFromUtxo(utxo: CardanoOutput): TyphonTypes.Input {
};
}

function getRewardWithdrawalCertificate(account: CardanoAccount): TyphonTypes.Withdrawal | null {
if (!account.cardanoResources.delegation?.rewards.gt(0)) {
return null;
}

const stakeCredential = getAccountStakeCredential(account.xpub as string, account.index);
const stakeKeyHashCredential: TyphonTypes.HashCredential = {
hash: Buffer.from(stakeCredential.key, "hex"),
type: TyphonTypes.HashType.ADDRESS,
bipPath: stakeCredential.path,
};

const networkId = isTestnet(account.currency)
? TyphonTypes.NetworkId.TESTNET
: TyphonTypes.NetworkId.MAINNET;
const rewardAddress = new RewardAddress(networkId, stakeKeyHashCredential);
const rewardsWithdrawalCertificate: TyphonTypes.Withdrawal = {
rewardAccount: rewardAddress,
amount: account.cardanoResources.delegation.rewards,
};

return rewardsWithdrawalCertificate;
function getRewardWithdrawalCertificate(_account: CardanoAccount): TyphonTypes.Withdrawal | null {
return null;

/**
* Disable rewards withdraw certificate, as a work around for Chang 2 hard fork
*/

// if (!account.cardanoResources.delegation?.rewards.gt(0)) {
// return null;
// }

// const stakeCredential = getAccountStakeCredential(account.xpub as string, account.index);
// const stakeKeyHashCredential: TyphonTypes.HashCredential = {
// hash: Buffer.from(stakeCredential.key, "hex"),
// type: TyphonTypes.HashType.ADDRESS,
// bipPath: stakeCredential.path,
// };

// const networkId = isTestnet(account.currency)
// ? TyphonTypes.NetworkId.TESTNET
// : TyphonTypes.NetworkId.MAINNET;
// const rewardAddress = new RewardAddress(networkId, stakeKeyHashCredential);
// const rewardsWithdrawalCertificate: TyphonTypes.Withdrawal = {
// rewardAccount: rewardAddress,
// amount: account.cardanoResources.delegation.rewards,
// };

// return rewardsWithdrawalCertificate;
}

const buildSendTokenTransaction = async ({
Expand Down