Skip to content

Commit a13f91e

Browse files
authored
Overpayment factor (#853)
* chore: bump Eclair to v0.12.0 * feat: add overpayment check for actual > expected * 2
2 parents c52fbf3 + e99d388 commit a13f91e

File tree

3 files changed

+24
-5
lines changed

3 files changed

+24
-5
lines changed

docker/build.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ class Image:
4646
GETH_VERSION = "1.15.5"
4747

4848
C_LIGHTNING_VERSION = "25.02"
49-
ECLAIR_VERSION = "0.11.0"
49+
ECLAIR_VERSION = "0.12.0"
5050
LND_VERSION = "0.18.5-beta"
5151

5252
BITCOIN_BUILD_ARG = BuildArgument(

lib/swap/OverpaymentProtector.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -37,10 +37,10 @@ class OverpaymentProtector {
3737
} else {
3838
return (
3939
actual - expected >
40-
Math.max(
41-
this.overPaymentExemptAmount,
42-
actual * this.overPaymentMaxPercentage,
43-
)
40+
Math.max(
41+
this.overPaymentExemptAmount,
42+
expected * this.overPaymentMaxPercentage,
43+
) || actual > expected * 2
4444
);
4545
}
4646
};

test/unit/swap/OverpaymentProtector.spec.ts

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -126,5 +126,24 @@ describe('OverpaymentProtector', () => {
126126
).toEqual(expectedResult);
127127
},
128128
);
129+
130+
test.each`
131+
expected | actual | config | expectedResult
132+
${100} | ${150} | ${{ exemptAmount: 500, maxPercentage: 60 }} | ${false}
133+
${100} | ${150} | ${{ exemptAmount: 500, maxPercentage: 40 }} | ${false}
134+
${100} | ${300} | ${{ exemptAmount: 500, maxPercentage: 1 }} | ${true}
135+
${5000} | ${5500} | ${{ exemptAmount: 100, maxPercentage: 1 }} | ${true}
136+
${1020} | ${3000} | ${{ exemptAmount: 10_000, maxPercentage: 2 }} | ${true}
137+
`(
138+
'should not allow overpayment when actual > expected * 2',
139+
({ expected, actual, config, expectedResult }) => {
140+
expect(
141+
new OverpaymentProtector(
142+
Logger.disabledLogger,
143+
config,
144+
).isUnacceptableOverpay(SwapType.Submarine, expected, actual),
145+
).toEqual(expectedResult);
146+
},
147+
);
129148
});
130149
});

0 commit comments

Comments
 (0)