diff --git a/harb-lib/README.md b/harb-lib/README.md index a4b697f..c9d4ee0 100644 --- a/harb-lib/README.md +++ b/harb-lib/README.md @@ -19,4 +19,15 @@ then import {bytesToUint256LittleEndian, uint256ToBytesLittleEndian} from 'harb-lib' uint256ToBytesLittleEndian(3n); -``` \ No newline at end of file +``` + +## get Snatch List + + +``` +import { getSnatchList } from "../helpers"; + +getSnatchList(, ); + +``` + diff --git a/harb-lib/src/helpers.ts b/harb-lib/src/helpers.ts index 62197b3..f84929b 100644 --- a/harb-lib/src/helpers.ts +++ b/harb-lib/src/helpers.ts @@ -20,10 +20,9 @@ export function getSnatchList( const rv: bigint[] = []; let i = 0; while (needed > 0 && i < positions.length) { - const available = (STAKE_TOTOAL_SUPPLY * BigInt(Math.round(sortedActivePositions[i].share * 100000))) / BigInt(100000); + const available = (STAKE_TOTOAL_SUPPLY * BigInt(Math.round(sortedActivePositions[i].share * 10000000))) / BigInt(10000000); if (sortedActivePositions[i].taxRate < taxRate) { rv.push(bytesToUint256LittleEndian(sortedActivePositions[i].id)); - console.log(rv, available); needed -= available; } i++; diff --git a/harb-lib/src/tests/helpers.test.ts b/harb-lib/src/tests/helpers.test.ts index 8cbe6ea..2f55253 100644 --- a/harb-lib/src/tests/helpers.test.ts +++ b/harb-lib/src/tests/helpers.test.ts @@ -3,10 +3,7 @@ import { getSnatchList } from "../helpers"; import { Position, PositionStatus } from '../__generated__/graphql'; -describe('BigInt Conversion Functions', () => { - test('get a list of positions to snatch', async () => { - - const mockPos: Position[] = [ + const mockPos1: Position[] = [ { __typename: 'Position', id: uint256ToBytesLittleEndian(3n), @@ -36,7 +33,17 @@ describe('BigInt Conversion Functions', () => { } ]; - expect(getSnatchList(mockPos, 20000000000000000000n, 0.03)).toEqual([4n, 5n]); +describe('BigInt Conversion Functions', () => { + test('get a list of positions to snatch', async () => { + // snatch 20 of 10000000 stake + expect(getSnatchList(mockPos1, 20000000000000000000n, 0.03)).toEqual([4n, 5n]); + // snatch 10 of 10000000 stake + expect(getSnatchList(mockPos1, 10000000000000000000n, 0.02)).toEqual([4n]); + // snatch 10 of 10000000 stake + expect(getSnatchList(mockPos1, 30000000000000000000n, 0.06)).toEqual([4n, 5n, 3n]); }); + test('test error', async () => { + expect(() => {getSnatchList(mockPos1, 20000000000000000000n, 0.02)}).toThrow("Not enough capacity"); + }); });