Skip to content

Commit

Permalink
fix: chain swaps to unconfidential Liquid addresses
Browse files Browse the repository at this point in the history
  • Loading branch information
michael1011 committed May 28, 2024
1 parent f305eaf commit 8e3fa41
Show file tree
Hide file tree
Showing 2 changed files with 45 additions and 11 deletions.
26 changes: 16 additions & 10 deletions src/components/Fees.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,11 @@ const Fees = () => {
addressValid,
} = useCreateContext();

const isToUnconfidentialLiquid = () =>
assetReceive() === LBTC &&
addressValid() &&
!isConfidentialAddress(onchainAddress());

createEffect(() => {
if (pairs()) {
const cfg = getPair(
Expand All @@ -62,25 +67,26 @@ const Fees = () => {
let fee =
reverseCfg.fees.minerFees.claim +
reverseCfg.fees.minerFees.lockup;
if (
assetReceive() === LBTC &&
addressValid() &&
!isConfidentialAddress(onchainAddress())
) {
if (isToUnconfidentialLiquid()) {
fee += 1;
}

setMinerFee(fee);
break;

case SwapType.Chain:
case SwapType.Chain: {
const chainCfg = cfg as ChainPairTypeTaproot;
setMinerFee(
let fee =
chainCfg.fees.minerFees.server +
chainCfg.fees.minerFees.user.lockup +
chainCfg.fees.minerFees.user.claim,
);
chainCfg.fees.minerFees.user.lockup +
chainCfg.fees.minerFees.user.claim;
if (isToUnconfidentialLiquid()) {
fee += 1;
}

setMinerFee(fee);
break;
}
}

const calculateLimit = (limit: number): number => {
Expand Down
30 changes: 29 additions & 1 deletion tests/components/Fees.spec.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ describe("Fees component", () => {
);
});

test("should increase the miner fee by 1 when sending to an unconfidential Liquid address", () => {
test("should increase the miner fee for reverse swaps by 1 when sending to an unconfidential Liquid address", () => {
render(
() => (
<>
Expand All @@ -93,4 +93,32 @@ describe("Fees component", () => {
fees.minerFees.lockup + fees.minerFees.claim + 1,
);
});

test("should increase the miner fee for chain swaps by 1 when sending to an unconfidential Liquid address", () => {
render(
() => (
<>
<TestComponent />
<Fees />
</>
),
{ wrapper: contextWrapper },
);

globalSignals.setPairs(pairs);
signals.setAssetSend(BTC);
signals.setAssetReceive(LBTC);
signals.setAddressValid(true);
signals.setOnchainAddress(
"ert1q2vf850cshpedhvn9x0lv33j8az4ela04afuzp0",
);

const fees = pairs.chain[BTC][LBTC].fees;
expect(signals.minerFee()).toEqual(
fees.minerFees.server +
fees.minerFees.user.lockup +
fees.minerFees.user.claim +
1,
);
});
});

0 comments on commit 8e3fa41

Please sign in to comment.