added snatchlist

This commit is contained in:
JulesCrown 2024-04-04 22:34:16 +02:00
parent 59533a64d2
commit c5f9836d4c
3 changed files with 25 additions and 8 deletions

View file

@ -19,4 +19,15 @@ then
import {bytesToUint256LittleEndian, uint256ToBytesLittleEndian} from 'harb-lib'
uint256ToBytesLittleEndian(3n);
```
```
## get Snatch List
```
import { getSnatchList } from "../helpers";
getSnatchList(<list of positions, <amount of stake>, <new tax rate>);
```

View file

@ -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++;

View file

@ -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");
});
});