tax rate, version and compose (#70)

resolves #67

Co-authored-by: johba <johba@harb.eth>
Reviewed-on: https://codeberg.org/johba/harb/pulls/70
This commit is contained in:
johba 2025-10-07 19:26:08 +02:00
parent d8ca557eb6
commit 6cbb1781ce
40 changed files with 1243 additions and 213 deletions

View file

@ -13,7 +13,7 @@ interface MockPositionsReturn {
interface MockStakeReturn {
stakingAmountShares: bigint;
taxRate: number;
taxRateIndex: number;
}
interface MockWalletReturn {
@ -27,7 +27,7 @@ interface MockStatCollectionReturn {
}
interface MockAdjustTaxRateReturn {
taxRates: Array<{ year: number }>;
taxRates: Array<{ index: number; year: number; daily: number; decimal: number }>;
}
// Mock all composables
@ -83,7 +83,7 @@ describe('useSnatchSelection', () => {
vi.mocked(useStake).mockReturnValue({
stakingAmountShares: 0n,
taxRate: 1.0,
taxRateIndex: 0,
} as MockStakeReturn);
vi.mocked(useWallet).mockReturnValue({
@ -100,7 +100,11 @@ describe('useSnatchSelection', () => {
} as MockStatCollectionReturn);
vi.mocked(useAdjustTaxRate).mockReturnValue({
taxRates: [{ year: 1 }],
taxRates: [
{ index: 0, year: 1, daily: 0.00274, decimal: 0.01 },
{ index: 1, year: 2, daily: 0.00548, decimal: 0.02 },
{ index: 2, year: 3, daily: 0.00822, decimal: 0.03 },
],
} as MockAdjustTaxRateReturn);
});
@ -123,7 +127,7 @@ describe('useSnatchSelection', () => {
vi.mocked(useStake).mockReturnValue({
stakingAmountShares: 900n,
taxRate: 1.0,
taxRateIndex: 0,
});
const { snatchablePositions, openPositionsAvailable } = useSnatchSelection();
@ -131,14 +135,14 @@ describe('useSnatchSelection', () => {
expect(openPositionsAvailable.value).toBe(true);
});
it('should filter out positions with higher tax rate', async () => {
it('should filter out positions with higher or equal tax rate index', async () => {
vi.mocked(usePositions).mockReturnValue({
activePositions: ref([
{
positionId: 1n,
owner: '0x456',
harbDeposit: 100n,
taxRate: 2.0,
taxRate: 0.02,
taxRateIndex: 1,
iAmOwner: false,
},
@ -147,7 +151,7 @@ describe('useSnatchSelection', () => {
vi.mocked(useStake).mockReturnValue({
stakingAmountShares: 100n,
taxRate: 1.0,
taxRateIndex: 0,
} as MockStakeReturn);
const { snatchablePositions } = useSnatchSelection();
@ -155,6 +159,7 @@ describe('useSnatchSelection', () => {
// Wait for watchEffect to run
await new Promise(resolve => setTimeout(resolve, 0));
// Position with taxRateIndex 1 should be filtered out when selecting taxRateIndex 0
expect(snatchablePositions.value).toEqual([]);
});
@ -182,8 +187,8 @@ describe('useSnatchSelection', () => {
positionId: 1n,
owner: '0x123',
harbDeposit: 100n,
taxRate: 0.005, // 0.5% tax rate (less than maxTaxRate)
taxRateIndex: 1,
taxRate: 0.01, // 1% tax rate (index 0)
taxRateIndex: 0,
iAmOwner: true,
};
@ -193,7 +198,7 @@ describe('useSnatchSelection', () => {
vi.mocked(useStake).mockReturnValue({
stakingAmountShares: 100n,
taxRate: 1.0, // Will be converted to 0.01 (1%) decimal
taxRateIndex: 1, // Corresponds to 2% decimal (index 1)
} as MockStakeReturn);
// Need outstandingStake > stakingAmountShares to create shortfall
@ -216,8 +221,8 @@ describe('useSnatchSelection', () => {
positionId: 1n,
owner: '0x456',
harbDeposit: 100n,
taxRate: 0.005, // 0.5% tax rate
taxRateIndex: 1,
taxRate: 0.01, // 1% tax rate (index 0)
taxRateIndex: 0,
iAmOwner: false,
};
@ -225,8 +230,8 @@ describe('useSnatchSelection', () => {
positionId: 2n,
owner: '0x789',
harbDeposit: 200n,
taxRate: 0.006, // 0.6% tax rate
taxRateIndex: 2,
taxRate: 0.02, // 2% tax rate (index 1)
taxRateIndex: 1,
iAmOwner: false,
};
@ -236,7 +241,7 @@ describe('useSnatchSelection', () => {
vi.mocked(useStake).mockReturnValue({
stakingAmountShares: 150n,
taxRate: 1.0, // Will be converted to 0.01 (1%) decimal
taxRateIndex: 2, // Corresponds to 3% decimal (index 2)
} as MockStakeReturn);
// Need outstandingStake > stakingAmountShares to create shortfall
@ -259,7 +264,7 @@ describe('useSnatchSelection', () => {
positionId: 1n,
owner: '0x456',
harbDeposit: 100n,
taxRate: 0.005, // 0.5% tax rate
taxRate: 0.02, // 2% tax rate (index 1)
taxRateIndex: 1,
iAmOwner: false,
};
@ -270,7 +275,7 @@ describe('useSnatchSelection', () => {
vi.mocked(useStake).mockReturnValue({
stakingAmountShares: 100n,
taxRate: 1.0, // Will be converted to 0.01 (1%) decimal
taxRateIndex: 2, // Corresponds to 3% decimal (index 2)
} as MockStakeReturn);
// Need outstandingStake > stakingAmountShares to create shortfall
@ -281,7 +286,11 @@ describe('useSnatchSelection', () => {
} as MockStatCollectionReturn);
vi.mocked(useAdjustTaxRate).mockReturnValue({
taxRates: [{ year: 1 }, { year: 2 }, { year: 3 }],
taxRates: [
{ index: 0, year: 1, daily: 0.00274, decimal: 0.01 },
{ index: 1, year: 2, daily: 0.00548, decimal: 0.02 },
{ index: 2, year: 3, daily: 0.00822, decimal: 0.03 },
],
} as MockAdjustTaxRateReturn);
const { floorTax } = useSnatchSelection();