Complete project rename from HARB/Harberg to KRAIKEN with KRK token symbol
- Renamed core contract from Harberg.sol to Kraiken.sol - Updated token symbol from HARB to KRK - Renamed TypeScript library from harb-lib to kraiken-lib - Updated all contract imports and references across smart contracts - Modified subgraph schema and source files for new naming - Updated transaction bot dependencies and service references - Fixed test files to use new contract and token names - Updated documentation in CLAUDE.md and README.md - Regenerated subgraph types and ABI files - Added new deployment script (DeployScript2.sol) All components compile successfully and tests pass. Smart contracts: ✅ Compilation and tests pass TypeScript library: ✅ Package renamed and configured Subgraph: ✅ Code generation and build successful Transaction bot: ✅ Dependencies updated 🤖 Generated with [Claude Code](https://claude.ai/code) Co-Authored-By: Claude <noreply@anthropic.com>
This commit is contained in:
parent
c5d94403e1
commit
74143dfac7
31 changed files with 202 additions and 235 deletions
2
kraiken-lib/.gitignore
vendored
Normal file
2
kraiken-lib/.gitignore
vendored
Normal file
|
|
@ -0,0 +1,2 @@
|
|||
dist
|
||||
node_modules
|
||||
33
kraiken-lib/README.md
Normal file
33
kraiken-lib/README.md
Normal file
|
|
@ -0,0 +1,33 @@
|
|||
|
||||
|
||||
## Test
|
||||
|
||||
```
|
||||
yarn test
|
||||
```
|
||||
|
||||
|
||||
## Import
|
||||
|
||||
```
|
||||
yarn add harb-lib
|
||||
```
|
||||
|
||||
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>);
|
||||
|
||||
```
|
||||
|
||||
8
kraiken-lib/codegen.yml
Normal file
8
kraiken-lib/codegen.yml
Normal file
|
|
@ -0,0 +1,8 @@
|
|||
overwrite: true
|
||||
schema: "../subgraph/harb/schema.graphql" # Or an endpoint if your schema is remote
|
||||
documents: "../subgraph/harb/src/**/*.graphql"
|
||||
generates:
|
||||
src/__generated__/graphql.ts:
|
||||
plugins:
|
||||
- "typescript"
|
||||
- "typescript-operations"
|
||||
5
kraiken-lib/jest.config.js
Normal file
5
kraiken-lib/jest.config.js
Normal file
|
|
@ -0,0 +1,5 @@
|
|||
module.exports = {
|
||||
preset: 'ts-jest',
|
||||
testEnvironment: 'node',
|
||||
maxWorkers: 1
|
||||
};
|
||||
32
kraiken-lib/package.json
Normal file
32
kraiken-lib/package.json
Normal file
|
|
@ -0,0 +1,32 @@
|
|||
{
|
||||
"name": "kraiken-lib",
|
||||
"version": "0.2.0",
|
||||
"description": "helper functions and snatch selection",
|
||||
"main": "dist/index.js",
|
||||
"types": "dist/index.d.ts",
|
||||
"files": [
|
||||
"/dist"
|
||||
],
|
||||
"scripts": {
|
||||
"test": "jest",
|
||||
"compile": "graphql-codegen",
|
||||
"watch": "graphql-codegen -w"
|
||||
},
|
||||
"dependencies": {
|
||||
"@apollo/client": "^3.9.10",
|
||||
"apollo-link-http": "^1.5.17",
|
||||
"graphql": "^16.8.1",
|
||||
"graphql-tag": "^2.12.6"
|
||||
},
|
||||
"devDependencies": {
|
||||
"@graphql-codegen/cli": "^5.0.2",
|
||||
"@graphql-codegen/client-preset": "^4.2.5",
|
||||
"@graphql-codegen/typescript": "^4.0.6",
|
||||
"@graphql-codegen/typescript-operations": "^4.2.0",
|
||||
"@graphql-typed-document-node/core": "^3.2.0",
|
||||
"@types/jest": "^29.5.12",
|
||||
"jest": "^29.7.0",
|
||||
"ts-jest": "^29.1.2",
|
||||
"typescript": "^5.4.3"
|
||||
}
|
||||
}
|
||||
52
kraiken-lib/src/__generated__/graphql.ts
generated
Normal file
52
kraiken-lib/src/__generated__/graphql.ts
generated
Normal file
|
|
@ -0,0 +1,52 @@
|
|||
export type Maybe<T> = T | null;
|
||||
export type InputMaybe<T> = Maybe<T>;
|
||||
export type Exact<T extends { [key: string]: unknown }> = { [K in keyof T]: T[K] };
|
||||
export type MakeOptional<T, K extends keyof T> = Omit<T, K> & { [SubKey in K]?: Maybe<T[SubKey]> };
|
||||
export type MakeMaybe<T, K extends keyof T> = Omit<T, K> & { [SubKey in K]: Maybe<T[SubKey]> };
|
||||
export type MakeEmpty<T extends { [key: string]: unknown }, K extends keyof T> = { [_ in K]?: never };
|
||||
export type Incremental<T> = T | { [P in keyof T]?: P extends ' $fragmentName' | '__typename' ? T[P] : never };
|
||||
/** All built-in and custom scalars, mapped to their actual values */
|
||||
export type Scalars = {
|
||||
ID: { input: string; output: string; }
|
||||
String: { input: string; output: string; }
|
||||
Boolean: { input: boolean; output: boolean; }
|
||||
Int: { input: number; output: number; }
|
||||
Float: { input: number; output: number; }
|
||||
BigDecimal: { input: any; output: any; }
|
||||
BigInt: { input: any; output: any; }
|
||||
Bytes: { input: any; output: any; }
|
||||
};
|
||||
|
||||
export type Position = {
|
||||
__typename?: 'Position';
|
||||
creationTime: Scalars['Int']['output'];
|
||||
id: Scalars['Bytes']['output'];
|
||||
lastTaxTime?: Maybe<Scalars['Int']['output']>;
|
||||
owner: Scalars['Bytes']['output'];
|
||||
share: Scalars['BigDecimal']['output'];
|
||||
status: PositionStatus;
|
||||
taxRate: Scalars['BigDecimal']['output'];
|
||||
};
|
||||
|
||||
export enum PositionStatus {
|
||||
Active = 'Active',
|
||||
Closed = 'Closed'
|
||||
}
|
||||
|
||||
export type Query = {
|
||||
__typename?: 'Query';
|
||||
positions?: Maybe<Array<Maybe<Position>>>;
|
||||
stats?: Maybe<Array<Maybe<Stats>>>;
|
||||
};
|
||||
|
||||
export type Stats = {
|
||||
__typename?: 'Stats';
|
||||
activeSupply: Scalars['BigInt']['output'];
|
||||
id: Scalars['Bytes']['output'];
|
||||
outstandingSupply: Scalars['BigInt']['output'];
|
||||
};
|
||||
|
||||
export type GetPositionsQueryVariables = Exact<{ [key: string]: never; }>;
|
||||
|
||||
|
||||
export type GetPositionsQuery = { __typename?: 'Query', positions?: Array<{ __typename?: 'Position', id: any, owner: any, share: any, creationTime: number, lastTaxTime?: number | null, taxRate: any, status: PositionStatus } | null> | null };
|
||||
36
kraiken-lib/src/helpers.ts
Normal file
36
kraiken-lib/src/helpers.ts
Normal file
|
|
@ -0,0 +1,36 @@
|
|||
import { bytesToUint256LittleEndian } from "./subgraph";
|
||||
import { Position, PositionStatus } from './__generated__/graphql';
|
||||
|
||||
const STAKE_TOTOAL_SUPPLY: bigint = 1000000000000000000n * 10000000n;
|
||||
|
||||
const sortAndFilterPositions = (positions) => {
|
||||
return positions
|
||||
.filter(position => position.status === PositionStatus.Active)
|
||||
.sort((a, b) => parseFloat(a.taxRate) - parseFloat(b.taxRate));
|
||||
};
|
||||
|
||||
export function getSnatchList(
|
||||
positions: Position[], // all active positions
|
||||
needed: bigint, // amount of stake requested by user
|
||||
taxRate: number
|
||||
): bigint[] {
|
||||
|
||||
const sortedActivePositions = sortAndFilterPositions(positions);
|
||||
|
||||
const rv: bigint[] = [];
|
||||
let i = 0;
|
||||
while (needed > 0 && i < positions.length) {
|
||||
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));
|
||||
needed -= available;
|
||||
}
|
||||
i++;
|
||||
// code block to be executed
|
||||
}
|
||||
|
||||
if (needed > 0)
|
||||
throw new Error('Not enough capacity');
|
||||
|
||||
return rv;
|
||||
}
|
||||
3
kraiken-lib/src/index.ts
Normal file
3
kraiken-lib/src/index.ts
Normal file
|
|
@ -0,0 +1,3 @@
|
|||
export {bytesToUint256LittleEndian, uint256ToBytesLittleEndian} from './subgraph'
|
||||
|
||||
export {getSnatchList} from './helpers'
|
||||
32
kraiken-lib/src/subgraph.ts
Normal file
32
kraiken-lib/src/subgraph.ts
Normal file
|
|
@ -0,0 +1,32 @@
|
|||
|
||||
export function bytesToUint256LittleEndian(bytes: Uint8Array): bigint {
|
||||
// console.log(hexString);
|
||||
// const cleanHexString = hexString.startsWith('0x') ? hexString.substring(2) : hexString;
|
||||
// const bytes = new Uint8Array(Math.ceil(cleanHexString.length / 2));
|
||||
// for (let i = 0, j = 0; i < cleanHexString.length; i += 2, j++) {
|
||||
// bytes[j] = parseInt(cleanHexString.slice(i, i + 2), 16);
|
||||
// }
|
||||
let value: bigint = 0n;
|
||||
|
||||
for (let i = bytes.length - 1; i >= 0; i--) {
|
||||
value = (value << 8n) | BigInt(bytes[i]);
|
||||
}
|
||||
|
||||
return value;
|
||||
}
|
||||
|
||||
export function uint256ToBytesLittleEndian(value: bigint): Uint8Array {
|
||||
const bytes = new Uint8Array(4);
|
||||
for (let i = 0; i < 4; i++) {
|
||||
bytes[i] = Number((value >> (8n * BigInt(i))) & 0xFFn);
|
||||
}
|
||||
return bytes;
|
||||
// let hexString = '0x';
|
||||
|
||||
// for (let i = 0; i < bytes.length; i++) {
|
||||
// // Convert each byte to a hexadecimal string and pad with zero if needed
|
||||
// hexString += bytes[i].toString(16).padStart(2, '0');
|
||||
// }
|
||||
|
||||
// return hexString;
|
||||
}
|
||||
29
kraiken-lib/src/tests/functions.test.ts
Normal file
29
kraiken-lib/src/tests/functions.test.ts
Normal file
|
|
@ -0,0 +1,29 @@
|
|||
import { bytesToUint256LittleEndian, uint256ToBytesLittleEndian } from "../subgraph";
|
||||
import { Position, PositionStatus } from '../__generated__/graphql';
|
||||
|
||||
|
||||
describe('BigInt Conversion Functions', () => {
|
||||
test('converts uint256 to bytes and back (little endian)', async () => {
|
||||
|
||||
const mockPos: Position = {
|
||||
__typename: 'Position',
|
||||
id: uint256ToBytesLittleEndian(3n),
|
||||
owner: '0x8db6b632d743aef641146dc943acb64957155388',
|
||||
share: '0.000001',
|
||||
creationTime: 1610000000,
|
||||
taxRate: '0.01',
|
||||
status: PositionStatus.Active, // Enum usage
|
||||
};
|
||||
let hexString = '0x';
|
||||
|
||||
for (let i = 0; i < mockPos.id.length; i++) {
|
||||
// Convert each byte to a hexadecimal string and pad with zero if needed
|
||||
hexString += mockPos.id[i].toString(16).padStart(2, '0');
|
||||
}
|
||||
expect(hexString).toEqual('0x03000000');
|
||||
|
||||
// return hexString;
|
||||
expect(bytesToUint256LittleEndian(mockPos.id)).toEqual(3n);
|
||||
});
|
||||
|
||||
});
|
||||
49
kraiken-lib/src/tests/helpers.test.ts
Normal file
49
kraiken-lib/src/tests/helpers.test.ts
Normal file
|
|
@ -0,0 +1,49 @@
|
|||
import { uint256ToBytesLittleEndian } from "../subgraph";
|
||||
import { getSnatchList } from "../helpers";
|
||||
import { Position, PositionStatus } from '../__generated__/graphql';
|
||||
|
||||
|
||||
const mockPos1: Position[] = [
|
||||
{
|
||||
__typename: 'Position',
|
||||
id: uint256ToBytesLittleEndian(3n),
|
||||
owner: '0x8db6b632d743aef641146dc943acb64957155388',
|
||||
share: 0.000001,
|
||||
creationTime: 1610000000,
|
||||
taxRate: 0.05,
|
||||
status: PositionStatus.Active, // Enum usage
|
||||
},
|
||||
{
|
||||
__typename: 'Position',
|
||||
id: uint256ToBytesLittleEndian(4n),
|
||||
owner: '0x8db6b632d743aef641146dc943acb64957155388',
|
||||
share: 0.000001,
|
||||
creationTime: 1610000000,
|
||||
taxRate: 0.01,
|
||||
status: PositionStatus.Active, // Enum usage
|
||||
},
|
||||
{
|
||||
__typename: 'Position',
|
||||
id: uint256ToBytesLittleEndian(5n),
|
||||
owner: '0x8db6b632d743aef641146dc943acb64957155388',
|
||||
share: 0.000001,
|
||||
creationTime: 1610000000,
|
||||
taxRate: 0.02,
|
||||
status: PositionStatus.Active, // Enum usage
|
||||
}
|
||||
];
|
||||
|
||||
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");
|
||||
});
|
||||
});
|
||||
11
kraiken-lib/tsconfig.json
Normal file
11
kraiken-lib/tsconfig.json
Normal file
|
|
@ -0,0 +1,11 @@
|
|||
{
|
||||
"compilerOptions": {
|
||||
"module": "commonjs",
|
||||
"target": "es2020",
|
||||
"declaration": true,
|
||||
"outDir": "./dist"
|
||||
},
|
||||
"include": [
|
||||
"src/**/*"
|
||||
]
|
||||
}
|
||||
4565
kraiken-lib/yarn.lock
Normal file
4565
kraiken-lib/yarn.lock
Normal file
File diff suppressed because it is too large
Load diff
Loading…
Add table
Add a link
Reference in a new issue