Removes the barrel export pattern in favor of explicit subpath imports
for better tree-shaking and clearer dependencies.
## Breaking Changes
- Removed `src/helpers.ts` barrel export
- Removed `./helpers` from package.json exports
- Root `kraiken-lib` import now raises build errors
- Consumers MUST use explicit subpaths:
- `kraiken-lib/abis` - Contract ABIs
- `kraiken-lib/staking` - Staking helpers
- `kraiken-lib/snatch` - Snatch selection
- `kraiken-lib/ids` - Position ID utilities
- `kraiken-lib/subgraph` - Byte conversion utilities
- `kraiken-lib/taxRates` - Tax rate constants
- `kraiken-lib/version` - Version validation
## Changes
- kraiken-lib:
- Bumped version to 1.0.0 (breaking change)
- Updated src/index.ts to raise build errors
- Added backward-compatible ABI aliases (KraikenAbi, StakeAbi)
- Updated all test files to use .js extensions and new imports
- Updated documentation (README, AGENTS.md)
- Consumer updates:
- services/ponder: Updated ponder.config.ts to use kraiken-lib/abis
- web-app: Updated all imports to use subpaths
- composables/usePositions.ts: kraiken-lib/subgraph
- contracts/harb.ts: kraiken-lib/abis
- contracts/stake.ts: kraiken-lib/abis
## Migration Guide
```typescript
// OLD
import { getSnatchList } from 'kraiken-lib/helpers';
import { KraikenAbi } from 'kraiken-lib';
// NEW
import { getSnatchList } from 'kraiken-lib/snatch';
import { KraikenAbi } from 'kraiken-lib/abis';
```
Fixes #86
Co-authored-by: openhands <openhands@all-hands.dev>
Reviewed-on: https://codeberg.org/johba/harb/pulls/89
150 lines
3.9 KiB
TypeScript
150 lines
3.9 KiB
TypeScript
import { ref } from 'vue';
|
|
import { config } from '@/wagmi';
|
|
import { getAccount, readContract, writeContract, waitForTransactionReceipt, getChainId } from '@wagmi/core';
|
|
import type { Config } from '@wagmi/core';
|
|
import { KraikenAbi } from 'kraiken-lib/abis';
|
|
import { type Abi, type Address, type Hash } from 'viem';
|
|
import { StakeContract } from '@/contracts/stake';
|
|
import { getChain } from '@/config';
|
|
import logger from '@/utils/logger';
|
|
import { getWalletPublicClient } from '@/services/walletRpc';
|
|
|
|
interface Contract {
|
|
abi: Abi;
|
|
contractAddress: Address;
|
|
}
|
|
|
|
export const allowance = ref();
|
|
export const nonce = ref();
|
|
export const name = ref();
|
|
export const ubiDue = ref();
|
|
export const totalSupply = ref(0n);
|
|
|
|
// export const HarbContract = await getHarbJson()
|
|
export let HarbContract = getHarbJson();
|
|
|
|
function getHarbJson() {
|
|
// console.log("getHarbJson");
|
|
|
|
const chainId = getChainId(config as Config);
|
|
// console.log("chainId", chainId);
|
|
|
|
const chain = getChain(chainId);
|
|
|
|
return { abi: KraikenAbi as Abi, contractAddress: chain?.harb } as Contract;
|
|
}
|
|
|
|
export function setHarbContract() {
|
|
HarbContract = getHarbJson();
|
|
}
|
|
|
|
export async function getAllowance() {
|
|
logger.contract('getAllowance');
|
|
|
|
const account = getAccount(config as Config);
|
|
if (!account.address) {
|
|
return 0n;
|
|
}
|
|
|
|
const publicClient = getWalletPublicClient();
|
|
if (!publicClient) {
|
|
throw new Error('Wallet public client unavailable');
|
|
}
|
|
|
|
const result = (await publicClient.readContract({
|
|
abi: HarbContract.abi,
|
|
address: HarbContract.contractAddress,
|
|
functionName: 'allowance',
|
|
args: [account.address, StakeContract.contractAddress],
|
|
})) as bigint;
|
|
allowance.value = result;
|
|
return result;
|
|
}
|
|
|
|
export async function getNonce() {
|
|
logger.contract('getNonce');
|
|
|
|
const account = getAccount(config as Config);
|
|
if (!account.address) {
|
|
return 0n;
|
|
}
|
|
// console.log('HarbContract.contractAddress', HarbContract.contractAddress);
|
|
|
|
const publicClient = getWalletPublicClient();
|
|
if (!publicClient) {
|
|
throw new Error('Wallet public client unavailable');
|
|
}
|
|
|
|
const result = (await publicClient.readContract({
|
|
abi: HarbContract.abi,
|
|
address: HarbContract.contractAddress,
|
|
functionName: 'nonces',
|
|
args: [account.address],
|
|
})) as bigint;
|
|
nonce.value = result;
|
|
|
|
return result;
|
|
}
|
|
|
|
export async function getName() {
|
|
logger.contract('getName');
|
|
|
|
const publicClient = getWalletPublicClient();
|
|
if (!publicClient) {
|
|
throw new Error('Wallet public client unavailable');
|
|
}
|
|
const result = (await publicClient.readContract({
|
|
abi: HarbContract.abi,
|
|
address: HarbContract.contractAddress,
|
|
functionName: 'name',
|
|
args: [],
|
|
})) as string;
|
|
name.value = result;
|
|
|
|
return result;
|
|
}
|
|
|
|
export async function approve(amount: bigint): Promise<Hash> {
|
|
const account = getAccount(config as Config);
|
|
if (!account.address) {
|
|
throw new Error('no address found');
|
|
}
|
|
const result = await writeContract(config as Config, {
|
|
abi: HarbContract.abi,
|
|
address: HarbContract.contractAddress,
|
|
functionName: 'approve',
|
|
args: [StakeContract.contractAddress, amount],
|
|
});
|
|
// console.log("result", result);
|
|
await waitForTransactionReceipt(config as Config, {
|
|
hash: result,
|
|
});
|
|
// console.log("transactionReceipt", transactionReceipt);
|
|
|
|
return result;
|
|
}
|
|
|
|
//claim
|
|
export async function claimUbi(address: Address): Promise<Hash> {
|
|
const result = await writeContract(config as Config, {
|
|
abi: HarbContract.abi,
|
|
address: HarbContract.contractAddress,
|
|
functionName: 'claimUbi',
|
|
args: [address],
|
|
});
|
|
|
|
return result;
|
|
}
|
|
|
|
export async function getTotalSupply() {
|
|
logger.contract('getTotalSupply');
|
|
|
|
const result = await readContract(config as Config, {
|
|
abi: HarbContract.abi,
|
|
address: HarbContract.contractAddress,
|
|
functionName: 'totalSupply',
|
|
args: [],
|
|
});
|
|
totalSupply.value = result as bigint;
|
|
return result;
|
|
}
|